Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add the signMessage(ecdsa) function for keystone wallet #135

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_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<InscriptionIdentifier[]> => {
Expand Down