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
9
package-lock.json
generated
9
package-lock.json
generated
|
@ -427,6 +427,15 @@
|
|||
"integrity": "sha512-SQaNzWQ2YZSr7FqAyPPiA3FYpux2Lqh3HWMZQk47x3xbMCqgC/w0dY3dw9rGqlweDDkrySQBcaScXWeR+Yb11Q==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/randombytes": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/randombytes/-/randombytes-2.0.0.tgz",
|
||||
"integrity": "sha512-bz8PhAVlwN72vqefzxa14DKNT8jK/mV66CSjwdVQM/k3Th3EPKfUtdMniwZgMedQTFuywAsfjnZsg+pEnltaMA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/wif": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/wif/-/wif-2.0.2.tgz",
|
||||
|
|
|
@ -65,6 +65,7 @@
|
|||
"@types/mocha": "^5.2.7",
|
||||
"@types/node": "^16.11.1",
|
||||
"@types/proxyquire": "^1.3.28",
|
||||
"@types/randombytes": "^2.0.0",
|
||||
"@types/wif": "^2.0.2",
|
||||
"bip39": "^3.0.2",
|
||||
"bip65": "^1.0.1",
|
||||
|
@ -80,6 +81,7 @@
|
|||
"nyc": "^15.1.0",
|
||||
"prettier": "1.16.4",
|
||||
"proxyquire": "^2.0.1",
|
||||
"randombytes": "^2.1.0",
|
||||
"regtest-client": "0.2.0",
|
||||
"rimraf": "^2.6.3",
|
||||
"ts-node": "^8.3.0",
|
||||
|
|
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;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ESNEXT",
|
||||
"target": "ES2020",
|
||||
"module": "commonjs",
|
||||
"outDir": "../",
|
||||
"declaration": false,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ESNEXT",
|
||||
"target": "ES2020",
|
||||
"module": "commonjs",
|
||||
"outDir": "./src",
|
||||
"declaration": true,
|
||||
|
|
Loading…
Reference in a new issue