@bitpay-labs/bitcore-client 11.11.4 → 11.11.6

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.
Files changed (35) hide show
  1. package/package.json +14 -9
  2. package/ts_build/src/wallet.d.ts +3 -3
  3. package/.mocharc.json +0 -6
  4. package/LICENSE +0 -21
  5. package/mcr.config.js +0 -16
  6. package/src/client.ts +0 -275
  7. package/src/encryption.ts +0 -191
  8. package/src/index.ts +0 -21
  9. package/src/storage/level.ts +0 -171
  10. package/src/storage/mongo.ts +0 -191
  11. package/src/storage/textFile.ts +0 -327
  12. package/src/storage.ts +0 -271
  13. package/src/stream-util.ts +0 -80
  14. package/src/types/index.d.ts +0 -2
  15. package/src/types/storage.d.ts +0 -1
  16. package/src/types/wallet.d.ts +0 -36
  17. package/src/utils.ts +0 -35
  18. package/src/wallet.ts +0 -1221
  19. package/test/unit/data/ethMigrationTestWallet.fixture.ts +0 -68
  20. package/test/unit/wallet.arc.test.ts +0 -10
  21. package/test/unit/wallet.test.ts +0 -1177
  22. package/ts_build/test/unit/data/ethMigrationTestWallet.fixture.d.ts +0 -51
  23. package/ts_build/test/unit/data/ethMigrationTestWallet.fixture.d.ts.map +0 -1
  24. package/ts_build/test/unit/data/ethMigrationTestWallet.fixture.js +0 -68
  25. package/ts_build/test/unit/data/ethMigrationTestWallet.fixture.js.map +0 -1
  26. package/ts_build/test/unit/wallet.arc.test.d.ts +0 -2
  27. package/ts_build/test/unit/wallet.arc.test.d.ts.map +0 -1
  28. package/ts_build/test/unit/wallet.arc.test.js +0 -12
  29. package/ts_build/test/unit/wallet.arc.test.js.map +0 -1
  30. package/ts_build/test/unit/wallet.test.d.ts +0 -2
  31. package/ts_build/test/unit/wallet.test.d.ts.map +0 -1
  32. package/ts_build/test/unit/wallet.test.js +0 -1037
  33. package/ts_build/test/unit/wallet.test.js.map +0 -1
  34. package/tsconfig.json +0 -40
  35. package/tsconfig.prod.json +0 -6
package/package.json CHANGED
@@ -1,13 +1,17 @@
1
1
  {
2
2
  "name": "@bitpay-labs/bitcore-client",
3
3
  "description": "Wallet client for Bitcore-Node",
4
- "version": "11.11.4",
4
+ "version": "11.11.6",
5
5
  "author": "Justin Langston <nitsujlangston@gmail.com>",
6
6
  "main": "./ts_build/src/index.js",
7
7
  "types": "./ts_build/src/index.d.ts",
8
8
  "bin": {
9
9
  "bitcore-client": "./bin/wallet"
10
10
  },
11
+ "files": [
12
+ "bin",
13
+ "ts_build"
14
+ ],
11
15
  "engines": {
12
16
  "node": ">=18.0.0"
13
17
  },
@@ -21,9 +25,9 @@
21
25
  "clean": "rm -rf ./ts_build",
22
26
  "pub": "npm run compile && npm publish",
23
27
  "watch": "tsc --watch",
24
- "precompile": "cd ../bitcore-node && npm run clean && npm run build:prod",
25
- "compile": "npm run clean && npm run build",
26
- "test": "npm run compile && mcr mocha ts_build/test",
28
+ "compile": "npm run clean && npm run build:prod",
29
+ "test:types": "tsc --noEmit -p tsconfig.json",
30
+ "test": "npm run compile && npm run test:types && npm run build && mcr mocha ts_build/test",
27
31
  "lint": "eslint .",
28
32
  "fix:errors": "eslint --fix --quiet .",
29
33
  "fix:all": "eslint --fix .",
@@ -31,20 +35,20 @@
31
35
  },
