@tinycloud/node-sdk 3.6.0-beta.6 → 3.6.0-beta.8
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.cjs +412 -390
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +9 -2
- package/dist/core.d.ts +9 -2
- package/dist/core.js +38 -14
- package/dist/core.js.map +1 -1
- package/dist/credential-pending-store.cjs +4 -0
- package/dist/credential-pending-store.cjs.map +1 -1
- package/dist/credential-pending-store.d.cts +6 -2
- package/dist/credential-pending-store.d.ts +6 -2
- package/dist/credential-pending-store.js +2 -0
- package/dist/credential-pending-store.js.map +1 -1
- package/dist/credentials.cjs +53 -3
- package/dist/credentials.cjs.map +1 -1
- package/dist/credentials.d.cts +1 -1
- package/dist/credentials.d.ts +1 -1
- package/dist/credentials.js +51 -2
- package/dist/credentials.js.map +1 -1
- package/dist/{email-proof-Blhdm4ox.d.cts → email-proof-GXXQhIff.d.cts} +23 -2
- package/dist/{email-proof-Blhdm4ox.d.ts → email-proof-GXXQhIff.d.ts} +23 -2
- package/dist/index.cjs +470 -450
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +37 -14
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/core.cjs
CHANGED
|
@@ -30,109 +30,110 @@ 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
|
-
CaveatedDelegationUnsupportedError: () =>
|
|
40
|
-
DEFAULT_MANIFEST_SPACE: () =>
|
|
41
|
-
DEFAULT_MANIFEST_VERSION: () =>
|
|
42
|
-
DEFAULT_SIGNED_READ_URL_EXPIRY_MS: () =>
|
|
43
|
-
DataVaultService: () =>
|
|
44
|
-
DatabaseHandle: () =>
|
|
33
|
+
ACCOUNT_REGISTRY_PATH: () => import_sdk_core14.ACCOUNT_REGISTRY_PATH,
|
|
34
|
+
ACCOUNT_REGISTRY_SPACE: () => import_sdk_core14.ACCOUNT_REGISTRY_SPACE,
|
|
35
|
+
AccountService: () => import_sdk_core7.AccountService,
|
|
36
|
+
AutoApproveSpaceCreationHandler: () => import_sdk_core13.AutoApproveSpaceCreationHandler,
|
|
37
|
+
CapabilityKeyRegistry: () => import_sdk_core20.CapabilityKeyRegistry,
|
|
38
|
+
CapabilityKeyRegistryErrorCodes: () => import_sdk_core20.CapabilityKeyRegistryErrorCodes,
|
|
39
|
+
CaveatedDelegationUnsupportedError: () => import_sdk_core14.CaveatedDelegationUnsupportedError,
|
|
40
|
+
DEFAULT_MANIFEST_SPACE: () => import_sdk_core14.DEFAULT_MANIFEST_SPACE,
|
|
41
|
+
DEFAULT_MANIFEST_VERSION: () => import_sdk_core14.DEFAULT_MANIFEST_VERSION,
|
|
42
|
+
DEFAULT_SIGNED_READ_URL_EXPIRY_MS: () => import_sdk_core15.DEFAULT_SIGNED_READ_URL_EXPIRY_MS,
|
|
43
|
+
DataVaultService: () => import_sdk_core18.DataVaultService,
|
|
44
|
+
DatabaseHandle: () => import_sdk_core16.DatabaseHandle,
|
|
45
45
|
DelegatedAccess: () => DelegatedAccess,
|
|
46
|
-
DelegationErrorCodes: () =>
|
|
47
|
-
DelegationManager: () =>
|
|
48
|
-
DuckDbAction: () =>
|
|
49
|
-
DuckDbDatabaseHandle: () =>
|
|
50
|
-
DuckDbService: () =>
|
|
46
|
+
DelegationErrorCodes: () => import_sdk_core19.DelegationErrorCodes,
|
|
47
|
+
DelegationManager: () => import_sdk_core19.DelegationManager,
|
|
48
|
+
DuckDbAction: () => import_sdk_core17.DuckDbAction,
|
|
49
|
+
DuckDbDatabaseHandle: () => import_sdk_core17.DuckDbDatabaseHandle,
|
|
50
|
+
DuckDbService: () => import_sdk_core17.DuckDbService,
|
|
51
51
|
FileSessionStorage: () => FileSessionStorage,
|
|
52
|
-
IdentityParseError: () =>
|
|
52
|
+
IdentityParseError: () => import_sdk_core13.IdentityParseError,
|
|
53
53
|
InvalidRestoredSessionError: () => InvalidRestoredSessionError,
|
|
54
|
-
KVService: () =>
|
|
55
|
-
ManifestValidationError: () =>
|
|
54
|
+
KVService: () => import_sdk_core15.KVService,
|
|
55
|
+
ManifestValidationError: () => import_sdk_core14.ManifestValidationError,
|
|
56
56
|
MemorySessionStorage: () => MemorySessionStorage,
|
|
57
57
|
NodeUserAuthorization: () => NodeUserAuthorization,
|
|
58
|
-
PermissionNotInManifestError: () =>
|
|
59
|
-
PrefixedKVService: () =>
|
|
60
|
-
ProtocolMismatchError: () =>
|
|
61
|
-
SECRET_NAME_RE: () =>
|
|
62
|
-
SQLAction: () =>
|
|
63
|
-
SQLService: () =>
|
|
64
|
-
SecretsService: () =>
|
|
65
|
-
ServiceContext: () =>
|
|
66
|
-
SessionExpiredError: () =>
|
|
67
|
-
SharingService: () =>
|
|
68
|
-
SilentNotificationHandler: () =>
|
|
69
|
-
Space: () =>
|
|
70
|
-
SpaceErrorCodes: () =>
|
|
71
|
-
SpaceService: () =>
|
|
72
|
-
TinyCloud: () =>
|
|
73
|
-
TinyCloudDebugLogger: () =>
|
|
58
|
+
PermissionNotInManifestError: () => import_sdk_core14.PermissionNotInManifestError,
|
|
59
|
+
PrefixedKVService: () => import_sdk_core15.PrefixedKVService,
|
|
60
|
+
ProtocolMismatchError: () => import_sdk_core22.ProtocolMismatchError,
|
|
61
|
+
SECRET_NAME_RE: () => import_sdk_core18.SECRET_NAME_RE,
|
|
62
|
+
SQLAction: () => import_sdk_core16.SQLAction,
|
|
63
|
+
SQLService: () => import_sdk_core16.SQLService,
|
|
64
|
+
SecretsService: () => import_sdk_core18.SecretsService,
|
|
65
|
+
ServiceContext: () => import_sdk_core23.ServiceContext,
|
|
66
|
+
SessionExpiredError: () => import_sdk_core14.SessionExpiredError,
|
|
67
|
+
SharingService: () => import_sdk_core19.SharingService,
|
|
68
|
+
SilentNotificationHandler: () => import_sdk_core13.SilentNotificationHandler,
|
|
69
|
+
Space: () => import_sdk_core21.Space,
|
|
70
|
+
SpaceErrorCodes: () => import_sdk_core21.SpaceErrorCodes,
|
|
71
|
+
SpaceService: () => import_sdk_core21.SpaceService,
|
|
72
|
+
TinyCloud: () => import_sdk_core12.TinyCloud,
|
|
73
|
+
TinyCloudDebugLogger: () => import_sdk_core13.TinyCloudDebugLogger,
|
|
74
74
|
TinyCloudNode: () => TinyCloudNode,
|
|
75
|
-
UnsupportedFeatureError: () =>
|
|
75
|
+
UnsupportedFeatureError: () => import_sdk_core22.UnsupportedFeatureError,
|
|
76
76
|
UnsupportedSessionRestoreError: () => UnsupportedSessionRestoreError,
|
|
77
|
-
VAULT_PERMISSION_SERVICE: () =>
|
|
78
|
-
VaultHeaders: () =>
|
|
79
|
-
VaultPublicSpaceKVActions: () =>
|
|
80
|
-
VersionCheckError: () =>
|
|
77
|
+
VAULT_PERMISSION_SERVICE: () => import_sdk_core14.VAULT_PERMISSION_SERVICE,
|
|
78
|
+
VaultHeaders: () => import_sdk_core18.VaultHeaders,
|
|
79
|
+
VaultPublicSpaceKVActions: () => import_sdk_core18.VaultPublicSpaceKVActions,
|
|
80
|
+
VersionCheckError: () => import_sdk_core22.VersionCheckError,
|
|
81
81
|
WasmKeyProvider: () => WasmKeyProvider,
|
|
82
82
|
activateCompactRuntimeDelegation: () => activateCompactRuntimeDelegation,
|
|
83
|
-
addressStorageKey: () =>
|
|
84
|
-
buildSpaceUri: () =>
|
|
85
|
-
canonicalizeAddress: () =>
|
|
86
|
-
canonicalizeDid: () =>
|
|
87
|
-
canonicalizeDidUrl: () =>
|
|
88
|
-
canonicalizeNetworkId: () =>
|
|
89
|
-
canonicalizeSecretScope: () =>
|
|
90
|
-
checkNodeInfo: () =>
|
|
91
|
-
clearTinyCloudDebugLogs: () =>
|
|
92
|
-
composeManifestRequest: () =>
|
|
93
|
-
createCapabilityKeyRegistry: () =>
|
|
94
|
-
createOpenKeyCallbackSigningStrategy: () =>
|
|
95
|
-
createSharingService: () =>
|
|
96
|
-
createSpaceService: () =>
|
|
97
|
-
createVaultCrypto: () =>
|
|
83
|
+
addressStorageKey: () => import_sdk_core13.addressStorageKey,
|
|
84
|
+
buildSpaceUri: () => import_sdk_core21.buildSpaceUri,
|
|
85
|
+
canonicalizeAddress: () => import_sdk_core13.canonicalizeAddress,
|
|
86
|
+
canonicalizeDid: () => import_sdk_core13.canonicalizeDid,
|
|
87
|
+
canonicalizeDidUrl: () => import_sdk_core13.canonicalizeDidUrl,
|
|
88
|
+
canonicalizeNetworkId: () => import_sdk_core13.canonicalizeNetworkId,
|
|
89
|
+
canonicalizeSecretScope: () => import_sdk_core18.canonicalizeSecretScope,
|
|
90
|
+
checkNodeInfo: () => import_sdk_core22.checkNodeInfo,
|
|
91
|
+
clearTinyCloudDebugLogs: () => import_sdk_core13.clearTinyCloudDebugLogs,
|
|
92
|
+
composeManifestRequest: () => import_sdk_core14.composeManifestRequest,
|
|
93
|
+
createCapabilityKeyRegistry: () => import_sdk_core20.createCapabilityKeyRegistry,
|
|
94
|
+
createOpenKeyCallbackSigningStrategy: () => import_sdk_core4.createOpenKeyCallbackSigningStrategy,
|
|
95
|
+
createSharingService: () => import_sdk_core19.createSharingService,
|
|
96
|
+
createSpaceService: () => import_sdk_core21.createSpaceService,
|
|
97
|
+
createVaultCrypto: () => import_sdk_core18.createVaultCrypto,
|
|
98
98
|
createWasmKeyProvider: () => createWasmKeyProvider,
|
|
99
99
|
defaultSignStrategy: () => defaultSignStrategy,
|
|
100
|
-
defaultSpaceCreationHandler: () =>
|
|
100
|
+
defaultSpaceCreationHandler: () => import_sdk_core13.defaultSpaceCreationHandler,
|
|
101
101
|
deserializeDelegation: () => deserializeDelegation,
|
|
102
|
-
didCacheKey: () =>
|
|
103
|
-
didEquals: () =>
|
|
104
|
-
disableTinyCloudDebug: () =>
|
|
105
|
-
enableTinyCloudDebug: () =>
|
|
106
|
-
expandActionShortNames: () =>
|
|
107
|
-
expandPermissionEntries: () =>
|
|
108
|
-
expandPermissionEntry: () =>
|
|
102
|
+
didCacheKey: () => import_sdk_core13.didCacheKey,
|
|
103
|
+
didEquals: () => import_sdk_core13.didEquals,
|
|
104
|
+
disableTinyCloudDebug: () => import_sdk_core13.disableTinyCloudDebug,
|
|
105
|
+
enableTinyCloudDebug: () => import_sdk_core13.enableTinyCloudDebug,
|
|
106
|
+
expandActionShortNames: () => import_sdk_core14.expandActionShortNames,
|
|
107
|
+
expandPermissionEntries: () => import_sdk_core14.expandPermissionEntries,
|
|
108
|
+
expandPermissionEntry: () => import_sdk_core14.expandPermissionEntry,
|
|
109
109
|
getNodeReplicationLoaders: () => getNodeReplicationLoaders,
|
|
110
|
-
getTinyCloudDebugLogs: () =>
|
|
111
|
-
installTinyCloudDebugGlobals: () =>
|
|
112
|
-
isCapabilitySubset: () =>
|
|
113
|
-
isEvmAddress: () =>
|
|
114
|
-
loadManifest: () =>
|
|
115
|
-
makePkhSpaceId: () =>
|
|
116
|
-
makePublicSpaceId: () =>
|
|
117
|
-
parseCanonicalNetworkId: () =>
|
|
118
|
-
parseExpiry: () =>
|
|
119
|
-
parsePkhDid: () =>
|
|
120
|
-
parseSecretCatalogKey: () =>
|
|
121
|
-
parseSpaceUri: () =>
|
|
122
|
-
pkhDid: () =>
|
|
123
|
-
principalDid: () =>
|
|
124
|
-
principalDidEquals: () =>
|
|
110
|
+
getTinyCloudDebugLogs: () => import_sdk_core13.getTinyCloudDebugLogs,
|
|
111
|
+
installTinyCloudDebugGlobals: () => import_sdk_core13.installTinyCloudDebugGlobals,
|
|
112
|
+
isCapabilitySubset: () => import_sdk_core14.isCapabilitySubset,
|
|
113
|
+
isEvmAddress: () => import_sdk_core13.isEvmAddress,
|
|
114
|
+
loadManifest: () => import_sdk_core14.loadManifest,
|
|
115
|
+
makePkhSpaceId: () => import_sdk_core13.makePkhSpaceId,
|
|
116
|
+
makePublicSpaceId: () => import_sdk_core21.makePublicSpaceId,
|
|
117
|
+
parseCanonicalNetworkId: () => import_sdk_core13.parseCanonicalNetworkId,
|
|
118
|
+
parseExpiry: () => import_sdk_core14.parseExpiry,
|
|
119
|
+
parsePkhDid: () => import_sdk_core13.parsePkhDid,
|
|
120
|
+
parseSecretCatalogKey: () => import_sdk_core18.parseSecretCatalogKey,
|
|
121
|
+
parseSpaceUri: () => import_sdk_core21.parseSpaceUri,
|
|
122
|
+
pkhDid: () => import_sdk_core13.pkhDid,
|
|
123
|
+
principalDid: () => import_sdk_core13.principalDid,
|
|
124
|
+
principalDidEquals: () => import_sdk_core13.principalDidEquals,
|
|
125
|
+
refuseCaveated: () => refuseCaveated,
|
|
125
126
|
registerReplicationLoaders: () => registerReplicationLoaders,
|
|
126
|
-
resolveManifest: () =>
|
|
127
|
-
resolveSecretListPrefix: () =>
|
|
128
|
-
resolveSecretPath: () =>
|
|
129
|
-
resourceCapabilitiesToSpaceAbilitiesMap: () =>
|
|
127
|
+
resolveManifest: () => import_sdk_core14.resolveManifest,
|
|
128
|
+
resolveSecretListPrefix: () => import_sdk_core18.resolveSecretListPrefix,
|
|
129
|
+
resolveSecretPath: () => import_sdk_core18.resolveSecretPath,
|
|
130
|
+
resourceCapabilitiesToSpaceAbilitiesMap: () => import_sdk_core14.resourceCapabilitiesToSpaceAbilitiesMap,
|
|
130
131
|
serializeDelegation: () => serializeDelegation,
|
|
131
|
-
tinyCloudDebugLogger: () =>
|
|
132
|
-
validateManifest: () =>
|
|
132
|
+
tinyCloudDebugLogger: () => import_sdk_core13.tinyCloudDebugLogger,
|
|
133
|
+
validateManifest: () => import_sdk_core14.validateManifest
|
|
133
134
|
});
|
|
134
135
|
module.exports = __toCommonJS(core_exports);
|
|
135
|
-
var
|
|
136
|
+
var import_sdk_core12 = require("@tinycloud/sdk-core");
|
|
136
137
|
|
|
137
138
|
// src/replication/module-registry.ts
|
|
138
139
|
var nodeLoaders;
|
|
@@ -147,7 +148,7 @@ function getNodeReplicationLoaders() {
|
|
|
147
148
|
}
|
|
148
149
|
|
|
149
150
|
// src/core.ts
|
|
150
|
-
var
|
|
151
|
+
var import_sdk_core13 = require("@tinycloud/sdk-core");
|
|
151
152
|
|
|
152
153
|
// src/storage/MemorySessionStorage.ts
|
|
153
154
|
var MemorySessionStorage = class {
|
|
@@ -343,7 +344,7 @@ var FileSessionStorage = class {
|
|
|
343
344
|
// src/authorization/NodeUserAuthorization.ts
|
|
344
345
|
var import_node_crypto = require("crypto");
|
|
345
346
|
var import_siwe = require("siwe");
|
|
346
|
-
var
|
|
347
|
+
var import_sdk_core5 = require("@tinycloud/sdk-core");
|
|
347
348
|
|
|
348
349
|
// src/replication/authority-sign-in.ts
|
|
349
350
|
var import_sdk_core2 = require("@tinycloud/sdk-core");
|
|
@@ -393,8 +394,21 @@ function augmentSignInEntriesWithReplication(input) {
|
|
|
393
394
|
return out;
|
|
394
395
|
}
|
|
395
396
|
|
|
396
|
-
// src/authorization/
|
|
397
|
+
// src/authorization/caveatRefusal.ts
|
|
397
398
|
var import_sdk_core3 = require("@tinycloud/sdk-core");
|
|
399
|
+
function refuseCaveated(input) {
|
|
400
|
+
const caveated = [input ?? []].flat().flatMap((item) => [item, ...item.permissions ?? []]).filter(({ caveats }) => {
|
|
401
|
+
try {
|
|
402
|
+
return caveats === null || !(0, import_sdk_core3.recapCaveatsEqual)(caveats, void 0);
|
|
403
|
+
} catch {
|
|
404
|
+
return true;
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
if (caveated.length) throw new import_sdk_core3.CaveatedDelegationUnsupportedError(caveated);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// src/authorization/strategies.ts
|
|
411
|
+
var import_sdk_core4 = require("@tinycloud/sdk-core");
|
|
398
412
|
var defaultSignStrategy = { type: "auto-sign" };
|
|
399
413
|
|
|
400
414
|
// src/authorization/NodeUserAuthorization.ts
|
|
@@ -402,8 +416,8 @@ function pkhSpaceIdentity(spaceId) {
|
|
|
402
416
|
const match = /^(tinycloud:pkh:eip155:\d+:)(0x[0-9a-fA-F]{40})(:.+)$/.exec(spaceId);
|
|
403
417
|
return match === null ? spaceId : `${match[1]}${match[2].toLowerCase()}${match[3]}`;
|
|
404
418
|
}
|
|
405
|
-
var DECRYPT_ACTION =
|
|
406
|
-
var NETWORK_CREATE_ACTION =
|
|
419
|
+
var DECRYPT_ACTION = import_sdk_core5.ENCRYPTION.DECRYPT;
|
|
420
|
+
var NETWORK_CREATE_ACTION = import_sdk_core5.ENCRYPTION.NETWORK_CREATE;
|
|
407
421
|
function describeHostFailure(result) {
|
|
408
422
|
const text = result.error?.trim();
|
|
409
423
|
return text ? `${result.status} - ${text}` : `${result.status}`;
|
|
@@ -431,7 +445,7 @@ function canonicalOpenKeyManifestSha256Hex(value) {
|
|
|
431
445
|
}
|
|
432
446
|
function didPrincipalMatches(actual, expected) {
|
|
433
447
|
try {
|
|
434
|
-
return (0,
|
|
448
|
+
return (0, import_sdk_core5.principalDidEquals)(actual, expected);
|
|
435
449
|
} catch {
|
|
436
450
|
return actual === expected;
|
|
437
451
|
}
|
|
@@ -447,7 +461,7 @@ function addRawAbility(rawAbilities, resource, action) {
|
|
|
447
461
|
}
|
|
448
462
|
}
|
|
449
463
|
function primaryManifestSpace(resources) {
|
|
450
|
-
return resources.find((entry) => entry.space !== "account")?.space ?? resources[0]?.space ??
|
|
464
|
+
return resources.find((entry) => entry.space !== "account")?.space ?? resources[0]?.space ?? import_sdk_core5.DEFAULT_MANIFEST_SPACE;
|
|
451
465
|
}
|
|
452
466
|
function cloneAbilitiesMap(actions) {
|
|
453
467
|
return Object.fromEntries(
|
|
@@ -488,30 +502,30 @@ var NodeUserAuthorization = class {
|
|
|
488
502
|
this.spacePrefix = config.spacePrefix ?? "default";
|
|
489
503
|
this.defaultActions = config.defaultActions ?? {
|
|
490
504
|
kv: {
|
|
491
|
-
"": [
|
|
505
|
+
"": [import_sdk_core5.KV.PUT, import_sdk_core5.KV.GET, import_sdk_core5.KV.DEL, import_sdk_core5.KV.LIST, import_sdk_core5.KV.METADATA]
|
|
492
506
|
},
|
|
493
507
|
sql: {
|
|
494
|
-
"": [
|
|
508
|
+
"": [import_sdk_core5.SQL.READ, import_sdk_core5.SQL.WRITE, import_sdk_core5.SQL.SCHEMA, import_sdk_core5.SQL.ADMIN, import_sdk_core5.SQL.EXPORT]
|
|
495
509
|
},
|
|
496
510
|
duckdb: {
|
|
497
511
|
"": [
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
512
|
+
import_sdk_core5.DUCKDB.READ,
|
|
513
|
+
import_sdk_core5.DUCKDB.WRITE,
|
|
514
|
+
import_sdk_core5.DUCKDB.ADMIN,
|
|
515
|
+
import_sdk_core5.DUCKDB.DESCRIBE,
|
|
516
|
+
import_sdk_core5.DUCKDB.EXPORT,
|
|
517
|
+
import_sdk_core5.DUCKDB.IMPORT,
|
|
518
|
+
import_sdk_core5.DUCKDB.EXECUTE
|
|
505
519
|
]
|
|
506
520
|
},
|
|
507
521
|
capabilities: {
|
|
508
|
-
"": [
|
|
522
|
+
"": [import_sdk_core5.CAPABILITIES.READ]
|
|
509
523
|
},
|
|
510
524
|
hooks: {
|
|
511
|
-
"": [
|
|
525
|
+
"": [import_sdk_core5.HOOKS.SUBSCRIBE, import_sdk_core5.HOOKS.REGISTER, import_sdk_core5.HOOKS.LIST, import_sdk_core5.HOOKS.UNREGISTER]
|
|
512
526
|
}
|
|
513
527
|
};
|
|
514
|
-
this.sessionExpirationMs = config.sessionExpirationMs ??
|
|
528
|
+
this.sessionExpirationMs = config.sessionExpirationMs ?? import_sdk_core5.EXPIRY.SESSION_MS;
|
|
515
529
|
this.autoCreateSpace = config.autoCreateSpace ?? false;
|
|
516
530
|
this.spaceCreationHandler = config.spaceCreationHandler;
|
|
517
531
|
this.tinycloudHosts = config.tinycloudHosts;
|
|
@@ -520,7 +534,7 @@ var NodeUserAuthorization = class {
|
|
|
520
534
|
this.registryPolicy = config.registryPolicy;
|
|
521
535
|
this.newUserHost = config.newUserHost;
|
|
522
536
|
this.registryChainId = config.registryChainId;
|
|
523
|
-
this.registrySequenceStore = config.registrySequenceStore ?? (0,
|
|
537
|
+
this.registrySequenceStore = config.registrySequenceStore ?? (0, import_sdk_core5.createInMemoryRegistrySequenceStore)();
|
|
524
538
|
this.onNodeNotFound = config.onNodeNotFound;
|
|
525
539
|
this.autoDiscoverLocalNode = config.autoDiscoverLocalNode;
|
|
526
540
|
this.localNodeUrl = config.localNodeUrl;
|
|
@@ -597,7 +611,7 @@ var NodeUserAuthorization = class {
|
|
|
597
611
|
* {@link ensureTinyCloudHosts}.
|
|
598
612
|
*/
|
|
599
613
|
setRestoredTinyCloudSession(session, hosts) {
|
|
600
|
-
const address = (0,
|
|
614
|
+
const address = (0, import_sdk_core5.canonicalizeAddress)(session.address);
|
|
601
615
|
this._tinyCloudSession = { ...session, address };
|
|
602
616
|
this._address = address;
|
|
603
617
|
this._chainId = session.chainId;
|
|
@@ -685,7 +699,7 @@ var NodeUserAuthorization = class {
|
|
|
685
699
|
return;
|
|
686
700
|
}
|
|
687
701
|
if (this.registryPolicy === "fail-closed") {
|
|
688
|
-
const resolved2 = await (0,
|
|
702
|
+
const resolved2 = await (0, import_sdk_core5.resolveFailClosedTinyCloudHosts)(address, {
|
|
689
703
|
registryUrl: this.tinycloudRegistryUrl,
|
|
690
704
|
registryChainId: this.registryChainId,
|
|
691
705
|
newUserHost: this.newUserHost,
|
|
@@ -701,8 +715,8 @@ var NodeUserAuthorization = class {
|
|
|
701
715
|
this.registryVerdict = resolved2.verdict;
|
|
702
716
|
return;
|
|
703
717
|
}
|
|
704
|
-
const subject = (0,
|
|
705
|
-
const resolved = await (0,
|
|
718
|
+
const subject = (0, import_sdk_core5.pkhDid)(address, chainId);
|
|
719
|
+
const resolved = await (0, import_sdk_core5.resolveTinyCloudHosts)(subject, {
|
|
706
720
|
registryUrl: this.tinycloudRegistryUrl,
|
|
707
721
|
fallbackHosts: this.tinycloudFallbackHosts,
|
|
708
722
|
autoDiscoverLocalNode: this.autoDiscoverLocalNode,
|
|
@@ -728,16 +742,16 @@ var NodeUserAuthorization = class {
|
|
|
728
742
|
throw new Error("Must be signed in to create a space");
|
|
729
743
|
}
|
|
730
744
|
await this.ensureTinyCloudHosts();
|
|
731
|
-
const subject = (0,
|
|
745
|
+
const subject = (0, import_sdk_core5.registryOwnerSubjectV1)(this._address, this.registryChainId);
|
|
732
746
|
let verdict = this.registryVerdict;
|
|
733
747
|
if (verdict?.subject !== subject || verdict.status === "unavailable") {
|
|
734
|
-
verdict = await (0,
|
|
748
|
+
verdict = await (0, import_sdk_core5.lookupOwnerRegistryVerdict)(subject, {
|
|
735
749
|
registryUrl: this.tinycloudRegistryUrl,
|
|
736
750
|
sequenceStore: this.registrySequenceStore
|
|
737
751
|
});
|
|
738
752
|
this.registryVerdict = verdict;
|
|
739
753
|
}
|
|
740
|
-
(0,
|
|
754
|
+
(0, import_sdk_core5.assertSpaceCreationAllowed)(verdict, this.primaryTinyCloudHost);
|
|
741
755
|
}
|
|
742
756
|
requireTinyCloudHosts() {
|
|
743
757
|
if (!this.tinycloudHosts || this.tinycloudHosts.length === 0) {
|
|
@@ -756,7 +770,7 @@ var NodeUserAuthorization = class {
|
|
|
756
770
|
}
|
|
757
771
|
async refreshNodeInfo() {
|
|
758
772
|
const infoHost = this.primaryTinyCloudHost;
|
|
759
|
-
const nodeInfo = await (0,
|
|
773
|
+
const nodeInfo = await (0, import_sdk_core5.checkNodeInfo)(infoHost, this.wasm.protocolVersion());
|
|
760
774
|
this._nodeFeatures = nodeInfo.features;
|
|
761
775
|
this._nodeFeaturesKnown = true;
|
|
762
776
|
this._nodeInfoIdentity = nodeInfo.nodeId ? { host: infoHost, nodeId: nodeInfo.nodeId } : void 0;
|
|
@@ -809,7 +823,7 @@ var NodeUserAuthorization = class {
|
|
|
809
823
|
if (this._manifest === void 0) {
|
|
810
824
|
return void 0;
|
|
811
825
|
}
|
|
812
|
-
this._capabilityRequest = (0,
|
|
826
|
+
this._capabilityRequest = (0, import_sdk_core5.composeManifestRequest)(
|
|
813
827
|
Array.isArray(this._manifest) ? this._manifest : [this._manifest],
|
|
814
828
|
{
|
|
815
829
|
includeAccountRegistryPermissions: this.includeAccountRegistryPermissions
|
|
@@ -821,7 +835,7 @@ var NodeUserAuthorization = class {
|
|
|
821
835
|
if (space.startsWith("tinycloud:")) {
|
|
822
836
|
return space;
|
|
823
837
|
}
|
|
824
|
-
return (0,
|
|
838
|
+
return (0, import_sdk_core5.makePkhSpaceId)(address, chainId, space);
|
|
825
839
|
}
|
|
826
840
|
/**
|
|
827
841
|
* The plain-session primary abilities: `defaultActions` (the shared table)
|
|
@@ -832,10 +846,10 @@ var NodeUserAuthorization = class {
|
|
|
832
846
|
* can't disagree (§4.6).
|
|
833
847
|
*/
|
|
834
848
|
primaryActionsForSignIn() {
|
|
835
|
-
const primaryActions = this.includeAccountRegistryPermissions && this.spacePrefix ===
|
|
836
|
-
if (this.includeAccountRegistryPermissions && this.spacePrefix ===
|
|
837
|
-
const accountAbilities = (0,
|
|
838
|
-
|
|
849
|
+
const primaryActions = this.includeAccountRegistryPermissions && this.spacePrefix === import_sdk_core5.ACCOUNT_REGISTRY_SPACE ? cloneAbilitiesMap(this.defaultActions) : this.defaultActions;
|
|
850
|
+
if (this.includeAccountRegistryPermissions && this.spacePrefix === import_sdk_core5.ACCOUNT_REGISTRY_SPACE) {
|
|
851
|
+
const accountAbilities = (0, import_sdk_core5.resourceCapabilitiesToAbilitiesMap)(
|
|
852
|
+
import_sdk_core5.ACCOUNT_MANIFEST_PERMISSIONS
|
|
839
853
|
);
|
|
840
854
|
for (const [service, paths] of Object.entries(accountAbilities)) {
|
|
841
855
|
const existingPaths = primaryActions[service] ?? (primaryActions[service] = {});
|
|
@@ -862,11 +876,11 @@ var NodeUserAuthorization = class {
|
|
|
862
876
|
return {
|
|
863
877
|
kv: {
|
|
864
878
|
"vault/secrets/": [
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
879
|
+
import_sdk_core5.KV.GET,
|
|
880
|
+
import_sdk_core5.KV.PUT,
|
|
881
|
+
import_sdk_core5.KV.DEL,
|
|
882
|
+
import_sdk_core5.KV.LIST,
|
|
883
|
+
import_sdk_core5.KV.METADATA
|
|
870
884
|
]
|
|
871
885
|
}
|
|
872
886
|
};
|
|
@@ -881,7 +895,7 @@ var NodeUserAuthorization = class {
|
|
|
881
895
|
signInPermissionInputs(address, chainId) {
|
|
882
896
|
const request = this.getCapabilityRequest();
|
|
883
897
|
if (request === void 0) {
|
|
884
|
-
const primarySpaceId2 = (0,
|
|
898
|
+
const primarySpaceId2 = (0, import_sdk_core5.makePkhSpaceId)(address, chainId, this.spacePrefix);
|
|
885
899
|
const effectivePrimary = this.spacePrefix === "secrets" ? this.secretsPrimaryAbilities() : this.primaryActionsForSignIn();
|
|
886
900
|
const kvPaths = effectivePrimary["kv"] ?? {};
|
|
887
901
|
return {
|
|
@@ -895,7 +909,7 @@ var NodeUserAuthorization = class {
|
|
|
895
909
|
};
|
|
896
910
|
}
|
|
897
911
|
const spaceResources = request.resources.filter(
|
|
898
|
-
(entry) => entry.service !==
|
|
912
|
+
(entry) => entry.service !== import_sdk_core5.ENCRYPTION_PERMISSION_SERVICE
|
|
899
913
|
);
|
|
900
914
|
const primarySpaceName = primaryManifestSpace(spaceResources);
|
|
901
915
|
const primarySpaceId = this.resolveSpaceName(
|
|
@@ -961,21 +975,21 @@ var NodeUserAuthorization = class {
|
|
|
961
975
|
});
|
|
962
976
|
}
|
|
963
977
|
defaultEncryptionNetworkId(address, chainId) {
|
|
964
|
-
return `urn:tinycloud:encryption:${(0,
|
|
978
|
+
return `urn:tinycloud:encryption:${(0, import_sdk_core5.pkhDid)(address, chainId)}:default`;
|
|
965
979
|
}
|
|
966
980
|
resolveSignInCapabilities(address, chainId) {
|
|
967
981
|
const request = this.getCapabilityRequest();
|
|
968
982
|
if (request === void 0) {
|
|
969
983
|
const defaultNetworkId = this.defaultEncryptionNetworkId(address, chainId);
|
|
970
|
-
const primarySpaceId2 = (0,
|
|
971
|
-
const secretsSpaceId = (0,
|
|
984
|
+
const primarySpaceId2 = (0, import_sdk_core5.makePkhSpaceId)(address, chainId, this.spacePrefix);
|
|
985
|
+
const secretsSpaceId = (0, import_sdk_core5.makePkhSpaceId)(address, chainId, "secrets");
|
|
972
986
|
const primaryActions = this.primaryActionsForSignIn();
|
|
973
987
|
const spaceAbilities2 = {
|
|
974
988
|
[primarySpaceId2]: primaryActions,
|
|
975
989
|
[secretsSpaceId]: this.secretsPrimaryAbilities()
|
|
976
990
|
};
|
|
977
|
-
if (this.includeAccountRegistryPermissions && this.spacePrefix !==
|
|
978
|
-
spaceAbilities2[(0,
|
|
991
|
+
if (this.includeAccountRegistryPermissions && this.spacePrefix !== import_sdk_core5.ACCOUNT_REGISTRY_SPACE) {
|
|
992
|
+
spaceAbilities2[(0, import_sdk_core5.makePkhSpaceId)(address, chainId, import_sdk_core5.ACCOUNT_REGISTRY_SPACE)] = (0, import_sdk_core5.resourceCapabilitiesToAbilitiesMap)(import_sdk_core5.ACCOUNT_MANIFEST_PERMISSIONS);
|
|
979
993
|
}
|
|
980
994
|
const mergedPrimary = this.mergeReplicationEntries(
|
|
981
995
|
spaceAbilities2,
|
|
@@ -996,16 +1010,16 @@ var NodeUserAuthorization = class {
|
|
|
996
1010
|
};
|
|
997
1011
|
}
|
|
998
1012
|
const rawAbilities = {};
|
|
999
|
-
const currentDid = (0,
|
|
1013
|
+
const currentDid = (0, import_sdk_core5.pkhDid)(address, chainId);
|
|
1000
1014
|
const spaceResources = request.resources.filter((entry) => {
|
|
1001
|
-
if (entry.service !==
|
|
1015
|
+
if (entry.service !== import_sdk_core5.ENCRYPTION_PERMISSION_SERVICE) {
|
|
1002
1016
|
return true;
|
|
1003
1017
|
}
|
|
1004
1018
|
for (const action of entry.actions) {
|
|
1005
1019
|
addRawAbility(rawAbilities, entry.path, action);
|
|
1006
1020
|
}
|
|
1007
1021
|
if (entry.actions.includes(DECRYPT_ACTION)) {
|
|
1008
|
-
const parsed = (0,
|
|
1022
|
+
const parsed = (0, import_sdk_core5.parseNetworkId)(entry.path);
|
|
1009
1023
|
if (didPrincipalMatches(parsed.ownerDid, currentDid)) {
|
|
1010
1024
|
addRawAbility(rawAbilities, entry.path, NETWORK_CREATE_ACTION);
|
|
1011
1025
|
}
|
|
@@ -1018,7 +1032,7 @@ var NodeUserAuthorization = class {
|
|
|
1018
1032
|
address,
|
|
1019
1033
|
chainId
|
|
1020
1034
|
);
|
|
1021
|
-
const bySpace = (0,
|
|
1035
|
+
const bySpace = (0, import_sdk_core5.resourceCapabilitiesToSpaceAbilitiesMap)(spaceResources);
|
|
1022
1036
|
const spaceAbilities = {};
|
|
1023
1037
|
for (const [space, abilities] of Object.entries(bySpace)) {
|
|
1024
1038
|
spaceAbilities[this.resolveSpaceName(space, address, chainId)] = abilities;
|
|
@@ -1026,7 +1040,7 @@ var NodeUserAuthorization = class {
|
|
|
1026
1040
|
const mergedPrimaryAbilities = this.mergeReplicationEntries(
|
|
1027
1041
|
spaceAbilities,
|
|
1028
1042
|
primarySpaceId,
|
|
1029
|
-
spaceAbilities[primarySpaceId] ?? (0,
|
|
1043
|
+
spaceAbilities[primarySpaceId] ?? (0, import_sdk_core5.resourceCapabilitiesToAbilitiesMap)([]),
|
|
1030
1044
|
augmentSignInEntriesWithReplication({
|
|
1031
1045
|
...this.signInPermissionInputs(address, chainId),
|
|
1032
1046
|
replication: this.replication
|
|
@@ -1098,7 +1112,7 @@ var NodeUserAuthorization = class {
|
|
|
1098
1112
|
await this.ensureTinyCloudHosts();
|
|
1099
1113
|
const host = this.primaryTinyCloudHost;
|
|
1100
1114
|
const spaceId = targetSpaceId ?? this._tinyCloudSession.spaceId;
|
|
1101
|
-
const peerId = await (0,
|
|
1115
|
+
const peerId = await (0, import_sdk_core5.fetchPeerId)(host, spaceId, signal);
|
|
1102
1116
|
const siwe = this.wasm.generateHostSIWEMessage({
|
|
1103
1117
|
address: this._address,
|
|
1104
1118
|
chainId: this._chainId,
|
|
@@ -1128,7 +1142,7 @@ var NodeUserAuthorization = class {
|
|
|
1128
1142
|
}
|
|
1129
1143
|
if (signal?.aborted) throw signal.reason;
|
|
1130
1144
|
const headers = this.wasm.siweToDelegationHeaders({ siwe, signature });
|
|
1131
|
-
return (0,
|
|
1145
|
+
return (0, import_sdk_core5.submitHostDelegation)(host, headers, signal);
|
|
1132
1146
|
}
|
|
1133
1147
|
/**
|
|
1134
1148
|
* Create a specific space on the server via host delegation.
|
|
@@ -1167,12 +1181,12 @@ var NodeUserAuthorization = class {
|
|
|
1167
1181
|
await this.ensureTinyCloudHosts();
|
|
1168
1182
|
const host = this.primaryTinyCloudHost;
|
|
1169
1183
|
const primarySpaceId = this._tinyCloudSession.spaceId;
|
|
1170
|
-
const result = await (0,
|
|
1184
|
+
const result = await (0, import_sdk_core5.activateSessionWithHost)(
|
|
1171
1185
|
host,
|
|
1172
1186
|
this._tinyCloudSession.delegationHeader
|
|
1173
1187
|
);
|
|
1174
1188
|
this.recordActivationSkippedSpaces(result, primarySpaceId);
|
|
1175
|
-
const handler = this.spaceCreationHandler ?? (this.autoCreateSpace ? new
|
|
1189
|
+
const handler = this.spaceCreationHandler ?? (this.autoCreateSpace ? new import_sdk_core5.AutoApproveSpaceCreationHandler() : void 0);
|
|
1176
1190
|
const creationContext = {
|
|
1177
1191
|
spaceId: primarySpaceId,
|
|
1178
1192
|
address: this._address,
|
|
@@ -1209,7 +1223,7 @@ var NodeUserAuthorization = class {
|
|
|
1209
1223
|
throw error;
|
|
1210
1224
|
}
|
|
1211
1225
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
1212
|
-
const retryResult = await (0,
|
|
1226
|
+
const retryResult = await (0, import_sdk_core5.activateSessionWithHost)(
|
|
1213
1227
|
host,
|
|
1214
1228
|
this._tinyCloudSession.delegationHeader
|
|
1215
1229
|
);
|
|
@@ -1250,7 +1264,7 @@ var NodeUserAuthorization = class {
|
|
|
1250
1264
|
throw error;
|
|
1251
1265
|
}
|
|
1252
1266
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
1253
|
-
const retryResult = await (0,
|
|
1267
|
+
const retryResult = await (0, import_sdk_core5.activateSessionWithHost)(
|
|
1254
1268
|
host,
|
|
1255
1269
|
this._tinyCloudSession.delegationHeader
|
|
1256
1270
|
);
|
|
@@ -1290,6 +1304,7 @@ var NodeUserAuthorization = class {
|
|
|
1290
1304
|
this._lastActivationSkippedSpaceIds = result.status === 404 ? [primarySpaceId] : [];
|
|
1291
1305
|
}
|
|
1292
1306
|
async createBootstrapSession(options) {
|
|
1307
|
+
refuseCaveated(options.capabilityRequest.manifests);
|
|
1293
1308
|
if (!this._address || !this._chainId) {
|
|
1294
1309
|
throw new Error("Must be signed in before creating bootstrap sessions");
|
|
1295
1310
|
}
|
|
@@ -1318,9 +1333,9 @@ var NodeUserAuthorization = class {
|
|
|
1318
1333
|
}
|
|
1319
1334
|
const spaceAbilities = {};
|
|
1320
1335
|
for (const { spaceId, resources } of resourcesBySpace.values()) {
|
|
1321
|
-
spaceAbilities[spaceId] = (0,
|
|
1336
|
+
spaceAbilities[spaceId] = (0, import_sdk_core5.resourceCapabilitiesToAbilitiesMap)(resources);
|
|
1322
1337
|
}
|
|
1323
|
-
const abilities = spaceAbilities[options.spaceId] ?? (0,
|
|
1338
|
+
const abilities = spaceAbilities[options.spaceId] ?? (0, import_sdk_core5.resourceCapabilitiesToAbilitiesMap)([]);
|
|
1324
1339
|
const prepared = this.wasm.prepareSession({
|
|
1325
1340
|
abilities,
|
|
1326
1341
|
spaceAbilities,
|
|
@@ -1391,8 +1406,9 @@ var NodeUserAuthorization = class {
|
|
|
1391
1406
|
* @param options - Optional per-call SIWE overrides for this sign-in only
|
|
1392
1407
|
*/
|
|
1393
1408
|
async signIn(options) {
|
|
1409
|
+
refuseCaveated(this.getCapabilityRequest()?.manifests);
|
|
1394
1410
|
const generation = this.sessionGeneration;
|
|
1395
|
-
const address = (0,
|
|
1411
|
+
const address = (0, import_sdk_core5.canonicalizeAddress)(await this.signer.getAddress());
|
|
1396
1412
|
const chainId = await this.signer.getChainId();
|
|
1397
1413
|
this.assertSignInCurrent(generation);
|
|
1398
1414
|
this._address = address;
|
|
@@ -1444,7 +1460,7 @@ var NodeUserAuthorization = class {
|
|
|
1444
1460
|
siwe: prepared.siwe,
|
|
1445
1461
|
signature
|
|
1446
1462
|
};
|
|
1447
|
-
const spacesMetadata = this.enablePublicSpace ? { public: (0,
|
|
1463
|
+
const spacesMetadata = this.enablePublicSpace ? { public: (0, import_sdk_core5.makePkhSpaceId)(address, chainId, "public") } : void 0;
|
|
1448
1464
|
const tinyCloudSession = {
|
|
1449
1465
|
address,
|
|
1450
1466
|
chainId,
|
|
@@ -1514,7 +1530,7 @@ var NodeUserAuthorization = class {
|
|
|
1514
1530
|
*/
|
|
1515
1531
|
async signMessage(message, purpose) {
|
|
1516
1532
|
if (!this._address) {
|
|
1517
|
-
this._address = (0,
|
|
1533
|
+
this._address = (0, import_sdk_core5.canonicalizeAddress)(await this.signer.getAddress());
|
|
1518
1534
|
}
|
|
1519
1535
|
if (!this._chainId) {
|
|
1520
1536
|
this._chainId = await this.signer.getChainId();
|
|
@@ -1542,7 +1558,8 @@ var NodeUserAuthorization = class {
|
|
|
1542
1558
|
* ```
|
|
1543
1559
|
*/
|
|
1544
1560
|
async prepareSessionForSigning() {
|
|
1545
|
-
|
|
1561
|
+
refuseCaveated(this.getCapabilityRequest()?.manifests);
|
|
1562
|
+
const address = (0, import_sdk_core5.canonicalizeAddress)(await this.signer.getAddress());
|
|
1546
1563
|
const chainId = await this.signer.getChainId();
|
|
1547
1564
|
const keyId = `session-${Date.now()}`;
|
|
1548
1565
|
this.sessionManager.renameSessionKeyId(this.activeSessionKeyId, keyId);
|
|
@@ -1593,7 +1610,7 @@ var NodeUserAuthorization = class {
|
|
|
1593
1610
|
...prepared,
|
|
1594
1611
|
signature
|
|
1595
1612
|
});
|
|
1596
|
-
const address = (0,
|
|
1613
|
+
const address = (0, import_sdk_core5.canonicalizeAddress)(await this.signer.getAddress());
|
|
1597
1614
|
const chainId = await this.signer.getChainId();
|
|
1598
1615
|
await this.resolveTinyCloudHostsForSignIn(address, chainId);
|
|
1599
1616
|
const clientSession = {
|
|
@@ -1604,7 +1621,7 @@ var NodeUserAuthorization = class {
|
|
|
1604
1621
|
siwe: prepared.siwe,
|
|
1605
1622
|
signature
|
|
1606
1623
|
};
|
|
1607
|
-
const spacesMetadata = this.enablePublicSpace ? { public: (0,
|
|
1624
|
+
const spacesMetadata = this.enablePublicSpace ? { public: (0, import_sdk_core5.makePkhSpaceId)(address, chainId, "public") } : void 0;
|
|
1608
1625
|
const tinyCloudSession = {
|
|
1609
1626
|
address,
|
|
1610
1627
|
chainId,
|
|
@@ -1673,6 +1690,7 @@ var NodeUserAuthorization = class {
|
|
|
1673
1690
|
* @param options Optional overrides for the OpenKey request.
|
|
1674
1691
|
*/
|
|
1675
1692
|
async signInWithOpenKey(authorizeFn, options) {
|
|
1693
|
+
refuseCaveated(this.getCapabilityRequest()?.manifests);
|
|
1676
1694
|
if (options?.host !== void 0) {
|
|
1677
1695
|
const overrideHost = options.host.trim();
|
|
1678
1696
|
if (!overrideHost) {
|
|
@@ -1680,7 +1698,7 @@ var NodeUserAuthorization = class {
|
|
|
1680
1698
|
}
|
|
1681
1699
|
this.tinycloudHosts = [overrideHost];
|
|
1682
1700
|
}
|
|
1683
|
-
const signingAddress = (0,
|
|
1701
|
+
const signingAddress = (0, import_sdk_core5.canonicalizeAddress)(await this.signer.getAddress());
|
|
1684
1702
|
const signingChainId = await this.signer.getChainId();
|
|
1685
1703
|
await this.resolveTinyCloudHostsForSignIn(signingAddress, signingChainId);
|
|
1686
1704
|
const { prepared, keyId, jwk } = await this.prepareSessionForSigning();
|
|
@@ -1811,8 +1829,8 @@ var NodeUserAuthorization = class {
|
|
|
1811
1829
|
"signInWithOpenKeyResult requires prepared.siwe (the SDK-generated SIWE the sign-in was proposed with)"
|
|
1812
1830
|
);
|
|
1813
1831
|
}
|
|
1814
|
-
const expectedAddress = (0,
|
|
1815
|
-
if ((0,
|
|
1832
|
+
const expectedAddress = (0, import_sdk_core5.canonicalizeAddress)(await this.signer.getAddress());
|
|
1833
|
+
if ((0, import_sdk_core5.canonicalizeAddress)(result.address) !== expectedAddress) {
|
|
1816
1834
|
throw new Error(
|
|
1817
1835
|
`OpenKey returned signature from ${result.address} but expected ${expectedAddress}`
|
|
1818
1836
|
);
|
|
@@ -1837,15 +1855,15 @@ var NodeUserAuthorization = class {
|
|
|
1837
1855
|
`OpenKey signature verification failed${type ? `: ${type}` : ""}${details}`
|
|
1838
1856
|
);
|
|
1839
1857
|
}
|
|
1840
|
-
if ((0,
|
|
1858
|
+
if ((0, import_sdk_core5.canonicalizeAddress)(parsedSignedSiwe.address) !== expectedAddress) {
|
|
1841
1859
|
throw new Error(
|
|
1842
1860
|
`OpenKey signedMessage.address (${parsedSignedSiwe.address}) does not match local signer address (${expectedAddress})`
|
|
1843
1861
|
);
|
|
1844
1862
|
}
|
|
1845
1863
|
const originalHasRecap = /(?:^|\n)-\s+urn:recap:/i.test(prepared.siwe);
|
|
1846
|
-
const originalFields = (0,
|
|
1847
|
-
const signedFields = (0,
|
|
1848
|
-
const changedFields = (0,
|
|
1864
|
+
const originalFields = (0, import_sdk_core5.extractImmutableSiweFields)(prepared.siwe);
|
|
1865
|
+
const signedFields = (0, import_sdk_core5.extractImmutableSiweFields)(result.signedMessage);
|
|
1866
|
+
const changedFields = (0, import_sdk_core5.diffImmutableSiweFields)(originalFields, signedFields, {
|
|
1849
1867
|
originalHasRecap
|
|
1850
1868
|
});
|
|
1851
1869
|
if (changedFields.length > 0) {
|
|
@@ -1856,20 +1874,20 @@ var NodeUserAuthorization = class {
|
|
|
1856
1874
|
let originalCaps;
|
|
1857
1875
|
let signedCaps;
|
|
1858
1876
|
try {
|
|
1859
|
-
originalCaps = (0,
|
|
1877
|
+
originalCaps = (0, import_sdk_core5.extractRecapAttenuations)(prepared.siwe);
|
|
1860
1878
|
} catch (err2) {
|
|
1861
1879
|
throw new Error(
|
|
1862
1880
|
`Failed to decode prepared SIWE recap: ${err2.message}`
|
|
1863
1881
|
);
|
|
1864
1882
|
}
|
|
1865
1883
|
try {
|
|
1866
|
-
signedCaps = (0,
|
|
1884
|
+
signedCaps = (0, import_sdk_core5.extractRecapAttenuations)(result.signedMessage);
|
|
1867
1885
|
} catch (err2) {
|
|
1868
1886
|
throw new Error(
|
|
1869
1887
|
`Failed to decode OpenKey signedMessage recap: ${err2.message}`
|
|
1870
1888
|
);
|
|
1871
1889
|
}
|
|
1872
|
-
const unauthorized = (0,
|
|
1890
|
+
const unauthorized = (0, import_sdk_core5.unauthorizedRecapCapabilities)(signedCaps, originalCaps);
|
|
1873
1891
|
if (unauthorized.length > 0) {
|
|
1874
1892
|
const previewLimit = 5;
|
|
1875
1893
|
const preview = unauthorized.slice(0, previewLimit).map((u) => `${u.resource}::${u.action}`).join(", ");
|
|
@@ -1886,7 +1904,7 @@ var NodeUserAuthorization = class {
|
|
|
1886
1904
|
const grantedPairs = /* @__PURE__ */ new Set();
|
|
1887
1905
|
const grantedFourPartIndex = /* @__PURE__ */ new Map();
|
|
1888
1906
|
for (const [resource, actions] of Object.entries(signedCaps)) {
|
|
1889
|
-
const { space, path } = (0,
|
|
1907
|
+
const { space, path } = (0, import_sdk_core5.parseCanonicalRecapResource)(resource);
|
|
1890
1908
|
for (const action of Object.keys(actions)) {
|
|
1891
1909
|
grantedPairs.add(`${resource}\0${action}`);
|
|
1892
1910
|
const slashIdx = action.indexOf("/");
|
|
@@ -2283,7 +2301,7 @@ function rememberInvokeAny(invokeAny, sink, pending) {
|
|
|
2283
2301
|
}
|
|
2284
2302
|
|
|
2285
2303
|
// src/delegation.ts
|
|
2286
|
-
var
|
|
2304
|
+
var import_sdk_core6 = require("@tinycloud/sdk-core");
|
|
2287
2305
|
var RuntimeDelegationRejectedError = class extends Error {
|
|
2288
2306
|
constructor(reason, message) {
|
|
2289
2307
|
super(message);
|
|
@@ -2323,7 +2341,7 @@ function normalizedHost(host) {
|
|
|
2323
2341
|
}
|
|
2324
2342
|
function didPrincipalsMatch(left, right) {
|
|
2325
2343
|
try {
|
|
2326
|
-
return (0,
|
|
2344
|
+
return (0, import_sdk_core6.principalDidEquals)(left, right);
|
|
2327
2345
|
} catch {
|
|
2328
2346
|
return left === right;
|
|
2329
2347
|
}
|
|
@@ -2338,7 +2356,7 @@ function compactUcanPayload(authorization) {
|
|
|
2338
2356
|
}
|
|
2339
2357
|
try {
|
|
2340
2358
|
const payload = JSON.parse(
|
|
2341
|
-
new TextDecoder("utf-8", { fatal: true }).decode((0,
|
|
2359
|
+
new TextDecoder("utf-8", { fatal: true }).decode((0, import_sdk_core6.decodeBase64Url)(parts[1]))
|
|
2342
2360
|
);
|
|
2343
2361
|
if (payload === null || typeof payload !== "object" || Array.isArray(payload)) {
|
|
2344
2362
|
throw new Error("payload is not an object");
|
|
@@ -2366,7 +2384,7 @@ function canonicalPermissionEntries(permissions) {
|
|
|
2366
2384
|
...permission,
|
|
2367
2385
|
actions: [...permission.actions].sort()
|
|
2368
2386
|
})).sort(
|
|
2369
|
-
(left, right) => left.service.localeCompare(right.service) || (left.space ?? "").localeCompare(right.space ?? "") || left.path.localeCompare(right.path) || left.actions.join("\0").localeCompare(right.actions.join("\0")) || (0,
|
|
2387
|
+
(left, right) => left.service.localeCompare(right.service) || (left.space ?? "").localeCompare(right.space ?? "") || left.path.localeCompare(right.path) || left.actions.join("\0").localeCompare(right.actions.join("\0")) || (0, import_sdk_core6.canonicalizeRecapCaveats)(left.caveats).localeCompare((0, import_sdk_core6.canonicalizeRecapCaveats)(right.caveats))
|
|
2370
2388
|
);
|
|
2371
2389
|
}
|
|
2372
2390
|
function signedCaveats(value) {
|
|
@@ -2376,13 +2394,13 @@ function signedCaveats(value) {
|
|
|
2376
2394
|
throw new Error("Validated runtime delegation has malformed signed ReCap caveats.");
|
|
2377
2395
|
}
|
|
2378
2396
|
const cloned = JSON.parse(JSON.stringify(value));
|
|
2379
|
-
return (0,
|
|
2397
|
+
return (0, import_sdk_core6.canonicalizeRecapCaveats)(cloned) === (0, import_sdk_core6.canonicalizeRecapCaveats)(void 0) ? void 0 : cloned;
|
|
2380
2398
|
}
|
|
2381
2399
|
function groupedSignedEntries(service, space, path, abilities) {
|
|
2382
2400
|
const groups = /* @__PURE__ */ new Map();
|
|
2383
2401
|
for (const [action, rawCaveats] of Object.entries(abilities)) {
|
|
2384
2402
|
const caveats = signedCaveats(rawCaveats);
|
|
2385
|
-
const identity = (0,
|
|
2403
|
+
const identity = (0, import_sdk_core6.canonicalizeRecapCaveats)(caveats);
|
|
2386
2404
|
const group = groups.get(identity) ?? { actions: [], caveats };
|
|
2387
2405
|
group.actions.push(action);
|
|
2388
2406
|
groups.set(identity, group);
|
|
@@ -2534,7 +2552,7 @@ function signedAuthorityFromSessionGrant(node, delegation, authorization, cid) {
|
|
|
2534
2552
|
reject("authority_invalid", "Runtime delegation has signed authority outside its space.");
|
|
2535
2553
|
}
|
|
2536
2554
|
const caveats = signedCaveats(entry.caveats ?? []);
|
|
2537
|
-
const key = JSON.stringify([service, raw ? "" : entry.space, entry.path, (0,
|
|
2555
|
+
const key = JSON.stringify([service, raw ? "" : entry.space, entry.path, (0, import_sdk_core6.canonicalizeRecapCaveats)(caveats)]);
|
|
2538
2556
|
const group = groups.get(key) ?? {
|
|
2539
2557
|
service,
|
|
2540
2558
|
...raw ? {} : { space: entry.space },
|
|
@@ -2558,7 +2576,7 @@ function signedAuthorityFromSessionGrant(node, delegation, authorization, cid) {
|
|
|
2558
2576
|
function canonicalResourcesFromPortableDelegation(delegation) {
|
|
2559
2577
|
if (delegation.resources !== void 0 && delegation.resources.length > 0) {
|
|
2560
2578
|
return delegation.resources.map((resource) => ({ ...resource, actions: [...resource.actions].sort() })).sort(
|
|
2561
|
-
(left, right) => left.service.localeCompare(right.service) || left.space.localeCompare(right.space) || left.path.localeCompare(right.path) || left.actions.join("\0").localeCompare(right.actions.join("\0")) || (0,
|
|
2579
|
+
(left, right) => left.service.localeCompare(right.service) || left.space.localeCompare(right.space) || left.path.localeCompare(right.path) || left.actions.join("\0").localeCompare(right.actions.join("\0")) || (0, import_sdk_core6.canonicalizeRecapCaveats)(left.caveats).localeCompare((0, import_sdk_core6.canonicalizeRecapCaveats)(right.caveats))
|
|
2562
2580
|
);
|
|
2563
2581
|
}
|
|
2564
2582
|
const byService = /* @__PURE__ */ new Map();
|
|
@@ -2582,7 +2600,7 @@ function canonicalResourcesFromPortableDelegation(delegation) {
|
|
|
2582
2600
|
function resourcesMatch(actual, expected) {
|
|
2583
2601
|
const comparable = (resource) => ({
|
|
2584
2602
|
...resource,
|
|
2585
|
-
caveats: (0,
|
|
2603
|
+
caveats: (0, import_sdk_core6.canonicalizeRecapCaveats)(resource.caveats)
|
|
2586
2604
|
});
|
|
2587
2605
|
return JSON.stringify(actual.map(comparable)) === JSON.stringify(expected.map(comparable));
|
|
2588
2606
|
}
|
|
@@ -2674,7 +2692,7 @@ async function activateValidatedRuntimeDelegation(node, delegation, options) {
|
|
|
2674
2692
|
...compact ? {} : { siweProof: delegation.siweProof }
|
|
2675
2693
|
};
|
|
2676
2694
|
try {
|
|
2677
|
-
if (node.isSessionOnly === true && typeof node.did === "string" && (0,
|
|
2695
|
+
if (node.isSessionOnly === true && typeof node.did === "string" && (0, import_sdk_core6.principalDidEquals)(node.did, node.sessionDid) && typeof node.useDelegation === "function") {
|
|
2678
2696
|
await node.useDelegation(installedCandidate);
|
|
2679
2697
|
} else {
|
|
2680
2698
|
await node.useRuntimeDelegation(installedCandidate);
|
|
@@ -2762,15 +2780,15 @@ function deserializeDelegation(data) {
|
|
|
2762
2780
|
|
|
2763
2781
|
// src/TinyCloudNode.ts
|
|
2764
2782
|
var import_siwe2 = require("siwe");
|
|
2765
|
-
var
|
|
2783
|
+
var import_sdk_core11 = require("@tinycloud/sdk-core");
|
|
2766
2784
|
var import_sdk_services3 = require("@tinycloud/sdk-services");
|
|
2767
2785
|
var import_requestLog2 = require("@tinycloud/sdk-services/telemetry/requestLog");
|
|
2768
2786
|
|
|
2769
2787
|
// src/account/AccountService.ts
|
|
2770
|
-
var
|
|
2788
|
+
var import_sdk_core7 = require("@tinycloud/sdk-core");
|
|
2771
2789
|
|
|
2772
2790
|
// src/DelegatedAccess.ts
|
|
2773
|
-
var
|
|
2791
|
+
var import_sdk_core8 = require("@tinycloud/sdk-core");
|
|
2774
2792
|
var DelegatedAccess = class {
|
|
2775
2793
|
/**
|
|
2776
2794
|
* @param lifetime - Optional owner of this access: its `fetch` is used for
|
|
@@ -2792,16 +2810,16 @@ var DelegatedAccess = class {
|
|
|
2792
2810
|
});
|
|
2793
2811
|
this._serviceContext = lifetime ? lifetime.track(context) : context;
|
|
2794
2812
|
const prefix = this._delegation.path.replace(/\/$/, "");
|
|
2795
|
-
this._kv = new
|
|
2813
|
+
this._kv = new import_sdk_core8.KVService({ prefix });
|
|
2796
2814
|
this._kv.initialize(this._serviceContext);
|
|
2797
2815
|
this._serviceContext.registerService("kv", this._kv);
|
|
2798
|
-
this._sql = new
|
|
2816
|
+
this._sql = new import_sdk_core8.SQLService({});
|
|
2799
2817
|
this._sql.initialize(this._serviceContext);
|
|
2800
2818
|
this._serviceContext.registerService("sql", this._sql);
|
|
2801
|
-
this._duckdb = new
|
|
2819
|
+
this._duckdb = new import_sdk_core8.DuckDbService({});
|
|
2802
2820
|
this._duckdb.initialize(this._serviceContext);
|
|
2803
2821
|
this._serviceContext.registerService("duckdb", this._duckdb);
|
|
2804
|
-
this._hooks = new
|
|
2822
|
+
this._hooks = new import_sdk_core8.HooksService({});
|
|
2805
2823
|
this._hooks.initialize(this._serviceContext);
|
|
2806
2824
|
this._serviceContext.registerService("hooks", this._hooks);
|
|
2807
2825
|
const serviceSession = {
|
|
@@ -2951,7 +2969,7 @@ function createWasmKeyProvider(sessionManager) {
|
|
|
2951
2969
|
}
|
|
2952
2970
|
|
|
2953
2971
|
// src/delegateToHelpers.ts
|
|
2954
|
-
var
|
|
2972
|
+
var import_sdk_core9 = require("@tinycloud/sdk-core");
|
|
2955
2973
|
function legacyParamsToPermissionEntries(actions, path, spaceIdOverride) {
|
|
2956
2974
|
const byService = /* @__PURE__ */ new Map();
|
|
2957
2975
|
for (const a of actions) {
|
|
@@ -2982,7 +3000,7 @@ function legacyParamsToPermissionEntries(actions, path, spaceIdOverride) {
|
|
|
2982
3000
|
}
|
|
2983
3001
|
return entries;
|
|
2984
3002
|
}
|
|
2985
|
-
var DEFAULT_DELEGATION_EXPIRY_MS =
|
|
3003
|
+
var DEFAULT_DELEGATION_EXPIRY_MS = import_sdk_core9.EXPIRY.SESSION_MS;
|
|
2986
3004
|
function resolveExpiryMs(expiry) {
|
|
2987
3005
|
if (expiry === void 0) {
|
|
2988
3006
|
return DEFAULT_DELEGATION_EXPIRY_MS;
|
|
@@ -2995,10 +3013,10 @@ function resolveExpiryMs(expiry) {
|
|
|
2995
3013
|
}
|
|
2996
3014
|
return expiry;
|
|
2997
3015
|
}
|
|
2998
|
-
return (0,
|
|
3016
|
+
return (0, import_sdk_core9.parseExpiry)(expiry);
|
|
2999
3017
|
}
|
|
3000
3018
|
function extractSiweExpiration(siwe) {
|
|
3001
|
-
const parsed = new
|
|
3019
|
+
const parsed = new import_sdk_core9.SiweMessage(siwe);
|
|
3002
3020
|
if (parsed.expirationTime === void 0 || parsed.expirationTime === null) {
|
|
3003
3021
|
return void 0;
|
|
3004
3022
|
}
|
|
@@ -3012,7 +3030,7 @@ function extractSiweExpiration(siwe) {
|
|
|
3012
3030
|
}
|
|
3013
3031
|
|
|
3014
3032
|
// src/NodeSecretsService.ts
|
|
3015
|
-
var
|
|
3033
|
+
var import_sdk_core10 = require("@tinycloud/sdk-core");
|
|
3016
3034
|
var SECRETS_SPACE = "secrets";
|
|
3017
3035
|
function ok() {
|
|
3018
3036
|
return { ok: true, data: void 0 };
|
|
@@ -3045,7 +3063,7 @@ function secretActionName(action) {
|
|
|
3045
3063
|
}
|
|
3046
3064
|
function secretPermissionEntries(name, options, action, space, encryptionNetworkId) {
|
|
3047
3065
|
const entries = [];
|
|
3048
|
-
const path = action === "list" ? (0,
|
|
3066
|
+
const path = action === "list" ? (0, import_sdk_core10.resolveSecretListPrefix)(options) : (0, import_sdk_core10.resolveSecretPath)(name, options).permissionPaths.vault;
|
|
3049
3067
|
entries.push({
|
|
3050
3068
|
service: "tinycloud.kv",
|
|
3051
3069
|
space,
|
|
@@ -3142,7 +3160,7 @@ var NodeSecretsService = class {
|
|
|
3142
3160
|
);
|
|
3143
3161
|
} catch (error) {
|
|
3144
3162
|
return secretsError(
|
|
3145
|
-
|
|
3163
|
+
import_sdk_core10.ErrorCodes.INVALID_INPUT,
|
|
3146
3164
|
error instanceof Error ? error.message : String(error),
|
|
3147
3165
|
error instanceof Error ? error : void 0
|
|
3148
3166
|
);
|
|
@@ -3161,7 +3179,7 @@ var NodeSecretsService = class {
|
|
|
3161
3179
|
}
|
|
3162
3180
|
if (!this.config.canEscalate()) {
|
|
3163
3181
|
return secretsError(
|
|
3164
|
-
|
|
3182
|
+
import_sdk_core10.ErrorCodes.PERMISSION_DENIED,
|
|
3165
3183
|
`Cannot autosign ${displayActionUrn(action)} for ${target}; TinyCloudNode needs wallet mode with a signer or privateKey.`
|
|
3166
3184
|
);
|
|
3167
3185
|
}
|
|
@@ -3174,7 +3192,7 @@ var NodeSecretsService = class {
|
|
|
3174
3192
|
}
|
|
3175
3193
|
escalationError(action, target, error) {
|
|
3176
3194
|
return secretsError(
|
|
3177
|
-
|
|
3195
|
+
import_sdk_core10.ErrorCodes.PERMISSION_DENIED,
|
|
3178
3196
|
error instanceof Error ? error.message : `Autosign escalation for ${displayActionUrn(action)} on ${target} failed.`,
|
|
3179
3197
|
error instanceof Error ? error : void 0
|
|
3180
3198
|
);
|
|
@@ -3194,10 +3212,10 @@ var NodeSecretsService = class {
|
|
|
3194
3212
|
return false;
|
|
3195
3213
|
}
|
|
3196
3214
|
const manifests = Array.isArray(manifest) ? manifest : [manifest];
|
|
3197
|
-
const requestedEntries = (0,
|
|
3215
|
+
const requestedEntries = (0, import_sdk_core10.expandPermissionEntries)(permissionEntries);
|
|
3198
3216
|
return requestedEntries.every(
|
|
3199
3217
|
(entry) => manifests.some((candidate) => {
|
|
3200
|
-
const resolved = (0,
|
|
3218
|
+
const resolved = (0, import_sdk_core10.resolveManifest)(candidate);
|
|
3201
3219
|
return resolved.resources.some(
|
|
3202
3220
|
(resource) => resource.service === entry.service && spaceMatches(
|
|
3203
3221
|
resource.space,
|
|
@@ -3213,8 +3231,8 @@ var NodeSecretsService = class {
|
|
|
3213
3231
|
// src/TinyCloudNode.ts
|
|
3214
3232
|
var DEFAULT_HOST = "https://node.tinycloud.xyz";
|
|
3215
3233
|
var DEFAULT_ENCRYPTION_NETWORK_NAME = "default";
|
|
3216
|
-
var NETWORK_CREATE_ACTION2 =
|
|
3217
|
-
var DECRYPT_ACTION2 =
|
|
3234
|
+
var NETWORK_CREATE_ACTION2 = import_sdk_core11.ENCRYPTION.NETWORK_CREATE;
|
|
3235
|
+
var DECRYPT_ACTION2 = import_sdk_core11.ENCRYPTION.DECRYPT;
|
|
3218
3236
|
var BOOTSTRAP_COMPLETION_MARKER_KEY = "system/bootstrap/complete";
|
|
3219
3237
|
var BOOTSTRAP_COMPLETION_MARKER_VERSION = 1;
|
|
3220
3238
|
var ACCEPTED_MARKER_VERSIONS = [BOOTSTRAP_COMPLETION_MARKER_VERSION];
|
|
@@ -3223,24 +3241,24 @@ function isSecretPayload(value) {
|
|
|
3223
3241
|
return typeof value === "object" && value !== null && "value" in value && typeof value.value === "string" && "createdAt" in value && typeof value.createdAt === "string" && "updatedAt" in value && typeof value.updatedAt === "string";
|
|
3224
3242
|
}
|
|
3225
3243
|
var ROOT_DELEGATION_ACTIONS = [
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3244
|
+
import_sdk_core11.KV.PUT,
|
|
3245
|
+
import_sdk_core11.KV.GET,
|
|
3246
|
+
import_sdk_core11.KV.DEL,
|
|
3247
|
+
import_sdk_core11.KV.LIST,
|
|
3248
|
+
import_sdk_core11.KV.METADATA,
|
|
3249
|
+
import_sdk_core11.SQL.READ,
|
|
3250
|
+
import_sdk_core11.SQL.WRITE,
|
|
3251
|
+
import_sdk_core11.SQL.ADMIN,
|
|
3252
|
+
import_sdk_core11.SQL.ALL,
|
|
3253
|
+
import_sdk_core11.DUCKDB.READ,
|
|
3254
|
+
import_sdk_core11.DUCKDB.WRITE,
|
|
3255
|
+
import_sdk_core11.DUCKDB.ADMIN,
|
|
3256
|
+
import_sdk_core11.DUCKDB.DESCRIBE,
|
|
3257
|
+
import_sdk_core11.DUCKDB.EXPORT,
|
|
3258
|
+
import_sdk_core11.DUCKDB.IMPORT,
|
|
3259
|
+
import_sdk_core11.DUCKDB.ALL
|
|
3242
3260
|
];
|
|
3243
|
-
var DEFAULT_SESSION_EXPIRATION_MS =
|
|
3261
|
+
var DEFAULT_SESSION_EXPIRATION_MS = import_sdk_core11.EXPIRY.SESSION_MS;
|
|
3244
3262
|
function unifiedRootAttenuation(capabilities) {
|
|
3245
3263
|
const attenuation = {};
|
|
3246
3264
|
for (const capability of capabilities) {
|
|
@@ -3291,7 +3309,7 @@ function spaceOwnerKey(spaceId) {
|
|
|
3291
3309
|
}
|
|
3292
3310
|
function didPrincipalMatches2(actual, expected) {
|
|
3293
3311
|
try {
|
|
3294
|
-
return (0,
|
|
3312
|
+
return (0, import_sdk_core11.principalDidEquals)(actual, expected);
|
|
3295
3313
|
} catch {
|
|
3296
3314
|
return actual === expected;
|
|
3297
3315
|
}
|
|
@@ -3512,6 +3530,7 @@ function ownerDelegationPermissions(params) {
|
|
|
3512
3530
|
if (!Array.isArray(params.permissions)) {
|
|
3513
3531
|
throw new Error("Owner delegation permissions are invalid");
|
|
3514
3532
|
}
|
|
3533
|
+
refuseCaveated(params.permissions);
|
|
3515
3534
|
permissions.push(...params.permissions.map((permission) => ({
|
|
3516
3535
|
service: permission.service,
|
|
3517
3536
|
path: permission.path,
|
|
@@ -3528,7 +3547,7 @@ function ownerDelegationPermissions(params) {
|
|
|
3528
3547
|
}
|
|
3529
3548
|
const slash = action.indexOf("/");
|
|
3530
3549
|
const service = slash === -1 ? "" : action.slice(0, slash);
|
|
3531
|
-
if (
|
|
3550
|
+
if (import_sdk_core11.SERVICE_LONG_TO_SHORT[service] === void 0) {
|
|
3532
3551
|
throw new Error("Owner delegation capabilities are unsupported");
|
|
3533
3552
|
}
|
|
3534
3553
|
const actions = byService.get(service) ?? [];
|
|
@@ -3544,7 +3563,7 @@ function ownerDelegationPermissions(params) {
|
|
|
3544
3563
|
}
|
|
3545
3564
|
const resources = /* @__PURE__ */ new Set();
|
|
3546
3565
|
for (const permission of permissions) {
|
|
3547
|
-
if (typeof permission.service !== "string" ||
|
|
3566
|
+
if (typeof permission.service !== "string" || import_sdk_core11.SERVICE_LONG_TO_SHORT[permission.service] === void 0 || typeof permission.path !== "string" || permission.path.length === 0 || permission.path.trim() !== permission.path || /[\u0000-\u001f\u007f\\*]/.test(permission.path) || !Array.isArray(permission.actions) || permission.actions.length === 0 || permission.actions.length > 32) {
|
|
3548
3567
|
throw new Error("Owner delegation requires bounded capabilities");
|
|
3549
3568
|
}
|
|
3550
3569
|
const resourceKey = `${permission.service}\0${permission.path}`;
|
|
@@ -3559,9 +3578,9 @@ function ownerDelegationPermissions(params) {
|
|
|
3559
3578
|
}
|
|
3560
3579
|
actions.add(action);
|
|
3561
3580
|
}
|
|
3562
|
-
if (permission.service ===
|
|
3581
|
+
if (permission.service === import_sdk_core11.ENCRYPTION_PERMISSION_SERVICE) {
|
|
3563
3582
|
try {
|
|
3564
|
-
(0,
|
|
3583
|
+
(0, import_sdk_core11.parseNetworkId)(permission.path);
|
|
3565
3584
|
} catch {
|
|
3566
3585
|
throw new Error("Owner delegation encryption permission requires a canonical network URN");
|
|
3567
3586
|
}
|
|
@@ -3573,11 +3592,11 @@ function ownerPermissionsToAbilities(permissions) {
|
|
|
3573
3592
|
const abilities = {};
|
|
3574
3593
|
const rawAbilities = {};
|
|
3575
3594
|
for (const permission of permissions) {
|
|
3576
|
-
if (permission.service ===
|
|
3595
|
+
if (permission.service === import_sdk_core11.ENCRYPTION_PERMISSION_SERVICE) {
|
|
3577
3596
|
rawAbilities[permission.path] = [...permission.actions];
|
|
3578
3597
|
continue;
|
|
3579
3598
|
}
|
|
3580
|
-
const shortService =
|
|
3599
|
+
const shortService = import_sdk_core11.SERVICE_LONG_TO_SHORT[permission.service];
|
|
3581
3600
|
abilities[shortService] ?? (abilities[shortService] = {});
|
|
3582
3601
|
abilities[shortService][permission.path] = [...permission.actions];
|
|
3583
3602
|
}
|
|
@@ -3756,7 +3775,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3756
3775
|
}
|
|
3757
3776
|
const stamp = await establishReplicaSessionStamp(
|
|
3758
3777
|
replication.storage,
|
|
3759
|
-
(0,
|
|
3778
|
+
(0, import_sdk_core11.pkhDid)(session.address, session.chainId),
|
|
3760
3779
|
anchor
|
|
3761
3780
|
);
|
|
3762
3781
|
if (epoch !== this.sessionEpoch || attempt !== this.latestSessionAttempt) return void 0;
|
|
@@ -3835,7 +3854,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3835
3854
|
* and remembers whose storage is full so sign-in and listing skip their
|
|
3836
3855
|
* best-effort writes. Lives as long as this instance, across sign-ins.
|
|
3837
3856
|
*/
|
|
3838
|
-
this.storageFull = new
|
|
3857
|
+
this.storageFull = new import_sdk_core11.StorageFullMonitor((spaceId) => spaceOwnerKey(spaceId) ?? spaceId);
|
|
3839
3858
|
this.invokeWithRuntimePermissions = (session, service, path, action, facts) => {
|
|
3840
3859
|
const operation = {
|
|
3841
3860
|
spaceId: session.spaceId,
|
|
@@ -3886,7 +3905,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3886
3905
|
if (!granted?.caveats?.length) {
|
|
3887
3906
|
return entry;
|
|
3888
3907
|
}
|
|
3889
|
-
if (entry.caveats !== void 0 && !(0,
|
|
3908
|
+
if (entry.caveats !== void 0 && !(0, import_sdk_core11.recapCaveatsEqual)(entry.caveats, granted.caveats)) {
|
|
3890
3909
|
throw new Error("Invocation caveats do not match signed ReCap authority.");
|
|
3891
3910
|
}
|
|
3892
3911
|
return { ...entry, caveats: cloneRecapCaveats(granted.caveats) };
|
|
@@ -3899,7 +3918,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3899
3918
|
...config,
|
|
3900
3919
|
host: config.host ?? DEFAULT_HOST,
|
|
3901
3920
|
// One store for every authorization this client creates.
|
|
3902
|
-
registrySequenceStore: config.registrySequenceStore ?? (0,
|
|
3921
|
+
registrySequenceStore: config.registrySequenceStore ?? (0, import_sdk_core11.createInMemoryRegistrySequenceStore)()
|
|
3903
3922
|
};
|
|
3904
3923
|
if (this.config.replication?.enabled) {
|
|
3905
3924
|
const runtime = getNodeReplicationLoaders().runtime().then(({ ReplicationRuntime }) => {
|
|
@@ -3968,11 +3987,11 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3968
3987
|
this.sessionKeyJwk = sessionKey.jwk;
|
|
3969
3988
|
this._requestLog = config.requestLog === true ? new import_requestLog2.RequestLog() : void 0;
|
|
3970
3989
|
this._serviceGraph = this.createServiceGraphLifetime();
|
|
3971
|
-
this._capabilityRegistry = new
|
|
3990
|
+
this._capabilityRegistry = new import_sdk_core11.CapabilityKeyRegistry();
|
|
3972
3991
|
this._keyProvider = new WasmKeyProvider({
|
|
3973
3992
|
sessionManager: this.sessionManager
|
|
3974
3993
|
});
|
|
3975
|
-
this.notificationHandler = config.notificationHandler ?? new
|
|
3994
|
+
this.notificationHandler = config.notificationHandler ?? new import_sdk_core11.SilentNotificationHandler();
|
|
3976
3995
|
this._sharingService = this.createReceiveOnlySharing();
|
|
3977
3996
|
if (config.signer) {
|
|
3978
3997
|
this.signer = config.signer;
|
|
@@ -4046,13 +4065,13 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4046
4065
|
async readStorageStatus(options) {
|
|
4047
4066
|
const session = this._serviceContext?.session;
|
|
4048
4067
|
if (!this._serviceContext || !session) {
|
|
4049
|
-
return (0,
|
|
4068
|
+
return (0, import_sdk_core11.err)((0, import_sdk_core11.serviceError)(import_sdk_core11.ErrorCodes.AUTH_REQUIRED, "Not signed in. Call signIn() first.", "storage"));
|
|
4050
4069
|
}
|
|
4051
4070
|
const spaceId = options?.space === void 0 ? session.spaceId : options.space.startsWith("tinycloud:") ? options.space : this.ownedSpaceId(options.space);
|
|
4052
4071
|
const action = "tinycloud.space/info";
|
|
4053
4072
|
if (!this.findGrantForOperation({ spaceId, service: "space", path: "", action })) {
|
|
4054
|
-
return (0,
|
|
4055
|
-
|
|
4073
|
+
return (0, import_sdk_core11.err)((0, import_sdk_core11.serviceError)(
|
|
4074
|
+
import_sdk_core11.ErrorCodes.PERMISSION_DENIED,
|
|
4056
4075
|
`Reading storage status needs ${action} on ${spaceId}, which this session was not granted.`,
|
|
4057
4076
|
"storage",
|
|
4058
4077
|
{ meta: { requiredAction: action, resource: spaceId } }
|
|
@@ -4068,8 +4087,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4068
4087
|
const text = await response.text();
|
|
4069
4088
|
if (!response.ok) {
|
|
4070
4089
|
const unauthorized = response.status === 401 || response.status === 403;
|
|
4071
|
-
return (0,
|
|
4072
|
-
unauthorized ?
|
|
4090
|
+
return (0, import_sdk_core11.err)((0, import_sdk_core11.serviceError)(
|
|
4091
|
+
unauthorized ? import_sdk_core11.ErrorCodes.AUTH_UNAUTHORIZED : import_sdk_core11.ErrorCodes.NETWORK_ERROR,
|
|
4073
4092
|
`Failed to read storage status: ${response.status} - ${text.slice(0, 300)}`,
|
|
4074
4093
|
"storage",
|
|
4075
4094
|
{ meta: { status: response.status, ...unauthorized ? { requiredAction: action, resource: spaceId } : {} } }
|
|
@@ -4081,10 +4100,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4081
4100
|
} catch {
|
|
4082
4101
|
body = void 0;
|
|
4083
4102
|
}
|
|
4084
|
-
const status = (0,
|
|
4103
|
+
const status = (0, import_sdk_core11.parseStorageStatus)(body);
|
|
4085
4104
|
if (!status) {
|
|
4086
|
-
return (0,
|
|
4087
|
-
|
|
4105
|
+
return (0, import_sdk_core11.err)((0, import_sdk_core11.serviceError)(
|
|
4106
|
+
import_sdk_core11.ErrorCodes.STORAGE_STATUS_UNAVAILABLE,
|
|
4088
4107
|
"This TinyCloud node does not report storage usage yet.",
|
|
4089
4108
|
"storage",
|
|
4090
4109
|
{ meta: { status: response.status } }
|
|
@@ -4094,10 +4113,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4094
4113
|
this.storageFull.clearFor(spaceId);
|
|
4095
4114
|
if (spaceOwnerKey(spaceId) === this.currentStorageOwner()) this.storageFull.clearFor(void 0);
|
|
4096
4115
|
}
|
|
4097
|
-
return (0,
|
|
4116
|
+
return (0, import_sdk_core11.ok)(status);
|
|
4098
4117
|
} catch (error) {
|
|
4099
|
-
return (0,
|
|
4100
|
-
|
|
4118
|
+
return (0, import_sdk_core11.err)((0, import_sdk_core11.serviceError)(
|
|
4119
|
+
import_sdk_core11.ErrorCodes.NETWORK_ERROR,
|
|
4101
4120
|
`Failed to read storage status: ${error instanceof Error ? error.message : String(error)}`,
|
|
4102
4121
|
"storage",
|
|
4103
4122
|
{ cause: error instanceof Error ? error : void 0 }
|
|
@@ -4122,7 +4141,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4122
4141
|
*/
|
|
4123
4142
|
createReceiveOnlySharing() {
|
|
4124
4143
|
const receiveOnlyGraph = this._serviceGraph;
|
|
4125
|
-
return new
|
|
4144
|
+
return new import_sdk_core11.SharingService({
|
|
4126
4145
|
hosts: [this.config.host],
|
|
4127
4146
|
// session: undefined - not needed for receive()
|
|
4128
4147
|
invoke: receiveOnlyGraph.invoke,
|
|
@@ -4137,7 +4156,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4137
4156
|
},
|
|
4138
4157
|
createKVService: (config) => {
|
|
4139
4158
|
const prefix = config.pathPrefix?.replace(/\/$/, "");
|
|
4140
|
-
const kvService = new
|
|
4159
|
+
const kvService = new import_sdk_core11.KVService({ prefix });
|
|
4141
4160
|
const kvContext = receiveOnlyGraph.track(createServiceContext({
|
|
4142
4161
|
requestSink: receiveOnlyGraph.requestSink,
|
|
4143
4162
|
invoke: config.invoke,
|
|
@@ -4183,7 +4202,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4183
4202
|
nonce: config.nonce,
|
|
4184
4203
|
siweConfig: config.siweConfig,
|
|
4185
4204
|
manifest: useBootstrapSignInRequest ? void 0 : config.manifest,
|
|
4186
|
-
capabilityRequest: useBootstrapSignInRequest ? config.includeAccountRegistryPermissions === false ?
|
|
4205
|
+
capabilityRequest: useBootstrapSignInRequest ? config.includeAccountRegistryPermissions === false ? import_sdk_core11.BOOTSTRAP_DEFAULT_ONLY_SESSION_REQUEST : import_sdk_core11.BOOTSTRAP_SESSION_REQUESTS.default : config.capabilityRequest,
|
|
4187
4206
|
includeAccountRegistryPermissions: useBootstrapSignInRequest ? false : config.includeAccountRegistryPermissions,
|
|
4188
4207
|
// Sign-in needs only the entry inputs (prefixes + secrets opt-in);
|
|
4189
4208
|
// storage and scheduling never leave TinyCloudNode.
|
|
@@ -4193,7 +4212,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4193
4212
|
allowSecrets: config.replication.allowSecrets === true
|
|
4194
4213
|
} : void 0
|
|
4195
4214
|
});
|
|
4196
|
-
this.tc = new
|
|
4215
|
+
this.tc = new import_sdk_core11.TinyCloud(this.auth, {
|
|
4197
4216
|
invokeAny: this.invokeAnyWithRuntimePermissions,
|
|
4198
4217
|
telemetry: config.telemetry,
|
|
4199
4218
|
retryPolicy: config.retryPolicy
|
|
@@ -4283,7 +4302,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4283
4302
|
/** Publish the active owner Node as a session-signed registry record. */
|
|
4284
4303
|
async publishActiveNodeLocation(registryUrl, fetchFn = globalThis.fetch.bind(globalThis)) {
|
|
4285
4304
|
const node = await this.activeNodeIdentity();
|
|
4286
|
-
return (0,
|
|
4305
|
+
return (0, import_sdk_core11.publishLocationRecord)({
|
|
4287
4306
|
registryUrl,
|
|
4288
4307
|
subject: this.credentialHolderDid,
|
|
4289
4308
|
nodeOrigin: node.origin,
|
|
@@ -4300,7 +4319,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4300
4319
|
*/
|
|
4301
4320
|
get did() {
|
|
4302
4321
|
if (this._address) {
|
|
4303
|
-
return (0,
|
|
4322
|
+
return (0, import_sdk_core11.pkhDid)(this._address, this._chainId);
|
|
4304
4323
|
}
|
|
4305
4324
|
return this.sessionManager.getDID(this.sessionKeyId);
|
|
4306
4325
|
}
|
|
@@ -4337,7 +4356,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4337
4356
|
/** Normalize signed capabilities without collapsing nested encryption into raw authority. */
|
|
4338
4357
|
projectSignedRecapCapabilities(siwe) {
|
|
4339
4358
|
const projected = this.parseRecapWithCaveats(siwe).map((entry) => {
|
|
4340
|
-
const normalized = (0,
|
|
4359
|
+
const normalized = (0, import_sdk_core11.parseRecapCapabilities)(() => [entry], siwe)[0];
|
|
4341
4360
|
if (normalized.service !== "tinycloud.encryption") return normalized;
|
|
4342
4361
|
if (!this.isEncryptionNetworkOperation("encryption", entry.path, entry.space)) {
|
|
4343
4362
|
return { ...normalized, space: entry.space };
|
|
@@ -4381,14 +4400,14 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4381
4400
|
if (!this._address) {
|
|
4382
4401
|
return void 0;
|
|
4383
4402
|
}
|
|
4384
|
-
return this.wasmBindings.makeSpaceId(this._address, this._chainId,
|
|
4403
|
+
return this.wasmBindings.makeSpaceId(this._address, this._chainId, import_sdk_core11.ACCOUNT_REGISTRY_SPACE);
|
|
4385
4404
|
}
|
|
4386
4405
|
/**
|
|
4387
4406
|
* Account-level application and delegation helpers.
|
|
4388
4407
|
*/
|
|
4389
4408
|
get account() {
|
|
4390
4409
|
if (!this._account) {
|
|
4391
|
-
this._account = new
|
|
4410
|
+
this._account = new import_sdk_core7.AccountService({
|
|
4392
4411
|
getDid: () => this.did,
|
|
4393
4412
|
getHost: () => this.hosts[0] ?? this.config.host,
|
|
4394
4413
|
getPrimarySpaceId: () => this.spaceId,
|
|
@@ -4446,7 +4465,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4446
4465
|
async endSession() {
|
|
4447
4466
|
const leavingAddress = this.address ?? this._restoredTcSession?.address;
|
|
4448
4467
|
const leavingChainId = this._chainId;
|
|
4449
|
-
const leavingPrincipal = this.replicaSessionPrincipal ?? (leavingAddress ? (0,
|
|
4468
|
+
const leavingPrincipal = this.replicaSessionPrincipal ?? (leavingAddress ? (0, import_sdk_core11.pkhDid)(leavingAddress, leavingChainId) : void 0);
|
|
4450
4469
|
const leavingAuth = this.auth;
|
|
4451
4470
|
const leavingContext = this._serviceContext;
|
|
4452
4471
|
let denied;
|
|
@@ -4563,12 +4582,12 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4563
4582
|
this.replicaRestoreGate = void 0;
|
|
4564
4583
|
this._serviceGraph = this.createServiceGraphLifetime();
|
|
4565
4584
|
this.auth = oldAuth;
|
|
4566
|
-
this.tc = this.auth ? new
|
|
4585
|
+
this.tc = this.auth ? new import_sdk_core11.TinyCloud(this.auth, {
|
|
4567
4586
|
invokeAny: this.invokeAnyWithRuntimePermissions,
|
|
4568
4587
|
telemetry: this.config.telemetry,
|
|
4569
4588
|
retryPolicy: this.config.retryPolicy
|
|
4570
4589
|
}) : null;
|
|
4571
|
-
this._capabilityRegistry = new
|
|
4590
|
+
this._capabilityRegistry = new import_sdk_core11.CapabilityKeyRegistry();
|
|
4572
4591
|
this._keyProvider = new WasmKeyProvider({ sessionManager: this.sessionManager });
|
|
4573
4592
|
this._sharingService = this.createReceiveOnlySharing();
|
|
4574
4593
|
}
|
|
@@ -4605,6 +4624,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4605
4624
|
await this.signInWith(() => this.auth.signInWithOpenKey(authorizeFn, options));
|
|
4606
4625
|
}
|
|
4607
4626
|
async signInWith(performSignIn) {
|
|
4627
|
+
refuseCaveated(this.auth?.capabilityRequest?.manifests);
|
|
4608
4628
|
const epoch = this.sessionEpoch;
|
|
4609
4629
|
const attempt = ++this.latestSessionAttempt;
|
|
4610
4630
|
await this.signOutInFlight;
|
|
@@ -4624,11 +4644,11 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4624
4644
|
this.pendingAccountRegistrySync?.controller.abort();
|
|
4625
4645
|
await this.accountRegistryTail;
|
|
4626
4646
|
await this.wasmBindings.ensureInitialized?.();
|
|
4627
|
-
const address = (0,
|
|
4647
|
+
const address = (0, import_sdk_core11.canonicalizeAddress)(await this.signer.getAddress());
|
|
4628
4648
|
const chainId = await this.signer.getChainId();
|
|
4629
4649
|
this.assertSessionEpoch(epoch, "Sign-in");
|
|
4630
|
-
const nextPrincipal = (0,
|
|
4631
|
-
const priorPrincipal = this.replicaSessionPrincipal ?? (this.address ? (0,
|
|
4650
|
+
const nextPrincipal = (0, import_sdk_core11.pkhDid)(address, chainId);
|
|
4651
|
+
const priorPrincipal = this.replicaSessionPrincipal ?? (this.address ? (0, import_sdk_core11.pkhDid)(this.address, this._chainId) : void 0);
|
|
4632
4652
|
if (this.config.replication?.enabled && priorPrincipal && priorPrincipal !== nextPrincipal) {
|
|
4633
4653
|
const denial = await this.denyReplicaGate({ reason: "account_switch", principal: priorPrincipal, next: nextPrincipal });
|
|
4634
4654
|
this.replicaRestoreGate = denial?.status === "unguarded" ? "gate_unavailable" : "stamp_stale";
|
|
@@ -4674,7 +4694,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4674
4694
|
this.hostedOwnedSpaceIds.add(spaceId);
|
|
4675
4695
|
}
|
|
4676
4696
|
this.replicationDelegateSession = void 0;
|
|
4677
|
-
this.replicaSessionPrincipal = (0,
|
|
4697
|
+
this.replicaSessionPrincipal = (0, import_sdk_core11.pkhDid)(address, chainId);
|
|
4678
4698
|
this.replicationScopeError = void 0;
|
|
4679
4699
|
await this.quiesceReplicaRuntime();
|
|
4680
4700
|
this.assertSessionEpoch(epoch, "Sign-in");
|
|
@@ -4698,7 +4718,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4698
4718
|
await this.ensureRequestedEncryptionNetworks();
|
|
4699
4719
|
this.assertSessionEpoch(epoch, "Sign-in");
|
|
4700
4720
|
if (!bootstrapped && this.config.manifest === void 0 && this.config.capabilityRequest === void 0) {
|
|
4701
|
-
await this.ensureOwnedSpaceHostedById(this.ownedSpaceId(
|
|
4721
|
+
await this.ensureOwnedSpaceHostedById(this.ownedSpaceId(import_sdk_core11.SECRETS_SPACE));
|
|
4702
4722
|
}
|
|
4703
4723
|
this.assertSessionEpoch(epoch, "Sign-in");
|
|
4704
4724
|
if (!bootstrapped) {
|
|
@@ -4741,7 +4761,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4741
4761
|
this._bootstrapStatus = { skipped: true, reason: "interactive-signer" };
|
|
4742
4762
|
return false;
|
|
4743
4763
|
}
|
|
4744
|
-
const steps = (0,
|
|
4764
|
+
const steps = (0, import_sdk_core11.bootstrapSteps)(this._address, this._chainId);
|
|
4745
4765
|
try {
|
|
4746
4766
|
const decision = await this.resolveBootstrapDecision(steps);
|
|
4747
4767
|
if (decision.action === "skip") {
|
|
@@ -4784,7 +4804,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4784
4804
|
if (!auth) {
|
|
4785
4805
|
throw new Error("Account bootstrap requires an active wallet session");
|
|
4786
4806
|
}
|
|
4787
|
-
const accountSpaceId = this.ownedSpaceId(
|
|
4807
|
+
const accountSpaceId = this.ownedSpaceId(import_sdk_core11.ACCOUNT_REGISTRY_SPACE);
|
|
4788
4808
|
const skipped = auth.lastActivationSkippedSpaceIds;
|
|
4789
4809
|
if (skipped.includes(accountSpaceId)) return { action: "run", mode: "fresh" };
|
|
4790
4810
|
if (skipped.some((spaceId) => enshrinedSpaceIds.has(spaceId))) {
|
|
@@ -4807,7 +4827,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4807
4827
|
}
|
|
4808
4828
|
return { action: "run", mode: "repair" };
|
|
4809
4829
|
}
|
|
4810
|
-
if (marker.error.code ===
|
|
4830
|
+
if (marker.error.code === import_sdk_core11.ErrorCodes.KV_NOT_FOUND && this.markerReadIsUnhostedSpace(marker.error.meta)) {
|
|
4811
4831
|
return { action: "run", mode: "fresh" };
|
|
4812
4832
|
}
|
|
4813
4833
|
} catch (err2) {
|
|
@@ -4821,7 +4841,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4821
4841
|
return { action: "run", mode: "repair" };
|
|
4822
4842
|
}
|
|
4823
4843
|
async readBootstrapCompletionMarker() {
|
|
4824
|
-
return this.kvForSpace(this.ownedSpaceId(
|
|
4844
|
+
return this.kvForSpace(this.ownedSpaceId(import_sdk_core11.ACCOUNT_REGISTRY_SPACE)).get(
|
|
4825
4845
|
BOOTSTRAP_COMPLETION_MARKER_KEY
|
|
4826
4846
|
);
|
|
4827
4847
|
}
|
|
@@ -4830,7 +4850,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4830
4850
|
throw new Error("Bootstrap completion marker requires an active wallet session");
|
|
4831
4851
|
}
|
|
4832
4852
|
const canonicalStepIds = new Set(
|
|
4833
|
-
(0,
|
|
4853
|
+
(0, import_sdk_core11.bootstrapSteps)(this._address, this._chainId).map((step) => step.id)
|
|
4834
4854
|
);
|
|
4835
4855
|
const providedStepIds = new Set(steps.map((step) => step.id));
|
|
4836
4856
|
if (canonicalStepIds.size !== providedStepIds.size || [...canonicalStepIds].some((stepId) => !providedStepIds.has(stepId))) {
|
|
@@ -4841,7 +4861,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4841
4861
|
stepIds: [...canonicalStepIds],
|
|
4842
4862
|
completedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
4843
4863
|
};
|
|
4844
|
-
const written = await this.kvForSpace(this.ownedSpaceId(
|
|
4864
|
+
const written = await this.kvForSpace(this.ownedSpaceId(import_sdk_core11.ACCOUNT_REGISTRY_SPACE)).put(
|
|
4845
4865
|
BOOTSTRAP_COMPLETION_MARKER_KEY,
|
|
4846
4866
|
marker
|
|
4847
4867
|
);
|
|
@@ -4888,7 +4908,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4888
4908
|
const warnings = [];
|
|
4889
4909
|
const primarySession = auth.tinyCloudSession;
|
|
4890
4910
|
const defaultSpaceId = this.ownedSpaceId("default");
|
|
4891
|
-
const canReusePrimaryBootstrapSession = primarySession?.spaceId === defaultSpaceId && auth.capabilityRequest ===
|
|
4911
|
+
const canReusePrimaryBootstrapSession = primarySession?.spaceId === defaultSpaceId && auth.capabilityRequest === import_sdk_core11.BOOTSTRAP_SESSION_REQUESTS.default;
|
|
4892
4912
|
if (steps.some((step) => step.kind === "host")) {
|
|
4893
4913
|
await this.assertMayCreateSpace();
|
|
4894
4914
|
}
|
|
@@ -4907,7 +4927,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4907
4927
|
try {
|
|
4908
4928
|
session = await auth.createBootstrapSession({
|
|
4909
4929
|
spaceId: step.spaceId,
|
|
4910
|
-
capabilityRequest: step.request ??
|
|
4930
|
+
capabilityRequest: step.request ?? import_sdk_core11.BOOTSTRAP_SESSION_REQUESTS[step.space],
|
|
4911
4931
|
rawAbilities
|
|
4912
4932
|
});
|
|
4913
4933
|
} catch (err2) {
|
|
@@ -4939,7 +4959,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4939
4959
|
if (!session) {
|
|
4940
4960
|
throw new Error(`Missing bootstrap session for ${step.space}`);
|
|
4941
4961
|
}
|
|
4942
|
-
const activated = await (0,
|
|
4962
|
+
const activated = await (0, import_sdk_core11.activateSessionWithHost)(host, session.delegationHeader, graph.signal).catch((error) => {
|
|
4943
4963
|
graph.assertActive();
|
|
4944
4964
|
throw error;
|
|
4945
4965
|
});
|
|
@@ -4954,7 +4974,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4954
4974
|
}
|
|
4955
4975
|
this.registerBootstrapRuntimeGrant(
|
|
4956
4976
|
session,
|
|
4957
|
-
|
|
4977
|
+
import_sdk_core11.BOOTSTRAP_SESSION_REQUESTS[step.space],
|
|
4958
4978
|
rawAbilitiesBySpace.get(step.space)
|
|
4959
4979
|
);
|
|
4960
4980
|
}
|
|
@@ -5004,7 +5024,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5004
5024
|
}
|
|
5005
5025
|
if (step.kind === "seed-applications") {
|
|
5006
5026
|
const registered = await this.account.applications.register(
|
|
5007
|
-
step.manifests.length > 0 ? [...step.manifests] :
|
|
5027
|
+
step.manifests.length > 0 ? [...step.manifests] : import_sdk_core11.TINYCLOUD_SECRETS_BOOTSTRAP_MANIFEST,
|
|
5008
5028
|
// The write is an INSERT OR REPLACE and is safe to repeat during a
|
|
5009
5029
|
// repair, so skip the manifest-hash pre-read.
|
|
5010
5030
|
{ assumeUnregistered: true }
|
|
@@ -5023,7 +5043,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5023
5043
|
migrations: [
|
|
5024
5044
|
{
|
|
5025
5045
|
id: "001_initial",
|
|
5026
|
-
sql: [...
|
|
5046
|
+
sql: [...import_sdk_core11.SECRET_RECORDS_SCHEMA]
|
|
5027
5047
|
}
|
|
5028
5048
|
]
|
|
5029
5049
|
});
|
|
@@ -5198,7 +5218,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5198
5218
|
if (!this.auth || !this.signer) {
|
|
5199
5219
|
throw new Error("Manifest registry write requires wallet mode");
|
|
5200
5220
|
}
|
|
5201
|
-
const accountSpaceId = this.ownedSpaceId(
|
|
5221
|
+
const accountSpaceId = this.ownedSpaceId(import_sdk_core11.ACCOUNT_REGISTRY_SPACE);
|
|
5202
5222
|
await this.ensureOwnedSpaceHostedById(accountSpaceId, signal);
|
|
5203
5223
|
if (signal.aborted) throw signal.reason;
|
|
5204
5224
|
const result = await account.applications.register(request.manifests);
|
|
@@ -5213,7 +5233,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5213
5233
|
const session = context.session;
|
|
5214
5234
|
if (!session) throw new Error("Account registry requires an active service session");
|
|
5215
5235
|
const contexts = [context];
|
|
5216
|
-
const accountSpaceId = this.ownedSpaceId(
|
|
5236
|
+
const accountSpaceId = this.ownedSpaceId(import_sdk_core11.ACCOUNT_REGISTRY_SPACE);
|
|
5217
5237
|
const createScopedContext = (spaceId) => {
|
|
5218
5238
|
const scoped = this._serviceGraph.track(createServiceContext({
|
|
5219
5239
|
requestSink: this._serviceGraph.requestSink,
|
|
@@ -5229,10 +5249,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5229
5249
|
contexts.push(scoped);
|
|
5230
5250
|
return scoped;
|
|
5231
5251
|
};
|
|
5232
|
-
const sql = new
|
|
5252
|
+
const sql = new import_sdk_core11.SQLService({});
|
|
5233
5253
|
const sqlContext = createScopedContext(accountSpaceId);
|
|
5234
5254
|
sql.initialize(sqlContext);
|
|
5235
|
-
const spaces = new
|
|
5255
|
+
const spaces = new import_sdk_core11.SpaceService({
|
|
5236
5256
|
hosts: context.hosts,
|
|
5237
5257
|
session,
|
|
5238
5258
|
invoke: context.invoke,
|
|
@@ -5242,14 +5262,14 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5242
5262
|
}),
|
|
5243
5263
|
userDid: this.did,
|
|
5244
5264
|
createKVService: (spaceId) => {
|
|
5245
|
-
const kv = new
|
|
5265
|
+
const kv = new import_sdk_core11.KVService({});
|
|
5246
5266
|
kv.initialize(createScopedContext(spaceId));
|
|
5247
5267
|
return kv;
|
|
5248
5268
|
}
|
|
5249
5269
|
});
|
|
5250
5270
|
return {
|
|
5251
5271
|
contexts,
|
|
5252
|
-
account: new
|
|
5272
|
+
account: new import_sdk_core7.AccountService({
|
|
5253
5273
|
getDid: () => this.did,
|
|
5254
5274
|
getHost: () => context.hosts[0] ?? this.config.host,
|
|
5255
5275
|
getPrimarySpaceId: () => session.spaceId,
|
|
@@ -5405,7 +5425,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5405
5425
|
return true;
|
|
5406
5426
|
}
|
|
5407
5427
|
const indexRead = {
|
|
5408
|
-
spaceId: this.ownedSpaceId(
|
|
5428
|
+
spaceId: this.ownedSpaceId(import_sdk_core11.ACCOUNT_REGISTRY_SPACE),
|
|
5409
5429
|
service: "sql",
|
|
5410
5430
|
path: "account",
|
|
5411
5431
|
action: "tinycloud.sql/read"
|
|
@@ -5433,7 +5453,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5433
5453
|
stopped(error);
|
|
5434
5454
|
return;
|
|
5435
5455
|
}
|
|
5436
|
-
const verdict = (0,
|
|
5456
|
+
const verdict = (0, import_sdk_core11.authorizationVerdictOf)(error);
|
|
5437
5457
|
const message = error instanceof Error ? error.message : String(error);
|
|
5438
5458
|
const isAuthorizationVerdict = verdict === void 0 ? /^(?:Unauthorized Action\b|(?:(?:request failed|HTTP request failed|status(?: code)?|response status)\s*:\s*)?(?:HTTP\s*)?(?:401|403)\b)/i.test(message) : verdict !== "other";
|
|
5439
5459
|
if (isAuthorizationVerdict) {
|
|
@@ -5443,7 +5463,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5443
5463
|
);
|
|
5444
5464
|
return;
|
|
5445
5465
|
}
|
|
5446
|
-
if ((0,
|
|
5466
|
+
if ((0, import_sdk_core11.isStorageFullError)(error) || (0, import_sdk_core11.isStorageFullError)(error?.cause) || message.includes(import_sdk_core11.STORAGE_FULL_MESSAGE) || message.includes(import_sdk_core11.STORAGE_WRITE_TOO_LARGE_MESSAGE)) {
|
|
5447
5467
|
console.warn(
|
|
5448
5468
|
"TinyCloud account registry sync stopped: storage is full",
|
|
5449
5469
|
error
|
|
@@ -5481,7 +5501,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5481
5501
|
}
|
|
5482
5502
|
const networkIds = /* @__PURE__ */ new Set();
|
|
5483
5503
|
for (const resource of request.resources) {
|
|
5484
|
-
if (resource.service ===
|
|
5504
|
+
if (resource.service === import_sdk_core11.ENCRYPTION_PERMISSION_SERVICE && resource.path.startsWith("urn:tinycloud:encryption:") && resource.actions.includes(DECRYPT_ACTION2)) {
|
|
5485
5505
|
networkIds.add(resource.path);
|
|
5486
5506
|
}
|
|
5487
5507
|
}
|
|
@@ -5492,7 +5512,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5492
5512
|
return;
|
|
5493
5513
|
}
|
|
5494
5514
|
for (const networkId of this.requestedEncryptionNetworkIds()) {
|
|
5495
|
-
const parsed = (0,
|
|
5515
|
+
const parsed = (0, import_sdk_core11.parseNetworkId)(networkId);
|
|
5496
5516
|
if (!didPrincipalMatches2(parsed.ownerDid, this.did)) {
|
|
5497
5517
|
continue;
|
|
5498
5518
|
}
|
|
@@ -5530,7 +5550,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5530
5550
|
if (!host) {
|
|
5531
5551
|
throw new Error("Owned space hosting requires a TinyCloud host");
|
|
5532
5552
|
}
|
|
5533
|
-
const activation = await (0,
|
|
5553
|
+
const activation = await (0, import_sdk_core11.activateSessionWithHost)(host, session.delegationHeader, signal);
|
|
5534
5554
|
if (activation.success && !activation.skipped?.includes(spaceId)) {
|
|
5535
5555
|
this.confirmedHostedSpaceIds.add(spaceId);
|
|
5536
5556
|
return;
|
|
@@ -5551,7 +5571,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5551
5571
|
);
|
|
5552
5572
|
}
|
|
5553
5573
|
if (signal?.aborted) throw signal.reason;
|
|
5554
|
-
const retry = await (0,
|
|
5574
|
+
const retry = await (0, import_sdk_core11.activateSessionWithHost)(host, session.delegationHeader, signal);
|
|
5555
5575
|
if (!retry.success || retry.skipped?.includes(spaceId)) {
|
|
5556
5576
|
throw Object.assign(
|
|
5557
5577
|
new Error(
|
|
@@ -5602,7 +5622,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5602
5622
|
{ cause: hosted }
|
|
5603
5623
|
);
|
|
5604
5624
|
}
|
|
5605
|
-
const activation = await (0,
|
|
5625
|
+
const activation = await (0, import_sdk_core11.activateSessionWithHost)(
|
|
5606
5626
|
host,
|
|
5607
5627
|
session.delegationHeader
|
|
5608
5628
|
);
|
|
@@ -5862,7 +5882,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5862
5882
|
}
|
|
5863
5883
|
let restoredAddress;
|
|
5864
5884
|
try {
|
|
5865
|
-
restoredAddress = hasPersistedProof ? (0,
|
|
5885
|
+
restoredAddress = hasPersistedProof ? (0, import_sdk_core11.canonicalizeAddress)(sessionData.address) : void 0;
|
|
5866
5886
|
} catch {
|
|
5867
5887
|
throw new InvalidRestoredSessionError("Persisted session has an invalid wallet address.");
|
|
5868
5888
|
}
|
|
@@ -5906,9 +5926,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5906
5926
|
let replicaProtocolMismatch = false;
|
|
5907
5927
|
if (this.config.replication?.enabled) {
|
|
5908
5928
|
try {
|
|
5909
|
-
restoredNodeFeatures = (await (0,
|
|
5929
|
+
restoredNodeFeatures = (await (0, import_sdk_core11.checkNodeInfo)(stagedHost, this.wasmBindings.protocolVersion())).features;
|
|
5910
5930
|
} catch (error) {
|
|
5911
|
-
replicaProtocolMismatch = error instanceof
|
|
5931
|
+
replicaProtocolMismatch = error instanceof import_sdk_core11.ProtocolMismatchError;
|
|
5912
5932
|
}
|
|
5913
5933
|
}
|
|
5914
5934
|
const stagedAddress = restoredAddress;
|
|
@@ -5919,7 +5939,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5919
5939
|
let replicationScopeUnavailable = false;
|
|
5920
5940
|
if (this.config.replication?.enabled) {
|
|
5921
5941
|
if (stagedAddress !== void 0) {
|
|
5922
|
-
replicationPrincipal = (0,
|
|
5942
|
+
replicationPrincipal = (0, import_sdk_core11.pkhDid)(stagedAddress, stagedChainId);
|
|
5923
5943
|
} else {
|
|
5924
5944
|
try {
|
|
5925
5945
|
const { replicationScopeFromSignedSession } = await getNodeReplicationLoaders().authority();
|
|
@@ -5968,7 +5988,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5968
5988
|
}
|
|
5969
5989
|
}
|
|
5970
5990
|
}
|
|
5971
|
-
const stagedNodeDid = stagedAddress ? (0,
|
|
5991
|
+
const stagedNodeDid = stagedAddress ? (0, import_sdk_core11.pkhDid)(stagedAddress, stagedChainId) : canonicalVerificationMethod;
|
|
5972
5992
|
const serviceSession = {
|
|
5973
5993
|
delegationHeader: sessionData.delegationHeader,
|
|
5974
5994
|
delegationCid: sessionData.delegationCid,
|
|
@@ -5996,7 +6016,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5996
6016
|
stagedSessionExpiry,
|
|
5997
6017
|
stagedRecap
|
|
5998
6018
|
);
|
|
5999
|
-
const stagedAccountSpaceId = stagedAddress ? this.wasmBindings.makeSpaceId(stagedAddress, stagedChainId,
|
|
6019
|
+
const stagedAccountSpaceId = stagedAddress ? this.wasmBindings.makeSpaceId(stagedAddress, stagedChainId, import_sdk_core11.ACCOUNT_REGISTRY_SPACE) : void 0;
|
|
6000
6020
|
const stagedGraph = this.stageRestoredServiceGraph({
|
|
6001
6021
|
host: stagedHost,
|
|
6002
6022
|
manager: stagedManager,
|
|
@@ -6131,7 +6151,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6131
6151
|
}
|
|
6132
6152
|
stageRestoredServiceGraph(input) {
|
|
6133
6153
|
const graph = this.createServiceGraphLifetime();
|
|
6134
|
-
const core = this.auth ? new
|
|
6154
|
+
const core = this.auth ? new import_sdk_core11.TinyCloud(this.auth, {
|
|
6135
6155
|
invokeAny: graph.invokeAny,
|
|
6136
6156
|
telemetry: this.config.telemetry,
|
|
6137
6157
|
retryPolicy: this.config.retryPolicy
|
|
@@ -6150,16 +6170,16 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6150
6170
|
telemetry: this.config.telemetry,
|
|
6151
6171
|
retryPolicy: this.config.retryPolicy
|
|
6152
6172
|
}));
|
|
6153
|
-
const kv = new
|
|
6173
|
+
const kv = new import_sdk_core11.KVService({});
|
|
6154
6174
|
kv.initialize(serviceContext);
|
|
6155
6175
|
serviceContext.registerService("kv", kv);
|
|
6156
|
-
const sql = new
|
|
6176
|
+
const sql = new import_sdk_core11.SQLService({});
|
|
6157
6177
|
sql.initialize(serviceContext);
|
|
6158
6178
|
serviceContext.registerService("sql", sql);
|
|
6159
|
-
const duckdb = new
|
|
6179
|
+
const duckdb = new import_sdk_core11.DuckDbService({});
|
|
6160
6180
|
duckdb.initialize(serviceContext);
|
|
6161
6181
|
serviceContext.registerService("duckdb", duckdb);
|
|
6162
|
-
const hooks = new
|
|
6182
|
+
const hooks = new import_sdk_core11.HooksService({});
|
|
6163
6183
|
hooks.initialize(serviceContext);
|
|
6164
6184
|
serviceContext.registerService("hooks", hooks);
|
|
6165
6185
|
serviceContext.setSession(input.serviceSession);
|
|
@@ -6182,7 +6202,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6182
6202
|
});
|
|
6183
6203
|
vault.initialize(serviceContext);
|
|
6184
6204
|
serviceContext.registerService("vault", vault);
|
|
6185
|
-
const capabilityRegistry = new
|
|
6205
|
+
const capabilityRegistry = new import_sdk_core11.CapabilityKeyRegistry();
|
|
6186
6206
|
if (input.tinyCloudSession) {
|
|
6187
6207
|
const session = input.tinyCloudSession;
|
|
6188
6208
|
const delegations = input.recap.map((entry) => ({
|
|
@@ -6206,7 +6226,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6206
6226
|
}, delegations);
|
|
6207
6227
|
}
|
|
6208
6228
|
}
|
|
6209
|
-
const delegationManager = new
|
|
6229
|
+
const delegationManager = new import_sdk_core11.DelegationManager({
|
|
6210
6230
|
hosts: [input.host],
|
|
6211
6231
|
accountSpaceId: input.accountSpaceId,
|
|
6212
6232
|
session: input.serviceSession,
|
|
@@ -6216,7 +6236,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6216
6236
|
fetch: graph.fetch
|
|
6217
6237
|
});
|
|
6218
6238
|
const keyProvider = new WasmKeyProvider({ sessionManager: input.manager });
|
|
6219
|
-
const sharingService = new
|
|
6239
|
+
const sharingService = new import_sdk_core11.SharingService({
|
|
6220
6240
|
hosts: [input.host],
|
|
6221
6241
|
invoke: graph.invoke,
|
|
6222
6242
|
fetch: graph.fetch,
|
|
@@ -6229,7 +6249,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6229
6249
|
return this.wasmBindings.computeCid(data, codec);
|
|
6230
6250
|
},
|
|
6231
6251
|
createKVService: (config) => {
|
|
6232
|
-
const service = new
|
|
6252
|
+
const service = new import_sdk_core11.KVService({ prefix: config.pathPrefix?.replace(/\/$/, "") });
|
|
6233
6253
|
const context = graph.track(createServiceContext({
|
|
6234
6254
|
requestSink: graph.requestSink,
|
|
6235
6255
|
invoke: config.invoke,
|
|
@@ -6261,7 +6281,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6261
6281
|
return delegation;
|
|
6262
6282
|
} : void 0
|
|
6263
6283
|
});
|
|
6264
|
-
const spaceService = new
|
|
6284
|
+
const spaceService = new import_sdk_core11.SpaceService({
|
|
6265
6285
|
hosts: [input.host],
|
|
6266
6286
|
session: input.serviceSession,
|
|
6267
6287
|
invoke: graph.invoke,
|
|
@@ -6270,7 +6290,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6270
6290
|
userDid: input.nodeDid,
|
|
6271
6291
|
createKVService: (spaceId) => {
|
|
6272
6292
|
graph.assertActive();
|
|
6273
|
-
const scopedKv = new
|
|
6293
|
+
const scopedKv = new import_sdk_core11.KVService({});
|
|
6274
6294
|
const context = graph.track(createServiceContext({
|
|
6275
6295
|
requestSink: graph.requestSink,
|
|
6276
6296
|
invoke: graph.invoke,
|
|
@@ -6287,7 +6307,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6287
6307
|
},
|
|
6288
6308
|
createVaultService: (spaceId) => {
|
|
6289
6309
|
graph.assertActive();
|
|
6290
|
-
const scopedKv = new
|
|
6310
|
+
const scopedKv = new import_sdk_core11.KVService({});
|
|
6291
6311
|
const context = graph.track(createServiceContext({
|
|
6292
6312
|
requestSink: graph.requestSink,
|
|
6293
6313
|
invoke: graph.invoke,
|
|
@@ -6379,7 +6399,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6379
6399
|
return void 0;
|
|
6380
6400
|
}
|
|
6381
6401
|
if (this.config.registryPolicy === "fail-closed") {
|
|
6382
|
-
const resolved2 = await (0,
|
|
6402
|
+
const resolved2 = await (0, import_sdk_core11.resolveFailClosedTinyCloudHosts)(address, {
|
|
6383
6403
|
registryUrl: this.config.tinycloudRegistryUrl,
|
|
6384
6404
|
registryChainId: this.config.registryChainId,
|
|
6385
6405
|
newUserHost: this.config.newUserHost,
|
|
@@ -6393,7 +6413,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6393
6413
|
});
|
|
6394
6414
|
return resolved2.hosts[0];
|
|
6395
6415
|
}
|
|
6396
|
-
const resolved = await (0,
|
|
6416
|
+
const resolved = await (0, import_sdk_core11.resolveTinyCloudHosts)((0, import_sdk_core11.pkhDid)(address, chainId), {
|
|
6397
6417
|
registryUrl: this.config.tinycloudRegistryUrl,
|
|
6398
6418
|
fallbackHosts: this.config.tinycloudFallbackHosts,
|
|
6399
6419
|
autoDiscoverLocalNode: this.config.autoDiscoverLocalNode,
|
|
@@ -6445,7 +6465,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6445
6465
|
nodeAudience: input.nodeAudience,
|
|
6446
6466
|
...input.role === "policy-enforcement" ? { enforcerDid: input.audienceDid } : {}
|
|
6447
6467
|
};
|
|
6448
|
-
const root = await (0,
|
|
6468
|
+
const root = await (0, import_sdk_core11.signCompactUcanRootAuthorization)({
|
|
6449
6469
|
issuerDid: ownerDid,
|
|
6450
6470
|
audienceDid: input.audienceDid,
|
|
6451
6471
|
attenuation: unifiedRootAttenuation(input.capabilities),
|
|
@@ -6487,7 +6507,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6487
6507
|
if (decision.needsApproval) return void 0;
|
|
6488
6508
|
throw new Error(decision.reason ?? "OpenKey automatic credential signing was rejected");
|
|
6489
6509
|
}
|
|
6490
|
-
if (typeof decision.signature !== "string" || !await (0,
|
|
6510
|
+
if (typeof decision.signature !== "string" || !await (0, import_sdk_core11.verifyEip191MessageSignature)(
|
|
6491
6511
|
request.message,
|
|
6492
6512
|
decision.signature,
|
|
6493
6513
|
request.address
|
|
@@ -6512,7 +6532,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6512
6532
|
if (approval) {
|
|
6513
6533
|
const decision = await approval(request);
|
|
6514
6534
|
if (!decision.approved) throw new Error(decision.reason ?? "Credential signing was rejected");
|
|
6515
|
-
if (decision.signature !== void 0 && !await (0,
|
|
6535
|
+
if (decision.signature !== void 0 && !await (0, import_sdk_core11.verifyEip191MessageSignature)(
|
|
6516
6536
|
request.message,
|
|
6517
6537
|
decision.signature,
|
|
6518
6538
|
request.address
|
|
@@ -6597,7 +6617,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6597
6617
|
nonce: this.config.nonce,
|
|
6598
6618
|
siweConfig: this.config.siweConfig,
|
|
6599
6619
|
manifest: useBootstrapSignInRequest ? void 0 : this.config.manifest,
|
|
6600
|
-
capabilityRequest: useBootstrapSignInRequest ? this.config.includeAccountRegistryPermissions === false ?
|
|
6620
|
+
capabilityRequest: useBootstrapSignInRequest ? this.config.includeAccountRegistryPermissions === false ? import_sdk_core11.BOOTSTRAP_DEFAULT_ONLY_SESSION_REQUEST : import_sdk_core11.BOOTSTRAP_SESSION_REQUESTS.default : this.config.capabilityRequest,
|
|
6601
6621
|
includeAccountRegistryPermissions: useBootstrapSignInRequest ? false : this.config.includeAccountRegistryPermissions,
|
|
6602
6622
|
replication: this.config.replication?.enabled === true ? {
|
|
6603
6623
|
enabled: true,
|
|
@@ -6605,7 +6625,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6605
6625
|
allowSecrets: this.config.replication.allowSecrets === true
|
|
6606
6626
|
} : void 0
|
|
6607
6627
|
});
|
|
6608
|
-
this.tc = new
|
|
6628
|
+
this.tc = new import_sdk_core11.TinyCloud(this.auth, {
|
|
6609
6629
|
invokeAny: this.invokeAnyWithRuntimePermissions,
|
|
6610
6630
|
telemetry: this.config.telemetry,
|
|
6611
6631
|
retryPolicy: this.config.retryPolicy
|
|
@@ -6658,7 +6678,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6658
6678
|
nonce: this.config.nonce,
|
|
6659
6679
|
siweConfig: this.config.siweConfig,
|
|
6660
6680
|
manifest: useBootstrapSignInRequest ? void 0 : this.config.manifest,
|
|
6661
|
-
capabilityRequest: useBootstrapSignInRequest ? this.config.includeAccountRegistryPermissions === false ?
|
|
6681
|
+
capabilityRequest: useBootstrapSignInRequest ? this.config.includeAccountRegistryPermissions === false ? import_sdk_core11.BOOTSTRAP_DEFAULT_ONLY_SESSION_REQUEST : import_sdk_core11.BOOTSTRAP_SESSION_REQUESTS.default : this.config.capabilityRequest,
|
|
6662
6682
|
includeAccountRegistryPermissions: useBootstrapSignInRequest ? false : this.config.includeAccountRegistryPermissions,
|
|
6663
6683
|
replication: this.config.replication?.enabled === true ? {
|
|
6664
6684
|
enabled: true,
|
|
@@ -6666,7 +6686,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6666
6686
|
allowSecrets: this.config.replication.allowSecrets === true
|
|
6667
6687
|
} : void 0
|
|
6668
6688
|
});
|
|
6669
|
-
this.tc = new
|
|
6689
|
+
this.tc = new import_sdk_core11.TinyCloud(this.auth, {
|
|
6670
6690
|
invokeAny: this.invokeAnyWithRuntimePermissions,
|
|
6671
6691
|
telemetry: this.config.telemetry,
|
|
6672
6692
|
retryPolicy: this.config.retryPolicy
|
|
@@ -6697,21 +6717,21 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6697
6717
|
telemetry: this.config.telemetry,
|
|
6698
6718
|
retryPolicy: this.config.retryPolicy
|
|
6699
6719
|
}));
|
|
6700
|
-
this._kv = new
|
|
6720
|
+
this._kv = new import_sdk_core11.KVService({});
|
|
6701
6721
|
this._kv.initialize(this._serviceContext);
|
|
6702
6722
|
this._serviceContext.registerService("kv", this._kv);
|
|
6703
6723
|
const features = this.nodeFeatures;
|
|
6704
6724
|
if (features.length === 0 || features.includes("sql")) {
|
|
6705
|
-
this._sql = new
|
|
6725
|
+
this._sql = new import_sdk_core11.SQLService({});
|
|
6706
6726
|
this._sql.initialize(this._serviceContext);
|
|
6707
6727
|
this._serviceContext.registerService("sql", this._sql);
|
|
6708
6728
|
}
|
|
6709
6729
|
if (features.length === 0 || features.includes("duckdb")) {
|
|
6710
|
-
this._duckdb = new
|
|
6730
|
+
this._duckdb = new import_sdk_core11.DuckDbService({});
|
|
6711
6731
|
this._duckdb.initialize(this._serviceContext);
|
|
6712
6732
|
this._serviceContext.registerService("duckdb", this._duckdb);
|
|
6713
6733
|
}
|
|
6714
|
-
this._hooks = new
|
|
6734
|
+
this._hooks = new import_sdk_core11.HooksService({});
|
|
6715
6735
|
this._hooks.initialize(this._serviceContext);
|
|
6716
6736
|
this._serviceContext.registerService("hooks", this._hooks);
|
|
6717
6737
|
const serviceSession = {
|
|
@@ -6735,7 +6755,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6735
6755
|
kvService.setReadThroughReady(attached);
|
|
6736
6756
|
}
|
|
6737
6757
|
createSpaceScopedKVService(spaceId) {
|
|
6738
|
-
const kvService = new
|
|
6758
|
+
const kvService = new import_sdk_core11.KVService({});
|
|
6739
6759
|
if (this._serviceContext) {
|
|
6740
6760
|
const spaceScopedContext = this._serviceGraph.track(createServiceContext({
|
|
6741
6761
|
requestSink: this._serviceGraph.requestSink,
|
|
@@ -6832,7 +6852,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6832
6852
|
const shared = wasm.vault_x25519_dh(receiverPrivateKey, peerPublic);
|
|
6833
6853
|
return columnDecrypt(shared, ciphertext);
|
|
6834
6854
|
},
|
|
6835
|
-
verifyNodeSignature: (nodeId, message, signature) => (0,
|
|
6855
|
+
verifyNodeSignature: (nodeId, message, signature) => (0, import_sdk_core11.verifyDidKeyEd25519Signature)(nodeId, message, signature)
|
|
6836
6856
|
};
|
|
6837
6857
|
}
|
|
6838
6858
|
/**
|
|
@@ -6848,7 +6868,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6848
6868
|
if (cached) return cached;
|
|
6849
6869
|
const response = await fetch(`${this.config.host}/info`);
|
|
6850
6870
|
if (!response.ok) {
|
|
6851
|
-
throw await (0,
|
|
6871
|
+
throw await (0, import_sdk_core11.httpResponseError)(response, "Failed to fetch node info");
|
|
6852
6872
|
}
|
|
6853
6873
|
const info = await response.json();
|
|
6854
6874
|
if (typeof info.nodeId !== "string" || info.nodeId.length === 0) {
|
|
@@ -6898,7 +6918,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6898
6918
|
);
|
|
6899
6919
|
if (response.status === 404) return null;
|
|
6900
6920
|
if (!response.ok) {
|
|
6901
|
-
throw await (0,
|
|
6921
|
+
throw await (0, import_sdk_core11.httpResponseError)(response, `Failed to fetch encryption network ${networkId}`);
|
|
6902
6922
|
}
|
|
6903
6923
|
const body = await response.json();
|
|
6904
6924
|
return "descriptor" in body && body.descriptor ? body.descriptor : body;
|
|
@@ -6934,12 +6954,12 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6934
6954
|
path: networkId,
|
|
6935
6955
|
actions: ["tinycloud.encryption/decrypt"]
|
|
6936
6956
|
}) : void 0;
|
|
6937
|
-
throw new
|
|
6957
|
+
throw new import_sdk_core11.DecryptTransportResponseError(response.status, permissionHint);
|
|
6938
6958
|
}
|
|
6939
6959
|
return await response.json();
|
|
6940
6960
|
}
|
|
6941
6961
|
};
|
|
6942
|
-
return new
|
|
6962
|
+
return new import_sdk_core11.EncryptionService({
|
|
6943
6963
|
crypto: crypto2,
|
|
6944
6964
|
signer: {
|
|
6945
6965
|
signDecryptInvocation: async (input) => {
|
|
@@ -6953,7 +6973,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6953
6973
|
graph.assertActive();
|
|
6954
6974
|
return {
|
|
6955
6975
|
...signed,
|
|
6956
|
-
canonicalBody: (0,
|
|
6976
|
+
canonicalBody: (0, import_sdk_core11.canonicalizeEncryptionJson)(
|
|
6957
6977
|
input.body
|
|
6958
6978
|
)
|
|
6959
6979
|
};
|
|
@@ -6985,7 +7005,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6985
7005
|
if (!address || !didPrincipalMatches2(principal, did)) {
|
|
6986
7006
|
return null;
|
|
6987
7007
|
}
|
|
6988
|
-
const publicSpaceId = (0,
|
|
7008
|
+
const publicSpaceId = (0, import_sdk_core11.makePublicSpaceId)(address, chainId);
|
|
6989
7009
|
const encodedKey = discoveryKey.split("/").map(encodeURIComponent).join("/");
|
|
6990
7010
|
const response = await graph.fetch(
|
|
6991
7011
|
`${host}/public/${encodeURIComponent(publicSpaceId)}/kv/${encodedKey}`,
|
|
@@ -7017,7 +7037,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7017
7037
|
createVaultService(spaceId, kv, encryptionService = this.getEncryptionService(), nodeContext) {
|
|
7018
7038
|
const wasm = this.wasmBindings;
|
|
7019
7039
|
const serviceGraph = nodeContext?.serviceGraph ?? this._serviceGraph;
|
|
7020
|
-
const vaultCrypto = (0,
|
|
7040
|
+
const vaultCrypto = (0, import_sdk_core11.createVaultCrypto)({
|
|
7021
7041
|
vault_encrypt: wasm.vault_encrypt,
|
|
7022
7042
|
vault_decrypt: wasm.vault_decrypt,
|
|
7023
7043
|
vault_derive_key: wasm.vault_derive_key,
|
|
@@ -7032,7 +7052,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7032
7052
|
const chainId = nodeContext?.chainId ?? this._chainId;
|
|
7033
7053
|
const host = nodeContext?.host ?? this.config.host;
|
|
7034
7054
|
const ownerDid = this.ownerDidFromSpaceId(spaceId) ?? did;
|
|
7035
|
-
return new
|
|
7055
|
+
return new import_sdk_core11.DataVaultService({
|
|
7036
7056
|
spaceId,
|
|
7037
7057
|
crypto: vaultCrypto,
|
|
7038
7058
|
encryption: {
|
|
@@ -7057,8 +7077,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7057
7077
|
serviceGraph.assertActive();
|
|
7058
7078
|
return self._publicKV ?? self.tc.publicKV;
|
|
7059
7079
|
},
|
|
7060
|
-
readPublicSpace: (host2, targetSpaceId, key) =>
|
|
7061
|
-
makePublicSpaceId:
|
|
7080
|
+
readPublicSpace: (host2, targetSpaceId, key) => import_sdk_core11.TinyCloud.readPublicSpace(host2, targetSpaceId, key),
|
|
7081
|
+
makePublicSpaceId: import_sdk_core11.TinyCloud.makePublicSpaceId,
|
|
7062
7082
|
did,
|
|
7063
7083
|
address: address ?? "",
|
|
7064
7084
|
chainId,
|
|
@@ -7072,7 +7092,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7072
7092
|
*/
|
|
7073
7093
|
initializeV2Services(serviceSession) {
|
|
7074
7094
|
const graph = this._serviceGraph;
|
|
7075
|
-
this._capabilityRegistry = new
|
|
7095
|
+
this._capabilityRegistry = new import_sdk_core11.CapabilityKeyRegistry();
|
|
7076
7096
|
const tcSession = this.auth?.tinyCloudSession;
|
|
7077
7097
|
if (tcSession && this._address) {
|
|
7078
7098
|
const sessionKey = {
|
|
@@ -7112,7 +7132,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7112
7132
|
}
|
|
7113
7133
|
this._capabilityRegistry.registerKey(sessionKey, delegations);
|
|
7114
7134
|
}
|
|
7115
|
-
this._delegationManager = new
|
|
7135
|
+
this._delegationManager = new import_sdk_core11.DelegationManager({
|
|
7116
7136
|
hosts: [this.config.host],
|
|
7117
7137
|
accountSpaceId: this.accountSpaceId,
|
|
7118
7138
|
session: serviceSession,
|
|
@@ -7121,7 +7141,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7121
7141
|
signOwnerRevocation: this.signer ? (cid) => this.signOwnerRevocation(cid) : void 0,
|
|
7122
7142
|
fetch: graph.fetch
|
|
7123
7143
|
});
|
|
7124
|
-
this._spaceService = new
|
|
7144
|
+
this._spaceService = new import_sdk_core11.SpaceService({
|
|
7125
7145
|
hosts: [this.config.host],
|
|
7126
7146
|
session: serviceSession,
|
|
7127
7147
|
invoke: graph.invoke,
|
|
@@ -7187,7 +7207,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7187
7207
|
},
|
|
7188
7208
|
isStorageFull: () => this.ownStorageFull
|
|
7189
7209
|
});
|
|
7190
|
-
this._sharingService = new
|
|
7210
|
+
this._sharingService = new import_sdk_core11.SharingService({
|
|
7191
7211
|
hosts: [this.config.host],
|
|
7192
7212
|
session: serviceSession,
|
|
7193
7213
|
invoke: graph.invoke,
|
|
@@ -7206,7 +7226,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7206
7226
|
},
|
|
7207
7227
|
createKVService: (config) => {
|
|
7208
7228
|
graph.assertActive();
|
|
7209
|
-
const service = new
|
|
7229
|
+
const service = new import_sdk_core11.KVService({ prefix: config.pathPrefix?.replace(/\/$/, "") });
|
|
7210
7230
|
const context = graph.track(createServiceContext({
|
|
7211
7231
|
requestSink: graph.requestSink,
|
|
7212
7232
|
invoke: config.invoke,
|
|
@@ -7280,7 +7300,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7280
7300
|
params.notBeforeSecs
|
|
7281
7301
|
);
|
|
7282
7302
|
return {
|
|
7283
|
-
...terminal ? (0,
|
|
7303
|
+
...terminal ? (0, import_sdk_core11.markDelegationTerminal)(result.delegation, params.session.jwk) : { delegation: result.delegation, cid: result.cid },
|
|
7284
7304
|
// Rust serde `rename_all = "camelCase"` emits `delegateDid`
|
|
7285
7305
|
// (lowercase d); the TypeScript interface uses `delegateDID`
|
|
7286
7306
|
// (historical, matches Delegation.delegateDID). Normalize here.
|
|
@@ -7303,15 +7323,15 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7303
7323
|
}
|
|
7304
7324
|
const permissions = ownerDelegationPermissions(params);
|
|
7305
7325
|
const now = /* @__PURE__ */ new Date();
|
|
7306
|
-
if (!(params.expiresAt instanceof Date) || params.expiresAt.getTime() <= now.getTime() || params.expiresAt.getTime() - now.getTime() >
|
|
7326
|
+
if (!(params.expiresAt instanceof Date) || params.expiresAt.getTime() <= now.getTime() || params.expiresAt.getTime() - now.getTime() > import_sdk_core11.EXPIRY.MAX_MS) {
|
|
7307
7327
|
throw new Error("Owner delegation expiry must be explicit, future, and within EXPIRY.MAX_MS");
|
|
7308
7328
|
}
|
|
7309
7329
|
if (!this.signer) throw new Error("Owner wallet signer is required");
|
|
7310
7330
|
const session = this.currentTinyCloudSession();
|
|
7311
7331
|
if (!session) throw new Error("Owner session is required");
|
|
7312
|
-
const ownerDid = (0,
|
|
7332
|
+
const ownerDid = (0, import_sdk_core11.pkhDid)(session.address, session.chainId);
|
|
7313
7333
|
for (const permission of permissions) {
|
|
7314
|
-
if (permission.service ===
|
|
7334
|
+
if (permission.service === import_sdk_core11.ENCRYPTION_PERMISSION_SERVICE && !(0, import_sdk_core11.principalDidEquals)((0, import_sdk_core11.parseNetworkId)(permission.path).ownerDid, ownerDid)) {
|
|
7315
7335
|
throw new Error("Owner delegation cannot grant a foreign encryption network");
|
|
7316
7336
|
}
|
|
7317
7337
|
}
|
|
@@ -7332,7 +7352,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7332
7352
|
const signature = await this.signer.signMessage(prepared.siwe);
|
|
7333
7353
|
assertOwnerGraphActive();
|
|
7334
7354
|
const delegationSession = this.wasmBindings.completeSessionSetup({ ...prepared, signature });
|
|
7335
|
-
const activation = await (0,
|
|
7355
|
+
const activation = await (0, import_sdk_core11.activateSessionWithHost)(host, delegationSession.delegationHeader);
|
|
7336
7356
|
assertOwnerGraphActive();
|
|
7337
7357
|
if (!activation.success) {
|
|
7338
7358
|
throw Object.assign(
|
|
@@ -7393,7 +7413,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7393
7413
|
/** Register a signed policy and sibling roots with this Node's Policy/v3 runtime. */
|
|
7394
7414
|
async registerPolicy(params) {
|
|
7395
7415
|
this._serviceGraph.assertActive();
|
|
7396
|
-
return (0,
|
|
7416
|
+
return (0, import_sdk_core11.registerPolicyV3)({
|
|
7397
7417
|
...params,
|
|
7398
7418
|
nodeOrigin: this.config.host,
|
|
7399
7419
|
fetch: globalThis.fetch.bind(globalThis)
|
|
@@ -7420,23 +7440,23 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7420
7440
|
jti: base64UrlEncode(jtiDigest.slice(0, 16)),
|
|
7421
7441
|
expiresAt: new Date(input.expiresAt).toISOString().replace(/\.\d{3}Z$/, "Z")
|
|
7422
7442
|
};
|
|
7423
|
-
const requestBodyDigest = base64UrlEncode(new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode((0,
|
|
7443
|
+
const requestBodyDigest = base64UrlEncode(new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode((0, import_sdk_core11.canonicalizeEncryptionJson)(body)))));
|
|
7424
7444
|
const request = { ...body, requestBodyDigest };
|
|
7425
7445
|
const authorization = authorizationHeader(this.wasmBindings.invoke(serviceSession, "kv", input.resourcePath, "tinycloud.kv/get"));
|
|
7426
7446
|
const response = await fetch(`${this.config.host}/policy/v3/deliveries/authorize`, {
|
|
7427
7447
|
method: "POST",
|
|
7428
7448
|
headers: { accept: "application/json", "content-type": "application/json", authorization },
|
|
7429
|
-
body: (0,
|
|
7449
|
+
body: (0, import_sdk_core11.canonicalizeEncryptionJson)(request)
|
|
7430
7450
|
});
|
|
7431
|
-
if (!response.ok) throw await (0,
|
|
7432
|
-
const verified = (0,
|
|
7451
|
+
if (!response.ok) throw await (0, import_sdk_core11.httpResponseError)(response, "V3 share delivery authorization failed");
|
|
7452
|
+
const verified = (0, import_sdk_core11.validateShareDeliveryAuthorizationV3Bytes)(new Uint8Array(await response.arrayBuffer()), {
|
|
7433
7453
|
request,
|
|
7434
7454
|
senderKeyDid: this.credentialHolderDid,
|
|
7435
7455
|
deliveryAudience: input.deliveryAudience
|
|
7436
7456
|
});
|
|
7437
7457
|
const requestDigest = new Uint8Array(await crypto.subtle.digest(
|
|
7438
7458
|
"SHA-256",
|
|
7439
|
-
new TextEncoder().encode(`${
|
|
7459
|
+
new TextEncoder().encode(`${import_sdk_core11.CREDENTIAL_INVITATION_REQUEST_DOMAIN}${(0, import_sdk_core11.canonicalizeEncryptionJson)(verified.request)}`)
|
|
7440
7460
|
));
|
|
7441
7461
|
return {
|
|
7442
7462
|
...verified,
|
|
@@ -7504,7 +7524,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7504
7524
|
if (!this._sql) {
|
|
7505
7525
|
const features = this.nodeFeatures;
|
|
7506
7526
|
if (features.length > 0 && !features.includes("sql")) {
|
|
7507
|
-
throw new
|
|
7527
|
+
throw new import_sdk_core11.UnsupportedFeatureError("sql", this.config.host, features);
|
|
7508
7528
|
}
|
|
7509
7529
|
throw new Error("Not signed in. Call signIn() first.");
|
|
7510
7530
|
}
|
|
@@ -7528,7 +7548,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7528
7548
|
if (!this._serviceContext || !this._serviceContext.session) {
|
|
7529
7549
|
throw new Error("Not signed in. Call signIn() first.");
|
|
7530
7550
|
}
|
|
7531
|
-
const sql = new
|
|
7551
|
+
const sql = new import_sdk_core11.SQLService({});
|
|
7532
7552
|
const spaceScopedContext = this._serviceGraph.track(createServiceContext({
|
|
7533
7553
|
requestSink: this._serviceGraph.requestSink,
|
|
7534
7554
|
invoke: this._serviceContext.invoke,
|
|
@@ -7560,7 +7580,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7560
7580
|
if (!this._serviceContext || !this._serviceContext.session) {
|
|
7561
7581
|
throw new Error("Not signed in. Call signIn() first.");
|
|
7562
7582
|
}
|
|
7563
|
-
const kv = new
|
|
7583
|
+
const kv = new import_sdk_core11.KVService({});
|
|
7564
7584
|
const spaceScopedContext = this._serviceGraph.track(createServiceContext({
|
|
7565
7585
|
requestSink: this._serviceGraph.requestSink,
|
|
7566
7586
|
invoke: this._serviceContext.invoke,
|
|
@@ -7580,7 +7600,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7580
7600
|
if (!this._duckdb) {
|
|
7581
7601
|
const features = this.nodeFeatures;
|
|
7582
7602
|
if (features.length > 0 && !features.includes("duckdb")) {
|
|
7583
|
-
throw new
|
|
7603
|
+
throw new import_sdk_core11.UnsupportedFeatureError("duckdb", this.config.host, features);
|
|
7584
7604
|
}
|
|
7585
7605
|
throw new Error("Not signed in. Call signIn() first.");
|
|
7586
7606
|
}
|
|
@@ -7624,7 +7644,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7624
7644
|
type: NETWORK_ADMIN_TYPE,
|
|
7625
7645
|
targetNode,
|
|
7626
7646
|
networkId,
|
|
7627
|
-
bodyHash: (0,
|
|
7647
|
+
bodyHash: (0, import_sdk_core11.canonicalHashHex)(
|
|
7628
7648
|
crypto2.sha256,
|
|
7629
7649
|
body
|
|
7630
7650
|
),
|
|
@@ -7642,7 +7662,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7642
7662
|
Authorization: signed.authorization,
|
|
7643
7663
|
"Content-Type": "application/json"
|
|
7644
7664
|
},
|
|
7645
|
-
body: (0,
|
|
7665
|
+
body: (0, import_sdk_core11.canonicalizeEncryptionJson)(
|
|
7646
7666
|
body
|
|
7647
7667
|
)
|
|
7648
7668
|
});
|
|
@@ -7654,7 +7674,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7654
7674
|
);
|
|
7655
7675
|
}
|
|
7656
7676
|
if (!response.ok) {
|
|
7657
|
-
throw await (0,
|
|
7677
|
+
throw await (0, import_sdk_core11.httpResponseError)(response, `Failed to create encryption network ${networkId}`);
|
|
7658
7678
|
}
|
|
7659
7679
|
const created = await response.json();
|
|
7660
7680
|
return created.descriptor;
|
|
@@ -7673,7 +7693,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7673
7693
|
return existing;
|
|
7674
7694
|
}
|
|
7675
7695
|
}
|
|
7676
|
-
const parsed = (0,
|
|
7696
|
+
const parsed = (0, import_sdk_core11.parseNetworkId)(networkId);
|
|
7677
7697
|
if (!didPrincipalMatches2(parsed.ownerDid, this.did)) {
|
|
7678
7698
|
throw new Error(
|
|
7679
7699
|
`Cannot create encryption network ${networkId}: owner ${parsed.ownerDid} does not match signed-in DID ${this.did}`
|
|
@@ -7722,7 +7742,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7722
7742
|
* normal KV and encryption invocation paths.
|
|
7723
7743
|
*/
|
|
7724
7744
|
async readSecret(input) {
|
|
7725
|
-
const resolved = (0,
|
|
7745
|
+
const resolved = (0, import_sdk_core11.resolveSecretPath)(input.name, { scope: input.scope });
|
|
7726
7746
|
const targetSpace = input.space.startsWith("tinycloud:") ? input.space : this.ownedSpaceId(input.space);
|
|
7727
7747
|
const result = await this.getBaseVault(targetSpace).readNetworkEncrypted(
|
|
7728
7748
|
resolved.vaultKey
|
|
@@ -7756,7 +7776,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7756
7776
|
const resolvedSpace = spaceId.startsWith("tinycloud:") ? spaceId : this.ownedSpaceId(spaceId);
|
|
7757
7777
|
let secrets = this._baseSecrets.get(resolvedSpace);
|
|
7758
7778
|
if (!secrets) {
|
|
7759
|
-
secrets = new
|
|
7779
|
+
secrets = new import_sdk_core11.SecretsService(() => this.getBaseVault(resolvedSpace));
|
|
7760
7780
|
this._baseSecrets.set(resolvedSpace, secrets);
|
|
7761
7781
|
}
|
|
7762
7782
|
return secrets;
|
|
@@ -7899,7 +7919,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7899
7919
|
for (const grant of this.runtimePermissionGrants) {
|
|
7900
7920
|
if (grant.provenance === "primary") continue;
|
|
7901
7921
|
for (const operation of grant.operations) {
|
|
7902
|
-
const service =
|
|
7922
|
+
const service = import_sdk_core11.SERVICE_SHORT_TO_LONG[operation.service];
|
|
7903
7923
|
if (service === void 0 || typeof operation.path !== "string" || typeof operation.action !== "string") {
|
|
7904
7924
|
continue;
|
|
7905
7925
|
}
|
|
@@ -7917,7 +7937,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7917
7937
|
service,
|
|
7918
7938
|
...space === void 0 ? {} : { space },
|
|
7919
7939
|
path: operation.path,
|
|
7920
|
-
caveats: (0,
|
|
7940
|
+
caveats: (0, import_sdk_core11.canonicalizeRecapCaveats)(caveats)
|
|
7921
7941
|
});
|
|
7922
7942
|
const existing = grouped.get(identity);
|
|
7923
7943
|
if (existing === void 0) {
|
|
@@ -7962,7 +7982,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7962
7982
|
delegationCid: grant.delegationCid,
|
|
7963
7983
|
spaceId: grant.spaceId,
|
|
7964
7984
|
jwk: this.sessionKeyJwk,
|
|
7965
|
-
address: (0,
|
|
7985
|
+
address: (0, import_sdk_core11.canonicalizeAddress)(grant.address),
|
|
7966
7986
|
chainId: grant.chainId,
|
|
7967
7987
|
siwe: grant.siwe,
|
|
7968
7988
|
signature: grant.signature
|
|
@@ -7984,10 +8004,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7984
8004
|
const graph = this._serviceGraph;
|
|
7985
8005
|
const session = this.currentTinyCloudSession();
|
|
7986
8006
|
if (!session) {
|
|
7987
|
-
throw new
|
|
8007
|
+
throw new import_sdk_core11.SessionExpiredError(/* @__PURE__ */ new Date(0));
|
|
7988
8008
|
}
|
|
7989
8009
|
if (delegation.expiry.getTime() <= Date.now()) {
|
|
7990
|
-
throw new
|
|
8010
|
+
throw new import_sdk_core11.SessionExpiredError(delegation.expiry);
|
|
7991
8011
|
}
|
|
7992
8012
|
const expectedDids = [session.verificationMethod, this.sessionDid];
|
|
7993
8013
|
if (!expectedDids.some((did) => didPrincipalMatches2(delegation.delegateDID, did))) {
|
|
@@ -7998,7 +8018,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
7998
8018
|
const targetHost = delegation.host ?? this.config.host;
|
|
7999
8019
|
let activateResult;
|
|
8000
8020
|
try {
|
|
8001
|
-
activateResult = await (0,
|
|
8021
|
+
activateResult = await (0, import_sdk_core11.activateSessionWithHost)(
|
|
8002
8022
|
targetHost,
|
|
8003
8023
|
delegation.delegationHeader,
|
|
8004
8024
|
graph.signal
|
|
@@ -8044,13 +8064,13 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
8044
8064
|
const graph = this._serviceGraph;
|
|
8045
8065
|
const session = this.currentTinyCloudSession();
|
|
8046
8066
|
if (!session) {
|
|
8047
|
-
throw new
|
|
8067
|
+
throw new import_sdk_core11.SessionExpiredError(/* @__PURE__ */ new Date(0));
|
|
8048
8068
|
}
|
|
8049
8069
|
const sessionExpiry = extractSiweExpiration(session.siwe);
|
|
8050
8070
|
if (sessionExpiry !== void 0) {
|
|
8051
8071
|
const marginMs = _TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS;
|
|
8052
8072
|
if (sessionExpiry.getTime() <= Date.now() + marginMs) {
|
|
8053
|
-
throw new
|
|
8073
|
+
throw new import_sdk_core11.SessionExpiredError(sessionExpiry);
|
|
8054
8074
|
}
|
|
8055
8075
|
}
|
|
8056
8076
|
const expanded = this.expandPermissionEntries(permissions);
|
|
@@ -8127,7 +8147,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
8127
8147
|
...prepared,
|
|
8128
8148
|
signature
|
|
8129
8149
|
});
|
|
8130
|
-
const activateResult = await (0,
|
|
8150
|
+
const activateResult = await (0, import_sdk_core11.activateSessionWithHost)(
|
|
8131
8151
|
this.config.host,
|
|
8132
8152
|
delegatedSession.delegationHeader,
|
|
8133
8153
|
graph.signal
|
|
@@ -8300,10 +8320,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
8300
8320
|
}
|
|
8301
8321
|
await this.assertMayCreateSpace();
|
|
8302
8322
|
await this.auth.hostPublicSpace(publicSpaceId);
|
|
8303
|
-
const kvActions = [
|
|
8323
|
+
const kvActions = [import_sdk_core11.KV.PUT, import_sdk_core11.KV.GET, import_sdk_core11.KV.DEL, import_sdk_core11.KV.LIST, import_sdk_core11.KV.METADATA];
|
|
8304
8324
|
const abilities = { kv: { "": kvActions } };
|
|
8305
8325
|
const now = /* @__PURE__ */ new Date();
|
|
8306
|
-
const expiryMs =
|
|
8326
|
+
const expiryMs = import_sdk_core11.EXPIRY.EPHEMERAL_MS;
|
|
8307
8327
|
const expirationTime = new Date(now.getTime() + expiryMs);
|
|
8308
8328
|
const prepared = this.wasmBindings.prepareSession({
|
|
8309
8329
|
abilities,
|
|
@@ -8321,7 +8341,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
8321
8341
|
...prepared,
|
|
8322
8342
|
signature
|
|
8323
8343
|
});
|
|
8324
|
-
const activateResult = await (0,
|
|
8344
|
+
const activateResult = await (0, import_sdk_core11.activateSessionWithHost)(
|
|
8325
8345
|
this.config.host,
|
|
8326
8346
|
delegationSession.delegationHeader
|
|
8327
8347
|
);
|
|
@@ -8351,7 +8371,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
8351
8371
|
}]);
|
|
8352
8372
|
}
|
|
8353
8373
|
if (this._serviceContext) {
|
|
8354
|
-
const publicKV = new
|
|
8374
|
+
const publicKV = new import_sdk_core11.KVService({ prefix: "" });
|
|
8355
8375
|
const publicContext = this._serviceGraph.track(createServiceContext({
|
|
8356
8376
|
requestSink: this._serviceGraph.requestSink,
|
|
8357
8377
|
invoke: this._serviceGraph.invoke,
|
|
@@ -8476,14 +8496,14 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
8476
8496
|
}
|
|
8477
8497
|
const session = this.currentTinyCloudSession();
|
|
8478
8498
|
if (!session) {
|
|
8479
|
-
throw new
|
|
8499
|
+
throw new import_sdk_core11.SessionExpiredError(/* @__PURE__ */ new Date(0));
|
|
8480
8500
|
}
|
|
8481
8501
|
const sessionExpiry = extractSiweExpiration(session.siwe);
|
|
8482
8502
|
if (sessionExpiry !== void 0) {
|
|
8483
8503
|
const now2 = Date.now();
|
|
8484
8504
|
const marginMs = _TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS;
|
|
8485
8505
|
if (sessionExpiry.getTime() <= now2 + marginMs) {
|
|
8486
|
-
throw new
|
|
8506
|
+
throw new import_sdk_core11.SessionExpiredError(sessionExpiry);
|
|
8487
8507
|
}
|
|
8488
8508
|
}
|
|
8489
8509
|
if (!Array.isArray(permissions) || permissions.length === 0) {
|
|
@@ -8524,12 +8544,12 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
8524
8544
|
);
|
|
8525
8545
|
if ("refused" in plan) {
|
|
8526
8546
|
if (plan.refused === "SESSION_EXPIRING") {
|
|
8527
|
-
throw new
|
|
8547
|
+
throw new import_sdk_core11.SessionExpiredError(plan.expiredAt ?? sessionExpiry ?? /* @__PURE__ */ new Date(0));
|
|
8528
8548
|
}
|
|
8529
8549
|
if (plan.refused === "CAVEATED_AUTHORITY") {
|
|
8530
|
-
throw new
|
|
8550
|
+
throw new import_sdk_core11.CaveatedDelegationUnsupportedError(plan.caveated ?? []);
|
|
8531
8551
|
}
|
|
8532
|
-
throw new
|
|
8552
|
+
throw new import_sdk_core11.PermissionNotInManifestError(plan.missing ?? [], plan.granted ?? []);
|
|
8533
8553
|
}
|
|
8534
8554
|
if (plan.path === "runtime") {
|
|
8535
8555
|
const delegation2 = await this.createDelegationViaRuntimeGrant(
|
|
@@ -8568,7 +8588,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
8568
8588
|
*/
|
|
8569
8589
|
planDerivation(expandedEntries, session, effectiveExpiration, nowMs) {
|
|
8570
8590
|
const caveatedRequest = expandedEntries.filter(
|
|
8571
|
-
(entry) => !(0,
|
|
8591
|
+
(entry) => !(0, import_sdk_core11.recapCaveatsEqual)(entry.caveats, void 0)
|
|
8572
8592
|
);
|
|
8573
8593
|
if (caveatedRequest.length > 0) {
|
|
8574
8594
|
return { refused: "CAVEATED_AUTHORITY", caveated: caveatedRequest };
|
|
@@ -8709,7 +8729,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
8709
8729
|
}, getNodeReplicationLoaders().gatedNetwork);
|
|
8710
8730
|
return;
|
|
8711
8731
|
}
|
|
8712
|
-
const identityPrincipal = principal ?? (this._address === void 0 ? void 0 : (0,
|
|
8732
|
+
const identityPrincipal = principal ?? (this._address === void 0 ? void 0 : (0, import_sdk_core11.pkhDid)(this._address, this._chainId));
|
|
8713
8733
|
if (identityPrincipal === void 0) return;
|
|
8714
8734
|
const authority = await this.replicationAuthority();
|
|
8715
8735
|
if (epoch !== this.sessionEpoch || attempt !== this.latestSessionAttempt || this._kv !== kv || this._serviceContext !== context) return;
|
|
@@ -8805,7 +8825,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
8805
8825
|
const spaceId = resolvedSpaces.size === 1 ? [...resolvedSpaces][0] : session.spaceId;
|
|
8806
8826
|
const abilities = {};
|
|
8807
8827
|
for (const entry of entries) {
|
|
8808
|
-
const shortService =
|
|
8828
|
+
const shortService = import_sdk_core11.SERVICE_LONG_TO_SHORT[entry.service];
|
|
8809
8829
|
if (shortService === void 0) {
|
|
8810
8830
|
throw new Error(
|
|
8811
8831
|
`delegateTo: unknown service '${entry.service}' \u2014 no short-form mapping`
|
|
@@ -8862,7 +8882,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
8862
8882
|
if (onPrepared) {
|
|
8863
8883
|
await onPrepared(delegation);
|
|
8864
8884
|
}
|
|
8865
|
-
const activateResult = await (0,
|
|
8885
|
+
const activateResult = await (0, import_sdk_core11.activateSessionWithHost)(
|
|
8866
8886
|
this.config.host,
|
|
8867
8887
|
delegationHeader
|
|
8868
8888
|
);
|
|
@@ -8899,7 +8919,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
8899
8919
|
if (onPrepared) {
|
|
8900
8920
|
await onPrepared(delegation);
|
|
8901
8921
|
}
|
|
8902
|
-
const activateResult = await (0,
|
|
8922
|
+
const activateResult = await (0, import_sdk_core11.activateSessionWithHost)(
|
|
8903
8923
|
targetHost,
|
|
8904
8924
|
delegationHeader
|
|
8905
8925
|
);
|
|
@@ -8923,7 +8943,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
8923
8943
|
return this.wasmBindings.makeSpaceId(session.address, session.chainId, space);
|
|
8924
8944
|
}
|
|
8925
8945
|
expandPermissionEntries(permissions) {
|
|
8926
|
-
return (0,
|
|
8946
|
+
return (0, import_sdk_core11.expandPermissionEntries)(permissions);
|
|
8927
8947
|
}
|
|
8928
8948
|
/**
|
|
8929
8949
|
* The current WASM child-delegation APIs accept action-only maps. Refuse any
|
|
@@ -8931,10 +8951,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
8931
8951
|
*/
|
|
8932
8952
|
assertDelegationCaveatsPreservable(entries) {
|
|
8933
8953
|
const caveated = entries.filter(
|
|
8934
|
-
(entry) => !(0,
|
|
8954
|
+
(entry) => !(0, import_sdk_core11.recapCaveatsEqual)(entry.caveats, void 0)
|
|
8935
8955
|
);
|
|
8936
8956
|
if (caveated.length > 0) {
|
|
8937
|
-
throw new
|
|
8957
|
+
throw new import_sdk_core11.CaveatedDelegationUnsupportedError(caveated);
|
|
8938
8958
|
}
|
|
8939
8959
|
}
|
|
8940
8960
|
/**
|
|
@@ -8946,7 +8966,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
8946
8966
|
assertRuntimeGrantCaveatsPreservable(entries, requestedOperations, grant) {
|
|
8947
8967
|
const caveated = this.caveatedRuntimeGrantEntries(entries, requestedOperations, grant);
|
|
8948
8968
|
if (caveated.length > 0) {
|
|
8949
|
-
throw new
|
|
8969
|
+
throw new import_sdk_core11.CaveatedDelegationUnsupportedError(caveated);
|
|
8950
8970
|
}
|
|
8951
8971
|
}
|
|
8952
8972
|
/**
|
|
@@ -8963,7 +8983,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
8963
8983
|
const requested = requestedOperations[operationIndex++];
|
|
8964
8984
|
if (!requested) continue;
|
|
8965
8985
|
const constrained = grant.operations.find(
|
|
8966
|
-
(granted) => this.operationCovers(granted, requested) && !(0,
|
|
8986
|
+
(granted) => this.operationCovers(granted, requested) && !(0, import_sdk_core11.recapCaveatsEqual)(granted.caveats, void 0)
|
|
8967
8987
|
);
|
|
8968
8988
|
if (constrained) {
|
|
8969
8989
|
caveated.push({
|
|
@@ -8980,7 +9000,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
8980
9000
|
assertPortableDelegationCaveatsPreservable(delegation) {
|
|
8981
9001
|
const entries = [];
|
|
8982
9002
|
const add = (service, space, path, actions, caveats) => {
|
|
8983
|
-
if ((0,
|
|
9003
|
+
if ((0, import_sdk_core11.recapCaveatsEqual)(caveats, void 0)) return;
|
|
8984
9004
|
entries.push({
|
|
8985
9005
|
service: service.startsWith("tinycloud.") ? service : `tinycloud.${service}`,
|
|
8986
9006
|
space,
|
|
@@ -9000,11 +9020,11 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
9000
9020
|
add(resource.service, resource.space, resource.path, resource.actions, resource.caveats);
|
|
9001
9021
|
}
|
|
9002
9022
|
if (entries.length > 0) {
|
|
9003
|
-
throw new
|
|
9023
|
+
throw new import_sdk_core11.CaveatedDelegationUnsupportedError(entries);
|
|
9004
9024
|
}
|
|
9005
9025
|
}
|
|
9006
9026
|
shortServiceName(service) {
|
|
9007
|
-
const short =
|
|
9027
|
+
const short = import_sdk_core11.SERVICE_LONG_TO_SHORT[service];
|
|
9008
9028
|
if (short === void 0) {
|
|
9009
9029
|
throw new Error(
|
|
9010
9030
|
`unknown service '${service}' \u2014 no short-form mapping`
|
|
@@ -9031,7 +9051,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
9031
9051
|
return abilities;
|
|
9032
9052
|
}
|
|
9033
9053
|
isEncryptionPermissionEntry(entry) {
|
|
9034
|
-
return entry.service ===
|
|
9054
|
+
return entry.service === import_sdk_core11.ENCRYPTION_PERMISSION_SERVICE && this.isEncryptionNetworkOperation("encryption", entry.path, entry.space);
|
|
9035
9055
|
}
|
|
9036
9056
|
isRawRevocationPermissionEntry(entry) {
|
|
9037
9057
|
return entry.service === "tinycloud.delegation" && entry.path === "" && entry.space?.startsWith("urn:cid:") === true && entry.actions.includes("tinycloud.delegation/revoke");
|
|
@@ -9079,7 +9099,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
9079
9099
|
const missing = requested.filter((entry) => {
|
|
9080
9100
|
const raw = this.isEncryptionPermissionEntry(entry) || this.isRawRevocationPermissionEntry(entry);
|
|
9081
9101
|
const comparable = raw && this.isEncryptionPermissionEntry(entry) ? { ...entry, space: "encryption" } : entry;
|
|
9082
|
-
return !(0,
|
|
9102
|
+
return !(0, import_sdk_core11.isCapabilitySubset)([comparable], raw ? rawGranted : spaceGranted).subset;
|
|
9083
9103
|
});
|
|
9084
9104
|
return { subset: missing.length === 0, missing };
|
|
9085
9105
|
}
|
|
@@ -9326,7 +9346,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
9326
9346
|
if (granted.service !== requested.service || !this.actionContains(granted.action, requested.action)) {
|
|
9327
9347
|
return false;
|
|
9328
9348
|
}
|
|
9329
|
-
if (requested.caveats !== void 0 && !(0,
|
|
9349
|
+
if (requested.caveats !== void 0 && !(0, import_sdk_core11.recapCaveatsEqual)(granted.caveats, requested.caveats)) {
|
|
9330
9350
|
return false;
|
|
9331
9351
|
}
|
|
9332
9352
|
if (granted.resource !== void 0 || requested.resource !== void 0) {
|
|
@@ -9348,7 +9368,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
9348
9368
|
if (grantedAction === requestedAction) {
|
|
9349
9369
|
return true;
|
|
9350
9370
|
}
|
|
9351
|
-
if ((0,
|
|
9371
|
+
if ((0, import_sdk_core11.isExplicitOnlyAction)(requestedAction)) {
|
|
9352
9372
|
return false;
|
|
9353
9373
|
}
|
|
9354
9374
|
if (grantedAction.endsWith("/*")) {
|
|
@@ -9460,7 +9480,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
9460
9480
|
if (resolvedDelegateDID.endsWith(".eth") && this.config.ensResolver) {
|
|
9461
9481
|
const address = await this.config.ensResolver.resolveAddress(resolvedDelegateDID);
|
|
9462
9482
|
if (!address) throw new Error(`Could not resolve ENS name: ${resolvedDelegateDID}`);
|
|
9463
|
-
resolvedDelegateDID = (0,
|
|
9483
|
+
resolvedDelegateDID = (0, import_sdk_core11.pkhDid)(address, 1);
|
|
9464
9484
|
}
|
|
9465
9485
|
const entries = legacyParamsToPermissionEntries(
|
|
9466
9486
|
params.actions,
|
|
@@ -9474,7 +9494,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
9474
9494
|
});
|
|
9475
9495
|
return result.delegation;
|
|
9476
9496
|
} catch (err2) {
|
|
9477
|
-
if (err2 instanceof
|
|
9497
|
+
if (err2 instanceof import_sdk_core11.PermissionNotInManifestError) {
|
|
9478
9498
|
} else {
|
|
9479
9499
|
throw err2;
|
|
9480
9500
|
}
|
|
@@ -9534,7 +9554,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
9534
9554
|
...prepared,
|
|
9535
9555
|
signature
|
|
9536
9556
|
});
|
|
9537
|
-
const activateResult = await (0,
|
|
9557
|
+
const activateResult = await (0, import_sdk_core11.activateSessionWithHost)(
|
|
9538
9558
|
this.config.host,
|
|
9539
9559
|
delegationSession.delegationHeader
|
|
9540
9560
|
);
|
|
@@ -9559,12 +9579,12 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
9559
9579
|
};
|
|
9560
9580
|
const hasKvActions = params.actions.some((a) => a.startsWith("tinycloud.kv/"));
|
|
9561
9581
|
if (hasKvActions && params.includePublicSpace !== false) {
|
|
9562
|
-
const publicSpaceId = (0,
|
|
9582
|
+
const publicSpaceId = (0, import_sdk_core11.makePublicSpaceId)(
|
|
9563
9583
|
this.wasmBindings.ensureEip55(session.address),
|
|
9564
9584
|
session.chainId
|
|
9565
9585
|
);
|
|
9566
9586
|
const publicAbilities = {
|
|
9567
|
-
kv: { "": [
|
|
9587
|
+
kv: { "": [import_sdk_core11.KV.GET, import_sdk_core11.KV.PUT, import_sdk_core11.KV.METADATA] }
|
|
9568
9588
|
};
|
|
9569
9589
|
const publicPrepared = this.wasmBindings.prepareSession({
|
|
9570
9590
|
abilities: publicAbilities,
|
|
@@ -9582,7 +9602,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
9582
9602
|
...publicPrepared,
|
|
9583
9603
|
signature: publicSignature
|
|
9584
9604
|
});
|
|
9585
|
-
const publicActivateResult = await (0,
|
|
9605
|
+
const publicActivateResult = await (0, import_sdk_core11.activateSessionWithHost)(
|
|
9586
9606
|
this.config.host,
|
|
9587
9607
|
publicSession.delegationHeader
|
|
9588
9608
|
);
|
|
@@ -9592,7 +9612,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
9592
9612
|
delegationHeader: publicSession.delegationHeader,
|
|
9593
9613
|
spaceId: publicSpaceId,
|
|
9594
9614
|
path: "",
|
|
9595
|
-
actions: [
|
|
9615
|
+
actions: [import_sdk_core11.KV.GET, import_sdk_core11.KV.PUT, import_sdk_core11.KV.METADATA],
|
|
9596
9616
|
disableSubDelegation: false,
|
|
9597
9617
|
expiry: expirationTime,
|
|
9598
9618
|
delegateDID: params.delegateDID,
|
|
@@ -9690,7 +9710,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
9690
9710
|
...prepared,
|
|
9691
9711
|
signature
|
|
9692
9712
|
});
|
|
9693
|
-
const activateResult = await (0,
|
|
9713
|
+
const activateResult = await (0, import_sdk_core11.activateSessionWithHost)(
|
|
9694
9714
|
targetHost,
|
|
9695
9715
|
invokerSession.delegationHeader,
|
|
9696
9716
|
graph.signal
|
|
@@ -9751,6 +9771,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
9751
9771
|
*/
|
|
9752
9772
|
async createSubDelegation(parentDelegation, params) {
|
|
9753
9773
|
this.assertPortableDelegationCaveatsPreservable(parentDelegation);
|
|
9774
|
+
refuseCaveated(params.resources);
|
|
9754
9775
|
if (!this.signer) {
|
|
9755
9776
|
throw new Error("Cannot createSubDelegation() in session-only mode. Requires wallet mode.");
|
|
9756
9777
|
}
|
|
@@ -9819,7 +9840,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
9819
9840
|
...prepared,
|
|
9820
9841
|
signature
|
|
9821
9842
|
});
|
|
9822
|
-
const activateResult = await (0,
|
|
9843
|
+
const activateResult = await (0, import_sdk_core11.activateSessionWithHost)(
|
|
9823
9844
|
targetHost,
|
|
9824
9845
|
subDelegationSession.delegationHeader
|
|
9825
9846
|
);
|
|
@@ -9866,7 +9887,6 @@ _TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS = 6e4;
|
|
|
9866
9887
|
var TinyCloudNode = _TinyCloudNode;
|
|
9867
9888
|
|
|
9868
9889
|
// src/core.ts
|
|
9869
|
-
var import_sdk_core13 = require("@tinycloud/sdk-core");
|
|
9870
9890
|
var import_sdk_core14 = require("@tinycloud/sdk-core");
|
|
9871
9891
|
var import_sdk_core15 = require("@tinycloud/sdk-core");
|
|
9872
9892
|
var import_sdk_core16 = require("@tinycloud/sdk-core");
|
|
@@ -9876,6 +9896,7 @@ var import_sdk_core19 = require("@tinycloud/sdk-core");
|
|
|
9876
9896
|
var import_sdk_core20 = require("@tinycloud/sdk-core");
|
|
9877
9897
|
var import_sdk_core21 = require("@tinycloud/sdk-core");
|
|
9878
9898
|
var import_sdk_core22 = require("@tinycloud/sdk-core");
|
|
9899
|
+
var import_sdk_core23 = require("@tinycloud/sdk-core");
|
|
9879
9900
|
// Annotate the CommonJS export names for ESM import in node:
|
|
9880
9901
|
0 && (module.exports = {
|
|
9881
9902
|
ACCOUNT_REGISTRY_PATH,
|
|
@@ -9970,6 +9991,7 @@ var import_sdk_core22 = require("@tinycloud/sdk-core");
|
|
|
9970
9991
|
pkhDid,
|
|
9971
9992
|
principalDid,
|
|
9972
9993
|
principalDidEquals,
|
|
9994
|
+
refuseCaveated,
|
|
9973
9995
|
registerReplicationLoaders,
|
|
9974
9996
|
resolveManifest,
|
|
9975
9997
|
resolveSecretListPrefix,
|