@dynamic-labs-wallet/svm 0.0.44 → 0.0.46

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
@@ -5,17 +5,9 @@ var bs58 = require('bs58');
5
5
  var web3_js = require('@solana/web3.js');
6
6
  require('@dynamic-labs-wallet/core');
7
7
 
8
- const addSignatureToTransaction = ({ transaction, signature })=>{
8
+ const addSignatureToTransaction = ({ transaction, signature, signerPublicKey })=>{
9
9
  try {
10
- if (transaction instanceof web3_js.Transaction) {
11
- transaction.addSignature(transaction.feePayer, Buffer.from(signature));
12
- } else {
13
- // For versioned transactions, we should add the signature to the fee payer
14
- // which is always the first account in the static account keys
15
- // TODO: see if this works for sponsored transactions
16
- const feePayer = transaction.message.staticAccountKeys[0];
17
- transaction.addSignature(feePayer, Buffer.from(signature));
18
- }
10
+ transaction.addSignature(signerPublicKey, Buffer.from(signature));
19
11
  return transaction;
20
12
  } catch (error) {
21
13
  console.error('Error in finalizing transaction:', error);
@@ -30,11 +22,27 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
30
22
  * @param thresholdSignatureScheme The threshold signature scheme to use
31
23
  * @returns The account address, public key hex, raw public key, and client key shares
32
24
  */ async createWalletAccount({ thresholdSignatureScheme, password = undefined }) {
25
+ let ceremonyCompleted = false;
33
26
  try {
34
27
  const { rawPublicKey, clientKeyShares } = await this.keyGen({
35
28
  chainName: this.chainName,
36
- thresholdSignatureScheme
29
+ thresholdSignatureScheme,
30
+ onCeremonyComplete: ()=>{
31
+ ceremonyCompleted = true;
32
+ }
37
33
  });
34
+ // Wait for the ceremony to complete, timeout after 5 seconds
35
+ await Promise.race([
36
+ (async ()=>{
37
+ while(!ceremonyCompleted){
38
+ await new Promise((resolve)=>setTimeout(resolve, 100));
39
+ }
40
+ })(),
41
+ browser.timeoutPromise({
42
+ timeInMs: 5000,
43
+ activity: 'Ceremony'
44
+ })
45
+ ]);
38
46
  if (!rawPublicKey || !(rawPublicKey instanceof Uint8Array)) {
39
47
  throw new Error('Raw public key is not a Uint8Array');
40
48
  }
@@ -151,9 +159,11 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
151
159
  if (!signatureEd25519) {
152
160
  throw new Error('Signature is undefined');
153
161
  }
162
+ const senderPublicKey = new web3_js.PublicKey(senderAddress);
154
163
  const signedTransaction = addSignatureToTransaction({
155
164
  transaction,
156
- signature: signatureEd25519
165
+ signature: signatureEd25519,
166
+ signerPublicKey: senderPublicKey
157
167
  });
158
168
  return signedTransaction;
159
169
  } catch (error) {
@@ -227,6 +237,7 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
227
237
  * @param password The password for encrypted backup shares
228
238
  * @returns The account address, raw public key, and client key shares
229
239
  */ async importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password = undefined, onError }) {
240
+ let ceremonyCompleted = false;
230
241
  //get public key from private key
231
242
  const publicKey = this.getPublicKeyFromPrivateKey(privateKey);
232
243
  const formattedPrivateKey = await this.decodePrivateKeyForSolana(privateKey);
@@ -234,8 +245,23 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
234
245
  chainName,
235
246
  privateKey: formattedPrivateKey,
236
247
  thresholdSignatureScheme,
237
- onError
248
+ onError,
249
+ onCeremonyComplete: ()=>{
250
+ ceremonyCompleted = true;
251
+ }
238
252
  });
253
+ // Wait for the ceremony to complete, timeout after 5 seconds
254
+ await Promise.race([
255
+ (async ()=>{
256
+ while(!ceremonyCompleted){
257
+ await new Promise((resolve)=>setTimeout(resolve, 100));
258
+ }
259
+ })(),
260
+ browser.timeoutPromise({
261
+ timeInMs: 5000,
262
+ activity: 'Ceremony'
263
+ })
264
+ ]);
239
265
  if (!rawPublicKey || !clientKeyShares) {
240
266
  throw new Error('Error creating wallet account');
241
267
  }
package/index.esm.js CHANGED
@@ -1,19 +1,11 @@
1
- import { DynamicWalletClient, getClientKeyShareBackupInfo, WalletOperation } from '@dynamic-labs-wallet/browser';
1
+ import { DynamicWalletClient, timeoutPromise, getClientKeyShareBackupInfo, WalletOperation } from '@dynamic-labs-wallet/browser';
2
2
  import bs58 from 'bs58';
3
- import { Transaction, VersionedTransaction, Keypair } from '@solana/web3.js';
3
+ import { VersionedTransaction, PublicKey, Keypair } from '@solana/web3.js';
4
4
  import '@dynamic-labs-wallet/core';
5
5
 
6
- const addSignatureToTransaction = ({ transaction, signature })=>{
6
+ const addSignatureToTransaction = ({ transaction, signature, signerPublicKey })=>{
7
7
  try {
8
- if (transaction instanceof Transaction) {
9
- transaction.addSignature(transaction.feePayer, Buffer.from(signature));
10
- } else {
11
- // For versioned transactions, we should add the signature to the fee payer
12
- // which is always the first account in the static account keys
13
- // TODO: see if this works for sponsored transactions
14
- const feePayer = transaction.message.staticAccountKeys[0];
15
- transaction.addSignature(feePayer, Buffer.from(signature));
16
- }
8
+ transaction.addSignature(signerPublicKey, Buffer.from(signature));
17
9
  return transaction;
18
10
  } catch (error) {
19
11
  console.error('Error in finalizing transaction:', error);
@@ -28,11 +20,27 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
28
20
  * @param thresholdSignatureScheme The threshold signature scheme to use
29
21
  * @returns The account address, public key hex, raw public key, and client key shares
30
22
  */ async createWalletAccount({ thresholdSignatureScheme, password = undefined }) {
23
+ let ceremonyCompleted = false;
31
24
  try {
32
25
  const { rawPublicKey, clientKeyShares } = await this.keyGen({
33
26
  chainName: this.chainName,
34
- thresholdSignatureScheme
27
+ thresholdSignatureScheme,
28
+ onCeremonyComplete: ()=>{
29
+ ceremonyCompleted = true;
30
+ }
35
31
  });
32
+ // Wait for the ceremony to complete, timeout after 5 seconds
33
+ await Promise.race([
34
+ (async ()=>{
35
+ while(!ceremonyCompleted){
36
+ await new Promise((resolve)=>setTimeout(resolve, 100));
37
+ }
38
+ })(),
39
+ timeoutPromise({
40
+ timeInMs: 5000,
41
+ activity: 'Ceremony'
42
+ })
43
+ ]);
36
44
  if (!rawPublicKey || !(rawPublicKey instanceof Uint8Array)) {
37
45
  throw new Error('Raw public key is not a Uint8Array');
38
46
  }
@@ -149,9 +157,11 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
149
157
  if (!signatureEd25519) {
150
158
  throw new Error('Signature is undefined');
151
159
  }
160
+ const senderPublicKey = new PublicKey(senderAddress);
152
161
  const signedTransaction = addSignatureToTransaction({
153
162
  transaction,
154
- signature: signatureEd25519
163
+ signature: signatureEd25519,
164
+ signerPublicKey: senderPublicKey
155
165
  });
156
166
  return signedTransaction;
157
167
  } catch (error) {
@@ -225,6 +235,7 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
225
235
  * @param password The password for encrypted backup shares
226
236
  * @returns The account address, raw public key, and client key shares
227
237
  */ async importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password = undefined, onError }) {
238
+ let ceremonyCompleted = false;
228
239
  //get public key from private key
229
240
  const publicKey = this.getPublicKeyFromPrivateKey(privateKey);
230
241
  const formattedPrivateKey = await this.decodePrivateKeyForSolana(privateKey);
@@ -232,8 +243,23 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
232
243
  chainName,
233
244
  privateKey: formattedPrivateKey,
234
245
  thresholdSignatureScheme,
235
- onError
246
+ onError,
247
+ onCeremonyComplete: ()=>{
248
+ ceremonyCompleted = true;
249
+ }
236
250
  });
251
+ // Wait for the ceremony to complete, timeout after 5 seconds
252
+ await Promise.race([
253
+ (async ()=>{
254
+ while(!ceremonyCompleted){
255
+ await new Promise((resolve)=>setTimeout(resolve, 100));
256
+ }
257
+ })(),
258
+ timeoutPromise({
259
+ timeInMs: 5000,
260
+ activity: 'Ceremony'
261
+ })
262
+ ]);
237
263
  if (!rawPublicKey || !clientKeyShares) {
238
264
  throw new Error('Error creating wallet account');
239
265
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@dynamic-labs-wallet/svm",
3
- "version": "0.0.44",
3
+ "version": "0.0.46",
4
4
  "license": "MIT",
5
5
  "dependencies": {
6
- "@dynamic-labs-wallet/browser": "0.0.44",
7
- "@dynamic-labs-wallet/core": "0.0.44",
6
+ "@dynamic-labs-wallet/browser": "0.0.46",
7
+ "@dynamic-labs-wallet/core": "0.0.46",
8
8
  "@solana/web3.js": "^1.98.0",
9
9
  "bs58": "^6.0.0"
10
10
  },
@@ -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,EAAW,WAAW,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAG7E,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;IAoDI,oBAAoB,CAAC,YAAY,EAAE,UAAU;;;IAOnD;;;;;;OAMG;IACG,WAAW,CAAC,EAChB,OAAO,EACP,cAAc,EACd,QAAoB,GACrB,EAAE;QACD,OAAO,EAAE,MAAM,CAAC;QAChB,cAAc,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,EAAE,MAAM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,gBAAgB,CAAC,EACrB,cAAc,EACd,QAAoB,GACrB,EAAE;QACD,cAAc,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB;;;IAaD;;;;;OAKG;IACG,uBAAuB,CAAC,EAC5B,SAAS,EACT,cAAc,GACf,EAAE;QACD,SAAS,EAAE,mBAAmB,EAAE,CAAC;QACjC,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB;;;IASD;;;;;OAKG;IACH,yBAAyB,CAAC,UAAU,EAAE,MAAM;IAM5C,0BAA0B,CAAC,UAAU,EAAE,MAAM;IAQ7C,eAAe,CAAC,SAAS,EAAE,UAAU,GAAG,MAAM;IAI9C;;;;;;;;OAQG;IACG,gBAAgB,CAAC,EACrB,UAAU,EACV,SAAS,EACT,wBAAwB,EACxB,QAAoB,EACpB,OAAO,GACR,EAAE;QACD,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;QAClB,wBAAwB,EAAE,wBAAwB,CAAC;QACnD,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;KAClC,GAAG,OAAO,CAAC;QACV,cAAc,EAAE,MAAM,CAAC;QACvB,YAAY,EAAE,UAAU,GAAG,SAAS,CAAC;QACrC,eAAe,EAAE,cAAc,EAAE,CAAC;KACnC,CAAC;IAoEI,aAAa;CAOpB"}
@@ -1,4 +1,4 @@
1
- import { Transaction, VersionedTransaction } from '@solana/web3.js';
1
+ import { PublicKey, Transaction, VersionedTransaction } from '@solana/web3.js';
2
2
  export declare function getBalance({ address, rpcUrl, }: {
3
3
  address: string;
4
4
  rpcUrl?: string;
@@ -12,9 +12,10 @@ export declare function createSolanaTransaction({ senderSolanaAddress, amount, t
12
12
  transaction: Transaction;
13
13
  serializedTransaction: Buffer;
14
14
  }>;
15
- export declare const addSignatureToTransaction: ({ transaction, signature, }: {
15
+ export declare const addSignatureToTransaction: ({ transaction, signature, signerPublicKey, }: {
16
16
  transaction: Transaction | VersionedTransaction;
17
17
  signature: Uint8Array;
18
+ signerPublicKey: PublicKey;
18
19
  }) => VersionedTransaction | Transaction;
19
20
  export declare function sendTransaction({ signedTransaction, rpcUrl, }: {
20
21
  signedTransaction: Uint8Array;
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/svm/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,WAAW,EACX,oBAAoB,EACrB,MAAM,iBAAiB,CAAC;AAEzB,wBAAsB,UAAU,CAAC,EAC/B,OAAO,EACP,MAAuB,GACxB,EAAE;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,mBAWA;AAED,wBAAsB,uBAAuB,CAAC,EAC5C,mBAAmB,EACnB,MAAM,EACN,EAAE,EACF,MAAwC,GACzC,EAAE;IACD,mBAAmB,EAAE,MAAM,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;;;GA+BA;AAED,eAAO,MAAM,yBAAyB,gCAGnC;IACD,WAAW,EAAE,WAAW,GAAG,oBAAoB,CAAC;IAChD,SAAS,EAAE,UAAU,CAAC;CACvB,KAAG,oBAAoB,GAAG,WAmB1B,CAAC;AAEF,wBAAsB,eAAe,CAAC,EACpC,iBAAiB,EACjB,MAAwC,GACzC,EAAE;IACD,iBAAiB,EAAE,UAAU,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,mBAaA"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/svm/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,SAAS,EAET,WAAW,EACX,oBAAoB,EACrB,MAAM,iBAAiB,CAAC;AAEzB,wBAAsB,UAAU,CAAC,EAC/B,OAAO,EACP,MAAuB,GACxB,EAAE;IACD,O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