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 4 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 @@
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,

Check failure on line 41 in packages/coin98-wallet/src/lib/coin98-wallet.spec.ts

View workflow job for this annotation

GitHub Actions / Test Suite

Insert `·84,`
84, 218, 45, 220, 10, 4,

Check failure on line 42 in packages/coin98-wallet/src/lib/coin98-wallet.spec.ts

View workflow job for this annotation

GitHub Actions / Test Suite

Delete `·84,`
]),
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 @@
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 @@
return getAccounts();
},

async signMessage({
message,

Check failure on line 111 in packages/coin98-wallet/src/lib/coin98-wallet.ts

View workflow job for this annotation

GitHub Actions / Test Suite

Delete `·`
nonce,

Check failure on line 112 in packages/coin98-wallet/src/lib/coin98-wallet.ts

View workflow job for this annotation

GitHub Actions / Test Suite

Delete `·`
recipient,

Check failure on line 113 in packages/coin98-wallet/src/lib/coin98-wallet.ts

View workflow job for this annotation

GitHub Actions / Test Suite

Delete `·`
state

Check failure on line 114 in packages/coin98-wallet/src/lib/coin98-wallet.ts

View workflow job for this annotation

GitHub Actions / Test Suite

Insert `,`
}: SignMessageParams): Promise<SignedMessage>{

Check failure on line 115 in packages/coin98-wallet/src/lib/coin98-wallet.ts

View workflow job for this annotation

GitHub Actions / Test Suite

Insert `·`
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
2 changes: 2 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,4 @@
import type { SignedMessage, SignMessageParams } from "@near-wallet-selector/core";

Check failure on line 1 in packages/coin98-wallet/src/lib/injected-coin98-wallet.ts

View workflow job for this annotation

GitHub Actions / Test Suite

Replace `·SignedMessage,·SignMessageParams·` with `⏎··SignedMessage,⏎··SignMessageParams,⏎`
import type { Signer } from "near-api-js/lib/signer";

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

export interface InjectedCoin98 {
Expand Down
Loading