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

fix: coin98 wallet add signMessage method #1122

Open
wants to merge 6 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
10 changes: 10 additions & 0 deletions packages/coin98-wallet/src/lib/coin98-wallet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ const mockCoin98WalletOnWindow = () => {
return "";
}),
disconnect: jest.fn(),
signMessage: jest.fn().mockReturnValue({
signature: Buffer.from([
86, 38, 222, 143, 115, 251, 107, 14, 115, 59, 92, 98, 66, 174, 173,
124, 209, 189, 191, 180, 89, 25, 125, 254, 97, 240, 178, 98, 65, 70,
238, 108, 105, 122, 165, 249, 193, 70, 118, 194, 126, 218, 117, 100,
250, 124, 202, 161, 173, 12, 232, 146, 105, 194, 138, 35, 207, 53, 84,
218, 45, 220, 10, 4,
]),
publicKey,
}),
},
};

Expand Down
29 changes: 29 additions & 0 deletions packages/coin98-wallet/src/lib/coin98-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import type {
Account,
Optional,
Transaction,
SignMessageParams,
SignedMessage,
} from "@near-wallet-selector/core";
import { getActiveAccount } from "@near-wallet-selector/core";
import type { InjectedCoin98 } from "./injected-coin98-wallet";
Expand Down Expand Up @@ -105,6 +107,33 @@ const Coin98Wallet: WalletBehaviourFactory<InjectedWallet> = async ({
return getAccounts();
},

async signMessage({
message,
nonce,
recipient,
state,
}: SignMessageParams): Promise<SignedMessage> {
if (!_state.wallet) {
throw new Error("Wallet is not installed");
}

logger.log("Coin98:signMessage", {
message,
nonce,
recipient,
state,
});

const signature = await _state.wallet.near.signMessage({
message,
nonce,
recipient,
state,
});

return signature;
},

async signOut() {
// Ignore if unsuccessful (returns false).
await _state.wallet.near.disconnect();
Expand Down
5 changes: 5 additions & 0 deletions packages/coin98-wallet/src/lib/injected-coin98-wallet.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import type {
SignedMessage,
SignMessageParams,
} from "@near-wallet-selector/core";
import type { Signer } from "near-api-js/lib/signer";

interface IConnectParams {
Expand All @@ -10,6 +14,7 @@ interface ICoin98Near {
signer: Signer;
connect: (params: IConnectParams) => Promise<string>;
disconnect: () => Promise<void>;
signMessage: (params: SignMessageParams) => Promise<SignedMessage>;
}

export interface InjectedCoin98 {
Expand Down
Loading