@tinycloud/node-sdk 2.4.0-beta.1 → 2.4.0-beta.10
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-Dbzm1kA_.d.cts → core-DiVEwp2P.d.cts} +105 -5
- package/dist/{core-Dbzm1kA_.d.ts → core-DiVEwp2P.d.ts} +105 -5
- package/dist/core.cjs +377 -218
- 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 +205 -44
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +448 -261
- 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 +236 -48
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/core.cjs
CHANGED
|
@@ -30,94 +30,95 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/core.ts
|
|
31
31
|
var core_exports = {};
|
|
32
32
|
__export(core_exports, {
|
|
33
|
-
ACCOUNT_REGISTRY_PATH: () =>
|
|
34
|
-
ACCOUNT_REGISTRY_SPACE: () =>
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
ACCOUNT_REGISTRY_PATH: () => import_sdk_core10.ACCOUNT_REGISTRY_PATH,
|
|
34
|
+
ACCOUNT_REGISTRY_SPACE: () => import_sdk_core10.ACCOUNT_REGISTRY_SPACE,
|
|
35
|
+
AccountService: () => import_sdk_core3.AccountService,
|
|
36
|
+
AutoApproveSpaceCreationHandler: () => import_sdk_core9.AutoApproveSpaceCreationHandler,
|
|
37
|
+
CapabilityKeyRegistry: () => import_sdk_core16.CapabilityKeyRegistry,
|
|
38
|
+
CapabilityKeyRegistryErrorCodes: () => import_sdk_core16.CapabilityKeyRegistryErrorCodes,
|
|
39
|
+
DEFAULT_MANIFEST_SPACE: () => import_sdk_core10.DEFAULT_MANIFEST_SPACE,
|
|
40
|
+
DEFAULT_MANIFEST_VERSION: () => import_sdk_core10.DEFAULT_MANIFEST_VERSION,
|
|
41
|
+
DEFAULT_SIGNED_READ_URL_EXPIRY_MS: () => import_sdk_core11.DEFAULT_SIGNED_READ_URL_EXPIRY_MS,
|
|
42
|
+
DataVaultService: () => import_sdk_core14.DataVaultService,
|
|
43
|
+
DatabaseHandle: () => import_sdk_core12.DatabaseHandle,
|
|
43
44
|
DelegatedAccess: () => DelegatedAccess,
|
|
44
|
-
DelegationErrorCodes: () =>
|
|
45
|
-
DelegationManager: () =>
|
|
46
|
-
DuckDbAction: () =>
|
|
47
|
-
DuckDbDatabaseHandle: () =>
|
|
48
|
-
DuckDbService: () =>
|
|
45
|
+
DelegationErrorCodes: () => import_sdk_core15.DelegationErrorCodes,
|
|
46
|
+
DelegationManager: () => import_sdk_core15.DelegationManager,
|
|
47
|
+
DuckDbAction: () => import_sdk_core13.DuckDbAction,
|
|
48
|
+
DuckDbDatabaseHandle: () => import_sdk_core13.DuckDbDatabaseHandle,
|
|
49
|
+
DuckDbService: () => import_sdk_core13.DuckDbService,
|
|
49
50
|
FileSessionStorage: () => FileSessionStorage,
|
|
50
|
-
IdentityParseError: () =>
|
|
51
|
-
KVService: () =>
|
|
52
|
-
ManifestValidationError: () =>
|
|
51
|
+
IdentityParseError: () => import_sdk_core9.IdentityParseError,
|
|
52
|
+
KVService: () => import_sdk_core11.KVService,
|
|
53
|
+
ManifestValidationError: () => import_sdk_core10.ManifestValidationError,
|
|
53
54
|
MemorySessionStorage: () => MemorySessionStorage,
|
|
54
55
|
NodeUserAuthorization: () => NodeUserAuthorization,
|
|
55
|
-
PermissionNotInManifestError: () =>
|
|
56
|
-
PrefixedKVService: () =>
|
|
57
|
-
ProtocolMismatchError: () =>
|
|
58
|
-
SECRET_NAME_RE: () =>
|
|
59
|
-
SQLAction: () =>
|
|
60
|
-
SQLService: () =>
|
|
61
|
-
SecretsService: () =>
|
|
62
|
-
ServiceContext: () =>
|
|
63
|
-
SessionExpiredError: () =>
|
|
64
|
-
SharingService: () =>
|
|
65
|
-
SilentNotificationHandler: () =>
|
|
66
|
-
Space: () =>
|
|
67
|
-
SpaceErrorCodes: () =>
|
|
68
|
-
SpaceService: () =>
|
|
69
|
-
TinyCloud: () =>
|
|
56
|
+
PermissionNotInManifestError: () => import_sdk_core10.PermissionNotInManifestError,
|
|
57
|
+
PrefixedKVService: () => import_sdk_core11.PrefixedKVService,
|
|
58
|
+
ProtocolMismatchError: () => import_sdk_core18.ProtocolMismatchError,
|
|
59
|
+
SECRET_NAME_RE: () => import_sdk_core14.SECRET_NAME_RE,
|
|
60
|
+
SQLAction: () => import_sdk_core12.SQLAction,
|
|
61
|
+
SQLService: () => import_sdk_core12.SQLService,
|
|
62
|
+
SecretsService: () => import_sdk_core14.SecretsService,
|
|
63
|
+
ServiceContext: () => import_sdk_core19.ServiceContext,
|
|
64
|
+
SessionExpiredError: () => import_sdk_core10.SessionExpiredError,
|
|
65
|
+
SharingService: () => import_sdk_core15.SharingService,
|
|
66
|
+
SilentNotificationHandler: () => import_sdk_core9.SilentNotificationHandler,
|
|
67
|
+
Space: () => import_sdk_core17.Space,
|
|
68
|
+
SpaceErrorCodes: () => import_sdk_core17.SpaceErrorCodes,
|
|
69
|
+
SpaceService: () => import_sdk_core17.SpaceService,
|
|
70
|
+
TinyCloud: () => import_sdk_core8.TinyCloud,
|
|
70
71
|
TinyCloudNode: () => TinyCloudNode,
|
|
71
|
-
UnsupportedFeatureError: () =>
|
|
72
|
-
VAULT_PERMISSION_SERVICE: () =>
|
|
73
|
-
VaultHeaders: () =>
|
|
74
|
-
VaultPublicSpaceKVActions: () =>
|
|
75
|
-
VersionCheckError: () =>
|
|
72
|
+
UnsupportedFeatureError: () => import_sdk_core18.UnsupportedFeatureError,
|
|
73
|
+
VAULT_PERMISSION_SERVICE: () => import_sdk_core10.VAULT_PERMISSION_SERVICE,
|
|
74
|
+
VaultHeaders: () => import_sdk_core14.VaultHeaders,
|
|
75
|
+
VaultPublicSpaceKVActions: () => import_sdk_core14.VaultPublicSpaceKVActions,
|
|
76
|
+
VersionCheckError: () => import_sdk_core18.VersionCheckError,
|
|
76
77
|
WasmKeyProvider: () => WasmKeyProvider,
|
|
77
|
-
addressStorageKey: () =>
|
|
78
|
-
buildSpaceUri: () =>
|
|
79
|
-
canonicalizeAddress: () =>
|
|
80
|
-
canonicalizeDid: () =>
|
|
81
|
-
canonicalizeDidUrl: () =>
|
|
82
|
-
canonicalizeNetworkId: () =>
|
|
83
|
-
canonicalizeSecretScope: () =>
|
|
84
|
-
checkNodeInfo: () =>
|
|
85
|
-
composeManifestRequest: () =>
|
|
86
|
-
createCapabilityKeyRegistry: () =>
|
|
87
|
-
createSharingService: () =>
|
|
88
|
-
createSpaceService: () =>
|
|
89
|
-
createVaultCrypto: () =>
|
|
78
|
+
addressStorageKey: () => import_sdk_core9.addressStorageKey,
|
|
79
|
+
buildSpaceUri: () => import_sdk_core17.buildSpaceUri,
|
|
80
|
+
canonicalizeAddress: () => import_sdk_core9.canonicalizeAddress,
|
|
81
|
+
canonicalizeDid: () => import_sdk_core9.canonicalizeDid,
|
|
82
|
+
canonicalizeDidUrl: () => import_sdk_core9.canonicalizeDidUrl,
|
|
83
|
+
canonicalizeNetworkId: () => import_sdk_core9.canonicalizeNetworkId,
|
|
84
|
+
canonicalizeSecretScope: () => import_sdk_core14.canonicalizeSecretScope,
|
|
85
|
+
checkNodeInfo: () => import_sdk_core18.checkNodeInfo,
|
|
86
|
+
composeManifestRequest: () => import_sdk_core10.composeManifestRequest,
|
|
87
|
+
createCapabilityKeyRegistry: () => import_sdk_core16.createCapabilityKeyRegistry,
|
|
88
|
+
createSharingService: () => import_sdk_core15.createSharingService,
|
|
89
|
+
createSpaceService: () => import_sdk_core17.createSpaceService,
|
|
90
|
+
createVaultCrypto: () => import_sdk_core14.createVaultCrypto,
|
|
90
91
|
createWasmKeyProvider: () => createWasmKeyProvider,
|
|
91
92
|
defaultSignStrategy: () => defaultSignStrategy,
|
|
92
|
-
defaultSpaceCreationHandler: () =>
|
|
93
|
+
defaultSpaceCreationHandler: () => import_sdk_core9.defaultSpaceCreationHandler,
|
|
93
94
|
deserializeDelegation: () => deserializeDelegation,
|
|
94
|
-
didCacheKey: () =>
|
|
95
|
-
didEquals: () =>
|
|
96
|
-
expandActionShortNames: () =>
|
|
97
|
-
expandPermissionEntries: () =>
|
|
98
|
-
expandPermissionEntry: () =>
|
|
99
|
-
isCapabilitySubset: () =>
|
|
100
|
-
isEvmAddress: () =>
|
|
101
|
-
loadManifest: () =>
|
|
102
|
-
makePkhSpaceId: () =>
|
|
103
|
-
makePublicSpaceId: () =>
|
|
104
|
-
parseCanonicalNetworkId: () =>
|
|
105
|
-
parseExpiry: () =>
|
|
106
|
-
parsePkhDid: () =>
|
|
107
|
-
parseSpaceUri: () =>
|
|
108
|
-
pkhDid: () =>
|
|
109
|
-
principalDid: () =>
|
|
110
|
-
principalDidEquals: () =>
|
|
111
|
-
resolveManifest: () =>
|
|
112
|
-
resolveSecretListPrefix: () =>
|
|
113
|
-
resolveSecretPath: () =>
|
|
114
|
-
resourceCapabilitiesToSpaceAbilitiesMap: () =>
|
|
95
|
+
didCacheKey: () => import_sdk_core9.didCacheKey,
|
|
96
|
+
didEquals: () => import_sdk_core9.didEquals,
|
|
97
|
+
expandActionShortNames: () => import_sdk_core10.expandActionShortNames,
|
|
98
|
+
expandPermissionEntries: () => import_sdk_core10.expandPermissionEntries,
|
|
99
|
+
expandPermissionEntry: () => import_sdk_core10.expandPermissionEntry,
|
|
100
|
+
isCapabilitySubset: () => import_sdk_core10.isCapabilitySubset,
|
|
101
|
+
isEvmAddress: () => import_sdk_core9.isEvmAddress,
|
|
102
|
+
loadManifest: () => import_sdk_core10.loadManifest,
|
|
103
|
+
makePkhSpaceId: () => import_sdk_core9.makePkhSpaceId,
|
|
104
|
+
makePublicSpaceId: () => import_sdk_core17.makePublicSpaceId,
|
|
105
|
+
parseCanonicalNetworkId: () => import_sdk_core9.parseCanonicalNetworkId,
|
|
106
|
+
parseExpiry: () => import_sdk_core10.parseExpiry,
|
|
107
|
+
parsePkhDid: () => import_sdk_core9.parsePkhDid,
|
|
108
|
+
parseSpaceUri: () => import_sdk_core17.parseSpaceUri,
|
|
109
|
+
pkhDid: () => import_sdk_core9.pkhDid,
|
|
110
|
+
principalDid: () => import_sdk_core9.principalDid,
|
|
111
|
+
principalDidEquals: () => import_sdk_core9.principalDidEquals,
|
|
112
|
+
resolveManifest: () => import_sdk_core10.resolveManifest,
|
|
113
|
+
resolveSecretListPrefix: () => import_sdk_core14.resolveSecretListPrefix,
|
|
114
|
+
resolveSecretPath: () => import_sdk_core14.resolveSecretPath,
|
|
115
|
+
resourceCapabilitiesToSpaceAbilitiesMap: () => import_sdk_core10.resourceCapabilitiesToSpaceAbilitiesMap,
|
|
115
116
|
serializeDelegation: () => serializeDelegation,
|
|
116
|
-
validateManifest: () =>
|
|
117
|
+
validateManifest: () => import_sdk_core10.validateManifest
|
|
117
118
|
});
|
|
118
119
|
module.exports = __toCommonJS(core_exports);
|
|
119
|
-
var import_sdk_core7 = require("@tinycloud/sdk-core");
|
|
120
120
|
var import_sdk_core8 = require("@tinycloud/sdk-core");
|
|
121
|
+
var import_sdk_core9 = require("@tinycloud/sdk-core");
|
|
121
122
|
|
|
122
123
|
// src/storage/MemorySessionStorage.ts
|
|
123
124
|
var MemorySessionStorage = class {
|
|
@@ -317,6 +318,25 @@ var import_sdk_core2 = require("@tinycloud/sdk-core");
|
|
|
317
318
|
var defaultSignStrategy = { type: "auto-sign" };
|
|
318
319
|
|
|
319
320
|
// src/authorization/NodeUserAuthorization.ts
|
|
321
|
+
var DECRYPT_ACTION = "tinycloud.encryption/decrypt";
|
|
322
|
+
var NETWORK_CREATE_ACTION = "tinycloud.encryption/network.create";
|
|
323
|
+
function didPrincipalMatches(actual, expected) {
|
|
324
|
+
try {
|
|
325
|
+
return (0, import_sdk_core2.principalDidEquals)(actual, expected);
|
|
326
|
+
} catch {
|
|
327
|
+
return actual === expected;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
function addRawAbility(rawAbilities, resource, action) {
|
|
331
|
+
const actions = rawAbilities[resource];
|
|
332
|
+
if (actions === void 0) {
|
|
333
|
+
rawAbilities[resource] = [action];
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
if (!actions.includes(action)) {
|
|
337
|
+
actions.push(action);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
320
340
|
var NodeUserAuthorization = class {
|
|
321
341
|
constructor(config) {
|
|
322
342
|
this.extensions = [];
|
|
@@ -343,6 +363,7 @@ var NodeUserAuthorization = class {
|
|
|
343
363
|
"": [
|
|
344
364
|
"tinycloud.sql/read",
|
|
345
365
|
"tinycloud.sql/write",
|
|
366
|
+
"tinycloud.sql/ddl",
|
|
346
367
|
"tinycloud.sql/admin",
|
|
347
368
|
"tinycloud.sql/export"
|
|
348
369
|
]
|
|
@@ -546,20 +567,18 @@ var NodeUserAuthorization = class {
|
|
|
546
567
|
};
|
|
547
568
|
}
|
|
548
569
|
const rawAbilities = {};
|
|
570
|
+
const currentDid = (0, import_sdk_core2.pkhDid)(address, chainId);
|
|
549
571
|
const spaceResources = request.resources.filter((entry) => {
|
|
550
572
|
if (entry.service !== import_sdk_core2.ENCRYPTION_PERMISSION_SERVICE) {
|
|
551
573
|
return true;
|
|
552
574
|
}
|
|
553
|
-
const
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
const
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
existing.push(action);
|
|
561
|
-
seen.add(action);
|
|
562
|
-
}
|
|
575
|
+
for (const action of entry.actions) {
|
|
576
|
+
addRawAbility(rawAbilities, entry.path, action);
|
|
577
|
+
}
|
|
578
|
+
if (entry.actions.includes(DECRYPT_ACTION)) {
|
|
579
|
+
const parsed = (0, import_sdk_core2.parseNetworkId)(entry.path);
|
|
580
|
+
if (didPrincipalMatches(parsed.ownerDid, currentDid)) {
|
|
581
|
+
addRawAbility(rawAbilities, entry.path, NETWORK_CREATE_ACTION);
|
|
563
582
|
}
|
|
564
583
|
}
|
|
565
584
|
return false;
|
|
@@ -1119,32 +1138,35 @@ var NodeUserAuthorization = class {
|
|
|
1119
1138
|
};
|
|
1120
1139
|
|
|
1121
1140
|
// src/TinyCloudNode.ts
|
|
1122
|
-
var
|
|
1141
|
+
var import_sdk_core7 = require("@tinycloud/sdk-core");
|
|
1123
1142
|
|
|
1124
|
-
// src/
|
|
1143
|
+
// src/account/AccountService.ts
|
|
1125
1144
|
var import_sdk_core3 = require("@tinycloud/sdk-core");
|
|
1145
|
+
|
|
1146
|
+
// src/DelegatedAccess.ts
|
|
1147
|
+
var import_sdk_core4 = require("@tinycloud/sdk-core");
|
|
1126
1148
|
var DelegatedAccess = class {
|
|
1127
1149
|
constructor(session, delegation, host, invoke, telemetry) {
|
|
1128
1150
|
this.session = session;
|
|
1129
1151
|
this._delegation = delegation;
|
|
1130
1152
|
this.host = host;
|
|
1131
|
-
this._serviceContext = new
|
|
1153
|
+
this._serviceContext = new import_sdk_core4.ServiceContext({
|
|
1132
1154
|
invoke,
|
|
1133
1155
|
fetch: globalThis.fetch.bind(globalThis),
|
|
1134
1156
|
hosts: [host],
|
|
1135
1157
|
telemetry
|
|
1136
1158
|
});
|
|
1137
1159
|
const prefix = this._delegation.path.replace(/\/$/, "");
|
|
1138
|
-
this._kv = new
|
|
1160
|
+
this._kv = new import_sdk_core4.KVService({ prefix });
|
|
1139
1161
|
this._kv.initialize(this._serviceContext);
|
|
1140
1162
|
this._serviceContext.registerService("kv", this._kv);
|
|
1141
|
-
this._sql = new
|
|
1163
|
+
this._sql = new import_sdk_core4.SQLService({});
|
|
1142
1164
|
this._sql.initialize(this._serviceContext);
|
|
1143
1165
|
this._serviceContext.registerService("sql", this._sql);
|
|
1144
|
-
this._duckdb = new
|
|
1166
|
+
this._duckdb = new import_sdk_core4.DuckDbService({});
|
|
1145
1167
|
this._duckdb.initialize(this._serviceContext);
|
|
1146
1168
|
this._serviceContext.registerService("duckdb", this._duckdb);
|
|
1147
|
-
this._hooks = new
|
|
1169
|
+
this._hooks = new import_sdk_core4.HooksService({});
|
|
1148
1170
|
this._hooks.initialize(this._serviceContext);
|
|
1149
1171
|
this._serviceContext.registerService("hooks", this._hooks);
|
|
1150
1172
|
const serviceSession = {
|
|
@@ -1294,7 +1316,7 @@ function createWasmKeyProvider(sessionManager) {
|
|
|
1294
1316
|
}
|
|
1295
1317
|
|
|
1296
1318
|
// src/delegateToHelpers.ts
|
|
1297
|
-
var
|
|
1319
|
+
var import_sdk_core5 = require("@tinycloud/sdk-core");
|
|
1298
1320
|
function legacyParamsToPermissionEntries(actions, path, spaceIdOverride) {
|
|
1299
1321
|
const byService = /* @__PURE__ */ new Map();
|
|
1300
1322
|
for (const a of actions) {
|
|
@@ -1325,7 +1347,7 @@ function legacyParamsToPermissionEntries(actions, path, spaceIdOverride) {
|
|
|
1325
1347
|
}
|
|
1326
1348
|
return entries;
|
|
1327
1349
|
}
|
|
1328
|
-
var DEFAULT_DELEGATION_EXPIRY_MS =
|
|
1350
|
+
var DEFAULT_DELEGATION_EXPIRY_MS = import_sdk_core5.EXPIRY.SESSION_MS;
|
|
1329
1351
|
function resolveExpiryMs(expiry) {
|
|
1330
1352
|
if (expiry === void 0) {
|
|
1331
1353
|
return DEFAULT_DELEGATION_EXPIRY_MS;
|
|
@@ -1338,10 +1360,10 @@ function resolveExpiryMs(expiry) {
|
|
|
1338
1360
|
}
|
|
1339
1361
|
return expiry;
|
|
1340
1362
|
}
|
|
1341
|
-
return (0,
|
|
1363
|
+
return (0, import_sdk_core5.parseExpiry)(expiry);
|
|
1342
1364
|
}
|
|
1343
1365
|
function extractSiweExpiration(siwe) {
|
|
1344
|
-
const parsed = new
|
|
1366
|
+
const parsed = new import_sdk_core5.SiweMessage(siwe);
|
|
1345
1367
|
if (parsed.expirationTime === void 0 || parsed.expirationTime === null) {
|
|
1346
1368
|
return void 0;
|
|
1347
1369
|
}
|
|
@@ -1355,7 +1377,7 @@ function extractSiweExpiration(siwe) {
|
|
|
1355
1377
|
}
|
|
1356
1378
|
|
|
1357
1379
|
// src/NodeSecretsService.ts
|
|
1358
|
-
var
|
|
1380
|
+
var import_sdk_core6 = require("@tinycloud/sdk-core");
|
|
1359
1381
|
var SECRETS_SPACE = "secrets";
|
|
1360
1382
|
function ok() {
|
|
1361
1383
|
return { ok: true, data: void 0 };
|
|
@@ -1388,7 +1410,7 @@ function secretActionName(action) {
|
|
|
1388
1410
|
}
|
|
1389
1411
|
function secretPermissionEntries(name, options, action, encryptionNetworkId) {
|
|
1390
1412
|
const entries = [];
|
|
1391
|
-
const path = action === "list" ? (0,
|
|
1413
|
+
const path = action === "list" ? (0, import_sdk_core6.resolveSecretListPrefix)(options) : (0, import_sdk_core6.resolveSecretPath)(name, options).permissionPaths.vault;
|
|
1392
1414
|
entries.push({
|
|
1393
1415
|
service: "tinycloud.kv",
|
|
1394
1416
|
space: SECRETS_SPACE,
|
|
@@ -1467,7 +1489,7 @@ var NodeSecretsService = class {
|
|
|
1467
1489
|
);
|
|
1468
1490
|
} catch (error) {
|
|
1469
1491
|
return secretsError(
|
|
1470
|
-
|
|
1492
|
+
import_sdk_core6.ErrorCodes.INVALID_INPUT,
|
|
1471
1493
|
error instanceof Error ? error.message : String(error),
|
|
1472
1494
|
error instanceof Error ? error : void 0
|
|
1473
1495
|
);
|
|
@@ -1477,7 +1499,7 @@ var NodeSecretsService = class {
|
|
|
1477
1499
|
}
|
|
1478
1500
|
if (!this.config.canEscalate()) {
|
|
1479
1501
|
return secretsError(
|
|
1480
|
-
|
|
1502
|
+
import_sdk_core6.ErrorCodes.PERMISSION_DENIED,
|
|
1481
1503
|
`Cannot autosign ${displayActionUrn(action)} for ${target}; TinyCloudNode needs wallet mode with a signer or privateKey.`
|
|
1482
1504
|
);
|
|
1483
1505
|
}
|
|
@@ -1486,7 +1508,7 @@ var NodeSecretsService = class {
|
|
|
1486
1508
|
return this.restoreUnlockAfterEscalation();
|
|
1487
1509
|
} catch (error) {
|
|
1488
1510
|
return secretsError(
|
|
1489
|
-
|
|
1511
|
+
import_sdk_core6.ErrorCodes.PERMISSION_DENIED,
|
|
1490
1512
|
error instanceof Error ? error.message : `Autosign escalation for ${displayActionUrn(action)} on ${target} failed.`,
|
|
1491
1513
|
error instanceof Error ? error : void 0
|
|
1492
1514
|
);
|
|
@@ -1507,10 +1529,10 @@ var NodeSecretsService = class {
|
|
|
1507
1529
|
return false;
|
|
1508
1530
|
}
|
|
1509
1531
|
const manifests = Array.isArray(manifest) ? manifest : [manifest];
|
|
1510
|
-
const requestedEntries = (0,
|
|
1532
|
+
const requestedEntries = (0, import_sdk_core6.expandPermissionEntries)(permissionEntries);
|
|
1511
1533
|
return requestedEntries.every(
|
|
1512
1534
|
(entry) => manifests.some((candidate) => {
|
|
1513
|
-
const resolved = (0,
|
|
1535
|
+
const resolved = (0, import_sdk_core6.resolveManifest)(candidate);
|
|
1514
1536
|
return resolved.resources.some(
|
|
1515
1537
|
(resource) => resource.service === entry.service && resource.space === entry.space && resource.path === entry.path && entry.actions.every((action) => resource.actions.includes(action))
|
|
1516
1538
|
);
|
|
@@ -1522,13 +1544,13 @@ var NodeSecretsService = class {
|
|
|
1522
1544
|
// src/TinyCloudNode.ts
|
|
1523
1545
|
var DEFAULT_HOST = "https://node.tinycloud.xyz";
|
|
1524
1546
|
var DEFAULT_ENCRYPTION_NETWORK_NAME = "default";
|
|
1525
|
-
var
|
|
1526
|
-
var
|
|
1547
|
+
var NETWORK_CREATE_ACTION2 = "tinycloud.encryption/network.create";
|
|
1548
|
+
var DECRYPT_ACTION2 = "tinycloud.encryption/decrypt";
|
|
1527
1549
|
var NETWORK_ADMIN_TYPE = "tinycloud.encryption.network-admin/v1";
|
|
1528
|
-
var DEFAULT_SESSION_EXPIRATION_MS =
|
|
1529
|
-
function
|
|
1550
|
+
var DEFAULT_SESSION_EXPIRATION_MS = import_sdk_core7.EXPIRY.SESSION_MS;
|
|
1551
|
+
function didPrincipalMatches2(actual, expected) {
|
|
1530
1552
|
try {
|
|
1531
|
-
return (0,
|
|
1553
|
+
return (0, import_sdk_core7.principalDidEquals)(actual, expected);
|
|
1532
1554
|
} catch {
|
|
1533
1555
|
return actual === expected;
|
|
1534
1556
|
}
|
|
@@ -1694,12 +1716,12 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1694
1716
|
throw new Error("Failed to get session key JWK");
|
|
1695
1717
|
}
|
|
1696
1718
|
this.sessionKeyJwk = JSON.parse(jwkStr);
|
|
1697
|
-
this._capabilityRegistry = new
|
|
1719
|
+
this._capabilityRegistry = new import_sdk_core7.CapabilityKeyRegistry();
|
|
1698
1720
|
this._keyProvider = new WasmKeyProvider({
|
|
1699
1721
|
sessionManager: this.sessionManager
|
|
1700
1722
|
});
|
|
1701
|
-
this.notificationHandler = config.notificationHandler ?? new
|
|
1702
|
-
this._sharingService = new
|
|
1723
|
+
this.notificationHandler = config.notificationHandler ?? new import_sdk_core7.SilentNotificationHandler();
|
|
1724
|
+
this._sharingService = new import_sdk_core7.SharingService({
|
|
1703
1725
|
hosts: [this.config.host],
|
|
1704
1726
|
// session: undefined - not needed for receive()
|
|
1705
1727
|
invoke: this.invokeWithRuntimePermissions,
|
|
@@ -1709,8 +1731,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1709
1731
|
// delegationManager: undefined - not needed for receive()
|
|
1710
1732
|
createKVService: (config2) => {
|
|
1711
1733
|
const prefix = config2.pathPrefix?.replace(/\/$/, "");
|
|
1712
|
-
const kvService = new
|
|
1713
|
-
const kvContext = new
|
|
1734
|
+
const kvService = new import_sdk_core7.KVService({ prefix });
|
|
1735
|
+
const kvContext = new import_sdk_core7.ServiceContext({
|
|
1714
1736
|
invoke: config2.invoke,
|
|
1715
1737
|
fetch: config2.fetch ?? globalThis.fetch.bind(globalThis),
|
|
1716
1738
|
hosts: config2.hosts,
|
|
@@ -1770,7 +1792,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1770
1792
|
capabilityRequest: config.capabilityRequest,
|
|
1771
1793
|
includeAccountRegistryPermissions: config.includeAccountRegistryPermissions
|
|
1772
1794
|
});
|
|
1773
|
-
this.tc = new
|
|
1795
|
+
this.tc = new import_sdk_core7.TinyCloud(this.auth, {
|
|
1774
1796
|
invokeAny: this.invokeAnyWithRuntimePermissions,
|
|
1775
1797
|
telemetry: config.telemetry
|
|
1776
1798
|
});
|
|
@@ -1831,7 +1853,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1831
1853
|
*/
|
|
1832
1854
|
get did() {
|
|
1833
1855
|
if (this._address) {
|
|
1834
|
-
return (0,
|
|
1856
|
+
return (0, import_sdk_core7.pkhDid)(this._address, this._chainId);
|
|
1835
1857
|
}
|
|
1836
1858
|
return this.sessionManager.getDID(this.sessionKeyId);
|
|
1837
1859
|
}
|
|
@@ -1865,6 +1887,37 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1865
1887
|
get spaceId() {
|
|
1866
1888
|
return this.auth?.tinyCloudSession?.spaceId;
|
|
1867
1889
|
}
|
|
1890
|
+
/**
|
|
1891
|
+
* Get the account space ID for this wallet identity.
|
|
1892
|
+
* Available after wallet-backed sign-in or a restored session with address metadata.
|
|
1893
|
+
*/
|
|
1894
|
+
get accountSpaceId() {
|
|
1895
|
+
if (!this._address) {
|
|
1896
|
+
return void 0;
|
|
1897
|
+
}
|
|
1898
|
+
return this.wasmBindings.makeSpaceId(this._address, this._chainId, import_sdk_core7.ACCOUNT_REGISTRY_SPACE);
|
|
1899
|
+
}
|
|
1900
|
+
/**
|
|
1901
|
+
* Account-level application and delegation helpers.
|
|
1902
|
+
*/
|
|
1903
|
+
get account() {
|
|
1904
|
+
if (!this._account) {
|
|
1905
|
+
this._account = new import_sdk_core3.AccountService({
|
|
1906
|
+
getDid: () => this.did,
|
|
1907
|
+
getHost: () => this.hosts[0] ?? this.config.host,
|
|
1908
|
+
getPrimarySpaceId: () => this.spaceId,
|
|
1909
|
+
getAccountSpaceId: () => this.accountSpaceId,
|
|
1910
|
+
getSpaces: () => this.spaces,
|
|
1911
|
+
getAccountDb: () => this.accountSpaceId ? this.sqlForSpace(this.accountSpaceId).db("account") : void 0,
|
|
1912
|
+
ensureAccountSpaceHosted: async () => {
|
|
1913
|
+
if (this.accountSpaceId && this.auth) {
|
|
1914
|
+
await this.ensureOwnedSpaceHostedById(this.accountSpaceId);
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
});
|
|
1918
|
+
}
|
|
1919
|
+
return this._account;
|
|
1920
|
+
}
|
|
1868
1921
|
/**
|
|
1869
1922
|
* Get the current TinyCloud session.
|
|
1870
1923
|
* Available after signIn().
|
|
@@ -1886,7 +1939,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1886
1939
|
);
|
|
1887
1940
|
}
|
|
1888
1941
|
await this.wasmBindings.ensureInitialized?.();
|
|
1889
|
-
this._address = (0,
|
|
1942
|
+
this._address = (0, import_sdk_core7.canonicalizeAddress)(await this.signer.getAddress());
|
|
1890
1943
|
this._chainId = await this.signer.getChainId();
|
|
1891
1944
|
this._kv = void 0;
|
|
1892
1945
|
this._sql = void 0;
|
|
@@ -1902,10 +1955,11 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1902
1955
|
await this.tc.signIn(options);
|
|
1903
1956
|
this.syncResolvedHostFromAuth();
|
|
1904
1957
|
this.initializeServices();
|
|
1958
|
+
await this.ensureRequestedEncryptionNetworks();
|
|
1905
1959
|
if (this.config.manifest === void 0 && this.config.capabilityRequest === void 0) {
|
|
1906
|
-
await this.
|
|
1960
|
+
await this.ensureOwnedSpaceHostedById(this.ownedSpaceId("secrets"));
|
|
1907
1961
|
}
|
|
1908
|
-
|
|
1962
|
+
this.scheduleAccountRegistrySync();
|
|
1909
1963
|
this.notificationHandler.success("Successfully signed in");
|
|
1910
1964
|
}
|
|
1911
1965
|
ownedSpaceId(name) {
|
|
@@ -1922,23 +1976,69 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1922
1976
|
if (!this.auth || !this.signer) {
|
|
1923
1977
|
throw new Error("Manifest registry write requires wallet mode");
|
|
1924
1978
|
}
|
|
1925
|
-
const accountSpaceId = this.ownedSpaceId(
|
|
1926
|
-
await this.
|
|
1927
|
-
const
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1979
|
+
const accountSpaceId = this.ownedSpaceId(import_sdk_core7.ACCOUNT_REGISTRY_SPACE);
|
|
1980
|
+
await this.ensureOwnedSpaceHostedById(accountSpaceId);
|
|
1981
|
+
const result = await this.account.applications.register(request.manifests);
|
|
1982
|
+
if (!result.ok) {
|
|
1983
|
+
throw new Error(
|
|
1984
|
+
`Failed to write manifest registry records: ${result.error.message}`
|
|
1985
|
+
);
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
scheduleAccountRegistrySync() {
|
|
1989
|
+
void this.withAccountRegistryRetry(async () => {
|
|
1990
|
+
await this.writeManifestRegistryRecords();
|
|
1991
|
+
const spaces = await this.account.spaces.syncAccessible();
|
|
1992
|
+
if (!spaces.ok) {
|
|
1993
|
+
throw new Error(`Failed to sync account spaces: ${spaces.error.message}`);
|
|
1994
|
+
}
|
|
1995
|
+
});
|
|
1996
|
+
}
|
|
1997
|
+
async withAccountRegistryRetry(task) {
|
|
1998
|
+
const delays = [250, 1e3, 3e3];
|
|
1999
|
+
let lastError;
|
|
2000
|
+
for (let attempt = 0; attempt < delays.length; attempt += 1) {
|
|
2001
|
+
try {
|
|
2002
|
+
await task();
|
|
2003
|
+
return;
|
|
2004
|
+
} catch (error) {
|
|
2005
|
+
lastError = error;
|
|
2006
|
+
if (attempt < delays.length - 1) {
|
|
2007
|
+
await new Promise((resolve) => setTimeout(resolve, delays[attempt]));
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
console.warn(
|
|
2012
|
+
"TinyCloud account registry sync failed after retries",
|
|
2013
|
+
lastError
|
|
2014
|
+
);
|
|
2015
|
+
}
|
|
2016
|
+
requestedEncryptionNetworkIds() {
|
|
2017
|
+
const request = this.capabilityRequest;
|
|
2018
|
+
if (!request) {
|
|
2019
|
+
return [];
|
|
2020
|
+
}
|
|
2021
|
+
const networkIds = /* @__PURE__ */ new Set();
|
|
2022
|
+
for (const resource of request.resources) {
|
|
2023
|
+
if (resource.service === import_sdk_core7.ENCRYPTION_PERMISSION_SERVICE && resource.path.startsWith("urn:tinycloud:encryption:") && resource.actions.includes(DECRYPT_ACTION2)) {
|
|
2024
|
+
networkIds.add(resource.path);
|
|
1938
2025
|
}
|
|
1939
2026
|
}
|
|
2027
|
+
return [...networkIds];
|
|
1940
2028
|
}
|
|
1941
|
-
async
|
|
2029
|
+
async ensureRequestedEncryptionNetworks() {
|
|
2030
|
+
if (!this.signer || !this.auth) {
|
|
2031
|
+
return;
|
|
2032
|
+
}
|
|
2033
|
+
for (const networkId of this.requestedEncryptionNetworkIds()) {
|
|
2034
|
+
const parsed = (0, import_sdk_core7.parseNetworkId)(networkId);
|
|
2035
|
+
if (!didPrincipalMatches2(parsed.ownerDid, this.did)) {
|
|
2036
|
+
continue;
|
|
2037
|
+
}
|
|
2038
|
+
await this.ensureEncryptionNetwork(networkId);
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
2041
|
+
async ensureOwnedSpaceHostedById(spaceId) {
|
|
1942
2042
|
if (!this.auth) {
|
|
1943
2043
|
throw new Error("Owned space hosting requires wallet mode");
|
|
1944
2044
|
}
|
|
@@ -1950,7 +2050,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1950
2050
|
if (!host) {
|
|
1951
2051
|
throw new Error("Owned space hosting requires a TinyCloud host");
|
|
1952
2052
|
}
|
|
1953
|
-
const activation = await (0,
|
|
2053
|
+
const activation = await (0, import_sdk_core7.activateSessionWithHost)(host, session.delegationHeader);
|
|
1954
2054
|
if (activation.success && !activation.skipped?.includes(spaceId)) {
|
|
1955
2055
|
return;
|
|
1956
2056
|
}
|
|
@@ -1964,7 +2064,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1964
2064
|
throw new Error(`Failed to create owned space: ${spaceId}`);
|
|
1965
2065
|
}
|
|
1966
2066
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
1967
|
-
const retry = await (0,
|
|
2067
|
+
const retry = await (0, import_sdk_core7.activateSessionWithHost)(host, session.delegationHeader);
|
|
1968
2068
|
if (!retry.success || retry.skipped?.includes(spaceId)) {
|
|
1969
2069
|
throw new Error(
|
|
1970
2070
|
`Failed to activate session after creating owned space ${spaceId}: ${retry.error ?? "space was skipped"}`
|
|
@@ -1981,7 +2081,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1981
2081
|
* caller is the root authority of their own owned spaces, so no additional
|
|
1982
2082
|
* delegation is required.
|
|
1983
2083
|
*
|
|
1984
|
-
* Unlike {@link
|
|
2084
|
+
* Unlike {@link ensureOwnedSpaceHostedById}, this always submits the host
|
|
1985
2085
|
* delegation rather than inferring hosting from session activation: a space
|
|
1986
2086
|
* the current session has never referenced is reported neither as
|
|
1987
2087
|
* `activated` nor `skipped`, so activation-based detection would wrongly
|
|
@@ -2006,7 +2106,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2006
2106
|
if (!hosted) {
|
|
2007
2107
|
throw new Error(`Failed to host owned space: ${spaceId}`);
|
|
2008
2108
|
}
|
|
2009
|
-
const activation = await (0,
|
|
2109
|
+
const activation = await (0, import_sdk_core7.activateSessionWithHost)(
|
|
2010
2110
|
host,
|
|
2011
2111
|
this.auth.tinyCloudSession.delegationHeader
|
|
2012
2112
|
);
|
|
@@ -2015,8 +2115,40 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2015
2115
|
`Failed to activate session for owned space ${spaceId}: ${activation.error ?? "space was skipped"}`
|
|
2016
2116
|
);
|
|
2017
2117
|
}
|
|
2118
|
+
void this.account.spaces.register({
|
|
2119
|
+
spaceId,
|
|
2120
|
+
name,
|
|
2121
|
+
ownerDid: this.did,
|
|
2122
|
+
type: "owned",
|
|
2123
|
+
permissions: ["*"],
|
|
2124
|
+
status: "active"
|
|
2125
|
+
}).catch(() => {
|
|
2126
|
+
});
|
|
2018
2127
|
return spaceId;
|
|
2019
2128
|
}
|
|
2129
|
+
/**
|
|
2130
|
+
* Ensure one of this user's owned spaces (e.g. `"secrets"`) is hosted on the
|
|
2131
|
+
* server.
|
|
2132
|
+
*
|
|
2133
|
+
* At sign-in, a full-authority session auto-hosts the owner's `secrets`
|
|
2134
|
+
* space, but a session created with a manifest / capabilityRequest does not.
|
|
2135
|
+
* Such a session can therefore hold valid `tinycloud.kv/*` capabilities for
|
|
2136
|
+
* the owned `secrets` space yet still fail its first scoped
|
|
2137
|
+
* `secrets.put(...)` with `404 Space not found`, because the space was never
|
|
2138
|
+
* registered on the node.
|
|
2139
|
+
*
|
|
2140
|
+
* Calling this resolves `name` to the owner's owned-space URI
|
|
2141
|
+
* (`tinycloud:pkh:eip155:<chain>:<addr>:<name>`) and hosts it via the
|
|
2142
|
+
* host-SIWE delegation flow. The host SIWE is idempotent server-side, so it
|
|
2143
|
+
* is safe to call whether or not the space already exists; do not gate it on
|
|
2144
|
+
* a prior existence check. Must be called after {@link signIn}.
|
|
2145
|
+
*
|
|
2146
|
+
* @param name - The owned space name (e.g. `"secrets"`).
|
|
2147
|
+
* @returns The hosted owned-space URI.
|
|
2148
|
+
*/
|
|
2149
|
+
async ensureOwnedSpaceHosted(name) {
|
|
2150
|
+
return this.hostOwnedSpace(name);
|
|
2151
|
+
}
|
|
2020
2152
|
/**
|
|
2021
2153
|
* Restore a previously established session from stored delegation data.
|
|
2022
2154
|
*
|
|
@@ -2039,30 +2171,30 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2039
2171
|
this._spaceService = void 0;
|
|
2040
2172
|
this._serviceContext = void 0;
|
|
2041
2173
|
this.runtimePermissionGrants = [];
|
|
2042
|
-
const restoredAddress = sessionData.address ? (0,
|
|
2174
|
+
const restoredAddress = sessionData.address ? (0, import_sdk_core7.canonicalizeAddress)(sessionData.address) : void 0;
|
|
2043
2175
|
if (restoredAddress) {
|
|
2044
2176
|
this._address = restoredAddress;
|
|
2045
2177
|
}
|
|
2046
2178
|
if (sessionData.chainId) {
|
|
2047
2179
|
this._chainId = sessionData.chainId;
|
|
2048
2180
|
}
|
|
2049
|
-
this._serviceContext = new
|
|
2181
|
+
this._serviceContext = new import_sdk_core7.ServiceContext({
|
|
2050
2182
|
invoke: this.invokeWithRuntimePermissions,
|
|
2051
2183
|
invokeAny: this.invokeAnyWithRuntimePermissions,
|
|
2052
2184
|
fetch: globalThis.fetch.bind(globalThis),
|
|
2053
2185
|
hosts: [this.config.host],
|
|
2054
2186
|
telemetry: this.config.telemetry
|
|
2055
2187
|
});
|
|
2056
|
-
this._kv = new
|
|
2188
|
+
this._kv = new import_sdk_core7.KVService({});
|
|
2057
2189
|
this._kv.initialize(this._serviceContext);
|
|
2058
2190
|
this._serviceContext.registerService("kv", this._kv);
|
|
2059
|
-
this._sql = new
|
|
2191
|
+
this._sql = new import_sdk_core7.SQLService({});
|
|
2060
2192
|
this._sql.initialize(this._serviceContext);
|
|
2061
2193
|
this._serviceContext.registerService("sql", this._sql);
|
|
2062
|
-
this._duckdb = new
|
|
2194
|
+
this._duckdb = new import_sdk_core7.DuckDbService({});
|
|
2063
2195
|
this._duckdb.initialize(this._serviceContext);
|
|
2064
2196
|
this._serviceContext.registerService("duckdb", this._duckdb);
|
|
2065
|
-
this._hooks = new
|
|
2197
|
+
this._hooks = new import_sdk_core7.HooksService({});
|
|
2066
2198
|
this._hooks.initialize(this._serviceContext);
|
|
2067
2199
|
this._serviceContext.registerService("hooks", this._hooks);
|
|
2068
2200
|
const serviceSession = {
|
|
@@ -2161,7 +2293,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2161
2293
|
capabilityRequest: this.config.capabilityRequest,
|
|
2162
2294
|
includeAccountRegistryPermissions: this.config.includeAccountRegistryPermissions
|
|
2163
2295
|
});
|
|
2164
|
-
this.tc = new
|
|
2296
|
+
this.tc = new import_sdk_core7.TinyCloud(this.auth, {
|
|
2165
2297
|
invokeAny: this.invokeAnyWithRuntimePermissions,
|
|
2166
2298
|
telemetry: this.config.telemetry
|
|
2167
2299
|
});
|
|
@@ -2206,7 +2338,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2206
2338
|
capabilityRequest: this.config.capabilityRequest,
|
|
2207
2339
|
includeAccountRegistryPermissions: this.config.includeAccountRegistryPermissions
|
|
2208
2340
|
});
|
|
2209
|
-
this.tc = new
|
|
2341
|
+
this.tc = new import_sdk_core7.TinyCloud(this.auth, {
|
|
2210
2342
|
invokeAny: this.invokeAnyWithRuntimePermissions,
|
|
2211
2343
|
telemetry: this.config.telemetry
|
|
2212
2344
|
});
|
|
@@ -2222,28 +2354,28 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2222
2354
|
return;
|
|
2223
2355
|
}
|
|
2224
2356
|
this.tc.initializeServices(this.invokeWithRuntimePermissions, [this.config.host]);
|
|
2225
|
-
this._serviceContext = new
|
|
2357
|
+
this._serviceContext = new import_sdk_core7.ServiceContext({
|
|
2226
2358
|
invoke: this.invokeWithRuntimePermissions,
|
|
2227
2359
|
invokeAny: this.invokeAnyWithRuntimePermissions,
|
|
2228
2360
|
fetch: globalThis.fetch.bind(globalThis),
|
|
2229
2361
|
hosts: [this.config.host],
|
|
2230
2362
|
telemetry: this.config.telemetry
|
|
2231
2363
|
});
|
|
2232
|
-
this._kv = new
|
|
2364
|
+
this._kv = new import_sdk_core7.KVService({});
|
|
2233
2365
|
this._kv.initialize(this._serviceContext);
|
|
2234
2366
|
this._serviceContext.registerService("kv", this._kv);
|
|
2235
2367
|
const features = this.nodeFeatures;
|
|
2236
2368
|
if (features.length === 0 || features.includes("sql")) {
|
|
2237
|
-
this._sql = new
|
|
2369
|
+
this._sql = new import_sdk_core7.SQLService({});
|
|
2238
2370
|
this._sql.initialize(this._serviceContext);
|
|
2239
2371
|
this._serviceContext.registerService("sql", this._sql);
|
|
2240
2372
|
}
|
|
2241
2373
|
if (features.length === 0 || features.includes("duckdb")) {
|
|
2242
|
-
this._duckdb = new
|
|
2374
|
+
this._duckdb = new import_sdk_core7.DuckDbService({});
|
|
2243
2375
|
this._duckdb.initialize(this._serviceContext);
|
|
2244
2376
|
this._serviceContext.registerService("duckdb", this._duckdb);
|
|
2245
2377
|
}
|
|
2246
|
-
this._hooks = new
|
|
2378
|
+
this._hooks = new import_sdk_core7.HooksService({});
|
|
2247
2379
|
this._hooks.initialize(this._serviceContext);
|
|
2248
2380
|
this._serviceContext.registerService("hooks", this._hooks);
|
|
2249
2381
|
const serviceSession = {
|
|
@@ -2261,9 +2393,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2261
2393
|
this.initializeV2Services(serviceSession);
|
|
2262
2394
|
}
|
|
2263
2395
|
createSpaceScopedKVService(spaceId) {
|
|
2264
|
-
const kvService = new
|
|
2396
|
+
const kvService = new import_sdk_core7.KVService({});
|
|
2265
2397
|
if (this._serviceContext) {
|
|
2266
|
-
const spaceScopedContext = new
|
|
2398
|
+
const spaceScopedContext = new import_sdk_core7.ServiceContext({
|
|
2267
2399
|
invoke: this._serviceContext.invoke,
|
|
2268
2400
|
fetch: this._serviceContext.fetch,
|
|
2269
2401
|
hosts: this._serviceContext.hosts,
|
|
@@ -2328,7 +2460,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2328
2460
|
const shared = wasm.vault_x25519_dh(receiverPrivateKey, peerPublic);
|
|
2329
2461
|
return columnDecrypt(shared, ciphertext);
|
|
2330
2462
|
},
|
|
2331
|
-
verifyNodeSignature: (nodeId, message, signature) => (0,
|
|
2463
|
+
verifyNodeSignature: (nodeId, message, signature) => (0, import_sdk_core7.verifyDidKeyEd25519Signature)(nodeId, message, signature)
|
|
2332
2464
|
};
|
|
2333
2465
|
}
|
|
2334
2466
|
async fetchNodeId() {
|
|
@@ -2399,19 +2531,19 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2399
2531
|
return await response.json();
|
|
2400
2532
|
}
|
|
2401
2533
|
};
|
|
2402
|
-
return new
|
|
2534
|
+
return new import_sdk_core7.EncryptionService({
|
|
2403
2535
|
crypto,
|
|
2404
2536
|
signer: {
|
|
2405
2537
|
signDecryptInvocation: async (input) => {
|
|
2406
2538
|
const signed = await this.signRawNetworkAuthorization({
|
|
2407
2539
|
targetNode: input.targetNode,
|
|
2408
2540
|
networkId: input.networkId,
|
|
2409
|
-
action:
|
|
2541
|
+
action: DECRYPT_ACTION2,
|
|
2410
2542
|
facts: input.facts
|
|
2411
2543
|
});
|
|
2412
2544
|
return {
|
|
2413
2545
|
...signed,
|
|
2414
|
-
canonicalBody: (0,
|
|
2546
|
+
canonicalBody: (0, import_sdk_core7.canonicalizeEncryptionJson)(
|
|
2415
2547
|
input.body
|
|
2416
2548
|
)
|
|
2417
2549
|
};
|
|
@@ -2423,14 +2555,14 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2423
2555
|
},
|
|
2424
2556
|
wellKnown: {
|
|
2425
2557
|
fetchWellKnown: async (principal, discoveryKey) => {
|
|
2426
|
-
if (!this._address || !
|
|
2558
|
+
if (!this._address || !didPrincipalMatches2(principal, this.did)) {
|
|
2427
2559
|
return null;
|
|
2428
2560
|
}
|
|
2429
2561
|
if (!this.config.host) {
|
|
2430
2562
|
return null;
|
|
2431
2563
|
}
|
|
2432
|
-
const publicSpaceId = (0,
|
|
2433
|
-
const result = await
|
|
2564
|
+
const publicSpaceId = (0, import_sdk_core7.makePublicSpaceId)(this._address, this._chainId);
|
|
2565
|
+
const result = await import_sdk_core7.TinyCloud.readPublicSpace(this.config.host, publicSpaceId, discoveryKey);
|
|
2434
2566
|
if (!result.ok) {
|
|
2435
2567
|
return null;
|
|
2436
2568
|
}
|
|
@@ -2453,7 +2585,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2453
2585
|
}
|
|
2454
2586
|
createVaultService(spaceId, kv) {
|
|
2455
2587
|
const wasm = this.wasmBindings;
|
|
2456
|
-
const vaultCrypto = (0,
|
|
2588
|
+
const vaultCrypto = (0, import_sdk_core7.createVaultCrypto)({
|
|
2457
2589
|
vault_encrypt: wasm.vault_encrypt,
|
|
2458
2590
|
vault_decrypt: wasm.vault_decrypt,
|
|
2459
2591
|
vault_derive_key: wasm.vault_derive_key,
|
|
@@ -2463,7 +2595,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2463
2595
|
vault_sha256: wasm.vault_sha256
|
|
2464
2596
|
});
|
|
2465
2597
|
const self = this;
|
|
2466
|
-
return new
|
|
2598
|
+
return new import_sdk_core7.DataVaultService({
|
|
2467
2599
|
spaceId,
|
|
2468
2600
|
crypto: vaultCrypto,
|
|
2469
2601
|
encryption: {
|
|
@@ -2486,8 +2618,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2486
2618
|
get publicKV() {
|
|
2487
2619
|
return self._publicKV ?? self.tc.publicKV;
|
|
2488
2620
|
},
|
|
2489
|
-
readPublicSpace: (host, targetSpaceId, key) =>
|
|
2490
|
-
makePublicSpaceId:
|
|
2621
|
+
readPublicSpace: (host, targetSpaceId, key) => import_sdk_core7.TinyCloud.readPublicSpace(host, targetSpaceId, key),
|
|
2622
|
+
makePublicSpaceId: import_sdk_core7.TinyCloud.makePublicSpaceId,
|
|
2491
2623
|
did: this.did,
|
|
2492
2624
|
address: this._address ?? "",
|
|
2493
2625
|
chainId: this._chainId,
|
|
@@ -2500,7 +2632,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2500
2632
|
* @internal
|
|
2501
2633
|
*/
|
|
2502
2634
|
initializeV2Services(serviceSession) {
|
|
2503
|
-
this._capabilityRegistry = new
|
|
2635
|
+
this._capabilityRegistry = new import_sdk_core7.CapabilityKeyRegistry();
|
|
2504
2636
|
const tcSession = this.auth?.tinyCloudSession;
|
|
2505
2637
|
if (tcSession && this._address) {
|
|
2506
2638
|
const sessionKey = {
|
|
@@ -2574,13 +2706,13 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2574
2706
|
}
|
|
2575
2707
|
this._capabilityRegistry.registerKey(sessionKey, delegations);
|
|
2576
2708
|
}
|
|
2577
|
-
this._delegationManager = new
|
|
2709
|
+
this._delegationManager = new import_sdk_core7.DelegationManager({
|
|
2578
2710
|
hosts: [this.config.host],
|
|
2579
2711
|
session: serviceSession,
|
|
2580
2712
|
invoke: this.invokeWithRuntimePermissions,
|
|
2581
2713
|
fetch: globalThis.fetch.bind(globalThis)
|
|
2582
2714
|
});
|
|
2583
|
-
this._spaceService = new
|
|
2715
|
+
this._spaceService = new import_sdk_core7.SpaceService({
|
|
2584
2716
|
hosts: [this.config.host],
|
|
2585
2717
|
session: serviceSession,
|
|
2586
2718
|
invoke: this.wasmBindings.invoke,
|
|
@@ -2632,6 +2764,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2632
2764
|
}
|
|
2633
2765
|
};
|
|
2634
2766
|
}
|
|
2767
|
+
},
|
|
2768
|
+
onSpaceRegistered: async (space) => {
|
|
2769
|
+
await this.account.spaces.register(space);
|
|
2635
2770
|
}
|
|
2636
2771
|
});
|
|
2637
2772
|
this._sharingService.updateConfig({
|
|
@@ -2737,7 +2872,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2737
2872
|
...prepared,
|
|
2738
2873
|
signature
|
|
2739
2874
|
});
|
|
2740
|
-
const activateResult = await (0,
|
|
2875
|
+
const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
|
|
2741
2876
|
host,
|
|
2742
2877
|
delegationSession.delegationHeader
|
|
2743
2878
|
);
|
|
@@ -2747,7 +2882,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2747
2882
|
return {
|
|
2748
2883
|
cid: delegationSession.delegationCid,
|
|
2749
2884
|
delegateDID: params.shareKeyDID,
|
|
2750
|
-
delegatorDID: (0,
|
|
2885
|
+
delegatorDID: (0, import_sdk_core7.pkhDid)(session.address, session.chainId),
|
|
2751
2886
|
spaceId: params.spaceId,
|
|
2752
2887
|
path: params.path,
|
|
2753
2888
|
actions: params.actions,
|
|
@@ -2804,7 +2939,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2804
2939
|
if (!this._sql) {
|
|
2805
2940
|
const features = this.nodeFeatures;
|
|
2806
2941
|
if (features.length > 0 && !features.includes("sql")) {
|
|
2807
|
-
throw new
|
|
2942
|
+
throw new import_sdk_core7.UnsupportedFeatureError("sql", this.config.host, features);
|
|
2808
2943
|
}
|
|
2809
2944
|
throw new Error("Not signed in. Call signIn() first.");
|
|
2810
2945
|
}
|
|
@@ -2828,8 +2963,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2828
2963
|
if (!this._serviceContext || !this._serviceContext.session) {
|
|
2829
2964
|
throw new Error("Not signed in. Call signIn() first.");
|
|
2830
2965
|
}
|
|
2831
|
-
const sql = new
|
|
2832
|
-
const spaceScopedContext = new
|
|
2966
|
+
const sql = new import_sdk_core7.SQLService({});
|
|
2967
|
+
const spaceScopedContext = new import_sdk_core7.ServiceContext({
|
|
2833
2968
|
invoke: this._serviceContext.invoke,
|
|
2834
2969
|
fetch: this._serviceContext.fetch,
|
|
2835
2970
|
hosts: this._serviceContext.hosts,
|
|
@@ -2857,8 +2992,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2857
2992
|
if (!this._serviceContext || !this._serviceContext.session) {
|
|
2858
2993
|
throw new Error("Not signed in. Call signIn() first.");
|
|
2859
2994
|
}
|
|
2860
|
-
const kv = new
|
|
2861
|
-
const spaceScopedContext = new
|
|
2995
|
+
const kv = new import_sdk_core7.KVService({});
|
|
2996
|
+
const spaceScopedContext = new import_sdk_core7.ServiceContext({
|
|
2862
2997
|
invoke: this._serviceContext.invoke,
|
|
2863
2998
|
fetch: this._serviceContext.fetch,
|
|
2864
2999
|
hosts: this._serviceContext.hosts
|
|
@@ -2874,7 +3009,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2874
3009
|
if (!this._duckdb) {
|
|
2875
3010
|
const features = this.nodeFeatures;
|
|
2876
3011
|
if (features.length > 0 && !features.includes("duckdb")) {
|
|
2877
|
-
throw new
|
|
3012
|
+
throw new import_sdk_core7.UnsupportedFeatureError("duckdb", this.config.host, features);
|
|
2878
3013
|
}
|
|
2879
3014
|
throw new Error("Not signed in. Call signIn() first.");
|
|
2880
3015
|
}
|
|
@@ -2926,16 +3061,16 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2926
3061
|
type: NETWORK_ADMIN_TYPE,
|
|
2927
3062
|
targetNode,
|
|
2928
3063
|
networkId,
|
|
2929
|
-
bodyHash: (0,
|
|
3064
|
+
bodyHash: (0, import_sdk_core7.canonicalHashHex)(
|
|
2930
3065
|
crypto.sha256,
|
|
2931
3066
|
body
|
|
2932
3067
|
),
|
|
2933
|
-
action:
|
|
3068
|
+
action: NETWORK_CREATE_ACTION2
|
|
2934
3069
|
};
|
|
2935
3070
|
const signed = await this.signRawNetworkAuthorization({
|
|
2936
3071
|
targetNode,
|
|
2937
3072
|
networkId,
|
|
2938
|
-
action:
|
|
3073
|
+
action: NETWORK_CREATE_ACTION2,
|
|
2939
3074
|
facts
|
|
2940
3075
|
});
|
|
2941
3076
|
const response = await fetch(`${this.config.host}/encryption/networks`, {
|
|
@@ -2944,7 +3079,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2944
3079
|
Authorization: signed.authorization,
|
|
2945
3080
|
"Content-Type": "application/json"
|
|
2946
3081
|
},
|
|
2947
|
-
body: (0,
|
|
3082
|
+
body: (0, import_sdk_core7.canonicalizeEncryptionJson)(
|
|
2948
3083
|
body
|
|
2949
3084
|
)
|
|
2950
3085
|
});
|
|
@@ -2956,12 +3091,19 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2956
3091
|
const created = await response.json();
|
|
2957
3092
|
return created.descriptor;
|
|
2958
3093
|
}
|
|
2959
|
-
async ensureEncryptionNetwork(
|
|
2960
|
-
const
|
|
3094
|
+
async ensureEncryptionNetwork(nameOrNetworkId = DEFAULT_ENCRYPTION_NETWORK_NAME) {
|
|
3095
|
+
const networkId = nameOrNetworkId.startsWith("urn:tinycloud:encryption:") ? nameOrNetworkId : this.getDefaultEncryptionNetworkId(nameOrNetworkId);
|
|
3096
|
+
const existing = await this.getEncryptionNetwork(networkId);
|
|
2961
3097
|
if (existing) {
|
|
2962
3098
|
return existing;
|
|
2963
3099
|
}
|
|
2964
|
-
|
|
3100
|
+
const parsed = (0, import_sdk_core7.parseNetworkId)(networkId);
|
|
3101
|
+
if (!didPrincipalMatches2(parsed.ownerDid, this.did)) {
|
|
3102
|
+
throw new Error(
|
|
3103
|
+
`Cannot create encryption network ${networkId}: owner ${parsed.ownerDid} does not match signed-in DID ${this.did}`
|
|
3104
|
+
);
|
|
3105
|
+
}
|
|
3106
|
+
return this.createEncryptionNetwork(parsed.name);
|
|
2965
3107
|
}
|
|
2966
3108
|
/**
|
|
2967
3109
|
* App-facing secrets API backed by the `secrets` space vault.
|
|
@@ -2988,7 +3130,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2988
3130
|
throw new Error("Not signed in. Call signIn() first.");
|
|
2989
3131
|
}
|
|
2990
3132
|
if (!this._baseSecrets) {
|
|
2991
|
-
this._baseSecrets = new
|
|
3133
|
+
this._baseSecrets = new import_sdk_core7.SecretsService(() => this.space("secrets").vault);
|
|
2992
3134
|
}
|
|
2993
3135
|
return this._baseSecrets;
|
|
2994
3136
|
}
|
|
@@ -3103,19 +3245,19 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3103
3245
|
async useRuntimeDelegation(delegation) {
|
|
3104
3246
|
const session = this.currentTinyCloudSession();
|
|
3105
3247
|
if (!session) {
|
|
3106
|
-
throw new
|
|
3248
|
+
throw new import_sdk_core7.SessionExpiredError(/* @__PURE__ */ new Date(0));
|
|
3107
3249
|
}
|
|
3108
3250
|
if (delegation.expiry.getTime() <= Date.now()) {
|
|
3109
|
-
throw new
|
|
3251
|
+
throw new import_sdk_core7.SessionExpiredError(delegation.expiry);
|
|
3110
3252
|
}
|
|
3111
3253
|
const expectedDids = [session.verificationMethod, this.sessionDid];
|
|
3112
|
-
if (!expectedDids.some((did) =>
|
|
3254
|
+
if (!expectedDids.some((did) => didPrincipalMatches2(delegation.delegateDID, did))) {
|
|
3113
3255
|
throw new Error(
|
|
3114
3256
|
`Runtime delegation targets ${delegation.delegateDID} but this session key is ${session.verificationMethod}.`
|
|
3115
3257
|
);
|
|
3116
3258
|
}
|
|
3117
3259
|
const targetHost = delegation.host ?? this.config.host;
|
|
3118
|
-
const activateResult = await (0,
|
|
3260
|
+
const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
|
|
3119
3261
|
targetHost,
|
|
3120
3262
|
delegation.delegationHeader
|
|
3121
3263
|
);
|
|
@@ -3142,13 +3284,13 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3142
3284
|
}
|
|
3143
3285
|
const session = this.currentTinyCloudSession();
|
|
3144
3286
|
if (!session) {
|
|
3145
|
-
throw new
|
|
3287
|
+
throw new import_sdk_core7.SessionExpiredError(/* @__PURE__ */ new Date(0));
|
|
3146
3288
|
}
|
|
3147
3289
|
const sessionExpiry = extractSiweExpiration(session.siwe);
|
|
3148
3290
|
if (sessionExpiry !== void 0) {
|
|
3149
3291
|
const marginMs = _TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS;
|
|
3150
3292
|
if (sessionExpiry.getTime() <= Date.now() + marginMs) {
|
|
3151
|
-
throw new
|
|
3293
|
+
throw new import_sdk_core7.SessionExpiredError(sessionExpiry);
|
|
3152
3294
|
}
|
|
3153
3295
|
}
|
|
3154
3296
|
const expanded = this.expandPermissionEntries(permissions);
|
|
@@ -3211,7 +3353,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3211
3353
|
...prepared,
|
|
3212
3354
|
signature
|
|
3213
3355
|
});
|
|
3214
|
-
const activateResult = await (0,
|
|
3356
|
+
const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
|
|
3215
3357
|
this.config.host,
|
|
3216
3358
|
delegatedSession.delegationHeader
|
|
3217
3359
|
);
|
|
@@ -3384,7 +3526,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3384
3526
|
];
|
|
3385
3527
|
const abilities = { kv: { "": kvActions } };
|
|
3386
3528
|
const now = /* @__PURE__ */ new Date();
|
|
3387
|
-
const expiryMs =
|
|
3529
|
+
const expiryMs = import_sdk_core7.EXPIRY.EPHEMERAL_MS;
|
|
3388
3530
|
const expirationTime = new Date(now.getTime() + expiryMs);
|
|
3389
3531
|
const prepared = this.wasmBindings.prepareSession({
|
|
3390
3532
|
abilities,
|
|
@@ -3402,7 +3544,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3402
3544
|
...prepared,
|
|
3403
3545
|
signature
|
|
3404
3546
|
});
|
|
3405
|
-
const activateResult = await (0,
|
|
3547
|
+
const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
|
|
3406
3548
|
this.config.host,
|
|
3407
3549
|
delegationSession.delegationHeader
|
|
3408
3550
|
);
|
|
@@ -3429,8 +3571,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3429
3571
|
}]);
|
|
3430
3572
|
}
|
|
3431
3573
|
if (this._serviceContext) {
|
|
3432
|
-
const publicKV = new
|
|
3433
|
-
const publicContext = new
|
|
3574
|
+
const publicKV = new import_sdk_core7.KVService({ prefix: "" });
|
|
3575
|
+
const publicContext = new import_sdk_core7.ServiceContext({
|
|
3434
3576
|
invoke: this.invokeWithRuntimePermissions,
|
|
3435
3577
|
fetch: this._serviceContext.fetch,
|
|
3436
3578
|
hosts: this._serviceContext.hosts,
|
|
@@ -3557,14 +3699,14 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3557
3699
|
async delegateTo(did, permissions, options) {
|
|
3558
3700
|
const session = this.currentTinyCloudSession();
|
|
3559
3701
|
if (!session) {
|
|
3560
|
-
throw new
|
|
3702
|
+
throw new import_sdk_core7.SessionExpiredError(/* @__PURE__ */ new Date(0));
|
|
3561
3703
|
}
|
|
3562
3704
|
const sessionExpiry = extractSiweExpiration(session.siwe);
|
|
3563
3705
|
if (sessionExpiry !== void 0) {
|
|
3564
3706
|
const now2 = Date.now();
|
|
3565
3707
|
const marginMs = _TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS;
|
|
3566
3708
|
if (sessionExpiry.getTime() <= now2 + marginMs) {
|
|
3567
|
-
throw new
|
|
3709
|
+
throw new import_sdk_core7.SessionExpiredError(sessionExpiry);
|
|
3568
3710
|
}
|
|
3569
3711
|
}
|
|
3570
3712
|
if (!Array.isArray(permissions) || permissions.length === 0) {
|
|
@@ -3593,11 +3735,11 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3593
3735
|
);
|
|
3594
3736
|
return { delegation: delegation2, prompted: true };
|
|
3595
3737
|
}
|
|
3596
|
-
const granted = (0,
|
|
3738
|
+
const granted = (0, import_sdk_core7.parseRecapCapabilities)(
|
|
3597
3739
|
(siwe) => this.wasmBindings.parseRecapFromSiwe(siwe),
|
|
3598
3740
|
session.siwe
|
|
3599
3741
|
);
|
|
3600
|
-
const { subset, missing } = (0,
|
|
3742
|
+
const { subset, missing } = (0, import_sdk_core7.isCapabilitySubset)(expandedEntries, granted);
|
|
3601
3743
|
if (!subset) {
|
|
3602
3744
|
const runtimeGrant = this.findGrantForOperations(
|
|
3603
3745
|
this.permissionEntriesToOperations(expandedEntries, session)
|
|
@@ -3605,7 +3747,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3605
3747
|
if (runtimeGrant) {
|
|
3606
3748
|
const marginMs = _TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS;
|
|
3607
3749
|
if (runtimeGrant.expiresAt.getTime() <= Date.now() + marginMs) {
|
|
3608
|
-
throw new
|
|
3750
|
+
throw new import_sdk_core7.SessionExpiredError(runtimeGrant.expiresAt);
|
|
3609
3751
|
}
|
|
3610
3752
|
const runtimeExpiration = runtimeGrant.expiresAt < effectiveExpiration ? runtimeGrant.expiresAt : effectiveExpiration;
|
|
3611
3753
|
const delegation2 = await this.createDelegationViaRuntimeGrant(
|
|
@@ -3616,7 +3758,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3616
3758
|
);
|
|
3617
3759
|
return { delegation: delegation2, prompted: false };
|
|
3618
3760
|
}
|
|
3619
|
-
throw new
|
|
3761
|
+
throw new import_sdk_core7.PermissionNotInManifestError(missing, granted);
|
|
3620
3762
|
}
|
|
3621
3763
|
const delegation = await this.createDelegationViaWasmPath(
|
|
3622
3764
|
did,
|
|
@@ -3638,7 +3780,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3638
3780
|
);
|
|
3639
3781
|
}
|
|
3640
3782
|
const target = request.delegationTargets.find(
|
|
3641
|
-
(entry) =>
|
|
3783
|
+
(entry) => didPrincipalMatches2(entry.did, did)
|
|
3642
3784
|
);
|
|
3643
3785
|
if (!target) {
|
|
3644
3786
|
throw new Error(`No manifest delegation target found for DID ${did}`);
|
|
@@ -3698,7 +3840,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3698
3840
|
const spaceId = resolvedSpaces.size === 1 ? [...resolvedSpaces][0] : session.spaceId;
|
|
3699
3841
|
const abilities = {};
|
|
3700
3842
|
for (const entry of entries) {
|
|
3701
|
-
const shortService =
|
|
3843
|
+
const shortService = import_sdk_core7.SERVICE_LONG_TO_SHORT[entry.service];
|
|
3702
3844
|
if (shortService === void 0) {
|
|
3703
3845
|
throw new Error(
|
|
3704
3846
|
`delegateTo: unknown service '${entry.service}' \u2014 no short-form mapping`
|
|
@@ -3738,7 +3880,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3738
3880
|
});
|
|
3739
3881
|
const primary = result.resources[0];
|
|
3740
3882
|
const delegationHeader = { Authorization: result.delegation };
|
|
3741
|
-
const activateResult = await (0,
|
|
3883
|
+
const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
|
|
3742
3884
|
this.config.host,
|
|
3743
3885
|
delegationHeader
|
|
3744
3886
|
);
|
|
@@ -3773,7 +3915,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3773
3915
|
const primary = result.resources[0];
|
|
3774
3916
|
const delegationHeader = { Authorization: result.delegation };
|
|
3775
3917
|
const targetHost = grant.delegation.host ?? this.config.host;
|
|
3776
|
-
const activateResult = await (0,
|
|
3918
|
+
const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
|
|
3777
3919
|
targetHost,
|
|
3778
3920
|
delegationHeader
|
|
3779
3921
|
);
|
|
@@ -3814,10 +3956,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3814
3956
|
return this.wasmBindings.makeSpaceId(session.address, session.chainId, space);
|
|
3815
3957
|
}
|
|
3816
3958
|
expandPermissionEntries(permissions) {
|
|
3817
|
-
return (0,
|
|
3959
|
+
return (0, import_sdk_core7.expandPermissionEntries)(permissions);
|
|
3818
3960
|
}
|
|
3819
3961
|
shortServiceName(service) {
|
|
3820
|
-
const short =
|
|
3962
|
+
const short = import_sdk_core7.SERVICE_LONG_TO_SHORT[service];
|
|
3821
3963
|
if (short === void 0) {
|
|
3822
3964
|
throw new Error(
|
|
3823
3965
|
`unknown service '${service}' \u2014 no short-form mapping`
|
|
@@ -3843,7 +3985,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3843
3985
|
return abilities;
|
|
3844
3986
|
}
|
|
3845
3987
|
isEncryptionPermissionEntry(entry) {
|
|
3846
|
-
return entry.service ===
|
|
3988
|
+
return entry.service === import_sdk_core7.ENCRYPTION_PERMISSION_SERVICE && entry.path.startsWith("urn:tinycloud:encryption:");
|
|
3847
3989
|
}
|
|
3848
3990
|
permissionsToRawAbilities(entries) {
|
|
3849
3991
|
const rawAbilities = {};
|
|
@@ -3876,11 +4018,11 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3876
4018
|
}
|
|
3877
4019
|
sessionCoversPermissionEntries(session, entries) {
|
|
3878
4020
|
try {
|
|
3879
|
-
const granted = (0,
|
|
4021
|
+
const granted = (0, import_sdk_core7.parseRecapCapabilities)(
|
|
3880
4022
|
(siwe) => this.wasmBindings.parseRecapFromSiwe(siwe),
|
|
3881
4023
|
session.siwe
|
|
3882
4024
|
);
|
|
3883
|
-
return (0,
|
|
4025
|
+
return (0, import_sdk_core7.isCapabilitySubset)(entries, granted).subset;
|
|
3884
4026
|
} catch {
|
|
3885
4027
|
return false;
|
|
3886
4028
|
}
|
|
@@ -4088,7 +4230,23 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4088
4230
|
if (granted.resource !== void 0 || requested.resource !== void 0) {
|
|
4089
4231
|
return granted.resource !== void 0 && requested.resource !== void 0 && granted.resource === requested.resource && this.pathContains(granted.path, requested.path);
|
|
4090
4232
|
}
|
|
4091
|
-
return granted.spaceId !== void 0 && requested.spaceId !== void 0 && granted.spaceId
|
|
4233
|
+
return granted.spaceId !== void 0 && requested.spaceId !== void 0 && this.spaceIdsEqual(granted.spaceId, requested.spaceId) && this.pathContains(granted.path, requested.path);
|
|
4234
|
+
}
|
|
4235
|
+
// Space IDs are `tinycloud:pkh:eip155:<chain>:<0xADDR>:<name>`. The embedded
|
|
4236
|
+
// EIP-155 address is case-insensitive, but the CLI canonicalizes it to
|
|
4237
|
+
// lowercase when building a space URI while stored runtime delegations keep
|
|
4238
|
+
// the EIP-55 checksummed form — so a byte-for-byte compare spuriously rejects
|
|
4239
|
+
// an otherwise-valid grant. Lowercase ONLY the `eip155:<chain>:0x<addr>`
|
|
4240
|
+
// segment and leave everything else (crucially the case-sensitive space NAME)
|
|
4241
|
+
// byte-exact. Mirrors the CLI's `normalizeSpaceForCompare` (OPENKEY_SCOPE_MISMATCH fix).
|
|
4242
|
+
spaceIdsEqual(a, b) {
|
|
4243
|
+
return this.normalizeSpaceAddress(a) === this.normalizeSpaceAddress(b);
|
|
4244
|
+
}
|
|
4245
|
+
normalizeSpaceAddress(space) {
|
|
4246
|
+
return space.replace(
|
|
4247
|
+
/(eip155:\d+:)(0x[0-9a-fA-F]{40})/,
|
|
4248
|
+
(_match, prefix, addr) => prefix + addr.toLowerCase()
|
|
4249
|
+
);
|
|
4092
4250
|
}
|
|
4093
4251
|
actionContains(grantedAction, requestedAction) {
|
|
4094
4252
|
if (grantedAction === requestedAction) {
|
|
@@ -4195,7 +4353,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4195
4353
|
if (resolvedDelegateDID.endsWith(".eth") && this.config.ensResolver) {
|
|
4196
4354
|
const address = await this.config.ensResolver.resolveAddress(resolvedDelegateDID);
|
|
4197
4355
|
if (!address) throw new Error(`Could not resolve ENS name: ${resolvedDelegateDID}`);
|
|
4198
|
-
resolvedDelegateDID = (0,
|
|
4356
|
+
resolvedDelegateDID = (0, import_sdk_core7.pkhDid)(address, 1);
|
|
4199
4357
|
}
|
|
4200
4358
|
const entries = legacyParamsToPermissionEntries(
|
|
4201
4359
|
params.actions,
|
|
@@ -4210,7 +4368,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4210
4368
|
);
|
|
4211
4369
|
return result.delegation;
|
|
4212
4370
|
} catch (err) {
|
|
4213
|
-
if (err instanceof
|
|
4371
|
+
if (err instanceof import_sdk_core7.PermissionNotInManifestError) {
|
|
4214
4372
|
} else {
|
|
4215
4373
|
throw err;
|
|
4216
4374
|
}
|
|
@@ -4267,7 +4425,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4267
4425
|
...prepared,
|
|
4268
4426
|
signature
|
|
4269
4427
|
});
|
|
4270
|
-
const activateResult = await (0,
|
|
4428
|
+
const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
|
|
4271
4429
|
this.config.host,
|
|
4272
4430
|
delegationSession.delegationHeader
|
|
4273
4431
|
);
|
|
@@ -4289,7 +4447,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4289
4447
|
};
|
|
4290
4448
|
const hasKvActions = params.actions.some((a) => a.startsWith("tinycloud.kv/"));
|
|
4291
4449
|
if (hasKvActions && params.includePublicSpace !== false) {
|
|
4292
|
-
const publicSpaceId = (0,
|
|
4450
|
+
const publicSpaceId = (0, import_sdk_core7.makePublicSpaceId)(
|
|
4293
4451
|
this.wasmBindings.ensureEip55(session.address),
|
|
4294
4452
|
session.chainId
|
|
4295
4453
|
);
|
|
@@ -4312,7 +4470,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4312
4470
|
...publicPrepared,
|
|
4313
4471
|
signature: publicSignature
|
|
4314
4472
|
});
|
|
4315
|
-
const publicActivateResult = await (0,
|
|
4473
|
+
const publicActivateResult = await (0, import_sdk_core7.activateSessionWithHost)(
|
|
4316
4474
|
this.config.host,
|
|
4317
4475
|
publicSession.delegationHeader
|
|
4318
4476
|
);
|
|
@@ -4352,7 +4510,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4352
4510
|
const targetHost = delegation.host ?? this.config.host;
|
|
4353
4511
|
if (this.isSessionOnly) {
|
|
4354
4512
|
const myDid = this.did;
|
|
4355
|
-
if (!
|
|
4513
|
+
if (!didPrincipalMatches2(delegation.delegateDID, myDid)) {
|
|
4356
4514
|
throw new Error(
|
|
4357
4515
|
`Delegation targets ${delegation.delegateDID} but this user's DID is ${myDid}. The delegation must target this user's DID.`
|
|
4358
4516
|
);
|
|
@@ -4417,7 +4575,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4417
4575
|
...prepared,
|
|
4418
4576
|
signature
|
|
4419
4577
|
});
|
|
4420
|
-
const activateResult = await (0,
|
|
4578
|
+
const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
|
|
4421
4579
|
targetHost,
|
|
4422
4580
|
invokerSession.delegationHeader
|
|
4423
4581
|
);
|
|
@@ -4523,7 +4681,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4523
4681
|
...prepared,
|
|
4524
4682
|
signature
|
|
4525
4683
|
});
|
|
4526
|
-
const activateResult = await (0,
|
|
4684
|
+
const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
|
|
4527
4685
|
targetHost,
|
|
4528
4686
|
subDelegationSession.delegationHeader
|
|
4529
4687
|
);
|
|
@@ -4559,7 +4717,7 @@ _TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS = 6e4;
|
|
|
4559
4717
|
var TinyCloudNode = _TinyCloudNode;
|
|
4560
4718
|
|
|
4561
4719
|
// src/core.ts
|
|
4562
|
-
var
|
|
4720
|
+
var import_sdk_core10 = require("@tinycloud/sdk-core");
|
|
4563
4721
|
|
|
4564
4722
|
// src/delegation.ts
|
|
4565
4723
|
function serializeDelegation(delegation) {
|
|
@@ -4578,7 +4736,6 @@ function deserializeDelegation(data) {
|
|
|
4578
4736
|
}
|
|
4579
4737
|
|
|
4580
4738
|
// src/core.ts
|
|
4581
|
-
var import_sdk_core10 = require("@tinycloud/sdk-core");
|
|
4582
4739
|
var import_sdk_core11 = require("@tinycloud/sdk-core");
|
|
4583
4740
|
var import_sdk_core12 = require("@tinycloud/sdk-core");
|
|
4584
4741
|
var import_sdk_core13 = require("@tinycloud/sdk-core");
|
|
@@ -4587,10 +4744,12 @@ var import_sdk_core15 = require("@tinycloud/sdk-core");
|
|
|
4587
4744
|
var import_sdk_core16 = require("@tinycloud/sdk-core");
|
|
4588
4745
|
var import_sdk_core17 = require("@tinycloud/sdk-core");
|
|
4589
4746
|
var import_sdk_core18 = require("@tinycloud/sdk-core");
|
|
4747
|
+
var import_sdk_core19 = require("@tinycloud/sdk-core");
|
|
4590
4748
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4591
4749
|
0 && (module.exports = {
|
|
4592
4750
|
ACCOUNT_REGISTRY_PATH,
|
|
4593
4751
|
ACCOUNT_REGISTRY_SPACE,
|
|
4752
|
+
AccountService,
|
|
4594
4753
|
AutoApproveSpaceCreationHandler,
|
|
4595
4754
|
CapabilityKeyRegistry,
|
|
4596
4755
|
CapabilityKeyRegistryErrorCodes,
|