mdip-agent-kit 0.1.4 → 0.1.5
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 +86 -0
- package/README.md +130 -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 +232 -0
- package/vectors/README.md +15 -4
- package/vectors/decrypt-openssl.sh +11 -2
- package/vectors/expiry-cases.txt +64 -20
- 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 +269 -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,86 @@
|
|
|
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.5
|
|
6
|
+
|
|
7
|
+
Security
|
|
8
|
+
- `verifyResponse` / `mdip-agent verify-response` match only if **all** checks pass. The challenge must be
|
|
9
|
+
one this agent created. With `{ challenge }` / `--challenge DID` it must be that exact challenge, so an old
|
|
10
|
+
response can't be replayed. Each presented credential must be about the responder and inside its
|
|
11
|
+
`validFrom`/`validUntil` window. Expiry applies (see below). Failures are listed in `.checks`.
|
|
12
|
+
Challenge receipts are published only after every check passes.
|
|
13
|
+
- Expiry interop with stock `@mdip/keymaster` (found in the MetaMask spike): stock keymaster sets a response's
|
|
14
|
+
`validUntil` to now + 1 h, a few seconds after its challenge's created + 1 h, and the earlier 0.1.5 rule
|
|
15
|
+
(`response.validUntil <= challenge.validUntil`) rejected every such response. `verifyResponse` now requires the
|
|
16
|
+
challenge and the response to both be unexpired at verify time and the response to expire at most 2 h after
|
|
17
|
+
the challenge (`RESPONSE_EXPIRY_SKEW_MS`; far-future expiries such as 2099 are still rejected). Responders:
|
|
18
|
+
prefer capping at the challenge's `validUntil` (the kit's `respond` does); verifiers accept stock keymaster
|
|
19
|
+
skew when both are unexpired.
|
|
20
|
+
- `verifyResponse` rejects a **copied response**: the response must be encrypted by its own controller.
|
|
21
|
+
keymaster decrypts with the `encrypted.sender` key but reports the asset's controller as responder, so
|
|
22
|
+
anyone could republish someone else's public response in an asset they control and "answer" a challenge
|
|
23
|
+
they never decrypted.
|
|
24
|
+
- `findCredentials` returns only credentials that are about this agent and signed by their stated issuer.
|
|
25
|
+
Before this, any signer was accepted. It also drops credentials whose dates are unparseable, not yet
|
|
26
|
+
valid or expired (fail closed).
|
|
27
|
+
- `checkResponseExpiry` fails closed on a `now` that is not a finite number or a `Date`. Before this, `null`,
|
|
28
|
+
`''` and `true` were coerced to 0 or 1.
|
|
29
|
+
- Timestamps are strict RFC 3339 and compared exactly to the nanosecond. Bash and JS behave identically
|
|
30
|
+
(`parseTimestampNs`, `vectors/expiry-cases.txt`).
|
|
31
|
+
|
|
32
|
+
Offline vectors
|
|
33
|
+
- `verify-openssl.sh` needs only bash 3.2+ and OpenSSL 3, with no python3, jq or GNU `date`. It ties every
|
|
34
|
+
signed op, key, DID and file together, pins the published DIDs and known answers, requires low-S
|
|
35
|
+
signatures and does a strict `SHA256SUMS` check (dotfiles included).
|
|
36
|
+
- `mdip-challenge-1` now ships `*.signed-op.bin`, so its DIDs can be recomputed offline too.
|
|
37
|
+
- Every JSON convenience copy (`*.op.json`, `dids.json`, `verify-response.json`, `test-verifier.json`,
|
|
38
|
+
kav-1 `signed.json`/`payload.json`/`test-key.json`) is now pretty JSON in JCS key order and checked
|
|
39
|
+
byte-for-byte against the signed bytes or an exact template. Before this, edited copies passed.
|
|
40
|
+
- MDIP does not sign `signature.signed`, so changing it yields a new, still-valid DID for the same content.
|
|
41
|
+
Both checkers now require the exact signature-block keys and `created <= signed <= created + 60 s`, and
|
|
42
|
+
the DIDs are pinned. A leading base58 `1` (an extra 0x00 byte) in a DID is rejected.
|
|
43
|
+
- `SHA256SUMS` listing a file twice is rejected. Without jq, the shell checker parses the plaintext by a
|
|
44
|
+
strict exact-shape match, so jq and the fallback can't disagree about a duplicate `challenge` key.
|
|
45
|
+
- `verify-with-kit.js` re-derives the PUBLIC TEST verifier from its label (mnemonic, `m/44'/0'/0'/0/0`).
|
|
46
|
+
- README: the tarball is unpacked only when its integrity matches.
|
|
47
|
+
- Both checkers also check the rest of every vector dir exactly. `signature.hex` and `message.sha256` must be
|
|
48
|
+
exactly the value plus one newline, and `message-tampered.bin` is pinned. Each PEM must be one canonical
|
|
49
|
+
block with nothing appended. The `WARNING` text in both test-key files is pinned. `verify-with-kit.js` now
|
|
50
|
+
does its own strict `SHA256SUMS` check, with the same rules as the shell checker.
|
|
51
|
+
- `test/vectors-negative.sh` is a mutation test: every tampered copy must be rejected by both checkers,
|
|
52
|
+
including copies that also rewrite `SHA256SUMS`.
|
|
53
|
+
- `decrypt-openssl.sh` checks its arguments, the blob length and the OpenSSL version. On LibreSSL it now
|
|
54
|
+
says so instead of reporting a misleading tag failure.
|
|
55
|
+
|
|
56
|
+
CLI
|
|
57
|
+
- An unknown option, or a value option with no value (`--valid-days` on its own), is an error. Before this,
|
|
58
|
+
it was silently ignored or treated as 1 day.
|
|
59
|
+
- `-h` works. `resolve`, `respond`, `verify-response`, `accept` and `credential` print usage when their
|
|
60
|
+
argument is missing. Argument checks run before any gatekeeper connection.
|
|
61
|
+
- `accept` exits 1 when the credential is not accepted.
|
|
62
|
+
|
|
63
|
+
Package
|
|
64
|
+
- `test/` ships, so `npm test` (gatekeeper end-to-end) and `npm run test:vectors` work from the tarball.
|
|
65
|
+
`npm test` now also checks directory modes and scans all CLI output for the recovery phrase and the
|
|
66
|
+
passphrase, and it deletes its temp home afterwards.
|
|
67
|
+
- This changelog was added; the README status line is now short.
|
|
68
|
+
|
|
69
|
+
## 0.1.4
|
|
70
|
+
- Vector checks parse the decrypted response with jq (independent of key order; sed is only a no-jq
|
|
71
|
+
fallback). Expiry is compared as epoch ms. Timestamps without a zone are rejected.
|
|
72
|
+
- npm description and homepage point at https://selfid.com.
|
|
73
|
+
|
|
74
|
+
## 0.1.3
|
|
75
|
+
- `mdip-challenge-2`: an offline challenge↔response binding vector. It uses a PUBLIC TEST verifier key, a
|
|
76
|
+
stock-OpenSSL XChaCha20-Poly1305 decrypt and a DID == CID(op) check.
|
|
77
|
+
- Strict-expiry rule and table. `verifyResponse` enforces expiry.
|
|
78
|
+
|
|
79
|
+
## 0.1.2
|
|
80
|
+
- Known-answer vectors that verify with stock OpenSSL and no install: `kav-1` and `mdip-challenge-1`.
|
|
81
|
+
|
|
82
|
+
## 0.1.1
|
|
83
|
+
- `respond --valid-days` (default 7 days, capped at the challenge's `validUntil`). Requires Node ≥ 22.
|
|
84
|
+
|
|
85
|
+
## 0.1.0
|
|
86
|
+
- 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,29 @@ 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.
|
|
180
|
+
|
|
159
181
|
```bash
|
|
160
|
-
# fetch the published files: a plain tarball download, nothing is installed or executed
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
182
|
+
# fetch the published files: a plain tarball download, nothing is installed or executed.
|
|
183
|
+
# Check the tarball against the registry's sha512 integrity BEFORE unpacking (don't pipe curl into tar):
|
|
184
|
+
V=0.1.5
|
|
185
|
+
curl -fsSLo kit.tgz https://registry.npmjs.org/mdip-agent-kit/-/mdip-agent-kit-$V.tgz
|
|
186
|
+
I=$(curl -fsS https://registry.npmjs.org/mdip-agent-kit/$V | grep -o '"integrity":"sha512-[^"]*"' | cut -d'"' -f4)
|
|
187
|
+
H="sha512-$(openssl dgst -sha512 -binary kit.tgz | openssl base64 -A)"
|
|
188
|
+
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
|
|
189
|
+
# (same value: `npm view mdip-agent-kit@$V dist.integrity`. npm versions are immutable, so this pins the
|
|
190
|
+
# bytes; it does not say who published them.)
|
|
191
|
+
# each dir's SHA256SUMS lists every file in it (verify-openssl.sh checks that with openssl alone and also
|
|
192
|
+
# rejects unlisted files). These sums catch corruption, not forgery: anyone who edits a file can rewrite
|
|
193
|
+
# them. The registry integrity above anchors the bytes; the checkers also pin the published DIDs and the
|
|
194
|
+
# kav-1 known answers (table below), so a wholesale regenerated vector set is caught too.
|
|
195
|
+
for d in kav-1 mdip-challenge-1 mdip-challenge-2; do (cd $d && shasum -a 256 -c SHA256SUMS); done # or: sha256sum -c
|
|
164
196
|
|
|
165
197
|
# A. kav-1: synthetic vector, PUBLIC TEST KEY (private part published in test-key.json on purpose)
|
|
166
198
|
openssl dgst -sha256 -r kav-1/message.bin
|
|
@@ -169,7 +201,8 @@ openssl dgst -sha256 -verify kav-1/pub.pem -signature kav-1/signature.der kav-1/
|
|
|
169
201
|
# Verified OK (exit 0)
|
|
170
202
|
openssl dgst -sha256 -verify kav-1/pub.pem -signature kav-1/signature.der kav-1/message-tampered.bin
|
|
171
203
|
# Verification failure (exit 1, one byte changed)
|
|
172
|
-
|
|
204
|
+
# same check on the raw 32-byte hash (what MDIP actually signs): pkeyutl verifies a precomputed digest
|
|
205
|
+
openssl dgst -sha256 -binary kav-1/message.bin > /tmp/h.bin
|
|
173
206
|
openssl pkeyutl -verify -pubin -inkey kav-1/pub.pem -in /tmp/h.bin -sigfile kav-1/signature.der
|
|
174
207
|
# Signature Verified Successfully (exit 0)
|
|
175
208
|
|
|
@@ -179,6 +212,8 @@ for p in verifier-agent:verifier-agent challenge:verifier-agent responder-agent:
|
|
|
179
212
|
openssl dgst -sha256 -verify mdip-challenge-1/$key.pub.pem -signature mdip-challenge-1/$op.sig.der mdip-challenge-1/$op.message.bin
|
|
180
213
|
done
|
|
181
214
|
# Verified OK x4 (exit 0 each)
|
|
215
|
+
# verify-openssl.sh also checks each DID == did:mdip:z + base58btc(01 8004 1220 || sha256(<name>.signed-op.bin))
|
|
216
|
+
# and that <name>.signed-op.bin is <name>.message.bin plus the signature in <name>.sig.der
|
|
182
217
|
|
|
183
218
|
# C. mdip-challenge-2 (new in 0.1.3, thanks @homies): offline challenge <-> response BINDING.
|
|
184
219
|
# The verifier is a PUBLIC TEST identity, so anyone can decrypt the response it received.
|
|
@@ -188,14 +223,22 @@ bash decrypt-openssl.sh $d/verifier-agent.PUBLIC-TEST-KEY.priv.pem $d/responder-
|
|
|
188
223
|
# {"response":{"challenge":"did:mdip:...","credentials":[],...,"match":true,"responseNonce":"..."}}
|
|
189
224
|
# the "challenge" value must equal dids.json "challenge"; verify-openssl.sh checks that, plus:
|
|
190
225
|
# - 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
|
|
226
|
+
# - every DID == did:mdip:z + base58btc(01 8004 1220 || sha256(<name>.signed-op.bin)) (DID is the op hash;
|
|
227
|
+
# B and C both; leading base58 '1's are 0x00 bytes, so a padded DID string is rejected)
|
|
228
|
+
# - every JSON copy is tied to signed bytes: <name>.op.json == <name>.signed-op.bin (keys in JCS
|
|
229
|
+
# order), dids.json has exactly the four names, verify-response.json / test-verifier.json /
|
|
230
|
+
# kav-1 payload.json, signed.json and test-key.json are pinned field by field
|
|
231
|
+
# - each signature block is exactly {hash, signed, [signer,] value}, with created <= signed <= created + 60 s
|
|
232
|
+
# - each <name>.signed-op.bin is exactly <name>.message.bin plus its signature, and that signature
|
|
233
|
+
# is <name>.sig.der (so the DID-bearing bytes are the ones OpenSSL verified)
|
|
234
|
+
# - each *.pub.pem is the publicJwk inside its signed agent op; signer == controller on asset ops
|
|
192
235
|
# - challenge controller == verifier DID; response controller == encrypted.sender == responder DID
|
|
193
236
|
# - a flipped ciphertext byte fails the Poly1305 tag
|
|
194
237
|
|
|
195
|
-
# D.
|
|
238
|
+
# D. expiry: response.validUntil <= challenge.validUntil + 2 h (stock keymaster skew); 2 h + 1 ns is rejected.
|
|
196
239
|
cat expiry-cases.txt # the table; verify-openssl.sh and verify-with-kit.js both run it
|
|
197
240
|
|
|
198
|
-
# or all of the above in one go (bash +
|
|
241
|
+
# or all of the above in one go (bash + OpenSSL 3 only):
|
|
199
242
|
bash verify-openssl.sh # last line: ALL VECTORS OK, exit 0
|
|
200
243
|
```
|
|
201
244
|
|
|
@@ -218,9 +261,11 @@ bash verify-openssl.sh # last line: ALL VECTORS OK, exit 0
|
|
|
218
261
|
`verifyResponse` result (`verify-response.json`). OpenSSL proves that the challenge was signed
|
|
219
262
|
by the verifier's key and the response by the responder's key. Read the JSON to check the bindings:
|
|
220
263
|
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 (
|
|
264
|
+
are the responder DID; the response `mdip.validUntil` ≤ the challenge's (this kit caps it there; the rule allows up to + 2 h).
|
|
222
265
|
The response payload (`challenge` DID, `responseNonce`, `match`) is **encrypted to the verifier**,
|
|
223
|
-
so only the verifier can check it; `verify-response.json` is
|
|
266
|
+
so only the verifier can check it; `verify-response.json` is a **recorded** result of what the
|
|
267
|
+
verifier saw, not re-derivable offline (see C for an offline-checkable version). These DIDs were
|
|
268
|
+
short-lived (1 h), so they may no longer resolve. The fixture is for
|
|
224
269
|
offline checks.
|
|
225
270
|
- **C (`mdip-challenge-2`, 0.1.3)** closes the gap @homies found in B: there the binding sat in
|
|
226
271
|
ciphertext only the verifier could open. Here the verifier is a **PUBLIC TEST identity**: its wallet
|
|
@@ -234,17 +279,61 @@ bash verify-openssl.sh # last line: ALL VECTORS OK, exit 0
|
|
|
234
279
|
DID string is the hash of its op. Real verifiers keep their key private, so in production only the
|
|
235
280
|
verifier can make this check. The vector proves the format and the kit's binding logic, not a stranger's
|
|
236
281
|
view of a live exchange.
|
|
237
|
-
- **D (
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
`
|
|
282
|
+
- **D (expiry)**: at verify time the challenge **and** the response must both still be valid (`now` before
|
|
283
|
+
each `validUntil`); that is what decides whether a response is accepted in time. In addition a response
|
|
284
|
+
may expire **at most 2 h after** its challenge (`response.validUntil <= challenge.validUntil + 2 h`,
|
|
285
|
+
`RESPONSE_EXPIRY_SKEW_MS`). Stock `@mdip/keymaster` 2.2.0 gives a challenge `created + 1 h` and a response
|
|
286
|
+
`responded + 1 h`, so its responses expire a few seconds to ~1 h after the challenge; 0.1.5 accepts those
|
|
287
|
+
(page wallets, Snaps and other stock-keymaster responders interoperate). This kit's `respond` still caps at
|
|
288
|
+
exactly the challenge expiry, which is why B and C show equal timestamps to the millisecond. 2 h + 1 ns
|
|
289
|
+
later (e.g. a forged 2099 expiry) is rejected, and so is a missing response expiry when the challenge has
|
|
290
|
+
one. Since 0.1.3, `agent.verifyResponse()` / `mdip-agent verify-response` enforce this, plus "neither already expired",
|
|
242
291
|
and return `expiry: { ok, reason }` with `match: false` on failure (exported as `checkResponseExpiry`).
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
292
|
+
**Timestamp rules (fail closed, 0.1.5, thanks @homies):** a timestamp must match
|
|
293
|
+
`YYYY-MM-DDTHH:MM:SS[.1-9 digits](Z|±hh:mm)` with a real calendar date (leap years included),
|
|
294
|
+
hour ≤ 23, minute/second ≤ 59 and offset ≤ 23:59. Rejected: lowercase `t`/`z` and space separators
|
|
295
|
+
(RFC 3339 allows them; we don't), no zone, `+hhmm`, leap second `:60`, `24:00`, expanded years,
|
|
296
|
+
RFC 2822 dates, more than 9 fraction digits. Times are compared exactly to the nanosecond.
|
|
297
|
+
`verify-openssl.sh` does this in pure bash (no `date`, python3 or jq, so macOS/BSD behave the same)
|
|
298
|
+
and the JS (`parseTimestampNs`, exported) uses the same grammar and arithmetic; the two were
|
|
299
|
+
differentially fuzzed to agree. MDIP itself writes `toISOString()` (ms, `Z`).
|
|
300
|
+
- **MDIP does not sign `signature.signed`** (the signature covers the op minus the whole
|
|
301
|
+
`signature` block). Anyone relaying an op can change that timestamp, which changes the op's hash
|
|
302
|
+
and therefore its DID, while `openssl ... -verify` still says Verified OK. The checkers pin the
|
|
303
|
+
shipped vectors (exact block shape, strict RFC 3339, `created <= signed <= created + 60 s`), but
|
|
304
|
+
that is a fixture rule, not an MDIP rule: the DIDs in `dids.json` are authentic only because the
|
|
305
|
+
tarball matched the registry's integrity hash. Never treat a signed op's `signed` time as attested.
|
|
306
|
+
- **Not covered offline, by definition:** `ALL VECTORS OK` says nothing about whether a key is still
|
|
307
|
+
live, rotated or revoked. DID resolution, key rotation and revocation are reads at verify time, so
|
|
308
|
+
no offline vector can cover them. `verifyResponse` re-resolves the challenge and each presented
|
|
309
|
+
credential **at verify time** and ignores deactivated or revoked ones. That needs a gatekeeper:
|
|
310
|
+
check it with `npm test` (in the package dir, against your own node; it publishes one throwaway DID).
|
|
311
|
+
- **Pinned, low-S, strict files.** Both checkers have the known answers built in: the kav-1
|
|
312
|
+
message hash, signature and test-key label (`pub.pem` must be the key derived from the label), and
|
|
313
|
+
all 8 DIDs of B and C. So a vector dir that was regenerated wholesale, or re-signed with another
|
|
314
|
+
key, fails even if it is self-consistent. Every signature must be **low-S** (`s <= n/2`), as MDIP
|
|
315
|
+
requires: OpenSSL also accepts the high-S twin `(r, n-s)`, so the scripts check S themselves.
|
|
316
|
+
`kav-1/message-tampered.bin` must differ from `message.bin` in exactly one byte. Each `SHA256SUMS`
|
|
317
|
+
line must be `<64 hex> <plain file name>`, including a last line with no newline. Symlinks, dotfiles
|
|
318
|
+
and unlisted files are rejected. The decrypted plaintext in C is compared byte for byte. The pins sit
|
|
319
|
+
in the same tarball as the vectors, so your real anchor is the registry `integrity` check above.
|
|
320
|
+
- **Every human-readable file is checked exactly.** The `.json` files are written in JCS key order
|
|
321
|
+
with 2-space indent, so each is compared to the bytes the signatures and DIDs cover: every
|
|
322
|
+
`*.op.json` must be its `*.signed-op.bin`, `kav-1/payload.json` must be `message.bin`, `signed.json`
|
|
323
|
+
must be `message.bin` plus the pinned signature block (hash, signed, signer, value = `signature.der`),
|
|
324
|
+
`test-key.json` / `test-verifier.json` must hold exactly the keys in the PEM files (and the pinned
|
|
325
|
+
label, mnemonic, DID, WARNING), `dids.json` exactly the pinned DIDs, and `verify-response.json` exactly
|
|
326
|
+
the recorded result (in C: the challenge and nonce of the decrypted plaintext). `signature.hex` and
|
|
327
|
+
`message.sha256` are exactly the value plus one newline, and each PEM is one canonical block. An
|
|
328
|
+
extra, duplicate or changed member, or extra bytes, fails. `verify-with-kit.js` applies the same
|
|
329
|
+
strict `SHA256SUMS` rules itself.
|
|
246
330
|
- 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
|
|
331
|
+
(recomputes JCS from the JSON instead of trusting the `.bin` files, and re-derives the PUBLIC TEST
|
|
332
|
+
verifier key from its label -> mnemonic -> `m/44'/0'/0'/0/0`; the shell script can't do BIP32, so
|
|
333
|
+
that one link is JS-only). `bash test/vectors-negative.sh` tampers with copies of the vectors
|
|
334
|
+
(including self-consistent forgeries that also rewrite `SHA256SUMS`, `dids.json` and the JSON
|
|
335
|
+
copies, high-S twins, the other public key recovered from the same signature, a fresh-key re-sign,
|
|
336
|
+
dotfiles, symlinks, and runs with jq hidden) and checks both checkers reject every one.
|
|
248
337
|
|
|
249
338
|
## Backup & restore
|
|
250
339
|
|
|
@@ -272,7 +361,19 @@ somewhere offline: anyone holding it controls the agent's identity.
|
|
|
272
361
|
Only reveal what you'd put on a billboard. Use *publish* without reveal, or nothing, for anything else.
|
|
273
362
|
- Challenges and responses are short-lived public DIDs. Their credential presentations are encrypted to the verifier.
|
|
274
363
|
- Accepting a credential doesn't make it valid. Always check the issuer, schema, and expiry before
|
|
275
|
-
acting (`findCredentials` does this and verifies signatures
|
|
364
|
+
acting (`findCredentials` does this and verifies signatures; it skips credentials whose
|
|
365
|
+
`validFrom`/`validUntil` is unparseable, not yet valid, or expired, or whose signer isn't the issuer
|
|
366
|
+
or subject isn't this agent). Revocation is possible: re-check before acting.
|
|
367
|
+
- `verifyResponse` adds checks keymaster 2.2.0 does not make, so act only on `match === true`:
|
|
368
|
+
the response answers `options.challenge` (replay), the challenge is yours, the response was encrypted
|
|
369
|
+
by its own controller (keymaster decrypts with the `encrypted.sender` key but reports the controller as
|
|
370
|
+
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
|
|
371
|
+
presented credential's subject is the responder (keymaster alone lets anyone who has seen a credential,
|
|
372
|
+
e.g. a revealed Public Profile, present it as their own), and every presented credential is inside its
|
|
373
|
+
validity window (keymaster alone accepts expired ones). Reasons are in `result.checks`. Challenge
|
|
374
|
+
receipts are published only after all of these pass (`publish: false` to never publish).
|
|
375
|
+
- `createChallenge`, `respondToChallenge({ validUntil })` and `issueCredential` reject timestamps that are
|
|
376
|
+
not strict RFC 3339 or already past, instead of creating DIDs that can never verify.
|
|
276
377
|
- Don't expose your gatekeeper's write API or any keymaster REST port to the Internet.
|
|
277
378
|
- npm ≥ 11 may skip `secp256k1`'s native build (`npm install-scripts approve secp256k1` to allow it).
|
|
278
379
|
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.5",
|
|
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",
|