@ohos-ports/crypto 0.0.0-stage → 0.3.1-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 (121) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +60 -2
  3. package/dist/bech32.d.ts +53 -0
  4. package/dist/bech32.js +187 -0
  5. package/dist/blake2b.d.ts +7 -0
  6. package/dist/blake2b.js +213 -0
  7. package/dist/bls12_318.d.ts +48 -0
  8. package/dist/bls12_318.js +268 -0
  9. package/dist/ed25519.d.ts +55 -0
  10. package/dist/ed25519.js +721 -0
  11. package/dist/hasGlobalWebCrypto.d.ts +1 -0
  12. package/dist/hasGlobalWebCrypto.js +21 -0
  13. package/dist/hmacSHA512.d.ts +6 -0
  14. package/dist/hmacSHA512.js +14 -0
  15. package/dist/index.d.ts +14 -0
  16. package/dist/index.js +30 -0
  17. package/dist/keccak.d.ts +4 -0
  18. package/dist/keccak.js +43 -0
  19. package/dist/kes/constants.d.ts +2 -0
  20. package/dist/kes/constants.js +5 -0
  21. package/dist/kes/index.d.ts +0 -0
  22. package/dist/kes/index.js +0 -0
  23. package/dist/kes/macro/sum_kes.d.ts +15 -0
  24. package/dist/kes/macro/sum_kes.js +9 -0
  25. package/dist/kes/singleKes.d.ts +0 -0
  26. package/dist/kes/singleKes.js +0 -0
  27. package/dist/noble/_assert.d.ts +23 -0
  28. package/dist/noble/_assert.js +55 -0
  29. package/dist/noble/_md.d.ts +29 -0
  30. package/dist/noble/_md.js +170 -0
  31. package/dist/noble/_shortw_utils.d.ts +61 -0
  32. package/dist/noble/_shortw_utils.js +63 -0
  33. package/dist/noble/_u64.d.ts +28 -0
  34. package/dist/noble/_u64.js +116 -0
  35. package/dist/noble/abstract/bls.d.ts +119 -0
  36. package/dist/noble/abstract/bls.js +334 -0
  37. package/dist/noble/abstract/curve.d.ts +83 -0
  38. package/dist/noble/abstract/curve.js +319 -0
  39. package/dist/noble/abstract/edwards.d.ts +85 -0
  40. package/dist/noble/abstract/edwards.js +508 -0
  41. package/dist/noble/abstract/hash-to-curve.d.ts +57 -0
  42. package/dist/noble/abstract/hash-to-curve.js +220 -0
  43. package/dist/noble/abstract/modular.d.ts +122 -0
  44. package/dist/noble/abstract/modular.js +455 -0
  45. package/dist/noble/abstract/montgomery.d.ts +28 -0
  46. package/dist/noble/abstract/montgomery.js +172 -0
  47. package/dist/noble/abstract/utils.d.ts +106 -0
  48. package/dist/noble/abstract/utils.js +442 -0
  49. package/dist/noble/bls12_381.d.ts +95 -0
  50. package/dist/noble/bls12_381.js +1434 -0
  51. package/dist/noble/crypto.d.ts +1 -0
  52. package/dist/noble/crypto.js +4 -0
  53. package/dist/noble/curves/curve.d.ts +69 -0
  54. package/dist/noble/curves/curve.js +167 -0
  55. package/dist/noble/curves/modular.d.ts +122 -0
  56. package/dist/noble/curves/modular.js +442 -0
  57. package/dist/noble/curves/utils.d.ts +93 -0
  58. package/dist/noble/curves/utils.js +385 -0
  59. package/dist/noble/curves/weierstrass.d.ts +240 -0
  60. package/dist/noble/curves/weierstrass.js +1178 -0
  61. package/dist/noble/ed25519.d.ts +100 -0
  62. package/dist/noble/ed25519.js +494 -0
  63. package/dist/noble/hmac.d.ts +25 -0
  64. package/dist/noble/hmac.js +101 -0
  65. package/dist/noble/index.d.ts +2 -0
  66. package/dist/noble/index.js +20 -0
  67. package/dist/noble/keccak.d.ts +58 -0
  68. package/dist/noble/keccak.js +289 -0
  69. package/dist/noble/ripemd_160.d.ts +20 -0
  70. package/dist/noble/ripemd_160.js +147 -0
  71. package/dist/noble/secp256k1.d.ts +98 -0
  72. package/dist/noble/secp256k1.js +309 -0
  73. package/dist/noble/sha256.d.ts +34 -0
  74. package/dist/noble/sha256.js +146 -0
  75. package/dist/noble/sha512.d.ts +66 -0
  76. package/dist/noble/sha512.js +301 -0
  77. package/dist/noble/utils.d.ts +90 -0
  78. package/dist/noble/utils.js +278 -0
  79. package/dist/ripemd_160.d.ts +1 -0
  80. package/dist/ripemd_160.js +23 -0
  81. package/dist/rust_vrf_reimpl/curves.d.ts +162 -0
  82. package/dist/rust_vrf_reimpl/curves.js +4225 -0
  83. package/dist/rust_vrf_reimpl/vrf03.d.ts +60 -0
  84. package/dist/rust_vrf_reimpl/vrf03.js +373 -0
  85. package/dist/rust_vrf_reimpl/vrf10.d.ts +73 -0
  86. package/dist/rust_vrf_reimpl/vrf10.js +468 -0
  87. package/dist/rust_vrf_reimpl/vrf10_batch.d.ts +53 -0
  88. package/dist/rust_vrf_reimpl/vrf10_batch.js +245 -0
  89. package/dist/secp256k1.d.ts +4 -0
  90. package/dist/secp256k1.js +33 -0
  91. package/dist/sha2_256.d.ts +16 -0
  92. package/dist/sha2_256.js +403 -0
  93. package/dist/sha2_512.d.ts +16 -0
  94. package/dist/sha2_512.js +256 -0
  95. package/dist/sha3.d.ts +17 -0
  96. package/dist/sha3.js +181 -0
  97. package/dist/types.d.ts +26 -0
  98. package/dist/types.js +120 -0
  99. package/dist/utils/assert.d.ts +3 -0
  100. package/dist/utils/assert.js +55 -0
  101. package/dist/utils/base32.d.ts +5 -0
  102. package/dist/utils/base32.js +52 -0
  103. package/dist/utils/bigintToBuffer.d.ts +1 -0
  104. package/dist/utils/bigintToBuffer.js +27 -0
  105. package/dist/utils/bytesToHex.d.ts +2 -0
  106. package/dist/utils/bytesToHex.js +15 -0
  107. package/dist/utils/getRandomValues.d.ts +4 -0
  108. package/dist/utils/getRandomValues.js +12 -0
  109. package/dist/utils/hexToBytes.d.ts +2 -0
  110. package/dist/utils/hexToBytes.js +14 -0
  111. package/dist/utils/index.d.ts +3 -0
  112. package/dist/utils/index.js +19 -0
  113. package/dist/utils/positiveMod.d.ts +1 -0
  114. package/dist/utils/positiveMod.js +11 -0
  115. package/dist/utils/promisifySync.d.ts +0 -0
  116. package/dist/utils/promisifySync.js +0 -0
  117. package/dist/utils/rotr32.d.ts +2 -0
  118. package/dist/utils/rotr32.js +7 -0
  119. package/dist/vrf.d.ts +74 -0
  120. package/dist/vrf.js +286 -0
  121. package/package.json +49 -4
