-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathindex.d.ts
100 lines (100 loc) · 3.69 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* ed25519 curve parameters. Equation is −x² + y² = -a + dx²y².
* Gx and Gy are generator coordinates. p is field order, n is group order.
* h is cofactor.
*/
declare const CURVE: {
a: bigint;
d: bigint;
p: bigint;
n: bigint;
h: number;
Gx: bigint;
Gy: bigint;
};
/** Alias to Uint8Array. */
export type Bytes = Uint8Array;
/** Hex-encoded string or Uint8Array. */
export type Hex = Bytes | string;
/** Point in 2d xy affine coordinates. */
export interface AffinePoint {
x: bigint;
y: bigint;
}
/** Point in xyzt extended coordinates. */
declare class Point {
readonly ex: bigint;
readonly ey: bigint;
readonly ez: bigint;
readonly et: bigint;
constructor(ex: bigint, ey: bigint, ez: bigint, et: bigint);
/** Generator / Base point */
static readonly BASE: Point;
/** Identity / Zero point */
static readonly ZERO: Point;
static fromAffine(p: AffinePoint): Point;
/** RFC8032 5.1.3: hex / Uint8Array to Point. */
static fromHex(hex: Hex, zip215?: boolean): Point;
get x(): bigint;
get y(): bigint;
equals(other: Point): boolean;
is0(): boolean;
negate(): Point;
/** Point doubling. Complete formula. */
double(): Point;
/** Point addition. Complete formula. */
add(other: Point): Point;
mul(n: bigint, safe?: boolean): Point;
multiply(scalar: bigint): Point;
clearCofactor(): Point;
isSmallOrder(): boolean;
isTorsionFree(): boolean;
/** converts point to 2d xy affine point. (x, y, z, t) ∋ (x=x/z, y=y/z, t=xy). */
toAffine(): AffinePoint;
toRawBytes(): Bytes;
toHex(): string;
}
export type Sha512FnSync = undefined | ((...messages: Bytes[]) => Bytes);
type ExtK = {
head: Bytes;
prefix: Bytes;
scalar: bigint;
point: Point;
pointBytes: Bytes;
};
/** Creates 32-byte ed25519 public key from 32-byte private key. Async. */
declare const getPublicKeyAsync: (priv: Hex) => Promise<Bytes>;
/** Creates 32-byte ed25519 public key from 32-byte private key. To use, set `etc.sha512Sync` first. */
declare const getPublicKey: (priv: Hex) => Bytes;
/** Signs message (NOT message hash) using private key. Async. */
declare const signAsync: (msg: Hex, privKey: Hex) => Promise<Bytes>;
/** Signs message (NOT message hash) using private key. To use, set `etc.sha512Sync` first. */
declare const sign: (msg: Hex, privKey: Hex) => Bytes;
/** Verification options. zip215: true (default) follows ZIP215 spec. false would follow RFC8032. */
export type VerifOpts = {
zip215?: boolean;
};
/** Verifies signature on message and public key. Async. */
declare const verifyAsync: (s: Hex, m: Hex, p: Hex, opts?: VerifOpts) => Promise<boolean>;
/** Verifies signature on message and public key. To use, set `etc.sha512Sync` first. */
declare const verify: (s: Hex, m: Hex, p: Hex, opts?: VerifOpts) => boolean;
/** Math, hex, byte helpers. Not in `utils` because utils share API with noble-curves. */
declare const etc: {
bytesToHex: (b: Bytes) => string;
hexToBytes: (hex: string) => Bytes;
concatBytes: (...arrs: Bytes[]) => Uint8Array;
mod: (a: bigint, b?: bigint) => bigint;
invert: (num: bigint, md: bigint) => bigint;
randomBytes: (len?: number) => Bytes;
sha512Async: (...messages: Bytes[]) => Promise<Bytes>;
sha512Sync: Sha512FnSync;
};
/** ed25519-specific key utilities. */
declare const utils: {
getExtendedPublicKeyAsync: (priv: Hex) => Promise<ExtK>;
getExtendedPublicKey: (priv: Hex) => ExtK;
randomPrivateKey: () => Bytes;
precompute: (w?: number, p?: Point) => Point;
};
export { getPublicKey, getPublicKeyAsync, sign, verify, // Remove the export to easily use in REPL
signAsync, verifyAsync, CURVE, etc, utils, Point as ExtendedPoint };