feat(invocation): produce example output similar to spec

This commit is contained in:
Steve Moyer
2024-10-24 12:59:38 -04:00
parent a52b48cf47
commit 4932e32052
3 changed files with 20 additions and 1 deletions

View File

@@ -15,7 +15,6 @@ import (
"github.com/ipld/go-ipld-prime/fluent/qp" "github.com/ipld/go-ipld-prime/fluent/qp"
"github.com/ipld/go-ipld-prime/node/basicnode" "github.com/ipld/go-ipld-prime/node/basicnode"
"github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/crypto"
"github.com/ucan-wg/go-ucan/did" "github.com/ucan-wg/go-ucan/did"
"github.com/ucan-wg/go-ucan/pkg/command" "github.com/ucan-wg/go-ucan/pkg/command"
"github.com/ucan-wg/go-ucan/token/invocation" "github.com/ucan-wg/go-ucan/token/invocation"

View File

@@ -65,14 +65,20 @@ type Token struct {
// the previous contents of their target field. // the previous contents of their target field.
func New(iss, sub did.DID, cmd command.Command, prf []cid.Cid, opts ...Option) (*Token, error) { func New(iss, sub did.DID, cmd command.Command, prf []cid.Cid, opts ...Option) (*Token, error) {
iat := time.Now() iat := time.Now()
metadata := meta.NewMeta()
tkn := Token{ tkn := Token{
issuer: iss, issuer: iss,
subject: sub, subject: sub,
command: cmd, command: cmd,
proof: prf, proof: prf,
<<<<<<< HEAD
meta: meta.NewMeta(), meta: meta.NewMeta(),
nonce: nil, nonce: nil,
=======
meta: metadata,
nonce: nonce,
>>>>>>> f44cf8a (feat(invocation): produce example output similar to spec)
invokedAt: &iat, invokedAt: &iat,
} }
@@ -82,6 +88,7 @@ func New(iss, sub did.DID, cmd command.Command, prf []cid.Cid, opts ...Option) (
} }
} }
<<<<<<< HEAD
if len(tkn.nonce) == 0 { if len(tkn.nonce) == 0 {
tkn.nonce, err = generateNonce() tkn.nonce, err = generateNonce()
if err != nil { if err != nil {
@@ -91,6 +98,10 @@ func New(iss, sub did.DID, cmd command.Command, prf []cid.Cid, opts ...Option) (
if err := tkn.validate(); err != nil { if err := tkn.validate(); err != nil {
return nil, err return nil, err
=======
if len(tkn.meta.Keys) == 0 {
tkn.meta = nil
>>>>>>> f44cf8a (feat(invocation): produce example output similar to spec)
} }
return &tkn, nil return &tkn, nil

View File

@@ -130,6 +130,15 @@ func WithoutInvokedAt() Option {
} }
} }
// WithoutInvokedAt clears the Token's invokedAt field.
func WithoutInvokedAt() Option {
return func(t *Token) error {
t.invokedAt = nil
return nil
}
}
// WithCause sets the Token's cause field to the provided cid.Cid. // WithCause sets the Token's cause field to the provided cid.Cid.
func WithCause(cause *cid.Cid) Option { func WithCause(cause *cid.Cid) Option {
return func(t *Token) error { return func(t *Token) error {