@substrate-system/keys 0.2.41 → 0.2.44

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 (74) hide show
  1. package/README.md +68 -1
  2. package/dist/_base.cjs +92 -22
  3. package/dist/_base.cjs.map +2 -2
  4. package/dist/_base.d.ts +44 -3
  5. package/dist/_base.d.ts.map +1 -1
  6. package/dist/_base.js +92 -22
  7. package/dist/_base.js.map +2 -2
  8. package/dist/_base.min.cjs +1 -1
  9. package/dist/_base.min.cjs.map +3 -3
  10. package/dist/_base.min.js +2 -2
  11. package/dist/_base.min.js.map +4 -4
  12. package/dist/aes/index.cjs +8 -8
  13. package/dist/aes/index.cjs.map +2 -2
  14. package/dist/aes/index.d.ts.map +1 -1
  15. package/dist/aes/index.js +1 -1
  16. package/dist/aes/index.js.map +2 -2
  17. package/dist/aes/index.min.cjs +1 -1
  18. package/dist/aes/index.min.cjs.map +3 -3
  19. package/dist/aes/index.min.js +2 -2
  20. package/dist/aes/index.min.js.map +4 -4
  21. package/dist/browser/index.js +169 -2411
  22. package/dist/browser/index.min.js +2 -2
  23. package/dist/crypto.cjs +24 -23
  24. package/dist/crypto.cjs.map +3 -3
  25. package/dist/crypto.d.ts.map +1 -1
  26. package/dist/crypto.js +14 -3
  27. package/dist/crypto.js.map +2 -2
  28. package/dist/crypto.min.cjs +2 -2
  29. package/dist/crypto.min.cjs.map +3 -3
  30. package/dist/crypto.min.js +2 -2
  31. package/dist/crypto.min.js.map +4 -4
  32. package/dist/ecc/index.cjs +9 -21
  33. package/dist/ecc/index.cjs.map +2 -2
  34. package/dist/ecc/index.d.ts +1 -2
  35. package/dist/ecc/index.d.ts.map +1 -1
  36. package/dist/ecc/index.js +2 -14
  37. package/dist/ecc/index.js.map +2 -2
  38. package/dist/ecc/index.min.cjs +1 -1
  39. package/dist/ecc/index.min.cjs.map +3 -3
  40. package/dist/ecc/index.min.js +2 -2
  41. package/dist/ecc/index.min.js.map +4 -4
  42. package/dist/errors.cjs +10 -0
  43. package/dist/errors.cjs.map +2 -2
  44. package/dist/errors.d.ts +8 -0
  45. package/dist/errors.d.ts.map +1 -1
  46. package/dist/errors.js +10 -0
  47. package/dist/errors.js.map +2 -2
  48. package/dist/errors.min.cjs +1 -1
  49. package/dist/errors.min.cjs.map +3 -3
  50. package/dist/errors.min.js +1 -1
  51. package/dist/errors.min.js.map +3 -3
  52. package/dist/index.min.js +2 -2
  53. package/dist/index.min.js.map +4 -4
  54. package/dist/meta.json +35 -58
  55. package/dist/rsa/index.cjs +4 -9
  56. package/dist/rsa/index.cjs.map +2 -2
  57. package/dist/rsa/index.d.ts +1 -2
  58. package/dist/rsa/index.d.ts.map +1 -1
  59. package/dist/rsa/index.js +1 -6
  60. package/dist/rsa/index.js.map +2 -2
  61. package/dist/rsa/index.min.cjs +1 -1
  62. package/dist/rsa/index.min.cjs.map +3 -3
  63. package/dist/rsa/index.min.js +2 -2
  64. package/dist/rsa/index.min.js.map +4 -4
  65. package/dist/util.cjs +7 -7
  66. package/dist/util.cjs.map +2 -2
  67. package/dist/util.d.ts.map +1 -1
  68. package/dist/util.js +1 -1
  69. package/dist/util.js.map +2 -2
  70. package/dist/util.min.cjs +1 -1
  71. package/dist/util.min.cjs.map +3 -3
  72. package/dist/util.min.js +1 -1
  73. package/dist/util.min.js.map +4 -4
  74. package/package.json +3 -4
@@ -1,2323 +1,11 @@
1
1
  "use strict";
2
2
  (() => {
3
- var __create = Object.create;
4
3
  var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
4
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
11
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
12
- }) : x)(function(x) {
13
- if (typeof require !== "undefined") return require.apply(this, arguments);
14
- throw Error('Dynamic require of "' + x + '" is not supported');
15
- });
16
- var __commonJS = (cb, mod) => function __require2() {
17
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
18
- };
19
5
  var __export = (target, all) => {
20
6
  for (var name2 in all)
21
7
  __defProp(target, name2, { get: all[name2], enumerable: true });
22
8
  };
