Spaces:
Sleeping
Sleeping
File size: 5,745 Bytes
2a1c46d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | /**
* Secret Key used for OTP generation.
*/
export declare type SecretKey = string;
/**
* A hex encoded string.
*/
export declare type HexString = string;
/**
* Base interface for all option interfaces.
* eg: [[HOTPOptions]].
*/
export interface OTPOptions {
[key: string]: unknown;
}
/**
* Returns an array of values of the enumerable properties of an object.
* This is used in place of Object.values for wider platform support.
*
* @ignore
*
* @param value Object that contains the properties and methods.
*/
export declare function objectValues<T>(value: T): string[];
/**
* Algorithms that are available to be used for
* calculating the HMAC value
*/
export declare enum HashAlgorithms {
'SHA1' = "sha1",
'SHA256' = "sha256",
'SHA512' = "sha512"
}
/**
* Array of [[HashAlgorithms]] enum values
*
* @ignore
*/
export declare const HASH_ALGORITHMS: string[];
/**
* The encoding format for the [[SecretKey]].
* This is mostly used for converting the
* provided secret into a Buffer.
*/
export declare enum KeyEncodings {
'ASCII' = "ascii",
'BASE64' = "base64",
'HEX' = "hex",
'LATIN1' = "latin1",
'UTF8' = "utf8"
}
/**
* Array of [[KeyEncodings]] enum values
*
* @ignore
*/
export declare const KEY_ENCODINGS: string[];
/**
* The OTP generation strategies.
* Either HMAC or Time based.
*/
export declare enum Strategy {
'HOTP' = "hotp",
'TOTP' = "totp"
}
/**
* Array of [[Strategy]] enum values
*
* @ignore
*/
export declare const STRATEGY: string[];
/**
* Interface method for formatting the [[SecretKey]] with
* the algorithm constraints before it is given to [[CreateDigest]].
*/
export interface CreateHmacKey<T = HexString> {
(algorithm: HashAlgorithms, secret: SecretKey, encoding: KeyEncodings): T;
}
/**
* Interface method for generating a HMAC digest
* which is then used to generate the token.
*/
export interface CreateDigest<T = HexString> {
(algorithm: HashAlgorithms, hmacKey: HexString, counter: HexString): T;
}
/**
* Inteface for options accepted by keyuri
*/
export interface KeyURIOptions {
accountName: string;
algorithm?: HashAlgorithms;
counter?: number;
digits?: number;
issuer?: string;
label?: string;
secret: SecretKey;
step?: number;
type: Strategy;
}
/**
* createDigest placholder function which throws an error
* when it is not replaced with an actual implementation.
*
* @ignore
*/
export declare const createDigestPlaceholder: CreateDigest;
/**
* Checks if a string contains a valid token format.
*
* @param value - a number string.
*/
export declare function isTokenValid(value: string): boolean;
/**
* Left pad the current string with a given string to a given length.
*
* This behaves similarly to String.prototype.padStart
*
* @ignore
*
* @param value The string to pad.
* @param maxLength The length of the resulting string once the current string has been padded.
* If this parameter is smaller than the current string's length, the current
* string will be returned as it is.
* @param fillString The string to pad the current string with.
*/
export declare function padStart(value: string, maxLength: number, fillString: string): string;
/**
* Generates an otpauth uri which can be used in a QR Code.
*
* Reference: https://github.com/google/google-authenticator/wiki/Key-Uri-Format
*
* Sample Output: otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example
*
* **Example**
*
* ```js
* import qrcode from 'qrcode';
*
* const otpauth = keyuri({ ... })
*
* qrcode.toDataURL(otpauth, (err, imageUrl) => {
* if (err) {
* console.log('Error with QR');
* return;
* }
* console.log(imageUrl);
* });
* ```
*/
export declare function keyuri(options: KeyURIOptions): string;
/**
* Base OTP class which provides options management
* All OTP classes should be extended from this class.
*/
export declare class OTP<T extends OTPOptions = OTPOptions> {
/**
* Default options for an instance.
*
* These options **WILL PERSIST** even when [[resetOptions]] is called.
*/
protected _defaultOptions: Readonly<Partial<T>>;
/**
* Transient options for an instance.
*
* Values set here will take precedence over the same options that
* are set in [[_defaultOptions]].
*
* These options **WILL NOT PERSIST** upon calling [[resetOptions]].
*/
protected _options: Readonly<Partial<T>>;
/**
* Constructs the class with defaultOptions set.
*
* @param defaultOptions used to override or add existing defaultOptions.
*/
constructor(defaultOptions?: Partial<T>);
/**
* Creates a new instance with all defaultOptions and options reset.
*/
create(defaultOptions?: Partial<T>): OTP<T>;
/**
* Copies the defaultOptions and options from the current
* instance and applies the provided defaultOptions.
*/
clone(defaultOptions?: Partial<T>): ReturnType<this['create']>;
/**
* - The options **getter** will return all [[_options]],
* including those set into [[_defaultOptions]].
*/
get options(): Partial<T>;
/**
* - The options **setter** sets values into [[_options]].
*/
set options(options: Partial<T>);
/**
* Returns class options polyfilled with some of
* the missing required options.
*
* Reference: [[hotpOptions]]
*/
allOptions(): Readonly<T>;
/**
* Resets the current options. Does not reset default options.
*
* Default options are those that are specified during class
* inititialisation, when calling [[clone]] or when calling [[create]]
*/
resetOptions(): void;
}
|