@dynamic-labs-wallet/svm 0.0.0-preview-120.0

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.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./src/index";
package/index.cjs.js ADDED
@@ -0,0 +1,286 @@
1
+ 'use strict';
2
+
3
+ var browser = require('@dynamic-labs-wallet/browser');
4
+ var bs58 = require('bs58');
5
+ var web3_js = require('@solana/web3.js');
6
+
7
+ function _extends() {
8
+ _extends = Object.assign || function assign(target) {
9
+ for(var i = 1; i < arguments.length; i++){
10
+ var source = arguments[i];
11
+ for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
12
+ }
13
+ return target;
14
+ };
15
+ return _extends.apply(this, arguments);
16
+ }
17
+
18
+ const addSignatureToTransaction = ({ transaction, signature, signerPublicKey })=>{
19
+ transaction.addSignature(signerPublicKey, Buffer.from(signature));
20
+ return transaction;
21
+ };
22
+
23
+ const ERROR_CREATE_WALLET_ACCOUNT = 'Error creating svm wallet account';
24
+
25
+ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
26
+ /**
27
+ * Creates a wallet account on the Solana chain
28
+ *
29
+ * @param thresholdSignatureScheme The threshold signature scheme to use
30
+ * @returns The account address, public key hex, raw public key, and client key shares
31
+ */ async createWalletAccount({ thresholdSignatureScheme, password = undefined }) {
32
+ try {
33
+ const { rawPublicKey, clientKeyShares } = await this.keyGen({
34
+ chainName: this.chainName,
35
+ thresholdSignatureScheme,
36
+ onCeremonyComplete: (accountAddress, walletId)=>{
37
+ // update wallet map
38
+ this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress] || {}, {
39
+ accountAddress,
40
+ walletId,
41
+ chainName: this.chainName,
42
+ thresholdSignatureScheme,
43
+ clientKeySharesBackupInfo: browser.getClientKeyShareBackupInfo()
44
+ });
45
+ }
46
+ });
47
+ if (!rawPublicKey || !(rawPublicKey instanceof Uint8Array)) {
48
+ throw new Error('Raw public key is not a Uint8Array');
49
+ }
50
+ if (!clientKeyShares) {
51
+ throw new Error('Error creating wallet account');
52
+ }
53
+ const { accountAddress } = await this.deriveAccountAddress(rawPublicKey);
54
+ // Update client key shares in wallet map
55
+ // warning: this might result in race condition if `onCeremonyComplete` executes at the same time
56
+ // TODO: remove this once iframe handling for secret shares is implemented
57
+ await this.setClientKeySharesToLocalStorage({
58
+ accountAddress,
59
+ clientKeyShares,
60
+ overwriteOrMerge: 'overwrite'
61
+ });
62
+ // Backup the new wallet without waiting for the promise to resolve
63
+ void this.storeEncryptedBackupByWalletWithRetry({
64
+ accountAddress,
65
+ clientKeyShares,
66
+ password
67
+ });
68
+ return {
69
+ accountAddress,
70
+ rawPublicKey: rawPublicKey,
71
+ clientKeyShares
72
+ };
73
+ } catch (error) {
74
+ this.logger.error(ERROR_CREATE_WALLET_ACCOUNT, error);
75
+ throw new Error(ERROR_CREATE_WALLET_ACCOUNT);
76
+ }
77
+ }
78
+ // Function to properly derive account address
79
+ async deriveAccountAddress(rawPublicKey) {
80
+ const accountAddress = bs58.encode(rawPublicKey);
81
+ return {
82
+ accountAddress
83
+ };
84
+ }
85
+ /**
86
+ * This function takes a message and returns it after being signed with MPC
87
+ *
88
+ * @param message The message to sign (Uint8Array)
89
+ * @param accountAddress Solana address (base58 encoded)
90
+ * @param password The password for encrypted backup shares
91
+ */ async signMessage({ message, accountAddress, password = undefined }) {
92
+ await this.verifyPassword({
93
+ accountAddress,
94
+ password,
95
+ walletOperation: browser.WalletOperation.SIGN_MESSAGE
96
+ });
97
+ if (!accountAddress) {
98
+ throw new Error('Account address is required');
99
+ }
100
+ try {
101
+ const signatureEd25519 = await this.sign({
102
+ message,
103
+ accountAddress: accountAddress,
104
+ chainName: this.chainName,
105
+ password
106
+ });
107
+ const base58Signature = bs58.encode(signatureEd25519);
108
+ return base58Signature;
109
+ } catch (error) {
110
+ this.logger.error('Error signing message:', error);
111
+ throw error;
112
+ }
113
+ }
114
+ async signTransaction({ senderAddress, transaction, password = undefined }) {
115
+ await this.verifyPassword({
116
+ accountAddress: senderAddress,
117
+ password,
118
+ walletOperation: browser.WalletOperation.SIGN_TRANSACTION
119
+ });
120
+ try {
121
+ let messageToSign;
122
+ if (transaction instanceof web3_js.VersionedTransaction) {
123
+ // For versioned transactions, we need to sign the message directly
124
+ const messageBytes = transaction.message.serialize();
125
+ messageToSign = Buffer.from(messageBytes).toString('hex');
126
+ } else {
127
+ // For legacy transactions, serialize the message
128
+ const messageBytes = transaction.serializeMessage();
129
+ messageToSign = Buffer.from(messageBytes).toString('hex');
130
+ }
131
+ const signatureEd25519 = await this.sign({
132
+ message: messageToSign,
133
+ accountAddress: senderAddress,
134
+ chainName: this.chainName,
135
+ password
136
+ });
137
+ if (!signatureEd25519) {
138
+ throw new Error('Signature is undefined');
139
+ }
140
+ const senderPublicKey = new web3_js.PublicKey(senderAddress);
141
+ const signedTransaction = addSignatureToTransaction({
142
+ transaction,
143
+ signature: signatureEd25519,
144
+ signerPublicKey: senderPublicKey
145
+ });
146
+ return signedTransaction;
147
+ } catch (error) {
148
+ this.logger.error('Error in signTransaction:', error);
149
+ if (error instanceof Error) {
150
+ this.logger.error('Error details:', error);
151
+ }
152
+ throw error;
153
+ }
154
+ }
155
+ /**
156
+ * Exports the private key for a given account address
157
+ *
158
+ * @param accountAddress The account address to export the private key for
159
+ * @param password The password for encrypted backup shares
160
+ * @returns The private key
161
+ */ async exportPrivateKey({ accountAddress, displayContainer, password = undefined }) {
162
+ await this.verifyPassword({
163
+ accountAddress,
164
+ password,
165
+ walletOperation: browser.WalletOperation.EXPORT_PRIVATE_KEY
166
+ });
167
+ const { derivedPrivateKey } = await this.exportKey({
168
+ accountAddress,
169
+ chainName: this.chainName,
170
+ password
171
+ });
172
+ if (!derivedPrivateKey) {
173
+ throw new Error('Derived private key is undefined');
174
+ }
175
+ const encodedPrivateKey = bs58.encode(Buffer.from(derivedPrivateKey));
176
+ // Display the private key in the container via iframe
177
+ const { iframeDisplay } = await this.initializeIframeDisplayForContainer({
178
+ container: displayContainer
179
+ });
180
+ iframeDisplay.displayPrivateKey(accountAddress, encodedPrivateKey);
181
+ }
182
+ /**
183
+ * Exports the private key for a given account address
184
+ *
185
+ * @param keyShares The key shares to export the private key for
186
+ * @returns The private key
187
+ */ async offlineExportPrivateKey({ keyShares, derivationPath }) {
188
+ const { derivedPrivateKey } = await this.offlineExportKey({
189
+ chainName: this.chainName,
190
+ keyShares,
191
+ derivationPath
192
+ });
193
+ return {
194
+ derivedPrivateKey
195
+ };
196
+ }
197
+ /**
198
+ * Converts the private key to a hex string
199
+ *
200
+ * @param privateKey The private key to convert
201
+ * @returns The hex string
202
+ */ decodePrivateKeyForSolana(privateKey) {
203
+ const decoded = bs58.decode(privateKey);
204
+ const slicedBytes = decoded.slice(0, 32);
205
+ return Buffer.from(slicedBytes).toString('hex');
206
+ }
207
+ getPublicKeyFromPrivateKey(privateKey) {
208
+ const privateKeyBytes = bs58.decode(privateKey);
209
+ const keypair = web3_js.Keypair.fromSecretKey(privateKeyBytes);
210
+ const publicKeyBase58 = keypair.publicKey.toBase58();
211
+ return publicKeyBase58;
212
+ }
213
+ encodePublicKey(publicKey) {
214
+ return bs58.encode(publicKey);
215
+ }
216
+ /**
217
+ * Imports the private key for a given account address
218
+ *
219
+ * @param privateKey The private key to import
220
+ * @param chainName The chain name to import the private key for
221
+ * @param thresholdSignatureScheme The threshold signature scheme to use
222
+ * @param password The password for encrypted backup shares
223
+ * @returns The account address, raw public key, and client key shares
224
+ */ async importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password = undefined, onError }) {
225
+ //get public key from private key
226
+ const publicKey = this.getPublicKeyFromPrivateKey(privateKey);
227
+ const formattedPrivateKey = await this.decodePrivateKeyForSolana(privateKey);
228
+ const { rawPublicKey, clientKeyShares } = await this.importRawPrivateKey({
229
+ chainName,
230
+ privateKey: formattedPrivateKey,
231
+ thresholdSignatureScheme,
232
+ onError,
233
+ onCeremonyComplete: (accountAddress, walletId)=>{
234
+ // update wallet map
235
+ this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress] || {}, {
236
+ accountAddress,
237
+ walletId,
238
+ chainName: this.chainName,
239
+ thresholdSignatureScheme,
240
+ clientKeySharesBackupInfo: browser.getClientKeyShareBackupInfo()
241
+ });
242
+ }
243
+ });
244
+ if (!rawPublicKey || !clientKeyShares) {
245
+ throw new Error('Error creating wallet account');
246
+ }
247
+ const { accountAddress } = await this.deriveAccountAddress(rawPublicKey);
248
+ if (accountAddress !== publicKey) {
249
+ throw new Error(`Public key mismatch: derived address ${accountAddress} !== public key ${publicKey}`);
250
+ }
251
+ // Update client key shares in wallet map
252
+ // warning: this might result in race condition if `onCeremonyComplete` executes at the same time
253
+ // TODO: remove this once iframe handling for secret shares is implemented
254
+ await this.setClientKeySharesToLocalStorage({
255
+ accountAddress,
256
+ clientKeyShares,
257
+ overwriteOrMerge: 'overwrite'
258
+ });
259
+ // Backup the new wallet without waiting for the promise to resolve
260
+ void this.storeEncryptedBackupByWalletWithRetry({
261
+ accountAddress,
262
+ clientKeyShares,
263
+ password
264
+ });
265
+ return {
266
+ accountAddress,
267
+ rawPublicKey: rawPublicKey,
268
+ clientKeyShares
269
+ };
270
+ }
271
+ async getSvmWallets() {
272
+ const wallets = await this.getWallets();
273
+ const svmWallets = wallets.filter((wallet)=>wallet.chainName === 'solana');
274
+ return svmWallets;
275
+ }
276
+ constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl }){
277
+ super({
278
+ environmentId,
279
+ authToken,
280
+ baseApiUrl,
281
+ baseMPCRelayApiUrl
282
+ }), this.chainName = 'SOL';
283
+ }
284
+ }
285
+
286
+ exports.DynamicSvmWalletClient = DynamicSvmWalletClient;
package/index.esm.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./src/index";
package/index.esm.js ADDED
@@ -0,0 +1,284 @@
1
+ import { DynamicWalletClient, getClientKeyShareBackupInfo, WalletOperation } from '@dynamic-labs-wallet/browser';
2
+ import bs58 from 'bs58';
3
+ import { VersionedTransaction, PublicKey, Keypair } from '@solana/web3.js';
4
+
5
+ function _extends() {
6
+ _extends = Object.assign || function assign(target) {
7
+ for(var i = 1; i < arguments.length; i++){
8
+ var source = arguments[i];
9
+ for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
10
+ }
11
+ return target;
12
+ };
13
+ return _extends.apply(this, arguments);
14
+ }
15
+
16
+ const addSignatureToTransaction = ({ transaction, signature, signerPublicKey })=>{
17
+ transaction.addSignature(signerPublicKey, Buffer.from(signature));
18
+ return transaction;
19
+ };
20
+
21
+ const ERROR_CREATE_WALLET_ACCOUNT = 'Error creating svm wallet account';
22
+
23
+ class DynamicSvmWalletClient extends DynamicWalletClient {
24
+ /**
25
+ * Creates a wallet account on the Solana chain
26
+ *
27
+ * @param thresholdSignatureScheme The threshold signature scheme to use
28
+ * @returns The account address, public key hex, raw public key, and client key shares
29
+ */ async createWalletAccount({ thresholdSignatureScheme, password = undefined }) {
30
+ try {
31
+ const { rawPublicKey, clientKeyShares } = await this.keyGen({
32
+ chainName: this.chainName,
33
+ thresholdSignatureScheme,
34
+ onCeremonyComplete: (accountAddress, walletId)=>{
35
+ // update wallet map
36
+ this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress] || {}, {
37
+ accountAddress,
38
+ walletId,
39
+ chainName: this.chainName,
40
+ thresholdSignatureScheme,
41
+ clientKeySharesBackupInfo: getClientKeyShareBackupInfo()
42
+ });
43
+ }
44
+ });
45
+ if (!rawPublicKey || !(rawPublicKey instanceof Uint8Array)) {
46
+ throw new Error('Raw public key is not a Uint8Array');
47
+ }
48
+ if (!clientKeyShares) {
49
+ throw new Error('Error creating wallet account');
50
+ }
51
+ const { accountAddress } = await this.deriveAccountAddress(rawPublicKey);
52
+ // Update client key shares in wallet map
53
+ // warning: this might result in race condition if `onCeremonyComplete` executes at the same time
54
+ // TODO: remove this once iframe handling for secret shares is implemented
55
+ await this.setClientKeySharesToLocalStorage({
56
+ accountAddress,
57
+ clientKeyShares,
58
+ overwriteOrMerge: 'overwrite'
59
+ });
60
+ // Backup the new wallet without waiting for the promise to resolve
61
+ void this.storeEncryptedBackupByWalletWithRetry({
62
+ accountAddress,
63
+ clientKeyShares,
64
+ password
65
+ });
66
+ return {
67
+ accountAddress,
68
+ rawPublicKey: rawPublicKey,
69
+ clientKeyShares
70
+ };
71
+ } catch (error) {
72
+ this.logger.error(ERROR_CREATE_WALLET_ACCOUNT, error);
73
+ throw new Error(ERROR_CREATE_WALLET_ACCOUNT);
74
+ }
75
+ }
76
+ // Function to properly derive account address
77
+ async deriveAccountAddress(rawPublicKey) {
78
+ const accountAddress = bs58.encode(rawPublicKey);
79
+ return {
80
+ accountAddress
81
+ };
82
+ }
83
+ /**
84
+ * This function takes a message and returns it after being signed with MPC
85
+ *
86
+ * @param message The message to sign (Uint8Array)
87
+ * @param accountAddress Solana address (base58 encoded)
88
+ * @param password The password for encrypted backup shares
89
+ */ async signMessage({ message, accountAddress, password = undefined }) {
90
+ await this.verifyPassword({
91
+ accountAddress,
92
+ password,
93
+ walletOperation: WalletOperation.SIGN_MESSAGE
94
+ });
95
+ if (!accountAddress) {
96
+ throw new Error('Account address is required');
97
+ }
98
+ try {
99
+ const signatureEd25519 = await this.sign({
100
+ message,
101
+ accountAddress: accountAddress,
102
+ chainName: this.chainName,
103
+ password
104
+ });
105
+ const base58Signature = bs58.encode(signatureEd25519);
106
+ return base58Signature;
107
+ } catch (error) {
108
+ this.logger.error('Error signing message:', error);
109
+ throw error;
110
+ }
111
+ }
112
+ async signTransaction({ senderAddress, transaction, password = undefined }) {
113
+ await this.verifyPassword({
114
+ accountAddress: senderAddress,
115
+ password,
116
+ walletOperation: WalletOperation.SIGN_TRANSACTION
117
+ });
118
+ try {
119
+ let messageToSign;
120
+ if (transaction instanceof VersionedTransaction) {
121
+ // For versioned transactions, we need to sign the message directly
122
+ const messageBytes = transaction.message.serialize();
123
+ messageToSign = Buffer.from(messageBytes).toString('hex');
124
+ } else {
125
+ // For legacy transactions, serialize the message
126
+ const messageBytes = transaction.serializeMessage();
127
+ messageToSign = Buffer.from(messageBytes).toString('hex');
128
+ }
129
+ const signatureEd25519 = await this.sign({
130
+ message: messageToSign,
131
+ accountAddress: senderAddress,
132
+ chainName: this.chainName,
133
+ password
134
+ });
135
+ if (!signatureEd25519) {
136
+ throw new Error('Signature is undefined');
137
+ }
138
+ const senderPublicKey = new PublicKey(senderAddress);
139
+ const signedTransaction = addSignatureToTransaction({
140
+ transaction,
141
+ signature: signatureEd25519,
142
+ signerPublicKey: senderPublicKey
143
+ });
144
+ return signedTransaction;
145
+ } catch (error) {
146
+ this.logger.error('Error in signTransaction:', error);
147
+ if (error instanceof Error) {
148
+ this.logger.error('Error details:', error);
149
+ }
150
+ throw error;
151
+ }
152
+ }
153
+ /**
154
+ * Exports the private key for a given account address
155
+ *
156
+ * @param accountAddress The account address to export the private key for
157
+ * @param password The password for encrypted backup shares
158
+ * @returns The private key
159
+ */ async exportPrivateKey({ accountAddress, displayContainer, password = undefined }) {
160
+ await this.verifyPassword({
161
+ accountAddress,
162
+ password,
163
+ walletOperation: WalletOperation.EXPORT_PRIVATE_KEY
164
+ });
165
+ const { derivedPrivateKey } = await this.exportKey({
166
+ accountAddress,
167
+ chainName: this.chainName,
168
+ password
169
+ });
170
+ if (!derivedPrivateKey) {
171
+ throw new Error('Derived private key is undefined');
172
+ }
173
+ const encodedPrivateKey = bs58.encode(Buffer.from(derivedPrivateKey));
174
+ // Display the private key in the container via iframe
175
+ const { iframeDisplay } = await this.initializeIframeDisplayForContainer({
176
+ container: displayContainer
177
+ });
178
+ iframeDisplay.displayPrivateKey(accountAddress, encodedPrivateKey);
179
+ }
180
+ /**
181
+ * Exports the private key for a given account address
182
+ *
183
+ * @param keyShares The key shares to export the private key for
184
+ * @returns The private key
185
+ */ async offlineExportPrivateKey({ keyShares, derivationPath }) {
186
+ const { derivedPrivateKey } = await this.offlineExportKey({
187
+ chainName: this.chainName,
188
+ keyShares,
189
+ derivationPath
190
+ });
191
+ return {
192
+ derivedPrivateKey
193
+ };
194
+ }
195
+ /**
196
+ * Converts the private key to a hex string
197
+ *
198
+ * @param privateKey The private key to convert
199
+ * @returns The hex string
200
+ */ decodePrivateKeyForSolana(privateKey) {
201
+ const decoded = bs58.decode(privateKey);
202
+ const slicedBytes = decoded.slice(0, 32);
203
+ return Buffer.from(slicedBytes).toString('hex');
204
+ }
205
+ getPublicKeyFromPrivateKey(privateKey) {
206
+ const privateKeyBytes = bs58.decode(privateKey);
207
+ const keypair = Keypair.fromSecretKey(privateKeyBytes);
208
+ const publicKeyBase58 = keypair.publicKey.toBase58();
209
+ return publicKeyBase58;
210
+ }
211
+ encodePublicKey(publicKey) {
212
+ return bs58.encode(publicKey);
213
+ }
214
+ /**
215
+ * Imports the private key for a given account address
216
+ *
217
+ * @param privateKey The private key to import
218
+ * @param chainName The chain name to import the private key for
219
+ * @param thresholdSignatureScheme The threshold signature scheme to use
220
+ * @param password The password for encrypted backup shares
221
+ * @returns The account address, raw public key, and client key shares
222
+ */ async importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password = undefined, onError }) {
223
+ //get public key from private key
224
+ const publicKey = this.getPublicKeyFromPrivateKey(privateKey);
225
+ const formattedPrivateKey = await this.decodePrivateKeyForSolana(privateKey);
226
+ const { rawPublicKey, clientKeyShares } = await this.importRawPrivateKey({
227
+ chainName,
228
+ privateKey: formattedPrivateKey,
229
+ thresholdSignatureScheme,
230
+ onError,
231
+ onCeremonyComplete: (accountAddress, walletId)=>{
232
+ // update wallet map
233
+ this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress] || {}, {
234
+ accountAddress,
235
+ walletId,
236
+ chainName: this.chainName,
237
+ thresholdSignatureScheme,
238
+ clientKeySharesBackupInfo: getClientKeyShareBackupInfo()
239
+ });
240
+ }
241
+ });
242
+ if (!rawPublicKey || !clientKeyShares) {
243
+ throw new Error('Error creating wallet account');
244
+ }
245
+ const { accountAddress } = await this.deriveAccountAddress(rawPublicKey);
246
+ if (accountAddress !== publicKey) {
247
+ throw new Error(`Public key mismatch: derived address ${accountAddress} !== public key ${publicKey}`);
248
+ }
249
+ // Update client key shares in wallet map
250
+ // warning: this might result in race condition if `onCeremonyComplete` executes at the same time
251
+ // TODO: remove this once iframe handling for secret shares is implemented
252
+ await this.setClientKeySharesToLocalStorage({
253
+ accountAddress,
254
+ clientKeyShares,
255
+ overwriteOrMerge: 'overwrite'
256
+ });
257
+ // Backup the new wallet without waiting for the promise to resolve
258
+ void this.storeEncryptedBackupByWalletWithRetry({
259
+ accountAddress,
260
+ clientKeyShares,
261
+ password
262
+ });
263
+ return {
264
+ accountAddress,
265
+ rawPublicKey: rawPublicKey,
266
+ clientKeyShares
267
+ };
268
+ }
269
+ async getSvmWallets() {
270
+ const wallets = await this.getWallets();
271
+ const svmWallets = wallets.filter((wallet)=>wallet.chainName === 'solana');
272
+ return svmWallets;
273
+ }
274
+ constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl }){
275
+ super({
276
+ environmentId,
277
+ authToken,
278
+ baseApiUrl,
279
+ baseMPCRelayApiUrl
280
+ }), this.chainName = 'SOL';
281
+ }
282
+ }
283
+
284
+ export { DynamicSvmWalletClient };
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@dynamic-labs-wallet/svm",
3
+ "version": "0.0.0-preview-120.0",
4
+ "license": "MIT",
5
+ "dependencies": {
6
+ "@dynamic-labs-wallet/browser": "0.0.0-preview-120.0",
7
+ "@solana/web3.js": "^1.98.0",
8
+ "bs58": "^6.0.0"
9
+ },
10
+ "nx": {
11
+ "sourceRoot": "packages/svm/src",
12
+ "projectType": "library",
13
+ "name": "svm",
14
+ "targets": {
15
+ "build": {}
16
+ }
17
+ },
18
+ "type": "module",
19
+ "main": "./index.cjs.js",
20
+ "module": "./index.esm.js",
21
+ "types": "./index.esm.d.ts",
22
+ "exports": {
23
+ "./package.json": "./package.json",
24
+ ".": {
25
+ "types": "./index.esm.d.ts",
26
+ "import": "./index.esm.js",
27
+ "require": "./index.cjs.js",
28
+ "default": "./index.cjs.js"
29
+ }
30
+ }
31
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './svm/index';
2
+ //# 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,aAAa,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const ERROR_CREATE_WALLET_ACCOUNT = "Error creating svm wallet account";
2
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/svm/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,2BAA2B,sCAAsC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './svm';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/svm/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC"}
@@ -0,0 +1,101 @@
1
+ import { ClientKeyShare, DynamicWalletClient, Ed25519KeygenResult, ThresholdSignatureScheme } from '@dynamic-labs-wallet/browser';
2
+ import { Transaction, VersionedTransaction } from '@solana/web3.js';
3
+ export declare class DynamicSvmWalletClient extends DynamicWalletClient {
4
+ readonly chainName = "SOL";
5
+ accountAddress?: string;
6
+ constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, }: {
7
+ environmentId: string;
8
+ authToken: string;
9
+ baseApiUrl?: string;
10
+ baseMPCRelayApiUrl?: string;
11
+ });
12
+ /**
13
+ * Creates a wallet account on the Solana chain
14
+ *
15
+ * @param thresholdSignatureScheme The threshold signature scheme to use
16
+ * @returns The account address, public key hex, raw public key, and client key shares
17
+ */
18
+ createWalletAccount({ thresholdSignatureScheme, password, }: {
19
+ thresholdSignatureScheme: ThresholdSignatureScheme;
20
+ password?: string;
21
+ }): Promise<{
22
+ accountAddress: string;
23
+ rawPublicKey: Uint8Array;
24
+ clientKeyShares: ClientKeyShare[];
25
+ }>;
26
+ deriveAccountAddress(rawPublicKey: Uint8Array): Promise<{
27
+ accountAddress: string;
28
+ }>;
29
+ /**
30
+ * This function takes a message and returns it after being signed with MPC
31
+ *
32
+ * @param message The message to sign (Uint8Array)
33
+ * @param accountAddress Solana address (base58 encoded)
34
+ * @param password The password for encrypted backup shares
35
+ */
36
+ signMessage({ message, accountAddress, password, }: {
37
+ message: string;
38
+ accountAddress: string;
39
+ password?: string;
40
+ }): Promise<string>;
41
+ signTransaction({ senderAddress, transaction, password, }: {
42
+ senderAddress: string;
43
+ transaction: VersionedTransaction | Transaction;
44
+ password?: string;
45
+ }): Promise<VersionedTransaction | Transaction>;
46
+ /**
47
+ * Exports the private key for a given account address
48
+ *
49
+ * @param accountAddress The account address to export the private key for
50
+ * @param password The password for encrypted backup shares
51
+ * @returns The private key
52
+ */
53
+ exportPrivateKey({ accountAddress, displayContainer, password, }: {
54
+ accountAddress: string;
55
+ displayContainer: HTMLElement;
56
+ password?: string;
57
+ }): Promise<void>;
58
+ /**
59
+ * Exports the private key for a given account address
60
+ *
61
+ * @param keyShares The key shares to export the private key for
62
+ * @returns The private key
63
+ */
64
+ offlineExportPrivateKey({ keyShares, derivationPath, }: {
65
+ keyShares: Ed25519KeygenResult[];
66
+ derivationPath?: string;
67
+ }): Promise<{
68
+ derivedPrivateKey: string | undefined;
69
+ }>;
70
+ /**
71
+ * Converts the private key to a hex string
72
+ *
73
+ * @param privateKey The private key to convert
74
+ * @returns The hex string
75
+ */
76
+ decodePrivateKeyForSolana(privateKey: string): string;
77
+ getPublicKeyFromPrivateKey(privateKey: string): string;
78
+ encodePublicKey(publicKey: Uint8Array): string;
79
+ /**
80
+ * Imports the private key for a given account address
81
+ *
82
+ * @param privateKey The private key to import
83
+ * @param chainName The chain name to import the private key for
84
+ * @param thresholdSignatureScheme The threshold signature scheme to use
85
+ * @param password The password for encrypted backup shares
86
+ * @returns The account address, raw public key, and client key shares
87
+ */
88
+ importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password, onError, }: {
89
+ privateKey: string;
90
+ chainName: string;
91
+ thresholdSignatureScheme: ThresholdSignatureScheme;
92
+ password?: string;
93
+ onError?: (error: Error) => void;
94
+ }): Promise<{
95
+ accountAddress: string;
96
+ rawPublicKey: Uint8Array | undefined;
97
+ clientKeyShares: ClientKeyShare[];
98
+ }>;
99
+ getSvmWallets(): Promise<any>;
100
+ }
101
+ //# sourceMappingURL=svm.d.ts.map
@@ -0,0 +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,EAEL,WAAW,EACX,oBAAoB,EAErB,MAAM,iBAAiB,CAAC;AAIzB,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;IA0DI,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,CAAC;KACnB;IA2BK,eAAe,CAAC,EACpB,aAAa,EACb,WAAW,EACX,QAAoB,GACrB,EAAE;QACD,aAAa,EAAE,MAAM,CAAC;QACtB,WAAW,EAAE,oBAAoB,GAAG,WAAW,CAAC;QAChD,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,GAAG,OAAO,CAAC,oBAAoB,GAAG,WAAW,CAAC;IAgD/C;;;;;;OAMG;IACG,gBAAgB,CAAC,EACrB,cAAc,EACd,gBAAgB,EAChB,QAAoB,GACrB,EAAE;QACD,cAAc,EAAE,MAAM,CAAC;QACvB,gBAAgB,EAAE,WAAW,CAAC;QAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB;IAwBD;;;;;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;IA6DI,aAAa;CAOpB"}
@@ -0,0 +1,24 @@
1
+ import { PublicKey, Transaction, 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 sendTransaction({ signedTransaction, rpcUrl, }: {
21
+ signedTransaction: Uint8Array;
22
+ rpcUrl?: string;
23
+ }): Promise<string>;
24
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
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,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,mBAIA;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,wBAAsB,eAAe,CAAC,EACpC,iBAAiB,EACjB,MAAwC,GACzC,EAAE;IACD,iBAAiB,EAAE,UAAU,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,mBAMA"}