23
- var __copyProps = (to, from3, except, desc) => {
24
- if (from3 && typeof from3 === "object" || typeof from3 === "function") {
25
- for (let key of __getOwnPropNames(from3))
26
- if (!__hasOwnProp.call(to, key) && key !== except)
27
- __defProp(to, key, { get: () => from3[key], enumerable: !(desc = __getOwnPropDesc(from3, key)) || desc.enumerable });
28
- }
29
- return to;
30
- };
31
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
32
- // If the importer is in node compatibility mode or this is not an ESM
33
- // file that has been converted to a CommonJS file using a Babel-
34
- // compatible transform (i.e. "__esModule" has not been set), then set
35
- // "default" to the CommonJS "module.exports" for node compatibility.
36
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
37
- mod
38
- ));
39
-
40
- // (disabled):crypto
41
- var require_crypto = __commonJS({
42
- "(disabled):crypto"() {
43
- }
44
- });
45
-
46
- // node_modules/tweetnacl/nacl-fast.js
47
- var require_nacl_fast = __commonJS({
48
- "node_modules/tweetnacl/nacl-fast.js"(exports, module) {
49
- (function(nacl) {
50
- "use strict";
51
- var gf = /* @__PURE__ */ __name(function(init) {
52
- var i, r = new Float64Array(16);
53
- if (init) for (i = 0; i < init.length; i++) r[i] = init[i];
54
- return r;
55
- }, "gf");
56
- var randombytes = /* @__PURE__ */ __name(function() {
57
- throw new Error("no PRNG");
58
- }, "randombytes");
59
- var _0 = new Uint8Array(16);
60
- var _9 = new Uint8Array(32);
61
- _9[0] = 9;
62
- var gf0 = gf(), gf1 = gf([1]), _121665 = gf([56129, 1]), D = gf([30883, 4953, 19914, 30187, 55467, 16705, 2637, 112, 59544, 30585, 16505, 36039, 65139, 11119, 27886, 20995]), D2 = gf([61785, 9906, 39828, 60374, 45398, 33411, 5274, 224, 53552, 61171, 33010, 6542, 64743, 22239, 55772, 9222]), X = gf([54554, 36645, 11616, 51542, 42930, 38181, 51040, 26924, 56412, 64982, 57905, 49316, 21502, 52590, 14035, 8553]), Y = gf([26200, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214, 26214]), I = gf([41136, 18958, 6951, 50414, 58488, 44335, 6150, 12099, 55207, 15867, 153, 11085, 57099, 20417, 9344, 11139]);
63
- function ts64(x, i, h, l) {
64
- x[i] = h >> 24 & 255;
65
- x[i + 1] = h >> 16 & 255;
66
- x[i + 2] = h >> 8 & 255;
67
- x[i + 3] = h & 255;
68
- x[i + 4] = l >> 24 & 255;
69
- x[i + 5] = l >> 16 & 255;
70
- x[i + 6] = l >> 8 & 255;
71
- x[i + 7] = l & 255;
72
- }
73
- __name(ts64, "ts64");
74
- function vn(x, xi, y, yi, n) {
75
- var i, d = 0;
76
- for (i = 0; i < n; i++) d |= x[xi + i] ^ y[yi + i];
77
- return (1 & d - 1 >>> 8) - 1;
78
- }
79
- __name(vn, "vn");
80
- function crypto_verify_16(x, xi, y, yi) {
81
- return vn(x, xi, y, yi, 16);
82
- }
83
- __name(crypto_verify_16, "crypto_verify_16");
84
- function crypto_verify_32(x, xi, y, yi) {
85
- return vn(x, xi, y, yi, 32);
86
- }
87
- __name(crypto_verify_32, "crypto_verify_32");
88
- function core_salsa20(o, p, k, c) {
89
- var j0 = c[0] & 255 | (c[1] & 255) << 8 | (c[2] & 255) << 16 | (c[3] & 255) << 24, j1 = k[0] & 255 | (k[1] & 255) << 8 | (k[2] & 255) << 16 | (k[3] & 255) << 24, j2 = k[4] & 255 | (k[5] & 255) << 8 | (k[6] & 255) << 16 | (k[7] & 255) << 24, j3 = k[8] & 255 | (k[9] & 255) << 8 | (k[10] & 255) << 16 | (k[11] & 255) << 24, j4 = k[12] & 255 | (k[13] & 255) << 8 | (k[14] & 255) << 16 | (k[15] & 255) << 24, j5 = c[4] & 255 | (c[5] & 255) << 8 | (c[6] & 255) << 16 | (c[7] & 255) << 24, j6 = p[0] & 255 | (p[1] & 255) << 8 | (p[2] & 255) << 16 | (p[3] & 255) << 24, j7 = p[4] & 255 | (p[5] & 255) << 8 | (p[6] & 255) << 16 | (p[7] & 255) << 24, j8 = p[8] & 255 | (p[9] & 255) << 8 | (p[10] & 255) << 16 | (p[11] & 255) << 24, j9 = p[12] & 255 | (p[13] & 255) << 8 | (p[14] & 255) << 16 | (p[15] & 255) << 24, j10 = c[8] & 255 | (c[9] & 255) << 8 | (c[10] & 255) << 16 | (c[11] & 255) << 24, j11 = k[16] & 255 | (k[17] & 255) << 8 | (k[18] & 255) << 16 | (k[19] & 255) << 24, j12 = k[20] & 255 | (k[21] & 255) << 8 | (k[22] & 255) << 16 | (k[23] & 255) << 24, j13 = k[24] & 255 | (k[25] & 255) << 8 | (k[26] & 255) << 16 | (k[27] & 255) << 24, j14 = k[28] & 255 | (k[29] & 255) << 8 | (k[30] & 255) << 16 | (k[31] & 255) << 24, j15 = c[12] & 255 | (c[13] & 255) << 8 | (c[14] & 255) << 16 | (c[15] & 255) << 24;
90
- var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, x15 = j15, u;
91
- for (var i = 0; i < 20; i += 2) {
92
- u = x0 + x12 | 0;
93
- x4 ^= u << 7 | u >>> 32 - 7;
94
- u = x4 + x0 | 0;
95
- x8 ^= u << 9 | u >>> 32 - 9;
96
- u = x8 + x4 | 0;
97
- x12 ^= u << 13 | u >>> 32 - 13;
98
- u = x12 + x8 | 0;
99
- x0 ^= u << 18 | u >>> 32 - 18;
100
- u = x5 + x1 | 0;
101
- x9 ^= u << 7 | u >>> 32 - 7;
102
- u = x9 + x5 | 0;
103
- x13 ^= u << 9 | u >>> 32 - 9;
104
- u = x13 + x9 | 0;
105
- x1 ^= u << 13 | u >>> 32 - 13;
106
- u = x1 + x13 | 0;
107
- x5 ^= u << 18 | u >>> 32 - 18;
108
- u = x10 + x6 | 0;
109
- x14 ^= u << 7 | u >>> 32 - 7;
110
- u = x14 + x10 | 0;
111
- x2 ^= u << 9 | u >>> 32 - 9;
112
- u = x2 + x14 | 0;
113
- x6 ^= u << 13 | u >>> 32 - 13;
114
- u = x6 + x2 | 0;
115
- x10 ^= u << 18 | u >>> 32 - 18;
116
- u = x15 + x11 | 0;
117
- x3 ^= u << 7 | u >>> 32 - 7;
118
- u = x3 + x15 | 0;
119
- x7 ^= u << 9 | u >>> 32 - 9;
120
- u = x7 + x3 | 0;
121
- x11 ^= u << 13 | u >>> 32 - 13;
122
- u = x11 + x7 | 0;
123
- x15 ^= u << 18 | u >>> 32 - 18;
124
- u = x0 + x3 | 0;
125
- x1 ^= u << 7 | u >>> 32 - 7;
126
- u = x1 + x0 | 0;
127
- x2 ^= u << 9 | u >>> 32 - 9;
128
- u = x2 + x1 | 0;
129
- x3 ^= u << 13 | u >>> 32 - 13;
130
- u = x3 + x2 | 0;
131
- x0 ^= u << 18 | u >>> 32 - 18;
132
- u = x5 + x4 | 0;
133
- x6 ^= u << 7 | u >>> 32 - 7;
134
- u = x6 + x5 | 0;
135
- x7 ^= u << 9 | u >>> 32 - 9;
136
- u = x7 + x6 | 0;
137
- x4 ^= u << 13 | u >>> 32 - 13;
138
- u = x4 + x7 | 0;
139
- x5 ^= u << 18 | u >>> 32 - 18;
140
- u = x10 + x9 | 0;
141
- x11 ^= u << 7 | u >>> 32 - 7;
142
- u = x11 + x10 | 0;
143
- x8 ^= u << 9 | u >>> 32 - 9;
144
- u = x8 + x11 | 0;
145
- x9 ^= u << 13 | u >>> 32 - 13;
146
- u = x9 + x8 | 0;
147
- x10 ^= u << 18 | u >>> 32 - 18;
148
- u = x15 + x14 | 0;
149
- x12 ^= u << 7 | u >>> 32 - 7;
150
- u = x12 + x15 | 0;
151
- x13 ^= u << 9 | u >>> 32 - 9;
152
- u = x13 + x12 | 0;
153
- x14 ^= u << 13 | u >>> 32 - 13;
154
- u = x14 + x13 | 0;
155
- x15 ^= u << 18 | u >>> 32 - 18;
156
- }
157
- x0 = x0 + j0 | 0;
158
- x1 = x1 + j1 | 0;
159
- x2 = x2 + j2 | 0;
160
- x3 = x3 + j3 | 0;
161
- x4 = x4 + j4 | 0;
162
- x5 = x5 + j5 | 0;
163
- x6 = x6 + j6 | 0;
164
- x7 = x7 + j7 | 0;
165
- x8 = x8 + j8 | 0;
166
- x9 = x9 + j9 | 0;
167
- x10 = x10 + j10 | 0;
168
- x11 = x11 + j11 | 0;
169
- x12 = x12 + j12 | 0;
170
- x13 = x13 + j13 | 0;
171
- x14 = x14 + j14 | 0;
172
- x15 = x15 + j15 | 0;
173
- o[0] = x0 >>> 0 & 255;
174
- o[1] = x0 >>> 8 & 255;
175
- o[2] = x0 >>> 16 & 255;
176
- o[3] = x0 >>> 24 & 255;
177
- o[4] = x1 >>> 0 & 255;
178
- o[5] = x1 >>> 8 & 255;
179
- o[6] = x1 >>> 16 & 255;
180
- o[7] = x1 >>> 24 & 255;
181
- o[8] = x2 >>> 0 & 255;
182
- o[9] = x2 >>> 8 & 255;
183
- o[10] = x2 >>> 16 & 255;
184
- o[11] = x2 >>> 24 & 255;
185
- o[12] = x3 >>> 0 & 255;
186
- o[13] = x3 >>> 8 & 255;
187
- o[14] = x3 >>> 16 & 255;
188
- o[15] = x3 >>> 24 & 255;
189
- o[16] = x4 >>> 0 & 255;
190
- o[17] = x4 >>> 8 & 255;
191
- o[18] = x4 >>> 16 & 255;
192
- o[19] = x4 >>> 24 & 255;
193
- o[20] = x5 >>> 0 & 255;
194
- o[21] = x5 >>> 8 & 255;
195
- o[22] = x5 >>> 16 & 255;
196
- o[23] = x5 >>> 24 & 255;
197
- o[24] = x6 >>> 0 & 255;
198
- o[25] = x6 >>> 8 & 255;
199
- o[26] = x6 >>> 16 & 255;
200
- o[27] = x6 >>> 24 & 255;
201
- o[28] = x7 >>> 0 & 255;
202
- o[29] = x7 >>> 8 & 255;
203
- o[30] = x7 >>> 16 & 255;
204
- o[31] = x7 >>> 24 & 255;
205
- o[32] = x8 >>> 0 & 255;
206
- o[33] = x8 >>> 8 & 255;
207
- o[34] = x8 >>> 16 & 255;
208
- o[35] = x8 >>> 24 & 255;
209
- o[36] = x9 >>> 0 & 255;
210
- o[37] = x9 >>> 8 & 255;
211
- o[38] = x9 >>> 16 & 255;
212
- o[39] = x9 >>> 24 & 255;
213
- o[40] = x10 >>> 0 & 255;
214
- o[41] = x10 >>> 8 & 255;
215
- o[42] = x10 >>> 16 & 255;
216
- o[43] = x10 >>> 24 & 255;
217
- o[44] = x11 >>> 0 & 255;
218
- o[45] = x11 >>> 8 & 255;
219
- o[46] = x11 >>> 16 & 255;
220
- o[47] = x11 >>> 24 & 255;
221
- o[48] = x12 >>> 0 & 255;
222
- o[49] = x12 >>> 8 & 255;
223
- o[50] = x12 >>> 16 & 255;
224
- o[51] = x12 >>> 24 & 255;
225
- o[52] = x13 >>> 0 & 255;
226
- o[53] = x13 >>> 8 & 255;
227
- o[54] = x13 >>> 16 & 255;
228
- o[55] = x13 >>> 24 & 255;
229
- o[56] = x14 >>> 0 & 255;
230
- o[57] = x14 >>> 8 & 255;
231
- o[58] = x14 >>> 16 & 255;
232
- o[59] = x14 >>> 24 & 255;
233
- o[60] = x15 >>> 0 & 255;
234
- o[61] = x15 >>> 8 & 255;
235
- o[62] = x15 >>> 16 & 255;
236
- o[63] = x15 >>> 24 & 255;
237
- }
238
- __name(core_salsa20, "core_salsa20");
239
- function core_hsalsa20(o, p, k, c) {
240
- var j0 = c[0] & 255 | (c[1] & 255) << 8 | (c[2] & 255) << 16 | (c[3] & 255) << 24, j1 = k[0] & 255 | (k[1] & 255) << 8 | (k[2] & 255) << 16 | (k[3] & 255) << 24, j2 = k[4] & 255 | (k[5] & 255) << 8 | (k[6] & 255) << 16 | (k[7] & 255) << 24, j3 = k[8] & 255 | (k[9] & 255) << 8 | (k[10] & 255) << 16 | (k[11] & 255) << 24, j4 = k[12] & 255 | (k[13] & 255) << 8 | (k[14] & 255) << 16 | (k[15] & 255) << 24, j5 = c[4] & 255 | (c[5] & 255) << 8 | (c[6] & 255) << 16 | (c[7] & 255) << 24, j6 = p[0] & 255 | (p[1] & 255) << 8 | (p[2] & 255) << 16 | (p[3] & 255) << 24, j7 = p[4] & 255 | (p[5] & 255) << 8 | (p[6] & 255) << 16 | (p[7] & 255) << 24, j8 = p[8] & 255 | (p[9] & 255) << 8 | (p[10] & 255) << 16 | (p[11] & 255) << 24, j9 = p[12] & 255 | (p[13] & 255) << 8 | (p[14] & 255) << 16 | (p[15] & 255) << 24, j10 = c[8] & 255 | (c[9] & 255) << 8 | (c[10] & 255) << 16 | (c[11] & 255) << 24, j11 = k[16] & 255 | (k[17] & 255) << 8 | (k[18] & 255) << 16 | (k[19] & 255) << 24, j12 = k[20] & 255 | (k[21] & 255) << 8 | (k[22] & 255) << 16 | (k[23] & 255) << 24, j13 = k[24] & 255 | (k[25] & 255) << 8 | (k[26] & 255) << 16 | (k[27] & 255) << 24, j14 = k[28] & 255 | (k[29] & 255) << 8 | (k[30] & 255) << 16 | (k[31] & 255) << 24, j15 = c[12] & 255 | (c[13] & 255) << 8 | (c[14] & 255) << 16 | (c[15] & 255) << 24;
241
- var x0 = j0, x1 = j1, x2 = j2, x3 = j3, x4 = j4, x5 = j5, x6 = j6, x7 = j7, x8 = j8, x9 = j9, x10 = j10, x11 = j11, x12 = j12, x13 = j13, x14 = j14, x15 = j15, u;
242
- for (var i = 0; i < 20; i += 2) {
243
- u = x0 + x12 | 0;
244
- x4 ^= u << 7 | u >>> 32 - 7;
245
- u = x4 + x0 | 0;
246
- x8 ^= u << 9 | u >>> 32 - 9;
247
- u = x8 + x4 | 0;
248
- x12 ^= u << 13 | u >>> 32 - 13;
249
- u = x12 + x8 | 0;
250
- x0 ^= u << 18 | u >>> 32 - 18;
251
- u = x5 + x1 | 0;
252
- x9 ^= u << 7 | u >>> 32 - 7;
253
- u = x9 + x5 | 0;
254
- x13 ^= u << 9 | u >>> 32 - 9;
255
- u = x13 + x9 | 0;
256
- x1 ^= u << 13 | u >>> 32 - 13;
257
- u = x1 + x13 | 0;
258
- x5 ^= u << 18 | u >>> 32 - 18;
259
- u = x10 + x6 | 0;
260
- x14 ^= u << 7 | u >>> 32 - 7;
261
- u = x14 + x10 | 0;
262
- x2 ^= u << 9 | u >>> 32 - 9;
263
- u = x2 + x14 | 0;
264
- x6 ^= u << 13 | u >>> 32 - 13;
265
- u = x6 + x2 | 0;
266
- x10 ^= u << 18 | u >>> 32 - 18;
267
- u = x15 + x11 | 0;
268
- x3 ^= u << 7 | u >>> 32 - 7;
269
- u = x3 + x15 | 0;
270
- x7 ^= u << 9 | u >>> 32 - 9;
271
- u = x7 + x3 | 0;
272
- x11 ^= u << 13 | u >>> 32 - 13;
273
- u = x11 + x7 | 0;
274
- x15 ^= u << 18 | u >>> 32 - 18;
275
- u = x0 + x3 | 0;
276
- x1 ^= u << 7 | u >>> 32 - 7;
277
- u = x1 + x0 | 0;
278
- x2 ^= u << 9 | u >>> 32 - 9;
279
- u = x2 + x1 | 0;
280
- x3 ^= u << 13 | u >>> 32 - 13;
281
- u = x3 + x2 | 0;
282
- x0 ^= u << 18 | u >>> 32 - 18;
283
- u = x5 + x4 | 0;
284
- x6 ^= u << 7 | u >>> 32 - 7;
285
- u = x6 + x5 | 0;
286
- x7 ^= u << 9 | u >>> 32 - 9;
287
- u = x7 + x6 | 0;
288
- x4 ^= u << 13 | u >>> 32 - 13;
289
- u = x4 + x7 | 0;
290
- x5 ^= u << 18 | u >>> 32 - 18;
291
- u = x10 + x9 | 0;
292
- x11 ^= u << 7 | u >>> 32 - 7;
293
- u = x11 + x10 | 0;
294
- x8 ^= u << 9 | u >>> 32 - 9;
295
- u = x8 + x11 | 0;
296
- x9 ^= u << 13 | u >>> 32 - 13;
297
- u = x9 + x8 | 0;
298
- x10 ^= u << 18 | u >>> 32 - 18;
299
- u = x15 + x14 | 0;
300
- x12 ^= u << 7 | u >>> 32 - 7;
301
- u = x12 + x15 | 0;
302
- x13 ^= u << 9 | u >>> 32 - 9;
303
- u = x13 + x12 | 0;
304
- x14 ^= u << 13 | u >>> 32 - 13;
305
- u = x14 + x13 | 0;
306
- x15 ^= u << 18 | u >>> 32 - 18;
307
- }
308
- o[0] = x0 >>> 0 & 255;
309
- o[1] = x0 >>> 8 & 255;
310
- o[2] = x0 >>> 16 & 255;
311
- o[3] = x0 >>> 24 & 255;
312
- o[4] = x5 >>> 0 & 255;
313
- o[5] = x5 >>> 8 & 255;
314
- o[6] = x5 >>> 16 & 255;
315
- o[7] = x5 >>> 24 & 255;
316
- o[8] = x10 >>> 0 & 255;
317
- o[9] = x10 >>> 8 & 255;
318
- o[10] = x10 >>> 16 & 255;
319
- o[11] = x10 >>> 24 & 255;
320
- o[12] = x15 >>> 0 & 255;
321
- o[13] = x15 >>> 8 & 255;
322
- o[14] = x15 >>> 16 & 255;
323
- o[15] = x15 >>> 24 & 255;
324
- o[16] = x6 >>> 0 & 255;
325
- o[17] = x6 >>> 8 & 255;
326
- o[18] = x6 >>> 16 & 255;
327
- o[19] = x6 >>> 24 & 255;
328
- o[20] = x7 >>> 0 & 255;
329
- o[21] = x7 >>> 8 & 255;
330
- o[22] = x7 >>> 16 & 255;
331
- o[23] = x7 >>> 24 & 255;
332
- o[24] = x8 >>> 0 & 255;
333
- o[25] = x8 >>> 8 & 255;
334
- o[26] = x8 >>> 16 & 255;
335
- o[27] = x8 >>> 24 & 255;
336
- o[28] = x9 >>> 0 & 255;
337
- o[29] = x9 >>> 8 & 255;
338
- o[30] = x9 >>> 16 & 255;
339
- o[31] = x9 >>> 24 & 255;
340
- }
341
- __name(core_hsalsa20, "core_hsalsa20");
342
- function crypto_core_salsa20(out, inp, k, c) {
343
- core_salsa20(out, inp, k, c);
344
- }
345
- __name(crypto_core_salsa20, "crypto_core_salsa20");
346
- function crypto_core_hsalsa20(out, inp, k, c) {
347
- core_hsalsa20(out, inp, k, c);
348
- }
349
- __name(crypto_core_hsalsa20, "crypto_core_hsalsa20");
350
- var sigma = new Uint8Array([101, 120, 112, 97, 110, 100, 32, 51, 50, 45, 98, 121, 116, 101, 32, 107]);
351
- function crypto_stream_salsa20_xor(c, cpos, m, mpos, b, n, k) {
352
- var z = new Uint8Array(16), x = new Uint8Array(64);
353
- var u, i;
354
- for (i = 0; i < 16; i++) z[i] = 0;
355
- for (i = 0; i < 8; i++) z[i] = n[i];
356
- while (b >= 64) {
357
- crypto_core_salsa20(x, z, k, sigma);
358
- for (i = 0; i < 64; i++) c[cpos + i] = m[mpos + i] ^ x[i];
359
- u = 1;
360
- for (i = 8; i < 16; i++) {
361
- u = u + (z[i] & 255) | 0;
362
- z[i] = u & 255;
363
- u >>>= 8;
364
- }
365
- b -= 64;
366
- cpos += 64;
367
- mpos += 64;
368
- }
369
- if (b > 0) {
370
- crypto_core_salsa20(x, z, k, sigma);
371
- for (i = 0; i < b; i++) c[cpos + i] = m[mpos + i] ^ x[i];
372
- }
373
- return 0;
374
- }
375
- __name(crypto_stream_salsa20_xor, "crypto_stream_salsa20_xor");
376
- function crypto_stream_salsa20(c, cpos, b, n, k) {
377
- var z = new Uint8Array(16), x = new Uint8Array(64);
378
- var u, i;
379
- for (i = 0; i < 16; i++) z[i] = 0;
380
- for (i = 0; i < 8; i++) z[i] = n[i];
381
- while (b >= 64) {
382
- crypto_core_salsa20(x, z, k, sigma);
383
- for (i = 0; i < 64; i++) c[cpos + i] = x[i];
384
- u = 1;
385
- for (i = 8; i < 16; i++) {
386
- u = u + (z[i] & 255) | 0;
387
- z[i] = u & 255;
388
- u >>>= 8;
389
- }
390
- b -= 64;
391
- cpos += 64;
392
- }
393
- if (b > 0) {
394
- crypto_core_salsa20(x, z, k, sigma);
395
- for (i = 0; i < b; i++) c[cpos + i] = x[i];
396
- }
397
- return 0;
398
- }
399
- __name(crypto_stream_salsa20, "crypto_stream_salsa20");
400
- function crypto_stream(c, cpos, d, n, k) {
401
- var s = new Uint8Array(32);
402
- crypto_core_hsalsa20(s, n, k, sigma);
403
- var sn = new Uint8Array(8);
404
- for (var i = 0; i < 8; i++) sn[i] = n[i + 16];
405
- return crypto_stream_salsa20(c, cpos, d, sn, s);
406
- }
407
- __name(crypto_stream, "crypto_stream");
408
- function crypto_stream_xor(c, cpos, m, mpos, d, n, k) {
409
- var s = new Uint8Array(32);
410
- crypto_core_hsalsa20(s, n, k, sigma);
411
- var sn = new Uint8Array(8);
412
- for (var i = 0; i < 8; i++) sn[i] = n[i + 16];
413
- return crypto_stream_salsa20_xor(c, cpos, m, mpos, d, sn, s);
414
- }
415
- __name(crypto_stream_xor, "crypto_stream_xor");
416
- var poly1305 = /* @__PURE__ */ __name(function(key) {
417
- this.buffer = new Uint8Array(16);
418
- this.r = new Uint16Array(10);
419
- this.h = new Uint16Array(10);
420
- this.pad = new Uint16Array(8);
421
- this.leftover = 0;
422
- this.fin = 0;
423
- var t0, t1, t2, t3, t4, t5, t6, t7;
424
- t0 = key[0] & 255 | (key[1] & 255) << 8;
425
- this.r[0] = t0 & 8191;
426
- t1 = key[2] & 255 | (key[3] & 255) << 8;
427
- this.r[1] = (t0 >>> 13 | t1 << 3) & 8191;
428
- t2 = key[4] & 255 | (key[5] & 255) << 8;
429
- this.r[2] = (t1 >>> 10 | t2 << 6) & 7939;
430
- t3 = key[6] & 255 | (key[7] & 255) << 8;
431
- this.r[3] = (t2 >>> 7 | t3 << 9) & 8191;
432
- t4 = key[8] & 255 | (key[9] & 255) << 8;
433
- this.r[4] = (t3 >>> 4 | t4 << 12) & 255;
434
- this.r[5] = t4 >>> 1 & 8190;
435
- t5 = key[10] & 255 | (key[11] & 255) << 8;
436
- this.r[6] = (t4 >>> 14 | t5 << 2) & 8191;
437
- t6 = key[12] & 255 | (key[13] & 255) << 8;
438
- this.r[7] = (t5 >>> 11 | t6 << 5) & 8065;
439
- t7 = key[14] & 255 | (key[15] & 255) << 8;
440
- this.r[8] = (t6 >>> 8 | t7 << 8) & 8191;
441
- this.r[9] = t7 >>> 5 & 127;
442
- this.pad[0] = key[16] & 255 | (key[17] & 255) << 8;
443
- this.pad[1] = key[18] & 255 | (key[19] & 255) << 8;
444
- this.pad[2] = key[20] & 255 | (key[21] & 255) << 8;
445
- this.pad[3] = key[22] & 255 | (key[23] & 255) << 8;
446
- this.pad[4] = key[24] & 255 | (key[25] & 255) << 8;
447
- this.pad[5] = key[26] & 255 | (key[27] & 255) << 8;
448
- this.pad[6] = key[28] & 255 | (key[29] & 255) << 8;
449
- this.pad[7] = key[30] & 255 | (key[31] & 255) << 8;
450
- }, "poly1305");
451
- poly1305.prototype.blocks = function(m, mpos, bytes) {
452
- var hibit = this.fin ? 0 : 1 << 11;
453
- var t0, t1, t2, t3, t4, t5, t6, t7, c;
454
- var d0, d1, d2, d3, d4, d5, d6, d7, d8, d9;
455
- var h0 = this.h[0], h1 = this.h[1], h2 = this.h[2], h3 = this.h[3], h4 = this.h[4], h5 = this.h[5], h6 = this.h[6], h7 = this.h[7], h8 = this.h[8], h9 = this.h[9];
456
- var r0 = this.r[0], r1 = this.r[1], r2 = this.r[2], r3 = this.r[3], r4 = this.r[4], r5 = this.r[5], r6 = this.r[6], r7 = this.r[7], r8 = this.r[8], r9 = this.r[9];
457
- while (bytes >= 16) {
458
- t0 = m[mpos + 0] & 255 | (m[mpos + 1] & 255) << 8;
459
- h0 += t0 & 8191;
460
- t1 = m[mpos + 2] & 255 | (m[mpos + 3] & 255) << 8;
461
- h1 += (t0 >>> 13 | t1 << 3) & 8191;
462
- t2 = m[mpos + 4] & 255 | (m[mpos + 5] & 255) << 8;
463
- h2 += (t1 >>> 10 | t2 << 6) & 8191;
464
- t3 = m[mpos + 6] & 255 | (m[mpos + 7] & 255) << 8;
465
- h3 += (t2 >>> 7 | t3 << 9) & 8191;
466
- t4 = m[mpos + 8] & 255 | (m[mpos + 9] & 255) << 8;
467
- h4 += (t3 >>> 4 | t4 << 12) & 8191;
468
- h5 += t4 >>> 1 & 8191;
469
- t5 = m[mpos + 10] & 255 | (m[mpos + 11] & 255) << 8;
470
- h6 += (t4 >>> 14 | t5 << 2) & 8191;
471
- t6 = m[mpos + 12] & 255 | (m[mpos + 13] & 255) << 8;
472
- h7 += (t5 >>> 11 | t6 << 5) & 8191;
473
- t7 = m[mpos + 14] & 255 | (m[mpos + 15] & 255) << 8;
474
- h8 += (t6 >>> 8 | t7 << 8) & 8191;
475
- h9 += t7 >>> 5 | hibit;
476
- c = 0;
477
- d0 = c;
478
- d0 += h0 * r0;
479
- d0 += h1 * (5 * r9);
480
- d0 += h2 * (5 * r8);
481
- d0 += h3 * (5 * r7);
482
- d0 += h4 * (5 * r6);
483
- c = d0 >>> 13;
484
- d0 &= 8191;
485
- d0 += h5 * (5 * r5);
486
- d0 += h6 * (5 * r4);
487
- d0 += h7 * (5 * r3);
488
- d0 += h8 * (5 * r2);
489
- d0 += h9 * (5 * r1);
490
- c += d0 >>> 13;
491
- d0 &= 8191;
492
- d1 = c;
493
- d1 += h0 * r1;
494
- d1 += h1 * r0;
495
- d1 += h2 * (5 * r9);
496
- d1 += h3 * (5 * r8);
497
- d1 += h4 * (5 * r7);
498
- c = d1 >>> 13;
499
- d1 &= 8191;
500
- d1 += h5 * (5 * r6);
501
- d1 += h6 * (5 * r5);
502
- d1 += h7 * (5 * r4);
503
- d1 += h8 * (5 * r3);
504
- d1 += h9 * (5 * r2);
505
- c += d1 >>> 13;
506
- d1 &= 8191;
507
- d2 = c;
508
- d2 += h0 * r2;
509
- d2 += h1 * r1;
510
- d2 += h2 * r0;
511
- d2 += h3 * (5 * r9);
512
- d2 += h4 * (5 * r8);
513
- c = d2 >>> 13;
514
- d2 &= 8191;
515
- d2 += h5 * (5 * r7);
516
- d2 += h6 * (5 * r6);
517
- d2 += h7 * (5 * r5);
518
- d2 += h8 * (5 * r4);
519
- d2 += h9 * (5 * r3);
520
- c += d2 >>> 13;
521
- d2 &= 8191;
522
- d3 = c;
523
- d3 += h0 * r3;
524
- d3 += h1 * r2;
525
- d3 += h2 * r1;
526
- d3 += h3 * r0;
527
- d3 += h4 * (5 * r9);
528
- c = d3 >>> 13;
529
- d3 &= 8191;
530
- d3 += h5 * (5 * r8);
531
- d3 += h6 * (5 * r7);
532
- d3 += h7 * (5 * r6);
533
- d3 += h8 * (5 * r5);
534
- d3 += h9 * (5 * r4);
535
- c += d3 >>> 13;
536
- d3 &= 8191;
537
- d4 = c;
538
- d4 += h0 * r4;
539
- d4 += h1 * r3;
540
- d4 += h2 * r2;
541
- d4 += h3 * r1;
542
- d4 += h4 * r0;
543
- c = d4 >>> 13;
544
- d4 &= 8191;
545
- d4 += h5 * (5 * r9);
546
- d4 += h6 * (5 * r8);
547
- d4 += h7 * (5 * r7);
548
- d4 += h8 * (5 * r6);
549
- d4 += h9 * (5 * r5);
550
- c += d4 >>> 13;
551
- d4 &= 8191;
552
- d5 = c;
553
- d5 += h0 * r5;
554
- d5 += h1 * r4;
555
- d5 += h2 * r3;
556
- d5 += h3 * r2;
557
- d5 += h4 * r1;
558
- c = d5 >>> 13;
559
- d5 &= 8191;
560
- d5 += h5 * r0;
561
- d5 += h6 * (5 * r9);
562
- d5 += h7 * (5 * r8);
563
- d5 += h8 * (5 * r7);
564
- d5 += h9 * (5 * r6);
565
- c += d5 >>> 13;
566
- d5 &= 8191;
567
- d6 = c;
568
- d6 += h0 * r6;
569
- d6 += h1 * r5;
570
- d6 += h2 * r4;
571
- d6 += h3 * r3;
572
- d6 += h4 * r2;
573
- c = d6 >>> 13;
574
- d6 &= 8191;
575
- d6 += h5 * r1;
576
- d6 += h6 * r0;
577
- d6 += h7 * (5 * r9);
578
- d6 += h8 * (5 * r8);
579
- d6 += h9 * (5 * r7);
580
- c += d6 >>> 13;
581
- d6 &= 8191;
582
- d7 = c;
583
- d7 += h0 * r7;
584
- d7 += h1 * r6;
585
- d7 += h2 * r5;
586
- d7 += h3 * r4;
587
- d7 += h4 * r3;
588
- c = d7 >>> 13;
589
- d7 &= 8191;
590
- d7 += h5 * r2;
591
- d7 += h6 * r1;
592
- d7 += h7 * r0;
593
- d7 += h8 * (5 * r9);
594
- d7 += h9 * (5 * r8);
595
- c += d7 >>> 13;
596
- d7 &= 8191;
597
- d8 = c;
598
- d8 += h0 * r8;
599
- d8 += h1 * r7;
600
- d8 += h2 * r6;
601
- d8 += h3 * r5;
602
- d8 += h4 * r4;
603
- c = d8 >>> 13;
604
- d8 &= 8191;
605
- d8 += h5 * r3;
606
- d8 += h6 * r2;
607
- d8 += h7 * r1;
608
- d8 += h8 * r0;
609
- d8 += h9 * (5 * r9);
610
- c += d8 >>> 13;
611
- d8 &= 8191;
612
- d9 = c;
613
- d9 += h0 * r9;
614
- d9 += h1 * r8;
615
- d9 += h2 * r7;
616
- d9 += h3 * r6;
617
- d9 += h4 * r5;
618
- c = d9 >>> 13;
619
- d9 &= 8191;
620
- d9 += h5 * r4;
621
- d9 += h6 * r3;
622
- d9 += h7 * r2;
623
- d9 += h8 * r1;
624
- d9 += h9 * r0;
625
- c += d9 >>> 13;
626
- d9 &= 8191;
627
- c = (c << 2) + c | 0;
628
- c = c + d0 | 0;
629
- d0 = c & 8191;
630
- c = c >>> 13;
631
- d1 += c;
632
- h0 = d0;
633
- h1 = d1;
634
- h2 = d2;
635
- h3 = d3;
636
- h4 = d4;
637
- h5 = d5;
638
- h6 = d6;
639
- h7 = d7;
640
- h8 = d8;
641
- h9 = d9;
642
- mpos += 16;
643
- bytes -= 16;
644
- }
645
- this.h[0] = h0;
646
- this.h[1] = h1;
647
- this.h[2] = h2;
648
- this.h[3] = h3;
649
- this.h[4] = h4;
650
- this.h[5] = h5;
651
- this.h[6] = h6;
652
- this.h[7] = h7;
653
- this.h[8] = h8;
654
- this.h[9] = h9;
655
- };
656
- poly1305.prototype.finish = function(mac, macpos) {
657
- var g = new Uint16Array(10);
658
- var c, mask, f, i;
659
- if (this.leftover) {
660
- i = this.leftover;
661
- this.buffer[i++] = 1;
662
- for (; i < 16; i++) this.buffer[i] = 0;
663
- this.fin = 1;
664
- this.blocks(this.buffer, 0, 16);
665
- }
666
- c = this.h[1] >>> 13;
667
- this.h[1] &= 8191;
668
- for (i = 2; i < 10; i++) {
669
- this.h[i] += c;
670
- c = this.h[i] >>> 13;
671
- this.h[i] &= 8191;
672
- }
673
- this.h[0] += c * 5;
674
- c = this.h[0] >>> 13;
675
- this.h[0] &= 8191;
676
- this.h[1] += c;
677
- c = this.h[1] >>> 13;
678
- this.h[1] &= 8191;
679
- this.h[2] += c;
680
- g[0] = this.h[0] + 5;
681
- c = g[0] >>> 13;
682
- g[0] &= 8191;
683
- for (i = 1; i < 10; i++) {
684
- g[i] = this.h[i] + c;
685
- c = g[i] >>> 13;
686
- g[i] &= 8191;
687
- }
688
- g[9] -= 1 << 13;
689
- mask = (c ^ 1) - 1;
690
- for (i = 0; i < 10; i++) g[i] &= mask;
691
- mask = ~mask;
692
- for (i = 0; i < 10; i++) this.h[i] = this.h[i] & mask | g[i];
693
- this.h[0] = (this.h[0] | this.h[1] << 13) & 65535;
694
- this.h[1] = (this.h[1] >>> 3 | this.h[2] << 10) & 65535;
695
- this.h[2] = (this.h[2] >>> 6 | this.h[3] << 7) & 65535;
696
- this.h[3] = (this.h[3] >>> 9 | this.h[4] << 4) & 65535;
697
- this.h[4] = (this.h[4] >>> 12 | this.h[5] << 1 | this.h[6] << 14) & 65535;
698
- this.h[5] = (this.h[6] >>> 2 | this.h[7] << 11) & 65535;
699
- this.h[6] = (this.h[7] >>> 5 | this.h[8] << 8) & 65535;
700
- this.h[7] = (this.h[8] >>> 8 | this.h[9] << 5) & 65535;
701
- f = this.h[0] + this.pad[0];
702
- this.h[0] = f & 65535;
703
- for (i = 1; i < 8; i++) {
704
- f = (this.h[i] + this.pad[i] | 0) + (f >>> 16) | 0;
705
- this.h[i] = f & 65535;
706
- }
707
- mac[macpos + 0] = this.h[0] >>> 0 & 255;
708
- mac[macpos + 1] = this.h[0] >>> 8 & 255;
709
- mac[macpos + 2] = this.h[1] >>> 0 & 255;
710
- mac[macpos + 3] = this.h[1] >>> 8 & 255;
711
- mac[macpos + 4] = this.h[2] >>> 0 & 255;
712
- mac[macpos + 5] = this.h[2] >>> 8 & 255;
713
- mac[macpos + 6] = this.h[3] >>> 0 & 255;
714
- mac[macpos + 7] = this.h[3] >>> 8 & 255;
715
- mac[macpos + 8] = this.h[4] >>> 0 & 255;
716
- mac[macpos + 9] = this.h[4] >>> 8 & 255;
717
- mac[macpos + 10] = this.h[5] >>> 0 & 255;
718
- mac[macpos + 11] = this.h[5] >>> 8 & 255;
719
- mac[macpos + 12] = this.h[6] >>> 0 & 255;
720
- mac[macpos + 13] = this.h[6] >>> 8 & 255;
721
- mac[macpos + 14] = this.h[7] >>> 0 & 255;
722
- mac[macpos + 15] = this.h[7] >>> 8 & 255;
723
- };
724
- poly1305.prototype.update = function(m, mpos, bytes) {
725
- var i, want;
726
- if (this.leftover) {
727
- want = 16 - this.leftover;
728
- if (want > bytes)
729
- want = bytes;
730
- for (i = 0; i < want; i++)
731
- this.buffer[this.leftover + i] = m[mpos + i];
732
- bytes -= want;
733
- mpos += want;
734
- this.leftover += want;
735
- if (this.leftover < 16)
736
- return;
737
- this.blocks(this.buffer, 0, 16);
738
- this.leftover = 0;
739
- }
740
- if (bytes >= 16) {
741
- want = bytes - bytes % 16;
742
- this.blocks(m, mpos, want);
743
- mpos += want;
744
- bytes -= want;
745
- }
746
- if (bytes) {
747
- for (i = 0; i < bytes; i++)
748
- this.buffer[this.leftover + i] = m[mpos + i];
749
- this.leftover += bytes;
750
- }
751
- };
752
- function crypto_onetimeauth(out, outpos, m, mpos, n, k) {
753
- var s = new poly1305(k);
754
- s.update(m, mpos, n);
755
- s.finish(out, outpos);
756
- return 0;
757
- }
758
- __name(crypto_onetimeauth, "crypto_onetimeauth");
759
- function crypto_onetimeauth_verify(h, hpos, m, mpos, n, k) {
760
- var x = new Uint8Array(16);
761
- crypto_onetimeauth(x, 0, m, mpos, n, k);
762
- return crypto_verify_16(h, hpos, x, 0);
763
- }
764
- __name(crypto_onetimeauth_verify, "crypto_onetimeauth_verify");
765
- function crypto_secretbox(c, m, d, n, k) {
766
- var i;
767
- if (d < 32) return -1;
768
- crypto_stream_xor(c, 0, m, 0, d, n, k);
769
- crypto_onetimeauth(c, 16, c, 32, d - 32, c);
770
- for (i = 0; i < 16; i++) c[i] = 0;
771
- return 0;
772
- }
773
- __name(crypto_secretbox, "crypto_secretbox");
774
- function crypto_secretbox_open(m, c, d, n, k) {
775
- var i;
776
- var x = new Uint8Array(32);
777
- if (d < 32) return -1;
778
- crypto_stream(x, 0, 32, n, k);
779
- if (crypto_onetimeauth_verify(c, 16, c, 32, d - 32, x) !== 0) return -1;
780
- crypto_stream_xor(m, 0, c, 0, d, n, k);
781
- for (i = 0; i < 32; i++) m[i] = 0;
782
- return 0;
783
- }
784
- __name(crypto_secretbox_open, "crypto_secretbox_open");
785
- function set25519(r, a) {
786
- var i;
787
- for (i = 0; i < 16; i++) r[i] = a[i] | 0;
788
- }
789
- __name(set25519, "set25519");
790
- function car25519(o) {
791
- var i, v, c = 1;
792
- for (i = 0; i < 16; i++) {
793
- v = o[i] + c + 65535;
794
- c = Math.floor(v / 65536);
795
- o[i] = v - c * 65536;
796
- }
797
- o[0] += c - 1 + 37 * (c - 1);
798
- }
799
- __name(car25519, "car25519");
800
- function sel25519(p, q, b) {
801
- var t, c = ~(b - 1);
802
- for (var i = 0; i < 16; i++) {
803
- t = c & (p[i] ^ q[i]);
804
- p[i] ^= t;
805
- q[i] ^= t;
806
- }
807
- }
808
- __name(sel25519, "sel25519");
809
- function pack25519(o, n) {
810
- var i, j, b;
811
- var m = gf(), t = gf();
812
- for (i = 0; i < 16; i++) t[i] = n[i];
813
- car25519(t);
814
- car25519(t);
815
- car25519(t);
816
- for (j = 0; j < 2; j++) {
817
- m[0] = t[0] - 65517;
818
- for (i = 1; i < 15; i++) {
819
- m[i] = t[i] - 65535 - (m[i - 1] >> 16 & 1);
820
- m[i - 1] &= 65535;
821
- }
822
- m[15] = t[15] - 32767 - (m[14] >> 16 & 1);
823
- b = m[15] >> 16 & 1;
824
- m[14] &= 65535;
825
- sel25519(t, m, 1 - b);
826
- }
827
- for (i = 0; i < 16; i++) {
828
- o[2 * i] = t[i] & 255;
829
- o[2 * i + 1] = t[i] >> 8;
830
- }
831
- }
832
- __name(pack25519, "pack25519");
833
- function neq25519(a, b) {
834
- var c = new Uint8Array(32), d = new Uint8Array(32);
835
- pack25519(c, a);
836
- pack25519(d, b);
837
- return crypto_verify_32(c, 0, d, 0);
838
- }
839
- __name(neq25519, "neq25519");
840
- function par25519(a) {
841
- var d = new Uint8Array(32);
842
- pack25519(d, a);
843
- return d[0] & 1;
844
- }
845
- __name(par25519, "par25519");
846
- function unpack25519(o, n) {
847
- var i;
848
- for (i = 0; i < 16; i++) o[i] = n[2 * i] + (n[2 * i + 1] << 8);
849
- o[15] &= 32767;
850
- }
851
- __name(unpack25519, "unpack25519");
852
- function A(o, a, b) {
853
- for (var i = 0; i < 16; i++) o[i] = a[i] + b[i];
854
- }
855
- __name(A, "A");
856
- function Z(o, a, b) {
857
- for (var i = 0; i < 16; i++) o[i] = a[i] - b[i];
858
- }
859
- __name(Z, "Z");
860
- function M(o, a, b) {
861
- var v, c, t0 = 0, t1 = 0, t2 = 0, t3 = 0, t4 = 0, t5 = 0, t6 = 0, t7 = 0, t8 = 0, t9 = 0, t10 = 0, t11 = 0, t12 = 0, t13 = 0, t14 = 0, t15 = 0, t16 = 0, t17 = 0, t18 = 0, t19 = 0, t20 = 0, t21 = 0, t22 = 0, t23 = 0, t24 = 0, t25 = 0, t26 = 0, t27 = 0, t28 = 0, t29 = 0, t30 = 0, b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4], b5 = b[5], b6 = b[6], b7 = b[7], b8 = b[8], b9 = b[9], b10 = b[10], b11 = b[11], b12 = b[12], b13 = b[13], b14 = b[14], b15 = b[15];
862
- v = a[0];
863
- t0 += v * b0;
864
- t1 += v * b1;
865
- t2 += v * b2;
866
- t3 += v * b3;
867
- t4 += v * b4;
868
- t5 += v * b5;
869
- t6 += v * b6;
870
- t7 += v * b7;
871
- t8 += v * b8;
872
- t9 += v * b9;
873
- t10 += v * b10;
874
- t11 += v * b11;
875
- t12 += v * b12;
876
- t13 += v * b13;
877
- t14 += v * b14;
878
- t15 += v * b15;
879
- v = a[1];
880
- t1 += v * b0;
881
- t2 += v * b1;
882
- t3 += v * b2;
883
- t4 += v * b3;
884
- t5 += v * b4;
885
- t6 += v * b5;
886
- t7 += v * b6;
887
- t8 += v * b7;
888
- t9 += v * b8;
889
- t10 += v * b9;
890
- t11 += v * b10;
891
- t12 += v * b11;
892
- t13 += v * b12;
893
- t14 += v * b13;
894
- t15 += v * b14;
895
- t16 += v * b15;
896
- v = a[2];
897
- t2 += v * b0;
898
- t3 += v * b1;
899
- t4 += v * b2;
900
- t5 += v * b3;
901
- t6 += v * b4;
902
- t7 += v * b5;
903
- t8 += v * b6;
904
- t9 += v * b7;
905
- t10 += v * b8;
906
- t11 += v * b9;
907
- t12 += v * b10;
908
- t13 += v * b11;
909
- t14 += v * b12;
910
- t15 += v * b13;
911
- t16 += v * b14;
912
- t17 += v * b15;
913
- v = a[3];
914
- t3 += v * b0;
915
- t4 += v * b1;
916
- t5 += v * b2;
917
- t6 += v * b3;
918
- t7 += v * b4;
919
- t8 += v * b5;
920
- t9 += v * b6;
921
- t10 += v * b7;
922
- t11 += v * b8;
923
- t12 += v * b9;
924
- t13 += v * b10;
925
- t14 += v * b11;
926
- t15 += v * b12;
927
- t16 += v * b13;
928
- t17 += v * b14;
929
- t18 += v * b15;
930
- v = a[4];
931
- t4 += v * b0;
932
- t5 += v * b1;
933
- t6 += v * b2;
934
- t7 += v * b3;
935
- t8 += v * b4;
936
- t9 += v * b5;
937
- t10 += v * b6;
938
- t11 += v * b7;
939
- t12 += v * b8;
940
- t13 += v * b9;
941
- t14 += v * b10;
942
- t15 += v * b11;
943
- t16 += v * b12;
944
- t17 += v * b13;
945
- t18 += v * b14;
946
- t19 += v * b15;
947
- v = a[5];
948
- t5 += v * b0;
949
- t6 += v * b1;
950
- t7 += v * b2;
951
- t8 += v * b3;
952
- t9 += v * b4;
953
- t10 += v * b5;
954
- t11 += v * b6;
955
- t12 += v * b7;
956
- t13 += v * b8;
957
- t14 += v * b9;
958
- t15 += v * b10;
959
- t16 += v * b11;
960
- t17 += v * b12;
961
- t18 += v * b13;
962
- t19 += v * b14;
963
- t20 += v * b15;
964
- v = a[6];
965
- t6 += v * b0;
966
- t7 += v * b1;
967
- t8 += v * b2;
968
- t9 += v * b3;
969
- t10 += v * b4;
970
- t11 += v * b5;
971
- t12 += v * b6;
972
- t13 += v * b7;
973
- t14 += v * b8;
974
- t15 += v * b9;
975
- t16 += v * b10;
976
- t17 += v * b11;
977
- t18 += v * b12;
978
- t19 += v * b13;
979
- t20 += v * b14;
980
- t21 += v * b15;
981
- v = a[7];
982
- t7 += v * b0;
983
- t8 += v * b1;
984
- t9 += v * b2;
985
- t10 += v * b3;
986
- t11 += v * b4;
987
- t12 += v * b5;
988
- t13 += v * b6;
989
- t14 += v * b7;
990
- t15 += v * b8;
991
- t16 += v * b9;
992
- t17 += v * b10;
993
- t18 += v * b11;
994
- t19 += v * b12;
995
- t20 += v * b13;
996
- t21 += v * b14;
997
- t22 += v * b15;
998
- v = a[8];
999
- t8 += v * b0;
1000
- t9 += v * b1;
1001
- t10 += v * b2;
1002
- t11 += v * b3;
1003
- t12 += v * b4;
1004
- t13 += v * b5;
1005
- t14 += v * b6;
1006
- t15 += v * b7;
1007
- t16 += v * b8;
1008
- t17 += v * b9;
1009
- t18 += v * b10;
1010
- t19 += v * b11;
1011
- t20 += v * b12;
1012
- t21 += v * b13;
1013
- t22 += v * b14;
1014
- t23 += v * b15;
1015
- v = a[9];
1016
- t9 += v * b0;
1017
- t10 += v * b1;
1018
- t11 += v * b2;
1019
- t12 += v * b3;
1020
- t13 += v * b4;
1021
- t14 += v * b5;
1022
- t15 += v * b6;
1023
- t16 += v * b7;
1024
- t17 += v * b8;
1025
- t18 += v * b9;
1026
- t19 += v * b10;
1027
- t20 += v * b11;
1028
- t21 += v * b12;
1029
- t22 += v * b13;
1030
- t23 += v * b14;
1031
- t24 += v * b15;
1032
- v = a[10];
1033
- t10 += v * b0;
1034
- t11 += v * b1;
1035
- t12 += v * b2;
1036
- t13 += v * b3;
1037
- t14 += v * b4;
1038
- t15 += v * b5;
1039
- t16 += v * b6;
1040
- t17 += v * b7;
1041
- t18 += v * b8;
1042
- t19 += v * b9;
1043
- t20 += v * b10;
1044
- t21 += v * b11;
1045
- t22 += v * b12;
1046
- t23 += v * b13;
1047
- t24 += v * b14;
1048
- t25 += v * b15;
1049
- v = a[11];
1050
- t11 += v * b0;
1051
- t12 += v * b1;
1052
- t13 += v * b2;
1053
- t14 += v * b3;
1054
- t15 += v * b4;
1055
- t16 += v * b5;
1056
- t17 += v * b6;
1057
- t18 += v * b7;
1058
- t19 += v * b8;
1059
- t20 += v * b9;
1060
- t21 += v * b10;
1061
- t22 += v * b11;
1062
- t23 += v * b12;
1063
- t24 += v * b13;
1064
- t25 += v * b14;
1065
- t26 += v * b15;
1066
- v = a[12];
1067
- t12 += v * b0;
1068
- t13 += v * b1;
1069
- t14 += v * b2;
1070
- t15 += v * b3;
1071
- t16 += v * b4;
1072
- t17 += v * b5;
1073
- t18 += v * b6;
1074
- t19 += v * b7;
1075
- t20 += v * b8;
1076
- t21 += v * b9;
1077
- t22 += v * b10;
1078
- t23 += v * b11;
1079
- t24 += v * b12;
1080
- t25 += v * b13;
1081
- t26 += v * b14;
1082
- t27 += v * b15;
1083
- v = a[13];
1084
- t13 += v * b0;
1085
- t14 += v * b1;
1086
- t15 += v * b2;
1087
- t16 += v * b3;
1088
- t17 += v * b4;
1089
- t18 += v * b5;
1090
- t19 += v * b6;
1091
- t20 += v * b7;
1092
- t21 += v * b8;
1093
- t22 += v * b9;
1094
- t23 += v * b10;
1095
- t24 += v * b11;
1096
- t25 += v * b12;
1097
- t26 += v * b13;
1098
- t27 += v * b14;
1099
- t28 += v * b15;
1100
- v = a[14];
1101
- t14 += v * b0;
1102
- t15 += v * b1;
1103
- t16 += v * b2;
1104
- t17 += v * b3;
1105
- t18 += v * b4;
1106
- t19 += v * b5;
1107
- t20 += v * b6;
1108
- t21 += v * b7;
1109
- t22 += v * b8;
1110
- t23 += v * b9;
1111
- t24 += v * b10;
1112
- t25 += v * b11;
1113
- t26 += v * b12;
1114
- t27 += v * b13;
1115
- t28 += v * b14;
1116
- t29 += v * b15;
1117
- v = a[15];
1118
- t15 += v * b0;
1119
- t16 += v * b1;
1120
- t17 += v * b2;
1121
- t18 += v * b3;
1122
- t19 += v * b4;
1123
- t20 += v * b5;
1124
- t21 += v * b6;
1125
- t22 += v * b7;
1126
- t23 += v * b8;
1127
- t24 += v * b9;
1128
- t25 += v * b10;
1129
- t26 += v * b11;
1130
- t27 += v * b12;
1131
- t28 += v * b13;
1132
- t29 += v * b14;
1133
- t30 += v * b15;
1134
- t0 += 38 * t16;
1135
- t1 += 38 * t17;
1136
- t2 += 38 * t18;
1137
- t3 += 38 * t19;
1138
- t4 += 38 * t20;
1139
- t5 += 38 * t21;
1140
- t6 += 38 * t22;
1141
- t7 += 38 * t23;
1142
- t8 += 38 * t24;
1143
- t9 += 38 * t25;
1144
- t10 += 38 * t26;
1145
- t11 += 38 * t27;
1146
- t12 += 38 * t28;
1147
- t13 += 38 * t29;
1148
- t14 += 38 * t30;
1149
- c = 1;
1150
- v = t0 + c + 65535;
1151
- c = Math.floor(v / 65536);
1152
- t0 = v - c * 65536;
1153
- v = t1 + c + 65535;
1154
- c = Math.floor(v / 65536);
1155
- t1 = v - c * 65536;
1156
- v = t2 + c + 65535;
1157
- c = Math.floor(v / 65536);
1158
- t2 = v - c * 65536;
1159
- v = t3 + c + 65535;
1160
- c = Math.floor(v / 65536);
1161
- t3 = v - c * 65536;
1162
- v = t4 + c + 65535;
1163
- c = Math.floor(v / 65536);
1164
- t4 = v - c * 65536;
1165
- v = t5 + c + 65535;
1166
- c = Math.floor(v / 65536);
1167
- t5 = v - c * 65536;
1168
- v = t6 + c + 65535;
1169
- c = Math.floor(v / 65536);
1170
- t6 = v - c * 65536;
1171
- v = t7 + c + 65535;
1172
- c = Math.floor(v / 65536);
1173
- t7 = v - c * 65536;
1174
- v = t8 + c + 65535;
1175
- c = Math.floor(v / 65536);
1176
- t8 = v - c * 65536;
1177
- v = t9 + c + 65535;
1178
- c = Math.floor(v / 65536);
1179
- t9 = v - c * 65536;
1180
- v = t10 + c + 65535;
1181
- c = Math.floor(v / 65536);
1182
- t10 = v - c * 65536;
1183
- v = t11 + c + 65535;
1184
- c = Math.floor(v / 65536);
1185
- t11 = v - c * 65536;
1186
- v = t12 + c + 65535;
1187
- c = Math.floor(v / 65536);
1188
- t12 = v - c * 65536;
1189
- v = t13 + c + 65535;
1190
- c = Math.floor(v / 65536);
1191
- t13 = v - c * 65536;
1192
- v = t14 + c + 65535;
1193
- c = Math.floor(v / 65536);
1194
- t14 = v - c * 65536;
1195
- v = t15 + c + 65535;
1196
- c = Math.floor(v / 65536);
1197
- t15 = v - c * 65536;
1198
- t0 += c - 1 + 37 * (c - 1);
1199
- c = 1;
1200
- v = t0 + c + 65535;
1201
- c = Math.floor(v / 65536);
1202
- t0 = v - c * 65536;
1203
- v = t1 + c + 65535;
1204
- c = Math.floor(v / 65536);
1205
- t1 = v - c * 65536;
1206
- v = t2 + c + 65535;
1207
- c = Math.floor(v / 65536);
1208
- t2 = v - c * 65536;
1209
- v = t3 + c + 65535;
1210
- c = Math.floor(v / 65536);
1211
- t3 = v - c * 65536;
1212
- v = t4 + c + 65535;
1213
- c = Math.floor(v / 65536);
1214
- t4 = v - c * 65536;
1215
- v = t5 + c + 65535;
1216
- c = Math.floor(v / 65536);
1217
- t5 = v - c * 65536;
1218
- v = t6 + c + 65535;
1219
- c = Math.floor(v / 65536);
1220
- t6 = v - c * 65536;
1221
- v = t7 + c + 65535;
1222
- c = Math.floor(v / 65536);
1223
- t7 = v - c * 65536;
1224
- v = t8 + c + 65535;
1225
- c = Math.floor(v / 65536);
1226
- t8 = v - c * 65536;
1227
- v = t9 + c + 65535;
1228
- c = Math.floor(v / 65536);
1229
- t9 = v - c * 65536;
1230
- v = t10 + c + 65535;
1231
- c = Math.floor(v / 65536);
1232
- t10 = v - c * 65536;
1233
- v = t11 + c + 65535;
1234
- c = Math.floor(v / 65536);
1235
- t11 = v - c * 65536;
1236
- v = t12 + c + 65535;
1237
- c = Math.floor(v / 65536);
1238
- t12 = v - c * 65536;
1239
- v = t13 + c + 65535;
1240
- c = Math.floor(v / 65536);
1241
- t13 = v - c * 65536;
1242
- v = t14 + c + 65535;
1243
- c = Math.floor(v / 65536);
1244
- t14 = v - c * 65536;
1245
- v = t15 + c + 65535;
1246
- c = Math.floor(v / 65536);
1247
- t15 = v - c * 65536;
1248
- t0 += c - 1 + 37 * (c - 1);
1249
- o[0] = t0;
1250
- o[1] = t1;
1251
- o[2] = t2;
1252
- o[3] = t3;
1253
- o[4] = t4;
1254
- o[5] = t5;
1255
- o[6] = t6;
1256
- o[7] = t7;
1257
- o[8] = t8;
1258
- o[9] = t9;
1259
- o[10] = t10;
1260
- o[11] = t11;
1261
- o[12] = t12;
1262
- o[13] = t13;
1263
- o[14] = t14;
1264
- o[15] = t15;
1265
- }
1266
- __name(M, "M");
1267
- function S(o, a) {
1268
- M(o, a, a);
1269
- }
1270
- __name(S, "S");
1271
- function inv25519(o, i) {
1272
- var c = gf();
1273
- var a;
1274
- for (a = 0; a < 16; a++) c[a] = i[a];
1275
- for (a = 253; a >= 0; a--) {
1276
- S(c, c);
1277
- if (a !== 2 && a !== 4) M(c, c, i);
1278
- }
1279
- for (a = 0; a < 16; a++) o[a] = c[a];
1280
- }
1281
- __name(inv25519, "inv25519");
1282
- function pow2523(o, i) {
1283
- var c = gf();
1284
- var a;
1285
- for (a = 0; a < 16; a++) c[a] = i[a];
1286
- for (a = 250; a >= 0; a--) {
1287
- S(c, c);
1288
- if (a !== 1) M(c, c, i);
1289
- }
1290
- for (a = 0; a < 16; a++) o[a] = c[a];
1291
- }
1292
- __name(pow2523, "pow2523");
1293
- function crypto_scalarmult(q, n, p) {
1294
- var z = new Uint8Array(32);
1295
- var x = new Float64Array(80), r, i;
1296
- var a = gf(), b = gf(), c = gf(), d = gf(), e = gf(), f = gf();
1297
- for (i = 0; i < 31; i++) z[i] = n[i];
1298
- z[31] = n[31] & 127 | 64;
1299
- z[0] &= 248;
1300
- unpack25519(x, p);
1301
- for (i = 0; i < 16; i++) {
1302
- b[i] = x[i];
1303
- d[i] = a[i] = c[i] = 0;
1304
- }
1305
- a[0] = d[0] = 1;
1306
- for (i = 254; i >= 0; --i) {
1307
- r = z[i >>> 3] >>> (i & 7) & 1;
1308
- sel25519(a, b, r);
1309
- sel25519(c, d, r);
1310
- A(e, a, c);
1311
- Z(a, a, c);
1312
- A(c, b, d);
1313
- Z(b, b, d);
1314
- S(d, e);
1315
- S(f, a);
1316
- M(a, c, a);
1317
- M(c, b, e);
1318
- A(e, a, c);
1319
- Z(a, a, c);
1320
- S(b, a);
1321
- Z(c, d, f);
1322
- M(a, c, _121665);
1323
- A(a, a, d);
1324
- M(c, c, a);
1325
- M(a, d, f);
1326
- M(d, b, x);
1327
- S(b, e);
1328
- sel25519(a, b, r);
1329
- sel25519(c, d, r);
1330
- }
1331
- for (i = 0; i < 16; i++) {
1332
- x[i + 16] = a[i];
1333
- x[i + 32] = c[i];
1334
- x[i + 48] = b[i];
1335
- x[i + 64] = d[i];
1336
- }
1337
- var x32 = x.subarray(32);
1338
- var x16 = x.subarray(16);
1339
- inv25519(x32, x32);
1340
- M(x16, x16, x32);
1341
- pack25519(q, x16);
1342
- return 0;
1343
- }
1344
- __name(crypto_scalarmult, "crypto_scalarmult");
1345
- function crypto_scalarmult_base(q, n) {
1346
- return crypto_scalarmult(q, n, _9);
1347
- }
1348
- __name(crypto_scalarmult_base, "crypto_scalarmult_base");
1349
- function crypto_box_keypair(y, x) {
1350
- randombytes(x, 32);
1351
- return crypto_scalarmult_base(y, x);
1352
- }
1353
- __name(crypto_box_keypair, "crypto_box_keypair");
1354
- function crypto_box_beforenm(k, y, x) {
1355
- var s = new Uint8Array(32);
1356
- crypto_scalarmult(s, x, y);
1357
- return crypto_core_hsalsa20(k, _0, s, sigma);
1358
- }
1359
- __name(crypto_box_beforenm, "crypto_box_beforenm");
1360
- var crypto_box_afternm = crypto_secretbox;
1361
- var crypto_box_open_afternm = crypto_secretbox_open;
1362
- function crypto_box(c, m, d, n, y, x) {
1363
- var k = new Uint8Array(32);
1364
- crypto_box_beforenm(k, y, x);
1365
- return crypto_box_afternm(c, m, d, n, k);
1366
- }
1367
- __name(crypto_box, "crypto_box");
1368
- function crypto_box_open(m, c, d, n, y, x) {
1369
- var k = new Uint8Array(32);
1370
- crypto_box_beforenm(k, y, x);
1371
- return crypto_box_open_afternm(m, c, d, n, k);
1372
- }
1373
- __name(crypto_box_open, "crypto_box_open");
1374
- var K = [
1375
- 1116352408,
1376
- 3609767458,
1377
- 1899447441,
1378
- 602891725,
1379
- 3049323471,
1380
- 3964484399,
1381
- 3921009573,
1382
- 2173295548,
1383
- 961987163,
1384
- 4081628472,
1385
- 1508970993,
1386
- 3053834265,
1387
- 2453635748,
1388
- 2937671579,
1389
- 2870763221,
1390
- 3664609560,
1391
- 3624381080,
1392
- 2734883394,
1393
- 310598401,
1394
- 1164996542,
1395
- 607225278,
1396
- 1323610764,
1397
- 1426881987,
1398
- 3590304994,
1399
- 1925078388,
1400
- 4068182383,
1401
- 2162078206,
1402
- 991336113,
1403
- 2614888103,
1404
- 633803317,
1405
- 3248222580,
1406
- 3479774868,
1407
- 3835390401,
1408
- 2666613458,
1409
- 4022224774,
1410
- 944711139,
1411
- 264347078,
1412
- 2341262773,
1413
- 604807628,
1414
- 2007800933,
1415
- 770255983,
1416
- 1495990901,
1417
- 1249150122,
1418
- 1856431235,
1419
- 1555081692,
1420
- 3175218132,
1421
- 1996064986,
1422
- 2198950837,
1423
- 2554220882,
1424
- 3999719339,
1425
- 2821834349,
1426
- 766784016,
1427
- 2952996808,
1428
- 2566594879,
1429
- 3210313671,
1430
- 3203337956,
1431
- 3336571891,
1432
- 1034457026,
1433
- 3584528711,
1434
- 2466948901,
1435
- 113926993,
1436
- 3758326383,
1437
- 338241895,
1438
- 168717936,
1439
- 666307205,
1440
- 1188179964,
1441
- 773529912,
1442
- 1546045734,
1443
- 1294757372,
1444
- 1522805485,
1445
- 1396182291,
1446
- 2643833823,
1447
- 1695183700,
1448
- 2343527390,
1449
- 1986661051,
1450
- 1014477480,
1451
- 2177026350,
1452
- 1206759142,
1453
- 2456956037,
1454
- 344077627,
1455
- 2730485921,
1456
- 1290863460,
1457
- 2820302411,
1458
- 3158454273,
1459
- 3259730800,
1460
- 3505952657,
1461
- 3345764771,
1462
- 106217008,
1463
- 3516065817,
1464
- 3606008344,
1465
- 3600352804,
1466
- 1432725776,
1467
- 4094571909,
1468
- 1467031594,
1469
- 275423344,
1470
- 851169720,
1471
- 430227734,
1472
- 3100823752,
1473
- 506948616,
1474
- 1363258195,
1475
- 659060556,
1476
- 3750685593,
1477
- 883997877,
1478
- 3785050280,
1479
- 958139571,
1480
- 3318307427,
1481
- 1322822218,
1482
- 3812723403,
1483
- 1537002063,
1484
- 2003034995,
1485
- 1747873779,
1486
- 3602036899,
1487
- 1955562222,
1488
- 1575990012,
1489
- 2024104815,
1490
- 1125592928,
1491
- 2227730452,
1492
- 2716904306,
1493
- 2361852424,
1494
- 442776044,
1495
- 2428436474,
1496
- 593698344,
1497
- 2756734187,
1498
- 3733110249,
1499
- 3204031479,
1500
- 2999351573,
1501
- 3329325298,
1502
- 3815920427,
1503
- 3391569614,
1504
- 3928383900,
1505
- 3515267271,
1506
- 566280711,
1507
- 3940187606,
1508
- 3454069534,
1509
- 4118630271,
1510
- 4000239992,
1511
- 116418474,
1512
- 1914138554,
1513
- 174292421,
1514
- 2731055270,
1515
- 289380356,
1516
- 3203993006,
1517
- 460393269,
1518
- 320620315,
1519
- 685471733,
1520
- 587496836,
1521
- 852142971,
1522
- 1086792851,
1523
- 1017036298,
1524
- 365543100,
1525
- 1126000580,
1526
- 2618297676,
1527
- 1288033470,
1528
- 3409855158,
1529
- 1501505948,
1530
- 4234509866,
1531
- 1607167915,
1532
- 987167468,
1533
- 1816402316,
1534
- 1246189591
1535
- ];
1536
- function crypto_hashblocks_hl(hh, hl, m, n) {
1537
- var wh = new Int32Array(16), wl = new Int32Array(16), bh0, bh1, bh2, bh3, bh4, bh5, bh6, bh7, bl0, bl1, bl2, bl3, bl4, bl5, bl6, bl7, th, tl, i, j, h, l, a, b, c, d;
1538
- var ah0 = hh[0], ah1 = hh[1], ah2 = hh[2], ah3 = hh[3], ah4 = hh[4], ah5 = hh[5], ah6 = hh[6], ah7 = hh[7], al0 = hl[0], al1 = hl[1], al2 = hl[2], al3 = hl[3], al4 = hl[4], al5 = hl[5], al6 = hl[6], al7 = hl[7];
1539
- var pos = 0;
1540
- while (n >= 128) {
1541
- for (i = 0; i < 16; i++) {
1542
- j = 8 * i + pos;
1543
- wh[i] = m[j + 0] << 24 | m[j + 1] << 16 | m[j + 2] << 8 | m[j + 3];
1544
- wl[i] = m[j + 4] << 24 | m[j + 5] << 16 | m[j + 6] << 8 | m[j + 7];
1545
- }
1546
- for (i = 0; i < 80; i++) {
1547
- bh0 = ah0;
1548
- bh1 = ah1;
1549
- bh2 = ah2;
1550
- bh3 = ah3;
1551
- bh4 = ah4;
1552
- bh5 = ah5;
1553
- bh6 = ah6;
1554
- bh7 = ah7;
1555
- bl0 = al0;
1556
- bl1 = al1;
1557
- bl2 = al2;
1558
- bl3 = al3;
1559
- bl4 = al4;
1560
- bl5 = al5;
1561
- bl6 = al6;
1562
- bl7 = al7;
1563
- h = ah7;
1564
- l = al7;
1565
- a = l & 65535;
1566
- b = l >>> 16;
1567
- c = h & 65535;
1568
- d = h >>> 16;
1569
- h = (ah4 >>> 14 | al4 << 32 - 14) ^ (ah4 >>> 18 | al4 << 32 - 18) ^ (al4 >>> 41 - 32 | ah4 << 32 - (41 - 32));
1570
- l = (al4 >>> 14 | ah4 << 32 - 14) ^ (al4 >>> 18 | ah4 << 32 - 18) ^ (ah4 >>> 41 - 32 | al4 << 32 - (41 - 32));
1571
- a += l & 65535;
1572
- b += l >>> 16;
1573
- c += h & 65535;
1574
- d += h >>> 16;
1575
- h = ah4 & ah5 ^ ~ah4 & ah6;
1576
- l = al4 & al5 ^ ~al4 & al6;
1577
- a += l & 65535;
1578
- b += l >>> 16;
1579
- c += h & 65535;
1580
- d += h >>> 16;
1581
- h = K[i * 2];
1582
- l = K[i * 2 + 1];
1583
- a += l & 65535;
1584
- b += l >>> 16;
1585
- c += h & 65535;
1586
- d += h >>> 16;
1587
- h = wh[i % 16];
1588
- l = wl[i % 16];
1589
- a += l & 65535;
1590
- b += l >>> 16;
1591
- c += h & 65535;
1592
- d += h >>> 16;
1593
- b += a >>> 16;
1594
- c += b >>> 16;
1595
- d += c >>> 16;
1596
- th = c & 65535 | d << 16;
1597
- tl = a & 65535 | b << 16;
1598
- h = th;
1599
- l = tl;
1600
- a = l & 65535;
1601
- b = l >>> 16;
1602
- c = h & 65535;
1603
- d = h >>> 16;
1604
- h = (ah0 >>> 28 | al0 << 32 - 28) ^ (al0 >>> 34 - 32 | ah0 << 32 - (34 - 32)) ^ (al0 >>> 39 - 32 | ah0 << 32 - (39 - 32));
1605
- l = (al0 >>> 28 | ah0 << 32 - 28) ^ (ah0 >>> 34 - 32 | al0 << 32 - (34 - 32)) ^ (ah0 >>> 39 - 32 | al0 << 32 - (39 - 32));
1606
- a += l & 65535;
1607
- b += l >>> 16;
1608
- c += h & 65535;
1609
- d += h >>> 16;
1610
- h = ah0 & ah1 ^ ah0 & ah2 ^ ah1 & ah2;
1611
- l = al0 & al1 ^ al0 & al2 ^ al1 & al2;
1612
- a += l & 65535;
1613
- b += l >>> 16;
1614
- c += h & 65535;
1615
- d += h >>> 16;
1616
- b += a >>> 16;
1617
- c += b >>> 16;
1618
- d += c >>> 16;
1619
- bh7 = c & 65535 | d << 16;
1620
- bl7 = a & 65535 | b << 16;
1621
- h = bh3;
1622
- l = bl3;
1623
- a = l & 65535;
1624
- b = l >>> 16;
1625
- c = h & 65535;
1626
- d = h >>> 16;
1627
- h = th;
1628
- l = tl;
1629
- a += l & 65535;
1630
- b += l >>> 16;
1631
- c += h & 65535;
1632
- d += h >>> 16;
1633
- b += a >>> 16;
1634
- c += b >>> 16;
1635
- d += c >>> 16;
1636
- bh3 = c & 65535 | d << 16;
1637
- bl3 = a & 65535 | b << 16;
1638
- ah1 = bh0;
1639
- ah2 = bh1;
1640
- ah3 = bh2;
1641
- ah4 = bh3;
1642
- ah5 = bh4;
1643
- ah6 = bh5;
1644
- ah7 = bh6;
1645
- ah0 = bh7;
1646
- al1 = bl0;
1647
- al2 = bl1;
1648
- al3 = bl2;
1649
- al4 = bl3;
1650
- al5 = bl4;
1651
- al6 = bl5;
1652
- al7 = bl6;
1653
- al0 = bl7;
1654
- if (i % 16 === 15) {
1655
- for (j = 0; j < 16; j++) {
1656
- h = wh[j];
1657
- l = wl[j];
1658
- a = l & 65535;
1659
- b = l >>> 16;
1660
- c = h & 65535;
1661
- d = h >>> 16;
1662
- h = wh[(j + 9) % 16];
1663
- l = wl[(j + 9) % 16];
1664
- a += l & 65535;
1665
- b += l >>> 16;
1666
- c += h & 65535;
1667
- d += h >>> 16;
1668
- th = wh[(j + 1) % 16];
1669
- tl = wl[(j + 1) % 16];
1670
- h = (th >>> 1 | tl << 32 - 1) ^ (th >>> 8 | tl << 32 - 8) ^ th >>> 7;
1671
- l = (tl >>> 1 | th << 32 - 1) ^ (tl >>> 8 | th << 32 - 8) ^ (tl >>> 7 | th << 32 - 7);
1672
- a += l & 65535;
1673
- b += l >>> 16;
1674
- c += h & 65535;
1675
- d += h >>> 16;
1676
- th = wh[(j + 14) % 16];
1677
- tl = wl[(j + 14) % 16];
1678
- h = (th >>> 19 | tl << 32 - 19) ^ (tl >>> 61 - 32 | th << 32 - (61 - 32)) ^ th >>> 6;
1679
- l = (tl >>> 19 | th << 32 - 19) ^ (th >>> 61 - 32 | tl << 32 - (61 - 32)) ^ (tl >>> 6 | th << 32 - 6);
1680
- a += l & 65535;
1681
- b += l >>> 16;
1682
- c += h & 65535;
1683
- d += h >>> 16;
1684
- b += a >>> 16;
1685
- c += b >>> 16;
1686
- d += c >>> 16;
1687
- wh[j] = c & 65535 | d << 16;
1688
- wl[j] = a & 65535 | b << 16;
1689
- }
1690
- }
1691
- }
1692
- h = ah0;
1693
- l = al0;
1694
- a = l & 65535;
1695
- b = l >>> 16;
1696
- c = h & 65535;
1697
- d = h >>> 16;
1698
- h = hh[0];
1699
- l = hl[0];
1700
- a += l & 65535;
1701
- b += l >>> 16;
1702
- c += h & 65535;
1703
- d += h >>> 16;
1704
- b += a >>> 16;
1705
- c += b >>> 16;
1706
- d += c >>> 16;
1707
- hh[0] = ah0 = c & 65535 | d << 16;
1708
- hl[0] = al0 = a & 65535 | b << 16;
1709
- h = ah1;
1710
- l = al1;
1711
- a = l & 65535;
1712
- b = l >>> 16;
1713
- c = h & 65535;
1714
- d = h >>> 16;
1715
- h = hh[1];
1716
- l = hl[1];
1717
- a += l & 65535;
1718
- b += l >>> 16;
1719
- c += h & 65535;
1720
- d += h >>> 16;
1721
- b += a >>> 16;
1722
- c += b >>> 16;
1723
- d += c >>> 16;
1724
- hh[1] = ah1 = c & 65535 | d << 16;
1725
- hl[1] = al1 = a & 65535 | b << 16;
1726
- h = ah2;
1727
- l = al2;
1728
- a = l & 65535;
1729
- b = l >>> 16;
1730
- c = h & 65535;
1731
- d = h >>> 16;
1732
- h = hh[2];
1733
- l = hl[2];
1734
- a += l & 65535;
1735
- b += l >>> 16;
1736
- c += h & 65535;
1737
- d += h >>> 16;
1738
- b += a >>> 16;
1739
- c += b >>> 16;
1740
- d += c >>> 16;
1741
- hh[2] = ah2 = c & 65535 | d << 16;
1742
- hl[2] = al2 = a & 65535 | b << 16;
1743
- h = ah3;
1744
- l = al3;
1745
- a = l & 65535;
1746
- b = l >>> 16;
1747
- c = h & 65535;
1748
- d = h >>> 16;
1749
- h = hh[3];
1750
- l = hl[3];
1751
- a += l & 65535;
1752
- b += l >>> 16;
1753
- c += h & 65535;
1754
- d += h >>> 16;
1755
- b += a >>> 16;
1756
- c += b >>> 16;
1757
- d += c >>> 16;
1758
- hh[3] = ah3 = c & 65535 | d << 16;
1759
- hl[3] = al3 = a & 65535 | b << 16;
1760
- h = ah4;
1761
- l = al4;
1762
- a = l & 65535;
1763
- b = l >>> 16;
1764
- c = h & 65535;
1765
- d = h >>> 16;
1766
- h = hh[4];
1767
- l = hl[4];
1768
- a += l & 65535;
1769
- b += l >>> 16;
1770
- c += h & 65535;
1771
- d += h >>> 16;
1772
- b += a >>> 16;
1773
- c += b >>> 16;
1774
- d += c >>> 16;
1775
- hh[4] = ah4 = c & 65535 | d << 16;
1776
- hl[4] = al4 = a & 65535 | b << 16;
1777
- h = ah5;
1778
- l = al5;
1779
- a = l & 65535;
1780
- b = l >>> 16;
1781
- c = h & 65535;
1782
- d = h >>> 16;
1783
- h = hh[5];
1784
- l = hl[5];
1785
- a += l & 65535;
1786
- b += l >>> 16;
1787
- c += h & 65535;
1788
- d += h >>> 16;
1789
- b += a >>> 16;
1790
- c += b >>> 16;
1791
- d += c >>> 16;
1792
- hh[5] = ah5 = c & 65535 | d << 16;
1793
- hl[5] = al5 = a & 65535 | b << 16;
1794
- h = ah6;
1795
- l = al6;
1796
- a = l & 65535;
1797
- b = l >>> 16;
1798
- c = h & 65535;
1799
- d = h >>> 16;
1800
- h = hh[6];
1801
- l = hl[6];
1802
- a += l & 65535;
1803
- b += l >>> 16;
1804
- c += h & 65535;
1805
- d += h >>> 16;
1806
- b += a >>> 16;
1807
- c += b >>> 16;
1808
- d += c >>> 16;
1809
- hh[6] = ah6 = c & 65535 | d << 16;
1810
- hl[6] = al6 = a & 65535 | b << 16;
1811
- h = ah7;
1812
- l = al7;
1813
- a = l & 65535;
1814
- b = l >>> 16;
1815
- c = h & 65535;
1816
- d = h >>> 16;
1817
- h = hh[7];
1818
- l = hl[7];
1819
- a += l & 65535;
1820
- b += l >>> 16;
1821
- c += h & 65535;
1822
- d += h >>> 16;
1823
- b += a >>> 16;
1824
- c += b >>> 16;
1825
- d += c >>> 16;
1826
- hh[7] = ah7 = c & 65535 | d << 16;
1827
- hl[7] = al7 = a & 65535 | b << 16;
1828
- pos += 128;
1829
- n -= 128;
1830
- }
1831
- return n;
1832
- }
1833
- __name(crypto_hashblocks_hl, "crypto_hashblocks_hl");
1834
- function crypto_hash(out, m, n) {
1835
- var hh = new Int32Array(8), hl = new Int32Array(8), x = new Uint8Array(256), i, b = n;
1836
- hh[0] = 1779033703;
1837
- hh[1] = 3144134277;
1838
- hh[2] = 1013904242;
1839
- hh[3] = 2773480762;
1840
- hh[4] = 1359893119;
1841
- hh[5] = 2600822924;
1842
- hh[6] = 528734635;
1843
- hh[7] = 1541459225;
1844
- hl[0] = 4089235720;
1845
- hl[1] = 2227873595;
1846
- hl[2] = 4271175723;
1847
- hl[3] = 1595750129;
1848
- hl[4] = 2917565137;
1849
- hl[5] = 725511199;
1850
- hl[6] = 4215389547;
1851
- hl[7] = 327033209;
1852
- crypto_hashblocks_hl(hh, hl, m, n);
1853
- n %= 128;
1854
- for (i = 0; i < n; i++) x[i] = m[b - n + i];
1855
- x[n] = 128;
1856
- n = 256 - 128 * (n < 112 ? 1 : 0);
1857
- x[n - 9] = 0;
1858
- ts64(x, n - 8, b / 536870912 | 0, b << 3);
1859
- crypto_hashblocks_hl(hh, hl, x, n);
1860
- for (i = 0; i < 8; i++) ts64(out, 8 * i, hh[i], hl[i]);
1861
- return 0;
1862
- }
1863
- __name(crypto_hash, "crypto_hash");
1864
- function add(p, q) {
1865
- var a = gf(), b = gf(), c = gf(), d = gf(), e = gf(), f = gf(), g = gf(), h = gf(), t = gf();
1866
- Z(a, p[1], p[0]);
1867
- Z(t, q[1], q[0]);
1868
- M(a, a, t);
1869
- A(b, p[0], p[1]);
1870
- A(t, q[0], q[1]);
1871
- M(b, b, t);
1872
- M(c, p[3], q[3]);
1873
- M(c, c, D2);
1874
- M(d, p[2], q[2]);
1875
- A(d, d, d);
1876
- Z(e, b, a);
1877
- Z(f, d, c);
1878
- A(g, d, c);
1879
- A(h, b, a);
1880
- M(p[0], e, f);
1881
- M(p[1], h, g);
1882
- M(p[2], g, f);
1883
- M(p[3], e, h);
1884
- }
1885
- __name(add, "add");
1886
- function cswap(p, q, b) {
1887
- var i;
1888
- for (i = 0; i < 4; i++) {
1889
- sel25519(p[i], q[i], b);
1890
- }
1891
- }
1892
- __name(cswap, "cswap");
1893
- function pack(r, p) {
1894
- var tx = gf(), ty = gf(), zi = gf();
1895
- inv25519(zi, p[2]);
1896
- M(tx, p[0], zi);
1897
- M(ty, p[1], zi);
1898
- pack25519(r, ty);
1899
- r[31] ^= par25519(tx) << 7;
1900
- }
1901
- __name(pack, "pack");
1902
- function scalarmult(p, q, s) {
1903
- var b, i;
1904
- set25519(p[0], gf0);
1905
- set25519(p[1], gf1);
1906
- set25519(p[2], gf1);
1907
- set25519(p[3], gf0);
1908
- for (i = 255; i >= 0; --i) {
1909
- b = s[i / 8 | 0] >> (i & 7) & 1;
1910
- cswap(p, q, b);
1911
- add(q, p);
1912
- add(p, p);
1913
- cswap(p, q, b);
1914
- }
1915
- }
1916
- __name(scalarmult, "scalarmult");
1917
- function scalarbase(p, s) {
1918
- var q = [gf(), gf(), gf(), gf()];
1919
- set25519(q[0], X);
1920
- set25519(q[1], Y);
1921
- set25519(q[2], gf1);
1922
- M(q[3], X, Y);
1923
- scalarmult(p, q, s);
1924
- }
1925
- __name(scalarbase, "scalarbase");
1926
- function crypto_sign_keypair(pk, sk, seeded) {
1927
- var d = new Uint8Array(64);
1928
- var p = [gf(), gf(), gf(), gf()];
1929
- var i;
1930
- if (!seeded) randombytes(sk, 32);
1931
- crypto_hash(d, sk, 32);
1932
- d[0] &= 248;
1933
- d[31] &= 127;
1934
- d[31] |= 64;
1935
- scalarbase(p, d);
1936
- pack(pk, p);
1937
- for (i = 0; i < 32; i++) sk[i + 32] = pk[i];
1938
- return 0;
1939
- }
1940
- __name(crypto_sign_keypair, "crypto_sign_keypair");
1941
- var L = new Float64Array([237, 211, 245, 92, 26, 99, 18, 88, 214, 156, 247, 162, 222, 249, 222, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16]);
1942
- function modL(r, x) {
1943
- var carry, i, j, k;
1944
- for (i = 63; i >= 32; --i) {
1945
- carry = 0;
1946
- for (j = i - 32, k = i - 12; j < k; ++j) {
1947
- x[j] += carry - 16 * x[i] * L[j - (i - 32)];
1948
- carry = Math.floor((x[j] + 128) / 256);
1949
- x[j] -= carry * 256;
1950
- }
1951
- x[j] += carry;
1952
- x[i] = 0;
1953
- }
1954
- carry = 0;
1955
- for (j = 0; j < 32; j++) {
1956
- x[j] += carry - (x[31] >> 4) * L[j];
1957
- carry = x[j] >> 8;
1958
- x[j] &= 255;
1959
- }
1960
- for (j = 0; j < 32; j++) x[j] -= carry * L[j];
1961
- for (i = 0; i < 32; i++) {
1962
- x[i + 1] += x[i] >> 8;
1963
- r[i] = x[i] & 255;
1964
- }
1965
- }
1966
- __name(modL, "modL");
1967
- function reduce(r) {
1968
- var x = new Float64Array(64), i;
1969
- for (i = 0; i < 64; i++) x[i] = r[i];
1970
- for (i = 0; i < 64; i++) r[i] = 0;
1971
- modL(r, x);
1972
- }
1973
- __name(reduce, "reduce");
1974
- function crypto_sign(sm, m, n, sk) {
1975
- var d = new Uint8Array(64), h = new Uint8Array(64), r = new Uint8Array(64);
1976
- var i, j, x = new Float64Array(64);
1977
- var p = [gf(), gf(), gf(), gf()];
1978
- crypto_hash(d, sk, 32);
1979
- d[0] &= 248;
1980
- d[31] &= 127;
1981
- d[31] |= 64;
1982
- var smlen = n + 64;
1983
- for (i = 0; i < n; i++) sm[64 + i] = m[i];
1984
- for (i = 0; i < 32; i++) sm[32 + i] = d[32 + i];
1985
- crypto_hash(r, sm.subarray(32), n + 32);
1986
- reduce(r);
1987
- scalarbase(p, r);
1988
- pack(sm, p);
1989
- for (i = 32; i < 64; i++) sm[i] = sk[i];
1990
- crypto_hash(h, sm, n + 64);
1991
- reduce(h);
1992
- for (i = 0; i < 64; i++) x[i] = 0;
1993
- for (i = 0; i < 32; i++) x[i] = r[i];
1994
- for (i = 0; i < 32; i++) {
1995
- for (j = 0; j < 32; j++) {
1996
- x[i + j] += h[i] * d[j];
1997
- }
1998
- }
1999
- modL(sm.subarray(32), x);
2000
- return smlen;
2001
- }
2002
- __name(crypto_sign, "crypto_sign");
2003
- function unpackneg(r, p) {
2004
- var t = gf(), chk = gf(), num = gf(), den = gf(), den2 = gf(), den4 = gf(), den6 = gf();
2005
- set25519(r[2], gf1);
2006
- unpack25519(r[1], p);
2007
- S(num, r[1]);
2008
- M(den, num, D);
2009
- Z(num, num, r[2]);
2010
- A(den, r[2], den);
2011
- S(den2, den);
2012
- S(den4, den2);
2013
- M(den6, den4, den2);
2014
- M(t, den6, num);
2015
- M(t, t, den);
2016
- pow2523(t, t);
2017
- M(t, t, num);
2018
- M(t, t, den);
2019
- M(t, t, den);
2020
- M(r[0], t, den);
2021
- S(chk, r[0]);
2022
- M(chk, chk, den);
2023
- if (neq25519(chk, num)) M(r[0], r[0], I);
2024
- S(chk, r[0]);
2025
- M(chk, chk, den);
2026
- if (neq25519(chk, num)) return -1;
2027
- if (par25519(r[0]) === p[31] >> 7) Z(r[0], gf0, r[0]);
2028
- M(r[3], r[0], r[1]);
2029
- return 0;
2030
- }
2031
- __name(unpackneg, "unpackneg");
2032
- function crypto_sign_open(m, sm, n, pk) {
2033
- var i;
2034
- var t = new Uint8Array(32), h = new Uint8Array(64);
2035
- var p = [gf(), gf(), gf(), gf()], q = [gf(), gf(), gf(), gf()];
2036
- if (n < 64) return -1;
2037
- if (unpackneg(q, pk)) return -1;
2038
- for (i = 0; i < n; i++) m[i] = sm[i];
2039
- for (i = 0; i < 32; i++) m[i + 32] = pk[i];
2040
- crypto_hash(h, m, n);
2041
- reduce(h);
2042
- scalarmult(p, q, h);
2043
- scalarbase(q, sm.subarray(32));
2044
- add(p, q);
2045
- pack(t, p);
2046
- n -= 64;
2047
- if (crypto_verify_32(sm, 0, t, 0)) {
2048
- for (i = 0; i < n; i++) m[i] = 0;
2049
- return -1;
2050
- }
2051
- for (i = 0; i < n; i++) m[i] = sm[i + 64];
2052
- return n;
2053
- }
2054
- __name(crypto_sign_open, "crypto_sign_open");
2055
- var crypto_secretbox_KEYBYTES = 32, crypto_secretbox_NONCEBYTES = 24, crypto_secretbox_ZEROBYTES = 32, crypto_secretbox_BOXZEROBYTES = 16, crypto_scalarmult_BYTES = 32, crypto_scalarmult_SCALARBYTES = 32, crypto_box_PUBLICKEYBYTES = 32, crypto_box_SECRETKEYBYTES = 32, crypto_box_BEFORENMBYTES = 32, crypto_box_NONCEBYTES = crypto_secretbox_NONCEBYTES, crypto_box_ZEROBYTES = crypto_secretbox_ZEROBYTES, crypto_box_BOXZEROBYTES = crypto_secretbox_BOXZEROBYTES, crypto_sign_BYTES = 64, crypto_sign_PUBLICKEYBYTES = 32, crypto_sign_SECRETKEYBYTES = 64, crypto_sign_SEEDBYTES = 32, crypto_hash_BYTES = 64;
2056
- nacl.lowlevel = {
2057
- crypto_core_hsalsa20,
2058
- crypto_stream_xor,
2059
- crypto_stream,
2060
- crypto_stream_salsa20_xor,
2061
- crypto_stream_salsa20,
2062
- crypto_onetimeauth,
2063
- crypto_onetimeauth_verify,
2064
- crypto_verify_16,
2065
- crypto_verify_32,
2066
- crypto_secretbox,
2067
- crypto_secretbox_open,
2068
- crypto_scalarmult,
2069
- crypto_scalarmult_base,
2070
- crypto_box_beforenm,
2071
- crypto_box_afternm,
2072
- crypto_box,
2073
- crypto_box_open,
2074
- crypto_box_keypair,
2075
- crypto_hash,
2076
- crypto_sign,
2077
- crypto_sign_keypair,
2078
- crypto_sign_open,
2079
- crypto_secretbox_KEYBYTES,
2080
- crypto_secretbox_NONCEBYTES,
2081
- crypto_secretbox_ZEROBYTES,
2082
- crypto_secretbox_BOXZEROBYTES,
2083
- crypto_scalarmult_BYTES,
2084
- crypto_scalarmult_SCALARBYTES,
2085
- crypto_box_PUBLICKEYBYTES,
2086
- crypto_box_SECRETKEYBYTES,
2087
- crypto_box_BEFORENMBYTES,
2088
- crypto_box_NONCEBYTES,
2089
- crypto_box_ZEROBYTES,
2090
- crypto_box_BOXZEROBYTES,
2091
- crypto_sign_BYTES,
2092
- crypto_sign_PUBLICKEYBYTES,
2093
- crypto_sign_SECRETKEYBYTES,
2094
- crypto_sign_SEEDBYTES,
2095
- crypto_hash_BYTES,
2096
- gf,
2097
- D,
2098
- L,
2099
- pack25519,
2100
- unpack25519,
2101
- M,
2102
- A,
2103
- S,
2104
- Z,
2105
- pow2523,
2106
- add,
2107
- set25519,
2108
- modL,
2109
- scalarmult,
2110
- scalarbase
2111
- };
2112
- function checkLengths(k, n) {
2113
- if (k.length !== crypto_secretbox_KEYBYTES) throw new Error("bad key size");
2114
- if (n.length !== crypto_secretbox_NONCEBYTES) throw new Error("bad nonce size");
2115
- }
2116
- __name(checkLengths, "checkLengths");
2117
- function checkBoxLengths(pk, sk) {
2118
- if (pk.length !== crypto_box_PUBLICKEYBYTES) throw new Error("bad public key size");
2119
- if (sk.length !== crypto_box_SECRETKEYBYTES) throw new Error("bad secret key size");
2120
- }
2121
- __name(checkBoxLengths, "checkBoxLengths");
2122
- function checkArrayTypes() {
2123
- for (var i = 0; i < arguments.length; i++) {
2124
- if (!(arguments[i] instanceof Uint8Array))
2125
- throw new TypeError("unexpected type, use Uint8Array");
2126
- }
2127
- }
2128
- __name(checkArrayTypes, "checkArrayTypes");
2129
- function cleanup(arr) {
2130
- for (var i = 0; i < arr.length; i++) arr[i] = 0;
2131
- }
2132
- __name(cleanup, "cleanup");
2133
- nacl.randomBytes = function(n) {
2134
- var b = new Uint8Array(n);
2135
- randombytes(b, n);
2136
- return b;
2137
- };
2138
- nacl.secretbox = function(msg, nonce, key) {
2139
- checkArrayTypes(msg, nonce, key);
2140
- checkLengths(key, nonce);
2141
- var m = new Uint8Array(crypto_secretbox_ZEROBYTES + msg.length);
2142
- var c = new Uint8Array(m.length);
2143
- for (var i = 0; i < msg.length; i++) m[i + crypto_secretbox_ZEROBYTES] = msg[i];
2144
- crypto_secretbox(c, m, m.length, nonce, key);
2145
- return c.subarray(crypto_secretbox_BOXZEROBYTES);
2146
- };
2147
- nacl.secretbox.open = function(box, nonce, key) {
2148
- checkArrayTypes(box, nonce, key);
2149
- checkLengths(key, nonce);
2150
- var c = new Uint8Array(crypto_secretbox_BOXZEROBYTES + box.length);
2151
- var m = new Uint8Array(c.length);
2152
- for (var i = 0; i < box.length; i++) c[i + crypto_secretbox_BOXZEROBYTES] = box[i];
2153
- if (c.length < 32) return null;
2154
- if (crypto_secretbox_open(m, c, c.length, nonce, key) !== 0) return null;
2155
- return m.subarray(crypto_secretbox_ZEROBYTES);
2156
- };
2157
- nacl.secretbox.keyLength = crypto_secretbox_KEYBYTES;
2158
- nacl.secretbox.nonceLength = crypto_secretbox_NONCEBYTES;
2159
- nacl.secretbox.overheadLength = crypto_secretbox_BOXZEROBYTES;
2160
- nacl.scalarMult = function(n, p) {
2161
- checkArrayTypes(n, p);
2162
- if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error("bad n size");
2163
- if (p.length !== crypto_scalarmult_BYTES) throw new Error("bad p size");
2164
- var q = new Uint8Array(crypto_scalarmult_BYTES);
2165
- crypto_scalarmult(q, n, p);
2166
- return q;
2167
- };
2168
- nacl.scalarMult.base = function(n) {
2169
- checkArrayTypes(n);
2170
- if (n.length !== crypto_scalarmult_SCALARBYTES) throw new Error("bad n size");
2171
- var q = new Uint8Array(crypto_scalarmult_BYTES);
2172
- crypto_scalarmult_base(q, n);
2173
- return q;
2174
- };
2175
- nacl.scalarMult.scalarLength = crypto_scalarmult_SCALARBYTES;
2176
- nacl.scalarMult.groupElementLength = crypto_scalarmult_BYTES;
2177
- nacl.box = function(msg, nonce, publicKey, secretKey) {
2178
- var k = nacl.box.before(publicKey, secretKey);
2179
- return nacl.secretbox(msg, nonce, k);
2180
- };
2181
- nacl.box.before = function(publicKey, secretKey) {
2182
- checkArrayTypes(publicKey, secretKey);
2183
- checkBoxLengths(publicKey, secretKey);
2184
- var k = new Uint8Array(crypto_box_BEFORENMBYTES);
2185
- crypto_box_beforenm(k, publicKey, secretKey);
2186
- return k;
2187
- };
2188
- nacl.box.after = nacl.secretbox;
2189
- nacl.box.open = function(msg, nonce, publicKey, secretKey) {
2190
- var k = nacl.box.before(publicKey, secretKey);
2191
- return nacl.secretbox.open(msg, nonce, k);
2192
- };
2193
- nacl.box.open.after = nacl.secretbox.open;
2194
- nacl.box.keyPair = function() {
2195
- var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
2196
- var sk = new Uint8Array(crypto_box_SECRETKEYBYTES);
2197
- crypto_box_keypair(pk, sk);
2198
- return { publicKey: pk, secretKey: sk };
2199
- };
2200
- nacl.box.keyPair.fromSecretKey = function(secretKey) {
2201
- checkArrayTypes(secretKey);
2202
- if (secretKey.length !== crypto_box_SECRETKEYBYTES)
2203
- throw new Error("bad secret key size");
2204
- var pk = new Uint8Array(crypto_box_PUBLICKEYBYTES);
2205
- crypto_scalarmult_base(pk, secretKey);
2206
- return { publicKey: pk, secretKey: new Uint8Array(secretKey) };
2207
- };
2208
- nacl.box.publicKeyLength = crypto_box_PUBLICKEYBYTES;
2209
- nacl.box.secretKeyLength = crypto_box_SECRETKEYBYTES;
2210
- nacl.box.sharedKeyLength = crypto_box_BEFORENMBYTES;
2211
- nacl.box.nonceLength = crypto_box_NONCEBYTES;
2212
- nacl.box.overheadLength = nacl.secretbox.overheadLength;
2213
- nacl.sign = function(msg, secretKey) {
2214
- checkArrayTypes(msg, secretKey);
2215
- if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
2216
- throw new Error("bad secret key size");
2217
- var signedMsg = new Uint8Array(crypto_sign_BYTES + msg.length);
2218
- crypto_sign(signedMsg, msg, msg.length, secretKey);
2219
- return signedMsg;
2220
- };
2221
- nacl.sign.open = function(signedMsg, publicKey) {
2222
- checkArrayTypes(signedMsg, publicKey);
2223
- if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
2224
- throw new Error("bad public key size");
2225
- var tmp = new Uint8Array(signedMsg.length);
2226
- var mlen = crypto_sign_open(tmp, signedMsg, signedMsg.length, publicKey);
2227
- if (mlen < 0) return null;
2228
- var m = new Uint8Array(mlen);
2229
- for (var i = 0; i < m.length; i++) m[i] = tmp[i];
2230
- return m;
2231
- };
2232
- nacl.sign.detached = function(msg, secretKey) {
2233
- var signedMsg = nacl.sign(msg, secretKey);
2234
- var sig = new Uint8Array(crypto_sign_BYTES);
2235
- for (var i = 0; i < sig.length; i++) sig[i] = signedMsg[i];
2236
- return sig;
2237
- };
2238
- nacl.sign.detached.verify = function(msg, sig, publicKey) {
2239
- checkArrayTypes(msg, sig, publicKey);
2240
- if (sig.length !== crypto_sign_BYTES)
2241
- throw new Error("bad signature size");
2242
- if (publicKey.length !== crypto_sign_PUBLICKEYBYTES)
2243
- throw new Error("bad public key size");
2244
- var sm = new Uint8Array(crypto_sign_BYTES + msg.length);
2245
- var m = new Uint8Array(crypto_sign_BYTES + msg.length);
2246
- var i;
2247
- for (i = 0; i < crypto_sign_BYTES; i++) sm[i] = sig[i];
2248
- for (i = 0; i < msg.length; i++) sm[i + crypto_sign_BYTES] = msg[i];
2249
- return crypto_sign_open(m, sm, sm.length, publicKey) >= 0;
2250
- };
2251
- nacl.sign.keyPair = function() {
2252
- var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
2253
- var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
2254
- crypto_sign_keypair(pk, sk);
2255
- return { publicKey: pk, secretKey: sk };
2256
- };
2257
- nacl.sign.keyPair.fromSecretKey = function(secretKey) {
2258
- checkArrayTypes(secretKey);
2259
- if (secretKey.length !== crypto_sign_SECRETKEYBYTES)
2260
- throw new Error("bad secret key size");
2261
- var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
2262
- for (var i = 0; i < pk.length; i++) pk[i] = secretKey[32 + i];
2263
- return { publicKey: pk, secretKey: new Uint8Array(secretKey) };
2264
- };
2265
- nacl.sign.keyPair.fromSeed = function(seed) {
2266
- checkArrayTypes(seed);
2267
- if (seed.length !== crypto_sign_SEEDBYTES)
2268
- throw new Error("bad seed size");
2269
- var pk = new Uint8Array(crypto_sign_PUBLICKEYBYTES);
2270
- var sk = new Uint8Array(crypto_sign_SECRETKEYBYTES);
2271
- for (var i = 0; i < 32; i++) sk[i] = seed[i];
2272
- crypto_sign_keypair(pk, sk, true);
2273
- return { publicKey: pk, secretKey: sk };
2274
- };
2275
- nacl.sign.publicKeyLength = crypto_sign_PUBLICKEYBYTES;
2276
- nacl.sign.secretKeyLength = crypto_sign_SECRETKEYBYTES;
2277
- nacl.sign.seedLength = crypto_sign_SEEDBYTES;
2278
- nacl.sign.signatureLength = crypto_sign_BYTES;
2279
- nacl.hash = function(msg) {
2280
- checkArrayTypes(msg);
2281
- var h = new Uint8Array(crypto_hash_BYTES);
2282
- crypto_hash(h, msg, msg.length);
2283
- return h;
2284
- };
2285
- nacl.hash.hashLength = crypto_hash_BYTES;
2286
- nacl.verify = function(x, y) {
2287
- checkArrayTypes(x, y);
2288
- if (x.length === 0 || y.length === 0) return false;
2289
- if (x.length !== y.length) return false;
2290
- return vn(x, 0, y, 0, x.length) === 0 ? true : false;
2291
- };
2292
- nacl.setPRNG = function(fn) {
2293
- randombytes = fn;
2294
- };
2295
- (function() {
2296
- var crypto2 = typeof self !== "undefined" ? self.crypto || self.msCrypto : null;
2297
- if (crypto2 && crypto2.getRandomValues) {
2298
- var QUOTA = 65536;
2299
- nacl.setPRNG(function(x, n) {
2300
- var i, v = new Uint8Array(n);
2301
- for (i = 0; i < n; i += QUOTA) {
2302
- crypto2.getRandomValues(v.subarray(i, i + Math.min(n - i, QUOTA)));
2303
- }
2304
- for (i = 0; i < n; i++) x[i] = v[i];
2305
- cleanup(v);
2306
- });
2307
- } else if (typeof __require !== "undefined") {
2308
- crypto2 = require_crypto();
2309
- if (crypto2 && crypto2.randomBytes) {
2310
- nacl.setPRNG(function(x, n) {
2311
- var i, v = crypto2.randomBytes(n);
2312
- for (i = 0; i < n; i++) x[i] = v[i];
2313
- cleanup(v);
2314
- });
2315
- }
2316
- }
2317
- })();
2318
- })(typeof module !== "undefined" && module.exports ? module.exports : self.nacl = self.nacl || {});
2319
- }
2320
- });
2321
9
 
