Skip to content

Commit 3cbed34

Browse files
authored
Merge pull request #1168 from okxwallet/main
add okxwallet signMessage
2 parents 5b83097 + d2c47d5 commit 3cbed34

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

packages/okx-wallet/src/lib/injected-okx-wallet.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import type {
2+
SignedMessage,
3+
SignMessageParams,
4+
} from "@near-wallet-selector/core";
5+
16
export interface AccessKey {
27
publicKey: string;
38
secretKey: string;
@@ -70,4 +75,5 @@ export interface InjectedOkx {
7075
requestSignTransactions: (
7176
params: RequestSignTransactionsParams
7277
) => Promise<RequestSignTransactionsResponse>;
78+
signMessage: (params: SignMessageParams) => Promise<SignedMessage>;
7379
}

packages/okx-wallet/src/lib/okx-wallet.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ const mockOkx = () => {
4949
requestSignTransactions: jest.fn().mockResolvedValue({
5050
txs: [{ signedTx: "signedTx" }],
5151
}),
52+
signMessage: jest.fn().mockResolvedValue({
53+
publickey: "publickey",
54+
accountId: "accountId",
55+
signature: "signature",
56+
}),
5257
},
5358
};
5459

@@ -131,3 +136,25 @@ describe("signAndSendTransactions", () => {
131136
expect(result.length).toEqual(transactions.length);
132137
});
133138
});
139+
140+
describe("signMessage", () => {
141+
it("signMessage in okx wallet", async () => {
142+
const { wallet, injectedOkx } = await createOKXWallet();
143+
await wallet.signIn({ contractId: "test.testnet" });
144+
const result = await wallet.signMessage!({
145+
message: "message",
146+
recipient: "recipient",
147+
nonce: Buffer.from(
148+
"4268ebc14ff247f5450d4a8682bec3729a06d268f83b0cb363083ab05b65486b",
149+
"hex"
150+
),
151+
});
152+
153+
expect(injectedOkx!.signMessage).toHaveBeenCalled();
154+
expect(result).toEqual({
155+
publickey: "publickey",
156+
accountId: "accountId",
157+
signature: "signature",
158+
});
159+
});
160+
});

packages/okx-wallet/src/lib/okx-wallet.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,13 @@ const OKXWallet: WalletBehaviourFactory<InjectedWallet> = async ({
167167
throw new Error(`Method not supported by ${metadata.name}`);
168168
},
169169

170-
async signMessage() {
171-
throw new Error(`Method not supported by ${metadata.name}`);
170+
async signMessage(message) {
171+
try {
172+
const signedMessage = await _state.wallet.signMessage(message);
173+
return signedMessage;
174+
} catch (error) {
175+
throw new Error("sign Error");
176+
}
172177
},
173178

174179
async signAndSendTransaction({ signerId, receiverId, actions }) {

0 commit comments

Comments
 (0)