Skip to content

Commit

Permalink
feat: add the signMessage(ecdsa) function for keystone wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronisme committed Dec 17, 2024
1 parent cdb4fd6 commit 0abb2e8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
27 changes: 23 additions & 4 deletions src/core/wallets/btc/keystone/provider.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -151,11 +151,30 @@ export class KeystoneProvider implements IBTCProvider {
};

signMessage = async (message: string, type: "ecdsa"): Promise<string> => {
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_SIGN_REQUEST);

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<InscriptionIdentifier[]> => {
Expand Down

0 comments on commit 0abb2e8

Please sign in to comment.