Skip to content

Commit

Permalink
test: add test for erc4361
Browse files Browse the repository at this point in the history
  • Loading branch information
Z4karia committed Oct 15, 2024
1 parent b17e8cc commit dd94310
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
27 changes: 19 additions & 8 deletions tests/newops/AcreBtcNew.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import AcreBtcNew from "../../src/AcreBtcNew";
import { DefaultDescriptorTemplate, WalletPolicy } from "../../src/newops/policy";
import { PsbtV2 } from "../../src/newops/psbtv2";
import { splitTransaction } from "../../src/splitTransaction";
import { withdrawalAPDUs, signMessageAPDUs } from "./apdus";
import { withdrawalAPDUs, signMessageAPDUs, signERC4361APDUs } from "./apdus";
import {
StandardPurpose,
addressFormatFromDescriptorTemplate,
Expand Down Expand Up @@ -58,10 +58,13 @@ test("testSignMessage", async () => {
await testSignMessageReplayer("m/44'/0'/0'");
});

test("signWithdrawal", async () => {
await testSignWithdrawalReplayer();
});

test("Sign ERC-4361 message", async () => {
await testSignERC4361Speculos();
}, 60 * 10 * 1000); // 10-minute timeout (60 seconds * 10 minutes * 1000 milliseconds)
test("Sign ERC4361 message", async () => {
await testSignERC4361MessageReplayer("m/44'/0'/0'");
});

function testPaths(type: StandardPurpose): { ins: string[]; out?: string } {
const basePath = `m/${type}/1'/0'/`;
Expand Down Expand Up @@ -230,14 +233,22 @@ async function testSignWithdrawalReplayer() {
});
}

async function testSignERC4361Speculos() {
const transport = new SpeculosTransport('http://localhost:5000')
async function testSignERC4361MessageReplayer(
accountPath: string,
) {
const transport = await openTransportReplayer(RecordStore.fromString(signERC4361APDUs));
const client = new AppClient(transport);
const path = accountPath + "/0/0";

const acreBtcNew = new AcreBtcNew(client);
const message = "stake.acre.fi wants you to sign in with your Bitcoin account:\nbc1q8fq0vs2f9g52cuk8px9f664qs0j7vtmx3r7wvx\n\n\nURI: https://stake.acre.fi\nVersion: 1\nNonce: cw73Kfdfn1lY42Jj8\nIssued At: 2024-10-01T11:03:05.707Z\nExpiration Time: 2024-10-08T11:03:05.707Z"
const path = "m/44'/0'/0'/0/0";
const result = await acreBtcNew.signERC4361Message({messageHex: Buffer.from(message).toString("hex"), path: path});
console.log(result);
expect(result).toEqual({
v: 1,
r: 'f30ff91331b840cc97560b468d9dce0647afbef7fd74819773721a096905da7e',
s: '664a3ce374f1951e40222d433cd8d6977dde08af6320acc8dd90fa35ed1c8ed8'
});

}

function verifyGetWalletPublicKeyResult(
Expand Down
21 changes: 21 additions & 0 deletions tests/newops/apdus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,24 @@ export const signMessageAPDUs = `
=> f80100000705050074657374
<= 1fdf44ce2f8f6f62fec9b0d01bd66bc91aa73984e0cf02ad8ff7bf12f8013ba7796d8ed4d795a542509ec7f63539ec6521a3d61a29e4cf9c6d9a386b06b32f224b9000
`;

export const signERC4361APDUs = `
=> e112000036058000002c80000000800000000000000000000000f714384fe48a178439d013364f5dda49f7996a5551e3c00727531906947ab21fc4
<= 4114384fe48a178439d013364f5dda49f7996a5551e3c00727531906947ab21fc40400e000
=> f801000062ed3e2c87ab5f2018467fec3740401cb87241e888f037e374331ae85a1ba5a22702026d870786ec5cd40f6898c4a13b94f8d5bcb50b776a7e83f868779d1a6b0ed170b0448f3bddf3fbc48f3e6d029aa0e43d8b882fd0bd490a18a01699eb4d1397b3
<= 4000ed3e2c87ab5f2018467fec3740401cb87241e888f037e374331ae85a1ba5a227e000
=> f8010000434141007374616b652e616372652e66692077616e747320796f7520746f207369676e20696e207769746820796f757220426974636f696e206163636f756e743a0a6263
<= 4114384fe48a178439d013364f5dda49f7996a5551e3c00727531906947ab21fc40401e000
=> f8010000626d870786ec5cd40f6898c4a13b94f8d5bcb50b776a7e83f868779d1a6b0ed1700202ed3e2c87ab5f2018467fec3740401cb87241e888f037e374331ae85a1ba5a227b0448f3bddf3fbc48f3e6d029aa0e43d8b882fd0bd490a18a01699eb4d1397b3
<= 40006d870786ec5cd40f6898c4a13b94f8d5bcb50b776a7e83f868779d1a6b0ed170e000
=> f801000043414100317138667130767332663967353263756b38707839663636347173306a3776746d783372377776780a0a0a5552493a2068747470733a2f2f7374616b652e6163
<= 4114384fe48a178439d013364f5dda49f7996a5551e3c00727531906947ab21fc40402e000
=> f801000062b02d2a861a934a4c9b88de91a2e1c399da88b1023423fdf60d8df66374fa1b9602023e0f091cf7fe3103e1327a1f734f4a2982068f8e9b33dd397d55fbe850967d61021417016261f943d7a7d76b4dc93c9cdac00805ee05e14233439b768148e06a
<= 4000b02d2a861a934a4c9b88de91a2e1c399da88b1023423fdf60d8df66374fa1b96e000
=> f80100004341410072652e66690a56657273696f6e3a20310a4e6f6e63653a20637737334b6664666e316c5934324a6a380a4973737565642041743a20323032342d31302d303154
<= 4114384fe48a178439d013364f5dda49f7996a5551e3c00727531906947ab21fc40403e000
=> f8010000623e0f091cf7fe3103e1327a1f734f4a2982068f8e9b33dd397d55fbe850967d610202b02d2a861a934a4c9b88de91a2e1c399da88b1023423fdf60d8df66374fa1b96021417016261f943d7a7d76b4dc93c9cdac00805ee05e14233439b768148e06a
<= 40003e0f091cf7fe3103e1327a1f734f4a2982068f8e9b33dd397d55fbe850967d61e000
=> f80100003a38380031313a30333a30352e3730375a0a45787069726174696f6e2054696d653a20323032342d31302d30385431313a30333a30352e3730375a
<= 20f30ff91331b840cc97560b468d9dce0647afbef7fd74819773721a096905da7e664a3ce374f1951e40222d433cd8d6977dde08af6320acc8dd90fa35ed1c8ed89000
`;

0 comments on commit dd94310

Please sign in to comment.