@vbyte/btc-dev 1.0.8 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.mjs CHANGED
@@ -8413,7 +8413,7 @@ const DEFAULT_CONFIG = {
8413
8413
  };
8414
8414
  function decode_tx(txbytes, options = {}) {
8415
8415
  const config = { ...DEFAULT_CONFIG, ...options };
8416
- Assert.is_bytes(txbytes, 'txbytes must be hex or a unit array');
8416
+ Assert.is_bytes(txbytes, 'transaction must be hex or a byte-array');
8417
8417
  const stream = new Stream(txbytes);
8418
8418
  const version = read_version(stream);
8419
8419
  const has_witness = (config.segwit)
@@ -9152,7 +9152,7 @@ const WIT_FLAG_BYTES = 2;
9152
9152
  function get_vsize$1(bytes) {
9153
9153
  const weight = Buff.bytes(bytes).length;
9154
9154
  const remain = (weight % 4 > 0) ? 1 : 0;
9155
- return Math.floor(weight / 4) + remain;
9155
+ return Math.ceil(weight / 4) + remain;
9156
9156
  }
9157
9157
  function get_txsize(txdata) {
9158
9158
  const json = parse_tx(txdata);
@@ -9160,7 +9160,7 @@ function get_txsize(txdata) {
9160
9160
  const total = encode_tx(json, true).length;
9161
9161
  const weight = base * 3 + total;
9162
9162
  const remain = (weight % 4 > 0) ? 1 : 0;
9163
- const vsize = Math.floor(weight / 4) + remain;
9163
+ const vsize = Math.ceil(weight / 4) + remain;
9164
9164
  return { base, total, vsize, weight };
9165
9165
  }
9166
9166
  function get_vin_size(vin) {
@@ -9471,6 +9471,8 @@ function sign_taproot_tx(seckey, txdata, options) {
9471
9471
 
9472
9472
  class TxSigner {
9473
9473
  constructor(seckey) {
9474
+ Assert.ok(Buff.is_bytes(seckey), 'seckey must be a string or bytes');
9475
+ Assert.size(seckey, 32, 'seckey must be 32 bytes');
9474
9476
  this._seckey = Buff.bytes(seckey).hex;
9475
9477
  }
9476
9478
  get pubkey() {
@@ -9877,16 +9879,11 @@ var index$6 = /*#__PURE__*/Object.freeze({
9877
9879
 
9878
9880
  class TransactionOutput {
9879
9881
  constructor(txout) {
9882
+ assert_tx_output(txout);
9880
9883
  this._txout = txout;
9881
9884
  }
9882
9885
  get data() {
9883
- return {
9884
- script_pk: this.script_pk,
9885
- size: this.size,
9886
- type: this.type,
9887
- value: this.value,
9888
- version: this.version
9889
- };
9886
+ return this._txout;
9890
9887
  }
9891
9888
  get script_pk() {
9892
9889
  return {
@@ -10001,15 +9998,21 @@ function get_witness_size(witness) {
10001
9998
  const vsize = Math.ceil(WIT_LENGTH_BYTE + size / 4);
10002
9999
  return { total: size, vsize };
10003
10000
  }
10001
+ function assert_witness(witness) {
10002
+ Assert.ok(Array.isArray(witness), 'witness must be an array');
10003
+ Assert.ok(witness.every(e => Buff.is_bytes(e)), 'witness must be an array of strings or bytes');
10004
+ }
10004
10005
 
10005
10006
  var index$5 = /*#__PURE__*/Object.freeze({
10006
10007
  __proto__: null,
10008
+ assert_witness: assert_witness,
10007
10009
  get_witness_size: get_witness_size,
10008
10010
  parse_witness: parse_witness
10009
10011
  });
10010
10012
 
10011
10013
  class TransactionWitness {
10012
10014
  constructor(witness) {
10015
+ assert_witness(witness);
10013
10016
  this._elems = witness.map(e => Buff.bytes(e));
10014
10017
  this._data = parse_witness(this._elems);
10015
10018
  this._size = get_witness_size(this._elems);
@@ -10074,22 +10077,14 @@ class TransactionWitness {
10074
10077
 
10075
10078
  class TransactionInput {
10076
10079
  constructor(txin) {
10080
+ assert_tx_input(txin);
10077
10081
  this._txin = txin;
10078
10082
  }
10079
10083
  get coinbase() {
10080
10084
  return this._txin.coinbase;
10081
10085
  }
10082
10086
  get data() {
10083
- return {
10084
- coinbase: this.coinbase,
10085
- prevout: this.prevout?.data ?? null,
10086
- script_sig: this.script_sig,
10087
- sequence: this.sequence,
10088
- size: this.size,
10089
- txid: this.txid,
10090
- vout: this.vout,
10091
- witness: this.witness?.data ?? null
10092
- };
10087
+ return this._txin;
10093
10088
  }
10094
10089
  get has_prevout() {
10095
10090
  return this._txin.prevout !== null;
@@ -10137,29 +10132,16 @@ class TransactionInput {
10137
10132
 
10138
10133
  let Transaction$1 = class Transaction {
10139
10134
  constructor(txdata = {}) {
10140
- this._tx = (typeof txdata !== 'string')
10141
- ? parse_tx(txdata)
10142
- : decode_tx(txdata);
10135
+ this._tx = parse_tx(txdata);
10136
+ this._vin = this._tx.vin.map(txin => new TransactionInput(txin));
10137
+ this._vout = this._tx.vout.map(txout => new TransactionOutput(txout));
10143
10138
  this._size = this._get_size();
10144
10139
  this._hash = get_txhash(this._tx);
10145
10140
  this._txid = get_txid(this._tx);
10146
10141
  this._value = get_tx_value(this._tx);
10147
- this._vin = this._tx.vin.map(txin => new TransactionInput(txin));
10148
- this._vout = this._tx.vout.map(txout => new TransactionOutput(txout));
10149
10142
  }
10150
10143
  get data() {
10151
- return {
10152
- hash: this.hash,
10153
- locktime: this.locktime,
10154
- return: this.return,
10155
- size: this.size,
10156
- spends: this.spends,
10157
- txid: this.txid,
10158
- value: this.value,
10159
- version: this.version,
10160
- vin: this.vin.map(txin => txin.data),
10161
- vout: this.vout.map(txout => txout.data)
10162
- };
10144
+ return this._tx;
10163
10145
  }
10164
10146
  get hash() {
10165
10147
  return this._hash;