@dynamic-labs-wallet/svm 0.0.45 → 0.0.47
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 +54 -29
- package/index.esm.js +54 -29
- package/package.json +3 -3
- package/src/svm/constants.d.ts +2 -0
- package/src/svm/constants.d.ts.map +1 -0
- package/src/svm/svm.d.ts.map +1 -1
package/index.cjs.js
CHANGED
|
@@ -5,6 +5,17 @@ var bs58 = require('bs58');
|
|
|
5
5
|
var web3_js = require('@solana/web3.js');
|
|
6
6
|
require('@dynamic-labs-wallet/core');
|
|
7
7
|
|
|
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];
|
|
13
|
+
}
|
|
14
|
+
return target;
|
|
15
|
+
};
|
|
16
|
+
return _extends.apply(this, arguments);
|
|
17
|
+
}
|
|
18
|
+
|
|
8
19
|
const addSignatureToTransaction = ({ transaction, signature, signerPublicKey })=>{
|
|
9
20
|
try {
|
|
10
21
|
transaction.addSignature(signerPublicKey, Buffer.from(signature));
|
|
@@ -15,6 +26,8 @@ const addSignatureToTransaction = ({ transaction, signature, signerPublicKey })=
|
|
|
15
26
|
}
|
|
16
27
|
};
|
|
17
28
|
|
|
29
|
+
const ERROR_CREATE_WALLET_ACCOUNT = 'Error creating svm wallet account';
|
|
30
|
+
|
|
18
31
|
class DynamicSvmWalletClient extends browser.DynamicWalletClient {
|
|
19
32
|
/**
|
|
20
33
|
* Creates a wallet account on the Solana chain
|
|
@@ -25,7 +38,17 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
|
|
|
25
38
|
try {
|
|
26
39
|
const { rawPublicKey, clientKeyShares } = await this.keyGen({
|
|
27
40
|
chainName: this.chainName,
|
|
28
|
-
thresholdSignatureScheme
|
|
41
|
+
thresholdSignatureScheme,
|
|
42
|
+
onCeremonyComplete: (accountAddress, walletId)=>{
|
|
43
|
+
// update wallet map
|
|
44
|
+
this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress] || {}, {
|
|
45
|
+
accountAddress,
|
|
46
|
+
walletId,
|
|
47
|
+
chainName: this.chainName,
|
|
48
|
+
thresholdSignatureScheme,
|
|
49
|
+
clientKeySharesBackupInfo: browser.getClientKeyShareBackupInfo()
|
|
50
|
+
});
|
|
51
|
+
}
|
|
29
52
|
});
|
|
30
53
|
if (!rawPublicKey || !(rawPublicKey instanceof Uint8Array)) {
|
|
31
54
|
throw new Error('Raw public key is not a Uint8Array');
|
|
@@ -33,22 +56,17 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
|
|
|
33
56
|
if (!clientKeyShares) {
|
|
34
57
|
throw new Error('Error creating wallet account');
|
|
35
58
|
}
|
|
36
|
-
// Get EVM address from public key
|
|
37
59
|
const { accountAddress } = await this.deriveAccountAddress(rawPublicKey);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
clientKeyShares: clientKeyShares,
|
|
47
|
-
thresholdSignatureScheme,
|
|
48
|
-
clientKeySharesBackupInfo: browser.getClientKeyShareBackupInfo()
|
|
49
|
-
};
|
|
50
|
-
await this.storeEncryptedBackupByWallet({
|
|
60
|
+
// Update client key shares in wallet map
|
|
61
|
+
// warning: this might result in race condition if `onCeremonyComplete` executes at the same time
|
|
62
|
+
// TODO: remove this once iframe handling for secret shares is implemented
|
|
63
|
+
this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress] || {}, {
|
|
64
|
+
clientKeyShares
|
|
65
|
+
});
|
|
66
|
+
// Backup the new wallet without waiting for the promise to resolve
|
|
67
|
+
void this.storeEncryptedBackupByWalletWithRetry({
|
|
51
68
|
accountAddress,
|
|
69
|
+
clientKeyShares,
|
|
52
70
|
password
|
|
53
71
|
});
|
|
54
72
|
return {
|
|
@@ -57,8 +75,8 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
|
|
|
57
75
|
clientKeyShares
|
|
58
76
|
};
|
|
59
77
|
} catch (error) {
|
|
60
|
-
|
|
61
|
-
throw new Error(
|
|
78
|
+
this.logger.error(ERROR_CREATE_WALLET_ACCOUNT, error);
|
|
79
|
+
throw new Error(ERROR_CREATE_WALLET_ACCOUNT);
|
|
62
80
|
}
|
|
63
81
|
}
|
|
64
82
|
// Function to properly derive account address
|
|
@@ -228,7 +246,17 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
|
|
|
228
246
|
chainName,
|
|
229
247
|
privateKey: formattedPrivateKey,
|
|
230
248
|
thresholdSignatureScheme,
|
|
231
|
-
onError
|
|
249
|
+
onError,
|
|
250
|
+
onCeremonyComplete: (accountAddress, walletId)=>{
|
|
251
|
+
// update wallet map
|
|
252
|
+
this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress] || {}, {
|
|
253
|
+
accountAddress,
|
|
254
|
+
walletId,
|
|
255
|
+
chainName: this.chainName,
|
|
256
|
+
thresholdSignatureScheme,
|
|
257
|
+
clientKeySharesBackupInfo: browser.getClientKeyShareBackupInfo()
|
|
258
|
+
});
|
|
259
|
+
}
|
|
232
260
|
});
|
|
233
261
|
if (!rawPublicKey || !clientKeyShares) {
|
|
234
262
|
throw new Error('Error creating wallet account');
|
|
@@ -237,19 +265,16 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
|
|
|
237
265
|
if (accountAddress !== publicKey) {
|
|
238
266
|
throw new Error(`Public key mismatch: derived address ${accountAddress} !== public key ${publicKey}`);
|
|
239
267
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
this.walletMap[accountAddress] = {
|
|
268
|
+
// Update client key shares in wallet map
|
|
269
|
+
// warning: this might result in race condition if `onCeremonyComplete` executes at the same time
|
|
270
|
+
// TODO: remove this once iframe handling for secret shares is implemented
|
|
271
|
+
this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress] || {}, {
|
|
272
|
+
clientKeyShares
|
|
273
|
+
});
|
|
274
|
+
// Backup the new wallet without waiting for the promise to resolve
|
|
275
|
+
void this.storeEncryptedBackupByWalletWithRetry({
|
|
244
276
|
accountAddress,
|
|
245
|
-
walletId: newWalletId,
|
|
246
|
-
chainName: this.chainName,
|
|
247
277
|
clientKeyShares,
|
|
248
|
-
thresholdSignatureScheme,
|
|
249
|
-
clientKeySharesBackupInfo: browser.getClientKeyShareBackupInfo()
|
|
250
|
-
};
|
|
251
|
-
await this.storeEncryptedBackupByWallet({
|
|
252
|
-
accountAddress,
|
|
253
278
|
password
|
|
254
279
|
});
|
|
255
280
|
return {
|
package/index.esm.js
CHANGED
|
@@ -3,6 +3,17 @@ import bs58 from 'bs58';
|
|
|
3
3
|
import { VersionedTransaction, PublicKey, Keypair } from '@solana/web3.js';
|
|
4
4
|
import '@dynamic-labs-wallet/core';
|
|
5
5
|
|
|
6
|
+
function _extends() {
|
|
7
|
+
_extends = Object.assign || function assign(target) {
|
|
8
|
+
for(var i = 1; i < arguments.length; i++){
|
|
9
|
+
var source = arguments[i];
|
|
10
|
+
for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
|
|
11
|
+
}
|
|
12
|
+
return target;
|
|
13
|
+
};
|
|
14
|
+
return _extends.apply(this, arguments);
|
|
15
|
+
}
|
|
16
|
+
|
|
6
17
|
const addSignatureToTransaction = ({ transaction, signature, signerPublicKey })=>{
|
|
7
18
|
try {
|
|
8
19
|
transaction.addSignature(signerPublicKey, Buffer.from(signature));
|
|
@@ -13,6 +24,8 @@ const addSignatureToTransaction = ({ transaction, signature, signerPublicKey })=
|
|
|
13
24
|
}
|
|
14
25
|
};
|
|
15
26
|
|
|
27
|
+
const ERROR_CREATE_WALLET_ACCOUNT = 'Error creating svm wallet account';
|
|
28
|
+
|
|
16
29
|
class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
17
30
|
/**
|
|
18
31
|
* Creates a wallet account on the Solana chain
|
|
@@ -23,7 +36,17 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
23
36
|
try {
|
|
24
37
|
const { rawPublicKey, clientKeyShares } = await this.keyGen({
|
|
25
38
|
chainName: this.chainName,
|
|
26
|
-
thresholdSignatureScheme
|
|
39
|
+
thresholdSignatureScheme,
|
|
40
|
+
onCeremonyComplete: (accountAddress, walletId)=>{
|
|
41
|
+
// update wallet map
|
|
42
|
+
this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress] || {}, {
|
|
43
|
+
accountAddress,
|
|
44
|
+
walletId,
|
|
45
|
+
chainName: this.chainName,
|
|
46
|
+
thresholdSignatureScheme,
|
|
47
|
+
clientKeySharesBackupInfo: getClientKeyShareBackupInfo()
|
|
48
|
+
});
|
|
49
|
+
}
|
|
27
50
|
});
|
|
28
51
|
if (!rawPublicKey || !(rawPublicKey instanceof Uint8Array)) {
|
|
29
52
|
throw new Error('Raw public key is not a Uint8Array');
|
|
@@ -31,22 +54,17 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
31
54
|
if (!clientKeyShares) {
|
|
32
55
|
throw new Error('Error creating wallet account');
|
|
33
56
|
}
|
|
34
|
-
// Get EVM address from public key
|
|
35
57
|
const { accountAddress } = await this.deriveAccountAddress(rawPublicKey);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
clientKeyShares: clientKeyShares,
|
|
45
|
-
thresholdSignatureScheme,
|
|
46
|
-
clientKeySharesBackupInfo: getClientKeyShareBackupInfo()
|
|
47
|
-
};
|
|
48
|
-
await this.storeEncryptedBackupByWallet({
|
|
58
|
+
// Update client key shares in wallet map
|
|
59
|
+
// warning: this might result in race condition if `onCeremonyComplete` executes at the same time
|
|
60
|
+
// TODO: remove this once iframe handling for secret shares is implemented
|
|
61
|
+
this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress] || {}, {
|
|
62
|
+
clientKeyShares
|
|
63
|
+
});
|
|
64
|
+
// Backup the new wallet without waiting for the promise to resolve
|
|
65
|
+
void this.storeEncryptedBackupByWalletWithRetry({
|
|
49
66
|
accountAddress,
|
|
67
|
+
clientKeyShares,
|
|
50
68
|
password
|
|
51
69
|
});
|
|
52
70
|
return {
|
|
@@ -55,8 +73,8 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
55
73
|
clientKeyShares
|
|
56
74
|
};
|
|
57
75
|
} catch (error) {
|
|
58
|
-
|
|
59
|
-
throw new Error(
|
|
76
|
+
this.logger.error(ERROR_CREATE_WALLET_ACCOUNT, error);
|
|
77
|
+
throw new Error(ERROR_CREATE_WALLET_ACCOUNT);
|
|
60
78
|
}
|
|
61
79
|
}
|
|
62
80
|
// Function to properly derive account address
|
|
@@ -226,7 +244,17 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
226
244
|
chainName,
|
|
227
245
|
privateKey: formattedPrivateKey,
|
|
228
246
|
thresholdSignatureScheme,
|
|
229
|
-
onError
|
|
247
|
+
onError,
|
|
248
|
+
onCeremonyComplete: (accountAddress, walletId)=>{
|
|
249
|
+
// update wallet map
|
|
250
|
+
this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress] || {}, {
|
|
251
|
+
accountAddress,
|
|
252
|
+
walletId,
|
|
253
|
+
chainName: this.chainName,
|
|
254
|
+
thresholdSignatureScheme,
|
|
255
|
+
clientKeySharesBackupInfo: getClientKeyShareBackupInfo()
|
|
256
|
+
});
|
|
257
|
+
}
|
|
230
258
|
});
|
|
231
259
|
if (!rawPublicKey || !clientKeyShares) {
|
|
232
260
|
throw new Error('Error creating wallet account');
|
|
@@ -235,19 +263,16 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
235
263
|
if (accountAddress !== publicKey) {
|
|
236
264
|
throw new Error(`Public key mismatch: derived address ${accountAddress} !== public key ${publicKey}`);
|
|
237
265
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
this.walletMap[accountAddress] = {
|
|
266
|
+
// Update client key shares in wallet map
|
|
267
|
+
// warning: this might result in race condition if `onCeremonyComplete` executes at the same time
|
|
268
|
+
// TODO: remove this once iframe handling for secret shares is implemented
|
|
269
|
+
this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress] || {}, {
|
|
270
|
+
clientKeyShares
|
|
271
|
+
});
|
|
272
|
+
// Backup the new wallet without waiting for the promise to resolve
|
|
273
|
+
void this.storeEncryptedBackupByWalletWithRetry({
|
|
242
274
|
accountAddress,
|
|
243
|
-
walletId: newWalletId,
|
|
244
|
-
chainName: this.chainName,
|
|
245
275
|
clientKeyShares,
|
|
246
|
-
thresholdSignatureScheme,
|
|
247
|
-
clientKeySharesBackupInfo: getClientKeyShareBackupInfo()
|
|
248
|
-
};
|
|
249
|
-
await this.storeEncryptedBackupByWallet({
|
|
250
|
-
accountAddress,
|
|
251
276
|
password
|
|
252
277
|
});
|
|
253
278
|
return {
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs-wallet/svm",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.47",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@dynamic-labs-wallet/browser": "0.0.
|
|
7
|
-
"@dynamic-labs-wallet/core": "0.0.
|
|
6
|
+
"@dynamic-labs-wallet/browser": "0.0.47",
|
|
7
|
+
"@dynamic-labs-wallet/core": "0.0.47",
|
|
8
8
|
"@solana/web3.js": "^1.98.0",
|
|
9
9
|
"bs58": "^6.0.0"
|
|
10
10
|
},
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/svm/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,2BAA2B,sCAAsC,CAAC"}
|
package/src/svm/svm.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"svm.d.ts","sourceRoot":"","sources":["../../src/svm/svm.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,wBAAwB,EAGzB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAEL,WAAW,EACX,oBAAoB,EAErB,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"svm.d.ts","sourceRoot":"","sources":["../../src/svm/svm.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,wBAAwB,EAGzB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAEL,WAAW,EACX,oBAAoB,EAErB,MAAM,iBAAiB,CAAC;AAIzB,qBAAa,sBAAuB,SAAQ,mBAAmB;IAC7D,QAAQ,CAAC,SAAS,SAAS;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;gBAEZ,EACV,aAAa,EACb,SAAS,EACT,UAAU,EACV,kBAAkB,GACnB,EAAE;QACD,aAAa,EAAE,MAAM,CAAC;QACtB,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,kBAAkB,CAAC,EAAE,MAAM,CAAC;KAC7B;IASD;;;;;OAKG;IACG,mBAAmB,CAAC,EACxB,wBAAwB,EACxB,QAAoB,GACrB,EAAE;QACD,wBAAwB,EAAE,wBAAwB,CAAC;QACnD,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,GAAG,OAAO,CAAC;QACV,cAAc,EAAE,MAAM,CAAC;QACvB,YAAY,EAAE,UAAU,CAAC;QACzB,eAAe,EAAE,cAAc,EAAE,CAAC;KACnC,CAAC;IAyDI,oBAAoB,CAAC,YAAY,EAAE,UAAU;;;IAOnD;;;;;;OAMG;IACG,WAAW,CAAC,EAChB,OAAO,EACP,cA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