@mtcute/web 0.16.7 → 0.16.13
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/{cjs/client.d.ts → client.d.ts} +2 -3
- package/{cjs/crypto.d.ts → crypto.d.ts} +2 -3
- package/idb/idb.test.d.ts +1 -0
- package/{esm/idb → idb}/index.d.ts +1 -1
- package/{esm/idb → idb}/repository/auth-keys.d.ts +2 -2
- package/{cjs/idb → idb}/repository/kv.d.ts +2 -2
- package/{esm/idb → idb}/repository/peers.d.ts +3 -3
- package/{cjs/idb → idb}/repository/ref-messages.d.ts +2 -2
- package/index.cjs +965 -0
- package/index.d.ts +7 -1
- package/index.js +955 -1
- package/methods.cjs +14 -0
- package/methods.d.ts +1 -1
- package/methods.js +1 -1
- package/package.json +56 -40
- package/{cjs/platform.d.ts → platform.d.ts} +1 -1
- package/utils.cjs +14 -0
- package/utils.d.ts +1 -1
- package/utils.js +1 -1
- package/{esm/websocket.d.ts → websocket.d.ts} +3 -4
- package/websocket.test.d.ts +1 -0
- package/{cjs/worker.d.ts → worker.d.ts} +1 -2
- package/cjs/client.js +0 -43
- package/cjs/client.js.map +0 -1
- package/cjs/common-internals-web/base64.js +0 -111
- package/cjs/common-internals-web/base64.js.map +0 -1
- package/cjs/common-internals-web/hex.js +0 -66
- package/cjs/common-internals-web/hex.js.map +0 -1
- package/cjs/common-internals-web/logging.js +0 -35
- package/cjs/common-internals-web/logging.js.map +0 -1
- package/cjs/common-internals-web/utf8.js +0 -28
- package/cjs/common-internals-web/utf8.js.map +0 -1
- package/cjs/crypto.js +0 -73
- package/cjs/crypto.js.map +0 -1
- package/cjs/exit-hook.js +0 -23
- package/cjs/exit-hook.js.map +0 -1
- package/cjs/idb/driver.js +0 -139
- package/cjs/idb/driver.js.map +0 -1
- package/cjs/idb/index.d.ts +0 -22
- package/cjs/idb/index.js +0 -34
- package/cjs/idb/index.js.map +0 -1
- package/cjs/idb/repository/auth-keys.d.ts +0 -14
- package/cjs/idb/repository/auth-keys.js +0 -71
- package/cjs/idb/repository/auth-keys.js.map +0 -1
- package/cjs/idb/repository/kv.js +0 -35
- package/cjs/idb/repository/kv.js.map +0 -1
- package/cjs/idb/repository/peers.d.ts +0 -12
- package/cjs/idb/repository/peers.js +0 -39
- package/cjs/idb/repository/peers.js.map +0 -1
- package/cjs/idb/repository/ref-messages.js +0 -62
- package/cjs/idb/repository/ref-messages.js.map +0 -1
- package/cjs/idb/utils.js +0 -17
- package/cjs/idb/utils.js.map +0 -1
- package/cjs/index.js +0 -30
- package/cjs/index.js.map +0 -1
- package/cjs/methods.js +0 -24
- package/cjs/methods.js.map +0 -1
- package/cjs/package.json +0 -3
- package/cjs/platform.js +0 -49
- package/cjs/platform.js.map +0 -1
- package/cjs/utils.js +0 -24
- package/cjs/utils.js.map +0 -1
- package/cjs/wasm.js +0 -35
- package/cjs/wasm.js.map +0 -1
- package/cjs/websocket.d.ts +0 -47
- package/cjs/websocket.js +0 -132
- package/cjs/websocket.js.map +0 -1
- package/cjs/worker.js +0 -128
- package/cjs/worker.js.map +0 -1
- package/esm/client.d.ts +0 -31
- package/esm/client.js +0 -38
- package/esm/client.js.map +0 -1
- package/esm/common-internals-web/base64.d.ts +0 -2
- package/esm/common-internals-web/base64.js +0 -107
- package/esm/common-internals-web/base64.js.map +0 -1
- package/esm/common-internals-web/hex.d.ts +0 -2
- package/esm/common-internals-web/hex.js +0 -62
- package/esm/common-internals-web/hex.js.map +0 -1
- package/esm/common-internals-web/logging.d.ts +0 -2
- package/esm/common-internals-web/logging.js +0 -31
- package/esm/common-internals-web/logging.js.map +0 -1
- package/esm/common-internals-web/utf8.d.ts +0 -3
- package/esm/common-internals-web/utf8.js +0 -23
- package/esm/common-internals-web/utf8.js.map +0 -1
- package/esm/crypto.d.ts +0 -22
- package/esm/crypto.js +0 -69
- package/esm/crypto.js.map +0 -1
- package/esm/exit-hook.d.ts +0 -1
- package/esm/exit-hook.js +0 -20
- package/esm/exit-hook.js.map +0 -1
- package/esm/idb/driver.d.ts +0 -18
- package/esm/idb/driver.js +0 -135
- package/esm/idb/driver.js.map +0 -1
- package/esm/idb/index.js +0 -29
- package/esm/idb/index.js.map +0 -1
- package/esm/idb/repository/auth-keys.js +0 -67
- package/esm/idb/repository/auth-keys.js.map +0 -1
- package/esm/idb/repository/kv.d.ts +0 -11
- package/esm/idb/repository/kv.js +0 -31
- package/esm/idb/repository/kv.js.map +0 -1
- package/esm/idb/repository/peers.js +0 -35
- package/esm/idb/repository/peers.js.map +0 -1
- package/esm/idb/repository/ref-messages.d.ts +0 -12
- package/esm/idb/repository/ref-messages.js +0 -58
- package/esm/idb/repository/ref-messages.js.map +0 -1
- package/esm/idb/utils.d.ts +0 -2
- package/esm/idb/utils.js +0 -13
- package/esm/idb/utils.js.map +0 -1
- package/esm/index.d.ts +0 -7
- package/esm/index.js +0 -8
- package/esm/index.js.map +0 -1
- package/esm/methods.d.ts +0 -1
- package/esm/methods.js +0 -2
- package/esm/methods.js.map +0 -1
- package/esm/platform.d.ts +0 -21
- package/esm/platform.js +0 -45
- package/esm/platform.js.map +0 -1
- package/esm/utils.d.ts +0 -1
- package/esm/utils.js +0 -2
- package/esm/utils.js.map +0 -1
- package/esm/wasm.d.ts +0 -2
- package/esm/wasm.js +0 -32
- package/esm/wasm.js.map +0 -1
- package/esm/websocket.js +0 -124
- package/esm/websocket.js.map +0 -1
- package/esm/worker.d.ts +0 -11
- package/esm/worker.js +0 -123
- package/esm/worker.js.map +0 -1
- /package/{cjs/common-internals-web → common-internals-web}/base64.d.ts +0 -0
- /package/{cjs/common-internals-web → common-internals-web}/hex.d.ts +0 -0
- /package/{cjs/common-internals-web → common-internals-web}/logging.d.ts +0 -0
- /package/{cjs/common-internals-web → common-internals-web}/utf8.d.ts +0 -0
- /package/{cjs/exit-hook.d.ts → exit-hook.d.ts} +0 -0
- /package/{cjs/idb → idb}/driver.d.ts +0 -0
- /package/{cjs/idb → idb}/utils.d.ts +0 -0
- /package/{cjs/index.d.ts → index.d.cts} +0 -0
- /package/{cjs/methods.d.ts → methods.d.cts} +0 -0
- /package/{cjs/utils.d.ts → utils.d.cts} +0 -0
- /package/{cjs/wasm.d.ts → wasm.d.ts} +0 -0
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/// Based on https://github.com/beatgammit/base64-js, MIT license
|
|
2
|
-
const lookup = [];
|
|
3
|
-
const revLookup = [];
|
|
4
|
-
const code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
5
|
-
for (let i = 0, len = code.length; i < len; ++i) {
|
|
6
|
-
lookup[i] = code[i];
|
|
7
|
-
revLookup[code.charCodeAt(i)] = i;
|
|
8
|
-
}
|
|
9
|
-
function getLens(b64) {
|
|
10
|
-
const len = b64.length;
|
|
11
|
-
if (len % 4 > 0) {
|
|
12
|
-
throw new Error('Invalid string. Length must be a multiple of 4');
|
|
13
|
-
}
|
|
14
|
-
// Trim off extra bytes after placeholder bytes are found
|
|
15
|
-
// See: https://github.com/beatgammit/base64-js/issues/42
|
|
16
|
-
let validLen = b64.indexOf('=');
|
|
17
|
-
if (validLen === -1)
|
|
18
|
-
validLen = len;
|
|
19
|
-
const placeHoldersLen = validLen === len ? 0 : 4 - (validLen % 4);
|
|
20
|
-
return [validLen, placeHoldersLen];
|
|
21
|
-
}
|
|
22
|
-
function _byteLength(b64, validLen, placeHoldersLen) {
|
|
23
|
-
return ((validLen + placeHoldersLen) * 3) / 4 - placeHoldersLen;
|
|
24
|
-
}
|
|
25
|
-
function toByteArray(b64, arr) {
|
|
26
|
-
let tmp;
|
|
27
|
-
const lens = getLens(b64);
|
|
28
|
-
const validLen = lens[0];
|
|
29
|
-
const placeHoldersLen = lens[1];
|
|
30
|
-
let curByte = 0;
|
|
31
|
-
// if there are placeholders, only get up to the last complete 4 chars
|
|
32
|
-
const len = placeHoldersLen > 0 ? validLen - 4 : validLen;
|
|
33
|
-
let i;
|
|
34
|
-
for (i = 0; i < len; i += 4) {
|
|
35
|
-
tmp
|
|
36
|
-
= (revLookup[b64.charCodeAt(i)] << 18)
|
|
37
|
-
| (revLookup[b64.charCodeAt(i + 1)] << 12)
|
|
38
|
-
| (revLookup[b64.charCodeAt(i + 2)] << 6)
|
|
39
|
-
| revLookup[b64.charCodeAt(i + 3)];
|
|
40
|
-
arr[curByte++] = (tmp >> 16) & 0xFF;
|
|
41
|
-
arr[curByte++] = (tmp >> 8) & 0xFF;
|
|
42
|
-
arr[curByte++] = tmp & 0xFF;
|
|
43
|
-
}
|
|
44
|
-
if (placeHoldersLen === 2) {
|
|
45
|
-
tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4);
|
|
46
|
-
arr[curByte++] = tmp & 0xFF;
|
|
47
|
-
}
|
|
48
|
-
if (placeHoldersLen === 1) {
|
|
49
|
-
tmp
|
|
50
|
-
= (revLookup[b64.charCodeAt(i)] << 10)
|
|
51
|
-
| (revLookup[b64.charCodeAt(i + 1)] << 4)
|
|
52
|
-
| (revLookup[b64.charCodeAt(i + 2)] >> 2);
|
|
53
|
-
arr[curByte++] = (tmp >> 8) & 0xFF;
|
|
54
|
-
arr[curByte++] = tmp & 0xFF;
|
|
55
|
-
}
|
|
56
|
-
return arr;
|
|
57
|
-
}
|
|
58
|
-
function tripletToBase64(num) {
|
|
59
|
-
return lookup[(num >> 18) & 0x3F] + lookup[(num >> 12) & 0x3F] + lookup[(num >> 6) & 0x3F] + lookup[num & 0x3F];
|
|
60
|
-
}
|
|
61
|
-
function encodeChunk(uint8, start, end) {
|
|
62
|
-
let tmp;
|
|
63
|
-
const output = [];
|
|
64
|
-
for (let i = start; i < end; i += 3) {
|
|
65
|
-
tmp = ((uint8[i] << 16) & 0xFF0000) + ((uint8[i + 1] << 8) & 0xFF00) + (uint8[i + 2] & 0xFF);
|
|
66
|
-
output.push(tripletToBase64(tmp));
|
|
67
|
-
}
|
|
68
|
-
return output.join('');
|
|
69
|
-
}
|
|
70
|
-
function fromByteArray(uint8) {
|
|
71
|
-
let tmp;
|
|
72
|
-
const len = uint8.length;
|
|
73
|
-
const extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
|
|
74
|
-
const parts = [];
|
|
75
|
-
const maxChunkLength = 16383; // must be multiple of 3
|
|
76
|
-
// go through the array every three bytes, we'll deal with trailing stuff later
|
|
77
|
-
for (let i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
|
|
78
|
-
parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength));
|
|
79
|
-
}
|
|
80
|
-
// pad the end with zeros, but make sure to not forget the extra bytes
|
|
81
|
-
if (extraBytes === 1) {
|
|
82
|
-
tmp = uint8[len - 1];
|
|
83
|
-
parts.push(`${lookup[tmp >> 2] + lookup[(tmp << 4) & 0x3F]}==`);
|
|
84
|
-
}
|
|
85
|
-
else if (extraBytes === 2) {
|
|
86
|
-
tmp = (uint8[len - 2] << 8) + uint8[len - 1];
|
|
87
|
-
parts.push(`${lookup[tmp >> 10] + lookup[(tmp >> 4) & 0x3F] + lookup[(tmp << 2) & 0x3F]}=`);
|
|
88
|
-
}
|
|
89
|
-
return parts.join('');
|
|
90
|
-
}
|
|
91
|
-
export function base64Encode(buf, url = false) {
|
|
92
|
-
const str = fromByteArray(buf);
|
|
93
|
-
if (url)
|
|
94
|
-
return str.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
95
|
-
return str;
|
|
96
|
-
}
|
|
97
|
-
export function base64Decode(string, url = false) {
|
|
98
|
-
if (url) {
|
|
99
|
-
string = string.replace(/-/g, '+').replace(/_/g, '/');
|
|
100
|
-
while (string.length % 4)
|
|
101
|
-
string += '=';
|
|
102
|
-
}
|
|
103
|
-
const buf = new Uint8Array(_byteLength(string, ...getLens(string)));
|
|
104
|
-
toByteArray(string, buf);
|
|
105
|
-
return buf;
|
|
106
|
-
}
|
|
107
|
-
//# sourceMappingURL=base64.js.map
|
|
@@ -1 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AC,CAAC,CAAC,CAAA;IAEnE,WAAW,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAExB,OAAO,GAAG,CAAA;AACd,CAAC","sourcesContent":["/// Based on https://github.com/beatgammit/base64-js, MIT license\nconst lookup: string[] = []\nconst revLookup: number[] = []\n\nconst code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'\n\nfor (let i = 0, len = code.length; i < len; ++i) {\n lookup[i] = code[i]\n revLookup[code.charCodeAt(i)] = i\n}\n\nfunction getLens(b64: string): [number, number] {\n const len = b64.length\n\n if (len % 4 > 0) {\n throw new Error('Invalid string. Length must be a multiple of 4')\n }\n\n // Trim off extra bytes after placeholder bytes are found\n // See: https://github.com/beatgammit/base64-js/issues/42\n let validLen = b64.indexOf('=')\n if (validLen === -1) validLen = len\n\n const placeHoldersLen = validLen === len ? 0 : 4 - (validLen % 4)\n\n return [validLen, placeHoldersLen]\n}\n\nfunction _byteLength(b64: string, validLen: number, placeHoldersLen: number) {\n return ((validLen + placeHoldersLen) * 3) / 4 - placeHoldersLen\n}\n\nfunction toByteArray(b64: string, arr: Uint8Array) {\n let tmp\n const lens = getLens(b64)\n const validLen = lens[0]\n const placeHoldersLen = lens[1]\n\n let curByte = 0\n\n // if there are placeholders, only get up to the last complete 4 chars\n const len = placeHoldersLen > 0 ? validLen - 4 : validLen\n\n let i\n\n for (i = 0; i < len; i += 4) {\n tmp\n = (revLookup[b64.charCodeAt(i)] << 18)\n | (revLookup[b64.charCodeAt(i + 1)] << 12)\n | (revLookup[b64.charCodeAt(i + 2)] << 6)\n | revLookup[b64.charCodeAt(i + 3)]\n arr[curByte++] = (tmp >> 16) & 0xFF\n arr[curByte++] = (tmp >> 8) & 0xFF\n arr[curByte++] = tmp & 0xFF\n }\n\n if (placeHoldersLen === 2) {\n tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4)\n arr[curByte++] = tmp & 0xFF\n }\n\n if (placeHoldersLen === 1) {\n tmp\n = (revLookup[b64.charCodeAt(i)] << 10)\n | (revLookup[b64.charCodeAt(i + 1)] << 4)\n | (revLookup[b64.charCodeAt(i + 2)] >> 2)\n arr[curByte++] = (tmp >> 8) & 0xFF\n arr[curByte++] = tmp & 0xFF\n }\n\n return arr\n}\n\nfunction tripletToBase64(num: number) {\n return lookup[(num >> 18) & 0x3F] + lookup[(num >> 12) & 0x3F] + lookup[(num >> 6) & 0x3F] + lookup[num & 0x3F]\n}\n\nfunction encodeChunk(uint8: Uint8Array, start: number, end: number) {\n let tmp\n const output = []\n\n for (let i = start; i < end; i += 3) {\n tmp = ((uint8[i] << 16) & 0xFF0000) + ((uint8[i + 1] << 8) & 0xFF00) + (uint8[i + 2] & 0xFF)\n output.push(tripletToBase64(tmp))\n }\n\n return output.join('')\n}\n\nfunction fromByteArray(uint8: Uint8Array) {\n let tmp\n const len = uint8.length\n const extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes\n const parts = []\n const maxChunkLength = 16383 // must be multiple of 3\n\n // go through the array every three bytes, we'll deal with trailing stuff later\n for (let i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {\n parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength))\n }\n\n // pad the end with zeros, but make sure to not forget the extra bytes\n if (extraBytes === 1) {\n tmp = uint8[len - 1]\n parts.push(`${lookup[tmp >> 2] + lookup[(tmp << 4) & 0x3F]}==`)\n } else if (extraBytes === 2) {\n tmp = (uint8[len - 2] << 8) + uint8[len - 1]\n parts.push(`${lookup[tmp >> 10] + lookup[(tmp >> 4) & 0x3F] + lookup[(tmp << 2) & 0x3F]}=`)\n }\n\n return parts.join('')\n}\n\nexport function base64Encode(buf: Uint8Array, url: boolean = false): string {\n const str = fromByteArray(buf)\n if (url) return str.replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=/g, '')\n\n return str\n}\n\nexport function base64Decode(string: string, url: boolean = false): Uint8Array {\n if (url) {\n string = string.replace(/-/g, '+').replace(/_/g, '/')\n while (string.length % 4) string += '='\n }\n\n const buf = new Uint8Array(_byteLength(string, ...getLens(string)))\n\n toByteArray(string, buf)\n\n return buf\n}\n"]}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/// Based on https://github.com/feross/buffer, MIT license
|
|
2
|
-
const hexSliceLookupTable = (function () {
|
|
3
|
-
const alphabet = '0123456789abcdef';
|
|
4
|
-
const table = Array.from({ length: 256 });
|
|
5
|
-
for (let i = 0; i < 16; ++i) {
|
|
6
|
-
const i16 = i * 16;
|
|
7
|
-
for (let j = 0; j < 16; ++j) {
|
|
8
|
-
table[i16 + j] = alphabet[i] + alphabet[j];
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
return table;
|
|
12
|
-
})();
|
|
13
|
-
const hexCharValueTable = {
|
|
14
|
-
0: 0,
|
|
15
|
-
1: 1,
|
|
16
|
-
2: 2,
|
|
17
|
-
3: 3,
|
|
18
|
-
4: 4,
|
|
19
|
-
5: 5,
|
|
20
|
-
6: 6,
|
|
21
|
-
7: 7,
|
|
22
|
-
8: 8,
|
|
23
|
-
9: 9,
|
|
24
|
-
a: 10,
|
|
25
|
-
b: 11,
|
|
26
|
-
c: 12,
|
|
27
|
-
d: 13,
|
|
28
|
-
e: 14,
|
|
29
|
-
f: 15,
|
|
30
|
-
A: 10,
|
|
31
|
-
B: 11,
|
|
32
|
-
C: 12,
|
|
33
|
-
D: 13,
|
|
34
|
-
E: 14,
|
|
35
|
-
F: 15,
|
|
36
|
-
};
|
|
37
|
-
export function hexEncode(buf) {
|
|
38
|
-
let out = '';
|
|
39
|
-
for (let i = 0; i < buf.byteLength; ++i) {
|
|
40
|
-
out += hexSliceLookupTable[buf[i]];
|
|
41
|
-
}
|
|
42
|
-
return out;
|
|
43
|
-
}
|
|
44
|
-
function hexDecodeInner(buf, string) {
|
|
45
|
-
const strLen = string.length;
|
|
46
|
-
const length = Math.min(buf.length, strLen / 2);
|
|
47
|
-
let i;
|
|
48
|
-
for (i = 0; i < length; ++i) {
|
|
49
|
-
const a = hexCharValueTable[string[i * 2]];
|
|
50
|
-
const b = hexCharValueTable[string[i * 2 + 1]];
|
|
51
|
-
if (a === undefined || b === undefined) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
buf[i] = (a << 4) | b;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
export function hexDecode(string) {
|
|
58
|
-
const buf = new Uint8Array(Math.ceil(string.length / 2));
|
|
59
|
-
hexDecodeInner(buf, string);
|
|
60
|
-
return buf;
|
|
61
|
-
}
|
|
62
|
-
//# sourceMappingURL=hex.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hex.js","sourceRoot":"","sources":["../../../src/common-internals-web/hex.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAE1D,MAAM,mBAAmB,GAAG,CAAC;IACzB,MAAM,QAAQ,GAAG,kBAAkB,CAAA;IACnC,MAAM,KAAK,GAAa,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA;IAEnD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;QAC1B,MAAM,GAAG,GAAG,CAAC,GAAG,EAAE,CAAA;QAElB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;YAC1B,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;QAC9C,CAAC;IACL,CAAC;IAED,OAAO,KAAK,CAAA;AAChB,CAAC,CAAC,EAAE,CAAA;AAEJ,MAAM,iBAAiB,GAA2B;IAC9C,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,CAAC;IACJ,CAAC,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I,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;YACrC,OAAM;QACV,CAAC;QACD,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAA;IACzB,CAAC;AACL,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,MAAc;IACpC,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAA;IACxD,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;IAE3B,OAAO,GAAG,CAAA;AACd,CAAC","sourcesContent":["/// Based on https://github.com/feross/buffer, MIT license\n\nconst hexSliceLookupTable = (function () {\n const alphabet = '0123456789abcdef'\n const table: string[] = Array.from({ length: 256 })\n\n for (let i = 0; i < 16; ++i) {\n const i16 = i * 16\n\n for (let j = 0; j < 16; ++j) {\n table[i16 + j] = alphabet[i] + alphabet[j]\n }\n }\n\n return table\n})()\n\nconst hexCharValueTable: Record<string, number> = {\n 0: 0,\n 1: 1,\n 2: 2,\n 3: 3,\n 4: 4,\n 5: 5,\n 6: 6,\n 7: 7,\n 8: 8,\n 9: 9,\n a: 10,\n b: 11,\n c: 12,\n d: 13,\n e: 14,\n f: 15,\n A: 10,\n B: 11,\n C: 12,\n D: 13,\n E: 14,\n F: 15,\n}\n\nexport function hexEncode(buf: Uint8Array): string {\n let out = ''\n\n for (let i = 0; i < buf.byteLength; ++i) {\n out += hexSliceLookupTable[buf[i]]\n }\n\n return out\n}\n\nfunction hexDecodeInner(buf: Uint8Array, string: string): void {\n const strLen = string.length\n const length = Math.min(buf.length, strLen / 2)\n\n let i\n\n for (i = 0; i < length; ++i) {\n const a = hexCharValueTable[string[i * 2]]\n const b = hexCharValueTable[string[i * 2 + 1]]\n\n if (a === undefined || b === undefined) {\n return\n }\n buf[i] = (a << 4) | b\n }\n}\n\nexport function hexDecode(string: string): Uint8Array {\n const buf = new Uint8Array(Math.ceil(string.length / 2))\n hexDecodeInner(buf, string)\n\n return buf\n}\n"]}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
const BASE_FORMAT = '%s [%c%s%c] [%c%s%c] ';
|
|
2
|
-
const LEVEL_NAMES = [
|
|
3
|
-
'', // OFF
|
|
4
|
-
'ERR',
|
|
5
|
-
'WRN',
|
|
6
|
-
'INF',
|
|
7
|
-
'DBG',
|
|
8
|
-
'VRB',
|
|
9
|
-
];
|
|
10
|
-
const COLORS = [
|
|
11
|
-
'', // OFF
|
|
12
|
-
'color: #7a5f9d',
|
|
13
|
-
'color: #8d7041',
|
|
14
|
-
'color: #396c9e',
|
|
15
|
-
'color: #437761',
|
|
16
|
-
'color: #7a5f9d',
|
|
17
|
-
];
|
|
18
|
-
const TAG_COLORS = [
|
|
19
|
-
'color: #437761',
|
|
20
|
-
'color: #537a36',
|
|
21
|
-
'color: #8d7041',
|
|
22
|
-
'color: #396c9e',
|
|
23
|
-
'color: #7a5f9d',
|
|
24
|
-
'color: #7a5f9d',
|
|
25
|
-
];
|
|
26
|
-
/** @internal */
|
|
27
|
-
export const defaultLoggingHandler = (color, level, tag, fmt, args) => {
|
|
28
|
-
// eslint-disable-next-line no-console
|
|
29
|
-
console.log(BASE_FORMAT + fmt, new Date().toISOString(), COLORS[level], LEVEL_NAMES[level], '', TAG_COLORS[color], tag, '', ...args);
|
|
30
|
-
};
|
|
31
|
-
//# sourceMappingURL=logging.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logging.js","sourceRoot":"","sources":["../../../src/common-internals-web/logging.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG,uBAAuB,CAAA;AAC3C,MAAM,WAAW,GAAG;IAChB,EAAE,EAAE,MAAM;IACV,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;IACL,KAAK;CACR,CAAA;AACD,MAAM,MAAM,GAAG;IACX,EAAE,EAAE,MAAM;IACV,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;CACnB,CAAA;AACD,MAAM,UAAU,GAAG;IACf,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,gBAAgB;CACnB,CAAA;AAED,gBAAgB;AAChB,MAAM,CAAC,MAAM,qBAAqB,GAMtB,CAAC,KAAa,EAAE,KAAa,EAAE,GAAW,EAAE,GAAW,EAAE,IAAe,EAAQ,EAAE;IAC1F,sCAAsC;IACtC,OAAO,CAAC,GAAG,CACP,WAAW,GAAG,GAAG,EACjB,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EACxB,MAAM,CAAC,KAAK,CAAC,EACb,WAAW,CAAC,KAAK,CAAC,EAClB,EAAE,EACF,UAAU,CAAC,KAAK,CAAC,EACjB,GAAG,EACH,EAAE,EACF,GAAG,IAAI,CACV,CAAA;AACL,CAAC,CAAA","sourcesContent":["const BASE_FORMAT = '%s [%c%s%c] [%c%s%c] '\nconst LEVEL_NAMES = [\n '', // OFF\n 'ERR',\n 'WRN',\n 'INF',\n 'DBG',\n 'VRB',\n]\nconst COLORS = [\n '', // OFF\n 'color: #7a5f9d',\n 'color: #8d7041',\n 'color: #396c9e',\n 'color: #437761',\n 'color: #7a5f9d',\n]\nconst TAG_COLORS = [\n 'color: #437761',\n 'color: #537a36',\n 'color: #8d7041',\n 'color: #396c9e',\n 'color: #7a5f9d',\n 'color: #7a5f9d',\n]\n\n/** @internal */\nexport const defaultLoggingHandler: (\n color: number,\n level: number,\n tag: string,\n fmt: string,\n args: unknown[],\n) => void = (color: number, level: number, tag: string, fmt: string, args: unknown[]): void => {\n // eslint-disable-next-line no-console\n console.log(\n BASE_FORMAT + fmt,\n new Date().toISOString(),\n COLORS[level],\n LEVEL_NAMES[level],\n '',\n TAG_COLORS[color],\n tag,\n '',\n ...args,\n )\n}\n"]}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const sharedEncoder = new TextEncoder();
|
|
2
|
-
const sharedDecoder = new TextDecoder('utf8');
|
|
3
|
-
export function utf8ByteLength(str) {
|
|
4
|
-
// https://stackoverflow.com/a/23329386
|
|
5
|
-
let s = str.length;
|
|
6
|
-
for (let i = str.length - 1; i >= 0; i--) {
|
|
7
|
-
const code = str.charCodeAt(i);
|
|
8
|
-
if (code > 0x7F && code <= 0x7FF)
|
|
9
|
-
s++;
|
|
10
|
-
else if (code > 0x7FF && code <= 0xFFFF)
|
|
11
|
-
s += 2;
|
|
12
|
-
if (code >= 0xDC00 && code <= 0xDFFF)
|
|
13
|
-
i--; // trail surrogate
|
|
14
|
-
}
|
|
15
|
-
return s;
|
|
16
|
-
}
|
|
17
|
-
export function utf8Decode(buf) {
|
|
18
|
-
return sharedDecoder.decode(buf);
|
|
19
|
-
}
|
|
20
|
-
export function utf8Encode(str) {
|
|
21
|
-
return sharedEncoder.encode(str);
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=utf8.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utf8.js","sourceRoot":"","sources":["../../../src/common-internals-web/utf8.ts"],"names":[],"mappings":"AAAA,MAAM,aAAa,GAAG,IAAI,WAAW,EAAE,CAAA;AACvC,MAAM,aAAa,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,CAAA;AAE7C,MAAM,UAAU,cAAc,CAAC,GAAW;IACtC,uCAAuC;IACvC,IAAI,CAAC,GAAG,GAAG,CAAC,MAAM,CAAA;IAElB,KAAK,IAAI,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACvC,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;QAC9B,IAAI,IAAI,GAAG,IAAI,IAAI,IAAI,IAAI,KAAK;YAAE,CAAC,EAAE,CAAA;aAChC,IAAI,IAAI,GAAG,KAAK,IAAI,IAAI,IAAI,MAAM;YAAE,CAAC,IAAI,CAAC,CAAA;QAC/C,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM;YAAE,CAAC,EAAE,CAAA,CAAC,kBAAkB;IAChE,CAAC;IAED,OAAO,CAAC,CAAA;AACZ,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,GAAe;IACtC,OAAO,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;AACpC,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,GAAW;IAClC,OAAO,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;AACpC,CAAC","sourcesContent":["const sharedEncoder = new TextEncoder()\nconst sharedDecoder = new TextDecoder('utf8')\n\nexport function utf8ByteLength(str: string): number {\n // https://stackoverflow.com/a/23329386\n let s = str.length\n\n for (let i = str.length - 1; i >= 0; i--) {\n const code = str.charCodeAt(i)\n if (code > 0x7F && code <= 0x7FF) s++\n else if (code > 0x7FF && code <= 0xFFFF) s += 2\n if (code >= 0xDC00 && code <= 0xDFFF) i-- // trail surrogate\n }\n\n return s\n}\n\nexport function utf8Decode(buf: Uint8Array): string {\n return sharedDecoder.decode(buf)\n}\n\nexport function utf8Encode(str: string): Uint8Array {\n return sharedEncoder.encode(str)\n}\n"]}
|
package/esm/crypto.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { IAesCtr, ICryptoProvider, IEncryptionScheme } from '@mtcute/core/utils.js';
|
|
2
|
-
import { BaseCryptoProvider } from '@mtcute/core/utils.js';
|
|
3
|
-
import type { WasmInitInput } from './wasm.js';
|
|
4
|
-
export interface WebCryptoProviderOptions {
|
|
5
|
-
crypto?: Crypto;
|
|
6
|
-
wasmInput?: WasmInitInput;
|
|
7
|
-
}
|
|
8
|
-
export declare class WebCryptoProvider extends BaseCryptoProvider implements ICryptoProvider {
|
|
9
|
-
readonly crypto: Crypto;
|
|
10
|
-
private _wasmInput?;
|
|
11
|
-
sha1(data: Uint8Array): Uint8Array;
|
|
12
|
-
sha256(data: Uint8Array): Uint8Array;
|
|
13
|
-
createAesCtr(key: Uint8Array, iv: Uint8Array): IAesCtr;
|
|
14
|
-
createAesIge(key: Uint8Array, iv: Uint8Array): IEncryptionScheme;
|
|
15
|
-
gzip(data: Uint8Array, maxSize: number): Uint8Array | null;
|
|
16
|
-
gunzip(data: Uint8Array): Uint8Array;
|
|
17
|
-
constructor(params?: WebCryptoProviderOptions);
|
|
18
|
-
initialize(): Promise<void>;
|
|
19
|
-
pbkdf2(password: Uint8Array, salt: Uint8Array, iterations: number, keylen?: number | undefined, algo?: string | undefined): Promise<Uint8Array>;
|
|
20
|
-
hmacSha256(data: Uint8Array, key: Uint8Array): Promise<Uint8Array>;
|
|
21
|
-
randomFill(buf: Uint8Array): void;
|
|
22
|
-
}
|
package/esm/crypto.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { BaseCryptoProvider } from '@mtcute/core/utils.js';
|
|
2
|
-
import { createCtr256, ctr256, deflateMaxSize, freeCtr256, gunzip, ige256Decrypt, ige256Encrypt, initSync, sha1, sha256, } from '@mtcute/wasm';
|
|
3
|
-
import { loadWasmBinary } from './wasm.js';
|
|
4
|
-
const ALGO_TO_SUBTLE = {
|
|
5
|
-
sha256: 'SHA-256',
|
|
6
|
-
sha1: 'SHA-1',
|
|
7
|
-
sha512: 'SHA-512',
|
|
8
|
-
};
|
|
9
|
-
export class WebCryptoProvider extends BaseCryptoProvider {
|
|
10
|
-
crypto;
|
|
11
|
-
_wasmInput;
|
|
12
|
-
sha1(data) {
|
|
13
|
-
return sha1(data);
|
|
14
|
-
}
|
|
15
|
-
sha256(data) {
|
|
16
|
-
return sha256(data);
|
|
17
|
-
}
|
|
18
|
-
createAesCtr(key, iv) {
|
|
19
|
-
const ctx = createCtr256(key, iv);
|
|
20
|
-
return {
|
|
21
|
-
process: data => ctr256(ctx, data),
|
|
22
|
-
close: () => freeCtr256(ctx),
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
createAesIge(key, iv) {
|
|
26
|
-
return {
|
|
27
|
-
encrypt: data => ige256Encrypt(data, key, iv),
|
|
28
|
-
decrypt: data => ige256Decrypt(data, key, iv),
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
gzip(data, maxSize) {
|
|
32
|
-
return deflateMaxSize(data, maxSize);
|
|
33
|
-
}
|
|
34
|
-
gunzip(data) {
|
|
35
|
-
return gunzip(data);
|
|
36
|
-
}
|
|
37
|
-
constructor(params) {
|
|
38
|
-
super();
|
|
39
|
-
const crypto = params?.crypto ?? globalThis.crypto;
|
|
40
|
-
if (!crypto || !crypto.subtle) {
|
|
41
|
-
throw new Error('WebCrypto is not available');
|
|
42
|
-
}
|
|
43
|
-
this.crypto = crypto;
|
|
44
|
-
this._wasmInput = params?.wasmInput;
|
|
45
|
-
}
|
|
46
|
-
async initialize() {
|
|
47
|
-
initSync(await loadWasmBinary(this._wasmInput));
|
|
48
|
-
}
|
|
49
|
-
async pbkdf2(password, salt, iterations, keylen, algo) {
|
|
50
|
-
const keyMaterial = await this.crypto.subtle.importKey('raw', password, 'PBKDF2', false, ['deriveBits']);
|
|
51
|
-
return this.crypto.subtle
|
|
52
|
-
.deriveBits({
|
|
53
|
-
name: 'PBKDF2',
|
|
54
|
-
salt,
|
|
55
|
-
iterations,
|
|
56
|
-
hash: algo ? ALGO_TO_SUBTLE[algo] : 'SHA-512',
|
|
57
|
-
}, keyMaterial, (keylen || 64) * 8)
|
|
58
|
-
.then(result => new Uint8Array(result));
|
|
59
|
-
}
|
|
60
|
-
async hmacSha256(data, key) {
|
|
61
|
-
const keyMaterial = await this.crypto.subtle.importKey('raw', key, { name: 'HMAC', hash: { name: 'SHA-256' } }, false, ['sign']);
|
|
62
|
-
const res = await this.crypto.subtle.sign({ name: 'HMAC' }, keyMaterial, data);
|
|
63
|
-
return new Uint8Array(res);
|
|
64
|
-
}
|
|
65
|
-
randomFill(buf) {
|
|
66
|
-
this.crypto.getRandomValues(buf);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
//# sourceMappingURL=crypto.js.map
|
package/esm/crypto.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../src/crypto.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC1D,OAAO,EACH,YAAY,EACZ,MAAM,EACN,cAAc,EACd,UAAU,EACV,MAAM,EACN,aAAa,EACb,aAAa,EACb,QAAQ,EACR,IAAI,EACJ,MAAM,GACT,MAAM,cAAc,CAAA;AAGrB,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAE1C,MAAM,cAAc,GAA2B;IAC3C,MAAM,EAAE,SAAS;IACjB,IAAI,EAAE,OAAO;IACb,MAAM,EAAE,SAAS;CACpB,CAAA;AAOD,MAAM,OAAO,iBAAkB,SAAQ,kBAAkB;IAC5C,MAAM,CAAQ;IACf,UAAU,CAAgB;IAElC,IAAI,CAAC,IAAgB;QACjB,OAAO,IAAI,CAAC,IAAI,CAAC,CAAA;IACrB,CAAC;IAED,MAAM,CAAC,IAAgB;QACnB,OAAO,MAAM,CAAC,IAAI,CAAC,CAAA;IACvB,CAAC;IAED,YAAY,CAAC,GAAe,EAAE,EAAc;QACxC,MAAM,GAAG,GAAG,YAAY,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;QAEjC,OAAO;YACH,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC;YAClC,KAAK,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC;SAC/B,CAAA;IACL,CAAC;IAED,YAAY,CAAC,GAAe,EAAE,EAAc;QACxC,OAAO;YACH,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC;YAC7C,OAAO,EAAE,IAAI,CA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,CACrB;aACA,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAA;IAC/C,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,IAAgB,EAAE,GAAe;QAC9C,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAClD,KAAK,EACL,GAAG,EACH,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAC3C,KAAK,EACL,CAAC,MAAM,CAAC,CACX,CAAA;QAED,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,IAAI,CAAC,CAAA;QAE9E,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,CAAA;IAC9B,CAAC;IAED,UAAU,CAAC,GAAe;QACtB,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAA;IACpC,CAAC;CACJ","sourcesContent":["import type { IAesCtr, ICryptoProvider, IEncryptionScheme } from '@mtcute/core/utils.js'\nimport { BaseCryptoProvider } from '@mtcute/core/utils.js'\nimport {\n createCtr256,\n ctr256,\n deflateMaxSize,\n freeCtr256,\n gunzip,\n ige256Decrypt,\n ige256Encrypt,\n initSync,\n sha1,\n sha256,\n} from '@mtcute/wasm'\n\nimport type { WasmInitInput } from './wasm.js'\nimport { loadWasmBinary } from './wasm.js'\n\nconst ALGO_TO_SUBTLE: Record<string, string> = {\n sha256: 'SHA-256',\n sha1: 'SHA-1',\n sha512: 'SHA-512',\n}\n\nexport interface WebCryptoProviderOptions {\n crypto?: Crypto\n wasmInput?: WasmInitInput\n}\n\nexport class WebCryptoProvider extends BaseCryptoProvider implements ICryptoProvider {\n readonly crypto: Crypto\n private _wasmInput?: WasmInitInput\n\n sha1(data: Uint8Array): Uint8Array {\n return sha1(data)\n }\n\n sha256(data: Uint8Array): Uint8Array {\n return sha256(data)\n }\n\n createAesCtr(key: Uint8Array, iv: Uint8Array): IAesCtr {\n const ctx = createCtr256(key, iv)\n\n return {\n process: data => ctr256(ctx, data),\n close: () => freeCtr256(ctx),\n }\n }\n\n createAesIge(key: Uint8Array, iv: Uint8Array): IEncryptionScheme {\n return {\n encrypt: data => ige256Encrypt(data, key, iv),\n decrypt: data => ige256Decrypt(data, key, iv),\n }\n }\n\n gzip(data: Uint8Array, maxSize: number): Uint8Array | null {\n return deflateMaxSize(data, maxSize)\n }\n\n gunzip(data: Uint8Array): Uint8Array {\n return gunzip(data)\n }\n\n constructor(params?: WebCryptoProviderOptions) {\n super()\n const crypto = params?.crypto ?? globalThis.crypto\n\n if (!crypto || !crypto.subtle) {\n throw new Error('WebCrypto is not available')\n }\n this.crypto = crypto\n this._wasmInput = params?.wasmInput\n }\n\n async initialize(): Promise<void> {\n initSync(await loadWasmBinary(this._wasmInput))\n }\n\n async pbkdf2(\n password: Uint8Array,\n salt: Uint8Array,\n iterations: number,\n keylen?: number | undefined,\n algo?: string | undefined,\n ): Promise<Uint8Array> {\n const keyMaterial = await this.crypto.subtle.importKey('raw', password, 'PBKDF2', false, ['deriveBits'])\n\n return this.crypto.subtle\n .deriveBits(\n {\n name: 'PBKDF2',\n salt,\n iterations,\n hash: algo ? ALGO_TO_SUBTLE[algo] : 'SHA-512',\n },\n keyMaterial,\n (keylen || 64) * 8,\n )\n .then(result => new Uint8Array(result))\n }\n\n async hmacSha256(data: Uint8Array, key: Uint8Array): Promise<Uint8Array> {\n const keyMaterial = await this.crypto.subtle.importKey(\n 'raw',\n key,\n { name: 'HMAC', hash: { name: 'SHA-256' } },\n false,\n ['sign'],\n )\n\n const res = await this.crypto.subtle.sign({ name: 'HMAC' }, keyMaterial, data)\n\n return new Uint8Array(res)\n }\n\n randomFill(buf: Uint8Array): void {\n this.crypto.getRandomValues(buf)\n }\n}\n"]}
|
package/esm/exit-hook.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function beforeExit(fn: () => void): () => void;
|
package/esm/exit-hook.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const callbacks = new Set();
|
|
2
|
-
let registered = false;
|
|
3
|
-
export function beforeExit(fn) {
|
|
4
|
-
if (typeof window === 'undefined') {
|
|
5
|
-
return () => { };
|
|
6
|
-
}
|
|
7
|
-
if (!registered) {
|
|
8
|
-
registered = true;
|
|
9
|
-
window.addEventListener('beforeunload', () => {
|
|
10
|
-
for (const callback of callbacks) {
|
|
11
|
-
callback();
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
callbacks.add(fn);
|
|
16
|
-
return () => {
|
|
17
|
-
callbacks.delete(fn);
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=exit-hook.js.map
|
package/esm/exit-hook.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"exit-hook.js","sourceRoot":"","sources":["../../src/exit-hook.ts"],"names":[],"mappings":"AAAA,MAAM,SAAS,GAAG,IAAI,GAAG,EAAc,CAAA;AAEvC,IAAI,UAAU,GAAG,KAAK,CAAA;AAEtB,MAAM,UAAU,UAAU,CAAC,EAAc;IACrC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAChC,OAAO,GAAG,EAAE,GAAE,CAAC,CAAA;IACnB,CAAC;IACD,IAAI,CAAC,UAAU,EAAE,CAAC;QACd,UAAU,GAAG,IAAI,CAAA;QAEjB,MAAM,CAAC,gBAAgB,CAAC,cAAc,EAAE,GAAG,EAAE;YACzC,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;gBAC/B,QAAQ,EAAE,CAAA;YACd,CAAC;QACL,CAAC,CAAC,CAAA;IACN,CAAC;IAED,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IAEjB,OAAO,GAAG,EAAE;QACR,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;IACxB,CAAC,CAAA;AACL,CAAC","sourcesContent":["const callbacks = new Set<() => void>()\n\nlet registered = false\n\nexport function beforeExit(fn: () => void): () => void {\n if (typeof window === 'undefined') {\n return () => {}\n }\n if (!registered) {\n registered = true\n\n window.addEventListener('beforeunload', () => {\n for (const callback of callbacks) {\n callback()\n }\n })\n }\n\n callbacks.add(fn)\n\n return () => {\n callbacks.delete(fn)\n }\n}\n"]}
|
package/esm/idb/driver.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { BaseStorageDriver } from '@mtcute/core';
|
|
2
|
-
export type PostMigrationFunction = (db: IDBDatabase) => Promise<void>;
|
|
3
|
-
type MigrationFunction = (db: IDBDatabase) => void | PostMigrationFunction;
|
|
4
|
-
export declare class IdbStorageDriver extends BaseStorageDriver {
|
|
5
|
-
readonly _dbName: string;
|
|
6
|
-
db: IDBDatabase;
|
|
7
|
-
constructor(_dbName: string);
|
|
8
|
-
private _pendingWrites;
|
|
9
|
-
private _pendingWritesOses;
|
|
10
|
-
private _migrations;
|
|
11
|
-
private _maxVersion;
|
|
12
|
-
registerMigration(repo: string, version: number, migration: MigrationFunction): void;
|
|
13
|
-
writeLater(os: string, obj: unknown): void;
|
|
14
|
-
_load(): Promise<void>;
|
|
15
|
-
_save(): Promise<void>;
|
|
16
|
-
_destroy(): void;
|
|
17
|
-
}
|
|
18
|
-
export {};
|
package/esm/idb/driver.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { BaseStorageDriver, MtUnsupportedError } from '@mtcute/core';
|
|
2
|
-
import { txToPromise } from './utils.js';
|
|
3
|
-
const REPO_VERSION_PREFIX = '__version:';
|
|
4
|
-
export class IdbStorageDriver extends BaseStorageDriver {
|
|
5
|
-
_dbName;
|
|
6
|
-
db;
|
|
7
|
-
constructor(_dbName) {
|
|
8
|
-
super();
|
|
9
|
-
this._dbName = _dbName;
|
|
10
|
-
if (typeof indexedDB === 'undefined') {
|
|
11
|
-
throw new MtUnsupportedError('IndexedDB is not available');
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
_pendingWrites = [];
|
|
15
|
-
_pendingWritesOses = new Set();
|
|
16
|
-
_migrations = new Map();
|
|
17
|
-
_maxVersion = new Map();
|
|
18
|
-
registerMigration(repo, version, migration) {
|
|
19
|
-
if (this.loaded) {
|
|
20
|
-
throw new Error('Cannot register migrations after loading');
|
|
21
|
-
}
|
|
22
|
-
let map = this._migrations.get(repo);
|
|
23
|
-
if (!map) {
|
|
24
|
-
map = new Map();
|
|
25
|
-
this._migrations.set(repo, map);
|
|
26
|
-
}
|
|
27
|
-
if (map.has(version)) {
|
|
28
|
-
throw new Error(`Migration for ${repo} version ${version} is already registered`);
|
|
29
|
-
}
|
|
30
|
-
map.set(version, migration);
|
|
31
|
-
const prevMax = this._maxVersion.get(repo) ?? 0;
|
|
32
|
-
if (version > prevMax) {
|
|
33
|
-
this._maxVersion.set(repo, version);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
writeLater(os, obj) {
|
|
37
|
-
this._pendingWrites.push([os, obj]);
|
|
38
|
-
this._pendingWritesOses.add(os);
|
|
39
|
-
}
|
|
40
|
-
async _load() {
|
|
41
|
-
this.db = await new Promise((resolve, reject) => {
|
|
42
|
-
// indexed db fucking sucks - we can't create tables once we have loaded
|
|
43
|
-
// and making an ever-incrementing version number is pretty hard
|
|
44
|
-
// since migrations are added dynamically.
|
|
45
|
-
//
|
|
46
|
-
// force the database to always emit `upgradeneeded` by passing current time
|
|
47
|
-
const req = indexedDB.open(this._dbName, Date.now());
|
|
48
|
-
req.onerror = () => reject(req.error);
|
|
49
|
-
const postUpgrade = [];
|
|
50
|
-
req.onsuccess = async () => {
|
|
51
|
-
try {
|
|
52
|
-
for (const cb of postUpgrade) {
|
|
53
|
-
await cb(req.result);
|
|
54
|
-
}
|
|
55
|
-
resolve(req.result);
|
|
56
|
-
}
|
|
57
|
-
catch (e) {
|
|
58
|
-
reject(e);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
req.onupgradeneeded = () => {
|
|
62
|
-
// indexed db still fucking sucks. we can't fetch anything from here,
|
|
63
|
-
// since migrations must be sync, and any fetch is inherently async
|
|
64
|
-
// what we do have, however, is the list of object stores.
|
|
65
|
-
// we can abuse them to store the current migrations status as plain strings
|
|
66
|
-
const db = req.result;
|
|
67
|
-
const didUpgrade = new Set();
|
|
68
|
-
const doUpgrade = (repo, fromVersion) => {
|
|
69
|
-
const migrations = this._migrations.get(repo);
|
|
70
|
-
if (!migrations)
|
|
71
|
-
return;
|
|
72
|
-
const targetVer = this._maxVersion.get(repo);
|
|
73
|
-
while (fromVersion < targetVer) {
|
|
74
|
-
const nextVersion = fromVersion + 1;
|
|
75
|
-
const migration = migrations.get(nextVersion);
|
|
76
|
-
if (!migration) {
|
|
77
|
-
throw new Error(`No migration for ${repo} to version ${nextVersion}`);
|
|
78
|
-
}
|
|
79
|
-
const result = migration(db);
|
|
80
|
-
if (result) {
|
|
81
|
-
// guess what? IDB still. fucking. sucks!
|
|
82
|
-
// if we want to do something except creating/removing
|
|
83
|
-
// databases, we should do this outside of migration
|
|
84
|
-
postUpgrade.push(result);
|
|
85
|
-
}
|
|
86
|
-
fromVersion = nextVersion;
|
|
87
|
-
}
|
|
88
|
-
didUpgrade.add(repo);
|
|
89
|
-
db.createObjectStore(`${REPO_VERSION_PREFIX}${repo}:${targetVer}`);
|
|
90
|
-
};
|
|
91
|
-
for (const key of db.objectStoreNames) {
|
|
92
|
-
if (!key.startsWith(REPO_VERSION_PREFIX))
|
|
93
|
-
continue;
|
|
94
|
-
const [, repo, version] = key.split(':');
|
|
95
|
-
const currentVer = Number(version);
|
|
96
|
-
db.deleteObjectStore(key);
|
|
97
|
-
doUpgrade(repo, currentVer);
|
|
98
|
-
didUpgrade.add(repo);
|
|
99
|
-
}
|
|
100
|
-
for (const repo of this._migrations.keys()) {
|
|
101
|
-
if (didUpgrade.has(repo))
|
|
102
|
-
continue;
|
|
103
|
-
doUpgrade(repo, 0);
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
async _save() {
|
|
109
|
-
if (this._pendingWritesOses.size === 0)
|
|
110
|
-
return;
|
|
111
|
-
const writes = this._pendingWrites;
|
|
112
|
-
const oses = this._pendingWritesOses;
|
|
113
|
-
this._pendingWrites = [];
|
|
114
|
-
this._pendingWritesOses = new Set();
|
|
115
|
-
const tx = this.db.transaction(oses, 'readwrite');
|
|
116
|
-
const osMap = new Map();
|
|
117
|
-
for (const table of oses) {
|
|
118
|
-
osMap.set(table, tx.objectStore(table));
|
|
119
|
-
}
|
|
120
|
-
for (const [table, obj] of writes) {
|
|
121
|
-
const os = osMap.get(table);
|
|
122
|
-
if (obj === null) {
|
|
123
|
-
os.delete(table);
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
os.put(obj);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
await txToPromise(tx);
|
|
130
|
-
}
|
|
131
|
-
_destroy() {
|
|
132
|
-
this.db.close();
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
//# sourceMappingURL=driver.js.map
|
package/esm/idb/driver.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"driver.js","sourceRoot":"","sources":["../../../src/idb/driver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAEpE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAKxC,MAAM,mBAAmB,GAAG,YAAY,CAAA;AAExC,MAAM,OAAO,gBAAiB,SAAQ,iBAAiB;IAG9B;IAFrB,EAAE,CAAc;IAEhB,YAAqB,OAAe;QAChC,KAAK,EAAE,CAAA;QADU,YAAO,GAAP,OAAO,CAAQ;QAGhC,IAAI,OAAO,SAAS,KAAK,WAAW,EAAE,CAAC;YACnC,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sourcesContent":["import { BaseStorageDriver, MtUnsupportedError } from '@mtcute/core'\n\nimport { txToPromise } from './utils.js'\n\nexport type PostMigrationFunction = (db: IDBDatabase) => Promise<void>\ntype MigrationFunction = (db: IDBDatabase) => void | PostMigrationFunction\n\nconst REPO_VERSION_PREFIX = '__version:'\n\nexport class IdbStorageDriver extends BaseStorageDriver {\n db!: IDBDatabase\n\n constructor(readonly _dbName: string) {\n super()\n\n if (typeof indexedDB === 'undefined') {\n throw new MtUnsupportedError('IndexedDB is not available')\n }\n }\n\n private _pendingWrites: [string, unknown][] = []\n private _pendingWritesOses = new Set<string>()\n private _migrations: Map<string, Map<number, MigrationFunction>> = new Map()\n private _maxVersion: Map<string, number> = new Map()\n\n registerMigration(repo: string, version: number, migration: MigrationFunction): void {\n if (this.loaded) {\n throw new Error('Cannot register migrations after loading')\n }\n\n let map = this._migrations.get(repo)\n\n if (!map) {\n map = new Map()\n this._migrations.set(repo, map)\n }\n\n if (map.has(version)) {\n throw new Error(`Migration for ${repo} version ${version} is already registered`)\n }\n\n map.set(version, migration)\n\n const prevMax = this._maxVersion.get(repo) ?? 0\n\n if (version > prevMax) {\n this._maxVersion.set(repo, version)\n }\n }\n\n writeLater(os: string, obj: unknown): void {\n this._pendingWrites.push([os, obj])\n this._pendingWritesOses.add(os)\n }\n\n async _load(): Promise<void> {\n this.db = await new Promise((resolve, reject) => {\n // indexed db fucking sucks - we can't create tables once we have loaded\n // and making an ever-incrementing version number is pretty hard\n // since migrations are added dynamically.\n //\n // force the database to always emit `upgradeneeded` by passing current time\n const req = indexedDB.open(this._dbName, Date.now())\n\n req.onerror = () => reject(req.error)\n\n const postUpgrade: PostMigrationFunction[] = []\n\n req.onsuccess = async () => {\n try {\n for (const cb of postUpgrade) {\n await cb(req.result)\n }\n resolve(req.result)\n } catch (e) {\n reject(e)\n }\n }\n req.onupgradeneeded = () => {\n // indexed db still fucking sucks. we can't fetch anything from here,\n // since migrations must be sync, and any fetch is inherently async\n // what we do have, however, is the list of object stores.\n // we can abuse them to store the current migrations status as plain strings\n const db = req.result\n\n const didUpgrade = new Set<string>()\n\n const doUpgrade = (repo: string, fromVersion: number) => {\n const migrations = this._migrations.get(repo)\n if (!migrations) return\n\n const targetVer = this._maxVersion.get(repo)!\n\n while (fromVersion < targetVer) {\n const nextVersion = fromVersion + 1\n const migration = migrations.get(nextVersion)\n\n if (!migration) {\n throw new Error(`No migration for ${repo} to version ${nextVersion}`)\n }\n\n const result = migration(db)\n\n if (result) {\n // guess what? IDB still. fucking. sucks!\n // if we want to do something except creating/removing\n // databases, we should do this outside of migration\n postUpgrade.push(result)\n }\n\n fromVersion = nextVersion\n }\n\n didUpgrade.add(repo)\n db.createObjectStore(`${REPO_VERSION_PREFIX}${repo}:${targetVer}`)\n }\n\n for (const key of db.objectStoreNames) {\n if (!key.startsWith(REPO_VERSION_PREFIX)) continue\n const [, repo, version] = key.split(':')\n\n const currentVer = Number(version)\n db.deleteObjectStore(key)\n doUpgrade(repo, currentVer)\n didUpgrade.add(repo)\n }\n\n for (const repo of this._migrations.keys()) {\n if (didUpgrade.has(repo)) continue\n\n doUpgrade(repo, 0)\n }\n }\n })\n }\n\n async _save(): Promise<void> {\n if (this._pendingWritesOses.size === 0) return\n\n const writes = this._pendingWrites\n const oses = this._pendingWritesOses\n this._pendingWrites = []\n this._pendingWritesOses = new Set()\n\n const tx = this.db.transaction(oses, 'readwrite')\n\n const osMap = new Map<string, IDBObjectStore>()\n\n for (const table of oses) {\n osMap.set(table, tx.objectStore(table))\n }\n\n for (const [table, obj] of writes) {\n const os = osMap.get(table)!\n\n if (obj === null) {\n os.delete(table)\n } else {\n os.put(obj)\n }\n }\n\n await txToPromise(tx)\n }\n\n _destroy(): void {\n this.db.close()\n }\n}\n"]}
|
package/esm/idb/index.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { IdbStorageDriver } from './driver.js';
|
|
2
|
-
import { IdbAuthKeysRepository } from './repository/auth-keys.js';
|
|
3
|
-
import { IdbKvRepository } from './repository/kv.js';
|
|
4
|
-
import { IdbPeersRepository } from './repository/peers.js';
|
|
5
|
-
import { IdbRefMsgRepository } from './repository/ref-messages.js';
|
|
6
|
-
export { IdbStorageDriver } from './driver.js';
|
|
7
|
-
/**
|
|
8
|
-
* mtcute storage that uses IndexedDB as a backend.
|
|
9
|
-
*
|
|
10
|
-
* This storage is the default one for browsers, and is generally
|
|
11
|
-
* recommended over local storage based one.
|
|
12
|
-
*/
|
|
13
|
-
export class IdbStorage {
|
|
14
|
-
dbName;
|
|
15
|
-
driver;
|
|
16
|
-
kv;
|
|
17
|
-
authKeys;
|
|
18
|
-
peers;
|
|
19
|
-
refMessages;
|
|
20
|
-
constructor(dbName) {
|
|
21
|
-
this.dbName = dbName;
|
|
22
|
-
this.driver = new IdbStorageDriver(this.dbName);
|
|
23
|
-
this.kv = new IdbKvRepository(this.driver);
|
|
24
|
-
this.authKeys = new IdbAuthKeysRepository(this.driver);
|
|
25
|
-
this.peers = new IdbPeersRepository(this.driver);
|
|
26
|
-
this.refMessages = new IdbRefMsgRepository(this.driver);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
//# sourceMappingURL=index.js.map
|
package/esm/idb/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/idb/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAA;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAA;AAElE,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAE9C;;;;;GAKG;AACH,MAAM,OAAO,UAAU;IAOE;IANZ,MAAM,CAAkB;IACxB,EAAE,CAAiB;IACnB,QAAQ,CAAuB;IAC/B,KAAK,CAAoB;IACzB,WAAW,CAAqB;IAEzC,YAAqB,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;QAC/B,IAAI,CAAC,MAAM,GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAC/C,IAAI,CAAC,EAAE,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAC1C,IAAI,CAAC,QAAQ,GAAG,IAAI,qBAAqB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QACtD,IAAI,CAAC,KAAK,GAAG,IAAI,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAChD,IAAI,CAAC,WAAW,GAAG,IAAI,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAC3D,CAAC;CACJ","sourcesContent":["import type { IMtStorageProvider } from '@mtcute/core'\n\nimport { IdbStorageDriver } from './driver.js'\nimport { IdbAuthKeysRepository } from './repository/auth-keys.js'\nimport { IdbKvRepository } from './repository/kv.js'\nimport { IdbPeersRepository } from './repository/peers.js'\nimport { IdbRefMsgRepository } from './repository/ref-messages.js'\n\nexport { IdbStorageDriver } from './driver.js'\n\n/**\n * mtcute storage that uses IndexedDB as a backend.\n *\n * This storage is the default one for browsers, and is generally\n * recommended over local storage based one.\n */\nexport class IdbStorage implements IMtStorageProvider {\n readonly driver: IdbStorageDriver\n readonly kv: IdbKvRepository\n readonly authKeys: IdbAuthKeysRepository\n readonly peers: IdbPeersRepository\n readonly refMessages: IdbRefMsgRepository\n\n constructor(readonly dbName: string) {\n this.driver = new IdbStorageDriver(this.dbName)\n this.kv = new IdbKvRepository(this.driver)\n this.authKeys = new IdbAuthKeysRepository(this.driver)\n this.peers = new IdbPeersRepository(this.driver)\n this.refMessages = new IdbRefMsgRepository(this.driver)\n }\n}\n"]}
|