Skip to content
This repository was archived by the owner on Oct 8, 2019. It is now read-only.

Commit 1fb0a8f

Browse files
authored
Merge pull request #35 from idandagan1/master
replace Buffer constructor
2 parents 71e0ab9 + ff05874 commit 1fb0a8f

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/LedgerArk.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var LedgerArk = function(comm) {
1010

1111
LedgerArk.prototype.getAddress_async = function(path) {
1212
var splitPath = utils.splitPath(path);
13-
var buffer = new Buffer(5 + 1 + splitPath.length * 4);
13+
var buffer = Buffer.alloc(5 + 1 + splitPath.length * 4);
1414
buffer[0] = 0xe0;
1515
buffer[1] = 0x02;
1616
buffer[2] = 0x00;
@@ -23,7 +23,7 @@ LedgerArk.prototype.getAddress_async = function(path) {
2323
return this.comm.exchange(buffer.toString('hex'), [0x9000]).then(function(response) {
2424
var result = {};
2525
//console.log(response);
26-
var response = new Buffer(response, 'hex');
26+
var response = Buffer.from(response, 'hex');
2727
var publicKeyLength = response[0];
2828
var addressLength = response[1 + publicKeyLength];
2929
result['publicKey'] = response.slice(1, 1 + publicKeyLength).toString('hex');
@@ -34,18 +34,18 @@ LedgerArk.prototype.getAddress_async = function(path) {
3434

3535
LedgerArk.prototype.signTransaction_async = function(path, rawTxHex) {
3636
var splitPath = utils.splitPath(path);
37-
var rawTx = new Buffer(rawTxHex, 'hex');
37+
var rawTx = Buffer.from(rawTxHex, 'hex');
3838
var self = this;
3939

4040
var data1, data2;
41-
var data1_headerlength = new Buffer(2);
42-
var data2_headerlength = new Buffer(1);
41+
var data1_headerlength = Buffer.alloc(2);
42+
var data2_headerlength = Buffer.alloc(1);
4343
var pathLength = 4 * splitPath.length + 1;
4444
var apdus = [];
4545
var p1;
4646
var response;
4747

48-
path = new Buffer(pathLength-1);
48+
path = Buffer.alloc(pathLength-1);
4949
splitPath.forEach(function (element, index) {
5050
path.writeUInt32BE(element, 4 * index);
5151
});
@@ -91,15 +91,15 @@ LedgerArk.prototype.signTransaction_async = function(path, rawTxHex) {
9191
}
9292

9393
LedgerArk.prototype.getAppConfiguration_async = function() {
94-
var buffer = new Buffer(5);
94+
var buffer = Buffer.alloc(5);
9595
buffer[0] = 0xe0;
9696
buffer[1] = 0x06;
9797
buffer[2] = 0x00;
9898
buffer[3] = 0x00;
9999
buffer[4] = 0x00;
100100
return this.comm.exchange(buffer.toString('hex'), [0x9000]).then(function(response) {
101101
var result = {};
102-
var response = new Buffer(response, 'hex');
102+
var response = Buffer.from(response, 'hex');
103103
result['arbitraryDataEnabled'] = (response[0] & 0x01);
104104
result['version'] = "" + response[1] + '.' + response[2] + '.' + response[3];
105105
return result;
@@ -109,14 +109,14 @@ LedgerArk.prototype.getAppConfiguration_async = function() {
109109
LedgerArk.prototype.signPersonalMessage_async = function(path, messageHex) {
110110
var splitPath = utils.splitPath(path);
111111
var offset = 0;
112-
var message = new Buffer(messageHex, 'hex');
112+
var message = Buffer.from(messageHex, 'hex');
113113
var apdus = [];
114114
var response = [];
115115
var self = this;
116116
while (offset != message.length) {
117117
var maxChunkSize = (offset == 0 ? (150 - 1 - splitPath.length * 4 - 4) : 150)
118118
var chunkSize = (offset + maxChunkSize > message.length ? message.length - offset : maxChunkSize);
119-
var buffer = new Buffer(offset == 0 ? 5 + 1 + splitPath.length * 4 + 4 + chunkSize : 5 + chunkSize);
119+
var buffer = Buffer.alloc(offset == 0 ? 5 + 1 + splitPath.length * 4 + 4 + chunkSize : 5 + chunkSize);
120120
buffer[0] = 0xe0;
121121
buffer[1] = 0x08;
122122
buffer[2] = (offset == 0 ? 0x00 : 0x80);
@@ -141,7 +141,7 @@ LedgerArk.prototype.signPersonalMessage_async = function(path, messageHex) {
141141
response = apduResponse;
142142
})
143143
}).then(function() {
144-
response = new Buffer(response, 'hex');
144+
response = Buffer.from(response, 'hex');
145145
var result = {};
146146
result['v'] = response[0];
147147
result['r'] = response.slice(1, 1 + 32).toString('hex');

0 commit comments

Comments
 (0)