🚀 Big News:Socket Has Acquired Secure Annex.Learn More
Socket
Book a DemoSign in
Socket

@codewarriorr/hw-app-btcv

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codewarriorr/hw-app-btcv - npm Package Compare versions

Comparing version
1.0.2
to
1.0.3
+25
lib-es/setPasswords.js
const passwordType = {
instant: 0,
recovery: 1
};
export async function setPasswords(transport, password, options) {
const {
type
} = {
type: "instant",
...options
};
if (!(type in passwordType)) {
throw new Error("btc.setPasswords invalid type=" + type);
}
const data = password.toString("hex");
const p1 = passwordType[type];
const p2 = 0;
const response = await transport.send(0xe0, 0xD8, p1, p2, data);
return {
response
};
}
//# sourceMappingURL=setPasswords.js.map

Sorry, the diff of this file is not supported yet

{"version":3,"sources":["../src/setPasswords.js"],"names":["passwordType","instant","recovery","setPasswords","transport","password","options","type","Error","data","toString","p1","p2","response","send"],"mappings":"AAGA,MAAMA,YAAY,GAAG;AACjBC,EAAAA,OAAO,EAAE,CADQ;AAEjBC,EAAAA,QAAQ,EAAE;AAFO,CAArB;AAKA,OAAO,eAAeC,YAAf,CACHC,SADG,EAEHC,QAFG,EAGHC,OAHG,EAIL;AACE,QAAM;AAAEC,IAAAA;AAAF,MAAW;AACbA,IAAAA,IAAI,EAAE,SADO;AAEb,OAAGD;AAFU,GAAjB;;AAKA,MAAI,EAAEC,IAAI,IAAIP,YAAV,CAAJ,EAA6B;AACzB,UAAM,IAAIQ,KAAJ,CAAU,mCAAmCD,IAA7C,CAAN;AACH;;AAED,QAAME,IAAI,GAAGJ,QAAQ,CAACK,QAAT,CAAkB,KAAlB,CAAb;AAEA,QAAMC,EAAE,GAAGX,YAAY,CAACO,IAAD,CAAvB;AACA,QAAMK,EAAE,GAAG,CAAX;AACA,QAAMC,QAAQ,GAAG,MAAMT,SAAS,CAACU,IAAV,CAAe,IAAf,EAAqB,IAArB,EAA2BH,EAA3B,EAA+BC,EAA/B,EAAmCH,IAAnC,CAAvB;AAEA,SAAO;AAAEI,IAAAA;AAAF,GAAP;AACH","sourcesContent":["// @flow\nimport type Transport from \"@ledgerhq/hw-transport\";\n\nconst passwordType = {\n instant: 0,\n recovery: 1,\n};\n\nexport async function setPasswords(\n transport: Transport<*>,\n password: string,\n options: { type: string }\n) {\n const { type } = {\n type: \"instant\",\n ...options,\n };\n\n if (!(type in passwordType)) {\n throw new Error(\"btc.setPasswords invalid type=\" + type);\n }\n\n const data = password.toString(\"hex\");\n\n const p1 = passwordType[type];\n const p2 = 0;\n const response = await transport.send(0xe0, 0xD8, p1, p2, data);\n\n return { response };\n}\n"],"file":"setPasswords.js"}
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.setPasswords = setPasswords;
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
const passwordType = {
instant: 0,
recovery: 1
};
async function setPasswords(transport, password, options) {
const {
type
} = _objectSpread({
type: "instant"
}, options);
if (!(type in passwordType)) {
throw new Error("btc.setPasswords invalid type=" + type);
}
const data = password.toString("hex");
const p1 = passwordType[type];
const p2 = 0;
const response = await transport.send(0xe0, 0xD8, p1, p2, data);
return {
response
};
}
//# sourceMappingURL=setPasswords.js.map

Sorry, the diff of this file is not supported yet

{"version":3,"sources":["../src/setPasswords.js"],"names":["passwordType","instant","recovery","setPasswords","transport","password","options","type","Error","data","toString","p1","p2","response","send"],"mappings":";;;;;;;;;;;;;AAGA,MAAMA,YAAY,GAAG;AACjBC,EAAAA,OAAO,EAAE,CADQ;AAEjBC,EAAAA,QAAQ,EAAE;AAFO,CAArB;;AAKO,eAAeC,YAAf,CACHC,SADG,EAEHC,QAFG,EAGHC,OAHG,EAIL;AACE,QAAM;AAAEC,IAAAA;AAAF;AACFA,IAAAA,IAAI,EAAE;AADJ,KAECD,OAFD,CAAN;;AAKA,MAAI,EAAEC,IAAI,IAAIP,YAAV,CAAJ,EAA6B;AACzB,UAAM,IAAIQ,KAAJ,CAAU,mCAAmCD,IAA7C,CAAN;AACH;;AAED,QAAME,IAAI,GAAGJ,QAAQ,CAACK,QAAT,CAAkB,KAAlB,CAAb;AAEA,QAAMC,EAAE,GAAGX,YAAY,CAACO,IAAD,CAAvB;AACA,QAAMK,EAAE,GAAG,CAAX;AACA,QAAMC,QAAQ,GAAG,MAAMT,SAAS,CAACU,IAAV,CAAe,IAAf,EAAqB,IAArB,EAA2BH,EAA3B,EAA+BC,EAA/B,EAAmCH,IAAnC,CAAvB;AAEA,SAAO;AAAEI,IAAAA;AAAF,GAAP;AACH","sourcesContent":["// @flow\nimport type Transport from \"@ledgerhq/hw-transport\";\n\nconst passwordType = {\n instant: 0,\n recovery: 1,\n};\n\nexport async function setPasswords(\n transport: Transport<*>,\n password: string,\n options: { type: string }\n) {\n const { type } = {\n type: \"instant\",\n ...options,\n };\n\n if (!(type in passwordType)) {\n throw new Error(\"btc.setPasswords invalid type=\" + type);\n }\n\n const data = password.toString(\"hex\");\n\n const p1 = passwordType[type];\n const p2 = 0;\n const response = await transport.send(0xe0, 0xD8, p1, p2, data);\n\n return { response };\n}\n"],"file":"setPasswords.js"}

Sorry, the diff of this file is too big to display

+7
-0

@@ -9,2 +9,3 @@ import { signMessage } from "./signMessage";

import { serializeTransactionOutputs } from "./serializeTransaction";
import { setPasswords } from "./setPasswords";

