@tktb-tess/util-fns 0.13.0 → 0.13.1
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/dist/esm/async_worker.d.ts +2 -2
- package/dist/esm/async_worker.js +14 -14
- package/dist/esm/baillie_psw.js +165 -3
- package/dist/esm/{u8arr_ext.d.ts → base64.d.ts} +0 -2
- package/dist/esm/base64.js +13 -0
- package/dist/esm/bpsw_worker_wrap-DlBkGgip.js +20 -0
- package/dist/esm/bpsw_worker_wrap.d.ts +1 -1
- package/dist/esm/compression.d.ts +30 -0
- package/dist/esm/compression.js +17 -0
- package/dist/esm/equality.d.ts +13 -0
- package/dist/esm/equality.js +29 -0
- package/dist/esm/fixed_array.d.ts +9 -0
- package/dist/esm/fixed_array.js +7 -0
- package/dist/esm/fraction.d.ts +19 -16
- package/dist/esm/fraction.js +2 -2
- package/dist/esm/index.d.ts +5 -1
- package/dist/esm/index.js +16 -11
- package/dist/esm/leb128.d.ts +10 -0
- package/dist/esm/math.d.ts +4 -39
- package/dist/esm/math.js +17 -44
- package/dist/esm/mod_pow-S-7GJ74l.js +17 -0
- package/dist/esm/mod_pow.d.ts +15 -0
- package/dist/esm/named_error.d.ts +2 -1
- package/dist/esm/named_error.js +4 -3
- package/dist/esm/oct.d.ts +13 -0
- package/dist/esm/oct.js +24 -0
- package/dist/esm/random.d.ts +22 -0
- package/dist/esm/random.js +28 -12
- package/dist/esm/util.d.ts +12 -36
- package/dist/esm/util.js +11 -56
- package/dist/iife/bundle.min.js +1 -2
- package/package.json +25 -9
- package/dist/esm/baillie_psw-DzyqB4sZ.js +0 -164
- package/dist/esm/bpsw_worker-CZOWXQMI.js +0 -16
- package/dist/esm/u8arr_ext.js +0 -19
|
@@ -6,7 +6,7 @@ export interface WorkerMessage<T> {
|
|
|
6
6
|
readonly value: T;
|
|
7
7
|
readonly id: ID;
|
|
8
8
|
}
|
|
9
|
-
export declare class AsyncWorker<TPost = unknown, TRecv = unknown
|
|
9
|
+
export declare class AsyncWorker<TPost = unknown, TRecv = unknown> {
|
|
10
10
|
#private;
|
|
11
11
|
static readonly name = "AsyncWorker";
|
|
12
12
|
constructor(w: Worker);
|
|
@@ -18,5 +18,5 @@ export declare class AsyncWorker<TPost = unknown, TRecv = unknown, TErr = unknow
|
|
|
18
18
|
readonly postMessage: (message: TPost, options?: StructuredSerializeOptions) => Promise<TRecv>;
|
|
19
19
|
}
|
|
20
20
|
export declare const postSuccess: <TRecv>(value: TRecv, id: ID) => void;
|
|
21
|
-
export declare const postFailed:
|
|
21
|
+
export declare const postFailed: (error: unknown, id: ID) => void;
|
|
22
22
|
export {};
|
package/dist/esm/async_worker.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
//#region lib/async_worker.ts
|
|
2
|
-
var e = "AsyncWorker", t =
|
|
2
|
+
var e = "AsyncWorker", t = 2n ** 128n, n = 0n, r = () => (n === t && (n = 0n), n++), i = class {
|
|
3
3
|
static name = e;
|
|
4
4
|
#e;
|
|
5
5
|
constructor(e) {
|
|
6
6
|
this.#e = e;
|
|
7
7
|
}
|
|
8
|
-
postMessage = (e, t) => new Promise((
|
|
9
|
-
let a =
|
|
8
|
+
postMessage = (e, t) => new Promise((n, i) => {
|
|
9
|
+
let a = r(), o = new AbortController(), { signal: s } = o;
|
|
10
|
+
this.#e.addEventListener("message", (e) => {
|
|
10
11
|
let t = e.data;
|
|
11
|
-
t.id === a && (
|
|
12
|
-
}, s
|
|
13
|
-
|
|
14
|
-
};
|
|
15
|
-
this.#e.addEventListener("message", o), this.#e.addEventListener("error", s);
|
|
12
|
+
t.id === a && (o.abort(), t.success ? n(t.value) : i(t.error));
|
|
13
|
+
}, { signal: s }), this.#e.addEventListener("error", (e) => {
|
|
14
|
+
o.abort(), i(e.error);
|
|
15
|
+
}, { signal: s });
|
|
16
16
|
let c = {
|
|
17
17
|
value: e,
|
|
18
18
|
id: a
|
|
@@ -20,20 +20,20 @@ var e = "AsyncWorker", t = 0n, n = () => (t === 2n ** 128n && (t = 0n), t++), r
|
|
|
20
20
|
this.#e.postMessage(c, t);
|
|
21
21
|
});
|
|
22
22
|
};
|
|
23
|
-
Object.defineProperty(
|
|
23
|
+
Object.defineProperty(i.prototype, Symbol.toStringTag, {
|
|
24
24
|
value: e,
|
|
25
25
|
enumerable: !0
|
|
26
26
|
});
|
|
27
|
-
var
|
|
28
|
-
if (!
|
|
27
|
+
var a = () => typeof window > "u" && typeof self < "u" && "importScripts" in self, o = (e, t) => {
|
|
28
|
+
if (!a()) throw Error("this function must be used in Worker");
|
|
29
29
|
let n = {
|
|
30
30
|
success: !0,
|
|
31
31
|
value: e,
|
|
32
32
|
id: t
|
|
33
33
|
};
|
|
34
34
|
self.postMessage(n);
|
|
35
|
-
},
|
|
36
|
-
if (!
|
|
35
|
+
}, s = (e, t) => {
|
|
36
|
+
if (!a()) throw Error("this function must be used in Worker");
|
|
37
37
|
let n = {
|
|
38
38
|
success: !1,
|
|
39
39
|
error: e,
|
|
@@ -42,4 +42,4 @@ var i = () => typeof window > "u" && typeof self < "u" && "importScripts" in sel
|
|
|
42
42
|
self.postMessage(n);
|
|
43
43
|
};
|
|
44
44
|
//#endregion
|
|
45
|
-
export {
|
|
45
|
+
export { i as AsyncWorker, s as postFailed, o as postSuccess };
|
package/dist/esm/baillie_psw.js
CHANGED
|
@@ -1,3 +1,165 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { n as e, t } from "./mod_pow-S-7GJ74l.js";
|
|
2
|
+
import { isSquare as n, jacobiSymbol as r } from "./math.js";
|
|
3
|
+
import { getRandBIByBitLength as i, getRandBIByRange as a } from "./random.js";
|
|
4
|
+
//#region lib/baillie_psw.ts
|
|
5
|
+
var o = [
|
|
6
|
+
2n,
|
|
7
|
+
3n,
|
|
8
|
+
5n,
|
|
9
|
+
7n,
|
|
10
|
+
11n,
|
|
11
|
+
13n,
|
|
12
|
+
17n,
|
|
13
|
+
19n,
|
|
14
|
+
23n,
|
|
15
|
+
29n,
|
|
16
|
+
31n,
|
|
17
|
+
37n,
|
|
18
|
+
41n,
|
|
19
|
+
43n,
|
|
20
|
+
47n,
|
|
21
|
+
53n,
|
|
22
|
+
59n,
|
|
23
|
+
61n,
|
|
24
|
+
67n,
|
|
25
|
+
71n,
|
|
26
|
+
73n,
|
|
27
|
+
79n,
|
|
28
|
+
83n,
|
|
29
|
+
89n,
|
|
30
|
+
97n,
|
|
31
|
+
101n,
|
|
32
|
+
103n,
|
|
33
|
+
107n,
|
|
34
|
+
109n,
|
|
35
|
+
113n,
|
|
36
|
+
127n,
|
|
37
|
+
131n,
|
|
38
|
+
137n,
|
|
39
|
+
139n,
|
|
40
|
+
149n,
|
|
41
|
+
151n,
|
|
42
|
+
157n,
|
|
43
|
+
163n,
|
|
44
|
+
167n,
|
|
45
|
+
173n,
|
|
46
|
+
179n,
|
|
47
|
+
181n,
|
|
48
|
+
191n,
|
|
49
|
+
193n,
|
|
50
|
+
197n,
|
|
51
|
+
199n,
|
|
52
|
+
211n,
|
|
53
|
+
223n,
|
|
54
|
+
227n,
|
|
55
|
+
229n,
|
|
56
|
+
233n,
|
|
57
|
+
239n,
|
|
58
|
+
241n,
|
|
59
|
+
251n,
|
|
60
|
+
257n,
|
|
61
|
+
263n,
|
|
62
|
+
269n,
|
|
63
|
+
271n,
|
|
64
|
+
277n,
|
|
65
|
+
281n,
|
|
66
|
+
283n,
|
|
67
|
+
293n,
|
|
68
|
+
307n,
|
|
69
|
+
311n,
|
|
70
|
+
313n,
|
|
71
|
+
317n,
|
|
72
|
+
331n,
|
|
73
|
+
337n,
|
|
74
|
+
347n,
|
|
75
|
+
349n,
|
|
76
|
+
353n,
|
|
77
|
+
359n,
|
|
78
|
+
367n,
|
|
79
|
+
373n,
|
|
80
|
+
379n,
|
|
81
|
+
383n,
|
|
82
|
+
389n,
|
|
83
|
+
397n,
|
|
84
|
+
401n,
|
|
85
|
+
409n,
|
|
86
|
+
419n,
|
|
87
|
+
421n,
|
|
88
|
+
431n,
|
|
89
|
+
433n,
|
|
90
|
+
439n,
|
|
91
|
+
443n,
|
|
92
|
+
449n,
|
|
93
|
+
457n,
|
|
94
|
+
461n,
|
|
95
|
+
463n,
|
|
96
|
+
467n,
|
|
97
|
+
479n,
|
|
98
|
+
487n,
|
|
99
|
+
491n,
|
|
100
|
+
499n
|
|
101
|
+
], s = (e) => {
|
|
102
|
+
if (e <= 1n) return !1;
|
|
103
|
+
if (e % 2n == 0n) return e === 2n;
|
|
104
|
+
let n = e - 1n, r = 0n;
|
|
105
|
+
for (; n % 2n == 0n;) n >>= 1n, r += 1n;
|
|
106
|
+
let [i, a] = [n, r], o = t(2n, i, e);
|
|
107
|
+
if (o === 1n) return !0;
|
|
108
|
+
for (let t = 0n; t < a; t++) {
|
|
109
|
+
if (o === e - 1n) return !0;
|
|
110
|
+
o = o * o % e;
|
|
111
|
+
}
|
|
112
|
+
return !1;
|
|
113
|
+
}, c = (e) => {
|
|
114
|
+
let t = 5n;
|
|
115
|
+
for (;;) {
|
|
116
|
+
let i = r(t, e);
|
|
117
|
+
if (i === -1n) return t;
|
|
118
|
+
if (i === 0n || (t = t > 0n ? -(t + 2n) : -(t - 2n), t === -15n && n(e))) return null;
|
|
119
|
+
}
|
|
120
|
+
}, l = (t, n) => {
|
|
121
|
+
if ((n & 1n) == 0n) throw Error("`n` is not odd");
|
|
122
|
+
return (t & 1n) == 1n ? e(t + n >> 1n, n) : e(t >> 1n, n);
|
|
123
|
+
}, u = (t, n, r, i) => {
|
|
124
|
+
let a = 1n, o = r, s = t.toString(2).slice(1);
|
|
125
|
+
for (let t of s) [a, o] = [e(a * o, n), l(o * o + i * a * a, n)], t === "1" && ([a, o] = [l(r * a + o, n), l(i * a + r * o, n)]);
|
|
126
|
+
return [a, o];
|
|
127
|
+
}, d = (n, r, i, a) => {
|
|
128
|
+
if (n % 2n != 1n) throw RangeError("`n` must be odd");
|
|
129
|
+
let o = n + 1n, s = 0n;
|
|
130
|
+
for (; o % 2n == 0n;) o >>= 1n, s += 1n;
|
|
131
|
+
let [c, l] = u(o, n, i, r), d = l;
|
|
132
|
+
if (c === 0n) return !0;
|
|
133
|
+
a = t(a, o, n);
|
|
134
|
+
for (let r = 0n; r < s; r++) {
|
|
135
|
+
if (d === 0n) return !0;
|
|
136
|
+
d = e(d * d - 2n * a, n), a = t(a, 2n, n);
|
|
137
|
+
}
|
|
138
|
+
return !1;
|
|
139
|
+
}, f = (e) => {
|
|
140
|
+
if (e <= 1n) return !1;
|
|
141
|
+
if (e % 2n == 0n) return e === 2n;
|
|
142
|
+
for (let t of o) if (e % t === 0n) return e === t;
|
|
143
|
+
if (!s(e)) return !1;
|
|
144
|
+
let t = c(e);
|
|
145
|
+
return t == null ? !1 : d(e, t, 1n, (1n - t) / 4n);
|
|
146
|
+
}, p = (e, t) => {
|
|
147
|
+
if (t < 2n) throw RangeError("`max` must be 2 or larger");
|
|
148
|
+
for (let n = 0; n < 1e5; n++) {
|
|
149
|
+
let n = a(e, t);
|
|
150
|
+
if (f(n)) return n;
|
|
151
|
+
}
|
|
152
|
+
throw Error("no primes were found");
|
|
153
|
+
}, m = (e, t = !1) => {
|
|
154
|
+
if (e < 2) throw RangeError("`bitLength` must be 2 or larger");
|
|
155
|
+
for (let n = 0; n < 1e5; n++) {
|
|
156
|
+
let n = i(e, t);
|
|
157
|
+
if (f(n)) return n;
|
|
158
|
+
}
|
|
159
|
+
throw Error("no primes were found");
|
|
160
|
+
}, h = async (e) => {
|
|
161
|
+
let { getWorker: t } = await import("./bpsw_worker_wrap-DlBkGgip.js");
|
|
162
|
+
return (await t()).postMessage(e);
|
|
163
|
+
};
|
|
164
|
+
//#endregion
|
|
165
|
+
export { f as bailliePSW, h as bailliePSWAsync, m as getRandPrimeByBitLength, p as getRandPrimeByRange };
|
|
@@ -2,5 +2,3 @@ export declare const toBase64: (bin: Uint8Array) => string;
|
|
|
2
2
|
export declare const fromBase64: (base64: string) => Uint8Array<ArrayBuffer>;
|
|
3
3
|
export declare const toBase64URL: (bin: Uint8Array) => string;
|
|
4
4
|
export declare const fromBase64URL: (base64URL: string) => Uint8Array<ArrayBuffer>;
|
|
5
|
-
export declare const toOct: (bin: Uint8Array) => string;
|
|
6
|
-
export declare const fromOct: (oct: string) => Uint8Array<ArrayBuffer>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region lib/base64.ts
|
|
2
|
+
var e = (e) => {
|
|
3
|
+
let t = Array.from(e, (e) => String.fromCharCode(e));
|
|
4
|
+
return btoa(t.join(""));
|
|
5
|
+
}, t = (e) => {
|
|
6
|
+
let t = atob(e);
|
|
7
|
+
return Uint8Array.from(t, (e) => e.charCodeAt(0));
|
|
8
|
+
}, n = (t) => e(t).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, ""), r = (e) => {
|
|
9
|
+
let n = 4 - (e.length & 3) & 3;
|
|
10
|
+
return t(e.concat("=".repeat(n)).replaceAll("-", "+").replaceAll("_", "/"));
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { t as fromBase64, r as fromBase64URL, e as toBase64, n as toBase64URL };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AsyncWorker as e } from "./async_worker.js";
|
|
2
|
+
//#region lib/bpsw_worker.ts?worker&inline
|
|
3
|
+
var t = "(function(){var e=(e,t)=>()=>(e&&(t=e(e=0)),t);let t=(e,t)=>{t<0n&&(t*=-1n);let n=e%t;return n<0n?n+t:n},n=(e,n,r)=>{if(r<1n)throw RangeError(\"`mod` must be positive\");if(n<0n)throw RangeError(\"`power` must not be negative\");if(e=t(e,r),r===1n)return 0n;if(e%r===1n||e%r===0n)return e;if(e===r-1n)return n&1n?r-1n:1n;let i=1n;for(;n>0n;)n&1n&&(i=i*e%r),e=e*e%r,n>>=1n;return i},r=(e,t)=>{if(t<1n||t%2n==0n)throw RangeError(\"`n` is out of range\");for(;e<0n;)e+=t;e%=t;let n=1n;for(;e!==0n;){for(;e%2n==0n;){e/=2n;let r=t%8n;(r===3n||r===5n)&&(n*=-1n)}[e,t]=[t,e],e%4n==3n&&t%4n==3n&&(n*=-1n),e%=t}return t===1n?n:0n},i=e=>{if(e<0n)return!1;if(e===0n)return!0;let t=1n,n=e;for(;t+1n<n;){let r=(t+n)/2n;r*r<e?t=r:n=r}return e===t**2n||e===(t+1n)**2n};var a,o,s,c,l,u,d,f,p=e((()=>{a=`AsyncWorker`,o=2n**128n,s=0n,c=()=>(s===o&&(s=0n),s++),l=class{static name=a;#e;constructor(e){this.#e=e}postMessage=(e,t)=>new Promise((n,r)=>{let i=c(),a=new AbortController,{signal:o}=a;this.#e.addEventListener(`message`,e=>{let t=e.data;t.id===i&&(a.abort(),t.success?n(t.value):r(t.error))},{signal:o}),this.#e.addEventListener(`error`,e=>{a.abort(),r(e.error)},{signal:o});let s={value:e,id:i};this.#e.postMessage(s,t)})},Object.defineProperty(l.prototype,Symbol.toStringTag,{value:a,enumerable:!0}),u=()=>typeof window>`u`&&typeof self<`u`&&`importScripts`in self,d=(e,t)=>{if(!u())throw Error(`this function must be used in Worker`);let n={success:!0,value:e,id:t};self.postMessage(n)},f=(e,t)=>{if(!u())throw Error(`this function must be used in Worker`);let n={success:!1,error:e,id:t};self.postMessage(n)}}));let m=[2n,3n,5n,7n,11n,13n,17n,19n,23n,29n,31n,37n,41n,43n,47n,53n,59n,61n,67n,71n,73n,79n,83n,89n,97n,101n,103n,107n,109n,113n,127n,131n,137n,139n,149n,151n,157n,163n,167n,173n,179n,181n,191n,193n,197n,199n,211n,223n,227n,229n,233n,239n,241n,251n,257n,263n,269n,271n,277n,281n,283n,293n,307n,311n,313n,317n,331n,337n,347n,349n,353n,359n,367n,373n,379n,383n,389n,397n,401n,409n,419n,421n,431n,433n,439n,443n,449n,457n,461n,463n,467n,479n,487n,491n,499n],h=e=>{if(e<=1n)return!1;if(e%2n==0n)return e===2n;let t=e-1n,r=0n;for(;t%2n==0n;)t>>=1n,r+=1n;let[i,a]=[t,r],o=n(2n,i,e);if(o===1n)return!0;for(let t=0n;t<a;t++){if(o===e-1n)return!0;o=o*o%e}return!1},g=e=>{let t=5n;for(;;){let n=r(t,e);if(n===-1n)return t;if(n===0n||(t=t>0n?-(t+2n):-(t-2n),t===-15n&&i(e)))return null}},_=(e,n)=>{if((n&1n)==0n)throw Error(\"`n` is not odd\");return(e&1n)==1n?t(e+n>>1n,n):t(e>>1n,n)},v=(e,n,r,i)=>{let a=1n,o=r,s=e.toString(2).slice(1);for(let e of s)[a,o]=[t(a*o,n),_(o*o+i*a*a,n)],e===`1`&&([a,o]=[_(r*a+o,n),_(i*a+r*o,n)]);return[a,o]},y=(e,r,i,a)=>{if(e%2n!=1n)throw RangeError(\"`n` must be odd\");let o=e+1n,s=0n;for(;o%2n==0n;)o>>=1n,s+=1n;let[c,l]=v(o,e,i,r),u=l;if(c===0n)return!0;a=n(a,o,e);for(let r=0n;r<s;r++){if(u===0n)return!0;u=t(u*u-2n*a,e),a=n(a,2n,e)}return!1},b=e=>{if(e<=1n)return!1;if(e%2n==0n)return e===2n;for(let t of m)if(e%t===0n)return e===t;if(!h(e))return!1;let t=g(e);return t==null?!1:y(e,t,1n,(1n-t)/4n)};p();let x=e=>{if(e==null)return;let t=`${e}`;return t===`[object Object]`?JSON.stringify(e):t};globalThis.onmessage=e=>{let{value:t,id:n}=e.data;try{d(b(t),n)}catch(e){if(e instanceof Error){let{name:t,message:r,stack:i,cause:a}=e;f({name:t,message:r,stack:i,cause:x(a)},n)}else f({name:`BPSWError`,message:`unidentified error`,cause:x(e)},n)}}})();", n = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", t], { type: "text/javascript;charset=utf-8" });
|
|
4
|
+
function r(e) {
|
|
5
|
+
let r;
|
|
6
|
+
try {
|
|
7
|
+
if (r = n && (self.URL || self.webkitURL).createObjectURL(n), !r) throw "";
|
|
8
|
+
let t = new Worker(r, { name: e?.name });
|
|
9
|
+
return t.addEventListener("error", () => {
|
|
10
|
+
(self.URL || self.webkitURL).revokeObjectURL(r);
|
|
11
|
+
}), t;
|
|
12
|
+
} catch {
|
|
13
|
+
return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(t), { name: e?.name });
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region lib/bpsw_worker_wrap.ts
|
|
18
|
+
var i, a = async () => (i ||= new e(new r({ name: "bpsw_worker" })), i);
|
|
19
|
+
//#endregion
|
|
20
|
+
export { a as getWorker };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { AsyncWorker } from './async_worker';
|
|
2
|
-
export declare const getWorker: () => Promise<AsyncWorker<bigint, boolean
|
|
2
|
+
export declare const getWorker: () => Promise<AsyncWorker<bigint, boolean>>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compress binary data
|
|
3
|
+
* @param raw
|
|
4
|
+
* @param format
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export declare const compress: (raw: Uint8Array<ArrayBuffer>, format: CompressionFormat) => Promise<Uint8Array<ArrayBuffer>>;
|
|
8
|
+
/**
|
|
9
|
+
* Decompress binary data
|
|
10
|
+
* @param compressed
|
|
11
|
+
* @param format
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
export declare const decompress: (compressed: Uint8Array<ArrayBuffer>, format: CompressionFormat) => Promise<Uint8Array<ArrayBuffer>>;
|
|
15
|
+
/**
|
|
16
|
+
* Compress string into Base64(URL)-encoded string
|
|
17
|
+
* @param str
|
|
18
|
+
* @param format
|
|
19
|
+
* @param encoding default: `base64url`
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
export declare const compressString: (str: string, format: CompressionFormat, encoding?: "base64" | "base64url") => Promise<string>;
|
|
23
|
+
/**
|
|
24
|
+
* Decompress Base64(URL)-encoded data
|
|
25
|
+
* @param compressedString
|
|
26
|
+
* @param format
|
|
27
|
+
* @param encoding default: `base64url`
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
export declare const decompressString: (compressedString: string, format: CompressionFormat, encoding?: "base64" | "base64url") => Promise<string>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { fromBase64 as e, fromBase64URL as t, toBase64 as n, toBase64URL as r } from "./base64.js";
|
|
2
|
+
//#region lib/compression.ts
|
|
3
|
+
var i = (e, t) => {
|
|
4
|
+
let n = new Blob([e]).stream().pipeThrough(new CompressionStream(t));
|
|
5
|
+
return new Response(n).bytes();
|
|
6
|
+
}, a = (e, t) => {
|
|
7
|
+
let n = new Blob([e]).stream().pipeThrough(new DecompressionStream(t));
|
|
8
|
+
return new Response(n).bytes();
|
|
9
|
+
}, o = async (e, t, i = "base64url") => {
|
|
10
|
+
let a = new Blob([e]).stream().pipeThrough(new CompressionStream(t)), o = await new Response(a).bytes();
|
|
11
|
+
return i === "base64" ? n(o) : r(o);
|
|
12
|
+
}, s = (n, r, i = "base64url") => {
|
|
13
|
+
let a = i === "base64" ? e(n) : t(n), o = new Blob([a]).stream().pipeThrough(new DecompressionStream(r));
|
|
14
|
+
return new Response(o).text();
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
export { i as compress, o as compressString, a as decompress, s as decompressString };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compare two objects with SameValueZero method
|
|
3
|
+
* @param a
|
|
4
|
+
* @param b
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export declare const sameValueZero: (a: unknown, b: unknown) => boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Judges whether two objects has the same (nested) properties \
|
|
10
|
+
* Compares with SameValueZero, ignores symbol keys in an object
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export declare const isDeepStrictEqual: (a: unknown, b: unknown) => boolean;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region lib/equality.ts
|
|
2
|
+
var e = (e, t) => [e].includes(t), t = (e, n) => {
|
|
3
|
+
if (typeof e != typeof n) return !1;
|
|
4
|
+
let r = Object.prototype.toString.call(e);
|
|
5
|
+
if (r !== Object.prototype.toString.call(n)) return !1;
|
|
6
|
+
if (typeof e == "string" || typeof e == "bigint" || typeof e == "boolean" || typeof e == "symbol" || e == null) return e === n;
|
|
7
|
+
if (typeof e == "number") return e === n || e !== e && n !== n;
|
|
8
|
+
if (typeof e == "function") return !1;
|
|
9
|
+
if (Array.isArray(e) && Array.isArray(n)) {
|
|
10
|
+
if (e.length !== n.length) return !1;
|
|
11
|
+
for (let r = 0; r < e.length; r++) if (!t(e[r], n[r])) return !1;
|
|
12
|
+
return !0;
|
|
13
|
+
}
|
|
14
|
+
if (e instanceof Set && n instanceof Set) return !!t([...e.values()], [...n.values()]);
|
|
15
|
+
if (e instanceof Map && n instanceof Map) return !(!t([...e.keys()], [...n.keys()]) || !t([...e.values()], [...n.values()]));
|
|
16
|
+
if (r === "[object Object]") {
|
|
17
|
+
let r = e, i = n, a = Object.keys(r), o = Object.keys(i);
|
|
18
|
+
for (let e of a) {
|
|
19
|
+
let n = o.find((t) => t === e);
|
|
20
|
+
if (n == null) return !1;
|
|
21
|
+
let [a, s] = [r[e], i[n]];
|
|
22
|
+
if (!t(a, s)) return !1;
|
|
23
|
+
}
|
|
24
|
+
return !0;
|
|
25
|
+
}
|
|
26
|
+
throw TypeError(`comparing these objects is unavailable: ${e}, ${n}`, { cause: [e, n] });
|
|
27
|
+
};
|
|
28
|
+
//#endregion
|
|
29
|
+
export { t as isDeepStrictEqual, e as sameValueZero };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface FixedUint8Array<B extends ArrayBufferLike, N extends number> extends Uint8Array<B> {
|
|
2
|
+
readonly length: N;
|
|
3
|
+
readonly byteLength: N;
|
|
4
|
+
}
|
|
5
|
+
declare const FixedUint8Array: {
|
|
6
|
+
new: <N extends number>(length: N) => FixedUint8Array<ArrayBuffer, N>;
|
|
7
|
+
fromBuffer: <B extends ArrayBufferLike, N extends number>(buffer: B, byteOffset: number, length: N) => FixedUint8Array<B, N>;
|
|
8
|
+
};
|
|
9
|
+
export { FixedUint8Array };
|
package/dist/esm/fraction.d.ts
CHANGED
|
@@ -3,64 +3,67 @@ export interface RationalData {
|
|
|
3
3
|
/** `[numerator, denominator]` */
|
|
4
4
|
value: [string, string];
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* Fraction (rational) class
|
|
8
|
+
*/
|
|
6
9
|
export declare class Rational {
|
|
7
10
|
#private;
|
|
8
11
|
static readonly name = "Rational";
|
|
9
12
|
/**
|
|
10
|
-
*
|
|
13
|
+
*
|
|
11
14
|
* @param numerator
|
|
12
15
|
* @param denominator
|
|
13
16
|
*/
|
|
14
17
|
constructor(numerator: bigint, denominator: bigint);
|
|
15
18
|
/**
|
|
16
|
-
*
|
|
19
|
+
* Generates fraction from `number` decimal using continued fraction
|
|
17
20
|
* @param value decimal
|
|
18
21
|
* @param denominatorDigits limit of digits of denominator
|
|
19
22
|
*/
|
|
20
23
|
static fromDecimal(value: number, denominatorDigits?: number): Rational;
|
|
21
24
|
/**
|
|
22
|
-
*
|
|
23
|
-
* @returns
|
|
25
|
+
*
|
|
26
|
+
* @returns A fraction multiplied by -1
|
|
24
27
|
*/
|
|
25
28
|
readonly minus: () => Rational;
|
|
26
29
|
/**
|
|
27
|
-
*
|
|
28
|
-
* @returns
|
|
30
|
+
*
|
|
31
|
+
* @returns Inverse of this fraction
|
|
29
32
|
*/
|
|
30
33
|
readonly inverse: () => Rational;
|
|
31
34
|
/**
|
|
32
|
-
*
|
|
35
|
+
*
|
|
33
36
|
* @param right
|
|
34
|
-
* @returns
|
|
37
|
+
* @returns `this + right`
|
|
35
38
|
*/
|
|
36
39
|
readonly add: (right: Rational) => Rational;
|
|
37
40
|
/**
|
|
38
|
-
*
|
|
41
|
+
*
|
|
39
42
|
* @param right
|
|
40
|
-
* @returns
|
|
43
|
+
* @returns `this - right`
|
|
41
44
|
*/
|
|
42
45
|
readonly substr: (right: Rational) => Rational;
|
|
43
46
|
/**
|
|
44
|
-
*
|
|
47
|
+
*
|
|
45
48
|
* @param right
|
|
46
|
-
* @returns
|
|
49
|
+
* @returns `this * right`
|
|
47
50
|
*/
|
|
48
51
|
readonly multiply: (right: Rational) => Rational;
|
|
49
52
|
/**
|
|
50
|
-
*
|
|
53
|
+
*
|
|
51
54
|
* @param right
|
|
52
|
-
* @returns
|
|
55
|
+
* @returns `this / right`
|
|
53
56
|
*/
|
|
54
57
|
readonly divide: (right: Rational) => Rational;
|
|
55
58
|
/**
|
|
56
|
-
*
|
|
59
|
+
* Returns mediant
|
|
57
60
|
* @param this `a / b`
|
|
58
61
|
* @param right `c / d`
|
|
59
62
|
* @returns `(a + c) / (b + d)`
|
|
60
63
|
*/
|
|
61
64
|
readonly mediant: (right: Rational) => Rational;
|
|
62
65
|
/**
|
|
63
|
-
*
|
|
66
|
+
* Returns `number` type decimal
|
|
64
67
|
* @returns decimal
|
|
65
68
|
*/
|
|
66
69
|
readonly toDecimal: () => number;
|
package/dist/esm/fraction.js
CHANGED
|
@@ -23,10 +23,10 @@ var t = "Rational", n = class n {
|
|
|
23
23
|
}
|
|
24
24
|
return new n(r ? -o : o, c);
|
|
25
25
|
}
|
|
26
|
-
#n() {
|
|
26
|
+
#n = () => {
|
|
27
27
|
let { gcd: t } = e(this.#e, this.#t);
|
|
28
28
|
t !== 0n && (this.#e /= t, this.#t /= t);
|
|
29
|
-
}
|
|
29
|
+
};
|
|
30
30
|
minus = () => new n(-this.#e, this.#t);
|
|
31
31
|
inverse = () => new n(this.#t, this.#e);
|
|
32
32
|
add = (e) => {
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
export * from './util';
|
|
2
2
|
export * from './math';
|
|
3
3
|
export * from './baillie_psw';
|
|
4
|
+
export * from './base64';
|
|
5
|
+
export * from './compression';
|
|
6
|
+
export * from './equality';
|
|
4
7
|
export * from './fraction';
|
|
5
|
-
export * from './
|
|
8
|
+
export * from './fixed_array';
|
|
6
9
|
export * from './named_error';
|
|
10
|
+
export * from './oct';
|
|
7
11
|
export * from './random';
|
|
8
12
|
export * from './pcg_minimal';
|
|
9
13
|
export * from './xoshiro_minimal';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { AsyncWorker as e, postFailed as t, postSuccess as n } from "./async_worker.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
2
|
+
import { n as r, t as i } from "./mod_pow-S-7GJ74l.js";
|
|
3
|
+
import { exEuclidean as a, factorial as o, isSquare as s, jacobiSymbol as c, rot32 as l, rot64 as u } from "./math.js";
|
|
4
|
+
import { floatRng as d, getRandBIByBitLength as f, getRandBIByRange as p, getRndInt as m } from "./random.js";
|
|
5
|
+
import { bailliePSW as h, bailliePSWAsync as g, getRandPrimeByBitLength as _, getRandPrimeByRange as v } from "./baillie_psw.js";
|
|
6
|
+
import { fromBase64 as y, fromBase64URL as b, toBase64 as x, toBase64URL as S } from "./base64.js";
|
|
7
|
+
import { compress as C, compressString as w, decompress as T, decompressString as E } from "./compression.js";
|
|
8
|
+
import { isDeepStrictEqual as D, sameValueZero as O } from "./equality.js";
|
|
9
|
+
import { Rational as k } from "./fraction.js";
|
|
10
|
+
import { FixedUint8Array as A } from "./fixed_array.js";
|
|
11
|
+
import { decodeLEB128 as j, encodeLEB128 as M } from "./leb128.js";
|
|
12
|
+
import { NamedError as N } from "./named_error.js";
|
|
13
|
+
import { fromOct as P, toOct as F } from "./oct.js";
|
|
14
|
+
import { PCGMinimal as I } from "./pcg_minimal.js";
|
|
15
|
+
import { decodeRFC3986URIComponent as L, encodeRFC3986URIComponent as R, getHash as z, getStringTag as B, lazify as V, nullableStrictAt as H, setTimeoutPromise as U, sleepSort as W, strictAt as G, withResolvers as K } from "./util.js";
|
|
16
|
+
import { XoshiroMinimal as q } from "./xoshiro_minimal.js";
|
|
17
|
+
export { e as AsyncWorker, A as FixedUint8Array, N as NamedError, I as PCGMinimal, k as Rational, q as XoshiroMinimal, h as bailliePSW, g as bailliePSWAsync, C as compress, w as compressString, j as decodeLEB128, L as decodeRFC3986URIComponent, T as decompress, E as decompressString, M as encodeLEB128, R as encodeRFC3986URIComponent, a as exEuclidean, o as factorial, d as floatRng, y as fromBase64, b as fromBase64URL, P as fromOct, z as getHash, f as getRandBIByBitLength, p as getRandBIByRange, _ as getRandPrimeByBitLength, v as getRandPrimeByRange, m as getRndInt, B as getStringTag, D as isDeepStrictEqual, s as isSquare, c as jacobiSymbol, V as lazify, i as modPow, H as nullableStrictAt, t as postFailed, n as postSuccess, r as residue, l as rot32, u as rot64, O as sameValueZero, U as setTimeoutPromise, W as sleepSort, G as strictAt, x as toBase64, S as toBase64URL, F as toOct, K as withResolvers };
|
package/dist/esm/leb128.d.ts
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Encode bigint to LEB128
|
|
3
|
+
* @param bigint
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
1
6
|
export declare const encodeLEB128: (bigint: bigint) => Uint8Array<ArrayBuffer>;
|
|
7
|
+
/**
|
|
8
|
+
* Decode LEB128 into bigint
|
|
9
|
+
* @param LEB128
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
2
12
|
export declare const decodeLEB128: (LEB128: Uint8Array<ArrayBuffer>) => bigint;
|
package/dist/esm/math.d.ts
CHANGED
|
@@ -1,41 +1,6 @@
|
|
|
1
|
+
export { residue, modPow } from './mod_pow';
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @param min
|
|
4
|
-
* @param max
|
|
5
|
-
* @returns 範囲内の整数乱数
|
|
6
|
-
*/
|
|
7
|
-
export declare const getRndInt: (min: number, max: number) => number;
|
|
8
|
-
/**
|
|
9
|
-
* residue, but always a positive residue even `n` is negative
|
|
10
|
-
* @param n
|
|
11
|
-
* @param modulo
|
|
12
|
-
* @returns
|
|
13
|
-
*/
|
|
14
|
-
export declare const residue: (n: bigint, modulo: bigint) => bigint;
|
|
15
|
-
/**
|
|
16
|
-
* `length` ビットの乱数 or `length` ビット以下の乱数を出力する
|
|
17
|
-
* @param length ビット長
|
|
18
|
-
* @param fixed true: 固定長, false (デフォルト値): `length` ビット以下の可変ビット長
|
|
19
|
-
*
|
|
20
|
-
*/
|
|
21
|
-
export declare const getRandBIByBitLength: (length: number, fixed?: boolean) => bigint;
|
|
22
|
-
/**
|
|
23
|
-
* returns a random integer of `min` or more and less than `max`
|
|
24
|
-
* @param min minimum
|
|
25
|
-
* @param max upper limit
|
|
26
|
-
* @returns
|
|
27
|
-
*/
|
|
28
|
-
export declare const getRandBIByRange: (min: bigint, max: bigint) => bigint;
|
|
29
|
-
/**
|
|
30
|
-
* calculates modpow
|
|
31
|
-
* @param base
|
|
32
|
-
* @param power
|
|
33
|
-
* @param mod
|
|
34
|
-
*
|
|
35
|
-
*/
|
|
36
|
-
export declare const modPow: (base: bigint, power: bigint, mod: bigint) => bigint;
|
|
37
|
-
/**
|
|
38
|
-
* extended Euclidean algorithm \
|
|
3
|
+
* Extended Euclidean algorithm \
|
|
39
4
|
* reference: https://qiita.com/angel_p_57/items/56a902cbd1fe519747bd
|
|
40
5
|
*
|
|
41
6
|
* @description `ax - by = gcd(a, b)`
|
|
@@ -49,7 +14,7 @@ export declare const exEuclidean: (a: bigint, b: bigint) => {
|
|
|
49
14
|
gcd: bigint;
|
|
50
15
|
};
|
|
51
16
|
/**
|
|
52
|
-
*
|
|
17
|
+
* Returns factorial of an input \
|
|
53
18
|
* ref: https://qiita.com/AkariLuminous/items/1b2e964ebabde9419224
|
|
54
19
|
* @param n integer
|
|
55
20
|
* @returns factorial of `n`
|
|
@@ -76,7 +41,7 @@ export declare const rot64: (value: bigint, rot: bigint) => bigint;
|
|
|
76
41
|
*/
|
|
77
42
|
export declare const jacobiSymbol: (a: bigint, n: bigint) => bigint;
|
|
78
43
|
/**
|
|
79
|
-
*
|
|
44
|
+
* Whether an input number is square
|
|
80
45
|
* @param n
|
|
81
46
|
* @returns
|
|
82
47
|
*/
|