secp256k1.d.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import { mod } from './abstract/modular.js';
  2. import type { Hex, PrivKey } from './abstract/utils.js';
  3. import { bytesToNumberBE, numberToBytesBE } from './abstract/utils.js';
  4. import { ProjPointType as PointType } from './abstract/weierstrass.js';
  5. export declare const secp256k1: Readonly<{
  6. create: (hash: import("./abstract/utils.js").CHash) => import("./abstract/weierstrass.js").CurveFn;
  7. CURVE: ReturnType<(curve: import("./abstract/weierstrass.js").CurveType) => Readonly<{
  8. readonly nBitLength: number;
  9. readonly nByteLength: number;
  10. readonly Fp: import("./abstract/modular.js").IField<bigint>;
  11. readonly n: bigint;
  12. readonly h: bigint;
  13. readonly hEff?: bigint;
  14. readonly Gx: bigint;
  15. readonly Gy: bigint;
  16. readonly allowInfinityPoint?: boolean;
  17. readonly a: bigint;
  18. readonly b: bigint;
  19. readonly allowedPrivateKeyLengths?: readonly number[];
  20. readonly wrapPrivateKey?: boolean;
  21. readonly endo?: {
  22. beta: bigint;
  23. splitScalar: (k: bigint) => {
  24. k1neg: boolean;
  25. k1: bigint;
  26. k2neg: boolean;
  27. k2: bigint;
  28. };
  29. };
  30. readonly isTorsionFree?: ((c: import("./abstract/weierstrass.js").ProjConstructor<bigint>, point: PointType<bigint>) => boolean) | undefined;
  31. readonly clearCofactor?: ((c: import("./abstract/weierstrass.js").ProjConstructor<bigint>, point: PointType<bigint>) => PointType<bigint>) | undefined;
  32. readonly hash: import("./abstract/utils.js").CHash;
  33. readonly hmac: (key: Uint8Array, ...messages: Uint8Array[]) => Uint8Array;
  34. readonly randomBytes: (bytesLength?: number) => Uint8Array;
  35. lowS: boolean;
  36. readonly bits2int?: (bytes: Uint8Array) => bigint;
  37. readonly bits2int_modN?: (bytes: Uint8Array) => bigint;
  38. readonly p: bigint;
  39. }>>;
  40. getPublicKey: (privateKey: PrivKey, isCompressed?: boolean) => Uint8Array;
  41. getSharedSecret: (privateA: PrivKey, publicB: Hex, isCompressed?: boolean) => Uint8Array;
  42. sign: (msgHash: Hex, privKey: PrivKey, opts?: import("./abstract/weierstrass.js").SignOpts) => import("./abstract/weierstrass.js").RecoveredSignatureType;
  43. verify: (signature: Hex | {
  44. r: bigint;
  45. s: bigint;
  46. }, msgHash: Hex, publicKey: Hex, opts?: import("./abstract/weierstrass.js").VerOpts) => boolean;
  47. ProjectivePoint: import("./abstract/weierstrass.js").ProjConstructor<bigint>;
  48. Signature: import("./abstract/weierstrass.js").SignatureConstructor;
  49. utils: {
  50. normPrivateKeyToScalar: (key: PrivKey) => bigint;
  51. isValidPrivateKey(privateKey: PrivKey): boolean;
  52. randomPrivateKey: () => Uint8Array;
  53. precompute: (windowSize?: number, point?: PointType<bigint>) => PointType<bigint>;
  54. };
  55. }>;
  56. declare function taggedHash(tag: string, ...messages: Uint8Array[]): Uint8Array;
  57. /**
  58. * lift_x from BIP340. Convert 32-byte x coordinate to elliptic curve point.
  59. * @returns valid point checked for being on-curve
  60. */
  61. declare function lift_x(x: bigint): PointType<bigint>;
  62. /**
  63. * Schnorr public key is just `x` coordinate of Point as per BIP340.
  64. */
  65. declare function schnorrGetPublicKey(privateKey: Hex): Uint8Array;
  66. /**
  67. * Creates Schnorr signature as per BIP340. Verifies itself before returning anything.
  68. * auxRand is optional and is not the sole source of k generation: bad CSPRNG won't be dangerous.
  69. */
  70. declare function schnorrSign(message: Hex, privateKey: PrivKey, auxRand?: Hex): Uint8Array;
  71. /**
  72. * Verifies Schnorr signature.
  73. * Will swallow errors & return false except for initial type validation of arguments.
  74. */
  75. declare function schnorrVerify(signature: Hex, message: Hex, publicKey: Hex): boolean;
  76. export declare const schnorr: {
  77. getPublicKey: typeof schnorrGetPublicKey;
  78. sign: typeof schnorrSign;
  79. verify: typeof schnorrVerify;
  80. utils: {
  81. randomPrivateKey: () => Uint8Array;
  82. lift_x: typeof lift_x;
  83. pointToBytes: (point: PointType<bigint>) => Uint8Array;
  84. numberToBytesBE: typeof numberToBytesBE;
  85. bytesToNumberBE: typeof bytesToNumberBE;
  86. taggedHash: typeof taggedHash;
  87. mod: typeof mod;
  88. };
  89. };
  90. export declare const hashToCurve: (msg: Uint8Array, options?: import("./abstract/hash-to-curve.js").htfBasicOpts) => import("./abstract/hash-to-curve.js").H2CPoint<bigint>;
  91. export declare const encodeToCurve: (msg: Uint8Array, options?: import("./abstract/hash-to-curve.js").htfBasicOpts) => import("./abstract/hash-to-curve.js").H2CPoint<bigint>;
  92. export {};
  93. //# sourceMappingURL=secp256k1.d.ts.map