@dynamic-labs-wallet/svm 0.0.125 → 0.0.127

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
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var browser = require('@dynamic-labs-wallet/browser');
4
- var bs58 = require('bs58');
5
4
  var web3_js = require('@solana/web3.js');
5
+ var bs58 = require('bs58');
6
6
 
7
7
  function _extends() {
8
8
  _extends = Object.assign || function assign(target) {
@@ -80,7 +80,7 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
80
80
  }
81
81
  }
82
82
  async deriveAccountAddress(rawPublicKey) {
83
- const pubKeyBytes = typeof rawPublicKey === 'string' ? Buffer.from(rawPublicKey, 'hex') : rawPublicKey;
83
+ const pubKeyBytes = typeof rawPublicKey === 'string' ? new Uint8Array(Buffer.from(rawPublicKey, 'hex')) : rawPublicKey;
84
84
  const accountAddress = bs58.encode(pubKeyBytes);
85
85
  return {
86
86
  accountAddress
@@ -118,7 +118,7 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
118
118
  throw new Error(browser.ERROR_SIGN_MESSAGE);
119
119
  }
120
120
  }
121
- async signTransaction({ senderAddress, transaction, password = undefined, signedSessionId, mfaToken }) {
121
+ async signTransaction({ senderAddress, transaction, password = undefined, signedSessionId, mfaToken, chainId }) {
122
122
  await this.verifyPassword({
123
123
  accountAddress: senderAddress,
124
124
  password,
@@ -126,14 +126,17 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
126
126
  signedSessionId
127
127
  });
128
128
  try {
129
- const signatureEd25519 = await this.sign({
130
- message: transaction,
131
- accountAddress: senderAddress,
132
- chainName: this.chainName,
129
+ const base58SerializedTransaction = this.prepareTransactionForSigning(transaction);
130
+ const signParams = this.buildSignParams({
131
+ transaction,
132
+ senderAddress,
133
133
  password,
134
134
  signedSessionId,
135
- mfaToken
135
+ mfaToken,
136
+ chainId,
137
+ base58SerializedTransaction
136
138
  });
139
+ const signatureEd25519 = await this.sign(signParams);
137
140
  if (!signatureEd25519) {
138
141
  throw new Error('Signature is undefined');
139
142
  }
@@ -146,6 +149,35 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
146
149
  throw error;
147
150
  }
148
151
  }
152
+ prepareTransactionForSigning(transaction) {
153
+ const transactionBytes = new Uint8Array(Buffer.from(transaction, 'hex'));
154
+ const deserializedTransaction = web3_js.VersionedMessage.deserialize(transactionBytes);
155
+ const versionedTransaction = new web3_js.VersionedTransaction(deserializedTransaction);
156
+ const serializedTransaction = versionedTransaction.serialize();
157
+ return bs58.encode(serializedTransaction);
158
+ }
159
+ buildSignParams({ transaction, senderAddress, password, signedSessionId, mfaToken, chainId, base58SerializedTransaction }) {
160
+ const signParams = {
161
+ message: transaction,
162
+ accountAddress: senderAddress,
163
+ chainName: this.chainName,
164
+ password,
165
+ signedSessionId,
166
+ mfaToken
167
+ };
168
+ if (chainId !== undefined) {
169
+ signParams.context = {
170
+ svmTransaction: {
171
+ chainId,
172
+ method: 'signAndSendTransaction',
173
+ serializedTransactions: [
174
+ base58SerializedTransaction
175
+ ]
176
+ }
177
+ };
178
+ }
179
+ return signParams;
180
+ }
149
181
  /**
150
182
  * Exports the private key for a given account address
151
183
  *
package/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
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
+ import { VersionedMessage, VersionedTransaction, Keypair } from '@solana/web3.js';
2
3
  import bs58 from 'bs58';
3
- import { Keypair } from '@solana/web3.js';
4
4
 
5
5
  function _extends() {
6
6
  _extends = Object.assign || function assign(target) {
@@ -78,7 +78,7 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
78
78
  }
79
79
  }
80
80
  async deriveAccountAddress(rawPublicKey) {
81
- const pubKeyBytes = typeof rawPublicKey === 'string' ? Buffer.from(rawPublicKey, 'hex') : rawPublicKey;
81
+ const pubKeyBytes = typeof rawPublicKey === 'string' ? new Uint8Array(Buffer.from(rawPublicKey, 'hex')) : rawPublicKey;
82
82
  const accountAddress = bs58.encode(pubKeyBytes);
83
83
  return {
84
84
  accountAddress
@@ -116,7 +116,7 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
116
116
  throw new Error(ERROR_SIGN_MESSAGE);
117
117
  }
118
118
  }
119
- async signTransaction({ senderAddress, transaction, password = undefined, signedSessionId, mfaToken }) {
119
+ async signTransaction({ senderAddress, transaction, password = undefined, signedSessionId, mfaToken, chainId }) {
120
120
  await this.verifyPassword({
121
121
  accountAddress: senderAddress,
122
122
  password,
@@ -124,14 +124,17 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
124
124
  signedSessionId
125
125
  });
126
126
  try {
127
- const signatureEd25519 = await this.sign({
128
- message: transaction,
129
- accountAddress: senderAddress,
130
- chainName: this.chainName,
127
+ const base58SerializedTransaction = this.prepareTransactionForSigning(transaction);
128
+ const signParams = this.buildSignParams({
129
+ transaction,
130
+ senderAddress,
131
131
  password,
132
132
  signedSessionId,
133
- mfaToken
133
+ mfaToken,
134
+ chainId,
135
+ base58SerializedTransaction
134
136
  });
137
+ const signatureEd25519 = await this.sign(signParams);
135
138
  if (!signatureEd25519) {
136
139
  throw new Error('Signature is undefined');
137
140
  }
@@ -144,6 +147,35 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
144
147
  throw error;
145
148
  }
146
149
  }
150
+ prepareTransactionForSigning(transaction) {
151
+ const transactionBytes = new Uint8Array(Buffer.from(transaction, 'hex'));
152
+ const deserializedTransaction = VersionedMessage.deserialize(transactionBytes);
153
+ const versionedTransaction = new VersionedTransaction(deserializedTransaction);
154
+ const serializedTransaction = versionedTransaction.serialize();
155
+ return bs58.encode(serializedTransaction);
156
+ }
157
+ buildSignParams({ transaction, senderAddress, password, signedSessionId, mfaToken, chainId, base58SerializedTransaction }) {
158
+ const signParams = {
159
+ message: transaction,
160
+ accountAddress: senderAddress,
161
+ chainName: this.chainName,
162
+ password,
163
+ signedSessionId,
164
+ mfaToken
165
+ };
166
+ if (chainId !== undefined) {
167
+ signParams.context = {
168
+ svmTransaction: {
169
+ chainId,
170
+ method: 'signAndSendTransaction',
171
+ serializedTransactions: [
172
+ base58SerializedTransaction
173
+ ]
174
+ }
175
+ };
176
+ }
177
+ return signParams;
178
+ }
147
179
  /**
148
180
  * Exports the private key for a given account address
149
181
  *
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@dynamic-labs-wallet/svm",
3
- "version": "0.0.125",
3
+ "version": "0.0.127",
4
4
  "license": "MIT",
5
5
  "type": "commonjs",
6
6
  "dependencies": {
7
- "@dynamic-labs-wallet/browser": "0.0.125",
7
+ "@dynamic-labs-wallet/browser": "0.0.127",
8
+ "@dynamic-labs/sdk-api-core": "^0.0.745",
8
9
  "@solana/web3.js": "^1.98.2",
9
10
  "bs58": "^6.0.0"
10
11
  },
@@ -34,13 +34,16 @@ export declare class DynamicSvmWalletClient extends DynamicWalletClient {
34
34
  signedSessionId: string;
35
35
  mfaToken?: string;
36
36
  }): Promise<string>;
37
- signTransaction({ senderAddress, transaction, password, signedSessionId, mfaToken, }: {
37
+ signTransaction({ senderAddress, transaction, password, signedSessionId, mfaToken, chainId, }: {
38
38
  senderAddress: string;
39
39
  transaction: string;
40
40
  password?: string;
41
41
  signedSessionId: string;
42
42
  mfaToken?: string;
43
+ chainId?: string;
43
44
  }): Promise<string>;
45
+ private prepareTransactionForSigning;
46
+ private buildSignParams;
44
47
  /**
45
48
  * Exports the private key for a given account address
46
49
  *
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/svm/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,mBA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