@northtalk/ts 0.9.0 → 0.11.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/{binary-value-B93hEK7l.d.ts → binary-value-np-QZCfn.d.ts} +1 -1
- package/{checker-D74oYIhs.js → checker-hkWO1UbN.js} +1 -1
- package/{core-BBPI6EhG.d.ts → core-kBXyAo-m.d.ts} +1 -1
- package/{debug-s6QIovKS.d.ts → debug-fthW6KN8.d.ts} +15 -1
- package/debug.d.ts +1 -1
- package/{driver-D5yrK3Nu.d.ts → driver-DtOBRKiH.d.ts} +1 -1
- package/driver.d.ts +1 -1
- package/{encoding-DzVFpg7k.js → encoding-DlMqlP2Y.js} +1 -1
- package/{engine-Dy-BCoiw.d.ts → engine-BoafZGEv.d.ts} +2 -2
- package/{engine-Bx8B63iQ.js → engine-CxcONfhv.js} +4 -4
- package/{group-CY4FKhzT.js → group-dgTtB1Pi.js} +179 -97
- package/{http-fetch-DnpfiOWK.js → http-fetch-CLAeEXVi.js} +1 -1
- package/http.d.ts +1 -1
- package/http.js +2 -2
- package/index.d.ts +4 -4
- package/index.js +11 -11
- package/{lean-Bg_UTRj0.d.ts → lean-BAz1NuyP.d.ts} +2 -2
- package/{lean-DTCTJUmR.js → lean-BwszbUJl.js} +8 -8
- package/lean.d.ts +4 -4
- package/lean.js +11 -11
- package/{manifest-DVS1SEmN.js → manifest-CRpUahPt.js} +2 -2
- package/message-layer.d.ts +2 -2
- package/message-layer.js +1 -1
- package/notify.d.ts +1 -1
- package/notify.js +1 -1
- package/{objects-q0lnCK-4.d.ts → objects-Cpc3eO-f.d.ts} +1 -1
- package/{operations-B3XaG7Ve.js → operations-DrsedOvj.js} +3 -3
- package/package.json +1 -1
- package/{peer-capability-3etyPHs3.js → peer-capability-RMdN4OHj.js} +2 -2
- package/peer.d.ts +1 -1
- package/peer.js +2 -2
- package/{readers-AeB1bJ--.d.ts → readers-DW4pUrD-.d.ts} +1 -1
- package/{request-pump-binary-VOPVqRZD.js → request-pump-binary-P8m6kLfB.js} +229 -51
- package/{router-Bdm4KiMG.js → router-C_Fjc2as.js} +4 -4
- package/{router-DXoJ_2Z4.d.ts → router-D6b7VJ92.d.ts} +2 -2
- package/session.d.ts +2 -2
- package/session.js +21 -17
- package/setup.d.ts +2 -2
- package/setup.js +3 -3
- package/sha256-C5Lqj5U7.js +197 -0
- package/sqlite.d.ts +2 -2
- package/sqlite.js +3 -3
- package/{store-BTcyKBLg.js → store-_af2DPoK.js} +2 -2
- package/{store-capability-CBJ6mUoH.js → store-capability-Db6v_dw9.js} +2 -2
- package/store.d.ts +2 -2
- package/store.js +2 -2
- package/{user-capability-DNY2dyjq.js → user-capability-CzoLN3RK.js} +2 -2
- package/wasm.d.ts +15 -4
- package/wasm.js +119 -46
- package/{zone-rules-DsCJtmlC.js → zone-rules-Cn-f9u_Z.js} +3 -3
- package/sha256-9CGf5BS_.js +0 -168
package/wasm.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
|
|
2
2
|
import { D as instant, G as patternValue, H as num, J as range, K as quantity, L as map, N as list, Qt as parseInstant, U as objectValue, V as nothing, X as requireArgs, Xt as nowMicros, Y as record, Z as requireValue, b as dec, c as Decimal, d as bytes, g as civilDate, i as ScriptError, it as text, l as Value, n as LoadError, o as invalidValue, qt as formatInstant, r as MailboxFull, s as sendFailed, t as HostError, u as bool, w as functionValue } from "./errors-CNc-xY_9.js";
|
|
3
3
|
import { a as rebindObject, n as makeObject, t as defineObjectKind } from "./objects-OKVLH190.js";
|
|
4
|
-
import { Dt as shape, Et as operationDeclarations, bt as defineCapability, gt as LimitReached, mt as limitDefaults, vt as conforms, wt as explain } from "./operations-
|
|
5
|
-
import { c as CallMeter, i as operationData, n as exportManifest, o as shapeData, s as invoke } from "./manifest-
|
|
4
|
+
import { Dt as shape, Et as operationDeclarations, bt as defineCapability, gt as LimitReached, mt as limitDefaults, vt as conforms, wt as explain } from "./operations-DrsedOvj.js";
|
|
5
|
+
import { c as CallMeter, i as operationData, n as exportManifest, o as shapeData, s as invoke } from "./manifest-CRpUahPt.js";
|
|
6
6
|
import { n as trackOperation } from "./operation-promises-ClA1BTaS.js";
|
|
7
7
|
import { n as toBase64, t as fromBase64 } from "./base64-CDO-a06R.js";
|
|
8
8
|
import { a as fromJson, c as readDisplay, l as readOrderedJSON, n as JsonObject, o as isJsonNumber, r as decodeValue, s as isJsonObject, t as JsonNumber } from "./readers-G1lHqrPl.js";
|
|
9
|
-
import { a as clockCapability, d as timerCapability, i as calendarCapability, l as isMusicalClock, n as quoteJSON, o as consoleCapability, p as standardChecks, r as MUSICAL_CLOCK, t as encodeValue, u as musicalClockCapability } from "./encoding-
|
|
10
|
-
import { a as peerKind, i as peerCapability } from "./peer-capability-
|
|
11
|
-
import { a as httpCapability, c as toValue, i as handlersOf, l as talk, n as inlineGrants, o as sqliteCapability, r as createGroup, s as fromValue, t as zoneRules } from "./zone-rules-
|
|
12
|
-
import { o as decodeJson, s as encodeJson } from "./http-fetch-
|
|
13
|
-
import { n as localeCapability, t as userCapability } from "./user-capability-
|
|
14
|
-
import { r as storeCapability, t as add } from "./store-capability-
|
|
15
|
-
import { a as encodeResult, c as isRequestPumpBinary, d as valueNode, i as encodeBinaryFrame, l as placeholderValues, n as decodeBinaryFrame, o as heldValue, r as decodeNeed, s as isBinaryNeed, t as callbacksFeature, u as requestPumpFeature } from "./request-pump-binary-
|
|
9
|
+
import { a as clockCapability, d as timerCapability, i as calendarCapability, l as isMusicalClock, n as quoteJSON, o as consoleCapability, p as standardChecks, r as MUSICAL_CLOCK, t as encodeValue, u as musicalClockCapability } from "./encoding-DlMqlP2Y.js";
|
|
10
|
+
import { a as peerKind, i as peerCapability } from "./peer-capability-RMdN4OHj.js";
|
|
11
|
+
import { a as httpCapability, c as toValue, i as handlersOf, l as talk, n as inlineGrants, o as sqliteCapability, r as createGroup, s as fromValue, t as zoneRules } from "./zone-rules-Cn-f9u_Z.js";
|
|
12
|
+
import { o as decodeJson, s as encodeJson } from "./http-fetch-CLAeEXVi.js";
|
|
13
|
+
import { n as localeCapability, t as userCapability } from "./user-capability-CzoLN3RK.js";
|
|
14
|
+
import { r as storeCapability, t as add } from "./store-capability-Db6v_dw9.js";
|
|
15
|
+
import { a as encodeResult, c as isRequestPumpBinary, d as valueNode, f as envelopeJsonMessages, i as encodeBinaryFrame, l as placeholderValues, m as envelopeViews, n as decodeBinaryFrame, o as heldValue, p as envelopeMessages, r as decodeNeed, s as isBinaryNeed, t as callbacksFeature, u as requestPumpFeature } from "./request-pump-binary-P8m6kLfB.js";
|
|
16
16
|
//#region src/wasm/wire.ts
|
|
17
17
|
const raw = Symbol("raw JSON");
|
|
18
18
|
const sep = Symbol("separator");
|
|
@@ -361,8 +361,56 @@ var Reactor = class {
|
|
|
361
361
|
}
|
|
362
362
|
};
|
|
363
363
|
//#endregion
|
|
364
|
+
//#region src/wasm/envelope-json.ts
|
|
365
|
+
const fieldsOf = new Map([...envelopeMessages.filter((m) => m.layouts?.includes("json")).map((m) => [m.name, m.fields]), ...envelopeJsonMessages.map((m) => [m.name, m.fields])]);
|
|
366
|
+
/** Each view's fields by name, and its required ones. */
|
|
367
|
+
const views = new Map(envelopeViews.map((v) => [v.name, {
|
|
368
|
+
byName: new Map(v.fields.map((f) => [f.name, f])),
|
|
369
|
+
required: v.fields.filter((f) => f.required).map((f) => f.name)
|
|
370
|
+
}]));
|
|
371
|
+
/** A message's JSON fields, in catalogue order; absent fields are left out. */
|
|
372
|
+
const encodeJsonMessage = (m, record) => {
|
|
373
|
+
const given = record;
|
|
374
|
+
const out = {};
|
|
375
|
+
for (const f of fieldsOf.get(m)) if (f.name !== "ref" && f.name !== "group" && given[f.name] !== void 0) out[f.name] = given[f.name];
|
|
376
|
+
return out;
|
|
377
|
+
};
|
|
378
|
+
const uintOf = (j) => isJsonNumber(j) ? BigInt(j.source) : typeof j === "string" && /^\d+$/.test(j) ? BigInt(j) : void 0;
|
|
379
|
+
const decodeField = (f, j) => {
|
|
380
|
+
switch (f.kind) {
|
|
381
|
+
case "text":
|
|
382
|
+
case "instant": return textOf(j);
|
|
383
|
+
case "texts": return textsOf(j);
|
|
384
|
+
case "bool": return boolOf(j);
|
|
385
|
+
case "int": return intOf(j);
|
|
386
|
+
case "uint": return uintOf(j);
|
|
387
|
+
case "pairs": return listOf(j).map((p) => {
|
|
388
|
+
const [k, v] = listOf(p);
|
|
389
|
+
return [textOf(k) ?? "", v ?? null];
|
|
390
|
+
});
|
|
391
|
+
case "views": return listOf(j).map((x) => decodeView(f.view, x));
|
|
392
|
+
default: return j;
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
const decodeView = (name, j) => {
|
|
396
|
+
const { byName, required } = views.get(name);
|
|
397
|
+
const out = {};
|
|
398
|
+
for (const [k, v] of entriesOf(j)) {
|
|
399
|
+
const f = byName.get(k);
|
|
400
|
+
if (f) {
|
|
401
|
+
const decoded = decodeField(f, v);
|
|
402
|
+
if (decoded !== void 0) out[k] = decoded;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
for (const k of required) if (!(k in out)) throw new InstanceLostError(`The ${name} reply lacks ${k}`);
|
|
406
|
+
return out;
|
|
407
|
+
};
|
|
408
|
+
/** A reply view read from its JSON, typed by the catalogue. */
|
|
409
|
+
const decodeJsonView = (view, j) => decodeView(view, j);
|
|
410
|
+
//#endregion
|
|
364
411
|
//#region src/wasm/group.ts
|
|
365
412
|
const key = (kind, id) => `${kind}\u0000${id}`;
|
|
413
|
+
const sameBytes = (a, b) => a.length === b.length && a.every((x, i) => x === b[i]);
|
|
366
414
|
const isLimitReached = (error) => error instanceof Error && error.name === "LimitReached";
|
|
367
415
|
const propertyFailure = (details, detail) => {
|
|
368
416
|
details.push(detail);
|
|
@@ -472,6 +520,8 @@ var WasmGroup = class {
|
|
|
472
520
|
/** Calls a restore left pending, until the first Pump. */
|
|
473
521
|
#restored = /* @__PURE__ */ new Map();
|
|
474
522
|
#restoring = null;
|
|
523
|
+
/** The Libraries the Host gave or `libraries()` made, by name, latest last. */
|
|
524
|
+
#libraries = /* @__PURE__ */ new Map();
|
|
475
525
|
#exchanging = 0;
|
|
476
526
|
#combining = false;
|
|
477
527
|
/** Answers given while their call was starting, sent once the exchange ends. */
|
|
@@ -1043,6 +1093,29 @@ var WasmGroup = class {
|
|
|
1043
1093
|
scriptNames() {
|
|
1044
1094
|
return [...this.#scripts.keys()];
|
|
1045
1095
|
}
|
|
1096
|
+
/**
|
|
1097
|
+
* The user Libraries the guest holds, in add order. One a Library
|
|
1098
|
+
* replacement recompiled is compiled again here, against the Libraries
|
|
1099
|
+
* before it, so a restore can install it.
|
|
1100
|
+
*/
|
|
1101
|
+
libraries() {
|
|
1102
|
+
const held = [];
|
|
1103
|
+
const now = /* @__PURE__ */ new Map();
|
|
1104
|
+
for (const item of listOf(field(this.send("libraries"), "libraries"))) {
|
|
1105
|
+
const name = textOf(field(item, "name"));
|
|
1106
|
+
const identity = bytesOfFrame(field(item, "identity"));
|
|
1107
|
+
let library = this.#libraries.get(name);
|
|
1108
|
+
if (!library) throw new HostError("library mismatch", `${name} isn't known here`);
|
|
1109
|
+
if (!sameBytes(library.identity, identity)) {
|
|
1110
|
+
library = this.#core.recompile(library, library.imports.map((l) => now.get(l.name) ?? l));
|
|
1111
|
+
if (!sameBytes(library.identity, identity)) throw new HostError("library mismatch", `${name} compiled differently`);
|
|
1112
|
+
this.#libraries.set(name, library);
|
|
1113
|
+
}
|
|
1114
|
+
now.set(name, library);
|
|
1115
|
+
held.push(library);
|
|
1116
|
+
}
|
|
1117
|
+
return held;
|
|
1118
|
+
}
|
|
1046
1119
|
#grantHandles(grants) {
|
|
1047
1120
|
return Object.fromEntries(Object.entries(grants).map(([name, g]) => [name, this.#session.grant(g)]));
|
|
1048
1121
|
}
|
|
@@ -1054,19 +1127,20 @@ var WasmGroup = class {
|
|
|
1054
1127
|
...given,
|
|
1055
1128
|
[MUSICAL_CLOCK]: this.#musicalClock
|
|
1056
1129
|
} : given;
|
|
1057
|
-
const
|
|
1130
|
+
const load = {
|
|
1058
1131
|
name: o.name,
|
|
1059
1132
|
source: o.source,
|
|
1060
1133
|
grants: this.#grantHandles(grants),
|
|
1061
1134
|
grantsAsUsed: o.grantsAsUsed,
|
|
1062
|
-
forbidSuspension: o.forbidSuspension || void 0,
|
|
1063
1135
|
owner: o.owner ? this.#objectRef(o.owner) : void 0,
|
|
1064
1136
|
objects: o.objects ? Object.fromEntries(Object.entries(o.objects).map(([n, h]) => [n, this.#objectRef(h)])) : void 0,
|
|
1065
1137
|
limits: {
|
|
1066
1138
|
...limitDefaults,
|
|
1067
1139
|
...o.limits
|
|
1068
|
-
}
|
|
1069
|
-
|
|
1140
|
+
},
|
|
1141
|
+
forbidSuspension: o.forbidSuspension || void 0
|
|
1142
|
+
};
|
|
1143
|
+
const ok = this.worker("load", encodeJsonMessage("load", load));
|
|
1070
1144
|
const name = textOf(field(ok, "script")) ?? o.name;
|
|
1071
1145
|
this.#bindings.set(name, new Map(Object.entries(grants)));
|
|
1072
1146
|
const script = new WasmScript(this, name);
|
|
@@ -1076,14 +1150,17 @@ var WasmGroup = class {
|
|
|
1076
1150
|
addLibrary(l) {
|
|
1077
1151
|
this.#core.install(this.#session, l);
|
|
1078
1152
|
this.worker("add-library", { identity: bytesFrame(l.identity) });
|
|
1153
|
+
this.#libraries.set(l.name, l);
|
|
1079
1154
|
}
|
|
1080
1155
|
replaceLibrary(l, carry, o) {
|
|
1081
1156
|
this.#core.install(this.#session, l);
|
|
1082
|
-
|
|
1157
|
+
const reports = this.lifecycle("replace-library", {
|
|
1083
1158
|
identity: bytesFrame(l.identity),
|
|
1084
1159
|
carry,
|
|
1085
1160
|
keepMailbox: o?.keepMailbox
|
|
1086
1161
|
});
|
|
1162
|
+
this.#libraries.set(l.name, l);
|
|
1163
|
+
return reports;
|
|
1087
1164
|
}
|
|
1088
1165
|
/** @internal Reload and Library replacement end Runs and settle their futures. */
|
|
1089
1166
|
lifecycle(m, fields) {
|
|
@@ -1293,37 +1370,29 @@ var WasmGroup = class {
|
|
|
1293
1370
|
return bytesOfFrame(field(this.worker("state-fingerprint"), "stateFingerprint"));
|
|
1294
1371
|
}
|
|
1295
1372
|
inspect() {
|
|
1296
|
-
const ok = this.worker("inspect");
|
|
1297
|
-
return { scripts:
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
}
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
}
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
name: textOf(field(message, "name")),
|
|
1320
|
-
args: listOf(field(message, "args")).map((a) => decode(this.#codec, a)),
|
|
1321
|
-
...limits ? { limits } : {}
|
|
1322
|
-
}
|
|
1323
|
-
};
|
|
1324
|
-
})
|
|
1325
|
-
};
|
|
1326
|
-
}) };
|
|
1373
|
+
const ok = this.worker("inspect", encodeJsonMessage("inspect", {}));
|
|
1374
|
+
return { scripts: decodeJsonView("inspection", ok).scripts.map((s) => ({
|
|
1375
|
+
name: s.name,
|
|
1376
|
+
...s.disabledGrants?.length ? { disabledGrants: [...s.disabledGrants] } : {},
|
|
1377
|
+
...s.forbidSuspension ? { forbidSuspension: true } : {},
|
|
1378
|
+
vars: s.vars.map(([name, v]) => [name, decode(this.#codec, v)]),
|
|
1379
|
+
runs: s.runs.map((r) => ({
|
|
1380
|
+
id: r.id,
|
|
1381
|
+
status: r.status,
|
|
1382
|
+
handler: r.handler,
|
|
1383
|
+
...r.wait !== void 0 ? { wait: r.wait } : {},
|
|
1384
|
+
...r.until !== void 0 ? { until: parseInstant(r.until) } : {},
|
|
1385
|
+
...r.calls ? { calls: [...r.calls] } : {}
|
|
1386
|
+
})),
|
|
1387
|
+
mailbox: s.mailbox.map((item) => ({
|
|
1388
|
+
...item.delivery !== void 0 ? { delivery: item.delivery } : {},
|
|
1389
|
+
...item.from !== void 0 ? { from: item.from } : {},
|
|
1390
|
+
message: {
|
|
1391
|
+
name: textOf(field(item.message, "name")),
|
|
1392
|
+
args: listOf(field(item.message, "args")).map((a) => decode(this.#codec, a))
|
|
1393
|
+
}
|
|
1394
|
+
}))
|
|
1395
|
+
})) };
|
|
1327
1396
|
}
|
|
1328
1397
|
settle(callId, s) {
|
|
1329
1398
|
const pending = this.#restored.get(callId);
|
|
@@ -1351,7 +1420,10 @@ var WasmGroup = class {
|
|
|
1351
1420
|
}
|
|
1352
1421
|
/** @internal */
|
|
1353
1422
|
restore(save, o) {
|
|
1354
|
-
for (const l of o.libraries)
|
|
1423
|
+
for (const l of o.libraries) {
|
|
1424
|
+
this.#core.install(this.#session, l);
|
|
1425
|
+
this.#libraries.set(l.name, l);
|
|
1426
|
+
}
|
|
1355
1427
|
this.#session.syncKinds();
|
|
1356
1428
|
this.#restoring = o;
|
|
1357
1429
|
let ok;
|
|
@@ -1684,6 +1756,7 @@ var WasmCore = class {
|
|
|
1684
1756
|
this.#groupCore = {
|
|
1685
1757
|
session: () => this.#session(),
|
|
1686
1758
|
install: (session, library) => this.#install(session, library),
|
|
1759
|
+
recompile: (library, imports) => this.compileLibrary(library, imports, this.#declarations.get(library)),
|
|
1687
1760
|
kind: (name) => this.#kinds.find((k) => k.name === name)
|
|
1688
1761
|
};
|
|
1689
1762
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
import { D as instant, Dt as integerOf, H as num, K as quantity, L as map, N as list, Ot as isInteger, P as listValues, V as nothing, Y as record, Z as requireValue, b as dec, d as bytes, i as ScriptError, it as text, k as isDecimal, l as Value, o as invalidValue, t as HostError, u as bool, x as decimalParts } from "./errors-CNc-xY_9.js";
|
|
3
|
-
import { Ct as expectedOf, Dt as shape, bt as defineCapability, jt as validStaticMessageName, kt as validComputedMessageName, n as ScriptError$1, xt as defineValueCapability } from "./operations-
|
|
4
|
-
import { c as fixed, f as registerStandardChecks, s as costOf } from "./encoding-
|
|
5
|
-
import { n as duplicateHeaderNames, r as fetchAnswerOk, s as encodeJson, t as checkFetch } from "./http-fetch-
|
|
3
|
+
import { Ct as expectedOf, Dt as shape, bt as defineCapability, jt as validStaticMessageName, kt as validComputedMessageName, n as ScriptError$1, xt as defineValueCapability } from "./operations-DrsedOvj.js";
|
|
4
|
+
import { c as fixed, f as registerStandardChecks, s as costOf } from "./encoding-DlMqlP2Y.js";
|
|
5
|
+
import { n as duplicateHeaderNames, r as fetchAnswerOk, s as encodeJson, t as checkFetch } from "./http-fetch-CLAeEXVi.js";
|
|
6
6
|
import { asyncDispose, newDrivenGroup } from "./driver.js";
|
|
7
7
|
//#region src/talk.ts
|
|
8
8
|
const blank = /^[\t ]*$/;
|
package/sha256-9CGf5BS_.js
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//#region src/sha256.ts
|
|
3
|
-
const K = new Uint32Array([
|
|
4
|
-
1116352408,
|
|
5
|
-
1899447441,
|
|
6
|
-
3049323471,
|
|
7
|
-
3921009573,
|
|
8
|
-
961987163,
|
|
9
|
-
1508970993,
|
|
10
|
-
2453635748,
|
|
11
|
-
2870763221,
|
|
12
|
-
3624381080,
|
|
13
|
-
310598401,
|
|
14
|
-
607225278,
|
|
15
|
-
1426881987,
|
|
16
|
-
1925078388,
|
|
17
|
-
2162078206,
|
|
18
|
-
2614888103,
|
|
19
|
-
3248222580,
|
|
20
|
-
3835390401,
|
|
21
|
-
4022224774,
|
|
22
|
-
264347078,
|
|
23
|
-
604807628,
|
|
24
|
-
770255983,
|
|
25
|
-
1249150122,
|
|
26
|
-
1555081692,
|
|
27
|
-
1996064986,
|
|
28
|
-
2554220882,
|
|
29
|
-
2821834349,
|
|
30
|
-
2952996808,
|
|
31
|
-
3210313671,
|
|
32
|
-
3336571891,
|
|
33
|
-
3584528711,
|
|
34
|
-
113926993,
|
|
35
|
-
338241895,
|
|
36
|
-
666307205,
|
|
37
|
-
773529912,
|
|
38
|
-
1294757372,
|
|
39
|
-
1396182291,
|
|
40
|
-
1695183700,
|
|
41
|
-
1986661051,
|
|
42
|
-
2177026350,
|
|
43
|
-
2456956037,
|
|
44
|
-
2730485921,
|
|
45
|
-
2820302411,
|
|
46
|
-
3259730800,
|
|
47
|
-
3345764771,
|
|
48
|
-
3516065817,
|
|
49
|
-
3600352804,
|
|
50
|
-
4094571909,
|
|
51
|
-
275423344,
|
|
52
|
-
430227734,
|
|
53
|
-
506948616,
|
|
54
|
-
659060556,
|
|
55
|
-
883997877,
|
|
56
|
-
958139571,
|
|
57
|
-
1322822218,
|
|
58
|
-
1537002063,
|
|
59
|
-
1747873779,
|
|
60
|
-
1955562222,
|
|
61
|
-
2024104815,
|
|
62
|
-
2227730452,
|
|
63
|
-
2361852424,
|
|
64
|
-
2428436474,
|
|
65
|
-
2756734187,
|
|
66
|
-
3204031479,
|
|
67
|
-
3329325298
|
|
68
|
-
]);
|
|
69
|
-
const rotr = (x, n) => x >>> n | x << 32 - n;
|
|
70
|
-
const initial = [
|
|
71
|
-
1779033703,
|
|
72
|
-
3144134277,
|
|
73
|
-
1013904242,
|
|
74
|
-
2773480762,
|
|
75
|
-
1359893119,
|
|
76
|
-
2600822924,
|
|
77
|
-
528734635,
|
|
78
|
-
1541459225
|
|
79
|
-
];
|
|
80
|
-
/** An incremental SHA-256: `update` with bytes, then `final` once. */
|
|
81
|
-
var Sha256 = class {
|
|
82
|
-
h = new Uint32Array(initial);
|
|
83
|
-
w = /* @__PURE__ */ new Uint32Array(64);
|
|
84
|
-
block = /* @__PURE__ */ new Uint8Array(64);
|
|
85
|
-
blockView = new DataView(this.block.buffer);
|
|
86
|
-
filled = 0;
|
|
87
|
-
length = 0;
|
|
88
|
-
done = false;
|
|
89
|
-
update(bytes) {
|
|
90
|
-
if (this.done) throw new Error("Sha256.update after final");
|
|
91
|
-
this.length += bytes.length;
|
|
92
|
-
let at = 0;
|
|
93
|
-
if (this.filled > 0) {
|
|
94
|
-
const take = Math.min(64 - this.filled, bytes.length);
|
|
95
|
-
this.block.set(bytes.subarray(0, take), this.filled);
|
|
96
|
-
this.filled += take;
|
|
97
|
-
at = take;
|
|
98
|
-
if (this.filled < 64) return this;
|
|
99
|
-
this.compress(this.blockView, 0);
|
|
100
|
-
this.filled = 0;
|
|
101
|
-
}
|
|
102
|
-
const whole = at + Math.floor((bytes.length - at) / 64) * 64;
|
|
103
|
-
if (whole > at) {
|
|
104
|
-
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.length);
|
|
105
|
-
for (; at < whole; at += 64) this.compress(view, at);
|
|
106
|
-
}
|
|
107
|
-
this.block.set(bytes.subarray(at));
|
|
108
|
-
this.filled = bytes.length - at;
|
|
109
|
-
return this;
|
|
110
|
-
}
|
|
111
|
-
/** The 32-byte digest; the hash takes no more input after it. */
|
|
112
|
-
final() {
|
|
113
|
-
if (this.done) throw new Error("Sha256.final twice");
|
|
114
|
-
const length = this.length;
|
|
115
|
-
const tail = new Uint8Array(this.filled < 56 ? 64 : 128);
|
|
116
|
-
tail.set(this.block.subarray(0, this.filled));
|
|
117
|
-
tail[this.filled] = 128;
|
|
118
|
-
const view = new DataView(tail.buffer);
|
|
119
|
-
view.setUint32(tail.length - 8, Math.floor(length / 536870912));
|
|
120
|
-
view.setUint32(tail.length - 4, length * 8 >>> 0);
|
|
121
|
-
for (let at = 0; at < tail.length; at += 64) this.compress(view, at);
|
|
122
|
-
this.done = true;
|
|
123
|
-
const out = /* @__PURE__ */ new Uint8Array(32);
|
|
124
|
-
const outView = new DataView(out.buffer);
|
|
125
|
-
for (let i = 0; i < 8; i++) outView.setUint32(i * 4, this.h[i]);
|
|
126
|
-
return out;
|
|
127
|
-
}
|
|
128
|
-
compress(view, block) {
|
|
129
|
-
const { h, w } = this;
|
|
130
|
-
for (let i = 0; i < 16; i++) w[i] = view.getUint32(block + i * 4);
|
|
131
|
-
for (let i = 16; i < 64; i++) {
|
|
132
|
-
const s0 = rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^ w[i - 15] >>> 3;
|
|
133
|
-
const s1 = rotr(w[i - 2], 17) ^ rotr(w[i - 2], 19) ^ w[i - 2] >>> 10;
|
|
134
|
-
w[i] = w[i - 16] + s0 + w[i - 7] + s1 >>> 0;
|
|
135
|
-
}
|
|
136
|
-
let a = h[0], b = h[1], c = h[2], d = h[3], e = h[4], f = h[5], g = h[6], hh = h[7];
|
|
137
|
-
for (let i = 0; i < 64; i++) {
|
|
138
|
-
const s1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
|
|
139
|
-
const ch = e & f ^ ~e & g;
|
|
140
|
-
const t1 = hh + s1 + ch + K[i] + w[i] >>> 0;
|
|
141
|
-
const t2 = (rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22)) + (a & b ^ a & c ^ b & c) >>> 0;
|
|
142
|
-
hh = g;
|
|
143
|
-
g = f;
|
|
144
|
-
f = e;
|
|
145
|
-
e = d + t1 >>> 0;
|
|
146
|
-
d = c;
|
|
147
|
-
c = b;
|
|
148
|
-
b = a;
|
|
149
|
-
a = t1 + t2 >>> 0;
|
|
150
|
-
}
|
|
151
|
-
h[0] = h[0] + a >>> 0;
|
|
152
|
-
h[1] = h[1] + b >>> 0;
|
|
153
|
-
h[2] = h[2] + c >>> 0;
|
|
154
|
-
h[3] = h[3] + d >>> 0;
|
|
155
|
-
h[4] = h[4] + e >>> 0;
|
|
156
|
-
h[5] = h[5] + f >>> 0;
|
|
157
|
-
h[6] = h[6] + g >>> 0;
|
|
158
|
-
h[7] = h[7] + hh >>> 0;
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
/** The SHA-256 of `bytes`, as 32 bytes. */
|
|
162
|
-
const sha256Bytes = (bytes) => new Sha256().update(bytes).final();
|
|
163
|
-
const sha256 = (input) => {
|
|
164
|
-
const bytes = typeof input === "string" ? new TextEncoder().encode(input) : input;
|
|
165
|
-
return Array.from(sha256Bytes(bytes), (x) => x.toString(16).padStart(2, "0")).join("");
|
|
166
|
-
};
|
|
167
|
-
//#endregion
|
|
168
|
-
export { sha256 as n, sha256Bytes as r, Sha256 as t };
|