@tinycloud/node-sdk 2.4.0-beta.9 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{core-iwTdsebf.d.cts → core-DfE4s_Rg.d.cts} +121 -5
- package/dist/{core-iwTdsebf.d.ts → core-DfE4s_Rg.d.ts} +121 -5
- package/dist/core.cjs +715 -247
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +2 -2
- package/dist/core.d.ts +2 -2
- package/dist/core.js +505 -32
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +758 -290
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +505 -32
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -17025,135 +17025,143 @@ var require_utils2 = __commonJS({
|
|
|
17025
17025
|
// src/index.ts
|
|
17026
17026
|
var index_exports = {};
|
|
17027
17027
|
__export(index_exports, {
|
|
17028
|
-
ACCOUNT_REGISTRY_PATH: () =>
|
|
17029
|
-
ACCOUNT_REGISTRY_SPACE: () =>
|
|
17030
|
-
AccountService: () =>
|
|
17031
|
-
AutoApproveSpaceCreationHandler: () =>
|
|
17032
|
-
CapabilityKeyRegistry: () =>
|
|
17033
|
-
CapabilityKeyRegistryErrorCodes: () =>
|
|
17034
|
-
DECRYPT_ACTION: () =>
|
|
17035
|
-
DECRYPT_FACT_TYPE: () =>
|
|
17036
|
-
DECRYPT_RESULT_TYPE: () =>
|
|
17037
|
-
DEFAULT_ENCRYPTION_ALG: () =>
|
|
17038
|
-
DEFAULT_KEY_VERSION: () =>
|
|
17039
|
-
DEFAULT_MANIFEST_SPACE: () =>
|
|
17040
|
-
DEFAULT_MANIFEST_VERSION: () =>
|
|
17041
|
-
DEFAULT_SIGNED_READ_URL_EXPIRY_MS: () =>
|
|
17042
|
-
DataVaultService: () =>
|
|
17043
|
-
DatabaseHandle: () =>
|
|
17028
|
+
ACCOUNT_REGISTRY_PATH: () => import_sdk_core11.ACCOUNT_REGISTRY_PATH,
|
|
17029
|
+
ACCOUNT_REGISTRY_SPACE: () => import_sdk_core11.ACCOUNT_REGISTRY_SPACE,
|
|
17030
|
+
AccountService: () => import_sdk_core3.AccountService,
|
|
17031
|
+
AutoApproveSpaceCreationHandler: () => import_sdk_core10.AutoApproveSpaceCreationHandler,
|
|
17032
|
+
CapabilityKeyRegistry: () => import_sdk_core19.CapabilityKeyRegistry,
|
|
17033
|
+
CapabilityKeyRegistryErrorCodes: () => import_sdk_core19.CapabilityKeyRegistryErrorCodes,
|
|
17034
|
+
DECRYPT_ACTION: () => import_sdk_core16.DECRYPT_ACTION,
|
|
17035
|
+
DECRYPT_FACT_TYPE: () => import_sdk_core16.DECRYPT_FACT_TYPE,
|
|
17036
|
+
DECRYPT_RESULT_TYPE: () => import_sdk_core16.DECRYPT_RESULT_TYPE,
|
|
17037
|
+
DEFAULT_ENCRYPTION_ALG: () => import_sdk_core16.DEFAULT_ENCRYPTION_ALG,
|
|
17038
|
+
DEFAULT_KEY_VERSION: () => import_sdk_core16.DEFAULT_KEY_VERSION,
|
|
17039
|
+
DEFAULT_MANIFEST_SPACE: () => import_sdk_core11.DEFAULT_MANIFEST_SPACE,
|
|
17040
|
+
DEFAULT_MANIFEST_VERSION: () => import_sdk_core11.DEFAULT_MANIFEST_VERSION,
|
|
17041
|
+
DEFAULT_SIGNED_READ_URL_EXPIRY_MS: () => import_sdk_core12.DEFAULT_SIGNED_READ_URL_EXPIRY_MS,
|
|
17042
|
+
DataVaultService: () => import_sdk_core15.DataVaultService,
|
|
17043
|
+
DatabaseHandle: () => import_sdk_core13.DatabaseHandle,
|
|
17044
17044
|
DelegatedAccess: () => DelegatedAccess,
|
|
17045
|
-
DelegationErrorCodes: () =>
|
|
17046
|
-
DelegationManager: () =>
|
|
17047
|
-
DuckDbAction: () =>
|
|
17048
|
-
DuckDbDatabaseHandle: () =>
|
|
17049
|
-
DuckDbService: () =>
|
|
17050
|
-
ENCRYPTION_NETWORK_URN_PREFIX: () =>
|
|
17051
|
-
ENCRYPTION_SERVICE: () =>
|
|
17052
|
-
ENCRYPTION_SERVICE_SHORT: () =>
|
|
17053
|
-
ENVELOPE_VERSION: () =>
|
|
17054
|
-
EncryptionService: () =>
|
|
17045
|
+
DelegationErrorCodes: () => import_sdk_core18.DelegationErrorCodes,
|
|
17046
|
+
DelegationManager: () => import_sdk_core18.DelegationManager,
|
|
17047
|
+
DuckDbAction: () => import_sdk_core14.DuckDbAction,
|
|
17048
|
+
DuckDbDatabaseHandle: () => import_sdk_core14.DuckDbDatabaseHandle,
|
|
17049
|
+
DuckDbService: () => import_sdk_core14.DuckDbService,
|
|
17050
|
+
ENCRYPTION_NETWORK_URN_PREFIX: () => import_sdk_core16.ENCRYPTION_NETWORK_URN_PREFIX,
|
|
17051
|
+
ENCRYPTION_SERVICE: () => import_sdk_core16.ENCRYPTION_SERVICE,
|
|
17052
|
+
ENCRYPTION_SERVICE_SHORT: () => import_sdk_core16.ENCRYPTION_SERVICE_SHORT,
|
|
17053
|
+
ENVELOPE_VERSION: () => import_sdk_core16.ENVELOPE_VERSION,
|
|
17054
|
+
EncryptionService: () => import_sdk_core16.EncryptionService,
|
|
17055
17055
|
FileSessionStorage: () => FileSessionStorage,
|
|
17056
|
-
HooksService: () =>
|
|
17057
|
-
IdentityParseError: () =>
|
|
17058
|
-
KVService: () =>
|
|
17059
|
-
ManifestValidationError: () =>
|
|
17056
|
+
HooksService: () => import_sdk_core17.HooksService,
|
|
17057
|
+
IdentityParseError: () => import_sdk_core10.IdentityParseError,
|
|
17058
|
+
KVService: () => import_sdk_core12.KVService,
|
|
17059
|
+
ManifestValidationError: () => import_sdk_core11.ManifestValidationError,
|
|
17060
17060
|
MemorySessionStorage: () => MemorySessionStorage,
|
|
17061
|
-
NETWORK_NAME_PATTERN: () =>
|
|
17062
|
-
NetworkIdError: () =>
|
|
17061
|
+
NETWORK_NAME_PATTERN: () => import_sdk_core16.NETWORK_NAME_PATTERN,
|
|
17062
|
+
NetworkIdError: () => import_sdk_core16.NetworkIdError,
|
|
17063
17063
|
NodeUserAuthorization: () => NodeUserAuthorization,
|
|
17064
17064
|
NodeWasmBindings: () => NodeWasmBindings,
|
|
17065
|
-
PermissionNotInManifestError: () =>
|
|
17066
|
-
PrefixedKVService: () =>
|
|
17065
|
+
PermissionNotInManifestError: () => import_sdk_core11.PermissionNotInManifestError,
|
|
17066
|
+
PrefixedKVService: () => import_sdk_core12.PrefixedKVService,
|
|
17067
17067
|
PrivateKeySigner: () => PrivateKeySigner,
|
|
17068
|
-
ProtocolMismatchError: () =>
|
|
17069
|
-
SECRET_NAME_RE: () =>
|
|
17070
|
-
SQLAction: () =>
|
|
17071
|
-
SQLService: () =>
|
|
17072
|
-
SecretsService: () =>
|
|
17073
|
-
ServiceContext: () =>
|
|
17074
|
-
SessionExpiredError: () =>
|
|
17075
|
-
SharingService: () =>
|
|
17076
|
-
SilentNotificationHandler: () =>
|
|
17077
|
-
Space: () =>
|
|
17078
|
-
SpaceErrorCodes: () =>
|
|
17079
|
-
SpaceService: () =>
|
|
17080
|
-
TinyCloud: () =>
|
|
17068
|
+
ProtocolMismatchError: () => import_sdk_core21.ProtocolMismatchError,
|
|
17069
|
+
SECRET_NAME_RE: () => import_sdk_core15.SECRET_NAME_RE,
|
|
17070
|
+
SQLAction: () => import_sdk_core13.SQLAction,
|
|
17071
|
+
SQLService: () => import_sdk_core13.SQLService,
|
|
17072
|
+
SecretsService: () => import_sdk_core15.SecretsService,
|
|
17073
|
+
ServiceContext: () => import_sdk_core22.ServiceContext,
|
|
17074
|
+
SessionExpiredError: () => import_sdk_core11.SessionExpiredError,
|
|
17075
|
+
SharingService: () => import_sdk_core18.SharingService,
|
|
17076
|
+
SilentNotificationHandler: () => import_sdk_core10.SilentNotificationHandler,
|
|
17077
|
+
Space: () => import_sdk_core20.Space,
|
|
17078
|
+
SpaceErrorCodes: () => import_sdk_core20.SpaceErrorCodes,
|
|
17079
|
+
SpaceService: () => import_sdk_core20.SpaceService,
|
|
17080
|
+
TinyCloud: () => import_sdk_core9.TinyCloud,
|
|
17081
|
+
TinyCloudDebugLogger: () => import_sdk_core10.TinyCloudDebugLogger,
|
|
17081
17082
|
TinyCloudNode: () => TinyCloudNode,
|
|
17082
|
-
UnsupportedFeatureError: () =>
|
|
17083
|
-
VAULT_PERMISSION_SERVICE: () =>
|
|
17084
|
-
VaultHeaders: () =>
|
|
17085
|
-
VaultPublicSpaceKVActions: () =>
|
|
17086
|
-
VersionCheckError: () =>
|
|
17083
|
+
UnsupportedFeatureError: () => import_sdk_core21.UnsupportedFeatureError,
|
|
17084
|
+
VAULT_PERMISSION_SERVICE: () => import_sdk_core11.VAULT_PERMISSION_SERVICE,
|
|
17085
|
+
VaultHeaders: () => import_sdk_core15.VaultHeaders,
|
|
17086
|
+
VaultPublicSpaceKVActions: () => import_sdk_core15.VaultPublicSpaceKVActions,
|
|
17087
|
+
VersionCheckError: () => import_sdk_core21.VersionCheckError,
|
|
17087
17088
|
WasmKeyProvider: () => WasmKeyProvider,
|
|
17088
|
-
addressStorageKey: () =>
|
|
17089
|
-
buildCanonicalDecryptRequest: () =>
|
|
17090
|
-
buildDecryptAttenuation: () =>
|
|
17091
|
-
buildDecryptFacts: () =>
|
|
17092
|
-
buildDecryptInvocation: () =>
|
|
17093
|
-
buildNetworkId: () =>
|
|
17094
|
-
buildSpaceUri: () =>
|
|
17095
|
-
canonicalHashHex: () =>
|
|
17096
|
-
canonicalSignedResponse: () =>
|
|
17097
|
-
canonicalizeAddress: () =>
|
|
17098
|
-
canonicalizeDid: () =>
|
|
17099
|
-
canonicalizeDidUrl: () =>
|
|
17100
|
-
canonicalizeEncryptionJson: () =>
|
|
17101
|
-
canonicalizeNetworkId: () =>
|
|
17102
|
-
canonicalizeSecretScope: () =>
|
|
17103
|
-
checkDecryptInvocationInput: () =>
|
|
17104
|
-
checkNodeInfo: () =>
|
|
17105
|
-
|
|
17106
|
-
|
|
17107
|
-
|
|
17108
|
-
|
|
17109
|
-
|
|
17089
|
+
addressStorageKey: () => import_sdk_core10.addressStorageKey,
|
|
17090
|
+
buildCanonicalDecryptRequest: () => import_sdk_core16.buildCanonicalDecryptRequest,
|
|
17091
|
+
buildDecryptAttenuation: () => import_sdk_core16.buildDecryptAttenuation,
|
|
17092
|
+
buildDecryptFacts: () => import_sdk_core16.buildDecryptFacts,
|
|
17093
|
+
buildDecryptInvocation: () => import_sdk_core16.buildDecryptInvocation,
|
|
17094
|
+
buildNetworkId: () => import_sdk_core16.buildNetworkId,
|
|
17095
|
+
buildSpaceUri: () => import_sdk_core20.buildSpaceUri,
|
|
17096
|
+
canonicalHashHex: () => import_sdk_core16.canonicalHashHex,
|
|
17097
|
+
canonicalSignedResponse: () => import_sdk_core16.canonicalSignedResponse,
|
|
17098
|
+
canonicalizeAddress: () => import_sdk_core10.canonicalizeAddress,
|
|
17099
|
+
canonicalizeDid: () => import_sdk_core10.canonicalizeDid,
|
|
17100
|
+
canonicalizeDidUrl: () => import_sdk_core10.canonicalizeDidUrl,
|
|
17101
|
+
canonicalizeEncryptionJson: () => import_sdk_core16.canonicalizeEncryptionJson,
|
|
17102
|
+
canonicalizeNetworkId: () => import_sdk_core10.canonicalizeNetworkId,
|
|
17103
|
+
canonicalizeSecretScope: () => import_sdk_core15.canonicalizeSecretScope,
|
|
17104
|
+
checkDecryptInvocationInput: () => import_sdk_core16.checkDecryptInvocationInput,
|
|
17105
|
+
checkNodeInfo: () => import_sdk_core21.checkNodeInfo,
|
|
17106
|
+
clearTinyCloudDebugLogs: () => import_sdk_core10.clearTinyCloudDebugLogs,
|
|
17107
|
+
composeManifestRequest: () => import_sdk_core11.composeManifestRequest,
|
|
17108
|
+
createCapabilityKeyRegistry: () => import_sdk_core19.createCapabilityKeyRegistry,
|
|
17109
|
+
createOpenKeyCallbackSigningStrategy: () => import_sdk_core.createOpenKeyCallbackSigningStrategy,
|
|
17110
|
+
createSharingService: () => import_sdk_core18.createSharingService,
|
|
17111
|
+
createSpaceService: () => import_sdk_core20.createSpaceService,
|
|
17112
|
+
createVaultCrypto: () => import_sdk_core15.createVaultCrypto,
|
|
17110
17113
|
createWasmKeyProvider: () => createWasmKeyProvider,
|
|
17111
|
-
decryptEnvelopeWithKey: () =>
|
|
17114
|
+
decryptEnvelopeWithKey: () => import_sdk_core16.decryptEnvelopeWithKey,
|
|
17112
17115
|
defaultSignStrategy: () => defaultSignStrategy,
|
|
17113
|
-
defaultSpaceCreationHandler: () =>
|
|
17114
|
-
deriveSignedReceiverKey: () =>
|
|
17116
|
+
defaultSpaceCreationHandler: () => import_sdk_core10.defaultSpaceCreationHandler,
|
|
17117
|
+
deriveSignedReceiverKey: () => import_sdk_core16.deriveSignedReceiverKey,
|
|
17115
17118
|
deserializeDelegation: () => deserializeDelegation,
|
|
17116
|
-
didCacheKey: () =>
|
|
17117
|
-
didEquals: () =>
|
|
17118
|
-
|
|
17119
|
-
|
|
17120
|
-
|
|
17121
|
-
|
|
17122
|
-
|
|
17123
|
-
|
|
17124
|
-
|
|
17125
|
-
|
|
17126
|
-
|
|
17127
|
-
|
|
17128
|
-
|
|
17129
|
-
|
|
17119
|
+
didCacheKey: () => import_sdk_core10.didCacheKey,
|
|
17120
|
+
didEquals: () => import_sdk_core10.didEquals,
|
|
17121
|
+
disableTinyCloudDebug: () => import_sdk_core10.disableTinyCloudDebug,
|
|
17122
|
+
discoverNetwork: () => import_sdk_core16.discoverNetwork,
|
|
17123
|
+
enableTinyCloudDebug: () => import_sdk_core10.enableTinyCloudDebug,
|
|
17124
|
+
encryptToNetwork: () => import_sdk_core16.encryptToNetwork,
|
|
17125
|
+
encryptionBase64Decode: () => import_sdk_core16.encryptionBase64Decode,
|
|
17126
|
+
encryptionBase64Encode: () => import_sdk_core16.encryptionBase64Encode,
|
|
17127
|
+
encryptionError: () => import_sdk_core16.encryptionError,
|
|
17128
|
+
encryptionUtf8Decode: () => import_sdk_core16.encryptionUtf8Decode,
|
|
17129
|
+
encryptionUtf8Encode: () => import_sdk_core16.encryptionUtf8Encode,
|
|
17130
|
+
ensureNetworkUsableForDecrypt: () => import_sdk_core16.ensureNetworkUsableForDecrypt,
|
|
17131
|
+
expandActionShortNames: () => import_sdk_core11.expandActionShortNames,
|
|
17132
|
+
expandPermissionEntries: () => import_sdk_core11.expandPermissionEntries,
|
|
17133
|
+
expandPermissionEntry: () => import_sdk_core11.expandPermissionEntry,
|
|
17134
|
+
generateRandomReceiverKey: () => import_sdk_core16.generateRandomReceiverKey,
|
|
17135
|
+
getTinyCloudDebugLogs: () => import_sdk_core10.getTinyCloudDebugLogs,
|
|
17130
17136
|
grantAuthRequest: () => grantAuthRequest,
|
|
17131
|
-
hexDecode: () =>
|
|
17132
|
-
hexEncode: () =>
|
|
17133
|
-
|
|
17134
|
-
|
|
17135
|
-
|
|
17136
|
-
|
|
17137
|
-
|
|
17138
|
-
|
|
17139
|
-
|
|
17140
|
-
|
|
17141
|
-
|
|
17142
|
-
|
|
17143
|
-
|
|
17144
|
-
|
|
17145
|
-
|
|
17146
|
-
|
|
17147
|
-
|
|
17148
|
-
|
|
17149
|
-
|
|
17150
|
-
|
|
17151
|
-
|
|
17152
|
-
|
|
17137
|
+
hexDecode: () => import_sdk_core16.hexDecode,
|
|
17138
|
+
hexEncode: () => import_sdk_core16.hexEncode,
|
|
17139
|
+
installTinyCloudDebugGlobals: () => import_sdk_core10.installTinyCloudDebugGlobals,
|
|
17140
|
+
isCapabilitySubset: () => import_sdk_core11.isCapabilitySubset,
|
|
17141
|
+
isEvmAddress: () => import_sdk_core10.isEvmAddress,
|
|
17142
|
+
isNetworkId: () => import_sdk_core16.isNetworkId,
|
|
17143
|
+
loadManifest: () => import_sdk_core11.loadManifest,
|
|
17144
|
+
makePkhSpaceId: () => import_sdk_core10.makePkhSpaceId,
|
|
17145
|
+
makePublicSpaceId: () => import_sdk_core20.makePublicSpaceId,
|
|
17146
|
+
networkDiscoveryKey: () => import_sdk_core16.networkDiscoveryKey,
|
|
17147
|
+
openWrappedKey: () => import_sdk_core16.openWrappedKey,
|
|
17148
|
+
parseCanonicalNetworkId: () => import_sdk_core10.parseCanonicalNetworkId,
|
|
17149
|
+
parseExpiry: () => import_sdk_core11.parseExpiry,
|
|
17150
|
+
parseNetworkId: () => import_sdk_core16.parseNetworkId,
|
|
17151
|
+
parsePkhDid: () => import_sdk_core10.parsePkhDid,
|
|
17152
|
+
parseSpaceUri: () => import_sdk_core20.parseSpaceUri,
|
|
17153
|
+
pkhDid: () => import_sdk_core10.pkhDid,
|
|
17154
|
+
principalDid: () => import_sdk_core10.principalDid,
|
|
17155
|
+
principalDidEquals: () => import_sdk_core10.principalDidEquals,
|
|
17156
|
+
resolveManifest: () => import_sdk_core11.resolveManifest,
|
|
17157
|
+
resolveSecretListPrefix: () => import_sdk_core15.resolveSecretListPrefix,
|
|
17158
|
+
resolveSecretPath: () => import_sdk_core15.resolveSecretPath,
|
|
17159
|
+
resourceCapabilitiesToSpaceAbilitiesMap: () => import_sdk_core11.resourceCapabilitiesToSpaceAbilitiesMap,
|
|
17153
17160
|
serializeDelegation: () => serializeDelegation,
|
|
17154
|
-
|
|
17155
|
-
|
|
17156
|
-
|
|
17161
|
+
tinyCloudDebugLogger: () => import_sdk_core10.tinyCloudDebugLogger,
|
|
17162
|
+
validateEnvelope: () => import_sdk_core16.validateEnvelope,
|
|
17163
|
+
validateManifest: () => import_sdk_core11.validateManifest,
|
|
17164
|
+
verifyDecryptResponse: () => import_sdk_core16.verifyDecryptResponse
|
|
17157
17165
|
});
|
|
17158
17166
|
module.exports = __toCommonJS(index_exports);
|
|
17159
17167
|
|
|
@@ -17258,12 +17266,13 @@ var PrivateKeySigner = class {
|
|
|
17258
17266
|
};
|
|
17259
17267
|
|
|
17260
17268
|
// src/TinyCloudNode.ts
|
|
17261
|
-
var
|
|
17269
|
+
var import_sdk_core7 = require("@tinycloud/sdk-core");
|
|
17262
17270
|
|
|
17263
17271
|
// src/authorization/NodeUserAuthorization.ts
|
|
17264
|
-
var
|
|
17272
|
+
var import_sdk_core2 = require("@tinycloud/sdk-core");
|
|
17265
17273
|
|
|
17266
17274
|
// src/authorization/strategies.ts
|
|
17275
|
+
var import_sdk_core = require("@tinycloud/sdk-core");
|
|
17267
17276
|
var defaultSignStrategy = { type: "auto-sign" };
|
|
17268
17277
|
|
|
17269
17278
|
// src/storage/MemorySessionStorage.ts
|
|
@@ -17342,7 +17351,7 @@ var DECRYPT_ACTION = "tinycloud.encryption/decrypt";
|
|
|
17342
17351
|
var NETWORK_CREATE_ACTION = "tinycloud.encryption/network.create";
|
|
17343
17352
|
function didPrincipalMatches(actual, expected) {
|
|
17344
17353
|
try {
|
|
17345
|
-
return (0,
|
|
17354
|
+
return (0, import_sdk_core2.principalDidEquals)(actual, expected);
|
|
17346
17355
|
} catch {
|
|
17347
17356
|
return actual === expected;
|
|
17348
17357
|
}
|
|
@@ -17361,6 +17370,7 @@ var NodeUserAuthorization = class {
|
|
|
17361
17370
|
constructor(config) {
|
|
17362
17371
|
this.extensions = [];
|
|
17363
17372
|
this._nodeFeatures = [];
|
|
17373
|
+
this._lastActivationSkippedSpaceIds = [];
|
|
17364
17374
|
this.wasm = config.wasmBindings;
|
|
17365
17375
|
this.signer = config.signer;
|
|
17366
17376
|
this.signStrategy = config.signStrategy ?? defaultSignStrategy;
|
|
@@ -17383,7 +17393,7 @@ var NodeUserAuthorization = class {
|
|
|
17383
17393
|
"": [
|
|
17384
17394
|
"tinycloud.sql/read",
|
|
17385
17395
|
"tinycloud.sql/write",
|
|
17386
|
-
"tinycloud.sql/
|
|
17396
|
+
"tinycloud.sql/schema",
|
|
17387
17397
|
"tinycloud.sql/admin",
|
|
17388
17398
|
"tinycloud.sql/export"
|
|
17389
17399
|
]
|
|
@@ -17411,7 +17421,7 @@ var NodeUserAuthorization = class {
|
|
|
17411
17421
|
]
|
|
17412
17422
|
}
|
|
17413
17423
|
};
|
|
17414
|
-
this.sessionExpirationMs = config.sessionExpirationMs ??
|
|
17424
|
+
this.sessionExpirationMs = config.sessionExpirationMs ?? import_sdk_core2.EXPIRY.SESSION_MS;
|
|
17415
17425
|
this.autoCreateSpace = config.autoCreateSpace ?? false;
|
|
17416
17426
|
this.spaceCreationHandler = config.spaceCreationHandler;
|
|
17417
17427
|
this.tinycloudHosts = config.tinycloudHosts;
|
|
@@ -17475,19 +17485,55 @@ var NodeUserAuthorization = class {
|
|
|
17475
17485
|
* `siwe` is the load-bearing one because `extractSiweExpiration` returns
|
|
17476
17486
|
* undefined for missing SIWEs and the SDK then treats the session as
|
|
17477
17487
|
* expired-at-epoch-zero.
|
|
17488
|
+
*
|
|
17489
|
+
* @param hosts - The TinyCloud hosts this session was created against,
|
|
17490
|
+
* as persisted in {@link PersistedSessionData.tinycloudHosts}. When
|
|
17491
|
+
* present (and non-empty) they are adopted directly so the restored
|
|
17492
|
+
* session resolves to the same node as the original sign-in without
|
|
17493
|
+
* re-running registry/fallback resolution. When absent (old session)
|
|
17494
|
+
* hosts are resolved lazily on the first host-needing call via
|
|
17495
|
+
* {@link ensureTinyCloudHosts}.
|
|
17478
17496
|
*/
|
|
17479
|
-
setRestoredTinyCloudSession(session) {
|
|
17480
|
-
const address = (0,
|
|
17497
|
+
setRestoredTinyCloudSession(session, hosts) {
|
|
17498
|
+
const address = (0, import_sdk_core2.canonicalizeAddress)(session.address);
|
|
17481
17499
|
this._tinyCloudSession = { ...session, address };
|
|
17482
17500
|
this._address = address;
|
|
17483
17501
|
this._chainId = session.chainId;
|
|
17502
|
+
if ((!this.tinycloudHosts || this.tinycloudHosts.length === 0) && hosts && hosts.length > 0) {
|
|
17503
|
+
this.tinycloudHosts = [...hosts];
|
|
17504
|
+
}
|
|
17505
|
+
}
|
|
17506
|
+
/**
|
|
17507
|
+
* Ensure `tinycloudHosts` are resolved before a host-needing call.
|
|
17508
|
+
*
|
|
17509
|
+
* Fresh sign-in resolves hosts up front; a restored session may not have
|
|
17510
|
+
* (old persisted sessions predate {@link PersistedSessionData.tinycloudHosts}).
|
|
17511
|
+
* This guard makes a restored session resolve the node exactly like a fresh
|
|
17512
|
+
* sign-in — persisted hosts are preferred (already set by
|
|
17513
|
+
* {@link setRestoredTinyCloudSession}), otherwise the registry/fallback
|
|
17514
|
+
* resolution runs lazily here. Idempotent: {@link resolveTinyCloudHostsForSignIn}
|
|
17515
|
+
* early-returns when hosts are already set.
|
|
17516
|
+
*
|
|
17517
|
+
* Throws if hosts are unset and the restored session has no address/chainId
|
|
17518
|
+
* to resolve from — a real failure that must surface, not be masked.
|
|
17519
|
+
*/
|
|
17520
|
+
async ensureTinyCloudHosts() {
|
|
17521
|
+
if (this.tinycloudHosts && this.tinycloudHosts.length > 0) {
|
|
17522
|
+
return;
|
|
17523
|
+
}
|
|
17524
|
+
if (this._address === void 0 || this._chainId === void 0) {
|
|
17525
|
+
throw new Error(
|
|
17526
|
+
"Cannot resolve TinyCloud hosts: no address/chainId available. Sign in or restore a session first."
|
|
17527
|
+
);
|
|
17528
|
+
}
|
|
17529
|
+
await this.resolveTinyCloudHostsForSignIn(this._address, this._chainId);
|
|
17484
17530
|
}
|
|
17485
17531
|
async resolveTinyCloudHostsForSignIn(address, chainId) {
|
|
17486
17532
|
if (this.tinycloudHosts && this.tinycloudHosts.length > 0) {
|
|
17487
17533
|
return;
|
|
17488
17534
|
}
|
|
17489
|
-
const subject = (0,
|
|
17490
|
-
const resolved = await (0,
|
|
17535
|
+
const subject = (0, import_sdk_core2.pkhDid)(address, chainId);
|
|
17536
|
+
const resolved = await (0, import_sdk_core2.resolveTinyCloudHosts)(subject, {
|
|
17491
17537
|
registryUrl: this.tinycloudRegistryUrl,
|
|
17492
17538
|
fallbackHosts: this.tinycloudFallbackHosts
|
|
17493
17539
|
});
|
|
@@ -17505,6 +17551,9 @@ var NodeUserAuthorization = class {
|
|
|
17505
17551
|
get nodeFeatures() {
|
|
17506
17552
|
return this._nodeFeatures;
|
|
17507
17553
|
}
|
|
17554
|
+
get lastActivationSkippedSpaceIds() {
|
|
17555
|
+
return [...this._lastActivationSkippedSpaceIds];
|
|
17556
|
+
}
|
|
17508
17557
|
/**
|
|
17509
17558
|
* Compute the `abilities` map the WASM `prepareSession` call should
|
|
17510
17559
|
* see at sign-in time.
|
|
@@ -17538,7 +17587,7 @@ var NodeUserAuthorization = class {
|
|
|
17538
17587
|
if (this._manifest === void 0) {
|
|
17539
17588
|
return void 0;
|
|
17540
17589
|
}
|
|
17541
|
-
this._capabilityRequest = (0,
|
|
17590
|
+
this._capabilityRequest = (0, import_sdk_core2.composeManifestRequest)(
|
|
17542
17591
|
Array.isArray(this._manifest) ? this._manifest : [this._manifest],
|
|
17543
17592
|
{
|
|
17544
17593
|
includeAccountRegistryPermissions: this.includeAccountRegistryPermissions
|
|
@@ -17550,17 +17599,17 @@ var NodeUserAuthorization = class {
|
|
|
17550
17599
|
if (space.startsWith("tinycloud:")) {
|
|
17551
17600
|
return space;
|
|
17552
17601
|
}
|
|
17553
|
-
return (0,
|
|
17602
|
+
return (0, import_sdk_core2.makePkhSpaceId)(address, chainId, space);
|
|
17554
17603
|
}
|
|
17555
17604
|
defaultEncryptionNetworkId(address, chainId) {
|
|
17556
|
-
return `urn:tinycloud:encryption:${(0,
|
|
17605
|
+
return `urn:tinycloud:encryption:${(0, import_sdk_core2.pkhDid)(address, chainId)}:default`;
|
|
17557
17606
|
}
|
|
17558
17607
|
resolveSignInCapabilities(address, chainId) {
|
|
17559
17608
|
const request = this.getCapabilityRequest();
|
|
17560
17609
|
if (request === void 0) {
|
|
17561
17610
|
const defaultNetworkId = this.defaultEncryptionNetworkId(address, chainId);
|
|
17562
|
-
const primarySpaceId2 = (0,
|
|
17563
|
-
const secretsSpaceId = (0,
|
|
17611
|
+
const primarySpaceId2 = (0, import_sdk_core2.makePkhSpaceId)(address, chainId, this.spacePrefix);
|
|
17612
|
+
const secretsSpaceId = (0, import_sdk_core2.makePkhSpaceId)(address, chainId, "secrets");
|
|
17564
17613
|
return {
|
|
17565
17614
|
abilities: this.defaultActions,
|
|
17566
17615
|
spaceId: primarySpaceId2,
|
|
@@ -17587,35 +17636,35 @@ var NodeUserAuthorization = class {
|
|
|
17587
17636
|
};
|
|
17588
17637
|
}
|
|
17589
17638
|
const rawAbilities = {};
|
|
17590
|
-
const currentDid = (0,
|
|
17639
|
+
const currentDid = (0, import_sdk_core2.pkhDid)(address, chainId);
|
|
17591
17640
|
const spaceResources = request.resources.filter((entry) => {
|
|
17592
|
-
if (entry.service !==
|
|
17641
|
+
if (entry.service !== import_sdk_core2.ENCRYPTION_PERMISSION_SERVICE) {
|
|
17593
17642
|
return true;
|
|
17594
17643
|
}
|
|
17595
17644
|
for (const action of entry.actions) {
|
|
17596
17645
|
addRawAbility(rawAbilities, entry.path, action);
|
|
17597
17646
|
}
|
|
17598
17647
|
if (entry.actions.includes(DECRYPT_ACTION)) {
|
|
17599
|
-
const parsed = (0,
|
|
17648
|
+
const parsed = (0, import_sdk_core2.parseNetworkId)(entry.path);
|
|
17600
17649
|
if (didPrincipalMatches(parsed.ownerDid, currentDid)) {
|
|
17601
17650
|
addRawAbility(rawAbilities, entry.path, NETWORK_CREATE_ACTION);
|
|
17602
17651
|
}
|
|
17603
17652
|
}
|
|
17604
17653
|
return false;
|
|
17605
17654
|
});
|
|
17606
|
-
const primarySpaceName = spaceResources.find((entry) => entry.space !== "account")?.space ??
|
|
17655
|
+
const primarySpaceName = spaceResources.find((entry) => entry.space !== "account")?.space ?? import_sdk_core2.DEFAULT_MANIFEST_SPACE;
|
|
17607
17656
|
const primarySpaceId = this.resolveSpaceName(
|
|
17608
17657
|
primarySpaceName,
|
|
17609
17658
|
address,
|
|
17610
17659
|
chainId
|
|
17611
17660
|
);
|
|
17612
|
-
const bySpace = (0,
|
|
17661
|
+
const bySpace = (0, import_sdk_core2.resourceCapabilitiesToSpaceAbilitiesMap)(spaceResources);
|
|
17613
17662
|
const spaceAbilities = {};
|
|
17614
17663
|
for (const [space, abilities] of Object.entries(bySpace)) {
|
|
17615
17664
|
spaceAbilities[this.resolveSpaceName(space, address, chainId)] = abilities;
|
|
17616
17665
|
}
|
|
17617
17666
|
return {
|
|
17618
|
-
abilities: spaceAbilities[primarySpaceId] ?? (0,
|
|
17667
|
+
abilities: spaceAbilities[primarySpaceId] ?? (0, import_sdk_core2.resourceCapabilitiesToAbilitiesMap)([]),
|
|
17619
17668
|
spaceId: primarySpaceId,
|
|
17620
17669
|
spaceAbilities,
|
|
17621
17670
|
rawAbilities: Object.keys(rawAbilities).length > 0 ? rawAbilities : void 0
|
|
@@ -17677,9 +17726,10 @@ var NodeUserAuthorization = class {
|
|
|
17677
17726
|
if (!this._tinyCloudSession || !this._address || !this._chainId) {
|
|
17678
17727
|
throw new Error("Must be signed in to host space");
|
|
17679
17728
|
}
|
|
17729
|
+
await this.ensureTinyCloudHosts();
|
|
17680
17730
|
const host = this.primaryTinyCloudHost;
|
|
17681
17731
|
const spaceId = targetSpaceId ?? this._tinyCloudSession.spaceId;
|
|
17682
|
-
const peerId = await (0,
|
|
17732
|
+
const peerId = await (0, import_sdk_core2.fetchPeerId)(host, spaceId);
|
|
17683
17733
|
const siwe = this.wasm.generateHostSIWEMessage({
|
|
17684
17734
|
address: this._address,
|
|
17685
17735
|
chainId: this._chainId,
|
|
@@ -17690,7 +17740,7 @@ var NodeUserAuthorization = class {
|
|
|
17690
17740
|
});
|
|
17691
17741
|
const signature2 = await this.signMessage(siwe);
|
|
17692
17742
|
const headers = this.wasm.siweToDelegationHeaders({ siwe, signature: signature2 });
|
|
17693
|
-
const result = await (0,
|
|
17743
|
+
const result = await (0, import_sdk_core2.submitHostDelegation)(host, headers);
|
|
17694
17744
|
return result.success;
|
|
17695
17745
|
}
|
|
17696
17746
|
/**
|
|
@@ -17719,13 +17769,15 @@ var NodeUserAuthorization = class {
|
|
|
17719
17769
|
if (!this._tinyCloudSession) {
|
|
17720
17770
|
throw new Error("Must be signed in to ensure space exists");
|
|
17721
17771
|
}
|
|
17772
|
+
await this.ensureTinyCloudHosts();
|
|
17722
17773
|
const host = this.primaryTinyCloudHost;
|
|
17723
17774
|
const primarySpaceId = this._tinyCloudSession.spaceId;
|
|
17724
|
-
const result = await (0,
|
|
17775
|
+
const result = await (0, import_sdk_core2.activateSessionWithHost)(
|
|
17725
17776
|
host,
|
|
17726
17777
|
this._tinyCloudSession.delegationHeader
|
|
17727
17778
|
);
|
|
17728
|
-
|
|
17779
|
+
this.recordActivationSkippedSpaces(result, primarySpaceId);
|
|
17780
|
+
const handler = this.spaceCreationHandler ?? (this.autoCreateSpace ? new import_sdk_core2.AutoApproveSpaceCreationHandler() : void 0);
|
|
17729
17781
|
const creationContext = {
|
|
17730
17782
|
spaceId: primarySpaceId,
|
|
17731
17783
|
address: this._address,
|
|
@@ -17759,7 +17811,7 @@ var NodeUserAuthorization = class {
|
|
|
17759
17811
|
throw error;
|
|
17760
17812
|
}
|
|
17761
17813
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
17762
|
-
const retryResult = await (0,
|
|
17814
|
+
const retryResult = await (0, import_sdk_core2.activateSessionWithHost)(
|
|
17763
17815
|
host,
|
|
17764
17816
|
this._tinyCloudSession.delegationHeader
|
|
17765
17817
|
);
|
|
@@ -17796,7 +17848,7 @@ var NodeUserAuthorization = class {
|
|
|
17796
17848
|
throw error;
|
|
17797
17849
|
}
|
|
17798
17850
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
17799
|
-
const retryResult = await (0,
|
|
17851
|
+
const retryResult = await (0, import_sdk_core2.activateSessionWithHost)(
|
|
17800
17852
|
host,
|
|
17801
17853
|
this._tinyCloudSession.delegationHeader
|
|
17802
17854
|
);
|
|
@@ -17812,6 +17864,66 @@ var NodeUserAuthorization = class {
|
|
|
17812
17864
|
}
|
|
17813
17865
|
throw new Error(`Failed to activate session: ${result.error}`);
|
|
17814
17866
|
}
|
|
17867
|
+
recordActivationSkippedSpaces(result, primarySpaceId) {
|
|
17868
|
+
if (result.success) {
|
|
17869
|
+
this._lastActivationSkippedSpaceIds = result.skipped ?? [];
|
|
17870
|
+
return;
|
|
17871
|
+
}
|
|
17872
|
+
this._lastActivationSkippedSpaceIds = result.status === 404 ? [primarySpaceId] : [];
|
|
17873
|
+
}
|
|
17874
|
+
async createBootstrapSession(options) {
|
|
17875
|
+
if (!this._address || !this._chainId) {
|
|
17876
|
+
throw new Error("Must be signed in before creating bootstrap sessions");
|
|
17877
|
+
}
|
|
17878
|
+
const address = this._address;
|
|
17879
|
+
const chainId = this._chainId;
|
|
17880
|
+
const keyId = `bootstrap-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
17881
|
+
this.sessionManager.createSessionKey(keyId);
|
|
17882
|
+
const jwkString = this.sessionManager.jwk(keyId);
|
|
17883
|
+
if (!jwkString) {
|
|
17884
|
+
throw new Error("Failed to create bootstrap session key");
|
|
17885
|
+
}
|
|
17886
|
+
const jwk = JSON.parse(jwkString);
|
|
17887
|
+
const now = /* @__PURE__ */ new Date();
|
|
17888
|
+
const expirationTime = new Date(now.getTime() + this.sessionExpirationMs);
|
|
17889
|
+
const abilities = (0, import_sdk_core2.resourceCapabilitiesToAbilitiesMap)(
|
|
17890
|
+
options.capabilityRequest.resources
|
|
17891
|
+
);
|
|
17892
|
+
const prepared = this.wasm.prepareSession({
|
|
17893
|
+
abilities,
|
|
17894
|
+
...options.rawAbilities !== void 0 ? { rawAbilities: options.rawAbilities } : {},
|
|
17895
|
+
address,
|
|
17896
|
+
chainId,
|
|
17897
|
+
domain: this.domain,
|
|
17898
|
+
issuedAt: now.toISOString(),
|
|
17899
|
+
expirationTime: expirationTime.toISOString(),
|
|
17900
|
+
spaceId: options.spaceId,
|
|
17901
|
+
jwk,
|
|
17902
|
+
...this.buildSiweOverrides()
|
|
17903
|
+
});
|
|
17904
|
+
const signature2 = await this.requestSignature({
|
|
17905
|
+
address,
|
|
17906
|
+
chainId,
|
|
17907
|
+
message: prepared.siwe,
|
|
17908
|
+
type: "siwe"
|
|
17909
|
+
});
|
|
17910
|
+
const session = this.wasm.completeSessionSetup({
|
|
17911
|
+
...prepared,
|
|
17912
|
+
signature: signature2
|
|
17913
|
+
});
|
|
17914
|
+
return {
|
|
17915
|
+
address,
|
|
17916
|
+
chainId,
|
|
17917
|
+
sessionKey: keyId,
|
|
17918
|
+
spaceId: options.spaceId,
|
|
17919
|
+
delegationCid: session.delegationCid,
|
|
17920
|
+
delegationHeader: session.delegationHeader,
|
|
17921
|
+
verificationMethod: this.sessionManager.getDID(keyId),
|
|
17922
|
+
jwk,
|
|
17923
|
+
siwe: prepared.siwe,
|
|
17924
|
+
signature: signature2
|
|
17925
|
+
};
|
|
17926
|
+
}
|
|
17815
17927
|
/**
|
|
17816
17928
|
* Sign in and create a new session.
|
|
17817
17929
|
*
|
|
@@ -17824,7 +17936,7 @@ var NodeUserAuthorization = class {
|
|
|
17824
17936
|
* @param options - Optional per-call SIWE overrides for this sign-in only
|
|
17825
17937
|
*/
|
|
17826
17938
|
async signIn(options) {
|
|
17827
|
-
this._address = (0,
|
|
17939
|
+
this._address = (0, import_sdk_core2.canonicalizeAddress)(await this.signer.getAddress());
|
|
17828
17940
|
this._chainId = await this.signer.getChainId();
|
|
17829
17941
|
const address = this._address;
|
|
17830
17942
|
const chainId = this._chainId;
|
|
@@ -17871,7 +17983,7 @@ var NodeUserAuthorization = class {
|
|
|
17871
17983
|
siwe: prepared.siwe,
|
|
17872
17984
|
signature: signature2
|
|
17873
17985
|
};
|
|
17874
|
-
const spacesMetadata = this.enablePublicSpace ? { public: (0,
|
|
17986
|
+
const spacesMetadata = this.enablePublicSpace ? { public: (0, import_sdk_core2.makePkhSpaceId)(address, chainId, "public") } : void 0;
|
|
17875
17987
|
const tinyCloudSession = {
|
|
17876
17988
|
address,
|
|
17877
17989
|
chainId,
|
|
@@ -17900,14 +18012,15 @@ var NodeUserAuthorization = class {
|
|
|
17900
18012
|
},
|
|
17901
18013
|
expiresAt: expirationTime.toISOString(),
|
|
17902
18014
|
createdAt: now.toISOString(),
|
|
17903
|
-
version: "1.0"
|
|
18015
|
+
version: "1.0",
|
|
18016
|
+
tinycloudHosts: this.tinycloudHosts
|
|
17904
18017
|
};
|
|
17905
18018
|
await this.sessionStorage.save(address, persistedData);
|
|
17906
18019
|
this._session = clientSession;
|
|
17907
18020
|
this._tinyCloudSession = tinyCloudSession;
|
|
17908
18021
|
this._address = address;
|
|
17909
18022
|
this._chainId = chainId;
|
|
17910
|
-
const nodeInfo = await (0,
|
|
18023
|
+
const nodeInfo = await (0, import_sdk_core2.checkNodeInfo)(
|
|
17911
18024
|
this.primaryTinyCloudHost,
|
|
17912
18025
|
this.wasm.protocolVersion()
|
|
17913
18026
|
);
|
|
@@ -17946,7 +18059,7 @@ var NodeUserAuthorization = class {
|
|
|
17946
18059
|
*/
|
|
17947
18060
|
async signMessage(message) {
|
|
17948
18061
|
if (!this._address) {
|
|
17949
|
-
this._address = (0,
|
|
18062
|
+
this._address = (0, import_sdk_core2.canonicalizeAddress)(await this.signer.getAddress());
|
|
17950
18063
|
}
|
|
17951
18064
|
if (!this._chainId) {
|
|
17952
18065
|
this._chainId = await this.signer.getChainId();
|
|
@@ -17973,7 +18086,7 @@ var NodeUserAuthorization = class {
|
|
|
17973
18086
|
* ```
|
|
17974
18087
|
*/
|
|
17975
18088
|
async prepareSessionForSigning() {
|
|
17976
|
-
const address = (0,
|
|
18089
|
+
const address = (0, import_sdk_core2.canonicalizeAddress)(await this.signer.getAddress());
|
|
17977
18090
|
const chainId = await this.signer.getChainId();
|
|
17978
18091
|
const keyId = `session-${Date.now()}`;
|
|
17979
18092
|
this.sessionManager.renameSessionKeyId("default", keyId);
|
|
@@ -18023,7 +18136,7 @@ var NodeUserAuthorization = class {
|
|
|
18023
18136
|
...prepared,
|
|
18024
18137
|
signature: signature2
|
|
18025
18138
|
});
|
|
18026
|
-
const address = (0,
|
|
18139
|
+
const address = (0, import_sdk_core2.canonicalizeAddress)(await this.signer.getAddress());
|
|
18027
18140
|
const chainId = await this.signer.getChainId();
|
|
18028
18141
|
await this.resolveTinyCloudHostsForSignIn(address, chainId);
|
|
18029
18142
|
const clientSession = {
|
|
@@ -18034,7 +18147,7 @@ var NodeUserAuthorization = class {
|
|
|
18034
18147
|
siwe: prepared.siwe,
|
|
18035
18148
|
signature: signature2
|
|
18036
18149
|
};
|
|
18037
|
-
const spacesMetadata = this.enablePublicSpace ? { public: (0,
|
|
18150
|
+
const spacesMetadata = this.enablePublicSpace ? { public: (0, import_sdk_core2.makePkhSpaceId)(address, chainId, "public") } : void 0;
|
|
18038
18151
|
const tinyCloudSession = {
|
|
18039
18152
|
address,
|
|
18040
18153
|
chainId,
|
|
@@ -18067,14 +18180,15 @@ var NodeUserAuthorization = class {
|
|
|
18067
18180
|
},
|
|
18068
18181
|
expiresAt,
|
|
18069
18182
|
createdAt,
|
|
18070
|
-
version: "1.0"
|
|
18183
|
+
version: "1.0",
|
|
18184
|
+
tinycloudHosts: this.tinycloudHosts
|
|
18071
18185
|
};
|
|
18072
18186
|
await this.sessionStorage.save(address, persistedData);
|
|
18073
18187
|
this._session = clientSession;
|
|
18074
18188
|
this._tinyCloudSession = tinyCloudSession;
|
|
18075
18189
|
this._address = address;
|
|
18076
18190
|
this._chainId = chainId;
|
|
18077
|
-
const nodeInfo = await (0,
|
|
18191
|
+
const nodeInfo = await (0, import_sdk_core2.checkNodeInfo)(
|
|
18078
18192
|
this.primaryTinyCloudHost,
|
|
18079
18193
|
this.wasm.protocolVersion()
|
|
18080
18194
|
);
|
|
@@ -18158,32 +18272,33 @@ var NodeUserAuthorization = class {
|
|
|
18158
18272
|
};
|
|
18159
18273
|
|
|
18160
18274
|
// src/account/AccountService.ts
|
|
18161
|
-
var
|
|
18275
|
+
var import_sdk_core3 = require("@tinycloud/sdk-core");
|
|
18162
18276
|
|
|
18163
18277
|
// src/DelegatedAccess.ts
|
|
18164
|
-
var
|
|
18278
|
+
var import_sdk_core4 = require("@tinycloud/sdk-core");
|
|
18165
18279
|
var DelegatedAccess = class {
|
|
18166
|
-
constructor(session, delegation, host, invoke2, telemetry) {
|
|
18280
|
+
constructor(session, delegation, host, invoke2, invokeAny2, telemetry) {
|
|
18167
18281
|
this.session = session;
|
|
18168
18282
|
this._delegation = delegation;
|
|
18169
18283
|
this.host = host;
|
|
18170
|
-
this._serviceContext = new
|
|
18284
|
+
this._serviceContext = new import_sdk_core4.ServiceContext({
|
|
18171
18285
|
invoke: invoke2,
|
|
18286
|
+
invokeAny: invokeAny2,
|
|
18172
18287
|
fetch: globalThis.fetch.bind(globalThis),
|
|
18173
18288
|
hosts: [host],
|
|
18174
18289
|
telemetry
|
|
18175
18290
|
});
|
|
18176
18291
|
const prefix = this._delegation.path.replace(/\/$/, "");
|
|
18177
|
-
this._kv = new
|
|
18292
|
+
this._kv = new import_sdk_core4.KVService({ prefix });
|
|
18178
18293
|
this._kv.initialize(this._serviceContext);
|
|
18179
18294
|
this._serviceContext.registerService("kv", this._kv);
|
|
18180
|
-
this._sql = new
|
|
18295
|
+
this._sql = new import_sdk_core4.SQLService({});
|
|
18181
18296
|
this._sql.initialize(this._serviceContext);
|
|
18182
18297
|
this._serviceContext.registerService("sql", this._sql);
|
|
18183
|
-
this._duckdb = new
|
|
18298
|
+
this._duckdb = new import_sdk_core4.DuckDbService({});
|
|
18184
18299
|
this._duckdb.initialize(this._serviceContext);
|
|
18185
18300
|
this._serviceContext.registerService("duckdb", this._duckdb);
|
|
18186
|
-
this._hooks = new
|
|
18301
|
+
this._hooks = new import_sdk_core4.HooksService({});
|
|
18187
18302
|
this._hooks.initialize(this._serviceContext);
|
|
18188
18303
|
this._serviceContext.registerService("hooks", this._hooks);
|
|
18189
18304
|
const serviceSession = {
|
|
@@ -18333,7 +18448,7 @@ function createWasmKeyProvider(sessionManager) {
|
|
|
18333
18448
|
}
|
|
18334
18449
|
|
|
18335
18450
|
// src/delegateToHelpers.ts
|
|
18336
|
-
var
|
|
18451
|
+
var import_sdk_core5 = require("@tinycloud/sdk-core");
|
|
18337
18452
|
function legacyParamsToPermissionEntries(actions, path, spaceIdOverride) {
|
|
18338
18453
|
const byService = /* @__PURE__ */ new Map();
|
|
18339
18454
|
for (const a of actions) {
|
|
@@ -18364,7 +18479,7 @@ function legacyParamsToPermissionEntries(actions, path, spaceIdOverride) {
|
|
|
18364
18479
|
}
|
|
18365
18480
|
return entries;
|
|
18366
18481
|
}
|
|
18367
|
-
var DEFAULT_DELEGATION_EXPIRY_MS =
|
|
18482
|
+
var DEFAULT_DELEGATION_EXPIRY_MS = import_sdk_core5.EXPIRY.SESSION_MS;
|
|
18368
18483
|
function resolveExpiryMs(expiry) {
|
|
18369
18484
|
if (expiry === void 0) {
|
|
18370
18485
|
return DEFAULT_DELEGATION_EXPIRY_MS;
|
|
@@ -18377,10 +18492,10 @@ function resolveExpiryMs(expiry) {
|
|
|
18377
18492
|
}
|
|
18378
18493
|
return expiry;
|
|
18379
18494
|
}
|
|
18380
|
-
return (0,
|
|
18495
|
+
return (0, import_sdk_core5.parseExpiry)(expiry);
|
|
18381
18496
|
}
|
|
18382
18497
|
function extractSiweExpiration(siwe) {
|
|
18383
|
-
const parsed = new
|
|
18498
|
+
const parsed = new import_sdk_core5.SiweMessage(siwe);
|
|
18384
18499
|
if (parsed.expirationTime === void 0 || parsed.expirationTime === null) {
|
|
18385
18500
|
return void 0;
|
|
18386
18501
|
}
|
|
@@ -18394,7 +18509,7 @@ function extractSiweExpiration(siwe) {
|
|
|
18394
18509
|
}
|
|
18395
18510
|
|
|
18396
18511
|
// src/NodeSecretsService.ts
|
|
18397
|
-
var
|
|
18512
|
+
var import_sdk_core6 = require("@tinycloud/sdk-core");
|
|
18398
18513
|
var SECRETS_SPACE = "secrets";
|
|
18399
18514
|
function ok() {
|
|
18400
18515
|
return { ok: true, data: void 0 };
|
|
@@ -18427,7 +18542,7 @@ function secretActionName(action) {
|
|
|
18427
18542
|
}
|
|
18428
18543
|
function secretPermissionEntries(name, options, action, encryptionNetworkId) {
|
|
18429
18544
|
const entries = [];
|
|
18430
|
-
const path = action === "list" ? (0,
|
|
18545
|
+
const path = action === "list" ? (0, import_sdk_core6.resolveSecretListPrefix)(options) : (0, import_sdk_core6.resolveSecretPath)(name, options).permissionPaths.vault;
|
|
18431
18546
|
entries.push({
|
|
18432
18547
|
service: "tinycloud.kv",
|
|
18433
18548
|
space: SECRETS_SPACE,
|
|
@@ -18506,7 +18621,7 @@ var NodeSecretsService = class {
|
|
|
18506
18621
|
);
|
|
18507
18622
|
} catch (error) {
|
|
18508
18623
|
return secretsError(
|
|
18509
|
-
|
|
18624
|
+
import_sdk_core6.ErrorCodes.INVALID_INPUT,
|
|
18510
18625
|
error instanceof Error ? error.message : String(error),
|
|
18511
18626
|
error instanceof Error ? error : void 0
|
|
18512
18627
|
);
|
|
@@ -18516,7 +18631,7 @@ var NodeSecretsService = class {
|
|
|
18516
18631
|
}
|
|
18517
18632
|
if (!this.config.canEscalate()) {
|
|
18518
18633
|
return secretsError(
|
|
18519
|
-
|
|
18634
|
+
import_sdk_core6.ErrorCodes.PERMISSION_DENIED,
|
|
18520
18635
|
`Cannot autosign ${displayActionUrn(action)} for ${target}; TinyCloudNode needs wallet mode with a signer or privateKey.`
|
|
18521
18636
|
);
|
|
18522
18637
|
}
|
|
@@ -18525,7 +18640,7 @@ var NodeSecretsService = class {
|
|
|
18525
18640
|
return this.restoreUnlockAfterEscalation();
|
|
18526
18641
|
} catch (error) {
|
|
18527
18642
|
return secretsError(
|
|
18528
|
-
|
|
18643
|
+
import_sdk_core6.ErrorCodes.PERMISSION_DENIED,
|
|
18529
18644
|
error instanceof Error ? error.message : `Autosign escalation for ${displayActionUrn(action)} on ${target} failed.`,
|
|
18530
18645
|
error instanceof Error ? error : void 0
|
|
18531
18646
|
);
|
|
@@ -18546,10 +18661,10 @@ var NodeSecretsService = class {
|
|
|
18546
18661
|
return false;
|
|
18547
18662
|
}
|
|
18548
18663
|
const manifests = Array.isArray(manifest) ? manifest : [manifest];
|
|
18549
|
-
const requestedEntries = (0,
|
|
18664
|
+
const requestedEntries = (0, import_sdk_core6.expandPermissionEntries)(permissionEntries);
|
|
18550
18665
|
return requestedEntries.every(
|
|
18551
18666
|
(entry) => manifests.some((candidate) => {
|
|
18552
|
-
const resolved = (0,
|
|
18667
|
+
const resolved = (0, import_sdk_core6.resolveManifest)(candidate);
|
|
18553
18668
|
return resolved.resources.some(
|
|
18554
18669
|
(resource) => resource.service === entry.service && resource.space === entry.space && resource.path === entry.path && entry.actions.every((action) => resource.actions.includes(action))
|
|
18555
18670
|
);
|
|
@@ -18564,10 +18679,13 @@ var DEFAULT_ENCRYPTION_NETWORK_NAME = "default";
|
|
|
18564
18679
|
var NETWORK_CREATE_ACTION2 = "tinycloud.encryption/network.create";
|
|
18565
18680
|
var DECRYPT_ACTION2 = "tinycloud.encryption/decrypt";
|
|
18566
18681
|
var NETWORK_ADMIN_TYPE = "tinycloud.encryption.network-admin/v1";
|
|
18567
|
-
var DEFAULT_SESSION_EXPIRATION_MS =
|
|
18682
|
+
var DEFAULT_SESSION_EXPIRATION_MS = import_sdk_core7.EXPIRY.SESSION_MS;
|
|
18683
|
+
function isOpenKeyAutoSignStrategy(strategy) {
|
|
18684
|
+
return strategy?.openKeyAutoSign === true;
|
|
18685
|
+
}
|
|
18568
18686
|
function didPrincipalMatches2(actual, expected) {
|
|
18569
18687
|
try {
|
|
18570
|
-
return (0,
|
|
18688
|
+
return (0, import_sdk_core7.principalDidEquals)(actual, expected);
|
|
18571
18689
|
} catch {
|
|
18572
18690
|
return actual === expected;
|
|
18573
18691
|
}
|
|
@@ -18733,12 +18851,12 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18733
18851
|
throw new Error("Failed to get session key JWK");
|
|
18734
18852
|
}
|
|
18735
18853
|
this.sessionKeyJwk = JSON.parse(jwkStr);
|
|
18736
|
-
this._capabilityRegistry = new
|
|
18854
|
+
this._capabilityRegistry = new import_sdk_core7.CapabilityKeyRegistry();
|
|
18737
18855
|
this._keyProvider = new WasmKeyProvider({
|
|
18738
18856
|
sessionManager: this.sessionManager
|
|
18739
18857
|
});
|
|
18740
|
-
this.notificationHandler = config.notificationHandler ?? new
|
|
18741
|
-
this._sharingService = new
|
|
18858
|
+
this.notificationHandler = config.notificationHandler ?? new import_sdk_core7.SilentNotificationHandler();
|
|
18859
|
+
this._sharingService = new import_sdk_core7.SharingService({
|
|
18742
18860
|
hosts: [this.config.host],
|
|
18743
18861
|
// session: undefined - not needed for receive()
|
|
18744
18862
|
invoke: this.invokeWithRuntimePermissions,
|
|
@@ -18748,8 +18866,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18748
18866
|
// delegationManager: undefined - not needed for receive()
|
|
18749
18867
|
createKVService: (config2) => {
|
|
18750
18868
|
const prefix = config2.pathPrefix?.replace(/\/$/, "");
|
|
18751
|
-
const kvService = new
|
|
18752
|
-
const kvContext = new
|
|
18869
|
+
const kvService = new import_sdk_core7.KVService({ prefix });
|
|
18870
|
+
const kvContext = new import_sdk_core7.ServiceContext({
|
|
18753
18871
|
invoke: config2.invoke,
|
|
18754
18872
|
fetch: config2.fetch ?? globalThis.fetch.bind(globalThis),
|
|
18755
18873
|
hosts: config2.hosts,
|
|
@@ -18789,9 +18907,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18789
18907
|
* @internal
|
|
18790
18908
|
*/
|
|
18791
18909
|
setupAuth(config) {
|
|
18910
|
+
const useBootstrapSignInRequest = this.shouldUseBootstrapSignInRequest(config);
|
|
18792
18911
|
this.auth = new NodeUserAuthorization({
|
|
18793
18912
|
signer: this.signer,
|
|
18794
|
-
signStrategy: { type: "auto-sign" },
|
|
18913
|
+
signStrategy: config.signStrategy ?? { type: "auto-sign" },
|
|
18795
18914
|
wasmBindings: this.wasmBindings,
|
|
18796
18915
|
sessionStorage: config.sessionStorage ?? new MemorySessionStorage(),
|
|
18797
18916
|
domain: this.siweDomain,
|
|
@@ -18800,20 +18919,23 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18800
18919
|
tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
|
|
18801
18920
|
tinycloudRegistryUrl: config.tinycloudRegistryUrl,
|
|
18802
18921
|
tinycloudFallbackHosts: config.tinycloudFallbackHosts,
|
|
18803
|
-
autoCreateSpace: config.autoCreateSpace,
|
|
18922
|
+
autoCreateSpace: useBootstrapSignInRequest ? false : config.autoCreateSpace,
|
|
18804
18923
|
enablePublicSpace: config.enablePublicSpace ?? true,
|
|
18805
|
-
spaceCreationHandler: config.spaceCreationHandler,
|
|
18924
|
+
spaceCreationHandler: useBootstrapSignInRequest ? void 0 : config.spaceCreationHandler,
|
|
18806
18925
|
nonce: config.nonce,
|
|
18807
18926
|
siweConfig: config.siweConfig,
|
|
18808
|
-
manifest: config.manifest,
|
|
18809
|
-
capabilityRequest: config.capabilityRequest,
|
|
18810
|
-
includeAccountRegistryPermissions: config.includeAccountRegistryPermissions
|
|
18927
|
+
manifest: useBootstrapSignInRequest ? void 0 : config.manifest,
|
|
18928
|
+
capabilityRequest: useBootstrapSignInRequest ? import_sdk_core7.BOOTSTRAP_SESSION_REQUESTS.default : config.capabilityRequest,
|
|
18929
|
+
includeAccountRegistryPermissions: useBootstrapSignInRequest ? false : config.includeAccountRegistryPermissions
|
|
18811
18930
|
});
|
|
18812
|
-
this.tc = new
|
|
18931
|
+
this.tc = new import_sdk_core7.TinyCloud(this.auth, {
|
|
18813
18932
|
invokeAny: this.invokeAnyWithRuntimePermissions,
|
|
18814
18933
|
telemetry: config.telemetry
|
|
18815
18934
|
});
|
|
18816
18935
|
}
|
|
18936
|
+
shouldUseBootstrapSignInRequest(config) {
|
|
18937
|
+
return config.autoBootstrapAccount !== false && config.manifest === void 0 && config.capabilityRequest === void 0 && (config.prefix ?? "default") === "default" && isOpenKeyAutoSignStrategy(config.signStrategy);
|
|
18938
|
+
}
|
|
18817
18939
|
syncResolvedHostFromAuth() {
|
|
18818
18940
|
const host = this.auth?.hosts[0];
|
|
18819
18941
|
if (host) {
|
|
@@ -18870,7 +18992,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18870
18992
|
*/
|
|
18871
18993
|
get did() {
|
|
18872
18994
|
if (this._address) {
|
|
18873
|
-
return (0,
|
|
18995
|
+
return (0, import_sdk_core7.pkhDid)(this._address, this._chainId);
|
|
18874
18996
|
}
|
|
18875
18997
|
return this.sessionManager.getDID(this.sessionKeyId);
|
|
18876
18998
|
}
|
|
@@ -18912,14 +19034,14 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18912
19034
|
if (!this._address) {
|
|
18913
19035
|
return void 0;
|
|
18914
19036
|
}
|
|
18915
|
-
return this.wasmBindings.makeSpaceId(this._address, this._chainId,
|
|
19037
|
+
return this.wasmBindings.makeSpaceId(this._address, this._chainId, import_sdk_core7.ACCOUNT_REGISTRY_SPACE);
|
|
18916
19038
|
}
|
|
18917
19039
|
/**
|
|
18918
19040
|
* Account-level application and delegation helpers.
|
|
18919
19041
|
*/
|
|
18920
19042
|
get account() {
|
|
18921
19043
|
if (!this._account) {
|
|
18922
|
-
this._account = new
|
|
19044
|
+
this._account = new import_sdk_core3.AccountService({
|
|
18923
19045
|
getDid: () => this.did,
|
|
18924
19046
|
getHost: () => this.hosts[0] ?? this.config.host,
|
|
18925
19047
|
getPrimarySpaceId: () => this.spaceId,
|
|
@@ -18928,7 +19050,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18928
19050
|
getAccountDb: () => this.accountSpaceId ? this.sqlForSpace(this.accountSpaceId).db("account") : void 0,
|
|
18929
19051
|
ensureAccountSpaceHosted: async () => {
|
|
18930
19052
|
if (this.accountSpaceId && this.auth) {
|
|
18931
|
-
await this.
|
|
19053
|
+
await this.ensureOwnedSpaceHostedById(this.accountSpaceId);
|
|
18932
19054
|
}
|
|
18933
19055
|
}
|
|
18934
19056
|
});
|
|
@@ -18956,7 +19078,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18956
19078
|
);
|
|
18957
19079
|
}
|
|
18958
19080
|
await this.wasmBindings.ensureInitialized?.();
|
|
18959
|
-
this._address = (0,
|
|
19081
|
+
this._address = (0, import_sdk_core7.canonicalizeAddress)(await this.signer.getAddress());
|
|
18960
19082
|
this._chainId = await this.signer.getChainId();
|
|
18961
19083
|
this._kv = void 0;
|
|
18962
19084
|
this._sql = void 0;
|
|
@@ -18972,11 +19094,14 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18972
19094
|
await this.tc.signIn(options);
|
|
18973
19095
|
this.syncResolvedHostFromAuth();
|
|
18974
19096
|
this.initializeServices();
|
|
19097
|
+
const bootstrapped = await this.bootstrapAccountIfNeeded();
|
|
18975
19098
|
await this.ensureRequestedEncryptionNetworks();
|
|
18976
|
-
if (this.config.manifest === void 0 && this.config.capabilityRequest === void 0) {
|
|
18977
|
-
await this.
|
|
19099
|
+
if (!bootstrapped && this.config.manifest === void 0 && this.config.capabilityRequest === void 0) {
|
|
19100
|
+
await this.ensureOwnedSpaceHostedById(this.ownedSpaceId(import_sdk_core7.SECRETS_SPACE));
|
|
19101
|
+
}
|
|
19102
|
+
if (!bootstrapped) {
|
|
19103
|
+
this.scheduleAccountRegistrySync();
|
|
18978
19104
|
}
|
|
18979
|
-
this.scheduleAccountRegistrySync();
|
|
18980
19105
|
this.notificationHandler.success("Successfully signed in");
|
|
18981
19106
|
}
|
|
18982
19107
|
ownedSpaceId(name) {
|
|
@@ -18985,6 +19110,208 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18985
19110
|
}
|
|
18986
19111
|
return this.wasmBindings.makeSpaceId(this._address, this._chainId, name);
|
|
18987
19112
|
}
|
|
19113
|
+
async bootstrapAccountIfNeeded() {
|
|
19114
|
+
if (this.config.autoBootstrapAccount === false) {
|
|
19115
|
+
return false;
|
|
19116
|
+
}
|
|
19117
|
+
if (!this.auth || !this._address) {
|
|
19118
|
+
return false;
|
|
19119
|
+
}
|
|
19120
|
+
const steps = (0, import_sdk_core7.bootstrapSteps)(this._address, this._chainId);
|
|
19121
|
+
if (!await this.isFreshBootstrapAccount(steps)) {
|
|
19122
|
+
return false;
|
|
19123
|
+
}
|
|
19124
|
+
await this.runAccountBootstrap(steps);
|
|
19125
|
+
return true;
|
|
19126
|
+
}
|
|
19127
|
+
async isFreshBootstrapAccount(steps) {
|
|
19128
|
+
const enshrinedSpaceIds = /* @__PURE__ */ new Set();
|
|
19129
|
+
for (const step of steps) {
|
|
19130
|
+
if (step.kind === "session") {
|
|
19131
|
+
enshrinedSpaceIds.add(step.spaceId);
|
|
19132
|
+
}
|
|
19133
|
+
}
|
|
19134
|
+
const skipped = this.auth.lastActivationSkippedSpaceIds;
|
|
19135
|
+
if (skipped.some((spaceId) => enshrinedSpaceIds.has(spaceId))) {
|
|
19136
|
+
return true;
|
|
19137
|
+
}
|
|
19138
|
+
try {
|
|
19139
|
+
const indexed = await this.account.index.spaces.list();
|
|
19140
|
+
if (indexed.ok && indexed.data.length === 0) {
|
|
19141
|
+
return true;
|
|
19142
|
+
}
|
|
19143
|
+
} catch {
|
|
19144
|
+
}
|
|
19145
|
+
try {
|
|
19146
|
+
const spaces = await this.account.spaces.list();
|
|
19147
|
+
return spaces.ok && spaces.data.length === 0;
|
|
19148
|
+
} catch {
|
|
19149
|
+
return false;
|
|
19150
|
+
}
|
|
19151
|
+
}
|
|
19152
|
+
async runAccountBootstrap(steps) {
|
|
19153
|
+
if (!this.auth || !this._address) {
|
|
19154
|
+
throw new Error("Account bootstrap requires an active wallet session");
|
|
19155
|
+
}
|
|
19156
|
+
const host = this.hosts[0] ?? this.config.host;
|
|
19157
|
+
if (!host) {
|
|
19158
|
+
throw new Error("Account bootstrap requires a TinyCloud host");
|
|
19159
|
+
}
|
|
19160
|
+
const auth = this.auth;
|
|
19161
|
+
const sessions = /* @__PURE__ */ new Map();
|
|
19162
|
+
const rawAbilitiesBySpace = /* @__PURE__ */ new Map();
|
|
19163
|
+
const primarySession = auth.tinyCloudSession;
|
|
19164
|
+
const defaultSpaceId = this.ownedSpaceId("default");
|
|
19165
|
+
const canReusePrimaryBootstrapSession = primarySession?.spaceId === defaultSpaceId && auth.capabilityRequest === import_sdk_core7.BOOTSTRAP_SESSION_REQUESTS.default;
|
|
19166
|
+
for (const step of steps) {
|
|
19167
|
+
if (step.kind !== "session") continue;
|
|
19168
|
+
if (step.space === "default" && canReusePrimaryBootstrapSession && primarySession) {
|
|
19169
|
+
sessions.set(step.space, primarySession);
|
|
19170
|
+
continue;
|
|
19171
|
+
}
|
|
19172
|
+
const rawAbilities = step.rawAbilities;
|
|
19173
|
+
if (rawAbilities) {
|
|
19174
|
+
rawAbilitiesBySpace.set(step.space, rawAbilities);
|
|
19175
|
+
}
|
|
19176
|
+
const session = await auth.createBootstrapSession({
|
|
19177
|
+
spaceId: step.spaceId,
|
|
19178
|
+
capabilityRequest: step.request ?? import_sdk_core7.BOOTSTRAP_SESSION_REQUESTS[step.space],
|
|
19179
|
+
rawAbilities
|
|
19180
|
+
});
|
|
19181
|
+
sessions.set(step.space, session);
|
|
19182
|
+
}
|
|
19183
|
+
for (const step of steps) {
|
|
19184
|
+
if (step.kind !== "host") continue;
|
|
19185
|
+
const hosted = await auth.hostOwnedSpace(step.spaceId);
|
|
19186
|
+
if (!hosted) {
|
|
19187
|
+
throw new Error(`Failed to host bootstrap space: ${step.spaceId}`);
|
|
19188
|
+
}
|
|
19189
|
+
}
|
|
19190
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
19191
|
+
for (const step of steps) {
|
|
19192
|
+
if (step.kind !== "activate") continue;
|
|
19193
|
+
const session = sessions.get(step.space);
|
|
19194
|
+
if (!session) {
|
|
19195
|
+
throw new Error(`Missing bootstrap session for ${step.space}`);
|
|
19196
|
+
}
|
|
19197
|
+
const activated = await (0, import_sdk_core7.activateSessionWithHost)(host, session.delegationHeader);
|
|
19198
|
+
if (!activated.success || activated.skipped?.includes(step.spaceId)) {
|
|
19199
|
+
throw new Error(
|
|
19200
|
+
`Failed to activate bootstrap session for ${step.spaceId}: ${activated.error ?? "space was skipped"}`
|
|
19201
|
+
);
|
|
19202
|
+
}
|
|
19203
|
+
this.registerBootstrapRuntimeGrant(
|
|
19204
|
+
session,
|
|
19205
|
+
import_sdk_core7.BOOTSTRAP_SESSION_REQUESTS[step.space],
|
|
19206
|
+
rawAbilitiesBySpace.get(step.space)
|
|
19207
|
+
);
|
|
19208
|
+
}
|
|
19209
|
+
for (const step of steps) {
|
|
19210
|
+
if (step.kind === "account-index-schema") {
|
|
19211
|
+
const ensured = await this.account.index.ensure();
|
|
19212
|
+
if (!ensured.ok) {
|
|
19213
|
+
throw new Error(`Failed to create account index schema: ${ensured.error.message}`);
|
|
19214
|
+
}
|
|
19215
|
+
}
|
|
19216
|
+
if (step.kind === "seed-spaces") {
|
|
19217
|
+
for (const space of step.spaces) {
|
|
19218
|
+
const registered = await this.account.spaces.register({
|
|
19219
|
+
spaceId: space.spaceId,
|
|
19220
|
+
name: space.name,
|
|
19221
|
+
ownerDid: this.did,
|
|
19222
|
+
type: "owned",
|
|
19223
|
+
permissions: ["*"],
|
|
19224
|
+
status: "active"
|
|
19225
|
+
});
|
|
19226
|
+
if (!registered.ok) {
|
|
19227
|
+
throw new Error(
|
|
19228
|
+
`Failed to seed account space ${space.spaceId}: ${registered.error.message}`
|
|
19229
|
+
);
|
|
19230
|
+
}
|
|
19231
|
+
}
|
|
19232
|
+
}
|
|
19233
|
+
if (step.kind === "seed-applications") {
|
|
19234
|
+
const registered = await this.account.applications.register(
|
|
19235
|
+
step.manifests.length > 0 ? [...step.manifests] : import_sdk_core7.TINYCLOUD_SECRETS_BOOTSTRAP_MANIFEST
|
|
19236
|
+
);
|
|
19237
|
+
if (!registered.ok) {
|
|
19238
|
+
throw new Error(`Failed to seed bootstrap applications: ${registered.error.message}`);
|
|
19239
|
+
}
|
|
19240
|
+
}
|
|
19241
|
+
if (step.kind === "encryption-network-create") {
|
|
19242
|
+
await this.ensureEncryptionNetwork(step.networkId);
|
|
19243
|
+
}
|
|
19244
|
+
if (step.kind === "secret-records-schema") {
|
|
19245
|
+
const db = this.sqlForSpace(step.spaceId).db(step.database);
|
|
19246
|
+
const migrated = await db.migrations.apply({
|
|
19247
|
+
namespace: "tinycloud.secrets.records",
|
|
19248
|
+
migrations: [
|
|
19249
|
+
{
|
|
19250
|
+
id: "001_initial",
|
|
19251
|
+
sql: [...import_sdk_core7.SECRET_RECORDS_SCHEMA]
|
|
19252
|
+
}
|
|
19253
|
+
]
|
|
19254
|
+
});
|
|
19255
|
+
if (!migrated.ok) {
|
|
19256
|
+
throw new Error(
|
|
19257
|
+
`Failed to create secret_records schema: ${migrated.error.message}`
|
|
19258
|
+
);
|
|
19259
|
+
}
|
|
19260
|
+
}
|
|
19261
|
+
}
|
|
19262
|
+
}
|
|
19263
|
+
registerBootstrapRuntimeGrant(session, request, rawAbilities) {
|
|
19264
|
+
const operations = [];
|
|
19265
|
+
for (const resource of request.resources) {
|
|
19266
|
+
const service = resource.service.startsWith("tinycloud.") ? this.shortServiceName(resource.service) : resource.service;
|
|
19267
|
+
const spaceId = resource.space.startsWith("tinycloud:") ? resource.space : this.ownedSpaceId(resource.space);
|
|
19268
|
+
for (const action of resource.actions) {
|
|
19269
|
+
operations.push({
|
|
19270
|
+
spaceId,
|
|
19271
|
+
service,
|
|
19272
|
+
path: resource.path,
|
|
19273
|
+
action
|
|
19274
|
+
});
|
|
19275
|
+
}
|
|
19276
|
+
}
|
|
19277
|
+
for (const [resource, actions2] of Object.entries(rawAbilities ?? {})) {
|
|
19278
|
+
for (const action of actions2) {
|
|
19279
|
+
operations.push({
|
|
19280
|
+
resource,
|
|
19281
|
+
service: "encryption",
|
|
19282
|
+
path: resource,
|
|
19283
|
+
action
|
|
19284
|
+
});
|
|
19285
|
+
}
|
|
19286
|
+
}
|
|
19287
|
+
const expiresAt = extractSiweExpiration(session.siwe) ?? this.getSessionExpiry();
|
|
19288
|
+
const actions = [...new Set(operations.map((operation) => operation.action))];
|
|
19289
|
+
this.runtimePermissionGrants.push({
|
|
19290
|
+
session: {
|
|
19291
|
+
delegationHeader: session.delegationHeader,
|
|
19292
|
+
delegationCid: session.delegationCid,
|
|
19293
|
+
spaceId: session.spaceId,
|
|
19294
|
+
verificationMethod: session.verificationMethod,
|
|
19295
|
+
jwk: session.jwk
|
|
19296
|
+
},
|
|
19297
|
+
delegation: {
|
|
19298
|
+
cid: session.delegationCid,
|
|
19299
|
+
delegationHeader: session.delegationHeader,
|
|
19300
|
+
delegateDID: session.verificationMethod,
|
|
19301
|
+
delegatorDID: this.did,
|
|
19302
|
+
spaceId: session.spaceId,
|
|
19303
|
+
path: "",
|
|
19304
|
+
actions,
|
|
19305
|
+
expiry: expiresAt,
|
|
19306
|
+
allowSubDelegation: true,
|
|
19307
|
+
ownerAddress: session.address,
|
|
19308
|
+
chainId: session.chainId,
|
|
19309
|
+
host: this.config.host
|
|
19310
|
+
},
|
|
19311
|
+
operations,
|
|
19312
|
+
expiresAt
|
|
19313
|
+
});
|
|
19314
|
+
}
|
|
18988
19315
|
async writeManifestRegistryRecords() {
|
|
18989
19316
|
const request = this.capabilityRequest;
|
|
18990
19317
|
if (!request || request.registryRecords.length === 0) {
|
|
@@ -18993,8 +19320,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18993
19320
|
if (!this.auth || !this.signer) {
|
|
18994
19321
|
throw new Error("Manifest registry write requires wallet mode");
|
|
18995
19322
|
}
|
|
18996
|
-
const accountSpaceId = this.ownedSpaceId(
|
|
18997
|
-
await this.
|
|
19323
|
+
const accountSpaceId = this.ownedSpaceId(import_sdk_core7.ACCOUNT_REGISTRY_SPACE);
|
|
19324
|
+
await this.ensureOwnedSpaceHostedById(accountSpaceId);
|
|
18998
19325
|
const result = await this.account.applications.register(request.manifests);
|
|
18999
19326
|
if (!result.ok) {
|
|
19000
19327
|
throw new Error(
|
|
@@ -19004,6 +19331,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19004
19331
|
}
|
|
19005
19332
|
scheduleAccountRegistrySync() {
|
|
19006
19333
|
void this.withAccountRegistryRetry(async () => {
|
|
19334
|
+
void this.account.index.ensure();
|
|
19007
19335
|
await this.writeManifestRegistryRecords();
|
|
19008
19336
|
const spaces = await this.account.spaces.syncAccessible();
|
|
19009
19337
|
if (!spaces.ok) {
|
|
@@ -19037,7 +19365,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19037
19365
|
}
|
|
19038
19366
|
const networkIds = /* @__PURE__ */ new Set();
|
|
19039
19367
|
for (const resource of request.resources) {
|
|
19040
|
-
if (resource.service ===
|
|
19368
|
+
if (resource.service === import_sdk_core7.ENCRYPTION_PERMISSION_SERVICE && resource.path.startsWith("urn:tinycloud:encryption:") && resource.actions.includes(DECRYPT_ACTION2)) {
|
|
19041
19369
|
networkIds.add(resource.path);
|
|
19042
19370
|
}
|
|
19043
19371
|
}
|
|
@@ -19048,14 +19376,14 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19048
19376
|
return;
|
|
19049
19377
|
}
|
|
19050
19378
|
for (const networkId of this.requestedEncryptionNetworkIds()) {
|
|
19051
|
-
const parsed = (0,
|
|
19379
|
+
const parsed = (0, import_sdk_core7.parseNetworkId)(networkId);
|
|
19052
19380
|
if (!didPrincipalMatches2(parsed.ownerDid, this.did)) {
|
|
19053
19381
|
continue;
|
|
19054
19382
|
}
|
|
19055
19383
|
await this.ensureEncryptionNetwork(networkId);
|
|
19056
19384
|
}
|
|
19057
19385
|
}
|
|
19058
|
-
async
|
|
19386
|
+
async ensureOwnedSpaceHostedById(spaceId) {
|
|
19059
19387
|
if (!this.auth) {
|
|
19060
19388
|
throw new Error("Owned space hosting requires wallet mode");
|
|
19061
19389
|
}
|
|
@@ -19067,7 +19395,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19067
19395
|
if (!host) {
|
|
19068
19396
|
throw new Error("Owned space hosting requires a TinyCloud host");
|
|
19069
19397
|
}
|
|
19070
|
-
const activation = await (0,
|
|
19398
|
+
const activation = await (0, import_sdk_core7.activateSessionWithHost)(host, session.delegationHeader);
|
|
19071
19399
|
if (activation.success && !activation.skipped?.includes(spaceId)) {
|
|
19072
19400
|
return;
|
|
19073
19401
|
}
|
|
@@ -19081,7 +19409,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19081
19409
|
throw new Error(`Failed to create owned space: ${spaceId}`);
|
|
19082
19410
|
}
|
|
19083
19411
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
19084
|
-
const retry = await (0,
|
|
19412
|
+
const retry = await (0, import_sdk_core7.activateSessionWithHost)(host, session.delegationHeader);
|
|
19085
19413
|
if (!retry.success || retry.skipped?.includes(spaceId)) {
|
|
19086
19414
|
throw new Error(
|
|
19087
19415
|
`Failed to activate session after creating owned space ${spaceId}: ${retry.error ?? "space was skipped"}`
|
|
@@ -19098,7 +19426,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19098
19426
|
* caller is the root authority of their own owned spaces, so no additional
|
|
19099
19427
|
* delegation is required.
|
|
19100
19428
|
*
|
|
19101
|
-
* Unlike {@link
|
|
19429
|
+
* Unlike {@link ensureOwnedSpaceHostedById}, this always submits the host
|
|
19102
19430
|
* delegation rather than inferring hosting from session activation: a space
|
|
19103
19431
|
* the current session has never referenced is reported neither as
|
|
19104
19432
|
* `activated` nor `skipped`, so activation-based detection would wrongly
|
|
@@ -19123,7 +19451,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19123
19451
|
if (!hosted) {
|
|
19124
19452
|
throw new Error(`Failed to host owned space: ${spaceId}`);
|
|
19125
19453
|
}
|
|
19126
|
-
const activation = await (0,
|
|
19454
|
+
const activation = await (0, import_sdk_core7.activateSessionWithHost)(
|
|
19127
19455
|
host,
|
|
19128
19456
|
this.auth.tinyCloudSession.delegationHeader
|
|
19129
19457
|
);
|
|
@@ -19143,6 +19471,91 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19143
19471
|
});
|
|
19144
19472
|
return spaceId;
|
|
19145
19473
|
}
|
|
19474
|
+
/**
|
|
19475
|
+
* Ensure one of this user's owned spaces (e.g. `"secrets"`) is hosted on the
|
|
19476
|
+
* server.
|
|
19477
|
+
*
|
|
19478
|
+
* At sign-in, a full-authority session auto-hosts the owner's `secrets`
|
|
19479
|
+
* space, but a session created with a manifest / capabilityRequest does not.
|
|
19480
|
+
* Such a session can therefore hold valid `tinycloud.kv/*` capabilities for
|
|
19481
|
+
* the owned `secrets` space yet still fail its first scoped
|
|
19482
|
+
* `secrets.put(...)` with `404 Space not found`, because the space was never
|
|
19483
|
+
* registered on the node.
|
|
19484
|
+
*
|
|
19485
|
+
* Calling this resolves `name` to the owner's owned-space URI
|
|
19486
|
+
* (`tinycloud:pkh:eip155:<chain>:<addr>:<name>`). It first consults the
|
|
19487
|
+
* account-space spaces registry (`account/spaces/{space_id}`, the canonical
|
|
19488
|
+
* KV source of truth, fronted by a best-effort SQLite index): if the space is
|
|
19489
|
+
* already registered/hosted it returns the URI WITHOUT submitting a host
|
|
19490
|
+
* delegation, avoiding a redundant host-SIWE signature prompt for owners who
|
|
19491
|
+
* already use the space. Only when the space is absent — or the registry
|
|
19492
|
+
* check fails for any reason (e.g. a cold SQLite index reporting
|
|
19493
|
+
* `no such table: spaces`) — does it fall through to {@link hostOwnedSpace}.
|
|
19494
|
+
*
|
|
19495
|
+
* The registry check is purely an optimization: any failure falls back to
|
|
19496
|
+
* hosting, and the host SIWE is idempotent server-side, so re-hosting an
|
|
19497
|
+
* existing space remains a safe no-op. Must be called after {@link signIn}.
|
|
19498
|
+
*
|
|
19499
|
+
* @param name - The owned space name (e.g. `"secrets"`).
|
|
19500
|
+
* @returns The hosted owned-space URI.
|
|
19501
|
+
*/
|
|
19502
|
+
async ensureOwnedSpaceHosted(name) {
|
|
19503
|
+
if (!this.auth || !this.auth.tinyCloudSession) {
|
|
19504
|
+
throw new Error("Not signed in. Call signIn() first.");
|
|
19505
|
+
}
|
|
19506
|
+
const spaceId = this.ownedSpaceId(name);
|
|
19507
|
+
if (await this.isOwnedSpaceRegistered(spaceId)) {
|
|
19508
|
+
return spaceId;
|
|
19509
|
+
}
|
|
19510
|
+
const hosted = await this.hostOwnedSpace(name);
|
|
19511
|
+
try {
|
|
19512
|
+
await this.account.spaces.register({
|
|
19513
|
+
spaceId,
|
|
19514
|
+
name,
|
|
19515
|
+
ownerDid: this.did,
|
|
19516
|
+
type: "owned",
|
|
19517
|
+
permissions: ["*"],
|
|
19518
|
+
status: "active"
|
|
19519
|
+
});
|
|
19520
|
+
} catch {
|
|
19521
|
+
}
|
|
19522
|
+
return hosted;
|
|
19523
|
+
}
|
|
19524
|
+
/**
|
|
19525
|
+
* Check whether an owned space is already registered/hosted by consulting the
|
|
19526
|
+
* account spaces registry.
|
|
19527
|
+
*
|
|
19528
|
+
* Source of truth is the canonical KV registry record
|
|
19529
|
+
* `account/spaces/{space_id}`, read here via `account.spaces.get(spaceId)`.
|
|
19530
|
+
* The KV path is used (rather than `syncAccessible()`) because it works under
|
|
19531
|
+
* a manifest/recap session with NO extra prompt: the composed manifest recap
|
|
19532
|
+
* already grants `tinycloud.kv get/list` on the account space `spaces/`
|
|
19533
|
+
* prefix, whereas `syncAccessible()` depends on `tinycloud.space/list`, which
|
|
19534
|
+
* a recap session does not hold. Before reading, it consults the fast SQLite
|
|
19535
|
+
* index (`account.index.spaces.list()`) as a best-effort short-circuit; on a
|
|
19536
|
+
* cold index (`no such table: spaces`) or any other index failure it falls
|
|
19537
|
+
* back to the canonical KV read.
|
|
19538
|
+
*
|
|
19539
|
+
* This is a best-effort optimization. ANY failure of the check path (missing
|
|
19540
|
+
* table, KV error, missing record, thrown exception) resolves to `false` so
|
|
19541
|
+
* the caller falls through to hosting — per the directive, "if it fails in any
|
|
19542
|
+
* way then create the space".
|
|
19543
|
+
*/
|
|
19544
|
+
async isOwnedSpaceRegistered(spaceId) {
|
|
19545
|
+
try {
|
|
19546
|
+
const indexed = await this.account.index.spaces.list();
|
|
19547
|
+
if (indexed.ok && indexed.data.some((space) => space.spaceId === spaceId)) {
|
|
19548
|
+
return true;
|
|
19549
|
+
}
|
|
19550
|
+
} catch {
|
|
19551
|
+
}
|
|
19552
|
+
try {
|
|
19553
|
+
const record = await this.account.spaces.get(spaceId);
|
|
19554
|
+
return record.ok;
|
|
19555
|
+
} catch {
|
|
19556
|
+
return false;
|
|
19557
|
+
}
|
|
19558
|
+
}
|
|
19146
19559
|
/**
|
|
19147
19560
|
* Restore a previously established session from stored delegation data.
|
|
19148
19561
|
*
|
|
@@ -19165,30 +19578,38 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19165
19578
|
this._spaceService = void 0;
|
|
19166
19579
|
this._serviceContext = void 0;
|
|
19167
19580
|
this.runtimePermissionGrants = [];
|
|
19168
|
-
const restoredAddress = sessionData.address ? (0,
|
|
19581
|
+
const restoredAddress = sessionData.address ? (0, import_sdk_core7.canonicalizeAddress)(sessionData.address) : void 0;
|
|
19169
19582
|
if (restoredAddress) {
|
|
19170
19583
|
this._address = restoredAddress;
|
|
19171
19584
|
}
|
|
19172
19585
|
if (sessionData.chainId) {
|
|
19173
19586
|
this._chainId = sessionData.chainId;
|
|
19174
19587
|
}
|
|
19175
|
-
|
|
19588
|
+
const resolvedHost = await this.resolveRestoredHost(
|
|
19589
|
+
sessionData.tinycloudHosts,
|
|
19590
|
+
restoredAddress,
|
|
19591
|
+
sessionData.chainId
|
|
19592
|
+
);
|
|
19593
|
+
if (resolvedHost) {
|
|
19594
|
+
this.config.host = resolvedHost;
|
|
19595
|
+
}
|
|
19596
|
+
this._serviceContext = new import_sdk_core7.ServiceContext({
|
|
19176
19597
|
invoke: this.invokeWithRuntimePermissions,
|
|
19177
19598
|
invokeAny: this.invokeAnyWithRuntimePermissions,
|
|
19178
19599
|
fetch: globalThis.fetch.bind(globalThis),
|
|
19179
19600
|
hosts: [this.config.host],
|
|
19180
19601
|
telemetry: this.config.telemetry
|
|
19181
19602
|
});
|
|
19182
|
-
this._kv = new
|
|
19603
|
+
this._kv = new import_sdk_core7.KVService({});
|
|
19183
19604
|
this._kv.initialize(this._serviceContext);
|
|
19184
19605
|
this._serviceContext.registerService("kv", this._kv);
|
|
19185
|
-
this._sql = new
|
|
19606
|
+
this._sql = new import_sdk_core7.SQLService({});
|
|
19186
19607
|
this._sql.initialize(this._serviceContext);
|
|
19187
19608
|
this._serviceContext.registerService("sql", this._sql);
|
|
19188
|
-
this._duckdb = new
|
|
19609
|
+
this._duckdb = new import_sdk_core7.DuckDbService({});
|
|
19189
19610
|
this._duckdb.initialize(this._serviceContext);
|
|
19190
19611
|
this._serviceContext.registerService("duckdb", this._duckdb);
|
|
19191
|
-
this._hooks = new
|
|
19612
|
+
this._hooks = new import_sdk_core7.HooksService({});
|
|
19192
19613
|
this._hooks.initialize(this._serviceContext);
|
|
19193
19614
|
this._serviceContext.registerService("hooks", this._hooks);
|
|
19194
19615
|
const serviceSession = {
|
|
@@ -19217,12 +19638,45 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19217
19638
|
signature: sessionData.signature ?? ""
|
|
19218
19639
|
};
|
|
19219
19640
|
if (this.auth) {
|
|
19220
|
-
this.auth.setRestoredTinyCloudSession(
|
|
19641
|
+
this.auth.setRestoredTinyCloudSession(
|
|
19642
|
+
tcSession,
|
|
19643
|
+
this.config.host ? [this.config.host] : void 0
|
|
19644
|
+
);
|
|
19221
19645
|
} else {
|
|
19222
19646
|
this._restoredTcSession = tcSession;
|
|
19223
19647
|
}
|
|
19224
19648
|
}
|
|
19225
19649
|
}
|
|
19650
|
+
/**
|
|
19651
|
+
* Resolve the host a restored session should target.
|
|
19652
|
+
*
|
|
19653
|
+
* Mirrors fresh sign-in host resolution but for the restore path:
|
|
19654
|
+
* an explicit/pinned host always wins, then the hosts the session was
|
|
19655
|
+
* persisted with, then a lazy registry/fallback resolution for sessions
|
|
19656
|
+
* that predate the persisted `tinycloudHosts` field. Returns `undefined`
|
|
19657
|
+
* only when there's nothing to resolve from (no explicit host, no
|
|
19658
|
+
* persisted hosts, and no address/chainId) — in which case the existing
|
|
19659
|
+
* `config.host` (default) is left in place.
|
|
19660
|
+
*
|
|
19661
|
+
* Resolution failures are surfaced, not swallowed: a genuinely broken
|
|
19662
|
+
* registry lookup throws rather than silently falling back to a wrong host.
|
|
19663
|
+
*/
|
|
19664
|
+
async resolveRestoredHost(persistedHosts, address, chainId) {
|
|
19665
|
+
if (this.explicitHost) {
|
|
19666
|
+
return this.explicitHost;
|
|
19667
|
+
}
|
|
19668
|
+
if (persistedHosts && persistedHosts.length > 0) {
|
|
19669
|
+
return persistedHosts[0];
|
|
19670
|
+
}
|
|
19671
|
+
if (address === void 0 || chainId === void 0) {
|
|
19672
|
+
return void 0;
|
|
19673
|
+
}
|
|
19674
|
+
const resolved = await (0, import_sdk_core7.resolveTinyCloudHosts)((0, import_sdk_core7.pkhDid)(address, chainId), {
|
|
19675
|
+
registryUrl: this.config.tinycloudRegistryUrl,
|
|
19676
|
+
fallbackHosts: this.config.tinycloudFallbackHosts
|
|
19677
|
+
});
|
|
19678
|
+
return resolved.hosts[0];
|
|
19679
|
+
}
|
|
19226
19680
|
/**
|
|
19227
19681
|
* Resolve the currently-active TinyCloudSession, preferring the auth
|
|
19228
19682
|
* layer's value (wallet mode) and falling back to the node-level
|
|
@@ -19267,9 +19721,11 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19267
19721
|
);
|
|
19268
19722
|
}
|
|
19269
19723
|
this.signer = _TinyCloudNode.nodeDefaults.createSigner(privateKey);
|
|
19724
|
+
const authConfig = { ...this.config, prefix };
|
|
19725
|
+
const useBootstrapSignInRequest = this.shouldUseBootstrapSignInRequest(authConfig);
|
|
19270
19726
|
this.auth = new NodeUserAuthorization({
|
|
19271
19727
|
signer: this.signer,
|
|
19272
|
-
signStrategy: { type: "auto-sign" },
|
|
19728
|
+
signStrategy: this.config.signStrategy ?? { type: "auto-sign" },
|
|
19273
19729
|
wasmBindings: this.wasmBindings,
|
|
19274
19730
|
sessionStorage: options?.sessionStorage ?? this.config.sessionStorage ?? new MemorySessionStorage(),
|
|
19275
19731
|
domain: this.siweDomain,
|
|
@@ -19278,16 +19734,16 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19278
19734
|
tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
|
|
19279
19735
|
tinycloudRegistryUrl: this.config.tinycloudRegistryUrl,
|
|
19280
19736
|
tinycloudFallbackHosts: this.config.tinycloudFallbackHosts,
|
|
19281
|
-
autoCreateSpace: this.config.autoCreateSpace,
|
|
19737
|
+
autoCreateSpace: useBootstrapSignInRequest ? false : this.config.autoCreateSpace,
|
|
19282
19738
|
enablePublicSpace: this.config.enablePublicSpace ?? true,
|
|
19283
|
-
spaceCreationHandler: this.config.spaceCreationHandler,
|
|
19739
|
+
spaceCreationHandler: useBootstrapSignInRequest ? void 0 : this.config.spaceCreationHandler,
|
|
19284
19740
|
nonce: this.config.nonce,
|
|
19285
19741
|
siweConfig: this.config.siweConfig,
|
|
19286
|
-
manifest: this.config.manifest,
|
|
19287
|
-
capabilityRequest: this.config.capabilityRequest,
|
|
19288
|
-
includeAccountRegistryPermissions: this.config.includeAccountRegistryPermissions
|
|
19742
|
+
manifest: useBootstrapSignInRequest ? void 0 : this.config.manifest,
|
|
19743
|
+
capabilityRequest: useBootstrapSignInRequest ? import_sdk_core7.BOOTSTRAP_SESSION_REQUESTS.default : this.config.capabilityRequest,
|
|
19744
|
+
includeAccountRegistryPermissions: useBootstrapSignInRequest ? false : this.config.includeAccountRegistryPermissions
|
|
19289
19745
|
});
|
|
19290
|
-
this.tc = new
|
|
19746
|
+
this.tc = new import_sdk_core7.TinyCloud(this.auth, {
|
|
19291
19747
|
invokeAny: this.invokeAnyWithRuntimePermissions,
|
|
19292
19748
|
telemetry: this.config.telemetry
|
|
19293
19749
|
});
|
|
@@ -19312,9 +19768,11 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19312
19768
|
}
|
|
19313
19769
|
const prefix = options?.prefix ?? "default";
|
|
19314
19770
|
this.signer = signer;
|
|
19771
|
+
const authConfig = { ...this.config, prefix };
|
|
19772
|
+
const useBootstrapSignInRequest = this.shouldUseBootstrapSignInRequest(authConfig);
|
|
19315
19773
|
this.auth = new NodeUserAuthorization({
|
|
19316
19774
|
signer: this.signer,
|
|
19317
|
-
signStrategy: { type: "auto-sign" },
|
|
19775
|
+
signStrategy: this.config.signStrategy ?? { type: "auto-sign" },
|
|
19318
19776
|
wasmBindings: this.wasmBindings,
|
|
19319
19777
|
sessionStorage: options?.sessionStorage ?? this.config.sessionStorage ?? new MemorySessionStorage(),
|
|
19320
19778
|
domain: this.siweDomain,
|
|
@@ -19323,16 +19781,16 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19323
19781
|
tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
|
|
19324
19782
|
tinycloudRegistryUrl: this.config.tinycloudRegistryUrl,
|
|
19325
19783
|
tinycloudFallbackHosts: this.config.tinycloudFallbackHosts,
|
|
19326
|
-
autoCreateSpace: this.config.autoCreateSpace,
|
|
19784
|
+
autoCreateSpace: useBootstrapSignInRequest ? false : this.config.autoCreateSpace,
|
|
19327
19785
|
enablePublicSpace: this.config.enablePublicSpace ?? true,
|
|
19328
|
-
spaceCreationHandler: this.config.spaceCreationHandler,
|
|
19786
|
+
spaceCreationHandler: useBootstrapSignInRequest ? void 0 : this.config.spaceCreationHandler,
|
|
19329
19787
|
nonce: this.config.nonce,
|
|
19330
19788
|
siweConfig: this.config.siweConfig,
|
|
19331
|
-
manifest: this.config.manifest,
|
|
19332
|
-
capabilityRequest: this.config.capabilityRequest,
|
|
19333
|
-
includeAccountRegistryPermissions: this.config.includeAccountRegistryPermissions
|
|
19789
|
+
manifest: useBootstrapSignInRequest ? void 0 : this.config.manifest,
|
|
19790
|
+
capabilityRequest: useBootstrapSignInRequest ? import_sdk_core7.BOOTSTRAP_SESSION_REQUESTS.default : this.config.capabilityRequest,
|
|
19791
|
+
includeAccountRegistryPermissions: useBootstrapSignInRequest ? false : this.config.includeAccountRegistryPermissions
|
|
19334
19792
|
});
|
|
19335
|
-
this.tc = new
|
|
19793
|
+
this.tc = new import_sdk_core7.TinyCloud(this.auth, {
|
|
19336
19794
|
invokeAny: this.invokeAnyWithRuntimePermissions,
|
|
19337
19795
|
telemetry: this.config.telemetry
|
|
19338
19796
|
});
|
|
@@ -19348,28 +19806,28 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19348
19806
|
return;
|
|
19349
19807
|
}
|
|
19350
19808
|
this.tc.initializeServices(this.invokeWithRuntimePermissions, [this.config.host]);
|
|
19351
|
-
this._serviceContext = new
|
|
19809
|
+
this._serviceContext = new import_sdk_core7.ServiceContext({
|
|
19352
19810
|
invoke: this.invokeWithRuntimePermissions,
|
|
19353
19811
|
invokeAny: this.invokeAnyWithRuntimePermissions,
|
|
19354
19812
|
fetch: globalThis.fetch.bind(globalThis),
|
|
19355
19813
|
hosts: [this.config.host],
|
|
19356
19814
|
telemetry: this.config.telemetry
|
|
19357
19815
|
});
|
|
19358
|
-
this._kv = new
|
|
19816
|
+
this._kv = new import_sdk_core7.KVService({});
|
|
19359
19817
|
this._kv.initialize(this._serviceContext);
|
|
19360
19818
|
this._serviceContext.registerService("kv", this._kv);
|
|
19361
19819
|
const features = this.nodeFeatures;
|
|
19362
19820
|
if (features.length === 0 || features.includes("sql")) {
|
|
19363
|
-
this._sql = new
|
|
19821
|
+
this._sql = new import_sdk_core7.SQLService({});
|
|
19364
19822
|
this._sql.initialize(this._serviceContext);
|
|
19365
19823
|
this._serviceContext.registerService("sql", this._sql);
|
|
19366
19824
|
}
|
|
19367
19825
|
if (features.length === 0 || features.includes("duckdb")) {
|
|
19368
|
-
this._duckdb = new
|
|
19826
|
+
this._duckdb = new import_sdk_core7.DuckDbService({});
|
|
19369
19827
|
this._duckdb.initialize(this._serviceContext);
|
|
19370
19828
|
this._serviceContext.registerService("duckdb", this._duckdb);
|
|
19371
19829
|
}
|
|
19372
|
-
this._hooks = new
|
|
19830
|
+
this._hooks = new import_sdk_core7.HooksService({});
|
|
19373
19831
|
this._hooks.initialize(this._serviceContext);
|
|
19374
19832
|
this._serviceContext.registerService("hooks", this._hooks);
|
|
19375
19833
|
const serviceSession = {
|
|
@@ -19387,9 +19845,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19387
19845
|
this.initializeV2Services(serviceSession);
|
|
19388
19846
|
}
|
|
19389
19847
|
createSpaceScopedKVService(spaceId) {
|
|
19390
|
-
const kvService = new
|
|
19848
|
+
const kvService = new import_sdk_core7.KVService({});
|
|
19391
19849
|
if (this._serviceContext) {
|
|
19392
|
-
const spaceScopedContext = new
|
|
19850
|
+
const spaceScopedContext = new import_sdk_core7.ServiceContext({
|
|
19393
19851
|
invoke: this._serviceContext.invoke,
|
|
19394
19852
|
fetch: this._serviceContext.fetch,
|
|
19395
19853
|
hosts: this._serviceContext.hosts,
|
|
@@ -19454,7 +19912,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19454
19912
|
const shared = wasm.vault_x25519_dh(receiverPrivateKey, peerPublic);
|
|
19455
19913
|
return columnDecrypt(shared, ciphertext);
|
|
19456
19914
|
},
|
|
19457
|
-
verifyNodeSignature: (nodeId, message, signature2) => (0,
|
|
19915
|
+
verifyNodeSignature: (nodeId, message, signature2) => (0, import_sdk_core7.verifyDidKeyEd25519Signature)(nodeId, message, signature2)
|
|
19458
19916
|
};
|
|
19459
19917
|
}
|
|
19460
19918
|
async fetchNodeId() {
|
|
@@ -19525,7 +19983,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19525
19983
|
return await response.json();
|
|
19526
19984
|
}
|
|
19527
19985
|
};
|
|
19528
|
-
return new
|
|
19986
|
+
return new import_sdk_core7.EncryptionService({
|
|
19529
19987
|
crypto: crypto2,
|
|
19530
19988
|
signer: {
|
|
19531
19989
|
signDecryptInvocation: async (input) => {
|
|
@@ -19537,7 +19995,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19537
19995
|
});
|
|
19538
19996
|
return {
|
|
19539
19997
|
...signed2,
|
|
19540
|
-
canonicalBody: (0,
|
|
19998
|
+
canonicalBody: (0, import_sdk_core7.canonicalizeEncryptionJson)(
|
|
19541
19999
|
input.body
|
|
19542
20000
|
)
|
|
19543
20001
|
};
|
|
@@ -19555,8 +20013,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19555
20013
|
if (!this.config.host) {
|
|
19556
20014
|
return null;
|
|
19557
20015
|
}
|
|
19558
|
-
const publicSpaceId = (0,
|
|
19559
|
-
const result = await
|
|
20016
|
+
const publicSpaceId = (0, import_sdk_core7.makePublicSpaceId)(this._address, this._chainId);
|
|
20017
|
+
const result = await import_sdk_core7.TinyCloud.readPublicSpace(this.config.host, publicSpaceId, discoveryKey);
|
|
19560
20018
|
if (!result.ok) {
|
|
19561
20019
|
return null;
|
|
19562
20020
|
}
|
|
@@ -19579,7 +20037,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19579
20037
|
}
|
|
19580
20038
|
createVaultService(spaceId, kv) {
|
|
19581
20039
|
const wasm = this.wasmBindings;
|
|
19582
|
-
const vaultCrypto = (0,
|
|
20040
|
+
const vaultCrypto = (0, import_sdk_core7.createVaultCrypto)({
|
|
19583
20041
|
vault_encrypt: wasm.vault_encrypt,
|
|
19584
20042
|
vault_decrypt: wasm.vault_decrypt,
|
|
19585
20043
|
vault_derive_key: wasm.vault_derive_key,
|
|
@@ -19589,7 +20047,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19589
20047
|
vault_sha256: wasm.vault_sha256
|
|
19590
20048
|
});
|
|
19591
20049
|
const self2 = this;
|
|
19592
|
-
return new
|
|
20050
|
+
return new import_sdk_core7.DataVaultService({
|
|
19593
20051
|
spaceId,
|
|
19594
20052
|
crypto: vaultCrypto,
|
|
19595
20053
|
encryption: {
|
|
@@ -19612,8 +20070,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19612
20070
|
get publicKV() {
|
|
19613
20071
|
return self2._publicKV ?? self2.tc.publicKV;
|
|
19614
20072
|
},
|
|
19615
|
-
readPublicSpace: (host, targetSpaceId, key2) =>
|
|
19616
|
-
makePublicSpaceId:
|
|
20073
|
+
readPublicSpace: (host, targetSpaceId, key2) => import_sdk_core7.TinyCloud.readPublicSpace(host, targetSpaceId, key2),
|
|
20074
|
+
makePublicSpaceId: import_sdk_core7.TinyCloud.makePublicSpaceId,
|
|
19617
20075
|
did: this.did,
|
|
19618
20076
|
address: this._address ?? "",
|
|
19619
20077
|
chainId: this._chainId,
|
|
@@ -19626,7 +20084,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19626
20084
|
* @internal
|
|
19627
20085
|
*/
|
|
19628
20086
|
initializeV2Services(serviceSession) {
|
|
19629
|
-
this._capabilityRegistry = new
|
|
20087
|
+
this._capabilityRegistry = new import_sdk_core7.CapabilityKeyRegistry();
|
|
19630
20088
|
const tcSession = this.auth?.tinyCloudSession;
|
|
19631
20089
|
if (tcSession && this._address) {
|
|
19632
20090
|
const sessionKey = {
|
|
@@ -19700,13 +20158,13 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19700
20158
|
}
|
|
19701
20159
|
this._capabilityRegistry.registerKey(sessionKey, delegations);
|
|
19702
20160
|
}
|
|
19703
|
-
this._delegationManager = new
|
|
20161
|
+
this._delegationManager = new import_sdk_core7.DelegationManager({
|
|
19704
20162
|
hosts: [this.config.host],
|
|
19705
20163
|
session: serviceSession,
|
|
19706
20164
|
invoke: this.invokeWithRuntimePermissions,
|
|
19707
20165
|
fetch: globalThis.fetch.bind(globalThis)
|
|
19708
20166
|
});
|
|
19709
|
-
this._spaceService = new
|
|
20167
|
+
this._spaceService = new import_sdk_core7.SpaceService({
|
|
19710
20168
|
hosts: [this.config.host],
|
|
19711
20169
|
session: serviceSession,
|
|
19712
20170
|
invoke: this.wasmBindings.invoke,
|
|
@@ -19866,7 +20324,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19866
20324
|
...prepared,
|
|
19867
20325
|
signature: signature2
|
|
19868
20326
|
});
|
|
19869
|
-
const activateResult = await (0,
|
|
20327
|
+
const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
|
|
19870
20328
|
host,
|
|
19871
20329
|
delegationSession.delegationHeader
|
|
19872
20330
|
);
|
|
@@ -19876,7 +20334,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19876
20334
|
return {
|
|
19877
20335
|
cid: delegationSession.delegationCid,
|
|
19878
20336
|
delegateDID: params.shareKeyDID,
|
|
19879
|
-
delegatorDID: (0,
|
|
20337
|
+
delegatorDID: (0, import_sdk_core7.pkhDid)(session.address, session.chainId),
|
|
19880
20338
|
spaceId: params.spaceId,
|
|
19881
20339
|
path: params.path,
|
|
19882
20340
|
actions: params.actions,
|
|
@@ -19933,7 +20391,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19933
20391
|
if (!this._sql) {
|
|
19934
20392
|
const features = this.nodeFeatures;
|
|
19935
20393
|
if (features.length > 0 && !features.includes("sql")) {
|
|
19936
|
-
throw new
|
|
20394
|
+
throw new import_sdk_core7.UnsupportedFeatureError("sql", this.config.host, features);
|
|
19937
20395
|
}
|
|
19938
20396
|
throw new Error("Not signed in. Call signIn() first.");
|
|
19939
20397
|
}
|
|
@@ -19957,8 +20415,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19957
20415
|
if (!this._serviceContext || !this._serviceContext.session) {
|
|
19958
20416
|
throw new Error("Not signed in. Call signIn() first.");
|
|
19959
20417
|
}
|
|
19960
|
-
const sql = new
|
|
19961
|
-
const spaceScopedContext = new
|
|
20418
|
+
const sql = new import_sdk_core7.SQLService({});
|
|
20419
|
+
const spaceScopedContext = new import_sdk_core7.ServiceContext({
|
|
19962
20420
|
invoke: this._serviceContext.invoke,
|
|
19963
20421
|
fetch: this._serviceContext.fetch,
|
|
19964
20422
|
hosts: this._serviceContext.hosts,
|
|
@@ -19986,8 +20444,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19986
20444
|
if (!this._serviceContext || !this._serviceContext.session) {
|
|
19987
20445
|
throw new Error("Not signed in. Call signIn() first.");
|
|
19988
20446
|
}
|
|
19989
|
-
const kv = new
|
|
19990
|
-
const spaceScopedContext = new
|
|
20447
|
+
const kv = new import_sdk_core7.KVService({});
|
|
20448
|
+
const spaceScopedContext = new import_sdk_core7.ServiceContext({
|
|
19991
20449
|
invoke: this._serviceContext.invoke,
|
|
19992
20450
|
fetch: this._serviceContext.fetch,
|
|
19993
20451
|
hosts: this._serviceContext.hosts
|
|
@@ -20003,7 +20461,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20003
20461
|
if (!this._duckdb) {
|
|
20004
20462
|
const features = this.nodeFeatures;
|
|
20005
20463
|
if (features.length > 0 && !features.includes("duckdb")) {
|
|
20006
|
-
throw new
|
|
20464
|
+
throw new import_sdk_core7.UnsupportedFeatureError("duckdb", this.config.host, features);
|
|
20007
20465
|
}
|
|
20008
20466
|
throw new Error("Not signed in. Call signIn() first.");
|
|
20009
20467
|
}
|
|
@@ -20055,7 +20513,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20055
20513
|
type: NETWORK_ADMIN_TYPE,
|
|
20056
20514
|
targetNode,
|
|
20057
20515
|
networkId,
|
|
20058
|
-
bodyHash: (0,
|
|
20516
|
+
bodyHash: (0, import_sdk_core7.canonicalHashHex)(
|
|
20059
20517
|
crypto2.sha256,
|
|
20060
20518
|
body
|
|
20061
20519
|
),
|
|
@@ -20073,7 +20531,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20073
20531
|
Authorization: signed2.authorization,
|
|
20074
20532
|
"Content-Type": "application/json"
|
|
20075
20533
|
},
|
|
20076
|
-
body: (0,
|
|
20534
|
+
body: (0, import_sdk_core7.canonicalizeEncryptionJson)(
|
|
20077
20535
|
body
|
|
20078
20536
|
)
|
|
20079
20537
|
});
|
|
@@ -20091,7 +20549,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20091
20549
|
if (existing) {
|
|
20092
20550
|
return existing;
|
|
20093
20551
|
}
|
|
20094
|
-
const parsed = (0,
|
|
20552
|
+
const parsed = (0, import_sdk_core7.parseNetworkId)(networkId);
|
|
20095
20553
|
if (!didPrincipalMatches2(parsed.ownerDid, this.did)) {
|
|
20096
20554
|
throw new Error(
|
|
20097
20555
|
`Cannot create encryption network ${networkId}: owner ${parsed.ownerDid} does not match signed-in DID ${this.did}`
|
|
@@ -20124,7 +20582,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20124
20582
|
throw new Error("Not signed in. Call signIn() first.");
|
|
20125
20583
|
}
|
|
20126
20584
|
if (!this._baseSecrets) {
|
|
20127
|
-
this._baseSecrets = new
|
|
20585
|
+
this._baseSecrets = new import_sdk_core7.SecretsService(() => this.space("secrets").vault);
|
|
20128
20586
|
}
|
|
20129
20587
|
return this._baseSecrets;
|
|
20130
20588
|
}
|
|
@@ -20239,10 +20697,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20239
20697
|
async useRuntimeDelegation(delegation) {
|
|
20240
20698
|
const session = this.currentTinyCloudSession();
|
|
20241
20699
|
if (!session) {
|
|
20242
|
-
throw new
|
|
20700
|
+
throw new import_sdk_core7.SessionExpiredError(/* @__PURE__ */ new Date(0));
|
|
20243
20701
|
}
|
|
20244
20702
|
if (delegation.expiry.getTime() <= Date.now()) {
|
|
20245
|
-
throw new
|
|
20703
|
+
throw new import_sdk_core7.SessionExpiredError(delegation.expiry);
|
|
20246
20704
|
}
|
|
20247
20705
|
const expectedDids = [session.verificationMethod, this.sessionDid];
|
|
20248
20706
|
if (!expectedDids.some((did) => didPrincipalMatches2(delegation.delegateDID, did))) {
|
|
@@ -20251,7 +20709,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20251
20709
|
);
|
|
20252
20710
|
}
|
|
20253
20711
|
const targetHost = delegation.host ?? this.config.host;
|
|
20254
|
-
const activateResult = await (0,
|
|
20712
|
+
const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
|
|
20255
20713
|
targetHost,
|
|
20256
20714
|
delegation.delegationHeader
|
|
20257
20715
|
);
|
|
@@ -20278,13 +20736,13 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20278
20736
|
}
|
|
20279
20737
|
const session = this.currentTinyCloudSession();
|
|
20280
20738
|
if (!session) {
|
|
20281
|
-
throw new
|
|
20739
|
+
throw new import_sdk_core7.SessionExpiredError(/* @__PURE__ */ new Date(0));
|
|
20282
20740
|
}
|
|
20283
20741
|
const sessionExpiry = extractSiweExpiration(session.siwe);
|
|
20284
20742
|
if (sessionExpiry !== void 0) {
|
|
20285
20743
|
const marginMs = _TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS;
|
|
20286
20744
|
if (sessionExpiry.getTime() <= Date.now() + marginMs) {
|
|
20287
|
-
throw new
|
|
20745
|
+
throw new import_sdk_core7.SessionExpiredError(sessionExpiry);
|
|
20288
20746
|
}
|
|
20289
20747
|
}
|
|
20290
20748
|
const expanded = this.expandPermissionEntries(permissions);
|
|
@@ -20347,7 +20805,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20347
20805
|
...prepared,
|
|
20348
20806
|
signature: signature2
|
|
20349
20807
|
});
|
|
20350
|
-
const activateResult = await (0,
|
|
20808
|
+
const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
|
|
20351
20809
|
this.config.host,
|
|
20352
20810
|
delegatedSession.delegationHeader
|
|
20353
20811
|
);
|
|
@@ -20520,7 +20978,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20520
20978
|
];
|
|
20521
20979
|
const abilities = { kv: { "": kvActions } };
|
|
20522
20980
|
const now = /* @__PURE__ */ new Date();
|
|
20523
|
-
const expiryMs =
|
|
20981
|
+
const expiryMs = import_sdk_core7.EXPIRY.EPHEMERAL_MS;
|
|
20524
20982
|
const expirationTime = new Date(now.getTime() + expiryMs);
|
|
20525
20983
|
const prepared = this.wasmBindings.prepareSession({
|
|
20526
20984
|
abilities,
|
|
@@ -20538,7 +20996,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20538
20996
|
...prepared,
|
|
20539
20997
|
signature: signature2
|
|
20540
20998
|
});
|
|
20541
|
-
const activateResult = await (0,
|
|
20999
|
+
const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
|
|
20542
21000
|
this.config.host,
|
|
20543
21001
|
delegationSession.delegationHeader
|
|
20544
21002
|
);
|
|
@@ -20565,8 +21023,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20565
21023
|
}]);
|
|
20566
21024
|
}
|
|
20567
21025
|
if (this._serviceContext) {
|
|
20568
|
-
const publicKV = new
|
|
20569
|
-
const publicContext = new
|
|
21026
|
+
const publicKV = new import_sdk_core7.KVService({ prefix: "" });
|
|
21027
|
+
const publicContext = new import_sdk_core7.ServiceContext({
|
|
20570
21028
|
invoke: this.invokeWithRuntimePermissions,
|
|
20571
21029
|
fetch: this._serviceContext.fetch,
|
|
20572
21030
|
hosts: this._serviceContext.hosts,
|
|
@@ -20693,14 +21151,14 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20693
21151
|
async delegateTo(did, permissions, options) {
|
|
20694
21152
|
const session = this.currentTinyCloudSession();
|
|
20695
21153
|
if (!session) {
|
|
20696
|
-
throw new
|
|
21154
|
+
throw new import_sdk_core7.SessionExpiredError(/* @__PURE__ */ new Date(0));
|
|
20697
21155
|
}
|
|
20698
21156
|
const sessionExpiry = extractSiweExpiration(session.siwe);
|
|
20699
21157
|
if (sessionExpiry !== void 0) {
|
|
20700
21158
|
const now2 = Date.now();
|
|
20701
21159
|
const marginMs = _TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS;
|
|
20702
21160
|
if (sessionExpiry.getTime() <= now2 + marginMs) {
|
|
20703
|
-
throw new
|
|
21161
|
+
throw new import_sdk_core7.SessionExpiredError(sessionExpiry);
|
|
20704
21162
|
}
|
|
20705
21163
|
}
|
|
20706
21164
|
if (!Array.isArray(permissions) || permissions.length === 0) {
|
|
@@ -20729,11 +21187,11 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20729
21187
|
);
|
|
20730
21188
|
return { delegation: delegation2, prompted: true };
|
|
20731
21189
|
}
|
|
20732
|
-
const granted = (0,
|
|
21190
|
+
const granted = (0, import_sdk_core7.parseRecapCapabilities)(
|
|
20733
21191
|
(siwe) => this.wasmBindings.parseRecapFromSiwe(siwe),
|
|
20734
21192
|
session.siwe
|
|
20735
21193
|
);
|
|
20736
|
-
const { subset, missing } = (0,
|
|
21194
|
+
const { subset, missing } = (0, import_sdk_core7.isCapabilitySubset)(expandedEntries, granted);
|
|
20737
21195
|
if (!subset) {
|
|
20738
21196
|
const runtimeGrant = this.findGrantForOperations(
|
|
20739
21197
|
this.permissionEntriesToOperations(expandedEntries, session)
|
|
@@ -20741,7 +21199,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20741
21199
|
if (runtimeGrant) {
|
|
20742
21200
|
const marginMs = _TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS;
|
|
20743
21201
|
if (runtimeGrant.expiresAt.getTime() <= Date.now() + marginMs) {
|
|
20744
|
-
throw new
|
|
21202
|
+
throw new import_sdk_core7.SessionExpiredError(runtimeGrant.expiresAt);
|
|
20745
21203
|
}
|
|
20746
21204
|
const runtimeExpiration = runtimeGrant.expiresAt < effectiveExpiration ? runtimeGrant.expiresAt : effectiveExpiration;
|
|
20747
21205
|
const delegation2 = await this.createDelegationViaRuntimeGrant(
|
|
@@ -20752,7 +21210,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20752
21210
|
);
|
|
20753
21211
|
return { delegation: delegation2, prompted: false };
|
|
20754
21212
|
}
|
|
20755
|
-
throw new
|
|
21213
|
+
throw new import_sdk_core7.PermissionNotInManifestError(missing, granted);
|
|
20756
21214
|
}
|
|
20757
21215
|
const delegation = await this.createDelegationViaWasmPath(
|
|
20758
21216
|
did,
|
|
@@ -20834,7 +21292,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20834
21292
|
const spaceId = resolvedSpaces.size === 1 ? [...resolvedSpaces][0] : session.spaceId;
|
|
20835
21293
|
const abilities = {};
|
|
20836
21294
|
for (const entry of entries) {
|
|
20837
|
-
const shortService =
|
|
21295
|
+
const shortService = import_sdk_core7.SERVICE_LONG_TO_SHORT[entry.service];
|
|
20838
21296
|
if (shortService === void 0) {
|
|
20839
21297
|
throw new Error(
|
|
20840
21298
|
`delegateTo: unknown service '${entry.service}' \u2014 no short-form mapping`
|
|
@@ -20874,7 +21332,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20874
21332
|
});
|
|
20875
21333
|
const primary = result.resources[0];
|
|
20876
21334
|
const delegationHeader = { Authorization: result.delegation };
|
|
20877
|
-
const activateResult = await (0,
|
|
21335
|
+
const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
|
|
20878
21336
|
this.config.host,
|
|
20879
21337
|
delegationHeader
|
|
20880
21338
|
);
|
|
@@ -20909,7 +21367,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20909
21367
|
const primary = result.resources[0];
|
|
20910
21368
|
const delegationHeader = { Authorization: result.delegation };
|
|
20911
21369
|
const targetHost = grant.delegation.host ?? this.config.host;
|
|
20912
|
-
const activateResult = await (0,
|
|
21370
|
+
const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
|
|
20913
21371
|
targetHost,
|
|
20914
21372
|
delegationHeader
|
|
20915
21373
|
);
|
|
@@ -20950,10 +21408,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20950
21408
|
return this.wasmBindings.makeSpaceId(session.address, session.chainId, space);
|
|
20951
21409
|
}
|
|
20952
21410
|
expandPermissionEntries(permissions) {
|
|
20953
|
-
return (0,
|
|
21411
|
+
return (0, import_sdk_core7.expandPermissionEntries)(permissions);
|
|
20954
21412
|
}
|
|
20955
21413
|
shortServiceName(service) {
|
|
20956
|
-
const short =
|
|
21414
|
+
const short = import_sdk_core7.SERVICE_LONG_TO_SHORT[service];
|
|
20957
21415
|
if (short === void 0) {
|
|
20958
21416
|
throw new Error(
|
|
20959
21417
|
`unknown service '${service}' \u2014 no short-form mapping`
|
|
@@ -20979,7 +21437,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20979
21437
|
return abilities;
|
|
20980
21438
|
}
|
|
20981
21439
|
isEncryptionPermissionEntry(entry) {
|
|
20982
|
-
return entry.service ===
|
|
21440
|
+
return entry.service === import_sdk_core7.ENCRYPTION_PERMISSION_SERVICE && entry.path.startsWith("urn:tinycloud:encryption:");
|
|
20983
21441
|
}
|
|
20984
21442
|
permissionsToRawAbilities(entries) {
|
|
20985
21443
|
const rawAbilities = {};
|
|
@@ -21012,11 +21470,11 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21012
21470
|
}
|
|
21013
21471
|
sessionCoversPermissionEntries(session, entries) {
|
|
21014
21472
|
try {
|
|
21015
|
-
const granted = (0,
|
|
21473
|
+
const granted = (0, import_sdk_core7.parseRecapCapabilities)(
|
|
21016
21474
|
(siwe) => this.wasmBindings.parseRecapFromSiwe(siwe),
|
|
21017
21475
|
session.siwe
|
|
21018
21476
|
);
|
|
21019
|
-
return (0,
|
|
21477
|
+
return (0, import_sdk_core7.isCapabilitySubset)(entries, granted).subset;
|
|
21020
21478
|
} catch {
|
|
21021
21479
|
return false;
|
|
21022
21480
|
}
|
|
@@ -21347,7 +21805,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21347
21805
|
if (resolvedDelegateDID.endsWith(".eth") && this.config.ensResolver) {
|
|
21348
21806
|
const address = await this.config.ensResolver.resolveAddress(resolvedDelegateDID);
|
|
21349
21807
|
if (!address) throw new Error(`Could not resolve ENS name: ${resolvedDelegateDID}`);
|
|
21350
|
-
resolvedDelegateDID = (0,
|
|
21808
|
+
resolvedDelegateDID = (0, import_sdk_core7.pkhDid)(address, 1);
|
|
21351
21809
|
}
|
|
21352
21810
|
const entries = legacyParamsToPermissionEntries(
|
|
21353
21811
|
params.actions,
|
|
@@ -21362,7 +21820,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21362
21820
|
);
|
|
21363
21821
|
return result.delegation;
|
|
21364
21822
|
} catch (err) {
|
|
21365
|
-
if (err instanceof
|
|
21823
|
+
if (err instanceof import_sdk_core7.PermissionNotInManifestError) {
|
|
21366
21824
|
} else {
|
|
21367
21825
|
throw err;
|
|
21368
21826
|
}
|
|
@@ -21419,7 +21877,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21419
21877
|
...prepared,
|
|
21420
21878
|
signature: signature2
|
|
21421
21879
|
});
|
|
21422
|
-
const activateResult = await (0,
|
|
21880
|
+
const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
|
|
21423
21881
|
this.config.host,
|
|
21424
21882
|
delegationSession.delegationHeader
|
|
21425
21883
|
);
|
|
@@ -21441,7 +21899,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21441
21899
|
};
|
|
21442
21900
|
const hasKvActions = params.actions.some((a) => a.startsWith("tinycloud.kv/"));
|
|
21443
21901
|
if (hasKvActions && params.includePublicSpace !== false) {
|
|
21444
|
-
const publicSpaceId = (0,
|
|
21902
|
+
const publicSpaceId = (0, import_sdk_core7.makePublicSpaceId)(
|
|
21445
21903
|
this.wasmBindings.ensureEip55(session.address),
|
|
21446
21904
|
session.chainId
|
|
21447
21905
|
);
|
|
@@ -21464,7 +21922,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21464
21922
|
...publicPrepared,
|
|
21465
21923
|
signature: publicSignature
|
|
21466
21924
|
});
|
|
21467
|
-
const publicActivateResult = await (0,
|
|
21925
|
+
const publicActivateResult = await (0, import_sdk_core7.activateSessionWithHost)(
|
|
21468
21926
|
this.config.host,
|
|
21469
21927
|
publicSession.delegationHeader
|
|
21470
21928
|
);
|
|
@@ -21540,6 +21998,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21540
21998
|
delegation,
|
|
21541
21999
|
targetHost,
|
|
21542
22000
|
this.wasmBindings.invoke,
|
|
22001
|
+
this.wasmBindings.invokeAny,
|
|
21543
22002
|
this.config.telemetry
|
|
21544
22003
|
);
|
|
21545
22004
|
}
|
|
@@ -21569,7 +22028,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21569
22028
|
...prepared,
|
|
21570
22029
|
signature: signature2
|
|
21571
22030
|
});
|
|
21572
|
-
const activateResult = await (0,
|
|
22031
|
+
const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
|
|
21573
22032
|
targetHost,
|
|
21574
22033
|
invokerSession.delegationHeader
|
|
21575
22034
|
);
|
|
@@ -21605,6 +22064,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21605
22064
|
delegation,
|
|
21606
22065
|
targetHost,
|
|
21607
22066
|
this.wasmBindings.invoke,
|
|
22067
|
+
this.wasmBindings.invokeAny,
|
|
21608
22068
|
this.config.telemetry
|
|
21609
22069
|
);
|
|
21610
22070
|
}
|
|
@@ -21675,7 +22135,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21675
22135
|
...prepared,
|
|
21676
22136
|
signature: signature2
|
|
21677
22137
|
});
|
|
21678
|
-
const activateResult = await (0,
|
|
22138
|
+
const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
|
|
21679
22139
|
targetHost,
|
|
21680
22140
|
subDelegationSession.delegationHeader
|
|
21681
22141
|
);
|
|
@@ -21717,11 +22177,11 @@ TinyCloudNode.registerNodeDefaults({
|
|
|
21717
22177
|
});
|
|
21718
22178
|
|
|
21719
22179
|
// src/index.ts
|
|
21720
|
-
var import_sdk_core8 = require("@tinycloud/sdk-core");
|
|
21721
22180
|
var import_sdk_core9 = require("@tinycloud/sdk-core");
|
|
22181
|
+
var import_sdk_core10 = require("@tinycloud/sdk-core");
|
|
21722
22182
|
|
|
21723
22183
|
// src/storage/FileSessionStorage.ts
|
|
21724
|
-
var
|
|
22184
|
+
var import_sdk_core8 = require("@tinycloud/sdk-core");
|
|
21725
22185
|
var import_fs = require("fs");
|
|
21726
22186
|
var import_path = require("path");
|
|
21727
22187
|
var FileSessionStorage = class {
|
|
@@ -21776,7 +22236,7 @@ var FileSessionStorage = class {
|
|
|
21776
22236
|
try {
|
|
21777
22237
|
const data = (0, import_fs.readFileSync)(filePath, "utf-8");
|
|
21778
22238
|
const parsed = JSON.parse(data);
|
|
21779
|
-
const validation = (0,
|
|
22239
|
+
const validation = (0, import_sdk_core8.validatePersistedSessionData)(parsed);
|
|
21780
22240
|
if (!validation.ok) {
|
|
21781
22241
|
console.warn(`Invalid session data for ${address}:`, validation.error.message);
|
|
21782
22242
|
(0, import_fs.unlinkSync)(filePath);
|
|
@@ -21841,7 +22301,7 @@ var FileSessionStorage = class {
|
|
|
21841
22301
|
};
|
|
21842
22302
|
|
|
21843
22303
|
// src/index.ts
|
|
21844
|
-
var
|
|
22304
|
+
var import_sdk_core11 = require("@tinycloud/sdk-core");
|
|
21845
22305
|
|
|
21846
22306
|
// src/delegation.ts
|
|
21847
22307
|
async function grantAuthRequest(authority, request, options) {
|
|
@@ -21886,7 +22346,6 @@ function deserializeDelegation(data) {
|
|
|
21886
22346
|
}
|
|
21887
22347
|
|
|
21888
22348
|
// src/index.ts
|
|
21889
|
-
var import_sdk_core11 = require("@tinycloud/sdk-core");
|
|
21890
22349
|
var import_sdk_core12 = require("@tinycloud/sdk-core");
|
|
21891
22350
|
var import_sdk_core13 = require("@tinycloud/sdk-core");
|
|
21892
22351
|
var import_sdk_core14 = require("@tinycloud/sdk-core");
|
|
@@ -21897,6 +22356,7 @@ var import_sdk_core18 = require("@tinycloud/sdk-core");
|
|
|
21897
22356
|
var import_sdk_core19 = require("@tinycloud/sdk-core");
|
|
21898
22357
|
var import_sdk_core20 = require("@tinycloud/sdk-core");
|
|
21899
22358
|
var import_sdk_core21 = require("@tinycloud/sdk-core");
|
|
22359
|
+
var import_sdk_core22 = require("@tinycloud/sdk-core");
|
|
21900
22360
|
// Annotate the CommonJS export names for ESM import in node:
|
|
21901
22361
|
0 && (module.exports = {
|
|
21902
22362
|
ACCOUNT_REGISTRY_PATH,
|
|
@@ -21952,6 +22412,7 @@ var import_sdk_core21 = require("@tinycloud/sdk-core");
|
|
|
21952
22412
|
SpaceErrorCodes,
|
|
21953
22413
|
SpaceService,
|
|
21954
22414
|
TinyCloud,
|
|
22415
|
+
TinyCloudDebugLogger,
|
|
21955
22416
|
TinyCloudNode,
|
|
21956
22417
|
UnsupportedFeatureError,
|
|
21957
22418
|
VAULT_PERMISSION_SERVICE,
|
|
@@ -21976,8 +22437,10 @@ var import_sdk_core21 = require("@tinycloud/sdk-core");
|
|
|
21976
22437
|
canonicalizeSecretScope,
|
|
21977
22438
|
checkDecryptInvocationInput,
|
|
21978
22439
|
checkNodeInfo,
|
|
22440
|
+
clearTinyCloudDebugLogs,
|
|
21979
22441
|
composeManifestRequest,
|
|
21980
22442
|
createCapabilityKeyRegistry,
|
|
22443
|
+
createOpenKeyCallbackSigningStrategy,
|
|
21981
22444
|
createSharingService,
|
|
21982
22445
|
createSpaceService,
|
|
21983
22446
|
createVaultCrypto,
|
|
@@ -21989,7 +22452,9 @@ var import_sdk_core21 = require("@tinycloud/sdk-core");
|
|
|
21989
22452
|
deserializeDelegation,
|
|
21990
22453
|
didCacheKey,
|
|
21991
22454
|
didEquals,
|
|
22455
|
+
disableTinyCloudDebug,
|
|
21992
22456
|
discoverNetwork,
|
|
22457
|
+
enableTinyCloudDebug,
|
|
21993
22458
|
encryptToNetwork,
|
|
21994
22459
|
encryptionBase64Decode,
|
|
21995
22460
|
encryptionBase64Encode,
|
|
@@ -22001,9 +22466,11 @@ var import_sdk_core21 = require("@tinycloud/sdk-core");
|
|
|
22001
22466
|
expandPermissionEntries,
|
|
22002
22467
|
expandPermissionEntry,
|
|
22003
22468
|
generateRandomReceiverKey,
|
|
22469
|
+
getTinyCloudDebugLogs,
|
|
22004
22470
|
grantAuthRequest,
|
|
22005
22471
|
hexDecode,
|
|
22006
22472
|
hexEncode,
|
|
22473
|
+
installTinyCloudDebugGlobals,
|
|
22007
22474
|
isCapabilitySubset,
|
|
22008
22475
|
isEvmAddress,
|
|
22009
22476
|
isNetworkId,
|
|
@@ -22025,6 +22492,7 @@ var import_sdk_core21 = require("@tinycloud/sdk-core");
|
|
|
22025
22492
|
resolveSecretPath,
|
|
22026
22493
|
resourceCapabilitiesToSpaceAbilitiesMap,
|
|
22027
22494
|
serializeDelegation,
|
|
22495
|
+
tinyCloudDebugLogger,
|
|
22028
22496
|
validateEnvelope,
|
|
22029
22497
|
validateManifest,
|
|
22030
22498
|
verifyDecryptResponse
|