Skip to content

Transport library to integrate with NEAR Ledger app

License

Notifications You must be signed in to change notification settings

Norfolks/near-ledger-rs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

near-ledger-rs

Rust

It is NEAR <-> Ledger transport

Provides a set of commands that can be executed to communicate with NEAR App installed on Ledger device:

  • Read PublicKey from Ledger device by HD Path
  • Sign a Transaction

Examples

Get PublicKey from Ledger

use near_ledger::get_public_key;
use slip10::BIP32Path;

let hd_path = BIP32Path::from_str("44'/397'/0'/0'/1'").unwrap();
let public_key = match get_public_key(hd_path)
   .await
   .map_err(|near_ledger_error| {
       panic!(
           "An error occurred while getting PublicKey from Ledger device: {:?}",
            near_ledger_error,
       )
   })?;

Trick

To convert the answer into near_crypto::PublicKey do:

near_crypto::PublicKey::ED25519(
    near_crypto::ED25519PublicKey::from(
        public_key.to_bytes(),
    )
)

How to sign a transaction

use near_ledger::sign_transaction;
use borsh::BorshSerializer;
use slip10::BIP32Path;
asyn fn main() {
let hd_path = BIP32Path::from_str("44'/397'/0'/0'/1'").unwrap();
let borsh_transaction = near_unsigned_transaction.try_to_vec().unwrap();
let signature = match sign_transaction(borsh_transaction, hd_path)
   .await
   .map_err(|near_ledger_error| {
       panic!(
           "An error occurred while getting PublicKey from Ledger device: {:?}",
            near_ledger_error,
       )
   })?;

Trick

To convert the answer into near_crypto::Signature do:

near_crypto::Signature::from_parts(near_crypto::KeyType::ED25519, &signature)
    .expect("Signature is not expected to fail on deserialization")

About

Transport library to integrate with NEAR Ledger app

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%