@tinycloud/node-sdk 2.6.4-beta.1 → 2.7.0-beta.2
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-BVk0VwGe.d.cts → core-BfqzTbfY.d.cts} +27 -2
- package/dist/{core-BVk0VwGe.d.ts → core-BfqzTbfY.d.ts} +27 -2
- package/dist/core.cjs +92 -43
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +2 -2
- package/dist/core.d.ts +2 -2
- package/dist/core.js +92 -43
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +92 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +92 -43
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -18697,6 +18697,22 @@ var ROOT_DELEGATION_ACTIONS = [
|
|
|
18697
18697
|
import_sdk_core7.DUCKDB.ALL
|
|
18698
18698
|
];
|
|
18699
18699
|
var DEFAULT_SESSION_EXPIRATION_MS = import_sdk_core7.EXPIRY.SESSION_MS;
|
|
18700
|
+
function decodeAuthorizationBytes(authorization) {
|
|
18701
|
+
const encoded = authorization.replace(/^Bearer /i, "");
|
|
18702
|
+
const match = /^([A-Za-z0-9_-]+)(={1,2})?$/.exec(encoded);
|
|
18703
|
+
const unpadded = match?.[1];
|
|
18704
|
+
const paddingLength = match?.[2]?.length ?? 0;
|
|
18705
|
+
const remainder = unpadded === void 0 ? 1 : unpadded.length % 4;
|
|
18706
|
+
const expectedPaddingLength = remainder === 2 ? 2 : remainder === 3 ? 1 : 0;
|
|
18707
|
+
if (unpadded === void 0 || remainder === 1 || paddingLength !== 0 && paddingLength !== expectedPaddingLength) {
|
|
18708
|
+
throw new Error("Delegation Authorization is not canonical base64url DAG-CBOR");
|
|
18709
|
+
}
|
|
18710
|
+
const decoded = Uint8Array.from(Buffer.from(unpadded, "base64url"));
|
|
18711
|
+
if (Buffer.from(decoded).toString("base64url") !== unpadded) {
|
|
18712
|
+
throw new Error("Delegation Authorization is not canonical base64url DAG-CBOR");
|
|
18713
|
+
}
|
|
18714
|
+
return decoded;
|
|
18715
|
+
}
|
|
18700
18716
|
function isOpenKeyAutoSignStrategy(strategy) {
|
|
18701
18717
|
return strategy?.openKeyAutoSign === true;
|
|
18702
18718
|
}
|
|
@@ -18921,6 +18937,11 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18921
18937
|
fetch: globalThis.fetch.bind(globalThis),
|
|
18922
18938
|
keyProvider: this._keyProvider,
|
|
18923
18939
|
registry: this._capabilityRegistry,
|
|
18940
|
+
createDelegationWasm: (params) => this.createDelegationWrapper(params),
|
|
18941
|
+
computeCid: (data, codec) => {
|
|
18942
|
+
if (!this.wasmBindings.computeCid) throw new Error("computeCid is unavailable");
|
|
18943
|
+
return this.wasmBindings.computeCid(data, codec);
|
|
18944
|
+
},
|
|
18924
18945
|
// delegationManager: undefined - not needed for receive()
|
|
18925
18946
|
createKVService: (config2) => {
|
|
18926
18947
|
const prefix = config2.pathPrefix?.replace(/\/$/, "");
|
|
@@ -20391,6 +20412,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20391
20412
|
hosts: [this.config.host],
|
|
20392
20413
|
session: serviceSession,
|
|
20393
20414
|
invoke: this.invokeWithRuntimePermissions,
|
|
20415
|
+
invokeAny: this.invokeAnyWithRuntimePermissions,
|
|
20394
20416
|
fetch: globalThis.fetch.bind(globalThis)
|
|
20395
20417
|
});
|
|
20396
20418
|
this._spaceService = new import_sdk_core7.SpaceService({
|
|
@@ -20528,56 +20550,69 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20528
20550
|
* with expiry longer than the current session.
|
|
20529
20551
|
* @internal
|
|
20530
20552
|
*/
|
|
20531
|
-
async
|
|
20532
|
-
if (!
|
|
20533
|
-
|
|
20553
|
+
async createOwnerDelegation(params) {
|
|
20554
|
+
if (!params.delegateDid.startsWith("did:key:") || params.actions.length === 0 || params.path.length === 0) {
|
|
20555
|
+
throw new Error("Owner delegation requires an external did:key audience and bounded capabilities");
|
|
20534
20556
|
}
|
|
20557
|
+
const now = /* @__PURE__ */ new Date();
|
|
20558
|
+
if (params.expiresAt.getTime() <= now.getTime() || params.expiresAt.getTime() - now.getTime() > import_sdk_core7.EXPIRY.MAX_MS) {
|
|
20559
|
+
throw new Error("Owner delegation expiry must be explicit, future, and within EXPIRY.MAX_MS");
|
|
20560
|
+
}
|
|
20561
|
+
if (!this.signer) throw new Error("Owner wallet signer is required");
|
|
20535
20562
|
const session = this.currentTinyCloudSession();
|
|
20536
|
-
if (!session)
|
|
20537
|
-
|
|
20563
|
+
if (!session) throw new Error("Owner session is required");
|
|
20564
|
+
const abilities = sharingActionsToAbilities(params.path, [...params.actions]);
|
|
20565
|
+
if (!abilities) throw new Error("Owner delegation capabilities are unsupported");
|
|
20566
|
+
const host = this.config.host;
|
|
20567
|
+
const prepared = this.wasmBindings.prepareSession({
|
|
20568
|
+
abilities,
|
|
20569
|
+
address: this.wasmBindings.ensureEip55(session.address),
|
|
20570
|
+
chainId: session.chainId,
|
|
20571
|
+
domain: this.siweDomain,
|
|
20572
|
+
issuedAt: now.toISOString(),
|
|
20573
|
+
expirationTime: params.expiresAt.toISOString(),
|
|
20574
|
+
spaceId: params.spaceId,
|
|
20575
|
+
delegateUri: params.delegateDid
|
|
20576
|
+
});
|
|
20577
|
+
const signature2 = await this.signer.signMessage(prepared.siwe);
|
|
20578
|
+
const delegationSession = this.wasmBindings.completeSessionSetup({ ...prepared, signature: signature2 });
|
|
20579
|
+
const activation = await (0, import_sdk_core7.activateSessionWithHost)(host, delegationSession.delegationHeader);
|
|
20580
|
+
if (!activation.success) {
|
|
20581
|
+
throw new Error(`Owner delegation import failed: ${activation.status} ${activation.error ?? ""}`.trim());
|
|
20538
20582
|
}
|
|
20539
|
-
|
|
20540
|
-
|
|
20541
|
-
|
|
20542
|
-
|
|
20543
|
-
|
|
20544
|
-
|
|
20545
|
-
|
|
20546
|
-
|
|
20547
|
-
|
|
20548
|
-
|
|
20549
|
-
|
|
20550
|
-
|
|
20551
|
-
|
|
20552
|
-
|
|
20553
|
-
|
|
20554
|
-
|
|
20555
|
-
|
|
20556
|
-
|
|
20557
|
-
|
|
20558
|
-
|
|
20559
|
-
|
|
20560
|
-
});
|
|
20561
|
-
const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
|
|
20562
|
-
host,
|
|
20563
|
-
delegationSession.delegationHeader
|
|
20564
|
-
);
|
|
20565
|
-
if (!activateResult.success) {
|
|
20566
|
-
return void 0;
|
|
20583
|
+
const delegation = {
|
|
20584
|
+
cid: delegationSession.delegationCid,
|
|
20585
|
+
delegateDID: params.delegateDid,
|
|
20586
|
+
delegatorDID: (0, import_sdk_core7.pkhDid)(session.address, session.chainId),
|
|
20587
|
+
spaceId: params.spaceId,
|
|
20588
|
+
path: params.path,
|
|
20589
|
+
actions: [...params.actions],
|
|
20590
|
+
expiry: params.expiresAt,
|
|
20591
|
+
isRevoked: false,
|
|
20592
|
+
allowSubDelegation: true,
|
|
20593
|
+
createdAt: now,
|
|
20594
|
+
authHeader: delegationSession.delegationHeader.Authorization
|
|
20595
|
+
};
|
|
20596
|
+
return {
|
|
20597
|
+
delegation,
|
|
20598
|
+
signedDagCbor: decodeAuthorizationBytes(delegationSession.delegationHeader.Authorization),
|
|
20599
|
+
delegationCid: delegationSession.delegationCid,
|
|
20600
|
+
nodeReceipt: {
|
|
20601
|
+
commitEventCid: activation.commitEventCid,
|
|
20602
|
+
activated: activation.activated ?? [],
|
|
20603
|
+
skipped: activation.skipped ?? []
|
|
20567
20604
|
}
|
|
20568
|
-
|
|
20569
|
-
|
|
20570
|
-
|
|
20571
|
-
|
|
20605
|
+
};
|
|
20606
|
+
}
|
|
20607
|
+
async createRootDelegationForSharing(params) {
|
|
20608
|
+
try {
|
|
20609
|
+
return (await this.createOwnerDelegation({
|
|
20610
|
+
delegateDid: params.shareKeyDID,
|
|
20572
20611
|
spaceId: params.spaceId,
|
|
20573
20612
|
path: params.path,
|
|
20574
20613
|
actions: params.actions,
|
|
20575
|
-
|
|
20576
|
-
|
|
20577
|
-
allowSubDelegation: true,
|
|
20578
|
-
createdAt: now,
|
|
20579
|
-
authHeader: delegationSession.delegationHeader.Authorization
|
|
20580
|
-
};
|
|
20614
|
+
expiresAt: params.requestedExpiry
|
|
20615
|
+
})).delegation;
|
|
20581
20616
|
} catch {
|
|
20582
20617
|
return void 0;
|
|
20583
20618
|
}
|
|
@@ -21345,6 +21380,20 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21345
21380
|
async revokeDelegation(cid) {
|
|
21346
21381
|
return this.delegationManager.revoke(cid);
|
|
21347
21382
|
}
|
|
21383
|
+
/** Read node-confirmed lifecycle state for one delegation. */
|
|
21384
|
+
async getDelegationStatus(cid) {
|
|
21385
|
+
return this.delegationManager.status(cid);
|
|
21386
|
+
}
|
|
21387
|
+
/** Compute the canonical CID of a compact delegation authorization. */
|
|
21388
|
+
computeDelegationCid(authorization) {
|
|
21389
|
+
if (!authorization || !this.wasmBindings.computeCid) {
|
|
21390
|
+
throw new Error("Delegation CID computation is unavailable");
|
|
21391
|
+
}
|
|
21392
|
+
return this.wasmBindings.computeCid(
|
|
21393
|
+
new TextEncoder().encode(authorization),
|
|
21394
|
+
0x55n
|
|
21395
|
+
);
|
|
21396
|
+
}
|
|
21348
21397
|
/**
|
|
21349
21398
|
* List all delegations for the current session's space.
|
|
21350
21399
|
*
|