@atep/core 0.0.1 → 0.1.0-alpha.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/README.md +257 -3
- package/THIRD-PARTY-NOTICES.md +557 -0
- package/dist/index.d.ts +455 -0
- package/dist/index.js +374 -0
- package/dist/wasm/atep_wasm.d.ts +312 -0
- package/dist/wasm/atep_wasm.js +1491 -0
- package/dist/wasm/atep_wasm_bg.wasm +0 -0
- package/dist/wasm/atep_wasm_bg.wasm.d.ts +49 -0
- package/package.json +57 -6
- /package/{LICENSE-APACHE → LICENSE} +0 -0
package/README.md
CHANGED
|
@@ -1,7 +1,261 @@
|
|
|
1
1
|
# @atep/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
ATEP is a quantum-safe trust layer for robots and AI agents. Every signature and key exchange pairs a classical algorithm with a finalized NIST post-quantum standard (Ed25519 with ML-DSA-65, X25519 with ML-KEM-768), and both halves must hold. A robot or agent can identify and verify another offline, with no internet connection, registry or central server: an identity is a hash of public keys, and everything else is checked against cached keys, revocation lists and log checkpoints.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
> **Experimental alpha. Do not rely on this to protect anything of value.** There has been no independent security audit. The wire format may change between releases (the COSE labels are private-use values and the media types are unregistered), and the post-quantum crates underneath are young. "Quantum-safe" means finalized NIST algorithms (FIPS 203 and FIPS 204) in a hybrid construction; it does not mean audited or proven.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
`@atep/core` is the ATEP reference core (Draft 08, `ATEP-1` suite, including `retired`, `successor`, anchors and domain binding) for JavaScript: the Rust
|
|
8
|
+
`atep-core` crate compiled to WebAssembly, with a TypeScript API. One ESM
|
|
9
|
+
package for Node, Bun, Deno and browsers, no framework and no runtime
|
|
10
|
+
dependencies.
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
npm install @atep/core@alpha
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Pre-releases are published under the `alpha` dist-tag, so a plain `npm install @atep/core` does not pick one until a stable release exists. Node 18 or later.
|
|
17
|
+
|
|
18
|
+
A complete example (generate keys, sign, encrypt, verify) is under "Usage" below.
|
|
19
|
+
|
|
20
|
+
Everything cryptographic and every protocol rule comes from the Rust crate
|
|
21
|
+
(RustCrypto: `ed25519-dalek`, `ml-dsa`, `x25519-dalek`, `ml-kem`, `aes-gcm`,
|
|
22
|
+
`hkdf`, `sha2`). The wrapper crate `rust/atep-wasm` only converts between JS
|
|
23
|
+
values and the core types.
|
|
24
|
+
|
|
25
|
+
## Build from the repository
|
|
26
|
+
|
|
27
|
+
The published package ships the built `dist/`. To build from a repository checkout (development, or to audit the build) use the steps below.
|
|
28
|
+
`js/dist/` is gitignored, so a fresh clone always needs `npm run build` before
|
|
29
|
+
the package can be imported.
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
rustup target add wasm32-unknown-unknown
|
|
33
|
+
cargo install wasm-bindgen-cli --version 0.2.129 --locked --no-default-features
|
|
34
|
+
npm ci # in the repository root: npm workspaces (js, mcp, examples), one lockfile
|
|
35
|
+
cd js
|
|
36
|
+
npm run build # cargo (wasm32, release) -> wasm-bindgen -> tsc -> dist/
|
|
37
|
+
npm test # all vectors plus round trip tests, under Node
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The wasm-bindgen CLI version must equal the `wasm-bindgen` crate version in
|
|
41
|
+
`rust/Cargo.lock` (0.2.129 at the time of writing). `npm run build` checks the
|
|
42
|
+
target and the CLI first, reads the required version from `rust/Cargo.lock`,
|
|
43
|
+
and prints the exact install commands if something is missing or mismatched.
|
|
44
|
+
`--no-default-features` is what CI uses: the default feature set pulls in
|
|
45
|
+
`ring`, which needs a C compiler, so without that flag the install fails on
|
|
46
|
+
machines that have none. The CLI is looked up on `PATH` (or `WASM_BINDGEN=/path`).
|
|
47
|
+
If `wasm-opt` is on `PATH` it is applied (saves about 6 percent). On a machine
|
|
48
|
+
without a C compiler also point `CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER`
|
|
49
|
+
at a linker for the build scripts; the wasm32 target itself needs no C compiler
|
|
50
|
+
because all dependencies are pure Rust.
|
|
51
|
+
|
|
52
|
+
The build remaps the cargo, rustup and workspace paths (`--remap-path-prefix`),
|
|
53
|
+
turns debug info off, and drops the wasm name and producers sections, so the
|
|
54
|
+
binary contains no absolute local paths. `scripts/ci/no-local-paths.sh` checks this.
|
|
55
|
+
|
|
56
|
+
Output in `dist/`: `index.js`, `index.d.ts` (generated from `src/index.ts`) and
|
|
57
|
+
`wasm/` (`atep_wasm.js`, `atep_wasm_bg.wasm`, typings).
|
|
58
|
+
|
|
59
|
+
## Size
|
|
60
|
+
|
|
61
|
+
| File | Bytes |
|
|
62
|
+
| --- | --- |
|
|
63
|
+
| `dist/wasm/atep_wasm_bg.wasm` (release, LTO, opt-level 3, no wasm-opt) | 758,345 (741 KiB) |
|
|
64
|
+
| same, gzip -9 | 286,802 (280 KiB) |
|
|
65
|
+
| `wasm-opt -Oz` (optional) | not measured for this build (measured once, on an earlier 657,927 byte build: 613,961) |
|
|
66
|
+
|
|
67
|
+
The Draft 05 exports (log admission rules, domain binding, anchors) grew the binary by 85,964 bytes
|
|
68
|
+
over the Draft 04 build (673,191).
|
|
69
|
+
|
|
70
|
+
## Usage
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
import { init, keygen, sign, encrypt, verify, hexToBytes } from "@atep/core";
|
|
74
|
+
|
|
75
|
+
await init(); // loads the wasm once (Node: from disk, browser: fetch)
|
|
76
|
+
|
|
77
|
+
const alice = keygen(false); // signing keys only
|
|
78
|
+
const bob = keygen(true); // plus X25519 + ML-KEM-768 to receive encrypted envelopes
|
|
79
|
+
|
|
80
|
+
const now = Math.floor(Date.now() / 1000);
|
|
81
|
+
const signed = sign(alice, new TextEncoder().encode("hello"), { issuedAt: now, expiresAt: now + 600 });
|
|
82
|
+
const sealed = encrypt(signed, bob.publicBundle); // tag 96
|
|
83
|
+
|
|
84
|
+
const r = verify(sealed, {}, { recipient: bob, now }); // spec section 10, steps 1 to 10
|
|
85
|
+
if (r.ok) console.log(r.signer, new TextDecoder().decode(hexToBytes(r.payload_hex)));
|
|
86
|
+
else console.log(`rejected at step ${r.step}: ${r.error}`);
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
A rejection is a returned value, `{ok: false, step, error, cause?}`. Exceptions
|
|
90
|
+
are for malformed arguments (bad hex, wrong seed length, bad JSON) and signing
|
|
91
|
+
or encryption failures.
|
|
92
|
+
|
|
93
|
+
Note the protocol rule that a data envelope (`application/atep+cbor`) must be
|
|
94
|
+
encrypted: a bare signed data envelope is refused at step 1. Trust documents
|
|
95
|
+
(attestations, SRLs, checkpoints) may travel signed only.
|
|
96
|
+
|
|
97
|
+
### Verification with a trust policy, attestations and SRLs
|
|
98
|
+
|
|
99
|
+
```js
|
|
100
|
+
const root = keygen(false), agent = keygen(false);
|
|
101
|
+
const att = root.issueAttestation({
|
|
102
|
+
subject: agent.agentId, claim: "operator-of",
|
|
103
|
+
issuedAt: now - 10, expiresAt: now + 86400, data: { operator: "Example Corp" },
|
|
104
|
+
});
|
|
105
|
+
const msg = encrypt(withAttestations(agent.sign(payload, { issuedAt: now }), [att]), bob.publicBundle);
|
|
106
|
+
|
|
107
|
+
const policy = {
|
|
108
|
+
trust: { roots: [root.agentId], rules: [{ claim: "operator-of" }] }, // same format as the Rust CLI policy file
|
|
109
|
+
known_bundles: [root.publicBundle],
|
|
110
|
+
srls: [], // signed revocation lists (hex or bytes)
|
|
111
|
+
attestations: [], // extra attestations known out of band
|
|
112
|
+
seen_nonces: [], // replay set
|
|
113
|
+
};
|
|
114
|
+
const result = bob.verify(msg, policy, now); // result.claims lists each satisfied rule with its chain
|
|
115
|
+
|
|
116
|
+
const srl = root.createSrl({ sequence: 1, issuedAt: now, nextUpdate: now + 3600,
|
|
117
|
+
revoked: [{ attestationId: hexToBytes(result.claims[0].chain[0].id), reason: "withdrawn", revokedAt: now }] });
|
|
118
|
+
bob.verify(msg, { ...policy, srls: [srl] }, now); // {ok: false, step: 9, ...}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
`VerifyPolicy` is the exact `policy` object of the test vectors (`vectors/README.md`).
|
|
122
|
+
|
|
123
|
+
### Retirement and succession (Draft 04)
|
|
124
|
+
|
|
125
|
+
* `policy.attestations` is the local attestation store. Step 8 reads valid `retired`
|
|
126
|
+
attestations from it, so an identity that retired is rejected (`8/signer_revoked`) for
|
|
127
|
+
anything issued at or after its retirement, including attestations checked at step 9.
|
|
128
|
+
* `policy.trust.follow_succession` (boolean, default false): when a rule fails with
|
|
129
|
+
`claim_missing`, a one-hop `successor` attestation is followed. Applies to ATEP-R rules too.
|
|
130
|
+
* `policy.revocations` and `policy.srls` work as before; `srls` are loaded in list order in the
|
|
131
|
+
verifier's own context (earlier lists, `revocations`, `attestations`).
|
|
132
|
+
* `verifySrl(srl, {now, onStale, cached, context})`: `context` is
|
|
133
|
+
`{known_bundles?, attestations?, revocations?, max_skew_secs?}`, the context in which `cached`
|
|
134
|
+
and then `srl` are loaded (steps 1 to 8). A list signed by a retired identity at or after its
|
|
135
|
+
retirement is rejected `8/signer_revoked`. Without `context` nothing is retired or revoked.
|
|
136
|
+
* Not provided: a stateful log (the `log-admission` vectors) and the monitor `successor_chain` alert
|
|
137
|
+
(this package has no log or monitor). `checkAdmission` applies the admission rules to one submission
|
|
138
|
+
(below), which is what the `registry-endpoint` vectors need.
|
|
139
|
+
|
|
140
|
+
### Anchors, chain ids, `require_anchor`, registry endpoints, domain binding (Draft 05)
|
|
141
|
+
|
|
142
|
+
All of these are pure functions of their input (no network, no clock unless `now` is passed) and return
|
|
143
|
+
the result shapes of `vectors/ANCHOR-DISCOVERY-NOTES.md`.
|
|
144
|
+
|
|
145
|
+
```js
|
|
146
|
+
chainIdKind("x-acme-ledger"); // {ok: true, kind: "extension"}
|
|
147
|
+
parseAnchorRecord(payload); // {ok, record} or {ok: false, error: "anchor_record_invalid"}
|
|
148
|
+
encodeAnchorRecord(record); // deterministic CBOR, no block-height key when null
|
|
149
|
+
checkpointHash(checkpointEnvelope, [logId], now); // verifyCheckpoint plus checkpoint_hash, payload_hex
|
|
150
|
+
checkPublishedAnchor(anchorEnvelope, logId, checkpointHashHex, now); // {ok, log, record} or step 1 to 9 rejection
|
|
151
|
+
parseRequireAnchor(policy); // {ok, require_anchor} or {ok: false, error: "policy_invalid"}
|
|
152
|
+
checkAdmission(attestation, { now, log, maxEnvelopeBytes, logged }); // {ok, document} or {ok: false, refusal, ...}
|
|
153
|
+
checkDomainBinding(fixture); // {well_known, dns, outcome, queried}, fetcher answers come from the fixture
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
`verify` already knows the `application/atep-anchor+cbor` media type and the policy member `require_anchor`
|
|
157
|
+
(step 9 refuses with `anchor_not_supported` while a rule exists; a malformed rule makes `verify` throw,
|
|
158
|
+
`parseRequireAnchor` reports it as `policy_invalid`). `checkDomainBinding` takes the answers of a fake
|
|
159
|
+
fetcher; wiring it to real HTTPS and DNS is the caller's job.
|
|
160
|
+
|
|
161
|
+
### API summary
|
|
162
|
+
|
|
163
|
+
| Function | Purpose |
|
|
164
|
+
| --- | --- |
|
|
165
|
+
| `init(source?)`, `initSync(bytes)` | load the wasm; required once |
|
|
166
|
+
| `keygen(withEncryption)`, `Identity.generate`, `Identity.fromSeeds`, `fromSeedsHex`, `fromSecret` | create identities |
|
|
167
|
+
| `identity.agentId`, `.did`, `.publicBundle`, `.agentIdBytes`, `.hasEncryption`, `.exportSecret()`, `.free()` | identity access |
|
|
168
|
+
| `agentId(bundle)`, `parseAgentId(text)` | Agent ID derivation and parsing (`atep:` and `did:atep:`) |
|
|
169
|
+
| `sign(identity, payload, opts)` / `identity.sign` | hybrid Ed25519 + ML-DSA-65 signature, tag 98 |
|
|
170
|
+
| `encrypt(signedEnvelope, recipientBundle)` | hybrid X25519 + ML-KEM-768 with AES-256-GCM, tag 96 |
|
|
171
|
+
| `decrypt(identity, data)` | returns the inner signed envelope (unverified) |
|
|
172
|
+
| `verify(data, policy, {now, recipient})` / `identity.verify` | full verification, policy, chains, SRLs, inclusion proofs, ATEP-R |
|
|
173
|
+
| `view(data)` | JSON debug rendering of any ATEP CBOR object |
|
|
174
|
+
| `identity.issueAttestation(opts)` | issue an attestation |
|
|
175
|
+
| `identity.createSrl(opts)`, `verifySrl(srl, {now, onStale, cached, context})` | revocation lists |
|
|
176
|
+
| `identity.createCheckpoint(opts)`, `verifyCheckpoint`, `verifyInclusion`, `checkConsistency`, `checkSplitView` | transparency log documents |
|
|
177
|
+
| `merkleRoot`, `auditPath`, `submittedFormOf`, `withInclusionProof`, `withAttestations` | log and envelope helpers |
|
|
178
|
+
| `chainIdKind`, `parseAnchorRecord`, `encodeAnchorRecord`, `checkpointHash`, `checkPublishedAnchor` | chain ids, anchor records, checkpoint hash, published anchors |
|
|
179
|
+
| `parseRequireAnchor`, `checkAdmission`, `checkDomainBinding` | `require_anchor` parse, log admission rules for one submission, domain binding over a fixture |
|
|
180
|
+
| `sha256`, `hexToBytes`, `bytesToHex` | utilities |
|
|
181
|
+
|
|
182
|
+
Types are in `dist/index.d.ts`.
|
|
183
|
+
|
|
184
|
+
### Runtimes
|
|
185
|
+
|
|
186
|
+
* Node 18+: tested (Node 25). `init()` reads the wasm next to `index.js`.
|
|
187
|
+
* Browsers: `init()` fetches `new URL("./wasm/atep_wasm_bg.wasm", import.meta.url)`; serve `.wasm` as `application/wasm`. Or pass your own source: `await init(fetch("/path/atep.wasm"))`, a `URL`, or bytes. Smoke page: `examples/smoke.html` (plain JS). Run `npm run smoke` and open http://127.0.0.1:8099/examples/smoke.html. The fetch + streaming instantiate path was exercised from Node against the local server; the page itself has not been opened in a real browser here.
|
|
188
|
+
* Bun and Deno: the package uses only standard ESM, `WebAssembly`, `fetch`, `crypto.getRandomValues` (through wasm-bindgen) and `node:fs/promises` (supported by both); not tested here (neither runtime is installed).
|
|
189
|
+
* Bundlers: the wasm is referenced via `new URL(..., import.meta.url)`; the export `@atep/core/atep_core_bg.wasm` points at the binary.
|
|
190
|
+
|
|
191
|
+
## Secrets and their limits
|
|
192
|
+
|
|
193
|
+
* An `Identity` keeps its seeds only inside wasm linear memory. `atep-core`
|
|
194
|
+
zeroizes them (`ZeroizeOnDrop`) when the object is freed: call `identity.free()`
|
|
195
|
+
(or `using id = ...`). If you forget, they stay in wasm memory until the
|
|
196
|
+
JS garbage collector finalizes the object.
|
|
197
|
+
* Seeds you pass in (`fromSeeds`, `fromSecret`) are zeroized on the wasm side
|
|
198
|
+
after use, but the Uint8Array you passed is yours: `fill(0)` it.
|
|
199
|
+
* `exportSecret()` copies secret material to a JS Uint8Array, which is
|
|
200
|
+
garbage collected memory. Only use it for persistence, wipe the array after.
|
|
201
|
+
* Signing keys are not held in JS strings or objects, but the guarantees stop
|
|
202
|
+
at the platform: JS engines may copy or retain buffers (for example in
|
|
203
|
+
`TextEncoder` or structured clones), wasm memory never shrinks and is not
|
|
204
|
+
locked, swap and core dumps can capture it, and other code in the same
|
|
205
|
+
realm can read the module's memory. This is an in-process software key, not
|
|
206
|
+
an HSM.
|
|
207
|
+
* Passing `recipient_seeds` inside the policy JSON puts seed hex into JS
|
|
208
|
+
strings; pass `recipient: identity` instead.
|
|
209
|
+
* `encryptDeterministic` takes explicit randomness for test vectors only.
|
|
210
|
+
* Randomness comes from `crypto.getRandomValues` (the `getrandom` crate with its
|
|
211
|
+
`wasm_js` backend). The module has no clock: pass `now` explicitly or let the
|
|
212
|
+
wrapper default to `Date.now()`.
|
|
213
|
+
* Verification is not constant time in the places the Rust crate is not; see the
|
|
214
|
+
crates' documentation.
|
|
215
|
+
|
|
216
|
+
## Timings
|
|
217
|
+
|
|
218
|
+
Node 25 on the development machine (WSL2), average over 50 to 100 calls after warm-up, 256 byte payload:
|
|
219
|
+
`node scripts/bench.mjs`.
|
|
220
|
+
|
|
221
|
+
| Operation | Time |
|
|
222
|
+
| --- | --- |
|
|
223
|
+
| `init()` (compile and instantiate) | about 5 ms |
|
|
224
|
+
| `keygen(true)` | 1.7 ms |
|
|
225
|
+
| `sign` (Ed25519 + ML-DSA-65) | 4.5 ms |
|
|
226
|
+
| `encrypt` (X25519 + ML-KEM-768 + AES-GCM) | 0.64 ms |
|
|
227
|
+
| `verify`, signed trust document, steps 1 to 10 | 0.91 ms |
|
|
228
|
+
| `verify`, encrypted envelope (decrypt, then steps 1 to 10) | 1.4 ms |
|
|
229
|
+
| `verify`, encrypted, with one attestation chain and trust policy | 2.6 ms |
|
|
230
|
+
|
|
231
|
+
## Tests
|
|
232
|
+
|
|
233
|
+
`npm test` (node:test) runs, under Node, through the built package:
|
|
234
|
+
|
|
235
|
+
* `test/vectors.test.mjs`: every vector listed in `../vectors/manifest.json`: **432 passed + 5 skipped = 437**.
|
|
236
|
+
The first 200 (identity, signing, encryption, verify-positive/negative, attestation, chain-positive/negative,
|
|
237
|
+
srl, log, atep-r-positive/negative, retired-positive/negative, successor-positive/negative, srl-context,
|
|
238
|
+
log-admission, monitor) and the 236 of Draft 05: checkpoint-hash 9, anchor-record 36, chain-id 30,
|
|
239
|
+
anchor-envelope 13, anchor-media-type 3, require-anchor 27, anchor-not-supported 9, registry-endpoint 26,
|
|
240
|
+
domain-binding 83. The 5 skipped are named and counted in the summary: `log-admission` (4) and `monitor` (1),
|
|
241
|
+
because they need a stateful log or a monitor, which this package does not have. Each vector is checked for
|
|
242
|
+
CBOR hash, JSON view equality with the vector's `.json` (a vector whose `.json` says `not_strict_cbor` has no
|
|
243
|
+
view, and the runner only accepts a failing view for those), and by category: exact bytes for identity,
|
|
244
|
+
signing, encryption and attestation (and for anchor records, decoded and re-encoded); the full expected JSON
|
|
245
|
+
result for every other category. It is the same set of checks as `atep-vectors check` in `rust/`.
|
|
246
|
+
* `test/roundtrip.test.mjs`: two identities exchange an encrypted envelope, tampering, replay and wrong recipient,
|
|
247
|
+
detached payloads, secret export and import, attestation and trust policy, SRL revocation, checkpoint and inclusion proof.
|
|
248
|
+
|
|
249
|
+
## Layout
|
|
250
|
+
|
|
251
|
+
```
|
|
252
|
+
js/
|
|
253
|
+
package.json tsconfig.json
|
|
254
|
+
src/index.ts TypeScript API (src/wasm/ is generated)
|
|
255
|
+
scripts/build.mjs cargo -> wasm-bindgen -> tsc
|
|
256
|
+
scripts/bench.mjs timings
|
|
257
|
+
scripts/serve.mjs static server for the smoke page
|
|
258
|
+
examples/smoke.html browser smoke page, plain JS
|
|
259
|
+
test/ node:test suites
|
|
260
|
+
rust/atep-wasm/ the wasm-bindgen wrapper crate (workspace member)
|
|
261
|
+
```
|