@ledgerhq/hw-app-btc
Advanced tools
Comparing version 4.37.0-beta.2b8718d2 to 4.37.0
{ | ||
"name": "@ledgerhq/hw-app-btc", | ||
"version": "4.37.0-beta.2b8718d2", | ||
"version": "4.37.0", | ||
"description": "Ledger Hardware Wallet Bitcoin Application API", | ||
@@ -28,7 +28,7 @@ "keywords": [ | ||
"dependencies": { | ||
"@ledgerhq/hw-transport": "^4.37.0-beta.2b8718d2", | ||
"@ledgerhq/hw-transport": "^4.37.0", | ||
"create-hash": "^1.1.3" | ||
}, | ||
"devDependencies": { | ||
"flow-bin": "^0.78.0", | ||
"flow-bin": "^0.92.1", | ||
"flow-typed": "^2.5.1" | ||
@@ -40,4 +40,6 @@ }, | ||
"build": "bash ../../script/build.sh", | ||
"watch": "bash ../../script/watch.sh" | ||
} | ||
"watch": "bash ../../script/watch.sh", | ||
"doc": "bash ../../script/doc.sh" | ||
}, | ||
"gitHead": "8b31eec9c71f2b8ec4d1db47c2fb7ae20f188de2" | ||
} |
251
README.md
<img src="https://user-images.githubusercontent.com/211411/34776833-6f1ef4da-f618-11e7-8b13-f0697901d6a8.png" height="100" /> | ||
[Github](https://github.com/LedgerHQ/ledgerjs/), | ||
[API Doc](http://ledgerhq.github.io/ledgerjs/), | ||
[Ledger Devs Slack](https://ledger-dev.slack.com/) | ||
## @ledgerhq/hw-app-btc | ||
Library for Ledger Hardware Wallets. | ||
Ledger Hardware Wallet BTC JavaScript bindings. Also supports many altcoins. | ||
[Github](https://github.com/LedgerHQ/ledgerjs/), | ||
[API Doc](http://ledgerhq.github.io/ledgerjs/), | ||
[Ledger Devs Slack](https://ledger-dev.slack.com/) | ||
## API | ||
<!-- Generated by documentation.js. Update this documentation by updating the source code. --> | ||
#### Table of Contents | ||
- [Btc](#btc) | ||
- [Parameters](#parameters) | ||
- [Examples](#examples) | ||
- [getWalletPublicKey](#getwalletpublickey) | ||
- [Parameters](#parameters-1) | ||
- [Examples](#examples-1) | ||
- [signMessageNew](#signmessagenew) | ||
- [Parameters](#parameters-2) | ||
- [Examples](#examples-2) | ||
- [createPaymentTransactionNew](#createpaymenttransactionnew) | ||
- [Parameters](#parameters-3) | ||
- [Examples](#examples-3) | ||
- [signP2SHTransaction](#signp2shtransaction) | ||
- [Parameters](#parameters-4) | ||
- [Examples](#examples-4) | ||
- [splitTransaction](#splittransaction) | ||
- [Parameters](#parameters-5) | ||
- [Examples](#examples-5) | ||
- [serializeTransactionOutputs](#serializetransactionoutputs) | ||
- [Parameters](#parameters-6) | ||
- [Examples](#examples-6) | ||
- [serializeTransaction](#serializetransaction) | ||
- [Parameters](#parameters-7) | ||
- [displayTransactionDebug](#displaytransactiondebug) | ||
- [Parameters](#parameters-8) | ||
- [TransactionInput](#transactioninput) | ||
- [Properties](#properties) | ||
- [TransactionOutput](#transactionoutput) | ||
- [Properties](#properties-1) | ||
- [Transaction](#transaction) | ||
- [Properties](#properties-2) | ||
### Btc | ||
Bitcoin API. | ||
#### Parameters | ||
- `transport` **Transport<any>** | ||
- `scrambleKey` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** (optional, default `"BTC"`) | ||
#### Examples | ||
```javascript | ||
import Btc from "@ledgerhq/hw-app-btc"; | ||
const btc = new Btc(transport) | ||
``` | ||
#### getWalletPublicKey | ||
##### Parameters | ||
- `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a BIP 32 path | ||
- `verify` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** (optional, default `false`) | ||
- `segwit` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** use segwit | ||
##### Examples | ||
```javascript | ||
btc.getWalletPublicKey("44'/0'/0'/0").then(o => o.bitcoinAddress) | ||
``` | ||
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{publicKey: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), bitcoinAddress: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), chainCode: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)}>** | ||
#### signMessageNew | ||
You can sign a message according to the Bitcoin Signature format and retrieve v, r, s given the message and the BIP 32 path of the account to sign. | ||
##### Parameters | ||
- `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** | ||
- `messageHex` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** | ||
##### Examples | ||
```javascript | ||
btc.signMessageNew_async("44'/60'/0'/0'/0", Buffer.from("test").toString("hex")).then(function(result) { | ||
var v = result['v'] + 27 + 4; | ||
var signature = Buffer.from(v.toString(16) + result['r'] + result['s'], 'hex').toString('base64'); | ||
console.log("Signature : " + signature); | ||
}).catch(function(ex) {console.log(ex);}); | ||
``` | ||
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{v: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), r: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), s: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)}>** | ||
#### createPaymentTransactionNew | ||
To sign a transaction involving standard (P2PKH) inputs, call createPaymentTransactionNew with the following parameters | ||
##### Parameters | ||
- `inputs` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<\[[Transaction](#transaction), [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?, [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?]>** 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` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** is an array of BIP 32 paths pointing to the path to the private key used for each UTXO | ||
- `changePath` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** is an optional BIP 32 path pointing to the path to the public key used to compute the change address | ||
- `outputScriptHex` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** is the hexadecimal serialized outputs of the transaction to sign | ||
- `lockTime` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** is the optional lockTime of the transaction to sign, or default (0) | ||
- `sigHashType` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** is the hash type of the transaction to sign, or default (all) | ||
- `segwit` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** is an optional boolean indicating wether to use segwit or not | ||
- `initialTimestamp` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** is an optional timestamp of the function call to use for coins that necessitate timestamps only, (not the one that the tx will include) | ||
- `additionals` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** list of additionnal options- "abc" for bch | ||
- "gold" for btg | ||
- "bipxxx" for using BIPxxx | ||
- "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200) | ||
- `expiryHeight` **[Buffer](https://nodejs.org/api/buffer.html)** is an optional Buffer for zec overwinter / sapling Txs | ||
##### Examples | ||
```javascript | ||
btc.createPaymentTransactionNew( | ||
[ [tx1, 1] ], | ||
["0'/0/0"], | ||
undefined, | ||
"01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac" | ||
).then(res => ...); | ||
``` | ||
Returns **any** the signed transaction ready to be broadcast | ||
#### signP2SHTransaction | ||
To obtain the signature of multisignature (P2SH) inputs, call signP2SHTransaction_async with the folowing parameters | ||
##### Parameters | ||
- `inputs` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<\[[Transaction](#transaction), [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?, [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?]>** 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` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** is an array of BIP 32 paths pointing to the path to the private key used for each UTXO | ||
- `outputScriptHex` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** is the hexadecimal serialized outputs of the transaction to sign | ||
- `lockTime` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** is the optional lockTime of the transaction to sign, or default (0) | ||
- `sigHashType` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** is the hash type of the transaction to sign, or default (all) | ||
- `segwit` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** (optional, default `false`) | ||
- `transactionVersion` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** (optional, default `DEFAULT_VERSION`) | ||
##### Examples | ||
```javascript | ||
btc.signP2SHTransaction( | ||
[ [tx, 1, "52210289b4a3ad52a919abd2bdd6920d8a6879b1e788c38aa76f0440a6f32a9f1996d02103a3393b1439d1693b063482c04bd40142db97bdf139eedd1b51ffb7070a37eac321030b9a409a1e476b0d5d17b804fcdb81cf30f9b99c6f3ae1178206e08bc500639853ae"] ], | ||
["0'/0/0"], | ||
"01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac" | ||
).then(result => ...); | ||
``` | ||
Returns **any** the signed transaction ready to be broadcast | ||
#### splitTransaction | ||
For each UTXO included in your transaction, create a transaction object from the raw serialized version of the transaction used in this UTXO. | ||
##### Parameters | ||
- `transactionHex` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** | ||
- `isSegwitSupported` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** (optional, default `false`) | ||
- `hasTimestamp` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** (optional, default `false`) | ||
- `hasExtraData` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** (optional, default `false`) | ||
- `additionals` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** (optional, default `[]`) | ||
##### Examples | ||
```javascript | ||
const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000"); | ||
``` | ||
Returns **[Transaction](#transaction)** | ||
#### serializeTransactionOutputs | ||
##### Parameters | ||
- `$0` **any** | ||
- `$0.outputs` | ||
##### Examples | ||
```javascript | ||
const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000"); | ||
const outputScript = btc.serializeTransactionOutputs(tx1).toString('hex'); | ||
``` | ||
Returns **[Buffer](https://nodejs.org/api/buffer.html)** | ||
#### serializeTransaction | ||
##### Parameters | ||
- `transaction` **[Transaction](#transaction)** | ||
- `skipWitness` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** | ||
- `timestamp` **[Buffer](https://nodejs.org/api/buffer.html)** | ||
- `additionals` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** (optional, default `[]`) | ||
#### displayTransactionDebug | ||
##### Parameters | ||
- `transaction` **[Transaction](#transaction)** | ||
### TransactionInput | ||
Type: {prevout: [Buffer](https://nodejs.org/api/buffer.html), script: [Buffer](https://nodejs.org/api/buffer.html), sequence: [Buffer](https://nodejs.org/api/buffer.html), tree: [Buffer](https://nodejs.org/api/buffer.html)?} | ||
#### Properties | ||
- `prevout` **[Buffer](https://nodejs.org/api/buffer.html)** | ||
- `script` **[Buffer](https://nodejs.org/api/buffer.html)** | ||
- `sequence` **[Buffer](https://nodejs.org/api/buffer.html)** | ||
- `tree` **[Buffer](https://nodejs.org/api/buffer.html)?** | ||
### TransactionOutput | ||
Type: {amount: [Buffer](https://nodejs.org/api/buffer.html), script: [Buffer](https://nodejs.org/api/buffer.html)} | ||
#### Properties | ||
- `amount` **[Buffer](https://nodejs.org/api/buffer.html)** | ||
- `script` **[Buffer](https://nodejs.org/api/buffer.html)** | ||
### Transaction | ||
Type: {version: [Buffer](https://nodejs.org/api/buffer.html), inputs: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[TransactionInput](#transactioninput)>, outputs: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[TransactionOutput](#transactionoutput)>?, locktime: [Buffer](https://nodejs.org/api/buffer.html)?, witness: [Buffer](https://nodejs.org/api/buffer.html)?, timestamp: [Buffer](https://nodejs.org/api/buffer.html)?, nVersionGroupId: [Buffer](https://nodejs.org/api/buffer.html)?, nExpiryHeight: [Buffer](https://nodejs.org/api/buffer.html)?, extraData: [Buffer](https://nodejs.org/api/buffer.html)?} | ||
#### Properties | ||
- `version` **[Buffer](https://nodejs.org/api/buffer.html)** | ||
- `inputs` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[TransactionInput](#transactioninput)>** | ||
- `outputs` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[TransactionOutput](#transactionoutput)>?** | ||
- `locktime` **[Buffer](https://nodejs.org/api/buffer.html)?** | ||
- `witness` **[Buffer](https://nodejs.org/api/buffer.html)?** | ||
- `timestamp` **[Buffer](https://nodejs.org/api/buffer.html)?** | ||
- `nVersionGroupId` **[Buffer](https://nodejs.org/api/buffer.html)?** | ||
- `nExpiryHeight` **[Buffer](https://nodejs.org/api/buffer.html)?** | ||
- `extraData` **[Buffer](https://nodejs.org/api/buffer.html)?** |
@@ -298,4 +298,4 @@ //@flow | ||
: overwinter | ||
? 0x04 | ||
: 0x02 | ||
? 0x04 | ||
: 0x02 | ||
: 0x00; | ||
@@ -760,8 +760,8 @@ return this.transport.send( | ||
: !segwit | ||
? regularOutputs[i].script | ||
: Buffer.concat([ | ||
Buffer.from([OP_DUP, OP_HASH160, HASH_SIZE]), | ||
this.hashPublicKey(publicKeys[i]), | ||
Buffer.from([OP_EQUALVERIFY, OP_CHECKSIG]) | ||
]); | ||
? regularOutputs[i].script | ||
: Buffer.concat([ | ||
Buffer.from([OP_DUP, OP_HASH160, HASH_SIZE]), | ||
this.hashPublicKey(publicKeys[i]), | ||
Buffer.from([OP_EQUALVERIFY, OP_CHECKSIG]) | ||
]); | ||
let pseudoTX = Object.assign({}, targetTransaction); | ||
@@ -768,0 +768,0 @@ let pseudoTrustedInputs = useBip143 |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
262661
12
0
253