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: Pass nonce as base64 to URL for MyNearWallet #1067

Merged
merged 6 commits into from
Feb 5, 2024
Merged
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
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
Loading