Merge pull request #50 from ucan-wg/fix/meta-optional-in-delegation

fix: change meta optional in `delegation` `Token`, model and schema
This commit is contained in:
Steve Moyer
2024-10-24 18:10:30 -04:00
committed by GitHub
5 changed files with 10 additions and 6 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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

View File

@@ -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,
}

View File

@@ -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