@vbyte/btc-dev 1.1.7 → 2.0.0

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 (174) hide show
  1. package/CHANGELOG.md +94 -0
  2. package/README.md +260 -3
  3. package/dist/const.d.ts +3 -0
  4. package/dist/const.js +23 -22
  5. package/dist/index.d.ts +11 -11
  6. package/dist/index.js +10 -10
  7. package/dist/lib/address/api.d.ts +2 -2
  8. package/dist/lib/address/api.js +12 -12
  9. package/dist/lib/address/encode.d.ts +1 -1
  10. package/dist/lib/address/encode.js +24 -24
  11. package/dist/lib/address/index.d.ts +6 -6
  12. package/dist/lib/address/index.js +6 -6
  13. package/dist/lib/address/p2pkh.d.ts +2 -2
  14. package/dist/lib/address/p2pkh.js +14 -14
  15. package/dist/lib/address/p2sh.d.ts +2 -2
  16. package/dist/lib/address/p2sh.js +13 -13
  17. package/dist/lib/address/p2tr.d.ts +2 -2
  18. package/dist/lib/address/p2tr.js +13 -13
  19. package/dist/lib/address/p2wpkh.d.ts +2 -2
  20. package/dist/lib/address/p2wpkh.js +14 -14
  21. package/dist/lib/address/p2wsh.d.ts +2 -2
  22. package/dist/lib/address/p2wsh.js +13 -13
  23. package/dist/lib/address/script.d.ts +1 -1
  24. package/dist/lib/address/script.js +16 -16
  25. package/dist/lib/address/util.d.ts +1 -1
  26. package/dist/lib/address/util.js +22 -22
  27. package/dist/lib/meta/index.d.ts +4 -4
  28. package/dist/lib/meta/index.js +4 -4
  29. package/dist/lib/meta/locktime.d.ts +1 -1
  30. package/dist/lib/meta/locktime.js +12 -12
  31. package/dist/lib/meta/ref.js +9 -6
  32. package/dist/lib/meta/scribe.d.ts +2 -2
  33. package/dist/lib/meta/scribe.js +48 -53
  34. package/dist/lib/meta/sequence.d.ts +1 -1
  35. package/dist/lib/meta/sequence.js +16 -15
  36. package/dist/lib/script/decode.d.ts +2 -2
  37. package/dist/lib/script/decode.js +50 -15
  38. package/dist/lib/script/encode.d.ts +1 -1
  39. package/dist/lib/script/encode.js +20 -16
  40. package/dist/lib/script/index.d.ts +5 -13
  41. package/dist/lib/script/index.js +5 -14
  42. package/dist/lib/script/lock.d.ts +2 -2
  43. package/dist/lib/script/lock.js +15 -12
  44. package/dist/lib/script/util.js +4 -4
  45. package/dist/lib/script/words.js +129 -129
  46. package/dist/lib/sighash/index.d.ts +3 -3
  47. package/dist/lib/sighash/index.js +3 -3
  48. package/dist/lib/sighash/segwit.d.ts +2 -2
  49. package/dist/lib/sighash/segwit.js +15 -14
  50. package/dist/lib/sighash/taproot.d.ts +2 -2
  51. package/dist/lib/sighash/taproot.js +24 -23
  52. package/dist/lib/sighash/util.d.ts +2 -2
  53. package/dist/lib/sighash/util.js +7 -7
  54. package/dist/lib/signer/index.d.ts +2 -2
  55. package/dist/lib/signer/index.js +2 -2
  56. package/dist/lib/signer/sign.d.ts +1 -1
  57. package/dist/lib/signer/sign.js +42 -7
  58. package/dist/lib/signer/verify.d.ts +17 -3
  59. package/dist/lib/signer/verify.js +233 -3
  60. package/dist/lib/taproot/cblock.d.ts +1 -1
  61. package/dist/lib/taproot/cblock.js +14 -16
  62. package/dist/lib/taproot/encode.d.ts +1 -1
  63. package/dist/lib/taproot/encode.js +7 -7
  64. package/dist/lib/taproot/index.d.ts +4 -4
  65. package/dist/lib/taproot/index.js +4 -4
  66. package/dist/lib/taproot/parse.d.ts +1 -1
  67. package/dist/lib/taproot/parse.js +12 -14
  68. package/dist/lib/taproot/tree.d.ts +2 -2
  69. package/dist/lib/taproot/tree.js +11 -7
  70. package/dist/lib/tx/create.d.ts +1 -1
  71. package/dist/lib/tx/create.js +28 -12
  72. package/dist/lib/tx/decode.d.ts +2 -2
  73. package/dist/lib/tx/decode.js +50 -17
  74. package/dist/lib/tx/encode.d.ts +2 -2
  75. package/dist/lib/tx/encode.js +13 -16
  76. package/dist/lib/tx/index.d.ts +7 -7
  77. package/dist/lib/tx/index.js +7 -7
  78. package/dist/lib/tx/parse.d.ts +1 -1
  79. package/dist/lib/tx/parse.js +9 -9
  80. package/dist/lib/tx/size.d.ts +2 -2
  81. package/dist/lib/tx/size.js +9 -9
  82. package/dist/lib/tx/util.d.ts +2 -2
  83. package/dist/lib/tx/util.js +23 -22
  84. package/dist/lib/tx/validate.d.ts +1 -1
  85. package/dist/lib/tx/validate.js +3 -3
  86. package/dist/lib/witness/index.d.ts +2 -2
  87. package/dist/lib/witness/index.js +2 -2
  88. package/dist/lib/witness/parse.d.ts +2 -2
  89. package/dist/lib/witness/parse.js +24 -23
  90. package/dist/lib/witness/util.d.ts +2 -2
  91. package/dist/lib/witness/util.js +5 -5
  92. package/dist/main.cjs +2308 -1007
  93. package/dist/main.cjs.map +1 -1
  94. package/dist/module.mjs +2308 -1007
  95. package/dist/module.mjs.map +1 -1
  96. package/dist/package.json +20 -17
  97. package/dist/schema/base.d.ts +1 -1
  98. package/dist/schema/base.js +17 -13
  99. package/dist/schema/index.d.ts +2 -2
  100. package/dist/schema/index.js +2 -2
  101. package/dist/schema/taproot.d.ts +1 -1
  102. package/dist/schema/taproot.js +2 -2
  103. package/dist/schema/tx.d.ts +1 -1
  104. package/dist/schema/tx.js +4 -4
  105. package/dist/script.js +8 -8
  106. package/dist/script.js.map +1 -1
  107. package/dist/types/address.d.ts +4 -4
  108. package/dist/types/index.d.ts +8 -8
  109. package/dist/types/index.js +8 -8
  110. package/dist/types/meta.d.ts +4 -4
  111. package/dist/types/psbt.d.ts +2 -2
  112. package/dist/types/script.d.ts +2 -2
  113. package/dist/types/sighash.d.ts +2 -2
  114. package/dist/types/witness.d.ts +5 -5
  115. package/package.json +20 -17
  116. package/src/const.ts +0 -61
  117. package/src/index.ts +0 -13
  118. package/src/lib/address/api.ts +0 -50
  119. package/src/lib/address/encode.ts +0 -183
  120. package/src/lib/address/index.ts +0 -7
  121. package/src/lib/address/p2pkh.ts +0 -94
  122. package/src/lib/address/p2sh.ts +0 -96
  123. package/src/lib/address/p2tr.ts +0 -91
  124. package/src/lib/address/p2wpkh.ts +0 -94
  125. package/src/lib/address/p2wsh.ts +0 -92
  126. package/src/lib/address/script.ts +0 -63
  127. package/src/lib/address/util.ts +0 -87
  128. package/src/lib/meta/index.ts +0 -4
  129. package/src/lib/meta/locktime.ts +0 -57
  130. package/src/lib/meta/ref.ts +0 -107
  131. package/src/lib/meta/scribe.ts +0 -256
  132. package/src/lib/meta/sequence.ts +0 -146
  133. package/src/lib/script/decode.ts +0 -85
  134. package/src/lib/script/encode.ts +0 -129
  135. package/src/lib/script/index.ts +0 -20
  136. package/src/lib/script/lock.ts +0 -73
  137. package/src/lib/script/util.ts +0 -78
  138. package/src/lib/script/words.ts +0 -182
  139. package/src/lib/sighash/index.ts +0 -3
  140. package/src/lib/sighash/segwit.ts +0 -152
  141. package/src/lib/sighash/taproot.ts +0 -206
  142. package/src/lib/sighash/util.ts +0 -51
  143. package/src/lib/signer/index.ts +0 -2
  144. package/src/lib/signer/sign.ts +0 -39
  145. package/src/lib/signer/verify.ts +0 -88
  146. package/src/lib/taproot/cblock.ts +0 -96
  147. package/src/lib/taproot/encode.ts +0 -49
  148. package/src/lib/taproot/index.ts +0 -4
  149. package/src/lib/taproot/parse.ts +0 -65
  150. package/src/lib/taproot/tree.ts +0 -94
  151. package/src/lib/tx/create.ts +0 -90
  152. package/src/lib/tx/decode.ts +0 -123
  153. package/src/lib/tx/encode.ts +0 -155
  154. package/src/lib/tx/index.ts +0 -7
  155. package/src/lib/tx/parse.ts +0 -69
  156. package/src/lib/tx/size.ts +0 -68
  157. package/src/lib/tx/util.ts +0 -113
  158. package/src/lib/tx/validate.ts +0 -49
  159. package/src/lib/witness/index.ts +0 -2
  160. package/src/lib/witness/parse.ts +0 -127
  161. package/src/lib/witness/util.ts +0 -18
  162. package/src/schema/base.ts +0 -57
  163. package/src/schema/index.ts +0 -2
  164. package/src/schema/taproot.ts +0 -12
  165. package/src/schema/tx.ts +0 -48
  166. package/src/types/address.ts +0 -35
  167. package/src/types/index.ts +0 -8
  168. package/src/types/meta.ts +0 -48
  169. package/src/types/psbt.ts +0 -15
  170. package/src/types/script.ts +0 -18
  171. package/src/types/sighash.ts +0 -16
  172. package/src/types/taproot.ts +0 -41
  173. package/src/types/txdata.ts +0 -85
  174. package/src/types/witness.ts +0 -42
