@tinycloud/web-sdk 1.0.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/LICENSE.md +320 -0
- package/README.md +151 -0
- package/dist/625.index.js +1 -0
- package/dist/authorization/WebSpaceCreationHandler.d.ts +40 -0
- package/dist/authorization/WebSpaceCreationHandler.d.ts.map +1 -0
- package/dist/authorization/WebUserAuthorization.d.ts +295 -0
- package/dist/authorization/WebUserAuthorization.d.ts.map +1 -0
- package/dist/authorization/index.d.ts +12 -0
- package/dist/authorization/index.d.ts.map +1 -0
- package/dist/delegation.d.ts +85 -0
- package/dist/delegation.d.ts.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/modules/Storage/index.d.ts +2 -0
- package/dist/modules/Storage/index.d.ts.map +1 -0
- package/dist/modules/Storage/tinycloud/KVServiceAdapter.d.ts +24 -0
- package/dist/modules/Storage/tinycloud/KVServiceAdapter.d.ts.map +1 -0
- package/dist/modules/Storage/tinycloud/index.d.ts +3 -0
- package/dist/modules/Storage/tinycloud/index.d.ts.map +1 -0
- package/dist/modules/Storage/tinycloud/module.d.ts +10 -0
- package/dist/modules/Storage/tinycloud/module.d.ts.map +1 -0
- package/dist/modules/Storage/tinycloud/types.d.ts +64 -0
- package/dist/modules/Storage/tinycloud/types.d.ts.map +1 -0
- package/dist/modules/Storage/tinycloud/types.schema.d.ts +159 -0
- package/dist/modules/Storage/tinycloud/types.schema.d.ts.map +1 -0
- package/dist/modules/UserAuthorization.d.ts +361 -0
- package/dist/modules/UserAuthorization.d.ts.map +1 -0
- package/dist/modules/WasmInitializer.d.ts +26 -0
- package/dist/modules/WasmInitializer.d.ts.map +1 -0
- package/dist/modules/index.d.ts +6 -0
- package/dist/modules/index.d.ts.map +1 -0
- package/dist/modules/keys/WasmKeyProvider.d.ts +126 -0
- package/dist/modules/keys/WasmKeyProvider.d.ts.map +1 -0
- package/dist/modules/keys/index.d.ts +7 -0
- package/dist/modules/keys/index.d.ts.map +1 -0
- package/dist/modules/registry/Registry.d.ts +59 -0
- package/dist/modules/registry/Registry.d.ts.map +1 -0
- package/dist/modules/tcw.d.ts +718 -0
- package/dist/modules/tcw.d.ts.map +1 -0
- package/dist/notifications/ErrorHandler.d.ts +32 -0
- package/dist/notifications/ErrorHandler.d.ts.map +1 -0
- package/dist/notifications/ModalManager.d.ts +15 -0
- package/dist/notifications/ModalManager.d.ts.map +1 -0
- package/dist/notifications/NodeSelectionModal.d.ts +29 -0
- package/dist/notifications/NodeSelectionModal.d.ts.map +1 -0
- package/dist/notifications/SpaceCreationModal.d.ts +28 -0
- package/dist/notifications/SpaceCreationModal.d.ts.map +1 -0
- package/dist/notifications/ToastContainer.d.ts +16 -0
- package/dist/notifications/ToastContainer.d.ts.map +1 -0
- package/dist/notifications/ToastElement.d.ts +22 -0
- package/dist/notifications/ToastElement.d.ts.map +1 -0
- package/dist/notifications/ToastManager.d.ts +36 -0
- package/dist/notifications/ToastManager.d.ts.map +1 -0
- package/dist/notifications/index.d.ts +9 -0
- package/dist/notifications/index.d.ts.map +1 -0
- package/dist/notifications/types.d.ts +37 -0
- package/dist/notifications/types.d.ts.map +1 -0
- package/dist/notifications/types.schema.d.ts +224 -0
- package/dist/notifications/types.schema.d.ts.map +1 -0
- package/dist/utils/debug.d.ts +9 -0
- package/dist/utils/debug.d.ts.map +1 -0
- package/dist/utils/multiaddr.d.ts +36 -0
- package/dist/utils/multiaddr.d.ts.map +1 -0
- package/package.json +82 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebUserAuthorization - Browser-based authorization following node-sdk architecture.
|
|
3
|
+
*
|
|
4
|
+
* This class implements IUserAuthorization for browser environments with:
|
|
5
|
+
* - Session-only mode (no wallet required)
|
|
6
|
+
* - SignStrategy patterns (wallet popup as default, callback, event-emitter)
|
|
7
|
+
* - did vs sessionDid model
|
|
8
|
+
* - connectWallet() upgrade pattern
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
import { providers } from "ethers";
|
|
13
|
+
import { IUserAuthorization, ISessionStorage, ClientSession, Extension, TinyCloudSession, SignStrategy, ISpaceCreationHandler, JWK } from "@tinycloud/sdk-core";
|
|
14
|
+
import { Session } from "../modules/Storage/tinycloud";
|
|
15
|
+
/**
|
|
16
|
+
* Wallet popup sign strategy for web.
|
|
17
|
+
* Shows browser wallet popup for each sign request.
|
|
18
|
+
*/
|
|
19
|
+
export interface WalletPopupStrategy {
|
|
20
|
+
type: "wallet-popup";
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Web-specific SignStrategy that includes wallet-popup.
|
|
24
|
+
*/
|
|
25
|
+
export type WebSignStrategy = SignStrategy | WalletPopupStrategy;
|
|
26
|
+
/**
|
|
27
|
+
* Default web sign strategy is wallet-popup.
|
|
28
|
+
*/
|
|
29
|
+
export declare const defaultWebSignStrategy: WebSignStrategy;
|
|
30
|
+
/**
|
|
31
|
+
* Configuration for WebUserAuthorization.
|
|
32
|
+
*/
|
|
33
|
+
export interface WebUserAuthorizationConfig {
|
|
34
|
+
/** Web3 provider (e.g., window.ethereum or WalletConnect) */
|
|
35
|
+
provider?: providers.ExternalProvider | providers.Web3Provider;
|
|
36
|
+
/** Sign strategy for handling sign requests (default: wallet-popup) */
|
|
37
|
+
signStrategy?: WebSignStrategy;
|
|
38
|
+
/** Session storage implementation */
|
|
39
|
+
sessionStorage?: ISessionStorage;
|
|
40
|
+
/** Handler for space creation confirmation */
|
|
41
|
+
spaceCreationHandler?: ISpaceCreationHandler;
|
|
42
|
+
/** Domain for SIWE messages (default: window.location.hostname) */
|
|
43
|
+
domain?: string;
|
|
44
|
+
/** URI for SIWE messages */
|
|
45
|
+
uri?: string;
|
|
46
|
+
/** Statement included in SIWE messages */
|
|
47
|
+
statement?: string;
|
|
48
|
+
/** Space prefix for new sessions (default: "default") */
|
|
49
|
+
spacePrefix?: string;
|
|
50
|
+
/** Default actions for sessions */
|
|
51
|
+
defaultActions?: Record<string, Record<string, string[]>>;
|
|
52
|
+
/** Session expiration time in milliseconds (default: 1 hour) */
|
|
53
|
+
sessionExpirationMs?: number;
|
|
54
|
+
/** Automatically create space if it doesn't exist (default: true) */
|
|
55
|
+
autoCreateSpace?: boolean;
|
|
56
|
+
/** TinyCloud server endpoints (default: ["https://node.tinycloud.xyz"]) */
|
|
57
|
+
tinycloudHosts?: string[];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Browser-based implementation of IUserAuthorization.
|
|
61
|
+
*
|
|
62
|
+
* Supports multiple modes:
|
|
63
|
+
* - **Session-only mode**: Can receive delegations without wallet
|
|
64
|
+
* - **Wallet mode**: Full sign-in with space ownership
|
|
65
|
+
*
|
|
66
|
+
* Supports multiple sign strategies:
|
|
67
|
+
* - **wallet-popup**: Show browser wallet popup (default for web)
|
|
68
|
+
* - **auto-sign**: Automatically approve (requires ISigner)
|
|
69
|
+
* - **callback**: Delegate to custom callback
|
|
70
|
+
* - **event-emitter**: Emit events for async approval
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* // Standard wallet popup flow
|
|
75
|
+
* const auth = new WebUserAuthorization({
|
|
76
|
+
* provider: window.ethereum,
|
|
77
|
+
* domain: 'myapp.com',
|
|
78
|
+
* });
|
|
79
|
+
* await auth.signIn();
|
|
80
|
+
*
|
|
81
|
+
* // Session-only mode (no wallet required)
|
|
82
|
+
* const auth = new WebUserAuthorization();
|
|
83
|
+
* console.log(auth.sessionDid); // Available immediately
|
|
84
|
+
* // Later: auth.connectWallet(window.ethereum);
|
|
85
|
+
*
|
|
86
|
+
* // Callback strategy for custom approval
|
|
87
|
+
* const auth = new WebUserAuthorization({
|
|
88
|
+
* provider: window.ethereum,
|
|
89
|
+
* signStrategy: {
|
|
90
|
+
* type: 'callback',
|
|
91
|
+
* handler: async (req) => {
|
|
92
|
+
* const approved = await showCustomModal(`Sign for ${req.address}?`);
|
|
93
|
+
* return { approved };
|
|
94
|
+
* }
|
|
95
|
+
* },
|
|
96
|
+
* domain: 'myapp.com',
|
|
97
|
+
* });
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare class WebUserAuthorization implements IUserAuthorization {
|
|
101
|
+
/** Flag to ensure WASM initialization is tracked */
|
|
102
|
+
private static wasmInitialized;
|
|
103
|
+
private readonly signStrategy;
|
|
104
|
+
private readonly sessionStorage?;
|
|
105
|
+
private readonly spaceCreationHandler;
|
|
106
|
+
private readonly domain;
|
|
107
|
+
private readonly uri;
|
|
108
|
+
private readonly statement?;
|
|
109
|
+
private readonly spacePrefix;
|
|
110
|
+
private readonly defaultActions;
|
|
111
|
+
private readonly sessionExpirationMs;
|
|
112
|
+
private readonly autoCreateSpace;
|
|
113
|
+
private readonly tinycloudHosts;
|
|
114
|
+
private _provider?;
|
|
115
|
+
private _signer?;
|
|
116
|
+
private sessionManager;
|
|
117
|
+
private sessionKeyId;
|
|
118
|
+
private extensions;
|
|
119
|
+
private _session?;
|
|
120
|
+
private _tinyCloudSession?;
|
|
121
|
+
private _address?;
|
|
122
|
+
private _chainId?;
|
|
123
|
+
constructor(config?: WebUserAuthorizationConfig);
|
|
124
|
+
/**
|
|
125
|
+
* Set or update the provider.
|
|
126
|
+
*/
|
|
127
|
+
private setProvider;
|
|
128
|
+
/**
|
|
129
|
+
* Whether this instance is in session-only mode (no wallet connected).
|
|
130
|
+
*/
|
|
131
|
+
get isSessionOnly(): boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Get the appropriate DID for this user.
|
|
134
|
+
*
|
|
135
|
+
* - If wallet connected and signed in: returns PKH DID (persistent identity)
|
|
136
|
+
* - If session-only mode: returns session key DID (ephemeral)
|
|
137
|
+
*
|
|
138
|
+
* Use this for delegations and identity operations.
|
|
139
|
+
*/
|
|
140
|
+
get did(): string;
|
|
141
|
+
/**
|
|
142
|
+
* Get the session key DID (always available).
|
|
143
|
+
*
|
|
144
|
+
* Format: `did:key:z6Mk...#z6Mk...`
|
|
145
|
+
*/
|
|
146
|
+
get sessionDid(): string;
|
|
147
|
+
/**
|
|
148
|
+
* Get the session key JWK (always available).
|
|
149
|
+
*
|
|
150
|
+
* This is used for session-only mode operations like useDelegation()
|
|
151
|
+
* where we need the session key to create a session from a received delegation.
|
|
152
|
+
*
|
|
153
|
+
* @returns The JWK for the current session key
|
|
154
|
+
* @throws Error if session key not found
|
|
155
|
+
*/
|
|
156
|
+
getSessionKeyJwk(): JWK;
|
|
157
|
+
/**
|
|
158
|
+
* Connect a wallet to upgrade from session-only mode.
|
|
159
|
+
*
|
|
160
|
+
* This allows users who started in session-only mode (e.g., received
|
|
161
|
+
* delegations) to later connect a wallet and create their own space.
|
|
162
|
+
*
|
|
163
|
+
* @param provider - Web3 provider (e.g., window.ethereum)
|
|
164
|
+
* @param options - Optional configuration
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* // Start in session-only mode
|
|
169
|
+
* const auth = new WebUserAuthorization();
|
|
170
|
+
* console.log(auth.isSessionOnly); // true
|
|
171
|
+
* console.log(auth.did); // did:key:z6Mk... (session key DID)
|
|
172
|
+
*
|
|
173
|
+
* // User clicks "Connect Wallet"
|
|
174
|
+
* auth.connectWallet(window.ethereum);
|
|
175
|
+
* console.log(auth.isSessionOnly); // false
|
|
176
|
+
*
|
|
177
|
+
* // Now can sign in to create own space
|
|
178
|
+
* await auth.signIn();
|
|
179
|
+
* console.log(auth.did); // did:pkh:eip155:1:0x... (wallet DID)
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
connectWallet(provider: providers.ExternalProvider | providers.Web3Provider, options?: {
|
|
183
|
+
spacePrefix?: string;
|
|
184
|
+
}): void;
|
|
185
|
+
/**
|
|
186
|
+
* Check if a wallet is connected (but may not be signed in).
|
|
187
|
+
*/
|
|
188
|
+
get isWalletConnected(): boolean;
|
|
189
|
+
/**
|
|
190
|
+
* The current active session (web-core compatible).
|
|
191
|
+
*/
|
|
192
|
+
get session(): ClientSession | undefined;
|
|
193
|
+
/**
|
|
194
|
+
* The current TinyCloud session with full delegation data.
|
|
195
|
+
*/
|
|
196
|
+
get tinyCloudSession(): TinyCloudSession | undefined;
|
|
197
|
+
/**
|
|
198
|
+
* Add an extension to the authorization flow.
|
|
199
|
+
*/
|
|
200
|
+
extend(extension: Extension): void;
|
|
201
|
+
/**
|
|
202
|
+
* Get the space ID for the current session.
|
|
203
|
+
*/
|
|
204
|
+
getSpaceId(): string | undefined;
|
|
205
|
+
/**
|
|
206
|
+
* Get the TinyCloud session.
|
|
207
|
+
*/
|
|
208
|
+
getTinycloudSession(): Session | undefined;
|
|
209
|
+
/**
|
|
210
|
+
* Get the configured TinyCloud hosts.
|
|
211
|
+
*/
|
|
212
|
+
getTinycloudHosts(): string[];
|
|
213
|
+
/**
|
|
214
|
+
* Sign in and create a new session.
|
|
215
|
+
*
|
|
216
|
+
* @throws Error if in session-only mode (no wallet connected)
|
|
217
|
+
*/
|
|
218
|
+
signIn(): Promise<ClientSession>;
|
|
219
|
+
/**
|
|
220
|
+
* Sign out and clear the current session.
|
|
221
|
+
*/
|
|
222
|
+
signOut(): Promise<void>;
|
|
223
|
+
/**
|
|
224
|
+
* Get the current wallet address.
|
|
225
|
+
*/
|
|
226
|
+
address(): string | undefined;
|
|
227
|
+
/**
|
|
228
|
+
* Get the current chain ID.
|
|
229
|
+
*/
|
|
230
|
+
chainId(): number | undefined;
|
|
231
|
+
/**
|
|
232
|
+
* Sign a message with the connected wallet.
|
|
233
|
+
*/
|
|
234
|
+
signMessage(message: string): Promise<string>;
|
|
235
|
+
/**
|
|
236
|
+
* Prepare a session for external signing.
|
|
237
|
+
*
|
|
238
|
+
* Use this when you need to sign the SIWE message externally (e.g., via
|
|
239
|
+
* a hardware wallet or WalletConnect that handles signing separately).
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```typescript
|
|
243
|
+
* const { prepared, keyId, jwk, address, chainId } = await auth.prepareSessionForSigning();
|
|
244
|
+
* // Sign with external tool
|
|
245
|
+
* const signature = await walletConnect.signMessage(prepared.siwe);
|
|
246
|
+
* const session = await auth.signInWithPreparedSession(prepared, signature, keyId, jwk);
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
prepareSessionForSigning(): Promise<{
|
|
250
|
+
prepared: {
|
|
251
|
+
siwe: string;
|
|
252
|
+
jwk: Record<string, unknown>;
|
|
253
|
+
spaceId: string;
|
|
254
|
+
verificationMethod: string;
|
|
255
|
+
};
|
|
256
|
+
keyId: string;
|
|
257
|
+
jwk: Record<string, unknown>;
|
|
258
|
+
address: string;
|
|
259
|
+
chainId: number;
|
|
260
|
+
}>;
|
|
261
|
+
/**
|
|
262
|
+
* Complete sign-in with a prepared session and signature.
|
|
263
|
+
*/
|
|
264
|
+
signInWithPreparedSession(prepared: {
|
|
265
|
+
siwe: string;
|
|
266
|
+
jwk: Record<string, unknown>;
|
|
267
|
+
spaceId: string;
|
|
268
|
+
verificationMethod: string;
|
|
269
|
+
}, signature: string, keyId: string, jwk: Record<string, unknown>): Promise<ClientSession>;
|
|
270
|
+
/**
|
|
271
|
+
* Ensure the user's space exists on the TinyCloud server.
|
|
272
|
+
*/
|
|
273
|
+
ensureSpaceExists(): Promise<void>;
|
|
274
|
+
/**
|
|
275
|
+
* Create the space on the TinyCloud server.
|
|
276
|
+
*/
|
|
277
|
+
private hostSpace;
|
|
278
|
+
/**
|
|
279
|
+
* Request a signature using the configured strategy.
|
|
280
|
+
*/
|
|
281
|
+
private requestSignature;
|
|
282
|
+
/**
|
|
283
|
+
* Request signature via event emitter.
|
|
284
|
+
*/
|
|
285
|
+
private requestSignatureViaEmitter;
|
|
286
|
+
/**
|
|
287
|
+
* Clear persisted session data.
|
|
288
|
+
*/
|
|
289
|
+
clearPersistedSession(address?: string): Promise<void>;
|
|
290
|
+
/**
|
|
291
|
+
* Check if a session is persisted for an address.
|
|
292
|
+
*/
|
|
293
|
+
isSessionPersisted(address: string): boolean;
|
|
294
|
+
}
|
|
295
|
+
//# sourceMappingURL=WebUserAuthorization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebUserAuthorization.d.ts","sourceRoot":"","sources":["../../src/authorization/WebUserAuthorization.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,SAAS,EAAU,MAAM,QAAQ,CAAC;AAE3C,OAAO,EACL,kBAAkB,EAElB,eAAe,EACf,aAAa,EACb,SAAS,EAET,gBAAgB,EAChB,YAAY,EAGZ,qBAAqB,EAQrB,GAAG,EACJ,MAAM,qBAAqB,CAAC;AAW7B,OAAO,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAsBvD;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,cAAc,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GACvB,YAAY,GACZ,mBAAmB,CAAC;AAExB;;GAEG;AACH,eAAO,MAAM,sBAAsB,EAAE,eAA0C,CAAC;AAEhF;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,SAAS,CAAC,gBAAgB,GAAG,SAAS,CAAC,YAAY,CAAC;IAC/D,uEAAuE;IACvE,YAAY,CAAC,EAAE,eAAe,CAAC;IAC/B,qCAAqC;IACrC,cAAc,CAAC,EAAE,eAAe,CAAC;IACjC,8CAA8C;IAC9C,oBAAoB,CAAC,EAAE,qBAAqB,CAAC;IAC7C,mEAAmE;IACnE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4BAA4B;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yDAAyD;IACzD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mCAAmC;IACnC,cAAc,CAAC,EAAE,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AE,MAAM,CAAC;YACb,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YAC7B,OAAO,EAAE,MAAM,CAAC;YAChB,kBAAkB,EAAE,MAAM,CAAC;SAC5B,CAAC;QACF,KAAK,EAAE,MAAM,CAAC;QACd,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC7B,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IAiDF;;OAEG;IACG,yBAAyB,CAC7B,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC7B,OAAO,EAAE,MAAM,CAAC;QAChB,kBAAkB,EAAE,MAAM,CAAC;KAC5B,EACD,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC3B,OAAO,CAAC,aAAa,CAAC;IA2FzB;;OAEG;IACG,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAqExC;;OAEG;YACW,SAAS;IAmCvB;;OAEG;YACW,gBAAgB;IA8C9B;;OAEG;IACH,OAAO,CAAC,0BAA0B;IAuClC;;OAEG;IACG,qBAAqB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS5D;;OAEG;IACH,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;CAG7C"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web-sdk authorization module.
|
|
3
|
+
*
|
|
4
|
+
* Provides WebUserAuthorization implementing the node-sdk architecture
|
|
5
|
+
* with browser-specific features like wallet popups and modal confirmations.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
export { WebUserAuthorization, WebUserAuthorizationConfig, WebSignStrategy, WalletPopupStrategy, defaultWebSignStrategy, } from "./WebUserAuthorization";
|
|
10
|
+
export { ModalSpaceCreationHandler, defaultWebSpaceCreationHandler, } from "./WebSpaceCreationHandler";
|
|
11
|
+
export { SignStrategy, SignRequest, SignResponse, SignCallback, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, EventEmitterStrategy, defaultSignStrategy, ISpaceCreationHandler, SpaceCreationContext, AutoApproveSpaceCreationHandler, defaultSpaceCreationHandler, } from "@tinycloud/sdk-core";
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/authorization/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,oBAAoB,EACpB,0BAA0B,EAC1B,eAAe,EACf,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,yBAAyB,EACzB,8BAA8B,GAC/B,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EACL,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,EACpB,+BAA+B,EAC/B,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Delegation types and utilities for web-sdk.
|
|
3
|
+
*
|
|
4
|
+
* These types are compatible with node-sdk's delegation system,
|
|
5
|
+
* allowing delegations to be exchanged between platforms.
|
|
6
|
+
*/
|
|
7
|
+
import { Delegation, TinyCloudSession, IKVService } from "@tinycloud/sdk-core";
|
|
8
|
+
/**
|
|
9
|
+
* A portable delegation that can be transported between users.
|
|
10
|
+
* Extends the base Delegation type with fields required for transport.
|
|
11
|
+
*
|
|
12
|
+
* @remarks
|
|
13
|
+
* PortableDelegation adds transport fields to Delegation:
|
|
14
|
+
* - `delegationHeader`: Structured authorization header for API calls
|
|
15
|
+
* - `ownerAddress`: Space owner's address for session creation
|
|
16
|
+
* - `chainId`: Chain ID for session creation
|
|
17
|
+
* - `host`: Optional server URL
|
|
18
|
+
*/
|
|
19
|
+
export interface PortableDelegation extends Omit<Delegation, "isRevoked"> {
|
|
20
|
+
/** The authorization header for this delegation (structured format) */
|
|
21
|
+
delegationHeader: {
|
|
22
|
+
Authorization: string;
|
|
23
|
+
};
|
|
24
|
+
/** The address of the space owner */
|
|
25
|
+
ownerAddress: string;
|
|
26
|
+
/** The chain ID */
|
|
27
|
+
chainId: number;
|
|
28
|
+
/** TinyCloud server URL where this delegation was created */
|
|
29
|
+
host?: string;
|
|
30
|
+
/** Whether the recipient is prevented from creating sub-delegations */
|
|
31
|
+
disableSubDelegation?: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Serialize a PortableDelegation for transport (e.g., over network).
|
|
35
|
+
*/
|
|
36
|
+
export declare function serializeDelegation(delegation: PortableDelegation): string;
|
|
37
|
+
/**
|
|
38
|
+
* Deserialize a PortableDelegation from transport.
|
|
39
|
+
* Handles both new format (cid) and legacy format (delegationCid).
|
|
40
|
+
*/
|
|
41
|
+
export declare function deserializeDelegation(data: string): PortableDelegation;
|
|
42
|
+
/**
|
|
43
|
+
* Provides access to a space via a received delegation.
|
|
44
|
+
*
|
|
45
|
+
* This is returned by TinyCloudWeb.useDelegation() and provides
|
|
46
|
+
* KV operations on the delegated space.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* // Receive a delegation from another user
|
|
51
|
+
* const delegation = deserializeDelegation(receivedData);
|
|
52
|
+
*
|
|
53
|
+
* // Use the delegation
|
|
54
|
+
* const access = await tcw.useDelegation(delegation);
|
|
55
|
+
*
|
|
56
|
+
* // Perform KV operations on the delegated space
|
|
57
|
+
* const data = await access.kv.get("shared/document.json");
|
|
58
|
+
* await access.kv.put("shared/notes.txt", "Hello!");
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare class DelegatedAccess {
|
|
62
|
+
private session;
|
|
63
|
+
private _delegation;
|
|
64
|
+
private host;
|
|
65
|
+
private _serviceContext;
|
|
66
|
+
private _kv;
|
|
67
|
+
constructor(session: TinyCloudSession, delegation: PortableDelegation, host: string);
|
|
68
|
+
/**
|
|
69
|
+
* Get the delegation this access was created from.
|
|
70
|
+
*/
|
|
71
|
+
get delegation(): PortableDelegation;
|
|
72
|
+
/**
|
|
73
|
+
* The space ID this access is for.
|
|
74
|
+
*/
|
|
75
|
+
get spaceId(): string;
|
|
76
|
+
/**
|
|
77
|
+
* The path this access is scoped to.
|
|
78
|
+
*/
|
|
79
|
+
get path(): string;
|
|
80
|
+
/**
|
|
81
|
+
* KV operations on the delegated space.
|
|
82
|
+
*/
|
|
83
|
+
get kv(): IKVService;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=delegation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delegation.d.ts","sourceRoot":"","sources":["../src/delegation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,UAAU,EACV,gBAAgB,EAEhB,UAAU,EAIX,MAAM,qBAAqB,CAAC;AAG7B;;;;;;;;;;GAUG;AACH,MAAM,WAAW,kBAAmB,SAAQ,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC;IACvE,uEAAuE;IACvE,gBAAgB,EAAE;QAAE,aAAa,EAAE,MAAM,CAAA;KAAE,CAAC;IAE5C,qCAAqC;IACrC,YAAY,EAAE,MAAM,CAAC;IAErB,mBAAmB;IACnB,OAAO,EAAE,MAAM,CAAC;IAEhB,6DAA6D;IAC7D,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,uEAAuE;IACvE,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,kBAAkB,GAAG,MAAM,CAK1E;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,CAStE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,OAAO,CAAmB;IAClC,OAAO,CAAC,WAAW,CAAqB;IACxC,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,eAAe,CAAiB;IACxC,OAAO,CAAC,GAAG,CAAY;gBAGrB,OAAO,EAAE,gBAAgB,EACzB,UAAU,EAAE,kBAAkB,EAC9B,IAAI,EAAE,MAAM;IA+Bd;;OAEG;IACH,IAAI,UAAU,IAAI,kBAAkB,CAEnC;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;OAEG;IACH,IAAI,EAAE,IAAI,UAAU,CAEnB;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { TinyCloudWeb, Config, ShareReceiveResult } from './modules/tcw';
|
|
2
|
+
export { UserAuthorization, IUserAuthorization } from './modules/UserAuthorization';
|
|
3
|
+
export { WebUserAuthorization, WebUserAuthorizationConfig, WebSignStrategy, WalletPopupStrategy, defaultWebSignStrategy, ModalSpaceCreationHandler, defaultWebSpaceCreationHandler, } from './authorization';
|
|
4
|
+
export { SignStrategy, SignRequest, SignResponse, SignCallback, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, EventEmitterStrategy, defaultSignStrategy, ISpaceCreationHandler, SpaceCreationContext, AutoApproveSpaceCreationHandler, defaultSpaceCreationHandler, } from '@tinycloud/sdk-core';
|
|
5
|
+
export * from '@tinycloud/web-core/client';
|
|
6
|
+
export * from '@tinycloud/web-core';
|
|
7
|
+
export { SiweMessage } from 'siwe';
|
|
8
|
+
export { TinyCloud, ISigner, ISessionStorage, IUserAuthorization as ICoreUserAuthorization, PersistedSessionData, SiweConfig, PartialSiweMessage, } from '@tinycloud/sdk-core';
|
|
9
|
+
export { IKVService, KVService, KVResponse, PrefixedKVService, IPrefixedKVService, } from '@tinycloud/sdk-core';
|
|
10
|
+
export { DelegationManager, DelegationManagerConfig, Delegation, CreateDelegationParams, DelegationChain, DelegationApiResponse, DelegationResult, DelegationError, DelegationErrorCodes, DelegationErrorCode, SharingService, createSharingService, ISharingService, SharingServiceConfig, EncodedShareData, ReceiveOptions, ShareAccess, JWK, KeyType, KeyInfo, CapabilityEntry, DelegationRecord, DelegationChainV2, DelegationDirection, DelegationFilters, SpaceOwnership, SpaceInfo, ShareSchema, ShareLink, ShareLinkData, IngestOptions, GenerateShareParams, } from '@tinycloud/sdk-core';
|
|
11
|
+
export { CapabilityKeyRegistry, ICapabilityKeyRegistry, createCapabilityKeyRegistry, StoredDelegationChain, CapabilityKeyRegistryErrorCodes, CapabilityKeyRegistryErrorCode, } from '@tinycloud/sdk-core';
|
|
12
|
+
export { SpaceService, ISpaceService, SpaceServiceConfig, SpaceErrorCodes, SpaceErrorCode, createSpaceService, parseSpaceUri, buildSpaceUri, Space, ISpace, SpaceConfig, ISpaceScopedDelegations, ISpaceScopedSharing, } from '@tinycloud/sdk-core';
|
|
13
|
+
export { ProtocolMismatchError, VersionCheckError, checkNodeVersion, } from '@tinycloud/sdk-core';
|
|
14
|
+
export { createKVService } from './modules/Storage/tinycloud/KVServiceAdapter';
|
|
15
|
+
export { PortableDelegation, DelegatedAccess, serializeDelegation, deserializeDelegation, } from './delegation';
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAKzE,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAA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