@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, LocalNodeIdentityStore, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignRequest, SignInOptions, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, INotificationHandler, IENSResolver, AccountService, RegisterOwnerSharePolicyParams, OwnerSharePolicyRegistrationReceipt, ShareDeliveryAuthorizationReceipt, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, DelegationRevocationReceipt, DelegationStatus, ResolvedDelegate, KeyProvider, JWK } from '@tinycloud/sdk-core';
|
|
1
|
+
import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, LocalNodeIdentityStore, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignRequest, SignInOptions, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, CreateOwnerDelegationParams as CreateOwnerDelegationParams$1, OwnerDelegationReceipt as OwnerDelegationReceipt$1, INotificationHandler, IENSResolver, AccountService, RegisterOwnerSharePolicyParams, OwnerSharePolicyRegistrationReceipt, ShareDeliveryAuthorizationReceipt, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, DelegationRevocationReceipt, DelegationStatus, ResolvedDelegate, KeyProvider, JWK } from '@tinycloud/sdk-core';
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
import { InvokeFunction, InvokeAnyFunction } from '@tinycloud/sdk-services';
|
|
4
4
|
|
|
@@ -856,19 +856,9 @@ type SecretReadResult = {
|
|
|
856
856
|
} | {
|
|
857
857
|
status: "invalid_payload";
|
|
858
858
|
};
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
readonly spaceId: string;
|
|
862
|
-
readonly path: string;
|
|
863
|
-
readonly actions: readonly string[];
|
|
864
|
-
readonly expiresAt: Date;
|
|
865
|
-
}
|
|
866
|
-
interface OwnerDelegationReceipt {
|
|
859
|
+
type CreateOwnerDelegationParams = CreateOwnerDelegationParams$1;
|
|
860
|
+
interface OwnerDelegationReceipt extends OwnerDelegationReceipt$1 {
|
|
867
861
|
readonly delegation: Delegation;
|
|
868
|
-
/** Exact signed DAG-CBOR bytes submitted in the Authorization header. */
|
|
869
|
-
readonly signedDagCbor: Uint8Array;
|
|
870
|
-
/** Locally derived by the node WASM implementation; this is delegation identity. */
|
|
871
|
-
readonly delegationCid: string;
|
|
872
862
|
readonly nodeReceipt: {
|
|
873
863
|
/** Raw /delegate response CID: a commit-event id, not delegation identity. */
|
|
874
864
|
readonly commitEventCid?: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, LocalNodeIdentityStore, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignRequest, SignInOptions, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, INotificationHandler, IENSResolver, AccountService, RegisterOwnerSharePolicyParams, OwnerSharePolicyRegistrationReceipt, ShareDeliveryAuthorizationReceipt, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, DelegationRevocationReceipt, DelegationStatus, ResolvedDelegate, KeyProvider, JWK } from '@tinycloud/sdk-core';
|
|
1
|
+
import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, LocalNodeIdentityStore, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignRequest, SignInOptions, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, CreateOwnerDelegationParams as CreateOwnerDelegationParams$1, OwnerDelegationReceipt as OwnerDelegationReceipt$1, INotificationHandler, IENSResolver, AccountService, RegisterOwnerSharePolicyParams, OwnerSharePolicyRegistrationReceipt, ShareDeliveryAuthorizationReceipt, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, DelegationRevocationReceipt, DelegationStatus, ResolvedDelegate, KeyProvider, JWK } from '@tinycloud/sdk-core';
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
import { InvokeFunction, InvokeAnyFunction } from '@tinycloud/sdk-services';
|
|
4
4
|
|
|
@@ -856,19 +856,9 @@ type SecretReadResult = {
|
|
|
856
856
|
} | {
|
|
857
857
|
status: "invalid_payload";
|
|
858
858
|
};
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
readonly spaceId: string;
|
|
862
|
-
readonly path: string;
|
|
863
|
-
readonly actions: readonly string[];
|
|
864
|
-
readonly expiresAt: Date;
|
|
865
|
-
}
|
|
866
|
-
interface OwnerDelegationReceipt {
|
|
859
|
+
type CreateOwnerDelegationParams = CreateOwnerDelegationParams$1;
|
|
860
|
+
interface OwnerDelegationReceipt extends OwnerDelegationReceipt$1 {
|
|
867
861
|
readonly delegation: Delegation;
|
|
868
|
-
/** Exact signed DAG-CBOR bytes submitted in the Authorization header. */
|
|
869
|
-
readonly signedDagCbor: Uint8Array;
|
|
870
|
-
/** Locally derived by the node WASM implementation; this is delegation identity. */
|
|
871
|
-
readonly delegationCid: string;
|
|
872
862
|
readonly nodeReceipt: {
|
|
873
863
|
/** Raw /delegate response CID: a commit-event id, not delegation identity. */
|
|
874
864
|
readonly commitEventCid?: string;
|
package/dist/core.cjs
CHANGED
|
@@ -1890,19 +1890,87 @@ function persistedExpiry(value) {
|
|
|
1890
1890
|
function sameInstant(left, right) {
|
|
1891
1891
|
return left.getTime() === right.getTime();
|
|
1892
1892
|
}
|
|
1893
|
-
function
|
|
1894
|
-
|
|
1893
|
+
function ownerDelegationPermissions(params) {
|
|
1894
|
+
const hasPermissions = Object.prototype.hasOwnProperty.call(params, "permissions");
|
|
1895
|
+
const hasLegacy = Object.prototype.hasOwnProperty.call(params, "path") || Object.prototype.hasOwnProperty.call(params, "actions");
|
|
1896
|
+
if (hasPermissions === hasLegacy) {
|
|
1897
|
+
throw new Error("Owner delegation requires exactly one authority shape: path/actions or permissions");
|
|
1898
|
+
}
|
|
1899
|
+
const permissions = [];
|
|
1900
|
+
if (hasPermissions) {
|
|
1901
|
+
if (!Array.isArray(params.permissions)) {
|
|
1902
|
+
throw new Error("Owner delegation permissions are invalid");
|
|
1903
|
+
}
|
|
1904
|
+
permissions.push(...params.permissions.map((permission) => ({
|
|
1905
|
+
service: permission.service,
|
|
1906
|
+
path: permission.path,
|
|
1907
|
+
actions: [...permission.actions]
|
|
1908
|
+
})));
|
|
1909
|
+
} else {
|
|
1910
|
+
if (typeof params.path !== "string" || !Array.isArray(params.actions)) {
|
|
1911
|
+
throw new Error("Owner delegation requires bounded capabilities");
|
|
1912
|
+
}
|
|
1913
|
+
const byService = /* @__PURE__ */ new Map();
|
|
1914
|
+
for (const action of params.actions) {
|
|
1915
|
+
if (typeof action !== "string") {
|
|
1916
|
+
throw new Error("Owner delegation capabilities are unsupported");
|
|
1917
|
+
}
|
|
1918
|
+
const slash = action.indexOf("/");
|
|
1919
|
+
const service = slash === -1 ? "" : action.slice(0, slash);
|
|
1920
|
+
if (import_sdk_core8.SERVICE_LONG_TO_SHORT[service] === void 0) {
|
|
1921
|
+
throw new Error("Owner delegation capabilities are unsupported");
|
|
1922
|
+
}
|
|
1923
|
+
const actions = byService.get(service) ?? [];
|
|
1924
|
+
actions.push(action);
|
|
1925
|
+
byService.set(service, actions);
|
|
1926
|
+
}
|
|
1927
|
+
for (const [service, actions] of byService) {
|
|
1928
|
+
permissions.push({ service, path: params.path, actions });
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
if (permissions.length === 0 || permissions.length > 16) {
|
|
1932
|
+
throw new Error("Owner delegation requires bounded capabilities");
|
|
1933
|
+
}
|
|
1934
|
+
const resources = /* @__PURE__ */ new Set();
|
|
1935
|
+
for (const permission of permissions) {
|
|
1936
|
+
if (typeof permission.service !== "string" || import_sdk_core8.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) {
|
|
1937
|
+
throw new Error("Owner delegation requires bounded capabilities");
|
|
1938
|
+
}
|
|
1939
|
+
const resourceKey = `${permission.service}\0${permission.path}`;
|
|
1940
|
+
if (resources.has(resourceKey)) {
|
|
1941
|
+
throw new Error("Owner delegation permissions contain duplicate resources");
|
|
1942
|
+
}
|
|
1943
|
+
resources.add(resourceKey);
|
|
1944
|
+
const actions = /* @__PURE__ */ new Set();
|
|
1945
|
+
for (const action of permission.actions) {
|
|
1946
|
+
if (typeof action !== "string" || !action.startsWith(`${permission.service}/`) || action.length === permission.service.length + 1 || actions.has(action)) {
|
|
1947
|
+
throw new Error("Owner delegation capabilities are unsupported");
|
|
1948
|
+
}
|
|
1949
|
+
actions.add(action);
|
|
1950
|
+
}
|
|
1951
|
+
if (permission.service === import_sdk_core8.ENCRYPTION_PERMISSION_SERVICE) {
|
|
1952
|
+
try {
|
|
1953
|
+
(0, import_sdk_core8.parseNetworkId)(permission.path);
|
|
1954
|
+
} catch {
|
|
1955
|
+
throw new Error("Owner delegation encryption permission requires a canonical network URN");
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
}
|
|
1959
|
+
return permissions;
|
|
1960
|
+
}
|
|
1961
|
+
function ownerPermissionsToAbilities(permissions) {
|
|
1895
1962
|
const abilities = {};
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
if (
|
|
1899
|
-
|
|
1900
|
-
|
|
1963
|
+
const rawAbilities = {};
|
|
1964
|
+
for (const permission of permissions) {
|
|
1965
|
+
if (permission.service === import_sdk_core8.ENCRYPTION_PERMISSION_SERVICE) {
|
|
1966
|
+
rawAbilities[permission.path] = [...permission.actions];
|
|
1967
|
+
continue;
|
|
1968
|
+
}
|
|
1969
|
+
const shortService = import_sdk_core8.SERVICE_LONG_TO_SHORT[permission.service];
|
|
1901
1970
|
abilities[shortService] ?? (abilities[shortService] = {});
|
|
1902
|
-
|
|
1903
|
-
abilities[shortService][path].push(action);
|
|
1971
|
+
abilities[shortService][permission.path] = [...permission.actions];
|
|
1904
1972
|
}
|
|
1905
|
-
return
|
|
1973
|
+
return { abilities, rawAbilities };
|
|
1906
1974
|
}
|
|
1907
1975
|
function base64UrlEncode(bytes) {
|
|
1908
1976
|
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
@@ -4276,21 +4344,29 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4276
4344
|
async createOwnerDelegation(params, assertActive) {
|
|
4277
4345
|
const assertOwnerGraphActive = assertActive ?? this._serviceGraph.assertActive.bind(this._serviceGraph);
|
|
4278
4346
|
assertOwnerGraphActive();
|
|
4279
|
-
if (!params.delegateDid.startsWith("did:key:")
|
|
4347
|
+
if (!params.delegateDid.startsWith("did:key:")) {
|
|
4280
4348
|
throw new Error("Owner delegation requires an external did:key audience and bounded capabilities");
|
|
4281
4349
|
}
|
|
4350
|
+
const permissions = ownerDelegationPermissions(params);
|
|
4282
4351
|
const now = /* @__PURE__ */ new Date();
|
|
4283
|
-
if (params.expiresAt.getTime() <= now.getTime() || params.expiresAt.getTime() - now.getTime() > import_sdk_core8.EXPIRY.MAX_MS) {
|
|
4352
|
+
if (!(params.expiresAt instanceof Date) || params.expiresAt.getTime() <= now.getTime() || params.expiresAt.getTime() - now.getTime() > import_sdk_core8.EXPIRY.MAX_MS) {
|
|
4284
4353
|
throw new Error("Owner delegation expiry must be explicit, future, and within EXPIRY.MAX_MS");
|
|
4285
4354
|
}
|
|
4286
4355
|
if (!this.signer) throw new Error("Owner wallet signer is required");
|
|
4287
4356
|
const session = this.currentTinyCloudSession();
|
|
4288
4357
|
if (!session) throw new Error("Owner session is required");
|
|
4289
|
-
const
|
|
4290
|
-
|
|
4358
|
+
const ownerDid = (0, import_sdk_core8.pkhDid)(session.address, session.chainId);
|
|
4359
|
+
for (const permission of permissions) {
|
|
4360
|
+
if (permission.service === import_sdk_core8.ENCRYPTION_PERMISSION_SERVICE && !(0, import_sdk_core8.principalDidEquals)((0, import_sdk_core8.parseNetworkId)(permission.path).ownerDid, ownerDid)) {
|
|
4361
|
+
throw new Error("Owner delegation cannot grant a foreign encryption network");
|
|
4362
|
+
}
|
|
4363
|
+
}
|
|
4364
|
+
const { abilities, rawAbilities } = ownerPermissionsToAbilities(permissions);
|
|
4365
|
+
const primary = permissions[0];
|
|
4291
4366
|
const host = this.config.host;
|
|
4292
4367
|
const prepared = this.wasmBindings.prepareSession({
|
|
4293
4368
|
abilities,
|
|
4369
|
+
...Object.keys(rawAbilities).length === 0 ? {} : { rawAbilities },
|
|
4294
4370
|
address: this.wasmBindings.ensureEip55(session.address),
|
|
4295
4371
|
chainId: session.chainId,
|
|
4296
4372
|
domain: this.siweDomain,
|
|
@@ -4310,10 +4386,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4310
4386
|
const delegation = {
|
|
4311
4387
|
cid: delegationSession.delegationCid,
|
|
4312
4388
|
delegateDID: params.delegateDid,
|
|
4313
|
-
delegatorDID:
|
|
4389
|
+
delegatorDID: ownerDid,
|
|
4314
4390
|
spaceId: params.spaceId,
|
|
4315
|
-
path:
|
|
4316
|
-
actions: [...
|
|
4391
|
+
path: primary.path,
|
|
4392
|
+
actions: [...primary.actions],
|
|
4317
4393
|
expiry: params.expiresAt,
|
|
4318
4394
|
isRevoked: false,
|
|
4319
4395
|
allowSubDelegation: true,
|
|
@@ -4324,6 +4400,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4324
4400
|
delegation,
|
|
4325
4401
|
signedDagCbor: decodeAuthorizationBytes(delegationSession.delegationHeader.Authorization),
|
|
4326
4402
|
delegationCid: delegationSession.delegationCid,
|
|
4403
|
+
permissions,
|
|
4327
4404
|
nodeReceipt: {
|
|
4328
4405
|
commitEventCid: activation.commitEventCid,
|
|
4329
4406
|
activated: activation.activated ?? [],
|