@dynamic-labs-wallet/svm 0.0.84 → 0.0.86

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 CHANGED
@@ -15,8 +15,6 @@ function _extends() {
15
15
  return _extends.apply(this, arguments);
16
16
  }
17
17
 
18
- const ERROR_CREATE_WALLET_ACCOUNT = 'Error creating svm wallet account';
19
-
20
18
  class DynamicSvmWalletClient extends browser.DynamicWalletClient {
21
19
  /**
22
20
  * Creates a wallet account on the Solana chain
@@ -43,7 +41,7 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
43
41
  throw new Error('Raw public key is not a Uint8Array or string' + typeof rawPublicKey);
44
42
  }
45
43
  if (!clientKeyShares) {
46
- throw new Error('Error creating wallet account');
44
+ throw new Error(browser.ERROR_KEYGEN_FAILED);
47
45
  }
48
46
  const { accountAddress } = await this.deriveAccountAddress(rawPublicKey);
49
47
  // Update client key shares in wallet map
@@ -64,8 +62,8 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
64
62
  rawPublicKey
65
63
  };
66
64
  } catch (error) {
67
- this.logger.error(ERROR_CREATE_WALLET_ACCOUNT, error);
68
- throw new Error(ERROR_CREATE_WALLET_ACCOUNT);
65
+ this.logger.error(browser.ERROR_CREATE_WALLET_ACCOUNT, error);
66
+ throw new Error(browser.ERROR_CREATE_WALLET_ACCOUNT);
69
67
  }
70
68
  }
71
69
  async deriveAccountAddress(rawPublicKey) {
@@ -89,7 +87,7 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
89
87
  signedSessionId
90
88
  });
91
89
  if (!accountAddress) {
92
- throw new Error('Account address is required');
90
+ throw new Error(browser.ERROR_ACCOUNT_ADDRESS_REQUIRED);
93
91
  }
94
92
  try {
95
93
  const signatureEd25519 = await this.sign({
@@ -102,8 +100,8 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
102
100
  const base58Signature = bs58.encode(signatureEd25519);
103
101
  return base58Signature;
104
102
  } catch (error) {
105
- this.logger.error('Error signing message:', error);
106
- throw error;
103
+ this.logger.error(browser.ERROR_SIGN_MESSAGE, error);
104
+ throw new Error(browser.ERROR_SIGN_MESSAGE);
107
105
  }
108
106
  }
109
107
  async signTransaction({ senderAddress, transaction, password = undefined, signedSessionId }) {
@@ -200,49 +198,57 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
200
198
  * @param password The password for encrypted backup shares
201
199
  * @returns The account address, raw public key, and client key shares
202
200
  */ async importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password = undefined, onError, signedSessionId }) {
203
- //get public key from private key
204
- const publicKey = this.getPublicKeyFromPrivateKey(privateKey);
205
- const formattedPrivateKey = this.decodePrivateKeyForSolana(privateKey);
206
- const { rawPublicKey, clientKeyShares } = await this.importRawPrivateKey({
207
- chainName,
208
- privateKey: formattedPrivateKey,
209
- thresholdSignatureScheme,
210
- onError,
211
- onCeremonyComplete: (accountAddress, walletId)=>{
212
- // update wallet map
213
- this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress] || {}, {
214
- accountAddress,
215
- walletId,
216
- chainName: this.chainName,
217
- thresholdSignatureScheme,
218
- clientKeySharesBackupInfo: browser.getClientKeyShareBackupInfo()
219
- });
201
+ try {
202
+ //get public key from private key
203
+ const publicKey = this.getPublicKeyFromPrivateKey(privateKey);
204
+ const formattedPrivateKey = this.decodePrivateKeyForSolana(privateKey);
205
+ const { rawPublicKey, clientKeyShares } = await this.importRawPrivateKey({
206
+ chainName,
207
+ privateKey: formattedPrivateKey,
208
+ thresholdSignatureScheme,
209
+ onError: (error)=>{
210
+ this.logger.error(browser.ERROR_IMPORT_PRIVATE_KEY, error);
211
+ onError == null ? void 0 : onError(error);
212
+ },
213
+ onCeremonyComplete: (accountAddress, walletId)=>{
214
+ // update wallet map
215
+ this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress] || {}, {
216
+ accountAddress,
217
+ walletId,
218
+ chainName: this.chainName,
219
+ thresholdSignatureScheme,
220
+ clientKeySharesBackupInfo: browser.getClientKeyShareBackupInfo()
221
+ });
222
+ }
223
+ });
224
+ if (!rawPublicKey || !clientKeyShares) {
225
+ throw new Error(browser.ERROR_IMPORT_PRIVATE_KEY);
220
226
  }
221
- });
222
- if (!rawPublicKey || !clientKeyShares) {
223
- throw new Error('Error creating wallet account');
224
- }
225
- const { accountAddress } = await this.deriveAccountAddress(rawPublicKey);
226
- if (accountAddress !== publicKey) {
227
- throw new Error(`Public key mismatch: derived address ${accountAddress} !== public key ${publicKey}`);
227
+ const { accountAddress } = await this.deriveAccountAddress(rawPublicKey);
228
+ if (accountAddress !== publicKey) {
229
+ throw new Error(`Public key mismatch: derived address ${accountAddress} !== public key ${publicKey}`);
230
+ }
231
+ // Update client key shares in wallet map
232
+ await this.setClientKeySharesToLocalStorage({
233
+ accountAddress,
234
+ clientKeyShares,
235
+ overwriteOrMerge: 'overwrite'
236
+ });
237
+ // Backup the new wallet without waiting for the promise to resolve
238
+ await this.storeEncryptedBackupByWalletWithRetry({
239
+ accountAddress,
240
+ clientKeyShares,
241
+ password,
242
+ signedSessionId
243
+ });
244
+ return {
245
+ accountAddress,
246
+ rawPublicKey: rawPublicKey
247
+ };
248
+ } catch (error) {
249
+ this.logger.error(browser.ERROR_IMPORT_PRIVATE_KEY, error);
250
+ throw new Error(browser.ERROR_IMPORT_PRIVATE_KEY);
228
251
  }
