@vbyte/btc-dev 1.0.7 → 1.0.8

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.
@@ -1,6 +1,6 @@
1
1
  import { TransactionInput } from './txin.js';
2
2
  import { TransactionOutput } from './txout.js';
3
- import type { TxData, TxTemplate, TransactionData, TxInput, TxOutput, TxSize, TxValue } from '../types/index.js';
3
+ import type { TxData, TxTemplate, TransactionData, TxOutput, TxSize, TxValue, TxInputTemplate } from '../types/index.js';
4
4
  export declare class Transaction {
5
5
  private readonly _tx;
6
6
  private _size;
@@ -9,7 +9,7 @@ export declare class Transaction {
9
9
  private _value;
10
10
  private _vin;
11
11
  private _vout;
12
- constructor(txdata: string | TxData | TxTemplate);
12
+ constructor(txdata?: string | TxData | TxTemplate);
13
13
  get data(): TransactionData;
14
14
  get hash(): string;
15
15
  get locktime(): {
@@ -27,10 +27,10 @@ export declare class Transaction {
27
27
  get version(): number;
28
28
  get vin(): TransactionInput[];
29
29
  get vout(): TransactionOutput[];
30
- add_vin(txin: TxInput): void;
31
- add_vout(txout: TxOutput): void;
32
- insert_vin(index: number, txin: TxInput): void;
33
- insert_vout(index: number, txout: TxOutput): void;
30
+ add_vin(tx_input: TxInputTemplate): void;
31
+ add_vout(tx_output: TxOutput): void;
32
+ insert_vin(index: number, tx_input: TxInputTemplate): void;
33
+ insert_vout(index: number, tx_output: TxOutput): void;
34
34
  remove_vin(index: number): void;
35
35
  remove_vout(index: number): void;
36
36
  _get_size(): {
package/dist/class/tx.js CHANGED
@@ -2,9 +2,9 @@ import { Assert } from '@vbyte/micro-lib';
2
2
  import { LocktimeUtil } from '../lib/meta/index.js';
3
3
  import { TransactionInput } from './txin.js';
4
4
  import { TransactionOutput } from './txout.js';
5
- import { decode_tx, get_txid, is_return_script, parse_tx, get_txsize, get_tx_value, get_txhash, encode_tx_locktime, } from '../lib/tx/index.js';
5
+ import { decode_tx, get_txid, is_return_script, parse_tx, get_txsize, get_tx_value, get_txhash, encode_tx_locktime, create_tx_input, create_tx_output, } from '../lib/tx/index.js';
6
6
  export class Transaction {
7
- constructor(txdata) {
7
+ constructor(txdata = {}) {
8
8
  this._tx = (typeof txdata !== 'string')
9
9
  ? parse_tx(txdata)
10
10
  : decode_tx(txdata);
@@ -65,16 +65,19 @@ export class Transaction {
65
65
  get vout() {
66
66
  return this._vout;
67
67
  }
68
- add_vin(txin) {
68
+ add_vin(tx_input) {
69
+ const txin = create_tx_input(tx_input);
69
70
  this._tx.vin.push(txin);
70
71
  this._update_vin();
71
72
  }
72
- add_vout(txout) {
73
+ add_vout(tx_output) {
74
+ const txout = create_tx_output(tx_output);
73
75
  this._tx.vout.push(txout);
74
76
  this._update_vout();
75
77
  }
76
- insert_vin(index, txin) {
78
+ insert_vin(index, tx_input) {
77
79
  Assert.ok(index >= 0 && index <= this._tx.vin.length, 'input goes out of bounds');
80
+ const txin = create_tx_input(tx_input);
78
81
  if (index === this._tx.vin.length) {
79
82
  this._tx.vin.push(txin);
80
83
  }
@@ -83,8 +86,9 @@ export class Transaction {
83
86
  }
84
87
  this._update_vin();
85
88
  }
86
- insert_vout(index, txout) {
89
+ insert_vout(index, tx_output) {
87
90
  Assert.ok(index >= 0 && index <= this._tx.vout.length, 'output goes out of bounds');
91
+ const txout = create_tx_output(tx_output);
88
92
  if (index === this._tx.vout.length) {
89
93
  this._tx.vout.push(txout);
90
94
  }
@@ -1,5 +1,5 @@
1
1
  import { Bytes } from '@vbyte/buff';
2
- import type { ScriptField, WitnessField, WitnessSize, WitnessType } from '../types/index.js';
2
+ import type { ScriptField, WitnessData, WitnessSize, WitnessType } from '../types/index.js';
3
3
  export declare class TransactionWitness {
4
4
  private readonly _elems;
5
5
  private _data;
@@ -7,7 +7,7 @@ export declare class TransactionWitness {
7
7
  constructor(witness: Bytes[]);
8
8
  get annex(): string | null;
9
9
  get cblock(): string | null;
10
- get data(): WitnessField;
10
+ get data(): WitnessData;
11
11
  get params(): string[];
12
12
  get script(): ScriptField | null;
13
13
  get size(): WitnessSize;
@@ -18,6 +18,6 @@ export declare class TransactionWitness {
18
18
  add(elem: Bytes): void;
19
19
  insert(index: number, elem: Bytes): void;
20
20
  remove(index: number): void;
21
- toJSON(): WitnessField;
21
+ toJSON(): WitnessData;
22
22
  toString(): string;
23
23
  }
@@ -15,16 +15,7 @@ export class TransactionWitness {
15
15
  return this._data.cblock;
16
16
  }
17
17
  get data() {
18
- return {
19
- annex: this.annex,
20
- cblock: this.cblock,
21
- params: this.params,
22
- script: this.script,
23
- size: this.size,
24
- stack: this.stack,
25
- type: this.type,
26
- version: this.version
27
- };
18
+ return this._data;
28
19
  }
29
20
  get params() {
30
21
  return this._data.params;
@@ -3,6 +3,7 @@ import { is_valid_script } from '../../lib/script/decode.js';
3
3
  import { TAPLEAF_VERSIONS } from '../../const.js';
4
4
  export function parse_witness(witness) {
5
5
  const elems = witness.map(e => Buff.bytes(e));
6
+ const stack = witness.map(e => Buff.bytes(e).hex);
6
7
  const annex = parse_annex_data(elems);
7
8
  if (annex !== null)
8
9
  elems.pop();
@@ -15,7 +16,7 @@ export function parse_witness(witness) {
15
16
  if (script !== null)
16
17
  elems.pop();
17
18
  const params = elems.map(e => e.hex);
18
- return { annex, cblock, params, script, type, version };
19
+ return { annex, cblock, params, script, stack, type, version };
19
20
  }
20
21
  function parse_annex_data(data) {
21
22
  let elem = data.at(-1);
package/dist/main.cjs CHANGED
@@ -9914,6 +9914,7 @@ class TransactionOutput {
9914
9914
 
9915
9915
  function parse_witness(witness) {
9916
9916
  const elems = witness.map(e => Buff.bytes(e));
9917
+ const stack = witness.map(e => Buff.bytes(e).hex);
9917
9918
  const annex = parse_annex_data(elems);
9918
9919
  if (annex !== null)
9919
9920
  elems.pop();
@@ -9926,7 +9927,7 @@ function parse_witness(witness) {
9926
9927
  if (script !== null)
9927
9928
  elems.pop();
9928
9929
  const params = elems.map(e => e.hex);
9929
- return { annex, cblock, params, script, type, version };
9930
+ return { annex, cblock, params, script, stack, type, version };
9930
9931
  }
9931
9932
  function parse_annex_data(data) {
9932
9933
  let elem = data.at(-1);
@@ -10022,16 +10023,7 @@ class TransactionWitness {
10022
10023
  return this._data.cblock;
10023
10024
  }
10024
10025
  get data() {
10025
- return {
10026
- annex: this.annex,
10027
- cblock: this.cblock,
10028
- params: this.params,
10029
- script: this.script,
10030
- size: this.size,
10031
- stack: this.stack,
10032
- type: this.type,
10033
- version: this.version
10034
- };
10026
+ return this._data;
10035
10027
  }
10036
10028
  get params() {
10037
10029
  return this._data.params;
@@ -10146,7 +10138,7 @@ class TransactionInput {
10146
10138
  }
10147
10139
 
10148
10140
  let Transaction$1 = class Transaction {
10149
- constructor(txdata) {
10141
+ constructor(txdata = {}) {
10150
10142
  this._tx = (typeof txdata !== 'string')
10151
10143
  ? parse_tx(txdata)
10152
10144
  : decode_tx(txdata);
@@ -10207,16 +10199,19 @@ let Transaction$1 = class Transaction {
10207
10199
  get vout() {
10208
10200
  return this._vout;
10209
10201
  }
10210
- add_vin(txin) {
10202
+ add_vin(tx_input) {
10203
+ const txin = create_tx_input(tx_input);
10211
10204
  this._tx.vin.push(txin);
10212
10205
  this._update_vin();
10213
10206
  }
10214
- add_vout(txout) {
10207
+ add_vout(tx_output) {
10208
+ const txout = create_tx_output(tx_output);
10215
10209
  this._tx.vout.push(txout);
10216
10210
  this._update_vout();
10217
10211
  }
10218
- insert_vin(index, txin) {
10212
+ insert_vin(index, tx_input) {
10219
10213
  Assert.ok(index >= 0 && index <= this._tx.vin.length, 'input goes out of bounds');
10214
+ const txin = create_tx_input(tx_input);
10220
10215
  if (index === this._tx.vin.length) {
10221
10216
  this._tx.vin.push(txin);
10222
10217
  }
@@ -10225,8 +10220,9 @@ let Transaction$1 = class Transaction {
10225
10220
  }
10226
10221
  this._update_vin();
10227
10222
  }
10228
- insert_vout(index, txout) {
10223
+ insert_vout(index, tx_output) {
10229
10224
  Assert.ok(index >= 0 && index <= this._tx.vout.length, 'output goes out of bounds');
10225
+ const txout = create_tx_output(tx_output);
10230
10226
  if (index === this._tx.vout.length) {
10231
10227
  this._tx.vout.push(txout);
10232
10228
  }