@dynamic-labs-wallet/node-svm 0.0.322 → 0.0.324

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,6 +15,7 @@ function _extends() {
15
15
  }
16
16
 
17
17
  const ERROR_CREATE_WALLET_ACCOUNT = 'Error creating svm wallet account';
18
+ const ERROR_SIGN_RAW_MESSAGE = 'Error signing raw message';
18
19
 
19
20
  // Base58 encoding/decoding (Bitcoin alphabet) without external dependencies
20
21
  // Implementation adapted from the reference algorithm; suitable for keys/signatures
@@ -209,12 +210,61 @@ class DynamicSvmWalletClient extends node.DynamicWalletClient {
209
210
  throw error;
210
211
  }
211
212
  }
213
+ /**
214
+ * Signs a pre-formatted (raw) message without additional encoding.
215
+ * The message must be a hex string representing already-hashed data.
216
+ *
217
+ * @param message The pre-formatted hex message to sign
218
+ * @param accountAddress Solana address (base58 encoded)
219
+ * @param password The password for encrypted backup shares
220
+ */ async signRawMessage({ message, accountAddress, password = undefined, externalServerKeyShares }) {
221
+ if (!accountAddress) {
222
+ throw new Error('Account address is required');
223
+ }
224
+ try {
225
+ // Attempt to recover key shares from backup if not provided
226
+ await this.ensureKeySharesRecovered({
227
+ accountAddress,
228
+ password,
229
+ walletOperation: node.WalletOperation.SIGN_MESSAGE,
230
+ externalServerKeyShares,
231
+ errorMessage: 'External server key shares are required to sign a raw message. No backup shares available for recovery.'
232
+ });
233
+ const messageHex = node.stripHexPrefix(message);
234
+ const signatureEd25519 = await this.sign({
235
+ message: messageHex,
236
+ accountAddress,
237
+ chainName: this.chainName,
238
+ password,
239
+ externalServerKeyShares,
240
+ isFormatted: true
241
+ });
242
+ return encodeBase58(signatureEd25519);
243
+ } catch (error) {
244
+ logError$1({
245
+ message: ERROR_SIGN_RAW_MESSAGE,
246
+ error: error,
247
+ context: {
248
+ accountAddress
249
+ }
250
+ });
251
+ throw new Error(ERROR_SIGN_RAW_MESSAGE);
252
+ }
253
+ }
212
254
  //todo:should txn just be a string?
