-
-
Notifications
You must be signed in to change notification settings - Fork 115
/
index.d.ts
97 lines (97 loc) · 3.2 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
declare const CURVE: {
p: bigint;
n: bigint;
a: bigint;
b: bigint;
Gx: bigint;
Gy: bigint;
};
type Bytes = Uint8Array;
type Hex = Bytes | string;
type PrivKey = Hex | bigint;
interface AffinePoint {
x: bigint;
y: bigint;
}
declare class Point {
readonly px: bigint;
readonly py: bigint;
readonly pz: bigint;
constructor(px: bigint, py: bigint, pz: bigint);
static readonly BASE: Point;
static readonly ZERO: Point;
static fromAffine(p: AffinePoint): Point;
static fromHex(hex: Hex): Point;
static fromPrivateKey(k: PrivKey): Point;
get x(): bigint;
get y(): bigint;
equals(other: Point): boolean;
negate(): Point;
double(): Point;
add(other: Point): Point;
mul(n: bigint, safe?: boolean): Point;
mulAddQUns(R: Point, u1: bigint, u2: bigint): Point;
toAffine(): AffinePoint;
assertValidity(): Point;
multiply(n: bigint): Point;
aff(): AffinePoint;
ok(): Point;
toHex(isCompressed?: boolean): string;
toRawBytes(isCompressed?: boolean): Uint8Array;
}
declare const getPublicKey: (privKey: PrivKey, isCompressed?: boolean) => Uint8Array;
type SignatureWithRecovery = Signature & {
recovery: number;
};
declare class Signature {
readonly r: bigint;
readonly s: bigint;
readonly recovery?: number | undefined;
constructor(r: bigint, s: bigint, recovery?: number | undefined);
static fromCompact(hex: Hex): Signature;
assertValidity(): this;
addRecoveryBit(rec: number): SignatureWithRecovery;
hasHighS(): boolean;
normalizeS(): Signature;
recoverPublicKey(msgh: Hex): Point;
toCompactRawBytes(): Uint8Array;
toCompactHex(): string;
}
type HmacFnSync = undefined | ((key: Bytes, ...msgs: Bytes[]) => Bytes);
declare const signAsync: (msgh: Hex, priv: PrivKey, opts?: {
lowS?: boolean | undefined;
extraEntropy?: boolean | Hex | undefined;
}) => Promise<SignatureWithRecovery>;
declare const sign: (msgh: Hex, priv: PrivKey, opts?: {
lowS?: boolean | undefined;
extraEntropy?: boolean | Hex | undefined;
}) => SignatureWithRecovery;
type SigLike = {
r: bigint;
s: bigint;
};
declare const verify: (sig: Hex | SigLike, msgh: Hex, pub: Hex, opts?: {
lowS?: boolean | undefined;
}) => boolean;
declare const getSharedSecret: (privA: Hex, pubB: Hex, isCompressed?: boolean) => Bytes;
declare const etc: {
hexToBytes: (hex: string) => Uint8Array;
bytesToHex: (b: Bytes) => string;
concatBytes: (...arrs: Bytes[]) => Uint8Array;
bytesToNumberBE: (b: Bytes) => bigint;
numberToBytesBE: (num: bigint) => Bytes;
mod: (a: bigint, b?: bigint) => bigint;
invert: (num: bigint, md?: bigint) => bigint;
hmacSha256Async: (key: Bytes, ...msgs: Bytes[]) => Promise<Bytes>;
hmacSha256Sync: HmacFnSync;
hashToPrivateKey: (hash: Hex) => Bytes;
randomBytes: (len?: number) => Bytes;
};
declare const utils: {
normPrivateKeyToScalar: (p: PrivKey) => bigint;
isValidPrivateKey: (key: Hex) => boolean;
randomPrivateKey: () => Bytes;
precompute(w?: number, p?: Point): Point;
};
export { getPublicKey, sign, signAsync, verify, CURVE, // Remove the export to easily use in REPL
getSharedSecret, etc, utils, Point as ProjectivePoint, Signature };