nervur 0.22.0 → 0.22.2-3
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/AUTHORING.md +741 -0
- package/KIT-SPEC.md +286 -0
- package/LICENSE +1 -1
- package/NOTICE +6 -2
- package/README.md +97 -424
- package/dist/app/app-ground.d.ts +18 -0
- package/dist/app/app-ground.js +25 -0
- package/dist/app/index.d.ts +2 -0
- package/dist/app/index.js +5 -0
- package/dist/app/native.d.ts +46 -0
- package/dist/app/native.js +101 -0
- package/dist/being/being.d.ts +229 -0
- package/dist/being/being.js +20 -0
- package/dist/being/covers.d.ts +9 -0
- package/dist/being/covers.js +21 -0
- package/dist/being/index.d.ts +3 -0
- package/dist/being/index.js +5 -0
- package/dist/being/need.d.ts +49 -0
- package/dist/being/need.js +33 -0
- package/dist/being/schema.d.ts +100 -0
- package/dist/being/schema.js +132 -0
- package/dist/being/table.d.ts +42 -0
- package/dist/being/table.js +288 -0
- package/dist/bench/bench-ground.d.ts +55 -0
- package/dist/bench/bench-ground.js +101 -0
- package/dist/bench/bench.d.ts +87 -0
- package/dist/bench/bench.js +260 -0
- package/dist/bench/fake-carry.d.ts +32 -0
- package/dist/bench/fake-carry.js +56 -0
- package/dist/bench/fake-clock.d.ts +17 -0
- package/dist/bench/fake-clock.js +34 -0
- package/dist/bench/fake-custody.d.ts +9 -0
- package/dist/bench/fake-custody.js +10 -0
- package/dist/bench/fake-faculty.d.ts +25 -0
- package/dist/bench/fake-faculty.js +48 -0
- package/dist/bench/fake-keys.d.ts +5 -0
- package/dist/bench/fake-keys.js +9 -0
- package/dist/bench/fake-memory.d.ts +14 -0
- package/dist/bench/fake-memory.js +46 -0
- package/dist/bench/fake-network.d.ts +57 -0
- package/dist/bench/fake-network.js +169 -0
- package/dist/bench/index.d.ts +11 -0
- package/dist/bench/index.js +13 -0
- package/dist/bench/seeded.d.ts +11 -0
- package/dist/bench/seeded.js +37 -0
- package/dist/bench/settle.d.ts +2 -0
- package/dist/bench/settle.js +49 -0
- package/dist/bench/stewards.d.ts +17 -0
- package/dist/bench/stewards.js +20 -0
- package/dist/bodies/class-list.d.ts +14 -0
- package/dist/bodies/class-list.js +33 -0
- package/dist/bodies/joined-carry.d.ts +23 -0
- package/dist/bodies/joined-carry.js +42 -0
- package/dist/bodies/noble-crypto.d.ts +22 -0
- package/dist/bodies/noble-crypto.js +88 -0
- package/dist/bodies/seed-keys.d.ts +10 -0
- package/dist/bodies/seed-keys.js +42 -0
- package/dist/bodies/strict-tools.d.ts +10 -0
- package/dist/bodies/strict-tools.js +306 -0
- package/dist/bodies/web-carry.d.ts +65 -0
- package/dist/bodies/web-carry.js +224 -0
- package/dist/bodies/web-clock.d.ts +12 -0
- package/dist/bodies/web-clock.js +33 -0
- package/dist/browser/browser-ground.d.ts +69 -0
- package/dist/browser/browser-ground.js +219 -0
- package/dist/browser/index.d.ts +4 -0
- package/dist/browser/index.js +7 -0
- package/dist/browser/indexeddb-memory.d.ts +17 -0
- package/dist/browser/indexeddb-memory.js +97 -0
- package/dist/browser/locked-custody.d.ts +25 -0
- package/dist/browser/locked-custody.js +89 -0
- package/dist/browser/origin-classes.d.ts +7 -0
- package/dist/browser/origin-classes.js +31 -0
- package/dist/foundation.d.ts +150 -0
- package/dist/foundation.js +4 -0
- package/dist/ground/ground.d.ts +177 -0
- package/dist/ground/ground.js +363 -0
- package/dist/house/crossing.d.ts +37 -0
- package/dist/house/crossing.js +131 -0
- package/dist/house/house.d.ts +80 -0
- package/dist/house/house.js +1753 -0
- package/dist/house/rows-shape.d.ts +103 -0
- package/dist/house/rows-shape.js +12 -0
- package/dist/house/rows.d.ts +27 -0
- package/dist/house/rows.js +168 -0
- package/dist/index.d.ts +29 -1
- package/dist/index.js +25 -14
- package/dist/node/bridge.d.ts +17 -0
- package/dist/node/bridge.js +188 -0
- package/dist/node/cli.js +170 -0
- package/dist/node/custody.d.ts +20 -0
- package/dist/node/custody.js +34 -0
- package/dist/node/file-keys.d.ts +7 -0
- package/dist/node/file-keys.js +30 -0
- package/dist/node/file-memory.d.ts +13 -0
- package/dist/node/file-memory.js +91 -0
- package/dist/node/folder-classes.d.ts +5 -0
- package/dist/node/folder-classes.js +40 -0
- package/dist/node/gone.d.ts +2 -0
- package/dist/node/gone.js +7 -0
- package/dist/node/hand.d.ts +29 -0
- package/dist/node/hand.js +85 -0
- package/dist/node/held-keys.d.ts +14 -0
- package/dist/node/held-keys.js +36 -0
- package/dist/node/http.d.ts +11 -0
- package/dist/node/http.js +90 -0
- package/dist/node/index.d.ts +13 -0
- package/dist/node/index.js +15 -0
- package/dist/node/keychain-keys.d.ts +10 -0
- package/dist/node/keychain-keys.js +51 -0
- package/dist/node/ledger-memory.d.ts +17 -0
- package/dist/node/ledger-memory.js +151 -0
- package/dist/node/lock.d.ts +10 -0
- package/dist/node/lock.js +78 -0
- package/dist/node/node-ground.d.ts +33 -0
- package/dist/node/node-ground.js +147 -0
- package/dist/node/notify.d.ts +1 -0
- package/dist/node/notify.js +18 -0
- package/dist/node/tcp-carry.d.ts +39 -0
- package/dist/node/tcp-carry.js +216 -0
- package/dist/node/websocket.d.ts +6 -0
- package/dist/node/websocket.js +118 -0
- package/dist/quo/frame.d.ts +20 -0
- package/dist/quo/frame.js +48 -0
- package/dist/quo/room.d.ts +154 -0
- package/dist/quo/room.js +362 -0
- package/dist/serve/index.d.ts +27 -0
- package/dist/serve/index.js +55 -0
- package/package.json +49 -47
- package/dist/browser.d.ts +0 -1
- package/dist/browser.js +0 -8
- package/dist/cli.js +0 -16
- package/dist/core/being/being.d.ts +0 -17
- package/dist/core/being/being.js +0 -72
- package/dist/core/being/digest.d.ts +0 -3
- package/dist/core/being/digest.js +0 -17
- package/dist/core/being/faculty.d.ts +0 -10
- package/dist/core/being/faculty.js +0 -77
- package/dist/core/being/index.d.ts +0 -6
- package/dist/core/being/index.js +0 -8
- package/dist/core/being/kind.d.ts +0 -6
- package/dist/core/being/kind.js +0 -34
- package/dist/core/being/types.d.ts +0 -61
- package/dist/core/being/types.js +0 -4
- package/dist/core/being/words.d.ts +0 -13
- package/dist/core/being/words.js +0 -14
- package/dist/core/browser/index.d.ts +0 -37
- package/dist/core/browser/index.js +0 -196
- package/dist/core/browser/worker.d.ts +0 -11
- package/dist/core/browser/worker.js +0 -37
- package/dist/core/cli/command.d.ts +0 -13
- package/dist/core/cli/command.js +0 -330
- package/dist/core/cli/edge.d.ts +0 -7
- package/dist/core/cli/edge.js +0 -79
- package/dist/core/cli/harbor.d.ts +0 -25
- package/dist/core/cli/harbor.js +0 -115
- package/dist/core/contract/index.d.ts +0 -42
- package/dist/core/contract/index.js +0 -34
- package/dist/core/contract/link.d.ts +0 -4
- package/dist/core/contract/link.js +0 -45
- package/dist/core/crypto/aes.d.ts +0 -3
- package/dist/core/crypto/aes.js +0 -24
- package/dist/core/crypto/bytes.d.ts +0 -6
- package/dist/core/crypto/bytes.js +0 -33
- package/dist/core/crypto/ed25519.d.ts +0 -3
- package/dist/core/crypto/ed25519.js +0 -93
- package/dist/core/crypto/hash.d.ts +0 -2
- package/dist/core/crypto/hash.js +0 -11
- package/dist/core/crypto/index.d.ts +0 -7
- package/dist/core/crypto/index.js +0 -10
- package/dist/core/crypto/json.d.ts +0 -8
- package/dist/core/crypto/json.js +0 -250
- package/dist/core/crypto/mlkem.d.ts +0 -12
- package/dist/core/crypto/mlkem.js +0 -36
- package/dist/core/crypto/subtle.d.ts +0 -3
- package/dist/core/crypto/subtle.js +0 -11
- package/dist/core/crypto/x25519.d.ts +0 -2
- package/dist/core/crypto/x25519.js +0 -24
- package/dist/core/edge/index.d.ts +0 -164
- package/dist/core/edge/index.js +0 -739
- package/dist/core/edge/kit.d.ts +0 -2
- package/dist/core/edge/kit.js +0 -2
- package/dist/core/folder/index.d.ts +0 -18
- package/dist/core/folder/index.js +0 -130
- package/dist/core/git/http.d.ts +0 -6
- package/dist/core/git/http.js +0 -102
- package/dist/core/git/index.d.ts +0 -5
- package/dist/core/git/index.js +0 -10
- package/dist/core/git/object.d.ts +0 -40
- package/dist/core/git/object.js +0 -103
- package/dist/core/git/pack.d.ts +0 -9
- package/dist/core/git/pack.js +0 -171
- package/dist/core/git/store.d.ts +0 -23
- package/dist/core/git/store.js +0 -120
- package/dist/core/git/zlib.d.ts +0 -6
- package/dist/core/git/zlib.js +0 -210
- package/dist/core/harbor/carrying.d.ts +0 -51
- package/dist/core/harbor/carrying.js +0 -69
- package/dist/core/harbor/catalogue.d.ts +0 -33
- package/dist/core/harbor/catalogue.js +0 -365
- package/dist/core/harbor/dna.d.ts +0 -13
- package/dist/core/harbor/dna.js +0 -120
- package/dist/core/harbor/dock.d.ts +0 -62
- package/dist/core/harbor/dock.js +0 -381
- package/dist/core/harbor/harbor.d.ts +0 -16
- package/dist/core/harbor/harbor.js +0 -438
- package/dist/core/harbor/index.d.ts +0 -11
- package/dist/core/harbor/index.js +0 -14
- package/dist/core/harbor/memory.d.ts +0 -10
- package/dist/core/harbor/memory.js +0 -25
- package/dist/core/harbor/package.d.ts +0 -20
- package/dist/core/harbor/package.js +0 -172
- package/dist/core/harbor/probe.d.ts +0 -22
- package/dist/core/harbor/probe.js +0 -15
- package/dist/core/harbor/registry.d.ts +0 -15
- package/dist/core/harbor/registry.js +0 -110
- package/dist/core/harbor/root-line.d.ts +0 -7
- package/dist/core/harbor/root-line.js +0 -9
- package/dist/core/harbor/terrain.d.ts +0 -25
- package/dist/core/harbor/terrain.js +0 -28
- package/dist/core/http/index.d.ts +0 -2
- package/dist/core/http/index.js +0 -154
- package/dist/core/http/websocket.d.ts +0 -29
- package/dist/core/http/websocket.js +0 -133
- package/dist/core/line/answer.d.ts +0 -8
- package/dist/core/line/answer.js +0 -60
- package/dist/core/line/frame.d.ts +0 -29
- package/dist/core/line/frame.js +0 -77
- package/dist/core/line/ground.d.ts +0 -3
- package/dist/core/line/ground.js +0 -7
- package/dist/core/line/index.d.ts +0 -4
- package/dist/core/line/index.js +0 -8
- package/dist/core/line/web.d.ts +0 -12
- package/dist/core/line/web.js +0 -117
- package/dist/core/node/index.d.ts +0 -23
- package/dist/core/node/index.js +0 -124
- package/dist/core/pointer/bodies.d.ts +0 -31
- package/dist/core/pointer/bodies.js +0 -118
- package/dist/core/pointer/index.d.ts +0 -2
- package/dist/core/pointer/index.js +0 -4
- package/dist/core/pointer/world.d.ts +0 -45
- package/dist/core/pointer/world.js +0 -106
- package/dist/core/proof/contracts.d.ts +0 -19
- package/dist/core/proof/contracts.js +0 -116
- package/dist/core/proof/expect.d.ts +0 -6
- package/dist/core/proof/expect.js +0 -18
- package/dist/core/proof/index.d.ts +0 -3
- package/dist/core/proof/index.js +0 -14
- package/dist/core/proof/law.d.ts +0 -25
- package/dist/core/proof/law.js +0 -715
- package/dist/core/quo/address.d.ts +0 -19
- package/dist/core/quo/address.js +0 -84
- package/dist/core/quo/door.d.ts +0 -34
- package/dist/core/quo/door.js +0 -174
- package/dist/core/quo/index.d.ts +0 -9
- package/dist/core/quo/index.js +0 -12
- package/dist/core/quo/invitation.d.ts +0 -8
- package/dist/core/quo/invitation.js +0 -19
- package/dist/core/quo/keys.d.ts +0 -40
- package/dist/core/quo/keys.js +0 -79
- package/dist/core/quo/payload.d.ts +0 -15
- package/dist/core/quo/payload.js +0 -55
- package/dist/core/quo/relations.d.ts +0 -40
- package/dist/core/quo/relations.js +0 -33
- package/dist/core/quo/reply.d.ts +0 -13
- package/dist/core/quo/reply.js +0 -35
- package/dist/core/quo/seal.d.ts +0 -42
- package/dist/core/quo/seal.js +0 -78
- package/dist/core/quo/standing.d.ts +0 -39
- package/dist/core/quo/standing.js +0 -90
- package/dist/core/tcp/index.d.ts +0 -27
- package/dist/core/tcp/index.js +0 -209
- package/dist/core/ward/allowance.d.ts +0 -14
- package/dist/core/ward/allowance.js +0 -32
- package/dist/core/ward/cells.d.ts +0 -7
- package/dist/core/ward/cells.js +0 -74
- package/dist/core/ward/house.d.ts +0 -67
- package/dist/core/ward/house.js +0 -473
- package/dist/core/ward/index.d.ts +0 -5
- package/dist/core/ward/index.js +0 -7
- package/dist/core/ward/partition.d.ts +0 -50
- package/dist/core/ward/partition.js +0 -66
- package/dist/core/ward/stance.d.ts +0 -29
- package/dist/core/ward/stance.js +0 -186
- package/dist/core/ward/ward.d.ts +0 -44
- package/dist/core/ward/ward.js +0 -140
- package/dist/core.d.ts +0 -10
- package/dist/core.js +0 -19
- package/dist/defaults/dock/index.d.ts +0 -4
- package/dist/defaults/dock/index.js +0 -11
- package/dist/defaults/index.d.ts +0 -5
- package/dist/defaults/index.js +0 -10
- package/dist/defaults/memory/index.d.ts +0 -12
- package/dist/defaults/memory/index.js +0 -39
- package/dist/defaults/tcp/index.d.ts +0 -16
- package/dist/defaults/tcp/index.js +0 -82
- package/dist/defaults/ward/index.d.ts +0 -4
- package/dist/defaults/ward/index.js +0 -11
- package/dist/defaults/web/index.d.ts +0 -15
- package/dist/defaults/web/index.js +0 -90
- package/dist/edge.d.ts +0 -1
- package/dist/edge.js +0 -9
- package/dist/kit.d.ts +0 -4
- package/dist/kit.js +0 -12
- package/dist/node.d.ts +0 -1
- package/dist/node.js +0 -8
- package/src/browser.ts +0 -10
- package/src/cli.ts +0 -15
- package/src/core/being/being.ts +0 -84
- package/src/core/being/digest.ts +0 -18
- package/src/core/being/faculty.ts +0 -76
- package/src/core/being/index.ts +0 -8
- package/src/core/being/kind.ts +0 -37
- package/src/core/being/types.ts +0 -74
- package/src/core/being/words.ts +0 -31
- package/src/core/browser/index.ts +0 -219
- package/src/core/browser/worker.ts +0 -63
- package/src/core/cli/command.ts +0 -311
- package/src/core/cli/edge.ts +0 -86
- package/src/core/cli/harbor.ts +0 -120
- package/src/core/contract/index.ts +0 -82
- package/src/core/contract/link.ts +0 -58
- package/src/core/crypto/aes.ts +0 -26
- package/src/core/crypto/bytes.ts +0 -37
- package/src/core/crypto/ed25519.ts +0 -92
- package/src/core/crypto/hash.ts +0 -14
- package/src/core/crypto/index.ts +0 -10
- package/src/core/crypto/json.ts +0 -241
- package/src/core/crypto/mlkem.ts +0 -38
- package/src/core/crypto/subtle.ts +0 -13
- package/src/core/crypto/x25519.ts +0 -23
- package/src/core/edge/index.ts +0 -865
- package/src/core/folder/index.ts +0 -137
- package/src/core/git/http.ts +0 -103
- package/src/core/git/index.ts +0 -10
- package/src/core/git/object.ts +0 -116
- package/src/core/git/pack.ts +0 -147
- package/src/core/git/store.ts +0 -122
- package/src/core/git/zlib.ts +0 -197
- package/src/core/harbor/carrying.ts +0 -124
- package/src/core/harbor/catalogue.ts +0 -386
- package/src/core/harbor/dna.ts +0 -116
- package/src/core/harbor/dock.ts +0 -420
- package/src/core/harbor/harbor.ts +0 -433
- package/src/core/harbor/index.ts +0 -14
- package/src/core/harbor/memory.ts +0 -31
- package/src/core/harbor/package.ts +0 -195
- package/src/core/harbor/probe.ts +0 -39
- package/src/core/harbor/registry.ts +0 -107
- package/src/core/harbor/root-line.ts +0 -19
- package/src/core/harbor/terrain.ts +0 -54
- package/src/core/http/index.ts +0 -147
- package/src/core/http/websocket.ts +0 -124
- package/src/core/line/answer.ts +0 -60
- package/src/core/line/frame.ts +0 -83
- package/src/core/line/ground.ts +0 -18
- package/src/core/line/index.ts +0 -8
- package/src/core/line/web.ts +0 -123
- package/src/core/node/index.ts +0 -139
- package/src/core/pointer/bodies.ts +0 -122
- package/src/core/pointer/index.ts +0 -4
- package/src/core/pointer/world.ts +0 -134
- package/src/core/proof/contracts.ts +0 -134
- package/src/core/proof/expect.ts +0 -25
- package/src/core/proof/index.ts +0 -14
- package/src/core/proof/law.ts +0 -742
- package/src/core/quo/address.ts +0 -87
- package/src/core/quo/door.ts +0 -180
- package/src/core/quo/index.ts +0 -12
- package/src/core/quo/invitation.ts +0 -19
- package/src/core/quo/keys.ts +0 -91
- package/src/core/quo/payload.ts +0 -61
- package/src/core/quo/relations.ts +0 -62
- package/src/core/quo/reply.ts +0 -38
- package/src/core/quo/seal.ts +0 -101
- package/src/core/quo/standing.ts +0 -111
- package/src/core/stand/main.ts +0 -20
- package/src/core/stand/stand.ts +0 -259
- package/src/core/tcp/index.ts +0 -227
- package/src/core/ward/allowance.ts +0 -47
- package/src/core/ward/cells.ts +0 -77
- package/src/core/ward/house.ts +0 -524
- package/src/core/ward/index.ts +0 -7
- package/src/core/ward/partition.ts +0 -117
- package/src/core/ward/stance.ts +0 -207
- package/src/core/ward/ward.ts +0 -166
- package/src/core.ts +0 -55
- package/src/defaults/dock/index.ts +0 -12
- package/src/defaults/index.ts +0 -10
- package/src/defaults/memory/index.ts +0 -50
- package/src/defaults/tcp/index.ts +0 -89
- package/src/defaults/ward/index.ts +0 -12
- package/src/defaults/web/index.ts +0 -97
- package/src/edge.ts +0 -11
- package/src/index.ts +0 -18
- package/src/kit.ts +0 -15
- package/src/node.ts +0 -10
- /package/dist/{cli.d.ts → node/cli.d.ts} +0 -0
package/src/core/crypto/json.ts
DELETED
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
// JSON text as the spec's values chapter reads it. Two readers, for two
|
|
3
|
-
// jobs:
|
|
4
|
-
//
|
|
5
|
-
// readObject Quo's reading of a payload, a reply text or an invitation:
|
|
6
|
-
// UTF-8 with no byte order mark, one object, no two own keys
|
|
7
|
-
// of one name, and every field kept as the text it was
|
|
8
|
-
// written in. What is inside a field is held to the grammar
|
|
9
|
-
// alone, at any depth, and read no further.
|
|
10
|
-
//
|
|
11
|
-
// readValue Nervur's reading of a text it hands to a being: the
|
|
12
|
-
// grammar, a nesting bound, no two keys of one name at any
|
|
13
|
-
// depth, no lone surrogate, and no number a double does not
|
|
14
|
-
// hold as written. Anything else is undefined, since null
|
|
15
|
-
// is a value.
|
|
16
|
-
//
|
|
17
|
-
// A runtime's own parser keeps the last of two keys, rounds numbers and
|
|
18
|
-
// mends bad bytes, which is where two kits stop agreeing, so neither reader
|
|
19
|
-
// trusts it with more than the escapes of one string.
|
|
20
|
-
export type Json = null | boolean | number | string | Json[] | { [key: string]: Json };
|
|
21
|
-
|
|
22
|
-
// A field's value exactly as it stood in the text, by its key.
|
|
23
|
-
export type Fields = ReadonlyMap<string, string>;
|
|
24
|
-
|
|
25
|
-
const decoder = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true });
|
|
26
|
-
const NUMBER = /-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/y;
|
|
27
|
-
const ESCAPE = /\\(?:["\\/bfnrt]|u[0-9a-fA-F]{4})/y;
|
|
28
|
-
const LONE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;
|
|
29
|
-
const LITERALS = ['true', 'false', 'null'];
|
|
30
|
-
|
|
31
|
-
const skip = (s: string, at: number): number => {
|
|
32
|
-
while (at < s.length && ' \t\n\r'.includes(s[at]!)) at += 1;
|
|
33
|
-
return at;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
// The end of the string opening at `at`, or -1.
|
|
37
|
-
const stringEnd = (s: string, at: number): number => {
|
|
38
|
-
if (s[at] !== '"') return -1;
|
|
39
|
-
for (at += 1; at < s.length; ) {
|
|
40
|
-
const c = s.charCodeAt(at);
|
|
41
|
-
if (c === 0x22) return at + 1;
|
|
42
|
-
if (c < 0x20) return -1;
|
|
43
|
-
if (c !== 0x5c) {
|
|
44
|
-
at += 1;
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
ESCAPE.lastIndex = at;
|
|
48
|
-
if (!ESCAPE.test(s)) return -1;
|
|
49
|
-
at = ESCAPE.lastIndex;
|
|
50
|
-
}
|
|
51
|
-
return -1;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const scalarEnd = (s: string, at: number): number => {
|
|
55
|
-
if (s[at] === '"') return stringEnd(s, at);
|
|
56
|
-
const literal = LITERALS.find((word) => s.startsWith(word, at));
|
|
57
|
-
if (literal) return at + literal.length;
|
|
58
|
-
NUMBER.lastIndex = at;
|
|
59
|
-
return NUMBER.test(s) ? NUMBER.lastIndex : -1;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
// A key, its colon and the space after it: the start of the key's value, or -1.
|
|
63
|
-
const keyEnd = (s: string, at: number): number => {
|
|
64
|
-
const end = stringEnd(s, at);
|
|
65
|
-
if (end < 0) return -1;
|
|
66
|
-
const colon = skip(s, end);
|
|
67
|
-
return s[colon] === ':' ? skip(s, colon + 1) : -1;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
// The end of the value starting at `at`, held to the grammar at any depth
|
|
71
|
-
// without recursion, or -1.
|
|
72
|
-
const valueEnd = (s: string, at: number): number => {
|
|
73
|
-
const open: string[] = [];
|
|
74
|
-
for (;;) {
|
|
75
|
-
const c = s[at];
|
|
76
|
-
if (c === '{' || c === '[') {
|
|
77
|
-
at = skip(s, at + 1);
|
|
78
|
-
if (s[at] === (c === '{' ? '}' : ']')) at += 1;
|
|
79
|
-
else {
|
|
80
|
-
open.push(c);
|
|
81
|
-
if (c === '{' && (at = keyEnd(s, at)) < 0) return -1;
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
} else if ((at = scalarEnd(s, at)) < 0) return -1;
|
|
85
|
-
for (;;) {
|
|
86
|
-
if (open.length === 0) return at;
|
|
87
|
-
at = skip(s, at);
|
|
88
|
-
const top = open.at(-1);
|
|
89
|
-
if (s[at] === ',') {
|
|
90
|
-
at = skip(s, at + 1);
|
|
91
|
-
if (top === '{' && (at = keyEnd(s, at)) < 0) return -1;
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
if (s[at] !== (top === '{' ? '}' : ']')) return -1;
|
|
95
|
-
open.pop();
|
|
96
|
-
at += 1;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
const text = (input: Uint8Array | string): string | null => {
|
|
102
|
-
if (typeof input === 'string') return input;
|
|
103
|
-
try {
|
|
104
|
-
return decoder.decode(input);
|
|
105
|
-
} catch {
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
export const readObject = (input: Uint8Array | string): Fields | null => {
|
|
111
|
-
const s = text(input);
|
|
112
|
-
if (s === null) return null;
|
|
113
|
-
const fields = new Map<string, string>();
|
|
114
|
-
let at = skip(s, 0);
|
|
115
|
-
if (s[at] !== '{') return null;
|
|
116
|
-
at = skip(s, at + 1);
|
|
117
|
-
if (s[at] === '}') return skip(s, at + 1) === s.length ? fields : null;
|
|
118
|
-
for (;;) {
|
|
119
|
-
const keyStart = at;
|
|
120
|
-
const valueStart = keyEnd(s, at);
|
|
121
|
-
if (valueStart < 0) return null;
|
|
122
|
-
const key = JSON.parse(s.slice(keyStart, stringEnd(s, keyStart))) as string;
|
|
123
|
-
if (fields.has(key)) return null;
|
|
124
|
-
const end = valueEnd(s, valueStart);
|
|
125
|
-
if (end < 0) return null;
|
|
126
|
-
fields.set(key, s.slice(valueStart, end));
|
|
127
|
-
at = skip(s, end);
|
|
128
|
-
if (s[at] === '}') return skip(s, at + 1) === s.length ? fields : null;
|
|
129
|
-
if (s[at] !== ',') return null;
|
|
130
|
-
at = skip(s, at + 1);
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
// A number text a double holds as written: a fraction, or a whole number
|
|
135
|
-
// the double it reads as is exactly, never past the largest double, never
|
|
136
|
-
// a value that rounds to zero, never minus zero.
|
|
137
|
-
const exactNumber = (literal: string): boolean => {
|
|
138
|
-
const [, sign, whole, frac = '', exp = '0'] = /^(-?)(0|[1-9]\d*)(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/.exec(literal)!;
|
|
139
|
-
const v = Number(literal);
|
|
140
|
-
if (!Number.isFinite(v)) return false;
|
|
141
|
-
const digits = (whole! + frac).replace(/^0+/, '');
|
|
142
|
-
if (v === 0) return digits === '' && sign === '';
|
|
143
|
-
const trimmed = digits.replace(/0+$/, '');
|
|
144
|
-
const e = BigInt(exp) - BigInt(frac.length) + BigInt(digits.length - trimmed.length);
|
|
145
|
-
if (e < 0n) return true;
|
|
146
|
-
return BigInt(trimmed) * 10n ** e === (v < 0 ? -BigInt(v) : BigInt(v)) || literal === String(v);
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
const depthOf = (s: string): number => {
|
|
150
|
-
let depth = 0;
|
|
151
|
-
let deepest = 0;
|
|
152
|
-
for (let at = 0; at < s.length; at += 1) {
|
|
153
|
-
const c = s[at];
|
|
154
|
-
if (c === '"') at = stringEnd(s, at) - 1;
|
|
155
|
-
else if (c === '{' || c === '[') deepest = Math.max(deepest, (depth += 1));
|
|
156
|
-
else if (c === '}' || c === ']') depth -= 1;
|
|
157
|
-
}
|
|
158
|
-
return deepest;
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
// Parses a text already held to the grammar and to the depth bound.
|
|
162
|
-
const parse = (s: string): Json => {
|
|
163
|
-
let at = 0;
|
|
164
|
-
const value = (): Json => {
|
|
165
|
-
at = skip(s, at);
|
|
166
|
-
const c = s[at];
|
|
167
|
-
if (c === '{' || c === '[') {
|
|
168
|
-
const object = c === '{';
|
|
169
|
-
const out: Json[] | Record<string, Json> = object ? {} : [];
|
|
170
|
-
at = skip(s, at + 1);
|
|
171
|
-
if (s[at] === (object ? '}' : ']')) {
|
|
172
|
-
at += 1;
|
|
173
|
-
return out;
|
|
174
|
-
}
|
|
175
|
-
for (;;) {
|
|
176
|
-
if (object) {
|
|
177
|
-
const key = str();
|
|
178
|
-
if (Object.hasOwn(out, key)) throw new Error('two keys of one name');
|
|
179
|
-
at = skip(s, at) + 1;
|
|
180
|
-
Object.defineProperty(out, key, { value: value(), enumerable: true, writable: true, configurable: true });
|
|
181
|
-
} else (out as Json[]).push(value());
|
|
182
|
-
at = skip(s, at);
|
|
183
|
-
if (s[at++] !== ',') return out;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
if (c === '"') return str();
|
|
187
|
-
const end = scalarEnd(s, at);
|
|
188
|
-
const literal = s.slice(at, end);
|
|
189
|
-
at = end;
|
|
190
|
-
if (LITERALS.includes(literal)) return JSON.parse(literal) as Json;
|
|
191
|
-
if (!exactNumber(literal)) throw new Error('a number no double holds as written');
|
|
192
|
-
return Number(literal);
|
|
193
|
-
};
|
|
194
|
-
const str = (): string => {
|
|
195
|
-
at = skip(s, at);
|
|
196
|
-
const end = stringEnd(s, at);
|
|
197
|
-
const out = JSON.parse(s.slice(at, end)) as string;
|
|
198
|
-
if (LONE.test(out)) throw new Error('a lone surrogate');
|
|
199
|
-
at = end;
|
|
200
|
-
return out;
|
|
201
|
-
};
|
|
202
|
-
return value();
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
export const readValue = (input: Uint8Array | string, depth: number): Json | undefined => {
|
|
206
|
-
const s = text(input);
|
|
207
|
-
if (s === null) return undefined;
|
|
208
|
-
const start = skip(s, 0);
|
|
209
|
-
const end = valueEnd(s, start);
|
|
210
|
-
if (end < 0 || skip(s, end) !== s.length || depthOf(s) > depth) return undefined;
|
|
211
|
-
try {
|
|
212
|
-
return parse(s);
|
|
213
|
-
} catch {
|
|
214
|
-
return undefined;
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
// A value as JSON text, or undefined for one that JSON would drop, rewrite
|
|
219
|
-
// or refuse: anything but null, a boolean, a finite number other than minus
|
|
220
|
-
// zero, well-formed text, a list with no holes, or a plain object of own
|
|
221
|
-
// string keys, nested no deeper than `depth`, with no cycle.
|
|
222
|
-
export const writeValue = (value: unknown, depth: number): string | undefined => {
|
|
223
|
-
const fits = (v: unknown, room: number, path: Set<object>): boolean => {
|
|
224
|
-
if (v === null || typeof v === 'boolean') return true;
|
|
225
|
-
if (typeof v === 'string') return !LONE.test(v);
|
|
226
|
-
if (typeof v === 'number') return Number.isFinite(v) && !Object.is(v, -0);
|
|
227
|
-
if (typeof v !== 'object' || room === 0 || path.has(v)) return false;
|
|
228
|
-
path.add(v);
|
|
229
|
-
const ok = Array.isArray(v)
|
|
230
|
-
? Object.keys(v).length === v.length && v.every((x) => fits(x, room - 1, path))
|
|
231
|
-
: [Object.prototype, null].includes(Object.getPrototypeOf(v)) &&
|
|
232
|
-
Object.getOwnPropertySymbols(v).length === 0 &&
|
|
233
|
-
Object.entries(Object.getOwnPropertyDescriptors(v)).every(([k, d]) => !LONE.test(k) && d.enumerable === true && 'value' in d && fits(d.value, room - 1, path));
|
|
234
|
-
path.delete(v);
|
|
235
|
-
return ok;
|
|
236
|
-
};
|
|
237
|
-
return fits(value, depth, new Set()) ? JSON.stringify(value) : undefined;
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
// A count number: no sign, no fraction, no exponent, from 1 to 2^53 - 1.
|
|
241
|
-
export const isCount = (literal: string): boolean => /^[1-9]\d{0,15}$/.test(literal) && Number(literal) <= Number.MAX_SAFE_INTEGER;
|
package/src/core/crypto/mlkem.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
// ML-KEM-768 of FIPS 203 encapsulates. Web Crypto has none on every terrain,
|
|
3
|
-
// so it comes from `@noble/post-quantum`.
|
|
4
|
-
import { ml_kem768 } from '@noble/post-quantum/ml-kem.js';
|
|
5
|
-
|
|
6
|
-
export const EK = 1184;
|
|
7
|
-
export const CIPHERTEXT = 1088;
|
|
8
|
-
|
|
9
|
-
export type Lock = { ek: Uint8Array; dk: Uint8Array };
|
|
10
|
-
|
|
11
|
-
// KeyGen_internal(d, z): the lock from sixty-four drawn bytes, d then z.
|
|
12
|
-
export const lockFrom = (d: Uint8Array, z: Uint8Array): Lock => {
|
|
13
|
-
const { publicKey, secretKey } = ml_kem768.keygen(Uint8Array.from([...d, ...z]));
|
|
14
|
-
return { ek: publicKey, dk: secretKey };
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// Encaps_internal(ek, m), or null for an encapsulation key the modulus check
|
|
18
|
-
// of FIPS 203 section 7.2 refuses.
|
|
19
|
-
export const encapsulate = (ek: Uint8Array, m: Uint8Array): { ciphertext: Uint8Array; shared: Uint8Array } | null => {
|
|
20
|
-
if (ek.length !== EK) return null;
|
|
21
|
-
try {
|
|
22
|
-
const { cipherText, sharedSecret } = ml_kem768.encapsulate(ek, m);
|
|
23
|
-
return { ciphertext: cipherText, shared: sharedSecret };
|
|
24
|
-
} catch {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
// Decapsulation is implicit rejection: a ciphertext for another lock gives a
|
|
30
|
-
// shared secret that opens nothing.
|
|
31
|
-
export const decapsulate = (dk: Uint8Array, ciphertext: Uint8Array): Uint8Array | null => {
|
|
32
|
-
if (ciphertext.length !== CIPHERTEXT) return null;
|
|
33
|
-
try {
|
|
34
|
-
return ml_kem768.decapsulate(ciphertext, dk);
|
|
35
|
-
} catch {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
// Web Crypto, read at every use. A page on a plain http origin has `crypto`
|
|
3
|
-
// without `subtle`, and a terrain may install it after this module loads.
|
|
4
|
-
export const subtle = (): SubtleCrypto => {
|
|
5
|
-
const found = globalThis.crypto?.subtle;
|
|
6
|
-
if (!found) throw new Error('this terrain has no crypto.subtle: a ward needs a secure context');
|
|
7
|
-
return found;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export type Bytes = Uint8Array<ArrayBuffer>;
|
|
11
|
-
|
|
12
|
-
// Web Crypto takes a buffer it owns, so every input is copied into one.
|
|
13
|
-
export const own = (bytes: Uint8Array): Bytes => Uint8Array.from(bytes);
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
// X25519 agrees, by `@noble/curves` in every engine, since an engine's Web
|
|
3
|
-
// Crypto may refuse a secret the curve takes. A secret is thirty-two bytes,
|
|
4
|
-
// clamped by the function and never before.
|
|
5
|
-
import { x25519 } from '@noble/curves/ed25519.js';
|
|
6
|
-
import { zero } from './bytes.ts';
|
|
7
|
-
|
|
8
|
-
export const x25519Public = async (secret: Uint8Array): Promise<Uint8Array> => {
|
|
9
|
-
if (secret.length !== 32) throw new TypeError('a secret is thirty-two bytes');
|
|
10
|
-
return x25519.getPublicKey(secret);
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
// The agreement, or null for a public key that takes no seal: one whose
|
|
14
|
-
// agreement is thirty-two zero bytes.
|
|
15
|
-
export const agree = async (secret: Uint8Array, pk: Uint8Array): Promise<Uint8Array | null> => {
|
|
16
|
-
if (pk.length !== 32 || secret.length !== 32) return null;
|
|
17
|
-
try {
|
|
18
|
-
const shared = x25519.getSharedSecret(secret, pk);
|
|
19
|
-
return zero(shared) ? null : shared;
|
|
20
|
-
} catch {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
};
|