Skip to content

Commit fa1c499

Browse files
authored
fix(browser-wallet): remove finalize logic from phantom and oyl wallet (#248)
* fix: remove finalize logic since it is not officially documented * poc: attempt to upgrade corepack * Revert "poc: attempt to upgrade corepack" This reverts commit 895b2b5. * poc: attempt to install corepack before using it * Revert "poc: attempt to install corepack before using it" This reverts commit 62dac5d. * poc: attempt to install latest corepack before each jobs * fix: linting * fix: remove inputsToSign from oyl wallet example Add comments to ci * fix: add finalize logic back to phantom wallet * Revert "fix: add finalize logic back to phantom wallet" This reverts commit 00d0b82.
1 parent a98cdb8 commit fa1c499

File tree

7 files changed

+10
-72
lines changed

7 files changed

+10
-72
lines changed

.github/workflows/ci.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
18-
18+
- run: npm i -g corepack@latest # Temporary workaround in response to https://github.com/pnpm/pnpm/issues/9029
1919
- run: corepack enable pnpm
2020

2121
- uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
@@ -31,7 +31,7 @@ jobs:
3131
runs-on: ubuntu-latest
3232
steps:
3333
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
34-
34+
- run: npm i -g corepack@latest # Temporary workaround in response to https://github.com/pnpm/pnpm/issues/9029
3535
- run: corepack enable pnpm
3636

3737
- uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
@@ -52,7 +52,7 @@ jobs:
5252
runs-on: ubuntu-latest
5353
steps:
5454
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
55-
55+
- run: npm i -g corepack@latest # Temporary workaround in response to https://github.com/pnpm/pnpm/issues/9029
5656
- run: corepack enable pnpm
5757

5858
- uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
@@ -69,7 +69,7 @@ jobs:
6969
runs-on: ubuntu-latest
7070
steps:
7171
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
72-
72+
- run: npm i -g corepack@latest # Temporary workaround in response to https://github.com/pnpm/pnpm/issues/9029
7373
- run: corepack enable pnpm
7474

7575
- uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0

apps/browser-tests/src/App.tsx

-6
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,6 @@ function Transactions({
157157
} else if (provider === "oyl") {
158158
signPsbtResponse = await oyl.signPsbt(psbt.toPSBT(), {
159159
network: NETWORK,
160-
inputsToSign: [
161-
{
162-
address: inputAddressInfo.address,
163-
signingIndexes: [0],
164-
},
165-
],
166160
});
167161
} else {
168162
throw new Error("Unknown provider");

packages/sdk/src/browser-wallets/oyl/__tests__/index.spec.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ describe("Oyl Wallet", () => {
111111

112112
expect(MOCK_SIGN_PSBT).toHaveBeenCalledWith({
113113
psbt: psbt.toHex(),
114-
finalize: false,
114+
finalize: true,
115115
broadcast: false,
116116
});
117117
expect(signedPsbtResponse).toEqual({
@@ -125,7 +125,6 @@ describe("Oyl Wallet", () => {
125125
const signedPsbtResponse = await signPsbt(psbt, {
126126
extractTx: true,
127127
network: "mainnet",
128-
inputsToSign: [],
129128
});
130129

131130
expect(signedPsbtResponse).toEqual({
@@ -139,7 +138,6 @@ describe("Oyl Wallet", () => {
139138
const signedPsbtResponse = await signPsbt(psbt, {
140139
extractTx: false,
141140
network: "mainnet",
142-
inputsToSign: [],
143141
});
144142
expect(signedPsbtResponse).toEqual({
145143
base64: "cHNidP8BAAoCAAAAAAAAAAAAAAAA",
@@ -152,7 +150,6 @@ describe("Oyl Wallet", () => {
152150
const signedPsbtResponse = await signPsbt(psbt, {
153151
finalize: true,
154152
network: "mainnet",
155-
inputsToSign: [],
156153
});
157154
expect(signedPsbtResponse).toEqual({
158155
base64: null,
@@ -166,7 +163,6 @@ describe("Oyl Wallet", () => {
166163
finalize: false,
167164
extractTx: false,
168165
network: "mainnet",
169-
inputsToSign: [],
170166
});
171167
expect(signedPsbtResponse).toEqual({
172168
base64: "cHNidP8BAAoCAAAAAAAAAAAAAAAA",
@@ -182,7 +178,6 @@ describe("Oyl Wallet", () => {
182178
signPsbt(psbt, {
183179
finalize: false,
184180
network: "mainnet",
185-
inputsToSign: [],
186181
}),
187182
).rejects.toThrowError(EXTRACTION_TRANSACTION_NON_FINALIZED_PSBT_ERROR);
188183
});
@@ -201,7 +196,6 @@ describe("Oyl Wallet", () => {
201196
signPsbt(psbt, {
202197
finalize: true,
203198
network: "mainnet",
204-
inputsToSign: [],
205199
}),
206200
).rejects.toThrowError(EXTRACTION_TRANSACTION_NON_FINALIZED_PSBT_ERROR);
207201
});

packages/sdk/src/browser-wallets/oyl/index.ts

+4-27
Original file line numberDiff line numberDiff line change
@@ -83,51 +83,28 @@ async function signMessage(
8383

8484
async function signPsbt(
8585
psbt: Psbt,
86-
{
87-
finalize = true,
88-
extractTx = true,
89-
network,
90-
inputsToSign,
91-
}: OylSignPSBTOptions = { network: "mainnet", inputsToSign: [] },
86+
{ finalize = true, extractTx = true, network }: OylSignPSBTOptions = {
87+
network: "mainnet",
88+
},
9289
): Promise<BrowserWalletSignResponse> {
9390
validateExtension(network);
9491

9592
if (extractTx && !finalize) {
9693
throw new BrowserWalletExtractTxFromNonFinalizedPsbtError();
9794
}
9895

99-
const toSignInputs: OylSignInput[] = [];
100-
inputsToSign.forEach((input) => {
101-
const { signingIndexes } = input;
102-
signingIndexes.forEach(() => {
103-
toSignInputs.push(input);
104-
});
105-
});
106-
10796
let signedPsbt: Psbt;
10897
try {
10998
const { psbt: signedPsbtInHex } = await window.oyl.signPsbt({
11099
psbt: psbt.toHex(),
111-
finalize: false, // ordit-sdk will finalize it manually if there is any inputs to sign
100+
finalize,
112101
broadcast: false, // ordit-sdk will not support broadcasting to keep implementation consistent across all wallets
113102
});
114103
signedPsbt = Psbt.fromHex(signedPsbtInHex);
115104
} catch (err) {
116105
throw new OrditSDKError("Failed to sign psbt with Oyl Wallet");
117106
}
118107

119-
if (finalize) {
120-
toSignInputs.forEach((_input, index) => {
121-
try {
122-
signedPsbt.finalizeInput(index);
123-
} catch (error) {
124-
// eslint-disable-next-line no-console
125-
console.error("Sign psbt error", error);
126-
throw new OrditSDKError("Failed to finalize input");
127-
}
128-
});
129-
}
130-
131108
if (extractTx) {
132109
try {
133110
return {
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { BrowserWalletNetwork } from "../../config/types";
2-
import { InputsToSign } from "../../inscription/types";
32

43
export type OylSignPSBTOptions = {
54
finalize?: boolean;
65
extractTx?: boolean;
76
network: BrowserWalletNetwork;
8-
inputsToSign: InputsToSign[];
97
};

packages/sdk/src/browser-wallets/phantom/index.ts

+1-21
Original file line numberDiff line numberDiff line change
@@ -98,40 +98,20 @@ async function signPsbt(
9898
throw new BrowserWalletExtractTxFromNonFinalizedPsbtError();
9999
}
100100

101-
const toSignInputs: PhantomSignInput[] = [];
102-
inputsToSign.forEach((input) => {
103-
const { signingIndexes } = input;
104-
signingIndexes.forEach(() => {
105-
toSignInputs.push(input);
106-
});
107-
});
108-
109101
let signedPsbtBuffer: Uint8Array;
110102
let signedPsbt: Psbt;
111103
try {
112104
signedPsbtBuffer = await window.phantom.bitcoin.signPSBT(
113105
Buffer.from(psbt.toHex(), "hex"),
114106
{
115-
inputsToSign: toSignInputs,
107+
inputsToSign,
116108
},
117109
);
118110
signedPsbt = Psbt.fromBuffer(Buffer.from(signedPsbtBuffer));
119111
} catch (err) {
120112
throw new OrditSDKError("Failed to sign psbt with Phantom Wallet");
121113
}
122114

123-
if (finalize) {
124-
toSignInputs.forEach((_input, index) => {
125-
try {
126-
signedPsbt.finalizeInput(index);
127-
} catch (error) {
128-
// eslint-disable-next-line no-console
129-
console.error("Sign psbt error", error);
130-
throw new OrditSDKError("Failed to finalize input");
131-
}
132-
});
133-
}
134-
135115
if (extractTx) {
136116
try {
137117
return {

packages/sdk/src/types.d.ts

-5
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,6 @@ type Oyl = {
160160
}) => Promise<{ psbt: string; txid?: string }>;
161161
};
162162

163-
type OylSignInput = {
164-
sigHash?: number;
165-
address: string;
166-
signingIndexes?: number[];
167-
};
168163
declare module "buffer-reverse" {
169164
export = (_: Buffer): Buffer => {};
170165
}

0 commit comments

Comments
 (0)