lib0 0.2.61 → 0.2.63
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 +48 -5
- package/array.d.ts +5 -5
- package/array.d.ts.map +1 -1
- package/array.js +26 -10
- package/array.test.d.ts +1 -0
- package/array.test.d.ts.map +1 -1
- package/crypto.d.ts +22 -0
- package/crypto.d.ts.map +1 -0
- package/crypto.js +185 -0
- package/crypto.test.d.ts +6 -0
- package/crypto.test.d.ts.map +1 -0
- package/dist/{array-42d0736b.cjs → array-5347125b.cjs} +27 -11
- package/dist/array-5347125b.cjs.map +1 -0
- package/dist/array.cjs +1 -1
- package/dist/array.d.ts +5 -5
- package/dist/array.d.ts.map +1 -1
- package/dist/array.test.d.ts +1 -0
- package/dist/array.test.d.ts.map +1 -1
- package/dist/{broadcastchannel-8d21c21c.cjs → broadcastchannel-61da4e94.cjs} +2 -2
- package/dist/{broadcastchannel-8d21c21c.cjs.map → broadcastchannel-61da4e94.cjs.map} +1 -1
- package/dist/broadcastchannel.cjs +5 -5
- package/dist/{buffer-22bb9fae.cjs → buffer-884e5a1d.cjs} +2 -2
- package/dist/{buffer-22bb9fae.cjs.map → buffer-884e5a1d.cjs.map} +1 -1
- package/dist/buffer.cjs +4 -4
- package/dist/cache.cjs +2 -2
- package/dist/component.cjs +3 -3
- package/dist/crypto.cjs +231 -0
- package/dist/crypto.cjs.map +1 -0
- package/dist/crypto.d.ts +22 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.test.d.ts +6 -0
- package/dist/crypto.test.d.ts.map +1 -0
- package/dist/decoding.cjs +4 -4
- package/dist/{diff-ee50c530.cjs → diff-2cbda723.cjs} +2 -2
- package/dist/{diff-ee50c530.cjs.map → diff-2cbda723.cjs.map} +1 -1
- package/dist/diff.cjs +3 -3
- package/dist/encoding.cjs +4 -4
- package/dist/{environment-f6386808.cjs → environment-ad5e7386.cjs} +2 -2
- package/dist/{environment-f6386808.cjs.map → environment-ad5e7386.cjs.map} +1 -1
- package/dist/environment.cjs +3 -3
- package/dist/{function-40d38a5b.cjs → function-3695121b.cjs} +2 -2
- package/dist/{function-40d38a5b.cjs.map → function-3695121b.cjs.map} +1 -1
- package/dist/function.cjs +2 -2
- package/dist/index.cjs +9 -9
- package/dist/list.cjs +2 -2
- package/dist/{logging-ba24d049.cjs → logging-70fd0a99.cjs} +3 -3
- package/dist/{logging-ba24d049.cjs.map → logging-70fd0a99.cjs.map} +1 -1
- package/dist/logging.cjs +4 -4
- package/dist/observable.cjs +1 -1
- package/dist/{prng-4493ba85.cjs → prng-397a85ab.cjs} +2 -2
- package/dist/{prng-4493ba85.cjs.map → prng-397a85ab.cjs.map} +1 -1
- package/dist/prng.cjs +5 -5
- package/dist/rollup.config.d.ts +1 -1
- package/dist/testing.cjs +7 -7
- package/dist/webcrypto.browser.cjs +12 -0
- package/dist/webcrypto.browser.cjs.map +1 -0
- package/dist/webcrypto.browser.d.ts +3 -0
- package/dist/webcrypto.browser.d.ts.map +1 -0
- package/dist/webcrypto.node.cjs +12 -0
- package/dist/webcrypto.node.cjs.map +1 -0
- package/dist/webcrypto.node.d.ts +3 -0
- package/dist/webcrypto.node.d.ts.map +1 -0
- package/dist/{websocket-a48155c2.cjs → websocket-dd57e44f.cjs} +1 -1
- package/dist/{websocket-a48155c2.cjs.map → websocket-dd57e44f.cjs.map} +1 -1
- package/dist/websocket.cjs +2 -2
- package/package.json +19 -1
- package/rollup.config.d.ts +1 -1
- package/test.js +2 -0
- package/webcrypto.browser.d.ts +3 -0
- package/webcrypto.browser.d.ts.map +1 -0
- package/webcrypto.browser.js +4 -0
- package/webcrypto.node.d.ts +3 -0
- package/webcrypto.node.d.ts.map +1 -0
- package/webcrypto.node.js +5 -0
- package/dist/array-42d0736b.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -78,7 +78,7 @@ import module from 'lib0/[module].js'
|
|
|
78
78
|
<details><summary><b>[lib0/array]</b> Utility module to work with Arrays.</summary>
|
|
79
79
|
<pre>import * as array from 'lib0/array'</pre>
|
|
80
80
|
<dl>
|
|
81
|
-
<b><code>array.last(arr:
|
|
81
|
+
<b><code>array.last(arr: ArrayLike<L>): L</code></b><br>
|
|
82
82
|
<dd><p>Return the last element of an array. The element must exist</p></dd>
|
|
83
83
|
<b><code>array.create(): Array<C></code></b><br>
|
|
84
84
|
<b><code>array.copy(a: Array<D>): Array<D></code></b><br>
|
|
@@ -86,15 +86,15 @@ import module from 'lib0/[module].js'
|
|
|
86
86
|
<dd><p>Append elements from src to dest</p></dd>
|
|
87
87
|
<b><code>array.from(arraylike: ArrayLike<T>|Iterable<T>): T</code></b><br>
|
|
88
88
|
<dd><p>Transforms something array-like to an actual Array.</p></dd>
|
|
89
|
-
<b><code>array.every(arr:
|
|
89
|
+
<b><code>array.every(arr: ARR, f: function(ITEM, number, ARR):boolean): boolean</code></b><br>
|
|
90
90
|
<dd><p>True iff condition holds on every element in the Array.</p></dd>
|
|
91
|
-
<b><code>array.some(arr:
|
|
91
|
+
<b><code>array.some(arr: ARR, f: function(S, number, ARR):boolean): boolean</code></b><br>
|
|
92
92
|
<dd><p>True iff condition holds on some element in the Array.</p></dd>
|
|
93
|
-
<b><code>array.equalFlat(a:
|
|
93
|
+
<b><code>array.equalFlat(a: ArrayLike<ELEM>, b: ArrayLike<ELEM>): boolean</code></b><br>
|
|
94
94
|
<b><code>array.flatten(arr: Array<Array<ELEM>>): Array<ELEM></code></b><br>
|
|
95
95
|
<b><code>array.isArray</code></b><br>
|
|
96
96
|
<b><code>array.unique(arr: Array<T>): Array<T></code></b><br>
|
|
97
|
-
<b><code>array.uniqueBy(arr:
|
|
97
|
+
<b><code>array.uniqueBy(arr: ArrayLike<T>, mapper: function(T):M): Array<T></code></b><br>
|
|
98
98
|
</dl>
|
|
99
99
|
</details>
|
|
100
100
|
<details><summary><b>[lib0/binary]</b> Binary data constants.</summary>
|
|
@@ -245,6 +245,30 @@ Using getAsync & setIfUndefined ensures that the init function is only calle
|
|
|
245
245
|
<b><code>conditions.undefinedToNull</code></b><br>
|
|
246
246
|
</dl>
|
|
247
247
|
</details>
|
|
248
|
+
<details><summary><b>[lib0/crypto]</b> </summary>
|
|
249
|
+
<pre>import * as crypto from 'lib0/crypto'</pre>
|
|
250
|
+
<dl>
|
|
251
|
+
<b><code>y(data: string | Uint8Array): Uint8Array</code></b><br>
|
|
252
|
+
<b><code>ymmetricKey(secret: string | Uint8Array, salt: string | Uint8Array, opts: Object, opts.extractable: boolean, opts.usages: Array<'sign'|'verify'|'encrypt'|'decrypt'>): PromiseLike<CryptoKey></code></b><br>
|
|
253
|
+
<b><code>ymmetricKey()</code></b><br>
|
|
254
|
+
<b><code>eAsymmetricKey(opts: Object, opts.extractable: boolean, opts.usages: Array<'sign'|'verify'|'encrypt'|'decrypt'>)</code></b><br>
|
|
255
|
+
<b><code>eAsymmetricKey()</code></b><br>
|
|
256
|
+
<b><code>ey(key: CryptoKey)</code></b><br>
|
|
257
|
+
<b><code>ey()</code></b><br>
|
|
258
|
+
<b><code>ymmetricKey(jwk: any, opts: Object, opts.extractable: boolean, opts.usages: Array<'sign'|'verify'|'encrypt'|'decrypt'>)</code></b><br>
|
|
259
|
+
<b><code>ymmetricKey()</code></b><br>
|
|
260
|
+
<b><code>symmetricKey(jwk: any, opts: Object, opts.extractable: boolean, opts.usages: Array<'sign'|'verify'|'encrypt'|'decrypt'>)</code></b><br>
|
|
261
|
+
<b><code>symmetricKey()</code></b><br>
|
|
262
|
+
<b><code>(data: Uint8Array, key: CryptoKey): PromiseLike<Uint8Array></code></b><br>
|
|
263
|
+
<b><code>()</code></b><br>
|
|
264
|
+
<b><code>(data: Uint8Array, key: CryptoKey): PromiseLike<Uint8Array></code></b><br>
|
|
265
|
+
<b><code>()</code></b><br>
|
|
266
|
+
<b><code>(data: Uint8Array, privateKey: CryptoKey): PromiseLike<Uint8Array></code></b><br>
|
|
267
|
+
<b><code>()</code></b><br>
|
|
268
|
+
<b><code>(signature: Uint8Array, data: Uint8Array, publicKey: CryptoKey): PromiseLike<boolean></code></b><br>
|
|
269
|
+
<b><code>()</code></b><br>
|
|
270
|
+
</dl>
|
|
271
|
+
</details>
|
|
248
272
|
<details><summary><b>[lib0/decoding]</b> Efficient schema-less binary decoding with support for variable length encoding.</summary>
|
|
249
273
|
<pre>import * as decoding from 'lib0/decoding'</pre>
|
|
250
274
|
|
|
@@ -1329,6 +1353,25 @@ export const testMyFirstTest = tc => {
|
|
|
1329
1353
|
<b><code>url.encodeQueryParams(params: Object<string,string>): string</code></b><br>
|
|
1330
1354
|
</dl>
|
|
1331
1355
|
</details>
|
|
1356
|
+
<details><summary><b>[lib0/webcrypto.browser]</b> </summary>
|
|
1357
|
+
<pre>import * as webcrypto.browser from 'lib0/webcrypto.browser'</pre>
|
|
1358
|
+
<dl>
|
|
1359
|
+
<b><code></code></b><br>
|
|
1360
|
+
<b><code>()</code></b><br>
|
|
1361
|
+
<b><code>omValues</code></b><br>
|
|
1362
|
+
<b><code>omValues()</code></b><br>
|
|
1363
|
+
</dl>
|
|
1364
|
+
</details>
|
|
1365
|
+
<details><summary><b>[lib0/webcrypto.node]</b> </summary>
|
|
1366
|
+
<pre>import * as webcrypto.node from 'lib0/webcrypto.node'</pre>
|
|
1367
|
+
<dl>
|
|
1368
|
+
<b><code></code></b><br>
|
|
1369
|
+
<b><code>()</code></b><br>
|
|
1370
|
+
<b><code>to.subtle: any</code></b><br>
|
|
1371
|
+
<b><code>omValues</code></b><br>
|
|
1372
|
+
<b><code>omValues()</code></b><br>
|
|
1373
|
+
</dl>
|
|
1374
|
+
</details>
|
|
1332
1375
|
<details><summary><b>[lib0/websocket]</b> Tiny websocket connection handler.</summary>
|
|
1333
1376
|
<pre>import * as websocket from 'lib0/websocket'</pre>
|
|
1334
1377
|
|
package/array.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function last<L>(arr: L
|
|
1
|
+
export function last<L>(arr: ArrayLike<L>): L;
|
|
2
2
|
export function create<C>(): C[];
|
|
3
3
|
export function copy<D>(a: D[]): D[];
|
|
4
4
|
export function appendTo<M>(dest: M[], src: M[]): void;
|
|
@@ -16,11 +16,11 @@ export const from: {
|
|
|
16
16
|
<T_3>(iterable: Iterable<T_3> | ArrayLike<T_3>): T_3[];
|
|
17
17
|
<T_4, U_1>(iterable: Iterable<T_4> | ArrayLike<T_4>, mapfn: (v: T_4, k: number) => U_1, thisArg?: any): U_1[];
|
|
18
18
|
};
|
|
19
|
-
export function every<ITEM
|
|
20
|
-
export function some<S
|
|
21
|
-
export function equalFlat<ELEM>(a: ELEM
|
|
19
|
+
export function every<ITEM, ARR extends ArrayLike<ITEM>>(arr: ARR, f: (arg0: ITEM, arg1: number, arg2: ARR) => boolean): boolean;
|
|
20
|
+
export function some<S, ARR extends ArrayLike<S>>(arr: ARR, f: (arg0: S, arg1: number, arg2: ARR) => boolean): boolean;
|
|
21
|
+
export function equalFlat<ELEM>(a: ArrayLike<ELEM>, b: ArrayLike<ELEM>): boolean;
|
|
22
22
|
export function flatten<ELEM>(arr: ELEM[][]): ELEM[];
|
|
23
23
|
export const isArray: (arg: any) => arg is any[];
|
|
24
24
|
export function unique<T_1>(arr: T_1[]): T_1[];
|
|
25
|
-
export function uniqueBy<T_1, M>(arr: T_1
|
|
25
|
+
export function uniqueBy<T_1, M>(arr: ArrayLike<T_1>, mapper: (arg0: T_1) => M): T_1[];
|
|
26
26
|
//# sourceMappingURL=array.d.ts.map
|
package/array.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["array.js"],"names":[],"mappings":"AAeO,
|
|
1
|
+
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["array.js"],"names":[],"mappings":"AAeO,8CAAuC;AAMvC,iCAAiD;AAOjD,qCAAqD;AASrD,uDAIN;AAED;;;;;;;GAOG;AACH;;;;;EAA8B;AAavB,yFAHmB,MAAM,gBAAO,OAAO,GAClC,OAAO,CASlB;AAYM,+EAHgB,MAAM,gBAAO,OAAO,GAC/B,OAAO,CASlB;AASM,yEAFK,OAAO,CAEqF;AAOjG,qDAAoE;AAE3E,iDAAoC;AAO7B,+CAAyC;AASzC,uFAkBN"}
|
package/array.js
CHANGED
|
@@ -10,7 +10,7 @@ import * as set from './set.js'
|
|
|
10
10
|
* Return the last element of an array. The element must exist
|
|
11
11
|
*
|
|
12
12
|
* @template L
|
|
13
|
-
* @param {
|
|
13
|
+
* @param {ArrayLike<L>} arr
|
|
14
14
|
* @return {L}
|
|
15
15
|
*/
|
|
16
16
|
export const last = arr => arr[arr.length - 1]
|
|
@@ -56,29 +56,45 @@ export const from = Array.from
|
|
|
56
56
|
*
|
|
57
57
|
* @function
|
|
58
58
|
* @template ITEM
|
|
59
|
+
* @template {ArrayLike<ITEM>} ARR
|
|
59
60
|
*
|
|
60
|
-
* @param {
|
|
61
|
-
* @param {function(ITEM, number,
|
|
61
|
+
* @param {ARR} arr
|
|
62
|
+
* @param {function(ITEM, number, ARR):boolean} f
|
|
62
63
|
* @return {boolean}
|
|
63
64
|
*/
|
|
64
|
-
export const every = (arr, f) =>
|
|
65
|
+
export const every = (arr, f) => {
|
|
66
|
+
for (let i = 0; i < arr.length; i++) {
|
|
67
|
+
if (!f(arr[i], i, arr)) {
|
|
68
|
+
return false
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return true
|
|
72
|
+
}
|
|
65
73
|
|
|
66
74
|
/**
|
|
67
75
|
* True iff condition holds on some element in the Array.
|
|
68
76
|
*
|
|
69
77
|
* @function
|
|
70
78
|
* @template S
|
|
71
|
-
* @
|
|
72
|
-
* @param {
|
|
79
|
+
* @template {ArrayLike<S>} ARR
|
|
80
|
+
* @param {ARR} arr
|
|
81
|
+
* @param {function(S, number, ARR):boolean} f
|
|
73
82
|
* @return {boolean}
|
|
74
83
|
*/
|
|
75
|
-
export const some = (arr, f) =>
|
|
84
|
+
export const some = (arr, f) => {
|
|
85
|
+
for (let i = 0; i < arr.length; i++) {
|
|
86
|
+
if (f(arr[i], i, arr)) {
|
|
87
|
+
return true
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return false
|
|
91
|
+
}
|
|
76
92
|
|
|
77
93
|
/**
|
|
78
94
|
* @template ELEM
|
|
79
95
|
*
|
|
80
|
-
* @param {
|
|
81
|
-
* @param {
|
|
96
|
+
* @param {ArrayLike<ELEM>} a
|
|
97
|
+
* @param {ArrayLike<ELEM>} b
|
|
82
98
|
* @return {boolean}
|
|
83
99
|
*/
|
|
84
100
|
export const equalFlat = (a, b) => a.length === b.length && every(a, (item, index) => item === b[index])
|
|
@@ -102,7 +118,7 @@ export const unique = arr => from(set.from(arr))
|
|
|
102
118
|
/**
|
|
103
119
|
* @template T
|
|
104
120
|
* @template M
|
|
105
|
-
* @param {
|
|
121
|
+
* @param {ArrayLike<T>} arr
|
|
106
122
|
* @param {function(T):M} mapper
|
|
107
123
|
* @return {Array<T>}
|
|
108
124
|
*/
|
package/array.test.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export function testAppend(tc: t.TestCase): void;
|
|
2
2
|
export function testflatten(tc: t.TestCase): void;
|
|
3
|
+
export function testEvery(tc: t.TestCase): void;
|
|
3
4
|
export function testIsArray(tc: t.TestCase): void;
|
|
4
5
|
export function testUnique(tc: t.TestCase): void;
|
|
5
6
|
import * as t from "./testing.js";
|
package/array.test.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array.test.d.ts","sourceRoot":"","sources":["array.test.js"],"names":[],"mappings":"AAOO,+BAFI,EAAE,QAAQ,QAMpB;AAKM,gCAFI,EAAE,QAAQ,QAKpB;AAKM,gCAFI,EAAE,QAAQ,QASpB;AAKM,+BAFI,EAAE,QAAQ,QAOpB"}
|
|
1
|
+
{"version":3,"file":"array.test.d.ts","sourceRoot":"","sources":["array.test.js"],"names":[],"mappings":"AAOO,+BAFI,EAAE,QAAQ,QAMpB;AAKM,gCAFI,EAAE,QAAQ,QAKpB;AAKM,8BAFI,EAAE,QAAQ,QAQpB;AAKM,gCAFI,EAAE,QAAQ,QASpB;AAKM,+BAFI,EAAE,QAAQ,QAOpB"}
|
package/crypto.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function deriveSymmetricKey(secret: string | Uint8Array, salt: string | Uint8Array, { extractable, usages }?: {
|
|
2
|
+
extractable?: boolean | undefined;
|
|
3
|
+
usages?: ("decrypt" | "encrypt" | "sign" | "verify")[] | undefined;
|
|
4
|
+
}): PromiseLike<CryptoKey>;
|
|
5
|
+
export function generateAsymmetricKey({ extractable, usages }?: {
|
|
6
|
+
extractable?: boolean | undefined;
|
|
7
|
+
usages?: ("decrypt" | "encrypt" | "sign" | "verify")[] | undefined;
|
|
8
|
+
}): Promise<CryptoKeyPair>;
|
|
9
|
+
export function exportKey(key: CryptoKey): Promise<JsonWebKey>;
|
|
10
|
+
export function importSymmetricKey(jwk: any, { extractable, usages }?: {
|
|
11
|
+
extractable?: boolean | undefined;
|
|
12
|
+
usages?: ("decrypt" | "encrypt" | "sign" | "verify")[] | undefined;
|
|
13
|
+
}): Promise<CryptoKey>;
|
|
14
|
+
export function importAsymmetricKey(jwk: any, { extractable, usages }?: {
|
|
15
|
+
extractable?: boolean | undefined;
|
|
16
|
+
usages?: ("decrypt" | "encrypt" | "sign" | "verify")[] | undefined;
|
|
17
|
+
}): Promise<CryptoKey>;
|
|
18
|
+
export function encrypt(data: Uint8Array, key: CryptoKey): PromiseLike<Uint8Array>;
|
|
19
|
+
export function decrypt(data: Uint8Array, key: CryptoKey): PromiseLike<Uint8Array>;
|
|
20
|
+
export function sign(data: Uint8Array, privateKey: CryptoKey): PromiseLike<Uint8Array>;
|
|
21
|
+
export function verify(signature: Uint8Array, data: Uint8Array, publicKey: CryptoKey): PromiseLike<boolean>;
|
|
22
|
+
//# sourceMappingURL=crypto.d.ts.map
|
package/crypto.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["crypto.js"],"names":[],"mappings":"AA0BO,2CAPI,MAAM,GAAG,UAAU,QACnB,MAAM,GAAG,UAAU;IAEJ,WAAW;IACwB,MAAM;IACvD,YAAY,SAAS,CAAC,CA4BjC;AAQM;IAHmB,WAAW;IACwB,MAAM;2BAUhE;AAMI,+BAFI,SAAS,uBAEkD;AAS/D,wCALI,GAAG;IAEY,WAAW;IACwB,MAAM;uBAGI;AAShE,yCALI,GAAG;IAEY,WAAW;IACwB,MAAM;uBAGkC;AAW9F,8BAJI,UAAU,OACV,SAAS,GACR,YAAY,UAAU,CAAC,CAkBlC;AAWM,8BAJI,UAAU,OACV,SAAS,GACR,YAAY,UAAU,CAAC,CAclC;AAWM,2BAJI,UAAU,cACV,SAAS,GACR,YAAY,UAAU,CAAC,CAUa;AAYzC,kCALI,UAAU,QACV,UAAU,aACV,SAAS,GACR,YAAY,OAAO,CAAC,CAW7B"}
|
package/crypto.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/* eslint-env browser */
|
|
2
|
+
|
|
3
|
+
import * as encoding from './encoding.js'
|
|
4
|
+
import * as decoding from './decoding.js'
|
|
5
|
+
import * as string from './string.js'
|
|
6
|
+
import * as webcrypto from 'lib0/webcrypto'
|
|
7
|
+
|
|
8
|
+
/* istanbul ignore next */
|
|
9
|
+
/**
|
|
10
|
+
* @param {string | Uint8Array} data
|
|
11
|
+
* @return {Uint8Array}
|
|
12
|
+
*/
|
|
13
|
+
const toBinary = data => typeof data === 'string' ? string.encodeUtf8(data) : data
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @experimental The API is not final!
|
|
17
|
+
*
|
|
18
|
+
* Derive an symmetric key using the Password-Based-Key-Derivation-Function-2.
|
|
19
|
+
*
|
|
20
|
+
* @param {string | Uint8Array} secret
|
|
21
|
+
* @param {string | Uint8Array} salt
|
|
22
|
+
* @param {Object} opts
|
|
23
|
+
* @param {boolean} [opts.extractable]
|
|
24
|
+
* @param {Array<'sign'|'verify'|'encrypt'|'decrypt'>} [opts.usages]
|
|
25
|
+
* @return {PromiseLike<CryptoKey>}
|
|
26
|
+
*/
|
|
27
|
+
export const deriveSymmetricKey = (secret, salt, { extractable = false, usages = ['encrypt', 'decrypt'] } = {}) => {
|
|
28
|
+
const binSecret = toBinary(secret)
|
|
29
|
+
const binSalt = toBinary(salt)
|
|
30
|
+
return webcrypto.subtle.importKey(
|
|
31
|
+
'raw',
|
|
32
|
+
binSecret,
|
|
33
|
+
'PBKDF2',
|
|
34
|
+
false,
|
|
35
|
+
['deriveKey']
|
|
36
|
+
).then(keyMaterial =>
|
|
37
|
+
webcrypto.subtle.deriveKey(
|
|
38
|
+
{
|
|
39
|
+
name: 'PBKDF2',
|
|
40
|
+
salt: binSalt, // NIST recommends at least 64 bits
|
|
41
|
+
iterations: 600000, // OWASP recommends 600k iterations
|
|
42
|
+
hash: 'SHA-256'
|
|
43
|
+
},
|
|
44
|
+
keyMaterial,
|
|
45
|
+
{
|
|
46
|
+
name: 'AES-GCM',
|
|
47
|
+
length: 256
|
|
48
|
+
},
|
|
49
|
+
extractable,
|
|
50
|
+
usages
|
|
51
|
+
)
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/* istanbul ignore next */
|
|
56
|
+
/**
|
|
57
|
+
* @param {Object} opts
|
|
58
|
+
* @param {boolean} [opts.extractable]
|
|
59
|
+
* @param {Array<'sign'|'verify'|'encrypt'|'decrypt'>} [opts.usages]
|
|
60
|
+
*/
|
|
61
|
+
export const generateAsymmetricKey = ({ extractable = false, usages = ['sign', 'verify'] } = {}) =>
|
|
62
|
+
webcrypto.subtle.generateKey(
|
|
63
|
+
{
|
|
64
|
+
name: 'ECDSA',
|
|
65
|
+
namedCurve: 'P-384'
|
|
66
|
+
},
|
|
67
|
+
extractable,
|
|
68
|
+
usages
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
/* istanbul ignore next */
|
|
72
|
+
/**
|
|
73
|
+
* @param {CryptoKey} key - Symmetric or Asymmetric key
|
|
74
|
+
*/
|
|
75
|
+
export const exportKey = key => webcrypto.subtle.exportKey('jwk', key)
|
|
76
|
+
|
|
77
|
+
/* istanbul ignore next */
|
|
78
|
+
/**
|
|
79
|
+
* @param {any} jwk
|
|
80
|
+
* @param {Object} opts
|
|
81
|
+
* @param {boolean} [opts.extractable]
|
|
82
|
+
* @param {Array<'sign'|'verify'|'encrypt'|'decrypt'>} [opts.usages]
|
|
83
|
+
*/
|
|
84
|
+
export const importSymmetricKey = (jwk, { extractable = false, usages = ['encrypt', 'decrypt'] } = {}) =>
|
|
85
|
+
webcrypto.subtle.importKey('jwk', jwk, 'PBKDF2', extractable, usages)
|
|
86
|
+
|
|
87
|
+
/* istanbul ignore next */
|
|
88
|
+
/**
|
|
89
|
+
* @param {any} jwk
|
|
90
|
+
* @param {Object} opts
|
|
91
|
+
* @param {boolean} [opts.extractable]
|
|
92
|
+
* @param {Array<'sign'|'verify'|'encrypt'|'decrypt'>} [opts.usages]
|
|
93
|
+
*/
|
|
94
|
+
export const importAsymmetricKey = (jwk, { extractable = false, usages = ['encrypt', 'decrypt'] } = {}) =>
|
|
95
|
+
webcrypto.subtle.importKey('jwk', jwk, { name: 'ECDSA', namedCurve: 'P-384' }, extractable, usages)
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @experimental The API is not final!
|
|
99
|
+
*
|
|
100
|
+
* Encrypt some data using AES-GCM method.
|
|
101
|
+
*
|
|
102
|
+
* @param {Uint8Array} data data to be encrypted
|
|
103
|
+
* @param {CryptoKey} key
|
|
104
|
+
* @return {PromiseLike<Uint8Array>} encrypted, base64 encoded message
|
|
105
|
+
*/
|
|
106
|
+
export const encrypt = (data, key) => {
|
|
107
|
+
const iv = webcrypto.getRandomValues(new Uint8Array(16)) // 92bit is enough. 128bit is recommended if space is not an issue.
|
|
108
|
+
return webcrypto.subtle.encrypt(
|
|
109
|
+
{
|
|
110
|
+
name: 'AES-GCM',
|
|
111
|
+
iv
|
|
112
|
+
},
|
|
113
|
+
key,
|
|
114
|
+
data
|
|
115
|
+
).then(cipher => {
|
|
116
|
+
const encryptedDataEncoder = encoding.createEncoder()
|
|
117
|
+
// iv may be sent in the clear to the other peers
|
|
118
|
+
encoding.writeUint8Array(encryptedDataEncoder, iv)
|
|
119
|
+
encoding.writeVarUint8Array(encryptedDataEncoder, new Uint8Array(cipher))
|
|
120
|
+
return encoding.toUint8Array(encryptedDataEncoder)
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* @experimental The API is not final!
|
|
126
|
+
*
|
|
127
|
+
* Decrypt some data using AES-GCM method.
|
|
128
|
+
*
|
|
129
|
+
* @param {Uint8Array} data
|
|
130
|
+
* @param {CryptoKey} key
|
|
131
|
+
* @return {PromiseLike<Uint8Array>} decrypted buffer
|
|
132
|
+
*/
|
|
133
|
+
export const decrypt = (data, key) => {
|
|
134
|
+
const dataDecoder = decoding.createDecoder(data)
|
|
135
|
+
const iv = decoding.readUint8Array(dataDecoder, 16)
|
|
136
|
+
const cipher = decoding.readVarUint8Array(dataDecoder)
|
|
137
|
+
return webcrypto.subtle.decrypt(
|
|
138
|
+
{
|
|
139
|
+
name: 'AES-GCM',
|
|
140
|
+
iv
|
|
141
|
+
},
|
|
142
|
+
key,
|
|
143
|
+
cipher
|
|
144
|
+
).then(data => new Uint8Array(data))
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* @experimental The API is not final!
|
|
149
|
+
*
|
|
150
|
+
* Sign a message
|
|
151
|
+
*
|
|
152
|
+
* @param {Uint8Array} data
|
|
153
|
+
* @param {CryptoKey} privateKey
|
|
154
|
+
* @return {PromiseLike<Uint8Array>} signature
|
|
155
|
+
*/
|
|
156
|
+
export const sign = (data, privateKey) =>
|
|
157
|
+
webcrypto.subtle.sign(
|
|
158
|
+
{
|
|
159
|
+
name: 'ECDSA',
|
|
160
|
+
hash: { name: 'SHA-384' }
|
|
161
|
+
},
|
|
162
|
+
privateKey,
|
|
163
|
+
data
|
|
164
|
+
).then(signature => new Uint8Array(signature))
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* @experimental The API is not final!
|
|
168
|
+
*
|
|
169
|
+
* Sign a message
|
|
170
|
+
*
|
|
171
|
+
* @param {Uint8Array} signature
|
|
172
|
+
* @param {Uint8Array} data
|
|
173
|
+
* @param {CryptoKey} publicKey
|
|
174
|
+
* @return {PromiseLike<boolean>} signature
|
|
175
|
+
*/
|
|
176
|
+
export const verify = (signature, data, publicKey) =>
|
|
177
|
+
webcrypto.subtle.verify(
|
|
178
|
+
{
|
|
179
|
+
name: 'ECDSA',
|
|
180
|
+
hash: { name: 'SHA-384' }
|
|
181
|
+
},
|
|
182
|
+
publicKey,
|
|
183
|
+
signature,
|
|
184
|
+
data
|
|
185
|
+
)
|
package/crypto.test.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export function testReapeatEncryption(tc: t.TestCase): Promise<void>;
|
|
2
|
+
export function testEncryptionPerformance(tc: t.TestCase): Promise<void>;
|
|
3
|
+
export function testConsistentKeyGeneration(_tc: t.TestCase): Promise<void>;
|
|
4
|
+
export function testSigning(tc: t.TestCase): Promise<void>;
|
|
5
|
+
import * as t from "./testing.js";
|
|
6
|
+
//# sourceMappingURL=crypto.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.test.d.ts","sourceRoot":"","sources":["crypto.test.js"],"names":[],"mappings":"AAQO,0CAFI,EAAE,QAAQ,iBA+BpB;AAKM,8CAFI,EAAE,QAAQ,iBAsCpB;AAKM,iDAFI,EAAE,QAAQ,iBA0CpB;AAKM,gCAFI,EAAE,QAAQ,iBAapB"}
|
|
@@ -12,7 +12,7 @@ var set = require('./set-b596ef38.cjs');
|
|
|
12
12
|
* Return the last element of an array. The element must exist
|
|
13
13
|
*
|
|
14
14
|
* @template L
|
|
15
|
-
* @param {
|
|
15
|
+
* @param {ArrayLike<L>} arr
|
|
16
16
|
* @return {L}
|
|
17
17
|
*/
|
|
18
18
|
const last = arr => arr[arr.length - 1];
|
|
@@ -58,29 +58,45 @@ const from = Array.from;
|
|
|
58
58
|
*
|
|
59
59
|
* @function
|
|
60
60
|
* @template ITEM
|
|
61
|
+
* @template {ArrayLike<ITEM>} ARR
|
|
61
62
|
*
|
|
62
|
-
* @param {
|
|
63
|
-
* @param {function(ITEM, number,
|
|
63
|
+
* @param {ARR} arr
|
|
64
|
+
* @param {function(ITEM, number, ARR):boolean} f
|
|
64
65
|
* @return {boolean}
|
|
65
66
|
*/
|
|
66
|
-
const every = (arr, f) =>
|
|
67
|
+
const every = (arr, f) => {
|
|
68
|
+
for (let i = 0; i < arr.length; i++) {
|
|
69
|
+
if (!f(arr[i], i, arr)) {
|
|
70
|
+
return false
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return true
|
|
74
|
+
};
|
|
67
75
|
|
|
68
76
|
/**
|
|
69
77
|
* True iff condition holds on some element in the Array.
|
|
70
78
|
*
|
|
71
79
|
* @function
|
|
72
80
|
* @template S
|
|
73
|
-
* @
|
|
74
|
-
* @param {
|
|
81
|
+
* @template {ArrayLike<S>} ARR
|
|
82
|
+
* @param {ARR} arr
|
|
83
|
+
* @param {function(S, number, ARR):boolean} f
|
|
75
84
|
* @return {boolean}
|
|
76
85
|
*/
|
|
77
|
-
const some = (arr, f) =>
|
|
86
|
+
const some = (arr, f) => {
|
|
87
|
+
for (let i = 0; i < arr.length; i++) {
|
|
88
|
+
if (f(arr[i], i, arr)) {
|
|
89
|
+
return true
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return false
|
|
93
|
+
};
|
|
78
94
|
|
|
79
95
|
/**
|
|
80
96
|
* @template ELEM
|
|
81
97
|
*
|
|
82
|
-
* @param {
|
|
83
|
-
* @param {
|
|
98
|
+
* @param {ArrayLike<ELEM>} a
|
|
99
|
+
* @param {ArrayLike<ELEM>} b
|
|
84
100
|
* @return {boolean}
|
|
85
101
|
*/
|
|
86
102
|
const equalFlat = (a, b) => a.length === b.length && every(a, (item, index) => item === b[index]);
|
|
@@ -104,7 +120,7 @@ const unique = arr => from(set.from(arr));
|
|
|
104
120
|
/**
|
|
105
121
|
* @template T
|
|
106
122
|
* @template M
|
|
107
|
-
* @param {
|
|
123
|
+
* @param {ArrayLike<T>} arr
|
|
108
124
|
* @param {function(T):M} mapper
|
|
109
125
|
* @return {Array<T>}
|
|
110
126
|
*/
|
|
@@ -157,4 +173,4 @@ exports.last = last;
|
|
|
157
173
|
exports.some = some;
|
|
158
174
|
exports.unique = unique;
|
|
159
175
|
exports.uniqueBy = uniqueBy;
|
|
160
|
-
//# sourceMappingURL=array-
|
|
176
|
+
//# sourceMappingURL=array-5347125b.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array-5347125b.cjs","sources":["../array.js"],"sourcesContent":["/**\n * Utility module to work with Arrays.\n *\n * @module array\n */\n\nimport * as set from './set.js'\n\n/**\n * Return the last element of an array. The element must exist\n *\n * @template L\n * @param {ArrayLike<L>} arr\n * @return {L}\n */\nexport const last = arr => arr[arr.length - 1]\n\n/**\n * @template C\n * @return {Array<C>}\n */\nexport const create = () => /** @type {Array<C>} */ ([])\n\n/**\n * @template D\n * @param {Array<D>} a\n * @return {Array<D>}\n */\nexport const copy = a => /** @type {Array<D>} */ (a.slice())\n\n/**\n * Append elements from src to dest\n *\n * @template M\n * @param {Array<M>} dest\n * @param {Array<M>} src\n */\nexport const appendTo = (dest, src) => {\n for (let i = 0; i < src.length; i++) {\n dest.push(src[i])\n }\n}\n\n/**\n * Transforms something array-like to an actual Array.\n *\n * @function\n * @template T\n * @param {ArrayLike<T>|Iterable<T>} arraylike\n * @return {T}\n */\nexport const from = Array.from\n\n/**\n * True iff condition holds on every element in the Array.\n *\n * @function\n * @template ITEM\n * @template {ArrayLike<ITEM>} ARR\n *\n * @param {ARR} arr\n * @param {function(ITEM, number, ARR):boolean} f\n * @return {boolean}\n */\nexport const every = (arr, f) => {\n for (let i = 0; i < arr.length; i++) {\n if (!f(arr[i], i, arr)) {\n return false\n }\n }\n return true\n}\n\n/**\n * True iff condition holds on some element in the Array.\n *\n * @function\n * @template S\n * @template {ArrayLike<S>} ARR\n * @param {ARR} arr\n * @param {function(S, number, ARR):boolean} f\n * @return {boolean}\n */\nexport const some = (arr, f) => {\n for (let i = 0; i < arr.length; i++) {\n if (f(arr[i], i, arr)) {\n return true\n }\n }\n return false\n}\n\n/**\n * @template ELEM\n *\n * @param {ArrayLike<ELEM>} a\n * @param {ArrayLike<ELEM>} b\n * @return {boolean}\n */\nexport const equalFlat = (a, b) => a.length === b.length && every(a, (item, index) => item === b[index])\n\n/**\n * @template ELEM\n * @param {Array<Array<ELEM>>} arr\n * @return {Array<ELEM>}\n */\nexport const flatten = arr => arr.reduce((acc, val) => acc.concat(val), [])\n\nexport const isArray = Array.isArray\n\n/**\n * @template T\n * @param {Array<T>} arr\n * @return {Array<T>}\n */\nexport const unique = arr => from(set.from(arr))\n\n/**\n * @template T\n * @template M\n * @param {ArrayLike<T>} arr\n * @param {function(T):M} mapper\n * @return {Array<T>}\n */\nexport const uniqueBy = (arr, mapper) => {\n /**\n * @type {Set<M>}\n */\n const happened = set.create()\n /**\n * @type {Array<T>}\n */\n const result = []\n for (let i = 0; i < arr.length; i++) {\n const el = arr[i]\n const mapped = mapper(el)\n if (!happened.has(mapped)) {\n happened.add(mapped)\n result.push(el)\n }\n }\n return result\n}\n"],"names":["set.from","set.create"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,IAAI,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,EAAC;AAC9C;AACA;AACA;AACA;AACA;AACY,MAAC,MAAM,GAAG,+BAA+B,EAAE,EAAC;AACxD;AACA;AACA;AACA;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package/dist/array.cjs
CHANGED
package/dist/array.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function last<L>(arr: L
|
|
1
|
+
export function last<L>(arr: ArrayLike<L>): L;
|
|
2
2
|
export function create<C>(): C[];
|
|
3
3
|
export function copy<D>(a: D[]): D[];
|
|
4
4
|
export function appendTo<M>(dest: M[], src: M[]): void;
|
|
@@ -16,11 +16,11 @@ export const from: {
|
|
|
16
16
|
<T_3>(iterable: Iterable<T_3> | ArrayLike<T_3>): T_3[];
|
|
17
17
|
<T_4, U_1>(iterable: Iterable<T_4> | ArrayLike<T_4>, mapfn: (v: T_4, k: number) => U_1, thisArg?: any): U_1[];
|
|
18
18
|
};
|
|
19
|
-
export function every<ITEM
|
|
20
|
-
export function some<S
|
|
21
|
-
export function equalFlat<ELEM>(a: ELEM
|
|
19
|
+
export function every<ITEM, ARR extends ArrayLike<ITEM>>(arr: ARR, f: (arg0: ITEM, arg1: number, arg2: ARR) => boolean): boolean;
|
|
20
|
+
export function some<S, ARR extends ArrayLike<S>>(arr: ARR, f: (arg0: S, arg1: number, arg2: ARR) => boolean): boolean;
|
|
21
|
+
export function equalFlat<ELEM>(a: ArrayLike<ELEM>, b: ArrayLike<ELEM>): boolean;
|
|
22
22
|
export function flatten<ELEM>(arr: ELEM[][]): ELEM[];
|
|
23
23
|
export const isArray: (arg: any) => arg is any[];
|
|
24
24
|
export function unique<T_1>(arr: T_1[]): T_1[];
|
|
25
|
-
export function uniqueBy<T_1, M>(arr: T_1
|
|
25
|
+
export function uniqueBy<T_1, M>(arr: ArrayLike<T_1>, mapper: (arg0: T_1) => M): T_1[];
|
|
26
26
|
//# sourceMappingURL=array.d.ts.map
|
package/dist/array.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../array.js"],"names":[],"mappings":"AAeO,
|
|
1
|
+
{"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../array.js"],"names":[],"mappings":"AAeO,8CAAuC;AAMvC,iCAAiD;AAOjD,qCAAqD;AASrD,uDAIN;AAED;;;;;;;GAOG;AACH;;;;;EAA8B;AAavB,yFAHmB,MAAM,gBAAO,OAAO,GAClC,OAAO,CASlB;AAYM,+EAHgB,MAAM,gBAAO,OAAO,GAC/B,OAAO,CASlB;AASM,yEAFK,OAAO,CAEqF;AAOjG,qDAAoE;AAE3E,iDAAoC;AAO7B,+CAAyC;AASzC,uFAkBN"}
|
package/dist/array.test.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export function testAppend(tc: t.TestCase): void;
|
|
2
2
|
export function testflatten(tc: t.TestCase): void;
|
|
3
|
+
export function testEvery(tc: t.TestCase): void;
|
|
3
4
|
export function testIsArray(tc: t.TestCase): void;
|
|
4
5
|
export function testUnique(tc: t.TestCase): void;
|
|
5
6
|
import * as t from "./testing.js";
|
package/dist/array.test.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array.test.d.ts","sourceRoot":"","sources":["../array.test.js"],"names":[],"mappings":"AAOO,+BAFI,EAAE,QAAQ,QAMpB;AAKM,gCAFI,EAAE,QAAQ,QAKpB;AAKM,gCAFI,EAAE,QAAQ,QASpB;AAKM,+BAFI,EAAE,QAAQ,QAOpB"}
|
|
1
|
+
{"version":3,"file":"array.test.d.ts","sourceRoot":"","sources":["../array.test.js"],"names":[],"mappings":"AAOO,+BAFI,EAAE,QAAQ,QAMpB;AAKM,gCAFI,EAAE,QAAQ,QAKpB;AAKM,8BAFI,EAAE,QAAQ,QAQpB;AAKM,gCAFI,EAAE,QAAQ,QASpB;AAKM,+BAFI,EAAE,QAAQ,QAOpB"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var map = require('./map-28a001c9.cjs');
|
|
4
4
|
var set = require('./set-b596ef38.cjs');
|
|
5
|
-
var encoding = require('./buffer-
|
|
5
|
+
var encoding = require('./buffer-884e5a1d.cjs');
|
|
6
6
|
var storage = require('./storage.cjs');
|
|
7
7
|
|
|
8
8
|
/* eslint-env browser */
|
|
@@ -117,4 +117,4 @@ exports.broadcastchannel = broadcastchannel;
|
|
|
117
117
|
exports.publish = publish;
|
|
118
118
|
exports.subscribe = subscribe;
|
|
119
119
|
exports.unsubscribe = unsubscribe;
|
|
120
|
-
//# sourceMappingURL=broadcastchannel-
|
|
120
|
+
//# sourceMappingURL=broadcastchannel-61da4e94.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"broadcastchannel-
|
|
1
|
+
{"version":3,"file":"broadcastchannel-61da4e94.cjs","sources":["../broadcastchannel.js"],"sourcesContent":["/* eslint-env browser */\n\n/**\n * Helpers for cross-tab communication using broadcastchannel with LocalStorage fallback.\n *\n * ```js\n * // In browser window A:\n * broadcastchannel.subscribe('my events', data => console.log(data))\n * broadcastchannel.publish('my events', 'Hello world!') // => A: 'Hello world!' fires synchronously in same tab\n *\n * // In browser window B:\n * broadcastchannel.publish('my events', 'hello from tab B') // => A: 'hello from tab B'\n * ```\n *\n * @module broadcastchannel\n */\n\n// @todo before next major: use Uint8Array instead as buffer object\n\nimport * as map from './map.js'\nimport * as set from './set.js'\nimport * as buffer from './buffer.js'\nimport * as storage from './storage.js'\n\n/**\n * @typedef {Object} Channel\n * @property {Set<function(any, any):any>} Channel.subs\n * @property {any} Channel.bc\n */\n\n/**\n * @type {Map<string, Channel>}\n */\nconst channels = new Map()\n\n/* istanbul ignore next */\nclass LocalStoragePolyfill {\n /**\n * @param {string} room\n */\n constructor (room) {\n this.room = room\n /**\n * @type {null|function({data:ArrayBuffer}):void}\n */\n this.onmessage = null\n storage.onChange(e => e.key === room && this.onmessage !== null && this.onmessage({ data: buffer.fromBase64(e.newValue || '') }))\n }\n\n /**\n * @param {ArrayBuffer} buf\n */\n postMessage (buf) {\n storage.varStorage.setItem(this.room, buffer.toBase64(buffer.createUint8ArrayFromArrayBuffer(buf)))\n }\n}\n\n/* istanbul ignore next */\n// Use BroadcastChannel or Polyfill\nconst BC = typeof BroadcastChannel === 'undefined' ? LocalStoragePolyfill : BroadcastChannel\n\n/**\n * @param {string} room\n * @return {Channel}\n */\nconst getChannel = room =>\n map.setIfUndefined(channels, room, () => {\n const subs = set.create()\n const bc = new BC(room)\n /* istanbul ignore next */\n /**\n * @param {{data:ArrayBuffer}} e\n */\n bc.onmessage = e => subs.forEach(sub => sub(e.data, 'broadcastchannel'))\n return {\n bc, subs\n }\n })\n\n/**\n * Subscribe to global `publish` events.\n *\n * @function\n * @param {string} room\n * @param {function(any, any):any} f\n */\nexport const subscribe = (room, f) => {\n getChannel(room).subs.add(f)\n return f\n}\n\n/**\n * Unsubscribe from `publish` global events.\n *\n * @function\n * @param {string} room\n * @param {function(any, any):any} f\n */\nexport const unsubscribe = (room, f) => {\n const channel = getChannel(room)\n const unsubscribed = channel.subs.delete(f)\n /* istanbul ignore else */\n if (unsubscribed && channel.subs.size === 0) {\n channel.bc.close()\n channels.delete(room)\n }\n return unsubscribed\n}\n\n/**\n * Publish data to all subscribers (including subscribers on this tab)\n *\n * @function\n * @param {string} room\n * @param {any} data\n * @param {any} [origin]\n */\nexport const publish = (room, data, origin = null) => {\n const c = getChannel(room)\n c.bc.postMessage(data)\n c.subs.forEach(sub => sub(data, origin))\n}\n"],"names":["storage.onChange","buffer.fromBase64","storage.varStorage","buffer.toBase64","buffer.createUint8ArrayFromArrayBuffer","map.setIfUndefined","set.create"],"mappings":";;;;;;;AAAA;AAuBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,QAAQ,GAAG,IAAI,GAAG,GAAE;AAC1B;AACA;AACA,MAAM,oBAAoB,CAAC;AAC3B;AACA;AACA;AACA,EAAE,WAAW,CAAC,CAAC,IAAI,EAAE;AACrB,IAAI,IAAI,CAAC,IAAI,GAAG,KAAI;AACpB;AACA;AACA;AACA,IAAI,IAAI,CAAC,SAAS,GAAG,KAAI;AACzB,IAAIA,gBAAgB,C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CAAC,IAAI,EAAE,CAAC,KAAK;AACxC,EAAE,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,EAAC;AAClC,EAAE,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAC;AAC7C;AACA,EAAE,IAAI,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,EAAE;AAC/C,IAAI,OAAO,CAAC,EAAE,CAAC,KAAK,GAAE;AACtB,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAC;AACzB,GAAG;AACH,EAAE,OAAO,YAAY;AACrB,EAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,OAAO,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,KAAK;AACtD,EAAE,MAAM,CAAC,GAAG,UAAU,CAAC,IAAI,EAAC;AAC5B,EAAE,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,EAAC;AACxB,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,EAAC;AAC1C;;;;;;;;;;;;;;"}
|
|
@@ -4,14 +4,14 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
require('./map-28a001c9.cjs');
|
|
6
6
|
require('./set-b596ef38.cjs');
|
|
7
|
-
require('./buffer-
|
|
7
|
+
require('./buffer-884e5a1d.cjs');
|
|
8
8
|
require('./storage.cjs');
|
|
9
|
-
var broadcastchannel = require('./broadcastchannel-
|
|
9
|
+
var broadcastchannel = require('./broadcastchannel-61da4e94.cjs');
|
|
10
10
|
require('./string-ad04f734.cjs');
|
|
11
|
-
require('./environment-
|
|
11
|
+
require('./environment-ad5e7386.cjs');
|
|
12
12
|
require('./conditions-fb475c70.cjs');
|
|
13
|
-
require('./function-
|
|
14
|
-
require('./array-
|
|
13
|
+
require('./function-3695121b.cjs');
|
|
14
|
+
require('./array-5347125b.cjs');
|
|
15
15
|
require('./object-fe9c0021.cjs');
|
|
16
16
|
require('./binary-ac8e39e2.cjs');
|
|
17
17
|
require('./math-08e068f9.cjs');
|