@tinycloud/node-sdk 2.4.0-beta.1 → 2.4.0-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{core-Dbzm1kA_.d.cts → core--mjBU9Jq.d.cts} +154 -6
- package/dist/{core-Dbzm1kA_.d.ts → core--mjBU9Jq.d.ts} +154 -6
- package/dist/core.cjs +462 -222
- 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 +291 -48
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +533 -265
- 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 +322 -52
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -17025,133 +17025,135 @@ 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
|
-
|
|
17031
|
-
|
|
17032
|
-
|
|
17033
|
-
|
|
17034
|
-
|
|
17035
|
-
|
|
17036
|
-
|
|
17037
|
-
|
|
17038
|
-
|
|
17039
|
-
|
|
17040
|
-
|
|
17041
|
-
|
|
17042
|
-
|
|
17028
|
+
ACCOUNT_REGISTRY_PATH: () => import_sdk_core10.ACCOUNT_REGISTRY_PATH,
|
|
17029
|
+
ACCOUNT_REGISTRY_SPACE: () => import_sdk_core10.ACCOUNT_REGISTRY_SPACE,
|
|
17030
|
+
AccountService: () => import_sdk_core2.AccountService,
|
|
17031
|
+
AutoApproveSpaceCreationHandler: () => import_sdk_core9.AutoApproveSpaceCreationHandler,
|
|
17032
|
+
CapabilityKeyRegistry: () => import_sdk_core18.CapabilityKeyRegistry,
|
|
17033
|
+
CapabilityKeyRegistryErrorCodes: () => import_sdk_core18.CapabilityKeyRegistryErrorCodes,
|
|
17034
|
+
DECRYPT_ACTION: () => import_sdk_core15.DECRYPT_ACTION,
|
|
17035
|
+
DECRYPT_FACT_TYPE: () => import_sdk_core15.DECRYPT_FACT_TYPE,
|
|
17036
|
+
DECRYPT_RESULT_TYPE: () => import_sdk_core15.DECRYPT_RESULT_TYPE,
|
|
17037
|
+
DEFAULT_ENCRYPTION_ALG: () => import_sdk_core15.DEFAULT_ENCRYPTION_ALG,
|
|
17038
|
+
DEFAULT_KEY_VERSION: () => import_sdk_core15.DEFAULT_KEY_VERSION,
|
|
17039
|
+
DEFAULT_MANIFEST_SPACE: () => import_sdk_core10.DEFAULT_MANIFEST_SPACE,
|
|
17040
|
+
DEFAULT_MANIFEST_VERSION: () => import_sdk_core10.DEFAULT_MANIFEST_VERSION,
|
|
17041
|
+
DEFAULT_SIGNED_READ_URL_EXPIRY_MS: () => import_sdk_core11.DEFAULT_SIGNED_READ_URL_EXPIRY_MS,
|
|
17042
|
+
DataVaultService: () => import_sdk_core14.DataVaultService,
|
|
17043
|
+
DatabaseHandle: () => import_sdk_core12.DatabaseHandle,
|
|
17043
17044
|
DelegatedAccess: () => DelegatedAccess,
|
|
17044
|
-
DelegationErrorCodes: () =>
|
|
17045
|
-
DelegationManager: () =>
|
|
17046
|
-
DuckDbAction: () =>
|
|
17047
|
-
DuckDbDatabaseHandle: () =>
|
|
17048
|
-
DuckDbService: () =>
|
|
17049
|
-
ENCRYPTION_NETWORK_URN_PREFIX: () =>
|
|
17050
|
-
ENCRYPTION_SERVICE: () =>
|
|
17051
|
-
ENCRYPTION_SERVICE_SHORT: () =>
|
|
17052
|
-
ENVELOPE_VERSION: () =>
|
|
17053
|
-
EncryptionService: () =>
|
|
17045
|
+
DelegationErrorCodes: () => import_sdk_core17.DelegationErrorCodes,
|
|
17046
|
+
DelegationManager: () => import_sdk_core17.DelegationManager,
|
|
17047
|
+
DuckDbAction: () => import_sdk_core13.DuckDbAction,
|
|
17048
|
+
DuckDbDatabaseHandle: () => import_sdk_core13.DuckDbDatabaseHandle,
|
|
17049
|
+
DuckDbService: () => import_sdk_core13.DuckDbService,
|
|
17050
|
+
ENCRYPTION_NETWORK_URN_PREFIX: () => import_sdk_core15.ENCRYPTION_NETWORK_URN_PREFIX,
|
|
17051
|
+
ENCRYPTION_SERVICE: () => import_sdk_core15.ENCRYPTION_SERVICE,
|
|
17052
|
+
ENCRYPTION_SERVICE_SHORT: () => import_sdk_core15.ENCRYPTION_SERVICE_SHORT,
|
|
17053
|
+
ENVELOPE_VERSION: () => import_sdk_core15.ENVELOPE_VERSION,
|
|
17054
|
+
EncryptionService: () => import_sdk_core15.EncryptionService,
|
|
17054
17055
|
FileSessionStorage: () => FileSessionStorage,
|
|
17055
|
-
HooksService: () =>
|
|
17056
|
-
IdentityParseError: () =>
|
|
17057
|
-
KVService: () =>
|
|
17058
|
-
ManifestValidationError: () =>
|
|
17056
|
+
HooksService: () => import_sdk_core16.HooksService,
|
|
17057
|
+
IdentityParseError: () => import_sdk_core9.IdentityParseError,
|
|
17058
|
+
KVService: () => import_sdk_core11.KVService,
|
|
17059
|
+
ManifestValidationError: () => import_sdk_core10.ManifestValidationError,
|
|
17059
17060
|
MemorySessionStorage: () => MemorySessionStorage,
|
|
17060
|
-
NETWORK_NAME_PATTERN: () =>
|
|
17061
|
-
NetworkIdError: () =>
|
|
17061
|
+
NETWORK_NAME_PATTERN: () => import_sdk_core15.NETWORK_NAME_PATTERN,
|
|
17062
|
+
NetworkIdError: () => import_sdk_core15.NetworkIdError,
|
|
17062
17063
|
NodeUserAuthorization: () => NodeUserAuthorization,
|
|
17063
17064
|
NodeWasmBindings: () => NodeWasmBindings,
|
|
17064
|
-
PermissionNotInManifestError: () =>
|
|
17065
|
-
PrefixedKVService: () =>
|
|
17065
|
+
PermissionNotInManifestError: () => import_sdk_core10.PermissionNotInManifestError,
|
|
17066
|
+
PrefixedKVService: () => import_sdk_core11.PrefixedKVService,
|
|
17066
17067
|
PrivateKeySigner: () => PrivateKeySigner,
|
|
17067
|
-
ProtocolMismatchError: () =>
|
|
17068
|
-
SECRET_NAME_RE: () =>
|
|
17069
|
-
SQLAction: () =>
|
|
17070
|
-
SQLService: () =>
|
|
17071
|
-
SecretsService: () =>
|
|
17072
|
-
ServiceContext: () =>
|
|
17073
|
-
SessionExpiredError: () =>
|
|
17074
|
-
SharingService: () =>
|
|
17075
|
-
SilentNotificationHandler: () =>
|
|
17076
|
-
Space: () =>
|
|
17077
|
-
SpaceErrorCodes: () =>
|
|
17078
|
-
SpaceService: () =>
|
|
17079
|
-
TinyCloud: () =>
|
|
17068
|
+
ProtocolMismatchError: () => import_sdk_core20.ProtocolMismatchError,
|
|
17069
|
+
SECRET_NAME_RE: () => import_sdk_core14.SECRET_NAME_RE,
|
|
17070
|
+
SQLAction: () => import_sdk_core12.SQLAction,
|
|
17071
|
+
SQLService: () => import_sdk_core12.SQLService,
|
|
17072
|
+
SecretsService: () => import_sdk_core14.SecretsService,
|
|
17073
|
+
ServiceContext: () => import_sdk_core21.ServiceContext,
|
|
17074
|
+
SessionExpiredError: () => import_sdk_core10.SessionExpiredError,
|
|
17075
|
+
SharingService: () => import_sdk_core17.SharingService,
|
|
17076
|
+
SilentNotificationHandler: () => import_sdk_core9.SilentNotificationHandler,
|
|
17077
|
+
Space: () => import_sdk_core19.Space,
|
|
17078
|
+
SpaceErrorCodes: () => import_sdk_core19.SpaceErrorCodes,
|
|
17079
|
+
SpaceService: () => import_sdk_core19.SpaceService,
|
|
17080
|
+
TinyCloud: () => import_sdk_core8.TinyCloud,
|
|
17080
17081
|
TinyCloudNode: () => TinyCloudNode,
|
|
17081
|
-
UnsupportedFeatureError: () =>
|
|
17082
|
-
VAULT_PERMISSION_SERVICE: () =>
|
|
17083
|
-
VaultHeaders: () =>
|
|
17084
|
-
VaultPublicSpaceKVActions: () =>
|
|
17085
|
-
VersionCheckError: () =>
|
|
17082
|
+
UnsupportedFeatureError: () => import_sdk_core20.UnsupportedFeatureError,
|
|
17083
|
+
VAULT_PERMISSION_SERVICE: () => import_sdk_core10.VAULT_PERMISSION_SERVICE,
|
|
17084
|
+
VaultHeaders: () => import_sdk_core14.VaultHeaders,
|
|
17085
|
+
VaultPublicSpaceKVActions: () => import_sdk_core14.VaultPublicSpaceKVActions,
|
|
17086
|
+
VersionCheckError: () => import_sdk_core20.VersionCheckError,
|
|
17086
17087
|
WasmKeyProvider: () => WasmKeyProvider,
|
|
17087
|
-
addressStorageKey: () =>
|
|
17088
|
-
buildCanonicalDecryptRequest: () =>
|
|
17089
|
-
buildDecryptAttenuation: () =>
|
|
17090
|
-
buildDecryptFacts: () =>
|
|
17091
|
-
buildDecryptInvocation: () =>
|
|
17092
|
-
buildNetworkId: () =>
|
|
17093
|
-
buildSpaceUri: () =>
|
|
17094
|
-
canonicalHashHex: () =>
|
|
17095
|
-
canonicalSignedResponse: () =>
|
|
17096
|
-
canonicalizeAddress: () =>
|
|
17097
|
-
canonicalizeDid: () =>
|
|
17098
|
-
canonicalizeDidUrl: () =>
|
|
17099
|
-
canonicalizeEncryptionJson: () =>
|
|
17100
|
-
canonicalizeNetworkId: () =>
|
|
17101
|
-
canonicalizeSecretScope: () =>
|
|
17102
|
-
checkDecryptInvocationInput: () =>
|
|
17103
|
-
checkNodeInfo: () =>
|
|
17104
|
-
composeManifestRequest: () =>
|
|
17105
|
-
createCapabilityKeyRegistry: () =>
|
|
17106
|
-
createSharingService: () =>
|
|
17107
|
-
createSpaceService: () =>
|
|
17108
|
-
createVaultCrypto: () =>
|
|
17088
|
+
addressStorageKey: () => import_sdk_core9.addressStorageKey,
|
|
17089
|
+
buildCanonicalDecryptRequest: () => import_sdk_core15.buildCanonicalDecryptRequest,
|
|
17090
|
+
buildDecryptAttenuation: () => import_sdk_core15.buildDecryptAttenuation,
|
|
17091
|
+
buildDecryptFacts: () => import_sdk_core15.buildDecryptFacts,
|
|
17092
|
+
buildDecryptInvocation: () => import_sdk_core15.buildDecryptInvocation,
|
|
17093
|
+
buildNetworkId: () => import_sdk_core15.buildNetworkId,
|
|
17094
|
+
buildSpaceUri: () => import_sdk_core19.buildSpaceUri,
|
|
17095
|
+
canonicalHashHex: () => import_sdk_core15.canonicalHashHex,
|
|
17096
|
+
canonicalSignedResponse: () => import_sdk_core15.canonicalSignedResponse,
|
|
17097
|
+
canonicalizeAddress: () => import_sdk_core9.canonicalizeAddress,
|
|
17098
|
+
canonicalizeDid: () => import_sdk_core9.canonicalizeDid,
|
|
17099
|
+
canonicalizeDidUrl: () => import_sdk_core9.canonicalizeDidUrl,
|
|
17100
|
+
canonicalizeEncryptionJson: () => import_sdk_core15.canonicalizeEncryptionJson,
|
|
17101
|
+
canonicalizeNetworkId: () => import_sdk_core9.canonicalizeNetworkId,
|
|
17102
|
+
canonicalizeSecretScope: () => import_sdk_core14.canonicalizeSecretScope,
|
|
17103
|
+
checkDecryptInvocationInput: () => import_sdk_core15.checkDecryptInvocationInput,
|
|
17104
|
+
checkNodeInfo: () => import_sdk_core20.checkNodeInfo,
|
|
17105
|
+
composeManifestRequest: () => import_sdk_core10.composeManifestRequest,
|
|
17106
|
+
createCapabilityKeyRegistry: () => import_sdk_core18.createCapabilityKeyRegistry,
|
|
17107
|
+
createSharingService: () => import_sdk_core17.createSharingService,
|
|
17108
|
+
createSpaceService: () => import_sdk_core19.createSpaceService,
|
|
17109
|
+
createVaultCrypto: () => import_sdk_core14.createVaultCrypto,
|
|
17109
17110
|
createWasmKeyProvider: () => createWasmKeyProvider,
|
|
17110
|
-
decryptEnvelopeWithKey: () =>
|
|
17111
|
+
decryptEnvelopeWithKey: () => import_sdk_core15.decryptEnvelopeWithKey,
|
|
17111
17112
|
defaultSignStrategy: () => defaultSignStrategy,
|
|
17112
|
-
defaultSpaceCreationHandler: () =>
|
|
17113
|
-
deriveSignedReceiverKey: () =>
|
|
17113
|
+
defaultSpaceCreationHandler: () => import_sdk_core9.defaultSpaceCreationHandler,
|
|
17114
|
+
deriveSignedReceiverKey: () => import_sdk_core15.deriveSignedReceiverKey,
|
|
17114
17115
|
deserializeDelegation: () => deserializeDelegation,
|
|
17115
|
-
didCacheKey: () =>
|
|
17116
|
-
didEquals: () =>
|
|
17117
|
-
discoverNetwork: () =>
|
|
17118
|
-
encryptToNetwork: () =>
|
|
17119
|
-
encryptionBase64Decode: () =>
|
|
17120
|
-
encryptionBase64Encode: () =>
|
|
17121
|
-
encryptionError: () =>
|
|
17122
|
-
encryptionUtf8Decode: () =>
|
|
17123
|
-
encryptionUtf8Encode: () =>
|
|
17124
|
-
ensureNetworkUsableForDecrypt: () =>
|
|
17125
|
-
expandActionShortNames: () =>
|
|
17126
|
-
expandPermissionEntries: () =>
|
|
17127
|
-
expandPermissionEntry: () =>
|
|
17128
|
-
generateRandomReceiverKey: () =>
|
|
17129
|
-
|
|
17130
|
-
|
|
17131
|
-
|
|
17132
|
-
|
|
17133
|
-
|
|
17134
|
-
|
|
17135
|
-
|
|
17136
|
-
|
|
17137
|
-
|
|
17138
|
-
|
|
17139
|
-
|
|
17140
|
-
|
|
17141
|
-
|
|
17142
|
-
|
|
17143
|
-
|
|
17144
|
-
|
|
17145
|
-
|
|
17146
|
-
|
|
17147
|
-
|
|
17148
|
-
|
|
17149
|
-
|
|
17150
|
-
|
|
17116
|
+
didCacheKey: () => import_sdk_core9.didCacheKey,
|
|
17117
|
+
didEquals: () => import_sdk_core9.didEquals,
|
|
17118
|
+
discoverNetwork: () => import_sdk_core15.discoverNetwork,
|
|
17119
|
+
encryptToNetwork: () => import_sdk_core15.encryptToNetwork,
|
|
17120
|
+
encryptionBase64Decode: () => import_sdk_core15.encryptionBase64Decode,
|
|
17121
|
+
encryptionBase64Encode: () => import_sdk_core15.encryptionBase64Encode,
|
|
17122
|
+
encryptionError: () => import_sdk_core15.encryptionError,
|
|
17123
|
+
encryptionUtf8Decode: () => import_sdk_core15.encryptionUtf8Decode,
|
|
17124
|
+
encryptionUtf8Encode: () => import_sdk_core15.encryptionUtf8Encode,
|
|
17125
|
+
ensureNetworkUsableForDecrypt: () => import_sdk_core15.ensureNetworkUsableForDecrypt,
|
|
17126
|
+
expandActionShortNames: () => import_sdk_core10.expandActionShortNames,
|
|
17127
|
+
expandPermissionEntries: () => import_sdk_core10.expandPermissionEntries,
|
|
17128
|
+
expandPermissionEntry: () => import_sdk_core10.expandPermissionEntry,
|
|
17129
|
+
generateRandomReceiverKey: () => import_sdk_core15.generateRandomReceiverKey,
|
|
17130
|
+
grantAuthRequest: () => grantAuthRequest,
|
|
17131
|
+
hexDecode: () => import_sdk_core15.hexDecode,
|
|
17132
|
+
hexEncode: () => import_sdk_core15.hexEncode,
|
|
17133
|
+
isCapabilitySubset: () => import_sdk_core10.isCapabilitySubset,
|
|
17134
|
+
isEvmAddress: () => import_sdk_core9.isEvmAddress,
|
|
17135
|
+
isNetworkId: () => import_sdk_core15.isNetworkId,
|
|
17136
|
+
loadManifest: () => import_sdk_core10.loadManifest,
|
|
17137
|
+
makePkhSpaceId: () => import_sdk_core9.makePkhSpaceId,
|
|
17138
|
+
makePublicSpaceId: () => import_sdk_core19.makePublicSpaceId,
|
|
17139
|
+
networkDiscoveryKey: () => import_sdk_core15.networkDiscoveryKey,
|
|
17140
|
+
openWrappedKey: () => import_sdk_core15.openWrappedKey,
|
|
17141
|
+
parseCanonicalNetworkId: () => import_sdk_core9.parseCanonicalNetworkId,
|
|
17142
|
+
parseExpiry: () => import_sdk_core10.parseExpiry,
|
|
17143
|
+
parseNetworkId: () => import_sdk_core15.parseNetworkId,
|
|
17144
|
+
parsePkhDid: () => import_sdk_core9.parsePkhDid,
|
|
17145
|
+
parseSpaceUri: () => import_sdk_core19.parseSpaceUri,
|
|
17146
|
+
pkhDid: () => import_sdk_core9.pkhDid,
|
|
17147
|
+
principalDid: () => import_sdk_core9.principalDid,
|
|
17148
|
+
principalDidEquals: () => import_sdk_core9.principalDidEquals,
|
|
17149
|
+
resolveManifest: () => import_sdk_core10.resolveManifest,
|
|
17150
|
+
resolveSecretListPrefix: () => import_sdk_core14.resolveSecretListPrefix,
|
|
17151
|
+
resolveSecretPath: () => import_sdk_core14.resolveSecretPath,
|
|
17152
|
+
resourceCapabilitiesToSpaceAbilitiesMap: () => import_sdk_core10.resourceCapabilitiesToSpaceAbilitiesMap,
|
|
17151
17153
|
serializeDelegation: () => serializeDelegation,
|
|
17152
|
-
validateEnvelope: () =>
|
|
17153
|
-
validateManifest: () =>
|
|
17154
|
-
verifyDecryptResponse: () =>
|
|
17154
|
+
validateEnvelope: () => import_sdk_core15.validateEnvelope,
|
|
17155
|
+
validateManifest: () => import_sdk_core10.validateManifest,
|
|
17156
|
+
verifyDecryptResponse: () => import_sdk_core15.verifyDecryptResponse
|
|
17155
17157
|
});
|
|
17156
17158
|
module.exports = __toCommonJS(index_exports);
|
|
17157
17159
|
|
|
@@ -17256,7 +17258,7 @@ var PrivateKeySigner = class {
|
|
|
17256
17258
|
};
|
|
17257
17259
|
|
|
17258
17260
|
// src/TinyCloudNode.ts
|
|
17259
|
-
var
|
|
17261
|
+
var import_sdk_core6 = require("@tinycloud/sdk-core");
|
|
17260
17262
|
|
|
17261
17263
|
// src/authorization/NodeUserAuthorization.ts
|
|
17262
17264
|
var import_sdk_core = require("@tinycloud/sdk-core");
|
|
@@ -17336,6 +17338,25 @@ var MemorySessionStorage = class {
|
|
|
17336
17338
|
};
|
|
17337
17339
|
|
|
17338
17340
|
// src/authorization/NodeUserAuthorization.ts
|
|
17341
|
+
var DECRYPT_ACTION = "tinycloud.encryption/decrypt";
|
|
17342
|
+
var NETWORK_CREATE_ACTION = "tinycloud.encryption/network.create";
|
|
17343
|
+
function didPrincipalMatches(actual, expected) {
|
|
17344
|
+
try {
|
|
17345
|
+
return (0, import_sdk_core.principalDidEquals)(actual, expected);
|
|
17346
|
+
} catch {
|
|
17347
|
+
return actual === expected;
|
|
17348
|
+
}
|
|
17349
|
+
}
|
|
17350
|
+
function addRawAbility(rawAbilities, resource, action) {
|
|
17351
|
+
const actions = rawAbilities[resource];
|
|
17352
|
+
if (actions === void 0) {
|
|
17353
|
+
rawAbilities[resource] = [action];
|
|
17354
|
+
return;
|
|
17355
|
+
}
|
|
17356
|
+
if (!actions.includes(action)) {
|
|
17357
|
+
actions.push(action);
|
|
17358
|
+
}
|
|
17359
|
+
}
|
|
17339
17360
|
var NodeUserAuthorization = class {
|
|
17340
17361
|
constructor(config) {
|
|
17341
17362
|
this.extensions = [];
|
|
@@ -17362,6 +17383,7 @@ var NodeUserAuthorization = class {
|
|
|
17362
17383
|
"": [
|
|
17363
17384
|
"tinycloud.sql/read",
|
|
17364
17385
|
"tinycloud.sql/write",
|
|
17386
|
+
"tinycloud.sql/ddl",
|
|
17365
17387
|
"tinycloud.sql/admin",
|
|
17366
17388
|
"tinycloud.sql/export"
|
|
17367
17389
|
]
|
|
@@ -17453,12 +17475,48 @@ var NodeUserAuthorization = class {
|
|
|
17453
17475
|
* `siwe` is the load-bearing one because `extractSiweExpiration` returns
|
|
17454
17476
|
* undefined for missing SIWEs and the SDK then treats the session as
|
|
17455
17477
|
* expired-at-epoch-zero.
|
|
17478
|
+
*
|
|
17479
|
+
* @param hosts - The TinyCloud hosts this session was created against,
|
|
17480
|
+
* as persisted in {@link PersistedSessionData.tinycloudHosts}. When
|
|
17481
|
+
* present (and non-empty) they are adopted directly so the restored
|
|
17482
|
+
* session resolves to the same node as the original sign-in without
|
|
17483
|
+
* re-running registry/fallback resolution. When absent (old session)
|
|
17484
|
+
* hosts are resolved lazily on the first host-needing call via
|
|
17485
|
+
* {@link ensureTinyCloudHosts}.
|
|
17456
17486
|
*/
|
|
17457
|
-
setRestoredTinyCloudSession(session) {
|
|
17487
|
+
setRestoredTinyCloudSession(session, hosts) {
|
|
17458
17488
|
const address = (0, import_sdk_core.canonicalizeAddress)(session.address);
|
|
17459
17489
|
this._tinyCloudSession = { ...session, address };
|
|
17460
17490
|
this._address = address;
|
|
17461
17491
|
this._chainId = session.chainId;
|
|
17492
|
+
if ((!this.tinycloudHosts || this.tinycloudHosts.length === 0) && hosts && hosts.length > 0) {
|
|
17493
|
+
this.tinycloudHosts = [...hosts];
|
|
17494
|
+
}
|
|
17495
|
+
}
|
|
17496
|
+
/**
|
|
17497
|
+
* Ensure `tinycloudHosts` are resolved before a host-needing call.
|
|
17498
|
+
*
|
|
17499
|
+
* Fresh sign-in resolves hosts up front; a restored session may not have
|
|
17500
|
+
* (old persisted sessions predate {@link PersistedSessionData.tinycloudHosts}).
|
|
17501
|
+
* This guard makes a restored session resolve the node exactly like a fresh
|
|
17502
|
+
* sign-in — persisted hosts are preferred (already set by
|
|
17503
|
+
* {@link setRestoredTinyCloudSession}), otherwise the registry/fallback
|
|
17504
|
+
* resolution runs lazily here. Idempotent: {@link resolveTinyCloudHostsForSignIn}
|
|
17505
|
+
* early-returns when hosts are already set.
|
|
17506
|
+
*
|
|
17507
|
+
* Throws if hosts are unset and the restored session has no address/chainId
|
|
17508
|
+
* to resolve from — a real failure that must surface, not be masked.
|
|
17509
|
+
*/
|
|
17510
|
+
async ensureTinyCloudHosts() {
|
|
17511
|
+
if (this.tinycloudHosts && this.tinycloudHosts.length > 0) {
|
|
17512
|
+
return;
|
|
17513
|
+
}
|
|
17514
|
+
if (this._address === void 0 || this._chainId === void 0) {
|
|
17515
|
+
throw new Error(
|
|
17516
|
+
"Cannot resolve TinyCloud hosts: no address/chainId available. Sign in or restore a session first."
|
|
17517
|
+
);
|
|
17518
|
+
}
|
|
17519
|
+
await this.resolveTinyCloudHostsForSignIn(this._address, this._chainId);
|
|
17462
17520
|
}
|
|
17463
17521
|
async resolveTinyCloudHostsForSignIn(address, chainId) {
|
|
17464
17522
|
if (this.tinycloudHosts && this.tinycloudHosts.length > 0) {
|
|
@@ -17565,20 +17623,18 @@ var NodeUserAuthorization = class {
|
|
|
17565
17623
|
};
|
|
17566
17624
|
}
|
|
17567
17625
|
const rawAbilities = {};
|
|
17626
|
+
const currentDid = (0, import_sdk_core.pkhDid)(address, chainId);
|
|
17568
17627
|
const spaceResources = request.resources.filter((entry) => {
|
|
17569
17628
|
if (entry.service !== import_sdk_core.ENCRYPTION_PERMISSION_SERVICE) {
|
|
17570
17629
|
return true;
|
|
17571
17630
|
}
|
|
17572
|
-
const
|
|
17573
|
-
|
|
17574
|
-
|
|
17575
|
-
|
|
17576
|
-
const
|
|
17577
|
-
|
|
17578
|
-
|
|
17579
|
-
existing.push(action);
|
|
17580
|
-
seen.add(action);
|
|
17581
|
-
}
|
|
17631
|
+
for (const action of entry.actions) {
|
|
17632
|
+
addRawAbility(rawAbilities, entry.path, action);
|
|
17633
|
+
}
|
|
17634
|
+
if (entry.actions.includes(DECRYPT_ACTION)) {
|
|
17635
|
+
const parsed = (0, import_sdk_core.parseNetworkId)(entry.path);
|
|
17636
|
+
if (didPrincipalMatches(parsed.ownerDid, currentDid)) {
|
|
17637
|
+
addRawAbility(rawAbilities, entry.path, NETWORK_CREATE_ACTION);
|
|
17582
17638
|
}
|
|
17583
17639
|
}
|
|
17584
17640
|
return false;
|
|
@@ -17657,6 +17713,7 @@ var NodeUserAuthorization = class {
|
|
|
17657
17713
|
if (!this._tinyCloudSession || !this._address || !this._chainId) {
|
|
17658
17714
|
throw new Error("Must be signed in to host space");
|
|
17659
17715
|
}
|
|
17716
|
+
await this.ensureTinyCloudHosts();
|
|
17660
17717
|
const host = this.primaryTinyCloudHost;
|
|
17661
17718
|
const spaceId = targetSpaceId ?? this._tinyCloudSession.spaceId;
|
|
17662
17719
|
const peerId = await (0, import_sdk_core.fetchPeerId)(host, spaceId);
|
|
@@ -17699,6 +17756,7 @@ var NodeUserAuthorization = class {
|
|
|
17699
17756
|
if (!this._tinyCloudSession) {
|
|
17700
17757
|
throw new Error("Must be signed in to ensure space exists");
|
|
17701
17758
|
}
|
|
17759
|
+
await this.ensureTinyCloudHosts();
|
|
17702
17760
|
const host = this.primaryTinyCloudHost;
|
|
17703
17761
|
const primarySpaceId = this._tinyCloudSession.spaceId;
|
|
17704
17762
|
const result = await (0, import_sdk_core.activateSessionWithHost)(
|
|
@@ -17880,7 +17938,8 @@ var NodeUserAuthorization = class {
|
|
|
17880
17938
|
},
|
|
17881
17939
|
expiresAt: expirationTime.toISOString(),
|
|
17882
17940
|
createdAt: now.toISOString(),
|
|
17883
|
-
version: "1.0"
|
|
17941
|
+
version: "1.0",
|
|
17942
|
+
tinycloudHosts: this.tinycloudHosts
|
|
17884
17943
|
};
|
|
17885
17944
|
await this.sessionStorage.save(address, persistedData);
|
|
17886
17945
|
this._session = clientSession;
|
|
@@ -18047,7 +18106,8 @@ var NodeUserAuthorization = class {
|
|
|
18047
18106
|
},
|
|
18048
18107
|
expiresAt,
|
|
18049
18108
|
createdAt,
|
|
18050
|
-
version: "1.0"
|
|
18109
|
+
version: "1.0",
|
|
18110
|
+
tinycloudHosts: this.tinycloudHosts
|
|
18051
18111
|
};
|
|
18052
18112
|
await this.sessionStorage.save(address, persistedData);
|
|
18053
18113
|
this._session = clientSession;
|
|
@@ -18137,30 +18197,33 @@ var NodeUserAuthorization = class {
|
|
|
18137
18197
|
}
|
|
18138
18198
|
};
|
|
18139
18199
|
|
|
18140
|
-
// src/
|
|
18200
|
+
// src/account/AccountService.ts
|
|
18141
18201
|
var import_sdk_core2 = require("@tinycloud/sdk-core");
|
|
18202
|
+
|
|
18203
|
+
// src/DelegatedAccess.ts
|
|
18204
|
+
var import_sdk_core3 = require("@tinycloud/sdk-core");
|
|
18142
18205
|
var DelegatedAccess = class {
|
|
18143
18206
|
constructor(session, delegation, host, invoke2, telemetry) {
|
|
18144
18207
|
this.session = session;
|
|
18145
18208
|
this._delegation = delegation;
|
|
18146
18209
|
this.host = host;
|
|
18147
|
-
this._serviceContext = new
|
|
18210
|
+
this._serviceContext = new import_sdk_core3.ServiceContext({
|
|
18148
18211
|
invoke: invoke2,
|
|
18149
18212
|
fetch: globalThis.fetch.bind(globalThis),
|
|
18150
18213
|
hosts: [host],
|
|
18151
18214
|
telemetry
|
|
18152
18215
|
});
|
|
18153
18216
|
const prefix = this._delegation.path.replace(/\/$/, "");
|
|
18154
|
-
this._kv = new
|
|
18217
|
+
this._kv = new import_sdk_core3.KVService({ prefix });
|
|
18155
18218
|
this._kv.initialize(this._serviceContext);
|
|
18156
18219
|
this._serviceContext.registerService("kv", this._kv);
|
|
18157
|
-
this._sql = new
|
|
18220
|
+
this._sql = new import_sdk_core3.SQLService({});
|
|
18158
18221
|
this._sql.initialize(this._serviceContext);
|
|
18159
18222
|
this._serviceContext.registerService("sql", this._sql);
|
|
18160
|
-
this._duckdb = new
|
|
18223
|
+
this._duckdb = new import_sdk_core3.DuckDbService({});
|
|
18161
18224
|
this._duckdb.initialize(this._serviceContext);
|
|
18162
18225
|
this._serviceContext.registerService("duckdb", this._duckdb);
|
|
18163
|
-
this._hooks = new
|
|
18226
|
+
this._hooks = new import_sdk_core3.HooksService({});
|
|
18164
18227
|
this._hooks.initialize(this._serviceContext);
|
|
18165
18228
|
this._serviceContext.registerService("hooks", this._hooks);
|
|
18166
18229
|
const serviceSession = {
|
|
@@ -18310,7 +18373,7 @@ function createWasmKeyProvider(sessionManager) {
|
|
|
18310
18373
|
}
|
|
18311
18374
|
|
|
18312
18375
|
// src/delegateToHelpers.ts
|
|
18313
|
-
var
|
|
18376
|
+
var import_sdk_core4 = require("@tinycloud/sdk-core");
|
|
18314
18377
|
function legacyParamsToPermissionEntries(actions, path, spaceIdOverride) {
|
|
18315
18378
|
const byService = /* @__PURE__ */ new Map();
|
|
18316
18379
|
for (const a of actions) {
|
|
@@ -18341,7 +18404,7 @@ function legacyParamsToPermissionEntries(actions, path, spaceIdOverride) {
|
|
|
18341
18404
|
}
|
|
18342
18405
|
return entries;
|
|
18343
18406
|
}
|
|
18344
|
-
var DEFAULT_DELEGATION_EXPIRY_MS =
|
|
18407
|
+
var DEFAULT_DELEGATION_EXPIRY_MS = import_sdk_core4.EXPIRY.SESSION_MS;
|
|
18345
18408
|
function resolveExpiryMs(expiry) {
|
|
18346
18409
|
if (expiry === void 0) {
|
|
18347
18410
|
return DEFAULT_DELEGATION_EXPIRY_MS;
|
|
@@ -18354,10 +18417,10 @@ function resolveExpiryMs(expiry) {
|
|
|
18354
18417
|
}
|
|
18355
18418
|
return expiry;
|
|
18356
18419
|
}
|
|
18357
|
-
return (0,
|
|
18420
|
+
return (0, import_sdk_core4.parseExpiry)(expiry);
|
|
18358
18421
|
}
|
|
18359
18422
|
function extractSiweExpiration(siwe) {
|
|
18360
|
-
const parsed = new
|
|
18423
|
+
const parsed = new import_sdk_core4.SiweMessage(siwe);
|
|
18361
18424
|
if (parsed.expirationTime === void 0 || parsed.expirationTime === null) {
|
|
18362
18425
|
return void 0;
|
|
18363
18426
|
}
|
|
@@ -18371,7 +18434,7 @@ function extractSiweExpiration(siwe) {
|
|
|
18371
18434
|
}
|
|
18372
18435
|
|
|
18373
18436
|
// src/NodeSecretsService.ts
|
|
18374
|
-
var
|
|
18437
|
+
var import_sdk_core5 = require("@tinycloud/sdk-core");
|
|
18375
18438
|
var SECRETS_SPACE = "secrets";
|
|
18376
18439
|
function ok() {
|
|
18377
18440
|
return { ok: true, data: void 0 };
|
|
@@ -18404,7 +18467,7 @@ function secretActionName(action) {
|
|
|
18404
18467
|
}
|
|
18405
18468
|
function secretPermissionEntries(name, options, action, encryptionNetworkId) {
|
|
18406
18469
|
const entries = [];
|
|
18407
|
-
const path = action === "list" ? (0,
|
|
18470
|
+
const path = action === "list" ? (0, import_sdk_core5.resolveSecretListPrefix)(options) : (0, import_sdk_core5.resolveSecretPath)(name, options).permissionPaths.vault;
|
|
18408
18471
|
entries.push({
|
|
18409
18472
|
service: "tinycloud.kv",
|
|
18410
18473
|
space: SECRETS_SPACE,
|
|
@@ -18483,7 +18546,7 @@ var NodeSecretsService = class {
|
|
|
18483
18546
|
);
|
|
18484
18547
|
} catch (error) {
|
|
18485
18548
|
return secretsError(
|
|
18486
|
-
|
|
18549
|
+
import_sdk_core5.ErrorCodes.INVALID_INPUT,
|
|
18487
18550
|
error instanceof Error ? error.message : String(error),
|
|
18488
18551
|
error instanceof Error ? error : void 0
|
|
18489
18552
|
);
|
|
@@ -18493,7 +18556,7 @@ var NodeSecretsService = class {
|
|
|
18493
18556
|
}
|
|
18494
18557
|
if (!this.config.canEscalate()) {
|
|
18495
18558
|
return secretsError(
|
|
18496
|
-
|
|
18559
|
+
import_sdk_core5.ErrorCodes.PERMISSION_DENIED,
|
|
18497
18560
|
`Cannot autosign ${displayActionUrn(action)} for ${target}; TinyCloudNode needs wallet mode with a signer or privateKey.`
|
|
18498
18561
|
);
|
|
18499
18562
|
}
|
|
@@ -18502,7 +18565,7 @@ var NodeSecretsService = class {
|
|
|
18502
18565
|
return this.restoreUnlockAfterEscalation();
|
|
18503
18566
|
} catch (error) {
|
|
18504
18567
|
return secretsError(
|
|
18505
|
-
|
|
18568
|
+
import_sdk_core5.ErrorCodes.PERMISSION_DENIED,
|
|
18506
18569
|
error instanceof Error ? error.message : `Autosign escalation for ${displayActionUrn(action)} on ${target} failed.`,
|
|
18507
18570
|
error instanceof Error ? error : void 0
|
|
18508
18571
|
);
|
|
@@ -18523,10 +18586,10 @@ var NodeSecretsService = class {
|
|
|
18523
18586
|
return false;
|
|
18524
18587
|
}
|
|
18525
18588
|
const manifests = Array.isArray(manifest) ? manifest : [manifest];
|
|
18526
|
-
const requestedEntries = (0,
|
|
18589
|
+
const requestedEntries = (0, import_sdk_core5.expandPermissionEntries)(permissionEntries);
|
|
18527
18590
|
return requestedEntries.every(
|
|
18528
18591
|
(entry) => manifests.some((candidate) => {
|
|
18529
|
-
const resolved = (0,
|
|
18592
|
+
const resolved = (0, import_sdk_core5.resolveManifest)(candidate);
|
|
18530
18593
|
return resolved.resources.some(
|
|
18531
18594
|
(resource) => resource.service === entry.service && resource.space === entry.space && resource.path === entry.path && entry.actions.every((action) => resource.actions.includes(action))
|
|
18532
18595
|
);
|
|
@@ -18538,13 +18601,13 @@ var NodeSecretsService = class {
|
|
|
18538
18601
|
// src/TinyCloudNode.ts
|
|
18539
18602
|
var DEFAULT_HOST = "https://node.tinycloud.xyz";
|
|
18540
18603
|
var DEFAULT_ENCRYPTION_NETWORK_NAME = "default";
|
|
18541
|
-
var
|
|
18542
|
-
var
|
|
18604
|
+
var NETWORK_CREATE_ACTION2 = "tinycloud.encryption/network.create";
|
|
18605
|
+
var DECRYPT_ACTION2 = "tinycloud.encryption/decrypt";
|
|
18543
18606
|
var NETWORK_ADMIN_TYPE = "tinycloud.encryption.network-admin/v1";
|
|
18544
|
-
var DEFAULT_SESSION_EXPIRATION_MS =
|
|
18545
|
-
function
|
|
18607
|
+
var DEFAULT_SESSION_EXPIRATION_MS = import_sdk_core6.EXPIRY.SESSION_MS;
|
|
18608
|
+
function didPrincipalMatches2(actual, expected) {
|
|
18546
18609
|
try {
|
|
18547
|
-
return (0,
|
|
18610
|
+
return (0, import_sdk_core6.principalDidEquals)(actual, expected);
|
|
18548
18611
|
} catch {
|
|
18549
18612
|
return actual === expected;
|
|
18550
18613
|
}
|
|
@@ -18710,12 +18773,12 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18710
18773
|
throw new Error("Failed to get session key JWK");
|
|
18711
18774
|
}
|
|
18712
18775
|
this.sessionKeyJwk = JSON.parse(jwkStr);
|
|
18713
|
-
this._capabilityRegistry = new
|
|
18776
|
+
this._capabilityRegistry = new import_sdk_core6.CapabilityKeyRegistry();
|
|
18714
18777
|
this._keyProvider = new WasmKeyProvider({
|
|
18715
18778
|
sessionManager: this.sessionManager
|
|
18716
18779
|
});
|
|
18717
|
-
this.notificationHandler = config.notificationHandler ?? new
|
|
18718
|
-
this._sharingService = new
|
|
18780
|
+
this.notificationHandler = config.notificationHandler ?? new import_sdk_core6.SilentNotificationHandler();
|
|
18781
|
+
this._sharingService = new import_sdk_core6.SharingService({
|
|
18719
18782
|
hosts: [this.config.host],
|
|
18720
18783
|
// session: undefined - not needed for receive()
|
|
18721
18784
|
invoke: this.invokeWithRuntimePermissions,
|
|
@@ -18725,8 +18788,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18725
18788
|
// delegationManager: undefined - not needed for receive()
|
|
18726
18789
|
createKVService: (config2) => {
|
|
18727
18790
|
const prefix = config2.pathPrefix?.replace(/\/$/, "");
|
|
18728
|
-
const kvService = new
|
|
18729
|
-
const kvContext = new
|
|
18791
|
+
const kvService = new import_sdk_core6.KVService({ prefix });
|
|
18792
|
+
const kvContext = new import_sdk_core6.ServiceContext({
|
|
18730
18793
|
invoke: config2.invoke,
|
|
18731
18794
|
fetch: config2.fetch ?? globalThis.fetch.bind(globalThis),
|
|
18732
18795
|
hosts: config2.hosts,
|
|
@@ -18786,7 +18849,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18786
18849
|
capabilityRequest: config.capabilityRequest,
|
|
18787
18850
|
includeAccountRegistryPermissions: config.includeAccountRegistryPermissions
|
|
18788
18851
|
});
|
|
18789
|
-
this.tc = new
|
|
18852
|
+
this.tc = new import_sdk_core6.TinyCloud(this.auth, {
|
|
18790
18853
|
invokeAny: this.invokeAnyWithRuntimePermissions,
|
|
18791
18854
|
telemetry: config.telemetry
|
|
18792
18855
|
});
|
|
@@ -18847,7 +18910,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18847
18910
|
*/
|
|
18848
18911
|
get did() {
|
|
18849
18912
|
if (this._address) {
|
|
18850
|
-
return (0,
|
|
18913
|
+
return (0, import_sdk_core6.pkhDid)(this._address, this._chainId);
|
|
18851
18914
|
}
|
|
18852
18915
|
return this.sessionManager.getDID(this.sessionKeyId);
|
|
18853
18916
|
}
|
|
@@ -18881,6 +18944,37 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18881
18944
|
get spaceId() {
|
|
18882
18945
|
return this.auth?.tinyCloudSession?.spaceId;
|
|
18883
18946
|
}
|
|
18947
|
+
/**
|
|
18948
|
+
* Get the account space ID for this wallet identity.
|
|
18949
|
+
* Available after wallet-backed sign-in or a restored session with address metadata.
|
|
18950
|
+
*/
|
|
18951
|
+
get accountSpaceId() {
|
|
18952
|
+
if (!this._address) {
|
|
18953
|
+
return void 0;
|
|
18954
|
+
}
|
|
18955
|
+
return this.wasmBindings.makeSpaceId(this._address, this._chainId, import_sdk_core6.ACCOUNT_REGISTRY_SPACE);
|
|
18956
|
+
}
|
|
18957
|
+
/**
|
|
18958
|
+
* Account-level application and delegation helpers.
|
|
18959
|
+
*/
|
|
18960
|
+
get account() {
|
|
18961
|
+
if (!this._account) {
|
|
18962
|
+
this._account = new import_sdk_core2.AccountService({
|
|
18963
|
+
getDid: () => this.did,
|
|
18964
|
+
getHost: () => this.hosts[0] ?? this.config.host,
|
|
18965
|
+
getPrimarySpaceId: () => this.spaceId,
|
|
18966
|
+
getAccountSpaceId: () => this.accountSpaceId,
|
|
18967
|
+
getSpaces: () => this.spaces,
|
|
18968
|
+
getAccountDb: () => this.accountSpaceId ? this.sqlForSpace(this.accountSpaceId).db("account") : void 0,
|
|
18969
|
+
ensureAccountSpaceHosted: async () => {
|
|
18970
|
+
if (this.accountSpaceId && this.auth) {
|
|
18971
|
+
await this.ensureOwnedSpaceHostedById(this.accountSpaceId);
|
|
18972
|
+
}
|
|
18973
|
+
}
|
|
18974
|
+
});
|
|
18975
|
+
}
|
|
18976
|
+
return this._account;
|
|
18977
|
+
}
|
|
18884
18978
|
/**
|
|
18885
18979
|
* Get the current TinyCloud session.
|
|
18886
18980
|
* Available after signIn().
|
|
@@ -18902,7 +18996,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18902
18996
|
);
|
|
18903
18997
|
}
|
|
18904
18998
|
await this.wasmBindings.ensureInitialized?.();
|
|
18905
|
-
this._address = (0,
|
|
18999
|
+
this._address = (0, import_sdk_core6.canonicalizeAddress)(await this.signer.getAddress());
|
|
18906
19000
|
this._chainId = await this.signer.getChainId();
|
|
18907
19001
|
this._kv = void 0;
|
|
18908
19002
|
this._sql = void 0;
|
|
@@ -18918,10 +19012,11 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18918
19012
|
await this.tc.signIn(options);
|
|
18919
19013
|
this.syncResolvedHostFromAuth();
|
|
18920
19014
|
this.initializeServices();
|
|
19015
|
+
await this.ensureRequestedEncryptionNetworks();
|
|
18921
19016
|
if (this.config.manifest === void 0 && this.config.capabilityRequest === void 0) {
|
|
18922
|
-
await this.
|
|
19017
|
+
await this.ensureOwnedSpaceHostedById(this.ownedSpaceId("secrets"));
|
|
18923
19018
|
}
|
|
18924
|
-
|
|
19019
|
+
this.scheduleAccountRegistrySync();
|
|
18925
19020
|
this.notificationHandler.success("Successfully signed in");
|
|
18926
19021
|
}
|
|
18927
19022
|
ownedSpaceId(name) {
|
|
@@ -18938,23 +19033,69 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18938
19033
|
if (!this.auth || !this.signer) {
|
|
18939
19034
|
throw new Error("Manifest registry write requires wallet mode");
|
|
18940
19035
|
}
|
|
18941
|
-
const accountSpaceId = this.ownedSpaceId(
|
|
18942
|
-
await this.
|
|
18943
|
-
const
|
|
18944
|
-
|
|
18945
|
-
|
|
18946
|
-
|
|
18947
|
-
|
|
18948
|
-
|
|
18949
|
-
|
|
18950
|
-
|
|
18951
|
-
|
|
18952
|
-
|
|
18953
|
-
|
|
19036
|
+
const accountSpaceId = this.ownedSpaceId(import_sdk_core6.ACCOUNT_REGISTRY_SPACE);
|
|
19037
|
+
await this.ensureOwnedSpaceHostedById(accountSpaceId);
|
|
19038
|
+
const result = await this.account.applications.register(request.manifests);
|
|
19039
|
+
if (!result.ok) {
|
|
19040
|
+
throw new Error(
|
|
19041
|
+
`Failed to write manifest registry records: ${result.error.message}`
|
|
19042
|
+
);
|
|
19043
|
+
}
|
|
19044
|
+
}
|
|
19045
|
+
scheduleAccountRegistrySync() {
|
|
19046
|
+
void this.withAccountRegistryRetry(async () => {
|
|
19047
|
+
await this.writeManifestRegistryRecords();
|
|
19048
|
+
const spaces = await this.account.spaces.syncAccessible();
|
|
19049
|
+
if (!spaces.ok) {
|
|
19050
|
+
throw new Error(`Failed to sync account spaces: ${spaces.error.message}`);
|
|
19051
|
+
}
|
|
19052
|
+
});
|
|
19053
|
+
}
|
|
19054
|
+
async withAccountRegistryRetry(task) {
|
|
19055
|
+
const delays = [250, 1e3, 3e3];
|
|
19056
|
+
let lastError;
|
|
19057
|
+
for (let attempt = 0; attempt < delays.length; attempt += 1) {
|
|
19058
|
+
try {
|
|
19059
|
+
await task();
|
|
19060
|
+
return;
|
|
19061
|
+
} catch (error) {
|
|
19062
|
+
lastError = error;
|
|
19063
|
+
if (attempt < delays.length - 1) {
|
|
19064
|
+
await new Promise((resolve) => setTimeout(resolve, delays[attempt]));
|
|
19065
|
+
}
|
|
19066
|
+
}
|
|
19067
|
+
}
|
|
19068
|
+
console.warn(
|
|
19069
|
+
"TinyCloud account registry sync failed after retries",
|
|
19070
|
+
lastError
|
|
19071
|
+
);
|
|
19072
|
+
}
|
|
19073
|
+
requestedEncryptionNetworkIds() {
|
|
19074
|
+
const request = this.capabilityRequest;
|
|
19075
|
+
if (!request) {
|
|
19076
|
+
return [];
|
|
19077
|
+
}
|
|
19078
|
+
const networkIds = /* @__PURE__ */ new Set();
|
|
19079
|
+
for (const resource of request.resources) {
|
|
19080
|
+
if (resource.service === import_sdk_core6.ENCRYPTION_PERMISSION_SERVICE && resource.path.startsWith("urn:tinycloud:encryption:") && resource.actions.includes(DECRYPT_ACTION2)) {
|
|
19081
|
+
networkIds.add(resource.path);
|
|
18954
19082
|
}
|
|
18955
19083
|
}
|
|
19084
|
+
return [...networkIds];
|
|
18956
19085
|
}
|
|
18957
|
-
async
|
|
19086
|
+
async ensureRequestedEncryptionNetworks() {
|
|
19087
|
+
if (!this.signer || !this.auth) {
|
|
19088
|
+
return;
|
|
19089
|
+
}
|
|
19090
|
+
for (const networkId of this.requestedEncryptionNetworkIds()) {
|
|
19091
|
+
const parsed = (0, import_sdk_core6.parseNetworkId)(networkId);
|
|
19092
|
+
if (!didPrincipalMatches2(parsed.ownerDid, this.did)) {
|
|
19093
|
+
continue;
|
|
19094
|
+
}
|
|
19095
|
+
await this.ensureEncryptionNetwork(networkId);
|
|
19096
|
+
}
|
|
19097
|
+
}
|
|
19098
|
+
async ensureOwnedSpaceHostedById(spaceId) {
|
|
18958
19099
|
if (!this.auth) {
|
|
18959
19100
|
throw new Error("Owned space hosting requires wallet mode");
|
|
18960
19101
|
}
|
|
@@ -18966,7 +19107,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18966
19107
|
if (!host) {
|
|
18967
19108
|
throw new Error("Owned space hosting requires a TinyCloud host");
|
|
18968
19109
|
}
|
|
18969
|
-
const activation = await (0,
|
|
19110
|
+
const activation = await (0, import_sdk_core6.activateSessionWithHost)(host, session.delegationHeader);
|
|
18970
19111
|
if (activation.success && !activation.skipped?.includes(spaceId)) {
|
|
18971
19112
|
return;
|
|
18972
19113
|
}
|
|
@@ -18980,7 +19121,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18980
19121
|
throw new Error(`Failed to create owned space: ${spaceId}`);
|
|
18981
19122
|
}
|
|
18982
19123
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
18983
|
-
const retry = await (0,
|
|
19124
|
+
const retry = await (0, import_sdk_core6.activateSessionWithHost)(host, session.delegationHeader);
|
|
18984
19125
|
if (!retry.success || retry.skipped?.includes(spaceId)) {
|
|
18985
19126
|
throw new Error(
|
|
18986
19127
|
`Failed to activate session after creating owned space ${spaceId}: ${retry.error ?? "space was skipped"}`
|
|
@@ -18997,7 +19138,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
18997
19138
|
* caller is the root authority of their own owned spaces, so no additional
|
|
18998
19139
|
* delegation is required.
|
|
18999
19140
|
*
|
|
19000
|
-
* Unlike {@link
|
|
19141
|
+
* Unlike {@link ensureOwnedSpaceHostedById}, this always submits the host
|
|
19001
19142
|
* delegation rather than inferring hosting from session activation: a space
|
|
19002
19143
|
* the current session has never referenced is reported neither as
|
|
19003
19144
|
* `activated` nor `skipped`, so activation-based detection would wrongly
|
|
@@ -19022,7 +19163,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19022
19163
|
if (!hosted) {
|
|
19023
19164
|
throw new Error(`Failed to host owned space: ${spaceId}`);
|
|
19024
19165
|
}
|
|
19025
|
-
const activation = await (0,
|
|
19166
|
+
const activation = await (0, import_sdk_core6.activateSessionWithHost)(
|
|
19026
19167
|
host,
|
|
19027
19168
|
this.auth.tinyCloudSession.delegationHeader
|
|
19028
19169
|
);
|
|
@@ -19031,8 +19172,40 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19031
19172
|
`Failed to activate session for owned space ${spaceId}: ${activation.error ?? "space was skipped"}`
|
|
19032
19173
|
);
|
|
19033
19174
|
}
|
|
19175
|
+
void this.account.spaces.register({
|
|
19176
|
+
spaceId,
|
|
19177
|
+
name,
|
|
19178
|
+
ownerDid: this.did,
|
|
19179
|
+
type: "owned",
|
|
19180
|
+
permissions: ["*"],
|
|
19181
|
+
status: "active"
|
|
19182
|
+
}).catch(() => {
|
|
19183
|
+
});
|
|
19034
19184
|
return spaceId;
|
|
19035
19185
|
}
|
|
19186
|
+
/**
|
|
19187
|
+
* Ensure one of this user's owned spaces (e.g. `"secrets"`) is hosted on the
|
|
19188
|
+
* server.
|
|
19189
|
+
*
|
|
19190
|
+
* At sign-in, a full-authority session auto-hosts the owner's `secrets`
|
|
19191
|
+
* space, but a session created with a manifest / capabilityRequest does not.
|
|
19192
|
+
* Such a session can therefore hold valid `tinycloud.kv/*` capabilities for
|
|
19193
|
+
* the owned `secrets` space yet still fail its first scoped
|
|
19194
|
+
* `secrets.put(...)` with `404 Space not found`, because the space was never
|
|
19195
|
+
* registered on the node.
|
|
19196
|
+
*
|
|
19197
|
+
* Calling this resolves `name` to the owner's owned-space URI
|
|
19198
|
+
* (`tinycloud:pkh:eip155:<chain>:<addr>:<name>`) and hosts it via the
|
|
19199
|
+
* host-SIWE delegation flow. The host SIWE is idempotent server-side, so it
|
|
19200
|
+
* is safe to call whether or not the space already exists; do not gate it on
|
|
19201
|
+
* a prior existence check. Must be called after {@link signIn}.
|
|
19202
|
+
*
|
|
19203
|
+
* @param name - The owned space name (e.g. `"secrets"`).
|
|
19204
|
+
* @returns The hosted owned-space URI.
|
|
19205
|
+
*/
|
|
19206
|
+
async ensureOwnedSpaceHosted(name) {
|
|
19207
|
+
return this.hostOwnedSpace(name);
|
|
19208
|
+
}
|
|
19036
19209
|
/**
|
|
19037
19210
|
* Restore a previously established session from stored delegation data.
|
|
19038
19211
|
*
|
|
@@ -19055,30 +19228,38 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19055
19228
|
this._spaceService = void 0;
|
|
19056
19229
|
this._serviceContext = void 0;
|
|
19057
19230
|
this.runtimePermissionGrants = [];
|
|
19058
|
-
const restoredAddress = sessionData.address ? (0,
|
|
19231
|
+
const restoredAddress = sessionData.address ? (0, import_sdk_core6.canonicalizeAddress)(sessionData.address) : void 0;
|
|
19059
19232
|
if (restoredAddress) {
|
|
19060
19233
|
this._address = restoredAddress;
|
|
19061
19234
|
}
|
|
19062
19235
|
if (sessionData.chainId) {
|
|
19063
19236
|
this._chainId = sessionData.chainId;
|
|
19064
19237
|
}
|
|
19065
|
-
|
|
19238
|
+
const resolvedHost = await this.resolveRestoredHost(
|
|
19239
|
+
sessionData.tinycloudHosts,
|
|
19240
|
+
restoredAddress,
|
|
19241
|
+
sessionData.chainId
|
|
19242
|
+
);
|
|
19243
|
+
if (resolvedHost) {
|
|
19244
|
+
this.config.host = resolvedHost;
|
|
19245
|
+
}
|
|
19246
|
+
this._serviceContext = new import_sdk_core6.ServiceContext({
|
|
19066
19247
|
invoke: this.invokeWithRuntimePermissions,
|
|
19067
19248
|
invokeAny: this.invokeAnyWithRuntimePermissions,
|
|
19068
19249
|
fetch: globalThis.fetch.bind(globalThis),
|
|
19069
19250
|
hosts: [this.config.host],
|
|
19070
19251
|
telemetry: this.config.telemetry
|
|
19071
19252
|
});
|
|
19072
|
-
this._kv = new
|
|
19253
|
+
this._kv = new import_sdk_core6.KVService({});
|
|
19073
19254
|
this._kv.initialize(this._serviceContext);
|
|
19074
19255
|
this._serviceContext.registerService("kv", this._kv);
|
|
19075
|
-
this._sql = new
|
|
19256
|
+
this._sql = new import_sdk_core6.SQLService({});
|
|
19076
19257
|
this._sql.initialize(this._serviceContext);
|
|
19077
19258
|
this._serviceContext.registerService("sql", this._sql);
|
|
19078
|
-
this._duckdb = new
|
|
19259
|
+
this._duckdb = new import_sdk_core6.DuckDbService({});
|
|
19079
19260
|
this._duckdb.initialize(this._serviceContext);
|
|
19080
19261
|
this._serviceContext.registerService("duckdb", this._duckdb);
|
|
19081
|
-
this._hooks = new
|
|
19262
|
+
this._hooks = new import_sdk_core6.HooksService({});
|
|
19082
19263
|
this._hooks.initialize(this._serviceContext);
|
|
19083
19264
|
this._serviceContext.registerService("hooks", this._hooks);
|
|
19084
19265
|
const serviceSession = {
|
|
@@ -19107,12 +19288,45 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19107
19288
|
signature: sessionData.signature ?? ""
|
|
19108
19289
|
};
|
|
19109
19290
|
if (this.auth) {
|
|
19110
|
-
this.auth.setRestoredTinyCloudSession(
|
|
19291
|
+
this.auth.setRestoredTinyCloudSession(
|
|
19292
|
+
tcSession,
|
|
19293
|
+
this.config.host ? [this.config.host] : void 0
|
|
19294
|
+
);
|
|
19111
19295
|
} else {
|
|
19112
19296
|
this._restoredTcSession = tcSession;
|
|
19113
19297
|
}
|
|
19114
19298
|
}
|
|
19115
19299
|
}
|
|
19300
|
+
/**
|
|
19301
|
+
* Resolve the host a restored session should target.
|
|
19302
|
+
*
|
|
19303
|
+
* Mirrors fresh sign-in host resolution but for the restore path:
|
|
19304
|
+
* an explicit/pinned host always wins, then the hosts the session was
|
|
19305
|
+
* persisted with, then a lazy registry/fallback resolution for sessions
|
|
19306
|
+
* that predate the persisted `tinycloudHosts` field. Returns `undefined`
|
|
19307
|
+
* only when there's nothing to resolve from (no explicit host, no
|
|
19308
|
+
* persisted hosts, and no address/chainId) — in which case the existing
|
|
19309
|
+
* `config.host` (default) is left in place.
|
|
19310
|
+
*
|
|
19311
|
+
* Resolution failures are surfaced, not swallowed: a genuinely broken
|
|
19312
|
+
* registry lookup throws rather than silently falling back to a wrong host.
|
|
19313
|
+
*/
|
|
19314
|
+
async resolveRestoredHost(persistedHosts, address, chainId) {
|
|
19315
|
+
if (this.explicitHost) {
|
|
19316
|
+
return this.explicitHost;
|
|
19317
|
+
}
|
|
19318
|
+
if (persistedHosts && persistedHosts.length > 0) {
|
|
19319
|
+
return persistedHosts[0];
|
|
19320
|
+
}
|
|
19321
|
+
if (address === void 0 || chainId === void 0) {
|
|
19322
|
+
return void 0;
|
|
19323
|
+
}
|
|
19324
|
+
const resolved = await (0, import_sdk_core6.resolveTinyCloudHosts)((0, import_sdk_core6.pkhDid)(address, chainId), {
|
|
19325
|
+
registryUrl: this.config.tinycloudRegistryUrl,
|
|
19326
|
+
fallbackHosts: this.config.tinycloudFallbackHosts
|
|
19327
|
+
});
|
|
19328
|
+
return resolved.hosts[0];
|
|
19329
|
+
}
|
|
19116
19330
|
/**
|
|
19117
19331
|
* Resolve the currently-active TinyCloudSession, preferring the auth
|
|
19118
19332
|
* layer's value (wallet mode) and falling back to the node-level
|
|
@@ -19177,7 +19391,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19177
19391
|
capabilityRequest: this.config.capabilityRequest,
|
|
19178
19392
|
includeAccountRegistryPermissions: this.config.includeAccountRegistryPermissions
|
|
19179
19393
|
});
|
|
19180
|
-
this.tc = new
|
|
19394
|
+
this.tc = new import_sdk_core6.TinyCloud(this.auth, {
|
|
19181
19395
|
invokeAny: this.invokeAnyWithRuntimePermissions,
|
|
19182
19396
|
telemetry: this.config.telemetry
|
|
19183
19397
|
});
|
|
@@ -19222,7 +19436,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19222
19436
|
capabilityRequest: this.config.capabilityRequest,
|
|
19223
19437
|
includeAccountRegistryPermissions: this.config.includeAccountRegistryPermissions
|
|
19224
19438
|
});
|
|
19225
|
-
this.tc = new
|
|
19439
|
+
this.tc = new import_sdk_core6.TinyCloud(this.auth, {
|
|
19226
19440
|
invokeAny: this.invokeAnyWithRuntimePermissions,
|
|
19227
19441
|
telemetry: this.config.telemetry
|
|
19228
19442
|
});
|
|
@@ -19238,28 +19452,28 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19238
19452
|
return;
|
|
19239
19453
|
}
|
|
19240
19454
|
this.tc.initializeServices(this.invokeWithRuntimePermissions, [this.config.host]);
|
|
19241
|
-
this._serviceContext = new
|
|
19455
|
+
this._serviceContext = new import_sdk_core6.ServiceContext({
|
|
19242
19456
|
invoke: this.invokeWithRuntimePermissions,
|
|
19243
19457
|
invokeAny: this.invokeAnyWithRuntimePermissions,
|
|
19244
19458
|
fetch: globalThis.fetch.bind(globalThis),
|
|
19245
19459
|
hosts: [this.config.host],
|
|
19246
19460
|
telemetry: this.config.telemetry
|
|
19247
19461
|
});
|
|
19248
|
-
this._kv = new
|
|
19462
|
+
this._kv = new import_sdk_core6.KVService({});
|
|
19249
19463
|
this._kv.initialize(this._serviceContext);
|
|
19250
19464
|
this._serviceContext.registerService("kv", this._kv);
|
|
19251
19465
|
const features = this.nodeFeatures;
|
|
19252
19466
|
if (features.length === 0 || features.includes("sql")) {
|
|
19253
|
-
this._sql = new
|
|
19467
|
+
this._sql = new import_sdk_core6.SQLService({});
|
|
19254
19468
|
this._sql.initialize(this._serviceContext);
|
|
19255
19469
|
this._serviceContext.registerService("sql", this._sql);
|
|
19256
19470
|
}
|
|
19257
19471
|
if (features.length === 0 || features.includes("duckdb")) {
|
|
19258
|
-
this._duckdb = new
|
|
19472
|
+
this._duckdb = new import_sdk_core6.DuckDbService({});
|
|
19259
19473
|
this._duckdb.initialize(this._serviceContext);
|
|
19260
19474
|
this._serviceContext.registerService("duckdb", this._duckdb);
|
|
19261
19475
|
}
|
|
19262
|
-
this._hooks = new
|
|
19476
|
+
this._hooks = new import_sdk_core6.HooksService({});
|
|
19263
19477
|
this._hooks.initialize(this._serviceContext);
|
|
19264
19478
|
this._serviceContext.registerService("hooks", this._hooks);
|
|
19265
19479
|
const serviceSession = {
|
|
@@ -19277,9 +19491,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19277
19491
|
this.initializeV2Services(serviceSession);
|
|
19278
19492
|
}
|
|
19279
19493
|
createSpaceScopedKVService(spaceId) {
|
|
19280
|
-
const kvService = new
|
|
19494
|
+
const kvService = new import_sdk_core6.KVService({});
|
|
19281
19495
|
if (this._serviceContext) {
|
|
19282
|
-
const spaceScopedContext = new
|
|
19496
|
+
const spaceScopedContext = new import_sdk_core6.ServiceContext({
|
|
19283
19497
|
invoke: this._serviceContext.invoke,
|
|
19284
19498
|
fetch: this._serviceContext.fetch,
|
|
19285
19499
|
hosts: this._serviceContext.hosts,
|
|
@@ -19344,7 +19558,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19344
19558
|
const shared = wasm.vault_x25519_dh(receiverPrivateKey, peerPublic);
|
|
19345
19559
|
return columnDecrypt(shared, ciphertext);
|
|
19346
19560
|
},
|
|
19347
|
-
verifyNodeSignature: (nodeId, message, signature2) => (0,
|
|
19561
|
+
verifyNodeSignature: (nodeId, message, signature2) => (0, import_sdk_core6.verifyDidKeyEd25519Signature)(nodeId, message, signature2)
|
|
19348
19562
|
};
|
|
19349
19563
|
}
|
|
19350
19564
|
async fetchNodeId() {
|
|
@@ -19415,19 +19629,19 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19415
19629
|
return await response.json();
|
|
19416
19630
|
}
|
|
19417
19631
|
};
|
|
19418
|
-
return new
|
|
19632
|
+
return new import_sdk_core6.EncryptionService({
|
|
19419
19633
|
crypto: crypto2,
|
|
19420
19634
|
signer: {
|
|
19421
19635
|
signDecryptInvocation: async (input) => {
|
|
19422
19636
|
const signed2 = await this.signRawNetworkAuthorization({
|
|
19423
19637
|
targetNode: input.targetNode,
|
|
19424
19638
|
networkId: input.networkId,
|
|
19425
|
-
action:
|
|
19639
|
+
action: DECRYPT_ACTION2,
|
|
19426
19640
|
facts: input.facts
|
|
19427
19641
|
});
|
|
19428
19642
|
return {
|
|
19429
19643
|
...signed2,
|
|
19430
|
-
canonicalBody: (0,
|
|
19644
|
+
canonicalBody: (0, import_sdk_core6.canonicalizeEncryptionJson)(
|
|
19431
19645
|
input.body
|
|
19432
19646
|
)
|
|
19433
19647
|
};
|
|
@@ -19439,14 +19653,14 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19439
19653
|
},
|
|
19440
19654
|
wellKnown: {
|
|
19441
19655
|
fetchWellKnown: async (principal, discoveryKey) => {
|
|
19442
|
-
if (!this._address || !
|
|
19656
|
+
if (!this._address || !didPrincipalMatches2(principal, this.did)) {
|
|
19443
19657
|
return null;
|
|
19444
19658
|
}
|
|
19445
19659
|
if (!this.config.host) {
|
|
19446
19660
|
return null;
|
|
19447
19661
|
}
|
|
19448
|
-
const publicSpaceId = (0,
|
|
19449
|
-
const result = await
|
|
19662
|
+
const publicSpaceId = (0, import_sdk_core6.makePublicSpaceId)(this._address, this._chainId);
|
|
19663
|
+
const result = await import_sdk_core6.TinyCloud.readPublicSpace(this.config.host, publicSpaceId, discoveryKey);
|
|
19450
19664
|
if (!result.ok) {
|
|
19451
19665
|
return null;
|
|
19452
19666
|
}
|
|
@@ -19469,7 +19683,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19469
19683
|
}
|
|
19470
19684
|
createVaultService(spaceId, kv) {
|
|
19471
19685
|
const wasm = this.wasmBindings;
|
|
19472
|
-
const vaultCrypto = (0,
|
|
19686
|
+
const vaultCrypto = (0, import_sdk_core6.createVaultCrypto)({
|
|
19473
19687
|
vault_encrypt: wasm.vault_encrypt,
|
|
19474
19688
|
vault_decrypt: wasm.vault_decrypt,
|
|
19475
19689
|
vault_derive_key: wasm.vault_derive_key,
|
|
@@ -19479,7 +19693,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19479
19693
|
vault_sha256: wasm.vault_sha256
|
|
19480
19694
|
});
|
|
19481
19695
|
const self2 = this;
|
|
19482
|
-
return new
|
|
19696
|
+
return new import_sdk_core6.DataVaultService({
|
|
19483
19697
|
spaceId,
|
|
19484
19698
|
crypto: vaultCrypto,
|
|
19485
19699
|
encryption: {
|
|
@@ -19502,8 +19716,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19502
19716
|
get publicKV() {
|
|
19503
19717
|
return self2._publicKV ?? self2.tc.publicKV;
|
|
19504
19718
|
},
|
|
19505
|
-
readPublicSpace: (host, targetSpaceId, key2) =>
|
|
19506
|
-
makePublicSpaceId:
|
|
19719
|
+
readPublicSpace: (host, targetSpaceId, key2) => import_sdk_core6.TinyCloud.readPublicSpace(host, targetSpaceId, key2),
|
|
19720
|
+
makePublicSpaceId: import_sdk_core6.TinyCloud.makePublicSpaceId,
|
|
19507
19721
|
did: this.did,
|
|
19508
19722
|
address: this._address ?? "",
|
|
19509
19723
|
chainId: this._chainId,
|
|
@@ -19516,7 +19730,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19516
19730
|
* @internal
|
|
19517
19731
|
*/
|
|
19518
19732
|
initializeV2Services(serviceSession) {
|
|
19519
|
-
this._capabilityRegistry = new
|
|
19733
|
+
this._capabilityRegistry = new import_sdk_core6.CapabilityKeyRegistry();
|
|
19520
19734
|
const tcSession = this.auth?.tinyCloudSession;
|
|
19521
19735
|
if (tcSession && this._address) {
|
|
19522
19736
|
const sessionKey = {
|
|
@@ -19590,13 +19804,13 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19590
19804
|
}
|
|
19591
19805
|
this._capabilityRegistry.registerKey(sessionKey, delegations);
|
|
19592
19806
|
}
|
|
19593
|
-
this._delegationManager = new
|
|
19807
|
+
this._delegationManager = new import_sdk_core6.DelegationManager({
|
|
19594
19808
|
hosts: [this.config.host],
|
|
19595
19809
|
session: serviceSession,
|
|
19596
19810
|
invoke: this.invokeWithRuntimePermissions,
|
|
19597
19811
|
fetch: globalThis.fetch.bind(globalThis)
|
|
19598
19812
|
});
|
|
19599
|
-
this._spaceService = new
|
|
19813
|
+
this._spaceService = new import_sdk_core6.SpaceService({
|
|
19600
19814
|
hosts: [this.config.host],
|
|
19601
19815
|
session: serviceSession,
|
|
19602
19816
|
invoke: this.wasmBindings.invoke,
|
|
@@ -19648,6 +19862,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19648
19862
|
}
|
|
19649
19863
|
};
|
|
19650
19864
|
}
|
|
19865
|
+
},
|
|
19866
|
+
onSpaceRegistered: async (space) => {
|
|
19867
|
+
await this.account.spaces.register(space);
|
|
19651
19868
|
}
|
|
19652
19869
|
});
|
|
19653
19870
|
this._sharingService.updateConfig({
|
|
@@ -19753,7 +19970,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19753
19970
|
...prepared,
|
|
19754
19971
|
signature: signature2
|
|
19755
19972
|
});
|
|
19756
|
-
const activateResult = await (0,
|
|
19973
|
+
const activateResult = await (0, import_sdk_core6.activateSessionWithHost)(
|
|
19757
19974
|
host,
|
|
19758
19975
|
delegationSession.delegationHeader
|
|
19759
19976
|
);
|
|
@@ -19763,7 +19980,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19763
19980
|
return {
|
|
19764
19981
|
cid: delegationSession.delegationCid,
|
|
19765
19982
|
delegateDID: params.shareKeyDID,
|
|
19766
|
-
delegatorDID: (0,
|
|
19983
|
+
delegatorDID: (0, import_sdk_core6.pkhDid)(session.address, session.chainId),
|
|
19767
19984
|
spaceId: params.spaceId,
|
|
19768
19985
|
path: params.path,
|
|
19769
19986
|
actions: params.actions,
|
|
@@ -19820,7 +20037,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19820
20037
|
if (!this._sql) {
|
|
19821
20038
|
const features = this.nodeFeatures;
|
|
19822
20039
|
if (features.length > 0 && !features.includes("sql")) {
|
|
19823
|
-
throw new
|
|
20040
|
+
throw new import_sdk_core6.UnsupportedFeatureError("sql", this.config.host, features);
|
|
19824
20041
|
}
|
|
19825
20042
|
throw new Error("Not signed in. Call signIn() first.");
|
|
19826
20043
|
}
|
|
@@ -19844,8 +20061,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19844
20061
|
if (!this._serviceContext || !this._serviceContext.session) {
|
|
19845
20062
|
throw new Error("Not signed in. Call signIn() first.");
|
|
19846
20063
|
}
|
|
19847
|
-
const sql = new
|
|
19848
|
-
const spaceScopedContext = new
|
|
20064
|
+
const sql = new import_sdk_core6.SQLService({});
|
|
20065
|
+
const spaceScopedContext = new import_sdk_core6.ServiceContext({
|
|
19849
20066
|
invoke: this._serviceContext.invoke,
|
|
19850
20067
|
fetch: this._serviceContext.fetch,
|
|
19851
20068
|
hosts: this._serviceContext.hosts,
|
|
@@ -19873,8 +20090,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19873
20090
|
if (!this._serviceContext || !this._serviceContext.session) {
|
|
19874
20091
|
throw new Error("Not signed in. Call signIn() first.");
|
|
19875
20092
|
}
|
|
19876
|
-
const kv = new
|
|
19877
|
-
const spaceScopedContext = new
|
|
20093
|
+
const kv = new import_sdk_core6.KVService({});
|
|
20094
|
+
const spaceScopedContext = new import_sdk_core6.ServiceContext({
|
|
19878
20095
|
invoke: this._serviceContext.invoke,
|
|
19879
20096
|
fetch: this._serviceContext.fetch,
|
|
19880
20097
|
hosts: this._serviceContext.hosts
|
|
@@ -19890,7 +20107,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19890
20107
|
if (!this._duckdb) {
|
|
19891
20108
|
const features = this.nodeFeatures;
|
|
19892
20109
|
if (features.length > 0 && !features.includes("duckdb")) {
|
|
19893
|
-
throw new
|
|
20110
|
+
throw new import_sdk_core6.UnsupportedFeatureError("duckdb", this.config.host, features);
|
|
19894
20111
|
}
|
|
19895
20112
|
throw new Error("Not signed in. Call signIn() first.");
|
|
19896
20113
|
}
|
|
@@ -19942,16 +20159,16 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19942
20159
|
type: NETWORK_ADMIN_TYPE,
|
|
19943
20160
|
targetNode,
|
|
19944
20161
|
networkId,
|
|
19945
|
-
bodyHash: (0,
|
|
20162
|
+
bodyHash: (0, import_sdk_core6.canonicalHashHex)(
|
|
19946
20163
|
crypto2.sha256,
|
|
19947
20164
|
body
|
|
19948
20165
|
),
|
|
19949
|
-
action:
|
|
20166
|
+
action: NETWORK_CREATE_ACTION2
|
|
19950
20167
|
};
|
|
19951
20168
|
const signed2 = await this.signRawNetworkAuthorization({
|
|
19952
20169
|
targetNode,
|
|
19953
20170
|
networkId,
|
|
19954
|
-
action:
|
|
20171
|
+
action: NETWORK_CREATE_ACTION2,
|
|
19955
20172
|
facts
|
|
19956
20173
|
});
|
|
19957
20174
|
const response = await fetch(`${this.config.host}/encryption/networks`, {
|
|
@@ -19960,7 +20177,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19960
20177
|
Authorization: signed2.authorization,
|
|
19961
20178
|
"Content-Type": "application/json"
|
|
19962
20179
|
},
|
|
19963
|
-
body: (0,
|
|
20180
|
+
body: (0, import_sdk_core6.canonicalizeEncryptionJson)(
|
|
19964
20181
|
body
|
|
19965
20182
|
)
|
|
19966
20183
|
});
|
|
@@ -19972,12 +20189,19 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
19972
20189
|
const created = await response.json();
|
|
19973
20190
|
return created.descriptor;
|
|
19974
20191
|
}
|
|
19975
|
-
async ensureEncryptionNetwork(
|
|
19976
|
-
const
|
|
20192
|
+
async ensureEncryptionNetwork(nameOrNetworkId = DEFAULT_ENCRYPTION_NETWORK_NAME) {
|
|
20193
|
+
const networkId = nameOrNetworkId.startsWith("urn:tinycloud:encryption:") ? nameOrNetworkId : this.getDefaultEncryptionNetworkId(nameOrNetworkId);
|
|
20194
|
+
const existing = await this.getEncryptionNetwork(networkId);
|
|
19977
20195
|
if (existing) {
|
|
19978
20196
|
return existing;
|
|
19979
20197
|
}
|
|
19980
|
-
|
|
20198
|
+
const parsed = (0, import_sdk_core6.parseNetworkId)(networkId);
|
|
20199
|
+
if (!didPrincipalMatches2(parsed.ownerDid, this.did)) {
|
|
20200
|
+
throw new Error(
|
|
20201
|
+
`Cannot create encryption network ${networkId}: owner ${parsed.ownerDid} does not match signed-in DID ${this.did}`
|
|
20202
|
+
);
|
|
20203
|
+
}
|
|
20204
|
+
return this.createEncryptionNetwork(parsed.name);
|
|
19981
20205
|
}
|
|
19982
20206
|
/**
|
|
19983
20207
|
* App-facing secrets API backed by the `secrets` space vault.
|
|
@@ -20004,7 +20228,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20004
20228
|
throw new Error("Not signed in. Call signIn() first.");
|
|
20005
20229
|
}
|
|
20006
20230
|
if (!this._baseSecrets) {
|
|
20007
|
-
this._baseSecrets = new
|
|
20231
|
+
this._baseSecrets = new import_sdk_core6.SecretsService(() => this.space("secrets").vault);
|
|
20008
20232
|
}
|
|
20009
20233
|
return this._baseSecrets;
|
|
20010
20234
|
}
|
|
@@ -20119,19 +20343,19 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20119
20343
|
async useRuntimeDelegation(delegation) {
|
|
20120
20344
|
const session = this.currentTinyCloudSession();
|
|
20121
20345
|
if (!session) {
|
|
20122
|
-
throw new
|
|
20346
|
+
throw new import_sdk_core6.SessionExpiredError(/* @__PURE__ */ new Date(0));
|
|
20123
20347
|
}
|
|
20124
20348
|
if (delegation.expiry.getTime() <= Date.now()) {
|
|
20125
|
-
throw new
|
|
20349
|
+
throw new import_sdk_core6.SessionExpiredError(delegation.expiry);
|
|
20126
20350
|
}
|
|
20127
20351
|
const expectedDids = [session.verificationMethod, this.sessionDid];
|
|
20128
|
-
if (!expectedDids.some((did) =>
|
|
20352
|
+
if (!expectedDids.some((did) => didPrincipalMatches2(delegation.delegateDID, did))) {
|
|
20129
20353
|
throw new Error(
|
|
20130
20354
|
`Runtime delegation targets ${delegation.delegateDID} but this session key is ${session.verificationMethod}.`
|
|
20131
20355
|
);
|
|
20132
20356
|
}
|
|
20133
20357
|
const targetHost = delegation.host ?? this.config.host;
|
|
20134
|
-
const activateResult = await (0,
|
|
20358
|
+
const activateResult = await (0, import_sdk_core6.activateSessionWithHost)(
|
|
20135
20359
|
targetHost,
|
|
20136
20360
|
delegation.delegationHeader
|
|
20137
20361
|
);
|
|
@@ -20158,13 +20382,13 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20158
20382
|
}
|
|
20159
20383
|
const session = this.currentTinyCloudSession();
|
|
20160
20384
|
if (!session) {
|
|
20161
|
-
throw new
|
|
20385
|
+
throw new import_sdk_core6.SessionExpiredError(/* @__PURE__ */ new Date(0));
|
|
20162
20386
|
}
|
|
20163
20387
|
const sessionExpiry = extractSiweExpiration(session.siwe);
|
|
20164
20388
|
if (sessionExpiry !== void 0) {
|
|
20165
20389
|
const marginMs = _TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS;
|
|
20166
20390
|
if (sessionExpiry.getTime() <= Date.now() + marginMs) {
|
|
20167
|
-
throw new
|
|
20391
|
+
throw new import_sdk_core6.SessionExpiredError(sessionExpiry);
|
|
20168
20392
|
}
|
|
20169
20393
|
}
|
|
20170
20394
|
const expanded = this.expandPermissionEntries(permissions);
|
|
@@ -20227,7 +20451,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20227
20451
|
...prepared,
|
|
20228
20452
|
signature: signature2
|
|
20229
20453
|
});
|
|
20230
|
-
const activateResult = await (0,
|
|
20454
|
+
const activateResult = await (0, import_sdk_core6.activateSessionWithHost)(
|
|
20231
20455
|
this.config.host,
|
|
20232
20456
|
delegatedSession.delegationHeader
|
|
20233
20457
|
);
|
|
@@ -20400,7 +20624,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20400
20624
|
];
|
|
20401
20625
|
const abilities = { kv: { "": kvActions } };
|
|
20402
20626
|
const now = /* @__PURE__ */ new Date();
|
|
20403
|
-
const expiryMs =
|
|
20627
|
+
const expiryMs = import_sdk_core6.EXPIRY.EPHEMERAL_MS;
|
|
20404
20628
|
const expirationTime = new Date(now.getTime() + expiryMs);
|
|
20405
20629
|
const prepared = this.wasmBindings.prepareSession({
|
|
20406
20630
|
abilities,
|
|
@@ -20418,7 +20642,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20418
20642
|
...prepared,
|
|
20419
20643
|
signature: signature2
|
|
20420
20644
|
});
|
|
20421
|
-
const activateResult = await (0,
|
|
20645
|
+
const activateResult = await (0, import_sdk_core6.activateSessionWithHost)(
|
|
20422
20646
|
this.config.host,
|
|
20423
20647
|
delegationSession.delegationHeader
|
|
20424
20648
|
);
|
|
@@ -20445,8 +20669,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20445
20669
|
}]);
|
|
20446
20670
|
}
|
|
20447
20671
|
if (this._serviceContext) {
|
|
20448
|
-
const publicKV = new
|
|
20449
|
-
const publicContext = new
|
|
20672
|
+
const publicKV = new import_sdk_core6.KVService({ prefix: "" });
|
|
20673
|
+
const publicContext = new import_sdk_core6.ServiceContext({
|
|
20450
20674
|
invoke: this.invokeWithRuntimePermissions,
|
|
20451
20675
|
fetch: this._serviceContext.fetch,
|
|
20452
20676
|
hosts: this._serviceContext.hosts,
|
|
@@ -20573,14 +20797,14 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20573
20797
|
async delegateTo(did, permissions, options) {
|
|
20574
20798
|
const session = this.currentTinyCloudSession();
|
|
20575
20799
|
if (!session) {
|
|
20576
|
-
throw new
|
|
20800
|
+
throw new import_sdk_core6.SessionExpiredError(/* @__PURE__ */ new Date(0));
|
|
20577
20801
|
}
|
|
20578
20802
|
const sessionExpiry = extractSiweExpiration(session.siwe);
|
|
20579
20803
|
if (sessionExpiry !== void 0) {
|
|
20580
20804
|
const now2 = Date.now();
|
|
20581
20805
|
const marginMs = _TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS;
|
|
20582
20806
|
if (sessionExpiry.getTime() <= now2 + marginMs) {
|
|
20583
|
-
throw new
|
|
20807
|
+
throw new import_sdk_core6.SessionExpiredError(sessionExpiry);
|
|
20584
20808
|
}
|
|
20585
20809
|
}
|
|
20586
20810
|
if (!Array.isArray(permissions) || permissions.length === 0) {
|
|
@@ -20609,11 +20833,11 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20609
20833
|
);
|
|
20610
20834
|
return { delegation: delegation2, prompted: true };
|
|
20611
20835
|
}
|
|
20612
|
-
const granted = (0,
|
|
20836
|
+
const granted = (0, import_sdk_core6.parseRecapCapabilities)(
|
|
20613
20837
|
(siwe) => this.wasmBindings.parseRecapFromSiwe(siwe),
|
|
20614
20838
|
session.siwe
|
|
20615
20839
|
);
|
|
20616
|
-
const { subset, missing } = (0,
|
|
20840
|
+
const { subset, missing } = (0, import_sdk_core6.isCapabilitySubset)(expandedEntries, granted);
|
|
20617
20841
|
if (!subset) {
|
|
20618
20842
|
const runtimeGrant = this.findGrantForOperations(
|
|
20619
20843
|
this.permissionEntriesToOperations(expandedEntries, session)
|
|
@@ -20621,7 +20845,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20621
20845
|
if (runtimeGrant) {
|
|
20622
20846
|
const marginMs = _TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS;
|
|
20623
20847
|
if (runtimeGrant.expiresAt.getTime() <= Date.now() + marginMs) {
|
|
20624
|
-
throw new
|
|
20848
|
+
throw new import_sdk_core6.SessionExpiredError(runtimeGrant.expiresAt);
|
|
20625
20849
|
}
|
|
20626
20850
|
const runtimeExpiration = runtimeGrant.expiresAt < effectiveExpiration ? runtimeGrant.expiresAt : effectiveExpiration;
|
|
20627
20851
|
const delegation2 = await this.createDelegationViaRuntimeGrant(
|
|
@@ -20632,7 +20856,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20632
20856
|
);
|
|
20633
20857
|
return { delegation: delegation2, prompted: false };
|
|
20634
20858
|
}
|
|
20635
|
-
throw new
|
|
20859
|
+
throw new import_sdk_core6.PermissionNotInManifestError(missing, granted);
|
|
20636
20860
|
}
|
|
20637
20861
|
const delegation = await this.createDelegationViaWasmPath(
|
|
20638
20862
|
did,
|
|
@@ -20654,7 +20878,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20654
20878
|
);
|
|
20655
20879
|
}
|
|
20656
20880
|
const target = request.delegationTargets.find(
|
|
20657
|
-
(entry) =>
|
|
20881
|
+
(entry) => didPrincipalMatches2(entry.did, did)
|
|
20658
20882
|
);
|
|
20659
20883
|
if (!target) {
|
|
20660
20884
|
throw new Error(`No manifest delegation target found for DID ${did}`);
|
|
@@ -20714,7 +20938,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20714
20938
|
const spaceId = resolvedSpaces.size === 1 ? [...resolvedSpaces][0] : session.spaceId;
|
|
20715
20939
|
const abilities = {};
|
|
20716
20940
|
for (const entry of entries) {
|
|
20717
|
-
const shortService =
|
|
20941
|
+
const shortService = import_sdk_core6.SERVICE_LONG_TO_SHORT[entry.service];
|
|
20718
20942
|
if (shortService === void 0) {
|
|
20719
20943
|
throw new Error(
|
|
20720
20944
|
`delegateTo: unknown service '${entry.service}' \u2014 no short-form mapping`
|
|
@@ -20754,7 +20978,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20754
20978
|
});
|
|
20755
20979
|
const primary = result.resources[0];
|
|
20756
20980
|
const delegationHeader = { Authorization: result.delegation };
|
|
20757
|
-
const activateResult = await (0,
|
|
20981
|
+
const activateResult = await (0, import_sdk_core6.activateSessionWithHost)(
|
|
20758
20982
|
this.config.host,
|
|
20759
20983
|
delegationHeader
|
|
20760
20984
|
);
|
|
@@ -20789,7 +21013,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20789
21013
|
const primary = result.resources[0];
|
|
20790
21014
|
const delegationHeader = { Authorization: result.delegation };
|
|
20791
21015
|
const targetHost = grant.delegation.host ?? this.config.host;
|
|
20792
|
-
const activateResult = await (0,
|
|
21016
|
+
const activateResult = await (0, import_sdk_core6.activateSessionWithHost)(
|
|
20793
21017
|
targetHost,
|
|
20794
21018
|
delegationHeader
|
|
20795
21019
|
);
|
|
@@ -20830,10 +21054,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20830
21054
|
return this.wasmBindings.makeSpaceId(session.address, session.chainId, space);
|
|
20831
21055
|
}
|
|
20832
21056
|
expandPermissionEntries(permissions) {
|
|
20833
|
-
return (0,
|
|
21057
|
+
return (0, import_sdk_core6.expandPermissionEntries)(permissions);
|
|
20834
21058
|
}
|
|
20835
21059
|
shortServiceName(service) {
|
|
20836
|
-
const short =
|
|
21060
|
+
const short = import_sdk_core6.SERVICE_LONG_TO_SHORT[service];
|
|
20837
21061
|
if (short === void 0) {
|
|
20838
21062
|
throw new Error(
|
|
20839
21063
|
`unknown service '${service}' \u2014 no short-form mapping`
|
|
@@ -20859,7 +21083,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20859
21083
|
return abilities;
|
|
20860
21084
|
}
|
|
20861
21085
|
isEncryptionPermissionEntry(entry) {
|
|
20862
|
-
return entry.service ===
|
|
21086
|
+
return entry.service === import_sdk_core6.ENCRYPTION_PERMISSION_SERVICE && entry.path.startsWith("urn:tinycloud:encryption:");
|
|
20863
21087
|
}
|
|
20864
21088
|
permissionsToRawAbilities(entries) {
|
|
20865
21089
|
const rawAbilities = {};
|
|
@@ -20892,11 +21116,11 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
20892
21116
|
}
|
|
20893
21117
|
sessionCoversPermissionEntries(session, entries) {
|
|
20894
21118
|
try {
|
|
20895
|
-
const granted = (0,
|
|
21119
|
+
const granted = (0, import_sdk_core6.parseRecapCapabilities)(
|
|
20896
21120
|
(siwe) => this.wasmBindings.parseRecapFromSiwe(siwe),
|
|
20897
21121
|
session.siwe
|
|
20898
21122
|
);
|
|
20899
|
-
return (0,
|
|
21123
|
+
return (0, import_sdk_core6.isCapabilitySubset)(entries, granted).subset;
|
|
20900
21124
|
} catch {
|
|
20901
21125
|
return false;
|
|
20902
21126
|
}
|
|
@@ -21104,7 +21328,23 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21104
21328
|
if (granted.resource !== void 0 || requested.resource !== void 0) {
|
|
21105
21329
|
return granted.resource !== void 0 && requested.resource !== void 0 && granted.resource === requested.resource && this.pathContains(granted.path, requested.path);
|
|
21106
21330
|
}
|
|
21107
|
-
return granted.spaceId !== void 0 && requested.spaceId !== void 0 && granted.spaceId
|
|
21331
|
+
return granted.spaceId !== void 0 && requested.spaceId !== void 0 && this.spaceIdsEqual(granted.spaceId, requested.spaceId) && this.pathContains(granted.path, requested.path);
|
|
21332
|
+
}
|
|
21333
|
+
// Space IDs are `tinycloud:pkh:eip155:<chain>:<0xADDR>:<name>`. The embedded
|
|
21334
|
+
// EIP-155 address is case-insensitive, but the CLI canonicalizes it to
|
|
21335
|
+
// lowercase when building a space URI while stored runtime delegations keep
|
|
21336
|
+
// the EIP-55 checksummed form — so a byte-for-byte compare spuriously rejects
|
|
21337
|
+
// an otherwise-valid grant. Lowercase ONLY the `eip155:<chain>:0x<addr>`
|
|
21338
|
+
// segment and leave everything else (crucially the case-sensitive space NAME)
|
|
21339
|
+
// byte-exact. Mirrors the CLI's `normalizeSpaceForCompare` (OPENKEY_SCOPE_MISMATCH fix).
|
|
21340
|
+
spaceIdsEqual(a, b) {
|
|
21341
|
+
return this.normalizeSpaceAddress(a) === this.normalizeSpaceAddress(b);
|
|
21342
|
+
}
|
|
21343
|
+
normalizeSpaceAddress(space) {
|
|
21344
|
+
return space.replace(
|
|
21345
|
+
/(eip155:\d+:)(0x[0-9a-fA-F]{40})/,
|
|
21346
|
+
(_match, prefix, addr) => prefix + addr.toLowerCase()
|
|
21347
|
+
);
|
|
21108
21348
|
}
|
|
21109
21349
|
actionContains(grantedAction, requestedAction) {
|
|
21110
21350
|
if (grantedAction === requestedAction) {
|
|
@@ -21211,7 +21451,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21211
21451
|
if (resolvedDelegateDID.endsWith(".eth") && this.config.ensResolver) {
|
|
21212
21452
|
const address = await this.config.ensResolver.resolveAddress(resolvedDelegateDID);
|
|
21213
21453
|
if (!address) throw new Error(`Could not resolve ENS name: ${resolvedDelegateDID}`);
|
|
21214
|
-
resolvedDelegateDID = (0,
|
|
21454
|
+
resolvedDelegateDID = (0, import_sdk_core6.pkhDid)(address, 1);
|
|
21215
21455
|
}
|
|
21216
21456
|
const entries = legacyParamsToPermissionEntries(
|
|
21217
21457
|
params.actions,
|
|
@@ -21226,7 +21466,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21226
21466
|
);
|
|
21227
21467
|
return result.delegation;
|
|
21228
21468
|
} catch (err) {
|
|
21229
|
-
if (err instanceof
|
|
21469
|
+
if (err instanceof import_sdk_core6.PermissionNotInManifestError) {
|
|
21230
21470
|
} else {
|
|
21231
21471
|
throw err;
|
|
21232
21472
|
}
|
|
@@ -21283,7 +21523,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21283
21523
|
...prepared,
|
|
21284
21524
|
signature: signature2
|
|
21285
21525
|
});
|
|
21286
|
-
const activateResult = await (0,
|
|
21526
|
+
const activateResult = await (0, import_sdk_core6.activateSessionWithHost)(
|
|
21287
21527
|
this.config.host,
|
|
21288
21528
|
delegationSession.delegationHeader
|
|
21289
21529
|
);
|
|
@@ -21305,7 +21545,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21305
21545
|
};
|
|
21306
21546
|
const hasKvActions = params.actions.some((a) => a.startsWith("tinycloud.kv/"));
|
|
21307
21547
|
if (hasKvActions && params.includePublicSpace !== false) {
|
|
21308
|
-
const publicSpaceId = (0,
|
|
21548
|
+
const publicSpaceId = (0, import_sdk_core6.makePublicSpaceId)(
|
|
21309
21549
|
this.wasmBindings.ensureEip55(session.address),
|
|
21310
21550
|
session.chainId
|
|
21311
21551
|
);
|
|
@@ -21328,7 +21568,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21328
21568
|
...publicPrepared,
|
|
21329
21569
|
signature: publicSignature
|
|
21330
21570
|
});
|
|
21331
|
-
const publicActivateResult = await (0,
|
|
21571
|
+
const publicActivateResult = await (0, import_sdk_core6.activateSessionWithHost)(
|
|
21332
21572
|
this.config.host,
|
|
21333
21573
|
publicSession.delegationHeader
|
|
21334
21574
|
);
|
|
@@ -21368,7 +21608,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21368
21608
|
const targetHost = delegation.host ?? this.config.host;
|
|
21369
21609
|
if (this.isSessionOnly) {
|
|
21370
21610
|
const myDid = this.did;
|
|
21371
|
-
if (!
|
|
21611
|
+
if (!didPrincipalMatches2(delegation.delegateDID, myDid)) {
|
|
21372
21612
|
throw new Error(
|
|
21373
21613
|
`Delegation targets ${delegation.delegateDID} but this user's DID is ${myDid}. The delegation must target this user's DID.`
|
|
21374
21614
|
);
|
|
@@ -21433,7 +21673,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21433
21673
|
...prepared,
|
|
21434
21674
|
signature: signature2
|
|
21435
21675
|
});
|
|
21436
|
-
const activateResult = await (0,
|
|
21676
|
+
const activateResult = await (0, import_sdk_core6.activateSessionWithHost)(
|
|
21437
21677
|
targetHost,
|
|
21438
21678
|
invokerSession.delegationHeader
|
|
21439
21679
|
);
|
|
@@ -21539,7 +21779,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
21539
21779
|
...prepared,
|
|
21540
21780
|
signature: signature2
|
|
21541
21781
|
});
|
|
21542
|
-
const activateResult = await (0,
|
|
21782
|
+
const activateResult = await (0, import_sdk_core6.activateSessionWithHost)(
|
|
21543
21783
|
targetHost,
|
|
21544
21784
|
subDelegationSession.delegationHeader
|
|
21545
21785
|
);
|
|
@@ -21581,11 +21821,11 @@ TinyCloudNode.registerNodeDefaults({
|
|
|
21581
21821
|
});
|
|
21582
21822
|
|
|
21583
21823
|
// src/index.ts
|
|
21584
|
-
var import_sdk_core7 = require("@tinycloud/sdk-core");
|
|
21585
21824
|
var import_sdk_core8 = require("@tinycloud/sdk-core");
|
|
21825
|
+
var import_sdk_core9 = require("@tinycloud/sdk-core");
|
|
21586
21826
|
|
|
21587
21827
|
// src/storage/FileSessionStorage.ts
|
|
21588
|
-
var
|
|
21828
|
+
var import_sdk_core7 = require("@tinycloud/sdk-core");
|
|
21589
21829
|
var import_fs = require("fs");
|
|
21590
21830
|
var import_path = require("path");
|
|
21591
21831
|
var FileSessionStorage = class {
|
|
@@ -21640,7 +21880,7 @@ var FileSessionStorage = class {
|
|
|
21640
21880
|
try {
|
|
21641
21881
|
const data = (0, import_fs.readFileSync)(filePath, "utf-8");
|
|
21642
21882
|
const parsed = JSON.parse(data);
|
|
21643
|
-
const validation = (0,
|
|
21883
|
+
const validation = (0, import_sdk_core7.validatePersistedSessionData)(parsed);
|
|
21644
21884
|
if (!validation.ok) {
|
|
21645
21885
|
console.warn(`Invalid session data for ${address}:`, validation.error.message);
|
|
21646
21886
|
(0, import_fs.unlinkSync)(filePath);
|
|
@@ -21705,9 +21945,35 @@ var FileSessionStorage = class {
|
|
|
21705
21945
|
};
|
|
21706
21946
|
|
|
21707
21947
|
// src/index.ts
|
|
21708
|
-
var
|
|
21948
|
+
var import_sdk_core10 = require("@tinycloud/sdk-core");
|
|
21709
21949
|
|
|
21710
21950
|
// src/delegation.ts
|
|
21951
|
+
async function grantAuthRequest(authority, request, options) {
|
|
21952
|
+
if (request.kind !== "tinycloud.auth.request") {
|
|
21953
|
+
throw new Error(
|
|
21954
|
+
`grantAuthRequest expects a tinycloud.auth.request artifact, got "${request.kind}".`
|
|
21955
|
+
);
|
|
21956
|
+
}
|
|
21957
|
+
if (!Array.isArray(request.requested) || request.requested.length === 0) {
|
|
21958
|
+
throw new Error("grantAuthRequest request has no requested capabilities.");
|
|
21959
|
+
}
|
|
21960
|
+
const expiry = options?.expiry ?? request.requestedExpiry;
|
|
21961
|
+
const result = await authority.delegateTo(
|
|
21962
|
+
request.sessionDid,
|
|
21963
|
+
request.requested,
|
|
21964
|
+
expiry !== void 0 ? { expiry } : void 0
|
|
21965
|
+
);
|
|
21966
|
+
return {
|
|
21967
|
+
kind: "tinycloud.auth.delegation",
|
|
21968
|
+
version: 1,
|
|
21969
|
+
requestId: request.requestId,
|
|
21970
|
+
delegationCid: result.delegation.cid,
|
|
21971
|
+
delegation: result.delegation,
|
|
21972
|
+
permissions: request.requested,
|
|
21973
|
+
expiry: result.delegation.expiry.toISOString(),
|
|
21974
|
+
prompted: result.prompted
|
|
21975
|
+
};
|
|
21976
|
+
}
|
|
21711
21977
|
function serializeDelegation(delegation) {
|
|
21712
21978
|
return JSON.stringify({
|
|
21713
21979
|
...delegation,
|
|
@@ -21724,7 +21990,6 @@ function deserializeDelegation(data) {
|
|
|
21724
21990
|
}
|
|
21725
21991
|
|
|
21726
21992
|
// src/index.ts
|
|
21727
|
-
var import_sdk_core10 = require("@tinycloud/sdk-core");
|
|
21728
21993
|
var import_sdk_core11 = require("@tinycloud/sdk-core");
|
|
21729
21994
|
var import_sdk_core12 = require("@tinycloud/sdk-core");
|
|
21730
21995
|
var import_sdk_core13 = require("@tinycloud/sdk-core");
|
|
@@ -21735,10 +22000,12 @@ var import_sdk_core17 = require("@tinycloud/sdk-core");
|
|
|
21735
22000
|
var import_sdk_core18 = require("@tinycloud/sdk-core");
|
|
21736
22001
|
var import_sdk_core19 = require("@tinycloud/sdk-core");
|
|
21737
22002
|
var import_sdk_core20 = require("@tinycloud/sdk-core");
|
|
22003
|
+
var import_sdk_core21 = require("@tinycloud/sdk-core");
|
|
21738
22004
|
// Annotate the CommonJS export names for ESM import in node:
|
|
21739
22005
|
0 && (module.exports = {
|
|
21740
22006
|
ACCOUNT_REGISTRY_PATH,
|
|
21741
22007
|
ACCOUNT_REGISTRY_SPACE,
|
|
22008
|
+
AccountService,
|
|
21742
22009
|
AutoApproveSpaceCreationHandler,
|
|
21743
22010
|
CapabilityKeyRegistry,
|
|
21744
22011
|
CapabilityKeyRegistryErrorCodes,
|
|
@@ -21838,6 +22105,7 @@ var import_sdk_core20 = require("@tinycloud/sdk-core");
|
|
|
21838
22105
|
expandPermissionEntries,
|
|
21839
22106
|
expandPermissionEntry,
|
|
21840
22107
|
generateRandomReceiverKey,
|
|
22108
|
+
grantAuthRequest,
|
|
21841
22109
|
hexDecode,
|
|
21842
22110
|
hexEncode,
|
|
21843
22111
|
isCapabilitySubset,
|