Merge pull request #112 from ucan-wg/fix/invokedat-to-issued-at
fix(invocation): iat incorrectly named InvokedAt instead of IssuedAt
This commit is contained in:
@@ -34,7 +34,7 @@ func ExampleNew() {
|
||||
invocation.WithMeta("env", "development"),
|
||||
invocation.WithMeta("tags", meta["tags"]),
|
||||
invocation.WithExpirationIn(time.Minute),
|
||||
invocation.WithoutInvokedAt())
|
||||
invocation.WithoutIssuedAt())
|
||||
if err != nil {
|
||||
fmt.Println("failed to create invocation:", err.Error())
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ type Token struct {
|
||||
// The timestamp at which the Invocation becomes invalid
|
||||
expiration *time.Time
|
||||
// The timestamp at which the Invocation was created
|
||||
invokedAt *time.Time
|
||||
issuedAt *time.Time
|
||||
|
||||
// An optional CID of the Receipt that enqueued the Task
|
||||
cause *cid.Cid
|
||||
@@ -66,9 +66,9 @@ type Token struct {
|
||||
// WithNonce or WithEmptyNonce options to specify provide your own nonce
|
||||
// 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
|
||||
// or the WithoutInvokedAt Option to clear the Token's invokedAt field.
|
||||
// If no IssuedAt is provided, the current time is used. Use the
|
||||
// IssuedAt or WithIssuedAtIn Options to specify a different time
|
||||
// or the WithoutIssuedAt Option to clear the Token's IssuedAt field.
|
||||
//
|
||||
// With the exception of the WithMeta option, all others will overwrite
|
||||
// the previous contents of their target field.
|
||||
@@ -85,7 +85,7 @@ func New(iss did.DID, cmd command.Command, sub did.DID, prf []cid.Cid, opts ...O
|
||||
proof: prf,
|
||||
meta: meta.NewMeta(),
|
||||
nonce: nil,
|
||||
invokedAt: &iat,
|
||||
issuedAt: &iat,
|
||||
}
|
||||
|
||||
for _, opt := range opts {
|
||||
@@ -192,10 +192,10 @@ func (t *Token) Expiration() *time.Time {
|
||||
return t.expiration
|
||||
}
|
||||
|
||||
// InvokedAt returns the time.Time at which the invocation token was
|
||||
// IssuedAt returns the time.Time at which the invocation token was
|
||||
// created.
|
||||
func (t *Token) InvokedAt() *time.Time {
|
||||
return t.invokedAt
|
||||
func (t *Token) IssuedAt() *time.Time {
|
||||
return t.issuedAt
|
||||
}
|
||||
|
||||
// Cause returns the Token's (optional) cause field which may specify
|
||||
@@ -231,7 +231,7 @@ func (t *Token) String() string {
|
||||
res.WriteString(fmt.Sprintf("Nonce: %s\n", base64.StdEncoding.EncodeToString(t.Nonce())))
|
||||
res.WriteString(fmt.Sprintf("Meta: %s\n", t.Meta()))
|
||||
res.WriteString(fmt.Sprintf("Expiration: %v\n", t.Expiration()))
|
||||
res.WriteString(fmt.Sprintf("Invoked At: %v\n", t.InvokedAt()))
|
||||
res.WriteString(fmt.Sprintf("Issued At: %v\n", t.IssuedAt()))
|
||||
res.WriteString(fmt.Sprintf("Cause: %v", t.Cause()))
|
||||
|
||||
return res.String()
|
||||
@@ -313,9 +313,9 @@ func tokenFromModel(m tokenPayloadModel) (*Token, error) {
|
||||
return nil, fmt.Errorf("parse expiration: %w", err)
|
||||
}
|
||||
|
||||
tkn.invokedAt, err = parse.OptionalTimestamp(m.Iat)
|
||||
tkn.issuedAt, err = parse.OptionalTimestamp(m.Iat)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("parse invokedAt: %w", err)
|
||||
return nil, fmt.Errorf("parse IssuedAt: %w", err)
|
||||
}
|
||||
|
||||
tkn.cause = m.Cause
|
||||
|
||||
@@ -217,8 +217,8 @@ func (t *Token) toIPLD(privKey crypto.PrivKey) (datamodel.Node, error) {
|
||||
}
|
||||
|
||||
var iat *int64
|
||||
if t.invokedAt != nil {
|
||||
i := t.invokedAt.Unix()
|
||||
if t.issuedAt != nil {
|
||||
i := t.issuedAt.Unix()
|
||||
iat = &i
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ func TestSealUnsealRoundtrip(t *testing.T) {
|
||||
invocation.WithMeta("env", "development"),
|
||||
invocation.WithMeta("tags", meta["tags"]),
|
||||
invocation.WithExpirationIn(time.Minute),
|
||||
invocation.WithoutInvokedAt(),
|
||||
invocation.WithoutIssuedAt(),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
@@ -123,30 +123,30 @@ func WithExpirationIn(after time.Duration) Option {
|
||||
return WithExpiration(time.Now().Add(after))
|
||||
}
|
||||
|
||||
// WithInvokedAt sets the Token's invokedAt field to the provided
|
||||
// WithIssuedAt sets the Token's IssuedAt 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 {
|
||||
// Token without this field being set, use the WithoutIssuedAt Option.
|
||||
func WithIssuedAt(iat time.Time) Option {
|
||||
return func(t *Token) error {
|
||||
t.invokedAt = &iat
|
||||
t.issuedAt = &iat
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// WithInvokedAtIn sets the Token's invokedAt field to Now() plus the
|
||||
// WithIssuedAtIn sets the Token's IssuedAt field to Now() plus the
|
||||
// given duration.
|
||||
func WithInvokedAtIn(after time.Duration) Option {
|
||||
return WithInvokedAt(time.Now().Add(after))
|
||||
func WithIssuedAtIn(after time.Duration) Option {
|
||||
return WithIssuedAt(time.Now().Add(after))
|
||||
}
|
||||
|
||||
// WithoutInvokedAt clears the Token's invokedAt field.
|
||||
func WithoutInvokedAt() Option {
|
||||
// WithoutIssuedAt clears the Token's IssuedAt field.
|
||||
func WithoutIssuedAt() Option {
|
||||
return func(t *Token) error {
|
||||
t.invokedAt = nil
|
||||
t.issuedAt = nil
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user