monoidentity 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { getLoginRecognized, getStorage } from "./storage.js";
1
+ export { getLoginRecognized, getVerification, retrieveVerification, useVerification, getStorage, } from "./storage.js";
2
2
  export { trackReady } from "./trackready.js";
3
3
  export { encode, decode } from "./utils-base36.js";
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export { getLoginRecognized, getStorage } from "./storage.js";
1
+ export { getLoginRecognized, getVerification, retrieveVerification, useVerification, getStorage, } from "./storage.js";
2
2
  export { trackReady } from "./trackready.js";
3
3
  export { encode, decode } from "./utils-base36.js";
@@ -1,4 +1,4 @@
1
- import type { Dict } from "./_createstore.js";
1
+ import type { Dict } from "./createstore.js";
2
2
  type Modification = {
3
3
  type: "set";
4
4
  old?: string;
@@ -1,4 +1,4 @@
1
- import { throttle } from "./utils-timing.js";
1
+ import { throttle } from "./_timing.js";
2
2
  export const wrapWithReplay = (storage) => {
3
3
  let modifications = {};
4
4
  if (localStorage["monoidentity-x/backup/modifications"]) {
@@ -1,3 +1,3 @@
1
- import { type Dict } from "./_createstore.js";
1
+ import { type Dict } from "./createstore.js";
2
2
  export declare const init: () => Record<string, string>;
3
3
  export declare const wrapWithBackup: (storage: Dict, requestBackup: (startBackup: () => void) => void) => Dict;
@@ -1,6 +1,6 @@
1
- import { createStore } from "./_createstore.js";
1
+ import { createStore } from "./createstore.js";
2
2
  import { wrapWithReplay } from "./_replay.js";
3
- import { canBackup } from "./utils-transport.js";
3
+ import { canBackup } from "../utils-transport.js";
4
4
  import { openDB } from "idb";
5
5
  const prefix = "monoidentity/";
6
6
  const prefixed = (key) => `${prefix}${key}`;
package/dist/storage.d.ts CHANGED
@@ -1,5 +1,11 @@
1
- import type { Login } from "./utils-transport.js";
2
1
  export declare const setup: (i: Record<string, string>, a: string) => void;
3
2
  export declare const LOGIN_RECOGNIZED_PATH = ".core/login.encjson";
4
- export declare const getLoginRecognized: () => Login;
3
+ export declare const getLoginRecognized: () => {
4
+ email: string;
5
+ password: string;
6
+ };
7
+ export declare const VERIFICATION_PATH = ".core/verification.jwt";
8
+ export declare const getVerification: () => Promise<string>;
9
+ export declare const retrieveVerification: () => Promise<any>;
10
+ export declare const useVerification: (jwt: string) => Promise<import("@tsndr/cloudflare-worker-jwt").JwtData<{}, {}> | undefined>;
5
11
  export declare const getStorage: (realm: "config" | "cache") => Record<string, any>;
package/dist/storage.js CHANGED
@@ -1,6 +1,11 @@
1
1
  import { stringify, parse } from "devalue";
2
- import { decode } from "./utils-base36.js";
3
- import { createStore } from "./_createstore.js";
2
+ import { parse as useSchema } from "valibot";
3
+ import { decode, encode } from "./utils-base36.js";
4
+ import { createStore } from "./storage/createstore.js";
5
+ import { login as loginSchema } from "./utils-transport.js";
6
+ import { verify } from "@tsndr/cloudflare-worker-jwt";
7
+ import publicKey from "./verification/public-key.js";
8
+ import attest from "./verification/attest-remote.js";
4
9
  let implementation;
5
10
  let app = "";
6
11
  export const setup = (i, a) => {
@@ -14,8 +19,32 @@ export const getLoginRecognized = () => {
14
19
  const login = implementation[LOGIN_RECOGNIZED_PATH];
15
20
  if (!login)
16
21
  throw new Error("No login found");
17
- return JSON.parse(decode(login));
22
+ return useSchema(loginSchema, JSON.parse(decode(login)));
18
23
  };
24
+ export const VERIFICATION_PATH = ".core/verification.jwt";
25
+ export const getVerification = async () => {
26
+ if (!implementation)
27
+ throw new Error("No implementation set");
28
+ const jwt = implementation[VERIFICATION_PATH];
29
+ if (!jwt)
30
+ throw new Error("No verification found");
31
+ await verify(jwt, publicKey, { algorithm: "ES256", throwError: true });
32
+ return jwt;
33
+ };
34
+ export const retrieveVerification = async () => {
35
+ if (!implementation)
36
+ throw new Error("No implementation set");
37
+ let jwt;
38
+ try {
39
+ jwt = await getVerification();
40
+ }
41
+ catch {
42
+ jwt = await attest(encode(JSON.stringify(getLoginRecognized())));
43
+ implementation[VERIFICATION_PATH] = jwt;
44
+ }
45
+ return jwt;
46
+ };
47
+ export const useVerification = (jwt) => verify(jwt, publicKey, { algorithm: "ES256", throwError: true });
19
48
  export const getStorage = (realm) => {
20
49
  const prefix = (text) => `.${realm}/${app}/${text}.devalue`;
21
50
  if (!app)
@@ -1,5 +1,5 @@
1
1
  import {} from "./utils-transport.js";
2
- import { init as initLocal, wrapWithBackup } from "./_localstorage.js";
2
+ import { init as initLocal, wrapWithBackup } from "./storage/localstorage.js";
3
3
  import { LOGIN_RECOGNIZED_PATH, setup } from "./storage.js";
4
4
  export const trackReady = (app, intents, requestBackup, ready) => {
5
5
  const params = new URLSearchParams(location.hash.slice(1));
@@ -44,9 +44,6 @@ export const trackReady = (app, intents, requestBackup, ready) => {
44
44
  if ("createLoginRecognized" in provision) {
45
45
  storage[LOGIN_RECOGNIZED_PATH] = provision.createLoginRecognized;
46
46
  }
47
- else if ("createVerification" in provision) {
48
- storage[".core/verification.jwt"] = provision.createVerification;
49
- }
50
47
  }
51
48
  ready();
52
49
  };
@@ -9,7 +9,7 @@ export type IntentEnvelope = {
9
9
  };
10
10
  export type StorageSetup = {
11
11
  method: "cloud";
12
- jwt: string;
12
+ verification: string;
13
13
  } | {
14
14
  method: "localStorage";
15
15
  };
@@ -17,15 +17,13 @@ export type Provision = {
17
17
  setup: StorageSetup;
18
18
  } | {
19
19
  createLoginRecognized: string;
20
- } | {
21
- createVerification: string;
22
20
  };
23
21
  /** @knipexternal */
24
22
  export type ProvisionEnvelope = {
25
23
  provisions: Provision[];
26
24
  };
27
- export type Login = {
28
- email: string;
29
- password: string;
30
- };
25
+ export declare const login: import("valibot", { with: { "resolution-mode": "require" } }).ObjectSchema<{
26
+ readonly email: import("valibot", { with: { "resolution-mode": "require" } }).SchemaWithPipe<readonly [import("valibot", { with: { "resolution-mode": "require" } }).StringSchema<undefined>, import("valibot", { with: { "resolution-mode": "require" } }).EmailAction<string, undefined>]>;
27
+ readonly password: import("valibot", { with: { "resolution-mode": "require" } }).StringSchema<undefined>;
28
+ }, undefined>;
31
29
  export declare const canBackup: boolean;
@@ -1 +1,3 @@
1
+ import { object, pipe, email, string } from "valibot";
2
+ export const login = object({ email: pipe(string(), email()), password: string() });
1
3
  export const canBackup = navigator.userAgent.includes("CrOS") && Boolean(window.showDirectoryPicker);
@@ -0,0 +1,2 @@
1
+ export { attest_remote_default as default };
2
+ declare function attest_remote_default(arg: any, init: any): Promise<any>;
@@ -0,0 +1,491 @@
1
+ //#region node_modules/.pnpm/devalue@5.3.2/node_modules/devalue/src/utils.js
2
+ var DevalueError = class extends Error {
3
+ /**
4
+ * @param {string} message
5
+ * @param {string[]} keys
6
+ */
7
+ constructor(message, keys) {
8
+ super(message);
9
+ this.name = "DevalueError";
10
+ this.path = keys.join("");
11
+ }
12
+ };
13
+ /** @param {any} thing */
14
+ function is_primitive(thing) {
15
+ return Object(thing) !== thing;
16
+ }
17
+ const object_proto_names = /* @__PURE__ */ Object.getOwnPropertyNames(Object.prototype).sort().join("\0");
18
+ /** @param {any} thing */
19
+ function is_plain_object(thing) {
20
+ const proto = Object.getPrototypeOf(thing);
21
+ return proto === Object.prototype || proto === null || Object.getPrototypeOf(proto) === null || Object.getOwnPropertyNames(proto).sort().join("\0") === object_proto_names;
22
+ }
23
+ /** @param {any} thing */
24
+ function get_type(thing) {
25
+ return Object.prototype.toString.call(thing).slice(8, -1);
26
+ }
27
+ /** @param {string} char */
28
+ function get_escaped_char(char) {
29
+ switch (char) {
30
+ case "\"": return "\\\"";
31
+ case "<": return "\\u003C";
32
+ case "\\": return "\\\\";
33
+ case "\n": return "\\n";
34
+ case "\r": return "\\r";
35
+ case " ": return "\\t";
36
+ case "\b": return "\\b";
37
+ case "\f": return "\\f";
38
+ case "\u2028": return "\\u2028";
39
+ case "\u2029": return "\\u2029";
40
+ default: return char < " " ? `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}` : "";
41
+ }
42
+ }
43
+ /** @param {string} str */
44
+ function stringify_string(str) {
45
+ let result = "";
46
+ let last_pos = 0;
47
+ const len = str.length;
48
+ for (let i = 0; i < len; i += 1) {
49
+ const char = str[i];
50
+ const replacement = get_escaped_char(char);
51
+ if (replacement) {
52
+ result += str.slice(last_pos, i) + replacement;
53
+ last_pos = i + 1;
54
+ }
55
+ }
56
+ return `"${last_pos === 0 ? str : result + str.slice(last_pos)}"`;
57
+ }
58
+ /** @param {Record<string | symbol, any>} object */
59
+ function enumerable_symbols(object) {
60
+ return Object.getOwnPropertySymbols(object).filter((symbol) => Object.getOwnPropertyDescriptor(object, symbol).enumerable);
61
+ }
62
+ const is_identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/;
63
+ /** @param {string} key */
64
+ function stringify_key(key) {
65
+ return is_identifier.test(key) ? "." + key : "[" + JSON.stringify(key) + "]";
66
+ }
67
+
68
+ //#endregion
69
+ //#region node_modules/.pnpm/devalue@5.3.2/node_modules/devalue/src/base64.js
70
+ /**
71
+ * Base64 Encodes an arraybuffer
72
+ * @param {ArrayBuffer} arraybuffer
73
+ * @returns {string}
74
+ */
75
+ function encode64(arraybuffer) {
76
+ const dv = new DataView(arraybuffer);
77
+ let binaryString = "";
78
+ for (let i = 0; i < arraybuffer.byteLength; i++) binaryString += String.fromCharCode(dv.getUint8(i));
79
+ return binaryToAscii(binaryString);
80
+ }
81
+ /**
82
+ * Decodes a base64 string into an arraybuffer
83
+ * @param {string} string
84
+ * @returns {ArrayBuffer}
85
+ */
86
+ function decode64(string) {
87
+ const binaryString = asciiToBinary(string);
88
+ const arraybuffer = new ArrayBuffer(binaryString.length);
89
+ const dv = new DataView(arraybuffer);
90
+ for (let i = 0; i < arraybuffer.byteLength; i++) dv.setUint8(i, binaryString.charCodeAt(i));
91
+ return arraybuffer;
92
+ }
93
+ const KEY_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
94
+ /**
95
+ * Substitute for atob since it's deprecated in node.
96
+ * Does not do any input validation.
97
+ *
98
+ * @see https://github.com/jsdom/abab/blob/master/lib/atob.js
99
+ *
100
+ * @param {string} data
101
+ * @returns {string}
102
+ */
103
+ function asciiToBinary(data) {
104
+ if (data.length % 4 === 0) data = data.replace(/==?$/, "");
105
+ let output = "";
106
+ let buffer = 0;
107
+ let accumulatedBits = 0;
108
+ for (let i = 0; i < data.length; i++) {
109
+ buffer <<= 6;
110
+ buffer |= KEY_STRING.indexOf(data[i]);
111
+ accumulatedBits += 6;
112
+ if (accumulatedBits === 24) {
113
+ output += String.fromCharCode((buffer & 16711680) >> 16);
114
+ output += String.fromCharCode((buffer & 65280) >> 8);
115
+ output += String.fromCharCode(buffer & 255);
116
+ buffer = accumulatedBits = 0;
117
+ }
118
+ }
119
+ if (accumulatedBits === 12) {
120
+ buffer >>= 4;
121
+ output += String.fromCharCode(buffer);
122
+ } else if (accumulatedBits === 18) {
123
+ buffer >>= 2;
124
+ output += String.fromCharCode((buffer & 65280) >> 8);
125
+ output += String.fromCharCode(buffer & 255);
126
+ }
127
+ return output;
128
+ }
129
+ /**
130
+ * Substitute for btoa since it's deprecated in node.
131
+ * Does not do any input validation.
132
+ *
133
+ * @see https://github.com/jsdom/abab/blob/master/lib/btoa.js
134
+ *
135
+ * @param {string} str
136
+ * @returns {string}
137
+ */
138
+ function binaryToAscii(str) {
139
+ let out = "";
140
+ for (let i = 0; i < str.length; i += 3) {
141
+ /** @type {[number, number, number, number]} */
142
+ const groupsOfSix = [
143
+ void 0,
144
+ void 0,
145
+ void 0,
146
+ void 0
147
+ ];
148
+ groupsOfSix[0] = str.charCodeAt(i) >> 2;
149
+ groupsOfSix[1] = (str.charCodeAt(i) & 3) << 4;
150
+ if (str.length > i + 1) {
151
+ groupsOfSix[1] |= str.charCodeAt(i + 1) >> 4;
152
+ groupsOfSix[2] = (str.charCodeAt(i + 1) & 15) << 2;
153
+ }
154
+ if (str.length > i + 2) {
155
+ groupsOfSix[2] |= str.charCodeAt(i + 2) >> 6;
156
+ groupsOfSix[3] = str.charCodeAt(i + 2) & 63;
157
+ }
158
+ for (let j = 0; j < groupsOfSix.length; j++) if (typeof groupsOfSix[j] === "undefined") out += "=";
159
+ else out += KEY_STRING[groupsOfSix[j]];
160
+ }
161
+ return out;
162
+ }
163
+
164
+ //#endregion
165
+ //#region node_modules/.pnpm/devalue@5.3.2/node_modules/devalue/src/constants.js
166
+ const UNDEFINED = -1;
167
+ const HOLE = -2;
168
+ const NAN = -3;
169
+ const POSITIVE_INFINITY = -4;
170
+ const NEGATIVE_INFINITY = -5;
171
+ const NEGATIVE_ZERO = -6;
172
+
173
+ //#endregion
174
+ //#region node_modules/.pnpm/devalue@5.3.2/node_modules/devalue/src/parse.js
175
+ /**
176
+ * Revive a value serialized with `devalue.stringify`
177
+ * @param {string} serialized
178
+ * @param {Record<string, (value: any) => any>} [revivers]
179
+ */
180
+ function parse(serialized, revivers) {
181
+ return unflatten(JSON.parse(serialized), revivers);
182
+ }
183
+ /**
184
+ * Revive a value flattened with `devalue.stringify`
185
+ * @param {number | any[]} parsed
186
+ * @param {Record<string, (value: any) => any>} [revivers]
187
+ */
188
+ function unflatten(parsed, revivers) {
189
+ if (typeof parsed === "number") return hydrate(parsed, true);
190
+ if (!Array.isArray(parsed) || parsed.length === 0) throw new Error("Invalid input");
191
+ const values = parsed;
192
+ const hydrated = Array(values.length);
193
+ /**
194
+ * @param {number} index
195
+ * @returns {any}
196
+ */
197
+ function hydrate(index, standalone = false) {
198
+ if (index === UNDEFINED) return void 0;
199
+ if (index === NAN) return NaN;
200
+ if (index === POSITIVE_INFINITY) return Infinity;
201
+ if (index === NEGATIVE_INFINITY) return -Infinity;
202
+ if (index === NEGATIVE_ZERO) return -0;
203
+ if (standalone || typeof index !== "number") throw new Error(`Invalid input`);
204
+ if (index in hydrated) return hydrated[index];
205
+ const value = values[index];
206
+ if (!value || typeof value !== "object") hydrated[index] = value;
207
+ else if (Array.isArray(value)) if (typeof value[0] === "string") {
208
+ const type = value[0];
209
+ const reviver = revivers?.[type];
210
+ if (reviver) return hydrated[index] = reviver(hydrate(value[1]));
211
+ switch (type) {
212
+ case "Date":
213
+ hydrated[index] = new Date(value[1]);
214
+ break;
215
+ case "Set":
216
+ const set = /* @__PURE__ */ new Set();
217
+ hydrated[index] = set;
218
+ for (let i = 1; i < value.length; i += 1) set.add(hydrate(value[i]));
219
+ break;
220
+ case "Map":
221
+ const map = /* @__PURE__ */ new Map();
222
+ hydrated[index] = map;
223
+ for (let i = 1; i < value.length; i += 2) map.set(hydrate(value[i]), hydrate(value[i + 1]));
224
+ break;
225
+ case "RegExp":
226
+ hydrated[index] = new RegExp(value[1], value[2]);
227
+ break;
228
+ case "Object":
229
+ hydrated[index] = Object(value[1]);
230
+ break;
231
+ case "BigInt":
232
+ hydrated[index] = BigInt(value[1]);
233
+ break;
234
+ case "null":
235
+ const obj = Object.create(null);
236
+ hydrated[index] = obj;
237
+ for (let i = 1; i < value.length; i += 2) obj[value[i]] = hydrate(value[i + 1]);
238
+ break;
239
+ case "Int8Array":
240
+ case "Uint8Array":
241
+ case "Uint8ClampedArray":
242
+ case "Int16Array":
243
+ case "Uint16Array":
244
+ case "Int32Array":
245
+ case "Uint32Array":
246
+ case "Float32Array":
247
+ case "Float64Array":
248
+ case "BigInt64Array":
249
+ case "BigUint64Array": {
250
+ const TypedArrayConstructor = globalThis[type];
251
+ const typedArray = new TypedArrayConstructor(hydrate(value[1]));
252
+ hydrated[index] = value[2] !== void 0 ? typedArray.subarray(value[2], value[3]) : typedArray;
253
+ break;
254
+ }
255
+ case "ArrayBuffer": {
256
+ const base64 = value[1];
257
+ hydrated[index] = decode64(base64);
258
+ break;
259
+ }
260
+ case "Temporal.Duration":
261
+ case "Temporal.Instant":
262
+ case "Temporal.PlainDate":
263
+ case "Temporal.PlainTime":
264
+ case "Temporal.PlainDateTime":
265
+ case "Temporal.PlainMonthDay":
266
+ case "Temporal.PlainYearMonth":
267
+ case "Temporal.ZonedDateTime": {
268
+ const temporalName = type.slice(9);
269
+ hydrated[index] = Temporal[temporalName].from(value[1]);
270
+ break;
271
+ }
272
+ case "URL":
273
+ hydrated[index] = new URL(value[1]);
274
+ break;
275
+ case "URLSearchParams":
276
+ hydrated[index] = new URLSearchParams(value[1]);
277
+ break;
278
+ default: throw new Error(`Unknown type ${type}`);
279
+ }
280
+ } else {
281
+ const array = new Array(value.length);
282
+ hydrated[index] = array;
283
+ for (let i = 0; i < value.length; i += 1) {
284
+ const n = value[i];
285
+ if (n === HOLE) continue;
286
+ array[i] = hydrate(n);
287
+ }
288
+ }
289
+ else {
290
+ /** @type {Record<string, any>} */
291
+ const object = {};
292
+ hydrated[index] = object;
293
+ for (const key in value) {
294
+ if (key === "__proto__") throw new Error("Cannot parse an object with a `__proto__` property");
295
+ const n = value[key];
296
+ object[key] = hydrate(n);
297
+ }
298
+ }
299
+ return hydrated[index];
300
+ }
301
+ return hydrate(0);
302
+ }
303
+
304
+ //#endregion
305
+ //#region node_modules/.pnpm/devalue@5.3.2/node_modules/devalue/src/stringify.js
306
+ /**
307
+ * Turn a value into a JSON string that can be parsed with `devalue.parse`
308
+ * @param {any} value
309
+ * @param {Record<string, (value: any) => any>} [reducers]
310
+ */
311
+ function stringify(value, reducers) {
312
+ /** @type {any[]} */
313
+ const stringified = [];
314
+ /** @type {Map<any, number>} */
315
+ const indexes = /* @__PURE__ */ new Map();
316
+ /** @type {Array<{ key: string, fn: (value: any) => any }>} */
317
+ const custom = [];
318
+ if (reducers) for (const key of Object.getOwnPropertyNames(reducers)) custom.push({
319
+ key,
320
+ fn: reducers[key]
321
+ });
322
+ /** @type {string[]} */
323
+ const keys = [];
324
+ let p = 0;
325
+ /** @param {any} thing */
326
+ function flatten(thing) {
327
+ if (typeof thing === "function") throw new DevalueError(`Cannot stringify a function`, keys);
328
+ if (thing === void 0) return UNDEFINED;
329
+ if (Number.isNaN(thing)) return NAN;
330
+ if (thing === Infinity) return POSITIVE_INFINITY;
331
+ if (thing === -Infinity) return NEGATIVE_INFINITY;
332
+ if (thing === 0 && 1 / thing < 0) return NEGATIVE_ZERO;
333
+ if (indexes.has(thing)) return indexes.get(thing);
334
+ const index$1 = p++;
335
+ indexes.set(thing, index$1);
336
+ for (const { key, fn } of custom) {
337
+ const value$1 = fn(thing);
338
+ if (value$1) {
339
+ stringified[index$1] = `["${key}",${flatten(value$1)}]`;
340
+ return index$1;
341
+ }
342
+ }
343
+ let str = "";
344
+ if (is_primitive(thing)) str = stringify_primitive(thing);
345
+ else {
346
+ const type = get_type(thing);
347
+ switch (type) {
348
+ case "Number":
349
+ case "String":
350
+ case "Boolean":
351
+ str = `["Object",${stringify_primitive(thing)}]`;
352
+ break;
353
+ case "BigInt":
354
+ str = `["BigInt",${thing}]`;
355
+ break;
356
+ case "Date":
357
+ str = `["Date","${!isNaN(thing.getDate()) ? thing.toISOString() : ""}"]`;
358
+ break;
359
+ case "URL":
360
+ str = `["URL",${stringify_string(thing.toString())}]`;
361
+ break;
362
+ case "URLSearchParams":
363
+ str = `["URLSearchParams",${stringify_string(thing.toString())}]`;
364
+ break;
365
+ case "RegExp":
366
+ const { source, flags } = thing;
367
+ str = flags ? `["RegExp",${stringify_string(source)},"${flags}"]` : `["RegExp",${stringify_string(source)}]`;
368
+ break;
369
+ case "Array":
370
+ str = "[";
371
+ for (let i = 0; i < thing.length; i += 1) {
372
+ if (i > 0) str += ",";
373
+ if (i in thing) {
374
+ keys.push(`[${i}]`);
375
+ str += flatten(thing[i]);
376
+ keys.pop();
377
+ } else str += HOLE;
378
+ }
379
+ str += "]";
380
+ break;
381
+ case "Set":
382
+ str = "[\"Set\"";
383
+ for (const value$1 of thing) str += `,${flatten(value$1)}`;
384
+ str += "]";
385
+ break;
386
+ case "Map":
387
+ str = "[\"Map\"";
388
+ for (const [key, value$1] of thing) {
389
+ keys.push(`.get(${is_primitive(key) ? stringify_primitive(key) : "..."})`);
390
+ str += `,${flatten(key)},${flatten(value$1)}`;
391
+ keys.pop();
392
+ }
393
+ str += "]";
394
+ break;
395
+ case "Int8Array":
396
+ case "Uint8Array":
397
+ case "Uint8ClampedArray":
398
+ case "Int16Array":
399
+ case "Uint16Array":
400
+ case "Int32Array":
401
+ case "Uint32Array":
402
+ case "Float32Array":
403
+ case "Float64Array":
404
+ case "BigInt64Array":
405
+ case "BigUint64Array": {
406
+ /** @type {import("./types.js").TypedArray} */
407
+ const typedArray = thing;
408
+ str = "[\"" + type + "\"," + flatten(typedArray.buffer);
409
+ const a = thing.byteOffset;
410
+ const b = a + thing.byteLength;
411
+ if (a > 0 || b !== typedArray.buffer.byteLength) {
412
+ const m = +/(\d+)/.exec(type)[1] / 8;
413
+ str += `,${a / m},${b / m}`;
414
+ }
415
+ str += "]";
416
+ break;
417
+ }
418
+ case "ArrayBuffer":
419
+ str = `["ArrayBuffer","${encode64(thing)}"]`;
420
+ break;
421
+ case "Temporal.Duration":
422
+ case "Temporal.Instant":
423
+ case "Temporal.PlainDate":
424
+ case "Temporal.PlainTime":
425
+ case "Temporal.PlainDateTime":
426
+ case "Temporal.PlainMonthDay":
427
+ case "Temporal.PlainYearMonth":
428
+ case "Temporal.ZonedDateTime":
429
+ str = `["${type}",${stringify_string(thing.toString())}]`;
430
+ break;
431
+ default:
432
+ if (!is_plain_object(thing)) throw new DevalueError(`Cannot stringify arbitrary non-POJOs`, keys);
433
+ if (enumerable_symbols(thing).length > 0) throw new DevalueError(`Cannot stringify POJOs with symbolic keys`, keys);
434
+ if (Object.getPrototypeOf(thing) === null) {
435
+ str = "[\"null\"";
436
+ for (const key in thing) {
437
+ keys.push(stringify_key(key));
438
+ str += `,${stringify_string(key)},${flatten(thing[key])}`;
439
+ keys.pop();
440
+ }
441
+ str += "]";
442
+ } else {
443
+ str = "{";
444
+ let started = false;
445
+ for (const key in thing) {
446
+ if (started) str += ",";
447
+ started = true;
448
+ keys.push(stringify_key(key));
449
+ str += `${stringify_string(key)}:${flatten(thing[key])}`;
450
+ keys.pop();
451
+ }
452
+ str += "}";
453
+ }
454
+ }
455
+ }
456
+ stringified[index$1] = str;
457
+ return index$1;
458
+ }
459
+ const index = flatten(value);
460
+ if (index < 0) return `${index}`;
461
+ return `[${stringified.join(",")}]`;
462
+ }
463
+ /**
464
+ * @param {any} thing
465
+ * @returns {string}
466
+ */
467
+ function stringify_primitive(thing) {
468
+ const type = typeof thing;
469
+ if (type === "string") return stringify_string(thing);
470
+ if (thing instanceof String) return stringify_string(thing.toString());
471
+ if (thing === void 0) return UNDEFINED.toString();
472
+ if (thing === 0 && 1 / thing < 0) return NEGATIVE_ZERO.toString();
473
+ if (type === "bigint") return `["BigInt","${thing}"]`;
474
+ return String(thing);
475
+ }
476
+
477
+ //#endregion
478
+ //#region src/lib/verification/attest.remote.ts
479
+ async function attest_remote_default(arg, init) {
480
+ const res = await fetch("https://benignmonoserver.fly.dev/b1c8ae45b4", {
481
+ method: "POST",
482
+ body: stringify(arg),
483
+ ...init
484
+ });
485
+ if (!res.ok) throw new Error(await res.text());
486
+ if (!res.headers.get("content-type")?.includes("application/json")) return res;
487
+ return parse(await res.text());
488
+ }
489
+
490
+ //#endregion
491
+ export { attest_remote_default as default };
@@ -0,0 +1,2 @@
1
+ openssl ecparam -genkey -name prime256v1 -noout | openssl pkcs8 -topk8 -nocrypt -out private.pem
2
+ openssl ec -in private.pem -pubout -out public.pem
@@ -0,0 +1,2 @@
1
+ declare const _default: "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAERXBMZBkx95Iua82tR9gsmdegOwuB\nOGgbkB6h9s4DROhBRkpubcAiu5Qa9GizbWk1g0RwrnrdVo7yxENcEs2+zw==\n-----END PUBLIC KEY-----\n";
2
+ export default _default;
@@ -0,0 +1,5 @@
1
+ export default `-----BEGIN PUBLIC KEY-----
2
+ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAERXBMZBkx95Iua82tR9gsmdegOwuB
3
+ OGgbkB6h9s4DROhBRkpubcAiu5Qa9GizbWk1g0RwrnrdVo7yxENcEs2+zw==
4
+ -----END PUBLIC KEY-----
5
+ `;
@@ -0,0 +1,6 @@
1
+ declare const _default: ({ base, userID, password }: {
2
+ base: string;
3
+ userID: string;
4
+ password: string;
5
+ }, name: string, params?: Record<string, string>) => Promise<any>;
6
+ export default _default;
@@ -0,0 +1,45 @@
1
+ import { XMLParser } from "fast-xml-parser";
2
+ const build = (object) => {
3
+ const params = new URLSearchParams();
4
+ for (const [key, value] of Object.entries(object)) {
5
+ params.set(key, value);
6
+ }
7
+ return params;
8
+ };
9
+ const parser = new XMLParser({ ignoreAttributes: false });
10
+ export default async ({ base, userID, password }, name, params = {}) => {
11
+ const request = build({
12
+ userID,
13
+ password,
14
+ skipLoginLog: "true",
15
+ parent: "false",
16
+ webServiceHandleName: "PXPWebServices",
17
+ methodName: name,
18
+ paramStr: `<Parms>${Object.keys(params)
19
+ .map((key) => `<${key}>${params[key]}</${key}>`)
20
+ .join("")}</Parms>`,
21
+ });
22
+ const response = await fetch(`${base}/Service/PXPCommunication.asmx/ProcessWebServiceRequest`, {
23
+ method: "POST",
24
+ body: request,
25
+ headers: {
26
+ "content-type": "application/x-www-form-urlencoded",
27
+ },
28
+ });
29
+ const dataWrap = await response.text();
30
+ const data = dataWrap
31
+ .split(`<string xmlns="http://edupoint.com/webservices/">`)[1]
32
+ .split("</string>")[0]
33
+ .replace(/&amp;/g, "&")
34
+ .replace(/&lt;/g, "<")
35
+ .replace(/&gt;/g, ">");
36
+ const xml = parser.parse(data);
37
+ const err = xml.RT_ERROR;
38
+ if (err) {
39
+ if (err["@_ERROR_MESSAGE"].startsWith("Invalid user id or password")) {
40
+ throw new Error("Invalid auth");
41
+ }
42
+ throw new Error("StudentVue error");
43
+ }
44
+ return xml;
45
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monoidentity",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "repository": "KTibow/monoidentity",
5
5
  "author": {
6
6
  "name": "KTibow"
@@ -31,21 +31,28 @@
31
31
  "svelte": "^5.0.0"
32
32
  },
33
33
  "dependencies": {
34
+ "@tsndr/cloudflare-worker-jwt": "^3.2.0",
34
35
  "devalue": "^5.3.2",
35
- "idb": "^8.0.3"
36
+ "idb": "^8.0.3",
37
+ "valibot": "^1.1.0"
36
38
  },
37
39
  "devDependencies": {
38
40
  "@sveltejs/adapter-static": "^3.0.9",
39
- "@sveltejs/kit": "^2.22.0",
40
- "@sveltejs/package": "^2.0.0",
41
- "@sveltejs/vite-plugin-svelte": "^6.0.0",
41
+ "@sveltejs/kit": "^2.43.5",
42
+ "@sveltejs/package": "^2.5.4",
43
+ "@sveltejs/vite-plugin-svelte": "^6.2.1",
42
44
  "@types/wicg-file-system-access": "^2023.10.6",
43
- "knip": "^5.64.0",
44
- "publint": "^0.3.2",
45
- "svelte": "^5.0.0",
46
- "svelte-check": "^4.0.0",
47
- "typescript": "^5.0.0",
48
- "vite": "^7.0.4"
45
+ "fast-xml-parser": "^5.2.5",
46
+ "knip": "^5.64.1",
47
+ "monoserve": "^2.2.0",
48
+ "publint": "^0.3.13",
49
+ "rolldown": "1.0.0-beta.40",
50
+ "school-districts": "^2.0.0",
51
+ "svelte": "^5.39.6",
52
+ "svelte-check": "^4.3.2",
53
+ "tinyglobby": "^0.2.15",
54
+ "typescript": "^5.9.2",
55
+ "vite": "^7.1.7"
49
56
  },
50
57
  "keywords": [
51
58
  "svelte"
File without changes