Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Porting src javascript files to typescript #150

Closed
wants to merge 11 commits into from
3 changes: 1 addition & 2 deletions app/src/apdu_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ static uint32_t msg_counter = 0;
void
extractHDPath(uint32_t rx, uint32_t offset, uint32_t path_len)
{

if ((rx - offset) < sizeof(uint32_t) * path_len) {
THROW(APDU_CODE_WRONG_LENGTH);
}
Expand Down Expand Up @@ -383,7 +382,7 @@ handleSign(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx)
break;

default:
THROW(APDU_CODE_COMMAND_NOT_ALLOWED);
THROW(APDU_CODE_COMMAND_NOT_ALLOWED);
break;
}
CHECK_APP_CANARY()
Expand Down
14 changes: 6 additions & 8 deletions tests_zemu/tests/eth_tests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,21 @@ describe.each(models)('ETH', function (m) {
await sim.start({...defaultOptions, model: m.name,});
const app = new FilecoinApp(sim.getTransport());
const msg = data.op

// Put the app in expert mode
await sim.toggleExpertMode();


const testcase = `${m.prefix.toLowerCase()}-eth-sign-${data.name}`


let eth = new Eth(sim.getTransport())


// eth pubkey used for ETH_PATH: "m/44'/60'/0'/0'/5"
// to verify signature
const EXPECTED_PUBLIC_KEY = '024f1dd50f180bfd546339e75410b127331469837fa618d950f7cfb8be351b0020';

// do not wait here..
const signatureRequest = app.signETHTransaction(ETH_PATH, msg, null);

const signatureRequest = app.signETHTransaction(ETH_PATH, msg.toString('hex'), null);
// Wait until we are not in the main menu
await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot());

Expand Down Expand Up @@ -151,11 +149,11 @@ describe('EthAddress', function () {

console.log(resp)

console.log(resp.publicKey.toString('hex'))
console.log(resp.publicKey.toString())
console.log(resp.address)

expect(resp.publicKey.toString('hex')).toEqual(EXPECTED_ETH_PK);
expect(resp.address.toString('hex')).toEqual(EXPECTED_ETH_ADDRESS);
expect(resp.publicKey.toString()).toEqual(EXPECTED_ETH_PK);
expect(resp.address.toString()).toEqual(EXPECTED_ETH_ADDRESS);

} finally {
await sim.close();
Expand Down
12 changes: 6 additions & 6 deletions tests_zemu/tests/multisig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ describe.each(models)('Multisig', function (m) {

const pkResponse = await app.getAddressAndPubKey(PATH_TESTNET);
console.log(pkResponse);
expect(pkResponse.return_code).toEqual(0x9000);
expect(pkResponse.error_message).toEqual("No errors");
expect(pkResponse.returnCode).toEqual(0x9000);
expect(pkResponse.errorMessage).toEqual("No errors");

// do not wait here so we can get snapshots and interact with the app
const signatureRequest = app.sign(PATH_TESTNET, txBlob);
Expand All @@ -72,13 +72,13 @@ describe.each(models)('Multisig', function (m) {
let resp = await signatureRequest;
console.log(resp, m.name, name)

expect(resp.return_code).toEqual(0x9000);
expect(resp.error_message).toEqual("No errors");
expect(resp.returnCode).toEqual(0x9000);
expect(resp.errorMessage).toEqual("No errors");

// Verify signature
const pk = Uint8Array.from(pkResponse.compressed_pk)
const pk = Uint8Array.from(pkResponse.compressedPk?? [])
const digest = getDigest(txBlob);
const signature = secp256k1.signatureImport(Uint8Array.from(resp.signature_der));
const signature = secp256k1.signatureImport(Uint8Array.from(resp.signatureDER ?? []));
const signatureOk = secp256k1.ecdsaVerify(signature, digest, pk);
expect(signatureOk).toEqual(true);
} finally {
Expand Down
Loading
Loading