-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.sql
1270 lines (1260 loc) · 51.8 KB
/
index.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
CREATE OR REPLACE FUNCTION extism_create_plugin(manifest integer, opts integer)
RETURNS integer
LANGUAGE plv8
AS $function$
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// node_modules/base64-js/index.js
var require_base64_js = __commonJS({
"node_modules/base64-js/index.js"(exports) {
"use strict";
exports.byteLength = byteLength;
exports.toByteArray = toByteArray2;
exports.fromByteArray = fromByteArray;
var lookup = [];
var revLookup = [];
var Arr = typeof Uint8Array !== "undefined" ? Uint8Array : Array;
var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
for (i = 0, len = code.length; i < len; ++i) {
lookup[i] = code[i];
revLookup[code.charCodeAt(i)] = i;
}
var i;
var len;
revLookup["-".charCodeAt(0)] = 62;
revLookup["_".charCodeAt(0)] = 63;
function getLens(b64) {
var len2 = b64.length;
if (len2 % 4 > 0) {
throw new Error("Invalid string. Length must be a multiple of 4");
}
var validLen = b64.indexOf("=");
if (validLen === -1)
validLen = len2;
var placeHoldersLen = validLen === len2 ? 0 : 4 - validLen % 4;
return [validLen, placeHoldersLen];
}
function byteLength(b64) {
var lens = getLens(b64);
var validLen = lens[0];
var placeHoldersLen = lens[1];
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
}
function _byteLength(b64, validLen, placeHoldersLen) {
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
}
function toByteArray2(b64) {
var tmp;
var lens = getLens(b64);
var validLen = lens[0];
var placeHoldersLen = lens[1];
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
var curByte = 0;
var len2 = placeHoldersLen > 0 ? validLen - 4 : validLen;
var i2;
for (i2 = 0; i2 < len2; i2 += 4) {
tmp = revLookup[b64.charCodeAt(i2)] << 18 | revLookup[b64.charCodeAt(i2 + 1)] << 12 | revLookup[b64.charCodeAt(i2 + 2)] << 6 | revLookup[b64.charCodeAt(i2 + 3)];
arr[curByte++] = tmp >> 16 & 255;
arr[curByte++] = tmp >> 8 & 255;
arr[curByte++] = tmp & 255;
}
if (placeHoldersLen === 2) {
tmp = revLookup[b64.charCodeAt(i2)] << 2 | revLookup[b64.charCodeAt(i2 + 1)] >> 4;
arr[curByte++] = tmp & 255;
}
if (placeHoldersLen === 1) {
tmp = revLookup[b64.charCodeAt(i2)] << 10 | revLookup[b64.charCodeAt(i2 + 1)] << 4 | revLookup[b64.charCodeAt(i2 + 2)] >> 2;
arr[curByte++] = tmp >> 8 & 255;
arr[curByte++] = tmp & 255;
}
return arr;
}
function tripletToBase64(num) {
return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];
}
function encodeChunk(uint8, start, end) {
var tmp;
var output = [];
for (var i2 = start; i2 < end; i2 += 3) {
tmp = (uint8[i2] << 16 & 16711680) + (uint8[i2 + 1] << 8 & 65280) + (uint8[i2 + 2] & 255);
output.push(tripletToBase64(tmp));
}
return output.join("");
}
function fromByteArray(uint8) {
var tmp;
var len2 = uint8.length;
var extraBytes = len2 % 3;
var parts = [];
var maxChunkLength = 16383;
for (var i2 = 0, len22 = len2 - extraBytes; i2 < len22; i2 += maxChunkLength) {
parts.push(encodeChunk(uint8, i2, i2 + maxChunkLength > len22 ? len22 : i2 + maxChunkLength));
}
if (extraBytes === 1) {
tmp = uint8[len2 - 1];
parts.push(
lookup[tmp >> 2] + lookup[tmp << 4 & 63] + "=="
);
} else if (extraBytes === 2) {
tmp = (uint8[len2 - 2] << 8) + uint8[len2 - 1];
parts.push(
lookup[tmp >> 10] + lookup[tmp >> 4 & 63] + lookup[tmp << 2 & 63] + "="
);
}
return parts.join("");
}
}
});
// (disabled):crypto
var require_crypto = __commonJS({
"(disabled):crypto"() {
}
});
// (disabled):buffer
var require_buffer = __commonJS({
"(disabled):buffer"() {
}
});
// node_modules/js-sha256/src/sha256.js
var require_sha256 = __commonJS({
"node_modules/js-sha256/src/sha256.js"(exports, module2) {
(function() {
"use strict";
var ERROR2 = "input is invalid type";
var WINDOW = typeof window === "object";
var root = WINDOW ? window : {};
if (root.JS_SHA256_NO_WINDOW) {
WINDOW = false;
}
var WEB_WORKER = !WINDOW && typeof self === "object";
var NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process === "object" && process.versions && process.versions.node;
if (NODE_JS) {
root = global;
} else if (WEB_WORKER) {
root = self;
}
var COMMON_JS = !root.JS_SHA256_NO_COMMON_JS && typeof module2 === "object" && module2.exports;
var AMD = typeof define === "function" && define.amd;
var ARRAY_BUFFER = !root.JS_SHA256_NO_ARRAY_BUFFER && typeof ArrayBuffer !== "undefined";
var HEX_CHARS = "0123456789abcdef".split("");
var EXTRA = [-2147483648, 8388608, 32768, 128];
var SHIFT = [24, 16, 8, 0];
var K = [
1116352408,
1899447441,
3049323471,
3921009573,
961987163,
1508970993,
2453635748,
2870763221,
3624381080,
310598401,
607225278,
1426881987,
1925078388,
2162078206,
2614888103,
3248222580,
3835390401,
4022224774,
264347078,
604807628,
770255983,
1249150122,
1555081692,
1996064986,
2554220882,
2821834349,
2952996808,
3210313671,
3336571891,
3584528711,
113926993,
338241895,
666307205,
773529912,
1294757372,
1396182291,
1695183700,
1986661051,
2177026350,
2456956037,
2730485921,
2820302411,
3259730800,
3345764771,
3516065817,
3600352804,
4094571909,
275423344,
430227734,
506948616,
659060556,
883997877,
958139571,
1322822218,
1537002063,
1747873779,
1955562222,
2024104815,
2227730452,
2361852424,
2428436474,
2756734187,
3204031479,
3329325298
];
var OUTPUT_TYPES = ["hex", "array", "digest", "arrayBuffer"];
var blocks = [];
if (root.JS_SHA256_NO_NODE_JS || !Array.isArray) {
Array.isArray = function(obj) {
return Object.prototype.toString.call(obj) === "[object Array]";
};
}
if (ARRAY_BUFFER && (root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) {
ArrayBuffer.isView = function(obj) {
return typeof obj === "object" && obj.buffer && obj.buffer.constructor === ArrayBuffer;
};
}
var createOutputMethod = function(outputType, is224) {
return function(message) {
return new Sha256(is224, true).update(message)[outputType]();
};
};
var createMethod = function(is224) {
var method = createOutputMethod("hex", is224);
if (NODE_JS) {
method = nodeWrap(method, is224);
}
method.create = function() {
return new Sha256(is224);
};
method.update = function(message) {
return method.create().update(message);
};
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
var type = OUTPUT_TYPES[i];
method[type] = createOutputMethod(type, is224);
}
return method;
};
var nodeWrap = function(method, is224) {
var crypto = require_crypto();
var Buffer2 = require_buffer().Buffer;
var algorithm = is224 ? "sha224" : "sha256";
var bufferFrom;
if (Buffer2.from && !root.JS_SHA256_NO_BUFFER_FROM) {
bufferFrom = Buffer2.from;
} else {
bufferFrom = function(message) {
return new Buffer2(message);
};
}
var nodeMethod = function(message) {
if (typeof message === "string") {
return crypto.createHash(algorithm).update(message, "utf8").digest("hex");
} else {
if (message === null || message === void 0) {
throw new Error(ERROR2);
} else if (message.constructor === ArrayBuffer) {
message = new Uint8Array(message);
}
}
if (Array.isArray(message) || ArrayBuffer.isView(message) || message.constructor === Buffer2) {
return crypto.createHash(algorithm).update(bufferFrom(message)).digest("hex");
} else {
return method(message);
}
};
return nodeMethod;
};
var createHmacOutputMethod = function(outputType, is224) {
return function(key, message) {
return new HmacSha256(key, is224, true).update(message)[outputType]();
};
};
var createHmacMethod = function(is224) {
var method = createHmacOutputMethod("hex", is224);
method.create = function(key) {
return new HmacSha256(key, is224);
};
method.update = function(key, message) {
return method.create(key).update(message);
};
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
var type = OUTPUT_TYPES[i];
method[type] = createHmacOutputMethod(type, is224);
}
return method;
};
function Sha256(is224, sharedMemory) {
if (sharedMemory) {
blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
this.blocks = blocks;
} else {
this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
}
if (is224) {
this.h0 = 3238371032;
this.h1 = 914150663;
this.h2 = 812702999;
this.h3 = 4144912697;
this.h4 = 4290775857;
this.h5 = 1750603025;
this.h6 = 1694076839;
this.h7 = 3204075428;
} else {
this.h0 = 1779033703;
this.h1 = 3144134277;
this.h2 = 1013904242;
this.h3 = 2773480762;
this.h4 = 1359893119;
this.h5 = 2600822924;
this.h6 = 528734635;
this.h7 = 1541459225;
}
this.block = this.start = this.bytes = this.hBytes = 0;
this.finalized = this.hashed = false;
this.first = true;
this.is224 = is224;
}
Sha256.prototype.update = function(message) {
if (this.finalized) {
return;
}
var notString, type = typeof message;
if (type !== "string") {
if (type === "object") {
if (message === null) {
throw new Error(ERROR2);
} else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
message = new Uint8Array(message);
} else if (!Array.isArray(message)) {
if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) {
throw new Error(ERROR2);
}
}
} else {
throw new Error(ERROR2);
}
notString = true;
}
var code, index = 0, i, length = message.length, blocks2 = this.blocks;
while (index < length) {
if (this.hashed) {
this.hashed = false;
blocks2[0] = this.block;
this.block = blocks2[16] = blocks2[1] = blocks2[2] = blocks2[3] = blocks2[4] = blocks2[5] = blocks2[6] = blocks2[7] = blocks2[8] = blocks2[9] = blocks2[10] = blocks2[11] = blocks2[12] = blocks2[13] = blocks2[14] = blocks2[15] = 0;
}
if (notString) {
for (i = this.start; index < length && i < 64; ++index) {
blocks2[i >>> 2] |= message[index] << SHIFT[i++ & 3];
}
} else {
for (i = this.start; index < length && i < 64; ++index) {
code = message.charCodeAt(index);
if (code < 128) {
blocks2[i >>> 2] |= code << SHIFT[i++ & 3];
} else if (code < 2048) {
blocks2[i >>> 2] |= (192 | code >>> 6) << SHIFT[i++ & 3];
blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3];
} else if (code < 55296 || code >= 57344) {
blocks2[i >>> 2] |= (224 | code >>> 12) << SHIFT[i++ & 3];
blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3];
blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3];
} else {
code = 65536 + ((code & 1023) << 10 | message.charCodeAt(++index) & 1023);
blocks2[i >>> 2] |= (240 | code >>> 18) << SHIFT[i++ & 3];
blocks2[i >>> 2] |= (128 | code >>> 12 & 63) << SHIFT[i++ & 3];
blocks2[i >>> 2] |= (128 | code >>> 6 & 63) << SHIFT[i++ & 3];
blocks2[i >>> 2] |= (128 | code & 63) << SHIFT[i++ & 3];
}
}
}
this.lastByteIndex = i;
this.bytes += i - this.start;
if (i >= 64) {
this.block = blocks2[16];
this.start = i - 64;
this.hash();
this.hashed = true;
} else {
this.start = i;
}
}
if (this.bytes > 4294967295) {
this.hBytes += this.bytes / 4294967296 << 0;
this.bytes = this.bytes % 4294967296;
}
return this;
};
Sha256.prototype.finalize = function() {
if (this.finalized) {
return;
}
this.finalized = true;
var blocks2 = this.blocks, i = this.lastByteIndex;
blocks2[16] = this.block;
blocks2[i >>> 2] |= EXTRA[i & 3];
this.block = blocks2[16];
if (i >= 56) {
if (!this.hashed) {
this.hash();
}
blocks2[0] = this.block;
blocks2[16] = blocks2[1] = blocks2[2] = blocks2[3] = blocks2[4] = blocks2[5] = blocks2[6] = blocks2[7] = blocks2[8] = blocks2[9] = blocks2[10] = blocks2[11] = blocks2[12] = blocks2[13] = blocks2[14] = blocks2[15] = 0;
}
blocks2[14] = this.hBytes << 3 | this.bytes >>> 29;
blocks2[15] = this.bytes << 3;
this.hash();
};
Sha256.prototype.hash = function() {
var a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4, f = this.h5, g = this.h6, h = this.h7, blocks2 = this.blocks, j, s0, s1, maj, t1, t2, ch, ab, da, cd, bc;
for (j = 16; j < 64; ++j) {
t1 = blocks2[j - 15];
s0 = (t1 >>> 7 | t1 << 25) ^ (t1 >>> 18 | t1 << 14) ^ t1 >>> 3;
t1 = blocks2[j - 2];
s1 = (t1 >>> 17 | t1 << 15) ^ (t1 >>> 19 | t1 << 13) ^ t1 >>> 10;
blocks2[j] = blocks2[j - 16] + s0 + blocks2[j - 7] + s1 << 0;
}
bc = b & c;
for (j = 0; j < 64; j += 4) {
if (this.first) {
if (this.is224) {
ab = 300032;
t1 = blocks2[0] - 1413257819;
h = t1 - 150054599 << 0;
d = t1 + 24177077 << 0;
} else {
ab = 704751109;
t1 = blocks2[0] - 210244248;
h = t1 - 1521486534 << 0;
d = t1 + 143694565 << 0;
}
this.first = false;
} else {
s0 = (a >>> 2 | a << 30) ^ (a >>> 13 | a << 19) ^ (a >>> 22 | a << 10);
s1 = (e >>> 6 | e << 26) ^ (e >>> 11 | e << 21) ^ (e >>> 25 | e << 7);
ab = a & b;
maj = ab ^ a & c ^ bc;
ch = e & f ^ ~e & g;
t1 = h + s1 + ch + K[j] + blocks2[j];
t2 = s0 + maj;
h = d + t1 << 0;
d = t1 + t2 << 0;
}
s0 = (d >>> 2 | d << 30) ^ (d >>> 13 | d << 19) ^ (d >>> 22 | d << 10);
s1 = (h >>> 6 | h << 26) ^ (h >>> 11 | h << 21) ^ (h >>> 25 | h << 7);
da = d & a;
maj = da ^ d & b ^ ab;
ch = h & e ^ ~h & f;
t1 = g + s1 + ch + K[j + 1] + blocks2[j + 1];
t2 = s0 + maj;
g = c + t1 << 0;
c = t1 + t2 << 0;
s0 = (c >>> 2 | c << 30) ^ (c >>> 13 | c << 19) ^ (c >>> 22 | c << 10);
s1 = (g >>> 6 | g << 26) ^ (g >>> 11 | g << 21) ^ (g >>> 25 | g << 7);
cd = c & d;
maj = cd ^ c & a ^ da;
ch = g & h ^ ~g & e;
t1 = f + s1 + ch + K[j + 2] + blocks2[j + 2];
t2 = s0 + maj;
f = b + t1 << 0;
b = t1 + t2 << 0;
s0 = (b >>> 2 | b << 30) ^ (b >>> 13 | b << 19) ^ (b >>> 22 | b << 10);
s1 = (f >>> 6 | f << 26) ^ (f >>> 11 | f << 21) ^ (f >>> 25 | f << 7);
bc = b & c;
maj = bc ^ b & d ^ cd;
ch = f & g ^ ~f & h;
t1 = e + s1 + ch + K[j + 3] + blocks2[j + 3];
t2 = s0 + maj;
e = a + t1 << 0;
a = t1 + t2 << 0;
this.chromeBugWorkAround = true;
}
this.h0 = this.h0 + a << 0;
this.h1 = this.h1 + b << 0;
this.h2 = this.h2 + c << 0;
this.h3 = this.h3 + d << 0;
this.h4 = this.h4 + e << 0;
this.h5 = this.h5 + f << 0;
this.h6 = this.h6 + g << 0;
this.h7 = this.h7 + h << 0;
};
Sha256.prototype.hex = function() {
this.finalize();
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, h6 = this.h6, h7 = this.h7;
var hex = HEX_CHARS[h0 >>> 28 & 15] + HEX_CHARS[h0 >>> 24 & 15] + HEX_CHARS[h0 >>> 20 & 15] + HEX_CHARS[h0 >>> 16 & 15] + HEX_CHARS[h0 >>> 12 & 15] + HEX_CHARS[h0 >>> 8 & 15] + HEX_CHARS[h0 >>> 4 & 15] + HEX_CHARS[h0 & 15] + HEX_CHARS[h1 >>> 28 & 15] + HEX_CHARS[h1 >>> 24 & 15] + HEX_CHARS[h1 >>> 20 & 15] + HEX_CHARS[h1 >>> 16 & 15] + HEX_CHARS[h1 >>> 12 & 15] + HEX_CHARS[h1 >>> 8 & 15] + HEX_CHARS[h1 >>> 4 & 15] + HEX_CHARS[h1 & 15] + HEX_CHARS[h2 >>> 28 & 15] + HEX_CHARS[h2 >>> 24 & 15] + HEX_CHARS[h2 >>> 20 & 15] + HEX_CHARS[h2 >>> 16 & 15] + HEX_CHARS[h2 >>> 12 & 15] + HEX_CHARS[h2 >>> 8 & 15] + HEX_CHARS[h2 >>> 4 & 15] + HEX_CHARS[h2 & 15] + HEX_CHARS[h3 >>> 28 & 15] + HEX_CHARS[h3 >>> 24 & 15] + HEX_CHARS[h3 >>> 20 & 15] + HEX_CHARS[h3 >>> 16 & 15] + HEX_CHARS[h3 >>> 12 & 15] + HEX_CHARS[h3 >>> 8 & 15] + HEX_CHARS[h3 >>> 4 & 15] + HEX_CHARS[h3 & 15] + HEX_CHARS[h4 >>> 28 & 15] + HEX_CHARS[h4 >>> 24 & 15] + HEX_CHARS[h4 >>> 20 & 15] + HEX_CHARS[h4 >>> 16 & 15] + HEX_CHARS[h4 >>> 12 & 15] + HEX_CHARS[h4 >>> 8 & 15] + HEX_CHARS[h4 >>> 4 & 15] + HEX_CHARS[h4 & 15] + HEX_CHARS[h5 >>> 28 & 15] + HEX_CHARS[h5 >>> 24 & 15] + HEX_CHARS[h5 >>> 20 & 15] + HEX_CHARS[h5 >>> 16 & 15] + HEX_CHARS[h5 >>> 12 & 15] + HEX_CHARS[h5 >>> 8 & 15] + HEX_CHARS[h5 >>> 4 & 15] + HEX_CHARS[h5 & 15] + HEX_CHARS[h6 >>> 28 & 15] + HEX_CHARS[h6 >>> 24 & 15] + HEX_CHARS[h6 >>> 20 & 15] + HEX_CHARS[h6 >>> 16 & 15] + HEX_CHARS[h6 >>> 12 & 15] + HEX_CHARS[h6 >>> 8 & 15] + HEX_CHARS[h6 >>> 4 & 15] + HEX_CHARS[h6 & 15];
if (!this.is224) {
hex += HEX_CHARS[h7 >>> 28 & 15] + HEX_CHARS[h7 >>> 24 & 15] + HEX_CHARS[h7 >>> 20 & 15] + HEX_CHARS[h7 >>> 16 & 15] + HEX_CHARS[h7 >>> 12 & 15] + HEX_CHARS[h7 >>> 8 & 15] + HEX_CHARS[h7 >>> 4 & 15] + HEX_CHARS[h7 & 15];
}
return hex;
};
Sha256.prototype.toString = Sha256.prototype.hex;
Sha256.prototype.digest = function() {
this.finalize();
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4, h5 = this.h5, h6 = this.h6, h7 = this.h7;
var arr = [
h0 >>> 24 & 255,
h0 >>> 16 & 255,
h0 >>> 8 & 255,
h0 & 255,
h1 >>> 24 & 255,
h1 >>> 16 & 255,
h1 >>> 8 & 255,
h1 & 255,
h2 >>> 24 & 255,
h2 >>> 16 & 255,
h2 >>> 8 & 255,
h2 & 255,
h3 >>> 24 & 255,
h3 >>> 16 & 255,
h3 >>> 8 & 255,
h3 & 255,
h4 >>> 24 & 255,
h4 >>> 16 & 255,
h4 >>> 8 & 255,
h4 & 255,
h5 >>> 24 & 255,
h5 >>> 16 & 255,
h5 >>> 8 & 255,
h5 & 255,
h6 >>> 24 & 255,
h6 >>> 16 & 255,
h6 >>> 8 & 255,
h6 & 255
];
if (!this.is224) {
arr.push(h7 >>> 24 & 255, h7 >>> 16 & 255, h7 >>> 8 & 255, h7 & 255);
}
return arr;
};
Sha256.prototype.array = Sha256.prototype.digest;
Sha256.prototype.arrayBuffer = function() {
this.finalize();
var buffer = new ArrayBuffer(this.is224 ? 28 : 32);
var dataView = new DataView(buffer);
dataView.setUint32(0, this.h0);
dataView.setUint32(4, this.h1);
dataView.setUint32(8, this.h2);
dataView.setUint32(12, this.h3);
dataView.setUint32(16, this.h4);
dataView.setUint32(20, this.h5);
dataView.setUint32(24, this.h6);
if (!this.is224) {
dataView.setUint32(28, this.h7);
}
return buffer;
};
function HmacSha256(key, is224, sharedMemory) {
var i, type = typeof key;
if (type === "string") {
var bytes = [], length = key.length, index = 0, code;
for (i = 0; i < length; ++i) {
code = key.charCodeAt(i);
if (code < 128) {
bytes[index++] = code;
} else if (code < 2048) {
bytes[index++] = 192 | code >>> 6;
bytes[index++] = 128 | code & 63;
} else if (code < 55296 || code >= 57344) {
bytes[index++] = 224 | code >>> 12;
bytes[index++] = 128 | code >>> 6 & 63;
bytes[index++] = 128 | code & 63;
} else {
code = 65536 + ((code & 1023) << 10 | key.charCodeAt(++i) & 1023);
bytes[index++] = 240 | code >>> 18;
bytes[index++] = 128 | code >>> 12 & 63;
bytes[index++] = 128 | code >>> 6 & 63;
bytes[index++] = 128 | code & 63;
}
}
key = bytes;
} else {
if (type === "object") {
if (key === null) {
throw new Error(ERROR2);
} else if (ARRAY_BUFFER && key.constructor === ArrayBuffer) {
key = new Uint8Array(key);
} else if (!Array.isArray(key)) {
if (!ARRAY_BUFFER || !ArrayBuffer.isView(key)) {
throw new Error(ERROR2);
}
}
} else {
throw new Error(ERROR2);
}
}
if (key.length > 64) {
key = new Sha256(is224, true).update(key).array();
}
var oKeyPad = [], iKeyPad = [];
for (i = 0; i < 64; ++i) {
var b = key[i] || 0;
oKeyPad[i] = 92 ^ b;
iKeyPad[i] = 54 ^ b;
}
Sha256.call(this, is224, sharedMemory);
this.update(iKeyPad);
this.oKeyPad = oKeyPad;
this.inner = true;
this.sharedMemory = sharedMemory;
}
HmacSha256.prototype = new Sha256();
HmacSha256.prototype.finalize = function() {
Sha256.prototype.finalize.call(this);
if (this.inner) {
this.inner = false;
var innerHash = this.array();
Sha256.call(this, this.is224, this.sharedMemory);
this.update(this.oKeyPad);
this.update(innerHash);
Sha256.prototype.finalize.call(this);
}
};
var exports2 = createMethod();
exports2.sha256 = exports2;
exports2.sha224 = createMethod(true);
exports2.sha256.hmac = createHmacMethod();
exports2.sha224.hmac = createHmacMethod(true);
if (COMMON_JS) {
module2.exports = exports2;
} else {
root.sha256 = exports2.sha256;
root.sha224 = exports2.sha224;
if (AMD) {
define(function() {
return exports2;
});
}
}
})();
}
});
// src/index.ts
var src_exports = {};
__export(src_exports, {
CurrentPlugin: () => CurrentPlugin,
Plugin: () => Plugin,
PluginOutput: () => PluginOutput,
PluginWasi: () => PluginWasi,
createPlugin: () => createPlugin,
decodeString: () => decodeString,
embeddedRuntime: () => embeddedRuntime,
embeddedRuntimeHash: () => embeddedRuntimeHash,
encodeString: () => encodeString,
instantiateExtismRuntime: () => instantiateExtismRuntime
});
var import_base64_js = __toESM(require_base64_js());
var import_js_sha256 = __toESM(require_sha256());
var PluginOutput = class extends DataView {
#output;
constructor(output) {
super(output.buffer);
this.#output = output;
}
json() {
return JSON.parse(this.text());
}
text() {
return decodeString(this.#output);
}
bytes() {
return this.#output;
}
arrayBuffer() {
return this.#output.buffer;
}
};
var Plugin = class {
moduleData;
currentPlugin;
vars;
input;
output;
module;
options;
lastStatusCode = 0;
guestRuntime;
constructor(extism, moduleData, options) {
this.moduleData = moduleData;
this.currentPlugin = new CurrentPlugin(this, extism);
this.vars = {};
this.input = new Uint8Array();
this.output = new Uint8Array();
this.options = options;
this.guestRuntime = { type: GuestRuntimeType.None, init: () => {
}, initialized: true };
}
getExports() {
const module2 = this.instantiateModule();
return module2.instance.exports;
}
getImports() {
const module2 = this.instantiateModule();
return WebAssembly.Module.imports(module2.module);
}
getInstance() {
const module2 = this.instantiateModule();
return module2.instance;
}
functionExists(name) {
const module2 = this.instantiateModule();
return module2.instance.exports[name] ? true : false;
}
callRaw(func_name, input) {
const module2 = this.instantiateModule();
this.input = input;
this.currentPlugin.reset();
let func = module2.instance.exports[func_name];
if (!func) {
throw Error(`Plugin error: function does not exist ${func_name}`);
}
if (func_name != "_start" && !this.guestRuntime.initialized) {
this.guestRuntime.init();
this.guestRuntime.initialized = true;
}
func();
return this.output;
}
call(func_name, input) {
const output = this.callRaw(func_name, encodeString(input));
return new PluginOutput(output);
}
loadWasi(options) {
const args = [];
const envVars = [];
return new PluginWasi();
}
instantiateModule() {
if (this.module) {
return this.module;
}
const pluginWasi = this.options.useWasi ? this.loadWasi(this.options) : void 0;
let imports = {
wasi_snapshot_preview1: pluginWasi?.importObject(),
"extism:host/env": this.makeEnv()
};
for (const m in this.options.functions) {
imports[m] = imports[m] || {};
const map = this.options.functions[m];
for (const f in map) {
imports[m][f] = this.options.functions[m][f];
}
}
for (const m in imports) {
if (m === "wasi_snapshot_preview1") {
continue;
}
for (const f in imports[m]) {
imports[m][f] = imports[m][f].bind(null, this.currentPlugin);
}
}
const mod = new WebAssembly.Module(this.moduleData);
const instance = new WebAssembly.Instance(mod, imports);
this.module = {
module: this.moduleData,
instance
};
if (pluginWasi) {
pluginWasi.initialize(this.module.instance);
}
this.guestRuntime = detectGuestRuntime(this.module.instance);
return this.module;
}
makeEnv() {
let plugin = this;
var env = {
alloc(cp, n) {
const response = cp.alloc(n);
return response;
},
length_unsafe(cp, n) {
return cp.lengthUnsafe(n);
},
free(cp, n) {
cp.free(n);
},
load_u8(cp, n) {
return cp.getMemoryBuffer()[Number(n)];
},
load_u64(cp, n) {
let cast = new DataView(cp.getMemory().buffer, Number(n));
return cast.getBigUint64(0, true);
},
store_u8(cp, offset, n) {
cp.getMemoryBuffer()[Number(offset)] = Number(n);
},
store_u64(cp, offset, n) {
const tmp = new DataView(cp.getMemory().buffer, Number(offset));
tmp.setBigUint64(0, n, true);
},
input_length() {
return BigInt(plugin.input.length);
},
input_load_u8(cp, i) {
return plugin.input[Number(i)];
},
input_load_u64(cp, idx) {
let cast = new DataView(plugin.input.buffer, Number(idx));
return cast.getBigUint64(0, true);
},
output_set(cp, offset, length) {
const offs = Number(offset);
const len = Number(length);
plugin.output = cp.getMemoryBuffer().slice(offs, offs + len);
},
error_set(cp, i) {
throw new Error(`Call error: ${cp.read(i)?.text()}`);
},
config_get(cp, i) {
if (typeof plugin.options.config === "undefined") {
return BigInt(0);
}
const key = cp.read(i)?.text();
if (!key) {
return BigInt(0);
}
const value = plugin.options.config[key];
if (typeof value === "undefined") {
return BigInt(0);
}
return cp.store(value);
},
var_get(cp, i) {
const key = cp.read(i)?.text();
if (!key) {
return BigInt(0);
}
const value = cp.vars[key];
if (typeof value === "undefined") {
return BigInt(0);
}
return cp.store(value);
},
var_set(cp, n, i) {
const key = cp.read(n)?.text();
if (!key) {
return;
}
const value = cp.read(i)?.bytes();
if (!value) {
return;
}
cp.vars[key] = value;
},
http_request(cp, requestOffset, bodyOffset) {
throw new Error("Call error: http requests are not supported.");
},
http_status_code() {
return plugin.lastStatusCode;
},
length(cp, i) {
return cp.length(i);
},
log_warn(cp, i) {
const s = cp.read(i)?.text();
plv8.elog(WARNING, s);
},
log_info(cp, i) {
const s = cp.read(i)?.text();
plv8.elog(INFO, s);
},
log_debug(cp, i) {
const s = cp.read(i)?.text();
plv8.elog(DEBUG1, s);
},
log_error(cp, i) {
const s = cp.read(i)?.text();
plv8.elog(ERROR, s);
}
};
return env;
}
};
var PluginWasi = class {
imports;
inst = null;
args;
env;
constructor(args = [], env = []) {
this.args = args;
this.env = env;
const self2 = this;
function memory() {
return self2.inst.exports.memory;
}
this.imports = {
fd_write: (fd, iovs, iovs_len, nwritten) => {
if (fd < 0 || fd > 2) {
throw new Error("fd_write not implemented");
}
const buffer = memory().buffer;
const view = new DataView(buffer);
let written = 0;
let totalLength = 0;
for (let i = 0; i < iovs_len; i++) {
const len = view.getUint32(iovs + i * 8 + 4, true);
totalLength += len;
}
const temp = new Uint8Array(totalLength);
for (let i = 0; i < iovs_len; i++) {
const iov = view.getUint32(iovs + i * 8, true);
const len = view.getUint32(iovs + i * 8 + 4, true);
const bytes = new Uint8Array(buffer, iov, len);
temp.set(bytes, written);
written += len;
}
const output = new TextDecoder().decode(temp);
console.log(output);
view.setUint32(nwritten, written, true);
return 0;
},
fd_close(fd) {
if (fd < 0 || fd > 2) {
throw new Error("fd_close not implemented");
}
return 0;
},
fd_seek(fd, offset, whence, newoffset) {
throw new Error("fd_seek not implemented");
},
fd_fdstat_get(fd, buf) {
throw new Error("fd_fdstat_get not implemented");
},
fd_read(fd, iovs_ptr, iovs_len, nread_ptr) {
throw new Error("fd_read not implemented");
},
fd_fdstat_set_flags(fd, flags) {
throw new Error("fd_fdstat_set_flags not implemented");
},
fd_filestat_get(fd, buf) {
throw new Error("fd_filestat_get not implemented");
},
fd_filestat_set_size(fd, size) {
throw new Error("fd_filestat_set_size not implemented");
},
path_create_directory(fd, path_ptr, path_len) {
throw new Error("path_create_directory not implemented");
},
path_filestat_get(fd, flags, path_ptr, path_len, filestat_ptr) {
throw new Error("path_filestat_get not implemented");
},
fd_prestat_get(fd, buf_ptr) {
throw new Error("fd_prestat_get not implemented");
},
fd_prestat_dir_name(fd, path_ptr, path_len) {
throw new Error("fd_prestat_dir_name not implemented");
},
path_open(fd, dirflags, path_ptr, path_len, oflags, fs_rights_base, fs_rights_inheriting, fd_flags, opened_fd_ptr) {
throw new Error("path_open not implemented");
},
poll_oneoff(in_ptr, out_ptr, nsubscriptions, nevents) {
throw new Error("poll_oneoff not implemented");
},
proc_exit(rval) {
throw new Error(`proc_exit: ${rval}`);
},
clock_time_get(id, precision, time) {
const buffer = new DataView(memory().buffer);
buffer.setBigUint64(
time,
BigInt(new Date().getTime()) * 1000000n,
true
);
return 0;
},
args_sizes_get(argc, argv_buf_size) {
const buffer = new DataView(memory().buffer);