@vbyte/btc-dev 1.0.9 → 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/class/signer.js +3 -1
- package/dist/class/tx.js +4 -6
- package/dist/class/txin.js +2 -1
- package/dist/class/txout.js +2 -1
- package/dist/class/witness.js +2 -1
- package/dist/lib/tx/decode.js +1 -1
- package/dist/lib/tx/size.js +2 -2
- package/dist/lib/witness/util.d.ts +1 -0
- package/dist/lib/witness/util.js +5 -0
- package/dist/main.cjs +16 -8
- package/dist/main.cjs.map +1 -1
- package/dist/module.mjs +16 -8
- package/dist/module.mjs.map +1 -1
- package/dist/package.json +1 -1
- package/dist/script.js +1 -1
- package/dist/script.js.map +1 -1
- package/package.json +1 -1
- package/src/class/signer.ts +3 -1
- package/src/class/tx.ts +4 -6
- package/src/class/txin.ts +2 -0
- package/src/class/txout.ts +2 -0
- package/src/class/witness.ts +2 -0
- package/src/lib/tx/decode.ts +1 -1
- package/src/lib/tx/size.ts +2 -2
- package/src/lib/witness/util.ts +6 -0
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, '
|
|
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.
|
|
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.
|
|
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,6 +9879,7 @@ 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() {
|
|
@@ -9995,15 +9998,21 @@ function get_witness_size(witness) {
|
|
|
9995
9998
|
const vsize = Math.ceil(WIT_LENGTH_BYTE + size / 4);
|
|
9996
9999
|
return { total: size, vsize };
|
|
9997
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
|
+
}
|
|
9998
10005
|
|
|
9999
10006
|
var index$5 = /*#__PURE__*/Object.freeze({
|
|
10000
10007
|
__proto__: null,
|
|
10008
|
+
assert_witness: assert_witness,
|
|
10001
10009
|
get_witness_size: get_witness_size,
|
|
10002
10010
|
parse_witness: parse_witness
|
|
10003
10011
|
});
|
|
10004
10012
|
|
|
10005
10013
|
class TransactionWitness {
|
|
10006
10014
|
constructor(witness) {
|
|
10015
|
+
assert_witness(witness);
|
|
10007
10016
|
this._elems = witness.map(e => Buff.bytes(e));
|
|
10008
10017
|
this._data = parse_witness(this._elems);
|
|
10009
10018
|
this._size = get_witness_size(this._elems);
|
|
@@ -10068,6 +10077,7 @@ class TransactionWitness {
|
|
|
10068
10077
|
|
|
10069
10078
|
class TransactionInput {
|
|
10070
10079
|
constructor(txin) {
|
|
10080
|
+
assert_tx_input(txin);
|
|
10071
10081
|
this._txin = txin;
|
|
10072
10082
|
}
|
|
10073
10083
|
get coinbase() {
|
|
@@ -10122,15 +10132,13 @@ class TransactionInput {
|
|
|
10122
10132
|
|
|
10123
10133
|
let Transaction$1 = class Transaction {
|
|
10124
10134
|
constructor(txdata = {}) {
|
|
10125
|
-
this._tx = (
|
|
10126
|
-
|
|
10127
|
-
|
|
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));
|
|
10128
10138
|
this._size = this._get_size();
|
|
10129
10139
|
this._hash = get_txhash(this._tx);
|
|
10130
10140
|
this._txid = get_txid(this._tx);
|
|
10131
10141
|
this._value = get_tx_value(this._tx);
|
|
10132
|
-
this._vin = this._tx.vin.map(txin => new TransactionInput(txin));
|
|
10133
|
-
this._vout = this._tx.vout.map(txout => new TransactionOutput(txout));
|
|
10134
10142
|
}
|
|
10135
10143
|
get data() {
|
|
10136
10144
|
return this._tx;
|