Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
avkos committed Jun 12, 2024
1 parent 93b28a5 commit 7c00ed8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 36 deletions.
18 changes: 0 additions & 18 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -881,21 +881,3 @@ export type Eip712TxData = FeeMarketEIP1559TxData & {
hash?: string;
signature?: string;
};

export const EIP712_TYPES = {
Transaction: [
{ name: 'txType', type: 'uint256' },
{ name: 'from', type: 'uint256' },
{ name: 'to', type: 'uint256' },
{ name: 'gasLimit', type: 'uint256' },
{ name: 'gasPerPubdataByteLimit', type: 'uint256' },
{ name: 'maxFeePerGas', type: 'uint256' },
{ name: 'maxPriorityFeePerGas', type: 'uint256' },
{ name: 'paymaster', type: 'uint256' },
{ name: 'nonce', type: 'uint256' },
{ name: 'value', type: 'uint256' },
{ name: 'data', type: 'bytes' },
{ name: 'factoryDeps', type: 'bytes32[]' },
{ name: 'paymasterInput', type: 'bytes' },
],
};
16 changes: 7 additions & 9 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ export class SignatureObject {
v?: web3Types.Numbers,
) {
if (typeof rOrSignature === 'string') {
if (rOrSignature.length !== 132) {
throw new Error('Invalid signature length');
}
// if (rOrSignature.length !== 132) {
// throw new Error('Invalid signature length');
// }
// Initialize with a single string parameter
const signature = rOrSignature;
this.r = web3Accounts.toUint8Array(signature.slice(0, 66));
Expand Down Expand Up @@ -710,18 +710,16 @@ export function serializeEip712(transaction: Eip712TxData, signature?: Signature
? new Uint8Array()
: toBytes(transaction.gasLimit!),
transaction.to ? web3Utils.toChecksumAddress(toHex(transaction.to)) : '0x',
toHex(transaction.value || 0) === '0x0'
? new Uint8Array()
: toBytes(toHex(transaction.value || 0)),
toHex(transaction.value || 0) === '0x0' ? new Uint8Array() : toHex(transaction.value || 0),
toHex(transaction.data || '0x'),
];

if (signature) {
const sig = new SignatureObject(signature);
// fields.push(toBytes(sig.yParity));
fields.push(toBytes(Number(sig.v) === 27 ? 0 : 1));
fields.push(toBytes(sig.r));
fields.push(toBytes(sig.s));
fields.push(toHex(Number(sig.v) === 27 ? 0 : 1));
fields.push(toHex(sig.r));
fields.push(toHex(sig.s));
} else {
fields.push(toHex(transaction.chainId));
fields.push('0x');
Expand Down
16 changes: 7 additions & 9 deletions test/unit/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { Web3 } from 'web3';
import * as web3Accounts from 'web3-eth-accounts';

import type { types } from '../../src';
import { utils } from '../../src';
import { ADDRESS1, ADDRESS2 } from '../utils';
import * as constants from '../../src/constants';
import { getSignInput, serializeEip712 } from '../../src/utils';

describe('utils', () => {
describe('#getHashedL2ToL1Msg()', () => {
Expand Down Expand Up @@ -160,11 +158,11 @@ describe('utils', () => {
it.only('should return a serialized transaction with provided signature', async () => {
const tx =
'0x71f87f8080808094a61464658afeaf65cccaafd3a512b69a83b77618830f42408001a073a20167b8d23b610b058c05368174495adf7da3a4ed4a57eb6dbdeb1fafc24aa02f87530d663a0d061f69bb564d2c6fb46ae5ae776bbd4bd2a2a4478b9cd1b42a82010e9436615cf349d7f6344891b1e7ca7c72883f5dc04982c350c080c0';

const signature =
'0x73a20167b8d23b610b058c05368174495adf7da3a4ed4a57eb6dbdeb1fafc24aaf87530d663a0d061f69bb564d2c6fb46ae5ae776bbd4bd2a2a4478b9cd1b42a';

// wallet.sign(message).signature;
const signature = new utils.SignatureObject(
'0x73a20167b8d23b610b058c05368174495adf7da3a4ed4a57eb6dbdeb1fafc24aaf87530d663a0d061f69bb564d2c6fb46ae5ae776bbd4bd2a2a4478b9cd1b42a',
);
const recoveredTx = utils.parseEip712(tx);
console.log('recoveredTx', recoveredTx);
// const signature = s.toString();
const result = utils.serializeEip712(
{
Expand Down Expand Up @@ -322,7 +320,7 @@ describe('utils', () => {

// const eip712Signer = new EIP712Signer(new Wallet(PRIVATE_KEY), web3.config.chainId);

const signInput = getSignInput(tx);
const signInput = utils.getSignInput(tx);

// const signInput = {
// txType: 113,
Expand Down Expand Up @@ -352,7 +350,7 @@ describe('utils', () => {
// const hash = eip712TxHash(tx);
// console.log('typedData', hash);

const signature = serializeEip712(signInput);
const signature = utils.serializeEip712(signInput);
console.log('signature', signature);
// const signature = await web3.eth.signTypedData(account.address, typedData);

Expand Down

0 comments on commit 7c00ed8

Please sign in to comment.