package/src/schema/tx.ts DELETED
@@ -1,48 +0,0 @@
1
- import { z } from 'zod'
2
-
3
- import { hex, hex32, uint } from './base.js'
4
-
5
- import type { TxOutput, TxOutputTemplate } from '@/types/index.js'
6
-
7
- const sats = z.bigint().min(0n).max(2_100_000_000_000_000n)
8
-
9
- export const tx_output = z.object({
10
- value : sats,
11
- script_pk : hex,
12
- }) satisfies z.ZodType<TxOutput>
13
-
14
- export const tx_input = z.object({
15
- coinbase : hex.nullable(),
16
- txid : hex32,
17
- vout : uint,
18
- prevout : tx_output.nullable(),
19
- script_sig : hex.nullable(),
20
- sequence : uint,
21
- witness : z.array(hex)
22
- })
23
-
24
- export const tx_data = z.object({
25
- version : uint,
26
- vin : z.array(tx_input),
27
- vout : z.array(tx_output),
28
- locktime : uint,
29
- })
30
-
31
- export const vout_template = tx_output.extend({
32
- value : z.union([ uint, sats ])
33
- }) satisfies z.ZodType<TxOutputTemplate>
34
-
35
- export const vin_template = tx_input.extend({
36
- coinbase : hex.nullable().optional(),
37
- prevout : vout_template.nullable().optional(),
38
- script_sig : hex.nullable().optional(),
39
- sequence : z.union([ hex, uint ]).optional(),
40
- witness : z.array(hex).optional(),
41
- })
42
-
43
- export const tx_template = z.object({
44
- version : uint.optional(),
45
- vin : z.array(vin_template),
46
- vout : z.array(vout_template),
47
- locktime : uint.optional(),
48
- })
@@ -1,35 +0,0 @@
1
- import type { ScriptInfo } from './script.js'
2
-
3
- export type AddressFormat = 'base58' | 'bech32' | 'bech32m'
4
- export type AddressType = 'p2pkh' | 'p2sh' | 'p2wpkh' | 'p2wsh' | 'p2tr'
5
- export type ChainNetwork = 'main' | 'testnet' | 'regtest' | string
6
-
7
- export type AddressConfigEntry = [
8
- prefix : string,
9
- type : AddressType,
10
- network : ChainNetwork,
11
- size : number,
12
- format : AddressFormat,
13
- version : number
14
- ]
15
-
16
- export interface EncoderConfig {
17
- format : AddressFormat
18
- data : Uint8Array
19
- prefix? : string
20
- version? : number
21
- }
22
-
23
- export interface AddressConfig {
24
- format : AddressFormat
25
- network : ChainNetwork
26
- prefix : string
27
- size : number
28
- type : AddressType
29
- version : number
30
- }
31
-
32
- export interface AddressInfo extends AddressConfig {
33
- data : string
34
- script : ScriptInfo
35
- }
@@ -1,8 +0,0 @@
1
- export * from './address.js'
2
- export * from './meta.js'
3
- export * from './psbt.js'
4
- export * from './script.js'
5
- export * from './sighash.js'
6
- export * from './taproot.js'
7
- export * from './txdata.js'
8
- export * from './witness.js'
package/src/types/meta.ts DELETED
@@ -1,48 +0,0 @@
1
- export type LocktimeData = LocktimeStamp | LocktimeHeight
2
- export type SequenceConfig = Partial<SequenceData>
3
- export type SequenceData = SequenceHeightLock | SequenceStampLock
4
-
5
- export interface LocktimeStamp {
6
- type : 'timelock' // Discriminator for timelock type
7
- stamp : number // Unix timestamp in seconds
8
- }
9
-
10
- export interface LocktimeHeight {
11
- type : 'heightlock' // Discriminator for heightlock type
12
- height : number // Block height value
13
- }
14
-
15
- // Represents a timestamp-based relative timelock.
16
- export interface SequenceStampLock {
17
- stamp : number // Unix timestamp in seconds.
18
- mode : 'stamp' // Discriminator for timelock mode.
19
- }
20
-
21
- // Represents a block-height-based relative timelock.
22
- export interface SequenceHeightLock {
23
- height : number // Block height.
24
- mode : 'height' // Discriminator for heightlock mode.
25
- }
26
-
27
- export interface LocktimeField {
28
- hex : string
29
- data : LocktimeData | null
30
- value : number
31
- }
32
-
33
- export interface SequenceField {
34
- hex : string
35
- data : SequenceData | null
36
- value : number
37
- }
38
-
39
- export interface InscriptionData {
40
- content ?: string
41
- delegate ?: string
42
- mimetype ?: string
43
- opcode ?: number
44
- parent ?: string
45
- pointer ?: number
46
- ref ?: string
47
- rune ?: string
48
- }
package/src/types/psbt.ts DELETED
@@ -1,15 +0,0 @@
1
- import type { Transaction } from '@scure/btc-signer'
2
-
3
- import type {
4
- TransactionInput,
5
- TransactionOutput
6
- } from '@scure/btc-signer/psbt'
7
-
8
- export type PSBTData = Transaction
9
- export type PSBTInput = TransactionInput
10
- export type PSBTOutput = TransactionOutput
11
-
12
- export interface PSBTPrevouts {
13
- amounts : bigint[]
14
- scripts : Uint8Array[]
15
- }
@@ -1,18 +0,0 @@
1
- export type LockScriptType = 'p2pkh' | 'p2sh' | 'p2wpkh' | 'p2wsh' | 'p2tr' | 'opreturn'
2
- export type SpendScriptType = 'p2pkh' | 'p2sh' | 'p2wpkh' | 'p2wsh' | 'p2tr' | 'p2ts'
3
- export type WitnessVersion = 0 | 1 | null
4
-
5
- export interface ScriptInfo {
6
- asm : string[]
7
- hex : string
8
- }
9
-
10
- export interface LockScriptInfo {
11
- type : LockScriptType | null
12
- version : WitnessVersion | null
13
- }
14
-
15
- export interface SpendScriptInfo {
16
- type : SpendScriptType
17
- version : WitnessVersion
18
- }
@@ -1,16 +0,0 @@
1
- import { TxInput } from './txdata.js'
2
-
3
- export type SigHashType = 'segwit' | 'taproot'
4
-
5
- export interface SigHashOptions {
6
- extension ?: string // Extend hash with additional commitment (for taproot).
7
- extflag ?: number // Set the extention version flag (future use).
8
- txindex ?: number // Index value of the input you wish to sign for.
9
- key_version ?: number // Set the key version flag (future use).
10
- pubkey ?: string // Verify using this pubkey instead of the tapkey.
11
- script ?: string // Use this script for signing and validation.
12
- separator_pos ?: number // If using OP_CODESEPARATOR, specify the latest opcode position.
13
- sigflag ?: number // Set the signature type flag.
14
- throws ?: boolean // Should throw an exception on failure.
15
- txinput ?: TxInput // Use this txinput for signing and validation.
16
- }
@@ -1,41 +0,0 @@
1
- type Bytes = string | Uint8Array
2
-
3
- export type TapTree = Array<Bytes | Bytes[]>
4
-
5
- export type MerkleProof = [
6
- root : string,
7
- target : string | undefined,
8
- path : string[]
9
- ]
10
-
11
- export interface TaprootConfig {
12
- pubkey : Bytes
13
- leaves ?: TapTree
14
- target ?: Bytes
15
- version ?: number
16
- }
17
-
18
- export interface TaprootContext {
19
- cblock : string
20
- int_key : string
21
- path : string[]
22
- parity : number
23
- taproot : string | null
24
- tapkey : string
25
- taptweak : string
26
- }
27
-
28
- export interface ControlBlock {
29
- int_key : string
30
- parity : number
31
- path : string[]
32
- version : number
33
- }
34
-
35
- export interface ProofData {
36
- cblock : ControlBlock
37
- params : string[]
38
- script : string
39
- tapkey : string
40
- tweak : string
41
- }
@@ -1,85 +0,0 @@
1
- export type TxInput = TxCoinbaseInput | TxSpendInput | TxVirtualInput
2
-
3
- export interface TxOutpoint {
4
- txid : string
5
- vout : number
6
- }
7
-
8
- export interface TxInputTemplate extends TxOutpoint {
9
- coinbase? : string | null
10
- prevout? : TxOutput | null
11
- script_sig? : string | null
12
- sequence? : number
13
- witness? : string[]
14
- }
15
-
16
- export interface TxCoinbaseInput extends TxOutpoint {
17
- coinbase : string
18
- prevout : null
19
- script_sig : null
20
- sequence : number
21
- witness : string[]
22
- }
23
-
24
- export interface TxVirtualInput extends TxOutpoint {
25
- coinbase : null
26
- prevout : TxOutput | null
27
- script_sig : string | null
28
- sequence : number
29
- witness : string[]
30
- }
31
-
32
- export interface TxSpendInput extends TxVirtualInput {
33
- prevout : TxOutput
34
- }
35
-
36
- export interface TxOutputTemplate {
37
- script_pk : string
38
- value : number | bigint
39
- }
40
-
41
- export interface TxOutput {
42
- script_pk : string
43
- value : bigint
44
- }
45
-
46
- export interface TxTemplate {
47
- locktime? : number
48
- vin : TxInputTemplate[]
49
- vout : TxOutputTemplate[]
50
- version? : number
51
- }
52
-
53
- export interface TxData {
54
- locktime : number
55
- vin : TxInput[]
56
- vout : TxOutput[]
57
- version : number
58
- }
59
-
60
- export interface TxDecodedData {
61
- locktime : number
62
- vin : (TxCoinbaseInput | TxVirtualInput)[]
63
- vout : TxOutput[]
64
- version : number
65
- }
66
-
67
- export interface TxSpendData {
68
- locktime : number
69
- vin : TxSpendInput[]
70
- vout : TxOutput[]
71
- version : number
72
- }
73
-
74
- export interface TxSize {
75
- base : number
76
- total : number
77
- vsize : number
78
- weight : number
79
- }
80
-
81
- export interface TxValue {
82
- fees : bigint
83
- vin : bigint
84
- vout : bigint
85
- }
@@ -1,42 +0,0 @@
1
- import type { SpendScriptType, WitnessVersion } from './script.js'
2
-
3
- export type WitnessContext = WitnessData | TaprootScript | SegwitScript | TaprootSpend | SegwitSpend
4
-
5
- export interface WitnessSize {
6
- total : number
7
- vsize : number
8
- }
9
-
10
- export interface WitnessData {
11
- annex : string | null
12
- cblock : string | null
13
- params : string[]
14
- script : string | null
15
- stack : string[]
16
- type : SpendScriptType | null
17
- version : WitnessVersion | null
18
- }
19
-
20
- export interface TaprootScript extends WitnessData {
21
- cblock : string
22
- script : string
23
- type : 'p2ts'
24
- version : 1
25
- }
26
-
27
- export interface SegwitScript extends WitnessData {
28
- script : string
29
- type : 'p2wsh'
30
- version : 0
31
- }
32
-
33
- export interface TaprootSpend extends WitnessData {
34
- type : 'p2tr'
35
- version : 1
36
- }
37
-
38
- export interface SegwitSpend extends WitnessData {
39
- type : 'p2wpkh'
40
- version : 0
41
- }
42
-