@atomicfinance/utils 4.2.7 → 4.2.8
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/dist/index.d.ts +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/lazyEcc.d.ts +42 -0
- package/dist/lazyEcc.js +61 -0
- package/dist/lazyEcc.js.map +1 -0
- package/lib/index.ts +1 -0
- package/lib/lazyEcc.ts +59 -0
- package/package.json +16 -4
package/dist/index.d.ts
CHANGED
|
@@ -10,3 +10,4 @@ declare function validateSecret(secret: string): void;
|
|
|
10
10
|
declare function validateSecretAndHash(secret: string, secretHash: string): void;
|
|
11
11
|
declare function validateExpiration(expiration: number): void;
|
|
12
12
|
export { sleep, addressToString, asyncSetImmediate, caseInsensitiveEqual, validateValue, validateSecret, validateSecretHash, validateSecretAndHash, validateExpiration, };
|
|
13
|
+
export { getEcc, getECPair } from './lazyEcc';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getECPair = exports.getEcc = void 0;
|
|
3
4
|
exports.sleep = sleep;
|
|
4
5
|
exports.addressToString = addressToString;
|
|
5
6
|
exports.asyncSetImmediate = asyncSetImmediate;
|
|
@@ -80,4 +81,7 @@ function validateExpiration(expiration) {
|
|
|
80
81
|
throw new errors_1.InvalidExpirationError(`Invalid expiration. Out of bounds: ${expiration}`);
|
|
81
82
|
}
|
|
82
83
|
}
|
|
84
|
+
var lazyEcc_1 = require("./lazyEcc");
|
|
85
|
+
Object.defineProperty(exports, "getEcc", { enumerable: true, get: function () { return lazyEcc_1.getEcc; } });
|
|
86
|
+
Object.defineProperty(exports, "getECPair", { enumerable: true, get: function () { return lazyEcc_1.getECPair; } });
|
|
83
87
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;AAuGE,sBAAK;AACL,0CAAe;AACf,8CAAiB;AACjB,oDAAoB;AACpB,sCAAa;AACb,wCAAc;AACd,gDAAkB;AAClB,sDAAqB;AACrB,gDAAkB;AA/GpB,wBAAsB;AAEtB,kDAA+C;AAC/C,kDAG+B;AAC/B,gDAA0D;AAE1D,SAAS,eAAe,CAAC,OAAyB;IAChD,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,OAAO,CAAC;;QAC3C,OAAO,OAAO,CAAC,OAAO,CAAC;AAC9B,CAAC;AAED,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED,SAAS,iBAAiB;IACxB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;AACzD,CAAC;AAED,SAAS,oBAAoB,CAAC,IAAY,EAAE,KAAa;IACvD,IAAI,GAAG,IAAI,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;IAClC,KAAK,GAAG,KAAK,IAAI,KAAK,CAAC,WAAW,EAAE,CAAC;IAErC,OAAO,IAAI,KAAK,KAAK,CAAC;AACxB,CAAC;AAED,SAAS,aAAa,CAAC,KAAgB;IACrC,IAAI,CAAC,iBAAS,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CAAC,kBAAkB,KAAK,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,kBAAkB,KAAK,E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qBAAqB,CAAC,MAAc,EAAE,UAAkB;IAC/D,cAAc,CAAC,MAAM,CAAC,CAAC;IACvB,kBAAkB,CAAC,UAAU,CAAC,CAAC;IAE/B,MAAM,kBAAkB,GAAG,MAAM,CAAC,IAAI,CAAC,IAAA,eAAM,EAAC,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC;IAC9D,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC;QAC/D,MAAM,IAAI,2BAAkB,CAC1B,wDAAwD,UAAU,EAAE,CACrE,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAS,kBAAkB,CAAC,UAAkB;IAC5C,IAAI,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,+BAAsB,CAAC,4BAA4B,UAAU,EAAE,CAAC,CAAC;IAC7E,CAAC;IAED,IAAI,UAAU,GAAG,SAAS,IAAI,UAAU,GAAG,aAAa,EAAE,CAAC;QACzD,MAAM,IAAI,+BAAsB,CAC9B,sCAAsC,UAAU,EAAE,CACnD,CAAC;IACJ,CAAC;AACH,CAAC;AAaD,qCAA8C;AAArC,iGAAA,MAAM,OAAA;AAAE,oGAAA,SAAS,OAAA"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazy accessors for `@bitcoin-js/tiny-secp256k1-asmjs` and the matching
|
|
3
|
+
* `ECPair` factory.
|
|
4
|
+
*
|
|
5
|
+
* Why this exists: cold-start measurements showed ~3.8 s of unlock time
|
|
6
|
+
* spent inside two top-level `const ECPair = ECPairFactory(ecc)` calls
|
|
7
|
+
* across the providers. The cost has two sources:
|
|
8
|
+
*
|
|
9
|
+
* 1. Module-eval of `secp256k1.asm.js` (32k+ lines). On Hermes there is
|
|
10
|
+
* no AOT for asm.js, so parse + eval blocks the JS thread.
|
|
11
|
+
* 2. ECPair's factory runs a validation pass (~150 secp256k1 ops)
|
|
12
|
+
* against the supplied `ecc` impl every time it's called. With
|
|
13
|
+
* Hermes interpreting asm.js at ~10 ms/op, that's ~1.6 s per call
|
|
14
|
+
* EVEN AFTER the module cache is warm.
|
|
15
|
+
*
|
|
16
|
+
* Both costs were paid on the unlock-screen critical path because the
|
|
17
|
+
* providers ran `ECPairFactory(ecc)` at module top level. By routing
|
|
18
|
+
* everything through these lazy getters, cold start does zero secp256k1
|
|
19
|
+
* work; the first signing/verification operation pays a one-time bill,
|
|
20
|
+
* which is acceptable because it lands on a user-initiated action.
|
|
21
|
+
*
|
|
22
|
+
* Usage in providers:
|
|
23
|
+
* - Replace `import * as ecc from '@bitcoin-js/tiny-secp256k1-asmjs'`
|
|
24
|
+
* and `const ECPair = ECPairFactory(ecc)` with imports from here.
|
|
25
|
+
* - Replace `ecc.verify(...)` with `getEcc().verify(...)`.
|
|
26
|
+
* - Replace `ECPair.fromWIF(...)` with `getECPair().fromWIF(...)`.
|
|
27
|
+
*
|
|
28
|
+
* The `require()` calls are deliberate \u2014 a static `import` would
|
|
29
|
+
* re-introduce module-eval at the top of this file, defeating the point.
|
|
30
|
+
*/
|
|
31
|
+
import type { ECPairAPI, TinySecp256k1Interface } from 'ecpair';
|
|
32
|
+
/**
|
|
33
|
+
* Returns the (cached) `@bitcoin-js/tiny-secp256k1-asmjs` module. First
|
|
34
|
+
* call triggers asm.js parse/eval; subsequent calls are O(1).
|
|
35
|
+
*/
|
|
36
|
+
export declare function getEcc(): TinySecp256k1Interface;
|
|
37
|
+
/**
|
|
38
|
+
* Returns the (cached) `ECPair` factory bound to `getEcc()`. First call
|
|
39
|
+
* triggers ECPair's secp256k1 validation pass (~1.6 s on Hermes);
|
|
40
|
+
* subsequent calls are O(1).
|
|
41
|
+
*/
|
|
42
|
+
export declare function getECPair(): ECPairAPI;
|
package/dist/lazyEcc.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Lazy accessors for `@bitcoin-js/tiny-secp256k1-asmjs` and the matching
|
|
4
|
+
* `ECPair` factory.
|
|
5
|
+
*
|
|
6
|
+
* Why this exists: cold-start measurements showed ~3.8 s of unlock time
|
|
7
|
+
* spent inside two top-level `const ECPair = ECPairFactory(ecc)` calls
|
|
8
|
+
* across the providers. The cost has two sources:
|
|
9
|
+
*
|
|
10
|
+
* 1. Module-eval of `secp256k1.asm.js` (32k+ lines). On Hermes there is
|
|
11
|
+
* no AOT for asm.js, so parse + eval blocks the JS thread.
|
|
12
|
+
* 2. ECPair's factory runs a validation pass (~150 secp256k1 ops)
|
|
13
|
+
* against the supplied `ecc` impl every time it's called. With
|
|
14
|
+
* Hermes interpreting asm.js at ~10 ms/op, that's ~1.6 s per call
|
|
15
|
+
* EVEN AFTER the module cache is warm.
|
|
16
|
+
*
|
|
17
|
+
* Both costs were paid on the unlock-screen critical path because the
|
|
18
|
+
* providers ran `ECPairFactory(ecc)` at module top level. By routing
|
|
19
|
+
* everything through these lazy getters, cold start does zero secp256k1
|
|
20
|
+
* work; the first signing/verification operation pays a one-time bill,
|
|
21
|
+
* which is acceptable because it lands on a user-initiated action.
|
|
22
|
+
*
|
|
23
|
+
* Usage in providers:
|
|
24
|
+
* - Replace `import * as ecc from '@bitcoin-js/tiny-secp256k1-asmjs'`
|
|
25
|
+
* and `const ECPair = ECPairFactory(ecc)` with imports from here.
|
|
26
|
+
* - Replace `ecc.verify(...)` with `getEcc().verify(...)`.
|
|
27
|
+
* - Replace `ECPair.fromWIF(...)` with `getECPair().fromWIF(...)`.
|
|
28
|
+
*
|
|
29
|
+
* The `require()` calls are deliberate \u2014 a static `import` would
|
|
30
|
+
* re-introduce module-eval at the top of this file, defeating the point.
|
|
31
|
+
*/
|
|
32
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
|
+
exports.getEcc = getEcc;
|
|
34
|
+
exports.getECPair = getECPair;
|
|
35
|
+
let _ecc = null;
|
|
36
|
+
let _ECPair = null;
|
|
37
|
+
/**
|
|
38
|
+
* Returns the (cached) `@bitcoin-js/tiny-secp256k1-asmjs` module. First
|
|
39
|
+
* call triggers asm.js parse/eval; subsequent calls are O(1).
|
|
40
|
+
*/
|
|
41
|
+
function getEcc() {
|
|
42
|
+
if (_ecc)
|
|
43
|
+
return _ecc;
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
45
|
+
_ecc = require('@bitcoin-js/tiny-secp256k1-asmjs');
|
|
46
|
+
return _ecc;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Returns the (cached) `ECPair` factory bound to `getEcc()`. First call
|
|
50
|
+
* triggers ECPair's secp256k1 validation pass (~1.6 s on Hermes);
|
|
51
|
+
* subsequent calls are O(1).
|
|
52
|
+
*/
|
|
53
|
+
function getECPair() {
|
|
54
|
+
if (_ECPair)
|
|
55
|
+
return _ECPair;
|
|
56
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
57
|
+
const { ECPairFactory } = require('ecpair');
|
|
58
|
+
_ECPair = ECPairFactory(getEcc());
|
|
59
|
+
return _ECPair;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=lazyEcc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazyEcc.js","sourceRoot":"","sources":["../lib/lazyEcc.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;;AAWH,wBAKC;AAOD,8BAMC;AAzBD,IAAI,IAAI,GAAkC,IAAI,CAAC;AAC/C,IAAI,OAAO,GAAqB,IAAI,CAAC;AAErC;;;GAGG;AACH,SAAgB,MAAM;IACpB,IAAI,IAAI;QAAE,OAAO,IAAI,CAAC;IACtB,iEAAiE;IACjE,IAAI,GAAG,OAAO,CAAC,kCAAkC,CAAC,CAAC;IACnD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;GAIG;AACH,SAAgB,SAAS;IACvB,IAAI,OAAO;QAAE,OAAO,OAAO,CAAC;IAC5B,iEAAiE;IACjE,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC5C,OAAO,GAAG,aAAa,CAAC,MAAM,EAAE,CAAC,CAAC;IAClC,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/lib/index.ts
CHANGED
package/lib/lazyEcc.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazy accessors for `@bitcoin-js/tiny-secp256k1-asmjs` and the matching
|
|
3
|
+
* `ECPair` factory.
|
|
4
|
+
*
|
|
5
|
+
* Why this exists: cold-start measurements showed ~3.8 s of unlock time
|
|
6
|
+
* spent inside two top-level `const ECPair = ECPairFactory(ecc)` calls
|
|
7
|
+
* across the providers. The cost has two sources:
|
|
8
|
+
*
|
|
9
|
+
* 1. Module-eval of `secp256k1.asm.js` (32k+ lines). On Hermes there is
|
|
10
|
+
* no AOT for asm.js, so parse + eval blocks the JS thread.
|
|
11
|
+
* 2. ECPair's factory runs a validation pass (~150 secp256k1 ops)
|
|
12
|
+
* against the supplied `ecc` impl every time it's called. With
|
|
13
|
+
* Hermes interpreting asm.js at ~10 ms/op, that's ~1.6 s per call
|
|
14
|
+
* EVEN AFTER the module cache is warm.
|
|
15
|
+
*
|
|
16
|
+
* Both costs were paid on the unlock-screen critical path because the
|
|
17
|
+
* providers ran `ECPairFactory(ecc)` at module top level. By routing
|
|
18
|
+
* everything through these lazy getters, cold start does zero secp256k1
|
|
19
|
+
* work; the first signing/verification operation pays a one-time bill,
|
|
20
|
+
* which is acceptable because it lands on a user-initiated action.
|
|
21
|
+
*
|
|
22
|
+
* Usage in providers:
|
|
23
|
+
* - Replace `import * as ecc from '@bitcoin-js/tiny-secp256k1-asmjs'`
|
|
24
|
+
* and `const ECPair = ECPairFactory(ecc)` with imports from here.
|
|
25
|
+
* - Replace `ecc.verify(...)` with `getEcc().verify(...)`.
|
|
26
|
+
* - Replace `ECPair.fromWIF(...)` with `getECPair().fromWIF(...)`.
|
|
27
|
+
*
|
|
28
|
+
* The `require()` calls are deliberate \u2014 a static `import` would
|
|
29
|
+
* re-introduce module-eval at the top of this file, defeating the point.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
import type { ECPairAPI, TinySecp256k1Interface } from 'ecpair';
|
|
33
|
+
|
|
34
|
+
let _ecc: TinySecp256k1Interface | null = null;
|
|
35
|
+
let _ECPair: ECPairAPI | null = null;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Returns the (cached) `@bitcoin-js/tiny-secp256k1-asmjs` module. First
|
|
39
|
+
* call triggers asm.js parse/eval; subsequent calls are O(1).
|
|
40
|
+
*/
|
|
41
|
+
export function getEcc(): TinySecp256k1Interface {
|
|
42
|
+
if (_ecc) return _ecc;
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
44
|
+
_ecc = require('@bitcoin-js/tiny-secp256k1-asmjs');
|
|
45
|
+
return _ecc;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Returns the (cached) `ECPair` factory bound to `getEcc()`. First call
|
|
50
|
+
* triggers ECPair's secp256k1 validation pass (~1.6 s on Hermes);
|
|
51
|
+
* subsequent calls are O(1).
|
|
52
|
+
*/
|
|
53
|
+
export function getECPair(): ECPairAPI {
|
|
54
|
+
if (_ECPair) return _ECPair;
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
56
|
+
const { ECPairFactory } = require('ecpair');
|
|
57
|
+
_ECPair = ECPairFactory(getEcc());
|
|
58
|
+
return _ECPair;
|
|
59
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atomicfinance/utils",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
"node": ">=14"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@atomicfinance/crypto": "^4.2.
|
|
22
|
-
"@atomicfinance/errors": "^4.2.
|
|
23
|
-
"@atomicfinance/types": "^4.2.
|
|
21
|
+
"@atomicfinance/crypto": "^4.2.8",
|
|
22
|
+
"@atomicfinance/errors": "^4.2.8",
|
|
23
|
+
"@atomicfinance/types": "^4.2.8",
|
|
24
24
|
"@babel/runtime": "^7.12.1",
|
|
25
25
|
"bignumber.js": "^9.0.0",
|
|
26
26
|
"bip174": "^2.0.1",
|
|
@@ -34,6 +34,18 @@
|
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
36
|
"sideEffects": false,
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@bitcoin-js/tiny-secp256k1-asmjs": "^2.2.0",
|
|
39
|
+
"ecpair": "^2.1.0"
|
|
40
|
+
},
|
|
41
|
+
"peerDependenciesMeta": {
|
|
42
|
+
"@bitcoin-js/tiny-secp256k1-asmjs": {
|
|
43
|
+
"optional": true
|
|
44
|
+
},
|
|
45
|
+
"ecpair": {
|
|
46
|
+
"optional": true
|
|
47
|
+
}
|
|
48
|
+
},
|
|
37
49
|
"devDependencies": {
|
|
38
50
|
"@types/node": "^20.0.0"
|
|
39
51
|
},
|