@bitcoin-js/tiny-secp256k1-asmjs 2.2.3 → 2.2.5

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/lib/validate.d.ts CHANGED
@@ -13,6 +13,7 @@ export declare function isXOnlyPoint(p: Uint8Array): boolean;
13
13
  export declare function isDERPoint(p: Uint8Array): boolean;
14
14
  export declare function isPointCompressed(p: Uint8Array): boolean;
15
15
  export declare function validateParity(p: 1 | 0): void;
16
+ export declare function validateRecoveryId(recoveryId: number): void;
16
17
  export declare function validatePrivate(d: Uint8Array): void;
17
18
  export declare function validatePoint(p: Uint8Array): void;
18
19
  export declare function validateXOnlyPoint(p: Uint8Array): void;
package/lib/validate.js CHANGED
@@ -80,6 +80,10 @@ export function validateParity(p) {
80
80
  if (p !== 0 && p !== 1)
81
81
  throwError(ERROR_BAD_PARITY);
82
82
  }
83
+ export function validateRecoveryId(recoveryId) {
84
+ if (!Number.isInteger(recoveryId) || recoveryId < 0 || recoveryId > 3)
85
+ throwError(ERROR_BAD_RECOVERY_ID);
86
+ }
83
87
  export function validatePrivate(d) {
84
88
  if (!isPrivate(d))
85
89
  throwError(ERROR_BAD_PRIVATE);
@@ -7,3 +7,9 @@ export declare const ERROR_BAD_EXTRA_DATA = 5;
7
7
  export declare const ERROR_BAD_PARITY = 6;
8
8
  export declare const ERROR_BAD_RECOVERY_ID = 7;
9
9
  export declare function throwError(errcode: number): never;
10
+ /**
11
+ * Checks for error codes in the higher bits and throws an error if any are found.
12
+ * @param retval The return value of the wasm function.
13
+ * @returns The original return value if no error is found.
14
+ */
15
+ export declare function vCheck(retval: number): number;
@@ -20,3 +20,16 @@ export function throwError(errcode) {
20
20
  const message = ERRORS_MESSAGES[errcode.toString()] || `Unknow error code: ${errcode}`;
21
21
  throw new TypeError(message);
22
22
  }
23
+ /**
24
+ * Checks for error codes in the higher bits and throws an error if any are found.
25
+ * @param retval The return value of the wasm function.
26
+ * @returns The original return value if no error is found.
27
+ */
28
+ export function vCheck(retval) {
29
+ if ((retval & 0x80) !== 0) {
30
+ const ERROR_MASK = 0xff00;
31
+ const errorCode = (retval & ERROR_MASK) >> 8;
32
+ throwError(errorCode);
33
+ }
34
+ return retval;
35
+ }
@@ -24,15 +24,15 @@ interface Secp256k1WASM {
24
24
  pointFromScalar: (outputlen: number) => number;
25
25
  xOnlyPointFromScalar: () => number;
26
26
  xOnlyPointFromPoint: (inputLen: number) => number;
27
- xOnlyPointAddTweak: () => 1 | 0 | -1;
27
+ xOnlyPointAddTweak: () => 1 | 0 | 42;
28
28
  xOnlyPointAddTweakCheck: (parity: number) => number;
29
29
  pointMultiply: (p: number, outputlen: number) => number;
30
30
  privateAdd: () => number;
31
31
  privateSub: () => number;
32
- privateNegate: () => void;
33
- sign: (e: number) => void;
32
+ privateNegate: () => number;
33
+ sign: (e: number) => number;
34
34
  signRecoverable: (e: number) => 0 | 1 | 2 | 3;
35
- signSchnorr: (e: number) => void;
35
+ signSchnorr: (e: number) => number;
36
36
  verify: (Q: number, strict: number) => number;
37
37
  verifySchnorr: () => number;
38
38
  recover: (outputlen: number, recoveryId: RecoveryIdType) => number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bitcoin-js/tiny-secp256k1-asmjs",
3
- "version": "2.2.3",
3
+ "version": "2.2.5",
4
4
  "description": "A tiny secp256k1 JS",
5
5
  "homepage": "https://github.com/bitcoinjs/tiny-secp256k1#readme",
6
6
  "bugs": {
@@ -12,7 +12,6 @@
12
12
  },
13
13
  "license": "MIT",
14
14
  "type": "module",
15
- "main": "./lib/cjs/index.cjs",
16
15
  "exports": {
17
16
  ".": {
18
17
  "node": {
@@ -24,6 +23,7 @@
24
23
  "default": "./lib/index.js"
25
24
  }
26
25
  },
26
+ "main": "./lib/cjs/index.cjs",
27
27
  "browser": {
28
28
  "./lib/rand.js": "./lib/rand.browser.js"
29
29
  },
@@ -40,7 +40,7 @@
40
40
  "@types/node": "^14.14.35",
41
41
  "@typescript-eslint/eslint-plugin": "^4.18.0",
42
42
  "@typescript-eslint/parser": "^4.18.0",
43
- "browser-run": "^10.1.0",
43
+ "browser-run": "^12.0.0",
44
44
  "buffer": "^6.0.3",
45
45
  "eslint": "^7.22.0",
46
46
  "eslint-config-prettier": "^8.1.0",