@ledgerhq/hw-app-btc
Advanced tools
Comparing version 4.19.0 to 4.20.0
@@ -1,3 +0,3 @@ | ||
// flow-typed signature: a6d424443969ff4bc7162d7f7bad024e | ||
// flow-typed version: <<STUB>>/@ledgerhq/hw-transport_v^4.13.0/flow_v0.68.0 | ||
// flow-typed signature: de76e43b7f594cd142bb9865fb4eb16a | ||
// flow-typed version: <<STUB>>/@ledgerhq/hw-transport_v^4.7.3/flow_v0.68.0 | ||
@@ -4,0 +4,0 @@ /** |
@@ -282,4 +282,6 @@ "use strict"; | ||
var bip143 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; | ||
var overwinter = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false; | ||
return this.transport.send(0xe0, 0x44, firstRound ? 0x00 : 0x80, newTransaction ? bip143 ? 0x02 : 0x00 : 0x80, transactionData); | ||
var p2 = bip143 ? overwinter ? 0x04 : 0x02 : 0x00; | ||
return this.transport.send(0xe0, 0x44, firstRound ? 0x00 : 0x80, newTransaction ? p2 : 0x80, transactionData); | ||
} | ||
@@ -292,5 +294,6 @@ }, { | ||
var bip143 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; | ||
var overwinter = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false; | ||
var data = Buffer.concat([transaction.version, transaction.timestamp || Buffer.alloc(0), this.createVarint(transaction.inputs.length)]); | ||
return this.startUntrustedHashTransactionInputRaw(newTransaction, true, data, bip143).then(function () { | ||
var data = Buffer.concat([transaction.version, transaction.timestamp || Buffer.alloc(0), transaction.nVersionGroupId || Buffer.alloc(0), this.createVarint(transaction.inputs.length)]); | ||
return this.startUntrustedHashTransactionInputRaw(newTransaction, true, data, bip143, overwinter).then(function () { | ||
var i = 0; | ||
@@ -309,3 +312,3 @@ return (0, _utils.eachSeries)(transaction.inputs, function (input) { | ||
data = Buffer.concat([prefix, inputs[i].value, _this2.createVarint(input.script.length)]); | ||
return _this2.startUntrustedHashTransactionInputRaw(newTransaction, false, data, bip143).then(function () { | ||
return _this2.startUntrustedHashTransactionInputRaw(newTransaction, false, data, bip143, overwinter).then(function () { | ||
var scriptBlocks = []; | ||
@@ -327,3 +330,3 @@ var offset = 0; | ||
return (0, _utils.eachSeries)(scriptBlocks, function (scriptBlock) { | ||
return _this2.startUntrustedHashTransactionInputRaw(newTransaction, false, scriptBlock, bip143); | ||
return _this2.startUntrustedHashTransactionInputRaw(newTransaction, false, scriptBlock, bip143, overwinter); | ||
}).then(function () { | ||
@@ -369,18 +372,23 @@ i++; | ||
var sigHashType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : SIGHASH_ALL; | ||
var expiryHeight = arguments[3]; | ||
var paths = (0, _utils.splitPath)(path); | ||
var buffer = Buffer.alloc(1 + paths.length * 4 + 1 + 4 + 1); // TODO shouldn't have to calc that, just use buffer concat all the way down | ||
var offset = 0; | ||
buffer[offset++] = paths.length; | ||
var pathsBuffer = Buffer.alloc(paths.length * 4); | ||
paths.forEach(function (element) { | ||
buffer.writeUInt32BE(element, offset); | ||
pathsBuffer.writeUInt32BE(element, offset); | ||
offset += 4; | ||
}); | ||
buffer[offset++] = 0x00; // authorization length | ||
buffer.writeUInt32BE(lockTime, offset); | ||
offset += 4; | ||
buffer[offset++] = sigHashType; | ||
var lockTimeBuffer = Buffer.alloc(4); | ||
lockTimeBuffer.writeUInt32BE(lockTime, 0); | ||
var buffer = Buffer.concat([Buffer.from([paths.length]), pathsBuffer, Buffer.from([0x00]), lockTimeBuffer, Buffer.from([sigHashType])]); | ||
if (expiryHeight) { | ||
buffer = Buffer.concat([buffer, expiryHeight]); | ||
} | ||
return this.transport.send(0xe0, 0x48, 0x00, 0x00, buffer).then(function (result) { | ||
result[0] = 0x30; | ||
return result.slice(0, result.length - 2); | ||
if (result.length > 0) { | ||
result[0] = 0x30; | ||
return result.slice(0, result.length - 2); | ||
} | ||
return result; | ||
}); | ||
@@ -464,5 +472,6 @@ } | ||
* @param sigHashType is the hash type of the transaction to sign, or default (all) | ||
* @param segwit is a boolean indicating wether to use segwit or not | ||
* @param initialTimestamp is the timestamp when the function is called, not the one that the tx will include | ||
* @param segwit is an optional boolean indicating wether to use segwit or not | ||
* @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) | ||
* @param additionals list of additionnal options ("abc" for bch, "gold" for btg, "bipxxx" for using BIPxxx) | ||
* @param expiryHeight is an optional Buffer for zec overwinter Txs | ||
* @return the signed transaction ready to be broadcast | ||
@@ -484,11 +493,12 @@ * @example | ||
var segwit = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false; | ||
var initialTimestamp = arguments[7]; | ||
var _this5 = this; | ||
var initialTimestamp = arguments[7]; | ||
var additionals = arguments[8]; | ||
var expiryHeight = arguments[9]; | ||
var hasTimestamp = initialTimestamp !== undefined; | ||
var startTime = Date.now(); | ||
var useBip143 = segwit || !!additionals && (additionals.includes("abc") || additionals.includes("gold") || additionals.includes("bip143")); | ||
var useBip143 = segwit || !!additionals && (additionals.includes("abc") || additionals.includes("gold") || additionals.includes("bip143")) || !!expiryHeight; | ||
// Inputs are provided as arrays of [transaction, output_index, optional redeem script, optional sequence] | ||
@@ -499,3 +509,3 @@ // associatedKeysets are provided as arrays of [path] | ||
var defaultVersion = Buffer.alloc(4); | ||
defaultVersion.writeUInt32LE(1, 0); | ||
expiryHeight ? defaultVersion.writeUInt32LE(0x80000003, 0) : defaultVersion.writeUInt32LE(1, 0); | ||
var trustedInputs = []; | ||
@@ -533,2 +543,8 @@ var regularOutputs = []; | ||
} | ||
}).then(function () { | ||
if (expiryHeight) { | ||
targetTransaction.nVersionGroupId = Buffer.from([0x70, 0x82, 0xc4, 0x03]); | ||
targetTransaction.nExpiryHeight = expiryHeight; | ||
targetTransaction.extraData = Buffer.from([0x00]); | ||
} | ||
}); | ||
@@ -567,3 +583,3 @@ }).then(function () { | ||
// Do the first run with all inputs | ||
_this5.startUntrustedHashTransactionInput(true, targetTransaction, trustedInputs, true).then(function () { | ||
_this5.startUntrustedHashTransactionInput(true, targetTransaction, trustedInputs, true, !!expiryHeight).then(function () { | ||
return (0, _utils.doIf)(!resuming && typeof changePath != "undefined", function () { | ||
@@ -579,2 +595,6 @@ // $FlowFixMe | ||
}).then(function () { | ||
return (0, _utils.doIf)(!!expiryHeight, function () { | ||
return _this5.signTransaction("", undefined, SIGHASH_ALL, expiryHeight); | ||
}); | ||
}).then(function () { | ||
return ( | ||
@@ -591,3 +611,3 @@ // Do the second run with the individual transaction | ||
} | ||
return _this5.startUntrustedHashTransactionInput(!useBip143 && firstRun, pseudoTX, pseudoTrustedInputs, useBip143).then(function () { | ||
return _this5.startUntrustedHashTransactionInput(!useBip143 && firstRun, pseudoTX, pseudoTrustedInputs, useBip143, !!expiryHeight).then(function () { | ||
return (0, _utils.doIf)(!useBip143, function () { | ||
@@ -602,3 +622,3 @@ return (0, _utils.doIf)(!resuming && typeof changePath != "undefined", function () { | ||
}).then(function () { | ||
return _this5.signTransaction(associatedKeysets[i], lockTime, sigHashType); | ||
return _this5.signTransaction(associatedKeysets[i], lockTime, sigHashType, expiryHeight); | ||
}).then(function (signature) { | ||
@@ -643,2 +663,5 @@ signatures.push(signature); | ||
} | ||
if (expiryHeight) { | ||
result = Buffer.concat([result, targetTransaction.nExpiryHeight || Buffer.alloc(0), targetTransaction.extraData || Buffer.alloc(0)]); | ||
} | ||
@@ -798,4 +821,8 @@ result = Buffer.concat([result, lockTimeBuffer]); | ||
var timestamp = Buffer.alloc(0); | ||
var nExpiryHeight = Buffer.alloc(0); | ||
var nVersionGroupId = Buffer.alloc(0); | ||
var extraData = Buffer.alloc(0); | ||
var transaction = Buffer.from(transactionHex, "hex"); | ||
var version = transaction.slice(offset, offset + 4); | ||
var overwinter = version.equals(Buffer.from([0x03, 0x00, 0x00, 0x80])); | ||
offset += 4; | ||
@@ -810,2 +837,6 @@ if (!hasTimestamp && isSegwitSupported && transaction[offset] === 0 && transaction[offset + 1] !== 0) { | ||
} | ||
if (overwinter) { | ||
nVersionGroupId = transaction.slice(offset, 4 + offset); | ||
offset += 4; | ||
} | ||
var varint = this.getVarint(transaction, offset); | ||
@@ -844,2 +875,8 @@ var numberInputs = varint[0]; | ||
} | ||
if (overwinter) { | ||
offset += 4; | ||
nExpiryHeight = transaction.slice(offset, offset + 4); | ||
offset += 4; | ||
extraData = transaction.slice(offset); | ||
} | ||
return { | ||
@@ -851,3 +888,6 @@ version: version, | ||
witness: witnessScript, | ||
timestamp: timestamp | ||
timestamp: timestamp, | ||
nVersionGroupId: nVersionGroupId, | ||
nExpiryHeight: nExpiryHeight, | ||
extraData: extraData | ||
}; | ||
@@ -895,6 +935,6 @@ } | ||
if (typeof transaction.outputs !== "undefined" && typeof transaction.locktime !== "undefined") { | ||
outputBuffer = Buffer.concat([outputBuffer, useWitness && transaction.witness || Buffer.alloc(0), transaction.locktime]); | ||
outputBuffer = Buffer.concat([outputBuffer, useWitness && transaction.witness || Buffer.alloc(0), transaction.locktime, transaction.nExpiryHeight || Buffer.alloc(0), transaction.extraData || Buffer.alloc(0)]); | ||
} | ||
return Buffer.concat([transaction.version, timestamp ? timestamp : Buffer.alloc(0), useWitness ? Buffer.from("0001", "hex") : Buffer.alloc(0), this.createVarint(transaction.inputs.length), inputBuffer, outputBuffer]); | ||
return Buffer.concat([transaction.version, timestamp ? timestamp : Buffer.alloc(0), transaction.nVersionGroupId || Buffer.alloc(0), useWitness ? Buffer.from("0001", "hex") : Buffer.alloc(0), this.createVarint(transaction.inputs.length), inputBuffer, outputBuffer]); | ||
} | ||
@@ -901,0 +941,0 @@ |
{ | ||
"name": "@ledgerhq/hw-app-btc", | ||
"version": "4.19.0", | ||
"version": "4.20.0", | ||
"description": "Ledger Hardware Wallet Bitcoin Application API", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
146
src/Btc.js
@@ -257,4 +257,6 @@ //@flow | ||
transactionData: Buffer, | ||
bip143?: boolean = false | ||
bip143?: boolean = false, | ||
overwinter?: boolean = false | ||
) { | ||
const p2 = bip143 ? (overwinter ? 0x04 : 0x02) : 0x00; | ||
return this.transport.send( | ||
@@ -264,3 +266,3 @@ 0xe0, | ||
firstRound ? 0x00 : 0x80, | ||
newTransaction ? (bip143 ? 0x02 : 0x00) : 0x80, | ||
newTransaction ? p2 : 0x80, | ||
transactionData | ||
@@ -274,3 +276,4 @@ ); | ||
inputs: Array<{ trustedInput: boolean, value: Buffer }>, | ||
bip143?: boolean = false | ||
bip143?: boolean = false, | ||
overwinter?: boolean = false | ||
) { | ||
@@ -280,2 +283,3 @@ let data = Buffer.concat([ | ||
transaction.timestamp || Buffer.alloc(0), | ||
transaction.nVersionGroupId || Buffer.alloc(0), | ||
this.createVarint(transaction.inputs.length) | ||
@@ -287,3 +291,4 @@ ]); | ||
data, | ||
bip143 | ||
bip143, | ||
overwinter | ||
).then(() => { | ||
@@ -311,3 +316,4 @@ let i = 0; | ||
data, | ||
bip143 | ||
bip143, | ||
overwinter | ||
).then(() => { | ||
@@ -344,3 +350,4 @@ let scriptBlocks = []; | ||
scriptBlock, | ||
bip143 | ||
bip143, | ||
overwinter | ||
); | ||
@@ -386,19 +393,30 @@ }).then(() => { | ||
lockTime?: number = DEFAULT_LOCKTIME, | ||
sigHashType?: number = SIGHASH_ALL | ||
sigHashType?: number = SIGHASH_ALL, | ||
expiryHeight?: Buffer | ||
): Promise<Buffer> { | ||
const paths = splitPath(path); | ||
const buffer = Buffer.alloc(1 + paths.length * 4 + 1 + 4 + 1); // TODO shouldn't have to calc that, just use buffer concat all the way down | ||
let offset = 0; | ||
buffer[offset++] = paths.length; | ||
const pathsBuffer = Buffer.alloc(paths.length * 4); | ||
paths.forEach(element => { | ||
buffer.writeUInt32BE(element, offset); | ||
pathsBuffer.writeUInt32BE(element, offset); | ||
offset += 4; | ||
}); | ||
buffer[offset++] = 0x00; // authorization length | ||
buffer.writeUInt32BE(lockTime, offset); | ||
offset += 4; | ||
buffer[offset++] = sigHashType; | ||
const lockTimeBuffer = Buffer.alloc(4); | ||
lockTimeBuffer.writeUInt32BE(lockTime, 0); | ||
let buffer = Buffer.concat([ | ||
Buffer.from([paths.length]), | ||
pathsBuffer, | ||
Buffer.from([0x00]), | ||
lockTimeBuffer, | ||
Buffer.from([sigHashType]) | ||
]); | ||
if (expiryHeight) { | ||
buffer = Buffer.concat([buffer, expiryHeight]); | ||
} | ||
return this.transport.send(0xe0, 0x48, 0x00, 0x00, buffer).then(result => { | ||
result[0] = 0x30; | ||
return result.slice(0, result.length - 2); | ||
if (result.length > 0) { | ||
result[0] = 0x30; | ||
return result.slice(0, result.length - 2); | ||
} | ||
return result; | ||
}); | ||
@@ -490,5 +508,6 @@ } | ||
* @param sigHashType is the hash type of the transaction to sign, or default (all) | ||
* @param segwit is a boolean indicating wether to use segwit or not | ||
* @param initialTimestamp is the timestamp when the function is called, not the one that the tx will include | ||
* @param segwit is an optional boolean indicating wether to use segwit or not | ||
* @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) | ||
* @param additionals list of additionnal options ("abc" for bch, "gold" for btg, "bipxxx" for using BIPxxx) | ||
* @param expiryHeight is an optional Buffer for zec overwinter Txs | ||
* @return the signed transaction ready to be broadcast | ||
@@ -512,3 +531,4 @@ * @example | ||
initialTimestamp?: number, | ||
additionals?: Array<string> | ||
additionals?: Array<string>, | ||
expiryHeight?: Buffer | ||
) { | ||
@@ -522,3 +542,4 @@ const hasTimestamp = initialTimestamp !== undefined; | ||
additionals.includes("gold") || | ||
additionals.includes("bip143"))); | ||
additionals.includes("bip143"))) || | ||
!!expiryHeight; | ||
// Inputs are provided as arrays of [transaction, output_index, optional redeem script, optional sequence] | ||
@@ -529,3 +550,5 @@ // associatedKeysets are provided as arrays of [path] | ||
const defaultVersion = Buffer.alloc(4); | ||
defaultVersion.writeUInt32LE(1, 0); | ||
expiryHeight | ||
? defaultVersion.writeUInt32LE(0x80000003, 0) | ||
: defaultVersion.writeUInt32LE(1, 0); | ||
const trustedInputs: Array<*> = []; | ||
@@ -563,9 +586,22 @@ const regularOutputs: Array<TransactionOutput> = []; | ||
}) | ||
).then(() => { | ||
const { outputs } = input[0]; | ||
const index = input[1]; | ||
if (outputs && index <= outputs.length - 1) { | ||
regularOutputs.push(outputs[index]); | ||
} | ||
}); | ||
) | ||
.then(() => { | ||
const { outputs } = input[0]; | ||
const index = input[1]; | ||
if (outputs && index <= outputs.length - 1) { | ||
regularOutputs.push(outputs[index]); | ||
} | ||
}) | ||
.then(() => { | ||
if (expiryHeight) { | ||
targetTransaction.nVersionGroupId = Buffer.from([ | ||
0x70, | ||
0x82, | ||
0xc4, | ||
0x03 | ||
]); | ||
targetTransaction.nExpiryHeight = expiryHeight; | ||
targetTransaction.extraData = Buffer.from([0x00]); | ||
} | ||
}); | ||
}) | ||
@@ -620,3 +656,4 @@ .then(() => { | ||
trustedInputs, | ||
true | ||
true, | ||
!!expiryHeight | ||
).then(() => | ||
@@ -631,2 +668,7 @@ doIf(!resuming && typeof changePath != "undefined", () => { | ||
.then(() => | ||
doIf(!!expiryHeight, () => | ||
this.signTransaction("", undefined, SIGHASH_ALL, expiryHeight) | ||
) | ||
) | ||
.then(() => | ||
// Do the second run with the individual transaction | ||
@@ -657,3 +699,4 @@ foreach(inputs, (input, i) => { | ||
pseudoTrustedInputs, | ||
useBip143 | ||
useBip143, | ||
!!expiryHeight | ||
) | ||
@@ -669,3 +712,8 @@ .then(() => | ||
.then(() => | ||
this.signTransaction(associatedKeysets[i], lockTime, sigHashType) | ||
this.signTransaction( | ||
associatedKeysets[i], | ||
lockTime, | ||
sigHashType, | ||
expiryHeight | ||
) | ||
) | ||
@@ -735,2 +783,9 @@ .then(signature => { | ||
} | ||
if (expiryHeight) { | ||
result = Buffer.concat([ | ||
result, | ||
targetTransaction.nExpiryHeight || Buffer.alloc(0), | ||
targetTransaction.extraData || Buffer.alloc(0) | ||
]); | ||
} | ||
@@ -898,4 +953,8 @@ result = Buffer.concat([result, lockTimeBuffer]); | ||
let timestamp = Buffer.alloc(0); | ||
let nExpiryHeight = Buffer.alloc(0); | ||
let nVersionGroupId = Buffer.alloc(0); | ||
let extraData = Buffer.alloc(0); | ||
const transaction = Buffer.from(transactionHex, "hex"); | ||
const version = transaction.slice(offset, offset + 4); | ||
const overwinter = version.equals(Buffer.from([0x03, 0x00, 0x00, 0x80])); | ||
offset += 4; | ||
@@ -914,2 +973,6 @@ if ( | ||
} | ||
if (overwinter) { | ||
nVersionGroupId = transaction.slice(offset, 4 + offset); | ||
offset += 4; | ||
} | ||
let varint = this.getVarint(transaction, offset); | ||
@@ -948,2 +1011,8 @@ const numberInputs = varint[0]; | ||
} | ||
if (overwinter) { | ||
offset += 4; | ||
nExpiryHeight = transaction.slice(offset, offset + 4); | ||
offset += 4; | ||
extraData = transaction.slice(offset); | ||
} | ||
return { | ||
@@ -955,3 +1024,6 @@ version, | ||
witness: witnessScript, | ||
timestamp | ||
timestamp, | ||
nVersionGroupId, | ||
nExpiryHeight, | ||
extraData | ||
}; | ||
@@ -1012,3 +1084,5 @@ } | ||
(useWitness && transaction.witness) || Buffer.alloc(0), | ||
transaction.locktime | ||
transaction.locktime, | ||
transaction.nExpiryHeight || Buffer.alloc(0), | ||
transaction.extraData || Buffer.alloc(0) | ||
]); | ||
@@ -1020,2 +1094,3 @@ } | ||
timestamp ? timestamp : Buffer.alloc(0), | ||
transaction.nVersionGroupId || Buffer.alloc(0), | ||
useWitness ? Buffer.from("0001", "hex") : Buffer.alloc(0), | ||
@@ -1074,3 +1149,6 @@ this.createVarint(transaction.inputs.length), | ||
witness?: Buffer, | ||
timestamp?: Buffer | ||
timestamp?: Buffer, | ||
nVersionGroupId?: Buffer, | ||
nExpiryHeight?: Buffer, | ||
extraData?: Buffer | ||
}; |
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
210281
2420