@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.
@@ -2,10 +2,10 @@ import type { WitnessType, WitnessVersion } from './witness.js';
2
2
  export type LocktimeData = LocktimeStamp | LocktimeHeight;
3
3
  export type SequenceConfig = Partial<SequenceData>;
4
4
  export type SequenceData = SequenceHeightLock | SequenceStampLock;
5
- export type TxOutputType = WitnessType | 'p2pkh' | 'p2sh' | 'opreturn';
5
+ export type TxOutputType = 'p2pkh' | 'p2sh' | 'p2w-pkh' | 'p2w-sh' | 'p2tr' | 'opreturn';
6
6
  export interface TxOutputInfo {
7
- type: TxOutputType;
8
- version: WitnessVersion;
7
+ type: TxOutputType | null;
8
+ version: WitnessVersion | null;
9
9
  }
10
10
  export interface TxInputInfo {
11
11
  type: WitnessType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vbyte/btc-dev",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Batteries-included toolset for plebian bitcoin development",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -1,4 +1,4 @@
1
- import { Buff } from '@vbyte/buff'
1
+ import { Buff, Bytes } from '@vbyte/buff'
2
2
  import { Test } from '@vbyte/micro-lib'
3
3
  import { Assert } from '@vbyte/micro-lib/assert'
4
4
  import { hash256 } from '@vbyte/micro-lib/hash'
@@ -17,34 +17,36 @@ import type {
17
17
  WitnessVersion
18
18
  } from '@/types/index.js'
19
19
 
20
- export function is_return_script (script : string) : boolean {
21
- return script.startsWith('6a')
20
+ export function is_return_script (script : Bytes) : boolean {
21
+ const bytes = Buff.bytes(script)
22
+ return bytes.at(0) === 0x6a
22
23
  }
23
24
 
24
- export function get_vout_info (txout : TxOutput) : TxOutputInfo {
25
+ export function get_vout_script_info (script : Bytes) : TxOutputInfo {
25
26
  return {
26
- type : get_vout_type(txout.script_pk),
27
- version : get_vout_version(txout.script_pk)
27
+ type : get_vout_script_type(script),
28
+ version : get_vout_script_version(script)
28
29
  }
29
30
  }
30
31
 
31
- export function get_vout_type (
32
- script : string
33
- ) : TxOutputType {
32
+ export function get_vout_script_type (
33
+ script : Bytes
34
+ ) : TxOutputType | null {
35
+ const hex = Buff.bytes(script).hex
34
36
  for (const [ type, regex ] of Object.entries(LOCK_SCRIPT_REGEX)) {
35
- if (regex.test(script)) return type as TxOutputType
37
+ if (regex.test(hex)) return type as TxOutputType
36
38
  }
37
- return 'unknown'
39
+ return null
38
40
  }
39
41
 
40
- export function get_vout_version (
41
- script : string
42
- ) : WitnessVersion {
43
- const wit_ver = script.slice(0, 4)
44
- switch (wit_ver) {
45
- case '0014' : return 0
46
- case '5120' : return 1
47
- default : return null
42
+ export function get_vout_script_version (
43
+ script : Bytes
44
+ ) : WitnessVersion | null{
45
+ const version = Buff.bytes(script)
46
+ switch (version.at(0)) {
47
+ case 0x00 : return 0
48
+ case 0x51 : return 1
49
+ default : return null
48
50
  }
49
51
  }
50
52
 
package/src/types/meta.ts CHANGED
@@ -3,11 +3,11 @@ import type{ WitnessType, WitnessVersion } from './witness.js'
3
3
  export type LocktimeData = LocktimeStamp | LocktimeHeight
4
4
  export type SequenceConfig = Partial<SequenceData>
5
5
  export type SequenceData = SequenceHeightLock | SequenceStampLock
6
- export type TxOutputType = WitnessType | 'p2pkh' | 'p2sh' | 'opreturn'
6
+ export type TxOutputType = 'p2pkh' | 'p2sh' | 'p2w-pkh' | 'p2w-sh' | 'p2tr' | 'opreturn'
7
7
 
8
8
  export interface TxOutputInfo {
9
- type : TxOutputType
10
- version : WitnessVersion
9
+ type : TxOutputType | null
10
+ version : WitnessVersion | null
11
11
  }
12
12
 
13
13
  export interface TxInputInfo {