hash-instance.d.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /// <reference types="node" />
  2. import { HashInput } from './hash-fn';
  3. import { IHasher, IInternalHash, IHasherDigestOptions } from '../base/index';
  4. import { Transform, TransformCallback } from 'stream';
  5. import { IBaseHashOptions } from '../base/hash-fn';
  6. import { NodeHashReader } from './hash-reader';
  7. export interface INodeHash extends IHasher<Buffer> {
  8. /**
  9. * @inheritdoc
  10. * @override
  11. */
  12. update(data: HashInput, encoding?: BufferEncoding): this;
  13. /**
  14. * @inheritdoc
  15. * @override
  16. */
  17. digest(options?: IBaseHashOptions): Buffer;
  18. /**
  19. * Returns a digest of the hash with the given set of hash options.
  20. */
  21. digest(encoding: undefined, options: IBaseHashOptions): Buffer;
  22. /**
  23. * Returns a digest of the hash with the given encoding.
  24. */
  25. digest(encoding: BufferEncoding, options?: IBaseHashOptions): string;
  26. }
  27. /**
  28. * @inheritdoc
  29. */
  30. export declare class NodeHash<Reader> extends Transform implements IHasher<Buffer> {
  31. private readonly hash;
  32. constructor(implementation: IInternalHash<Reader>, getReader: (r: Reader) => NodeHashReader);
  33. /**
  34. * @reader
  35. */
  36. reader(options?: {
  37. dispose?: boolean;
  38. }): NodeHashReader;
  39. /**
  40. * @inheritdoc
  41. */
  42. update(data: HashInput, encoding?: BufferEncoding): this;
  43. /**
  44. * @inheritdoc
  45. */
  46. digest(encoding?: IHasherDigestOptions): Buffer;
  47. digest(encoding: undefined, options: IHasherDigestOptions): Buffer;
  48. digest(encoding: BufferEncoding, options?: IHasherDigestOptions): string;
  49. /**
  50. * @inheritdoc
  51. */
  52. dispose(): void;
  53. /**
  54. * @inheritdoc
  55. * @hidden
  56. */
  57. _transform(chunk: Buffer | string, encoding: string, callback: TransformCallback): void;
  58. /**
  59. * @inheritdoc
  60. * @hidden
  61. */
  62. _flush(callback: TransformCallback): void;
  63. }
  64. /**
  65. * A Node.js crypto-like createHash method.
  66. */
  67. export declare const createHash: () => NodeHash<import("../../dist/wasm/nodejs/blake3_js").HashReader>;
  68. /**
  69. * Construct a new Hasher for the keyed hash function.
  70. */
  71. export declare const createKeyed: (key: Buffer) => NodeHash<import("../../dist/wasm/nodejs/blake3_js").HashReader>;
  72. /**
  73. * Construct a new Hasher for the key derivation function.
  74. */
  75. export declare const createDeriveKey: (context: string) => NodeHash<import("../../dist/wasm/nodejs/blake3_js").HashReader>;