@tinycloud/node-sdk 3.1.0-beta.7 → 3.1.0-beta.9
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-BWvBTn9l.d.cts → core-CC7uDKZP.d.cts} +72 -6
- package/dist/{core-BWvBTn9l.d.ts → core-CC7uDKZP.d.ts} +72 -6
- package/dist/core.cjs +200 -53
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +1 -1
- package/dist/core.d.ts +1 -1
- package/dist/core.js +201 -53
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +252 -85
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +252 -85
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/core.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, AccountApplication, AccountApplicationListOptions, AccountApplicationRegisterOptions, AccountDelegation, AccountDelegationListOptions, AccountDelegationRevokeOptions, AccountIndexEnsureResult, AccountIndexRebuildResult, AccountIndexStatus, AccountIndexedReadOptions, AccountService, AccountServiceConfig, AccountSpace, AccountSpaceListOptions, AccountStatus, AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CanonicalAddress, CanonicalParsedNetworkId, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, CaveatedDelegationUnsupportedError, ClientSession, ColumnInfo, ComposeManifestOptions, ComposedManifestRequest, CreateDelegationParams, DEFAULT_MANIFEST_SPACE, DEFAULT_MANIFEST_VERSION, DEFAULT_SIGNED_READ_URL_EXPIRY_MS, DataVaultConfig, DataVaultService, DatabaseHandle, DelegateReceivedShareParams, DelegatedShareAccess, Delegation, DelegationChain, DelegationChainV2, DelegationDirection, DelegationError, DelegationErrorCode, DelegationErrorCodes, DelegationFilters, DelegationManager, DelegationManagerConfig, DelegationRecord, DelegationResult, DidCacheKeyOptions, DidEqualsOptions, DuckDbAction, DuckDbActionType, DuckDbBatchOptions, DuckDbBatchResponse, DuckDbDatabaseHandle, DuckDbExecuteOptions, DuckDbExecuteResponse, DuckDbOptions, DuckDbQueryOptions, DuckDbQueryResponse, DuckDbService, DuckDbServiceConfig, DuckDbStatement, DuckDbValue, EncodedShareData, ExecuteOptions, ExecuteResponse, Extension, FetchFunction, GenerateShareParams, ICapabilityKeyRegistry, IDataVaultService, IDatabaseHandle, IDuckDbDatabaseHandle, IDuckDbService, IENSResolver, IKVService, INotificationHandler, IPrefixedKVService, ISQLService, ISecretsService, ISessionManager, ISessionStorage, ISharingService, ISigner, ISpace, ISpaceCreationHandler, ISpaceScopedDelegations, ISpaceScopedSharing, ISpaceService, IUserAuthorization, IWasmBindings, IdentityParseError, IngestOptions, InvokeFunction, JWK, KVBatchReadResponse, KVCreateSignedReadUrlOptions, KVResponse, KVService, KVServiceConfig, KVSignedReadUrlResponse, KeyInfo, KeyProvider, KeyType, Manifest, ManifestDefaults, ManifestRegistryRecord, ManifestSecretActions, ManifestValidationError, OpenKeyCallbackStrategy, OpenKeySigningRequestBody, OpenKeySigningResponseBody, OpenKeySigningStrategyOptions, ParsedSecretCatalogKey, PermissionEntry, PermissionNotInManifestError, PersistedSessionData, PkhDidParts, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, RegisterBatchSuccess, RegisterPolicyV3Input, RegisterPolicyV3Receipt, ResolvedCapabilities, ResolvedDelegate, ResolvedSecretPath, ResourceCapability, SECRET_NAME_RE, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, SecretCatalogEntry, SecretPayload, SecretScopeOptions, SecretsError, SecretsService, ServiceContext, ServiceContextConfig, ServiceSession, SessionExpiredError, ShareAccess, ShareLink, ShareLinkData, ShareSchema, SharingService, SharingServiceConfig, SignCallback, SignInOptions, SignRequest, SignResponse, SilentNotificationHandler, Space, SpaceAbilitiesMap, SpaceConfig, SpaceCreationContext, SpaceErrorCode, SpaceErrorCodes, SpaceInfo, SpaceOwnership, SpaceService, SpaceServiceConfig, SqlStatement, SqlValue, StoredDelegationChain, TableInfo, TelemetryConfig, TelemetryEventHandler, TinyCloud, TinyCloudConfig, TinyCloudDebugEnableOptions, TinyCloudDebugEvent, TinyCloudDebugLevel, TinyCloudDebugLogger, TinyCloudDebugTimer, TinyCloudSession, UnsupportedFeatureError, VAULT_PERMISSION_SERVICE, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultNetworkReadResult, VaultPublicSpaceKVActions, VaultPutOptions, VersionCheckError, ViewInfo, WasmVaultFunctions, addressStorageKey, buildSpaceUri, canonicalizeAddress, canonicalizeDid, canonicalizeDidUrl, canonicalizeNetworkId, canonicalizeSecretScope, checkNodeInfo, clearTinyCloudDebugLogs, composeManifestRequest, createCapabilityKeyRegistry, createOpenKeyCallbackSigningStrategy, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, didCacheKey, didEquals, disableTinyCloudDebug, enableTinyCloudDebug, expandActionShortNames, expandPermissionEntries, expandPermissionEntry, getTinyCloudDebugLogs, installTinyCloudDebugGlobals, isCapabilitySubset, isEvmAddress, loadManifest, makePkhSpaceId, makePublicSpaceId, parseCanonicalNetworkId, parseExpiry, parsePkhDid, parseSecretCatalogKey, parseSpaceUri, pkhDid, principalDid, principalDidEquals, resolveManifest, resolveSecretListPrefix, resolveSecretPath, resourceCapabilitiesToSpaceAbilitiesMap, tinyCloudDebugLogger, validateManifest } from '@tinycloud/sdk-core';
|
|
2
|
-
export { e as BootstrapWarning, C as CompactRuntimeDelegationInput, f as CreateOwnerDelegationParams, D as DelegateToOptions, g as DelegateToResult, h as DelegatedAccess, E as EnsureEncryptionNetworkOptions, F as FileSessionStorage, I as InvalidRestoredSessionError, M as MemorySessionStorage, N as NodeEventEmitterStrategy, j as NodeUserAuthorization, k as NodeUserAuthorizationConfig, O as OwnerDelegationReceipt, P as PortableDelegation,
|
|
2
|
+
export { e as BootstrapWarning, C as CompactRuntimeDelegationInput, f as CreateOwnerDelegationParams, D as DelegateToOptions, g as DelegateToResult, h as DelegatedAccess, E as EnsureEncryptionNetworkOptions, F as FileSessionStorage, I as InvalidRestoredSessionError, M as MemorySessionStorage, N as NodeEventEmitterStrategy, j as NodeUserAuthorization, k as NodeUserAuthorizationConfig, O as OwnerDelegationReceipt, P as PortableDelegation, p as RuntimePermissionGrantOptions, S as SecretPermissionHint, q as SecretReadInput, r as SecretReadResult, t as SignStrategy, T as TinyCloudNode, u as TinyCloudNodeConfig, U as UnifiedOwnerRootInput, v as UnifiedOwnerRootReceipt, w as UnsupportedSessionRestoreError, V as ValidatedRuntimeDelegation, W as WasmKeyProvider, y as WasmKeyProviderConfig, z as activateCompactRuntimeDelegation, H as createWasmKeyProvider, J as defaultSignStrategy, K as deserializeDelegation, Q as serializeDelegation } from './core-CC7uDKZP.cjs';
|
|
3
3
|
import 'events';
|
|
4
4
|
import '@tinycloud/sdk-services';
|
package/dist/core.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, AccountApplication, AccountApplicationListOptions, AccountApplicationRegisterOptions, AccountDelegation, AccountDelegationListOptions, AccountDelegationRevokeOptions, AccountIndexEnsureResult, AccountIndexRebuildResult, AccountIndexStatus, AccountIndexedReadOptions, AccountService, AccountServiceConfig, AccountSpace, AccountSpaceListOptions, AccountStatus, AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CanonicalAddress, CanonicalParsedNetworkId, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, CaveatedDelegationUnsupportedError, ClientSession, ColumnInfo, ComposeManifestOptions, ComposedManifestRequest, CreateDelegationParams, DEFAULT_MANIFEST_SPACE, DEFAULT_MANIFEST_VERSION, DEFAULT_SIGNED_READ_URL_EXPIRY_MS, DataVaultConfig, DataVaultService, DatabaseHandle, DelegateReceivedShareParams, DelegatedShareAccess, Delegation, DelegationChain, DelegationChainV2, DelegationDirection, DelegationError, DelegationErrorCode, DelegationErrorCodes, DelegationFilters, DelegationManager, DelegationManagerConfig, DelegationRecord, DelegationResult, DidCacheKeyOptions, DidEqualsOptions, DuckDbAction, DuckDbActionType, DuckDbBatchOptions, DuckDbBatchResponse, DuckDbDatabaseHandle, DuckDbExecuteOptions, DuckDbExecuteResponse, DuckDbOptions, DuckDbQueryOptions, DuckDbQueryResponse, DuckDbService, DuckDbServiceConfig, DuckDbStatement, DuckDbValue, EncodedShareData, ExecuteOptions, ExecuteResponse, Extension, FetchFunction, GenerateShareParams, ICapabilityKeyRegistry, IDataVaultService, IDatabaseHandle, IDuckDbDatabaseHandle, IDuckDbService, IENSResolver, IKVService, INotificationHandler, IPrefixedKVService, ISQLService, ISecretsService, ISessionManager, ISessionStorage, ISharingService, ISigner, ISpace, ISpaceCreationHandler, ISpaceScopedDelegations, ISpaceScopedSharing, ISpaceService, IUserAuthorization, IWasmBindings, IdentityParseError, IngestOptions, InvokeFunction, JWK, KVBatchReadResponse, KVCreateSignedReadUrlOptions, KVResponse, KVService, KVServiceConfig, KVSignedReadUrlResponse, KeyInfo, KeyProvider, KeyType, Manifest, ManifestDefaults, ManifestRegistryRecord, ManifestSecretActions, ManifestValidationError, OpenKeyCallbackStrategy, OpenKeySigningRequestBody, OpenKeySigningResponseBody, OpenKeySigningStrategyOptions, ParsedSecretCatalogKey, PermissionEntry, PermissionNotInManifestError, PersistedSessionData, PkhDidParts, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, RegisterBatchSuccess, RegisterPolicyV3Input, RegisterPolicyV3Receipt, ResolvedCapabilities, ResolvedDelegate, ResolvedSecretPath, ResourceCapability, SECRET_NAME_RE, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, SecretCatalogEntry, SecretPayload, SecretScopeOptions, SecretsError, SecretsService, ServiceContext, ServiceContextConfig, ServiceSession, SessionExpiredError, ShareAccess, ShareLink, ShareLinkData, ShareSchema, SharingService, SharingServiceConfig, SignCallback, SignInOptions, SignRequest, SignResponse, SilentNotificationHandler, Space, SpaceAbilitiesMap, SpaceConfig, SpaceCreationContext, SpaceErrorCode, SpaceErrorCodes, SpaceInfo, SpaceOwnership, SpaceService, SpaceServiceConfig, SqlStatement, SqlValue, StoredDelegationChain, TableInfo, TelemetryConfig, TelemetryEventHandler, TinyCloud, TinyCloudConfig, TinyCloudDebugEnableOptions, TinyCloudDebugEvent, TinyCloudDebugLevel, TinyCloudDebugLogger, TinyCloudDebugTimer, TinyCloudSession, UnsupportedFeatureError, VAULT_PERMISSION_SERVICE, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultNetworkReadResult, VaultPublicSpaceKVActions, VaultPutOptions, VersionCheckError, ViewInfo, WasmVaultFunctions, addressStorageKey, buildSpaceUri, canonicalizeAddress, canonicalizeDid, canonicalizeDidUrl, canonicalizeNetworkId, canonicalizeSecretScope, checkNodeInfo, clearTinyCloudDebugLogs, composeManifestRequest, createCapabilityKeyRegistry, createOpenKeyCallbackSigningStrategy, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, didCacheKey, didEquals, disableTinyCloudDebug, enableTinyCloudDebug, expandActionShortNames, expandPermissionEntries, expandPermissionEntry, getTinyCloudDebugLogs, installTinyCloudDebugGlobals, isCapabilitySubset, isEvmAddress, loadManifest, makePkhSpaceId, makePublicSpaceId, parseCanonicalNetworkId, parseExpiry, parsePkhDid, parseSecretCatalogKey, parseSpaceUri, pkhDid, principalDid, principalDidEquals, resolveManifest, resolveSecretListPrefix, resolveSecretPath, resourceCapabilitiesToSpaceAbilitiesMap, tinyCloudDebugLogger, validateManifest } from '@tinycloud/sdk-core';
|
|
2
|
-
export { e as BootstrapWarning, C as CompactRuntimeDelegationInput, f as CreateOwnerDelegationParams, D as DelegateToOptions, g as DelegateToResult, h as DelegatedAccess, E as EnsureEncryptionNetworkOptions, F as FileSessionStorage, I as InvalidRestoredSessionError, M as MemorySessionStorage, N as NodeEventEmitterStrategy, j as NodeUserAuthorization, k as NodeUserAuthorizationConfig, O as OwnerDelegationReceipt, P as PortableDelegation,
|
|
2
|
+
export { e as BootstrapWarning, C as CompactRuntimeDelegationInput, f as CreateOwnerDelegationParams, D as DelegateToOptions, g as DelegateToResult, h as DelegatedAccess, E as EnsureEncryptionNetworkOptions, F as FileSessionStorage, I as InvalidRestoredSessionError, M as MemorySessionStorage, N as NodeEventEmitterStrategy, j as NodeUserAuthorization, k as NodeUserAuthorizationConfig, O as OwnerDelegationReceipt, P as PortableDelegation, p as RuntimePermissionGrantOptions, S as SecretPermissionHint, q as SecretReadInput, r as SecretReadResult, t as SignStrategy, T as TinyCloudNode, u as TinyCloudNodeConfig, U as UnifiedOwnerRootInput, v as UnifiedOwnerRootReceipt, w as UnsupportedSessionRestoreError, V as ValidatedRuntimeDelegation, W as WasmKeyProvider, y as WasmKeyProviderConfig, z as activateCompactRuntimeDelegation, H as createWasmKeyProvider, J as defaultSignStrategy, K as deserializeDelegation, Q as serializeDelegation } from './core-CC7uDKZP.js';
|
|
3
3
|
import 'events';
|
|
4
4
|
import '@tinycloud/sdk-services';
|
package/dist/core.js
CHANGED
|
@@ -1658,14 +1658,14 @@ var NodeUserAuthorization = class {
|
|
|
1658
1658
|
* Request signature via event emitter with timeout.
|
|
1659
1659
|
*/
|
|
1660
1660
|
requestSignatureViaEmitter(request, emitter, timeout) {
|
|
1661
|
-
return new Promise((resolve,
|
|
1661
|
+
return new Promise((resolve, reject2) => {
|
|
1662
1662
|
const timeoutId = setTimeout(() => {
|
|
1663
|
-
|
|
1663
|
+
reject2(new Error("Sign request timed out"));
|
|
1664
1664
|
}, timeout);
|
|
1665
1665
|
const respond = async (response) => {
|
|
1666
1666
|
clearTimeout(timeoutId);
|
|
1667
1667
|
if (!response.approved) {
|
|
1668
|
-
|
|
1668
|
+
reject2(
|
|
1669
1669
|
new Error(response.reason ?? "Sign request rejected via emitter")
|
|
1670
1670
|
);
|
|
1671
1671
|
} else {
|
|
@@ -1717,6 +1717,7 @@ import {
|
|
|
1717
1717
|
recapCaveatsEqual,
|
|
1718
1718
|
expandPermissionEntries as expandPermissionEntriesCore,
|
|
1719
1719
|
isCapabilitySubset,
|
|
1720
|
+
isExplicitOnlyAction,
|
|
1720
1721
|
parseRecapCapabilities,
|
|
1721
1722
|
SERVICE_LONG_TO_SHORT,
|
|
1722
1723
|
SERVICE_SHORT_TO_LONG,
|
|
@@ -2330,6 +2331,25 @@ function jsonFromVerifier(value) {
|
|
|
2330
2331
|
function verifierRecapEntries(entries) {
|
|
2331
2332
|
return entries.map((entry) => Array.isArray(entry.caveats) ? { ...entry, caveats: entry.caveats.map((caveat) => jsonFromVerifier(caveat)) } : entry);
|
|
2332
2333
|
}
|
|
2334
|
+
function exactVerifiedRecap(verified) {
|
|
2335
|
+
const exactRecap = Array.isArray(verified.verifiedRecap) ? verifierRecapEntries(verified.verifiedRecap) : verified.verifiedRecap;
|
|
2336
|
+
if (!Array.isArray(exactRecap) || !exactRecap.every(
|
|
2337
|
+
(entry) => entry !== null && typeof entry === "object" && typeof entry.service === "string" && typeof entry.space === "string" && typeof entry.path === "string" && Array.isArray(entry.actions) && entry.actions.every((action) => typeof action === "string") && Array.isArray(entry.caveats) && entry.caveats.every(
|
|
2338
|
+
(caveat) => caveat !== null && typeof caveat === "object" && !Array.isArray(caveat)
|
|
2339
|
+
)
|
|
2340
|
+
)) {
|
|
2341
|
+
throw new UnsupportedSessionRestoreError(
|
|
2342
|
+
"it cannot reconstruct caveat-preserving persisted ReCap authority"
|
|
2343
|
+
);
|
|
2344
|
+
}
|
|
2345
|
+
return exactRecap.map((entry) => ({
|
|
2346
|
+
service: entry.service,
|
|
2347
|
+
space: entry.space,
|
|
2348
|
+
path: entry.path,
|
|
2349
|
+
actions: [...entry.actions],
|
|
2350
|
+
caveats: cloneRecapCaveats(entry.caveats)
|
|
2351
|
+
}));
|
|
2352
|
+
}
|
|
2333
2353
|
var ServiceGraphLifetime = class {
|
|
2334
2354
|
constructor(invokeFn, invokeAnyFn, fetchFn) {
|
|
2335
2355
|
this.invokeFn = invokeFn;
|
|
@@ -3994,23 +4014,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
3994
4014
|
throw new InvalidRestoredSessionError(error instanceof Error ? error.message : String(error));
|
|
3995
4015
|
}
|
|
3996
4016
|
})();
|
|
3997
|
-
|
|
3998
|
-
if (!Array.isArray(exactRecap) || !exactRecap.every(
|
|
3999
|
-
(entry) => entry !== null && typeof entry === "object" && typeof entry.service === "string" && typeof entry.space === "string" && typeof entry.path === "string" && Array.isArray(entry.actions) && entry.actions.every((action) => typeof action === "string") && Array.isArray(entry.caveats) && entry.caveats.every(
|
|
4000
|
-
(caveat) => caveat !== null && typeof caveat === "object" && !Array.isArray(caveat)
|
|
4001
|
-
)
|
|
4002
|
-
)) {
|
|
4003
|
-
throw new UnsupportedSessionRestoreError(
|
|
4004
|
-
"it cannot reconstruct caveat-preserving persisted ReCap authority"
|
|
4005
|
-
);
|
|
4006
|
-
}
|
|
4007
|
-
stagedRecap = exactRecap.map((entry) => ({
|
|
4008
|
-
service: entry.service,
|
|
4009
|
-
space: entry.space,
|
|
4010
|
-
path: entry.path,
|
|
4011
|
-
actions: [...entry.actions],
|
|
4012
|
-
caveats: cloneRecapCaveats(entry.caveats)
|
|
4013
|
-
}));
|
|
4017
|
+
stagedRecap = exactVerifiedRecap(verified);
|
|
4014
4018
|
const signedExpiry = verified.expiresAt === void 0 ? void 0 : persistedExpiry(verified.expiresAt);
|
|
4015
4019
|
const persistedPolicyExpiry = sessionData.expiresAt === void 0 ? void 0 : persistedExpiry(sessionData.expiresAt);
|
|
4016
4020
|
if (signedExpiry && persistedPolicyExpiry && !sameInstant(signedExpiry, persistedPolicyExpiry)) {
|
|
@@ -5871,6 +5875,42 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5871
5875
|
(left, right) => left.service.localeCompare(right.service) || (left.space ?? "").localeCompare(right.space ?? "") || left.path.localeCompare(right.path) || left.actions.join("\0").localeCompare(right.actions.join("\0"))
|
|
5872
5876
|
);
|
|
5873
5877
|
}
|
|
5878
|
+
/**
|
|
5879
|
+
* Verify a wallet-signed session grant (a CACAO built from a SIWE and its
|
|
5880
|
+
* EIP-191 signature) issued to this instance's live session key. The
|
|
5881
|
+
* verifier rebuilds the CACAO from `siwe` and `signature`, so the grant is
|
|
5882
|
+
* accepted only when its authorization bytes and CID are exactly that CACAO,
|
|
5883
|
+
* its signer is `address`, its audience is this session key, it is valid
|
|
5884
|
+
* now, and its ReCap covers `spaceId` or names only raw encryption networks
|
|
5885
|
+
* (a decrypt-only grant has no space). Returns the signed ReCap and expiry.
|
|
5886
|
+
* Bindings without `validateSessionGrant` fall back to the session verifier,
|
|
5887
|
+
* which also refuses decrypt-only grants.
|
|
5888
|
+
*/
|
|
5889
|
+
verifySessionGrant(grant) {
|
|
5890
|
+
const bindings = this.wasmBindings;
|
|
5891
|
+
const validate = typeof bindings.validateSessionGrant === "function" ? bindings.validateSessionGrant.bind(bindings) : bindings.validatePersistedSession?.bind(bindings);
|
|
5892
|
+
if (validate === void 0) {
|
|
5893
|
+
throw new UnsupportedSessionRestoreError("it cannot verify persisted SIWE authority");
|
|
5894
|
+
}
|
|
5895
|
+
const verified = validate({
|
|
5896
|
+
delegationHeader: { Authorization: grant.delegationHeader.Authorization },
|
|
5897
|
+
delegationCid: grant.delegationCid,
|
|
5898
|
+
spaceId: grant.spaceId,
|
|
5899
|
+
jwk: this.sessionKeyJwk,
|
|
5900
|
+
address: canonicalizeAddress2(grant.address),
|
|
5901
|
+
chainId: grant.chainId,
|
|
5902
|
+
siwe: grant.siwe,
|
|
5903
|
+
signature: grant.signature
|
|
5904
|
+
});
|
|
5905
|
+
if (typeof verified.expiresAt !== "string") {
|
|
5906
|
+
throw new Error("Session grant has no signed expiry.");
|
|
5907
|
+
}
|
|
5908
|
+
const expiresAt = new Date(verified.expiresAt);
|
|
5909
|
+
if (!Number.isFinite(expiresAt.getTime())) {
|
|
5910
|
+
throw new Error("Session grant has an invalid signed expiry.");
|
|
5911
|
+
}
|
|
5912
|
+
return { recap: exactVerifiedRecap(verified), expiresAt };
|
|
5913
|
+
}
|
|
5874
5914
|
/**
|
|
5875
5915
|
* Install a portable runtime permission delegation into this SDK instance so
|
|
5876
5916
|
* matching service calls and downstream `delegateTo()` calls can use it.
|
|
@@ -6003,7 +6043,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6003
6043
|
delegatedEntries,
|
|
6004
6044
|
spaceId,
|
|
6005
6045
|
session,
|
|
6006
|
-
expiresAt
|
|
6046
|
+
expiresAt,
|
|
6047
|
+
{ siwe: prepared.siwe, signature }
|
|
6007
6048
|
);
|
|
6008
6049
|
this.runtimePermissionGrants.push({
|
|
6009
6050
|
session: {
|
|
@@ -6789,7 +6830,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6789
6830
|
}
|
|
6790
6831
|
return grants;
|
|
6791
6832
|
}
|
|
6792
|
-
runtimeDelegationFromSession(delegatedSession, entries, spaceId, session, expiresAt) {
|
|
6833
|
+
runtimeDelegationFromSession(delegatedSession, entries, spaceId, session, expiresAt, siweProof) {
|
|
6793
6834
|
const resources = this.delegatedResourcesForEntries(entries, spaceId);
|
|
6794
6835
|
const primary = resources[0];
|
|
6795
6836
|
return {
|
|
@@ -6804,7 +6845,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6804
6845
|
delegateDID: session.verificationMethod,
|
|
6805
6846
|
ownerAddress: session.address,
|
|
6806
6847
|
chainId: session.chainId,
|
|
6807
|
-
host: this.config.host
|
|
6848
|
+
host: this.config.host,
|
|
6849
|
+
siweProof
|
|
6808
6850
|
};
|
|
6809
6851
|
}
|
|
6810
6852
|
runtimeGrantFromDelegation(delegation, session) {
|
|
@@ -6997,6 +7039,9 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6997
7039
|
if (grantedAction === requestedAction) {
|
|
6998
7040
|
return true;
|
|
6999
7041
|
}
|
|
7042
|
+
if (isExplicitOnlyAction(requestedAction)) {
|
|
7043
|
+
return false;
|
|
7044
|
+
}
|
|
7000
7045
|
if (grantedAction.endsWith("/*")) {
|
|
7001
7046
|
const prefix = grantedAction.slice(0, -2);
|
|
7002
7047
|
return requestedAction.startsWith(`${prefix}/`);
|
|
@@ -7524,6 +7569,16 @@ import {
|
|
|
7524
7569
|
decodeBase64Url,
|
|
7525
7570
|
principalDidEquals as principalDidEquals3
|
|
7526
7571
|
} from "@tinycloud/sdk-core";
|
|
7572
|
+
var RuntimeDelegationRejectedError = class extends Error {
|
|
7573
|
+
constructor(reason, message) {
|
|
7574
|
+
super(message);
|
|
7575
|
+
this.name = "RuntimeDelegationRejectedError";
|
|
7576
|
+
this.reason = reason;
|
|
7577
|
+
}
|
|
7578
|
+
};
|
|
7579
|
+
function reject(reason, message) {
|
|
7580
|
+
throw new RuntimeDelegationRejectedError(reason, message);
|
|
7581
|
+
}
|
|
7527
7582
|
var SERVICE_BY_SHORT_NAME = {
|
|
7528
7583
|
kv: "tinycloud.kv",
|
|
7529
7584
|
sql: "tinycloud.sql",
|
|
@@ -7670,6 +7725,15 @@ function signedAuthorityFromCompactUcan(authorization) {
|
|
|
7670
7725
|
abilities
|
|
7671
7726
|
));
|
|
7672
7727
|
}
|
|
7728
|
+
return canonicalSignedAuthority({
|
|
7729
|
+
issuer: payload.iss,
|
|
7730
|
+
audience: payload.aud,
|
|
7731
|
+
expiry,
|
|
7732
|
+
proofs: [...payload.prf],
|
|
7733
|
+
...remainingRedelegationDepth === void 0 ? {} : { remainingRedelegationDepth }
|
|
7734
|
+
}, permissions);
|
|
7735
|
+
}
|
|
7736
|
+
function canonicalSignedAuthority(signed, permissions) {
|
|
7673
7737
|
if (permissions.length === 0) {
|
|
7674
7738
|
throw new Error("Validated runtime delegation has no signed capabilities.");
|
|
7675
7739
|
}
|
|
@@ -7681,15 +7745,84 @@ function signedAuthorityFromCompactUcan(authorization) {
|
|
|
7681
7745
|
actions: [...permission.actions],
|
|
7682
7746
|
...permission.caveats === void 0 ? {} : { caveats: permission.caveats }
|
|
7683
7747
|
}));
|
|
7684
|
-
return {
|
|
7685
|
-
|
|
7686
|
-
|
|
7687
|
-
|
|
7688
|
-
|
|
7689
|
-
|
|
7690
|
-
|
|
7691
|
-
|
|
7692
|
-
|
|
7748
|
+
return { ...signed, permissions: canonicalPermissions, resources: canonicalResources };
|
|
7749
|
+
}
|
|
7750
|
+
var RAW_ENCRYPTION_PREFIX = "urn:tinycloud:encryption:";
|
|
7751
|
+
var PKH_SPACE = /^tinycloud:pkh:eip155:(\d+):(0x[0-9a-fA-F]{40}):(.+)$/;
|
|
7752
|
+
function comparableSpace(space) {
|
|
7753
|
+
const match = PKH_SPACE.exec(space);
|
|
7754
|
+
return match ? `tinycloud:pkh:eip155:${match[1]}:${match[2].toLowerCase()}:${match[3]}` : space;
|
|
7755
|
+
}
|
|
7756
|
+
function signedAuthorityFromSessionGrant(node, delegation, authorization, cid) {
|
|
7757
|
+
const proof = delegation.siweProof;
|
|
7758
|
+
if (proof === void 0 || proof === null || typeof proof !== "object" || typeof proof.siwe !== "string" || typeof proof.signature !== "string") {
|
|
7759
|
+
reject(
|
|
7760
|
+
"proof_missing",
|
|
7761
|
+
"Runtime delegation is a wallet-signed session grant stored without its signed SIWE proof, so its authority cannot be verified."
|
|
7762
|
+
);
|
|
7763
|
+
}
|
|
7764
|
+
if (typeof node.verifySessionGrant !== "function") {
|
|
7765
|
+
reject("unsupported", "This runtime cannot verify wallet-signed session grants.");
|
|
7766
|
+
}
|
|
7767
|
+
const owner = `did:pkh:eip155:${delegation.chainId}:${delegation.ownerAddress}`;
|
|
7768
|
+
if (typeof node.did !== "string" || !didPrincipalsMatch(owner, node.did)) {
|
|
7769
|
+
reject("owner_mismatch", "Runtime delegation is not signed by this session's owner.");
|
|
7770
|
+
}
|
|
7771
|
+
let verified;
|
|
7772
|
+
try {
|
|
7773
|
+
verified = node.verifySessionGrant({
|
|
7774
|
+
delegationHeader: { Authorization: authorization },
|
|
7775
|
+
delegationCid: cid,
|
|
7776
|
+
spaceId: delegation.spaceId,
|
|
7777
|
+
address: delegation.ownerAddress,
|
|
7778
|
+
chainId: delegation.chainId,
|
|
7779
|
+
siwe: proof.siwe,
|
|
7780
|
+
signature: proof.signature
|
|
7781
|
+
});
|
|
7782
|
+
} catch (error) {
|
|
7783
|
+
reject("proof_invalid", error instanceof Error ? error.message : String(error));
|
|
7784
|
+
}
|
|
7785
|
+
const space = comparableSpace(delegation.spaceId);
|
|
7786
|
+
const spaceOwner = PKH_SPACE.exec(delegation.spaceId);
|
|
7787
|
+
if (!spaceOwner || !didPrincipalsMatch(`did:pkh:eip155:${spaceOwner[1]}:${spaceOwner[2]}`, owner)) {
|
|
7788
|
+
reject("authority_invalid", "Runtime delegation space is not owned by its signer.");
|
|
7789
|
+
}
|
|
7790
|
+
const groups = /* @__PURE__ */ new Map();
|
|
7791
|
+
for (const entry of verified.recap) {
|
|
7792
|
+
const service = entry.service.startsWith("tinycloud.") ? entry.service : `tinycloud.${entry.service}`;
|
|
7793
|
+
const raw = entry.space === "encryption";
|
|
7794
|
+
if (raw) {
|
|
7795
|
+
if (service !== "tinycloud.encryption" || !entry.path.startsWith(RAW_ENCRYPTION_PREFIX)) {
|
|
7796
|
+
reject("authority_invalid", "Runtime delegation has an unsupported signed raw resource.");
|
|
7797
|
+
}
|
|
7798
|
+
const networkOwner = entry.path.slice(RAW_ENCRYPTION_PREFIX.length, entry.path.lastIndexOf(":"));
|
|
7799
|
+
if (!didPrincipalsMatch(networkOwner, owner)) {
|
|
7800
|
+
reject("authority_invalid", "Runtime delegation names an encryption network its signer does not own.");
|
|
7801
|
+
}
|
|
7802
|
+
} else if (service === "tinycloud.encryption" || comparableSpace(entry.space) !== space) {
|
|
7803
|
+
reject("authority_invalid", "Runtime delegation has signed authority outside its space.");
|
|
7804
|
+
}
|
|
7805
|
+
const caveats = signedCaveats(entry.caveats ?? []);
|
|
7806
|
+
const key = JSON.stringify([service, raw ? "" : entry.space, entry.path, canonicalizeRecapCaveats2(caveats)]);
|
|
7807
|
+
const group = groups.get(key) ?? {
|
|
7808
|
+
service,
|
|
7809
|
+
...raw ? {} : { space: entry.space },
|
|
7810
|
+
path: entry.path,
|
|
7811
|
+
actions: [],
|
|
7812
|
+
...caveats === void 0 ? {} : { caveats }
|
|
7813
|
+
};
|
|
7814
|
+
for (const action of entry.actions) {
|
|
7815
|
+
if (!group.actions.includes(action)) group.actions.push(action);
|
|
7816
|
+
}
|
|
7817
|
+
groups.set(key, group);
|
|
7818
|
+
}
|
|
7819
|
+
return canonicalSignedAuthority({
|
|
7820
|
+
issuer: owner,
|
|
7821
|
+
// The verifier bound the SIWE audience to this runtime's own session key.
|
|
7822
|
+
audience: node.sessionDid,
|
|
7823
|
+
expiry: verified.expiresAt,
|
|
7824
|
+
proofs: []
|
|
7825
|
+
}, [...groups.values()]);
|
|
7693
7826
|
}
|
|
7694
7827
|
function canonicalResourcesFromPortableDelegation(delegation) {
|
|
7695
7828
|
if (delegation.resources !== void 0 && delegation.resources.length > 0) {
|
|
@@ -7725,49 +7858,58 @@ function resourcesMatch(actual, expected) {
|
|
|
7725
7858
|
async function activateValidatedRuntimeDelegation(node, delegation, options) {
|
|
7726
7859
|
const host = normalizedHost(options.host);
|
|
7727
7860
|
if (delegation.host !== void 0 && normalizedHost(delegation.host) !== host) {
|
|
7728
|
-
|
|
7861
|
+
reject(
|
|
7862
|
+
"host_mismatch",
|
|
7729
7863
|
`Runtime delegation host '${delegation.host}' does not match expected host '${options.host}'.`
|
|
7730
7864
|
);
|
|
7731
7865
|
}
|
|
7732
7866
|
if (!(delegation.expiry instanceof Date) || Number.isNaN(delegation.expiry.getTime())) {
|
|
7733
|
-
|
|
7867
|
+
reject("authority_invalid", "Runtime delegation has an invalid expiry.");
|
|
7734
7868
|
}
|
|
7735
7869
|
if (delegation.expiry.getTime() <= Date.now()) {
|
|
7736
|
-
|
|
7870
|
+
reject("expired", "Runtime delegation is expired.");
|
|
7737
7871
|
}
|
|
7738
7872
|
const authorization = delegation.delegationHeader?.Authorization;
|
|
7739
7873
|
if (typeof authorization !== "string" || authorization.length === 0) {
|
|
7740
|
-
|
|
7874
|
+
reject("authority_invalid", "Runtime delegation is missing authorization bytes.");
|
|
7741
7875
|
}
|
|
7742
7876
|
const cid = node.computeDelegationCid(authorization);
|
|
7743
7877
|
if (cid !== delegation.cid) {
|
|
7744
|
-
|
|
7878
|
+
reject("cid_mismatch", "Runtime delegation CID does not match authorization bytes.");
|
|
7879
|
+
}
|
|
7880
|
+
const compact = authorizationWithoutBearer(authorization).split(".").length === 3;
|
|
7881
|
+
let signed;
|
|
7882
|
+
try {
|
|
7883
|
+
signed = compact ? signedAuthorityFromCompactUcan(authorization) : signedAuthorityFromSessionGrant(node, delegation, authorization, cid);
|
|
7884
|
+
} catch (error) {
|
|
7885
|
+
if (error instanceof RuntimeDelegationRejectedError) throw error;
|
|
7886
|
+
reject("authority_invalid", error instanceof Error ? error.message : String(error));
|
|
7745
7887
|
}
|
|
7746
|
-
const signed = signedAuthorityFromCompactUcan(authorization);
|
|
7747
7888
|
if (signed.expiry.getTime() <= Date.now()) {
|
|
7748
|
-
|
|
7889
|
+
reject("expired", "Runtime delegation is expired.");
|
|
7749
7890
|
}
|
|
7750
7891
|
if (delegation.expiry.getTime() !== signed.expiry.getTime()) {
|
|
7751
|
-
|
|
7892
|
+
reject("authority_invalid", "Runtime delegation expiry does not match signed authority.");
|
|
7752
7893
|
}
|
|
7753
7894
|
if (!didPrincipalsMatch(signed.audience, node.sessionDid)) {
|
|
7754
|
-
|
|
7895
|
+
reject(
|
|
7896
|
+
"audience_mismatch",
|
|
7755
7897
|
`Runtime delegation targets ${signed.audience} but this session is ${node.sessionDid}.`
|
|
7756
7898
|
);
|
|
7757
7899
|
}
|
|
7758
7900
|
if (!didPrincipalsMatch(delegation.delegateDID, signed.audience)) {
|
|
7759
|
-
|
|
7901
|
+
reject("audience_mismatch", "Runtime delegation audience does not match signed authority.");
|
|
7760
7902
|
}
|
|
7761
|
-
|
|
7762
|
-
|
|
7763
|
-
throw new Error("Runtime delegation resources do not match signed authority.");
|
|
7903
|
+
if (compact && !resourcesMatch(canonicalResourcesFromPortableDelegation(delegation), signed.resources)) {
|
|
7904
|
+
reject("resources_mismatch", "Runtime delegation resources do not match signed authority.");
|
|
7764
7905
|
}
|
|
7765
7906
|
if (options.authorize !== void 0 && !options.authorize(signed.permissions)) {
|
|
7766
7907
|
throw new Error("Runtime delegation is not authorized for this runtime.");
|
|
7767
7908
|
}
|
|
7768
7909
|
const previouslyInstalled = node.getRuntimePermissionDelegations().find((candidate) => candidate.cid === cid);
|
|
7769
7910
|
if (previouslyInstalled !== void 0 && previouslyInstalled.delegationHeader.Authorization !== authorization) {
|
|
7770
|
-
|
|
7911
|
+
reject(
|
|
7912
|
+
"cid_mismatch",
|
|
7771
7913
|
"A different authorization is already installed for this runtime delegation CID."
|
|
7772
7914
|
);
|
|
7773
7915
|
}
|
|
@@ -7797,22 +7939,28 @@ async function activateValidatedRuntimeDelegation(node, delegation, options) {
|
|
|
7797
7939
|
})),
|
|
7798
7940
|
expiry: new Date(signed.expiry),
|
|
7799
7941
|
delegateDID: signed.audience,
|
|
7800
|
-
host
|
|
7942
|
+
host,
|
|
7943
|
+
...compact ? {} : { siweProof: delegation.siweProof }
|
|
7801
7944
|
};
|
|
7802
|
-
|
|
7803
|
-
|
|
7804
|
-
|
|
7805
|
-
|
|
7945
|
+
try {
|
|
7946
|
+
if (node.isSessionOnly === true && typeof node.did === "string" && principalDidEquals3(node.did, node.sessionDid) && typeof node.useDelegation === "function") {
|
|
7947
|
+
await node.useDelegation(installedCandidate);
|
|
7948
|
+
} else {
|
|
7949
|
+
await node.useRuntimeDelegation(installedCandidate);
|
|
7950
|
+
}
|
|
7951
|
+
} catch (error) {
|
|
7952
|
+
reject("activation_rejected", error instanceof Error ? error.message : String(error));
|
|
7806
7953
|
}
|
|
7807
7954
|
const installed = node.getRuntimePermissionDelegations().find((candidate) => candidate.cid === cid);
|
|
7808
7955
|
if (!installed) {
|
|
7809
|
-
|
|
7956
|
+
reject("activation_rejected", "Runtime delegation activation did not install the validated authority.");
|
|
7810
7957
|
}
|
|
7811
7958
|
if (installed.delegationHeader.Authorization !== authorization || !didPrincipalsMatch(installed.delegateDID, signed.audience) || installed.expiry.getTime() !== signed.expiry.getTime() || !resourcesMatch(
|
|
7812
7959
|
canonicalResourcesFromPortableDelegation(installed),
|
|
7813
7960
|
signed.resources
|
|
7814
7961
|
) || normalizedHost(installed.host ?? "") !== host) {
|
|
7815
|
-
|
|
7962
|
+
reject(
|
|
7963
|
+
"activation_rejected",
|
|
7816
7964
|
"Runtime delegation activation installed authority that differs from the validated authority."
|
|
7817
7965
|
);
|
|
7818
7966
|
}
|