Skip to content

Commit db45ce2

Browse files
Make use of the native crypto module to create random nonce.
1 parent 3682242 commit db45ce2

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

examples/angular/src/app/components/content/content.component.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import { CONTRACT_ID } from "../../../constants";
2626
import { WalletSelector } from "@near-wallet-selector/core";
2727
import type { GetAccountBalanceProps } from "../../interfaces/account-balance";
2828
import BN from "bn.js";
29-
import { randomBytes } from "crypto";
3029

3130
const SUGGESTED_DONATION = "0";
3231
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -238,7 +237,7 @@ export class ContentComponent implements OnInit, OnDestroy {
238237
async onSignMessage() {
239238
const wallet = await this.selector.wallet();
240239
const message = "test message to sign";
241-
const nonce = randomBytes(32);
240+
const nonce = Buffer.from(crypto.getRandomValues(new Uint8Array(32)));
242241
const recipient = "guest-book.testnet";
243242

244243
if (wallet.type === "browser") {

examples/react/components/Content.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { CONTRACT_ID } from "../constants";
1919
import SignIn from "./SignIn";
2020
import Form from "./Form";
2121
import Messages from "./Messages";
22-
import { randomBytes } from "crypto";
2322

2423
type Submitted = SubmitEvent & {
2524
target: { elements: { [key: string]: HTMLInputElement } };
@@ -339,7 +338,7 @@ const Content: React.FC = () => {
339338
const wallet = await selector.wallet();
340339

341340
const message = "test message to sign";
342-
const nonce = randomBytes(32);
341+
const nonce = Buffer.from(crypto.getRandomValues(new Uint8Array(32)));
343342
const recipient = "guest-book.testnet";
344343

345344
if (wallet.type === "browser") {

0 commit comments

Comments
 (0)