@vbyte/btc-dev 1.0.1 → 1.0.3

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.
Files changed (100) hide show
  1. package/dist/class/signer.js +1 -1
  2. package/dist/class/tx.js +5 -4
  3. package/dist/class/txin.js +3 -2
  4. package/dist/class/witness.js +1 -1
  5. package/dist/index.d.ts +8 -6
  6. package/dist/index.js +8 -6
  7. package/dist/lib/meta/index.d.ts +3 -1
  8. package/dist/lib/meta/index.js +3 -1
  9. package/dist/lib/{tx → meta}/locktime.d.ts +1 -1
  10. package/dist/lib/{tx → meta}/locktime.js +5 -5
  11. package/dist/lib/meta/{pointer.d.ts → ref.d.ts} +1 -1
  12. package/dist/lib/meta/{pointer.js → ref.js} +6 -6
  13. package/dist/lib/meta/scribe.d.ts +1 -1
  14. package/dist/lib/meta/scribe.js +5 -5
  15. package/dist/lib/{tx → meta}/sequence.d.ts +1 -1
  16. package/dist/lib/{tx → meta}/sequence.js +5 -5
  17. package/dist/lib/sighash/index.d.ts +0 -2
  18. package/dist/lib/sighash/index.js +0 -2
  19. package/dist/lib/sighash/segwit.js +2 -2
  20. package/dist/lib/sighash/taproot.js +2 -2
  21. package/dist/lib/signer/index.d.ts +2 -0
  22. package/dist/lib/signer/index.js +2 -0
  23. package/dist/lib/{sighash → signer}/sign.js +6 -6
  24. package/dist/lib/signer/verify.d.ts +4 -0
  25. package/dist/lib/signer/verify.js +8 -0
  26. package/dist/lib/taproot/parse.js +1 -1
  27. package/dist/lib/tx/create.d.ts +4 -4
  28. package/dist/lib/tx/create.js +1 -1
  29. package/dist/lib/tx/decode.d.ts +1 -1
  30. package/dist/lib/tx/decode.js +1 -1
  31. package/dist/lib/tx/encode.d.ts +1 -1
  32. package/dist/lib/tx/encode.js +3 -3
  33. package/dist/lib/tx/index.d.ts +1 -4
  34. package/dist/lib/tx/index.js +1 -4
  35. package/dist/lib/tx/parse.d.ts +1 -1
  36. package/dist/lib/tx/parse.js +5 -5
  37. package/dist/lib/tx/size.d.ts +1 -2
  38. package/dist/lib/tx/size.js +5 -12
  39. package/dist/lib/tx/{meta.js → util.js} +7 -7
  40. package/dist/lib/tx/validate.d.ts +2 -2
  41. package/dist/lib/witness/index.d.ts +2 -0
  42. package/dist/lib/witness/index.js +2 -0
  43. package/dist/lib/witness/util.d.ts +3 -0
  44. package/dist/lib/witness/util.js +8 -0
  45. package/dist/main.cjs +1002 -980
  46. package/dist/main.cjs.map +1 -1
  47. package/dist/module.mjs +993 -973
  48. package/dist/module.mjs.map +1 -1
  49. package/dist/package.json +11 -7
  50. package/dist/script.js +1 -1
  51. package/dist/script.js.map +1 -1
  52. package/dist/types/address.d.ts +1 -1
  53. package/dist/types/index.d.ts +0 -1
  54. package/dist/types/index.js +0 -1
  55. package/dist/types/meta.d.ts +19 -0
  56. package/dist/types/transaction.d.ts +1 -1
  57. package/dist/types/txdata.d.ts +4 -4
  58. package/package.json +11 -7
  59. package/src/class/signer.ts +1 -1
  60. package/src/class/tx.ts +6 -6
  61. package/src/class/txin.ts +2 -2
  62. package/src/class/witness.ts +1 -1
  63. package/src/index.ts +8 -6
  64. package/src/lib/meta/index.ts +3 -1
  65. package/src/lib/{tx → meta}/locktime.ts +1 -1
  66. package/src/lib/meta/{pointer.ts → ref.ts} +1 -1
  67. package/src/lib/meta/scribe.ts +1 -1
  68. package/src/lib/{tx → meta}/sequence.ts +1 -1
  69. package/src/lib/sighash/index.ts +0 -2
  70. package/src/lib/sighash/segwit.ts +2 -2
  71. package/src/lib/sighash/taproot.ts +2 -2
  72. package/src/lib/signer/index.ts +2 -0
  73. package/src/lib/{sighash → signer}/sign.ts +6 -6
  74. package/src/lib/{sighash → signer}/verify.ts +22 -0
  75. package/src/lib/taproot/parse.ts +1 -1
  76. package/src/lib/tx/create.ts +5 -5
  77. package/src/lib/tx/decode.ts +7 -7
  78. package/src/lib/tx/encode.ts +3 -3
  79. package/src/lib/tx/index.ts +1 -4
  80. package/src/lib/tx/parse.ts +5 -5
  81. package/src/lib/tx/size.ts +7 -16
  82. package/src/lib/tx/{meta.ts → util.ts} +7 -7
  83. package/src/lib/tx/validate.ts +2 -2
  84. package/src/lib/witness/index.ts +2 -0
  85. package/src/lib/witness/util.ts +12 -0
  86. package/src/types/address.ts +1 -1
  87. package/src/types/index.ts +0 -1
  88. package/src/types/meta.ts +26 -0
  89. package/src/types/transaction.ts +2 -2
  90. package/src/types/txdata.ts +4 -4
  91. package/dist/lib/sighash/verify.d.ts +0 -1
  92. package/dist/lib/sighash/verify.js +0 -1
  93. package/dist/types/txmeta.d.ts +0 -19
  94. package/dist/types/txmeta.js +0 -1
  95. package/src/types/txmeta.ts +0 -25
  96. /package/dist/lib/{sighash → signer}/sign.d.ts +0 -0
  97. /package/dist/lib/tx/{meta.d.ts → util.d.ts} +0 -0
  98. /package/dist/lib/{tx/witness.d.ts → witness/parse.d.ts} +0 -0
  99. /package/dist/lib/{tx/witness.js → witness/parse.js} +0 -0
  100. /package/src/lib/{tx/witness.ts → witness/parse.ts} +0 -0
