Skip to content

Commit

Permalink
Merge pull request #3 from luoquanquan/main
Browse files Browse the repository at this point in the history
Add signMessage for okx-wallet
  • Loading branch information
okxwallet authored Aug 16, 2024
2 parents 4077231 + f430227 commit a580b38
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/okx-wallet/src/lib/injected-okx-wallet.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import type {
SignedMessage,
SignMessageParams,
} from "@near-wallet-selector/core";

export interface AccessKey {
publicKey: string;
secretKey: string;
Expand Down Expand Up @@ -70,4 +75,5 @@ export interface InjectedOkx {
requestSignTransactions: (
params: RequestSignTransactionsParams
) => Promise<RequestSignTransactionsResponse>;
signMessage: (params: SignMessageParams) => Promise<SignedMessage>;
}
27 changes: 27 additions & 0 deletions packages/okx-wallet/src/lib/okx-wallet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ const mockOkx = () => {
requestSignTransactions: jest.fn().mockResolvedValue({
txs: [{ signedTx: "signedTx" }],
}),
signMessage: jest.fn().mockResolvedValue({
publickey: "publickey",
accountId: "accountId",
signature: "signature",
}),
},
};

Expand Down Expand Up @@ -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",
});
});
});
9 changes: 7 additions & 2 deletions packages/okx-wallet/src/lib/okx-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,13 @@ const OKXWallet: WalletBehaviourFactory<InjectedWallet> = 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 }) {
Expand Down

0 comments on commit a580b38

Please sign in to comment.