@dynamic-labs-wallet/svm 0.0.0-beta-191.1

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,295 @@
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
+ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
19
+ /**
20
+ * Creates a wallet account on the Solana chain
21
+ *
22
+ * @param thresholdSignatureScheme The threshold signature scheme to use
23
+ * @returns The account address, public key hex, raw public key, and client key shares
24
+ */ async createWalletAccount({ thresholdSignatureScheme, password = undefined, signedSessionId }) {
25
+ try {
26
+ let ceremonyCeremonyCompleteResolver;
27
+ const ceremonyCompletePromise = new Promise((resolve)=>{
28
+ ceremonyCeremonyCompleteResolver = resolve;
29
+ });
30
+ const { rawPublicKey, clientKeyShares } = await this.keyGen({
31
+ chainName: this.chainName,
32
+ thresholdSignatureScheme,
33
+ onCeremonyComplete: (accountAddress, walletId)=>{
34
+ // update wallet map
35
+ this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress] || {}, {
36
+ accountAddress,
37
+ walletId,
38
+ chainName: this.chainName,
39
+ thresholdSignatureScheme,
40
+ clientKeySharesBackupInfo: browser.getClientKeyShareBackupInfo()
41
+ });
42
+ this.logger.debug('walletMap updated for wallet', {
43
+ context: {
44
+ accountAddress,
45
+ walletId,
46
+ walletMap: this.walletMap
47
+ }
48
+ });
49
+ ceremonyCeremonyCompleteResolver(undefined);
50
+ }
51
+ });
52
+ // Wait for the ceremony to complete before proceeding
53
+ await ceremonyCompletePromise;
54
+ if (!rawPublicKey || !(rawPublicKey instanceof Uint8Array || typeof rawPublicKey === 'string')) {
55
+ throw new Error('Raw public key is not a Uint8Array or string' + typeof rawPublicKey);
56
+ }
57
+ if (!clientKeyShares) {
58
+ throw new Error(browser.ERROR_KEYGEN_FAILED);
59
+ }
60
+ const { accountAddress } = await this.deriveAccountAddress(rawPublicKey);
61
+ // Update client key shares in wallet map
62
+ await this.setClientKeySharesToLocalStorage({
63
+ accountAddress,
64
+ clientKeyShares,
65
+ overwriteOrMerge: 'overwrite'
66
+ });
67
+ await this.storeEncryptedBackupByWalletWithRetry({
68
+ accountAddress,
69
+ clientKeyShares,
70
+ password,
71
+ signedSessionId
72
+ });
73
+ return {
74
+ accountAddress,
75
+ rawPublicKey
76
+ };
77
+ } catch (error) {
78
+ this.logger.error(browser.ERROR_CREATE_WALLET_ACCOUNT, error);
79
+ throw new Error(browser.ERROR_CREATE_WALLET_ACCOUNT);
80
+ }
81
+ }
82
+ async deriveAccountAddress(rawPublicKey) {
83
+ const pubKeyBytes = typeof rawPublicKey === 'string' ? Buffer.from(rawPublicKey, 'hex') : rawPublicKey;
84
+ const accountAddress = bs58.encode(pubKeyBytes);
85
+ return {
86
+ accountAddress
87
+ };
88
+ }
89
+ /**
90
+ * This function takes a message and returns it after being signed with MPC
91
+ *
92
+ * @param message The message to sign (Uint8Array)
93
+ * @param accountAddress Solana address (base58 encoded)
94
+ * @param password The password for encrypted backup shares
95
+ */ async signMessage({ message, accountAddress, password = undefined, signedSessionId }) {
96
+ await this.verifyPassword({
97
+ accountAddress,
98
+ password,
99
+ walletOperation: browser.WalletOperation.SIGN_MESSAGE,
100
+ signedSessionId
101
+ });
102
+ if (!accountAddress) {
103
+ throw new Error(browser.ERROR_ACCOUNT_ADDRESS_REQUIRED);
104
+ }
105
+ try {
106
+ const signatureEd25519 = await this.sign({
107
+ message,
108
+ accountAddress: accountAddress,
109
+ chainName: this.chainName,
110
+ password,
111
+ signedSessionId
112
+ });
113
+ const base58Signature = bs58.encode(signatureEd25519);
114
+ return base58Signature;
115
+ } catch (error) {
116
+ this.logger.error(browser.ERROR_SIGN_MESSAGE, error);
117
+ throw new Error(browser.ERROR_SIGN_MESSAGE);
118
+ }
119
+ }
120
+ async signTransaction({ senderAddress, transaction, password = undefined, signedSessionId }) {
121
+ await this.verifyPassword({
122
+ accountAddress: senderAddress,
123
+ password,
124
+ walletOperation: browser.WalletOperation.SIGN_TRANSACTION,
125
+ signedSessionId
126
+ });
127
+ try {
128
+ const signatureEd25519 = await this.sign({
129
+ message: transaction,
130
+ accountAddress: senderAddress,
131
+ chainName: this.chainName,
132
+ password,
133
+ signedSessionId
134
+ });
135
+ if (!signatureEd25519) {
136
+ throw new Error('Signature is undefined');
137
+ }
138
+ return Buffer.from(signatureEd25519).toString('hex');
139
+ } catch (error) {
140
+ this.logger.error('Error in signTransaction:', error);
141
+ if (error instanceof Error) {
142
+ this.logger.error('Error details:', error);
143
+ }
144
+ throw error;
145
+ }
146
+ }
147
+ /**
148
+ * Exports the private key for a given account address
149
+ *
150
+ * @param accountAddress The account address to export the private key for
151
+ * @param password The password for encrypted backup shares
152
+ * @returns The private key
153
+ */ async exportPrivateKey({ accountAddress, password = undefined, signedSessionId }) {
154
+ await this.verifyPassword({
155
+ accountAddress,
156
+ password,
157
+ walletOperation: browser.WalletOperation.EXPORT_PRIVATE_KEY,
158
+ signedSessionId
159
+ });
160
+ const { derivedPrivateKey } = await this.exportKey({
161
+ accountAddress,
162
+ chainName: this.chainName,
163
+ password,
164
+ signedSessionId
165
+ });
166
+ if (!derivedPrivateKey) {
167
+ throw new Error('Derived private key is undefined');
168
+ }
169
+ return derivedPrivateKey;
170
+ }
171
+ /**
172
+ * Exports the private key for a given account address
173
+ *
174
+ * @param keyShares The key shares to export the private key for
175
+ * @returns The private key
176
+ */ async offlineExportPrivateKey({ keyShares, derivationPath }) {
177
+ const { derivedPrivateKey } = await this.offlineExportKey({
178
+ chainName: this.chainName,
179
+ keyShares,
180
+ derivationPath
181
+ });
182
+ return {
183
+ derivedPrivateKey
184
+ };
185
+ }
186
+ /**
187
+ * Converts the private key to a hex string
188
+ *
189
+ * @param privateKey The private key to convert
190
+ * @returns The hex string
191
+ */ decodePrivateKeyForSolana(privateKey) {
192
+ const decoded = bs58.decode(privateKey);
193
+ const slicedBytes = decoded.slice(0, 32);
194
+ return Buffer.from(slicedBytes).toString('hex');
195
+ }
196
+ getPublicKeyFromPrivateKey(privateKey) {
197
+ const privateKeyBytes = bs58.decode(privateKey);
198
+ const keypair = web3_js.Keypair.fromSecretKey(privateKeyBytes);
199
+ const publicKeyBase58 = keypair.publicKey.toBase58();
200
+ return publicKeyBase58;
201
+ }
202
+ encodePublicKey(publicKey) {
203
+ return bs58.encode(publicKey);
204
+ }
205
+ /**
206
+ * Imports the private key for a given account address
207
+ *
208
+ * @param privateKey The private key to import
209
+ * @param chainName The chain name to import the private key for
210
+ * @param thresholdSignatureScheme The threshold signature scheme to use
211
+ * @param password The password for encrypted backup shares
212
+ * @returns The account address, raw public key, and client key shares
213
+ */ async importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password = undefined, onError, signedSessionId }) {
214
+ try {
215
+ let ceremonyCeremonyCompleteResolver;
216
+ const ceremonyCompletePromise = new Promise((resolve)=>{
217
+ ceremonyCeremonyCompleteResolver = resolve;
218
+ });
219
+ //get public key from private key
220
+ const publicKey = this.getPublicKeyFromPrivateKey(privateKey);
221
+ const formattedPrivateKey = this.decodePrivateKeyForSolana(privateKey);
222
+ const { rawPublicKey, clientKeyShares } = await this.importRawPrivateKey({
223
+ chainName,
224
+ privateKey: formattedPrivateKey,
225
+ thresholdSignatureScheme,
226
+ onError: (error)=>{
227
+ this.logger.error(browser.ERROR_IMPORT_PRIVATE_KEY, error);
228
+ onError == null ? void 0 : onError(error);
229
+ },
230
+ onCeremonyComplete: (accountAddress, walletId)=>{
231
+ // update wallet map
232
+ this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress] || {}, {
233
+ accountAddress,
234
+ walletId,
235
+ chainName: this.chainName,
236
+ thresholdSignatureScheme,
237
+ clientKeySharesBackupInfo: browser.getClientKeyShareBackupInfo()
238
+ });
239
+ this.logger.debug('walletMap updated for wallet', {
240
+ context: {
241
+ accountAddress,
242
+ walletId,
243
+ walletMap: this.walletMap
244
+ }
245
+ });
246
+ ceremonyCeremonyCompleteResolver(undefined);
247
+ }
248
+ });
249
+ // Wait for the ceremony to complete before proceeding
250
+ await ceremonyCompletePromise;
251
+ if (!rawPublicKey || !clientKeyShares) {
252
+ throw new Error(browser.ERROR_IMPORT_PRIVATE_KEY);
253
+ }
254
+ const { accountAddress } = await this.deriveAccountAddress(rawPublicKey);
255
+ if (accountAddress !== publicKey) {
256
+ throw new Error(`Public key mismatch: derived address ${accountAddress} !== public key ${publicKey}`);
257
+ }
258
+ // Update client key shares in wallet map
259
+ await this.setClientKeySharesToLocalStorage({
260
+ accountAddress,
261
+ clientKeyShares,
262
+ overwriteOrMerge: 'overwrite'
263
+ });
264
+ await this.storeEncryptedBackupByWalletWithRetry({
265
+ accountAddress,
266
+ clientKeyShares,
267
+ password,
268
+ signedSessionId
269
+ });
270
+ return {
271
+ accountAddress,
272
+ rawPublicKey: rawPublicKey
273
+ };
274
+ } catch (error) {
275
+ this.logger.error(browser.ERROR_IMPORT_PRIVATE_KEY, error);
276
+ throw new Error(browser.ERROR_IMPORT_PRIVATE_KEY);
277
+ }
278
+ }
279
+ async getSvmWallets() {
280
+ const wallets = await this.getWallets();
281
+ const svmWallets = wallets.filter((wallet)=>wallet.chainName === 'solana');
282
+ return svmWallets;
283
+ }
284
+ constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, baseClientRelayApiUrl }){
285
+ super({
286
+ environmentId,
287
+ authToken,
288
+ baseApiUrl,
289
+ baseMPCRelayApiUrl,
290
+ baseClientRelayApiUrl
291
+ }), this.chainName = 'SVM';
292
+ }
293
+ }
294
+
295
+ 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,293 @@
1
+ import { DynamicWalletClient, getClientKeyShareBackupInfo, ERROR_KEYGEN_FAILED, ERROR_CREATE_WALLET_ACCOUNT, WalletOperation, ERROR_ACCOUNT_ADDRESS_REQUIRED, ERROR_SIGN_MESSAGE, ERROR_IMPORT_PRIVATE_KEY } from '@dynamic-labs-wallet/browser';
2
+ import bs58 from 'bs58';
3
+ import { 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
+ class DynamicSvmWalletClient extends DynamicWalletClient {
17
+ /**
18
+ * Creates a wallet account on the Solana chain
19
+ *
20
+ * @param thresholdSignatureScheme The threshold signature scheme to use
21
+ * @returns The account address, public key hex, raw public key, and client key shares
22
+ */ async createWalletAccount({ thresholdSignatureScheme, password = undefined, signedSessionId }) {
23
+ try {
24
+ let ceremonyCeremonyCompleteResolver;
25
+ const ceremonyCompletePromise = new Promise((resolve)=>{
26
+ ceremonyCeremonyCompleteResolver = resolve;
27
+ });
28
+ const { rawPublicKey, clientKeyShares } = await this.keyGen({
29
+ chainName: this.chainName,
30
+ thresholdSignatureScheme,
31
+ onCeremonyComplete: (accountAddress, walletId)=>{
32
+ // update wallet map
33
+ this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress] || {}, {
34
+ accountAddress,
35
+ walletId,
36
+ chainName: this.chainName,
37
+ thresholdSignatureScheme,
38
+ clientKeySharesBackupInfo: getClientKeyShareBackupInfo()
39
+ });
40
+ this.logger.debug('walletMap updated for wallet', {
41
+ context: {
42
+ accountAddress,
43
+ walletId,
44
+ walletMap: this.walletMap
45
+ }
46
+ });
47
+ ceremonyCeremonyCompleteResolver(undefined);
48
+ }
49
+ });
50
+ // Wait for the ceremony to complete before proceeding
51
+ await ceremonyCompletePromise;
52
+ if (!rawPublicKey || !(rawPublicKey instanceof Uint8Array || typeof rawPublicKey === 'string')) {
53
+ throw new Error('Raw public key is not a Uint8Array or string' + typeof rawPublicKey);
54
+ }
55
+ if (!clientKeyShares) {
56
+ throw new Error(ERROR_KEYGEN_FAILED);
57
+ }
58
+ const { accountAddress } = await this.deriveAccountAddress(rawPublicKey);
59
+ // Update client key shares in wallet map
60
+ await this.setClientKeySharesToLocalStorage({
61
+ accountAddress,
62
+ clientKeyShares,
63
+ overwriteOrMerge: 'overwrite'
64
+ });
65
+ await this.storeEncryptedBackupByWalletWithRetry({
66
+ accountAddress,
67
+ clientKeyShares,
68
+ password,
69
+ signedSessionId
70
+ });
71
+ return {
72
+ accountAddress,
73
+ rawPublicKey
74
+ };
75
+ } catch (error) {
76
+ this.logger.error(ERROR_CREATE_WALLET_ACCOUNT, error);
77
+ throw new Error(ERROR_CREATE_WALLET_ACCOUNT);
78
+ }
79
+ }
80
+ async deriveAccountAddress(rawPublicKey) {
81
+ const pubKeyBytes = typeof rawPublicKey === 'string' ? Buffer.from(rawPublicKey, 'hex') : rawPublicKey;
82
+ const accountAddress = bs58.encode(pubKeyBytes);
83
+ return {
84
+ accountAddress
85
+ };
86
+ }
87
+ /**
88
+ * This function takes a message and returns it after being signed with MPC
89
+ *
90
+ * @param message The message to sign (Uint8Array)
91
+ * @param accountAddress Solana address (base58 encoded)
92
+ * @param password The password for encrypted backup shares
93
+ */ async signMessage({ message, accountAddress, password = undefined, signedSessionId }) {
94
+ await this.verifyPassword({
95
+ accountAddress,
96
+ password,
97
+ walletOperation: WalletOperation.SIGN_MESSAGE,
98
+ signedSessionId
99
+ });
100
+ if (!accountAddress) {
101
+ throw new Error(ERROR_ACCOUNT_ADDRESS_REQUIRED);
102
+ }
103
+ try {
104
+ const signatureEd25519 = await this.sign({
105
+ message,
106
+ accountAddress: accountAddress,
107
+ chainName: this.chainName,
108
+ password,
109
+ signedSessionId
110
+ });
111
+ const base58Signature = bs58.encode(signatureEd25519);
112
+ return base58Signature;
113
+ } catch (error) {
114
+ this.logger.error(ERROR_SIGN_MESSAGE, error);
115
+ throw new Error(ERROR_SIGN_MESSAGE);
116
+ }
117
+ }
118
+ async signTransaction({ senderAddress, transaction, password = undefined, signedSessionId }) {
119
+ await this.verifyPassword({
120
+ accountAddress: senderAddress,
121
+ password,
122
+ walletOperation: WalletOperation.SIGN_TRANSACTION,
123
+ signedSessionId
124
+ });
125
+ try {
126
+ const signatureEd25519 = await this.sign({
127
+ message: transaction,
128
+ accountAddress: senderAddress,
129
+ chainName: this.chainName,
130
+ password,
131
+ signedSessionId
132
+ });
133
+ if (!signatureEd25519) {
134
+ throw new Error('Signature is undefined');
135
+ }
136
+ return Buffer.from(signatureEd25519).toString('hex');
137
+ } catch (error) {
138
+ this.logger.error('Error in signTransaction:', error);
139
+ if (error instanceof Error) {
140
+ this.logger.error('Error details:', error);
141
+ }
142
+ throw error;
143
+ }
144
+ }
145
+ /**
146
+ * Exports the private key for a given account address
147
+ *
148
+ * @param accountAddress The account address to export the private key for
149
+ * @param password The password for encrypted backup shares
150
+ * @returns The private key
151
+ */ async exportPrivateKey({ accountAddress, password = undefined, signedSessionId }) {
152
+ await this.verifyPassword({
153
+ accountAddress,
154
+ password,
155
+ walletOperation: WalletOperation.EXPORT_PRIVATE_KEY,
156
+ signedSessionId
157
+ });
158
+ const { derivedPrivateKey } = await this.exportKey({
159
+ accountAddress,
160
+ chainName: this.chainName,
161
+ password,
162
+ signedSessionId
163
+ });
164
+ if (!derivedPrivateKey) {
165
+ throw new Error('Derived private key is undefined');
166
+ }
167
+ return derivedPrivateKey;
168
+ }
169
+ /**
170
+ * Exports the private key for a given account address
171
+ *
172
+ * @param keyShares The key shares to export the private key for
173
+ * @returns The private key
174
+ */ async offlineExportPrivateKey({ keyShares, derivationPath }) {
175
+ const { derivedPrivateKey } = await this.offlineExportKey({
176
+ chainName: this.chainName,
177
+ keyShares,
178
+ derivationPath
179
+ });
180
+ return {
181
+ derivedPrivateKey
182
+ };
183
+ }
184
+ /**
185
+ * Converts the private key to a hex string
186
+ *
187
+ * @param privateKey The private key to convert
188
+ * @returns The hex string
189
+ */ decodePrivateKeyForSolana(privateKey) {
190
+ const decoded = bs58.decode(privateKey);
191
+ const slicedBytes = decoded.slice(0, 32);
192
+ return Buffer.from(slicedBytes).toString('hex');
193
+ }
194
+ getPublicKeyFromPrivateKey(privateKey) {
195
+ const privateKeyBytes = bs58.decode(privateKey);
196
+ const keypair = Keypair.fromSecretKey(privateKeyBytes);
197
+ const publicKeyBase58 = keypair.publicKey.toBase58();
198
+ return publicKeyBase58;
199
+ }
200
+ encodePublicKey(publicKey) {
201
+ return bs58.encode(publicKey);
202
+ }
203
+ /**
204
+ * Imports the private key for a given account address
205
+ *
206
+ * @param privateKey The private key to import
207
+ * @param chainName The chain name to import the private key for
208
+ * @param thresholdSignatureScheme The threshold signature scheme to use
209
+ * @param password The password for encrypted backup shares
210
+ * @returns The account address, raw public key, and client key shares
211
+ */ async importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password = undefined, onError, signedSessionId }) {
212
+ try {
213
+ let ceremonyCeremonyCompleteResolver;
214
+ const ceremonyCompletePromise = new Promise((resolve)=>{
215
+ ceremonyCeremonyCompleteResolver = resolve;
216
+ });
217
+ //get public key from private key
218
+ const publicKey = this.getPublicKeyFromPrivateKey(privateKey);
219
+ const formattedPrivateKey = this.decodePrivateKeyForSolana(privateKey);
220
+ const { rawPublicKey, clientKeyShares } = await this.importRawPrivateKey({
221
+ chainName,
222
+ privateKey: formattedPrivateKey,
223
+ thresholdSignatureScheme,
224
+ onError: (error)=>{
225
+ this.logger.error(ERROR_IMPORT_PRIVATE_KEY, error);
226
+ onError == null ? void 0 : onError(error);
227
+ },
228
+ onCeremonyComplete: (accountAddress, walletId)=>{
229
+ // update wallet map
230
+ this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress] || {}, {
231
+ accountAddress,
232
+ walletId,
233
+ chainName: this.chainName,
234
+ thresholdSignatureScheme,
235
+ clientKeySharesBackupInfo: getClientKeyShareBackupInfo()
236
+ });
237
+ this.logger.debug('walletMap updated for wallet', {
238
+ context: {
239
+ accountAddress,
240
+ walletId,
241
+ walletMap: this.walletMap
242
+ }
243
+ });
244
+ ceremonyCeremonyCompleteResolver(undefined);
245
+ }
246
+ });
247
+ // Wait for the ceremony to complete before proceeding
248
+ await ceremonyCompletePromise;
249
+ if (!rawPublicKey || !clientKeyShares) {
250
+ throw new Error(ERROR_IMPORT_PRIVATE_KEY);
251
+ }
252
+ const { accountAddress } = await this.deriveAccountAddress(rawPublicKey);
253
+ if (accountAddress !== publicKey) {
254
+ throw new Error(`Public key mismatch: derived address ${accountAddress} !== public key ${publicKey}`);
255
+ }
256
+ // Update client key shares in wallet map
257
+ await this.setClientKeySharesToLocalStorage({
258
+ accountAddress,
259
+ clientKeyShares,
260
+ overwriteOrMerge: 'overwrite'
261
+ });
262
+ await this.storeEncryptedBackupByWalletWithRetry({
263
+ accountAddress,
264
+ clientKeyShares,
265
+ password,
266
+ signedSessionId
267
+ });
268
+ return {
269
+ accountAddress,
270
+ rawPublicKey: rawPublicKey
271
+ };
272
+ } catch (error) {
273
+ this.logger.error(ERROR_IMPORT_PRIVATE_KEY, error);
274
+ throw new Error(ERROR_IMPORT_PRIVATE_KEY);
275
+ }
276
+ }
277
+ async getSvmWallets() {
278
+ const wallets = await this.getWallets();
279
+ const svmWallets = wallets.filter((wallet)=>wallet.chainName === 'solana');
280
+ return svmWallets;
281
+ }
282
+ constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, baseClientRelayApiUrl }){
283
+ super({
284
+ environmentId,
285
+ authToken,
286
+ baseApiUrl,
287
+ baseMPCRelayApiUrl,
288
+ baseClientRelayApiUrl
289
+ }), this.chainName = 'SVM';
290
+ }
291
+ }
292
+
293
+ export { DynamicSvmWalletClient };
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@dynamic-labs-wallet/svm",
3
+ "version": "0.0.0-beta-191.1",
4
+ "license": "MIT",
5
+ "dependencies": {
6
+ "@dynamic-labs-wallet/browser": "0.0.0-beta-191.1",
7
+ "@solana/web3.js": "^1.98.2",
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
+ "main": "./index.cjs.js",
19
+ "module": "./index.esm.js",
20
+ "types": "./index.esm.d.ts",
21
+ "exports": {
22
+ "./package.json": "./package.json",
23
+ ".": {
24
+ "types": "./index.esm.d.ts",
25
+ "import": "./index.esm.js",
26
+ "require": "./index.cjs.js",
27
+ "default": "./index.cjs.js"
28
+ }
29
+ }
30
+ }
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,103 @@
1
+ import { DynamicWalletClient, Ed25519KeygenResult, ThresholdSignatureScheme } from '@dynamic-labs-wallet/browser';
2
+ export declare class DynamicSvmWalletClient extends DynamicWalletClient {
3
+ readonly chainName = "SVM";
4
+ accountAddress?: string;
5
+ constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, baseClientRelayApiUrl, }: {
6
+ environmentId: string;
7
+ authToken: string;
8
+ baseApiUrl?: string;
9
+ baseMPCRelayApiUrl?: string;
10
+ baseClientRelayApiUrl?: 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, signedSessionId, }: {
19
+ thresholdSignatureScheme: ThresholdSignatureScheme;
20
+ password?: string;
21
+ signedSessionId?: string;
22
+ }): Promise<{
23
+ accountAddress: string;
24
+ rawPublicKey: Uint8Array | string;
25
+ }>;
26
+ deriveAccountAddress(rawPublicKey: string | 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, signedSessionId, }: {
37
+ message: string;
38
+ accountAddress: string;
39
+ password?: string;
40
+ signedSessionId?: string;
41
+ }): Promise<string>;
42
+ signTransaction({ senderAddress, transaction, password, signedSessionId, }: {
43
+ senderAddress: string;
44
+ transaction: string;
45
+ password?: string;
46
+ signedSessionId?: string;
47
+ }): Promise<string>;
48
+ /**
49
+ * Exports the private key for a given account address
50
+ *
51
+ * @param accountAddress The account address to export the private key for
52
+ * @param password The password for encrypted backup shares
53
+ * @returns The private key
54
+ */
55
+ exportPrivateKey({ accountAddress, password, signedSessionId, }: {
56
+ accountAddress: string;
57
+ password?: string;
58
+ signedSessionId?: string;
59
+ }): Promise<string>;
60
+ /**
61
+ * Exports the private key for a given account address
62
+ *
63
+ * @param keyShares The key shares to export the private key for
64
+ * @returns The private key
65
+ */
66
+ offlineExportPrivateKey({ keyShares, derivationPath, }: {
67
+ keyShares: Ed25519KeygenResult[];
68
+ derivationPath?: string;
69
+ }): Promise<{
70
+ derivedPrivateKey: string | undefined;
71
+ }>;
72
+ /**
73
+ * Converts the private key to a hex string
74
+ *
75
+ * @param privateKey The private key to convert
76
+ * @returns The hex string
77
+ */
78
+ decodePrivateKeyForSolana(privateKey: string): string;
79
+ getPublicKeyFromPrivateKey(privateKey: string): string;
80
+ encodePublicKey(publicKey: Uint8Array): string;
81
+ /**
82
+ * Imports the private key for a given account address
83
+ *
84
+ * @param privateKey The private key to import
85
+ * @param chainName The chain name to import the private key for
86
+ * @param thresholdSignatureScheme The threshold signature scheme to use
87
+ * @param password The password for encrypted backup shares
88
+ * @returns The account address, raw public key, and client key shares
89
+ */
90
+ importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password, onError, signedSessionId, }: {
91
+ privateKey: string;
92
+ chainName: string;
93
+ thresholdSignatureScheme: ThresholdSignatureScheme;
94
+ password?: string;
95
+ onError?: (error: Error) => void;
96
+ signedSessionId?: string;
97
+ }): Promise<{
98
+ accountAddress: string;
99
+ rawPublicKey: Uint8Array | undefined;
100
+ }>;
101
+ getSvmWallets(): Promise<any>;
102
+ }
103
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/svm/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,wBAAwB,EAQzB,MAAM,8BAA8B,CAAC;AAItC,qBAAa,sBAAuB,SAAQ,mBAAmB;IAC7D,QAAQ,CAAC,SAAS,SAAS;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;gBAEZ,EACV,aAAa,EACb,SAAS,EACT,UAAU,EACV,kBAAkB,EAClB,qBAAqB,GACtB,EAAE;QACD,aAAa,EAAE,MAAM,CAAC;QACtB,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,kBAAkB,CAAC,EAAE,MAAM,CAAC;QAC5B,qBAAqB,CAAC,EAAE,MAAM,CAAC;KAChC;IAUD;;;;;OAKG;IACG,mBAAmB,CAAC,EACxB,wBAAwB,EACxB,QAAoB,EACpB,eAAe,GAChB,EAAE;QACD,wBAAwB,EAAE,wBAAwB,CAAC;QACnD,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B,GAAG,OAAO,CAAC;QACV,cAAc,EAAE,MAAM,CAAC;QACvB,YAAY,EAAE,UAAU,GAAG,MAAM,CAAC;KACnC,CAAC;IA2EI,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,UAAU;;;IAY5D;;;;;;OAMG;IACG,WAAW,CAAC,EAChB,OAAO,EACP,cAAc,EACd,QAAoB,EACpB,eAAe,GAChB,EAAE;QACD,OAAO,EAAE,MAAM,CAAC;QAChB,cAAc,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B;IA6BK,eAAe,CAAC,EACpB,aAAa,EACb,WAAW,EACX,QAAoB,EACpB,eAAe,GAChB,EAAE;QACD,aAAa,EAAE,MAAM,CAAC;QACtB,WAAW,EAAE,MAAM,CAAC;QACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B,GAAG,OAAO,CAAC,MAAM,CAAC;IA+BnB;;;;;;OAMG;IACG,gBAAgB,CAAC,EACrB,cAAc,EACd,QAAoB,EACpB,eAAe,GAChB,EAAE;QACD,cAAc,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B,GAAG,OAAO,CAAC,MAAM,CAAC;IAqBnB;;;;;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,EACP,eAAe,GAChB,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;QACjC,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B,GAAG,OAAO,CAAC;QACV,cAAc,EAAE,MAAM,CAAC;QACvB,YAAY,EAAE,UAAU,GAAG,SAAS,CAAC;KACtC,CAAC;IAgFI,aAAa;CAOpB"}
@@ -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 './client';
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,UAAU,CAAC"}
@@ -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"}