@dynamic-labs-wallet/evm 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 +205 -89
- package/index.esm.js +199 -83
- package/package.json +5 -3
- package/src/client/client.d.ts +30 -10
- package/src/client/client.d.ts.map +1 -1
- package/src/client/constants.d.ts +0 -5
- package/src/client/constants.d.ts.map +1 -1
- package/src/client/helpers.d.ts +5 -0
- package/src/client/helpers.d.ts.map +1 -0
- package/src/utils.d.ts +7 -3
- package/src/utils.d.ts.map +1 -1
package/index.cjs.js
CHANGED
|
@@ -16,31 +16,58 @@ function _extends() {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
const EVM_SIGN_MESSAGE_PREFIX = `\x19Ethereum Signed Message:\n`;
|
|
19
|
-
// Error messages
|
|
20
|
-
const ERROR_KEYGEN_FAILED = 'Error with keygen';
|
|
21
|
-
const ERROR_CREATE_WALLET_ACCOUNT = 'Error creating evm wallet account';
|
|
22
|
-
const ERROR_SIGN_MESSAGE = 'Error signing message';
|
|
23
|
-
const ERROR_ACCOUNT_ADDRESS_REQUIRED = 'Account address is required';
|
|
24
|
-
const ERROR_VERIFY_MESSAGE_SIGNATURE = 'Error verifying message signature';
|
|
25
19
|
|
|
26
|
-
const formatEVMMessage = (message_)=>{
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
20
|
+
const formatEVMMessage = (message_, logger)=>{
|
|
21
|
+
try {
|
|
22
|
+
const message = (()=>{
|
|
23
|
+
if (typeof message_ === 'string') return viem.stringToHex(message_);
|
|
24
|
+
if (typeof message_.raw === 'string') return message_.raw;
|
|
25
|
+
return viem.bytesToHex(message_.raw);
|
|
26
|
+
})();
|
|
27
|
+
const prefix = viem.stringToHex(`${EVM_SIGN_MESSAGE_PREFIX}${viem.size(message)}`);
|
|
28
|
+
return viem.concat([
|
|
29
|
+
prefix,
|
|
30
|
+
message
|
|
31
|
+
]);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
logger.error('[DynamicWaasWalletClient]: Error formatting EVM message:', error);
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const formatTypedData = (typedData)=>{
|
|
38
|
+
return viem.hashTypedData(typedData).slice(2);
|
|
39
|
+
};
|
|
40
|
+
const serializeECDSASignature = (signature, logger)=>{
|
|
41
|
+
try {
|
|
42
|
+
return viem.serializeSignature({
|
|
43
|
+
r: `0x${Buffer.from(signature.r).toString('hex')}`,
|
|
44
|
+
s: `0x${Buffer.from(signature.s).toString('hex')}`,
|
|
45
|
+
v: BigInt(signature.v)
|
|
46
|
+
});
|
|
47
|
+
} catch (error) {
|
|
48
|
+
logger.error('[DynamicWaasWalletClient]: Error serializing ECDSA signature:', error);
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
37
51
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
52
|
+
|
|
53
|
+
const checkRawPublicKeyInstance = (rawPublicKey)=>{
|
|
54
|
+
if (!(rawPublicKey instanceof browser.EcdsaPublicKey)) {
|
|
55
|
+
throw new Error('Invalid raw public key');
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const mapTransactionToEvmTransaction = (transaction)=>{
|
|
59
|
+
var _transaction_to, _transaction_chainId;
|
|
60
|
+
return {
|
|
61
|
+
to: (_transaction_to = transaction.to) != null ? _transaction_to : '',
|
|
62
|
+
data: transaction.data,
|
|
63
|
+
gas: transaction.gas ? `0x${transaction.gas.toString(16)}` : undefined,
|
|
64
|
+
gasPrice: transaction.gasPrice ? `0x${transaction.gasPrice.toString(16)}` : undefined,
|
|
65
|
+
maxFeePerGas: transaction.maxFeePerGas ? `0x${transaction.maxFeePerGas.toString(16)}` : undefined,
|
|
66
|
+
maxPriorityFeePerGas: transaction.maxPriorityFeePerGas ? `0x${transaction.maxPriorityFeePerGas.toString(16)}` : undefined,
|
|
67
|
+
nonce: transaction.nonce,
|
|
68
|
+
value: transaction.value ? `0x${transaction.value.toString(16)}` : undefined,
|
|
69
|
+
chainId: (_transaction_chainId = transaction.chainId) != null ? _transaction_chainId : 0
|
|
70
|
+
};
|
|
44
71
|
};
|
|
45
72
|
|
|
46
73
|
class DynamicEvmWalletClient extends browser.DynamicWalletClient {
|
|
@@ -50,7 +77,7 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
|
|
|
50
77
|
transport: viem.http(rpcUrl)
|
|
51
78
|
});
|
|
52
79
|
}
|
|
53
|
-
async createWalletAccount({ thresholdSignatureScheme, password = undefined, onError }) {
|
|
80
|
+
async createWalletAccount({ thresholdSignatureScheme, password = undefined, onError, signedSessionId }) {
|
|
54
81
|
try {
|
|
55
82
|
// Create a promise that will resolve when the ceremony is complete
|
|
56
83
|
let ceremonyCeremonyCompleteResolver;
|
|
@@ -61,7 +88,10 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
|
|
|
61
88
|
const { rawPublicKey, clientKeyShares } = await this.keyGen({
|
|
62
89
|
chainName: this.chainName,
|
|
63
90
|
thresholdSignatureScheme,
|
|
64
|
-
onError
|
|
91
|
+
onError: (error)=>{
|
|
92
|
+
this.logger.error(browser.ERROR_CREATE_WALLET_ACCOUNT, error);
|
|
93
|
+
onError == null ? void 0 : onError(error);
|
|
94
|
+
},
|
|
65
95
|
onCeremonyComplete: (accountAddress, walletId)=>{
|
|
66
96
|
// update wallet map
|
|
67
97
|
const checksumAddress = viem.getAddress(accountAddress);
|
|
@@ -72,6 +102,13 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
|
|
|
72
102
|
thresholdSignatureScheme,
|
|
73
103
|
clientKeySharesBackupInfo: browser.getClientKeyShareBackupInfo()
|
|
74
104
|
});
|
|
105
|
+
this.logger.debug('walletMap updated for wallet', {
|
|
106
|
+
context: {
|
|
107
|
+
accountAddress,
|
|
108
|
+
walletId,
|
|
109
|
+
walletMap: this.walletMap
|
|
110
|
+
}
|
|
111
|
+
});
|
|
75
112
|
// Resolve the promise when ceremony is complete
|
|
76
113
|
ceremonyCeremonyCompleteResolver(undefined);
|
|
77
114
|
}
|
|
@@ -79,8 +116,9 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
|
|
|
79
116
|
// Wait for the ceremony to complete before proceeding
|
|
80
117
|
await ceremonyCompletePromise;
|
|
81
118
|
if (!rawPublicKey || !clientKeyShares) {
|
|
82
|
-
throw new Error(ERROR_KEYGEN_FAILED);
|
|
119
|
+
throw new Error(browser.ERROR_KEYGEN_FAILED);
|
|
83
120
|
}
|
|
121
|
+
checkRawPublicKeyInstance(rawPublicKey);
|
|
84
122
|
const { accountAddress, publicKeyHex } = await this.deriveAccountAddress({
|
|
85
123
|
rawPublicKey: rawPublicKey
|
|
86
124
|
});
|
|
@@ -90,11 +128,11 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
|
|
|
90
128
|
clientKeyShares,
|
|
91
129
|
overwriteOrMerge: 'overwrite'
|
|
92
130
|
});
|
|
93
|
-
|
|
94
|
-
void this.storeEncryptedBackupByWalletWithRetry({
|
|
131
|
+
await this.storeEncryptedBackupByWalletWithRetry({
|
|
95
132
|
accountAddress,
|
|
96
133
|
clientKeyShares,
|
|
97
|
-
password
|
|
134
|
+
password,
|
|
135
|
+
signedSessionId
|
|
98
136
|
});
|
|
99
137
|
return {
|
|
100
138
|
accountAddress,
|
|
@@ -102,35 +140,43 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
|
|
|
102
140
|
publicKeyHex
|
|
103
141
|
};
|
|
104
142
|
} catch (error) {
|
|
105
|
-
this.logger.error(ERROR_CREATE_WALLET_ACCOUNT, error);
|
|
106
|
-
throw new Error(ERROR_CREATE_WALLET_ACCOUNT);
|
|
143
|
+
this.logger.error(browser.ERROR_CREATE_WALLET_ACCOUNT, error);
|
|
144
|
+
throw new Error(browser.ERROR_CREATE_WALLET_ACCOUNT);
|
|
107
145
|
}
|
|
108
146
|
}
|
|
109
|
-
async signMessage({ message, accountAddress, password = undefined }) {
|
|
147
|
+
async signMessage({ message, accountAddress, password = undefined, signedSessionId, mfaToken, context, onError }) {
|
|
110
148
|
await this.verifyPassword({
|
|
111
149
|
accountAddress,
|
|
112
150
|
password,
|
|
113
|
-
walletOperation: browser.WalletOperation.SIGN_MESSAGE
|
|
151
|
+
walletOperation: browser.WalletOperation.SIGN_MESSAGE,
|
|
152
|
+
signedSessionId
|
|
114
153
|
});
|
|
115
154
|
try {
|
|
116
155
|
if (!accountAddress) {
|
|
117
|
-
throw new Error(ERROR_ACCOUNT_ADDRESS_REQUIRED);
|
|
156
|
+
throw new Error(browser.ERROR_ACCOUNT_ADDRESS_REQUIRED);
|
|
118
157
|
}
|
|
119
158
|
// Format the message for EVM signing
|
|
120
|
-
const formattedMessage = formatEVMMessage(message);
|
|
159
|
+
const formattedMessage = formatEVMMessage(message, this.logger);
|
|
160
|
+
const resolvedContext = context != null ? context : {
|
|
161
|
+
evmMessage: message
|
|
162
|
+
};
|
|
121
163
|
// Sign the message using MPC
|
|
122
164
|
const signatureEcdsa = await this.sign({
|
|
123
165
|
message: formattedMessage,
|
|
124
166
|
accountAddress: accountAddress,
|
|
125
167
|
chainName: this.chainName,
|
|
126
|
-
password
|
|
168
|
+
password,
|
|
169
|
+
signedSessionId,
|
|
170
|
+
mfaToken,
|
|
171
|
+
context: resolvedContext,
|
|
172
|
+
onError
|
|
127
173
|
});
|
|
128
174
|
// Serialize the signature
|
|
129
|
-
const serializedSignature = serializeECDSASignature(signatureEcdsa);
|
|
175
|
+
const serializedSignature = serializeECDSASignature(signatureEcdsa, this.logger);
|
|
130
176
|
return serializedSignature;
|
|
131
177
|
} catch (error) {
|
|
132
|
-
this.logger.error(ERROR_SIGN_MESSAGE, error);
|
|
133
|
-
throw new Error(ERROR_SIGN_MESSAGE);
|
|
178
|
+
this.logger.error(browser.ERROR_SIGN_MESSAGE, error);
|
|
179
|
+
throw new Error(browser.ERROR_SIGN_MESSAGE);
|
|
134
180
|
}
|
|
135
181
|
}
|
|
136
182
|
async verifyMessageSignature({ accountAddress, message, signature }) {
|
|
@@ -146,15 +192,16 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
|
|
|
146
192
|
});
|
|
147
193
|
return verified;
|
|
148
194
|
} catch (error) {
|
|
149
|
-
this.logger.error(ERROR_VERIFY_MESSAGE_SIGNATURE, error);
|
|
150
|
-
throw new Error(ERROR_VERIFY_MESSAGE_SIGNATURE);
|
|
195
|
+
this.logger.error(browser.ERROR_VERIFY_MESSAGE_SIGNATURE, error);
|
|
196
|
+
throw new Error(browser.ERROR_VERIFY_MESSAGE_SIGNATURE);
|
|
151
197
|
}
|
|
152
198
|
}
|
|
153
|
-
async signTransaction({ senderAddress, transaction, password = undefined }) {
|
|
199
|
+
async signTransaction({ senderAddress, transaction, password = undefined, signedSessionId, mfaToken, onError }) {
|
|
154
200
|
await this.verifyPassword({
|
|
155
201
|
accountAddress: senderAddress,
|
|
156
202
|
password,
|
|
157
|
-
walletOperation: browser.WalletOperation.SIGN_TRANSACTION
|
|
203
|
+
walletOperation: browser.WalletOperation.SIGN_TRANSACTION,
|
|
204
|
+
signedSessionId
|
|
158
205
|
});
|
|
159
206
|
const serializedTx = viem.serializeTransaction(transaction);
|
|
160
207
|
const serializedTxBytes = Uint8Array.from(Buffer.from(serializedTx.slice(2), 'hex'));
|
|
@@ -166,7 +213,13 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
|
|
|
166
213
|
message: serializedTxBytes,
|
|
167
214
|
accountAddress: senderAddress,
|
|
168
215
|
chainName: this.chainName,
|
|
169
|
-
password
|
|
216
|
+
password,
|
|
217
|
+
signedSessionId,
|
|
218
|
+
mfaToken,
|
|
219
|
+
context: {
|
|
220
|
+
evmTransaction: mapTransactionToEvmTransaction(transaction)
|
|
221
|
+
},
|
|
222
|
+
onError
|
|
170
223
|
});
|
|
171
224
|
if (!('r' in signatureEcdsa && 's' in signatureEcdsa && 'v' in signatureEcdsa)) {
|
|
172
225
|
throw new Error('Invalid signature format returned from MPC signing');
|
|
@@ -187,6 +240,38 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
|
|
|
187
240
|
throw error;
|
|
188
241
|
}
|
|
189
242
|
}
|
|
243
|
+
async signTypedData({ accountAddress, typedData, password = undefined, signedSessionId, mfaToken, onError }) {
|
|
244
|
+
await this.verifyPassword({
|
|
245
|
+
accountAddress,
|
|
246
|
+
password,
|
|
247
|
+
walletOperation: browser.WalletOperation.SIGN_MESSAGE,
|
|
248
|
+
signedSessionId
|
|
249
|
+
});
|
|
250
|
+
try {
|
|
251
|
+
if (!accountAddress) {
|
|
252
|
+
throw new Error(browser.ERROR_ACCOUNT_ADDRESS_REQUIRED);
|
|
253
|
+
}
|
|
254
|
+
const formattedTypedData = formatTypedData(typedData);
|
|
255
|
+
const signatureEcdsa = await this.sign({
|
|
256
|
+
message: formattedTypedData,
|
|
257
|
+
accountAddress: accountAddress,
|
|
258
|
+
chainName: this.chainName,
|
|
259
|
+
password,
|
|
260
|
+
signedSessionId,
|
|
261
|
+
isFormatted: true,
|
|
262
|
+
mfaToken,
|
|
263
|
+
context: {
|
|
264
|
+
evmTypedData: typedData
|
|
265
|
+
},
|
|
266
|
+
onError
|
|
267
|
+
});
|
|
268
|
+
const serializedSignature = serializeECDSASignature(signatureEcdsa, this.logger);
|
|
269
|
+
return serializedSignature;
|
|
270
|
+
} catch (error) {
|
|
271
|
+
this.logger.error(browser.ERROR_SIGN_TYPED_DATA, error);
|
|
272
|
+
throw new Error(browser.ERROR_SIGN_TYPED_DATA);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
190
275
|
deriveAccountAddress({ rawPublicKey }) {
|
|
191
276
|
const serializedUncompressed = rawPublicKey.serializeUncompressed();
|
|
192
277
|
const firstByteRemoved = serializedUncompressed.slice(1);
|
|
@@ -199,16 +284,19 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
|
|
|
199
284
|
publicKeyHex
|
|
200
285
|
};
|
|
201
286
|
}
|
|
202
|
-
async exportPrivateKey({ accountAddress, password = undefined }) {
|
|
287
|
+
async exportPrivateKey({ accountAddress, password = undefined, signedSessionId, mfaToken }) {
|
|
203
288
|
await this.verifyPassword({
|
|
204
289
|
accountAddress,
|
|
205
290
|
password,
|
|
206
|
-
walletOperation: browser.WalletOperation.EXPORT_PRIVATE_KEY
|
|
291
|
+
walletOperation: browser.WalletOperation.EXPORT_PRIVATE_KEY,
|
|
292
|
+
signedSessionId
|
|
207
293
|
});
|
|
208
294
|
const { derivedPrivateKey } = await this.exportKey({
|
|
209
295
|
accountAddress,
|
|
210
296
|
chainName: this.chainName,
|
|
211
|
-
password
|
|
297
|
+
password,
|
|
298
|
+
signedSessionId,
|
|
299
|
+
mfaToken
|
|
212
300
|
});
|
|
213
301
|
return derivedPrivateKey;
|
|
214
302
|
}
|
|
@@ -222,62 +310,90 @@ class DynamicEvmWalletClient extends browser.DynamicWalletClient {
|
|
|
222
310
|
derivedPrivateKey
|
|
223
311
|
};
|
|
224
312
|
}
|
|
225
|
-
async importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password = undefined, onError }) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
313
|
+
async importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password = undefined, onError, signedSessionId }) {
|
|
314
|
+
try {
|
|
315
|
+
let ceremonyCeremonyCompleteResolver;
|
|
316
|
+
const ceremonyCompletePromise = new Promise((resolve)=>{
|
|
317
|
+
ceremonyCeremonyCompleteResolver = resolve;
|
|
318
|
+
});
|
|
319
|
+
//remove 0x if it exists
|
|
320
|
+
const formattedPrivateKey = privateKey.startsWith('0x') ? privateKey.slice(2) : privateKey;
|
|
321
|
+
// TODO: validate private key for EVM
|
|
322
|
+
const { rawPublicKey, clientKeyShares } = await this.importRawPrivateKey({
|
|
323
|
+
chainName,
|
|
324
|
+
privateKey: formattedPrivateKey,
|
|
325
|
+
thresholdSignatureScheme,
|
|
326
|
+
onError: (error)=>{
|
|
327
|
+
this.logger.error(browser.ERROR_IMPORT_PRIVATE_KEY, error);
|
|
328
|
+
onError == null ? void 0 : onError(error);
|
|
329
|
+
},
|
|
330
|
+
onCeremonyComplete: (accountAddress, walletId)=>{
|
|
331
|
+
// update wallet map
|
|
332
|
+
const checksumAddress = viem.getAddress(accountAddress);
|
|
333
|
+
this.walletMap[checksumAddress] = _extends({}, this.walletMap[checksumAddress] || {}, {
|
|
334
|
+
accountAddress: checksumAddress,
|
|
335
|
+
walletId,
|
|
336
|
+
chainName: this.chainName,
|
|
337
|
+
thresholdSignatureScheme,
|
|
338
|
+
clientKeySharesBackupInfo: browser.getClientKeyShareBackupInfo()
|
|
339
|
+
});
|
|
340
|
+
this.logger.debug('walletMap updated for wallet', {
|
|
341
|
+
context: {
|
|
342
|
+
accountAddress,
|
|
343
|
+
walletId,
|
|
344
|
+
walletMap: this.walletMap
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
ceremonyCeremonyCompleteResolver(undefined);
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
// Wait for the ceremony to complete before proceeding
|
|
351
|
+
await ceremonyCompletePromise;
|
|
352
|
+
if (!rawPublicKey || !clientKeyShares) {
|
|
353
|
+
throw new Error(browser.ERROR_IMPORT_PRIVATE_KEY);
|
|
242
354
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
355
|
+
checkRawPublicKeyInstance(rawPublicKey);
|
|
356
|
+
const { accountAddress, publicKeyHex } = await this.deriveAccountAddress({
|
|
357
|
+
rawPublicKey: rawPublicKey
|
|
358
|
+
});
|
|
359
|
+
// Update client key shares in wallet map
|
|
360
|
+
await this.setClientKeySharesToLocalStorage({
|
|
361
|
+
accountAddress,
|
|
362
|
+
clientKeyShares,
|
|
363
|
+
overwriteOrMerge: 'overwrite'
|
|
364
|
+
});
|
|
365
|
+
await this.storeEncryptedBackupByWalletWithRetry({
|
|
366
|
+
accountAddress,
|
|
367
|
+
clientKeyShares,
|
|
368
|
+
password,
|
|
369
|
+
signedSessionId
|
|
370
|
+
});
|
|
371
|
+
return {
|
|
372
|
+
accountAddress,
|
|
373
|
+
rawPublicKey,
|
|
374
|
+
publicKeyHex
|
|
375
|
+
};
|
|
376
|
+
} catch (error) {
|
|
377
|
+
this.logger.error(browser.ERROR_IMPORT_PRIVATE_KEY, error);
|
|
378
|
+
throw error;
|
|
246
379
|
}
|
|
247
|
-
const { accountAddress, publicKeyHex } = await this.deriveAccountAddress({
|
|
248
|
-
rawPublicKey: rawPublicKey
|
|
249
|
-
});
|
|
250
|
-
// Update client key shares in wallet map
|
|
251
|
-
await this.setClientKeySharesToLocalStorage({
|
|
252
|
-
accountAddress,
|
|
253
|
-
clientKeyShares,
|
|
254
|
-
overwriteOrMerge: 'overwrite'
|
|
255
|
-
});
|
|
256
|
-
// Backup the new wallet without waiting for the promise to resolve
|
|
257
|
-
void this.storeEncryptedBackupByWalletWithRetry({
|
|
258
|
-
accountAddress,
|
|
259
|
-
clientKeyShares,
|
|
260
|
-
password
|
|
261
|
-
});
|
|
262
|
-
return {
|
|
263
|
-
accountAddress,
|
|
264
|
-
rawPublicKey,
|
|
265
|
-
publicKeyHex
|
|
266
|
-
};
|
|
267
380
|
}
|
|
268
381
|
async getEvmWallets() {
|
|
269
382
|
const wallets = await this.getWallets();
|
|
270
383
|
const evmWallets = wallets.filter((wallet)=>wallet.chainName === 'eip155');
|
|
271
384
|
return evmWallets;
|
|
272
385
|
}
|
|
273
|
-
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, storageKey, debug }){
|
|
386
|
+
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, storageKey, debug, featureFlags, authMode = browser.AuthMode.HEADER, sdkVersion }){
|
|
274
387
|
super({
|
|
275
388
|
environmentId,
|
|
276
389
|
authToken,
|
|
277
390
|
baseApiUrl,
|
|
278
391
|
baseMPCRelayApiUrl,
|
|
279
392
|
storageKey,
|
|
280
|
-
debug
|
|
393
|
+
debug,
|
|
394
|
+
featureFlags,
|
|
395
|
+
authMode,
|
|
396
|
+
sdkVersion
|
|
281
397
|
}), this.chainName = 'EVM';
|
|
282
398
|
}
|
|
283
399
|
}
|
package/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DynamicWalletClient, getClientKeyShareBackupInfo, WalletOperation, MessageHash } from '@dynamic-labs-wallet/browser';
|
|
2
|
-
import { stringToHex, bytesToHex, size, concat, serializeSignature, createPublicClient, http, getAddress, serializeTransaction } from 'viem';
|
|
1
|
+
import { EcdsaPublicKey, DynamicWalletClient, getClientKeyShareBackupInfo, ERROR_CREATE_WALLET_ACCOUNT, ERROR_KEYGEN_FAILED, WalletOperation, ERROR_ACCOUNT_ADDRESS_REQUIRED, ERROR_SIGN_MESSAGE, ERROR_VERIFY_MESSAGE_SIGNATURE, ERROR_SIGN_TYPED_DATA, MessageHash, ERROR_IMPORT_PRIVATE_KEY, AuthMode } from '@dynamic-labs-wallet/browser';
|
|
2
|
+
import { stringToHex, bytesToHex, size, concat, serializeSignature, hashTypedData, createPublicClient, http, getAddress, serializeTransaction } from 'viem';
|
|
3
3
|
import { mainnet } from 'viem/chains';
|
|
4
4
|
|
|
5
5
|
function _extends() {
|
|
@@ -14,31 +14,58 @@ function _extends() {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
const EVM_SIGN_MESSAGE_PREFIX = `\x19Ethereum Signed Message:\n`;
|
|
17
|
-
// Error messages
|
|
18
|
-
const ERROR_KEYGEN_FAILED = 'Error with keygen';
|
|
19
|
-
const ERROR_CREATE_WALLET_ACCOUNT = 'Error creating evm wallet account';
|
|
20
|
-
const ERROR_SIGN_MESSAGE = 'Error signing message';
|
|
21
|
-
const ERROR_ACCOUNT_ADDRESS_REQUIRED = 'Account address is required';
|
|
22
|
-
const ERROR_VERIFY_MESSAGE_SIGNATURE = 'Error verifying message signature';
|
|
23
17
|
|
|
24
|
-
const formatEVMMessage = (message_)=>{
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
18
|
+
const formatEVMMessage = (message_, logger)=>{
|
|
19
|
+
try {
|
|
20
|
+
const message = (()=>{
|
|
21
|
+
if (typeof message_ === 'string') return stringToHex(message_);
|
|
22
|
+
if (typeof message_.raw === 'string') return message_.raw;
|
|
23
|
+
return bytesToHex(message_.raw);
|
|
24
|
+
})();
|
|
25
|
+
const prefix = stringToHex(`${EVM_SIGN_MESSAGE_PREFIX}${size(message)}`);
|
|
26
|
+
return concat([
|
|
27
|
+
prefix,
|
|
28
|
+
message
|
|
29
|
+
]);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
logger.error('[DynamicWaasWalletClient]: Error formatting EVM message:', error);
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const formatTypedData = (typedData)=>{
|
|
36
|
+
return hashTypedData(typedData).slice(2);
|
|
35
37
|
};
|
|
36
|
-
const serializeECDSASignature = (signature)=>{
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
const serializeECDSASignature = (signature, logger)=>{
|
|
39
|
+
try {
|
|
40
|
+
return serializeSignature({
|
|
41
|
+
r: `0x${Buffer.from(signature.r).toString('hex')}`,
|
|
42
|
+
s: `0x${Buffer.from(signature.s).toString('hex')}`,
|
|
43
|
+
v: BigInt(signature.v)
|
|
44
|
+
});
|
|
45
|
+
} catch (error) {
|
|
46
|
+
logger.error('[DynamicWaasWalletClient]: Error serializing ECDSA signature:', error);
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const checkRawPublicKeyInstance = (rawPublicKey)=>{
|
|
52
|
+
if (!(rawPublicKey instanceof EcdsaPublicKey)) {
|
|
53
|
+
throw new Error('Invalid raw public key');
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const mapTransactionToEvmTransaction = (transaction)=>{
|
|
57
|
+
var _transaction_to, _transaction_chainId;
|
|
58
|
+
return {
|
|
59
|
+
to: (_transaction_to = transaction.to) != null ? _transaction_to : '',
|
|
60
|
+
data: transaction.data,
|
|
61
|
+
gas: transaction.gas ? `0x${transaction.gas.toString(16)}` : undefined,
|
|
62
|
+
gasPrice: transaction.gasPrice ? `0x${transaction.gasPrice.toString(16)}` : undefined,
|
|
63
|
+
maxFeePerGas: transaction.maxFeePerGas ? `0x${transaction.maxFeePerGas.toString(16)}` : undefined,
|
|
64
|
+
maxPriorityFeePerGas: transaction.maxPriorityFeePerGas ? `0x${transaction.maxPriorityFeePerGas.toString(16)}` : undefined,
|
|
65
|
+
nonce: transaction.nonce,
|
|
66
|
+
value: transaction.value ? `0x${transaction.value.toString(16)}` : undefined,
|
|
67
|
+
chainId: (_transaction_chainId = transaction.chainId) != null ? _transaction_chainId : 0
|
|
68
|
+
};
|
|
42
69
|
};
|
|
43
70
|
|
|
44
71
|
class DynamicEvmWalletClient extends DynamicWalletClient {
|
|
@@ -48,7 +75,7 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
|
|
|
48
75
|
transport: http(rpcUrl)
|
|
49
76
|
});
|
|
50
77
|
}
|
|
51
|
-
async createWalletAccount({ thresholdSignatureScheme, password = undefined, onError }) {
|
|
78
|
+
async createWalletAccount({ thresholdSignatureScheme, password = undefined, onError, signedSessionId }) {
|
|
52
79
|
try {
|
|
53
80
|
// Create a promise that will resolve when the ceremony is complete
|
|
54
81
|
let ceremonyCeremonyCompleteResolver;
|
|
@@ -59,7 +86,10 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
|
|
|
59
86
|
const { rawPublicKey, clientKeyShares } = await this.keyGen({
|
|
60
87
|
chainName: this.chainName,
|
|
61
88
|
thresholdSignatureScheme,
|
|
62
|
-
onError
|
|
89
|
+
onError: (error)=>{
|
|
90
|
+
this.logger.error(ERROR_CREATE_WALLET_ACCOUNT, error);
|
|
91
|
+
onError == null ? void 0 : onError(error);
|
|
92
|
+
},
|
|
63
93
|
onCeremonyComplete: (accountAddress, walletId)=>{
|
|
64
94
|
// update wallet map
|
|
65
95
|
const checksumAddress = getAddress(accountAddress);
|
|
@@ -70,6 +100,13 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
|
|
|
70
100
|
thresholdSignatureScheme,
|
|
71
101
|
clientKeySharesBackupInfo: getClientKeyShareBackupInfo()
|
|
72
102
|
});
|
|
103
|
+
this.logger.debug('walletMap updated for wallet', {
|
|
104
|
+
context: {
|
|
105
|
+
accountAddress,
|
|
106
|
+
walletId,
|
|
107
|
+
walletMap: this.walletMap
|
|
108
|
+
}
|
|
109
|
+
});
|
|
73
110
|
// Resolve the promise when ceremony is complete
|
|
74
111
|
ceremonyCeremonyCompleteResolver(undefined);
|
|
75
112
|
}
|
|
@@ -79,6 +116,7 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
|
|
|
79
116
|
if (!rawPublicKey || !clientKeyShares) {
|
|
80
117
|
throw new Error(ERROR_KEYGEN_FAILED);
|
|
81
118
|
}
|
|
119
|
+
checkRawPublicKeyInstance(rawPublicKey);
|
|
82
120
|
const { accountAddress, publicKeyHex } = await this.deriveAccountAddress({
|
|
83
121
|
rawPublicKey: rawPublicKey
|
|
84
122
|
});
|
|
@@ -88,11 +126,11 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
|
|
|
88
126
|
clientKeyShares,
|
|
89
127
|
overwriteOrMerge: 'overwrite'
|
|
90
128
|
});
|
|
91
|
-
|
|
92
|
-
void this.storeEncryptedBackupByWalletWithRetry({
|
|
129
|
+
await this.storeEncryptedBackupByWalletWithRetry({
|
|
93
130
|
accountAddress,
|
|
94
131
|
clientKeyShares,
|
|
95
|
-
password
|
|
132
|
+
password,
|
|
133
|
+
signedSessionId
|
|
96
134
|
});
|
|
97
135
|
return {
|
|
98
136
|
accountAddress,
|
|
@@ -104,27 +142,35 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
|
|
|
104
142
|
throw new Error(ERROR_CREATE_WALLET_ACCOUNT);
|
|
105
143
|
}
|
|
106
144
|
}
|
|
107
|
-
async signMessage({ message, accountAddress, password = undefined }) {
|
|
145
|
+
async signMessage({ message, accountAddress, password = undefined, signedSessionId, mfaToken, context, onError }) {
|
|
108
146
|
await this.verifyPassword({
|
|
109
147
|
accountAddress,
|
|
110
148
|
password,
|
|
111
|
-
walletOperation: WalletOperation.SIGN_MESSAGE
|
|
149
|
+
walletOperation: WalletOperation.SIGN_MESSAGE,
|
|
150
|
+
signedSessionId
|
|
112
151
|
});
|
|
113
152
|
try {
|
|
114
153
|
if (!accountAddress) {
|
|
115
154
|
throw new Error(ERROR_ACCOUNT_ADDRESS_REQUIRED);
|
|
116
155
|
}
|
|
117
156
|
// Format the message for EVM signing
|
|
118
|
-
const formattedMessage = formatEVMMessage(message);
|
|
157
|
+
const formattedMessage = formatEVMMessage(message, this.logger);
|
|
158
|
+
const resolvedContext = context != null ? context : {
|
|
159
|
+
evmMessage: message
|
|
160
|
+
};
|
|
119
161
|
// Sign the message using MPC
|
|
120
162
|
const signatureEcdsa = await this.sign({
|
|
121
163
|
message: formattedMessage,
|
|
122
164
|
accountAddress: accountAddress,
|
|
123
165
|
chainName: this.chainName,
|
|
124
|
-
password
|
|
166
|
+
password,
|
|
167
|
+
signedSessionId,
|
|
168
|
+
mfaToken,
|
|
169
|
+
context: resolvedContext,
|
|
170
|
+
onError
|
|
125
171
|
});
|
|
126
172
|
// Serialize the signature
|
|
127
|
-
const serializedSignature = serializeECDSASignature(signatureEcdsa);
|
|
173
|
+
const serializedSignature = serializeECDSASignature(signatureEcdsa, this.logger);
|
|
128
174
|
return serializedSignature;
|
|
129
175
|
} catch (error) {
|
|
130
176
|
this.logger.error(ERROR_SIGN_MESSAGE, error);
|
|
@@ -148,11 +194,12 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
|
|
|
148
194
|
throw new Error(ERROR_VERIFY_MESSAGE_SIGNATURE);
|
|
149
195
|
}
|
|
150
196
|
}
|
|
151
|
-
async signTransaction({ senderAddress, transaction, password = undefined }) {
|
|
197
|
+
async signTransaction({ senderAddress, transaction, password = undefined, signedSessionId, mfaToken, onError }) {
|
|
152
198
|
await this.verifyPassword({
|
|
153
199
|
accountAddress: senderAddress,
|
|
154
200
|
password,
|
|
155
|
-
walletOperation: WalletOperation.SIGN_TRANSACTION
|
|
201
|
+
walletOperation: WalletOperation.SIGN_TRANSACTION,
|
|
202
|
+
signedSessionId
|
|
156
203
|
});
|
|
157
204
|
const serializedTx = serializeTransaction(transaction);
|
|
158
205
|
const serializedTxBytes = Uint8Array.from(Buffer.from(serializedTx.slice(2), 'hex'));
|
|
@@ -164,7 +211,13 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
|
|
|
164
211
|
message: serializedTxBytes,
|
|
165
212
|
accountAddress: senderAddress,
|
|
166
213
|
chainName: this.chainName,
|
|
167
|
-
password
|
|
214
|
+
password,
|
|
215
|
+
signedSessionId,
|
|
216
|
+
mfaToken,
|
|
217
|
+
context: {
|
|
218
|
+
evmTransaction: mapTransactionToEvmTransaction(transaction)
|
|
219
|
+
},
|
|
220
|
+
onError
|
|
168
221
|
});
|
|
169
222
|
if (!('r' in signatureEcdsa && 's' in signatureEcdsa && 'v' in signatureEcdsa)) {
|
|
170
223
|
throw new Error('Invalid signature format returned from MPC signing');
|
|
@@ -185,6 +238,38 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
|
|
|
185
238
|
throw error;
|
|
186
239
|
}
|
|
187
240
|
}
|
|
241
|
+
async signTypedData({ accountAddress, typedData, password = undefined, signedSessionId, mfaToken, onError }) {
|
|
242
|
+
await this.verifyPassword({
|
|
243
|
+
accountAddress,
|
|
244
|
+
password,
|
|
245
|
+
walletOperation: WalletOperation.SIGN_MESSAGE,
|
|
246
|
+
signedSessionId
|
|
247
|
+
});
|
|
248
|
+
try {
|
|
249
|
+
if (!accountAddress) {
|
|
250
|
+
throw new Error(ERROR_ACCOUNT_ADDRESS_REQUIRED);
|
|
251
|
+
}
|
|
252
|
+
const formattedTypedData = formatTypedData(typedData);
|
|
253
|
+
const signatureEcdsa = await this.sign({
|
|
254
|
+
message: formattedTypedData,
|
|
255
|
+
accountAddress: accountAddress,
|
|
256
|
+
chainName: this.chainName,
|
|
257
|
+
password,
|
|
258
|
+
signedSessionId,
|
|
259
|
+
isFormatted: true,
|
|
260
|
+
mfaToken,
|
|
261
|
+
context: {
|
|
262
|
+
evmTypedData: typedData
|
|
263
|
+
},
|
|
264
|
+
onError
|
|
265
|
+
});
|
|
266
|
+
const serializedSignature = serializeECDSASignature(signatureEcdsa, this.logger);
|
|
267
|
+
return serializedSignature;
|
|
268
|
+
} catch (error) {
|
|
269
|
+
this.logger.error(ERROR_SIGN_TYPED_DATA, error);
|
|
270
|
+
throw new Error(ERROR_SIGN_TYPED_DATA);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
188
273
|
deriveAccountAddress({ rawPublicKey }) {
|
|
189
274
|
const serializedUncompressed = rawPublicKey.serializeUncompressed();
|
|
190
275
|
const firstByteRemoved = serializedUncompressed.slice(1);
|
|
@@ -197,16 +282,19 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
|
|
|
197
282
|
publicKeyHex
|
|
198
283
|
};
|
|
199
284
|
}
|
|
200
|
-
async exportPrivateKey({ accountAddress, password = undefined }) {
|
|
285
|
+
async exportPrivateKey({ accountAddress, password = undefined, signedSessionId, mfaToken }) {
|
|
201
286
|
await this.verifyPassword({
|
|
202
287
|
accountAddress,
|
|
203
288
|
password,
|
|
204
|
-
walletOperation: WalletOperation.EXPORT_PRIVATE_KEY
|
|
289
|
+
walletOperation: WalletOperation.EXPORT_PRIVATE_KEY,
|
|
290
|
+
signedSessionId
|
|
205
291
|
});
|
|
206
292
|
const { derivedPrivateKey } = await this.exportKey({
|
|
207
293
|
accountAddress,
|
|
208
294
|
chainName: this.chainName,
|
|
209
|
-
password
|
|
295
|
+
password,
|
|
296
|
+
signedSessionId,
|
|
297
|
+
mfaToken
|
|
210
298
|
});
|
|
211
299
|
return derivedPrivateKey;
|
|
212
300
|
}
|
|
@@ -220,62 +308,90 @@ class DynamicEvmWalletClient extends DynamicWalletClient {
|
|
|
220
308
|
derivedPrivateKey
|
|
221
309
|
};
|
|
222
310
|
}
|
|
223
|
-
async importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password = undefined, onError }) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
311
|
+
async importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password = undefined, onError, signedSessionId }) {
|
|
312
|
+
try {
|
|
313
|
+
let ceremonyCeremonyCompleteResolver;
|
|
314
|
+
const ceremonyCompletePromise = new Promise((resolve)=>{
|
|
315
|
+
ceremonyCeremonyCompleteResolver = resolve;
|
|
316
|
+
});
|
|
317
|
+
//remove 0x if it exists
|
|
318
|
+
const formattedPrivateKey = privateKey.startsWith('0x') ? privateKey.slice(2) : privateKey;
|
|
319
|
+
// TODO: validate private key for EVM
|
|
320
|
+
const { rawPublicKey, clientKeyShares } = await this.importRawPrivateKey({
|
|
321
|
+
chainName,
|
|
322
|
+
privateKey: formattedPrivateKey,
|
|
323
|
+
thresholdSignatureScheme,
|
|
324
|
+
onError: (error)=>{
|
|
325
|
+
this.logger.error(ERROR_IMPORT_PRIVATE_KEY, error);
|
|
326
|
+
onError == null ? void 0 : onError(error);
|
|
327
|
+
},
|
|
328
|
+
onCeremonyComplete: (accountAddress, walletId)=>{
|
|
329
|
+
// update wallet map
|
|
330
|
+
const checksumAddress = getAddress(accountAddress);
|
|
331
|
+
this.walletMap[checksumAddress] = _extends({}, this.walletMap[checksumAddress] || {}, {
|
|
332
|
+
accountAddress: checksumAddress,
|
|
333
|
+
walletId,
|
|
334
|
+
chainName: this.chainName,
|
|
335
|
+
thresholdSignatureScheme,
|
|
336
|
+
clientKeySharesBackupInfo: getClientKeyShareBackupInfo()
|
|
337
|
+
});
|
|
338
|
+
this.logger.debug('walletMap updated for wallet', {
|
|
339
|
+
context: {
|
|
340
|
+
accountAddress,
|
|
341
|
+
walletId,
|
|
342
|
+
walletMap: this.walletMap
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
ceremonyCeremonyCompleteResolver(undefined);
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
// Wait for the ceremony to complete before proceeding
|
|
349
|
+
await ceremonyCompletePromise;
|
|
350
|
+
if (!rawPublicKey || !clientKeyShares) {
|
|
351
|
+
throw new Error(ERROR_IMPORT_PRIVATE_KEY);
|
|
240
352
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
353
|
+
checkRawPublicKeyInstance(rawPublicKey);
|
|
354
|
+
const { accountAddress, publicKeyHex } = await this.deriveAccountAddress({
|
|
355
|
+
rawPublicKey: rawPublicKey
|
|
356
|
+
});
|
|
357
|
+
// Update client key shares in wallet map
|
|
358
|
+
await this.setClientKeySharesToLocalStorage({
|
|
359
|
+
accountAddress,
|
|
360
|
+
clientKeyShares,
|
|
361
|
+
overwriteOrMerge: 'overwrite'
|
|
362
|
+
});
|
|
363
|
+
await this.storeEncryptedBackupByWalletWithRetry({
|
|
364
|
+
accountAddress,
|
|
365
|
+
clientKeyShares,
|
|
366
|
+
password,
|
|
367
|
+
signedSessionId
|
|
368
|
+
});
|
|
369
|
+
return {
|
|
370
|
+
accountAddress,
|
|
371
|
+
rawPublicKey,
|
|
372
|
+
publicKeyHex
|
|
373
|
+
};
|
|
374
|
+
} catch (error) {
|
|
375
|
+
this.logger.error(ERROR_IMPORT_PRIVATE_KEY, error);
|
|
376
|
+
throw error;
|
|
244
377
|
}
|
|
245
|
-
const { accountAddress, publicKeyHex } = await this.deriveAccountAddress({
|
|
246
|
-
rawPublicKey: rawPublicKey
|
|
247
|
-
});
|
|
248
|
-
// Update client key shares in wallet map
|
|
249
|
-
await this.setClientKeySharesToLocalStorage({
|
|
250
|
-
accountAddress,
|
|
251
|
-
clientKeyShares,
|
|
252
|
-
overwriteOrMerge: 'overwrite'
|
|
253
|
-
});
|
|
254
|
-
// Backup the new wallet without waiting for the promise to resolve
|
|
255
|
-
void this.storeEncryptedBackupByWalletWithRetry({
|
|
256
|
-
accountAddress,
|
|
257
|
-
clientKeyShares,
|
|
258
|
-
password
|
|
259
|
-
});
|
|
260
|
-
return {
|
|
261
|
-
accountAddress,
|
|
262
|
-
rawPublicKey,
|
|
263
|
-
publicKeyHex
|
|
264
|
-
};
|
|
265
378
|
}
|
|
266
379
|
async getEvmWallets() {
|
|
267
380
|
const wallets = await this.getWallets();
|
|
268
381
|
const evmWallets = wallets.filter((wallet)=>wallet.chainName === 'eip155');
|
|
269
382
|
return evmWallets;
|
|
270
383
|
}
|
|
271
|
-
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, storageKey, debug }){
|
|
384
|
+
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, storageKey, debug, featureFlags, authMode = AuthMode.HEADER, sdkVersion }){
|
|
272
385
|
super({
|
|
273
386
|
environmentId,
|
|
274
387
|
authToken,
|
|
275
388
|
baseApiUrl,
|
|
276
389
|
baseMPCRelayApiUrl,
|
|
277
390
|
storageKey,
|
|
278
|
-
debug
|
|
391
|
+
debug,
|
|
392
|
+
featureFlags,
|
|
393
|
+
authMode,
|
|
394
|
+
sdkVersion
|
|
279
395
|
}), this.chainName = 'EVM';
|
|
280
396
|
}
|
|
281
397
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs-wallet/evm",
|
|
3
|
-
"version": "0.0.0-beta.
|
|
3
|
+
"version": "0.0.0-beta.308.1",
|
|
4
4
|
"license": "MIT",
|
|
5
|
+
"type": "commonjs",
|
|
5
6
|
"dependencies": {
|
|
6
|
-
"@dynamic-labs-wallet/browser": "0.0.0-beta.
|
|
7
|
+
"@dynamic-labs-wallet/browser": "0.0.0-beta.308.1",
|
|
8
|
+
"@dynamic-labs/sdk-api-core": "^0.0.758"
|
|
7
9
|
},
|
|
8
10
|
"peerDependencies": {
|
|
9
11
|
"viem": "^2.22.1"
|
|
@@ -25,7 +27,7 @@
|
|
|
25
27
|
"types": "./index.esm.d.ts",
|
|
26
28
|
"import": "./index.esm.js",
|
|
27
29
|
"require": "./index.cjs.js",
|
|
28
|
-
"default": "./index.
|
|
30
|
+
"default": "./index.esm.js"
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
33
|
}
|
package/src/client/client.d.ts
CHANGED
|
@@ -1,45 +1,64 @@
|
|
|
1
|
-
import { DynamicWalletClient, EcdsaKeygenResult, EcdsaPublicKey, Ed25519KeygenResult, ThresholdSignatureScheme
|
|
2
|
-
import
|
|
1
|
+
import { DynamicWalletClient, DynamicWalletClientProps, EcdsaKeygenResult, EcdsaPublicKey, Ed25519KeygenResult, ThresholdSignatureScheme } from '@dynamic-labs-wallet/browser';
|
|
2
|
+
import type { SignMessageContext } from '@dynamic-labs/sdk-api-core';
|
|
3
|
+
import { type Chain, type PublicClient, type SignableMessage, type TransactionSerializable, type TypedData } from 'viem';
|
|
3
4
|
export declare class DynamicEvmWalletClient extends DynamicWalletClient {
|
|
4
5
|
readonly chainName = "EVM";
|
|
5
|
-
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, storageKey, debug, }: DynamicWalletClientProps);
|
|
6
|
+
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, storageKey, debug, featureFlags, authMode, sdkVersion, }: DynamicWalletClientProps);
|
|
6
7
|
createViemPublicClient({ chain, rpcUrl, }: {
|
|
7
8
|
chain: Chain;
|
|
8
9
|
rpcUrl?: string;
|
|
9
10
|
}): PublicClient;
|
|
10
|
-
createWalletAccount({ thresholdSignatureScheme, password, onError, }: {
|
|
11
|
+
createWalletAccount({ thresholdSignatureScheme, password, onError, signedSessionId, }: {
|
|
11
12
|
thresholdSignatureScheme: ThresholdSignatureScheme;
|
|
12
13
|
password?: string;
|
|
13
14
|
onError?: (error: Error) => void;
|
|
15
|
+
signedSessionId: string;
|
|
14
16
|
}): Promise<{
|
|
15
17
|
accountAddress: string;
|
|
16
18
|
publicKeyHex: string;
|
|
17
|
-
rawPublicKey: EcdsaPublicKey | Uint8Array | undefined;
|
|
19
|
+
rawPublicKey: EcdsaPublicKey | Uint8Array | string | undefined;
|
|
18
20
|
}>;
|
|
19
|
-
signMessage({ message, accountAddress, password, }: {
|
|
21
|
+
signMessage({ message, accountAddress, password, signedSessionId, mfaToken, context, onError, }: {
|
|
20
22
|
message: string;
|
|
21
23
|
accountAddress: string;
|
|
22
24
|
password?: string;
|
|
25
|
+
signedSessionId: string;
|
|
26
|
+
mfaToken?: string;
|
|
27
|
+
context?: SignMessageContext;
|
|
28
|
+
onError?: (error: Error) => void;
|
|
23
29
|
}): Promise<`0x${string}`>;
|
|
24
30
|
verifyMessageSignature({ accountAddress, message, signature, }: {
|
|
25
31
|
accountAddress: string;
|
|
26
32
|
message: SignableMessage;
|
|
27
33
|
signature: any;
|
|
28
34
|
}): Promise<boolean>;
|
|
29
|
-
signTransaction({ senderAddress, transaction, password, }: {
|
|
35
|
+
signTransaction({ senderAddress, transaction, password, signedSessionId, mfaToken, onError, }: {
|
|
30
36
|
senderAddress: string;
|
|
31
37
|
transaction: TransactionSerializable;
|
|
32
38
|
password?: string;
|
|
39
|
+
signedSessionId: string;
|
|
40
|
+
mfaToken?: string;
|
|
41
|
+
onError?: (error: Error) => void;
|
|
33
42
|
}): Promise<string>;
|
|
43
|
+
signTypedData({ accountAddress, typedData, password, signedSessionId, mfaToken, onError, }: {
|
|
44
|
+
accountAddress: string;
|
|
45
|
+
typedData: TypedData;
|
|
46
|
+
password?: string;
|
|
47
|
+
signedSessionId: string;
|
|
48
|
+
mfaToken?: string;
|
|
49
|
+
onError?: (error: Error) => void;
|
|
50
|
+
}): Promise<`0x${string}`>;
|
|
34
51
|
deriveAccountAddress({ rawPublicKey }: {
|
|
35
52
|
rawPublicKey: EcdsaPublicKey;
|
|
36
53
|
}): {
|
|
37
54
|
accountAddress: `0x${string}`;
|
|
38
55
|
publicKeyHex: any;
|
|
39
56
|
};
|
|
40
|
-
exportPrivateKey({ accountAddress, password, }: {
|
|
57
|
+
exportPrivateKey({ accountAddress, password, signedSessionId, mfaToken, }: {
|
|
41
58
|
accountAddress: string;
|
|
42
59
|
password?: string;
|
|
60
|
+
signedSessionId: string;
|
|
61
|
+
mfaToken?: string;
|
|
43
62
|
}): Promise<string | undefined>;
|
|
44
63
|
offlineExportPrivateKey({ keyShares, derivationPath, }: {
|
|
45
64
|
keyShares: (EcdsaKeygenResult | Ed25519KeygenResult)[];
|
|
@@ -47,16 +66,17 @@ export declare class DynamicEvmWalletClient extends DynamicWalletClient {
|
|
|
47
66
|
}): Promise<{
|
|
48
67
|
derivedPrivateKey: string | undefined;
|
|
49
68
|
}>;
|
|
50
|
-
importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password, onError, }: {
|
|
69
|
+
importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password, onError, signedSessionId, }: {
|
|
51
70
|
privateKey: string;
|
|
52
71
|
chainName: string;
|
|
53
72
|
thresholdSignatureScheme: ThresholdSignatureScheme;
|
|
54
73
|
password?: string;
|
|
55
74
|
onError?: (error: Error) => void;
|
|
75
|
+
signedSessionId: string;
|
|
56
76
|
}): Promise<{
|
|
57
77
|
accountAddress: string;
|
|
58
78
|
publicKeyHex: string;
|
|
59
|
-
rawPublicKey: EcdsaPublicKey | Uint8Array | undefined;
|
|
79
|
+
rawPublicKey: EcdsaPublicKey | Uint8Array | string | undefined;
|
|
60
80
|
}>;
|
|
61
81
|
getEvmWallets(): Promise<any>;
|
|
62
82
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,7 +1,2 @@
|
|
|
1
1
|
export declare const EVM_SIGN_MESSAGE_PREFIX = "\u0019Ethereum Signed Message:\n";
|
|
2
|
-
export declare const ERROR_KEYGEN_FAILED = "Error with keygen";
|
|
3
|
-
export declare const ERROR_CREATE_WALLET_ACCOUNT = "Error creating evm wallet account";
|
|
4
|
-
export declare const ERROR_SIGN_MESSAGE = "Error signing message";
|
|
5
|
-
export declare const ERROR_ACCOUNT_ADDRESS_REQUIRED = "Account address is required";
|
|
6
|
-
export declare const ERROR_VERIFY_MESSAGE_SIGNATURE = "Error verifying message signature";
|
|
7
2
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/client/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,uBAAuB,qCAAmC,CAAC
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/client/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,uBAAuB,qCAAmC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SignMessageEvmTransaction } from '@dynamic-labs/sdk-api-core';
|
|
2
|
+
import type { TransactionSerializable } from 'viem';
|
|
3
|
+
export declare const checkRawPublicKeyInstance: (rawPublicKey: any) => void;
|
|
4
|
+
export declare const mapTransactionToEvmTransaction: (transaction: TransactionSerializable) => SignMessageEvmTransaction;
|
|
5
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/client/helpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AAC5E,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,MAAM,CAAC;AAEpD,eAAO,MAAM,yBAAyB,iBAAkB,GAAG,SAI1D,CAAC;AAEF,eAAO,MAAM,8BAA8B,gBAC5B,uBAAuB,KACnC,yBAgBD,CAAC"}
|
package/src/utils.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import type { EcdsaSignature } from '@dynamic-labs-wallet/browser';
|
|
1
|
+
import type { EcdsaSignature, Logger } from '@dynamic-labs-wallet/browser';
|
|
2
|
+
import type { TypedData } from 'viem';
|
|
2
3
|
export declare const formatEVMMessage: (message_: string | {
|
|
3
4
|
raw: string | Uint8Array;
|
|
4
|
-
}) => `0x${string}`;
|
|
5
|
-
export declare const
|
|
5
|
+
}, logger: Logger) => `0x${string}`;
|
|
6
|
+
export declare const formatTypedData: (typedData: TypedData | {
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}) => string;
|
|
9
|
+
export declare const serializeECDSASignature: (signature: EcdsaSignature, logger: Logger) => `0x${string}`;
|
|
6
10
|
//# sourceMappingURL=utils.d.ts.map
|
package/src/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../packages/src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../packages/src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,KAAK,EAA2B,SAAS,EAAE,MAAM,MAAM,CAAC;AAW/D,eAAO,MAAM,gBAAgB,aACjB,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;CAAE,UACvC,MAAM,kBAmBf,CAAC;AAEF,eAAO,MAAM,eAAe,cACf,SAAS,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,WAGlD,CAAC;AAEF,eAAO,MAAM,uBAAuB,cACvB,cAAc,UACjB,MAAM,kBAef,CAAC"}
|