From e1d771333c1c9ad216a47d16423eb36e8c988d1a Mon Sep 17 00:00:00 2001 From: Steve Moyer Date: Thu, 24 Oct 2024 13:43:52 -0400 Subject: [PATCH 1/2] fix(delegation): meta is optional --- token/delegation/delegation.go | 6 +++++- token/delegation/delegation.ipldsch | 2 +- token/delegation/ipld.go | 2 +- token/delegation/schema.go | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/token/delegation/delegation.go b/token/delegation/delegation.go index ccaed08..10db932 100644 --- a/token/delegation/delegation.go +++ b/token/delegation/delegation.go @@ -79,6 +79,10 @@ func New(privKey crypto.PrivKey, aud did.DID, cmd command.Command, pol policy.Po } } + if len(tkn.meta.Keys) < 1 { + tkn.meta = nil + } + if err := tkn.validate(); err != nil { return nil, err } @@ -213,7 +217,7 @@ func tokenFromModel(m tokenPayloadModel) (*Token, error) { } tkn.nonce = m.Nonce - tkn.meta = &m.Meta + tkn.meta = m.Meta if m.Nbf != nil { t := time.Unix(*m.Nbf, 0) diff --git a/token/delegation/delegation.ipldsch b/token/delegation/delegation.ipldsch index c65988a..09ea964 100644 --- a/token/delegation/delegation.ipldsch +++ b/token/delegation/delegation.ipldsch @@ -20,7 +20,7 @@ type Payload struct { nonce Bytes # Arbitrary Metadata - meta {String : Any} + meta optional {String : Any} # "Not before" UTC Unix Timestamp in seconds (valid from), 53-bits integer nbf optional Int diff --git a/token/delegation/ipld.go b/token/delegation/ipld.go index 004a49b..8508faa 100644 --- a/token/delegation/ipld.go +++ b/token/delegation/ipld.go @@ -224,7 +224,7 @@ func (t *Token) toIPLD(privKey crypto.PrivKey) (datamodel.Node, error) { Cmd: t.command.String(), Pol: pol, Nonce: t.nonce, - Meta: *t.meta, + Meta: t.meta, Nbf: nbf, Exp: exp, } diff --git a/token/delegation/schema.go b/token/delegation/schema.go index d9b7a27..1c6873c 100644 --- a/token/delegation/schema.go +++ b/token/delegation/schema.go @@ -66,7 +66,7 @@ type tokenPayloadModel struct { Nonce []byte // Arbitrary Metadata - Meta meta.Meta + Meta *meta.Meta // "Not before" UTC Unix Timestamp in seconds (valid from), 53-bits integer // optional: can be nil From 89f648a94e8c4cfe0784c33e030e1de479be45c5 Mon Sep 17 00:00:00 2001 From: Steve Moyer Date: Thu, 24 Oct 2024 13:44:32 -0400 Subject: [PATCH 2/2] docs(did): re-fix typo RE coercion of secp256k1 public keys --- did/crypto.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/did/crypto.go b/did/crypto.go index 87e561f..d0065a7 100644 --- a/did/crypto.go +++ b/did/crypto.go @@ -204,8 +204,8 @@ func codeForCurve(pubKey crypto.PubKey) (multicodec.Code, error) { // package treats it as a different type and has a different format for // the raw bytes of the public key. // -// If a valid ECDSA public key was created the secp256k1.S256 curve, this -// function will "convert" it from a crypto.ECDSAPubKey to a +// If a valid ECDSA public key was created using the secp256k1.S256 curve, +// this function will "convert" it from a crypto.ECDSAPubKey to a // crypto.Secp256k1PublicKey. func coerceECDSAToSecp256k1(pubKey crypto.PubKey) (crypto.PubKey, error) { stdPub, err := crypto.PubKeyToStdKey(pubKey)