micro-eth-signer
Advanced tools
Comparing version 0.3.1 to 0.4.0
28
index.js
@@ -5,5 +5,6 @@ "use strict"; | ||
exports.Transaction = exports.Address = exports.strip0x = exports.add0x = exports.TRANSACTION_TYPES = exports.CHAIN_TYPES = void 0; | ||
const js_sha3_1 = require("js-sha3"); | ||
const sha3_1 = require("noble-hashes/lib/sha3"); | ||
const utils_1 = require("noble-hashes/lib/utils"); | ||
const secp256k1 = require("noble-secp256k1"); | ||
const rlp = require("micro-rlp"); | ||
const secp256k1 = require("noble-secp256k1"); | ||
exports.CHAIN_TYPES = { mainnet: 1, ropsten: 3, rinkeby: 4, goerli: 5, kovan: 42 }; | ||
@@ -35,9 +36,2 @@ exports.TRANSACTION_TYPES = { legacy: 0, eip2930: 1, eip1559: 2 }; | ||
} | ||
function bytesToHex(uint8a) { | ||
let hex = ''; | ||
for (let i = 0; i < uint8a.length; i++) { | ||
hex += uint8a[i].toString(16).padStart(2, '0'); | ||
} | ||
return hex; | ||
} | ||
const padHex = (hex) => (hex.length & 1 ? `0${hex}` : hex); | ||
@@ -84,3 +78,3 @@ function hexToBytes(hex) { | ||
if (value instanceof Uint8Array) | ||
value = add0x(bytesToHex(value)); | ||
value = add0x(utils_1.bytesToHex(value)); | ||
if (field === 'yParity' && typeof value === 'boolean') | ||
@@ -104,3 +98,3 @@ value = value ? '0x1' : '0x0'; | ||
if (value instanceof Uint8Array) | ||
value = bytesToHex(value); | ||
value = utils_1.bytesToHex(value); | ||
if (typeof value !== 'string') | ||
@@ -222,3 +216,3 @@ throw new TypeError(`Invalid type for field ${field}`); | ||
const tNum = exports.TRANSACTION_TYPES[type]; | ||
return (tNum ? `0x0${tNum}` : '0x') + bytesToHex(rlp.encode(normalized)); | ||
return (tNum ? `0x0${tNum}` : '0x') + utils_1.bytesToHex(rlp.encode(normalized)); | ||
} | ||
@@ -238,3 +232,3 @@ exports.Address = { | ||
const pub = len === 65 ? key : secp256k1.Point.fromHex(key).toRawBytes(false); | ||
const addr = js_sha3_1.keccak256(pub.slice(1, 65)).slice(24); | ||
const addr = utils_1.bytesToHex(sha3_1.keccak_256(pub.slice(1, 65))).slice(24); | ||
return exports.Address.checksum(addr); | ||
@@ -246,3 +240,3 @@ }, | ||
throw new Error('Invalid address, must have 40 chars'); | ||
const hash = strip0x(js_sha3_1.keccak256(addr)); | ||
const hash = strip0x(utils_1.bytesToHex(sha3_1.keccak_256(addr))); | ||
let checksummed = ''; | ||
@@ -264,3 +258,3 @@ for (let i = 0; i < addr.length; i++) { | ||
return true; | ||
const hash = js_sha3_1.keccak256(addr.toLowerCase()); | ||
const hash = utils_1.bytesToHex(sha3_1.keccak_256(addr.toLowerCase())); | ||
for (let i = 0; i < 40; i++) { | ||
@@ -285,3 +279,3 @@ const nth = Number.parseInt(hash[i], 16); | ||
else if (data instanceof Uint8Array) { | ||
norm = bytesToHex(data); | ||
norm = utils_1.bytesToHex(data); | ||
} | ||
@@ -397,3 +391,3 @@ else if (Array.isArray(data) || (typeof data === 'object' && data != null)) { | ||
encoded = new Uint8Array([exports.TRANSACTION_TYPES[this.type], ...Array.from(encoded)]); | ||
return js_sha3_1.keccak256(encoded); | ||
return utils_1.bytesToHex(sha3_1.keccak_256(encoded)); | ||
} | ||
@@ -400,0 +394,0 @@ get hash() { |
{ | ||
"name": "micro-eth-signer", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"description": "Create, sign and validate Ethereum transactions & addresses with minimum deps. Supports London & Berlin txs", | ||
@@ -43,4 +43,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"js-sha3": "0.8.0", | ||
"micro-rlp": "2.2.9", | ||
"noble-hashes": "^0.1.1", | ||
"noble-secp256k1": "^1.2.7" | ||
@@ -47,0 +47,0 @@ }, |
29227
503
+ Addednoble-hashes@^0.1.1
+ Addednoble-hashes@0.1.1(transitive)
- Removedjs-sha3@0.8.0
- Removedjs-sha3@0.8.0(transitive)