32
36
  "dependencies": {
33
37
  "@bitpay-labs/bitcore-mnemonic": "^11.11.2",
34
- "@bitpay-labs/crypto-wallet-core": "^11.11.4",
35
- "async": "2.5.0",
38
+ "@bitpay-labs/crypto-wallet-core": "^11.11.5",
39
+ "async": "2.6.4",
36
40
  "bcrypt": "5.1.0",
37
41
  "commander": "11.1.0",
38
42
  "level-js": "4.0.2",
39
43
  "leveldown": "6.1.1",
40
44
  "levelup": "4.3.2",
41
- "mkdirp": "0.5.1",
45
+ "mkdirp": "0.5.6",
42
46
  "mongodb": "^3.6.0",
43
47
  "progress": "2.0.0",
44
48
  "promptly": "3.0.3",
45
49
  "request": "2.87.0",
46
50
  "request-promise-native": "1.0.5",
47
- "secp256k1": "3.7.1",
51
+ "secp256k1": "3.8.1",
48
52
  "source-map-support": "0.5.13"
49
53
  },
50
54
  "devDependencies": {
@@ -59,11 +63,12 @@
59
63
  "@types/request": "2.48.1",
60
64
  "@types/request-promise-native": "1.0.15",
61
65
  "@types/secp256k1": "3.5.0",
66
+ "@types/sinon": "^22.0.0",
62
67
  "chai": "5.1.2",
63
68
  "mocha": "11.1.0",
64
69
  "sinon": "19.0.2",
65
70
  "supertest": "7.0.0",
66
71
  "typescript": "5.7.3"
67
72
  },
68
- "gitHead": "1eb34cc33d0628f9304be08a19da5315f140e70f"
73
+ "gitHead": "e091d99915d099863ad3e78dbe867aa7780191e4"
69
74
  }
@@ -107,7 +107,7 @@ export declare class Wallet {
107
107
  }): Promise<any>;
108
108
  getUtxos(params?: {
109
109
  includeSpent?: boolean;
110
- }): import("node_modules/@types/request").Request;
110
+ }): import("request").Request;
111
111
  getUtxosArray(params?: {
112
112
  includeSpent?: boolean;
113
113
  }): Promise<unknown>;
@@ -115,7 +115,7 @@ export declare class Wallet {
115
115
  tokenName?: string;
116
116
  token?: string;
117
117
  }): any;
118
- listTransactions(params: any): import("node_modules/@types/request").Request;
118
+ listTransactions(params: any): import("request").Request;
119
119
  getToken(contractAddress: any): Promise<any>;
120
120
  addToken(params: any): Promise<void>;
