ed25519.d.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { AffinePoint, Group } from './abstract/curve.js';
  2. import { ExtPointType } from './abstract/edwards.js';
  3. import { htfBasicOpts } from './abstract/hash-to-curve.js';
  4. import { Hex } from './abstract/utils.js';
  5. export declare const ED25519_TORSION_SUBGROUP: string[];
  6. export declare const ed25519: import("./abstract/edwards.js").CurveFn;
  7. export declare const ed25519ctx: import("./abstract/edwards.js").CurveFn;
  8. export declare const ed25519ph: import("./abstract/edwards.js").CurveFn;
  9. export declare const x25519: import("./abstract/montgomery.js").CurveFn;
  10. /**
  11. * Converts ed25519 public key to x25519 public key. Uses formula:
  12. * * `(u, v) = ((1+y)/(1-y), sqrt(-486664)*u/x)`
  13. * * `(x, y) = (sqrt(-486664)*u/v, (u-1)/(u+1))`
  14. * @example
  15. * const someonesPub = ed25519.getPublicKey(ed25519.utils.randomPrivateKey());
  16. * const aPriv = x25519.utils.randomPrivateKey();
  17. * x25519.getSharedSecret(aPriv, edwardsToMontgomeryPub(someonesPub))
  18. */
  19. export declare function edwardsToMontgomeryPub(edwardsPub: Hex): Uint8Array;
  20. export declare const edwardsToMontgomery: typeof edwardsToMontgomeryPub;
  21. /**
  22. * Converts ed25519 secret key to x25519 secret key.
  23. * @example
  24. * const someonesPub = x25519.getPublicKey(x25519.utils.randomPrivateKey());
  25. * const aPriv = ed25519.utils.randomPrivateKey();
  26. * x25519.getSharedSecret(edwardsToMontgomeryPriv(aPriv), someonesPub)
  27. */
  28. export declare function edwardsToMontgomeryPriv(edwardsPriv: Uint8Array): Uint8Array;
  29. export declare const hashToCurve: (msg: Uint8Array, options?: htfBasicOpts) => import("./abstract/hash-to-curve.js").H2CPoint<bigint>;
  30. export declare const encodeToCurve: (msg: Uint8Array, options?: htfBasicOpts) => import("./abstract/hash-to-curve.js").H2CPoint<bigint>;
  31. type ExtendedPoint = ExtPointType;
  32. /**
  33. * Each ed25519/ExtendedPoint has 8 different equivalent points. This can be
  34. * a source of bugs for protocols like ring signatures. Ristretto was created to solve this.
  35. * Ristretto point operates in X:Y:Z:T extended coordinates like ExtendedPoint,
  36. * but it should work in its own namespace: do not combine those two.
  37. * https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-ristretto255-decaf448
  38. */
  39. declare class RistPoint implements Group<RistPoint> {
  40. private readonly ep;
  41. static BASE: RistPoint;
  42. static ZERO: RistPoint;
  43. constructor(ep: ExtendedPoint);
  44. static fromAffine(ap: AffinePoint<bigint>): RistPoint;
  45. /**
  46. * Takes uniform output of 64-byte hash function like sha512 and converts it to `RistrettoPoint`.
  47. * The hash-to-group operation applies Elligator twice and adds the results.
  48. * **Note:** this is one-way map, there is no conversion from point to hash.
  49. * https://ristretto.group/formulas/elligator.html
  50. * @param hex 64-byte output of a hash function
  51. */
  52. static hashToCurve(hex: Hex): RistPoint;
  53. /**
  54. * Converts ristretto-encoded string to ristretto point.
  55. * https://ristretto.group/formulas/decoding.html
  56. * @param hex Ristretto-encoded 32 bytes. Not every 32-byte string is valid ristretto encoding
  57. */
  58. static fromHex(hex: Hex): RistPoint;
  59. /**
  60. * Encodes ristretto point to Uint8Array.
  61. * https://ristretto.group/formulas/encoding.html
  62. */
  63. toRawBytes(): Uint8Array;
  64. toHex(): string;
  65. toString(): string;
  66. equals(other: RistPoint): boolean;
  67. add(other: RistPoint): RistPoint;
  68. subtract(other: RistPoint): RistPoint;
  69. multiply(scalar: bigint): RistPoint;
  70. multiplyUnsafe(scalar: bigint): RistPoint;
  71. double(): RistPoint;
  72. negate(): RistPoint;
  73. }
  74. export declare const RistrettoPoint: typeof RistPoint;
  75. export declare const hashToRistretto255: (msg: Uint8Array, options: htfBasicOpts) => RistPoint;
  76. export declare const hash_to_ristretto255: (msg: Uint8Array, options: htfBasicOpts) => RistPoint;
  77. export {};
  78. //# sourceMappingURL=ed25519.d.ts.map