@dynamic-labs-wallet/node-svm 1.0.101 → 1.0.102
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 +79 -69
- package/index.esm.js +81 -71
- package/package.json +2 -2
- package/src/client/client.d.ts +15 -8
- package/src/client/client.d.ts.map +1 -1
package/index.cjs
CHANGED
|
@@ -84,6 +84,54 @@ function decodeBase58(str) {
|
|
|
84
84
|
return out;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
async function getBalance({ address, rpcUrl = node.SOLANA_RPC_URL }) {
|
|
88
|
+
const connection = new web3_js.Connection(rpcUrl != null ? rpcUrl : 'https://api.devnet.solana.com');
|
|
89
|
+
const balance = await connection.getBalance(new web3_js.PublicKey(address));
|
|
90
|
+
return balance;
|
|
91
|
+
}
|
|
92
|
+
async function createSolanaTransaction({ senderSolanaAddress, amount, to, rpcUrl = 'https://api.devnet.solana.com' }) {
|
|
93
|
+
const connection = new web3_js.Connection(rpcUrl != null ? rpcUrl : 'https://api.devnet.solana.com');
|
|
94
|
+
const balance = await getBalance({
|
|
95
|
+
address: senderSolanaAddress,
|
|
96
|
+
rpcUrl
|
|
97
|
+
});
|
|
98
|
+
if (balance < amount * 1e9) {
|
|
99
|
+
throw new Error('Insufficient balance');
|
|
100
|
+
}
|
|
101
|
+
const fromPubkey = new web3_js.PublicKey(senderSolanaAddress);
|
|
102
|
+
const transaction = new web3_js.Transaction().add(web3_js.SystemProgram.transfer({
|
|
103
|
+
fromPubkey: fromPubkey,
|
|
104
|
+
toPubkey: new web3_js.PublicKey(to),
|
|
105
|
+
lamports: amount * 1e9
|
|
106
|
+
}));
|
|
107
|
+
const { blockhash } = await connection.getLatestBlockhash();
|
|
108
|
+
transaction.recentBlockhash = blockhash;
|
|
109
|
+
transaction.feePayer = fromPubkey;
|
|
110
|
+
const serializedTransaction = transaction.serializeMessage();
|
|
111
|
+
return {
|
|
112
|
+
transaction,
|
|
113
|
+
serializedTransaction
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
const addSignatureToTransaction = ({ transaction, signature, signerPublicKey })=>{
|
|
117
|
+
transaction.addSignature(signerPublicKey, Buffer.from(signature));
|
|
118
|
+
return transaction;
|
|
119
|
+
};
|
|
120
|
+
function attachSignature({ transaction, signatureBase58, senderAddress }) {
|
|
121
|
+
const sigBytes = decodeBase58(signatureBase58);
|
|
122
|
+
const signerPubkey = new web3_js.PublicKey(senderAddress);
|
|
123
|
+
return addSignatureToTransaction({
|
|
124
|
+
transaction,
|
|
125
|
+
signature: sigBytes,
|
|
126
|
+
signerPublicKey: signerPubkey
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
async function sendTransaction({ signedTransaction, rpcUrl = 'https://api.devnet.solana.com' }) {
|
|
130
|
+
const connection = new web3_js.Connection(rpcUrl != null ? rpcUrl : 'https://api.devnet.solana.com');
|
|
131
|
+
const txid = await connection.sendRawTransaction(Buffer.from(signedTransaction));
|
|
132
|
+
return txid;
|
|
133
|
+
}
|
|
134
|
+
|
|
87
135
|
const logError$1 = node.createLogError('node-svm');
|
|
88
136
|
// Helper: normalize bytes to hex without triggering Buffer.from(string, encoding) overload
|
|
89
137
|
const toHex = (bytes)=>(Buffer.isBuffer(bytes) ? bytes : Buffer.from(bytes)).toString('hex');
|
|
@@ -247,40 +295,40 @@ class DynamicSvmWalletClient extends node.DynamicWalletClient {
|
|
|
247
295
|
});
|
|
248
296
|
}
|
|
249
297
|
}
|
|
250
|
-
//todo:should txn just be a string?
|
|
251
298
|
async signTransaction({ walletMetadata, transaction, password = undefined, externalServerKeyShares, sponsor = false, chainId, context }) {
|
|
252
299
|
const { accountAddress } = walletMetadata;
|
|
253
300
|
if (!accountAddress) {
|
|
254
301
|
throw new Error('Account address is required');
|
|
255
302
|
}
|
|
303
|
+
let resolvedTransaction = transaction;
|
|
256
304
|
if (sponsor) {
|
|
257
|
-
if (typeof
|
|
305
|
+
if (typeof resolvedTransaction === 'string') {
|
|
258
306
|
throw new TypeError('sponsor=true requires a Transaction or VersionedTransaction object, not a hex string');
|
|
259
307
|
}
|
|
260
|
-
|
|
261
|
-
transaction
|
|
308
|
+
resolvedTransaction = await this.sponsorTransaction({
|
|
309
|
+
transaction: resolvedTransaction
|
|
262
310
|
});
|
|
263
311
|
}
|
|
264
312
|
try {
|
|
265
313
|
let messageToSign;
|
|
266
|
-
if (typeof
|
|
267
|
-
messageToSign =
|
|
268
|
-
} else if (
|
|
269
|
-
const messageBytes =
|
|
314
|
+
if (typeof resolvedTransaction === 'string') {
|
|
315
|
+
messageToSign = resolvedTransaction.startsWith('0x') ? resolvedTransaction.slice(2) : resolvedTransaction;
|
|
316
|
+
} else if (resolvedTransaction instanceof web3_js.VersionedTransaction) {
|
|
317
|
+
const messageBytes = resolvedTransaction.message.serialize();
|
|
270
318
|
messageToSign = toHex(messageBytes);
|
|
271
319
|
} else {
|
|
272
|
-
const messageBytes =
|
|
320
|
+
const messageBytes = resolvedTransaction.serializeMessage();
|
|
273
321
|
messageToSign = toHex(Buffer.isBuffer(messageBytes) ? messageBytes : messageBytes);
|
|
274
322
|
}
|
|
275
323
|
// Mirrors the browser SVM client: svmTransaction context requires a chainId,
|
|
276
324
|
// so it's only attached when the caller provides one. Not derivable when
|
|
277
325
|
// `transaction` is a raw hex string (no Transaction object to serialize).
|
|
278
|
-
const resolvedContext = chainId !== undefined && typeof
|
|
326
|
+
const resolvedContext = chainId !== undefined && typeof resolvedTransaction !== 'string' ? _extends({}, context, {
|
|
279
327
|
svmTransaction: {
|
|
280
328
|
chainId,
|
|
281
329
|
method: 'signAndSendTransaction',
|
|
282
330
|
serializedTransactions: [
|
|
283
|
-
encodeBase58(
|
|
331
|
+
encodeBase58(resolvedTransaction instanceof web3_js.VersionedTransaction ? resolvedTransaction.serialize() : resolvedTransaction.serialize({
|
|
284
332
|
requireAllSignatures: false,
|
|
285
333
|
verifySignatures: false
|
|
286
334
|
}))
|
|
@@ -300,7 +348,19 @@ class DynamicSvmWalletClient extends node.DynamicWalletClient {
|
|
|
300
348
|
if (!signatureEd25519) {
|
|
301
349
|
throw new Error('Signature is undefined');
|
|
302
350
|
}
|
|
303
|
-
|
|
351
|
+
const signature = encodeBase58(signatureEd25519);
|
|
352
|
+
if (sponsor) {
|
|
353
|
+
const signedTransaction = addSignatureToTransaction({
|
|
354
|
+
transaction: resolvedTransaction,
|
|
355
|
+
signature: signatureEd25519,
|
|
356
|
+
signerPublicKey: new web3_js.PublicKey(accountAddress)
|
|
357
|
+
});
|
|
358
|
+
return {
|
|
359
|
+
signature,
|
|
360
|
+
transaction: signedTransaction
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
return signature;
|
|
304
364
|
} catch (error) {
|
|
305
365
|
logError$1({
|
|
306
366
|
message: 'Error in signTransaction:',
|
|
@@ -451,15 +511,16 @@ class DynamicSvmWalletClient extends node.DynamicWalletClient {
|
|
|
451
511
|
* Sponsors a Solana transaction via the Dynamic gas sponsorship API.
|
|
452
512
|
*
|
|
453
513
|
* Sends the unsigned transaction to Dynamic's sponsorTransaction endpoint,
|
|
454
|
-
* which replaces the fee payer with the sponsor's address. The
|
|
455
|
-
*
|
|
456
|
-
* {@link signTransaction} instead of the
|
|
514
|
+
* which replaces the fee payer with the sponsor's address. The endpoint
|
|
515
|
+
* always returns a v0 versioned transaction, which is deserialized and
|
|
516
|
+
* returned. It should be passed to {@link signTransaction} instead of the
|
|
517
|
+
* original transaction.
|
|
457
518
|
*
|
|
458
519
|
* Gas sponsorship must be enabled for your environment in the Dynamic
|
|
459
520
|
* dashboard before calling this method.
|
|
460
521
|
*
|
|
461
522
|
* @param transaction - Unsigned Solana transaction (legacy or versioned).
|
|
462
|
-
* @returns The sponsored transaction with the gas sponsor as fee payer.
|
|
523
|
+
* @returns The sponsored v0 transaction with the gas sponsor as fee payer.
|
|
463
524
|
*/ async sponsorTransaction({ transaction, traceContext }) {
|
|
464
525
|
// Serialize the unsigned transaction to base64 wire format
|
|
465
526
|
const serialized = transaction instanceof web3_js.VersionedTransaction ? transaction.serialize() : transaction.serialize({
|
|
@@ -472,11 +533,8 @@ class DynamicSvmWalletClient extends node.DynamicWalletClient {
|
|
|
472
533
|
traceContext
|
|
473
534
|
});
|
|
474
535
|
const sponsoredBytes = Buffer.from(sponsoredBase64, 'base64');
|
|
475
|
-
//
|
|
476
|
-
|
|
477
|
-
return web3_js.VersionedTransaction.deserialize(sponsoredBytes);
|
|
478
|
-
}
|
|
479
|
-
return web3_js.Transaction.from(sponsoredBytes);
|
|
536
|
+
// The sponsor endpoint always returns a v0 versioned transaction.
|
|
537
|
+
return web3_js.VersionedTransaction.deserialize(sponsoredBytes);
|
|
480
538
|
}
|
|
481
539
|
/** @deprecated Use getWalletByAddress instead for better performance */ async getSvmWallets() {
|
|
482
540
|
// Calling the deprecated getWallets() is the point of this shim, and it is
|
|
@@ -497,54 +555,6 @@ class DynamicSvmWalletClient extends node.DynamicWalletClient {
|
|
|
497
555
|
}
|
|
498
556
|
}
|
|
499
557
|
|
|
500
|
-
async function getBalance({ address, rpcUrl = node.SOLANA_RPC_URL }) {
|
|
501
|
-
const connection = new web3_js.Connection(rpcUrl != null ? rpcUrl : 'https://api.devnet.solana.com');
|
|
502
|
-
const balance = await connection.getBalance(new web3_js.PublicKey(address));
|
|
503
|
-
return balance;
|
|
504
|
-
}
|
|
505
|
-
async function createSolanaTransaction({ senderSolanaAddress, amount, to, rpcUrl = 'https://api.devnet.solana.com' }) {
|
|
506
|
-
const connection = new web3_js.Connection(rpcUrl != null ? rpcUrl : 'https://api.devnet.solana.com');
|
|
507
|
-
const balance = await getBalance({
|
|
508
|
-
address: senderSolanaAddress,
|
|
509
|
-
rpcUrl
|
|
510
|
-
});
|
|
511
|
-
if (balance < amount * 1e9) {
|
|
512
|
-
throw new Error('Insufficient balance');
|
|
513
|
-
}
|
|
514
|
-
const fromPubkey = new web3_js.PublicKey(senderSolanaAddress);
|
|
515
|
-
const transaction = new web3_js.Transaction().add(web3_js.SystemProgram.transfer({
|
|
516
|
-
fromPubkey: fromPubkey,
|
|
517
|
-
toPubkey: new web3_js.PublicKey(to),
|
|
518
|
-
lamports: amount * 1e9
|
|
519
|
-
}));
|
|
520
|
-
const { blockhash } = await connection.getLatestBlockhash();
|
|
521
|
-
transaction.recentBlockhash = blockhash;
|
|
522
|
-
transaction.feePayer = fromPubkey;
|
|
523
|
-
const serializedTransaction = transaction.serializeMessage();
|
|
524
|
-
return {
|
|
525
|
-
transaction,
|
|
526
|
-
serializedTransaction
|
|
527
|
-
};
|
|
528
|
-
}
|
|
529
|
-
const addSignatureToTransaction = ({ transaction, signature, signerPublicKey })=>{
|
|
530
|
-
transaction.addSignature(signerPublicKey, Buffer.from(signature));
|
|
531
|
-
return transaction;
|
|
532
|
-
};
|
|
533
|
-
function attachSignature({ transaction, signatureBase58, senderAddress }) {
|
|
534
|
-
const sigBytes = decodeBase58(signatureBase58);
|
|
535
|
-
const signerPubkey = new web3_js.PublicKey(senderAddress);
|
|
536
|
-
return addSignatureToTransaction({
|
|
537
|
-
transaction,
|
|
538
|
-
signature: sigBytes,
|
|
539
|
-
signerPublicKey: signerPubkey
|
|
540
|
-
});
|
|
541
|
-
}
|
|
542
|
-
async function sendTransaction({ signedTransaction, rpcUrl = 'https://api.devnet.solana.com' }) {
|
|
543
|
-
const connection = new web3_js.Connection(rpcUrl != null ? rpcUrl : 'https://api.devnet.solana.com');
|
|
544
|
-
const txid = await connection.sendRawTransaction(Buffer.from(signedTransaction));
|
|
545
|
-
return txid;
|
|
546
|
-
}
|
|
547
|
-
|
|
548
558
|
const logError = node.createLogError('node-svm');
|
|
549
559
|
/**
|
|
550
560
|
* Creates a delegated SVM wallet client for functional operations
|
package/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createLogError, DynamicWalletClient, getMPCChainConfig, stripHexPrefix, WalletOperation,
|
|
2
|
-
import { PublicKey,
|
|
1
|
+
import { SOLANA_RPC_URL, createLogError, DynamicWalletClient, getMPCChainConfig, stripHexPrefix, WalletOperation, createDelegatedWalletClient, delegatedSignMessage as delegatedSignMessage$1, revokeDelegation as revokeDelegation$1 } from '@dynamic-labs-wallet/node';
|
|
2
|
+
import { PublicKey, Connection, Transaction, SystemProgram, VersionedTransaction, Keypair } from '@solana/web3.js';
|
|
3
3
|
|
|
4
4
|
function _extends() {
|
|
5
5
|
_extends = Object.assign || function assign(target) {
|
|
@@ -82,6 +82,54 @@ function decodeBase58(str) {
|
|
|
82
82
|
return out;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
async function getBalance({ address, rpcUrl = SOLANA_RPC_URL }) {
|
|
86
|
+
const connection = new Connection(rpcUrl != null ? rpcUrl : 'https://api.devnet.solana.com');
|
|
87
|
+
const balance = await connection.getBalance(new PublicKey(address));
|
|
88
|
+
return balance;
|
|
89
|
+
}
|
|
90
|
+
async function createSolanaTransaction({ senderSolanaAddress, amount, to, rpcUrl = 'https://api.devnet.solana.com' }) {
|
|
91
|
+
const connection = new Connection(rpcUrl != null ? rpcUrl : 'https://api.devnet.solana.com');
|
|
92
|
+
const balance = await getBalance({
|
|
93
|
+
address: senderSolanaAddress,
|
|
94
|
+
rpcUrl
|
|
95
|
+
});
|
|
96
|
+
if (balance < amount * 1e9) {
|
|
97
|
+
throw new Error('Insufficient balance');
|
|
98
|
+
}
|
|
99
|
+
const fromPubkey = new PublicKey(senderSolanaAddress);
|
|
100
|
+
const transaction = new Transaction().add(SystemProgram.transfer({
|
|
101
|
+
fromPubkey: fromPubkey,
|
|
102
|
+
toPubkey: new PublicKey(to),
|
|
103
|
+
lamports: amount * 1e9
|
|
104
|
+
}));
|
|
105
|
+
const { blockhash } = await connection.getLatestBlockhash();
|
|
106
|
+
transaction.recentBlockhash = blockhash;
|
|
107
|
+
transaction.feePayer = fromPubkey;
|
|
108
|
+
const serializedTransaction = transaction.serializeMessage();
|
|
109
|
+
return {
|
|
110
|
+
transaction,
|
|
111
|
+
serializedTransaction
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
const addSignatureToTransaction = ({ transaction, signature, signerPublicKey })=>{
|
|
115
|
+
transaction.addSignature(signerPublicKey, Buffer.from(signature));
|
|
116
|
+
return transaction;
|
|
117
|
+
};
|
|
118
|
+
function attachSignature({ transaction, signatureBase58, senderAddress }) {
|
|
119
|
+
const sigBytes = decodeBase58(signatureBase58);
|
|
120
|
+
const signerPubkey = new PublicKey(senderAddress);
|
|
121
|
+
return addSignatureToTransaction({
|
|
122
|
+
transaction,
|
|
123
|
+
signature: sigBytes,
|
|
124
|
+
signerPublicKey: signerPubkey
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
async function sendTransaction({ signedTransaction, rpcUrl = 'https://api.devnet.solana.com' }) {
|
|
128
|
+
const connection = new Connection(rpcUrl != null ? rpcUrl : 'https://api.devnet.solana.com');
|
|
129
|
+
const txid = await connection.sendRawTransaction(Buffer.from(signedTransaction));
|
|
130
|
+
return txid;
|
|
131
|
+
}
|
|
132
|
+
|
|
85
133
|
const logError$1 = createLogError('node-svm');
|
|
86
134
|
// Helper: normalize bytes to hex without triggering Buffer.from(string, encoding) overload
|
|
87
135
|
const toHex = (bytes)=>(Buffer.isBuffer(bytes) ? bytes : Buffer.from(bytes)).toString('hex');
|
|
@@ -245,40 +293,40 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
245
293
|
});
|
|
246
294
|
}
|
|
247
295
|
}
|
|
248
|
-
//todo:should txn just be a string?
|
|
249
296
|
async signTransaction({ walletMetadata, transaction, password = undefined, externalServerKeyShares, sponsor = false, chainId, context }) {
|
|
250
297
|
const { accountAddress } = walletMetadata;
|
|
251
298
|
if (!accountAddress) {
|
|
252
299
|
throw new Error('Account address is required');
|
|
253
300
|
}
|
|
301
|
+
let resolvedTransaction = transaction;
|
|
254
302
|
if (sponsor) {
|
|
255
|
-
if (typeof
|
|
303
|
+
if (typeof resolvedTransaction === 'string') {
|
|
256
304
|
throw new TypeError('sponsor=true requires a Transaction or VersionedTransaction object, not a hex string');
|
|
257
305
|
}
|
|
258
|
-
|
|
259
|
-
transaction
|
|
306
|
+
resolvedTransaction = await this.sponsorTransaction({
|
|
307
|
+
transaction: resolvedTransaction
|
|
260
308
|
});
|
|
261
309
|
}
|
|
262
310
|
try {
|
|
263
311
|
let messageToSign;
|
|
264
|
-
if (typeof
|
|
265
|
-
messageToSign =
|
|
266
|
-
} else if (
|
|
267
|
-
const messageBytes =
|
|
312
|
+
if (typeof resolvedTransaction === 'string') {
|
|
313
|
+
messageToSign = resolvedTransaction.startsWith('0x') ? resolvedTransaction.slice(2) : resolvedTransaction;
|
|
314
|
+
} else if (resolvedTransaction instanceof VersionedTransaction) {
|
|
315
|
+
const messageBytes = resolvedTransaction.message.serialize();
|
|
268
316
|
messageToSign = toHex(messageBytes);
|
|
269
317
|
} else {
|
|
270
|
-
const messageBytes =
|
|
318
|
+
const messageBytes = resolvedTransaction.serializeMessage();
|
|
271
319
|
messageToSign = toHex(Buffer.isBuffer(messageBytes) ? messageBytes : messageBytes);
|
|
272
320
|
}
|
|
273
321
|
// Mirrors the browser SVM client: svmTransaction context requires a chainId,
|
|
274
322
|
// so it's only attached when the caller provides one. Not derivable when
|
|
275
323
|
// `transaction` is a raw hex string (no Transaction object to serialize).
|
|
276
|
-
const resolvedContext = chainId !== undefined && typeof
|
|
324
|
+
const resolvedContext = chainId !== undefined && typeof resolvedTransaction !== 'string' ? _extends({}, context, {
|
|
277
325
|
svmTransaction: {
|
|
278
326
|
chainId,
|
|
279
327
|
method: 'signAndSendTransaction',
|
|
280
328
|
serializedTransactions: [
|
|
281
|
-
encodeBase58(
|
|
329
|
+
encodeBase58(resolvedTransaction instanceof VersionedTransaction ? resolvedTransaction.serialize() : resolvedTransaction.serialize({
|
|
282
330
|
requireAllSignatures: false,
|
|
283
331
|
verifySignatures: false
|
|
284
332
|
}))
|
|
@@ -298,7 +346,19 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
298
346
|
if (!signatureEd25519) {
|
|
299
347
|
throw new Error('Signature is undefined');
|
|
300
348
|
}
|
|
301
|
-
|
|
349
|
+
const signature = encodeBase58(signatureEd25519);
|
|
350
|
+
if (sponsor) {
|
|
351
|
+
const signedTransaction = addSignatureToTransaction({
|
|
352
|
+
transaction: resolvedTransaction,
|
|
353
|
+
signature: signatureEd25519,
|
|
354
|
+
signerPublicKey: new PublicKey(accountAddress)
|
|
355
|
+
});
|
|
356
|
+
return {
|
|
357
|
+
signature,
|
|
358
|
+
transaction: signedTransaction
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
return signature;
|
|
302
362
|
} catch (error) {
|
|
303
363
|
logError$1({
|
|
304
364
|
message: 'Error in signTransaction:',
|
|
@@ -449,15 +509,16 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
449
509
|
* Sponsors a Solana transaction via the Dynamic gas sponsorship API.
|
|
450
510
|
*
|
|
451
511
|
* Sends the unsigned transaction to Dynamic's sponsorTransaction endpoint,
|
|
452
|
-
* which replaces the fee payer with the sponsor's address. The
|
|
453
|
-
*
|
|
454
|
-
* {@link signTransaction} instead of the
|
|
512
|
+
* which replaces the fee payer with the sponsor's address. The endpoint
|
|
513
|
+
* always returns a v0 versioned transaction, which is deserialized and
|
|
514
|
+
* returned. It should be passed to {@link signTransaction} instead of the
|
|
515
|
+
* original transaction.
|
|
455
516
|
*
|
|
456
517
|
* Gas sponsorship must be enabled for your environment in the Dynamic
|
|
457
518
|
* dashboard before calling this method.
|
|
458
519
|
*
|
|
459
520
|
* @param transaction - Unsigned Solana transaction (legacy or versioned).
|
|
460
|
-
* @returns The sponsored transaction with the gas sponsor as fee payer.
|
|
521
|
+
* @returns The sponsored v0 transaction with the gas sponsor as fee payer.
|
|
461
522
|
*/ async sponsorTransaction({ transaction, traceContext }) {
|
|
462
523
|
// Serialize the unsigned transaction to base64 wire format
|
|
463
524
|
const serialized = transaction instanceof VersionedTransaction ? transaction.serialize() : transaction.serialize({
|
|
@@ -470,11 +531,8 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
470
531
|
traceContext
|
|
471
532
|
});
|
|
472
533
|
const sponsoredBytes = Buffer.from(sponsoredBase64, 'base64');
|
|
473
|
-
//
|
|
474
|
-
|
|
475
|
-
return VersionedTransaction.deserialize(sponsoredBytes);
|
|
476
|
-
}
|
|
477
|
-
return Transaction.from(sponsoredBytes);
|
|
534
|
+
// The sponsor endpoint always returns a v0 versioned transaction.
|
|
535
|
+
return VersionedTransaction.deserialize(sponsoredBytes);
|
|
478
536
|
}
|
|
479
537
|
/** @deprecated Use getWalletByAddress instead for better performance */ async getSvmWallets() {
|
|
480
538
|
// Calling the deprecated getWallets() is the point of this shim, and it is
|
|
@@ -495,54 +553,6 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
495
553
|
}
|
|
496
554
|
}
|
|
497
555
|
|
|
498
|
-
async function getBalance({ address, rpcUrl = SOLANA_RPC_URL }) {
|
|
499
|
-
const connection = new Connection(rpcUrl != null ? rpcUrl : 'https://api.devnet.solana.com');
|
|
500
|
-
const balance = await connection.getBalance(new PublicKey(address));
|
|
501
|
-
return balance;
|
|
502
|
-
}
|
|
503
|
-
async function createSolanaTransaction({ senderSolanaAddress, amount, to, rpcUrl = 'https://api.devnet.solana.com' }) {
|
|
504
|
-
const connection = new Connection(rpcUrl != null ? rpcUrl : 'https://api.devnet.solana.com');
|
|
505
|
-
const balance = await getBalance({
|
|
506
|
-
address: senderSolanaAddress,
|
|
507
|
-
rpcUrl
|
|
508
|
-
});
|
|
509
|
-
if (balance < amount * 1e9) {
|
|
510
|
-
throw new Error('Insufficient balance');
|
|
511
|
-
}
|
|
512
|
-
const fromPubkey = new PublicKey(senderSolanaAddress);
|
|
513
|
-
const transaction = new Transaction().add(SystemProgram.transfer({
|
|
514
|
-
fromPubkey: fromPubkey,
|
|
515
|
-
toPubkey: new PublicKey(to),
|
|
516
|
-
lamports: amount * 1e9
|
|
517
|
-
}));
|
|
518
|
-
const { blockhash } = await connection.getLatestBlockhash();
|
|
519
|
-
transaction.recentBlockhash = blockhash;
|
|
520
|
-
transaction.feePayer = fromPubkey;
|
|
521
|
-
const serializedTransaction = transaction.serializeMessage();
|
|
522
|
-
return {
|
|
523
|
-
transaction,
|
|
524
|
-
serializedTransaction
|
|
525
|
-
};
|
|
526
|
-
}
|
|
527
|
-
const addSignatureToTransaction = ({ transaction, signature, signerPublicKey })=>{
|
|
528
|
-
transaction.addSignature(signerPublicKey, Buffer.from(signature));
|
|
529
|
-
return transaction;
|
|
530
|
-
};
|
|
531
|
-
function attachSignature({ transaction, signatureBase58, senderAddress }) {
|
|
532
|
-
const sigBytes = decodeBase58(signatureBase58);
|
|
533
|
-
const signerPubkey = new PublicKey(senderAddress);
|
|
534
|
-
return addSignatureToTransaction({
|
|
535
|
-
transaction,
|
|
536
|
-
signature: sigBytes,
|
|
537
|
-
signerPublicKey: signerPubkey
|
|
538
|
-
});
|
|
539
|
-
}
|
|
540
|
-
async function sendTransaction({ signedTransaction, rpcUrl = 'https://api.devnet.solana.com' }) {
|
|
541
|
-
const connection = new Connection(rpcUrl != null ? rpcUrl : 'https://api.devnet.solana.com');
|
|
542
|
-
const txid = await connection.sendRawTransaction(Buffer.from(signedTransaction));
|
|
543
|
-
return txid;
|
|
544
|
-
}
|
|
545
|
-
|
|
546
556
|
const logError = createLogError('node-svm');
|
|
547
557
|
/**
|
|
548
558
|
* Creates a delegated SVM wallet client for functional operations
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs-wallet/node-svm",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.102",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@dynamic-labs-wallet/node": "1.0.
|
|
7
|
+
"@dynamic-labs-wallet/node": "1.0.102",
|
|
8
8
|
"@solana/web3.js": "^1.98.2"
|
|
9
9
|
},
|
|
10
10
|
"publishConfig": {
|
package/src/client/client.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { type ServerKeyShare, DynamicWalletClient, type Ed25519KeygenResult, type ThresholdSignatureScheme, type TraceContext, type DynamicWalletClientProps, type WalletMetadata } from '@dynamic-labs-wallet/node';
|
|
2
2
|
import type { SignMessageContext } from '@dynamic-labs/sdk-api-core';
|
|
3
|
-
import { Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
3
|
+
import { type Transaction, VersionedTransaction } from '@solana/web3.js';
|
|
4
|
+
type SvmSignableTransaction = VersionedTransaction | Transaction | string;
|
|
5
|
+
type SignTransactionResult = string | {
|
|
6
|
+
signature: string;
|
|
7
|
+
transaction: Transaction | VersionedTransaction;
|
|
8
|
+
};
|
|
4
9
|
export declare class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
5
10
|
readonly chainName = "SVM";
|
|
6
11
|
accountAddress?: string;
|
|
@@ -59,14 +64,14 @@ export declare class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
59
64
|
}): Promise<string>;
|
|
60
65
|
signTransaction({ walletMetadata, transaction, password, externalServerKeyShares, sponsor, chainId, context, }: {
|
|
61
66
|
walletMetadata: WalletMetadata;
|
|
62
|
-
transaction:
|
|
67
|
+
transaction: SvmSignableTransaction;
|
|
63
68
|
password?: string;
|
|
64
69
|
externalServerKeyShares?: ServerKeyShare[];
|
|
65
70
|
/** If true, requests gas sponsorship from Dynamic before signing. */
|
|
66
71
|
sponsor?: boolean;
|
|
67
72
|
chainId?: string;
|
|
68
73
|
context?: SignMessageContext;
|
|
69
|
-
}): Promise<
|
|
74
|
+
}): Promise<SignTransactionResult>;
|
|
70
75
|
/**
|
|
71
76
|
* Exports the private key for a given wallet
|
|
72
77
|
*
|
|
@@ -134,20 +139,21 @@ export declare class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
134
139
|
* Sponsors a Solana transaction via the Dynamic gas sponsorship API.
|
|
135
140
|
*
|
|
136
141
|
* Sends the unsigned transaction to Dynamic's sponsorTransaction endpoint,
|
|
137
|
-
* which replaces the fee payer with the sponsor's address. The
|
|
138
|
-
*
|
|
139
|
-
* {@link signTransaction} instead of the
|
|
142
|
+
* which replaces the fee payer with the sponsor's address. The endpoint
|
|
143
|
+
* always returns a v0 versioned transaction, which is deserialized and
|
|
144
|
+
* returned. It should be passed to {@link signTransaction} instead of the
|
|
145
|
+
* original transaction.
|
|
140
146
|
*
|
|
141
147
|
* Gas sponsorship must be enabled for your environment in the Dynamic
|
|
142
148
|
* dashboard before calling this method.
|
|
143
149
|
*
|
|
144
150
|
* @param transaction - Unsigned Solana transaction (legacy or versioned).
|
|
145
|
-
* @returns The sponsored transaction with the gas sponsor as fee payer.
|
|
151
|
+
* @returns The sponsored v0 transaction with the gas sponsor as fee payer.
|
|
146
152
|
*/
|
|
147
153
|
sponsorTransaction({ transaction, traceContext, }: {
|
|
148
154
|
transaction: VersionedTransaction | Transaction;
|
|
149
155
|
traceContext?: TraceContext;
|
|
150
|
-
}): Promise<VersionedTransaction
|
|
156
|
+
}): Promise<VersionedTransaction>;
|
|
151
157
|
/** @deprecated Use getWalletByAddress instead for better performance */
|
|
152
158
|
getSvmWallets(): Promise<{
|
|
153
159
|
walletId: string;
|
|
@@ -159,4 +165,5 @@ export declare class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
159
165
|
thresholdSignatureScheme: ThresholdSignatureScheme;
|
|
160
166
|
}[]>;
|
|
161
167
|
}
|
|
168
|
+
export {};
|
|
162
169
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EACnB,mBAAmB,EACnB,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EAGjB,KAAK,wBAAwB,EAC7B,KAAK,cAAc,EAGpB,MAAM,2BAA2B,C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