@noble/curves 1.9.5 → 2.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/README.md +267 -421
  2. package/abstract/bls.d.ts +49 -111
  3. package/abstract/bls.d.ts.map +1 -1
  4. package/abstract/bls.js +108 -152
  5. package/abstract/bls.js.map +1 -1
  6. package/abstract/curve.d.ts +7 -48
  7. package/abstract/curve.d.ts.map +1 -1
  8. package/abstract/curve.js +22 -47
  9. package/abstract/curve.js.map +1 -1
  10. package/abstract/edwards.d.ts +17 -68
  11. package/abstract/edwards.d.ts.map +1 -1
  12. package/abstract/edwards.js +98 -175
  13. package/abstract/edwards.js.map +1 -1
  14. package/abstract/fft.js +14 -27
  15. package/abstract/fft.js.map +1 -1
  16. package/abstract/hash-to-curve.d.ts +11 -24
  17. package/abstract/hash-to-curve.d.ts.map +1 -1
  18. package/abstract/hash-to-curve.js +30 -35
  19. package/abstract/hash-to-curve.js.map +1 -1
  20. package/abstract/modular.d.ts +5 -17
  21. package/abstract/modular.d.ts.map +1 -1
  22. package/abstract/modular.js +166 -167
  23. package/abstract/modular.js.map +1 -1
  24. package/abstract/montgomery.d.ts +4 -9
  25. package/abstract/montgomery.d.ts.map +1 -1
  26. package/abstract/montgomery.js +17 -20
  27. package/abstract/montgomery.js.map +1 -1
  28. package/abstract/oprf.d.ts +282 -0
  29. package/abstract/oprf.d.ts.map +1 -0
  30. package/abstract/oprf.js +297 -0
  31. package/abstract/oprf.js.map +1 -0
  32. package/abstract/poseidon.js +20 -24
  33. package/abstract/poseidon.js.map +1 -1
  34. package/abstract/tower.d.ts +9 -7
  35. package/abstract/tower.d.ts.map +1 -1
  36. package/abstract/tower.js +600 -364
  37. package/abstract/tower.js.map +1 -1
  38. package/abstract/weierstrass.d.ts +12 -145
  39. package/abstract/weierstrass.d.ts.map +1 -1
  40. package/abstract/weierstrass.js +153 -377
  41. package/abstract/weierstrass.js.map +1 -1
  42. package/bls12-381.d.ts +2 -2
  43. package/bls12-381.d.ts.map +1 -1
  44. package/bls12-381.js +174 -216
  45. package/bls12-381.js.map +1 -1
  46. package/bn254.d.ts +58 -10
  47. package/bn254.d.ts.map +1 -1
  48. package/bn254.js +70 -130
  49. package/bn254.js.map +1 -1
  50. package/ed25519.d.ts +12 -31
  51. package/ed25519.d.ts.map +1 -1
  52. package/ed25519.js +104 -146
  53. package/ed25519.js.map +1 -1
  54. package/ed448.d.ts +14 -33
  55. package/ed448.d.ts.map +1 -1
  56. package/ed448.js +105 -132
  57. package/ed448.js.map +1 -1
  58. package/index.js +1 -1
  59. package/misc.d.ts +10 -14
  60. package/misc.d.ts.map +1 -1
  61. package/misc.js +51 -60
  62. package/misc.js.map +1 -1
  63. package/nist.d.ts +11 -14
  64. package/nist.d.ts.map +1 -1
  65. package/nist.js +46 -55
  66. package/nist.js.map +1 -1
  67. package/package.json +9 -224
  68. package/secp256k1.d.ts +7 -23
  69. package/secp256k1.d.ts.map +1 -1
  70. package/secp256k1.js +72 -83
  71. package/secp256k1.js.map +1 -1
  72. package/src/abstract/bls.ts +197 -344
  73. package/src/abstract/curve.ts +10 -83
  74. package/src/abstract/edwards.ts +96 -223
  75. package/src/abstract/hash-to-curve.ts +32 -45
  76. package/src/abstract/modular.ts +144 -130
  77. package/src/abstract/montgomery.ts +21 -22
  78. package/src/abstract/oprf.ts +600 -0
  79. package/src/abstract/tower.ts +627 -382
  80. package/src/abstract/weierstrass.ts +101 -482
  81. package/src/bls12-381.ts +148 -176
  82. package/src/bn254.ts +67 -122
  83. package/src/ed25519.ts +65 -118
  84. package/src/ed448.ts +63 -113
  85. package/src/index.ts +1 -1
  86. package/src/misc.ts +66 -49
  87. package/src/nist.ts +48 -57
  88. package/src/secp256k1.ts +56 -88
  89. package/src/utils.ts +41 -61
  90. package/src/webcrypto.ts +362 -0
  91. package/utils.d.ts +28 -19
  92. package/utils.d.ts.map +1 -1
  93. package/utils.js +45 -121
  94. package/utils.js.map +1 -1
  95. package/webcrypto.d.ts +47 -0
  96. package/webcrypto.d.ts.map +1 -0
  97. package/webcrypto.js +231 -0
  98. package/webcrypto.js.map +1 -0
  99. package/esm/_shortw_utils.d.ts +0 -19
  100. package/esm/_shortw_utils.d.ts.map +0 -1
  101. package/esm/_shortw_utils.js +0 -16
  102. package/esm/_shortw_utils.js.map +0 -1
  103. package/esm/abstract/bls.d.ts +0 -190
  104. package/esm/abstract/bls.d.ts.map +0 -1
  105. package/esm/abstract/bls.js +0 -408
  106. package/esm/abstract/bls.js.map +0 -1
  107. package/esm/abstract/curve.d.ts +0 -231
  108. package/esm/abstract/curve.d.ts.map +0 -1
  109. package/esm/abstract/curve.js +0 -465
  110. package/esm/abstract/curve.js.map +0 -1
  111. package/esm/abstract/edwards.d.ts +0 -237
  112. package/esm/abstract/edwards.d.ts.map +0 -1
  113. package/esm/abstract/edwards.js +0 -632
  114. package/esm/abstract/edwards.js.map +0 -1
  115. package/esm/abstract/fft.d.ts +0 -122
  116. package/esm/abstract/fft.d.ts.map +0 -1
  117. package/esm/abstract/fft.js +0 -425
  118. package/esm/abstract/fft.js.map +0 -1
  119. package/esm/abstract/hash-to-curve.d.ts +0 -102
  120. package/esm/abstract/hash-to-curve.d.ts.map +0 -1
  121. package/esm/abstract/hash-to-curve.js +0 -203
  122. package/esm/abstract/hash-to-curve.js.map +0 -1
  123. package/esm/abstract/modular.d.ts +0 -171
  124. package/esm/abstract/modular.d.ts.map +0 -1
  125. package/esm/abstract/modular.js +0 -530
  126. package/esm/abstract/modular.js.map +0 -1
  127. package/esm/abstract/montgomery.d.ts +0 -30
  128. package/esm/abstract/montgomery.d.ts.map +0 -1
  129. package/esm/abstract/montgomery.js +0 -157
  130. package/esm/abstract/montgomery.js.map +0 -1
  131. package/esm/abstract/poseidon.d.ts +0 -68
  132. package/esm/abstract/poseidon.d.ts.map +0 -1
  133. package/esm/abstract/poseidon.js +0 -296
  134. package/esm/abstract/poseidon.js.map +0 -1
  135. package/esm/abstract/tower.d.ts +0 -93
  136. package/esm/abstract/tower.d.ts.map +0 -1
  137. package/esm/abstract/tower.js +0 -502
  138. package/esm/abstract/tower.js.map +0 -1
  139. package/esm/abstract/utils.d.ts +0 -5
  140. package/esm/abstract/utils.d.ts.map +0 -1
  141. package/esm/abstract/utils.js +0 -7
  142. package/esm/abstract/utils.js.map +0 -1
  143. package/esm/abstract/weierstrass.d.ts +0 -412
  144. package/esm/abstract/weierstrass.d.ts.map +0 -1
  145. package/esm/abstract/weierstrass.js +0 -1428
  146. package/esm/abstract/weierstrass.js.map +0 -1
  147. package/esm/bls12-381.d.ts +0 -16
  148. package/esm/bls12-381.d.ts.map +0 -1
  149. package/esm/bls12-381.js +0 -738
  150. package/esm/bls12-381.js.map +0 -1
  151. package/esm/bn254.d.ts +0 -18
  152. package/esm/bn254.d.ts.map +0 -1
  153. package/esm/bn254.js +0 -246
  154. package/esm/bn254.js.map +0 -1
  155. package/esm/ed25519.d.ts +0 -106
  156. package/esm/ed25519.d.ts.map +0 -1
  157. package/esm/ed25519.js +0 -467
  158. package/esm/ed25519.js.map +0 -1
  159. package/esm/ed448.d.ts +0 -101
  160. package/esm/ed448.d.ts.map +0 -1
  161. package/esm/ed448.js +0 -448
  162. package/esm/ed448.js.map +0 -1
  163. package/esm/index.d.ts +0 -2
  164. package/esm/index.d.ts.map +0 -1
  165. package/esm/index.js +0 -17
  166. package/esm/index.js.map +0 -1
  167. package/esm/jubjub.d.ts +0 -12
  168. package/esm/jubjub.d.ts.map +0 -1
  169. package/esm/jubjub.js +0 -12
  170. package/esm/jubjub.js.map +0 -1
  171. package/esm/misc.d.ts +0 -19
  172. package/esm/misc.d.ts.map +0 -1
  173. package/esm/misc.js +0 -109
  174. package/esm/misc.js.map +0 -1
  175. package/esm/nist.d.ts +0 -21
  176. package/esm/nist.d.ts.map +0 -1
  177. package/esm/nist.js +0 -132
  178. package/esm/nist.js.map +0 -1
  179. package/esm/p256.d.ts +0 -16
  180. package/esm/p256.d.ts.map +0 -1
  181. package/esm/p256.js +0 -16
  182. package/esm/p256.js.map +0 -1
  183. package/esm/p384.d.ts +0 -16
  184. package/esm/p384.d.ts.map +0 -1
  185. package/esm/p384.js +0 -16
  186. package/esm/p384.js.map +0 -1
  187. package/esm/p521.d.ts +0 -16
  188. package/esm/p521.d.ts.map +0 -1
  189. package/esm/p521.js +0 -16
  190. package/esm/p521.js.map +0 -1
  191. package/esm/package.json +0 -4
  192. package/esm/pasta.d.ts +0 -10
  193. package/esm/pasta.d.ts.map +0 -1
  194. package/esm/pasta.js +0 -10
  195. package/esm/pasta.js.map +0 -1
  196. package/esm/secp256k1.d.ts +0 -89
  197. package/esm/secp256k1.d.ts.map +0 -1
  198. package/esm/secp256k1.js +0 -292
  199. package/esm/secp256k1.js.map +0 -1
  200. package/esm/utils.d.ts +0 -110
  201. package/esm/utils.d.ts.map +0 -1
  202. package/esm/utils.js +0 -322
  203. package/esm/utils.js.map +0 -1
  204. package/src/_shortw_utils.ts +0 -21
  205. package/src/abstract/utils.ts +0 -7
  206. package/src/jubjub.ts +0 -12
  207. package/src/p256.ts +0 -15
  208. package/src/p384.ts +0 -15
  209. package/src/p521.ts +0 -15
  210. package/src/package.json +0 -3
  211. package/src/pasta.ts +0 -9
