edwards.d.ts 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
  2. import { AffinePoint, BasicCurve, Group, GroupConstructor } from './curve.js';
  3. import { FHash, Hex } from './utils.js';
  4. export type CurveType = BasicCurve<bigint> & {
  5. a: bigint;
  6. d: bigint;
  7. hash: FHash;
  8. randomBytes: (bytesLength?: number) => Uint8Array;
  9. adjustScalarBytes?: (bytes: Uint8Array) => Uint8Array;
  10. domain?: (data: Uint8Array, ctx: Uint8Array, phflag: boolean) => Uint8Array;
  11. uvRatio?: (u: bigint, v: bigint) => {
  12. isValid: boolean;
  13. value: bigint;
  14. };
  15. prehash?: FHash;
  16. mapToCurve?: (scalar: bigint[]) => AffinePoint<bigint>;
  17. };
  18. declare function validateOpts(curve: CurveType): Readonly<{
  19. readonly nBitLength: number;
  20. readonly nByteLength: number;
  21. readonly Fp: import("./modular.js").IField<bigint>;
  22. readonly n: bigint;
  23. readonly h: bigint;
  24. readonly hEff?: bigint;
  25. readonly Gx: bigint;
  26. readonly Gy: bigint;
  27. readonly allowInfinityPoint?: boolean;
  28. readonly a: bigint;
  29. readonly d: bigint;
  30. readonly hash: FHash;
  31. readonly randomBytes: (bytesLength?: number) => Uint8Array;
  32. readonly adjustScalarBytes?: (bytes: Uint8Array) => Uint8Array;
  33. readonly domain?: (data: Uint8Array, ctx: Uint8Array, phflag: boolean) => Uint8Array;
  34. readonly uvRatio?: (u: bigint, v: bigint) => {
  35. isValid: boolean;
  36. value: bigint;
  37. };
  38. readonly prehash?: FHash;
  39. readonly mapToCurve?: (scalar: bigint[]) => AffinePoint<bigint>;
  40. readonly p: bigint;
  41. }>;
  42. export interface ExtPointType extends Group<ExtPointType> {
  43. readonly ex: bigint;
  44. readonly ey: bigint;
  45. readonly ez: bigint;
  46. readonly et: bigint;
  47. get x(): bigint;
  48. get y(): bigint;
  49. assertValidity(): void;
  50. multiply(scalar: bigint): ExtPointType;
  51. multiplyUnsafe(scalar: bigint): ExtPointType;
  52. isSmallOrder(): boolean;
  53. isTorsionFree(): boolean;
  54. clearCofactor(): ExtPointType;
  55. toAffine(iz?: bigint): AffinePoint<bigint>;
  56. toRawBytes(isCompressed?: boolean): Uint8Array;
  57. toHex(isCompressed?: boolean): string;
  58. }
  59. export interface ExtPointConstructor extends GroupConstructor<ExtPointType> {
  60. new (x: bigint, y: bigint, z: bigint, t: bigint): ExtPointType;
  61. fromAffine(p: AffinePoint<bigint>): ExtPointType;
  62. fromHex(hex: Hex): ExtPointType;
  63. fromPrivateKey(privateKey: Hex): ExtPointType;
  64. }
  65. export type CurveFn = {
  66. CURVE: ReturnType<typeof validateOpts>;
  67. getPublicKey: (privateKey: Hex) => Uint8Array;
  68. sign: (message: Hex, privateKey: Hex, options?: {
  69. context?: Hex;
  70. }) => Uint8Array;
  71. verify: (sig: Hex, message: Hex, publicKey: Hex, options?: {
  72. context?: Hex;
  73. zip215: boolean;
  74. }) => boolean;
  75. ExtendedPoint: ExtPointConstructor;
  76. utils: {
  77. randomPrivateKey: () => Uint8Array;
  78. getExtendedPublicKey: (key: Hex) => {
  79. head: Uint8Array;
  80. prefix: Uint8Array;
  81. scalar: bigint;
  82. point: ExtPointType;
  83. pointBytes: Uint8Array;
  84. };
  85. };
  86. };
  87. export declare function twistedEdwards(curveDef: CurveType): CurveFn;
  88. export {};
  89. //# sourceMappingURL=edwards.d.ts.map