@vbyte/btc-dev 1.0.2 → 1.0.4

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,55 +1,31 @@
1
- import { LocktimeInfo, SequenceInfo } from './meta.js';
2
- import { TxOutput } from './txdata.js';
1
+ import type { LocktimeData, SequenceData } from './meta.js';
2
+ import type { TxOutput, TxOutputType, TxSize, TxValue } from './txdata.js';
3
3
  import type { WitnessType, WitnessVersion } from './witness.js';
4
- export type TxOutputType = WitnessType | 'p2pkh' | 'p2sh' | 'opreturn';
5
- export interface TxOutputInfo {
6
- type: TxOutputType;
7
- version: WitnessVersion;
8
- }
9
- export interface TxInputInfo {
10
- type: WitnessType;
11
- version: WitnessVersion;
12
- }
13
4
  export interface LocktimeField {
14
5
  hex: string;
15
- data: LocktimeInfo | null;
6
+ data: LocktimeData | null;
16
7
  value: number;
17
8
  }
18
9
  export interface SequenceField {
19
10
  hex: string;
20
- data: SequenceInfo | null;
11
+ data: SequenceData | null;
21
12
  value: number;
22
13
  }
23
14
  export interface ScriptField {
24
15
  asm: string[];
25
16
  hex: string;
26
17
  }
27
- export interface TxSize {
28
- base: number;
29
- real: number;
30
- weight: number;
31
- vsize: number;
32
- }
33
- export interface TxValue {
34
- fees: bigint;
35
- vin: bigint;
36
- vout: bigint;
37
- }
38
- export interface WitnessSize {
39
- size: number;
40
- vsize: number;
41
- }
42
18
  export interface TransactionData {
43
19
  hash: string;
44
20
  locktime: LocktimeField;
45
21
  return: TxOutput | null;
46
22
  size: TxSize;
47
- spends: TxOutputField[];
23
+ spends: TransactionOutputData[];
48
24
  txid: string;
49
25
  value: TxValue;
50
26
  version: number;
51
- vin: TxInputField[];
52
- vout: TxOutputField[];
27
+ vin: TransactionInputData[];
28
+ vout: TransactionOutputData[];
53
29
  }
