diff --git a/token/invocation/invocation.go b/token/invocation/invocation.go index c55fd9e..38b1c68 100644 --- a/token/invocation/invocation.go +++ b/token/invocation/invocation.go @@ -57,7 +57,8 @@ type Token struct { // or to leave the nonce empty respectively. // // If no invokedAt is provided, the current time is used. Use the -// WithInvokedAt or WithInvokedAtIn options to specify a different time. +// WithInvokedAt or WithInvokedAtIn Options to specify a different time +// or the WithoutInvokedAt Option to clear the Token's invokedAt field. // // With the exception of the WithMeta option, all other will overwrite // the previous contents of their target field. @@ -113,10 +114,14 @@ func (t *Token) Command() command.Command { return t.command } +// Arguments returns the arguments to be used when the command is +// invoked. func (t *Token) Arguments() map[string]datamodel.Node { return t.arguments } +// Proof() returns the ordered list of cid.Cids which referenced the +// delegation Tokens that authorize this invocation. func (t *Token) Proof() []cid.Cid { return t.proof } @@ -136,11 +141,14 @@ func (t *Token) Expiration() *time.Time { return t.expiration } +// InvokedAt returns the time.Time at which the invocation token was +// created. func (t *Token) InvokedAt() *time.Time { return t.invokedAt } -// Cause returns the (optional) +// Cause returns the Token's (optional) cause field which may specify +// which describes the Receipt that requested the invocation. func (t *Token) Cause() *cid.Cid { return t.cause } diff --git a/token/invocation/options.go b/token/invocation/options.go index ca79577..c8656d5 100644 --- a/token/invocation/options.go +++ b/token/invocation/options.go @@ -9,7 +9,7 @@ import ( ) // Option is a type that allows optional fields to be set during the -// creation of a Token. +// creation of a invocation Token. type Option func(*Token) error // WithArgument adds a key/value pair to the Token's Arguments field. @@ -62,7 +62,9 @@ func WithMeta(key string, val any) Option { // WithNonce sets the Token's nonce with the given value. // // If this option is not used, a random 12-byte nonce is generated for -// this require. +// this required field. If you truly want to create an invocation Token +// without a nonce, use the WithEmptyNonce Option which will set the +// nonce to an empty byte array. func WithNonce(nonce []byte) Option { return func(t *Token) error { t.nonce = nonce @@ -95,12 +97,16 @@ func WithExpiration(exp time.Time) Option { // WithExpirationIn set's the Token's optional "expiration" field to // Now() plus the given duration. -func WithExpirationIn(exp time.Duration) Option { - return WithExpiration(time.Now().Add(exp)) +func WithExpirationIn(after time.Duration) Option { + return WithExpiration(time.Now().Add(after)) } // WithInvokedAt sets the Token's invokedAt field to the provided // time.Time. +// +// If this Option is not provided, the invocation Token's iat field will +// be set to the value of time.Now(). If you want to create an invocation +// Token without this field being set, use the WithoutInvokedAt Option. func WithInvokedAt(iat time.Time) Option { return func(t *Token) error { t.invokedAt = &iat