@exodus/web3-ethereum-utils 4.7.6 → 5.0.1

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 (2) hide show
  1. package/lib/signatures.js +16 -2
  2. package/package.json +10 -10
package/lib/signatures.js CHANGED
@@ -18,9 +18,23 @@ export function signTransaction(transactionParams, privateKey) {
18
18
  const signedTransaction = transaction.sign(privateKey);
19
19
  return signedTransaction.serialize();
20
20
  }
21
+ const HEX_BODY = /^[0-9a-fA-F]*$/;
21
22
  export function hex0xStringToBuffer(hex) {
23
+ if (typeof hex !== 'string') {
24
+ throw new TypeError('expected a hex string');
25
+ }
22
26
  // Remove the 0x
23
27
  const hexWithout0x = hex.startsWith('0x') ? hex.slice(2) : hex;
28
+ // `Buffer.from(str, 'hex')` decodes the leading valid pairs of `str` and SILENTLY DROPS
29
+ // the remainder, without error. Anything not fully hex therefore produced a buffer that
30
+ // no longer corresponds to its input: `<hex> Login only.` decoded to `<hex>`, an
31
+ // uppercase `0X` prefix decoded to nothing, and plain text decoded to nothing at all --
32
+ // so `personal_sign` signed bytes that were never on screen, and every plain-text
33
+ // message signed as the EMPTY message, whose hash is a constant. A partial decode is
34
+ // never what the caller meant, so refuse it instead of guessing.
35
+ if (!HEX_BODY.test(hexWithout0x)) {
36
+ throw new TypeError('expected a hex string');
37
+ }
24
38
  // Pad the value until even
25
39
  const hexWithLeadingZeros = hexWithout0x.length % 2 === 0 ? hexWithout0x : '0' + hexWithout0x;
26
40
  // Finally return the buffer
@@ -28,11 +42,11 @@ export function hex0xStringToBuffer(hex) {
28
42
  }
29
43
  export function bufferToHex0xString(buf) {
30
44
  if (!Buffer.isBuffer(buf)) {
31
- throw new Error('expected a buffer');
45
+ throw new TypeError('expected a buffer');
32
46
  }
33
47
  const hex = buf.toString('hex');
34
48
  if (typeof hex !== 'string') {
35
- throw new Error('expected hex string');
49
+ throw new TypeError('expected hex string');
36
50
  }
37
51
  return '0x' + hex;
38
52
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@exodus/web3-ethereum-utils",
3
3
  "description": "Web3 Ethereum utils.",
4
- "version": "4.7.6",
4
+ "version": "5.0.1",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "module": "lib/index.js",
@@ -27,21 +27,21 @@
27
27
  },
28
28
  "license": "MIT",
29
29
  "scripts": {
30
- "clean": "run -T rimraf lib",
31
- "build": "yarn clean && run -T tsc",
32
- "lint": "run -T eslintc .",
33
- "lint:fix": "yarn lint --fix",
34
- "prepublishOnly": "yarn run -T build --scope @exodus/web3-ethereum-utils",
35
- "test": "run -T exodus-test --jest --esbuild"
30
+ "clean": "rimraf lib",
31
+ "build": "pnpm clean && tsc",
32
+ "prepublishOnly": "pnpm -w run build --scope @exodus/web3-ethereum-utils",
33
+ "test": "exodus-test --jest --esbuild"
36
34
  },
37
35
  "devDependencies": {
38
36
  "@exodus/assets": "^11.10.0",
39
- "@exodus/ethereum-meta": "^2.12.0",
37
+ "@exodus/ethereum-meta": "^2.13.0",
38
+ "@types/bn.js": "^5.1.6",
39
+ "@types/minimalistic-assert": "^1.0.3",
40
40
  "lodash": "^4.17.21"
41
41
  },
42
42
  "dependencies": {
43
43
  "@exodus/basic-utils": "^3.0.1",
44
- "@exodus/ethereum-api": "^8.76.4",
44
+ "@exodus/ethereum-api": "^9.0.0",
45
45
  "@exodus/ethereum-lib": "^5.20.0",
46
46
  "@exodus/ethereumjs": "^1.5.0",
47
47
  "@exodus/solidity-contract": "^1.2.1",
@@ -55,5 +55,5 @@
55
55
  "url": "https://github.com/ExodusMovement/assets/issues?q=is%3Aissue+is%3Aopen+label%3Aweb3-ethereum-utils"
56
56
  },
57
57
  "homepage": "https://github.com/ExodusMovement/assets/tree/master/web3/web3-ethereum-utils",
58
- "gitHead": "6defbed4f39a326cb0c2d5fcdadf3f2abfb83a46"
58
+ "gitHead": "92d6cdde313e5244fb05a99b1be964a96f989c3b"
59
59
  }