@ledgerhq/hw-app-btc
Advanced tools
Comparing version 4.33.7 to 4.34.0
@@ -165,4 +165,4 @@ "use strict"; | ||
return (0, _utils.eachSeries)(inputs, function (input) { | ||
var data = Buffer.concat([input.prevout, isDecred ? Buffer.from([0x00]) : Buffer.alloc(0), //tree | ||
_this.createVarint(input.script.length)]); | ||
var treeField = isDecred ? input.tree || Buffer.from([0x00]) : Buffer.alloc(0); | ||
var data = Buffer.concat([input.prevout, treeField, _this.createVarint(input.script.length)]); | ||
return _this.getTrustedInputRaw(data).then(function () { | ||
@@ -506,3 +506,2 @@ // iteration (eachSeries) ended | ||
* @param expiryHeight is an optional Buffer for zec overwinter / sapling Txs | ||
* @param multisigInputs is an optional array of [ transaction, output_index ] that cannot be signed by the device | ||
* @return the signed transaction ready to be broadcast | ||
@@ -525,8 +524,7 @@ * @example | ||
var initialTimestamp = arguments[7]; | ||
var additionals = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : []; | ||
var _this5 = this; | ||
var additionals = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : []; | ||
var expiryHeight = arguments[9]; | ||
var multisigInputs = arguments.length > 10 && arguments[10] !== undefined ? arguments[10] : []; | ||
@@ -598,22 +596,2 @@ var isDecred = additionals.includes("decred"); | ||
}).then(function () { | ||
return (0, _utils.foreach)(multisigInputs, function (input) { | ||
return (0, _utils.doIf)(!resuming, function () { | ||
return getTrustedInputCall(input[1], input[0], additionals).then(function (trustedInput) { | ||
var sequence = Buffer.alloc(4); | ||
sequence.writeUInt32LE(input.length >= 4 && typeof input[3] === "number" ? input[3] : DEFAULT_SEQUENCE, 0); | ||
trustedInputs.push({ | ||
trustedInput: false, | ||
value: Buffer.from(trustedInput, "hex"), | ||
sequence: sequence | ||
}); | ||
var offset = useBip143 ? 0 : 4; | ||
targetTransaction.inputs.push({ | ||
prevout: Buffer.from(trustedInput, "hex").slice(offset, offset + 0x24), | ||
script: Buffer.alloc(0), | ||
sequence: sequence | ||
}); | ||
}); | ||
}); | ||
}); | ||
}).then(function () { | ||
return (0, _utils.doIf)(!resuming, function () { | ||
@@ -660,9 +638,4 @@ return ( | ||
// Do the second run with the individual transaction | ||
(0, _utils.foreach)(inputs.concat(multisigInputs), function (input, i) { | ||
var script = void 0; | ||
if (inputs[i]) { | ||
script = inputs[i].length >= 3 && typeof inputs[i][2] === "string" ? Buffer.from(inputs[i][2], "hex") : !segwit ? regularOutputs[i].script : Buffer.concat([Buffer.from([OP_DUP, OP_HASH160, HASH_SIZE]), _this5.hashPublicKey(publicKeys[i]), Buffer.from([OP_EQUALVERIFY, OP_CHECKSIG])]); | ||
} else { | ||
script = Buffer.alloc(0); | ||
} | ||
(0, _utils.foreach)(inputs, function (input, i) { | ||
var script = inputs[i].length >= 3 && typeof inputs[i][2] === "string" ? Buffer.from(inputs[i][2], "hex") : !segwit ? regularOutputs[i].script : Buffer.concat([Buffer.from([OP_DUP, OP_HASH160, HASH_SIZE]), _this5.hashPublicKey(publicKeys[i]), Buffer.from([OP_EQUALVERIFY, OP_CHECKSIG])]); | ||
var pseudoTX = Object.assign({}, targetTransaction); | ||
@@ -685,14 +658,8 @@ var pseudoTrustedInputs = useBip143 ? [trustedInputs[i]] : trustedInputs; | ||
}).then(function () { | ||
if (associatedKeysets[i]) { | ||
return _this5.signTransaction(associatedKeysets[i], lockTime, sigHashType, expiryHeight); | ||
} else { | ||
return false; | ||
} | ||
return _this5.signTransaction(associatedKeysets[i], lockTime, sigHashType, expiryHeight, additionals); | ||
}).then(function (signature) { | ||
if (signature) { | ||
signatures.push(signature); | ||
targetTransaction.inputs[i].script = nullScript; | ||
if (firstRun) { | ||
firstRun = false; | ||
} | ||
signatures.push(signature); | ||
targetTransaction.inputs[i].script = nullScript; | ||
if (firstRun) { | ||
firstRun = false; | ||
} | ||
@@ -950,13 +917,6 @@ }); | ||
for (var i = 0; i < numberInputs; i++) { | ||
var _prevout = transaction.slice(offset, offset + 32); | ||
offset += 32; | ||
//Tree field | ||
if (isDecred) { | ||
offset += 1; | ||
} | ||
var prevOutIndex = transaction.slice(offset, offset + 4); | ||
offset += 4; | ||
_prevout = Buffer.concat([_prevout, prevOutIndex]); | ||
var _prevout = transaction.slice(offset, offset + 36); | ||
offset += 36; | ||
var _script = Buffer.alloc(0); | ||
var _tree = Buffer.alloc(0); | ||
//No script for decred, it has a witness | ||
@@ -968,2 +928,6 @@ if (!isDecred) { | ||
offset += varint[0]; | ||
} else { | ||
//Tree field | ||
_tree = transaction.slice(offset, offset + 1); | ||
offset += 1; | ||
} | ||
@@ -973,3 +937,3 @@ | ||
offset += 4; | ||
inputs.push({ prevout: _prevout, script: _script, sequence: _sequence3 }); | ||
inputs.push({ prevout: _prevout, script: _script, sequence: _sequence3, tree: _tree }); | ||
} | ||
@@ -976,0 +940,0 @@ varint = this.getVarint(transaction, offset); |
{ | ||
"name": "@ledgerhq/hw-app-btc", | ||
"version": "4.33.7", | ||
"version": "4.34.0", | ||
"description": "Ledger Hardware Wallet Bitcoin Application API", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
109
src/Btc.js
@@ -181,5 +181,6 @@ //@flow | ||
return eachSeries(inputs, input => { | ||
const treeField = isDecred ? (input.tree || Buffer.from([0x00])) : Buffer.alloc(0); | ||
const data = Buffer.concat([ | ||
input.prevout, | ||
isDecred ? Buffer.from([0x00]) : Buffer.alloc(0), //tree | ||
treeField, | ||
this.createVarint(input.script.length) | ||
@@ -573,3 +574,2 @@ ]); | ||
* @param expiryHeight is an optional Buffer for zec overwinter / sapling Txs | ||
* @param multisigInputs is an optional array of [ transaction, output_index ] that cannot be signed by the device | ||
* @return the signed transaction ready to be broadcast | ||
@@ -594,4 +594,3 @@ * @example | ||
additionals: Array<string> = [], | ||
expiryHeight?: Buffer, | ||
multisigInputs?: Array<[Transaction, number, ?string, ?number]> = [] | ||
expiryHeight?: Buffer | ||
) { | ||
@@ -705,28 +704,2 @@ const isDecred = additionals.includes("decred"); | ||
}) | ||
.then(() => { | ||
return foreach(multisigInputs, input => { | ||
return doIf(!resuming, () => | ||
getTrustedInputCall(input[1], input[0], additionals).then(trustedInput => { | ||
let sequence = Buffer.alloc(4); | ||
sequence.writeUInt32LE( | ||
input.length >= 4 && typeof input[3] === "number" | ||
? input[3] | ||
: DEFAULT_SEQUENCE, | ||
0 | ||
); | ||
trustedInputs.push({ | ||
trustedInput: false, | ||
value: Buffer.from(trustedInput, "hex"), | ||
sequence | ||
}); | ||
let offset = useBip143 ? 0 : 4; | ||
targetTransaction.inputs.push({ | ||
prevout: Buffer.from(trustedInput, "hex").slice(offset, offset + 0x24), | ||
script: Buffer.alloc(0), | ||
sequence | ||
}); | ||
}) | ||
); | ||
}); | ||
}) | ||
.then(() => | ||
@@ -783,18 +756,13 @@ doIf(!resuming, () => | ||
// Do the second run with the individual transaction | ||
foreach(inputs.concat(multisigInputs), (input, i) => { | ||
let script; | ||
if (inputs[i]) { | ||
script = | ||
inputs[i].length >= 3 && typeof inputs[i][2] === "string" | ||
? Buffer.from(inputs[i][2], "hex") | ||
: !segwit | ||
? regularOutputs[i].script | ||
: Buffer.concat([ | ||
Buffer.from([OP_DUP, OP_HASH160, HASH_SIZE]), | ||
this.hashPublicKey(publicKeys[i]), | ||
Buffer.from([OP_EQUALVERIFY, OP_CHECKSIG]) | ||
]); | ||
} else { | ||
script = Buffer.alloc(0); | ||
} | ||
foreach(inputs, (input, i) => { | ||
let script = | ||
inputs[i].length >= 3 && typeof inputs[i][2] === "string" | ||
? Buffer.from(inputs[i][2], "hex") | ||
: !segwit | ||
? regularOutputs[i].script | ||
: Buffer.concat([ | ||
Buffer.from([OP_DUP, OP_HASH160, HASH_SIZE]), | ||
this.hashPublicKey(publicKeys[i]), | ||
Buffer.from([OP_EQUALVERIFY, OP_CHECKSIG]) | ||
]); | ||
let pseudoTX = Object.assign({}, targetTransaction); | ||
@@ -826,20 +794,15 @@ let pseudoTrustedInputs = useBip143 | ||
.then(() => { | ||
if (associatedKeysets[i]) { | ||
return this.signTransaction( | ||
associatedKeysets[i], | ||
lockTime, | ||
sigHashType, | ||
expiryHeight | ||
); | ||
} else { | ||
return false; | ||
} | ||
return this.signTransaction( | ||
associatedKeysets[i], | ||
lockTime, | ||
sigHashType, | ||
expiryHeight, | ||
additionals | ||
); | ||
}) | ||
.then(signature => { | ||
if (signature) { | ||
signatures.push(signature); | ||
targetTransaction.inputs[i].script = nullScript; | ||
if (firstRun) { | ||
firstRun = false; | ||
} | ||
signatures.push(signature); | ||
targetTransaction.inputs[i].script = nullScript; | ||
if (firstRun) { | ||
firstRun = false; | ||
} | ||
@@ -1160,13 +1123,6 @@ }); | ||
for (let i = 0; i < numberInputs; i++) { | ||
let prevout = transaction.slice(offset, offset + 32); | ||
offset += 32; | ||
//Tree field | ||
if (isDecred) { | ||
offset += 1; | ||
} | ||
const prevOutIndex = transaction.slice(offset, offset + 4); | ||
offset += 4; | ||
prevout = Buffer.concat([prevout, prevOutIndex]); | ||
const prevout = transaction.slice(offset, offset + 36); | ||
offset += 36; | ||
let script = Buffer.alloc(0); | ||
let tree = Buffer.alloc(0); | ||
//No script for decred, it has a witness | ||
@@ -1178,2 +1134,6 @@ if (!isDecred) { | ||
offset += varint[0]; | ||
} else { | ||
//Tree field | ||
tree = transaction.slice(offset, offset + 1); | ||
offset += 1; | ||
} | ||
@@ -1183,3 +1143,3 @@ | ||
offset += 4; | ||
inputs.push({ prevout, script, sequence }); | ||
inputs.push({ prevout, script, sequence, tree }); | ||
} | ||
@@ -1362,3 +1322,4 @@ varint = this.getVarint(transaction, offset); | ||
script: Buffer, | ||
sequence: Buffer | ||
sequence: Buffer, | ||
tree?: Buffer | ||
}; | ||
@@ -1365,0 +1326,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
235977
2467