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

ADR14 M1 update #627

Merged
merged 11 commits into from May 4, 2023
Merged

ADR14 M1 update #627

merged 11 commits into from May 4, 2023

Conversation

chcmedeiros
Copy link
Contributor

Support Milestone 1 of ADR14 implementation:

  • Rename old methods;
  • Add new methods.

package.json Outdated
@@ -1,6 +1,6 @@
{
"name": "@oasisprotocol/ledger",
"version": "0.2.3",
"version": "0.2.4",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep consistency with the new methods, getAddressAndPubKey was renamed to getAddressAndPubKey_ed25519 (new method is called getAddressAndPubKey_secp256k1)
To respect SemVer, major field should be bumped. However, if you don't want to make breaking changes in the API, it's possible to keep the old names.
I think that this should be decided by Oasis team 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! I will bump the major so that we have a version that respects SemVer, since the changes in this PR ask for that. Then Oasis Team can decide to merge this as is or we change the old method names.

src/helperV1.js Outdated Show resolved Hide resolved
@matevz
Copy link
Member

matevz commented Jan 16, 2023

I'm getting bunch of linter errors when running yarn serve. Can you check it out?

@matevz
Copy link
Member

matevz commented Jan 16, 2023

I'm getting bunch of linter errors when running yarn serve. Can you check it out?

Nevermind, it seems I had some leftovers from the old repo.

Copy link
Member

@matevz matevz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package.json Show resolved Hide resolved
@chcmedeiros
Copy link
Contributor Author

@matevz I have fixed the old tests that were not correct and added tests coverage for the new methods. Also tested it using a NanoS with the test mnemonic).
Regarding the UI (.vue) that example has some time, and we have deprecated it months ago.

@chcmedeiros chcmedeiros requested review from matevz and ftheirs and removed request for pro-wh, matevz and ftheirs January 17, 2023 15:22

expect(resp.return_code).toEqual(0x9000);
expect(resp.error_message).toEqual("No errors");
expect(resp.hex_address).toEqual("7dac3ca6b185b7778a7027a52c0cc3940d2e1ca0");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The standard BIP44 address for testing mnemonic equip will roof matter pink blind book anxiety banner elbow sun young is 95e5e3C1BDD92cd4A0c14c62480DB5867946281D. Where does discrepancy come from?