229
- // Update client key shares in wallet map
230
- await this.setClientKeySharesToLocalStorage({
231
- accountAddress,
232
- clientKeyShares,
233
- overwriteOrMerge: 'overwrite'
234
- });
235
- // Backup the new wallet without waiting for the promise to resolve
236
- await this.storeEncryptedBackupByWalletWithRetry({
237
- accountAddress,
238
- clientKeyShares,
239
- password,
240
- signedSessionId
241
- });
242
- return {
243
- accountAddress,
244
- rawPublicKey: rawPublicKey
245
- };
246
252
  }
247
253
  async getSvmWallets() {
248
254
  const wallets = await this.getWallets();
package/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { DynamicWalletClient, getClientKeyShareBackupInfo, WalletOperation } from '@dynamic-labs-wallet/browser';
1
+ import { DynamicWalletClient, getClientKeyShareBackupInfo, ERROR_KEYGEN_FAILED, ERROR_CREATE_WALLET_ACCOUNT, WalletOperation, ERROR_ACCOUNT_ADDRESS_REQUIRED, ERROR_SIGN_MESSAGE, ERROR_IMPORT_PRIVATE_KEY } from '@dynamic-labs-wallet/browser';
2
2
  import bs58 from 'bs58';
3
3
  import { Keypair } from '@solana/web3.js';
4
4
 
@@ -13,8 +13,6 @@ function _extends() {
13
13
  return _extends.apply(this, arguments);
14
14
  }
15
15
 
16
- const ERROR_CREATE_WALLET_ACCOUNT = 'Error creating svm wallet account';
17
-
18
16
  class DynamicSvmWalletClient extends DynamicWalletClient {
19
17
  /**
20
18
  * Creates a wallet account on the Solana chain
@@ -41,7 +39,7 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
41
39
  throw new Error('Raw public key is not a Uint8Array or string' + typeof rawPublicKey);
42
40
  }
43
41
  if (!clientKeyShares) {
44
- throw new Error('Error creating wallet account');
42
+ throw new Error(ERROR_KEYGEN_FAILED);
45
43
  }
46
44
  const { accountAddress } = await this.deriveAccountAddress(rawPublicKey);
47
45
  // Update client key shares in wallet map
@@ -87,7 +85,7 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
87
85
  signedSessionId
88
86
  });
89
87
  if (!accountAddress) {
90
- throw new Error('Account address is required');
88
+ throw new Error(ERROR_ACCOUNT_ADDRESS_REQUIRED);
91
89
  }
92
90
  try {
93
91
  const signatureEd25519 = await this.sign({
@@ -100,8 +98,8 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
100
98
  const base58Signature = bs58.encode(signatureEd25519);
101
99
  return base58Signature;
102
100
  } catch (error) {
103
- this.logger.error('Error signing message:', error);
104
- throw error;
101
+ this.logger.error(ERROR_SIGN_MESSAGE, error);
102
+ throw new Error(ERROR_SIGN_MESSAGE);
105
103
  }
106
104
  }
107
105
  async signTransaction({ senderAddress, transaction, password = undefined, signedSessionId }) {
@@ -198,49 +196,57 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
198
196
  * @param password The password for encrypted backup shares
199
197
  * @returns The account address, raw public key, and client key shares
200
198
  */ async importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password = undefined, onError, signedSessionId }) {
201
- //get public key from private key
202
- const publicKey = this.getPublicKeyFromPrivateKey(privateKey);
203
- const formattedPrivateKey = this.decodePrivateKeyForSolana(privateKey);
204
- const { rawPublicKey, clientKeyShares } = await this.importRawPrivateKey({
205
- chainName,
206
- privateKey: formattedPrivateKey,
207
- thresholdSignatureScheme,
208
- onError,
209
- onCeremonyComplete: (accountAddress, walletId)=>{
210
- // update wallet map
211
- this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress] || {}, {
212
- accountAddress,
213
- walletId,
214
- chainName: this.chainName,
215
- thresholdSignatureScheme,
216
- clientKeySharesBackupInfo: getClientKeyShareBackupInfo()
217
- });
199
+ try {
200
+ //get public key from private key
201
+ const publicKey = this.getPublicKeyFromPrivateKey(privateKey);
202
+ const formattedPrivateKey = this.decodePrivateKeyForSolana(privateKey);
203
+ const { rawPublicKey, clientKeyShares } = await this.importRawPrivateKey({
204
+ chainName,
205
+ privateKey: formattedPrivateKey,
206
+ thresholdSignatureScheme,
207
+ onError: (error)=>{
208
+ this.logger.error(ERROR_IMPORT_PRIVATE_KEY, error);
209
+ onError == null ? void 0 : onError(error);
210
+ },
211
+ onCeremonyComplete: (accountAddress, walletId)=>{
212
+ // update wallet map
213
+ this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress] || {}, {
214
+ accountAddress,
215
+ walletId,
216
+ chainName: this.chainName,
217
+ thresholdSignatureScheme,
218
+ clientKeySharesBackupInfo: getClientKeyShareBackupInfo()
219
+ });
220
+ }
221
+ });
222
+ if (!rawPublicKey || !clientKeyShares) {
223
+ throw new Error(ERROR_IMPORT_PRIVATE_KEY);
218
224
  }
219
- });
220
- if (!rawPublicKey || !clientKeyShares) {
221
- throw new Error('Error creating wallet account');
222
- }
223
- const { accountAddress } = await this.deriveAccountAddress(rawPublicKey);
224
- if (accountAddress !== publicKey) {
225
- throw new Error(`Public key mismatch: derived address ${accountAddress} !== public key ${publicKey}`);
225
+ const { accountAddress } = await this.deriveAccountAddress(rawPublicKey);
226
+ if (accountAddress !== publicKey) {
227
+ throw new Error(`Public key mismatch: derived address ${accountAddress} !== public key ${publicKey}`);
228
+ }
229
+ // Update client key shares in wallet map
230
+ await this.setClientKeySharesToLocalStorage({
231
+ accountAddress,
232
+ clientKeyShares,
233
+ overwriteOrMerge: 'overwrite'
234
+ });
235
+ // Backup the new wallet without waiting for the promise to resolve
236
+ await this.storeEncryptedBackupByWalletWithRetry({
237
+ accountAddress,
238
+ clientKeyShares,
239
+ password,
240
+ signedSessionId
241
+ });
242
+ return {
243
+ accountAddress,
244
+ rawPublicKey: rawPublicKey
245
+ };
246
+ } catch (error) {
247
+ this.logger.error(ERROR_IMPORT_PRIVATE_KEY, error);
248
+ throw new Error(ERROR_IMPORT_PRIVATE_KEY);
226
249
  }
227
- // Update client key shares in wallet map
228
- await this.setClientKeySharesToLocalStorage({
229
- accountAddress,
230
- clientKeyShares,
231
- overwriteOrMerge: 'overwrite'
232
- });
233
- // Backup the new wallet without waiting for the promise to resolve
234
- await this.storeEncryptedBackupByWalletWithRetry({
235
- accountAddress,
236
- clientKeyShares,
237
- password,
238
- signedSessionId
239
- });
240
- return {
241
- accountAddress,
242
- rawPublicKey: rawPublicKey
243
- };
244
250
  }
245
251
  async getSvmWallets() {
246
252
  const wallets = await this.getWallets();
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@dynamic-labs-wallet/svm",
3
- "version": "0.0.84",
3
+ "version": "0.0.86",
4
4
  "license": "MIT",
5
5
  "dependencies": {
6
- "@dynamic-labs-wallet/browser": "0.0.84",
6
+ "@dynamic-labs-wallet/browser": "0.0.86",
7
7
  "@solana/web3.js": "^1.98.2",
8
8
  "bs58": "^6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