54
30
  export interface WitnessField {
55
31
  annex: string | null;
@@ -62,9 +38,9 @@ export interface WitnessField {
62
38
  version: WitnessVersion;
63
39
  vsize: number;
64
40
  }
65
- export interface TxInputField {
41
+ export interface TransactionInputData {
66
42
  coinbase?: string | null;
67
- prevout?: TxOutputField | null;
43
+ prevout?: TransactionOutputData | null;
68
44
  script_sig?: ScriptField | null;
69
45
  sequence: SequenceField;
70
46
  size: number;
@@ -72,7 +48,7 @@ export interface TxInputField {
72
48
  vout: number;
73
49
  witness?: WitnessField | null;
74
50
  }
75
- export interface TxOutputField {
51
+ export interface TransactionOutputData {
76
52
  script_pk: ScriptField;
77
53
  size: number;
78
54
  type: TxOutputType;
@@ -1,8 +1,8 @@
1
1
  export * from './address.js';
2
+ export * from './class.js';
2
3
  export * from './meta.js';
3
4
  export * from './psbt.js';
4
5
  export * from './sighash.js';
5
6
  export * from './taproot.js';
6
- export * from './transaction.js';
7
7
  export * from './txdata.js';
8
8
  export * from './witness.js';
@@ -1,8 +1,8 @@
1
1
  export * from './address.js';
2
+ export * from './class.js';
2
3
  export * from './meta.js';
3
4
  export * from './psbt.js';
4
5
  export * from './sighash.js';
5
6
  export * from './taproot.js';
6
- export * from './transaction.js';
7
7
  export * from './txdata.js';
8
8
  export * from './witness.js';
@@ -1,6 +1,6 @@
1
- export type LocktimeInfo = LocktimeStamp | LocktimeHeight;
2
- export type SequenceConfig = Partial<SequenceInfo>;
3
- export type SequenceInfo = SequenceHeightLock | SequenceStampLock;
1
+ export type LocktimeData = LocktimeStamp | LocktimeHeight;
2
+ export type SequenceConfig = Partial<SequenceData>;
3
+ export type SequenceData = SequenceHeightLock | SequenceStampLock;
4
4
  export interface LocktimeStamp {
5
5
  type: 'timelock';
6
6
  stamp: number;
@@ -1,4 +1,14 @@
1
+ import type { WitnessType, WitnessVersion } from './witness.js';
1
2
  export type TxInput = TxCoinbaseInput | TxSpendInput | TxVirtualInput;
3
+ export type TxOutputType = WitnessType | 'p2pkh' | 'p2sh' | 'opreturn';
4
+ export interface TxOutputInfo {
5
+ type: TxOutputType;
6
+ version: WitnessVersion;
7
+ }
8
+ export interface TxInputInfo {
9
+ type: WitnessType;
10
+ version: WitnessVersion;
11
+ }
2
12
  export interface TxOutpoint {
3
13
  txid: string;
4
14
  vout: number;
@@ -43,3 +53,14 @@ export interface TxData {
43
53
  vout: TxOutput[];
44
54
  version: number;
45
55
  }
56
+ export interface TxSize {
57
+ base: number;
58
+ real: number;
59
+ weight: number;
60
+ vsize: number;
61
+ }
62
+ export interface TxValue {
63
+ fees: bigint;
64
+ vin: bigint;
65
+ vout: bigint;
66
+ }
@@ -1,7 +1,11 @@
1
- export type WitnessContext = WitnessInfo | TaprootScript | SegwitScript | TaprootSpend | SegwitSpend;
1
+ export type WitnessContext = WitnessData | TaprootScript | SegwitScript | TaprootSpend | SegwitSpend;
2
2
  export type WitnessVersion = number | null;
3
3
  export type WitnessType = 'p2w-pkh' | 'p2w-sh' | 'p2tr-pk' | 'p2tr-ts' | 'unknown';
4
- export interface WitnessInfo {
4
+ export interface WitnessSize {
5
+ size: number;
6
+ vsize: number;
7
+ }
8
+ export interface WitnessData {
5
9
  annex: string | null;
6
10
  cblock: string | null;
7
11
  params: string[];
@@ -9,22 +13,22 @@ export interface WitnessInfo {
9
13
  type: WitnessType;
10
14
  version: WitnessVersion;
11
15
  }
12
- export interface TaprootScript extends WitnessInfo {
16
+ export interface TaprootScript extends WitnessData {
13
17
  cblock: string;
14
18
  script: string;
15
19
  type: 'p2tr-ts';
16
20
  version: 1;
17
21
  }
18
- export interface SegwitScript extends WitnessInfo {
22
+ export interface SegwitScript extends WitnessData {
19
23
  script: string;
20
24
  type: 'p2w-sh';
21
25
  version: 0;
22
26
  }
23
- export interface TaprootSpend extends WitnessInfo {
27
+ export interface TaprootSpend extends WitnessData {
24
28
  type: 'p2tr-pk';
25
29
  version: 1;
26
30
  }
27
- export interface SegwitSpend extends WitnessInfo {
31
+ export interface SegwitSpend extends WitnessData {
28
32
  type: 'p2w-pkh';
29
33
  version: 0;
30
34
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vbyte/btc-dev",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Batteries-included toolset for plebian bitcoin development",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -42,8 +42,8 @@
42
42
  "import": "./dist/lib/address/index.js"
43
43
  },
44
44
  "./meta": {
45
- "types": "./dist/lib/meta.d.ts",
46
- "import": "./dist/lib/meta.js"
45
+ "types": "./dist/lib/meta/index.d.ts",
46
+ "import": "./dist/lib/meta/index.js"
47
47
  },
48
48
  "./psbt": {
49
49
  "types": "./dist/lib/psbt/index.d.ts",
package/src/class/txin.ts CHANGED
@@ -10,7 +10,7 @@ import {
10
10
 
11
11
  import type {
12
12
  TxInput,
13
- TxInputField
13
+ TransactionInputData
14
14
  } from '@/types/index.js'
15
15
 
16
16
  export class TransactionInput {
@@ -31,7 +31,7 @@ export class TransactionInput {
31
31
  return this._txin.coinbase
32
32
  }
33
33
 
34
- get data () : TxInputField {
34
+ get data () : TransactionInputData {
35
35
  return {
36
36
  coinbase : this.coinbase,
37
37
  prevout : this.prevout?.data ?? null,
@@ -5,7 +5,7 @@ import {
5
5
  get_vout_info
6
6
  } from '@/lib/tx/index.js'
7
7
 
8
- import type { TxOutput, TxOutputField, TxOutputInfo } from '@/types/index.js'
8
+ import type { TxOutput, TransactionOutputData, TxOutputInfo } from '@/types/index.js'
9
9
 
10
10
  export class TransactionOutput {
11
11
 
@@ -19,7 +19,7 @@ export class TransactionOutput {
19
19
  this._txout = txout
20
20
  }
21
21
 
22
- get data () : TxOutputField {
22
+ get data () : TransactionOutputData {
23
23
  return {
24
24
  script_pk : this.script_pk,
25
25
  size : this.size,
@@ -9,7 +9,7 @@ import {
9
9
  import type {
10
10
  ScriptField,
11
11
  WitnessField,
12
- WitnessInfo,
12
+ WitnessData,
13
13
  WitnessSize,
14
14
  WitnessType
15
15
  } from '@/types/index.js'
@@ -17,7 +17,7 @@ import type {
17
17
  export class TransactionWitness {
18
18
 
19
19
  private readonly _data : Buff[]
20
- private readonly _meta : WitnessInfo
20
+ private readonly _meta : WitnessData
21
21
  private readonly _size : WitnessSize
22
22
 
23
23
  constructor (witness : Bytes[]) {
@@ -1,6 +1,6 @@
1
1
  import { Assert } from '@vbyte/micro-lib'
2
2
 
3
- import type { LocktimeInfo } from '@/types/index.js'
3
+ import type { LocktimeData } from '@/types/index.js'
4
4
 
5
5
  // The threshold between block height and timestamp.
6
6
  const LOCKTIME_THRESHOLD = 500000000
@@ -15,7 +15,7 @@ export namespace LocktimeUtil {
15
15
  * According to BIP-65, the value is simply the numeric value as a string.
16
16
  */
17
17
  export function encode_locktime (
18
- locktime : LocktimeInfo
18
+ locktime : LocktimeData
19
19
  ) : number {
20
20
  switch (locktime.type) {
21
21
  case 'timelock':
@@ -37,7 +37,7 @@ export function encode_locktime (
37
37
  */
38
38
  export function decode_locktime (
39
39
  locktime : number
40
- ) : LocktimeInfo | null {
40
+ ) : LocktimeData | null {
41
41
  // Check if the value is valid (non-negative)
42
42
  if (isNaN(locktime) || locktime <= 0) {
43
43
  return null
@@ -11,7 +11,7 @@
11
11
  * that allows additional metadata to be encoded in the sequence field (to be used by on-chain indexers).
12
12
  */
13
13
 
14
- import type { SequenceConfig, SequenceInfo } from '@/types/index.js'
14
+ import type { SequenceConfig, SequenceData } from '@/types/index.js'
15
15
 
16
16
  /* ===== [ Constants ] ===================================================== */
17
17
 
@@ -65,7 +65,7 @@ export function encode_sequence (data : SequenceConfig): number {
65
65
  * @returns A SequenceData object or null if the sequence doesn't represent special data
66
66
  * @throws Error if the sequence value is invalid or exceeds maximum values
67
67
  */
68
- export function decode_sequence (sequence: number | string) : SequenceInfo | null {
68
+ export function decode_sequence (sequence: number | string) : SequenceData | null {
69
69
  // Parse and validate the sequence value.
70
70
  const seq = parse_sequence(sequence)
71
71
  // If the sequence is disabled, return null.
@@ -3,13 +3,13 @@ import { is_valid_script } from '@/lib/script/decode.js'
3
3
  import { TAPLEAF_VERSIONS } from '@/const.js'
4
4
 
5
5
  import type {
6
- WitnessInfo,
6
+ WitnessData,
7
7
  WitnessType
8
8
  } from '@/types/index.js'
9
9
 
10
10
  export function parse_witness_data (
11
11
  witness : Bytes[]
12
- ) : WitnessInfo {
12
+ ) : WitnessData {
13
13
  // Parse the witness data.
14
14
  const elems = witness.map(e => Buff.bytes(e))
15
15
  const annex = parse_annex_data(elems)
@@ -0,0 +1,64 @@
1
+ import type { LocktimeData, SequenceData } from './meta.js'
2
+ import type { TxOutput, TxOutputType, TxSize, TxValue } from './txdata.js'
3
+ import type { WitnessType, WitnessVersion } from './witness.js'
4
+
5
+ export interface LocktimeField {
6
+ hex : string
7
+ data : LocktimeData | null
8
+ value : number
9
+ }
10
+
11
+ export interface SequenceField {
12
+ hex : string
13
+ data : SequenceData | null
14
+ value : number
15
+ }
16
+
17
+ export interface ScriptField {
18
+ asm : string[]
19
+ hex : string
20
+ }
21
+
22
+ export interface TransactionData {
23
+ hash : string
24
+ locktime : LocktimeField
25
+ return : TxOutput | null
26
+ size : TxSize
27
+ spends : TransactionOutputData[]
28
+ txid : string
29
+ value : TxValue
30
+ version : number
31
+ vin : TransactionInputData[]
32
+ vout : TransactionOutputData[]
33
+ }
34
+
35
+ export interface WitnessField {
36
+ annex : string | null
37
+ cblock : string | null
38
+ params : string[]
39
+ script : ScriptField | null
40
+ size : number
41
+ stack : string[]
42
+ type : WitnessType
43
+ version : WitnessVersion
44
+ vsize : number
45
+ }
46
+
47
+ export interface TransactionInputData {
48
+ coinbase? : string | null
49
+ prevout? : TransactionOutputData | null
50
+ script_sig? : ScriptField | null
51
+ sequence : SequenceField
52
+ size : number
53
+ txid : string
54
+ vout : number
55
+ witness? : WitnessField | null
56
+ }
57
+
58
+ export interface TransactionOutputData {
59
+ script_pk : ScriptField
60
+ size : number
61
+ type : TxOutputType
62
+ value : bigint
63
+ version : WitnessVersion | null
64
+ }
@@ -1,8 +1,8 @@
1
1
  export * from './address.js'
2
+ export * from './class.js'
2
3
  export * from './meta.js'
3
4
  export * from './psbt.js'
4
5
  export * from './sighash.js'
5
6
  export * from './taproot.js'
6
- export * from './transaction.js'
7
7
  export * from './txdata.js'
8
8
  export * from './witness.js'
package/src/types/meta.ts CHANGED
@@ -1,6 +1,6 @@
1
- export type LocktimeInfo = LocktimeStamp | LocktimeHeight
2
- export type SequenceConfig = Partial<SequenceInfo>
3
- export type SequenceInfo = SequenceHeightLock | SequenceStampLock
1
+ export type LocktimeData = LocktimeStamp | LocktimeHeight
2
+ export type SequenceConfig = Partial<SequenceData>
3
+ export type SequenceData = SequenceHeightLock | SequenceStampLock
4
4
 
5
5
  export interface LocktimeStamp {
6
6
  type : 'timelock' // Discriminator for timelock type
@@ -1,4 +1,17 @@
1
- export type TxInput = TxCoinbaseInput | TxSpendInput | TxVirtualInput
1
+ import type { WitnessType, WitnessVersion } from './witness.js'
2
+
3
+ export type TxInput = TxCoinbaseInput | TxSpendInput | TxVirtualInput
4
+ export type TxOutputType = WitnessType | 'p2pkh' | 'p2sh' | 'opreturn'
5
+
6
+ export interface TxOutputInfo {
7
+ type : TxOutputType
8
+ version : WitnessVersion
9
+ }
10
+
11
+ export interface TxInputInfo {
12
+ type : WitnessType
13
+ version : WitnessVersion
14
+ }
2
15
 
3
16
  export interface TxOutpoint {
4
17
  txid : string
@@ -51,3 +64,16 @@ export interface TxData {
51
64
  vout : TxOutput[]
52
65
  version : number
53
66
  }
67
+
68
+ export interface TxSize {
69
+ base : number
70
+ real : number
71
+ weight : number
72
+ vsize : number
73
+ }
74
+
75
+ export interface TxValue {
76
+ fees : bigint
77
+ vin : bigint
78
+ vout : bigint
79
+ }
@@ -1,8 +1,13 @@
1
- export type WitnessContext = WitnessInfo | TaprootScript | SegwitScript | TaprootSpend | SegwitSpend
1
+ export type WitnessContext = WitnessData | TaprootScript | SegwitScript | TaprootSpend | SegwitSpend
2
2
  export type WitnessVersion = number | null
3
3
  export type WitnessType = 'p2w-pkh' | 'p2w-sh' | 'p2tr-pk' | 'p2tr-ts' | 'unknown'
4
4
 
5
- export interface WitnessInfo {
5
+ export interface WitnessSize {
6
+ size : number
7
+ vsize : number
8
+ }
9
+
10
+ export interface WitnessData {
6
11
  annex : string | null
7
12
  cblock : string | null
8
13
  params : string[]
@@ -11,25 +16,25 @@ export interface WitnessInfo {
11
16
  version : WitnessVersion
12
17
  }
13
18
 
14
- export interface TaprootScript extends WitnessInfo {
19
+ export interface TaprootScript extends WitnessData {
15
20
  cblock : string
16
21
  script : string
17
22
  type : 'p2tr-ts'
18
23
  version : 1
19
24
  }
20
25
 
21
- export interface SegwitScript extends WitnessInfo {
26
+ export interface SegwitScript extends WitnessData {
22
27
  script : string
23
28
  type : 'p2w-sh'
24
29
  version : 0
25
30
  }
26
31
 
27
- export interface TaprootSpend extends WitnessInfo {
32
+ export interface TaprootSpend extends WitnessData {
28
33
  type : 'p2tr-pk'
29
34
  version : 1
30
35
  }
31
36
 
32
- export interface SegwitSpend extends WitnessInfo {
37
+ export interface SegwitSpend extends WitnessData {
33
38
  type : 'p2w-pkh'
34
39
  version : 0
35
40
  }
@@ -1,98 +0,0 @@
1
- import { LocktimeInfo, SequenceInfo } from './meta.js'
2
- import { TxOutput } from './txdata.js'
3
-
4
- import type {
5
- WitnessType,
6
- WitnessVersion
7
- } from './witness.js'
8
-
9
- export type TxOutputType = WitnessType | 'p2pkh' | 'p2sh' | 'opreturn'
10
-
11
- export interface TxOutputInfo {
12
- type : TxOutputType
13
- version : WitnessVersion
14
- }
15
-
16
- export interface TxInputInfo {
17
- type : WitnessType
18
- version : WitnessVersion
19
- }
20
-
21
- export interface LocktimeField {
22
- hex : string
23
- data : LocktimeInfo | null
24
- value : number
25
- }
26
-
27
- export interface SequenceField {
28
- hex : string
29
- data : SequenceInfo | null
30
- value : number
31
- }
32
-
33
- export interface ScriptField {
34
- asm : string[]
35
- hex : string
36
- }
37
-
38
- export interface TxSize {
39
- base : number
40
- real : number
41
- weight : number
42
- vsize : number
43
- }
44
-
45
- export interface TxValue {
46
- fees : bigint
47
- vin : bigint
48
- vout : bigint
49
- }
50
-
51
- export interface WitnessSize {
52
- size : number
53
- vsize : number
54
- }
55
-
56
- export interface TransactionData {
57
- hash : string
58
- locktime : LocktimeField
59
- return : TxOutput | null
60
- size : TxSize
61
- spends : TxOutputField[]
62
- txid : string
63
- value : TxValue
64
- version : number
65
- vin : TxInputField[]
66
- vout : TxOutputField[]
67
- }
68
-
69
- export interface WitnessField {
70
- annex : string | null
71
- cblock : string | null
72
- params : string[]
73
- script : ScriptField | null
74
- size : number
75
- stack : string[]
76
- type : WitnessType
77
- version : WitnessVersion
78
- vsize : number
79
- }
80
-
81
- export interface TxInputField {
82
- coinbase? : string | null
83
- prevout? : TxOutputField | null
84
- script_sig? : ScriptField | null
85
- sequence : SequenceField
86
- size : number
87
- txid : string
88
- vout : number
89
- witness? : WitnessField | null
90
- }
91
-
92
- export interface TxOutputField {
93
- script_pk : ScriptField
94
- size : number
95
- type : TxOutputType
96
- value : bigint
97
- version : WitnessVersion | null
98
- }
File without changes