@ledgerhq/hw-app-btc
Advanced tools
Comparing version 10.2.1 to 10.2.2-next.0
# @ledgerhq/hw-app-btc | ||
## 10.2.2-next.0 | ||
### Patch Changes | ||
- [#6105](https://github.com/LedgerHQ/ledger-live/pull/6105) [`6d40673`](https://github.com/LedgerHQ/ledger-live/commit/6d4067382b55827b00806a1b71ac0b249563d90f) Thanks [@hzheng-ledger](https://github.com/hzheng-ledger)! - update hw-app-btc doc | ||
- Updated dependencies []: | ||
- @ledgerhq/hw-transport@6.30.4-next.0 | ||
## 10.2.1 | ||
@@ -4,0 +13,0 @@ |
@@ -0,1 +1,10 @@ | ||
/** | ||
* @file bip32.ts | ||
* @description BIP32 Path Handling for Bitcoin Wallets | ||
* | ||
* This file provides utility functions to handle BIP32 paths, | ||
* which are commonly used in hierarchical deterministic (HD) wallets. | ||
* It includes functions to convert BIP32 paths to and from different formats, | ||
* extract components from extended public keys (xpubs), and manipulate path elements. | ||
*/ | ||
/// <reference types="node" /> | ||
@@ -2,0 +11,0 @@ export declare function pathElementsToBuffer(paths: number[]): Buffer; |
@@ -0,1 +1,10 @@ | ||
/** | ||
* @file bip32.ts | ||
* @description BIP32 Path Handling for Bitcoin Wallets | ||
* | ||
* This file provides utility functions to handle BIP32 paths, | ||
* which are commonly used in hierarchical deterministic (HD) wallets. | ||
* It includes functions to convert BIP32 paths to and from different formats, | ||
* extract components from extended public keys (xpubs), and manipulate path elements. | ||
*/ | ||
import bippath from "bip32-path"; | ||
@@ -2,0 +11,0 @@ import bs58check from "bs58check"; |
@@ -11,4 +11,7 @@ /// <reference types="node" /> | ||
/** | ||
* Bitcoin API. | ||
* | ||
* @class Btc | ||
* @description Bitcoin API. | ||
* @param transport The transport layer used for communication. | ||
* @param scrambleKey This parameter is deprecated and no longer needed. | ||
* @param currency The currency to use, defaults to "bitcoin". | ||
* @example | ||
@@ -29,4 +32,6 @@ * import Btc from "@ledgerhq/hw-app-btc"; | ||
* @param arg derivation parameter | ||
* - path: a BIP 32 path of the account level. e.g. `84'/0'/0'` | ||
* - xpubVersion: the XPUBVersion of the coin used. (use @ledgerhq/currencies if needed) | ||
* - path: a BIP 32 path of the account level. (e.g. The derivation path `84'/0'/0'` | ||
* follows the `purpose' / coin_type' / account'` standard, with purpose=84, coin_type=0, account=0) | ||
* - xpubVersion: the XPUBVersion of the coin used. (refer to ledgerjs/packages/cryptoassets/src/currencies.ts | ||
* for the XPUBVersion value if needed) | ||
* @returns XPUB of the account | ||
@@ -39,6 +44,6 @@ */ | ||
/** | ||
* @param path a BIP 32 path | ||
* @param path a BIP 32 path (i.e. the `purpose’ / coin_type’ / account’ / change / address_index` standard) | ||
* @param options an object with optional these fields: | ||
* | ||
* - verify (boolean) will ask user to confirm the address on the device | ||
* - verify (boolean) whether ask user to confirm the address on the device | ||
* | ||
@@ -55,2 +60,4 @@ * - format ("legacy" | "p2sh" | "bech32" | "bech32m" | "cashaddr") to use different bitcoin address formatter. | ||
* | ||
* - bech32m format with 86' paths | ||
* | ||
* - cashaddr in case of Bitcoin Cash | ||
@@ -105,2 +112,4 @@ * | ||
* - "gold" for btg | ||
* - "decred" for decred | ||
* - "zcash" for zcash | ||
* - "bipxxx" for using BIPxxx | ||
@@ -141,2 +150,8 @@ * - "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200) | ||
* For each UTXO included in your transaction, create a transaction object from the raw serialized version of the transaction used in this UTXO. | ||
* @param transactionHex a raw hexadecimal serialized transaction | ||
* @param isSegwitSupported is a boolean indicating if the segwit is supported | ||
* @param hasTimestamp is a boolean (peercoin includes timestamp in their transactions, others don't) | ||
* @param hasExtraData is a boolean (komodo, zencash and zcash include extraData in their transactions, others don't) | ||
* @param additionals list of additionnal options | ||
* @return the transaction object deserialized from the raw hexadecimal transaction | ||
* @example | ||
@@ -147,3 +162,4 @@ const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000"); | ||
/** | ||
@example | ||
* Serialize a transaction's outputs to hexadecimal | ||
* @example | ||
const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000"); | ||
@@ -153,3 +169,11 @@ const outputScript = btc.serializeTransactionOutputs(tx1).toString('hex'); | ||
serializeTransactionOutputs(t: Transaction): Buffer; | ||
/** | ||
* Trusted input is the hash of a UTXO that needs to be signed | ||
* For Legacy transactions, the app has some APDUs flows that do the amount check for an UTXO, | ||
* by parsing the transaction that created this UTXO | ||
*/ | ||
getTrustedInput(indexLookup: number, transaction: Transaction, additionals?: Array<string>): Promise<string>; | ||
/** | ||
* Trusted input is the hash of a UTXO that needs to be signed. BIP143 is used for Segwit inputs. | ||
*/ | ||
getTrustedInputBIP143(indexLookup: number, transaction: Transaction, additionals?: Array<string>): string; | ||
@@ -156,0 +180,0 @@ changeImplIfNecessary(): Promise<BtcOld | BtcNew>; |
@@ -21,4 +21,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
/** | ||
* Bitcoin API. | ||
* | ||
* @class Btc | ||
* @description Bitcoin API. | ||
* @param transport The transport layer used for communication. | ||
* @param scrambleKey This parameter is deprecated and no longer needed. | ||
* @param currency The currency to use, defaults to "bitcoin". | ||
* @example | ||
@@ -56,4 +59,6 @@ * import Btc from "@ledgerhq/hw-app-btc"; | ||
* @param arg derivation parameter | ||
* - path: a BIP 32 path of the account level. e.g. `84'/0'/0'` | ||
* - xpubVersion: the XPUBVersion of the coin used. (use @ledgerhq/currencies if needed) | ||
* - path: a BIP 32 path of the account level. (e.g. The derivation path `84'/0'/0'` | ||
* follows the `purpose' / coin_type' / account'` standard, with purpose=84, coin_type=0, account=0) | ||
* - xpubVersion: the XPUBVersion of the coin used. (refer to ledgerjs/packages/cryptoassets/src/currencies.ts | ||
* for the XPUBVersion value if needed) | ||
* @returns XPUB of the account | ||
@@ -67,6 +72,6 @@ */ | ||
/** | ||
* @param path a BIP 32 path | ||
* @param path a BIP 32 path (i.e. the `purpose’ / coin_type’ / account’ / change / address_index` standard) | ||
* @param options an object with optional these fields: | ||
* | ||
* - verify (boolean) will ask user to confirm the address on the device | ||
* - verify (boolean) whether ask user to confirm the address on the device | ||
* | ||
@@ -83,2 +88,4 @@ * - format ("legacy" | "p2sh" | "bech32" | "bech32m" | "cashaddr") to use different bitcoin address formatter. | ||
* | ||
* - bech32m format with 86' paths | ||
* | ||
* - cashaddr in case of Bitcoin Cash | ||
@@ -145,2 +152,4 @@ * | ||
* - "gold" for btg | ||
* - "decred" for decred | ||
* - "zcash" for zcash | ||
* - "bipxxx" for using BIPxxx | ||
@@ -190,2 +199,8 @@ * - "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200) | ||
* For each UTXO included in your transaction, create a transaction object from the raw serialized version of the transaction used in this UTXO. | ||
* @param transactionHex a raw hexadecimal serialized transaction | ||
* @param isSegwitSupported is a boolean indicating if the segwit is supported | ||
* @param hasTimestamp is a boolean (peercoin includes timestamp in their transactions, others don't) | ||
* @param hasExtraData is a boolean (komodo, zencash and zcash include extraData in their transactions, others don't) | ||
* @param additionals list of additionnal options | ||
* @return the transaction object deserialized from the raw hexadecimal transaction | ||
* @example | ||
@@ -198,3 +213,4 @@ const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000"); | ||
/** | ||
@example | ||
* Serialize a transaction's outputs to hexadecimal | ||
* @example | ||
const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000"); | ||
@@ -206,5 +222,13 @@ const outputScript = btc.serializeTransactionOutputs(tx1).toString('hex'); | ||
} | ||
/** | ||
* Trusted input is the hash of a UTXO that needs to be signed | ||
* For Legacy transactions, the app has some APDUs flows that do the amount check for an UTXO, | ||
* by parsing the transaction that created this UTXO | ||
*/ | ||
getTrustedInput(indexLookup, transaction, additionals = []) { | ||
return getTrustedInput(this._transport, indexLookup, transaction, additionals); | ||
} | ||
/** | ||
* Trusted input is the hash of a UTXO that needs to be signed. BIP143 is used for Segwit inputs. | ||
*/ | ||
getTrustedInputBIP143(indexLookup, transaction, additionals = []) { | ||
@@ -211,0 +235,0 @@ return getTrustedInputBIP143(this._transport, indexLookup, transaction, additionals); |
@@ -5,4 +5,5 @@ import type { CreateTransactionArg } from "./createTransaction"; | ||
/** | ||
* This class implements the same interface as BtcOld (formerly | ||
* named Btc), but interacts with Bitcoin hardware app version 2+ | ||
* @class BtcNew | ||
* @description This class implements the same interface as BtcOld (formerly | ||
* named Btc), but interacts with Bitcoin hardware app version 2.1.0+ | ||
* which uses a totally new APDU protocol. This new | ||
@@ -17,2 +18,3 @@ * protocol is documented at | ||
* a much cleaner implementation. | ||
* | ||
*/ | ||
@@ -19,0 +21,0 @@ export default class BtcNew { |
@@ -21,4 +21,5 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
/** | ||
* This class implements the same interface as BtcOld (formerly | ||
* named Btc), but interacts with Bitcoin hardware app version 2+ | ||
* @class BtcNew | ||
* @description This class implements the same interface as BtcOld (formerly | ||
* named Btc), but interacts with Bitcoin hardware app version 2.1.0+ | ||
* which uses a totally new APDU protocol. This new | ||
@@ -33,2 +34,3 @@ * protocol is documented at | ||
* a much cleaner implementation. | ||
* | ||
*/ | ||
@@ -348,2 +350,7 @@ export default class BtcNew { | ||
} | ||
/** | ||
* This function returns a descriptor template based on the address format. | ||
* See https://github.com/LedgerHQ/app-bitcoin-new/blob/develop/doc/wallet.md for details of | ||
* the bitcoin descriptor template. | ||
*/ | ||
function descrTemplFrom(addressFormat) { | ||
@@ -350,0 +357,0 @@ if (addressFormat == "legacy") |
@@ -6,7 +6,5 @@ import type Transport from "@ledgerhq/hw-transport"; | ||
/** | ||
* Bitcoin API. | ||
* @class BtcOld | ||
* @description This Bitcoin old API is compatible with versions of the Bitcoin nano app that are earlier than 2.1.0 | ||
* | ||
* @example | ||
* import Btc from "@ledgerhq/hw-app-btc"; | ||
* const btc = new Btc({ transport, currency: "zcash" }); | ||
*/ | ||
@@ -28,3 +26,3 @@ export default class BtcOld { | ||
* | ||
* - format ("legacy" | "p2sh" | "bech32" | "cashaddr") to use different bitcoin address formatter. | ||
* - format ("legacy" | "p2sh" | "bech32" | "bech32m" | "cashaddr") to use different bitcoin address formatter. | ||
* | ||
@@ -37,4 +35,6 @@ * NB The normal usage is to use: | ||
* | ||
* - bech32 format with 173' paths | ||
* - bech32 format with 84' paths | ||
* | ||
* - bech32m format with 86' paths | ||
* | ||
* - cashaddr in case of Bitcoin Cash | ||
@@ -74,2 +74,4 @@ * | ||
* - "gold" for btg | ||
* - "decred" for decred | ||
* - "zcash" for zcash | ||
* - "bipxxx" for using BIPxxx | ||
@@ -76,0 +78,0 @@ * - "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200) |
@@ -18,7 +18,5 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
/** | ||
* Bitcoin API. | ||
* @class BtcOld | ||
* @description This Bitcoin old API is compatible with versions of the Bitcoin nano app that are earlier than 2.1.0 | ||
* | ||
* @example | ||
* import Btc from "@ledgerhq/hw-app-btc"; | ||
* const btc = new Btc({ transport, currency: "zcash" }); | ||
*/ | ||
@@ -58,3 +56,3 @@ export default class BtcOld { | ||
* | ||
* - format ("legacy" | "p2sh" | "bech32" | "cashaddr") to use different bitcoin address formatter. | ||
* - format ("legacy" | "p2sh" | "bech32" | "bech32m" | "cashaddr") to use different bitcoin address formatter. | ||
* | ||
@@ -67,4 +65,6 @@ * NB The normal usage is to use: | ||
* | ||
* - bech32 format with 173' paths | ||
* - bech32 format with 84' paths | ||
* | ||
* - bech32m format with 86' paths | ||
* | ||
* - cashaddr in case of Bitcoin Cash | ||
@@ -102,2 +102,4 @@ * | ||
* - "gold" for btg | ||
* - "decred" for decred | ||
* - "zcash" for zcash | ||
* - "bipxxx" for using BIPxxx | ||
@@ -104,0 +106,0 @@ * - "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200) |
@@ -1,7 +0,12 @@ | ||
// flow | ||
// the maximum number of bytes allowed in a single chunk when processing bitcoin script data. | ||
// if the Bitcoin script is too large, we will process it in several chunks. | ||
export const MAX_SCRIPT_BLOCK = 50; | ||
export const DEFAULT_VERSION = 1; | ||
export const DEFAULT_LOCKTIME = 0; | ||
// input sequence for non-rbf transactions | ||
export const DEFAULT_SEQUENCE = 0xffffffff; | ||
// SIGHASH flags(Sign all inputs and outputs) | ||
// refer to https://wiki.bitcoinsv.io/index.php/SIGHASH_flags for more details | ||
export const SIGHASH_ALL = 1; | ||
// refer to https://en.bitcoin.it/wiki/Script for Opcodes(OP_DUP, OP_HASH160...) that are used in bitcoin script | ||
export const OP_DUP = 0x76; | ||
@@ -8,0 +13,0 @@ export const OP_HASH160 = 0xa9; |
@@ -127,3 +127,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
targetTransaction.nVersionGroupId = Buffer.from( | ||
// nVersionGroupId is 0x26A7270A for zcash from https://z.cash/upgrade/nu5/ | ||
// nVersionGroupId is 0x26A7270A for zcash NU5 upgrade | ||
// refer to https://github.com/zcash/zcash/blob/master/src/primitives/transaction.h | ||
isZcash | ||
@@ -130,0 +131,0 @@ ? [0x0a, 0x27, 0xa7, 0x26] |
import type Transport from "@ledgerhq/hw-transport"; | ||
/** | ||
* address format is one of legacy | p2sh | bech32 | cashaddr | ||
* address format is one of legacy | p2sh | bech32 | bech32m | cashaddr | ||
*/ | ||
@@ -5,0 +5,0 @@ export type AddressFormat = "legacy" | "p2sh" | "bech32" | "bech32m" | "cashaddr"; |
@@ -0,1 +1,10 @@ | ||
/** | ||
* @file bip32.ts | ||
* @description BIP32 Path Handling for Bitcoin Wallets | ||
* | ||
* This file provides utility functions to handle BIP32 paths, | ||
* which are commonly used in hierarchical deterministic (HD) wallets. | ||
* It includes functions to convert BIP32 paths to and from different formats, | ||
* extract components from extended public keys (xpubs), and manipulate path elements. | ||
*/ | ||
/// <reference types="node" /> | ||
@@ -2,0 +11,0 @@ export declare function pathElementsToBuffer(paths: number[]): Buffer; |
"use strict"; | ||
/** | ||
* @file bip32.ts | ||
* @description BIP32 Path Handling for Bitcoin Wallets | ||
* | ||
* This file provides utility functions to handle BIP32 paths, | ||
* which are commonly used in hierarchical deterministic (HD) wallets. | ||
* It includes functions to convert BIP32 paths to and from different formats, | ||
* extract components from extended public keys (xpubs), and manipulate path elements. | ||
*/ | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -3,0 +12,0 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; |
@@ -11,4 +11,7 @@ /// <reference types="node" /> | ||
/** | ||
* Bitcoin API. | ||
* | ||
* @class Btc | ||
* @description Bitcoin API. | ||
* @param transport The transport layer used for communication. | ||
* @param scrambleKey This parameter is deprecated and no longer needed. | ||
* @param currency The currency to use, defaults to "bitcoin". | ||
* @example | ||
@@ -29,4 +32,6 @@ * import Btc from "@ledgerhq/hw-app-btc"; | ||
* @param arg derivation parameter | ||
* - path: a BIP 32 path of the account level. e.g. `84'/0'/0'` | ||
* - xpubVersion: the XPUBVersion of the coin used. (use @ledgerhq/currencies if needed) | ||
* - path: a BIP 32 path of the account level. (e.g. The derivation path `84'/0'/0'` | ||
* follows the `purpose' / coin_type' / account'` standard, with purpose=84, coin_type=0, account=0) | ||
* - xpubVersion: the XPUBVersion of the coin used. (refer to ledgerjs/packages/cryptoassets/src/currencies.ts | ||
* for the XPUBVersion value if needed) | ||
* @returns XPUB of the account | ||
@@ -39,6 +44,6 @@ */ | ||
/** | ||
* @param path a BIP 32 path | ||
* @param path a BIP 32 path (i.e. the `purpose’ / coin_type’ / account’ / change / address_index` standard) | ||
* @param options an object with optional these fields: | ||
* | ||
* - verify (boolean) will ask user to confirm the address on the device | ||
* - verify (boolean) whether ask user to confirm the address on the device | ||
* | ||
@@ -55,2 +60,4 @@ * - format ("legacy" | "p2sh" | "bech32" | "bech32m" | "cashaddr") to use different bitcoin address formatter. | ||
* | ||
* - bech32m format with 86' paths | ||
* | ||
* - cashaddr in case of Bitcoin Cash | ||
@@ -105,2 +112,4 @@ * | ||
* - "gold" for btg | ||
* - "decred" for decred | ||
* - "zcash" for zcash | ||
* - "bipxxx" for using BIPxxx | ||
@@ -141,2 +150,8 @@ * - "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200) | ||
* For each UTXO included in your transaction, create a transaction object from the raw serialized version of the transaction used in this UTXO. | ||
* @param transactionHex a raw hexadecimal serialized transaction | ||
* @param isSegwitSupported is a boolean indicating if the segwit is supported | ||
* @param hasTimestamp is a boolean (peercoin includes timestamp in their transactions, others don't) | ||
* @param hasExtraData is a boolean (komodo, zencash and zcash include extraData in their transactions, others don't) | ||
* @param additionals list of additionnal options | ||
* @return the transaction object deserialized from the raw hexadecimal transaction | ||
* @example | ||
@@ -147,3 +162,4 @@ const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000"); | ||
/** | ||
@example | ||
* Serialize a transaction's outputs to hexadecimal | ||
* @example | ||
const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000"); | ||
@@ -153,3 +169,11 @@ const outputScript = btc.serializeTransactionOutputs(tx1).toString('hex'); | ||
serializeTransactionOutputs(t: Transaction): Buffer; | ||
/** | ||
* Trusted input is the hash of a UTXO that needs to be signed | ||
* For Legacy transactions, the app has some APDUs flows that do the amount check for an UTXO, | ||
* by parsing the transaction that created this UTXO | ||
*/ | ||
getTrustedInput(indexLookup: number, transaction: Transaction, additionals?: Array<string>): Promise<string>; | ||
/** | ||
* Trusted input is the hash of a UTXO that needs to be signed. BIP143 is used for Segwit inputs. | ||
*/ | ||
getTrustedInputBIP143(indexLookup: number, transaction: Transaction, additionals?: Array<string>): string; | ||
@@ -156,0 +180,0 @@ changeImplIfNecessary(): Promise<BtcOld | BtcNew>; |
@@ -26,4 +26,7 @@ "use strict"; | ||
/** | ||
* Bitcoin API. | ||
* | ||
* @class Btc | ||
* @description Bitcoin API. | ||
* @param transport The transport layer used for communication. | ||
* @param scrambleKey This parameter is deprecated and no longer needed. | ||
* @param currency The currency to use, defaults to "bitcoin". | ||
* @example | ||
@@ -61,4 +64,6 @@ * import Btc from "@ledgerhq/hw-app-btc"; | ||
* @param arg derivation parameter | ||
* - path: a BIP 32 path of the account level. e.g. `84'/0'/0'` | ||
* - xpubVersion: the XPUBVersion of the coin used. (use @ledgerhq/currencies if needed) | ||
* - path: a BIP 32 path of the account level. (e.g. The derivation path `84'/0'/0'` | ||
* follows the `purpose' / coin_type' / account'` standard, with purpose=84, coin_type=0, account=0) | ||
* - xpubVersion: the XPUBVersion of the coin used. (refer to ledgerjs/packages/cryptoassets/src/currencies.ts | ||
* for the XPUBVersion value if needed) | ||
* @returns XPUB of the account | ||
@@ -72,6 +77,6 @@ */ | ||
/** | ||
* @param path a BIP 32 path | ||
* @param path a BIP 32 path (i.e. the `purpose’ / coin_type’ / account’ / change / address_index` standard) | ||
* @param options an object with optional these fields: | ||
* | ||
* - verify (boolean) will ask user to confirm the address on the device | ||
* - verify (boolean) whether ask user to confirm the address on the device | ||
* | ||
@@ -88,2 +93,4 @@ * - format ("legacy" | "p2sh" | "bech32" | "bech32m" | "cashaddr") to use different bitcoin address formatter. | ||
* | ||
* - bech32m format with 86' paths | ||
* | ||
* - cashaddr in case of Bitcoin Cash | ||
@@ -150,2 +157,4 @@ * | ||
* - "gold" for btg | ||
* - "decred" for decred | ||
* - "zcash" for zcash | ||
* - "bipxxx" for using BIPxxx | ||
@@ -195,2 +204,8 @@ * - "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200) | ||
* For each UTXO included in your transaction, create a transaction object from the raw serialized version of the transaction used in this UTXO. | ||
* @param transactionHex a raw hexadecimal serialized transaction | ||
* @param isSegwitSupported is a boolean indicating if the segwit is supported | ||
* @param hasTimestamp is a boolean (peercoin includes timestamp in their transactions, others don't) | ||
* @param hasExtraData is a boolean (komodo, zencash and zcash include extraData in their transactions, others don't) | ||
* @param additionals list of additionnal options | ||
* @return the transaction object deserialized from the raw hexadecimal transaction | ||
* @example | ||
@@ -203,3 +218,4 @@ const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000"); | ||
/** | ||
@example | ||
* Serialize a transaction's outputs to hexadecimal | ||
* @example | ||
const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000"); | ||
@@ -211,5 +227,13 @@ const outputScript = btc.serializeTransactionOutputs(tx1).toString('hex'); | ||
} | ||
/** | ||
* Trusted input is the hash of a UTXO that needs to be signed | ||
* For Legacy transactions, the app has some APDUs flows that do the amount check for an UTXO, | ||
* by parsing the transaction that created this UTXO | ||
*/ | ||
getTrustedInput(indexLookup, transaction, additionals = []) { | ||
return (0, getTrustedInput_1.getTrustedInput)(this._transport, indexLookup, transaction, additionals); | ||
} | ||
/** | ||
* Trusted input is the hash of a UTXO that needs to be signed. BIP143 is used for Segwit inputs. | ||
*/ | ||
getTrustedInputBIP143(indexLookup, transaction, additionals = []) { | ||
@@ -216,0 +240,0 @@ return (0, getTrustedInputBIP143_1.getTrustedInputBIP143)(this._transport, indexLookup, transaction, additionals); |
@@ -5,4 +5,5 @@ import type { CreateTransactionArg } from "./createTransaction"; | ||
/** | ||
* This class implements the same interface as BtcOld (formerly | ||
* named Btc), but interacts with Bitcoin hardware app version 2+ | ||
* @class BtcNew | ||
* @description This class implements the same interface as BtcOld (formerly | ||
* named Btc), but interacts with Bitcoin hardware app version 2.1.0+ | ||
* which uses a totally new APDU protocol. This new | ||
@@ -17,2 +18,3 @@ * protocol is documented at | ||
* a much cleaner implementation. | ||
* | ||
*/ | ||
@@ -19,0 +21,0 @@ export default class BtcNew { |
@@ -24,4 +24,5 @@ "use strict"; | ||
/** | ||
* This class implements the same interface as BtcOld (formerly | ||
* named Btc), but interacts with Bitcoin hardware app version 2+ | ||
* @class BtcNew | ||
* @description This class implements the same interface as BtcOld (formerly | ||
* named Btc), but interacts with Bitcoin hardware app version 2.1.0+ | ||
* which uses a totally new APDU protocol. This new | ||
@@ -36,2 +37,3 @@ * protocol is documented at | ||
* a much cleaner implementation. | ||
* | ||
*/ | ||
@@ -352,2 +354,7 @@ class BtcNew { | ||
exports.default = BtcNew; | ||
/** | ||
* This function returns a descriptor template based on the address format. | ||
* See https://github.com/LedgerHQ/app-bitcoin-new/blob/develop/doc/wallet.md for details of | ||
* the bitcoin descriptor template. | ||
*/ | ||
function descrTemplFrom(addressFormat) { | ||
@@ -354,0 +361,0 @@ if (addressFormat == "legacy") |
@@ -6,7 +6,5 @@ import type Transport from "@ledgerhq/hw-transport"; | ||
/** | ||
* Bitcoin API. | ||
* @class BtcOld | ||
* @description This Bitcoin old API is compatible with versions of the Bitcoin nano app that are earlier than 2.1.0 | ||
* | ||
* @example | ||
* import Btc from "@ledgerhq/hw-app-btc"; | ||
* const btc = new Btc({ transport, currency: "zcash" }); | ||
*/ | ||
@@ -28,3 +26,3 @@ export default class BtcOld { | ||
* | ||
* - format ("legacy" | "p2sh" | "bech32" | "cashaddr") to use different bitcoin address formatter. | ||
* - format ("legacy" | "p2sh" | "bech32" | "bech32m" | "cashaddr") to use different bitcoin address formatter. | ||
* | ||
@@ -37,4 +35,6 @@ * NB The normal usage is to use: | ||
* | ||
* - bech32 format with 173' paths | ||
* - bech32 format with 84' paths | ||
* | ||
* - bech32m format with 86' paths | ||
* | ||
* - cashaddr in case of Bitcoin Cash | ||
@@ -74,2 +74,4 @@ * | ||
* - "gold" for btg | ||
* - "decred" for decred | ||
* - "zcash" for zcash | ||
* - "bipxxx" for using BIPxxx | ||
@@ -76,0 +78,0 @@ * - "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200) |
@@ -23,7 +23,5 @@ "use strict"; | ||
/** | ||
* Bitcoin API. | ||
* @class BtcOld | ||
* @description This Bitcoin old API is compatible with versions of the Bitcoin nano app that are earlier than 2.1.0 | ||
* | ||
* @example | ||
* import Btc from "@ledgerhq/hw-app-btc"; | ||
* const btc = new Btc({ transport, currency: "zcash" }); | ||
*/ | ||
@@ -63,3 +61,3 @@ class BtcOld { | ||
* | ||
* - format ("legacy" | "p2sh" | "bech32" | "cashaddr") to use different bitcoin address formatter. | ||
* - format ("legacy" | "p2sh" | "bech32" | "bech32m" | "cashaddr") to use different bitcoin address formatter. | ||
* | ||
@@ -72,4 +70,6 @@ * NB The normal usage is to use: | ||
* | ||
* - bech32 format with 173' paths | ||
* - bech32 format with 84' paths | ||
* | ||
* - bech32m format with 86' paths | ||
* | ||
* - cashaddr in case of Bitcoin Cash | ||
@@ -107,2 +107,4 @@ * | ||
* - "gold" for btg | ||
* - "decred" for decred | ||
* - "zcash" for zcash | ||
* - "bipxxx" for using BIPxxx | ||
@@ -109,0 +111,0 @@ * - "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200) |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.OP_RETURN = exports.OP_CHECKSIG = exports.OP_EQUALVERIFY = exports.OP_EQUAL = exports.HASH_SIZE = exports.OP_HASH160 = exports.OP_DUP = exports.SIGHASH_ALL = exports.DEFAULT_SEQUENCE = exports.DEFAULT_LOCKTIME = exports.DEFAULT_VERSION = exports.MAX_SCRIPT_BLOCK = void 0; | ||
// flow | ||
// the maximum number of bytes allowed in a single chunk when processing bitcoin script data. | ||
// if the Bitcoin script is too large, we will process it in several chunks. | ||
exports.MAX_SCRIPT_BLOCK = 50; | ||
exports.DEFAULT_VERSION = 1; | ||
exports.DEFAULT_LOCKTIME = 0; | ||
// input sequence for non-rbf transactions | ||
exports.DEFAULT_SEQUENCE = 0xffffffff; | ||
// SIGHASH flags(Sign all inputs and outputs) | ||
// refer to https://wiki.bitcoinsv.io/index.php/SIGHASH_flags for more details | ||
exports.SIGHASH_ALL = 1; | ||
// refer to https://en.bitcoin.it/wiki/Script for Opcodes(OP_DUP, OP_HASH160...) that are used in bitcoin script | ||
exports.OP_DUP = 0x76; | ||
@@ -11,0 +16,0 @@ exports.OP_HASH160 = 0xa9; |
@@ -130,3 +130,4 @@ "use strict"; | ||
targetTransaction.nVersionGroupId = Buffer.from( | ||
// nVersionGroupId is 0x26A7270A for zcash from https://z.cash/upgrade/nu5/ | ||
// nVersionGroupId is 0x26A7270A for zcash NU5 upgrade | ||
// refer to https://github.com/zcash/zcash/blob/master/src/primitives/transaction.h | ||
isZcash | ||
@@ -133,0 +134,0 @@ ? [0x0a, 0x27, 0xa7, 0x26] |
import type Transport from "@ledgerhq/hw-transport"; | ||
/** | ||
* address format is one of legacy | p2sh | bech32 | cashaddr | ||
* address format is one of legacy | p2sh | bech32 | bech32m | cashaddr | ||
*/ | ||
@@ -5,0 +5,0 @@ export type AddressFormat = "legacy" | "p2sh" | "bech32" | "bech32m" | "cashaddr"; |
{ | ||
"name": "@ledgerhq/hw-app-btc", | ||
"version": "10.2.1", | ||
"version": "10.2.2-next.0", | ||
"description": "Ledger Hardware Wallet Bitcoin Application API", | ||
@@ -73,3 +73,3 @@ "keywords": [ | ||
"varuint-bitcoin": "1.1.2", | ||
"@ledgerhq/hw-transport": "^6.30.3", | ||
"@ledgerhq/hw-transport": "^6.30.4-next.0", | ||
"@ledgerhq/logs": "^6.12.0" | ||
@@ -87,4 +87,4 @@ }, | ||
"ts-node": "^10.4.0", | ||
"@ledgerhq/hw-transport-mocker": "^6.28.3", | ||
"@ledgerhq/hw-transport-node-speculos": "^6.28.3" | ||
"@ledgerhq/hw-transport-mocker": "^6.28.4-next.0", | ||
"@ledgerhq/hw-transport-node-speculos": "^6.28.4-next.0" | ||
}, | ||
@@ -91,0 +91,0 @@ "gitHead": "dd0dea64b58e5a9125c8a422dcffd29e5ef6abec", |
162
README.md
@@ -30,2 +30,3 @@ <img src="https://user-images.githubusercontent.com/4631227/191834116-59cf590e-25cc-4956-ae5c-812ea464f324.png" height="100" /> | ||
* [bippath](#bippath) | ||
* [Btc](#btc) | ||
@@ -54,21 +55,24 @@ * [Parameters](#parameters) | ||
* [Examples](#examples-6) | ||
* [getTrustedInput](#gettrustedinput) | ||
* [Parameters](#parameters-8) | ||
* [getTrustedInputBIP143](#gettrustedinputbip143) | ||
* [Parameters](#parameters-9) | ||
* [BtcNew](#btcnew) | ||
* [Parameters](#parameters-8) | ||
* [getWalletXpub](#getwalletxpub-1) | ||
* [Parameters](#parameters-9) | ||
* [Parameters](#parameters-10) | ||
* [getWalletPublicKey](#getwalletpublickey-1) | ||
* [Parameters](#parameters-10) | ||
* [Parameters](#parameters-11) | ||
* [createPaymentTransaction](#createpaymenttransaction-1) | ||
* [Parameters](#parameters-11) | ||
* [Parameters](#parameters-12) | ||
* [signMessage](#signmessage-1) | ||
* [Parameters](#parameters-12) | ||
* [Parameters](#parameters-13) | ||
* [descrTemplFrom](#descrtemplfrom) | ||
* [Parameters](#parameters-14) | ||
* [BtcOld](#btcold) | ||
* [Parameters](#parameters-13) | ||
* [Examples](#examples-7) | ||
* [getWalletPublicKey](#getwalletpublickey-2) | ||
* [Parameters](#parameters-14) | ||
* [Parameters](#parameters-15) | ||
* [Examples](#examples-7) | ||
* [createPaymentTransaction](#createpaymenttransaction-2) | ||
* [Parameters](#parameters-16) | ||
* [Examples](#examples-8) | ||
* [createPaymentTransaction](#createpaymenttransaction-2) | ||
* [Parameters](#parameters-15) | ||
* [Examples](#examples-9) | ||
* [CreateTransactionArg](#createtransactionarg) | ||
@@ -79,35 +83,35 @@ * [Properties](#properties) | ||
* [spendingCondition](#spendingcondition) | ||
* [Parameters](#parameters-16) | ||
* [Parameters](#parameters-17) | ||
* [setInput](#setinput) | ||
* [Parameters](#parameters-17) | ||
* [Parameters](#parameters-18) | ||
* [setOwnOutput](#setownoutput) | ||
* [Parameters](#parameters-18) | ||
* [Parameters](#parameters-19) | ||
* [getDescriptorTemplate](#getdescriptortemplate) | ||
* [SingleKeyAccount](#singlekeyaccount) | ||
* [getTaprootOutputKey](#gettaprootoutputkey) | ||
* [Parameters](#parameters-19) | ||
* [Parameters](#parameters-20) | ||
* [AppClient](#appclient) | ||
* [Parameters](#parameters-20) | ||
* [Parameters](#parameters-21) | ||
* [ClientCommandInterpreter](#clientcommandinterpreter) | ||
* [Parameters](#parameters-21) | ||
* [Parameters](#parameters-22) | ||
* [MerkelizedPsbt](#merkelizedpsbt) | ||
* [Parameters](#parameters-22) | ||
* [Parameters](#parameters-23) | ||
* [Merkle](#merkle) | ||
* [Parameters](#parameters-23) | ||
* [Parameters](#parameters-24) | ||
* [MerkleMap](#merklemap) | ||
* [Parameters](#parameters-24) | ||
* [Parameters](#parameters-25) | ||
* [WalletPolicy](#walletpolicy) | ||
* [Parameters](#parameters-25) | ||
* [Parameters](#parameters-26) | ||
* [extract](#extract) | ||
* [Parameters](#parameters-26) | ||
* [Parameters](#parameters-27) | ||
* [finalize](#finalize) | ||
* [Parameters](#parameters-27) | ||
* [Parameters](#parameters-28) | ||
* [clearFinalizedInput](#clearfinalizedinput) | ||
* [Parameters](#parameters-28) | ||
* [Parameters](#parameters-29) | ||
* [writePush](#writepush) | ||
* [Parameters](#parameters-29) | ||
* [Parameters](#parameters-30) | ||
* [PsbtV2](#psbtv2) | ||
* [serializeTransactionOutputs](#serializetransactionoutputs-1) | ||
* [Parameters](#parameters-30) | ||
* [Examples](#examples-10) | ||
* [Parameters](#parameters-31) | ||
* [Examples](#examples-9) | ||
* [SignP2SHTransactionArg](#signp2shtransactionarg) | ||
@@ -119,2 +123,11 @@ * [Properties](#properties-1) | ||
### bippath | ||
BIP32 Path Handling for Bitcoin Wallets | ||
This file provides utility functions to handle BIP32 paths, | ||
which are commonly used in hierarchical deterministic (HD) wallets. | ||
It includes functions to convert BIP32 paths to and from different formats, | ||
extract components from extended public keys (xpubs), and manipulate path elements. | ||
### Btc | ||
@@ -126,8 +139,6 @@ | ||
* `$0` **{transport: Transport, scrambleKey: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?, currency: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?}**  | ||
* `transport` The transport layer used for communication. | ||
* `scrambleKey` This parameter is deprecated and no longer needed. | ||
* `currency` The currency to use, defaults to "bitcoin". | ||
* `$0.transport`   | ||
* `$0.scrambleKey` (optional, default `"BTC"`) | ||
* `$0.currency` (optional, default `"bitcoin"`) | ||
#### Examples | ||
@@ -146,4 +157,6 @@ | ||
* `arg` **{path: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), xpubVersion: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)}** derivation parameter* path: a BIP 32 path of the account level. e.g. `84'/0'/0'` | ||
* xpubVersion: the XPUBVersion of the coin used. (use @ledgerhq/currencies if needed) | ||
* `arg` **{path: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), xpubVersion: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)}** derivation parameter* path: a BIP 32 path of the account level. (e.g. The derivation path `84'/0'/0'` | ||
follows the `purpose' / coin_type' / account'` standard, with purpose=84, coin\_type=0, account=0) | ||
* xpubVersion: the XPUBVersion of the coin used. (refer to ledgerjs/packages/cryptoassets/src/currencies.ts | ||
for the XPUBVersion value if needed) | ||
@@ -156,5 +169,5 @@ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** XPUB of the account | ||
* `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a BIP 32 path | ||
* `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a BIP 32 path (i.e. the `purpose’ / coin_type’ / account’ / change / address_index` standard) | ||
* `opts` **{verify: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?, format: [AddressFormat](#addressformat)?}?**  | ||
* `options` an object with optional these fields:* verify (boolean) will ask user to confirm the address on the device | ||
* `options` an object with optional these fields:* verify (boolean) whether ask user to confirm the address on the device | ||
@@ -167,2 +180,4 @@ * format ("legacy" | "p2sh" | "bech32" | "bech32m" | "cashaddr") to use different bitcoin address formatter.NB The normal usage is to use:* legacy format with 44' paths | ||
* bech32m format with 86' paths | ||
* cashaddr in case of Bitcoin Cash | ||
@@ -222,2 +237,4 @@ | ||
* "gold" for btg | ||
* "decred" for decred | ||
* "zcash" for zcash | ||
* "bipxxx" for using BIPxxx | ||
@@ -274,7 +291,7 @@ * "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200) | ||
* `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) | null | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))** (optional, default `false`) | ||
* `hasTimestamp` (optional, default `false`) | ||
* `hasExtraData` (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 `[]`) | ||
* `transactionHex` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a raw hexadecimal serialized transaction | ||
* `isSegwitSupported` **([boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean) | null | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))** is a boolean indicating if the segwit is supported (optional, default `false`) | ||
* `hasTimestamp` is a boolean (peercoin includes timestamp in their transactions, others don't) (optional, default `false`) | ||
* `hasExtraData` is a boolean (komodo, zencash and zcash include extraData in their transactions, others don't) (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)>** list of additionnal options (optional, default `[]`) | ||
@@ -287,6 +304,8 @@ ##### Examples | ||
Returns **[Transaction](#transaction)**  | ||
Returns **[Transaction](#transaction)** the transaction object deserialized from the raw hexadecimal transaction | ||
#### serializeTransactionOutputs | ||
Serialize a transaction's outputs to hexadecimal | ||
##### Parameters | ||
@@ -305,6 +324,32 @@ | ||
#### getTrustedInput | ||
Trusted input is the hash of a UTXO that needs to be signed | ||
For Legacy transactions, the app has some APDUs flows that do the amount check for an UTXO, | ||
by parsing the transaction that created this UTXO | ||
##### Parameters | ||
* `indexLookup` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**  | ||
* `transaction` **[Transaction](#transaction)**  | ||
* `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 `[]`) | ||
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>**  | ||
#### getTrustedInputBIP143 | ||
Trusted input is the hash of a UTXO that needs to be signed. BIP143 is used for Segwit inputs. | ||
##### Parameters | ||
* `indexLookup` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**  | ||
* `transaction` **[Transaction](#transaction)**  | ||
* `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 `[]`) | ||
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**  | ||
### BtcNew | ||
This class implements the same interface as BtcOld (formerly | ||
named Btc), but interacts with Bitcoin hardware app version 2+ | ||
named Btc), but interacts with Bitcoin hardware app version 2.1.0+ | ||
which uses a totally new APDU protocol. This new | ||
@@ -320,6 +365,2 @@ protocol is documented at | ||
#### Parameters | ||
* ``   | ||
#### getWalletXpub | ||
@@ -410,17 +451,18 @@ | ||
### BtcOld | ||
### descrTemplFrom | ||
Bitcoin API. | ||
This function returns a descriptor template based on the address format. | ||
See <https://github.com/LedgerHQ/app-bitcoin-new/blob/develop/doc/wallet.md> for details of | ||
the bitcoin descriptor template. | ||
#### Parameters | ||
* ``   | ||
* `addressFormat` **[AddressFormat](#addressformat)**  | ||
#### Examples | ||
Returns **DefaultDescriptorTemplate**  | ||
```javascript | ||
import Btc from "@ledgerhq/hw-app-btc"; | ||
const btc = new Btc({ transport, currency: "zcash" }); | ||
``` | ||
### BtcOld | ||
This Bitcoin old API is compatible with versions of the Bitcoin nano app that are earlier than 2.1.0 | ||
#### getWalletPublicKey | ||
@@ -434,8 +476,10 @@ | ||
* format ("legacy" | "p2sh" | "bech32" | "cashaddr") to use different bitcoin address formatter.NB The normal usage is to use:* legacy format with 44' paths | ||
* format ("legacy" | "p2sh" | "bech32" | "bech32m" | "cashaddr") to use different bitcoin address formatter.NB The normal usage is to use:* legacy format with 44' paths | ||
* p2sh format with 49' paths | ||
* bech32 format with 173' paths | ||
* bech32 format with 84' paths | ||
* bech32m format with 86' paths | ||
* cashaddr in case of Bitcoin Cash | ||
@@ -473,2 +517,4 @@ | ||
* "gold" for btg | ||
* "decred" for decred | ||
* "zcash" for zcash | ||
* "bipxxx" for using BIPxxx | ||
@@ -514,3 +560,3 @@ * "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200) | ||
address format is one of legacy | p2sh | bech32 | cashaddr | ||
address format is one of legacy | p2sh | bech32 | bech32m | cashaddr | ||
@@ -517,0 +563,0 @@ Type: (`"legacy"` | `"p2sh"` | `"bech32"` | `"bech32m"` | `"cashaddr"`) |
@@ -0,1 +1,11 @@ | ||
/** | ||
* @file bip32.ts | ||
* @description BIP32 Path Handling for Bitcoin Wallets | ||
* | ||
* This file provides utility functions to handle BIP32 paths, | ||
* which are commonly used in hierarchical deterministic (HD) wallets. | ||
* It includes functions to convert BIP32 paths to and from different formats, | ||
* extract components from extended public keys (xpubs), and manipulate path elements. | ||
*/ | ||
import bippath from "bip32-path"; | ||
@@ -2,0 +12,0 @@ import bs58check from "bs58check"; |
@@ -19,4 +19,7 @@ import semver from "semver"; | ||
/** | ||
* Bitcoin API. | ||
* | ||
* @class Btc | ||
* @description Bitcoin API. | ||
* @param transport The transport layer used for communication. | ||
* @param scrambleKey This parameter is deprecated and no longer needed. | ||
* @param currency The currency to use, defaults to "bitcoin". | ||
* @example | ||
@@ -28,5 +31,7 @@ * import Btc from "@ledgerhq/hw-app-btc"; | ||
export default class Btc { | ||
// Transport instance | ||
private _transport: Transport; | ||
// The specific implementation used, determined by the nano app and its version. | ||
// It chooses between BtcNew (new interface) and BtcOld (old interface). | ||
private _impl: BtcOld | BtcNew; | ||
constructor({ | ||
@@ -73,4 +78,6 @@ transport, | ||
* @param arg derivation parameter | ||
* - path: a BIP 32 path of the account level. e.g. `84'/0'/0'` | ||
* - xpubVersion: the XPUBVersion of the coin used. (use @ledgerhq/currencies if needed) | ||
* - path: a BIP 32 path of the account level. (e.g. The derivation path `84'/0'/0'` | ||
* follows the `purpose' / coin_type' / account'` standard, with purpose=84, coin_type=0, account=0) | ||
* - xpubVersion: the XPUBVersion of the coin used. (refer to ledgerjs/packages/cryptoassets/src/currencies.ts | ||
* for the XPUBVersion value if needed) | ||
* @returns XPUB of the account | ||
@@ -85,6 +92,6 @@ */ | ||
/** | ||
* @param path a BIP 32 path | ||
* @param path a BIP 32 path (i.e. the `purpose’ / coin_type’ / account’ / change / address_index` standard) | ||
* @param options an object with optional these fields: | ||
* | ||
* - verify (boolean) will ask user to confirm the address on the device | ||
* - verify (boolean) whether ask user to confirm the address on the device | ||
* | ||
@@ -101,2 +108,4 @@ * - format ("legacy" | "p2sh" | "bech32" | "bech32m" | "cashaddr") to use different bitcoin address formatter. | ||
* | ||
* - bech32m format with 86' paths | ||
* | ||
* - cashaddr in case of Bitcoin Cash | ||
@@ -183,2 +192,4 @@ * | ||
* - "gold" for btg | ||
* - "decred" for decred | ||
* - "zcash" for zcash | ||
* - "bipxxx" for using BIPxxx | ||
@@ -232,2 +243,8 @@ * - "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200) | ||
* For each UTXO included in your transaction, create a transaction object from the raw serialized version of the transaction used in this UTXO. | ||
* @param transactionHex a raw hexadecimal serialized transaction | ||
* @param isSegwitSupported is a boolean indicating if the segwit is supported | ||
* @param hasTimestamp is a boolean (peercoin includes timestamp in their transactions, others don't) | ||
* @param hasExtraData is a boolean (komodo, zencash and zcash include extraData in their transactions, others don't) | ||
* @param additionals list of additionnal options | ||
* @return the transaction object deserialized from the raw hexadecimal transaction | ||
* @example | ||
@@ -253,3 +270,4 @@ const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000"); | ||
/** | ||
@example | ||
* Serialize a transaction's outputs to hexadecimal | ||
* @example | ||
const tx1 = btc.splitTransaction("01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000"); | ||
@@ -262,2 +280,7 @@ const outputScript = btc.serializeTransactionOutputs(tx1).toString('hex'); | ||
/** | ||
* Trusted input is the hash of a UTXO that needs to be signed | ||
* For Legacy transactions, the app has some APDUs flows that do the amount check for an UTXO, | ||
* by parsing the transaction that created this UTXO | ||
*/ | ||
getTrustedInput( | ||
@@ -271,2 +294,5 @@ indexLookup: number, | ||
/** | ||
* Trusted input is the hash of a UTXO that needs to be signed. BIP143 is used for Segwit inputs. | ||
*/ | ||
getTrustedInputBIP143( | ||
@@ -273,0 +299,0 @@ indexLookup: number, |
@@ -30,4 +30,5 @@ import { crypto } from "bitcoinjs-lib"; | ||
/** | ||
* This class implements the same interface as BtcOld (formerly | ||
* named Btc), but interacts with Bitcoin hardware app version 2+ | ||
* @class BtcNew | ||
* @description This class implements the same interface as BtcOld (formerly | ||
* named Btc), but interacts with Bitcoin hardware app version 2.1.0+ | ||
* which uses a totally new APDU protocol. This new | ||
@@ -42,2 +43,3 @@ * protocol is documented at | ||
* a much cleaner implementation. | ||
* | ||
*/ | ||
@@ -428,2 +430,7 @@ export default class BtcNew { | ||
/** | ||
* This function returns a descriptor template based on the address format. | ||
* See https://github.com/LedgerHQ/app-bitcoin-new/blob/develop/doc/wallet.md for details of | ||
* the bitcoin descriptor template. | ||
*/ | ||
function descrTemplFrom(addressFormat: AddressFormat): DefaultDescriptorTemplate { | ||
@@ -430,0 +437,0 @@ if (addressFormat == "legacy") return "pkh(@0)"; |
@@ -14,7 +14,5 @@ import bs58 from "bs58"; | ||
/** | ||
* Bitcoin API. | ||
* @class BtcOld | ||
* @description This Bitcoin old API is compatible with versions of the Bitcoin nano app that are earlier than 2.1.0 | ||
* | ||
* @example | ||
* import Btc from "@ledgerhq/hw-app-btc"; | ||
* const btc = new Btc({ transport, currency: "zcash" }); | ||
*/ | ||
@@ -66,3 +64,3 @@ | ||
* | ||
* - format ("legacy" | "p2sh" | "bech32" | "cashaddr") to use different bitcoin address formatter. | ||
* - format ("legacy" | "p2sh" | "bech32" | "bech32m" | "cashaddr") to use different bitcoin address formatter. | ||
* | ||
@@ -75,4 +73,6 @@ * NB The normal usage is to use: | ||
* | ||
* - bech32 format with 173' paths | ||
* - bech32 format with 84' paths | ||
* | ||
* - bech32m format with 86' paths | ||
* | ||
* - cashaddr in case of Bitcoin Cash | ||
@@ -121,2 +121,4 @@ * | ||
* - "gold" for btg | ||
* - "decred" for decred | ||
* - "zcash" for zcash | ||
* - "bipxxx" for using BIPxxx | ||
@@ -123,0 +125,0 @@ * - "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200) |
@@ -1,7 +0,12 @@ | ||
// flow | ||
// the maximum number of bytes allowed in a single chunk when processing bitcoin script data. | ||
// if the Bitcoin script is too large, we will process it in several chunks. | ||
export const MAX_SCRIPT_BLOCK = 50; | ||
export const DEFAULT_VERSION = 1; | ||
export const DEFAULT_LOCKTIME = 0; | ||
// input sequence for non-rbf transactions | ||
export const DEFAULT_SEQUENCE = 0xffffffff; | ||
// SIGHASH flags(Sign all inputs and outputs) | ||
// refer to https://wiki.bitcoinsv.io/index.php/SIGHASH_flags for more details | ||
export const SIGHASH_ALL = 1; | ||
// refer to https://en.bitcoin.it/wiki/Script for Opcodes(OP_DUP, OP_HASH160...) that are used in bitcoin script | ||
export const OP_DUP = 0x76; | ||
@@ -8,0 +13,0 @@ export const OP_HASH160 = 0xa9; |
@@ -176,3 +176,4 @@ import { log } from "@ledgerhq/logs"; | ||
targetTransaction.nVersionGroupId = Buffer.from( | ||
// nVersionGroupId is 0x26A7270A for zcash from https://z.cash/upgrade/nu5/ | ||
// nVersionGroupId is 0x26A7270A for zcash NU5 upgrade | ||
// refer to https://github.com/zcash/zcash/blob/master/src/primitives/transaction.h | ||
isZcash | ||
@@ -179,0 +180,0 @@ ? [0x0a, 0x27, 0xa7, 0x26] |
@@ -5,3 +5,3 @@ import type Transport from "@ledgerhq/hw-transport"; | ||
/** | ||
* address format is one of legacy | p2sh | bech32 | cashaddr | ||
* address format is one of legacy | p2sh | bech32 | bech32m | cashaddr | ||
*/ | ||
@@ -8,0 +8,0 @@ export type AddressFormat = "legacy" | "p2sh" | "bech32" | "bech32m" | "cashaddr"; |
@@ -20,10 +20,22 @@ /** | ||
export interface Transaction { | ||
// Each transaction is prefixed by a four-byte transaction version number | ||
// which tells Bitcoin peers and miners which set of rules to use to validate it. | ||
version: Buffer; | ||
inputs: TransactionInput[]; | ||
outputs?: TransactionOutput[]; | ||
// locktime indicates the earliest time or earliest block when that transaction may | ||
// be added to the block chain. | ||
locktime?: Buffer; | ||
witness?: Buffer; | ||
// timestamp is used only for peercoin but it is no longer necessary anymore | ||
timestamp?: Buffer; | ||
// nVersionGroupId is used only for Zcash, different version of Zcash has different nVersionGroupId | ||
// refer to https://github.com/zcash/zcash/blob/master/src/primitives/transaction.h for more details | ||
nVersionGroupId?: Buffer; | ||
// nExpiryHeight is used only for Decred and Zcash and ZenCash. | ||
// It sets the block height after which transactions will be removed | ||
// from the mempool if they have not been mined | ||
// refer to https://zips.z.cash/zip-0203 for more details | ||
nExpiryHeight?: Buffer; | ||
// extraData is used only for Zcash and ZenCash and komodo | ||
extraData?: Buffer; | ||
@@ -30,0 +42,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
1071749
15429
826
1