From abb7e51af33ceec90ebe445f5426149aec72ae31 Mon Sep 17 00:00:00 2001 From: "quanquan.luo" Date: Wed, 19 Jun 2024 10:53:07 +0800 Subject: [PATCH 1/4] chore: add publish script for okx-wallet --- scripts/release-packages.bash | 1 + 1 file changed, 1 insertion(+) 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}" From 49681cd5c930f10c9a84ead209a1c83c16b75c95 Mon Sep 17 00:00:00 2001 From: "quanquan.luo" Date: Tue, 13 Aug 2024 16:40:03 +0800 Subject: [PATCH 2/4] feat: add signMessage for okx wallet --- packages/okx-wallet/src/lib/injected-okx-wallet.ts | 6 ++++++ packages/okx-wallet/src/lib/okx-wallet.ts | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) 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.ts b/packages/okx-wallet/src/lib/okx-wallet.ts index 05b4b5768..f37d744ad 100644 --- a/packages/okx-wallet/src/lib/okx-wallet.ts +++ b/packages/okx-wallet/src/lib/okx-wallet.ts @@ -167,8 +167,12 @@ 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 { + return _state.wallet.signMessage(message); + } catch (error) { + throw new Error("sign Error"); + } }, async signAndSendTransaction({ signerId, receiverId, actions }) { From 167be49dfd825b9432d8e62e4855778f4a71267d Mon Sep 17 00:00:00 2001 From: "quanquan.luo" Date: Tue, 13 Aug 2024 16:43:34 +0800 Subject: [PATCH 3/4] test: add unit test for signMessage method --- .../okx-wallet/src/lib/okx-wallet.spec.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) 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", + }); + }); +}); From e97d1b860a11f87893653369ded88ae2df9c5f5f Mon Sep 17 00:00:00 2001 From: "quanquan.luo" Date: Wed, 14 Aug 2024 11:26:59 +0800 Subject: [PATCH 4/4] feat: optimize okx signMessage logic --- packages/okx-wallet/src/lib/okx-wallet.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/okx-wallet/src/lib/okx-wallet.ts b/packages/okx-wallet/src/lib/okx-wallet.ts index f37d744ad..3b33da7f0 100644 --- a/packages/okx-wallet/src/lib/okx-wallet.ts +++ b/packages/okx-wallet/src/lib/okx-wallet.ts @@ -169,7 +169,8 @@ const OKXWallet: WalletBehaviourFactory = async ({ async signMessage(message) { try { - return _state.wallet.signMessage(message); + const signedMessage = await _state.wallet.signMessage(message); + return signedMessage; } catch (error) { throw new Error("sign Error"); }