Code Monkey home page Code Monkey logo

near-ledger-rs's Introduction

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")

near-ledger-rs's People

Contributors

khorolets avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.