From 3e27ccbc666126b505c99701ee83e178492ada4f Mon Sep 17 00:00:00 2001 From: Nishant Ghodke <64554492+iamcrazycoder@users.noreply.github.com> Date: Mon, 6 Nov 2023 08:33:49 +0530 Subject: [PATCH] feat(unisat): extend message signer to accept type (#92) * feat(unisat): extend message signer to accept type * feat: default to `ecdsa` --- packages/sdk/src/browser-wallets/types.ts | 2 ++ packages/sdk/src/browser-wallets/unisat/signatures.ts | 7 +++---- packages/sdk/src/types.d.ts | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/sdk/src/browser-wallets/types.ts b/packages/sdk/src/browser-wallets/types.ts index 6a537ca5..434b40c9 100644 --- a/packages/sdk/src/browser-wallets/types.ts +++ b/packages/sdk/src/browser-wallets/types.ts @@ -2,3 +2,5 @@ export interface BrowserWalletSignPSBTResponse { hex: string base64: string | null } + +export type MessageSignatureTypes = "bip322-simple" | "ecdsa" diff --git a/packages/sdk/src/browser-wallets/unisat/signatures.ts b/packages/sdk/src/browser-wallets/unisat/signatures.ts index 8b2949ba..15e94e05 100644 --- a/packages/sdk/src/browser-wallets/unisat/signatures.ts +++ b/packages/sdk/src/browser-wallets/unisat/signatures.ts @@ -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" @@ -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.") } diff --git a/packages/sdk/src/types.d.ts b/packages/sdk/src/types.d.ts index 37c3fe82..ba47b52c 100644 --- a/packages/sdk/src/types.d.ts +++ b/packages/sdk/src/types.d.ts @@ -11,7 +11,7 @@ type Unisat = { getAccounts: () => Promise getPublicKey: () => Promise signPsbt: (hex: string, { autoFinalized }: Record) => Promise - signMessage: (message: string) => Promise + signMessage: (message: string, type: MessageSignatureTypes) => Promise } type MetaMask = {