Skip to content

Commit

Permalink
Merge branch 'dev' into nb/addr-fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
netbonus committed Aug 19, 2024
2 parents 047c230 + 1a1f9da commit 3850591
Show file tree
Hide file tree
Showing 14 changed files with 6,332 additions and 16,506 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Install Node.js
uses: actions/setup-node@v1
with:
node-version: 16.x
node-version: 18.x

- name: Install NPM packages
run: npm ci
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16
18
22,546 changes: 6,132 additions & 16,414 deletions package-lock.json

Large diffs are not rendered by default.

33 changes: 14 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,33 +48,28 @@
"js-sha3": "^0.9.3"
},
"dependencies": {
"@ethereumjs/common": "3.1.2",
"@ethereumjs/tx": "4.1.2",
"@ethereumjs/common": "4.3.0",
"@ethereumjs/rlp": "^5.0.2",
"@ethereumjs/tx": "5.3.0",
"@ethersproject/abi": "^5.7.0",
"@metamask/eth-sig-util": "^7.0.2",
"@types/uuid": "^9.0.0",
"aes-js": "^3.1.1",
"@metamask/eth-sig-util": "^7.0.3",
"@types/uuid": "^10.0.0",
"aes-js": "^3.1.2",
"bech32": "^2.0.0",
"bignumber.js": "^9.1.1",
"bitwise": "^2.0.4",
"borc": "^2.1.2",
"bs58check": "^2.1.2",
"bignumber.js": "^9.1.2",
"bitwise": "^2.2.1",
"borc": "^3.0.0",
"bs58check": "^4.0.0",
"buffer": "^6.0.3",
"crc-32": "^1.2.0",
"elliptic": "6.5.4",
"crc-32": "^1.2.2",
"elliptic": "6.5.6",
"hash.js": "^1.1.7",
"js-sha3": "^0.9.3",
"rlp": "^3.0.0",
"secp256k1": "5.0.0",
"uuid": "^9.0.0"
"uuid": "^10.0.0"
},
"devDependencies": {
"@babel/core": "^7.18.2",
"@babel/preset-env": "^7.18.2",
"@babel/preset-typescript": "^7.17.12",
"@chainsafe/bls-keystore": "^3.0.0",
"@ethersproject/providers": "^5.7.2",
"@ethersproject/transactions": "^5.5.0",
"@noble/bls12-381": "^1.3.0",
"@solana/web3.js": "^1.90.0",
"@terra-money/terra.js": "^3.0.7",
Expand Down Expand Up @@ -102,7 +97,7 @@
"jsonc": "^2.0.0",
"lodash": ">=4.17.21",
"minimist": ">=0.2.1",
"msw": "^0.42.0",
"msw": "^2.3.4",
"node-fetch": "^3.2.10",
"patch-package": "^6.4.7",
"prettier": "^2.6.2",
Expand Down
4 changes: 2 additions & 2 deletions src/__test__/e2e/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getClient } from './../../api/utilities';
import { Chain, Common, Hardfork } from '@ethereumjs/common';
import { TransactionFactory } from '@ethereumjs/tx';
import { question } from 'readline-sync';
import { encode } from 'rlp';
import { RLP } from '@ethereumjs/rlp';
import {
fetchActiveWallets,
fetchAddress,
Expand Down Expand Up @@ -120,7 +120,7 @@ describe('API', () => {
});

test('legacy', async () => {
const rawTx = encode([
const rawTx = RLP.encode([
txData.nonce,
txData.gasPrice,
txData.gasLimit,
Expand Down
114 changes: 114 additions & 0 deletions src/__test__/e2e/bug.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/* eslint-disable quotes */
import { question } from 'readline-sync';
import { getClient, pair } from '../../api';
import { sign } from '../../api/index';

Check warning on line 4 in src/__test__/e2e/bug.test.ts

View workflow job for this annotation

GitHub Actions / Build

'sign' is defined but never used
import { setupClient } from '../utils/setup';

describe('bug', () => {
test('pair', async () => {
const isPaired = await setupClient();
if (!isPaired) {
const secret = question('Please enter the pairing secret: ');
await pair(secret.toUpperCase());
}
});

test('payload', async () => {
const client = getClient();
await client.sign({
currency: 'ETH_MSG',
data: {
signerPath: [2147483692, 2147483708, 2147483648, 0, 0],
protocol: 'eip712',
payload: {
types: {
EIP712Domain: [
{
name: 'name',
type: 'string',
},
{
name: 'version',
type: 'string',
},
{
name: 'chainId',
type: 'uint256',
},
{
name: 'verifyingContract',
type: 'address',
},
],
Group: [
{
name: 'name',
type: 'string',
},
{
name: 'members',
type: 'Person[]',
},
],
Mail: [
{
name: 'from',
type: 'Person',
},
{
name: 'to',
type: 'Person[]',
},
{
name: 'contents',
type: 'string',
},
{
name: 'attachment',
type: 'bytes',
},
],
Person: [
{
name: 'name',
type: 'string',
},
{
name: 'wallets',
type: 'address[]',
},
],
},
primaryType: 'Mail',
domain: {
chainId: '0xaa36a7',
name: 'Ether Mail',
verifyingContract: '0xcccccccccccccccccccccccccccccccccccccccc',
version: '1',
},
message: {
contents: 'Hello, Bob!',
from: {
name: 'Cow',
wallets: [
'0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826',
'0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
],
},
to: [
{
name: 'Bob',
wallets: [
'0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
'0xb0bdabea57b0bdabea57b0bdabea57b0bdabea57',
'0xb0b0b0b0b0b0b000000000000000000000000000',
],
},
],
attachment: '0x',
},
},
},
});
});
});
2 changes: 1 addition & 1 deletion src/__test__/e2e/signing/evm-abi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ describe('[EVM ABI]', () => {
// should uncomment these prints and validate that the `data` matches
// what you see on the screen for each case. Please scroll through
// ALL the data on the Lattice to confirm each param has properly decoded.
// const { types, data } = convertDecoderToEthers(rlpDecode(req.data.decoder).slice(1));
// const { types, data } = convertDecoderToEthers(RLP.decode(req.data.decoder).slice(1));
// console.log('types', types)
// console.log('params', JSON.stringify(data))
// for (let cd = 2; cd < calldata.length; cd += 64) {
Expand Down
6 changes: 3 additions & 3 deletions src/__test__/e2e/signing/evm-tx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ You must have `FEATURE_TEST_RUNNER=1` enabled in firmware to run these tests.
import { Chain, Common, Hardfork } from '@ethereumjs/common';
import { TransactionFactory as EthTxFactory } from '@ethereumjs/tx';
import { BN } from 'bn.js';
import { encode as rlpEncode } from 'rlp';
import { RLP } from '@ethereumjs/rlp';
import { randomBytes } from '../../../util';
import { DEFAULT_SIGNER, buildEvmReq, getNumIter } from '../../utils/builders';
import { runEvm } from '../../utils/runners';
Expand Down Expand Up @@ -254,7 +254,7 @@ describe('[EVM TX]', () => {
const dummyTx = EthTxFactory.fromTxData(req.txData, {
common: req.common,
});
const dummyTxSz = rlpEncode(dummyTx.getMessageToSign(false)).length;
const dummyTxSz = RLP.encode(dummyTx.getMessageToSign(false)).length;
const rlpPrefixSz = 4; // 1 byte for descriptor, 1 byte for length, 2 bytes for length
const maxDataSz = maxSz - dummyTxSz - rlpPrefixSz;

Expand Down Expand Up @@ -289,7 +289,7 @@ describe('[EVM TX]', () => {
const getParamPayloadReq = (n: number, val?: any) => {
const params = tx.getMessageToSign(false);
params[n] = oversizedInt;
return { data: { payload: val ? val : rlpEncode(params) } };
return { data: { payload: val ? val : RLP.encode(params) } };
};
// Test numerical values >32 bytes
// ---
Expand Down
92 changes: 45 additions & 47 deletions src/__test__/integration/__mocks__/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { rest } from 'msw';
import { http, HttpResponse } from 'msw';
import connectResponse from './connect.json';
import getAddressesResponse from './getAddresses.json';
import signResponse from './sign.json';
Expand All @@ -22,80 +22,78 @@ import {
} from './4byte';

export const handlers = [
rest.post('https://signing.gridpl.us/test/connect', (req, res, ctx) => {
return res(ctx.json(connectResponse));
http.post('https://signing.gridpl.us/test/connect', () => {
return HttpResponse.json(connectResponse);
}),
rest.post('https://signing.gridpl.us/test/getAddresses', (req, res, ctx) => {
return res(ctx.json(getAddressesResponse));
http.post('https://signing.gridpl.us/test/getAddresses', () => {
return HttpResponse.json(getAddressesResponse);
}),
rest.post('https://signing.gridpl.us/test/sign', (req, res, ctx) => {
return res(ctx.json(signResponse));
http.post('https://signing.gridpl.us/test/sign', () => {
return HttpResponse.json(signResponse);
}),
rest.post(
'https://signing.gridpl.us/test/fetchActiveWallet',
(req, res, ctx) => {
return res(ctx.json(fetchActiveWalletResponse));
},
),
rest.post('https://signing.gridpl.us/test/addKvRecords', (req, res, ctx) => {
return res(ctx.json(addKvRecordsResponse));
http.post('https://signing.gridpl.us/test/fetchActiveWallet', () => {
return HttpResponse.json(fetchActiveWalletResponse);
}),
rest.post('https://signing.gridpl.us/test/getKvRecords', (req, res, ctx) => {
return res(ctx.json(getKvRecordsResponse));
http.post('https://signing.gridpl.us/test/addKvRecords', () => {
return HttpResponse.json(addKvRecordsResponse);
}),
rest.post(
'https://signing.gridpl.us/test/removeKvRecords',
(req, res, ctx) => {
return res(ctx.json(removeKvRecordsResponse));
},
),
rest.get('https://api.etherscan.io/api', (req, res, ctx) => {
const module = req.url.searchParams.get('module');
const action = req.url.searchParams.get('action');
const address = req.url.searchParams.get('address');
http.post('https://signing.gridpl.us/test/getKvRecords', () => {
return HttpResponse.json(getKvRecordsResponse);
}),
http.post('https://signing.gridpl.us/test/removeKvRecords', () => {
return HttpResponse.json(removeKvRecordsResponse);
}),
http.get('https://api.etherscan.io/api', ({ request }) => {
const url = new URL(request.url);
const module = url.searchParams.get('module');
const action = url.searchParams.get('action');
const address = url.searchParams.get('address');

if (module === 'contract' && action === 'getabi') {
if (address === '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48') {
return res(
ctx.json({ result: JSON.stringify(etherscanResponse0xa0b86991) }),
);
return HttpResponse.json({
result: JSON.stringify(etherscanResponse0xa0b86991),
});
}
if (address === '0x7a250d5630b4cf539739df2c5dacb4c659f2488d') {
return res(
ctx.json({ result: JSON.stringify(etherscanResponse0x7a250d56) }),
);
return HttpResponse.json({
result: JSON.stringify(etherscanResponse0x7a250d56),
});
}
if (address === '0xc36442b4a4522e871399cd717abdd847ab11fe88') {
return res(
ctx.json({ result: JSON.stringify(etherscanResponse0xc36442b6) }),
);
return HttpResponse.json({
result: JSON.stringify(etherscanResponse0xc36442b6),
});
}
if (address === '0x06412d7ebfbf66c25607e2ed24c1d207043be327') {
return res(
ctx.json({ result: JSON.stringify(etherscanResponse0x06412d7e) }),
);
return HttpResponse.json({
result: JSON.stringify(etherscanResponse0x06412d7e),
});
}
}
return new HttpResponse(null, { status: 404 });
}),
rest.get('https://www.4byte.directory/api/v1/signatures', (req, res, ctx) => {
const hexSignature = req.url.searchParams.get('hex_signature');
http.get('https://www.4byte.directory/api/v1/signatures', ({ request }) => {
const url = new URL(request.url);
const hexSignature = url.searchParams.get('hex_signature');
if (hexSignature === '0xa9059cbb') {
return res(ctx.json(fourbyteResponse0xa9059cbb));
return HttpResponse.json(fourbyteResponse0xa9059cbb);
}
if (hexSignature === '0x38ed1739') {
return res(ctx.json(fourbyteResponse0x38ed1739));
return HttpResponse.json(fourbyteResponse0x38ed1739);
}
if (hexSignature === '0xac9650d8') {
return res(ctx.json(fourbyteResponseac9650d8));
return HttpResponse.json(fourbyteResponseac9650d8);
}
if (hexSignature === '0x0c49ccbe') {
return res(ctx.json(fourbyteResponse0c49ccbe));
return HttpResponse.json(fourbyteResponse0c49ccbe);
}
if (hexSignature === '0xfc6f7865') {
return res(ctx.json(fourbyteResponsefc6f7865));
return HttpResponse.json(fourbyteResponsefc6f7865);
}
if (hexSignature === '0x6a761202') {
return res(ctx.json(fourbyteResponse0x6a761202));
return HttpResponse.json(fourbyteResponse0x6a761202);
}
return new HttpResponse(null, { status: 404 });
}),
];
6 changes: 3 additions & 3 deletions src/__test__/utils/builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import { AbiCoder } from '@ethersproject/abi';
import { keccak256 } from 'js-sha3';
import randomWords from 'random-words';
import { decode as rlpDecode, encode as rlpEncode } from 'rlp';
import { RLP } from '@ethereumjs/rlp';
import { Calldata, Constants } from '../..';
import { Client } from '../../client';
import {
Expand Down Expand Up @@ -303,9 +303,9 @@ export const buildEncDefs = (vectors: any) => {
const name = vectors.canonicalNames[i];
const selector = `0x${keccak256(name).slice(0, 8)}`;
const def = EVMCalldata.parsers.parseCanonicalName(selector, name);
const encDef = Buffer.from(rlpEncode(def));
const encDef = Buffer.from(RLP.encode(def));
encDefs.push(encDef);
const { types, data } = convertDecoderToEthers(rlpDecode(encDef).slice(1));
const { types, data } = convertDecoderToEthers(RLP.decode(encDef).slice(1));
const calldata = coder.encode(types, data);
encDefsCalldata.push(`${selector}${calldata.slice(2)}`);
}
Expand Down
Loading

0 comments on commit 3850591

Please sign in to comment.