Skip to content

Commit

Permalink
fix: padded printing for e2e-cli (#2106)
Browse files Browse the repository at this point in the history
This fixes a 1 in 256 chance of failure when the last hex byte was 00.
  • Loading branch information
ludamad authored Sep 7, 2023
1 parent c6890fe commit 5988014
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions yarn-project/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
publicKey = await generatePublicKey(key);
} else {
const key = GrumpkinScalar.random();
privKey = key.toString();
privKey = key.toString(true);
publicKey = await generatePublicKey(key);
}
log(`\nPrivate Key: ${privKey}\nPublic Key: ${publicKey.toString()}\n`);
Expand Down Expand Up @@ -144,7 +144,7 @@ export function getProgram(log: LogFn, debugLogger: DebugLogger): Command {
log(`\nCreated new account:\n`);
log(`Address: ${address.toString()}`);
log(`Public key: ${publicKey.toString()}`);
if (!options.privateKey) log(`Private key: ${privateKey.toString()}`);
if (!options.privateKey) log(`Private key: ${privateKey.toString(true)}`);
log(`Partial address: ${partialAddress.toString()}`);
});

Expand Down
5 changes: 3 additions & 2 deletions yarn-project/foundation/src/fields/grumpkin_scalar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ export class GrumpkinScalar {
* The resulting string is prefixed with '0x' and contains the exact number of hex characters required
* to represent the numeric value of this instance.
*
* @param padTo32 - Whether to pad the resulting string to 32 bytes.
* @returns A hexadecimal string representing the GrumpkinScalar value.
*/
toString() {
return toHex(this.value);
toString(padTo32 = false) {
return toHex(this.value, padTo32);
}

/**
Expand Down

0 comments on commit 5988014

Please sign in to comment.