1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | import BN = require("bn.js");
|
8 |
|
9 |
|
10 | export const utils: any;
|
11 | export const rand: any;
|
12 |
|
13 | export type BNInput = string | BN | number | Buffer | Uint8Array | ReadonlyArray<number>;
|
14 | export type SignatureInput = ec.Signature | ec.SignatureOptions | Uint8Array | ReadonlyArray<number> | string;
|
15 |
|
16 | export const version: number;
|
17 |
|
18 | export namespace curve {
|
19 | |
20 |
|
21 |
|
22 | class base {
|
23 | p: BN;
|
24 | type: string;
|
25 | red: any;
|
26 | zero: BN;
|
27 | one: BN;
|
28 | two: BN;
|
29 | n: BN;
|
30 | g: base.BasePoint;
|
31 | redN: BN;
|
32 |
|
33 | constructor(type: string, conf: base.BaseCurveOptions);
|
34 |
|
35 | validate(point: base.BasePoint): boolean;
|
36 | decodePoint(bytes: Buffer | string, enc?: "hex"): base.BasePoint;
|
37 | }
|
38 |
|
39 | namespace base {
|
40 | class BasePoint {
|
41 | curve: base;
|
42 | type: string;
|
43 | precomputed: PrecomputedValues | null;
|
44 |
|
45 | constructor(curve: base, type: string);
|
46 |
|
47 | encode(enc: "hex", compact: boolean): string;
|
48 | encode(enc: "array" | undefined, compact: boolean): number[];
|
49 | encodeCompressed(enc: "hex"): string;
|
50 | encodeCompressed(enc?: "array"): number[];
|
51 | validate(): boolean;
|
52 | precompute(power: number): BasePoint;
|
53 | dblp(k: number): BasePoint;
|
54 | inspect(): string;
|
55 | isInfinity(): boolean;
|
56 | add(p: BasePoint): BasePoint;
|
57 | mul(k: BN): BasePoint;
|
58 | dbl(): BasePoint;
|
59 | getX(): BN;
|
60 | getY(): BN;
|
61 | eq(p: BasePoint): boolean;
|
62 | neg(): BasePoint;
|
63 | }
|
64 |
|
65 | interface BaseCurveOptions {
|
66 | p: number | string | number[] | Buffer | BN;
|
67 | prime?: BN | string | undefined;
|
68 | n?: number | BN | Buffer | undefined;
|
69 | g?: BasePoint | undefined;
|
70 | gRed?: any;
|
71 | }
|
72 |
|
73 | interface PrecomputedValues {
|
74 | doubles: any;
|
75 | naf: any;
|
76 | beta: any;
|
77 | }
|
78 | }
|
79 |
|
80 | class edwards extends base {
|
81 | a: BN;
|
82 | c: BN;
|
83 | c2: BN;
|
84 | d: BN;
|
85 | dd: BN;
|
86 |
|
87 | constructor(conf: edwards.EdwardsConf);
|
88 |
|
89 | point(
|
90 | x: BNInput,
|
91 | y: BNInput,
|
92 | z?: BNInput,
|
93 | t?: BNInput
|
94 | ): edwards.EdwardsPoint;
|
95 | pointFromX(x: BNInput, odd?: boolean): edwards.EdwardsPoint;
|
96 | pointFromY(y: BNInput, odd?: boolean): edwards.EdwardsPoint;
|
97 | pointFromJSON(obj: BNInput[]): edwards.EdwardsPoint;
|
98 | }
|
99 |
|
100 | namespace edwards {
|
101 | interface EdwardsConf extends base.BaseCurveOptions {
|
102 | a: BNInput;
|
103 | c: BNInput;
|
104 | d: BNInput;
|
105 | }
|
106 |
|
107 | class EdwardsPoint extends base.BasePoint {
|
108 | x: BN;
|
109 | y: BN;
|
110 | z: BN;
|
111 | t: BN;
|
112 |
|
113 | normalize(): EdwardsPoint;
|
114 | eqXToP(x: BN): boolean;
|
115 | }
|
116 | }
|
117 |
|
118 | class short extends base {
|
119 | a: BNInput;
|
120 | b: BNInput;
|
121 | g: short.ShortPoint;
|
122 |
|
123 | constructor(conf: short.ShortConf);
|
124 |
|
125 | point(x: BNInput, y: BNInput, isRed?: boolean): short.ShortPoint;
|
126 | pointFromX(x: BNInput, odd?: boolean): short.ShortPoint;
|
127 | pointFromJSON(obj: BNInput[], red: boolean): short.ShortPoint;
|
128 | }
|
129 |
|
130 | namespace short {
|
131 | interface ShortConf extends base.BaseCurveOptions {
|
132 | a: BNInput;
|
133 | b: BNInput;
|
134 | beta?: BNInput | undefined;
|
135 | lambda?: BNInput | undefined;
|
136 | }
|
137 |
|
138 | class ShortPoint extends base.BasePoint {
|
139 | x: BN | null;
|
140 | y: BN | null;
|
141 | inf: boolean;
|
142 |
|
143 | toJSON(): BNInput[];
|
144 | }
|
145 | }
|
146 | }
|
147 |
|
148 | export namespace curves {
|
149 | class PresetCurve {
|
150 | type: string;
|
151 | g: any;
|
152 | n: BN | undefined | null;
|
153 | hash: any;
|
154 |
|
155 | constructor(options: PresetCurve.Options);
|
156 | }
|
157 |
|
158 | namespace PresetCurve {
|
159 | interface Options {
|
160 | type: string;
|
161 | prime: string | null;
|
162 | p: string;
|
163 | a: string;
|
164 | b: string;
|
165 | n: string;
|
166 | hash: any;
|
167 | gRed: boolean;
|
168 | g: any;
|
169 | beta?: string | undefined;
|
170 | lambda?: string | undefined;
|
171 | basis?: any;
|
172 | }
|
173 | }
|
174 | }
|
175 |
|
176 | export class ec {
|
177 | curve: any;
|
178 | n: BN | undefined | null;
|
179 | nh: any;
|
180 | g: any;
|
181 | hash: any;
|
182 |
|
183 | constructor(options: string | curves.PresetCurve);
|
184 |
|
185 | keyPair(options: ec.KeyPairOptions): ec.KeyPair;
|
186 | keyFromPrivate(
|
187 | priv: Uint8Array | Buffer | string | number[] | ec.KeyPair,
|
188 | enc?: string
|
189 | ): ec.KeyPair;
|
190 | keyFromPublic(
|
191 | pub: Uint8Array | Buffer | string | number[] | { x: string; y: string } | ec.KeyPair,
|
192 | enc?: string
|
193 | ): ec.KeyPair;
|
194 | genKeyPair(options?: ec.GenKeyPairOptions): ec.KeyPair;
|
195 | sign(
|
196 | msg: BNInput,
|
197 | key: Buffer | ec.KeyPair,
|
198 | enc: string,
|
199 | options?: ec.SignOptions
|
200 | ): ec.Signature;
|
201 | sign(
|
202 | msg: BNInput,
|
203 | key: Buffer | ec.KeyPair,
|
204 | options?: ec.SignOptions
|
205 | ): ec.Signature;
|
206 | verify(
|
207 | msg: BNInput,
|
208 | signature: SignatureInput,
|
209 | key: Buffer | ec.KeyPair,
|
210 | enc?: string
|
211 | ): boolean;
|
212 | recoverPubKey(
|
213 | msg: BNInput,
|
214 | signature: SignatureInput,
|
215 | j: number,
|
216 | enc?: string
|
217 | ): any;
|
218 | getKeyRecoveryParam(
|
219 | e: Error | undefined,
|
220 | signature: SignatureInput,
|
221 | Q: BN,
|
222 | enc?: string
|
223 | ): number;
|
224 | }
|
225 |
|
226 | export namespace ec {
|
227 | interface GenKeyPairOptions {
|
228 | pers?: any;
|
229 | entropy: any;
|
230 | persEnc?: string | undefined;
|
231 | entropyEnc?: string | undefined;
|
232 | }
|
233 |
|
234 | interface SignOptions {
|
235 | pers?: any;
|
236 | persEnc?: string | undefined;
|
237 | canonical?: boolean | undefined;
|
238 | k?: BN | undefined;
|
239 | }
|
240 |
|
241 | class KeyPair {
|
242 | static fromPublic(
|
243 | ec: ec,
|
244 | pub: Buffer | string | { x: string; y: string } | KeyPair,
|
245 | enc?: string
|
246 | ): KeyPair;
|
247 | static fromPrivate(
|
248 | ec: ec,
|
249 | priv: Buffer | string | KeyPair,
|
250 | enc?: string
|
251 | ): KeyPair;
|
252 |
|
253 | ec: ec;
|
254 |
|
255 | constructor(ec: ec, options: KeyPairOptions);
|
256 |
|
257 | validate(): { readonly result: boolean; readonly reason: string };
|
258 | getPublic(compact: boolean, enc: "hex"): string;
|
259 | getPublic(compact: boolean, enc: "array"): number[];
|
260 | getPublic(enc: "hex"): string;
|
261 | getPublic(enc: "array"): number[];
|
262 | getPublic(): curve.base.BasePoint;
|
263 | getPrivate(enc: "hex"): string;
|
264 | getPrivate(): BN;
|
265 | derive(pub: curve.base.BasePoint): BN;
|
266 | sign(msg: BNInput, enc: string, options?: SignOptions): Signature;
|
267 | sign(msg: BNInput, options?: SignOptions): Signature;
|
268 | verify(
|
269 | msg: BNInput,
|
270 | signature: SignatureInput
|
271 | ): boolean;
|
272 | inspect(): string;
|
273 | }
|
274 |
|
275 | class Signature {
|
276 | r: BN;
|
277 | s: BN;
|
278 | recoveryParam: number | null;
|
279 |
|
280 | constructor(options: SignatureInput, enc?: string);
|
281 |
|
282 | toDER(enc?: string | null): any; // ?
|
283 | }
|
284 |
|
285 | interface SignatureOptions {
|
286 | r: BNInput;
|
287 | s: BNInput;
|
288 | recoveryParam?: number | undefined;
|
289 | }
|
290 |
|
291 | interface KeyPairOptions {
|
292 | priv?: Buffer | undefined;
|
293 | privEnc?: string | undefined;
|
294 | pub?: Buffer | undefined;
|
295 | pubEnc?: string | undefined;
|
296 | }
|
297 | }
|
298 |
|
299 | export class eddsa {
|
300 | curve: curve.edwards;
|
301 |
|
302 | constructor(name: "ed25519");
|
303 |
|
304 | sign(message: eddsa.Bytes, secret: eddsa.Bytes): eddsa.Signature;
|
305 | verify(
|
306 | message: eddsa.Bytes,
|
307 | sig: eddsa.Bytes | eddsa.Signature,
|
308 | pub: eddsa.Bytes | eddsa.Point | eddsa.KeyPair
|
309 | ): boolean;
|
310 | hashInt(): BN;
|
311 | keyFromPublic(pub: eddsa.Bytes | eddsa.KeyPair | eddsa.Point): eddsa.KeyPair;
|
312 | keyFromSecret(secret: eddsa.Bytes): eddsa.KeyPair;
|
313 | makeSignature(sig: eddsa.Signature | Buffer | string): eddsa.Signature;
|
314 | encodePoint(point: eddsa.Point): Buffer;
|
315 | decodePoint(bytes: eddsa.Bytes): eddsa.Point;
|
316 | encodeInt(num: BN): Buffer;
|
317 | decodeInt(bytes: BNInput): BN;
|
318 | isPoint(val: any): boolean;
|
319 | }
|
320 |
|
321 | export namespace eddsa {
|
322 | type Point = curve.base.BasePoint;
|
323 | type Bytes = string | Buffer;
|
324 |
|
325 | class Signature {
|
326 | constructor(eddsa: eddsa, sig: Signature | Bytes);
|
327 |
|
328 | toBytes(): Buffer;
|
329 | toHex(): string;
|
330 | }
|
331 |
|
332 | class KeyPair {
|
333 | constructor(eddsa: eddsa, params: KeyPairOptions);
|
334 |
|
335 | static fromPublic(eddsa: eddsa, pub: Bytes): KeyPair;
|
336 | static fromSecret(eddsa: eddsa, secret: Bytes): KeyPair;
|
337 |
|
338 | secret(): Buffer;
|
339 | sign(message: Bytes): Signature;
|
340 | verify(message: Bytes, sig: Signature | Bytes): boolean;
|
341 | getSecret(enc: "hex"): string;
|
342 | getSecret(): Buffer;
|
343 | getPublic(enc: "hex"): string;
|
344 | getPublic(): Buffer;
|
345 | }
|
346 |
|
347 | interface KeyPairOptions {
|
348 | secret: Buffer;
|
349 | pub: Buffer | Point;
|
350 | }
|
351 | }
|