@dynamic-labs-wallet/browser 0.0.10 → 0.0.12
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 +69 -105
- package/index.esm.js +70 -106
- package/package.json +3 -3
- package/src/client.d.ts +13 -20
- package/src/client.d.ts.map +1 -1
package/index.cjs.js
CHANGED
|
@@ -182,34 +182,24 @@ const downloadFileFromGoogleDrive = async ({ accessToken, name })=>{
|
|
|
182
182
|
const BACKUP_FILENAME = 'dynamicWalletSecretBackup.json';
|
|
183
183
|
|
|
184
184
|
class DynamicWalletClient {
|
|
185
|
-
async serverInitializeKeyGen({ chainName,
|
|
185
|
+
async serverInitializeKeyGen({ chainName, clientKeygenIds, thresholdSignatureScheme }) {
|
|
186
186
|
// Initilize keygen, create room, and create the wallet account on the server
|
|
187
187
|
const data = await this.apiClient.createWalletAccount({
|
|
188
188
|
chainName,
|
|
189
|
-
clientKeygenIds
|
|
190
|
-
clientPrimaryKeygenId,
|
|
191
|
-
clientSecondaryKeygenId
|
|
192
|
-
],
|
|
189
|
+
clientKeygenIds,
|
|
193
190
|
thresholdSignatureScheme
|
|
194
191
|
});
|
|
195
192
|
return data;
|
|
196
193
|
}
|
|
197
|
-
async clientInitializeKeyGen({ chainName }) {
|
|
194
|
+
async clientInitializeKeyGen({ chainName, thresholdSignatureScheme }) {
|
|
198
195
|
// Get the mpc signer
|
|
199
196
|
const mpcSigner = getMPCSigner({
|
|
200
197
|
chainName,
|
|
201
198
|
baseRelayUrl: this.baseMPCRelayApiUrl
|
|
202
199
|
});
|
|
203
|
-
|
|
204
|
-
const keygenInitResults = await Promise.all(
|
|
205
|
-
|
|
206
|
-
mpcSigner.initKeygen()
|
|
207
|
-
]);
|
|
208
|
-
const [clientPrimaryKeygenInitResult, clientSecondaryKeygenInitResult] = keygenInitResults;
|
|
209
|
-
return {
|
|
210
|
-
clientPrimaryKeygenInitResult,
|
|
211
|
-
clientSecondaryKeygenInitResult
|
|
212
|
-
};
|
|
200
|
+
const clientThreshold = core.getClientThreshold(thresholdSignatureScheme);
|
|
201
|
+
const keygenInitResults = await Promise.all(Array(clientThreshold).fill(null).map(()=>mpcSigner.initKeygen()));
|
|
202
|
+
return keygenInitResults;
|
|
213
203
|
}
|
|
214
204
|
async derivePublicKey({ chainName, keyShare }) {
|
|
215
205
|
const mpcSigner = getMPCSigner({
|
|
@@ -225,72 +215,58 @@ class DynamicWalletClient {
|
|
|
225
215
|
}
|
|
226
216
|
return publicKey;
|
|
227
217
|
}
|
|
228
|
-
async clientKeyGen({ chainName, roomId, serverKeygenIds,
|
|
218
|
+
async clientKeyGen({ chainName, roomId, serverKeygenIds, clientKeygenInitResults, thresholdSignatureScheme }) {
|
|
229
219
|
// Get the chain config and the mpc signer
|
|
230
|
-
const chainConfig = core.getMPCChainConfig(chainName);
|
|
231
220
|
const mpcSigner = getMPCSigner({
|
|
232
221
|
chainName,
|
|
233
222
|
baseRelayUrl: this.baseMPCRelayApiUrl
|
|
234
223
|
});
|
|
235
|
-
// All parties receive the keygenIds from all OTHER parties
|
|
236
|
-
const clientPrimaryKeygenId = clientPrimaryKeygenInitResult.keygenId;
|
|
237
|
-
const clientSecondaryKeygenId = clientSecondaryKeygenInitResult.keygenId;
|
|
238
|
-
const clientPrimaryKeygenIds = [
|
|
239
|
-
...serverKeygenIds,
|
|
240
|
-
clientSecondaryKeygenId
|
|
241
|
-
];
|
|
242
|
-
const clientSecondaryKeygenIds = [
|
|
243
|
-
...serverKeygenIds,
|
|
244
|
-
clientPrimaryKeygenId
|
|
245
|
-
];
|
|
246
224
|
// Get the MPC config for the threshold signature scheme
|
|
247
225
|
const mpcConfig = core.MPC_CONFIG[thresholdSignatureScheme];
|
|
248
|
-
//
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}
|
|
226
|
+
// For each client keygen init result, create an array of other parties' keygenIds
|
|
227
|
+
const clientKeygenResults = await Promise.all(clientKeygenInitResults.map((currentInit)=>{
|
|
228
|
+
// Get all other client keygenIds (excluding current one)
|
|
229
|
+
const otherClientKeygenIds = clientKeygenInitResults.filter((init)=>init.keygenId !== currentInit.keygenId).map((init)=>init.keygenId);
|
|
230
|
+
// Combine server keygenIds with other client keygenIds
|
|
231
|
+
const allOtherKeygenIds = [
|
|
232
|
+
...serverKeygenIds,
|
|
233
|
+
...otherClientKeygenIds
|
|
234
|
+
];
|
|
235
|
+
return mpcSigner.keygen(roomId, mpcConfig.numberOfParties, mpcConfig.threshold, currentInit, allOtherKeygenIds);
|
|
236
|
+
}));
|
|
237
|
+
// only need one client keygen result to derive the public key
|
|
238
|
+
const [clientKeygenResult] = clientKeygenResults;
|
|
239
|
+
const rawPublicKey = await this.derivePublicKey({
|
|
240
|
+
chainName,
|
|
241
|
+
keyShare: clientKeygenResult
|
|
242
|
+
});
|
|
265
243
|
return {
|
|
266
244
|
rawPublicKey,
|
|
267
|
-
|
|
268
|
-
secondaryKeygenResult: clientSecondaryKeygenResult
|
|
245
|
+
clientKeygenResults
|
|
269
246
|
};
|
|
270
247
|
}
|
|
271
248
|
async keyGen({ chainName, thresholdSignatureScheme }) {
|
|
272
249
|
try {
|
|
273
|
-
const
|
|
274
|
-
chainName
|
|
250
|
+
const clientKeygenInitResults = await this.clientInitializeKeyGen({
|
|
251
|
+
chainName,
|
|
252
|
+
thresholdSignatureScheme
|
|
275
253
|
});
|
|
276
|
-
const
|
|
254
|
+
const clientKeygenIds = clientKeygenInitResults.map((result)=>result.keygenId);
|
|
255
|
+
const { roomId, serverKeygenIds } = await this.serverInitializeKeyGen({
|
|
277
256
|
chainName,
|
|
278
|
-
|
|
279
|
-
clientSecondaryKeygenId: clientSecondaryKeygenInitResult.keygenId,
|
|
257
|
+
clientKeygenIds,
|
|
280
258
|
thresholdSignatureScheme
|
|
281
259
|
});
|
|
282
|
-
const { rawPublicKey,
|
|
260
|
+
const { rawPublicKey, clientKeygenResults: clientKeyShares } = await this.clientKeyGen({
|
|
283
261
|
chainName,
|
|
284
|
-
roomId
|
|
285
|
-
serverKeygenIds
|
|
286
|
-
|
|
287
|
-
clientSecondaryKeygenInitResult,
|
|
262
|
+
roomId,
|
|
263
|
+
serverKeygenIds,
|
|
264
|
+
clientKeygenInitResults,
|
|
288
265
|
thresholdSignatureScheme
|
|
289
266
|
});
|
|
290
267
|
return {
|
|
291
268
|
rawPublicKey,
|
|
292
|
-
|
|
293
|
-
secondaryKeygenResult
|
|
269
|
+
clientKeyShares
|
|
294
270
|
};
|
|
295
271
|
} catch (error) {
|
|
296
272
|
console.error('Error creating wallet account', error);
|
|
@@ -299,6 +275,9 @@ class DynamicWalletClient {
|
|
|
299
275
|
}
|
|
300
276
|
async serverSign({ walletId, message }) {
|
|
301
277
|
// Create the room and sign the message
|
|
278
|
+
if (typeof message !== 'string') {
|
|
279
|
+
message = '0x' + Buffer.from(message).toString('hex');
|
|
280
|
+
}
|
|
302
281
|
const data = await this.apiClient.signMessage({
|
|
303
282
|
walletId,
|
|
304
283
|
message
|
|
@@ -314,11 +293,12 @@ class DynamicWalletClient {
|
|
|
314
293
|
});
|
|
315
294
|
const derivationPath = new Uint32Array(chainConfig.derivationPath);
|
|
316
295
|
let formattedMessage;
|
|
296
|
+
//note: Ecdsa can also be used by bitcoin, but only keccak256 is used by ethereum
|
|
317
297
|
if (mpcSigner instanceof libMpcWeb.Ecdsa) {
|
|
318
|
-
formattedMessage = libMpcWeb.MessageHash.
|
|
319
|
-
} else if (mpcSigner instanceof libMpcWeb.Ed25519) {
|
|
298
|
+
formattedMessage = libMpcWeb.MessageHash.keccak256(message);
|
|
299
|
+
} else if (mpcSigner instanceof libMpcWeb.Ed25519 && typeof message === 'string') {
|
|
320
300
|
formattedMessage = new TextEncoder().encode(message);
|
|
321
|
-
} else if (mpcSigner instanceof libMpcWeb.BIP340) {
|
|
301
|
+
} else if (mpcSigner instanceof libMpcWeb.BIP340 && typeof message === 'string') {
|
|
322
302
|
formattedMessage = new TextEncoder().encode(message);
|
|
323
303
|
} else {
|
|
324
304
|
throw new Error('Unsupported signer type');
|
|
@@ -594,59 +574,43 @@ class DynamicWalletClient {
|
|
|
594
574
|
return decryptedKeyShare;
|
|
595
575
|
}
|
|
596
576
|
async importRawPrivateKey({ chainName, privateKey, thresholdSignatureScheme }) {
|
|
597
|
-
const chainConfig = core.getMPCChainConfig(chainName);
|
|
598
577
|
const mpcSigner = getMPCSigner({
|
|
599
578
|
chainName,
|
|
600
579
|
baseRelayUrl: this.baseMPCRelayApiUrl
|
|
601
580
|
});
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
});
|
|
606
|
-
const
|
|
607
|
-
const clientPrimaryKeygenId = clientPrimaryKeygenInitResult.keygenId;
|
|
608
|
-
// 2. server to create a room for importing the private key
|
|
609
|
-
// server will do 3 things:
|
|
610
|
-
// --- 1. init keygen for the server as a party
|
|
611
|
-
// --- 2. open a room and return the roomId for the ceremony
|
|
612
|
-
// --- 3. join the room as a party for the 2/3 ceremony
|
|
581
|
+
const clientKeygenInitResults = await this.clientInitializeKeyGen({
|
|
582
|
+
chainName,
|
|
583
|
+
thresholdSignatureScheme
|
|
584
|
+
});
|
|
585
|
+
const clientKeygenIds = clientKeygenInitResults.map((result)=>result.keygenId);
|
|
613
586
|
const { roomId, serverKeygenIds } = await this.apiClient.importPrivateKey({
|
|
614
587
|
chainName,
|
|
615
|
-
clientKeygenIds
|
|
616
|
-
clientPrimaryKeygenId,
|
|
617
|
-
clientSecondaryKeygenId
|
|
618
|
-
],
|
|
588
|
+
clientKeygenIds,
|
|
619
589
|
thresholdSignatureScheme
|
|
620
590
|
});
|
|
621
591
|
const { threshold } = core.getTSSConfig(thresholdSignatureScheme);
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
const
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
} else if (mpcSigner instanceof libMpcWeb.Ed25519) {
|
|
642
|
-
rawPublicKey = await mpcSigner.derivePubkey(clientPrimaryKeygenResult, derivationPath);
|
|
643
|
-
} else if (mpcSigner instanceof libMpcWeb.BIP340) {
|
|
644
|
-
rawPublicKey = await mpcSigner.deriveTweakPubkey(clientPrimaryKeygenResult, derivationPath);
|
|
645
|
-
}
|
|
592
|
+
const clientKeygenResults = await Promise.all(clientKeygenInitResults.map((currentInit, index)=>{
|
|
593
|
+
const otherClientKeygenIds = clientKeygenInitResults.filter((init)=>init.keygenId !== currentInit.keygenId).map((init)=>init.keygenId);
|
|
594
|
+
if (index === 0) {
|
|
595
|
+
return mpcSigner.importPrivateKeyImporter(roomId, threshold, privateKey, currentInit, [
|
|
596
|
+
...serverKeygenIds,
|
|
597
|
+
...otherClientKeygenIds
|
|
598
|
+
]);
|
|
599
|
+
} else {
|
|
600
|
+
return mpcSigner.importPrivateKeyRecipient(roomId, threshold, currentInit, [
|
|
601
|
+
...serverKeygenIds,
|
|
602
|
+
...otherClientKeygenIds
|
|
603
|
+
]);
|
|
604
|
+
}
|
|
605
|
+
}));
|
|
606
|
+
const [clientKeygenResult] = clientKeygenResults;
|
|
607
|
+
const rawPublicKey = await this.derivePublicKey({
|
|
608
|
+
chainName,
|
|
609
|
+
keyShare: clientKeygenResult
|
|
610
|
+
});
|
|
646
611
|
return {
|
|
647
612
|
rawPublicKey,
|
|
648
|
-
|
|
649
|
-
secondaryKeygenResult: clientSecondaryKeygenResult
|
|
613
|
+
clientKeyShares: clientKeygenResults
|
|
650
614
|
};
|
|
651
615
|
}
|
|
652
616
|
async exportClientKeyshares({ accountAddress }) {
|
package/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SigningAlgorithm, MPC_RELAY_PROD_API_URL, getMPCChainConfig, MPC_CONFIG, getTSSConfig, DynamicApiClient } from '@dynamic-labs-wallet/core';
|
|
1
|
+
import { SigningAlgorithm, MPC_RELAY_PROD_API_URL, getMPCChainConfig, getClientThreshold, MPC_CONFIG, getTSSConfig, DynamicApiClient } from '@dynamic-labs-wallet/core';
|
|
2
2
|
export * from '@dynamic-labs-wallet/core';
|
|
3
3
|
import { BIP340, Ed25519, Ecdsa, MessageHash, EcdsaKeygenResult, Ed25519KeygenResult, BIP340KeygenResult } from '@dynamic-labs-wallet/lib-mpc-web';
|
|
4
4
|
export { BIP340, BIP340InitKeygenResult, BIP340KeygenResult, Ecdsa, EcdsaInitKeygenResult, EcdsaKeygenResult, EcdsaPublicKey, EcdsaSignature, Ed25519, Ed25519InitKeygenResult, Ed25519KeygenResult, MessageHash } from '@dynamic-labs-wallet/lib-mpc-web';
|
|
@@ -182,34 +182,24 @@ const downloadFileFromGoogleDrive = async ({ accessToken, name })=>{
|
|
|
182
182
|
const BACKUP_FILENAME = 'dynamicWalletSecretBackup.json';
|
|
183
183
|
|
|
184
184
|
class DynamicWalletClient {
|
|
185
|
-
async serverInitializeKeyGen({ chainName,
|
|
185
|
+
async serverInitializeKeyGen({ chainName, clientKeygenIds, thresholdSignatureScheme }) {
|
|
186
186
|
// Initilize keygen, create room, and create the wallet account on the server
|
|
187
187
|
const data = await this.apiClient.createWalletAccount({
|
|
188
188
|
chainName,
|
|
189
|
-
clientKeygenIds
|
|
190
|
-
clientPrimaryKeygenId,
|
|
191
|
-
clientSecondaryKeygenId
|
|
192
|
-
],
|
|
189
|
+
clientKeygenIds,
|
|
193
190
|
thresholdSignatureScheme
|
|
194
191
|
});
|
|
195
192
|
return data;
|
|
196
193
|
}
|
|
197
|
-
async clientInitializeKeyGen({ chainName }) {
|
|
194
|
+
async clientInitializeKeyGen({ chainName, thresholdSignatureScheme }) {
|
|
198
195
|
// Get the mpc signer
|
|
199
196
|
const mpcSigner = getMPCSigner({
|
|
200
197
|
chainName,
|
|
201
198
|
baseRelayUrl: this.baseMPCRelayApiUrl
|
|
202
199
|
});
|
|
203
|
-
|
|
204
|
-
const keygenInitResults = await Promise.all(
|
|
205
|
-
|
|
206
|
-
mpcSigner.initKeygen()
|
|
207
|
-
]);
|
|
208
|
-
const [clientPrimaryKeygenInitResult, clientSecondaryKeygenInitResult] = keygenInitResults;
|
|
209
|
-
return {
|
|
210
|
-
clientPrimaryKeygenInitResult,
|
|
211
|
-
clientSecondaryKeygenInitResult
|
|
212
|
-
};
|
|
200
|
+
const clientThreshold = getClientThreshold(thresholdSignatureScheme);
|
|
201
|
+
const keygenInitResults = await Promise.all(Array(clientThreshold).fill(null).map(()=>mpcSigner.initKeygen()));
|
|
202
|
+
return keygenInitResults;
|
|
213
203
|
}
|
|
214
204
|
async derivePublicKey({ chainName, keyShare }) {
|
|
215
205
|
const mpcSigner = getMPCSigner({
|
|
@@ -225,72 +215,58 @@ class DynamicWalletClient {
|
|
|
225
215
|
}
|
|
226
216
|
return publicKey;
|
|
227
217
|
}
|
|
228
|
-
async clientKeyGen({ chainName, roomId, serverKeygenIds,
|
|
218
|
+
async clientKeyGen({ chainName, roomId, serverKeygenIds, clientKeygenInitResults, thresholdSignatureScheme }) {
|
|
229
219
|
// Get the chain config and the mpc signer
|
|
230
|
-
const chainConfig = getMPCChainConfig(chainName);
|
|
231
220
|
const mpcSigner = getMPCSigner({
|
|
232
221
|
chainName,
|
|
233
222
|
baseRelayUrl: this.baseMPCRelayApiUrl
|
|
234
223
|
});
|
|
235
|
-
// All parties receive the keygenIds from all OTHER parties
|
|
236
|
-
const clientPrimaryKeygenId = clientPrimaryKeygenInitResult.keygenId;
|
|
237
|
-
const clientSecondaryKeygenId = clientSecondaryKeygenInitResult.keygenId;
|
|
238
|
-
const clientPrimaryKeygenIds = [
|
|
239
|
-
...serverKeygenIds,
|
|
240
|
-
clientSecondaryKeygenId
|
|
241
|
-
];
|
|
242
|
-
const clientSecondaryKeygenIds = [
|
|
243
|
-
...serverKeygenIds,
|
|
244
|
-
clientPrimaryKeygenId
|
|
245
|
-
];
|
|
246
224
|
// Get the MPC config for the threshold signature scheme
|
|
247
225
|
const mpcConfig = MPC_CONFIG[thresholdSignatureScheme];
|
|
248
|
-
//
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}
|
|
226
|
+
// For each client keygen init result, create an array of other parties' keygenIds
|
|
227
|
+
const clientKeygenResults = await Promise.all(clientKeygenInitResults.map((currentInit)=>{
|
|
228
|
+
// Get all other client keygenIds (excluding current one)
|
|
229
|
+
const otherClientKeygenIds = clientKeygenInitResults.filter((init)=>init.keygenId !== currentInit.keygenId).map((init)=>init.keygenId);
|
|
230
|
+
// Combine server keygenIds with other client keygenIds
|
|
231
|
+
const allOtherKeygenIds = [
|
|
232
|
+
...serverKeygenIds,
|
|
233
|
+
...otherClientKeygenIds
|
|
234
|
+
];
|
|
235
|
+
return mpcSigner.keygen(roomId, mpcConfig.numberOfParties, mpcConfig.threshold, currentInit, allOtherKeygenIds);
|
|
236
|
+
}));
|
|
237
|
+
// only need one client keygen result to derive the public key
|
|
238
|
+
const [clientKeygenResult] = clientKeygenResults;
|
|
239
|
+
const rawPublicKey = await this.derivePublicKey({
|
|
240
|
+
chainName,
|
|
241
|
+
keyShare: clientKeygenResult
|
|
242
|
+
});
|
|
265
243
|
return {
|
|
266
244
|
rawPublicKey,
|
|
267
|
-
|
|
268
|
-
secondaryKeygenResult: clientSecondaryKeygenResult
|
|
245
|
+
clientKeygenResults
|
|
269
246
|
};
|
|
270
247
|
}
|
|
271
248
|
async keyGen({ chainName, thresholdSignatureScheme }) {
|
|
272
249
|
try {
|
|
273
|
-
const
|
|
274
|
-
chainName
|
|
250
|
+
const clientKeygenInitResults = await this.clientInitializeKeyGen({
|
|
251
|
+
chainName,
|
|
252
|
+
thresholdSignatureScheme
|
|
275
253
|
});
|
|
276
|
-
const
|
|
254
|
+
const clientKeygenIds = clientKeygenInitResults.map((result)=>result.keygenId);
|
|
255
|
+
const { roomId, serverKeygenIds } = await this.serverInitializeKeyGen({
|
|
277
256
|
chainName,
|
|
278
|
-
|
|
279
|
-
clientSecondaryKeygenId: clientSecondaryKeygenInitResult.keygenId,
|
|
257
|
+
clientKeygenIds,
|
|
280
258
|
thresholdSignatureScheme
|
|
281
259
|
});
|
|
282
|
-
const { rawPublicKey,
|
|
260
|
+
const { rawPublicKey, clientKeygenResults: clientKeyShares } = await this.clientKeyGen({
|
|
283
261
|
chainName,
|
|
284
|
-
roomId
|
|
285
|
-
serverKeygenIds
|
|
286
|
-
|
|
287
|
-
clientSecondaryKeygenInitResult,
|
|
262
|
+
roomId,
|
|
263
|
+
serverKeygenIds,
|
|
264
|
+
clientKeygenInitResults,
|
|
288
265
|
thresholdSignatureScheme
|
|
289
266
|
});
|
|
290
267
|
return {
|
|
291
268
|
rawPublicKey,
|
|
292
|
-
|
|
293
|
-
secondaryKeygenResult
|
|
269
|
+
clientKeyShares
|
|
294
270
|
};
|
|
295
271
|
} catch (error) {
|
|
296
272
|
console.error('Error creating wallet account', error);
|
|
@@ -299,6 +275,9 @@ class DynamicWalletClient {
|
|
|
299
275
|
}
|
|
300
276
|
async serverSign({ walletId, message }) {
|
|
301
277
|
// Create the room and sign the message
|
|
278
|
+
if (typeof message !== 'string') {
|
|
279
|
+
message = '0x' + Buffer.from(message).toString('hex');
|
|
280
|
+
}
|
|
302
281
|
const data = await this.apiClient.signMessage({
|
|
303
282
|
walletId,
|
|
304
283
|
message
|
|
@@ -314,11 +293,12 @@ class DynamicWalletClient {
|
|
|
314
293
|
});
|
|
315
294
|
const derivationPath = new Uint32Array(chainConfig.derivationPath);
|
|
316
295
|
let formattedMessage;
|
|
296
|
+
//note: Ecdsa can also be used by bitcoin, but only keccak256 is used by ethereum
|
|
317
297
|
if (mpcSigner instanceof Ecdsa) {
|
|
318
|
-
formattedMessage = MessageHash.
|
|
319
|
-
} else if (mpcSigner instanceof Ed25519) {
|
|
298
|
+
formattedMessage = MessageHash.keccak256(message);
|
|
299
|
+
} else if (mpcSigner instanceof Ed25519 && typeof message === 'string') {
|
|
320
300
|
formattedMessage = new TextEncoder().encode(message);
|
|
321
|
-
} else if (mpcSigner instanceof BIP340) {
|
|
301
|
+
} else if (mpcSigner instanceof BIP340 && typeof message === 'string') {
|
|
322
302
|
formattedMessage = new TextEncoder().encode(message);
|
|
323
303
|
} else {
|
|
324
304
|
throw new Error('Unsupported signer type');
|
|
@@ -594,59 +574,43 @@ class DynamicWalletClient {
|
|
|
594
574
|
return decryptedKeyShare;
|
|
595
575
|
}
|
|
596
576
|
async importRawPrivateKey({ chainName, privateKey, thresholdSignatureScheme }) {
|
|
597
|
-
const chainConfig = getMPCChainConfig(chainName);
|
|
598
577
|
const mpcSigner = getMPCSigner({
|
|
599
578
|
chainName,
|
|
600
579
|
baseRelayUrl: this.baseMPCRelayApiUrl
|
|
601
580
|
});
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
});
|
|
606
|
-
const
|
|
607
|
-
const clientPrimaryKeygenId = clientPrimaryKeygenInitResult.keygenId;
|
|
608
|
-
// 2. server to create a room for importing the private key
|
|
609
|
-
// server will do 3 things:
|
|
610
|
-
// --- 1. init keygen for the server as a party
|
|
611
|
-
// --- 2. open a room and return the roomId for the ceremony
|
|
612
|
-
// --- 3. join the room as a party for the 2/3 ceremony
|
|
581
|
+
const clientKeygenInitResults = await this.clientInitializeKeyGen({
|
|
582
|
+
chainName,
|
|
583
|
+
thresholdSignatureScheme
|
|
584
|
+
});
|
|
585
|
+
const clientKeygenIds = clientKeygenInitResults.map((result)=>result.keygenId);
|
|
613
586
|
const { roomId, serverKeygenIds } = await this.apiClient.importPrivateKey({
|
|
614
587
|
chainName,
|
|
615
|
-
clientKeygenIds
|
|
616
|
-
clientPrimaryKeygenId,
|
|
617
|
-
clientSecondaryKeygenId
|
|
618
|
-
],
|
|
588
|
+
clientKeygenIds,
|
|
619
589
|
thresholdSignatureScheme
|
|
620
590
|
});
|
|
621
591
|
const { threshold } = getTSSConfig(thresholdSignatureScheme);
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
const
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
} else if (mpcSigner instanceof Ed25519) {
|
|
642
|
-
rawPublicKey = await mpcSigner.derivePubkey(clientPrimaryKeygenResult, derivationPath);
|
|
643
|
-
} else if (mpcSigner instanceof BIP340) {
|
|
644
|
-
rawPublicKey = await mpcSigner.deriveTweakPubkey(clientPrimaryKeygenResult, derivationPath);
|
|
645
|
-
}
|
|
592
|
+
const clientKeygenResults = await Promise.all(clientKeygenInitResults.map((currentInit, index)=>{
|
|
593
|
+
const otherClientKeygenIds = clientKeygenInitResults.filter((init)=>init.keygenId !== currentInit.keygenId).map((init)=>init.keygenId);
|
|
594
|
+
if (index === 0) {
|
|
595
|
+
return mpcSigner.importPrivateKeyImporter(roomId, threshold, privateKey, currentInit, [
|
|
596
|
+
...serverKeygenIds,
|
|
597
|
+
...otherClientKeygenIds
|
|
598
|
+
]);
|
|
599
|
+
} else {
|
|
600
|
+
return mpcSigner.importPrivateKeyRecipient(roomId, threshold, currentInit, [
|
|
601
|
+
...serverKeygenIds,
|
|
602
|
+
...otherClientKeygenIds
|
|
603
|
+
]);
|
|
604
|
+
}
|
|
605
|
+
}));
|
|
606
|
+
const [clientKeygenResult] = clientKeygenResults;
|
|
607
|
+
const rawPublicKey = await this.derivePublicKey({
|
|
608
|
+
chainName,
|
|
609
|
+
keyShare: clientKeygenResult
|
|
610
|
+
});
|
|
646
611
|
return {
|
|
647
612
|
rawPublicKey,
|
|
648
|
-
|
|
649
|
-
secondaryKeygenResult: clientSecondaryKeygenResult
|
|
613
|
+
clientKeyShares: clientKeygenResults
|
|
650
614
|
};
|
|
651
615
|
}
|
|
652
616
|
async exportClientKeyshares({ accountAddress }) {
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs-wallet/browser",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@dynamic-labs-wallet/core": "0.0.
|
|
6
|
-
"@dynamic-labs-wallet/lib-mpc-web": "0.0.
|
|
5
|
+
"@dynamic-labs-wallet/core": "0.0.12",
|
|
6
|
+
"@dynamic-labs-wallet/lib-mpc-web": "0.0.12"
|
|
7
7
|
},
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "restricted"
|
package/src/client.d.ts
CHANGED
|
@@ -19,55 +19,49 @@ export declare class DynamicWalletClient {
|
|
|
19
19
|
baseApiUrl?: string;
|
|
20
20
|
baseMPCRelayApiUrl?: string;
|
|
21
21
|
});
|
|
22
|
-
serverInitializeKeyGen({ chainName,
|
|
22
|
+
serverInitializeKeyGen({ chainName, clientKeygenIds, thresholdSignatureScheme, }: {
|
|
23
23
|
chainName: string;
|
|
24
|
-
|
|
25
|
-
clientSecondaryKeygenId: string;
|
|
24
|
+
clientKeygenIds: string[];
|
|
26
25
|
thresholdSignatureScheme: ThresholdSignatureScheme;
|
|
27
26
|
}): Promise<any>;
|
|
28
|
-
clientInitializeKeyGen({ chainName }: {
|
|
27
|
+
clientInitializeKeyGen({ chainName, thresholdSignatureScheme, }: {
|
|
29
28
|
chainName: string;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
clientSecondaryKeygenInitResult: import("@dynamic-labs-wallet/lib-mpc-internal").BIP340InitKeygenResult;
|
|
33
|
-
}>;
|
|
29
|
+
thresholdSignatureScheme: ThresholdSignatureScheme;
|
|
30
|
+
}): Promise<ClientInitKeygenResult[]>;
|
|
34
31
|
derivePublicKey({ chainName, keyShare, }: {
|
|
35
32
|
chainName: string;
|
|
36
33
|
keyShare: ClientKeyShare;
|
|
37
34
|
}): Promise<EcdsaPublicKey | Uint8Array | undefined>;
|
|
38
|
-
clientKeyGen({ chainName, roomId, serverKeygenIds,
|
|
35
|
+
clientKeyGen({ chainName, roomId, serverKeygenIds, clientKeygenInitResults, thresholdSignatureScheme, }: {
|
|
39
36
|
chainName: string;
|
|
40
37
|
roomId: string;
|
|
41
38
|
serverKeygenIds: string[];
|
|
42
|
-
|
|
43
|
-
clientSecondaryKeygenInitResult: ClientInitKeygenResult;
|
|
39
|
+
clientKeygenInitResults: ClientInitKeygenResult[];
|
|
44
40
|
thresholdSignatureScheme: ThresholdSignatureScheme;
|
|
45
41
|
}): Promise<{
|
|
46
42
|
rawPublicKey: EcdsaPublicKey | Uint8Array | undefined;
|
|
47
|
-
|
|
48
|
-
secondaryKeygenResult: EcdsaKeygenResult | BIP340KeygenResult;
|
|
43
|
+
clientKeygenResults: ClientKeyShare[];
|
|
49
44
|
}>;
|
|
50
45
|
keyGen({ chainName, thresholdSignatureScheme, }: {
|
|
51
46
|
chainName: string;
|
|
52
47
|
thresholdSignatureScheme: ThresholdSignatureScheme;
|
|
53
48
|
}): Promise<{
|
|
54
49
|
rawPublicKey: EcdsaPublicKey | Uint8Array | undefined;
|
|
55
|
-
|
|
56
|
-
secondaryKeygenResult: EcdsaKeygenResult | BIP340KeygenResult;
|
|
50
|
+
clientKeyShares: ClientKeyShare[];
|
|
57
51
|
}>;
|
|
58
52
|
serverSign({ walletId, message, }: {
|
|
59
53
|
walletId: string;
|
|
60
|
-
message: string;
|
|
54
|
+
message: string | Uint8Array;
|
|
61
55
|
}): Promise<any>;
|
|
62
56
|
clientSign({ chainName, message, roomId, keyShare, }: {
|
|
63
57
|
chainName: string;
|
|
64
|
-
message: string;
|
|
58
|
+
message: string | Uint8Array;
|
|
65
59
|
roomId: string;
|
|
66
60
|
keyShare: ClientKeyShare;
|
|
67
61
|
}): Promise<Uint8Array | EcdsaSignature>;
|
|
68
62
|
sign({ accountAddress, message, chainName, }: {
|
|
69
63
|
accountAddress?: string;
|
|
70
|
-
message: string;
|
|
64
|
+
message: string | Uint8Array;
|
|
71
65
|
chainName: string;
|
|
72
66
|
}): Promise<Uint8Array | EcdsaSignature>;
|
|
73
67
|
refreshWalletAccountShares({ accountAddress, }: {
|
|
@@ -138,8 +132,7 @@ export declare class DynamicWalletClient {
|
|
|
138
132
|
thresholdSignatureScheme: ThresholdSignatureScheme;
|
|
139
133
|
}): Promise<{
|
|
140
134
|
rawPublicKey: EcdsaPublicKey | Uint8Array | undefined;
|
|
141
|
-
|
|
142
|
-
secondaryKeygenResult: ClientKeyShare;
|
|
135
|
+
clientKeyShares: ClientKeyShare[];
|
|
143
136
|
}>;
|
|
144
137
|
exportClientKeyshares({ accountAddress }: {
|
|
145
138
|
accountAddress?: string;
|
package/src/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../packages/src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,wBAAwB,EACxB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../packages/src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,wBAAwB,EACxB,gBAAgB,EAGjB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAIL,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,EAElB,cAAc,EACf,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAOrE,UAAU,gBAAgB;IACxB,SAA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