@@ -67,2 +68,8 @@ /**

}
setPasswords(type, password) {
return setPasswords(this.transport, password, {
type: type
});
}
/**

@@ -69,0 +76,0 @@ * 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.

+1
-1

@@ -1,1 +0,1 @@

{"version":3,"sources":["../src/Btcv.js"],"names":["signMessage","getWalletPublicKey","splitTransaction","getTrustedInput","getTrustedInputBIP143","createTransaction","signP2SHTransaction","serializeTransactionOutputs","Btcv","constructor","transport","scrambleKey","decorateAppAPIMethods","path","opts","options","arguments","length","console","warn","verify","format","signMessageNew","messageHex","createPaymentTransactionNew","arg","fromDeprecateArguments","inputs","associatedKeysets","outputScriptHex","lockTime","sigHashType","segwit","transactionVersion","transactionHex","isSegwitSupported","hasTimestamp","hasExtraData","additionals","t","indexLookup","transaction","args","keys","obj","forEach","key","i","value","undefined"],"mappings":"AAEA,SAASA,WAAT,QAA4B,eAA5B;AACA,SAASC,kBAAT,QAAmC,sBAAnC;AAEA,SAASC,gBAAT,QAAiC,oBAAjC;AACA,SAASC,eAAT,QAAgC,mBAAhC;AACA,SAASC,qBAAT,QAAsC,yBAAtC;AAEA,SAASC,iBAAT,QAAkC,qBAAlC;AAEA,SAASC,mBAAT,QAAoC,uBAApC;AAEA,SAASC,2BAAT,QAA4C,wBAA5C;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,MAAMC,IAAN,CAAW;AAGxBC,EAAAA,WAAW,CAACC,SAAD,EAA0BC,WAAmB,GAAG,KAAhD,EAAuD;AAAA,SAFlED,SAEkE;AAChE,SAAKA,SAAL,GAAiBA,SAAjB;AACAA,IAAAA,SAAS,CAACE,qBAAV,CACE,IADF,EAEE,CACE,oBADF,EAEE,qBAFF,EAGE,gBAHF,EAIE,6BAJF,EAKE,iBALF,EAME,uBANF,CAFF,EAUED,WAVF;AAYD;A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EAKrBC,WALqB,CAAvB;AAOD;AAED;AACF;AACA;AACA;AACA;;;AACE/B,EAAAA,2BAA2B,CAACgC,CAAD,EAAyB;AAClD,WAAOhC,2BAA2B,CAACgC,CAAD,CAAlC;AACD;;AAEDpC,EAAAA,eAAe,CACbqC,WADa,EAEbC,WAFa,EAGbH,WAA0B,GAAG,EAHhB,EAII;AACjB,WAAOnC,eAAe,CACpB,KAAKO,SADe,EAEpB8B,WAFoB,EAGpBC,WAHoB,EAIpBH,WAJoB,CAAtB;AAMD;;AAEDlC,EAAAA,qBAAqB,CACnBoC,WADmB,EAEnBC,WAFmB,EAGnBH,WAA0B,GAAG,EAHV,EAIX;AACR,WAAOlC,qBAAqB,CAC1B,KAAKM,SADqB,EAE1B8B,WAF0B,EAG1BC,WAH0B,EAI1BH,WAJ0B,CAA5B;AAMD;;AArPuB;;AAwP1B,SAASZ,sBAAT,CAAgCgB,IAAhC,EAAsCC,IAAtC,EAA4C;AAC1C,QAAMC,GAAG,GAAG,EAAZ;AACAD,EAAAA,IAAI,CAACE,OAAL,CAAa,CAACC,GAAD,EAAMC,CAAN,KAAY;AACvB,UAAMC,KAAK,GAAGN,IAAI,CAACK,CAAD,CAAlB;;AACA,QAAIC,KAAK,KAAKC,SAAd,EAAyB;AACvBL,MAAAA,GAAG,CAACE,GAAD,CAAH,GAAWE,KAAX;AACD;AACF,GALD;AAMA,SAAOJ,GAAP;AACD","sourcesContent":["//@flow\nimport type Transport from \"@ledgerhq/hw-transport\";\nimport { signMessage } from \"./signMessage\";\nimport { getWalletPublicKey } from \"./getWalletPublicKey\";\nimport type { AddressFormat } from \"./getWalletPublicKey\";\nimport { splitTransaction } from \"./splitTransaction\";\nimport { getTrustedInput } from \"./getTrustedInput\";\nimport { getTrustedInputBIP143 } from \"./getTrustedInputBIP143\";\nimport type { Transaction } from \"./types\";\nimport { createTransaction } from \"./createTransaction\";\nimport type { CreateTransactionArg } from \"./createTransaction\";\nimport { signP2SHTransaction } from \"./signP2SHTransaction\";\nimport type { SignP2SHTransactionArg } from \"./signP2SHTransaction\";\nimport { serializeTransactionOutputs } from \"./serializeTransaction\";\n\nexport type { AddressFormat };\n\n/**\n * Bitcoin API.\n *\n * @example\n * TODO: import Btcv from \"@codewarriorr/hw-app-btcv\";\n * const btcv = new Btcv(transport)\n */\nexport default class Btcv {\n transport: Transport<*>;\n\n constructor(transport: Transport<*>, scrambleKey: string = \"BTC\") {\n this.transport = transport;\n transport.decorateAppAPIMethods(\n this,\n [\n \"getWalletPublicKey\",\n \"signP2SHTransaction\",\n \"signMessageNew\",\n \"createPaymentTransactionNew\",\n \"getTrustedInput\",\n \"getTrustedInputBIP143\",\n ],\n scrambleKey\n );\n }\n\n /**\n * @param path a BIP 32 path\n * @param options an object with optional these fields:\n *\n * - verify (boolean) will ask user to confirm the address on the device\n *\n * TODO: remove cashaddr\n * - format (\"legacy\" | \"p2sh\" | \"bech32\" | \"cashaddr\") to use different bitcoin address formatter.\n *\n * NB The normal usage is to use:\n *\n * - legacy format with 44' paths\n *\n * - p2sh format with 49' paths\n *\n * - bech32 format with 173' paths\n *\n * TODO: remove cashaddr\n * - cashaddr in case of Bitcoin Cash\n *\n * @example\n * btc.getWalletPublicKey(\"44'/0'/0'/0/0\").then(o => o.bitcoinAddress)\n * btc.getWalletPublicKey(\"49'/0'/0'/0/0\", { format: \"p2sh\" }).then(o => o.bitcoinAddress)\n */\n getWalletPublicKey(\n path: string,\n opts?: boolean | { verify?: boolean, format?: AddressFormat }\n ): Promise<{\n publicKey: string,\n bitcoinAddress: string,\n chainCode: string,\n }> {\n let options;\n if (arguments.length > 2 || typeof opts === \"boolean\") {\n console.warn(\n \"btc.getWalletPublicKey deprecated signature used. Please switch to getWalletPublicKey(path, { format, verify })\"\n );\n options = {\n verify: !!opts,\n format: arguments[2] ? \"p2sh\" : \"legacy\",\n };\n } else {\n options = opts || {};\n }\n return getWalletPublicKey(this.transport, { ...options, path });\n }\n\n /**\n * 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.\n * @example\n btc.signMessageNew_async(\"44'/60'/0'/0'/0\", Buffer.from(\"test\").toString(\"hex\")).then(function(result) {\n var v = result['v'] + 27 + 4;\n var signature = Buffer.from(v.toString(16) + result['r'] + result['s'], 'hex').toString('base64');\n console.log(\"Signature : \" + signature);\n }).catch(function(ex) {console.log(ex);});\n */\n signMessageNew(\n path: string,\n messageHex: string\n ): Promise<{ v: number, r: string, s: string }> {\n return signMessage(this.transport, { path, messageHex });\n }\n\n /**\n * To sign a transaction involving standard (P2PKH) inputs, call createTransaction with the following parameters\n * @param inputs is an array of [ transaction, output_index, optional redeem script, optional sequence ] where\n *\n * * transaction is the previously computed transaction object for this UTXO\n * * output_index is the output in the transaction used as input for this UTXO (counting from 0)\n * * redeem script is the optional redeem script to use when consuming a Segregated Witness input\n * * sequence is the sequence number to use for this input (when using RBF), or non present\n * @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO\n * @param changePath is an optional BIP 32 path pointing to the path to the public key used to compute the change address\n * @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign\n * @param lockTime is the optional lockTime of the transaction to sign, or default (0)\n * @param sigHashType is the hash type of the transaction to sign, or default (all)\n * @param segwit is an optional boolean indicating wether to use segwit or not\n * @param initialTimestamp is an optional timestamp of the function call to use for coins that necessitate timestamps only, (not the one that the tx will include)\n * @param additionals list of additionnal options\n *\n * - \"bech32\" for spending native segwit outputs\n * - \"abc\" for bch\n * - \"gold\" for btg\n * - \"bipxxx\" for using BIPxxx\n * - \"sapling\" to indicate a zec transaction is supporting sapling (to be set over block 419200)\n * @param expiryHeight is an optional Buffer for zec overwinter / sapling Txs\n * @param useTrustedInputForSegwit trust inputs for segwit transactions\n * @return the signed transaction ready to be broadcast\n * @example\nbtc.createTransaction({\n inputs: [ [tx1, 1] ],\n associatedKeysets: [\"0'/0/0\"],\n outputScriptHex: \"01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac\"\n}).then(res => ...);\n */\n createPaymentTransactionNew(arg: CreateTransactionArg) {\n if (arguments.length > 1) {\n console.warn(\n \"@ledgerhq/hw-app-btc: createPaymentTransactionNew multi argument signature is deprecated. please switch to named parameters.\"\n );\n arg = fromDeprecateArguments(arguments, [\n \"inputs\",\n \"associatedKeysets\",\n \"changePath\",\n \"outputScriptHex\",\n \"lockTime\",\n \"sigHashType\",\n \"segwit\",\n \"initialTimestamp\",\n \"additionals\",\n \"expiryHeight\",\n \"useTrustedInputForSegwit\",\n ]);\n }\n return createTransaction(this.transport, arg);\n }\n\n /**\n * To obtain the signature of multisignature (P2SH) inputs, call signP2SHTransaction_async with the folowing parameters\n * @param inputs is an array of [ transaction, output_index, redeem script, optional sequence ] where\n * * transaction is the previously computed transaction object for this UTXO\n * * output_index is the output in the transaction used as input for this UTXO (counting from 0)\n * * redeem script is the mandatory redeem script associated to the current P2SH input\n * * sequence is the sequence number to use for this input (when using RBF), or non present\n * @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO\n * @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign\n * @param lockTime is the optional lockTime of the transaction to sign, or default (0)\n * @param sigHashType is the hash type of the transaction to sign, or default (all)\n * @return the signed transaction ready to be broadcast\n * @example\nbtc.signP2SHTransaction({\n inputs: [ [tx, 1, \"52210289b4a3ad52a919abd2bdd6920d8a6879b1e788c38aa76f0440a6f32a9f1996d02103a3393b1439d1693b063482c04bd40142db97bdf139eedd1b51ffb7070a37eac321030b9a409a1e476b0d5d17b804fcdb81cf30f9b99c6f3ae1178206e08bc500639853ae\"] ],\n associatedKeysets: [\"0'/0/0\"],\n outputScriptHex: \"01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac\"\n}).then(result => ...);\n */\n signP2SHTransaction(arg: SignP2SHTransactionArg) {\n if (arguments.length > 1) {\n console.warn(\n \"@ledgerhq/hw-app-btc: signP2SHTransaction multi argument signature is deprecated. please switch to named parameters.\"\n );\n const [\n inputs,\n associatedKeysets,\n outputScriptHex,\n lockTime,\n sigHashType,\n segwit,\n transactionVersion,\n ] = arguments;\n arg = {\n inputs,\n associatedKeysets,\n outputScriptHex,\n lockTime,\n sigHashType,\n segwit,\n transactionVersion,\n };\n arg = fromDeprecateArguments(arguments, [\n \"inputs\",\n \"associatedKeysets\",\n \"outputScriptHex\",\n \"lockTime\",\n \"sigHashType\",\n \"segwit\",\n \"transactionVersion\",\n ]);\n }\n return signP2SHTransaction(this.transport, arg);\n }\n\n /**\n * For each UTXO included in your transaction, create a transaction object from the raw serialized version of the transaction used in this UTXO.\n * @example\nconst tx1 = btc.splitTransaction(\"01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000\");\n */\n splitTransaction(\n transactionHex: string,\n isSegwitSupported: ?boolean = false,\n hasTimestamp: boolean = false,\n hasExtraData: boolean = false,\n additionals: Array<string> = []\n ): Transaction {\n return splitTransaction(\n transactionHex,\n isSegwitSupported,\n hasTimestamp,\n hasExtraData,\n additionals\n );\n }\n\n /**\n @example\nconst tx1 = btc.splitTransaction(\"01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000\");\nconst outputScript = btc.serializeTransactionOutputs(tx1).toString('hex');\n */\n serializeTransactionOutputs(t: Transaction): Buffer {\n return serializeTransactionOutputs(t);\n }\n\n getTrustedInput(\n indexLookup: number,\n transaction: Transaction,\n additionals: Array<string> = []\n ): Promise<string> {\n return getTrustedInput(\n this.transport,\n indexLookup,\n transaction,\n additionals\n );\n }\n\n getTrustedInputBIP143(\n indexLookup: number,\n transaction: Transaction,\n additionals: Array<string> = []\n ): string {\n return getTrustedInputBIP143(\n this.transport,\n indexLookup,\n transaction,\n additionals\n );\n }\n}\n\nfunction fromDeprecateArguments(args, keys) {\n const obj = {};\n keys.forEach((key, i) => {\n const value = args[i];\n if (value !== undefined) {\n obj[key] = value;\n }\n });\n return obj;\n}\n"],"file":"Btcv.js"}
{"version":3,"sources":["../src/Btcv.js"],"names":["signMessage","getWalletPublicKey","splitTransaction","getTrustedInput","getTrustedInputBIP143","createTransaction","signP2SHTransaction","serializeTransactionOutputs","setPasswords","Btcv","constructor","transport","scrambleKey","decorateAppAPIMethods","path","opts","options","arguments","length","console","warn","verify","format","type","password","signMessageNew","messageHex","createPaymentTransactionNew","arg","fromDeprecateArguments","inputs","associatedKeysets","outputScriptHex","lockTime","sigHashType","segwit","transactionVersion","transactionHex","isSegwitSupported","hasTimestamp","hasExtraData","additionals","t","indexLookup","transaction","args","keys","obj","forEach","key","i","value","undefined"],"mappings":"AAEA,SAASA,WAAT,QAA4B,eAA5B;AACA,SAASC,kBAAT,QAAmC,sBAAnC;AAEA,SAASC,gBAAT,QAAiC,oBAAjC;AACA,SAASC,eAAT,QAAgC,mBAAhC;AACA,SAASC,qBAAT,QAAsC,yBAAtC;AAEA,SAASC,iBAAT,QAAkC,qBAAlC;AAEA,SAASC,mBAAT,QAAoC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IAAI,CAACE,OAAL,CAAa,CAACC,GAAD,EAAMC,CAAN,KAAY;AACvB,UAAMC,KAAK,GAAGN,IAAI,CAACK,CAAD,CAAlB;;AACA,QAAIC,KAAK,KAAKC,SAAd,EAAyB;AACvBL,MAAAA,GAAG,CAACE,GAAD,CAAH,GAAWE,KAAX;AACD;AACF,GALD;AAMA,SAAOJ,GAAP;AACD","sourcesContent":["//@flow\nimport type Transport from \"@ledgerhq/hw-transport\";\nimport { signMessage } from \"./signMessage\";\nimport { getWalletPublicKey } from \"./getWalletPublicKey\";\nimport type { AddressFormat } from \"./getWalletPublicKey\";\nimport { splitTransaction } from \"./splitTransaction\";\nimport { getTrustedInput } from \"./getTrustedInput\";\nimport { getTrustedInputBIP143 } from \"./getTrustedInputBIP143\";\nimport type { Transaction } from \"./types\";\nimport { createTransaction } from \"./createTransaction\";\nimport type { CreateTransactionArg } from \"./createTransaction\";\nimport { signP2SHTransaction } from \"./signP2SHTransaction\";\nimport type { SignP2SHTransactionArg } from \"./signP2SHTransaction\";\nimport { serializeTransactionOutputs } from \"./serializeTransaction\";\nimport {setPasswords} from \"./setPasswords\";\n\nexport type { AddressFormat };\n\n/**\n * Bitcoin API.\n *\n * @example\n * TODO: import Btcv from \"@codewarriorr/hw-app-btcv\";\n * const btcv = new Btcv(transport)\n */\nexport default class Btcv {\n transport: Transport<*>;\n\n constructor(transport: Transport<*>, scrambleKey: string = \"BTC\") {\n this.transport = transport;\n transport.decorateAppAPIMethods(\n this,\n [\n \"getWalletPublicKey\",\n \"signP2SHTransaction\",\n \"signMessageNew\",\n \"createPaymentTransactionNew\",\n \"getTrustedInput\",\n \"getTrustedInputBIP143\",\n ],\n scrambleKey\n );\n }\n\n /**\n * @param path a BIP 32 path\n * @param options an object with optional these fields:\n *\n * - verify (boolean) will ask user to confirm the address on the device\n *\n * TODO: remove cashaddr\n * - format (\"legacy\" | \"p2sh\" | \"bech32\" | \"cashaddr\") to use different bitcoin address formatter.\n *\n * NB The normal usage is to use:\n *\n * - legacy format with 44' paths\n *\n * - p2sh format with 49' paths\n *\n * - bech32 format with 173' paths\n *\n * TODO: remove cashaddr\n * - cashaddr in case of Bitcoin Cash\n *\n * @example\n * btc.getWalletPublicKey(\"44'/0'/0'/0/0\").then(o => o.bitcoinAddress)\n * btc.getWalletPublicKey(\"49'/0'/0'/0/0\", { format: \"p2sh\" }).then(o => o.bitcoinAddress)\n */\n getWalletPublicKey(\n path: string,\n opts?: boolean | { verify?: boolean, format?: AddressFormat }\n ): Promise<{\n publicKey: string,\n bitcoinAddress: string,\n chainCode: string,\n }> {\n let options;\n if (arguments.length > 2 || typeof opts === \"boolean\") {\n console.warn(\n \"btc.getWalletPublicKey deprecated signature used. Please switch to getWalletPublicKey(path, { format, verify })\"\n );\n options = {\n verify: !!opts,\n format: arguments[2] ? \"p2sh\" : \"legacy\",\n };\n } else {\n options = opts || {};\n }\n return getWalletPublicKey(this.transport, { ...options, path });\n }\n\n setPasswords(type: string, password: string) {\n return setPasswords(this.transport, password, { type: type });\n }\n\n /**\n * 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.\n * @example\n btc.signMessageNew_async(\"44'/60'/0'/0'/0\", Buffer.from(\"test\").toString(\"hex\")).then(function(result) {\n var v = result['v'] + 27 + 4;\n var signature = Buffer.from(v.toString(16) + result['r'] + result['s'], 'hex').toString('base64');\n console.log(\"Signature : \" + signature);\n }).catch(function(ex) {console.log(ex);});\n */\n signMessageNew(\n path: string,\n messageHex: string\n ): Promise<{ v: number, r: string, s: string }> {\n return signMessage(this.transport, { path, messageHex });\n }\n\n /**\n * To sign a transaction involving standard (P2PKH) inputs, call createTransaction with the following parameters\n * @param inputs is an array of [ transaction, output_index, optional redeem script, optional sequence ] where\n *\n * * transaction is the previously computed transaction object for this UTXO\n * * output_index is the output in the transaction used as input for this UTXO (counting from 0)\n * * redeem script is the optional redeem script to use when consuming a Segregated Witness input\n * * sequence is the sequence number to use for this input (when using RBF), or non present\n * @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO\n * @param changePath is an optional BIP 32 path pointing to the path to the public key used to compute the change address\n * @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign\n * @param lockTime is the optional lockTime of the transaction to sign, or default (0)\n * @param sigHashType is the hash type of the transaction to sign, or default (all)\n * @param segwit is an optional boolean indicating wether to use segwit or not\n * @param initialTimestamp is an optional timestamp of the function call to use for coins that necessitate timestamps only, (not the one that the tx will include)\n * @param additionals list of additionnal options\n *\n * - \"bech32\" for spending native segwit outputs\n * - \"abc\" for bch\n * - \"gold\" for btg\n * - \"bipxxx\" for using BIPxxx\n * - \"sapling\" to indicate a zec transaction is supporting sapling (to be set over block 419200)\n * @param expiryHeight is an optional Buffer for zec overwinter / sapling Txs\n * @param useTrustedInputForSegwit trust inputs for segwit transactions\n * @return the signed transaction ready to be broadcast\n * @example\nbtc.createTransaction({\n inputs: [ [tx1, 1] ],\n associatedKeysets: [\"0'/0/0\"],\n outputScriptHex: \"01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac\"\n}).then(res => ...);\n */\n createPaymentTransactionNew(arg: CreateTransactionArg) {\n if (arguments.length > 1) {\n console.warn(\n \"@ledgerhq/hw-app-btc: createPaymentTransactionNew multi argument signature is deprecated. please switch to named parameters.\"\n );\n arg = fromDeprecateArguments(arguments, [\n \"inputs\",\n \"associatedKeysets\",\n \"changePath\",\n \"outputScriptHex\",\n \"lockTime\",\n \"sigHashType\",\n \"segwit\",\n \"initialTimestamp\",\n \"additionals\",\n \"expiryHeight\",\n \"useTrustedInputForSegwit\",\n ]);\n }\n return createTransaction(this.transport, arg);\n }\n\n /**\n * To obtain the signature of multisignature (P2SH) inputs, call signP2SHTransaction_async with the folowing parameters\n * @param inputs is an array of [ transaction, output_index, redeem script, optional sequence ] where\n * * transaction is the previously computed transaction object for this UTXO\n * * output_index is the output in the transaction used as input for this UTXO (counting from 0)\n * * redeem script is the mandatory redeem script associated to the current P2SH input\n * * sequence is the sequence number to use for this input (when using RBF), or non present\n * @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO\n * @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign\n * @param lockTime is the optional lockTime of the transaction to sign, or default (0)\n * @param sigHashType is the hash type of the transaction to sign, or default (all)\n * @return the signed transaction ready to be broadcast\n * @example\nbtc.signP2SHTransaction({\n inputs: [ [tx, 1, \"52210289b4a3ad52a919abd2bdd6920d8a6879b1e788c38aa76f0440a6f32a9f1996d02103a3393b1439d1693b063482c04bd40142db97bdf139eedd1b51ffb7070a37eac321030b9a409a1e476b0d5d17b804fcdb81cf30f9b99c6f3ae1178206e08bc500639853ae\"] ],\n associatedKeysets: [\"0'/0/0\"],\n outputScriptHex: \"01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac\"\n}).then(result => ...);\n */\n signP2SHTransaction(arg: SignP2SHTransactionArg) {\n if (arguments.length > 1) {\n console.warn(\n \"@ledgerhq/hw-app-btc: signP2SHTransaction multi argument signature is deprecated. please switch to named parameters.\"\n );\n const [\n inputs,\n associatedKeysets,\n outputScriptHex,\n lockTime,\n sigHashType,\n segwit,\n transactionVersion,\n ] = arguments;\n arg = {\n inputs,\n associatedKeysets,\n outputScriptHex,\n lockTime,\n sigHashType,\n segwit,\n transactionVersion,\n };\n arg = fromDeprecateArguments(arguments, [\n \"inputs\",\n \"associatedKeysets\",\n \"outputScriptHex\",\n \"lockTime\",\n \"sigHashType\",\n \"segwit\",\n \"transactionVersion\",\n ]);\n }\n return signP2SHTransaction(this.transport, arg);\n }\n\n /**\n * For each UTXO included in your transaction, create a transaction object from the raw serialized version of the transaction used in this UTXO.\n * @example\nconst tx1 = btc.splitTransaction(\"01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000\");\n */\n splitTransaction(\n transactionHex: string,\n isSegwitSupported: ?boolean = false,\n hasTimestamp: boolean = false,\n hasExtraData: boolean = false,\n additionals: Array<string> = []\n ): Transaction {\n return splitTransaction(\n transactionHex,\n isSegwitSupported,\n hasTimestamp,\n hasExtraData,\n additionals\n );\n }\n\n /**\n @example\nconst tx1 = btc.splitTransaction(\"01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000\");\nconst outputScript = btc.serializeTransactionOutputs(tx1).toString('hex');\n */\n serializeTransactionOutputs(t: Transaction): Buffer {\n return serializeTransactionOutputs(t);\n }\n\n getTrustedInput(\n indexLookup: number,\n transaction: Transaction,\n additionals: Array<string> = []\n ): Promise<string> {\n return getTrustedInput(\n this.transport,\n indexLookup,\n transaction,\n additionals\n );\n }\n\n getTrustedInputBIP143(\n indexLookup: number,\n transaction: Transaction,\n additionals: Array<string> = []\n ): string {\n return getTrustedInputBIP143(\n this.transport,\n indexLookup,\n transaction,\n additionals\n );\n }\n}\n\nfunction fromDeprecateArguments(args, keys) {\n const obj = {};\n keys.forEach((key, i) => {\n const value = args[i];\n if (value !== undefined) {\n obj[key] = value;\n }\n });\n return obj;\n}\n"],"file":"Btcv.js"}

