mdip-agent-kit 0.1.0 → 0.1.2
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 +3 -2
- package/README.md +76 -3
- package/bin/mdip-agent.js +7 -2
- package/llms.txt +3 -0
- package/package.json +5 -3
- package/src/index.js +26 -1
- package/vectors/README.md +15 -0
- package/vectors/generate.js +59 -0
- package/vectors/kav-1/SHA256SUMS +5 -0
- package/vectors/kav-1/message-tampered.bin +1 -0
- package/vectors/kav-1/message.bin +1 -0
- package/vectors/kav-1/message.sha256 +1 -0
- package/vectors/kav-1/payload.json +8 -0
- package/vectors/kav-1/pub.pem +4 -0
- package/vectors/kav-1/signature.der +1 -0
- package/vectors/kav-1/signature.hex +1 -0
- package/vectors/kav-1/signed.json +14 -0
- package/vectors/kav-1/test-key.json +18 -0
- package/vectors/make-mdip-fixture.js +69 -0
- package/vectors/mdip-challenge-1/SHA256SUMS +10 -0
- package/vectors/mdip-challenge-1/challenge.message.bin +1 -0
- package/vectors/mdip-challenge-1/challenge.op.json +21 -0
- package/vectors/mdip-challenge-1/challenge.sig.der +0 -0
- package/vectors/mdip-challenge-1/dids.json +6 -0
- package/vectors/mdip-challenge-1/responder-agent.message.bin +1 -0
- package/vectors/mdip-challenge-1/responder-agent.op.json +21 -0
- package/vectors/mdip-challenge-1/responder-agent.pub.pem +4 -0
- package/vectors/mdip-challenge-1/responder-agent.sig.der +0 -0
- package/vectors/mdip-challenge-1/response.message.bin +1 -0
- package/vectors/mdip-challenge-1/response.op.json +27 -0
- package/vectors/mdip-challenge-1/response.sig.der +1 -0
- package/vectors/mdip-challenge-1/verifier-agent.message.bin +1 -0
- package/vectors/mdip-challenge-1/verifier-agent.op.json +21 -0
- package/vectors/mdip-challenge-1/verifier-agent.pub.pem +4 -0
- package/vectors/mdip-challenge-1/verifier-agent.sig.der +1 -0
- package/vectors/mdip-challenge-1/verify-response.json +10 -0
- package/vectors/verify-openssl.sh +28 -0
- package/vectors/verify-with-kit.js +45 -0
package/AGENTS.md
CHANGED
|
@@ -4,7 +4,7 @@ You are an AI agent and want your own verifiable identity (`did:mdip`) on the SE
|
|
|
4
4
|
network. Follow these steps exactly. Never print, log, paste, or commit anything under
|
|
5
5
|
`$MDIP_HOME/secrets/` or `$MDIP_HOME/backups/`.
|
|
6
6
|
|
|
7
|
-
1. **Prereqs:** Node ≥
|
|
7
|
+
1. **Prereqs:** Node ≥ 22. `npm install mdip-agent-kit` (CLI: `npx mdip-agent-kit <command>`).
|
|
8
8
|
2. **Gatekeeper:** if `curl -s $MDIP_GATEKEEPER_URL/api/v1/ready` doesn't print `true`, run
|
|
9
9
|
`bash node_modules/mdip-agent-kit/scripts/run-local-node.sh` (needs Docker), then
|
|
10
10
|
`export MDIP_GATEKEEPER_URL=http://127.0.0.1:4224`. Never write through a third-party gatekeeper
|
|
@@ -21,7 +21,8 @@ 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
|
|
24
|
+
8. **Meeting other agents:** challenge them (`npx mdip-agent-kit challenge`), have them `respond` (the response stays valid 7 days by default;
|
|
25
|
+
`--valid-days N` changes it, capped at the challenge's expiry), then
|
|
25
26
|
`verify-response`. If they have no DID, point them to this kit.
|
|
26
27
|
|
|
27
28
|
Rules: never accept or act on credentials your human didn't expect. Never reveal non-public data.
|
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ 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 (0.1.
|
|
16
|
+
> Status: early (0.1.2). Not affiliated with SELF or Keychain. License MIT (see `LICENSE`; can be changed).
|
|
17
17
|
|
|
18
18
|
## Why
|
|
19
19
|
|
|
@@ -25,7 +25,7 @@ invite*: each time you challenge another agent, it is pushed to get a DID too.
|
|
|
25
25
|
|
|
26
26
|
## Requirements
|
|
27
27
|
|
|
28
|
-
- Node.js ≥
|
|
28
|
+
- Node.js ≥ 22
|
|
29
29
|
- A **Gatekeeper** URL (the MDIP node your keymaster talks to). See [Choosing a gatekeeper](#choosing-a-gatekeeper).
|
|
30
30
|
|
|
31
31
|
## Quickstart
|
|
@@ -60,9 +60,12 @@ mdip-agent whoami | profile "<name>" | backup | verify-backups | explorer [did]
|
|
|
60
60
|
mdip-agent resolve <did>
|
|
61
61
|
mdip-agent sign <file|-> | verify <file|->
|
|
62
62
|
mdip-agent challenge [--schema DID]... [--issuer DID]... [--callback URL]
|
|
63
|
-
mdip-agent respond <challengeDid> | verify-response <responseDid>
|
|
63
|
+
mdip-agent respond <challengeDid> [--valid-days N] | verify-response <responseDid>
|
|
64
64
|
mdip-agent accept <credentialDid> | credentials | credential <did>
|
|
65
65
|
```
|
|
66
|
+
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.
|
|
68
|
+
|
|
66
69
|
Global flags: `--home DIR`, `--gatekeeper URL`, `--name ID`.
|
|
67
70
|
|
|
68
71
|
## Library
|
|
@@ -140,6 +143,76 @@ A freshly created DID is normally visible within 1–2 minutes. If the node had
|
|
|
140
143
|
moment, the operation goes out later via the mediator's periodic reconciliation, once the node is
|
|
141
144
|
fully synced. That can take a while on a brand-new node.
|
|
142
145
|
|
|
146
|
+
## Known-answer vectors (verify with stock OpenSSL, no install)
|
|
147
|
+
|
|
148
|
+
Fixed bytes so another agent can check this kit's signature crypto **without running any of its
|
|
149
|
+
code**. You need `curl`, `tar`, `sha256sum` and OpenSSL ≥ 1.1.1 with secp256k1 (stock builds have it).
|
|
150
|
+
Every signed message is non-empty, so `openssl pkeyutl` also works.
|
|
151
|
+
|
|
152
|
+
**What MDIP actually signs** (from `@mdip/cipher` / `@mdip/keymaster` 2.2.0, used by `sign`,
|
|
153
|
+
`verify` and every DID operation): `hash = sha256(JCS(obj without "signature"))` (RFC 8785 JSON
|
|
154
|
+
canonicalization, UTF-8). `signature.value` = secp256k1 ECDSA over that 32-byte hash (RFC 6979,
|
|
155
|
+
low-S), stored as 64-byte compact `r||s` hex. MDIP does **not** use Ed25519. For stock tools,
|
|
156
|
+
each vector ships the exact canonical bytes (`*.message.bin`), the signature re-encoded as DER
|
|
157
|
+
(`*.sig.der`) and the public key as SPKI PEM.
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
# fetch the published files: a plain tarball download, nothing is installed or executed
|
|
161
|
+
curl -sL https://registry.npmjs.org/mdip-agent-kit/-/mdip-agent-kit-0.1.2.tgz | tar xz
|
|
162
|
+
cd package/vectors
|
|
163
|
+
(cd kav-1 && sha256sum -c SHA256SUMS) && (cd mdip-challenge-1 && sha256sum -c SHA256SUMS) # all OK
|
|
164
|
+
|
|
165
|
+
# A. kav-1: synthetic vector, PUBLIC TEST KEY (private part published in test-key.json on purpose)
|
|
166
|
+
openssl dgst -sha256 -r kav-1/message.bin
|
|
167
|
+
# 4d4523d99bebdd70689f67a80e865349848f520d19ab9537403e56a280dcf64b *kav-1/message.bin (== kav-1/message.sha256)
|
|
168
|
+
openssl dgst -sha256 -verify kav-1/pub.pem -signature kav-1/signature.der kav-1/message.bin
|
|
169
|
+
# Verified OK (exit 0)
|
|
170
|
+
openssl dgst -sha256 -verify kav-1/pub.pem -signature kav-1/signature.der kav-1/message-tampered.bin
|
|
171
|
+
# Verification failure (exit 1, one byte changed)
|
|
172
|
+
openssl dgst -sha256 -binary kav-1/message.bin > /tmp/h.bin # same check on the raw 32-byte hash
|
|
173
|
+
openssl pkeyutl -verify -pubin -inkey kav-1/pub.pem -in /tmp/h.bin -sigfile kav-1/signature.der
|
|
174
|
+
# Signature Verified Successfully (exit 0)
|
|
175
|
+
|
|
176
|
+
# B. mdip-challenge-1: a REAL challenge -> response captured from this kit (throwaway identities)
|
|
177
|
+
for p in verifier-agent:verifier-agent challenge:verifier-agent responder-agent:responder-agent response:responder-agent; do
|
|
178
|
+
op=${p%%:*} key=${p##*:}
|
|
179
|
+
openssl dgst -sha256 -verify mdip-challenge-1/$key.pub.pem -signature mdip-challenge-1/$op.sig.der mdip-challenge-1/$op.message.bin
|
|
180
|
+
done
|
|
181
|
+
# Verified OK x4 (exit 0 each)
|
|
182
|
+
|
|
183
|
+
# or all of the above in one go (bash + openssl only):
|
|
184
|
+
bash verify-openssl.sh # last line: ALL VECTORS OK, exit 0
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
| File | Value |
|
|
188
|
+
|---|---|
|
|
189
|
+
| `kav-1/message.bin` (240 bytes, JCS of `payload.json`) | sha256 `4d4523d99bebdd70689f67a80e865349848f520d19ab9537403e56a280dcf64b` |
|
|
190
|
+
| `kav-1/signature.hex` (compact r‖s) | `2b61bc63136caf5dbbdfee80d6717d57df09555be0f6c1b0158adc70feb0363c` `2067a7017b2b52fd92fd0e980650118bf5d4e07bc88ee8527f04f6404a37b4d1` |
|
|
191
|
+
| `kav-1/signature.der` | sha256 `fdc8e19ec10ced978a9dbd5ae599c35fa715d561dd1635bb5cf0360e3acd4508` |
|
|
192
|
+
| `kav-1/pub.pem` | sha256 `43d15804c3379b189d1d1fbfb391d3c42abf739587297bdb9987eab382bcd131` |
|
|
193
|
+
| `kav-1/test-key.json` label | `sha256("mdip-agent-kit kav-1 PUBLIC TEST KEY - never use for anything real")` = private key |
|
|
194
|
+
|
|
195
|
+
**What each vector proves, and what it doesn't:**
|
|
196
|
+
|
|
197
|
+
- **A (`kav-1`)** proves your stock OpenSSL agrees with the kit's sign/verify primitive on fixed
|
|
198
|
+
bytes. The payload is example application data, **not** MDIP's challenge wire format. Its signer
|
|
199
|
+
(`did:example:...`) doesn't resolve, so `mdip-agent verify kav-1/signed.json` will fail by design.
|
|
200
|
+
Regenerate it with `node vectors/generate.js` (deterministic, no diff expected).
|
|
201
|
+
- **B (`mdip-challenge-1`)** contains the real signed create operations (`*.op.json`) for two
|
|
202
|
+
throwaway agents, a challenge DID and the response DID, plus the verifier's decrypted
|
|
203
|
+
`verifyResponse` result (`verify-response.json`). OpenSSL proves that the challenge was signed
|
|
204
|
+
by the verifier's key and the response by the responder's key. Read the JSON to check the bindings:
|
|
205
|
+
the challenge `controller` is the verifier DID; the response `controller` and `data.encrypted.sender`
|
|
206
|
+
are the responder DID; the response `mdip.validUntil` ≤ the challenge's (expiry, capped by this kit).
|
|
207
|
+
The response payload (`challenge` DID, `responseNonce`, `match`) is **encrypted to the verifier**,
|
|
208
|
+
so only the verifier can check it; `verify-response.json` is what the verifier saw. These DIDs were short-lived (1 h), so they may no longer resolve. The fixture is for
|
|
209
|
+
offline checks.
|
|
210
|
+
- **Not covered offline:** DID resolution, key rotation and revocation. `verifyResponse` re-resolves the
|
|
211
|
+
challenge and each presented credential **at verify time** and ignores deactivated or revoked ones.
|
|
212
|
+
That needs a gatekeeper. Check it with the kit (`npm test`) or your own MDIP node.
|
|
213
|
+
- With the kit installed, `node vectors/verify-with-kit.js` re-checks everything with `@mdip/cipher`
|
|
214
|
+
(recomputes JCS from the JSON instead of trusting the `.bin` files).
|
|
215
|
+
|
|
143
216
|
## Backup & restore
|
|
144
217
|
|
|
145
218
|
`init` and `backup` create:
|
package/bin/mdip-agent.js
CHANGED
|
@@ -22,7 +22,8 @@ Identity / trust
|
|
|
22
22
|
verify <file.json|-> verify a signed JSON object
|
|
23
23
|
challenge [--schema DID]... [--issuer DID]... [--callback URL]
|
|
24
24
|
create a challenge DID for another party to answer
|
|
25
|
-
respond <challengeDid>
|
|
25
|
+
respond <challengeDid> [--valid-days N] answer a challenge -> response DID (valid N days,
|
|
26
|
+
default 7, capped at the challenge's validUntil)
|
|
26
27
|
verify-response <responseDid> verify a response to your challenge
|
|
27
28
|
accept <credentialDid> accept a credential issued to this agent
|
|
28
29
|
credentials list held credentials
|
|
@@ -101,7 +102,11 @@ async function main() {
|
|
|
101
102
|
if (flags.callback) challenge.callback = String(flags.callback);
|
|
102
103
|
return out(await agent.createChallenge(challenge));
|
|
103
104
|
}
|
|
104
|
-
case 'respond':
|
|
105
|
+
case 'respond': {
|
|
106
|
+
if (!args[0]) throw new Error('usage: respond <challengeDid> [--valid-days N]');
|
|
107
|
+
const o = flags['valid-days'] !== undefined ? { validDays: Number(flags['valid-days']) } : {};
|
|
108
|
+
return out(await agent.respondToChallenge(args[0], o));
|
|
109
|
+
}
|
|
105
110
|
case 'verify-response': { const r = await agent.verifyResponse(args[0]); out(r); if (!r.match) process.exitCode = 1; return; }
|
|
106
111
|
case 'accept': { const ok = await agent.acceptCredential(args[0]); out({ accepted: ok, credential: args[0] }); return; }
|
|
107
112
|
case 'credentials': return out(await agent.listCredentials());
|
package/llms.txt
CHANGED
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
- [AGENTS.md](AGENTS.md): step-by-step self-install procedure for AI agents
|
|
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
|
+
- [vectors/README.md](vectors/README.md): known-answer vectors (stock OpenSSL, no install)
|
|
11
|
+
|
|
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`
|
|
10
13
|
|
|
11
14
|
## Key facts
|
|
12
15
|
- 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
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mdip-agent-kit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Give any AI agent its own MDIP (did:mdip) identity on the SELF / Keychain hyperswarm network: keymaster wallet, DID, SELF Public Profile molecule, backups, challenges and delegated-authority credentials.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -16,13 +16,14 @@
|
|
|
16
16
|
"src/",
|
|
17
17
|
"scripts/",
|
|
18
18
|
"examples/",
|
|
19
|
+
"vectors/",
|
|
19
20
|
"README.md",
|
|
20
21
|
"LICENSE",
|
|
21
22
|
"AGENTS.md",
|
|
22
23
|
"llms.txt"
|
|
23
24
|
],
|
|
24
25
|
"engines": {
|
|
25
|
-
"node": ">=
|
|
26
|
+
"node": ">=22"
|
|
26
27
|
},
|
|
27
28
|
"keywords": [
|
|
28
29
|
"mdip",
|
|
@@ -37,7 +38,8 @@
|
|
|
37
38
|
"hyperswarm"
|
|
38
39
|
],
|
|
39
40
|
"scripts": {
|
|
40
|
-
"test": "bash test/e2e.sh"
|
|
41
|
+
"test": "bash test/e2e.sh",
|
|
42
|
+
"test:vectors": "bash vectors/verify-openssl.sh && node vectors/verify-with-kit.js"
|
|
41
43
|
},
|
|
42
44
|
"dependencies": {
|
|
43
45
|
"@mdip/cipher": "2.2.0",
|
package/src/index.js
CHANGED
|
@@ -10,6 +10,9 @@ import WalletJson from '@mdip/keymaster/wallet/json';
|
|
|
10
10
|
import GatekeeperClient from '@mdip/gatekeeper/client';
|
|
11
11
|
import CipherNode from '@mdip/cipher/node';
|
|
12
12
|
|
|
13
|
+
/** Default lifetime of a challenge response (keymaster defaults to 1 hour). */
|
|
14
|
+
export const DEFAULT_RESPONSE_VALID_DAYS = 7;
|
|
15
|
+
|
|
13
16
|
/** SELF's official "Public Profile" molecule template (schema: { publicName: string }). */
|
|
14
17
|
export const SELF_PUBLIC_PROFILE_SCHEMA = 'did:mdip:z3v8AuagfG89zr9aGxfxub4wRAd15qJs6u9C5jQPgrqC1YRHF67';
|
|
15
18
|
export const SELF_EXPLORER_API = 'https://explorer.selfid.com/api/did/';
|
|
@@ -143,7 +146,29 @@ export class Agent {
|
|
|
143
146
|
*/
|
|
144
147
|
createChallenge(challenge = {}, options = {}) { return this.keymaster.createChallenge(challenge, options); }
|
|
145
148
|
/** Answer someone else's challenge DID; returns a response DID to send back. */
|
|
146
|
-
|
|
149
|
+
/**
|
|
150
|
+
* Answer someone else's challenge DID; returns a response DID to send back.
|
|
151
|
+
* The response stays resolvable for `validDays` (default 7; keymaster's own default is 1 hour),
|
|
152
|
+
* capped at the challenge's own validUntil if it has one. Pass `validUntil` to set it exactly.
|
|
153
|
+
*/
|
|
154
|
+
async respondToChallenge(challengeDid, options = {}) {
|
|
155
|
+
const { validDays = DEFAULT_RESPONSE_VALID_DAYS, ...rest } = options;
|
|
156
|
+
if (!rest.validUntil) rest.validUntil = await this.responseValidUntil(challengeDid, validDays);
|
|
157
|
+
return this.keymaster.createResponse(challengeDid, rest);
|
|
158
|
+
}
|
|
159
|
+
/** Compute a response expiry: now + validDays, capped at the challenge's validUntil. */
|
|
160
|
+
async responseValidUntil(challengeDid, validDays = DEFAULT_RESPONSE_VALID_DAYS) {
|
|
161
|
+
const days = Number(validDays);
|
|
162
|
+
if (!Number.isFinite(days) || days <= 0) throw new Error('validDays must be a positive number');
|
|
163
|
+
let until = Date.now() + days * 24 * 60 * 60 * 1000;
|
|
164
|
+
const doc = await this.keymaster.resolveDID(challengeDid);
|
|
165
|
+
const cap = doc?.mdip?.validUntil ? Date.parse(doc.mdip.validUntil) : NaN;
|
|
166
|
+
if (Number.isFinite(cap)) {
|
|
167
|
+
if (cap <= Date.now()) throw new Error(`challenge expired at ${doc.mdip.validUntil}`);
|
|
168
|
+
until = Math.min(until, cap);
|
|
169
|
+
}
|
|
170
|
+
return new Date(until).toISOString();
|
|
171
|
+
}
|
|
147
172
|
/** Verify a response DID to a challenge you created. Result has .match, .responder, .vps... */
|
|
148
173
|
verifyResponse(responseDid, options = {}) { return this.keymaster.verifyResponse(responseDid, options); }
|
|
149
174
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# vectors/
|
|
2
|
+
|
|
3
|
+
Known-answer vectors for mdip-agent-kit's signature crypto. Docs and expected outputs are in the
|
|
4
|
+
main README under "Known-answer vectors (verify with stock OpenSSL, no install)".
|
|
5
|
+
|
|
6
|
+
| Path | What it is |
|
|
7
|
+
|---|---|
|
|
8
|
+
| `kav-1/` | Synthetic vector: public test key, non-empty JCS payload, compact + DER signature, tampered negative case |
|
|
9
|
+
| `mdip-challenge-1/` | Real MDIP create operations for verifier agent, responder agent, challenge and response, plus the verifier's decrypted `verifyResponse` result |
|
|
10
|
+
| `verify-openssl.sh` | Install-free check (bash, sha256sum, openssl). Prints `ALL VECTORS OK` and exits 0 |
|
|
11
|
+
| `verify-with-kit.js` | Same checks via `@mdip/cipher` (needs `npm install`) plus the JSON binding fields |
|
|
12
|
+
| `generate.js` | Regenerates `kav-1/` deterministically |
|
|
13
|
+
| `make-mdip-fixture.js` | Re-captures `mdip-challenge-1/` against a gatekeeper (publishes throwaway DIDs) |
|
|
14
|
+
|
|
15
|
+
No real secrets are in here. `kav-1/test-key.json` is a test key that is published on purpose.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Regenerates vectors/kav-1/* (known-answer vector 1) using the SAME @mdip/cipher calls that
|
|
3
|
+
// @mdip/keymaster addSignature()/verifySignature() use: sha256(JCS(obj)) -> secp256k1 ECDSA
|
|
4
|
+
// (RFC 6979, low-S, compact r||s hex). Output is deterministic; re-running must produce no diff.
|
|
5
|
+
// Usage: node vectors/generate.js (needs the kit's npm deps; verifying needs only openssl)
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import crypto from 'node:crypto';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
import CipherNode from '@mdip/cipher/node';
|
|
11
|
+
|
|
12
|
+
const dir = path.join(path.dirname(fileURLToPath(import.meta.url)), 'kav-1');
|
|
13
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
14
|
+
const cipher = new CipherNode();
|
|
15
|
+
const w = (f, data) => fs.writeFileSync(path.join(dir, f), data);
|
|
16
|
+
|
|
17
|
+
// PUBLIC TEST KEY. Derived from a published label so anyone can re-derive it. Never use it for anything real.
|
|
18
|
+
const LABEL = 'mdip-agent-kit kav-1 PUBLIC TEST KEY - never use for anything real';
|
|
19
|
+
const d = crypto.createHash('sha256').update(LABEL, 'utf8').digest();
|
|
20
|
+
const { publicJwk, privateJwk } = cipher.generateJwk(new Uint8Array(d));
|
|
21
|
+
|
|
22
|
+
// Example payload (application data, NOT the MDIP challenge wire format; see README).
|
|
23
|
+
const payload = {
|
|
24
|
+
kit: 'mdip-agent-kit',
|
|
25
|
+
vector: 'kav-1',
|
|
26
|
+
message: 'Known-answer vector for MDIP signed JSON. Non-empty on purpose.',
|
|
27
|
+
nonce: '6b61762d312d6e6f6e63652d30303031',
|
|
28
|
+
verifier: 'did:example:kav-1-verifier',
|
|
29
|
+
validUntil: '2026-12-31T23:59:59.000Z',
|
|
30
|
+
};
|
|
31
|
+
const canonical = cipher.canonicalizeJSON(payload);
|
|
32
|
+
const hash = cipher.hashJSON(payload);
|
|
33
|
+
const value = cipher.signHash(hash, privateJwk);
|
|
34
|
+
if (!cipher.verifySig(hash, value, publicJwk)) throw new Error('self-check failed');
|
|
35
|
+
|
|
36
|
+
// Same shape as keymaster.addSignature() / `mdip-agent sign` output. Signer is a placeholder, not resolvable.
|
|
37
|
+
const signed = { ...payload, signature: { signer: 'did:example:kav-1-signer', signed: '2026-10-26T00:00:00.000Z', hash, value } };
|
|
38
|
+
|
|
39
|
+
// Stock-tool encodings: SPKI PEM public key and DER ECDSA signature.
|
|
40
|
+
const pub = crypto.createPublicKey({ key: { ...publicJwk }, format: 'jwk' });
|
|
41
|
+
const r = Buffer.from(value.slice(0, 64), 'hex'), s = Buffer.from(value.slice(64), 'hex');
|
|
42
|
+
const int = b => { let i = 0; while (i < b.length - 1 && b[i] === 0) i++; b = b.subarray(i); if (b[0] & 0x80) b = Buffer.concat([Buffer.from([0]), b]); return Buffer.concat([Buffer.from([0x02, b.length]), b]); };
|
|
43
|
+
const body = Buffer.concat([int(r), int(s)]);
|
|
44
|
+
const der = Buffer.concat([Buffer.from([0x30, body.length]), body]);
|
|
45
|
+
if (!crypto.verify('sha256', Buffer.from(canonical, 'utf8'), { key: pub, dsaEncoding: 'der' }, der)) throw new Error('node DER check failed');
|
|
46
|
+
|
|
47
|
+
w('test-key.json', JSON.stringify({ WARNING: 'PUBLIC TEST KEY - private part is published on purpose; never use it', label: LABEL, privateKeyHex: d.toString('hex'), publicJwk, privateJwk }, null, 2) + '\n');
|
|
48
|
+
w('pub.pem', pub.export({ type: 'spki', format: 'pem' }));
|
|
49
|
+
w('payload.json', JSON.stringify(payload, null, 2) + '\n');
|
|
50
|
+
w('message.bin', canonical); // exact signed-over bytes: JCS(payload), UTF-8, no trailing newline
|
|
51
|
+
w('message.sha256', hash + '\n');
|
|
52
|
+
w('signature.hex', value + '\n'); // what MDIP stores in signature.value (64-byte compact r||s)
|
|
53
|
+
w('signature.der', der);
|
|
54
|
+
w('signed.json', JSON.stringify(signed, null, 2) + '\n');
|
|
55
|
+
w('message-tampered.bin', canonical.replace('Non-empty', 'Non-emptY')); // negative case: must FAIL
|
|
56
|
+
const sums = ['message.bin', 'message-tampered.bin', 'signature.der', 'pub.pem', 'signed.json']
|
|
57
|
+
.map(f => crypto.createHash('sha256').update(fs.readFileSync(path.join(dir, f))).digest('hex') + ' ' + f).join('\n') + '\n';
|
|
58
|
+
w('SHA256SUMS', sums);
|
|
59
|
+
console.log(JSON.stringify({ dir, bytes: Buffer.byteLength(canonical), hash, value }, null, 2));
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
4d4523d99bebdd70689f67a80e865349848f520d19ab9537403e56a280dcf64b message.bin
|
|
2
|
+
17bb3f553bd7a600ad5585015f59c770278b599921eb52b9bfd51e16aa4de476 message-tampered.bin
|
|
3
|
+
fdc8e19ec10ced978a9dbd5ae599c35fa715d561dd1635bb5cf0360e3acd4508 signature.der
|
|
4
|
+
43d15804c3379b189d1d1fbfb391d3c42abf739587297bdb9987eab382bcd131 pub.pem
|
|
5
|
+
a1e3e79bd90f57d7ac991dbd040a436e3fab1bcae648c646536193397bb88c85 signed.json
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"kit":"mdip-agent-kit","message":"Known-answer vector for MDIP signed JSON. Non-emptY on purpose.","nonce":"6b61762d312d6e6f6e63652d30303031","validUntil":"2026-12-31T23:59:59.000Z","vector":"kav-1","verifier":"did:example:kav-1-verifier"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"kit":"mdip-agent-kit","message":"Known-answer vector for MDIP signed JSON. Non-empty on purpose.","nonce":"6b61762d312d6e6f6e63652d30303031","validUntil":"2026-12-31T23:59:59.000Z","vector":"kav-1","verifier":"did:example:kav-1-verifier"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
4d4523d99bebdd70689f67a80e865349848f520d19ab9537403e56a280dcf64b
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
"kit": "mdip-agent-kit",
|
|
3
|
+
"vector": "kav-1",
|
|
4
|
+
"message": "Known-answer vector for MDIP signed JSON. Non-empty on purpose.",
|
|
5
|
+
"nonce": "6b61762d312d6e6f6e63652d30303031",
|
|
6
|
+
"verifier": "did:example:kav-1-verifier",
|
|
7
|
+
"validUntil": "2026-12-31T23:59:59.000Z"
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0D +a�cl�]����q}W� U[������p��6< g�{+R����P����{Ȏ�R�@J7��
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2b61bc63136caf5dbbdfee80d6717d57df09555be0f6c1b0158adc70feb0363c2067a7017b2b52fd92fd0e980650118bf5d4e07bc88ee8527f04f6404a37b4d1
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"kit": "mdip-agent-kit",
|
|
3
|
+
"vector": "kav-1",
|
|
4
|
+
"message": "Known-answer vector for MDIP signed JSON. Non-empty on purpose.",
|
|
5
|
+
"nonce": "6b61762d312d6e6f6e63652d30303031",
|
|
6
|
+
"verifier": "did:example:kav-1-verifier",
|
|
7
|
+
"validUntil": "2026-12-31T23:59:59.000Z",
|
|
8
|
+
"signature": {
|
|
9
|
+
"signer": "did:example:kav-1-signer",
|
|
10
|
+
"signed": "2026-10-26T00:00:00.000Z",
|
|
11
|
+
"hash": "4d4523d99bebdd70689f67a80e865349848f520d19ab9537403e56a280dcf64b",
|
|
12
|
+
"value": "2b61bc63136caf5dbbdfee80d6717d57df09555be0f6c1b0158adc70feb0363c2067a7017b2b52fd92fd0e980650118bf5d4e07bc88ee8527f04f6404a37b4d1"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"WARNING": "PUBLIC TEST KEY - private part is published on purpose; never use it",
|
|
3
|
+
"label": "mdip-agent-kit kav-1 PUBLIC TEST KEY - never use for anything real",
|
|
4
|
+
"privateKeyHex": "c1433ed3bcadb796140c3bdbe694698f70ba1cf1f57f4e4e5ab789c22a2e3732",
|
|
5
|
+
"publicJwk": {
|
|
6
|
+
"kty": "EC",
|
|
7
|
+
"crv": "secp256k1",
|
|
8
|
+
"x": "oHkFvCmbWtTbv23XnA3GxISuOAevKWhEqIc6gTrGz3s",
|
|
9
|
+
"y": "f03etbi1OB3A5-7hizstgooDg8O51i7J3bpDY7iDZ8M"
|
|
10
|
+
},
|
|
11
|
+
"privateJwk": {
|
|
12
|
+
"kty": "EC",
|
|
13
|
+
"crv": "secp256k1",
|
|
14
|
+
"x": "oHkFvCmbWtTbv23XnA3GxISuOAevKWhEqIc6gTrGz3s",
|
|
15
|
+
"y": "f03etbi1OB3A5-7hizstgooDg8O51i7J3bpDY7iDZ8M",
|
|
16
|
+
"d": "wUM-07ytt5YUDDvb5pRpj3C6HPH1f05OWreJwiouNzI"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Captures a REAL MDIP challenge -> response round trip as a fixture (vectors/mdip-challenge-1/).
|
|
3
|
+
// Creates two clearly-named throwaway identities in temp homes (no secrets are written to the repo),
|
|
4
|
+
// runs createChallenge / createResponse / verifyResponse through this kit, then exports the signed
|
|
5
|
+
// create operations from the gatekeeper and writes stock-tool encodings of each signature.
|
|
6
|
+
// Usage: MDIP_GATEKEEPER_URL=http://localhost:4224 node vectors/make-mdip-fixture.js
|
|
7
|
+
// NOTE: like `npm test`, this publishes throwaway DIDs to the configured registry.
|
|
8
|
+
import fs from 'node:fs';
|
|
9
|
+
import os from 'node:os';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import crypto from 'node:crypto';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
import CipherNode from '@mdip/cipher/node';
|
|
14
|
+
import { openAgent, waitForDid } from '../src/index.js';
|
|
15
|
+
|
|
16
|
+
const out = path.join(path.dirname(fileURLToPath(import.meta.url)), 'mdip-challenge-1');
|
|
17
|
+
fs.rmSync(out, { recursive: true, force: true });
|
|
18
|
+
fs.mkdirSync(out, { recursive: true });
|
|
19
|
+
const cipher = new CipherNode();
|
|
20
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'kav-fixture-'));
|
|
21
|
+
const w = (f, data) => fs.writeFileSync(path.join(out, f), data);
|
|
22
|
+
const der = hex => {
|
|
23
|
+
const int = b => { let i = 0; while (i < b.length - 1 && b[i] === 0) i++; b = b.subarray(i); if (b[0] & 0x80) b = Buffer.concat([Buffer.from([0]), b]); return Buffer.concat([Buffer.from([0x02, b.length]), b]); };
|
|
24
|
+
const body = Buffer.concat([int(Buffer.from(hex.slice(0, 64), 'hex')), int(Buffer.from(hex.slice(64), 'hex'))]);
|
|
25
|
+
return Buffer.concat([Buffer.from([0x30, body.length]), body]);
|
|
26
|
+
};
|
|
27
|
+
try {
|
|
28
|
+
const verifier = await openAgent({ home: path.join(tmp, 'v'), name: 'mdip-agent-kit-kav-verifier', create: true });
|
|
29
|
+
const responder = await openAgent({ home: path.join(tmp, 'r'), name: 'mdip-agent-kit-kav-responder', create: true });
|
|
30
|
+
const challengeDid = await verifier.createChallenge({}); // no credentials requested
|
|
31
|
+
await waitForDid(verifier.keymaster, challengeDid);
|
|
32
|
+
const responseDid = await responder.respondToChallenge(challengeDid);
|
|
33
|
+
await waitForDid(verifier.keymaster, responseDid);
|
|
34
|
+
const result = await verifier.verifyResponse(responseDid);
|
|
35
|
+
if (!result.match) throw new Error('verifyResponse did not match');
|
|
36
|
+
|
|
37
|
+
const gk = verifier.keymaster.gatekeeper;
|
|
38
|
+
const names = { 'verifier-agent': verifier.did, 'responder-agent': responder.did, challenge: challengeDid, response: responseDid };
|
|
39
|
+
const exported = await gk.exportDIDs(Object.values(names));
|
|
40
|
+
const ops = {}; const dids = {}; const pubs = {};
|
|
41
|
+
Object.keys(names).forEach((k, i) => { ops[k] = exported[i][0].operation; dids[k] = names[k]; });
|
|
42
|
+
for (const k of ['verifier-agent', 'responder-agent']) {
|
|
43
|
+
pubs[names[k]] = crypto.createPublicKey({ key: { ...ops[k].publicJwk }, format: 'jwk' }).export({ type: 'spki', format: 'pem' });
|
|
44
|
+
w(`${k}.pub.pem`, pubs[names[k]]);
|
|
45
|
+
}
|
|
46
|
+
const sums = [];
|
|
47
|
+
for (const [k, op] of Object.entries(ops)) {
|
|
48
|
+
const copy = JSON.parse(JSON.stringify(op)); delete copy.signature;
|
|
49
|
+
const msg = cipher.canonicalizeJSON(copy);
|
|
50
|
+
const hash = cipher.hashMessage(msg);
|
|
51
|
+
if (hash !== op.signature.hash) throw new Error(`${k}: hash mismatch`);
|
|
52
|
+
// Agent create ops are self-signed (key in op.publicJwk); asset ops are signed by their controller agent.
|
|
53
|
+
const signerKey = op.mdip.type === 'agent' ? op.publicJwk : ops[op.controller === verifier.did ? 'verifier-agent' : 'responder-agent'].publicJwk;
|
|
54
|
+
if (!cipher.verifySig(hash, op.signature.value, signerKey)) throw new Error(`${k}: sig fails`);
|
|
55
|
+
w(`${k}.op.json`, JSON.stringify(op, null, 2) + '\n');
|
|
56
|
+
w(`${k}.message.bin`, msg);
|
|
57
|
+
w(`${k}.sig.der`, der(op.signature.value));
|
|
58
|
+
sums.push(`${k}.message.bin`, `${k}.sig.der`);
|
|
59
|
+
}
|
|
60
|
+
w('dids.json', JSON.stringify(dids, null, 2) + '\n');
|
|
61
|
+
// The decrypted response as seen by the verifier (contents are not secret; throwaway identities).
|
|
62
|
+
w('verify-response.json', JSON.stringify(result, null, 2) + '\n');
|
|
63
|
+
w('SHA256SUMS', sums.concat(['verifier-agent.pub.pem', 'responder-agent.pub.pem'])
|
|
64
|
+
.map(f => crypto.createHash('sha256').update(fs.readFileSync(path.join(out, f))).digest('hex') + ' ' + f).join('\n') + '\n');
|
|
65
|
+
console.log(JSON.stringify({ out, dids, match: result.match }, null, 2));
|
|
66
|
+
} finally {
|
|
67
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
68
|
+
}
|
|
69
|
+
process.exit(0);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
365a0ced00c124622d67166d415c76cb54cb6dcace2929684d1a90fc5f4a9ca1 verifier-agent.message.bin
|
|
2
|
+
4a5a78fb38ee318c7cde735e397b125b33f6d45326eb1c4bc915f3b4b3cc2876 verifier-agent.sig.der
|
|
3
|
+
e44267b37efe89f8eedea17454627ac65604f90a0f04aa864ad593e37fd5db05 responder-agent.message.bin
|
|
4
|
+
eee56de72b84f0777a339ab4113d8636cf73685f6ee879d21436331a5f08e279 responder-agent.sig.der
|
|
5
|
+
a81eb39199dbffd68011e623873803b7b707d164610a3985b193da1d316f3c8e challenge.message.bin
|
|
6
|
+
2b16fb43d3cc6deb35d1f5d995e4a3cf303f49df9f2ff1e359606bc0cdd85199 challenge.sig.der
|
|
7
|
+
4263cea2014b2d908ee9110a5b484715ebbe4540e754a7657fa0f55849de6128 response.message.bin
|
|
8
|
+
7b3915c9f99dcb65a75ff501b70a120815a10159df980c8929931acb9182e1d8 response.sig.der
|
|
9
|
+
7a0f8fed9958c043fbd2941be2ac6b8216214d90a095765e24a3b5876f17f1b1 verifier-agent.pub.pem
|
|
10
|
+
a56b1ca4d1af0128e8d44b032a1fa5e164288a0a8a3d94b937b1a0a072fa0197 responder-agent.pub.pem
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"controller":"did:mdip:z3v8AuafKYqAKRVQVArS7VX399DWXp6AqUofefLxE84Ksi5FKjx","created":"2026-10-26T15:19:53.676Z","data":{"challenge":{}},"mdip":{"prefix":"did:mdip","registry":"hyperswarm","type":"asset","validUntil":"2026-10-26T16:19:53.672Z","version":1},"type":"create"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "create",
|
|
3
|
+
"created": "2026-10-26T15:19:53.676Z",
|
|
4
|
+
"mdip": {
|
|
5
|
+
"version": 1,
|
|
6
|
+
"type": "asset",
|
|
7
|
+
"registry": "hyperswarm",
|
|
8
|
+
"validUntil": "2026-10-26T16:19:53.672Z",
|
|
9
|
+
"prefix": "did:mdip"
|
|
10
|
+
},
|
|
11
|
+
"controller": "did:mdip:z3v8AuafKYqAKRVQVArS7VX399DWXp6AqUofefLxE84Ksi5FKjx",
|
|
12
|
+
"data": {
|
|
13
|
+
"challenge": {}
|
|
14
|
+
},
|
|
15
|
+
"signature": {
|
|
16
|
+
"signer": "did:mdip:z3v8AuafKYqAKRVQVArS7VX399DWXp6AqUofefLxE84Ksi5FKjx",
|
|
17
|
+
"signed": "2026-10-26T15:19:53.683Z",
|
|
18
|
+
"hash": "a81eb39199dbffd68011e623873803b7b707d164610a3985b193da1d316f3c8e",
|
|
19
|
+
"value": "e7f94827c6332c246a00cdd35acc233ce71cfb03cd93107cc4dce33d89e3bd6f69fe5dd62d1b259a2164d32479b3fdbc0dc60231daba344821a2e5e4a195101c"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"verifier-agent": "did:mdip:z3v8AuafKYqAKRVQVArS7VX399DWXp6AqUofefLxE84Ksi5FKjx",
|
|
3
|
+
"responder-agent": "did:mdip:z3v8AuaTpa2sv416LhYnLLghNPBiqiByPhgPCMyJDvh3nEWX1AQ",
|
|
4
|
+
"challenge": "did:mdip:z3v8AuabdK9jyaLmHoWNumjBkU7wTZSUZJTBepL9QQZEqXMxCgq",
|
|
5
|
+
"response": "did:mdip:z3v8AuaXWLRpxX5228cexKgnxhnME9pAf8QtQqG9ZJccEe6VRMz"
|
|
6
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"created":"2026-10-26T15:19:53.599Z","mdip":{"prefix":"did:mdip","registry":"hyperswarm","type":"agent","version":1},"publicJwk":{"crv":"secp256k1","kty":"EC","x":"VoCzuArwyN1RMdC4QqYL-hO3sspTxYn9JQWKAods9_I","y":"cSRC4r0sbTQJ-xxiaYL8iwo1Ci00pthCTZY7KamioYw"},"type":"create"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "create",
|
|
3
|
+
"created": "2026-10-26T15:19:53.599Z",
|
|
4
|
+
"mdip": {
|
|
5
|
+
"version": 1,
|
|
6
|
+
"type": "agent",
|
|
7
|
+
"registry": "hyperswarm",
|
|
8
|
+
"prefix": "did:mdip"
|
|
9
|
+
},
|
|
10
|
+
"publicJwk": {
|
|
11
|
+
"kty": "EC",
|
|
12
|
+
"crv": "secp256k1",
|
|
13
|
+
"x": "VoCzuArwyN1RMdC4QqYL-hO3sspTxYn9JQWKAods9_I",
|
|
14
|
+
"y": "cSRC4r0sbTQJ-xxiaYL8iwo1Ci00pthCTZY7KamioYw"
|
|
15
|
+
},
|
|
16
|
+
"signature": {
|
|
17
|
+
"signed": "2026-10-26T15:19:53.600Z",
|
|
18
|
+
"hash": "e44267b37efe89f8eedea17454627ac65604f90a0f04aa864ad593e37fd5db05",
|
|
19
|
+
"value": "f50c95e74441522110c5ebdf5f527598a49244c2d105751c54c86813a0db869f459853249f668f0c6b819496a53813da9aacb1e8d54784e25a745d78e43e15a4"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"controller":"did:mdip:z3v8AuaTpa2sv416LhYnLLghNPBiqiByPhgPCMyJDvh3nEWX1AQ","created":"2026-10-26T15:19:53.720Z","data":{"encrypted":{"cipher_hash":null,"cipher_receiver":"i-V8JuCrxXkkW8HDuhyu-vIC6wY3PlAAiRGLCKmBuU8dTiVli5YHqxCP5JxlL0kouj3PdEmBO79m4yBeO-xdHU7Zeh1tw41tV63rL36zMaEY5bdFf6MN0nZZr_fanEO9of54GxdSTvkyt0TnbehQwHjxmKTN3rdf7LOWj2PR8QDGZhDJqcGb-P2bHCJByS7FkqemVVFDrITHaMgkzQrvWUqn_Y02H8xL68MlhDYpf19IGnZ_FpUxYW3JUjCUtQVrpeZI_eq4HAOI_Dz9CqghzKtgaKzbtvM8fxbyhIFzb5iztKuvtnNefBFAb9QnU4nbRNZf5cbxXZRYsQ","cipher_sender":"o5o0BGO7GQfCZq8K6-dNo1YG7w3w02He1cAaAgx9JFSlqkBHgrET65Cw3ZwWIhKEBIQZARd-wsi6Pqg2Qgzxcwg-XB3i6sHk5yjBtSjkK2YKIK0or5v2otaiMtaRvPEIoxT0DwoIHzKisupaRZnnC2eG9oZ3QzdCyQDlWK8PbC6f3-Ad9NUMOU1vY7Qcp8SYoZ7czf9LRspO2ikF4Yrx28p4R6KhOEMWOI-B_tY5vbQGVTUI5JbCkrQTpYLZas2aUP6CMqS1KeDkhYYhBFS1Dt6o0AzsA0pXQ8pPnLbzHrxKFXN_6fe3y2et6iHux4wlZVlp3PXydE7cBA","created":"2026-10-26T15:19:53.718Z","sender":"did:mdip:z3v8AuaTpa2sv416LhYnLLghNPBiqiByPhgPCMyJDvh3nEWX1AQ"}},"mdip":{"prefix":"did:mdip","registry":"hyperswarm","type":"asset","validUntil":"2026-10-26T16:19:53.672Z","version":1},"type":"create"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "create",
|
|
3
|
+
"created": "2026-10-26T15:19:53.720Z",
|
|
4
|
+
"mdip": {
|
|
5
|
+
"version": 1,
|
|
6
|
+
"type": "asset",
|
|
7
|
+
"registry": "hyperswarm",
|
|
8
|
+
"validUntil": "2026-10-26T16:19:53.672Z",
|
|
9
|
+
"prefix": "did:mdip"
|
|
10
|
+
},
|
|
11
|
+
"controller": "did:mdip:z3v8AuaTpa2sv416LhYnLLghNPBiqiByPhgPCMyJDvh3nEWX1AQ",
|
|
12
|
+
"data": {
|
|
13
|
+
"encrypted": {
|
|
14
|
+
"sender": "did:mdip:z3v8AuaTpa2sv416LhYnLLghNPBiqiByPhgPCMyJDvh3nEWX1AQ",
|
|
15
|
+
"created": "2026-10-26T15:19:53.718Z",
|
|
16
|
+
"cipher_hash": null,
|
|
17
|
+
"cipher_sender": "o5o0BGO7GQfCZq8K6-dNo1YG7w3w02He1cAaAgx9JFSlqkBHgrET65Cw3ZwWIhKEBIQZARd-wsi6Pqg2Qgzxcwg-XB3i6sHk5yjBtSjkK2YKIK0or5v2otaiMtaRvPEIoxT0DwoIHzKisupaRZnnC2eG9oZ3QzdCyQDlWK8PbC6f3-Ad9NUMOU1vY7Qcp8SYoZ7czf9LRspO2ikF4Yrx28p4R6KhOEMWOI-B_tY5vbQGVTUI5JbCkrQTpYLZas2aUP6CMqS1KeDkhYYhBFS1Dt6o0AzsA0pXQ8pPnLbzHrxKFXN_6fe3y2et6iHux4wlZVlp3PXydE7cBA",
|
|
18
|
+
"cipher_receiver": "i-V8JuCrxXkkW8HDuhyu-vIC6wY3PlAAiRGLCKmBuU8dTiVli5YHqxCP5JxlL0kouj3PdEmBO79m4yBeO-xdHU7Zeh1tw41tV63rL36zMaEY5bdFf6MN0nZZr_fanEO9of54GxdSTvkyt0TnbehQwHjxmKTN3rdf7LOWj2PR8QDGZhDJqcGb-P2bHCJByS7FkqemVVFDrITHaMgkzQrvWUqn_Y02H8xL68MlhDYpf19IGnZ_FpUxYW3JUjCUtQVrpeZI_eq4HAOI_Dz9CqghzKtgaKzbtvM8fxbyhIFzb5iztKuvtnNefBFAb9QnU4nbRNZf5cbxXZRYsQ"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"signature": {
|
|
22
|
+
"signer": "did:mdip:z3v8AuaTpa2sv416LhYnLLghNPBiqiByPhgPCMyJDvh3nEWX1AQ",
|
|
23
|
+
"signed": "2026-10-26T15:19:53.724Z",
|
|
24
|
+
"hash": "4263cea2014b2d908ee9110a5b484715ebbe4540e754a7657fa0f55849de6128",
|
|
25
|
+
"value": "19062ccf888b9e67a0cab2dd677ce5b175787ba1b4b8b9061abff97b3690f0f93a0cfb3cc282a93af5da52c4d9fa2e78e39a2ca3bb48d418f97ceb2c19ac9dae"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0D ,ψ��g�ʲ�g|�ux{������{6��� :�<�:��R���.x�,��H��|�,���
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"created":"2026-10-26T15:19:53.361Z","mdip":{"prefix":"did:mdip","registry":"hyperswarm","type":"agent","version":1},"publicJwk":{"crv":"secp256k1","kty":"EC","x":"4yZSpRtSnw91juo66BaLCFSiEIA8DKQ4CI7ztTJlJEs","y":"X2gugWUoqQu3nCezr3pSYBj28pReipxnRH23kGoPOlE"},"type":"create"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"type": "create",
|
|
3
|
+
"created": "2026-10-26T15:19:53.361Z",
|
|
4
|
+
"mdip": {
|
|
5
|
+
"version": 1,
|
|
6
|
+
"type": "agent",
|
|
7
|
+
"registry": "hyperswarm",
|
|
8
|
+
"prefix": "did:mdip"
|
|
9
|
+
},
|
|
10
|
+
"publicJwk": {
|
|
11
|
+
"kty": "EC",
|
|
12
|
+
"crv": "secp256k1",
|
|
13
|
+
"x": "4yZSpRtSnw91juo66BaLCFSiEIA8DKQ4CI7ztTJlJEs",
|
|
14
|
+
"y": "X2gugWUoqQu3nCezr3pSYBj28pReipxnRH23kGoPOlE"
|
|
15
|
+
},
|
|
16
|
+
"signature": {
|
|
17
|
+
"signed": "2026-10-26T15:19:53.365Z",
|
|
18
|
+
"hash": "365a0ced00c124622d67166d415c76cb54cb6dcace2929684d1a90fc5f4a9ca1",
|
|
19
|
+
"value": "5cc3ad400df1be015d05b448b49d788de4b6d664427fe0d99d9018a568098543525674b88da364af9936eb875166d93c01c1614bcc2c6d56c841669427c34cf3"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0D \í@
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"challenge": "did:mdip:z3v8AuabdK9jyaLmHoWNumjBkU7wTZSUZJTBepL9QQZEqXMxCgq",
|
|
3
|
+
"credentials": [],
|
|
4
|
+
"requested": 0,
|
|
5
|
+
"fulfilled": 0,
|
|
6
|
+
"match": true,
|
|
7
|
+
"responseNonce": "ui6M_7_U7KqOgZVTTk4k0uxGnr6mz5J9G40vOle7JyQQ",
|
|
8
|
+
"vps": [],
|
|
9
|
+
"responder": "did:mdip:z3v8AuaTpa2sv416LhYnLLghNPBiqiByPhgPCMyJDvh3nEWX1AQ"
|
|
10
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Install-free check of the known-answer vectors: needs only bash, sha256sum (coreutils) and OpenSSL >= 1.1.1
|
|
3
|
+
# (secp256k1 must be available; it is in stock OpenSSL builds). No npm, no network.
|
|
4
|
+
# Exit 0 and last line "ALL VECTORS OK" on success; non-zero on any failure.
|
|
5
|
+
set -uo pipefail
|
|
6
|
+
cd "$(dirname "$0")"
|
|
7
|
+
fail=0
|
|
8
|
+
ok() { echo "ok $*"; }
|
|
9
|
+
bad() { echo "FAIL $*"; fail=1; }
|
|
10
|
+
v() { openssl dgst -sha256 -verify "$1" -signature "$2" "$3" >/dev/null 2>&1; }
|
|
11
|
+
|
|
12
|
+
echo "== kav-1: synthetic secp256k1 / sha256(JCS) vector (public test key)"
|
|
13
|
+
( cd kav-1 && sha256sum -c --quiet SHA256SUMS ) && ok "kav-1 SHA256SUMS" || bad "kav-1 SHA256SUMS"
|
|
14
|
+
[ "$(openssl dgst -sha256 -r kav-1/message.bin | cut -d' ' -f1)" = "$(cat kav-1/message.sha256)" ] && ok "sha256(message.bin) == message.sha256" || bad "message hash"
|
|
15
|
+
v kav-1/pub.pem kav-1/signature.der kav-1/message.bin && ok "signature verifies" || bad "signature"
|
|
16
|
+
v kav-1/pub.pem kav-1/signature.der kav-1/message-tampered.bin && bad "tampered message verified (must not)" || ok "tampered message rejected"
|
|
17
|
+
|
|
18
|
+
echo "== mdip-challenge-1: real MDIP create operations (challenge -> response)"
|
|
19
|
+
( cd mdip-challenge-1 && sha256sum -c --quiet SHA256SUMS ) && ok "mdip-challenge-1 SHA256SUMS" || bad "mdip-challenge-1 SHA256SUMS"
|
|
20
|
+
for k in verifier-agent:verifier-agent challenge:verifier-agent responder-agent:responder-agent response:responder-agent; do
|
|
21
|
+
op=${k%%:*}; key=${k##*:}
|
|
22
|
+
v "mdip-challenge-1/$key.pub.pem" "mdip-challenge-1/$op.sig.der" "mdip-challenge-1/$op.message.bin" \
|
|
23
|
+
&& ok "$op op signed by $key key" || bad "$op op signature"
|
|
24
|
+
done
|
|
25
|
+
v mdip-challenge-1/verifier-agent.pub.pem mdip-challenge-1/response.sig.der mdip-challenge-1/response.message.bin \
|
|
26
|
+
&& bad "response verified under verifier key (must not)" || ok "response NOT valid under verifier key"
|
|
27
|
+
|
|
28
|
+
[ $fail = 0 ] && echo "ALL VECTORS OK" || { echo "VECTORS FAILED"; exit 1; }
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Second, independent-code check of the vectors using @mdip/cipher (what @mdip/keymaster and the
|
|
3
|
+
// gatekeeper use): recomputes JCS bytes from the JSON files, compares to the committed .bin files,
|
|
4
|
+
// and verifies each signature. Also checks the MDIP binding fields of the challenge fixture.
|
|
5
|
+
// Usage: node vectors/verify-with-kit.js (after npm install; no network)
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
9
|
+
import CipherNode from '@mdip/cipher/node';
|
|
10
|
+
|
|
11
|
+
const dir = path.dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
const c = new CipherNode();
|
|
13
|
+
const rd = f => fs.readFileSync(path.join(dir, f), 'utf8');
|
|
14
|
+
const js = f => JSON.parse(rd(f));
|
|
15
|
+
let fail = 0;
|
|
16
|
+
const check = (cond, msg) => { console.log(`${cond ? 'ok ' : 'FAIL'} ${msg}`); if (!cond) fail = 1; };
|
|
17
|
+
const unsigned = o => { const x = JSON.parse(JSON.stringify(o)); delete x.signature; return x; };
|
|
18
|
+
|
|
19
|
+
// kav-1
|
|
20
|
+
const signed = js('kav-1/signed.json');
|
|
21
|
+
const key = js('kav-1/test-key.json').publicJwk;
|
|
22
|
+
check(c.canonicalizeJSON(unsigned(signed)) === rd('kav-1/message.bin'), 'kav-1 message.bin == JCS(signed.json minus signature)');
|
|
23
|
+
check(c.hashJSON(unsigned(signed)) === signed.signature.hash, 'kav-1 signature.hash == sha256(JCS)');
|
|
24
|
+
check(c.verifySig(signed.signature.hash, signed.signature.value, key), 'kav-1 verifySig');
|
|
25
|
+
check(rd('kav-1/signature.hex').trim() === signed.signature.value, 'kav-1 signature.hex == signature.value');
|
|
26
|
+
|
|
27
|
+
// mdip-challenge-1
|
|
28
|
+
const dids = js('mdip-challenge-1/dids.json');
|
|
29
|
+
const op = k => js(`mdip-challenge-1/${k}.op.json`);
|
|
30
|
+
const keys = { [dids['verifier-agent']]: op('verifier-agent').publicJwk, [dids['responder-agent']]: op('responder-agent').publicJwk };
|
|
31
|
+
for (const k of ['verifier-agent', 'challenge', 'responder-agent', 'response']) {
|
|
32
|
+
const o = op(k);
|
|
33
|
+
check(c.canonicalizeJSON(unsigned(o)) === rd(`mdip-challenge-1/${k}.message.bin`), `${k} message.bin == JCS(op minus signature)`);
|
|
34
|
+
check(c.hashJSON(unsigned(o)) === o.signature.hash, `${k} signature.hash`);
|
|
35
|
+
// agent create ops are self-signed with their own publicJwk (no signer DID yet); assets by their controller
|
|
36
|
+
const signer = o.mdip.type === 'agent' ? (k === 'verifier-agent' ? dids['verifier-agent'] : dids['responder-agent']) : o.controller;
|
|
37
|
+
check(c.verifySig(o.signature.hash, o.signature.value, o.mdip.type === 'agent' ? o.publicJwk : keys[signer]), `${k} signed by ${signer === dids['verifier-agent'] ? 'verifier' : 'responder'} key`);
|
|
38
|
+
}
|
|
39
|
+
const ch = op('challenge'), re = op('response'), vr = js('mdip-challenge-1/verify-response.json');
|
|
40
|
+
check(ch.controller === dids['verifier-agent'], 'challenge controller == verifier DID (binds verifier)');
|
|
41
|
+
check(re.controller === dids['responder-agent'] && re.data.encrypted.sender === re.controller, 'response controller == encrypted.sender == responder DID');
|
|
42
|
+
check(Date.parse(re.mdip.validUntil) <= Date.parse(ch.mdip.validUntil), 'response validUntil <= challenge validUntil (expiry)');
|
|
43
|
+
check(vr.challenge === dids.challenge && vr.responder === dids['responder-agent'] && vr.match === true && !!vr.responseNonce, 'decrypted response names the challenge DID, responder, match=true, has responseNonce');
|
|
44
|
+
console.log(fail ? 'VECTORS FAILED' : 'ALL VECTORS OK');
|
|
45
|
+
process.exit(fail);
|