@dynamic-labs-wallet/browser-wallet-client 0.0.117 → 0.0.119
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.js +161 -136
- package/index.esm.js +162 -137
- package/package.json +2 -2
- package/src/client/client.d.ts +2 -67
- package/src/client/client.d.ts.map +1 -1
- package/src/client/iframeManager/IframeManager.d.ts +86 -0
- package/src/client/iframeManager/IframeManager.d.ts.map +1 -0
- package/src/client/iframeManager/index.d.ts +2 -0
- package/src/client/iframeManager/index.d.ts.map +1 -0
package/index.cjs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var uuid = require('uuid');
|
|
4
3
|
var core = require('@dynamic-labs-wallet/core');
|
|
4
|
+
var uuid = require('uuid');
|
|
5
5
|
var messageTransport = require('@dynamic-labs/message-transport');
|
|
6
6
|
var logger$1 = require('@dynamic-labs/logger');
|
|
7
7
|
|
|
@@ -116,7 +116,7 @@ const setupMessageTransportBridge = (messageTransport$1, iframe, iframeOrigin)=>
|
|
|
116
116
|
*/ window.addEventListener('message', handleIncomingMessage);
|
|
117
117
|
};
|
|
118
118
|
|
|
119
|
-
class
|
|
119
|
+
class IframeManager {
|
|
120
120
|
// Simply load the iframe from localhost
|
|
121
121
|
async initialize() {
|
|
122
122
|
await this.doInitializeIframeCommunication();
|
|
@@ -125,10 +125,10 @@ class DynamicWalletClient {
|
|
|
125
125
|
* this is called on class construction time
|
|
126
126
|
* @returns {Promise<void>} that resolves when the iframe is loaded and the message transport and iframe storage are initialized
|
|
127
127
|
*/ initializeIframeCommunication() {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
return
|
|
128
|
+
var _IframeManager;
|
|
129
|
+
var _iframeLoadPromise;
|
|
130
|
+
(_iframeLoadPromise = (_IframeManager = IframeManager).iframeLoadPromise) != null ? _iframeLoadPromise : _IframeManager.iframeLoadPromise = this.doInitializeIframeCommunication();
|
|
131
|
+
return IframeManager.iframeLoadPromise;
|
|
132
132
|
}
|
|
133
133
|
/**
|
|
134
134
|
* initialize the iframe communication by awaiting the iframe load promise
|
|
@@ -177,111 +177,124 @@ class DynamicWalletClient {
|
|
|
177
177
|
/**
|
|
178
178
|
* Reset the shared iframe and iframe load promise, and iframe instance count
|
|
179
179
|
*/ async resetSharedIframe() {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
180
|
+
IframeManager.sharedIframe = null;
|
|
181
|
+
IframeManager.iframeInstanceCount = 0;
|
|
182
|
+
IframeManager.iframeLoadPromise = null;
|
|
183
183
|
this.iframe = null;
|
|
184
184
|
this.iframeMessageHandler = null;
|
|
185
185
|
this.messageTransport = null;
|
|
186
186
|
// Double the timeout and cap at 60 seconds to give more time for slow networks
|
|
187
|
-
|
|
187
|
+
IframeManager.iframeLoadTimeout = Math.min(IframeManager.iframeLoadTimeout * 2, 60000);
|
|
188
188
|
}
|
|
189
189
|
async loadIframe() {
|
|
190
190
|
// If the iframe is already loaded, just assign and resolve
|
|
191
|
-
if (
|
|
192
|
-
this.
|
|
193
|
-
DynamicWalletClient.iframeInstanceCount++;
|
|
191
|
+
if (IframeManager.sharedIframe) {
|
|
192
|
+
this.assignExistingIframe();
|
|
194
193
|
return Promise.resolve();
|
|
195
194
|
}
|
|
196
195
|
// If a load is in progress, wait for it, then assign
|
|
197
|
-
if (
|
|
198
|
-
return
|
|
199
|
-
this.
|
|
200
|
-
DynamicWalletClient.iframeInstanceCount++;
|
|
196
|
+
if (IframeManager.iframeLoadPromise) {
|
|
197
|
+
return IframeManager.iframeLoadPromise.then(()=>{
|
|
198
|
+
this.assignExistingIframe();
|
|
201
199
|
});
|
|
202
200
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
201
|
+
IframeManager.iframeLoadPromise = this.createIframeLoadPromise();
|
|
202
|
+
return IframeManager.iframeLoadPromise;
|
|
203
|
+
}
|
|
204
|
+
assignExistingIframe() {
|
|
205
|
+
this.iframe = IframeManager.sharedIframe;
|
|
206
|
+
IframeManager.iframeInstanceCount++;
|
|
207
|
+
}
|
|
208
|
+
createIframeLoadPromise() {
|
|
209
|
+
return new Promise((resolve, reject)=>{
|
|
210
|
+
this.logger.info('Loading iframe for waas wallet client...', this.getIframeContext());
|
|
212
211
|
const iframe = document.createElement('iframe');
|
|
213
212
|
let messageListener = null;
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
iframeDomain: this.iframeDomain,
|
|
217
|
-
environmentId: this.environmentId,
|
|
218
|
-
sdkVersion: (_this_sdkVersion1 = this.sdkVersion) != null ? _this_sdkVersion1 : '',
|
|
219
|
-
instanceId: this.instanceId,
|
|
220
|
-
chainName: this.chainName,
|
|
221
|
-
iframeLoadTimeout: this.iframeLoadTimeout
|
|
222
|
-
};
|
|
223
|
-
const iframeTimeoutId = setTimeout(()=>{
|
|
224
|
-
if (messageListener) {
|
|
225
|
-
window.removeEventListener('message', messageListener);
|
|
226
|
-
}
|
|
227
|
-
this.resetSharedIframe();
|
|
228
|
-
this.logger.error(`(loadIframe) Iframe load timeout due to no handshake message from iframe, this could be network issues, incorrect iframe domain, or CORS errors that prevents iframe from being loaded or sending handshake message, context: ${JSON.stringify(context)}`);
|
|
229
|
-
reject(new Error(`(loadIframe) Iframe load timeout due to no handshake message from iframe, this could be network issues, incorrect iframe domain, or CORS errors that prevents iframe from being loaded or sending handshake message, context: ${JSON.stringify(context)}`));
|
|
230
|
-
}, this.iframeLoadTimeout);
|
|
231
|
-
// Set up message listener BEFORE creating iframe
|
|
232
|
-
messageListener = (event)=>{
|
|
233
|
-
if (event.source === iframe.contentWindow && event.data === `iframe-ready-${this.instanceId}`) {
|
|
234
|
-
if (messageListener) {
|
|
235
|
-
window.removeEventListener('message', messageListener);
|
|
236
|
-
}
|
|
237
|
-
clearTimeout(iframeTimeoutId);
|
|
238
|
-
DynamicWalletClient.sharedIframe = iframe;
|
|
239
|
-
this.iframe = iframe;
|
|
240
|
-
DynamicWalletClient.iframeInstanceCount++;
|
|
241
|
-
resolve();
|
|
242
|
-
this.logger.info('Iframe loaded successfully...', context);
|
|
243
|
-
}
|
|
244
|
-
};
|
|
213
|
+
const iframeTimeoutId = this.setupIframeTimeout(messageListener, reject);
|
|
214
|
+
messageListener = this.createMessageListener(iframe, iframeTimeoutId, resolve);
|
|
245
215
|
window.addEventListener('message', messageListener);
|
|
246
|
-
|
|
247
|
-
iframe
|
|
248
|
-
iframe.setAttribute('title', 'Dynamic Wallet Iframe');
|
|
249
|
-
iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-downloads');
|
|
250
|
-
iframe.setAttribute('referrerpolicy', 'origin');
|
|
251
|
-
iframe.style.position = 'fixed';
|
|
252
|
-
iframe.style.top = '0';
|
|
253
|
-
iframe.style.left = '0';
|
|
254
|
-
iframe.style.width = '0';
|
|
255
|
-
iframe.style.height = '0';
|
|
256
|
-
iframe.style.border = 'none';
|
|
257
|
-
iframe.style.pointerEvents = 'none';
|
|
258
|
-
var _this_instanceId, _this_sdkVersion2;
|
|
259
|
-
const params = new URLSearchParams({
|
|
260
|
-
instanceId: (_this_instanceId = this.instanceId) != null ? _this_instanceId : '',
|
|
261
|
-
hostOrigin: window.location.origin,
|
|
262
|
-
environmentId: this.environmentId,
|
|
263
|
-
baseApiUrl: this.baseApiUrl,
|
|
264
|
-
baseMPCRelayApiUrl: this.baseMPCRelayApiUrl,
|
|
265
|
-
sdkVersion: (_this_sdkVersion2 = this.sdkVersion) != null ? _this_sdkVersion2 : ''
|
|
266
|
-
});
|
|
267
|
-
iframe.src = `${this.iframeDomain}/waas-v1/${this.environmentId}?${params.toString()}`;
|
|
216
|
+
this.configureIframe(iframe);
|
|
217
|
+
this.setIframeSource(iframe);
|
|
268
218
|
this.logger.debug('Creating iframe with src:', iframe.src);
|
|
269
219
|
document.body.appendChild(iframe);
|
|
270
|
-
iframe
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
220
|
+
this.setupIframeEventHandlers(iframe, messageListener, iframeTimeoutId, reject);
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
getIframeContext() {
|
|
224
|
+
var _this_sdkVersion;
|
|
225
|
+
return {
|
|
226
|
+
iframeDomain: this.iframeDomain,
|
|
227
|
+
environmentId: this.environmentId,
|
|
228
|
+
sdkVersion: (_this_sdkVersion = this.sdkVersion) != null ? _this_sdkVersion : '',
|
|
229
|
+
instanceId: this.instanceId,
|
|
230
|
+
chainName: this.chainName,
|
|
231
|
+
iframeLoadTimeout: IframeManager.iframeLoadTimeout
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
setupIframeTimeout(messageListener, reject) {
|
|
235
|
+
return setTimeout(()=>{
|
|
236
|
+
if (messageListener) {
|
|
237
|
+
window.removeEventListener('message', messageListener);
|
|
238
|
+
}
|
|
239
|
+
this.resetSharedIframe();
|
|
240
|
+
const context = this.getIframeContext();
|
|
241
|
+
const errorMessage = `(loadIframe) Iframe load timeout due to no handshake message from iframe, this could be network issues, incorrect iframe domain, or CORS errors that prevents iframe from being loaded or sending handshake message, context: ${JSON.stringify(context)}`;
|
|
242
|
+
this.logger.error(errorMessage);
|
|
243
|
+
reject(new Error(errorMessage));
|
|
244
|
+
}, IframeManager.iframeLoadTimeout);
|
|
245
|
+
}
|
|
246
|
+
createMessageListener(iframe, iframeTimeoutId, resolve) {
|
|
247
|
+
const messageListener = (event)=>{
|
|
248
|
+
if (event.source === iframe.contentWindow && event.data === `iframe-ready-${this.instanceId}`) {
|
|
249
|
+
window.removeEventListener('message', messageListener);
|
|
278
250
|
clearTimeout(iframeTimeoutId);
|
|
279
|
-
|
|
280
|
-
this.
|
|
281
|
-
|
|
282
|
-
|
|
251
|
+
IframeManager.sharedIframe = iframe;
|
|
252
|
+
this.iframe = iframe;
|
|
253
|
+
IframeManager.iframeInstanceCount++;
|
|
254
|
+
resolve();
|
|
255
|
+
this.logger.info('Iframe loaded successfully...', this.getIframeContext());
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
return messageListener;
|
|
259
|
+
}
|
|
260
|
+
configureIframe(iframe) {
|
|
261
|
+
iframe.style.display = 'none';
|
|
262
|
+
iframe.setAttribute('title', 'Dynamic Wallet Iframe');
|
|
263
|
+
iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-downloads');
|
|
264
|
+
iframe.setAttribute('referrerpolicy', 'origin');
|
|
265
|
+
iframe.style.position = 'fixed';
|
|
266
|
+
iframe.style.top = '0';
|
|
267
|
+
iframe.style.left = '0';
|
|
268
|
+
iframe.style.width = '0';
|
|
269
|
+
iframe.style.height = '0';
|
|
270
|
+
iframe.style.border = 'none';
|
|
271
|
+
iframe.style.pointerEvents = 'none';
|
|
272
|
+
}
|
|
273
|
+
setIframeSource(iframe) {
|
|
274
|
+
var _this_instanceId, _this_sdkVersion;
|
|
275
|
+
const params = new URLSearchParams({
|
|
276
|
+
instanceId: (_this_instanceId = this.instanceId) != null ? _this_instanceId : '',
|
|
277
|
+
hostOrigin: window.location.origin,
|
|
278
|
+
environmentId: this.environmentId,
|
|
279
|
+
baseApiUrl: this.baseApiUrl,
|
|
280
|
+
baseMPCRelayApiUrl: this.baseMPCRelayApiUrl,
|
|
281
|
+
sdkVersion: (_this_sdkVersion = this.sdkVersion) != null ? _this_sdkVersion : ''
|
|
283
282
|
});
|
|
284
|
-
|
|
283
|
+
iframe.src = `${this.iframeDomain}/waas-v1/${this.environmentId}?${params.toString()}`;
|
|
284
|
+
}
|
|
285
|
+
setupIframeEventHandlers(iframe, messageListener, iframeTimeoutId, reject) {
|
|
286
|
+
iframe.onload = ()=>{
|
|
287
|
+
this.logger.debug('Iframe onload fired, waiting for ready message...');
|
|
288
|
+
};
|
|
289
|
+
iframe.onerror = (error)=>{
|
|
290
|
+
if (messageListener) {
|
|
291
|
+
window.removeEventListener('message', messageListener);
|
|
292
|
+
}
|
|
293
|
+
clearTimeout(iframeTimeoutId);
|
|
294
|
+
this.logger.error('Iframe failed to load due to errors: ', error);
|
|
295
|
+
this.resetSharedIframe();
|
|
296
|
+
reject(new Error('Failed to load iframe...'));
|
|
297
|
+
};
|
|
285
298
|
}
|
|
286
299
|
/**
|
|
287
300
|
* Load an iframe for a specific container
|
|
@@ -296,7 +309,7 @@ class DynamicWalletClient {
|
|
|
296
309
|
sdkVersion: (_this_sdkVersion = this.sdkVersion) != null ? _this_sdkVersion : '',
|
|
297
310
|
instanceId: this.instanceId,
|
|
298
311
|
chainName: this.chainName,
|
|
299
|
-
iframeLoadTimeout:
|
|
312
|
+
iframeLoadTimeout: IframeManager.iframeLoadTimeout
|
|
300
313
|
};
|
|
301
314
|
this.logger.info(`Loading iframe for container...`, context);
|
|
302
315
|
const iframe = document.createElement('iframe');
|
|
@@ -307,7 +320,7 @@ class DynamicWalletClient {
|
|
|
307
320
|
}
|
|
308
321
|
this.logger.error(`(loadIframeForContainer) Iframe load timeout due to no handshake message from iframe, this could be network issues, incorrect iframe domain, or CORS errors that prevents iframe from being loaded or sending handshake message, context: ${JSON.stringify(context)}`);
|
|
309
322
|
reject(new Error(`(loadIframeForContainer) Iframe load timeout due to no handshake message from iframe, this could be network issues, incorrect iframe domain, or CORS errors that prevents iframe from being loaded or sending handshake message, context: ${JSON.stringify(context)}`));
|
|
310
|
-
},
|
|
323
|
+
}, IframeManager.iframeLoadTimeout);
|
|
311
324
|
iframe.style.display = 'block';
|
|
312
325
|
iframe.style.width = '100%';
|
|
313
326
|
iframe.style.height = '100%';
|
|
@@ -346,9 +359,9 @@ class DynamicWalletClient {
|
|
|
346
359
|
window.removeEventListener('message', messageListener);
|
|
347
360
|
}
|
|
348
361
|
clearTimeout(iframeTimeoutId);
|
|
349
|
-
|
|
362
|
+
IframeManager.sharedIframe = iframe;
|
|
350
363
|
this.iframe = iframe;
|
|
351
|
-
|
|
364
|
+
IframeManager.iframeInstanceCount++;
|
|
352
365
|
resolve(iframe);
|
|
353
366
|
var _this_sdkVersion;
|
|
354
367
|
this.logger.info('Iframe loaded successfully...', {
|
|
@@ -394,6 +407,49 @@ class DynamicWalletClient {
|
|
|
394
407
|
throw error;
|
|
395
408
|
}
|
|
396
409
|
}
|
|
410
|
+
async cleanup() {
|
|
411
|
+
await this.initializeMessageTransport();
|
|
412
|
+
if (!this.iframeMessageHandler) {
|
|
413
|
+
throw new Error('Iframe message handler not initialized');
|
|
414
|
+
}
|
|
415
|
+
await this.iframeMessageHandler.cleanup();
|
|
416
|
+
if (this.iframe) {
|
|
417
|
+
IframeManager.iframeInstanceCount--;
|
|
418
|
+
if (IframeManager.sharedIframe && IframeManager.iframeInstanceCount === 0) {
|
|
419
|
+
document.body.removeChild(IframeManager.sharedIframe);
|
|
420
|
+
IframeManager.sharedIframe = null;
|
|
421
|
+
IframeManager.iframeLoadPromise = null;
|
|
422
|
+
}
|
|
423
|
+
this.iframe = null;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, chainName, sdkVersion, debug }){
|
|
427
|
+
this.logger = logger;
|
|
428
|
+
this.instanceId = null;
|
|
429
|
+
this.iframeDomain = null;
|
|
430
|
+
this.messageTransport = null;
|
|
431
|
+
this.iframeMessageHandler = null;
|
|
432
|
+
this.iframe = null;
|
|
433
|
+
this.environmentId = environmentId;
|
|
434
|
+
this.authToken = authToken;
|
|
435
|
+
this.baseApiUrl = baseApiUrl;
|
|
436
|
+
this.baseMPCRelayApiUrl = baseMPCRelayApiUrl;
|
|
437
|
+
this.chainName = chainName;
|
|
438
|
+
this.sdkVersion = sdkVersion;
|
|
439
|
+
const environment = core.getEnvironmentFromUrl(baseApiUrl);
|
|
440
|
+
this.iframeDomain = core.IFRAME_DOMAIN_MAP[environment];
|
|
441
|
+
// Generate unique instanceId when client is created
|
|
442
|
+
this.instanceId = uuid.v4();
|
|
443
|
+
this.debug = Boolean(debug);
|
|
444
|
+
this.logger.setLogLevel(this.debug ? 'DEBUG' : 'INFO');
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
IframeManager.iframeLoadPromise = null;
|
|
448
|
+
IframeManager.iframeLoadTimeout = 10000;
|
|
449
|
+
IframeManager.sharedIframe = null;
|
|
450
|
+
IframeManager.iframeInstanceCount = 0;
|
|
451
|
+
|
|
452
|
+
class DynamicWalletClient extends IframeManager {
|
|
397
453
|
async getWallets() {
|
|
398
454
|
await this.initializeMessageTransport();
|
|
399
455
|
if (!this.iframeMessageHandler) {
|
|
@@ -663,49 +719,18 @@ class DynamicWalletClient {
|
|
|
663
719
|
base64Args
|
|
664
720
|
});
|
|
665
721
|
}
|
|
666
|
-
async cleanup() {
|
|
667
|
-
await this.initializeMessageTransport();
|
|
668
|
-
if (!this.iframeMessageHandler) {
|
|
669
|
-
throw new Error('Iframe message handler not initialized');
|
|
670
|
-
}
|
|
671
|
-
await this.iframeMessageHandler.cleanup();
|
|
672
|
-
if (this.iframe) {
|
|
673
|
-
DynamicWalletClient.iframeInstanceCount--;
|
|
674
|
-
if (DynamicWalletClient.sharedIframe && DynamicWalletClient.iframeInstanceCount === 0) {
|
|
675
|
-
document.body.removeChild(DynamicWalletClient.sharedIframe);
|
|
676
|
-
DynamicWalletClient.sharedIframe = null;
|
|
677
|
-
DynamicWalletClient.iframeLoadPromise = null;
|
|
678
|
-
}
|
|
679
|
-
this.iframe = null;
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
722
|
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, chainName, sdkVersion, debug }){
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
this.baseApiUrl = baseApiUrl;
|
|
693
|
-
this.baseMPCRelayApiUrl = baseMPCRelayApiUrl;
|
|
694
|
-
this.chainName = chainName;
|
|
695
|
-
this.sdkVersion = sdkVersion;
|
|
696
|
-
const environment = core.getEnvironmentFromUrl(baseApiUrl);
|
|
697
|
-
this.iframeDomain = core.IFRAME_DOMAIN_MAP[environment];
|
|
698
|
-
// Generate unique instanceId when client is created
|
|
699
|
-
this.instanceId = uuid.v4();
|
|
700
|
-
this.debug = Boolean(debug);
|
|
701
|
-
this.logger.setLogLevel(this.debug ? 'DEBUG' : 'INFO');
|
|
702
|
-
// initialize the client
|
|
703
|
-
this.initialize();
|
|
723
|
+
super({
|
|
724
|
+
environmentId,
|
|
725
|
+
authToken,
|
|
726
|
+
baseApiUrl,
|
|
727
|
+
baseMPCRelayApiUrl,
|
|
728
|
+
chainName,
|
|
729
|
+
sdkVersion,
|
|
730
|
+
debug
|
|
731
|
+
});
|
|
704
732
|
}
|
|
705
733
|
}
|
|
706
|
-
DynamicWalletClient.iframeLoadPromise = null;
|
|
707
|
-
DynamicWalletClient.sharedIframe = null;
|
|
708
|
-
DynamicWalletClient.iframeInstanceCount = 0;
|
|
709
734
|
|
|
710
735
|
Object.defineProperty(exports, "MPC_RELAY_PREPROD_API_URL", {
|
|
711
736
|
enumerable: true,
|
package/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { WalletOperation, getEnvironmentFromUrl, IFRAME_DOMAIN_MAP } from '@dynamic-labs-wallet/core';
|
|
1
|
+
import { getEnvironmentFromUrl, IFRAME_DOMAIN_MAP, WalletOperation } from '@dynamic-labs-wallet/core';
|
|
3
2
|
export { MPC_RELAY_PREPROD_API_URL, MPC_RELAY_PROD_API_URL, ThresholdSignatureScheme, WalletOperation } from '@dynamic-labs-wallet/core';
|
|
3
|
+
import { v4 } from 'uuid';
|
|
4
4
|
import { createRequestChannel, parseMessageTransportData, applyDefaultMessageOrigin, createMessageTransport } from '@dynamic-labs/message-transport';
|
|
5
5
|
import { Logger } from '@dynamic-labs/logger';
|
|
6
6
|
|
|
@@ -115,7 +115,7 @@ const setupMessageTransportBridge = (messageTransport, iframe, iframeOrigin)=>{
|
|
|
115
115
|
*/ window.addEventListener('message', handleIncomingMessage);
|
|
116
116
|
};
|
|
117
117
|
|
|
118
|
-
class
|
|
118
|
+
class IframeManager {
|
|
119
119
|
// Simply load the iframe from localhost
|
|
120
120
|
async initialize() {
|
|
121
121
|
await this.doInitializeIframeCommunication();
|
|
@@ -124,10 +124,10 @@ class DynamicWalletClient {
|
|
|
124
124
|
* this is called on class construction time
|
|
125
125
|
* @returns {Promise<void>} that resolves when the iframe is loaded and the message transport and iframe storage are initialized
|
|
126
126
|
*/ initializeIframeCommunication() {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return
|
|
127
|
+
var _IframeManager;
|
|
128
|
+
var _iframeLoadPromise;
|
|
129
|
+
(_iframeLoadPromise = (_IframeManager = IframeManager).iframeLoadPromise) != null ? _iframeLoadPromise : _IframeManager.iframeLoadPromise = this.doInitializeIframeCommunication();
|
|
130
|
+
return IframeManager.iframeLoadPromise;
|
|
131
131
|
}
|
|
132
132
|
/**
|
|
133
133
|
* initialize the iframe communication by awaiting the iframe load promise
|
|
@@ -176,111 +176,124 @@ class DynamicWalletClient {
|
|
|
176
176
|
/**
|
|
177
177
|
* Reset the shared iframe and iframe load promise, and iframe instance count
|
|
178
178
|
*/ async resetSharedIframe() {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
179
|
+
IframeManager.sharedIframe = null;
|
|
180
|
+
IframeManager.iframeInstanceCount = 0;
|
|
181
|
+
IframeManager.iframeLoadPromise = null;
|
|
182
182
|
this.iframe = null;
|
|
183
183
|
this.iframeMessageHandler = null;
|
|
184
184
|
this.messageTransport = null;
|
|
185
185
|
// Double the timeout and cap at 60 seconds to give more time for slow networks
|
|
186
|
-
|
|
186
|
+
IframeManager.iframeLoadTimeout = Math.min(IframeManager.iframeLoadTimeout * 2, 60000);
|
|
187
187
|
}
|
|
188
188
|
async loadIframe() {
|
|
189
189
|
// If the iframe is already loaded, just assign and resolve
|
|
190
|
-
if (
|
|
191
|
-
this.
|
|
192
|
-
DynamicWalletClient.iframeInstanceCount++;
|
|
190
|
+
if (IframeManager.sharedIframe) {
|
|
191
|
+
this.assignExistingIframe();
|
|
193
192
|
return Promise.resolve();
|
|
194
193
|
}
|
|
195
194
|
// If a load is in progress, wait for it, then assign
|
|
196
|
-
if (
|
|
197
|
-
return
|
|
198
|
-
this.
|
|
199
|
-
DynamicWalletClient.iframeInstanceCount++;
|
|
195
|
+
if (IframeManager.iframeLoadPromise) {
|
|
196
|
+
return IframeManager.iframeLoadPromise.then(()=>{
|
|
197
|
+
this.assignExistingIframe();
|
|
200
198
|
});
|
|
201
199
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
200
|
+
IframeManager.iframeLoadPromise = this.createIframeLoadPromise();
|
|
201
|
+
return IframeManager.iframeLoadPromise;
|
|
202
|
+
}
|
|
203
|
+
assignExistingIframe() {
|
|
204
|
+
this.iframe = IframeManager.sharedIframe;
|
|
205
|
+
IframeManager.iframeInstanceCount++;
|
|
206
|
+
}
|
|
207
|
+
createIframeLoadPromise() {
|
|
208
|
+
return new Promise((resolve, reject)=>{
|
|
209
|
+
this.logger.info('Loading iframe for waas wallet client...', this.getIframeContext());
|
|
211
210
|
const iframe = document.createElement('iframe');
|
|
212
211
|
let messageListener = null;
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
iframeDomain: this.iframeDomain,
|
|
216
|
-
environmentId: this.environmentId,
|
|
217
|
-
sdkVersion: (_this_sdkVersion1 = this.sdkVersion) != null ? _this_sdkVersion1 : '',
|
|
218
|
-
instanceId: this.instanceId,
|
|
219
|
-
chainName: this.chainName,
|
|
220
|
-
iframeLoadTimeout: this.iframeLoadTimeout
|
|
221
|
-
};
|
|
222
|
-
const iframeTimeoutId = setTimeout(()=>{
|
|
223
|
-
if (messageListener) {
|
|
224
|
-
window.removeEventListener('message', messageListener);
|
|
225
|
-
}
|
|
226
|
-
this.resetSharedIframe();
|
|
227
|
-
this.logger.error(`(loadIframe) Iframe load timeout due to no handshake message from iframe, this could be network issues, incorrect iframe domain, or CORS errors that prevents iframe from being loaded or sending handshake message, context: ${JSON.stringify(context)}`);
|
|
228
|
-
reject(new Error(`(loadIframe) Iframe load timeout due to no handshake message from iframe, this could be network issues, incorrect iframe domain, or CORS errors that prevents iframe from being loaded or sending handshake message, context: ${JSON.stringify(context)}`));
|
|
229
|
-
}, this.iframeLoadTimeout);
|
|
230
|
-
// Set up message listener BEFORE creating iframe
|
|
231
|
-
messageListener = (event)=>{
|
|
232
|
-
if (event.source === iframe.contentWindow && event.data === `iframe-ready-${this.instanceId}`) {
|
|
233
|
-
if (messageListener) {
|
|
234
|
-
window.removeEventListener('message', messageListener);
|
|
235
|
-
}
|
|
236
|
-
clearTimeout(iframeTimeoutId);
|
|
237
|
-
DynamicWalletClient.sharedIframe = iframe;
|
|
238
|
-
this.iframe = iframe;
|
|
239
|
-
DynamicWalletClient.iframeInstanceCount++;
|
|
240
|
-
resolve();
|
|
241
|
-
this.logger.info('Iframe loaded successfully...', context);
|
|
242
|
-
}
|
|
243
|
-
};
|
|
212
|
+
const iframeTimeoutId = this.setupIframeTimeout(messageListener, reject);
|
|
213
|
+
messageListener = this.createMessageListener(iframe, iframeTimeoutId, resolve);
|
|
244
214
|
window.addEventListener('message', messageListener);
|
|
245
|
-
|
|
246
|
-
iframe
|
|
247
|
-
iframe.setAttribute('title', 'Dynamic Wallet Iframe');
|
|
248
|
-
iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-downloads');
|
|
249
|
-
iframe.setAttribute('referrerpolicy', 'origin');
|
|
250
|
-
iframe.style.position = 'fixed';
|
|
251
|
-
iframe.style.top = '0';
|
|
252
|
-
iframe.style.left = '0';
|
|
253
|
-
iframe.style.width = '0';
|
|
254
|
-
iframe.style.height = '0';
|
|
255
|
-
iframe.style.border = 'none';
|
|
256
|
-
iframe.style.pointerEvents = 'none';
|
|
257
|
-
var _this_instanceId, _this_sdkVersion2;
|
|
258
|
-
const params = new URLSearchParams({
|
|
259
|
-
instanceId: (_this_instanceId = this.instanceId) != null ? _this_instanceId : '',
|
|
260
|
-
hostOrigin: window.location.origin,
|
|
261
|
-
environmentId: this.environmentId,
|
|
262
|
-
baseApiUrl: this.baseApiUrl,
|
|
263
|
-
baseMPCRelayApiUrl: this.baseMPCRelayApiUrl,
|
|
264
|
-
sdkVersion: (_this_sdkVersion2 = this.sdkVersion) != null ? _this_sdkVersion2 : ''
|
|
265
|
-
});
|
|
266
|
-
iframe.src = `${this.iframeDomain}/waas-v1/${this.environmentId}?${params.toString()}`;
|
|
215
|
+
this.configureIframe(iframe);
|
|
216
|
+
this.setIframeSource(iframe);
|
|
267
217
|
this.logger.debug('Creating iframe with src:', iframe.src);
|
|
268
218
|
document.body.appendChild(iframe);
|
|
269
|
-
iframe
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
219
|
+
this.setupIframeEventHandlers(iframe, messageListener, iframeTimeoutId, reject);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
getIframeContext() {
|
|
223
|
+
var _this_sdkVersion;
|
|
224
|
+
return {
|
|
225
|
+
iframeDomain: this.iframeDomain,
|
|
226
|
+
environmentId: this.environmentId,
|
|
227
|
+
sdkVersion: (_this_sdkVersion = this.sdkVersion) != null ? _this_sdkVersion : '',
|
|
228
|
+
instanceId: this.instanceId,
|
|
229
|
+
chainName: this.chainName,
|
|
230
|
+
iframeLoadTimeout: IframeManager.iframeLoadTimeout
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
setupIframeTimeout(messageListener, reject) {
|
|
234
|
+
return setTimeout(()=>{
|
|
235
|
+
if (messageListener) {
|
|
236
|
+
window.removeEventListener('message', messageListener);
|
|
237
|
+
}
|
|
238
|
+
this.resetSharedIframe();
|
|
239
|
+
const context = this.getIframeContext();
|
|
240
|
+
const errorMessage = `(loadIframe) Iframe load timeout due to no handshake message from iframe, this could be network issues, incorrect iframe domain, or CORS errors that prevents iframe from being loaded or sending handshake message, context: ${JSON.stringify(context)}`;
|
|
241
|
+
this.logger.error(errorMessage);
|
|
242
|
+
reject(new Error(errorMessage));
|
|
243
|
+
}, IframeManager.iframeLoadTimeout);
|
|
244
|
+
}
|
|
245
|
+
createMessageListener(iframe, iframeTimeoutId, resolve) {
|
|
246
|
+
const messageListener = (event)=>{
|
|
247
|
+
if (event.source === iframe.contentWindow && event.data === `iframe-ready-${this.instanceId}`) {
|
|
248
|
+
window.removeEventListener('message', messageListener);
|
|
277
249
|
clearTimeout(iframeTimeoutId);
|
|
278
|
-
|
|
279
|
-
this.
|
|
280
|
-
|
|
281
|
-
|
|
250
|
+
IframeManager.sharedIframe = iframe;
|
|
251
|
+
this.iframe = iframe;
|
|
252
|
+
IframeManager.iframeInstanceCount++;
|
|
253
|
+
resolve();
|
|
254
|
+
this.logger.info('Iframe loaded successfully...', this.getIframeContext());
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
return messageListener;
|
|
258
|
+
}
|
|
259
|
+
configureIframe(iframe) {
|
|
260
|
+
iframe.style.display = 'none';
|
|
261
|
+
iframe.setAttribute('title', 'Dynamic Wallet Iframe');
|
|
262
|
+
iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-downloads');
|
|
263
|
+
iframe.setAttribute('referrerpolicy', 'origin');
|
|
264
|
+
iframe.style.position = 'fixed';
|
|
265
|
+
iframe.style.top = '0';
|
|
266
|
+
iframe.style.left = '0';
|
|
267
|
+
iframe.style.width = '0';
|
|
268
|
+
iframe.style.height = '0';
|
|
269
|
+
iframe.style.border = 'none';
|
|
270
|
+
iframe.style.pointerEvents = 'none';
|
|
271
|
+
}
|
|
272
|
+
setIframeSource(iframe) {
|
|
273
|
+
var _this_instanceId, _this_sdkVersion;
|
|
274
|
+
const params = new URLSearchParams({
|
|
275
|
+
instanceId: (_this_instanceId = this.instanceId) != null ? _this_instanceId : '',
|
|
276
|
+
hostOrigin: window.location.origin,
|
|
277
|
+
environmentId: this.environmentId,
|
|
278
|
+
baseApiUrl: this.baseApiUrl,
|
|
279
|
+
baseMPCRelayApiUrl: this.baseMPCRelayApiUrl,
|
|
280
|
+
sdkVersion: (_this_sdkVersion = this.sdkVersion) != null ? _this_sdkVersion : ''
|
|
282
281
|
});
|
|
283
|
-
|
|
282
|
+
iframe.src = `${this.iframeDomain}/waas-v1/${this.environmentId}?${params.toString()}`;
|
|
283
|
+
}
|
|
284
|
+
setupIframeEventHandlers(iframe, messageListener, iframeTimeoutId, reject) {
|
|
285
|
+
iframe.onload = ()=>{
|
|
286
|
+
this.logger.debug('Iframe onload fired, waiting for ready message...');
|
|
287
|
+
};
|
|
288
|
+
iframe.onerror = (error)=>{
|
|
289
|
+
if (messageListener) {
|
|
290
|
+
window.removeEventListener('message', messageListener);
|
|
291
|
+
}
|
|
292
|
+
clearTimeout(iframeTimeoutId);
|
|
293
|
+
this.logger.error('Iframe failed to load due to errors: ', error);
|
|
294
|
+
this.resetSharedIframe();
|
|
295
|
+
reject(new Error('Failed to load iframe...'));
|
|
296
|
+
};
|
|
284
297
|
}
|
|
285
298
|
/**
|
|
286
299
|
* Load an iframe for a specific container
|
|
@@ -295,7 +308,7 @@ class DynamicWalletClient {
|
|
|
295
308
|
sdkVersion: (_this_sdkVersion = this.sdkVersion) != null ? _this_sdkVersion : '',
|
|
296
309
|
instanceId: this.instanceId,
|
|
297
310
|
chainName: this.chainName,
|
|
298
|
-
iframeLoadTimeout:
|
|
311
|
+
iframeLoadTimeout: IframeManager.iframeLoadTimeout
|
|
299
312
|
};
|
|
300
313
|
this.logger.info(`Loading iframe for container...`, context);
|
|
301
314
|
const iframe = document.createElement('iframe');
|
|
@@ -306,7 +319,7 @@ class DynamicWalletClient {
|
|
|
306
319
|
}
|
|
307
320
|
this.logger.error(`(loadIframeForContainer) Iframe load timeout due to no handshake message from iframe, this could be network issues, incorrect iframe domain, or CORS errors that prevents iframe from being loaded or sending handshake message, context: ${JSON.stringify(context)}`);
|
|
308
321
|
reject(new Error(`(loadIframeForContainer) Iframe load timeout due to no handshake message from iframe, this could be network issues, incorrect iframe domain, or CORS errors that prevents iframe from being loaded or sending handshake message, context: ${JSON.stringify(context)}`));
|
|
309
|
-
},
|
|
322
|
+
}, IframeManager.iframeLoadTimeout);
|
|
310
323
|
iframe.style.display = 'block';
|
|
311
324
|
iframe.style.width = '100%';
|
|
312
325
|
iframe.style.height = '100%';
|
|
@@ -345,9 +358,9 @@ class DynamicWalletClient {
|
|
|
345
358
|
window.removeEventListener('message', messageListener);
|
|
346
359
|
}
|
|
347
360
|
clearTimeout(iframeTimeoutId);
|
|
348
|
-
|
|
361
|
+
IframeManager.sharedIframe = iframe;
|
|
349
362
|
this.iframe = iframe;
|
|
350
|
-
|
|
363
|
+
IframeManager.iframeInstanceCount++;
|
|
351
364
|
resolve(iframe);
|
|
352
365
|
var _this_sdkVersion;
|
|
353
366
|
this.logger.info('Iframe loaded successfully...', {
|
|
@@ -393,6 +406,49 @@ class DynamicWalletClient {
|
|
|
393
406
|
throw error;
|
|
394
407
|
}
|
|
395
408
|
}
|
|
409
|
+
async cleanup() {
|
|
410
|
+
await this.initializeMessageTransport();
|
|
411
|
+
if (!this.iframeMessageHandler) {
|
|
412
|
+
throw new Error('Iframe message handler not initialized');
|
|
413
|
+
}
|
|
414
|
+
await this.iframeMessageHandler.cleanup();
|
|
415
|
+
if (this.iframe) {
|
|
416
|
+
IframeManager.iframeInstanceCount--;
|
|
417
|
+
if (IframeManager.sharedIframe && IframeManager.iframeInstanceCount === 0) {
|
|
418
|
+
document.body.removeChild(IframeManager.sharedIframe);
|
|
419
|
+
IframeManager.sharedIframe = null;
|
|
420
|
+
IframeManager.iframeLoadPromise = null;
|
|
421
|
+
}
|
|
422
|
+
this.iframe = null;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, chainName, sdkVersion, debug }){
|
|
426
|
+
this.logger = logger;
|
|
427
|
+
this.instanceId = null;
|
|
428
|
+
this.iframeDomain = null;
|
|
429
|
+
this.messageTransport = null;
|
|
430
|
+
this.iframeMessageHandler = null;
|
|
431
|
+
this.iframe = null;
|
|
432
|
+
this.environmentId = environmentId;
|
|
433
|
+
this.authToken = authToken;
|
|
434
|
+
this.baseApiUrl = baseApiUrl;
|
|
435
|
+
this.baseMPCRelayApiUrl = baseMPCRelayApiUrl;
|
|
436
|
+
this.chainName = chainName;
|
|
437
|
+
this.sdkVersion = sdkVersion;
|
|
438
|
+
const environment = getEnvironmentFromUrl(baseApiUrl);
|
|
439
|
+
this.iframeDomain = IFRAME_DOMAIN_MAP[environment];
|
|
440
|
+
// Generate unique instanceId when client is created
|
|
441
|
+
this.instanceId = v4();
|
|
442
|
+
this.debug = Boolean(debug);
|
|
443
|
+
this.logger.setLogLevel(this.debug ? 'DEBUG' : 'INFO');
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
IframeManager.iframeLoadPromise = null;
|
|
447
|
+
IframeManager.iframeLoadTimeout = 10000;
|
|
448
|
+
IframeManager.sharedIframe = null;
|
|
449
|
+
IframeManager.iframeInstanceCount = 0;
|
|
450
|
+
|
|
451
|
+
class DynamicWalletClient extends IframeManager {
|
|
396
452
|
async getWallets() {
|
|
397
453
|
await this.initializeMessageTransport();
|
|
398
454
|
if (!this.iframeMessageHandler) {
|
|
@@ -662,48 +718,17 @@ class DynamicWalletClient {
|
|
|
662
718
|
base64Args
|
|
663
719
|
});
|
|
664
720
|
}
|
|
665
|
-
async cleanup() {
|
|
666
|
-
await this.initializeMessageTransport();
|
|
667
|
-
if (!this.iframeMessageHandler) {
|
|
668
|
-
throw new Error('Iframe message handler not initialized');
|
|
669
|
-
}
|
|
670
|
-
await this.iframeMessageHandler.cleanup();
|
|
671
|
-
if (this.iframe) {
|
|
672
|
-
DynamicWalletClient.iframeInstanceCount--;
|
|
673
|
-
if (DynamicWalletClient.sharedIframe && DynamicWalletClient.iframeInstanceCount === 0) {
|
|
674
|
-
document.body.removeChild(DynamicWalletClient.sharedIframe);
|
|
675
|
-
DynamicWalletClient.sharedIframe = null;
|
|
676
|
-
DynamicWalletClient.iframeLoadPromise = null;
|
|
677
|
-
}
|
|
678
|
-
this.iframe = null;
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
721
|
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, chainName, sdkVersion, debug }){
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
this.baseApiUrl = baseApiUrl;
|
|
692
|
-
this.baseMPCRelayApiUrl = baseMPCRelayApiUrl;
|
|
693
|
-
this.chainName = chainName;
|
|
694
|
-
this.sdkVersion = sdkVersion;
|
|
695
|
-
const environment = getEnvironmentFromUrl(baseApiUrl);
|
|
696
|
-
this.iframeDomain = IFRAME_DOMAIN_MAP[environment];
|
|
697
|
-
// Generate unique instanceId when client is created
|
|
698
|
-
this.instanceId = v4();
|
|
699
|
-
this.debug = Boolean(debug);
|
|
700
|
-
this.logger.setLogLevel(this.debug ? 'DEBUG' : 'INFO');
|
|
701
|
-
// initialize the client
|
|
702
|
-
this.initialize();
|
|
722
|
+
super({
|
|
723
|
+
environmentId,
|
|
724
|
+
authToken,
|
|
725
|
+
baseApiUrl,
|
|
726
|
+
baseMPCRelayApiUrl,
|
|
727
|
+
chainName,
|
|
728
|
+
sdkVersion,
|
|
729
|
+
debug
|
|
730
|
+
});
|
|
703
731
|
}
|
|
704
732
|
}
|
|
705
|
-
DynamicWalletClient.iframeLoadPromise = null;
|
|
706
|
-
DynamicWalletClient.sharedIframe = null;
|
|
707
|
-
DynamicWalletClient.iframeInstanceCount = 0;
|
|
708
733
|
|
|
709
734
|
export { DynamicWalletClient };
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs-wallet/browser-wallet-client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.119",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@dynamic-labs-wallet/core": "0.0.
|
|
7
|
+
"@dynamic-labs-wallet/core": "0.0.119",
|
|
8
8
|
"@dynamic-labs/logger": "^4.9.9",
|
|
9
9
|
"@dynamic-labs/message-transport": "^4.9.9",
|
|
10
10
|
"uuid": "11.1.0"
|
package/src/client/client.d.ts
CHANGED
|
@@ -1,25 +1,7 @@
|
|
|
1
1
|
import type { BackupKeySharesToGoogleDriveRequest, CreateWalletAccountRequest, CreateWalletAccountResponse, ExportClientKeysharesRequest, GetWalletResponse, ImportPrivateKeyRequest, IsPasswordEncryptedRequest, OfflineExportPrivateKeyResponse, RefreshWalletAccountSharesRequest, RequiresPasswordForOperationRequest, ReshareRequest, SignMessageRequest, SignRawMessageRequest, SignTransactionRequest, SignTypedDataRequest, UpdatePasswordRequest, VerifyPasswordRequest } from '@dynamic-labs-wallet/core';
|
|
2
2
|
import { WalletOperation } from '@dynamic-labs-wallet/core';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export declare class DynamicWalletClient {
|
|
6
|
-
protected chainName: string;
|
|
7
|
-
protected logger: import("@dynamic-labs/logger").Logger;
|
|
8
|
-
instanceId: string | null;
|
|
9
|
-
iframeDomain: string | null;
|
|
10
|
-
environmentId: string;
|
|
11
|
-
private authToken;
|
|
12
|
-
baseApiUrl: string;
|
|
13
|
-
baseMPCRelayApiUrl: string;
|
|
14
|
-
protected messageTransport: MessageTransportWithDefaultOrigin | null;
|
|
15
|
-
protected iframeMessageHandler: iframeMessageHandler | null;
|
|
16
|
-
private static iframeLoadPromise;
|
|
17
|
-
protected iframe: HTMLIFrameElement | null;
|
|
18
|
-
private debug;
|
|
19
|
-
iframeLoadTimeout: number;
|
|
20
|
-
private static sharedIframe;
|
|
21
|
-
private static iframeInstanceCount;
|
|
22
|
-
sdkVersion: string | undefined;
|
|
3
|
+
import { IframeManager } from './iframeManager';
|
|
4
|
+
export declare class DynamicWalletClient extends IframeManager {
|
|
23
5
|
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, chainName, sdkVersion, debug, }: {
|
|
24
6
|
environmentId: string;
|
|
25
7
|
authToken: string;
|
|
@@ -29,52 +11,6 @@ export declare class DynamicWalletClient {
|
|
|
29
11
|
sdkVersion?: string;
|
|
30
12
|
debug?: boolean;
|
|
31
13
|
});
|
|
32
|
-
initialize(): Promise<void>;
|
|
33
|
-
/**
|
|
34
|
-
* this is called on class construction time
|
|
35
|
-
* @returns {Promise<void>} that resolves when the iframe is loaded and the message transport and iframe storage are initialized
|
|
36
|
-
*/
|
|
37
|
-
initializeIframeCommunication(): Promise<void>;
|
|
38
|
-
/**
|
|
39
|
-
* initialize the iframe communication by awaiting the iframe load promise
|
|
40
|
-
* and initializing the message transport and iframe storage after iframe is successfully loaded
|
|
41
|
-
*/
|
|
42
|
-
private doInitializeIframeCommunication;
|
|
43
|
-
/**
|
|
44
|
-
* initialize the message transport after iframe is successfully loaded
|
|
45
|
-
*/
|
|
46
|
-
private initializeMessageTransport;
|
|
47
|
-
/**
|
|
48
|
-
* securely exchange the auth token with iframe securely
|
|
49
|
-
*/
|
|
50
|
-
private initAuthToken;
|
|
51
|
-
/**
|
|
52
|
-
* Reset the shared iframe and iframe load promise, and iframe instance count
|
|
53
|
-
*/
|
|
54
|
-
private resetSharedIframe;
|
|
55
|
-
private loadIframe;
|
|
56
|
-
/**
|
|
57
|
-
* Load an iframe for a specific container
|
|
58
|
-
* @param {HTMLElement} container - The container to which the iframe will be attached
|
|
59
|
-
* @returns {Promise<HTMLIFrameElement>} that resolves when the iframe is loaded
|
|
60
|
-
*/
|
|
61
|
-
private loadIframeForContainer;
|
|
62
|
-
/**
|
|
63
|
-
* Initializes the iframe display for a specific container.
|
|
64
|
-
*
|
|
65
|
-
* @param {HTMLElement} container - The container to which the iframe will be attached.
|
|
66
|
-
* @returns:
|
|
67
|
-
* iframe: HTMLIFrameElement;
|
|
68
|
-
* iframeDisplay: IframeDisplayChannelAdapter;
|
|
69
|
-
* cleanup: () => void;
|
|
70
|
-
*/
|
|
71
|
-
initializeIframeDisplayForContainer({ container, }: {
|
|
72
|
-
container: HTMLElement;
|
|
73
|
-
}): Promise<{
|
|
74
|
-
iframe: HTMLIFrameElement;
|
|
75
|
-
iframeDisplay: iframeMessageHandler;
|
|
76
|
-
cleanup: () => void;
|
|
77
|
-
}>;
|
|
78
14
|
getWallets(): Promise<GetWalletResponse[]>;
|
|
79
15
|
getWallet({ accountAddress, walletOperation, signedSessionId, authToken, }: {
|
|
80
16
|
accountAddress: string;
|
|
@@ -128,6 +64,5 @@ export declare class DynamicWalletClient {
|
|
|
128
64
|
keyShares: string[];
|
|
129
65
|
derivationPath?: string;
|
|
130
66
|
}): Promise<OfflineExportPrivateKeyResponse>;
|
|
131
|
-
cleanup(): Promise<void>;
|
|
132
67
|
}
|
|
133
68
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mCAAmC,EACnC,0BAA0B,EAC1B,2BAA2B,EAC3B,4BAA4B,EAC5B,iBAAiB,EACjB,uBAAuB,EACvB,0BAA0B,EAC1B,+BAA+B,EAC/B,iCAAiC,EACjC,mCAAmC,EACnC,cAAc,EACd,kBAAkB,EAClB,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/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EACR,eAAe,EACf,SAAS,GACV,EAAE,IAAI,CAAC,4BAA4B,EAAE,WAAW,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAelE;;OAEG;IACG,uBAAuB,CAAC,EAC5B,SAAS,EACT,cAAc,GACf,EAAE;QACD,SAAS,EAAE,MAAM,EAAE,CAAC;QACpB,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,GAAG,OAAO,CAAC,+BAA+B,CAAC;CAoB7C"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { type MessageTransportWithDefaultOrigin } from '@dynamic-labs/message-transport';
|
|
2
|
+
import { iframeMessageHandler } from '../../services/iframeMessageHandler';
|
|
3
|
+
export declare class IframeManager {
|
|
4
|
+
protected chainName: string;
|
|
5
|
+
protected logger: import("@dynamic-labs/logger").Logger;
|
|
6
|
+
instanceId: string | null;
|
|
7
|
+
iframeDomain: string | null;
|
|
8
|
+
environmentId: string;
|
|
9
|
+
private readonly authToken;
|
|
10
|
+
baseApiUrl: string;
|
|
11
|
+
baseMPCRelayApiUrl: string;
|
|
12
|
+
protected messageTransport: MessageTransportWithDefaultOrigin | null;
|
|
13
|
+
protected iframeMessageHandler: iframeMessageHandler | null;
|
|
14
|
+
private static iframeLoadPromise;
|
|
15
|
+
protected iframe: HTMLIFrameElement | null;
|
|
16
|
+
private readonly debug;
|
|
17
|
+
static iframeLoadTimeout: number;
|
|
18
|
+
private static sharedIframe;
|
|
19
|
+
private static iframeInstanceCount;
|
|
20
|
+
sdkVersion: string | undefined;
|
|
21
|
+
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, chainName, sdkVersion, debug, }: {
|
|
22
|
+
environmentId: string;
|
|
23
|
+
authToken: string;
|
|
24
|
+
baseApiUrl: string;
|
|
25
|
+
baseMPCRelayApiUrl: string;
|
|
26
|
+
chainName: string;
|
|
27
|
+
sdkVersion?: string;
|
|
28
|
+
debug?: boolean;
|
|
29
|
+
});
|
|
30
|
+
initialize(): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* this is called on class construction time
|
|
33
|
+
* @returns {Promise<void>} that resolves when the iframe is loaded and the message transport and iframe storage are initialized
|
|
34
|
+
*/
|
|
35
|
+
initializeIframeCommunication(): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* initialize the iframe communication by awaiting the iframe load promise
|
|
38
|
+
* and initializing the message transport and iframe storage after iframe is successfully loaded
|
|
39
|
+
*/
|
|
40
|
+
private doInitializeIframeCommunication;
|
|
41
|
+
/**
|
|
42
|
+
* initialize the message transport after iframe is successfully loaded
|
|
43
|
+
*/
|
|
44
|
+
protected initializeMessageTransport(): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* securely exchange the auth token with iframe securely
|
|
47
|
+
*/
|
|
48
|
+
private initAuthToken;
|
|
49
|
+
/**
|
|
50
|
+
* Reset the shared iframe and iframe load promise, and iframe instance count
|
|
51
|
+
*/
|
|
52
|
+
private resetSharedIframe;
|
|
53
|
+
private loadIframe;
|
|
54
|
+
private assignExistingIframe;
|
|
55
|
+
private createIframeLoadPromise;
|
|
56
|
+
private getIframeContext;
|
|
57
|
+
private setupIframeTimeout;
|
|
58
|
+
private createMessageListener;
|
|
59
|
+
private configureIframe;
|
|
60
|
+
private setIframeSource;
|
|
61
|
+
private setupIframeEventHandlers;
|
|
62
|
+
/**
|
|
63
|
+
* Load an iframe for a specific container
|
|
64
|
+
* @param {HTMLElement} container - The container to which the iframe will be attached
|
|
65
|
+
* @returns {Promise<HTMLIFrameElement>} that resolves when the iframe is loaded
|
|
66
|
+
*/
|
|
67
|
+
private loadIframeForContainer;
|
|
68
|
+
/**
|
|
69
|
+
* Initializes the iframe display for a specific container.
|
|
70
|
+
*
|
|
71
|
+
* @param {HTMLElement} container - The container to which the iframe will be attached.
|
|
72
|
+
* @returns:
|
|
73
|
+
* iframe: HTMLIFrameElement;
|
|
74
|
+
* iframeDisplay: IframeDisplayChannelAdapter;
|
|
75
|
+
* cleanup: () => void;
|
|
76
|
+
*/
|
|
77
|
+
initializeIframeDisplayForContainer({ container, }: {
|
|
78
|
+
container: HTMLElement;
|
|
79
|
+
}): Promise<{
|
|
80
|
+
iframe: HTMLIFrameElement;
|
|
81
|
+
iframeDisplay: iframeMessageHandler;
|
|
82
|
+
cleanup: () => void;
|
|
83
|
+
}>;
|
|
84
|
+
cleanup(): Promise<void>;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=IframeManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IframeManager.d.ts","sourceRoot":"","sources":["../../../src/client/iframeManager/IframeManager.ts"],"names":[],"mappings":"AAKA,OAAO,EAGL,KAAK,iCAAiC,EACvC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAI3E,qBAAa,aAAa;IACxB,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC;IAC5B,SAAS,CAAC,MAAM,wCAAU;IACnB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAQ;IACjC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAQ;IACnC,aAAa,EAAE,MAAM,CAAC;IAC7B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,kBAAkB,EAAE,MAAM,CAAC;IAClC,SAAS,CAAC,gBAAgB,EAAE,iCAAiC,GAAG,IAAI,CAAQ;IAC5E,SAAS,CAAC,oBAAoB,EAAE,oBAAoB,GAAG,IAAI,CAAQ;IACnE,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAA8B;IAC9D,SAAS,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI,CAAQ;IAClD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAU;IAChC,OAAc,iBAAiB,SAAS;IAExC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAkC;IAC7D,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAAK;IAChC,UAAU,EAAE,M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