micro-eth-signer
Advanced tools
Comparing version 0.1.6 to 0.1.7
28
index.js
@@ -54,2 +54,5 @@ "use strict"; | ||
function normalizeField(field, value) { | ||
if (field === 'gasLimit' && !value) { | ||
value = '0x5208'; | ||
} | ||
if (['nonce', 'gasPrice', 'gasLimit', 'value'].includes(field)) { | ||
@@ -64,12 +67,9 @@ if (typeof value === 'number' || typeof value === 'bigint') { | ||
else { | ||
throw new TypeError('Invalid type'); | ||
throw new TypeError(`Invalid type for field ${field}`); | ||
} | ||
} | ||
if (field === 'gasLimit' && !value) { | ||
value = '0x5208'; | ||
} | ||
if (['gasPrice'].includes(field) && !value) { | ||
throw new TypeError('The field must have non-zero value'); | ||
} | ||
if (['v', 'r', 's'].includes(field) && !value) | ||
if (['v', 'r', 's', 'data'].includes(field) && !value) | ||
return ''; | ||
@@ -81,11 +81,5 @@ if (typeof value !== 'string') | ||
function rawToSerialized(input) { | ||
let array = Array.isArray(input) ? input : mapToArray(input); | ||
for (let i = 0; i < array.length; i++) { | ||
const field = FIELDS[i]; | ||
const value = array[i]; | ||
const adjusted = normalizeField(field, value); | ||
if (typeof value === 'string') | ||
array[i] = add0x(adjusted); | ||
} | ||
return add0x(bytesToHex(rlp.encode(array))); | ||
const initial = Array.isArray(input) ? input : mapToArray(input); | ||
const normalized = initial.map((value, i) => add0x(normalizeField(FIELDS[i], value))); | ||
return add0x(bytesToHex(rlp.encode(normalized))); | ||
} | ||
@@ -110,2 +104,4 @@ exports.Address = { | ||
const addr = strip0x(nonChecksummedAddress.toLowerCase()); | ||
if (addr.length !== 40) | ||
throw new Error('Invalid address, must have 40 chars'); | ||
const hash = strip0x(js_sha3_1.keccak256(addr)); | ||
@@ -124,2 +120,4 @@ let checksummed = ''; | ||
const addr = strip0x(address); | ||
if (addr.length !== 40) | ||
throw new Error('Invalid address, must have 40 chars'); | ||
if (addr === addr.toLowerCase() || addr === addr.toUpperCase()) | ||
@@ -263,3 +261,3 @@ return true; | ||
exports.Transaction = Transaction; | ||
Transaction.DEFAULT_HARDFORK = 'muirGlacier'; | ||
Transaction.DEFAULT_HARDFORK = 'berlin'; | ||
Transaction.DEFAULT_CHAIN = 'mainnet'; |
{ | ||
"name": "micro-eth-signer", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "Create, sign and validate Ethereum transactions & addresses with minimum deps", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
18820
303