react-native-quick-crypto
Version:
A fast implementation of Node's `crypto` module written in C/C++ JSI
66 lines • 2.68 kB
TypeScript
import { Buffer } from '@craftzdog/react-native-buffer';
import { Stream } from 'readable-stream';
import type { TransformOptions } from 'readable-stream';
import type { BinaryLike, Encoding } from './utils/types';
declare class Hmac extends Stream.Transform {
private algorithm;
private key;
private native;
private validate;
/**
* @internal use `createHmac()` instead
*/
private constructor();
/**
* Updates the `Hmac` content with the given `data`, the encoding of which is given in `inputEncoding`.
* If `encoding` is not provided, and the `data` is a string, an encoding of `'utf8'` is enforced.
* If `data` is a `Buffer`, `TypedArray`, or`DataView`, then `inputEncoding` is ignored.
*
* This can be called many times with new data as it is streamed.
* @since v1.0.0
* @param inputEncoding The `encoding` of the `data` string.
*/
update(data: BinaryLike): Hmac;
update(data: BinaryLike, inputEncoding: Encoding): Hmac;
/**
* Calculates the HMAC digest of all of the data passed using `hmac.update()`.
* If `encoding` is provided a string is returned; otherwise a `Buffer` is returned;
*
* The `Hmac` object can not be used again after `hmac.digest()` has been
* called. Multiple calls to `hmac.digest()` will result in an error being thrown.
* @since v1.0.0
* @param encoding The `encoding` of the return value.
*/
digest(): Buffer;
digest(encoding: Encoding): string;
_transform(chunk: BinaryLike, encoding: BufferEncoding, callback: () => void): void;
_flush(callback: () => void): void;
}
/**
* Creates and returns an `Hmac` object that uses the given `algorithm` and `key`.
* Optional `options` argument controls stream behavior.
*
* The `algorithm` is dependent on the available algorithms supported by the
* version of OpenSSL on the platform. Examples are `'sha256'`, `'sha512'`, etc.
* On recent releases of OpenSSL, `openssl list -digest-algorithms` will
* display the available digest algorithms.
*
* Example: generating the sha256 HMAC of a file
*
* ```js
* import crypto from 'react-native-quick-crypto';
*
* const hmac = crypto.createHmac('sha256', 'secret-key');
* hmac.update('message to hash');
* const digest = hmac.digest('hex');
* console.log(digest); // prints HMAC digest in hexadecimal format
* ```
* @since v1.0.0
* @param options `stream.transform` options
*/
export declare function createHmac(algorithm: string, key: BinaryLike, options?: TransformOptions): Hmac;
export declare const hmacExports: {
createHmac: typeof createHmac;
};
export {};
//# sourceMappingURL=hmac.d.ts.map