@ledgerhq/hw-app-eth
Advanced tools
Comparing version 1.2.0-beta.b4ba11b7 to 1.2.0-beta.df091f88
@@ -34,15 +34,9 @@ "use strict"; | ||
let paths = (0, _utils.splitPath)(path); | ||
let buffer = new Buffer(5 + 1 + paths.length * 4); | ||
buffer[0] = 0xe0; | ||
buffer[1] = 0x02; | ||
buffer[2] = boolDisplay ? 0x01 : 0x00; | ||
buffer[3] = boolChaincode ? 0x01 : 0x00; | ||
buffer[4] = 1 + paths.length * 4; | ||
buffer[5] = paths.length; | ||
let buffer = new Buffer(1 + paths.length * 4); | ||
buffer[0] = paths.length; | ||
paths.forEach((element, index) => { | ||
buffer.writeUInt32BE(element, 6 + 4 * index); | ||
buffer.writeUInt32BE(element, 1 + 4 * index); | ||
}); | ||
return this.transport.exchange(buffer.toString("hex"), [0x9000]).then(responseHex => { | ||
return this.transport.send(0xe0, 0x02, boolDisplay ? 0x01 : 0x00, boolChaincode ? 0x01 : 0x00, buffer).then(response => { | ||
let result = {}; | ||
let response = new Buffer(responseHex, "hex"); | ||
let publicKeyLength = response[0]; | ||
@@ -68,29 +62,23 @@ let addressLength = response[1 + publicKeyLength]; | ||
let rawTx = new Buffer(rawTxHex, "hex"); | ||
let apdus = []; | ||
let response = []; | ||
let toSend = []; | ||
let response; | ||
while (offset !== rawTx.length) { | ||
let maxChunkSize = offset === 0 ? 150 - 1 - paths.length * 4 : 150; | ||
let chunkSize = offset + maxChunkSize > rawTx.length ? rawTx.length - offset : maxChunkSize; | ||
let buffer = new Buffer(offset === 0 ? 5 + 1 + paths.length * 4 + chunkSize : 5 + chunkSize); | ||
buffer[0] = 0xe0; | ||
buffer[1] = 0x04; | ||
buffer[2] = offset === 0 ? 0x00 : 0x80; | ||
buffer[3] = 0x00; | ||
buffer[4] = offset === 0 ? 1 + paths.length * 4 + chunkSize : chunkSize; | ||
let buffer = new Buffer(offset === 0 ? 1 + paths.length * 4 + chunkSize : chunkSize); | ||
if (offset === 0) { | ||
buffer[5] = paths.length; | ||
buffer[0] = paths.length; | ||
paths.forEach((element, index) => { | ||
buffer.writeUInt32BE(element, 6 + 4 * index); | ||
buffer.writeUInt32BE(element, 1 + 4 * index); | ||
}); | ||
rawTx.copy(buffer, 6 + 4 * paths.length, offset, offset + chunkSize); | ||
rawTx.copy(buffer, 1 + 4 * paths.length, offset, offset + chunkSize); | ||
} else { | ||
rawTx.copy(buffer, 5, offset, offset + chunkSize); | ||
rawTx.copy(buffer, 0, offset, offset + chunkSize); | ||
} | ||
apdus.push(buffer.toString("hex")); | ||
toSend.push(buffer); | ||
offset += chunkSize; | ||
} | ||
return (0, _utils.foreach)(apdus, apdu => this.transport.exchange(apdu, [0x9000]).then(apduResponse => { | ||
return (0, _utils.foreach)(toSend, (data, i) => this.transport.send(0xe0, 0x04, i === 0 ? 0x00 : 0x80, 0x00, data).then(apduResponse => { | ||
response = apduResponse; | ||
})).then(() => { | ||
response = new Buffer(response, "hex"); | ||
const v = response.slice(0, 1).toString("hex"); | ||
@@ -106,11 +94,4 @@ const r = response.slice(1, 1 + 32).toString("hex"); | ||
getAppConfiguration() { | ||
let buffer = new Buffer(5); | ||
buffer[0] = 0xe0; | ||
buffer[1] = 0x06; | ||
buffer[2] = 0x00; | ||
buffer[3] = 0x00; | ||
buffer[4] = 0x00; | ||
return this.transport.exchange(buffer.toString("hex"), [0x9000]).then(responseHex => { | ||
return this.transport.send(0xe0, 0x06, 0x00, 0x00).then(response => { | ||
let result = {}; | ||
let response = Buffer.from(responseHex, "hex"); | ||
result.arbitraryDataEnabled = response[0] & 0x01; | ||
@@ -138,30 +119,24 @@ result.version = "" + response[1] + "." + response[2] + "." + response[3]; | ||
let message = new Buffer(messageHex, "hex"); | ||
let apdus = []; | ||
let response = []; | ||
let toSend = []; | ||
let response; | ||
while (offset !== message.length) { | ||
let maxChunkSize = offset === 0 ? 150 - 1 - paths.length * 4 - 4 : 150; | ||
let chunkSize = offset + maxChunkSize > message.length ? message.length - offset : maxChunkSize; | ||
let buffer = new Buffer(offset === 0 ? 5 + 1 + paths.length * 4 + 4 + chunkSize : 5 + chunkSize); | ||
buffer[0] = 0xe0; | ||
buffer[1] = 0x08; | ||
buffer[2] = offset === 0 ? 0x00 : 0x80; | ||
buffer[3] = 0x00; | ||
buffer[4] = offset === 0 ? 1 + paths.length * 4 + 4 + chunkSize : chunkSize; | ||
let buffer = new Buffer(offset === 0 ? 1 + paths.length * 4 + 4 + chunkSize : chunkSize); | ||
if (offset === 0) { | ||
buffer[5] = paths.length; | ||
buffer[0] = paths.length; | ||
paths.forEach((element, index) => { | ||
buffer.writeUInt32BE(element, 6 + 4 * index); | ||
buffer.writeUInt32BE(element, 1 + 4 * index); | ||
}); | ||
buffer.writeUInt32BE(message.length, 6 + 4 * paths.length); | ||
message.copy(buffer, 6 + 4 * paths.length + 4, offset, offset + chunkSize); | ||
buffer.writeUInt32BE(message.length, 1 + 4 * paths.length); | ||
message.copy(buffer, 1 + 4 * paths.length + 4, offset, offset + chunkSize); | ||
} else { | ||
message.copy(buffer, 5, offset, offset + chunkSize); | ||
message.copy(buffer, 0, offset, offset + chunkSize); | ||
} | ||
apdus.push(buffer.toString("hex")); | ||
toSend.push(buffer); | ||
offset += chunkSize; | ||
} | ||
return (0, _utils.foreach)(apdus, apdu => this.transport.exchange(apdu, [0x9000]).then(apduResponse => { | ||
return (0, _utils.foreach)(toSend, (data, i) => this.transport.send(0xe0, 0x08, i === 0 ? 0x00 : 0x80, 0x00, data).then(apduResponse => { | ||
response = apduResponse; | ||
})).then(() => { | ||
response = new Buffer(response, "hex"); | ||
const v = response[0]; | ||
@@ -168,0 +143,0 @@ const r = response.slice(1, 1 + 32).toString("hex"); |
{ | ||
"name": "@ledgerhq/hw-app-eth", | ||
"version": "1.2.0-beta.b4ba11b7", | ||
"version": "1.2.0-beta.df091f88", | ||
"description": "Ledger Hardware Wallet Ethereum Application API", | ||
@@ -28,3 +28,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@ledgerhq/hw-transport": "^1.2.0-beta.b4ba11b7" | ||
"@ledgerhq/hw-transport": "^1.2.0-beta.df091f88" | ||
}, | ||
@@ -31,0 +31,0 @@ "devDependencies": { |
111
src/Eth.js
@@ -57,17 +57,17 @@ /******************************************************************************** | ||
let paths = splitPath(path); | ||
let buffer = new Buffer(5 + 1 + paths.length * 4); | ||
buffer[0] = 0xe0; | ||
buffer[1] = 0x02; | ||
buffer[2] = boolDisplay ? 0x01 : 0x00; | ||
buffer[3] = boolChaincode ? 0x01 : 0x00; | ||
buffer[4] = 1 + paths.length * 4; | ||
buffer[5] = paths.length; | ||
let buffer = new Buffer(1 + paths.length * 4); | ||
buffer[0] = paths.length; | ||
paths.forEach((element, index) => { | ||
buffer.writeUInt32BE(element, 6 + 4 * index); | ||
buffer.writeUInt32BE(element, 1 + 4 * index); | ||
}); | ||
return this.transport | ||
.exchange(buffer.toString("hex"), [0x9000]) | ||
.then(responseHex => { | ||
.send( | ||
0xe0, | ||
0x02, | ||
boolDisplay ? 0x01 : 0x00, | ||
boolChaincode ? 0x01 : 0x00, | ||
buffer | ||
) | ||
.then(response => { | ||
let result = {}; | ||
let response = new Buffer(responseHex, "hex"); | ||
let publicKeyLength = response[0]; | ||
@@ -114,4 +114,4 @@ let addressLength = response[1 + publicKeyLength]; | ||
let rawTx = new Buffer(rawTxHex, "hex"); | ||
let apdus = []; | ||
let response = []; | ||
let toSend = []; | ||
let response; | ||
while (offset !== rawTx.length) { | ||
@@ -124,27 +124,23 @@ let maxChunkSize = offset === 0 ? 150 - 1 - paths.length * 4 : 150; | ||
let buffer = new Buffer( | ||
offset === 0 ? 5 + 1 + paths.length * 4 + chunkSize : 5 + chunkSize | ||
offset === 0 ? 1 + paths.length * 4 + chunkSize : chunkSize | ||
); | ||
buffer[0] = 0xe0; | ||
buffer[1] = 0x04; | ||
buffer[2] = offset === 0 ? 0x00 : 0x80; | ||
buffer[3] = 0x00; | ||
buffer[4] = offset === 0 ? 1 + paths.length * 4 + chunkSize : chunkSize; | ||
if (offset === 0) { | ||
buffer[5] = paths.length; | ||
buffer[0] = paths.length; | ||
paths.forEach((element, index) => { | ||
buffer.writeUInt32BE(element, 6 + 4 * index); | ||
buffer.writeUInt32BE(element, 1 + 4 * index); | ||
}); | ||
rawTx.copy(buffer, 6 + 4 * paths.length, offset, offset + chunkSize); | ||
rawTx.copy(buffer, 1 + 4 * paths.length, offset, offset + chunkSize); | ||
} else { | ||
rawTx.copy(buffer, 5, offset, offset + chunkSize); | ||
rawTx.copy(buffer, 0, offset, offset + chunkSize); | ||
} | ||
apdus.push(buffer.toString("hex")); | ||
toSend.push(buffer); | ||
offset += chunkSize; | ||
} | ||
return foreach(apdus, apdu => | ||
this.transport.exchange(apdu, [0x9000]).then(apduResponse => { | ||
response = apduResponse; | ||
}) | ||
return foreach(toSend, (data, i) => | ||
this.transport | ||
.send(0xe0, 0x04, i === 0 ? 0x00 : 0x80, 0x00, data) | ||
.then(apduResponse => { | ||
response = apduResponse; | ||
}) | ||
).then(() => { | ||
response = new Buffer(response, "hex"); | ||
const v = response.slice(0, 1).toString("hex"); | ||
@@ -163,18 +159,8 @@ const r = response.slice(1, 1 + 32).toString("hex"); | ||
}> { | ||
let buffer = new Buffer(5); | ||
buffer[0] = 0xe0; | ||
buffer[1] = 0x06; | ||
buffer[2] = 0x00; | ||
buffer[3] = 0x00; | ||
buffer[4] = 0x00; | ||
return this.transport | ||
.exchange(buffer.toString("hex"), [0x9000]) | ||
.then(responseHex => { | ||
let result = {}; | ||
let response = Buffer.from(responseHex, "hex"); | ||
result.arbitraryDataEnabled = response[0] & 0x01; | ||
result.version = | ||
"" + response[1] + "." + response[2] + "." + response[3]; | ||
return result; | ||
}); | ||
return this.transport.send(0xe0, 0x06, 0x00, 0x00).then(response => { | ||
let result = {}; | ||
result.arbitraryDataEnabled = response[0] & 0x01; | ||
result.version = "" + response[1] + "." + response[2] + "." + response[3]; | ||
return result; | ||
}); | ||
} | ||
@@ -205,4 +191,4 @@ | ||
let message = new Buffer(messageHex, "hex"); | ||
let apdus = []; | ||
let response = []; | ||
let toSend = []; | ||
let response; | ||
while (offset !== message.length) { | ||
@@ -215,19 +201,13 @@ let maxChunkSize = offset === 0 ? 150 - 1 - paths.length * 4 - 4 : 150; | ||
let buffer = new Buffer( | ||
offset === 0 ? 5 + 1 + paths.length * 4 + 4 + chunkSize : 5 + chunkSize | ||
offset === 0 ? 1 + paths.length * 4 + 4 + chunkSize : chunkSize | ||
); | ||
buffer[0] = 0xe0; | ||
buffer[1] = 0x08; | ||
buffer[2] = offset === 0 ? 0x00 : 0x80; | ||
buffer[3] = 0x00; | ||
buffer[4] = | ||
offset === 0 ? 1 + paths.length * 4 + 4 + chunkSize : chunkSize; | ||
if (offset === 0) { | ||
buffer[5] = paths.length; | ||
buffer[0] = paths.length; | ||
paths.forEach((element, index) => { | ||
buffer.writeUInt32BE(element, 6 + 4 * index); | ||
buffer.writeUInt32BE(element, 1 + 4 * index); | ||
}); | ||
buffer.writeUInt32BE(message.length, 6 + 4 * paths.length); | ||
buffer.writeUInt32BE(message.length, 1 + 4 * paths.length); | ||
message.copy( | ||
buffer, | ||
6 + 4 * paths.length + 4, | ||
1 + 4 * paths.length + 4, | ||
offset, | ||
@@ -237,13 +217,14 @@ offset + chunkSize | ||
} else { | ||
message.copy(buffer, 5, offset, offset + chunkSize); | ||
message.copy(buffer, 0, offset, offset + chunkSize); | ||
} | ||
apdus.push(buffer.toString("hex")); | ||
toSend.push(buffer); | ||
offset += chunkSize; | ||
} | ||
return foreach(apdus, apdu => | ||
this.transport.exchange(apdu, [0x9000]).then(apduResponse => { | ||
response = apduResponse; | ||
}) | ||
return foreach(toSend, (data, i) => | ||
this.transport | ||
.send(0xe0, 0x08, i === 0 ? 0x00 : 0x80, 0x00, data) | ||
.then(apduResponse => { | ||
response = apduResponse; | ||
}) | ||
).then(() => { | ||
response = new Buffer(response, "hex"); | ||
const v = response[0]; | ||
@@ -250,0 +231,0 @@ const r = response.slice(1, 1 + 32).toString("hex"); |
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
55207
752