iso-ucan 0.5.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"invocation.d.ts","sourceRoot":"","sources":["../../src/invocation.js"],"names":[],"mappings":"AA6OA;;;;GAIG;AACH,sCAHW,OAAO,YAAY,EAAE,iBAAiB,UACtC,UAAU,EAAE,WA6DtB;AA3RD;;;GAGG;AAEH;;GAEG;AACH;IAuCE;;;OAGG;IACH,qBAFW,OAAO,YAAY,EAAE,qBAAqB,uBAgEpD;IAED;;OAEG;IACH,uBAFW,OAAO,YAAY,EAAE,iBAAiB,uBAgEhD;IAtJD;;;;;;;OAOG;IACH,sBANW,OAAO,YAAY,EAAE,eAAe,CAAC,KAAK,CAAC,SAC3C,UAAU,OACV,GAAG,eACH,UAAU,EAAE,aACZ,MAAM,EAShB;IApCD;;OAEG;IACH,aAFU,UAAU,EAAE,CAEX;IAEX;;OAEG;IACH,KAFU,GAAG,CAEV;IAEH;;;;;;;;OAQG;IACH,WAFU,MAAM,CAEP;IAWP,sDAAwB;IACxB,gDAA+B;IAC/B,mCAAkB;CA4IrB;gCApL4B,iBAAiB;yBACxB,cAAc"}
1
+ {"version":3,"file":"invocation.d.ts","sourceRoot":"","sources":["../../src/invocation.js"],"names":[],"mappings":"AAmPA;;;;GAIG;AACH,sCAHW,OAAO,YAAY,EAAE,iBAAiB,UACtC,UAAU,EAAE,WA6DtB;AAjSD;;;GAGG;AAEH;;GAEG;AACH;IAuCE;;;OAGG;IACH,qBAFW,OAAO,YAAY,EAAE,qBAAqB,uBA6DpD;IAED;;OAEG;IACH,uBAFW,OAAO,YAAY,EAAE,iBAAiB,uBAmEhD;IAtJD;;;;;;;OAOG;IACH,sBANW,OAAO,YAAY,EAAE,eAAe,CAAC,KAAK,CAAC,SAC3C,UAAU,OACV,GAAG,eACH,UAAU,EAAE,aACZ,MAAM,EAShB;IApCD;;OAEG;IACH,aAFU,UAAU,EAAE,CAEX;IAEX;;OAEG;IACH,KAFU,GAAG,CAEV;IAEH;;;;;;;;OAQG;IACH,WAFU,MAAM,CAEP;IAWP,sDAAwB;IACxB,gDAA+B;IAC/B,mCAAkB;CA4IrB;gCApL4B,iBAAiB;yBACxB,cAAc"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "iso-ucan",
3
3
  "type": "module",
4
- "version": "0.5.2",
4
+ "version": "1.0.0",
5
5
  "description": "Isomorphic UCAN",
6
6
  "author": "Hugo Dias <hugomrdias@gmail.com> (hugodias.me)",
7
7
  "license": "MIT",
@@ -109,7 +109,7 @@
109
109
  "iso-base": "^4.4.0",
110
110
  "iso-did": "^3.0.0",
111
111
  "iso-kv": "^3.2.0",
112
- "iso-signatures": "^0.5.2",
112
+ "iso-signatures": "^0.6.0",
113
113
  "iso-web": "^4.0.0",
114
114
  "it-merge": "^3.0.15",
115
115
  "multiformats": "^14.0.5",
package/src/invocation.js CHANGED
@@ -79,14 +79,11 @@ export class Invocation {
79
79
  `Invalid envelope type. Expected "inv" but got "${envelope.spec}"`
80
80
  )
81
81
  }
82
- // Audience or subject must match receiver
83
- if (
84
- audience &&
85
- envelope.payload.aud !== audience.did &&
86
- envelope.payload.sub !== audience.did
87
- ) {
82
+ // The executor is `aud` when present, otherwise `sub`
83
+ const executor = envelope.payload.aud ?? envelope.payload.sub
84
+ if (audience && executor !== audience.did) {
88
85
  throw new TypeError(
89
- `UCAN Invocation audience or subject does not match receiver. Expected: ${audience.did} but got: ${envelope.payload.aud ?? envelope.payload.sub ?? 'null'}`
86
+ `UCAN Invocation audience does not match receiver. Expected: ${audience.did} but got: ${executor ?? 'null'}`
90
87
  )
91
88
  }
92
89
 
@@ -140,7 +137,6 @@ export class Invocation {
140
137
  /** @type {import("./types.js").InvocationPayload} */
141
138
  const payload = {
142
139
  iss: options.iss.toString(),
143
- aud: options.aud ? options.aud : options.sub,
144
140
  sub: options.sub,
145
141
  cmd: options.cmd,
146
142
  nonce,
@@ -148,6 +144,10 @@ export class Invocation {
148
144
  args: options.args,
149
145
  prf: options.prf.map((p) => p.cid),
150
146
  }
147
+ // `aud` MUST be omitted when the executor is the subject
148
+ if (options.aud && options.aud !== options.sub) {
149
+ payload.aud = options.aud
150
+ }
151
151
  if (options.cause) {
152
152
  payload.cause = options.cause
153
153
  }
@@ -226,6 +226,12 @@ function assertStructure(payload) {
226
226
 
227
227
  if (payload.aud) {
228
228
  didParse(payload.aud)
229
+ // Spec: `aud` MUST be omitted when the executor is the subject
230
+ if (payload.aud === payload.sub) {
231
+ throw new TypeError(
232
+ 'UCAN Invocation audience must be omitted when it equals the subject'
233
+ )
234
+ }
229
235
  }
230
236
 
231
237
  assertIsValidCommand(payload.cmd)