@dynamic-labs-wallet/svm 0.0.0-preview.57 → 0.0.1-paolo-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.js +167 -109
- package/index.esm.js +166 -108
- package/package.json +7 -6
- package/src/index.d.ts +1 -1
- package/src/index.d.ts.map +1 -1
- package/src/svm/{svm.d.ts → client.d.ts} +33 -23
- package/src/svm/client.d.ts.map +1 -0
- package/src/svm/index.d.ts +1 -1
- package/src/svm/index.d.ts.map +1 -1
- package/src/svm/utils.d.ts +1 -1
- package/src/svm/utils.d.ts.map +1 -1
- package/src/svm/svm.d.ts.map +0 -1
package/index.cjs.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var browser = require('@dynamic-labs-wallet/browser');
|
|
4
|
-
var bs58 = require('bs58');
|
|
5
4
|
var web3_js = require('@solana/web3.js');
|
|
5
|
+
var bs58 = require('bs58');
|
|
6
6
|
|
|
7
7
|
function _extends() {
|
|
8
8
|
_extends = Object.assign || function assign(target) {
|
|
@@ -15,21 +15,18 @@ function _extends() {
|
|
|
15
15
|
return _extends.apply(this, arguments);
|
|
16
16
|
}
|
|
17
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
18
|
class DynamicSvmWalletClient extends browser.DynamicWalletClient {
|
|
26
19
|
/**
|
|
27
20
|
* Creates a wallet account on the Solana chain
|
|
28
21
|
*
|
|
29
22
|
* @param thresholdSignatureScheme The threshold signature scheme to use
|
|
30
23
|
* @returns The account address, public key hex, raw public key, and client key shares
|
|
31
|
-
*/ async createWalletAccount({ thresholdSignatureScheme, password = undefined }) {
|
|
24
|
+
*/ async createWalletAccount({ thresholdSignatureScheme, password = undefined, signedSessionId, traceContext }) {
|
|
32
25
|
try {
|
|
26
|
+
let ceremonyCeremonyCompleteResolver;
|
|
27
|
+
const ceremonyCompletePromise = new Promise((resolve)=>{
|
|
28
|
+
ceremonyCeremonyCompleteResolver = resolve;
|
|
29
|
+
});
|
|
33
30
|
const { rawPublicKey, clientKeyShares } = await this.keyGen({
|
|
34
31
|
chainName: this.chainName,
|
|
35
32
|
thresholdSignatureScheme,
|
|
@@ -42,42 +39,49 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
|
|
|
42
39
|
thresholdSignatureScheme,
|
|
43
40
|
clientKeySharesBackupInfo: browser.getClientKeyShareBackupInfo()
|
|
44
41
|
});
|
|
42
|
+
this.logger.debug('walletMap updated for wallet', _extends({
|
|
43
|
+
context: {
|
|
44
|
+
accountAddress,
|
|
45
|
+
walletId,
|
|
46
|
+
walletMap: this.walletMap
|
|
47
|
+
}
|
|
48
|
+
}, this.getTraceContext(traceContext)));
|
|
49
|
+
ceremonyCeremonyCompleteResolver(undefined);
|
|
45
50
|
}
|
|
46
51
|
});
|
|
47
|
-
|
|
48
|
-
|
|
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);
|
|
49
56
|
}
|
|
50
57
|
if (!clientKeyShares) {
|
|
51
|
-
throw new Error(
|
|
58
|
+
throw new Error(browser.ERROR_KEYGEN_FAILED);
|
|
52
59
|
}
|
|
53
60
|
const { accountAddress } = await this.deriveAccountAddress(rawPublicKey);
|
|
54
61
|
// 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
62
|
await this.setClientKeySharesToLocalStorage({
|
|
58
63
|
accountAddress,
|
|
59
64
|
clientKeyShares,
|
|
60
65
|
overwriteOrMerge: 'overwrite'
|
|
61
66
|
});
|
|
62
|
-
|
|
63
|
-
void this.storeEncryptedBackupByWalletWithRetry({
|
|
67
|
+
await this.storeEncryptedBackupByWalletWithRetry({
|
|
64
68
|
accountAddress,
|
|
65
69
|
clientKeyShares,
|
|
66
|
-
password
|
|
70
|
+
password,
|
|
71
|
+
signedSessionId
|
|
67
72
|
});
|
|
68
73
|
return {
|
|
69
74
|
accountAddress,
|
|
70
|
-
rawPublicKey
|
|
71
|
-
clientKeyShares
|
|
75
|
+
rawPublicKey
|
|
72
76
|
};
|
|
73
77
|
} catch (error) {
|
|
74
|
-
this.logger.error(ERROR_CREATE_WALLET_ACCOUNT, error);
|
|
75
|
-
throw new Error(ERROR_CREATE_WALLET_ACCOUNT);
|
|
78
|
+
this.logger.error(browser.ERROR_CREATE_WALLET_ACCOUNT, error);
|
|
79
|
+
throw new Error(browser.ERROR_CREATE_WALLET_ACCOUNT);
|
|
76
80
|
}
|
|
77
81
|
}
|
|
78
|
-
// Function to properly derive account address
|
|
79
82
|
async deriveAccountAddress(rawPublicKey) {
|
|
80
|
-
const
|
|
83
|
+
const pubKeyBytes = typeof rawPublicKey === 'string' ? new Uint8Array(Buffer.from(rawPublicKey, 'hex')) : rawPublicKey;
|
|
84
|
+
const accountAddress = bs58.encode(pubKeyBytes);
|
|
81
85
|
return {
|
|
82
86
|
accountAddress
|
|
83
87
|
};
|
|
@@ -88,62 +92,64 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
|
|
|
88
92
|
* @param message The message to sign (Uint8Array)
|
|
89
93
|
* @param accountAddress Solana address (base58 encoded)
|
|
90
94
|
* @param password The password for encrypted backup shares
|
|
91
|
-
*/ async signMessage({ message, accountAddress, password = undefined }) {
|
|
95
|
+
*/ async signMessage({ message, accountAddress, password = undefined, signedSessionId, mfaToken, onError, traceContext }) {
|
|
92
96
|
await this.verifyPassword({
|
|
93
97
|
accountAddress,
|
|
94
98
|
password,
|
|
95
|
-
walletOperation: browser.WalletOperation.SIGN_MESSAGE
|
|
99
|
+
walletOperation: browser.WalletOperation.SIGN_MESSAGE,
|
|
100
|
+
signedSessionId
|
|
96
101
|
});
|
|
97
102
|
if (!accountAddress) {
|
|
98
|
-
throw new Error(
|
|
103
|
+
throw new Error(browser.ERROR_ACCOUNT_ADDRESS_REQUIRED);
|
|
99
104
|
}
|
|
100
105
|
try {
|
|
101
106
|
const signatureEd25519 = await this.sign({
|
|
102
107
|
message,
|
|
103
108
|
accountAddress: accountAddress,
|
|
104
109
|
chainName: this.chainName,
|
|
105
|
-
password
|
|
110
|
+
password,
|
|
111
|
+
signedSessionId,
|
|
112
|
+
mfaToken,
|
|
113
|
+
context: {
|
|
114
|
+
svmMessage: message
|
|
115
|
+
},
|
|
116
|
+
onError,
|
|
117
|
+
traceContext
|
|
106
118
|
});
|
|
107
119
|
const base58Signature = bs58.encode(signatureEd25519);
|
|
108
120
|
return base58Signature;
|
|
109
121
|
} catch (error) {
|
|
110
|
-
this.logger.error(
|
|
111
|
-
throw
|
|
122
|
+
this.logger.error(browser.ERROR_SIGN_MESSAGE, error);
|
|
123
|
+
throw new Error(browser.ERROR_SIGN_MESSAGE);
|
|
112
124
|
}
|
|
113
125
|
}
|
|
114
|
-
async signTransaction({ senderAddress, transaction, password = undefined }) {
|
|
126
|
+
async signTransaction({ senderAddress, transaction, password = undefined, signedSessionId, mfaToken, chainId, context, onError, traceContext }) {
|
|
115
127
|
await this.verifyPassword({
|
|
116
128
|
accountAddress: senderAddress,
|
|
117
129
|
password,
|
|
118
|
-
walletOperation: browser.WalletOperation.SIGN_TRANSACTION
|
|
130
|
+
walletOperation: browser.WalletOperation.SIGN_TRANSACTION,
|
|
131
|
+
signedSessionId
|
|
119
132
|
});
|
|
120
133
|
try {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const signatureEd25519 = await this.sign({
|
|
132
|
-
message: messageToSign,
|
|
133
|
-
accountAddress: senderAddress,
|
|
134
|
-
chainName: this.chainName,
|
|
135
|
-
password
|
|
134
|
+
const base58SerializedTransaction = this.prepareTransactionForSigning(transaction);
|
|
135
|
+
const signParams = this.buildSignParams({
|
|
136
|
+
transaction,
|
|
137
|
+
senderAddress,
|
|
138
|
+
password,
|
|
139
|
+
signedSessionId,
|
|
140
|
+
mfaToken,
|
|
141
|
+
chainId,
|
|
142
|
+
base58SerializedTransaction,
|
|
143
|
+
context
|
|
136
144
|
});
|
|
145
|
+
const signatureEd25519 = await this.sign(_extends({}, signParams, {
|
|
146
|
+
onError,
|
|
147
|
+
traceContext
|
|
148
|
+
}));
|
|
137
149
|
if (!signatureEd25519) {
|
|
138
150
|
throw new Error('Signature is undefined');
|
|
139
151
|
}
|
|
140
|
-
|
|
141
|
-
const signedTransaction = addSignatureToTransaction({
|
|
142
|
-
transaction,
|
|
143
|
-
signature: signatureEd25519,
|
|
144
|
-
signerPublicKey: senderPublicKey
|
|
145
|
-
});
|
|
146
|
-
return signedTransaction;
|
|
152
|
+
return Buffer.from(signatureEd25519).toString('hex');
|
|
147
153
|
} catch (error) {
|
|
148
154
|
this.logger.error('Error in signTransaction:', error);
|
|
149
155
|
if (error instanceof Error) {
|
|
@@ -152,33 +158,59 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
|
|
|
152
158
|
throw error;
|
|
153
159
|
}
|
|
154
160
|
}
|
|
161
|
+
prepareTransactionForSigning(transaction) {
|
|
162
|
+
const transactionBytes = new Uint8Array(Buffer.from(transaction, 'hex'));
|
|
163
|
+
const deserializedTransaction = web3_js.VersionedMessage.deserialize(transactionBytes);
|
|
164
|
+
const versionedTransaction = new web3_js.VersionedTransaction(deserializedTransaction);
|
|
165
|
+
const serializedTransaction = versionedTransaction.serialize();
|
|
166
|
+
return bs58.encode(serializedTransaction);
|
|
167
|
+
}
|
|
168
|
+
buildSignParams({ transaction, senderAddress, password, signedSessionId, mfaToken, chainId, base58SerializedTransaction, context }) {
|
|
169
|
+
const signParams = {
|
|
170
|
+
message: transaction,
|
|
171
|
+
accountAddress: senderAddress,
|
|
172
|
+
chainName: this.chainName,
|
|
173
|
+
password,
|
|
174
|
+
signedSessionId,
|
|
175
|
+
mfaToken
|
|
176
|
+
};
|
|
177
|
+
if (chainId !== undefined) {
|
|
178
|
+
signParams.context = _extends({}, context, {
|
|
179
|
+
svmTransaction: {
|
|
180
|
+
chainId,
|
|
181
|
+
method: 'signAndSendTransaction',
|
|
182
|
+
serializedTransactions: [
|
|
183
|
+
base58SerializedTransaction
|
|
184
|
+
]
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
return signParams;
|
|
189
|
+
}
|
|
155
190
|
/**
|
|
156
191
|
* Exports the private key for a given account address
|
|
157
192
|
*
|
|
158
193
|
* @param accountAddress The account address to export the private key for
|
|
159
194
|
* @param password The password for encrypted backup shares
|
|
160
195
|
* @returns The private key
|
|
161
|
-
*/ async exportPrivateKey({ accountAddress,
|
|
196
|
+
*/ async exportPrivateKey({ accountAddress, password = undefined, signedSessionId, mfaToken }) {
|
|
162
197
|
await this.verifyPassword({
|
|
163
198
|
accountAddress,
|
|
164
199
|
password,
|
|
165
|
-
walletOperation: browser.WalletOperation.EXPORT_PRIVATE_KEY
|
|
200
|
+
walletOperation: browser.WalletOperation.EXPORT_PRIVATE_KEY,
|
|
201
|
+
signedSessionId
|
|
166
202
|
});
|
|
167
203
|
const { derivedPrivateKey } = await this.exportKey({
|
|
168
204
|
accountAddress,
|
|
169
205
|
chainName: this.chainName,
|
|
170
206
|
password,
|
|
171
|
-
|
|
207
|
+
signedSessionId,
|
|
208
|
+
mfaToken
|
|
172
209
|
});
|
|
173
210
|
if (!derivedPrivateKey) {
|
|
174
211
|
throw new Error('Derived private key is undefined');
|
|
175
212
|
}
|
|
176
|
-
|
|
177
|
-
// Display the private key in the container via iframe
|
|
178
|
-
const { iframeDisplay } = await this.initializeIframeDisplayForContainer({
|
|
179
|
-
container: displayContainer
|
|
180
|
-
});
|
|
181
|
-
iframeDisplay.displayPrivateKey(accountAddress, encodedPrivateKey);
|
|
213
|
+
return derivedPrivateKey;
|
|
182
214
|
}
|
|
183
215
|
/**
|
|
184
216
|
* Exports the private key for a given account address
|
|
@@ -222,65 +254,91 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
|
|
|
222
254
|
* @param thresholdSignatureScheme The threshold signature scheme to use
|
|
223
255
|
* @param password The password for encrypted backup shares
|
|
224
256
|
* @returns The account address, raw public key, and client key shares
|
|
225
|
-
*/ async importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password = undefined, onError }) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
// update wallet map
|
|
236
|
-
this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress] || {}, {
|
|
237
|
-
accountAddress,
|
|
238
|
-
walletId,
|
|
239
|
-
chainName: this.chainName,
|
|
240
|
-
thresholdSignatureScheme,
|
|
241
|
-
clientKeySharesBackupInfo: browser.getClientKeyShareBackupInfo()
|
|
242
|
-
});
|
|
257
|
+
*/ async importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password = undefined, onError, signedSessionId, publicAddressCheck }) {
|
|
258
|
+
try {
|
|
259
|
+
let ceremonyCeremonyCompleteResolver;
|
|
260
|
+
const ceremonyCompletePromise = new Promise((resolve)=>{
|
|
261
|
+
ceremonyCeremonyCompleteResolver = resolve;
|
|
262
|
+
});
|
|
263
|
+
//get public key from private key
|
|
264
|
+
const publicKey = this.getPublicKeyFromPrivateKey(privateKey);
|
|
265
|
+
if (publicAddressCheck && publicKey !== publicAddressCheck) {
|
|
266
|
+
throw new Error(`Public address mismatch: derived address ${publicKey} !== public address ${publicAddressCheck}`);
|
|
243
267
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
268
|
+
const formattedPrivateKey = this.decodePrivateKeyForSolana(privateKey);
|
|
269
|
+
const { rawPublicKey, clientKeyShares } = await this.importRawPrivateKey({
|
|
270
|
+
chainName,
|
|
271
|
+
privateKey: formattedPrivateKey,
|
|
272
|
+
thresholdSignatureScheme,
|
|
273
|
+
onCeremonyComplete: (accountAddress, walletId)=>{
|
|
274
|
+
// update wallet map
|
|
275
|
+
this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress] || {}, {
|
|
276
|
+
accountAddress,
|
|
277
|
+
walletId,
|
|
278
|
+
chainName: this.chainName,
|
|
279
|
+
thresholdSignatureScheme,
|
|
280
|
+
clientKeySharesBackupInfo: browser.getClientKeyShareBackupInfo()
|
|
281
|
+
});
|
|
282
|
+
this.logger.debug('walletMap updated for wallet', {
|
|
283
|
+
context: {
|
|
284
|
+
accountAddress,
|
|
285
|
+
walletId,
|
|
286
|
+
walletMap: this.walletMap
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
ceremonyCeremonyCompleteResolver(undefined);
|
|
290
|
+
},
|
|
291
|
+
onError
|
|
292
|
+
});
|
|
293
|
+
// Wait for the ceremony to complete before proceeding
|
|
294
|
+
await ceremonyCompletePromise;
|
|
295
|
+
if (!rawPublicKey || !clientKeyShares) {
|
|
296
|
+
throw new Error(browser.ERROR_IMPORT_PRIVATE_KEY);
|
|
297
|
+
}
|
|
298
|
+
const { accountAddress } = await this.deriveAccountAddress(rawPublicKey);
|
|
299
|
+
if (accountAddress !== publicKey) {
|
|
300
|
+
throw new Error(`Public key mismatch: derived address ${accountAddress} !== public key ${publicKey}`);
|
|
301
|
+
}
|
|
302
|
+
// Update client key shares in wallet map
|
|
303
|
+
await this.setClientKeySharesToLocalStorage({
|
|
304
|
+
accountAddress,
|
|
305
|
+
clientKeyShares,
|
|
306
|
+
overwriteOrMerge: 'overwrite'
|
|
307
|
+
});
|
|
308
|
+
await this.storeEncryptedBackupByWalletWithRetry({
|
|
309
|
+
accountAddress,
|
|
310
|
+
clientKeyShares,
|
|
311
|
+
password,
|
|
312
|
+
signedSessionId
|
|
313
|
+
});
|
|
314
|
+
return {
|
|
315
|
+
accountAddress,
|
|
316
|
+
rawPublicKey: rawPublicKey
|
|
317
|
+
};
|
|
318
|
+
} catch (error) {
|
|
319
|
+
this.logger.error(browser.ERROR_IMPORT_PRIVATE_KEY, error);
|
|
320
|
+
onError == null ? void 0 : onError(error);
|
|
321
|
+
throw new Error(browser.ERROR_IMPORT_PRIVATE_KEY);
|
|
251
322
|
}
|
|
252
|
-
// Update client key shares in wallet map
|
|
253
|
-
// warning: this might result in race condition if `onCeremonyComplete` executes at the same time
|
|
254
|
-
// TODO: remove this once iframe handling for secret shares is implemented
|
|
255
|
-
await this.setClientKeySharesToLocalStorage({
|
|
256
|
-
accountAddress,
|
|
257
|
-
clientKeyShares,
|
|
258
|
-
overwriteOrMerge: 'overwrite'
|
|
259
|
-
});
|
|
260
|
-
// Backup the new wallet without waiting for the promise to resolve
|
|
261
|
-
void this.storeEncryptedBackupByWalletWithRetry({
|
|
262
|
-
accountAddress,
|
|
263
|
-
clientKeyShares,
|
|
264
|
-
password
|
|
265
|
-
});
|
|
266
|
-
return {
|
|
267
|
-
accountAddress,
|
|
268
|
-
rawPublicKey: rawPublicKey,
|
|
269
|
-
clientKeyShares
|
|
270
|
-
};
|
|
271
323
|
}
|
|
272
324
|
async getSvmWallets() {
|
|
273
325
|
const wallets = await this.getWallets();
|
|
274
326
|
const svmWallets = wallets.filter((wallet)=>wallet.chainName === 'solana');
|
|
275
327
|
return svmWallets;
|
|
276
328
|
}
|
|
277
|
-
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl }){
|
|
329
|
+
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, storageKey, debug, featureFlags, authMode = browser.AuthMode.HEADER, sdkVersion, forwardMPCClient }){
|
|
278
330
|
super({
|
|
279
331
|
environmentId,
|
|
280
332
|
authToken,
|
|
281
333
|
baseApiUrl,
|
|
282
|
-
baseMPCRelayApiUrl
|
|
283
|
-
|
|
334
|
+
baseMPCRelayApiUrl,
|
|
335
|
+
storageKey,
|
|
336
|
+
debug,
|
|
337
|
+
featureFlags,
|
|
338
|
+
authMode,
|
|
339
|
+
sdkVersion,
|
|
340
|
+
forwardMPCClient
|
|
341
|
+
}), this.chainName = 'SVM';
|
|
284
342
|
}
|
|
285
343
|
}
|
|
286
344
|
|
package/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DynamicWalletClient, getClientKeyShareBackupInfo, WalletOperation } from '@dynamic-labs-wallet/browser';
|
|
1
|
+
import { DynamicWalletClient, getClientKeyShareBackupInfo, ERROR_KEYGEN_FAILED, ERROR_CREATE_WALLET_ACCOUNT, WalletOperation, ERROR_ACCOUNT_ADDRESS_REQUIRED, ERROR_SIGN_MESSAGE, ERROR_IMPORT_PRIVATE_KEY, AuthMode } from '@dynamic-labs-wallet/browser';
|
|
2
|
+
import { VersionedMessage, VersionedTransaction, Keypair } from '@solana/web3.js';
|
|
2
3
|
import bs58 from 'bs58';
|
|
3
|
-
import { VersionedTransaction, PublicKey, Keypair } from '@solana/web3.js';
|
|
4
4
|
|
|
5
5
|
function _extends() {
|
|
6
6
|
_extends = Object.assign || function assign(target) {
|
|
@@ -13,21 +13,18 @@ function _extends() {
|
|
|
13
13
|
return _extends.apply(this, arguments);
|
|
14
14
|
}
|
|
15
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
16
|
class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
24
17
|
/**
|
|
25
18
|
* Creates a wallet account on the Solana chain
|
|
26
19
|
*
|
|
27
20
|
* @param thresholdSignatureScheme The threshold signature scheme to use
|
|
28
21
|
* @returns The account address, public key hex, raw public key, and client key shares
|
|
29
|
-
*/ async createWalletAccount({ thresholdSignatureScheme, password = undefined }) {
|
|
22
|
+
*/ async createWalletAccount({ thresholdSignatureScheme, password = undefined, signedSessionId, traceContext }) {
|
|
30
23
|
try {
|
|
24
|
+
let ceremonyCeremonyCompleteResolver;
|
|
25
|
+
const ceremonyCompletePromise = new Promise((resolve)=>{
|
|
26
|
+
ceremonyCeremonyCompleteResolver = resolve;
|
|
27
|
+
});
|
|
31
28
|
const { rawPublicKey, clientKeyShares } = await this.keyGen({
|
|
32
29
|
chainName: this.chainName,
|
|
33
30
|
thresholdSignatureScheme,
|
|
@@ -40,42 +37,49 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
40
37
|
thresholdSignatureScheme,
|
|
41
38
|
clientKeySharesBackupInfo: getClientKeyShareBackupInfo()
|
|
42
39
|
});
|
|
40
|
+
this.logger.debug('walletMap updated for wallet', _extends({
|
|
41
|
+
context: {
|
|
42
|
+
accountAddress,
|
|
43
|
+
walletId,
|
|
44
|
+
walletMap: this.walletMap
|
|
45
|
+
}
|
|
46
|
+
}, this.getTraceContext(traceContext)));
|
|
47
|
+
ceremonyCeremonyCompleteResolver(undefined);
|
|
43
48
|
}
|
|
44
49
|
});
|
|
45
|
-
|
|
46
|
-
|
|
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);
|
|
47
54
|
}
|
|
48
55
|
if (!clientKeyShares) {
|
|
49
|
-
throw new Error(
|
|
56
|
+
throw new Error(ERROR_KEYGEN_FAILED);
|
|
50
57
|
}
|
|
51
58
|
const { accountAddress } = await this.deriveAccountAddress(rawPublicKey);
|
|
52
59
|
// 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
60
|
await this.setClientKeySharesToLocalStorage({
|
|
56
61
|
accountAddress,
|
|
57
62
|
clientKeyShares,
|
|
58
63
|
overwriteOrMerge: 'overwrite'
|
|
59
64
|
});
|
|
60
|
-
|
|
61
|
-
void this.storeEncryptedBackupByWalletWithRetry({
|
|
65
|
+
await this.storeEncryptedBackupByWalletWithRetry({
|
|
62
66
|
accountAddress,
|
|
63
67
|
clientKeyShares,
|
|
64
|
-
password
|
|
68
|
+
password,
|
|
69
|
+
signedSessionId
|
|
65
70
|
});
|
|
66
71
|
return {
|
|
67
72
|
accountAddress,
|
|
68
|
-
rawPublicKey
|
|
69
|
-
clientKeyShares
|
|
73
|
+
rawPublicKey
|
|
70
74
|
};
|
|
71
75
|
} catch (error) {
|
|
72
76
|
this.logger.error(ERROR_CREATE_WALLET_ACCOUNT, error);
|
|
73
77
|
throw new Error(ERROR_CREATE_WALLET_ACCOUNT);
|
|
74
78
|
}
|
|
75
79
|
}
|
|
76
|
-
// Function to properly derive account address
|
|
77
80
|
async deriveAccountAddress(rawPublicKey) {
|
|
78
|
-
const
|
|
81
|
+
const pubKeyBytes = typeof rawPublicKey === 'string' ? new Uint8Array(Buffer.from(rawPublicKey, 'hex')) : rawPublicKey;
|
|
82
|
+
const accountAddress = bs58.encode(pubKeyBytes);
|
|
79
83
|
return {
|
|
80
84
|
accountAddress
|
|
81
85
|
};
|
|
@@ -86,62 +90,64 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
86
90
|
* @param message The message to sign (Uint8Array)
|
|
87
91
|
* @param accountAddress Solana address (base58 encoded)
|
|
88
92
|
* @param password The password for encrypted backup shares
|
|
89
|
-
*/ async signMessage({ message, accountAddress, password = undefined }) {
|
|
93
|
+
*/ async signMessage({ message, accountAddress, password = undefined, signedSessionId, mfaToken, onError, traceContext }) {
|
|
90
94
|
await this.verifyPassword({
|
|
91
95
|
accountAddress,
|
|
92
96
|
password,
|
|
93
|
-
walletOperation: WalletOperation.SIGN_MESSAGE
|
|
97
|
+
walletOperation: WalletOperation.SIGN_MESSAGE,
|
|
98
|
+
signedSessionId
|
|
94
99
|
});
|
|
95
100
|
if (!accountAddress) {
|
|
96
|
-
throw new Error(
|
|
101
|
+
throw new Error(ERROR_ACCOUNT_ADDRESS_REQUIRED);
|
|
97
102
|
}
|
|
98
103
|
try {
|
|
99
104
|
const signatureEd25519 = await this.sign({
|
|
100
105
|
message,
|
|
101
106
|
accountAddress: accountAddress,
|
|
102
107
|
chainName: this.chainName,
|
|
103
|
-
password
|
|
108
|
+
password,
|
|
109
|
+
signedSessionId,
|
|
110
|
+
mfaToken,
|
|
111
|
+
context: {
|
|
112
|
+
svmMessage: message
|
|
113
|
+
},
|
|
114
|
+
onError,
|
|
115
|
+
traceContext
|
|
104
116
|
});
|
|
105
117
|
const base58Signature = bs58.encode(signatureEd25519);
|
|
106
118
|
return base58Signature;
|
|
107
119
|
} catch (error) {
|
|
108
|
-
this.logger.error(
|
|
109
|
-
throw
|
|
120
|
+
this.logger.error(ERROR_SIGN_MESSAGE, error);
|
|
121
|
+
throw new Error(ERROR_SIGN_MESSAGE);
|
|
110
122
|
}
|
|
111
123
|
}
|
|
112
|
-
async signTransaction({ senderAddress, transaction, password = undefined }) {
|
|
124
|
+
async signTransaction({ senderAddress, transaction, password = undefined, signedSessionId, mfaToken, chainId, context, onError, traceContext }) {
|
|
113
125
|
await this.verifyPassword({
|
|
114
126
|
accountAddress: senderAddress,
|
|
115
127
|
password,
|
|
116
|
-
walletOperation: WalletOperation.SIGN_TRANSACTION
|
|
128
|
+
walletOperation: WalletOperation.SIGN_TRANSACTION,
|
|
129
|
+
signedSessionId
|
|
117
130
|
});
|
|
118
131
|
try {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const signatureEd25519 = await this.sign({
|
|
130
|
-
message: messageToSign,
|
|
131
|
-
accountAddress: senderAddress,
|
|
132
|
-
chainName: this.chainName,
|
|
133
|
-
password
|
|
132
|
+
const base58SerializedTransaction = this.prepareTransactionForSigning(transaction);
|
|
133
|
+
const signParams = this.buildSignParams({
|
|
134
|
+
transaction,
|
|
135
|
+
senderAddress,
|
|
136
|
+
password,
|
|
137
|
+
signedSessionId,
|
|
138
|
+
mfaToken,
|
|
139
|
+
chainId,
|
|
140
|
+
base58SerializedTransaction,
|
|
141
|
+
context
|
|
134
142
|
});
|
|
143
|
+
const signatureEd25519 = await this.sign(_extends({}, signParams, {
|
|
144
|
+
onError,
|
|
145
|
+
traceContext
|
|
146
|
+
}));
|
|
135
147
|
if (!signatureEd25519) {
|
|
136
148
|
throw new Error('Signature is undefined');
|
|
137
149
|
}
|
|
138
|
-
|
|
139
|
-
const signedTransaction = addSignatureToTransaction({
|
|
140
|
-
transaction,
|
|
141
|
-
signature: signatureEd25519,
|
|
142
|
-
signerPublicKey: senderPublicKey
|
|
143
|
-
});
|
|
144
|
-
return signedTransaction;
|
|
150
|
+
return Buffer.from(signatureEd25519).toString('hex');
|
|
145
151
|
} catch (error) {
|
|
146
152
|
this.logger.error('Error in signTransaction:', error);
|
|
147
153
|
if (error instanceof Error) {
|
|
@@ -150,33 +156,59 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
150
156
|
throw error;
|
|
151
157
|
}
|
|
152
158
|
}
|
|
159
|
+
prepareTransactionForSigning(transaction) {
|
|
160
|
+
const transactionBytes = new Uint8Array(Buffer.from(transaction, 'hex'));
|
|
161
|
+
const deserializedTransaction = VersionedMessage.deserialize(transactionBytes);
|
|
162
|
+
const versionedTransaction = new VersionedTransaction(deserializedTransaction);
|
|
163
|
+
const serializedTransaction = versionedTransaction.serialize();
|
|
164
|
+
return bs58.encode(serializedTransaction);
|
|
165
|
+
}
|
|
166
|
+
buildSignParams({ transaction, senderAddress, password, signedSessionId, mfaToken, chainId, base58SerializedTransaction, context }) {
|
|
167
|
+
const signParams = {
|
|
168
|
+
message: transaction,
|
|
169
|
+
accountAddress: senderAddress,
|
|
170
|
+
chainName: this.chainName,
|
|
171
|
+
password,
|
|
172
|
+
signedSessionId,
|
|
173
|
+
mfaToken
|
|
174
|
+
};
|
|
175
|
+
if (chainId !== undefined) {
|
|
176
|
+
signParams.context = _extends({}, context, {
|
|
177
|
+
svmTransaction: {
|
|
178
|
+
chainId,
|
|
179
|
+
method: 'signAndSendTransaction',
|
|
180
|
+
serializedTransactions: [
|
|
181
|
+
base58SerializedTransaction
|
|
182
|
+
]
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
return signParams;
|
|
187
|
+
}
|
|
153
188
|
/**
|
|
154
189
|
* Exports the private key for a given account address
|
|
155
190
|
*
|
|
156
191
|
* @param accountAddress The account address to export the private key for
|
|
157
192
|
* @param password The password for encrypted backup shares
|
|
158
193
|
* @returns The private key
|
|
159
|
-
*/ async exportPrivateKey({ accountAddress,
|
|
194
|
+
*/ async exportPrivateKey({ accountAddress, password = undefined, signedSessionId, mfaToken }) {
|
|
160
195
|
await this.verifyPassword({
|
|
161
196
|
accountAddress,
|
|
162
197
|
password,
|
|
163
|
-
walletOperation: WalletOperation.EXPORT_PRIVATE_KEY
|
|
198
|
+
walletOperation: WalletOperation.EXPORT_PRIVATE_KEY,
|
|
199
|
+
signedSessionId
|
|
164
200
|
});
|
|
165
201
|
const { derivedPrivateKey } = await this.exportKey({
|
|
166
202
|
accountAddress,
|
|
167
203
|
chainName: this.chainName,
|
|
168
204
|
password,
|
|
169
|
-
|
|
205
|
+
signedSessionId,
|
|
206
|
+
mfaToken
|
|
170
207
|
});
|
|
171
208
|
if (!derivedPrivateKey) {
|
|
172
209
|
throw new Error('Derived private key is undefined');
|
|
173
210
|
}
|
|
174
|
-
|
|
175
|
-
// Display the private key in the container via iframe
|
|
176
|
-
const { iframeDisplay } = await this.initializeIframeDisplayForContainer({
|
|
177
|
-
container: displayContainer
|
|
178
|
-
});
|
|
179
|
-
iframeDisplay.displayPrivateKey(accountAddress, encodedPrivateKey);
|
|
211
|
+
return derivedPrivateKey;
|
|
180
212
|
}
|
|
181
213
|
/**
|
|
182
214
|
* Exports the private key for a given account address
|
|
@@ -220,65 +252,91 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
220
252
|
* @param thresholdSignatureScheme The threshold signature scheme to use
|
|
221
253
|
* @param password The password for encrypted backup shares
|
|
222
254
|
* @returns The account address, raw public key, and client key shares
|
|
223
|
-
*/ async importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password = undefined, onError }) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
// update wallet map
|
|
234
|
-
this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress] || {}, {
|
|
235
|
-
accountAddress,
|
|
236
|
-
walletId,
|
|
237
|
-
chainName: this.chainName,
|
|
238
|
-
thresholdSignatureScheme,
|
|
239
|
-
clientKeySharesBackupInfo: getClientKeyShareBackupInfo()
|
|
240
|
-
});
|
|
255
|
+
*/ async importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password = undefined, onError, signedSessionId, publicAddressCheck }) {
|
|
256
|
+
try {
|
|
257
|
+
let ceremonyCeremonyCompleteResolver;
|
|
258
|
+
const ceremonyCompletePromise = new Promise((resolve)=>{
|
|
259
|
+
ceremonyCeremonyCompleteResolver = resolve;
|
|
260
|
+
});
|
|
261
|
+
//get public key from private key
|
|
262
|
+
const publicKey = this.getPublicKeyFromPrivateKey(privateKey);
|
|
263
|
+
if (publicAddressCheck && publicKey !== publicAddressCheck) {
|
|
264
|
+
throw new Error(`Public address mismatch: derived address ${publicKey} !== public address ${publicAddressCheck}`);
|
|
241
265
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
266
|
+
const formattedPrivateKey = this.decodePrivateKeyForSolana(privateKey);
|
|
267
|
+
const { rawPublicKey, clientKeyShares } = await this.importRawPrivateKey({
|
|
268
|
+
chainName,
|
|
269
|
+
privateKey: formattedPrivateKey,
|
|
270
|
+
thresholdSignatureScheme,
|
|
271
|
+
onCeremonyComplete: (accountAddress, walletId)=>{
|
|
272
|
+
// update wallet map
|
|
273
|
+
this.walletMap[accountAddress] = _extends({}, this.walletMap[accountAddress] || {}, {
|
|
274
|
+
accountAddress,
|
|
275
|
+
walletId,
|
|
276
|
+
chainName: this.chainName,
|
|
277
|
+
thresholdSignatureScheme,
|
|
278
|
+
clientKeySharesBackupInfo: getClientKeyShareBackupInfo()
|
|
279
|
+
});
|
|
280
|
+
this.logger.debug('walletMap updated for wallet', {
|
|
281
|
+
context: {
|
|
282
|
+
accountAddress,
|
|
283
|
+
walletId,
|
|
284
|
+
walletMap: this.walletMap
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
ceremonyCeremonyCompleteResolver(undefined);
|
|
288
|
+
},
|
|
289
|
+
onError
|
|
290
|
+
});
|
|
291
|
+
// Wait for the ceremony to complete before proceeding
|
|
292
|
+
await ceremonyCompletePromise;
|
|
293
|
+
if (!rawPublicKey || !clientKeyShares) {
|
|
294
|
+
throw new Error(ERROR_IMPORT_PRIVATE_KEY);
|
|
295
|
+
}
|
|
296
|
+
const { accountAddress } = await this.deriveAccountAddress(rawPublicKey);
|
|
297
|
+
if (accountAddress !== publicKey) {
|
|
298
|
+
throw new Error(`Public key mismatch: derived address ${accountAddress} !== public key ${publicKey}`);
|
|
299
|
+
}
|
|
300
|
+
// Update client key shares in wallet map
|
|
301
|
+
await this.setClientKeySharesToLocalStorage({
|
|
302
|
+
accountAddress,
|
|
303
|
+
clientKeyShares,
|
|
304
|
+
overwriteOrMerge: 'overwrite'
|
|
305
|
+
});
|
|
306
|
+
await this.storeEncryptedBackupByWalletWithRetry({
|
|
307
|
+
accountAddress,
|
|
308
|
+
clientKeyShares,
|
|
309
|
+
password,
|
|
310
|
+
signedSessionId
|
|
311
|
+
});
|
|
312
|
+
return {
|
|
313
|
+
accountAddress,
|
|
314
|
+
rawPublicKey: rawPublicKey
|
|
315
|
+
};
|
|
316
|
+
} catch (error) {
|
|
317
|
+
this.logger.error(ERROR_IMPORT_PRIVATE_KEY, error);
|
|
318
|
+
onError == null ? void 0 : onError(error);
|
|
319
|
+
throw new Error(ERROR_IMPORT_PRIVATE_KEY);
|
|
249
320
|
}
|
|
250
|
-
// Update client key shares in wallet map
|
|
251
|
-
// warning: this might result in race condition if `onCeremonyComplete` executes at the same time
|
|
252
|
-
// TODO: remove this once iframe handling for secret shares is implemented
|
|
253
|
-
await this.setClientKeySharesToLocalStorage({
|
|
254
|
-
accountAddress,
|
|
255
|
-
clientKeyShares,
|
|
256
|
-
overwriteOrMerge: 'overwrite'
|
|
257
|
-
});
|
|
258
|
-
// Backup the new wallet without waiting for the promise to resolve
|
|
259
|
-
void this.storeEncryptedBackupByWalletWithRetry({
|
|
260
|
-
accountAddress,
|
|
261
|
-
clientKeyShares,
|
|
262
|
-
password
|
|
263
|
-
});
|
|
264
|
-
return {
|
|
265
|
-
accountAddress,
|
|
266
|
-
rawPublicKey: rawPublicKey,
|
|
267
|
-
clientKeyShares
|
|
268
|
-
};
|
|
269
321
|
}
|
|
270
322
|
async getSvmWallets() {
|
|
271
323
|
const wallets = await this.getWallets();
|
|
272
324
|
const svmWallets = wallets.filter((wallet)=>wallet.chainName === 'solana');
|
|
273
325
|
return svmWallets;
|
|
274
326
|
}
|
|
275
|
-
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl }){
|
|
327
|
+
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, storageKey, debug, featureFlags, authMode = AuthMode.HEADER, sdkVersion, forwardMPCClient }){
|
|
276
328
|
super({
|
|
277
329
|
environmentId,
|
|
278
330
|
authToken,
|
|
279
331
|
baseApiUrl,
|
|
280
|
-
baseMPCRelayApiUrl
|
|
281
|
-
|
|
332
|
+
baseMPCRelayApiUrl,
|
|
333
|
+
storageKey,
|
|
334
|
+
debug,
|
|
335
|
+
featureFlags,
|
|
336
|
+
authMode,
|
|
337
|
+
sdkVersion,
|
|
338
|
+
forwardMPCClient
|
|
339
|
+
}), this.chainName = 'SVM';
|
|
282
340
|
}
|
|
283
341
|
}
|
|
284
342
|
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs-wallet/svm",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.1-paolo-1",
|
|
4
4
|
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"dependencies": {
|
|
6
|
-
"@dynamic-labs-wallet/browser": "0.0.
|
|
7
|
-
"@solana/web3.js": "^1.98.
|
|
8
|
-
"bs58": "^6.0.0"
|
|
7
|
+
"@dynamic-labs-wallet/browser": "0.0.1-paolo-1",
|
|
8
|
+
"@solana/web3.js": "^1.98.2",
|
|
9
|
+
"bs58": "^6.0.0",
|
|
10
|
+
"@dynamic-labs/sdk-api-core": "^0.0.818"
|
|
9
11
|
},
|
|
10
12
|
"nx": {
|
|
11
13
|
"sourceRoot": "packages/svm/src",
|
|
@@ -15,7 +17,6 @@
|
|
|
15
17
|
"build": {}
|
|
16
18
|
}
|
|
17
19
|
},
|
|
18
|
-
"type": "module",
|
|
19
20
|
"main": "./index.cjs.js",
|
|
20
21
|
"module": "./index.esm.js",
|
|
21
22
|
"types": "./index.esm.d.ts",
|
|
@@ -25,7 +26,7 @@
|
|
|
25
26
|
"types": "./index.esm.d.ts",
|
|
26
27
|
"import": "./index.esm.js",
|
|
27
28
|
"require": "./index.cjs.js",
|
|
28
|
-
"default": "./index.
|
|
29
|
+
"default": "./index.esm.js"
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './svm/index';
|
|
1
|
+
export * from './svm/index.js';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
|
@@ -1,29 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { DynamicWalletClient, type DynamicWalletClientProps, type Ed25519KeygenResult, type ThresholdSignatureScheme, type TraceContext } from '@dynamic-labs-wallet/browser';
|
|
2
|
+
import type { SignMessageContext } from '@dynamic-labs/sdk-api-core';
|
|
3
3
|
export declare class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
4
|
-
readonly chainName = "
|
|
4
|
+
readonly chainName = "SVM";
|
|
5
5
|
accountAddress?: string;
|
|
6
|
-
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, }:
|
|
7
|
-
environmentId: string;
|
|
8
|
-
authToken: string;
|
|
9
|
-
baseApiUrl?: string;
|
|
10
|
-
baseMPCRelayApiUrl?: string;
|
|
11
|
-
});
|
|
6
|
+
constructor({ environmentId, authToken, baseApiUrl, baseMPCRelayApiUrl, storageKey, debug, featureFlags, authMode, sdkVersion, forwardMPCClient, }: DynamicWalletClientProps);
|
|
12
7
|
/**
|
|
13
8
|
* Creates a wallet account on the Solana chain
|
|
14
9
|
*
|
|
15
10
|
* @param thresholdSignatureScheme The threshold signature scheme to use
|
|
16
11
|
* @returns The account address, public key hex, raw public key, and client key shares
|
|
17
12
|
*/
|
|
18
|
-
createWalletAccount({ thresholdSignatureScheme, password, }: {
|
|
13
|
+
createWalletAccount({ thresholdSignatureScheme, password, signedSessionId, traceContext, }: {
|
|
19
14
|
thresholdSignatureScheme: ThresholdSignatureScheme;
|
|
20
15
|
password?: string;
|
|
16
|
+
signedSessionId: string;
|
|
17
|
+
traceContext?: TraceContext;
|
|
21
18
|
}): Promise<{
|
|
22
19
|
accountAddress: string;
|
|
23
|
-
rawPublicKey: Uint8Array;
|
|
24
|
-
clientKeyShares: ClientKeyShare[];
|
|
20
|
+
rawPublicKey: Uint8Array | string;
|
|
25
21
|
}>;
|
|
26
|
-
deriveAccountAddress(rawPublicKey: Uint8Array): Promise<{
|
|
22
|
+
deriveAccountAddress(rawPublicKey: string | Uint8Array): Promise<{
|
|
27
23
|
accountAddress: string;
|
|
28
24
|
}>;
|
|
29
25
|
/**
|
|
@@ -33,16 +29,28 @@ export declare class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
33
29
|
* @param accountAddress Solana address (base58 encoded)
|
|
34
30
|
* @param password The password for encrypted backup shares
|
|
35
31
|
*/
|
|
36
|
-
signMessage({ message, accountAddress, password, }: {
|
|
32
|
+
signMessage({ message, accountAddress, password, signedSessionId, mfaToken, onError, traceContext, }: {
|
|
37
33
|
message: string;
|
|
38
34
|
accountAddress: string;
|
|
39
35
|
password?: string;
|
|
36
|
+
signedSessionId: string;
|
|
37
|
+
mfaToken?: string;
|
|
38
|
+
onError?: (error: Error) => void;
|
|
39
|
+
traceContext?: TraceContext;
|
|
40
40
|
}): Promise<string>;
|
|
41
|
-
signTransaction({ senderAddress, transaction, password, }: {
|
|
41
|
+
signTransaction({ senderAddress, transaction, password, signedSessionId, mfaToken, chainId, context, onError, traceContext, }: {
|
|
42
42
|
senderAddress: string;
|
|
43
|
-
transaction:
|
|
43
|
+
transaction: string;
|
|
44
44
|
password?: string;
|
|
45
|
-
|
|
45
|
+
signedSessionId: string;
|
|
46
|
+
mfaToken?: string;
|
|
47
|
+
chainId?: string;
|
|
48
|
+
context?: SignMessageContext;
|
|
49
|
+
onError?: (error: Error) => void;
|
|
50
|
+
traceContext?: TraceContext;
|
|
51
|
+
}): Promise<string>;
|
|
52
|
+
private prepareTransactionForSigning;
|
|
53
|
+
private buildSignParams;
|
|
46
54
|
/**
|
|
47
55
|
* Exports the private key for a given account address
|
|
48
56
|
*
|
|
@@ -50,11 +58,12 @@ export declare class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
50
58
|
* @param password The password for encrypted backup shares
|
|
51
59
|
* @returns The private key
|
|
52
60
|
*/
|
|
53
|
-
exportPrivateKey({ accountAddress,
|
|
61
|
+
exportPrivateKey({ accountAddress, password, signedSessionId, mfaToken, }: {
|
|
54
62
|
accountAddress: string;
|
|
55
|
-
displayContainer: HTMLElement;
|
|
56
63
|
password?: string;
|
|
57
|
-
|
|
64
|
+
signedSessionId: string;
|
|
65
|
+
mfaToken?: string;
|
|
66
|
+
}): Promise<string>;
|
|
58
67
|
/**
|
|
59
68
|
* Exports the private key for a given account address
|
|
60
69
|
*
|
|
@@ -85,17 +94,18 @@ export declare class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
85
94
|
* @param password The password for encrypted backup shares
|
|
86
95
|
* @returns The account address, raw public key, and client key shares
|
|
87
96
|
*/
|
|
88
|
-
importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password, onError, }: {
|
|
97
|
+
importPrivateKey({ privateKey, chainName, thresholdSignatureScheme, password, onError, signedSessionId, publicAddressCheck, }: {
|
|
89
98
|
privateKey: string;
|
|
90
99
|
chainName: string;
|
|
91
100
|
thresholdSignatureScheme: ThresholdSignatureScheme;
|
|
92
101
|
password?: string;
|
|
93
102
|
onError?: (error: Error) => void;
|
|
103
|
+
signedSessionId: string;
|
|
104
|
+
publicAddressCheck?: string;
|
|
94
105
|
}): Promise<{
|
|
95
106
|
accountAddress: string;
|
|
96
107
|
rawPublicKey: Uint8Array | undefined;
|
|
97
|
-
clientKeyShares: ClientKeyShare[];
|
|
98
108
|
}>;
|
|
99
109
|
getSvmWallets(): Promise<any>;
|
|
100
110
|
}
|
|
101
|
-
//# sourceMappingURL=
|
|
111
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/svm/client.ts"],"names":[],"mappings":"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"}
|
package/src/svm/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './client.js';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/src/svm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/svm/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/svm/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
|
package/src/svm/utils.d.ts
CHANGED
package/src/svm/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/svm/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,SAAS,EAET,WAAW,EACX,oBAAoB,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/svm/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,SAAS,EAET,WAAW,EACX,KAAK,oBAAoB,EAC1B,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"}
|
package/src/svm/svm.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;IAyBD;;;;;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"}
|