@vbyte/btc-dev 1.1.1 → 1.1.2

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,8 +1,9 @@
1
+ import { Bytes } from '@vbyte/buff';
1
2
  import type { TxData, TxOutput, TxOutputInfo, TxOutputTemplate, TxOutputType, TxValue, WitnessVersion } from '../../types/index.js';
2
- export declare function is_return_script(script: string): boolean;
3
- export declare function get_vout_info(txout: TxOutput): TxOutputInfo;
4
- export declare function get_vout_type(script: string): TxOutputType;
5
- export declare function get_vout_version(script: string): WitnessVersion;
3
+ export declare function is_return_script(script: Bytes): boolean;
4
+ export declare function get_vout_script_info(script: Bytes): TxOutputInfo;
5
+ export declare function get_vout_script_type(script: Bytes): TxOutputType | null;
6
+ export declare function get_vout_script_version(script: Bytes): WitnessVersion | null;
6
7
  export declare function get_txid(txdata: TxData): string;
7
8
  export declare function get_txhash(txdata: TxData): string;
8
9
  export declare function get_tx_value(txdata: TxData): TxValue;
@@ -6,26 +6,28 @@ import { encode_tx } from './encode.js';
6
6
  import { assert_tx_template } from './validate.js';
7
7
  import { DEFAULT, LOCK_SCRIPT_REGEX } from '../../const.js';
8
8
  export function is_return_script(script) {
9
- return script.startsWith('6a');
9
+ const bytes = Buff.bytes(script);
10
+ return bytes.at(0) === 0x6a;
10
11
  }
11
- export function get_vout_info(txout) {
12
+ export function get_vout_script_info(script) {
12
13
  return {
13
- type: get_vout_type(txout.script_pk),
14
- version: get_vout_version(txout.script_pk)
14
+ type: get_vout_script_type(script),
15
+ version: get_vout_script_version(script)
15
16
  };
16
17
  }
17
- export function get_vout_type(script) {
18
+ export function get_vout_script_type(script) {
19
+ const hex = Buff.bytes(script).hex;
18
20
  for (const [type, regex] of Object.entries(LOCK_SCRIPT_REGEX)) {
19
- if (regex.test(script))
21
+ if (regex.test(hex))
20
22
  return type;
21
23
  }
22
- return 'unknown';
24
+ return null;
23
25
  }
24
- export function get_vout_version(script) {
25
- const wit_ver = script.slice(0, 4);
26
- switch (wit_ver) {
27
- case '0014': return 0;
28
- case '5120': return 1;
26
+ export function get_vout_script_version(script) {
27
+ const version = Buff.bytes(script);
28
+ switch (version.at(0)) {
29
+ case 0x00: return 0;
30
+ case 0x51: return 1;
29
31
  default: return null;
30
32
  }
31
33
  }
package/dist/main.cjs CHANGED
@@ -9679,26 +9679,28 @@ function encode_script_data(script) {
9679
9679
  }
9680
9680
 
9681
9681
  function is_return_script(script) {
9682
- return script.startsWith('6a');
9682
+ const bytes = Buff.bytes(script);
9683
+ return bytes.at(0) === 0x6a;
9683
9684
  }
9684
- function get_vout_info(txout) {
9685
+ function get_vout_script_info(script) {
9685
9686
  return {
9686
- type: get_vout_type(txout.script_pk),
9687
- version: get_vout_version(txout.script_pk)
9687
+ type: get_vout_script_type(script),
9688
+ version: get_vout_script_version(script)
9688
9689
  };
9689
9690
  }
9690
- function get_vout_type(script) {
9691
+ function get_vout_script_type(script) {
9692
+ const hex = Buff.bytes(script).hex;
9691
9693
  for (const [type, regex] of Object.entries(LOCK_SCRIPT_REGEX)) {
9692
- if (regex.test(script))
9694
+ if (regex.test(hex))
9693
9695
  return type;
9694
9696
  }
9695
- return 'unknown';
9697
+ return null;
9696
9698
  }
9697
- function get_vout_version(script) {
9698
- const wit_ver = script.slice(0, 4);
9699
- switch (wit_ver) {
9700
- case '0014': return 0;
9701
- case '5120': return 1;
9699
+ function get_vout_script_version(script) {
9700
+ const version = Buff.bytes(script);
9701
+ switch (version.at(0)) {
9702
+ case 0x00: return 0;
9703
+ case 0x51: return 1;
9702
9704
  default: return null;
9703
9705
  }
9704
9706
  }
@@ -10007,10 +10009,10 @@ var index$4 = /*#__PURE__*/Object.freeze({
10007
10009
  get_txout_size: get_txout_size,
10008
10010
  get_txsize: get_txsize,
10009
10011
  get_vin_size: get_vin_size,
10010
- get_vout_info: get_vout_info,
10012
+ get_vout_script_info: get_vout_script_info,
10013
+ get_vout_script_type: get_vout_script_type,
10014
+ get_vout_script_version: get_vout_script_version,
10011
10015
  get_vout_size: get_vout_size,
10012
- get_vout_type: get_vout_type,
10013
- get_vout_version: get_vout_version,
10014
10016
  get_vsize: get_vsize,
10015
10017
  is_return_script: is_return_script,
10016
10018
  normalize_prevout: normalize_prevout,