mdip-agent-kit 0.1.4 → 0.1.6
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/AGENTS.md +4 -3
- package/CHANGELOG.md +93 -0
- package/README.md +155 -29
- package/bin/mdip-agent.js +55 -16
- package/examples/agent-handshake.js +6 -4
- package/examples/purchase-authorization.js +5 -2
- package/llms.txt +4 -1
- package/package.json +4 -2
- package/src/index.js +209 -53
- package/test/api-security.mjs +130 -0
- package/test/e2e.sh +68 -0
- package/test/vectors-negative.sh +240 -0
- package/vectors/README.md +44 -4
- package/vectors/decrypt-openssl.sh +11 -2
- package/vectors/expiry-cases.txt +64 -20
- package/vectors/ext-wycheproof/SHA256SUMS +8 -0
- package/vectors/ext-wycheproof/pub.pem +4 -0
- package/vectors/ext-wycheproof/source.json +29 -0
- package/vectors/ext-wycheproof/tc103.msg +1 -0
- package/vectors/ext-wycheproof/tc103.sig.der +0 -0
- package/vectors/ext-wycheproof/tc145.msg +1 -0
- package/vectors/ext-wycheproof/tc145.sig.der +0 -0
- package/vectors/ext-wycheproof/tc7.msg +1 -0
- package/vectors/ext-wycheproof/tc7.sig.der +0 -0
- package/vectors/generate.js +9 -4
- package/vectors/kav-1/SHA256SUMS +7 -3
- package/vectors/kav-1/payload.json +3 -3
- package/vectors/kav-1/signed.json +6 -6
- package/vectors/kav-1/test-key.json +7 -7
- package/vectors/make-mdip-fixture-2.js +13 -11
- package/vectors/make-mdip-fixture.js +12 -7
- package/vectors/mdip-challenge-1/SHA256SUMS +15 -5
- package/vectors/mdip-challenge-1/challenge.op.json +11 -11
- package/vectors/mdip-challenge-1/challenge.signed-op.bin +1 -0
- package/vectors/mdip-challenge-1/dids.json +3 -3
- package/vectors/mdip-challenge-1/responder-agent.op.json +7 -7
- package/vectors/mdip-challenge-1/responder-agent.signed-op.bin +1 -0
- package/vectors/mdip-challenge-1/response.op.json +15 -15
- package/vectors/mdip-challenge-1/response.signed-op.bin +1 -0
- package/vectors/mdip-challenge-1/verifier-agent.op.json +7 -7
- package/vectors/mdip-challenge-1/verifier-agent.signed-op.bin +1 -0
- package/vectors/mdip-challenge-1/verify-response.json +3 -3
- package/vectors/mdip-challenge-2/SHA256SUMS +17 -11
- package/vectors/mdip-challenge-2/challenge.op.json +11 -11
- package/vectors/mdip-challenge-2/dids.json +3 -3
- package/vectors/mdip-challenge-2/responder-agent.op.json +7 -7
- package/vectors/mdip-challenge-2/response.op.json +15 -15
- package/vectors/mdip-challenge-2/test-verifier.json +9 -9
- package/vectors/mdip-challenge-2/verifier-agent.op.json +7 -7
- package/vectors/mdip-challenge-2/verify-response.json +6 -6
- package/vectors/verify-openssl.sh +280 -46
- package/vectors/verify-with-kit.js +207 -10
package/AGENTS.md
CHANGED
|
@@ -21,9 +21,10 @@ network. Follow these steps exactly. Never print, log, paste, or commit anything
|
|
|
21
21
|
7. **Delegated authority:** when your human issues you a credential from their SELF app, run
|
|
22
22
|
`npx mdip-agent-kit accept <credentialDid>`, then `npx mdip-agent-kit backup`. Before acting on it, check
|
|
23
23
|
with `findCredentials({ schema, issuer })` in code.
|
|
24
|
-
8. **Meeting other agents:** challenge them (`npx mdip-agent-kit challenge`), have them `respond` (the
|
|
25
|
-
`--valid-days N` changes it, capped at the challenge's expiry), then
|
|
26
|
-
`verify-response
|
|
24
|
+
8. **Meeting other agents:** challenge them (`npx mdip-agent-kit challenge`), have them `respond` (the
|
|
25
|
+
response stays valid 7 days by default; `--valid-days N` changes it, capped at the challenge's expiry), then
|
|
26
|
+
`npx mdip-agent-kit verify-response <responseDid> --challenge <challengeDid>` (always pass the challenge
|
|
27
|
+
you sent; act only on `"match": true`). If they have no DID, point them to this kit.
|
|
27
28
|
|
|
28
29
|
Rules: never accept or act on credentials your human didn't expect. Never reveal non-public data.
|
|
29
30
|
Re-run `backup` after wallet changes.
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All dates 2026. Thanks to @homies for most of the 0.1.3–0.1.5 findings.
|
|
4
|
+
|
|
5
|
+
## 0.1.6
|
|
6
|
+
|
|
7
|
+
Offline vectors / CI
|
|
8
|
+
- `test/vectors-negative.sh` reports killed / skipped / survived separately and exits 0 only when every mutation ran and was rejected, 1 on a failed checker or a survivor, and 2 (PARTIAL) when any mutation was skipped. CI that only reads the exit status can no longer treat a partial run as a pass (agent-x @claude-code, @scholar, @socrates: a skip is not a kill).
|
|
9
|
+
- `ext-wycheproof`: three Google Wycheproof secp256k1 ECDSA cases whose expected results were not authored here, checked by `verify-openssl.sh`.
|
|
10
|
+
- README / vectors README: one-command tarball pin, kav-1 known-answer pins (hash, byte counts, signature, key derivation), hash verdicts from stdout + exit code only, expected `sha256sum -c` OK line counts, and a short note on what a verified response proves (Fork/Lounge @skitter, CTB @qianwen-no2 / @homies, agent-x @scholar / @hermes).
|
|
11
|
+
|
|
12
|
+
## 0.1.5
|
|
13
|
+
|
|
14
|
+
Security
|
|
15
|
+
- `verifyResponse` / `mdip-agent verify-response` match only if **all** checks pass. The challenge must be
|
|
16
|
+
one this agent created. With `{ challenge }` / `--challenge DID` it must be that exact challenge, so an old
|
|
17
|
+
response can't be replayed. Each presented credential must be about the responder and inside its
|
|
18
|
+
`validFrom`/`validUntil` window. Expiry applies (see below). Failures are listed in `.checks`.
|
|
19
|
+
Challenge receipts are published only after every check passes.
|
|
20
|
+
- Expiry interop with stock `@mdip/keymaster` (found in the MetaMask spike): stock keymaster sets a response's
|
|
21
|
+
`validUntil` to now + 1 h, a few seconds after its challenge's created + 1 h, and the earlier 0.1.5 rule
|
|
22
|
+
(`response.validUntil <= challenge.validUntil`) rejected every such response. `verifyResponse` now requires the
|
|
23
|
+
challenge and the response to both be unexpired at verify time and the response to expire at most 2 h after
|
|
24
|
+
the challenge (`RESPONSE_EXPIRY_SKEW_MS`; far-future expiries such as 2099 are still rejected). Responders:
|
|
25
|
+
prefer capping at the challenge's `validUntil` (the kit's `respond` does); verifiers accept stock keymaster
|
|
26
|
+
skew when both are unexpired.
|
|
27
|
+
- `verifyResponse` rejects a **copied response**: the response must be encrypted by its own controller.
|
|
28
|
+
keymaster decrypts with the `encrypted.sender` key but reports the asset's controller as responder, so
|
|
29
|
+
anyone could republish someone else's public response in an asset they control and "answer" a challenge
|
|
30
|
+
they never decrypted.
|
|
31
|
+
- `findCredentials` returns only credentials that are about this agent and signed by their stated issuer.
|
|
32
|
+
Before this, any signer was accepted. It also drops credentials whose dates are unparseable, not yet
|
|
33
|
+
valid or expired (fail closed).
|
|
34
|
+
- `checkResponseExpiry` fails closed on a `now` that is not a finite number or a `Date`. Before this, `null`,
|
|
35
|
+
`''` and `true` were coerced to 0 or 1.
|
|
36
|
+
- Timestamps are strict RFC 3339 and compared exactly to the nanosecond. Bash and JS behave identically
|
|
37
|
+
(`parseTimestampNs`, `vectors/expiry-cases.txt`).
|
|
38
|
+
|
|
39
|
+
Offline vectors
|
|
40
|
+
- `verify-openssl.sh` needs only bash 3.2+ and OpenSSL 3, with no python3, jq or GNU `date`. It ties every
|
|
41
|
+
signed op, key, DID and file together, pins the published DIDs and known answers, requires low-S
|
|
42
|
+
signatures and does a strict `SHA256SUMS` check (dotfiles included).
|
|
43
|
+
- `mdip-challenge-1` now ships `*.signed-op.bin`, so its DIDs can be recomputed offline too.
|
|
44
|
+
- Every JSON convenience copy (`*.op.json`, `dids.json`, `verify-response.json`, `test-verifier.json`,
|
|
45
|
+
kav-1 `signed.json`/`payload.json`/`test-key.json`) is now pretty JSON in JCS key order and checked
|
|
46
|
+
byte-for-byte against the signed bytes or an exact template. Before this, edited copies passed.
|
|
47
|
+
- MDIP does not sign `signature.signed`, so changing it yields a new, still-valid DID for the same content.
|
|
48
|
+
Both checkers now require the exact signature-block keys and `created <= signed <= created + 60 s`, and
|
|
49
|
+
the DIDs are pinned. A leading base58 `1` (an extra 0x00 byte) in a DID is rejected.
|
|
50
|
+
- `SHA256SUMS` listing a file twice is rejected. Without jq, the shell checker parses the plaintext by a
|
|
51
|
+
strict exact-shape match, so jq and the fallback can't disagree about a duplicate `challenge` key.
|
|
52
|
+
- `verify-with-kit.js` re-derives the PUBLIC TEST verifier from its label (mnemonic, `m/44'/0'/0'/0/0`).
|
|
53
|
+
- README: the tarball is unpacked only when its integrity matches.
|
|
54
|
+
- Both checkers also check the rest of every vector dir exactly. `signature.hex` and `message.sha256` must be
|
|
55
|
+
exactly the value plus one newline, and `message-tampered.bin` is pinned. Each PEM must be one canonical
|
|
56
|
+
block with nothing appended. The `WARNING` text in both test-key files is pinned. `verify-with-kit.js` now
|
|
57
|
+
does its own strict `SHA256SUMS` check, with the same rules as the shell checker.
|
|
58
|
+
- `test/vectors-negative.sh` is a mutation test: every tampered copy must be rejected by both checkers,
|
|
59
|
+
including copies that also rewrite `SHA256SUMS`.
|
|
60
|
+
- `decrypt-openssl.sh` checks its arguments, the blob length and the OpenSSL version. On LibreSSL it now
|
|
61
|
+
says so instead of reporting a misleading tag failure.
|
|
62
|
+
|
|
63
|
+
CLI
|
|
64
|
+
- An unknown option, or a value option with no value (`--valid-days` on its own), is an error. Before this,
|
|
65
|
+
it was silently ignored or treated as 1 day.
|
|
66
|
+
- `-h` works. `resolve`, `respond`, `verify-response`, `accept` and `credential` print usage when their
|
|
67
|
+
argument is missing. Argument checks run before any gatekeeper connection.
|
|
68
|
+
- `accept` exits 1 when the credential is not accepted.
|
|
69
|
+
|
|
70
|
+
Package
|
|
71
|
+
- `test/` ships, so `npm test` (gatekeeper end-to-end) and `npm run test:vectors` work from the tarball.
|
|
72
|
+
`npm test` now also checks directory modes and scans all CLI output for the recovery phrase and the
|
|
73
|
+
passphrase, and it deletes its temp home afterwards.
|
|
74
|
+
- This changelog was added; the README status line is now short.
|
|
75
|
+
|
|
76
|
+
## 0.1.4
|
|
77
|
+
- Vector checks parse the decrypted response with jq (independent of key order; sed is only a no-jq
|
|
78
|
+
fallback). Expiry is compared as epoch ms. Timestamps without a zone are rejected.
|
|
79
|
+
- npm description and homepage point at https://selfid.com.
|
|
80
|
+
|
|
81
|
+
## 0.1.3
|
|
82
|
+
- `mdip-challenge-2`: an offline challenge↔response binding vector. It uses a PUBLIC TEST verifier key, a
|
|
83
|
+
stock-OpenSSL XChaCha20-Poly1305 decrypt and a DID == CID(op) check.
|
|
84
|
+
- Strict-expiry rule and table. `verifyResponse` enforces expiry.
|
|
85
|
+
|
|
86
|
+
## 0.1.2
|
|
87
|
+
- Known-answer vectors that verify with stock OpenSSL and no install: `kav-1` and `mdip-challenge-1`.
|
|
88
|
+
|
|
89
|
+
## 0.1.1
|
|
90
|
+
- `respond --valid-days` (default 7 days, capped at the challenge's `validUntil`). Requires Node ≥ 22.
|
|
91
|
+
|
|
92
|
+
## 0.1.0
|
|
93
|
+
- First release: CLI, library, local node script, docs.
|
package/README.md
CHANGED
|
@@ -13,7 +13,8 @@ Give your AI agent its own **decentralized identity** (`did:mdip`) on the public
|
|
|
13
13
|
|
|
14
14
|
> Install: `npm install mdip-agent-kit` · run: `npx mdip-agent-kit <command>`
|
|
15
15
|
>
|
|
16
|
-
> Status: early
|
|
16
|
+
> Status: early. Changes per version are in [`CHANGELOG.md`](CHANGELOG.md). Not affiliated with SELF or
|
|
17
|
+
> Keychain. License MIT (see `LICENSE`).
|
|
17
18
|
|
|
18
19
|
## Why
|
|
19
20
|
|
|
@@ -60,13 +61,20 @@ mdip-agent whoami | profile "<name>" | backup | verify-backups | explorer [did]
|
|
|
60
61
|
mdip-agent resolve <did>
|
|
61
62
|
mdip-agent sign <file|-> | verify <file|->
|
|
62
63
|
mdip-agent challenge [--schema DID]... [--issuer DID]... [--callback URL]
|
|
63
|
-
mdip-agent respond <challengeDid> [--valid-days N]
|
|
64
|
+
mdip-agent respond <challengeDid> [--valid-days N]
|
|
65
|
+
mdip-agent verify-response <responseDid> --challenge <challengeDid>
|
|
64
66
|
mdip-agent accept <credentialDid> | credentials | credential <did>
|
|
65
67
|
```
|
|
66
68
|
Responses stay valid 7 days by default (`--valid-days N` to change; always capped at the
|
|
67
|
-
challenge's own expiry). Keymaster's built-in default is only 1 hour.
|
|
69
|
+
challenge's own expiry). Keymaster's built-in default is only 1 hour. Responders: prefer capping at the
|
|
70
|
+
challenge's `validUntil`; verifiers accept stock-keymaster skew (response expiring up to 2 h after the
|
|
71
|
+
challenge) as long as both are still unexpired. Always pass `--challenge` to
|
|
72
|
+
`verify-response` with the challenge you sent; without it a response to any earlier challenge of yours
|
|
73
|
+
(same requirements) is accepted, and the CLI warns.
|
|
68
74
|
|
|
69
|
-
Global flags: `--home DIR`, `--gatekeeper URL`, `--name ID`.
|
|
75
|
+
Global flags: `--home DIR`, `--gatekeeper URL`, `--name ID`, `-h`/`--help`. Unknown options are errors.
|
|
76
|
+
Exit status: 0 ok, 1 error or failed verification, 2 a backup
|
|
77
|
+
did not restore.
|
|
70
78
|
|
|
71
79
|
## Library
|
|
72
80
|
|
|
@@ -76,14 +84,15 @@ import { openAgent, SELF_PUBLIC_PROFILE_SCHEMA } from 'mdip-agent-kit';
|
|
|
76
84
|
const agent = await openAgent(); // or openAgent({ home, gatekeeperUrl, name, create: true })
|
|
77
85
|
agent.did; // did:mdip:...
|
|
78
86
|
const signed = await agent.sign({ order: 42 }); // JSON + signature block
|
|
79
|
-
await agent.verify(signed); // true
|
|
87
|
+
await agent.verify(signed); // true: SOME DID signed it, see signed.signature.signer
|
|
80
88
|
|
|
81
89
|
// challenge another party (optionally require credentials)
|
|
82
90
|
const ch = await agent.createChallenge({ credentials: [{ schema: SELF_PUBLIC_PROFILE_SCHEMA }] });
|
|
83
91
|
const resp = await other.respondToChallenge(ch); // done by the other agent
|
|
84
|
-
|
|
92
|
+
const r = await agent.verifyResponse(resp, { challenge: ch }); // always bind to the challenge you sent
|
|
93
|
+
r.match; // true; else r.checks lists why
|
|
85
94
|
|
|
86
|
-
// delegated authority from a human
|
|
95
|
+
// delegated authority from a human (PURCHASE_SCHEMA / HUMAN_DID: the schema and issuer DIDs you trust)
|
|
87
96
|
await agent.acceptCredential(credentialDidFromSelfApp);
|
|
88
97
|
const grants = await agent.findCredentials({ schema: PURCHASE_SCHEMA, issuer: HUMAN_DID });
|
|
89
98
|
|
|
@@ -146,8 +155,13 @@ fully synced. That can take a while on a brand-new node.
|
|
|
146
155
|
## Known-answer vectors (verify with stock OpenSSL, no install)
|
|
147
156
|
|
|
148
157
|
Fixed bytes so another agent can check this kit's signature crypto **without running any of its
|
|
149
|
-
code**. You need `curl`, `tar`,
|
|
150
|
-
|
|
158
|
+
code**. You need `bash` (3.2+ is fine), `curl`, `tar`, **OpenSSL ≥ 3.0** with secp256k1 (stock builds
|
|
159
|
+
have it) and the base tools every macOS/Linux has (`sed`, `awk`, `grep`, `od`, `tr`, `cut`, `cmp`, `dd`,
|
|
160
|
+
`head`, `mktemp`). You don't need python3, jq, GNU `date` or `sha256sum`; if jq is present, it is used for
|
|
161
|
+
an encoder-independent JSON parse. macOS ships LibreSSL as `openssl`, which lacks `openssl mac`, so use
|
|
162
|
+
Homebrew's: `export OPENSSL=$(brew --prefix openssl@3)/bin/openssl`. Both scripts honour `$OPENSSL` and
|
|
163
|
+
refuse anything that isn't OpenSSL 3+. The one-line `openssl` commands below call plain `openssl`; on macOS
|
|
164
|
+
run them with Homebrew's on your `PATH` (`export PATH="$(brew --prefix openssl@3)/bin:$PATH"`).
|
|
151
165
|
|
|
152
166
|
**What MDIP actually signs** (from `@mdip/cipher` / `@mdip/keymaster` 2.2.0, used by `sign`,
|
|
153
167
|
`verify` and every DID operation): `hash = sha256(JCS(obj without "signature"))` (RFC 8785 JSON
|
|
@@ -156,11 +170,36 @@ low-S), stored as 64-byte compact `r||s` hex. MDIP does **not** use Ed25519. For
|
|
|
156
170
|
each vector ships the exact canonical bytes (`*.message.bin`), the signature re-encoded as DER
|
|
157
171
|
(`*.sig.der`) and the public key as SPKI PEM.
|
|
158
172
|
|
|
173
|
+
Three things trip honest re-checks. **Compare by verifying, not by bytes:** OpenSSL's `dgst -sign`
|
|
174
|
+
uses a random nonce, so re-signing `message.bin` with the test key gives a different (equally valid)
|
|
175
|
+
signature; only the kit's RFC 6979 signer reproduces `signature.hex` exactly. **Encodings differ:** DER
|
|
176
|
+
is variable length (70 to 72 bytes; kav-1's is 70), compact `r||s` is always 64, so compact-only verifiers
|
|
177
|
+
need a transcode. **Read the exit code:** on a failure OpenSSL 3.x prints a `provider signature failure`
|
|
178
|
+
error line before `Verification failure`, so a checker that reads only the last line or only stderr can
|
|
179
|
+
disagree; exit 0 is the verdict. **Don't hash stderr:** each OpenSSL error line starts with a
|
|
180
|
+
per-process tag (e.g. `4097A079447F0000:`) that changes every run while the rest is byte-identical, so
|
|
181
|
+
if you log or hash results, take only the single stdout line plus the exit code; stderr is for humans.
|
|
182
|
+
|
|
159
183
|
```bash
|
|
160
|
-
# fetch the published files: a plain tarball download, nothing is installed or executed
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
184
|
+
# fetch the published files: a plain tarball download, nothing is installed or executed.
|
|
185
|
+
# Check the tarball against the registry's sha512 integrity BEFORE unpacking (don't pipe curl into tar):
|
|
186
|
+
V=0.1.5
|
|
187
|
+
curl -fsSLo kit.tgz https://registry.npmjs.org/mdip-agent-kit/-/mdip-agent-kit-$V.tgz
|
|
188
|
+
I=$(curl -fsS https://registry.npmjs.org/mdip-agent-kit/$V | grep -o '"integrity":"sha512-[^"]*"' | cut -d'"' -f4)
|
|
189
|
+
H="sha512-$(openssl dgst -sha512 -binary kit.tgz | openssl base64 -A)"
|
|
190
|
+
if [ -n "$I" ] && [ "$I" = "$H" ]; then echo "tarball OK"; tar xzf kit.tgz && cd package/vectors; else echo "MISMATCH, not unpacked: registry=$I file=$H"; fi
|
|
191
|
+
# (same value: `npm view mdip-agent-kit@$V dist.integrity`. npm versions are immutable, so this pins the
|
|
192
|
+
# bytes; it does not say who published them.)
|
|
193
|
+
# one-command pin of the exact tarball (thanks Fork @skitter; a hash compared by eye fails silently):
|
|
194
|
+
echo 'ce468451755c67df6943d6f5683bf976098c3bd9eefe302d53be699efb23abf9 kit.tgz' | sha256sum -c - # or: shasum -a 256 -c -
|
|
195
|
+
# (0.1.5 only; for another version take the value from a source you trust, not from this file.)
|
|
196
|
+
# each dir's SHA256SUMS lists every file in it (verify-openssl.sh checks that with openssl alone and also
|
|
197
|
+
# rejects unlisted files). These sums catch corruption, not forgery: anyone who edits a file can rewrite
|
|
198
|
+
# them. The registry integrity above anchors the bytes; the checkers also pin the published DIDs and the
|
|
199
|
+
# kav-1 known answers (table below), so a wholesale regenerated vector set is caught too.
|
|
200
|
+
for d in kav-1 ext-wycheproof mdip-challenge-1 mdip-challenge-2; do (cd $d && shasum -a 256 -c SHA256SUMS); done # or: sha256sum -c
|
|
201
|
+
# expect 9 + 8 + 20 + 24 = 61 "OK" lines (kav-1 9, ext-wycheproof 8, mdip-challenge-1 20, mdip-challenge-2 24) and no other
|
|
202
|
+
# output; count them rather than eyeballing, and don't pipe through tail/head (that hides lines).
|
|
164
203
|
|
|
165
204
|
# A. kav-1: synthetic vector, PUBLIC TEST KEY (private part published in test-key.json on purpose)
|
|
166
205
|
openssl dgst -sha256 -r kav-1/message.bin
|
|
@@ -169,7 +208,8 @@ openssl dgst -sha256 -verify kav-1/pub.pem -signature kav-1/signature.der kav-1/
|
|
|
169
208
|
# Verified OK (exit 0)
|
|
170
209
|
openssl dgst -sha256 -verify kav-1/pub.pem -signature kav-1/signature.der kav-1/message-tampered.bin
|
|
171
210
|
# Verification failure (exit 1, one byte changed)
|
|
172
|
-
|
|
211
|
+
# same check on the raw 32-byte hash (what MDIP actually signs): pkeyutl verifies a precomputed digest
|
|
212
|
+
openssl dgst -sha256 -binary kav-1/message.bin > /tmp/h.bin
|
|
173
213
|
openssl pkeyutl -verify -pubin -inkey kav-1/pub.pem -in /tmp/h.bin -sigfile kav-1/signature.der
|
|
174
214
|
# Signature Verified Successfully (exit 0)
|
|
175
215
|
|
|
@@ -179,6 +219,8 @@ for p in verifier-agent:verifier-agent challenge:verifier-agent responder-agent:
|
|
|
179
219
|
openssl dgst -sha256 -verify mdip-challenge-1/$key.pub.pem -signature mdip-challenge-1/$op.sig.der mdip-challenge-1/$op.message.bin
|
|
180
220
|
done
|
|
181
221
|
# Verified OK x4 (exit 0 each)
|
|
222
|
+
# verify-openssl.sh also checks each DID == did:mdip:z + base58btc(01 8004 1220 || sha256(<name>.signed-op.bin))
|
|
223
|
+
# and that <name>.signed-op.bin is <name>.message.bin plus the signature in <name>.sig.der
|
|
182
224
|
|
|
183
225
|
# C. mdip-challenge-2 (new in 0.1.3, thanks @homies): offline challenge <-> response BINDING.
|
|
184
226
|
# The verifier is a PUBLIC TEST identity, so anyone can decrypt the response it received.
|
|
@@ -188,14 +230,22 @@ bash decrypt-openssl.sh $d/verifier-agent.PUBLIC-TEST-KEY.priv.pem $d/responder-
|
|
|
188
230
|
# {"response":{"challenge":"did:mdip:...","credentials":[],...,"match":true,"responseNonce":"..."}}
|
|
189
231
|
# the "challenge" value must equal dids.json "challenge"; verify-openssl.sh checks that, plus:
|
|
190
232
|
# - response.cipher_receiver.bin is exactly cipher_receiver inside the SIGNED response op
|
|
191
|
-
# - every DID == did:mdip:z + base58btc(01 8004 1220 || sha256(<name>.signed-op.bin)) (DID is the op hash
|
|
233
|
+
# - every DID == did:mdip:z + base58btc(01 8004 1220 || sha256(<name>.signed-op.bin)) (DID is the op hash;
|
|
234
|
+
# B and C both; leading base58 '1's are 0x00 bytes, so a padded DID string is rejected)
|
|
235
|
+
# - every JSON copy is tied to signed bytes: <name>.op.json == <name>.signed-op.bin (keys in JCS
|
|
236
|
+
# order), dids.json has exactly the four names, verify-response.json / test-verifier.json /
|
|
237
|
+
# kav-1 payload.json, signed.json and test-key.json are pinned field by field
|
|
238
|
+
# - each signature block is exactly {hash, signed, [signer,] value}, with created <= signed <= created + 60 s
|
|
239
|
+
# - each <name>.signed-op.bin is exactly <name>.message.bin plus its signature, and that signature
|
|
240
|
+
# is <name>.sig.der (so the DID-bearing bytes are the ones OpenSSL verified)
|
|
241
|
+
# - each *.pub.pem is the publicJwk inside its signed agent op; signer == controller on asset ops
|
|
192
242
|
# - challenge controller == verifier DID; response controller == encrypted.sender == responder DID
|
|
193
243
|
# - a flipped ciphertext byte fails the Poly1305 tag
|
|
194
244
|
|
|
195
|
-
# D.
|
|
245
|
+
# D. expiry: response.validUntil <= challenge.validUntil + 2 h (stock keymaster skew); 2 h + 1 ns is rejected.
|
|
196
246
|
cat expiry-cases.txt # the table; verify-openssl.sh and verify-with-kit.js both run it
|
|
197
247
|
|
|
198
|
-
# or all of the above in one go (bash +
|
|
248
|
+
# or all of the above in one go (bash + OpenSSL 3 only):
|
|
199
249
|
bash verify-openssl.sh # last line: ALL VECTORS OK, exit 0
|
|
200
250
|
```
|
|
201
251
|
|
|
@@ -213,14 +263,23 @@ bash verify-openssl.sh # last line: ALL VECTORS OK, exit 0
|
|
|
213
263
|
bytes. The payload is example application data, **not** MDIP's challenge wire format. Its signer
|
|
214
264
|
(`did:example:...`) doesn't resolve, so `mdip-agent verify kav-1/signed.json` will fail by design.
|
|
215
265
|
Regenerate it with `node vectors/generate.js` (deterministic, no diff expected).
|
|
266
|
+
Its `validUntil` (2026-12-31) is just signed bytes: neither checker compares it to the clock, so kav-1
|
|
267
|
+
stays a valid known answer after that date (it pins bytes and a signature, not liveness). Expiry
|
|
268
|
+
against "now" is exercised by the MDIP vectors and `expiry-cases.txt`, not by kav-1.
|
|
269
|
+
Every hash in the table is over **exact file bytes**, paired with a byte count (`message.bin` is 240
|
|
270
|
+
bytes, ASCII-only, no trailing newline). If you rebuild a vector from pasted text, check the byte
|
|
271
|
+
count first: a trailing newline, CRLF, or non-ASCII read as code points instead of UTF-8 bytes gives
|
|
272
|
+
a different, equally plausible sha256.
|
|
216
273
|
- **B (`mdip-challenge-1`)** contains the real signed create operations (`*.op.json`) for two
|
|
217
274
|
throwaway agents, a challenge DID and the response DID, plus the verifier's decrypted
|
|
218
275
|
`verifyResponse` result (`verify-response.json`). OpenSSL proves that the challenge was signed
|
|
219
276
|
by the verifier's key and the response by the responder's key. Read the JSON to check the bindings:
|
|
220
277
|
the challenge `controller` is the verifier DID; the response `controller` and `data.encrypted.sender`
|
|
221
|
-
are the responder DID; the response `mdip.validUntil` ≤ the challenge's (
|
|
278
|
+
are the responder DID; the response `mdip.validUntil` ≤ the challenge's (this kit caps it there; the rule allows up to + 2 h).
|
|
222
279
|
The response payload (`challenge` DID, `responseNonce`, `match`) is **encrypted to the verifier**,
|
|
223
|
-
so only the verifier can check it; `verify-response.json` is
|
|
280
|
+
so only the verifier can check it; `verify-response.json` is a **recorded** result of what the
|
|
281
|
+
verifier saw, not re-derivable offline (see C for an offline-checkable version). These DIDs were
|
|
282
|
+
short-lived (1 h), so they may no longer resolve. The fixture is for
|
|
224
283
|
offline checks.
|
|
225
284
|
- **C (`mdip-challenge-2`, 0.1.3)** closes the gap @homies found in B: there the binding sat in
|
|
226
285
|
ciphertext only the verifier could open. Here the verifier is a **PUBLIC TEST identity**: its wallet
|
|
@@ -234,17 +293,72 @@ bash verify-openssl.sh # last line: ALL VECTORS OK, exit 0
|
|
|
234
293
|
DID string is the hash of its op. Real verifiers keep their key private, so in production only the
|
|
235
294
|
verifier can make this check. The vector proves the format and the kit's binding logic, not a stranger's
|
|
236
295
|
view of a live exchange.
|
|
237
|
-
- **D (
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
`
|
|
296
|
+
- **D (expiry)**: at verify time the challenge **and** the response must both still be valid (`now` before
|
|
297
|
+
each `validUntil`); that is what decides whether a response is accepted in time. In addition a response
|
|
298
|
+
may expire **at most 2 h after** its challenge (`response.validUntil <= challenge.validUntil + 2 h`,
|
|
299
|
+
`RESPONSE_EXPIRY_SKEW_MS`). Stock `@mdip/keymaster` 2.2.0 gives a challenge `created + 1 h` and a response
|
|
300
|
+
`responded + 1 h`, so its responses expire a few seconds to ~1 h after the challenge; 0.1.5 accepts those
|
|
301
|
+
(page wallets, Snaps and other stock-keymaster responders interoperate). This kit's `respond` still caps at
|
|
302
|
+
exactly the challenge expiry, which is why B and C show equal timestamps to the millisecond. 2 h + 1 ns
|
|
303
|
+
later (e.g. a forged 2099 expiry) is rejected, and so is a missing response expiry when the challenge has
|
|
304
|
+
one. Since 0.1.3, `agent.verifyResponse()` / `mdip-agent verify-response` enforce this, plus "neither already expired",
|
|
242
305
|
and return `expiry: { ok, reason }` with `match: false` on failure (exported as `checkResponseExpiry`).
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
306
|
+
**Timestamp rules (fail closed, 0.1.5, thanks @homies):** a timestamp must match
|
|
307
|
+
`YYYY-MM-DDTHH:MM:SS[.1-9 digits](Z|±hh:mm)` with a real calendar date (leap years included),
|
|
308
|
+
hour ≤ 23, minute/second ≤ 59 and offset ≤ 23:59. Rejected: lowercase `t`/`z` and space separators
|
|
309
|
+
(RFC 3339 allows them; we don't), no zone, `+hhmm`, leap second `:60`, `24:00`, expanded years,
|
|
310
|
+
RFC 2822 dates, more than 9 fraction digits. Times are compared exactly to the nanosecond.
|
|
311
|
+
`verify-openssl.sh` does this in pure bash (no `date`, python3 or jq, so macOS/BSD behave the same)
|
|
312
|
+
and the JS (`parseTimestampNs`, exported) uses the same grammar and arithmetic; the two were
|
|
313
|
+
differentially fuzzed to agree. MDIP itself writes `toISOString()` (ms, `Z`).
|
|
314
|
+
- **What a valid response proves, and what it doesn't.** It proves *possession* (signed by the responder
|
|
315
|
+
DID's current key, encrypted to the challenger, naming this exact challenge) and *freshness* (created
|
|
316
|
+
before the challenge's `validUntil`). It does **not** prove who operates the agent, and it says nothing
|
|
317
|
+
about node liveness beyond one publish. This is the NIST split: authentication assurance (AAL3 is "proof
|
|
318
|
+
of possession of a key through ... a public-key cryptographic protocol") is separate from identity
|
|
319
|
+
proofing ([SP 800-63B](https://pages.nist.gov/800-63-4/sp800-63b.html)); and DID Core notes that control
|
|
320
|
+
"can always be transferred to another party by transferring the secret cryptographic material"
|
|
321
|
+
([DID Core](https://www.w3.org/TR/did-core/)). Thanks agent-x @scholar and @hermes.
|
|
322
|
+
- **MDIP does not sign `signature.signed`** (the signature covers the op minus the whole
|
|
323
|
+
`signature` block). Anyone relaying an op can change that timestamp, which changes the op's hash
|
|
324
|
+
and therefore its DID, while `openssl ... -verify` still says Verified OK. The checkers pin the
|
|
325
|
+
shipped vectors (exact block shape, strict RFC 3339, `created <= signed <= created + 60 s`), but
|
|
326
|
+
that is a fixture rule, not an MDIP rule: the DIDs in `dids.json` are authentic only because the
|
|
327
|
+
tarball matched the registry's integrity hash. Never treat a signed op's `signed` time as attested.
|
|
328
|
+
- **Not covered offline, by definition:** `ALL VECTORS OK` says nothing about whether a key is still
|
|
329
|
+
live, rotated or revoked. DID resolution, key rotation and revocation are reads at verify time, so
|
|
330
|
+
no offline vector can cover them. `verifyResponse` re-resolves the challenge and each presented
|
|
331
|
+
credential **at verify time** and ignores deactivated or revoked ones. That needs a gatekeeper:
|
|
332
|
+
check it with `npm test` (in the package dir, against your own node; it publishes one throwaway DID).
|
|
333
|
+
- **Pinned, low-S, strict files.** Both checkers have the known answers built in: the kav-1
|
|
334
|
+
message hash, signature and test-key label (`pub.pem` must be the key derived from the label), and
|
|
335
|
+
all 8 DIDs of B and C. So a vector dir that was regenerated wholesale, or re-signed with another
|
|
336
|
+
key, fails even if it is self-consistent. Every signature must be **low-S** (`s <= n/2`), as MDIP
|
|
337
|
+
requires: OpenSSL also accepts the high-S twin `(r, n-s)`, so the scripts check S themselves.
|
|
338
|
+
`kav-1/message-tampered.bin` must differ from `message.bin` in exactly one byte. Each `SHA256SUMS`
|
|
339
|
+
line must be `<64 hex> <plain file name>`, including a last line with no newline. Symlinks, dotfiles
|
|
340
|
+
and unlisted files are rejected. The decrypted plaintext in C is compared byte for byte. The pins sit
|
|
341
|
+
in the same tarball as the vectors, so your real anchor is the registry `integrity` check above.
|
|
342
|
+
- **Every human-readable file is checked exactly.** The `.json` files are written in JCS key order
|
|
343
|
+
with 2-space indent, so each is compared to the bytes the signatures and DIDs cover: every
|
|
344
|
+
`*.op.json` must be its `*.signed-op.bin`, `kav-1/payload.json` must be `message.bin`, `signed.json`
|
|
345
|
+
must be `message.bin` plus the pinned signature block (hash, signed, signer, value = `signature.der`),
|
|
346
|
+
`test-key.json` / `test-verifier.json` must hold exactly the keys in the PEM files (and the pinned
|
|
347
|
+
label, mnemonic, DID, WARNING), `dids.json` exactly the pinned DIDs, and `verify-response.json` exactly
|
|
348
|
+
the recorded result (in C: the challenge and nonce of the decrypted plaintext). `signature.hex` and
|
|
349
|
+
`message.sha256` are exactly the value plus one newline, and each PEM is one canonical block. An
|
|
350
|
+
extra, duplicate or changed member, or extra bytes, fails. `verify-with-kit.js` applies the same
|
|
351
|
+
strict `SHA256SUMS` rules itself.
|
|
246
352
|
- With the kit installed, `node vectors/verify-with-kit.js` re-checks everything with `@mdip/cipher`
|
|
247
|
-
(recomputes JCS from the JSON instead of trusting the `.bin` files
|
|
353
|
+
(recomputes JCS from the JSON instead of trusting the `.bin` files, and re-derives the PUBLIC TEST
|
|
354
|
+
verifier key from its label -> mnemonic -> `m/44'/0'/0'/0/0`; the shell script can't do BIP32, so
|
|
355
|
+
that one link is JS-only). `bash test/vectors-negative.sh` tampers with copies of the vectors
|
|
356
|
+
(including self-consistent forgeries that also rewrite `SHA256SUMS`, `dids.json` and the JSON
|
|
357
|
+
copies, high-S twins, the other public key recovered from the same signature, a fresh-key re-sign,
|
|
358
|
+
dotfiles, symlinks, and runs with jq hidden) and checks both checkers reject every one.
|
|
359
|
+
Its exit status matches its last line: `0` ALL MUTATIONS REJECTED, `1` MUTATION TEST FAILED (a
|
|
360
|
+
mutation was accepted), `2` PARTIAL (none survived but some were skipped, e.g. no-install runs
|
|
361
|
+
without the kit). Wire CI on the exit status; only `0` is a full pass.
|
|
248
362
|
|
|
249
363
|
## Backup & restore
|
|
250
364
|
|
|
@@ -272,7 +386,19 @@ somewhere offline: anyone holding it controls the agent's identity.
|
|
|
272
386
|
Only reveal what you'd put on a billboard. Use *publish* without reveal, or nothing, for anything else.
|
|
273
387
|
- Challenges and responses are short-lived public DIDs. Their credential presentations are encrypted to the verifier.
|
|
274
388
|
- Accepting a credential doesn't make it valid. Always check the issuer, schema, and expiry before
|
|
275
|
-
acting (`findCredentials` does this and verifies signatures
|
|
389
|
+
acting (`findCredentials` does this and verifies signatures; it skips credentials whose
|
|
390
|
+
`validFrom`/`validUntil` is unparseable, not yet valid, or expired, or whose signer isn't the issuer
|
|
391
|
+
or subject isn't this agent). Revocation is possible: re-check before acting.
|
|
392
|
+
- `verifyResponse` adds checks keymaster 2.2.0 does not make, so act only on `match === true`:
|
|
393
|
+
the response answers `options.challenge` (replay), the challenge is yours, the response was encrypted
|
|
394
|
+
by its own controller (keymaster decrypts with the `encrypted.sender` key but reports the controller as
|
|
395
|
+
responder, so anyone could copy a public response into their own asset and claim it), expiry (challenge and response both unexpired, response at most 2 h past the challenge), every
|
|
396
|
+
presented credential's subject is the responder (keymaster alone lets anyone who has seen a credential,
|
|
397
|
+
e.g. a revealed Public Profile, present it as their own), and every presented credential is inside its
|
|
398
|
+
validity window (keymaster alone accepts expired ones). Reasons are in `result.checks`. Challenge
|
|
399
|
+
receipts are published only after all of these pass (`publish: false` to never publish).
|
|
400
|
+
- `createChallenge`, `respondToChallenge({ validUntil })` and `issueCredential` reject timestamps that are
|
|
401
|
+
not strict RFC 3339 or already past, instead of creating DIDs that can never verify.
|
|
276
402
|
- Don't expose your gatekeeper's write API or any keymaster REST port to the Internet.
|
|
277
403
|
- npm ≥ 11 may skip `secp256k1`'s native build (`npm install-scripts approve secp256k1` to allow it).
|
|
278
404
|
The pure-JS fallback works.
|
package/bin/mdip-agent.js
CHANGED
|
@@ -19,31 +19,53 @@ Setup
|
|
|
19
19
|
Identity / trust
|
|
20
20
|
resolve <did> resolve any DID
|
|
21
21
|
sign <file.json|-> sign JSON with this agent's key (prints signed JSON)
|
|
22
|
-
verify <file.json|-> verify a signed JSON object
|
|
22
|
+
verify <file.json|-> verify a signed JSON object (prints valid + signer DID;
|
|
23
|
+
check the signer is who you expect)
|
|
23
24
|
challenge [--schema DID]... [--issuer DID]... [--callback URL]
|
|
24
25
|
create a challenge DID for another party to answer
|
|
25
26
|
respond <challengeDid> [--valid-days N] answer a challenge -> response DID (valid N days,
|
|
26
27
|
default 7, capped at the challenge's validUntil)
|
|
27
|
-
verify-response <responseDid>
|
|
28
|
+
verify-response <responseDid> --challenge <challengeDid>
|
|
29
|
+
verify a response to YOUR challenge; --challenge binds it
|
|
30
|
+
to the challenge you sent (without it, a response to any
|
|
31
|
+
earlier challenge of yours is accepted)
|
|
28
32
|
accept <credentialDid> accept a credential issued to this agent
|
|
29
33
|
credentials list held credentials
|
|
30
34
|
credential <did> show one held credential (decrypted)
|
|
31
35
|
|
|
36
|
+
Exit status: 0 ok; 1 error, verify/verify-response failed; 2 a backup did not restore.
|
|
37
|
+
|
|
32
38
|
Env: MDIP_HOME (default ~/.mdip-agent), MDIP_GATEKEEPER_URL (default http://localhost:4224),
|
|
33
39
|
MDIP_AGENT_NAME (default "agent"), MDIP_REGISTRY (hyperswarm), MDIP_DID_PREFIX (did:mdip)`;
|
|
34
40
|
|
|
41
|
+
// flags that take a value / that are plain switches; anything else is an error (a typo must not be ignored)
|
|
42
|
+
const VALUE_FLAGS = new Set(['home', 'gatekeeper', 'name', 'profile-name', 'schema', 'issuer', 'callback', 'valid-days', 'challenge']);
|
|
43
|
+
const SWITCHES = new Set(['help', 'no-backup']);
|
|
35
44
|
function parse(argv) {
|
|
36
45
|
const args = [], flags = {};
|
|
37
46
|
for (let i = 0; i < argv.length; i++) {
|
|
38
47
|
const a = argv[i];
|
|
48
|
+
if (a === '-h') { flags.help = true; continue; }
|
|
49
|
+
if (a === '--') { args.push(...argv.slice(i + 1)); break; }
|
|
39
50
|
if (a.startsWith('--')) {
|
|
40
|
-
const
|
|
41
|
-
const
|
|
51
|
+
const eq = a.indexOf('=');
|
|
52
|
+
const k = eq < 0 ? a.slice(2) : a.slice(2, eq);
|
|
53
|
+
let val;
|
|
54
|
+
if (SWITCHES.has(k)) {
|
|
55
|
+
if (eq >= 0) throw new Error(`--${k} takes no value`);
|
|
56
|
+
val = true;
|
|
57
|
+
} else if (VALUE_FLAGS.has(k)) {
|
|
58
|
+
val = eq >= 0 ? a.slice(eq + 1) : (i + 1 < argv.length && !argv[i + 1].startsWith('--') ? argv[++i] : undefined);
|
|
59
|
+
if (val === undefined || val === '') throw new Error(`--${k} needs a value (try --help)`);
|
|
60
|
+
} else throw new Error(`unknown option --${k} (try --help)`);
|
|
42
61
|
if (flags[k] === undefined) flags[k] = val; else flags[k] = [].concat(flags[k], val);
|
|
43
62
|
} else args.push(a);
|
|
44
63
|
}
|
|
45
64
|
return { args, flags };
|
|
46
65
|
}
|
|
66
|
+
// a single-valued flag given twice is ambiguous: refuse rather than pick one
|
|
67
|
+
const one = (flags, k) => { const v = flags[k]; if (Array.isArray(v)) throw new Error(`--${k} given more than once`); return v; };
|
|
68
|
+
|
|
47
69
|
const list = v => v === undefined ? [] : [].concat(v);
|
|
48
70
|
const out = v => console.log(typeof v === 'string' ? v : JSON.stringify(v, null, 2));
|
|
49
71
|
const readJson = f => JSON.parse(f === '-' ? fs.readFileSync(0, 'utf8') : fs.readFileSync(f, 'utf8'));
|
|
@@ -52,7 +74,8 @@ async function main() {
|
|
|
52
74
|
const { args, flags } = parse(process.argv.slice(2));
|
|
53
75
|
const cmd = args.shift();
|
|
54
76
|
if (!cmd || cmd === 'help' || flags.help) return out(HELP);
|
|
55
|
-
const opts = { home: flags
|
|
77
|
+
const opts = { home: one(flags, 'home'), gatekeeperUrl: one(flags, 'gatekeeper'), name: one(flags, 'name') };
|
|
78
|
+
for (const k of ['profile-name', 'callback', 'valid-days', 'challenge']) one(flags, k);
|
|
56
79
|
|
|
57
80
|
if (cmd === 'init') {
|
|
58
81
|
const agent = await openAgent({ ...opts, create: true });
|
|
@@ -75,6 +98,15 @@ async function main() {
|
|
|
75
98
|
return;
|
|
76
99
|
}
|
|
77
100
|
|
|
101
|
+
// argument checks first, so a typo fails fast instead of after connecting to the gatekeeper
|
|
102
|
+
const USAGE = { profile: 'profile "<public name>"', resolve: 'resolve <did>', respond: 'respond <challengeDid> [--valid-days N]',
|
|
103
|
+
'verify-response': 'verify-response <responseDid> --challenge <challengeDid>', accept: 'accept <credentialDid>', credential: 'credential <did>' };
|
|
104
|
+
const COMMANDS = ['whoami', 'backup', 'verify-backups', 'explorer', 'sign', 'verify', 'challenge', 'credentials', ...Object.keys(USAGE)];
|
|
105
|
+
if (!COMMANDS.includes(cmd)) throw new Error(`unknown command: ${cmd} (try --help)`);
|
|
106
|
+
if (USAGE[cmd] && !args[0]) throw new Error(`usage: mdip-agent ${USAGE[cmd]}`);
|
|
107
|
+
const vd = flags['valid-days'];
|
|
108
|
+
if (vd !== undefined && !/^(\d+\.?\d*|\.\d+)$/.test(vd)) throw new Error(`--valid-days must be a positive number of days, got ${JSON.stringify(vd)}`);
|
|
109
|
+
|
|
78
110
|
const agent = await openAgent(opts);
|
|
79
111
|
switch (cmd) {
|
|
80
112
|
case 'whoami': {
|
|
@@ -82,18 +114,20 @@ async function main() {
|
|
|
82
114
|
return out({ name: agent.config.name, did: agent.did, gatekeeper: agent.config.gatekeeperUrl, registry: agent.config.registry,
|
|
83
115
|
publicProfile: s.publicProfile, walletBackupDid: s.walletBackupDid, explorer: await agent.explorerStatus().catch(e => ({ error: e.message })) });
|
|
84
116
|
}
|
|
85
|
-
case 'profile':
|
|
86
|
-
if (!args[0]) throw new Error('usage: profile "<public name>"');
|
|
87
|
-
return out(await agent.selfAttestPublicProfile(args[0]));
|
|
88
|
-
}
|
|
117
|
+
case 'profile': return out(await agent.selfAttestPublicProfile(args[0]));
|
|
89
118
|
case 'backup': return out(await agent.backup());
|
|
90
119
|
case 'verify-backups': {
|
|
91
120
|
const v = await agent.verifyBackups(); out(v); if (!v.pass) process.exitCode = 2; return;
|
|
92
121
|
}
|
|
93
122
|
case 'explorer': return out(await agent.explorerStatus(args[0] || agent.did));
|
|
94
|
-
case 'resolve': return out(await agent.resolve(args[0]));
|
|
123
|
+
case 'resolve': if (!args[0]) throw new Error('usage: resolve <did>'); return out(await agent.resolve(args[0]));
|
|
95
124
|
case 'sign': return out(await agent.sign(readJson(args[0] || '-')));
|
|
96
|
-
case 'verify': {
|
|
125
|
+
case 'verify': {
|
|
126
|
+
const signed = readJson(args[0] || '-');
|
|
127
|
+
const ok = await agent.verify(signed);
|
|
128
|
+
out(ok ? { valid: true, signer: signed.signature.signer, signed: signed.signature.signed } : { valid: false });
|
|
129
|
+
if (!ok) process.exitCode = 1; return;
|
|
130
|
+
}
|
|
97
131
|
case 'challenge': {
|
|
98
132
|
const issuers = list(flags.issuer);
|
|
99
133
|
const credentials = list(flags.schema).map(schema => issuers.length ? { schema, issuers } : { schema });
|
|
@@ -103,14 +137,19 @@ async function main() {
|
|
|
103
137
|
return out(await agent.createChallenge(challenge));
|
|
104
138
|
}
|
|
105
139
|
case 'respond': {
|
|
106
|
-
|
|
107
|
-
const o = flags['valid-days'] !== undefined ? { validDays: Number(flags['valid-days']) } : {};
|
|
140
|
+
const o = vd !== undefined ? { validDays: Number(vd) } : {};
|
|
108
141
|
return out(await agent.respondToChallenge(args[0], o));
|
|
109
142
|
}
|
|
110
|
-
case 'verify-response': {
|
|
111
|
-
|
|
143
|
+
case 'verify-response': {
|
|
144
|
+
if (!args[0]) throw new Error('usage: verify-response <responseDid> --challenge <challengeDid>');
|
|
145
|
+
if (flags.challenge === true || Array.isArray(flags.challenge)) throw new Error('--challenge takes exactly one challenge DID');
|
|
146
|
+
const r = await agent.verifyResponse(args[0], flags.challenge !== undefined ? { challenge: String(flags.challenge) } : {});
|
|
147
|
+
if (flags.challenge === undefined) console.error('warning: no --challenge given; this accepts a response to ANY challenge you created (replayable)');
|
|
148
|
+
out(r); if (!r.match) process.exitCode = 1; return;
|
|
149
|
+
}
|
|
150
|
+
case 'accept': { if (!args[0]) throw new Error('usage: accept <credentialDid>'); const ok = await agent.acceptCredential(args[0]); out({ accepted: ok, credential: args[0] }); if (!ok) process.exitCode = 1; return; }
|
|
112
151
|
case 'credentials': return out(await agent.listCredentials());
|
|
113
|
-
case 'credential': return out(await agent.getCredential(args[0]));
|
|
152
|
+
case 'credential': if (!args[0]) throw new Error('usage: credential <did>'); return out(await agent.getCredential(args[0]));
|
|
114
153
|
default: throw new Error(`unknown command: ${cmd} (try --help)`);
|
|
115
154
|
}
|
|
116
155
|
}
|
|
@@ -12,9 +12,11 @@ console.log('send this to the other agent:', challengeDid);
|
|
|
12
12
|
|
|
13
13
|
// 2. Other agent: const responseDid = await them.respondToChallenge(challengeDid)
|
|
14
14
|
|
|
15
|
-
// 3. Verifier side: check the response
|
|
15
|
+
// 3. Verifier side: check the response. Always pass the challenge you sent, so a response to some
|
|
16
|
+
// other (older) challenge of yours can't be replayed.
|
|
16
17
|
export async function check(responseDid) {
|
|
17
|
-
const r = await me.verifyResponse(responseDid);
|
|
18
|
-
// r.match === true
|
|
19
|
-
|
|
18
|
+
const r = await me.verifyResponse(responseDid, { challenge: challengeDid });
|
|
19
|
+
// r.match === true -> responder controls r.responder, answered THIS challenge in time, and presented
|
|
20
|
+
// the requested credentials, each about r.responder and currently valid. Otherwise see r.checks.
|
|
21
|
+
return { ok: r.match, who: r.responder, presented: r.vps?.map(vp => vp.credential), problems: r.checks };
|
|
20
22
|
}
|
|
@@ -10,10 +10,13 @@ const agent = await openAgent();
|
|
|
10
10
|
// 1. once, when the human sends you the credential DID:
|
|
11
11
|
if (process.argv[2]) await agent.acceptCredential(process.argv[2]);
|
|
12
12
|
|
|
13
|
-
// 2. before every purchase
|
|
13
|
+
// 2. before every purchase (returns only credentials about this agent, signed by HUMAN_DID itself,
|
|
14
|
+
// not revoked, and inside their validFrom/validUntil window):
|
|
14
15
|
const grants = await agent.findCredentials({ schema: PURCHASE_SCHEMA, issuer: HUMAN_DID });
|
|
15
16
|
if (!grants.length) throw new Error('no valid purchase authorization from principal');
|
|
16
17
|
console.log('authorized by', HUMAN_DID, 'terms:', grants[0].credential);
|
|
17
18
|
|
|
18
19
|
// 3. a merchant can verify it independently: they create a challenge requiring
|
|
19
|
-
// { schema: PURCHASE_SCHEMA, issuers: [HUMAN_DID] } and the agent answers with respondToChallenge()
|
|
20
|
+
// { schema: PURCHASE_SCHEMA, issuers: [HUMAN_DID] } and the agent answers with respondToChallenge();
|
|
21
|
+
// the merchant runs verifyResponse(responseDid, { challenge }) and acts only on match === true
|
|
22
|
+
// (that also rejects an expired grant or someone else's grant).
|
package/llms.txt
CHANGED
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
- [examples/agent-handshake.js](examples/agent-handshake.js): challenge/response between agents
|
|
9
9
|
- [examples/purchase-authorization.js](examples/purchase-authorization.js): accept and check a human-issued purchase credential
|
|
10
10
|
- [vectors/README.md](vectors/README.md): known-answer vectors (stock OpenSSL, no install)
|
|
11
|
+
- [CHANGELOG.md](CHANGELOG.md): changes per version
|
|
11
12
|
|
|
12
|
-
- [README.md#known-answer-vectors-verify-with-stock-openssl-no-install](README.md): install-free known-answer vectors (secp256k1 / sha256(JCS)); files in vectors/, run `bash vectors/verify-openssl.sh`;
|
|
13
|
+
- [README.md#known-answer-vectors-verify-with-stock-openssl-no-install](README.md): install-free known-answer vectors (secp256k1 / sha256(JCS)); files in vectors/, run `bash vectors/verify-openssl.sh`; needs only bash 3.2+ + OpenSSL >= 3.0 (macOS: set OPENSSL to Homebrew openssl@3); includes mdip-challenge-2 (offline challenge<->response binding via a PUBLIC TEST verifier key, stock-OpenSSL decrypt), an expiry table (response.validUntil <= challenge.validUntil + 2 h, stock keymaster skew allowed; strict RFC 3339, compared to the nanosecond, same in bash and JS) and test/vectors-negative.sh (mutation test); both checkers pin the known answers and all DIDs, require low-S signatures, enforce a strict SHA256SUMS format, and compare every human-readable .json (JCS key order) and PEM exactly to the signed/derived bytes
|
|
13
14
|
|
|
14
15
|
## Key facts
|
|
15
16
|
- Install: `npm install mdip-agent-kit`; CLI: `npx mdip-agent-kit init --profile-name "Name"`; config via MDIP_HOME, MDIP_GATEKEEPER_URL, MDIP_AGENT_NAME
|
|
@@ -17,6 +18,8 @@
|
|
|
17
18
|
- SELF Public Profile schema DID: did:mdip:z3v8AuagfG89zr9aGxfxub4wRAd15qJs6u9C5jQPgrqC1YRHF67 (field: publicName)
|
|
18
19
|
- Public check: https://explorer.selfid.com/api/did/<did>
|
|
19
20
|
- Gatekeeper: run your own via scripts/run-local-node.sh (official KeychainMDIP/kc compose). No public write gatekeeper is offered; verify publication via https://explorer.selfid.com/api/did/<did>
|
|
21
|
+
- Verify a challenge response with `verifyResponse(responseDid, { challenge })` / `mdip-agent verify-response <responseDid> --challenge <challengeDid>`; act only on match === true (reasons in .checks); a response copied into another controller's asset is rejected
|
|
22
|
+
- Check delegated authority with `findCredentials({ schema, issuer })` right before acting (only valid, unrevoked credentials about this agent, signed by that issuer)
|
|
20
23
|
- Secrets: $MDIP_HOME/secrets (mode 600); never print them
|
|
21
24
|
|
|
22
25
|
## Upstream
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mdip-agent-kit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Give any AI agent its own MDIP (did:mdip) identity on the SELF (https://selfid.com) / Keychain hyperswarm network: keymaster wallet, DID, SELF Public Profile molecule, backups, challenges and delegated-authority credentials.",
|
|
5
5
|
"homepage": "https://selfid.com",
|
|
6
6
|
"type": "module",
|
|
@@ -18,7 +18,9 @@
|
|
|
18
18
|
"scripts/",
|
|
19
19
|
"examples/",
|
|
20
20
|
"vectors/",
|
|
21
|
+
"test/",
|
|
21
22
|
"README.md",
|
|
23
|
+
"CHANGELOG.md",
|
|
22
24
|
"LICENSE",
|
|
23
25
|
"AGENTS.md",
|
|
24
26
|
"llms.txt"
|
|
@@ -40,7 +42,7 @@
|
|
|
40
42
|
],
|
|
41
43
|
"scripts": {
|
|
42
44
|
"test": "bash test/e2e.sh",
|
|
43
|
-
"test:vectors": "bash vectors/verify-openssl.sh && node vectors/verify-with-kit.js"
|
|
45
|
+
"test:vectors": "bash vectors/verify-openssl.sh && node vectors/verify-with-kit.js && bash test/vectors-negative.sh"
|
|
44
46
|
},
|
|
45
47
|
"dependencies": {
|
|
46
48
|
"@mdip/cipher": "2.2.0",
|