krillplayer-plugin 0.3.0 → 0.5.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 +2 -0
- package/dist/cli.js +577 -84
- package/dist/crypto.js +155 -5
- package/kernel/Sources/Kernel/Network/PublicSuffixList.dat +16978 -0
- package/kernel/Sources/Kernel/PluginPrelude.js +1 -0
- package/package.json +2 -2
- package/skill/krillplayer-plugin/SKILL.md +1 -0
- package/skill/krillplayer-plugin/references/cases.md +21 -0
- package/skill/krillplayer-plugin/references/contract.d.ts +51 -5
package/dist/crypto.js
CHANGED
|
@@ -69,7 +69,8 @@ var Capability = enumeration("Capability", [
|
|
|
69
69
|
"danmakuSend",
|
|
70
70
|
"browseLists",
|
|
71
71
|
"playerPanels",
|
|
72
|
-
"cardActions"
|
|
72
|
+
"cardActions",
|
|
73
|
+
"danmakuSendSession"
|
|
73
74
|
]);
|
|
74
75
|
var Media = enumeration("Media", ["video", "audio"]);
|
|
75
76
|
var ChannelKind = enumeration("ChannelKind", ["creator", "station", "podcast"]);
|
|
@@ -473,6 +474,23 @@ var LiveDanmakuConnection = object("LiveDanmakuConnection", {
|
|
|
473
474
|
heartbeat: optional(object("DanmakuHeartbeat", { frame: DanmakuFrame, interval: number })),
|
|
474
475
|
recent: optional(array(DanmakuComment))
|
|
475
476
|
});
|
|
477
|
+
var DanmakuSendWait = object("DanmakuSendWait", {
|
|
478
|
+
seconds: number,
|
|
479
|
+
outcome: enumeration("DanmakuSendOutcome", ["sent", "failed"], "failed")
|
|
480
|
+
});
|
|
481
|
+
var DanmakuSendSession = object("DanmakuSendSession", {
|
|
482
|
+
url: string,
|
|
483
|
+
headers: optional(map(string)),
|
|
484
|
+
handshake: array(DanmakuFrame),
|
|
485
|
+
wait: DanmakuSendWait,
|
|
486
|
+
state: optional(string)
|
|
487
|
+
});
|
|
488
|
+
var DanmakuSendStep = object("DanmakuSendStep", {
|
|
489
|
+
replies: optional(array(DanmakuFrame)),
|
|
490
|
+
sent: optional(boolean),
|
|
491
|
+
wait: optional(DanmakuSendWait),
|
|
492
|
+
state: optional(string)
|
|
493
|
+
});
|
|
476
494
|
var DanmakuBatch = object("DanmakuBatch", {
|
|
477
495
|
messages: array(DanmakuComment),
|
|
478
496
|
replies: optional(array(DanmakuFrame)),
|
|
@@ -770,7 +788,9 @@ var SLOT_RETURNS = {
|
|
|
770
788
|
decode: { schema: DanmakuBatch },
|
|
771
789
|
segment: { schema: DanmakuSegment },
|
|
772
790
|
match: { schema: array(DanmakuMatch) },
|
|
773
|
-
comments: { schema: DanmakuSegment }
|
|
791
|
+
comments: { schema: DanmakuSegment },
|
|
792
|
+
send: { schema: DanmakuSendSession, nullable: true },
|
|
793
|
+
sendDecode: { schema: DanmakuSendStep }
|
|
774
794
|
},
|
|
775
795
|
status: { check: { schema: array(ChannelStatus) }, images: { schema: array(ChannelImage) } },
|
|
776
796
|
login: {
|
|
@@ -784,6 +804,121 @@ var SLOT_RETURNS = {
|
|
|
784
804
|
resolve: { "": { schema: Resolved, nullable: true } }
|
|
785
805
|
};
|
|
786
806
|
|
|
807
|
+
// host/interop-crypto.ts
|
|
808
|
+
var rotl = (x, n) => x << n | x >>> 32 - n;
|
|
809
|
+
function padded(data, littleEndian) {
|
|
810
|
+
const length = (data.length + 8 >> 6) + 1 << 6;
|
|
811
|
+
const block = new Uint8Array(length);
|
|
812
|
+
block.set(data);
|
|
813
|
+
block[data.length] = 128;
|
|
814
|
+
const view = new DataView(block.buffer);
|
|
815
|
+
const bits = data.length * 8;
|
|
816
|
+
const high = Math.floor(bits / 4294967296);
|
|
817
|
+
const low = bits >>> 0;
|
|
818
|
+
if (littleEndian) {
|
|
819
|
+
view.setUint32(length - 8, low, true);
|
|
820
|
+
view.setUint32(length - 4, high, true);
|
|
821
|
+
} else {
|
|
822
|
+
view.setUint32(length - 8, high);
|
|
823
|
+
view.setUint32(length - 4, low);
|
|
824
|
+
}
|
|
825
|
+
return view;
|
|
826
|
+
}
|
|
827
|
+
var MD5_K = Array.from({ length: 64 }, (_, i) => Math.floor(Math.abs(Math.sin(i + 1)) * 4294967296) >>> 0);
|
|
828
|
+
var MD5_S = [7, 12, 17, 22, 5, 9, 14, 20, 4, 11, 16, 23, 6, 10, 15, 21];
|
|
829
|
+
function md5(data) {
|
|
830
|
+
const view = padded(data, true);
|
|
831
|
+
let a0 = 1732584193, b0 = 4023233417, c0 = 2562383102, d0 = 271733878;
|
|
832
|
+
const m = new Array(16);
|
|
833
|
+
for (let offset = 0; offset < view.byteLength; offset += 64) {
|
|
834
|
+
for (let i = 0; i < 16; i++) m[i] = view.getUint32(offset + i * 4, true);
|
|
835
|
+
let a = a0, b = b0, c = c0, d = d0;
|
|
836
|
+
for (let i = 0; i < 64; i++) {
|
|
837
|
+
const round = i >> 4;
|
|
838
|
+
let f, g;
|
|
839
|
+
if (round === 0) {
|
|
840
|
+
f = b & c | ~b & d;
|
|
841
|
+
g = i;
|
|
842
|
+
} else if (round === 1) {
|
|
843
|
+
f = d & b | ~d & c;
|
|
844
|
+
g = 5 * i + 1 & 15;
|
|
845
|
+
} else if (round === 2) {
|
|
846
|
+
f = b ^ c ^ d;
|
|
847
|
+
g = 3 * i + 5 & 15;
|
|
848
|
+
} else {
|
|
849
|
+
f = c ^ (b | ~d);
|
|
850
|
+
g = 7 * i & 15;
|
|
851
|
+
}
|
|
852
|
+
const next = d;
|
|
853
|
+
d = c;
|
|
854
|
+
c = b;
|
|
855
|
+
b = b + rotl(a + f + MD5_K[i] + m[g] | 0, MD5_S[round << 2 | i & 3]) | 0;
|
|
856
|
+
a = next;
|
|
857
|
+
}
|
|
858
|
+
a0 = a0 + a | 0;
|
|
859
|
+
b0 = b0 + b | 0;
|
|
860
|
+
c0 = c0 + c | 0;
|
|
861
|
+
d0 = d0 + d | 0;
|
|
862
|
+
}
|
|
863
|
+
const out = new DataView(new ArrayBuffer(16));
|
|
864
|
+
[a0, b0, c0, d0].forEach((word, i) => out.setUint32(i * 4, word >>> 0, true));
|
|
865
|
+
return new Uint8Array(out.buffer);
|
|
866
|
+
}
|
|
867
|
+
var SM3_IV = [1937774191, 1226093241, 388252375, 3666478592, 2842636476, 372324522, 3817729613, 2969243214];
|
|
868
|
+
var p0 = (x) => x ^ rotl(x, 9) ^ rotl(x, 17);
|
|
869
|
+
var p1 = (x) => x ^ rotl(x, 15) ^ rotl(x, 23);
|
|
870
|
+
function sm3(data) {
|
|
871
|
+
const view = padded(data, false);
|
|
872
|
+
const v = [...SM3_IV];
|
|
873
|
+
const w = new Array(68);
|
|
874
|
+
const w1 = new Array(64);
|
|
875
|
+
for (let offset = 0; offset < view.byteLength; offset += 64) {
|
|
876
|
+
for (let j = 0; j < 16; j++) w[j] = view.getUint32(offset + j * 4) | 0;
|
|
877
|
+
for (let j = 16; j < 68; j++) w[j] = p1(w[j - 16] ^ w[j - 9] ^ rotl(w[j - 3], 15)) ^ rotl(w[j - 13], 7) ^ w[j - 6];
|
|
878
|
+
for (let j = 0; j < 64; j++) w1[j] = w[j] ^ w[j + 4];
|
|
879
|
+
let [a, b, c, d, e, f, g, h] = v;
|
|
880
|
+
for (let j = 0; j < 64; j++) {
|
|
881
|
+
const t = j < 16 ? 2043430169 : 2055708042;
|
|
882
|
+
const ss1 = rotl(rotl(a, 12) + e + rotl(t, j % 32) | 0, 7);
|
|
883
|
+
const ss2 = ss1 ^ rotl(a, 12);
|
|
884
|
+
const ff = j < 16 ? a ^ b ^ c : a & b | a & c | b & c;
|
|
885
|
+
const gg = j < 16 ? e ^ f ^ g : e & f | ~e & g;
|
|
886
|
+
const tt1 = ff + d + ss2 + w1[j] | 0;
|
|
887
|
+
const tt2 = gg + h + ss1 + w[j] | 0;
|
|
888
|
+
d = c;
|
|
889
|
+
c = rotl(b, 9);
|
|
890
|
+
b = a;
|
|
891
|
+
a = tt1;
|
|
892
|
+
h = g;
|
|
893
|
+
g = rotl(f, 19);
|
|
894
|
+
f = e;
|
|
895
|
+
e = p0(tt2);
|
|
896
|
+
}
|
|
897
|
+
[a, b, c, d, e, f, g, h].forEach((word, i) => {
|
|
898
|
+
v[i] ^= word;
|
|
899
|
+
});
|
|
900
|
+
}
|
|
901
|
+
const out = new DataView(new ArrayBuffer(32));
|
|
902
|
+
v.forEach((word, i) => out.setUint32(i * 4, word >>> 0));
|
|
903
|
+
return new Uint8Array(out.buffer);
|
|
904
|
+
}
|
|
905
|
+
function rc4(key, data) {
|
|
906
|
+
const s = new Uint8Array(256);
|
|
907
|
+
for (let i = 0; i < 256; i++) s[i] = i;
|
|
908
|
+
for (let i = 0, j = 0; i < 256; i++) {
|
|
909
|
+
j = j + s[i] + key[i % key.length] & 255;
|
|
910
|
+
[s[i], s[j]] = [s[j], s[i]];
|
|
911
|
+
}
|
|
912
|
+
const out = new Uint8Array(data.length);
|
|
913
|
+
for (let n = 0, i = 0, j = 0; n < data.length; n++) {
|
|
914
|
+
i = i + 1 & 255;
|
|
915
|
+
j = j + s[i] & 255;
|
|
916
|
+
[s[i], s[j]] = [s[j], s[i]];
|
|
917
|
+
out[n] = data[n] ^ s[s[i] + s[j] & 255];
|
|
918
|
+
}
|
|
919
|
+
return out;
|
|
920
|
+
}
|
|
921
|
+
|
|
787
922
|
// host/json-depth.ts
|
|
788
923
|
function pluginJSONText(bytes2) {
|
|
789
924
|
if (bytes2[0] === 239 && bytes2[1] === 187 && bytes2[2] === 191) return void 0;
|
|
@@ -1572,15 +1707,30 @@ function createSubtle() {
|
|
|
1572
1707
|
};
|
|
1573
1708
|
}
|
|
1574
1709
|
var DIGESTS = /* @__PURE__ */ new Map([["sha-1", "SHA-1"], ["sha-256", "SHA-256"], ["sha-384", "SHA-384"], ["sha-512", "SHA-512"]]);
|
|
1710
|
+
var INTEROP_DIGESTS = /* @__PURE__ */ new Map([["md5", md5], ["sm3", sm3]]);
|
|
1711
|
+
function plainBytes(value) {
|
|
1712
|
+
if (typeof value === "string") return new TextEncoder().encode(value);
|
|
1713
|
+
if (ArrayBuffer.isView(value) && Object.prototype.toString.call(value) === "[object Uint8Array]") return new Uint8Array(value);
|
|
1714
|
+
throw new TypeError("expected a Uint8Array or a string");
|
|
1715
|
+
}
|
|
1575
1716
|
async function plainDigest(algorithm, data) {
|
|
1576
|
-
const
|
|
1577
|
-
|
|
1578
|
-
|
|
1717
|
+
const lowered = String(algorithm).toLowerCase();
|
|
1718
|
+
const interop = INTEROP_DIGESTS.get(lowered);
|
|
1719
|
+
const name = DIGESTS.get(lowered);
|
|
1720
|
+
if (interop === void 0 && name === void 0) throw new TypeError(`unsupported digest ${algorithm}`);
|
|
1721
|
+
const bytes2 = plainBytes(data);
|
|
1722
|
+
return interop !== void 0 ? interop(bytes2) : new Uint8Array(await subtle().digest(name, bytes2));
|
|
1723
|
+
}
|
|
1724
|
+
async function plainRC4(key, data) {
|
|
1725
|
+
const keyBytes = plainBytes(key);
|
|
1726
|
+
if (keyBytes.length < 1 || keyBytes.length > 256) throw new TypeError("krillplayer.crypto.rc4 needs a key of 1 to 256 bytes");
|
|
1727
|
+
return rc4(keyBytes, plainBytes(data));
|
|
1579
1728
|
}
|
|
1580
1729
|
function createCrypto() {
|
|
1581
1730
|
return {
|
|
1582
1731
|
randomBytes: (length) => globalThis.crypto.getRandomValues(new Uint8Array(length)),
|
|
1583
1732
|
digest: plainDigest,
|
|
1733
|
+
rc4: plainRC4,
|
|
1584
1734
|
subtle: createSubtle()
|
|
1585
1735
|
};
|
|
1586
1736
|
}
|