Skip to content

Commit b1ff3ce

Browse files
committed
Use ES2020, add dev dep for randombytes
1 parent 32cc25d commit b1ff3ce

File tree

8 files changed

+50
-43
lines changed

8 files changed

+50
-43
lines changed

package-lock.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"@types/mocha": "^5.2.7",
6666
"@types/node": "^16.11.1",
6767
"@types/proxyquire": "^1.3.28",
68+
"@types/randombytes": "^2.0.0",
6869
"@types/wif": "^2.0.2",
6970
"bip39": "^3.0.2",
7071
"bip65": "^1.0.1",
@@ -80,6 +81,7 @@
8081
"nyc": "^15.1.0",
8182
"prettier": "1.16.4",
8283
"proxyquire": "^2.0.1",
84+
"randombytes": "^2.1.0",
8385
"regtest-client": "0.2.0",
8486
"rimraf": "^2.6.3",
8587
"ts-node": "^8.3.0",

src/block.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ const errorWitnessNotSegwit = new TypeError(
1414
'Cannot compute witness commit for non-segwit block',
1515
);
1616
class Block {
17+
constructor() {
18+
this.version = 1;
19+
this.prevHash = undefined;
20+
this.merkleRoot = undefined;
21+
this.timestamp = 0;
22+
this.witnessCommit = undefined;
23+
this.bits = 0;
24+
this.nonce = 0;
25+
this.transactions = undefined;
26+
}
1727
static fromBuffer(buffer) {
1828
if (buffer.length < 80) throw new Error('Buffer too small (< 80 bytes)');
1929
const bufferReader = new bufferutils_1.BufferReader(buffer);
@@ -69,14 +79,6 @@ class Block {
6979
)
7080
: rootHash;
7181
}
72-
version = 1;
73-
prevHash = undefined;
74-
merkleRoot = undefined;
75-
timestamp = 0;
76-
witnessCommit = undefined;
77-
bits = 0;
78-
nonce = 0;
79-
transactions = undefined;
8082
getWitnessCommit() {
8183
if (!txesHaveWitnessCommit(this.transactions)) return null;
8284
// The merkle root for the witness data is in an OP_RETURN output.

src/bufferutils.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ exports.cloneBuffer = cloneBuffer;
5353
* Helper class for serialization of bitcoin data types into a pre-allocated buffer.
5454
*/
5555
class BufferWriter {
56-
buffer;
57-
offset;
5856
constructor(buffer, offset = 0) {
5957
this.buffer = buffer;
6058
this.offset = offset;
@@ -96,8 +94,6 @@ exports.BufferWriter = BufferWriter;
9694
* Helper class for reading of bitcoin data types from a buffer.
9795
*/
9896
class BufferReader {
99-
buffer;
100-
offset;
10197
constructor(buffer, offset = 0) {
10298
this.buffer = buffer;
10399
this.offset = offset;

src/psbt.js

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,6 @@ const DEFAULT_OPTS = {
6060
* Transaction object. Such as fee rate not being larger than maximumFeeRate etc.
6161
*/
6262
class Psbt {
63-
data;
64-
static fromBase64(data, opts = {}) {
65-
const buffer = Buffer.from(data, 'base64');
66-
return this.fromBuffer(buffer, opts);
67-
}
68-
static fromHex(data, opts = {}) {
69-
const buffer = Buffer.from(data, 'hex');
70-
return this.fromBuffer(buffer, opts);
71-
}
72-
static fromBuffer(buffer, opts = {}) {
73-
const psbtBase = bip174_1.Psbt.fromBuffer(buffer, transactionFromBuffer);
74-
const psbt = new Psbt(opts, psbtBase);
75-
checkTxForDupeIns(psbt.__CACHE.__TX, psbt.__CACHE);
76-
return psbt;
77-
}
78-
__CACHE;
79-
opts;
8063
constructor(opts = {}, data = new bip174_1.Psbt(new PsbtTransaction())) {
8164
this.data = data;
8265
// set defaults
@@ -106,6 +89,20 @@ class Psbt {
10689
dpew(this, '__CACHE', false, true);
10790
dpew(this, 'opts', false, true);
10891
}
92+
static fromBase64(data, opts = {}) {
93+
const buffer = Buffer.from(data, 'base64');
94+
return this.fromBuffer(buffer, opts);
95+
}
96+
static fromHex(data, opts = {}) {
97+
const buffer = Buffer.from(data, 'hex');
98+
return this.fromBuffer(buffer, opts);
99+
}
100+
static fromBuffer(buffer, opts = {}) {
101+
const psbtBase = bip174_1.Psbt.fromBuffer(buffer, transactionFromBuffer);
102+
const psbt = new Psbt(opts, psbtBase);
103+
checkTxForDupeIns(psbt.__CACHE.__TX, psbt.__CACHE);
104+
return psbt;
105+
}
109106
get inputCount() {
110107
return this.data.inputs.length;
111108
}
@@ -625,7 +622,6 @@ const transactionFromBuffer = buffer => new PsbtTransaction(buffer);
625622
* It contains a bitcoinjs-lib Transaction object.
626623
*/
627624
class PsbtTransaction {
628-
tx;
629625
constructor(buffer = Buffer.from([2, 0, 0, 0, 0, 0, 0, 0, 0, 0])) {
630626
this.tx = transaction_1.Transaction.fromBuffer(buffer);
631627
checkTxEmpty(this.tx);

src/transaction.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,12 @@ function isOutput(out) {
3939
return out.value !== undefined;
4040
}
4141
class Transaction {
42-
static DEFAULT_SEQUENCE = 0xffffffff;
43-
static SIGHASH_ALL = 0x01;
44-
static SIGHASH_NONE = 0x02;
45-
static SIGHASH_SINGLE = 0x03;
46-
static SIGHASH_ANYONECANPAY = 0x80;
47-
static ADVANCED_TRANSACTION_MARKER = 0x00;
48-
static ADVANCED_TRANSACTION_FLAG = 0x01;
42+
constructor() {
43+
this.version = 1;
44+
this.locktime = 0;
45+
this.ins = [];
46+
this.outs = [];
47+
}
4948
static fromBuffer(buffer, _NO_STRICT) {
5049
const bufferReader = new bufferutils_1.BufferReader(buffer);
5150
const tx = new Transaction();
@@ -102,10 +101,6 @@ class Transaction {
102101
}
103102
return true;
104103
}
105-
version = 1;
106-
locktime = 0;
107-
ins = [];
108-
outs = [];
109104
isCoinbase() {
110105
return (
111106
this.ins.length === 1 && Transaction.isCoinbaseHash(this.ins[0].hash)
@@ -400,3 +395,10 @@ class Transaction {
400395
}
401396
}
402397
exports.Transaction = Transaction;
398+
Transaction.DEFAULT_SEQUENCE = 0xffffffff;
399+
Transaction.SIGHASH_ALL = 0x01;
400+
Transaction.SIGHASH_NONE = 0x02;
401+
Transaction.SIGHASH_SINGLE = 0x03;
402+
Transaction.SIGHASH_ANYONECANPAY = 0x80;
403+
Transaction.ADVANCED_TRANSACTION_MARKER = 0x00;
404+
Transaction.ADVANCED_TRANSACTION_FLAG = 0x01;

test/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "ESNEXT",
3+
"target": "ES2020",
44
"module": "commonjs",
55
"outDir": "../",
66
"declaration": false,

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "ESNEXT",
3+
"target": "ES2020",
44
"module": "commonjs",
55
"outDir": "./src",
66
"declaration": true,

0 commit comments

Comments
 (0)