diff --git a/packages/sdk/wallets/wallet-base/package.json b/packages/sdk/wallets/wallet-base/package.json index 580274608..3b891b937 100644 --- a/packages/sdk/wallets/wallet-base/package.json +++ b/packages/sdk/wallets/wallet-base/package.json @@ -35,7 +35,6 @@ "@types/debug": "^4.1.5", "bignumber.js": "^9.0.0", "debug": "^4.1.1", - "eth-lib": "^0.2.8", "web3": "1.10.0", "web3-eth-accounts": "1.10.0" }, diff --git a/packages/sdk/wallets/wallet-base/src/signing-utils.test.ts b/packages/sdk/wallets/wallet-base/src/signing-utils.test.ts index 7bc753f10..73a9a1f63 100644 --- a/packages/sdk/wallets/wallet-base/src/signing-utils.test.ts +++ b/packages/sdk/wallets/wallet-base/src/signing-utils.test.ts @@ -261,7 +261,7 @@ describe('rlpEncodedTx', () => { function ckToViem(tx: CeloTx & { v?: number }) { return { ...tx, - gas: BigInt(tx.gas!), + gas: BigInt(tx.gas! as string), maxFeePerGas: BigInt(tx.maxFeePerGas?.toString()!), maxPriorityFeePerGas: BigInt(tx.maxPriorityFeePerGas?.toString()!), value: BigInt(tx.value?.toString()!), @@ -356,7 +356,7 @@ describe('recoverTransaction', () => { "data": "0xabcdef", "feeCurrency": "0x", "gas": 10, - "gasPrice": 99, + "gasPrice": "99", "gatewayFee": "0x5678", "gatewayFeeRecipient": "0x1be31a94361a391bbafb2a4ccd704f57dc04d4bb", "nonce": 0, @@ -565,8 +565,17 @@ describe('extractSignature', () => { `) }) it('fails when length is wrong', () => { + expect(() => + extractSignature( + '0xf88282ad5a8063630a94588e4b68193001e4d10928660ab4165b813717c0880de0b6b3a764000083abcdefc094cd2a3d9f938e13cd947ec05abc7fe734df8dd82680a091b5504a59e529e7efa42dbb97fbc3311a91d035c873a94ab0789441fc989f84a02e8254d6b3101b63417e5d496833bc84f4832d4a8bf8a2b83e291d8f38c0f62d' + ) + ).toThrowErrorMatchingInlineSnapshot( + `"@extractSignature: provided transaction has 13 elements but celo-legacy txs with a signature have 12 [{"0":173,"1":90},{},{"0":99},{"0":99},{"0":10},{"0":88,"1":142,"2":75,"3":104,"4":25,"5":48,"6":1,"7":228,"8":209,"9":9,"10":40,"11":102,"12":10,"13":180,"14":22,"15":91,"16":129,"17":55,"18":23,"19":192},{"0":13,"1":224,"2":182,"3":179,"4":167,"5":100,"6":0,"7":0},{"0":171,"1":205,"2":239},[],{"0":205,"1":42,"2":61,"3":159,"4":147,"5":142,"6":19,"7":205,"8":148,"9":126,"10":192,"11":90,"12":188,"13":127,"14":231,"15":52,"16":223,"17":141,"18":216,"19":38},{},{"0":145,"1":181,"2":80,"3":74,"4":89,"5":229,"6":41,"7":231,"8":239,"9":164,"10":45,"11":187,"12":151,"13":251,"14":195,"15":49,"16":26,"17":145,"18":208,"19":53,"20":200,"21":115,"22":169,"23":74,"24":176,"25":120,"26":148,"27":65,"28":252,"29":152,"30":159,"31":132},{"0":46,"1":130,"2":84,"3":214,"4":179,"5":16,"6":27,"7":99,"8":65,"9":126,"10":93,"11":73,"12":104,"13":51,"14":188,"15":132,"16":244,"17":131,"18":45,"19":74,"20":139,"21":248,"22":162,"23":184,"24":62,"25":41,"26":29,"27":143,"28":56,"29":192,"30":246,"31":45}]"` + ) + }) + it('fails when length is empty', () => { expect(() => extractSignature('0x')).toThrowErrorMatchingInlineSnapshot( - `"@extractSignature: provided transaction has 0 elements but celo-legacy txs with a signature have 12 []"` + `"Invalid byte sequence"` ) }) }) diff --git a/packages/sdk/wallets/wallet-base/src/signing-utils.ts b/packages/sdk/wallets/wallet-base/src/signing-utils.ts index a31cf451f..3f76d32c3 100644 --- a/packages/sdk/wallets/wallet-base/src/signing-utils.ts +++ b/packages/sdk/wallets/wallet-base/src/signing-utils.ts @@ -1,4 +1,4 @@ -import { ensureLeading0x, trimLeading0x } from '@celo/base/lib/address' +import { ensureLeading0x, normalizeAddressWith0x, trimLeading0x } from '@celo/base/lib/address' import { CeloTx, CeloTxWithSig, @@ -16,15 +16,12 @@ import { import { EIP712TypedData, generateTypedDataHash } from '@celo/utils/lib/sign-typed-data-utils' import { parseSignatureWithoutPrefix } from '@celo/utils/lib/signatureUtils' import { publicKeyToAddress } from '@celo/utils/src/address' -// @ts-ignore-next-line +import * as RLP from '@ethereumjs/rlp' import * as ethUtil from '@ethereumjs/util' import { secp256k1 } from '@noble/curves/secp256k1' import { keccak_256 } from '@noble/hashes/sha3' -import { hexToBytes } from '@noble/hashes/utils' +import { bytesToHex, hexToBytes } from '@noble/hashes/utils' import debugFactory from 'debug' -// @ts-ignore-next-line eth-lib types not found -import { bytes as Bytes, RLP } from 'eth-lib' -// TODO: replace by @ethereumjs/rlp import Web3 from 'web3' // TODO try to do this without web3 direct import Accounts from 'web3-eth-accounts' @@ -42,6 +39,10 @@ export const thirtyTwo: number = 32 const Y_PARITY_EIP_2098 = 27 +function rlpEncodeHex(value: RLP.Input): Hex { + return ensureLeading0x(Buffer.from(RLP.encode(value)).toString('hex')) +} + function isNullOrUndefined(value: any): boolean { return value === null || value === undefined } @@ -110,15 +111,15 @@ function stringNumberToHex(num?: number | string): Hex { export function rlpEncodedTx(tx: CeloTx): RLPEncodedTx { assertSerializableTX(tx) const transaction = inputCeloTxFormatter(tx) - transaction.to = Bytes.fromNat(tx.to || '0x').toLowerCase() + transaction.to = ensureLeading0x((tx.to || '0x').toLowerCase()) transaction.nonce = Number(((tx.nonce as any) !== '0x' ? tx.nonce : 0) || 0) - transaction.data = Bytes.fromNat(tx.data || '0x').toLowerCase() + transaction.data = (tx.data || '0x').toLowerCase() transaction.value = stringNumberOrBNToHex(tx.value) transaction.gas = stringNumberOrBNToHex(tx.gas) transaction.chainId = tx.chainId || 1 // Celo Specific - transaction.feeCurrency = Bytes.fromNat(tx.feeCurrency || '0x').toLowerCase() - transaction.gatewayFeeRecipient = Bytes.fromNat(tx.gatewayFeeRecipient || '0x').toLowerCase() + transaction.feeCurrency = ensureLeading0x((tx.feeCurrency || '0x').toLowerCase()) + transaction.gatewayFeeRecipient = ensureLeading0x((tx.gatewayFeeRecipient || '0x').toLowerCase()) transaction.gatewayFee = stringNumberOrBNToHex(tx.gatewayFee) // Legacy @@ -131,7 +132,7 @@ export function rlpEncodedTx(tx: CeloTx): RLPEncodedTx { if (isCIP64(tx)) { // https://github.com/celo-org/celo-proposals/blob/master/CIPs/cip-0064.md // 0x7b || rlp([chainId, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, accessList, feeCurrency, signatureYParity, signatureR, signatureS]). - rlpEncode = RLP.encode([ + rlpEncode = rlpEncodeHex([ stringNumberToHex(transaction.chainId), stringNumberToHex(transaction.nonce), transaction.maxPriorityFeePerGas || '0x', @@ -151,7 +152,7 @@ export function rlpEncodedTx(tx: CeloTx): RLPEncodedTx { // There shall be a typed transaction with the code 0x7c that has the following format: // 0x7c || rlp([chain_id, nonce, max_priority_fee_per_gas, max_fee_per_gas, gas_limit, feecurrency, gatewayFeeRecipient, gatewayfee, destination, amount, data, access_list, signature_y_parity, signature_r, signature_s]). // This will be in addition to the type 0x02 transaction as specified in EIP-1559. - rlpEncode = RLP.encode([ + rlpEncode = rlpEncodeHex([ stringNumberToHex(transaction.chainId), stringNumberToHex(transaction.nonce), transaction.maxPriorityFeePerGas || '0x', @@ -170,7 +171,7 @@ export function rlpEncodedTx(tx: CeloTx): RLPEncodedTx { } else if (isEIP1559(tx)) { // https://eips.ethereum.org/EIPS/eip-1559 // 0x02 || rlp([chain_id, nonce, max_priority_fee_per_gas, max_fee_per_gas, gas_limit, destination, amount, data, access_list, signature_y_parity, signature_r, signature_s]). - rlpEncode = RLP.encode([ + rlpEncode = rlpEncodeHex([ stringNumberToHex(transaction.chainId), stringNumberToHex(transaction.nonce), transaction.maxPriorityFeePerGas || '0x', @@ -193,7 +194,7 @@ export function rlpEncodedTx(tx: CeloTx): RLPEncodedTx { } else { // This order should match the order in Geth. // https://github.com/celo-org/celo-blockchain/blob/027dba2e4584936cc5a8e8993e4e27d28d5247b8/core/types/transaction.go#L65 - rlpEncode = RLP.encode([ + rlpEncode = rlpEncodeHex([ stringNumberToHex(transaction.nonce), transaction.gasPrice, transaction.gas, @@ -324,16 +325,16 @@ export async function encodeTransaction( const v = sanitizedSignature.v const r = sanitizedSignature.r const s = sanitizedSignature.s - const decodedTX = prefixAwareRLPDecode(rlpEncoded.rlpEncode, rlpEncoded.type) + const decodedTX = prefixAwareRLPDecode(rlpEncoded.rlpEncode, rlpEncoded.type) as Uint8Array[] // for legacy tx we need to slice but for new ones we do not want to do that const rawTx = (rlpEncoded.type === 'celo-legacy' ? decodedTX.slice(0, 9) : decodedTX).concat([ - v, - r, - s, + hexToBytes(v), + hexToBytes(r), + hexToBytes(s), ]) // After signing, the transaction is encoded again and type prefix added - const rawTransaction = concatTypePrefixHex(RLP.encode(rawTx), rlpEncoded.type) + const rawTransaction = concatTypePrefixHex(rlpEncodeHex(rawTx), rlpEncoded.type) const hash = getHashFromEncoded(rawTransaction) const baseTX = { @@ -382,7 +383,7 @@ export async function encodeTransaction( return result } // new types have prefix but legacy does not -function prefixAwareRLPDecode(rlpEncode: string, type: TransactionTypes): string[] { +function prefixAwareRLPDecode(rlpEncode: string, type: TransactionTypes) { return type === 'celo-legacy' ? RLP.decode(rlpEncode) : RLP.decode(`0x${rlpEncode.slice(4)}`) } @@ -410,10 +411,10 @@ export function extractSignature(rawTx: string) { )} ${JSON.stringify(rawValues)}` ) } - return extractSignatureFromDecoded(rawValues) + return extractSignatureFromDecoded(rawValues as Uint8Array[]) } -function extractSignatureFromDecoded(rawValues: string[]) { +function extractSignatureFromDecoded(rawValues: Uint8Array[]) { // signature is always (for the tx we support so far) the last three elements of the array in order v, r, s, const v = rawValues.at(-3) let r = rawValues.at(-2) @@ -421,13 +422,10 @@ function extractSignatureFromDecoded(rawValues: string[]) { // https://github.com/wagmi-dev/viem/blob/993321689b3e2220976504e7e170fe47731297ce/src/utils/transaction/parseTransaction.ts#L281 // Account.recover cannot handle canonicalized signatures // A canonicalized signature may have the first byte removed if its value is 0 - r = ensureLeading0x(trimLeading0x(r as string).padStart(64, '0')) - s = ensureLeading0x(trimLeading0x(s as string).padStart(64, '0')) - return { - v, - r, - s, + v: handleHexString(v!), + r: ensureLeading0x(bytesToHex(r!).padStart(64, '0')), + s: ensureLeading0x(bytesToHex(s!).padStart(64, '0')), } } @@ -446,32 +444,42 @@ export function recoverTransaction(rawTx: string): [CeloTx, string] { case 'eip1559': return recoverTransactionEIP1559(rawTx as Hex) default: - const rawValues = RLP.decode(rawTx) + const rawValues = RLP.decode(rawTx) as Uint8Array[] debug('signing-utils@recoverTransaction: values are %s', rawValues) - const recovery = Bytes.toNumber(rawValues[9]) - // eslint-disable-next-line no-bitwise - const chainId = Bytes.fromNumber((recovery - 35) >> 1) + const recovery = handleNumber(rawValues[9]) + // eslint-disable-next-line no-bitwise + const chainId = (recovery - 35) >> 1 const celoTx: CeloTx = { type: 'celo-legacy', - nonce: rawValues[0].toLowerCase() === '0x' ? 0 : parseInt(rawValues[0], 16), - gasPrice: rawValues[1].toLowerCase() === '0x' ? 0 : parseInt(rawValues[1], 16), - gas: rawValues[2].toLowerCase() === '0x' ? 0 : parseInt(rawValues[2], 16), - feeCurrency: rawValues[3], - gatewayFeeRecipient: rawValues[4], - gatewayFee: rawValues[5], - to: rawValues[6], - value: rawValues[7], - data: rawValues[8], - chainId, + nonce: handleNumber(rawValues[0]), + // NOTE: I used `handleNumber` to make it match the snapshot but we may + // lose accuracy, should use `handleHexString` + gasPrice: handleNumber(rawValues[1]), + // NOTE: I used `handleNumber` to make it match the snapshot but we may + // lose accuracy, should use `handleHexString` + gas: handleNumber(rawValues[2]), + feeCurrency: handleHexString(rawValues[3]), + gatewayFeeRecipient: handleHexString(rawValues[4]), + gatewayFee: handleHexString(rawValues[5]), + to: handleHexString(rawValues[6]), + value: handleHexString(rawValues[7]), + data: handleData(rawValues[8]), + // NOTE: I stringified to make it match the snapshot but it doesn't + // match the signature of TransactionConfig which expects a number + // @ts-expect-error + chainId: ensureLeading0x(chainId.toString(16)), } + console.log(celoTx) const { r, v: _v, s } = extractSignatureFromDecoded(rawValues) let v = parseInt(_v || '0x0', 16) const signature = new secp256k1.Signature(BigInt(r), BigInt(s)).addRecoveryBit( v - chainIdTransformationForSigning(chainId) ) - const extraData = recovery < 35 ? [] : [chainId, '0x', '0x'] + console.log({ r, v, s, vv: v - chainIdTransformationForSigning(chainId) }) + const extraData = + recovery < 35 ? [] : [hexToBytes(chainId.toString(16)), hexToBytes(''), hexToBytes('')] const signingData = rawValues.slice(0, 9).concat(extraData) - const signingDataHex = RLP.encode(signingData) + const signingDataHex = rlpEncodeHex(signingData) const signingDataHash = getHashFromEncoded(signingDataHex) const publicKey = signature.recoverPublicKey(trimLeading0x(signingDataHash)).toHex(false) return [celoTx, publicKeyToAddress(publicKey)] @@ -479,10 +487,10 @@ export function recoverTransaction(rawTx: string): [CeloTx, string] { } // inspired by @ethereumjs/tx -function getPublicKeyofSignerFromTx(transactionArray: string[], type: TransactionTypes) { +function getPublicKeyofSignerFromTx(transactionArray: Uint8Array[], type: TransactionTypes) { // this needs to be 10 for cip64, 12 for cip42 and eip1559 const base = transactionArray.slice(0, correctLengthOf(type, false)) - const message = concatHex([TxTypeToPrefix[type], RLP.encode(base).slice(2)]) + const message = concatHex([TxTypeToPrefix[type], rlpEncodeHex(base).slice(2)]) const msgHash = keccak_256(hexToBytes(trimLeading0x(message))) const { v, r, s } = extractSignatureFromDecoded(transactionArray) @@ -499,9 +507,9 @@ function getPublicKeyofSignerFromTx(transactionArray: string[], type: Transactio } export function getSignerFromTxEIP2718TX(serializedTransaction: string): string { - const transactionArray: any[] = RLP.decode(`0x${serializedTransaction.slice(4)}`) + const transactionArray = RLP.decode(`0x${serializedTransaction.slice(4)}`) const signer = getPublicKeyofSignerFromTx( - transactionArray, + transactionArray as Uint8Array[], determineTXType(serializedTransaction) ) @@ -532,7 +540,7 @@ function vrsForRecovery(vRaw: string, r: string, s: string) { } function recoverTransactionCIP42(serializedTransaction: Hex): [CeloTxWithSig, string] { - const transactionArray: any[] = prefixAwareRLPDecode(serializedTransaction, 'cip42') + const transactionArray = prefixAwareRLPDecode(serializedTransaction, 'cip42') debug('signing-utils@recoverTransactionCIP42: values are %s', transactionArray) if (transactionArray.length !== 15 && transactionArray.length !== 12) { throw new Error( @@ -555,24 +563,23 @@ function recoverTransactionCIP42(serializedTransaction: Hex): [CeloTxWithSig, st vRaw, r, s, - ] = transactionArray + ] = transactionArray as Uint8Array[] const celoTX: CeloTxWithSig = { type: 'cip42', - nonce: nonce.toLowerCase() === '0x' ? 0 : parseInt(nonce, 16), - maxPriorityFeePerGas: - maxPriorityFeePerGas.toLowerCase() === '0x' ? 0 : parseInt(maxPriorityFeePerGas, 16), - maxFeePerGas: maxFeePerGas.toLowerCase() === '0x' ? 0 : parseInt(maxFeePerGas, 16), - gas: gas.toLowerCase() === '0x' ? 0 : parseInt(gas, 16), - feeCurrency, - gatewayFeeRecipient, - gatewayFee, - to, - value: value.toLowerCase() === '0x' ? 0 : parseInt(value, 16), - data, - chainId: chainId.toLowerCase() === '0x' ? 0 : parseInt(chainId, 16), - accessList: parseAccessList(accessList), - ...vrsForRecovery(vRaw, r, s), + nonce: handleNumber(nonce), + maxPriorityFeePerGas: handleNumber(maxPriorityFeePerGas), + maxFeePerGas: handleNumber(maxFeePerGas), + gas: handleNumber(gas), + feeCurrency: handleHexString(feeCurrency), + gatewayFeeRecipient: handleHexString(gatewayFeeRecipient), + gatewayFee: handleHexString(gatewayFee), + to: handleHexString(to), + value: handleNumber(value), + data: handleData(data), + chainId: handleNumber(chainId), + accessList: parseAccessList(accessList as unknown as [string, string[]][]), + ...vrsForRecovery(handleHexString(vRaw), handleHexString(r), handleHexString(s)), } const signer = @@ -581,7 +588,7 @@ function recoverTransactionCIP42(serializedTransaction: Hex): [CeloTxWithSig, st } function recoverTransactionCIP64(serializedTransaction: Hex): [CeloTxWithSig, string] { - const transactionArray: any[] = prefixAwareRLPDecode(serializedTransaction, 'cip64') + const transactionArray = prefixAwareRLPDecode(serializedTransaction, 'cip64') debug('signing-utils@recoverTransactionCIP64: values are %s', transactionArray) if (transactionArray.length !== 13 && transactionArray.length !== 10) { throw new Error( @@ -602,22 +609,21 @@ function recoverTransactionCIP64(serializedTransaction: Hex): [CeloTxWithSig, st vRaw, r, s, - ] = transactionArray + ] = transactionArray as Uint8Array[] const celoTX: CeloTxWithSig = { type: 'cip64', - nonce: nonce.toLowerCase() === '0x' ? 0 : parseInt(nonce, 16), - maxPriorityFeePerGas: - maxPriorityFeePerGas.toLowerCase() === '0x' ? 0 : parseInt(maxPriorityFeePerGas, 16), - maxFeePerGas: maxFeePerGas.toLowerCase() === '0x' ? 0 : parseInt(maxFeePerGas, 16), - gas: gas.toLowerCase() === '0x' ? 0 : parseInt(gas, 16), - feeCurrency, - to, - value: value.toLowerCase() === '0x' ? 0 : parseInt(value, 16), - data, - chainId: chainId.toLowerCase() === '0x' ? 0 : parseInt(chainId, 16), - accessList: parseAccessList(accessList), - ...vrsForRecovery(vRaw, r, s), + nonce: handleNumber(nonce), + maxPriorityFeePerGas: handleNumber(maxPriorityFeePerGas), + maxFeePerGas: handleNumber(maxFeePerGas), + gas: handleNumber(gas), + feeCurrency: handleHexString(feeCurrency), + to: handleHexString(to), + value: handleNumber(value), + data: handleData(data), + chainId: handleNumber(chainId), + accessList: parseAccessList(accessList as unknown as [string, string[]][]), + ...vrsForRecovery(handleHexString(vRaw), handleHexString(r), handleHexString(s)), } const signer = @@ -626,7 +632,7 @@ function recoverTransactionCIP64(serializedTransaction: Hex): [CeloTxWithSig, st } function recoverTransactionEIP1559(serializedTransaction: Hex): [CeloTxWithSig, string] { - const transactionArray: any[] = prefixAwareRLPDecode(serializedTransaction, 'eip1559') + const transactionArray = prefixAwareRLPDecode(serializedTransaction, 'eip1559') debug('signing-utils@recoverTransactionEIP1559: values are %s', transactionArray) const [ @@ -642,21 +648,20 @@ function recoverTransactionEIP1559(serializedTransaction: Hex): [CeloTxWithSig, vRaw, r, s, - ] = transactionArray + ] = transactionArray as Uint8Array[] const celoTx: CeloTxWithSig = { type: 'eip1559', - nonce: nonce.toLowerCase() === '0x' ? 0 : parseInt(nonce, 16), - gas: gas.toLowerCase() === '0x' ? 0 : parseInt(gas, 16), - maxPriorityFeePerGas: - maxPriorityFeePerGas.toLowerCase() === '0x' ? 0 : parseInt(maxPriorityFeePerGas, 16), - maxFeePerGas: maxFeePerGas.toLowerCase() === '0x' ? 0 : parseInt(maxFeePerGas, 16), - to, - value: value.toLowerCase() === '0x' ? 0 : parseInt(value, 16), - data, - chainId: chainId.toLowerCase() === '0x' ? 0 : parseInt(chainId, 16), - accessList: parseAccessList(accessList), - ...vrsForRecovery(vRaw, r, s), + nonce: handleNumber(nonce), + gas: handleNumber(gas), + maxPriorityFeePerGas: handleNumber(maxPriorityFeePerGas), + maxFeePerGas: handleNumber(maxFeePerGas), + to: handleHexString(to), + value: handleNumber(value), + data: handleData(data), + chainId: handleNumber(chainId), + accessList: parseAccessList(accessList as unknown as [string, string[]][]), + ...vrsForRecovery(handleHexString(vRaw), handleHexString(r), handleHexString(s)), } const web3Account = new Accounts() const signer = web3Account.recoverTransaction(serializedTransaction) @@ -696,30 +701,14 @@ export function verifySignatureWithoutPrefix( } } -function bigintToPaddedHex(n: bigint, length: number): string { - const hex = n.toString(16) - if (hex.length >= length) { - return hex - } - const padded = new Array(length).fill('0').join('') + hex - return padded.slice(-length) -} - export function decodeSig(sig: Hex | ReturnType, addToV = 0) { const { recovery, r, s } = typeof sig === 'string' ? secp256k1.Signature.fromCompact(sig) : sig return { v: recovery! + addToV, - r: Buffer.from(bigintToPaddedHex(r, 64), 'hex'), - s: Buffer.from(bigintToPaddedHex(s, 64), 'hex'), + r: Buffer.from(r.toString(16).padStart(64, '0'), 'hex'), + s: Buffer.from(s.toString(16).padStart(64, '0'), 'hex'), } - // const [v, r, s] = Account.decodeSignature(sig) - - // return { - // v: parseInt(v, 16), - // r: toBuffer(r) as Buffer, - // s: toBuffer(s) as Buffer, - // } } export function signTransaction(hash: Hex, privateKey: Hex, addToV = 0) { @@ -730,3 +719,31 @@ export function signTransaction(hash: Hex, privateKey: Hex, addToV = 0) { ) return decodeSig(signature, addToV) } + +function handleNumber(n: Uint8Array) { + const hex = `0x${bytesToHex(n)}` + if (hex === '0x') return 0 + return parseInt(hex, 16) +} + +// function handleBigNumber(n: Uint8Array) { +// const hex = `0x${bytesToHex(n)}` +// if (hex === '0x') return '0' +// return BigInt(hex) +// } + +function handleHexString(adr: Uint8Array) { + if (!adr.length) { + return '0x' + } + const hex = `0x${bytesToHex(adr)}` + return normalizeAddressWith0x(hex) +} + +function handleData(data: Uint8Array) { + if (!data.length) { + return '0x' + } + const hex = `0x${bytesToHex(data)}` + return hex // unsure +} diff --git a/packages/sdk/wallets/wallet-hsm-aws/package.json b/packages/sdk/wallets/wallet-hsm-aws/package.json index 23244ec9c..70bf8c9cf 100644 --- a/packages/sdk/wallets/wallet-hsm-aws/package.json +++ b/packages/sdk/wallets/wallet-hsm-aws/package.json @@ -32,8 +32,7 @@ "@types/secp256k1": "^4.0.0", "aws-sdk": "^2.705.0", "bignumber.js": "^9.0.0", - "debug": "^4.1.1", - "eth-lib": "^0.2.8" + "debug": "^4.1.1" }, "devDependencies": { "@noble/ciphers": "0.4.1", diff --git a/packages/sdk/wallets/wallet-hsm-azure/package.json b/packages/sdk/wallets/wallet-hsm-azure/package.json index fa083ba25..f4d88cf4e 100644 --- a/packages/sdk/wallets/wallet-hsm-azure/package.json +++ b/packages/sdk/wallets/wallet-hsm-azure/package.json @@ -34,8 +34,7 @@ "@ethereumjs/util": "8.0.5", "@types/secp256k1": "^4.0.0", "bignumber.js": "^9.0.0", - "debug": "^4.1.1", - "eth-lib": "^0.2.8" + "debug": "^4.1.1" }, "devDependencies": { "@noble/ciphers": "0.4.1", diff --git a/packages/sdk/wallets/wallet-hsm-gcp/package.json b/packages/sdk/wallets/wallet-hsm-gcp/package.json index 57cba00b8..fb60da69a 100644 --- a/packages/sdk/wallets/wallet-hsm-gcp/package.json +++ b/packages/sdk/wallets/wallet-hsm-gcp/package.json @@ -31,8 +31,7 @@ "@types/debug": "^4.1.5", "@types/secp256k1": "^4.0.0", "bignumber.js": "^9.0.0", - "debug": "^4.1.1", - "eth-lib": "^0.2.8" + "debug": "^4.1.1" }, "devDependencies": { "@noble/ciphers": "0.4.1", diff --git a/packages/sdk/wallets/wallet-hsm/package.json b/packages/sdk/wallets/wallet-hsm/package.json index 1f7de2a72..d5fd8e8f4 100644 --- a/packages/sdk/wallets/wallet-hsm/package.json +++ b/packages/sdk/wallets/wallet-hsm/package.json @@ -31,8 +31,7 @@ "@types/debug": "^4.1.5", "@types/secp256k1": "^4.0.0", "asn1js": "^2.0.26", - "bignumber.js": "^9.0.0", - "eth-lib": "^0.2.8" + "bignumber.js": "^9.0.0" }, "devDependencies": { "dotenv": "^8.2.0" diff --git a/packages/sdk/wallets/wallet-local/package.json b/packages/sdk/wallets/wallet-local/package.json index d03981d65..f627b5cd4 100644 --- a/packages/sdk/wallets/wallet-local/package.json +++ b/packages/sdk/wallets/wallet-local/package.json @@ -25,8 +25,7 @@ "@celo/connect": "^5.1.2", "@celo/utils": "^6.0.0", "@celo/wallet-base": "^5.1.2", - "@ethereumjs/util": "8.0.5", - "eth-lib": "^0.2.8" + "@ethereumjs/util": "8.0.5" }, "devDependencies": { "viem": "~1.5.4", diff --git a/packages/sdk/wallets/wallet-remote/package.json b/packages/sdk/wallets/wallet-remote/package.json index a2121373c..5ab313259 100644 --- a/packages/sdk/wallets/wallet-remote/package.json +++ b/packages/sdk/wallets/wallet-remote/package.json @@ -26,8 +26,7 @@ "@celo/utils": "^6.0.0", "@celo/wallet-base": "^5.1.2", "@ethereumjs/util": "8.0.5", - "@types/debug": "^4.1.5", - "eth-lib": "^0.2.8" + "@types/debug": "^4.1.5" }, "devDependencies": { "web3": "1.10.0" diff --git a/yarn.lock b/yarn.lock index 554201bb8..3cbe2a4d8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2009,7 +2009,6 @@ __metadata: "@types/debug": "npm:^4.1.5" bignumber.js: "npm:^9.0.0" debug: "npm:^4.1.1" - eth-lib: "npm:^0.2.8" viem: "npm:~1.5.4" web3: "npm:1.10.0" web3-eth-accounts: "npm:1.10.0" @@ -2035,7 +2034,6 @@ __metadata: bignumber.js: "npm:^9.0.0" debug: "npm:^4.1.1" dotenv: "npm:^8.2.0" - eth-lib: "npm:^0.2.8" web3: "npm:1.10.0" languageName: unknown linkType: soft @@ -2061,7 +2059,6 @@ __metadata: bignumber.js: "npm:^9.0.0" debug: "npm:^4.1.1" dotenv: "npm:^8.2.0" - eth-lib: "npm:^0.2.8" web3: "npm:1.10.0" languageName: unknown linkType: soft @@ -2085,7 +2082,6 @@ __metadata: bignumber.js: "npm:^9.0.0" debug: "npm:^4.1.1" dotenv: "npm:^8.2.0" - eth-lib: "npm:^0.2.8" web3: "npm:1.10.0" languageName: unknown linkType: soft @@ -2105,7 +2101,6 @@ __metadata: asn1js: "npm:^2.0.26" bignumber.js: "npm:^9.0.0" dotenv: "npm:^8.2.0" - eth-lib: "npm:^0.2.8" languageName: unknown linkType: soft @@ -2137,7 +2132,6 @@ __metadata: "@celo/utils": "npm:^6.0.0" "@celo/wallet-base": "npm:^5.1.2" "@ethereumjs/util": "npm:8.0.5" - eth-lib: "npm:^0.2.8" viem: "npm:~1.5.4" web3: "npm:1.10.0" languageName: unknown @@ -2152,7 +2146,6 @@ __metadata: "@celo/wallet-base": "npm:^5.1.2" "@ethereumjs/util": "npm:8.0.5" "@types/debug": "npm:^4.1.5" - eth-lib: "npm:^0.2.8" web3: "npm:1.10.0" languageName: unknown linkType: soft @@ -11425,7 +11418,7 @@ __metadata: languageName: node linkType: hard -"eth-lib@npm:0.2.8, eth-lib@npm:^0.2.8": +"eth-lib@npm:0.2.8": version: 0.2.8 resolution: "eth-lib@npm:0.2.8" dependencies: