@dynamic-labs-wallet/svm 0.0.48 → 0.0.49
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 +25 -38
- package/index.esm.js +25 -38
- package/package.json +2 -3
- package/src/svm/svm.d.ts +3 -4
- package/src/svm/svm.d.ts.map +1 -1
- package/src/svm/utils.d.ts.map +1 -1
package/index.cjs.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
var browser = require('@dynamic-labs-wallet/browser');
|
|
4
4
|
var bs58 = require('bs58');
|
|
5
5
|
var web3_js = require('@solana/web3.js');
|
|
6
|
-
require('@dynamic-labs-wallet/core');
|
|
7
6
|
|
|
8
7
|
function _extends() {
|
|
9
8
|
_extends = Object.assign || function assign(target) {
|
|
@@ -17,13 +16,8 @@ function _extends() {
|
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
const addSignatureToTransaction = ({ transaction, signature, signerPublicKey })=>{
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return transaction;
|
|
23
|
-
} catch (error) {
|
|
24
|
-
console.error('Error in finalizing transaction:', error);
|
|
25
|
-
throw error;
|
|
26
|
-
}
|
|
19
|
+
transaction.addSignature(signerPublicKey, Buffer.from(signature));
|
|
20
|
+
return transaction;
|
|
27
21
|
};
|
|
28
22
|
|
|
29
23
|
const ERROR_CREATE_WALLET_ACCOUNT = 'Error creating svm wallet account';
|
|
@@ -60,8 +54,10 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
|
|
|
60
54
|
// Update client key shares in wallet map
|
|
61
55
|
// warning: this might result in race condition if `onCeremonyComplete` executes at the same time
|
|
62
56
|
// TODO: remove this once iframe handling for secret shares is implemented
|
|
63
|
-
this.
|
|
64
|
-
|
|
57
|
+
await this.setClientKeySharesToLocalStorage({
|
|
58
|
+
accountAddress,
|
|
59
|
+
clientKeyShares,
|
|
60
|
+
overwriteOrMerge: 'overwrite'
|
|
65
61
|
});
|
|
66
62
|
// Backup the new wallet without waiting for the promise to resolve
|
|
67
63
|
void this.storeEncryptedBackupByWalletWithRetry({
|
|
@@ -111,30 +107,10 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
|
|
|
111
107
|
const base58Signature = bs58.encode(signatureEd25519);
|
|
112
108
|
return base58Signature;
|
|
113
109
|
} catch (error) {
|
|
114
|
-
|
|
110
|
+
this.logger.error('Error signing message:', error);
|
|
115
111
|
throw error;
|
|
116
112
|
}
|
|
117
113
|
}
|
|
118
|
-
// async verifyMessageSignature({
|
|
119
|
-
// accountAddress,
|
|
120
|
-
// message,
|
|
121
|
-
// signature,
|
|
122
|
-
// }: {
|
|
123
|
-
// accountAddress: string;
|
|
124
|
-
// message: string;
|
|
125
|
-
// signature: string;
|
|
126
|
-
// }) {
|
|
127
|
-
// const signatureEd25519 = bs58.decode(signature);
|
|
128
|
-
// const publicKey = new PublicKey(accountAddress);
|
|
129
|
-
// const messageBytes = new TextEncoder().encode(message);
|
|
130
|
-
// const verified = nacl.sign.detached.verify(
|
|
131
|
-
// messageBytes,
|
|
132
|
-
// signatureEd25519,
|
|
133
|
-
// publicKey.toBytes()
|
|
134
|
-
// );
|
|
135
|
-
// console.log('verified', verified);
|
|
136
|
-
// return verified;
|
|
137
|
-
// }
|
|
138
114
|
async signTransaction({ senderAddress, transaction, password = undefined }) {
|
|
139
115
|
await this.verifyPassword({
|
|
140
116
|
accountAddress: senderAddress,
|
|
@@ -182,19 +158,28 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
|
|
|
182
158
|
* @param accountAddress The account address to export the private key for
|
|
183
159
|
* @param password The password for encrypted backup shares
|
|
184
160
|
* @returns The private key
|
|
185
|
-
*/ async exportPrivateKey({ accountAddress, password = undefined }) {
|
|
161
|
+
*/ async exportPrivateKey({ accountAddress, displayContainer, password = undefined }) {
|
|
162
|
+
await this.verifyPassword({
|
|
163
|
+
accountAddress,
|
|
164
|
+
password,
|
|
165
|
+
walletOperation: browser.WalletOperation.EXPORT_PRIVATE_KEY
|
|
166
|
+
});
|
|
186
167
|
const { derivedPrivateKey } = await this.exportKey({
|
|
187
168
|
accountAddress,
|
|
188
169
|
chainName: this.chainName,
|
|
189
|
-
password
|
|
170
|
+
password,
|
|
171
|
+
displayContainer
|
|
190
172
|
});
|
|
191
173
|
if (!derivedPrivateKey) {
|
|
192
174
|
throw new Error('Derived private key is undefined');
|
|
193
175
|
}
|
|
194
176
|
const encodedPrivateKey = bs58.encode(Buffer.from(derivedPrivateKey));
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
177
|
+
if (this.useIframeStorage) {
|
|
178
|
+
const { iframeDisplay } = await this.initializeIframeDisplayForContainer({
|
|
179
|
+
container: displayContainer
|
|
180
|
+
});
|
|
181
|
+
iframeDisplay.displayPrivateKey(accountAddress, encodedPrivateKey);
|
|
182
|
+
}
|
|
198
183
|
}
|
|
199
184
|
/**
|
|
200
185
|
* Exports the private key for a given account address
|
|
@@ -268,8 +253,10 @@ class DynamicSvmWalletClient extends browser.DynamicWalletClient {
|
|
|
268
253
|
// Update client key shares in wallet map
|
|
269
254
|
// warning: this might result in race condition if `onCeremonyComplete` executes at the same time
|
|
270
255
|
// TODO: remove this once iframe handling for secret shares is implemented
|
|
271
|
-
this.
|
|
272
|
-
|
|
256
|
+
await this.setClientKeySharesToLocalStorage({
|
|
257
|
+
accountAddress,
|
|
258
|
+
clientKeyShares,
|
|
259
|
+
overwriteOrMerge: 'overwrite'
|
|
273
260
|
});
|
|
274
261
|
// Backup the new wallet without waiting for the promise to resolve
|
|
275
262
|
void this.storeEncryptedBackupByWalletWithRetry({
|
package/index.esm.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { DynamicWalletClient, getClientKeyShareBackupInfo, WalletOperation } from '@dynamic-labs-wallet/browser';
|
|
2
2
|
import bs58 from 'bs58';
|
|
3
3
|
import { VersionedTransaction, PublicKey, Keypair } from '@solana/web3.js';
|
|
4
|
-
import '@dynamic-labs-wallet/core';
|
|
5
4
|
|
|
6
5
|
function _extends() {
|
|
7
6
|
_extends = Object.assign || function assign(target) {
|
|
@@ -15,13 +14,8 @@ function _extends() {
|
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
const addSignatureToTransaction = ({ transaction, signature, signerPublicKey })=>{
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return transaction;
|
|
21
|
-
} catch (error) {
|
|
22
|
-
console.error('Error in finalizing transaction:', error);
|
|
23
|
-
throw error;
|
|
24
|
-
}
|
|
17
|
+
transaction.addSignature(signerPublicKey, Buffer.from(signature));
|
|
18
|
+
return transaction;
|
|
25
19
|
};
|
|
26
20
|
|
|
27
21
|
const ERROR_CREATE_WALLET_ACCOUNT = 'Error creating svm wallet account';
|
|
@@ -58,8 +52,10 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
58
52
|
// Update client key shares in wallet map
|
|
59
53
|
// warning: this might result in race condition if `onCeremonyComplete` executes at the same time
|
|
60
54
|
// TODO: remove this once iframe handling for secret shares is implemented
|
|
61
|
-
this.
|
|
62
|
-
|
|
55
|
+
await this.setClientKeySharesToLocalStorage({
|
|
56
|
+
accountAddress,
|
|
57
|
+
clientKeyShares,
|
|
58
|
+
overwriteOrMerge: 'overwrite'
|
|
63
59
|
});
|
|
64
60
|
// Backup the new wallet without waiting for the promise to resolve
|
|
65
61
|
void this.storeEncryptedBackupByWalletWithRetry({
|
|
@@ -109,30 +105,10 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
109
105
|
const base58Signature = bs58.encode(signatureEd25519);
|
|
110
106
|
return base58Signature;
|
|
111
107
|
} catch (error) {
|
|
112
|
-
|
|
108
|
+
this.logger.error('Error signing message:', error);
|
|
113
109
|
throw error;
|
|
114
110
|
}
|
|
115
111
|
}
|
|
116
|
-
// async verifyMessageSignature({
|
|
117
|
-
// accountAddress,
|
|
118
|
-
// message,
|
|
119
|
-
// signature,
|
|
120
|
-
// }: {
|
|
121
|
-
// accountAddress: string;
|
|
122
|
-
// message: string;
|
|
123
|
-
// signature: string;
|
|
124
|
-
// }) {
|
|
125
|
-
// const signatureEd25519 = bs58.decode(signature);
|
|
126
|
-
// const publicKey = new PublicKey(accountAddress);
|
|
127
|
-
// const messageBytes = new TextEncoder().encode(message);
|
|
128
|
-
// const verified = nacl.sign.detached.verify(
|
|
129
|
-
// messageBytes,
|
|
130
|
-
// signatureEd25519,
|
|
131
|
-
// publicKey.toBytes()
|
|
132
|
-
// );
|
|
133
|
-
// console.log('verified', verified);
|
|
134
|
-
// return verified;
|
|
135
|
-
// }
|
|
136
112
|
async signTransaction({ senderAddress, transaction, password = undefined }) {
|
|
137
113
|
await this.verifyPassword({
|
|
138
114
|
accountAddress: senderAddress,
|
|
@@ -180,19 +156,28 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
180
156
|
* @param accountAddress The account address to export the private key for
|
|
181
157
|
* @param password The password for encrypted backup shares
|
|
182
158
|
* @returns The private key
|
|
183
|
-
*/ async exportPrivateKey({ accountAddress, password = undefined }) {
|
|
159
|
+
*/ async exportPrivateKey({ accountAddress, displayContainer, password = undefined }) {
|
|
160
|
+
await this.verifyPassword({
|
|
161
|
+
accountAddress,
|
|
162
|
+
password,
|
|
163
|
+
walletOperation: WalletOperation.EXPORT_PRIVATE_KEY
|
|
164
|
+
});
|
|
184
165
|
const { derivedPrivateKey } = await this.exportKey({
|
|
185
166
|
accountAddress,
|
|
186
167
|
chainName: this.chainName,
|
|
187
|
-
password
|
|
168
|
+
password,
|
|
169
|
+
displayContainer
|
|
188
170
|
});
|
|
189
171
|
if (!derivedPrivateKey) {
|
|
190
172
|
throw new Error('Derived private key is undefined');
|
|
191
173
|
}
|
|
192
174
|
const encodedPrivateKey = bs58.encode(Buffer.from(derivedPrivateKey));
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
175
|
+
if (this.useIframeStorage) {
|
|
176
|
+
const { iframeDisplay } = await this.initializeIframeDisplayForContainer({
|
|
177
|
+
container: displayContainer
|
|
178
|
+
});
|
|
179
|
+
iframeDisplay.displayPrivateKey(accountAddress, encodedPrivateKey);
|
|
180
|
+
}
|
|
196
181
|
}
|
|
197
182
|
/**
|
|
198
183
|
* Exports the private key for a given account address
|
|
@@ -266,8 +251,10 @@ class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
266
251
|
// Update client key shares in wallet map
|
|
267
252
|
// warning: this might result in race condition if `onCeremonyComplete` executes at the same time
|
|
268
253
|
// TODO: remove this once iframe handling for secret shares is implemented
|
|
269
|
-
this.
|
|
270
|
-
|
|
254
|
+
await this.setClientKeySharesToLocalStorage({
|
|
255
|
+
accountAddress,
|
|
256
|
+
clientKeyShares,
|
|
257
|
+
overwriteOrMerge: 'overwrite'
|
|
271
258
|
});
|
|
272
259
|
// Backup the new wallet without waiting for the promise to resolve
|
|
273
260
|
void this.storeEncryptedBackupByWalletWithRetry({
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs-wallet/svm",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.49",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@dynamic-labs-wallet/browser": "0.0.
|
|
7
|
-
"@dynamic-labs-wallet/core": "0.0.48",
|
|
6
|
+
"@dynamic-labs-wallet/browser": "0.0.49",
|
|
8
7
|
"@solana/web3.js": "^1.98.0",
|
|
9
8
|
"bs58": "^6.0.0"
|
|
10
9
|
},
|
package/src/svm/svm.d.ts
CHANGED
|
@@ -50,12 +50,11 @@ export declare class DynamicSvmWalletClient extends DynamicWalletClient {
|
|
|
50
50
|
* @param password The password for encrypted backup shares
|
|
51
51
|
* @returns The private key
|
|
52
52
|
*/
|
|
53
|
-
exportPrivateKey({ accountAddress, password, }: {
|
|
53
|
+
exportPrivateKey({ accountAddress, displayContainer, password, }: {
|
|
54
54
|
accountAddress: string;
|
|
55
|
+
displayContainer: HTMLElement;
|
|
55
56
|
password?: string;
|
|
56
|
-
}): Promise<
|
|
57
|
-
derivedPrivateKey: string;
|
|
58
|
-
}>;
|
|
57
|
+
}): Promise<void>;
|
|
59
58
|
/**
|
|
60
59
|
* Exports the private key for a given account address
|
|
61
60
|
*
|
package/src/svm/svm.d.ts.map
CHANGED
|
@@ -1 +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;
|
|
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,E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AAE,WAAW,CAAC;QAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB;IA0BD;;;;;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"}
|
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,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,
|
|
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"}
|