diff --git a/tokens/delegation/delegation.go b/token/delegation/delegation.go similarity index 100% rename from tokens/delegation/delegation.go rename to token/delegation/delegation.go diff --git a/tokens/delegation/delegation.ipldsch b/token/delegation/delegation.ipldsch similarity index 100% rename from tokens/delegation/delegation.ipldsch rename to token/delegation/delegation.ipldsch diff --git a/tokens/delegation/delegation_test.go b/token/delegation/delegation_test.go similarity index 98% rename from tokens/delegation/delegation_test.go rename to token/delegation/delegation_test.go index 0e307bd..3c662fc 100644 --- a/tokens/delegation/delegation_test.go +++ b/token/delegation/delegation_test.go @@ -11,7 +11,7 @@ import ( "github.com/ucan-wg/go-ucan/did" "github.com/ucan-wg/go-ucan/pkg/command" "github.com/ucan-wg/go-ucan/pkg/policy" - "github.com/ucan-wg/go-ucan/tokens/delegation" + "github.com/ucan-wg/go-ucan/token/delegation" ) const ( diff --git a/tokens/delegation/examples_test.go b/token/delegation/examples_test.go similarity index 79% rename from tokens/delegation/examples_test.go rename to token/delegation/examples_test.go index 70ccb81..a9d5522 100644 --- a/tokens/delegation/examples_test.go +++ b/token/delegation/examples_test.go @@ -12,11 +12,12 @@ import ( "github.com/ipld/go-ipld-prime/codec/dagcbor" "github.com/ipld/go-ipld-prime/codec/dagjson" "github.com/libp2p/go-libp2p/core/crypto" + "github.com/ucan-wg/go-ucan/did" "github.com/ucan-wg/go-ucan/pkg/command" "github.com/ucan-wg/go-ucan/pkg/policy" - "github.com/ucan-wg/go-ucan/tokens/delegation" - "github.com/ucan-wg/go-ucan/tokens/internal/envelope" + "github.com/ucan-wg/go-ucan/token/delegation" + "github.com/ucan-wg/go-ucan/token/internal/envelope" ) // The following example shows how to create a delegation.Token with @@ -50,11 +51,11 @@ func ExampleNew() { printCIDAndSealed(id, data) - //Output: - //CID (base58BTC): zdpuAw26pFuvZa2Z9YAtpZZnWN6VmnRFr7Z8LVY5c7RVWoxGY - //DAG-CBOR (base64) out: glhAmnAkgfjAx4SA5pzJmtaHRJtTGNpF1y6oqb4yhGoM2H2EUGbBYT4rVDjMKBgCjhdGHjipm00L8iR5SsQh3sIEBaJhaEQ07QFxc3VjYW4vZGxnQDEuMC4wLXJjLjGoY2F1ZHg4ZGlkOmtleTp6Nk1rcTVZbWJKY1RyUEV4TkRpMjZpbXJUQ3BLaGVwakJGQlNIcXJCRE4yQXJQa3ZjY21kaC9mb28vYmFyY2V4cPZjaXNzeDhkaWQ6a2V5Ono2TWtwem4ybjNaR1QyVmFxTUdTUUMzdHptelY0VFM5UzcxaUZzRFhFMVdub05IMmNwb2yDg2I9PWcuc3RhdHVzZWRyYWZ0g2NhbGxpLnJldmlld2Vyg2RsaWtlZi5lbWFpbG0qQGV4YW1wbGUuY29tg2NhbnllLnRhZ3OCYm9ygoNiPT1hLmRuZXdzg2I9PWEuZXByZXNzY3N1Yng4ZGlkOmtleTp6Nk1rdEExdUJkQ3BxNHVKQnFFOWpqTWlMeXhaQmc5YTZ4Z1BQS0pqTXFzczZaYzJkbWV0YaBlbm9uY2VMAAECAwQFBgcICQoL - //Converted to DAG-JSON out: - //[ + // Output: + // CID (base58BTC): zdpuAw26pFuvZa2Z9YAtpZZnWN6VmnRFr7Z8LVY5c7RVWoxGY + // DAG-CBOR (base64) out: glhAmnAkgfjAx4SA5pzJmtaHRJtTGNpF1y6oqb4yhGoM2H2EUGbBYT4rVDjMKBgCjhdGHjipm00L8iR5SsQh3sIEBaJhaEQ07QFxc3VjYW4vZGxnQDEuMC4wLXJjLjGoY2F1ZHg4ZGlkOmtleTp6Nk1rcTVZbWJKY1RyUEV4TkRpMjZpbXJUQ3BLaGVwakJGQlNIcXJCRE4yQXJQa3ZjY21kaC9mb28vYmFyY2V4cPZjaXNzeDhkaWQ6a2V5Ono2TWtwem4ybjNaR1QyVmFxTUdTUUMzdHptelY0VFM5UzcxaUZzRFhFMVdub05IMmNwb2yDg2I9PWcuc3RhdHVzZWRyYWZ0g2NhbGxpLnJldmlld2Vyg2RsaWtlZi5lbWFpbG0qQGV4YW1wbGUuY29tg2NhbnllLnRhZ3OCYm9ygoNiPT1hLmRuZXdzg2I9PWEuZXByZXNzY3N1Yng4ZGlkOmtleTp6Nk1rdEExdUJkQ3BxNHVKQnFFOWpqTWlMeXhaQmc5YTZ4Z1BQS0pqTXFzczZaYzJkbWV0YaBlbm9uY2VMAAECAwQFBgcICQoL + // Converted to DAG-JSON out: + // [ // { // "/": { // "bytes": "mnAkgfjAx4SA5pzJmtaHRJtTGNpF1y6oqb4yhGoM2H2EUGbBYT4rVDjMKBgCjhdGHjipm00L8iR5SsQh3sIEBQ" @@ -115,7 +116,7 @@ func ExampleNew() { // "sub": "did:key:z6MktA1uBdCpq4uJBqE9jjMiLyxZBg9a6xgPPKJjMqss6Zc2" // } // } - //] + // ] } // The following example shows how to create a UCAN root delegation.Token @@ -148,11 +149,11 @@ func ExampleRoot() { printCIDAndSealed(id, data) - //Output: - //CID (base58BTC): zdpuAnbsR3e6DK8hBk5WA7KwbHYN6CKY4a3Bv1GNehvFYShQ8 - //DAG-CBOR (base64) out: glhA67ASBczF/wlIP0ESENn+4ZNQKukjcTNz+fo7K2tYa6OUm0rWICDJJkDWm7lJeQt+KvSA+Y4ctHTQbAr3Lr7mDqJhaEQ07QFxc3VjYW4vZGxnQDEuMC4wLXJjLjGoY2F1ZHg4ZGlkOmtleTp6Nk1rcTVZbWJKY1RyUEV4TkRpMjZpbXJUQ3BLaGVwakJGQlNIcXJCRE4yQXJQa3ZjY21kaC9mb28vYmFyY2V4cPZjaXNzeDhkaWQ6a2V5Ono2TWtwem4ybjNaR1QyVmFxTUdTUUMzdHptelY0VFM5UzcxaUZzRFhFMVdub05IMmNwb2yDg2I9PWcuc3RhdHVzZWRyYWZ0g2NhbGxpLnJldmlld2Vyg2RsaWtlZi5lbWFpbG0qQGV4YW1wbGUuY29tg2NhbnllLnRhZ3OCYm9ygoNiPT1hLmRuZXdzg2I9PWEuZXByZXNzY3N1Yng4ZGlkOmtleTp6Nk1rcHpuMm4zWkdUMlZhcU1HU1FDM3R6bXpWNFRTOVM3MWlGc0RYRTFXbm9OSDJkbWV0YaBlbm9uY2VMAAECAwQFBgcICQoL - //Converted to DAG-JSON out: - //[ + // Output: + // CID (base58BTC): zdpuAnbsR3e6DK8hBk5WA7KwbHYN6CKY4a3Bv1GNehvFYShQ8 + // DAG-CBOR (base64) out: glhA67ASBczF/wlIP0ESENn+4ZNQKukjcTNz+fo7K2tYa6OUm0rWICDJJkDWm7lJeQt+KvSA+Y4ctHTQbAr3Lr7mDqJhaEQ07QFxc3VjYW4vZGxnQDEuMC4wLXJjLjGoY2F1ZHg4ZGlkOmtleTp6Nk1rcTVZbWJKY1RyUEV4TkRpMjZpbXJUQ3BLaGVwakJGQlNIcXJCRE4yQXJQa3ZjY21kaC9mb28vYmFyY2V4cPZjaXNzeDhkaWQ6a2V5Ono2TWtwem4ybjNaR1QyVmFxTUdTUUMzdHptelY0VFM5UzcxaUZzRFhFMVdub05IMmNwb2yDg2I9PWcuc3RhdHVzZWRyYWZ0g2NhbGxpLnJldmlld2Vyg2RsaWtlZi5lbWFpbG0qQGV4YW1wbGUuY29tg2NhbnllLnRhZ3OCYm9ygoNiPT1hLmRuZXdzg2I9PWEuZXByZXNzY3N1Yng4ZGlkOmtleTp6Nk1rcHpuMm4zWkdUMlZhcU1HU1FDM3R6bXpWNFRTOVM3MWlGc0RYRTFXbm9OSDJkbWV0YaBlbm9uY2VMAAECAwQFBgcICQoL + // Converted to DAG-JSON out: + // [ // { // "/": { // "bytes": "67ASBczF/wlIP0ESENn+4ZNQKukjcTNz+fo7K2tYa6OUm0rWICDJJkDWm7lJeQt+KvSA+Y4ctHTQbAr3Lr7mDg" @@ -213,7 +214,7 @@ func ExampleRoot() { // "sub": "did:key:z6Mkpzn2n3ZGT2VaqMGSQC3tzmzV4TS9S71iFsDXE1WnoNH2" // } // } - //] + // ] } // The following example demonstrates how to get a delegation.Token from @@ -236,18 +237,18 @@ func ExampleToken_FromSealed() { fmt.Println("NotBefore (nbf):", tkn.NotBefore()) fmt.Println("Expiration (exp):", tkn.Expiration()) - //Output: - //DAG-CBOR (base64) in: glhAmnAkgfjAx4SA5pzJmtaHRJtTGNpF1y6oqb4yhGoM2H2EUGbBYT4rVDjMKBgCjhdGHjipm00L8iR5SsQh3sIEBaJhaEQ07QFxc3VjYW4vZGxnQDEuMC4wLXJjLjGoY2F1ZHg4ZGlkOmtleTp6Nk1rcTVZbWJKY1RyUEV4TkRpMjZpbXJUQ3BLaGVwakJGQlNIcXJCRE4yQXJQa3ZjY21kaC9mb28vYmFyY2V4cPZjaXNzeDhkaWQ6a2V5Ono2TWtwem4ybjNaR1QyVmFxTUdTUUMzdHptelY0VFM5UzcxaUZzRFhFMVdub05IMmNwb2yDg2I9PWcuc3RhdHVzZWRyYWZ0g2NhbGxpLnJldmlld2Vyg2RsaWtlZi5lbWFpbG0qQGV4YW1wbGUuY29tg2NhbnllLnRhZ3OCYm9ygoNiPT1hLmRuZXdzg2I9PWEuZXByZXNzY3N1Yng4ZGlkOmtleTp6Nk1rdEExdUJkQ3BxNHVKQnFFOWpqTWlMeXhaQmc5YTZ4Z1BQS0pqTXFzczZaYzJkbWV0YaBlbm9uY2VMAAECAwQFBgcICQoL - //CID (base58BTC): zdpuAw26pFuvZa2Z9YAtpZZnWN6VmnRFr7Z8LVY5c7RVWoxGY - //Issuer (iss): did:key:z6Mkpzn2n3ZGT2VaqMGSQC3tzmzV4TS9S71iFsDXE1WnoNH2 - //Audience (aud): did:key:z6Mkq5YmbJcTrPExNDi26imrTCpKhepjBFBSHqrBDN2ArPkv - //Subject (sub): did:key:z6MktA1uBdCpq4uJBqE9jjMiLyxZBg9a6xgPPKJjMqss6Zc2 - //Command (cmd): /foo/bar - //Policy (pol): TODO - //Nonce (nonce): 000102030405060708090a0b - //Meta (meta): TODO - //NotBefore (nbf): - //Expiration (exp): + // Output: + // DAG-CBOR (base64) in: glhAmnAkgfjAx4SA5pzJmtaHRJtTGNpF1y6oqb4yhGoM2H2EUGbBYT4rVDjMKBgCjhdGHjipm00L8iR5SsQh3sIEBaJhaEQ07QFxc3VjYW4vZGxnQDEuMC4wLXJjLjGoY2F1ZHg4ZGlkOmtleTp6Nk1rcTVZbWJKY1RyUEV4TkRpMjZpbXJUQ3BLaGVwakJGQlNIcXJCRE4yQXJQa3ZjY21kaC9mb28vYmFyY2V4cPZjaXNzeDhkaWQ6a2V5Ono2TWtwem4ybjNaR1QyVmFxTUdTUUMzdHptelY0VFM5UzcxaUZzRFhFMVdub05IMmNwb2yDg2I9PWcuc3RhdHVzZWRyYWZ0g2NhbGxpLnJldmlld2Vyg2RsaWtlZi5lbWFpbG0qQGV4YW1wbGUuY29tg2NhbnllLnRhZ3OCYm9ygoNiPT1hLmRuZXdzg2I9PWEuZXByZXNzY3N1Yng4ZGlkOmtleTp6Nk1rdEExdUJkQ3BxNHVKQnFFOWpqTWlMeXhaQmc5YTZ4Z1BQS0pqTXFzczZaYzJkbWV0YaBlbm9uY2VMAAECAwQFBgcICQoL + // CID (base58BTC): zdpuAw26pFuvZa2Z9YAtpZZnWN6VmnRFr7Z8LVY5c7RVWoxGY + // Issuer (iss): did:key:z6Mkpzn2n3ZGT2VaqMGSQC3tzmzV4TS9S71iFsDXE1WnoNH2 + // Audience (aud): did:key:z6Mkq5YmbJcTrPExNDi26imrTCpKhepjBFBSHqrBDN2ArPkv + // Subject (sub): did:key:z6MktA1uBdCpq4uJBqE9jjMiLyxZBg9a6xgPPKJjMqss6Zc2 + // Command (cmd): /foo/bar + // Policy (pol): TODO + // Nonce (nonce): 000102030405060708090a0b + // Meta (meta): TODO + // NotBefore (nbf): + // Expiration (exp): } func exampleCBORData() []byte { diff --git a/tokens/delegation/ipld.go b/token/delegation/ipld.go similarity index 94% rename from tokens/delegation/ipld.go rename to token/delegation/ipld.go index 0c2dbb1..7c21b79 100644 --- a/tokens/delegation/ipld.go +++ b/token/delegation/ipld.go @@ -12,7 +12,7 @@ import ( "github.com/libp2p/go-libp2p/core/crypto" "github.com/ucan-wg/go-ucan/did" - "github.com/ucan-wg/go-ucan/tokens/internal/envelope" + "github.com/ucan-wg/go-ucan/token/internal/envelope" ) // ToSealed wraps the delegation token in an envelope, generates the @@ -32,7 +32,7 @@ func (t *Token) ToSealed(privKey crypto.PrivKey) ([]byte, cid.Cid, error) { return data, id, nil } -// ToSealedWriter is the same as Seal but accepts an io.Writer. +// ToSealedWriter is the same as ToSealed but accepts an io.Writer. func (t *Token) ToSealedWriter(w io.Writer, privKey crypto.PrivKey) (cid.Cid, error) { cidWriter := envelope.NewCIDWriter(w) @@ -93,7 +93,7 @@ func (t *Token) Encode(privKey crypto.PrivKey, encFn codec.Encoder) ([]byte, err return ipld.Encode(node, encFn) } -// EncodeWriter is the same as Encode but accepts an io.Writer. +// EncodeWriter is the same as Encode, but accepts an io.Writer. func (t *Token) EncodeWriter(w io.Writer, privKey crypto.PrivKey, encFn codec.Encoder) error { node, err := t.toIPLD(privKey) if err != nil { @@ -108,7 +108,7 @@ func (t *Token) ToDagCbor(privKey crypto.PrivKey) ([]byte, error) { return t.Encode(privKey, dagcbor.Encode) } -// ToDagCborWriter is the same as ToDagCbor but it accepts an io.Writer. +// ToDagCborWriter is the same as ToDagCbor, but it accepts an io.Writer. func (t *Token) ToDagCborWriter(w io.Writer, privKey crypto.PrivKey) error { return t.EncodeWriter(w, privKey, dagcbor.Encode) } @@ -118,7 +118,7 @@ func (t *Token) ToDagJson(privKey crypto.PrivKey) ([]byte, error) { return t.Encode(privKey, dagjson.Encode) } -// ToDagJsonWriter is the same as ToDagJson but it accepts an io.Writer. +// ToDagJsonWriter is the same as ToDagJson, but it accepts an io.Writer. func (t *Token) ToDagJsonWriter(w io.Writer, privKey crypto.PrivKey) error { return t.EncodeWriter(w, privKey, dagjson.Encode) } diff --git a/tokens/delegation/options.go b/token/delegation/options.go similarity index 100% rename from tokens/delegation/options.go rename to token/delegation/options.go diff --git a/tokens/delegation/schema.go b/token/delegation/schema.go similarity index 97% rename from tokens/delegation/schema.go rename to token/delegation/schema.go index fe702a6..d9b7a27 100644 --- a/tokens/delegation/schema.go +++ b/token/delegation/schema.go @@ -11,7 +11,7 @@ import ( "github.com/ipld/go-ipld-prime/schema" "github.com/ucan-wg/go-ucan/pkg/meta" - "github.com/ucan-wg/go-ucan/tokens/internal/envelope" + "github.com/ucan-wg/go-ucan/token/internal/envelope" ) // [Tag] is the string used as a key within the SigPayload that identifies diff --git a/tokens/delegation/schema_test.go b/token/delegation/schema_test.go similarity index 97% rename from tokens/delegation/schema_test.go rename to token/delegation/schema_test.go index fbfc919..685f6c8 100644 --- a/tokens/delegation/schema_test.go +++ b/token/delegation/schema_test.go @@ -11,8 +11,8 @@ import ( "github.com/stretchr/testify/require" "gotest.tools/v3/golden" - "github.com/ucan-wg/go-ucan/tokens/delegation" - "github.com/ucan-wg/go-ucan/tokens/internal/envelope" + "github.com/ucan-wg/go-ucan/token/delegation" + "github.com/ucan-wg/go-ucan/token/internal/envelope" ) //go:embed delegation.ipldsch diff --git a/tokens/delegation/testdata/new.dagjson b/token/delegation/testdata/new.dagjson similarity index 100% rename from tokens/delegation/testdata/new.dagjson rename to token/delegation/testdata/new.dagjson diff --git a/tokens/delegation/testdata/root.dagjson b/token/delegation/testdata/root.dagjson similarity index 100% rename from tokens/delegation/testdata/root.dagjson rename to token/delegation/testdata/root.dagjson diff --git a/tokens/inspect.go b/token/inspect.go similarity index 85% rename from tokens/inspect.go rename to token/inspect.go index cfb8a24..108aed5 100644 --- a/tokens/inspect.go +++ b/token/inspect.go @@ -1,9 +1,9 @@ -package tokens +package token import ( "github.com/ipld/go-ipld-prime/datamodel" - "github.com/ucan-wg/go-ucan/tokens/internal/envelope" + "github.com/ucan-wg/go-ucan/token/internal/envelope" ) type Info = envelope.Info diff --git a/token/interface.go b/token/interface.go new file mode 100644 index 0000000..4e8e1c9 --- /dev/null +++ b/token/interface.go @@ -0,0 +1,41 @@ +package token + +import ( + "io" + + "github.com/ipfs/go-cid" + "github.com/ipld/go-ipld-prime/codec" + "github.com/libp2p/go-libp2p/core/crypto" + + "github.com/ucan-wg/go-ucan/did" + "github.com/ucan-wg/go-ucan/pkg/meta" +) + +type Token interface { + Marshaller + + // Issuer returns the did.DID representing the Token's issuer. + Issuer() did.DID + // Meta returns the Token's metadata. + Meta() *meta.Meta +} + +type Marshaller interface { + // ToSealed wraps the token in an envelope, generates the signature, encodes + // the result to DAG-CBOR and calculates the CID of the resulting binary data. + ToSealed(privKey crypto.PrivKey) ([]byte, cid.Cid, error) + // ToSealedWriter is the same as ToSealed but accepts an io.Writer. + ToSealedWriter(w io.Writer, privKey crypto.PrivKey) (cid.Cid, error) + // Encode marshals a Token to the format specified by the provided codec.Encoder. + Encode(privKey crypto.PrivKey, encFn codec.Encoder) ([]byte, error) + // EncodeWriter is the same as Encode, but accepts an io.Writer. + EncodeWriter(w io.Writer, privKey crypto.PrivKey, encFn codec.Encoder) error + // ToDagCbor marshals the Token to the DAG-CBOR format. + ToDagCbor(privKey crypto.PrivKey) ([]byte, error) + // ToDagCborWriter is the same as ToDagCbor, but it accepts an io.Writer. + ToDagCborWriter(w io.Writer, privKey crypto.PrivKey) error + // ToDagJson marshals the Token to the DAG-JSON format. + ToDagJson(privKey crypto.PrivKey) ([]byte, error) + // ToDagJsonWriter is the same as ToDagJson, but it accepts an io.Writer. + ToDagJsonWriter(w io.Writer, privKey crypto.PrivKey) error +} diff --git a/tokens/internal/envelope/cid.go b/token/internal/envelope/cid.go similarity index 100% rename from tokens/internal/envelope/cid.go rename to token/internal/envelope/cid.go diff --git a/tokens/internal/envelope/cid_test.go b/token/internal/envelope/cid_test.go similarity index 97% rename from tokens/internal/envelope/cid_test.go rename to token/internal/envelope/cid_test.go index fd4be1b..9b2d91c 100644 --- a/tokens/internal/envelope/cid_test.go +++ b/token/internal/envelope/cid_test.go @@ -11,7 +11,7 @@ import ( "github.com/stretchr/testify/require" "gotest.tools/v3/golden" - "github.com/ucan-wg/go-ucan/tokens/internal/envelope" + "github.com/ucan-wg/go-ucan/token/internal/envelope" ) func TestCidFromBytes(t *testing.T) { diff --git a/tokens/internal/envelope/example_test.go b/token/internal/envelope/example_test.go similarity index 98% rename from tokens/internal/envelope/example_test.go rename to token/internal/envelope/example_test.go index 9f140db..707488e 100644 --- a/tokens/internal/envelope/example_test.go +++ b/token/internal/envelope/example_test.go @@ -18,7 +18,7 @@ import ( "github.com/stretchr/testify/require" "gotest.tools/v3/golden" - "github.com/ucan-wg/go-ucan/tokens/internal/envelope" + "github.com/ucan-wg/go-ucan/token/internal/envelope" ) const ( diff --git a/tokens/internal/envelope/ipld.go b/token/internal/envelope/ipld.go similarity index 99% rename from tokens/internal/envelope/ipld.go rename to token/internal/envelope/ipld.go index 3ba3c63..6b74809 100644 --- a/tokens/internal/envelope/ipld.go +++ b/token/internal/envelope/ipld.go @@ -43,7 +43,7 @@ import ( "github.com/libp2p/go-libp2p/core/crypto" "github.com/ucan-wg/go-ucan/did" - "github.com/ucan-wg/go-ucan/tokens/internal/varsig" + "github.com/ucan-wg/go-ucan/token/internal/varsig" ) const ( diff --git a/tokens/internal/envelope/ipld_test.go b/token/internal/envelope/ipld_test.go similarity index 98% rename from tokens/internal/envelope/ipld_test.go rename to token/internal/envelope/ipld_test.go index 3a0b93a..3aca88e 100644 --- a/tokens/internal/envelope/ipld_test.go +++ b/token/internal/envelope/ipld_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/require" "gotest.tools/v3/golden" - "github.com/ucan-wg/go-ucan/tokens/internal/envelope" + "github.com/ucan-wg/go-ucan/token/internal/envelope" ) func TestDecode(t *testing.T) { diff --git a/tokens/internal/envelope/testdata/example.dagcbor b/token/internal/envelope/testdata/example.dagcbor similarity index 100% rename from tokens/internal/envelope/testdata/example.dagcbor rename to token/internal/envelope/testdata/example.dagcbor diff --git a/tokens/internal/envelope/testdata/example.dagjson b/token/internal/envelope/testdata/example.dagjson similarity index 100% rename from tokens/internal/envelope/testdata/example.dagjson rename to token/internal/envelope/testdata/example.dagjson diff --git a/tokens/internal/envelope/testdata/example.ipldsch b/token/internal/envelope/testdata/example.ipldsch similarity index 100% rename from tokens/internal/envelope/testdata/example.ipldsch rename to token/internal/envelope/testdata/example.ipldsch diff --git a/tokens/internal/varsig/varsig.go b/token/internal/varsig/varsig.go similarity index 100% rename from tokens/internal/varsig/varsig.go rename to token/internal/varsig/varsig.go diff --git a/tokens/internal/varsig/varsig_test.go b/token/internal/varsig/varsig_test.go similarity index 94% rename from tokens/internal/varsig/varsig_test.go rename to token/internal/varsig/varsig_test.go index a1ab1cd..3b5387a 100644 --- a/tokens/internal/varsig/varsig_test.go +++ b/token/internal/varsig/varsig_test.go @@ -8,7 +8,7 @@ import ( "github.com/libp2p/go-libp2p/core/crypto/pb" "github.com/stretchr/testify/assert" - "github.com/ucan-wg/go-ucan/tokens/internal/varsig" + "github.com/ucan-wg/go-ucan/token/internal/varsig" ) func TestDecode(t *testing.T) { diff --git a/tokens/read.go b/token/read.go similarity index 77% rename from tokens/read.go rename to token/read.go index 999fc50..2a9b151 100644 --- a/tokens/read.go +++ b/token/read.go @@ -1,4 +1,4 @@ -package tokens +package token import ( "fmt" @@ -10,8 +10,8 @@ import ( "github.com/ipld/go-ipld-prime/codec/dagjson" "github.com/ipld/go-ipld-prime/datamodel" - "github.com/ucan-wg/go-ucan/tokens/delegation" - "github.com/ucan-wg/go-ucan/tokens/internal/envelope" + "github.com/ucan-wg/go-ucan/token/delegation" + "github.com/ucan-wg/go-ucan/token/internal/envelope" ) // Decode unmarshals the input data using the format specified by the @@ -20,7 +20,7 @@ import ( // Token is invalid. // Supported and returned types are: // - delegation.Token -func Decode(b []byte, decFn codec.Decoder) (any, error) { +func Decode(b []byte, decFn codec.Decoder) (Token, error) { node, err := ipld.Decode(b, decFn) if err != nil { return nil, err @@ -29,7 +29,7 @@ func Decode(b []byte, decFn codec.Decoder) (any, error) { } // DecodeReader is the same as Decode, but accept an io.Reader. -func DecodeReader(r io.Reader, decFn codec.Decoder) (any, error) { +func DecodeReader(r io.Reader, decFn codec.Decoder) (Token, error) { node, err := ipld.DecodeStreaming(r, decFn) if err != nil { return nil, err @@ -42,12 +42,12 @@ func DecodeReader(r io.Reader, decFn codec.Decoder) (any, error) { // Token is invalid. // Supported and returned types are: // - delegation.Token -func FromDagCbor(b []byte) (any, error) { +func FromDagCbor(b []byte) (Token, error) { return Decode(b, dagcbor.Decode) } // FromDagCborReader is the same as FromDagCbor, but accept an io.Reader. -func FromDagCborReader(r io.Reader) (any, error) { +func FromDagCborReader(r io.Reader) (Token, error) { return DecodeReader(r, dagcbor.Decode) } @@ -56,16 +56,16 @@ func FromDagCborReader(r io.Reader) (any, error) { // Token is invalid. // Supported and returned types are: // - delegation.Token -func FromDagJson(b []byte) (any, error) { +func FromDagJson(b []byte) (Token, error) { return Decode(b, dagjson.Decode) } // FromDagJsonReader is the same as FromDagJson, but accept an io.Reader. -func FromDagJsonReader(r io.Reader) (any, error) { +func FromDagJsonReader(r io.Reader) (Token, error) { return DecodeReader(r, dagjson.Decode) } -func fromIPLD(node datamodel.Node) (any, error) { +func fromIPLD(node datamodel.Node) (Token, error) { tag, err := envelope.FindTag(node) if err != nil { return nil, err