@tinycloud/sdk-core 2.0.1 → 2.0.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +3816 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3867 -0
- package/dist/index.d.ts +3861 -21
- package/dist/index.js +3767 -61
- package/dist/index.js.map +1 -1
- package/package.json +6 -5
- package/dist/TinyCloud.d.ts +0 -271
- package/dist/TinyCloud.d.ts.map +0 -1
- package/dist/TinyCloud.js +0 -458
- package/dist/TinyCloud.js.map +0 -1
- package/dist/TinyCloud.schema.d.ts +0 -173
- package/dist/TinyCloud.schema.d.ts.map +0 -1
- package/dist/TinyCloud.schema.js +0 -136
- package/dist/TinyCloud.schema.js.map +0 -1
- package/dist/TinyCloud.schema.test.d.ts +0 -5
- package/dist/TinyCloud.schema.test.d.ts.map +0 -1
- package/dist/TinyCloud.schema.test.js +0 -286
- package/dist/TinyCloud.schema.test.js.map +0 -1
- package/dist/authorization/CapabilityKeyRegistry.d.ts +0 -317
- package/dist/authorization/CapabilityKeyRegistry.d.ts.map +0 -1
- package/dist/authorization/CapabilityKeyRegistry.js +0 -509
- package/dist/authorization/CapabilityKeyRegistry.js.map +0 -1
- package/dist/authorization/authorization.schema.d.ts +0 -233
- package/dist/authorization/authorization.schema.d.ts.map +0 -1
- package/dist/authorization/authorization.schema.js +0 -220
- package/dist/authorization/authorization.schema.js.map +0 -1
- package/dist/authorization/authorization.schema.test.d.ts +0 -5
- package/dist/authorization/authorization.schema.test.d.ts.map +0 -1
- package/dist/authorization/authorization.schema.test.js +0 -618
- package/dist/authorization/authorization.schema.test.js.map +0 -1
- package/dist/authorization/index.d.ts +0 -38
- package/dist/authorization/index.d.ts.map +0 -1
- package/dist/authorization/index.js +0 -52
- package/dist/authorization/index.js.map +0 -1
- package/dist/authorization/spaceCreation.d.ts +0 -96
- package/dist/authorization/spaceCreation.d.ts.map +0 -1
- package/dist/authorization/spaceCreation.js +0 -35
- package/dist/authorization/spaceCreation.js.map +0 -1
- package/dist/authorization/spaceCreation.schema.d.ts +0 -67
- package/dist/authorization/spaceCreation.schema.d.ts.map +0 -1
- package/dist/authorization/spaceCreation.schema.js +0 -95
- package/dist/authorization/spaceCreation.schema.js.map +0 -1
- package/dist/authorization/spaceCreation.schema.test.d.ts +0 -5
- package/dist/authorization/spaceCreation.schema.test.d.ts.map +0 -1
- package/dist/authorization/spaceCreation.schema.test.js +0 -168
- package/dist/authorization/spaceCreation.schema.test.js.map +0 -1
- package/dist/authorization/strategies.d.ts +0 -134
- package/dist/authorization/strategies.d.ts.map +0 -1
- package/dist/authorization/strategies.js +0 -15
- package/dist/authorization/strategies.js.map +0 -1
- package/dist/authorization/strategies.schema.d.ts +0 -185
- package/dist/authorization/strategies.schema.d.ts.map +0 -1
- package/dist/authorization/strategies.schema.js +0 -147
- package/dist/authorization/strategies.schema.js.map +0 -1
- package/dist/authorization/strategies.schema.test.d.ts +0 -5
- package/dist/authorization/strategies.schema.test.d.ts.map +0 -1
- package/dist/authorization/strategies.schema.test.js +0 -253
- package/dist/authorization/strategies.schema.test.js.map +0 -1
- package/dist/client-types.d.ts +0 -128
- package/dist/client-types.d.ts.map +0 -1
- package/dist/client-types.js +0 -40
- package/dist/client-types.js.map +0 -1
- package/dist/delegations/DelegationManager.d.ts +0 -164
- package/dist/delegations/DelegationManager.d.ts.map +0 -1
- package/dist/delegations/DelegationManager.js +0 -428
- package/dist/delegations/DelegationManager.js.map +0 -1
- package/dist/delegations/SharingService.d.ts +0 -341
- package/dist/delegations/SharingService.d.ts.map +0 -1
- package/dist/delegations/SharingService.js +0 -722
- package/dist/delegations/SharingService.js.map +0 -1
- package/dist/delegations/SharingService.schema.d.ts +0 -409
- package/dist/delegations/SharingService.schema.d.ts.map +0 -1
- package/dist/delegations/SharingService.schema.js +0 -222
- package/dist/delegations/SharingService.schema.js.map +0 -1
- package/dist/delegations/index.d.ts +0 -38
- package/dist/delegations/index.d.ts.map +0 -1
- package/dist/delegations/index.js +0 -42
- package/dist/delegations/index.js.map +0 -1
- package/dist/delegations/types.d.ts +0 -13
- package/dist/delegations/types.d.ts.map +0 -1
- package/dist/delegations/types.js +0 -42
- package/dist/delegations/types.js.map +0 -1
- package/dist/delegations/types.schema.d.ts +0 -1773
- package/dist/delegations/types.schema.d.ts.map +0 -1
- package/dist/delegations/types.schema.js +0 -535
- package/dist/delegations/types.schema.js.map +0 -1
- package/dist/delegations/types.schema.test.d.ts +0 -5
- package/dist/delegations/types.schema.test.d.ts.map +0 -1
- package/dist/delegations/types.schema.test.js +0 -627
- package/dist/delegations/types.schema.test.js.map +0 -1
- package/dist/ens.d.ts +0 -17
- package/dist/ens.d.ts.map +0 -1
- package/dist/ens.js +0 -10
- package/dist/ens.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/json-schema.d.ts +0 -327
- package/dist/json-schema.d.ts.map +0 -1
- package/dist/json-schema.js +0 -703
- package/dist/json-schema.js.map +0 -1
- package/dist/json-schema.test.d.ts +0 -7
- package/dist/json-schema.test.d.ts.map +0 -1
- package/dist/json-schema.test.js +0 -365
- package/dist/json-schema.test.js.map +0 -1
- package/dist/notifications.d.ts +0 -33
- package/dist/notifications.d.ts.map +0 -1
- package/dist/notifications.js +0 -15
- package/dist/notifications.js.map +0 -1
- package/dist/signer.d.ts +0 -28
- package/dist/signer.d.ts.map +0 -1
- package/dist/signer.js +0 -2
- package/dist/signer.js.map +0 -1
- package/dist/space.d.ts +0 -57
- package/dist/space.d.ts.map +0 -1
- package/dist/space.js +0 -87
- package/dist/space.js.map +0 -1
- package/dist/space.schema.d.ts +0 -65
- package/dist/space.schema.d.ts.map +0 -1
- package/dist/space.schema.js +0 -65
- package/dist/space.schema.js.map +0 -1
- package/dist/space.schema.test.d.ts +0 -5
- package/dist/space.schema.test.d.ts.map +0 -1
- package/dist/space.schema.test.js +0 -148
- package/dist/space.schema.test.js.map +0 -1
- package/dist/space.test.d.ts +0 -5
- package/dist/space.test.d.ts.map +0 -1
- package/dist/space.test.js +0 -87
- package/dist/space.test.js.map +0 -1
- package/dist/spaces/Space.d.ts +0 -175
- package/dist/spaces/Space.d.ts.map +0 -1
- package/dist/spaces/Space.js +0 -84
- package/dist/spaces/Space.js.map +0 -1
- package/dist/spaces/SpaceService.d.ts +0 -291
- package/dist/spaces/SpaceService.d.ts.map +0 -1
- package/dist/spaces/SpaceService.js +0 -740
- package/dist/spaces/SpaceService.js.map +0 -1
- package/dist/spaces/index.d.ts +0 -11
- package/dist/spaces/index.d.ts.map +0 -1
- package/dist/spaces/index.js +0 -22
- package/dist/spaces/index.js.map +0 -1
- package/dist/spaces/spaces.schema.d.ts +0 -421
- package/dist/spaces/spaces.schema.d.ts.map +0 -1
- package/dist/spaces/spaces.schema.js +0 -342
- package/dist/spaces/spaces.schema.js.map +0 -1
- package/dist/spaces/spaces.schema.test.d.ts +0 -5
- package/dist/spaces/spaces.schema.test.d.ts.map +0 -1
- package/dist/spaces/spaces.schema.test.js +0 -471
- package/dist/spaces/spaces.schema.test.js.map +0 -1
- package/dist/storage.d.ts +0 -47
- package/dist/storage.d.ts.map +0 -1
- package/dist/storage.js +0 -14
- package/dist/storage.js.map +0 -1
- package/dist/storage.schema.d.ts +0 -291
- package/dist/storage.schema.d.ts.map +0 -1
- package/dist/storage.schema.js +0 -189
- package/dist/storage.schema.js.map +0 -1
- package/dist/storage.schema.test.d.ts +0 -5
- package/dist/storage.schema.test.d.ts.map +0 -1
- package/dist/storage.schema.test.js +0 -346
- package/dist/storage.schema.test.js.map +0 -1
- package/dist/userAuthorization.d.ts +0 -117
- package/dist/userAuthorization.d.ts.map +0 -1
- package/dist/userAuthorization.js +0 -3
- package/dist/userAuthorization.js.map +0 -1
- package/dist/userAuthorization.schema.d.ts +0 -260
- package/dist/userAuthorization.schema.d.ts.map +0 -1
- package/dist/userAuthorization.schema.js +0 -169
- package/dist/userAuthorization.schema.js.map +0 -1
- package/dist/userAuthorization.schema.test.d.ts +0 -5
- package/dist/userAuthorization.schema.test.d.ts.map +0 -1
- package/dist/userAuthorization.schema.test.js +0 -356
- package/dist/userAuthorization.schema.test.js.map +0 -1
- package/dist/version.d.ts +0 -32
- package/dist/version.d.ts.map +0 -1
- package/dist/version.js +0 -59
- package/dist/version.js.map +0 -1
- package/dist/wasm-validation.d.ts +0 -291
- package/dist/wasm-validation.d.ts.map +0 -1
- package/dist/wasm-validation.js +0 -221
- package/dist/wasm-validation.js.map +0 -1
- package/dist/wasm-validation.test.d.ts +0 -5
- package/dist/wasm-validation.test.d.ts.map +0 -1
- package/dist/wasm-validation.test.js +0 -233
- package/dist/wasm-validation.test.js.map +0 -1
- package/dist/wasm.d.ts +0 -66
- package/dist/wasm.d.ts.map +0 -1
- package/dist/wasm.js +0 -10
- package/dist/wasm.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,27 +1,3867 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { InvokeFunction, ServiceError, Result as Result$1, ServiceSession, FetchFunction, ServiceConstructor, RetryPolicy, IServiceContext, IService, IKVService, ISQLService, IDuckDbService, IDataVaultService } from '@tinycloud/sdk-services';
|
|
3
|
+
export { BatchOptions, BatchResponse, ColumnInfo, DataVaultConfig, DataVaultService, DatabaseHandle, DuckDbAction, DuckDbActionType, DuckDbBatchOptions, DuckDbBatchResponse, DuckDbDatabaseHandle, DuckDbExecuteOptions, DuckDbExecuteResponse, DuckDbOptions, DuckDbQueryOptions, DuckDbQueryResponse, DuckDbService, DuckDbServiceConfig, DuckDbStatement, DuckDbValue, ErrorCode, ErrorCodes, ExecuteOptions, ExecuteResponse, FetchFunction, IDataVaultService, IDatabaseHandle, IDuckDbDatabaseHandle, IDuckDbService, IKVService, IPrefixedKVService, ISQLService, IService, IServiceContext, InvokeFunction, KVDeleteOptions, KVGetOptions, KVHeadOptions, KVListOptions, KVListResponse, KVPutOptions, KVResponse, KVResponseHeaders, KVService, KVServiceConfig, PrefixedKVService, QueryOptions, QueryResponse, Result, RetryPolicy, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, ServiceContext, ServiceContextConfig, ServiceError, ServiceSession, SqlStatement, SqlValue, TableInfo, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultPublicSpaceKVActions, VaultPutOptions, ViewInfo, WasmVaultFunctions, createVaultCrypto, defaultRetryPolicy, err, ok, serviceError } from '@tinycloud/sdk-services';
|
|
4
|
+
export { SiweMessage } from 'siwe';
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
|
-
*
|
|
7
|
+
* Platform-agnostic client types for TinyCloud SDK.
|
|
3
8
|
*
|
|
4
|
-
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** ENS data associated with a user session. */
|
|
13
|
+
interface EnsData {
|
|
14
|
+
domain?: string | null;
|
|
15
|
+
avatarUrl?: string | null;
|
|
16
|
+
}
|
|
17
|
+
declare const EnsDataSchema: z.ZodObject<{
|
|
18
|
+
domain: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
19
|
+
avatarUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
20
|
+
}, "strip", z.ZodTypeAny, {
|
|
21
|
+
domain?: string | null | undefined;
|
|
22
|
+
avatarUrl?: string | null | undefined;
|
|
23
|
+
}, {
|
|
24
|
+
domain?: string | null | undefined;
|
|
25
|
+
avatarUrl?: string | null | undefined;
|
|
26
|
+
}>;
|
|
27
|
+
/** SIWE configuration. All fields optional — callers provide only what they need to override. */
|
|
28
|
+
interface SiweConfig {
|
|
29
|
+
domain?: string;
|
|
30
|
+
uri?: string;
|
|
31
|
+
chainId?: number;
|
|
32
|
+
statement?: string;
|
|
33
|
+
nonce?: string;
|
|
34
|
+
expirationTime?: string;
|
|
35
|
+
notBefore?: string;
|
|
36
|
+
requestId?: string;
|
|
37
|
+
resources?: string[];
|
|
38
|
+
}
|
|
39
|
+
declare const SiweConfigSchema: z.ZodObject<{
|
|
40
|
+
domain: z.ZodOptional<z.ZodString>;
|
|
41
|
+
uri: z.ZodOptional<z.ZodString>;
|
|
42
|
+
chainId: z.ZodOptional<z.ZodNumber>;
|
|
43
|
+
statement: z.ZodOptional<z.ZodString>;
|
|
44
|
+
nonce: z.ZodOptional<z.ZodString>;
|
|
45
|
+
expirationTime: z.ZodOptional<z.ZodString>;
|
|
46
|
+
notBefore: z.ZodOptional<z.ZodString>;
|
|
47
|
+
requestId: z.ZodOptional<z.ZodString>;
|
|
48
|
+
resources: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
49
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
50
|
+
domain: z.ZodOptional<z.ZodString>;
|
|
51
|
+
uri: z.ZodOptional<z.ZodString>;
|
|
52
|
+
chainId: z.ZodOptional<z.ZodNumber>;
|
|
53
|
+
statement: z.ZodOptional<z.ZodString>;
|
|
54
|
+
nonce: z.ZodOptional<z.ZodString>;
|
|
55
|
+
expirationTime: z.ZodOptional<z.ZodString>;
|
|
56
|
+
notBefore: z.ZodOptional<z.ZodString>;
|
|
57
|
+
requestId: z.ZodOptional<z.ZodString>;
|
|
58
|
+
resources: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
59
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
60
|
+
domain: z.ZodOptional<z.ZodString>;
|
|
61
|
+
uri: z.ZodOptional<z.ZodString>;
|
|
62
|
+
chainId: z.ZodOptional<z.ZodNumber>;
|
|
63
|
+
statement: z.ZodOptional<z.ZodString>;
|
|
64
|
+
nonce: z.ZodOptional<z.ZodString>;
|
|
65
|
+
expirationTime: z.ZodOptional<z.ZodString>;
|
|
66
|
+
notBefore: z.ZodOptional<z.ZodString>;
|
|
67
|
+
requestId: z.ZodOptional<z.ZodString>;
|
|
68
|
+
resources: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
69
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
70
|
+
/** Representation of an active client session. */
|
|
71
|
+
interface ClientSession {
|
|
72
|
+
/** User address (may be delegated) */
|
|
73
|
+
address: string;
|
|
74
|
+
/** User address without delegation */
|
|
75
|
+
walletAddress: string;
|
|
76
|
+
/** EIP-155 chain ID */
|
|
77
|
+
chainId: number;
|
|
78
|
+
/** Key to identify the session */
|
|
79
|
+
sessionKey: string;
|
|
80
|
+
/** The SIWE message text (from SiweMessage.prepareMessage()) */
|
|
81
|
+
siwe: string;
|
|
82
|
+
/** The signature of the SIWE message */
|
|
83
|
+
signature: string;
|
|
84
|
+
/** ENS data supported by TinyCloud */
|
|
85
|
+
ens?: EnsData;
|
|
86
|
+
}
|
|
87
|
+
declare const ClientSessionSchema: z.ZodObject<{
|
|
88
|
+
address: z.ZodString;
|
|
89
|
+
walletAddress: z.ZodString;
|
|
90
|
+
chainId: z.ZodNumber;
|
|
91
|
+
sessionKey: z.ZodString;
|
|
92
|
+
siwe: z.ZodString;
|
|
93
|
+
signature: z.ZodString;
|
|
94
|
+
ens: z.ZodOptional<z.ZodObject<{
|
|
95
|
+
domain: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
96
|
+
avatarUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
97
|
+
}, "strip", z.ZodTypeAny, {
|
|
98
|
+
domain?: string | null | undefined;
|
|
99
|
+
avatarUrl?: string | null | undefined;
|
|
100
|
+
}, {
|
|
101
|
+
domain?: string | null | undefined;
|
|
102
|
+
avatarUrl?: string | null | undefined;
|
|
103
|
+
}>>;
|
|
104
|
+
}, "strip", z.ZodTypeAny, {
|
|
105
|
+
chainId: number;
|
|
106
|
+
address: string;
|
|
107
|
+
walletAddress: string;
|
|
108
|
+
sessionKey: string;
|
|
109
|
+
siwe: string;
|
|
110
|
+
signature: string;
|
|
111
|
+
ens?: {
|
|
112
|
+
domain?: string | null | undefined;
|
|
113
|
+
avatarUrl?: string | null | undefined;
|
|
114
|
+
} | undefined;
|
|
115
|
+
}, {
|
|
116
|
+
chainId: number;
|
|
117
|
+
address: string;
|
|
118
|
+
walletAddress: string;
|
|
119
|
+
sessionKey: string;
|
|
120
|
+
siwe: string;
|
|
121
|
+
signature: string;
|
|
122
|
+
ens?: {
|
|
123
|
+
domain?: string | null | undefined;
|
|
124
|
+
avatarUrl?: string | null | undefined;
|
|
125
|
+
} | undefined;
|
|
126
|
+
}>;
|
|
127
|
+
/** The URL of a server running tinycloud-node. */
|
|
128
|
+
type ServerHost = string;
|
|
129
|
+
/** Validate unknown data as a ClientSession. Returns the parsed session or null. */
|
|
130
|
+
declare function validateClientSession(data: unknown): ClientSession | null;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Notification handler interface for TinyCloud SDK.
|
|
134
|
+
*
|
|
135
|
+
* Abstracts UI notifications so that web-sdk can show toasts
|
|
136
|
+
* while node-sdk uses a silent no-op handler.
|
|
137
|
+
*
|
|
138
|
+
* @packageDocumentation
|
|
139
|
+
*/
|
|
140
|
+
/**
|
|
141
|
+
* Platform-agnostic notification handler.
|
|
142
|
+
*
|
|
143
|
+
* Implementations can provide different UX patterns:
|
|
144
|
+
* - Browser: toast notifications via antd or similar
|
|
145
|
+
* - Node.js: silent (default) or logging
|
|
146
|
+
* - CLI: console output
|
|
147
|
+
*/
|
|
148
|
+
interface INotificationHandler {
|
|
149
|
+
/** Called on successful operations (e.g., "Successfully signed in") */
|
|
150
|
+
success(message: string, description?: string): void;
|
|
151
|
+
/** Called on warnings */
|
|
152
|
+
warning(message: string, description?: string): void;
|
|
153
|
+
/** Called on errors */
|
|
154
|
+
error(category: string, message: string, description?: string): void;
|
|
155
|
+
/** Optional cleanup (e.g., dismiss all active notifications) */
|
|
156
|
+
cleanup?(): void;
|
|
157
|
+
}
|
|
158
|
+
/** No-op handler for environments without UI (node-sdk default). */
|
|
159
|
+
declare class SilentNotificationHandler implements INotificationHandler {
|
|
160
|
+
success(): void;
|
|
161
|
+
warning(): void;
|
|
162
|
+
error(): void;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Platform-agnostic ENS resolution interface.
|
|
167
|
+
*
|
|
168
|
+
* Browser implementations use ethers.js provider.
|
|
169
|
+
* Node implementations can use any Ethereum RPC.
|
|
170
|
+
*
|
|
171
|
+
* @packageDocumentation
|
|
172
|
+
*/
|
|
173
|
+
interface IENSResolver {
|
|
174
|
+
/** Resolve an ENS name to an Ethereum address */
|
|
175
|
+
resolveAddress(ensName: string): Promise<string | null>;
|
|
176
|
+
/** Reverse-resolve an address to an ENS name */
|
|
177
|
+
resolveName(address: string): Promise<string | null>;
|
|
178
|
+
/** Resolve an ENS name to an avatar URL */
|
|
179
|
+
resolveAvatar?(ensName: string): Promise<string | null>;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* WASM binding abstraction for TinyCloud SDK.
|
|
184
|
+
*
|
|
185
|
+
* Allows TinyCloudNode to accept either @tinycloud/node-sdk-wasm (Node.js)
|
|
186
|
+
* or @tinycloud/web-sdk-wasm (browser) without direct dependency on either.
|
|
187
|
+
*
|
|
188
|
+
* @packageDocumentation
|
|
189
|
+
*/
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Platform-agnostic WASM bindings interface.
|
|
193
|
+
*
|
|
194
|
+
* Each platform provides its own implementation:
|
|
195
|
+
* - node-sdk-wasm: Node.js WASM bindings
|
|
196
|
+
* - web-sdk-wasm: Browser WASM bindings
|
|
197
|
+
*/
|
|
198
|
+
interface IWasmBindings {
|
|
199
|
+
/** Invoke a TinyCloud action */
|
|
200
|
+
invoke: InvokeFunction;
|
|
201
|
+
/** Prepare a session (generate session key, build SIWE message) */
|
|
202
|
+
prepareSession: (params: any) => any;
|
|
203
|
+
/** Complete session setup (create delegation) */
|
|
204
|
+
completeSessionSetup: (params: any) => any;
|
|
205
|
+
/** Ensure an address is in EIP-55 checksummed format */
|
|
206
|
+
ensureEip55: (address: string) => string;
|
|
207
|
+
/** Generate a space ID from address, chain ID, and prefix */
|
|
208
|
+
makeSpaceId: (address: string, chainId: number, prefix: string) => string;
|
|
209
|
+
/** Create a delegation */
|
|
210
|
+
createDelegation: (...args: any[]) => any;
|
|
211
|
+
/** Generate a host SIWE message for space activation */
|
|
212
|
+
generateHostSIWEMessage: (params: any) => string;
|
|
213
|
+
/** Convert a signed SIWE message to delegation headers */
|
|
214
|
+
siweToDelegationHeaders: (params: any) => any;
|
|
215
|
+
/** Get the protocol version */
|
|
216
|
+
protocolVersion: () => number;
|
|
217
|
+
vault_encrypt: (key: Uint8Array, plaintext: Uint8Array) => Uint8Array;
|
|
218
|
+
vault_decrypt: (key: Uint8Array, blob: Uint8Array) => Uint8Array;
|
|
219
|
+
vault_derive_key: (salt: Uint8Array, signature: Uint8Array, info: Uint8Array) => Uint8Array;
|
|
220
|
+
vault_x25519_from_seed: (seed: Uint8Array) => {
|
|
221
|
+
publicKey: Uint8Array;
|
|
222
|
+
privateKey: Uint8Array;
|
|
223
|
+
};
|
|
224
|
+
vault_x25519_dh: (privateKey: Uint8Array, publicKey: Uint8Array) => Uint8Array;
|
|
225
|
+
vault_random_bytes: (length: number) => Uint8Array;
|
|
226
|
+
vault_sha256: (data: Uint8Array) => Uint8Array;
|
|
227
|
+
/** Factory for session managers */
|
|
228
|
+
createSessionManager: () => ISessionManager;
|
|
229
|
+
/** Ensure WASM module is initialized (optional — some bindings auto-init) */
|
|
230
|
+
ensureInitialized?: () => Promise<void>;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Session key manager backed by WASM.
|
|
234
|
+
*
|
|
235
|
+
* Manages Ed25519 session keys used for delegated authentication.
|
|
236
|
+
*/
|
|
237
|
+
interface ISessionManager {
|
|
238
|
+
/** Create a new session key with the given ID, returns the DID */
|
|
239
|
+
createSessionKey(id: string): string;
|
|
240
|
+
/** Rename a session key ID */
|
|
241
|
+
renameSessionKeyId(oldId: string, newId: string): void;
|
|
242
|
+
/** Get the DID for a session key */
|
|
243
|
+
getDID(keyId: string): string;
|
|
244
|
+
/** Get the JWK representation of a session key */
|
|
245
|
+
jwk(keyId: string): string | undefined;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Bytes representation as an array of integers.
|
|
250
|
+
*/
|
|
251
|
+
type Bytes = ArrayLike<number>;
|
|
252
|
+
/**
|
|
253
|
+
* Platform-agnostic signer interface.
|
|
254
|
+
*
|
|
255
|
+
* This interface defines the minimal signing capabilities required by TinyCloud.
|
|
256
|
+
* It can be implemented by browser wallets (via ethers.js Signer), private key
|
|
257
|
+
* signers in Node.js, or hardware wallets.
|
|
258
|
+
*/
|
|
259
|
+
interface ISigner {
|
|
260
|
+
/**
|
|
261
|
+
* Returns the account address.
|
|
262
|
+
*/
|
|
263
|
+
getAddress(): Promise<string>;
|
|
264
|
+
/**
|
|
265
|
+
* Returns the chain ID that this signer is connected to.
|
|
266
|
+
*/
|
|
267
|
+
getChainId(): Promise<number>;
|
|
268
|
+
/**
|
|
269
|
+
* Signs a message and returns the signature.
|
|
270
|
+
* @param message - The message to sign (string or bytes)
|
|
271
|
+
* @returns The signature as a hex string (format: "0x<65 bytes>")
|
|
272
|
+
*/
|
|
273
|
+
signMessage(message: Bytes | string): Promise<string>;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Zod schemas for session persistence types.
|
|
278
|
+
*
|
|
279
|
+
* This is the source of truth for session-related types. TypeScript types
|
|
280
|
+
* are derived from these schemas using z.infer<>.
|
|
281
|
+
*
|
|
282
|
+
* @packageDocumentation
|
|
283
|
+
*/
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Schema for TinyCloud-specific session data that's persisted.
|
|
287
|
+
*/
|
|
288
|
+
declare const PersistedTinyCloudSessionSchema: z.ZodObject<{
|
|
289
|
+
/** The delegation header containing the UCAN */
|
|
290
|
+
delegationHeader: z.ZodObject<{
|
|
291
|
+
Authorization: z.ZodString;
|
|
292
|
+
}, "strip", z.ZodTypeAny, {
|
|
293
|
+
Authorization: string;
|
|
294
|
+
}, {
|
|
295
|
+
Authorization: string;
|
|
296
|
+
}>;
|
|
297
|
+
/** The delegation CID */
|
|
298
|
+
delegationCid: z.ZodString;
|
|
299
|
+
/** The space ID for this session */
|
|
300
|
+
spaceId: z.ZodString;
|
|
301
|
+
/** Additional spaces included in this session's capabilities. Key is logical name, value is full spaceId URI */
|
|
302
|
+
spaces: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
303
|
+
/** The verification method DID */
|
|
304
|
+
verificationMethod: z.ZodString;
|
|
305
|
+
}, "strip", z.ZodTypeAny, {
|
|
306
|
+
delegationHeader: {
|
|
307
|
+
Authorization: string;
|
|
308
|
+
};
|
|
309
|
+
delegationCid: string;
|
|
310
|
+
spaceId: string;
|
|
311
|
+
verificationMethod: string;
|
|
312
|
+
spaces?: Record<string, string> | undefined;
|
|
313
|
+
}, {
|
|
314
|
+
delegationHeader: {
|
|
315
|
+
Authorization: string;
|
|
316
|
+
};
|
|
317
|
+
delegationCid: string;
|
|
318
|
+
spaceId: string;
|
|
319
|
+
verificationMethod: string;
|
|
320
|
+
spaces?: Record<string, string> | undefined;
|
|
321
|
+
}>;
|
|
322
|
+
type PersistedTinyCloudSession = z.infer<typeof PersistedTinyCloudSessionSchema>;
|
|
323
|
+
/**
|
|
324
|
+
* Schema for full persisted session data.
|
|
325
|
+
*
|
|
326
|
+
* Contains all data needed to restore a session without re-authentication.
|
|
327
|
+
*/
|
|
328
|
+
declare const PersistedSessionDataSchema: z.ZodObject<{
|
|
329
|
+
/** User's Ethereum address */
|
|
330
|
+
address: z.ZodString;
|
|
331
|
+
/** EIP-155 Chain ID */
|
|
332
|
+
chainId: z.ZodNumber;
|
|
333
|
+
/** Session key in JWK format (stringified) */
|
|
334
|
+
sessionKey: z.ZodString;
|
|
335
|
+
/** The signed SIWE message */
|
|
336
|
+
siwe: z.ZodString;
|
|
337
|
+
/** User's signature of the SIWE message */
|
|
338
|
+
signature: z.ZodString;
|
|
339
|
+
/** TinyCloud delegation data if available */
|
|
340
|
+
tinycloudSession: z.ZodOptional<z.ZodObject<{
|
|
341
|
+
/** The delegation header containing the UCAN */
|
|
342
|
+
delegationHeader: z.ZodObject<{
|
|
343
|
+
Authorization: z.ZodString;
|
|
344
|
+
}, "strip", z.ZodTypeAny, {
|
|
345
|
+
Authorization: string;
|
|
346
|
+
}, {
|
|
347
|
+
Authorization: string;
|
|
348
|
+
}>;
|
|
349
|
+
/** The delegation CID */
|
|
350
|
+
delegationCid: z.ZodString;
|
|
351
|
+
/** The space ID for this session */
|
|
352
|
+
spaceId: z.ZodString;
|
|
353
|
+
/** Additional spaces included in this session's capabilities. Key is logical name, value is full spaceId URI */
|
|
354
|
+
spaces: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
355
|
+
/** The verification method DID */
|
|
356
|
+
verificationMethod: z.ZodString;
|
|
357
|
+
}, "strip", z.ZodTypeAny, {
|
|
358
|
+
delegationHeader: {
|
|
359
|
+
Authorization: string;
|
|
360
|
+
};
|
|
361
|
+
delegationCid: string;
|
|
362
|
+
spaceId: string;
|
|
363
|
+
verificationMethod: string;
|
|
364
|
+
spaces?: Record<string, string> | undefined;
|
|
365
|
+
}, {
|
|
366
|
+
delegationHeader: {
|
|
367
|
+
Authorization: string;
|
|
368
|
+
};
|
|
369
|
+
delegationCid: string;
|
|
370
|
+
spaceId: string;
|
|
371
|
+
verificationMethod: string;
|
|
372
|
+
spaces?: Record<string, string> | undefined;
|
|
373
|
+
}>>;
|
|
374
|
+
/** Session expiration timestamp (ISO 8601 with timezone offset) */
|
|
375
|
+
expiresAt: z.ZodString;
|
|
376
|
+
/** Session creation timestamp (ISO 8601 with timezone offset) */
|
|
377
|
+
createdAt: z.ZodString;
|
|
378
|
+
/** Schema version for migrations */
|
|
379
|
+
version: z.ZodString;
|
|
380
|
+
/** Optional ENS data */
|
|
381
|
+
ens: z.ZodOptional<z.ZodObject<{
|
|
382
|
+
/** ENS name/domain. */
|
|
383
|
+
domain: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
384
|
+
/** ENS avatar URL. */
|
|
385
|
+
avatarUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
386
|
+
}, "strip", z.ZodTypeAny, {
|
|
387
|
+
domain?: string | null | undefined;
|
|
388
|
+
avatarUrl?: string | null | undefined;
|
|
389
|
+
}, {
|
|
390
|
+
domain?: string | null | undefined;
|
|
391
|
+
avatarUrl?: string | null | undefined;
|
|
392
|
+
}>>;
|
|
393
|
+
}, "strip", z.ZodTypeAny, {
|
|
394
|
+
chainId: number;
|
|
395
|
+
address: string;
|
|
396
|
+
sessionKey: string;
|
|
397
|
+
siwe: string;
|
|
398
|
+
signature: string;
|
|
399
|
+
expiresAt: string;
|
|
400
|
+
createdAt: string;
|
|
401
|
+
version: string;
|
|
402
|
+
ens?: {
|
|
403
|
+
domain?: string | null | undefined;
|
|
404
|
+
avatarUrl?: string | null | undefined;
|
|
405
|
+
} | undefined;
|
|
406
|
+
tinycloudSession?: {
|
|
407
|
+
delegationHeader: {
|
|
408
|
+
Authorization: string;
|
|
409
|
+
};
|
|
410
|
+
delegationCid: string;
|
|
411
|
+
spaceId: string;
|
|
412
|
+
verificationMethod: string;
|
|
413
|
+
spaces?: Record<string, string> | undefined;
|
|
414
|
+
} | undefined;
|
|
415
|
+
}, {
|
|
416
|
+
chainId: number;
|
|
417
|
+
address: string;
|
|
418
|
+
sessionKey: string;
|
|
419
|
+
siwe: string;
|
|
420
|
+
signature: string;
|
|
421
|
+
expiresAt: string;
|
|
422
|
+
createdAt: string;
|
|
423
|
+
version: string;
|
|
424
|
+
ens?: {
|
|
425
|
+
domain?: string | null | undefined;
|
|
426
|
+
avatarUrl?: string | null | undefined;
|
|
427
|
+
} | undefined;
|
|
428
|
+
tinycloudSession?: {
|
|
429
|
+
delegationHeader: {
|
|
430
|
+
Authorization: string;
|
|
431
|
+
};
|
|
432
|
+
delegationCid: string;
|
|
433
|
+
spaceId: string;
|
|
434
|
+
verificationMethod: string;
|
|
435
|
+
spaces?: Record<string, string> | undefined;
|
|
436
|
+
} | undefined;
|
|
437
|
+
}>;
|
|
438
|
+
type PersistedSessionData = z.infer<typeof PersistedSessionDataSchema>;
|
|
439
|
+
/**
|
|
440
|
+
* Schema for full TinyCloud session with delegation data.
|
|
441
|
+
*
|
|
442
|
+
* This is the runtime session type used for making invocations and delegations.
|
|
443
|
+
*/
|
|
444
|
+
declare const TinyCloudSessionSchema: z.ZodObject<{
|
|
445
|
+
/** User's Ethereum address */
|
|
446
|
+
address: z.ZodString;
|
|
447
|
+
/** EIP-155 Chain ID */
|
|
448
|
+
chainId: z.ZodNumber;
|
|
449
|
+
/** Session key ID */
|
|
450
|
+
sessionKey: z.ZodString;
|
|
451
|
+
/** The space ID for this session */
|
|
452
|
+
spaceId: z.ZodString;
|
|
453
|
+
/** Additional spaces included in this session's capabilities. Key is logical name, value is full spaceId URI */
|
|
454
|
+
spaces: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
455
|
+
/** The delegation CID */
|
|
456
|
+
delegationCid: z.ZodString;
|
|
457
|
+
/** The delegation header for API calls */
|
|
458
|
+
delegationHeader: z.ZodObject<{
|
|
459
|
+
Authorization: z.ZodString;
|
|
460
|
+
}, "strip", z.ZodTypeAny, {
|
|
461
|
+
Authorization: string;
|
|
462
|
+
}, {
|
|
463
|
+
Authorization: string;
|
|
464
|
+
}>;
|
|
465
|
+
/** The verification method DID */
|
|
466
|
+
verificationMethod: z.ZodString;
|
|
467
|
+
/** The session key JWK (required for invoke operations) */
|
|
468
|
+
jwk: z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>;
|
|
469
|
+
/** The signed SIWE message */
|
|
470
|
+
siwe: z.ZodString;
|
|
471
|
+
/** User's signature of the SIWE message */
|
|
472
|
+
signature: z.ZodString;
|
|
473
|
+
}, "strip", z.ZodTypeAny, {
|
|
474
|
+
chainId: number;
|
|
475
|
+
address: string;
|
|
476
|
+
sessionKey: string;
|
|
477
|
+
siwe: string;
|
|
478
|
+
signature: string;
|
|
479
|
+
delegationHeader: {
|
|
480
|
+
Authorization: string;
|
|
481
|
+
};
|
|
482
|
+
delegationCid: string;
|
|
483
|
+
spaceId: string;
|
|
484
|
+
verificationMethod: string;
|
|
485
|
+
jwk: {} & {
|
|
486
|
+
[k: string]: unknown;
|
|
487
|
+
};
|
|
488
|
+
spaces?: Record<string, string> | undefined;
|
|
489
|
+
}, {
|
|
490
|
+
chainId: number;
|
|
491
|
+
address: string;
|
|
492
|
+
sessionKey: string;
|
|
493
|
+
siwe: string;
|
|
494
|
+
signature: string;
|
|
495
|
+
delegationHeader: {
|
|
496
|
+
Authorization: string;
|
|
497
|
+
};
|
|
498
|
+
delegationCid: string;
|
|
499
|
+
spaceId: string;
|
|
500
|
+
verificationMethod: string;
|
|
501
|
+
jwk: {} & {
|
|
502
|
+
[k: string]: unknown;
|
|
503
|
+
};
|
|
504
|
+
spaces?: Record<string, string> | undefined;
|
|
505
|
+
}>;
|
|
506
|
+
type TinyCloudSession = z.infer<typeof TinyCloudSessionSchema>;
|
|
507
|
+
/**
|
|
508
|
+
* Validation error type for schema validation failures.
|
|
509
|
+
*/
|
|
510
|
+
interface ValidationError extends ServiceError {
|
|
511
|
+
code: "VALIDATION_ERROR";
|
|
512
|
+
meta?: {
|
|
513
|
+
issues: z.ZodIssue[];
|
|
514
|
+
path?: string;
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Validate persisted session data against the schema.
|
|
519
|
+
*
|
|
520
|
+
* @param data - Unknown data to validate
|
|
521
|
+
* @returns Result with validated data or validation error
|
|
522
|
+
*
|
|
523
|
+
* @example
|
|
524
|
+
* ```typescript
|
|
525
|
+
* const result = validatePersistedSessionData(JSON.parse(rawData));
|
|
526
|
+
* if (result.ok) {
|
|
527
|
+
* // result.data is typed as PersistedSessionData
|
|
528
|
+
* console.log(result.data.address);
|
|
529
|
+
* } else {
|
|
530
|
+
* console.error(result.error.message);
|
|
531
|
+
* }
|
|
532
|
+
* ```
|
|
533
|
+
*/
|
|
534
|
+
declare function validatePersistedSessionData(data: unknown): Result$1<PersistedSessionData, ValidationError>;
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Session storage types and interfaces.
|
|
538
|
+
*
|
|
539
|
+
* Types are derived from Zod schemas in storage.schema.ts.
|
|
540
|
+
*
|
|
541
|
+
* @packageDocumentation
|
|
542
|
+
*/
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Session storage interface.
|
|
546
|
+
*
|
|
547
|
+
* Abstracts how sessions are persisted across different platforms.
|
|
548
|
+
* - Browser: localStorage
|
|
549
|
+
* - Node.js: file system or memory
|
|
550
|
+
*/
|
|
551
|
+
interface ISessionStorage {
|
|
552
|
+
/**
|
|
553
|
+
* Save a session for an address.
|
|
554
|
+
* @param address - Ethereum address (key for lookup)
|
|
555
|
+
* @param session - Session data to persist
|
|
556
|
+
*/
|
|
557
|
+
save(address: string, session: PersistedSessionData): Promise<void>;
|
|
558
|
+
/**
|
|
559
|
+
* Load a session for an address.
|
|
560
|
+
* @param address - Ethereum address
|
|
561
|
+
* @returns Session data or null if not found
|
|
562
|
+
*/
|
|
563
|
+
load(address: string): Promise<PersistedSessionData | null>;
|
|
564
|
+
/**
|
|
565
|
+
* Clear a session for an address.
|
|
566
|
+
* @param address - Ethereum address
|
|
567
|
+
*/
|
|
568
|
+
clear(address: string): Promise<void>;
|
|
569
|
+
/**
|
|
570
|
+
* Check if a session exists for an address (synchronous check).
|
|
571
|
+
* @param address - Ethereum address
|
|
572
|
+
* @returns true if session exists
|
|
573
|
+
*/
|
|
574
|
+
exists(address: string): boolean;
|
|
575
|
+
/**
|
|
576
|
+
* Check if the storage backend is available.
|
|
577
|
+
* @returns true if storage can be used
|
|
578
|
+
*/
|
|
579
|
+
isAvailable(): boolean;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Zod schemas for delegation management types.
|
|
584
|
+
*
|
|
585
|
+
* These schemas provide runtime validation for delegation, capability key management,
|
|
586
|
+
* and sharing link functionality. Types are derived from schemas using z.infer<>.
|
|
587
|
+
*
|
|
588
|
+
* @packageDocumentation
|
|
589
|
+
*/
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* Result type pattern for delegation operations.
|
|
593
|
+
*/
|
|
594
|
+
type Result<T, E = DelegationError> = {
|
|
595
|
+
ok: true;
|
|
596
|
+
data: T;
|
|
597
|
+
} | {
|
|
598
|
+
ok: false;
|
|
599
|
+
error: E;
|
|
600
|
+
};
|
|
601
|
+
/**
|
|
602
|
+
* JSON Web Key representation for cryptographic keys.
|
|
603
|
+
* Follows the JWK specification (RFC 7517).
|
|
604
|
+
*/
|
|
605
|
+
declare const JWKSchema: z.ZodObject<{
|
|
606
|
+
/** Key type (e.g., "EC", "RSA", "OKP") */
|
|
607
|
+
kty: z.ZodString;
|
|
608
|
+
/** Curve for EC/OKP keys (e.g., "P-256", "Ed25519") */
|
|
609
|
+
crv: z.ZodOptional<z.ZodString>;
|
|
610
|
+
/** X coordinate for EC keys, public key for OKP */
|
|
611
|
+
x: z.ZodOptional<z.ZodString>;
|
|
612
|
+
/** Y coordinate for EC keys */
|
|
613
|
+
y: z.ZodOptional<z.ZodString>;
|
|
614
|
+
/** Private key value (d parameter) */
|
|
615
|
+
d: z.ZodOptional<z.ZodString>;
|
|
616
|
+
/** Public exponent for RSA keys */
|
|
617
|
+
e: z.ZodOptional<z.ZodString>;
|
|
618
|
+
/** Modulus for RSA keys */
|
|
619
|
+
n: z.ZodOptional<z.ZodString>;
|
|
620
|
+
/** Key ID */
|
|
621
|
+
kid: z.ZodOptional<z.ZodString>;
|
|
622
|
+
/** Algorithm */
|
|
623
|
+
alg: z.ZodOptional<z.ZodString>;
|
|
624
|
+
/** Key use (e.g., "sig", "enc") */
|
|
625
|
+
use: z.ZodOptional<z.ZodString>;
|
|
626
|
+
/** Key operations (e.g., ["sign", "verify"]) */
|
|
627
|
+
key_ops: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
628
|
+
}, "strip", z.ZodTypeAny, {
|
|
629
|
+
kty: string;
|
|
630
|
+
crv?: string | undefined;
|
|
631
|
+
x?: string | undefined;
|
|
632
|
+
y?: string | undefined;
|
|
633
|
+
d?: string | undefined;
|
|
634
|
+
e?: string | undefined;
|
|
635
|
+
n?: string | undefined;
|
|
636
|
+
kid?: string | undefined;
|
|
637
|
+
alg?: string | undefined;
|
|
638
|
+
use?: string | undefined;
|
|
639
|
+
key_ops?: string[] | undefined;
|
|
640
|
+
}, {
|
|
641
|
+
kty: string;
|
|
642
|
+
crv?: string | undefined;
|
|
643
|
+
x?: string | undefined;
|
|
644
|
+
y?: string | undefined;
|
|
645
|
+
d?: string | undefined;
|
|
646
|
+
e?: string | undefined;
|
|
647
|
+
n?: string | undefined;
|
|
648
|
+
kid?: string | undefined;
|
|
649
|
+
alg?: string | undefined;
|
|
650
|
+
use?: string | undefined;
|
|
651
|
+
key_ops?: string[] | undefined;
|
|
652
|
+
}>;
|
|
653
|
+
type JWK = z.infer<typeof JWKSchema>;
|
|
654
|
+
/**
|
|
655
|
+
* Type of key in the capability registry.
|
|
656
|
+
*/
|
|
657
|
+
declare const KeyTypeSchema: z.ZodEnum<["main", "session", "ingested"]>;
|
|
658
|
+
type KeyType = z.infer<typeof KeyTypeSchema>;
|
|
659
|
+
/**
|
|
660
|
+
* Information about a cryptographic key used for delegations.
|
|
661
|
+
*/
|
|
662
|
+
declare const KeyInfoSchema: z.ZodObject<{
|
|
663
|
+
/** Unique identifier for this key */
|
|
664
|
+
id: z.ZodString;
|
|
665
|
+
/** DID associated with this key */
|
|
666
|
+
did: z.ZodString;
|
|
667
|
+
/** Type of key determining its authority level */
|
|
668
|
+
type: z.ZodEnum<["main", "session", "ingested"]>;
|
|
669
|
+
/** Private key in JWK format */
|
|
670
|
+
jwk: z.ZodOptional<z.ZodObject<{
|
|
671
|
+
/** Key type (e.g., "EC", "RSA", "OKP") */
|
|
672
|
+
kty: z.ZodString;
|
|
673
|
+
/** Curve for EC/OKP keys (e.g., "P-256", "Ed25519") */
|
|
674
|
+
crv: z.ZodOptional<z.ZodString>;
|
|
675
|
+
/** X coordinate for EC keys, public key for OKP */
|
|
676
|
+
x: z.ZodOptional<z.ZodString>;
|
|
677
|
+
/** Y coordinate for EC keys */
|
|
678
|
+
y: z.ZodOptional<z.ZodString>;
|
|
679
|
+
/** Private key value (d parameter) */
|
|
680
|
+
d: z.ZodOptional<z.ZodString>;
|
|
681
|
+
/** Public exponent for RSA keys */
|
|
682
|
+
e: z.ZodOptional<z.ZodString>;
|
|
683
|
+
/** Modulus for RSA keys */
|
|
684
|
+
n: z.ZodOptional<z.ZodString>;
|
|
685
|
+
/** Key ID */
|
|
686
|
+
kid: z.ZodOptional<z.ZodString>;
|
|
687
|
+
/** Algorithm */
|
|
688
|
+
alg: z.ZodOptional<z.ZodString>;
|
|
689
|
+
/** Key use (e.g., "sig", "enc") */
|
|
690
|
+
use: z.ZodOptional<z.ZodString>;
|
|
691
|
+
/** Key operations (e.g., ["sign", "verify"]) */
|
|
692
|
+
key_ops: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
693
|
+
}, "strip", z.ZodTypeAny, {
|
|
694
|
+
kty: string;
|
|
695
|
+
crv?: string | undefined;
|
|
696
|
+
x?: string | undefined;
|
|
697
|
+
y?: string | undefined;
|
|
698
|
+
d?: string | undefined;
|
|
699
|
+
e?: string | undefined;
|
|
700
|
+
n?: string | undefined;
|
|
701
|
+
kid?: string | undefined;
|
|
702
|
+
alg?: string | undefined;
|
|
703
|
+
use?: string | undefined;
|
|
704
|
+
key_ops?: string[] | undefined;
|
|
705
|
+
}, {
|
|
706
|
+
kty: string;
|
|
707
|
+
crv?: string | undefined;
|
|
708
|
+
x?: string | undefined;
|
|
709
|
+
y?: string | undefined;
|
|
710
|
+
d?: string | undefined;
|
|
711
|
+
e?: string | undefined;
|
|
712
|
+
n?: string | undefined;
|
|
713
|
+
kid?: string | undefined;
|
|
714
|
+
alg?: string | undefined;
|
|
715
|
+
use?: string | undefined;
|
|
716
|
+
key_ops?: string[] | undefined;
|
|
717
|
+
}>>;
|
|
718
|
+
/** Priority for key selection (lower = higher priority) */
|
|
719
|
+
priority: z.ZodNumber;
|
|
720
|
+
}, "strip", z.ZodTypeAny, {
|
|
721
|
+
type: "session" | "main" | "ingested";
|
|
722
|
+
id: string;
|
|
723
|
+
did: string;
|
|
724
|
+
priority: number;
|
|
725
|
+
jwk?: {
|
|
726
|
+
kty: string;
|
|
727
|
+
crv?: string | undefined;
|
|
728
|
+
x?: string | undefined;
|
|
729
|
+
y?: string | undefined;
|
|
730
|
+
d?: string | undefined;
|
|
731
|
+
e?: string | undefined;
|
|
732
|
+
n?: string | undefined;
|
|
733
|
+
kid?: string | undefined;
|
|
734
|
+
alg?: string | undefined;
|
|
735
|
+
use?: string | undefined;
|
|
736
|
+
key_ops?: string[] | undefined;
|
|
737
|
+
} | undefined;
|
|
738
|
+
}, {
|
|
739
|
+
type: "session" | "main" | "ingested";
|
|
740
|
+
id: string;
|
|
741
|
+
did: string;
|
|
742
|
+
priority: number;
|
|
743
|
+
jwk?: {
|
|
744
|
+
kty: string;
|
|
745
|
+
crv?: string | undefined;
|
|
746
|
+
x?: string | undefined;
|
|
747
|
+
y?: string | undefined;
|
|
748
|
+
d?: string | undefined;
|
|
749
|
+
e?: string | undefined;
|
|
750
|
+
n?: string | undefined;
|
|
751
|
+
kid?: string | undefined;
|
|
752
|
+
alg?: string | undefined;
|
|
753
|
+
use?: string | undefined;
|
|
754
|
+
key_ops?: string[] | undefined;
|
|
755
|
+
} | undefined;
|
|
756
|
+
}>;
|
|
757
|
+
type KeyInfo = z.infer<typeof KeyInfoSchema>;
|
|
758
|
+
/**
|
|
759
|
+
* Error type for delegation operations.
|
|
760
|
+
*/
|
|
761
|
+
declare const DelegationErrorSchema: z.ZodObject<{
|
|
762
|
+
/** Error code for programmatic handling */
|
|
763
|
+
code: z.ZodString;
|
|
764
|
+
/** Human-readable error message */
|
|
765
|
+
message: z.ZodString;
|
|
766
|
+
/** The service that produced the error */
|
|
767
|
+
service: z.ZodLiteral<"delegation">;
|
|
768
|
+
/** Original error if wrapping another error */
|
|
769
|
+
cause: z.ZodOptional<z.ZodType<Error, z.ZodTypeDef, Error>>;
|
|
770
|
+
/** Additional metadata about the error */
|
|
771
|
+
meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
772
|
+
}, "strip", z.ZodTypeAny, {
|
|
773
|
+
code: string;
|
|
774
|
+
message: string;
|
|
775
|
+
service: "delegation";
|
|
776
|
+
cause?: Error | undefined;
|
|
777
|
+
meta?: Record<string, unknown> | undefined;
|
|
778
|
+
}, {
|
|
779
|
+
code: string;
|
|
780
|
+
message: string;
|
|
781
|
+
service: "delegation";
|
|
782
|
+
cause?: Error | undefined;
|
|
783
|
+
meta?: Record<string, unknown> | undefined;
|
|
784
|
+
}>;
|
|
785
|
+
type DelegationError = z.infer<typeof DelegationErrorSchema>;
|
|
786
|
+
/**
|
|
787
|
+
* Error codes for delegation operations.
|
|
788
|
+
*/
|
|
789
|
+
declare const DelegationErrorCodes: {
|
|
790
|
+
readonly AUTH_REQUIRED: "AUTH_REQUIRED";
|
|
791
|
+
readonly AUTH_EXPIRED: "AUTH_EXPIRED";
|
|
792
|
+
readonly NOT_INITIALIZED: "NOT_INITIALIZED";
|
|
793
|
+
readonly NOT_FOUND: "NOT_FOUND";
|
|
794
|
+
readonly REVOKED: "REVOKED";
|
|
795
|
+
readonly NETWORK_ERROR: "NETWORK_ERROR";
|
|
796
|
+
readonly TIMEOUT: "TIMEOUT";
|
|
797
|
+
readonly ABORTED: "ABORTED";
|
|
798
|
+
readonly INVALID_INPUT: "INVALID_INPUT";
|
|
799
|
+
readonly PERMISSION_DENIED: "PERMISSION_DENIED";
|
|
800
|
+
readonly CREATION_FAILED: "CREATION_FAILED";
|
|
801
|
+
readonly REVOCATION_FAILED: "REVOCATION_FAILED";
|
|
802
|
+
readonly INVALID_TOKEN: "INVALID_TOKEN";
|
|
803
|
+
readonly KV_SERVICE_UNAVAILABLE: "KV_SERVICE_UNAVAILABLE";
|
|
804
|
+
readonly DATA_FETCH_FAILED: "DATA_FETCH_FAILED";
|
|
805
|
+
readonly VALIDATION_ERROR: "VALIDATION_ERROR";
|
|
806
|
+
};
|
|
807
|
+
type DelegationErrorCode = (typeof DelegationErrorCodes)[keyof typeof DelegationErrorCodes];
|
|
808
|
+
/**
|
|
809
|
+
* Represents a delegation from one DID to another.
|
|
810
|
+
*/
|
|
811
|
+
declare const DelegationSchema: z.ZodObject<{
|
|
812
|
+
/** Content identifier (CID) of the delegation */
|
|
813
|
+
cid: z.ZodString;
|
|
814
|
+
/** DID of the delegate (the party receiving the delegation) */
|
|
815
|
+
delegateDID: z.ZodString;
|
|
816
|
+
/** Space ID this delegation applies to */
|
|
817
|
+
spaceId: z.ZodString;
|
|
818
|
+
/** Resource path this delegation grants access to */
|
|
819
|
+
path: z.ZodString;
|
|
820
|
+
/** Actions this delegation authorizes */
|
|
821
|
+
actions: z.ZodArray<z.ZodString, "many">;
|
|
822
|
+
/** When this delegation expires (accepts Date or ISO string from JSON) */
|
|
823
|
+
expiry: z.ZodDate;
|
|
824
|
+
/** Whether this delegation has been revoked */
|
|
825
|
+
isRevoked: z.ZodBoolean;
|
|
826
|
+
/** DID of the delegator (the party granting the delegation) */
|
|
827
|
+
delegatorDID: z.ZodOptional<z.ZodString>;
|
|
828
|
+
/** When this delegation was created (accepts Date or ISO string from JSON) */
|
|
829
|
+
createdAt: z.ZodOptional<z.ZodDate>;
|
|
830
|
+
/** Parent delegation CID if this is a sub-delegation */
|
|
831
|
+
parentCid: z.ZodOptional<z.ZodString>;
|
|
832
|
+
/** Whether sub-delegation is allowed */
|
|
833
|
+
allowSubDelegation: z.ZodOptional<z.ZodBoolean>;
|
|
834
|
+
/** Authorization header (UCAN bearer token) */
|
|
835
|
+
authHeader: z.ZodOptional<z.ZodString>;
|
|
836
|
+
}, "strip", z.ZodTypeAny, {
|
|
837
|
+
path: string;
|
|
838
|
+
spaceId: string;
|
|
839
|
+
cid: string;
|
|
840
|
+
delegateDID: string;
|
|
841
|
+
actions: string[];
|
|
842
|
+
expiry: Date;
|
|
843
|
+
isRevoked: boolean;
|
|
844
|
+
createdAt?: Date | undefined;
|
|
845
|
+
delegatorDID?: string | undefined;
|
|
846
|
+
parentCid?: string | undefined;
|
|
847
|
+
allowSubDelegation?: boolean | undefined;
|
|
848
|
+
authHeader?: string | undefined;
|
|
849
|
+
}, {
|
|
850
|
+
path: string;
|
|
851
|
+
spaceId: string;
|
|
852
|
+
cid: string;
|
|
853
|
+
delegateDID: string;
|
|
854
|
+
actions: string[];
|
|
855
|
+
expiry: Date;
|
|
856
|
+
isRevoked: boolean;
|
|
857
|
+
createdAt?: Date | undefined;
|
|
858
|
+
delegatorDID?: string | undefined;
|
|
859
|
+
parentCid?: string | undefined;
|
|
860
|
+
allowSubDelegation?: boolean | undefined;
|
|
861
|
+
authHeader?: string | undefined;
|
|
862
|
+
}>;
|
|
863
|
+
type Delegation = z.infer<typeof DelegationSchema>;
|
|
864
|
+
/**
|
|
865
|
+
* Entry in the capability registry mapping a capability to available keys.
|
|
866
|
+
*/
|
|
867
|
+
declare const CapabilityEntrySchema: z.ZodObject<{
|
|
868
|
+
/** Resource URI this capability applies to */
|
|
869
|
+
resource: z.ZodString;
|
|
870
|
+
/** Action this capability authorizes */
|
|
871
|
+
action: z.ZodString;
|
|
872
|
+
/** Keys that can exercise this capability, ordered by priority */
|
|
873
|
+
keys: z.ZodArray<z.ZodObject<{
|
|
874
|
+
/** Unique identifier for this key */
|
|
875
|
+
id: z.ZodString;
|
|
876
|
+
/** DID associated with this key */
|
|
877
|
+
did: z.ZodString;
|
|
878
|
+
/** Type of key determining its authority level */
|
|
879
|
+
type: z.ZodEnum<["main", "session", "ingested"]>;
|
|
880
|
+
/** Private key in JWK format */
|
|
881
|
+
jwk: z.ZodOptional<z.ZodObject<{
|
|
882
|
+
/** Key type (e.g., "EC", "RSA", "OKP") */
|
|
883
|
+
kty: z.ZodString;
|
|
884
|
+
/** Curve for EC/OKP keys (e.g., "P-256", "Ed25519") */
|
|
885
|
+
crv: z.ZodOptional<z.ZodString>;
|
|
886
|
+
/** X coordinate for EC keys, public key for OKP */
|
|
887
|
+
x: z.ZodOptional<z.ZodString>;
|
|
888
|
+
/** Y coordinate for EC keys */
|
|
889
|
+
y: z.ZodOptional<z.ZodString>;
|
|
890
|
+
/** Private key value (d parameter) */
|
|
891
|
+
d: z.ZodOptional<z.ZodString>;
|
|
892
|
+
/** Public exponent for RSA keys */
|
|
893
|
+
e: z.ZodOptional<z.ZodString>;
|
|
894
|
+
/** Modulus for RSA keys */
|
|
895
|
+
n: z.ZodOptional<z.ZodString>;
|
|
896
|
+
/** Key ID */
|
|
897
|
+
kid: z.ZodOptional<z.ZodString>;
|
|
898
|
+
/** Algorithm */
|
|
899
|
+
alg: z.ZodOptional<z.ZodString>;
|
|
900
|
+
/** Key use (e.g., "sig", "enc") */
|
|
901
|
+
use: z.ZodOptional<z.ZodString>;
|
|
902
|
+
/** Key operations (e.g., ["sign", "verify"]) */
|
|
903
|
+
key_ops: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
904
|
+
}, "strip", z.ZodTypeAny, {
|
|
905
|
+
kty: string;
|
|
906
|
+
crv?: string | undefined;
|
|
907
|
+
x?: string | undefined;
|
|
908
|
+
y?: string | undefined;
|
|
909
|
+
d?: string | undefined;
|
|
910
|
+
e?: string | undefined;
|
|
911
|
+
n?: string | undefined;
|
|
912
|
+
kid?: string | undefined;
|
|
913
|
+
alg?: string | undefined;
|
|
914
|
+
use?: string | undefined;
|
|
915
|
+
key_ops?: string[] | undefined;
|
|
916
|
+
}, {
|
|
917
|
+
kty: string;
|
|
918
|
+
crv?: string | undefined;
|
|
919
|
+
x?: string | undefined;
|
|
920
|
+
y?: string | undefined;
|
|
921
|
+
d?: string | undefined;
|
|
922
|
+
e?: string | undefined;
|
|
923
|
+
n?: string | undefined;
|
|
924
|
+
kid?: string | undefined;
|
|
925
|
+
alg?: string | undefined;
|
|
926
|
+
use?: string | undefined;
|
|
927
|
+
key_ops?: string[] | undefined;
|
|
928
|
+
}>>;
|
|
929
|
+
/** Priority for key selection (lower = higher priority) */
|
|
930
|
+
priority: z.ZodNumber;
|
|
931
|
+
}, "strip", z.ZodTypeAny, {
|
|
932
|
+
type: "session" | "main" | "ingested";
|
|
933
|
+
id: string;
|
|
934
|
+
did: string;
|
|
935
|
+
priority: number;
|
|
936
|
+
jwk?: {
|
|
937
|
+
kty: string;
|
|
938
|
+
crv?: string | undefined;
|
|
939
|
+
x?: string | undefined;
|
|
940
|
+
y?: string | undefined;
|
|
941
|
+
d?: string | undefined;
|
|
942
|
+
e?: string | undefined;
|
|
943
|
+
n?: string | undefined;
|
|
944
|
+
kid?: string | undefined;
|
|
945
|
+
alg?: string | undefined;
|
|
946
|
+
use?: string | undefined;
|
|
947
|
+
key_ops?: string[] | undefined;
|
|
948
|
+
} | undefined;
|
|
949
|
+
}, {
|
|
950
|
+
type: "session" | "main" | "ingested";
|
|
951
|
+
id: string;
|
|
952
|
+
did: string;
|
|
953
|
+
priority: number;
|
|
954
|
+
jwk?: {
|
|
955
|
+
kty: string;
|
|
956
|
+
crv?: string | undefined;
|
|
957
|
+
x?: string | undefined;
|
|
958
|
+
y?: string | undefined;
|
|
959
|
+
d?: string | undefined;
|
|
960
|
+
e?: string | undefined;
|
|
961
|
+
n?: string | undefined;
|
|
962
|
+
kid?: string | undefined;
|
|
963
|
+
alg?: string | undefined;
|
|
964
|
+
use?: string | undefined;
|
|
965
|
+
key_ops?: string[] | undefined;
|
|
966
|
+
} | undefined;
|
|
967
|
+
}>, "many">;
|
|
968
|
+
/** The delegation that grants this capability */
|
|
969
|
+
delegation: z.ZodObject<{
|
|
970
|
+
/** Content identifier (CID) of the delegation */
|
|
971
|
+
cid: z.ZodString;
|
|
972
|
+
/** DID of the delegate (the party receiving the delegation) */
|
|
973
|
+
delegateDID: z.ZodString;
|
|
974
|
+
/** Space ID this delegation applies to */
|
|
975
|
+
spaceId: z.ZodString;
|
|
976
|
+
/** Resource path this delegation grants access to */
|
|
977
|
+
path: z.ZodString;
|
|
978
|
+
/** Actions this delegation authorizes */
|
|
979
|
+
actions: z.ZodArray<z.ZodString, "many">;
|
|
980
|
+
/** When this delegation expires (accepts Date or ISO string from JSON) */
|
|
981
|
+
expiry: z.ZodDate;
|
|
982
|
+
/** Whether this delegation has been revoked */
|
|
983
|
+
isRevoked: z.ZodBoolean;
|
|
984
|
+
/** DID of the delegator (the party granting the delegation) */
|
|
985
|
+
delegatorDID: z.ZodOptional<z.ZodString>;
|
|
986
|
+
/** When this delegation was created (accepts Date or ISO string from JSON) */
|
|
987
|
+
createdAt: z.ZodOptional<z.ZodDate>;
|
|
988
|
+
/** Parent delegation CID if this is a sub-delegation */
|
|
989
|
+
parentCid: z.ZodOptional<z.ZodString>;
|
|
990
|
+
/** Whether sub-delegation is allowed */
|
|
991
|
+
allowSubDelegation: z.ZodOptional<z.ZodBoolean>;
|
|
992
|
+
/** Authorization header (UCAN bearer token) */
|
|
993
|
+
authHeader: z.ZodOptional<z.ZodString>;
|
|
994
|
+
}, "strip", z.ZodTypeAny, {
|
|
995
|
+
path: string;
|
|
996
|
+
spaceId: string;
|
|
997
|
+
cid: string;
|
|
998
|
+
delegateDID: string;
|
|
999
|
+
actions: string[];
|
|
1000
|
+
expiry: Date;
|
|
1001
|
+
isRevoked: boolean;
|
|
1002
|
+
createdAt?: Date | undefined;
|
|
1003
|
+
delegatorDID?: string | undefined;
|
|
1004
|
+
parentCid?: string | undefined;
|
|
1005
|
+
allowSubDelegation?: boolean | undefined;
|
|
1006
|
+
authHeader?: string | undefined;
|
|
1007
|
+
}, {
|
|
1008
|
+
path: string;
|
|
1009
|
+
spaceId: string;
|
|
1010
|
+
cid: string;
|
|
1011
|
+
delegateDID: string;
|
|
1012
|
+
actions: string[];
|
|
1013
|
+
expiry: Date;
|
|
1014
|
+
isRevoked: boolean;
|
|
1015
|
+
createdAt?: Date | undefined;
|
|
1016
|
+
delegatorDID?: string | undefined;
|
|
1017
|
+
parentCid?: string | undefined;
|
|
1018
|
+
allowSubDelegation?: boolean | undefined;
|
|
1019
|
+
authHeader?: string | undefined;
|
|
1020
|
+
}>;
|
|
1021
|
+
/** When this capability expires (accepts Date or ISO string from JSON) */
|
|
1022
|
+
expiresAt: z.ZodOptional<z.ZodDate>;
|
|
1023
|
+
}, "strip", z.ZodTypeAny, {
|
|
1024
|
+
keys: {
|
|
1025
|
+
type: "session" | "main" | "ingested";
|
|
1026
|
+
id: string;
|
|
1027
|
+
did: string;
|
|
1028
|
+
priority: number;
|
|
1029
|
+
jwk?: {
|
|
1030
|
+
kty: string;
|
|
1031
|
+
crv?: string | undefined;
|
|
1032
|
+
x?: string | undefined;
|
|
1033
|
+
y?: string | undefined;
|
|
1034
|
+
d?: string | undefined;
|
|
1035
|
+
e?: string | undefined;
|
|
1036
|
+
n?: string | undefined;
|
|
1037
|
+
kid?: string | undefined;
|
|
1038
|
+
alg?: string | undefined;
|
|
1039
|
+
use?: string | undefined;
|
|
1040
|
+
key_ops?: string[] | undefined;
|
|
1041
|
+
} | undefined;
|
|
1042
|
+
}[];
|
|
1043
|
+
delegation: {
|
|
1044
|
+
path: string;
|
|
1045
|
+
spaceId: string;
|
|
1046
|
+
cid: string;
|
|
1047
|
+
delegateDID: string;
|
|
1048
|
+
actions: string[];
|
|
1049
|
+
expiry: Date;
|
|
1050
|
+
isRevoked: boolean;
|
|
1051
|
+
createdAt?: Date | undefined;
|
|
1052
|
+
delegatorDID?: string | undefined;
|
|
1053
|
+
parentCid?: string | undefined;
|
|
1054
|
+
allowSubDelegation?: boolean | undefined;
|
|
1055
|
+
authHeader?: string | undefined;
|
|
1056
|
+
};
|
|
1057
|
+
resource: string;
|
|
1058
|
+
action: string;
|
|
1059
|
+
expiresAt?: Date | undefined;
|
|
1060
|
+
}, {
|
|
1061
|
+
keys: {
|
|
1062
|
+
type: "session" | "main" | "ingested";
|
|
1063
|
+
id: string;
|
|
1064
|
+
did: string;
|
|
1065
|
+
priority: number;
|
|
1066
|
+
jwk?: {
|
|
1067
|
+
kty: string;
|
|
1068
|
+
crv?: string | undefined;
|
|
1069
|
+
x?: string | undefined;
|
|
1070
|
+
y?: string | undefined;
|
|
1071
|
+
d?: string | undefined;
|
|
1072
|
+
e?: string | undefined;
|
|
1073
|
+
n?: string | undefined;
|
|
1074
|
+
kid?: string | undefined;
|
|
1075
|
+
alg?: string | undefined;
|
|
1076
|
+
use?: string | undefined;
|
|
1077
|
+
key_ops?: string[] | undefined;
|
|
1078
|
+
} | undefined;
|
|
1079
|
+
}[];
|
|
1080
|
+
delegation: {
|
|
1081
|
+
path: string;
|
|
1082
|
+
spaceId: string;
|
|
1083
|
+
cid: string;
|
|
1084
|
+
delegateDID: string;
|
|
1085
|
+
actions: string[];
|
|
1086
|
+
expiry: Date;
|
|
1087
|
+
isRevoked: boolean;
|
|
1088
|
+
createdAt?: Date | undefined;
|
|
1089
|
+
delegatorDID?: string | undefined;
|
|
1090
|
+
parentCid?: string | undefined;
|
|
1091
|
+
allowSubDelegation?: boolean | undefined;
|
|
1092
|
+
authHeader?: string | undefined;
|
|
1093
|
+
};
|
|
1094
|
+
resource: string;
|
|
1095
|
+
action: string;
|
|
1096
|
+
expiresAt?: Date | undefined;
|
|
1097
|
+
}>;
|
|
1098
|
+
type CapabilityEntry = z.infer<typeof CapabilityEntrySchema>;
|
|
1099
|
+
/**
|
|
1100
|
+
* Persistent record of a delegation stored in the system.
|
|
1101
|
+
*/
|
|
1102
|
+
declare const DelegationRecordSchema: z.ZodObject<{
|
|
1103
|
+
/** Content identifier (CID) of the delegation */
|
|
1104
|
+
cid: z.ZodString;
|
|
1105
|
+
/** Space ID this delegation applies to */
|
|
1106
|
+
spaceId: z.ZodString;
|
|
1107
|
+
/** DID of the delegator (grantor) */
|
|
1108
|
+
delegator: z.ZodString;
|
|
1109
|
+
/** DID of the delegatee (recipient) */
|
|
1110
|
+
delegatee: z.ZodString;
|
|
1111
|
+
/** Key ID used to sign/exercise this delegation */
|
|
1112
|
+
keyId: z.ZodOptional<z.ZodString>;
|
|
1113
|
+
/** Resource path pattern this delegation grants access to */
|
|
1114
|
+
path: z.ZodString;
|
|
1115
|
+
/** Actions this delegation authorizes */
|
|
1116
|
+
actions: z.ZodArray<z.ZodString, "many">;
|
|
1117
|
+
/** When this delegation expires (accepts Date or ISO string from JSON) */
|
|
1118
|
+
expiry: z.ZodOptional<z.ZodDate>;
|
|
1119
|
+
/** When this delegation becomes valid (not before) (accepts Date or ISO string) */
|
|
1120
|
+
notBefore: z.ZodOptional<z.ZodDate>;
|
|
1121
|
+
/** Whether this delegation has been revoked */
|
|
1122
|
+
isRevoked: z.ZodBoolean;
|
|
1123
|
+
/** When this delegation was created (accepts Date or ISO string from JSON) */
|
|
1124
|
+
createdAt: z.ZodDate;
|
|
1125
|
+
/** Parent delegation CID if this is a sub-delegation */
|
|
1126
|
+
parentCid: z.ZodOptional<z.ZodString>;
|
|
1127
|
+
}, "strip", z.ZodTypeAny, {
|
|
1128
|
+
path: string;
|
|
1129
|
+
spaceId: string;
|
|
1130
|
+
createdAt: Date;
|
|
1131
|
+
cid: string;
|
|
1132
|
+
actions: string[];
|
|
1133
|
+
isRevoked: boolean;
|
|
1134
|
+
delegator: string;
|
|
1135
|
+
delegatee: string;
|
|
1136
|
+
notBefore?: Date | undefined;
|
|
1137
|
+
expiry?: Date | undefined;
|
|
1138
|
+
parentCid?: string | undefined;
|
|
1139
|
+
keyId?: string | undefined;
|
|
1140
|
+
}, {
|
|
1141
|
+
path: string;
|
|
1142
|
+
spaceId: string;
|
|
1143
|
+
createdAt: Date;
|
|
1144
|
+
cid: string;
|
|
1145
|
+
actions: string[];
|
|
1146
|
+
isRevoked: boolean;
|
|
1147
|
+
delegator: string;
|
|
1148
|
+
delegatee: string;
|
|
1149
|
+
notBefore?: Date | undefined;
|
|
1150
|
+
expiry?: Date | undefined;
|
|
1151
|
+
parentCid?: string | undefined;
|
|
1152
|
+
keyId?: string | undefined;
|
|
1153
|
+
}>;
|
|
1154
|
+
type DelegationRecord = z.infer<typeof DelegationRecordSchema>;
|
|
1155
|
+
/**
|
|
1156
|
+
* Parameters for creating a new delegation.
|
|
1157
|
+
*/
|
|
1158
|
+
declare const CreateDelegationParamsSchema: z.ZodObject<{
|
|
1159
|
+
/** DID of the delegate (the party receiving the delegation) */
|
|
1160
|
+
delegateDID: z.ZodString;
|
|
1161
|
+
/** Resource path this delegation grants access to */
|
|
1162
|
+
path: z.ZodString;
|
|
1163
|
+
/** Actions to authorize */
|
|
1164
|
+
actions: z.ZodArray<z.ZodString, "many">;
|
|
1165
|
+
/** When this delegation expires (accepts Date or ISO string) */
|
|
1166
|
+
expiry: z.ZodOptional<z.ZodDate>;
|
|
1167
|
+
/** Whether to disable sub-delegation */
|
|
1168
|
+
disableSubDelegation: z.ZodOptional<z.ZodBoolean>;
|
|
1169
|
+
/** Optional statement for the SIWE message */
|
|
1170
|
+
statement: z.ZodOptional<z.ZodString>;
|
|
1171
|
+
}, "strip", z.ZodTypeAny, {
|
|
1172
|
+
path: string;
|
|
1173
|
+
delegateDID: string;
|
|
1174
|
+
actions: string[];
|
|
1175
|
+
statement?: string | undefined;
|
|
1176
|
+
expiry?: Date | undefined;
|
|
1177
|
+
disableSubDelegation?: boolean | undefined;
|
|
1178
|
+
}, {
|
|
1179
|
+
path: string;
|
|
1180
|
+
delegateDID: string;
|
|
1181
|
+
actions: string[];
|
|
1182
|
+
statement?: string | undefined;
|
|
1183
|
+
expiry?: Date | undefined;
|
|
1184
|
+
disableSubDelegation?: boolean | undefined;
|
|
1185
|
+
}>;
|
|
1186
|
+
type CreateDelegationParams = z.infer<typeof CreateDelegationParamsSchema>;
|
|
1187
|
+
/**
|
|
1188
|
+
* A chain of delegations from root to leaf (array format).
|
|
1189
|
+
*/
|
|
1190
|
+
declare const DelegationChainSchema: z.ZodArray<z.ZodObject<{
|
|
1191
|
+
/** Content identifier (CID) of the delegation */
|
|
1192
|
+
cid: z.ZodString;
|
|
1193
|
+
/** DID of the delegate (the party receiving the delegation) */
|
|
1194
|
+
delegateDID: z.ZodString;
|
|
1195
|
+
/** Space ID this delegation applies to */
|
|
1196
|
+
spaceId: z.ZodString;
|
|
1197
|
+
/** Resource path this delegation grants access to */
|
|
1198
|
+
path: z.ZodString;
|
|
1199
|
+
/** Actions this delegation authorizes */
|
|
1200
|
+
actions: z.ZodArray<z.ZodString, "many">;
|
|
1201
|
+
/** When this delegation expires (accepts Date or ISO string from JSON) */
|
|
1202
|
+
expiry: z.ZodDate;
|
|
1203
|
+
/** Whether this delegation has been revoked */
|
|
1204
|
+
isRevoked: z.ZodBoolean;
|
|
1205
|
+
/** DID of the delegator (the party granting the delegation) */
|
|
1206
|
+
delegatorDID: z.ZodOptional<z.ZodString>;
|
|
1207
|
+
/** When this delegation was created (accepts Date or ISO string from JSON) */
|
|
1208
|
+
createdAt: z.ZodOptional<z.ZodDate>;
|
|
1209
|
+
/** Parent delegation CID if this is a sub-delegation */
|
|
1210
|
+
parentCid: z.ZodOptional<z.ZodString>;
|
|
1211
|
+
/** Whether sub-delegation is allowed */
|
|
1212
|
+
allowSubDelegation: z.ZodOptional<z.ZodBoolean>;
|
|
1213
|
+
/** Authorization header (UCAN bearer token) */
|
|
1214
|
+
authHeader: z.ZodOptional<z.ZodString>;
|
|
1215
|
+
}, "strip", z.ZodTypeAny, {
|
|
1216
|
+
path: string;
|
|
1217
|
+
spaceId: string;
|
|
1218
|
+
cid: string;
|
|
1219
|
+
delegateDID: string;
|
|
1220
|
+
actions: string[];
|
|
1221
|
+
expiry: Date;
|
|
1222
|
+
isRevoked: boolean;
|
|
1223
|
+
createdAt?: Date | undefined;
|
|
1224
|
+
delegatorDID?: string | undefined;
|
|
1225
|
+
parentCid?: string | undefined;
|
|
1226
|
+
allowSubDelegation?: boolean | undefined;
|
|
1227
|
+
authHeader?: string | undefined;
|
|
1228
|
+
}, {
|
|
1229
|
+
path: string;
|
|
1230
|
+
spaceId: string;
|
|
1231
|
+
cid: string;
|
|
1232
|
+
delegateDID: string;
|
|
1233
|
+
actions: string[];
|
|
1234
|
+
expiry: Date;
|
|
1235
|
+
isRevoked: boolean;
|
|
1236
|
+
createdAt?: Date | undefined;
|
|
1237
|
+
delegatorDID?: string | undefined;
|
|
1238
|
+
parentCid?: string | undefined;
|
|
1239
|
+
allowSubDelegation?: boolean | undefined;
|
|
1240
|
+
authHeader?: string | undefined;
|
|
1241
|
+
}>, "many">;
|
|
1242
|
+
type DelegationChain = z.infer<typeof DelegationChainSchema>;
|
|
1243
|
+
/**
|
|
1244
|
+
* Structured delegation chain (v2 spec).
|
|
1245
|
+
*/
|
|
1246
|
+
declare const DelegationChainV2Schema: z.ZodObject<{
|
|
1247
|
+
/** The root delegation from the original authority */
|
|
1248
|
+
root: z.ZodObject<{
|
|
1249
|
+
/** Content identifier (CID) of the delegation */
|
|
1250
|
+
cid: z.ZodString;
|
|
1251
|
+
/** DID of the delegate (the party receiving the delegation) */
|
|
1252
|
+
delegateDID: z.ZodString;
|
|
1253
|
+
/** Space ID this delegation applies to */
|
|
1254
|
+
spaceId: z.ZodString;
|
|
1255
|
+
/** Resource path this delegation grants access to */
|
|
1256
|
+
path: z.ZodString;
|
|
1257
|
+
/** Actions this delegation authorizes */
|
|
1258
|
+
actions: z.ZodArray<z.ZodString, "many">;
|
|
1259
|
+
/** When this delegation expires (accepts Date or ISO string from JSON) */
|
|
1260
|
+
expiry: z.ZodDate;
|
|
1261
|
+
/** Whether this delegation has been revoked */
|
|
1262
|
+
isRevoked: z.ZodBoolean;
|
|
1263
|
+
/** DID of the delegator (the party granting the delegation) */
|
|
1264
|
+
delegatorDID: z.ZodOptional<z.ZodString>;
|
|
1265
|
+
/** When this delegation was created (accepts Date or ISO string from JSON) */
|
|
1266
|
+
createdAt: z.ZodOptional<z.ZodDate>;
|
|
1267
|
+
/** Parent delegation CID if this is a sub-delegation */
|
|
1268
|
+
parentCid: z.ZodOptional<z.ZodString>;
|
|
1269
|
+
/** Whether sub-delegation is allowed */
|
|
1270
|
+
allowSubDelegation: z.ZodOptional<z.ZodBoolean>;
|
|
1271
|
+
/** Authorization header (UCAN bearer token) */
|
|
1272
|
+
authHeader: z.ZodOptional<z.ZodString>;
|
|
1273
|
+
}, "strip", z.ZodTypeAny, {
|
|
1274
|
+
path: string;
|
|
1275
|
+
spaceId: string;
|
|
1276
|
+
cid: string;
|
|
1277
|
+
delegateDID: string;
|
|
1278
|
+
actions: string[];
|
|
1279
|
+
expiry: Date;
|
|
1280
|
+
isRevoked: boolean;
|
|
1281
|
+
createdAt?: Date | undefined;
|
|
1282
|
+
delegatorDID?: string | undefined;
|
|
1283
|
+
parentCid?: string | undefined;
|
|
1284
|
+
allowSubDelegation?: boolean | undefined;
|
|
1285
|
+
authHeader?: string | undefined;
|
|
1286
|
+
}, {
|
|
1287
|
+
path: string;
|
|
1288
|
+
spaceId: string;
|
|
1289
|
+
cid: string;
|
|
1290
|
+
delegateDID: string;
|
|
1291
|
+
actions: string[];
|
|
1292
|
+
expiry: Date;
|
|
1293
|
+
isRevoked: boolean;
|
|
1294
|
+
createdAt?: Date | undefined;
|
|
1295
|
+
delegatorDID?: string | undefined;
|
|
1296
|
+
parentCid?: string | undefined;
|
|
1297
|
+
allowSubDelegation?: boolean | undefined;
|
|
1298
|
+
authHeader?: string | undefined;
|
|
1299
|
+
}>;
|
|
1300
|
+
/** Intermediate delegations in the chain (may be empty) */
|
|
1301
|
+
chain: z.ZodArray<z.ZodObject<{
|
|
1302
|
+
/** Content identifier (CID) of the delegation */
|
|
1303
|
+
cid: z.ZodString;
|
|
1304
|
+
/** DID of the delegate (the party receiving the delegation) */
|
|
1305
|
+
delegateDID: z.ZodString;
|
|
1306
|
+
/** Space ID this delegation applies to */
|
|
1307
|
+
spaceId: z.ZodString;
|
|
1308
|
+
/** Resource path this delegation grants access to */
|
|
1309
|
+
path: z.ZodString;
|
|
1310
|
+
/** Actions this delegation authorizes */
|
|
1311
|
+
actions: z.ZodArray<z.ZodString, "many">;
|
|
1312
|
+
/** When this delegation expires (accepts Date or ISO string from JSON) */
|
|
1313
|
+
expiry: z.ZodDate;
|
|
1314
|
+
/** Whether this delegation has been revoked */
|
|
1315
|
+
isRevoked: z.ZodBoolean;
|
|
1316
|
+
/** DID of the delegator (the party granting the delegation) */
|
|
1317
|
+
delegatorDID: z.ZodOptional<z.ZodString>;
|
|
1318
|
+
/** When this delegation was created (accepts Date or ISO string from JSON) */
|
|
1319
|
+
createdAt: z.ZodOptional<z.ZodDate>;
|
|
1320
|
+
/** Parent delegation CID if this is a sub-delegation */
|
|
1321
|
+
parentCid: z.ZodOptional<z.ZodString>;
|
|
1322
|
+
/** Whether sub-delegation is allowed */
|
|
1323
|
+
allowSubDelegation: z.ZodOptional<z.ZodBoolean>;
|
|
1324
|
+
/** Authorization header (UCAN bearer token) */
|
|
1325
|
+
authHeader: z.ZodOptional<z.ZodString>;
|
|
1326
|
+
}, "strip", z.ZodTypeAny, {
|
|
1327
|
+
path: string;
|
|
1328
|
+
spaceId: string;
|
|
1329
|
+
cid: string;
|
|
1330
|
+
delegateDID: string;
|
|
1331
|
+
actions: string[];
|
|
1332
|
+
expiry: Date;
|
|
1333
|
+
isRevoked: boolean;
|
|
1334
|
+
createdAt?: Date | undefined;
|
|
1335
|
+
delegatorDID?: string | undefined;
|
|
1336
|
+
parentCid?: string | undefined;
|
|
1337
|
+
allowSubDelegation?: boolean | undefined;
|
|
1338
|
+
authHeader?: string | undefined;
|
|
1339
|
+
}, {
|
|
1340
|
+
path: string;
|
|
1341
|
+
spaceId: string;
|
|
1342
|
+
cid: string;
|
|
1343
|
+
delegateDID: string;
|
|
1344
|
+
actions: string[];
|
|
1345
|
+
expiry: Date;
|
|
1346
|
+
isRevoked: boolean;
|
|
1347
|
+
createdAt?: Date | undefined;
|
|
1348
|
+
delegatorDID?: string | undefined;
|
|
1349
|
+
parentCid?: string | undefined;
|
|
1350
|
+
allowSubDelegation?: boolean | undefined;
|
|
1351
|
+
authHeader?: string | undefined;
|
|
1352
|
+
}>, "many">;
|
|
1353
|
+
/** The final delegation to the current user */
|
|
1354
|
+
leaf: z.ZodObject<{
|
|
1355
|
+
/** Content identifier (CID) of the delegation */
|
|
1356
|
+
cid: z.ZodString;
|
|
1357
|
+
/** DID of the delegate (the party receiving the delegation) */
|
|
1358
|
+
delegateDID: z.ZodString;
|
|
1359
|
+
/** Space ID this delegation applies to */
|
|
1360
|
+
spaceId: z.ZodString;
|
|
1361
|
+
/** Resource path this delegation grants access to */
|
|
1362
|
+
path: z.ZodString;
|
|
1363
|
+
/** Actions this delegation authorizes */
|
|
1364
|
+
actions: z.ZodArray<z.ZodString, "many">;
|
|
1365
|
+
/** When this delegation expires (accepts Date or ISO string from JSON) */
|
|
1366
|
+
expiry: z.ZodDate;
|
|
1367
|
+
/** Whether this delegation has been revoked */
|
|
1368
|
+
isRevoked: z.ZodBoolean;
|
|
1369
|
+
/** DID of the delegator (the party granting the delegation) */
|
|
1370
|
+
delegatorDID: z.ZodOptional<z.ZodString>;
|
|
1371
|
+
/** When this delegation was created (accepts Date or ISO string from JSON) */
|
|
1372
|
+
createdAt: z.ZodOptional<z.ZodDate>;
|
|
1373
|
+
/** Parent delegation CID if this is a sub-delegation */
|
|
1374
|
+
parentCid: z.ZodOptional<z.ZodString>;
|
|
1375
|
+
/** Whether sub-delegation is allowed */
|
|
1376
|
+
allowSubDelegation: z.ZodOptional<z.ZodBoolean>;
|
|
1377
|
+
/** Authorization header (UCAN bearer token) */
|
|
1378
|
+
authHeader: z.ZodOptional<z.ZodString>;
|
|
1379
|
+
}, "strip", z.ZodTypeAny, {
|
|
1380
|
+
path: string;
|
|
1381
|
+
spaceId: string;
|
|
1382
|
+
cid: string;
|
|
1383
|
+
delegateDID: string;
|
|
1384
|
+
actions: string[];
|
|
1385
|
+
expiry: Date;
|
|
1386
|
+
isRevoked: boolean;
|
|
1387
|
+
createdAt?: Date | undefined;
|
|
1388
|
+
delegatorDID?: string | undefined;
|
|
1389
|
+
parentCid?: string | undefined;
|
|
1390
|
+
allowSubDelegation?: boolean | undefined;
|
|
1391
|
+
authHeader?: string | undefined;
|
|
1392
|
+
}, {
|
|
1393
|
+
path: string;
|
|
1394
|
+
spaceId: string;
|
|
1395
|
+
cid: string;
|
|
1396
|
+
delegateDID: string;
|
|
1397
|
+
actions: string[];
|
|
1398
|
+
expiry: Date;
|
|
1399
|
+
isRevoked: boolean;
|
|
1400
|
+
createdAt?: Date | undefined;
|
|
1401
|
+
delegatorDID?: string | undefined;
|
|
1402
|
+
parentCid?: string | undefined;
|
|
1403
|
+
allowSubDelegation?: boolean | undefined;
|
|
1404
|
+
authHeader?: string | undefined;
|
|
1405
|
+
}>;
|
|
1406
|
+
}, "strip", z.ZodTypeAny, {
|
|
1407
|
+
root: {
|
|
1408
|
+
path: string;
|
|
1409
|
+
spaceId: string;
|
|
1410
|
+
cid: string;
|
|
1411
|
+
delegateDID: string;
|
|
1412
|
+
actions: string[];
|
|
1413
|
+
expiry: Date;
|
|
1414
|
+
isRevoked: boolean;
|
|
1415
|
+
createdAt?: Date | undefined;
|
|
1416
|
+
delegatorDID?: string | undefined;
|
|
1417
|
+
parentCid?: string | undefined;
|
|
1418
|
+
allowSubDelegation?: boolean | undefined;
|
|
1419
|
+
authHeader?: string | undefined;
|
|
1420
|
+
};
|
|
1421
|
+
chain: {
|
|
1422
|
+
path: string;
|
|
1423
|
+
spaceId: string;
|
|
1424
|
+
cid: string;
|
|
1425
|
+
delegateDID: string;
|
|
1426
|
+
actions: string[];
|
|
1427
|
+
expiry: Date;
|
|
1428
|
+
isRevoked: boolean;
|
|
1429
|
+
createdAt?: Date | undefined;
|
|
1430
|
+
delegatorDID?: string | undefined;
|
|
1431
|
+
parentCid?: string | undefined;
|
|
1432
|
+
allowSubDelegation?: boolean | undefined;
|
|
1433
|
+
authHeader?: string | undefined;
|
|
1434
|
+
}[];
|
|
1435
|
+
leaf: {
|
|
1436
|
+
path: string;
|
|
1437
|
+
spaceId: string;
|
|
1438
|
+
cid: string;
|
|
1439
|
+
delegateDID: string;
|
|
1440
|
+
actions: string[];
|
|
1441
|
+
expiry: Date;
|
|
1442
|
+
isRevoked: boolean;
|
|
1443
|
+
createdAt?: Date | undefined;
|
|
1444
|
+
delegatorDID?: string | undefined;
|
|
1445
|
+
parentCid?: string | undefined;
|
|
1446
|
+
allowSubDelegation?: boolean | undefined;
|
|
1447
|
+
authHeader?: string | undefined;
|
|
1448
|
+
};
|
|
1449
|
+
}, {
|
|
1450
|
+
root: {
|
|
1451
|
+
path: string;
|
|
1452
|
+
spaceId: string;
|
|
1453
|
+
cid: string;
|
|
1454
|
+
delegateDID: string;
|
|
1455
|
+
actions: string[];
|
|
1456
|
+
expiry: Date;
|
|
1457
|
+
isRevoked: boolean;
|
|
1458
|
+
createdAt?: Date | undefined;
|
|
1459
|
+
delegatorDID?: string | undefined;
|
|
1460
|
+
parentCid?: string | undefined;
|
|
1461
|
+
allowSubDelegation?: boolean | undefined;
|
|
1462
|
+
authHeader?: string | undefined;
|
|
1463
|
+
};
|
|
1464
|
+
chain: {
|
|
1465
|
+
path: string;
|
|
1466
|
+
spaceId: string;
|
|
1467
|
+
cid: string;
|
|
1468
|
+
delegateDID: string;
|
|
1469
|
+
actions: string[];
|
|
1470
|
+
expiry: Date;
|
|
1471
|
+
isRevoked: boolean;
|
|
1472
|
+
createdAt?: Date | undefined;
|
|
1473
|
+
delegatorDID?: string | undefined;
|
|
1474
|
+
parentCid?: string | undefined;
|
|
1475
|
+
allowSubDelegation?: boolean | undefined;
|
|
1476
|
+
authHeader?: string | undefined;
|
|
1477
|
+
}[];
|
|
1478
|
+
leaf: {
|
|
1479
|
+
path: string;
|
|
1480
|
+
spaceId: string;
|
|
1481
|
+
cid: string;
|
|
1482
|
+
delegateDID: string;
|
|
1483
|
+
actions: string[];
|
|
1484
|
+
expiry: Date;
|
|
1485
|
+
isRevoked: boolean;
|
|
1486
|
+
createdAt?: Date | undefined;
|
|
1487
|
+
delegatorDID?: string | undefined;
|
|
1488
|
+
parentCid?: string | undefined;
|
|
1489
|
+
allowSubDelegation?: boolean | undefined;
|
|
1490
|
+
authHeader?: string | undefined;
|
|
1491
|
+
};
|
|
1492
|
+
}>;
|
|
1493
|
+
type DelegationChainV2 = z.infer<typeof DelegationChainV2Schema>;
|
|
1494
|
+
/**
|
|
1495
|
+
* Direction of delegation to filter by.
|
|
1496
|
+
*/
|
|
1497
|
+
declare const DelegationDirectionSchema: z.ZodEnum<["granted", "received", "all"]>;
|
|
1498
|
+
type DelegationDirection = z.infer<typeof DelegationDirectionSchema>;
|
|
1499
|
+
/**
|
|
1500
|
+
* Filters for listing delegations.
|
|
1501
|
+
*/
|
|
1502
|
+
declare const DelegationFiltersSchema: z.ZodObject<{
|
|
1503
|
+
/** Filter by delegation direction */
|
|
1504
|
+
direction: z.ZodOptional<z.ZodEnum<["granted", "received", "all"]>>;
|
|
1505
|
+
/** Filter by resource path pattern */
|
|
1506
|
+
path: z.ZodOptional<z.ZodString>;
|
|
1507
|
+
/** Filter by required actions */
|
|
1508
|
+
actions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
1509
|
+
/** Include revoked delegations */
|
|
1510
|
+
includeRevoked: z.ZodOptional<z.ZodBoolean>;
|
|
1511
|
+
/** Filter by delegator DID */
|
|
1512
|
+
delegator: z.ZodOptional<z.ZodString>;
|
|
1513
|
+
/** Filter by delegatee DID */
|
|
1514
|
+
delegatee: z.ZodOptional<z.ZodString>;
|
|
1515
|
+
/** Only include delegations valid at this time */
|
|
1516
|
+
validAt: z.ZodOptional<z.ZodDate>;
|
|
1517
|
+
/** Maximum number of results to return */
|
|
1518
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
1519
|
+
/** Cursor for pagination */
|
|
1520
|
+
cursor: z.ZodOptional<z.ZodString>;
|
|
1521
|
+
}, "strip", z.ZodTypeAny, {
|
|
1522
|
+
path?: string | undefined;
|
|
1523
|
+
actions?: string[] | undefined;
|
|
1524
|
+
delegator?: string | undefined;
|
|
1525
|
+
delegatee?: string | undefined;
|
|
1526
|
+
direction?: "received" | "granted" | "all" | undefined;
|
|
1527
|
+
includeRevoked?: boolean | undefined;
|
|
1528
|
+
validAt?: Date | undefined;
|
|
1529
|
+
limit?: number | undefined;
|
|
1530
|
+
cursor?: string | undefined;
|
|
1531
|
+
}, {
|
|
1532
|
+
path?: string | undefined;
|
|
1533
|
+
actions?: string[] | undefined;
|
|
1534
|
+
delegator?: string | undefined;
|
|
1535
|
+
delegatee?: string | undefined;
|
|
1536
|
+
direction?: "received" | "granted" | "all" | undefined;
|
|
1537
|
+
includeRevoked?: boolean | undefined;
|
|
1538
|
+
validAt?: Date | undefined;
|
|
1539
|
+
limit?: number | undefined;
|
|
1540
|
+
cursor?: string | undefined;
|
|
1541
|
+
}>;
|
|
1542
|
+
type DelegationFilters = z.infer<typeof DelegationFiltersSchema>;
|
|
1543
|
+
/**
|
|
1544
|
+
* Type of space ownership.
|
|
1545
|
+
*/
|
|
1546
|
+
declare const SpaceOwnershipSchema: z.ZodEnum<["owned", "delegated"]>;
|
|
1547
|
+
type SpaceOwnership = z.infer<typeof SpaceOwnershipSchema>;
|
|
1548
|
+
/**
|
|
1549
|
+
* Information about a space the user has access to.
|
|
1550
|
+
*/
|
|
1551
|
+
declare const SpaceInfoSchema: z.ZodObject<{
|
|
1552
|
+
/** Space identifier */
|
|
1553
|
+
id: z.ZodString;
|
|
1554
|
+
/** Human-readable name for the space */
|
|
1555
|
+
name: z.ZodOptional<z.ZodString>;
|
|
1556
|
+
/** DID of the space owner */
|
|
1557
|
+
owner: z.ZodString;
|
|
1558
|
+
/** Whether user owns or has delegated access */
|
|
1559
|
+
type: z.ZodEnum<["owned", "delegated"]>;
|
|
1560
|
+
/** Permissions the user has in this space */
|
|
1561
|
+
permissions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
1562
|
+
/** When the access expires (for delegated spaces) */
|
|
1563
|
+
expiresAt: z.ZodOptional<z.ZodDate>;
|
|
1564
|
+
}, "strip", z.ZodTypeAny, {
|
|
1565
|
+
type: "owned" | "delegated";
|
|
1566
|
+
id: string;
|
|
1567
|
+
owner: string;
|
|
1568
|
+
expiresAt?: Date | undefined;
|
|
1569
|
+
name?: string | undefined;
|
|
1570
|
+
permissions?: string[] | undefined;
|
|
1571
|
+
}, {
|
|
1572
|
+
type: "owned" | "delegated";
|
|
1573
|
+
id: string;
|
|
1574
|
+
owner: string;
|
|
1575
|
+
expiresAt?: Date | undefined;
|
|
1576
|
+
name?: string | undefined;
|
|
1577
|
+
permissions?: string[] | undefined;
|
|
1578
|
+
}>;
|
|
1579
|
+
type SpaceInfo = z.infer<typeof SpaceInfoSchema>;
|
|
1580
|
+
/**
|
|
1581
|
+
* Schema for encoding share link data.
|
|
1582
|
+
*/
|
|
1583
|
+
declare const ShareSchemaSchema: z.ZodEnum<["base64", "compact", "ipfs"]>;
|
|
1584
|
+
type ShareSchema = z.infer<typeof ShareSchemaSchema>;
|
|
1585
|
+
/**
|
|
1586
|
+
* A shareable link containing delegation credentials.
|
|
1587
|
+
*/
|
|
1588
|
+
declare const ShareLinkSchema: z.ZodObject<{
|
|
1589
|
+
/** Unique token identifying this share link */
|
|
1590
|
+
token: z.ZodString;
|
|
1591
|
+
/** Full URL for sharing */
|
|
1592
|
+
url: z.ZodString;
|
|
1593
|
+
/** The delegation this link grants access to */
|
|
1594
|
+
delegation: z.ZodObject<{
|
|
1595
|
+
/** Content identifier (CID) of the delegation */
|
|
1596
|
+
cid: z.ZodString;
|
|
1597
|
+
/** DID of the delegate (the party receiving the delegation) */
|
|
1598
|
+
delegateDID: z.ZodString;
|
|
1599
|
+
/** Space ID this delegation applies to */
|
|
1600
|
+
spaceId: z.ZodString;
|
|
1601
|
+
/** Resource path this delegation grants access to */
|
|
1602
|
+
path: z.ZodString;
|
|
1603
|
+
/** Actions this delegation authorizes */
|
|
1604
|
+
actions: z.ZodArray<z.ZodString, "many">;
|
|
1605
|
+
/** When this delegation expires (accepts Date or ISO string from JSON) */
|
|
1606
|
+
expiry: z.ZodDate;
|
|
1607
|
+
/** Whether this delegation has been revoked */
|
|
1608
|
+
isRevoked: z.ZodBoolean;
|
|
1609
|
+
/** DID of the delegator (the party granting the delegation) */
|
|
1610
|
+
delegatorDID: z.ZodOptional<z.ZodString>;
|
|
1611
|
+
/** When this delegation was created (accepts Date or ISO string from JSON) */
|
|
1612
|
+
createdAt: z.ZodOptional<z.ZodDate>;
|
|
1613
|
+
/** Parent delegation CID if this is a sub-delegation */
|
|
1614
|
+
parentCid: z.ZodOptional<z.ZodString>;
|
|
1615
|
+
/** Whether sub-delegation is allowed */
|
|
1616
|
+
allowSubDelegation: z.ZodOptional<z.ZodBoolean>;
|
|
1617
|
+
/** Authorization header (UCAN bearer token) */
|
|
1618
|
+
authHeader: z.ZodOptional<z.ZodString>;
|
|
1619
|
+
}, "strip", z.ZodTypeAny, {
|
|
1620
|
+
path: string;
|
|
1621
|
+
spaceId: string;
|
|
1622
|
+
cid: string;
|
|
1623
|
+
delegateDID: string;
|
|
1624
|
+
actions: string[];
|
|
1625
|
+
expiry: Date;
|
|
1626
|
+
isRevoked: boolean;
|
|
1627
|
+
createdAt?: Date | undefined;
|
|
1628
|
+
delegatorDID?: string | undefined;
|
|
1629
|
+
parentCid?: string | undefined;
|
|
1630
|
+
allowSubDelegation?: boolean | undefined;
|
|
1631
|
+
authHeader?: string | undefined;
|
|
1632
|
+
}, {
|
|
1633
|
+
path: string;
|
|
1634
|
+
spaceId: string;
|
|
1635
|
+
cid: string;
|
|
1636
|
+
delegateDID: string;
|
|
1637
|
+
actions: string[];
|
|
1638
|
+
expiry: Date;
|
|
1639
|
+
isRevoked: boolean;
|
|
1640
|
+
createdAt?: Date | undefined;
|
|
1641
|
+
delegatorDID?: string | undefined;
|
|
1642
|
+
parentCid?: string | undefined;
|
|
1643
|
+
allowSubDelegation?: boolean | undefined;
|
|
1644
|
+
authHeader?: string | undefined;
|
|
1645
|
+
}>;
|
|
1646
|
+
/** Encoding schema used for the link */
|
|
1647
|
+
schema: z.ZodEnum<["base64", "compact", "ipfs"]>;
|
|
1648
|
+
/** When this share link expires */
|
|
1649
|
+
expiresAt: z.ZodOptional<z.ZodDate>;
|
|
1650
|
+
/** Human-readable description of what is being shared */
|
|
1651
|
+
description: z.ZodOptional<z.ZodString>;
|
|
1652
|
+
}, "strip", z.ZodTypeAny, {
|
|
1653
|
+
url: string;
|
|
1654
|
+
delegation: {
|
|
1655
|
+
path: string;
|
|
1656
|
+
spaceId: string;
|
|
1657
|
+
cid: string;
|
|
1658
|
+
delegateDID: string;
|
|
1659
|
+
actions: string[];
|
|
1660
|
+
expiry: Date;
|
|
1661
|
+
isRevoked: boolean;
|
|
1662
|
+
createdAt?: Date | undefined;
|
|
1663
|
+
delegatorDID?: string | undefined;
|
|
1664
|
+
parentCid?: string | undefined;
|
|
1665
|
+
allowSubDelegation?: boolean | undefined;
|
|
1666
|
+
authHeader?: string | undefined;
|
|
1667
|
+
};
|
|
1668
|
+
token: string;
|
|
1669
|
+
schema: "base64" | "compact" | "ipfs";
|
|
1670
|
+
expiresAt?: Date | undefined;
|
|
1671
|
+
description?: string | undefined;
|
|
1672
|
+
}, {
|
|
1673
|
+
url: string;
|
|
1674
|
+
delegation: {
|
|
1675
|
+
path: string;
|
|
1676
|
+
spaceId: string;
|
|
1677
|
+
cid: string;
|
|
1678
|
+
delegateDID: string;
|
|
1679
|
+
actions: string[];
|
|
1680
|
+
expiry: Date;
|
|
1681
|
+
isRevoked: boolean;
|
|
1682
|
+
createdAt?: Date | undefined;
|
|
1683
|
+
delegatorDID?: string | undefined;
|
|
1684
|
+
parentCid?: string | undefined;
|
|
1685
|
+
allowSubDelegation?: boolean | undefined;
|
|
1686
|
+
authHeader?: string | undefined;
|
|
1687
|
+
};
|
|
1688
|
+
token: string;
|
|
1689
|
+
schema: "base64" | "compact" | "ipfs";
|
|
1690
|
+
expiresAt?: Date | undefined;
|
|
1691
|
+
description?: string | undefined;
|
|
1692
|
+
}>;
|
|
1693
|
+
type ShareLink = z.infer<typeof ShareLinkSchema>;
|
|
1694
|
+
type ShareLinkData<T = unknown> = {
|
|
1695
|
+
data: T;
|
|
1696
|
+
delegation: Delegation;
|
|
1697
|
+
spaceId: string;
|
|
1698
|
+
path: string;
|
|
1699
|
+
};
|
|
1700
|
+
/**
|
|
1701
|
+
* Options for ingesting an external delegation.
|
|
1702
|
+
*/
|
|
1703
|
+
declare const IngestOptionsSchema: z.ZodObject<{
|
|
1704
|
+
/** Whether to persist the delegation to storage */
|
|
1705
|
+
persist: z.ZodOptional<z.ZodBoolean>;
|
|
1706
|
+
/** Whether to validate the full delegation chain */
|
|
1707
|
+
validateChain: z.ZodOptional<z.ZodBoolean>;
|
|
1708
|
+
/** Name for the ingested key */
|
|
1709
|
+
keyName: z.ZodOptional<z.ZodString>;
|
|
1710
|
+
/** Whether to create a session key for this delegation */
|
|
1711
|
+
createSessionKey: z.ZodOptional<z.ZodBoolean>;
|
|
1712
|
+
/** Override the priority for the ingested key */
|
|
1713
|
+
priority: z.ZodOptional<z.ZodNumber>;
|
|
1714
|
+
}, "strip", z.ZodTypeAny, {
|
|
1715
|
+
priority?: number | undefined;
|
|
1716
|
+
persist?: boolean | undefined;
|
|
1717
|
+
validateChain?: boolean | undefined;
|
|
1718
|
+
keyName?: string | undefined;
|
|
1719
|
+
createSessionKey?: boolean | undefined;
|
|
1720
|
+
}, {
|
|
1721
|
+
priority?: number | undefined;
|
|
1722
|
+
persist?: boolean | undefined;
|
|
1723
|
+
validateChain?: boolean | undefined;
|
|
1724
|
+
keyName?: string | undefined;
|
|
1725
|
+
createSessionKey?: boolean | undefined;
|
|
1726
|
+
}>;
|
|
1727
|
+
type IngestOptions = z.infer<typeof IngestOptionsSchema>;
|
|
1728
|
+
/**
|
|
1729
|
+
* Parameters for generating a share link.
|
|
1730
|
+
*/
|
|
1731
|
+
declare const GenerateShareParamsSchema: z.ZodObject<{
|
|
1732
|
+
/** Resource path to share */
|
|
1733
|
+
path: z.ZodString;
|
|
1734
|
+
/** Actions to authorize */
|
|
1735
|
+
actions: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
1736
|
+
/** When the share link expires */
|
|
1737
|
+
expiry: z.ZodOptional<z.ZodDate>;
|
|
1738
|
+
/** Encoding schema for the link */
|
|
1739
|
+
schema: z.ZodOptional<z.ZodEnum<["base64", "compact", "ipfs"]>>;
|
|
1740
|
+
/** Human-readable description */
|
|
1741
|
+
description: z.ZodOptional<z.ZodString>;
|
|
1742
|
+
/** Base URL for the share link */
|
|
1743
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
1744
|
+
}, "strip", z.ZodTypeAny, {
|
|
1745
|
+
path: string;
|
|
1746
|
+
actions?: string[] | undefined;
|
|
1747
|
+
expiry?: Date | undefined;
|
|
1748
|
+
schema?: "base64" | "compact" | "ipfs" | undefined;
|
|
1749
|
+
description?: string | undefined;
|
|
1750
|
+
baseUrl?: string | undefined;
|
|
1751
|
+
}, {
|
|
1752
|
+
path: string;
|
|
1753
|
+
actions?: string[] | undefined;
|
|
1754
|
+
expiry?: Date | undefined;
|
|
1755
|
+
schema?: "base64" | "compact" | "ipfs" | undefined;
|
|
1756
|
+
description?: string | undefined;
|
|
1757
|
+
baseUrl?: string | undefined;
|
|
1758
|
+
}>;
|
|
1759
|
+
type GenerateShareParams = z.infer<typeof GenerateShareParamsSchema>;
|
|
1760
|
+
/**
|
|
1761
|
+
* Configuration for DelegationManager.
|
|
1762
|
+
* Note: ServiceSession, InvokeFunction, and FetchFunction are external types.
|
|
1763
|
+
*/
|
|
1764
|
+
declare const DelegationManagerConfigSchema: z.ZodObject<{
|
|
1765
|
+
/** TinyCloud host URLs */
|
|
1766
|
+
hosts: z.ZodArray<z.ZodString, "many">;
|
|
1767
|
+
/** Active session for authentication */
|
|
1768
|
+
session: z.ZodEffects<z.ZodUnknown, ServiceSession, unknown>;
|
|
1769
|
+
/** Platform-specific invoke function */
|
|
1770
|
+
invoke: z.ZodEffects<z.ZodUnknown, InvokeFunction, unknown>;
|
|
1771
|
+
/** Optional custom fetch implementation */
|
|
1772
|
+
fetch: z.ZodOptional<z.ZodEffects<z.ZodUnknown, FetchFunction, unknown>>;
|
|
1773
|
+
}, "strip", z.ZodTypeAny, {
|
|
1774
|
+
session: ServiceSession;
|
|
1775
|
+
hosts: string[];
|
|
1776
|
+
invoke: InvokeFunction;
|
|
1777
|
+
fetch?: FetchFunction | undefined;
|
|
1778
|
+
}, {
|
|
1779
|
+
hosts: string[];
|
|
1780
|
+
session?: unknown;
|
|
1781
|
+
invoke?: unknown;
|
|
1782
|
+
fetch?: unknown;
|
|
1783
|
+
}>;
|
|
1784
|
+
type DelegationManagerConfig = z.infer<typeof DelegationManagerConfigSchema>;
|
|
1785
|
+
/**
|
|
1786
|
+
* Provider interface for cryptographic key operations.
|
|
1787
|
+
*/
|
|
1788
|
+
declare const KeyProviderSchema: z.ZodObject<{
|
|
1789
|
+
/** Generate a new session key, returns key ID */
|
|
1790
|
+
createSessionKey: z.ZodEffects<z.ZodUnknown, (name: string) => Promise<string>, unknown>;
|
|
1791
|
+
/** Get JWK for a key */
|
|
1792
|
+
getJWK: z.ZodEffects<z.ZodUnknown, (keyId: string) => object, unknown>;
|
|
1793
|
+
/** Get DID for a key */
|
|
1794
|
+
getDID: z.ZodEffects<z.ZodUnknown, (keyId: string) => Promise<string>, unknown>;
|
|
1795
|
+
}, "strip", z.ZodTypeAny, {
|
|
1796
|
+
createSessionKey: (name: string) => Promise<string>;
|
|
1797
|
+
getJWK: (keyId: string) => object;
|
|
1798
|
+
getDID: (keyId: string) => Promise<string>;
|
|
1799
|
+
}, {
|
|
1800
|
+
createSessionKey?: unknown;
|
|
1801
|
+
getJWK?: unknown;
|
|
1802
|
+
getDID?: unknown;
|
|
1803
|
+
}>;
|
|
1804
|
+
type KeyProvider = z.infer<typeof KeyProviderSchema>;
|
|
1805
|
+
/**
|
|
1806
|
+
* Response from the delegation API.
|
|
1807
|
+
*/
|
|
1808
|
+
declare const DelegationApiResponseSchema: z.ZodObject<{
|
|
1809
|
+
/** SIWE message content */
|
|
1810
|
+
siwe: z.ZodString;
|
|
1811
|
+
/** Signature of the SIWE message */
|
|
1812
|
+
signature: z.ZodString;
|
|
1813
|
+
/** Delegation version */
|
|
1814
|
+
version: z.ZodNumber;
|
|
1815
|
+
/** CID of the created delegation */
|
|
1816
|
+
cid: z.ZodOptional<z.ZodString>;
|
|
1817
|
+
}, "strip", z.ZodTypeAny, {
|
|
1818
|
+
siwe: string;
|
|
1819
|
+
signature: string;
|
|
1820
|
+
version: number;
|
|
1821
|
+
cid?: string | undefined;
|
|
1822
|
+
}, {
|
|
1823
|
+
siwe: string;
|
|
1824
|
+
signature: string;
|
|
1825
|
+
version: number;
|
|
1826
|
+
cid?: string | undefined;
|
|
1827
|
+
}>;
|
|
1828
|
+
type DelegationApiResponse = z.infer<typeof DelegationApiResponseSchema>;
|
|
1829
|
+
/**
|
|
1830
|
+
* Input parameters for the createDelegation WASM function.
|
|
1831
|
+
*/
|
|
1832
|
+
declare const CreateDelegationWasmParamsSchema: z.ZodObject<{
|
|
1833
|
+
/** The session containing delegation credentials */
|
|
1834
|
+
session: z.ZodEffects<z.ZodUnknown, ServiceSession, unknown>;
|
|
1835
|
+
/** DID of the delegate */
|
|
1836
|
+
delegateDID: z.ZodString;
|
|
1837
|
+
/** Space ID this delegation applies to */
|
|
1838
|
+
spaceId: z.ZodString;
|
|
1839
|
+
/** Resource path this delegation grants access to */
|
|
1840
|
+
path: z.ZodString;
|
|
1841
|
+
/** Actions to authorize */
|
|
1842
|
+
actions: z.ZodArray<z.ZodString, "many">;
|
|
1843
|
+
/** Expiration time in seconds since Unix epoch */
|
|
1844
|
+
expirationSecs: z.ZodNumber;
|
|
1845
|
+
/** Optional not-before time in seconds since Unix epoch */
|
|
1846
|
+
notBeforeSecs: z.ZodOptional<z.ZodNumber>;
|
|
1847
|
+
}, "strip", z.ZodTypeAny, {
|
|
1848
|
+
path: string;
|
|
1849
|
+
spaceId: string;
|
|
1850
|
+
session: ServiceSession;
|
|
1851
|
+
delegateDID: string;
|
|
1852
|
+
actions: string[];
|
|
1853
|
+
expirationSecs: number;
|
|
1854
|
+
notBeforeSecs?: number | undefined;
|
|
1855
|
+
}, {
|
|
1856
|
+
path: string;
|
|
1857
|
+
spaceId: string;
|
|
1858
|
+
delegateDID: string;
|
|
1859
|
+
actions: string[];
|
|
1860
|
+
expirationSecs: number;
|
|
1861
|
+
session?: unknown;
|
|
1862
|
+
notBeforeSecs?: number | undefined;
|
|
1863
|
+
}>;
|
|
1864
|
+
type CreateDelegationWasmParams = z.infer<typeof CreateDelegationWasmParamsSchema>;
|
|
1865
|
+
/**
|
|
1866
|
+
* Result from the createDelegation WASM function.
|
|
1867
|
+
*/
|
|
1868
|
+
declare const CreateDelegationWasmResultSchema: z.ZodObject<{
|
|
1869
|
+
/** Base64url-encoded UCAN delegation */
|
|
1870
|
+
delegation: z.ZodString;
|
|
1871
|
+
/** CID of the delegation */
|
|
1872
|
+
cid: z.ZodString;
|
|
1873
|
+
/** DID of the delegate */
|
|
1874
|
+
delegateDID: z.ZodString;
|
|
1875
|
+
/** Resource path the delegation grants access to */
|
|
1876
|
+
path: z.ZodString;
|
|
1877
|
+
/** Actions the delegation authorizes */
|
|
1878
|
+
actions: z.ZodArray<z.ZodString, "many">;
|
|
1879
|
+
/** Expiration time */
|
|
1880
|
+
expiry: z.ZodDate;
|
|
1881
|
+
}, "strip", z.ZodTypeAny, {
|
|
1882
|
+
path: string;
|
|
1883
|
+
delegation: string;
|
|
1884
|
+
cid: string;
|
|
1885
|
+
delegateDID: string;
|
|
1886
|
+
actions: string[];
|
|
1887
|
+
expiry: Date;
|
|
1888
|
+
}, {
|
|
1889
|
+
path: string;
|
|
1890
|
+
delegation: string;
|
|
1891
|
+
cid: string;
|
|
1892
|
+
delegateDID: string;
|
|
1893
|
+
actions: string[];
|
|
1894
|
+
expiry: Date;
|
|
1895
|
+
}>;
|
|
1896
|
+
type CreateDelegationWasmResult = z.infer<typeof CreateDelegationWasmResultSchema>;
|
|
1897
|
+
|
|
1898
|
+
/**
|
|
1899
|
+
* CapabilityKeyRegistry - Tracks keys and their capabilities for automatic key selection.
|
|
1900
|
+
*
|
|
1901
|
+
* The registry maintains mappings between:
|
|
1902
|
+
* - Keys and their associated delegations
|
|
1903
|
+
* - Capabilities (resource/action pairs) and the keys that can exercise them
|
|
1904
|
+
*
|
|
1905
|
+
* This enables automatic key selection when performing operations, choosing
|
|
1906
|
+
* the most appropriate key based on priority and validity.
|
|
1907
|
+
*
|
|
1908
|
+
* @packageDocumentation
|
|
1909
|
+
*/
|
|
1910
|
+
|
|
1911
|
+
/**
|
|
1912
|
+
* Error codes specific to CapabilityKeyRegistry operations.
|
|
1913
|
+
*/
|
|
1914
|
+
declare const CapabilityKeyRegistryErrorCodes: {
|
|
1915
|
+
/** Key not found in registry */
|
|
1916
|
+
readonly KEY_NOT_FOUND: "KEY_NOT_FOUND";
|
|
1917
|
+
/** No key available for the requested capability */
|
|
1918
|
+
readonly NO_CAPABLE_KEY: "NO_CAPABLE_KEY";
|
|
1919
|
+
/** Delegation has expired */
|
|
1920
|
+
readonly DELEGATION_EXPIRED: "DELEGATION_EXPIRED";
|
|
1921
|
+
/** Delegation has been revoked */
|
|
1922
|
+
readonly DELEGATION_REVOKED: "DELEGATION_REVOKED";
|
|
1923
|
+
/** Invalid delegation data */
|
|
1924
|
+
readonly INVALID_DELEGATION: "INVALID_DELEGATION";
|
|
1925
|
+
/** Key already registered */
|
|
1926
|
+
readonly KEY_EXISTS: "KEY_EXISTS";
|
|
1927
|
+
};
|
|
1928
|
+
type CapabilityKeyRegistryErrorCode = (typeof CapabilityKeyRegistryErrorCodes)[keyof typeof CapabilityKeyRegistryErrorCodes];
|
|
1929
|
+
/**
|
|
1930
|
+
* Stored delegation with chain information.
|
|
1931
|
+
*/
|
|
1932
|
+
interface StoredDelegationChain {
|
|
1933
|
+
/** The delegation itself */
|
|
1934
|
+
delegation: Delegation;
|
|
1935
|
+
/** Parent delegation CID if this is a sub-delegation */
|
|
1936
|
+
parentCid?: string;
|
|
1937
|
+
/** Key ID used to sign/exercise this delegation */
|
|
1938
|
+
keyId: string;
|
|
1939
|
+
/** When this was stored */
|
|
1940
|
+
storedAt: Date;
|
|
1941
|
+
}
|
|
1942
|
+
/**
|
|
1943
|
+
* Interface for the CapabilityKeyRegistry.
|
|
1944
|
+
*
|
|
1945
|
+
* Tracks keys and their capabilities for automatic key selection.
|
|
1946
|
+
*/
|
|
1947
|
+
interface ICapabilityKeyRegistry {
|
|
1948
|
+
/**
|
|
1949
|
+
* Register a key with its associated delegations.
|
|
1950
|
+
*
|
|
1951
|
+
* @param key - Key information
|
|
1952
|
+
* @param delegations - Delegations granted to this key
|
|
1953
|
+
*/
|
|
1954
|
+
registerKey(key: KeyInfo, delegations: Delegation[]): void;
|
|
1955
|
+
/**
|
|
1956
|
+
* Remove a key and all its associated delegations.
|
|
1957
|
+
*
|
|
1958
|
+
* @param keyId - The key ID to remove
|
|
1959
|
+
*/
|
|
1960
|
+
removeKey(keyId: string): void;
|
|
1961
|
+
/**
|
|
1962
|
+
* Get a key that can exercise the specified capability.
|
|
1963
|
+
*
|
|
1964
|
+
* Uses the key selection algorithm:
|
|
1965
|
+
* 1. Filter keys that have the required capability
|
|
1966
|
+
* 2. Check delegation validity (not expired, not revoked)
|
|
1967
|
+
* 3. Sort by priority (session=0, main=1, ingested=2)
|
|
1968
|
+
* 4. Return highest priority valid key
|
|
1969
|
+
*
|
|
1970
|
+
* @param resource - Resource URI (e.g., "tinycloud://space-id/kv/my-data")
|
|
1971
|
+
* @param action - Action to perform (e.g., "tinycloud.kv/get")
|
|
1972
|
+
* @returns The best matching key, or null if none available
|
|
1973
|
+
*/
|
|
1974
|
+
getKeyForCapability(resource: string, action: string): KeyInfo | null;
|
|
1975
|
+
/**
|
|
1976
|
+
* Get all registered capabilities.
|
|
1977
|
+
*
|
|
1978
|
+
* @returns All capability entries in the registry
|
|
1979
|
+
*/
|
|
1980
|
+
getAllCapabilities(): CapabilityEntry[];
|
|
1981
|
+
/**
|
|
1982
|
+
* Get all delegations for a specific key.
|
|
1983
|
+
*
|
|
1984
|
+
* @param keyId - The key ID
|
|
1985
|
+
* @returns Array of delegations for this key
|
|
1986
|
+
*/
|
|
1987
|
+
getDelegationsForKey(keyId: string): Delegation[];
|
|
1988
|
+
/**
|
|
1989
|
+
* Ingest a key and delegation from an external source (e.g., sharing link).
|
|
1990
|
+
*
|
|
1991
|
+
* @param key - Key information to ingest
|
|
1992
|
+
* @param delegation - Delegation to associate with the key
|
|
1993
|
+
* @param options - Ingestion options
|
|
1994
|
+
*/
|
|
1995
|
+
ingestKey(key: KeyInfo, delegation: Delegation, options?: IngestOptions): void;
|
|
1996
|
+
/**
|
|
1997
|
+
* Check if a delegation is currently valid.
|
|
1998
|
+
*
|
|
1999
|
+
* @param delegation - The delegation to check
|
|
2000
|
+
* @returns true if valid, false if expired or revoked
|
|
2001
|
+
*/
|
|
2002
|
+
isDelegationValid(delegation: Delegation): boolean;
|
|
2003
|
+
/**
|
|
2004
|
+
* Get a key by its ID.
|
|
2005
|
+
*
|
|
2006
|
+
* @param keyId - The key ID
|
|
2007
|
+
* @returns The key info, or undefined if not found
|
|
2008
|
+
*/
|
|
2009
|
+
getKey(keyId: string): KeyInfo | undefined;
|
|
2010
|
+
/**
|
|
2011
|
+
* Get all registered keys.
|
|
2012
|
+
*
|
|
2013
|
+
* @returns Array of all registered keys
|
|
2014
|
+
*/
|
|
2015
|
+
getAllKeys(): KeyInfo[];
|
|
2016
|
+
/**
|
|
2017
|
+
* Clear all registered keys and delegations.
|
|
2018
|
+
*/
|
|
2019
|
+
clear(): void;
|
|
2020
|
+
/**
|
|
2021
|
+
* Revoke a delegation by CID.
|
|
2022
|
+
*
|
|
2023
|
+
* @param cid - The delegation CID to revoke
|
|
2024
|
+
* @returns Result indicating success or failure
|
|
2025
|
+
*/
|
|
2026
|
+
revokeDelegation(cid: string): Result$1<void, ServiceError>;
|
|
2027
|
+
/**
|
|
2028
|
+
* Find capabilities that match a resource path pattern.
|
|
2029
|
+
*
|
|
2030
|
+
* @param resourcePattern - Resource pattern (supports wildcards)
|
|
2031
|
+
* @param action - Optional action filter
|
|
2032
|
+
* @returns Matching capability entries
|
|
2033
|
+
*/
|
|
2034
|
+
findCapabilities(resourcePattern: string, action?: string): CapabilityEntry[];
|
|
2035
|
+
}
|
|
2036
|
+
/**
|
|
2037
|
+
* CapabilityKeyRegistry - Tracks keys and their capabilities for automatic key selection.
|
|
2038
|
+
*
|
|
2039
|
+
* @example
|
|
2040
|
+
* ```typescript
|
|
2041
|
+
* const registry = new CapabilityKeyRegistry();
|
|
2042
|
+
*
|
|
2043
|
+
* // Register a session key with its delegations
|
|
2044
|
+
* registry.registerKey(sessionKey, [rootDelegation]);
|
|
2045
|
+
*
|
|
2046
|
+
* // Get the best key for an operation
|
|
2047
|
+
* const key = registry.getKeyForCapability(
|
|
2048
|
+
* "tinycloud://my-space/kv/data",
|
|
2049
|
+
* "tinycloud.kv/get"
|
|
2050
|
+
* );
|
|
2051
|
+
*
|
|
2052
|
+
* if (key) {
|
|
2053
|
+
* // Use this key for the operation
|
|
2054
|
+
* console.log("Using key:", key.id);
|
|
2055
|
+
* }
|
|
2056
|
+
* ```
|
|
2057
|
+
*/
|
|
2058
|
+
declare class CapabilityKeyRegistry implements ICapabilityKeyRegistry {
|
|
2059
|
+
/**
|
|
2060
|
+
* Registry of all keys indexed by ID.
|
|
2061
|
+
*/
|
|
2062
|
+
private keys;
|
|
2063
|
+
/**
|
|
2064
|
+
* Delegation storage.
|
|
2065
|
+
*/
|
|
2066
|
+
private store;
|
|
2067
|
+
/**
|
|
2068
|
+
* Register a key with its associated delegations.
|
|
2069
|
+
*
|
|
2070
|
+
* @param key - Key information
|
|
2071
|
+
* @param delegations - Delegations granted to this key
|
|
2072
|
+
*/
|
|
2073
|
+
registerKey(key: KeyInfo, delegations: Delegation[]): void;
|
|
2074
|
+
/**
|
|
2075
|
+
* Remove a key and all its associated delegations.
|
|
2076
|
+
*
|
|
2077
|
+
* @param keyId - The key ID to remove
|
|
2078
|
+
*/
|
|
2079
|
+
removeKey(keyId: string): void;
|
|
2080
|
+
/**
|
|
2081
|
+
* Get a key that can exercise the specified capability.
|
|
2082
|
+
*
|
|
2083
|
+
* Key selection algorithm:
|
|
2084
|
+
* 1. Filter keys that have the required capability
|
|
2085
|
+
* 2. Check delegation validity (not expired, not revoked)
|
|
2086
|
+
* 3. Sort by priority (session=0, main=1, ingested=2)
|
|
2087
|
+
* 4. Return highest priority valid key
|
|
2088
|
+
*
|
|
2089
|
+
* @param resource - Resource URI
|
|
2090
|
+
* @param action - Action to perform
|
|
2091
|
+
* @returns The best matching key, or null if none available
|
|
2092
|
+
*/
|
|
2093
|
+
getKeyForCapability(resource: string, action: string): KeyInfo | null;
|
|
2094
|
+
/**
|
|
2095
|
+
* Get all registered capabilities.
|
|
2096
|
+
*
|
|
2097
|
+
* @returns All capability entries in the registry
|
|
2098
|
+
*/
|
|
2099
|
+
getAllCapabilities(): CapabilityEntry[];
|
|
2100
|
+
/**
|
|
2101
|
+
* Get all delegations for a specific key.
|
|
2102
|
+
*
|
|
2103
|
+
* @param keyId - The key ID
|
|
2104
|
+
* @returns Array of delegations for this key
|
|
2105
|
+
*/
|
|
2106
|
+
getDelegationsForKey(keyId: string): Delegation[];
|
|
2107
|
+
/**
|
|
2108
|
+
* Ingest a key and delegation from an external source.
|
|
2109
|
+
*
|
|
2110
|
+
* @param key - Key information to ingest
|
|
2111
|
+
* @param delegation - Delegation to associate with the key
|
|
2112
|
+
* @param options - Ingestion options
|
|
2113
|
+
*/
|
|
2114
|
+
ingestKey(key: KeyInfo, delegation: Delegation, options?: IngestOptions): void;
|
|
2115
|
+
/**
|
|
2116
|
+
* Check if a delegation is currently valid.
|
|
2117
|
+
*
|
|
2118
|
+
* @param delegation - The delegation to check
|
|
2119
|
+
* @returns true if valid, false if expired or revoked
|
|
2120
|
+
*/
|
|
2121
|
+
isDelegationValid(delegation: Delegation): boolean;
|
|
2122
|
+
/**
|
|
2123
|
+
* Get a key by its ID.
|
|
2124
|
+
*
|
|
2125
|
+
* @param keyId - The key ID
|
|
2126
|
+
* @returns The key info, or undefined if not found
|
|
2127
|
+
*/
|
|
2128
|
+
getKey(keyId: string): KeyInfo | undefined;
|
|
2129
|
+
/**
|
|
2130
|
+
* Get all registered keys.
|
|
2131
|
+
*
|
|
2132
|
+
* @returns Array of all registered keys
|
|
2133
|
+
*/
|
|
2134
|
+
getAllKeys(): KeyInfo[];
|
|
2135
|
+
/**
|
|
2136
|
+
* Clear all registered keys and delegations.
|
|
2137
|
+
*/
|
|
2138
|
+
clear(): void;
|
|
2139
|
+
/**
|
|
2140
|
+
* Revoke a delegation by CID.
|
|
2141
|
+
*
|
|
2142
|
+
* @param cid - The delegation CID to revoke
|
|
2143
|
+
* @returns Result indicating success or failure
|
|
2144
|
+
*/
|
|
2145
|
+
revokeDelegation(cid: string): Result$1<void, ServiceError>;
|
|
2146
|
+
/**
|
|
2147
|
+
* Find capabilities that match a resource path pattern.
|
|
2148
|
+
*
|
|
2149
|
+
* @param resourcePattern - Resource pattern (supports wildcards)
|
|
2150
|
+
* @param action - Optional action filter
|
|
2151
|
+
* @returns Matching capability entries
|
|
2152
|
+
*/
|
|
2153
|
+
findCapabilities(resourcePattern: string, action?: string): CapabilityEntry[];
|
|
2154
|
+
/**
|
|
2155
|
+
* Add a delegation to the store.
|
|
2156
|
+
*
|
|
2157
|
+
* @param key - The key associated with this delegation
|
|
2158
|
+
* @param delegation - The delegation to add
|
|
2159
|
+
*/
|
|
2160
|
+
private addDelegation;
|
|
2161
|
+
/**
|
|
2162
|
+
* Create a capability key for indexing.
|
|
2163
|
+
*
|
|
2164
|
+
* @param resource - Resource path
|
|
2165
|
+
* @param action - Action
|
|
2166
|
+
* @returns Combined key string
|
|
2167
|
+
*/
|
|
2168
|
+
private makeCapabilityKey;
|
|
2169
|
+
/**
|
|
2170
|
+
* Find capability entries that match a resource and action.
|
|
2171
|
+
*
|
|
2172
|
+
* @param resource - Resource to match
|
|
2173
|
+
* @param action - Action to match
|
|
2174
|
+
* @returns Matching entries
|
|
2175
|
+
*/
|
|
2176
|
+
private findMatchingEntries;
|
|
2177
|
+
/**
|
|
2178
|
+
* Check if an action pattern matches a specific action.
|
|
2179
|
+
*
|
|
2180
|
+
* @param pattern - Action pattern (may include wildcard like "tinycloud.kv/*")
|
|
2181
|
+
* @param action - Specific action to check
|
|
2182
|
+
* @returns true if pattern matches action
|
|
2183
|
+
*/
|
|
2184
|
+
private actionMatches;
|
|
2185
|
+
/**
|
|
2186
|
+
* Check if a resource matches a pattern.
|
|
2187
|
+
*
|
|
2188
|
+
* Patterns support:
|
|
2189
|
+
* - Exact match: "/kv/data" matches "/kv/data"
|
|
2190
|
+
* - Wildcard suffix: "/kv/*" matches "/kv/anything"
|
|
2191
|
+
* - Double wildcard: "/kv/**" matches "/kv/any/nested/path"
|
|
2192
|
+
*
|
|
2193
|
+
* @param resource - The specific resource being accessed
|
|
2194
|
+
* @param pattern - The pattern from the delegation
|
|
2195
|
+
* @returns true if resource matches pattern
|
|
2196
|
+
*/
|
|
2197
|
+
private resourceMatchesPattern;
|
|
2198
|
+
/**
|
|
2199
|
+
* Check if a specific resource matches a resource pattern for searching.
|
|
2200
|
+
*
|
|
2201
|
+
* @param entryResource - The resource from a capability entry
|
|
2202
|
+
* @param searchPattern - The pattern to search for
|
|
2203
|
+
* @returns true if entry resource matches search pattern
|
|
2204
|
+
*/
|
|
2205
|
+
private matchesResourcePattern;
|
|
2206
|
+
}
|
|
2207
|
+
/**
|
|
2208
|
+
* Create a new CapabilityKeyRegistry instance.
|
|
2209
|
+
*
|
|
2210
|
+
* @returns A new registry instance
|
|
2211
|
+
*/
|
|
2212
|
+
declare function createCapabilityKeyRegistry(): ICapabilityKeyRegistry;
|
|
2213
|
+
|
|
2214
|
+
/**
|
|
2215
|
+
* SignStrategy types for TinyCloud authorization.
|
|
2216
|
+
*
|
|
2217
|
+
* These types define how sign requests are handled across different
|
|
2218
|
+
* SDK implementations (web-sdk, node-sdk). The pattern allows for
|
|
2219
|
+
* automatic signing, rejection, callback-based approval, or event-driven
|
|
2220
|
+
* workflows.
|
|
2221
|
+
*
|
|
2222
|
+
* @packageDocumentation
|
|
2223
|
+
*/
|
|
2224
|
+
/**
|
|
2225
|
+
* Sign request passed to callback or event handlers.
|
|
2226
|
+
*/
|
|
2227
|
+
interface SignRequest {
|
|
2228
|
+
/** Ethereum address of the signer */
|
|
2229
|
+
address: string;
|
|
2230
|
+
/** Chain ID for the signing context */
|
|
2231
|
+
chainId: number;
|
|
2232
|
+
/** Message to be signed */
|
|
2233
|
+
message: string;
|
|
2234
|
+
/** Type of sign operation */
|
|
2235
|
+
type: "siwe" | "message";
|
|
2236
|
+
}
|
|
2237
|
+
/**
|
|
2238
|
+
* Sign response from callback or event handlers.
|
|
2239
|
+
*/
|
|
2240
|
+
interface SignResponse {
|
|
2241
|
+
/** Whether the sign request was approved */
|
|
2242
|
+
approved: boolean;
|
|
2243
|
+
/** The signature if approved */
|
|
2244
|
+
signature?: string;
|
|
2245
|
+
/** Reason for rejection if not approved */
|
|
2246
|
+
reason?: string;
|
|
2247
|
+
}
|
|
2248
|
+
/**
|
|
2249
|
+
* Callback handler type for sign requests.
|
|
2250
|
+
*/
|
|
2251
|
+
type SignCallback = (request: SignRequest) => Promise<SignResponse>;
|
|
2252
|
+
/**
|
|
2253
|
+
* Auto-sign strategy: automatically signs all requests.
|
|
2254
|
+
*
|
|
2255
|
+
* Use cases:
|
|
2256
|
+
* - Trusted backend services
|
|
2257
|
+
* - Automated scripts
|
|
2258
|
+
* - CI/CD pipelines
|
|
2259
|
+
*
|
|
2260
|
+
* @example
|
|
2261
|
+
* ```typescript
|
|
2262
|
+
* const strategy: AutoSignStrategy = { type: 'auto-sign' };
|
|
2263
|
+
* ```
|
|
2264
|
+
*/
|
|
2265
|
+
interface AutoSignStrategy {
|
|
2266
|
+
type: "auto-sign";
|
|
2267
|
+
}
|
|
2268
|
+
/**
|
|
2269
|
+
* Auto-reject strategy: rejects all sign requests.
|
|
2270
|
+
*
|
|
2271
|
+
* Use cases:
|
|
2272
|
+
* - Read-only applications
|
|
2273
|
+
* - Testing rejection flows
|
|
2274
|
+
*
|
|
2275
|
+
* @example
|
|
2276
|
+
* ```typescript
|
|
2277
|
+
* const strategy: AutoRejectStrategy = { type: 'auto-reject' };
|
|
2278
|
+
* ```
|
|
2279
|
+
*/
|
|
2280
|
+
interface AutoRejectStrategy {
|
|
2281
|
+
type: "auto-reject";
|
|
2282
|
+
}
|
|
2283
|
+
/**
|
|
2284
|
+
* Callback strategy: delegates sign decisions to a callback function.
|
|
2285
|
+
*
|
|
2286
|
+
* Use cases:
|
|
2287
|
+
* - CLI applications with user prompts
|
|
2288
|
+
* - Custom approval workflows
|
|
2289
|
+
* - Interactive sign flows
|
|
2290
|
+
*
|
|
2291
|
+
* @example
|
|
2292
|
+
* ```typescript
|
|
2293
|
+
* const strategy: CallbackStrategy = {
|
|
2294
|
+
* type: 'callback',
|
|
2295
|
+
* handler: async (req) => {
|
|
2296
|
+
* const approved = await promptUser(`Sign message for ${req.address}?`);
|
|
2297
|
+
* return { approved, signature: approved ? await signer.sign(req.message) : undefined };
|
|
2298
|
+
* }
|
|
2299
|
+
* };
|
|
2300
|
+
* ```
|
|
2301
|
+
*/
|
|
2302
|
+
interface CallbackStrategy {
|
|
2303
|
+
type: "callback";
|
|
2304
|
+
handler: SignCallback;
|
|
2305
|
+
}
|
|
2306
|
+
/**
|
|
2307
|
+
* Event emitter strategy: emits sign requests as events.
|
|
2308
|
+
*
|
|
2309
|
+
* Uses EventTarget for cross-platform compatibility (browser + Node.js).
|
|
2310
|
+
*
|
|
2311
|
+
* Events emitted:
|
|
2312
|
+
* - 'sign-request': When a sign request is received
|
|
2313
|
+
*
|
|
2314
|
+
* Use cases:
|
|
2315
|
+
* - Async approval workflows
|
|
2316
|
+
* - External signing services
|
|
2317
|
+
* - Multi-step authorization flows
|
|
2318
|
+
*
|
|
2319
|
+
* @example
|
|
2320
|
+
* ```typescript
|
|
2321
|
+
* const emitter = new EventTarget();
|
|
2322
|
+
* const strategy: EventEmitterStrategy = { type: 'event-emitter', emitter };
|
|
2323
|
+
*
|
|
2324
|
+
* emitter.addEventListener('sign-request', async (event) => {
|
|
2325
|
+
* const { request, respond } = (event as CustomEvent).detail;
|
|
2326
|
+
* const approved = await externalApprovalService.check(request);
|
|
2327
|
+
* respond({ approved, signature: approved ? await sign(request.message) : undefined });
|
|
2328
|
+
* });
|
|
2329
|
+
* ```
|
|
2330
|
+
*/
|
|
2331
|
+
interface EventEmitterStrategy {
|
|
2332
|
+
type: "event-emitter";
|
|
2333
|
+
emitter: EventTarget;
|
|
2334
|
+
/** Timeout in milliseconds for waiting on event response (default: 60000) */
|
|
2335
|
+
timeout?: number;
|
|
2336
|
+
}
|
|
2337
|
+
/**
|
|
2338
|
+
* Sign strategy union type.
|
|
2339
|
+
*
|
|
2340
|
+
* Determines how sign requests are handled in UserAuthorization implementations.
|
|
2341
|
+
*/
|
|
2342
|
+
type SignStrategy = AutoSignStrategy | AutoRejectStrategy | CallbackStrategy | EventEmitterStrategy;
|
|
2343
|
+
/**
|
|
2344
|
+
* Default sign strategy is auto-sign for convenience.
|
|
2345
|
+
*/
|
|
2346
|
+
declare const defaultSignStrategy: SignStrategy;
|
|
2347
|
+
|
|
2348
|
+
/**
|
|
2349
|
+
* Space creation handler types for TinyCloud authorization.
|
|
2350
|
+
*
|
|
2351
|
+
* These types abstract space creation confirmation, allowing different
|
|
2352
|
+
* implementations for web (modal) vs node (auto-approve) environments.
|
|
2353
|
+
*
|
|
2354
|
+
* @packageDocumentation
|
|
2355
|
+
*/
|
|
2356
|
+
/**
|
|
2357
|
+
* Context passed to space creation handlers.
|
|
2358
|
+
*/
|
|
2359
|
+
interface SpaceCreationContext {
|
|
2360
|
+
/** The unique identifier for the space being created */
|
|
2361
|
+
spaceId: string;
|
|
2362
|
+
/** Ethereum address of the user creating the space */
|
|
2363
|
+
address: string;
|
|
2364
|
+
/** Chain ID for the creation context */
|
|
2365
|
+
chainId: number;
|
|
2366
|
+
/** Host URL where the space will be created */
|
|
2367
|
+
host: string;
|
|
2368
|
+
}
|
|
2369
|
+
/**
|
|
2370
|
+
* Interface for handling space creation confirmation.
|
|
2371
|
+
*
|
|
2372
|
+
* Implementations can provide different UX patterns:
|
|
2373
|
+
* - Auto-approve for backend services
|
|
2374
|
+
* - Modal confirmation for web apps
|
|
2375
|
+
* - CLI prompts for terminal apps
|
|
2376
|
+
*
|
|
2377
|
+
* @example
|
|
2378
|
+
* ```typescript
|
|
2379
|
+
* class ModalSpaceCreationHandler implements ISpaceCreationHandler {
|
|
2380
|
+
* async confirmSpaceCreation(context: SpaceCreationContext): Promise<boolean> {
|
|
2381
|
+
* return await showConfirmationModal(`Create space ${context.spaceId}?`);
|
|
2382
|
+
* }
|
|
2383
|
+
*
|
|
2384
|
+
* onSpaceCreated(context: SpaceCreationContext): void {
|
|
2385
|
+
* showToast(`Space ${context.spaceId} created!`);
|
|
2386
|
+
* }
|
|
2387
|
+
*
|
|
2388
|
+
* onSpaceCreationFailed(context: SpaceCreationContext, error: Error): void {
|
|
2389
|
+
* showErrorModal(`Failed to create space: ${error.message}`);
|
|
2390
|
+
* }
|
|
2391
|
+
* }
|
|
2392
|
+
* ```
|
|
2393
|
+
*/
|
|
2394
|
+
interface ISpaceCreationHandler {
|
|
2395
|
+
/**
|
|
2396
|
+
* Called when a new space needs to be created.
|
|
2397
|
+
* Returns true if space should be created, false to skip.
|
|
2398
|
+
*
|
|
2399
|
+
* @param context - Information about the space to be created
|
|
2400
|
+
* @returns Promise resolving to true to proceed, false to cancel
|
|
2401
|
+
*/
|
|
2402
|
+
confirmSpaceCreation(context: SpaceCreationContext): Promise<boolean>;
|
|
2403
|
+
/**
|
|
2404
|
+
* Called after successful space creation.
|
|
2405
|
+
* Optional - implement to show success UI or perform cleanup.
|
|
2406
|
+
*
|
|
2407
|
+
* @param context - Information about the created space
|
|
2408
|
+
*/
|
|
2409
|
+
onSpaceCreated?(context: SpaceCreationContext): void;
|
|
2410
|
+
/**
|
|
2411
|
+
* Called if space creation fails.
|
|
2412
|
+
* Optional - implement to show error UI or perform recovery.
|
|
2413
|
+
*
|
|
2414
|
+
* @param context - Information about the space that failed to create
|
|
2415
|
+
* @param error - The error that occurred
|
|
2416
|
+
*/
|
|
2417
|
+
onSpaceCreationFailed?(context: SpaceCreationContext, error: Error): void;
|
|
2418
|
+
}
|
|
2419
|
+
/**
|
|
2420
|
+
* Default handler that auto-approves all space creation.
|
|
2421
|
+
*
|
|
2422
|
+
* Use cases:
|
|
2423
|
+
* - Backend services
|
|
2424
|
+
* - Automated scripts
|
|
2425
|
+
* - Node.js applications without UI
|
|
2426
|
+
*
|
|
2427
|
+
* @example
|
|
2428
|
+
* ```typescript
|
|
2429
|
+
* const handler = new AutoApproveSpaceCreationHandler();
|
|
2430
|
+
* const config = { spaceCreationHandler: handler };
|
|
2431
|
+
* ```
|
|
2432
|
+
*/
|
|
2433
|
+
declare class AutoApproveSpaceCreationHandler implements ISpaceCreationHandler {
|
|
2434
|
+
/**
|
|
2435
|
+
* Always returns true to auto-approve space creation.
|
|
2436
|
+
*/
|
|
2437
|
+
confirmSpaceCreation(): Promise<boolean>;
|
|
2438
|
+
}
|
|
2439
|
+
/**
|
|
2440
|
+
* Default space creation handler that auto-approves all requests.
|
|
2441
|
+
*/
|
|
2442
|
+
declare const defaultSpaceCreationHandler: ISpaceCreationHandler;
|
|
2443
|
+
|
|
2444
|
+
/**
|
|
2445
|
+
* Interface for an extension to TCW.
|
|
2446
|
+
* This is the platform-agnostic subset — browser-coupled extensions
|
|
2447
|
+
* (IConnected, ConfigOverrides, ExtraFields) live in web-sdk/providers.
|
|
2448
|
+
*/
|
|
2449
|
+
interface Extension {
|
|
2450
|
+
/** [recap] Capability namespace. */
|
|
2451
|
+
namespace?: string;
|
|
2452
|
+
/** [recap] Default delegated actions in capability namespace. */
|
|
2453
|
+
defaultActions?(): Promise<string[]>;
|
|
2454
|
+
/** [recap] Delegated actions by target in capability namespace. */
|
|
2455
|
+
targetedActions?(): Promise<{
|
|
2456
|
+
[target: string]: string[];
|
|
2457
|
+
}>;
|
|
2458
|
+
/** [recap] Extra metadata to help validate the capability. */
|
|
2459
|
+
extraFields?(): Promise<Record<string, unknown>>;
|
|
2460
|
+
/** Hook to run after TCW has signed in. */
|
|
2461
|
+
afterSignIn?(session: ClientSession): Promise<void>;
|
|
2462
|
+
}
|
|
2463
|
+
/**
|
|
2464
|
+
* Partial SIWE message for overrides.
|
|
2465
|
+
*/
|
|
2466
|
+
interface PartialSiweMessage extends Partial<SiweConfig> {
|
|
2467
|
+
address?: string;
|
|
2468
|
+
chainId?: number;
|
|
2469
|
+
uri?: string;
|
|
2470
|
+
version?: string;
|
|
2471
|
+
}
|
|
2472
|
+
/**
|
|
2473
|
+
* Platform-agnostic user authorization interface.
|
|
2474
|
+
*
|
|
2475
|
+
* This interface defines how users authenticate and manage sessions.
|
|
2476
|
+
* Implementations differ by platform:
|
|
2477
|
+
* - WebUserAuthorization: Browser with wallet popups
|
|
2478
|
+
* - NodeUserAuthorization: Node.js with configurable sign strategies
|
|
2479
|
+
*/
|
|
2480
|
+
interface IUserAuthorization {
|
|
2481
|
+
/**
|
|
2482
|
+
* The current active session, if signed in.
|
|
2483
|
+
*/
|
|
2484
|
+
session?: ClientSession;
|
|
2485
|
+
/**
|
|
2486
|
+
* Add an extension to the authorization flow.
|
|
2487
|
+
* Extensions can add capabilities and lifecycle hooks.
|
|
2488
|
+
*/
|
|
2489
|
+
extend(extension: Extension): void;
|
|
2490
|
+
/**
|
|
2491
|
+
* Sign in and create a new session.
|
|
2492
|
+
* This will prompt for wallet signature (browser) or use configured strategy (node).
|
|
2493
|
+
* @returns The new session
|
|
2494
|
+
*/
|
|
2495
|
+
signIn(): Promise<ClientSession>;
|
|
2496
|
+
/**
|
|
2497
|
+
* Sign out and clear the current session.
|
|
2498
|
+
*/
|
|
2499
|
+
signOut(): Promise<void>;
|
|
2500
|
+
/**
|
|
2501
|
+
* Get the current wallet/signer address.
|
|
2502
|
+
* @returns Address or undefined if not connected
|
|
2503
|
+
*/
|
|
2504
|
+
address(): string | undefined;
|
|
2505
|
+
/**
|
|
2506
|
+
* Get the current chain ID.
|
|
2507
|
+
* @returns Chain ID or undefined if not connected
|
|
2508
|
+
*/
|
|
2509
|
+
chainId(): number | undefined;
|
|
2510
|
+
/**
|
|
2511
|
+
* Sign a message with the connected wallet/signer.
|
|
2512
|
+
* @param message - Message to sign
|
|
2513
|
+
* @returns Signature hex string
|
|
2514
|
+
*/
|
|
2515
|
+
signMessage(message: string): Promise<string>;
|
|
2516
|
+
/**
|
|
2517
|
+
* Get the current space ID.
|
|
2518
|
+
* @returns Space ID or undefined if not available
|
|
2519
|
+
*/
|
|
2520
|
+
getSpaceId?(): string | undefined;
|
|
2521
|
+
/**
|
|
2522
|
+
* Ensure the user's space exists on the TinyCloud server.
|
|
2523
|
+
* Creates the space if it doesn't exist (when autoCreateSpace is true).
|
|
2524
|
+
* This is called automatically during sign-in but can be invoked manually.
|
|
2525
|
+
*/
|
|
2526
|
+
ensureSpaceExists?(): Promise<void>;
|
|
2527
|
+
}
|
|
2528
|
+
/**
|
|
2529
|
+
* Configuration for creating a UserAuthorization instance.
|
|
2530
|
+
*/
|
|
2531
|
+
interface UserAuthorizationConfig {
|
|
2532
|
+
/** The signer to use for signing */
|
|
2533
|
+
signer: ISigner;
|
|
2534
|
+
/** Session storage implementation */
|
|
2535
|
+
sessionStorage?: ISessionStorage;
|
|
2536
|
+
/** Default SIWE configuration */
|
|
2537
|
+
siweConfig?: SiweConfig;
|
|
2538
|
+
/** Domain for SIWE messages */
|
|
2539
|
+
domain?: string;
|
|
2540
|
+
/** Extensions to apply */
|
|
2541
|
+
extensions?: Extension[];
|
|
2542
|
+
/** Strategy for handling sign requests (default: auto-sign for node, callback for web) */
|
|
2543
|
+
signStrategy?: SignStrategy;
|
|
2544
|
+
/** Handler for space creation confirmation (default: AutoApproveSpaceCreationHandler) */
|
|
2545
|
+
spaceCreationHandler?: ISpaceCreationHandler;
|
|
2546
|
+
/** Whether to automatically create space if it doesn't exist */
|
|
2547
|
+
autoCreateSpace?: boolean;
|
|
2548
|
+
/** Space name prefix (default: "default") */
|
|
2549
|
+
spacePrefix?: string;
|
|
2550
|
+
/** TinyCloud host URLs */
|
|
2551
|
+
tinycloudHosts?: string[];
|
|
2552
|
+
/** Session expiration in milliseconds */
|
|
2553
|
+
sessionExpirationMs?: number;
|
|
2554
|
+
}
|
|
2555
|
+
|
|
2556
|
+
/**
|
|
2557
|
+
* Configuration for the TinyCloud SDK.
|
|
2558
|
+
*/
|
|
2559
|
+
interface TinyCloudConfig {
|
|
2560
|
+
/** Whether to automatically resolve ENS names */
|
|
2561
|
+
resolveEns?: boolean;
|
|
2562
|
+
/**
|
|
2563
|
+
* TinyCloud host URLs.
|
|
2564
|
+
* Required when using services.
|
|
2565
|
+
*/
|
|
2566
|
+
hosts?: string[];
|
|
2567
|
+
/**
|
|
2568
|
+
* Platform-specific invoke function from WASM binding.
|
|
2569
|
+
* Required when using services.
|
|
2570
|
+
*/
|
|
2571
|
+
invoke?: InvokeFunction;
|
|
2572
|
+
/**
|
|
2573
|
+
* Custom fetch implementation.
|
|
2574
|
+
* Defaults to globalThis.fetch.
|
|
2575
|
+
*/
|
|
2576
|
+
fetch?: FetchFunction;
|
|
2577
|
+
/**
|
|
2578
|
+
* Service constructors to register.
|
|
2579
|
+
* Built-in services (like KVService) are registered by default unless overridden.
|
|
2580
|
+
*
|
|
2581
|
+
* @example
|
|
2582
|
+
* ```typescript
|
|
2583
|
+
* services: {
|
|
2584
|
+
* kv: KVService, // default
|
|
2585
|
+
* files: MyFileService, // custom
|
|
2586
|
+
* }
|
|
2587
|
+
* ```
|
|
2588
|
+
*/
|
|
2589
|
+
services?: Record<string, ServiceConstructor>;
|
|
2590
|
+
/**
|
|
2591
|
+
* Per-service configuration.
|
|
2592
|
+
*
|
|
2593
|
+
* @example
|
|
2594
|
+
* ```typescript
|
|
2595
|
+
* serviceConfigs: {
|
|
2596
|
+
* kv: { prefix: 'myapp' },
|
|
2597
|
+
* files: { maxSize: 10_000_000 },
|
|
2598
|
+
* }
|
|
2599
|
+
* ```
|
|
2600
|
+
*/
|
|
2601
|
+
serviceConfigs?: Record<string, Record<string, unknown>>;
|
|
2602
|
+
/**
|
|
2603
|
+
* Retry policy for service operations.
|
|
2604
|
+
*/
|
|
2605
|
+
retryPolicy?: Partial<RetryPolicy>;
|
|
2606
|
+
}
|
|
2607
|
+
/**
|
|
2608
|
+
* TinyCloud SDK - Unified entry point for web and node.
|
|
2609
|
+
*
|
|
2610
|
+
* This class provides the main SDK interface. Platform-specific behavior
|
|
2611
|
+
* is injected through the IUserAuthorization implementation:
|
|
2612
|
+
* - WebUserAuthorization for browser environments
|
|
2613
|
+
* - NodeUserAuthorization for Node.js environments
|
|
2614
|
+
*
|
|
2615
|
+
* @example
|
|
2616
|
+
* ```typescript
|
|
2617
|
+
* // Web usage
|
|
2618
|
+
* import { TinyCloud } from '@tinycloud/sdk-core';
|
|
2619
|
+
* import { WebUserAuthorization } from '@tinycloud/web-sdk';
|
|
2620
|
+
*
|
|
2621
|
+
* const auth = new WebUserAuthorization({ ... });
|
|
2622
|
+
* const tc = new TinyCloud(auth);
|
|
2623
|
+
* await tc.signIn();
|
|
2624
|
+
* const result = await tc.kv.put('key', 'value');
|
|
2625
|
+
*
|
|
2626
|
+
* // Node usage
|
|
2627
|
+
* import { TinyCloud } from '@tinycloud/sdk-core';
|
|
2628
|
+
* import { NodeUserAuthorization, PrivateKeySigner } from '@tinycloud/node-sdk';
|
|
2629
|
+
*
|
|
2630
|
+
* const signer = new PrivateKeySigner(process.env.PRIVATE_KEY);
|
|
2631
|
+
* const auth = new NodeUserAuthorization({
|
|
2632
|
+
* signStrategy: { type: 'auto-sign' },
|
|
2633
|
+
* signer,
|
|
2634
|
+
* domain: 'api.myapp.com'
|
|
2635
|
+
* });
|
|
2636
|
+
* const tc = new TinyCloud(auth);
|
|
2637
|
+
* await tc.signIn();
|
|
2638
|
+
* ```
|
|
2639
|
+
*/
|
|
2640
|
+
declare class TinyCloud {
|
|
2641
|
+
/**
|
|
2642
|
+
* User authorization handler.
|
|
2643
|
+
* Provides authentication and signing capabilities.
|
|
2644
|
+
*/
|
|
2645
|
+
readonly userAuthorization: IUserAuthorization;
|
|
2646
|
+
/**
|
|
2647
|
+
* SDK configuration.
|
|
2648
|
+
*/
|
|
2649
|
+
private config;
|
|
2650
|
+
/**
|
|
2651
|
+
* Registered extensions.
|
|
2652
|
+
*/
|
|
2653
|
+
private extensions;
|
|
2654
|
+
/**
|
|
2655
|
+
* Service context providing platform dependencies to services.
|
|
2656
|
+
*/
|
|
2657
|
+
private _serviceContext?;
|
|
2658
|
+
/**
|
|
2659
|
+
* Registered services by name.
|
|
2660
|
+
*/
|
|
2661
|
+
private _services;
|
|
2662
|
+
/**
|
|
2663
|
+
* Whether services have been initialized.
|
|
2664
|
+
*/
|
|
2665
|
+
private _servicesInitialized;
|
|
2666
|
+
/**
|
|
2667
|
+
* Create a new TinyCloud SDK instance.
|
|
2668
|
+
*
|
|
2669
|
+
* @param userAuthorization - Platform-specific authorization implementation
|
|
2670
|
+
* @param config - Optional SDK configuration
|
|
2671
|
+
*/
|
|
2672
|
+
constructor(userAuthorization: IUserAuthorization, config?: TinyCloudConfig);
|
|
2673
|
+
/**
|
|
2674
|
+
* Initialize services with platform dependencies.
|
|
2675
|
+
* Must be called before using services.
|
|
2676
|
+
*
|
|
2677
|
+
* @param invoke - Platform-specific invoke function from WASM binding
|
|
2678
|
+
* @param hosts - TinyCloud host URLs (optional, uses config.hosts)
|
|
2679
|
+
* @param fetchFn - Custom fetch implementation (optional)
|
|
2680
|
+
*/
|
|
2681
|
+
initializeServices(invoke?: InvokeFunction, hosts?: string[], fetchFn?: FetchFunction): void;
|
|
2682
|
+
/**
|
|
2683
|
+
* Get the service context.
|
|
2684
|
+
* @throws Error if services are not initialized
|
|
2685
|
+
*/
|
|
2686
|
+
get serviceContext(): IServiceContext;
|
|
2687
|
+
/**
|
|
2688
|
+
* Get a registered service by name.
|
|
2689
|
+
*
|
|
2690
|
+
* @param name - Service name (e.g., 'kv')
|
|
2691
|
+
* @returns The service instance or undefined
|
|
2692
|
+
*/
|
|
2693
|
+
getService<T extends IService>(name: string): T | undefined;
|
|
2694
|
+
/**
|
|
2695
|
+
* Get the KV service.
|
|
2696
|
+
* @throws Error if services are not initialized
|
|
2697
|
+
*/
|
|
2698
|
+
get kv(): IKVService;
|
|
2699
|
+
/**
|
|
2700
|
+
* Get the SQL service.
|
|
2701
|
+
* @throws Error if services are not initialized
|
|
2702
|
+
*/
|
|
2703
|
+
get sql(): ISQLService;
|
|
2704
|
+
/**
|
|
2705
|
+
* Get the DuckDB service.
|
|
2706
|
+
* @throws Error if services are not initialized
|
|
2707
|
+
*/
|
|
2708
|
+
get duckdb(): IDuckDbService;
|
|
2709
|
+
/**
|
|
2710
|
+
* Get the Data Vault service.
|
|
2711
|
+
* @throws Error if services are not initialized or vault service is not registered
|
|
2712
|
+
*/
|
|
2713
|
+
get vault(): IDataVaultService;
|
|
2714
|
+
/**
|
|
2715
|
+
* Notify services of session change.
|
|
2716
|
+
* Called internally after sign-in and sign-out.
|
|
2717
|
+
*
|
|
2718
|
+
* @param session - The new session, or null if signed out
|
|
2719
|
+
*/
|
|
2720
|
+
private notifyServicesOfSessionChange;
|
|
2721
|
+
/**
|
|
2722
|
+
* Abort all pending service operations.
|
|
2723
|
+
* Called internally before sign-out.
|
|
2724
|
+
*/
|
|
2725
|
+
private abortServiceOperations;
|
|
2726
|
+
/**
|
|
2727
|
+
* Convert ClientSession to ServiceSession.
|
|
2728
|
+
* Returns null if session lacks required fields.
|
|
2729
|
+
*/
|
|
2730
|
+
private toServiceSession;
|
|
2731
|
+
/**
|
|
2732
|
+
* Add an extension to the SDK.
|
|
2733
|
+
* Extensions can add capabilities and lifecycle hooks.
|
|
2734
|
+
*/
|
|
2735
|
+
extend(extension: Extension): void;
|
|
2736
|
+
/**
|
|
2737
|
+
* Check if an extension is enabled.
|
|
2738
|
+
* @param namespace - The extension namespace to check
|
|
2739
|
+
*/
|
|
2740
|
+
isExtensionEnabled(namespace: string): boolean;
|
|
2741
|
+
/**
|
|
2742
|
+
* Get the current session, if signed in.
|
|
2743
|
+
*/
|
|
2744
|
+
get session(): ClientSession | undefined;
|
|
2745
|
+
/**
|
|
2746
|
+
* Check if the user is signed in.
|
|
2747
|
+
*/
|
|
2748
|
+
get isSignedIn(): boolean;
|
|
2749
|
+
/**
|
|
2750
|
+
* Sign in and create a new session.
|
|
2751
|
+
* Notifies services of the new session after successful sign-in.
|
|
2752
|
+
* @returns The new session
|
|
2753
|
+
*/
|
|
2754
|
+
signIn(): Promise<ClientSession>;
|
|
2755
|
+
/**
|
|
2756
|
+
* Sign out and clear the current session.
|
|
2757
|
+
* Aborts pending service operations and notifies services.
|
|
2758
|
+
*/
|
|
2759
|
+
signOut(): Promise<void>;
|
|
2760
|
+
/**
|
|
2761
|
+
* Get the current wallet address.
|
|
2762
|
+
*/
|
|
2763
|
+
address(): string | undefined;
|
|
2764
|
+
/**
|
|
2765
|
+
* Get the current chain ID.
|
|
2766
|
+
*/
|
|
2767
|
+
chainId(): number | undefined;
|
|
2768
|
+
/**
|
|
2769
|
+
* Sign a message with the connected wallet.
|
|
2770
|
+
* @param message - Message to sign
|
|
2771
|
+
*/
|
|
2772
|
+
signMessage(message: string): Promise<string>;
|
|
2773
|
+
/**
|
|
2774
|
+
* Cached public KV service instance.
|
|
2775
|
+
*/
|
|
2776
|
+
private _publicKV?;
|
|
2777
|
+
/**
|
|
2778
|
+
* Construct the deterministic public space ID for a given address and chain ID.
|
|
2779
|
+
*
|
|
2780
|
+
* @param address - Ethereum address (0x-prefixed)
|
|
2781
|
+
* @param chainId - Chain ID (e.g., 1 for mainnet)
|
|
2782
|
+
* @returns The public space ID
|
|
2783
|
+
*/
|
|
2784
|
+
static makePublicSpaceId(address: string, chainId: number): string;
|
|
2785
|
+
/**
|
|
2786
|
+
* Ensure the user's public space exists.
|
|
2787
|
+
* Creates it via spaces.create('public') if it doesn't.
|
|
2788
|
+
* Called automatically by modules that need to publish data.
|
|
2789
|
+
*
|
|
2790
|
+
* Requires the user to be signed in and services to be initialized.
|
|
2791
|
+
*/
|
|
2792
|
+
ensurePublicSpace(): Promise<Result$1<void, ServiceError>>;
|
|
2793
|
+
/**
|
|
2794
|
+
* Get a KVService scoped to the user's own public space.
|
|
2795
|
+
* Writes require authentication (owner/delegate).
|
|
2796
|
+
*
|
|
2797
|
+
* @throws Error if not signed in or services not initialized
|
|
2798
|
+
*/
|
|
2799
|
+
get publicKV(): IKVService;
|
|
2800
|
+
/**
|
|
2801
|
+
* Read from any user's public space (unauthenticated).
|
|
2802
|
+
* Uses the public REST endpoint — no session needed.
|
|
2803
|
+
*
|
|
2804
|
+
* @param host - TinyCloud server URL (e.g., "https://node.tinycloud.xyz")
|
|
2805
|
+
* @param spaceId - Full public space ID
|
|
2806
|
+
* @param key - Key to read
|
|
2807
|
+
* @param fetchFn - Optional custom fetch function
|
|
2808
|
+
* @returns The data at the key
|
|
2809
|
+
*/
|
|
2810
|
+
static readPublicSpace<T = unknown>(host: string, spaceId: string, key: string, fetchFn?: FetchFunction): Promise<Result$1<T, ServiceError>>;
|
|
2811
|
+
/**
|
|
2812
|
+
* Read from any user's public space by address (unauthenticated).
|
|
2813
|
+
* Convenience method that constructs the space ID from address and chain ID.
|
|
2814
|
+
*
|
|
2815
|
+
* @param host - TinyCloud server URL
|
|
2816
|
+
* @param address - Ethereum address (0x-prefixed)
|
|
2817
|
+
* @param chainId - Chain ID (e.g., 1 for mainnet)
|
|
2818
|
+
* @param key - Key to read
|
|
2819
|
+
* @param fetchFn - Optional custom fetch function
|
|
2820
|
+
* @returns The data at the key
|
|
2821
|
+
*/
|
|
2822
|
+
static readPublicKey<T = unknown>(host: string, address: string, chainId: number, key: string, fetchFn?: FetchFunction): Promise<Result$1<T, ServiceError>>;
|
|
2823
|
+
}
|
|
2824
|
+
|
|
2825
|
+
/**
|
|
2826
|
+
* Shared space utilities for TinyCloud.
|
|
2827
|
+
*
|
|
2828
|
+
* These functions are platform-agnostic and can be used by both
|
|
2829
|
+
* web-sdk and node-sdk for space hosting and session activation.
|
|
2830
|
+
*/
|
|
2831
|
+
/**
|
|
2832
|
+
* Result of a space hosting or session activation attempt.
|
|
2833
|
+
*/
|
|
2834
|
+
interface SpaceHostResult {
|
|
2835
|
+
/** Whether the operation succeeded (2xx status) */
|
|
2836
|
+
success: boolean;
|
|
2837
|
+
/** HTTP status code */
|
|
2838
|
+
status: number;
|
|
2839
|
+
/** Error message if failed */
|
|
2840
|
+
error?: string;
|
|
2841
|
+
/** Space IDs that were successfully activated */
|
|
2842
|
+
activated?: string[];
|
|
2843
|
+
/** Space IDs that were skipped (e.g., space doesn't exist yet) */
|
|
2844
|
+
skipped?: string[];
|
|
2845
|
+
}
|
|
2846
|
+
/**
|
|
2847
|
+
* Fetch the peer ID from TinyCloud server for space hosting.
|
|
2848
|
+
*
|
|
2849
|
+
* The peer ID identifies the TinyCloud server instance that will host the space.
|
|
2850
|
+
*
|
|
2851
|
+
* @param host - TinyCloud server URL (e.g., "https://node.tinycloud.xyz")
|
|
2852
|
+
* @param spaceId - The space ID to host
|
|
2853
|
+
* @returns The peer ID string
|
|
2854
|
+
* @throws Error if the request fails
|
|
2855
|
+
*/
|
|
2856
|
+
declare function fetchPeerId(host: string, spaceId: string): Promise<string>;
|
|
2857
|
+
/**
|
|
2858
|
+
* Submit a space hosting delegation to TinyCloud server.
|
|
2859
|
+
*
|
|
2860
|
+
* This registers a new space with the server, allowing the user
|
|
2861
|
+
* to store data in it.
|
|
2862
|
+
*
|
|
2863
|
+
* @param host - TinyCloud server URL
|
|
2864
|
+
* @param headers - Delegation headers (from siweToDelegationHeaders)
|
|
2865
|
+
* @returns Result indicating success/failure
|
|
2866
|
+
*/
|
|
2867
|
+
declare function submitHostDelegation(host: string, headers: Record<string, string>): Promise<SpaceHostResult>;
|
|
2868
|
+
/**
|
|
2869
|
+
* Activate a session with TinyCloud server.
|
|
2870
|
+
*
|
|
2871
|
+
* This submits the session delegation to the server, enabling the session
|
|
2872
|
+
* key to perform operations on behalf of the user.
|
|
2873
|
+
*
|
|
2874
|
+
* @param host - TinyCloud server URL
|
|
2875
|
+
* @param delegationHeader - Session delegation header (from session.delegationHeader)
|
|
2876
|
+
* @returns Result indicating success/failure (404 means space doesn't exist)
|
|
2877
|
+
*/
|
|
2878
|
+
declare function activateSessionWithHost(host: string, delegationHeader: {
|
|
2879
|
+
Authorization: string;
|
|
2880
|
+
}): Promise<SpaceHostResult>;
|
|
2881
|
+
|
|
2882
|
+
/**
|
|
2883
|
+
* DelegationManager - Handles delegation CRUD operations.
|
|
2884
|
+
*
|
|
2885
|
+
* This class manages the creation, revocation, listing, and querying
|
|
2886
|
+
* of delegations within TinyCloud. It extracts and improves upon the
|
|
2887
|
+
* delegation functionality previously in ITinyCloudStorage.
|
|
2888
|
+
*
|
|
2889
|
+
* @packageDocumentation
|
|
2890
|
+
*/
|
|
2891
|
+
|
|
2892
|
+
/**
|
|
2893
|
+
* DelegationManager handles all delegation-related operations.
|
|
2894
|
+
*
|
|
2895
|
+
* @example
|
|
2896
|
+
* ```typescript
|
|
2897
|
+
* import { DelegationManager } from "@tinycloud/sdk-core/delegations";
|
|
2898
|
+
*
|
|
2899
|
+
* const delegations = new DelegationManager({
|
|
2900
|
+
* hosts: ["https://node.tinycloud.xyz"],
|
|
2901
|
+
* session,
|
|
2902
|
+
* invoke,
|
|
2903
|
+
* });
|
|
2904
|
+
*
|
|
2905
|
+
* // Create a delegation
|
|
2906
|
+
* const result = await delegations.create({
|
|
2907
|
+
* delegateDID: "did:pkh:eip155:1:0x...",
|
|
2908
|
+
* path: "shared/",
|
|
2909
|
+
* actions: ["tinycloud.kv/get", "tinycloud.kv/list"],
|
|
2910
|
+
* expiry: new Date(Date.now() + 24 * 60 * 60 * 1000), // 24 hours
|
|
2911
|
+
* });
|
|
2912
|
+
*
|
|
2913
|
+
* if (result.ok) {
|
|
2914
|
+
* console.log("Created delegation:", result.data.cid);
|
|
2915
|
+
* }
|
|
2916
|
+
* ```
|
|
2917
|
+
*/
|
|
2918
|
+
declare class DelegationManager {
|
|
2919
|
+
private hosts;
|
|
2920
|
+
private session;
|
|
2921
|
+
private invoke;
|
|
2922
|
+
private fetchFn;
|
|
2923
|
+
/**
|
|
2924
|
+
* Creates a new DelegationManager instance.
|
|
2925
|
+
*
|
|
2926
|
+
* @param config - Configuration including hosts, session, and invoke function
|
|
2927
|
+
*/
|
|
2928
|
+
constructor(config: DelegationManagerConfig);
|
|
2929
|
+
/**
|
|
2930
|
+
* Updates the session (e.g., after re-authentication).
|
|
2931
|
+
*
|
|
2932
|
+
* @param session - New session to use for operations
|
|
2933
|
+
*/
|
|
2934
|
+
updateSession(session: ServiceSession): void;
|
|
2935
|
+
/**
|
|
2936
|
+
* Gets the primary host URL.
|
|
2937
|
+
*/
|
|
2938
|
+
private get host();
|
|
2939
|
+
/**
|
|
2940
|
+
* Executes an invoke operation against the delegation API.
|
|
2941
|
+
*/
|
|
2942
|
+
private invokeOperation;
|
|
2943
|
+
/**
|
|
2944
|
+
* Creates a new delegation.
|
|
2945
|
+
*
|
|
2946
|
+
* Delegates specific permissions to another DID for a given path.
|
|
2947
|
+
* The delegatee can then use these permissions to access resources
|
|
2948
|
+
* within the specified scope.
|
|
2949
|
+
*
|
|
2950
|
+
* @param params - Parameters for the delegation
|
|
2951
|
+
* @returns Result containing the created Delegation or an error
|
|
2952
|
+
*
|
|
2953
|
+
* @example
|
|
2954
|
+
* ```typescript
|
|
2955
|
+
* const result = await manager.create({
|
|
2956
|
+
* delegateDID: bob.did,
|
|
2957
|
+
* path: "documents/shared/",
|
|
2958
|
+
* actions: ["tinycloud.kv/get", "tinycloud.kv/put"],
|
|
2959
|
+
* expiry: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000), // 7 days
|
|
2960
|
+
* });
|
|
2961
|
+
* ```
|
|
2962
|
+
*/
|
|
2963
|
+
create(params: CreateDelegationParams): Promise<Result<Delegation>>;
|
|
2964
|
+
/**
|
|
2965
|
+
* Revokes an existing delegation.
|
|
2966
|
+
*
|
|
2967
|
+
* Once revoked, the delegation can no longer be used to access resources.
|
|
2968
|
+
* This also invalidates any sub-delegations derived from this delegation.
|
|
2969
|
+
*
|
|
2970
|
+
* @param cid - The CID of the delegation to revoke
|
|
2971
|
+
* @returns Result indicating success or an error
|
|
2972
|
+
*
|
|
2973
|
+
* @example
|
|
2974
|
+
* ```typescript
|
|
2975
|
+
* const result = await manager.revoke("bafy...");
|
|
2976
|
+
* if (result.ok) {
|
|
2977
|
+
* console.log("Delegation revoked successfully");
|
|
2978
|
+
* }
|
|
2979
|
+
* ```
|
|
2980
|
+
*/
|
|
2981
|
+
revoke(cid: string): Promise<Result<void>>;
|
|
2982
|
+
/**
|
|
2983
|
+
* Lists all delegations for the current session's space.
|
|
2984
|
+
*
|
|
2985
|
+
* Returns both delegations created by the current user (as delegator)
|
|
2986
|
+
* and delegations granted to the current user (as delegatee).
|
|
2987
|
+
*
|
|
2988
|
+
* @returns Result containing an array of Delegations or an error
|
|
2989
|
+
*
|
|
2990
|
+
* @example
|
|
2991
|
+
* ```typescript
|
|
2992
|
+
* const result = await manager.list();
|
|
2993
|
+
* if (result.ok) {
|
|
2994
|
+
* for (const delegation of result.data) {
|
|
2995
|
+
* console.log(`${delegation.cid}: ${delegation.path} -> ${delegation.delegateDID}`);
|
|
2996
|
+
* }
|
|
2997
|
+
* }
|
|
2998
|
+
* ```
|
|
2999
|
+
*/
|
|
3000
|
+
list(): Promise<Result<Delegation[]>>;
|
|
3001
|
+
/**
|
|
3002
|
+
* Gets the full delegation chain for a given delegation.
|
|
3003
|
+
*
|
|
3004
|
+
* Returns the chain of delegations from the root (original delegator)
|
|
3005
|
+
* to the specified delegation, including all intermediate sub-delegations.
|
|
3006
|
+
*
|
|
3007
|
+
* @param cid - The CID of the delegation to get the chain for
|
|
3008
|
+
* @returns Result containing the DelegationChain or an error
|
|
3009
|
+
*
|
|
3010
|
+
* @example
|
|
3011
|
+
* ```typescript
|
|
3012
|
+
* const result = await manager.getChain("bafy...");
|
|
3013
|
+
* if (result.ok) {
|
|
3014
|
+
* console.log("Chain length:", result.data.length);
|
|
3015
|
+
* for (const delegation of result.data) {
|
|
3016
|
+
* console.log(`- ${delegation.delegatorDID} -> ${delegation.delegateDID}`);
|
|
3017
|
+
* }
|
|
3018
|
+
* }
|
|
3019
|
+
* ```
|
|
3020
|
+
*/
|
|
3021
|
+
getChain(cid: string): Promise<Result<DelegationChain>>;
|
|
3022
|
+
/**
|
|
3023
|
+
* Checks if the current session has permission for a given path and action.
|
|
3024
|
+
*
|
|
3025
|
+
* This can be used to verify permissions before attempting an operation,
|
|
3026
|
+
* or to implement custom access control logic.
|
|
3027
|
+
*
|
|
3028
|
+
* @param path - The resource path to check
|
|
3029
|
+
* @param action - The action to check (e.g., "tinycloud.kv/get")
|
|
3030
|
+
* @returns Result containing a boolean indicating permission or an error
|
|
3031
|
+
*
|
|
3032
|
+
* @example
|
|
3033
|
+
* ```typescript
|
|
3034
|
+
* const result = await manager.checkPermission("documents/private/", "tinycloud.kv/put");
|
|
3035
|
+
* if (result.ok && result.data) {
|
|
3036
|
+
* console.log("Permission granted");
|
|
3037
|
+
* } else {
|
|
3038
|
+
* console.log("Permission denied");
|
|
3039
|
+
* }
|
|
3040
|
+
* ```
|
|
3041
|
+
*/
|
|
3042
|
+
checkPermission(path: string, action: string): Promise<Result<boolean>>;
|
|
3043
|
+
}
|
|
3044
|
+
|
|
3045
|
+
/**
|
|
3046
|
+
* SharingService - v2 sharing link service with embedded private keys.
|
|
5
3047
|
*
|
|
6
|
-
* This
|
|
7
|
-
*
|
|
8
|
-
*
|
|
3048
|
+
* This service implements the v2 sharing specification, which embeds private keys
|
|
3049
|
+
* directly in sharing links. This allows recipients to exercise delegations
|
|
3050
|
+
* without requiring prior session setup.
|
|
3051
|
+
*
|
|
3052
|
+
* Key differences from v1 SharingLinks:
|
|
3053
|
+
* - Private keys are embedded in the link (not just tokens)
|
|
3054
|
+
* - Recipients can optionally sub-delegate to their own session key
|
|
3055
|
+
* - Pre-configured KV service returned for immediate use
|
|
3056
|
+
*
|
|
3057
|
+
* @packageDocumentation
|
|
3058
|
+
*/
|
|
3059
|
+
|
|
3060
|
+
/**
|
|
3061
|
+
* Data encoded in a sharing link.
|
|
3062
|
+
*/
|
|
3063
|
+
interface EncodedShareData {
|
|
3064
|
+
/** Private key in JWK format (includes d parameter) */
|
|
3065
|
+
key: JWK;
|
|
3066
|
+
/** DID of the key */
|
|
3067
|
+
keyDid: string;
|
|
3068
|
+
/** The delegation granting access */
|
|
3069
|
+
delegation: Delegation;
|
|
3070
|
+
/** Resource path this link grants access to */
|
|
3071
|
+
path: string;
|
|
3072
|
+
/** TinyCloud host URL */
|
|
3073
|
+
host: string;
|
|
3074
|
+
/** Space ID */
|
|
3075
|
+
spaceId: string;
|
|
3076
|
+
/** Schema version */
|
|
3077
|
+
version: 1;
|
|
3078
|
+
}
|
|
3079
|
+
/**
|
|
3080
|
+
* Options for receiving a sharing link.
|
|
3081
|
+
*/
|
|
3082
|
+
interface ReceiveOptions {
|
|
3083
|
+
/**
|
|
3084
|
+
* Whether to automatically create a sub-delegation to the current session key.
|
|
3085
|
+
* Default: true
|
|
3086
|
+
*/
|
|
3087
|
+
autoSubdelegate?: boolean;
|
|
3088
|
+
/**
|
|
3089
|
+
* Whether to use the current session key for operations (requires autoSubdelegate).
|
|
3090
|
+
* Default: true
|
|
3091
|
+
*/
|
|
3092
|
+
useSessionKey?: boolean;
|
|
3093
|
+
/**
|
|
3094
|
+
* Ingestion options passed to CapabilityKeyRegistry.
|
|
3095
|
+
*/
|
|
3096
|
+
ingestOptions?: IngestOptions;
|
|
3097
|
+
}
|
|
3098
|
+
/**
|
|
3099
|
+
* Result of receiving a sharing link.
|
|
3100
|
+
*/
|
|
3101
|
+
interface ShareAccess {
|
|
3102
|
+
/** The delegation that was received/created */
|
|
3103
|
+
delegation: Delegation;
|
|
3104
|
+
/** Key info for the received key */
|
|
3105
|
+
key: KeyInfo;
|
|
3106
|
+
/** Pre-configured KV service for the shared path */
|
|
3107
|
+
kv: IKVService;
|
|
3108
|
+
/** The space ID */
|
|
3109
|
+
spaceId: string;
|
|
3110
|
+
/** The path prefix for this share */
|
|
3111
|
+
path: string;
|
|
3112
|
+
}
|
|
3113
|
+
/**
|
|
3114
|
+
* Configuration for SharingService.
|
|
3115
|
+
*/
|
|
3116
|
+
interface SharingServiceConfig {
|
|
3117
|
+
/** TinyCloud host URLs */
|
|
3118
|
+
hosts: string[];
|
|
3119
|
+
/**
|
|
3120
|
+
* Active session for authentication.
|
|
3121
|
+
* Required for generate(), optional for receive().
|
|
3122
|
+
*/
|
|
3123
|
+
session?: ServiceSession;
|
|
3124
|
+
/** Platform-specific invoke function */
|
|
3125
|
+
invoke: InvokeFunction;
|
|
3126
|
+
/** Optional custom fetch implementation */
|
|
3127
|
+
fetch?: FetchFunction;
|
|
3128
|
+
/** Key provider for cryptographic operations */
|
|
3129
|
+
keyProvider: KeyProvider;
|
|
3130
|
+
/** Capability key registry for key/delegation management */
|
|
3131
|
+
registry: ICapabilityKeyRegistry;
|
|
3132
|
+
/**
|
|
3133
|
+
* Delegation manager for creating delegations (used if createDelegation not provided).
|
|
3134
|
+
* Required for generate(), optional for receive().
|
|
3135
|
+
*/
|
|
3136
|
+
delegationManager?: DelegationManager;
|
|
3137
|
+
/** Factory for creating KV service instances */
|
|
3138
|
+
createKVService: (config: {
|
|
3139
|
+
hosts: string[];
|
|
3140
|
+
session: ServiceSession;
|
|
3141
|
+
invoke: InvokeFunction;
|
|
3142
|
+
fetch?: FetchFunction;
|
|
3143
|
+
pathPrefix?: string;
|
|
3144
|
+
}) => IKVService;
|
|
3145
|
+
/** Base URL for sharing links (e.g., "https://share.myapp.com") */
|
|
3146
|
+
baseUrl?: string;
|
|
3147
|
+
/**
|
|
3148
|
+
* Custom delegation creation function. When provided, this is used instead
|
|
3149
|
+
* of delegationManager.create(). This allows platforms to use their own
|
|
3150
|
+
* delegation creation logic (e.g., SIWE-based /delegate endpoint).
|
|
3151
|
+
*/
|
|
3152
|
+
createDelegation?: (params: CreateDelegationParams) => Promise<Result<Delegation, DelegationError>>;
|
|
3153
|
+
/**
|
|
3154
|
+
* WASM function for client-side delegation creation.
|
|
3155
|
+
* When provided, this is preferred over server-side creation (createDelegation/delegationManager).
|
|
3156
|
+
* Creates UCAN delegations directly without requiring server roundtrip.
|
|
3157
|
+
*/
|
|
3158
|
+
createDelegationWasm?: (params: CreateDelegationWasmParams) => CreateDelegationWasmResult;
|
|
3159
|
+
/**
|
|
3160
|
+
* Path prefix for KV operations.
|
|
3161
|
+
* When set, paths passed to generate() are prefixed with this value.
|
|
3162
|
+
* This ensures the share path matches the session's authorized paths.
|
|
3163
|
+
*/
|
|
3164
|
+
pathPrefix?: string;
|
|
3165
|
+
/**
|
|
3166
|
+
* Session expiry time.
|
|
3167
|
+
* When set, sharing link expiry is clamped to not exceed this value
|
|
3168
|
+
* unless onRootDelegationNeeded is provided and returns a new delegation.
|
|
3169
|
+
*/
|
|
3170
|
+
sessionExpiry?: Date;
|
|
3171
|
+
/**
|
|
3172
|
+
* Callback to create a DIRECT delegation from the root (wallet) to a share key.
|
|
3173
|
+
* This bypasses the session delegation chain, allowing share links with
|
|
3174
|
+
* expiry longer than the current session.
|
|
3175
|
+
*
|
|
3176
|
+
* When provided and share expiry > session expiry:
|
|
3177
|
+
* 1. SharingService creates the ephemeral share key
|
|
3178
|
+
* 2. This callback is invoked with the share key DID
|
|
3179
|
+
* 3. The callback signs a direct PKH -> share key delegation with the wallet
|
|
3180
|
+
* 4. The returned delegation is used for the share link
|
|
3181
|
+
*
|
|
3182
|
+
* This is the CORRECT solution for long-lived share links because:
|
|
3183
|
+
* - It creates a fresh delegation chain: PKH -> share key
|
|
3184
|
+
* - Not constrained by session expiry (no sub-delegation from session key)
|
|
3185
|
+
*
|
|
3186
|
+
* @param params - Parameters for creating the root delegation
|
|
3187
|
+
* @returns The delegation from wallet to share key, or undefined to fall back to session extension
|
|
3188
|
+
*/
|
|
3189
|
+
onRootDelegationNeeded?: (params: {
|
|
3190
|
+
/** DID of the share key to delegate to */
|
|
3191
|
+
shareKeyDID: string;
|
|
3192
|
+
/** Space ID */
|
|
3193
|
+
spaceId: string;
|
|
3194
|
+
/** Path to grant access to */
|
|
3195
|
+
path: string;
|
|
3196
|
+
/** Actions to grant */
|
|
3197
|
+
actions: string[];
|
|
3198
|
+
/** Requested expiry time */
|
|
3199
|
+
requestedExpiry: Date;
|
|
3200
|
+
}) => Promise<Delegation | undefined>;
|
|
3201
|
+
}
|
|
3202
|
+
/**
|
|
3203
|
+
* Interface for the SharingService.
|
|
3204
|
+
*/
|
|
3205
|
+
interface ISharingService {
|
|
3206
|
+
/**
|
|
3207
|
+
* Generate a sharing link with an embedded private key.
|
|
3208
|
+
*
|
|
3209
|
+
* This creates a new session key, delegates to it, and encodes
|
|
3210
|
+
* the key and delegation into a shareable link.
|
|
3211
|
+
*/
|
|
3212
|
+
generate(params: GenerateShareParams): Promise<Result<ShareLink, DelegationError>>;
|
|
3213
|
+
/**
|
|
3214
|
+
* Receive and activate a sharing link.
|
|
3215
|
+
*
|
|
3216
|
+
* Decodes the link, ingests the key into the registry, and optionally
|
|
3217
|
+
* creates a sub-delegation to the current session key.
|
|
3218
|
+
*/
|
|
3219
|
+
receive(link: string, options?: ReceiveOptions): Promise<Result<ShareAccess, DelegationError>>;
|
|
3220
|
+
/**
|
|
3221
|
+
* Encode sharing data into a link string.
|
|
3222
|
+
*/
|
|
3223
|
+
encodeLink(data: EncodedShareData, schema?: ShareSchema): string;
|
|
3224
|
+
/**
|
|
3225
|
+
* Decode a link string into sharing data.
|
|
3226
|
+
*/
|
|
3227
|
+
decodeLink(link: string): EncodedShareData;
|
|
3228
|
+
}
|
|
3229
|
+
/**
|
|
3230
|
+
* SharingService - v2 sharing link service with embedded private keys.
|
|
3231
|
+
*
|
|
3232
|
+
* @example
|
|
3233
|
+
* ```typescript
|
|
3234
|
+
* import { SharingService } from "@tinycloud/sdk-core/delegations";
|
|
3235
|
+
*
|
|
3236
|
+
* const sharing = new SharingService({
|
|
3237
|
+
* hosts: ["https://node.tinycloud.xyz"],
|
|
3238
|
+
* session,
|
|
3239
|
+
* invoke,
|
|
3240
|
+
* keyProvider,
|
|
3241
|
+
* registry,
|
|
3242
|
+
* delegationManager,
|
|
3243
|
+
* createKVService,
|
|
3244
|
+
* baseUrl: "https://share.myapp.com"
|
|
3245
|
+
* });
|
|
3246
|
+
*
|
|
3247
|
+
* // Generate a sharing link
|
|
3248
|
+
* const result = await sharing.generate({
|
|
3249
|
+
* path: "/kv/documents/report.pdf",
|
|
3250
|
+
* actions: ["tinycloud.kv/get"],
|
|
3251
|
+
* expiry: new Date("2024-12-31")
|
|
3252
|
+
* });
|
|
3253
|
+
*
|
|
3254
|
+
* if (result.ok) {
|
|
3255
|
+
* console.log("Share this URL:", result.data.url);
|
|
3256
|
+
* }
|
|
3257
|
+
*
|
|
3258
|
+
* // Receive a sharing link
|
|
3259
|
+
* const receiveResult = await sharing.receive(shareUrl);
|
|
3260
|
+
* if (receiveResult.ok) {
|
|
3261
|
+
* // Use the pre-configured KV service
|
|
3262
|
+
* const data = await receiveResult.data.kv.get("report.pdf");
|
|
3263
|
+
* }
|
|
3264
|
+
* ```
|
|
3265
|
+
*/
|
|
3266
|
+
declare class SharingService implements ISharingService {
|
|
3267
|
+
private hosts;
|
|
3268
|
+
private session?;
|
|
3269
|
+
private invoke;
|
|
3270
|
+
private fetchFn;
|
|
3271
|
+
private keyProvider;
|
|
3272
|
+
private registry;
|
|
3273
|
+
private delegationManager?;
|
|
3274
|
+
private createKVService;
|
|
3275
|
+
private baseUrl;
|
|
3276
|
+
private createDelegationFn?;
|
|
3277
|
+
private createDelegationWasmFn?;
|
|
3278
|
+
private pathPrefix;
|
|
3279
|
+
private sessionExpiry?;
|
|
3280
|
+
private onRootDelegationNeeded?;
|
|
3281
|
+
/**
|
|
3282
|
+
* Creates a new SharingService instance.
|
|
3283
|
+
*/
|
|
3284
|
+
constructor(config: SharingServiceConfig);
|
|
3285
|
+
/**
|
|
3286
|
+
* Gets the primary host URL.
|
|
3287
|
+
*/
|
|
3288
|
+
private get host();
|
|
3289
|
+
/**
|
|
3290
|
+
* Updates the session (e.g., after re-authentication).
|
|
3291
|
+
*/
|
|
3292
|
+
updateSession(session: ServiceSession): void;
|
|
3293
|
+
/**
|
|
3294
|
+
* Updates the service configuration.
|
|
3295
|
+
* Used to add full capabilities (session, delegationManager, createDelegation, createDelegationWasm) after signIn.
|
|
3296
|
+
*/
|
|
3297
|
+
updateConfig(config: Partial<Pick<SharingServiceConfig, "session" | "delegationManager" | "createDelegation" | "createDelegationWasm" | "sessionExpiry" | "onRootDelegationNeeded">>): void;
|
|
3298
|
+
/**
|
|
3299
|
+
* Generate a sharing link with an embedded private key.
|
|
3300
|
+
*
|
|
3301
|
+
* Flow:
|
|
3302
|
+
* 1. Spawn new session key (unique per share)
|
|
3303
|
+
* 2. Create delegation from current session to spawned key
|
|
3304
|
+
* 3. Package: { key (with private!), delegation, path, host }
|
|
3305
|
+
* 4. Encode based on schema (base64 for now)
|
|
3306
|
+
* 5. Return link string
|
|
3307
|
+
*/
|
|
3308
|
+
generate(params: GenerateShareParams): Promise<Result<ShareLink, DelegationError>>;
|
|
3309
|
+
/**
|
|
3310
|
+
* Check if any key in the registry can satisfy the delegation request.
|
|
3311
|
+
* A key can satisfy if it has a delegation that:
|
|
3312
|
+
* 1. Covers the required path (exact match or parent path)
|
|
3313
|
+
* 2. Has all required actions
|
|
3314
|
+
* 3. Has sufficient expiry (delegation.expiry >= requestedExpiry)
|
|
3315
|
+
* 4. Allows sub-delegation
|
|
3316
|
+
* @internal
|
|
3317
|
+
*/
|
|
3318
|
+
private findSuitableKeyForDelegation;
|
|
3319
|
+
/**
|
|
3320
|
+
* Check if a delegation path matches/covers the requested path.
|
|
3321
|
+
* A delegation path covers the request if:
|
|
3322
|
+
* - It's an exact match
|
|
3323
|
+
* - It's a parent path (e.g., delegation for "" covers "foo/bar")
|
|
3324
|
+
* - It uses wildcards that match
|
|
3325
|
+
* @internal
|
|
3326
|
+
*/
|
|
3327
|
+
private pathMatches;
|
|
3328
|
+
/**
|
|
3329
|
+
* Handle fallback to session extension when root delegation is not available.
|
|
3330
|
+
* @internal
|
|
3331
|
+
*/
|
|
3332
|
+
private handleSessionExtensionFallback;
|
|
3333
|
+
/**
|
|
3334
|
+
* Create a delegation from the current session to a share key.
|
|
3335
|
+
* This is the fallback path when root delegation is not available.
|
|
3336
|
+
* @internal
|
|
3337
|
+
*/
|
|
3338
|
+
private createSessionDelegation;
|
|
3339
|
+
/**
|
|
3340
|
+
* Receive and activate a sharing link.
|
|
3341
|
+
*
|
|
3342
|
+
* Flow:
|
|
3343
|
+
* 1. Decode link -> extract { key, delegation, path, host }
|
|
3344
|
+
* 2. Ingest key into CapabilityKeyRegistry
|
|
3345
|
+
* 3. If autoSubdelegate (default true) + useSessionKey:
|
|
3346
|
+
* - Create sub-delegation from ingested key -> current session
|
|
3347
|
+
* - Register sub-delegation capabilities
|
|
3348
|
+
* 4. Return ShareAccess with pre-configured KV service
|
|
3349
|
+
*/
|
|
3350
|
+
receive(link: string, options?: ReceiveOptions): Promise<Result<ShareAccess, DelegationError>>;
|
|
3351
|
+
/**
|
|
3352
|
+
* Encode sharing data into a link string.
|
|
3353
|
+
*
|
|
3354
|
+
* @param data - The share data to encode
|
|
3355
|
+
* @param schema - The encoding schema (default: "base64")
|
|
3356
|
+
* @returns Encoded link string
|
|
3357
|
+
*/
|
|
3358
|
+
encodeLink(data: EncodedShareData, schema?: ShareSchema): string;
|
|
3359
|
+
/**
|
|
3360
|
+
* Decode a link string into sharing data.
|
|
3361
|
+
*
|
|
3362
|
+
* @param link - The encoded link string (may include URL prefix)
|
|
3363
|
+
* @returns Decoded share data
|
|
3364
|
+
* @throws Error if link format is invalid or data fails validation
|
|
3365
|
+
*/
|
|
3366
|
+
decodeLink(link: string): EncodedShareData;
|
|
3367
|
+
/**
|
|
3368
|
+
* Decode and validate a link string into sharing data.
|
|
3369
|
+
*
|
|
3370
|
+
* Internal method that returns a Result instead of throwing.
|
|
3371
|
+
* Used by receive() for proper error handling.
|
|
3372
|
+
*
|
|
3373
|
+
* @param link - The encoded link string (may include URL prefix)
|
|
3374
|
+
* @returns Result with decoded share data or validation error
|
|
3375
|
+
*/
|
|
3376
|
+
private decodeLinkWithValidation;
|
|
3377
|
+
}
|
|
3378
|
+
/**
|
|
3379
|
+
* Create a new SharingService instance.
|
|
3380
|
+
*/
|
|
3381
|
+
declare function createSharingService(config: SharingServiceConfig): ISharingService;
|
|
3382
|
+
|
|
3383
|
+
/**
|
|
3384
|
+
* Interface for space-scoped delegation operations.
|
|
3385
|
+
*
|
|
3386
|
+
* Provides delegation management scoped to a specific space.
|
|
3387
|
+
*/
|
|
3388
|
+
interface ISpaceScopedDelegations {
|
|
3389
|
+
/**
|
|
3390
|
+
* List delegations created by the user in this space (outgoing).
|
|
3391
|
+
*/
|
|
3392
|
+
list(): Promise<Result$1<Delegation[], ServiceError>>;
|
|
3393
|
+
/**
|
|
3394
|
+
* List delegations received by the user for this space (incoming).
|
|
3395
|
+
*/
|
|
3396
|
+
listReceived(): Promise<Result$1<Delegation[], ServiceError>>;
|
|
3397
|
+
/**
|
|
3398
|
+
* Create a delegation within this space.
|
|
3399
|
+
*/
|
|
3400
|
+
create(params: Omit<CreateDelegationParams, "spaceId">): Promise<Result$1<Delegation, ServiceError>>;
|
|
3401
|
+
/**
|
|
3402
|
+
* Revoke a delegation within this space.
|
|
3403
|
+
*/
|
|
3404
|
+
revoke(cid: string): Promise<Result$1<void, ServiceError>>;
|
|
3405
|
+
}
|
|
3406
|
+
/**
|
|
3407
|
+
* Interface for space-scoped sharing operations.
|
|
3408
|
+
*
|
|
3409
|
+
* Provides sharing link management scoped to a specific space.
|
|
3410
|
+
*/
|
|
3411
|
+
interface ISpaceScopedSharing {
|
|
3412
|
+
/**
|
|
3413
|
+
* Generate a sharing link for a resource in this space.
|
|
3414
|
+
*/
|
|
3415
|
+
generate(params: Omit<GenerateShareParams, "spaceId">): Promise<Result$1<ShareLink, ServiceError>>;
|
|
3416
|
+
/**
|
|
3417
|
+
* List active sharing links in this space.
|
|
3418
|
+
*/
|
|
3419
|
+
list(): Promise<Result$1<ShareLink[], ServiceError>>;
|
|
3420
|
+
/**
|
|
3421
|
+
* Revoke a sharing link.
|
|
3422
|
+
*/
|
|
3423
|
+
revoke(token: string): Promise<Result$1<void, ServiceError>>;
|
|
3424
|
+
}
|
|
3425
|
+
/**
|
|
3426
|
+
* Interface for a Space object.
|
|
3427
|
+
*
|
|
3428
|
+
* Provides scoped access to services within a specific space.
|
|
3429
|
+
*/
|
|
3430
|
+
interface ISpace {
|
|
3431
|
+
/**
|
|
3432
|
+
* The space identifier.
|
|
3433
|
+
*/
|
|
3434
|
+
readonly id: string;
|
|
3435
|
+
/**
|
|
3436
|
+
* The short name of the space.
|
|
3437
|
+
*/
|
|
3438
|
+
readonly name: string;
|
|
3439
|
+
/**
|
|
3440
|
+
* KV operations scoped to this space.
|
|
3441
|
+
*/
|
|
3442
|
+
readonly kv: IKVService;
|
|
3443
|
+
/**
|
|
3444
|
+
* Delegation operations scoped to this space.
|
|
3445
|
+
*/
|
|
3446
|
+
readonly delegations: ISpaceScopedDelegations;
|
|
3447
|
+
/**
|
|
3448
|
+
* Sharing operations scoped to this space.
|
|
3449
|
+
*/
|
|
3450
|
+
readonly sharing: ISpaceScopedSharing;
|
|
3451
|
+
/**
|
|
3452
|
+
* Get space metadata.
|
|
3453
|
+
*/
|
|
3454
|
+
info(): Promise<Result$1<SpaceInfo, ServiceError>>;
|
|
3455
|
+
}
|
|
3456
|
+
/**
|
|
3457
|
+
* Configuration for creating a Space object.
|
|
3458
|
+
*/
|
|
3459
|
+
interface SpaceConfig {
|
|
3460
|
+
/**
|
|
3461
|
+
* The space identifier (full URI).
|
|
3462
|
+
*/
|
|
3463
|
+
id: string;
|
|
3464
|
+
/**
|
|
3465
|
+
* The short name of the space.
|
|
3466
|
+
*/
|
|
3467
|
+
name: string;
|
|
3468
|
+
/**
|
|
3469
|
+
* Factory function to create a space-scoped KV service.
|
|
3470
|
+
*/
|
|
3471
|
+
createKV: (spaceId: string) => IKVService;
|
|
3472
|
+
/**
|
|
3473
|
+
* Factory function to create space-scoped delegations.
|
|
3474
|
+
*/
|
|
3475
|
+
createDelegations: (spaceId: string) => ISpaceScopedDelegations;
|
|
3476
|
+
/**
|
|
3477
|
+
* Factory function to create space-scoped sharing.
|
|
3478
|
+
*/
|
|
3479
|
+
createSharing: (spaceId: string) => ISpaceScopedSharing;
|
|
3480
|
+
/**
|
|
3481
|
+
* Function to get space info.
|
|
3482
|
+
*/
|
|
3483
|
+
getInfo: (spaceId: string) => Promise<Result$1<SpaceInfo, ServiceError>>;
|
|
3484
|
+
}
|
|
3485
|
+
/**
|
|
3486
|
+
* Space - Provides scoped access to services within a specific space.
|
|
3487
|
+
*
|
|
3488
|
+
* @example
|
|
3489
|
+
* ```typescript
|
|
3490
|
+
* const space = sdk.space('default');
|
|
3491
|
+
*
|
|
3492
|
+
* // KV operations scoped to this space
|
|
3493
|
+
* await space.kv.put('key', 'value');
|
|
3494
|
+
* const result = await space.kv.get('key');
|
|
3495
|
+
*
|
|
3496
|
+
* // Delegation operations scoped to this space
|
|
3497
|
+
* await space.delegations.create({
|
|
3498
|
+
* delegateDID: 'did:pkh:eip155:1:0x...',
|
|
3499
|
+
* path: '/shared/',
|
|
3500
|
+
* actions: ['tinycloud.kv/get']
|
|
3501
|
+
* });
|
|
3502
|
+
*
|
|
3503
|
+
* // Get space metadata
|
|
3504
|
+
* const info = await space.info();
|
|
3505
|
+
* ```
|
|
3506
|
+
*/
|
|
3507
|
+
declare class Space implements ISpace {
|
|
3508
|
+
private readonly _id;
|
|
3509
|
+
private readonly _name;
|
|
3510
|
+
private readonly _kv;
|
|
3511
|
+
private readonly _delegations;
|
|
3512
|
+
private readonly _sharing;
|
|
3513
|
+
private readonly _getInfo;
|
|
3514
|
+
/**
|
|
3515
|
+
* Create a new Space instance.
|
|
3516
|
+
*
|
|
3517
|
+
* @param config - Space configuration
|
|
3518
|
+
*/
|
|
3519
|
+
constructor(config: SpaceConfig);
|
|
3520
|
+
/**
|
|
3521
|
+
* The space identifier (full URI).
|
|
3522
|
+
*/
|
|
3523
|
+
get id(): string;
|
|
3524
|
+
/**
|
|
3525
|
+
* The short name of the space.
|
|
3526
|
+
*/
|
|
3527
|
+
get name(): string;
|
|
3528
|
+
/**
|
|
3529
|
+
* KV operations scoped to this space.
|
|
3530
|
+
*/
|
|
3531
|
+
get kv(): IKVService;
|
|
3532
|
+
/**
|
|
3533
|
+
* Delegation operations scoped to this space.
|
|
3534
|
+
*/
|
|
3535
|
+
get delegations(): ISpaceScopedDelegations;
|
|
3536
|
+
/**
|
|
3537
|
+
* Sharing operations scoped to this space.
|
|
3538
|
+
*/
|
|
3539
|
+
get sharing(): ISpaceScopedSharing;
|
|
3540
|
+
/**
|
|
3541
|
+
* Get space metadata.
|
|
3542
|
+
*
|
|
3543
|
+
* @returns Result containing space information
|
|
3544
|
+
*/
|
|
3545
|
+
info(): Promise<Result$1<SpaceInfo, ServiceError>>;
|
|
3546
|
+
}
|
|
3547
|
+
|
|
3548
|
+
/**
|
|
3549
|
+
* SpaceService - Global singleton for managing spaces (owned and delegated).
|
|
3550
|
+
*
|
|
3551
|
+
* SpaceService provides a unified interface for discovering, creating,
|
|
3552
|
+
* and accessing spaces. It handles both owned spaces (created by the user)
|
|
3553
|
+
* and delegated spaces (shared by other users).
|
|
3554
|
+
*
|
|
3555
|
+
* @packageDocumentation
|
|
3556
|
+
*/
|
|
3557
|
+
|
|
3558
|
+
/**
|
|
3559
|
+
* Error codes for SpaceService operations.
|
|
3560
|
+
*/
|
|
3561
|
+
declare const SpaceErrorCodes: {
|
|
3562
|
+
/** Space not found */
|
|
3563
|
+
readonly NOT_FOUND: "SPACE_NOT_FOUND";
|
|
3564
|
+
/** Space already exists */
|
|
3565
|
+
readonly ALREADY_EXISTS: "SPACE_ALREADY_EXISTS";
|
|
3566
|
+
/** Creation failed */
|
|
3567
|
+
readonly CREATION_FAILED: "SPACE_CREATION_FAILED";
|
|
3568
|
+
/** Authentication required */
|
|
3569
|
+
readonly AUTH_REQUIRED: "AUTH_REQUIRED";
|
|
3570
|
+
/** Invalid space name or URI */
|
|
3571
|
+
readonly INVALID_NAME: "INVALID_SPACE_NAME";
|
|
3572
|
+
/** Network error */
|
|
3573
|
+
readonly NETWORK_ERROR: "NETWORK_ERROR";
|
|
3574
|
+
/** Not initialized */
|
|
3575
|
+
readonly NOT_INITIALIZED: "NOT_INITIALIZED";
|
|
3576
|
+
};
|
|
3577
|
+
type SpaceErrorCode = (typeof SpaceErrorCodes)[keyof typeof SpaceErrorCodes];
|
|
3578
|
+
/**
|
|
3579
|
+
* Parameters for creating a space-scoped delegation.
|
|
3580
|
+
* Extends CreateDelegationParams with the spaceId.
|
|
3581
|
+
*/
|
|
3582
|
+
interface SpaceDelegationParams extends Omit<CreateDelegationParams, "spaceId"> {
|
|
3583
|
+
/** The space ID to create the delegation for */
|
|
3584
|
+
spaceId: string;
|
|
3585
|
+
}
|
|
3586
|
+
/**
|
|
3587
|
+
* Function type for creating delegations.
|
|
3588
|
+
* Platform SDKs provide this to handle SIWE-based delegation creation.
|
|
3589
|
+
*/
|
|
3590
|
+
type CreateDelegationFunction = (params: SpaceDelegationParams) => Promise<Result$1<Delegation, ServiceError>>;
|
|
3591
|
+
/**
|
|
3592
|
+
* Configuration for SpaceService.
|
|
3593
|
+
*/
|
|
3594
|
+
interface SpaceServiceConfig {
|
|
3595
|
+
/** TinyCloud host URLs */
|
|
3596
|
+
hosts: string[];
|
|
3597
|
+
/** Active session for authentication */
|
|
3598
|
+
session: ServiceSession;
|
|
3599
|
+
/** Platform-specific invoke function */
|
|
3600
|
+
invoke: InvokeFunction;
|
|
3601
|
+
/** Optional custom fetch implementation */
|
|
3602
|
+
fetch?: FetchFunction;
|
|
3603
|
+
/** Optional capability key registry for delegated space discovery */
|
|
3604
|
+
capabilityRegistry?: ICapabilityKeyRegistry;
|
|
3605
|
+
/** Factory function to create a space-scoped KV service */
|
|
3606
|
+
createKVService?: (spaceId: string) => IKVService;
|
|
3607
|
+
/** User's PKH DID (derived from address or provided explicitly) */
|
|
3608
|
+
userDid?: string;
|
|
3609
|
+
/** Optional SharingService for v2 sharing links (client-side) */
|
|
3610
|
+
sharingService?: ISharingService;
|
|
3611
|
+
/**
|
|
3612
|
+
* Factory function to create delegations using SIWE-based flow.
|
|
3613
|
+
* Platform SDKs (web-sdk, node-sdk) provide this using their WASM bindings.
|
|
3614
|
+
* Required for space.delegations.create() to work.
|
|
3615
|
+
*/
|
|
3616
|
+
createDelegation?: CreateDelegationFunction;
|
|
3617
|
+
}
|
|
3618
|
+
/**
|
|
3619
|
+
* Interface for SpaceService.
|
|
3620
|
+
*/
|
|
3621
|
+
interface ISpaceService {
|
|
3622
|
+
/**
|
|
3623
|
+
* List all spaces the user has access to (owned + delegated).
|
|
3624
|
+
*/
|
|
3625
|
+
list(): Promise<Result$1<SpaceInfo[], ServiceError>>;
|
|
3626
|
+
/**
|
|
3627
|
+
* Create a new space.
|
|
3628
|
+
*
|
|
3629
|
+
* @param name - The name for the new space
|
|
3630
|
+
*/
|
|
3631
|
+
create(name: string): Promise<Result$1<SpaceInfo, ServiceError>>;
|
|
3632
|
+
/**
|
|
3633
|
+
* Get a Space object by name or full URI.
|
|
3634
|
+
*
|
|
3635
|
+
* For owned spaces, use the short name: `sdk.space('default')`
|
|
3636
|
+
* For delegated spaces, use the full URI: `sdk.space('tinycloud:pkh:eip155:1:0x...:photos')`
|
|
3637
|
+
*
|
|
3638
|
+
* @param nameOrUri - Short name or full URI
|
|
3639
|
+
*/
|
|
3640
|
+
get(nameOrUri: string): ISpace;
|
|
3641
|
+
/**
|
|
3642
|
+
* Check if a space exists and the user has access.
|
|
3643
|
+
*
|
|
3644
|
+
* @param nameOrUri - Short name or full URI
|
|
3645
|
+
*/
|
|
3646
|
+
exists(nameOrUri: string): Promise<Result$1<boolean, ServiceError>>;
|
|
3647
|
+
/**
|
|
3648
|
+
* Get the current user's primary space ID.
|
|
3649
|
+
*/
|
|
3650
|
+
getCurrentSpaceId(): string | undefined;
|
|
3651
|
+
/**
|
|
3652
|
+
* Update the service configuration.
|
|
3653
|
+
*/
|
|
3654
|
+
updateConfig(config: Partial<SpaceServiceConfig>): void;
|
|
3655
|
+
}
|
|
3656
|
+
/**
|
|
3657
|
+
* Construct the deterministic public space ID for a given address and chain ID.
|
|
3658
|
+
*
|
|
3659
|
+
* Public space IDs follow the format:
|
|
3660
|
+
* `tinycloud:pkh:eip155:{chainId}:{address}:public`
|
|
3661
|
+
*
|
|
3662
|
+
* Given an address and chain ID, any client can construct this ID
|
|
3663
|
+
* to discover and read a user's public data without prior interaction.
|
|
3664
|
+
*
|
|
3665
|
+
* @param address - Ethereum address (0x-prefixed)
|
|
3666
|
+
* @param chainId - Chain ID (e.g., 1 for mainnet)
|
|
3667
|
+
* @returns The full public space ID URI
|
|
3668
|
+
*
|
|
3669
|
+
* @example
|
|
3670
|
+
* ```typescript
|
|
3671
|
+
* const spaceId = makePublicSpaceId('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', 1);
|
|
3672
|
+
* // => "tinycloud:pkh:eip155:1:0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045:public"
|
|
3673
|
+
* ```
|
|
3674
|
+
*/
|
|
3675
|
+
declare function makePublicSpaceId(address: string, chainId: number): string;
|
|
3676
|
+
/**
|
|
3677
|
+
* Parse a space URI to extract components.
|
|
3678
|
+
*
|
|
3679
|
+
* Full URI format: `tinycloud:pkh:eip155:{chainId}:{address}:{name}`
|
|
3680
|
+
* Short name format: `{name}`
|
|
3681
|
+
*
|
|
3682
|
+
* @param uri - The space URI or short name
|
|
3683
|
+
* @returns Parsed components or null if invalid
|
|
3684
|
+
*/
|
|
3685
|
+
declare function parseSpaceUri(uri: string): {
|
|
3686
|
+
owner: string;
|
|
3687
|
+
name: string;
|
|
3688
|
+
chainId?: string;
|
|
3689
|
+
address?: string;
|
|
3690
|
+
} | null;
|
|
3691
|
+
/**
|
|
3692
|
+
* Build a full space URI from components.
|
|
3693
|
+
*
|
|
3694
|
+
* @param owner - Owner DID (did:pkh:eip155:{chainId}:{address})
|
|
3695
|
+
* @param name - Space name
|
|
3696
|
+
* @returns Full space URI
|
|
3697
|
+
*/
|
|
3698
|
+
declare function buildSpaceUri(owner: string, name: string): string;
|
|
3699
|
+
/**
|
|
3700
|
+
* SpaceService - Global singleton for managing spaces.
|
|
3701
|
+
*
|
|
3702
|
+
* @example
|
|
3703
|
+
* ```typescript
|
|
3704
|
+
* const spaceService = new SpaceService({
|
|
3705
|
+
* hosts: ['https://node.tinycloud.xyz'],
|
|
3706
|
+
* session,
|
|
3707
|
+
* invoke,
|
|
3708
|
+
* });
|
|
3709
|
+
*
|
|
3710
|
+
* // List all accessible spaces
|
|
3711
|
+
* const result = await spaceService.list();
|
|
3712
|
+
* if (result.ok) {
|
|
3713
|
+
* for (const space of result.data) {
|
|
3714
|
+
* console.log(`${space.name} (${space.type})`);
|
|
3715
|
+
* }
|
|
3716
|
+
* }
|
|
3717
|
+
*
|
|
3718
|
+
* // Create a new space
|
|
3719
|
+
* const createResult = await spaceService.create('photos');
|
|
3720
|
+
*
|
|
3721
|
+
* // Get a space object for operations
|
|
3722
|
+
* const space = spaceService.get('photos');
|
|
3723
|
+
* await space.kv.put('album/vacation', { photos: [...] });
|
|
3724
|
+
* ```
|
|
3725
|
+
*/
|
|
3726
|
+
declare class SpaceService implements ISpaceService {
|
|
3727
|
+
private hosts;
|
|
3728
|
+
private session;
|
|
3729
|
+
private invoke;
|
|
3730
|
+
private fetchFn;
|
|
3731
|
+
private capabilityRegistry?;
|
|
3732
|
+
private createKVServiceFn?;
|
|
3733
|
+
private _userDid?;
|
|
3734
|
+
private sharingService?;
|
|
3735
|
+
private createDelegationFn?;
|
|
3736
|
+
/** Cache of created Space objects */
|
|
3737
|
+
private spaceCache;
|
|
3738
|
+
/** Cache of space info */
|
|
3739
|
+
private infoCache;
|
|
3740
|
+
/** Cache TTL in milliseconds (5 minutes) */
|
|
3741
|
+
private readonly cacheTTL;
|
|
3742
|
+
/**
|
|
3743
|
+
* Create a new SpaceService instance.
|
|
3744
|
+
*
|
|
3745
|
+
* @param config - Service configuration
|
|
3746
|
+
*/
|
|
3747
|
+
constructor(config: SpaceServiceConfig);
|
|
3748
|
+
/**
|
|
3749
|
+
* Update the service configuration.
|
|
3750
|
+
*/
|
|
3751
|
+
updateConfig(config: Partial<SpaceServiceConfig>): void;
|
|
3752
|
+
/**
|
|
3753
|
+
* Get the current user's primary space ID.
|
|
3754
|
+
*/
|
|
3755
|
+
getCurrentSpaceId(): string | undefined;
|
|
3756
|
+
/**
|
|
3757
|
+
* Get the primary host URL.
|
|
3758
|
+
*/
|
|
3759
|
+
private get host();
|
|
3760
|
+
/**
|
|
3761
|
+
* Get the current user's PKH DID.
|
|
3762
|
+
*/
|
|
3763
|
+
private get userDid();
|
|
3764
|
+
/**
|
|
3765
|
+
* List all spaces the user has access to.
|
|
3766
|
+
*
|
|
3767
|
+
* Combines owned spaces (from the server) with delegated spaces
|
|
3768
|
+
* (from the capability registry).
|
|
3769
|
+
*/
|
|
3770
|
+
list(): Promise<Result$1<SpaceInfo[], ServiceError>>;
|
|
3771
|
+
/**
|
|
3772
|
+
* List owned spaces from the server.
|
|
3773
|
+
*/
|
|
3774
|
+
private listOwnedSpaces;
|
|
3775
|
+
/**
|
|
3776
|
+
* Discover delegated spaces from the capability registry.
|
|
3777
|
+
*/
|
|
3778
|
+
private discoverDelegatedSpaces;
|
|
3779
|
+
/**
|
|
3780
|
+
* Extract space name from a full space ID.
|
|
3781
|
+
*/
|
|
3782
|
+
private extractNameFromId;
|
|
3783
|
+
/**
|
|
3784
|
+
* Deduplicate spaces, preferring owned over delegated.
|
|
3785
|
+
*/
|
|
3786
|
+
private deduplicateSpaces;
|
|
3787
|
+
/**
|
|
3788
|
+
* Create a new space.
|
|
3789
|
+
*
|
|
3790
|
+
* @param name - The name for the new space
|
|
3791
|
+
*/
|
|
3792
|
+
create(name: string): Promise<Result$1<SpaceInfo, ServiceError>>;
|
|
3793
|
+
/**
|
|
3794
|
+
* Get a Space object by name or full URI.
|
|
3795
|
+
*
|
|
3796
|
+
* @param nameOrUri - Short name or full URI
|
|
3797
|
+
*/
|
|
3798
|
+
get(nameOrUri: string): ISpace;
|
|
3799
|
+
/**
|
|
3800
|
+
* Resolve a name or URI to a full space ID.
|
|
3801
|
+
*/
|
|
3802
|
+
private resolveSpaceId;
|
|
3803
|
+
/**
|
|
3804
|
+
* Check if a space exists and the user has access.
|
|
3805
|
+
*/
|
|
3806
|
+
exists(nameOrUri: string): Promise<Result$1<boolean, ServiceError>>;
|
|
3807
|
+
/**
|
|
3808
|
+
* Get space info from server or cache.
|
|
3809
|
+
*/
|
|
3810
|
+
private getSpaceInfo;
|
|
3811
|
+
/**
|
|
3812
|
+
* Create a space-scoped KV service.
|
|
3813
|
+
*/
|
|
3814
|
+
private createSpaceScopedKV;
|
|
3815
|
+
/**
|
|
3816
|
+
* Create space-scoped delegation operations.
|
|
3817
|
+
*/
|
|
3818
|
+
private createSpaceScopedDelegations;
|
|
3819
|
+
/**
|
|
3820
|
+
* Create space-scoped sharing operations.
|
|
3821
|
+
*
|
|
3822
|
+
* When a SharingService is configured, delegates to client-side v2 sharing.
|
|
3823
|
+
* V2 sharing links are self-contained with embedded private keys - no server tracking.
|
|
3824
|
+
*/
|
|
3825
|
+
private createSpaceScopedSharing;
|
|
3826
|
+
}
|
|
3827
|
+
/**
|
|
3828
|
+
* Create a new SpaceService instance.
|
|
3829
|
+
*
|
|
3830
|
+
* @param config - Service configuration
|
|
3831
|
+
* @returns A new SpaceService instance
|
|
3832
|
+
*/
|
|
3833
|
+
declare function createSpaceService(config: SpaceServiceConfig): ISpaceService;
|
|
3834
|
+
|
|
3835
|
+
/**
|
|
3836
|
+
* Protocol version checking for SDK-to-node compatibility.
|
|
9
3837
|
*
|
|
10
3838
|
* @packageDocumentation
|
|
11
3839
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
3840
|
+
declare class ProtocolMismatchError extends Error {
|
|
3841
|
+
readonly sdkProtocol: number;
|
|
3842
|
+
readonly nodeProtocol: number;
|
|
3843
|
+
readonly nodeVersion: string;
|
|
3844
|
+
readonly host: string;
|
|
3845
|
+
name: "ProtocolMismatchError";
|
|
3846
|
+
constructor(sdkProtocol: number, nodeProtocol: number, nodeVersion: string, host: string);
|
|
3847
|
+
}
|
|
3848
|
+
declare class VersionCheckError extends Error {
|
|
3849
|
+
readonly host: string;
|
|
3850
|
+
readonly cause?: Error | undefined;
|
|
3851
|
+
name: "VersionCheckError";
|
|
3852
|
+
constructor(host: string, cause?: Error | undefined);
|
|
3853
|
+
}
|
|
3854
|
+
declare class UnsupportedFeatureError extends Error {
|
|
3855
|
+
readonly feature: string;
|
|
3856
|
+
readonly host: string;
|
|
3857
|
+
readonly availableFeatures: string[];
|
|
3858
|
+
name: "UnsupportedFeatureError";
|
|
3859
|
+
constructor(feature: string, host: string, availableFeatures: string[]);
|
|
3860
|
+
}
|
|
3861
|
+
interface NodeInfo {
|
|
3862
|
+
features: string[];
|
|
3863
|
+
quotaUrl?: string;
|
|
3864
|
+
}
|
|
3865
|
+
declare function checkNodeInfo(host: string, sdkProtocol: number, fetchFn?: typeof globalThis.fetch): Promise<NodeInfo>;
|
|
3866
|
+
|
|
3867
|
+
export { AutoApproveSpaceCreationHandler, type AutoRejectStrategy, type AutoSignStrategy, type Bytes, type CallbackStrategy, type CapabilityEntry, CapabilityKeyRegistry, type CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, type ClientSession, ClientSessionSchema, type CreateDelegationFunction, type CreateDelegationParams, type CreateDelegationWasmParams, type CreateDelegationWasmResult, type Delegation, type DelegationApiResponse, type DelegationChain, type DelegationChainV2, type DelegationDirection, type DelegationError, type DelegationErrorCode, DelegationErrorCodes, type DelegationFilters, DelegationManager, type DelegationManagerConfig, type DelegationRecord, type Result as DelegationResult, type EncodedShareData, type EnsData, EnsDataSchema, type EventEmitterStrategy, type Extension, type GenerateShareParams, type ICapabilityKeyRegistry, type IENSResolver, type INotificationHandler, type ISessionManager, type ISessionStorage, type ISharingService, type ISigner, type ISpace, type ISpaceCreationHandler, type ISpaceScopedDelegations, type ISpaceScopedSharing, type ISpaceService, type IUserAuthorization, type IWasmBindings, type IngestOptions, type JWK, type KeyInfo, type KeyProvider, type KeyType, type NodeInfo, type PartialSiweMessage, type PersistedSessionData, type PersistedTinyCloudSession, ProtocolMismatchError, type ReceiveOptions, type ServerHost, type ShareAccess, type ShareLink, type ShareLinkData, type ShareSchema, SharingService, type SharingServiceConfig, type SignCallback, type SignRequest, type SignResponse, type SignStrategy, SilentNotificationHandler, type SiweConfig, SiweConfigSchema, Space, type SpaceConfig, type SpaceCreationContext, type SpaceDelegationParams, type SpaceErrorCode, SpaceErrorCodes, type SpaceHostResult, type SpaceInfo, type SpaceOwnership, SpaceService, type SpaceServiceConfig, type StoredDelegationChain, TinyCloud, type TinyCloudConfig, type TinyCloudSession, UnsupportedFeatureError, type UserAuthorizationConfig, type ValidationError, VersionCheckError, activateSessionWithHost, buildSpaceUri, checkNodeInfo, createCapabilityKeyRegistry, createSharingService, createSpaceService, defaultSignStrategy, defaultSpaceCreationHandler, fetchPeerId, makePublicSpaceId, parseSpaceUri, submitHostDelegation, validateClientSession, validatePersistedSessionData };
|