@dynamic-labs-wallet/browser-wallet-client 0.0.0-beta.146.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 +487 -0
- package/index.esm.d.ts +1 -0
- package/index.esm.js +485 -0
- package/package.json +30 -0
- package/src/client/client.d.ts +115 -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/crypto/crypto.d.ts +2 -0
- package/src/crypto/crypto.d.ts.map +1 -0
- package/src/index.d.ts +2 -0
- package/src/index.d.ts.map +1 -0
- package/src/services/iframeMessageHandler.d.ts +27 -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,487 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var messageTransport = require('@dynamic-labs/message-transport');
|
|
4
|
+
var logger$1 = require('@dynamic-labs/logger');
|
|
5
|
+
|
|
6
|
+
const setupMessageTransportBridge = (messageTransport$1, iframe, iframeOrigin)=>{
|
|
7
|
+
if (!(iframe == null ? void 0 : iframe.contentWindow)) {
|
|
8
|
+
throw new Error('Iframe or contentWindow not available');
|
|
9
|
+
}
|
|
10
|
+
const logger = new logger$1.Logger('debug');
|
|
11
|
+
messageTransport$1.on((message)=>{
|
|
12
|
+
// Forward the message to webview via postMessage
|
|
13
|
+
if (message.origin === 'host') {
|
|
14
|
+
var _iframe_contentWindow;
|
|
15
|
+
iframe == null ? void 0 : (_iframe_contentWindow = iframe.contentWindow) == null ? void 0 : _iframe_contentWindow.postMessage(message, iframeOrigin);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
const handleIncomingMessage = (message)=>{
|
|
19
|
+
const { data } = message;
|
|
20
|
+
if (!data) return;
|
|
21
|
+
if ((data == null ? void 0 : data.origin) !== 'webview') {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (typeof data !== 'object') {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const message = messageTransport.parseMessageTransportData(data);
|
|
29
|
+
messageTransport$1.emit(message);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
if (!(error instanceof SyntaxError)) {
|
|
32
|
+
logger.error('Error handling incoming message:', error);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Handle incoming message from android client
|
|
38
|
+
*/ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
document.addEventListener('message', handleIncomingMessage);
|
|
41
|
+
/**
|
|
42
|
+
* Handle incoming message from iOS client
|
|
43
|
+
*/ window.addEventListener('message', handleIncomingMessage);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
class iframeMessageHandler {
|
|
47
|
+
async getWallets() {
|
|
48
|
+
return this.requestChannel.request('getWallets');
|
|
49
|
+
}
|
|
50
|
+
async getWallet({ accountAddress, walletOperation }) {
|
|
51
|
+
return this.requestChannel.request('getWallet', {
|
|
52
|
+
accountAddress,
|
|
53
|
+
walletOperation
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
async createWalletAccount(thresholdSignatureScheme, password) {
|
|
57
|
+
return this.requestChannel.request('createWalletAccount', {
|
|
58
|
+
thresholdSignatureScheme,
|
|
59
|
+
password
|
|
60
|
+
});
|
|
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 signTransaction(request) {
|
|
69
|
+
return this.requestChannel.request('signTransaction', request);
|
|
70
|
+
}
|
|
71
|
+
async isPasswordEncrypted(request) {
|
|
72
|
+
return this.requestChannel.request('isPasswordEncrypted', request);
|
|
73
|
+
}
|
|
74
|
+
async backupKeySharesToGoogleDrive(request) {
|
|
75
|
+
return this.requestChannel.request('backupKeySharesToGoogleDrive', request);
|
|
76
|
+
}
|
|
77
|
+
async restoreBackupFromGoogleDrive(request) {
|
|
78
|
+
return this.requestChannel.request('restoreBackupFromGoogleDrive', request);
|
|
79
|
+
}
|
|
80
|
+
async refreshWalletAccountShares(request) {
|
|
81
|
+
return this.requestChannel.request('refreshWalletAccountShares', request);
|
|
82
|
+
}
|
|
83
|
+
async reshare(request) {
|
|
84
|
+
return this.requestChannel.request('reshare', request);
|
|
85
|
+
}
|
|
86
|
+
async exportPrivateKey(request) {
|
|
87
|
+
return this.requestChannel.request('exportPrivateKey', request);
|
|
88
|
+
}
|
|
89
|
+
async verifyPassword(request) {
|
|
90
|
+
return this.requestChannel.request('verifyPassword', request);
|
|
91
|
+
}
|
|
92
|
+
async updatePassword(request) {
|
|
93
|
+
return this.requestChannel.request('updatePassword', request);
|
|
94
|
+
}
|
|
95
|
+
async importPrivateKey(request) {
|
|
96
|
+
return this.requestChannel.request('importPrivateKey', request);
|
|
97
|
+
}
|
|
98
|
+
async getPublicKey() {
|
|
99
|
+
return this.requestChannel.request('getPublicKey');
|
|
100
|
+
}
|
|
101
|
+
async sendEncryptedToken(token) {
|
|
102
|
+
return this.requestChannel.request('sendEncryptedToken', token);
|
|
103
|
+
}
|
|
104
|
+
constructor(messageTransport$1){
|
|
105
|
+
this.requestChannel = messageTransport.createRequestChannel(messageTransport$1);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const logger = new logger$1.Logger('DynamicWaasWalletClient');
|
|
110
|
+
|
|
111
|
+
async function encryptWithPublicKey(token, keyBase64) {
|
|
112
|
+
const keyBuffer = Buffer.from(keyBase64, 'base64');
|
|
113
|
+
const key = await window.crypto.subtle.importKey('raw', keyBuffer, {
|
|
114
|
+
name: 'AES-GCM',
|
|
115
|
+
length: 256
|
|
116
|
+
}, false, [
|
|
117
|
+
'encrypt'
|
|
118
|
+
]);
|
|
119
|
+
// Generate random IV
|
|
120
|
+
const iv = window.crypto.getRandomValues(new Uint8Array(12));
|
|
121
|
+
// Encrypt the data
|
|
122
|
+
const encodedData = new TextEncoder().encode(token);
|
|
123
|
+
const encryptedData = await window.crypto.subtle.encrypt({
|
|
124
|
+
name: 'AES-GCM',
|
|
125
|
+
iv: iv
|
|
126
|
+
}, key, encodedData);
|
|
127
|
+
// Package everything together
|
|
128
|
+
const result = {
|
|
129
|
+
data: Buffer.from(encryptedData).toString('base64'),
|
|
130
|
+
iv: Buffer.from(iv).toString('base64')
|
|
131
|
+
};
|
|
132
|
+
return Buffer.from(JSON.stringify(result)).toString('base64');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
class DynamicWalletClient {
|
|
136
|
+
// Simply load the iframe from localhost
|
|
137
|
+
async initialize() {
|
|
138
|
+
await this.doInitializeIframeCommunication();
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* this is called on class construction time
|
|
142
|
+
* @returns {Promise<void>} that resolves when the iframe is loaded and the message transport and iframe storage are initialized
|
|
143
|
+
*/ initializeIframeCommunication() {
|
|
144
|
+
if (!this.iframeLoadPromise) {
|
|
145
|
+
this.iframeLoadPromise = this.doInitializeIframeCommunication();
|
|
146
|
+
}
|
|
147
|
+
return this.iframeLoadPromise;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* initialize the iframe communication by awaiting the iframe load promise
|
|
151
|
+
* and initializing the message transport and iframe storage after iframe is successfully loaded
|
|
152
|
+
*/ async doInitializeIframeCommunication() {
|
|
153
|
+
try {
|
|
154
|
+
await this.loadIframe();
|
|
155
|
+
this.initializeMessageTransport();
|
|
156
|
+
await this.initAuthToken();
|
|
157
|
+
} catch (error) {
|
|
158
|
+
// eslint-disable-next-line no-console
|
|
159
|
+
console.error('Error initializing iframe:', error);
|
|
160
|
+
throw error;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* initialize the message transport after iframe is successfully loaded
|
|
165
|
+
*/ initializeMessageTransport() {
|
|
166
|
+
const transport = messageTransport.applyDefaultMessageOrigin({
|
|
167
|
+
defaultOrigin: 'host',
|
|
168
|
+
messageTransport: messageTransport.createMessageTransport()
|
|
169
|
+
});
|
|
170
|
+
this.messageTransport = transport;
|
|
171
|
+
if (!this.iframe) {
|
|
172
|
+
throw new Error('Iframe not available');
|
|
173
|
+
}
|
|
174
|
+
setupMessageTransportBridge(this.messageTransport, this.iframe, this.iframeDomain);
|
|
175
|
+
this.iframeMessageHandler = new iframeMessageHandler(this.messageTransport);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* securely exchange the auth token with iframe securely
|
|
179
|
+
*/ async initAuthToken() {
|
|
180
|
+
if (!this.iframeMessageHandler) {
|
|
181
|
+
throw new Error('Iframe message handler not initialized');
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
const publicKey = await this.iframeMessageHandler.getPublicKey();
|
|
185
|
+
// Encrypt auth token
|
|
186
|
+
const token = await encryptWithPublicKey(this.authToken, publicKey);
|
|
187
|
+
// Send encrypted token to iframe
|
|
188
|
+
await this.iframeMessageHandler.sendEncryptedToken(token);
|
|
189
|
+
} catch (error) {
|
|
190
|
+
throw new Error('Failed to establish secure token exchange: ' + error);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
loadIframe() {
|
|
194
|
+
return new Promise((resolve, reject)=>{
|
|
195
|
+
const iframe = document.createElement('iframe');
|
|
196
|
+
const iframeTimeoutId = setTimeout(()=>{
|
|
197
|
+
reject(new Error('Iframe load timeout'));
|
|
198
|
+
}, 10000);
|
|
199
|
+
iframe.style.display = 'none';
|
|
200
|
+
iframe.setAttribute('title', 'Dynamic Wallet Iframe');
|
|
201
|
+
iframe.setAttribute('referrerpolicy', 'origin');
|
|
202
|
+
iframe.style.position = 'fixed';
|
|
203
|
+
iframe.style.top = '0';
|
|
204
|
+
iframe.style.left = '0';
|
|
205
|
+
iframe.style.width = '0';
|
|
206
|
+
iframe.style.height = '0';
|
|
207
|
+
iframe.style.border = 'none';
|
|
208
|
+
iframe.style.pointerEvents = 'none';
|
|
209
|
+
var _this_instanceId;
|
|
210
|
+
const params = new URLSearchParams({
|
|
211
|
+
instanceId: (_this_instanceId = this.instanceId) != null ? _this_instanceId : '',
|
|
212
|
+
hostOrigin: window.location.origin,
|
|
213
|
+
environmentId: this.environmentId,
|
|
214
|
+
authToken: this.authToken,
|
|
215
|
+
baseApiUrl: this.baseApiUrl,
|
|
216
|
+
baseMPCRelayApiUrl: this.baseMPCRelayApiUrl,
|
|
217
|
+
chain: this.chainName
|
|
218
|
+
});
|
|
219
|
+
iframe.src = `${this.iframeDomain}/waas/${this.environmentId}?${params.toString()}`;
|
|
220
|
+
// eslint-disable-next-line no-console
|
|
221
|
+
console.log('Creating iframe with src:', iframe.src);
|
|
222
|
+
document.body.appendChild(iframe);
|
|
223
|
+
iframe.onload = ()=>{
|
|
224
|
+
clearTimeout(iframeTimeoutId);
|
|
225
|
+
this.iframe = iframe;
|
|
226
|
+
resolve();
|
|
227
|
+
};
|
|
228
|
+
iframe.onerror = (error)=>{
|
|
229
|
+
clearTimeout(iframeTimeoutId);
|
|
230
|
+
// eslint-disable-next-line no-console
|
|
231
|
+
console.error('Iframe failed to load:', error);
|
|
232
|
+
reject(new Error('Failed to load iframe'));
|
|
233
|
+
};
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Load an iframe for a specific container
|
|
238
|
+
* @param {HTMLElement} container - The container to which the iframe will be attached
|
|
239
|
+
* @returns {Promise<HTMLIFrameElement>} that resolves when the iframe is loaded
|
|
240
|
+
*/ loadIframeForContainer(container) {
|
|
241
|
+
return new Promise((resolve, reject)=>{
|
|
242
|
+
const iframe = document.createElement('iframe');
|
|
243
|
+
const iframeTimeoutId = setTimeout(()=>{
|
|
244
|
+
reject(new Error('Iframe load timeout'));
|
|
245
|
+
}, 10000);
|
|
246
|
+
iframe.style.display = 'block';
|
|
247
|
+
iframe.style.width = '100%';
|
|
248
|
+
iframe.style.height = '100%';
|
|
249
|
+
iframe.setAttribute('title', 'Dynamic Wallet Storage');
|
|
250
|
+
iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin');
|
|
251
|
+
iframe.setAttribute('referrerpolicy', 'origin');
|
|
252
|
+
var _this_instanceId;
|
|
253
|
+
const params = new URLSearchParams({
|
|
254
|
+
instanceId: (_this_instanceId = this.instanceId) != null ? _this_instanceId : '',
|
|
255
|
+
hostOrigin: window.location.origin,
|
|
256
|
+
environmentId: this.environmentId,
|
|
257
|
+
authToken: this.authToken,
|
|
258
|
+
baseApiUrl: this.baseApiUrl,
|
|
259
|
+
baseMPCRelayApiUrl: this.baseMPCRelayApiUrl,
|
|
260
|
+
chain: this.chainName
|
|
261
|
+
});
|
|
262
|
+
iframe.src = `${this.iframeDomain}/waas/${this.environmentId}?${params.toString()}`;
|
|
263
|
+
this.logger.debug('Creating iframe with src:', iframe.src);
|
|
264
|
+
// Add iframe to the provided container
|
|
265
|
+
container.appendChild(iframe);
|
|
266
|
+
iframe.onload = ()=>{
|
|
267
|
+
clearTimeout(iframeTimeoutId);
|
|
268
|
+
this.logger.debug('Iframe loaded successfully');
|
|
269
|
+
this.iframe = iframe;
|
|
270
|
+
resolve(iframe);
|
|
271
|
+
};
|
|
272
|
+
iframe.onerror = (error)=>{
|
|
273
|
+
clearTimeout(iframeTimeoutId);
|
|
274
|
+
this.logger.error('Iframe failed to load:', error);
|
|
275
|
+
reject(new Error('Failed to load iframe'));
|
|
276
|
+
};
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Initializes the iframe display for a specific container.
|
|
281
|
+
*
|
|
282
|
+
* @param {HTMLElement} container - The container to which the iframe will be attached.
|
|
283
|
+
* @returns:
|
|
284
|
+
* iframe: HTMLIFrameElement;
|
|
285
|
+
* iframeDisplay: IframeDisplayChannelAdapter;
|
|
286
|
+
* cleanup: () => void;
|
|
287
|
+
*/ async initializeIframeDisplayForContainer({ container }) {
|
|
288
|
+
try {
|
|
289
|
+
const iframe = await this.loadIframeForContainer(container);
|
|
290
|
+
const transport = messageTransport.applyDefaultMessageOrigin({
|
|
291
|
+
defaultOrigin: 'host',
|
|
292
|
+
messageTransport: messageTransport.createMessageTransport()
|
|
293
|
+
});
|
|
294
|
+
setupMessageTransportBridge(transport, iframe, this.iframeDomain);
|
|
295
|
+
const iframeDisplay = new iframeMessageHandler(transport);
|
|
296
|
+
return {
|
|
297
|
+
iframe,
|
|
298
|
+
iframeDisplay,
|
|
299
|
+
cleanup: ()=>{
|
|
300
|
+
container.removeChild(iframe);
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
} catch (error) {
|
|
304
|
+
this.logger.error('Error initializing iframe:', error);
|
|
305
|
+
throw error;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
async getWallets() {
|
|
309
|
+
await this.initializeIframeCommunication();
|
|
310
|
+
if (!this.iframeMessageHandler) {
|
|
311
|
+
throw new Error('Iframe message handler not initialized');
|
|
312
|
+
}
|
|
313
|
+
return this.iframeMessageHandler.getWallets();
|
|
314
|
+
}
|
|
315
|
+
async getWallet({ accountAddress, walletOperation }) {
|
|
316
|
+
await this.initializeIframeCommunication();
|
|
317
|
+
if (!this.iframeMessageHandler) {
|
|
318
|
+
throw new Error('Iframe message handler not initialized');
|
|
319
|
+
}
|
|
320
|
+
return this.iframeMessageHandler.getWallet({
|
|
321
|
+
accountAddress,
|
|
322
|
+
walletOperation
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
async createWalletAccount({ thresholdSignatureScheme, password = undefined }) {
|
|
326
|
+
await this.initializeIframeCommunication();
|
|
327
|
+
if (!this.iframeMessageHandler) {
|
|
328
|
+
throw new Error('Iframe message handler not initialized');
|
|
329
|
+
}
|
|
330
|
+
return this.iframeMessageHandler.createWalletAccount(thresholdSignatureScheme, password);
|
|
331
|
+
}
|
|
332
|
+
async requiresPasswordForOperation({ accountAddress, walletOperation }) {
|
|
333
|
+
await this.initializeIframeCommunication();
|
|
334
|
+
if (!this.iframeMessageHandler) {
|
|
335
|
+
throw new Error('Iframe message handler not initialized');
|
|
336
|
+
}
|
|
337
|
+
return this.iframeMessageHandler.requiresPasswordForOperation({
|
|
338
|
+
accountAddress,
|
|
339
|
+
walletOperation
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
async isPasswordEncrypted({ accountAddress }) {
|
|
343
|
+
await this.initializeIframeCommunication();
|
|
344
|
+
if (!this.iframeMessageHandler) {
|
|
345
|
+
throw new Error('Iframe message handler not initialized');
|
|
346
|
+
}
|
|
347
|
+
return this.iframeMessageHandler.isPasswordEncrypted({
|
|
348
|
+
accountAddress
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
async signMessage({ message, accountAddress, password = undefined }) {
|
|
352
|
+
await this.initializeIframeCommunication();
|
|
353
|
+
if (!this.iframeMessageHandler) {
|
|
354
|
+
throw new Error('Iframe message handler not initialized');
|
|
355
|
+
}
|
|
356
|
+
return this.iframeMessageHandler.signMessage({
|
|
357
|
+
message,
|
|
358
|
+
accountAddress,
|
|
359
|
+
password
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Signs a transaction and returns the signature, @transaction is a string of the serialized transaction
|
|
364
|
+
* EVM:
|
|
365
|
+
* transaction = serializeTransaction()
|
|
366
|
+
* SOL:
|
|
367
|
+
* const messageBytes = transaction.serializeMessage();
|
|
368
|
+
* const messageToSign = Buffer.from(messageBytes).toString("hex");
|
|
369
|
+
* SUI:
|
|
370
|
+
* const txBytes = await txb.build({ client });
|
|
371
|
+
* const txString = Buffer.from(txBytes).toString("hex");
|
|
372
|
+
*/ async signTransaction({ senderAddress, transaction, password = undefined }) {
|
|
373
|
+
await this.initializeIframeCommunication();
|
|
374
|
+
if (!this.iframeMessageHandler) {
|
|
375
|
+
throw new Error('Iframe message handler not initialized');
|
|
376
|
+
}
|
|
377
|
+
return this.iframeMessageHandler.signTransaction({
|
|
378
|
+
senderAddress,
|
|
379
|
+
transaction,
|
|
380
|
+
password
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
async backupKeySharesToGoogleDrive(request) {
|
|
384
|
+
await this.initializeIframeCommunication();
|
|
385
|
+
if (!this.iframeMessageHandler) {
|
|
386
|
+
throw new Error('Iframe message handler not initialized');
|
|
387
|
+
}
|
|
388
|
+
return this.iframeMessageHandler.backupKeySharesToGoogleDrive(request);
|
|
389
|
+
}
|
|
390
|
+
async restoreBackupFromGoogleDrive({ accountAddress, oauthAccountId, displayContainer, name, password }) {
|
|
391
|
+
const { iframeDisplay } = await this.initializeIframeDisplayForContainer({
|
|
392
|
+
container: displayContainer
|
|
393
|
+
});
|
|
394
|
+
if (!iframeDisplay) {
|
|
395
|
+
throw new Error('Failed to initialize iframe handler with display functionality');
|
|
396
|
+
}
|
|
397
|
+
return iframeDisplay.restoreBackupFromGoogleDrive({
|
|
398
|
+
accountAddress,
|
|
399
|
+
oauthAccountId,
|
|
400
|
+
name,
|
|
401
|
+
password
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
async refreshWalletAccountShares(request) {
|
|
405
|
+
await this.initializeIframeCommunication();
|
|
406
|
+
if (!this.iframeMessageHandler) {
|
|
407
|
+
throw new Error('Iframe message handler not initialized');
|
|
408
|
+
}
|
|
409
|
+
return this.iframeMessageHandler.refreshWalletAccountShares(request);
|
|
410
|
+
}
|
|
411
|
+
async reshare(request) {
|
|
412
|
+
await this.initializeIframeCommunication();
|
|
413
|
+
if (!this.iframeMessageHandler) {
|
|
414
|
+
throw new Error('Iframe message handler not initialized');
|
|
415
|
+
}
|
|
416
|
+
return this.iframeMessageHandler.reshare(request);
|
|
417
|
+
}
|
|
418
|
+
async exportPrivateKey({ accountAddress, displayContainer, password }) {
|
|
419
|
+
const { iframeDisplay } = await this.initializeIframeDisplayForContainer({
|
|
420
|
+
container: displayContainer
|
|
421
|
+
});
|
|
422
|
+
if (!iframeDisplay) {
|
|
423
|
+
throw new Error('Failed to initialize iframe handler with display functionality');
|
|
424
|
+
}
|
|
425
|
+
return iframeDisplay.exportPrivateKey({
|
|
426
|
+
accountAddress,
|
|
427
|
+
password
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
async verifyPassword({ accountAddress, password, walletOperation }) {
|
|
431
|
+
await this.initializeIframeCommunication();
|
|
432
|
+
if (!this.iframeMessageHandler) {
|
|
433
|
+
throw new Error('Iframe message handler not initialized');
|
|
434
|
+
}
|
|
435
|
+
return this.iframeMessageHandler.verifyPassword({
|
|
436
|
+
accountAddress,
|
|
437
|
+
password,
|
|
438
|
+
walletOperation
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
async updatePassword({ accountAddress, existingPassword, newPassword }) {
|
|
442
|
+
await this.initializeIframeCommunication();
|
|
443
|
+
if (!this.iframeMessageHandler) {
|
|
444
|
+
throw new Error('Iframe message handler not initialized');
|
|
445
|
+
}
|
|
446
|
+
return this.iframeMessageHandler.updatePassword({
|
|
447
|
+
accountAddress,
|
|
448
|
+
existingPassword,
|
|
449
|
+
newPassword
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
async importPrivateKey({ privateKey, chainName, thresholdSignatureScheme }) {
|
|
453
|
+
await this.initializeIframeCommunication();
|
|
454
|
+
if (!this.iframeMessageHandler) {
|
|
455
|
+
throw new Error('Iframe message handler not initialized');
|
|
456
|
+
}
|
|
457
|
+
return this.iframeMessageHandler.importPrivateKey({
|
|
458
|
+
privateKey,
|
|
459
|
+
chainName,
|
|
460
|
+
thresholdSignatureScheme
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, chainName, debug }){
|
|
464
|
+
this.logger = logger;
|
|
465
|
+
this.instanceId = null;
|
|
466
|
+
this.iframeDomain = null;
|
|
467
|
+
this.messageTransport = null;
|
|
468
|
+
this.iframeMessageHandler = null;
|
|
469
|
+
this.iframeLoadPromise = null;
|
|
470
|
+
this.iframe = null;
|
|
471
|
+
this.environmentId = environmentId;
|
|
472
|
+
this.authToken = authToken;
|
|
473
|
+
this.baseApiUrl = baseApiUrl;
|
|
474
|
+
this.baseMPCRelayApiUrl = baseMPCRelayApiUrl;
|
|
475
|
+
this.chainName = chainName;
|
|
476
|
+
// TODO: infer iframeDomain from environment
|
|
477
|
+
this.iframeDomain = 'http://localhost:8090';
|
|
478
|
+
// Generate unique instanceId when client is created
|
|
479
|
+
this.instanceId = crypto.randomUUID();
|
|
480
|
+
this.debug = Boolean(debug);
|
|
481
|
+
this.logger.setLogLevel(this.debug ? 'DEBUG' : 'INFO');
|
|
482
|
+
// initialize the client
|
|
483
|
+
this.initialize();
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
exports.DynamicWalletClient = DynamicWalletClient;
|
package/index.esm.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|
package/index.esm.js
ADDED
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
import { parseMessageTransportData, createRequestChannel, applyDefaultMessageOrigin, createMessageTransport } from '@dynamic-labs/message-transport';
|
|
2
|
+
import { Logger } from '@dynamic-labs/logger';
|
|
3
|
+
|
|
4
|
+
const setupMessageTransportBridge = (messageTransport, iframe, iframeOrigin)=>{
|
|
5
|
+
if (!(iframe == null ? void 0 : iframe.contentWindow)) {
|
|
6
|
+
throw new Error('Iframe or contentWindow not available');
|
|
7
|
+
}
|
|
8
|
+
const logger = new Logger('debug');
|
|
9
|
+
messageTransport.on((message)=>{
|
|
10
|
+
// Forward the message to webview via postMessage
|
|
11
|
+
if (message.origin === 'host') {
|
|
12
|
+
var _iframe_contentWindow;
|
|
13
|
+
iframe == null ? void 0 : (_iframe_contentWindow = iframe.contentWindow) == null ? void 0 : _iframe_contentWindow.postMessage(message, iframeOrigin);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
const handleIncomingMessage = (message)=>{
|
|
17
|
+
const { data } = message;
|
|
18
|
+
if (!data) return;
|
|
19
|
+
if ((data == null ? void 0 : data.origin) !== 'webview') {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (typeof data !== 'object') {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const message = parseMessageTransportData(data);
|
|
27
|
+
messageTransport.emit(message);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
if (!(error instanceof SyntaxError)) {
|
|
30
|
+
logger.error('Error handling incoming message:', error);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Handle incoming message from android client
|
|
36
|
+
*/ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
document.addEventListener('message', handleIncomingMessage);
|
|
39
|
+
/**
|
|
40
|
+
* Handle incoming message from iOS client
|
|
41
|
+
*/ window.addEventListener('message', handleIncomingMessage);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
class iframeMessageHandler {
|
|
45
|
+
async getWallets() {
|
|
46
|
+
return this.requestChannel.request('getWallets');
|
|
47
|
+
}
|
|
48
|
+
async getWallet({ accountAddress, walletOperation }) {
|
|
49
|
+
return this.requestChannel.request('getWallet', {
|
|
50
|
+
accountAddress,
|
|
51
|
+
walletOperation
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async createWalletAccount(thresholdSignatureScheme, password) {
|
|
55
|
+
return this.requestChannel.request('createWalletAccount', {
|
|
56
|
+
thresholdSignatureScheme,
|
|
57
|
+
password
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
async requiresPasswordForOperation(request) {
|
|
61
|
+
return this.requestChannel.request('requiresPasswordForOperation', request);
|
|
62
|
+
}
|
|
63
|
+
async signMessage(request) {
|
|
64
|
+
return this.requestChannel.request('signMessage', request);
|
|
65
|
+
}
|
|
66
|
+
async signTransaction(request) {
|
|
67
|
+
return this.requestChannel.request('signTransaction', request);
|
|
68
|
+
}
|
|
69
|
+
async isPasswordEncrypted(request) {
|
|
70
|
+
return this.requestChannel.request('isPasswordEncrypted', request);
|
|
71
|
+
}
|
|
72
|
+
async backupKeySharesToGoogleDrive(request) {
|
|
73
|
+
return this.requestChannel.request('backupKeySharesToGoogleDrive', request);
|
|
74
|
+
}
|
|
75
|
+
async restoreBackupFromGoogleDrive(request) {
|
|
76
|
+
return this.requestChannel.request('restoreBackupFromGoogleDrive', request);
|
|
77
|
+
}
|
|
78
|
+
async refreshWalletAccountShares(request) {
|
|
79
|
+
return this.requestChannel.request('refreshWalletAccountShares', request);
|
|
80
|
+
}
|
|
81
|
+
async reshare(request) {
|
|
82
|
+
return this.requestChannel.request('reshare', request);
|
|
83
|
+
}
|
|
84
|
+
async exportPrivateKey(request) {
|
|
85
|
+
return this.requestChannel.request('exportPrivateKey', request);
|
|
86
|
+
}
|
|
87
|
+
async verifyPassword(request) {
|
|
88
|
+
return this.requestChannel.request('verifyPassword', request);
|
|
89
|
+
}
|
|
90
|
+
async updatePassword(request) {
|
|
91
|
+
return this.requestChannel.request('updatePassword', request);
|
|
92
|
+
}
|
|
93
|
+
async importPrivateKey(request) {
|
|
94
|
+
return this.requestChannel.request('importPrivateKey', request);
|
|
95
|
+
}
|
|
96
|
+
async getPublicKey() {
|
|
97
|
+
return this.requestChannel.request('getPublicKey');
|
|
98
|
+
}
|
|
99
|
+
async sendEncryptedToken(token) {
|
|
100
|
+
return this.requestChannel.request('sendEncryptedToken', token);
|
|
101
|
+
}
|
|
102
|
+
constructor(messageTransport){
|
|
103
|
+
this.requestChannel = createRequestChannel(messageTransport);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const logger = new Logger('DynamicWaasWalletClient');
|
|
108
|
+
|
|
109
|
+
async function encryptWithPublicKey(token, keyBase64) {
|
|
110
|
+
const keyBuffer = Buffer.from(keyBase64, 'base64');
|
|
111
|
+
const key = await window.crypto.subtle.importKey('raw', keyBuffer, {
|
|
112
|
+
name: 'AES-GCM',
|
|
113
|
+
length: 256
|
|
114
|
+
}, false, [
|
|
115
|
+
'encrypt'
|
|
116
|
+
]);
|
|
117
|
+
// Generate random IV
|
|
118
|
+
const iv = window.crypto.getRandomValues(new Uint8Array(12));
|
|
119
|
+
// Encrypt the data
|
|
120
|
+
const encodedData = new TextEncoder().encode(token);
|
|
121
|
+
const encryptedData = await window.crypto.subtle.encrypt({
|
|
122
|
+
name: 'AES-GCM',
|
|
123
|
+
iv: iv
|
|
124
|
+
}, key, encodedData);
|
|
125
|
+
// Package everything together
|
|
126
|
+
const result = {
|
|
127
|
+
data: Buffer.from(encryptedData).toString('base64'),
|
|
128
|
+
iv: Buffer.from(iv).toString('base64')
|
|
129
|
+
};
|
|
130
|
+
return Buffer.from(JSON.stringify(result)).toString('base64');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
class DynamicWalletClient {
|
|
134
|
+
// Simply load the iframe from localhost
|
|
135
|
+
async initialize() {
|
|
136
|
+
await this.doInitializeIframeCommunication();
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* this is called on class construction time
|
|
140
|
+
* @returns {Promise<void>} that resolves when the iframe is loaded and the message transport and iframe storage are initialized
|
|
141
|
+
*/ initializeIframeCommunication() {
|
|
142
|
+
if (!this.iframeLoadPromise) {
|
|
143
|
+
this.iframeLoadPromise = this.doInitializeIframeCommunication();
|
|
144
|
+
}
|
|
145
|
+
return this.iframeLoadPromise;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* initialize the iframe communication by awaiting the iframe load promise
|
|
149
|
+
* and initializing the message transport and iframe storage after iframe is successfully loaded
|
|
150
|
+
*/ async doInitializeIframeCommunication() {
|
|
151
|
+
try {
|
|
152
|
+
await this.loadIframe();
|
|
153
|
+
this.initializeMessageTransport();
|
|
154
|
+
await this.initAuthToken();
|
|
155
|
+
} catch (error) {
|
|
156
|
+
// eslint-disable-next-line no-console
|
|
157
|
+
console.error('Error initializing iframe:', error);
|
|
158
|
+
throw error;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* initialize the message transport after iframe is successfully loaded
|
|
163
|
+
*/ initializeMessageTransport() {
|
|
164
|
+
const transport = applyDefaultMessageOrigin({
|
|
165
|
+
defaultOrigin: 'host',
|
|
166
|
+
messageTransport: createMessageTransport()
|
|
167
|
+
});
|
|
168
|
+
this.messageTransport = transport;
|
|
169
|
+
if (!this.iframe) {
|
|
170
|
+
throw new Error('Iframe not available');
|
|
171
|
+
}
|
|
172
|
+
setupMessageTransportBridge(this.messageTransport, this.iframe, this.iframeDomain);
|
|
173
|
+
this.iframeMessageHandler = new iframeMessageHandler(this.messageTransport);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* securely exchange the auth token with iframe securely
|
|
177
|
+
*/ async initAuthToken() {
|
|
178
|
+
if (!this.iframeMessageHandler) {
|
|
179
|
+
throw new Error('Iframe message handler not initialized');
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
const publicKey = await this.iframeMessageHandler.getPublicKey();
|
|
183
|
+
// Encrypt auth token
|
|
184
|
+
const token = await encryptWithPublicKey(this.authToken, publicKey);
|
|
185
|
+
// Send encrypted token to iframe
|
|
186
|
+
await this.iframeMessageHandler.sendEncryptedToken(token);
|
|
187
|
+
} catch (error) {
|
|
188
|
+
throw new Error('Failed to establish secure token exchange: ' + error);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
loadIframe() {
|
|
192
|
+
return new Promise((resolve, reject)=>{
|
|
193
|
+
const iframe = document.createElement('iframe');
|
|
194
|
+
const iframeTimeoutId = setTimeout(()=>{
|
|
195
|
+
reject(new Error('Iframe load timeout'));
|
|
196
|
+
}, 10000);
|
|
197
|
+
iframe.style.display = 'none';
|
|
198
|
+
iframe.setAttribute('title', 'Dynamic Wallet Iframe');
|
|
199
|
+
iframe.setAttribute('referrerpolicy', 'origin');
|
|
200
|
+
iframe.style.position = 'fixed';
|
|
201
|
+
iframe.style.top = '0';
|
|
202
|
+
iframe.style.left = '0';
|
|
203
|
+
iframe.style.width = '0';
|
|
204
|
+
iframe.style.height = '0';
|
|
205
|
+
iframe.style.border = 'none';
|
|
206
|
+
iframe.style.pointerEvents = 'none';
|
|
207
|
+
var _this_instanceId;
|
|
208
|
+
const params = new URLSearchParams({
|
|
209
|
+
instanceId: (_this_instanceId = this.instanceId) != null ? _this_instanceId : '',
|
|
210
|
+
hostOrigin: window.location.origin,
|
|
211
|
+
environmentId: this.environmentId,
|
|
212
|
+
authToken: this.authToken,
|
|
213
|
+
baseApiUrl: this.baseApiUrl,
|
|
214
|
+
baseMPCRelayApiUrl: this.baseMPCRelayApiUrl,
|
|
215
|
+
chain: this.chainName
|
|
216
|
+
});
|
|
217
|
+
iframe.src = `${this.iframeDomain}/waas/${this.environmentId}?${params.toString()}`;
|
|
218
|
+
// eslint-disable-next-line no-console
|
|
219
|
+
console.log('Creating iframe with src:', iframe.src);
|
|
220
|
+
document.body.appendChild(iframe);
|
|
221
|
+
iframe.onload = ()=>{
|
|
222
|
+
clearTimeout(iframeTimeoutId);
|
|
223
|
+
this.iframe = iframe;
|
|
224
|
+
resolve();
|
|
225
|
+
};
|
|
226
|
+
iframe.onerror = (error)=>{
|
|
227
|
+
clearTimeout(iframeTimeoutId);
|
|
228
|
+
// eslint-disable-next-line no-console
|
|
229
|
+
console.error('Iframe failed to load:', error);
|
|
230
|
+
reject(new Error('Failed to load iframe'));
|
|
231
|
+
};
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Load an iframe for a specific container
|
|
236
|
+
* @param {HTMLElement} container - The container to which the iframe will be attached
|
|
237
|
+
* @returns {Promise<HTMLIFrameElement>} that resolves when the iframe is loaded
|
|
238
|
+
*/ loadIframeForContainer(container) {
|
|
239
|
+
return new Promise((resolve, reject)=>{
|
|
240
|
+
const iframe = document.createElement('iframe');
|
|
241
|
+
const iframeTimeoutId = setTimeout(()=>{
|
|
242
|
+
reject(new Error('Iframe load timeout'));
|
|
243
|
+
}, 10000);
|
|
244
|
+
iframe.style.display = 'block';
|
|
245
|
+
iframe.style.width = '100%';
|
|
246
|
+
iframe.style.height = '100%';
|
|
247
|
+
iframe.setAttribute('title', 'Dynamic Wallet Storage');
|
|
248
|
+
iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin');
|
|
249
|
+
iframe.setAttribute('referrerpolicy', 'origin');
|
|
250
|
+
var _this_instanceId;
|
|
251
|
+
const params = new URLSearchParams({
|
|
252
|
+
instanceId: (_this_instanceId = this.instanceId) != null ? _this_instanceId : '',
|
|
253
|
+
hostOrigin: window.location.origin,
|
|
254
|
+
environmentId: this.environmentId,
|
|
255
|
+
authToken: this.authToken,
|
|
256
|
+
baseApiUrl: this.baseApiUrl,
|
|
257
|
+
baseMPCRelayApiUrl: this.baseMPCRelayApiUrl,
|
|
258
|
+
chain: this.chainName
|
|
259
|
+
});
|
|
260
|
+
iframe.src = `${this.iframeDomain}/waas/${this.environmentId}?${params.toString()}`;
|
|
261
|
+
this.logger.debug('Creating iframe with src:', iframe.src);
|
|
262
|
+
// Add iframe to the provided container
|
|
263
|
+
container.appendChild(iframe);
|
|
264
|
+
iframe.onload = ()=>{
|
|
265
|
+
clearTimeout(iframeTimeoutId);
|
|
266
|
+
this.logger.debug('Iframe loaded successfully');
|
|
267
|
+
this.iframe = iframe;
|
|
268
|
+
resolve(iframe);
|
|
269
|
+
};
|
|
270
|
+
iframe.onerror = (error)=>{
|
|
271
|
+
clearTimeout(iframeTimeoutId);
|
|
272
|
+
this.logger.error('Iframe failed to load:', error);
|
|
273
|
+
reject(new Error('Failed to load iframe'));
|
|
274
|
+
};
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Initializes the iframe display for a specific container.
|
|
279
|
+
*
|
|
280
|
+
* @param {HTMLElement} container - The container to which the iframe will be attached.
|
|
281
|
+
* @returns:
|
|
282
|
+
* iframe: HTMLIFrameElement;
|
|
283
|
+
* iframeDisplay: IframeDisplayChannelAdapter;
|
|
284
|
+
* cleanup: () => void;
|
|
285
|
+
*/ async initializeIframeDisplayForContainer({ container }) {
|
|
286
|
+
try {
|
|
287
|
+
const iframe = await this.loadIframeForContainer(container);
|
|
288
|
+
const transport = applyDefaultMessageOrigin({
|
|
289
|
+
defaultOrigin: 'host',
|
|
290
|
+
messageTransport: createMessageTransport()
|
|
291
|
+
});
|
|
292
|
+
setupMessageTransportBridge(transport, iframe, this.iframeDomain);
|
|
293
|
+
const iframeDisplay = new iframeMessageHandler(transport);
|
|
294
|
+
return {
|
|
295
|
+
iframe,
|
|
296
|
+
iframeDisplay,
|
|
297
|
+
cleanup: ()=>{
|
|
298
|
+
container.removeChild(iframe);
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
} catch (error) {
|
|
302
|
+
this.logger.error('Error initializing iframe:', error);
|
|
303
|
+
throw error;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
async getWallets() {
|
|
307
|
+
await this.initializeIframeCommunication();
|
|
308
|
+
if (!this.iframeMessageHandler) {
|
|
309
|
+
throw new Error('Iframe message handler not initialized');
|
|
310
|
+
}
|
|
311
|
+
return this.iframeMessageHandler.getWallets();
|
|
312
|
+
}
|
|
313
|
+
async getWallet({ accountAddress, walletOperation }) {
|
|
314
|
+
await this.initializeIframeCommunication();
|
|
315
|
+
if (!this.iframeMessageHandler) {
|
|
316
|
+
throw new Error('Iframe message handler not initialized');
|
|
317
|
+
}
|
|
318
|
+
return this.iframeMessageHandler.getWallet({
|
|
319
|
+
accountAddress,
|
|
320
|
+
walletOperation
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
async createWalletAccount({ thresholdSignatureScheme, password = undefined }) {
|
|
324
|
+
await this.initializeIframeCommunication();
|
|
325
|
+
if (!this.iframeMessageHandler) {
|
|
326
|
+
throw new Error('Iframe message handler not initialized');
|
|
327
|
+
}
|
|
328
|
+
return this.iframeMessageHandler.createWalletAccount(thresholdSignatureScheme, password);
|
|
329
|
+
}
|
|
330
|
+
async requiresPasswordForOperation({ accountAddress, walletOperation }) {
|
|
331
|
+
await this.initializeIframeCommunication();
|
|
332
|
+
if (!this.iframeMessageHandler) {
|
|
333
|
+
throw new Error('Iframe message handler not initialized');
|
|
334
|
+
}
|
|
335
|
+
return this.iframeMessageHandler.requiresPasswordForOperation({
|
|
336
|
+
accountAddress,
|
|
337
|
+
walletOperation
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
async isPasswordEncrypted({ accountAddress }) {
|
|
341
|
+
await this.initializeIframeCommunication();
|
|
342
|
+
if (!this.iframeMessageHandler) {
|
|
343
|
+
throw new Error('Iframe message handler not initialized');
|
|
344
|
+
}
|
|
345
|
+
return this.iframeMessageHandler.isPasswordEncrypted({
|
|
346
|
+
accountAddress
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
async signMessage({ message, accountAddress, password = undefined }) {
|
|
350
|
+
await this.initializeIframeCommunication();
|
|
351
|
+
if (!this.iframeMessageHandler) {
|
|
352
|
+
throw new Error('Iframe message handler not initialized');
|
|
353
|
+
}
|
|
354
|
+
return this.iframeMessageHandler.signMessage({
|
|
355
|
+
message,
|
|
356
|
+
accountAddress,
|
|
357
|
+
password
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Signs a transaction and returns the signature, @transaction is a string of the serialized transaction
|
|
362
|
+
* EVM:
|
|
363
|
+
* transaction = serializeTransaction()
|
|
364
|
+
* SOL:
|
|
365
|
+
* const messageBytes = transaction.serializeMessage();
|
|
366
|
+
* const messageToSign = Buffer.from(messageBytes).toString("hex");
|
|
367
|
+
* SUI:
|
|
368
|
+
* const txBytes = await txb.build({ client });
|
|
369
|
+
* const txString = Buffer.from(txBytes).toString("hex");
|
|
370
|
+
*/ async signTransaction({ senderAddress, transaction, password = undefined }) {
|
|
371
|
+
await this.initializeIframeCommunication();
|
|
372
|
+
if (!this.iframeMessageHandler) {
|
|
373
|
+
throw new Error('Iframe message handler not initialized');
|
|
374
|
+
}
|
|
375
|
+
return this.iframeMessageHandler.signTransaction({
|
|
376
|
+
senderAddress,
|
|
377
|
+
transaction,
|
|
378
|
+
password
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
async backupKeySharesToGoogleDrive(request) {
|
|
382
|
+
await this.initializeIframeCommunication();
|
|
383
|
+
if (!this.iframeMessageHandler) {
|
|
384
|
+
throw new Error('Iframe message handler not initialized');
|
|
385
|
+
}
|
|
386
|
+
return this.iframeMessageHandler.backupKeySharesToGoogleDrive(request);
|
|
387
|
+
}
|
|
388
|
+
async restoreBackupFromGoogleDrive({ accountAddress, oauthAccountId, displayContainer, name, password }) {
|
|
389
|
+
const { iframeDisplay } = await this.initializeIframeDisplayForContainer({
|
|
390
|
+
container: displayContainer
|
|
391
|
+
});
|
|
392
|
+
if (!iframeDisplay) {
|
|
393
|
+
throw new Error('Failed to initialize iframe handler with display functionality');
|
|
394
|
+
}
|
|
395
|
+
return iframeDisplay.restoreBackupFromGoogleDrive({
|
|
396
|
+
accountAddress,
|
|
397
|
+
oauthAccountId,
|
|
398
|
+
name,
|
|
399
|
+
password
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
async refreshWalletAccountShares(request) {
|
|
403
|
+
await this.initializeIframeCommunication();
|
|
404
|
+
if (!this.iframeMessageHandler) {
|
|
405
|
+
throw new Error('Iframe message handler not initialized');
|
|
406
|
+
}
|
|
407
|
+
return this.iframeMessageHandler.refreshWalletAccountShares(request);
|
|
408
|
+
}
|
|
409
|
+
async reshare(request) {
|
|
410
|
+
await this.initializeIframeCommunication();
|
|
411
|
+
if (!this.iframeMessageHandler) {
|
|
412
|
+
throw new Error('Iframe message handler not initialized');
|
|
413
|
+
}
|
|
414
|
+
return this.iframeMessageHandler.reshare(request);
|
|
415
|
+
}
|
|
416
|
+
async exportPrivateKey({ accountAddress, displayContainer, password }) {
|
|
417
|
+
const { iframeDisplay } = await this.initializeIframeDisplayForContainer({
|
|
418
|
+
container: displayContainer
|
|
419
|
+
});
|
|
420
|
+
if (!iframeDisplay) {
|
|
421
|
+
throw new Error('Failed to initialize iframe handler with display functionality');
|
|
422
|
+
}
|
|
423
|
+
return iframeDisplay.exportPrivateKey({
|
|
424
|
+
accountAddress,
|
|
425
|
+
password
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
async verifyPassword({ accountAddress, password, walletOperation }) {
|
|
429
|
+
await this.initializeIframeCommunication();
|
|
430
|
+
if (!this.iframeMessageHandler) {
|
|
431
|
+
throw new Error('Iframe message handler not initialized');
|
|
432
|
+
}
|
|
433
|
+
return this.iframeMessageHandler.verifyPassword({
|
|
434
|
+
accountAddress,
|
|
435
|
+
password,
|
|
436
|
+
walletOperation
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
async updatePassword({ accountAddress, existingPassword, newPassword }) {
|
|
440
|
+
await this.initializeIframeCommunication();
|
|
441
|
+
if (!this.iframeMessageHandler) {
|
|
442
|
+
throw new Error('Iframe message handler not initialized');
|
|
443
|
+
}
|
|
444
|
+
return this.iframeMessageHandler.updatePassword({
|
|
445
|
+
accountAddress,
|
|
446
|
+
existingPassword,
|
|
447
|
+
newPassword
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
async importPrivateKey({ privateKey, chainName, thresholdSignatureScheme }) {
|
|
451
|
+
await this.initializeIframeCommunication();
|
|
452
|
+
if (!this.iframeMessageHandler) {
|
|
453
|
+
throw new Error('Iframe message handler not initialized');
|
|
454
|
+
}
|
|
455
|
+
return this.iframeMessageHandler.importPrivateKey({
|
|
456
|
+
privateKey,
|
|
457
|
+
chainName,
|
|
458
|
+
thresholdSignatureScheme
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, chainName, debug }){
|
|
462
|
+
this.logger = logger;
|
|
463
|
+
this.instanceId = null;
|
|
464
|
+
this.iframeDomain = null;
|
|
465
|
+
this.messageTransport = null;
|
|
466
|
+
this.iframeMessageHandler = null;
|
|
467
|
+
this.iframeLoadPromise = null;
|
|
468
|
+
this.iframe = null;
|
|
469
|
+
this.environmentId = environmentId;
|
|
470
|
+
this.authToken = authToken;
|
|
471
|
+
this.baseApiUrl = baseApiUrl;
|
|
472
|
+
this.baseMPCRelayApiUrl = baseMPCRelayApiUrl;
|
|
473
|
+
this.chainName = chainName;
|
|
474
|
+
// TODO: infer iframeDomain from environment
|
|
475
|
+
this.iframeDomain = 'http://localhost:8090';
|
|
476
|
+
// Generate unique instanceId when client is created
|
|
477
|
+
this.instanceId = crypto.randomUUID();
|
|
478
|
+
this.debug = Boolean(debug);
|
|
479
|
+
this.logger.setLogLevel(this.debug ? 'DEBUG' : 'INFO');
|
|
480
|
+
// initialize the client
|
|
481
|
+
this.initialize();
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
export { DynamicWalletClient };
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dynamic-labs-wallet/browser-wallet-client",
|
|
3
|
+
"version": "0.0.0-beta.146.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"@dynamic-labs-wallet/core": "0.0.0-beta.146.1",
|
|
7
|
+
"@dynamic-labs/message-transport": "^4.9.9",
|
|
8
|
+
"@dynamic-labs/logger": "^4.9.9"
|
|
9
|
+
},
|
|
10
|
+
"nx": {
|
|
11
|
+
"sourceRoot": "packages/browser-wallet-client/src",
|
|
12
|
+
"projectType": "library",
|
|
13
|
+
"name": "browser-wallet-client",
|
|
14
|
+
"targets": {
|
|
15
|
+
"build": {}
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"main": "./index.cjs.js",
|
|
19
|
+
"module": "./index.esm.js",
|
|
20
|
+
"types": "./index.esm.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
"./package.json": "./package.json",
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./index.esm.d.ts",
|
|
25
|
+
"import": "./index.esm.js",
|
|
26
|
+
"require": "./index.cjs.js",
|
|
27
|
+
"default": "./index.cjs.js"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { type MessageTransportWithDefaultOrigin } from '@dynamic-labs/message-transport';
|
|
2
|
+
import { iframeMessageHandler } from '../services/iframeMessageHandler';
|
|
3
|
+
import type { ThresholdSignatureScheme, WalletOperation, GetWalletResponse, CreateWalletAccountResponse, RequiresPasswordForOperationRequest, SignMessageRequest, IsPasswordEncryptedRequest, BackupKeySharesToGoogleDriveRequest, RefreshWalletAccountSharesRequest, ReshareRequest, VerifyPasswordRequest, UpdatePasswordRequest, ImportPrivateKeyRequest } from '@dynamic-labs-wallet/core';
|
|
4
|
+
export declare class DynamicWalletClient {
|
|
5
|
+
protected chainName: string;
|
|
6
|
+
protected logger: import("@dynamic-labs/logger").Logger;
|
|
7
|
+
instanceId: string | null;
|
|
8
|
+
iframeDomain: string | null;
|
|
9
|
+
environmentId: string;
|
|
10
|
+
authToken: string;
|
|
11
|
+
baseApiUrl: string;
|
|
12
|
+
baseMPCRelayApiUrl: string;
|
|
13
|
+
protected messageTransport: MessageTransportWithDefaultOrigin | null;
|
|
14
|
+
protected iframeMessageHandler: iframeMessageHandler | null;
|
|
15
|
+
private iframeLoadPromise;
|
|
16
|
+
protected iframe: HTMLIFrameElement | null;
|
|
17
|
+
private debug;
|
|
18
|
+
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, chainName, debug, }: {
|
|
19
|
+
environmentId: string;
|
|
20
|
+
authToken: string;
|
|
21
|
+
baseApiUrl: string;
|
|
22
|
+
baseMPCRelayApiUrl: string;
|
|
23
|
+
chainName: string;
|
|
24
|
+
debug?: boolean;
|
|
25
|
+
});
|
|
26
|
+
initialize(): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* this is called on class construction time
|
|
29
|
+
* @returns {Promise<void>} that resolves when the iframe is loaded and the message transport and iframe storage are initialized
|
|
30
|
+
*/
|
|
31
|
+
initializeIframeCommunication(): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* initialize the iframe communication by awaiting the iframe load promise
|
|
34
|
+
* and initializing the message transport and iframe storage after iframe is successfully loaded
|
|
35
|
+
*/
|
|
36
|
+
private doInitializeIframeCommunication;
|
|
37
|
+
/**
|
|
38
|
+
* initialize the message transport after iframe is successfully loaded
|
|
39
|
+
*/
|
|
40
|
+
private initializeMessageTransport;
|
|
41
|
+
/**
|
|
42
|
+
* securely exchange the auth token with iframe securely
|
|
43
|
+
*/
|
|
44
|
+
private initAuthToken;
|
|
45
|
+
private loadIframe;
|
|
46
|
+
/**
|
|
47
|
+
* Load an iframe for a specific container
|
|
48
|
+
* @param {HTMLElement} container - The container to which the iframe will be attached
|
|
49
|
+
* @returns {Promise<HTMLIFrameElement>} that resolves when the iframe is loaded
|
|
50
|
+
*/
|
|
51
|
+
private loadIframeForContainer;
|
|
52
|
+
/**
|
|
53
|
+
* Initializes the iframe display for a specific container.
|
|
54
|
+
*
|
|
55
|
+
* @param {HTMLElement} container - The container to which the iframe will be attached.
|
|
56
|
+
* @returns:
|
|
57
|
+
* iframe: HTMLIFrameElement;
|
|
58
|
+
* iframeDisplay: IframeDisplayChannelAdapter;
|
|
59
|
+
* cleanup: () => void;
|
|
60
|
+
*/
|
|
61
|
+
initializeIframeDisplayForContainer({ container, }: {
|
|
62
|
+
container: HTMLElement;
|
|
63
|
+
}): Promise<{
|
|
64
|
+
iframe: HTMLIFrameElement;
|
|
65
|
+
iframeDisplay: iframeMessageHandler;
|
|
66
|
+
cleanup: () => void;
|
|
67
|
+
}>;
|
|
68
|
+
getWallets(): Promise<GetWalletResponse[]>;
|
|
69
|
+
getWallet({ accountAddress, walletOperation, }: {
|
|
70
|
+
accountAddress: string;
|
|
71
|
+
walletOperation: WalletOperation;
|
|
72
|
+
}): Promise<GetWalletResponse>;
|
|
73
|
+
createWalletAccount({ thresholdSignatureScheme, password, }: {
|
|
74
|
+
thresholdSignatureScheme: ThresholdSignatureScheme;
|
|
75
|
+
password?: string;
|
|
76
|
+
}): Promise<CreateWalletAccountResponse>;
|
|
77
|
+
requiresPasswordForOperation({ accountAddress, walletOperation, }: RequiresPasswordForOperationRequest): Promise<boolean>;
|
|
78
|
+
isPasswordEncrypted({ accountAddress, }: IsPasswordEncryptedRequest): Promise<boolean>;
|
|
79
|
+
signMessage({ message, accountAddress, password, }: SignMessageRequest): Promise<string>;
|
|
80
|
+
/**
|
|
81
|
+
* Signs a transaction and returns the signature, @transaction is a string of the serialized transaction
|
|
82
|
+
* EVM:
|
|
83
|
+
* transaction = serializeTransaction()
|
|
84
|
+
* SOL:
|
|
85
|
+
* const messageBytes = transaction.serializeMessage();
|
|
86
|
+
* const messageToSign = Buffer.from(messageBytes).toString("hex");
|
|
87
|
+
* SUI:
|
|
88
|
+
* const txBytes = await txb.build({ client });
|
|
89
|
+
* const txString = Buffer.from(txBytes).toString("hex");
|
|
90
|
+
*/
|
|
91
|
+
signTransaction({ senderAddress, transaction, password, }: {
|
|
92
|
+
senderAddress: string;
|
|
93
|
+
transaction: string;
|
|
94
|
+
password?: string;
|
|
95
|
+
}): Promise<string>;
|
|
96
|
+
backupKeySharesToGoogleDrive(request: BackupKeySharesToGoogleDriveRequest): Promise<string[]>;
|
|
97
|
+
restoreBackupFromGoogleDrive({ accountAddress, oauthAccountId, displayContainer, name, password, }: {
|
|
98
|
+
accountAddress: string;
|
|
99
|
+
oauthAccountId: string;
|
|
100
|
+
displayContainer: HTMLElement;
|
|
101
|
+
name?: string;
|
|
102
|
+
password?: string;
|
|
103
|
+
}): Promise<void>;
|
|
104
|
+
refreshWalletAccountShares(request: RefreshWalletAccountSharesRequest): Promise<void>;
|
|
105
|
+
reshare(request: ReshareRequest): Promise<void>;
|
|
106
|
+
exportPrivateKey({ accountAddress, displayContainer, password, }: {
|
|
107
|
+
accountAddress: string;
|
|
108
|
+
displayContainer: HTMLElement;
|
|
109
|
+
password?: string;
|
|
110
|
+
}): Promise<void>;
|
|
111
|
+
verifyPassword({ accountAddress, password, walletOperation, }: VerifyPasswordRequest): Promise<void>;
|
|
112
|
+
updatePassword({ accountAddress, existingPassword, newPassword, }: UpdatePasswordRequest): Promise<void>;
|
|
113
|
+
importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, }: ImportPrivateKeyRequest): Promise<CreateWalletAccountResponse>;
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../src/crypto/crypto.ts"],"names":[],"mappings":"AAAA,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,MAAM,CAAC,CAkCjB"}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type MessageTransportWithDefaultOrigin, type RequestChannel } from '@dynamic-labs/message-transport';
|
|
2
|
+
import type { ThresholdSignatureScheme, IframeRequestMessages, WalletOperation, GetWalletResponse, CreateWalletAccountResponse, SignMessageRequest, RequiresPasswordForOperationRequest, SignTransactionRequest, IsPasswordEncryptedRequest, BackupKeySharesToGoogleDriveRequest, RestoreBackupFromGoogleDriveRequest, RefreshWalletAccountSharesRequest, ReshareRequest, ExportPrivateKeyRequest, VerifyPasswordRequest, UpdatePasswordRequest, ImportPrivateKeyRequest } from '@dynamic-labs-wallet/core';
|
|
3
|
+
export declare class iframeMessageHandler {
|
|
4
|
+
requestChannel: RequestChannel<IframeRequestMessages>;
|
|
5
|
+
constructor(messageTransport: MessageTransportWithDefaultOrigin);
|
|
6
|
+
getWallets(): Promise<GetWalletResponse[]>;
|
|
7
|
+
getWallet({ accountAddress, walletOperation, }: {
|
|
8
|
+
accountAddress: string;
|
|
9
|
+
walletOperation: WalletOperation;
|
|
10
|
+
}): Promise<GetWalletResponse>;
|
|
11
|
+
createWalletAccount(thresholdSignatureScheme: ThresholdSignatureScheme, password?: string): Promise<CreateWalletAccountResponse>;
|
|
12
|
+
requiresPasswordForOperation(request: RequiresPasswordForOperationRequest): Promise<boolean>;
|
|
13
|
+
signMessage(request: SignMessageRequest): Promise<string>;
|
|
14
|
+
signTransaction(request: SignTransactionRequest): Promise<string>;
|
|
15
|
+
isPasswordEncrypted(request: IsPasswordEncryptedRequest): Promise<boolean>;
|
|
16
|
+
backupKeySharesToGoogleDrive(request: BackupKeySharesToGoogleDriveRequest): Promise<string[]>;
|
|
17
|
+
restoreBackupFromGoogleDrive(request: RestoreBackupFromGoogleDriveRequest): Promise<void>;
|
|
18
|
+
refreshWalletAccountShares(request: RefreshWalletAccountSharesRequest): Promise<void>;
|
|
19
|
+
reshare(request: ReshareRequest): Promise<void>;
|
|
20
|
+
exportPrivateKey(request: ExportPrivateKeyRequest): Promise<void>;
|
|
21
|
+
verifyPassword(request: VerifyPasswordRequest): Promise<void>;
|
|
22
|
+
updatePassword(request: UpdatePasswordRequest): Promise<void>;
|
|
23
|
+
importPrivateKey(request: ImportPrivateKeyRequest): Promise<CreateWalletAccountResponse>;
|
|
24
|
+
getPublicKey(): Promise<string>;
|
|
25
|
+
sendEncryptedToken(token: string): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=iframeMessageHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iframeMessageHandler.d.ts","sourceRoot":"","sources":["../../src/services/iframeMessageHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,iCAAiC,EACtC,KAAK,cAAc,EACpB,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EACV,wBAAwB,EACxB,qBAAqB,EACrB,eAAe,EACf,iBAAiB,EACjB,2BAA2B,EAC3B,kBAAkB,EAClB,mCAAmC,EACnC,sBAAsB,EACtB,0BAA0B,EAC1B,mCAAmC,EACnC,mCAAmC,EACnC,iCAAiC,EACjC,cAAc,EACd,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,EACxB,MAAM,2BAA2B,CAAC;AAEnC,qBAAa,oBAAoB;IAC/B,cAAc,EAAE,cAAc,CAAC,qBAAqB,CAAC,CAAC;gBAE1C,gBAAgB,EAAE,iCAAiC;IAKzD,UAAU,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAI1C,SAAS,CAAC,EACd,cAAc,EACd,eAAe,GAChB,EAAE;QACD,cAAc,EAAE,MAAM,CAAC;QACvB,eAAe,EAAE,eAAe,CAAC;KAClC;IAOK,mBAAmB,CACvB,wBAAwB,EAAE,wBAAwB,EAClD,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,2BAA2B,CAAC;IAOjC,4BAA4B,CAChC,OAAO,EAAE,mCAAmC,GAC3C,OAAO,CAAC,OAAO,CAAC;IAIb,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC;IAIzD,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,MAAM,CAAC;IAIjE,mBAAmB,CACvB,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,OAAO,CAAC;IAIb,4BAA4B,CAChC,OAAO,EAAE,mCAAmC,GAC3C,OAAO,CAAC,MAAM,EAAE,CAAC;IAId,4BAA4B,CAChC,OAAO,EAAE,mCAAmC,GAC3C,OAAO,CAAC,IAAI,CAAC;IAIV,0BAA0B,CAC9B,OAAO,EAAE,iCAAiC,GACzC,OAAO,CAAC,IAAI,CAAC;IAIV,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/C,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjE,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7D,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7D,gBAAgB,CACpB,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,2BAA2B,CAAC;IAIjC,YAAY,IAAI,OAAO,CAAC,MAAM,CAAC;IAI/B,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGvD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/services/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,eAAO,MAAM,MAAM,QAAwC,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type MessageTransportWithDefaultOrigin } from '@dynamic-labs/message-transport';
|
|
2
|
+
export declare const setupMessageTransportBridge: (messageTransport: MessageTransportWithDefaultOrigin, iframe: HTMLIFrameElement, iframeOrigin: string) => void;
|
|
3
|
+
//# sourceMappingURL=messageTransportBridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messageTransportBridge.d.ts","sourceRoot":"","sources":["../../src/services/messageTransportBridge.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,iCAAiC,EAGvC,MAAM,iCAAiC,CAAC;AAGzC,eAAO,MAAM,2BAA2B,qBACpB,iCAAiC,UAC3C,iBAAiB,gBACX,MAAM,SAgDrB,CAAC"}
|