@vbyte/btc-dev 1.1.6 → 1.1.7
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.
- package/dist/lib/tx/decode.js +2 -3
- package/dist/lib/tx/util.d.ts +2 -0
- package/dist/lib/tx/util.js +21 -3
- package/dist/main.cjs +5976 -5695
- package/dist/main.cjs.map +1 -1
- package/dist/module.mjs +5976 -5695
- package/dist/module.mjs.map +1 -1
- package/dist/package.json +10 -10
- package/dist/schema/base.d.ts +40 -0
- package/dist/schema/base.js +42 -0
- package/dist/schema/taproot.js +1 -1
- package/dist/schema/tx.js +1 -1
- package/dist/script.js +8 -9
- package/dist/script.js.map +1 -1
- package/package.json +10 -10
- package/src/lib/tx/decode.ts +3 -3
- package/src/lib/tx/util.ts +28 -4
- package/src/schema/base.ts +57 -0
- package/src/schema/taproot.ts +1 -1
- package/src/schema/tx.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vbyte/btc-dev",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "Batteries-included toolset for plebian bitcoin development",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -79,12 +79,12 @@
|
|
|
79
79
|
"test": "npm run script test/src/tape.ts"
|
|
80
80
|
},
|
|
81
81
|
"dependencies": {
|
|
82
|
-
"@noble/curves": "
|
|
83
|
-
"@noble/hashes": "
|
|
84
|
-
"@scure/btc-signer": "
|
|
82
|
+
"@noble/curves": "1.9.7",
|
|
83
|
+
"@noble/hashes": "1.8.0",
|
|
84
|
+
"@scure/btc-signer": "1.8.1",
|
|
85
85
|
"@vbyte/buff": "^1.0.2",
|
|
86
|
-
"@vbyte/micro-lib": "^1.1.
|
|
87
|
-
"zod": "^4.
|
|
86
|
+
"@vbyte/micro-lib": "^1.1.2",
|
|
87
|
+
"zod": "^4.1.5"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
90
|
"@cmdcode/core-cmd": "^1.6.5",
|
|
@@ -93,13 +93,13 @@
|
|
|
93
93
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
94
94
|
"@rollup/plugin-terser": "^0.4.4",
|
|
95
95
|
"@rollup/plugin-typescript": "^12.1.4",
|
|
96
|
-
"@types/node": "^24.
|
|
96
|
+
"@types/node": "^24.3.1",
|
|
97
97
|
"@types/tape": "^5.8.1",
|
|
98
98
|
"faucet": "^0.0.4",
|
|
99
|
-
"rollup": "^4.
|
|
99
|
+
"rollup": "^4.50.1",
|
|
100
100
|
"tape": "^5.9.0",
|
|
101
101
|
"tslib": "^2.8.1",
|
|
102
|
-
"tsx": "^4.20.
|
|
103
|
-
"typescript": "^5.
|
|
102
|
+
"tsx": "^4.20.5",
|
|
103
|
+
"typescript": "^5.9.2"
|
|
104
104
|
}
|
|
105
105
|
}
|
package/src/lib/tx/decode.ts
CHANGED
|
@@ -22,9 +22,9 @@ export function decode_tx (
|
|
|
22
22
|
// Parse tx version.
|
|
23
23
|
const version = read_version(stream)
|
|
24
24
|
// Check and enable any flags that are set.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
let has_witness = check_witness_flag(stream)
|
|
26
|
+
// If use_segwit is false, set has_witness to false.
|
|
27
|
+
has_witness = (use_segwit) ? has_witness : false
|
|
28
28
|
// Parse our inputs and outputs.
|
|
29
29
|
const vin = read_inputs(stream)
|
|
30
30
|
const vout = read_outputs(stream)
|
package/src/lib/tx/util.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Buff } 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'
|
|
5
|
+
import { decode_tx } from './decode.js'
|
|
5
6
|
import { encode_tx } from './encode.js'
|
|
6
7
|
import { parse_tx } from './parse.js'
|
|
7
8
|
import { assert_tx_template } from './validate.js'
|
|
@@ -15,16 +16,39 @@ import type {
|
|
|
15
16
|
TxValue
|
|
16
17
|
} from '@/types/index.js'
|
|
17
18
|
|
|
19
|
+
export function transcode_tx (
|
|
20
|
+
txdata : string | Uint8Array,
|
|
21
|
+
use_segwit = true
|
|
22
|
+
) : Buff {
|
|
23
|
+
console.log('txdata:', txdata)
|
|
24
|
+
// Decode the transaction data.
|
|
25
|
+
const decoded = decode_tx(txdata)
|
|
26
|
+
console.log('decoded:', decoded)
|
|
27
|
+
// Re-encode and return the encoded transaction data.
|
|
28
|
+
return encode_tx(decoded, use_segwit)
|
|
29
|
+
}
|
|
30
|
+
|
|
18
31
|
export function get_txid (txdata : string | Uint8Array | TxData) : string {
|
|
19
|
-
|
|
20
|
-
|
|
32
|
+
let buffer : Uint8Array
|
|
33
|
+
|
|
34
|
+
if (txdata instanceof Uint8Array) {
|
|
35
|
+
// Set the buffer to the transaction data.
|
|
36
|
+
buffer = transcode_tx(txdata, false)
|
|
37
|
+
} else if (typeof txdata === 'object') {
|
|
21
38
|
// Assert the structure of the transaction data is valid.
|
|
22
39
|
assert_tx_template(txdata)
|
|
23
40
|
// Encode the transaction data.
|
|
24
|
-
|
|
41
|
+
buffer = encode_tx(txdata, false)
|
|
42
|
+
} else if (typeof txdata === 'string') {
|
|
43
|
+
// Assert the transaction data is a hex string.
|
|
44
|
+
Assert.is_hex(txdata)
|
|
45
|
+
// Convert the hex string to a Uint8Array.
|
|
46
|
+
buffer = transcode_tx(txdata, false)
|
|
47
|
+
} else {
|
|
48
|
+
throw new TypeError('invalid txdata type: ' + typeof txdata)
|
|
25
49
|
}
|
|
26
50
|
// Return the txid of the transaction data.
|
|
27
|
-
return hash256(
|
|
51
|
+
return hash256(buffer).reverse().hex
|
|
28
52
|
}
|
|
29
53
|
|
|
30
54
|
export function get_txhash (txdata : string | Uint8Array | TxData) : string {
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
|
|
3
|
+
type Literal = z.infer<typeof literal>
|
|
4
|
+
type Json = Literal | { [key : string] : Json } | Json[]
|
|
5
|
+
|
|
6
|
+
export const big = z.bigint()
|
|
7
|
+
export const bool = z.boolean()
|
|
8
|
+
export const date = z.date()
|
|
9
|
+
export const num = z.number().min(Number.MIN_SAFE_INTEGER).max(Number.MAX_SAFE_INTEGER)
|
|
10
|
+
export const int = num.int()
|
|
11
|
+
export const u8a = z.instanceof(Uint8Array)
|
|
12
|
+
export const str = z.string()
|
|
13
|
+
export const stamp = int.min(500_000_000)
|
|
14
|
+
export const any = z.any()
|
|
15
|
+
export const zod = z
|
|
16
|
+
export const char = int.min(0).max(0xFF)
|
|
17
|
+
export const short = int.min(0).max(0xFFFF)
|
|
18
|
+
export const uint = int.min(0).max(0xFFFFFFFF)
|
|
19
|
+
|
|
20
|
+
export const float = z.number().refine((e) => String(e).includes('.'))
|
|
21
|
+
|
|
22
|
+
export const float2 = float.refine((e) => {
|
|
23
|
+
const parts = String(e).split('.').at(1)
|
|
24
|
+
return parts !== undefined && parts.length <= 2
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
export const hex = z.string()
|
|
28
|
+
.regex(/^[0-9a-fA-F]*$/)
|
|
29
|
+
.refine(e => e.length % 2 === 0)
|
|
30
|
+
|
|
31
|
+
export const literal = z.union([
|
|
32
|
+
z.string(), z.number(), z.boolean(), z.null()
|
|
33
|
+
])
|
|
34
|
+
|
|
35
|
+
export const json : z.ZodType<Json> = z.lazy(() =>
|
|
36
|
+
z.union([ literal, z.array(json), z.record(str, json) ])
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
export const u8a20 = u8a.refine((e) => e.length === 20)
|
|
40
|
+
export const u8a32 = u8a.refine((e) => e.length === 32)
|
|
41
|
+
export const u8a33 = u8a.refine((e) => e.length === 33)
|
|
42
|
+
export const u8a64 = u8a.refine((e) => e.length === 64)
|
|
43
|
+
|
|
44
|
+
export const hex20 = hex.refine((e) => e.length === 40)
|
|
45
|
+
export const hex32 = hex.refine((e) => e.length === 64)
|
|
46
|
+
export const hex33 = hex.refine((e) => e.length === 66)
|
|
47
|
+
export const hex64 = hex.refine((e) => e.length === 128)
|
|
48
|
+
|
|
49
|
+
export const bytes = z.union([ hex, u8a ])
|
|
50
|
+
export const byte32 = z.union([ hex32, u8a32 ])
|
|
51
|
+
export const byte33 = z.union([ hex33, u8a33 ])
|
|
52
|
+
export const byte64 = z.union([ hex64, u8a64 ])
|
|
53
|
+
|
|
54
|
+
export const base58 = z.string().regex(/^[1-9A-HJ-NP-Za-km-z]+$/)
|
|
55
|
+
export const base64 = z.string().regex(/^[a-zA-Z0-9+/]+={0,2}$/)
|
|
56
|
+
export const base64url = z.string().regex(/^[a-zA-Z0-9\-_]+={0,2}$/)
|
|
57
|
+
export const bech32 = z.string().regex(/^[a-z]+1[023456789acdefghjklmnpqrstuvwxyz]+$/)
|
package/src/schema/taproot.ts
CHANGED