@tinycloud/node-sdk 2.4.0-beta.8 → 2.4.0
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-iwTdsebf.d.cts → core-DfE4s_Rg.d.cts} +121 -5
- package/dist/{core-iwTdsebf.d.ts → core-DfE4s_Rg.d.ts} +121 -5
- package/dist/core.cjs +715 -247
- 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 +505 -32
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +758 -290
- 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 +505 -32
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/core.cjs
CHANGED
|
@@ -30,95 +30,103 @@ 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
|
-
AccountService: () =>
|
|
36
|
-
AutoApproveSpaceCreationHandler: () =>
|
|
37
|
-
CapabilityKeyRegistry: () =>
|
|
38
|
-
CapabilityKeyRegistryErrorCodes: () =>
|
|
39
|
-
DEFAULT_MANIFEST_SPACE: () =>
|
|
40
|
-
DEFAULT_MANIFEST_VERSION: () =>
|
|
41
|
-
DEFAULT_SIGNED_READ_URL_EXPIRY_MS: () =>
|
|
42
|
-
DataVaultService: () =>
|
|
43
|
-
DatabaseHandle: () =>
|
|
33
|
+
ACCOUNT_REGISTRY_PATH: () => import_sdk_core11.ACCOUNT_REGISTRY_PATH,
|
|
34
|
+
ACCOUNT_REGISTRY_SPACE: () => import_sdk_core11.ACCOUNT_REGISTRY_SPACE,
|
|
35
|
+
AccountService: () => import_sdk_core4.AccountService,
|
|
36
|
+
AutoApproveSpaceCreationHandler: () => import_sdk_core10.AutoApproveSpaceCreationHandler,
|
|
37
|
+
CapabilityKeyRegistry: () => import_sdk_core17.CapabilityKeyRegistry,
|
|
38
|
+
CapabilityKeyRegistryErrorCodes: () => import_sdk_core17.CapabilityKeyRegistryErrorCodes,
|
|
39
|
+
DEFAULT_MANIFEST_SPACE: () => import_sdk_core11.DEFAULT_MANIFEST_SPACE,
|
|
40
|
+
DEFAULT_MANIFEST_VERSION: () => import_sdk_core11.DEFAULT_MANIFEST_VERSION,
|
|
41
|
+
DEFAULT_SIGNED_READ_URL_EXPIRY_MS: () => import_sdk_core12.DEFAULT_SIGNED_READ_URL_EXPIRY_MS,
|
|
42
|
+
DataVaultService: () => import_sdk_core15.DataVaultService,
|
|
43
|
+
DatabaseHandle: () => import_sdk_core13.DatabaseHandle,
|
|
44
44
|
DelegatedAccess: () => DelegatedAccess,
|
|
45
|
-
DelegationErrorCodes: () =>
|
|
46
|
-
DelegationManager: () =>
|
|
47
|
-
DuckDbAction: () =>
|
|
48
|
-
DuckDbDatabaseHandle: () =>
|
|
49
|
-
DuckDbService: () =>
|
|
45
|
+
DelegationErrorCodes: () => import_sdk_core16.DelegationErrorCodes,
|
|
46
|
+
DelegationManager: () => import_sdk_core16.DelegationManager,
|
|
47
|
+
DuckDbAction: () => import_sdk_core14.DuckDbAction,
|
|
48
|
+
DuckDbDatabaseHandle: () => import_sdk_core14.DuckDbDatabaseHandle,
|
|
49
|
+
DuckDbService: () => import_sdk_core14.DuckDbService,
|
|
50
50
|
FileSessionStorage: () => FileSessionStorage,
|
|
51
|
-
IdentityParseError: () =>
|
|
52
|
-
KVService: () =>
|
|
53
|
-
ManifestValidationError: () =>
|
|
51
|
+
IdentityParseError: () => import_sdk_core10.IdentityParseError,
|
|
52
|
+
KVService: () => import_sdk_core12.KVService,
|
|
53
|
+
ManifestValidationError: () => import_sdk_core11.ManifestValidationError,
|
|
54
54
|
MemorySessionStorage: () => MemorySessionStorage,
|
|
55
55
|
NodeUserAuthorization: () => NodeUserAuthorization,
|
|
56
|
-
PermissionNotInManifestError: () =>
|
|
57
|
-
PrefixedKVService: () =>
|
|
58
|
-
ProtocolMismatchError: () =>
|
|
59
|
-
SECRET_NAME_RE: () =>
|
|
60
|
-
SQLAction: () =>
|
|
61
|
-
SQLService: () =>
|
|
62
|
-
SecretsService: () =>
|
|
63
|
-
ServiceContext: () =>
|
|
64
|
-
SessionExpiredError: () =>
|
|
65
|
-
SharingService: () =>
|
|
66
|
-
SilentNotificationHandler: () =>
|
|
67
|
-
Space: () =>
|
|
68
|
-
SpaceErrorCodes: () =>
|
|
69
|
-
SpaceService: () =>
|
|
70
|
-
TinyCloud: () =>
|
|
56
|
+
PermissionNotInManifestError: () => import_sdk_core11.PermissionNotInManifestError,
|
|
57
|
+
PrefixedKVService: () => import_sdk_core12.PrefixedKVService,
|
|
58
|
+
ProtocolMismatchError: () => import_sdk_core19.ProtocolMismatchError,
|
|
59
|
+
SECRET_NAME_RE: () => import_sdk_core15.SECRET_NAME_RE,
|
|
60
|
+
SQLAction: () => import_sdk_core13.SQLAction,
|
|
61
|
+
SQLService: () => import_sdk_core13.SQLService,
|
|
62
|
+
SecretsService: () => import_sdk_core15.SecretsService,
|
|
63
|
+
ServiceContext: () => import_sdk_core20.ServiceContext,
|
|
64
|
+
SessionExpiredError: () => import_sdk_core11.SessionExpiredError,
|
|
65
|
+
SharingService: () => import_sdk_core16.SharingService,
|
|
66
|
+
SilentNotificationHandler: () => import_sdk_core10.SilentNotificationHandler,
|
|
67
|
+
Space: () => import_sdk_core18.Space,
|
|
68
|
+
SpaceErrorCodes: () => import_sdk_core18.SpaceErrorCodes,
|
|
69
|
+
SpaceService: () => import_sdk_core18.SpaceService,
|
|
70
|
+
TinyCloud: () => import_sdk_core9.TinyCloud,
|
|
71
|
+
TinyCloudDebugLogger: () => import_sdk_core10.TinyCloudDebugLogger,
|
|
71
72
|
TinyCloudNode: () => TinyCloudNode,
|
|
72
|
-
UnsupportedFeatureError: () =>
|
|
73
|
-
VAULT_PERMISSION_SERVICE: () =>
|
|
74
|
-
VaultHeaders: () =>
|
|
75
|
-
VaultPublicSpaceKVActions: () =>
|
|
76
|
-
VersionCheckError: () =>
|
|
73
|
+
UnsupportedFeatureError: () => import_sdk_core19.UnsupportedFeatureError,
|
|
74
|
+
VAULT_PERMISSION_SERVICE: () => import_sdk_core11.VAULT_PERMISSION_SERVICE,
|
|
75
|
+
VaultHeaders: () => import_sdk_core15.VaultHeaders,
|
|
76
|
+
VaultPublicSpaceKVActions: () => import_sdk_core15.VaultPublicSpaceKVActions,
|
|
77
|
+
VersionCheckError: () => import_sdk_core19.VersionCheckError,
|
|
77
78
|
WasmKeyProvider: () => WasmKeyProvider,
|
|
78
|
-
addressStorageKey: () =>
|
|
79
|
-
buildSpaceUri: () =>
|
|
80
|
-
canonicalizeAddress: () =>
|
|
81
|
-
canonicalizeDid: () =>
|
|
82
|
-
canonicalizeDidUrl: () =>
|
|
83
|
-
canonicalizeNetworkId: () =>
|
|
84
|
-
canonicalizeSecretScope: () =>
|
|
85
|
-
checkNodeInfo: () =>
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
79
|
+
addressStorageKey: () => import_sdk_core10.addressStorageKey,
|
|
80
|
+
buildSpaceUri: () => import_sdk_core18.buildSpaceUri,
|
|
81
|
+
canonicalizeAddress: () => import_sdk_core10.canonicalizeAddress,
|
|
82
|
+
canonicalizeDid: () => import_sdk_core10.canonicalizeDid,
|
|
83
|
+
canonicalizeDidUrl: () => import_sdk_core10.canonicalizeDidUrl,
|
|
84
|
+
canonicalizeNetworkId: () => import_sdk_core10.canonicalizeNetworkId,
|
|
85
|
+
canonicalizeSecretScope: () => import_sdk_core15.canonicalizeSecretScope,
|
|
86
|
+
checkNodeInfo: () => import_sdk_core19.checkNodeInfo,
|
|
87
|
+
clearTinyCloudDebugLogs: () => import_sdk_core10.clearTinyCloudDebugLogs,
|
|
88
|
+
composeManifestRequest: () => import_sdk_core11.composeManifestRequest,
|
|
89
|
+
createCapabilityKeyRegistry: () => import_sdk_core17.createCapabilityKeyRegistry,
|
|
90
|
+
createOpenKeyCallbackSigningStrategy: () => import_sdk_core2.createOpenKeyCallbackSigningStrategy,
|
|
91
|
+
createSharingService: () => import_sdk_core16.createSharingService,
|
|
92
|
+
createSpaceService: () => import_sdk_core18.createSpaceService,
|
|
93
|
+
createVaultCrypto: () => import_sdk_core15.createVaultCrypto,
|
|
91
94
|
createWasmKeyProvider: () => createWasmKeyProvider,
|
|
92
95
|
defaultSignStrategy: () => defaultSignStrategy,
|
|
93
|
-
defaultSpaceCreationHandler: () =>
|
|
96
|
+
defaultSpaceCreationHandler: () => import_sdk_core10.defaultSpaceCreationHandler,
|
|
94
97
|
deserializeDelegation: () => deserializeDelegation,
|
|
95
|
-
didCacheKey: () =>
|
|
96
|
-
didEquals: () =>
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
98
|
+
didCacheKey: () => import_sdk_core10.didCacheKey,
|
|
99
|
+
didEquals: () => import_sdk_core10.didEquals,
|
|
100
|
+
disableTinyCloudDebug: () => import_sdk_core10.disableTinyCloudDebug,
|
|
101
|
+
enableTinyCloudDebug: () => import_sdk_core10.enableTinyCloudDebug,
|
|
102
|
+
expandActionShortNames: () => import_sdk_core11.expandActionShortNames,
|
|
103
|
+
expandPermissionEntries: () => import_sdk_core11.expandPermissionEntries,
|
|
104
|
+
expandPermissionEntry: () => import_sdk_core11.expandPermissionEntry,
|
|
105
|
+
getTinyCloudDebugLogs: () => import_sdk_core10.getTinyCloudDebugLogs,
|
|
106
|
+
installTinyCloudDebugGlobals: () => import_sdk_core10.installTinyCloudDebugGlobals,
|
|
107
|
+
isCapabilitySubset: () => import_sdk_core11.isCapabilitySubset,
|
|
108
|
+
isEvmAddress: () => import_sdk_core10.isEvmAddress,
|
|
109
|
+
loadManifest: () => import_sdk_core11.loadManifest,
|
|
110
|
+
makePkhSpaceId: () => import_sdk_core10.makePkhSpaceId,
|
|
111
|
+
makePublicSpaceId: () => import_sdk_core18.makePublicSpaceId,
|
|
112
|
+
parseCanonicalNetworkId: () => import_sdk_core10.parseCanonicalNetworkId,
|
|
113
|
+
parseExpiry: () => import_sdk_core11.parseExpiry,
|
|
114
|
+
parsePkhDid: () => import_sdk_core10.parsePkhDid,
|
|
115
|
+
parseSpaceUri: () => import_sdk_core18.parseSpaceUri,
|
|
116
|
+
pkhDid: () => import_sdk_core10.pkhDid,
|
|
117
|
+
principalDid: () => import_sdk_core10.principalDid,
|
|
118
|
+
principalDidEquals: () => import_sdk_core10.principalDidEquals,
|
|
119
|
+
resolveManifest: () => import_sdk_core11.resolveManifest,
|
|
120
|
+
resolveSecretListPrefix: () => import_sdk_core15.resolveSecretListPrefix,
|
|
121
|
+
resolveSecretPath: () => import_sdk_core15.resolveSecretPath,
|
|
122
|
+
resourceCapabilitiesToSpaceAbilitiesMap: () => import_sdk_core11.resourceCapabilitiesToSpaceAbilitiesMap,
|
|
116
123
|
serializeDelegation: () => serializeDelegation,
|
|
117
|
-
|
|
124
|
+
tinyCloudDebugLogger: () => import_sdk_core10.tinyCloudDebugLogger,
|
|
125
|
+
validateManifest: () => import_sdk_core11.validateManifest
|
|
118
126
|
});
|
|
119
127
|
module.exports = __toCommonJS(core_exports);
|
|
120
|
-
var import_sdk_core8 = require("@tinycloud/sdk-core");
|
|
121
128
|
var import_sdk_core9 = require("@tinycloud/sdk-core");
|
|
129
|
+
var import_sdk_core10 = require("@tinycloud/sdk-core");
|
|
122
130
|
|
|
123
131
|
// src/storage/MemorySessionStorage.ts
|
|
124
132
|
var MemorySessionStorage = class {
|
|
@@ -312,9 +320,10 @@ var FileSessionStorage = class {
|
|
|
312
320
|
};
|
|
313
321
|
|
|
314
322
|
// src/authorization/NodeUserAuthorization.ts
|
|
315
|
-
var
|
|
323
|
+
var import_sdk_core3 = require("@tinycloud/sdk-core");
|
|
316
324
|
|
|
317
325
|
// src/authorization/strategies.ts
|
|
326
|
+
var import_sdk_core2 = require("@tinycloud/sdk-core");
|
|
318
327
|
var defaultSignStrategy = { type: "auto-sign" };
|
|
319
328
|
|
|
320
329
|
// src/authorization/NodeUserAuthorization.ts
|
|
@@ -322,7 +331,7 @@ var DECRYPT_ACTION = "tinycloud.encryption/decrypt";
|
|
|
322
331
|
var NETWORK_CREATE_ACTION = "tinycloud.encryption/network.create";
|
|
323
332
|
function didPrincipalMatches(actual, expected) {
|
|
324
333
|
try {
|
|
325
|
-
return (0,
|
|
334
|
+
return (0, import_sdk_core3.principalDidEquals)(actual, expected);
|
|
326
335
|
} catch {
|
|
327
336
|
return actual === expected;
|
|
328
337
|
}
|
|
@@ -341,6 +350,7 @@ var NodeUserAuthorization = class {
|
|
|
341
350
|
constructor(config) {
|
|
342
351
|
this.extensions = [];
|
|
343
352
|
this._nodeFeatures = [];
|
|
353
|
+
this._lastActivationSkippedSpaceIds = [];
|
|
344
354
|
this.wasm = config.wasmBindings;
|
|
345
355
|
this.signer = config.signer;
|
|
346
356
|
this.signStrategy = config.signStrategy ?? defaultSignStrategy;
|
|
@@ -363,7 +373,7 @@ var NodeUserAuthorization = class {
|
|
|
363
373
|
"": [
|
|
364
374
|
"tinycloud.sql/read",
|
|
365
375
|
"tinycloud.sql/write",
|
|
366
|
-
"tinycloud.sql/
|
|
376
|
+
"tinycloud.sql/schema",
|
|
367
377
|
"tinycloud.sql/admin",
|
|
368
378
|
"tinycloud.sql/export"
|
|
369
379
|
]
|
|
@@ -391,7 +401,7 @@ var NodeUserAuthorization = class {
|
|
|
391
401
|
]
|
|
392
402
|
}
|
|
393
403
|
};
|
|
394
|
-
this.sessionExpirationMs = config.sessionExpirationMs ??
|
|
404
|
+
this.sessionExpirationMs = config.sessionExpirationMs ?? import_sdk_core3.EXPIRY.SESSION_MS;
|
|
395
405
|
this.autoCreateSpace = config.autoCreateSpace ?? false;
|
|
396
406
|
this.spaceCreationHandler = config.spaceCreationHandler;
|
|
397
407
|
this.tinycloudHosts = config.tinycloudHosts;
|
|
@@ -455,19 +465,55 @@ var NodeUserAuthorization = class {
|
|
|
455
465
|
* `siwe` is the load-bearing one because `extractSiweExpiration` returns
|
|
456
466
|
* undefined for missing SIWEs and the SDK then treats the session as
|
|
457
467
|
* expired-at-epoch-zero.
|
|
468
|
+
*
|
|
469
|
+
* @param hosts - The TinyCloud hosts this session was created against,
|
|
470
|
+
* as persisted in {@link PersistedSessionData.tinycloudHosts}. When
|
|
471
|
+
* present (and non-empty) they are adopted directly so the restored
|
|
472
|
+
* session resolves to the same node as the original sign-in without
|
|
473
|
+
* re-running registry/fallback resolution. When absent (old session)
|
|
474
|
+
* hosts are resolved lazily on the first host-needing call via
|
|
475
|
+
* {@link ensureTinyCloudHosts}.
|
|
458
476
|
*/
|
|
459
|
-
setRestoredTinyCloudSession(session) {
|
|
460
|
-
const address = (0,
|
|
477
|
+
setRestoredTinyCloudSession(session, hosts) {
|
|
478
|
+
const address = (0, import_sdk_core3.canonicalizeAddress)(session.address);
|
|
461
479
|
this._tinyCloudSession = { ...session, address };
|
|
462
480
|
this._address = address;
|
|
463
481
|
this._chainId = session.chainId;
|
|
482
|
+
if ((!this.tinycloudHosts || this.tinycloudHosts.length === 0) && hosts && hosts.length > 0) {
|
|
483
|
+
this.tinycloudHosts = [...hosts];
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Ensure `tinycloudHosts` are resolved before a host-needing call.
|
|
488
|
+
*
|
|
489
|
+
* Fresh sign-in resolves hosts up front; a restored session may not have
|
|
490
|
+
* (old persisted sessions predate {@link PersistedSessionData.tinycloudHosts}).
|
|
491
|
+
* This guard makes a restored session resolve the node exactly like a fresh
|
|
492
|
+
* sign-in — persisted hosts are preferred (already set by
|
|
493
|
+
* {@link setRestoredTinyCloudSession}), otherwise the registry/fallback
|
|
494
|
+
* resolution runs lazily here. Idempotent: {@link resolveTinyCloudHostsForSignIn}
|
|
495
|
+
* early-returns when hosts are already set.
|
|
496
|
+
*
|
|
497
|
+
* Throws if hosts are unset and the restored session has no address/chainId
|
|
498
|
+
* to resolve from — a real failure that must surface, not be masked.
|
|
499
|
+
*/
|
|
500
|
+
async ensureTinyCloudHosts() {
|
|
501
|
+
if (this.tinycloudHosts && this.tinycloudHosts.length > 0) {
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
if (this._address === void 0 || this._chainId === void 0) {
|
|
505
|
+
throw new Error(
|
|
506
|
+
"Cannot resolve TinyCloud hosts: no address/chainId available. Sign in or restore a session first."
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
await this.resolveTinyCloudHostsForSignIn(this._address, this._chainId);
|
|
464
510
|
}
|
|
465
511
|
async resolveTinyCloudHostsForSignIn(address, chainId) {
|
|
466
512
|
if (this.tinycloudHosts && this.tinycloudHosts.length > 0) {
|
|
467
513
|
return;
|
|
468
514
|
}
|
|
469
|
-
const subject = (0,
|
|
470
|
-
const resolved = await (0,
|
|
515
|
+
const subject = (0, import_sdk_core3.pkhDid)(address, chainId);
|
|
516
|
+
const resolved = await (0, import_sdk_core3.resolveTinyCloudHosts)(subject, {
|
|
471
517
|
registryUrl: this.tinycloudRegistryUrl,
|
|
472
518
|
fallbackHosts: this.tinycloudFallbackHosts
|
|
473
519
|
});
|
|
@@ -485,6 +531,9 @@ var NodeUserAuthorization = class {
|
|
|
485
531
|
get nodeFeatures() {
|
|
486
532
|
return this._nodeFeatures;
|
|
487
533
|
}
|
|
534
|
+
get lastActivationSkippedSpaceIds() {
|
|
535
|
+
return [...this._lastActivationSkippedSpaceIds];
|
|
536
|
+
}
|
|
488
537
|
/**
|
|
489
538
|
* Compute the `abilities` map the WASM `prepareSession` call should
|
|
490
539
|
* see at sign-in time.
|
|
@@ -518,7 +567,7 @@ var NodeUserAuthorization = class {
|
|
|
518
567
|
if (this._manifest === void 0) {
|
|
519
568
|
return void 0;
|
|
520
569
|
}
|
|
521
|
-
this._capabilityRequest = (0,
|
|
570
|
+
this._capabilityRequest = (0, import_sdk_core3.composeManifestRequest)(
|
|
522
571
|
Array.isArray(this._manifest) ? this._manifest : [this._manifest],
|
|
523
572
|
{
|
|
524
573
|
includeAccountRegistryPermissions: this.includeAccountRegistryPermissions
|
|
@@ -530,17 +579,17 @@ var NodeUserAuthorization = class {
|
|
|
530
579
|
if (space.startsWith("tinycloud:")) {
|
|
531
580
|
return space;
|
|
532
581
|
}
|
|
533
|
-
return (0,
|
|
582
|
+
return (0, import_sdk_core3.makePkhSpaceId)(address, chainId, space);
|
|
534
583
|
}
|
|
535
584
|
defaultEncryptionNetworkId(address, chainId) {
|
|
536
|
-
return `urn:tinycloud:encryption:${(0,
|
|
585
|
+
return `urn:tinycloud:encryption:${(0, import_sdk_core3.pkhDid)(address, chainId)}:default`;
|
|
537
586
|
}
|
|
538
587
|
resolveSignInCapabilities(address, chainId) {
|
|
539
588
|
const request = this.getCapabilityRequest();
|
|
540
589
|
if (request === void 0) {
|
|
541
590
|
const defaultNetworkId = this.defaultEncryptionNetworkId(address, chainId);
|
|
542
|
-
const primarySpaceId2 = (0,
|
|
543
|
-
const secretsSpaceId = (0,
|
|
591
|
+
const primarySpaceId2 = (0, import_sdk_core3.makePkhSpaceId)(address, chainId, this.spacePrefix);
|
|
592
|
+
const secretsSpaceId = (0, import_sdk_core3.makePkhSpaceId)(address, chainId, "secrets");
|
|
544
593
|
return {
|
|
545
594
|
abilities: this.defaultActions,
|
|
546
595
|
spaceId: primarySpaceId2,
|
|
@@ -567,35 +616,35 @@ var NodeUserAuthorization = class {
|
|
|
567
616
|
};
|
|
568
617
|
}
|
|
569
618
|
const rawAbilities = {};
|
|
570
|
-
const currentDid = (0,
|
|
619
|
+
const currentDid = (0, import_sdk_core3.pkhDid)(address, chainId);
|
|
571
620
|
const spaceResources = request.resources.filter((entry) => {
|
|
572
|
-
if (entry.service !==
|
|
621
|
+
if (entry.service !== import_sdk_core3.ENCRYPTION_PERMISSION_SERVICE) {
|
|
573
622
|
return true;
|
|
574
623
|
}
|
|
575
624
|
for (const action of entry.actions) {
|
|
576
625
|
addRawAbility(rawAbilities, entry.path, action);
|
|
577
626
|
}
|
|
578
627
|
if (entry.actions.includes(DECRYPT_ACTION)) {
|
|
579
|
-
const parsed = (0,
|
|
628
|
+
const parsed = (0, import_sdk_core3.parseNetworkId)(entry.path);
|
|
580
629
|
if (didPrincipalMatches(parsed.ownerDid, currentDid)) {
|
|
581
630
|
addRawAbility(rawAbilities, entry.path, NETWORK_CREATE_ACTION);
|
|
582
631
|
}
|
|
583
632
|
}
|
|
584
633
|
return false;
|
|
585
634
|
});
|
|
586
|
-
const primarySpaceName = spaceResources.find((entry) => entry.space !== "account")?.space ??
|
|
635
|
+
const primarySpaceName = spaceResources.find((entry) => entry.space !== "account")?.space ?? import_sdk_core3.DEFAULT_MANIFEST_SPACE;
|
|
587
636
|
const primarySpaceId = this.resolveSpaceName(
|
|
588
637
|
primarySpaceName,
|
|
589
638
|
address,
|
|
590
639
|
chainId
|
|
591
640
|
);
|
|
592
|
-
const bySpace = (0,
|
|
641
|
+
const bySpace = (0, import_sdk_core3.resourceCapabilitiesToSpaceAbilitiesMap)(spaceResources);
|
|
593
642
|
const spaceAbilities = {};
|
|
594
643
|
for (const [space, abilities] of Object.entries(bySpace)) {
|
|
595
644
|
spaceAbilities[this.resolveSpaceName(space, address, chainId)] = abilities;
|
|
596
645
|
}
|
|
597
646
|
return {
|
|
598
|
-
abilities: spaceAbilities[primarySpaceId] ?? (0,
|
|
647
|
+
abilities: spaceAbilities[primarySpaceId] ?? (0, import_sdk_core3.resourceCapabilitiesToAbilitiesMap)([]),
|
|
599
648
|
spaceId: primarySpaceId,
|
|
600
649
|
spaceAbilities,
|
|
601
650
|
rawAbilities: Object.keys(rawAbilities).length > 0 ? rawAbilities : void 0
|
|
@@ -657,9 +706,10 @@ var NodeUserAuthorization = class {
|
|
|
657
706
|
if (!this._tinyCloudSession || !this._address || !this._chainId) {
|
|
658
707
|
throw new Error("Must be signed in to host space");
|
|
659
708
|
}
|
|
709
|
+
await this.ensureTinyCloudHosts();
|
|
660
710
|
const host = this.primaryTinyCloudHost;
|
|
661
711
|
const spaceId = targetSpaceId ?? this._tinyCloudSession.spaceId;
|
|
662
|
-
const peerId = await (0,
|
|
712
|
+
const peerId = await (0, import_sdk_core3.fetchPeerId)(host, spaceId);
|
|
663
713
|
const siwe = this.wasm.generateHostSIWEMessage({
|
|
664
714
|
address: this._address,
|
|
665
715
|
chainId: this._chainId,
|
|
@@ -670,7 +720,7 @@ var NodeUserAuthorization = class {
|
|
|
670
720
|
});
|
|
671
721
|
const signature = await this.signMessage(siwe);
|
|
672
722
|
const headers = this.wasm.siweToDelegationHeaders({ siwe, signature });
|
|
673
|
-
const result = await (0,
|
|
723
|
+
const result = await (0, import_sdk_core3.submitHostDelegation)(host, headers);
|
|
674
724
|
return result.success;
|
|
675
725
|
}
|
|
676
726
|
/**
|
|
@@ -699,13 +749,15 @@ var NodeUserAuthorization = class {
|
|
|
699
749
|
if (!this._tinyCloudSession) {
|
|
700
750
|
throw new Error("Must be signed in to ensure space exists");
|
|
701
751
|
}
|
|
752
|
+
await this.ensureTinyCloudHosts();
|
|
702
753
|
const host = this.primaryTinyCloudHost;
|
|
703
754
|
const primarySpaceId = this._tinyCloudSession.spaceId;
|
|
704
|
-
const result = await (0,
|
|
755
|
+
const result = await (0, import_sdk_core3.activateSessionWithHost)(
|
|
705
756
|
host,
|
|
706
757
|
this._tinyCloudSession.delegationHeader
|
|
707
758
|
);
|
|
708
|
-
|
|
759
|
+
this.recordActivationSkippedSpaces(result, primarySpaceId);
|
|
760
|
+
const handler = this.spaceCreationHandler ?? (this.autoCreateSpace ? new import_sdk_core3.AutoApproveSpaceCreationHandler() : void 0);
|
|
709
761
|
const creationContext = {
|
|
710
762
|
spaceId: primarySpaceId,
|
|
711
763
|
address: this._address,
|
|
@@ -739,7 +791,7 @@ var NodeUserAuthorization = class {
|
|
|
739
791
|
throw error;
|
|
740
792
|
}
|
|
741
793
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
742
|
-
const retryResult = await (0,
|
|
794
|
+
const retryResult = await (0, import_sdk_core3.activateSessionWithHost)(
|
|
743
795
|
host,
|
|
744
796
|
this._tinyCloudSession.delegationHeader
|
|
745
797
|
);
|
|
@@ -776,7 +828,7 @@ var NodeUserAuthorization = class {
|
|
|
776
828
|
throw error;
|
|
777
829
|
}
|
|
778
830
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
779
|
-
const retryResult = await (0,
|
|
831
|
+
const retryResult = await (0, import_sdk_core3.activateSessionWithHost)(
|
|
780
832
|
host,
|
|
781
833
|
this._tinyCloudSession.delegationHeader
|
|
782
834
|
);
|
|
@@ -792,6 +844,66 @@ var NodeUserAuthorization = class {
|
|
|
792
844
|
}
|
|
793
845
|
throw new Error(`Failed to activate session: ${result.error}`);
|
|
794
846
|
}
|
|
847
|
+
recordActivationSkippedSpaces(result, primarySpaceId) {
|
|
848
|
+
if (result.success) {
|
|
849
|
+
this._lastActivationSkippedSpaceIds = result.skipped ?? [];
|
|
850
|
+
return;
|
|
851
|
+
}
|
|
852
|
+
this._lastActivationSkippedSpaceIds = result.status === 404 ? [primarySpaceId] : [];
|
|
853
|
+
}
|
|
854
|
+
async createBootstrapSession(options) {
|
|
855
|
+
if (!this._address || !this._chainId) {
|
|
856
|
+
throw new Error("Must be signed in before creating bootstrap sessions");
|
|
857
|
+
}
|
|
858
|
+
const address = this._address;
|
|
859
|
+
const chainId = this._chainId;
|
|
860
|
+
const keyId = `bootstrap-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
861
|
+
this.sessionManager.createSessionKey(keyId);
|
|
862
|
+
const jwkString = this.sessionManager.jwk(keyId);
|
|
863
|
+
if (!jwkString) {
|
|
864
|
+
throw new Error("Failed to create bootstrap session key");
|
|
865
|
+
}
|
|
866
|
+
const jwk = JSON.parse(jwkString);
|
|
867
|
+
const now = /* @__PURE__ */ new Date();
|
|
868
|
+
const expirationTime = new Date(now.getTime() + this.sessionExpirationMs);
|
|
869
|
+
const abilities = (0, import_sdk_core3.resourceCapabilitiesToAbilitiesMap)(
|
|
870
|
+
options.capabilityRequest.resources
|
|
871
|
+
);
|
|
872
|
+
const prepared = this.wasm.prepareSession({
|
|
873
|
+
abilities,
|
|
874
|
+
...options.rawAbilities !== void 0 ? { rawAbilities: options.rawAbilities } : {},
|
|
875
|
+
address,
|
|
876
|
+
chainId,
|
|
877
|
+
domain: this.domain,
|
|
878
|
+
issuedAt: now.toISOString(),
|
|
879
|
+
expirationTime: expirationTime.toISOString(),
|
|
880
|
+
spaceId: options.spaceId,
|
|
881
|
+
jwk,
|
|
882
|
+
...this.buildSiweOverrides()
|
|
883
|
+
});
|
|
884
|
+
const signature = await this.requestSignature({
|
|
885
|
+
address,
|
|
886
|
+
chainId,
|
|
887
|
+
message: prepared.siwe,
|
|
888
|
+
type: "siwe"
|
|
889
|
+
});
|
|
890
|
+
const session = this.wasm.completeSessionSetup({
|
|
891
|
+
...prepared,
|
|
892
|
+
signature
|
|
893
|
+
});
|
|
894
|
+
return {
|
|
895
|
+
address,
|
|
896
|
+
chainId,
|
|
897
|
+
sessionKey: keyId,
|
|
898
|
+
spaceId: options.spaceId,
|
|
899
|
+
delegationCid: session.delegationCid,
|
|
900
|
+
delegationHeader: session.delegationHeader,
|
|
901
|
+
verificationMethod: this.sessionManager.getDID(keyId),
|
|
902
|
+
jwk,
|
|
903
|
+
siwe: prepared.siwe,
|
|
904
|
+
signature
|
|
905
|
+
};
|
|
906
|
+
}
|
|
795
907
|
/**
|
|
796
908
|
* Sign in and create a new session.
|
|
797
909
|
*
|
|
@@ -804,7 +916,7 @@ var NodeUserAuthorization = class {
|
|
|
804
916
|
* @param options - Optional per-call SIWE overrides for this sign-in only
|
|
805
917
|
*/
|
|
806
918
|
async signIn(options) {
|
|
807
|
-
this._address = (0,
|
|
919
|
+
this._address = (0, import_sdk_core3.canonicalizeAddress)(await this.signer.getAddress());
|
|
808
920
|
this._chainId = await this.signer.getChainId();
|
|
809
921
|
const address = this._address;
|
|
810
922
|
const chainId = this._chainId;
|
|
@@ -851,7 +963,7 @@ var NodeUserAuthorization = class {
|
|
|
851
963
|
siwe: prepared.siwe,
|
|
852
964
|
signature
|
|
853
965
|
};
|
|
854
|
-
const spacesMetadata = this.enablePublicSpace ? { public: (0,
|
|
966
|
+
const spacesMetadata = this.enablePublicSpace ? { public: (0, import_sdk_core3.makePkhSpaceId)(address, chainId, "public") } : void 0;
|
|
855
967
|
const tinyCloudSession = {
|
|
856
968
|
address,
|
|
857
969
|
chainId,
|
|
@@ -880,14 +992,15 @@ var NodeUserAuthorization = class {
|
|
|
880
992
|
},
|
|
881
993
|
expiresAt: expirationTime.toISOString(),
|
|
882
994
|
createdAt: now.toISOString(),
|
|
883
|
-
version: "1.0"
|
|
995
|
+
version: "1.0",
|
|
996
|
+
tinycloudHosts: this.tinycloudHosts
|
|
884
997
|
};
|
|
885
998
|
await this.sessionStorage.save(address, persistedData);
|
|
886
999
|
this._session = clientSession;
|
|
887
1000
|
this._tinyCloudSession = tinyCloudSession;
|
|
888
1001
|
this._address = address;
|
|
889
1002
|
this._chainId = chainId;
|
|
890
|
-
const nodeInfo = await (0,
|
|
1003
|
+
const nodeInfo = await (0, import_sdk_core3.checkNodeInfo)(
|
|
891
1004
|
this.primaryTinyCloudHost,
|
|
892
1005
|
this.wasm.protocolVersion()
|
|
893
1006
|
);
|
|
@@ -926,7 +1039,7 @@ var NodeUserAuthorization = class {
|
|
|
926
1039
|
*/
|
|
927
1040
|
async signMessage(message) {
|
|
928
1041
|
if (!this._address) {
|
|
929
|
-
this._address = (0,
|
|
1042
|
+
this._address = (0, import_sdk_core3.canonicalizeAddress)(await this.signer.getAddress());
|
|
930
1043
|
}
|
|
931
1044
|
if (!this._chainId) {
|
|
932
1045
|
this._chainId = await this.signer.getChainId();
|
|
@@ -953,7 +1066,7 @@ var NodeUserAuthorization = class {
|
|
|
953
1066
|
* ```
|
|
954
1067
|
*/
|
|
955
1068
|
async prepareSessionForSigning() {
|
|
956
|
-
const address = (0,
|
|
1069
|
+
const address = (0, import_sdk_core3.canonicalizeAddress)(await this.signer.getAddress());
|
|
957
1070
|
const chainId = await this.signer.getChainId();
|
|
958
1071
|
const keyId = `session-${Date.now()}`;
|
|
959
1072
|
this.sessionManager.renameSessionKeyId("default", keyId);
|
|
@@ -1003,7 +1116,7 @@ var NodeUserAuthorization = class {
|
|
|
1003
1116
|
...prepared,
|
|
1004
1117
|
signature
|
|
1005
1118
|
});
|
|
1006
|
-
const address = (0,
|
|
1119
|
+
const address = (0, import_sdk_core3.canonicalizeAddress)(await this.signer.getAddress());
|
|
1007
1120
|
const chainId = await this.signer.getChainId();
|
|
1008
1121
|
await this.resolveTinyCloudHostsForSignIn(address, chainId);
|
|
1009
1122
|
const clientSession = {
|
|
@@ -1014,7 +1127,7 @@ var NodeUserAuthorization = class {
|
|
|
1014
1127
|
siwe: prepared.siwe,
|
|
1015
1128
|
signature
|
|
1016
1129
|
};
|
|
1017
|
-
const spacesMetadata = this.enablePublicSpace ? { public: (0,
|
|
1130
|
+
const spacesMetadata = this.enablePublicSpace ? { public: (0, import_sdk_core3.makePkhSpaceId)(address, chainId, "public") } : void 0;
|
|
1018
1131
|
const tinyCloudSession = {
|
|
1019
1132
|
address,
|
|
1020
1133
|
chainId,
|
|
@@ -1047,14 +1160,15 @@ var NodeUserAuthorization = class {
|
|
|
1047
1160
|
},
|
|
1048
1161
|
expiresAt,
|
|
1049
1162
|
createdAt,
|
|
1050
|
-
version: "1.0"
|
|
1163
|
+
version: "1.0",
|
|
1164
|
+
tinycloudHosts: this.tinycloudHosts
|
|
1051
1165
|
};
|
|
1052
1166
|
await this.sessionStorage.save(address, persistedData);
|
|
1053
1167
|
this._session = clientSession;
|
|
1054
1168
|
this._tinyCloudSession = tinyCloudSession;
|
|
1055
1169
|
this._address = address;
|
|
1056
1170
|
this._chainId = chainId;
|
|
1057
|
-
const nodeInfo = await (0,
|
|
1171
|
+
const nodeInfo = await (0, import_sdk_core3.checkNodeInfo)(
|
|
1058
1172
|
this.primaryTinyCloudHost,
|
|
1059
1173
|
this.wasm.protocolVersion()
|
|
1060
1174
|
);
|
|
@@ -1138,35 +1252,36 @@ var NodeUserAuthorization = class {
|
|
|
1138
1252
|
};
|
|
1139
1253
|
|
|
1140
1254
|
// src/TinyCloudNode.ts
|
|
1141
|
-
var
|
|
1255
|
+
var import_sdk_core8 = require("@tinycloud/sdk-core");
|
|
1142
1256
|
|
|
1143
1257
|
// src/account/AccountService.ts
|
|
1144
|
-
var
|
|
1258
|
+
var import_sdk_core4 = require("@tinycloud/sdk-core");
|
|
1145
1259
|
|
|
1146
1260
|
// src/DelegatedAccess.ts
|
|
1147
|
-
var
|
|
1261
|
+
var import_sdk_core5 = require("@tinycloud/sdk-core");
|
|
1148
1262
|
var DelegatedAccess = class {
|
|
1149
|
-
constructor(session, delegation, host, invoke, telemetry) {
|
|
1263
|
+
constructor(session, delegation, host, invoke, invokeAny, telemetry) {
|
|
1150
1264
|
this.session = session;
|
|
1151
1265
|
this._delegation = delegation;
|
|
1152
1266
|
this.host = host;
|
|
1153
|
-
this._serviceContext = new
|
|
1267
|
+
this._serviceContext = new import_sdk_core5.ServiceContext({
|
|
1154
1268
|
invoke,
|
|
1269
|
+
invokeAny,
|
|
1155
1270
|
fetch: globalThis.fetch.bind(globalThis),
|
|
1156
1271
|
hosts: [host],
|
|
1157
1272
|
telemetry
|
|
1158
1273
|
});
|
|
1159
1274
|
const prefix = this._delegation.path.replace(/\/$/, "");
|
|
1160
|
-
this._kv = new
|
|
1275
|
+
this._kv = new import_sdk_core5.KVService({ prefix });
|
|
1161
1276
|
this._kv.initialize(this._serviceContext);
|
|
1162
1277
|
this._serviceContext.registerService("kv", this._kv);
|
|
1163
|
-
this._sql = new
|
|
1278
|
+
this._sql = new import_sdk_core5.SQLService({});
|
|
1164
1279
|
this._sql.initialize(this._serviceContext);
|
|
1165
1280
|
this._serviceContext.registerService("sql", this._sql);
|
|
1166
|
-
this._duckdb = new
|
|
1281
|
+
this._duckdb = new import_sdk_core5.DuckDbService({});
|
|
1167
1282
|
this._duckdb.initialize(this._serviceContext);
|
|
1168
1283
|
this._serviceContext.registerService("duckdb", this._duckdb);
|
|
1169
|
-
this._hooks = new
|
|
1284
|
+
this._hooks = new import_sdk_core5.HooksService({});
|
|
1170
1285
|
this._hooks.initialize(this._serviceContext);
|
|
1171
1286
|
this._serviceContext.registerService("hooks", this._hooks);
|
|
1172
1287
|
const serviceSession = {
|
|
@@ -1316,7 +1431,7 @@ function createWasmKeyProvider(sessionManager) {
|
|
|
1316
1431
|
}
|
|
1317
1432
|
|
|
1318
1433
|
// src/delegateToHelpers.ts
|
|
1319
|
-
var
|
|
1434
|
+
var import_sdk_core6 = require("@tinycloud/sdk-core");
|
|
1320
1435
|
function legacyParamsToPermissionEntries(actions, path, spaceIdOverride) {
|
|
1321
1436
|
const byService = /* @__PURE__ */ new Map();
|
|
1322
1437
|
for (const a of actions) {
|
|
@@ -1347,7 +1462,7 @@ function legacyParamsToPermissionEntries(actions, path, spaceIdOverride) {
|
|
|
1347
1462
|
}
|
|
1348
1463
|
return entries;
|
|
1349
1464
|
}
|
|
1350
|
-
var DEFAULT_DELEGATION_EXPIRY_MS =
|
|
1465
|
+
var DEFAULT_DELEGATION_EXPIRY_MS = import_sdk_core6.EXPIRY.SESSION_MS;
|
|
1351
1466
|
function resolveExpiryMs(expiry) {
|
|
1352
1467
|
if (expiry === void 0) {
|
|
1353
1468
|
return DEFAULT_DELEGATION_EXPIRY_MS;
|
|
@@ -1360,10 +1475,10 @@ function resolveExpiryMs(expiry) {
|
|
|
1360
1475
|
}
|
|
1361
1476
|
return expiry;
|
|
1362
1477
|
}
|
|
1363
|
-
return (0,
|
|
1478
|
+
return (0, import_sdk_core6.parseExpiry)(expiry);
|
|
1364
1479
|
}
|
|
1365
1480
|
function extractSiweExpiration(siwe) {
|
|
1366
|
-
const parsed = new
|
|
1481
|
+
const parsed = new import_sdk_core6.SiweMessage(siwe);
|
|
1367
1482
|
if (parsed.expirationTime === void 0 || parsed.expirationTime === null) {
|
|
1368
1483
|
return void 0;
|
|
1369
1484
|
}
|
|
@@ -1377,7 +1492,7 @@ function extractSiweExpiration(siwe) {
|
|
|
1377
1492
|
}
|
|
1378
1493
|
|
|
1379
1494
|
// src/NodeSecretsService.ts
|
|
1380
|
-
var
|
|
1495
|
+
var import_sdk_core7 = require("@tinycloud/sdk-core");
|
|
1381
1496
|
var SECRETS_SPACE = "secrets";
|
|
1382
1497
|
function ok() {
|
|
1383
1498
|
return { ok: true, data: void 0 };
|
|
@@ -1410,7 +1525,7 @@ function secretActionName(action) {
|
|
|
1410
1525
|
}
|
|
1411
1526
|
function secretPermissionEntries(name, options, action, encryptionNetworkId) {
|
|
1412
1527
|
const entries = [];
|
|
1413
|
-
const path = action === "list" ? (0,
|
|
1528
|
+
const path = action === "list" ? (0, import_sdk_core7.resolveSecretListPrefix)(options) : (0, import_sdk_core7.resolveSecretPath)(name, options).permissionPaths.vault;
|
|
1414
1529
|
entries.push({
|
|
1415
1530
|
service: "tinycloud.kv",
|
|
1416
1531
|
space: SECRETS_SPACE,
|
|
@@ -1489,7 +1604,7 @@ var NodeSecretsService = class {
|
|
|
1489
1604
|
);
|
|
1490
1605
|
} catch (error) {
|
|
1491
1606
|
return secretsError(
|
|
1492
|
-
|
|
1607
|
+
import_sdk_core7.ErrorCodes.INVALID_INPUT,
|
|
1493
1608
|
error instanceof Error ? error.message : String(error),
|
|
1494
1609
|
error instanceof Error ? error : void 0
|
|
1495
1610
|
);
|
|
@@ -1499,7 +1614,7 @@ var NodeSecretsService = class {
|
|
|
1499
1614
|
}
|
|
1500
1615
|
if (!this.config.canEscalate()) {
|
|
1501
1616
|
return secretsError(
|
|
1502
|
-
|
|
1617
|
+
import_sdk_core7.ErrorCodes.PERMISSION_DENIED,
|
|
1503
1618
|
`Cannot autosign ${displayActionUrn(action)} for ${target}; TinyCloudNode needs wallet mode with a signer or privateKey.`
|
|
1504
1619
|
);
|
|
1505
1620
|
}
|
|
@@ -1508,7 +1623,7 @@ var NodeSecretsService = class {
|
|
|
1508
1623
|
return this.restoreUnlockAfterEscalation();
|
|
1509
1624
|
} catch (error) {
|
|
1510
1625
|
return secretsError(
|
|
1511
|
-
|
|
1626
|
+
import_sdk_core7.ErrorCodes.PERMISSION_DENIED,
|
|
1512
1627
|
error instanceof Error ? error.message : `Autosign escalation for ${displayActionUrn(action)} on ${target} failed.`,
|
|
1513
1628
|
error instanceof Error ? error : void 0
|
|
1514
1629
|
);
|
|
@@ -1529,10 +1644,10 @@ var NodeSecretsService = class {
|
|
|
1529
1644
|
return false;
|
|
1530
1645
|
}
|
|
1531
1646
|
const manifests = Array.isArray(manifest) ? manifest : [manifest];
|
|
1532
|
-
const requestedEntries = (0,
|
|
1647
|
+
const requestedEntries = (0, import_sdk_core7.expandPermissionEntries)(permissionEntries);
|
|
1533
1648
|
return requestedEntries.every(
|
|
1534
1649
|
(entry) => manifests.some((candidate) => {
|
|
1535
|
-
const resolved = (0,
|
|
1650
|
+
const resolved = (0, import_sdk_core7.resolveManifest)(candidate);
|
|
1536
1651
|
return resolved.resources.some(
|
|
1537
1652
|
(resource) => resource.service === entry.service && resource.space === entry.space && resource.path === entry.path && entry.actions.every((action) => resource.actions.includes(action))
|
|
1538
1653
|
);
|
|
@@ -1547,10 +1662,13 @@ var DEFAULT_ENCRYPTION_NETWORK_NAME = "default";
|
|
|
1547
1662
|
var NETWORK_CREATE_ACTION2 = "tinycloud.encryption/network.create";
|
|
1548
1663
|
var DECRYPT_ACTION2 = "tinycloud.encryption/decrypt";
|
|
1549
1664
|
var NETWORK_ADMIN_TYPE = "tinycloud.encryption.network-admin/v1";
|
|
1550
|
-
var DEFAULT_SESSION_EXPIRATION_MS =
|
|
1665
|
+
var DEFAULT_SESSION_EXPIRATION_MS = import_sdk_core8.EXPIRY.SESSION_MS;
|
|
1666
|
+
function isOpenKeyAutoSignStrategy(strategy) {
|
|
1667
|
+
return strategy?.openKeyAutoSign === true;
|
|
1668
|
+
}
|
|
1551
1669
|
function didPrincipalMatches2(actual, expected) {
|
|
1552
1670
|
try {
|
|
1553
|
-
return (0,
|
|
1671
|
+
return (0, import_sdk_core8.principalDidEquals)(actual, expected);
|
|
1554
1672
|
} catch {
|
|
1555
1673
|
return actual === expected;
|
|
1556
1674
|
}
|
|
@@ -1716,12 +1834,12 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1716
1834
|
throw new Error("Failed to get session key JWK");
|
|
1717
1835
|
}
|
|
1718
1836
|
this.sessionKeyJwk = JSON.parse(jwkStr);
|
|
1719
|
-
this._capabilityRegistry = new
|
|
1837
|
+
this._capabilityRegistry = new import_sdk_core8.CapabilityKeyRegistry();
|
|
1720
1838
|
this._keyProvider = new WasmKeyProvider({
|
|
1721
1839
|
sessionManager: this.sessionManager
|
|
1722
1840
|
});
|
|
1723
|
-
this.notificationHandler = config.notificationHandler ?? new
|
|
1724
|
-
this._sharingService = new
|
|
1841
|
+
this.notificationHandler = config.notificationHandler ?? new import_sdk_core8.SilentNotificationHandler();
|
|
1842
|
+
this._sharingService = new import_sdk_core8.SharingService({
|
|
1725
1843
|
hosts: [this.config.host],
|
|
1726
1844
|
// session: undefined - not needed for receive()
|
|
1727
1845
|
invoke: this.invokeWithRuntimePermissions,
|
|
@@ -1731,8 +1849,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1731
1849
|
// delegationManager: undefined - not needed for receive()
|
|
1732
1850
|
createKVService: (config2) => {
|
|
1733
1851
|
const prefix = config2.pathPrefix?.replace(/\/$/, "");
|
|
1734
|
-
const kvService = new
|
|
1735
|
-
const kvContext = new
|
|
1852
|
+
const kvService = new import_sdk_core8.KVService({ prefix });
|
|
1853
|
+
const kvContext = new import_sdk_core8.ServiceContext({
|
|
1736
1854
|
invoke: config2.invoke,
|
|
1737
1855
|
fetch: config2.fetch ?? globalThis.fetch.bind(globalThis),
|
|
1738
1856
|
hosts: config2.hosts,
|
|
@@ -1772,9 +1890,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1772
1890
|
* @internal
|
|
1773
1891
|
*/
|
|
1774
1892
|
setupAuth(config) {
|
|
1893
|
+
const useBootstrapSignInRequest = this.shouldUseBootstrapSignInRequest(config);
|
|
1775
1894
|
this.auth = new NodeUserAuthorization({
|
|
1776
1895
|
signer: this.signer,
|
|
1777
|
-
signStrategy: { type: "auto-sign" },
|
|
1896
|
+
signStrategy: config.signStrategy ?? { type: "auto-sign" },
|
|
1778
1897
|
wasmBindings: this.wasmBindings,
|
|
1779
1898
|
sessionStorage: config.sessionStorage ?? new MemorySessionStorage(),
|
|
1780
1899
|
domain: this.siweDomain,
|
|
@@ -1783,20 +1902,23 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1783
1902
|
tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
|
|
1784
1903
|
tinycloudRegistryUrl: config.tinycloudRegistryUrl,
|
|
1785
1904
|
tinycloudFallbackHosts: config.tinycloudFallbackHosts,
|
|
1786
|
-
autoCreateSpace: config.autoCreateSpace,
|
|
1905
|
+
autoCreateSpace: useBootstrapSignInRequest ? false : config.autoCreateSpace,
|
|
1787
1906
|
enablePublicSpace: config.enablePublicSpace ?? true,
|
|
1788
|
-
spaceCreationHandler: config.spaceCreationHandler,
|
|
1907
|
+
spaceCreationHandler: useBootstrapSignInRequest ? void 0 : config.spaceCreationHandler,
|
|
1789
1908
|
nonce: config.nonce,
|
|
1790
1909
|
siweConfig: config.siweConfig,
|
|
1791
|
-
manifest: config.manifest,
|
|
1792
|
-
capabilityRequest: config.capabilityRequest,
|
|
1793
|
-
includeAccountRegistryPermissions: config.includeAccountRegistryPermissions
|
|
1910
|
+
manifest: useBootstrapSignInRequest ? void 0 : config.manifest,
|
|
1911
|
+
capabilityRequest: useBootstrapSignInRequest ? import_sdk_core8.BOOTSTRAP_SESSION_REQUESTS.default : config.capabilityRequest,
|
|
1912
|
+
includeAccountRegistryPermissions: useBootstrapSignInRequest ? false : config.includeAccountRegistryPermissions
|
|
1794
1913
|
});
|
|
1795
|
-
this.tc = new
|
|
1914
|
+
this.tc = new import_sdk_core8.TinyCloud(this.auth, {
|
|
1796
1915
|
invokeAny: this.invokeAnyWithRuntimePermissions,
|
|
1797
1916
|
telemetry: config.telemetry
|
|
1798
1917
|
});
|
|
1799
1918
|
}
|
|
1919
|
+
shouldUseBootstrapSignInRequest(config) {
|
|
1920
|
+
return config.autoBootstrapAccount !== false && config.manifest === void 0 && config.capabilityRequest === void 0 && (config.prefix ?? "default") === "default" && isOpenKeyAutoSignStrategy(config.signStrategy);
|
|
1921
|
+
}
|
|
1800
1922
|
syncResolvedHostFromAuth() {
|
|
1801
1923
|
const host = this.auth?.hosts[0];
|
|
1802
1924
|
if (host) {
|
|
@@ -1853,7 +1975,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1853
1975
|
*/
|
|
1854
1976
|
get did() {
|
|
1855
1977
|
if (this._address) {
|
|
1856
|
-
return (0,
|
|
1978
|
+
return (0, import_sdk_core8.pkhDid)(this._address, this._chainId);
|
|
1857
1979
|
}
|
|
1858
1980
|
return this.sessionManager.getDID(this.sessionKeyId);
|
|
1859
1981
|
}
|
|
@@ -1895,14 +2017,14 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1895
2017
|
if (!this._address) {
|
|
1896
2018
|
return void 0;
|
|
1897
2019
|
}
|
|
1898
|
-
return this.wasmBindings.makeSpaceId(this._address, this._chainId,
|
|
2020
|
+
return this.wasmBindings.makeSpaceId(this._address, this._chainId, import_sdk_core8.ACCOUNT_REGISTRY_SPACE);
|
|
1899
2021
|
}
|
|
1900
2022
|
/**
|
|
1901
2023
|
* Account-level application and delegation helpers.
|
|
1902
2024
|
*/
|
|
1903
2025
|
get account() {
|
|
1904
2026
|
if (!this._account) {
|
|
1905
|
-
this._account = new
|
|
2027
|
+
this._account = new import_sdk_core4.AccountService({
|
|
1906
2028
|
getDid: () => this.did,
|
|
1907
2029
|
getHost: () => this.hosts[0] ?? this.config.host,
|
|
1908
2030
|
getPrimarySpaceId: () => this.spaceId,
|
|
@@ -1911,7 +2033,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1911
2033
|
getAccountDb: () => this.accountSpaceId ? this.sqlForSpace(this.accountSpaceId).db("account") : void 0,
|
|
1912
2034
|
ensureAccountSpaceHosted: async () => {
|
|
1913
2035
|
if (this.accountSpaceId && this.auth) {
|
|
1914
|
-
await this.
|
|
2036
|
+
await this.ensureOwnedSpaceHostedById(this.accountSpaceId);
|
|
1915
2037
|
}
|
|
1916
2038
|
}
|
|
1917
2039
|
});
|
|
@@ -1939,7 +2061,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1939
2061
|
);
|
|
1940
2062
|
}
|
|
1941
2063
|
await this.wasmBindings.ensureInitialized?.();
|
|
1942
|
-
this._address = (0,
|
|
2064
|
+
this._address = (0, import_sdk_core8.canonicalizeAddress)(await this.signer.getAddress());
|
|
1943
2065
|
this._chainId = await this.signer.getChainId();
|
|
1944
2066
|
this._kv = void 0;
|
|
1945
2067
|
this._sql = void 0;
|
|
@@ -1955,11 +2077,14 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1955
2077
|
await this.tc.signIn(options);
|
|
1956
2078
|
this.syncResolvedHostFromAuth();
|
|
1957
2079
|
this.initializeServices();
|
|
2080
|
+
const bootstrapped = await this.bootstrapAccountIfNeeded();
|
|
1958
2081
|
await this.ensureRequestedEncryptionNetworks();
|
|
1959
|
-
if (this.config.manifest === void 0 && this.config.capabilityRequest === void 0) {
|
|
1960
|
-
await this.
|
|
2082
|
+
if (!bootstrapped && this.config.manifest === void 0 && this.config.capabilityRequest === void 0) {
|
|
2083
|
+
await this.ensureOwnedSpaceHostedById(this.ownedSpaceId(import_sdk_core8.SECRETS_SPACE));
|
|
2084
|
+
}
|
|
2085
|
+
if (!bootstrapped) {
|
|
2086
|
+
this.scheduleAccountRegistrySync();
|
|
1961
2087
|
}
|
|
1962
|
-
this.scheduleAccountRegistrySync();
|
|
1963
2088
|
this.notificationHandler.success("Successfully signed in");
|
|
1964
2089
|
}
|
|
1965
2090
|
ownedSpaceId(name) {
|
|
@@ -1968,6 +2093,208 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1968
2093
|
}
|
|
1969
2094
|
return this.wasmBindings.makeSpaceId(this._address, this._chainId, name);
|
|
1970
2095
|
}
|
|
2096
|
+
async bootstrapAccountIfNeeded() {
|
|
2097
|
+
if (this.config.autoBootstrapAccount === false) {
|
|
2098
|
+
return false;
|
|
2099
|
+
}
|
|
2100
|
+
if (!this.auth || !this._address) {
|
|
2101
|
+
return false;
|
|
2102
|
+
}
|
|
2103
|
+
const steps = (0, import_sdk_core8.bootstrapSteps)(this._address, this._chainId);
|
|
2104
|
+
if (!await this.isFreshBootstrapAccount(steps)) {
|
|
2105
|
+
return false;
|
|
2106
|
+
}
|
|
2107
|
+
await this.runAccountBootstrap(steps);
|
|
2108
|
+
return true;
|
|
2109
|
+
}
|
|
2110
|
+
async isFreshBootstrapAccount(steps) {
|
|
2111
|
+
const enshrinedSpaceIds = /* @__PURE__ */ new Set();
|
|
2112
|
+
for (const step of steps) {
|
|
2113
|
+
if (step.kind === "session") {
|
|
2114
|
+
enshrinedSpaceIds.add(step.spaceId);
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
const skipped = this.auth.lastActivationSkippedSpaceIds;
|
|
2118
|
+
if (skipped.some((spaceId) => enshrinedSpaceIds.has(spaceId))) {
|
|
2119
|
+
return true;
|
|
2120
|
+
}
|
|
2121
|
+
try {
|
|
2122
|
+
const indexed = await this.account.index.spaces.list();
|
|
2123
|
+
if (indexed.ok && indexed.data.length === 0) {
|
|
2124
|
+
return true;
|
|
2125
|
+
}
|
|
2126
|
+
} catch {
|
|
2127
|
+
}
|
|
2128
|
+
try {
|
|
2129
|
+
const spaces = await this.account.spaces.list();
|
|
2130
|
+
return spaces.ok && spaces.data.length === 0;
|
|
2131
|
+
} catch {
|
|
2132
|
+
return false;
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
2135
|
+
async runAccountBootstrap(steps) {
|
|
2136
|
+
if (!this.auth || !this._address) {
|
|
2137
|
+
throw new Error("Account bootstrap requires an active wallet session");
|
|
2138
|
+
}
|
|
2139
|
+
const host = this.hosts[0] ?? this.config.host;
|
|
2140
|
+
if (!host) {
|
|
2141
|
+
throw new Error("Account bootstrap requires a TinyCloud host");
|
|
2142
|
+
}
|
|
2143
|
+
const auth = this.auth;
|
|
2144
|
+
const sessions = /* @__PURE__ */ new Map();
|
|
2145
|
+
const rawAbilitiesBySpace = /* @__PURE__ */ new Map();
|
|
2146
|
+
const primarySession = auth.tinyCloudSession;
|
|
2147
|
+
const defaultSpaceId = this.ownedSpaceId("default");
|
|
2148
|
+
const canReusePrimaryBootstrapSession = primarySession?.spaceId === defaultSpaceId && auth.capabilityRequest === import_sdk_core8.BOOTSTRAP_SESSION_REQUESTS.default;
|
|
2149
|
+
for (const step of steps) {
|
|
2150
|
+
if (step.kind !== "session") continue;
|
|
2151
|
+
if (step.space === "default" && canReusePrimaryBootstrapSession && primarySession) {
|
|
2152
|
+
sessions.set(step.space, primarySession);
|
|
2153
|
+
continue;
|
|
2154
|
+
}
|
|
2155
|
+
const rawAbilities = step.rawAbilities;
|
|
2156
|
+
if (rawAbilities) {
|
|
2157
|
+
rawAbilitiesBySpace.set(step.space, rawAbilities);
|
|
2158
|
+
}
|
|
2159
|
+
const session = await auth.createBootstrapSession({
|
|
2160
|
+
spaceId: step.spaceId,
|
|
2161
|
+
capabilityRequest: step.request ?? import_sdk_core8.BOOTSTRAP_SESSION_REQUESTS[step.space],
|
|
2162
|
+
rawAbilities
|
|
2163
|
+
});
|
|
2164
|
+
sessions.set(step.space, session);
|
|
2165
|
+
}
|
|
2166
|
+
for (const step of steps) {
|
|
2167
|
+
if (step.kind !== "host") continue;
|
|
2168
|
+
const hosted = await auth.hostOwnedSpace(step.spaceId);
|
|
2169
|
+
if (!hosted) {
|
|
2170
|
+
throw new Error(`Failed to host bootstrap space: ${step.spaceId}`);
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
2174
|
+
for (const step of steps) {
|
|
2175
|
+
if (step.kind !== "activate") continue;
|
|
2176
|
+
const session = sessions.get(step.space);
|
|
2177
|
+
if (!session) {
|
|
2178
|
+
throw new Error(`Missing bootstrap session for ${step.space}`);
|
|
2179
|
+
}
|
|
2180
|
+
const activated = await (0, import_sdk_core8.activateSessionWithHost)(host, session.delegationHeader);
|
|
2181
|
+
if (!activated.success || activated.skipped?.includes(step.spaceId)) {
|
|
2182
|
+
throw new Error(
|
|
2183
|
+
`Failed to activate bootstrap session for ${step.spaceId}: ${activated.error ?? "space was skipped"}`
|
|
2184
|
+
);
|
|
2185
|
+
}
|
|
2186
|
+
this.registerBootstrapRuntimeGrant(
|
|
2187
|
+
session,
|
|
2188
|
+
import_sdk_core8.BOOTSTRAP_SESSION_REQUESTS[step.space],
|
|
2189
|
+
rawAbilitiesBySpace.get(step.space)
|
|
2190
|
+
);
|
|
2191
|
+
}
|
|
2192
|
+
for (const step of steps) {
|
|
2193
|
+
if (step.kind === "account-index-schema") {
|
|
2194
|
+
const ensured = await this.account.index.ensure();
|
|
2195
|
+
if (!ensured.ok) {
|
|
2196
|
+
throw new Error(`Failed to create account index schema: ${ensured.error.message}`);
|
|
2197
|
+
}
|
|
2198
|
+
}
|
|
2199
|
+
if (step.kind === "seed-spaces") {
|
|
2200
|
+
for (const space of step.spaces) {
|
|
2201
|
+
const registered = await this.account.spaces.register({
|
|
2202
|
+
spaceId: space.spaceId,
|
|
2203
|
+
name: space.name,
|
|
2204
|
+
ownerDid: this.did,
|
|
2205
|
+
type: "owned",
|
|
2206
|
+
permissions: ["*"],
|
|
2207
|
+
status: "active"
|
|
2208
|
+
});
|
|
2209
|
+
if (!registered.ok) {
|
|
2210
|
+
throw new Error(
|
|
2211
|
+
`Failed to seed account space ${space.spaceId}: ${registered.error.message}`
|
|
2212
|
+
);
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
}
|
|
2216
|
+
if (step.kind === "seed-applications") {
|
|
2217
|
+
const registered = await this.account.applications.register(
|
|
2218
|
+
step.manifests.length > 0 ? [...step.manifests] : import_sdk_core8.TINYCLOUD_SECRETS_BOOTSTRAP_MANIFEST
|
|
2219
|
+
);
|
|
2220
|
+
if (!registered.ok) {
|
|
2221
|
+
throw new Error(`Failed to seed bootstrap applications: ${registered.error.message}`);
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
if (step.kind === "encryption-network-create") {
|
|
2225
|
+
await this.ensureEncryptionNetwork(step.networkId);
|
|
2226
|
+
}
|
|
2227
|
+
if (step.kind === "secret-records-schema") {
|
|
2228
|
+
const db = this.sqlForSpace(step.spaceId).db(step.database);
|
|
2229
|
+
const migrated = await db.migrations.apply({
|
|
2230
|
+
namespace: "tinycloud.secrets.records",
|
|
2231
|
+
migrations: [
|
|
2232
|
+
{
|
|
2233
|
+
id: "001_initial",
|
|
2234
|
+
sql: [...import_sdk_core8.SECRET_RECORDS_SCHEMA]
|
|
2235
|
+
}
|
|
2236
|
+
]
|
|
2237
|
+
});
|
|
2238
|
+
if (!migrated.ok) {
|
|
2239
|
+
throw new Error(
|
|
2240
|
+
`Failed to create secret_records schema: ${migrated.error.message}`
|
|
2241
|
+
);
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
registerBootstrapRuntimeGrant(session, request, rawAbilities) {
|
|
2247
|
+
const operations = [];
|
|
2248
|
+
for (const resource of request.resources) {
|
|
2249
|
+
const service = resource.service.startsWith("tinycloud.") ? this.shortServiceName(resource.service) : resource.service;
|
|
2250
|
+
const spaceId = resource.space.startsWith("tinycloud:") ? resource.space : this.ownedSpaceId(resource.space);
|
|
2251
|
+
for (const action of resource.actions) {
|
|
2252
|
+
operations.push({
|
|
2253
|
+
spaceId,
|
|
2254
|
+
service,
|
|
2255
|
+
path: resource.path,
|
|
2256
|
+
action
|
|
2257
|
+
});
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
for (const [resource, actions2] of Object.entries(rawAbilities ?? {})) {
|
|
2261
|
+
for (const action of actions2) {
|
|
2262
|
+
operations.push({
|
|
2263
|
+
resource,
|
|
2264
|
+
service: "encryption",
|
|
2265
|
+
path: resource,
|
|
2266
|
+
action
|
|
2267
|
+
});
|
|
2268
|
+
}
|
|
2269
|
+
}
|
|
2270
|
+
const expiresAt = extractSiweExpiration(session.siwe) ?? this.getSessionExpiry();
|
|
2271
|
+
const actions = [...new Set(operations.map((operation) => operation.action))];
|
|
2272
|
+
this.runtimePermissionGrants.push({
|
|
2273
|
+
session: {
|
|
2274
|
+
delegationHeader: session.delegationHeader,
|
|
2275
|
+
delegationCid: session.delegationCid,
|
|
2276
|
+
spaceId: session.spaceId,
|
|
2277
|
+
verificationMethod: session.verificationMethod,
|
|
2278
|
+
jwk: session.jwk
|
|
2279
|
+
},
|
|
2280
|
+
delegation: {
|
|
2281
|
+
cid: session.delegationCid,
|
|
2282
|
+
delegationHeader: session.delegationHeader,
|
|
2283
|
+
delegateDID: session.verificationMethod,
|
|
2284
|
+
delegatorDID: this.did,
|
|
2285
|
+
spaceId: session.spaceId,
|
|
2286
|
+
path: "",
|
|
2287
|
+
actions,
|
|
2288
|
+
expiry: expiresAt,
|
|
2289
|
+
allowSubDelegation: true,
|
|
2290
|
+
ownerAddress: session.address,
|
|
2291
|
+
chainId: session.chainId,
|
|
2292
|
+
host: this.config.host
|
|
2293
|
+
},
|
|
2294
|
+
operations,
|
|
2295
|
+
expiresAt
|
|
2296
|
+
});
|
|
2297
|
+
}
|
|
1971
2298
|
async writeManifestRegistryRecords() {
|
|
1972
2299
|
const request = this.capabilityRequest;
|
|
1973
2300
|
if (!request || request.registryRecords.length === 0) {
|
|
@@ -1976,8 +2303,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1976
2303
|
if (!this.auth || !this.signer) {
|
|
1977
2304
|
throw new Error("Manifest registry write requires wallet mode");
|
|
1978
2305
|
}
|
|
1979
|
-
const accountSpaceId = this.ownedSpaceId(
|
|
1980
|
-
await this.
|
|
2306
|
+
const accountSpaceId = this.ownedSpaceId(import_sdk_core8.ACCOUNT_REGISTRY_SPACE);
|
|
2307
|
+
await this.ensureOwnedSpaceHostedById(accountSpaceId);
|
|
1981
2308
|
const result = await this.account.applications.register(request.manifests);
|
|
1982
2309
|
if (!result.ok) {
|
|
1983
2310
|
throw new Error(
|
|
@@ -1987,6 +2314,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
1987
2314
|
}
|
|
1988
2315
|
scheduleAccountRegistrySync() {
|
|
1989
2316
|
void this.withAccountRegistryRetry(async () => {
|
|
2317
|
+
void this.account.index.ensure();
|
|
1990
2318
|
await this.writeManifestRegistryRecords();
|
|
1991
2319
|
const spaces = await this.account.spaces.syncAccessible();
|
|
1992
2320
|
if (!spaces.ok) {
|
|
@@ -2020,7 +2348,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2020
2348
|
}
|
|
2021
2349
|
const networkIds = /* @__PURE__ */ new Set();
|
|
2022
2350
|
for (const resource of request.resources) {
|
|
2023
|
-
if (resource.service ===
|
|
2351
|
+
if (resource.service === import_sdk_core8.ENCRYPTION_PERMISSION_SERVICE && resource.path.startsWith("urn:tinycloud:encryption:") && resource.actions.includes(DECRYPT_ACTION2)) {
|
|
2024
2352
|
networkIds.add(resource.path);
|
|
2025
2353
|
}
|
|
2026
2354
|
}
|
|
@@ -2031,14 +2359,14 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2031
2359
|
return;
|
|
2032
2360
|
}
|
|
2033
2361
|
for (const networkId of this.requestedEncryptionNetworkIds()) {
|
|
2034
|
-
const parsed = (0,
|
|
2362
|
+
const parsed = (0, import_sdk_core8.parseNetworkId)(networkId);
|
|
2035
2363
|
if (!didPrincipalMatches2(parsed.ownerDid, this.did)) {
|
|
2036
2364
|
continue;
|
|
2037
2365
|
}
|
|
2038
2366
|
await this.ensureEncryptionNetwork(networkId);
|
|
2039
2367
|
}
|
|
2040
2368
|
}
|
|
2041
|
-
async
|
|
2369
|
+
async ensureOwnedSpaceHostedById(spaceId) {
|
|
2042
2370
|
if (!this.auth) {
|
|
2043
2371
|
throw new Error("Owned space hosting requires wallet mode");
|
|
2044
2372
|
}
|
|
@@ -2050,7 +2378,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2050
2378
|
if (!host) {
|
|
2051
2379
|
throw new Error("Owned space hosting requires a TinyCloud host");
|
|
2052
2380
|
}
|
|
2053
|
-
const activation = await (0,
|
|
2381
|
+
const activation = await (0, import_sdk_core8.activateSessionWithHost)(host, session.delegationHeader);
|
|
2054
2382
|
if (activation.success && !activation.skipped?.includes(spaceId)) {
|
|
2055
2383
|
return;
|
|
2056
2384
|
}
|
|
@@ -2064,7 +2392,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2064
2392
|
throw new Error(`Failed to create owned space: ${spaceId}`);
|
|
2065
2393
|
}
|
|
2066
2394
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
2067
|
-
const retry = await (0,
|
|
2395
|
+
const retry = await (0, import_sdk_core8.activateSessionWithHost)(host, session.delegationHeader);
|
|
2068
2396
|
if (!retry.success || retry.skipped?.includes(spaceId)) {
|
|
2069
2397
|
throw new Error(
|
|
2070
2398
|
`Failed to activate session after creating owned space ${spaceId}: ${retry.error ?? "space was skipped"}`
|
|
@@ -2081,7 +2409,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2081
2409
|
* caller is the root authority of their own owned spaces, so no additional
|
|
2082
2410
|
* delegation is required.
|
|
2083
2411
|
*
|
|
2084
|
-
* Unlike {@link
|
|
2412
|
+
* Unlike {@link ensureOwnedSpaceHostedById}, this always submits the host
|
|
2085
2413
|
* delegation rather than inferring hosting from session activation: a space
|
|
2086
2414
|
* the current session has never referenced is reported neither as
|
|
2087
2415
|
* `activated` nor `skipped`, so activation-based detection would wrongly
|
|
@@ -2106,7 +2434,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2106
2434
|
if (!hosted) {
|
|
2107
2435
|
throw new Error(`Failed to host owned space: ${spaceId}`);
|
|
2108
2436
|
}
|
|
2109
|
-
const activation = await (0,
|
|
2437
|
+
const activation = await (0, import_sdk_core8.activateSessionWithHost)(
|
|
2110
2438
|
host,
|
|
2111
2439
|
this.auth.tinyCloudSession.delegationHeader
|
|
2112
2440
|
);
|
|
@@ -2126,6 +2454,91 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2126
2454
|
});
|
|
2127
2455
|
return spaceId;
|
|
2128
2456
|
}
|
|
2457
|
+
/**
|
|
2458
|
+
* Ensure one of this user's owned spaces (e.g. `"secrets"`) is hosted on the
|
|
2459
|
+
* server.
|
|
2460
|
+
*
|
|
2461
|
+
* At sign-in, a full-authority session auto-hosts the owner's `secrets`
|
|
2462
|
+
* space, but a session created with a manifest / capabilityRequest does not.
|
|
2463
|
+
* Such a session can therefore hold valid `tinycloud.kv/*` capabilities for
|
|
2464
|
+
* the owned `secrets` space yet still fail its first scoped
|
|
2465
|
+
* `secrets.put(...)` with `404 Space not found`, because the space was never
|
|
2466
|
+
* registered on the node.
|
|
2467
|
+
*
|
|
2468
|
+
* Calling this resolves `name` to the owner's owned-space URI
|
|
2469
|
+
* (`tinycloud:pkh:eip155:<chain>:<addr>:<name>`). It first consults the
|
|
2470
|
+
* account-space spaces registry (`account/spaces/{space_id}`, the canonical
|
|
2471
|
+
* KV source of truth, fronted by a best-effort SQLite index): if the space is
|
|
2472
|
+
* already registered/hosted it returns the URI WITHOUT submitting a host
|
|
2473
|
+
* delegation, avoiding a redundant host-SIWE signature prompt for owners who
|
|
2474
|
+
* already use the space. Only when the space is absent — or the registry
|
|
2475
|
+
* check fails for any reason (e.g. a cold SQLite index reporting
|
|
2476
|
+
* `no such table: spaces`) — does it fall through to {@link hostOwnedSpace}.
|
|
2477
|
+
*
|
|
2478
|
+
* The registry check is purely an optimization: any failure falls back to
|
|
2479
|
+
* hosting, and the host SIWE is idempotent server-side, so re-hosting an
|
|
2480
|
+
* existing space remains a safe no-op. Must be called after {@link signIn}.
|
|
2481
|
+
*
|
|
2482
|
+
* @param name - The owned space name (e.g. `"secrets"`).
|
|
2483
|
+
* @returns The hosted owned-space URI.
|
|
2484
|
+
*/
|
|
2485
|
+
async ensureOwnedSpaceHosted(name) {
|
|
2486
|
+
if (!this.auth || !this.auth.tinyCloudSession) {
|
|
2487
|
+
throw new Error("Not signed in. Call signIn() first.");
|
|
2488
|
+
}
|
|
2489
|
+
const spaceId = this.ownedSpaceId(name);
|
|
2490
|
+
if (await this.isOwnedSpaceRegistered(spaceId)) {
|
|
2491
|
+
return spaceId;
|
|
2492
|
+
}
|
|
2493
|
+
const hosted = await this.hostOwnedSpace(name);
|
|
2494
|
+
try {
|
|
2495
|
+
await this.account.spaces.register({
|
|
2496
|
+
spaceId,
|
|
2497
|
+
name,
|
|
2498
|
+
ownerDid: this.did,
|
|
2499
|
+
type: "owned",
|
|
2500
|
+
permissions: ["*"],
|
|
2501
|
+
status: "active"
|
|
2502
|
+
});
|
|
2503
|
+
} catch {
|
|
2504
|
+
}
|
|
2505
|
+
return hosted;
|
|
2506
|
+
}
|
|
2507
|
+
/**
|
|
2508
|
+
* Check whether an owned space is already registered/hosted by consulting the
|
|
2509
|
+
* account spaces registry.
|
|
2510
|
+
*
|
|
2511
|
+
* Source of truth is the canonical KV registry record
|
|
2512
|
+
* `account/spaces/{space_id}`, read here via `account.spaces.get(spaceId)`.
|
|
2513
|
+
* The KV path is used (rather than `syncAccessible()`) because it works under
|
|
2514
|
+
* a manifest/recap session with NO extra prompt: the composed manifest recap
|
|
2515
|
+
* already grants `tinycloud.kv get/list` on the account space `spaces/`
|
|
2516
|
+
* prefix, whereas `syncAccessible()` depends on `tinycloud.space/list`, which
|
|
2517
|
+
* a recap session does not hold. Before reading, it consults the fast SQLite
|
|
2518
|
+
* index (`account.index.spaces.list()`) as a best-effort short-circuit; on a
|
|
2519
|
+
* cold index (`no such table: spaces`) or any other index failure it falls
|
|
2520
|
+
* back to the canonical KV read.
|
|
2521
|
+
*
|
|
2522
|
+
* This is a best-effort optimization. ANY failure of the check path (missing
|
|
2523
|
+
* table, KV error, missing record, thrown exception) resolves to `false` so
|
|
2524
|
+
* the caller falls through to hosting — per the directive, "if it fails in any
|
|
2525
|
+
* way then create the space".
|
|
2526
|
+
*/
|
|
2527
|
+
async isOwnedSpaceRegistered(spaceId) {
|
|
2528
|
+
try {
|
|
2529
|
+
const indexed = await this.account.index.spaces.list();
|
|
2530
|
+
if (indexed.ok && indexed.data.some((space) => space.spaceId === spaceId)) {
|
|
2531
|
+
return true;
|
|
2532
|
+
}
|
|
2533
|
+
} catch {
|
|
2534
|
+
}
|
|
2535
|
+
try {
|
|
2536
|
+
const record = await this.account.spaces.get(spaceId);
|
|
2537
|
+
return record.ok;
|
|
2538
|
+
} catch {
|
|
2539
|
+
return false;
|
|
2540
|
+
}
|
|
2541
|
+
}
|
|
2129
2542
|
/**
|
|
2130
2543
|
* Restore a previously established session from stored delegation data.
|
|
2131
2544
|
*
|
|
@@ -2148,30 +2561,38 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2148
2561
|
this._spaceService = void 0;
|
|
2149
2562
|
this._serviceContext = void 0;
|
|
2150
2563
|
this.runtimePermissionGrants = [];
|
|
2151
|
-
const restoredAddress = sessionData.address ? (0,
|
|
2564
|
+
const restoredAddress = sessionData.address ? (0, import_sdk_core8.canonicalizeAddress)(sessionData.address) : void 0;
|
|
2152
2565
|
if (restoredAddress) {
|
|
2153
2566
|
this._address = restoredAddress;
|
|
2154
2567
|
}
|
|
2155
2568
|
if (sessionData.chainId) {
|
|
2156
2569
|
this._chainId = sessionData.chainId;
|
|
2157
2570
|
}
|
|
2158
|
-
|
|
2571
|
+
const resolvedHost = await this.resolveRestoredHost(
|
|
2572
|
+
sessionData.tinycloudHosts,
|
|
2573
|
+
restoredAddress,
|
|
2574
|
+
sessionData.chainId
|
|
2575
|
+
);
|
|
2576
|
+
if (resolvedHost) {
|
|
2577
|
+
this.config.host = resolvedHost;
|
|
2578
|
+
}
|
|
2579
|
+
this._serviceContext = new import_sdk_core8.ServiceContext({
|
|
2159
2580
|
invoke: this.invokeWithRuntimePermissions,
|
|
2160
2581
|
invokeAny: this.invokeAnyWithRuntimePermissions,
|
|
2161
2582
|
fetch: globalThis.fetch.bind(globalThis),
|
|
2162
2583
|
hosts: [this.config.host],
|
|
2163
2584
|
telemetry: this.config.telemetry
|
|
2164
2585
|
});
|
|
2165
|
-
this._kv = new
|
|
2586
|
+
this._kv = new import_sdk_core8.KVService({});
|
|
2166
2587
|
this._kv.initialize(this._serviceContext);
|
|
2167
2588
|
this._serviceContext.registerService("kv", this._kv);
|
|
2168
|
-
this._sql = new
|
|
2589
|
+
this._sql = new import_sdk_core8.SQLService({});
|
|
2169
2590
|
this._sql.initialize(this._serviceContext);
|
|
2170
2591
|
this._serviceContext.registerService("sql", this._sql);
|
|
2171
|
-
this._duckdb = new
|
|
2592
|
+
this._duckdb = new import_sdk_core8.DuckDbService({});
|
|
2172
2593
|
this._duckdb.initialize(this._serviceContext);
|
|
2173
2594
|
this._serviceContext.registerService("duckdb", this._duckdb);
|
|
2174
|
-
this._hooks = new
|
|
2595
|
+
this._hooks = new import_sdk_core8.HooksService({});
|
|
2175
2596
|
this._hooks.initialize(this._serviceContext);
|
|
2176
2597
|
this._serviceContext.registerService("hooks", this._hooks);
|
|
2177
2598
|
const serviceSession = {
|
|
@@ -2200,12 +2621,45 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2200
2621
|
signature: sessionData.signature ?? ""
|
|
2201
2622
|
};
|
|
2202
2623
|
if (this.auth) {
|
|
2203
|
-
this.auth.setRestoredTinyCloudSession(
|
|
2624
|
+
this.auth.setRestoredTinyCloudSession(
|
|
2625
|
+
tcSession,
|
|
2626
|
+
this.config.host ? [this.config.host] : void 0
|
|
2627
|
+
);
|
|
2204
2628
|
} else {
|
|
2205
2629
|
this._restoredTcSession = tcSession;
|
|
2206
2630
|
}
|
|
2207
2631
|
}
|
|
2208
2632
|
}
|
|
2633
|
+
/**
|
|
2634
|
+
* Resolve the host a restored session should target.
|
|
2635
|
+
*
|
|
2636
|
+
* Mirrors fresh sign-in host resolution but for the restore path:
|
|
2637
|
+
* an explicit/pinned host always wins, then the hosts the session was
|
|
2638
|
+
* persisted with, then a lazy registry/fallback resolution for sessions
|
|
2639
|
+
* that predate the persisted `tinycloudHosts` field. Returns `undefined`
|
|
2640
|
+
* only when there's nothing to resolve from (no explicit host, no
|
|
2641
|
+
* persisted hosts, and no address/chainId) — in which case the existing
|
|
2642
|
+
* `config.host` (default) is left in place.
|
|
2643
|
+
*
|
|
2644
|
+
* Resolution failures are surfaced, not swallowed: a genuinely broken
|
|
2645
|
+
* registry lookup throws rather than silently falling back to a wrong host.
|
|
2646
|
+
*/
|
|
2647
|
+
async resolveRestoredHost(persistedHosts, address, chainId) {
|
|
2648
|
+
if (this.explicitHost) {
|
|
2649
|
+
return this.explicitHost;
|
|
2650
|
+
}
|
|
2651
|
+
if (persistedHosts && persistedHosts.length > 0) {
|
|
2652
|
+
return persistedHosts[0];
|
|
2653
|
+
}
|
|
2654
|
+
if (address === void 0 || chainId === void 0) {
|
|
2655
|
+
return void 0;
|
|
2656
|
+
}
|
|
2657
|
+
const resolved = await (0, import_sdk_core8.resolveTinyCloudHosts)((0, import_sdk_core8.pkhDid)(address, chainId), {
|
|
2658
|
+
registryUrl: this.config.tinycloudRegistryUrl,
|
|
2659
|
+
fallbackHosts: this.config.tinycloudFallbackHosts
|
|
2660
|
+
});
|
|
2661
|
+
return resolved.hosts[0];
|
|
2662
|
+
}
|
|
2209
2663
|
/**
|
|
2210
2664
|
* Resolve the currently-active TinyCloudSession, preferring the auth
|
|
2211
2665
|
* layer's value (wallet mode) and falling back to the node-level
|
|
@@ -2250,9 +2704,11 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2250
2704
|
);
|
|
2251
2705
|
}
|
|
2252
2706
|
this.signer = _TinyCloudNode.nodeDefaults.createSigner(privateKey);
|
|
2707
|
+
const authConfig = { ...this.config, prefix };
|
|
2708
|
+
const useBootstrapSignInRequest = this.shouldUseBootstrapSignInRequest(authConfig);
|
|
2253
2709
|
this.auth = new NodeUserAuthorization({
|
|
2254
2710
|
signer: this.signer,
|
|
2255
|
-
signStrategy: { type: "auto-sign" },
|
|
2711
|
+
signStrategy: this.config.signStrategy ?? { type: "auto-sign" },
|
|
2256
2712
|
wasmBindings: this.wasmBindings,
|
|
2257
2713
|
sessionStorage: options?.sessionStorage ?? this.config.sessionStorage ?? new MemorySessionStorage(),
|
|
2258
2714
|
domain: this.siweDomain,
|
|
@@ -2261,16 +2717,16 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2261
2717
|
tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
|
|
2262
2718
|
tinycloudRegistryUrl: this.config.tinycloudRegistryUrl,
|
|
2263
2719
|
tinycloudFallbackHosts: this.config.tinycloudFallbackHosts,
|
|
2264
|
-
autoCreateSpace: this.config.autoCreateSpace,
|
|
2720
|
+
autoCreateSpace: useBootstrapSignInRequest ? false : this.config.autoCreateSpace,
|
|
2265
2721
|
enablePublicSpace: this.config.enablePublicSpace ?? true,
|
|
2266
|
-
spaceCreationHandler: this.config.spaceCreationHandler,
|
|
2722
|
+
spaceCreationHandler: useBootstrapSignInRequest ? void 0 : this.config.spaceCreationHandler,
|
|
2267
2723
|
nonce: this.config.nonce,
|
|
2268
2724
|
siweConfig: this.config.siweConfig,
|
|
2269
|
-
manifest: this.config.manifest,
|
|
2270
|
-
capabilityRequest: this.config.capabilityRequest,
|
|
2271
|
-
includeAccountRegistryPermissions: this.config.includeAccountRegistryPermissions
|
|
2725
|
+
manifest: useBootstrapSignInRequest ? void 0 : this.config.manifest,
|
|
2726
|
+
capabilityRequest: useBootstrapSignInRequest ? import_sdk_core8.BOOTSTRAP_SESSION_REQUESTS.default : this.config.capabilityRequest,
|
|
2727
|
+
includeAccountRegistryPermissions: useBootstrapSignInRequest ? false : this.config.includeAccountRegistryPermissions
|
|
2272
2728
|
});
|
|
2273
|
-
this.tc = new
|
|
2729
|
+
this.tc = new import_sdk_core8.TinyCloud(this.auth, {
|
|
2274
2730
|
invokeAny: this.invokeAnyWithRuntimePermissions,
|
|
2275
2731
|
telemetry: this.config.telemetry
|
|
2276
2732
|
});
|
|
@@ -2295,9 +2751,11 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2295
2751
|
}
|
|
2296
2752
|
const prefix = options?.prefix ?? "default";
|
|
2297
2753
|
this.signer = signer;
|
|
2754
|
+
const authConfig = { ...this.config, prefix };
|
|
2755
|
+
const useBootstrapSignInRequest = this.shouldUseBootstrapSignInRequest(authConfig);
|
|
2298
2756
|
this.auth = new NodeUserAuthorization({
|
|
2299
2757
|
signer: this.signer,
|
|
2300
|
-
signStrategy: { type: "auto-sign" },
|
|
2758
|
+
signStrategy: this.config.signStrategy ?? { type: "auto-sign" },
|
|
2301
2759
|
wasmBindings: this.wasmBindings,
|
|
2302
2760
|
sessionStorage: options?.sessionStorage ?? this.config.sessionStorage ?? new MemorySessionStorage(),
|
|
2303
2761
|
domain: this.siweDomain,
|
|
@@ -2306,16 +2764,16 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2306
2764
|
tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
|
|
2307
2765
|
tinycloudRegistryUrl: this.config.tinycloudRegistryUrl,
|
|
2308
2766
|
tinycloudFallbackHosts: this.config.tinycloudFallbackHosts,
|
|
2309
|
-
autoCreateSpace: this.config.autoCreateSpace,
|
|
2767
|
+
autoCreateSpace: useBootstrapSignInRequest ? false : this.config.autoCreateSpace,
|
|
2310
2768
|
enablePublicSpace: this.config.enablePublicSpace ?? true,
|
|
2311
|
-
spaceCreationHandler: this.config.spaceCreationHandler,
|
|
2769
|
+
spaceCreationHandler: useBootstrapSignInRequest ? void 0 : this.config.spaceCreationHandler,
|
|
2312
2770
|
nonce: this.config.nonce,
|
|
2313
2771
|
siweConfig: this.config.siweConfig,
|
|
2314
|
-
manifest: this.config.manifest,
|
|
2315
|
-
capabilityRequest: this.config.capabilityRequest,
|
|
2316
|
-
includeAccountRegistryPermissions: this.config.includeAccountRegistryPermissions
|
|
2772
|
+
manifest: useBootstrapSignInRequest ? void 0 : this.config.manifest,
|
|
2773
|
+
capabilityRequest: useBootstrapSignInRequest ? import_sdk_core8.BOOTSTRAP_SESSION_REQUESTS.default : this.config.capabilityRequest,
|
|
2774
|
+
includeAccountRegistryPermissions: useBootstrapSignInRequest ? false : this.config.includeAccountRegistryPermissions
|
|
2317
2775
|
});
|
|
2318
|
-
this.tc = new
|
|
2776
|
+
this.tc = new import_sdk_core8.TinyCloud(this.auth, {
|
|
2319
2777
|
invokeAny: this.invokeAnyWithRuntimePermissions,
|
|
2320
2778
|
telemetry: this.config.telemetry
|
|
2321
2779
|
});
|
|
@@ -2331,28 +2789,28 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2331
2789
|
return;
|
|
2332
2790
|
}
|
|
2333
2791
|
this.tc.initializeServices(this.invokeWithRuntimePermissions, [this.config.host]);
|
|
2334
|
-
this._serviceContext = new
|
|
2792
|
+
this._serviceContext = new import_sdk_core8.ServiceContext({
|
|
2335
2793
|
invoke: this.invokeWithRuntimePermissions,
|
|
2336
2794
|
invokeAny: this.invokeAnyWithRuntimePermissions,
|
|
2337
2795
|
fetch: globalThis.fetch.bind(globalThis),
|
|
2338
2796
|
hosts: [this.config.host],
|
|
2339
2797
|
telemetry: this.config.telemetry
|
|
2340
2798
|
});
|
|
2341
|
-
this._kv = new
|
|
2799
|
+
this._kv = new import_sdk_core8.KVService({});
|
|
2342
2800
|
this._kv.initialize(this._serviceContext);
|
|
2343
2801
|
this._serviceContext.registerService("kv", this._kv);
|
|
2344
2802
|
const features = this.nodeFeatures;
|
|
2345
2803
|
if (features.length === 0 || features.includes("sql")) {
|
|
2346
|
-
this._sql = new
|
|
2804
|
+
this._sql = new import_sdk_core8.SQLService({});
|
|
2347
2805
|
this._sql.initialize(this._serviceContext);
|
|
2348
2806
|
this._serviceContext.registerService("sql", this._sql);
|
|
2349
2807
|
}
|
|
2350
2808
|
if (features.length === 0 || features.includes("duckdb")) {
|
|
2351
|
-
this._duckdb = new
|
|
2809
|
+
this._duckdb = new import_sdk_core8.DuckDbService({});
|
|
2352
2810
|
this._duckdb.initialize(this._serviceContext);
|
|
2353
2811
|
this._serviceContext.registerService("duckdb", this._duckdb);
|
|
2354
2812
|
}
|
|
2355
|
-
this._hooks = new
|
|
2813
|
+
this._hooks = new import_sdk_core8.HooksService({});
|
|
2356
2814
|
this._hooks.initialize(this._serviceContext);
|
|
2357
2815
|
this._serviceContext.registerService("hooks", this._hooks);
|
|
2358
2816
|
const serviceSession = {
|
|
@@ -2370,9 +2828,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2370
2828
|
this.initializeV2Services(serviceSession);
|
|
2371
2829
|
}
|
|
2372
2830
|
createSpaceScopedKVService(spaceId) {
|
|
2373
|
-
const kvService = new
|
|
2831
|
+
const kvService = new import_sdk_core8.KVService({});
|
|
2374
2832
|
if (this._serviceContext) {
|
|
2375
|
-
const spaceScopedContext = new
|
|
2833
|
+
const spaceScopedContext = new import_sdk_core8.ServiceContext({
|
|
2376
2834
|
invoke: this._serviceContext.invoke,
|
|
2377
2835
|
fetch: this._serviceContext.fetch,
|
|
2378
2836
|
hosts: this._serviceContext.hosts,
|
|
@@ -2437,7 +2895,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2437
2895
|
const shared = wasm.vault_x25519_dh(receiverPrivateKey, peerPublic);
|
|
2438
2896
|
return columnDecrypt(shared, ciphertext);
|
|
2439
2897
|
},
|
|
2440
|
-
verifyNodeSignature: (nodeId, message, signature) => (0,
|
|
2898
|
+
verifyNodeSignature: (nodeId, message, signature) => (0, import_sdk_core8.verifyDidKeyEd25519Signature)(nodeId, message, signature)
|
|
2441
2899
|
};
|
|
2442
2900
|
}
|
|
2443
2901
|
async fetchNodeId() {
|
|
@@ -2508,7 +2966,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2508
2966
|
return await response.json();
|
|
2509
2967
|
}
|
|
2510
2968
|
};
|
|
2511
|
-
return new
|
|
2969
|
+
return new import_sdk_core8.EncryptionService({
|
|
2512
2970
|
crypto,
|
|
2513
2971
|
signer: {
|
|
2514
2972
|
signDecryptInvocation: async (input) => {
|
|
@@ -2520,7 +2978,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2520
2978
|
});
|
|
2521
2979
|
return {
|
|
2522
2980
|
...signed,
|
|
2523
|
-
canonicalBody: (0,
|
|
2981
|
+
canonicalBody: (0, import_sdk_core8.canonicalizeEncryptionJson)(
|
|
2524
2982
|
input.body
|
|
2525
2983
|
)
|
|
2526
2984
|
};
|
|
@@ -2538,8 +2996,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2538
2996
|
if (!this.config.host) {
|
|
2539
2997
|
return null;
|
|
2540
2998
|
}
|
|
2541
|
-
const publicSpaceId = (0,
|
|
2542
|
-
const result = await
|
|
2999
|
+
const publicSpaceId = (0, import_sdk_core8.makePublicSpaceId)(this._address, this._chainId);
|
|
3000
|
+
const result = await import_sdk_core8.TinyCloud.readPublicSpace(this.config.host, publicSpaceId, discoveryKey);
|
|
2543
3001
|
if (!result.ok) {
|
|
2544
3002
|
return null;
|
|
2545
3003
|
}
|
|
@@ -2562,7 +3020,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2562
3020
|
}
|
|
2563
3021
|
createVaultService(spaceId, kv) {
|
|
2564
3022
|
const wasm = this.wasmBindings;
|
|
2565
|
-
const vaultCrypto = (0,
|
|
3023
|
+
const vaultCrypto = (0, import_sdk_core8.createVaultCrypto)({
|
|
2566
3024
|
vault_encrypt: wasm.vault_encrypt,
|
|
2567
3025
|
vault_decrypt: wasm.vault_decrypt,
|
|
2568
3026
|
vault_derive_key: wasm.vault_derive_key,
|
|
@@ -2572,7 +3030,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2572
3030
|
vault_sha256: wasm.vault_sha256
|
|
2573
3031
|
});
|
|
2574
3032
|
const self = this;
|
|
2575
|
-
return new
|
|
3033
|
+
return new import_sdk_core8.DataVaultService({
|
|
2576
3034
|
spaceId,
|
|
2577
3035
|
crypto: vaultCrypto,
|
|
2578
3036
|
encryption: {
|
|
@@ -2595,8 +3053,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2595
3053
|
get publicKV() {
|
|
2596
3054
|
return self._publicKV ?? self.tc.publicKV;
|
|
2597
3055
|
},
|
|
2598
|
-
readPublicSpace: (host, targetSpaceId, key) =>
|
|
2599
|
-
makePublicSpaceId:
|
|
3056
|
+
readPublicSpace: (host, targetSpaceId, key) => import_sdk_core8.TinyCloud.readPublicSpace(host, targetSpaceId, key),
|
|
3057
|
+
makePublicSpaceId: import_sdk_core8.TinyCloud.makePublicSpaceId,
|
|
2600
3058
|
did: this.did,
|
|
2601
3059
|
address: this._address ?? "",
|
|
2602
3060
|
chainId: this._chainId,
|
|
@@ -2609,7 +3067,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2609
3067
|
* @internal
|
|
2610
3068
|
*/
|
|
2611
3069
|
initializeV2Services(serviceSession) {
|
|
2612
|
-
this._capabilityRegistry = new
|
|
3070
|
+
this._capabilityRegistry = new import_sdk_core8.CapabilityKeyRegistry();
|
|
2613
3071
|
const tcSession = this.auth?.tinyCloudSession;
|
|
2614
3072
|
if (tcSession && this._address) {
|
|
2615
3073
|
const sessionKey = {
|
|
@@ -2683,13 +3141,13 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2683
3141
|
}
|
|
2684
3142
|
this._capabilityRegistry.registerKey(sessionKey, delegations);
|
|
2685
3143
|
}
|
|
2686
|
-
this._delegationManager = new
|
|
3144
|
+
this._delegationManager = new import_sdk_core8.DelegationManager({
|
|
2687
3145
|
hosts: [this.config.host],
|
|
2688
3146
|
session: serviceSession,
|
|
2689
3147
|
invoke: this.invokeWithRuntimePermissions,
|
|
2690
3148
|
fetch: globalThis.fetch.bind(globalThis)
|
|
2691
3149
|
});
|
|
2692
|
-
this._spaceService = new
|
|
3150
|
+
this._spaceService = new import_sdk_core8.SpaceService({
|
|
2693
3151
|
hosts: [this.config.host],
|
|
2694
3152
|
session: serviceSession,
|
|
2695
3153
|
invoke: this.wasmBindings.invoke,
|
|
@@ -2849,7 +3307,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2849
3307
|
...prepared,
|
|
2850
3308
|
signature
|
|
2851
3309
|
});
|
|
2852
|
-
const activateResult = await (0,
|
|
3310
|
+
const activateResult = await (0, import_sdk_core8.activateSessionWithHost)(
|
|
2853
3311
|
host,
|
|
2854
3312
|
delegationSession.delegationHeader
|
|
2855
3313
|
);
|
|
@@ -2859,7 +3317,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2859
3317
|
return {
|
|
2860
3318
|
cid: delegationSession.delegationCid,
|
|
2861
3319
|
delegateDID: params.shareKeyDID,
|
|
2862
|
-
delegatorDID: (0,
|
|
3320
|
+
delegatorDID: (0, import_sdk_core8.pkhDid)(session.address, session.chainId),
|
|
2863
3321
|
spaceId: params.spaceId,
|
|
2864
3322
|
path: params.path,
|
|
2865
3323
|
actions: params.actions,
|
|
@@ -2916,7 +3374,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2916
3374
|
if (!this._sql) {
|
|
2917
3375
|
const features = this.nodeFeatures;
|
|
2918
3376
|
if (features.length > 0 && !features.includes("sql")) {
|
|
2919
|
-
throw new
|
|
3377
|
+
throw new import_sdk_core8.UnsupportedFeatureError("sql", this.config.host, features);
|
|
2920
3378
|
}
|
|
2921
3379
|
throw new Error("Not signed in. Call signIn() first.");
|
|
2922
3380
|
}
|
|
@@ -2940,8 +3398,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2940
3398
|
if (!this._serviceContext || !this._serviceContext.session) {
|
|
2941
3399
|
throw new Error("Not signed in. Call signIn() first.");
|
|
2942
3400
|
}
|
|
2943
|
-
const sql = new
|
|
2944
|
-
const spaceScopedContext = new
|
|
3401
|
+
const sql = new import_sdk_core8.SQLService({});
|
|
3402
|
+
const spaceScopedContext = new import_sdk_core8.ServiceContext({
|
|
2945
3403
|
invoke: this._serviceContext.invoke,
|
|
2946
3404
|
fetch: this._serviceContext.fetch,
|
|
2947
3405
|
hosts: this._serviceContext.hosts,
|
|
@@ -2969,8 +3427,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2969
3427
|
if (!this._serviceContext || !this._serviceContext.session) {
|
|
2970
3428
|
throw new Error("Not signed in. Call signIn() first.");
|
|
2971
3429
|
}
|
|
2972
|
-
const kv = new
|
|
2973
|
-
const spaceScopedContext = new
|
|
3430
|
+
const kv = new import_sdk_core8.KVService({});
|
|
3431
|
+
const spaceScopedContext = new import_sdk_core8.ServiceContext({
|
|
2974
3432
|
invoke: this._serviceContext.invoke,
|
|
2975
3433
|
fetch: this._serviceContext.fetch,
|
|
2976
3434
|
hosts: this._serviceContext.hosts
|
|
@@ -2986,7 +3444,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
2986
3444
|
if (!this._duckdb) {
|
|
2987
3445
|
const features = this.nodeFeatures;
|
|
2988
3446
|
if (features.length > 0 && !features.includes("duckdb")) {
|
|
2989
|
-
throw new
|
|
3447
|
+
throw new import_sdk_core8.UnsupportedFeatureError("duckdb", this.config.host, features);
|
|
2990
3448
|
}
|
|
2991
3449
|
throw new Error("Not signed in. Call signIn() first.");
|
|
2992
3450
|
}
|
|
@@ -3038,7 +3496,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3038
3496
|
type: NETWORK_ADMIN_TYPE,
|
|
3039
3497
|
targetNode,
|
|
3040
3498
|
networkId,
|
|
3041
|
-
bodyHash: (0,
|
|
3499
|
+
bodyHash: (0, import_sdk_core8.canonicalHashHex)(
|
|
3042
3500
|
crypto.sha256,
|
|
3043
3501
|
body
|
|
3044
3502
|
),
|
|
@@ -3056,7 +3514,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3056
3514
|
Authorization: signed.authorization,
|
|
3057
3515
|
"Content-Type": "application/json"
|
|
3058
3516
|
},
|
|
3059
|
-
body: (0,
|
|
3517
|
+
body: (0, import_sdk_core8.canonicalizeEncryptionJson)(
|
|
3060
3518
|
body
|
|
3061
3519
|
)
|
|
3062
3520
|
});
|
|
@@ -3074,7 +3532,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3074
3532
|
if (existing) {
|
|
3075
3533
|
return existing;
|
|
3076
3534
|
}
|
|
3077
|
-
const parsed = (0,
|
|
3535
|
+
const parsed = (0, import_sdk_core8.parseNetworkId)(networkId);
|
|
3078
3536
|
if (!didPrincipalMatches2(parsed.ownerDid, this.did)) {
|
|
3079
3537
|
throw new Error(
|
|
3080
3538
|
`Cannot create encryption network ${networkId}: owner ${parsed.ownerDid} does not match signed-in DID ${this.did}`
|
|
@@ -3107,7 +3565,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3107
3565
|
throw new Error("Not signed in. Call signIn() first.");
|
|
3108
3566
|
}
|
|
3109
3567
|
if (!this._baseSecrets) {
|
|
3110
|
-
this._baseSecrets = new
|
|
3568
|
+
this._baseSecrets = new import_sdk_core8.SecretsService(() => this.space("secrets").vault);
|
|
3111
3569
|
}
|
|
3112
3570
|
return this._baseSecrets;
|
|
3113
3571
|
}
|
|
@@ -3222,10 +3680,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3222
3680
|
async useRuntimeDelegation(delegation) {
|
|
3223
3681
|
const session = this.currentTinyCloudSession();
|
|
3224
3682
|
if (!session) {
|
|
3225
|
-
throw new
|
|
3683
|
+
throw new import_sdk_core8.SessionExpiredError(/* @__PURE__ */ new Date(0));
|
|
3226
3684
|
}
|
|
3227
3685
|
if (delegation.expiry.getTime() <= Date.now()) {
|
|
3228
|
-
throw new
|
|
3686
|
+
throw new import_sdk_core8.SessionExpiredError(delegation.expiry);
|
|
3229
3687
|
}
|
|
3230
3688
|
const expectedDids = [session.verificationMethod, this.sessionDid];
|
|
3231
3689
|
if (!expectedDids.some((did) => didPrincipalMatches2(delegation.delegateDID, did))) {
|
|
@@ -3234,7 +3692,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3234
3692
|
);
|
|
3235
3693
|
}
|
|
3236
3694
|
const targetHost = delegation.host ?? this.config.host;
|
|
3237
|
-
const activateResult = await (0,
|
|
3695
|
+
const activateResult = await (0, import_sdk_core8.activateSessionWithHost)(
|
|
3238
3696
|
targetHost,
|
|
3239
3697
|
delegation.delegationHeader
|
|
3240
3698
|
);
|
|
@@ -3261,13 +3719,13 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3261
3719
|
}
|
|
3262
3720
|
const session = this.currentTinyCloudSession();
|
|
3263
3721
|
if (!session) {
|
|
3264
|
-
throw new
|
|
3722
|
+
throw new import_sdk_core8.SessionExpiredError(/* @__PURE__ */ new Date(0));
|
|
3265
3723
|
}
|
|
3266
3724
|
const sessionExpiry = extractSiweExpiration(session.siwe);
|
|
3267
3725
|
if (sessionExpiry !== void 0) {
|
|
3268
3726
|
const marginMs = _TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS;
|
|
3269
3727
|
if (sessionExpiry.getTime() <= Date.now() + marginMs) {
|
|
3270
|
-
throw new
|
|
3728
|
+
throw new import_sdk_core8.SessionExpiredError(sessionExpiry);
|
|
3271
3729
|
}
|
|
3272
3730
|
}
|
|
3273
3731
|
const expanded = this.expandPermissionEntries(permissions);
|
|
@@ -3330,7 +3788,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3330
3788
|
...prepared,
|
|
3331
3789
|
signature
|
|
3332
3790
|
});
|
|
3333
|
-
const activateResult = await (0,
|
|
3791
|
+
const activateResult = await (0, import_sdk_core8.activateSessionWithHost)(
|
|
3334
3792
|
this.config.host,
|
|
3335
3793
|
delegatedSession.delegationHeader
|
|
3336
3794
|
);
|
|
@@ -3503,7 +3961,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3503
3961
|
];
|
|
3504
3962
|
const abilities = { kv: { "": kvActions } };
|
|
3505
3963
|
const now = /* @__PURE__ */ new Date();
|
|
3506
|
-
const expiryMs =
|
|
3964
|
+
const expiryMs = import_sdk_core8.EXPIRY.EPHEMERAL_MS;
|
|
3507
3965
|
const expirationTime = new Date(now.getTime() + expiryMs);
|
|
3508
3966
|
const prepared = this.wasmBindings.prepareSession({
|
|
3509
3967
|
abilities,
|
|
@@ -3521,7 +3979,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3521
3979
|
...prepared,
|
|
3522
3980
|
signature
|
|
3523
3981
|
});
|
|
3524
|
-
const activateResult = await (0,
|
|
3982
|
+
const activateResult = await (0, import_sdk_core8.activateSessionWithHost)(
|
|
3525
3983
|
this.config.host,
|
|
3526
3984
|
delegationSession.delegationHeader
|
|
3527
3985
|
);
|
|
@@ -3548,8 +4006,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3548
4006
|
}]);
|
|
3549
4007
|
}
|
|
3550
4008
|
if (this._serviceContext) {
|
|
3551
|
-
const publicKV = new
|
|
3552
|
-
const publicContext = new
|
|
4009
|
+
const publicKV = new import_sdk_core8.KVService({ prefix: "" });
|
|
4010
|
+
const publicContext = new import_sdk_core8.ServiceContext({
|
|
3553
4011
|
invoke: this.invokeWithRuntimePermissions,
|
|
3554
4012
|
fetch: this._serviceContext.fetch,
|
|
3555
4013
|
hosts: this._serviceContext.hosts,
|
|
@@ -3676,14 +4134,14 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3676
4134
|
async delegateTo(did, permissions, options) {
|
|
3677
4135
|
const session = this.currentTinyCloudSession();
|
|
3678
4136
|
if (!session) {
|
|
3679
|
-
throw new
|
|
4137
|
+
throw new import_sdk_core8.SessionExpiredError(/* @__PURE__ */ new Date(0));
|
|
3680
4138
|
}
|
|
3681
4139
|
const sessionExpiry = extractSiweExpiration(session.siwe);
|
|
3682
4140
|
if (sessionExpiry !== void 0) {
|
|
3683
4141
|
const now2 = Date.now();
|
|
3684
4142
|
const marginMs = _TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS;
|
|
3685
4143
|
if (sessionExpiry.getTime() <= now2 + marginMs) {
|
|
3686
|
-
throw new
|
|
4144
|
+
throw new import_sdk_core8.SessionExpiredError(sessionExpiry);
|
|
3687
4145
|
}
|
|
3688
4146
|
}
|
|
3689
4147
|
if (!Array.isArray(permissions) || permissions.length === 0) {
|
|
@@ -3712,11 +4170,11 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3712
4170
|
);
|
|
3713
4171
|
return { delegation: delegation2, prompted: true };
|
|
3714
4172
|
}
|
|
3715
|
-
const granted = (0,
|
|
4173
|
+
const granted = (0, import_sdk_core8.parseRecapCapabilities)(
|
|
3716
4174
|
(siwe) => this.wasmBindings.parseRecapFromSiwe(siwe),
|
|
3717
4175
|
session.siwe
|
|
3718
4176
|
);
|
|
3719
|
-
const { subset, missing } = (0,
|
|
4177
|
+
const { subset, missing } = (0, import_sdk_core8.isCapabilitySubset)(expandedEntries, granted);
|
|
3720
4178
|
if (!subset) {
|
|
3721
4179
|
const runtimeGrant = this.findGrantForOperations(
|
|
3722
4180
|
this.permissionEntriesToOperations(expandedEntries, session)
|
|
@@ -3724,7 +4182,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3724
4182
|
if (runtimeGrant) {
|
|
3725
4183
|
const marginMs = _TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS;
|
|
3726
4184
|
if (runtimeGrant.expiresAt.getTime() <= Date.now() + marginMs) {
|
|
3727
|
-
throw new
|
|
4185
|
+
throw new import_sdk_core8.SessionExpiredError(runtimeGrant.expiresAt);
|
|
3728
4186
|
}
|
|
3729
4187
|
const runtimeExpiration = runtimeGrant.expiresAt < effectiveExpiration ? runtimeGrant.expiresAt : effectiveExpiration;
|
|
3730
4188
|
const delegation2 = await this.createDelegationViaRuntimeGrant(
|
|
@@ -3735,7 +4193,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3735
4193
|
);
|
|
3736
4194
|
return { delegation: delegation2, prompted: false };
|
|
3737
4195
|
}
|
|
3738
|
-
throw new
|
|
4196
|
+
throw new import_sdk_core8.PermissionNotInManifestError(missing, granted);
|
|
3739
4197
|
}
|
|
3740
4198
|
const delegation = await this.createDelegationViaWasmPath(
|
|
3741
4199
|
did,
|
|
@@ -3817,7 +4275,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3817
4275
|
const spaceId = resolvedSpaces.size === 1 ? [...resolvedSpaces][0] : session.spaceId;
|
|
3818
4276
|
const abilities = {};
|
|
3819
4277
|
for (const entry of entries) {
|
|
3820
|
-
const shortService =
|
|
4278
|
+
const shortService = import_sdk_core8.SERVICE_LONG_TO_SHORT[entry.service];
|
|
3821
4279
|
if (shortService === void 0) {
|
|
3822
4280
|
throw new Error(
|
|
3823
4281
|
`delegateTo: unknown service '${entry.service}' \u2014 no short-form mapping`
|
|
@@ -3857,7 +4315,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3857
4315
|
});
|
|
3858
4316
|
const primary = result.resources[0];
|
|
3859
4317
|
const delegationHeader = { Authorization: result.delegation };
|
|
3860
|
-
const activateResult = await (0,
|
|
4318
|
+
const activateResult = await (0, import_sdk_core8.activateSessionWithHost)(
|
|
3861
4319
|
this.config.host,
|
|
3862
4320
|
delegationHeader
|
|
3863
4321
|
);
|
|
@@ -3892,7 +4350,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3892
4350
|
const primary = result.resources[0];
|
|
3893
4351
|
const delegationHeader = { Authorization: result.delegation };
|
|
3894
4352
|
const targetHost = grant.delegation.host ?? this.config.host;
|
|
3895
|
-
const activateResult = await (0,
|
|
4353
|
+
const activateResult = await (0, import_sdk_core8.activateSessionWithHost)(
|
|
3896
4354
|
targetHost,
|
|
3897
4355
|
delegationHeader
|
|
3898
4356
|
);
|
|
@@ -3933,10 +4391,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3933
4391
|
return this.wasmBindings.makeSpaceId(session.address, session.chainId, space);
|
|
3934
4392
|
}
|
|
3935
4393
|
expandPermissionEntries(permissions) {
|
|
3936
|
-
return (0,
|
|
4394
|
+
return (0, import_sdk_core8.expandPermissionEntries)(permissions);
|
|
3937
4395
|
}
|
|
3938
4396
|
shortServiceName(service) {
|
|
3939
|
-
const short =
|
|
4397
|
+
const short = import_sdk_core8.SERVICE_LONG_TO_SHORT[service];
|
|
3940
4398
|
if (short === void 0) {
|
|
3941
4399
|
throw new Error(
|
|
3942
4400
|
`unknown service '${service}' \u2014 no short-form mapping`
|
|
@@ -3962,7 +4420,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3962
4420
|
return abilities;
|
|
3963
4421
|
}
|
|
3964
4422
|
isEncryptionPermissionEntry(entry) {
|
|
3965
|
-
return entry.service ===
|
|
4423
|
+
return entry.service === import_sdk_core8.ENCRYPTION_PERMISSION_SERVICE && entry.path.startsWith("urn:tinycloud:encryption:");
|
|
3966
4424
|
}
|
|
3967
4425
|
permissionsToRawAbilities(entries) {
|
|
3968
4426
|
const rawAbilities = {};
|
|
@@ -3995,11 +4453,11 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3995
4453
|
}
|
|
3996
4454
|
sessionCoversPermissionEntries(session, entries) {
|
|
3997
4455
|
try {
|
|
3998
|
-
const granted = (0,
|
|
4456
|
+
const granted = (0, import_sdk_core8.parseRecapCapabilities)(
|
|
3999
4457
|
(siwe) => this.wasmBindings.parseRecapFromSiwe(siwe),
|
|
4000
4458
|
session.siwe
|
|
4001
4459
|
);
|
|
4002
|
-
return (0,
|
|
4460
|
+
return (0, import_sdk_core8.isCapabilitySubset)(entries, granted).subset;
|
|
4003
4461
|
} catch {
|
|
4004
4462
|
return false;
|
|
4005
4463
|
}
|
|
@@ -4330,7 +4788,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4330
4788
|
if (resolvedDelegateDID.endsWith(".eth") && this.config.ensResolver) {
|
|
4331
4789
|
const address = await this.config.ensResolver.resolveAddress(resolvedDelegateDID);
|
|
4332
4790
|
if (!address) throw new Error(`Could not resolve ENS name: ${resolvedDelegateDID}`);
|
|
4333
|
-
resolvedDelegateDID = (0,
|
|
4791
|
+
resolvedDelegateDID = (0, import_sdk_core8.pkhDid)(address, 1);
|
|
4334
4792
|
}
|
|
4335
4793
|
const entries = legacyParamsToPermissionEntries(
|
|
4336
4794
|
params.actions,
|
|
@@ -4345,7 +4803,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4345
4803
|
);
|
|
4346
4804
|
return result.delegation;
|
|
4347
4805
|
} catch (err) {
|
|
4348
|
-
if (err instanceof
|
|
4806
|
+
if (err instanceof import_sdk_core8.PermissionNotInManifestError) {
|
|
4349
4807
|
} else {
|
|
4350
4808
|
throw err;
|
|
4351
4809
|
}
|
|
@@ -4402,7 +4860,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4402
4860
|
...prepared,
|
|
4403
4861
|
signature
|
|
4404
4862
|
});
|
|
4405
|
-
const activateResult = await (0,
|
|
4863
|
+
const activateResult = await (0, import_sdk_core8.activateSessionWithHost)(
|
|
4406
4864
|
this.config.host,
|
|
4407
4865
|
delegationSession.delegationHeader
|
|
4408
4866
|
);
|
|
@@ -4424,7 +4882,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4424
4882
|
};
|
|
4425
4883
|
const hasKvActions = params.actions.some((a) => a.startsWith("tinycloud.kv/"));
|
|
4426
4884
|
if (hasKvActions && params.includePublicSpace !== false) {
|
|
4427
|
-
const publicSpaceId = (0,
|
|
4885
|
+
const publicSpaceId = (0, import_sdk_core8.makePublicSpaceId)(
|
|
4428
4886
|
this.wasmBindings.ensureEip55(session.address),
|
|
4429
4887
|
session.chainId
|
|
4430
4888
|
);
|
|
@@ -4447,7 +4905,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4447
4905
|
...publicPrepared,
|
|
4448
4906
|
signature: publicSignature
|
|
4449
4907
|
});
|
|
4450
|
-
const publicActivateResult = await (0,
|
|
4908
|
+
const publicActivateResult = await (0, import_sdk_core8.activateSessionWithHost)(
|
|
4451
4909
|
this.config.host,
|
|
4452
4910
|
publicSession.delegationHeader
|
|
4453
4911
|
);
|
|
@@ -4523,6 +4981,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4523
4981
|
delegation,
|
|
4524
4982
|
targetHost,
|
|
4525
4983
|
this.wasmBindings.invoke,
|
|
4984
|
+
this.wasmBindings.invokeAny,
|
|
4526
4985
|
this.config.telemetry
|
|
4527
4986
|
);
|
|
4528
4987
|
}
|
|
@@ -4552,7 +5011,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4552
5011
|
...prepared,
|
|
4553
5012
|
signature
|
|
4554
5013
|
});
|
|
4555
|
-
const activateResult = await (0,
|
|
5014
|
+
const activateResult = await (0, import_sdk_core8.activateSessionWithHost)(
|
|
4556
5015
|
targetHost,
|
|
4557
5016
|
invokerSession.delegationHeader
|
|
4558
5017
|
);
|
|
@@ -4588,6 +5047,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4588
5047
|
delegation,
|
|
4589
5048
|
targetHost,
|
|
4590
5049
|
this.wasmBindings.invoke,
|
|
5050
|
+
this.wasmBindings.invokeAny,
|
|
4591
5051
|
this.config.telemetry
|
|
4592
5052
|
);
|
|
4593
5053
|
}
|
|
@@ -4658,7 +5118,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4658
5118
|
...prepared,
|
|
4659
5119
|
signature
|
|
4660
5120
|
});
|
|
4661
|
-
const activateResult = await (0,
|
|
5121
|
+
const activateResult = await (0, import_sdk_core8.activateSessionWithHost)(
|
|
4662
5122
|
targetHost,
|
|
4663
5123
|
subDelegationSession.delegationHeader
|
|
4664
5124
|
);
|
|
@@ -4694,7 +5154,7 @@ _TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS = 6e4;
|
|
|
4694
5154
|
var TinyCloudNode = _TinyCloudNode;
|
|
4695
5155
|
|
|
4696
5156
|
// src/core.ts
|
|
4697
|
-
var
|
|
5157
|
+
var import_sdk_core11 = require("@tinycloud/sdk-core");
|
|
4698
5158
|
|
|
4699
5159
|
// src/delegation.ts
|
|
4700
5160
|
function serializeDelegation(delegation) {
|
|
@@ -4713,7 +5173,6 @@ function deserializeDelegation(data) {
|
|
|
4713
5173
|
}
|
|
4714
5174
|
|
|
4715
5175
|
// src/core.ts
|
|
4716
|
-
var import_sdk_core11 = require("@tinycloud/sdk-core");
|
|
4717
5176
|
var import_sdk_core12 = require("@tinycloud/sdk-core");
|
|
4718
5177
|
var import_sdk_core13 = require("@tinycloud/sdk-core");
|
|
4719
5178
|
var import_sdk_core14 = require("@tinycloud/sdk-core");
|
|
@@ -4722,6 +5181,7 @@ var import_sdk_core16 = require("@tinycloud/sdk-core");
|
|
|
4722
5181
|
var import_sdk_core17 = require("@tinycloud/sdk-core");
|
|
4723
5182
|
var import_sdk_core18 = require("@tinycloud/sdk-core");
|
|
4724
5183
|
var import_sdk_core19 = require("@tinycloud/sdk-core");
|
|
5184
|
+
var import_sdk_core20 = require("@tinycloud/sdk-core");
|
|
4725
5185
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4726
5186
|
0 && (module.exports = {
|
|
4727
5187
|
ACCOUNT_REGISTRY_PATH,
|
|
@@ -4762,6 +5222,7 @@ var import_sdk_core19 = require("@tinycloud/sdk-core");
|
|
|
4762
5222
|
SpaceErrorCodes,
|
|
4763
5223
|
SpaceService,
|
|
4764
5224
|
TinyCloud,
|
|
5225
|
+
TinyCloudDebugLogger,
|
|
4765
5226
|
TinyCloudNode,
|
|
4766
5227
|
UnsupportedFeatureError,
|
|
4767
5228
|
VAULT_PERMISSION_SERVICE,
|
|
@@ -4777,8 +5238,10 @@ var import_sdk_core19 = require("@tinycloud/sdk-core");
|
|
|
4777
5238
|
canonicalizeNetworkId,
|
|
4778
5239
|
canonicalizeSecretScope,
|
|
4779
5240
|
checkNodeInfo,
|
|
5241
|
+
clearTinyCloudDebugLogs,
|
|
4780
5242
|
composeManifestRequest,
|
|
4781
5243
|
createCapabilityKeyRegistry,
|
|
5244
|
+
createOpenKeyCallbackSigningStrategy,
|
|
4782
5245
|
createSharingService,
|
|
4783
5246
|
createSpaceService,
|
|
4784
5247
|
createVaultCrypto,
|
|
@@ -4788,9 +5251,13 @@ var import_sdk_core19 = require("@tinycloud/sdk-core");
|
|
|
4788
5251
|
deserializeDelegation,
|
|
4789
5252
|
didCacheKey,
|
|
4790
5253
|
didEquals,
|
|
5254
|
+
disableTinyCloudDebug,
|
|
5255
|
+
enableTinyCloudDebug,
|
|
4791
5256
|
expandActionShortNames,
|
|
4792
5257
|
expandPermissionEntries,
|
|
4793
5258
|
expandPermissionEntry,
|
|
5259
|
+
getTinyCloudDebugLogs,
|
|
5260
|
+
installTinyCloudDebugGlobals,
|
|
4794
5261
|
isCapabilitySubset,
|
|
4795
5262
|
isEvmAddress,
|
|
4796
5263
|
loadManifest,
|
|
@@ -4808,6 +5275,7 @@ var import_sdk_core19 = require("@tinycloud/sdk-core");
|
|
|
4808
5275
|
resolveSecretPath,
|
|
4809
5276
|
resourceCapabilitiesToSpaceAbilitiesMap,
|
|
4810
5277
|
serializeDelegation,
|
|
5278
|
+
tinyCloudDebugLogger,
|
|
4811
5279
|
validateManifest
|
|
4812
5280
|
});
|
|
4813
5281
|
//# sourceMappingURL=core.cjs.map
|