Skip to content

Commit 2788a62

Browse files
refactor: move psbt util functions to separate file
Issue: BTC-1451
1 parent 5f5aa92 commit 2788a62

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

packages/wasm-miniscript/test/psbt.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,13 @@
11
import * as utxolib from "@bitgo/utxo-lib";
22
import * as assert from "node:assert";
3-
import { getPsbtFixtures, toPsbtWithPrevOutOnly } from "./psbtFixtures";
3+
import { getPsbtFixtures } from "./psbtFixtures";
44
import { Descriptor, Psbt } from "../js";
55

66
import { getDescriptorForScriptType } from "./descriptorUtil";
7+
import { toUtxoPsbt, toWrappedPsbt } from "./psbt.util";
78

89
const rootWalletKeys = new utxolib.bitgo.RootWalletKeys(utxolib.testutil.getKeyTriple("wasm"));
910

10-
function toWrappedPsbt(psbt: utxolib.bitgo.UtxoPsbt | Buffer | Uint8Array) {
11-
if (psbt instanceof utxolib.bitgo.UtxoPsbt) {
12-
psbt = psbt.toBuffer();
13-
}
14-
if (psbt instanceof Buffer || psbt instanceof Uint8Array) {
15-
return Psbt.deserialize(psbt);
16-
}
17-
throw new Error("Invalid input");
18-
}
19-
20-
function toUtxoPsbt(psbt: Psbt | Buffer | Uint8Array) {
21-
if (psbt instanceof Psbt) {
22-
psbt = psbt.serialize();
23-
}
24-
if (psbt instanceof Buffer || psbt instanceof Uint8Array) {
25-
return utxolib.bitgo.UtxoPsbt.fromBuffer(Buffer.from(psbt), {
26-
network: utxolib.networks.bitcoin,
27-
});
28-
}
29-
throw new Error("Invalid input");
30-
}
31-
3211
function assertEqualBuffer(a: Buffer | Uint8Array, b: Buffer | Uint8Array, message?: string) {
3312
assert.strictEqual(Buffer.from(a).toString("hex"), Buffer.from(b).toString("hex"), message);
3413
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as utxolib from "@bitgo/utxo-lib";
2+
import { Psbt } from "../js";
3+
4+
export function toWrappedPsbt(psbt: utxolib.bitgo.UtxoPsbt | Buffer | Uint8Array) {
5+
if (psbt instanceof utxolib.bitgo.UtxoPsbt) {
6+
psbt = psbt.toBuffer();
7+
}
8+
if (psbt instanceof Buffer || psbt instanceof Uint8Array) {
9+
return Psbt.deserialize(psbt);
10+
}
11+
throw new Error("Invalid input");
12+
}
13+
14+
export function toUtxoPsbt(psbt: Psbt | Buffer | Uint8Array) {
15+
if (psbt instanceof Psbt) {
16+
psbt = psbt.serialize();
17+
}
18+
if (psbt instanceof Buffer || psbt instanceof Uint8Array) {
19+
return utxolib.bitgo.UtxoPsbt.fromBuffer(Buffer.from(psbt), {
20+
network: utxolib.networks.bitcoin,
21+
});
22+
}
23+
throw new Error("Invalid input");
24+
}

0 commit comments

Comments
 (0)