@vbyte/btc-dev 1.0.7 → 1.0.9

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, TxOutput, TxSize, TxValue, TxInputTemplate } from '../types/index.js';
4
4
  export declare class Transaction {
5
5
  private readonly _tx;
6
6
  private _size;
@@ -9,8 +9,8 @@ export declare class Transaction {
9
9
  private _value;
10
10
  private _vin;
11
11
  private _vout;
12
- constructor(txdata: string | TxData | TxTemplate);
13
- get data(): TransactionData;
12
+ constructor(txdata?: string | TxData | TxTemplate);
13
+ get data(): TxData;
14
14
  get hash(): string;
15
15
  get locktime(): {
16
16
  hex: string;
@@ -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(): {
@@ -40,12 +40,12 @@ export declare class Transaction {
40
40
  witness: number;
41
41
  base: number;
42
42
  total: number;
43
- weight: number;
44
43
  vsize: number;
44
+ weight: number;
45
45
  };
46
46
  _update_tx(): void;
47
47
  _update_vin(): void;
48
48
  _update_vout(): void;
49
- toJSON(): TransactionData;
49
+ toJSON(): TxData;
50
50
  toString(): string;
51
51
  }
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);
@@ -16,18 +16,7 @@ export class Transaction {
16
16
  this._vout = this._tx.vout.map(txout => new TransactionOutput(txout));
17
17
  }
18
18
  get data() {
19
- return {
20
- hash: this.hash,
21
- locktime: this.locktime,
22
- return: this.return,
23
- size: this.size,
24
- spends: this.spends,
25
- txid: this.txid,
26
- value: this.value,
27
- version: this.version,
28
- vin: this.vin.map(txin => txin.data),
29
- vout: this.vout.map(txout => txout.data)
30
- };
19
+ return this._tx;
31
20
  }
32
21
  get hash() {
33
22
  return this._hash;
@@ -65,16 +54,19 @@ export class Transaction {
65
54
  get vout() {
66
55
  return this._vout;
67
56
  }
68
- add_vin(txin) {
57
+ add_vin(tx_input) {
58
+ const txin = create_tx_input(tx_input);
69
59
  this._tx.vin.push(txin);
70
60
  this._update_vin();
71
61
  }
72
- add_vout(txout) {
62
+ add_vout(tx_output) {
63
+ const txout = create_tx_output(tx_output);
73
64
  this._tx.vout.push(txout);
74
65
  this._update_vout();
75
66
  }
76
- insert_vin(index, txin) {
67
+ insert_vin(index, tx_input) {
77
68
  Assert.ok(index >= 0 && index <= this._tx.vin.length, 'input goes out of bounds');
69
+ const txin = create_tx_input(tx_input);
78
70
  if (index === this._tx.vin.length) {
79
71
  this._tx.vin.push(txin);
80
72
  }
@@ -83,8 +75,9 @@ export class Transaction {
83
75
  }
84
76
  this._update_vin();
85
77
  }
86
- insert_vout(index, txout) {
78
+ insert_vout(index, tx_output) {
87
79
  Assert.ok(index >= 0 && index <= this._tx.vout.length, 'output goes out of bounds');
80
+ const txout = create_tx_output(tx_output);
88
81
  if (index === this._tx.vout.length) {
89
82
  this._tx.vout.push(txout);
90
83
  }
@@ -1,11 +1,11 @@
1
1
  import { TransactionOutput } from './txout.js';
2
2
  import { TransactionWitness } from './witness.js';
3
- import type { TxInput, TransactionInputData } from '../types/index.js';
3
+ import type { TxInput } from '../types/index.js';
4
4
  export declare class TransactionInput {
5
5
  private readonly _txin;
6
6
  constructor(txin: TxInput);
7
7
  get coinbase(): string | null;
8
- get data(): TransactionInputData;
8
+ get data(): TxInput;
9
9
  get has_prevout(): boolean;
10
10
  get is_coinbase(): boolean;
11
11
  get prevout(): TransactionOutput | null;
@@ -22,6 +22,6 @@ export declare class TransactionInput {
22
22
  get txid(): string;
23
23
  get vout(): number;
24
24
  get witness(): TransactionWitness | null;
25
- toJSON(): TransactionInputData;
25
+ toJSON(): TxInput;
26
26
  toString(): string;
27
27
  }
@@ -11,16 +11,7 @@ export class TransactionInput {
11
11
  return this._txin.coinbase;
12
12
  }
13
13
  get data() {
14
- return {
15
- coinbase: this.coinbase,
16
- prevout: this.prevout?.data ?? null,
17
- script_sig: this.script_sig,
18
- sequence: this.sequence,
19
- size: this.size,
20
- txid: this.txid,
21
- vout: this.vout,
22
- witness: this.witness?.data ?? null
23
- };
14
+ return this._txin;
24
15
  }
25
16
  get has_prevout() {
26
17
  return this._txin.prevout !== null;
@@ -1,8 +1,8 @@
1
- import type { TxOutput, TransactionOutputData } from '../types/index.js';
1
+ import type { TxOutput } from '../types/index.js';
2
2
  export declare class TransactionOutput {
3
3
  private readonly _txout;
4
4
  constructor(txout: TxOutput);
5
- get data(): TransactionOutputData;
5
+ get data(): TxOutput;
6
6
  get script_pk(): {
7
7
  hex: string;
8
8
  asm: string[];
@@ -11,6 +11,6 @@ export declare class TransactionOutput {
11
11
  get type(): import("../types/index.js").TxOutputType;
12
12
  get value(): bigint;
13
13
  get version(): import("../types/index.js").WitnessVersion;
14
- toJSON(): TransactionOutputData;
14
+ toJSON(): TxOutput;
15
15
  toString(): string;
16
16
  }
@@ -5,13 +5,7 @@ export class TransactionOutput {
5
5
  this._txout = txout;
6
6
  }
7
7
  get data() {
8
- return {
9
- script_pk: this.script_pk,
10
- size: this.size,
11
- type: this.type,
12
- value: this.value,
13
- version: this.version
14
- };
8
+ return this._txout;
15
9
  }
16
10
  get script_pk() {
17
11
  return {
@@ -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
@@ -9882,13 +9882,7 @@ class TransactionOutput {
9882
9882
  this._txout = txout;
9883
9883
  }
9884
9884
  get data() {
9885
- return {
9886
- script_pk: this.script_pk,
9887
- size: this.size,
9888
- type: this.type,
9889
- value: this.value,
9890
- version: this.version
9891
- };
9885
+ return this._txout;
9892
9886
  }
9893
9887
  get script_pk() {
9894
9888
  return {
@@ -9914,6 +9908,7 @@ class TransactionOutput {
9914
9908
 
9915
9909
  function parse_witness(witness) {
9916
9910
  const elems = witness.map(e => Buff.bytes(e));
9911
+ const stack = witness.map(e => Buff.bytes(e).hex);
9917
9912
  const annex = parse_annex_data(elems);
9918
9913
  if (annex !== null)
9919
9914
  elems.pop();
@@ -9926,7 +9921,7 @@ function parse_witness(witness) {
9926
9921
  if (script !== null)
9927
9922
  elems.pop();
9928
9923
  const params = elems.map(e => e.hex);
9929
- return { annex, cblock, params, script, type, version };
9924
+ return { annex, cblock, params, script, stack, type, version };
9930
9925
  }
9931
9926
  function parse_annex_data(data) {
9932
9927
  let elem = data.at(-1);
@@ -10022,16 +10017,7 @@ class TransactionWitness {
10022
10017
  return this._data.cblock;
10023
10018
  }
10024
10019
  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
- };
10020
+ return this._data;
10035
10021
  }
10036
10022
  get params() {
10037
10023
  return this._data.params;
@@ -10090,16 +10076,7 @@ class TransactionInput {
10090
10076
  return this._txin.coinbase;
10091
10077
  }
10092
10078
  get data() {
10093
- return {
10094
- coinbase: this.coinbase,
10095
- prevout: this.prevout?.data ?? null,
10096
- script_sig: this.script_sig,
10097
- sequence: this.sequence,
10098
- size: this.size,
10099
- txid: this.txid,
10100
- vout: this.vout,
10101
- witness: this.witness?.data ?? null
10102
- };
10079
+ return this._txin;
10103
10080
  }
10104
10081
  get has_prevout() {
10105
10082
  return this._txin.prevout !== null;
@@ -10146,7 +10123,7 @@ class TransactionInput {
10146
10123
  }
10147
10124
 
10148
10125
  let Transaction$1 = class Transaction {
10149
- constructor(txdata) {
10126
+ constructor(txdata = {}) {
10150
10127
  this._tx = (typeof txdata !== 'string')
10151
10128
  ? parse_tx(txdata)
10152
10129
  : decode_tx(txdata);
@@ -10158,18 +10135,7 @@ let Transaction$1 = class Transaction {
10158
10135
  this._vout = this._tx.vout.map(txout => new TransactionOutput(txout));
10159
10136
  }
10160
10137
  get data() {
10161
- return {
10162
- hash: this.hash,
10163
- locktime: this.locktime,
10164
- return: this.return,
10165
- size: this.size,
10166
- spends: this.spends,
10167
- txid: this.txid,
10168
- value: this.value,
10169
- version: this.version,
10170
- vin: this.vin.map(txin => txin.data),
10171
- vout: this.vout.map(txout => txout.data)
10172
- };
10138
+ return this._tx;
10173
10139
  }
10174
10140
  get hash() {
10175
10141
  return this._hash;
@@ -10207,16 +10173,19 @@ let Transaction$1 = class Transaction {
10207
10173
  get vout() {
10208
10174
  return this._vout;
10209
10175
  }
10210
- add_vin(txin) {
10176
+ add_vin(tx_input) {
10177
+ const txin = create_tx_input(tx_input);
10211
10178
  this._tx.vin.push(txin);
10212
10179
  this._update_vin();
10213
10180
  }
10214
- add_vout(txout) {
10181
+ add_vout(tx_output) {
10182
+ const txout = create_tx_output(tx_output);
10215
10183
  this._tx.vout.push(txout);
10216
10184
  this._update_vout();
10217
10185
  }
10218
- insert_vin(index, txin) {
10186
+ insert_vin(index, tx_input) {
10219
10187
  Assert.ok(index >= 0 && index <= this._tx.vin.length, 'input goes out of bounds');
10188
+ const txin = create_tx_input(tx_input);
10220
10189
  if (index === this._tx.vin.length) {
10221
10190
  this._tx.vin.push(txin);
10222
10191
  }
@@ -10225,8 +10194,9 @@ let Transaction$1 = class Transaction {
10225
10194
  }
10226
10195
  this._update_vin();
10227
10196
  }
10228
- insert_vout(index, txout) {
10197
+ insert_vout(index, tx_output) {
10229
10198
  Assert.ok(index >= 0 && index <= this._tx.vout.length, 'output goes out of bounds');
10199
+ const txout = create_tx_output(tx_output);
10230
10200
  if (index === this._tx.vout.length) {
10231
10201
  this._tx.vout.push(txout);
10232
10202
  }