@dynamic-labs-wallet/browser-wallet-client 0.0.0-beta.3 → 0.0.0-beta.308.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.js +555 -221
- package/index.esm.js +545 -199
- package/package.json +7 -6
- package/src/client/client.d.ts +37 -87
- package/src/client/client.d.ts.map +1 -1
- package/src/client/iframeManager/IframeManager.d.ts +90 -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/src/client/index.d.ts +1 -0
- package/src/client/index.d.ts.map +1 -1
- package/src/index.d.ts +0 -1
- package/src/index.d.ts.map +1 -1
- package/src/services/iframeMessageHandler.d.ts +10 -8
- package/src/services/iframeMessageHandler.d.ts.map +1 -1
- package/internal/core/bip340.d.ts +0 -22
- package/internal/core/bip340.js +0 -1
- package/internal/core/common.d.ts +0 -1
- package/internal/core/common.js +0 -1
- package/internal/core/ecdsa.d.ts +0 -23
- package/internal/core/ecdsa.js +0 -1
- package/internal/core/ed25519.d.ts +0 -22
- package/internal/core/ed25519.js +0 -1
- package/internal/core/index.d.ts +0 -6
- package/internal/core/index.js +0 -1
- package/internal/core/native.d.ts +0 -103
- package/internal/core/native.js +0 -1
- package/internal/core/types.d.ts +0 -58
- package/internal/core/types.js +0 -1
- package/internal/web/generated/libmpc_executor.d.ts +0 -130
- package/internal/web/generated/libmpc_executor.js +0 -2
- package/internal/web/generated/libmpc_executor_bg.wasm +0 -0
- package/internal/web/generated/libmpc_executor_bg.wasm.d.ts +0 -64
- package/internal/web/index.d.ts +0 -11
- package/internal/web/index.js +0 -1
package/index.cjs.js
CHANGED
|
@@ -1,110 +1,124 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var core = require('@dynamic-labs-wallet/core');
|
|
4
|
+
var uuid = require('uuid');
|
|
3
5
|
var messageTransport = require('@dynamic-labs/message-transport');
|
|
4
6
|
var logger$1 = require('@dynamic-labs/logger');
|
|
5
|
-
var core = require('@dynamic-labs-wallet/core');
|
|
6
|
-
var web = require('./internal/web');
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
messageTransport$1.on((message)=>{
|
|
14
|
-
// Forward the message to webview via postMessage
|
|
15
|
-
if (message.origin === 'host') {
|
|
16
|
-
var _iframe_contentWindow;
|
|
17
|
-
iframe == null ? void 0 : (_iframe_contentWindow = iframe.contentWindow) == null ? void 0 : _iframe_contentWindow.postMessage(message, iframeOrigin);
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
const handleIncomingMessage = (message)=>{
|
|
21
|
-
const { data } = message;
|
|
22
|
-
if (!data) return;
|
|
23
|
-
if ((data == null ? void 0 : data.origin) !== 'webview') {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
if (typeof data !== 'object') {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
try {
|
|
30
|
-
const message = messageTransport.parseMessageTransportData(data);
|
|
31
|
-
messageTransport$1.emit(message);
|
|
32
|
-
} catch (error) {
|
|
33
|
-
if (!(error instanceof SyntaxError)) {
|
|
34
|
-
logger.error('Error handling incoming message:', error);
|
|
35
|
-
}
|
|
8
|
+
function _extends() {
|
|
9
|
+
_extends = Object.assign || function assign(target) {
|
|
10
|
+
for(var i = 1; i < arguments.length; i++){
|
|
11
|
+
var source = arguments[i];
|
|
12
|
+
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
36
13
|
}
|
|
14
|
+
return target;
|
|
37
15
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
*/ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
41
|
-
// @ts-ignore
|
|
42
|
-
document.addEventListener('message', handleIncomingMessage);
|
|
43
|
-
/**
|
|
44
|
-
* Handle incoming message from iOS client
|
|
45
|
-
*/ window.addEventListener('message', handleIncomingMessage);
|
|
46
|
-
};
|
|
16
|
+
return _extends.apply(this, arguments);
|
|
17
|
+
}
|
|
47
18
|
|
|
48
19
|
class iframeMessageHandler {
|
|
49
|
-
|
|
50
|
-
|
|
20
|
+
// Handle error response from iframe message handler
|
|
21
|
+
handleIframeMessageResponseError(response) {
|
|
22
|
+
if (typeof response === 'object' && response !== null && 'error' in response) {
|
|
23
|
+
throw new Error(String(response.error));
|
|
24
|
+
}
|
|
51
25
|
}
|
|
52
|
-
async
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
});
|
|
26
|
+
async getWallets(request) {
|
|
27
|
+
const response = await this.requestChannel.request('getWallets', request);
|
|
28
|
+
this.handleIframeMessageResponseError(response);
|
|
29
|
+
return response;
|
|
57
30
|
}
|
|
58
|
-
async
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
31
|
+
async getWallet(request) {
|
|
32
|
+
const response = await this.requestChannel.request('getWallet', request);
|
|
33
|
+
this.handleIframeMessageResponseError(response);
|
|
34
|
+
return response;
|
|
35
|
+
}
|
|
36
|
+
async createWalletAccount(request) {
|
|
37
|
+
const response = await this.requestChannel.request('createWalletAccount', request);
|
|
38
|
+
this.handleIframeMessageResponseError(response);
|
|
39
|
+
return response;
|
|
63
40
|
}
|
|
64
41
|
async requiresPasswordForOperation(request) {
|
|
65
|
-
|
|
42
|
+
const response = await this.requestChannel.request('requiresPasswordForOperation', request);
|
|
43
|
+
this.handleIframeMessageResponseError(response);
|
|
44
|
+
return response;
|
|
66
45
|
}
|
|
67
46
|
async signMessage(request) {
|
|
68
|
-
|
|
47
|
+
const response = await this.requestChannel.request('signMessage', request);
|
|
48
|
+
this.handleIframeMessageResponseError(response);
|
|
49
|
+
return response;
|
|
50
|
+
}
|
|
51
|
+
async signRawMessage(request) {
|
|
52
|
+
const response = await this.requestChannel.request('signRawMessage', request);
|
|
53
|
+
this.handleIframeMessageResponseError(response);
|
|
54
|
+
return response;
|
|
69
55
|
}
|
|
70
56
|
async signTransaction(request) {
|
|
71
|
-
|
|
57
|
+
const response = await this.requestChannel.request('signTransaction', request);
|
|
58
|
+
this.handleIframeMessageResponseError(response);
|
|
59
|
+
return response;
|
|
72
60
|
}
|
|
73
61
|
async isPasswordEncrypted(request) {
|
|
74
|
-
|
|
62
|
+
const response = await this.requestChannel.request('isPasswordEncrypted', request);
|
|
63
|
+
this.handleIframeMessageResponseError(response);
|
|
64
|
+
return response;
|
|
75
65
|
}
|
|
76
66
|
async backupKeySharesToGoogleDrive(request) {
|
|
77
|
-
await this.requestChannel.request('backupKeySharesToGoogleDrive', request);
|
|
67
|
+
const response = await this.requestChannel.request('backupKeySharesToGoogleDrive', request);
|
|
68
|
+
this.handleIframeMessageResponseError(response);
|
|
69
|
+
}
|
|
70
|
+
async delegateKeyShares(request) {
|
|
71
|
+
const response = await this.requestChannel.request('delegateKeyShares', request);
|
|
72
|
+
this.handleIframeMessageResponseError(response);
|
|
78
73
|
}
|
|
79
74
|
async restoreBackupFromGoogleDrive(request) {
|
|
80
|
-
|
|
75
|
+
const response = await this.requestChannel.request('restoreBackupFromGoogleDrive', request);
|
|
76
|
+
this.handleIframeMessageResponseError(response);
|
|
81
77
|
}
|
|
82
78
|
async refreshWalletAccountShares(request) {
|
|
83
|
-
|
|
79
|
+
const response = await this.requestChannel.request('refreshWalletAccountShares', request);
|
|
80
|
+
this.handleIframeMessageResponseError(response);
|
|
84
81
|
}
|
|
85
82
|
async reshare(request) {
|
|
86
|
-
|
|
83
|
+
const response = await this.requestChannel.request('reshare', request);
|
|
84
|
+
this.handleIframeMessageResponseError(response);
|
|
87
85
|
}
|
|
88
86
|
async exportPrivateKey(request) {
|
|
89
|
-
|
|
87
|
+
const response = await this.requestChannel.request('exportPrivateKey', request);
|
|
88
|
+
this.handleIframeMessageResponseError(response);
|
|
90
89
|
}
|
|
91
90
|
async verifyPassword(request) {
|
|
92
|
-
|
|
91
|
+
const response = await this.requestChannel.request('verifyPassword', request);
|
|
92
|
+
this.handleIframeMessageResponseError(response);
|
|
93
93
|
}
|
|
94
94
|
async updatePassword(request) {
|
|
95
|
-
|
|
95
|
+
const response = await this.requestChannel.request('updatePassword', request);
|
|
96
|
+
this.handleIframeMessageResponseError(response);
|
|
96
97
|
}
|
|
97
98
|
async importPrivateKey(request) {
|
|
98
|
-
|
|
99
|
+
const response = await this.requestChannel.request('importPrivateKey', request);
|
|
100
|
+
this.handleIframeMessageResponseError(response);
|
|
101
|
+
return response;
|
|
99
102
|
}
|
|
100
|
-
async sendAuthToken(token) {
|
|
101
|
-
return this.requestChannel.request('sendAuthToken', token);
|
|
103
|
+
async sendAuthToken(token, authMode) {
|
|
104
|
+
return this.requestChannel.request('sendAuthToken', token, authMode);
|
|
102
105
|
}
|
|
103
106
|
async exportClientKeyshares(request) {
|
|
104
|
-
|
|
107
|
+
const response = await this.requestChannel.request('exportClientKeyshares', request);
|
|
108
|
+
this.handleIframeMessageResponseError(response);
|
|
105
109
|
}
|
|
106
110
|
async offlineExportPrivateKey(request) {
|
|
107
|
-
|
|
111
|
+
const response = await this.requestChannel.request('offlineExportPrivateKey', request);
|
|
112
|
+
this.handleIframeMessageResponseError(response);
|
|
113
|
+
return response;
|
|
114
|
+
}
|
|
115
|
+
async signTypedData(request) {
|
|
116
|
+
const response = await this.requestChannel.request('signTypedData', request);
|
|
117
|
+
this.handleIframeMessageResponseError(response);
|
|
118
|
+
return response;
|
|
119
|
+
}
|
|
120
|
+
async cleanup() {
|
|
121
|
+
return this.requestChannel.request('cleanup');
|
|
108
122
|
}
|
|
109
123
|
constructor(messageTransport$1){
|
|
110
124
|
this.requestChannel = messageTransport.createRequestChannel(messageTransport$1);
|
|
@@ -113,7 +127,47 @@ class iframeMessageHandler {
|
|
|
113
127
|
|
|
114
128
|
const logger = new logger$1.Logger('DynamicWaasWalletClient');
|
|
115
129
|
|
|
116
|
-
|
|
130
|
+
const setupMessageTransportBridge = (messageTransport$1, iframe, iframeOrigin)=>{
|
|
131
|
+
if (!(iframe == null ? void 0 : iframe.contentWindow)) {
|
|
132
|
+
throw new Error('Iframe or contentWindow not available');
|
|
133
|
+
}
|
|
134
|
+
const logger = new logger$1.Logger('debug');
|
|
135
|
+
messageTransport$1.on((message)=>{
|
|
136
|
+
// Forward the message to webview via postMessage
|
|
137
|
+
if (message.origin === 'host') {
|
|
138
|
+
var _iframe_contentWindow;
|
|
139
|
+
iframe == null ? void 0 : (_iframe_contentWindow = iframe.contentWindow) == null ? void 0 : _iframe_contentWindow.postMessage(message, iframeOrigin);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
const handleIncomingMessage = (message)=>{
|
|
143
|
+
const { data } = message;
|
|
144
|
+
if (!data) return;
|
|
145
|
+
if ((data == null ? void 0 : data.origin) !== 'webview') {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (typeof data !== 'object') {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
const message = messageTransport.parseMessageTransportData(data);
|
|
153
|
+
messageTransport$1.emit(message);
|
|
154
|
+
} catch (error) {
|
|
155
|
+
if (!(error instanceof SyntaxError)) {
|
|
156
|
+
logger.error('Error handling incoming message:', error);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Handle incoming message from android client
|
|
162
|
+
*/ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
163
|
+
// @ts-ignore
|
|
164
|
+
document.addEventListener('message', handleIncomingMessage);
|
|
165
|
+
/**
|
|
166
|
+
* Handle incoming message from iOS client
|
|
167
|
+
*/ window.addEventListener('message', handleIncomingMessage);
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
class IframeManager {
|
|
117
171
|
// Simply load the iframe from localhost
|
|
118
172
|
async initialize() {
|
|
119
173
|
await this.doInitializeIframeCommunication();
|
|
@@ -122,10 +176,10 @@ class DynamicWalletClient {
|
|
|
122
176
|
* this is called on class construction time
|
|
123
177
|
* @returns {Promise<void>} that resolves when the iframe is loaded and the message transport and iframe storage are initialized
|
|
124
178
|
*/ initializeIframeCommunication() {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return
|
|
179
|
+
var _IframeManager;
|
|
180
|
+
var _iframeLoadPromise;
|
|
181
|
+
(_iframeLoadPromise = (_IframeManager = IframeManager).iframeLoadPromise) != null ? _iframeLoadPromise : _IframeManager.iframeLoadPromise = this.doInitializeIframeCommunication();
|
|
182
|
+
return IframeManager.iframeLoadPromise;
|
|
129
183
|
}
|
|
130
184
|
/**
|
|
131
185
|
* initialize the iframe communication by awaiting the iframe load promise
|
|
@@ -133,8 +187,6 @@ class DynamicWalletClient {
|
|
|
133
187
|
*/ async doInitializeIframeCommunication() {
|
|
134
188
|
try {
|
|
135
189
|
await this.loadIframe();
|
|
136
|
-
this.initializeMessageTransport();
|
|
137
|
-
await this.initAuthToken();
|
|
138
190
|
} catch (error) {
|
|
139
191
|
this.logger.error('Error initializing iframe:', error);
|
|
140
192
|
throw error;
|
|
@@ -142,7 +194,12 @@ class DynamicWalletClient {
|
|
|
142
194
|
}
|
|
143
195
|
/**
|
|
144
196
|
* initialize the message transport after iframe is successfully loaded
|
|
145
|
-
*/ initializeMessageTransport() {
|
|
197
|
+
*/ async initializeMessageTransport() {
|
|
198
|
+
if (this.messageTransport && this.iframeMessageHandler) {
|
|
199
|
+
this.logger.debug('Skipping initializeMessageTransport: transport and message handler already initialized');
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
await this.initializeIframeCommunication();
|
|
146
203
|
const transport = messageTransport.applyDefaultMessageOrigin({
|
|
147
204
|
defaultOrigin: 'host',
|
|
148
205
|
messageTransport: messageTransport.createMessageTransport()
|
|
@@ -153,6 +210,7 @@ class DynamicWalletClient {
|
|
|
153
210
|
}
|
|
154
211
|
setupMessageTransportBridge(this.messageTransport, this.iframe, this.iframeDomain);
|
|
155
212
|
this.iframeMessageHandler = new iframeMessageHandler(this.messageTransport);
|
|
213
|
+
await this.initAuthToken();
|
|
156
214
|
}
|
|
157
215
|
/**
|
|
158
216
|
* securely exchange the auth token with iframe securely
|
|
@@ -162,52 +220,150 @@ class DynamicWalletClient {
|
|
|
162
220
|
}
|
|
163
221
|
try {
|
|
164
222
|
// Send auth token to iframe
|
|
165
|
-
await this.iframeMessageHandler.sendAuthToken(this.authToken);
|
|
223
|
+
await this.iframeMessageHandler.sendAuthToken(this.authToken, this.authMode);
|
|
166
224
|
} catch (error) {
|
|
167
225
|
throw new Error('Failed to establish secure token exchange: ' + error);
|
|
168
226
|
}
|
|
169
227
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
authToken: this.authToken,
|
|
193
|
-
baseApiUrl: this.baseApiUrl,
|
|
194
|
-
baseMPCRelayApiUrl: this.baseMPCRelayApiUrl,
|
|
195
|
-
chain: this.chainName
|
|
228
|
+
/**
|
|
229
|
+
* Reset the shared iframe and iframe load promise, and iframe instance count
|
|
230
|
+
*/ async resetSharedIframe() {
|
|
231
|
+
IframeManager.sharedIframe = null;
|
|
232
|
+
IframeManager.iframeInstanceCount = 0;
|
|
233
|
+
IframeManager.iframeLoadPromise = null;
|
|
234
|
+
this.iframe = null;
|
|
235
|
+
this.iframeMessageHandler = null;
|
|
236
|
+
this.messageTransport = null;
|
|
237
|
+
// Double the timeout and cap at 60 seconds to give more time for slow networks
|
|
238
|
+
IframeManager.iframeLoadTimeout = Math.min(IframeManager.iframeLoadTimeout * 2, 60000);
|
|
239
|
+
}
|
|
240
|
+
async loadIframe() {
|
|
241
|
+
// If the iframe is already loaded, just assign and resolve
|
|
242
|
+
if (IframeManager.sharedIframe) {
|
|
243
|
+
this.assignExistingIframe();
|
|
244
|
+
return Promise.resolve();
|
|
245
|
+
}
|
|
246
|
+
// If a load is in progress, wait for it, then assign
|
|
247
|
+
if (IframeManager.iframeLoadPromise) {
|
|
248
|
+
return IframeManager.iframeLoadPromise.then(()=>{
|
|
249
|
+
this.assignExistingIframe();
|
|
196
250
|
});
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
251
|
+
}
|
|
252
|
+
IframeManager.iframeLoadPromise = this.createIframeLoadPromise();
|
|
253
|
+
return IframeManager.iframeLoadPromise;
|
|
254
|
+
}
|
|
255
|
+
assignExistingIframe() {
|
|
256
|
+
this.iframe = IframeManager.sharedIframe;
|
|
257
|
+
IframeManager.iframeInstanceCount++;
|
|
258
|
+
}
|
|
259
|
+
createIframeLoadPromise() {
|
|
260
|
+
return new Promise((resolve, reject)=>{
|
|
261
|
+
const attemptLoad = ()=>{
|
|
262
|
+
IframeManager.iframeLoadAttempts++;
|
|
263
|
+
this.logger.info(`Loading iframe for waas wallet client... (attempt ${IframeManager.iframeLoadAttempts}/${IframeManager.maxRetryAttempts + 1})`, this.getIframeContext());
|
|
264
|
+
const iframe = document.createElement('iframe');
|
|
265
|
+
let messageListener = null;
|
|
266
|
+
const context = _extends({}, this.getIframeContext(), {
|
|
267
|
+
attempt: IframeManager.iframeLoadAttempts
|
|
268
|
+
});
|
|
269
|
+
// Set up timeout that will trigger iframe error, a retry will be triggered on this iframe error
|
|
270
|
+
const iframeTimeoutId = setTimeout(()=>{
|
|
271
|
+
if (iframe.onerror) {
|
|
272
|
+
iframe.onerror('Iframe load timeout');
|
|
273
|
+
}
|
|
274
|
+
}, IframeManager.iframeLoadTimeout);
|
|
275
|
+
messageListener = this.createMessageListener(iframe, iframeTimeoutId, resolve);
|
|
276
|
+
window.addEventListener('message', messageListener);
|
|
277
|
+
this.configureIframe(iframe);
|
|
278
|
+
this.setIframeSource(iframe);
|
|
279
|
+
this.logger.debug('Creating iframe with src:', iframe.src);
|
|
280
|
+
document.body.appendChild(iframe);
|
|
281
|
+
this.setupIframeEventHandlersWithRetry(iframe, messageListener, iframeTimeoutId, reject, attemptLoad, context);
|
|
282
|
+
};
|
|
283
|
+
// Start the first attempt
|
|
284
|
+
attemptLoad();
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
setupIframeEventHandlersWithRetry(iframe, messageListener, iframeTimeoutId, reject, attemptLoad, context) {
|
|
288
|
+
iframe.onload = ()=>{
|
|
289
|
+
this.logger.debug('Iframe onload fired, waiting for ready message...');
|
|
290
|
+
};
|
|
291
|
+
iframe.onerror = (error)=>{
|
|
292
|
+
if (messageListener) {
|
|
293
|
+
window.removeEventListener('message', messageListener);
|
|
294
|
+
}
|
|
295
|
+
clearTimeout(iframeTimeoutId);
|
|
296
|
+
// Check if we should retry
|
|
297
|
+
if (IframeManager.iframeLoadAttempts <= IframeManager.maxRetryAttempts) {
|
|
298
|
+
const errorMsg = error instanceof Error ? error.message : 'Unknown error occurred.';
|
|
299
|
+
this.logger.warn(`(loadIframe) Iframe failed to load on attempt ${IframeManager.iframeLoadAttempts}, retrying... context: ${JSON.stringify(context)}, error: ${errorMsg}`);
|
|
300
|
+
// Clean up current attempt
|
|
301
|
+
if (iframe.parentNode) {
|
|
302
|
+
iframe.parentNode.removeChild(iframe);
|
|
303
|
+
}
|
|
304
|
+
// Retry after a short delay
|
|
305
|
+
setTimeout(()=>{
|
|
306
|
+
attemptLoad();
|
|
307
|
+
}, 1000); // 1 second delay between retries
|
|
308
|
+
} else {
|
|
309
|
+
// Max retries reached, give up
|
|
310
|
+
this.logger.error('Iframe failed to load after all retry attempts: ', error);
|
|
311
|
+
this.resetSharedIframe();
|
|
312
|
+
IframeManager.iframeLoadAttempts = 0;
|
|
313
|
+
reject(new Error(`Failed to load iframe after all retry attempts... context: ${JSON.stringify(context)}`));
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
getIframeContext() {
|
|
318
|
+
var _this_sdkVersion;
|
|
319
|
+
return {
|
|
320
|
+
iframeDomain: this.iframeDomain,
|
|
321
|
+
environmentId: this.environmentId,
|
|
322
|
+
sdkVersion: (_this_sdkVersion = this.sdkVersion) != null ? _this_sdkVersion : '',
|
|
323
|
+
instanceId: this.instanceId,
|
|
324
|
+
chainName: this.chainName,
|
|
325
|
+
iframeLoadTimeout: IframeManager.iframeLoadTimeout
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
createMessageListener(iframe, iframeTimeoutId, resolve) {
|
|
329
|
+
const messageListener = (event)=>{
|
|
330
|
+
if (event.source === iframe.contentWindow && event.data === `iframe-ready-${this.instanceId}`) {
|
|
331
|
+
window.removeEventListener('message', messageListener);
|
|
201
332
|
clearTimeout(iframeTimeoutId);
|
|
333
|
+
IframeManager.sharedIframe = iframe;
|
|
202
334
|
this.iframe = iframe;
|
|
335
|
+
IframeManager.iframeInstanceCount++;
|
|
336
|
+
IframeManager.iframeLoadAttempts = 0; // Reset retry counter on success
|
|
203
337
|
resolve();
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
338
|
+
this.logger.info('Iframe loaded successfully...', this.getIframeContext());
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
return messageListener;
|
|
342
|
+
}
|
|
343
|
+
configureIframe(iframe) {
|
|
344
|
+
iframe.style.display = 'none';
|
|
345
|
+
iframe.setAttribute('title', 'Dynamic Wallet Iframe');
|
|
346
|
+
iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-downloads');
|
|
347
|
+
iframe.setAttribute('referrerpolicy', 'origin');
|
|
348
|
+
iframe.style.position = 'fixed';
|
|
349
|
+
iframe.style.top = '0';
|
|
350
|
+
iframe.style.left = '0';
|
|
351
|
+
iframe.style.width = '0';
|
|
352
|
+
iframe.style.height = '0';
|
|
353
|
+
iframe.style.border = 'none';
|
|
354
|
+
iframe.style.pointerEvents = 'none';
|
|
355
|
+
}
|
|
356
|
+
setIframeSource(iframe) {
|
|
357
|
+
var _this_instanceId, _this_sdkVersion;
|
|
358
|
+
const params = new URLSearchParams({
|
|
359
|
+
instanceId: (_this_instanceId = this.instanceId) != null ? _this_instanceId : '',
|
|
360
|
+
hostOrigin: window.location.origin,
|
|
361
|
+
environmentId: this.environmentId,
|
|
362
|
+
baseApiUrl: this.baseApiUrl,
|
|
363
|
+
baseMPCRelayApiUrl: this.baseMPCRelayApiUrl,
|
|
364
|
+
sdkVersion: (_this_sdkVersion = this.sdkVersion) != null ? _this_sdkVersion : ''
|
|
210
365
|
});
|
|
366
|
+
iframe.src = `${this.iframeDomain}/waas-v1/${this.environmentId}?${params.toString()}`;
|
|
211
367
|
}
|
|
212
368
|
/**
|
|
213
369
|
* Load an iframe for a specific container
|
|
@@ -215,41 +371,78 @@ class DynamicWalletClient {
|
|
|
215
371
|
* @returns {Promise<HTMLIFrameElement>} that resolves when the iframe is loaded
|
|
216
372
|
*/ loadIframeForContainer(container) {
|
|
217
373
|
return new Promise((resolve, reject)=>{
|
|
374
|
+
var _this_sdkVersion;
|
|
375
|
+
const context = {
|
|
376
|
+
iframeDomain: this.iframeDomain,
|
|
377
|
+
environmentId: this.environmentId,
|
|
378
|
+
sdkVersion: (_this_sdkVersion = this.sdkVersion) != null ? _this_sdkVersion : '',
|
|
379
|
+
instanceId: this.instanceId,
|
|
380
|
+
chainName: this.chainName,
|
|
381
|
+
iframeLoadTimeout: IframeManager.iframeLoadTimeout
|
|
382
|
+
};
|
|
383
|
+
this.logger.info(`Loading iframe for container...`, context);
|
|
218
384
|
const iframe = document.createElement('iframe');
|
|
385
|
+
let messageListener = null;
|
|
219
386
|
const iframeTimeoutId = setTimeout(()=>{
|
|
220
|
-
|
|
221
|
-
|
|
387
|
+
if (messageListener) {
|
|
388
|
+
window.removeEventListener('message', messageListener);
|
|
389
|
+
}
|
|
390
|
+
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)}`);
|
|
391
|
+
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)}`));
|
|
392
|
+
}, IframeManager.iframeLoadTimeout);
|
|
222
393
|
iframe.style.display = 'block';
|
|
223
394
|
iframe.style.width = '100%';
|
|
224
395
|
iframe.style.height = '100%';
|
|
225
396
|
iframe.setAttribute('title', 'Dynamic Wallet Storage');
|
|
226
397
|
iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin');
|
|
227
398
|
iframe.setAttribute('referrerpolicy', 'origin');
|
|
228
|
-
var _this_instanceId;
|
|
399
|
+
var _this_instanceId, _this_sdkVersion1;
|
|
229
400
|
const params = new URLSearchParams({
|
|
230
401
|
instanceId: (_this_instanceId = this.instanceId) != null ? _this_instanceId : '',
|
|
231
402
|
hostOrigin: window.location.origin,
|
|
232
403
|
environmentId: this.environmentId,
|
|
233
|
-
authToken: this.authToken,
|
|
234
404
|
baseApiUrl: this.baseApiUrl,
|
|
235
405
|
baseMPCRelayApiUrl: this.baseMPCRelayApiUrl,
|
|
236
|
-
|
|
406
|
+
sdkVersion: (_this_sdkVersion1 = this.sdkVersion) != null ? _this_sdkVersion1 : ''
|
|
237
407
|
});
|
|
238
|
-
iframe.src = `${this.iframeDomain}/waas/${this.environmentId}?${params.toString()}`;
|
|
408
|
+
iframe.src = `${this.iframeDomain}/waas-v1/${this.environmentId}?${params.toString()}`;
|
|
239
409
|
this.logger.debug('Creating iframe with src:', iframe.src);
|
|
240
410
|
// Add iframe to the provided container
|
|
241
411
|
container.appendChild(iframe);
|
|
242
412
|
iframe.onload = ()=>{
|
|
243
|
-
|
|
244
|
-
this.logger.debug('Iframe
|
|
245
|
-
this.iframe = iframe;
|
|
246
|
-
resolve(iframe);
|
|
413
|
+
// The message listener is already set up, so iframe can send ready message
|
|
414
|
+
this.logger.debug('Iframe onload fired, waiting for ready message...');
|
|
247
415
|
};
|
|
248
416
|
iframe.onerror = (error)=>{
|
|
417
|
+
if (messageListener) {
|
|
418
|
+
window.removeEventListener('message', messageListener);
|
|
419
|
+
}
|
|
249
420
|
clearTimeout(iframeTimeoutId);
|
|
250
|
-
this.logger.error('Iframe failed to load:', error);
|
|
251
|
-
reject(new Error('Failed to load iframe'));
|
|
421
|
+
this.logger.error('Iframe failed to load due to errors: ', error);
|
|
422
|
+
reject(new Error('Failed to load iframe due to unknown load errors, this is likely a browser or network issue.'));
|
|
252
423
|
};
|
|
424
|
+
// Set up message listener BEFORE creating iframe
|
|
425
|
+
messageListener = (event)=>{
|
|
426
|
+
if (event.source === iframe.contentWindow && event.data === `iframe-ready-${this.instanceId}`) {
|
|
427
|
+
if (messageListener) {
|
|
428
|
+
window.removeEventListener('message', messageListener);
|
|
429
|
+
}
|
|
430
|
+
clearTimeout(iframeTimeoutId);
|
|
431
|
+
IframeManager.sharedIframe = iframe;
|
|
432
|
+
this.iframe = iframe;
|
|
433
|
+
IframeManager.iframeInstanceCount++;
|
|
434
|
+
resolve(iframe);
|
|
435
|
+
var _this_sdkVersion;
|
|
436
|
+
this.logger.info('Iframe loaded successfully...', {
|
|
437
|
+
iframeDomain: this.iframeDomain,
|
|
438
|
+
environmentId: this.environmentId,
|
|
439
|
+
sdkVersion: (_this_sdkVersion = this.sdkVersion) != null ? _this_sdkVersion : '',
|
|
440
|
+
instanceId: this.instanceId,
|
|
441
|
+
chainName: this.chainName
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
window.addEventListener('message', messageListener);
|
|
253
446
|
});
|
|
254
447
|
}
|
|
255
448
|
/**
|
|
@@ -269,8 +462,10 @@ class DynamicWalletClient {
|
|
|
269
462
|
});
|
|
270
463
|
setupMessageTransportBridge(transport, iframe, this.iframeDomain);
|
|
271
464
|
const iframeDisplay = new iframeMessageHandler(transport);
|
|
272
|
-
|
|
273
|
-
|
|
465
|
+
var _this_authMode;
|
|
466
|
+
// if authMode is header: inform iframe the authMode with auth token
|
|
467
|
+
// if authMode is cookie: inform iframe the authMode with empty authToken
|
|
468
|
+
await iframeDisplay.sendAuthToken(this.authToken, (_this_authMode = this.authMode) != null ? _this_authMode : core.AuthMode.HEADER);
|
|
274
469
|
return {
|
|
275
470
|
iframe,
|
|
276
471
|
iframeDisplay,
|
|
@@ -283,58 +478,144 @@ class DynamicWalletClient {
|
|
|
283
478
|
throw error;
|
|
284
479
|
}
|
|
285
480
|
}
|
|
481
|
+
async cleanup() {
|
|
482
|
+
await this.initializeMessageTransport();
|
|
483
|
+
if (!this.iframeMessageHandler) {
|
|
484
|
+
throw new Error('Iframe message handler not initialized');
|
|
485
|
+
}
|
|
486
|
+
await this.iframeMessageHandler.cleanup();
|
|
487
|
+
if (this.iframe) {
|
|
488
|
+
IframeManager.iframeInstanceCount--;
|
|
489
|
+
if (IframeManager.sharedIframe && IframeManager.iframeInstanceCount === 0) {
|
|
490
|
+
document.body.removeChild(IframeManager.sharedIframe);
|
|
491
|
+
IframeManager.sharedIframe = null;
|
|
492
|
+
IframeManager.iframeLoadPromise = null;
|
|
493
|
+
}
|
|
494
|
+
this.iframe = null;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
constructor({ environmentId, baseApiUrl, baseMPCRelayApiUrl, chainName, sdkVersion, authMode = core.AuthMode.HEADER, authToken, debug }){
|
|
498
|
+
this.logger = logger;
|
|
499
|
+
this.instanceId = null;
|
|
500
|
+
this.iframeDomain = null;
|
|
501
|
+
this.messageTransport = null;
|
|
502
|
+
this.iframeMessageHandler = null;
|
|
503
|
+
this.iframe = null;
|
|
504
|
+
this.environmentId = environmentId;
|
|
505
|
+
this.authToken = authToken;
|
|
506
|
+
this.authMode = authMode;
|
|
507
|
+
this.baseApiUrl = baseApiUrl;
|
|
508
|
+
this.baseMPCRelayApiUrl = baseMPCRelayApiUrl;
|
|
509
|
+
this.chainName = chainName;
|
|
510
|
+
this.sdkVersion = sdkVersion;
|
|
511
|
+
const environment = core.getEnvironmentFromUrl(baseApiUrl);
|
|
512
|
+
this.iframeDomain = core.IFRAME_DOMAIN_MAP[environment];
|
|
513
|
+
if (this.authMode === core.AuthMode.COOKIE) {
|
|
514
|
+
this.iframeDomain = this.baseApiUrl;
|
|
515
|
+
}
|
|
516
|
+
// Generate unique instanceId when client is created
|
|
517
|
+
this.instanceId = uuid.v4();
|
|
518
|
+
this.debug = Boolean(debug);
|
|
519
|
+
this.logger.setLogLevel(this.debug ? 'DEBUG' : 'INFO');
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
IframeManager.iframeLoadPromise = null;
|
|
523
|
+
IframeManager.iframeLoadTimeout = 10000;
|
|
524
|
+
IframeManager.iframeLoadAttempts = 0;
|
|
525
|
+
IframeManager.maxRetryAttempts = 1;
|
|
526
|
+
IframeManager.sharedIframe = null;
|
|
527
|
+
IframeManager.iframeInstanceCount = 0;
|
|
528
|
+
|
|
529
|
+
class DynamicWalletClient extends IframeManager {
|
|
286
530
|
async getWallets() {
|
|
287
|
-
await this.
|
|
531
|
+
await this.initializeMessageTransport();
|
|
288
532
|
if (!this.iframeMessageHandler) {
|
|
289
533
|
throw new Error('Iframe message handler not initialized');
|
|
290
534
|
}
|
|
291
|
-
return this.iframeMessageHandler.getWallets(
|
|
535
|
+
return this.iframeMessageHandler.getWallets({
|
|
536
|
+
chainName: this.chainName
|
|
537
|
+
});
|
|
292
538
|
}
|
|
293
|
-
async getWallet({ accountAddress, walletOperation }) {
|
|
294
|
-
await this.
|
|
539
|
+
async getWallet({ accountAddress, walletOperation = core.WalletOperation.NO_OPERATION, signedSessionId, authToken }) {
|
|
540
|
+
await this.initializeMessageTransport();
|
|
295
541
|
if (!this.iframeMessageHandler) {
|
|
296
542
|
throw new Error('Iframe message handler not initialized');
|
|
297
543
|
}
|
|
298
544
|
return this.iframeMessageHandler.getWallet({
|
|
545
|
+
chainName: this.chainName,
|
|
299
546
|
accountAddress,
|
|
300
|
-
walletOperation
|
|
547
|
+
walletOperation,
|
|
548
|
+
signedSessionId,
|
|
549
|
+
authToken
|
|
301
550
|
});
|
|
302
551
|
}
|
|
303
|
-
async createWalletAccount({ thresholdSignatureScheme, password = undefined }) {
|
|
304
|
-
await this.
|
|
552
|
+
async createWalletAccount({ thresholdSignatureScheme, password = undefined, signedSessionId, authToken }) {
|
|
553
|
+
await this.initializeMessageTransport();
|
|
305
554
|
if (!this.iframeMessageHandler) {
|
|
306
555
|
throw new Error('Iframe message handler not initialized');
|
|
307
556
|
}
|
|
308
|
-
return this.iframeMessageHandler.createWalletAccount(
|
|
557
|
+
return this.iframeMessageHandler.createWalletAccount({
|
|
558
|
+
chainName: this.chainName,
|
|
559
|
+
thresholdSignatureScheme,
|
|
560
|
+
password,
|
|
561
|
+
signedSessionId,
|
|
562
|
+
authToken
|
|
563
|
+
});
|
|
309
564
|
}
|
|
310
|
-
async requiresPasswordForOperation({ accountAddress, walletOperation }) {
|
|
311
|
-
await this.
|
|
565
|
+
async requiresPasswordForOperation({ accountAddress, walletOperation = core.WalletOperation.REACH_THRESHOLD, authToken }) {
|
|
566
|
+
await this.initializeMessageTransport();
|
|
312
567
|
if (!this.iframeMessageHandler) {
|
|
313
568
|
throw new Error('Iframe message handler not initialized');
|
|
314
569
|
}
|
|
315
570
|
return this.iframeMessageHandler.requiresPasswordForOperation({
|
|
571
|
+
chainName: this.chainName,
|
|
316
572
|
accountAddress,
|
|
317
|
-
walletOperation
|
|
573
|
+
walletOperation,
|
|
574
|
+
authToken
|
|
318
575
|
});
|
|
319
576
|
}
|
|
320
|
-
async isPasswordEncrypted({ accountAddress }) {
|
|
321
|
-
await this.
|
|
577
|
+
async isPasswordEncrypted({ accountAddress, authToken }) {
|
|
578
|
+
await this.initializeMessageTransport();
|
|
322
579
|
if (!this.iframeMessageHandler) {
|
|
323
580
|
throw new Error('Iframe message handler not initialized');
|
|
324
581
|
}
|
|
325
582
|
return this.iframeMessageHandler.isPasswordEncrypted({
|
|
326
|
-
|
|
583
|
+
chainName: this.chainName,
|
|
584
|
+
accountAddress,
|
|
585
|
+
authToken
|
|
327
586
|
});
|
|
328
587
|
}
|
|
329
|
-
async signMessage({ message, accountAddress, password = undefined }) {
|
|
330
|
-
await this.
|
|
588
|
+
async signMessage({ message, accountAddress, password = undefined, signedSessionId, authToken, mfaToken, context }) {
|
|
589
|
+
await this.initializeMessageTransport();
|
|
331
590
|
if (!this.iframeMessageHandler) {
|
|
332
591
|
throw new Error('Iframe message handler not initialized');
|
|
333
592
|
}
|
|
593
|
+
const contextString = JSON.stringify(context, (_key, value)=>typeof value === 'bigint' ? value.toString() : value);
|
|
334
594
|
return this.iframeMessageHandler.signMessage({
|
|
595
|
+
chainName: this.chainName,
|
|
596
|
+
message,
|
|
597
|
+
accountAddress,
|
|
598
|
+
password,
|
|
599
|
+
signedSessionId,
|
|
600
|
+
authToken,
|
|
601
|
+
mfaToken,
|
|
602
|
+
context: contextString
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
async signRawMessage({ message, accountAddress, password = undefined, signedSessionId, authToken, mfaToken, context }) {
|
|
606
|
+
await this.initializeMessageTransport();
|
|
607
|
+
if (!this.iframeMessageHandler) {
|
|
608
|
+
throw new Error('Iframe message handler not initialized');
|
|
609
|
+
}
|
|
610
|
+
return this.iframeMessageHandler.signRawMessage({
|
|
611
|
+
chainName: this.chainName,
|
|
335
612
|
message,
|
|
336
613
|
accountAddress,
|
|
337
|
-
password
|
|
614
|
+
password,
|
|
615
|
+
signedSessionId,
|
|
616
|
+
authToken,
|
|
617
|
+
mfaToken,
|
|
618
|
+
context
|
|
338
619
|
});
|
|
339
620
|
}
|
|
340
621
|
/**
|
|
@@ -347,25 +628,65 @@ class DynamicWalletClient {
|
|
|
347
628
|
* SUI:
|
|
348
629
|
* const txBytes = await txb.build({ client });
|
|
349
630
|
* const txString = Buffer.from(txBytes).toString("hex");
|
|
350
|
-
*/ async signTransaction({ senderAddress, transaction, password = undefined }) {
|
|
351
|
-
await this.
|
|
631
|
+
*/ async signTransaction({ senderAddress, transaction, password = undefined, signedSessionId, authToken, mfaToken, chainId }) {
|
|
632
|
+
await this.initializeMessageTransport();
|
|
352
633
|
if (!this.iframeMessageHandler) {
|
|
353
634
|
throw new Error('Iframe message handler not initialized');
|
|
354
635
|
}
|
|
355
636
|
return this.iframeMessageHandler.signTransaction({
|
|
637
|
+
chainName: this.chainName,
|
|
356
638
|
senderAddress,
|
|
357
639
|
transaction,
|
|
358
|
-
password
|
|
640
|
+
password,
|
|
641
|
+
signedSessionId,
|
|
642
|
+
authToken,
|
|
643
|
+
mfaToken,
|
|
644
|
+
chainId
|
|
359
645
|
});
|
|
360
646
|
}
|
|
361
|
-
async
|
|
362
|
-
await this.
|
|
647
|
+
async signTypedData({ accountAddress, typedData, password = undefined, signedSessionId, authToken, mfaToken }) {
|
|
648
|
+
await this.initializeMessageTransport();
|
|
363
649
|
if (!this.iframeMessageHandler) {
|
|
364
650
|
throw new Error('Iframe message handler not initialized');
|
|
365
651
|
}
|
|
366
|
-
return this.iframeMessageHandler.
|
|
652
|
+
return this.iframeMessageHandler.signTypedData({
|
|
653
|
+
chainName: this.chainName,
|
|
654
|
+
accountAddress,
|
|
655
|
+
typedData: JSON.stringify(typedData),
|
|
656
|
+
password,
|
|
657
|
+
signedSessionId,
|
|
658
|
+
authToken,
|
|
659
|
+
mfaToken
|
|
660
|
+
});
|
|
367
661
|
}
|
|
368
|
-
async
|
|
662
|
+
async backupKeySharesToGoogleDrive({ accountAddress, password = undefined, signedSessionId, authToken }) {
|
|
663
|
+
await this.initializeMessageTransport();
|
|
664
|
+
if (!this.iframeMessageHandler) {
|
|
665
|
+
throw new Error('Iframe message handler not initialized');
|
|
666
|
+
}
|
|
667
|
+
return this.iframeMessageHandler.backupKeySharesToGoogleDrive({
|
|
668
|
+
chainName: this.chainName,
|
|
669
|
+
accountAddress,
|
|
670
|
+
password,
|
|
671
|
+
signedSessionId,
|
|
672
|
+
authToken
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
async delegateKeyShares({ accountAddress, password, signedSessionId, authToken, mfaToken }) {
|
|
676
|
+
await this.initializeMessageTransport();
|
|
677
|
+
if (!this.iframeMessageHandler) {
|
|
678
|
+
throw new Error('Iframe message handler not initialized');
|
|
679
|
+
}
|
|
680
|
+
return this.iframeMessageHandler.delegateKeyShares({
|
|
681
|
+
chainName: this.chainName,
|
|
682
|
+
accountAddress,
|
|
683
|
+
password,
|
|
684
|
+
signedSessionId,
|
|
685
|
+
authToken,
|
|
686
|
+
mfaToken
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
async restoreBackupFromGoogleDrive({ accountAddress, displayContainer, password, signedSessionId, authToken }) {
|
|
369
690
|
const { iframeDisplay } = await this.initializeIframeDisplayForContainer({
|
|
370
691
|
container: displayContainer
|
|
371
692
|
});
|
|
@@ -373,27 +694,44 @@ class DynamicWalletClient {
|
|
|
373
694
|
throw new Error('Failed to initialize iframe handler with display functionality');
|
|
374
695
|
}
|
|
375
696
|
return iframeDisplay.restoreBackupFromGoogleDrive({
|
|
697
|
+
chainName: this.chainName,
|
|
376
698
|
accountAddress,
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
699
|
+
password,
|
|
700
|
+
signedSessionId,
|
|
701
|
+
authToken
|
|
380
702
|
});
|
|
381
703
|
}
|
|
382
|
-
async refreshWalletAccountShares(
|
|
383
|
-
await this.
|
|
704
|
+
async refreshWalletAccountShares({ accountAddress, password, signedSessionId, authToken, mfaToken }) {
|
|
705
|
+
await this.initializeMessageTransport();
|
|
384
706
|
if (!this.iframeMessageHandler) {
|
|
385
707
|
throw new Error('Iframe message handler not initialized');
|
|
386
708
|
}
|
|
387
|
-
return this.iframeMessageHandler.refreshWalletAccountShares(
|
|
709
|
+
return this.iframeMessageHandler.refreshWalletAccountShares({
|
|
710
|
+
chainName: this.chainName,
|
|
711
|
+
accountAddress: accountAddress,
|
|
712
|
+
password: password,
|
|
713
|
+
signedSessionId,
|
|
714
|
+
authToken,
|
|
715
|
+
mfaToken
|
|
716
|
+
});
|
|
388
717
|
}
|
|
389
|
-
async reshare(
|
|
390
|
-
await this.
|
|
718
|
+
async reshare({ accountAddress, oldThresholdSignatureScheme, newThresholdSignatureScheme, password, signedSessionId, authToken, mfaToken }) {
|
|
719
|
+
await this.initializeMessageTransport();
|
|
391
720
|
if (!this.iframeMessageHandler) {
|
|
392
721
|
throw new Error('Iframe message handler not initialized');
|
|
393
722
|
}
|
|
394
|
-
return this.iframeMessageHandler.reshare(
|
|
723
|
+
return this.iframeMessageHandler.reshare({
|
|
724
|
+
chainName: this.chainName,
|
|
725
|
+
accountAddress,
|
|
726
|
+
oldThresholdSignatureScheme,
|
|
727
|
+
newThresholdSignatureScheme,
|
|
728
|
+
password,
|
|
729
|
+
signedSessionId,
|
|
730
|
+
authToken,
|
|
731
|
+
mfaToken
|
|
732
|
+
});
|
|
395
733
|
}
|
|
396
|
-
async exportPrivateKey({ accountAddress, displayContainer, password }) {
|
|
734
|
+
async exportPrivateKey({ accountAddress, displayContainer, password, signedSessionId, authToken, mfaToken }) {
|
|
397
735
|
const { iframeDisplay } = await this.initializeIframeDisplayForContainer({
|
|
398
736
|
container: displayContainer
|
|
399
737
|
});
|
|
@@ -401,55 +739,72 @@ class DynamicWalletClient {
|
|
|
401
739
|
throw new Error('Failed to initialize iframe handler with display functionality');
|
|
402
740
|
}
|
|
403
741
|
return iframeDisplay.exportPrivateKey({
|
|
742
|
+
chainName: this.chainName,
|
|
404
743
|
accountAddress,
|
|
405
|
-
password
|
|
744
|
+
password,
|
|
745
|
+
signedSessionId,
|
|
746
|
+
authToken,
|
|
747
|
+
mfaToken
|
|
406
748
|
});
|
|
407
749
|
}
|
|
408
|
-
async verifyPassword({ accountAddress, password, walletOperation }) {
|
|
409
|
-
await this.
|
|
750
|
+
async verifyPassword({ accountAddress, password, walletOperation = core.WalletOperation.NO_OPERATION, signedSessionId, authToken }) {
|
|
751
|
+
await this.initializeMessageTransport();
|
|
410
752
|
if (!this.iframeMessageHandler) {
|
|
411
753
|
throw new Error('Iframe message handler not initialized');
|
|
412
754
|
}
|
|
413
755
|
return this.iframeMessageHandler.verifyPassword({
|
|
756
|
+
chainName: this.chainName,
|
|
414
757
|
accountAddress,
|
|
415
758
|
password,
|
|
416
|
-
walletOperation
|
|
759
|
+
walletOperation,
|
|
760
|
+
signedSessionId,
|
|
761
|
+
authToken
|
|
417
762
|
});
|
|
418
763
|
}
|
|
419
|
-
async updatePassword({ accountAddress, existingPassword, newPassword }) {
|
|
420
|
-
await this.
|
|
764
|
+
async updatePassword({ accountAddress, existingPassword, newPassword, signedSessionId, authToken }) {
|
|
765
|
+
await this.initializeMessageTransport();
|
|
421
766
|
if (!this.iframeMessageHandler) {
|
|
422
767
|
throw new Error('Iframe message handler not initialized');
|
|
423
768
|
}
|
|
424
769
|
return this.iframeMessageHandler.updatePassword({
|
|
770
|
+
chainName: this.chainName,
|
|
425
771
|
accountAddress,
|
|
426
772
|
existingPassword,
|
|
427
|
-
newPassword
|
|
773
|
+
newPassword,
|
|
774
|
+
signedSessionId,
|
|
775
|
+
authToken
|
|
428
776
|
});
|
|
429
777
|
}
|
|
430
|
-
async importPrivateKey({ privateKey,
|
|
431
|
-
await this.
|
|
778
|
+
async importPrivateKey({ privateKey, thresholdSignatureScheme, signedSessionId, authToken }) {
|
|
779
|
+
await this.initializeMessageTransport();
|
|
432
780
|
if (!this.iframeMessageHandler) {
|
|
433
781
|
throw new Error('Iframe message handler not initialized');
|
|
434
782
|
}
|
|
435
783
|
return this.iframeMessageHandler.importPrivateKey({
|
|
784
|
+
chainName: this.chainName,
|
|
436
785
|
privateKey,
|
|
437
|
-
|
|
438
|
-
|
|
786
|
+
thresholdSignatureScheme,
|
|
787
|
+
signedSessionId,
|
|
788
|
+
authToken
|
|
439
789
|
});
|
|
440
790
|
}
|
|
441
|
-
async exportClientKeyshares({ accountAddress, password }) {
|
|
442
|
-
await this.
|
|
791
|
+
async exportClientKeyshares({ accountAddress, password, signedSessionId, authToken }) {
|
|
792
|
+
await this.initializeMessageTransport();
|
|
443
793
|
if (!this.iframeMessageHandler) {
|
|
444
794
|
throw new Error('Iframe message handler not initialized');
|
|
445
795
|
}
|
|
446
796
|
return this.iframeMessageHandler.exportClientKeyshares({
|
|
797
|
+
chainName: this.chainName,
|
|
447
798
|
accountAddress,
|
|
448
|
-
password
|
|
799
|
+
password,
|
|
800
|
+
signedSessionId,
|
|
801
|
+
authToken
|
|
449
802
|
});
|
|
450
803
|
}
|
|
451
|
-
|
|
452
|
-
|
|
804
|
+
/**
|
|
805
|
+
* keyShares is stringified list of EcdsaKeygenResult[] and Ed25519KeygenResult[]
|
|
806
|
+
*/ async offlineExportPrivateKey({ keyShares, derivationPath }) {
|
|
807
|
+
await this.initializeMessageTransport();
|
|
453
808
|
if (!this.iframeMessageHandler) {
|
|
454
809
|
throw new Error('Iframe message handler not initialized');
|
|
455
810
|
}
|
|
@@ -462,63 +817,42 @@ class DynamicWalletClient {
|
|
|
462
817
|
const argsBuffer = new TextEncoder().encode(serializedArgs);
|
|
463
818
|
const base64Args = Buffer.from(argsBuffer).toString('base64');
|
|
464
819
|
return this.iframeMessageHandler.offlineExportPrivateKey({
|
|
820
|
+
chainName: this.chainName,
|
|
465
821
|
base64Args
|
|
466
822
|
});
|
|
467
823
|
}
|
|
468
|
-
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, chainName, debug }){
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
this.baseMPCRelayApiUrl = baseMPCRelayApiUrl;
|
|
480
|
-
this.chainName = chainName;
|
|
481
|
-
const environment = core.getEnvironmentFromUrl(baseApiUrl);
|
|
482
|
-
this.iframeDomain = core.IFRAME_DOMAIN_MAP[environment];
|
|
483
|
-
// Generate unique instanceId when client is created
|
|
484
|
-
this.instanceId = crypto.randomUUID();
|
|
485
|
-
this.debug = Boolean(debug);
|
|
486
|
-
this.logger.setLogLevel(this.debug ? 'DEBUG' : 'INFO');
|
|
487
|
-
// initialize the client
|
|
488
|
-
this.initialize();
|
|
824
|
+
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, chainName, sdkVersion, debug, authMode = core.AuthMode.HEADER }){
|
|
825
|
+
super({
|
|
826
|
+
environmentId,
|
|
827
|
+
authToken,
|
|
828
|
+
baseApiUrl,
|
|
829
|
+
baseMPCRelayApiUrl,
|
|
830
|
+
chainName,
|
|
831
|
+
sdkVersion,
|
|
832
|
+
debug,
|
|
833
|
+
authMode
|
|
834
|
+
});
|
|
489
835
|
}
|
|
490
836
|
}
|
|
491
837
|
|
|
838
|
+
Object.defineProperty(exports, "AuthMode", {
|
|
839
|
+
enumerable: true,
|
|
840
|
+
get: function () { return core.AuthMode; }
|
|
841
|
+
});
|
|
492
842
|
Object.defineProperty(exports, "MPC_RELAY_PREPROD_API_URL", {
|
|
493
|
-
|
|
494
|
-
|
|
843
|
+
enumerable: true,
|
|
844
|
+
get: function () { return core.MPC_RELAY_PREPROD_API_URL; }
|
|
495
845
|
});
|
|
496
846
|
Object.defineProperty(exports, "MPC_RELAY_PROD_API_URL", {
|
|
497
|
-
|
|
498
|
-
|
|
847
|
+
enumerable: true,
|
|
848
|
+
get: function () { return core.MPC_RELAY_PROD_API_URL; }
|
|
499
849
|
});
|
|
500
850
|
Object.defineProperty(exports, "ThresholdSignatureScheme", {
|
|
501
|
-
|
|
502
|
-
|
|
851
|
+
enumerable: true,
|
|
852
|
+
get: function () { return core.ThresholdSignatureScheme; }
|
|
503
853
|
});
|
|
504
854
|
Object.defineProperty(exports, "WalletOperation", {
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
});
|
|
508
|
-
Object.defineProperty(exports, "BIP340KeygenResult", {
|
|
509
|
-
enumerable: true,
|
|
510
|
-
get: function () { return web.BIP340KeygenResult; }
|
|
511
|
-
});
|
|
512
|
-
Object.defineProperty(exports, "EcdsaKeygenResult", {
|
|
513
|
-
enumerable: true,
|
|
514
|
-
get: function () { return web.EcdsaKeygenResult; }
|
|
515
|
-
});
|
|
516
|
-
Object.defineProperty(exports, "EcdsaSignature", {
|
|
517
|
-
enumerable: true,
|
|
518
|
-
get: function () { return web.EcdsaSignature; }
|
|
519
|
-
});
|
|
520
|
-
Object.defineProperty(exports, "Ed25519KeygenResult", {
|
|
521
|
-
enumerable: true,
|
|
522
|
-
get: function () { return web.Ed25519KeygenResult; }
|
|
855
|
+
enumerable: true,
|
|
856
|
+
get: function () { return core.WalletOperation; }
|
|
523
857
|
});
|
|
524
858
|
exports.DynamicWalletClient = DynamicWalletClient;
|