feat(invocation): ipld unseal to invocation

This commit is contained in:
Steve Moyer
2024-11-04 16:07:11 -05:00
parent 4932e32052
commit d89fb395e3
3 changed files with 28 additions and 20 deletions

View File

@@ -135,6 +135,8 @@ func prettyDAGJSON(data []byte) (string, error) {
return "", err return "", err
} }
fmt.Println(string(jsonData))
var out bytes.Buffer var out bytes.Buffer
if err := json.Indent(&out, jsonData, "", " "); err != nil { if err := json.Indent(&out, jsonData, "", " "); err != nil {
return "", err return "", err

View File

@@ -65,20 +65,14 @@ 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,
} }
@@ -88,7 +82,6 @@ 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 {
@@ -98,10 +91,6 @@ 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
@@ -240,3 +229,29 @@ func generateNonce() ([]byte, error) {
} }
return res, nil 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
}

View File

@@ -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. // 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 {