swarmlite 0.2.0
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.
- package/README.md +75 -0
- package/bin/swarmlite.mjs +167 -0
- package/package.json +49 -0
- package/src/SwarmVFS.js +274 -0
- package/src/feeds.js +135 -0
- package/src/index.js +97 -0
- package/src/mantaray.js +157 -0
- package/src/memvfs.js +112 -0
- package/src/prepare.js +104 -0
- package/src/publisher.js +240 -0
- package/src/verify.js +267 -0
- package/vendor/js-sha3/LICENSE +20 -0
- package/vendor/js-sha3/PROVENANCE.md +19 -0
- package/vendor/js-sha3/index.js +12 -0
- package/vendor/js-sha3/sha3.js +662 -0
- package/vendor/noble-secp256k1/LICENSE +21 -0
- package/vendor/noble-secp256k1/PROVENANCE.md +17 -0
- package/vendor/noble-secp256k1/index.js +790 -0
- package/vendor/wa-sqlite/LICENSE +21 -0
- package/vendor/wa-sqlite/PROVENANCE.md +18 -0
- package/vendor/wa-sqlite/dist/wa-sqlite-async.mjs +115 -0
- package/vendor/wa-sqlite/dist/wa-sqlite-async.wasm +0 -0
- package/vendor/wa-sqlite/src/VFS.js +172 -0
- package/vendor/wa-sqlite/src/sqlite-api.js +955 -0
- package/vendor/wa-sqlite/src/sqlite-constants.js +271 -0
|
@@ -0,0 +1,662 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [js-sha3]{@link https://github.com/emn178/js-sha3}
|
|
3
|
+
*
|
|
4
|
+
* @version 0.9.3
|
|
5
|
+
* @author Chen, Yi-Cyuan [emn178@gmail.com]
|
|
6
|
+
* @copyright Chen, Yi-Cyuan 2015-2023
|
|
7
|
+
* @license MIT
|
|
8
|
+
*/
|
|
9
|
+
/*jslint bitwise: true */
|
|
10
|
+
(function () {
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
var INPUT_ERROR = 'input is invalid type';
|
|
14
|
+
var FINALIZE_ERROR = 'finalize already called';
|
|
15
|
+
var WINDOW = typeof window === 'object';
|
|
16
|
+
var root = WINDOW ? window : {};
|
|
17
|
+
if (root.JS_SHA3_NO_WINDOW) {
|
|
18
|
+
WINDOW = false;
|
|
19
|
+
}
|
|
20
|
+
var WEB_WORKER = !WINDOW && typeof self === 'object';
|
|
21
|
+
var NODE_JS = !root.JS_SHA3_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
|
|
22
|
+
if (NODE_JS) {
|
|
23
|
+
root = global;
|
|
24
|
+
} else if (WEB_WORKER) {
|
|
25
|
+
root = self;
|
|
26
|
+
}
|
|
27
|
+
var COMMON_JS = !root.JS_SHA3_NO_COMMON_JS && typeof module === 'object' && module.exports;
|
|
28
|
+
var AMD = typeof define === 'function' && define.amd;
|
|
29
|
+
var ARRAY_BUFFER = !root.JS_SHA3_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined';
|
|
30
|
+
var HEX_CHARS = '0123456789abcdef'.split('');
|
|
31
|
+
var SHAKE_PADDING = [31, 7936, 2031616, 520093696];
|
|
32
|
+
var CSHAKE_PADDING = [4, 1024, 262144, 67108864];
|
|
33
|
+
var KECCAK_PADDING = [1, 256, 65536, 16777216];
|
|
34
|
+
var PADDING = [6, 1536, 393216, 100663296];
|
|
35
|
+
var SHIFT = [0, 8, 16, 24];
|
|
36
|
+
var RC = [1, 0, 32898, 0, 32906, 2147483648, 2147516416, 2147483648, 32907, 0, 2147483649,
|
|
37
|
+
0, 2147516545, 2147483648, 32777, 2147483648, 138, 0, 136, 0, 2147516425, 0,
|
|
38
|
+
2147483658, 0, 2147516555, 0, 139, 2147483648, 32905, 2147483648, 32771,
|
|
39
|
+
2147483648, 32770, 2147483648, 128, 2147483648, 32778, 0, 2147483658, 2147483648,
|
|
40
|
+
2147516545, 2147483648, 32896, 2147483648, 2147483649, 0, 2147516424, 2147483648];
|
|
41
|
+
var BITS = [224, 256, 384, 512];
|
|
42
|
+
var SHAKE_BITS = [128, 256];
|
|
43
|
+
var OUTPUT_TYPES = ['hex', 'buffer', 'arrayBuffer', 'array', 'digest'];
|
|
44
|
+
var CSHAKE_BYTEPAD = {
|
|
45
|
+
'128': 168,
|
|
46
|
+
'256': 136
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
var isArray = root.JS_SHA3_NO_NODE_JS || !Array.isArray
|
|
51
|
+
? function (obj) {
|
|
52
|
+
return Object.prototype.toString.call(obj) === '[object Array]';
|
|
53
|
+
}
|
|
54
|
+
: Array.isArray;
|
|
55
|
+
|
|
56
|
+
var isView = (ARRAY_BUFFER && (root.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView))
|
|
57
|
+
? function (obj) {
|
|
58
|
+
return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;
|
|
59
|
+
}
|
|
60
|
+
: ArrayBuffer.isView;
|
|
61
|
+
|
|
62
|
+
// [message: string, isString: bool]
|
|
63
|
+
var formatMessage = function (message) {
|
|
64
|
+
var type = typeof message;
|
|
65
|
+
if (type === 'string') {
|
|
66
|
+
return [message, true];
|
|
67
|
+
}
|
|
68
|
+
if (type !== 'object' || message === null) {
|
|
69
|
+
throw new Error(INPUT_ERROR);
|
|
70
|
+
}
|
|
71
|
+
if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
|
|
72
|
+
return [new Uint8Array(message), false];
|
|
73
|
+
}
|
|
74
|
+
if (!isArray(message) && !isView(message)) {
|
|
75
|
+
throw new Error(INPUT_ERROR);
|
|
76
|
+
}
|
|
77
|
+
return [message, false];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
var empty = function (message) {
|
|
81
|
+
return formatMessage(message)[0].length === 0;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
var cloneArray = function (array) {
|
|
85
|
+
var newArray = [];
|
|
86
|
+
for (var i = 0; i < array.length; ++i) {
|
|
87
|
+
newArray[i] = array[i];
|
|
88
|
+
}
|
|
89
|
+
return newArray;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
var createOutputMethod = function (bits, padding, outputType) {
|
|
93
|
+
return function (message) {
|
|
94
|
+
return new Keccak(bits, padding, bits).update(message)[outputType]();
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
var createShakeOutputMethod = function (bits, padding, outputType) {
|
|
99
|
+
return function (message, outputBits) {
|
|
100
|
+
return new Keccak(bits, padding, outputBits).update(message)[outputType]();
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
var createCshakeOutputMethod = function (bits, padding, outputType) {
|
|
105
|
+
return function (message, outputBits, n, s) {
|
|
106
|
+
return methods['cshake' + bits].update(message, outputBits, n, s)[outputType]();
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
var createKmacOutputMethod = function (bits, padding, outputType) {
|
|
111
|
+
return function (key, message, outputBits, s) {
|
|
112
|
+
return methods['kmac' + bits].update(key, message, outputBits, s)[outputType]();
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
var createOutputMethods = function (method, createMethod, bits, padding) {
|
|
117
|
+
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
|
|
118
|
+
var type = OUTPUT_TYPES[i];
|
|
119
|
+
method[type] = createMethod(bits, padding, type);
|
|
120
|
+
}
|
|
121
|
+
return method;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
var createMethod = function (bits, padding) {
|
|
125
|
+
var method = createOutputMethod(bits, padding, 'hex');
|
|
126
|
+
method.create = function () {
|
|
127
|
+
return new Keccak(bits, padding, bits);
|
|
128
|
+
};
|
|
129
|
+
method.update = function (message) {
|
|
130
|
+
return method.create().update(message);
|
|
131
|
+
};
|
|
132
|
+
return createOutputMethods(method, createOutputMethod, bits, padding);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
var createShakeMethod = function (bits, padding) {
|
|
136
|
+
var method = createShakeOutputMethod(bits, padding, 'hex');
|
|
137
|
+
method.create = function (outputBits) {
|
|
138
|
+
return new Keccak(bits, padding, outputBits);
|
|
139
|
+
};
|
|
140
|
+
method.update = function (message, outputBits) {
|
|
141
|
+
return method.create(outputBits).update(message);
|
|
142
|
+
};
|
|
143
|
+
return createOutputMethods(method, createShakeOutputMethod, bits, padding);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
var createCshakeMethod = function (bits, padding) {
|
|
147
|
+
var w = CSHAKE_BYTEPAD[bits];
|
|
148
|
+
var method = createCshakeOutputMethod(bits, padding, 'hex');
|
|
149
|
+
method.create = function (outputBits, n, s) {
|
|
150
|
+
if (empty(n) && empty(s)) {
|
|
151
|
+
return methods['shake' + bits].create(outputBits);
|
|
152
|
+
} else {
|
|
153
|
+
return new Keccak(bits, padding, outputBits).bytepad([n, s], w);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
method.update = function (message, outputBits, n, s) {
|
|
157
|
+
return method.create(outputBits, n, s).update(message);
|
|
158
|
+
};
|
|
159
|
+
return createOutputMethods(method, createCshakeOutputMethod, bits, padding);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
var createKmacMethod = function (bits, padding) {
|
|
163
|
+
var w = CSHAKE_BYTEPAD[bits];
|
|
164
|
+
var method = createKmacOutputMethod(bits, padding, 'hex');
|
|
165
|
+
method.create = function (key, outputBits, s) {
|
|
166
|
+
return new Kmac(bits, padding, outputBits).bytepad(['KMAC', s], w).bytepad([key], w);
|
|
167
|
+
};
|
|
168
|
+
method.update = function (key, message, outputBits, s) {
|
|
169
|
+
return method.create(key, outputBits, s).update(message);
|
|
170
|
+
};
|
|
171
|
+
return createOutputMethods(method, createKmacOutputMethod, bits, padding);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
var algorithms = [
|
|
175
|
+
{ name: 'keccak', padding: KECCAK_PADDING, bits: BITS, createMethod: createMethod },
|
|
176
|
+
{ name: 'sha3', padding: PADDING, bits: BITS, createMethod: createMethod },
|
|
177
|
+
{ name: 'shake', padding: SHAKE_PADDING, bits: SHAKE_BITS, createMethod: createShakeMethod },
|
|
178
|
+
{ name: 'cshake', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createCshakeMethod },
|
|
179
|
+
{ name: 'kmac', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createKmacMethod }
|
|
180
|
+
];
|
|
181
|
+
|
|
182
|
+
var methods = {}, methodNames = [];
|
|
183
|
+
|
|
184
|
+
for (var i = 0; i < algorithms.length; ++i) {
|
|
185
|
+
var algorithm = algorithms[i];
|
|
186
|
+
var bits = algorithm.bits;
|
|
187
|
+
for (var j = 0; j < bits.length; ++j) {
|
|
188
|
+
var methodName = algorithm.name + '_' + bits[j];
|
|
189
|
+
methodNames.push(methodName);
|
|
190
|
+
methods[methodName] = algorithm.createMethod(bits[j], algorithm.padding);
|
|
191
|
+
if (algorithm.name !== 'sha3') {
|
|
192
|
+
var newMethodName = algorithm.name + bits[j];
|
|
193
|
+
methodNames.push(newMethodName);
|
|
194
|
+
methods[newMethodName] = methods[methodName];
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function Keccak(bits, padding, outputBits) {
|
|
200
|
+
this.blocks = [];
|
|
201
|
+
this.s = [];
|
|
202
|
+
this.padding = padding;
|
|
203
|
+
this.outputBits = outputBits;
|
|
204
|
+
this.reset = true;
|
|
205
|
+
this.finalized = false;
|
|
206
|
+
this.block = 0;
|
|
207
|
+
this.start = 0;
|
|
208
|
+
this.blockCount = (1600 - (bits << 1)) >> 5;
|
|
209
|
+
this.byteCount = this.blockCount << 2;
|
|
210
|
+
this.outputBlocks = outputBits >> 5;
|
|
211
|
+
this.extraBytes = (outputBits & 31) >> 3;
|
|
212
|
+
|
|
213
|
+
for (var i = 0; i < 50; ++i) {
|
|
214
|
+
this.s[i] = 0;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
Keccak.prototype.update = function (message) {
|
|
219
|
+
if (this.finalized) {
|
|
220
|
+
throw new Error(FINALIZE_ERROR);
|
|
221
|
+
}
|
|
222
|
+
var result = formatMessage(message);
|
|
223
|
+
message = result[0];
|
|
224
|
+
var isString = result[1];
|
|
225
|
+
var blocks = this.blocks, byteCount = this.byteCount, length = message.length,
|
|
226
|
+
blockCount = this.blockCount, index = 0, s = this.s, i, code;
|
|
227
|
+
|
|
228
|
+
while (index < length) {
|
|
229
|
+
if (this.reset) {
|
|
230
|
+
this.reset = false;
|
|
231
|
+
blocks[0] = this.block;
|
|
232
|
+
for (i = 1; i < blockCount + 1; ++i) {
|
|
233
|
+
blocks[i] = 0;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (isString) {
|
|
237
|
+
for (i = this.start; index < length && i < byteCount; ++index) {
|
|
238
|
+
code = message.charCodeAt(index);
|
|
239
|
+
if (code < 0x80) {
|
|
240
|
+
blocks[i >> 2] |= code << SHIFT[i++ & 3];
|
|
241
|
+
} else if (code < 0x800) {
|
|
242
|
+
blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
|
|
243
|
+
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
244
|
+
} else if (code < 0xd800 || code >= 0xe000) {
|
|
245
|
+
blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3];
|
|
246
|
+
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
|
|
247
|
+
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
248
|
+
} else {
|
|
249
|
+
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
|
|
250
|
+
blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3];
|
|
251
|
+
blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3];
|
|
252
|
+
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
|
|
253
|
+
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
} else {
|
|
257
|
+
for (i = this.start; index < length && i < byteCount; ++index) {
|
|
258
|
+
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
this.lastByteIndex = i;
|
|
262
|
+
if (i >= byteCount) {
|
|
263
|
+
this.start = i - byteCount;
|
|
264
|
+
this.block = blocks[blockCount];
|
|
265
|
+
for (i = 0; i < blockCount; ++i) {
|
|
266
|
+
s[i] ^= blocks[i];
|
|
267
|
+
}
|
|
268
|
+
f(s);
|
|
269
|
+
this.reset = true;
|
|
270
|
+
} else {
|
|
271
|
+
this.start = i;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return this;
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
Keccak.prototype.encode = function (x, right) {
|
|
278
|
+
var o = x & 255, n = 1;
|
|
279
|
+
var bytes = [o];
|
|
280
|
+
x = x >> 8;
|
|
281
|
+
o = x & 255;
|
|
282
|
+
while (o > 0) {
|
|
283
|
+
bytes.unshift(o);
|
|
284
|
+
x = x >> 8;
|
|
285
|
+
o = x & 255;
|
|
286
|
+
++n;
|
|
287
|
+
}
|
|
288
|
+
if (right) {
|
|
289
|
+
bytes.push(n);
|
|
290
|
+
} else {
|
|
291
|
+
bytes.unshift(n);
|
|
292
|
+
}
|
|
293
|
+
this.update(bytes);
|
|
294
|
+
return bytes.length;
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
Keccak.prototype.encodeString = function (str) {
|
|
298
|
+
var result = formatMessage(str);
|
|
299
|
+
str = result[0];
|
|
300
|
+
var isString = result[1];
|
|
301
|
+
var bytes = 0, length = str.length;
|
|
302
|
+
if (isString) {
|
|
303
|
+
for (var i = 0; i < str.length; ++i) {
|
|
304
|
+
var code = str.charCodeAt(i);
|
|
305
|
+
if (code < 0x80) {
|
|
306
|
+
bytes += 1;
|
|
307
|
+
} else if (code < 0x800) {
|
|
308
|
+
bytes += 2;
|
|
309
|
+
} else if (code < 0xd800 || code >= 0xe000) {
|
|
310
|
+
bytes += 3;
|
|
311
|
+
} else {
|
|
312
|
+
code = 0x10000 + (((code & 0x3ff) << 10) | (str.charCodeAt(++i) & 0x3ff));
|
|
313
|
+
bytes += 4;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
} else {
|
|
317
|
+
bytes = length;
|
|
318
|
+
}
|
|
319
|
+
bytes += this.encode(bytes * 8);
|
|
320
|
+
this.update(str);
|
|
321
|
+
return bytes;
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
Keccak.prototype.bytepad = function (strs, w) {
|
|
325
|
+
var bytes = this.encode(w);
|
|
326
|
+
for (var i = 0; i < strs.length; ++i) {
|
|
327
|
+
bytes += this.encodeString(strs[i]);
|
|
328
|
+
}
|
|
329
|
+
var paddingBytes = (w - bytes % w) % w;
|
|
330
|
+
var zeros = [];
|
|
331
|
+
zeros.length = paddingBytes;
|
|
332
|
+
this.update(zeros);
|
|
333
|
+
return this;
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
Keccak.prototype.finalize = function () {
|
|
337
|
+
if (this.finalized) {
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
this.finalized = true;
|
|
341
|
+
var blocks = this.blocks, i = this.lastByteIndex, blockCount = this.blockCount, s = this.s;
|
|
342
|
+
blocks[i >> 2] |= this.padding[i & 3];
|
|
343
|
+
if (this.lastByteIndex === this.byteCount) {
|
|
344
|
+
blocks[0] = blocks[blockCount];
|
|
345
|
+
for (i = 1; i < blockCount + 1; ++i) {
|
|
346
|
+
blocks[i] = 0;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
blocks[blockCount - 1] |= 0x80000000;
|
|
350
|
+
for (i = 0; i < blockCount; ++i) {
|
|
351
|
+
s[i] ^= blocks[i];
|
|
352
|
+
}
|
|
353
|
+
f(s);
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
Keccak.prototype.toString = Keccak.prototype.hex = function () {
|
|
357
|
+
this.finalize();
|
|
358
|
+
|
|
359
|
+
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
|
|
360
|
+
extraBytes = this.extraBytes, i = 0, j = 0;
|
|
361
|
+
var hex = '', block;
|
|
362
|
+
while (j < outputBlocks) {
|
|
363
|
+
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
|
|
364
|
+
block = s[i];
|
|
365
|
+
hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F] +
|
|
366
|
+
HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F] +
|
|
367
|
+
HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F] +
|
|
368
|
+
HEX_CHARS[(block >> 28) & 0x0F] + HEX_CHARS[(block >> 24) & 0x0F];
|
|
369
|
+
}
|
|
370
|
+
if (j % blockCount === 0) {
|
|
371
|
+
s = cloneArray(s);
|
|
372
|
+
f(s);
|
|
373
|
+
i = 0;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
if (extraBytes) {
|
|
377
|
+
block = s[i];
|
|
378
|
+
hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F];
|
|
379
|
+
if (extraBytes > 1) {
|
|
380
|
+
hex += HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F];
|
|
381
|
+
}
|
|
382
|
+
if (extraBytes > 2) {
|
|
383
|
+
hex += HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F];
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return hex;
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
Keccak.prototype.arrayBuffer = function () {
|
|
390
|
+
this.finalize();
|
|
391
|
+
|
|
392
|
+
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
|
|
393
|
+
extraBytes = this.extraBytes, i = 0, j = 0;
|
|
394
|
+
var bytes = this.outputBits >> 3;
|
|
395
|
+
var buffer;
|
|
396
|
+
if (extraBytes) {
|
|
397
|
+
buffer = new ArrayBuffer((outputBlocks + 1) << 2);
|
|
398
|
+
} else {
|
|
399
|
+
buffer = new ArrayBuffer(bytes);
|
|
400
|
+
}
|
|
401
|
+
var array = new Uint32Array(buffer);
|
|
402
|
+
while (j < outputBlocks) {
|
|
403
|
+
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
|
|
404
|
+
array[j] = s[i];
|
|
405
|
+
}
|
|
406
|
+
if (j % blockCount === 0) {
|
|
407
|
+
s = cloneArray(s);
|
|
408
|
+
f(s);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
if (extraBytes) {
|
|
412
|
+
array[j] = s[i];
|
|
413
|
+
buffer = buffer.slice(0, bytes);
|
|
414
|
+
}
|
|
415
|
+
return buffer;
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
Keccak.prototype.buffer = Keccak.prototype.arrayBuffer;
|
|
419
|
+
|
|
420
|
+
Keccak.prototype.digest = Keccak.prototype.array = function () {
|
|
421
|
+
this.finalize();
|
|
422
|
+
|
|
423
|
+
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
|
|
424
|
+
extraBytes = this.extraBytes, i = 0, j = 0;
|
|
425
|
+
var array = [], offset, block;
|
|
426
|
+
while (j < outputBlocks) {
|
|
427
|
+
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
|
|
428
|
+
offset = j << 2;
|
|
429
|
+
block = s[i];
|
|
430
|
+
array[offset] = block & 0xFF;
|
|
431
|
+
array[offset + 1] = (block >> 8) & 0xFF;
|
|
432
|
+
array[offset + 2] = (block >> 16) & 0xFF;
|
|
433
|
+
array[offset + 3] = (block >> 24) & 0xFF;
|
|
434
|
+
}
|
|
435
|
+
if (j % blockCount === 0) {
|
|
436
|
+
s = cloneArray(s);
|
|
437
|
+
f(s);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
if (extraBytes) {
|
|
441
|
+
offset = j << 2;
|
|
442
|
+
block = s[i];
|
|
443
|
+
array[offset] = block & 0xFF;
|
|
444
|
+
if (extraBytes > 1) {
|
|
445
|
+
array[offset + 1] = (block >> 8) & 0xFF;
|
|
446
|
+
}
|
|
447
|
+
if (extraBytes > 2) {
|
|
448
|
+
array[offset + 2] = (block >> 16) & 0xFF;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
return array;
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
function Kmac(bits, padding, outputBits) {
|
|
455
|
+
Keccak.call(this, bits, padding, outputBits);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
Kmac.prototype = new Keccak();
|
|
459
|
+
|
|
460
|
+
Kmac.prototype.finalize = function () {
|
|
461
|
+
this.encode(this.outputBits, true);
|
|
462
|
+
return Keccak.prototype.finalize.call(this);
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
var f = function (s) {
|
|
466
|
+
var h, l, n, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9,
|
|
467
|
+
b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17,
|
|
468
|
+
b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33,
|
|
469
|
+
b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45, b46, b47, b48, b49;
|
|
470
|
+
for (n = 0; n < 48; n += 2) {
|
|
471
|
+
c0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40];
|
|
472
|
+
c1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41];
|
|
473
|
+
c2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42];
|
|
474
|
+
c3 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43];
|
|
475
|
+
c4 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44];
|
|
476
|
+
c5 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45];
|
|
477
|
+
c6 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46];
|
|
478
|
+
c7 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47];
|
|
479
|
+
c8 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48];
|
|
480
|
+
c9 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49];
|
|
481
|
+
|
|
482
|
+
h = c8 ^ ((c2 << 1) | (c3 >>> 31));
|
|
483
|
+
l = c9 ^ ((c3 << 1) | (c2 >>> 31));
|
|
484
|
+
s[0] ^= h;
|
|
485
|
+
s[1] ^= l;
|
|
486
|
+
s[10] ^= h;
|
|
487
|
+
s[11] ^= l;
|
|
488
|
+
s[20] ^= h;
|
|
489
|
+
s[21] ^= l;
|
|
490
|
+
s[30] ^= h;
|
|
491
|
+
s[31] ^= l;
|
|
492
|
+
s[40] ^= h;
|
|
493
|
+
s[41] ^= l;
|
|
494
|
+
h = c0 ^ ((c4 << 1) | (c5 >>> 31));
|
|
495
|
+
l = c1 ^ ((c5 << 1) | (c4 >>> 31));
|
|
496
|
+
s[2] ^= h;
|
|
497
|
+
s[3] ^= l;
|
|
498
|
+
s[12] ^= h;
|
|
499
|
+
s[13] ^= l;
|
|
500
|
+
s[22] ^= h;
|
|
501
|
+
s[23] ^= l;
|
|
502
|
+
s[32] ^= h;
|
|
503
|
+
s[33] ^= l;
|
|
504
|
+
s[42] ^= h;
|
|
505
|
+
s[43] ^= l;
|
|
506
|
+
h = c2 ^ ((c6 << 1) | (c7 >>> 31));
|
|
507
|
+
l = c3 ^ ((c7 << 1) | (c6 >>> 31));
|
|
508
|
+
s[4] ^= h;
|
|
509
|
+
s[5] ^= l;
|
|
510
|
+
s[14] ^= h;
|
|
511
|
+
s[15] ^= l;
|
|
512
|
+
s[24] ^= h;
|
|
513
|
+
s[25] ^= l;
|
|
514
|
+
s[34] ^= h;
|
|
515
|
+
s[35] ^= l;
|
|
516
|
+
s[44] ^= h;
|
|
517
|
+
s[45] ^= l;
|
|
518
|
+
h = c4 ^ ((c8 << 1) | (c9 >>> 31));
|
|
519
|
+
l = c5 ^ ((c9 << 1) | (c8 >>> 31));
|
|
520
|
+
s[6] ^= h;
|
|
521
|
+
s[7] ^= l;
|
|
522
|
+
s[16] ^= h;
|
|
523
|
+
s[17] ^= l;
|
|
524
|
+
s[26] ^= h;
|
|
525
|
+
s[27] ^= l;
|
|
526
|
+
s[36] ^= h;
|
|
527
|
+
s[37] ^= l;
|
|
528
|
+
s[46] ^= h;
|
|
529
|
+
s[47] ^= l;
|
|
530
|
+
h = c6 ^ ((c0 << 1) | (c1 >>> 31));
|
|
531
|
+
l = c7 ^ ((c1 << 1) | (c0 >>> 31));
|
|
532
|
+
s[8] ^= h;
|
|
533
|
+
s[9] ^= l;
|
|
534
|
+
s[18] ^= h;
|
|
535
|
+
s[19] ^= l;
|
|
536
|
+
s[28] ^= h;
|
|
537
|
+
s[29] ^= l;
|
|
538
|
+
s[38] ^= h;
|
|
539
|
+
s[39] ^= l;
|
|
540
|
+
s[48] ^= h;
|
|
541
|
+
s[49] ^= l;
|
|
542
|
+
|
|
543
|
+
b0 = s[0];
|
|
544
|
+
b1 = s[1];
|
|
545
|
+
b32 = (s[11] << 4) | (s[10] >>> 28);
|
|
546
|
+
b33 = (s[10] << 4) | (s[11] >>> 28);
|
|
547
|
+
b14 = (s[20] << 3) | (s[21] >>> 29);
|
|
548
|
+
b15 = (s[21] << 3) | (s[20] >>> 29);
|
|
549
|
+
b46 = (s[31] << 9) | (s[30] >>> 23);
|
|
550
|
+
b47 = (s[30] << 9) | (s[31] >>> 23);
|
|
551
|
+
b28 = (s[40] << 18) | (s[41] >>> 14);
|
|
552
|
+
b29 = (s[41] << 18) | (s[40] >>> 14);
|
|
553
|
+
b20 = (s[2] << 1) | (s[3] >>> 31);
|
|
554
|
+
b21 = (s[3] << 1) | (s[2] >>> 31);
|
|
555
|
+
b2 = (s[13] << 12) | (s[12] >>> 20);
|
|
556
|
+
b3 = (s[12] << 12) | (s[13] >>> 20);
|
|
557
|
+
b34 = (s[22] << 10) | (s[23] >>> 22);
|
|
558
|
+
b35 = (s[23] << 10) | (s[22] >>> 22);
|
|
559
|
+
b16 = (s[33] << 13) | (s[32] >>> 19);
|
|
560
|
+
b17 = (s[32] << 13) | (s[33] >>> 19);
|
|
561
|
+
b48 = (s[42] << 2) | (s[43] >>> 30);
|
|
562
|
+
b49 = (s[43] << 2) | (s[42] >>> 30);
|
|
563
|
+
b40 = (s[5] << 30) | (s[4] >>> 2);
|
|
564
|
+
b41 = (s[4] << 30) | (s[5] >>> 2);
|
|
565
|
+
b22 = (s[14] << 6) | (s[15] >>> 26);
|
|
566
|
+
b23 = (s[15] << 6) | (s[14] >>> 26);
|
|
567
|
+
b4 = (s[25] << 11) | (s[24] >>> 21);
|
|
568
|
+
b5 = (s[24] << 11) | (s[25] >>> 21);
|
|
569
|
+
b36 = (s[34] << 15) | (s[35] >>> 17);
|
|
570
|
+
b37 = (s[35] << 15) | (s[34] >>> 17);
|
|
571
|
+
b18 = (s[45] << 29) | (s[44] >>> 3);
|
|
572
|
+
b19 = (s[44] << 29) | (s[45] >>> 3);
|
|
573
|
+
b10 = (s[6] << 28) | (s[7] >>> 4);
|
|
574
|
+
b11 = (s[7] << 28) | (s[6] >>> 4);
|
|
575
|
+
b42 = (s[17] << 23) | (s[16] >>> 9);
|
|
576
|
+
b43 = (s[16] << 23) | (s[17] >>> 9);
|
|
577
|
+
b24 = (s[26] << 25) | (s[27] >>> 7);
|
|
578
|
+
b25 = (s[27] << 25) | (s[26] >>> 7);
|
|
579
|
+
b6 = (s[36] << 21) | (s[37] >>> 11);
|
|
580
|
+
b7 = (s[37] << 21) | (s[36] >>> 11);
|
|
581
|
+
b38 = (s[47] << 24) | (s[46] >>> 8);
|
|
582
|
+
b39 = (s[46] << 24) | (s[47] >>> 8);
|
|
583
|
+
b30 = (s[8] << 27) | (s[9] >>> 5);
|
|
584
|
+
b31 = (s[9] << 27) | (s[8] >>> 5);
|
|
585
|
+
b12 = (s[18] << 20) | (s[19] >>> 12);
|
|
586
|
+
b13 = (s[19] << 20) | (s[18] >>> 12);
|
|
587
|
+
b44 = (s[29] << 7) | (s[28] >>> 25);
|
|
588
|
+
b45 = (s[28] << 7) | (s[29] >>> 25);
|
|
589
|
+
b26 = (s[38] << 8) | (s[39] >>> 24);
|
|
590
|
+
b27 = (s[39] << 8) | (s[38] >>> 24);
|
|
591
|
+
b8 = (s[48] << 14) | (s[49] >>> 18);
|
|
592
|
+
b9 = (s[49] << 14) | (s[48] >>> 18);
|
|
593
|
+
|
|
594
|
+
s[0] = b0 ^ (~b2 & b4);
|
|
595
|
+
s[1] = b1 ^ (~b3 & b5);
|
|
596
|
+
s[10] = b10 ^ (~b12 & b14);
|
|
597
|
+
s[11] = b11 ^ (~b13 & b15);
|
|
598
|
+
s[20] = b20 ^ (~b22 & b24);
|
|
599
|
+
s[21] = b21 ^ (~b23 & b25);
|
|
600
|
+
s[30] = b30 ^ (~b32 & b34);
|
|
601
|
+
s[31] = b31 ^ (~b33 & b35);
|
|
602
|
+
s[40] = b40 ^ (~b42 & b44);
|
|
603
|
+
s[41] = b41 ^ (~b43 & b45);
|
|
604
|
+
s[2] = b2 ^ (~b4 & b6);
|
|
605
|
+
s[3] = b3 ^ (~b5 & b7);
|
|
606
|
+
s[12] = b12 ^ (~b14 & b16);
|
|
607
|
+
s[13] = b13 ^ (~b15 & b17);
|
|
608
|
+
s[22] = b22 ^ (~b24 & b26);
|
|
609
|
+
s[23] = b23 ^ (~b25 & b27);
|
|
610
|
+
s[32] = b32 ^ (~b34 & b36);
|
|
611
|
+
s[33] = b33 ^ (~b35 & b37);
|
|
612
|
+
s[42] = b42 ^ (~b44 & b46);
|
|
613
|
+
s[43] = b43 ^ (~b45 & b47);
|
|
614
|
+
s[4] = b4 ^ (~b6 & b8);
|
|
615
|
+
s[5] = b5 ^ (~b7 & b9);
|
|
616
|
+
s[14] = b14 ^ (~b16 & b18);
|
|
617
|
+
s[15] = b15 ^ (~b17 & b19);
|
|
618
|
+
s[24] = b24 ^ (~b26 & b28);
|
|
619
|
+
s[25] = b25 ^ (~b27 & b29);
|
|
620
|
+
s[34] = b34 ^ (~b36 & b38);
|
|
621
|
+
s[35] = b35 ^ (~b37 & b39);
|
|
622
|
+
s[44] = b44 ^ (~b46 & b48);
|
|
623
|
+
s[45] = b45 ^ (~b47 & b49);
|
|
624
|
+
s[6] = b6 ^ (~b8 & b0);
|
|
625
|
+
s[7] = b7 ^ (~b9 & b1);
|
|
626
|
+
s[16] = b16 ^ (~b18 & b10);
|
|
627
|
+
s[17] = b17 ^ (~b19 & b11);
|
|
628
|
+
s[26] = b26 ^ (~b28 & b20);
|
|
629
|
+
s[27] = b27 ^ (~b29 & b21);
|
|
630
|
+
s[36] = b36 ^ (~b38 & b30);
|
|
631
|
+
s[37] = b37 ^ (~b39 & b31);
|
|
632
|
+
s[46] = b46 ^ (~b48 & b40);
|
|
633
|
+
s[47] = b47 ^ (~b49 & b41);
|
|
634
|
+
s[8] = b8 ^ (~b0 & b2);
|
|
635
|
+
s[9] = b9 ^ (~b1 & b3);
|
|
636
|
+
s[18] = b18 ^ (~b10 & b12);
|
|
637
|
+
s[19] = b19 ^ (~b11 & b13);
|
|
638
|
+
s[28] = b28 ^ (~b20 & b22);
|
|
639
|
+
s[29] = b29 ^ (~b21 & b23);
|
|
640
|
+
s[38] = b38 ^ (~b30 & b32);
|
|
641
|
+
s[39] = b39 ^ (~b31 & b33);
|
|
642
|
+
s[48] = b48 ^ (~b40 & b42);
|
|
643
|
+
s[49] = b49 ^ (~b41 & b43);
|
|
644
|
+
|
|
645
|
+
s[0] ^= RC[n];
|
|
646
|
+
s[1] ^= RC[n + 1];
|
|
647
|
+
}
|
|
648
|
+
};
|
|
649
|
+
|
|
650
|
+
if (COMMON_JS) {
|
|
651
|
+
module.exports = methods;
|
|
652
|
+
} else {
|
|
653
|
+
for (i = 0; i < methodNames.length; ++i) {
|
|
654
|
+
root[methodNames[i]] = methods[methodNames[i]];
|
|
655
|
+
}
|
|
656
|
+
if (AMD) {
|
|
657
|
+
define(function () {
|
|
658
|
+
return methods;
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
})();
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Paul Miller (https://paulmillr.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the “Software”), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Vendored: @noble/secp256k1 2.3.0
|
|
2
|
+
|
|
3
|
+
Source: the `@noble/secp256k1` npm package, version 2.3.0
|
|
4
|
+
(https://github.com/paulmillr/noble-secp256k1), MIT license (see
|
|
5
|
+
LICENSE). Single-file, zero-dependency, audited ECDSA implementation.
|
|
6
|
+
|
|
7
|
+
Vendored subset: `index.js` only (unmodified ESM).
|
|
8
|
+
|
|
9
|
+
Used for one thing: recovering the signer address of a feed update's
|
|
10
|
+
single-owner chunk (`src/verify.js` verifySoc), so `resolveFeed(...,
|
|
11
|
+
{verify: true})` catches a forged feed even on an untrusted gateway.
|
|
12
|
+
|
|
13
|
+
Vendored (rather than npm-installed) for the same reason as wa-sqlite
|
|
14
|
+
and js-sha3: pages must be fully self-contained to publish on Swarm.
|
|
15
|
+
|
|
16
|
+
To upgrade: `npm pack @noble/secp256k1`, extract, copy `index.js` and
|
|
17
|
+
LICENSE, update the version here, re-run `node js/test/verify.mjs`.
|