From cdf62a011513f7ee5e9c110612466d3cc3876c13 Mon Sep 17 00:00:00 2001 From: esau <152162806+sklppy88@users.noreply.github.com> Date: Wed, 14 Aug 2024 17:37:55 +0200 Subject: [PATCH] feat: add generate-secret-and-hash to cli (#7977) --- .../cli/src/cmds/misc/generate_secret_and_hash.ts | 15 +++++++++++++++ yarn-project/cli/src/cmds/misc/index.ts | 8 ++++++++ 2 files changed, 23 insertions(+) create mode 100644 yarn-project/cli/src/cmds/misc/generate_secret_and_hash.ts diff --git a/yarn-project/cli/src/cmds/misc/generate_secret_and_hash.ts b/yarn-project/cli/src/cmds/misc/generate_secret_and_hash.ts new file mode 100644 index 00000000000..fddea589c33 --- /dev/null +++ b/yarn-project/cli/src/cmds/misc/generate_secret_and_hash.ts @@ -0,0 +1,15 @@ +import { computeSecretHash } from '@aztec/aztec.js'; +import { Fr } from '@aztec/foundation/fields'; +import { type LogFn } from '@aztec/foundation/log'; + +export function generateSecretAndHash(log: LogFn) { + const secret = Fr.random(); + + // We hash this the same way that aztec nr hash does. + const secretHash = computeSecretHash(secret); + + log(` + Secret: ${secret} + Secret hash: ${secretHash} + `); +} diff --git a/yarn-project/cli/src/cmds/misc/index.ts b/yarn-project/cli/src/cmds/misc/index.ts index 474ab0e24bf..75d30d59e04 100644 --- a/yarn-project/cli/src/cmds/misc/index.ts +++ b/yarn-project/cli/src/cmds/misc/index.ts @@ -48,6 +48,14 @@ export function injectCommands(program: Command, log: LogFn) { computeSelector(functionSignature, log); }); + program + .command('generate-secret-and-hash') + .description('Generates an arbitrary secret (Fr), and its hash (using aztec-nr defaults)') + .action(async () => { + const { generateSecretAndHash } = await import('./generate_secret_and_hash.js'); + generateSecretAndHash(log); + }); + program .command('update') .description('Updates Nodejs and Noir dependencies')