diff --git a/examples/angular/src/app/components/content/content.component.ts b/examples/angular/src/app/components/content/content.component.ts index 631c027da..31b010090 100644 --- a/examples/angular/src/app/components/content/content.component.ts +++ b/examples/angular/src/app/components/content/content.component.ts @@ -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") { diff --git a/examples/react/components/Content.tsx b/examples/react/components/Content.tsx index 68d60c6c6..271442fa9 100644 --- a/examples/react/components/Content.tsx +++ b/examples/react/components/Content.tsx @@ -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") { diff --git a/packages/my-near-wallet/src/lib/my-near-wallet.spec.ts b/packages/my-near-wallet/src/lib/my-near-wallet.spec.ts index 94b32b37b..9c84817b6 100644 --- a/packages/my-near-wallet/src/lib/my-near-wallet.spec.ts +++ b/packages/my-near-wallet/src/lib/my-near-wallet.spec.ts @@ -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; }); diff --git a/packages/my-near-wallet/src/lib/my-near-wallet.ts b/packages/my-near-wallet/src/lib/my-near-wallet.ts index 0d3b3beb8..5a3721567 100644 --- a/packages/my-near-wallet/src/lib/my-near-wallet.ts +++ b/packages/my-near-wallet/src/lib/my-near-wallet.ts @@ -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) {