Skip to content

Commit ae26c7b

Browse files
committed
feat: reduce random nonce to 3 bytes
1 parent d09d86b commit ae26c7b

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

packages/lib/utils/src/common.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { Logger } from "@renproject/interfaces";
21
import BigNumber from "bignumber.js";
32
import { defaultAbiCoder } from "ethers/lib/utils";
43

4+
import { Logger } from "@renproject/interfaces";
5+
56
import { assertType } from "./assert";
67

78
/**
@@ -231,9 +232,12 @@ export const randomBytes = (bytes: number): Buffer => {
231232
};
232233

233234
/**
234-
* Returns a random 32 byte Buffer.
235+
* Returns a random 3-byte Buffer, padded to 32 bytes. This was reduced from
236+
* using the full 32-bytes so that mint details can be recovered if all the
237+
* other details besides the nonce are known.
235238
*/
236-
export const randomNonce = (): Buffer => randomBytes(32);
239+
export const randomNonce = (n: number = 3): Buffer =>
240+
Buffer.concat([fromHex("00".repeat(32 - n)), randomBytes(n)]);
237241

238242
export const emptyNonce = (): Buffer => fromHex("00".repeat(32));
239243

packages/lib/utils/test/common.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ describe("common utils", () => {
257257
});
258258
});
259259

260-
context("randomNonce", () => {
260+
context.only("randomNonce", () => {
261261
it("should return a random 32-byte buffer", () => {
262262
expect(randomNonce().length).toEqual(32);
263263
expect(randomNonce()).not.toEqual(randomNonce());

0 commit comments

Comments
 (0)