@tinycloud/web-sdk 1.7.2 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/BrowserENSResolver.d.ts +10 -0
- package/dist/adapters/BrowserENSResolver.d.ts.map +1 -0
- package/dist/adapters/BrowserNotificationHandler.d.ts +11 -0
- package/dist/adapters/BrowserNotificationHandler.d.ts.map +1 -0
- package/dist/adapters/BrowserSessionStorage.d.ts +9 -0
- package/dist/adapters/BrowserSessionStorage.d.ts.map +1 -0
- package/dist/adapters/BrowserWalletSigner.d.ts +22 -0
- package/dist/adapters/BrowserWalletSigner.d.ts.map +1 -0
- package/dist/adapters/BrowserWasmBindings.d.ts +23 -0
- package/dist/adapters/BrowserWasmBindings.d.ts.map +1 -0
- package/dist/adapters/index.d.ts +6 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/authorization/index.d.ts +1 -3
- package/dist/authorization/index.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/modules/Storage/tinycloud/types.schema.d.ts +6 -6
- package/dist/modules/index.d.ts +1 -1
- package/dist/modules/index.d.ts.map +1 -1
- package/dist/modules/keys/index.d.ts +0 -1
- package/dist/modules/keys/index.d.ts.map +1 -1
- package/dist/modules/tcw.d.ts +68 -656
- package/dist/modules/tcw.d.ts.map +1 -1
- package/dist/notifications/types.schema.d.ts +2 -2
- package/dist/providers/config.d.ts +44 -0
- package/dist/providers/config.d.ts.map +1 -0
- package/dist/providers/extension.d.ts +64 -0
- package/dist/providers/extension.d.ts.map +1 -0
- package/dist/providers/index.d.ts +10 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/types.d.ts +657 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/utils.d.ts +20 -0
- package/dist/providers/utils.d.ts.map +1 -0
- package/package.json +6 -6
- package/dist/authorization/WebUserAuthorization.d.ts +0 -297
- package/dist/authorization/WebUserAuthorization.d.ts.map +0 -1
- package/dist/delegation.d.ts +0 -84
- package/dist/delegation.d.ts.map +0 -1
- package/dist/modules/keys/WasmKeyProvider.d.ts +0 -126
- package/dist/modules/keys/WasmKeyProvider.d.ts.map +0 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider utility functions.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
6
|
+
import { ethers } from "ethers";
|
|
7
|
+
import { EnsData, RPCProvider } from "./types";
|
|
8
|
+
/**
|
|
9
|
+
* @param rpc - RPCProvider
|
|
10
|
+
* @returns an ethers provider based on the RPC configuration.
|
|
11
|
+
*/
|
|
12
|
+
export declare const getProvider: (rpc?: RPCProvider) => ethers.providers.BaseProvider;
|
|
13
|
+
/**
|
|
14
|
+
* Resolves ENS data supported by TCW.
|
|
15
|
+
* @param provider - Ethers provider.
|
|
16
|
+
* @param address - User address.
|
|
17
|
+
* @returns Object containing ENS data.
|
|
18
|
+
*/
|
|
19
|
+
export declare const resolveEns: (provider: ethers.providers.BaseProvider, address: string) => Promise<EnsData>;
|
|
20
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/providers/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,EAAsB,MAAM,QAAQ,CAAC;AACpD,OAAO,EAaL,OAAO,EACP,WAAW,EACZ,MAAM,SAAS,CAAC;AAEjB;;;GAGG;AACH,eAAO,MAAM,WAAW,SAChB,WAAW,KAChB,MAAM,CAAC,SAAS,CAAC,YAyCnB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,aACX,MAAM,CAAC,SAAS,CAAC,YAAY,WAE9B,MAAM,KACd,OAAO,CAAC,OAAO,CAqBjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinycloud/web-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "A set of tools and utilities to help you build your app with TinyCloud.",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -38,15 +38,15 @@
|
|
|
38
38
|
"@metamask/detect-provider": "^1.2.0",
|
|
39
39
|
"@multiformats/multiaddr": "^13.0.1",
|
|
40
40
|
"@multiformats/multiaddr-to-uri": "^12.0.0",
|
|
41
|
-
"@tinycloud/sdk
|
|
42
|
-
"@tinycloud/
|
|
41
|
+
"@tinycloud/node-sdk": "^2.0.1",
|
|
42
|
+
"@tinycloud/sdk-core": "^2.0.1",
|
|
43
43
|
"@tinycloud/web-sdk-wasm": "^1.7.0",
|
|
44
44
|
"assert": "^2.1.0",
|
|
45
45
|
"axios": "^1.7.9",
|
|
46
46
|
"browser": "^0.2.6",
|
|
47
47
|
"browserify-zlib": "^0.2.0",
|
|
48
48
|
"buffer": "^6.0.3",
|
|
49
|
-
"cross-env": "
|
|
49
|
+
"cross-env": "10.1.0",
|
|
50
50
|
"crypto-browserify": "^3.12.1",
|
|
51
51
|
"ethers": "^5.7.2",
|
|
52
52
|
"events": "^3.3.0",
|
|
@@ -71,12 +71,12 @@
|
|
|
71
71
|
"@types/lodash.merge": "^4.6.9",
|
|
72
72
|
"@types/node": "^18.19.74",
|
|
73
73
|
"@types/webpack": "^5.28.5",
|
|
74
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
74
|
+
"@typescript-eslint/eslint-plugin": "^8.57.1",
|
|
75
75
|
"@typescript-eslint/parser": "^5.62.0",
|
|
76
76
|
"@webpack-cli/generators": "^3.0.7",
|
|
77
77
|
"babel-jest": "^28.1.3",
|
|
78
78
|
"clean-webpack-plugin": "^4.0.0",
|
|
79
|
-
"copy-webpack-plugin": "^
|
|
79
|
+
"copy-webpack-plugin": "^14.0.0",
|
|
80
80
|
"declaration-bundler-webpack-plugin": "^1.0.3",
|
|
81
81
|
"eslint": "^8.57.1",
|
|
82
82
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
@@ -1,297 +0,0 @@
|
|
|
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
|
-
private _nodeFeatures;
|
|
124
|
-
constructor(config?: WebUserAuthorizationConfig);
|
|
125
|
-
/**
|
|
126
|
-
* Set or update the provider.
|
|
127
|
-
*/
|
|
128
|
-
private setProvider;
|
|
129
|
-
/**
|
|
130
|
-
* Whether this instance is in session-only mode (no wallet connected).
|
|
131
|
-
*/
|
|
132
|
-
get isSessionOnly(): boolean;
|
|
133
|
-
/**
|
|
134
|
-
* Get the appropriate DID for this user.
|
|
135
|
-
*
|
|
136
|
-
* - If wallet connected and signed in: returns PKH DID (persistent identity)
|
|
137
|
-
* - If session-only mode: returns session key DID (ephemeral)
|
|
138
|
-
*
|
|
139
|
-
* Use this for delegations and identity operations.
|
|
140
|
-
*/
|
|
141
|
-
get did(): string;
|
|
142
|
-
/**
|
|
143
|
-
* Get the session key DID (always available).
|
|
144
|
-
*
|
|
145
|
-
* Format: `did:key:z6Mk...#z6Mk...`
|
|
146
|
-
*/
|
|
147
|
-
get sessionDid(): string;
|
|
148
|
-
/**
|
|
149
|
-
* Get the session key JWK (always available).
|
|
150
|
-
*
|
|
151
|
-
* This is used for session-only mode operations like useDelegation()
|
|
152
|
-
* where we need the session key to create a session from a received delegation.
|
|
153
|
-
*
|
|
154
|
-
* @returns The JWK for the current session key
|
|
155
|
-
* @throws Error if session key not found
|
|
156
|
-
*/
|
|
157
|
-
getSessionKeyJwk(): JWK;
|
|
158
|
-
/**
|
|
159
|
-
* Connect a wallet to upgrade from session-only mode.
|
|
160
|
-
*
|
|
161
|
-
* This allows users who started in session-only mode (e.g., received
|
|
162
|
-
* delegations) to later connect a wallet and create their own space.
|
|
163
|
-
*
|
|
164
|
-
* @param provider - Web3 provider (e.g., window.ethereum)
|
|
165
|
-
* @param options - Optional configuration
|
|
166
|
-
*
|
|
167
|
-
* @example
|
|
168
|
-
* ```typescript
|
|
169
|
-
* // Start in session-only mode
|
|
170
|
-
* const auth = new WebUserAuthorization();
|
|
171
|
-
* console.log(auth.isSessionOnly); // true
|
|
172
|
-
* console.log(auth.did); // did:key:z6Mk... (session key DID)
|
|
173
|
-
*
|
|
174
|
-
* // User clicks "Connect Wallet"
|
|
175
|
-
* auth.connectWallet(window.ethereum);
|
|
176
|
-
* console.log(auth.isSessionOnly); // false
|
|
177
|
-
*
|
|
178
|
-
* // Now can sign in to create own space
|
|
179
|
-
* await auth.signIn();
|
|
180
|
-
* console.log(auth.did); // did:pkh:eip155:1:0x... (wallet DID)
|
|
181
|
-
* ```
|
|
182
|
-
*/
|
|
183
|
-
connectWallet(provider: providers.ExternalProvider | providers.Web3Provider, options?: {
|
|
184
|
-
spacePrefix?: string;
|
|
185
|
-
}): void;
|
|
186
|
-
/**
|
|
187
|
-
* Check if a wallet is connected (but may not be signed in).
|
|
188
|
-
*/
|
|
189
|
-
get isWalletConnected(): boolean;
|
|
190
|
-
/**
|
|
191
|
-
* The current active session (web-core compatible).
|
|
192
|
-
*/
|
|
193
|
-
get session(): ClientSession | undefined;
|
|
194
|
-
/**
|
|
195
|
-
* The current TinyCloud session with full delegation data.
|
|
196
|
-
*/
|
|
197
|
-
get tinyCloudSession(): TinyCloudSession | undefined;
|
|
198
|
-
get nodeFeatures(): string[];
|
|
199
|
-
/**
|
|
200
|
-
* Add an extension to the authorization flow.
|
|
201
|
-
*/
|
|
202
|
-
extend(extension: Extension): void;
|
|
203
|
-
/**
|
|
204
|
-
* Get the space ID for the current session.
|
|
205
|
-
*/
|
|
206
|
-
getSpaceId(): string | undefined;
|
|
207
|
-
/**
|
|
208
|
-
* Get the TinyCloud session.
|
|
209
|
-
*/
|
|
210
|
-
getTinycloudSession(): Session | undefined;
|
|
211
|
-
/**
|
|
212
|
-
* Get the configured TinyCloud hosts.
|
|
213
|
-
*/
|
|
214
|
-
getTinycloudHosts(): string[];
|
|
215
|
-
/**
|
|
216
|
-
* Sign in and create a new session.
|
|
217
|
-
*
|
|
218
|
-
* @throws Error if in session-only mode (no wallet connected)
|
|
219
|
-
*/
|
|
220
|
-
signIn(): Promise<ClientSession>;
|
|
221
|
-
/**
|
|
222
|
-
* Sign out and clear the current session.
|
|
223
|
-
*/
|
|
224
|
-
signOut(): Promise<void>;
|
|
225
|
-
/**
|
|
226
|
-
* Get the current wallet address.
|
|
227
|
-
*/
|
|
228
|
-
address(): string | undefined;
|
|
229
|
-
/**
|
|
230
|
-
* Get the current chain ID.
|
|
231
|
-
*/
|
|
232
|
-
chainId(): number | undefined;
|
|
233
|
-
/**
|
|
234
|
-
* Sign a message with the connected wallet.
|
|
235
|
-
*/
|
|
236
|
-
signMessage(message: string): Promise<string>;
|
|
237
|
-
/**
|
|
238
|
-
* Prepare a session for external signing.
|
|
239
|
-
*
|
|
240
|
-
* Use this when you need to sign the SIWE message externally (e.g., via
|
|
241
|
-
* a hardware wallet or WalletConnect that handles signing separately).
|
|
242
|
-
*
|
|
243
|
-
* @example
|
|
244
|
-
* ```typescript
|
|
245
|
-
* const { prepared, keyId, jwk, address, chainId } = await auth.prepareSessionForSigning();
|
|
246
|
-
* // Sign with external tool
|
|
247
|
-
* const signature = await walletConnect.signMessage(prepared.siwe);
|
|
248
|
-
* const session = await auth.signInWithPreparedSession(prepared, signature, keyId, jwk);
|
|
249
|
-
* ```
|
|
250
|
-
*/
|
|
251
|
-
prepareSessionForSigning(): Promise<{
|
|
252
|
-
prepared: {
|
|
253
|
-
siwe: string;
|
|
254
|
-
jwk: Record<string, unknown>;
|
|
255
|
-
spaceId: string;
|
|
256
|
-
verificationMethod: string;
|
|
257
|
-
};
|
|
258
|
-
keyId: string;
|
|
259
|
-
jwk: Record<string, unknown>;
|
|
260
|
-
address: string;
|
|
261
|
-
chainId: number;
|
|
262
|
-
}>;
|
|
263
|
-
/**
|
|
264
|
-
* Complete sign-in with a prepared session and signature.
|
|
265
|
-
*/
|
|
266
|
-
signInWithPreparedSession(prepared: {
|
|
267
|
-
siwe: string;
|
|
268
|
-
jwk: Record<string, unknown>;
|
|
269
|
-
spaceId: string;
|
|
270
|
-
verificationMethod: string;
|
|
271
|
-
}, signature: string, keyId: string, jwk: Record<string, unknown>): Promise<ClientSession>;
|
|
272
|
-
/**
|
|
273
|
-
* Ensure the user's space exists on the TinyCloud server.
|
|
274
|
-
*/
|
|
275
|
-
ensureSpaceExists(): Promise<void>;
|
|
276
|
-
/**
|
|
277
|
-
* Create the space on the TinyCloud server.
|
|
278
|
-
*/
|
|
279
|
-
private hostSpace;
|
|
280
|
-
/**
|
|
281
|
-
* Request a signature using the configured strategy.
|
|
282
|
-
*/
|
|
283
|
-
private requestSignature;
|
|
284
|
-
/**
|
|
285
|
-
* Request signature via event emitter.
|
|
286
|
-
*/
|
|
287
|
-
private requestSignatureViaEmitter;
|
|
288
|
-
/**
|
|
289
|
-
* Clear persisted session data.
|
|
290
|
-
*/
|
|
291
|
-
clearPersistedSession(address?: string): Promise<void>;
|
|
292
|
-
/**
|
|
293
|
-
* Check if a session is persisted for an address.
|
|
294
|
-
*/
|
|
295
|
-
isSessionPersisted(address: string): boolean;
|
|
296
|
-
}
|
|
297
|
-
//# sourceMappingURL=WebUserAuthorization.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,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AC;IA4FzB;;OAEG;IACG,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAyGxC;;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"}
|
package/dist/delegation.d.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
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
|
-
*/
|
|
40
|
-
export declare function deserializeDelegation(data: string): PortableDelegation;
|
|
41
|
-
/**
|
|
42
|
-
* Provides access to a space via a received delegation.
|
|
43
|
-
*
|
|
44
|
-
* This is returned by TinyCloudWeb.useDelegation() and provides
|
|
45
|
-
* KV operations on the delegated space.
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```typescript
|
|
49
|
-
* // Receive a delegation from another user
|
|
50
|
-
* const delegation = deserializeDelegation(receivedData);
|
|
51
|
-
*
|
|
52
|
-
* // Use the delegation
|
|
53
|
-
* const access = await tcw.useDelegation(delegation);
|
|
54
|
-
*
|
|
55
|
-
* // Perform KV operations on the delegated space
|
|
56
|
-
* const data = await access.kv.get("shared/document.json");
|
|
57
|
-
* await access.kv.put("shared/notes.txt", "Hello!");
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
export declare class DelegatedAccess {
|
|
61
|
-
private session;
|
|
62
|
-
private _delegation;
|
|
63
|
-
private host;
|
|
64
|
-
private _serviceContext;
|
|
65
|
-
private _kv;
|
|
66
|
-
constructor(session: TinyCloudSession, delegation: PortableDelegation, host: string);
|
|
67
|
-
/**
|
|
68
|
-
* Get the delegation this access was created from.
|
|
69
|
-
*/
|
|
70
|
-
get delegation(): PortableDelegation;
|
|
71
|
-
/**
|
|
72
|
-
* The space ID this access is for.
|
|
73
|
-
*/
|
|
74
|
-
get spaceId(): string;
|
|
75
|
-
/**
|
|
76
|
-
* The path this access is scoped to.
|
|
77
|
-
*/
|
|
78
|
-
get path(): string;
|
|
79
|
-
/**
|
|
80
|
-
* KV operations on the delegated space.
|
|
81
|
-
*/
|
|
82
|
-
get kv(): IKVService;
|
|
83
|
-
}
|
|
84
|
-
//# sourceMappingURL=delegation.d.ts.map
|
package/dist/delegation.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,CAOtE;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"}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WasmKeyProvider - KeyProvider implementation using WASM session manager.
|
|
3
|
-
*
|
|
4
|
-
* This provider wraps the SessionManager from web-sdk-wasm to provide
|
|
5
|
-
* cryptographic key operations required by the SharingService.
|
|
6
|
-
*
|
|
7
|
-
* Supports multiple named session keys that can coexist within a single
|
|
8
|
-
* session manager instance.
|
|
9
|
-
*
|
|
10
|
-
* @packageDocumentation
|
|
11
|
-
*/
|
|
12
|
-
import type { KeyProvider, JWK } from "@tinycloud/sdk-core";
|
|
13
|
-
import { tcwSession } from "@tinycloud/web-sdk-wasm";
|
|
14
|
-
/** Type alias for SessionManager from the tcwSession namespace */
|
|
15
|
-
type TCWSessionManager = tcwSession.TCWSessionManager;
|
|
16
|
-
/**
|
|
17
|
-
* Configuration for WasmKeyProvider.
|
|
18
|
-
*/
|
|
19
|
-
export interface WasmKeyProviderConfig {
|
|
20
|
-
/**
|
|
21
|
-
* Optional WASM session manager instance.
|
|
22
|
-
* If not provided, a new manager will be created.
|
|
23
|
-
*/
|
|
24
|
-
sessionManager?: TCWSessionManager;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* KeyProvider implementation for web-sdk using WASM session manager.
|
|
28
|
-
*
|
|
29
|
-
* This allows the SharingService to create new session keys for sharing links
|
|
30
|
-
* using the same cryptographic operations as the main session management.
|
|
31
|
-
*
|
|
32
|
-
* Multiple named keys can coexist and are identified by their key ID for
|
|
33
|
-
* delegation targeting.
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```typescript
|
|
37
|
-
* // Create with a shared session manager
|
|
38
|
-
* const sessionManager = new tcwSession.TCWSessionManager();
|
|
39
|
-
* const keyProvider = new WasmKeyProvider({ sessionManager });
|
|
40
|
-
*
|
|
41
|
-
* // Or create standalone (manages its own session manager)
|
|
42
|
-
* const keyProvider = new WasmKeyProvider();
|
|
43
|
-
*
|
|
44
|
-
* // Create multiple named keys
|
|
45
|
-
* const keyId1 = await keyProvider.createSessionKey("share:abc123");
|
|
46
|
-
* const keyId2 = await keyProvider.createSessionKey("share:def456");
|
|
47
|
-
*
|
|
48
|
-
* // Retrieve keys by ID
|
|
49
|
-
* const jwk1 = keyProvider.getJWK(keyId1);
|
|
50
|
-
* const did1 = await keyProvider.getDID(keyId1);
|
|
51
|
-
*
|
|
52
|
-
* // List all keys
|
|
53
|
-
* console.log(keyProvider.listKeys()); // ["share:abc123", "share:def456"]
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
export declare class WasmKeyProvider implements KeyProvider {
|
|
57
|
-
/** The WASM session manager instance */
|
|
58
|
-
private sessionManager?;
|
|
59
|
-
/** Promise that resolves when initialization is complete */
|
|
60
|
-
private initPromise?;
|
|
61
|
-
/**
|
|
62
|
-
* Create a new WasmKeyProvider.
|
|
63
|
-
*
|
|
64
|
-
* @param config - Optional configuration with session manager
|
|
65
|
-
*/
|
|
66
|
-
constructor(config?: WasmKeyProviderConfig);
|
|
67
|
-
/**
|
|
68
|
-
* Ensure the session manager is initialized.
|
|
69
|
-
* Creates a new one if not provided in config.
|
|
70
|
-
*/
|
|
71
|
-
private ensureInitialized;
|
|
72
|
-
/**
|
|
73
|
-
* Generate a new session key with the given name.
|
|
74
|
-
*
|
|
75
|
-
* This creates a new Ed25519 key pair in the WASM session manager.
|
|
76
|
-
* The key can then be used for signing delegations in sharing links.
|
|
77
|
-
*
|
|
78
|
-
* @param name - A unique name/ID for the key (e.g., "share:timestamp:random")
|
|
79
|
-
* @returns The key ID (same as the name provided)
|
|
80
|
-
*/
|
|
81
|
-
createSessionKey(name: string): Promise<string>;
|
|
82
|
-
/**
|
|
83
|
-
* Get the JWK (JSON Web Key) for a key.
|
|
84
|
-
*
|
|
85
|
-
* Returns the full JWK including the private key (d parameter),
|
|
86
|
-
* which is required for signing and for embedding in sharing links.
|
|
87
|
-
*
|
|
88
|
-
* @param keyId - The key ID to retrieve
|
|
89
|
-
* @returns The JWK object with public and private key components
|
|
90
|
-
* @throws Error if the key is not found
|
|
91
|
-
*/
|
|
92
|
-
getJWK(keyId: string): JWK;
|
|
93
|
-
/**
|
|
94
|
-
* Get the DID (Decentralized Identifier) for a key.
|
|
95
|
-
*
|
|
96
|
-
* Returns the did:key format DID derived from the key's public key.
|
|
97
|
-
* The DID can be used as the delegatee in delegations.
|
|
98
|
-
*
|
|
99
|
-
* @param keyId - The key ID to get the DID for
|
|
100
|
-
* @returns The did:key formatted DID string
|
|
101
|
-
* @throws Error if the key is not found
|
|
102
|
-
*/
|
|
103
|
-
getDID(keyId: string): Promise<string>;
|
|
104
|
-
/**
|
|
105
|
-
* List all session keys currently held by the provider.
|
|
106
|
-
*
|
|
107
|
-
* @returns Array of key IDs
|
|
108
|
-
*/
|
|
109
|
-
listKeys(): string[];
|
|
110
|
-
/**
|
|
111
|
-
* Check if a key exists in the provider.
|
|
112
|
-
*
|
|
113
|
-
* @param keyId - The key ID to check
|
|
114
|
-
* @returns True if the key exists
|
|
115
|
-
*/
|
|
116
|
-
hasKey(keyId: string): boolean;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Create a new WasmKeyProvider instance.
|
|
120
|
-
*
|
|
121
|
-
* @param sessionManager - Optional WASM session manager to use
|
|
122
|
-
* @returns A new WasmKeyProvider instance
|
|
123
|
-
*/
|
|
124
|
-
export declare function createWasmKeyProvider(sessionManager?: TCWSessionManager): WasmKeyProvider;
|
|
125
|
-
export {};
|
|
126
|
-
//# sourceMappingURL=WasmKeyProvider.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WasmKeyProvider.d.ts","sourceRoot":"","sources":["../../../src/modules/keys/WasmKeyProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAe,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAElE,kEAAkE;AAClE,KAAK,iBAAiB,GAAG,UAAU,CAAC,iBAAiB,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,cAAc,CAAC,EAAE,iBAAiB,CAAC;CACpC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBAAa,eAAgB,YAAW,WAAW;IACjD,wCAAwC;IACxC,OAAO,CAAC,cAAc,CAAC,CAAoB;IAE3C,4DAA4D;IAC5D,OAAO,CAAC,WAAW,CAAC,CAAgB;IAEpC;;;;OAIG;gBACS,MAAM,GAAE,qBAA0B;IAM9C;;;OAGG;YACW,iBAAiB;IAgB/B;;;;;;;;OAQG;IACG,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAOrD;;;;;;;;;OASG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG;IAa1B;;;;;;;;;OASG;IACG,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAM5C;;;;OAIG;IACH,QAAQ,IAAI,MAAM,EAAE;IAQpB;;;;;OAKG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAO/B;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,cAAc,CAAC,EAAE,iBAAiB,GAAG,eAAe,CAEzF"}
|