-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement collection and payment
- Loading branch information
Showing
36 changed files
with
1,732 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/base64" | ||
"flag" | ||
"os" | ||
|
||
"github.com/fxamacker/cbor/v2" | ||
"github.com/ldclabs/cose/iana" | ||
"github.com/ldclabs/cose/key" | ||
"github.com/ldclabs/cose/key/aesgcm" | ||
"github.com/ldclabs/cose/key/hmac" | ||
) | ||
|
||
var kind = flag.String("kind", "state", "generate key for kind") | ||
var out = flag.String("out", "./keys/out.key", "write key to a file") | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
var err error | ||
var k key.Key | ||
var data []byte | ||
|
||
switch *kind { | ||
case "hmac": | ||
k, err = hmac.GenerateKey(iana.AlgorithmHMAC_256_64) | ||
case "aesgcm": | ||
k, err = aesgcm.GenerateKey(iana.AlgorithmA256GCM) | ||
default: | ||
panic("unsupported kind") | ||
} | ||
|
||
if err == nil { | ||
// data, err = k.MarshalCBOR() | ||
data, err = cbor.Marshal(cbor.Tag{ | ||
Number: 55799, // self described CBOR Tag | ||
Content: k, | ||
}) | ||
} | ||
|
||
if err == nil { | ||
err = os.WriteFile(*out, []byte(base64.RawURLEncoding.EncodeToString(data)), 0644) | ||
} | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
"unicode/utf8" | ||
|
||
"github.com/pkoukk/tiktoken-go" | ||
tiktoken_loader "github.com/pkoukk/tiktoken-go-loader" | ||
) | ||
|
||
var help = flag.Bool("help", false, "show help info") | ||
var version = flag.Bool("version", false, "show version info") | ||
|
||
func main() { | ||
flag.Parse() | ||
if *help || *version { | ||
fmt.Println("tiktoken example.txt") | ||
os.Exit(0) | ||
} | ||
|
||
args := flag.Args() | ||
if len(args) == 0 { | ||
fmt.Println("tiktoken example.txt") | ||
os.Exit(0) | ||
} | ||
file, err := os.ReadFile(args[0]) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
text := string(file) | ||
if !utf8.ValidString(text) { | ||
fmt.Println("invalid utf8 text") | ||
os.Exit(1) | ||
} | ||
|
||
tiktoken.SetBpeLoader(tiktoken_loader.NewOfflineLoader()) | ||
tk, err := tiktoken.GetEncoding("cl100k_base") | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Printf("%s %d tokens\n", args[0], len(tk.Encode(text, nil, nil))) | ||
os.Exit(0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2dn3pAEEAlRkHwywt4RHc4QPkRFC1Tzcuov7CgMDIFggtG5vgaB8sZJqQ1HDpQ78QBQLYO7HHUnXutsovGCAArI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2dn3pAEEAlScZRWIAJlBA18cw7mHo3bB03xW9gMEIFggBQ13neTam4zLiMMLn2Hk6J5jT3TQlS5eHegh4AO_Qh0 |
Oops, something went wrong.