@dynamic-labs-wallet/browser-wallet-client 0.0.0-beta-191.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/index.cjs.d.ts +1 -0
- package/index.cjs.js +598 -0
- package/index.esm.d.ts +1 -0
- package/index.esm.js +581 -0
- package/package.json +30 -0
- package/src/client/client.d.ts +122 -0
- package/src/client/client.d.ts.map +1 -0
- package/src/client/index.d.ts +2 -0
- package/src/client/index.d.ts.map +1 -0
- package/src/index.d.ts +3 -0
- package/src/index.d.ts.map +1 -0
- package/src/services/iframeMessageHandler.d.ts +32 -0
- package/src/services/iframeMessageHandler.d.ts.map +1 -0
- package/src/services/logger.d.ts +3 -0
- package/src/services/logger.d.ts.map +1 -0
- package/src/services/messageTransportBridge.d.ts +3 -0
- package/src/services/messageTransportBridge.d.ts.map +1 -0
package/index.cjs.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|
package/index.cjs.js
ADDED
|
@@ -0,0 +1,598 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var messageTransport = require('@dynamic-labs/message-transport');
|
|
4
|
+
var logger$1 = require('@dynamic-labs/logger');
|
|
5
|
+
var core = require('@dynamic-labs-wallet/core');
|
|
6
|
+
|
|
7
|
+
const setupMessageTransportBridge = (messageTransport$1, iframe, iframeOrigin)=>{
|
|
8
|
+
if (!(iframe == null ? void 0 : iframe.contentWindow)) {
|
|
9
|
+
throw new Error('Iframe or contentWindow not available');
|
|
10
|
+
}
|
|
11
|
+
const logger = new logger$1.Logger('debug');
|
|
12
|
+
messageTransport$1.on((message)=>{
|
|
13
|
+
// Forward the message to webview via postMessage
|
|
14
|
+
if (message.origin === 'host') {
|
|
15
|
+
var _iframe_contentWindow;
|
|
16
|
+
iframe == null ? void 0 : (_iframe_contentWindow = iframe.contentWindow) == null ? void 0 : _iframe_contentWindow.postMessage(message, iframeOrigin);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const handleIncomingMessage = (message)=>{
|
|
20
|
+
const { data } = message;
|
|
21
|
+
if (!data) return;
|
|
22
|
+
if ((data == null ? void 0 : data.origin) !== 'webview') {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (typeof data !== 'object') {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const message = messageTransport.parseMessageTransportData(data);
|
|
30
|
+
messageTransport$1.emit(message);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
if (!(error instanceof SyntaxError)) {
|
|
33
|
+
logger.error('Error handling incoming message:', error);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Handle incoming message from android client
|
|
39
|
+
*/ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
document.addEventListener('message', handleIncomingMessage);
|
|
42
|
+
/**
|
|
43
|
+
* Handle incoming message from iOS client
|
|
44
|
+
*/ window.addEventListener('message', handleIncomingMessage);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
class iframeMessageHandler {
|
|
48
|
+
async getWallets(request) {
|
|
49
|
+
return this.requestChannel.request('getWallets', request);
|
|
50
|
+
}
|
|
51
|
+
async getWallet({ chainName, accountAddress, walletOperation, signedSessionId }) {
|
|
52
|
+
return this.requestChannel.request('getWallet', {
|
|
53
|
+
chainName,
|
|
54
|
+
accountAddress,
|
|
55
|
+
walletOperation,
|
|
56
|
+
signedSessionId
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async createWalletAccount(request) {
|
|
60
|
+
return this.requestChannel.request('createWalletAccount', request);
|
|
61
|
+
}
|
|
62
|
+
async requiresPasswordForOperation(request) {
|
|
63
|
+
return this.requestChannel.request('requiresPasswordForOperation', request);
|
|
64
|
+
}
|
|
65
|
+
async signMessage(request) {
|
|
66
|
+
return this.requestChannel.request('signMessage', request);
|
|
67
|
+
}
|
|
68
|
+
async signRawMessage(request) {
|
|
69
|
+
return this.requestChannel.request('signRawMessage', request);
|
|
70
|
+
}
|
|
71
|
+
async signTransaction(request) {
|
|
72
|
+
return this.requestChannel.request('signTransaction', request);
|
|
73
|
+
}
|
|
74
|
+
async isPasswordEncrypted(request) {
|
|
75
|
+
return this.requestChannel.request('isPasswordEncrypted', request);
|
|
76
|
+
}
|
|
77
|
+
async backupKeySharesToGoogleDrive(request) {
|
|
78
|
+
await this.requestChannel.request('backupKeySharesToGoogleDrive', request);
|
|
79
|
+
}
|
|
80
|
+
async restoreBackupFromGoogleDrive(request) {
|
|
81
|
+
return this.requestChannel.request('restoreBackupFromGoogleDrive', request);
|
|
82
|
+
}
|
|
83
|
+
async refreshWalletAccountShares(request) {
|
|
84
|
+
return this.requestChannel.request('refreshWalletAccountShares', request);
|
|
85
|
+
}
|
|
86
|
+
async reshare(request) {
|
|
87
|
+
return this.requestChannel.request('reshare', request);
|
|
88
|
+
}
|
|
89
|
+
async exportPrivateKey(request) {
|
|
90
|
+
return this.requestChannel.request('exportPrivateKey', request);
|
|
91
|
+
}
|
|
92
|
+
async verifyPassword(request) {
|
|
93
|
+
return this.requestChannel.request('verifyPassword', request);
|
|
94
|
+
}
|
|
95
|
+
async updatePassword(request) {
|
|
96
|
+
return this.requestChannel.request('updatePassword', request);
|
|
97
|
+
}
|
|
98
|
+
async importPrivateKey(request) {
|
|
99
|
+
return this.requestChannel.request('importPrivateKey', request);
|
|
100
|
+
}
|
|
101
|
+
async sendAuthToken(token) {
|
|
102
|
+
return this.requestChannel.request('sendAuthToken', token);
|
|
103
|
+
}
|
|
104
|
+
async exportClientKeyshares(request) {
|
|
105
|
+
return this.requestChannel.request('exportClientKeyshares', request);
|
|
106
|
+
}
|
|
107
|
+
async offlineExportPrivateKey(request) {
|
|
108
|
+
return this.requestChannel.request('offlineExportPrivateKey', request);
|
|
109
|
+
}
|
|
110
|
+
async cleanup() {
|
|
111
|
+
return this.requestChannel.request('cleanup');
|
|
112
|
+
}
|
|
113
|
+
constructor(messageTransport$1){
|
|
114
|
+
this.requestChannel = messageTransport.createRequestChannel(messageTransport$1);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const logger = new logger$1.Logger('DynamicWaasWalletClient');
|
|
119
|
+
|
|
120
|
+
class DynamicWalletClient {
|
|
121
|
+
// Simply load the iframe from localhost
|
|
122
|
+
async initialize() {
|
|
123
|
+
await this.doInitializeIframeCommunication();
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* this is called on class construction time
|
|
127
|
+
* @returns {Promise<void>} that resolves when the iframe is loaded and the message transport and iframe storage are initialized
|
|
128
|
+
*/ initializeIframeCommunication() {
|
|
129
|
+
if (!DynamicWalletClient.iframeLoadPromise) {
|
|
130
|
+
DynamicWalletClient.iframeLoadPromise = this.doInitializeIframeCommunication();
|
|
131
|
+
}
|
|
132
|
+
return DynamicWalletClient.iframeLoadPromise;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* initialize the iframe communication by awaiting the iframe load promise
|
|
136
|
+
* and initializing the message transport and iframe storage after iframe is successfully loaded
|
|
137
|
+
*/ async doInitializeIframeCommunication() {
|
|
138
|
+
try {
|
|
139
|
+
await this.loadIframe();
|
|
140
|
+
} catch (error) {
|
|
141
|
+
this.logger.error('Error initializing iframe:', error);
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* initialize the message transport after iframe is successfully loaded
|
|
147
|
+
*/ async initializeMessageTransport() {
|
|
148
|
+
await this.initializeIframeCommunication();
|
|
149
|
+
const transport = messageTransport.applyDefaultMessageOrigin({
|
|
150
|
+
defaultOrigin: 'host',
|
|
151
|
+
messageTransport: messageTransport.createMessageTransport()
|
|
152
|
+
});
|
|
153
|
+
this.messageTransport = transport;
|
|
154
|
+
if (!this.iframe) {
|
|
155
|
+
throw new Error('Iframe not available');
|
|
156
|
+
}
|
|
157
|
+
setupMessageTransportBridge(this.messageTransport, this.iframe, this.iframeDomain);
|
|
158
|
+
this.iframeMessageHandler = new iframeMessageHandler(this.messageTransport);
|
|
159
|
+
await this.initAuthToken();
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* securely exchange the auth token with iframe securely
|
|
163
|
+
*/ async initAuthToken() {
|
|
164
|
+
if (!this.iframeMessageHandler) {
|
|
165
|
+
throw new Error('Iframe message handler not initialized');
|
|
166
|
+
}
|
|
167
|
+
try {
|
|
168
|
+
// Send auth token to iframe
|
|
169
|
+
await this.iframeMessageHandler.sendAuthToken(this.authToken);
|
|
170
|
+
} catch (error) {
|
|
171
|
+
throw new Error('Failed to establish secure token exchange: ' + error);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
async loadIframe() {
|
|
175
|
+
// If the iframe is already loaded, just assign and resolve
|
|
176
|
+
if (DynamicWalletClient.sharedIframe) {
|
|
177
|
+
this.iframe = DynamicWalletClient.sharedIframe;
|
|
178
|
+
DynamicWalletClient.iframeInstanceCount++;
|
|
179
|
+
return Promise.resolve();
|
|
180
|
+
}
|
|
181
|
+
// If a load is in progress, wait for it, then assign
|
|
182
|
+
if (DynamicWalletClient.iframeLoadPromise) {
|
|
183
|
+
return DynamicWalletClient.iframeLoadPromise.then(()=>{
|
|
184
|
+
this.iframe = DynamicWalletClient.sharedIframe;
|
|
185
|
+
DynamicWalletClient.iframeInstanceCount++;
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
DynamicWalletClient.iframeLoadPromise = new Promise((resolve, reject)=>{
|
|
189
|
+
const iframe = document.createElement('iframe');
|
|
190
|
+
const iframeTimeoutId = setTimeout(()=>{
|
|
191
|
+
reject(new Error('Iframe load timeout'));
|
|
192
|
+
}, 10000);
|
|
193
|
+
iframe.style.display = 'none';
|
|
194
|
+
iframe.setAttribute('title', 'Dynamic Wallet Iframe');
|
|
195
|
+
iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-downloads');
|
|
196
|
+
iframe.setAttribute('referrerpolicy', 'origin');
|
|
197
|
+
iframe.style.position = 'fixed';
|
|
198
|
+
iframe.style.top = '0';
|
|
199
|
+
iframe.style.left = '0';
|
|
200
|
+
iframe.style.width = '0';
|
|
201
|
+
iframe.style.height = '0';
|
|
202
|
+
iframe.style.border = 'none';
|
|
203
|
+
iframe.style.pointerEvents = 'none';
|
|
204
|
+
var _this_instanceId;
|
|
205
|
+
const params = new URLSearchParams({
|
|
206
|
+
instanceId: (_this_instanceId = this.instanceId) != null ? _this_instanceId : '',
|
|
207
|
+
hostOrigin: window.location.origin,
|
|
208
|
+
environmentId: this.environmentId,
|
|
209
|
+
baseApiUrl: this.baseApiUrl,
|
|
210
|
+
baseMPCRelayApiUrl: this.baseMPCRelayApiUrl
|
|
211
|
+
});
|
|
212
|
+
iframe.src = `${this.iframeDomain}/waas-v1/${this.environmentId}?${params.toString()}`;
|
|
213
|
+
this.logger.debug('Creating iframe with src:', iframe.src);
|
|
214
|
+
document.body.appendChild(iframe);
|
|
215
|
+
iframe.onload = ()=>{
|
|
216
|
+
clearTimeout(iframeTimeoutId);
|
|
217
|
+
DynamicWalletClient.sharedIframe = iframe;
|
|
218
|
+
this.iframe = iframe;
|
|
219
|
+
DynamicWalletClient.iframeInstanceCount++;
|
|
220
|
+
resolve();
|
|
221
|
+
};
|
|
222
|
+
iframe.onerror = (error)=>{
|
|
223
|
+
clearTimeout(iframeTimeoutId);
|
|
224
|
+
this.logger.error('Iframe failed to load:', error);
|
|
225
|
+
reject(new Error('Failed to load iframe'));
|
|
226
|
+
};
|
|
227
|
+
});
|
|
228
|
+
return DynamicWalletClient.iframeLoadPromise;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Load an iframe for a specific container
|
|
232
|
+
* @param {HTMLElement} container - The container to which the iframe will be attached
|
|
233
|
+
* @returns {Promise<HTMLIFrameElement>} that resolves when the iframe is loaded
|
|
234
|
+
*/ loadIframeForContainer(container) {
|
|
235
|
+
return new Promise((resolve, reject)=>{
|
|
236
|
+
const iframe = document.createElement('iframe');
|
|
237
|
+
const iframeTimeoutId = setTimeout(()=>{
|
|
238
|
+
reject(new Error('Iframe load timeout'));
|
|
239
|
+
}, 10000);
|
|
240
|
+
iframe.style.display = 'block';
|
|
241
|
+
iframe.style.width = '100%';
|
|
242
|
+
iframe.style.height = '100%';
|
|
243
|
+
iframe.setAttribute('title', 'Dynamic Wallet Storage');
|
|
244
|
+
iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin');
|
|
245
|
+
iframe.setAttribute('referrerpolicy', 'origin');
|
|
246
|
+
var _this_instanceId;
|
|
247
|
+
const params = new URLSearchParams({
|
|
248
|
+
instanceId: (_this_instanceId = this.instanceId) != null ? _this_instanceId : '',
|
|
249
|
+
hostOrigin: window.location.origin,
|
|
250
|
+
environmentId: this.environmentId,
|
|
251
|
+
baseApiUrl: this.baseApiUrl,
|
|
252
|
+
baseMPCRelayApiUrl: this.baseMPCRelayApiUrl,
|
|
253
|
+
chain: this.chainName
|
|
254
|
+
});
|
|
255
|
+
iframe.src = `${this.iframeDomain}/waas-v1/${this.environmentId}?${params.toString()}`;
|
|
256
|
+
this.logger.debug('Creating iframe with src:', iframe.src);
|
|
257
|
+
// Add iframe to the provided container
|
|
258
|
+
container.appendChild(iframe);
|
|
259
|
+
iframe.onload = ()=>{
|
|
260
|
+
clearTimeout(iframeTimeoutId);
|
|
261
|
+
this.logger.debug('Iframe loaded successfully');
|
|
262
|
+
resolve(iframe);
|
|
263
|
+
};
|
|
264
|
+
iframe.onerror = (error)=>{
|
|
265
|
+
clearTimeout(iframeTimeoutId);
|
|
266
|
+
this.logger.error('Iframe failed to load:', error);
|
|
267
|
+
reject(new Error('Failed to load iframe'));
|
|
268
|
+
};
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Initializes the iframe display for a specific container.
|
|
273
|
+
*
|
|
274
|
+
* @param {HTMLElement} container - The container to which the iframe will be attached.
|
|
275
|
+
* @returns:
|
|
276
|
+
* iframe: HTMLIFrameElement;
|
|
277
|
+
* iframeDisplay: IframeDisplayChannelAdapter;
|
|
278
|
+
* cleanup: () => void;
|
|
279
|
+
*/ async initializeIframeDisplayForContainer({ container }) {
|
|
280
|
+
try {
|
|
281
|
+
const iframe = await this.loadIframeForContainer(container);
|
|
282
|
+
const transport = messageTransport.applyDefaultMessageOrigin({
|
|
283
|
+
defaultOrigin: 'host',
|
|
284
|
+
messageTransport: messageTransport.createMessageTransport()
|
|
285
|
+
});
|
|
286
|
+
setupMessageTransportBridge(transport, iframe, this.iframeDomain);
|
|
287
|
+
const iframeDisplay = new iframeMessageHandler(transport);
|
|
288
|
+
// Send auth token to iframe
|
|
289
|
+
await iframeDisplay.sendAuthToken(this.authToken);
|
|
290
|
+
return {
|
|
291
|
+
iframe,
|
|
292
|
+
iframeDisplay,
|
|
293
|
+
cleanup: ()=>{
|
|
294
|
+
container.removeChild(iframe);
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
} catch (error) {
|
|
298
|
+
this.logger.error('Error initializing iframe:', error);
|
|
299
|
+
throw error;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
async getWallets() {
|
|
303
|
+
await this.initializeMessageTransport();
|
|
304
|
+
if (!this.iframeMessageHandler) {
|
|
305
|
+
throw new Error('Iframe message handler not initialized');
|
|
306
|
+
}
|
|
307
|
+
return this.iframeMessageHandler.getWallets({
|
|
308
|
+
chainName: this.chainName
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
async getWallet({ accountAddress, walletOperation = core.WalletOperation.NO_OPERATION, signedSessionId }) {
|
|
312
|
+
await this.initializeMessageTransport();
|
|
313
|
+
if (!this.iframeMessageHandler) {
|
|
314
|
+
throw new Error('Iframe message handler not initialized');
|
|
315
|
+
}
|
|
316
|
+
return this.iframeMessageHandler.getWallet({
|
|
317
|
+
chainName: this.chainName,
|
|
318
|
+
accountAddress,
|
|
319
|
+
walletOperation,
|
|
320
|
+
signedSessionId
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
async createWalletAccount({ thresholdSignatureScheme, password = undefined, signedSessionId }) {
|
|
324
|
+
await this.initializeMessageTransport();
|
|
325
|
+
if (!this.iframeMessageHandler) {
|
|
326
|
+
throw new Error('Iframe message handler not initialized');
|
|
327
|
+
}
|
|
328
|
+
return this.iframeMessageHandler.createWalletAccount({
|
|
329
|
+
chainName: this.chainName,
|
|
330
|
+
thresholdSignatureScheme,
|
|
331
|
+
password,
|
|
332
|
+
signedSessionId
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
async requiresPasswordForOperation({ accountAddress, walletOperation = core.WalletOperation.REACH_THRESHOLD }) {
|
|
336
|
+
await this.initializeMessageTransport();
|
|
337
|
+
if (!this.iframeMessageHandler) {
|
|
338
|
+
throw new Error('Iframe message handler not initialized');
|
|
339
|
+
}
|
|
340
|
+
return this.iframeMessageHandler.requiresPasswordForOperation({
|
|
341
|
+
chainName: this.chainName,
|
|
342
|
+
accountAddress,
|
|
343
|
+
walletOperation
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
async isPasswordEncrypted({ accountAddress }) {
|
|
347
|
+
await this.initializeMessageTransport();
|
|
348
|
+
if (!this.iframeMessageHandler) {
|
|
349
|
+
throw new Error('Iframe message handler not initialized');
|
|
350
|
+
}
|
|
351
|
+
return this.iframeMessageHandler.isPasswordEncrypted({
|
|
352
|
+
chainName: this.chainName,
|
|
353
|
+
accountAddress
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
async signMessage({ message, accountAddress, password = undefined, signedSessionId }) {
|
|
357
|
+
await this.initializeMessageTransport();
|
|
358
|
+
if (!this.iframeMessageHandler) {
|
|
359
|
+
throw new Error('Iframe message handler not initialized');
|
|
360
|
+
}
|
|
361
|
+
return this.iframeMessageHandler.signMessage({
|
|
362
|
+
chainName: this.chainName,
|
|
363
|
+
message,
|
|
364
|
+
accountAddress,
|
|
365
|
+
password,
|
|
366
|
+
signedSessionId
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
async signRawMessage({ message, accountAddress, password = undefined, signedSessionId }) {
|
|
370
|
+
await this.initializeMessageTransport();
|
|
371
|
+
if (!this.iframeMessageHandler) {
|
|
372
|
+
throw new Error('Iframe message handler not initialized');
|
|
373
|
+
}
|
|
374
|
+
return this.iframeMessageHandler.signRawMessage({
|
|
375
|
+
chainName: this.chainName,
|
|
376
|
+
message,
|
|
377
|
+
accountAddress,
|
|
378
|
+
password,
|
|
379
|
+
signedSessionId
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Signs a transaction and returns the signature, @transaction is a string of the serialized transaction
|
|
384
|
+
* EVM:
|
|
385
|
+
* transaction = serializeTransaction()
|
|
386
|
+
* SOL:
|
|
387
|
+
* const messageBytes = transaction.serializeMessage();
|
|
388
|
+
* const messageToSign = Buffer.from(messageBytes).toString("hex");
|
|
389
|
+
* SUI:
|
|
390
|
+
* const txBytes = await txb.build({ client });
|
|
391
|
+
* const txString = Buffer.from(txBytes).toString("hex");
|
|
392
|
+
*/ async signTransaction({ senderAddress, transaction, password = undefined, signedSessionId }) {
|
|
393
|
+
await this.initializeMessageTransport();
|
|
394
|
+
if (!this.iframeMessageHandler) {
|
|
395
|
+
throw new Error('Iframe message handler not initialized');
|
|
396
|
+
}
|
|
397
|
+
return this.iframeMessageHandler.signTransaction({
|
|
398
|
+
chainName: this.chainName,
|
|
399
|
+
senderAddress,
|
|
400
|
+
transaction,
|
|
401
|
+
password,
|
|
402
|
+
signedSessionId
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
async backupKeySharesToGoogleDrive({ accountAddress, password = undefined, signedSessionId }) {
|
|
406
|
+
await this.initializeMessageTransport();
|
|
407
|
+
if (!this.iframeMessageHandler) {
|
|
408
|
+
throw new Error('Iframe message handler not initialized');
|
|
409
|
+
}
|
|
410
|
+
return this.iframeMessageHandler.backupKeySharesToGoogleDrive({
|
|
411
|
+
chainName: this.chainName,
|
|
412
|
+
accountAddress,
|
|
413
|
+
password,
|
|
414
|
+
signedSessionId
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
async restoreBackupFromGoogleDrive({ accountAddress, displayContainer, password, signedSessionId }) {
|
|
418
|
+
const { iframeDisplay } = await this.initializeIframeDisplayForContainer({
|
|
419
|
+
container: displayContainer
|
|
420
|
+
});
|
|
421
|
+
if (!iframeDisplay) {
|
|
422
|
+
throw new Error('Failed to initialize iframe handler with display functionality');
|
|
423
|
+
}
|
|
424
|
+
return iframeDisplay.restoreBackupFromGoogleDrive({
|
|
425
|
+
chainName: this.chainName,
|
|
426
|
+
accountAddress,
|
|
427
|
+
password,
|
|
428
|
+
signedSessionId
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
async refreshWalletAccountShares({ accountAddress, password, signedSessionId }) {
|
|
432
|
+
await this.initializeMessageTransport();
|
|
433
|
+
if (!this.iframeMessageHandler) {
|
|
434
|
+
throw new Error('Iframe message handler not initialized');
|
|
435
|
+
}
|
|
436
|
+
return this.iframeMessageHandler.refreshWalletAccountShares({
|
|
437
|
+
chainName: this.chainName,
|
|
438
|
+
accountAddress: accountAddress,
|
|
439
|
+
password: password,
|
|
440
|
+
signedSessionId
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
async reshare({ accountAddress, oldThresholdSignatureScheme, newThresholdSignatureScheme, password, signedSessionId }) {
|
|
444
|
+
await this.initializeMessageTransport();
|
|
445
|
+
if (!this.iframeMessageHandler) {
|
|
446
|
+
throw new Error('Iframe message handler not initialized');
|
|
447
|
+
}
|
|
448
|
+
return this.iframeMessageHandler.reshare({
|
|
449
|
+
chainName: this.chainName,
|
|
450
|
+
accountAddress,
|
|
451
|
+
oldThresholdSignatureScheme,
|
|
452
|
+
newThresholdSignatureScheme,
|
|
453
|
+
password,
|
|
454
|
+
signedSessionId
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
async exportPrivateKey({ accountAddress, displayContainer, password, signedSessionId }) {
|
|
458
|
+
const { iframeDisplay } = await this.initializeIframeDisplayForContainer({
|
|
459
|
+
container: displayContainer
|
|
460
|
+
});
|
|
461
|
+
if (!iframeDisplay) {
|
|
462
|
+
throw new Error('Failed to initialize iframe handler with display functionality');
|
|
463
|
+
}
|
|
464
|
+
return iframeDisplay.exportPrivateKey({
|
|
465
|
+
chainName: this.chainName,
|
|
466
|
+
accountAddress,
|
|
467
|
+
password,
|
|
468
|
+
signedSessionId
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
async verifyPassword({ accountAddress, password, walletOperation = core.WalletOperation.NO_OPERATION, signedSessionId }) {
|
|
472
|
+
await this.initializeMessageTransport();
|
|
473
|
+
if (!this.iframeMessageHandler) {
|
|
474
|
+
throw new Error('Iframe message handler not initialized');
|
|
475
|
+
}
|
|
476
|
+
return this.iframeMessageHandler.verifyPassword({
|
|
477
|
+
chainName: this.chainName,
|
|
478
|
+
accountAddress,
|
|
479
|
+
password,
|
|
480
|
+
walletOperation,
|
|
481
|
+
signedSessionId
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
async updatePassword({ accountAddress, existingPassword, newPassword, signedSessionId }) {
|
|
485
|
+
await this.initializeMessageTransport();
|
|
486
|
+
if (!this.iframeMessageHandler) {
|
|
487
|
+
throw new Error('Iframe message handler not initialized');
|
|
488
|
+
}
|
|
489
|
+
return this.iframeMessageHandler.updatePassword({
|
|
490
|
+
chainName: this.chainName,
|
|
491
|
+
accountAddress,
|
|
492
|
+
existingPassword,
|
|
493
|
+
newPassword,
|
|
494
|
+
signedSessionId
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
async importPrivateKey({ privateKey, thresholdSignatureScheme }) {
|
|
498
|
+
await this.initializeMessageTransport();
|
|
499
|
+
if (!this.iframeMessageHandler) {
|
|
500
|
+
throw new Error('Iframe message handler not initialized');
|
|
501
|
+
}
|
|
502
|
+
return this.iframeMessageHandler.importPrivateKey({
|
|
503
|
+
chainName: this.chainName,
|
|
504
|
+
privateKey,
|
|
505
|
+
thresholdSignatureScheme
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
async exportClientKeyshares({ accountAddress, password, signedSessionId }) {
|
|
509
|
+
await this.initializeMessageTransport();
|
|
510
|
+
if (!this.iframeMessageHandler) {
|
|
511
|
+
throw new Error('Iframe message handler not initialized');
|
|
512
|
+
}
|
|
513
|
+
return this.iframeMessageHandler.exportClientKeyshares({
|
|
514
|
+
chainName: this.chainName,
|
|
515
|
+
accountAddress,
|
|
516
|
+
password,
|
|
517
|
+
signedSessionId
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* keyShares is stringified list of EcdsaKeygenResult[] and Ed25519KeygenResult[]
|
|
522
|
+
*/ async offlineExportPrivateKey({ keyShares, derivationPath }) {
|
|
523
|
+
await this.initializeMessageTransport();
|
|
524
|
+
if (!this.iframeMessageHandler) {
|
|
525
|
+
throw new Error('Iframe message handler not initialized');
|
|
526
|
+
}
|
|
527
|
+
const args = {
|
|
528
|
+
chainName: this.chainName,
|
|
529
|
+
keyShares,
|
|
530
|
+
derivationPath
|
|
531
|
+
};
|
|
532
|
+
const serializedArgs = JSON.stringify(args);
|
|
533
|
+
const argsBuffer = new TextEncoder().encode(serializedArgs);
|
|
534
|
+
const base64Args = Buffer.from(argsBuffer).toString('base64');
|
|
535
|
+
return this.iframeMessageHandler.offlineExportPrivateKey({
|
|
536
|
+
chainName: this.chainName,
|
|
537
|
+
base64Args
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
async cleanup() {
|
|
541
|
+
await this.initializeMessageTransport();
|
|
542
|
+
if (!this.iframeMessageHandler) {
|
|
543
|
+
throw new Error('Iframe message handler not initialized');
|
|
544
|
+
}
|
|
545
|
+
await this.iframeMessageHandler.cleanup();
|
|
546
|
+
if (this.iframe) {
|
|
547
|
+
DynamicWalletClient.iframeInstanceCount--;
|
|
548
|
+
if (DynamicWalletClient.sharedIframe && DynamicWalletClient.iframeInstanceCount === 0) {
|
|
549
|
+
document.body.removeChild(DynamicWalletClient.sharedIframe);
|
|
550
|
+
DynamicWalletClient.sharedIframe = null;
|
|
551
|
+
DynamicWalletClient.iframeLoadPromise = null;
|
|
552
|
+
}
|
|
553
|
+
this.iframe = null;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, chainName, debug }){
|
|
557
|
+
this.logger = logger;
|
|
558
|
+
this.instanceId = null;
|
|
559
|
+
this.iframeDomain = null;
|
|
560
|
+
this.messageTransport = null;
|
|
561
|
+
this.iframeMessageHandler = null;
|
|
562
|
+
this.iframe = null;
|
|
563
|
+
this.environmentId = environmentId;
|
|
564
|
+
this.authToken = authToken;
|
|
565
|
+
this.baseApiUrl = baseApiUrl;
|
|
566
|
+
this.baseMPCRelayApiUrl = baseMPCRelayApiUrl;
|
|
567
|
+
this.chainName = chainName;
|
|
568
|
+
const environment = core.getEnvironmentFromUrl(baseApiUrl);
|
|
569
|
+
this.iframeDomain = core.IFRAME_DOMAIN_MAP[environment];
|
|
570
|
+
// Generate unique instanceId when client is created
|
|
571
|
+
this.instanceId = crypto.randomUUID();
|
|
572
|
+
this.debug = Boolean(debug);
|
|
573
|
+
this.logger.setLogLevel(this.debug ? 'DEBUG' : 'INFO');
|
|
574
|
+
// initialize the client
|
|
575
|
+
this.initialize();
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
DynamicWalletClient.iframeLoadPromise = null;
|
|
579
|
+
DynamicWalletClient.sharedIframe = null;
|
|
580
|
+
DynamicWalletClient.iframeInstanceCount = 0;
|
|
581
|
+
|
|
582
|
+
Object.defineProperty(exports, "MPC_RELAY_PREPROD_API_URL", {
|
|
583
|
+
enumerable: true,
|
|
584
|
+
get: function () { return core.MPC_RELAY_PREPROD_API_URL; }
|
|
585
|
+
});
|
|
586
|
+
Object.defineProperty(exports, "MPC_RELAY_PROD_API_URL", {
|
|
587
|
+
enumerable: true,
|
|
588
|
+
get: function () { return core.MPC_RELAY_PROD_API_URL; }
|
|
589
|
+
});
|
|
590
|
+
Object.defineProperty(exports, "ThresholdSignatureScheme", {
|
|
591
|
+
enumerable: true,
|
|
592
|
+
get: function () { return core.ThresholdSignatureScheme; }
|
|
593
|
+
});
|
|
594
|
+
Object.defineProperty(exports, "WalletOperation", {
|
|
595
|
+
enumerable: true,
|
|
596
|
+
get: function () { return core.WalletOperation; }
|
|
597
|
+
});
|
|
598
|
+
exports.DynamicWalletClient = DynamicWalletClient;
|
package/index.esm.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|