Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Skeleton issue #3

Closed
68 of 70 tasks
dj8yfo opened this issue Jan 18, 2024 · 2 comments
Closed
68 of 70 tasks

Skeleton issue #3

dj8yfo opened this issue Jan 18, 2024 · 2 comments

Comments

@dj8yfo
Copy link
Owner

dj8yfo commented Jan 18, 2024

Various

Existing functionality

advantages as compared to app-near

comparison of details shown with app-near

  • CreateAccountAction
    • no change
  • DeleteAccountAction
    • cargo run --example sign_delete_account_{short,long}
      • Beneficiary ID action field not displayed in app-near
  • DeleteKeyAction
    • cargo run --example sign_delete_key_{ed25519/secp256k1}
      • Public Key action field not displayed in app-near
  • StakeAction
    • cargo run --example sign_stake
      • Stake and Public Key fields of action not displayed in app-near
  • TransferAction
    • cargo run --example sign_transfer
      • no change
  • AddKeyAction
    • cargo run --example sign_add_key_fullaccess
      • Public Key field and access_key.Nonce field of action is not displayed in app-near
    • cargo run --example sign_add_key_functioncall
      • app-near displays this case identical to Full Access one (Public Key field and access_key.Nonce field of action is not displayed, no details show on Function Call Permission)
  • DeployContractAction
    • cargo run --example sign_deploy_contract
      • code field of action not displayed in app-near; sha256 of code field is displayed in app-near-rs
  • FunctionCallAction
    • gas field of action isn't displayed in app-near (string args argument)
    • gas field of action isn't diplayed, binary args argument displayed as blank in app-near

New functionality

nep-413 message protocol

The protocol is similar to regular transaction signing, which has 20 bytes of 5-component BIP32Path followed by borsh serialization of transaction transferred over multiple apdu messages. There're two differences:

  1. instruction byte in all of apdu headers is changed from 2 -> 7
const INS_SIGN_TRANSACTION: u8 = 2; // Instruction code to sign a transaction on the Ledger
const INS_SIGN_NEP413_MESSAGE: u8 = 7; // Instruction code to sign a nep-413 message with Ledger
  1. 20 bytes of 5-component BIP32Path are followed by borsh serialization of NEP413Payload:
pub struct NEP413Payload {
    pub messsage: String,
    pub nonce: [u8; 32],
    pub recipient: String,
    pub callback_url: Option<String>,
}

Sample code which forms and sends such a message is targeted by this link.

nep-366 message protocol

The protocol is similar to regular transaction signing, which has 20 bytes of 5-component BIP32Path followed by borsh serialization of transaction transferred over multiple apdu messages. There're two differences:

  1. instruction byte in all of apdu headers is changed from 2 -> 8
const INS_SIGN_TRANSACTION: u8 = 2; // Instruction code to sign a transaction on the Ledger
const INS_SIGN_NEP366_DELEGATE_ACTION: u8 = 8; // Instruction code to sign a nep-366 delegate action with Ledger
  1. 20 bytes of 5-component BIP32Path are followed by borsh serialization of DelegateAction:
pub struct DelegateAction {
    /// Signer of the delegated actions
    pub sender_id: AccountId,
    /// Receiver of the delegated actions.
    pub receiver_id: AccountId,
    /// List of actions to be executed.
    ///
    /// With the meta transactions MVP defined in NEP-366, nested
    /// DelegateActions are not allowed. A separate type is used to enforce it.
    pub actions: Vec<NonDelegateAction>,
    /// Nonce to ensure that the same delegate action is not sent twice by a
    /// relayer and should match for given account's `public_key`.
    /// After this action is processed it will increment.
    pub nonce: Nonce,
    /// The maximal height of the block in the blockchain below which the given DelegateAction is valid.
    pub max_block_height: BlockHeight,
    /// Public key used to sign this delegated action.
    pub public_key: PublicKey,
}
pub type Nonce = u64;
pub type BlockHeight = u64;

Sample code which forms and sends such a message is targeted by this link.

CI/Ragger tests

details

Encountered issues:

These LedgerHQ/ledger-device-rust-sdk#124 and LedgerHQ/ledger-device-rust-sdk#146 haven't been resolved yet, but have been worked around by #47

@frol
Copy link

frol commented Feb 4, 2024

question: should public_key, nonce, block_hash fields of transaction prefix be displayed as well

Nah, it is useless for users. Public key has to match the private key on Ledger, so you may validate this and it would be better than asking user to do that.

question: can AccountId be Secp256K1PublicKey representation as hex string 128 bytes long?

Nope, but before you asked, I have never really put a thought that NEAR doesn't support implicit accounts with keys different than ed25519. Which is a bit odd, but it makes things simpler

@dj8yfo
Copy link
Owner Author

dj8yfo commented Mar 26, 2024

mentioned in README

@dj8yfo dj8yfo closed this as completed Mar 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants