diff --git a/packages/okx-wallet/src/lib/injected-okx-wallet.ts b/packages/okx-wallet/src/lib/injected-okx-wallet.ts index aa967c5f3..913977579 100644 --- a/packages/okx-wallet/src/lib/injected-okx-wallet.ts +++ b/packages/okx-wallet/src/lib/injected-okx-wallet.ts @@ -1,3 +1,8 @@ +import type { + SignedMessage, + SignMessageParams, +} from "@near-wallet-selector/core"; + export interface AccessKey { publicKey: string; secretKey: string; @@ -70,4 +75,5 @@ export interface InjectedOkx { requestSignTransactions: ( params: RequestSignTransactionsParams ) => Promise; + signMessage: (params: SignMessageParams) => Promise; } diff --git a/packages/okx-wallet/src/lib/okx-wallet.spec.ts b/packages/okx-wallet/src/lib/okx-wallet.spec.ts index 56b45c01b..6ce71ab5c 100644 --- a/packages/okx-wallet/src/lib/okx-wallet.spec.ts +++ b/packages/okx-wallet/src/lib/okx-wallet.spec.ts @@ -49,6 +49,11 @@ const mockOkx = () => { requestSignTransactions: jest.fn().mockResolvedValue({ txs: [{ signedTx: "signedTx" }], }), + signMessage: jest.fn().mockResolvedValue({ + publickey: "publickey", + accountId: "accountId", + signature: "signature", + }), }, }; @@ -131,3 +136,25 @@ describe("signAndSendTransactions", () => { expect(result.length).toEqual(transactions.length); }); }); + +describe("signMessage", () => { + it("signMessage in okx wallet", async () => { + const { wallet, injectedOkx } = await createOKXWallet(); + await wallet.signIn({ contractId: "test.testnet" }); + const result = await wallet.signMessage!({ + message: "message", + recipient: "recipient", + nonce: Buffer.from( + "4268ebc14ff247f5450d4a8682bec3729a06d268f83b0cb363083ab05b65486b", + "hex" + ), + }); + + expect(injectedOkx!.signMessage).toHaveBeenCalled(); + expect(result).toEqual({ + publickey: "publickey", + accountId: "accountId", + signature: "signature", + }); + }); +}); diff --git a/packages/okx-wallet/src/lib/okx-wallet.ts b/packages/okx-wallet/src/lib/okx-wallet.ts index 05b4b5768..3b33da7f0 100644 --- a/packages/okx-wallet/src/lib/okx-wallet.ts +++ b/packages/okx-wallet/src/lib/okx-wallet.ts @@ -167,8 +167,13 @@ const OKXWallet: WalletBehaviourFactory = async ({ throw new Error(`Method not supported by ${metadata.name}`); }, - async signMessage() { - throw new Error(`Method not supported by ${metadata.name}`); + async signMessage(message) { + try { + const signedMessage = await _state.wallet.signMessage(message); + return signedMessage; + } catch (error) { + throw new Error("sign Error"); + } }, async signAndSendTransaction({ signerId, receiverId, actions }) { diff --git a/scripts/release-packages.bash b/scripts/release-packages.bash index 14aeeece6..479b00cb5 100644 --- a/scripts/release-packages.bash +++ b/scripts/release-packages.bash @@ -27,3 +27,4 @@ npm publish dist/packages/ramper-wallet --tag "${TAG}" --otp "${OTP}" npm publish dist/packages/near-mobile-wallet --tag "${TAG}" --otp "${OTP}" npm publish dist/packages/mintbase-wallet --tag "${TAG}" --otp "${OTP}" npm publish dist/packages/bitget-wallet --tag "${TAG}" --otp "${OTP}" +npm publish dist/packages/okx-wallet --tag "${TAG}" --otp "${OTP}"