Skip to content

Commit 947add6

Browse files
authored
Merge pull request #112 from ucan-wg/fix/invokedat-to-issued-at
fix(invocation): iat incorrectly named InvokedAt instead of IssuedAt
2 parents 5eb7b1a + 3faf9d5 commit 947add6

File tree

5 files changed

+25
-25
lines changed

5 files changed

+25
-25
lines changed

token/invocation/examples_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func ExampleNew() {
3434
invocation.WithMeta("env", "development"),
3535
invocation.WithMeta("tags", meta["tags"]),
3636
invocation.WithExpirationIn(time.Minute),
37-
invocation.WithoutInvokedAt())
37+
invocation.WithoutIssuedAt())
3838
if err != nil {
3939
fmt.Println("failed to create invocation:", err.Error())
4040

token/invocation/invocation.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type Token struct {
5151
// The timestamp at which the Invocation becomes invalid
5252
expiration *time.Time
5353
// The timestamp at which the Invocation was created
54-
invokedAt *time.Time
54+
issuedAt *time.Time
5555

5656
// An optional CID of the Receipt that enqueued the Task
5757
cause *cid.Cid
@@ -66,9 +66,9 @@ type Token struct {
6666
// WithNonce or WithEmptyNonce options to specify provide your own nonce
6767
// or to leave the nonce empty respectively.
6868
//
69-
// If no invokedAt is provided, the current time is used. Use the
70-
// WithInvokedAt or WithInvokedAtIn Options to specify a different time
71-
// or the WithoutInvokedAt Option to clear the Token's invokedAt field.
69+
// If no IssuedAt is provided, the current time is used. Use the
70+
// IssuedAt or WithIssuedAtIn Options to specify a different time
71+
// or the WithoutIssuedAt Option to clear the Token's IssuedAt field.
7272
//
7373
// With the exception of the WithMeta option, all others will overwrite
7474
// 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
8585
proof: prf,
8686
meta: meta.NewMeta(),
8787
nonce: nil,
88-
invokedAt: &iat,
88+
issuedAt: &iat,
8989
}
9090

9191
for _, opt := range opts {
@@ -192,10 +192,10 @@ func (t *Token) Expiration() *time.Time {
192192
return t.expiration
193193
}
194194

195-
// InvokedAt returns the time.Time at which the invocation token was
195+
// IssuedAt returns the time.Time at which the invocation token was
196196
// created.
197-
func (t *Token) InvokedAt() *time.Time {
198-
return t.invokedAt
197+
func (t *Token) IssuedAt() *time.Time {
198+
return t.issuedAt
199199
}
200200

201201
// Cause returns the Token's (optional) cause field which may specify
@@ -231,7 +231,7 @@ func (t *Token) String() string {
231231
res.WriteString(fmt.Sprintf("Nonce: %s\n", base64.StdEncoding.EncodeToString(t.Nonce())))
232232
res.WriteString(fmt.Sprintf("Meta: %s\n", t.Meta()))
233233
res.WriteString(fmt.Sprintf("Expiration: %v\n", t.Expiration()))
234-
res.WriteString(fmt.Sprintf("Invoked At: %v\n", t.InvokedAt()))
234+
res.WriteString(fmt.Sprintf("Issued At: %v\n", t.IssuedAt()))
235235
res.WriteString(fmt.Sprintf("Cause: %v", t.Cause()))
236236

237237
return res.String()
@@ -313,9 +313,9 @@ func tokenFromModel(m tokenPayloadModel) (*Token, error) {
313313
return nil, fmt.Errorf("parse expiration: %w", err)
314314
}
315315

316-
tkn.invokedAt, err = parse.OptionalTimestamp(m.Iat)
316+
tkn.issuedAt, err = parse.OptionalTimestamp(m.Iat)
317317
if err != nil {
318-
return nil, fmt.Errorf("parse invokedAt: %w", err)
318+
return nil, fmt.Errorf("parse IssuedAt: %w", err)
319319
}
320320

321321
tkn.cause = m.Cause

token/invocation/ipld.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ func (t *Token) toIPLD(privKey crypto.PrivKey) (datamodel.Node, error) {
217217
}
218218

219219
var iat *int64
220-
if t.invokedAt != nil {
221-
i := t.invokedAt.Unix()
220+
if t.issuedAt != nil {
221+
i := t.issuedAt.Unix()
222222
iat = &i
223223
}
224224

token/invocation/ipld_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestSealUnsealRoundtrip(t *testing.T) {
2323
invocation.WithMeta("env", "development"),
2424
invocation.WithMeta("tags", meta["tags"]),
2525
invocation.WithExpirationIn(time.Minute),
26-
invocation.WithoutInvokedAt(),
26+
invocation.WithoutIssuedAt(),
2727
)
2828
require.NoError(t, err)
2929

token/invocation/options.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -123,30 +123,30 @@ func WithExpirationIn(after time.Duration) Option {
123123
return WithExpiration(time.Now().Add(after))
124124
}
125125

126-
// WithInvokedAt sets the Token's invokedAt field to the provided
126+
// WithIssuedAt sets the Token's IssuedAt field to the provided
127127
// time.Time.
128128
//
129129
// If this Option is not provided, the invocation Token's iat field will
130130
// be set to the value of time.Now(). If you want to create an invocation
131-
// Token without this field being set, use the WithoutInvokedAt Option.
132-
func WithInvokedAt(iat time.Time) Option {
131+
// Token without this field being set, use the WithoutIssuedAt Option.
132+
func WithIssuedAt(iat time.Time) Option {
133133
return func(t *Token) error {
134-
t.invokedAt = &iat
134+
t.issuedAt = &iat
135135

136136
return nil
137137
}
138138
}
139139

140-
// WithInvokedAtIn sets the Token's invokedAt field to Now() plus the
140+
// WithIssuedAtIn sets the Token's IssuedAt field to Now() plus the
141141
// given duration.
142-
func WithInvokedAtIn(after time.Duration) Option {
143-
return WithInvokedAt(time.Now().Add(after))
142+
func WithIssuedAtIn(after time.Duration) Option {
143+
return WithIssuedAt(time.Now().Add(after))
144144
}
145145

146-
// WithoutInvokedAt clears the Token's invokedAt field.
147-
func WithoutInvokedAt() Option {
146+
// WithoutIssuedAt clears the Token's IssuedAt field.
147+
func WithoutIssuedAt() Option {
148148
return func(t *Token) error {
149-
t.invokedAt = nil
149+
t.issuedAt = nil
150150

151151
return nil
152152
}

0 commit comments

Comments
 (0)