Skip to content

Commit

Permalink
feat: add finalize option to Unisat signPsbt fn
Browse files Browse the repository at this point in the history
  • Loading branch information
iamcrazycoder committed Aug 6, 2023
1 parent 0b263c6 commit 7e7d9ca
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
7 changes: 4 additions & 3 deletions packages/sdk/src/browser-wallets/unisat/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./addresses";
export * from "./signatures";
export * from "./utils";
export * from "./addresses"
export * from "./signatures"
export * from "./types"
export * from "./utils"
4 changes: 2 additions & 2 deletions packages/sdk/src/browser-wallets/unisat/signatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { Psbt } from "bitcoinjs-lib";

import { isUnisatInstalled } from "./utils";

export async function signPsbt(psbt: Psbt) {
export async function signPsbt(psbt: Psbt, { finalize = true }: UnisatSignPSBTOptions = {}) {
if (!isUnisatInstalled()) {
throw new Error("Unisat not installed.");
}

const psbtHex = psbt.toHex();

const signedPsbtHex = await window.unisat.signPsbt(psbtHex);
const signedPsbtHex = await window.unisat.signPsbt(psbtHex, { autoFinalized: finalize })

if (!signedPsbtHex) {
throw new Error("Failed to sign psbt hex using Unisat.");
Expand Down
3 changes: 3 additions & 0 deletions packages/sdk/src/browser-wallets/unisat/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface UnisatSignPSBTOptions {
finalize?: boolean
}
26 changes: 13 additions & 13 deletions packages/sdk/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
declare interface Window {
unisat: Unisat;
satsConnect: any;
ethereum: MetaMask;
unisat: Unisat
satsConnect: any
ethereum: MetaMask
}

type Unisat = {
getNetwork: () => Promise<UnisatNetwork>;
switchNetwork: (targetNetwork: UnisatNetwork) => Promise<void>;
requestAccounts: () => Promise<string[]>;
getPublicKey: () => Promise<string>;
signPsbt: (hex: string) => Promise<string>;
signMessage: (message: string) => Promise<string>;
};
getNetwork: () => Promise<UnisatNetwork>
switchNetwork: (targetNetwork: UnisatNetwork) => Promise<void>
requestAccounts: () => Promise<string[]>
getPublicKey: () => Promise<string>
signPsbt: (hex: string, { autoFinalized }: Record<string, boolean>) => Promise<string>
signMessage: (message: string) => Promise<string>
}

type MetaMask = {
isMetaMask: boolean;
request: (options: { method: string; params?: any }) => Promise<any>;
};
isMetaMask: boolean
request: (options: { method: string; params?: any }) => Promise<any>
}

0 comments on commit 7e7d9ca

Please sign in to comment.