Skip to content

Commit

Permalink
added sign inputs without finalize method
Browse files Browse the repository at this point in the history
  • Loading branch information
killsanEXE committed Feb 19, 2024
1 parent a83a0a6 commit 35d3255
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bellhdw",
"version": "0.5.19",
"version": "0.5.20",
"description": "Client-side Bitcoin JavaScript library",
"main": "./src/index.js",
"types": "./src/index.d.ts",
Expand Down
20 changes: 20 additions & 0 deletions ts_src/hd/private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,26 @@ class HDPrivateKey extends BaseWallet implements Keyring<SerializedHDKey> {
};
}

signInputsWithoutFinalizing(
psbt: Psbt,
inputs: ToSignInput[]
): {
inputIndex: number;
partialSig: { pubkey: Buffer; signature: Buffer }[];
}[] {
let account: ECPairInterface | undefined;

inputs.map((i) => {
account = this.findAccountByPk(i.publicKey);
psbt.signInput(i.index, account, i.sighashTypes);
});

return psbt.data.inputs.map((f, i) => ({
inputIndex: i,
partialSig: f.partialSig?.flatMap((p) => p) ?? [],
}));
}

signMessage(address: Hex, text: string) {
const account = this.findAccount(address);
const hash = sha256(text);
Expand Down
20 changes: 20 additions & 0 deletions ts_src/hd/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class HDSimpleKey extends BaseWallet implements Keyring<SerializedSimpleKey> {
}

signAllInputsInPsbt(psbt: Psbt, accountAddress: string) {
this.initPair();
if (this.pair === undefined)
throw new Error("Cannot sign all inputs since pair is undefined");
if (accountAddress !== this.getAddress(this.publicKey))
Expand All @@ -131,6 +132,25 @@ class HDSimpleKey extends BaseWallet implements Keyring<SerializedSimpleKey> {
};
}

signInputsWithoutFinalizing(
psbt: Psbt,
inputs: ToSignInput[]
): {
inputIndex: number;
partialSig: { pubkey: Buffer; signature: Buffer }[];
}[] {
this.initPair();
if (this.pair === undefined)
throw new Error("Cannot sign inputs since pair is undefined");
for (let i of inputs) {
psbt.signInput(i.index, this.pair!, i.sighashTypes);
}
return psbt.data.inputs.map((f, i) => ({
inputIndex: i,
partialSig: f.partialSig?.flatMap((p) => p) ?? [],
}));
}

signMessage(_address: string, message: string) {
this.initPair();

Expand Down
7 changes: 7 additions & 0 deletions ts_src/hd/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ export type Keyring<State> = {
psbt: Psbt,
accountAddress: string
): { signatures: (string | undefined)[] };
signInputsWithoutFinalizing(
psbt: Psbt,
inputs: ToSignInput[]
): {
inputIndex: number;
partialSig: { pubkey: Buffer; signature: Buffer }[];
}[];
};

export const DISALLOWED_CHILD_METHODS: (keyof Keyring<any>)[] = [
Expand Down

0 comments on commit 35d3255

Please sign in to comment.