curve.d.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
  2. import { IField } from './modular.js';
  3. export type AffinePoint<T> = {
  4. x: T;
  5. y: T;
  6. } & {
  7. z?: never;
  8. t?: never;
  9. };
  10. export interface Group<T extends Group<T>> {
  11. double(): T;
  12. negate(): T;
  13. add(other: T): T;
  14. subtract(other: T): T;
  15. equals(other: T): boolean;
  16. multiply(scalar: bigint): T;
  17. }
  18. export type GroupConstructor<T> = {
  19. BASE: T;
  20. ZERO: T;
  21. };
  22. export type Mapper<T> = (i: T[]) => T[];
  23. export declare function wNAF<T extends Group<T>>(c: GroupConstructor<T>, bits: number): {
  24. constTimeNegate: (condition: boolean, item: T) => T;
  25. unsafeLadder(elm: T, n: bigint): T;
  26. /**
  27. * Creates a wNAF precomputation window. Used for caching.
  28. * Default window size is set by `utils.precompute()` and is equal to 8.
  29. * Number of precomputed points depends on the curve size:
  30. * 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
  31. * - 𝑊 is the window size
  32. * - 𝑛 is the bitlength of the curve order.
  33. * For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
  34. * @returns precomputed point tables flattened to a single array
  35. */
  36. precomputeWindow(elm: T, W: number): Group<T>[];
  37. /**
  38. * Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
  39. * @param W window size
  40. * @param precomputes precomputed tables
  41. * @param n scalar (we don't check here, but should be less than curve order)
  42. * @returns real and fake (for const-time) points
  43. */
  44. wNAF(W: number, precomputes: T[], n: bigint): {
  45. p: T;
  46. f: T;
  47. };
  48. wNAFCached(P: T, precomputesMap: Map<T, T[]>, n: bigint, transform: Mapper<T>): {
  49. p: T;
  50. f: T;
  51. };
  52. };
  53. export type BasicCurve<T> = {
  54. Fp: IField<T>;
  55. n: bigint;
  56. nBitLength?: number;
  57. nByteLength?: number;
  58. h: bigint;
  59. hEff?: bigint;
  60. Gx: T;
  61. Gy: T;
  62. allowInfinityPoint?: boolean;
  63. };
  64. export declare function validateBasic<FP, T>(curve: BasicCurve<FP> & T): Readonly<{
  65. readonly nBitLength: number;
  66. readonly nByteLength: number;
  67. } & BasicCurve<FP> & T & {
  68. p: bigint;
  69. }>;
  70. //# sourceMappingURL=curve.d.ts.map