File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 11export * from './4mat.browser'
22
33import { webcrypto } from 'node:crypto'
4+ import { base16 , base64 , bech32 , bech32m } from '@scure/base'
45
56/** Returns Uint8Array of given length. */
67export const randomBytes = ( n : number = 16 ) =>
78 webcrypto . getRandomValues ( new Uint8Array ( n ) )
9+
10+ /** Returns a hex-encoded string of given length.
11+ * Default is 16 bytes, i.e. 128 bits of entropy. */
12+ export const randomBase16 = ( n : number = 16 ) =>
13+ base16 . encode ( randomBytes ( n ) )
14+
15+ /** Returns a base64-encoded string of given length.
16+ * Default is 64 bytes, i.e. 512 bits of entropy. */
17+ export const randomBase64 = ( n : number = 64 ) =>
18+ base64 . encode ( randomBytes ( n ) )
19+
20+ /** Returns a random valid bech32 address.
21+ * Default length is 32 bytes (canonical addr in Cosmos) */
22+ export const randomBech32 = ( prefix = 'hackbg' , n = 32 ) =>
23+ bech32 . encode ( prefix , bech32 . toWords ( randomBytes ( n ) ) )
24+
25+ /** Returns a random valid bech32m address. */
26+ export const randomBech32m = ( prefix = 'hackbg' , n = 32 ) =>
27+ bech32m . encode ( prefix , bech32m . toWords ( randomBytes ( n ) ) )
Original file line number Diff line number Diff line change 11{
22 "name" : " @hackbg/4mat" ,
3- "version" : " 2.0.3 " ,
3+ "version" : " 2.0.4 " ,
44 "main" : " 4mat.ts" ,
55 "browser" : " 4mat.browser.ts" ,
66 "type" : " module" ,
You can’t perform that action at this time.
0 commit comments