Skip to content

Commit

Permalink
problem: incompatible with new sepolia testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
splix committed Apr 24, 2024
1 parent f785ff4 commit 3bea460
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 111 deletions.
3 changes: 2 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
},
"devDependencies": {
"@types/jest": "24.0.13",
"@types/node": "^20.12.7",
"jest": "24.8.0",
"jest-serial-runner": "1.1.0",
"rimraf": "^2.6.3",
"ts-jest": "24.0.2",
"typescript": "^3.9.10"
"typescript": "^4.9.5"
}
}
6 changes: 4 additions & 2 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export enum BlockchainId {
KOVAN_TESTNET = 10002,
BITCOIN_TESTNET = 10003,
GOERLI_TESTNET = 10005,
SEPOLIA_TESTNET = 10009,
}

export const DEFAULT_BITCOIN_SEQ = 0xfffffffe;
Expand All @@ -39,7 +40,7 @@ export function getBlockchainType(id: BlockchainId): BlockchainType {
if (id == BlockchainId.BITCOIN || id == BlockchainId.BITCOIN_TESTNET) {
return "bitcoin";
}
if (id == BlockchainId.ETHEREUM || id == BlockchainId.ETHEREUM_CLASSIC || id == BlockchainId.KOVAN_TESTNET || id == BlockchainId.GOERLI_TESTNET) {
if (id == BlockchainId.ETHEREUM || id == BlockchainId.ETHEREUM_CLASSIC || id == BlockchainId.KOVAN_TESTNET || id == BlockchainId.GOERLI_TESTNET || id == BlockchainId.SEPOLIA_TESTNET) {
return "ethereum";
}
throw new Error("Unsupported id: " + id);
Expand All @@ -48,7 +49,8 @@ export function getBlockchainType(id: BlockchainId): BlockchainType {
export function isBlockchainId(id: number): id is BlockchainId {
return id === BlockchainId.BITCOIN || id === BlockchainId.BITCOIN_TESTNET
|| id === BlockchainId.ETHEREUM || id === BlockchainId.ETHEREUM_CLASSIC
|| id === BlockchainId.KOVAN_TESTNET || id === BlockchainId.GOERLI_TESTNET;
|| id === BlockchainId.KOVAN_TESTNET || id === BlockchainId.GOERLI_TESTNET || id === BlockchainId.SEPOLIA_TESTNET
;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/native/native/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions packages/native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"@jest-runner/electron": "^2.0.3",
"@mapbox/node-pre-gyp": "^1.0.8",
"@types/jest": "24.0.13",
"@types/node": "^16.0.0",
"@types/node": "^20.12.7",
"bitcoinjs-lib": "^5.2.0",
"cross-env": "6.0.3",
"crypto-js": "^4.0.0",
Expand All @@ -80,9 +80,9 @@
"node-gyp": "8.4.1",
"rimraf": "^2.6.3",
"ts-jest": "24.0.2",
"typescript": "^3.9.10",
"typescript": "^4.9.5",
"unzipper": "0.10.5",
"@ethereumjs/common": "^3.2.0",
"@ethereumjs/tx": "^4.2.0"
"@ethereumjs/common": "^4.3.0",
"@ethereumjs/tx": "^5.3.0"
}
}
26 changes: 7 additions & 19 deletions packages/native/src/__integration-tests__/sign_ethereum.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@ describe('Sign different tx combinations (slow to execute)', () => {
function testAll(entryId: EntryId, chainId: number): Promise<any> {
let chainConfig = {};
if (chainId !== 1) {
chainConfig = {common: Common.custom({ chainId }, { baseChain: 1, hardfork: Hardfork.Byzantium })};
chainConfig = {common: Common.custom({ chainId }, { baseChain: 1, hardfork: Hardfork.Shanghai })};
} else {
chainConfig = {common: new Common({ hardfork: Hardfork.Shanghai, chain: chainId })};
}

let result = [];
["0", "1", "255", "256", "1000000000000000000", "12345600000000000000"].forEach((value) => {
["0", "1", "255", "256", "1000000000000000000"].forEach((value) => {
[0x5208, 0x1fbd0, 0x1, 0xb7, 0x100].forEach((gas) => {
["2000000000", "1", "0", "128"].forEach((gasPrice) => {
[0x0, 0x1, 0x1f, 0xff, 0x38ae].forEach((nonce) => {
[0x0, 0x1, 0xff, 0x38ae].forEach((nonce) => {
["", "d0e30db0", "095ea7b300000000000000000000000036a8ce9b0b86361a02070e4303d5e24d6c63b3f10000000000000000000000000000000000000000033b2e3c9fd0803ce8000000"].forEach((data) => {
["0x3eaf0b987b49c4d782ee134fdc1243fd0ccdfdd3"].forEach(async (to) => {
let tx = {
Expand All @@ -107,14 +107,14 @@ describe('Sign different tx combinations (slow to execute)', () => {
console.error(e);
}
expect(parsed).toBeDefined();
expect(convertHex(parsed.hash())).toBe(raw.txid);
expect(convertHex(Buffer.from(parsed.hash()))).toBe(raw.txid);
expect(parsed.getSenderAddress().toString()).toBe("0x36a8ce9b0b86361a02070e4303d5e24d6c63b3f1");
expect(parsed.to.toString()).toBe(to);
expect(parsed.value.toString()).toBe(value);
expect(parsed.gasLimit.toString()).toBe(gas.toString());
// expect(hexQuantity(convertHex(parsed.gasPrice))).toBe(gasPrice);
expect(parsed.nonce.toString()).toBe(nonce.toString());
expect(parsed.data.toString('hex')).toBe(data);
expect(Buffer.from(parsed.data).toString("hex")).toBe(data);
expect(parseInt(parsed.v.toString())).toBeGreaterThanOrEqual(chainId * 2 + 35);
expect(parseInt(parsed.v.toString())).toBeLessThanOrEqual(chainId * 2 + 36);
})
Expand Down Expand Up @@ -152,18 +152,6 @@ describe('Sign different tx combinations (slow to execute)', () => {
await testAll(entryId, 61);
});

test("Kovan", async () => {
let walletId = await vault.addWallet("slow sign Kovan");
let entryId = await vault.addEntry(walletId, {
blockchain: 10002,
type: "ethereum-json",
key: JSON.stringify(pk),
jsonPassword: "123456",
password: "global-password"
});
await testAll(entryId, 42);
})

});

describe('Sign different key combinations (slow to execute)', () => {
Expand Down Expand Up @@ -216,11 +204,11 @@ describe('Sign different key combinations (slow to execute)', () => {

let raw = await vault.signTx(entry.id, tx, "global-password");
expect(raw).toBeDefined();
let parsed: Transaction;
let parsed;
try {
const bytes = Buffer.from(raw.raw.slice(2), 'hex');
let chainConfig = {common: new Common({ hardfork: Hardfork.Shanghai, chain: chainId })};
parsed = TransactionFactory.fromSerializedData(bytes, chainConfig) as Transaction;
parsed = TransactionFactory.fromSerializedData(bytes, chainConfig);
} catch (e) {
console.error("Invalid signature", tx);
console.error("Raw", raw);
Expand Down
4 changes: 2 additions & 2 deletions packages/native/src/__tests__/entries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ describe("Entries", () => {

describe("Details", () => {
let vault: EmeraldVaultNative;
beforeAll(async () => {
beforeEach(async () => {
vault = new EmeraldVaultNative({
dir: tempPath("entry-details")
});
vault.open();
await vault.createGlobalKey("test");
});
afterAll(() => {
afterEach(() => {
vault.close()
});

Expand Down
40 changes: 40 additions & 0 deletions packages/native/src/__tests__/signTx.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {EmeraldVaultNative} from "../EmeraldVaultNative";
import {tempPath} from "./_commons";
import {BlockchainId, UnsignedBitcoinTx, WalletsOp} from "@emeraldpay/emerald-vault-core";
import {TransactionFactory, TypedTransaction} from '@ethereumjs/tx';
import {Common, Hardfork} from "@ethereumjs/common";


describe("Sign transaction", () => {
Expand Down Expand Up @@ -211,6 +213,44 @@ describe("Sign transaction", () => {
expect(raw.txid).toBe("0x7b0958868a76aee6803da842859c40e4594e762c8f26304d54e05cff60b1fac4");
});

test("sign sepolia tx", async () => {
let walletId = await vault.addWallet("test");
let seedId = await vault.importSeed({
type: "mnemonic",
value: {
value: "fever misery evidence miss toddler fold scatter mail believe fire cabbage story verify tunnel echo"
},
password: "test-global"
});
let entryId = await vault.addEntry(walletId, {
blockchain: 10009,
type: "hd-path",
key: {
seed: {type: "id", value: seedId, password: "test-global"},
hdPath: "m/44'/60'/0'/0/3",
}
});

let tx = {
from: "0xD4345AbBeEF14d2Fd2E0DEB898A67c26F1cbC4F1",
to: "0x3eaf0b987b49c4d782ee134fdc1243fd0ccdfdd3",
value: "0",
gas: 0x5208,
maxGasPrice: "2000000000",
priorityGasPrice: "100000",
nonce: 0x19
};
let raw = await vault.signTx(entryId, tx, "test-global");

let chainConfig = new Common({ chain: 'sepolia', hardfork: 'shanghai' });
const bytes = Buffer.from(raw.raw.slice(2), 'hex');
let parsed = TransactionFactory.fromSerializedData(bytes, {common: chainConfig});

expect(parsed.getSenderAddress().toString().toLowerCase()).toBe("0xD4345AbBeEF14d2Fd2E0DEB898A67c26F1cbC4F1".toLowerCase());
expect(parsed.nonce.toString()).toBe("25");
expect(parsed.to.toString().toLowerCase()).toBe("0x3eaf0b987b49c4d782ee134fdc1243fd0ccdfdd3".toLowerCase());
});

test("sign bitcoin tx", async () => {
let walletId = await vault.addWallet("test sign 2");
let seedId = await vault.importSeed({
Expand Down
Loading

0 comments on commit 3bea460

Please sign in to comment.