2322
10
  // src/types.ts
2323
11
  var RsaSize = /* @__PURE__ */ ((RsaSize2) => {
@@ -2401,10 +89,6 @@
2401
89
  verify: () => verify2
2402
90
  });
2403
91
 
2404
- // node_modules/@substrate-system/one-webcrypto/browser.mjs
2405
- var _globalReference = globalThis || window || self;
2406
- var webcrypto = _globalReference.crypto;
2407
-
2408
92
  // node_modules/uint8arrays/dist/src/alloc.js
2409
93
  function allocUnsafe(size = 0) {
2410
94
  return new Uint8Array(size);
@@ -3345,9 +1029,9 @@
3345
1029
  equals(other) {
3346
1030
  return _CID.equals(this, other);
3347
1031
  }
3348
- static equals(self2, other) {
1032
+ static equals(self, other) {
3349
1033
  const unknown = other;
3350
- return unknown != null && self2.code === unknown.code && self2.version === unknown.version && equals2(self2.multihash, unknown.multihash);
1034
+ return unknown != null && self.code === unknown.code && self.version === unknown.version && equals2(self.multihash, unknown.multihash);
3351
1035
  }
3352
1036
  toString(base3) {
3353
1037
  return format(this, base3);
@@ -3360,7 +1044,7 @@
3360
1044
  }
3361
1045
  [Symbol.toStringTag] = "CID";
3362
1046
  // Legacy
3363
- [Symbol.for("nodejs.util.inspect.custom")]() {
1047
+ [/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
3364
1048
  return `CID(${this.toString()})`;
3365
1049
  }
3366
1050
  /**
@@ -3590,7 +1274,7 @@
3590
1274
  return bytes;
3591
1275
  }
3592
1276
  __name(encodeCID, "encodeCID");
3593
- var cidSymbol = Symbol.for("@ipld/js-cid/CID");
1277
+ var cidSymbol = /* @__PURE__ */ Symbol.for("@ipld/js-cid/CID");
3594
1278
 
3595
1279
  // node_modules/multiformats/dist/src/basics.js
3596
1280
  var bases = { ...identity_exports, ...base2_exports, ...base8_exports, ...base10_exports, ...base16_exports, ...base32_exports, ...base36_exports, ...base58_exports, ...base64_exports, ...base256emoji_exports };
@@ -3707,6 +1391,7 @@
3707
1391
  var SALT_LENGTH = 16;
3708
1392
 
3709
1393
  // src/util.ts
1394
+ var webcrypto = globalThis.crypto;
3710
1395
  var InvalidKeyUse = new Error("Invalid key use. Please use 'encryption' or 'signing");
3711
1396
  var InvalidMaxValue = new Error("Max must be less than 256 and greater than 0");
3712
1397
  function toArrayBuffer(data) {
@@ -3885,7 +1570,7 @@
3885
1570
  __name(publicExponent, "publicExponent");
3886
1571
 
3887
1572
  // src/crypto.ts
3888
- var import_tweetnacl = __toESM(require_nacl_fast(), 1);
1573
+ var webcrypto2 = globalThis.crypto;
3889
1574
  var did = {
3890
1575
  keyTypes: {
3891
1576
  "bls12-381": {
@@ -3952,7 +1637,19 @@
3952
1637
  if (sig.length !== 64) {
3953
1638
  throw new Error(`Invalid Ed25519 signature size: ${sig.length} bytes, expected 64`);
3954
1639
  }
3955
- return import_tweetnacl.default.sign.detached.verify(msg, sig, pub);
1640
+ const key = await webcrypto2.subtle.importKey(
1641
+ "raw",
1642
+ toArrayBuffer(pub),
1643
+ { name: "Ed25519" },
1644
+ false,
1645
+ ["verify"]
1646
+ );
1647
+ return webcrypto2.subtle.verify(
1648
+ { name: "Ed25519" },
1649
+ key,
1650
+ toArrayBuffer(sig),
1651
+ toArrayBuffer(msg)
1652
+ );
3956
1653
  }
3957
1654
  __name(ed25519Verify, "ed25519Verify");
3958
1655
  async function rsaVerify({
@@ -3967,7 +1664,7 @@
3967
1664
  return rsaOperations.verify(
3968
1665
  message,
3969
1666
  signature,
3970
- await webcrypto.subtle.importKey(
1667
+ await webcrypto2.subtle.importKey(
3971
1668
  "spki",
3972
1669
  toArrayBuffer(pub),
3973
1670
  { name: RSA_SIGN_ALGORITHM, hash: RSA_HASHING_ALGORITHM },
@@ -3980,7 +1677,7 @@
3980
1677
  __name(rsaVerify, "rsaVerify");
3981
1678
  var rsaOperations = {
3982
1679
  verify: /* @__PURE__ */ __name(async function rsaVerify2(msg, sig, publicKey, charSize = DEFAULT_CHAR_SIZE, hashAlg = DEFAULT_HASH_ALGORITHM) {
3983
- return webcrypto.subtle.verify(
1680
+ return webcrypto2.subtle.verify(
3984
1681
  {
3985
1682
  name: RSA_SIGN_ALGORITHM,
3986
1683
  saltLength: SALT_LENGTH
@@ -3991,7 +1688,7 @@
3991
1688
  );
3992
1689
  }, "rsaVerify"),
3993
1690
  sign: /* @__PURE__ */ __name(async function sign(msg, privateKey, charSize = DEFAULT_CHAR_SIZE) {
3994
- return webcrypto.subtle.sign(
1691
+ return webcrypto2.subtle.sign(
3995
1692
  { name: RSA_SIGN_ALGORITHM, saltLength: SALT_LENGTH },
3996
1693
  privateKey,
3997
1694
  normalizeUnicodeToBuf(msg, charSize)
@@ -4011,7 +1708,7 @@
4011
1708
  "exchange" /* Exchange */
4012
1709
  ) : publicKey;
4013
1710
  }
4014
- return webcrypto.subtle.encrypt(
1711
+ return webcrypto2.subtle.encrypt(
4015
1712
  { name: RSA_ALGORITHM },
4016
1713
  pubKey,
4017
1714
  normalizeUnicodeToBuf(msg, charSize)
@@ -4028,7 +1725,7 @@
4028
1725
  } else {
4029
1726
  data = _data;
4030
1727
  }
4031
- const arrayBuffer = await webcrypto.subtle.decrypt(
1728
+ const arrayBuffer = await webcrypto2.subtle.decrypt(
4032
1729
  { name: RSA_ALGORITHM },
4033
1730
  key,
4034
1731
  data instanceof Uint8Array ? toArrayBuffer(data) : data
@@ -4042,7 +1739,7 @@
4042
1739
  const alg = use === "exchange" /* Exchange */ ? RSA_ALGORITHM : RSA_SIGN_ALGORITHM;
4043
1740
  const uses = use === "exchange" /* Exchange */ ? ["encrypt"] : ["verify"];
4044
1741
  const buf = typeof base64Key === "string" ? base64ToArrBuf(stripKeyHeader(base64Key)) : base64Key;
4045
- return webcrypto.subtle.importKey("spki", buf, {
1742
+ return webcrypto2.subtle.importKey("spki", buf, {
4046
1743
  name: alg,
4047
1744
  hash: { name: hashAlg }
4048
1745
  }, true, uses);
@@ -4072,7 +1769,7 @@
4072
1769
  }
4073
1770
  __name(hasProp, "hasProp");
4074
1771
  function importRsaKey(key, keyUsages) {
4075
- return webcrypto.subtle.importKey(
1772
+ return webcrypto2.subtle.importKey(
4076
1773
  "spki",
4077
1774
  key instanceof Uint8Array ? toArrayBuffer(key) : key,
4078
1775
  { name: RSA_ALGORITHM, hash: RSA_HASHING_ALGORITHM },
@@ -4086,7 +1783,7 @@
4086
1783
  if (_publicKey instanceof CryptoKey) {
4087
1784
  keyType = _publicKey.algorithm.name.includes("RSA") ? "rsa" : "ed25519";
4088
1785
  const format2 = keyType === "ed25519" ? "raw" : "spki";
4089
- const exported = await webcrypto.subtle.exportKey(format2, _publicKey);
1786
+ const exported = await webcrypto2.subtle.exportKey(format2, _publicKey);
4090
1787
  publicKey = new Uint8Array(exported);
4091
1788
  } else {
4092
1789
  publicKey = _publicKey;
@@ -4117,10 +1814,10 @@
4117
1814
  }
4118
1815
  __name(keyTypeFromDid, "keyTypeFromDid");
4119
1816
  async function getPublicKeyAsArrayBuffer(keypair) {
4120
- const spki = keypair instanceof CryptoKey ? await webcrypto.subtle.exportKey(
1817
+ const spki = keypair instanceof CryptoKey ? await webcrypto2.subtle.exportKey(
4121
1818
  "spki",
4122
1819
  keypair
4123
- ) : await webcrypto.subtle.exportKey(
1820
+ ) : await webcrypto2.subtle.exportKey(
4124
1821
  "spki",
4125
1822
  keypair.publicKey
4126
1823
  );
@@ -4160,6 +1857,7 @@
4160
1857
  __name(didToPublicKey2, "didToPublicKey");
4161
1858
 
4162
1859
  // src/aes/index.ts
1860
+ var webcrypto3 = globalThis.crypto;
4163
1861
  var AES = {
4164
1862
  /**
4165
1863
  * Factory function -- create a new AES key. Defaults are `AES-GCM`
@@ -4173,7 +1871,7 @@
4173
1871
  }) {
4174
1872
  const length2 = opts.length || DEFAULT_SYMM_LENGTH;
4175
1873
  const alg = opts.alg || DEFAULT_SYMM_ALGORITHM;
4176
- return webcrypto.subtle.generateKey({
1874
+ return webcrypto3.subtle.generateKey({
4177
1875
  name: alg,
4178
1876
  length: length2
4179
1877
  }, true, ["encrypt", "decrypt"]);
@@ -4184,7 +1882,7 @@
4184
1882
  */
4185
1883
  export: Object.assign(
4186
1884
  async (key) => {
4187
- const raw = await webcrypto.subtle.exportKey("raw", key);
1885
+ const raw = await webcrypto3.subtle.exportKey("raw", key);
4188
1886
  return new Uint8Array(raw);
4189
1887
  },
4190
1888
  {
@@ -4204,7 +1902,7 @@
4204
1902
  encrypt,
4205
1903
  async decrypt(encryptedData, cryptoKey, iv) {
4206
1904
  const key = isCryptoKey(cryptoKey) ? cryptoKey : await importAesKey(cryptoKey);
4207
- const decrypted = iv ? await webcrypto.subtle.decrypt(
1905
+ const decrypted = iv ? await webcrypto3.subtle.decrypt(
4208
1906
  {
4209
1907
  name: AES_GCM,
4210
1908
  iv: toArrayBuffer(iv)
@@ -4216,7 +1914,7 @@
4216
1914
  }
4217
1915
  };
4218
1916
  function importAesKey(key, length2) {
4219
- return webcrypto.subtle.importKey(
1917
+ return webcrypto3.subtle.importKey(
4220
1918
  "raw",
4221
1919
  key instanceof Uint8Array ? toArrayBuffer(key) : key,
4222
1920
  {
@@ -4232,7 +1930,7 @@
4232
1930
  const key = isCryptoKey(cryptoKey) ? cryptoKey : await importAesKey(cryptoKey);
4233
1931
  const encrypted = iv ? (
4234
1932
  // was an `iv` passed in? then encrypt here
4235
- await webcrypto.subtle.encrypt(
1933
+ await webcrypto3.subtle.encrypt(
4236
1934
  {
4237
1935
  name: AES_GCM,
4238
1936
  iv: toArrayBuffer(iv)
@@ -4249,7 +1947,7 @@
4249
1947
  const data = normalizeUnicodeToBuf(msg, opts?.charsize ?? DEFAULT_CHAR_SIZE);
4250
1948
  const importedKey = typeof key === "string" ? await importKey(key, opts) : key;
4251
1949
  const iv = opts?.iv || randomBuf(IV_LENGTH);
4252
- const cipherBuf = await webcrypto.subtle.encrypt({
1950
+ const cipherBuf = await webcrypto3.subtle.encrypt({
4253
1951
  name: AES_GCM,
4254
1952
  iv
4255
1953
  }, importedKey, data);
@@ -4261,7 +1959,7 @@
4261
1959
  const importedKey = typeof key === "string" ? await importKey(key, opts) : key;
4262
1960
  const iv = cipherText.slice(0, IV_LENGTH);
4263
1961
  const cipherBytes = cipherText.slice(IV_LENGTH);
4264
- const msgBuff = await webcrypto.subtle.decrypt({
1962
+ const msgBuff = await webcrypto3.subtle.decrypt({
4265
1963
  name: DEFAULT_SYMM_ALGORITHM,
4266
1964
  iv
4267
1965
  }, importedKey, cipherBytes);
@@ -4321,29 +2019,83 @@
4321
2019
  }
4322
2020
  __name(delMany, "delMany");
4323
2021
 
2022
+ // src/errors.ts
2023
+ var KeyDoesNotExist = new Error("Key does not exist. Make sure you properly instantiated the keystore.");
2024
+ var NotKeyPair = new Error("Retrieved a symmetric key when an asymmetric keypair was expected. Please use a different key name.");
2025
+ var NotKey = new Error("Retrieved an asymmetric keypair when an symmetric key was expected. Please use a different key name.");
2026
+ var ECCNotEnabled = new Error("ECC is not enabled for this browser. Please use RSA instead.");
2027
+ var UnsupportedCrypto = new Error("Cryptosystem not supported. Please use ECC or RSA");
2028
+ var InvalidKeyUse2 = new Error("Invalid key use. Please use 'exchange' or 'write'");
2029
+ var InvalidMaxValue2 = new Error("Max must be less than 256 and greater than 0");
2030
+ var KeysDeletedError = class extends Error {
2031
+ static {
2032
+ __name(this, "KeysDeletedError");
2033
+ }
2034
+ constructor(msg) {
2035
+ super(msg || "These keys were deleted");
2036
+ this.name = "KeysDeletedError";
2037
+ }
2038
+ };
2039
+ function checkValidKeyUse2(use) {
2040
+ checkValid2(use, ["exchange" /* Exchange */, "write" /* Write */, "signing" /* Sign */], InvalidKeyUse2);
2041
+ }
2042
+ __name(checkValidKeyUse2, "checkValidKeyUse");
2043
+ function checkValid2(toCheck, opts, error) {
2044
+ const match = opts.some((opt) => opt === toCheck);
2045
+ if (!match) {
2046
+ throw error;
2047
+ }
2048
+ }
2049
+ __name(checkValid2, "checkValid");
2050
+
4324
2051
  // src/_base.ts
4325
2052
  var AbstractKeys = class _AbstractKeys {
4326
2053
  static {
4327
2054
  __name(this, "AbstractKeys");
4328
2055
  }
4329
2056
  DID;
4330
- exchangeKey;
4331
- writeKey;
4332
2057
  hasPersisted;
4333
2058
  isSessionOnly;
2059
+ /**
2060
+ * Have these keys been deleted? A deleted keypair is terminal -- the key
2061
+ * material is gone, and any use of it throws.
2062
+ */
2063
+ destroyed;
2064
+ /**
2065
+ * The `indexedDB` names this keypair was loaded from, and the names
2066
+ * `persist` and `delete` will use.
2067
+ */
2068
+ exchangeKeyName;
2069
+ writeKeyName;
4334
2070
  // type:'ecc'|'rsa'
4335
2071
  static EXCHANGE_KEY_NAME;
4336
2072
  // needs to be defined by child class
4337
2073
  static WRITE_KEY_NAME;
4338
2074
  static _instance;
4339
2075
  // a cache for indexedDB
2076
+ // the key material -- read it via the `exchangeKey`/`writeKey` getters,
2077
+ // which throw if this instance was deleted
2078
+ _exchangeKey;
2079
+ _writeKey;
4340
2080
  constructor(opts) {
4341
2081
  const { keys } = opts;
2082
+ const ctor = this.constructor;
4342
2083
  this.DID = opts.did;
4343
- this.exchangeKey = keys.exchange;
4344
- this.writeKey = keys.write;
2084
+ this._exchangeKey = keys.exchange;
2085
+ this._writeKey = keys.write;
4345
2086
  this.hasPersisted = opts.hasPersisted;
4346
2087
  this.isSessionOnly = !!opts.isSessionOnly;
2088
+ this.destroyed = false;
2089
+ this.exchangeKeyName = opts.exchangeKeyName || ctor.EXCHANGE_KEY_NAME;
2090
+ this.writeKeyName = opts.writeKeyName || ctor.WRITE_KEY_NAME;
2091
+ }
2092
+ get exchangeKey() {
2093
+ if (this.destroyed || !this._exchangeKey) throw new KeysDeletedError();
2094
+ return this._exchangeKey;
2095
+ }
2096
+ get writeKey() {
2097
+ if (this.destroyed || !this._writeKey) throw new KeysDeletedError();
2098
+ return this._writeKey;
4347
2099
  }
4348
2100
  publicExchangeKeyAsString(format2) {
4349
2101
  return this.publicExchangeKey.asString(format2);
@@ -4396,24 +2148,64 @@
4396
2148
  * Save this keys instance to `indexedDB`.
4397
2149
  */
4398
2150
  async persist() {
2151
+ if (this.destroyed) throw new KeysDeletedError();
4399
2152
  if (this.isSessionOnly) return;
4400
- const exchange = this.constructor.EXCHANGE_KEY_NAME;
4401
- const write = this.constructor.WRITE_KEY_NAME;
4402
2153
  await Promise.all([
4403
- set(exchange, this.exchangeKey),
4404
- set(write, this.writeKey)
2154
+ set(this.exchangeKeyName, this.exchangeKey),
2155
+ set(this.writeKeyName, this.writeKey)
4405
2156
  ]);
4406
2157
  this.hasPersisted = true;
4407
2158
  }
4408
2159
  /**
4409
- * Delete the keys stored in indexedDB.
2160
+ * Delete this keypair. This deletes the keys from indexedDB, drops the
2161
+ * in-memory key material, and clears the instance cache, so `load` will
2162
+ * not hand out these keys again.
2163
+ *
2164
+ * After this, the instance is `destroyed` -- using it throws
2165
+ * a `KeysDeletedError`.
4410
2166
  */
4411
2167
  async delete() {
4412
- await delMany([
4413
- this.constructor.EXCHANGE_KEY_NAME,
4414
- this.constructor.WRITE_KEY_NAME
4415
- ]);
2168
+ const exchangeName = this.exchangeKeyName;
2169
+ const writeName = this.writeKeyName;
2170
+ await delMany([exchangeName, writeName]);
2171
+ const ctor = this.constructor;
2172
+ ctor._invalidate(exchangeName, writeName);
2173
+ this._destroy();
2174
+ }
2175
+ /**
2176
+ * Drop the in-memory key material. Internal -- call `delete` instead.
2177
+ */
2178
+ _destroy() {
2179
+ this.destroyed = true;
4416
2180
  this.hasPersisted = false;
2181
+ this._exchangeKey = null;
2182
+ this._writeKey = null;
2183
+ }
2184
+ /**
2185
+ * If the cached instance was loaded from the given names, then its keys
2186
+ * are gone too. Destroy it, and clear the cache. Internal.
2187
+ */
2188
+ static _invalidate(exchangeName, writeName) {
2189
+ const cached = this._instance;
2190
+ if (!cached) return;
2191
+ if (cached.exchangeKeyName !== exchangeName) return;
2192
+ if (cached.writeKeyName !== writeName) return;
2193
+ cached._destroy();
2194
+ this._instance = null;
2195
+ }
2196
+ /**
2197
+ * Delete a stored keypair without loading it first. Deletes the keys from
2198
+ * indexedDB, and destroys the cached instance, if there is one for
2199
+ * these names.
2200
+ *
2201
+ * @param {{ encryptionKeyName, writeKeyName }} [opts] The indexedDB names
2202
+ * to delete. Defaults to this class's names.
2203
+ */
2204
+ static async delete(opts = {}) {
2205
+ const exchangeName = opts.encryptionKeyName || this.EXCHANGE_KEY_NAME;
2206
+ const writeName = opts.writeKeyName || this.WRITE_KEY_NAME;
2207
+ await delMany([exchangeName, writeName]);
2208
+ this._invalidate(exchangeName, writeName);
4417
2209
  }
4418
2210
  /**
4419
2211
  * Return a 32-character, DNS friendly hash of the public signing key.
@@ -4466,14 +2258,15 @@
4466
2258
  static async load(opts = {
4467
2259
  session: false
4468
2260
  }) {
4469
- if (this._instance) return this._instance;
2261
+ const exchangeKeyName = opts.encryptionKeyName || this.EXCHANGE_KEY_NAME;
2262
+ const writeKeyName = opts.writeKeyName || this.WRITE_KEY_NAME;
2263
+ const cached = this._instance;
2264
+ if (cached && !cached.destroyed && cached.exchangeKeyName === exchangeKeyName && cached.writeKeyName === writeKeyName) {
2265
+ return cached;
2266
+ }
4470
2267
  let hasPersisted = true;
4471
- let exchangeKeys = await get(
4472
- opts.encryptionKeyName || this.EXCHANGE_KEY_NAME
4473
- );
4474
- let writeKeys = await get(
4475
- opts.writeKeyName || this.WRITE_KEY_NAME
4476
- );
2268
+ let exchangeKeys = await get(exchangeKeyName);
2269
+ let writeKeys = await get(writeKeyName);
4477
2270
  if (!exchangeKeys) {
4478
2271
  hasPersisted = false;
4479
2272
  exchangeKeys = await this._createExchangeKeys(opts.extractable);
@@ -4491,7 +2284,9 @@
4491
2284
  keys: { exchange: exchangeKeys, write: writeKeys },
4492
2285
  did: did2,
4493
2286
  hasPersisted,
4494
- isSessionOnly: !!opts.session
2287
+ isSessionOnly: !!opts.session,
2288
+ exchangeKeyName,
2289
+ writeKeyName
4495
2290
  });
4496
2291
  this._instance = keys;
4497
2292
  return keys;
@@ -4537,11 +2332,12 @@
4537
2332
  __name(getDeviceName, "getDeviceName");
4538
2333
 
4539
2334
  // src/rsa/index.ts
2335
+ var webcrypto4 = globalThis.crypto;
4540
2336
  function toArrayBuffer2(data) {
4541
2337
  return new Uint8Array(data).buffer;
4542
2338
  }
4543
2339
  __name(toArrayBuffer2, "toArrayBuffer");
4544
- var RsaKeys = class _RsaKeys extends AbstractKeys {
2340
+ var RsaKeys = class extends AbstractKeys {
4545
2341
  static {
4546
2342
  __name(this, "RsaKeys");
4547
2343
  }
@@ -4561,11 +2357,6 @@
4561
2357
  static async create(session, extractable, keys) {
4562
2358
  return await super.create(session, extractable, keys);
4563
2359
  }
4564
- constructor(opts) {
4565
- super(opts);
4566
- _RsaKeys.EXCHANGE_KEY_NAME = opts.exchangeKeyName || DEFAULT_RSA_EXCHANGE;
4567
- _RsaKeys.WRITE_KEY_NAME = opts.writeKeyName || DEFAULT_RSA_WRITE;
4568
- }
4569
2360
  static async _createExchangeKeys(extractable = false) {
4570
2361
  const exchangeKeys = await makeRSAKeypair(
4571
2362
  DEFAULT_RSA_SIZE,
@@ -4593,7 +2384,7 @@
4593
2384
  async toJson(format2) {
4594
2385
  const pubEnc = this.publicExchangeKey;
4595
2386
  const did2 = this.DID;
4596
- const spki = await webcrypto.subtle.exportKey(
2387
+ const spki = await webcrypto4.subtle.exportKey(
4597
2388
  "spki",
4598
2389
  pubEnc
4599
2390
  );
@@ -4776,7 +2567,7 @@
4776
2567
  };
4777
2568
  async function encrypt2(data, cryptoKey, format2, iv) {
4778
2569
  const key = isCryptoKey(cryptoKey) ? cryptoKey : await importAesKey(cryptoKey);
4779
- const encrypted = iv ? await webcrypto.subtle.encrypt({ name: AES_GCM, iv: toArrayBuffer2(iv) }, key, toArrayBuffer2(data)) : await encryptBytes2(data, key);
2570
+ const encrypted = iv ? await webcrypto4.subtle.encrypt({ name: AES_GCM, iv: toArrayBuffer2(iv) }, key, toArrayBuffer2(data)) : await encryptBytes2(data, key);
4780
2571
  if (format2 && format2 === "arraybuffer") return encrypted;
4781
2572
  return new Uint8Array(encrypted);
4782
2573
  }
@@ -4785,7 +2576,7 @@
4785
2576
  const data = normalizeUnicodeToBuf(msg, opts?.charsize ?? DEFAULT_CHAR_SIZE);
4786
2577
  const importedKey = typeof key === "string" ? await importKey(key, opts) : key;
4787
2578
  const iv = opts?.iv || randomBuf(IV_LENGTH);
4788
- const cipherBuf = await webcrypto.subtle.encrypt({
2579
+ const cipherBuf = await webcrypto4.subtle.encrypt({
4789
2580
  name: AES_GCM,
4790
2581
  iv
4791
2582
  }, importedKey, data);
@@ -4802,28 +2593,7 @@
4802
2593
  importPublicKey: () => importPublicKey,
4803
2594
  verify: () => verify3
4804
2595
  });
4805
-
4806
- // src/errors.ts
4807
- var KeyDoesNotExist = new Error("Key does not exist. Make sure you properly instantiated the keystore.");
4808
- var NotKeyPair = new Error("Retrieved a symmetric key when an asymmetric keypair was expected. Please use a different key name.");
4809
- var NotKey = new Error("Retrieved an asymmetric keypair when an symmetric key was expected. Please use a different key name.");
4810
- var ECCNotEnabled = new Error("ECC is not enabled for this browser. Please use RSA instead.");
4811
- var UnsupportedCrypto = new Error("Cryptosystem not supported. Please use ECC or RSA");
4812
- var InvalidKeyUse2 = new Error("Invalid key use. Please use 'exchange' or 'write'");
4813
- var InvalidMaxValue2 = new Error("Max must be less than 256 and greater than 0");
4814
- function checkValidKeyUse2(use) {
4815
- checkValid2(use, ["exchange" /* Exchange */, "write" /* Write */, "signing" /* Sign */], InvalidKeyUse2);
4816
- }
4817
- __name(checkValidKeyUse2, "checkValidKeyUse");
4818
- function checkValid2(toCheck, opts, error) {
4819
- const match = opts.some((opt) => opt === toCheck);
4820
- if (!match) {
4821
- throw error;
4822
- }
4823
- }
4824
- __name(checkValid2, "checkValid");
4825
-
4826
- // src/ecc/index.ts
2596
+ var webcrypto5 = globalThis.crypto;
4827
2597
  function toArrayBuffer3(data) {
4828
2598
  return new Uint8Array(data).buffer;
4829
2599
  }
@@ -4848,11 +2618,6 @@
4848
2618
  static async create(session, extractable, keys) {
4849
2619
  return await super.create(session, extractable, keys);
4850
2620
  }
4851
- constructor(opts) {
4852
- super(opts);
4853
- _EccKeys.EXCHANGE_KEY_NAME = opts.exchangeKeyName || DEFAULT_ECC_EXCHANGE;
4854
- _EccKeys.WRITE_KEY_NAME = opts.writeKeyName || DEFAULT_ECC_WRITE;
4855
- }
4856
2621
  get publicExchangeKey() {
4857
2622
  const publicKey = this.exchangeKey.publicKey;
4858
2623
  return Object.assign(publicKey, {
@@ -4874,7 +2639,7 @@
4874
2639
  });
4875
2640
  }
4876
2641
  static async _createExchangeKeys(extractable = false) {
4877
- return await webcrypto.subtle.generateKey(
2642
+ return await webcrypto5.subtle.generateKey(
4878
2643
  {
4879
2644
  name: ECC_EXCHANGE_ALGORITHM
4880
2645
  // namedCurve: EccCurve.X25519
@@ -4884,7 +2649,7 @@
4884
2649
  );
4885
2650
  }
4886
2651
  static async _createWriteKeys(extractable = false) {
4887
- return await webcrypto.subtle.generateKey(
2652
+ return await webcrypto5.subtle.generateKey(
4888
2653
  {
4889
2654
  name: ECC_WRITE_ALGORITHM
4890
2655
  },
@@ -4899,14 +2664,7 @@
4899
2664
  static async load(opts = {
4900
2665
  session: false
4901
2666
  }) {
4902
- if (this._instance) return this._instance;
4903
- const exchangeKeyName = opts.encryptionKeyName || DEFAULT_ECC_EXCHANGE;
4904
- const writeKeyName = opts.writeKeyName || DEFAULT_ECC_WRITE;
4905
- return super.load({
4906
- ...opts,
4907
- encryptionKeyName: exchangeKeyName,
4908
- writeKeyName
4909
- });
2667
+ return super.load(opts);
4910
2668
  }
4911
2669
  /**
4912
2670
  * Serialize this keys instance. Will return an object of
@@ -5120,7 +2878,7 @@
5120
2878
  async decrypt(msg, aesAlgorithm, info) {
5121
2879
  const encrypted = normalizeToBuf(msg, base64ToArrBuf);
5122
2880
  const ephemeralPubKeyBuf = encrypted.slice(0, X25519_PUBLIC_KEY_LENGTH);
5123
- const ephemeralPublicKey = await webcrypto.subtle.importKey(
2881
+ const ephemeralPublicKey = await webcrypto5.subtle.importKey(
5124
2882
  "raw",
5125
2883
  ephemeralPubKeyBuf,
5126
2884
  { name: ECC_EXCHANGE_ALGORITHM },
@@ -5216,7 +2974,7 @@
5216
2974
  } else {
5217
2975
  data = msg;
5218
2976
  }
5219
- const signature = await webcrypto.subtle.sign(
2977
+ const signature = await webcrypto5.subtle.sign(
5220
2978
  { name: ECC_WRITE_ALGORITHM },
5221
2979
  this.writeKey.privateKey,
5222
2980
  toArrayBuffer3(data)
@@ -5247,7 +3005,7 @@
5247
3005
  const uses = use === "exchange" /* Exchange */ ? [] : ["verify"];
5248
3006
  const buf = base64ToArrBuf(base64Key);
5249
3007
  const algorithm = curve === "X25519" /* X25519 */ ? { name: alg } : { name: alg, namedCurve: curve };
5250
- return webcrypto.subtle.importKey(
3008
+ return webcrypto5.subtle.importKey(
5251
3009
  "raw",
5252
3010
  buf,
5253
3011
  algorithm,
@@ -5282,7 +3040,7 @@
5282
3040
  throw new Error(`Expected Ed25519 key for ECC verification, got ${_key.type}`);
5283
3041
  }
5284
3042
  const rawKeyBytes = _key.publicKey.slice(-32);
5285
- const publicKey = await webcrypto.subtle.importKey(
3043
+ const publicKey = await webcrypto5.subtle.importKey(
5286
3044
  "raw",
5287
3045
  rawKeyBytes,
5288
3046
  { name: ECC_WRITE_ALGORITHM },
@@ -5304,7 +3062,7 @@
5304
3062
  } else {
5305
3063
  signature = sig;
5306
3064
  }
5307
- const isValid = await webcrypto.subtle.verify(
3065
+ const isValid = await webcrypto5.subtle.verify(
5308
3066
  { name: ECC_WRITE_ALGORITHM },
5309
3067
  publicKey,
5310
3068
  toArrayBuffer3(signature),