mdip-agent-kit 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md 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.3: offline challenge↔response binding vector + strict-expiry check). Not affiliated with SELF or Keychain. License MIT (see `LICENSE`; can be changed).
16
+ > Status: early (0.1.4: vector checks parse JSON with jq and compare expiry as epoch ms; 0.1.3 added the offline challenge↔response binding vector + strict-expiry check). Not affiliated with SELF or Keychain. License MIT (see `LICENSE`; can be changed).
17
17
 
18
18
  ## Why
19
19
 
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "mdip-agent-kit",
3
- "version": "0.1.3",
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.",
3
+ "version": "0.1.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
+ "homepage": "https://selfid.com",
5
6
  "type": "module",
6
7
  "license": "MIT",
7
8
  "bin": {
package/src/index.js CHANGED
@@ -93,6 +93,10 @@ export async function createKeymaster({ gatekeeperUrl, walletDir, passphrase, re
93
93
  * @returns {{ok: boolean, reason?: string}}
94
94
  */
95
95
  export function checkResponseExpiry(challengeValidUntil, responseValidUntil, now) {
96
+ // a timestamp without Z or an offset would be read in the verifier's local zone: reject it (fail closed)
97
+ const zoned = (t) => /(Z|[+-]\d{2}:?\d{2})$/.test(String(t));
98
+ if (challengeValidUntil && !zoned(challengeValidUntil)) return { ok: false, reason: 'challenge validUntil has no timezone' };
99
+ if (responseValidUntil && !zoned(responseValidUntil)) return { ok: false, reason: 'response validUntil has no timezone' };
96
100
  const c = challengeValidUntil ? Date.parse(challengeValidUntil) : NaN;
97
101
  const r = responseValidUntil ? Date.parse(responseValidUntil) : NaN;
98
102
  if (challengeValidUntil && !Number.isFinite(c)) return { ok: false, reason: 'challenge validUntil unparseable' };
@@ -3,7 +3,8 @@
3
3
  # equality is ALLOWED (the kit caps a response's expiry at exactly the challenge's validUntil);
4
4
  # one millisecond later is REJECTED. A missing response validUntil is REJECTED when the challenge has one.
5
5
  # Separately, at verify time both must still be in the future (now < validUntil); that needs a clock, not a vector.
6
- # Timestamps are ISO-8601 UTC with milliseconds (what MDIP writes), so a plain string compare is exact.
6
+ # Timestamps are ISO-8601 (MDIP writes UTC with ms). Since 0.1.4 they are compared as epoch ms, not strings,
7
+ # so a missing fractional part or a +00:00 offset still compares correctly; a timestamp with NO zone is rejected.
7
8
  # challenge.validUntil response.validUntil expected
8
9
  2026-10-26T16:41:19.930Z 2026-10-26T16:41:19.930Z accept equal (mdip-challenge-1/-2 are this case)
9
10
  2026-10-26T16:41:19.930Z 2026-10-26T16:41:19.929Z accept 1 ms earlier
@@ -13,3 +14,7 @@
13
14
  2026-10-26T16:41:19.930Z 2027-01-01T00:00:00.000Z reject next year
14
15
  2026-10-26T16:41:19.930Z - reject response has no validUntil
15
16
  - 2026-10-26T16:41:19.930Z accept challenge has no validUntil (nothing to cap)
17
+ 2026-10-26T16:41:19.930Z 2026-10-26T16:41:19Z accept response without ms (0.930 s earlier)
18
+ 2026-10-26T16:41:19.930Z 2026-10-26T16:41:20Z reject response without ms, 70 ms later
19
+ 2026-10-26T16:41:19.930Z 2026-10-26T09:41:19.930-07:00 accept same instant written with an offset
20
+ 2026-10-26T16:41:19.930Z 2026-10-26T16:41:19.930 reject response with no timezone (fail closed)
@@ -59,7 +59,11 @@ pt=$(bash decrypt-openssl.sh $d/verifier-agent.PUBLIC-TEST-KEY.priv.pem $d/respo
59
59
  && ok "response decrypts, Poly1305 tag OK" || bad "response decrypt"
60
60
  [ "$pt" = "$(cat $d/response.plaintext.json)" ] && ok "decrypted bytes == response.plaintext.json" || bad "plaintext mismatch"
61
61
  # 5. THE BINDING: the signed+encrypted response names this challenge DID
62
- [ "$(printf %s "$pt" | sed -n 's/^{"response":{"challenge":"\(did:mdip:[^"]*\)".*/\1/p')" = "$(did challenge)" ] \
62
+ # parse as JSON (key order independent) when jq exists; the anchored sed is only a no-jq fallback
63
+ if command -v jq >/dev/null; then bound=$(printf %s "$pt" | jq -r '.response.challenge // empty'); else
64
+ echo " (no jq: falling back to anchored sed; install jq for an encoder-independent parse)"
65
+ bound=$(printf %s "$pt" | sed -n 's/^{"response":{"challenge":"\(did:mdip:[^"]*\)".*/\1/p'); fi
66
+ [ -n "$bound" ] && [ "$bound" = "$(did challenge)" ] \
63
67
  && ok "BINDING: decrypted response.challenge == challenge DID" || bad "BINDING: response does not answer this challenge"
64
68
  printf %s "$pt" | grep -q '"match":true' && printf %s "$pt" | grep -q '"responseNonce":"[^"]\+"' && ok "response match=true, has responseNonce" || bad "response fields"
65
69
  # negative: one flipped ciphertext byte must fail the tag
@@ -68,7 +72,9 @@ bash decrypt-openssl.sh $d/verifier-agent.PUBLIC-TEST-KEY.priv.pem $d/responder-
68
72
  && bad "tampered ciphertext decrypted (must not)" || ok "tampered ciphertext rejected (tag)"; rm -f "$tmpc"
69
73
 
70
74
  echo "== strict expiry: response.validUntil <= challenge.validUntil (equal allowed, 1 ms later rejected)"
71
- expiry_ok() { [ "$1" = - ] && return 0; [ "$2" = - ] && return 1; [[ ! "$2" > "$1" ]]; }
75
+ # compare as epoch ms, not strings: accepts with/without fractional seconds; a timestamp with no Z/offset is rejected (fail closed)
76
+ tms() { [[ "$1" =~ (Z|[+-][0-9]{2}:?[0-9]{2})$ ]] || return 1; date -u -d "$1" +%s%3N 2>/dev/null; }
77
+ expiry_ok() { [ "$1" = - ] && return 0; [ "$2" = - ] && return 1; local c r; c=$(tms "$1") && r=$(tms "$2") || return 1; [ "$r" -le "$c" ]; }
72
78
  for dd in mdip-challenge-1 mdip-challenge-2; do
73
79
  c=$(jget validUntil $dd/challenge.message.bin); r=$(jget validUntil $dd/response.message.bin)
74
80
  expiry_ok "$c" "$r" && ok "$dd response $r <= challenge $c$([ "$r" = "$c" ] && echo ' (equal: allowed)')" || bad "$dd expiry"