blake3.d.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { BLAKE2 } from './blake2.ts';
  2. import { type CHashXO, type HashXOF, type Input } from './utils.ts';
  3. /**
  4. * Ensure to use EITHER `key` OR `context`, not both.
  5. *
  6. * * `key`: 32-byte MAC key.
  7. * * `context`: string for KDF. Should be hardcoded, globally unique, and application - specific.
  8. * A good default format for the context string is "[application] [commit timestamp] [purpose]".
  9. */
  10. export type Blake3Opts = {
  11. dkLen?: number;
  12. key?: Input;
  13. context?: Input;
  14. };
  15. /** Blake3 hash. Can be used as MAC and KDF. */
  16. export declare class BLAKE3 extends BLAKE2<BLAKE3> implements HashXOF<BLAKE3> {
  17. private chunkPos;
  18. private chunksDone;
  19. private flags;
  20. private IV;
  21. private state;
  22. private stack;
  23. private posOut;
  24. private bufferOut32;
  25. private bufferOut;
  26. private chunkOut;
  27. private enableXOF;
  28. constructor(opts?: Blake3Opts, flags?: number);
  29. protected get(): [];
  30. protected set(): void;
  31. private b2Compress;
  32. protected compress(buf: Uint32Array, bufPos?: number, isLast?: boolean): void;
  33. _cloneInto(to?: BLAKE3): BLAKE3;
  34. destroy(): void;
  35. private b2CompressOut;
  36. protected finish(): void;
  37. private writeInto;
  38. xofInto(out: Uint8Array): Uint8Array;
  39. xof(bytes: number): Uint8Array;
  40. digestInto(out: Uint8Array): Uint8Array;
  41. digest(): Uint8Array;
  42. }
  43. /**
  44. * BLAKE3 hash function. Can be used as MAC and KDF.
  45. * @param msg - message that would be hashed
  46. * @param opts - `dkLen` for output length, `key` for MAC mode, `context` for KDF mode
  47. * @example
  48. * const data = new Uint8Array(32);
  49. * const hash = blake3(data);
  50. * const mac = blake3(data, { key: new Uint8Array(32) });
  51. * const kdf = blake3(data, { context: 'application name' });
  52. */
  53. export declare const blake3: CHashXO;
  54. //# sourceMappingURL=blake3.d.ts.map