Skip to content

Commit

Permalink
taproot fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hank-schrader committed Sep 19, 2024
1 parent 6cdaf87 commit 4b6a190
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 14 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bellhdw",
"version": "0.5.38",
"version": "0.5.42",
"description": "Client-side Bitcoin JavaScript library",
"main": "./src/index.js",
"types": "./src/index.d.ts",
Expand Down Expand Up @@ -37,12 +37,12 @@
],
"dependencies": {
"@noble/hashes": "1.3.3",
"belcoinjs-lib": "0.1.1",
"bells-secp256k1": "0.1.0",
"belpair": "0.1.2",
"belcoinjs-lib": "0.1.2",
"bells-secp256k1": "0.1.1",
"belpair": "0.1.3",
"nintondo-bip39": "1.0.0",
"bn.js": "5.2.1",
"browser-hdkey": "0.1.8"
"browser-hdkey": "0.1.9"
},
"devDependencies": {
"@types/bn.js": "^5.1.1",
Expand Down
24 changes: 20 additions & 4 deletions ts_src/hd/private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ class HDPrivateKey extends BaseWallet implements Keyring<SerializedHDKey> {

inputs.forEach((input) => {
account = this.findAccountByPk(input.publicKey);
if (this.addressType === AddressType.P2TR) {
if (
(this.addressType === AddressType.P2TR ||
this.addressType === AddressType.M44_P2TR) &&
!input.disableTweakSigner
) {
const signer = tweakSigner(account, {
network: this.network ?? networks.bellcoin,
});
Expand All @@ -176,11 +180,19 @@ class HDPrivateKey extends BaseWallet implements Keyring<SerializedHDKey> {
psbt.finalizeAllInputs();
}

signAllInputsInPsbt(psbt: Psbt, accountAddress: string) {
signAllInputsInPsbt(
psbt: Psbt,
accountAddress: string,
disableTweakSigner?: boolean
) {
const account = this.findAccount(accountAddress);

psbt.data.inputs.forEach((input, idx) => {
if (this.addressType === AddressType.P2TR) {
if (
(this.addressType === AddressType.P2TR ||
this.addressType === AddressType.M44_P2TR) &&
!disableTweakSigner
) {
const signer = tweakSigner(account, {
network: this.network ?? networks.bellcoin,
});
Expand Down Expand Up @@ -223,7 +235,11 @@ class HDPrivateKey extends BaseWallet implements Keyring<SerializedHDKey> {

inputs.forEach((input) => {
account = this.findAccountByPk(input.publicKey);
if (this.addressType === AddressType.P2TR) {
if (
(this.addressType === AddressType.P2TR ||
this.addressType === AddressType.M44_P2TR) &&
!input.disableTweakSigner
) {
const signer = tweakSigner(account, {
network: this.network ?? networks.bellcoin,
});
Expand Down
24 changes: 20 additions & 4 deletions ts_src/hd/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ class HDSimpleKey extends BaseWallet implements Keyring<SerializedSimpleKey> {

inputs.forEach((input) => {
const account = this.pair!;
if (this.addressType === AddressType.P2TR) {
if (
(this.addressType === AddressType.P2TR ||
this.addressType === AddressType.M44_P2TR) &&
!input.disableTweakSigner
) {
const signer = tweakSigner(account, {
network: this.network ?? networks.bellcoin,
});
Expand All @@ -162,7 +166,11 @@ class HDSimpleKey extends BaseWallet implements Keyring<SerializedSimpleKey> {
psbt.finalizeAllInputs();
}

signAllInputsInPsbt(psbt: Psbt, accountAddress: string) {
signAllInputsInPsbt(
psbt: Psbt,
accountAddress: string,
disableTweakSigner?: boolean
) {
this.initPair();
if (this.pair === undefined)
throw new Error("Cannot sign all inputs since pair is undefined");
Expand All @@ -172,7 +180,11 @@ class HDSimpleKey extends BaseWallet implements Keyring<SerializedSimpleKey> {
);

psbt.data.inputs.forEach((input, idx) => {
if (this.addressType === AddressType.P2TR) {
if (
(this.addressType === AddressType.P2TR ||
this.addressType === AddressType.M44_P2TR) &&
!disableTweakSigner
) {
const signer = tweakSigner(this.pair!, {
network: this.network ?? networks.bellcoin,
});
Expand Down Expand Up @@ -214,7 +226,11 @@ class HDSimpleKey extends BaseWallet implements Keyring<SerializedSimpleKey> {
if (this.pair === undefined)
throw new Error("Cannot sign inputs since pair is undefined");
inputs.forEach((input) => {
if (this.addressType === AddressType.P2TR) {
if (
(this.addressType === AddressType.P2TR ||
this.addressType === AddressType.M44_P2TR) &&
!input.disableTweakSigner
) {
const signer = tweakSigner(this.pair!, {
network: this.network ?? networks.bellcoin,
});
Expand Down
4 changes: 3 additions & 1 deletion ts_src/hd/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface ToSignInput {
index: number;
publicKey: string;
sighashTypes?: number[];
disableTweakSigner?: boolean;
}

export enum AddressType {
Expand Down Expand Up @@ -82,7 +83,8 @@ export type Keyring<State> = {
signTypedData(address: Hex, typedData: Record<string, unknown>): string;
signAllInputsInPsbt(
psbt: Psbt,
accountAddress: string
accountAddress: string,
disableTweakSigner?: boolean
): { signatures: (string | undefined)[] };
signInputsWithoutFinalizing(
psbt: Psbt,
Expand Down

0 comments on commit 4b6a190

Please sign in to comment.