@ledgerhq/hw-app-btc
Advanced tools
Comparing version 4.48.0 to 4.49.0
@@ -29,2 +29,11 @@ "use strict"; | ||
/** | ||
* address format is one of legacy | p2sh | bech32 | ||
*/ | ||
var addressFormatMap = { | ||
legacy: 0, | ||
p2sh: 1, | ||
bech32: 2 | ||
}; | ||
var MAX_SCRIPT_BLOCK = 50; | ||
@@ -65,12 +74,18 @@ var DEFAULT_VERSION = 1; | ||
key: "getWalletPublicKey_private", | ||
value: function getWalletPublicKey_private(path, verify, segwit) { | ||
value: function getWalletPublicKey_private(path) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var _verify$format$option = _extends({ | ||
verify: false, | ||
format: "legacy" | ||
}, options), | ||
verify = _verify$format$option.verify, | ||
format = _verify$format$option.format; | ||
if (!(format in addressFormatMap)) { | ||
throw new Error("btc.getWalletPublicKey invalid format=" + format); | ||
} | ||
var paths = (0, _utils.splitPath)(path); | ||
var p1 = 0x00; | ||
var p2 = 0x00; | ||
if (verify === true) { | ||
p1 = 0x01; | ||
} | ||
if (segwit == true) { | ||
p2 = 0x01; | ||
} | ||
var p1 = verify ? 1 : 0; | ||
var p2 = addressFormatMap[format]; | ||
var buffer = Buffer.alloc(1 + paths.length * 4); | ||
@@ -93,5 +108,19 @@ buffer[0] = paths.length; | ||
* @param path a BIP 32 path | ||
* @param segwit use segwit | ||
* @param options an object with optional these fields: | ||
* | ||
* - verify (boolean) will ask user to confirm the address on the device | ||
* | ||
* - format ("legacy" | "p2sh" | "bech32") 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 | ||
* | ||
* @example | ||
* btc.getWalletPublicKey("44'/0'/0'/0").then(o => o.bitcoinAddress) | ||
* btc.getWalletPublicKey("44'/0'/0'/0/0").then(o => o.bitcoinAddress) | ||
* btc.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress) | ||
*/ | ||
@@ -101,7 +130,15 @@ | ||
key: "getWalletPublicKey", | ||
value: function getWalletPublicKey(path) { | ||
var verify = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
var segwit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
return this.getWalletPublicKey_private(path, verify, segwit); | ||
value: function getWalletPublicKey(path, opts) { | ||
var deprecatedSignature = arguments.length > 2 || typeof opts === "boolean"; | ||
var options = void 0; | ||
if (deprecatedSignature) { | ||
console.warn("btc.getWalletPublicKey deprecated signature used. Please switch to getWalletPublicKey(path, { format, verify })"); | ||
options = { | ||
verify: !!opts, | ||
format: arguments[2] ? "p2sh" : "legacy" | ||
}; | ||
} else { | ||
options = opts || {}; | ||
} | ||
return this.getWalletPublicKey_private(path, options); | ||
} | ||
@@ -275,3 +312,3 @@ }, { | ||
function getTrustedInputBIP143(_x5, _x6) { | ||
function getTrustedInputBIP143(_x4, _x5) { | ||
return _ref.apply(this, arguments); | ||
@@ -278,0 +315,0 @@ } |
{ | ||
"name": "@ledgerhq/hw-app-btc", | ||
"version": "4.48.0", | ||
"version": "4.49.0", | ||
"description": "Ledger Hardware Wallet Bitcoin Application API", | ||
@@ -42,3 +42,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "ae4f6034a9364c12212060fd46e39bdaf14d562e" | ||
"gitHead": "f5a15a1d0d43c31d0b3b0fa1f147d4fca4e9ac90" | ||
} |
@@ -17,2 +17,3 @@ <img src="https://user-images.githubusercontent.com/211411/34776833-6f1ef4da-f618-11e7-8b13-f0697901d6a8.png" height="100" /> | ||
- [AddressFormat](#addressformat) | ||
- [Btc](#btc) | ||
@@ -50,2 +51,8 @@ - [Parameters](#parameters) | ||
### AddressFormat | ||
address format is one of legacy | p2sh | bech32 | ||
Type: (`"legacy"` \| `"p2sh"` \| `"bech32"`) | ||
### Btc | ||
@@ -72,9 +79,16 @@ | ||
- `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 | ||
- `opts` **any** | ||
- `options` an object with optional these fields:- verify (boolean) will ask user to confirm the address on the device | ||
- format ("legacy" | "p2sh" | "bech32") 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 | ||
##### Examples | ||
```javascript | ||
btc.getWalletPublicKey("44'/0'/0'/0").then(o => o.bitcoinAddress) | ||
btc.getWalletPublicKey("44'/0'/0'/0/0").then(o => o.bitcoinAddress) | ||
btc.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress) | ||
``` | ||
@@ -81,0 +95,0 @@ |
@@ -11,2 +11,13 @@ //@flow | ||
/** | ||
* address format is one of legacy | p2sh | bech32 | ||
*/ | ||
export type AddressFormat = "legacy" | "p2sh" | "bech32"; | ||
const addressFormatMap = { | ||
legacy: 0, | ||
p2sh: 1, | ||
bech32: 2 | ||
}; | ||
const MAX_SCRIPT_BLOCK = 50; | ||
@@ -58,4 +69,6 @@ const DEFAULT_VERSION = 1; | ||
path: string, | ||
verify: boolean, | ||
segwit: boolean | ||
options: { | ||
verify?: boolean, | ||
format?: AddressFormat | ||
} = {} | ||
): Promise<{ | ||
@@ -66,11 +79,13 @@ publicKey: string, | ||
}> { | ||
const { verify, format } = { | ||
verify: false, | ||
format: "legacy", | ||
...options | ||
}; | ||
if (!(format in addressFormatMap)) { | ||
throw new Error("btc.getWalletPublicKey invalid format=" + format); | ||
} | ||
const paths = splitPath(path); | ||
var p1 = 0x00; | ||
var p2 = 0x00; | ||
if (verify === true) { | ||
p1 = 0x01; | ||
} | ||
if (segwit == true) { | ||
p2 = 0x01; | ||
} | ||
var p1 = verify ? 1 : 0; | ||
var p2 = addressFormatMap[format]; | ||
const buffer = Buffer.alloc(1 + paths.length * 4); | ||
@@ -100,10 +115,23 @@ buffer[0] = paths.length; | ||
* @param path a BIP 32 path | ||
* @param segwit use segwit | ||
* @param options an object with optional these fields: | ||
* | ||
* - verify (boolean) will ask user to confirm the address on the device | ||
* | ||
* - format ("legacy" | "p2sh" | "bech32") 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 | ||
* | ||
* @example | ||
* btc.getWalletPublicKey("44'/0'/0'/0").then(o => o.bitcoinAddress) | ||
* btc.getWalletPublicKey("44'/0'/0'/0/0").then(o => o.bitcoinAddress) | ||
* btc.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress) | ||
*/ | ||
getWalletPublicKey( | ||
path: string, | ||
verify?: boolean = false, | ||
segwit?: boolean = false | ||
opts?: any | ||
): Promise<{ | ||
@@ -114,3 +142,17 @@ publicKey: string, | ||
}> { | ||
return this.getWalletPublicKey_private(path, verify, segwit); | ||
const deprecatedSignature = | ||
arguments.length > 2 || typeof opts === "boolean"; | ||
let options; | ||
if (deprecatedSignature) { | ||
console.warn( | ||
"btc.getWalletPublicKey deprecated signature used. Please switch to getWalletPublicKey(path, { format, verify })" | ||
); | ||
options = { | ||
verify: !!opts, | ||
format: arguments[2] ? "p2sh" : "legacy" | ||
}; | ||
} else { | ||
options = opts || {}; | ||
} | ||
return this.getWalletPublicKey_private(path, options); | ||
} | ||
@@ -117,0 +159,0 @@ |
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
268586
2544
267