@tinycloud/node-sdk 2.10.0 → 2.11.0-beta.1
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-B_i2KfID.d.cts → core-CQ_5wXQT.d.cts} +3 -13
- package/dist/{core-B_i2KfID.d.ts → core-CQ_5wXQT.d.ts} +3 -13
- package/dist/core.cjs +94 -17
- 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 +94 -17
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +94 -17
- 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 +94 -17
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -18913,19 +18913,87 @@ function persistedExpiry(value) {
|
|
|
18913
18913
|
function sameInstant(left, right) {
|
|
18914
18914
|
return left.getTime() === right.getTime();
|
|
18915
18915
|
}
|
|
18916
|
-
function
|
|
18917
|
-
|
|
18916
|
+
function ownerDelegationPermissions(params) {
|
|
18917
|
+
const hasPermissions = Object.prototype.hasOwnProperty.call(params, "permissions");
|
|
18918
|
+
const hasLegacy = Object.prototype.hasOwnProperty.call(params, "path") || Object.prototype.hasOwnProperty.call(params, "actions");
|
|
18919
|
+
if (hasPermissions === hasLegacy) {
|
|
18920
|
+
throw new Error("Owner delegation requires exactly one authority shape: path/actions or permissions");
|
|
18921
|
+
}
|
|
18922
|
+
const permissions = [];
|
|
18923
|
+
if (hasPermissions) {
|
|
18924
|
+
if (!Array.isArray(params.permissions)) {
|
|
18925
|
+
throw new Error("Owner delegation permissions are invalid");
|
|
18926
|
+
}
|
|
18927
|
+
permissions.push(...params.permissions.map((permission) => ({
|
|
18928
|
+
service: permission.service,
|
|
18929
|
+
path: permission.path,
|
|
18930
|
+
actions: [...permission.actions]
|
|
18931
|
+
})));
|
|
18932
|
+
} else {
|
|
18933
|
+
if (typeof params.path !== "string" || !Array.isArray(params.actions)) {
|
|
18934
|
+
throw new Error("Owner delegation requires bounded capabilities");
|
|
18935
|
+
}
|
|
18936
|
+
const byService = /* @__PURE__ */ new Map();
|
|
18937
|
+
for (const action of params.actions) {
|
|
18938
|
+
if (typeof action !== "string") {
|
|
18939
|
+
throw new Error("Owner delegation capabilities are unsupported");
|
|
18940
|
+
}
|
|
18941
|
+
const slash = action.indexOf("/");
|
|
18942
|
+
const service = slash === -1 ? "" : action.slice(0, slash);
|
|
18943
|
+
if (import_sdk_core7.SERVICE_LONG_TO_SHORT[service] === void 0) {
|
|
18944
|
+
throw new Error("Owner delegation capabilities are unsupported");
|
|
18945
|
+
}
|
|
18946
|
+
const actions = byService.get(service) ?? [];
|
|
18947
|
+
actions.push(action);
|
|
18948
|
+
byService.set(service, actions);
|
|
18949
|
+
}
|
|
18950
|
+
for (const [service, actions] of byService) {
|
|
18951
|
+
permissions.push({ service, path: params.path, actions });
|
|
18952
|
+
}
|
|
18953
|
+
}
|
|
18954
|
+
if (permissions.length === 0 || permissions.length > 16) {
|
|
18955
|
+
throw new Error("Owner delegation requires bounded capabilities");
|
|
18956
|
+
}
|
|
18957
|
+
const resources = /* @__PURE__ */ new Set();
|
|
18958
|
+
for (const permission of permissions) {
|
|
18959
|
+
if (typeof permission.service !== "string" || import_sdk_core7.SERVICE_LONG_TO_SHORT[permission.service] === void 0 || typeof permission.path !== "string" || permission.path.length === 0 || permission.path.trim() !== permission.path || /[\u0000-\u001f\u007f\\*]/.test(permission.path) || !Array.isArray(permission.actions) || permission.actions.length === 0 || permission.actions.length > 32) {
|
|
18960
|
+
throw new Error("Owner delegation requires bounded capabilities");
|
|
18961
|
+
}
|
|
18962
|
+
const resourceKey = `${permission.service}\0${permission.path}`;
|
|
18963
|
+
if (resources.has(resourceKey)) {
|
|
18964
|
+
throw new Error("Owner delegation permissions contain duplicate resources");
|
|
18965
|
+
}
|
|
18966
|
+
resources.add(resourceKey);
|
|
18967
|
+
const actions = /* @__PURE__ */ new Set();
|
|
18968
|
+
for (const action of permission.actions) {
|
|
18969
|
+
if (typeof action !== "string" || !action.startsWith(`${permission.service}/`) || action.length === permission.service.length + 1 || actions.has(action)) {
|
|
18970
|
+
throw new Error("Owner delegation capabilities are unsupported");
|
|
18971
|
+
}
|
|
18972
|
+
actions.add(action);
|
|
18973
|
+
}
|
|
18974
|
+
if (permission.service === import_sdk_core7.ENCRYPTION_PERMISSION_SERVICE) {
|
|
18975
|
+
try {
|
|
18976
|
+
(0, import_sdk_core7.parseNetworkId)(permission.path);
|
|
18977
|
+
} catch {
|
|
18978
|
+
throw new Error("Owner delegation encryption permission requires a canonical network URN");
|
|
18979
|
+
}
|
|
18980
|
+
}
|
|
18981
|
+
}
|
|
18982
|
+
return permissions;
|
|
18983
|
+
}
|
|
18984
|
+
function ownerPermissionsToAbilities(permissions) {
|
|
18918
18985
|
const abilities = {};
|
|
18919
|
-
|
|
18920
|
-
|
|
18921
|
-
if (
|
|
18922
|
-
|
|
18923
|
-
|
|
18986
|
+
const rawAbilities = {};
|
|
18987
|
+
for (const permission of permissions) {
|
|
18988
|
+
if (permission.service === import_sdk_core7.ENCRYPTION_PERMISSION_SERVICE) {
|
|
18989
|
+
rawAbilities[permission.path] = [...permission.actions];
|
|
18990
|
+
continue;
|
|
18991
|
+
}
|
|
18992
|
+
const shortService = import_sdk_core7.SERVICE_LONG_TO_SHORT[permission.service];
|
|
18924
18993
|
abilities[shortService] ?? (abilities[shortService] = {});
|
|
18925
|
-
|
|
18926
|
-
abilities[shortService][path].push(action);
|
|
18994
|
+
abilities[shortService][permission.path] = [...permission.actions];
|
|
18927
18995
|
}
|
|
18928
|
-
return
|
|
18996
|
+
return { abilities, rawAbilities };
|
|
18929
18997
|
}
|
|
18930
18998
|
function base64UrlEncode(bytes) {
|
|
18931
18999
|
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
@@ -21299,21 +21367,29 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21299
21367
|
async createOwnerDelegation(params, assertActive) {
|
|
21300
21368
|
const assertOwnerGraphActive = assertActive ?? this._serviceGraph.assertActive.bind(this._serviceGraph);
|
|
21301
21369
|
assertOwnerGraphActive();
|
|
21302
|
-
if (!params.delegateDid.startsWith("did:key:")
|
|
21370
|
+
if (!params.delegateDid.startsWith("did:key:")) {
|
|
21303
21371
|
throw new Error("Owner delegation requires an external did:key audience and bounded capabilities");
|
|
21304
21372
|
}
|
|
21373
|
+
const permissions = ownerDelegationPermissions(params);
|
|
21305
21374
|
const now = /* @__PURE__ */ new Date();
|
|
21306
|
-
if (params.expiresAt.getTime() <= now.getTime() || params.expiresAt.getTime() - now.getTime() > import_sdk_core7.EXPIRY.MAX_MS) {
|
|
21375
|
+
if (!(params.expiresAt instanceof Date) || params.expiresAt.getTime() <= now.getTime() || params.expiresAt.getTime() - now.getTime() > import_sdk_core7.EXPIRY.MAX_MS) {
|
|
21307
21376
|
throw new Error("Owner delegation expiry must be explicit, future, and within EXPIRY.MAX_MS");
|
|
21308
21377
|
}
|
|
21309
21378
|
if (!this.signer) throw new Error("Owner wallet signer is required");
|
|
21310
21379
|
const session = this.currentTinyCloudSession();
|
|
21311
21380
|
if (!session) throw new Error("Owner session is required");
|
|
21312
|
-
const
|
|
21313
|
-
|
|
21381
|
+
const ownerDid = (0, import_sdk_core7.pkhDid)(session.address, session.chainId);
|
|
21382
|
+
for (const permission of permissions) {
|
|
21383
|
+
if (permission.service === import_sdk_core7.ENCRYPTION_PERMISSION_SERVICE && !(0, import_sdk_core7.principalDidEquals)((0, import_sdk_core7.parseNetworkId)(permission.path).ownerDid, ownerDid)) {
|
|
21384
|
+
throw new Error("Owner delegation cannot grant a foreign encryption network");
|
|
21385
|
+
}
|
|
21386
|
+
}
|
|
21387
|
+
const { abilities, rawAbilities } = ownerPermissionsToAbilities(permissions);
|
|
21388
|
+
const primary = permissions[0];
|
|
21314
21389
|
const host = this.config.host;
|
|
21315
21390
|
const prepared = this.wasmBindings.prepareSession({
|
|
21316
21391
|
abilities,
|
|
21392
|
+
...Object.keys(rawAbilities).length === 0 ? {} : { rawAbilities },
|
|
21317
21393
|
address: this.wasmBindings.ensureEip55(session.address),
|
|
21318
21394
|
chainId: session.chainId,
|
|
21319
21395
|
domain: this.siweDomain,
|
|
@@ -21333,10 +21409,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21333
21409
|
const delegation = {
|
|
21334
21410
|
cid: delegationSession.delegationCid,
|
|
21335
21411
|
delegateDID: params.delegateDid,
|
|
21336
|
-
delegatorDID:
|
|
21412
|
+
delegatorDID: ownerDid,
|
|
21337
21413
|
spaceId: params.spaceId,
|
|
21338
|
-
path:
|
|
21339
|
-
actions: [...
|
|
21414
|
+
path: primary.path,
|
|
21415
|
+
actions: [...primary.actions],
|
|
21340
21416
|
expiry: params.expiresAt,
|
|
21341
21417
|
isRevoked: false,
|
|
21342
21418
|
allowSubDelegation: true,
|
|
@@ -21347,6 +21423,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21347
21423
|
delegation,
|
|
21348
21424
|
signedDagCbor: decodeAuthorizationBytes(delegationSession.delegationHeader.Authorization),
|
|
21349
21425
|
delegationCid: delegationSession.delegationCid,
|
|
21426
|
+
permissions,
|
|
21350
21427
|
nodeReceipt: {
|
|
21351
21428
|
commitEventCid: activation.commitEventCid,
|
|
21352
21429
|
activated: activation.activated ?? [],
|