hash-to-curve.d.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
  2. import type { AffinePoint, Group, GroupConstructor } from './curve.js';
  3. import { IField } from './modular.js';
  4. import type { CHash } from './utils.js';
  5. /**
  6. * * `DST` is a domain separation tag, defined in section 2.2.5
  7. * * `p` characteristic of F, where F is a finite field of characteristic p and order q = p^m
  8. * * `m` is extension degree (1 for prime fields)
  9. * * `k` is the target security target in bits (e.g. 128), from section 5.1
  10. * * `expand` is `xmd` (SHA2, SHA3, BLAKE) or `xof` (SHAKE, BLAKE-XOF)
  11. * * `hash` conforming to `utils.CHash` interface, with `outputLen` / `blockLen` props
  12. */
  13. type UnicodeOrBytes = string | Uint8Array;
  14. export type Opts = {
  15. DST: UnicodeOrBytes;
  16. p: bigint;
  17. m: number;
  18. k: number;
  19. expand: 'xmd' | 'xof';
  20. hash: CHash;
  21. };
  22. export declare function expand_message_xmd(msg: Uint8Array, DST: Uint8Array, lenInBytes: number, H: CHash): Uint8Array;
  23. export declare function expand_message_xof(msg: Uint8Array, DST: Uint8Array, lenInBytes: number, k: number, H: CHash): Uint8Array;
  24. /**
  25. * Hashes arbitrary-length byte strings to a list of one or more elements of a finite field F
  26. * https://www.rfc-editor.org/rfc/rfc9380#section-5.2
  27. * @param msg a byte string containing the message to hash
  28. * @param count the number of elements of F to output
  29. * @param options `{DST: string, p: bigint, m: number, k: number, expand: 'xmd' | 'xof', hash: H}`, see above
  30. * @returns [u_0, ..., u_(count - 1)], a list of field elements.
  31. */
  32. export declare function hash_to_field(msg: Uint8Array, count: number, options: Opts): bigint[][];
  33. export declare function isogenyMap<T, F extends IField<T>>(field: F, map: [T[], T[], T[], T[]]): (x: T, y: T) => {
  34. x: T;
  35. y: T;
  36. };
  37. export interface H2CPoint<T> extends Group<H2CPoint<T>> {
  38. add(rhs: H2CPoint<T>): H2CPoint<T>;
  39. toAffine(iz?: bigint): AffinePoint<T>;
  40. clearCofactor(): H2CPoint<T>;
  41. assertValidity(): void;
  42. }
  43. export interface H2CPointConstructor<T> extends GroupConstructor<H2CPoint<T>> {
  44. fromAffine(ap: AffinePoint<T>): H2CPoint<T>;
  45. }
  46. export type MapToCurve<T> = (scalar: bigint[]) => AffinePoint<T>;
  47. export type htfBasicOpts = {
  48. DST: UnicodeOrBytes;
  49. };
  50. export declare function createHasher<T>(Point: H2CPointConstructor<T>, mapToCurve: MapToCurve<T>, def: Opts & {
  51. encodeDST?: UnicodeOrBytes;
  52. }): {
  53. hashToCurve(msg: Uint8Array, options?: htfBasicOpts): H2CPoint<T>;
  54. encodeToCurve(msg: Uint8Array, options?: htfBasicOpts): H2CPoint<T>;
  55. mapToCurve(scalars: bigint[]): H2CPoint<T>;
  56. };
  57. export {};
  58. //# sourceMappingURL=hash-to-curve.d.ts.map