@@ -0,0 +1,268 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.isFp6 = exports.isBlsResult = exports.bls12_381_finalVerify = exports.bls12_381_eqMlResult = exports.bls12_381_mulMlResult = exports.bls12_381_millerLoop = exports.bls12_381_G2_uncompress = exports.bls12_381_G2_compress = exports.bls12_381_G2_hashToGroup = exports.bls12_381_G2_equal = exports.bls12_381_G2_scalarMul = exports.bls12_381_G2_neg = exports.bls12_381_G2_add = exports.bls12_381_G1_uncompress = exports.bls12_381_G1_compress = exports.bls12_381_G1_hashToGroup = exports.bls12_381_G1_equal = exports.bls12_381_G1_scalarMul = exports.bls12_381_G1_neg = exports.bls12_381_G1_add = exports.isFp2 = exports.isBlsG2 = exports.isBlsG1 = exports.BlsG2 = exports.BlsG1 = void 0;
15
+ var noble_1 = require("./noble/index.js");
16
+ var hash_to_curve_1 = require("./noble/abstract/hash-to-curve.js");
17
+ var utils_1 = require("./noble/abstract/utils.js");
18
+ var sha256_1 = require("./noble/sha256.js");
19
+ exports.BlsG1 = noble_1.bls12_381.G1.ProjectivePoint;
20
+ exports.BlsG2 = noble_1.bls12_381.G2.ProjectivePoint;
21
+ function isBlsG1(stuff) {
22
+ return stuff instanceof exports.BlsG1 && (typeof stuff.px === "bigint" &&
23
+ typeof stuff.py === "bigint" &&
24
+ typeof stuff.pz === "bigint");
25
+ }
26
+ exports.isBlsG1 = isBlsG1;
27
+ function isBlsG2(stuff) {
28
+ return stuff instanceof exports.BlsG2 && (isFp2(stuff.px) &&
29
+ isFp2(stuff.py) &&
30
+ isFp2(stuff.pz));
31
+ }
32
+ exports.isBlsG2 = isBlsG2;
33
+ function isFp2(stuff) {
34
+ return typeof stuff === "object" && (stuff !== null && !Array.isArray(stuff) &&
35
+ typeof stuff.c0 === "bigint" &&
36
+ typeof stuff.c1 === "bigint");
37
+ }
38
+ exports.isFp2 = isFp2;
39
+ var curveOrder = BigInt("52435875175126190479447740508185965837690552500527637822603658699938581184513");
40
+ var htfDefaults = Object.freeze({
41
+ // DST: a domain separation tag
42
+ // defined in section 2.2.5
43
+ // Use utils.getDSTLabel(), utils.setDSTLabel(value)
44
+ DST: "",
45
+ encodeDST: "",
46
+ // p: the characteristic of F
47
+ // where F is a finite field of characteristic p and order q = p^m
48
+ p: noble_1.Fp.ORDER,
49
+ // m: the extension degree of F, m >= 1
50
+ // where F is a finite field of characteristic p and order q = p^m
51
+ m: 2,
52
+ // k: the target security level for the suite in bits
53
+ // defined in section 5.1
54
+ k: 128,
55
+ // option to use a message that has already been processed by
56
+ // expand_message_xmd
57
+ expand: 'xmd',
58
+ // Hash functions for: expand_message_xmd is appropriate for use with a
59
+ // wide range of hash functions, including SHA-2, SHA-3, BLAKE2, and others.
60
+ // BBS+ uses blake2: https://github.com/hyperledger/aries-framework-go/issues/2247
61
+ hash: sha256_1.sha256,
62
+ });
63
+ var G2_Hasher = (0, hash_to_curve_1.createHasher)(exports.BlsG2, noble_1.G2_mapToCurve, __assign({}, htfDefaults));
64
+ var G1_Hasher = (0, hash_to_curve_1.createHasher)(exports.BlsG1, noble_1.G1_mapToCurve, __assign(__assign({}, htfDefaults), { m: 1, DST: 'BLS_SIG_BLS12381G1_XMD:SHA-256_SSWU_RO_NUL_' }));
65
+ function bls12_381_G1_add(a, b) {
66
+ // if( bls12_381_G1_equal( a, BlsG1.ZERO ) ) return b;
67
+ // if( bls12_381_G1_equal( b, BlsG1.ZERO ) ) return a;
68
+ return a.add(b);
69
+ }
70
+ exports.bls12_381_G1_add = bls12_381_G1_add;
71
+ function bls12_381_G1_neg(elem) {
72
+ return elem.negate();
73
+ }
74
+ exports.bls12_381_G1_neg = bls12_381_G1_neg;
75
+ function bls12_381_G1_scalarMul(n, g1) {
76
+ if (n < 0)
77
+ return bls12_381_G1_scalarMul(-n, bls12_381_G1_neg(g1));
78
+ n = BigInt(n);
79
+ if (n >= curveOrder)
80
+ n = n % curveOrder;
81
+ if (n === BigInt(0))
82
+ return exports.BlsG1.ZERO;
83
+ return g1.multiply(n);
84
+ }
85
+ exports.bls12_381_G1_scalarMul = bls12_381_G1_scalarMul;
86
+ function bls12_381_G1_equal(a, b) {
87
+ return a.equals(b);
88
+ }
89
+ exports.bls12_381_G1_equal = bls12_381_G1_equal;
90
+ function bls12_381_G1_hashToGroup(a, b) {
91
+ // noble-curves can handle that but the plutus-machine doesn't
92
+ // so we artificially throw an error here
93
+ if (b.length > 255)
94
+ throw new Error("DST length can not be greater than 255");
95
+ return exports.BlsG1.fromAffine(G1_Hasher.hashToCurve(a, { DST: b })
96
+ .toAffine());
97
+ }
98
+ exports.bls12_381_G1_hashToGroup = bls12_381_G1_hashToGroup;
99
+ function bls12_381_G1_compress(elem) {
100
+ return elem.toRawBytes();
101
+ }
102
+ exports.bls12_381_G1_compress = bls12_381_G1_compress;
103
+ function bls12_381_G1_uncompress(compressed) {
104
+ var _a = (0, noble_1.parseMask)(compressed), compressed_bit = _a.compressed, infinity = _a.infinity, sort = _a.sort, value = _a.value;
105
+ // point zero edge case
106
+ if (compressed_bit &&
107
+ infinity &&
108
+ sort &&
109
+ value.every(function (n) { return n === 0; }))
110
+ throw new Error("sign bit set on pont ZERO, we don't like it");
111
+ // not compressed bytes would be totally fine for the library but we artificially fail here
112
+ // https://github.com/IntersectMBO/plutus/blob/master/plutus-conformance/test-cases/uplc/evaluation/builtin/semantics/bls12_381_G1_uncompress/on-curve-serialised-not-compressed/on-curve-serialised-not-compressed.uplc
113
+ if (!compressed_bit)
114
+ throw new Error("uncompress only works with compressed byets");
115
+ return exports.BlsG1.fromHex(compressed);
116
+ }
117
+ exports.bls12_381_G1_uncompress = bls12_381_G1_uncompress;
118
+ function bls12_381_G2_add(a, b) {
119
+ // if( bls12_381_G2_equal( a, BlsG2.ZERO ) ) return b;
120
+ // if( bls12_381_G2_equal( b, BlsG2.ZERO ) ) return a;
121
+ return a.add(b);
122
+ }
123
+ exports.bls12_381_G2_add = bls12_381_G2_add;
124
+ function bls12_381_G2_neg(elem) {
125
+ return elem.negate();
126
+ }
127
+ exports.bls12_381_G2_neg = bls12_381_G2_neg;
128
+ function bls12_381_G2_scalarMul(n, g2) {
129
+ if (n < 0)
130
+ return bls12_381_G2_scalarMul(-n, bls12_381_G2_neg(g2));
131
+ n = BigInt(n);
132
+ if (n >= curveOrder)
133
+ n = n % curveOrder;
134
+ if (n === BigInt(0))
135
+ return exports.BlsG2.ZERO;
136
+ return g2.multiply(BigInt(n));
137
+ }
138
+ exports.bls12_381_G2_scalarMul = bls12_381_G2_scalarMul;
139
+ function bls12_381_G2_equal(a, b) {
140
+ return a.equals(b);
141
+ }
142
+ exports.bls12_381_G2_equal = bls12_381_G2_equal;
143
+ function bls12_381_G2_hashToGroup(a, b) {
144
+ // noble-curves can handle that but the plutus-machine doesn't
145
+ // so we artificially throw an error here
146
+ if (b.length > 255)
147
+ throw new Error("DST length can not be greater than 255");
148
+ return exports.BlsG2.fromAffine(G2_Hasher.hashToCurve(a, { DST: b })
149
+ .toAffine());
150
+ }
151
+ exports.bls12_381_G2_hashToGroup = bls12_381_G2_hashToGroup;
152
+ function bls12_381_G2_compress(elem) {
153
+ return elem.toRawBytes();
154
+ }
155
+ exports.bls12_381_G2_compress = bls12_381_G2_compress;
156
+ function bls12_381_G2_uncompress(compressed) {
157
+ var compressed_bit = (0, noble_1.parseMask)(compressed).compressed;
158
+ // not compressed bytes would be totally fine for the library but we artificially fail here
159
+ // https://github.com/IntersectMBO/plutus/blob/master/plutus-conformance/test-cases/uplc/evaluation/builtin/semantics/bls12_381_G2_uncompress/on-curve-serialised-not-compressed/on-curve-serialised-not-compressed.uplc
160
+ if (!compressed_bit)
161
+ throw new Error("uncompress only works with compressed byets");
162
+ return exports.BlsG2.fromHex(compressed);
163
+ }
164
+ exports.bls12_381_G2_uncompress = bls12_381_G2_uncompress;
165
+ function bls12_381_millerLoop(g1, g2) {
166
+ var _a = g1.toAffine(), x = _a.x, y = _a.y;
167
+ return millerLoop(pairingPrecomputes(g2), [x, y]);
168
+ }
169
+ exports.bls12_381_millerLoop = bls12_381_millerLoop;
170
+ function bls12_381_mulMlResult(a, b) {
171
+ return (0, noble_1.Fp12Multiply)(a, b);
172
+ }
173
+ exports.bls12_381_mulMlResult = bls12_381_mulMlResult;
174
+ exports.bls12_381_eqMlResult = noble_1.Fp12_eql;
175
+ function bls12_381_finalVerify(a, b) {
176
+ // blst implementation https://github.com/supranational/blst/blob/0d46eefa45fc1e57aceb42bba0e84eab3a7a9725/src/aggregate.c#L506
177
+ var GT = (0, noble_1.Fp12_conjugate)(a);
178
+ GT = (0, noble_1.Fp12Multiply)(GT, b);
179
+ GT = (0, noble_1.Fp12_finalExponentiate)(GT);
180
+ return (0, noble_1.Fp12_eql)(GT, noble_1.Fp12_ONE);
181
+ }
182
+ exports.bls12_381_finalVerify = bls12_381_finalVerify;
183
+ // The BLS parameter x for BLS12-381
184
+ var BLS_X = BigInt('0xd201000000010000');
185
+ var BLS_X_LEN = (0, utils_1.bitLen)(BLS_X);
186
+ var _2n = BigInt(2), _3n = BigInt(3);
187
+ // Pre-compute coefficients for sparse multiplication
188
+ // Point addition and point double calculations is reused for coefficients
189
+ function calcPairingPrecomputes(p) {
190
+ var x = p.x, y = p.y;
191
+ // prettier-ignore
192
+ var Qx = x, Qy = y, Qz = noble_1.Fp2.ONE;
193
+ // prettier-ignore
194
+ var Rx = Qx, Ry = Qy, Rz = Qz;
195
+ var ell_coeff = [];
196
+ for (var i = BLS_X_LEN - 2; i >= 0; i--) {
197
+ // Double
198
+ var t0 = noble_1.Fp2.sqr(Ry); // Ry²
199
+ var t1 = noble_1.Fp2.sqr(Rz); // Rz²
200
+ var t2 = noble_1.Fp2.multiplyByB(noble_1.Fp2.mul(t1, _3n)); // 3 * T1 * B
201
+ var t3 = noble_1.Fp2.mul(t2, _3n); // 3 * T2
202
+ var t4 = noble_1.Fp2.sub(noble_1.Fp2.sub(noble_1.Fp2.sqr(noble_1.Fp2.add(Ry, Rz)), t1), t0); // (Ry + Rz)² - T1 - T0
203
+ ell_coeff.push([
204
+ noble_1.Fp2.sub(t2, t0),
205
+ noble_1.Fp2.mul(noble_1.Fp2.sqr(Rx), _3n),
206
+ noble_1.Fp2.neg(t4), // -T4
207
+ ]);
208
+ Rx = noble_1.Fp2.div(noble_1.Fp2.mul(noble_1.Fp2.mul(noble_1.Fp2.sub(t0, t3), Rx), Ry), _2n); // ((T0 - T3) * Rx * Ry) / 2
209
+ Ry = noble_1.Fp2.sub(noble_1.Fp2.sqr(noble_1.Fp2.div(noble_1.Fp2.add(t0, t3), _2n)), noble_1.Fp2.mul(noble_1.Fp2.sqr(t2), _3n)); // ((T0 + T3) / 2)² - 3 * T2²
210
+ Rz = noble_1.Fp2.mul(t0, t4); // T0 * T4
211
+ if ((0, utils_1.bitGet)(BLS_X /*CURVE.params.x*/, i)) {
212
+ // Addition
213
+ var t0_1 = noble_1.Fp2.sub(Ry, noble_1.Fp2.mul(Qy, Rz)); // Ry - Qy * Rz
214
+ var t1_1 = noble_1.Fp2.sub(Rx, noble_1.Fp2.mul(Qx, Rz)); // Rx - Qx * Rz
215
+ ell_coeff.push([
216
+ noble_1.Fp2.sub(noble_1.Fp2.mul(t0_1, Qx), noble_1.Fp2.mul(t1_1, Qy)),
217
+ noble_1.Fp2.neg(t0_1),
218
+ t1_1, // T1
219
+ ]);
220
+ var t2_1 = noble_1.Fp2.sqr(t1_1); // T1²
221
+ var t3_1 = noble_1.Fp2.mul(t2_1, t1_1); // T2 * T1
222
+ var t4_1 = noble_1.Fp2.mul(t2_1, Rx); // T2 * Rx
223
+ var t5 = noble_1.Fp2.add(noble_1.Fp2.sub(t3_1, noble_1.Fp2.mul(t4_1, _2n)), noble_1.Fp2.mul(noble_1.Fp2.sqr(t0_1), Rz)); // T3 - 2 * T4 + T0² * Rz
224
+ Rx = noble_1.Fp2.mul(t1_1, t5); // T1 * T5
225
+ Ry = noble_1.Fp2.sub(noble_1.Fp2.mul(noble_1.Fp2.sub(t4_1, t5), t0_1), noble_1.Fp2.mul(t3_1, Ry)); // (T4 - T5) * T0 - T3 * Ry
226
+ Rz = noble_1.Fp2.mul(Rz, t3_1); // Rz * T3
227
+ }
228
+ }
229
+ return ell_coeff;
230
+ }
231
+ function pairingPrecomputes(point) {
232
+ var p = point;
233
+ if (p._PPRECOMPUTES)
234
+ return p._PPRECOMPUTES;
235
+ p._PPRECOMPUTES = calcPairingPrecomputes(point.toAffine());
236
+ return p._PPRECOMPUTES;
237
+ }
238
+ function millerLoop(ell, g1) {
239
+ var x = BLS_X;
240
+ var Px = g1[0];
241
+ var Py = g1[1];
242
+ var f12 = noble_1.Fp12.ONE;
243
+ for (var j = 0, i = BLS_X_LEN - 2; i >= 0; i--, j++) {
244
+ var E = ell[j];
245
+ f12 = noble_1.Fp12.multiplyBy014(f12, E[0], noble_1.Fp2.mul(E[1], Px), noble_1.Fp2.mul(E[2], Py));
246
+ if ((0, utils_1.bitGet)(x, i)) {
247
+ j += 1;
248
+ var F = ell[j];
249
+ f12 = noble_1.Fp12.multiplyBy014(f12, F[0], noble_1.Fp2.mul(F[1], Px), noble_1.Fp2.mul(F[2], Py));
250
+ }
251
+ if (i !== 0)
252
+ f12 = noble_1.Fp12.sqr(f12);
253
+ }
254
+ return noble_1.Fp12.conjugate(f12);
255
+ }
256
+ function isBlsResult(stuff) {
257
+ return typeof stuff === "object" && (stuff !== null && !Array.isArray(stuff) &&
258
+ isFp6(stuff.c0) &&
259
+ isFp6(stuff.c1));
260
+ }
261
+ exports.isBlsResult = isBlsResult;
262
+ function isFp6(stuff) {
263
+ return typeof stuff === "object" && (stuff !== null && !Array.isArray(stuff) &&
264
+ isFp2(stuff.c0) &&
265
+ isFp2(stuff.c1) &&
266
+ isFp2(stuff.c2));
267
+ }
268
+ exports.isFp6 = isFp6;
@@ -0,0 +1,55 @@
1
+ import { byte } from "./types.js";
2
+ declare function nativeEd25519Sign(privateKey: Uint8Array, data: Uint8Array): Promise<Uint8Array>;
3
+ export declare function ed25519bigint(n: bigint): bigint;
4
+ declare function nativeEd25519Verify(publicKey: Uint8Array, signature: Uint8Array | ArrayBuffer, data: Uint8Array | ArrayBuffer): Promise<boolean>;
5
+ export type bigpoint = [bigint, bigint];
6
+ /**
7
+ * Curve point 'addition'
8
+ * Note: this is probably the bottleneck of this Ed25519 implementation
9
+ */
10
+ export declare function addPointsEdwards(a: Readonly<bigpoint>, b: Readonly<bigpoint>): bigpoint;
11
+ export declare function scalarMul(point: Readonly<bigpoint>, n: bigint): bigpoint;
12
+ /**
13
+ * Curve point 'multiplication'
14
+ */
15
+ export declare function encodeInt(y: bigint): Uint8Array;
16
+ export declare function bigpointToUint8Array(point: bigpoint): Uint8Array;
17
+ export declare function pointFromBytes(s: Uint8Array): bigpoint;
18
+ export declare function scalarFromBytes(h: Uint8Array): bigint;
19
+ export declare function scalarToBytes(s: bigint): Uint8Array;
20
+ type Uint8ArrayLike = ArrayBuffer | Uint8Array | string | byte[];
21
+ export declare function scalarMultBase(scalar: bigint): bigpoint;
22
+ export declare function getExtendEd25519PrivateKeyComponentsAsBytes_sync(privateKey: Uint8Array): [scalar: Uint8Array, extension: Uint8Array];
23
+ export declare function getExtendEd25519PrivateKeyComponents_sync(privateKey: Uint8Array): [scalar: bigint, extension: Uint8Array];
24
+ export declare function getExtendedEd25519PrivateKey_sync(privateKey: Uint8Array): Uint8Array;
25
+ export declare function getExtendedEd25519PrivateKey(privateKey: Uint8Array): Promise<Uint8Array>;
26
+ export declare function deriveEd25519PublicKey_sync(privateKey: Uint8Array): Uint8Array;
27
+ declare function deriveEd25519PublicKey_async(privateKey: Uint8Array): Promise<Uint8Array>;
28
+ export declare const deriveEd25519PublicKey: typeof deriveEd25519PublicKey_async;
29
+ export declare function extendedToPublic(extended: Uint8Array | byte[]): Uint8Array;
30
+ export interface SignEd25519Result {
31
+ 0: Uint8Array;
32
+ 1: Uint8Array;
33
+ /** to be `ArrayLike` */
34
+ length: 2;
35
+ [Symbol.iterator]: () => Generator<Uint8Array, void, unknown>;
36
+ pubKey: Uint8Array;
37
+ signature: Uint8Array;
38
+ }
39
+ /** sign a message with a (32 bytes) private key */
40
+ export declare function signEd25519_sync(message: Uint8ArrayLike, privateKey: Uint8ArrayLike): SignEd25519Result;
41
+ /** sign a message with a (32 bytes) private key */
42
+ export declare function signEd25519(message: Uint8ArrayLike, privateKey: Uint8ArrayLike): Promise<SignEd25519Result>;
43
+ /** sign a message with a (64 bytes) private key */
44
+ export declare function signExtendedEd25519_sync(_message: Uint8ArrayLike, _extendedKey: Uint8ArrayLike): SignEd25519Result;
45
+ /** sign a message with a (64 bytes) private key */
46
+ declare function nativeExtendedSignEd25519(_message: Uint8ArrayLike, _extendedKey: Uint8ArrayLike): Promise<SignEd25519Result>;
47
+ /** sign a message with a (64 bytes) private key */
48
+ export declare const signExtendedEd25519: typeof nativeExtendedSignEd25519;
49
+ /** sign a message with a (32 bytes) private key */
50
+ export declare function getEd25519Signature_sync(message: Uint8ArrayLike, privateKey: Uint8ArrayLike): Uint8Array;
51
+ /** sign a message with a (32 bytes) private key */
52
+ export declare const getEd25519Signature: typeof nativeEd25519Sign;
53
+ export declare function verifyEd25519Signature_sync(_signature: Uint8ArrayLike, _message: Uint8ArrayLike, _publicKey: Uint8ArrayLike): boolean;
54
+ export declare const verifyEd25519Signature: typeof nativeEd25519Verify;
55
+ export {};