Skip to content

Commit

Permalink
Merge pull request #8 from jordankzf/jordankzf/xverse-signed-psbt
Browse files Browse the repository at this point in the history
fix(sdk/xverse): return a defined type for signPsbt fn
  • Loading branch information
iamcrazycoder authored Jul 19, 2023
2 parents 6228345 + 4848430 commit 6f0391b
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions packages/sdk/src/browser-wallets/xverse/signatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,22 @@ import { InputToSign, signMessage as _signMessage, signTransaction } from "sats-
import { Network } from "../../config/types";
import { isXverseInstalled, XverseNetwork } from "./utils";

interface XverseSignedPsbt {
rawTxHex: string | null;
psbt: {
hex: string;
base64: string;
};
}

export async function signPsbt(options: XverseSignPsbtOptions) {
let result = null;
const result: XverseSignedPsbt = {
rawTxHex: null,
psbt: {
hex: "",
base64: ""
}
};

if (!options.psbt || !options.network || !options.inputs) {
throw new Error("Invalid options provided.");
Expand All @@ -23,27 +37,17 @@ export async function signPsbt(options: XverseSignPsbtOptions) {
}

const signedPsbt = Psbt.fromBase64(psbtBase64);
let rawTxHex = null;

try {
signedPsbt.finalizeAllInputs();
rawTxHex = signedPsbt.extractTransaction().toHex();
result.rawTxHex = signedPsbt.extractTransaction().toHex();
} catch (error) {
result = {
rawTxHex,
psbt: {
hex: signedPsbt.toHex(),
base64: signedPsbt.toBase64()
}
};
// Do nothing, leave the rawTxHex as null
}

result = {
rawTxHex,
psbt: {
hex: signedPsbt.toHex(),
base64: signedPsbt.toBase64()
}
result.psbt = {
hex: signedPsbt.toHex(),
base64: signedPsbt.toBase64()
};
};

Expand Down

0 comments on commit 6f0391b

Please sign in to comment.