213
- async signTransaction({ senderAddress, transaction, password = undefined, externalServerKeyShares }) {
255
+ async signTransaction({ senderAddress, transaction, password = undefined, externalServerKeyShares, sponsor = false }) {
214
256
  // Validate inputs early
215
257
  if (!senderAddress) {
216
258
  throw new Error('Sender address is required');
217
259
  }
260
+ if (sponsor) {
261
+ if (typeof transaction === 'string') {
262
+ throw new TypeError('sponsor=true requires a Transaction or VersionedTransaction object, not a hex string');
263
+ }
264
+ transaction = await this.sponsorTransaction({
265
+ transaction
266
+ });
267
+ }
218
268
  await this.verifyPassword({
219
269
  accountAddress: senderAddress,
220
270
  password
@@ -381,6 +431,37 @@ class DynamicSvmWalletClient extends node.DynamicWalletClient {
381
431
  externalKeySharesWithBackupStatus
382
432
  };
383
433
  }
434
+ /**
435
+ * Sponsors a Solana transaction via the Dynamic gas sponsorship API.
436
+ *
437
+ * Sends the unsigned transaction to Dynamic's sponsorTransaction endpoint,
438
+ * which replaces the fee payer with the sponsor's address. The returned
439
+ * transaction object has the sponsor as fee payer and should be passed to
440
+ * {@link signTransaction} instead of the original transaction.
441
+ *
442
+ * Gas sponsorship must be enabled for your environment in the Dynamic
443
+ * dashboard before calling this method.
444
+ *
445
+ * @param transaction - Unsigned Solana transaction (legacy or versioned).
446
+ * @returns The sponsored transaction with the gas sponsor as fee payer.
447
+ */ async sponsorTransaction({ transaction, traceContext }) {
448
+ // Serialize the unsigned transaction to base64 wire format
449
+ const serialized = transaction instanceof web3_js.VersionedTransaction ? transaction.serialize() : transaction.serialize({
450
+ requireAllSignatures: false,
451
+ verifySignatures: false
452
+ });
453
+ const txBase64 = Buffer.from(serialized).toString('base64');
454
+ const { transaction: sponsoredBase64 } = await this.apiClient.requestSvmSponsoredTransaction({
455
+ transaction: txBase64,
456
+ traceContext
457
+ });
458
+ const sponsoredBytes = Buffer.from(sponsoredBase64, 'base64');
459
+ // Deserialize back to the same transaction type
460
+ if (transaction instanceof web3_js.VersionedTransaction) {
461
+ return web3_js.VersionedTransaction.deserialize(sponsoredBytes);
462
+ }
463
+ return web3_js.Transaction.from(sponsoredBytes);
464
+ }
384
465
  async getSvmWallets() {
385
466
  const wallets = await this.getWallets();
386
467
  const svmWallets = wallets.filter((wallet)=>wallet.chainName === 'solana');
@@ -589,6 +670,62 @@ const logError = node.createLogError('node-svm');
589
670
  throw error;
590
671
  }
591
672
  };
673
+ /**
674
+ * Signs a pre-formatted (raw) message using delegated signing for SVM.
675
+ * The message must be a hex string representing already-hashed data.
676
+ *
677
+ * @param client - The delegated SVM wallet client
678
+ * @param options - Signing options
679
+ * @param options.walletId - The wallet ID
680
+ * @param options.walletApiKey - The wallet API key
681
+ * @param options.keyShare - The server key share
682
+ * @param options.message - Hex string of the already-hashed data to sign
683
+ *
684
+ * @returns The base58-encoded signature
685
+ *
686
+ * @example
687
+ * // Sign a pre-hashed message
688
+ * const signature = await delegatedSignRawMessage(client, {
689
+ * walletId,
690
+ * walletApiKey,
691
+ * keyShare,
692
+ * message: preHashedHex, // hex string of already-hashed data
693
+ * });
694
+ *
695
+ * @example
696
+ * // Sign a SHA-256 hash derived from arbitrary application data
697
+ * import { createHash } from 'crypto';
698
+ * const hash = createHash('sha256').update('my application data').digest('hex');
699
+ * const signature = await delegatedSignRawMessage(client, {
700
+ * walletId,
701
+ * walletApiKey,
702
+ * keyShare,
703
+ * message: hash,
704
+ * });
705
+ *
706
+ */ const delegatedSignRawMessage = async (client, { walletId, walletApiKey, keyShare, message })=>{
707
+ if (!keyShare || !walletId || !walletApiKey) {
708
+ throw new Error('Delegated key share, wallet ID, and wallet API key are required to sign a raw message');
709
+ }
710
+ try {
711
+ return await delegatedSignMessage(client, {
712
+ walletId,
713
+ walletApiKey,
714
+ keyShare,
715
+ message: node.stripHexPrefix(message),
716
+ isFormatted: true
717
+ });
718
+ } catch (error) {
719
+ logError({
720
+ message: 'Error in delegatedSignRawMessage',
721
+ error: error,
722
+ context: {
723
+ walletId
724
+ }
725
+ });
726
+ throw error;
727
+ }
728
+ };
592
729
  /**
593
730
  * Revoke delegation - delegates to the node package
594
731
  */ const revokeDelegation = async (client, params)=>{
@@ -597,12 +734,14 @@ const logError = node.createLogError('node-svm');
597
734
 
598
735
  exports.DynamicSvmWalletClient = DynamicSvmWalletClient;
599
736
  exports.ERROR_CREATE_WALLET_ACCOUNT = ERROR_CREATE_WALLET_ACCOUNT;
737
+ exports.ERROR_SIGN_RAW_MESSAGE = ERROR_SIGN_RAW_MESSAGE;
600
738
  exports.addSignatureToTransaction = addSignatureToTransaction;
601
739
  exports.attachSignature = attachSignature;
602
740
  exports.createDelegatedSvmWalletClient = createDelegatedSvmWalletClient;
603
741
  exports.createSolanaTransaction = createSolanaTransaction;
604
742
  exports.decodeBase58 = decodeBase58;
605
743
  exports.delegatedSignMessage = delegatedSignMessage;
744
+ exports.delegatedSignRawMessage = delegatedSignRawMessage;
606
745
  exports.delegatedSignTransaction = delegatedSignTransaction;
607
746
  exports.encodeBase58 = encodeBase58;
608
747
  exports.getBalance = getBalance;
package/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
- import { createLogError, DynamicWalletClient, getMPCChainConfig, getExternalServerKeyShareBackupInfo, WalletOperation, SOLANA_RPC_URL, createDelegatedWalletClient, delegatedSignMessage as delegatedSignMessage$1, revokeDelegation as revokeDelegation$1 } from '@dynamic-labs-wallet/node';
2
- import { PublicKey, VersionedTransaction, Keypair, Connection, Transaction, SystemProgram } from '@solana/web3.js';
1
+ import { createLogError, DynamicWalletClient, getMPCChainConfig, getExternalServerKeyShareBackupInfo, WalletOperation, stripHexPrefix, SOLANA_RPC_URL, createDelegatedWalletClient, delegatedSignMessage as delegatedSignMessage$1, revokeDelegation as revokeDelegation$1 } from '@dynamic-labs-wallet/node';
2
+ import { PublicKey, VersionedTransaction, Keypair, Transaction, Connection, SystemProgram } from '@solana/web3.js';
3
3
 
4
4
  function _extends() {
5
5
  _extends = Object.assign || function assign(target) {
@@ -13,6 +13,7 @@ function _extends() {
13
13
  }
14
14
 
15
15
  const ERROR_CREATE_WALLET_ACCOUNT = 'Error creating svm wallet account';
16
+ const ERROR_SIGN_RAW_MESSAGE = 'Error signing raw message';
16
17
 
17
18
  // Base58 encoding/decoding (Bitcoin alphabet) without external dependencies
18
19
  // Implementation adapted from the reference algorithm; suitable for keys/signatures
@@ -207,12 +208,61 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
207
208
  throw error;
208
209
  }
209
210
  }
211
+ /**
212
+ * Signs a pre-formatted (raw) message without additional encoding.
213
+ * The message must be a hex string representing already-hashed data.
214
+ *
215
+ * @param message The pre-formatted hex message to sign
216
+ * @param accountAddress Solana address (base58 encoded)
217
+ * @param password The password for encrypted backup shares
218
+ */ async signRawMessage({ message, accountAddress, password = undefined, externalServerKeyShares }) {
219
+ if (!accountAddress) {
220
+ throw new Error('Account address is required');
221
+ }
222
+ try {
223
+ // Attempt to recover key shares from backup if not provided
224
+ await this.ensureKeySharesRecovered({
225
+ accountAddress,
226
+ password,
227
+ walletOperation: WalletOperation.SIGN_MESSAGE,
228
+ externalServerKeyShares,
229
+ errorMessage: 'External server key shares are required to sign a raw message. No backup shares available for recovery.'
230
+ });
231
+ const messageHex = stripHexPrefix(message);
232
+ const signatureEd25519 = await this.sign({
233
+ message: messageHex,
234
+ accountAddress,
235
+ chainName: this.chainName,
236
+ password,
237
+ externalServerKeyShares,
238
+ isFormatted: true
239
+ });
240
+ return encodeBase58(signatureEd25519);
241
+ } catch (error) {
242
+ logError$1({
243
+ message: ERROR_SIGN_RAW_MESSAGE,
244
+ error: error,
245
+ context: {
246
+ accountAddress
247
+ }
248
+ });
249
+ throw new Error(ERROR_SIGN_RAW_MESSAGE);
250
+ }
251
+ }
210
252
  //todo:should txn just be a string?
211
- async signTransaction({ senderAddress, transaction, password = undefined, externalServerKeyShares }) {
253
+ async signTransaction({ senderAddress, transaction, password = undefined, externalServerKeyShares, sponsor = false }) {
212
254
  // Validate inputs early
213
255
  if (!senderAddress) {
214
256
  throw new Error('Sender address is required');
215
257
  }
258
+ if (sponsor) {
259
+ if (typeof transaction === 'string') {
260
+ throw new TypeError('sponsor=true requires a Transaction or VersionedTransaction object, not a hex string');
261
+ }
262
+ transaction = await this.sponsorTransaction({
263
+ transaction
264
+ });
265
+ }
216
266
  await this.verifyPassword({
217
267
  accountAddress: senderAddress,
218
268
  password
@@ -379,6 +429,37 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
379
429
  externalKeySharesWithBackupStatus
380
430
  };
381
431
  }
432
+ /**
433
+ * Sponsors a Solana transaction via the Dynamic gas sponsorship API.
434
+ *
435
+ * Sends the unsigned transaction to Dynamic's sponsorTransaction endpoint,
436
+ * which replaces the fee payer with the sponsor's address. The returned
437
+ * transaction object has the sponsor as fee payer and should be passed to
438
+ * {@link signTransaction} instead of the original transaction.
439
+ *
440
+ * Gas sponsorship must be enabled for your environment in the Dynamic
441
+ * dashboard before calling this method.
442
+ *
443
+ * @param transaction - Unsigned Solana transaction (legacy or versioned).
444
+ * @returns The sponsored transaction with the gas sponsor as fee payer.
445
+ */ async sponsorTransaction({ transaction, traceContext }) {
446
+ // Serialize the unsigned transaction to base64 wire format
447
+ const serialized = transaction instanceof VersionedTransaction ? transaction.serialize() : transaction.serialize({
448
+ requireAllSignatures: false,
449
+ verifySignatures: false
450
+ });
451
+ const txBase64 = Buffer.from(serialized).toString('base64');
452
+ const { transaction: sponsoredBase64 } = await this.apiClient.requestSvmSponsoredTransaction({
453
+ transaction: txBase64,
454
+ traceContext
455
+ });
456
+ const sponsoredBytes = Buffer.from(sponsoredBase64, 'base64');
457
+ // Deserialize back to the same transaction type
458
+ if (transaction instanceof VersionedTransaction) {
459
+ return VersionedTransaction.deserialize(sponsoredBytes);
460
+ }
461
+ return Transaction.from(sponsoredBytes);
462
+ }
382
463
  async getSvmWallets() {
383
464
  const wallets = await this.getWallets();
384
465
  const svmWallets = wallets.filter((wallet)=>wallet.chainName === 'solana');
@@ -587,10 +668,66 @@ const logError = createLogError('node-svm');
587
668
  throw error;
588
669
  }
589
670
  };
671
+ /**
672
+ * Signs a pre-formatted (raw) message using delegated signing for SVM.
673
+ * The message must be a hex string representing already-hashed data.
674
+ *
675
+ * @param client - The delegated SVM wallet client
676
+ * @param options - Signing options
677
+ * @param options.walletId - The wallet ID
678
+ * @param options.walletApiKey - The wallet API key
679
+ * @param options.keyShare - The server key share
680
+ * @param options.message - Hex string of the already-hashed data to sign
681
+ *
682
+ * @returns The base58-encoded signature
683
+ *
684
+ * @example
685
+ * // Sign a pre-hashed message
686
+ * const signature = await delegatedSignRawMessage(client, {
687
+ * walletId,
688
+ * walletApiKey,
689
+ * keyShare,
690
+ * message: preHashedHex, // hex string of already-hashed data
691
+ * });
692
+ *
693
+ * @example
694
+ * // Sign a SHA-256 hash derived from arbitrary application data
695
+ * import { createHash } from 'crypto';
696
+ * const hash = createHash('sha256').update('my application data').digest('hex');
697
+ * const signature = await delegatedSignRawMessage(client, {
698
+ * walletId,
699
+ * walletApiKey,
700
+ * keyShare,
701
+ * message: hash,
702
+ * });
703
+ *
704
+ */ const delegatedSignRawMessage = async (client, { walletId, walletApiKey, keyShare, message })=>{
705
+ if (!keyShare || !walletId || !walletApiKey) {
706
+ throw new Error('Delegated key share, wallet ID, and wallet API key are required to sign a raw message');
707
+ }
708
+ try {
709
+ return await delegatedSignMessage(client, {
710
+ walletId,
711
+ walletApiKey,
712
+ keyShare,
713
+ message: stripHexPrefix(message),
714
+ isFormatted: true
715
+ });
716
+ } catch (error) {
717
+ logError({
718
+ message: 'Error in delegatedSignRawMessage',
719
+ error: error,
720
+ context: {
721
+ walletId
722
+ }
723
+ });
724
+ throw error;
725
+ }
726
+ };
590
727
  /**
591
728
  * Revoke delegation - delegates to the node package
592
729
  */ const revokeDelegation = async (client, params)=>{
593
730
  return revokeDelegation$1(client, params);
594
731
  };
595
732
 
596
- export { DynamicSvmWalletClient, ERROR_CREATE_WALLET_ACCOUNT, addSignatureToTransaction, attachSignature, createDelegatedSvmWalletClient, createSolanaTransaction, decodeBase58, delegatedSignMessage, delegatedSignTransaction, encodeBase58, getBalance, revokeDelegation, sendTransaction };
733
+ export { DynamicSvmWalletClient, ERROR_CREATE_WALLET_ACCOUNT, ERROR_SIGN_RAW_MESSAGE, addSignatureToTransaction, attachSignature, createDelegatedSvmWalletClient, createSolanaTransaction, decodeBase58, delegatedSignMessage, delegatedSignRawMessage, 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.322",
3
+ "version": "0.0.324",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "dependencies": {
7
- "@dynamic-labs-wallet/node": "0.0.322",
7
+ "@dynamic-labs-wallet/node": "0.0.324",
8
8
  "@solana/web3.js": "^1.98.2"
9
9
  },
10
10
  "publishConfig": {
@@ -0,0 +1,3 @@
1
+ export declare function encodeBase58(source: Uint8Array): string;
2
+ export declare function decodeBase58(str: string): Uint8Array;
3
+ //# sourceMappingURL=base58.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base58.d.ts","sourceRoot":"","sources":["../../src/client/base58.ts"],"names":[],"mappings":"AAOA,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAkCvD;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAmCpD"}
@@ -0,0 +1,145 @@
1
+ import { type ServerKeyShare, DynamicWalletClient, type Ed25519KeygenResult, type ThresholdSignatureScheme, type TraceContext, type DynamicWalletClientProps } from '@dynamic-labs-wallet/node';
2
+ import { Transaction, VersionedTransaction } from '@solana/web3.js';
3
+ export declare class DynamicSvmWalletClient extends DynamicWalletClient {
4
+ readonly chainName = "SVM";
5
+ accountAddress?: string;
6
+ constructor({ environmentId, baseApiUrl, baseMPCRelayApiUrl, enableMPCAccelerator, logger, debug, }: DynamicWalletClientProps);
7
+ /**
8
+ * Creates a wallet account on the Solana chain
9
+ *
10
+ * @param thresholdSignatureScheme The threshold signature scheme to use
11
+ * @returns The account address, public key hex, raw public key, and client key shares
12
+ */
13
+ createWalletAccount({ thresholdSignatureScheme, password, onError, backUpToClientShareService, }: {
14
+ thresholdSignatureScheme: ThresholdSignatureScheme;
15
+ password?: string;
16
+ onError?: (error: Error) => void;
17
+ backUpToClientShareService?: boolean;
18
+ }): Promise<{
19
+ accountAddress: string;
20
+ rawPublicKey: Uint8Array | string;
21
+ /** @deprecated Use externalKeySharesWithBackupStatus instead */
22
+ externalServerKeyShares: ServerKeyShare[];
23
+ externalKeySharesWithBackupStatus: Array<{
24
+ share: ServerKeyShare;
25
+ backedUpToClientKeyShareService: boolean;
26
+ }>;
27
+ }>;
28
+ deriveAccountAddress(rawPublicKey: string | Uint8Array): Promise<{
29
+ accountAddress: string;
30
+ }>;
31
+ /**
32
+ * This function takes a message and returns it after being signed with MPC
33
+ *
34
+ * @param message The message to sign (Uint8Array)
35
+ * @param accountAddress Solana address (base58 encoded)
36
+ * @param password The password for encrypted backup shares
37
+ */
38
+ signMessage({ message, accountAddress, password, externalServerKeyShares, }: {
39
+ message: string | Uint8Array;
40
+ accountAddress: string;
41
+ password?: string;
42
+ externalServerKeyShares?: ServerKeyShare[];
43
+ }): Promise<string>;
44
+ /**
45
+ * Signs a pre-formatted (raw) message without additional encoding.
46
+ * The message must be a hex string representing already-hashed data.
47
+ *
48
+ * @param message The pre-formatted hex message to sign
49
+ * @param accountAddress Solana address (base58 encoded)
50
+ * @param password The password for encrypted backup shares
51
+ */
52
+ signRawMessage({ message, accountAddress, password, externalServerKeyShares, }: {
53
+ message: string;
54
+ accountAddress: string;
55
+ password?: string;
56
+ externalServerKeyShares?: ServerKeyShare[];
57
+ }): Promise<string>;
58
+ signTransaction({ senderAddress, transaction, password, externalServerKeyShares, sponsor, }: {
59
+ senderAddress: string;
60
+ transaction: VersionedTransaction | Transaction | string;
61
+ password?: string;
62
+ externalServerKeyShares?: ServerKeyShare[];
63
+ /** If true, requests gas sponsorship from Dynamic before signing. */
64
+ sponsor?: boolean;
65
+ }): Promise<string>;
66
+ /**
67
+ * Exports the private key for a given account address
68
+ *
69
+ * @param accountAddress The account address to export the private key for
70
+ * @param password The password for encrypted backup shares
71
+ * @returns The private key
72
+ */
73
+ exportPrivateKey({ accountAddress, password, externalServerKeyShares, }: {
74
+ accountAddress: string;
75
+ password?: string;
76
+ externalServerKeyShares?: ServerKeyShare[];
77
+ }): Promise<string>;
78
+ /**
79
+ * Exports the private key for a given account address
80
+ *
81
+ * @param keyShares The key shares to export the private key for
82
+ * @returns The private key
83
+ */
84
+ offlineExportPrivateKey({ keyShares, derivationPath, }: {
85
+ keyShares: Ed25519KeygenResult[];
86
+ derivationPath?: string;
87
+ }): Promise<{
88
+ derivedPrivateKey: string;
89
+ }>;
90
+ /**
91
+ * Converts the private key to a hex string
92
+ *
93
+ * @param privateKey The private key to convert
94
+ * @returns The hex string
95
+ */
96
+ decodePrivateKeyForSolana(privateKey: string): string;
97
+ getPublicKeyFromPrivateKey(privateKey: string): string;
98
+ encodePublicKey(publicKey: Uint8Array): string;
99
+ /**
100
+ * Imports the private key for a given account address
101
+ *
102
+ * @param privateKey The private key to import
103
+ * @param chainName The chain name to import the private key for
104
+ * @param thresholdSignatureScheme The threshold signature scheme to use
105
+ * @param password The password for encrypted backup shares
106
+ * @returns The account address, raw public key, and client key shares
107
+ */
108
+ importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password, onError, backUpToClientShareService, }: {
109
+ privateKey: string;
110
+ chainName: string;
111
+ thresholdSignatureScheme: ThresholdSignatureScheme;
112
+ password?: string;
113
+ onError?: (error: Error) => void;
114
+ backUpToClientShareService?: boolean;
115
+ }): Promise<{
116
+ accountAddress: string;
117
+ rawPublicKey: Uint8Array | string | undefined;
118
+ /** @deprecated Use externalKeySharesWithBackupStatus instead */
119
+ externalServerKeyShares: ServerKeyShare[];
120
+ externalKeySharesWithBackupStatus: Array<{
121
+ share: ServerKeyShare;
122
+ backedUpToClientKeyShareService: boolean;
123
+ }>;
124
+ }>;
125
+ /**
126
+ * Sponsors a Solana transaction via the Dynamic gas sponsorship API.
127
+ *
128
+ * Sends the unsigned transaction to Dynamic's sponsorTransaction endpoint,
129
+ * which replaces the fee payer with the sponsor's address. The returned
130
+ * transaction object has the sponsor as fee payer and should be passed to
131
+ * {@link signTransaction} instead of the original transaction.
132
+ *
133
+ * Gas sponsorship must be enabled for your environment in the Dynamic
134
+ * dashboard before calling this method.
135
+ *
136
+ * @param transaction - Unsigned Solana transaction (legacy or versioned).
137
+ * @returns The sponsored transaction with the gas sponsor as fee payer.
138
+ */
139
+ sponsorTransaction({ transaction, traceContext, }: {
140
+ transaction: VersionedTransaction | Transaction;
141
+ traceContext?: TraceContext;
142
+ }): Promise<VersionedTransaction | Transaction>;
143
+ getSvmWallets(): Promise<import("@dynamic-labs-wallet/node").WalletProperties[]>;
144
+ }
145
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +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,EAIjB,KAAK,wBAAwB,EAG9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAW,WAAW,EAAE,oBAAoB,EAAa,MAAM,iBAAiB,CAAC;AAUxF,qBAAa,sBAAuB,SAAQ,mBAAmB;IAC7D,QAAQ,CAAC,SAAS,SAAS;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;gBAEZ,EACV,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,oBAAoB,EACpB,MAAM,EACN,KAAK,GACN,EAAE,wBAAwB;IAW3B;;;;;OAKG;IACG,mBAAmB,CAAC,EACxB,wBAAwB,EACxB,QAAoB,EACpB,OAAO,EACP,0BAAkC,GACnC,EAAE;QACD,wBAAwB,EAAE,wBAAwB,C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CAAC,CAAC;KACJ,CAAC;IA4DF;;;;;;;;;;;;;OAaG;IACG,kBAAkB,CAAC,EACvB,WAAW,EACX,YAAY,GACb,EAAE;QACD,WAAW,EAAE,oBAAoB,GAAG,WAAW,CAAC;QAChD,YAAY,CAAC,EAAE,YAAY,CAAC;KAC7B,GAAG,OAAO,CAAC,oBAAoB,GAAG,WAAW,CAAC;IAuBzC,aAAa;CAKpB"}
@@ -0,0 +1,3 @@
1
+ export declare const ERROR_CREATE_WALLET_ACCOUNT = "Error creating svm wallet account";
2
+ export declare const ERROR_SIGN_RAW_MESSAGE = "Error signing raw message";
3
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/client/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,2BAA2B,sCAAsC,CAAC;AAE/E,eAAO,MAAM,sBAAsB,8BAA8B,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from './client.js';
2
+ export * from './utils.js';
3
+ export * from './base58.js';
4
+ export * from './constants.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { PublicKey, Transaction, type VersionedTransaction } from '@solana/web3.js';
2
+ export declare function getBalance({ address, rpcUrl }: {
3
+ address: string;
4
+ rpcUrl?: string;
5
+ }): Promise<number>;
6
+ export declare function createSolanaTransaction({ senderSolanaAddress, amount, to, rpcUrl, }: {
7
+ senderSolanaAddress: string;
8
+ amount: number;
9
+ to: string;
10
+ rpcUrl?: string;
11
+ }): Promise<{
12
+ transaction: Transaction;
13
+ serializedTransaction: Buffer;
14
+ }>;
15
+ export declare const addSignatureToTransaction: ({ transaction, signature, signerPublicKey, }: {
16
+ transaction: Transaction | VersionedTransaction;
17
+ signature: Uint8Array;
18
+ signerPublicKey: PublicKey;
19
+ }) => VersionedTransaction | Transaction;
20
+ export declare function attachSignature({ transaction, signatureBase58, senderAddress, }: {
21
+ transaction: Transaction | VersionedTransaction;
22
+ signatureBase58: string;
23
+ senderAddress: string;
24
+ }): VersionedTransaction | Transaction;
25
+ export declare function sendTransaction({ signedTransaction, rpcUrl, }: {
26
+ signedTransaction: Uint8Array;
27
+ rpcUrl?: string;
28
+ }): Promise<string>;
29
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/client/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAc,SAAS,EAAiB,WAAW,EAAE,KAAK,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAG/G,wBAAsB,UAAU,CAAC,EAAE,OAAO,EAAE,MAAuB,EAAE,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,mBAI1G;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;;;GAwBA;AAED,eAAO,MAAM,yBAAyB,iDAInC;IACD,WAAW,EAAE,WAAW,GAAG,oBAAoB,CAAC;IAChD,SAAS,EAAE,UAAU,CAAC;IACtB,eAAe,EAAE,SAAS,CAAC;CAC5B,KAAG,oBAAoB,GAAG,WAG1B,CAAC;AAEF,wBAAgB,eAAe,CAAC,EAC9B,WAAW,EACX,eAAe,EACf,aAAa,GACd,EAAE;IACD,WAAW,EAAE,WAAW,GAAG,oBAAoB,CAAC;IAChD,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;CACvB,GAAG,oBAAoB,GAAG,WAAW,CAQrC;AAED,wBAAsB,eAAe,CAAC,EACpC,iBAAiB,EACjB,MAAwC,GACzC,EAAE;IACD,iBAAiB,EAAE,UAAU,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,mBAIA"}
@@ -0,0 +1,119 @@
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
+ * @param client - The delegated SVM wallet client
32
+ * @param options - Signing options
33
+ * @param options.walletId - The wallet ID
34
+ * @param options.walletApiKey - The wallet API key
35
+ * @param options.keyShare - The server key share
36
+ * @param options.transaction - The transaction to sign (VersionedTransaction or Transaction)
37
+ * @param options.signerAddress - Optional. The address that should sign the transaction.
38
+ * If not provided, defaults to the first signer (VersionedTransaction)
39
+ * or fee payer (Transaction). Use this for gasless transactions where
40
+ * a separate fee payer pays the fees.
41
+ *
42
+ * @returns The partially signed transaction with the signature attached for the specified signer
43
+ *
44
+ * @example
45
+ * // Standard transaction where sender is also fee payer
46
+ * const signedTx = await delegatedSignTransaction(client, {
47
+ * walletId,
48
+ * walletApiKey,
49
+ * keyShare,
50
+ * transaction,
51
+ * });
52
+ *
53
+ * @example
54
+ * // Gasless transaction with separate fee payer
55
+ * const transaction = new Transaction();
56
+ * transaction.feePayer = feePayerPublicKey; // Set the actual fee payer
57
+ * transaction.add(instruction); // Instruction that requires sender signature
58
+ *
59
+ * const signedTx = await delegatedSignTransaction(client, {
60
+ * walletId,
61
+ * walletApiKey,
62
+ * keyShare,
63
+ * transaction,
64
+ * signerAddress: senderAddress, // Explicitly specify who signs
65
+ * });
66
+ *
67
+ */
68
+ export declare const delegatedSignTransaction: (client: DelegatedSvmWalletClient, { walletId, walletApiKey, keyShare, transaction, signerAddress, }: {
69
+ walletId: string;
70
+ walletApiKey: string;
71
+ keyShare: any;
72
+ transaction: VersionedTransaction | Transaction;
73
+ signerAddress?: string;
74
+ }) => Promise<VersionedTransaction | Transaction>;
75
+ /**
76
+ * Signs a pre-formatted (raw) message using delegated signing for SVM.
77
+ * The message must be a hex string representing already-hashed data.
78
+ *
79
+ * @param client - The delegated SVM wallet client
80
+ * @param options - Signing options
81
+ * @param options.walletId - The wallet ID
82
+ * @param options.walletApiKey - The wallet API key
83
+ * @param options.keyShare - The server key share
84
+ * @param options.message - Hex string of the already-hashed data to sign
85
+ *
86
+ * @returns The base58-encoded signature
87
+ *
88
+ * @example
89
+ * // Sign a pre-hashed message
90
+ * const signature = await delegatedSignRawMessage(client, {
91
+ * walletId,
92
+ * walletApiKey,
93
+ * keyShare,
94
+ * message: preHashedHex, // hex string of already-hashed data
95
+ * });
96
+ *
97
+ * @example
98
+ * // Sign a SHA-256 hash derived from arbitrary application data
99
+ * import { createHash } from 'crypto';
100
+ * const hash = createHash('sha256').update('my application data').digest('hex');
101
+ * const signature = await delegatedSignRawMessage(client, {
102
+ * walletId,
103
+ * walletApiKey,
104
+ * keyShare,
105
+ * message: hash,
106
+ * });
107
+ *
108
+ */
109
+ export declare const delegatedSignRawMessage: (client: DelegatedSvmWalletClient, { walletId, walletApiKey, keyShare, message, }: {
110
+ walletId: string;
111
+ walletApiKey: string;
112
+ keyShare: ServerKeyShare;
113
+ message: string;
114
+ }) => Promise<string>;
115
+ /**
116
+ * Revoke delegation - delegates to the node package
117
+ */
118
+ export declare const revokeDelegation: (client: DelegatedSvmWalletClient, params: any) => Promise<void>;
119
+ //# sourceMappingURL=delegatedClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delegatedClient.d.ts","sourceRoot":"","sources":["../../packages/src/delegatedClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAQvF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAa,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAMlE,MAAM,MAAM,wBAAwB,GAAG;IACrC,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,qBAAqB,GAAG;IAC7D,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,8BAA8B,sEAMxC,wBAAwB,KAAG,wBAe7B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,WACvB,wBAAwB,+DAO7B;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,cAAc,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,KACA,OAAO,CAAC,MAAM,CAwBhB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,eAAO,MAAM,wBAAwB,WAC3B,wBAAwB,qEAO7B;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,GAAG,CAAC;IACd,WAAW,EAAE,oBAAoB,GAAG,WAAW,CAAC;IAChD,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,KACA,OAAO,CAAC,oBAAoB,GAAG,WAAW,CAmE5C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,uBAAuB,WAC1B,wBAAwB,kDAM7B;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,cAAc,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;CACjB,KACA,OAAO,CAAC,MAAM,CAqBhB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,WAAkB,wBAAwB,UAAU,GAAG,kBAEnF,CAAC"}
package/src/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './client/index.js';
2
+ export * from './delegatedClient.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC"}