121
121
  rmToken({ tokenName }: {
@@ -177,7 +177,7 @@ export declare class Wallet {
177
177
  deriveAddress(addressIndex: any, isChange: any): string;
178
178
  solSignMessage(privateKey: any, message: any): Promise<string>;
179
179
  getBlockTip(): Promise<any>;
180
- derivePrivateKey(isChange: any, addressIndex?: number): Promise<import("node_modules/@bitpay-labs/crypto-wallet-core/ts_build/src/types/derivation").Key>;
180
+ derivePrivateKey(isChange: any, addressIndex?: number): Promise<import("@bitpay-labs/crypto-wallet-core/ts_build/src/types/derivation").Key>;
181
181
  nextAddressPair(withChangeAddress?: boolean): Promise<any[]>;
182
182
  generateAddressPair(addressIndex: number, withChangeAddress?: boolean): Promise<any[]>;
183
183
  nextAddressPairLite(withChangeAddress?: boolean): Promise<any[]>;
package/.mocharc.json DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "enable-source-maps": true,
3
- "exit": true,
4
- "recursive": true,
5
- "extension": ".test.js"
6
- }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 BitPay, Inc.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/mcr.config.js DELETED
@@ -1,16 +0,0 @@
1
- // @ts-check
2
- /* eslint-disable */
3
- const builder = require('../../coverage-builder.js').default;
4
-
5
- /**
6
- * @type {import('monocart-coverage-reports').CoverageReportOptions}
7
- */
8
- const config = builder({
9
- bytes: 60,
10
- statements: 50,
11
- branches: 40,
12
- functions: 50,
13
- lines: 50
14
- });
15
-
16
- module.exports = config;
package/src/client.ts DELETED
@@ -1,275 +0,0 @@
1
- import { URL } from 'url';
2
- import { BitcoreLib } from '@bitpay-labs/crypto-wallet-core';
3
- import requestStream from 'request';
4
- import request from 'request-promise-native';
5
- import * as secp256k1 from 'secp256k1';
6
- import { utils } from './utils';
7
-
8
- const usingBrowser = (global as any).window;
9
- const URLClass = usingBrowser ? usingBrowser.URL : URL;
10
- export class Client {
11
- apiUrl: string;
12
- authKey: any;
13
-
14
- constructor(params: {
15
- apiUrl: string;
16
- authKey: BitcoreLib.PrivateKey;
17
- }) {
18
- this.apiUrl = params.apiUrl;
19
- this.authKey = params.authKey;
20
- }
21
-
22
- async _request(params: request.OptionsWithUrl) {
23
- try {
24
- return await request(params);
25
- } catch (err) {
26
- if (err.statusCode) {
27
- throw new Error(`${err.statusCode} - ${params.method}: ${params.url} - "${JSON.stringify(err.error)}"`);
28
- } else if (err.error instanceof Error) {
29
- throw err.error;
30
- }
31
- throw err;
32
- }
33
- }
34
-
35
- _buildQueryString( params: any) {
36
- const query = [];
37
- for (const [key, value] of Object.entries(params)) {
38
- value && query.push(`${key}=${value}`);
39
- }
40
- return query.length ? `?${query.join('&')}` : '';
41
- }
42
-
43
- getMessage(params: { method: string; url: string; payload?: any }) {
44
- const { method, url, payload = {} } = params;
45
- const parsedUrl = new URLClass(url);
46
- return [method, parsedUrl.pathname + parsedUrl.search, JSON.stringify(payload)].join('|');
47
- }
48
-
49
- sign(params: { method: string; url: string; payload?: any }) {
50
- const message = this.getMessage(params);
51
- const privateKey = this.authKey.toBuffer();
52
- const messageHash = BitcoreLib.crypto.Hash.sha256sha256(Buffer.from(message));
53
- return secp256k1.sign(messageHash, privateKey).signature.toString('hex');
54
- }
55
-
56
- async register(params: { payload: { baseUrl?: string } & any }) {
57
- const { payload } = params;
58
- // allow you to overload the client's baseUrl
59
- const { baseUrl = this.apiUrl } = payload;
60
- const url = `${baseUrl}/wallet`;
61
- const signature = this.sign({ method: 'POST', url, payload });
62
- return this._request({
63
- method: 'POST',
64
- url,
65
- headers: { 'x-signature': signature },
66
- body: payload,
67
- json: true
68
- });
69
- }
70
-
71
- async getToken(contractAddress) {
72
- const url = `${this.apiUrl}/token/${contractAddress}`;
73
- return this._request({ method: 'GET', url, json: true });
74
- }
75
-
76
- async getSolanaTokens(address) {
77
- const url = `${this.apiUrl}/ata/${address}`;
78
- return this._request({ method: 'GET', url, json: true });
79
- }
80
-
81
- async getBalance(params: { payload?: any; pubKey: string; time?: string; address?: string; hex?: boolean }) {
82
- const { payload, pubKey, time, address, hex } = params;
83
- let url = `${this.apiUrl}/wallet/${pubKey}/balance`;
84
- if (time) {
85
- url += `/${time}`;
86
- }
87
- const query = [];
88
- if (payload?.tokenContractAddress) {
89
- query.push(`tokenAddress=${payload.tokenContractAddress}`);
90
- }
91
- if (address) {
92
- query.push(`address=${address}`);
93
- }
94
- if (hex) {
95
- query.push('hex=true');
96
- }
97
- url += query.length ? `?${query.join('&')}` : '';
98
- const signature = this.sign({ method: 'GET', url });
99
- return this._request({
100
- method: 'GET',
101
- url,
102
- headers: { 'x-signature': signature },
103
- json: true
104
- });
105
- }
106
-
107
- async getTransaction(params: { txid: string; populated?: boolean }) {
108
- const { txid, populated } = params;
109
- const url = `${this.apiUrl}/tx/${txid}${populated ? '/populated' : ''}`;
110
- return this._request({ method: 'GET', url, json: true });
111
- }
112
-
113
- async getNonce(params) {
114
- const { address } = params;
115
- const url = `${this.apiUrl}/address/${address}/txs/count`;
116
- return this._request({ method: 'GET', url, json: true });
117
- }
118
-
119
- getAddressTxos = async function(params) {
120
- const { unspent, address } = params;
121
- const args = unspent ? `?unspent=${unspent}` : '';
122
- const url = `${this.apiUrl}/address/${address}${args}`;
123
- return this._request({ method: 'GET', url, json: true });
124
- };
125
-
126
- getCoins(params: { payload?: any; pubKey: string; includeSpent: boolean }) {
127
- const { payload, pubKey, includeSpent } = params;
128
- const url = `${this.apiUrl}/wallet/${pubKey}/utxos?includeSpent=${includeSpent}`;
129
- const signature = this.sign({ method: 'GET', url, payload });
130
- return requestStream.get(url, {
131
- headers: { 'x-signature': signature },
132
- body: payload,
133
- json: true
134
- });
135
- }
136
-
137
- listTransactions(params) {
138
- const { pubKey, startBlock, startDate, endBlock, endDate, includeMempool, payload, tokenContractAddress, limit } = params;
139
- let url = `${this.apiUrl}/wallet/${pubKey}/transactions`;
140
- let query = '';
141
- if (startBlock) {
142
- query += `startBlock=${startBlock}&`;
143
- }
144
- if (endBlock) {
145
- query += `endBlock=${endBlock}&`;
146
- }
147
- if (startDate) {
148
- query += `startDate=${startDate}&`;
149
- }
150
- if (endDate) {
151
- query += `endDate=${endDate}&`;
152
- }
153
- if (includeMempool) {
154
- query += 'includeMempool=true&';
155
- }
156
- if (tokenContractAddress) {
157
- query += `tokenAddress=${tokenContractAddress}&`;
158
- }
159
- if (limit) {
160
- query += `limit=${limit}&`;
161
- }
162
- query = query.endsWith('&') ? query.slice(0, -1) : query;
163
- if (query) {
164
- url += '?' + query;
165
- }
166
- const signature = this.sign({ method: 'GET', url, payload });
167
- return requestStream.get(url, {
168
- headers: { 'x-signature': signature },
169
- body: payload,
170
- json: true
171
- });
172
- }
173
-
174
- async getFee(params) {
175
- const { target, txType } = params;
176
- const url = `${this.apiUrl}/fee/${target}${this._buildQueryString({ txType })}`;
177
- const result = await this._request({ method: 'GET', url, json: true });
178
- if (result.errors?.length) {
179
- throw new Error(result.errors[0]);
180
- }
181
- return result;
182
- }
183
-
184
- async getPriorityFee(params) {
185
- const { percentile } = params;
186
- const url = `${this.apiUrl}/priorityFee/${percentile}`;
187
- const result = await this._request({ method: 'GET', url, json: true });
188
- if (result.errors?.length) {
189
- throw new Error(result.errors[0]);
190
- }
191
- return result;
192
- }
193
-
194
- async importAddresses(params: { pubKey: string; payload: Array<{ address: string }> }): Promise<void> {
195
- const { payload, pubKey } = params;
196
- const url = `${this.apiUrl}/wallet/${pubKey}`;
197
- const pageSize = 100;
198
-
199
- for (let i = 0; i < payload.length; i += pageSize) {
200
- const body = payload.slice(i, i + pageSize);
201
- if (payload.length > pageSize) {
202
- // If we're paginating through a long list of addresses, log progress so the user knows something is happening
203
- console.log(`Importing addresses ${i + 1}-${i + body.length} of ${payload.length}`);
204
- }
205
- if (i >= pageSize) {
206
- await utils.sleep(1000); // cooldown
207
- }
208
-
209
- const signature = this.sign({ method: 'POST', url, payload: body });
210
-
211
- await this._request({
212
- method: 'POST',
213
- url,
214
- headers: { 'x-signature': signature },
215
- body,
216
- json: true
217
- });
218
- }
219
- }
220
-
221
- async broadcast(params) {
222
- const { payload } = params;
223
- const url = `${this.apiUrl}/tx/send`;
224
- return this._request({ method: 'POST', url, body: payload, json: true });
225
- }
226
-
227
- async checkWallet(params) {
228
- const { pubKey } = params;
229
- const url = `${this.apiUrl}/wallet/${pubKey}/check`;
230
- const signature = this.sign({ method: 'GET', url });
231
- return this._request({
232
- method: 'GET',
233
- url,
234
- headers: { 'x-signature': signature },
235
- json: true
236
- });
237
- }
238
-
239
- getAddresses(params: { pubKey: string }) {
240
- const { pubKey } = params;
241
- const url = `${this.apiUrl}/wallet/${pubKey}/addresses`;
242
- const signature = this.sign({ method: 'GET', url });
243
- return this._request({
244
- method: 'GET',
245
- url,
246
- headers: { 'x-signature': signature },
247
- json: true
248
- });
249
- }
250
-
251
- getAccountFlags(params: { address: string }) {
252
- const { address } = params;
253
- const url = `${this.apiUrl}/address/${address}/flags`;
254
- return this._request({ method: 'GET', url, json: true });
255
- }
256
-
257
- estimateGas(params: { to: string; from: string; data: string; value: string }) {
258
- const { to, from, data, value } = params;
259
- const body = { to, from, data, value };
260
- const url = `${this.apiUrl}/gas`;
261
- return this._request({ method: 'POST', url, json: true, body });
262
- }
263
-
264
- getL1Fee(params: { rawTx: string; safe?: boolean }) {
265
- const { rawTx, safe } = params;
266
- const body = { rawTx };
267
- const url = `${this.apiUrl}/l1/fee${safe ? '?safe=true' : ''}`;
268
- return this._request({ method: 'POST', url, json: true, body });
269
- }
270
-
271
- getBlockTip() {
272
- const url = `${this.apiUrl}/block/tip`;
273
- return this._request({ method: 'GET', url, json: true });
274
- }
275
- }
package/src/encryption.ts DELETED
@@ -1,191 +0,0 @@
1
- import crypto from 'crypto';
2
- import { BitcoreLib as bitcore } from '@bitpay-labs/crypto-wallet-core';
3
-
4
- export function shaHash(data, algo = 'sha256') {
5
- const hash = crypto
6
- .createHash(algo)
7
- .update(data, 'utf8')
8
- .digest('hex')
9
- .toUpperCase();
10
- return hash;
11
- }
12
-
13
- const SHA512 = data => shaHash(data, 'sha512');
14
- const SHA256 = data => shaHash(data, 'sha256');
15
- const algo = 'aes-256-cbc';
16
-
17
- export function encryptEncryptionKey(encryptionKey, password) {
18
- const password_hash = Buffer.from(SHA512(password));
19
- const key = password_hash.subarray(0, 32);
20
- const iv = password_hash.subarray(32, 48);
21
- const cipher = crypto.createCipheriv(algo, key, iv);
22
- const encData = cipher.update(encryptionKey, 'hex', 'hex') + cipher.final('hex');
23
- return encData;
24
- }
25
-
26
- export function decryptEncryptionKey(encEncryptionKey, password, toBuffer: true): Buffer;
27
- export function decryptEncryptionKey(encEncryptionKey, password, toBuffer: false): string;
28
- export function decryptEncryptionKey(encEncryptionKey, password, toBuffer?: boolean): Buffer | string {
29
- const password_hash = Buffer.from(SHA512(password));
30
- const key = password_hash.subarray(0, 32);
31
- const iv = password_hash.subarray(32, 48);
32
- const decipher = crypto.createDecipheriv(algo, key, iv);
33
-
34
- let payload: Buffer | undefined;
35
- let final: Buffer | undefined;
36
- let output: Buffer | undefined;
37
- try {
38
- payload = decipher.update(encEncryptionKey, 'hex');
39
- final = decipher.final();
40
- output = Buffer.concat([payload, final]);
41
- return toBuffer ? output : output.toString('hex');
42
- } finally {
43
- payload.fill(0);
44
- final.fill(0);
45
- if (!toBuffer) {
46
- // Don't fill output if it's what's returned directly
47
- output.fill(0);
48
- }
49
- }
50
- }
51
-
52
- /** @deprecated - Use encryptBuffer */
53
- export function encryptPrivateKey(privKey, pubKey, encryptionKey) {
54
- encryptionKey = Buffer.from(encryptionKey, 'hex');
55
- privKey = Buffer.from(privKey, 'utf8');
56
- return encryptBuffer(privKey, pubKey, encryptionKey).toString('hex');
57
- }
58
-
59
- function decryptPrivateKey(encPrivateKey: string, pubKey: string, encryptionKey: Buffer | string) {
60
- if (!Buffer.isBuffer(encryptionKey)) {
61
- encryptionKey = Buffer.from(encryptionKey, 'hex');
62
- }
63
- const doubleHash = Buffer.from(SHA256(SHA256(pubKey)), 'hex');
64
- const iv = doubleHash.subarray(0, 16);
65
- const decipher = crypto.createDecipheriv(algo, encryptionKey, iv);
66
- const decrypted = decipher.update(encPrivateKey, 'hex', 'utf8') + decipher.final('utf8');
67
- return decrypted;
68
- }
69
-
70
- function encryptBuffer(data: Buffer, pubKey: string, encryptionKey: Buffer): Buffer {
71
- let payload: Buffer | undefined;
72
- try {
73
- const iv = Buffer.from(SHA256(SHA256(pubKey)), 'hex').subarray(0, 16);
74
- const cipher = crypto.createCipheriv(algo, encryptionKey, iv);
75
- payload = cipher.update(data);
76
- return Buffer.concat([payload, cipher.final()]);
77
- } finally {
78
- if (Buffer.isBuffer(payload)) {
79
- payload.fill(0);
80
- }
81
- }
82
- }
83
-
84
- function decryptToBuffer(encHex: string, pubKey: string, encryptionKey: Buffer): Buffer {
85
- let decrypted: Buffer | undefined;
86
- let final: Buffer | undefined;
87
- try {
88
- const iv = Buffer.from(SHA256(SHA256(pubKey)), 'hex').subarray(0, 16);
89
- const decipher = crypto.createDecipheriv(algo, encryptionKey, iv);
90
- decrypted = decipher.update(encHex, 'hex');
91
- final = decipher.final();
92
- return Buffer.concat([decrypted, final]);
93
- } finally {
94
- if (Buffer.isBuffer(decrypted)) {
95
- decrypted.fill(0);
96
- }
97
- if (Buffer.isBuffer(final)) {
98
- final.fill(0);
99
- }
100
- }
101
- }
102
-
103
- function sha512KDF(passphrase: string, salt: Buffer, derivationOptions: { rounds?: number }): string {
104
- const rounds = derivationOptions.rounds || 1;
105
- // if salt was sent in as a string, we will have to assume the default encoding type
106
- if (!Buffer.isBuffer(salt)) {
107
- salt = Buffer.from(salt, 'hex');
108
- }
109
- let derivation: Buffer<ArrayBufferLike> = Buffer.concat([Buffer.from(''), Buffer.from(passphrase), salt]);
110
- for (let i = 0; i < rounds; i++) {
111
- derivation = crypto
112
- .createHash('sha512')
113
- .update(derivation)
114
- .digest();
115
- }
116
- return derivation.toString('hex');
117
- }
118
-
119
- export function bitcoinCoreDecrypt(
120
- jsonl: Array<{
121
- cipherText?: string;
122
- derivationMethod?: string;
123
- rounds?: number;
124
- salt?: Buffer;
125
- pubKey?: string;
126
- address?: string;
127
- }>,
128
- passphrase: string
129
- ) {
130
- const derivationMethods = { SHA512: 0 };
131
- let master = null;
132
- const jsonlDecrypted = [];
133
- for (const line of jsonl) {
134
- const cipherText = line.cipherText;
135
- if (line.derivationMethod) {
136
- const salt = line.salt;
137
- const derivationOptions = {
138
- method: derivationMethods[line.derivationMethod],
139
- rounds: line.rounds
140
- };
141
- // derive the key from passphrase
142
- const key = sha512KDF(passphrase, salt, derivationOptions);
143
- master = decrypt({ cipherText, key });
144
- } else {
145
- const privKey = decrypt({
146
- key: master,
147
- iv: bitcore.crypto.Hash.sha256sha256(Buffer.from(line.pubKey, 'hex')),
148
- cipherText
149
- });
150
- const address = line.address.split(':');
151
- const keyObj = {
152
- privKey,
153
- pubKey: line.pubKey,
154
- address: address[address.length - 1]
155
- };
156
- jsonlDecrypted.push(keyObj);
157
- }
158
- }
159
- return { jsonlDecrypted, master };
160
- }
161
-
162
- function decrypt(opts: { key?: string; iv?: Buffer | string; cipherText?: string }) {
163
- const key = Buffer.from(opts.key, 'hex');
164
- let secondHalf;
165
- if (opts.iv) {
166
- secondHalf = opts.iv.slice(0, 16);
167
- } else {
168
- secondHalf = key.subarray(32, 48); // AES256-cbc IV
169
- }
170
- const cipherText = Buffer.from(opts.cipherText, 'hex');
171
- const firstHalf = key.subarray(0, 32); // AES256-cbc shared key
172
- const AESDecipher = crypto.createDecipheriv(algo, firstHalf, secondHalf);
173
- const plainText = Buffer.concat([AESDecipher.update(cipherText), AESDecipher.final()]).toString('hex');
174
-
175
- return plainText;
176
- }
177
-
178
- export function generateEncryptionKey() {
179
- return crypto.randomBytes(32);
180
- }
181
-
182
- export const Encryption = {
183
- encryptEncryptionKey,
184
- decryptEncryptionKey,
185
- encryptPrivateKey,
186
- decryptPrivateKey,
187
- encryptBuffer,
188
- decryptToBuffer,
189
- generateEncryptionKey,
190
- bitcoinCoreDecrypt
191
- };
package/src/index.ts DELETED
@@ -1,21 +0,0 @@
1
- import 'source-map-support/register';
2
- import * as CryptoWalletCore from '@bitpay-labs/crypto-wallet-core';
3
- import { Client } from './client';
4
- import { Encryption } from './encryption';
5
- import { Storage } from './storage';
6
- import { ParseApiStream, StreamUtil } from './stream-util';
7
- import { Wallet } from './wallet';
8
-
9
- export * from './wallet';
10
- export {
11
- Wallet,
12
- Client,
13
- Storage,
14
- ParseApiStream,
15
- Encryption,
16
- StreamUtil,
17
- CryptoWalletCore
18
- };
19
-
20
- // Types
21
- export type * as Types from './types';