const transport = await TransportNodeHid.create(1000);
const app = new OasisApp(transport);
// Derivation path. First 3 items are automatically hardened!
const path = [44, 60, 0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also cover the case for the 2nd key [44', 60', 0', 0, 1]. The helper function in helperV1.js will probably need to be updated or a new one added, but please don't break backward compatibility.

@matevz
Copy link
Member

matevz commented Jan 23, 2023

I'm getting compilation error after applying ac681ad. Can you take a look?

$ yarn build
yarn run v1.22.5
warning ../package.json: No license field
$ babel src --out-dir dist && yarn build-types
Successfully compiled 3 files with Babel (610ms).
warning ../package.json: No license field
$ tsc -p ./tsconfig.json
src/types.ts:39:30 - error TS2345: Argument of type 'Buffer | { return_code: number; error_message: string; } | { pk: Buffer; hex_address: string; return_code: any; error_message: string; }' is not assignable to parameter of type 'Response<Buffer | { pk: Buffer; hex_address: string; return_code: any; error_message: string; }>'.
  Type 'Buffer' is not assignable to type 'Response<Buffer | { pk: Buffer; hex_address: string; return_code: any; error_message: string; }>'.
    Type 'Buffer' is not assignable to type 'Buffer & { return_code: number; error_message: string; }'.
      Type 'Buffer' is missing the following properties from type '{ return_code: number; error_message: string; }': return_code, error_message

39   console.log(successOrThrow(await app.getAddressAndPubKey_secp256k1([44])).hex_address.trim());
                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/types.ts:39:77 - error TS2339: Property 'hex_address' does not exist on type 'Buffer | { pk: Buffer; hex_address: string; return_code: any; error_message: string; }'.
  Property 'hex_address' does not exist on type 'Buffer'.

39   console.log(successOrThrow(await app.getAddressAndPubKey_secp256k1([44])).hex_address.trim());
                                                                               ~~~~~~~~~~~

src/types.ts:40:30 - error TS2345: Argument of type 'Buffer | { return_code: number; error_message: string; } | { pk: Buffer; hex_address: string; return_code: any; error_message: string; }' is not assignable to parameter of type 'Response<Buffer | { pk: Buffer; hex_address: string; return_code: any; error_message: string; }>'.

40   console.log(successOrThrow(await app.showAddressAndPubKey_secp256k1([44])).hex_address.trim());
                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/types.ts:40:78 - error TS2339: Property 'hex_address' does not exist on type 'Buffer | { pk: Buffer; hex_address: string; return_code: any; error_message: string; }'.
  Property 'hex_address' does not exist on type 'Buffer'.

40   console.log(successOrThrow(await app.showAddressAndPubKey_secp256k1([44])).hex_address.trim());
                                                                                ~~~~~~~~~~~


Found 4 errors in the same file, starting at: src/types.ts:39

Copy link
Member

@matevz matevz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, thanks.

@pro-wh
Copy link
Contributor

pro-wh commented Apr 17, 2023

@matevz are we waiting for anything before merging this?

@kostko
Copy link
Member

kostko commented Apr 18, 2023

Looks like the tests did not run for some reason.

Copy link
Member

@matevz matevz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting an error when running yarn build-example. @chcmedeiros Can you take a look and then merge this so we can add ParaTime support for Ledger to our javascript wallets as well.

src/index.js Outdated
const returnCode = errorCodeData[0] * 256 + errorCodeData[1];

const pk = Buffer.from(response.slice(0, 33));
const hex_address = Buffer.from(response.slice(33, 73)).toString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const hex_address = Buffer.from(response.slice(33, 73)).toString();
const hexAddress = Buffer.from(response.slice(33, 73)).toString();

src/index.js Outdated

return {
pk,
hex_address,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
hex_address,
hex_address: hexAddress,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I will take a look

@chcmedeiros
Copy link
Contributor Author

I'm getting an error when running yarn build-example. @chcmedeiros Can you take a look and then merge this so we can add ParaTime support for Ledger to our javascript wallets as well.

@matevz Regarding the vue-example that example has some time, and we have deprecated it months ago. If it's ok with you and since we have test coverage for the package with the real device we would remove that vue-example folder, avoiding more errors.

@pro-wh
Copy link
Contributor

pro-wh commented Apr 26, 2023

sure, sounds good. would reduce the dev dependency tree by a lot too

@chcmedeiros
Copy link
Contributor Author

Vue example was removed. @matevz @pro-wh If you want to take a last look at it

Copy link
Member

@matevz matevz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chcmedeiros yarn test:integration freezes on the second test for me using hardware ledger with the latest firmware you sent to me (UI fixes). Can you check it out? Also, what would be the easiest way to do Ledger tests inside CI?

@chcmedeiros
Copy link
Contributor Author

chcmedeiros commented May 2, 2023

Hey @matevz The M3-maintenance branch now has a version that is working here on the ledger-js, if you want to test. Regarding the ledger tests, I think the procedure would be to compile the app from the repository to get the .elf and then use our tool zemu (device emulator) combined with this repo to run the tests. This should require some more work, so maybe we can merge this, discuss these tests implementation and possibly do it in the future PR for SR25519.

@matevz
Copy link
Member

matevz commented May 4, 2023

Hey @matevz The M3-maintenance branch now has a version that is working here on the ledger-js, if you want to test. Regarding the ledger tests, I think the procedure would be to compile the app from the repository to get the .elf and then use our tool zemu (device emulator) combined with this repo to run the tests. This should require some more work, so maybe we can merge this, discuss these tests implementation and possibly do it in the future PR for SR25519.

I can confirm that integration tests now pass with Zondax/ledger-oasis@9b9c85a . Feel free to merge this PR.

@chcmedeiros
Copy link
Contributor Author

@matevz I am not able to merge, probably don't haver permission to do so.

@matevz matevz merged commit 9829c54 into oasisprotocol:master May 4, 2023
1 check passed
@lukaw3d lukaw3d mentioned this pull request Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants