@tinycloud/node-sdk 3.1.0-beta.13 → 3.1.0-beta.15
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/{core-CMDgVfBj.d.cts → core-AEx5vAa8.d.cts} +17 -0
- package/dist/{core-CMDgVfBj.d.ts → core-AEx5vAa8.d.ts} +17 -0
- package/dist/core.cjs +46 -26
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +1 -1
- package/dist/core.d.ts +1 -1
- package/dist/core.js +46 -26
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +46 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +46 -26
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -1201,12 +1201,25 @@ interface TinyCloudNodeConfig {
|
|
|
1201
1201
|
* delegation through the legacy wallet-signed SIWE path, which always
|
|
1202
1202
|
* triggers a wallet prompt. Used for testing, for explicit wallet
|
|
1203
1203
|
* confirmation flows, and by the legacy `createDelegation` fallback.
|
|
1204
|
+
*
|
|
1205
|
+
* `onPrepared` runs after the delegation is fully built and signed (CID
|
|
1206
|
+
* included) and before it is activated with the host. It receives the same
|
|
1207
|
+
* `PortableDelegation` object that `delegateTo` returns as
|
|
1208
|
+
* `result.delegation`, so callers can durably record the grant before it
|
|
1209
|
+
* goes live. If the hook rejects, the delegation is not activated and
|
|
1210
|
+
* `delegateTo` rejects with the same error. It cannot be combined with
|
|
1211
|
+
* `forceWalletSign`, whose wallet path activates as part of signing.
|
|
1204
1212
|
*/
|
|
1205
1213
|
interface DelegateToOptions {
|
|
1206
1214
|
/** Override expiry. ms-format string ("7d", "1h") or raw milliseconds. */
|
|
1207
1215
|
expiry?: string | number;
|
|
1208
1216
|
/** Force the wallet-signed SIWE path even if the caps are derivable. Default false. */
|
|
1209
1217
|
forceWalletSign?: boolean;
|
|
1218
|
+
/**
|
|
1219
|
+
* Called with the prepared delegation before host activation. A rejection
|
|
1220
|
+
* aborts activation and propagates from `delegateTo`.
|
|
1221
|
+
*/
|
|
1222
|
+
onPrepared?: (prepared: PortableDelegation) => Promise<void>;
|
|
1210
1223
|
}
|
|
1211
1224
|
/**
|
|
1212
1225
|
* Result of {@link TinyCloudNode.delegateTo}.
|
|
@@ -2253,6 +2266,10 @@ declare class TinyCloudNode {
|
|
|
2253
2266
|
* @throws {@link PermissionNotInManifestError} when any requested
|
|
2254
2267
|
* entry is not a subset of the granted session capabilities and
|
|
2255
2268
|
* `forceWalletSign` is not set.
|
|
2269
|
+
* @throws when `onPrepared` is combined with `forceWalletSign: true`,
|
|
2270
|
+
* before anything is signed.
|
|
2271
|
+
* @throws the `onPrepared` rejection, unchanged, without activating the
|
|
2272
|
+
* delegation.
|
|
2256
2273
|
*/
|
|
2257
2274
|
delegateTo(did: string, permissions: PermissionEntry[], options?: DelegateToOptions): Promise<DelegateToResult>;
|
|
2258
2275
|
/**
|
|
@@ -1201,12 +1201,25 @@ interface TinyCloudNodeConfig {
|
|
|
1201
1201
|
* delegation through the legacy wallet-signed SIWE path, which always
|
|
1202
1202
|
* triggers a wallet prompt. Used for testing, for explicit wallet
|
|
1203
1203
|
* confirmation flows, and by the legacy `createDelegation` fallback.
|
|
1204
|
+
*
|
|
1205
|
+
* `onPrepared` runs after the delegation is fully built and signed (CID
|
|
1206
|
+
* included) and before it is activated with the host. It receives the same
|
|
1207
|
+
* `PortableDelegation` object that `delegateTo` returns as
|
|
1208
|
+
* `result.delegation`, so callers can durably record the grant before it
|
|
1209
|
+
* goes live. If the hook rejects, the delegation is not activated and
|
|
1210
|
+
* `delegateTo` rejects with the same error. It cannot be combined with
|
|
1211
|
+
* `forceWalletSign`, whose wallet path activates as part of signing.
|
|
1204
1212
|
*/
|
|
1205
1213
|
interface DelegateToOptions {
|
|
1206
1214
|
/** Override expiry. ms-format string ("7d", "1h") or raw milliseconds. */
|
|
1207
1215
|
expiry?: string | number;
|
|
1208
1216
|
/** Force the wallet-signed SIWE path even if the caps are derivable. Default false. */
|
|
1209
1217
|
forceWalletSign?: boolean;
|
|
1218
|
+
/**
|
|
1219
|
+
* Called with the prepared delegation before host activation. A rejection
|
|
1220
|
+
* aborts activation and propagates from `delegateTo`.
|
|
1221
|
+
*/
|
|
1222
|
+
onPrepared?: (prepared: PortableDelegation) => Promise<void>;
|
|
1210
1223
|
}
|
|
1211
1224
|
/**
|
|
1212
1225
|
* Result of {@link TinyCloudNode.delegateTo}.
|
|
@@ -2253,6 +2266,10 @@ declare class TinyCloudNode {
|
|
|
2253
2266
|
* @throws {@link PermissionNotInManifestError} when any requested
|
|
2254
2267
|
* entry is not a subset of the granted session capabilities and
|
|
2255
2268
|
* `forceWalletSign` is not set.
|
|
2269
|
+
* @throws when `onPrepared` is combined with `forceWalletSign: true`,
|
|
2270
|
+
* before anything is signed.
|
|
2271
|
+
* @throws the `onPrepared` rejection, unchanged, without activating the
|
|
2272
|
+
* delegation.
|
|
2256
2273
|
*/
|
|
2257
2274
|
delegateTo(did: string, permissions: PermissionEntry[], options?: DelegateToOptions): Promise<DelegateToResult>;
|
|
2258
2275
|
/**
|
package/dist/core.cjs
CHANGED
|
@@ -6425,8 +6425,18 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6425
6425
|
* @throws {@link PermissionNotInManifestError} when any requested
|
|
6426
6426
|
* entry is not a subset of the granted session capabilities and
|
|
6427
6427
|
* `forceWalletSign` is not set.
|
|
6428
|
+
* @throws when `onPrepared` is combined with `forceWalletSign: true`,
|
|
6429
|
+
* before anything is signed.
|
|
6430
|
+
* @throws the `onPrepared` rejection, unchanged, without activating the
|
|
6431
|
+
* delegation.
|
|
6428
6432
|
*/
|
|
6429
6433
|
async delegateTo(did, permissions, options) {
|
|
6434
|
+
const onPrepared = options?.onPrepared;
|
|
6435
|
+
if (onPrepared && options?.forceWalletSign) {
|
|
6436
|
+
throw new Error(
|
|
6437
|
+
"delegateTo: onPrepared cannot be combined with forceWalletSign=true; the wallet-signed path activates the delegation before it could be handed to onPrepared."
|
|
6438
|
+
);
|
|
6439
|
+
}
|
|
6430
6440
|
const session = this.currentTinyCloudSession();
|
|
6431
6441
|
if (!session) {
|
|
6432
6442
|
throw new import_sdk_core8.SessionExpiredError(/* @__PURE__ */ new Date(0));
|
|
@@ -6485,7 +6495,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6485
6495
|
expandedEntries,
|
|
6486
6496
|
runtimeExpiration,
|
|
6487
6497
|
runtimeGrant,
|
|
6488
|
-
runtimeOperations
|
|
6498
|
+
runtimeOperations,
|
|
6499
|
+
onPrepared
|
|
6489
6500
|
);
|
|
6490
6501
|
return { delegation: delegation2, prompted: false };
|
|
6491
6502
|
}
|
|
@@ -6495,7 +6506,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6495
6506
|
did,
|
|
6496
6507
|
expandedEntries,
|
|
6497
6508
|
effectiveExpiration,
|
|
6498
|
-
session
|
|
6509
|
+
session,
|
|
6510
|
+
onPrepared
|
|
6499
6511
|
);
|
|
6500
6512
|
return { delegation, prompted: false };
|
|
6501
6513
|
}
|
|
@@ -6549,7 +6561,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6549
6561
|
*
|
|
6550
6562
|
* @internal
|
|
6551
6563
|
*/
|
|
6552
|
-
async createDelegationViaWasmPath(did, entries, expirationTime, session) {
|
|
6564
|
+
async createDelegationViaWasmPath(did, entries, expirationTime, session, onPrepared) {
|
|
6553
6565
|
if (entries.length === 0) {
|
|
6554
6566
|
throw new Error(
|
|
6555
6567
|
"createDelegationViaWasmPath requires a non-empty entries array"
|
|
@@ -6612,17 +6624,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6612
6624
|
});
|
|
6613
6625
|
const primary = result.resources[0];
|
|
6614
6626
|
const delegationHeader = { Authorization: result.delegation };
|
|
6615
|
-
const
|
|
6616
|
-
this.config.host,
|
|
6617
|
-
delegationHeader
|
|
6618
|
-
);
|
|
6619
|
-
if (!activateResult.success) {
|
|
6620
|
-
throw Object.assign(
|
|
6621
|
-
new Error(`Failed to activate delegation with host: ${describeHostFailure2(activateResult)}`),
|
|
6622
|
-
{ cause: activateResult }
|
|
6623
|
-
);
|
|
6624
|
-
}
|
|
6625
|
-
return {
|
|
6627
|
+
const delegation = {
|
|
6626
6628
|
cid: result.cid,
|
|
6627
6629
|
delegationHeader,
|
|
6628
6630
|
spaceId,
|
|
@@ -6636,8 +6638,22 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6636
6638
|
chainId: session.chainId,
|
|
6637
6639
|
host: this.config.host
|
|
6638
6640
|
};
|
|
6641
|
+
if (onPrepared) {
|
|
6642
|
+
await onPrepared(delegation);
|
|
6643
|
+
}
|
|
6644
|
+
const activateResult = await (0, import_sdk_core8.activateSessionWithHost)(
|
|
6645
|
+
this.config.host,
|
|
6646
|
+
delegationHeader
|
|
6647
|
+
);
|
|
6648
|
+
if (!activateResult.success) {
|
|
6649
|
+
throw Object.assign(
|
|
6650
|
+
new Error(`Failed to activate delegation with host: ${describeHostFailure2(activateResult)}`),
|
|
6651
|
+
{ cause: activateResult }
|
|
6652
|
+
);
|
|
6653
|
+
}
|
|
6654
|
+
return delegation;
|
|
6639
6655
|
}
|
|
6640
|
-
async createDelegationViaRuntimeGrant(did, entries, expirationTime, grant, requestedOperations) {
|
|
6656
|
+
async createDelegationViaRuntimeGrant(did, entries, expirationTime, grant, requestedOperations, onPrepared) {
|
|
6641
6657
|
this.assertRuntimeGrantCaveatsPreservable(entries, requestedOperations, grant);
|
|
6642
6658
|
this.assertDelegationCaveatsPreservable(entries);
|
|
6643
6659
|
const result = this.createDelegationWrapper({
|
|
@@ -6650,17 +6666,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6650
6666
|
const primary = result.resources[0];
|
|
6651
6667
|
const delegationHeader = { Authorization: result.delegation };
|
|
6652
6668
|
const targetHost = grant.delegation.host ?? this.config.host;
|
|
6653
|
-
const
|
|
6654
|
-
targetHost,
|
|
6655
|
-
delegationHeader
|
|
6656
|
-
);
|
|
6657
|
-
if (!activateResult.success) {
|
|
6658
|
-
throw Object.assign(
|
|
6659
|
-
new Error(`Failed to activate delegation with host: ${describeHostFailure2(activateResult)}`),
|
|
6660
|
-
{ cause: activateResult }
|
|
6661
|
-
);
|
|
6662
|
-
}
|
|
6663
|
-
return {
|
|
6669
|
+
const delegation = {
|
|
6664
6670
|
cid: result.cid,
|
|
6665
6671
|
delegationHeader,
|
|
6666
6672
|
spaceId: grant.session.spaceId,
|
|
@@ -6674,6 +6680,20 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6674
6680
|
chainId: grant.delegation.chainId,
|
|
6675
6681
|
host: targetHost
|
|
6676
6682
|
};
|
|
6683
|
+
if (onPrepared) {
|
|
6684
|
+
await onPrepared(delegation);
|
|
6685
|
+
}
|
|
6686
|
+
const activateResult = await (0, import_sdk_core8.activateSessionWithHost)(
|
|
6687
|
+
targetHost,
|
|
6688
|
+
delegationHeader
|
|
6689
|
+
);
|
|
6690
|
+
if (!activateResult.success) {
|
|
6691
|
+
throw Object.assign(
|
|
6692
|
+
new Error(`Failed to activate delegation with host: ${describeHostFailure2(activateResult)}`),
|
|
6693
|
+
{ cause: activateResult }
|
|
6694
|
+
);
|
|
6695
|
+
}
|
|
6696
|
+
return delegation;
|
|
6677
6697
|
}
|
|
6678
6698
|
resolvePermissionSpace(space, session) {
|
|
6679
6699
|
if (space === void 0) {
|