@@ -24,2 +24,4 @@ "use strict";

var _setPasswords = require("./setPasswords");
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

@@ -87,2 +89,8 @@

}
setPasswords(type, password) {
return (0, _setPasswords.setPasswords)(this.transport, password, {
type: type
});
}
/**

@@ -89,0 +97,0 @@ * 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.

@@ -1,1 +0,1 @@

{"version":3,"sources":["../src/Btcv.js"],"names":["Btcv","constructor","transport","scrambleKey","decorateAppAPIMethods","getWalletPublicKey","path","opts","options","arguments","length","console","warn","verify","format","signMessageNew","messageHex","createPaymentTransactionNew","arg","fromDeprecateArguments","signP2SHTransaction","inputs","associatedKeysets","outputScriptHex","lockTime","sigHashType","segwit","transactionVersion","splitTransaction","transactionHex","isSegwitSupported","hasTimestamp","hasExtraData","additionals","serializeTransactionOutputs","t","getTrustedInput","indexLookup","transaction","getTrustedInputBIP143","args","keys","obj","forEach","key","i","value","undefined"],"mappings":";;;;;;;AAEA;;AACA;;AAEA;;AACA;;AACA;;AAEA;;AAEA;;AAEA;;;;;;;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,MAAMA,IAAN,CAAW;AAGxBC,EAAAA,WAAW,CAACC,SAAD,EAA0BC,WAAmB,GAAG,KAAhD,EAAuD;AAAA,SAFlED,SAEkE;AAChE,SAAKA,SAAL,GAAiBA,SAAjB;AACAA,IAAAA,SAAS,CAACE,qBAAV,CACE,IADF,EAEE,CACE,oBADF,EAEE,qBAFF,EAGE,gBAHF,EAIE,6BAJF,EAKE,iBALF,EAME,uBANF,CAFF,EAUED,WAVF;AAYD;AAED;AAC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ACC,CAAD,EAAyB;AAClD,WAAO,uDAA4BA,CAA5B,CAAP;AACD;;AAEDC,EAAAA,eAAe,CACbC,WADa,EAEbC,WAFa,EAGbL,WAA0B,GAAG,EAHhB,EAII;AACjB,WAAO,sCACL,KAAK/B,SADA,EAELmC,WAFK,EAGLC,WAHK,EAILL,WAJK,CAAP;AAMD;;AAEDM,EAAAA,qBAAqB,CACnBF,WADmB,EAEnBC,WAFmB,EAGnBL,WAA0B,GAAG,EAHV,EAIX;AACR,WAAO,+CACL,KAAK/B,SADA,EAELmC,WAFK,EAGLC,WAHK,EAILL,WAJK,CAAP;AAMD;;AArPuB;;;;AAwP1B,SAASd,sBAAT,CAAgCqB,IAAhC,EAAsCC,IAAtC,EAA4C;AAC1C,QAAMC,GAAG,GAAG,EAAZ;AACAD,EAAAA,IAAI,CAACE,OAAL,CAAa,CAACC,GAAD,EAAMC,CAAN,KAAY;AACvB,UAAMC,KAAK,GAAGN,IAAI,CAACK,CAAD,CAAlB;;AACA,QAAIC,KAAK,KAAKC,SAAd,EAAyB;AACvBL,MAAAA,GAAG,CAACE,GAAD,CAAH,GAAWE,KAAX;AACD;AACF,GALD;AAMA,SAAOJ,GAAP;AACD","sourcesContent":["//@flow\nimport type Transport from \"@ledgerhq/hw-transport\";\nimport { signMessage } from \"./signMessage\";\nimport { getWalletPublicKey } from \"./getWalletPublicKey\";\nimport type { AddressFormat } from \"./getWalletPublicKey\";\nimport { splitTransaction } from \"./splitTransaction\";\nimport { getTrustedInput } from \"./getTrustedInput\";\nimport { getTrustedInputBIP143 } from \"./getTrustedInputBIP143\";\nimport type { Transaction } from \"./types\";\nimport { createTransaction } from \"./createTransaction\";\nimport type { CreateTransactionArg } from \"./createTransaction\";\nimport { signP2SHTransaction } from \"./signP2SHTransaction\";\nimport type { SignP2SHTransactionArg } from \"./signP2SHTransaction\";\nimport { serializeTransactionOutputs } from \"./serializeTransaction\";\n\nexport type { AddressFormat };\n\n/**\n * Bitcoin API.\n *\n * @example\n * TODO: import Btcv from \"@codewarriorr/hw-app-btcv\";\n * const btcv = new Btcv(transport)\n */\nexport default class Btcv {\n transport: Transport<*>;\n\n constructor(transport: Transport<*>, scrambleKey: string = \"BTC\") {\n this.transport = transport;\n transport.decorateAppAPIMethods(\n this,\n [\n \"getWalletPublicKey\",\n \"signP2SHTransaction\",\n \"signMessageNew\",\n \"createPaymentTransactionNew\",\n \"getTrustedInput\",\n \"getTrustedInputBIP143\",\n ],\n scrambleKey\n );\n }\n\n /**\n * @param path a BIP 32 path\n * @param options an object with optional these fields:\n *\n * - verify (boolean) will ask user to confirm the address on the device\n *\n * TODO: remove cashaddr\n * - format (\"legacy\" | \"p2sh\" | \"bech32\" | \"cashaddr\") to use different bitcoin address formatter.\n *\n * NB The normal usage is to use:\n *\n * - legacy format with 44' paths\n *\n * - p2sh format with 49' paths\n *\n * - bech32 format with 173' paths\n *\n * TODO: remove cashaddr\n * - cashaddr in case of Bitcoin Cash\n *\n * @example\n * btc.getWalletPublicKey(\"44'/0'/0'/0/0\").then(o => o.bitcoinAddress)\n * btc.getWalletPublicKey(\"49'/0'/0'/0/0\", { format: \"p2sh\" }).then(o => o.bitcoinAddress)\n */\n getWalletPublicKey(\n path: string,\n opts?: boolean | { verify?: boolean, format?: AddressFormat }\n ): Promise<{\n publicKey: string,\n bitcoinAddress: string,\n chainCode: string,\n }> {\n let options;\n if (arguments.length > 2 || typeof opts === \"boolean\") {\n console.warn(\n \"btc.getWalletPublicKey deprecated signature used. Please switch to getWalletPublicKey(path, { format, verify })\"\n );\n options = {\n verify: !!opts,\n format: arguments[2] ? \"p2sh\" : \"legacy\",\n };\n } else {\n options = opts || {};\n }\n return getWalletPublicKey(this.transport, { ...options, path });\n }\n\n /**\n * 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.\n * @example\n btc.signMessageNew_async(\"44'/60'/0'/0'/0\", Buffer.from(\"test\").toString(\"hex\")).then(function(result) {\n var v = result['v'] + 27 + 4;\n var signature = Buffer.from(v.toString(16) + result['r'] + result['s'], 'hex').toString('base64');\n console.log(\"Signature : \" + signature);\n }).catch(function(ex) {console.log(ex);});\n */\n signMessageNew(\n path: string,\n messageHex: string\n ): Promise<{ v: number, r: string, s: string }> {\n return signMessage(this.transport, { path, messageHex });\n }\n\n /**\n * To sign a transaction involving standard (P2PKH) inputs, call createTransaction with the following parameters\n * @param inputs is an array of [ transaction, output_index, optional redeem script, optional sequence ] where\n *\n * * transaction is the previously computed transaction object for this UTXO\n * * output_index is the output in the transaction used as input for this UTXO (counting from 0)\n * * redeem script is the optional redeem script to use when consuming a Segregated Witness input\n * * sequence is the sequence number to use for this input (when using RBF), or non present\n * @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO\n * @param changePath is an optional BIP 32 path pointing to the path to the public key used to compute the change address\n * @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign\n * @param lockTime is the optional lockTime of the transaction to sign, or default (0)\n * @param sigHashType is the hash type of the transaction to sign, or default (all)\n * @param segwit is an optional boolean indicating wether to use segwit or not\n * @param initialTimestamp is an optional timestamp of the function call to use for coins that necessitate timestamps only, (not the one that the tx will include)\n * @param additionals list of additionnal options\n *\n * - \"bech32\" for spending native segwit outputs\n * - \"abc\" for bch\n * - \"gold\" for btg\n * - \"bipxxx\" for using BIPxxx\n * - \"sapling\" to indicate a zec transaction is supporting sapling (to be set over block 419200)\n * @param expiryHeight is an optional Buffer for zec overwinter / sapling Txs\n * @param useTrustedInputForSegwit trust inputs for segwit transactions\n * @return the signed transaction ready to be broadcast\n * @example\nbtc.createTransaction({\n inputs: [ [tx1, 1] ],\n associatedKeysets: [\"0'/0/0\"],\n outputScriptHex: \"01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac\"\n}).then(res => ...);\n */\n createPaymentTransactionNew(arg: CreateTransactionArg) {\n if (arguments.length > 1) {\n console.warn(\n \"@ledgerhq/hw-app-btc: createPaymentTransactionNew multi argument signature is deprecated. please switch to named parameters.\"\n );\n arg = fromDeprecateArguments(arguments, [\n \"inputs\",\n \"associatedKeysets\",\n \"changePath\",\n \"outputScriptHex\",\n \"lockTime\",\n \"sigHashType\",\n \"segwit\",\n \"initialTimestamp\",\n \"additionals\",\n \"expiryHeight\",\n \"useTrustedInputForSegwit\",\n ]);\n }\n return createTransaction(this.transport, arg);\n }\n\n /**\n * To obtain the signature of multisignature (P2SH) inputs, call signP2SHTransaction_async with the folowing parameters\n * @param inputs is an array of [ transaction, output_index, redeem script, optional sequence ] where\n * * transaction is the previously computed transaction object for this UTXO\n * * output_index is the output in the transaction used as input for this UTXO (counting from 0)\n * * redeem script is the mandatory redeem script associated to the current P2SH input\n * * sequence is the sequence number to use for this input (when using RBF), or non present\n * @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO\n * @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign\n * @param lockTime is the optional lockTime of the transaction to sign, or default (0)\n * @param sigHashType is the hash type of the transaction to sign, or default (all)\n * @return the signed transaction ready to be broadcast\n * @example\nbtc.signP2SHTransaction({\n inputs: [ [tx, 1, \"52210289b4a3ad52a919abd2bdd6920d8a6879b1e788c38aa76f0440a6f32a9f1996d02103a3393b1439d1693b063482c04bd40142db97bdf139eedd1b51ffb7070a37eac321030b9a409a1e476b0d5d17b804fcdb81cf30f9b99c6f3ae1178206e08bc500639853ae\"] ],\n associatedKeysets: [\"0'/0/0\"],\n outputScriptHex: \"01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac\"\n}).then(result => ...);\n */\n signP2SHTransaction(arg: SignP2SHTransactionArg) {\n if (arguments.length > 1) {\n console.warn(\n \"@ledgerhq/hw-app-btc: signP2SHTransaction multi argument signature is deprecated. please switch to named parameters.\"\n );\n const [\n inputs,\n associatedKeysets,\n outputScriptHex,\n lockTime,\n sigHashType,\n segwit,\n transactionVersion,\n ] = arguments;\n arg = {\n inputs,\n associatedKeysets,\n outputScriptHex,\n lockTime,\n sigHashType,\n segwit,\n transactionVersion,\n };\n arg = fromDeprecateArguments(arguments, [\n \"inputs\",\n \"associatedKeysets\",\n \"outputScriptHex\",\n \"lockTime\",\n \"sigHashType\",\n \"segwit\",\n \"transactionVersion\",\n ]);\n }\n return signP2SHTransaction(this.transport, arg);\n }\n\n /**\n * For each UTXO included in your transaction, create a transaction object from the raw serialized version of the transaction used in this UTXO.\n * @example\nconst tx1 = btc.splitTransaction(\"01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000\");\n */\n splitTransaction(\n transactionHex: string,\n isSegwitSupported: ?boolean = false,\n hasTimestamp: boolean = false,\n hasExtraData: boolean = false,\n additionals: Array<string> = []\n ): Transaction {\n return splitTransaction(\n transactionHex,\n isSegwitSupported,\n hasTimestamp,\n hasExtraData,\n additionals\n );\n }\n\n /**\n @example\nconst tx1 = btc.splitTransaction(\"01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000\");\nconst outputScript = btc.serializeTransactionOutputs(tx1).toString('hex');\n */\n serializeTransactionOutputs(t: Transaction): Buffer {\n return serializeTransactionOutputs(t);\n }\n\n getTrustedInput(\n indexLookup: number,\n transaction: Transaction,\n additionals: Array<string> = []\n ): Promise<string> {\n return getTrustedInput(\n this.transport,\n indexLookup,\n transaction,\n additionals\n );\n }\n\n getTrustedInputBIP143(\n indexLookup: number,\n transaction: Transaction,\n additionals: Array<string> = []\n ): string {\n return getTrustedInputBIP143(\n this.transport,\n indexLookup,\n transaction,\n additionals\n );\n }\n}\n\nfunction fromDeprecateArguments(args, keys) {\n const obj = {};\n keys.forEach((key, i) => {\n const value = args[i];\n if (value !== undefined) {\n obj[key] = value;\n }\n });\n return obj;\n}\n"],"file":"Btcv.js"}
{"version":3,"sources":["../src/Btcv.js"],"names":["Btcv","constructor","transport","scrambleKey","decorateAppAPIMethods","getWalletPublicKey","path","opts","options","arguments","length","console","warn","verify","format","setPasswords","type","password","signMessageNew","messageHex","createPaymentTransactionNew","arg","fromDeprecateArguments","signP2SHTransaction","inputs","associatedKeysets","outputScriptHex","lockTime","sigHashType","segwit","transactionVersion","splitTransaction","transactionHex","isSegwitSupported","hasTimestamp","hasExtraData","additionals","serializeTransactionOutputs","t","getTrustedInput","indexLookup","transaction","getTrustedInputBIP143","args","keys","obj","forEach","key","i","value","undefined"],"mappings":";;;;;;;AAEA;;AACA;;AAEA;;AACA;;AACA;;AAEA;;AAEA;;AAEA;;AACA;;;;;;;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,MAAMA,IAAN,CAAW;AAGxBC,EAAAA,WAAW,CAACC,SAAD,EAA0BC,WAAmB,GAAG,KAAhD,EAAuD;AAAA,SAFlED,SAEkE;AAChE,SAAKA,SAAL,GAAiBA,SAAjB;AACAA,IAAAA,SAAS,CAACE,qBAAV,CACE,IADF,EAEE,CACE,oBADF,EAEE,qBAFF,EAGE,gBAHF,EAIE,6BAJF,EAKE,iBALF,EAME,u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AG,KAHV,EAIdC,YAAqB,GAAG,KAJV,EAKdC,WAA0B,GAAG,EALf,EAMD;AACb,WAAO,wCACLJ,cADK,EAELC,iBAFK,EAGLC,YAHK,EAILC,YAJK,EAKLC,WALK,CAAP;AAOD;AAED;AACF;AACA;AACA;AACA;;;AACEC,EAAAA,2BAA2B,CAACC,CAAD,EAAyB;AAClD,WAAO,uDAA4BA,CAA5B,CAAP;AACD;;AAEDC,EAAAA,eAAe,CACbC,WADa,EAEbC,WAFa,EAGbL,WAA0B,GAAG,EAHhB,EAII;AACjB,WAAO,sCACL,KAAKlC,SADA,EAELsC,WAFK,EAGLC,WAHK,EAILL,WAJK,CAAP;AAMD;;AAEDM,EAAAA,qBAAqB,CACnBF,WADmB,EAEnBC,WAFmB,EAGnBL,WAA0B,GAAG,EAHV,EAIX;AACR,WAAO,+CACL,KAAKlC,SADA,EAELsC,WAFK,EAGLC,WAHK,EAILL,WAJK,CAAP;AAMD;;AAzPuB;;;;AA4P1B,SAASd,sBAAT,CAAgCqB,IAAhC,EAAsCC,IAAtC,EAA4C;AAC1C,QAAMC,GAAG,GAAG,EAAZ;AACAD,EAAAA,IAAI,CAACE,OAAL,CAAa,CAACC,GAAD,EAAMC,CAAN,KAAY;AACvB,UAAMC,KAAK,GAAGN,IAAI,CAACK,CAAD,CAAlB;;AACA,QAAIC,KAAK,KAAKC,SAAd,EAAyB;AACvBL,MAAAA,GAAG,CAACE,GAAD,CAAH,GAAWE,KAAX;AACD;AACF,GALD;AAMA,SAAOJ,GAAP;AACD","sourcesContent":["//@flow\nimport type Transport from \"@ledgerhq/hw-transport\";\nimport { signMessage } from \"./signMessage\";\nimport { getWalletPublicKey } from \"./getWalletPublicKey\";\nimport type { AddressFormat } from \"./getWalletPublicKey\";\nimport { splitTransaction } from \"./splitTransaction\";\nimport { getTrustedInput } from \"./getTrustedInput\";\nimport { getTrustedInputBIP143 } from \"./getTrustedInputBIP143\";\nimport type { Transaction } from \"./types\";\nimport { createTransaction } from \"./createTransaction\";\nimport type { CreateTransactionArg } from \"./createTransaction\";\nimport { signP2SHTransaction } from \"./signP2SHTransaction\";\nimport type { SignP2SHTransactionArg } from \"./signP2SHTransaction\";\nimport { serializeTransactionOutputs } from \"./serializeTransaction\";\nimport {setPasswords} from \"./setPasswords\";\n\nexport type { AddressFormat };\n\n/**\n * Bitcoin API.\n *\n * @example\n * TODO: import Btcv from \"@codewarriorr/hw-app-btcv\";\n * const btcv = new Btcv(transport)\n */\nexport default class Btcv {\n transport: Transport<*>;\n\n constructor(transport: Transport<*>, scrambleKey: string = \"BTC\") {\n this.transport = transport;\n transport.decorateAppAPIMethods(\n this,\n [\n \"getWalletPublicKey\",\n \"signP2SHTransaction\",\n \"signMessageNew\",\n \"createPaymentTransactionNew\",\n \"getTrustedInput\",\n \"getTrustedInputBIP143\",\n ],\n scrambleKey\n );\n }\n\n /**\n * @param path a BIP 32 path\n * @param options an object with optional these fields:\n *\n * - verify (boolean) will ask user to confirm the address on the device\n *\n * TODO: remove cashaddr\n * - format (\"legacy\" | \"p2sh\" | \"bech32\" | \"cashaddr\") to use different bitcoin address formatter.\n *\n * NB The normal usage is to use:\n *\n * - legacy format with 44' paths\n *\n * - p2sh format with 49' paths\n *\n * - bech32 format with 173' paths\n *\n * TODO: remove cashaddr\n * - cashaddr in case of Bitcoin Cash\n *\n * @example\n * btc.getWalletPublicKey(\"44'/0'/0'/0/0\").then(o => o.bitcoinAddress)\n * btc.getWalletPublicKey(\"49'/0'/0'/0/0\", { format: \"p2sh\" }).then(o => o.bitcoinAddress)\n */\n getWalletPublicKey(\n path: string,\n opts?: boolean | { verify?: boolean, format?: AddressFormat }\n ): Promise<{\n publicKey: string,\n bitcoinAddress: string,\n chainCode: string,\n }> {\n let options;\n if (arguments.length > 2 || typeof opts === \"boolean\") {\n console.warn(\n \"btc.getWalletPublicKey deprecated signature used. Please switch to getWalletPublicKey(path, { format, verify })\"\n );\n options = {\n verify: !!opts,\n format: arguments[2] ? \"p2sh\" : \"legacy\",\n };\n } else {\n options = opts || {};\n }\n return getWalletPublicKey(this.transport, { ...options, path });\n }\n\n setPasswords(type: string, password: string) {\n return setPasswords(this.transport, password, { type: type });\n }\n\n /**\n * 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.\n * @example\n btc.signMessageNew_async(\"44'/60'/0'/0'/0\", Buffer.from(\"test\").toString(\"hex\")).then(function(result) {\n var v = result['v'] + 27 + 4;\n var signature = Buffer.from(v.toString(16) + result['r'] + result['s'], 'hex').toString('base64');\n console.log(\"Signature : \" + signature);\n }).catch(function(ex) {console.log(ex);});\n */\n signMessageNew(\n path: string,\n messageHex: string\n ): Promise<{ v: number, r: string, s: string }> {\n return signMessage(this.transport, { path, messageHex });\n }\n\n /**\n * To sign a transaction involving standard (P2PKH) inputs, call createTransaction with the following parameters\n * @param inputs is an array of [ transaction, output_index, optional redeem script, optional sequence ] where\n *\n * * transaction is the previously computed transaction object for this UTXO\n * * output_index is the output in the transaction used as input for this UTXO (counting from 0)\n * * redeem script is the optional redeem script to use when consuming a Segregated Witness input\n * * sequence is the sequence number to use for this input (when using RBF), or non present\n * @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO\n * @param changePath is an optional BIP 32 path pointing to the path to the public key used to compute the change address\n * @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign\n * @param lockTime is the optional lockTime of the transaction to sign, or default (0)\n * @param sigHashType is the hash type of the transaction to sign, or default (all)\n * @param segwit is an optional boolean indicating wether to use segwit or not\n * @param initialTimestamp is an optional timestamp of the function call to use for coins that necessitate timestamps only, (not the one that the tx will include)\n * @param additionals list of additionnal options\n *\n * - \"bech32\" for spending native segwit outputs\n * - \"abc\" for bch\n * - \"gold\" for btg\n * - \"bipxxx\" for using BIPxxx\n * - \"sapling\" to indicate a zec transaction is supporting sapling (to be set over block 419200)\n * @param expiryHeight is an optional Buffer for zec overwinter / sapling Txs\n * @param useTrustedInputForSegwit trust inputs for segwit transactions\n * @return the signed transaction ready to be broadcast\n * @example\nbtc.createTransaction({\n inputs: [ [tx1, 1] ],\n associatedKeysets: [\"0'/0/0\"],\n outputScriptHex: \"01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac\"\n}).then(res => ...);\n */\n createPaymentTransactionNew(arg: CreateTransactionArg) {\n if (arguments.length > 1) {\n console.warn(\n \"@ledgerhq/hw-app-btc: createPaymentTransactionNew multi argument signature is deprecated. please switch to named parameters.\"\n );\n arg = fromDeprecateArguments(arguments, [\n \"inputs\",\n \"associatedKeysets\",\n \"changePath\",\n \"outputScriptHex\",\n \"lockTime\",\n \"sigHashType\",\n \"segwit\",\n \"initialTimestamp\",\n \"additionals\",\n \"expiryHeight\",\n \"useTrustedInputForSegwit\",\n ]);\n }\n return createTransaction(this.transport, arg);\n }\n\n /**\n * To obtain the signature of multisignature (P2SH) inputs, call signP2SHTransaction_async with the folowing parameters\n * @param inputs is an array of [ transaction, output_index, redeem script, optional sequence ] where\n * * transaction is the previously computed transaction object for this UTXO\n * * output_index is the output in the transaction used as input for this UTXO (counting from 0)\n * * redeem script is the mandatory redeem script associated to the current P2SH input\n * * sequence is the sequence number to use for this input (when using RBF), or non present\n * @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO\n * @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign\n * @param lockTime is the optional lockTime of the transaction to sign, or default (0)\n * @param sigHashType is the hash type of the transaction to sign, or default (all)\n * @return the signed transaction ready to be broadcast\n * @example\nbtc.signP2SHTransaction({\n inputs: [ [tx, 1, \"52210289b4a3ad52a919abd2bdd6920d8a6879b1e788c38aa76f0440a6f32a9f1996d02103a3393b1439d1693b063482c04bd40142db97bdf139eedd1b51ffb7070a37eac321030b9a409a1e476b0d5d17b804fcdb81cf30f9b99c6f3ae1178206e08bc500639853ae\"] ],\n associatedKeysets: [\"0'/0/0\"],\n outputScriptHex: \"01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac\"\n}).then(result => ...);\n */\n signP2SHTransaction(arg: SignP2SHTransactionArg) {\n if (arguments.length > 1) {\n console.warn(\n \"@ledgerhq/hw-app-btc: signP2SHTransaction multi argument signature is deprecated. please switch to named parameters.\"\n );\n const [\n inputs,\n associatedKeysets,\n outputScriptHex,\n lockTime,\n sigHashType,\n segwit,\n transactionVersion,\n ] = arguments;\n arg = {\n inputs,\n associatedKeysets,\n outputScriptHex,\n lockTime,\n sigHashType,\n segwit,\n transactionVersion,\n };\n arg = fromDeprecateArguments(arguments, [\n \"inputs\",\n \"associatedKeysets\",\n \"outputScriptHex\",\n \"lockTime\",\n \"sigHashType\",\n \"segwit\",\n \"transactionVersion\",\n ]);\n }\n return signP2SHTransaction(this.transport, arg);\n }\n\n /**\n * For each UTXO included in your transaction, create a transaction object from the raw serialized version of the transaction used in this UTXO.\n * @example\nconst tx1 = btc.splitTransaction(\"01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000\");\n */\n splitTransaction(\n transactionHex: string,\n isSegwitSupported: ?boolean = false,\n hasTimestamp: boolean = false,\n hasExtraData: boolean = false,\n additionals: Array<string> = []\n ): Transaction {\n return splitTransaction(\n transactionHex,\n isSegwitSupported,\n hasTimestamp,\n hasExtraData,\n additionals\n );\n }\n\n /**\n @example\nconst tx1 = btc.splitTransaction(\"01000000014ea60aeac5252c14291d428915bd7ccd1bfc4af009f4d4dc57ae597ed0420b71010000008a47304402201f36a12c240dbf9e566bc04321050b1984cd6eaf6caee8f02bb0bfec08e3354b022012ee2aeadcbbfd1e92959f57c15c1c6debb757b798451b104665aa3010569b49014104090b15bde569386734abf2a2b99f9ca6a50656627e77de663ca7325702769986cf26cc9dd7fdea0af432c8e2becc867c932e1b9dd742f2a108997c2252e2bdebffffffff0281b72e00000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88aca0860100000000001976a9144533f5fb9b4817f713c48f0bfe96b9f50c476c9b88ac00000000\");\nconst outputScript = btc.serializeTransactionOutputs(tx1).toString('hex');\n */\n serializeTransactionOutputs(t: Transaction): Buffer {\n return serializeTransactionOutputs(t);\n }\n\n getTrustedInput(\n indexLookup: number,\n transaction: Transaction,\n additionals: Array<string> = []\n ): Promise<string> {\n return getTrustedInput(\n this.transport,\n indexLookup,\n transaction,\n additionals\n );\n }\n\n getTrustedInputBIP143(\n indexLookup: number,\n transaction: Transaction,\n additionals: Array<string> = []\n ): string {\n return getTrustedInputBIP143(\n this.transport,\n indexLookup,\n transaction,\n additionals\n );\n }\n}\n\nfunction fromDeprecateArguments(args, keys) {\n const obj = {};\n keys.forEach((key, i) => {\n const value = args[i];\n if (value !== undefined) {\n obj[key] = value;\n }\n });\n return obj;\n}\n"],"file":"Btcv.js"}
{
"name": "@codewarriorr/hw-app-btcv",
"version": "1.0.2",
"version": "1.0.3",
"description": "Ledger Hardware Wallet Bitcoin Vault Application API",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet