@northtalk/ts 0.8.0 → 0.10.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-B8W4W_e1.d.ts} +1 -1
- package/{checker-Q4w7rLXk.js → checker-hkWO1UbN.js} +2 -2
- package/{core-BBPI6EhG.d.ts → core-Dwec7SRy.d.ts} +1 -1
- package/{debug-s6QIovKS.d.ts → debug-2yfUZYzF.d.ts} +7 -0
- package/debug.d.ts +1 -1
- package/debug.js +1 -1
- package/{driver-D5yrK3Nu.d.ts → driver-CT-ksM-N.d.ts} +1 -1
- package/driver.d.ts +1 -1
- package/driver.js +1 -1
- package/{encoding-B7MCQ4ii.js → encoding-DlMqlP2Y.js} +2 -2
- package/{engine-OL1BveVZ.js → engine-CxcONfhv.js} +6 -6
- package/{engine-Dy-BCoiw.d.ts → engine-DP_lqWfI.d.ts} +2 -2
- package/{errors-VuwK669R.js → errors-CNc-xY_9.js} +1 -1
- package/{group-Ccuqwq12.js → group--dcl0em8.js} +83 -24
- package/{http-fetch--O27xjSW.js → http-fetch-CLAeEXVi.js} +2 -2
- package/http.d.ts +1 -1
- package/http.js +4 -4
- package/index-CBuczWK0.d.ts +9 -0
- package/index.d.ts +6 -12
- package/index.js +15 -15
- package/{lean-BjhQvHyr.js → lean-BtbKWkXA.js} +10 -10
- package/{lean-D6DQfbqH.d.ts → lean-DU_muGpT.d.ts} +134 -5
- package/lean.d.ts +5 -6
- package/lean.js +15 -15
- package/{manifest-BeViDIoy.js → manifest-CRpUahPt.js} +3 -3
- package/message-layer.d.ts +2 -2
- package/message-layer.js +2 -2
- package/notify.d.ts +1 -1
- package/notify.js +1 -1
- package/{objects-q0lnCK-4.d.ts → objects-DoyEohtr.d.ts} +1 -1
- package/{objects-TarIKBL8.js → objects-OKVLH190.js} +1 -1
- package/{operations-BAELnqwf.js → operations-DrsedOvj.js} +116 -13
- package/package.json +1 -1
- package/{peer-capability-B8eKbljR.js → peer-capability-RMdN4OHj.js} +4 -4
- package/peer.d.ts +1 -1
- package/peer.js +4 -4
- package/{readers-BG8g59qS.js → readers-G1lHqrPl.js} +1 -1
- package/{readers-AeB1bJ--.d.ts → readers-IhVpgXkj.d.ts} +1 -1
- package/{request-pump-binary-87klb6sX.js → request-pump-binary-P8m6kLfB.js} +231 -53
- package/{router-DXoJ_2Z4.d.ts → router-2vjYbqx3.d.ts} +2 -2
- package/{router-DXmPA-qi.js → router-C_Fjc2as.js} +5 -5
- package/session.d.ts +2 -2
- package/session.js +23 -22
- package/setup.d.ts +2 -2
- package/setup.js +5 -5
- package/sha256-C5Lqj5U7.js +197 -0
- package/sqlite.d.ts +2 -2
- package/sqlite.js +5 -5
- package/{store-DzpyWjt2.js → store-_af2DPoK.js} +2 -2
- package/{store-capability-CxQJ_Huz.js → store-capability-Db6v_dw9.js} +3 -3
- package/store.d.ts +2 -2
- package/store.js +2 -2
- package/{user-capability-ClYd8Vln.js → user-capability-CzoLN3RK.js} +3 -3
- package/wasm.d.ts +5 -5
- package/wasm.js +88 -48
- package/{inline-grants-DmOdgSoK.js → zone-rules-Cn-f9u_Z.js} +88 -5
- package/manifest-l07K7nW-.d.ts +0 -124
- package/sha256-9CGf5BS_.js +0 -168
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
|
-
import { Dt as integerOf, H as num, L as map, 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-
|
|
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
|
|
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-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 ]*$/;
|
|
@@ -577,4 +577,87 @@ const inlineGrants = (capabilities) => Object.fromEntries(Object.entries(capabil
|
|
|
577
577
|
return [name, defineCapability(name, ops).grant("all", void 0)];
|
|
578
578
|
}));
|
|
579
579
|
//#endregion
|
|
580
|
-
|
|
580
|
+
//#region src/zone-rules.ts
|
|
581
|
+
const SECOND = 1e3;
|
|
582
|
+
const STEP = 21600 * SECOND;
|
|
583
|
+
const formatIn = (zone) => {
|
|
584
|
+
try {
|
|
585
|
+
return new Intl.DateTimeFormat("en-US", {
|
|
586
|
+
timeZone: zone,
|
|
587
|
+
hourCycle: "h23",
|
|
588
|
+
era: "short",
|
|
589
|
+
year: "numeric",
|
|
590
|
+
month: "numeric",
|
|
591
|
+
day: "numeric",
|
|
592
|
+
hour: "numeric",
|
|
593
|
+
minute: "numeric",
|
|
594
|
+
second: "numeric"
|
|
595
|
+
});
|
|
596
|
+
} catch {
|
|
597
|
+
throw new HostError("invalid value", `zoneRules: unknown zone ${zone}`);
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
/** The zone's offset from UTC at `ms`, a whole second, in seconds. */
|
|
601
|
+
const offsetAt = (format, ms) => {
|
|
602
|
+
const parts = {};
|
|
603
|
+
for (const p of format.formatToParts(new Date(ms))) parts[p.type] = p.value;
|
|
604
|
+
const year = parts.era === "BC" ? 1 - Number(parts.year) : Number(parts.year);
|
|
605
|
+
const wall = /* @__PURE__ */ new Date(0);
|
|
606
|
+
wall.setUTCFullYear(year, Number(parts.month) - 1, Number(parts.day));
|
|
607
|
+
wall.setUTCHours(Number(parts.hour), Number(parts.minute), Number(parts.second));
|
|
608
|
+
return (wall.getTime() - ms) / SECOND;
|
|
609
|
+
};
|
|
610
|
+
/** `ms` rounded down to a whole second. */
|
|
611
|
+
const second = (ms) => Math.floor(ms / SECOND) * SECOND;
|
|
612
|
+
const instantOfMs = (ms) => instant(BigInt(ms) * 1000n);
|
|
613
|
+
/**
|
|
614
|
+
* Zone Rules for the IANA zone `zone` from `from` up to `until`, exclusive,
|
|
615
|
+
* as an ordinary map (chapter 7): the offset in effect at `from`, then each
|
|
616
|
+
* Instant in the window where the offset changes. An unknown zone, an empty
|
|
617
|
+
* window, or an offset that isn't a whole number of minutes, as in local mean
|
|
618
|
+
* time before a zone adopted standard time, throws invalid value.
|
|
619
|
+
*/
|
|
620
|
+
const zoneRules = (zone, from, until) => {
|
|
621
|
+
const start = from.getTime();
|
|
622
|
+
const end = until.getTime();
|
|
623
|
+
if (!Number.isFinite(start) || !Number.isFinite(end) || start >= end) throw new HostError("invalid value", "zoneRules: an empty window");
|
|
624
|
+
const format = formatIn(zone);
|
|
625
|
+
const offset = (ms) => {
|
|
626
|
+
const o = offsetAt(format, second(ms));
|
|
627
|
+
if (o % 60 !== 0) throw new HostError("invalid value", `zoneRules: ${zone} is ${o} s from UTC at ${new Date(ms).toISOString()}, not whole minutes`);
|
|
628
|
+
return o;
|
|
629
|
+
};
|
|
630
|
+
const changes = [];
|
|
631
|
+
const change = (at, o) => changes.push(record({
|
|
632
|
+
at: instantOfMs(at),
|
|
633
|
+
offset: quantity(num(o), "s")
|
|
634
|
+
}));
|
|
635
|
+
let current = offset(start);
|
|
636
|
+
change(start, current);
|
|
637
|
+
let at = start;
|
|
638
|
+
const last = second(end - 1);
|
|
639
|
+
while (at < last) {
|
|
640
|
+
const next = Math.min(at + STEP, last);
|
|
641
|
+
if (offset(next) === current) {
|
|
642
|
+
at = next;
|
|
643
|
+
continue;
|
|
644
|
+
}
|
|
645
|
+
let low = second(at);
|
|
646
|
+
let high = next;
|
|
647
|
+
while (high - low > SECOND) {
|
|
648
|
+
const mid = second(low + (high - low) / 2);
|
|
649
|
+
if (offset(mid) === current) low = mid;
|
|
650
|
+
else high = mid;
|
|
651
|
+
}
|
|
652
|
+
current = offset(high);
|
|
653
|
+
change(Math.max(high, start), current);
|
|
654
|
+
at = high;
|
|
655
|
+
}
|
|
656
|
+
return record({
|
|
657
|
+
zone: text(zone),
|
|
658
|
+
until: instantOfMs(end),
|
|
659
|
+
changes: list(...changes)
|
|
660
|
+
});
|
|
661
|
+
};
|
|
662
|
+
//#endregion
|
|
663
|
+
export { httpCapability as a, toValue as c, handlersOf as i, talk as l, inlineGrants as n, sqliteCapability as o, createGroup as r, fromValue as s, zoneRules as t };
|
package/manifest-l07K7nW-.d.ts
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
/// <reference lib="esnext.disposable" />
|
|
2
|
-
import { Fn as Library, J as Value, K as Decimal, _ as LoadOptions, en as Core, ht as ObjectKind, jt as Grant, nn as Script, qt as Shape, tn as Group } from "./debug-s6QIovKS.js";
|
|
3
|
-
import { n as Drive, r as DrivenGroupOptions } from "./driver-D5yrK3Nu.js";
|
|
4
|
-
//#region src/talk.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Dedents NorthTalk source; rejects JS interpolation.
|
|
7
|
-
*
|
|
8
|
-
* Write NorthTalk's own interpolation as `\${…}` and its backticks as `` \` ``.
|
|
9
|
-
* Pass values as Request arguments instead of splicing them into source. The
|
|
10
|
-
* longest whitespace prefix shared by every non-blank line is removed, compared
|
|
11
|
-
* exactly, so tabs and spaces never match each other.
|
|
12
|
-
*/
|
|
13
|
-
declare const talk: (strings: TemplateStringsArray, ...values: unknown[]) => string;
|
|
14
|
-
//#endregion
|
|
15
|
-
//#region src/plain.d.ts
|
|
16
|
-
/** Plain JS data, as `fromValue` writes it (ADR 0119). */
|
|
17
|
-
type PlainValue = null | boolean | string | Decimal | Uint8Array | Value | PlainValue[] | {
|
|
18
|
-
[key: string]: PlainValue;
|
|
19
|
-
} | Map<string, PlainValue>;
|
|
20
|
-
type ToValueOptions = {
|
|
21
|
-
/**
|
|
22
|
-
* `integer` reads safe integers through `num`; `decimal` uses `num` for
|
|
23
|
-
* any JS number. The default refuses JS numbers.
|
|
24
|
-
*/
|
|
25
|
-
numbers?: 'refuse' | 'integer' | 'decimal';
|
|
26
|
-
};
|
|
27
|
-
type FromValueOptions = {
|
|
28
|
-
maps?: 'object' | 'map';
|
|
29
|
-
numbers?: 'decimal' | 'string';
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Plain JS data to a Value by the named constructors (ADR 0119). Anything
|
|
33
|
-
* the table doesn't name, and cyclic data, throws `invalid value`.
|
|
34
|
-
*/
|
|
35
|
-
declare const toValue: (plain: unknown, options?: ToValueOptions) => Value;
|
|
36
|
-
/** A Value as plain JS data (ADR 0119); kinds with no JS form stay Values. */
|
|
37
|
-
declare const fromValue: (v: Value, options?: FromValueOptions) => PlainValue;
|
|
38
|
-
//#endregion
|
|
39
|
-
//#region src/encoding.d.ts
|
|
40
|
-
/**
|
|
41
|
-
* A Message Layer adapter's own spelling of a Function Value or a Text
|
|
42
|
-
* Pattern, which the Value Encoding doesn't hold.
|
|
43
|
-
*/
|
|
44
|
-
type AdapterEncoder = (v: Value) => string;
|
|
45
|
-
declare const encodeValue: (value: Value, adapter?: AdapterEncoder) => string;
|
|
46
|
-
//#endregion
|
|
47
|
-
//#region src/json.d.ts
|
|
48
|
-
/** Read exact decimal digits, NFC strings and insertion-ordered maps. */
|
|
49
|
-
declare const decodeJson: (source: string) => Value;
|
|
50
|
-
/** Compact JSON, with canonical numbers and chapter 7's string escapes. */
|
|
51
|
-
declare const encodeJson: (value: Value) => string;
|
|
52
|
-
//#endregion
|
|
53
|
-
//#region src/handlers.d.ts
|
|
54
|
-
/** Untyped Handler calls accept safe-integer JS numbers and plain data. */
|
|
55
|
-
type Handlers = {
|
|
56
|
-
[name: string]: (...args: (PlainValue | number | bigint)[]) => Promise<PlainValue>;
|
|
57
|
-
};
|
|
58
|
-
/** The Host supplies T without runtime checking of its arguments or results. */
|
|
59
|
-
type ScriptWithHandlers<T = Handlers> = Script & {
|
|
60
|
-
readonly handlers: T;
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* Calls invoke with integer-mode toValue arguments and default fromValue answers.
|
|
64
|
-
* The Script's existing driver or Host Pump loop still runs the Requests.
|
|
65
|
-
* Promise hooks, symbols and non-message properties read as undefined.
|
|
66
|
-
*/
|
|
67
|
-
declare const handlersOf: <T = Handlers>(script: Script) => T;
|
|
68
|
-
//#endregion
|
|
69
|
-
//#region src/group-helper.d.ts
|
|
70
|
-
/** A Group whose driver closes explicitly or at the end of an `await using` scope. */
|
|
71
|
-
type DrivenGroup = Omit<Group, 'load'> & Pick<Drive, 'close' | typeof Symbol.asyncDispose> & {
|
|
72
|
-
load<T = Handlers>(o: LoadOptions): ScriptWithHandlers<T>;
|
|
73
|
-
};
|
|
74
|
-
/** The Zig Host Adapter requires its asynchronously created Core. */
|
|
75
|
-
type CreateGroupOptions = DrivenGroupOptions & {
|
|
76
|
-
core: Core;
|
|
77
|
-
};
|
|
78
|
-
/** Creates a driven Group on the supplied Core; close has the driver's shutdown semantics. */
|
|
79
|
-
declare const createGroup: (o: CreateGroupOptions) => DrivenGroup;
|
|
80
|
-
//#endregion
|
|
81
|
-
//#region src/inline-grants.d.ts
|
|
82
|
-
/** Argument and result types are supplied by the Host, without runtime checking. */
|
|
83
|
-
type InlineFunction = (...args: never[]) => unknown;
|
|
84
|
-
type InlineOperation = InlineFunction | {
|
|
85
|
-
arity?: number;
|
|
86
|
-
fn: InlineFunction;
|
|
87
|
-
} | {
|
|
88
|
-
arity?: number;
|
|
89
|
-
async: InlineFunction;
|
|
90
|
-
maxPendingMs?: number;
|
|
91
|
-
};
|
|
92
|
-
/**
|
|
93
|
-
* Defines one Capability per key and grants all its Operations. Arguments use
|
|
94
|
-
* default fromValue; results use integer-mode toValue. Arity is fn.length unless
|
|
95
|
-
* overridden, including for async functions, which also receive a final signal.
|
|
96
|
-
*/
|
|
97
|
-
declare const inlineGrants: (capabilities: Readonly<Record<string, Readonly<Record<string, InlineOperation>>>>) => Record<string, Grant<void>>;
|
|
98
|
-
//#endregion
|
|
99
|
-
//#region src/manifest.d.ts
|
|
100
|
-
type MessageDecl = {
|
|
101
|
-
args?: readonly Shape[];
|
|
102
|
-
description?: string;
|
|
103
|
-
/** NorthTalk source, each sending this message. */
|
|
104
|
-
examples?: readonly string[];
|
|
105
|
-
name: string;
|
|
106
|
-
receivers?: readonly ObjectKind[];
|
|
107
|
-
};
|
|
108
|
-
type ManifestSpec = {
|
|
109
|
-
grants: Readonly<Record<string, Grant<any>>>;
|
|
110
|
-
kind: string;
|
|
111
|
-
libraries?: readonly Library[];
|
|
112
|
-
messages?: readonly MessageDecl[];
|
|
113
|
-
/** Whether the Host supplies a musical clock (chapter 9, The musical clock). */
|
|
114
|
-
musicalTime?: boolean;
|
|
115
|
-
objectKinds?: readonly ObjectKind[];
|
|
116
|
-
objects?: Readonly<Record<string, ObjectKind>>;
|
|
117
|
-
/** The Owner Kind: one of objectKinds, the kind of `me` for tooling. */
|
|
118
|
-
ownerKind?: ObjectKind;
|
|
119
|
-
version: string;
|
|
120
|
-
};
|
|
121
|
-
/** Chapter 9's deterministic JSON file, ending in LF; never calls the Host. */
|
|
122
|
-
declare const exportManifest: (m: ManifestSpec) => string;
|
|
123
|
-
//#endregion
|
|
124
|
-
export { PlainValue as _, InlineOperation as a, toValue as b, DrivenGroup as c, ScriptWithHandlers as d, handlersOf as f, FromValueOptions as g, encodeValue as h, InlineFunction as i, createGroup as l, encodeJson as m, MessageDecl as n, inlineGrants as o, decodeJson as p, exportManifest as r, CreateGroupOptions as s, ManifestSpec as t, Handlers as u, ToValueOptions as v, talk as x, fromValue as y };
|
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 };
|