ecash-lib 1.2.2-rc → 1.2.2-rc10
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/ecc.d.ts +8 -3
- package/dist/ecc.d.ts.map +1 -1
- package/dist/ecc.js +30 -2
- package/dist/ecc.js.map +1 -1
- package/dist/hash.d.ts.map +1 -1
- package/dist/hash.js +6 -1
- package/dist/hash.js.map +1 -1
- package/global.d.ts +45 -2
- package/package.json +1 -1
package/dist/ecc.d.ts
CHANGED
|
@@ -8,16 +8,21 @@ export interface Ecc {
|
|
|
8
8
|
schnorrSign(seckey: Uint8Array, msg: Uint8Array): Uint8Array;
|
|
9
9
|
}
|
|
10
10
|
/** Ecc implementation using WebAssembly */
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
declare class EccUninitialized implements Ecc {
|
|
12
|
+
constructor();
|
|
13
|
+
derivePubkey(_seckey: Uint8Array): Uint8Array;
|
|
14
|
+
ecdsaSign(_seckey: Uint8Array, _msg: Uint8Array): Uint8Array;
|
|
15
|
+
schnorrSign(_seckey: Uint8Array, _msg: Uint8Array): Uint8Array;
|
|
16
|
+
}
|
|
14
17
|
/** Dummy Ecc impl that always returns 0, useful for measuring tx size */
|
|
15
18
|
export declare class EccDummy implements Ecc {
|
|
16
19
|
derivePubkey(_seckey: Uint8Array): Uint8Array;
|
|
17
20
|
ecdsaSign(_seckey: Uint8Array, _msg: Uint8Array): Uint8Array;
|
|
18
21
|
schnorrSign(_seckey: Uint8Array, _msg: Uint8Array): Uint8Array;
|
|
19
22
|
}
|
|
23
|
+
export declare let Ecc: typeof EccUninitialized;
|
|
20
24
|
export declare function __setEcc(ecc: {
|
|
21
25
|
new (): Ecc;
|
|
22
26
|
}): void;
|
|
27
|
+
export {};
|
|
23
28
|
//# sourceMappingURL=ecc.d.ts.map
|
package/dist/ecc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ecc.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AAU,GAAG,UAAU;CAGjE;AAID,eAAO,IAAI,GAAG,yBAOV,CAAC;AAEL,wBAAgB,QAAQ,CAAC,GAAG,EAAE;IAAE,QAAQ,GAAG,CAAA;CAAE,QAS5C"}
|
package/dist/ecc.js
CHANGED
|
@@ -3,7 +3,24 @@
|
|
|
3
3
|
// Distributed under the MIT software license, see the accompanying
|
|
4
4
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.__setEcc = exports.
|
|
6
|
+
exports.__setEcc = exports.Ecc = exports.EccDummy = void 0;
|
|
7
|
+
/** Ecc implementation using WebAssembly */
|
|
8
|
+
class EccUninitialized {
|
|
9
|
+
constructor() {
|
|
10
|
+
if (!exports.Ecc.prototype.derivePubkey) {
|
|
11
|
+
throw new Error('Ecc not initialized. Call initWasm first.');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
derivePubkey(_seckey) {
|
|
15
|
+
throw new Error('Ecc not initialized. Call initWasm first.');
|
|
16
|
+
}
|
|
17
|
+
ecdsaSign(_seckey, _msg) {
|
|
18
|
+
throw new Error('Ecc not initialized. Call initWasm first.');
|
|
19
|
+
}
|
|
20
|
+
schnorrSign(_seckey, _msg) {
|
|
21
|
+
throw new Error('Ecc not initialized. Call initWasm first.');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
7
24
|
/** Dummy Ecc impl that always returns 0, useful for measuring tx size */
|
|
8
25
|
class EccDummy {
|
|
9
26
|
derivePubkey(_seckey) {
|
|
@@ -17,9 +34,20 @@ class EccDummy {
|
|
|
17
34
|
}
|
|
18
35
|
}
|
|
19
36
|
exports.EccDummy = EccDummy;
|
|
37
|
+
// Ecc is EccUninitialized if not available in globalThis
|
|
38
|
+
// Ecc is as expected if initWasm() has placed it in globalThis
|
|
39
|
+
exports.Ecc = (() => {
|
|
40
|
+
const globalEcc = globalThis.ecashlib?.Ecc;
|
|
41
|
+
return globalEcc || EccUninitialized;
|
|
42
|
+
})();
|
|
20
43
|
function __setEcc(ecc) {
|
|
21
44
|
exports.Ecc = ecc;
|
|
22
|
-
Object.assign(globalThis, {
|
|
45
|
+
Object.assign(globalThis, {
|
|
46
|
+
ecashlib: {
|
|
47
|
+
...(globalThis.ecashlib || {}),
|
|
48
|
+
Ecc: ecc,
|
|
49
|
+
},
|
|
50
|
+
});
|
|
23
51
|
}
|
|
24
52
|
exports.__setEcc = __setEcc;
|
|
25
53
|
//# sourceMappingURL=ecc.js.map
|
package/dist/ecc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ecc.js","sourceRoot":"","sources":["../src/ecc.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,mEAAmE;AACnE,sEAAsE;;;
|
|
1
|
+
{"version":3,"file":"ecc.js","sourceRoot":"","sources":["../src/ecc.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,mEAAmE;AACnE,sEAAsE;;;AActE,2CAA2C;AAC3C,MAAM,gBAAgB;IAClB;QACI,IAAI,CAAC,WAAG,CAAC,SAAS,CAAC,YAAY,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;QACjE,CAAC;IACL,CAAC;IAED,YAAY,CAAC,OAAmB;QAC5B,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IACjE,CAAC;IAED,SAAS,CAAC,OAAmB,EAAE,IAAgB;QAC3C,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IACjE,CAAC;IAED,WAAW,CAAC,OAAmB,EAAE,IAAgB;QAC7C,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IACjE,CAAC;CACJ;AAED,yEAAyE;AACzE,MAAa,QAAQ;IACjB,YAAY,CAAC,OAAmB;QAC5B,OAAO,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IAC9B,CAAC;IAED,SAAS,CAAC,OAAmB,EAAE,IAAgB;QAC3C,OAAO,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IAC9B,CAAC;IAED,WAAW,CAAC,OAAmB,EAAE,IAAgB;QAC7C,OAAO,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IAC9B,CAAC;CACJ;AAZD,4BAYC;AAED,yDAAyD;AACzD,+DAA+D;AACpD,QAAA,GAAG,GAAG,CAAC,GAAG,EAAE;IACnB,MAAM,SAAS,GACX,UAGH,CAAC,QAAQ,EAAE,GAAG,CAAC;IAChB,OAAO,SAAS,IAAI,gBAAgB,CAAC;AACzC,CAAC,CAAC,EAAE,CAAC;AAEL,SAAgB,QAAQ,CAAC,GAAoB;IACzC,WAAG,GAAG,GAAG,CAAC;IAEV,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE;QACtB,QAAQ,EAAE;YACN,GAAG,CAAE,UAAkC,CAAC,QAAQ,IAAI,EAAE,CAAC;YACvD,GAAG,EAAE,GAAG;SACX;KAC0B,CAAC,CAAC;AACrC,CAAC;AATD,4BASC"}
|
package/dist/hash.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAIhD,wBAAgB,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAMnD;AACD,wBAAgB,OAAO,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAMpD;AACD,wBAAgB,SAAS,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAMtD;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAIhD,wBAAgB,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAMnD;AACD,wBAAgB,OAAO,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAMpD;AACD,wBAAgB,SAAS,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAMtD;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,cAAc,QASjD"}
|
package/dist/hash.js
CHANGED
|
@@ -19,7 +19,12 @@ function shaRmd160(data) {
|
|
|
19
19
|
exports.shaRmd160 = shaRmd160;
|
|
20
20
|
function __setHashes(hashes) {
|
|
21
21
|
HASHES = hashes;
|
|
22
|
-
Object.assign(globalThis, {
|
|
22
|
+
Object.assign(globalThis, {
|
|
23
|
+
ecashlib: {
|
|
24
|
+
...(globalThis.ecashlib || {}),
|
|
25
|
+
HASHES: hashes,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
23
28
|
}
|
|
24
29
|
exports.__setHashes = __setHashes;
|
|
25
30
|
//# sourceMappingURL=hash.js.map
|
package/dist/hash.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,mEAAmE;AACnE,sEAAsE;;;AAItE,IAAI,MAAsB,CAAC;AAE3B,SAAgB,MAAM,CAAC,IAAgB;IACnC,OACI,UAGH,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACnC,CAAC;AAND,wBAMC;AACD,SAAgB,OAAO,CAAC,IAAgB;IACpC,OACI,UAGH,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC;AAND,0BAMC;AACD,SAAgB,SAAS,CAAC,IAAgB;IACtC,OACI,UAGH,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC;AAND,8BAMC;AAED,SAAgB,WAAW,CAAC,MAAsB;IAC9C,MAAM,GAAG,MAAM,CAAC;IAEhB,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":";AAAA,4CAA4C;AAC5C,mEAAmE;AACnE,sEAAsE;;;AAItE,IAAI,MAAsB,CAAC;AAE3B,SAAgB,MAAM,CAAC,IAAgB;IACnC,OACI,UAGH,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACnC,CAAC;AAND,wBAMC;AACD,SAAgB,OAAO,CAAC,IAAgB;IACpC,OACI,UAGH,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC;AAND,0BAMC;AACD,SAAgB,SAAS,CAAC,IAAgB;IACtC,OACI,UAGH,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC;AAND,8BAMC;AAED,SAAgB,WAAW,CAAC,MAAsB;IAC9C,MAAM,GAAG,MAAM,CAAC;IAEhB,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE;QACtB,QAAQ,EAAE;YACN,GAAG,CAAE,UAAkC,CAAC,QAAQ,IAAI,EAAE,CAAC;YACvD,MAAM,EAAE,MAAM;SACjB;KAC0B,CAAC,CAAC;AACrC,CAAC;AATD,kCASC"}
|
package/global.d.ts
CHANGED
|
@@ -2,7 +2,50 @@
|
|
|
2
2
|
// Distributed under the MIT software license, see the accompanying
|
|
3
3
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* global.d.ts
|
|
7
|
+
*
|
|
8
|
+
* Extend globalThis to include a new namespace, ecashlib
|
|
9
|
+
* We use this namespace to store lib functions that are only
|
|
10
|
+
* available after initWasm()
|
|
11
|
+
*
|
|
12
|
+
* We store all lib methods in ecashlib namespace to reduce chances of
|
|
13
|
+
* namespace collision in global this
|
|
14
|
+
*
|
|
15
|
+
* In general, dependency injection is a better practice, and this is what
|
|
16
|
+
* ecash-lib used until 1.2.2
|
|
17
|
+
*
|
|
18
|
+
* However dependency injection caused issues with libraries that used ecash-lib
|
|
19
|
+
* as a dependency, like ecash-agora. Methods that "should" have been available
|
|
20
|
+
* after initWasm() would not be available.
|
|
21
|
+
*
|
|
22
|
+
* Resolved by adding to globalThis (as responsibly as possible)
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
// BEGIN DUPLICATED CLASS DEFINITIONS
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Note
|
|
29
|
+
* These definitions are duplicated in src/ecc.ts
|
|
30
|
+
* Could not import it here as it leads to rel path errors in the
|
|
31
|
+
* published dependency when it is consumed by other apps
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
/** Interface to abstract over Elliptic Curve Cryptography */
|
|
35
|
+
export interface Ecc {
|
|
36
|
+
/** Derive a public key from secret key. */
|
|
37
|
+
derivePubkey(seckey: Uint8Array): Uint8Array;
|
|
38
|
+
|
|
39
|
+
/** Sign an ECDSA signature. msg needs to be a 32-byte hash */
|
|
40
|
+
ecdsaSign(seckey: Uint8Array, msg: Uint8Array): Uint8Array;
|
|
41
|
+
|
|
42
|
+
/** Sign a Schnorr signature. msg needs to be a 32-byte hash */
|
|
43
|
+
schnorrSign(seckey: Uint8Array, msg: Uint8Array): Uint8Array;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Ecc implementation using WebAssembly */
|
|
47
|
+
export let Ecc: { new (): Ecc };
|
|
48
|
+
// END DUPLICATED CLASS DEFINITIONS
|
|
6
49
|
|
|
7
50
|
export interface EcashLibHashes {
|
|
8
51
|
sha256: (data: Uint8Array) => Uint8Array;
|
|
@@ -10,7 +53,7 @@ export interface EcashLibHashes {
|
|
|
10
53
|
shaRmd160: (data: Uint8Array) => Uint8Array;
|
|
11
54
|
}
|
|
12
55
|
|
|
13
|
-
// Extend global this to include
|
|
56
|
+
// Extend global this to include HASHES and Ecc
|
|
14
57
|
declare global {
|
|
15
58
|
interface GlobalThis {
|
|
16
59
|
ecashlib: {
|