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

add okxwallet signMessage #1168

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
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
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
1 change: 1 addition & 0 deletions scripts/release-packages.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Loading