@@ -1,6 +1,6 @@
1
1
  import { Buff } from '@vbyte/buff';
2
2
  import { ECC } from '@vbyte/micro-lib';
3
- import { sign_segwit_tx, sign_taproot_tx } from '../lib/sighash/sign.js';
3
+ import { sign_segwit_tx, sign_taproot_tx } from '../lib/signer/sign.js';
4
4
  export class TxSigner {
5
5
  constructor(seckey) {
6
6
  this._seckey = Buff.bytes(seckey).hex;
package/dist/class/tx.js CHANGED
@@ -1,11 +1,12 @@
1
+ import { LocktimeUtil } from '../lib/meta/index.js';
1
2
  import { TransactionInput } from './txin.js';
2
3
  import { TransactionOutput } from './txout.js';
3
- import { decode_tx_data, get_txid, is_return_script, parse_tx_data, Locktime, get_txsize, get_tx_value, get_txhash, encode_tx_locktime, } from '../lib/tx/index.js';
4
+ 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';
4
5
  export class Transaction {
5
6
  constructor(txdata) {
6
7
  this._tx = (typeof txdata !== 'string')
7
- ? parse_tx_data(txdata)
8
- : decode_tx_data(txdata);
8
+ ? parse_tx(txdata)
9
+ : decode_tx(txdata);
9
10
  this._vin = this._tx.vin.map(txin => new TransactionInput(txin));
10
11
  this._vout = this._tx.vout.map(txout => new TransactionOutput(txout));
11
12
  this._size = get_txsize(this._tx);
@@ -32,7 +33,7 @@ export class Transaction {
32
33
  get locktime() {
33
34
  return {
34
35
  hex: encode_tx_locktime(this._tx.locktime).hex,
35
- data: Locktime.decode(this._tx.locktime),
36
+ data: LocktimeUtil.decode(this._tx.locktime),
36
37
  value: this._tx.locktime
37
38
  };
38
39
  }
@@ -1,7 +1,8 @@
1
1
  import { decode_script } from '../lib/script/index.js';
2
+ import { SequenceUtil } from '../lib/meta/index.js';
2
3
  import { TransactionOutput } from './txout.js';
3
4
  import { TransactionWitness } from './witness.js';
4
- import { encode_txin_sequence, get_txin_size, Sequence } from '../lib/tx/index.js';
5
+ import { encode_txin_sequence, get_txin_size, } from '../lib/tx/index.js';
5
6
  export class TransactionInput {
6
7
  constructor(txin) {
7
8
  this._size = get_txin_size(txin);
@@ -47,7 +48,7 @@ export class TransactionInput {
47
48
  get sequence() {
48
49
  return {
49
50
  hex: encode_txin_sequence(this._txin.sequence).hex,
50
- data: Sequence.decode(this._txin.sequence),
51
+ data: SequenceUtil.decode(this._txin.sequence),
51
52
  value: this._txin.sequence
52
53
  };
53
54
  }
@@ -1,6 +1,6 @@
1
1
  import { Buff } from '@vbyte/buff';
2
2
  import { decode_script } from '../lib/script/index.js';
3
- import { parse_witness_data, get_witness_size, } from '../lib/tx/index.js';
3
+ import { parse_witness_data, get_witness_size, } from '../lib/witness/index.js';
4
4
  export class TransactionWitness {
5
5
  constructor(witness) {
6
6
  this._data = witness.map(e => Buff.bytes(e));
package/dist/index.d.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  export * from './class/index.js';
2
- export * as Address from './lib/address/index.js';
3
- export * as Meta from './lib/meta/index.js';
2
+ export * as ADDRESS from './lib/address/index.js';
3
+ export * as META from './lib/meta/index.js';
4
4
  export * as PSBT from './lib/psbt/index.js';
5
- export * as Script from './lib/script/index.js';
6
- export * as Sighash from './lib/sighash/index.js';
7
- export * as Taproot from './lib/taproot/index.js';
8
- export * as Tx from './lib/tx/index.js';
5
+ export * as SCRIPT from './lib/script/index.js';
6
+ export * as SIGHASH from './lib/sighash/index.js';
7
+ export * as SIGNER from './lib/signer/index.js';
8
+ export * as TAPROOT from './lib/taproot/index.js';
9
+ export * as TX from './lib/tx/index.js';
10
+ export * as WITNESS from './lib/witness/index.js';
9
11
  export * as CONST from './const.js';
10
12
  export * as SCHEMA from './schema/index.js';
11
13
  export type * from './types/index.js';
package/dist/index.js CHANGED
@@ -1,10 +1,12 @@
1
1
  export * from './class/index.js';
2
- export * as Address from './lib/address/index.js';
3
- export * as Meta from './lib/meta/index.js';
2
+ export * as ADDRESS from './lib/address/index.js';
3
+ export * as META from './lib/meta/index.js';
4
4
  export * as PSBT from './lib/psbt/index.js';
5
- export * as Script from './lib/script/index.js';
6
- export * as Sighash from './lib/sighash/index.js';
7
- export * as Taproot from './lib/taproot/index.js';
8
- export * as Tx from './lib/tx/index.js';
5
+ export * as SCRIPT from './lib/script/index.js';
6
+ export * as SIGHASH from './lib/sighash/index.js';
7
+ export * as SIGNER from './lib/signer/index.js';
8
+ export * as TAPROOT from './lib/taproot/index.js';
9
+ export * as TX from './lib/tx/index.js';
10
+ export * as WITNESS from './lib/witness/index.js';
9
11
  export * as CONST from './const.js';
10
12
  export * as SCHEMA from './schema/index.js';
@@ -1,2 +1,4 @@
1
- export * from './pointer.js';
1
+ export * from './locktime.js';
2
+ export * from './ref.js';
2
3
  export * from './scribe.js';
4
+ export * from './sequence.js';
@@ -1,2 +1,4 @@
1
- export * from './pointer.js';
1
+ export * from './locktime.js';
2
+ export * from './ref.js';
2
3
  export * from './scribe.js';
4
+ export * from './sequence.js';
@@ -1,5 +1,5 @@
1
1
  import type { LocktimeInfo } from '../../types/index.js';
2
- export declare namespace Locktime {
2
+ export declare namespace LocktimeUtil {
3
3
  const encode: typeof encode_locktime;
4
4
  const decode: typeof decode_locktime;
5
5
  }
@@ -1,10 +1,10 @@
1
1
  import { Assert } from '@vbyte/micro-lib';
2
2
  const LOCKTIME_THRESHOLD = 500000000;
3
- export var Locktime;
4
- (function (Locktime) {
5
- Locktime.encode = encode_locktime;
6
- Locktime.decode = decode_locktime;
7
- })(Locktime || (Locktime = {}));
3
+ export var LocktimeUtil;
4
+ (function (LocktimeUtil) {
5
+ LocktimeUtil.encode = encode_locktime;
6
+ LocktimeUtil.decode = decode_locktime;
7
+ })(LocktimeUtil || (LocktimeUtil = {}));
8
8
  export function encode_locktime(locktime) {
9
9
  switch (locktime.type) {
10
10
  case 'timelock':
@@ -1,4 +1,4 @@
1
- export declare namespace TxPointer {
1
+ export declare namespace RefEncoder {
2
2
  const outpoint: {
3
3
  encode: typeof encode_outpoint;
4
4
  decode: typeof decode_outpoint;
@@ -1,24 +1,24 @@
1
- export var TxPointer;
2
- (function (TxPointer) {
3
- TxPointer.outpoint = {
1
+ export var RefEncoder;
2
+ (function (RefEncoder) {
3
+ RefEncoder.outpoint = {
4
4
  encode: encode_outpoint,
5
5
  decode: decode_outpoint,
6
6
  verify: verify_outpoint,
7
7
  assert: assert_outpoint,
8
8
  };
9
- TxPointer.record_id = {
9
+ RefEncoder.record_id = {
10
10
  encode: encode_inscription_id,
11
11
  decode: decode_inscription_id,
12
12
  verify: verify_inscription_id,
13
13
  assert: assert_inscription_id,
14
14
  };
15
- TxPointer.rune_id = {
15
+ RefEncoder.rune_id = {
16
16
  encode: encode_rune_id,
17
17
  decode: decode_rune_id,
18
18
  verify: verify_rune_id,
19
19
  assert: assert_rune_id,
20
20
  };
21
- })(TxPointer || (TxPointer = {}));
21
+ })(RefEncoder || (RefEncoder = {}));
22
22
  function encode_inscription_id(txid, order = 0) {
23
23
  return `${txid}i${order}`;
24
24
  }
@@ -1,5 +1,5 @@
1
1
  import type { InscriptionData } from '../../types/index.js';
2
- export declare namespace Inscription {
2
+ export declare namespace ScribeEncoder {
3
3
  const encode: typeof encode_inscription;
4
4
  const decode: typeof decode_inscription;
5
5
  }
@@ -5,11 +5,11 @@ import { decode_script } from '../../lib/script/decode.js';
5
5
  const _0n = BigInt(0);
6
6
  const _1n = BigInt(1);
7
7
  const _26n = BigInt(26);
8
- export var Inscription;
9
- (function (Inscription) {
10
- Inscription.encode = encode_inscription;
11
- Inscription.decode = decode_inscription;
12
- })(Inscription || (Inscription = {}));
8
+ export var ScribeEncoder;
9
+ (function (ScribeEncoder) {
10
+ ScribeEncoder.encode = encode_inscription;
11
+ ScribeEncoder.decode = decode_inscription;
12
+ })(ScribeEncoder || (ScribeEncoder = {}));
13
13
  export function decode_inscription(script) {
14
14
  const envelopes = parse_envelopes(script);
15
15
  return envelopes.map(parse_record);
@@ -1,5 +1,5 @@
1
1
  import type { SequenceConfig, SequenceInfo } from '../../types/index.js';
2
- export declare namespace Sequence {
2
+ export declare namespace SequenceUtil {
3
3
  const encode: typeof encode_sequence;
4
4
  const decode: typeof decode_sequence;
5
5
  }
@@ -3,11 +3,11 @@ const TIMELOCK_TYPE = 0x00400000;
3
3
  const TIMELOCK_VALUE_MASK = 0x0000FFFF;
4
4
  const TIMELOCK_VALUE_MAX = 0xFFFF;
5
5
  const TIMELOCK_GRANULARITY = 512;
6
- export var Sequence;
7
- (function (Sequence) {
8
- Sequence.encode = encode_sequence;
9
- Sequence.decode = decode_sequence;
10
- })(Sequence || (Sequence = {}));
6
+ export var SequenceUtil;
7
+ (function (SequenceUtil) {
8
+ SequenceUtil.encode = encode_sequence;
9
+ SequenceUtil.decode = decode_sequence;
10
+ })(SequenceUtil || (SequenceUtil = {}));
11
11
  export function encode_sequence(data) {
12
12
  if (data.mode === 'height') {
13
13
  const height = parse_height(data.height);
@@ -1,5 +1,3 @@
1
1
  export * from './segwit.js';
2
- export * from './sign.js';
3
2
  export * from './taproot.js';
4
- export * from './verify.js';
5
3
  export * from './util.js';
@@ -1,5 +1,3 @@
1
1
  export * from './segwit.js';
2
- export * from './sign.js';
3
2
  export * from './taproot.js';
4
- export * from './verify.js';
5
3
  export * from './util.js';
@@ -3,11 +3,11 @@ import { hash160, hash256 } from '@vbyte/micro-lib/hash';
3
3
  import { Assert } from '@vbyte/micro-lib';
4
4
  import { parse_txinput } from './util.js';
5
5
  import { prefix_script_size, decode_script } from '../../lib/script/index.js';
6
- import { encode_txin_vout, encode_tx_locktime, encode_txin_sequence, encode_txin_txid, encode_vout_value, encode_tx_version, parse_tx_data } from '../../lib/tx/index.js';
6
+ import { encode_txin_vout, encode_tx_locktime, encode_txin_sequence, encode_txin_txid, encode_vout_value, encode_tx_version, parse_tx } from '../../lib/tx/index.js';
7
7
  import * as CONST from '../../const.js';
8
8
  export function hash_segwit_tx(txdata, options = {}) {
9
9
  const { sigflag = 0x01, txindex } = options;
10
- const tx = parse_tx_data(txdata);
10
+ const tx = parse_tx(txdata);
11
11
  const is_anypay = (sigflag & 0x80) === 0x80;
12
12
  const flag = sigflag % 0x80;
13
13
  if (!CONST.SIGHASH_SEGWIT.includes(flag)) {
@@ -3,13 +3,13 @@ import { Assert } from '@vbyte/micro-lib';
3
3
  import { hash340, sha256 } from '@vbyte/micro-lib/hash';
4
4
  import { prefix_script_size } from '../../lib/script/util.js';
5
5
  import { encode_tapscript } from '../../lib/taproot/encode.js';
6
- import { parse_tx_data } from '../../lib/tx/parse.js';
6
+ import { parse_tx } from '../../lib/tx/parse.js';
7
7
  import * as CONST from '../../const.js';
8
8
  import { parse_txinput } from './util.js';
9
9
  import { encode_txin_vout, encode_tx_locktime, encode_txin_sequence, encode_txin_txid, encode_vout_value, encode_tx_version } from '../../lib/tx/encode.js';
10
10
  export function hash_taproot_tx(template, config = {}) {
11
11
  const { script, txindex, sigflag = 0x00, extflag = 0x00, key_version = 0x00, separator_pos = 0xFFFFFFFF } = config;
12
- const tx = parse_tx_data(template);
12
+ const tx = parse_tx(template);
13
13
  const { version, vin: input, vout: output, locktime } = tx;
14
14
  const txinput = parse_txinput(tx, config);
15
15
  const { txid, vout, sequence, witness = [] } = txinput;
@@ -0,0 +1,2 @@
1
+ export * from './sign.js';
2
+ export * from './verify.js';
@@ -0,0 +1,2 @@
1
+ export * from './sign.js';
2
+ export * from './verify.js';
@@ -1,18 +1,18 @@
1
1
  import { ECC } from '@vbyte/micro-lib';
2
- import { parse_tx_data } from '../../lib/tx/parse.js';
2
+ import { parse_tx } from '../../lib/tx/parse.js';
3
3
  import { SIGHASH_DEFAULT } from '../../const.js';
4
- import { hash_segwit_tx } from './segwit.js';
5
- import { hash_taproot_tx } from './taproot.js';
6
- import { format_sigflag } from './util.js';
4
+ import { hash_segwit_tx } from '../sighash/segwit.js';
5
+ import { hash_taproot_tx } from '../sighash/taproot.js';
6
+ import { format_sigflag } from '../sighash/util.js';
7
7
  export function sign_segwit_tx(seckey, txdata, options) {
8
- const tx = parse_tx_data(txdata);
8
+ const tx = parse_tx(txdata);
9
9
  const msg = hash_segwit_tx(tx, options);
10
10
  const sig = ECC.sign_ecdsa(seckey, msg).hex;
11
11
  const flag = format_sigflag(options.sigflag ?? SIGHASH_DEFAULT);
12
12
  return sig + flag;
13
13
  }
14
14
  export function sign_taproot_tx(seckey, txdata, options) {
15
- const tx = parse_tx_data(txdata);
15
+ const tx = parse_tx(txdata);
16
16
  const msg = hash_taproot_tx(tx, options);
17
17
  const sig = ECC.sign_bip340(seckey, msg).hex;
18
18
  const flag = format_sigflag(options.sigflag ?? 0);
@@ -0,0 +1,4 @@
1
+ import { Bytes } from '@vbyte/buff';
2
+ import type { SigHashOptions, TxData } from '../../types/index.js';
3
+ export declare function verify_segwit_tx(_txdata: TxData | Bytes, _config?: SigHashOptions): boolean;
4
+ export declare function verify_taproot_tx(_txdata: TxData | Bytes, _config?: SigHashOptions): boolean;
@@ -0,0 +1,8 @@
1
+ export function verify_segwit_tx(_txdata, _config = {}) {
2
+ console.warn('verify_segwit_tx is not implemented');
3
+ return true;
4
+ }
5
+ export function verify_taproot_tx(_txdata, _config = {}) {
6
+ console.warn('verify_taproot_tx is not implemented');
7
+ return true;
8
+ }
@@ -1,6 +1,6 @@
1
1
  import { Buff, Stream } from '@vbyte/buff';
2
2
  import { Assert, ECC } from '@vbyte/micro-lib';
3
- import { parse_witness_data } from '../../lib/tx/witness.js';
3
+ import { parse_witness_data } from '../../lib/witness/parse.js';
4
4
  import { encode_tapbranch, encode_tapscript, encode_taptweak, } from './encode.js';
5
5
  export function parse_taproot_witness(witness) {
6
6
  const { cblock, params, script } = parse_witness_data(witness);
@@ -1,6 +1,6 @@
1
- import type { TxData, TxInputTemplate, TxInput, TxOutput, TxTemplate, SpendInput, CoinbaseInput } from '../../types/index.js';
2
- export declare function create_coinbase_input(config: TxInputTemplate | TxInput): CoinbaseInput;
3
- export declare function create_spend_input(config: TxInputTemplate | TxInput): SpendInput;
1
+ import type { TxData, TxInputTemplate, TxInput, TxOutput, TxTemplate, TxSpendInput, TxCoinbaseInput } from '../../types/index.js';
2
+ export declare function create_coinbase_input(config: TxInputTemplate | TxInput): TxCoinbaseInput;
3
+ export declare function create_spend_input(config: TxInputTemplate | TxInput): TxSpendInput;
4
4
  export declare function create_tx_input(config: TxInputTemplate | TxInput): TxInput;
5
5
  export declare function create_tx_output(config: TxOutput): TxOutput;
6
- export declare function create_tx_data(config: TxTemplate | TxData): TxData;
6
+ export declare function create_tx(config: TxTemplate | TxData): TxData;
@@ -43,7 +43,7 @@ export function create_tx_output(config) {
43
43
  const { script_pk, value } = config;
44
44
  return { script_pk, value: BigInt(value) };
45
45
  }
46
- export function create_tx_data(config) {
46
+ export function create_tx(config) {
47
47
  assert_tx_template(config);
48
48
  const { vin = [], vout = [] } = config;
49
49
  const locktime = config.locktime ?? DEFAULT.LOCKTIME;
@@ -4,6 +4,6 @@ interface TxEncoderConfig {
4
4
  prevouts: TxOutput[];
5
5
  segwit: boolean;
6
6
  }
7
- export declare function decode_tx_data(txbytes: Bytes, options?: Partial<TxEncoderConfig>): TxData;
7
+ export declare function decode_tx(txbytes: Bytes, options?: Partial<TxEncoderConfig>): TxData;
8
8
  export declare function read_script(stream: Stream, varint?: boolean): string | null;
9
9
  export {};
@@ -6,7 +6,7 @@ const DEFAULT_CONFIG = {
6
6
  prevouts: [],
7
7
  segwit: true
8
8
  };
9
- export function decode_tx_data(txbytes, options = {}) {
9
+ export function decode_tx(txbytes, options = {}) {
10
10
  const config = { ...DEFAULT_CONFIG, ...options };
11
11
  Assert.is_bytes(txbytes, 'txbytes must be hex or a unit array');
12
12
  const stream = new Stream(txbytes);
@@ -1,6 +1,6 @@
1
1
  import { Buff } from '@vbyte/buff';
2
2
  import { TxInput, TxOutput, TxData } from '../../types/index.js';
3
- export declare function encode_tx_data(txdata: TxData, segwit?: boolean): Buff;
3
+ export declare function encode_tx(txdata: TxData, segwit?: boolean): Buff;
4
4
  export declare function encode_tx_version(num: number): Buff;
5
5
  export declare function encode_txin_txid(txid: string): Buff;
6
6
  export declare function encode_txin_vout(vout: number): Buff;
@@ -1,9 +1,9 @@
1
1
  import { Buff } from '@vbyte/buff';
2
2
  import { Assert } from '@vbyte/micro-lib';
3
- import { parse_tx_data } from './parse.js';
3
+ import { parse_tx } from './parse.js';
4
4
  import { COINBASE } from '../../const.js';
5
- export function encode_tx_data(txdata, segwit = true) {
6
- const tx = parse_tx_data(txdata);
5
+ export function encode_tx(txdata, segwit = true) {
6
+ const tx = parse_tx(txdata);
7
7
  const { version, vin, vout, locktime } = tx;
8
8
  const buffer = [encode_tx_version(version)];
9
9
  if (segwit) {
@@ -1,10 +1,7 @@
1
1
  export * from './create.js';
2
2
  export * from './decode.js';
3
3
  export * from './encode.js';
4
- export * from './locktime.js';
5
- export * from './meta.js';
4
+ export * from './util.js';
6
5
  export * from './parse.js';
7
- export * from './sequence.js';
8
6
  export * from './size.js';
9
7
  export * from './validate.js';
10
- export * from './witness.js';
@@ -1,10 +1,7 @@
1
1
  export * from './create.js';
2
2
  export * from './decode.js';
3
3
  export * from './encode.js';
4
- export * from './locktime.js';
5
- export * from './meta.js';
4
+ export * from './util.js';
6
5
  export * from './parse.js';
7
- export * from './sequence.js';
8
6
  export * from './size.js';
9
7
  export * from './validate.js';
10
- export * from './witness.js';
@@ -1,2 +1,2 @@
1
1
  import type { TxData } from '../../types/index.js';
2
- export declare function parse_tx_data(txdata: unknown): TxData;
2
+ export declare function parse_tx(txdata: unknown): TxData;
@@ -1,12 +1,12 @@
1
- import { decode_tx_data } from './decode.js';
2
- import { create_tx_data } from './create.js';
1
+ import { decode_tx } from './decode.js';
2
+ import { create_tx } from './create.js';
3
3
  import { assert_tx_template } from './validate.js';
4
- export function parse_tx_data(txdata) {
4
+ export function parse_tx(txdata) {
5
5
  if (typeof txdata === 'string') {
6
- return decode_tx_data(txdata);
6
+ return decode_tx(txdata);
7
7
  }
8
8
  else {
9
9
  assert_tx_template(txdata);
10
- return create_tx_data(txdata);
10
+ return create_tx(txdata);
11
11
  }
12
12
  }
@@ -1,5 +1,5 @@
1
1
  import { Bytes } from '@vbyte/buff';
2
- import type { TxData, TxInput, TxOutput, TxSize, WitnessSize } from '../../types/index.js';
2
+ import type { TxData, TxInput, TxOutput, TxSize } from '../../types/index.js';
3
3
  export declare function get_vsize(bytes: Bytes): number;
4
4
  export declare function get_txsize(txdata: string | TxData): TxSize;
5
5
  export declare function get_vin_size(vin: TxInput[]): number;
@@ -7,4 +7,3 @@ export declare function get_vout_size(vout: TxOutput[]): number;
7
7
  export declare function get_segwit_size(txinputs: TxInput[]): number;
8
8
  export declare function get_txin_size(txinput: TxInput): number;
9
9
  export declare function get_txout_size(txoutput: TxOutput): number;
10
- export declare function get_witness_size(witness: Bytes[]): WitnessSize;
@@ -1,17 +1,16 @@
1
1
  import { Buff } from '@vbyte/buff';
2
- import { parse_tx_data } from './parse.js';
3
- import { encode_tx_data, encode_tx_inputs, encode_tx_outputs, encode_tx_vout, encode_vin, encode_vin_witness } from './encode.js';
2
+ import { parse_tx } from './parse.js';
3
+ import { encode_tx, encode_tx_inputs, encode_tx_outputs, encode_tx_vout, encode_vin, encode_vin_witness } from './encode.js';
4
4
  const WIT_FLAG_BYTES = 2;
5
- const WIT_LENGTH_BYTE = 1;
6
5
  export function get_vsize(bytes) {
7
6
  const weight = Buff.bytes(bytes).length;
8
7
  const remain = (weight % 4 > 0) ? 1 : 0;
9
8
  return Math.floor(weight / 4) + remain;
10
9
  }
11
10
  export function get_txsize(txdata) {
12
- const json = parse_tx_data(txdata);
13
- const base = encode_tx_data(json, false).length;
14
- const size = encode_tx_data(json, true).length;
11
+ const json = parse_tx(txdata);
12
+ const base = encode_tx(json, false).length;
13
+ const size = encode_tx(json, true).length;
15
14
  const weight = base * 3 + size;
16
15
  const remain = (weight % 4 > 0) ? 1 : 0;
17
16
  const vsize = Math.floor(weight / 4) + remain;
@@ -40,9 +39,3 @@ export function get_txout_size(txoutput) {
40
39
  const bytes = encode_tx_vout(txoutput);
41
40
  return bytes.length;
42
41
  }
43
- export function get_witness_size(witness) {
44
- const stack = witness.map(e => Buff.bytes(e));
45
- const size = stack.reduce((prev, next) => prev + next.length, 0);
46
- const vsize = Math.ceil(WIT_LENGTH_BYTE + size / 4);
47
- return { size, vsize };
48
- }
@@ -1,7 +1,7 @@
1
1
  import { hash256 } from '@vbyte/micro-lib/hash';
2
2
  import { LOCK_SCRIPT_REGEX } from '../../const.js';
3
- import { encode_tx_data } from './encode.js';
4
- import { parse_tx_data } from './parse.js';
3
+ import { encode_tx } from './encode.js';
4
+ import { parse_tx } from './parse.js';
5
5
  export function is_return_script(script) {
6
6
  return script.startsWith('6a');
7
7
  }
@@ -30,17 +30,17 @@ export function get_vout_version(script) {
30
30
  }
31
31
  }
32
32
  export function get_txid(txdata) {
33
- const json = parse_tx_data(txdata);
34
- const data = encode_tx_data(json, false);
33
+ const json = parse_tx(txdata);
34
+ const data = encode_tx(json, false);
35
35
  return hash256(data).reverse().hex;
36
36
  }
37
37
  export function get_txhash(txdata) {
38
- const json = parse_tx_data(txdata);
39
- const data = encode_tx_data(json, true);
38
+ const json = parse_tx(txdata);
39
+ const data = encode_tx(json, true);
40
40
  return hash256(data).reverse().hex;
41
41
  }
42
42
  export function get_tx_value(txdata) {
43
- const tx = parse_tx_data(txdata);
43
+ const tx = parse_tx(txdata);
44
44
  const vin = tx.vin.reduce((acc, txin) => acc + (txin.prevout?.value ?? 0n), 0n);
45
45
  const vout = tx.vout.reduce((acc, txout) => acc + txout.value, 0n);
46
46
  const fees = (vin > vout) ? (vin - vout) : 0n;
@@ -1,6 +1,6 @@
1
- import { SpendInput, TxData, TxInput, TxInputTemplate, TxOutput, TxTemplate } from '../../types/index.js';
1
+ import { TxSpendInput, TxData, TxInput, TxInputTemplate, TxOutput, TxTemplate } from '../../types/index.js';
2
2
  export declare function assert_tx_template(txdata: unknown): asserts txdata is TxTemplate;
3
- export declare function assert_has_prevouts(vin: TxInput[]): asserts vin is SpendInput[];
3
+ export declare function assert_has_prevouts(vin: TxInput[]): asserts vin is TxSpendInput[];
4
4
  export declare function assert_tx_data(txdata: unknown): asserts txdata is TxData;
5
5
  export declare function assert_tx_input(tx_input: unknown): asserts tx_input is TxInput;
6
6
  export declare function assert_tx_output(tx_output: unknown): asserts tx_output is TxOutput;
@@ -0,0 +1,2 @@
1
+ export * from './parse.js';
2
+ export * from './util.js';
@@ -0,0 +1,2 @@
1
+ export * from './parse.js';
2
+ export * from './util.js';
@@ -0,0 +1,3 @@
1
+ import { Bytes } from '@vbyte/buff';
2
+ import type { WitnessSize } from '../../types/index.js';
3
+ export declare function get_witness_size(witness: Bytes[]): WitnessSize;
@@ -0,0 +1,8 @@
1
+ import { Buff } from '@vbyte/buff';
2
+ const WIT_LENGTH_BYTE = 1;
3
+ export function get_witness_size(witness) {
4
+ const stack = witness.map(e => Buff.bytes(e));
5
+ const size = stack.reduce((prev, next) => prev + next.length, 0);
6
+ const vsize = Math.ceil(WIT_LENGTH_BYTE + size / 4);
7
+ return { size, vsize };
8
+ }