diff --git a/token/invocation/examples_test.go b/token/invocation/examples_test.go index ce1743f..1f2e713 100644 --- a/token/invocation/examples_test.go +++ b/token/invocation/examples_test.go @@ -135,6 +135,8 @@ func prettyDAGJSON(data []byte) (string, error) { return "", err } + fmt.Println(string(jsonData)) + var out bytes.Buffer if err := json.Indent(&out, jsonData, "", " "); err != nil { return "", err diff --git a/token/invocation/invocation.go b/token/invocation/invocation.go index ff6275f..0a44285 100644 --- a/token/invocation/invocation.go +++ b/token/invocation/invocation.go @@ -65,20 +65,14 @@ type Token struct { // the previous contents of their target field. func New(iss, sub did.DID, cmd command.Command, prf []cid.Cid, opts ...Option) (*Token, error) { iat := time.Now() - metadata := meta.NewMeta() tkn := Token{ issuer: iss, subject: sub, command: cmd, proof: prf, -<<<<<<< HEAD meta: meta.NewMeta(), nonce: nil, -======= - meta: metadata, - nonce: nonce, ->>>>>>> f44cf8a (feat(invocation): produce example output similar to spec) invokedAt: &iat, } @@ -88,7 +82,6 @@ func New(iss, sub did.DID, cmd command.Command, prf []cid.Cid, opts ...Option) ( } } -<<<<<<< HEAD if len(tkn.nonce) == 0 { tkn.nonce, err = generateNonce() if err != nil { @@ -98,10 +91,6 @@ func New(iss, sub did.DID, cmd command.Command, prf []cid.Cid, opts ...Option) ( if err := tkn.validate(); err != nil { return nil, err -======= - if len(tkn.meta.Keys) == 0 { - tkn.meta = nil ->>>>>>> f44cf8a (feat(invocation): produce example output similar to spec) } return &tkn, nil @@ -240,3 +229,29 @@ func generateNonce() ([]byte, error) { } return res, nil } + +func parseOptionalCID(c *cid.Cid) (*cid.Cid, error) { + if c == nil { + return nil, nil + } + + return c, nil +} + +func parseOptionalDID(s *string) (did.DID, error) { + if s == nil { + return did.Undef, nil + } + + return did.Parse(*s) +} + +func parseOptionalTimestamp(sec *int64) (*time.Time, error) { + if sec == nil { + return nil, nil + } + + t := time.Unix(*sec, 0) + + return &t, nil +} diff --git a/token/invocation/options.go b/token/invocation/options.go index fc6ca34..f2f870a 100644 --- a/token/invocation/options.go +++ b/token/invocation/options.go @@ -130,15 +130,6 @@ 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. func WithCause(cause *cid.Cid) Option { return func(t *Token) error {