@signumjs/crypto
Version:
Cryptographic functions for building Signum Network apps.
54 lines (53 loc) • 1.82 kB
TypeScript
/**
* Original work Copyright (c) 2024 Signum Network
*/
/**
* Gets am Array of random bytes
*
* This random function used is based on what kind of entropy the User Agent (Browser, OS) returns.
* Depending on its runtime environment, it may use https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
* or https://nodejs.org/api/webcrypto.html#cryptogetrandomvaluestypedarray
*
* This means for that for browsers a secure context, i.e. https is required to make it work!
*
* @param length Length of array
*
* @return An array of bytes of given length
*
*
* @category random
*/
export declare function getRandomBytes(length: number): Uint8Array;
/**
* Gets an array of random words from a dictionary
*
* > Usually 2048 words are sufficient. This method does not support dictionaries with more than 65536 words
*
* @param count The number of words generated
* @param dictionary An array of strings from where the random words are picked
*
* @return An array with _count_ words
* @throws An error if dictionary's length is smaller than _count_
*
* @category random
*/
export declare function getRandomWords(count: number, dictionary: string[]): string[];
/**
* Default Alphabet
* @see {@link getRandomString}
*
* @category random
*/
export declare const DefaultAlphabet: string;
/**
* Gets a string of random characters from a given alphabet
*
* @param length The length of the resulting string
* @param alphabet An string with characters used for random picks. Default Alphabet is alphanumeric without special chars
*
* @return A string with random characters of given length
* @throws An error if alphabet is empty or too large (2^16 chars is limit)
*
* @category random
*/
export declare function getRandomString(length: number, alphabet?: string): string;