@vbyte/btc-dev 1.0.15 → 1.1.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.
@@ -14,6 +14,7 @@ export interface TaprootConfig {
14
14
  export interface TaprootContext {
15
15
  cblock: string;
16
16
  int_key: string;
17
+ path: string[];
17
18
  parity: number;
18
19
  taproot: string | null;
19
20
  tapkey: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vbyte/btc-dev",
3
- "version": "1.0.15",
3
+ "version": "1.1.0",
4
4
  "description": "Batteries-included toolset for plebian bitcoin development",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -45,10 +45,6 @@
45
45
  "types": "./dist/lib/meta/index.d.ts",
46
46
  "import": "./dist/lib/meta/index.js"
47
47
  },
48
- "./psbt": {
49
- "types": "./dist/lib/psbt/index.d.ts",
50
- "import": "./dist/lib/psbt/index.js"
51
- },
52
48
  "./script": {
53
49
  "types": "./dist/lib/script/index.d.ts",
54
50
  "import": "./dist/lib/script/index.js"
@@ -87,8 +83,8 @@
87
83
  "@noble/hashes": "^1.8.0",
88
84
  "@scure/btc-signer": "^1.8.1",
89
85
  "@vbyte/buff": "^1.0.2",
90
- "@vbyte/micro-lib": "^1.0.14",
91
- "zod": "^3.25.69"
86
+ "@vbyte/micro-lib": "^1.1.1",
87
+ "zod": "^4.0.5"
92
88
  },
93
89
  "devDependencies": {
94
90
  "@cmdcode/core-cmd": "^1.6.5",
@@ -97,10 +93,10 @@
97
93
  "@rollup/plugin-node-resolve": "^16.0.1",
98
94
  "@rollup/plugin-terser": "^0.4.4",
99
95
  "@rollup/plugin-typescript": "^12.1.4",
100
- "@types/node": "^24.0.10",
96
+ "@types/node": "^24.0.14",
101
97
  "@types/tape": "^5.8.1",
102
98
  "faucet": "^0.0.4",
103
- "rollup": "^4.44.1",
99
+ "rollup": "^4.45.1",
104
100
  "tape": "^5.9.0",
105
101
  "tslib": "^2.8.1",
106
102
  "tsx": "^4.20.3",
package/src/index.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export * as ADDRESS from './lib/address/index.js'
2
2
  export * as META from './lib/meta/index.js'
3
- export * as PSBT from './lib/psbt/index.js'
4
3
  export * as SCRIPT from './lib/script/index.js'
5
4
  export * as SIGHASH from './lib/sighash/index.js'
6
5
  export * as SIGNER from './lib/signer/index.js'
@@ -64,6 +64,7 @@ export function create_taproot (config : TaprootConfig) : TaprootContext {
64
64
 
65
65
  return {
66
66
  int_key : Buff.bytes(pubkey).hex,
67
+ path,
67
68
  parity,
68
69
  taproot : taproot ?? null,
69
70
  cblock : cblock.hex,
@@ -18,6 +18,7 @@ export interface TaprootConfig {
18
18
  export interface TaprootContext {
19
19
  cblock : string
20
20
  int_key : string
21
+ path : string[]
21
22
  parity : number
22
23
  taproot : string | null
23
24
  tapkey : string
@@ -1,5 +0,0 @@
1
- import { Transaction } from '@scure/btc-signer';
2
- import type { PSBTData } from '../../types/index.js';
3
- export declare function decode_psbt(b64str: string): Transaction;
4
- export declare function encode_psbt(psbt: PSBTData): string;
5
- export declare function parse_psbt(psbt: string | PSBTData): Transaction;
@@ -1,21 +0,0 @@
1
- import { Base64 } from '@vbyte/micro-lib';
2
- import { Transaction } from '@scure/btc-signer';
3
- export function decode_psbt(b64str) {
4
- const psbt = Base64.decode(b64str);
5
- return Transaction.fromPSBT(psbt, { allowUnknownOutputs: true });
6
- }
7
- export function encode_psbt(psbt) {
8
- const psbt_bytes = psbt.toPSBT(0);
9
- return Base64.encode(psbt_bytes);
10
- }
11
- export function parse_psbt(psbt) {
12
- if (psbt instanceof Transaction) {
13
- return psbt;
14
- }
15
- else if (typeof psbt === 'string') {
16
- return decode_psbt(psbt);
17
- }
18
- else {
19
- throw new Error('invalid psbt input: ' + psbt);
20
- }
21
- }
@@ -1,4 +0,0 @@
1
- export * from './encoder.js';
2
- export * from './meta.js';
3
- export * from './util.js';
4
- export * from './validate.js';
@@ -1,4 +0,0 @@
1
- export * from './encoder.js';
2
- export * from './meta.js';
3
- export * from './util.js';
4
- export * from './validate.js';
@@ -1,3 +0,0 @@
1
- import { PSBTData } from '../../types/index.js';
2
- export declare function get_vsize(psbt: string | PSBTData): number;
3
- export declare function get_txhex(psbt: PSBTData): string;
@@ -1,11 +0,0 @@
1
- import { parse_psbt } from './encoder.js';
2
- import { finalize_legacy_inputs } from './util.js';
3
- export function get_vsize(psbt) {
4
- const pdata = parse_psbt(psbt);
5
- return pdata.vsize;
6
- }
7
- export function get_txhex(psbt) {
8
- let pdata = parse_psbt(psbt);
9
- pdata = finalize_legacy_inputs(pdata);
10
- return pdata.hex;
11
- }
@@ -1,5 +0,0 @@
1
- import type { PSBTData, PSBTInput, PSBTOutput, PSBTPrevouts } from '../../types/index.js';
2
- export declare function collect_vins(psbt: string | PSBTData): PSBTInput[];
3
- export declare function collect_vouts(psbt: string | PSBTData): PSBTOutput[];
4
- export declare function collect_prevouts(psbt: PSBTData): PSBTPrevouts;
5
- export declare function finalize_legacy_inputs(pdata: PSBTData): import("node_modules/@scure/btc-signer/transaction.js").Transaction;
@@ -1,44 +0,0 @@
1
- import { Assert } from '@vbyte/micro-lib';
2
- import { parse_psbt } from './encoder.js';
3
- export function collect_vins(psbt) {
4
- const pdata = parse_psbt(psbt);
5
- const count = pdata.inputsLength;
6
- const vins = [];
7
- for (let i = 0; i < count; i++) {
8
- const vin = pdata.getInput(i);
9
- vins.push(vin);
10
- }
11
- return vins;
12
- }
13
- export function collect_vouts(psbt) {
14
- const pdata = parse_psbt(psbt);
15
- const count = pdata.outputsLength;
16
- const vouts = [];
17
- for (let i = 0; i < count; i++) {
18
- const vout = pdata.getOutput(i);
19
- vouts.push(vout);
20
- }
21
- return vouts;
22
- }
23
- export function collect_prevouts(psbt) {
24
- const amounts = [], scripts = [];
25
- const pdata = parse_psbt(psbt);
26
- for (let i = 0; i < pdata.inputsLength; i++) {
27
- const txin = pdata.getInput(i);
28
- Assert.exists(txin.witnessUtxo, `witness utxo does not exist for input ${i}`);
29
- amounts.push(txin.witnessUtxo.amount);
30
- scripts.push(txin.witnessUtxo.script);
31
- }
32
- return { amounts, scripts };
33
- }
34
- export function finalize_legacy_inputs(pdata) {
35
- for (let i = 0; i < pdata.inputsLength; i++) {
36
- const pvin = pdata.getInput(i);
37
- const script = pvin.redeemScript;
38
- const psig = pvin.partialSig?.at(0);
39
- if (script !== undefined && psig !== undefined) {
40
- pdata.finalizeIdx(i);
41
- }
42
- }
43
- return pdata;
44
- }
@@ -1,2 +0,0 @@
1
- import type { PSBTData } from '../../types/index.js';
2
- export declare function assert_psbt_is_funded(psbt: string | PSBTData): void;
@@ -1,11 +0,0 @@
1
- import { Assert } from '@vbyte/micro-lib';
2
- import { parse_psbt } from './encoder.js';
3
- import { collect_vins, collect_vouts } from './util.js';
4
- export function assert_psbt_is_funded(psbt) {
5
- const pdata = parse_psbt(psbt);
6
- const pvouts = collect_vins(pdata);
7
- const txouts = collect_vouts(pdata);
8
- const vin_amt = pvouts.reduce((p, n) => p + Number(n.witnessUtxo?.amount ?? 0), 0);
9
- const out_amt = txouts.reduce((p, n) => p + Number(n.amount ?? 0), 0);
10
- Assert.ok(vin_amt >= out_amt, `value in (${vin_amt}) < value out (${out_amt})`);
11
- }
@@ -1,24 +0,0 @@
1
- import { Base64 } from '@vbyte/micro-lib'
2
- import { Transaction } from '@scure/btc-signer'
3
-
4
- import type { PSBTData } from '@/types/index.js'
5
-
6
- export function decode_psbt (b64str : string) : Transaction {
7
- const psbt = Base64.decode(b64str)
8
- return Transaction.fromPSBT(psbt, { allowUnknownOutputs: true })
9
- }
10
-
11
- export function encode_psbt (psbt : PSBTData) : string {
12
- const psbt_bytes = psbt.toPSBT(0)
13
- return Base64.encode(psbt_bytes)
14
- }
15
-
16
- export function parse_psbt (psbt : string | PSBTData) : Transaction {
17
- if (psbt instanceof Transaction) {
18
- return psbt
19
- } else if (typeof psbt === 'string') {
20
- return decode_psbt(psbt)
21
- } else {
22
- throw new Error('invalid psbt input: ' + psbt)
23
- }
24
- }
@@ -1,4 +0,0 @@
1
- export * from './encoder.js'
2
- export * from './meta.js'
3
- export * from './util.js'
4
- export * from './validate.js'
@@ -1,15 +0,0 @@
1
- import { parse_psbt } from './encoder.js'
2
- import { finalize_legacy_inputs } from './util.js'
3
-
4
- import { PSBTData } from '@/types/index.js'
5
-
6
- export function get_vsize (psbt : string | PSBTData) : number {
7
- const pdata = parse_psbt(psbt)
8
- return pdata.vsize
9
- }
10
-
11
- export function get_txhex (psbt : PSBTData) : string {
12
- let pdata = parse_psbt(psbt)
13
- pdata = finalize_legacy_inputs(pdata)
14
- return pdata.hex
15
- }
@@ -1,62 +0,0 @@
1
- import { Assert } from '@vbyte/micro-lib'
2
- import { parse_psbt } from './encoder.js'
3
-
4
- import type {
5
- PSBTData,
6
- PSBTInput,
7
- PSBTOutput,
8
- PSBTPrevouts
9
- } from '@/types/index.js'
10
-
11
- export function collect_vins (
12
- psbt : string | PSBTData
13
- ) : PSBTInput[] {
14
- const pdata = parse_psbt(psbt)
15
- const count = pdata.inputsLength
16
- const vins : PSBTInput[] = []
17
- for (let i = 0; i < count; i++) {
18
- const vin = pdata.getInput(i)
19
- vins.push(vin)
20
- }
21
- return vins
22
- }
23
-
24
- export function collect_vouts (
25
- psbt : string | PSBTData
26
- ) : PSBTOutput[] {
27
- const pdata = parse_psbt(psbt)
28
- const count = pdata.outputsLength
29
- const vouts : PSBTOutput[] = []
30
- for (let i = 0; i < count; i++) {
31
- const vout = pdata.getOutput(i)
32
- vouts.push(vout)
33
- }
34
- return vouts
35
- }
36
-
37
- export function collect_prevouts (
38
- psbt : PSBTData
39
- ) : PSBTPrevouts {
40
- const amounts : bigint[] = [],
41
- scripts : Uint8Array[] = []
42
- const pdata = parse_psbt(psbt)
43
- for (let i = 0; i < pdata.inputsLength; i++) {
44
- const txin = pdata.getInput(i)
45
- Assert.exists(txin.witnessUtxo, `witness utxo does not exist for input ${i}`)
46
- amounts.push(txin.witnessUtxo.amount)
47
- scripts.push(txin.witnessUtxo.script)
48
- }
49
- return { amounts, scripts }
50
- }
51
-
52
- export function finalize_legacy_inputs (pdata : PSBTData) {
53
- for (let i = 0; i < pdata.inputsLength; i++) {
54
- const pvin = pdata.getInput(i)
55
- const script = pvin.redeemScript
56
- const psig = pvin.partialSig?.at(0)
57
- if (script !== undefined && psig !== undefined) {
58
- pdata.finalizeIdx(i)
59
- }
60
- }
61
- return pdata
62
- }
@@ -1,18 +0,0 @@
1
- import { Assert } from '@vbyte/micro-lib'
2
- import { parse_psbt } from './encoder.js'
3
-
4
- import {
5
- collect_vins,
6
- collect_vouts
7
- } from './util.js'
8
-
9
- import type { PSBTData } from '@/types/index.js'
10
-
11
- export function assert_psbt_is_funded (psbt : string | PSBTData) : void {
12
- const pdata = parse_psbt(psbt)
13
- const pvouts = collect_vins(pdata)
14
- const txouts = collect_vouts(pdata)
15
- const vin_amt = pvouts.reduce((p, n) => p + Number(n.witnessUtxo?.amount ?? 0), 0)
16
- const out_amt = txouts.reduce((p, n) => p + Number(n.amount ?? 0), 0)
17
- Assert.ok(vin_amt >= out_amt, `value in (${vin_amt}) < value out (${out_amt})`)
18
- }