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

Ledger signer 211 #1246

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

PhilippeR26
Copy link
Collaborator

@PhilippeR26 PhilippeR26 commented Oct 11, 2024

Motivation and Resolution

Ledger has released a new version 2.1.1 of the Starknet APP.
It includes improvements, including a comprehensive display of the details of V1 & V3 transactions.
20241011_100145

Starknet.js is now able to use APP v1.1.1 & v2.1.1.

Usage related changes

Important

No breaking changes for code using Ledger APP v1.1.1 (just no comprehensive display, only blind signatures)

  • For users still using v1.1.1 :
    No change of the code :
const myLedgerSigner = new LedgerSigner(myLedgerTransport, 0);

LedgerSigner and LedgerSigner111 classes are equivalent.

  • For new users, using v2.1.1 to create a new account :
const myLedgerSigner = new LedgerSigner211(myLedgerTransport, 0);

They can also use the v1.1.1 signer ; they will only not have access to the display of transaction details.

  • For new users, using v1.1.1 to create a new account that will be natively compatible with v2.1.1 :
const myLedgerSigner = new LedgerSigner111(myLedgerTransport, 0, undefined, getLedgerPathBuffer211);
  • For users that have created an account with V1.1.1, and are now using v2.1.1 :
const myLedgerSigner = new LedgerSigner211(myLedgerTransport, 0, getLedgerPathBuffer111);

Development related changes

LedgerSigner and getLedgerPathBuffer are still there, and are related to v1.1.1 APP.
They are now also named LedgerSigner111 and getLedgerPathBuffer111.

LedgerSigner211 and getLedgerPathBuffer211 have been created to handle v2.1.1.

As several functions are common for both signers, the LedgerSigner211 is an extension of the LedgerSigner111.

Some maths included in hashFeeField (utils/hash/transactionHash/v3.ts) are necessary, and have been isolated in exportable functions.

The new signer has been tested successfully in Node ( https://github.com/PhilippeR26/starknet.js-workshop-typescript/blob/main/src/scripts/ledgerNano/6.testLedgerAccount211.ts ) and in a demo DAPP ( https://github.com/PhilippeR26/Starknet-Ledger-Wallet )

Checklist:

  • Performed a self-review of the code
  • Rebased to the last commit of the target branch (or merged it into my branch)
  • Documented the changes in code (API docs will be generated automatically)
  • Updated the tests
  • All tests are passing

@PhilippeR26 PhilippeR26 marked this pull request as ready for review October 11, 2024 10:24
txDetails: V2InvocationsSignerDetails,
calls: Call[]
): Promise<{ hash: bigint; signature: Signature }> {
// APDU 0 for path
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is APDU ? :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's a Ledger wording, about a batch of bytes exchanged with a Nano.

Copy link
Collaborator

@tabaktoni tabaktoni left a comment

Choose a reason for hiding this comment

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

There are a couple of nitpicks but in general LGTM!

We would need to refactor this soon when v1 tx gets deprecated with RPC 0.8

@@ -354,12 +355,25 @@ describe('Ethereum signer', () => {
describe('Ledger Signer', () => {
// signature of Ledger can't be tested automatically.
Copy link
Collaborator

Choose a reason for hiding this comment

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

@@ -82,3 +82,7 @@ export const SNIP9_V1_INTERFACE_ID =
'0x68cfd18b92d1907b8ba3cc324900277f5a3622099431ea85dd8089255e4181';
export const SNIP9_V2_INTERFACE_ID =
'0x1d1144bb2138366ff28d8e9ab57456b1d332ac42196230c3a602003c89872';

// Ledger signer
export const HARDENING_BYTE = Number('0x80');
Copy link
Collaborator

Choose a reason for hiding this comment

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

nitpick, Can we store this as a static constant

Suggested change
export const HARDENING_BYTE = Number('0x80');
// 0x80
export const HARDENING_BYTE = 128;


// Ledger signer
export const HARDENING_BYTE = Number('0x80');
export const HARDENING_4BYTES = BigInt('0x80000000');
Copy link
Collaborator

Choose a reason for hiding this comment

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

nitpick , Same

Suggested change
export const HARDENING_4BYTES = BigInt('0x80000000');
// 0x80000000
export const HARDENING_4BYTES = 2147483648n

@@ -24,17 +24,33 @@ export function hashDAMode(nonceDAMode: BigNumberish, feeDAMode: BigNumberish) {
return (BigInt(nonceDAMode) << DATA_AVAILABILITY_MODE_BITS) + BigInt(feeDAMode);
}

export function hashFeeField(tip: BigNumberish, bounds: ResourceBounds) {
const L1Bound =
export function encodeResourceBoundsL1(bounds: ResourceBounds): bigint {
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe add desc, and note what this encoding is for

@PhilippeR26
Copy link
Collaborator Author

Ledger informed me that they are preparing a new version, including a human readable account deployment .
So, hold on for this PR. I will update it once the new Ledger APP available, including at the same time your comments.

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.

3 participants