@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
package/dist/vrf.d.ts ADDED
@@ -0,0 +1,74 @@
1
+ import { EdwardsPoint } from "./rust_vrf_reimpl/curves.js";
2
+ import { IVrfProof03 } from "./rust_vrf_reimpl/vrf03.js";
3
+ import { IVrfProof10 } from "./rust_vrf_reimpl/vrf10.js";
4
+ import { IVrfBatchProof10 } from "./rust_vrf_reimpl/vrf10_batch.js";
5
+ export declare class VrfProof03 implements IVrfProof03 {
6
+ readonly gamma: EdwardsPoint;
7
+ readonly challenge: Uint8Array;
8
+ readonly response: Uint8Array;
9
+ constructor({ gamma, challenge, response }: IVrfProof03);
10
+ toHash(): Uint8Array & {
11
+ length: 64;
12
+ };
13
+ static generate(secret_key: Uint8Array, public_key: Uint8Array, alpha_string: Uint8Array): VrfProof03;
14
+ static verify(public_key: Uint8Array, alpha_string: Uint8Array, proof: IVrfProof03): boolean;
15
+ verify(public_key: Uint8Array, alpha_string: Uint8Array): boolean;
16
+ toBytes(): Uint8Array & {
17
+ length: 80;
18
+ };
19
+ static fromBytes(bytes: Uint8Array): VrfProof03;
20
+ }
21
+ export declare function derive_vrf10_public_key(secret_key: Uint8Array): Uint8Array;
22
+ export declare class VrfProof10 implements IVrfProof10 {
23
+ readonly gamma: EdwardsPoint;
24
+ readonly challenge: Uint8Array;
25
+ readonly response: Uint8Array;
26
+ constructor({ gamma, challenge, response }: IVrfProof10);
27
+ toHash(): Uint8Array & {
28
+ length: 64;
29
+ };
30
+ static generate(secret_key: Uint8Array, public_key: Uint8Array, alpha_string: Uint8Array): VrfProof10;
31
+ static verify(public_key: Uint8Array, alpha_string: Uint8Array, proof: IVrfProof10): boolean;
32
+ verify(public_key: Uint8Array, alpha_string: Uint8Array): boolean;
33
+ toBytes(): Uint8Array & {
34
+ length: 80;
35
+ };
36
+ static fromBytes(bytes: Uint8Array): VrfProof10;
37
+ }
38
+ export declare class VrfBatchProof10 implements IVrfBatchProof10 {
39
+ readonly gamma: EdwardsPoint;
40
+ readonly u_point: EdwardsPoint;
41
+ readonly v_point: EdwardsPoint;
42
+ readonly response: Uint8Array;
43
+ constructor({ gamma, u_point, v_point, response }: IVrfBatchProof10);
44
+ toHash(): Uint8Array & {
45
+ length: 64;
46
+ };
47
+ static generate(secret_key: Uint8Array, public_key: Uint8Array, alpha_string: Uint8Array): VrfBatchProof10;
48
+ static verify(public_key: Uint8Array, alpha_string: Uint8Array, proof: IVrfBatchProof10): boolean;
49
+ verify(public_key: Uint8Array, alpha_string: Uint8Array): boolean;
50
+ toBytes(): Uint8Array & {
51
+ length: 128;
52
+ };
53
+ static fromBytes(bytes: Uint8Array): VrfBatchProof10;
54
+ }
55
+ export interface IBatchItem {
56
+ proof: VrfBatchProof10;
57
+ /** in rust called "key" */
58
+ public_key: Uint8Array;
59
+ /** in rust called "msg" */
60
+ alpha: Uint8Array;
61
+ }
62
+ export declare class VrfBatchVerifier {
63
+ readonly size: number;
64
+ readonly proof_scalars: [Uint8Array, Uint8Array][];
65
+ readonly pks: EdwardsPoint[];
66
+ readonly us: EdwardsPoint[];
67
+ readonly hs: EdwardsPoint[];
68
+ readonly gammas: EdwardsPoint[];
69
+ readonly vs: EdwardsPoint[];
70
+ private _currLen;
71
+ constructor(size: number);
72
+ insert(item: IBatchItem): void;
73
+ verify(): boolean;
74
+ }
package/dist/vrf.js ADDED
@@ -0,0 +1,286 @@
1
+ "use strict";
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.VrfBatchVerifier = exports.VrfBatchProof10 = exports.VrfProof10 = exports.derive_vrf10_public_key = exports.VrfProof03 = void 0;
20
+ var uint8array_utils_1 = require("@harmoniclabs/uint8array-utils");
21
+ var curves_1 = require("./rust_vrf_reimpl/curves.js");
22
+ var vrf03_1 = require("./rust_vrf_reimpl/vrf03.js");
23
+ var vrf10_1 = require("./rust_vrf_reimpl/vrf10.js");
24
+ var vrf10_batch_1 = require("./rust_vrf_reimpl/vrf10_batch.js");
25
+ var getRandomValues_1 = require("./utils/getRandomValues.js");
26
+ var VrfProof03 = /** @class */ (function () {
27
+ function VrfProof03(_a) {
28
+ var gamma = _a.gamma, challenge = _a.challenge, response = _a.response;
29
+ this.gamma = gamma;
30
+ this.challenge = challenge;
31
+ this.response = response;
32
+ }
33
+ VrfProof03.prototype.toHash = function () {
34
+ return (0, vrf03_1.proof_to_hash)(this);
35
+ };
36
+ VrfProof03.generate = function (secret_key, public_key, alpha_string) {
37
+ return new VrfProof03((0, vrf03_1.vrf_ed25519_sha512_ell2_generate_proof)(secret_key, public_key, alpha_string));
38
+ };
39
+ VrfProof03.verify = function (public_key, alpha_string, proof) {
40
+ return (0, vrf03_1.vrf_ed25519_sha512_ell2_verify_proof)(public_key, alpha_string, proof);
41
+ };
42
+ VrfProof03.prototype.verify = function (public_key, alpha_string) {
43
+ return (0, vrf03_1.vrf_ed25519_sha512_ell2_verify_proof)(public_key, alpha_string, this);
44
+ };
45
+ /*
46
+ pub fn to_bytes(&self) -> [u8; PROOF_SIZE] {
47
+ let mut proof = [0u8; PROOF_SIZE];
48
+ proof[..32].copy_from_slice(self.gamma.compress().as_bytes());
49
+ proof[32..48].copy_from_slice(&self.challenge.to_bytes()[..16]);
50
+ proof[48..].copy_from_slice(self.response.as_bytes());
51
+
52
+ proof
53
+ }
54
+ */
55
+ VrfProof03.prototype.toBytes = function () {
56
+ var output = new Uint8Array(80);
57
+ output.set(this.gamma.compress(), 0);
58
+ output.set(this.challenge.slice(0, 16), 32);
59
+ output.set(this.response, 48);
60
+ return output;
61
+ };
62
+ VrfProof03.fromBytes = function (bytes) {
63
+ var gamma = curves_1.EdwardsPoint.decompress(Uint8Array.prototype.slice.call(bytes, 0, 32));
64
+ if (!gamma)
65
+ throw new Error("Invalid gamma point");
66
+ var challenge = new Uint8Array(32);
67
+ challenge.set(Uint8Array.prototype.slice.call(bytes, 32, 48), 0);
68
+ var response = Uint8Array.prototype.slice.call(bytes, 48, 80);
69
+ return new VrfProof03({
70
+ gamma: gamma,
71
+ challenge: challenge,
72
+ response: response
73
+ });
74
+ };
75
+ return VrfProof03;
76
+ }());
77
+ exports.VrfProof03 = VrfProof03;
78
+ function derive_vrf10_public_key(secret_key) {
79
+ return curves_1.EdwardsPoint.BASEPOINT_ED25519.scalarMul((0, vrf10_1.extend_secret_key)(secret_key)[0]).compress();
80
+ }
81
+ exports.derive_vrf10_public_key = derive_vrf10_public_key;
82
+ var VrfProof10 = /** @class */ (function () {
83
+ function VrfProof10(_a) {
84
+ var gamma = _a.gamma, challenge = _a.challenge, response = _a.response;
85
+ this.gamma = gamma;
86
+ this.challenge = challenge;
87
+ this.response = response;
88
+ }
89
+ VrfProof10.prototype.toHash = function () {
90
+ return (0, vrf10_1.vrf10_proof_to_hash)(this);
91
+ };
92
+ VrfProof10.generate = function (secret_key, public_key, alpha_string) {
93
+ return new VrfProof10((0, vrf10_1.vrf10_ed25519_sha512_ell2_generate_proof)(secret_key, public_key, alpha_string));
94
+ };
95
+ VrfProof10.verify = function (public_key, alpha_string, proof) {
96
+ return (0, vrf10_1.vrf10_ed25519_sha512_ell2_verify_proof)(public_key, alpha_string, proof);
97
+ };
98
+ VrfProof10.prototype.verify = function (public_key, alpha_string) {
99
+ return (0, vrf10_1.vrf10_ed25519_sha512_ell2_verify_proof)(public_key, alpha_string, this);
100
+ };
101
+ /*
102
+ pub fn to_bytes(&self) -> [u8; PROOF_SIZE] {
103
+ let mut proof = [0u8; PROOF_SIZE];
104
+ proof[..32].copy_from_slice(self.gamma.compress().as_bytes());
105
+ proof[32..48].copy_from_slice(&self.challenge.to_bytes()[..16]);
106
+ proof[48..].copy_from_slice(self.response.as_bytes());
107
+
108
+ proof
109
+ }
110
+ */
111
+ VrfProof10.prototype.toBytes = function () {
112
+ var output = new Uint8Array(80);
113
+ output.set(this.gamma.compress(), 0);
114
+ output.set(this.challenge.slice(0, 16), 32);
115
+ output.set(this.response, 48);
116
+ return output;
117
+ };
118
+ VrfProof10.fromBytes = function (bytes) {
119
+ var gamma = curves_1.EdwardsPoint.decompress(Uint8Array.prototype.slice.call(bytes, 0, 32));
120
+ if (!gamma)
121
+ throw new Error("Invalid gamma point");
122
+ var challenge = new Uint8Array(32);
123
+ challenge.set(Uint8Array.prototype.slice.call(bytes, 32, 48), 0);
124
+ var response = Uint8Array.prototype.slice.call(bytes, 48, 80);
125
+ return new VrfProof10({
126
+ gamma: gamma,
127
+ challenge: challenge,
128
+ response: response
129
+ });
130
+ };
131
+ return VrfProof10;
132
+ }());
133
+ exports.VrfProof10 = VrfProof10;
134
+ var VrfBatchProof10 = /** @class */ (function () {
135
+ function VrfBatchProof10(_a) {
136
+ var gamma = _a.gamma, u_point = _a.u_point, v_point = _a.v_point, response = _a.response;
137
+ this.gamma = gamma;
138
+ this.u_point = u_point;
139
+ this.v_point = v_point;
140
+ this.response = response;
141
+ }
142
+ VrfBatchProof10.prototype.toHash = function () {
143
+ return (0, vrf10_batch_1.vrf10_batch_ed25519_sha512_ell2_proof_to_hash)(this);
144
+ };
145
+ VrfBatchProof10.generate = function (secret_key, public_key, alpha_string) {
146
+ return new VrfBatchProof10((0, vrf10_batch_1.vrf10_batch_ed25519_sha512_ell2_generate_proof)(secret_key, public_key, alpha_string));
147
+ };
148
+ VrfBatchProof10.verify = function (public_key, alpha_string, proof) {
149
+ return (0, vrf10_batch_1.vrf10_batch_ed25519_sha512_ell2_verify_proof)(public_key, alpha_string, proof);
150
+ };
151
+ VrfBatchProof10.prototype.verify = function (public_key, alpha_string) {
152
+ return (0, vrf10_batch_1.vrf10_batch_ed25519_sha512_ell2_verify_proof)(public_key, alpha_string, this);
153
+ };
154
+ /*
155
+ pub fn to_bytes(&self) -> [u8; PROOF_SIZE] {
156
+ let mut proof = [0u8; PROOF_SIZE];
157
+ proof[..32].copy_from_slice(self.gamma.compress().as_bytes());
158
+ proof[32..48].copy_from_slice(&self.challenge.to_bytes()[..16]);
159
+ proof[48..].copy_from_slice(self.response.as_bytes());
160
+
161
+ proof
162
+ }
163
+ */
164
+ VrfBatchProof10.prototype.toBytes = function () {
165
+ var output = new Uint8Array(128);
166
+ output.set(this.gamma.compress(), 0);
167
+ output.set(this.u_point.compress(), 32);
168
+ output.set(this.v_point.compress(), 64);
169
+ output.set(this.response, 96);
170
+ return output;
171
+ };
172
+ VrfBatchProof10.fromBytes = function (bytes) {
173
+ var gamma = curves_1.EdwardsPoint.decompress(Uint8Array.prototype.slice.call(bytes, 0, 32));
174
+ if (!gamma)
175
+ throw new Error("Invalid gamma point");
176
+ var u_point = curves_1.EdwardsPoint.decompress(Uint8Array.prototype.slice.call(bytes, 32, 64));
177
+ if (!u_point)
178
+ throw new Error("Invalid u_point point");
179
+ var v_point = curves_1.EdwardsPoint.decompress(Uint8Array.prototype.slice.call(bytes, 64, 96));
180
+ if (!v_point)
181
+ throw new Error("Invalid v_point point");
182
+ var response = Uint8Array.prototype.slice.call(bytes, 96, 128);
183
+ return new VrfBatchProof10({
184
+ gamma: gamma,
185
+ u_point: u_point,
186
+ v_point: v_point,
187
+ response: response
188
+ });
189
+ };
190
+ return VrfBatchProof10;
191
+ }());
192
+ exports.VrfBatchProof10 = VrfBatchProof10;
193
+ function gen_u128_bytes() {
194
+ var buff = new Uint8Array(16);
195
+ (0, getRandomValues_1.getRandomValues)(buff);
196
+ return buff;
197
+ }
198
+ function gen_u128() {
199
+ return BigInt("0x" +
200
+ (0, uint8array_utils_1.toHex)(gen_u128_bytes()));
201
+ }
202
+ /** for some reason, from 38 elems up it fails */
203
+ var MAX_BATCH_SIZE = 37;
204
+ var VrfBatchVerifier = /** @class */ (function () {
205
+ function VrfBatchVerifier(size) {
206
+ this.size = size;
207
+ this._currLen = 0;
208
+ this.proof_scalars = new Array(size);
209
+ this.pks = new Array(size);
210
+ this.us = new Array(size);
211
+ this.hs = new Array(size);
212
+ this.gammas = new Array(size);
213
+ this.vs = new Array(size);
214
+ this._currLen = 0;
215
+ }
216
+ VrfBatchVerifier.prototype.insert = function (item) {
217
+ if (this._currLen >= this.size)
218
+ throw new Error("BatchVerifier is full");
219
+ var output = item.proof.toHash();
220
+ var decompressed_pk = curves_1.EdwardsPoint.decompress(item.public_key);
221
+ if (!decompressed_pk || decompressed_pk.is_small_order())
222
+ throw new Error("Invalid public key");
223
+ var h = (0, vrf10_1.vrf10_ed25519_sha512_ell2_hash_to_curve)(item.public_key, item.alpha);
224
+ var compressed_h = h.compress();
225
+ var gamma = item.proof.gamma;
226
+ var compressed_gamma = gamma.compress();
227
+ var u = item.proof.u_point;
228
+ var compressed_u = u.compress();
229
+ var v = item.proof.v_point;
230
+ var compressed_v = v.compress();
231
+ this.proof_scalars[this._currLen] = [
232
+ (0, vrf10_1.vrf10_ed25519_sha512_ell2_compute_challenge)(compressed_h, compressed_gamma, compressed_u, compressed_v),
233
+ item.proof.response
234
+ ];
235
+ this.pks[this._currLen] = decompressed_pk;
236
+ this.us[this._currLen] = u;
237
+ this.hs[this._currLen] = h;
238
+ this.gammas[this._currLen] = gamma;
239
+ this.vs[this._currLen] = v;
240
+ this._currLen++;
241
+ };
242
+ VrfBatchVerifier.prototype.verify = function () {
243
+ var size = this._currLen;
244
+ var b_coeff = scalar_zero();
245
+ /** array of scalars */
246
+ var lchalls = new Array(size);
247
+ /** array of scalars */
248
+ var rchalls = new Array(size);
249
+ /** array of scalars */
250
+ var ls = new Array(size);
251
+ /** array of scalars */
252
+ var rs = new Array(size);
253
+ /** array of scalars */
254
+ var rresponses = new Array(size);
255
+ for (var i = 0; i < size; i++) {
256
+ var _a = __read(this.proof_scalars[i], 2), challenge = _a[0], response = _a[1];
257
+ var li = new Uint8Array(32);
258
+ li.set(gen_u128_bytes(), 0);
259
+ var ri = new Uint8Array(32);
260
+ ri.set(gen_u128_bytes(), 0);
261
+ b_coeff = (0, curves_1.add_scalars)(b_coeff, (0, curves_1.mul_scalars)(li, response));
262
+ lchalls[i] = (0, curves_1.mul_scalars)(li, challenge);
263
+ ls[i] = li;
264
+ rresponses[i] = (0, curves_1.mul_scalars)(ri, (0, curves_1.negate_scalar)(response));
265
+ rchalls[i] = (0, curves_1.mul_scalars)(ri, challenge);
266
+ rs[i] = ri;
267
+ }
268
+ var result = curves_1.EdwardsPoint.vartime_multiscalar_mul([(0, curves_1.negate_scalar)(b_coeff)]
269
+ .concat(lchalls)
270
+ .concat(ls)
271
+ .concat(rresponses)
272
+ .concat(rchalls)
273
+ .concat(rs), [curves_1.EdwardsPoint.BASEPOINT_ED25519]
274
+ .concat(this.pks)
275
+ .concat(this.us)
276
+ .concat(this.hs)
277
+ .concat(this.gammas)
278
+ .concat(this.vs));
279
+ return result.is_identity();
280
+ };
281
+ return VrfBatchVerifier;
282
+ }());
283
+ exports.VrfBatchVerifier = VrfBatchVerifier;
284
+ function scalar_zero() {
285
+ return new Uint8Array(32);
286
+ }
package/package.json CHANGED
@@ -1,6 +1,51 @@
1
1
  {
2
2
  "name": "@ohos-ports/crypto",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.3.1-beta.1",
4
+ "description": "collection of cryptographic functions that support every js runtime for ES5+",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "type": "commonjs",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "test": "jest",
13
+ "tes": "jest",
14
+ "clear-jest": "jest --clearCache",
15
+ "test-watch": "jest --watchman",
16
+ "test-coverage": "jest --coverage",
17
+ "build": "rm -rf ./dist && tsc --project ./tsconfig.json && tsc-alias -p ./tsconfig.json",
18
+ "build:light": "tsc --project ./tsconfig.json && tsc-alias -p ./tsconfig.json",
19
+ "buidl": "npm run build",
20
+ "ci": "npm run test && npm run build",
21
+ "start": "npm-run-all --parallel build:watch run:watch"
22
+ },
23
+ "publishConfig": {
24
+ "registry": "https://registry.npmjs.org"
25
+ },
26
+ "author": "Harmonic Laboratories",
27
+ "license": "MIT",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/ohos-ports/ohos-ports.git",
31
+ "directory": "ports/crypto/0.3.1"
32
+ },
33
+ "bugs": {
34
+ "url": "https://github.com/ohos-ports/ohos-ports/issues"
35
+ },
36
+ "dependencies": {
37
+ "@harmoniclabs/bitstream": "^1.0.0",
38
+ "@harmoniclabs/uint8array-utils": "^1.0.3"
39
+ },
40
+ "devDependencies": {
41
+ "@babel/preset-env": "^7.18.6",
42
+ "@babel/preset-typescript": "^7.18.6",
43
+ "@types/blake2": "^4.0.1",
44
+ "@types/jest": "^28.1.4",
45
+ "@types/node": "^18.14.6",
46
+ "blake2": "^5.0.0",
47
+ "jest": "^29.4.3",
48
+ "tsc-alias": "^1.7.1",
49
+ "typescript": "^4.6.3"
50
+ }
51
+ }