Skip to content

Commit 3df889a

Browse files
Merge pull request #62 from BitGo/BTC-1966.refine-sign-result
feat(types): make SignPsbtResult type more precise
2 parents 752c5e7 + e0a668e commit 3df889a

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

packages/wasm-miniscript/js/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ export type DescriptorPkType = "derivable" | "definite" | "string";
88

99
export type ScriptContext = "tap" | "segwitv0" | "legacy";
1010

11+
export type SignPsbtInputResult = { Ecdsa: string[] } | { Schnorr: string[] };
12+
1113
export type SignPsbtResult = {
12-
[inputIndex: number]: [pubkey: string][];
14+
[inputIndex: number]: SignPsbtInputResult;
1315
};
1416

1517
declare module "./wasm/wasm_miniscript" {

packages/wasm-miniscript/test/psbtFromDescriptor.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getKey } from "@bitgo/utxo-lib/dist/src/testutil";
44

55
import { DescriptorNode, formatNode } from "../js/ast";
66
import { mockPsbtDefault } from "./psbtFromDescriptor.util";
7-
import { Descriptor } from "../js";
7+
import { Descriptor, SignPsbtInputResult, SignPsbtResult } from "../js";
88
import { toWrappedPsbt } from "./psbt.util";
99

1010
function toKeyWithPath(k: BIP32Interface, path = "*"): string {
@@ -59,12 +59,9 @@ function describeSignDescriptor(
5959
),
6060
});
6161

62-
function getSigResult(keys: (BIP32Interface | ECPairInterface)[]) {
63-
return {
64-
[isTaproot ? "Schnorr" : "Ecdsa"]: keys.map((key) =>
65-
key.publicKey.subarray(isTaproot ? 1 : 0).toString("hex"),
66-
),
67-
};
62+
function getSigResult(keys: (BIP32Interface | ECPairInterface)[]): SignPsbtInputResult {
63+
const pks = keys.map((key) => key.publicKey.subarray(isTaproot ? 1 : 0).toString("hex"));
64+
return isTaproot ? { Schnorr: pks } : { Ecdsa: pks };
6865
}
6966

7067
signBip32.forEach((signSeq, i) => {
@@ -100,7 +97,7 @@ function describeSignDescriptor(
10097
assert.deepStrictEqual(wrappedPsbt.signWithPrv(key.privateKey), {
10198
0: getSigResult([key]),
10299
1: getSigResult([key]),
103-
});
100+
} satisfies SignPsbtResult);
104101
});
105102
wrappedPsbt.finalize();
106103
});

0 commit comments

Comments
 (0)