1 |
|
2 |
|
3 |
|
4 | export interface SignOptions {
|
5 |
|
6 | noncefn?:
|
7 | | ((
|
8 | message: Uint8Array,
|
9 | privateKey: Uint8Array,
|
10 | algo: Uint8Array | null,
|
11 | data: Uint8Array | null,
|
12 | attempt: number,
|
13 | ) => Uint8Array)
|
14 | | undefined;
|
15 |
|
16 | |
17 |
|
18 |
|
19 |
|
20 |
|
21 | data?: Uint8Array | undefined;
|
22 | }
|
23 |
|
24 | export interface ecdhOptions {
|
25 | data?: Uint8Array | undefined;
|
26 | xbuf?: Uint8Array | undefined;
|
27 | ybuf?: Uint8Array | undefined;
|
28 | hashfn?: ((x: Uint8Array, y: Uint8Array, data: Uint8Array) => Uint8Array) | undefined;
|
29 | }
|
30 |
|
31 | /**
|
32 | * Updates the context randomization to protect against side-channel leakage, `seed` should be Uint8Array with length 32.
|
33 | */
|
34 | export function contextRandomize(seed: Uint8Array): void;
|
35 |
|
36 | /**
|
37 | * Verify an ECDSA privateKey.
|
38 | */
|
39 | export function privateKeyVerify(privateKey: Uint8Array): boolean;
|
40 |
|
41 | /**
|
42 | * Export a privateKey in DER format.
|
43 | */
|
44 | export function privateKeyExport(privateKey: Uint8Array, compressed?: boolean): Uint8Array;
|
45 |
|
46 | /**
|
47 | * Import a privateKey in DER format.
|
48 | */
|
49 | export function privateKeyImport(privateKey: Uint8Array): Uint8Array;
|
50 |
|
51 | /**
|
52 | * Negate a privateKey by subtracting it from the order of the curve's base point.
|
53 | */
|
54 | export function privateKeyNegate(privateKey: Uint8Array): Uint8Array;
|
55 |
|
56 | /**
|
57 | * Compute the inverse of a privateKey (modulo the order of the curve's base point).
|
58 | */
|
59 | export function privateKeyModInverse(privateKey: Uint8Array): Uint8Array;
|
60 |
|
61 | /**
|
62 | * Tweak a privateKey by adding tweak to it.
|
63 | */
|
64 | export function privateKeyTweakAdd(privateKey: Uint8Array, tweak: Uint8Array): Uint8Array;
|
65 |
|
66 | /**
|
67 | * Tweak a privateKey by multiplying it by a tweak.
|
68 | */
|
69 | export function privateKeyTweakMul(privateKey: Uint8Array, tweak: Uint8Array): Uint8Array;
|
70 |
|
71 | /**
|
72 | * Compute the public key for a privateKey.
|
73 | */
|
74 | export function publicKeyCreate(
|
75 | privateKey: Uint8Array,
|
76 | compressed?: boolean,
|
77 | output?: Uint8Array | ((len: number) => Uint8Array),
|
78 | ): Uint8Array;
|
79 |
|
80 | /**
|
81 | * Convert a publicKey to compressed or uncompressed form.
|
82 | */
|
83 | export function publicKeyConvert(
|
84 | publicKey: Uint8Array,
|
85 | compressed?: boolean,
|
86 | output?: Uint8Array | ((len: number) => Uint8Array),
|
87 | ): Uint8Array;
|
88 |
|
89 | /**
|
90 | * Negates a public key in place.
|
91 | */
|
92 | export function publicKeyNegate(
|
93 | publicKey: Uint8Array,
|
94 | compressed?: boolean,
|
95 | output?: Uint8Array | ((len: number) => Uint8Array),
|
96 | ): Uint8Array;
|
97 |
|
98 | /**
|
99 | * Verify an ECDSA publicKey.
|
100 | */
|
101 | export function publicKeyVerify(publicKey: Uint8Array): boolean;
|
102 |
|
103 | /**
|
104 | * Tweak a publicKey by adding tweak times the generator to it.
|
105 | */
|
106 | export function publicKeyTweakAdd(
|
107 | publicKey: Uint8Array,
|
108 | tweak: Uint8Array,
|
109 | compressed?: boolean,
|
110 | output?: Uint8Array | ((len: number) => Uint8Array),
|
111 | ): Uint8Array;
|
112 |
|
113 | /**
|
114 | * Tweak a publicKey by multiplying it by a tweak value.
|
115 | */
|
116 | export function publicKeyTweakMul(
|
117 | publicKey: Uint8Array,
|
118 | tweak: Uint8Array,
|
119 | compressed?: boolean,
|
120 | output?: Uint8Array | ((len: number) => Uint8Array),
|
121 | ): Uint8Array;
|
122 |
|
123 | /**
|
124 | * Add a given publicKeys together.
|
125 | */
|
126 | export function publicKeyCombine(
|
127 | publicKeys: Uint8Array[],
|
128 | compressed?: boolean,
|
129 | output?: Uint8Array | ((len: number) => Uint8Array),
|
130 | ): Uint8Array;
|
131 |
|
132 | /**
|
133 | * Convert a signature to a normalized lower-S form.
|
134 | */
|
135 | export function signatureNormalize(signature: Uint8Array): Uint8Array;
|
136 |
|
137 | /**
|
138 | * Serialize an ECDSA signature in DER format.
|
139 | */
|
140 | export function signatureExport(signature: Uint8Array, output?: Uint8Array | ((len: number) => Uint8Array)): Uint8Array;
|
141 |
|
142 | /**
|
143 | * Parse a DER ECDSA signature (follow by BIP66).
|
144 | */
|
145 | export function signatureImport(signature: Uint8Array, output?: Uint8Array | ((len: number) => Uint8Array)): Uint8Array;
|
146 |
|
147 | /**
|
148 | * Create an ECDSA signature. Always return low-S signature.
|
149 | *
|
150 | * Inputs: 32-byte message `m`, 32-byte scalar key `d`, 32-byte scalar nonce `k`.
|
151 | * - Compute point `R = k * G`. Reject nonce if R's `x` coordinate is zero.
|
152 | * - Compute 32-byte scalar `r`, the serialization of R's `x` coordinate.
|
153 | * - Compose 32-byte scalar `s = k^-1 * (r * d + m)`. Reject nonce if `s` is zero.
|
154 | * - The signature is `(r, s)`.
|
155 | */
|
156 | export function ecdsaSign(
|
157 | message: Uint8Array,
|
158 | privateKey: Uint8Array,
|
159 | options?: SignOptions,
|
160 | output?: Uint8Array | ((len: number) => Uint8Array),
|
161 | ): { signature: Uint8Array; recid: number };
|
162 |
|
163 | /**
|
164 | * Verify an ECDSA signature.
|
165 | *
|
166 | * Note: return false for high signatures!
|
167 | *
|
168 | * Inputs: 32-byte message `m`, public key point `Q`, signature: (32-byte `r`, scalar `s`).
|
169 | * - Signature is invalid if `r` is zero.
|
170 | * - Signature is invalid if `s` is zero.
|
171 | * - Compute point `R = (s^-1 * m * G + s^-1 * r * Q)`. Reject if `R` is infinity.
|
172 | * - Signature is valid if R's `x` coordinate equals to `r`.
|
173 | */
|
174 | export function ecdsaVerify(signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array): boolean;
|
175 |
|
176 | /**
|
177 | * Recover an ECDSA public key from a signature.
|
178 | */
|
179 | export function ecdsaRecover(
|
180 | signature: Uint8Array,
|
181 | recid: number,
|
182 | message: Uint8Array,
|
183 | compressed?: boolean,
|
184 | output?: Uint8Array | ((len: number) => Uint8Array),
|
185 | ): Uint8Array;
|
186 |
|
187 | /**
|
188 | * Compute an EC Diffie-Hellman secret and applied sha256 to compressed public key.
|
189 | */
|
190 | export function ecdh(
|
191 | publicKey: Uint8Array,
|
192 | privateKey: Uint8Array,
|
193 | opt?: ecdhOptions,
|
194 | output?: Uint8Array | ((len: number) => Uint8Array),
|
195 | ): Uint8Array;
|
196 |
|
\ | No newline at end of file |