diff --git a/package.json b/package.json index e0106c1..43baa5c 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "@keplr-wallet/types": "^0.12.156", "@keystonehq/animated-qr": "^0.8.6", "@keystonehq/keystone-sdk": "^0.4.1", - "@keystonehq/sdk": "^0.22.0", + "@keystonehq/sdk": "0.22.1", "buffer": "^6.0.3", "nanoevents": "^9.1.0" }, diff --git a/src/core/wallets/btc/keystone/provider.ts b/src/core/wallets/btc/keystone/provider.ts index b9b1e35..e4def25 100644 --- a/src/core/wallets/btc/keystone/provider.ts +++ b/src/core/wallets/btc/keystone/provider.ts @@ -1,5 +1,5 @@ import * as ecc from "@bitcoin-js/tiny-secp256k1-asmjs"; -import { KeystoneSDK, UR } from "@keystonehq/keystone-sdk"; +import { KeystoneBitcoinSDK, KeystoneSDK, UR } from "@keystonehq/keystone-sdk"; import { viewSdk as keystoneViewSDK, PlayStatus, ReadStatus, SDK, SupportedResult } from "@keystonehq/sdk"; import { HDKey } from "@scure/bip32"; import { PsbtInput } from "bip174/src/lib/interfaces"; @@ -151,11 +151,30 @@ export class KeystoneProvider implements IBTCProvider { }; signMessage = async (message: string, type: "ecdsa"): Promise => { + if (type !== "ecdsa") throw new Error("Only ECDSA signature is supported"); if (!this.keystoneWaleltInfo) throw new Error("Keystone Wallet not connected"); - // TODO implement - console.log("signMessage", message, type); - return ""; + const ur = this.dataSdk.btc.generateSignRequest({ + requestId: "7afd5e09-9267-43fb-a02e-08c4a09417ec", + signData: Buffer.from(message, "utf-8").toString("hex"), + dataType: KeystoneBitcoinSDK.DataType.message, + accounts: [ + { + path: `${this.keystoneWaleltInfo.path}/0/0`, + xfp: `${this.keystoneWaleltInfo.mfp}`, + address: this.keystoneWaleltInfo.address, + }, + ], + origin: "babylon staking app", + }); + + const signMessage = composeQRProcess(SupportedResult.UR_BTC_SIGNATURE); + + const keystoneContainer = await this.viewSDK.getSdk(); + const signedMessageUR = await signMessage(keystoneContainer, ur); + + const result = this.dataSdk.btc.parseSignature(signedMessageUR); + return Buffer.from(result.signature, "hex").toString("base64"); }; getInscriptions = async (): Promise => {