@bitpay-labs/bitcore-client 11.7.2 → 11.7.3
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/package.json +4 -4
- package/ts_build/src/client.d.ts.map +1 -1
- package/ts_build/src/client.js +7 -4
- package/ts_build/src/client.js.map +1 -1
- package/ts_build/src/encryption.d.ts +7 -2
- package/ts_build/src/encryption.d.ts.map +1 -1
- package/ts_build/src/encryption.js +59 -11
- package/ts_build/src/encryption.js.map +1 -1
- package/ts_build/src/storage/mongo.d.ts.map +1 -1
- package/ts_build/src/storage/mongo.js +1 -1
- package/ts_build/src/storage/mongo.js.map +1 -1
- package/ts_build/src/storage/textFile.d.ts +5 -0
- package/ts_build/src/storage/textFile.d.ts.map +1 -1
- package/ts_build/src/storage/textFile.js +46 -0
- package/ts_build/src/storage/textFile.js.map +1 -1
- package/ts_build/src/storage.d.ts +17 -0
- package/ts_build/src/storage.d.ts.map +1 -1
- package/ts_build/src/storage.js +66 -2
- package/ts_build/src/storage.js.map +1 -1
- package/ts_build/src/wallet.d.ts +9 -2
- package/ts_build/src/wallet.d.ts.map +1 -1
- package/ts_build/src/wallet.js +215 -59
- package/ts_build/src/wallet.js.map +1 -1
- package/ts_build/test/unit/data/ethMigrationTestWallet.fixture.d.ts +51 -0
- package/ts_build/test/unit/data/ethMigrationTestWallet.fixture.d.ts.map +1 -0
- package/ts_build/test/unit/data/ethMigrationTestWallet.fixture.js +68 -0
- package/ts_build/test/unit/data/ethMigrationTestWallet.fixture.js.map +1 -0
- package/ts_build/test/unit/wallet.test.js +517 -14
- package/ts_build/test/unit/wallet.test.js.map +1 -1
- package/LICENSE +0 -21
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/storage.ts"],"names":[],"mappings":";;;AAAA,uCAAqC;AACrC,mCAAqC;AACrC,wEAA6D;AAC7D,6CAA0C;AAC1C,2CAAwC;AACxC,2CAAwC;AACxC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C;QACd,CAAC;IACH,CAAC;CACF;AA5PD,0BA4PC"}
|
package/ts_build/src/wallet.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { StorageType } from './types/storage';
|
|
|
6
6
|
import { BumpTxFeeType, IWallet, KeyImport } from './types/wallet';
|
|
7
7
|
export interface IWalletExt extends IWallet {
|
|
8
8
|
storage?: Storage;
|
|
9
|
+
version?: 0 | 2;
|
|
9
10
|
}
|
|
10
11
|
export declare class Wallet {
|
|
11
12
|
masterKey?: any;
|
|
@@ -16,8 +17,11 @@ export declare class Wallet {
|
|
|
16
17
|
storage: Storage;
|
|
17
18
|
storageType: string;
|
|
18
19
|
unlocked?: {
|
|
19
|
-
encryptionKey:
|
|
20
|
-
masterKey:
|
|
20
|
+
encryptionKey: Buffer;
|
|
21
|
+
masterKey: {
|
|
22
|
+
xprivkey: Buffer;
|
|
23
|
+
privateKey: Buffer;
|
|
24
|
+
};
|
|
21
25
|
};
|
|
22
26
|
password: string;
|
|
23
27
|
encryptionKey: string;
|
|
@@ -33,6 +37,7 @@ export declare class Wallet {
|
|
|
33
37
|
lite: boolean;
|
|
34
38
|
addressType: string;
|
|
35
39
|
addressZero: string;
|
|
40
|
+
version?: number;
|
|
36
41
|
static XrpAccountFlags: typeof xrpl.AccountSetTfFlags;
|
|
37
42
|
constructor(params: Wallet | IWalletExt);
|
|
38
43
|
getApiUrl(): string;
|
|
@@ -56,6 +61,7 @@ export declare class Wallet {
|
|
|
56
61
|
lite: boolean;
|
|
57
62
|
addressType: string;
|
|
58
63
|
addressZero: string;
|
|
64
|
+
version: number;
|
|
59
65
|
};
|
|
60
66
|
static deleteWallet(params: {
|
|
61
67
|
name: string;
|
|
@@ -80,6 +86,7 @@ export declare class Wallet {
|
|
|
80
86
|
isSolanaChain(): boolean;
|
|
81
87
|
lock(): this;
|
|
82
88
|
unlock(password: any): Promise<this>;
|
|
89
|
+
migrateWallet(encryptionKey: Buffer): Promise<Wallet>;
|
|
83
90
|
register(params?: {
|
|
84
91
|
baseUrl?: string;
|
|
85
92
|
}): Promise<any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/wallet.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/wallet.ts"],"names":[],"mappings":"AACA,OAAO,6BAA6B,CAAC;AAIrC,OAAO,EAYL,IAAI,EACL,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAiCnE,MAAM,WAAW,UAAW,SAAQ,OAAO;IACzC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;CACjB;AAED,qBAAa,MAAM;IACjB,SAAS,CAAC,EAAE,GAAG,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE;YAAE,QAAQ,EAAE,MAAM,CAAC;YAAC,UAAU,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;IAC1F,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;I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U,KAAA,EAAE,OAAO,KAAA;IAQlC,WAAW;IAIX,gBAAgB,CAAC,QAAQ,KAAA,EAAE,YAAY,SAAoB;IAW3D,eAAe,CAAC,iBAAiB,CAAC,EAAE,OAAO;IAI3C,mBAAmB,CAAC,YAAY,EAAE,MAAM,EAAE,iBAAiB,CAAC,EAAE,OAAO;IAsBrE,mBAAmB,CAAC,iBAAiB,CAAC,EAAE,OAAO;IAI/C,uBAAuB,CAAC,YAAY,EAAE,MAAM,EAAE,iBAAiB,CAAC,EAAE,OAAO;IAkBzE,QAAQ,CAAC,aAAa,GAAE,MAAU,EAAE,QAAQ,CAAC,EAAE,OAAO;YAS9C,iBAAiB;IASzB,SAAS,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,EAAE,gBAAsB;;;;IAsF3G,eAAe,CAAC,EAAE,KAAK,EAAE;;KAAA;IAMzB,WAAW,CAAC,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;IAI7E,QAAQ,CAAC,KAAK,KAAA;IAQpB,SAAS;IAIT,UAAU;CAGX;AAED,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiDxB,CAAC"}
|
package/ts_build/src/wallet.js
CHANGED
|
@@ -37,13 +37,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.AddressTypes = exports.Wallet = void 0;
|
|
40
|
+
const promises_1 = require("fs/promises");
|
|
40
41
|
require("source-map-support/register");
|
|
42
|
+
const os_1 = __importDefault(require("os"));
|
|
43
|
+
const path_1 = __importDefault(require("path"));
|
|
41
44
|
const bitcore_mnemonic_1 = __importDefault(require("@bitpay-labs/bitcore-mnemonic"));
|
|
42
45
|
const crypto_wallet_core_1 = require("@bitpay-labs/crypto-wallet-core");
|
|
43
46
|
const Bcrypt = __importStar(require("bcrypt"));
|
|
44
47
|
const client_1 = require("./client");
|
|
45
48
|
const encryption_1 = require("./encryption");
|
|
46
49
|
const storage_1 = require("./storage");
|
|
50
|
+
const textFile_1 = require("./storage/textFile");
|
|
47
51
|
const stream_util_1 = require("./stream-util");
|
|
48
52
|
const { PrivateKey, HDPrivateKey } = crypto_wallet_core_1.BitcoreLib;
|
|
49
53
|
const chainLibs = {
|
|
@@ -59,11 +63,26 @@ const chainLibs = {
|
|
|
59
63
|
XRP: crypto_wallet_core_1.xrpl,
|
|
60
64
|
SOL: { SolKit: crypto_wallet_core_1.SolKit, SolanaProgram: crypto_wallet_core_1.SolanaProgram }
|
|
61
65
|
};
|
|
66
|
+
const CURRENT_WALLET_VERSION = 2;
|
|
67
|
+
const baseUrls = {
|
|
68
|
+
BTC: 'https://api.bitcore.io/api',
|
|
69
|
+
BCH: 'https://api.bitcore.io/api',
|
|
70
|
+
DOGE: 'https://api.bitcore.io/api',
|
|
71
|
+
LTC: 'https://api.bitcore.io/api',
|
|
72
|
+
ETH: 'https://api-eth.bitcore.io/api',
|
|
73
|
+
MATIC: 'https://api-matic.bitcore.io/api',
|
|
74
|
+
ARB: 'https://api-eth.bitcore.io/api',
|
|
75
|
+
OP: 'https://api-eth.bitcore.io/api',
|
|
76
|
+
BASE: 'https://api-eth.bitcore.io/api',
|
|
77
|
+
ARC: 'https://api-eth.bitcore.io/api',
|
|
78
|
+
XRP: 'https://api-xrp.bitcore.io/api',
|
|
79
|
+
SOL: 'https://api-sol.bitcore.io/api'
|
|
80
|
+
};
|
|
62
81
|
class Wallet {
|
|
63
82
|
constructor(params) {
|
|
64
83
|
Object.assign(this, params);
|
|
65
84
|
if (!this.baseUrl) {
|
|
66
|
-
this.baseUrl = 'https://api.bitcore.io/api';
|
|
85
|
+
this.baseUrl = baseUrls[this.chain.toUpperCase()] || 'https://api.bitcore.io/api';
|
|
67
86
|
}
|
|
68
87
|
this.client = new client_1.Client({
|
|
69
88
|
apiUrl: this.getApiUrl(),
|
|
@@ -109,7 +128,8 @@ class Wallet {
|
|
|
109
128
|
storageType: this.storageType,
|
|
110
129
|
lite,
|
|
111
130
|
addressType: this.addressType,
|
|
112
|
-
addressZero: this.addressZero
|
|
131
|
+
addressZero: this.addressZero,
|
|
132
|
+
version: this.version
|
|
113
133
|
};
|
|
114
134
|
}
|
|
115
135
|
static async deleteWallet(params) {
|
|
@@ -143,13 +163,16 @@ class Wallet {
|
|
|
143
163
|
const keyType = crypto_wallet_core_1.Constants.ALGO_TO_KEY_TYPE[algo];
|
|
144
164
|
hdPrivKey = mnemonic.toHDPrivateKey('', network).derive(crypto_wallet_core_1.Deriver.pathFor(chain, network), keyType);
|
|
145
165
|
}
|
|
146
|
-
const privKeyObj = hdPrivKey.
|
|
147
|
-
const authKey = new PrivateKey();
|
|
148
|
-
const authPubKey = authKey.toPublicKey().toString();
|
|
166
|
+
const privKeyObj = hdPrivKey.toObjectWithBufferPrivateKey();
|
|
149
167
|
const pubKey = hdPrivKey.publicKey.toString();
|
|
150
168
|
const walletEncryptionKey = encryption_1.Encryption.generateEncryptionKey();
|
|
151
169
|
const encryptionKey = encryption_1.Encryption.encryptEncryptionKey(walletEncryptionKey, password);
|
|
152
|
-
const
|
|
170
|
+
const xprivBuffer = crypto_wallet_core_1.BitcoreLib.encoding.Base58Check.decode(privKeyObj.xprivkey);
|
|
171
|
+
privKeyObj.xprivkey = encryption_1.Encryption.encryptBuffer(xprivBuffer, pubKey, walletEncryptionKey).toString('hex');
|
|
172
|
+
privKeyObj.privateKey = encryption_1.Encryption.encryptBuffer(privKeyObj.privateKey, pubKey, walletEncryptionKey).toString('hex');
|
|
173
|
+
const authKey = new PrivateKey();
|
|
174
|
+
const authPubKey = authKey.toPublicKey().toString();
|
|
175
|
+
const masterKeyWithEncryptedPrivateKeys = JSON.stringify(privKeyObj);
|
|
153
176
|
storageType = storageType ? storageType : 'Level';
|
|
154
177
|
storage =
|
|
155
178
|
storage ||
|
|
@@ -159,11 +182,7 @@ class Wallet {
|
|
|
159
182
|
createIfMissing: true,
|
|
160
183
|
storageType
|
|
161
184
|
});
|
|
162
|
-
|
|
163
|
-
try {
|
|
164
|
-
alreadyExists = await this.loadWallet({ storage, name, storageType });
|
|
165
|
-
}
|
|
166
|
-
catch { }
|
|
185
|
+
const alreadyExists = await this.loadWallet({ storage, name, storageType }).catch(() => { });
|
|
167
186
|
if (alreadyExists) {
|
|
168
187
|
throw new Error('Wallet already exists');
|
|
169
188
|
}
|
|
@@ -176,7 +195,7 @@ class Wallet {
|
|
|
176
195
|
encryptionKey,
|
|
177
196
|
authKey,
|
|
178
197
|
authPubKey,
|
|
179
|
-
masterKey:
|
|
198
|
+
masterKey: masterKeyWithEncryptedPrivateKeys,
|
|
180
199
|
password,
|
|
181
200
|
xPubKey: hdPrivKey.xpubkey,
|
|
182
201
|
pubKey,
|
|
@@ -185,7 +204,8 @@ class Wallet {
|
|
|
185
204
|
storageType,
|
|
186
205
|
lite,
|
|
187
206
|
addressType,
|
|
188
|
-
addressZero: null
|
|
207
|
+
addressZero: null,
|
|
208
|
+
version: CURRENT_WALLET_VERSION,
|
|
189
209
|
});
|
|
190
210
|
await storage.saveWallet({ wallet: wallet.toObject(lite) });
|
|
191
211
|
const loadedWallet = await this.loadWallet({
|
|
@@ -194,10 +214,12 @@ class Wallet {
|
|
|
194
214
|
storageType
|
|
195
215
|
});
|
|
196
216
|
if (!xpriv) {
|
|
197
|
-
|
|
217
|
+
process.stdout.write(Buffer.from(mnemonic.phrase));
|
|
218
|
+
process.stdout.write(os_1.default.EOL);
|
|
198
219
|
}
|
|
199
220
|
else {
|
|
200
|
-
|
|
221
|
+
process.stdout.write(hdPrivKey.toBuffer());
|
|
222
|
+
process.stdout.write(os_1.default.EOL);
|
|
201
223
|
}
|
|
202
224
|
await loadedWallet.register().catch(e => {
|
|
203
225
|
console.debug(e);
|
|
@@ -224,12 +246,10 @@ class Wallet {
|
|
|
224
246
|
let { storage } = params;
|
|
225
247
|
storage = storage || new storage_1.Storage({ errorIfExists: false, createIfMissing: false, path, storageType });
|
|
226
248
|
const loadedWallet = await storage.loadWallet({ name });
|
|
227
|
-
if (loadedWallet) {
|
|
228
|
-
return new Wallet(Object.assign(loadedWallet, { storage }));
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
249
|
+
if (!loadedWallet) {
|
|
231
250
|
throw new Error('No wallet could be found');
|
|
232
251
|
}
|
|
252
|
+
return new Wallet(Object.assign(loadedWallet, { storage }));
|
|
233
253
|
}
|
|
234
254
|
isUtxoChain() {
|
|
235
255
|
return ['BTC', 'BCH', 'DOGE', 'LTC'].includes(this.chain?.toUpperCase() || 'BTC');
|
|
@@ -241,7 +261,21 @@ class Wallet {
|
|
|
241
261
|
return ['SOL'].includes(this.chain?.toUpperCase());
|
|
242
262
|
}
|
|
243
263
|
lock() {
|
|
244
|
-
this.unlocked
|
|
264
|
+
if (!this.unlocked) {
|
|
265
|
+
return this;
|
|
266
|
+
}
|
|
267
|
+
if (Buffer.isBuffer(this.unlocked.masterKey.xprivkey)) {
|
|
268
|
+
this.unlocked.masterKey.xprivkey.fill(0);
|
|
269
|
+
}
|
|
270
|
+
if (Buffer.isBuffer(this.unlocked.masterKey.privateKey)) {
|
|
271
|
+
this.unlocked.masterKey.privateKey.fill(0);
|
|
272
|
+
}
|
|
273
|
+
this.unlocked.masterKey = null;
|
|
274
|
+
if (Buffer.isBuffer(this.unlocked.encryptionKey)) {
|
|
275
|
+
this.unlocked.encryptionKey.fill(0);
|
|
276
|
+
}
|
|
277
|
+
this.unlocked.encryptionKey = null;
|
|
278
|
+
this.unlocked = null;
|
|
245
279
|
return this;
|
|
246
280
|
}
|
|
247
281
|
async unlock(password) {
|
|
@@ -249,12 +283,15 @@ class Wallet {
|
|
|
249
283
|
if (!validPass) {
|
|
250
284
|
throw new Error('Incorrect Password');
|
|
251
285
|
}
|
|
252
|
-
const encryptionKey =
|
|
286
|
+
const encryptionKey = encryption_1.Encryption.decryptEncryptionKey(this.encryptionKey, password, true);
|
|
287
|
+
if (this.version != CURRENT_WALLET_VERSION) {
|
|
288
|
+
await this.migrateWallet(encryptionKey);
|
|
289
|
+
}
|
|
253
290
|
let masterKey;
|
|
254
291
|
if (!this.lite) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
masterKey =
|
|
292
|
+
masterKey = JSON.parse(this.masterKey);
|
|
293
|
+
masterKey.xprivkey = encryption_1.Encryption.decryptToBuffer(masterKey.xprivkey, this.pubKey, encryptionKey);
|
|
294
|
+
masterKey.privateKey = encryption_1.Encryption.decryptToBuffer(masterKey.privateKey, this.pubKey, encryptionKey);
|
|
258
295
|
}
|
|
259
296
|
this.unlocked = {
|
|
260
297
|
encryptionKey,
|
|
@@ -262,6 +299,89 @@ class Wallet {
|
|
|
262
299
|
};
|
|
263
300
|
return this;
|
|
264
301
|
}
|
|
302
|
+
async migrateWallet(encryptionKey) {
|
|
303
|
+
const preMigrationVersion = this.version ?? 1;
|
|
304
|
+
if (preMigrationVersion == CURRENT_WALLET_VERSION) {
|
|
305
|
+
console.warn('Wallet migration unnecessarily called - wallet is current version');
|
|
306
|
+
return this;
|
|
307
|
+
}
|
|
308
|
+
if (preMigrationVersion > CURRENT_WALLET_VERSION) {
|
|
309
|
+
console.warn(`Wallet version ${preMigrationVersion} greater than expected current wallet version ${CURRENT_WALLET_VERSION}`);
|
|
310
|
+
return this;
|
|
311
|
+
}
|
|
312
|
+
console.log(`Migrating wallet from version ${preMigrationVersion} to version ${CURRENT_WALLET_VERSION}`);
|
|
313
|
+
const rawWallet = await this.storage.loadWallet({ name: this.name, raw: true });
|
|
314
|
+
if (!rawWallet) {
|
|
315
|
+
throw new Error('Migration failed - wallet not found');
|
|
316
|
+
}
|
|
317
|
+
const backupDir = path_1.default.join(os_1.default.homedir(), '.bitcore', 'bitcoreWallet', 'backup');
|
|
318
|
+
await (0, promises_1.mkdir)(backupDir, { recursive: true });
|
|
319
|
+
const walletFilePath = path_1.default.join(backupDir, `${this.name}.v${preMigrationVersion}.bak`);
|
|
320
|
+
await (0, promises_1.writeFile)(walletFilePath, rawWallet, 'utf8')
|
|
321
|
+
.then(() => console.log(`Pre-migration wallet backup written to ${walletFilePath}`))
|
|
322
|
+
.catch(err => {
|
|
323
|
+
console.error('Wallet backup failed, aborting migration', err.message);
|
|
324
|
+
throw new Error('Migration failure: failed to write wallet backup file. Aborting.');
|
|
325
|
+
});
|
|
326
|
+
const addresses = await this.getAddresses();
|
|
327
|
+
const storedKeys = await this.storage.getStoredKeys({
|
|
328
|
+
addresses,
|
|
329
|
+
name: this.name,
|
|
330
|
+
});
|
|
331
|
+
const backupKeysStr = JSON.stringify(storedKeys);
|
|
332
|
+
const keysFilePath = path_1.default.join(backupDir, `${this.name}_keys.v${preMigrationVersion}.bak`);
|
|
333
|
+
await (0, promises_1.writeFile)(keysFilePath, backupKeysStr, 'utf8')
|
|
334
|
+
.then(() => console.log(`Pre-migration keys backup written to ${keysFilePath}`))
|
|
335
|
+
.catch(err => {
|
|
336
|
+
console.error('Keys backup failed, aborting migration', err.message);
|
|
337
|
+
throw new Error('Migration failure: failed to write keys backup file. Aborting.');
|
|
338
|
+
});
|
|
339
|
+
const masterKeyStr = encryption_1.Encryption.decryptPrivateKey(this.masterKey, this.pubKey, encryptionKey);
|
|
340
|
+
const masterKey = JSON.parse(masterKeyStr);
|
|
341
|
+
if (!(masterKey.xprivkey && masterKey.privateKey)) {
|
|
342
|
+
throw new Error('Migration failure: masterKey is not formatted as expected');
|
|
343
|
+
}
|
|
344
|
+
const xprivBuffer = crypto_wallet_core_1.BitcoreLib.encoding.Base58Check.decode(masterKey.xprivkey);
|
|
345
|
+
const enc_xprivkeyBuffer = encryption_1.Encryption.encryptBuffer(xprivBuffer, this.pubKey, encryptionKey);
|
|
346
|
+
xprivBuffer.fill(0);
|
|
347
|
+
masterKey.xprivkey = enc_xprivkeyBuffer.toString('hex');
|
|
348
|
+
enc_xprivkeyBuffer.fill(0);
|
|
349
|
+
const privateKeyBuffer = Buffer.from(masterKey.privateKey, 'hex');
|
|
350
|
+
const enc_privateKeyBuffer = encryption_1.Encryption.encryptBuffer(privateKeyBuffer, this.pubKey, encryptionKey);
|
|
351
|
+
privateKeyBuffer.fill(0);
|
|
352
|
+
masterKey.privateKey = enc_privateKeyBuffer.toString('hex');
|
|
353
|
+
enc_privateKeyBuffer.fill(0);
|
|
354
|
+
this.masterKey = JSON.stringify(masterKey);
|
|
355
|
+
const newKeys = [];
|
|
356
|
+
for (const key of storedKeys) {
|
|
357
|
+
const { encKey, pubKey } = key;
|
|
358
|
+
const decryptedKey = encryption_1.Encryption.decryptPrivateKey(encKey, pubKey, encryptionKey);
|
|
359
|
+
const decryptedKeyJSON = JSON.parse(decryptedKey);
|
|
360
|
+
const privKeyBuffer = crypto_wallet_core_1.Deriver.privateKeyToBuffer(this.chain, decryptedKeyJSON.privKey);
|
|
361
|
+
const encryptedPrivateKeyBuffer = encryption_1.Encryption.encryptBuffer(privKeyBuffer, pubKey, encryptionKey);
|
|
362
|
+
privKeyBuffer.fill(0);
|
|
363
|
+
decryptedKeyJSON.privKey = encryptedPrivateKeyBuffer.toString('hex');
|
|
364
|
+
newKeys.push(decryptedKeyJSON);
|
|
365
|
+
}
|
|
366
|
+
const overwriteKeys = this.storage.storageType instanceof textFile_1.TextFile
|
|
367
|
+
? this.storage.storageType.migrate({ version: preMigrationVersion, name: this.name, keys: newKeys })
|
|
368
|
+
: this.storage.addKeysSafe({ name: this.name, keys: newKeys });
|
|
369
|
+
await overwriteKeys.catch(err => {
|
|
370
|
+
console.error('Migration failure: updated keys not successfully stored', err);
|
|
371
|
+
throw new Error('Migration failure: keys not successfully stored. Use backups to restore prior wallet and keys.');
|
|
372
|
+
});
|
|
373
|
+
this.version = CURRENT_WALLET_VERSION;
|
|
374
|
+
const storedEncryptedPassword = this.password;
|
|
375
|
+
const walletObj = this.toObject(false);
|
|
376
|
+
walletObj.password = storedEncryptedPassword;
|
|
377
|
+
await this.storage.saveWallet({ wallet: walletObj })
|
|
378
|
+
.catch(err => {
|
|
379
|
+
console.error('Migration failure: wallet not successfully saved', err);
|
|
380
|
+
throw new Error('Migration failure: wallet not successfully saved. Use backups to restore prior wallet and keys');
|
|
381
|
+
});
|
|
382
|
+
console.log('Migration succeeded');
|
|
383
|
+
return this;
|
|
384
|
+
}
|
|
265
385
|
async register(params = {}) {
|
|
266
386
|
const { baseUrl } = params;
|
|
267
387
|
if (baseUrl) {
|
|
@@ -480,24 +600,38 @@ class Wallet {
|
|
|
480
600
|
return this.client.getTransaction({ txid, populated });
|
|
481
601
|
}
|
|
482
602
|
async importKeys(params) {
|
|
483
|
-
const { encryptionKey } = this.unlocked;
|
|
484
603
|
const { rederiveAddys } = params;
|
|
485
604
|
let { keys } = params;
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
605
|
+
keys = keys.map(k => ({ ...k }));
|
|
606
|
+
const keysToSave = [];
|
|
607
|
+
for (const key of keys) {
|
|
608
|
+
if (typeof key.privKey !== 'string') {
|
|
609
|
+
continue;
|
|
610
|
+
}
|
|
611
|
+
let privKeyBuffer;
|
|
612
|
+
try {
|
|
613
|
+
privKeyBuffer = crypto_wallet_core_1.Deriver.privateKeyToBuffer(this.chain, key.privKey);
|
|
614
|
+
if (typeof key.pubKey !== 'string') {
|
|
615
|
+
key.pubKey = crypto_wallet_core_1.Deriver.getPublicKey(this.chain, this.network, privKeyBuffer);
|
|
616
|
+
}
|
|
617
|
+
if (!key.pubKey) {
|
|
618
|
+
throw new Error(`pubKey is undefined for ${this.name}. Keys not added to storage`);
|
|
619
|
+
}
|
|
620
|
+
if (rederiveAddys) {
|
|
621
|
+
key.address = crypto_wallet_core_1.Deriver.getAddress(this.chain, this.network, key.pubKey, this.addressType);
|
|
622
|
+
}
|
|
623
|
+
key.privKey = encryption_1.Encryption.encryptBuffer(privKeyBuffer, key.pubKey, this.unlocked.encryptionKey).toString('hex');
|
|
624
|
+
}
|
|
625
|
+
finally {
|
|
626
|
+
if (Buffer.isBuffer(privKeyBuffer)) {
|
|
627
|
+
privKeyBuffer.fill(0);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
keysToSave.push(key);
|
|
496
631
|
}
|
|
497
632
|
if (keysToSave.length) {
|
|
498
|
-
await this.storage.
|
|
633
|
+
await this.storage.addKeysSafe({
|
|
499
634
|
keys: keysToSave,
|
|
500
|
-
encryptionKey,
|
|
501
635
|
name: this.name
|
|
502
636
|
});
|
|
503
637
|
}
|
|
@@ -523,36 +657,59 @@ class Wallet {
|
|
|
523
657
|
}
|
|
524
658
|
let addresses = [];
|
|
525
659
|
let decryptedKeys;
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
660
|
+
let decryptPrivateKeys = true;
|
|
661
|
+
if (!signingKeys) {
|
|
662
|
+
if (!keys) {
|
|
663
|
+
for (const utxo of utxos) {
|
|
664
|
+
addresses.push(utxo.address);
|
|
665
|
+
}
|
|
666
|
+
addresses = addresses.length > 0 ? addresses : await this.getAddresses();
|
|
667
|
+
decryptedKeys = await this.storage.getStoredKeys({
|
|
668
|
+
addresses,
|
|
669
|
+
name: this.name,
|
|
670
|
+
});
|
|
529
671
|
}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
for (const element of utxos) {
|
|
540
|
-
const keyToDecrypt = keys.find(key => key.address === element.address);
|
|
541
|
-
addresses.push(keyToDecrypt);
|
|
672
|
+
else {
|
|
673
|
+
addresses.push(keys[0]);
|
|
674
|
+
for (const element of utxos) {
|
|
675
|
+
const keyToDecrypt = keys.find(key => key.address === element.address);
|
|
676
|
+
addresses.push(keyToDecrypt);
|
|
677
|
+
}
|
|
678
|
+
const decryptedParams = encryption_1.Encryption.bitcoinCoreDecrypt(addresses, passphrase);
|
|
679
|
+
decryptedKeys = [...decryptedParams.jsonlDecrypted];
|
|
680
|
+
decryptPrivateKeys = false;
|
|
542
681
|
}
|
|
543
|
-
const decryptedParams = encryption_1.Encryption.bitcoinCoreDecrypt(addresses, passphrase);
|
|
544
|
-
decryptedKeys = [...decryptedParams.jsonlDecrypted];
|
|
545
682
|
}
|
|
546
683
|
if (this.isUtxoChain()) {
|
|
547
684
|
const changeKey = await this.derivePrivateKey(true, changeAddressIdx == null ? this.addressIndex : changeAddressIdx);
|
|
548
685
|
await this.importKeys({ keys: [changeKey] });
|
|
549
686
|
}
|
|
687
|
+
const keysForSigning = [...(signingKeys || decryptedKeys)];
|
|
688
|
+
if (decryptPrivateKeys) {
|
|
689
|
+
for (const key of keysForSigning) {
|
|
690
|
+
let privKeyBuf;
|
|
691
|
+
try {
|
|
692
|
+
privKeyBuf = encryption_1.Encryption.decryptToBuffer(key.privKey, key.pubKey, this.unlocked.encryptionKey);
|
|
693
|
+
const nativePrivKey = crypto_wallet_core_1.Deriver.bufferToPrivateKey_TEMP(this.chain, this.network, privKeyBuf);
|
|
694
|
+
key.privKey = nativePrivKey;
|
|
695
|
+
}
|
|
696
|
+
catch (e) {
|
|
697
|
+
console.error('Failed to decrypt/convert private key:', e);
|
|
698
|
+
continue;
|
|
699
|
+
}
|
|
700
|
+
finally {
|
|
701
|
+
if (Buffer.isBuffer(privKeyBuf)) {
|
|
702
|
+
privKeyBuf.fill(0);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
}
|
|
550
707
|
const payload = {
|
|
551
708
|
chain: this.chain,
|
|
552
709
|
network: this.network,
|
|
553
710
|
tx,
|
|
554
|
-
keys:
|
|
555
|
-
key:
|
|
711
|
+
keys: keysForSigning,
|
|
712
|
+
key: keysForSigning[0],
|
|
556
713
|
utxos
|
|
557
714
|
};
|
|
558
715
|
return crypto_wallet_core_1.Transactions.sign({ ...payload });
|
|
@@ -611,8 +768,7 @@ class Wallet {
|
|
|
611
768
|
return this.client.getBlockTip();
|
|
612
769
|
}
|
|
613
770
|
async derivePrivateKey(isChange, addressIndex = this.addressIndex) {
|
|
614
|
-
|
|
615
|
-
return keyToImport;
|
|
771
|
+
return crypto_wallet_core_1.Deriver.derivePrivateKey(this.chain, this.network, this.unlocked.masterKey, addressIndex || 0, isChange, this.addressType);
|
|
616
772
|
}
|
|
617
773
|
async nextAddressPair(withChangeAddress) {
|
|
618
774
|
return this.generateAddressPair(this.addressIndex, withChangeAddress);
|
|
@@ -682,7 +838,7 @@ class Wallet {
|
|
|
682
838
|
let existingTx;
|
|
683
839
|
if (rawTx) {
|
|
684
840
|
if (lib.ethers) {
|
|
685
|
-
existingTx = lib.ethers.
|
|
841
|
+
existingTx = lib.ethers.Transaction.from(rawTx);
|
|
686
842
|
}
|
|
687
843
|
else {
|
|
688
844
|
const tx = new lib.Transaction(rawTx);
|