Skip to content

Commit

Permalink
feat(unisat): extend message signer to accept type (#92)
Browse files Browse the repository at this point in the history
* feat(unisat): extend message signer to accept type

* feat: default to `ecdsa`
  • Loading branch information
iamcrazycoder authored Nov 6, 2023
1 parent de0fdf1 commit 3e27ccb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/sdk/src/browser-wallets/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export interface BrowserWalletSignPSBTResponse {
hex: string
base64: string | null
}

export type MessageSignatureTypes = "bip322-simple" | "ecdsa"
7 changes: 3 additions & 4 deletions packages/sdk/src/browser-wallets/unisat/signatures.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Psbt } from "bitcoinjs-lib"

import { BrowserWalletSignPSBTResponse } from "../types"
import { BrowserWalletSignPSBTResponse, MessageSignatureTypes } from "../types"
import { UnisatSignPSBTOptions } from "./types"
import { isUnisatInstalled } from "./utils"

Expand Down Expand Up @@ -30,13 +30,12 @@ export async function signPsbt(
}
}

export async function signMessage(message: string) {
export async function signMessage(message: string, type: MessageSignatureTypes = "ecdsa") {
if (!isUnisatInstalled()) {
throw new Error("Unisat not installed.")
}

const signature = await window.unisat.signMessage(message)

const signature = await window.unisat.signMessage(message, type)
if (!signature) {
throw new Error("Failed to sign message using Unisat.")
}
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Unisat = {
getAccounts: () => Promise<string[]>
getPublicKey: () => Promise<string>
signPsbt: (hex: string, { autoFinalized }: Record<string, boolean>) => Promise<string>
signMessage: (message: string) => Promise<string>
signMessage: (message: string, type: MessageSignatureTypes) => Promise<string>
}

type MetaMask = {
Expand Down

0 comments on commit 3e27ccb

Please sign in to comment.