Coder Social home page Coder Social logo

ledgerhq / app-zcash Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ledgerhq/app-bitcoin

0.0 1.0 0.0 1.69 MB

Bitcoin wallet application for Ledger Blue and Nano S

License: Apache License 2.0

Shell 0.06% JavaScript 6.15% Python 20.40% C 72.12% Makefile 1.26%

app-zcash's Introduction

ledger-app-btc

Bitcoin wallet application for Ledger Nano S and Nano X, up to version 1.6.5.

This is currently only used in order to support and maintain altcoins cloned from Bitcoin. The last stable version of the app as it was used for Bitcoin is kept in the branch legacy-1.6.6 for future reference.

Versions starting from 2.0.0 are at https://github.com/LedgerHQ/app-bitcoin-new.

Ledger Blue is not maintained anymore, but the app can still be compiled for this target using the branch blue-final-release.

This follows the beta specification at https://ledgerhq.github.io/btchip-doc/bitcoin-technical-beta.html - with the regular set of APDUs for standard wallet operations enabled.

To compile and load it on a device, have a look here: https://developers.ledger.com/docs/nano-app/load/

Can be tested quickly tested with the Python API at https://github.com/LedgerHQ/btchip-python and Electrum (force noPin = True in getClient in plugins/ledger/ledger.py)

Usage

Include the necessary headers (copied from the js/ directory) in your web page

<head>
  <script src="thirdparty/q.js"></script>
  <script src="thirdparty/async.min.js"></script>
  <script src="thirdparty/u2f-api.js"></script>
  <script src="dist/ledger-btc.js"></script>
</head>

Create a communication object

var dongle = new LedgerBtc(20);

For each UTXO included in your transaction, create a transaction object from the raw serialized version of the transaction used in this UTXO

var tx1 = dongle.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000");

var tx2 = dongle.splitTransaction("...")

To sign a transaction involving standard (P2PKH) inputs, call createPaymentTransactionNew_async with the folowing parameters

  • inputs is an array of [ transaction, output_index, optional redeem script, optional sequence ] where
    • transaction is the previously computed transaction object for this UTXO
    • output_index is the output in the transaction used as input for this UTXO (counting from 0)
    • redeem script is the optional redeem script to use when consuming a Segregated Witness input
    • sequence is the sequence number to use for this input (when using RBF), or non present
  • associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
  • changePath is an optional BIP 32 path pointing to the path to the public key used to compute the change address
  • outputScript is the hexadecimal serialized outputs of the transaction to sign
  • lockTime is the optional lockTime of the transaction to sign, or default (0)
  • sigHashType is the hash type of the transaction to sign, or default (all)

This method returns the signed transaction ready to be broadcast

dongle.createPaymentTransactionNew_async(
   [ [tx, 1] ],
   ["0'/0/0"],
   undefined,
   "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac").then(
     function(result) { console.log(result);}).fail(
     function(error) { console.log(error); });
);

To obtain the signature of multisignature (P2SH) inputs, call signP2SHTransaction_async with the folowing parameters

  • inputs is an array of [ transaction, output_index, redeem script, optional sequence ] where
    • transaction is the previously computed transaction object for this UTXO
    • output_index is the output in the transaction used as input for this UTXO (counting from 0)
    • redeem script is the mandatory redeem script associated to the current P2SH input
    • sequence is the sequence number to use for this input (when using RBF), or non present
  • associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
  • outputScript is the hexadecimal serialized outputs of the transaction to sign
  • lockTime is the optional lockTime of the transaction to sign, or default (0)
  • sigHashType is the hash type of the transaction to sign, or default (all)

This method returns the signed transaction ready to be broadcast

dongle.signP2SHTransaction_async(
   [ [tx, 1, "52210289b4a3ad52a919abd2bdd6920d8a6879b1e788c38aa76f0440a6f32a9f1996d02103a3393b1439d1693b063482c04bd40142db97bdf139eedd1b51ffb7070a37eac321030b9a409a1e476b0d5d17b804fcdb81cf30f9b99c6f3ae1178206e08bc500639853ae"] ],
   ["0'/0/0"],
   "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac").then(
     function(result) { console.log(result);}).fail(
     function(error) { console.log(error); });
);

app-zcash's People

Contributors

a-bezrukov avatar ablagoev avatar alexitc avatar bigspider avatar btchip avatar clementperon avatar fabricedautriat avatar gbillou avatar greenknot avatar grydz avatar jibeee avatar josephnicholas avatar khalilbellakrid avatar oto-ledger avatar pa-t avatar philippebonnaz avatar pscott avatar raulo avatar rodendron-xrhodium avatar saltari avatar samadsajanlal avatar scotty0448 avatar sgliner-ledger avatar tamtamhero avatar teams2ua avatar tjulien-ledger avatar

Watchers

 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.