package/package.json CHANGED
@@ -1,27 +1,24 @@
1
1
  {
2
2
  "name": "@noble/curves",
3
- "version": "1.9.5",
3
+ "version": "2.0.0-beta.1",
4
4
  "description": "Audited & minimal JS implementation of elliptic curve cryptography",
5
5
  "files": [
6
6
  "*.js",
7
7
  "*.js.map",
8
8
  "*.d.ts",
9
9
  "*.d.ts.map",
10
- "esm",
11
- "src",
12
10
  "abstract",
13
- "!oprf.*",
14
- "!webcrypto.*"
11
+ "src"
15
12
  ],
16
13
  "scripts": {
17
14
  "bench": "npm run bench:install; cd test/benchmark; node secp256k1.js; node curves.js; node utils.js; node bls.js",
18
15
  "bench:install": "cd test/benchmark; npm install; npm install ../.. --install-links",
19
- "build": "tsc && tsc -p tsconfig.cjs.json",
20
- "build:release": "npx jsbt esbuild test/build",
16
+ "build": "tsc",
17
+ "build:release": "npx --no @paulmillr/jsbt esbuild test/build",
21
18
  "build:clean": "rm {.,esm,abstract,esm/abstract}/*.{js,d.ts,d.ts.map,js.map} 2> /dev/null",
22
19
  "lint": "prettier --check 'src/**/*.{js,ts}' 'test/*.js'",
23
20
  "format": "prettier --write 'src/**/*.{js,ts}' 'test/*.js'",
24
- "test": "node test/index.js",
21
+ "test": "node --disable-warning=ExperimentalWarning test/index.js",
25
22
  "test:bun": "bun test/index.js",
26
23
  "test:deno": "deno --allow-env --allow-read test/index.js",
27
24
  "test:coverage": "npm install --no-save c8@10.1.2 && npx c8 npm test"
@@ -34,7 +31,7 @@
34
31
  },
35
32
  "license": "MIT",
36
33
  "dependencies": {
37
- "@noble/hashes": "1.8.0"
34
+ "@noble/hashes": "2.0.0-beta.3"
38
35
  },
39
36
  "devDependencies": {
40
37
  "@paulmillr/jsbt": "0.4.0",
@@ -46,223 +43,11 @@
46
43
  "typescript": "5.8.3"
47
44
  },
48
45
  "sideEffects": false,
46
+ "type": "module",
49
47
  "main": "index.js",
50
- "exports": {
51
- ".": {
52
- "import": "./esm/index.js",
53
- "require": "./index.js"
54
- },
55
- "./abstract/bls": {
56
- "import": "./esm/abstract/bls.js",
57
- "require": "./abstract/bls.js"
58
- },
59
- "./abstract/curve": {
60
- "import": "./esm/abstract/curve.js",
61
- "require": "./abstract/curve.js"
62
- },
63
- "./abstract/edwards": {
64
- "import": "./esm/abstract/edwards.js",
65
- "require": "./abstract/edwards.js"
66
- },
67
- "./abstract/hash-to-curve": {
68
- "import": "./esm/abstract/hash-to-curve.js",
69
- "require": "./abstract/hash-to-curve.js"
70
- },
71
- "./abstract/modular": {
72
- "import": "./esm/abstract/modular.js",
73
- "require": "./abstract/modular.js"
74
- },
75
- "./abstract/montgomery": {
76
- "import": "./esm/abstract/montgomery.js",
77
- "require": "./abstract/montgomery.js"
78
- },
79
- "./abstract/poseidon": {
80
- "import": "./esm/abstract/poseidon.js",
81
- "require": "./abstract/poseidon.js"
82
- },
83
- "./abstract/tower": {
84
- "import": "./esm/abstract/tower.js",
85
- "require": "./abstract/tower.js"
86
- },
87
- "./abstract/utils": {
88
- "import": "./esm/abstract/utils.js",
89
- "require": "./abstract/utils.js"
90
- },
91
- "./abstract/weierstrass": {
92
- "import": "./esm/abstract/weierstrass.js",
93
- "require": "./abstract/weierstrass.js"
94
- },
95
- "./abstract/fft": {
96
- "import": "./esm/abstract/fft.js",
97
- "require": "./abstract/fft.js"
98
- },
99
- "./_shortw_utils": {
100
- "import": "./esm/_shortw_utils.js",
101
- "require": "./_shortw_utils.js"
102
- },
103
- "./bls12-381": {
104
- "import": "./esm/bls12-381.js",
105
- "require": "./bls12-381.js"
106
- },
107
- "./bn254": {
108
- "import": "./esm/bn254.js",
109
- "require": "./bn254.js"
110
- },
111
- "./ed448": {
112
- "import": "./esm/ed448.js",
113
- "require": "./ed448.js"
114
- },
115
- "./ed25519": {
116
- "import": "./esm/ed25519.js",
117
- "require": "./ed25519.js"
118
- },
119
- "./index": {
120
- "import": "./esm/index.js",
121
- "require": "./index.js"
122
- },
123
- "./jubjub": {
124
- "import": "./esm/jubjub.js",
125
- "require": "./jubjub.js"
126
- },
127
- "./misc": {
128
- "import": "./esm/misc.js",
129
- "require": "./misc.js"
130
- },
131
- "./nist": {
132
- "import": "./esm/nist.js",
133
- "require": "./nist.js"
134
- },
135
- "./p256": {
136
- "import": "./esm/p256.js",
137
- "require": "./p256.js"
138
- },
139
- "./p384": {
140
- "import": "./esm/p384.js",
141
- "require": "./p384.js"
142
- },
143
- "./p521": {
144
- "import": "./esm/p521.js",
145
- "require": "./p521.js"
146
- },
147
- "./pasta": {
148
- "import": "./esm/pasta.js",
149
- "require": "./pasta.js"
150
- },
151
- "./secp256k1": {
152
- "import": "./esm/secp256k1.js",
153
- "require": "./secp256k1.js"
154
- },
155
- "./utils": {
156
- "import": "./esm/utils.js",
157
- "require": "./utils.js"
158
- },
159
- "./abstract/bls.js": {
160
- "import": "./esm/abstract/bls.js",
161
- "require": "./abstract/bls.js"
162
- },
163
- "./abstract/curve.js": {
164
- "import": "./esm/abstract/curve.js",
165
- "require": "./abstract/curve.js"
166
- },
167
- "./abstract/edwards.js": {
168
- "import": "./esm/abstract/edwards.js",
169
- "require": "./abstract/edwards.js"
170
- },
171
- "./abstract/hash-to-curve.js": {
172
- "import": "./esm/abstract/hash-to-curve.js",
173
- "require": "./abstract/hash-to-curve.js"
174
- },
175
- "./abstract/modular.js": {
176
- "import": "./esm/abstract/modular.js",
177
- "require": "./abstract/modular.js"
178
- },
179
- "./abstract/montgomery.js": {
180
- "import": "./esm/abstract/montgomery.js",
181
- "require": "./abstract/montgomery.js"
182
- },
183
- "./abstract/poseidon.js": {
184
- "import": "./esm/abstract/poseidon.js",
185
- "require": "./abstract/poseidon.js"
186
- },
187
- "./abstract/tower.js": {
188
- "import": "./esm/abstract/tower.js",
189
- "require": "./abstract/tower.js"
190
- },
191
- "./abstract/utils.js": {
192
- "import": "./esm/abstract/utils.js",
193
- "require": "./abstract/utils.js"
194
- },
195
- "./abstract/weierstrass.js": {
196
- "import": "./esm/abstract/weierstrass.js",
197
- "require": "./abstract/weierstrass.js"
198
- },
199
- "./abstract/fft.js": {
200
- "import": "./esm/abstract/fft.js",
201
- "require": "./abstract/fft.js"
202
- },
203
- "./_shortw_utils.js": {
204
- "import": "./esm/_shortw_utils.js",
205
- "require": "./_shortw_utils.js"
206
- },
207
- "./bls12-381.js": {
208
- "import": "./esm/bls12-381.js",
209
- "require": "./bls12-381.js"
210
- },
211
- "./bn254.js": {
212
- "import": "./esm/bn254.js",
213
- "require": "./bn254.js"
214
- },
215
- "./utils.js": {
216
- "import": "./esm/utils.js",
217
- "require": "./utils.js"
218
- },
219
- "./ed448.js": {
220
- "import": "./esm/ed448.js",
221
- "require": "./ed448.js"
222
- },
223
- "./ed25519.js": {
224
- "import": "./esm/ed25519.js",
225
- "require": "./ed25519.js"
226
- },
227
- "./index.js": {
228
- "import": "./esm/index.js",
229
- "require": "./index.js"
230
- },
231
- "./jubjub.js": {
232
- "import": "./esm/jubjub.js",
233
- "require": "./jubjub.js"
234
- },
235
- "./misc.js": {
236
- "import": "./esm/misc.js",
237
- "require": "./misc.js"
238
- },
239
- "./nist.js": {
240
- "import": "./esm/nist.js",
241
- "require": "./nist.js"
242
- },
243
- "./p256.js": {
244
- "import": "./esm/p256.js",
245
- "require": "./p256.js"
246
- },
247
- "./p384.js": {
248
- "import": "./esm/p384.js",
249
- "require": "./p384.js"
250
- },
251
- "./p521.js": {
252
- "import": "./esm/p521.js",
253
- "require": "./p521.js"
254
- },
255
- "./pasta.js": {
256
- "import": "./esm/pasta.js",
257
- "require": "./pasta.js"
258
- },
259
- "./secp256k1.js": {
260
- "import": "./esm/secp256k1.js",
261
- "require": "./secp256k1.js"
262
- }
263
- },
48
+ "module": "index.js",
264
49
  "engines": {
265
- "node": "^14.21.3 || >=16"
50
+ "node": ">= 20.19.0"
266
51
  },
267
52
  "keywords": [
268
53
  "elliptic",
package/secp256k1.d.ts CHANGED
@@ -1,10 +1,6 @@
1
- import { type CurveFnWithCreate } from './_shortw_utils.ts';
2
1
  import type { CurveLengths } from './abstract/curve.ts';
3
- import { type H2CHasher, type H2CMethod } from './abstract/hash-to-curve.ts';
4
- import { mod } from './abstract/modular.ts';
5
- import { type WeierstrassPoint as PointType, type WeierstrassPointCons } from './abstract/weierstrass.ts';
6
- import type { Hex, PrivKey } from './utils.ts';
7
- import { bytesToNumberBE, numberToBytesBE } from './utils.ts';
2
+ import { type H2CHasher } from './abstract/hash-to-curve.ts';
3
+ import { type ECDSA, type WeierstrassPoint as PointType, type WeierstrassPointCons } from './abstract/weierstrass.ts';
8
4
  /**
9
5
  * secp256k1 curve, ECDSA and ECDH methods.
10
6
  *
@@ -19,7 +15,7 @@ import { bytesToNumberBE, numberToBytesBE } from './utils.ts';
19
15
  * const isValid = secp256k1.verify(sig, msg, publicKey) === true;
20
16
  * ```
21
17
  */
22
- export declare const secp256k1: CurveFnWithCreate;
18
+ export declare const secp256k1: ECDSA;
23
19
  declare function taggedHash(tag: string, ...messages: Uint8Array[]): Uint8Array;
24
20
  /**
25
21
  * lift_x from BIP340. Convert 32-byte x coordinate to elliptic curve point.
@@ -29,17 +25,17 @@ declare function lift_x(x: bigint): PointType<bigint>;
29
25
  /**
30
26
  * Schnorr public key is just `x` coordinate of Point as per BIP340.
31
27
  */
32
- declare function schnorrGetPublicKey(secretKey: Hex): Uint8Array;
28
+ declare function schnorrGetPublicKey(secretKey: Uint8Array): Uint8Array;
33
29
  /**
34
30
  * Creates Schnorr signature as per BIP340. Verifies itself before returning anything.
35
31
  * auxRand is optional and is not the sole source of k generation: bad CSPRNG won't be dangerous.
36
32
  */
37
- declare function schnorrSign(message: Hex, secretKey: PrivKey, auxRand?: Hex): Uint8Array;
33
+ declare function schnorrSign(message: Uint8Array, secretKey: Uint8Array, auxRand?: Uint8Array): Uint8Array;
38
34
  /**
39
35
  * Verifies Schnorr signature.
40
36
  * Will swallow errors & return false except for initial type validation of arguments.
41
37
  */
42
- declare function schnorrVerify(signature: Hex, message: Hex, publicKey: Hex): boolean;
38
+ declare function schnorrVerify(signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array): boolean;
43
39
  export type SecpSchnorr = {
44
40
  keygen: (seed?: Uint8Array) => {
45
41
  secretKey: Uint8Array;
@@ -54,14 +50,6 @@ export type SecpSchnorr = {
54
50
  pointToBytes: (point: PointType<bigint>) => Uint8Array;
55
51
  lift_x: typeof lift_x;
56
52
  taggedHash: typeof taggedHash;
57
- /** @deprecated use `randomSecretKey` */
58
- randomPrivateKey: (seed?: Uint8Array) => Uint8Array;
59
- /** @deprecated use `utils` */
60
- numberToBytesBE: typeof numberToBytesBE;
61
- /** @deprecated use `utils` */
62
- bytesToNumberBE: typeof bytesToNumberBE;
63
- /** @deprecated use `modular` */
64
- mod: typeof mod;
65
53
  };
66
54
  lengths: CurveLengths;
67
55
  };
@@ -80,10 +68,6 @@ export type SecpSchnorr = {
80
68
  */
81
69
  export declare const schnorr: SecpSchnorr;
82
70
  /** Hashing / encoding to secp256k1 points / field. RFC 9380 methods. */
83
- export declare const secp256k1_hasher: H2CHasher<bigint>;
84
- /** @deprecated use `import { secp256k1_hasher } from '@noble/curves/secp256k1.js';` */
85
- export declare const hashToCurve: H2CMethod<bigint>;
86
- /** @deprecated use `import { secp256k1_hasher } from '@noble/curves/secp256k1.js';` */
87
- export declare const encodeToCurve: H2CMethod<bigint>;
71
+ export declare const secp256k1_hasher: H2CHasher<WeierstrassPointCons<bigint>>;
88
72
  export {};
89
73
  //# sourceMappingURL=secp256k1.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"secp256k1.d.ts","sourceRoot":"","sources":["src/secp256k1.ts"],"names":[],"mappings":"AAUA,OAAO,EAAe,KAAK,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,SAAS,EAEf,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAyB,GAAG,EAAQ,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAIL,KAAK,gBAAgB,IAAI,SAAS,EAElC,KAAK,oBAAoB,EAC1B,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAEL,eAAe,EAIf,eAAe,EAEhB,MAAM,YAAY,CAAC;AAyDpB;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,SAAS,EAAE,iBAGvB,CAAC;AAMF,iBAAS,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,UAAU,EAAE,GAAG,UAAU,CAQtE;AAkBD;;;GAGG;AACH,iBAAS,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAS5C;AASD;;GAEG;AACH,iBAAS,mBAAmB,CAAC,SAAS,EAAE,GAAG,GAAG,UAAU,CAEvD;AAED;;;GAGG;AACH,iBAAS,WAAW,CAAC,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,GAAE,GAAqB,GAAG,UAAU,CAgBjG;AAED;;;GAGG;AACH,iBAAS,aAAa,CAAC,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,GAAG,OAAO,CAoB5E;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,UAAU,KAAK;QAAE,SAAS,EAAE,UAAU,CAAC;QAAC,SAAS,EAAE,UAAU,CAAA;KAAE,CAAC;IAChF,YAAY,EAAE,OAAO,mBAAmB,CAAC;IACzC,IAAI,EAAE,OAAO,WAAW,CAAC;IACzB,MAAM,EAAE,OAAO,aAAa,CAAC;IAC7B,KAAK,EAAE,oBAAoB,CAAC,MAAM,CAAC,CAAC;IACpC,KAAK,EAAE;QACL,eAAe,EAAE,CAAC,IAAI,CAAC,EAAE,UAAU,KAAK,UAAU,CAAC;QACnD,YAAY,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,UAAU,CAAC;QACvD,MAAM,EAAE,OAAO,MAAM,CAAC;QACtB,UAAU,EAAE,OAAO,UAAU,CAAC;QAE9B,wCAAwC;QACxC,gBAAgB,EAAE,CAAC,IAAI,CAAC,EAAE,UAAU,KAAK,UAAU,CAAC;QACpD,8BAA8B;QAC9B,eAAe,EAAE,OAAO,eAAe,CAAC;QACxC,8BAA8B;QAC9B,eAAe,EAAE,OAAO,eAAe,CAAC;QACxC,gCAAgC;QAChC,GAAG,EAAE,OAAO,GAAG,CAAC;KACjB,CAAC;IACF,OAAO,EAAE,YAAY,CAAC;CACvB,CAAC;AACF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,OAAO,EAAE,WAsClB,CAAC;AA0CL,wEAAwE;AACxE,eAAO,MAAM,gBAAgB,EAAE,SAAS,CAAC,MAAM,CAgBzC,CAAC;AAEP,uFAAuF;AACvF,eAAO,MAAM,WAAW,EAAE,SAAS,CAAC,MAAM,CACT,CAAC;AAElC,uFAAuF;AACvF,eAAO,MAAM,aAAa,EAAE,SAAS,CAAC,MAAM,CACT,CAAC"}
1
+ {"version":3,"file":"secp256k1.d.ts","sourceRoot":"","sources":["src/secp256k1.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAgB,KAAK,SAAS,EAAc,MAAM,6BAA6B,CAAC;AAEvF,OAAO,EACL,KAAK,KAAK,EAIV,KAAK,gBAAgB,IAAI,SAAS,EAGlC,KAAK,oBAAoB,EAC1B,MAAM,2BAA2B,CAAC;AA8DnC;;;;;;;;;;;;;GAaG;AAEH,eAAO,MAAM,SAAS,EAAE,KAA8C,CAAC;AAMvE,iBAAS,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,UAAU,EAAE,GAAG,UAAU,CAQtE;AAcD;;;GAGG;AACH,iBAAS,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAY5C;AASD;;GAEG;AACH,iBAAS,mBAAmB,CAAC,SAAS,EAAE,UAAU,GAAG,UAAU,CAE9D;AAED;;;GAGG;AACH,iBAAS,WAAW,CAClB,OAAO,EAAE,UAAU,EACnB,SAAS,EAAE,UAAU,EACrB,OAAO,GAAE,UAA4B,GACpC,UAAU,CAgBZ;AAED;;;GAGG;AACH,iBAAS,aAAa,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,GAAG,OAAO,CAqBjG;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,UAAU,KAAK;QAAE,SAAS,EAAE,UAAU,CAAC;QAAC,SAAS,EAAE,UAAU,CAAA;KAAE,CAAC;IAChF,YAAY,EAAE,OAAO,mBAAmB,CAAC;IACzC,IAAI,EAAE,OAAO,WAAW,CAAC;IACzB,MAAM,EAAE,OAAO,aAAa,CAAC;IAC7B,KAAK,EAAE,oBAAoB,CAAC,MAAM,CAAC,CAAC;IACpC,KAAK,EAAE;QACL,eAAe,EAAE,CAAC,IAAI,CAAC,EAAE,UAAU,KAAK,UAAU,CAAC;QACnD,YAAY,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,UAAU,CAAC;QACvD,MAAM,EAAE,OAAO,MAAM,CAAC;QACtB,UAAU,EAAE,OAAO,UAAU,CAAC;KAC/B,CAAC;IACF,OAAO,EAAE,YAAY,CAAC;CACvB,CAAC;AACF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,OAAO,EAAE,WA8BlB,CAAC;AA0CL,wEAAwE;AACxE,eAAO,MAAM,gBAAgB,EAAE,SAAS,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAgB/D,CAAC"}
package/secp256k1.js CHANGED
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.encodeToCurve = exports.hashToCurve = exports.secp256k1_hasher = exports.schnorr = exports.secp256k1 = void 0;
4
1
  /**
5
2
  * SECG secp256k1. See [pdf](https://www.secg.org/sec2-v2.pdf).
6
3
  *
@@ -9,15 +6,14 @@ exports.encodeToCurve = exports.hashToCurve = exports.secp256k1_hasher = exports
9
6
  * @module
10
7
  */
11
8
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
12
- const sha2_js_1 = require("@noble/hashes/sha2.js");
13
- const utils_js_1 = require("@noble/hashes/utils.js");
14
- const _shortw_utils_ts_1 = require("./_shortw_utils.js");
15
- const hash_to_curve_ts_1 = require("./abstract/hash-to-curve.js");
16
- const modular_ts_1 = require("./abstract/modular.js");
17
- const weierstrass_ts_1 = require("./abstract/weierstrass.js");
18
- const utils_ts_1 = require("./utils.js");
9
+ import { sha256 } from '@noble/hashes/sha2.js';
10
+ import { randomBytes } from '@noble/hashes/utils.js';
11
+ import { createHasher, isogenyMap } from "./abstract/hash-to-curve.js";
12
+ import { Field, mapHashToField, pow2 } from "./abstract/modular.js";
13
+ import { ecdsa, mapToCurveSimpleSWU, weierstrass, } from "./abstract/weierstrass.js";
14
+ import { abytes, asciiToBytes, bytesToNumberBE, concatBytes, inRange } from "./utils.js";
19
15
  // Seems like generator was produced from some seed:
20
- // `Point.BASE.multiply(Point.Fn.inv(2n, N)).toAffine().x`
16
+ // `Pointk1.BASE.multiply(Pointk1.Fn.inv(2n, N)).toAffine().x`
21
17
  // // gives short x 0x3b78ce563f89a0ed9414f5aa28ad0d96d6795f9c63n
22
18
  const secp256k1_CURVE = {
23
19
  p: BigInt('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f'),
@@ -50,23 +46,27 @@ function sqrtMod(y) {
50
46
  const _23n = BigInt(23), _44n = BigInt(44), _88n = BigInt(88);
51
47
  const b2 = (y * y * y) % P; // x^3, 11
52
48
  const b3 = (b2 * b2 * y) % P; // x^7
53
- const b6 = ((0, modular_ts_1.pow2)(b3, _3n, P) * b3) % P;
54
- const b9 = ((0, modular_ts_1.pow2)(b6, _3n, P) * b3) % P;
55
- const b11 = ((0, modular_ts_1.pow2)(b9, _2n, P) * b2) % P;
56
- const b22 = ((0, modular_ts_1.pow2)(b11, _11n, P) * b11) % P;
57
- const b44 = ((0, modular_ts_1.pow2)(b22, _22n, P) * b22) % P;
58
- const b88 = ((0, modular_ts_1.pow2)(b44, _44n, P) * b44) % P;
59
- const b176 = ((0, modular_ts_1.pow2)(b88, _88n, P) * b88) % P;
60
- const b220 = ((0, modular_ts_1.pow2)(b176, _44n, P) * b44) % P;
61
- const b223 = ((0, modular_ts_1.pow2)(b220, _3n, P) * b3) % P;
62
- const t1 = ((0, modular_ts_1.pow2)(b223, _23n, P) * b22) % P;
63
- const t2 = ((0, modular_ts_1.pow2)(t1, _6n, P) * b2) % P;
64
- const root = (0, modular_ts_1.pow2)(t2, _2n, P);
49
+ const b6 = (pow2(b3, _3n, P) * b3) % P;
50
+ const b9 = (pow2(b6, _3n, P) * b3) % P;
51
+ const b11 = (pow2(b9, _2n, P) * b2) % P;
52
+ const b22 = (pow2(b11, _11n, P) * b11) % P;
53
+ const b44 = (pow2(b22, _22n, P) * b22) % P;
54
+ const b88 = (pow2(b44, _44n, P) * b44) % P;
55
+ const b176 = (pow2(b88, _88n, P) * b88) % P;
56
+ const b220 = (pow2(b176, _44n, P) * b44) % P;
57
+ const b223 = (pow2(b220, _3n, P) * b3) % P;
58
+ const t1 = (pow2(b223, _23n, P) * b22) % P;
59
+ const t2 = (pow2(t1, _6n, P) * b2) % P;
60
+ const root = pow2(t2, _2n, P);
65
61
  if (!Fpk1.eql(Fpk1.sqr(root), y))
66
62
  throw new Error('Cannot find square root');
67
63
  return root;
68
64
  }
69
- const Fpk1 = (0, modular_ts_1.Field)(secp256k1_CURVE.p, { sqrt: sqrtMod });
65
+ const Fpk1 = Field(secp256k1_CURVE.p, { sqrt: sqrtMod });
66
+ const Pointk1 = /* @__PURE__ */ weierstrass(secp256k1_CURVE, {
67
+ Fp: Fpk1,
68
+ endo: secp256k1_ENDO,
69
+ });
70
70
  /**
71
71
  * secp256k1 curve, ECDSA and ECDH methods.
72
72
  *
@@ -81,7 +81,7 @@ const Fpk1 = (0, modular_ts_1.Field)(secp256k1_CURVE.p, { sqrt: sqrtMod });
81
81
  * const isValid = secp256k1.verify(sig, msg, publicKey) === true;
82
82
  * ```
83
83
  */
84
- exports.secp256k1 = (0, _shortw_utils_ts_1.createCurve)({ ...secp256k1_CURVE, Fp: Fpk1, lowS: true, endo: secp256k1_ENDO }, sha2_js_1.sha256);
84
+ export const secp256k1 = /* @__PURE__ */ ecdsa(Pointk1, sha256);
85
85
  // Schnorr signatures are superior to ECDSA from above. Below is Schnorr-specific BIP0340 code.
86
86
  // https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki
87
87
  /** An object mapping tags to their tagged hash prefix of [SHA256(tag) | SHA256(tag)] */
@@ -89,25 +89,21 @@ const TAGGED_HASH_PREFIXES = {};
89
89
  function taggedHash(tag, ...messages) {
90
90
  let tagP = TAGGED_HASH_PREFIXES[tag];
91
91
  if (tagP === undefined) {
92
- const tagH = (0, sha2_js_1.sha256)((0, utils_ts_1.utf8ToBytes)(tag));
93
- tagP = (0, utils_ts_1.concatBytes)(tagH, tagH);
92
+ const tagH = sha256(asciiToBytes(tag));
93
+ tagP = concatBytes(tagH, tagH);
94
94
  TAGGED_HASH_PREFIXES[tag] = tagP;
95
95
  }
96
- return (0, sha2_js_1.sha256)((0, utils_ts_1.concatBytes)(tagP, ...messages));
96
+ return sha256(concatBytes(tagP, ...messages));
97
97
  }
98
98
  // ECDSA compact points are 33-byte. Schnorr is 32: we strip first byte 0x02 or 0x03
99
99
  const pointToBytes = (point) => point.toBytes(true).slice(1);
100
- const numTo32b = (n) => (0, utils_ts_1.numberToBytesBE)(n, 32);
101
- const modP = (x) => (0, modular_ts_1.mod)(x, secp256k1_CURVE.p);
102
- const modN = (x) => (0, modular_ts_1.mod)(x, secp256k1_CURVE.n);
103
- const Point = /* @__PURE__ */ (() => exports.secp256k1.Point)();
104
100
  const hasEven = (y) => y % _2n === _0n;
105
101
  // Calculate point, scalar and bytes
106
102
  function schnorrGetExtPubKey(priv) {
107
- // TODO: replace with Point.Fn.fromBytes(priv)
108
- let d_ = (0, weierstrass_ts_1._normFnElement)(Point.Fn, priv);
109
- let p = Point.BASE.multiply(d_); // P = d'⋅G; 0 < d' < n check is done inside
110
- const scalar = hasEven(p.y) ? d_ : modN(-d_);
103
+ const { Fn, BASE } = Pointk1;
104
+ const d_ = Fn.fromBytes(priv);
105
+ const p = BASE.multiply(d_); // P = d'⋅G; 0 < d' < n check is done inside
106
+ const scalar = hasEven(p.y) ? d_ : Fn.neg(d_);
111
107
  return { scalar, bytes: pointToBytes(p) };
112
108
  }
113
109
  /**
@@ -115,22 +111,26 @@ function schnorrGetExtPubKey(priv) {
115
111
  * @returns valid point checked for being on-curve
116
112
  */
117
113
  function lift_x(x) {
118
- (0, utils_ts_1.aInRange)('x', x, _1n, secp256k1_CURVE.p); // Fail if x ≥ p.
119
- const xx = modP(x * x);
120
- const c = modP(xx * x + BigInt(7)); // Let c = x³ + 7 mod p.
121
- let y = sqrtMod(c); // Let y = c^(p+1)/4 mod p.
114
+ const Fp = Fpk1;
115
+ if (!Fp.isValidNot0(x))
116
+ throw new Error('invalid x: Fail if x p');
117
+ const xx = Fp.create(x * x);
118
+ const c = Fp.create(xx * x + BigInt(7)); // Let c = x³ + 7 mod p.
119
+ let y = Fp.sqrt(c); // Let y = c^(p+1)/4 mod p. Same as sqrt().
120
+ // Return the unique point P such that x(P) = x and
121
+ // y(P) = y if y mod 2 = 0 or y(P) = p-y otherwise.
122
122
  if (!hasEven(y))
123
- y = modP(-y); // Return the unique point P such that x(P) = x and
124
- const p = Point.fromAffine({ x, y }); // y(P) = y if y mod 2 = 0 or y(P) = p-y otherwise.
123
+ y = Fp.neg(y);
124
+ const p = Pointk1.fromAffine({ x, y });
125
125
  p.assertValidity();
126
126
  return p;
127
127
  }
128
- const num = utils_ts_1.bytesToNumberBE;
128
+ const num = bytesToNumberBE;
129
129
  /**
130
130
  * Create tagged hash, convert it to bigint, reduce modulo-n.
131
131
  */
132
132
  function challenge(...args) {
133
- return modN(num(taggedHash('BIP0340/challenge', ...args)));
133
+ return Pointk1.Fn.create(num(taggedHash('BIP0340/challenge', ...args)));
134
134
  }
135
135
  /**
136
136
  * Schnorr public key is just `x` coordinate of Point as per BIP340.
@@ -142,20 +142,19 @@ function schnorrGetPublicKey(secretKey) {
142
142
  * Creates Schnorr signature as per BIP340. Verifies itself before returning anything.
143
143
  * auxRand is optional and is not the sole source of k generation: bad CSPRNG won't be dangerous.
144
144
  */
145
- function schnorrSign(message, secretKey, auxRand = (0, utils_js_1.randomBytes)(32)) {
146
- const m = (0, utils_ts_1.ensureBytes)('message', message);
145
+ function schnorrSign(message, secretKey, auxRand = randomBytes(32)) {
146
+ const { Fn } = Pointk1;
147
+ const m = abytes(message, undefined, 'message');
147
148
  const { bytes: px, scalar: d } = schnorrGetExtPubKey(secretKey); // checks for isWithinCurveOrder
148
- const a = (0, utils_ts_1.ensureBytes)('auxRand', auxRand, 32); // Auxiliary random data a: a 32-byte array
149
- const t = numTo32b(d ^ num(taggedHash('BIP0340/aux', a))); // Let t be the byte-wise xor of bytes(d) and hash/aux(a)
149
+ const a = abytes(auxRand, 32, 'auxRand'); // Auxiliary random data a: a 32-byte array
150
+ const t = Fn.toBytes(d ^ num(taggedHash('BIP0340/aux', a))); // Let t be the byte-wise xor of bytes(d) and hash/aux(a)
150
151
  const rand = taggedHash('BIP0340/nonce', t, px, m); // Let rand = hash/nonce(t || bytes(P) || m)
151
- const k_ = modN(num(rand)); // Let k' = int(rand) mod n
152
- if (k_ === _0n)
153
- throw new Error('sign failed: k is zero'); // Fail if k' = 0.
154
- const { bytes: rx, scalar: k } = schnorrGetExtPubKey(k_); // Let R = k'⋅G.
152
+ // Let k' = int(rand) mod n. Fail if k' = 0. Let R = k'⋅G
153
+ const { bytes: rx, scalar: k } = schnorrGetExtPubKey(rand);
155
154
  const e = challenge(rx, px, m); // Let e = int(hash/challenge(bytes(R) || bytes(P) || m)) mod n.
156
155
  const sig = new Uint8Array(64); // Let sig = bytes(R) || bytes((k + ed) mod n).
157
156
  sig.set(rx, 0);
158
- sig.set(numTo32b(modN(k + e * d)), 32);
157
+ sig.set(Fn.toBytes(Fn.create(k + e * d)), 32);
159
158
  // If Verify(bytes(P), m, sig) (see below) returns failure, abort
160
159
  if (!schnorrVerify(sig, m, px))
161
160
  throw new Error('sign: Invalid signature produced');
@@ -166,20 +165,21 @@ function schnorrSign(message, secretKey, auxRand = (0, utils_js_1.randomBytes)(3
166
165
  * Will swallow errors & return false except for initial type validation of arguments.
167
166
  */
168
167
  function schnorrVerify(signature, message, publicKey) {
169
- const sig = (0, utils_ts_1.ensureBytes)('signature', signature, 64);
170
- const m = (0, utils_ts_1.ensureBytes)('message', message);
171
- const pub = (0, utils_ts_1.ensureBytes)('publicKey', publicKey, 32);
168
+ const { Fn, BASE } = Pointk1;
169
+ const sig = abytes(signature, 64, 'signature');
170
+ const m = abytes(message, undefined, 'message');
171
+ const pub = abytes(publicKey, 32, 'publicKey');
172
172
  try {
173
173
  const P = lift_x(num(pub)); // P = lift_x(int(pk)); fail if that fails
174
174
  const r = num(sig.subarray(0, 32)); // Let r = int(sig[0:32]); fail if r ≥ p.
175
- if (!(0, utils_ts_1.inRange)(r, _1n, secp256k1_CURVE.p))
175
+ if (!inRange(r, _1n, secp256k1_CURVE.p))
176
176
  return false;
177
177
  const s = num(sig.subarray(32, 64)); // Let s = int(sig[32:64]); fail if s ≥ n.
178
- if (!(0, utils_ts_1.inRange)(s, _1n, secp256k1_CURVE.n))
178
+ if (!inRange(s, _1n, secp256k1_CURVE.n))
179
179
  return false;
180
- const e = challenge(numTo32b(r), pointToBytes(P), m); // int(challenge(bytes(r)||bytes(P)||m))%n
180
+ const e = challenge(Fn.toBytes(r), pointToBytes(P), m); // int(challenge(bytes(r)||bytes(P)||m))%n
181
181
  // R = s⋅G - e⋅P, where -eP == (n-e)P
182
- const R = Point.BASE.multiplyUnsafe(s).add(P.multiplyUnsafe(modN(-e)));
182
+ const R = BASE.multiplyUnsafe(s).add(P.multiplyUnsafe(Fn.neg(e)));
183
183
  const { x, y } = R.toAffine();
184
184
  // Fail if is_infinite(R) / not has_even_y(R) / x(R) ≠ r.
185
185
  if (R.is0() || !hasEven(y) || x !== r)
@@ -203,14 +203,12 @@ function schnorrVerify(signature, message, publicKey) {
203
203
  * const isValid = schnorr.verify(sig, msg, publicKey);
204
204
  * ```
205
205
  */
206
- exports.schnorr = (() => {
206
+ export const schnorr = /* @__PURE__ */ (() => {
207
207
  const size = 32;
208
208
  const seedLength = 48;
209
- const randomSecretKey = (seed = (0, utils_js_1.randomBytes)(seedLength)) => {
210
- return (0, modular_ts_1.mapHashToField)(seed, secp256k1_CURVE.n);
209
+ const randomSecretKey = (seed = randomBytes(seedLength)) => {
210
+ return mapHashToField(seed, secp256k1_CURVE.n);
211
211
  };
212
- // TODO: remove
213
- exports.secp256k1.utils.randomSecretKey;
214
212
  function keygen(seed) {
215
213
  const secretKey = randomSecretKey(seed);
216
214
  return { secretKey, publicKey: schnorrGetPublicKey(secretKey) };
@@ -220,28 +218,23 @@ exports.schnorr = (() => {
220
218
  getPublicKey: schnorrGetPublicKey,
221
219
  sign: schnorrSign,
222
220
  verify: schnorrVerify,
223
- Point,
221
+ Point: Pointk1,
224
222
  utils: {
225
- randomSecretKey: randomSecretKey,
226
- randomPrivateKey: randomSecretKey,
223
+ randomSecretKey,
227
224
  taggedHash,
228
- // TODO: remove
229
225
  lift_x,
230
226
  pointToBytes,
231
- numberToBytesBE: utils_ts_1.numberToBytesBE,
232
- bytesToNumberBE: utils_ts_1.bytesToNumberBE,
233
- mod: modular_ts_1.mod,
234
227
  },
235
228
  lengths: {
236
- secret: size,
237
- public: size,
229
+ secretKey: size,
230
+ publicKey: size,
231
+ publicKeyHasPrefix: false,
238
232
  signature: size * 2,
239
233
  seed: seedLength,
240
- publicKeyHasPrefix: false,
241
234
  },
242
235
  };
243
236
  })();
244
- const isoMap = /* @__PURE__ */ (() => (0, hash_to_curve_ts_1.isogenyMap)(Fpk1, [
237
+ const isoMap = /* @__PURE__ */ (() => isogenyMap(Fpk1, [
245
238
  // xNum
246
239
  [
247
240
  '0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7',
@@ -270,13 +263,13 @@ const isoMap = /* @__PURE__ */ (() => (0, hash_to_curve_ts_1.isogenyMap)(Fpk1, [
270
263
  '0x0000000000000000000000000000000000000000000000000000000000000001', // LAST 1
271
264
  ],
272
265
  ].map((i) => i.map((j) => BigInt(j)))))();
273
- const mapSWU = /* @__PURE__ */ (() => (0, weierstrass_ts_1.mapToCurveSimpleSWU)(Fpk1, {
266
+ const mapSWU = /* @__PURE__ */ (() => mapToCurveSimpleSWU(Fpk1, {
274
267
  A: BigInt('0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533'),
275
268
  B: BigInt('1771'),
276
269
  Z: Fpk1.create(BigInt('-11')),
277
270
  }))();
278
271
  /** Hashing / encoding to secp256k1 points / field. RFC 9380 methods. */
279
- exports.secp256k1_hasher = (() => (0, hash_to_curve_ts_1.createHasher)(exports.secp256k1.Point, (scalars) => {
272
+ export const secp256k1_hasher = /* @__PURE__ */ (() => createHasher(Pointk1, (scalars) => {
280
273
  const { x, y } = mapSWU(Fpk1.create(scalars[0]));
281
274
  return isoMap(x, y);
282
275
  }, {
@@ -286,10 +279,6 @@ exports.secp256k1_hasher = (() => (0, hash_to_curve_ts_1.createHasher)(exports.s
286
279
  m: 1,
287
280
  k: 128,
288
281
  expand: 'xmd',
289
- hash: sha2_js_1.sha256,
282
+ hash: sha256,
290
283
  }))();
291
- /** @deprecated use `import { secp256k1_hasher } from '@noble/curves/secp256k1.js';` */
292
- exports.hashToCurve = (() => exports.secp256k1_hasher.hashToCurve)();
293
- /** @deprecated use `import { secp256k1_hasher } from '@noble/curves/secp256k1.js';` */
294
- exports.encodeToCurve = (() => exports.secp256k1_hasher.encodeToCurve)();
295
284
  //# sourceMappingURL=secp256k1.js.map