Use ES2020, add dev dep for randombytes
This commit is contained in:
parent
32cc25dad8
commit
b1ff3cee49
8 changed files with 50 additions and 43 deletions
18
src/block.js
18
src/block.js
|
@ -14,6 +14,16 @@ const errorWitnessNotSegwit = new TypeError(
|
|||
'Cannot compute witness commit for non-segwit block',
|
||||
);
|
||||
class Block {
|
||||
constructor() {
|
||||
this.version = 1;
|
||||
this.prevHash = undefined;
|
||||
this.merkleRoot = undefined;
|
||||
this.timestamp = 0;
|
||||
this.witnessCommit = undefined;
|
||||
this.bits = 0;
|
||||
this.nonce = 0;
|
||||
this.transactions = undefined;
|
||||
}
|
||||
static fromBuffer(buffer) {
|
||||
if (buffer.length < 80) throw new Error('Buffer too small (< 80 bytes)');
|
||||
const bufferReader = new bufferutils_1.BufferReader(buffer);
|
||||
|
@ -69,14 +79,6 @@ class Block {
|
|||
)
|
||||
: rootHash;
|
||||
}
|
||||
version = 1;
|
||||
prevHash = undefined;
|
||||
merkleRoot = undefined;
|
||||
timestamp = 0;
|
||||
witnessCommit = undefined;
|
||||
bits = 0;
|
||||
nonce = 0;
|
||||
transactions = undefined;
|
||||
getWitnessCommit() {
|
||||
if (!txesHaveWitnessCommit(this.transactions)) return null;
|
||||
// The merkle root for the witness data is in an OP_RETURN output.
|
||||
|
|
|
@ -53,8 +53,6 @@ exports.cloneBuffer = cloneBuffer;
|
|||
* Helper class for serialization of bitcoin data types into a pre-allocated buffer.
|
||||
*/
|
||||
class BufferWriter {
|
||||
buffer;
|
||||
offset;
|
||||
constructor(buffer, offset = 0) {
|
||||
this.buffer = buffer;
|
||||
this.offset = offset;
|
||||
|
@ -96,8 +94,6 @@ exports.BufferWriter = BufferWriter;
|
|||
* Helper class for reading of bitcoin data types from a buffer.
|
||||
*/
|
||||
class BufferReader {
|
||||
buffer;
|
||||
offset;
|
||||
constructor(buffer, offset = 0) {
|
||||
this.buffer = buffer;
|
||||
this.offset = offset;
|
||||
|
|
32
src/psbt.js
32
src/psbt.js
|
@ -60,23 +60,6 @@ const DEFAULT_OPTS = {
|
|||
* Transaction object. Such as fee rate not being larger than maximumFeeRate etc.
|
||||
*/
|
||||
class Psbt {
|
||||
data;
|
||||
static fromBase64(data, opts = {}) {
|
||||
const buffer = Buffer.from(data, 'base64');
|
||||
return this.fromBuffer(buffer, opts);
|
||||
}
|
||||
static fromHex(data, opts = {}) {
|
||||
const buffer = Buffer.from(data, 'hex');
|
||||
return this.fromBuffer(buffer, opts);
|
||||
}
|
||||
static fromBuffer(buffer, opts = {}) {
|
||||
const psbtBase = bip174_1.Psbt.fromBuffer(buffer, transactionFromBuffer);
|
||||
const psbt = new Psbt(opts, psbtBase);
|
||||
checkTxForDupeIns(psbt.__CACHE.__TX, psbt.__CACHE);
|
||||
return psbt;
|
||||
}
|
||||
__CACHE;
|
||||
opts;
|
||||
constructor(opts = {}, data = new bip174_1.Psbt(new PsbtTransaction())) {
|
||||
this.data = data;
|
||||
// set defaults
|
||||
|
@ -106,6 +89,20 @@ class Psbt {
|
|||
dpew(this, '__CACHE', false, true);
|
||||
dpew(this, 'opts', false, true);
|
||||
}
|
||||
static fromBase64(data, opts = {}) {
|
||||
const buffer = Buffer.from(data, 'base64');
|
||||
return this.fromBuffer(buffer, opts);
|
||||
}
|
||||
static fromHex(data, opts = {}) {
|
||||
const buffer = Buffer.from(data, 'hex');
|
||||
return this.fromBuffer(buffer, opts);
|
||||
}
|
||||
static fromBuffer(buffer, opts = {}) {
|
||||
const psbtBase = bip174_1.Psbt.fromBuffer(buffer, transactionFromBuffer);
|
||||
const psbt = new Psbt(opts, psbtBase);
|
||||
checkTxForDupeIns(psbt.__CACHE.__TX, psbt.__CACHE);
|
||||
return psbt;
|
||||
}
|
||||
get inputCount() {
|
||||
return this.data.inputs.length;
|
||||
}
|
||||
|
@ -625,7 +622,6 @@ const transactionFromBuffer = buffer => new PsbtTransaction(buffer);
|
|||
* It contains a bitcoinjs-lib Transaction object.
|
||||
*/
|
||||
class PsbtTransaction {
|
||||
tx;
|
||||
constructor(buffer = Buffer.from([2, 0, 0, 0, 0, 0, 0, 0, 0, 0])) {
|
||||
this.tx = transaction_1.Transaction.fromBuffer(buffer);
|
||||
checkTxEmpty(this.tx);
|
||||
|
|
|
@ -39,13 +39,12 @@ function isOutput(out) {
|
|||
return out.value !== undefined;
|
||||
}
|
||||
class Transaction {
|
||||
static DEFAULT_SEQUENCE = 0xffffffff;
|
||||
static SIGHASH_ALL = 0x01;
|
||||
static SIGHASH_NONE = 0x02;
|
||||
static SIGHASH_SINGLE = 0x03;
|
||||
static SIGHASH_ANYONECANPAY = 0x80;
|
||||
static ADVANCED_TRANSACTION_MARKER = 0x00;
|
||||
static ADVANCED_TRANSACTION_FLAG = 0x01;
|
||||
constructor() {
|
||||
this.version = 1;
|
||||
this.locktime = 0;
|
||||
this.ins = [];
|
||||
this.outs = [];
|
||||
}
|
||||
static fromBuffer(buffer, _NO_STRICT) {
|
||||
const bufferReader = new bufferutils_1.BufferReader(buffer);
|
||||
const tx = new Transaction();
|
||||
|
@ -102,10 +101,6 @@ class Transaction {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
version = 1;
|
||||
locktime = 0;
|
||||
ins = [];
|
||||
outs = [];
|
||||
isCoinbase() {
|
||||
return (
|
||||
this.ins.length === 1 && Transaction.isCoinbaseHash(this.ins[0].hash)
|
||||
|
@ -400,3 +395,10 @@ class Transaction {
|
|||
}
|
||||
}
|
||||
exports.Transaction = Transaction;
|
||||
Transaction.DEFAULT_SEQUENCE = 0xffffffff;
|
||||
Transaction.SIGHASH_ALL = 0x01;
|
||||
Transaction.SIGHASH_NONE = 0x02;
|
||||
Transaction.SIGHASH_SINGLE = 0x03;
|
||||
Transaction.SIGHASH_ANYONECANPAY = 0x80;
|
||||
Transaction.ADVANCED_TRANSACTION_MARKER = 0x00;
|
||||
Transaction.ADVANCED_TRANSACTION_FLAG = 0x01;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue