@bcts/gstp 1.0.0-alpha.23 → 1.0.0-beta.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.
- package/dist/index.cjs +130 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +38 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.iife.js +131 -46
- package/dist/index.iife.js.map +1 -1
- package/dist/index.mjs +130 -44
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
- package/src/continuation.ts +81 -41
- package/src/sealed-event.ts +9 -6
- package/src/sealed-request.ts +69 -27
- package/src/sealed-response.ts +7 -6
package/dist/index.d.mts
CHANGED
|
@@ -169,8 +169,10 @@ declare class Continuation {
|
|
|
169
169
|
/**
|
|
170
170
|
* Checks if the continuation is valid at the given time.
|
|
171
171
|
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
172
|
+
* Mirrors Rust `is_valid_date(now)`: at the exact `valid_until`
|
|
173
|
+
* instant, the continuation is **expired** (returns `false`). The
|
|
174
|
+
* earlier port used `<=` here, which differed from Rust by one
|
|
175
|
+
* millisecond at the boundary.
|
|
174
176
|
*
|
|
175
177
|
* @param now - The time to check against, or undefined to skip time validation
|
|
176
178
|
* @returns true if the continuation is valid at the given time
|
|
@@ -197,7 +199,17 @@ declare class Continuation {
|
|
|
197
199
|
/**
|
|
198
200
|
* Converts the continuation to an envelope.
|
|
199
201
|
*
|
|
200
|
-
*
|
|
202
|
+
* Mirrors Rust `Continuation::to_envelope`:
|
|
203
|
+
*
|
|
204
|
+
* ```rust
|
|
205
|
+
* self.state.wrap()
|
|
206
|
+
* .add_optional_assertion(ID, self.valid_id)
|
|
207
|
+
* .add_optional_assertion(VALID_UNTIL, self.valid_until)
|
|
208
|
+
* ```
|
|
209
|
+
*
|
|
210
|
+
* The state is wrapped first; the optional assertions then live on
|
|
211
|
+
* the wrap node. `valid_until` is encoded as a CBOR-tagged Date
|
|
212
|
+
* (tag 1) — never as a plain ISO 8601 string.
|
|
201
213
|
*
|
|
202
214
|
* @param recipient - Optional recipient to encrypt the envelope to
|
|
203
215
|
* @returns The continuation as an envelope
|
|
@@ -206,6 +218,14 @@ declare class Continuation {
|
|
|
206
218
|
/**
|
|
207
219
|
* Parses a continuation from an envelope.
|
|
208
220
|
*
|
|
221
|
+
* Mirrors Rust `Continuation::try_from_envelope`:
|
|
222
|
+
*
|
|
223
|
+
* ```rust
|
|
224
|
+
* state: envelope.try_unwrap()?, // unwrap
|
|
225
|
+
* valid_id: envelope.extract_optional_object_for_predicate(ID)?,
|
|
226
|
+
* valid_until: envelope.extract_optional_object_for_predicate(VALID_UNTIL)?,
|
|
227
|
+
* ```
|
|
228
|
+
*
|
|
209
229
|
* @param encryptedEnvelope - The envelope to parse
|
|
210
230
|
* @param expectedId - Optional ID to validate against
|
|
211
231
|
* @param now - Optional time to validate against
|
|
@@ -341,10 +361,25 @@ declare class SealedRequest implements SealedRequestBehavior {
|
|
|
341
361
|
objectForParameter(param: ParameterID): Envelope | undefined;
|
|
342
362
|
/**
|
|
343
363
|
* Returns all objects for a parameter.
|
|
364
|
+
*
|
|
365
|
+
* Mirrors Rust `SealedRequest::objects_for_parameter` which delegates
|
|
366
|
+
* to `Expression::objects_for_parameter`. GSTP requests can carry
|
|
367
|
+
* multiple parameters with the same ID — e.g. a DKG invite has
|
|
368
|
+
* one `participant` per group member — and a decoder must see
|
|
369
|
+
* every one of them.
|
|
344
370
|
*/
|
|
345
371
|
objectsForParameter(param: ParameterID): Envelope[];
|
|
346
372
|
/**
|
|
347
373
|
* Extracts an object for a parameter as a specific type.
|
|
374
|
+
*
|
|
375
|
+
* Mirrors Rust `SealedRequest::extract_object_for_parameter` — Rust
|
|
376
|
+
* uses a `T: TryFrom<CBOR>` constraint and dispatches to whatever
|
|
377
|
+
* `From<CBOR> for T` impl is in scope (e.g. tag-1 CBOR decodes to
|
|
378
|
+
* `chrono::DateTime`, tag-40012 to `ARID`, etc.). TS lacks that
|
|
379
|
+
* trait dispatch, so we recognise the most common tagged types
|
|
380
|
+
* (`Date` via tag 1, `ARID` via tag 40012) plus the primitive
|
|
381
|
+
* fall-through. Callers needing other typed extraction should use
|
|
382
|
+
* `objectForParameter()` directly and decode the envelope themselves.
|
|
348
383
|
*/
|
|
349
384
|
extractObjectForParameter<T>(param: ParameterID): T;
|
|
350
385
|
/**
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/error.ts","../src/continuation.ts","../src/sealed-request.ts","../src/sealed-response.ts","../src/sealed-event.ts","../src/prelude.ts","../src/index.ts"],"mappings":";;;;;;;;;;;AAcA;;;;;;;aAAY,aAAA;EAcV;EAZA,6BAAA;EAkBA;EAfA,gCAAA;EAqBA;EAlBA,+BAAA;EAkBG;EAfH,oBAAA;EAwBqB;EArBrB,uBAAA;EAsBe;EAnBf,+BAAA;EAsBkB;EAnBlB,yBAAA;EAwCqC;EArCrC,QAAA;EAyDuC;EAtDvC,GAAA;AAAA;;;;;;;cASW,SAAA,SAAkB,KAAA;EAAA,SACpB,IAAA,EAAM,aAAA;EAAA,SACE,KAAA,GAAQ,KAAA;cAEb,IAAA,EAAM,aAAA,EAAe,OAAA,UAAiB,KAAA,GAAQ,KAAA;EAHjD;;;EAAA,OAwBF,0BAAA,CAAA,GAA8B,SAAA;;;;SAU9B,6BAAA,CAAA,GAAiC,SAAA;EA/BkB;;;EAAA,OAyCnD,4BAAA,CAAA,GAAgC,SAAA;EAVhC;;;EAAA,OAoBA,mBAAA,CAAA,GAAuB,SAAA;EAAvB;;;EAAA,OAOA,qBAAA,CAAA,GAAyB,SAAA;EAOzB;;;EAAA,OAAA,4BAAA,CAAA,GAAgC,SAAA;EAoBhC;;;EAAA,OAVA,uBAAA,CAAA,GAA2B,SAAA;EAiB3B;;;EAAA,OAPA,QAAA,CAAS,KAAA,GAAQ,KAAA,GAAQ,SAAA;EAOI;;;EAAA,OAA7B,GAAA,CAAI,KAAA,GAAQ,KAAA,GAAQ,SAAA;AAAA
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/error.ts","../src/continuation.ts","../src/sealed-request.ts","../src/sealed-response.ts","../src/sealed-event.ts","../src/prelude.ts","../src/index.ts"],"mappings":";;;;;;;;;;;AAcA;;;;;;;aAAY,aAAA;EAcV;EAZA,6BAAA;EAkBA;EAfA,gCAAA;EAqBA;EAlBA,+BAAA;EAkBG;EAfH,oBAAA;EAwBqB;EArBrB,uBAAA;EAsBe;EAnBf,+BAAA;EAsBkB;EAnBlB,yBAAA;EAwCqC;EArCrC,QAAA;EAyDuC;EAtDvC,GAAA;AAAA;;;;;;;cASW,SAAA,SAAkB,KAAA;EAAA,SACpB,IAAA,EAAM,aAAA;EAAA,SACE,KAAA,GAAQ,KAAA;cAEb,IAAA,EAAM,aAAA,EAAe,OAAA,UAAiB,KAAA,GAAQ,KAAA;EAHjD;;;EAAA,OAwBF,0BAAA,CAAA,GAA8B,SAAA;;;;SAU9B,6BAAA,CAAA,GAAiC,SAAA;EA/BkB;;;EAAA,OAyCnD,4BAAA,CAAA,GAAgC,SAAA;EAVhC;;;EAAA,OAoBA,mBAAA,CAAA,GAAuB,SAAA;EAAvB;;;EAAA,OAOA,qBAAA,CAAA,GAAyB,SAAA;EAOzB;;;EAAA,OAAA,4BAAA,CAAA,GAAgC,SAAA;EAoBhC;;;EAAA,OAVA,uBAAA,CAAA,GAA2B,SAAA;EAiB3B;;;EAAA,OAPA,QAAA,CAAS,KAAA,GAAQ,KAAA,GAAQ,SAAA;EAOI;;;EAAA,OAA7B,GAAA,CAAI,KAAA,GAAQ,KAAA,GAAQ,SAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;cCzFhB,YAAA;EAAA,iBACM,MAAA;EAAA,iBACA,QAAA;EAAA,iBACA,WAAA;EDeoB;;;;;;;;;cCJzB,KAAA,EAAO,sBAAA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AA;EH/Ef;;;EGsFA,MAAA,CAAA,GAAU,WAAA;EHvEE;;;EG8EZ,KAAA,CAAA,GAAS,QAAA;EHzCT;;;EGgDA,gBAAA,CAAA,GAAoB,QAAA;EHhDA;;;EG2DpB,OAAA,CAAA,GAAW,KAAA,CAAM,CAAA;EHrCkB;;;;;;;;EGqDnC,UAAA,CAAW,UAAA,GAAa,IAAA,EAAM,MAAA,GAAS,MAAA,EAAQ,SAAA,GAAY,WAAA,GAAc,QAAA;EHZvE;;;;;;;;EGyBF,uBAAA,CACE,UAAA,GAAa,IAAA,EACb,MAAA,GAAS,MAAA,EACT,UAAA,GAAa,WAAA,KACZ,QAAA;;;AFvNL;;;;;;;;SE6RS,eAAA,WAA0B,sBAAA,CAAA,CAC/B,iBAAA,EAAmB,QAAA,EACnB,UAAA,EAAY,IAAA,cACZ,GAAA,EAAK,IAAA,cACL,mBAAA,EAAqB,WAAA,EACrB,gBAAA,IAAoB,GAAA,EAAK,QAAA,KAAa,CAAA,GACrC,WAAA,CAAY,CAAA;EFhRgC;;;EEmW/C,QAAA,CAAA;EFpVS;;;EE6VT,MAAA,CAAO,KAAA,EAAO,WAAA,CAAY,CAAA;AAAA;AAAA;;;;;cEvaf,OAAA"}
|
package/dist/index.iife.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var bctsGstp = (function(exports, _bcts_components, _bcts_envelope, _bcts_known_values, _bcts_xid) {
|
|
1
|
+
var bctsGstp = (function(exports, _bcts_components, _bcts_envelope, _bcts_dcbor, _bcts_known_values, _bcts_xid) {
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
//#region \0rolldown/runtime.js
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
@@ -130,7 +130,22 @@ var bctsGstp = (function(exports, _bcts_components, _bcts_envelope, _bcts_known_
|
|
|
130
130
|
* eliminating the need for local state storage and enhancing security
|
|
131
131
|
* for devices with limited storage or requiring distributed state management.
|
|
132
132
|
*
|
|
133
|
-
* Ported from gstp-rust/src/continuation.rs
|
|
133
|
+
* Ported from gstp-rust/src/continuation.rs.
|
|
134
|
+
*
|
|
135
|
+
* Wire shape — mirrors Rust:
|
|
136
|
+
* ```
|
|
137
|
+
* {
|
|
138
|
+
* <state envelope>
|
|
139
|
+
* } [
|
|
140
|
+
* 'id': ARID(...)
|
|
141
|
+
* 'validUntil': Date(...) ← CBOR tag 1, not ISO 8601 text
|
|
142
|
+
* ]
|
|
143
|
+
* ```
|
|
144
|
+
*
|
|
145
|
+
* The `state` envelope is **wrapped** before assertions are attached,
|
|
146
|
+
* matching Rust `self.state.wrap().add_optional_assertion(...)`. The
|
|
147
|
+
* earlier port attached the assertions directly to the un-wrapped state,
|
|
148
|
+
* producing a different digest tree.
|
|
134
149
|
*/
|
|
135
150
|
/**
|
|
136
151
|
* Represents an encrypted state continuation.
|
|
@@ -237,8 +252,10 @@ var bctsGstp = (function(exports, _bcts_components, _bcts_envelope, _bcts_known_
|
|
|
237
252
|
/**
|
|
238
253
|
* Checks if the continuation is valid at the given time.
|
|
239
254
|
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
255
|
+
* Mirrors Rust `is_valid_date(now)`: at the exact `valid_until`
|
|
256
|
+
* instant, the continuation is **expired** (returns `false`). The
|
|
257
|
+
* earlier port used `<=` here, which differed from Rust by one
|
|
258
|
+
* millisecond at the boundary.
|
|
242
259
|
*
|
|
243
260
|
* @param now - The time to check against, or undefined to skip time validation
|
|
244
261
|
* @returns true if the continuation is valid at the given time
|
|
@@ -246,7 +263,7 @@ var bctsGstp = (function(exports, _bcts_components, _bcts_envelope, _bcts_known_
|
|
|
246
263
|
isValidDate(now) {
|
|
247
264
|
if (this._validUntil === void 0) return true;
|
|
248
265
|
if (now === void 0) return true;
|
|
249
|
-
return now.getTime()
|
|
266
|
+
return now.getTime() < this._validUntil.getTime();
|
|
250
267
|
}
|
|
251
268
|
/**
|
|
252
269
|
* Checks if the continuation has the expected ID.
|
|
@@ -275,21 +292,39 @@ var bctsGstp = (function(exports, _bcts_components, _bcts_envelope, _bcts_known_
|
|
|
275
292
|
/**
|
|
276
293
|
* Converts the continuation to an envelope.
|
|
277
294
|
*
|
|
278
|
-
*
|
|
295
|
+
* Mirrors Rust `Continuation::to_envelope`:
|
|
296
|
+
*
|
|
297
|
+
* ```rust
|
|
298
|
+
* self.state.wrap()
|
|
299
|
+
* .add_optional_assertion(ID, self.valid_id)
|
|
300
|
+
* .add_optional_assertion(VALID_UNTIL, self.valid_until)
|
|
301
|
+
* ```
|
|
302
|
+
*
|
|
303
|
+
* The state is wrapped first; the optional assertions then live on
|
|
304
|
+
* the wrap node. `valid_until` is encoded as a CBOR-tagged Date
|
|
305
|
+
* (tag 1) — never as a plain ISO 8601 string.
|
|
279
306
|
*
|
|
280
307
|
* @param recipient - Optional recipient to encrypt the envelope to
|
|
281
308
|
* @returns The continuation as an envelope
|
|
282
309
|
*/
|
|
283
310
|
toEnvelope(recipient) {
|
|
284
|
-
let envelope = this._state;
|
|
311
|
+
let envelope = this._state.wrap();
|
|
285
312
|
if (this._validId !== void 0) envelope = envelope.addAssertion(_bcts_known_values.ID, this._validId);
|
|
286
|
-
if (this._validUntil !== void 0) envelope = envelope.addAssertion(_bcts_known_values.VALID_UNTIL, this._validUntil
|
|
313
|
+
if (this._validUntil !== void 0) envelope = envelope.addAssertion(_bcts_known_values.VALID_UNTIL, _bcts_dcbor.CborDate.fromDatetime(this._validUntil));
|
|
287
314
|
if (recipient !== void 0) envelope = envelope.encryptToRecipients([recipient]);
|
|
288
315
|
return envelope;
|
|
289
316
|
}
|
|
290
317
|
/**
|
|
291
318
|
* Parses a continuation from an envelope.
|
|
292
319
|
*
|
|
320
|
+
* Mirrors Rust `Continuation::try_from_envelope`:
|
|
321
|
+
*
|
|
322
|
+
* ```rust
|
|
323
|
+
* state: envelope.try_unwrap()?, // unwrap
|
|
324
|
+
* valid_id: envelope.extract_optional_object_for_predicate(ID)?,
|
|
325
|
+
* valid_until: envelope.extract_optional_object_for_predicate(VALID_UNTIL)?,
|
|
326
|
+
* ```
|
|
327
|
+
*
|
|
293
328
|
* @param encryptedEnvelope - The envelope to parse
|
|
294
329
|
* @param expectedId - Optional ID to validate against
|
|
295
330
|
* @param now - Optional time to validate against
|
|
@@ -304,23 +339,32 @@ var bctsGstp = (function(exports, _bcts_components, _bcts_envelope, _bcts_known_
|
|
|
304
339
|
} catch (e) {
|
|
305
340
|
throw GstpError.envelope(e instanceof Error ? e : new Error(String(e)));
|
|
306
341
|
}
|
|
307
|
-
|
|
308
|
-
let validId;
|
|
342
|
+
let state;
|
|
309
343
|
try {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
344
|
+
state = envelope.tryUnwrap();
|
|
345
|
+
} catch (e) {
|
|
346
|
+
throw GstpError.envelope(e instanceof Error ? e : new Error(String(e)));
|
|
347
|
+
}
|
|
348
|
+
let validId;
|
|
349
|
+
const idObj = envelope.optionalObjectForPredicate(_bcts_known_values.ID);
|
|
350
|
+
if (idObj !== void 0) {
|
|
351
|
+
const leafCbor = idObj.asLeaf();
|
|
352
|
+
if (leafCbor !== void 0) try {
|
|
353
|
+
validId = _bcts_components.ARID.fromTaggedCbor(leafCbor);
|
|
354
|
+
} catch (e) {
|
|
355
|
+
throw GstpError.envelope(e instanceof Error ? e : new Error(String(e)));
|
|
314
356
|
}
|
|
315
|
-
}
|
|
357
|
+
}
|
|
316
358
|
let validUntil;
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
359
|
+
const validUntilObj = envelope.optionalObjectForPredicate(_bcts_known_values.VALID_UNTIL);
|
|
360
|
+
if (validUntilObj !== void 0) {
|
|
361
|
+
const leafCbor = validUntilObj.asLeaf();
|
|
362
|
+
if (leafCbor !== void 0) try {
|
|
363
|
+
validUntil = _bcts_dcbor.CborDate.fromTaggedCbor(leafCbor).datetime();
|
|
364
|
+
} catch (e) {
|
|
365
|
+
throw GstpError.envelope(e instanceof Error ? e : new Error(String(e)));
|
|
322
366
|
}
|
|
323
|
-
}
|
|
367
|
+
}
|
|
324
368
|
const continuation = new Continuation(state, validId, validUntil);
|
|
325
369
|
if (!continuation.isValidDate(now)) throw GstpError.continuationExpired();
|
|
326
370
|
if (!continuation.isValidId(expectedId)) throw GstpError.continuationIdInvalid();
|
|
@@ -357,6 +401,47 @@ var bctsGstp = (function(exports, _bcts_components, _bcts_envelope, _bcts_known_
|
|
|
357
401
|
//#endregion
|
|
358
402
|
//#region src/sealed-request.ts
|
|
359
403
|
/**
|
|
404
|
+
* Copyright © 2023-2026 Blockchain Commons, LLC
|
|
405
|
+
* Copyright © 2025-2026 Parity Technologies
|
|
406
|
+
*
|
|
407
|
+
*
|
|
408
|
+
* SealedRequest - Sealed request messages for GSTP
|
|
409
|
+
*
|
|
410
|
+
* A SealedRequest wraps a Request with sender information and state
|
|
411
|
+
* continuations for secure, authenticated request messages.
|
|
412
|
+
*
|
|
413
|
+
* Ported from gstp-rust/src/sealed_request.rs
|
|
414
|
+
*/
|
|
415
|
+
/**
|
|
416
|
+
* Decode a CBOR value into a typed JS value.
|
|
417
|
+
*
|
|
418
|
+
* Mirrors the type-driven `T: TryFrom<CBOR>` dispatch Rust's
|
|
419
|
+
* `extract_object_for_parameter` relies on. TS lacks compile-time
|
|
420
|
+
* trait dispatch, so we hand-roll the most common cases:
|
|
421
|
+
* - tag 1 (`Date`) → JS `Date`,
|
|
422
|
+
* - tag 40012 (`ARID`) → `ARID`,
|
|
423
|
+
* - integer / text / bool / number / byte-string primitives,
|
|
424
|
+
* - everything else → the raw `Cbor` value.
|
|
425
|
+
*
|
|
426
|
+
* Callers needing other typed extraction should use
|
|
427
|
+
* `objectForParameter()` directly and decode the envelope themselves.
|
|
428
|
+
*/
|
|
429
|
+
function extractCborAsT(cbor) {
|
|
430
|
+
const tagged = cbor.asTagged();
|
|
431
|
+
if (tagged !== void 0) {
|
|
432
|
+
const [tag] = tagged;
|
|
433
|
+
const tagNumber = Number(tag.value);
|
|
434
|
+
if (tagNumber === 1) return _bcts_dcbor.CborDate.fromTaggedCbor(cbor).datetime();
|
|
435
|
+
if (tagNumber === 40012) return _bcts_components.ARID.fromTaggedCbor(cbor);
|
|
436
|
+
}
|
|
437
|
+
if (cbor.isInteger()) return cbor.toInteger();
|
|
438
|
+
if (cbor.isText()) return cbor.toText();
|
|
439
|
+
if (cbor.isBool()) return cbor.toBool();
|
|
440
|
+
if (cbor.isNumber()) return cbor.toNumber();
|
|
441
|
+
if (cbor.isByteString()) return cbor.toByteString();
|
|
442
|
+
return cbor;
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
360
445
|
* A sealed request that combines a Request with sender information and
|
|
361
446
|
* state continuations for secure communication.
|
|
362
447
|
*
|
|
@@ -448,25 +533,32 @@ var bctsGstp = (function(exports, _bcts_components, _bcts_envelope, _bcts_known_
|
|
|
448
533
|
}
|
|
449
534
|
/**
|
|
450
535
|
* Returns all objects for a parameter.
|
|
536
|
+
*
|
|
537
|
+
* Mirrors Rust `SealedRequest::objects_for_parameter` which delegates
|
|
538
|
+
* to `Expression::objects_for_parameter`. GSTP requests can carry
|
|
539
|
+
* multiple parameters with the same ID — e.g. a DKG invite has
|
|
540
|
+
* one `participant` per group member — and a decoder must see
|
|
541
|
+
* every one of them.
|
|
451
542
|
*/
|
|
452
543
|
objectsForParameter(param) {
|
|
453
|
-
|
|
454
|
-
return obj !== void 0 ? [obj] : [];
|
|
544
|
+
return this._request.body().objectsForParameter(param);
|
|
455
545
|
}
|
|
456
546
|
/**
|
|
457
547
|
* Extracts an object for a parameter as a specific type.
|
|
548
|
+
*
|
|
549
|
+
* Mirrors Rust `SealedRequest::extract_object_for_parameter` — Rust
|
|
550
|
+
* uses a `T: TryFrom<CBOR>` constraint and dispatches to whatever
|
|
551
|
+
* `From<CBOR> for T` impl is in scope (e.g. tag-1 CBOR decodes to
|
|
552
|
+
* `chrono::DateTime`, tag-40012 to `ARID`, etc.). TS lacks that
|
|
553
|
+
* trait dispatch, so we recognise the most common tagged types
|
|
554
|
+
* (`Date` via tag 1, `ARID` via tag 40012) plus the primitive
|
|
555
|
+
* fall-through. Callers needing other typed extraction should use
|
|
556
|
+
* `objectForParameter()` directly and decode the envelope themselves.
|
|
458
557
|
*/
|
|
459
558
|
extractObjectForParameter(param) {
|
|
460
559
|
const envelope = this.objectForParameter(param);
|
|
461
560
|
if (envelope === void 0) throw GstpError.envelope(/* @__PURE__ */ new Error(`Parameter not found: ${param}`));
|
|
462
|
-
return envelope.extractSubject((cbor) =>
|
|
463
|
-
if (cbor.isInteger()) return cbor.toInteger();
|
|
464
|
-
if (cbor.isText()) return cbor.toText();
|
|
465
|
-
if (cbor.isBool()) return cbor.toBool();
|
|
466
|
-
if (cbor.isNumber()) return cbor.toNumber();
|
|
467
|
-
if (cbor.isByteString()) return cbor.toByteString();
|
|
468
|
-
return cbor;
|
|
469
|
-
});
|
|
561
|
+
return envelope.extractSubject((cbor) => extractCborAsT(cbor));
|
|
470
562
|
}
|
|
471
563
|
/**
|
|
472
564
|
* Extracts an optional object for a parameter.
|
|
@@ -474,14 +566,7 @@ var bctsGstp = (function(exports, _bcts_components, _bcts_envelope, _bcts_known_
|
|
|
474
566
|
extractOptionalObjectForParameter(param) {
|
|
475
567
|
const envelope = this.objectForParameter(param);
|
|
476
568
|
if (envelope === void 0) return;
|
|
477
|
-
return envelope.extractSubject((cbor) =>
|
|
478
|
-
if (cbor.isInteger()) return cbor.toInteger();
|
|
479
|
-
if (cbor.isText()) return cbor.toText();
|
|
480
|
-
if (cbor.isBool()) return cbor.toBool();
|
|
481
|
-
if (cbor.isNumber()) return cbor.toNumber();
|
|
482
|
-
if (cbor.isByteString()) return cbor.toByteString();
|
|
483
|
-
return cbor;
|
|
484
|
-
});
|
|
569
|
+
return envelope.extractSubject((cbor) => extractCborAsT(cbor));
|
|
485
570
|
}
|
|
486
571
|
/**
|
|
487
572
|
* Extracts all objects for a parameter as a specific type.
|
|
@@ -613,7 +698,7 @@ var bctsGstp = (function(exports, _bcts_components, _bcts_envelope, _bcts_known_
|
|
|
613
698
|
*/
|
|
614
699
|
toEnvelopeForRecipients(validUntil, signer, recipients) {
|
|
615
700
|
const continuation = new Continuation(this._state ?? _bcts_envelope.Envelope.new(null), this.id(), validUntil);
|
|
616
|
-
const senderEncryptionKey = this._sender.
|
|
701
|
+
const senderEncryptionKey = this._sender.encryptionKey();
|
|
617
702
|
if (senderEncryptionKey === void 0) throw GstpError.senderMissingEncryptionKey();
|
|
618
703
|
const senderContinuation = continuation.toEnvelope(senderEncryptionKey);
|
|
619
704
|
let result = this._request.toEnvelope();
|
|
@@ -655,7 +740,7 @@ var bctsGstp = (function(exports, _bcts_components, _bcts_envelope, _bcts_known_
|
|
|
655
740
|
} catch (e) {
|
|
656
741
|
throw GstpError.xid(e instanceof Error ? e : new Error(String(e)));
|
|
657
742
|
}
|
|
658
|
-
const senderVerificationKey = sender.
|
|
743
|
+
const senderVerificationKey = sender.verificationKey();
|
|
659
744
|
if (senderVerificationKey === void 0) throw GstpError.senderMissingVerificationKey();
|
|
660
745
|
let requestEnvelope;
|
|
661
746
|
try {
|
|
@@ -917,7 +1002,7 @@ var bctsGstp = (function(exports, _bcts_components, _bcts_envelope, _bcts_known_
|
|
|
917
1002
|
let senderContinuation;
|
|
918
1003
|
if (this._state !== void 0) {
|
|
919
1004
|
const continuation = new Continuation(this._state, void 0, validUntil);
|
|
920
|
-
const senderEncryptionKey = this._sender.
|
|
1005
|
+
const senderEncryptionKey = this._sender.encryptionKey();
|
|
921
1006
|
if (senderEncryptionKey === void 0) throw GstpError.senderMissingEncryptionKey();
|
|
922
1007
|
senderContinuation = continuation.toEnvelope(senderEncryptionKey);
|
|
923
1008
|
}
|
|
@@ -960,7 +1045,7 @@ var bctsGstp = (function(exports, _bcts_components, _bcts_envelope, _bcts_known_
|
|
|
960
1045
|
} catch (e) {
|
|
961
1046
|
throw GstpError.xid(e instanceof Error ? e : new Error(String(e)));
|
|
962
1047
|
}
|
|
963
|
-
const senderVerificationKey = sender.
|
|
1048
|
+
const senderVerificationKey = sender.verificationKey();
|
|
964
1049
|
if (senderVerificationKey === void 0) throw GstpError.senderMissingVerificationKey();
|
|
965
1050
|
let responseEnvelope;
|
|
966
1051
|
try {
|
|
@@ -1179,7 +1264,7 @@ var bctsGstp = (function(exports, _bcts_components, _bcts_envelope, _bcts_known_
|
|
|
1179
1264
|
* @returns The sealed event as an envelope
|
|
1180
1265
|
*/
|
|
1181
1266
|
toEnvelopeForRecipients(validUntil, signer, recipients) {
|
|
1182
|
-
const senderEncryptionKey = this._sender.
|
|
1267
|
+
const senderEncryptionKey = this._sender.encryptionKey();
|
|
1183
1268
|
if (senderEncryptionKey === void 0) throw GstpError.senderMissingEncryptionKey();
|
|
1184
1269
|
let senderContinuation;
|
|
1185
1270
|
if (this._state !== void 0) senderContinuation = new Continuation(this._state, void 0, validUntil).toEnvelope(senderEncryptionKey);
|
|
@@ -1224,7 +1309,7 @@ var bctsGstp = (function(exports, _bcts_components, _bcts_envelope, _bcts_known_
|
|
|
1224
1309
|
} catch (e) {
|
|
1225
1310
|
throw GstpError.xid(e instanceof Error ? e : new Error(String(e)));
|
|
1226
1311
|
}
|
|
1227
|
-
const senderVerificationKey = sender.
|
|
1312
|
+
const senderVerificationKey = sender.verificationKey();
|
|
1228
1313
|
if (senderVerificationKey === void 0) throw GstpError.senderMissingVerificationKey();
|
|
1229
1314
|
let eventEnvelope;
|
|
1230
1315
|
try {
|
|
@@ -1299,6 +1384,6 @@ var bctsGstp = (function(exports, _bcts_components, _bcts_envelope, _bcts_known_
|
|
|
1299
1384
|
}
|
|
1300
1385
|
});
|
|
1301
1386
|
return exports;
|
|
1302
|
-
})({}, bctsComponents, bctsEnvelope, bctsKnownValues, bctsXid);
|
|
1387
|
+
})({}, bctsComponents, bctsEnvelope, bctsDcbor, bctsKnownValues, bctsXid);
|
|
1303
1388
|
|
|
1304
1389
|
//# sourceMappingURL=index.iife.js.map
|