Skip to content

Commit

Permalink
Merge pull request #1067 from near/improve-sign-message-for-mnw
Browse files Browse the repository at this point in the history
fix: Pass `nonce` as `base64` to URL for MyNearWallet
  • Loading branch information
kujtimprenkuSQA authored Feb 5, 2024
2 parents b03a06e + db45ce2 commit 0136d9b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export class ContentComponent implements OnInit, OnDestroy {
async onSignMessage() {
const wallet = await this.selector.wallet();
const message = "test message to sign";
const nonce = Buffer.from(Array.from(Array(32).keys()));
const nonce = Buffer.from(crypto.getRandomValues(new Uint8Array(32)));
const recipient = "guest-book.testnet";

if (wallet.type === "browser") {
Expand Down
2 changes: 1 addition & 1 deletion examples/react/components/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ const Content: React.FC = () => {
const wallet = await selector.wallet();

const message = "test message to sign";
const nonce = Buffer.from(Array.from(Array(32).keys()));
const nonce = Buffer.from(crypto.getRandomValues(new Uint8Array(32)));
const recipient = "guest-book.testnet";

if (wallet.type === "browser") {
Expand Down
9 changes: 6 additions & 3 deletions packages/my-near-wallet/src/lib/my-near-wallet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,13 @@ describe("signMessage", () => {

const result = await wallet.signMessage!(attributes);

const nonceBase64 = attributes.nonce.toString("base64");
const urlParams = `https://testnet.mynearwallet.com/sign-message?message=test+message&nonce=${encodeURIComponent(
nonceBase64
)}&recipient=test.app&callbackUrl=https%3A%2F%2Ftest.app`;

expect(result).toBe(undefined);
expect(window.location.replace).toHaveBeenCalledWith(
"https://testnet.mynearwallet.com/sign-message?message=test+message&nonce=30990309-30990309-390A303-292090&recipient=test.app&callbackUrl=https%3A%2F%2Ftest.app"
);
expect(window.location.replace).toHaveBeenCalledWith(urlParams);

window.location.replace = replace;
});
Expand Down
2 changes: 1 addition & 1 deletion packages/my-near-wallet/src/lib/my-near-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ const MyNearWallet: WalletBehaviourFactory<
const href = new URL(params.walletUrl);
href.pathname = "sign-message";
href.searchParams.append("message", message);
href.searchParams.append("nonce", nonce.toString());
href.searchParams.append("nonce", nonce.toString("base64"));
href.searchParams.append("recipient", recipient);
href.searchParams.append("callbackUrl", url);
if (state) {
Expand Down

0 comments on commit 0136d9b

Please sign in to comment.