@tinycloud/node-sdk 2.1.0-beta.0 → 2.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.cjs +366 -89
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +92 -3
- package/dist/core.d.ts +92 -3
- package/dist/core.js +294 -8
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +370 -92
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +296 -8
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ISigner, Bytes, IWasmBindings, ISessionManager } from '@tinycloud/sdk-core';
|
|
2
|
-
export { AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, ClientSession, ColumnInfo, CreateDelegationParams, DataVaultConfig, DataVaultService, DatabaseHandle, Delegation, DelegationChain, DelegationChainV2, DelegationDirection, DelegationError, DelegationErrorCode, DelegationErrorCodes, DelegationFilters, DelegationManager, DelegationManagerConfig, DelegationRecord, DelegationResult, DuckDbAction, DuckDbActionType, DuckDbBatchOptions, DuckDbBatchResponse, DuckDbDatabaseHandle, DuckDbExecuteOptions, DuckDbExecuteResponse, DuckDbOptions, DuckDbQueryOptions, DuckDbQueryResponse, DuckDbService, DuckDbServiceConfig, DuckDbStatement, DuckDbValue, EncodedShareData, ExecuteOptions, ExecuteResponse, Extension, FetchFunction, GenerateShareParams, HookEvent, HookServiceName, HookStreamEvent, HookSubscription, HookWebhookListOptions, HookWebhookRecord, HookWebhookRegistration, HookWebhookScope, HookWebhookUnregisterOptions, HooksService, HooksServiceConfig, ICapabilityKeyRegistry, IDataVaultService, IDatabaseHandle, IDuckDbDatabaseHandle, IDuckDbService, IENSResolver, IHooksService, IKVService, INotificationHandler, IPrefixedKVService, ISQLService, ISessionManager, ISessionStorage, ISharingService, ISigner, ISpace, ISpaceCreationHandler, ISpaceScopedDelegations, ISpaceScopedSharing, ISpaceService, IUserAuthorization, IWasmBindings, IngestOptions, InvokeFunction, JWK, KVResponse, KVService, KVServiceConfig, KeyInfo, KeyProvider, KeyType, PersistedSessionData, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, ServiceContext, ServiceContextConfig, ServiceSession, ShareAccess, ShareLink, ShareLinkData, ShareSchema, SharingService, SharingServiceConfig, SignCallback, SignRequest, SignResponse, SilentNotificationHandler, Space, SpaceConfig, SpaceCreationContext, SpaceErrorCode, SpaceErrorCodes, SpaceInfo, SpaceOwnership, SpaceService, SpaceServiceConfig, SqlStatement, SqlValue, StoredDelegationChain, SubscribeOptions, TableInfo, TinyCloud, TinyCloudConfig, TinyCloudSession, UnsupportedFeatureError, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultPublicSpaceKVActions, VaultPutOptions, VersionCheckError, ViewInfo, WasmVaultFunctions, buildSpaceUri, checkNodeInfo, createCapabilityKeyRegistry, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, makePublicSpaceId, parseSpaceUri } from '@tinycloud/sdk-core';
|
|
3
|
-
export { DelegatedAccess, FileSessionStorage, MemorySessionStorage, NodeEventEmitterStrategy, NodeUserAuthorization, NodeUserAuthorizationConfig, PortableDelegation, SignStrategy, TinyCloudNode, TinyCloudNodeConfig, WasmKeyProvider, WasmKeyProviderConfig, createWasmKeyProvider, defaultSignStrategy, deserializeDelegation, serializeDelegation } from './core.cjs';
|
|
4
|
-
import { invoke, invokeAny, prepareSession, completeSessionSetup, ensureEip55, makeSpaceId, createDelegation, generateHostSIWEMessage, siweToDelegationHeaders, protocolVersion, vault_encrypt, vault_decrypt, vault_derive_key, vault_x25519_from_seed, vault_x25519_dh, vault_random_bytes, vault_sha256 } from '@tinycloud/node-sdk-wasm';
|
|
2
|
+
export { AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, ClientSession, ColumnInfo, CreateDelegationParams, DataVaultConfig, DataVaultService, DatabaseHandle, Delegation, DelegationChain, DelegationChainV2, DelegationDirection, DelegationError, DelegationErrorCode, DelegationErrorCodes, DelegationFilters, DelegationManager, DelegationManagerConfig, DelegationRecord, DelegationResult, DuckDbAction, DuckDbActionType, DuckDbBatchOptions, DuckDbBatchResponse, DuckDbDatabaseHandle, DuckDbExecuteOptions, DuckDbExecuteResponse, DuckDbOptions, DuckDbQueryOptions, DuckDbQueryResponse, DuckDbService, DuckDbServiceConfig, DuckDbStatement, DuckDbValue, EncodedShareData, ExecuteOptions, ExecuteResponse, Extension, FetchFunction, GenerateShareParams, HookEvent, HookServiceName, HookStreamEvent, HookSubscription, HookWebhookListOptions, HookWebhookRecord, HookWebhookRegistration, HookWebhookScope, HookWebhookUnregisterOptions, HooksService, HooksServiceConfig, ICapabilityKeyRegistry, IDataVaultService, IDatabaseHandle, IDuckDbDatabaseHandle, IDuckDbService, IENSResolver, IHooksService, IKVService, INotificationHandler, IPrefixedKVService, ISQLService, ISessionManager, ISessionStorage, ISharingService, ISigner, ISpace, ISpaceCreationHandler, ISpaceScopedDelegations, ISpaceScopedSharing, ISpaceService, IUserAuthorization, IWasmBindings, IngestOptions, InvokeFunction, JWK, KVResponse, KVService, KVServiceConfig, KeyInfo, KeyProvider, KeyType, Manifest, ManifestDefaults, ManifestDelegation, ManifestValidationError, PermissionEntry, PermissionNotInManifestError, PersistedSessionData, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, ResolvedCapabilities, ResolvedDelegate, ResourceCapability, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, ServiceContext, ServiceContextConfig, ServiceSession, SessionExpiredError, ShareAccess, ShareLink, ShareLinkData, ShareSchema, SharingService, SharingServiceConfig, SignCallback, SignRequest, SignResponse, SilentNotificationHandler, Space, SpaceConfig, SpaceCreationContext, SpaceErrorCode, SpaceErrorCodes, SpaceInfo, SpaceOwnership, SpaceService, SpaceServiceConfig, SqlStatement, SqlValue, StoredDelegationChain, SubscribeOptions, TableInfo, TinyCloud, TinyCloudConfig, TinyCloudSession, UnsupportedFeatureError, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultPublicSpaceKVActions, VaultPutOptions, VersionCheckError, ViewInfo, WasmVaultFunctions, buildSpaceUri, checkNodeInfo, createCapabilityKeyRegistry, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, expandActionShortNames, isCapabilitySubset, loadManifest, makePublicSpaceId, parseExpiry, parseSpaceUri, resolveManifest, validateManifest } from '@tinycloud/sdk-core';
|
|
3
|
+
export { DelegateToOptions, DelegateToResult, DelegatedAccess, FileSessionStorage, MemorySessionStorage, NodeEventEmitterStrategy, NodeUserAuthorization, NodeUserAuthorizationConfig, PortableDelegation, SignStrategy, TinyCloudNode, TinyCloudNodeConfig, WasmKeyProvider, WasmKeyProviderConfig, createWasmKeyProvider, defaultSignStrategy, deserializeDelegation, serializeDelegation } from './core.cjs';
|
|
4
|
+
import { invoke, invokeAny, prepareSession, completeSessionSetup, ensureEip55, makeSpaceId, createDelegation, parseRecapFromSiwe, generateHostSIWEMessage, siweToDelegationHeaders, protocolVersion, vault_encrypt, vault_decrypt, vault_derive_key, vault_x25519_from_seed, vault_x25519_dh, vault_random_bytes, vault_sha256 } from '@tinycloud/node-sdk-wasm';
|
|
5
5
|
import 'events';
|
|
6
6
|
import '@tinycloud/sdk-services';
|
|
7
7
|
|
|
@@ -76,6 +76,7 @@ declare class NodeWasmBindings implements IWasmBindings {
|
|
|
76
76
|
ensureEip55: typeof ensureEip55;
|
|
77
77
|
makeSpaceId: typeof makeSpaceId;
|
|
78
78
|
createDelegation: typeof createDelegation;
|
|
79
|
+
parseRecapFromSiwe: typeof parseRecapFromSiwe;
|
|
79
80
|
generateHostSIWEMessage: typeof generateHostSIWEMessage;
|
|
80
81
|
siweToDelegationHeaders: typeof siweToDelegationHeaders;
|
|
81
82
|
protocolVersion: typeof protocolVersion;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ISigner, Bytes, IWasmBindings, ISessionManager } from '@tinycloud/sdk-core';
|
|
2
|
-
export { AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, ClientSession, ColumnInfo, CreateDelegationParams, DataVaultConfig, DataVaultService, DatabaseHandle, Delegation, DelegationChain, DelegationChainV2, DelegationDirection, DelegationError, DelegationErrorCode, DelegationErrorCodes, DelegationFilters, DelegationManager, DelegationManagerConfig, DelegationRecord, DelegationResult, DuckDbAction, DuckDbActionType, DuckDbBatchOptions, DuckDbBatchResponse, DuckDbDatabaseHandle, DuckDbExecuteOptions, DuckDbExecuteResponse, DuckDbOptions, DuckDbQueryOptions, DuckDbQueryResponse, DuckDbService, DuckDbServiceConfig, DuckDbStatement, DuckDbValue, EncodedShareData, ExecuteOptions, ExecuteResponse, Extension, FetchFunction, GenerateShareParams, HookEvent, HookServiceName, HookStreamEvent, HookSubscription, HookWebhookListOptions, HookWebhookRecord, HookWebhookRegistration, HookWebhookScope, HookWebhookUnregisterOptions, HooksService, HooksServiceConfig, ICapabilityKeyRegistry, IDataVaultService, IDatabaseHandle, IDuckDbDatabaseHandle, IDuckDbService, IENSResolver, IHooksService, IKVService, INotificationHandler, IPrefixedKVService, ISQLService, ISessionManager, ISessionStorage, ISharingService, ISigner, ISpace, ISpaceCreationHandler, ISpaceScopedDelegations, ISpaceScopedSharing, ISpaceService, IUserAuthorization, IWasmBindings, IngestOptions, InvokeFunction, JWK, KVResponse, KVService, KVServiceConfig, KeyInfo, KeyProvider, KeyType, PersistedSessionData, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, ServiceContext, ServiceContextConfig, ServiceSession, ShareAccess, ShareLink, ShareLinkData, ShareSchema, SharingService, SharingServiceConfig, SignCallback, SignRequest, SignResponse, SilentNotificationHandler, Space, SpaceConfig, SpaceCreationContext, SpaceErrorCode, SpaceErrorCodes, SpaceInfo, SpaceOwnership, SpaceService, SpaceServiceConfig, SqlStatement, SqlValue, StoredDelegationChain, SubscribeOptions, TableInfo, TinyCloud, TinyCloudConfig, TinyCloudSession, UnsupportedFeatureError, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultPublicSpaceKVActions, VaultPutOptions, VersionCheckError, ViewInfo, WasmVaultFunctions, buildSpaceUri, checkNodeInfo, createCapabilityKeyRegistry, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, makePublicSpaceId, parseSpaceUri } from '@tinycloud/sdk-core';
|
|
3
|
-
export { DelegatedAccess, FileSessionStorage, MemorySessionStorage, NodeEventEmitterStrategy, NodeUserAuthorization, NodeUserAuthorizationConfig, PortableDelegation, SignStrategy, TinyCloudNode, TinyCloudNodeConfig, WasmKeyProvider, WasmKeyProviderConfig, createWasmKeyProvider, defaultSignStrategy, deserializeDelegation, serializeDelegation } from './core.js';
|
|
4
|
-
import { invoke, invokeAny, prepareSession, completeSessionSetup, ensureEip55, makeSpaceId, createDelegation, generateHostSIWEMessage, siweToDelegationHeaders, protocolVersion, vault_encrypt, vault_decrypt, vault_derive_key, vault_x25519_from_seed, vault_x25519_dh, vault_random_bytes, vault_sha256 } from '@tinycloud/node-sdk-wasm';
|
|
2
|
+
export { AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, ClientSession, ColumnInfo, CreateDelegationParams, DataVaultConfig, DataVaultService, DatabaseHandle, Delegation, DelegationChain, DelegationChainV2, DelegationDirection, DelegationError, DelegationErrorCode, DelegationErrorCodes, DelegationFilters, DelegationManager, DelegationManagerConfig, DelegationRecord, DelegationResult, DuckDbAction, DuckDbActionType, DuckDbBatchOptions, DuckDbBatchResponse, DuckDbDatabaseHandle, DuckDbExecuteOptions, DuckDbExecuteResponse, DuckDbOptions, DuckDbQueryOptions, DuckDbQueryResponse, DuckDbService, DuckDbServiceConfig, DuckDbStatement, DuckDbValue, EncodedShareData, ExecuteOptions, ExecuteResponse, Extension, FetchFunction, GenerateShareParams, HookEvent, HookServiceName, HookStreamEvent, HookSubscription, HookWebhookListOptions, HookWebhookRecord, HookWebhookRegistration, HookWebhookScope, HookWebhookUnregisterOptions, HooksService, HooksServiceConfig, ICapabilityKeyRegistry, IDataVaultService, IDatabaseHandle, IDuckDbDatabaseHandle, IDuckDbService, IENSResolver, IHooksService, IKVService, INotificationHandler, IPrefixedKVService, ISQLService, ISessionManager, ISessionStorage, ISharingService, ISigner, ISpace, ISpaceCreationHandler, ISpaceScopedDelegations, ISpaceScopedSharing, ISpaceService, IUserAuthorization, IWasmBindings, IngestOptions, InvokeFunction, JWK, KVResponse, KVService, KVServiceConfig, KeyInfo, KeyProvider, KeyType, Manifest, ManifestDefaults, ManifestDelegation, ManifestValidationError, PermissionEntry, PermissionNotInManifestError, PersistedSessionData, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, ResolvedCapabilities, ResolvedDelegate, ResourceCapability, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, ServiceContext, ServiceContextConfig, ServiceSession, SessionExpiredError, ShareAccess, ShareLink, ShareLinkData, ShareSchema, SharingService, SharingServiceConfig, SignCallback, SignRequest, SignResponse, SilentNotificationHandler, Space, SpaceConfig, SpaceCreationContext, SpaceErrorCode, SpaceErrorCodes, SpaceInfo, SpaceOwnership, SpaceService, SpaceServiceConfig, SqlStatement, SqlValue, StoredDelegationChain, SubscribeOptions, TableInfo, TinyCloud, TinyCloudConfig, TinyCloudSession, UnsupportedFeatureError, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultPublicSpaceKVActions, VaultPutOptions, VersionCheckError, ViewInfo, WasmVaultFunctions, buildSpaceUri, checkNodeInfo, createCapabilityKeyRegistry, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, expandActionShortNames, isCapabilitySubset, loadManifest, makePublicSpaceId, parseExpiry, parseSpaceUri, resolveManifest, validateManifest } from '@tinycloud/sdk-core';
|
|
3
|
+
export { DelegateToOptions, DelegateToResult, DelegatedAccess, FileSessionStorage, MemorySessionStorage, NodeEventEmitterStrategy, NodeUserAuthorization, NodeUserAuthorizationConfig, PortableDelegation, SignStrategy, TinyCloudNode, TinyCloudNodeConfig, WasmKeyProvider, WasmKeyProviderConfig, createWasmKeyProvider, defaultSignStrategy, deserializeDelegation, serializeDelegation } from './core.js';
|
|
4
|
+
import { invoke, invokeAny, prepareSession, completeSessionSetup, ensureEip55, makeSpaceId, createDelegation, parseRecapFromSiwe, generateHostSIWEMessage, siweToDelegationHeaders, protocolVersion, vault_encrypt, vault_decrypt, vault_derive_key, vault_x25519_from_seed, vault_x25519_dh, vault_random_bytes, vault_sha256 } from '@tinycloud/node-sdk-wasm';
|
|
5
5
|
import 'events';
|
|
6
6
|
import '@tinycloud/sdk-services';
|
|
7
7
|
|
|
@@ -76,6 +76,7 @@ declare class NodeWasmBindings implements IWasmBindings {
|
|
|
76
76
|
ensureEip55: typeof ensureEip55;
|
|
77
77
|
makeSpaceId: typeof makeSpaceId;
|
|
78
78
|
createDelegation: typeof createDelegation;
|
|
79
|
+
parseRecapFromSiwe: typeof parseRecapFromSiwe;
|
|
79
80
|
generateHostSIWEMessage: typeof generateHostSIWEMessage;
|
|
80
81
|
siweToDelegationHeaders: typeof siweToDelegationHeaders;
|
|
81
82
|
protocolVersion: typeof protocolVersion;
|
package/dist/index.js
CHANGED
|
@@ -17036,6 +17036,7 @@ import {
|
|
|
17036
17036
|
ensureEip55,
|
|
17037
17037
|
makeSpaceId,
|
|
17038
17038
|
createDelegation,
|
|
17039
|
+
parseRecapFromSiwe,
|
|
17039
17040
|
generateHostSIWEMessage,
|
|
17040
17041
|
siweToDelegationHeaders,
|
|
17041
17042
|
protocolVersion,
|
|
@@ -17058,6 +17059,7 @@ var _NodeWasmBindings = class _NodeWasmBindings {
|
|
|
17058
17059
|
this.ensureEip55 = ensureEip55;
|
|
17059
17060
|
this.makeSpaceId = makeSpaceId;
|
|
17060
17061
|
this.createDelegation = createDelegation;
|
|
17062
|
+
this.parseRecapFromSiwe = parseRecapFromSiwe;
|
|
17061
17063
|
this.generateHostSIWEMessage = generateHostSIWEMessage;
|
|
17062
17064
|
this.siweToDelegationHeaders = siweToDelegationHeaders;
|
|
17063
17065
|
this.protocolVersion = protocolVersion;
|
|
@@ -17165,7 +17167,12 @@ import {
|
|
|
17165
17167
|
CapabilityKeyRegistry,
|
|
17166
17168
|
SharingService,
|
|
17167
17169
|
UnsupportedFeatureError,
|
|
17168
|
-
makePublicSpaceId
|
|
17170
|
+
makePublicSpaceId,
|
|
17171
|
+
PermissionNotInManifestError,
|
|
17172
|
+
SessionExpiredError,
|
|
17173
|
+
expandActionShortNames,
|
|
17174
|
+
isCapabilitySubset,
|
|
17175
|
+
parseRecapCapabilities
|
|
17169
17176
|
} from "@tinycloud/sdk-core";
|
|
17170
17177
|
|
|
17171
17178
|
// src/authorization/NodeUserAuthorization.ts
|
|
@@ -18004,9 +18011,72 @@ function createWasmKeyProvider(sessionManager) {
|
|
|
18004
18011
|
return new WasmKeyProvider({ sessionManager });
|
|
18005
18012
|
}
|
|
18006
18013
|
|
|
18014
|
+
// src/delegateToHelpers.ts
|
|
18015
|
+
import {
|
|
18016
|
+
parseExpiry,
|
|
18017
|
+
SiweMessage
|
|
18018
|
+
} from "@tinycloud/sdk-core";
|
|
18019
|
+
function legacyParamsToPermissionEntries(actions, path, spaceIdOverride) {
|
|
18020
|
+
const byService = /* @__PURE__ */ new Map();
|
|
18021
|
+
for (const a of actions) {
|
|
18022
|
+
const slashIdx = a.indexOf("/");
|
|
18023
|
+
if (slashIdx === -1) {
|
|
18024
|
+
continue;
|
|
18025
|
+
}
|
|
18026
|
+
const service = a.slice(0, slashIdx);
|
|
18027
|
+
if (!service.startsWith("tinycloud.")) {
|
|
18028
|
+
continue;
|
|
18029
|
+
}
|
|
18030
|
+
const list = byService.get(service);
|
|
18031
|
+
if (list === void 0) {
|
|
18032
|
+
byService.set(service, [a]);
|
|
18033
|
+
} else {
|
|
18034
|
+
list.push(a);
|
|
18035
|
+
}
|
|
18036
|
+
}
|
|
18037
|
+
const space = spaceIdOverride ?? "default";
|
|
18038
|
+
const entries = [];
|
|
18039
|
+
for (const [service, actionList] of byService) {
|
|
18040
|
+
entries.push({
|
|
18041
|
+
service,
|
|
18042
|
+
space,
|
|
18043
|
+
path,
|
|
18044
|
+
actions: actionList
|
|
18045
|
+
});
|
|
18046
|
+
}
|
|
18047
|
+
return entries;
|
|
18048
|
+
}
|
|
18049
|
+
function resolveExpiryMs(expiry) {
|
|
18050
|
+
if (expiry === void 0) {
|
|
18051
|
+
return 60 * 60 * 1e3;
|
|
18052
|
+
}
|
|
18053
|
+
if (typeof expiry === "number") {
|
|
18054
|
+
if (!Number.isFinite(expiry) || expiry <= 0) {
|
|
18055
|
+
throw new Error(
|
|
18056
|
+
`delegateTo expiry must be a positive finite number (got ${expiry})`
|
|
18057
|
+
);
|
|
18058
|
+
}
|
|
18059
|
+
return expiry;
|
|
18060
|
+
}
|
|
18061
|
+
return parseExpiry(expiry);
|
|
18062
|
+
}
|
|
18063
|
+
function extractSiweExpiration(siwe) {
|
|
18064
|
+
const parsed = new SiweMessage(siwe);
|
|
18065
|
+
if (parsed.expirationTime === void 0 || parsed.expirationTime === null) {
|
|
18066
|
+
return void 0;
|
|
18067
|
+
}
|
|
18068
|
+
const d = new Date(parsed.expirationTime);
|
|
18069
|
+
if (Number.isNaN(d.getTime())) {
|
|
18070
|
+
throw new Error(
|
|
18071
|
+
`Session SIWE has unparseable expirationTime: ${parsed.expirationTime}`
|
|
18072
|
+
);
|
|
18073
|
+
}
|
|
18074
|
+
return d;
|
|
18075
|
+
}
|
|
18076
|
+
|
|
18007
18077
|
// src/TinyCloudNode.ts
|
|
18008
18078
|
var DEFAULT_HOST = "https://node.tinycloud.xyz";
|
|
18009
|
-
var
|
|
18079
|
+
var _TinyCloudNode = class _TinyCloudNode {
|
|
18010
18080
|
/**
|
|
18011
18081
|
* Create a new TinyCloudNode instance.
|
|
18012
18082
|
*
|
|
@@ -19140,6 +19210,150 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
19140
19210
|
async checkPermission(path, action) {
|
|
19141
19211
|
return this.delegationManager.checkPermission(path, action);
|
|
19142
19212
|
}
|
|
19213
|
+
/**
|
|
19214
|
+
* Issue a delegation using the capability-chain flow.
|
|
19215
|
+
*
|
|
19216
|
+
* When the requested permissions are a subset of the current session's
|
|
19217
|
+
* recap, the delegation is signed by the session key via WASM — no wallet
|
|
19218
|
+
* prompt. When they are not, a {@link PermissionNotInManifestError} is
|
|
19219
|
+
* raised so the caller can trigger an escalation flow (e.g.
|
|
19220
|
+
* `TinyCloudWeb.requestPermissions`). Passing `forceWalletSign: true`
|
|
19221
|
+
* bypasses the derivability check and always uses the wallet-signed SIWE
|
|
19222
|
+
* path — used by the legacy `createDelegation` fallback and by callers
|
|
19223
|
+
* that want explicit wallet confirmation.
|
|
19224
|
+
*
|
|
19225
|
+
* Current limitation: exactly one {@link PermissionEntry} per call. For
|
|
19226
|
+
* multi-resource delegation, call `delegateTo` multiple times. This keeps
|
|
19227
|
+
* each delegation a single `(spaceId, path)` grant, which matches the
|
|
19228
|
+
* underlying `PortableDelegation` shape.
|
|
19229
|
+
*
|
|
19230
|
+
* @throws {@link SessionExpiredError} when there is no session or the
|
|
19231
|
+
* current session has expired (or will within the 60s safety margin).
|
|
19232
|
+
* @throws {@link PermissionNotInManifestError} when the requested entries
|
|
19233
|
+
* are not a subset of the granted session capabilities and
|
|
19234
|
+
* `forceWalletSign` is not set.
|
|
19235
|
+
*/
|
|
19236
|
+
async delegateTo(did, permissions, options) {
|
|
19237
|
+
const session = this.auth?.tinyCloudSession;
|
|
19238
|
+
if (!session) {
|
|
19239
|
+
throw new SessionExpiredError(/* @__PURE__ */ new Date(0));
|
|
19240
|
+
}
|
|
19241
|
+
const sessionExpiry = extractSiweExpiration(session.siwe);
|
|
19242
|
+
if (sessionExpiry !== void 0) {
|
|
19243
|
+
const now2 = Date.now();
|
|
19244
|
+
const marginMs = _TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS;
|
|
19245
|
+
if (sessionExpiry.getTime() <= now2 + marginMs) {
|
|
19246
|
+
throw new SessionExpiredError(sessionExpiry);
|
|
19247
|
+
}
|
|
19248
|
+
}
|
|
19249
|
+
if (!Array.isArray(permissions) || permissions.length === 0) {
|
|
19250
|
+
throw new Error(
|
|
19251
|
+
"delegateTo requires a non-empty permissions array"
|
|
19252
|
+
);
|
|
19253
|
+
}
|
|
19254
|
+
if (permissions.length > 1) {
|
|
19255
|
+
throw new Error(
|
|
19256
|
+
"delegateTo currently supports one permission entry per call. Call delegateTo multiple times for multi-resource delegation."
|
|
19257
|
+
);
|
|
19258
|
+
}
|
|
19259
|
+
const entry = permissions[0];
|
|
19260
|
+
const expandedEntry = {
|
|
19261
|
+
...entry,
|
|
19262
|
+
actions: expandActionShortNames(entry.service, entry.actions)
|
|
19263
|
+
};
|
|
19264
|
+
const now = /* @__PURE__ */ new Date();
|
|
19265
|
+
const expiryMs = resolveExpiryMs(options?.expiry);
|
|
19266
|
+
const expirationTime = new Date(now.getTime() + expiryMs);
|
|
19267
|
+
let effectiveExpiration = expirationTime;
|
|
19268
|
+
if (sessionExpiry !== void 0 && sessionExpiry < expirationTime) {
|
|
19269
|
+
effectiveExpiration = sessionExpiry;
|
|
19270
|
+
}
|
|
19271
|
+
if (options?.forceWalletSign) {
|
|
19272
|
+
const delegation2 = await this.createDelegationLegacyWalletPath(
|
|
19273
|
+
did,
|
|
19274
|
+
expandedEntry,
|
|
19275
|
+
effectiveExpiration
|
|
19276
|
+
);
|
|
19277
|
+
return { delegation: delegation2, prompted: true };
|
|
19278
|
+
}
|
|
19279
|
+
const granted = parseRecapCapabilities(
|
|
19280
|
+
(siwe) => this.wasmBindings.parseRecapFromSiwe(siwe),
|
|
19281
|
+
session.siwe
|
|
19282
|
+
);
|
|
19283
|
+
const requested = [expandedEntry];
|
|
19284
|
+
const { subset, missing } = isCapabilitySubset(requested, granted);
|
|
19285
|
+
if (!subset) {
|
|
19286
|
+
throw new PermissionNotInManifestError(missing, granted);
|
|
19287
|
+
}
|
|
19288
|
+
const delegation = await this.createDelegationViaWasmPath(
|
|
19289
|
+
did,
|
|
19290
|
+
expandedEntry,
|
|
19291
|
+
effectiveExpiration,
|
|
19292
|
+
session
|
|
19293
|
+
);
|
|
19294
|
+
return { delegation, prompted: false };
|
|
19295
|
+
}
|
|
19296
|
+
/**
|
|
19297
|
+
* Issue a delegation via the session-key UCAN WASM path.
|
|
19298
|
+
*
|
|
19299
|
+
* The caller has already verified the request is derivable from the
|
|
19300
|
+
* current session; we just need to shape the inputs for
|
|
19301
|
+
* {@link createDelegationWrapper}.
|
|
19302
|
+
*
|
|
19303
|
+
* @internal
|
|
19304
|
+
*/
|
|
19305
|
+
async createDelegationViaWasmPath(did, entry, expirationTime, session) {
|
|
19306
|
+
const spaceId = entry.space === "default" ? session.spaceId : entry.space;
|
|
19307
|
+
const serviceSession = {
|
|
19308
|
+
delegationHeader: session.delegationHeader,
|
|
19309
|
+
delegationCid: session.delegationCid,
|
|
19310
|
+
jwk: session.jwk,
|
|
19311
|
+
spaceId,
|
|
19312
|
+
verificationMethod: session.verificationMethod
|
|
19313
|
+
};
|
|
19314
|
+
const expirationSecs = Math.floor(expirationTime.getTime() / 1e3);
|
|
19315
|
+
const result = this.createDelegationWrapper({
|
|
19316
|
+
session: serviceSession,
|
|
19317
|
+
delegateDID: did,
|
|
19318
|
+
spaceId,
|
|
19319
|
+
path: entry.path,
|
|
19320
|
+
actions: entry.actions,
|
|
19321
|
+
expirationSecs
|
|
19322
|
+
});
|
|
19323
|
+
return {
|
|
19324
|
+
cid: result.cid,
|
|
19325
|
+
delegationHeader: { Authorization: `Bearer ${result.delegation}` },
|
|
19326
|
+
spaceId,
|
|
19327
|
+
path: entry.path,
|
|
19328
|
+
actions: entry.actions,
|
|
19329
|
+
disableSubDelegation: false,
|
|
19330
|
+
expiry: result.expiry,
|
|
19331
|
+
delegateDID: did,
|
|
19332
|
+
ownerAddress: session.address,
|
|
19333
|
+
chainId: session.chainId,
|
|
19334
|
+
host: this.config.host
|
|
19335
|
+
};
|
|
19336
|
+
}
|
|
19337
|
+
/**
|
|
19338
|
+
* Issue a delegation via the legacy wallet-signed SIWE path for a single
|
|
19339
|
+
* {@link PermissionEntry}. Shares the implementation with the public
|
|
19340
|
+
* `createDelegation` method via {@link createDelegationWalletPath} so
|
|
19341
|
+
* both entry points hit exactly the same SIWE / signer / public-space
|
|
19342
|
+
* logic without mutual recursion.
|
|
19343
|
+
*
|
|
19344
|
+
* @internal
|
|
19345
|
+
*/
|
|
19346
|
+
async createDelegationLegacyWalletPath(delegateDID, entry, expirationTime) {
|
|
19347
|
+
const spaceIdOverride = entry.space === "default" ? void 0 : entry.space;
|
|
19348
|
+
return this.createDelegationWalletPath({
|
|
19349
|
+
path: entry.path,
|
|
19350
|
+
actions: entry.actions,
|
|
19351
|
+
delegateDID,
|
|
19352
|
+
includePublicSpace: true,
|
|
19353
|
+
expiryMs: Math.max(0, expirationTime.getTime() - Date.now()),
|
|
19354
|
+
spaceIdOverride
|
|
19355
|
+
});
|
|
19356
|
+
}
|
|
19143
19357
|
/**
|
|
19144
19358
|
* Create a delegation from this user to another user.
|
|
19145
19359
|
*
|
|
@@ -19150,6 +19364,51 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
19150
19364
|
* @returns A portable delegation that can be sent to the recipient
|
|
19151
19365
|
*/
|
|
19152
19366
|
async createDelegation(params) {
|
|
19367
|
+
if (!this.signer) {
|
|
19368
|
+
throw new Error("Cannot createDelegation() in session-only mode. Requires wallet mode.");
|
|
19369
|
+
}
|
|
19370
|
+
if (!this.auth?.tinyCloudSession) {
|
|
19371
|
+
throw new Error("Not signed in. Call signIn() first.");
|
|
19372
|
+
}
|
|
19373
|
+
let resolvedDelegateDID = params.delegateDID;
|
|
19374
|
+
if (resolvedDelegateDID.endsWith(".eth") && this.config.ensResolver) {
|
|
19375
|
+
const address = await this.config.ensResolver.resolveAddress(resolvedDelegateDID);
|
|
19376
|
+
if (!address) throw new Error(`Could not resolve ENS name: ${resolvedDelegateDID}`);
|
|
19377
|
+
resolvedDelegateDID = `did:pkh:eip155:1:${address}`;
|
|
19378
|
+
}
|
|
19379
|
+
const entries = legacyParamsToPermissionEntries(
|
|
19380
|
+
params.actions,
|
|
19381
|
+
params.path,
|
|
19382
|
+
params.spaceIdOverride
|
|
19383
|
+
);
|
|
19384
|
+
if (entries.length === 1) {
|
|
19385
|
+
try {
|
|
19386
|
+
const result = await this.delegateTo(
|
|
19387
|
+
resolvedDelegateDID,
|
|
19388
|
+
[entries[0]],
|
|
19389
|
+
params.expiryMs !== void 0 ? { expiry: params.expiryMs } : void 0
|
|
19390
|
+
);
|
|
19391
|
+
return result.delegation;
|
|
19392
|
+
} catch (err) {
|
|
19393
|
+
if (err instanceof PermissionNotInManifestError) {
|
|
19394
|
+
} else {
|
|
19395
|
+
throw err;
|
|
19396
|
+
}
|
|
19397
|
+
}
|
|
19398
|
+
}
|
|
19399
|
+
return this.createDelegationWalletPath({
|
|
19400
|
+
...params,
|
|
19401
|
+
delegateDID: resolvedDelegateDID
|
|
19402
|
+
});
|
|
19403
|
+
}
|
|
19404
|
+
/**
|
|
19405
|
+
* Legacy wallet-signed SIWE delegation path. Lifted from the original
|
|
19406
|
+
* `createDelegation` body verbatim so both the legacy public method and
|
|
19407
|
+
* `delegateTo({ forceWalletSign: true })` hit the same code.
|
|
19408
|
+
*
|
|
19409
|
+
* @internal
|
|
19410
|
+
*/
|
|
19411
|
+
async createDelegationWalletPath(params) {
|
|
19153
19412
|
if (!this.signer) {
|
|
19154
19413
|
throw new Error("Cannot createDelegation() in session-only mode. Requires wallet mode.");
|
|
19155
19414
|
}
|
|
@@ -19157,11 +19416,6 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
19157
19416
|
if (!session) {
|
|
19158
19417
|
throw new Error("Not signed in. Call signIn() first.");
|
|
19159
19418
|
}
|
|
19160
|
-
if (params.delegateDID.endsWith(".eth") && this.config.ensResolver) {
|
|
19161
|
-
const address = await this.config.ensResolver.resolveAddress(params.delegateDID);
|
|
19162
|
-
if (!address) throw new Error(`Could not resolve ENS name: ${params.delegateDID}`);
|
|
19163
|
-
params = { ...params, delegateDID: `did:pkh:eip155:1:${address}` };
|
|
19164
|
-
}
|
|
19165
19419
|
const abilities = {};
|
|
19166
19420
|
const kvActions = params.actions.filter((a) => a.startsWith("tinycloud.kv/"));
|
|
19167
19421
|
const sqlActions = params.actions.filter((a) => a.startsWith("tinycloud.sql/"));
|
|
@@ -19449,6 +19703,18 @@ var TinyCloudNode = class _TinyCloudNode {
|
|
|
19449
19703
|
};
|
|
19450
19704
|
}
|
|
19451
19705
|
};
|
|
19706
|
+
// ===========================================================================
|
|
19707
|
+
// Capability-chain delegation (spec: .claude/specs/capability-chain.md)
|
|
19708
|
+
// ===========================================================================
|
|
19709
|
+
/**
|
|
19710
|
+
* Safety margin before the session's own expiry at which {@link delegateTo}
|
|
19711
|
+
* will refuse to issue a derived delegation. Prevents issuing sub-delegations
|
|
19712
|
+
* that would be invalid by the time the recipient used them. Spec: 60 seconds.
|
|
19713
|
+
*
|
|
19714
|
+
* @internal
|
|
19715
|
+
*/
|
|
19716
|
+
_TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS = 6e4;
|
|
19717
|
+
var TinyCloudNode = _TinyCloudNode;
|
|
19452
19718
|
|
|
19453
19719
|
// src/nodeDefaults.ts
|
|
19454
19720
|
TinyCloudNode.registerNodeDefaults({
|
|
@@ -19584,6 +19850,19 @@ var FileSessionStorage = class {
|
|
|
19584
19850
|
}
|
|
19585
19851
|
};
|
|
19586
19852
|
|
|
19853
|
+
// src/index.ts
|
|
19854
|
+
import {
|
|
19855
|
+
PermissionNotInManifestError as PermissionNotInManifestError2,
|
|
19856
|
+
SessionExpiredError as SessionExpiredError2,
|
|
19857
|
+
ManifestValidationError,
|
|
19858
|
+
resolveManifest,
|
|
19859
|
+
validateManifest,
|
|
19860
|
+
loadManifest,
|
|
19861
|
+
isCapabilitySubset as isCapabilitySubset2,
|
|
19862
|
+
expandActionShortNames as expandActionShortNames2,
|
|
19863
|
+
parseExpiry as parseExpiry2
|
|
19864
|
+
} from "@tinycloud/sdk-core";
|
|
19865
|
+
|
|
19587
19866
|
// src/delegation.ts
|
|
19588
19867
|
function serializeDelegation(delegation) {
|
|
19589
19868
|
return JSON.stringify({
|
|
@@ -19657,15 +19936,18 @@ export {
|
|
|
19657
19936
|
FileSessionStorage,
|
|
19658
19937
|
HooksService3 as HooksService,
|
|
19659
19938
|
KVService3 as KVService,
|
|
19939
|
+
ManifestValidationError,
|
|
19660
19940
|
MemorySessionStorage,
|
|
19661
19941
|
NodeUserAuthorization,
|
|
19662
19942
|
NodeWasmBindings,
|
|
19943
|
+
PermissionNotInManifestError2 as PermissionNotInManifestError,
|
|
19663
19944
|
PrefixedKVService,
|
|
19664
19945
|
PrivateKeySigner,
|
|
19665
19946
|
ProtocolMismatchError,
|
|
19666
19947
|
SQLAction,
|
|
19667
19948
|
SQLService3 as SQLService,
|
|
19668
19949
|
ServiceContext3 as ServiceContext,
|
|
19950
|
+
SessionExpiredError2 as SessionExpiredError,
|
|
19669
19951
|
SharingService2 as SharingService,
|
|
19670
19952
|
SilentNotificationHandler2 as SilentNotificationHandler,
|
|
19671
19953
|
Space,
|
|
@@ -19688,9 +19970,15 @@ export {
|
|
|
19688
19970
|
defaultSignStrategy,
|
|
19689
19971
|
defaultSpaceCreationHandler,
|
|
19690
19972
|
deserializeDelegation,
|
|
19973
|
+
expandActionShortNames2 as expandActionShortNames,
|
|
19974
|
+
isCapabilitySubset2 as isCapabilitySubset,
|
|
19975
|
+
loadManifest,
|
|
19691
19976
|
makePublicSpaceId2 as makePublicSpaceId,
|
|
19977
|
+
parseExpiry2 as parseExpiry,
|
|
19692
19978
|
parseSpaceUri,
|
|
19693
|
-
|
|
19979
|
+
resolveManifest,
|
|
19980
|
+
serializeDelegation,
|
|
19981
|
+
validateManifest
|
|
19694
19982
|
};
|
|
19695
19983
|
/*! Bundled license information:
|
|
19696
19984
|
|