Skip to content

Commit 2010bc5

Browse files
committed
refactor: tighten ucan type surface
- UTCUnixTimestamp: alias → defined type. The compiler now catches accidental mixing with raw int64s carrying other units (e.g. nanos). - Nonce: drop the alias. It was []byte and the call-site name already documents the role; the alias added a parallel name with no teeth. - Link: drop the alias. The datamodels already used cid.Cid directly; the alias just created a dual public name for the same type. Regenerates cborgen/dagjsongen output for delegation and invocation datamodels so the optional timestamp pointer casts pick up the defined type. No wire format change.
1 parent 4d8e8fa commit 2010bc5

19 files changed

Lines changed: 77 additions & 71 deletions

File tree

execution/bindexec/task.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func NewTask[A Arguments](
2121
subject did.DID,
2222
command ucan.Command,
2323
argsBytes []byte,
24-
nonce ucan.Nonce,
24+
nonce []byte,
2525
) (*Task[A], error) {
2626
var args A
2727
// if args is a pointer type, allocate the underlying value so

ucan/delegation/datamodel/cbor_gen.maps.go

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ucan/delegation/datamodel/dag_json_gen.maps.go

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ucan/delegation/datamodel/delegation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type TokenPayloadModel1_0_0_rc1 struct {
2222
// UCAN Policy Language.
2323
Pol policy.Policy `cborgen:"pol" dagjsongen:"pol"`
2424
// A unique, random nonce.
25-
Nonce ucan.Nonce `cborgen:"nonce" dagjsongen:"nonce"`
25+
Nonce []byte `cborgen:"nonce" dagjsongen:"nonce"`
2626
// Arbitrary metadata.
2727
Meta *datamodel.Raw `cborgen:"meta,omitempty" dagjsongen:"meta,omitempty"`
2828
// "Not before" UTC Unix Timestamp in seconds (valid from).

ucan/delegation/delegation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (d *Delegation) SignedBytes() []byte {
9999
// Nonce helps prevent replay attacks and ensures a unique CID per delegation.
100100
//
101101
// https://github.com/ucan-wg/spec/blob/main/README.md#nonce
102-
func (d *Delegation) Nonce() ucan.Nonce {
102+
func (d *Delegation) Nonce() []byte {
103103
return d.sigPayload.TokenPayload1_0_0_rc1.Nonce
104104
}
105105

ucan/delegation/options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func WithNoExpiration() Option {
4141
}
4242

4343
// WithNonce configures the nonce value for the UCAN.
44-
func WithNonce(nnc ucan.Nonce) Option {
44+
func WithNonce(nnc []byte) Option {
4545
return func(cfg *delegationConfig) error {
4646
cfg.nnc = nnc
4747
return nil

ucan/invocation/datamodel/cbor_gen.maps.go

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ucan/invocation/datamodel/dag_json_gen.maps.go

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ucan/invocation/datamodel/invocation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type TaskModel struct {
1313
Sub did.DID `cborgen:"sub" dagjsongen:"sub"`
1414
Cmd ucan.Command `cborgen:"cmd" dagjsongen:"cmd"`
1515
Args datamodel.Raw `cborgen:"args" dagjsongen:"args"`
16-
Nonce ucan.Nonce `cborgen:"nonce" dagjsongen:"nonce"`
16+
Nonce []byte `cborgen:"nonce" dagjsongen:"nonce"`
1717
}
1818

1919
type TokenPayloadModel1_0_0_rc1 struct {
@@ -32,7 +32,7 @@ type TokenPayloadModel1_0_0_rc1 struct {
3232
// Arbitrary metadata.
3333
Meta *datamodel.Raw `cborgen:"meta,omitempty" dagjsongen:"meta,omitempty"`
3434
// A unique, random nonce.
35-
Nonce ucan.Nonce `cborgen:"nonce" dagjsongen:"nonce"`
35+
Nonce []byte `cborgen:"nonce" dagjsongen:"nonce"`
3636
// The timestamp at which the invocation becomes invalid.
3737
Exp *ucan.UTCUnixTimestamp `cborgen:"exp" dagjsongen:"exp"`
3838
// The timestamp at which the invocation was created.

ucan/invocation/invocation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func (inv *Invocation) SignedBytes() []byte {
140140
// (such as deterministic Wasm modules or standards-abiding HTTP PUT requests).
141141
//
142142
// https://github.com/ucan-wg/invocation/blob/main/README.md#nonce
143-
func (inv *Invocation) Nonce() ucan.Nonce {
143+
func (inv *Invocation) Nonce() []byte {
144144
return inv.sigPayload.TokenPayload1_0_0_rc1.Nonce
145145
}
146146

0 commit comments

Comments
 (0)