File tree 2 files changed +8
-4
lines changed
2 files changed +8
-4
lines changed Original file line number Diff line number Diff line change 1
- import { Logger } from "@renproject/interfaces" ;
2
1
import BigNumber from "bignumber.js" ;
3
2
import { defaultAbiCoder } from "ethers/lib/utils" ;
4
3
4
+ import { Logger } from "@renproject/interfaces" ;
5
+
5
6
import { assertType } from "./assert" ;
6
7
7
8
/**
@@ -231,9 +232,12 @@ export const randomBytes = (bytes: number): Buffer => {
231
232
} ;
232
233
233
234
/**
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.
235
238
*/
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 ) ] ) ;
237
241
238
242
export const emptyNonce = ( ) : Buffer => fromHex ( "00" . repeat ( 32 ) ) ;
239
243
Original file line number Diff line number Diff line change @@ -257,7 +257,7 @@ describe("common utils", () => {
257
257
} ) ;
258
258
} ) ;
259
259
260
- context ( "randomNonce" , ( ) => {
260
+ context . only ( "randomNonce" , ( ) => {
261
261
it ( "should return a random 32-byte buffer" , ( ) => {
262
262
expect ( randomNonce ( ) . length ) . toEqual ( 32 ) ;
263
263
expect ( randomNonce ( ) ) . not . toEqual ( randomNonce ( ) ) ;
You can’t perform that action at this time.
0 commit comments