File tree Expand file tree Collapse file tree 2 files changed +78
-0
lines changed Expand file tree Collapse file tree 2 files changed +78
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,43 @@ Include the `go-varsig` library by running the following command:
12
12
go get github.com/ucan-wg/go-varsig@latest
13
13
```
14
14
15
+ ## Quickstart
16
+
17
+ ``` go
18
+ func ExampleDecode () {
19
+ example , err := base64.RawStdEncoding .DecodeString (" NAHtAe0BE3E" )
20
+ handleErr (err)
21
+
22
+ vs , err := varsig.Decode (example)
23
+ handleErr (err)
24
+
25
+ fmt.Printf (" %T \n " , vs)
26
+ fmt.Printf (" Discriminator: %d \n " , vs.Discriminator ())
27
+ fmt.Printf (" Hash: %d \n " , vs.Hash ())
28
+ fmt.Printf (" PayloadEncoding: %d \n " , vs.PayloadEncoding ())
29
+
30
+ // Output:
31
+ // varsig.EdDSAVarsig
32
+ // Discriminator: 237
33
+ // Hash: 19
34
+ // PayloadEncoding: 3
35
+ }
36
+
37
+ func ExampleEncode () {
38
+ edDSAVarsig := varsig.NewEdDSAVarsig (
39
+ varsig.CurveEd25519 ,
40
+ varsig.HashSha2_512 ,
41
+ varsig.PayloadEncodingDAGCBOR ,
42
+ )
43
+
44
+ b64 := base64.RawStdEncoding .EncodeToString (edDSAVarsig.Encode ())
45
+ fmt.Print (b64)
46
+
47
+ // Output:
48
+ // NAHtAe0BE3E
49
+ }
50
+ ```
51
+
15
52
## Documentation
16
53
17
54
Documentation for this library is provided as Go docs at
Original file line number Diff line number Diff line change 1
1
package varsig_test
2
2
3
3
import (
4
+ "encoding/base64"
4
5
"encoding/hex"
6
+ "fmt"
5
7
"io"
6
8
"testing"
7
9
@@ -11,6 +13,39 @@ import (
11
13
"github.com/ucan-wg/go-varsig"
12
14
)
13
15
16
+ func ExampleDecode () {
17
+ example , err := base64 .RawStdEncoding .DecodeString ("NAHtAe0BE3E" )
18
+ handleErr (err )
19
+
20
+ vs , err := varsig .Decode (example )
21
+ handleErr (err )
22
+
23
+ fmt .Printf ("%T\n " , vs )
24
+ fmt .Printf ("Discriminator: %d\n " , vs .Discriminator ())
25
+ fmt .Printf ("Hash: %d\n " , vs .Hash ())
26
+ fmt .Printf ("PayloadEncoding: %d\n " , vs .PayloadEncoding ())
27
+
28
+ // Output:
29
+ // varsig.EdDSAVarsig
30
+ // Discriminator: 237
31
+ // Hash: 19
32
+ // PayloadEncoding: 3
33
+ }
34
+
35
+ func ExampleEncode () {
36
+ edDSAVarsig := varsig .NewEdDSAVarsig (
37
+ varsig .CurveEd25519 ,
38
+ varsig .HashSha2_512 ,
39
+ varsig .PayloadEncodingDAGCBOR ,
40
+ )
41
+
42
+ b64 := base64 .RawStdEncoding .EncodeToString (edDSAVarsig .Encode ())
43
+ fmt .Print (b64 )
44
+
45
+ // Output:
46
+ // NAHtAe0BE3E
47
+ }
48
+
14
49
func TestDecode (t * testing.T ) {
15
50
t .Parallel ()
16
51
@@ -112,3 +147,9 @@ func TestDecode(t *testing.T) {
112
147
assert .Nil (t , vs )
113
148
})
114
149
}
150
+
151
+ func handleErr (err error ) {
152
+ if err != nil {
153
+ panic (err )
154
+ }
155
+ }
You can’t perform that action at this time.
0 commit comments