@dynamic-labs-wallet/node-svm 0.0.168 → 0.0.170
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 +98 -0
- package/index.esm.js +96 -2
- package/package.json +2 -2
- package/src/delegatedClient.d.ts +41 -0
- package/src/delegatedClient.d.ts.map +1 -0
- package/src/index.d.ts +1 -0
- package/src/index.d.ts.map +1 -1
package/index.cjs.js
CHANGED
|
@@ -410,12 +410,110 @@ async function sendTransaction({ signedTransaction, rpcUrl = 'https://api.devnet
|
|
|
410
410
|
return txid;
|
|
411
411
|
}
|
|
412
412
|
|
|
413
|
+
/**
|
|
414
|
+
* Creates a delegated SVM wallet client for functional operations
|
|
415
|
+
*/ const createDelegatedSvmWalletClient = ({ environmentId, baseApiUrl, baseMPCRelayApiUrl, apiKey, debug = false })=>{
|
|
416
|
+
const baseClient = node.createDelegatedWalletClient({
|
|
417
|
+
environmentId,
|
|
418
|
+
baseApiUrl,
|
|
419
|
+
baseMPCRelayApiUrl,
|
|
420
|
+
apiKey,
|
|
421
|
+
debug
|
|
422
|
+
});
|
|
423
|
+
const svmClient = _extends({}, baseClient, {
|
|
424
|
+
chainName: 'SVM'
|
|
425
|
+
});
|
|
426
|
+
return svmClient;
|
|
427
|
+
};
|
|
428
|
+
/**
|
|
429
|
+
* Signs a message using delegated signing for SVM
|
|
430
|
+
*/ const delegatedSignMessage = async (client, { walletId, walletApiKey, keyShare, message, isFormatted = false })=>{
|
|
431
|
+
try {
|
|
432
|
+
// Use the delegated sign message function from node package
|
|
433
|
+
const signatureEd25519 = await node.delegatedSignMessage(client, {
|
|
434
|
+
walletId,
|
|
435
|
+
walletApiKey,
|
|
436
|
+
keyShare,
|
|
437
|
+
message,
|
|
438
|
+
chainName: client.chainName,
|
|
439
|
+
isFormatted
|
|
440
|
+
});
|
|
441
|
+
// Use PublicKey to encode signature as base58 (SVM format)
|
|
442
|
+
const base58Signature = encodeBase58(signatureEd25519);
|
|
443
|
+
return base58Signature;
|
|
444
|
+
} catch (error) {
|
|
445
|
+
client.logger.error('Error in delegatedSignMessage', error);
|
|
446
|
+
throw error;
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
/**
|
|
450
|
+
* Signs a transaction using delegated signing for SVM
|
|
451
|
+
*/ const delegatedSignTransaction = async (client, { walletId, walletApiKey, keyShare, transaction })=>{
|
|
452
|
+
try {
|
|
453
|
+
let messageToSign;
|
|
454
|
+
if (transaction instanceof web3_js.VersionedTransaction) {
|
|
455
|
+
// For versioned transactions, we need to sign the message directly
|
|
456
|
+
const messageBytes = transaction.message.serialize();
|
|
457
|
+
messageToSign = Buffer.from(Array.from(messageBytes)).toString('hex');
|
|
458
|
+
} else {
|
|
459
|
+
// For legacy transactions, serialize the message
|
|
460
|
+
const messageBytes = transaction.serializeMessage();
|
|
461
|
+
messageToSign = messageBytes.toString('hex');
|
|
462
|
+
}
|
|
463
|
+
// Use the delegated sign message function from node package
|
|
464
|
+
const signatureEd25519 = await node.delegatedSignMessage(client, {
|
|
465
|
+
walletId,
|
|
466
|
+
walletApiKey,
|
|
467
|
+
keyShare,
|
|
468
|
+
message: messageToSign,
|
|
469
|
+
chainName: client.chainName,
|
|
470
|
+
isFormatted: false
|
|
471
|
+
});
|
|
472
|
+
if (!signatureEd25519) {
|
|
473
|
+
throw new Error('Signature is undefined');
|
|
474
|
+
}
|
|
475
|
+
// Get the sender address from the transaction
|
|
476
|
+
let senderAddress;
|
|
477
|
+
if (transaction instanceof web3_js.VersionedTransaction) {
|
|
478
|
+
// For versioned transactions, get the first signer
|
|
479
|
+
const signers = transaction.message.staticAccountKeys;
|
|
480
|
+
senderAddress = signers[0].toBase58();
|
|
481
|
+
} else {
|
|
482
|
+
var _transaction_feePayer;
|
|
483
|
+
// For legacy transactions, use feePayer
|
|
484
|
+
senderAddress = ((_transaction_feePayer = transaction.feePayer) == null ? void 0 : _transaction_feePayer.toBase58()) || '';
|
|
485
|
+
}
|
|
486
|
+
if (!senderAddress) {
|
|
487
|
+
throw new Error('Could not determine sender address from transaction');
|
|
488
|
+
}
|
|
489
|
+
const senderPublicKey = new web3_js.PublicKey(senderAddress);
|
|
490
|
+
const signedTransaction = addSignatureToTransaction({
|
|
491
|
+
transaction,
|
|
492
|
+
signature: signatureEd25519,
|
|
493
|
+
signerPublicKey: senderPublicKey
|
|
494
|
+
});
|
|
495
|
+
return signedTransaction;
|
|
496
|
+
} catch (error) {
|
|
497
|
+
client.logger.error('Error in delegatedSignTransaction', error);
|
|
498
|
+
throw error;
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
/**
|
|
502
|
+
* Revoke delegation - delegates to the node package
|
|
503
|
+
*/ const revokeDelegation = async (client, params)=>{
|
|
504
|
+
return node.revokeDelegation(client, params);
|
|
505
|
+
};
|
|
506
|
+
|
|
413
507
|
exports.DynamicSvmWalletClient = DynamicSvmWalletClient;
|
|
414
508
|
exports.ERROR_CREATE_WALLET_ACCOUNT = ERROR_CREATE_WALLET_ACCOUNT;
|
|
415
509
|
exports.addSignatureToTransaction = addSignatureToTransaction;
|
|
416
510
|
exports.attachSignature = attachSignature;
|
|
511
|
+
exports.createDelegatedSvmWalletClient = createDelegatedSvmWalletClient;
|
|
417
512
|
exports.createSolanaTransaction = createSolanaTransaction;
|
|
418
513
|
exports.decodeBase58 = decodeBase58;
|
|
514
|
+
exports.delegatedSignMessage = delegatedSignMessage;
|
|
515
|
+
exports.delegatedSignTransaction = delegatedSignTransaction;
|
|
419
516
|
exports.encodeBase58 = encodeBase58;
|
|
420
517
|
exports.getBalance = getBalance;
|
|
518
|
+
exports.revokeDelegation = revokeDelegation;
|
|
421
519
|
exports.sendTransaction = sendTransaction;
|
package/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DynamicWalletClient, getMPCChainConfig, getExternalServerKeyShareBackupInfo, WalletOperation, SOLANA_RPC_URL } from '@dynamic-labs-wallet/node';
|
|
1
|
+
import { DynamicWalletClient, getMPCChainConfig, getExternalServerKeyShareBackupInfo, WalletOperation, SOLANA_RPC_URL, createDelegatedWalletClient, delegatedSignMessage as delegatedSignMessage$1, revokeDelegation as revokeDelegation$1 } from '@dynamic-labs-wallet/node';
|
|
2
2
|
import { PublicKey, VersionedTransaction, Keypair, Connection, Transaction, SystemProgram } from '@solana/web3.js';
|
|
3
3
|
|
|
4
4
|
function _extends() {
|
|
@@ -408,4 +408,98 @@ async function sendTransaction({ signedTransaction, rpcUrl = 'https://api.devnet
|
|
|
408
408
|
return txid;
|
|
409
409
|
}
|
|
410
410
|
|
|
411
|
-
|
|
411
|
+
/**
|
|
412
|
+
* Creates a delegated SVM wallet client for functional operations
|
|
413
|
+
*/ const createDelegatedSvmWalletClient = ({ environmentId, baseApiUrl, baseMPCRelayApiUrl, apiKey, debug = false })=>{
|
|
414
|
+
const baseClient = createDelegatedWalletClient({
|
|
415
|
+
environmentId,
|
|
416
|
+
baseApiUrl,
|
|
417
|
+
baseMPCRelayApiUrl,
|
|
418
|
+
apiKey,
|
|
419
|
+
debug
|
|
420
|
+
});
|
|
421
|
+
const svmClient = _extends({}, baseClient, {
|
|
422
|
+
chainName: 'SVM'
|
|
423
|
+
});
|
|
424
|
+
return svmClient;
|
|
425
|
+
};
|
|
426
|
+
/**
|
|
427
|
+
* Signs a message using delegated signing for SVM
|
|
428
|
+
*/ const delegatedSignMessage = async (client, { walletId, walletApiKey, keyShare, message, isFormatted = false })=>{
|
|
429
|
+
try {
|
|
430
|
+
// Use the delegated sign message function from node package
|
|
431
|
+
const signatureEd25519 = await delegatedSignMessage$1(client, {
|
|
432
|
+
walletId,
|
|
433
|
+
walletApiKey,
|
|
434
|
+
keyShare,
|
|
435
|
+
message,
|
|
436
|
+
chainName: client.chainName,
|
|
437
|
+
isFormatted
|
|
438
|
+
});
|
|
439
|
+
// Use PublicKey to encode signature as base58 (SVM format)
|
|
440
|
+
const base58Signature = encodeBase58(signatureEd25519);
|
|
441
|
+
return base58Signature;
|
|
442
|
+
} catch (error) {
|
|
443
|
+
client.logger.error('Error in delegatedSignMessage', error);
|
|
444
|
+
throw error;
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
/**
|
|
448
|
+
* Signs a transaction using delegated signing for SVM
|
|
449
|
+
*/ const delegatedSignTransaction = async (client, { walletId, walletApiKey, keyShare, transaction })=>{
|
|
450
|
+
try {
|
|
451
|
+
let messageToSign;
|
|
452
|
+
if (transaction instanceof VersionedTransaction) {
|
|
453
|
+
// For versioned transactions, we need to sign the message directly
|
|
454
|
+
const messageBytes = transaction.message.serialize();
|
|
455
|
+
messageToSign = Buffer.from(Array.from(messageBytes)).toString('hex');
|
|
456
|
+
} else {
|
|
457
|
+
// For legacy transactions, serialize the message
|
|
458
|
+
const messageBytes = transaction.serializeMessage();
|
|
459
|
+
messageToSign = messageBytes.toString('hex');
|
|
460
|
+
}
|
|
461
|
+
// Use the delegated sign message function from node package
|
|
462
|
+
const signatureEd25519 = await delegatedSignMessage$1(client, {
|
|
463
|
+
walletId,
|
|
464
|
+
walletApiKey,
|
|
465
|
+
keyShare,
|
|
466
|
+
message: messageToSign,
|
|
467
|
+
chainName: client.chainName,
|
|
468
|
+
isFormatted: false
|
|
469
|
+
});
|
|
470
|
+
if (!signatureEd25519) {
|
|
471
|
+
throw new Error('Signature is undefined');
|
|
472
|
+
}
|
|
473
|
+
// Get the sender address from the transaction
|
|
474
|
+
let senderAddress;
|
|
475
|
+
if (transaction instanceof VersionedTransaction) {
|
|
476
|
+
// For versioned transactions, get the first signer
|
|
477
|
+
const signers = transaction.message.staticAccountKeys;
|
|
478
|
+
senderAddress = signers[0].toBase58();
|
|
479
|
+
} else {
|
|
480
|
+
var _transaction_feePayer;
|
|
481
|
+
// For legacy transactions, use feePayer
|
|
482
|
+
senderAddress = ((_transaction_feePayer = transaction.feePayer) == null ? void 0 : _transaction_feePayer.toBase58()) || '';
|
|
483
|
+
}
|
|
484
|
+
if (!senderAddress) {
|
|
485
|
+
throw new Error('Could not determine sender address from transaction');
|
|
486
|
+
}
|
|
487
|
+
const senderPublicKey = new PublicKey(senderAddress);
|
|
488
|
+
const signedTransaction = addSignatureToTransaction({
|
|
489
|
+
transaction,
|
|
490
|
+
signature: signatureEd25519,
|
|
491
|
+
signerPublicKey: senderPublicKey
|
|
492
|
+
});
|
|
493
|
+
return signedTransaction;
|
|
494
|
+
} catch (error) {
|
|
495
|
+
client.logger.error('Error in delegatedSignTransaction', error);
|
|
496
|
+
throw error;
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
/**
|
|
500
|
+
* Revoke delegation - delegates to the node package
|
|
501
|
+
*/ const revokeDelegation = async (client, params)=>{
|
|
502
|
+
return revokeDelegation$1(client, params);
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
export { DynamicSvmWalletClient, ERROR_CREATE_WALLET_ACCOUNT, addSignatureToTransaction, attachSignature, createDelegatedSvmWalletClient, createSolanaTransaction, decodeBase58, delegatedSignMessage, delegatedSignTransaction, encodeBase58, getBalance, revokeDelegation, sendTransaction };
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs-wallet/node-svm",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.170",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@dynamic-labs-wallet/node": "0.0.
|
|
7
|
+
"@dynamic-labs-wallet/node": "0.0.170",
|
|
8
8
|
"@solana/web3.js": "^1.98.2"
|
|
9
9
|
},
|
|
10
10
|
"publishConfig": {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { DelegatedWalletClient, ServerKeyShare } from '@dynamic-labs-wallet/node';
|
|
2
|
+
import type { Transaction } from '@solana/web3.js';
|
|
3
|
+
import { VersionedTransaction } from '@solana/web3.js';
|
|
4
|
+
export type DelegatedSvmClientConfig = {
|
|
5
|
+
environmentId: string;
|
|
6
|
+
baseApiUrl?: string;
|
|
7
|
+
baseMPCRelayApiUrl?: string;
|
|
8
|
+
apiKey: string;
|
|
9
|
+
debug?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type DelegatedSvmWalletClient = DelegatedWalletClient & {
|
|
12
|
+
readonly chainName: 'SVM';
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Creates a delegated SVM wallet client for functional operations
|
|
16
|
+
*/
|
|
17
|
+
export declare const createDelegatedSvmWalletClient: ({ environmentId, baseApiUrl, baseMPCRelayApiUrl, apiKey, debug, }: DelegatedSvmClientConfig) => DelegatedSvmWalletClient;
|
|
18
|
+
/**
|
|
19
|
+
* Signs a message using delegated signing for SVM
|
|
20
|
+
*/
|
|
21
|
+
export declare const delegatedSignMessage: (client: DelegatedSvmWalletClient, { walletId, walletApiKey, keyShare, message, isFormatted, }: {
|
|
22
|
+
walletId: string;
|
|
23
|
+
walletApiKey: string;
|
|
24
|
+
keyShare: ServerKeyShare;
|
|
25
|
+
message: string;
|
|
26
|
+
isFormatted?: boolean;
|
|
27
|
+
}) => Promise<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Signs a transaction using delegated signing for SVM
|
|
30
|
+
*/
|
|
31
|
+
export declare const delegatedSignTransaction: (client: DelegatedSvmWalletClient, { walletId, walletApiKey, keyShare, transaction, }: {
|
|
32
|
+
walletId: string;
|
|
33
|
+
walletApiKey: string;
|
|
34
|
+
keyShare: any;
|
|
35
|
+
transaction: VersionedTransaction | Transaction;
|
|
36
|
+
}) => Promise<VersionedTransaction | Transaction>;
|
|
37
|
+
/**
|
|
38
|
+
* Revoke delegation - delegates to the node package
|
|
39
|
+
*/
|
|
40
|
+
export declare const revokeDelegation: (client: DelegatedSvmWalletClient, params: any) => Promise<void>;
|
|
41
|
+
//# sourceMappingURL=delegatedClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delegatedClient.d.ts","sourceRoot":"","sources":["../../packages/src/delegatedClient.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CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC"}
|