@suveren/gateway 0.7.4 → 0.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/dist/control-plane/index.mjs +248 -58
  2. package/dist/mcp-server/http.mjs +408 -65
  3. package/dist/ui/assets/{index-CkWaRck1.css → index-BYVb_0oG.css} +1 -1
  4. package/dist/ui/assets/index-CsrM6RQr.js +110 -0
  5. package/dist/ui/index.html +2 -2
  6. package/node_modules/@hap/core/dist/index.d.mts +258 -9
  7. package/node_modules/@hap/core/dist/index.d.ts +258 -9
  8. package/node_modules/@hap/core/dist/index.js +227 -5
  9. package/node_modules/@hap/core/dist/index.mjs +213 -4
  10. package/node_modules/@hap/core/package.json +3 -2
  11. package/node_modules/@hap/core/src/did-key.ts +126 -0
  12. package/node_modules/@hap/core/src/identity.ts +21 -5
  13. package/node_modules/@hap/core/src/index.ts +3 -0
  14. package/node_modules/@hap/core/src/mandate.ts +207 -0
  15. package/node_modules/@hap/core/src/receipt.ts +74 -0
  16. package/node_modules/@hap/core/src/types.ts +81 -5
  17. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/lib/accept.js +54 -0
  18. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/lib/charset.js +10 -34
  19. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/lib/encoding.js +9 -30
  20. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/lib/language.js +15 -36
  21. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/lib/mediaType.js +16 -134
  22. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/node_modules/content-type/LICENSE +22 -0
  23. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/node_modules/content-type/README.md +71 -0
  24. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/node_modules/content-type/dist/index.d.ts +46 -0
  25. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/node_modules/content-type/dist/index.js +176 -0
  26. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/node_modules/content-type/dist/index.js.map +1 -0
  27. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/node_modules/content-type/package.json +52 -0
  28. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/package.json +16 -10
  29. package/node_modules/@types/node/README.md +1 -1
  30. package/node_modules/@types/node/buffer.buffer.d.ts +5 -5
  31. package/node_modules/@types/node/crypto.d.ts +2 -2
  32. package/node_modules/@types/node/http.d.ts +16 -0
  33. package/node_modules/@types/node/http2.d.ts +10 -2
  34. package/node_modules/@types/node/package.json +2 -2
  35. package/node_modules/@types/node/process.d.ts +52 -0
  36. package/node_modules/@types/node/quic.d.ts +210 -28
  37. package/node_modules/@types/node/sqlite.d.ts +6 -2
  38. package/node_modules/@types/node/test.d.ts +36 -0
  39. package/node_modules/fast-uri/index.js +201 -48
  40. package/node_modules/fast-uri/lib/schemes.js +9 -4
  41. package/node_modules/fast-uri/lib/utils.js +388 -91
  42. package/node_modules/fast-uri/package.json +1 -1
  43. package/node_modules/fast-uri/test/component-safe-serialization.test.js +105 -0
  44. package/node_modules/fast-uri/test/equal.test.js +31 -3
  45. package/node_modules/fast-uri/test/fixtures/uri-js-parse.json +2 -0
  46. package/node_modules/fast-uri/test/ipv6-canonical.test.js +34 -0
  47. package/node_modules/fast-uri/test/ipv6-validation.test.js +90 -0
  48. package/node_modules/fast-uri/test/malformed-percent.test.js +77 -0
  49. package/node_modules/fast-uri/test/malformed-urn.test.js +61 -0
  50. package/node_modules/fast-uri/test/parse.test.js +7 -3
  51. package/node_modules/fast-uri/test/query-fragment-normalization.test.js +33 -0
  52. package/node_modules/fast-uri/test/reserved-path-normalization.test.js +109 -0
  53. package/node_modules/fast-uri/test/scheme-validation.test.js +124 -0
  54. package/node_modules/fast-uri/test/security-normalization.test.js +101 -0
  55. package/node_modules/fast-uri/test/security.test.js +75 -3
  56. package/node_modules/fast-uri/test/urn-full-input.test.js +29 -0
  57. package/node_modules/fast-uri/test/websocket-query-preservation.test.js +24 -0
  58. package/node_modules/hono/dist/cjs/client/client.js +25 -11
  59. package/node_modules/hono/dist/cjs/client/utils.js +4 -1
  60. package/node_modules/hono/dist/cjs/context.js +4 -0
  61. package/node_modules/hono/dist/cjs/helper/accepts/accepts.js +36 -2
  62. package/node_modules/hono/dist/cjs/helper/ssg/ssg.js +1 -1
  63. package/node_modules/hono/dist/cjs/helper/ssg/utils.js +30 -10
  64. package/node_modules/hono/dist/cjs/jsx/dom/render.js +2 -0
  65. package/node_modules/hono/dist/cjs/middleware/cache/index.js +1 -1
  66. package/node_modules/hono/dist/cjs/middleware/cors/index.js +1 -1
  67. package/node_modules/hono/dist/cjs/middleware/csrf/index.js +1 -1
  68. package/node_modules/hono/dist/cjs/middleware/etag/digest.js +1 -1
  69. package/node_modules/hono/dist/cjs/middleware/etag/index.js +3 -3
  70. package/node_modules/hono/dist/cjs/middleware/pretty-json/index.js +3 -1
  71. package/node_modules/hono/dist/cjs/request.js +8 -4
  72. package/node_modules/hono/dist/cjs/router/linear-router/router.js +7 -2
  73. package/node_modules/hono/dist/cjs/router/pattern-router/router.js +3 -9
  74. package/node_modules/hono/dist/cjs/router/reg-exp-router/node.js +10 -3
  75. package/node_modules/hono/dist/cjs/router/reg-exp-router/router.js +47 -83
  76. package/node_modules/hono/dist/cjs/router/reg-exp-router/trie.js +2 -1
  77. package/node_modules/hono/dist/cjs/router/trie-router/node.js +46 -69
  78. package/node_modules/hono/dist/cjs/router/trie-router/router.js +3 -11
  79. package/node_modules/hono/dist/cjs/router/utils.js +27 -0
  80. package/node_modules/hono/dist/cjs/utils/body.js +15 -3
  81. package/node_modules/hono/dist/cjs/utils/cookie.js +1 -1
  82. package/node_modules/hono/dist/cjs/utils/ipaddr.js +5 -3
  83. package/node_modules/hono/dist/cjs/utils/stream.js +7 -1
  84. package/node_modules/hono/dist/cjs/utils/url.js +9 -1
  85. package/node_modules/hono/dist/client/client.js +25 -11
  86. package/node_modules/hono/dist/client/utils.js +4 -1
  87. package/node_modules/hono/dist/context.js +4 -0
  88. package/node_modules/hono/dist/helper/accepts/accepts.js +36 -2
  89. package/node_modules/hono/dist/helper/ssg/ssg.js +1 -1
  90. package/node_modules/hono/dist/helper/ssg/utils.js +30 -10
  91. package/node_modules/hono/dist/jsx/dom/render.js +2 -0
  92. package/node_modules/hono/dist/middleware/cache/index.js +1 -1
  93. package/node_modules/hono/dist/middleware/cors/index.js +1 -1
  94. package/node_modules/hono/dist/middleware/csrf/index.js +1 -1
  95. package/node_modules/hono/dist/middleware/etag/digest.js +1 -1
  96. package/node_modules/hono/dist/middleware/etag/index.js +3 -3
  97. package/node_modules/hono/dist/middleware/pretty-json/index.js +3 -1
  98. package/node_modules/hono/dist/request.js +8 -4
  99. package/node_modules/hono/dist/router/linear-router/router.js +7 -2
  100. package/node_modules/hono/dist/router/pattern-router/router.js +3 -9
  101. package/node_modules/hono/dist/router/reg-exp-router/node.js +6 -2
  102. package/node_modules/hono/dist/router/reg-exp-router/router.js +53 -84
  103. package/node_modules/hono/dist/router/reg-exp-router/trie.js +2 -1
  104. package/node_modules/hono/dist/router/trie-router/node.js +46 -69
  105. package/node_modules/hono/dist/router/trie-router/router.js +3 -11
  106. package/node_modules/hono/dist/router/utils.js +5 -0
  107. package/node_modules/hono/dist/types/context.d.ts +4 -0
  108. package/node_modules/hono/dist/types/router/reg-exp-router/node.d.ts +3 -0
  109. package/node_modules/hono/dist/types/router/trie-router/node.d.ts +1 -2
  110. package/node_modules/hono/dist/types/router/trie-router/router.d.ts +0 -1
  111. package/node_modules/hono/dist/types/router/utils.d.ts +1 -0
  112. package/node_modules/hono/dist/types/utils/url.d.ts +4 -0
  113. package/node_modules/hono/dist/utils/body.js +15 -3
  114. package/node_modules/hono/dist/utils/cookie.js +1 -1
  115. package/node_modules/hono/dist/utils/ipaddr.js +5 -3
  116. package/node_modules/hono/dist/utils/stream.js +7 -1
  117. package/node_modules/hono/dist/utils/url.js +9 -1
  118. package/node_modules/hono/package.json +1 -1
  119. package/node_modules/is-plain-object/README.md +39 -95
  120. package/node_modules/is-plain-object/dist/is-plain-object.js +0 -2
  121. package/node_modules/is-plain-object/is-plain-object.d.ts +6 -1
  122. package/node_modules/is-plain-object/package.json +8 -34
  123. package/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +4 -3
  124. package/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +4 -3
  125. package/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +4 -3
  126. package/node_modules/jose/dist/types/jwks/remote.d.ts +4 -4
  127. package/node_modules/jose/dist/types/jws/general/verify.d.ts +3 -3
  128. package/node_modules/jose/dist/types/jwt/encrypt.d.ts +12 -17
  129. package/node_modules/jose/dist/types/jwt/sign.d.ts +8 -14
  130. package/node_modules/jose/dist/types/jwt/unsecured.d.ts +9 -15
  131. package/node_modules/jose/dist/types/types.d.ts +4 -2
  132. package/node_modules/jose/dist/webapi/jwe/compact/encrypt.js +30 -8
  133. package/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js +8 -4
  134. package/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js +6 -13
  135. package/node_modules/jose/dist/webapi/jwe/general/decrypt.js +19 -19
  136. package/node_modules/jose/dist/webapi/jwe/general/encrypt.js +32 -21
  137. package/node_modules/jose/dist/webapi/jwk/embedded.js +15 -1
  138. package/node_modules/jose/dist/webapi/jwk/thumbprint.js +11 -5
  139. package/node_modules/jose/dist/webapi/jwks/local.js +45 -53
  140. package/node_modules/jose/dist/webapi/jwks/remote.js +82 -103
  141. package/node_modules/jose/dist/webapi/jws/compact/sign.js +10 -9
  142. package/node_modules/jose/dist/webapi/jws/flattened/sign.js +2 -1
  143. package/node_modules/jose/dist/webapi/jws/flattened/verify.js +8 -7
  144. package/node_modules/jose/dist/webapi/jws/general/sign.js +5 -3
  145. package/node_modules/jose/dist/webapi/jws/general/verify.js +51 -21
  146. package/node_modules/jose/dist/webapi/jwt/decrypt.js +7 -9
  147. package/node_modules/jose/dist/webapi/jwt/encrypt.js +21 -50
  148. package/node_modules/jose/dist/webapi/jwt/sign.js +8 -41
  149. package/node_modules/jose/dist/webapi/jwt/unsecured.js +21 -42
  150. package/node_modules/jose/dist/webapi/key/generate_key_pair.js +6 -2
  151. package/node_modules/jose/dist/webapi/key/generate_secret.js +7 -6
  152. package/node_modules/jose/dist/webapi/key/import.js +16 -12
  153. package/node_modules/jose/dist/webapi/lib/asn1.js +7 -2
  154. package/node_modules/jose/dist/webapi/lib/content_encryption.js +7 -15
  155. package/node_modules/jose/dist/webapi/lib/deflate.js +8 -0
  156. package/node_modules/jose/dist/webapi/lib/helpers.js +1 -1
  157. package/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +85 -28
  158. package/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +45 -13
  159. package/node_modules/jose/dist/webapi/lib/jwk_metadata.js +20 -0
  160. package/node_modules/jose/dist/webapi/lib/jws_sign.js +47 -36
  161. package/node_modules/jose/dist/webapi/lib/jws_verify.js +77 -45
  162. package/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +82 -47
  163. package/node_modules/jose/dist/webapi/lib/key.js +24 -9
  164. package/node_modules/jose/dist/webapi/lib/key_management.js +10 -4
  165. package/node_modules/jose/dist/webapi/lib/key_options.js +6 -0
  166. package/node_modules/jose/dist/webapi/lib/options.js +26 -0
  167. package/node_modules/jose/dist/webapi/lib/type_checks.js +11 -13
  168. package/node_modules/jose/package.json +1 -1
  169. package/package.json +2 -2
  170. package/dist/ui/assets/index-0Q2eNytX.js +0 -110
  171. package/node_modules/@modelcontextprotocol/sdk/node_modules/negotiator/HISTORY.md +0 -114
@@ -0,0 +1,126 @@
1
+ /**
2
+ * did:key — encode/decode for KEY-BEARING DIDs (HAP v0.6).
3
+ *
4
+ * A real `did:key` is self-certifying: the public key IS the identifier, so
5
+ * substituting the key produces a DIFFERENT DID and no key directory is ever
6
+ * consulted. That property is what the Owner Mandate design stands on
7
+ * (protocol.md → "Identity DIDs vs signing DIDs"): a signing DID MUST be
8
+ * key-bearing, and verification uses the key carried in the identifier —
9
+ * deliberately, there is no `public_key` field anywhere on the wire.
10
+ *
11
+ * Format (W3C did:key method, Ed25519):
12
+ * did:key:z<base58btc( 0xed 0x01 ‖ 32-byte-public-key )>
13
+ * `z` is the multibase prefix for base58btc; `0xed 0x01` is the multicodec
14
+ * varint for ed25519-pub. The result always starts `did:key:z6Mk`.
15
+ *
16
+ * Scope: Ed25519 only — the one signing curve this protocol version uses.
17
+ * Anything else (including the reference implementation's legacy decorative
18
+ * `did:key:<uuid-fragment>` identifiers) decodes as NOT key-bearing.
19
+ */
20
+
21
+ const B58_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
22
+ const B58_MAP: Record<string, number> = {};
23
+ for (let i = 0; i < B58_ALPHABET.length; i++) B58_MAP[B58_ALPHABET[i]] = i;
24
+
25
+ /** multicodec ed25519-pub (0xed) as unsigned varint, followed by key bytes. */
26
+ const ED25519_MULTICODEC = Uint8Array.from([0xed, 0x01]);
27
+ const ED25519_KEY_BYTES = 32;
28
+
29
+ function base58btcEncode(bytes: Uint8Array): string {
30
+ // Count leading zero bytes — they encode as leading '1's.
31
+ let zeros = 0;
32
+ while (zeros < bytes.length && bytes[zeros] === 0) zeros++;
33
+
34
+ const digits: number[] = [];
35
+ for (let i = zeros; i < bytes.length; i++) {
36
+ let carry = bytes[i];
37
+ for (let j = 0; j < digits.length; j++) {
38
+ carry += digits[j] * 256;
39
+ digits[j] = carry % 58;
40
+ carry = (carry / 58) | 0;
41
+ }
42
+ while (carry > 0) {
43
+ digits.push(carry % 58);
44
+ carry = (carry / 58) | 0;
45
+ }
46
+ }
47
+
48
+ let out = '1'.repeat(zeros);
49
+ for (let i = digits.length - 1; i >= 0; i--) out += B58_ALPHABET[digits[i]];
50
+ return out;
51
+ }
52
+
53
+ function base58btcDecode(s: string): Uint8Array {
54
+ let zeros = 0;
55
+ while (zeros < s.length && s[zeros] === '1') zeros++;
56
+
57
+ const bytes: number[] = [];
58
+ for (let i = zeros; i < s.length; i++) {
59
+ const val = B58_MAP[s[i]];
60
+ if (val === undefined) throw new Error(`invalid base58 character "${s[i]}"`);
61
+ let carry = val;
62
+ for (let j = 0; j < bytes.length; j++) {
63
+ carry += bytes[j] * 58;
64
+ bytes[j] = carry & 0xff;
65
+ carry >>= 8;
66
+ }
67
+ while (carry > 0) {
68
+ bytes.push(carry & 0xff);
69
+ carry >>= 8;
70
+ }
71
+ }
72
+
73
+ const out = new Uint8Array(zeros + bytes.length);
74
+ for (let i = 0; i < bytes.length; i++) out[zeros + i] = bytes[bytes.length - 1 - i];
75
+ return out;
76
+ }
77
+
78
+ /** Encode a 32-byte Ed25519 public key as a key-bearing `did:key:z6Mk…`. */
79
+ export function encodeDidKey(publicKey: Uint8Array): string {
80
+ if (publicKey.length !== ED25519_KEY_BYTES) {
81
+ throw new Error(`INVALID_KEY: expected ${ED25519_KEY_BYTES} bytes, got ${publicKey.length}`);
82
+ }
83
+ const prefixed = new Uint8Array(ED25519_MULTICODEC.length + publicKey.length);
84
+ prefixed.set(ED25519_MULTICODEC, 0);
85
+ prefixed.set(publicKey, ED25519_MULTICODEC.length);
86
+ return `did:key:z${base58btcEncode(prefixed)}`;
87
+ }
88
+
89
+ /**
90
+ * Decode a key-bearing `did:key` to its Ed25519 public key bytes.
91
+ *
92
+ * @throws Error prefixed `NOT_KEY_BEARING:` for anything that is not a valid
93
+ * base58btc-multibase Ed25519 did:key — including the legacy decorative
94
+ * `did:key:<uuid-fragment>` identifiers, other multibase prefixes, and other
95
+ * key types. The error name is the point: under the mandate design, a
96
+ * non-key-bearing signing DID must fail STRUCTURALLY, never fall back.
97
+ */
98
+ export function decodeDidKey(did: string): Uint8Array {
99
+ if (!did.startsWith('did:key:z')) {
100
+ throw new Error(`NOT_KEY_BEARING: ${JSON.stringify(did)} is not a base58btc did:key`);
101
+ }
102
+ let decoded: Uint8Array;
103
+ try {
104
+ decoded = base58btcDecode(did.slice('did:key:z'.length));
105
+ } catch (err) {
106
+ throw new Error(`NOT_KEY_BEARING: ${(err as Error).message}`);
107
+ }
108
+ if (
109
+ decoded.length !== ED25519_MULTICODEC.length + ED25519_KEY_BYTES ||
110
+ decoded[0] !== ED25519_MULTICODEC[0] ||
111
+ decoded[1] !== ED25519_MULTICODEC[1]
112
+ ) {
113
+ throw new Error('NOT_KEY_BEARING: not an ed25519-pub multicodec payload');
114
+ }
115
+ return decoded.slice(ED25519_MULTICODEC.length);
116
+ }
117
+
118
+ /** True iff the DID decodes as a key-bearing Ed25519 did:key. Never throws. */
119
+ export function isKeyBearingDid(did: string): boolean {
120
+ try {
121
+ decodeDidKey(did);
122
+ return true;
123
+ } catch {
124
+ return false;
125
+ }
126
+ }
@@ -8,7 +8,7 @@
8
8
  * - {@link deriveIdentityLine} — the human-readable footer line for a subject.
9
9
  */
10
10
 
11
- import type { Subject } from './types';
11
+ import type { OwnerMandate, Subject } from './types';
12
12
 
13
13
  export interface SubjectValidation {
14
14
  valid: boolean;
@@ -19,12 +19,25 @@ export interface SubjectValidation {
19
19
  * Enforce the Identity-Assurance invariants on a single subject:
20
20
  * - `self_declared` ⇒ `low` / `self`, no disclosed name.
21
21
  * - `as_vouched` ⇒ `high` / `as`, `verifier` required.
22
- * - `eudi` ⇒ `high` / `external`, `verifier` + `owner_signature` required.
22
+ * - `eudi` ⇒ `high` / `external`, `verifier` required and, when the
23
+ * carrying attestation's `owner_mandates` are supplied, a corresponding
24
+ * entry with `binding:"eudi"` for this subject's DID.
23
25
  * - `disclose.name` only at `assurance:"high"`.
26
+ *
27
+ * v0.6: `Subject.owner_signature` is deprecated and IGNORED here — it signed
28
+ * the identity claim, not the mandate (see the field's deprecation note). The
29
+ * signature-bearing object is the attestation's `owner_mandates` entry, which
30
+ * is payload-level context this per-subject check cannot see on its own; pass
31
+ * `opts.ownerMandates` to enforce the eudi ⇒ mandate-entry rule, omit it to
32
+ * validate subject shape alone (pre-0.6 callers keep their behaviour minus
33
+ * the retired owner_signature requirement).
24
34
  */
25
- export function validateSubject(subject: Subject): SubjectValidation {
35
+ export function validateSubject(
36
+ subject: Subject,
37
+ opts?: { ownerMandates?: OwnerMandate[] },
38
+ ): SubjectValidation {
26
39
  const errors: string[] = [];
27
- const { did, assurance, method, trust_root, verifier, disclose, owner_signature } = subject;
40
+ const { did, assurance, method, trust_root, verifier, disclose } = subject;
28
41
 
29
42
  if (!did) errors.push('subject.did is required');
30
43
 
@@ -39,7 +52,10 @@ export function validateSubject(subject: Subject): SubjectValidation {
39
52
  } else if (method === 'eudi') {
40
53
  if (trust_root !== 'external') errors.push('eudi requires trust_root "external"');
41
54
  if (!verifier) errors.push('eudi requires a verifier');
42
- if (!owner_signature) errors.push('eudi requires an owner_signature');
55
+ if (opts?.ownerMandates !== undefined) {
56
+ const entry = opts.ownerMandates.find(m => m.did === did && m.binding === 'eudi');
57
+ if (!entry) errors.push('eudi requires an owner_mandates entry with binding "eudi" for this DID');
58
+ }
43
59
  } else {
44
60
  errors.push(`high assurance requires method "as_vouched" or "eudi", got "${method}"`);
45
61
  }
@@ -13,3 +13,6 @@ export * from './frame';
13
13
  export * from './attestation';
14
14
  export * from './gatekeeper';
15
15
  export * from './profiles';
16
+ export * from './did-key';
17
+ export * from './mandate';
18
+ export * from './receipt';
@@ -0,0 +1,207 @@
1
+ /**
2
+ * Owner Mandate Signatures (HAP v0.6) — the `HAP-mandate` projection, the
3
+ * `HAP-approval` object, and their verification.
4
+ *
5
+ * The human signs BEFORE the AS does, so they cannot sign the finished
6
+ * attestation (`attestation_id`/`issued_at` do not exist yet). They sign a
7
+ * mandate PROJECTION: a canonical object every field of which is known at
8
+ * approval time and reconstructible from the finished attestation — so a
9
+ * verifier rebuilds it from the attestation it already holds and checks the
10
+ * signature with the key carried in the owner's DID. No side channel, no
11
+ * second fetch, no key directory. See protocol.md → "Owner Mandate Signatures".
12
+ *
13
+ * Verification here requires NO trust in the AS. What it cannot do is tell the
14
+ * verifier WHOSE key signed — confirming the DID belongs to the expected
15
+ * person is the out-of-band step (protocol.md → "Identity DIDs vs signing
16
+ * DIDs"), and it is the honest cost of cold verification.
17
+ */
18
+
19
+ import * as ed from '@noble/ed25519';
20
+ import type { Attestation, AttestationPayload, OwnerMandate } from './types';
21
+ import { canonicalize } from './canonicalize';
22
+ import { decodeDidKey } from './did-key';
23
+
24
+ /** The object the owner signs — a canonical projection of the mandate. */
25
+ export interface MandateProjection {
26
+ typ: 'HAP-mandate';
27
+ /** Projection/canonicalization version. A verifier MUST pin it. */
28
+ version: '0.6';
29
+ profile_id: string;
30
+ /** The signing owner's own DID. MUST be a member of `resolved_owners`. */
31
+ owner_did: string;
32
+ bounds_hash: string;
33
+ context_hash: string;
34
+ execution_context_hash: string;
35
+ gate_content_hashes: Record<string, string>;
36
+ /** Included iff the attestation carries one — binds ciphertext AND the
37
+ * frozen approver set, the swap this mechanism exists to stop. */
38
+ intent_disclosure_hash?: string;
39
+ commitment_mode: string;
40
+ /** The replay defence: the human signs how long the authority lives. */
41
+ expires_at: number;
42
+ nonce: string;
43
+ }
44
+
45
+ /** Per-action approval, signed by the owner in `review` mode. Signing a
46
+ * `reject` matters as much as a `commit`: a rejection the AS can discard is a
47
+ * rejection that never happened. */
48
+ export interface ApprovalObject {
49
+ typ: 'HAP-approval';
50
+ version: '0.6';
51
+ proposal_id: string;
52
+ attestation_id: string;
53
+ decision: 'commit' | 'reject';
54
+ /** What was approved: the receipt's contentHash where the profile binds
55
+ * content; otherwise sha256 over the JCS of the proposal's argument set. */
56
+ content_hash: string;
57
+ decided_at: number;
58
+ nonce: string;
59
+ }
60
+
61
+ export class MandateError extends Error {
62
+ constructor(
63
+ public code:
64
+ | 'MANDATE_SIGNATURE_INVALID'
65
+ | 'APPROVAL_SIGNATURE_INVALID'
66
+ | 'NOT_KEY_BEARING'
67
+ | 'OWNER_NOT_RESOLVED'
68
+ | 'MALFORMED_ATTESTATION',
69
+ message: string,
70
+ ) {
71
+ super(`${code}: ${message}`);
72
+ this.name = 'MandateError';
73
+ }
74
+ }
75
+
76
+ /**
77
+ * Rebuild the projection a given `owner_mandates` entry signed, from the
78
+ * attestation's own signed fields. Field absence is defined, not incidental:
79
+ * `intent_disclosure_hash` is included iff the attestation carries one.
80
+ */
81
+ export function buildMandateProjection(
82
+ payload: AttestationPayload,
83
+ entry: Pick<OwnerMandate, 'did' | 'nonce'>,
84
+ ): MandateProjection {
85
+ const { profile_id, bounds_hash, context_hash, execution_context_hash, gate_content_hashes, commitment_mode, expires_at } = payload;
86
+ if (!bounds_hash || !context_hash || !commitment_mode) {
87
+ throw new MandateError('MALFORMED_ATTESTATION', 'mandate projection requires bounds_hash, context_hash and commitment_mode');
88
+ }
89
+ const projection: MandateProjection = {
90
+ typ: 'HAP-mandate',
91
+ version: '0.6',
92
+ profile_id,
93
+ owner_did: entry.did,
94
+ bounds_hash,
95
+ context_hash,
96
+ execution_context_hash,
97
+ gate_content_hashes,
98
+ commitment_mode,
99
+ expires_at,
100
+ nonce: entry.nonce,
101
+ };
102
+ if (payload.intent_disclosure_hash !== undefined) {
103
+ projection.intent_disclosure_hash = payload.intent_disclosure_hash;
104
+ }
105
+ return projection;
106
+ }
107
+
108
+ /** The exact bytes an owner signs: RFC 8785 (JCS) canonical UTF-8. */
109
+ export function mandateSigningBytes(projection: MandateProjection): Uint8Array {
110
+ return new TextEncoder().encode(canonicalize(projection));
111
+ }
112
+
113
+ /** The exact bytes an owner signs for a per-action approval. */
114
+ export function approvalSigningBytes(approval: ApprovalObject): Uint8Array {
115
+ return new TextEncoder().encode(canonicalize(approval));
116
+ }
117
+
118
+ function base64urlToBytes(s: string): Uint8Array {
119
+ const base64 = s.replace(/-/g, '+').replace(/_/g, '/');
120
+ const padding = base64.length % 4 === 0 ? '' : '='.repeat(4 - (base64.length % 4));
121
+ return new Uint8Array(Buffer.from(base64 + padding, 'base64'));
122
+ }
123
+
124
+ function bytesToBase64url(bytes: Uint8Array): string {
125
+ return Buffer.from(bytes).toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
126
+ }
127
+
128
+ /**
129
+ * Sign a mandate projection with a raw Ed25519 private key — the `raw`
130
+ * binding: tests and CI only, no custody claim. WebAuthn (`webauthn`) and
131
+ * wallet (`eudi`) bindings sign the same bytes through their own custody;
132
+ * they are implemented by the platforms that hold those keys, not here.
133
+ */
134
+ export async function signMandateProjection(
135
+ projection: MandateProjection,
136
+ privateKey: Uint8Array,
137
+ ): Promise<string> {
138
+ const sig = await ed.signAsync(mandateSigningBytes(projection), privateKey);
139
+ return bytesToBase64url(sig);
140
+ }
141
+
142
+ /** Sign an approval object with a raw Ed25519 private key (`raw` binding). */
143
+ export async function signApproval(approval: ApprovalObject, privateKey: Uint8Array): Promise<string> {
144
+ const sig = await ed.signAsync(approvalSigningBytes(approval), privateKey);
145
+ return bytesToBase64url(sig);
146
+ }
147
+
148
+ /**
149
+ * Verify ONE `owner_mandates` entry against the attestation that carries it.
150
+ *
151
+ * Steps (protocol.md → "Verification procedure", steps 4 of 6): membership in
152
+ * `resolved_owners`, key-bearing DID, projection reconstruction, Ed25519 over
153
+ * JCS bytes. The DID is authoritative over `alg` — a disagreement is
154
+ * MANDATE_SIGNATURE_INVALID, never a fallback to the claimed algorithm.
155
+ *
156
+ * What this deliberately does NOT verify: that the DID belongs to the person
157
+ * the verifier expects (out-of-band, step 5) and the AS's own signature over
158
+ * the attestation (verifyAttestationSignature, step 1).
159
+ */
160
+ export async function verifyOwnerMandate(attestation: Attestation, entry: OwnerMandate): Promise<void> {
161
+ const owners = attestation.payload.resolved_owners ?? [];
162
+ if (!owners.includes(entry.did)) {
163
+ throw new MandateError('OWNER_NOT_RESOLVED', `signing DID ${entry.did} is not in resolved_owners`);
164
+ }
165
+ if (entry.alg !== 'EdDSA') {
166
+ // The only key type a did:key carries in this protocol version is Ed25519;
167
+ // an entry claiming otherwise disagrees with its own DID.
168
+ throw new MandateError('MANDATE_SIGNATURE_INVALID', `alg ${entry.alg} disagrees with the DID's key type (DID is authoritative)`);
169
+ }
170
+ let publicKey: Uint8Array;
171
+ try {
172
+ publicKey = decodeDidKey(entry.did);
173
+ } catch (err) {
174
+ throw new MandateError('NOT_KEY_BEARING', (err as Error).message);
175
+ }
176
+
177
+ const projection = buildMandateProjection(attestation.payload, entry);
178
+ const ok = await ed.verifyAsync(base64urlToBytes(entry.signature), mandateSigningBytes(projection), publicKey);
179
+ if (!ok) {
180
+ throw new MandateError('MANDATE_SIGNATURE_INVALID', `owner mandate signature by ${entry.did} does not verify`);
181
+ }
182
+ }
183
+
184
+ /** Verify every `owner_mandates` entry an attestation carries. Resolves to the
185
+ * verified entries; an attestation with none resolves to `[]` (the v0.5
186
+ * posture — nothing to check, and nothing claimed). */
187
+ export async function verifyOwnerMandates(attestation: Attestation): Promise<OwnerMandate[]> {
188
+ const entries = attestation.payload.owner_mandates ?? [];
189
+ for (const entry of entries) {
190
+ await verifyOwnerMandate(attestation, entry);
191
+ }
192
+ return entries;
193
+ }
194
+
195
+ /** Verify an approval signature against a signer's key-bearing DID. */
196
+ export async function verifyApproval(approval: ApprovalObject, signature: string, signerDid: string): Promise<void> {
197
+ let publicKey: Uint8Array;
198
+ try {
199
+ publicKey = decodeDidKey(signerDid);
200
+ } catch (err) {
201
+ throw new MandateError('NOT_KEY_BEARING', (err as Error).message);
202
+ }
203
+ const ok = await ed.verifyAsync(base64urlToBytes(signature), approvalSigningBytes(approval), publicKey);
204
+ if (!ok) {
205
+ throw new MandateError('APPROVAL_SIGNATURE_INVALID', `approval signature by ${signerDid} does not verify`);
206
+ }
207
+ }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Execution receipts (HAP v0.5/v0.6) — the wire type and holder-side
3
+ * verification. Until v0.6 this library had no receipt surface at all; every
4
+ * verifier hand-assembled the strip→canonicalize→verify dance. This module is
5
+ * that dance, once.
6
+ *
7
+ * Receipt payloads are camelCase on the wire (unlike the snake_case
8
+ * attestation payload) — a shipped inconsistency v0.6 chose to document
9
+ * rather than break (changelog.md → "Renames and terminology").
10
+ */
11
+
12
+ import * as ed from '@noble/ed25519';
13
+ import type { ContentBinding, Subject } from './types';
14
+ import { canonicalize } from './canonicalize';
15
+
16
+ /** Signed execution receipt — protocol.md → "Receipt Payload Schema". */
17
+ export interface ReceiptPayload {
18
+ id: string;
19
+ groupId?: string | null;
20
+ userId?: string;
21
+ boundsHash: string;
22
+ profileId: string;
23
+ /** Downstream tool name. Audit metadata only — never a dispatch key. */
24
+ action: string;
25
+ /** Semantic category — drives cumulative bucketing and bounds dispatch. */
26
+ actionType: string;
27
+ executionContext: Record<string, unknown>;
28
+ cumulativeState?: Record<string, unknown>;
29
+ limits?: Record<string, unknown>;
30
+ timestamp: number;
31
+ /** v0.6 — hash of the bound content, computed by the Gatekeeper, copied
32
+ * verbatim by the AS. The AS never sees the content. */
33
+ contentHash?: string;
34
+ /** v0.6 — the binding declaration echoed into the signed receipt, so a
35
+ * verifier knows exactly what `contentHash` covers. */
36
+ contentBinding?: Pick<ContentBinding, 'version' | 'kind' | 'fields' | 'required_fields' | 'appliesTo'>;
37
+ /** v0.6 — disclosed subset of the attestation's identity overlay. */
38
+ subjects?: Subject[];
39
+ /** v0.6 — review path: the proposal this receipt executed. */
40
+ proposalId?: string;
41
+ /** v0.6 — review path: the owner's HAP-approval signature (or its sha256)
42
+ * for the executed proposal. */
43
+ approvalSignature?: string;
44
+ /** Ed25519 over the JCS-canonical payload (this field excluded), base64url. */
45
+ signature: string;
46
+ }
47
+
48
+ /**
49
+ * Verify a receipt's AS signature: strip `signature`, JCS-canonicalize the
50
+ * rest, Ed25519-verify against the AS public key (hex). This is holder-side
51
+ * verification — it needs the COMPLETE receipt; a redacted public view cannot
52
+ * be re-verified this way (protocol.md → "Receipt Verification").
53
+ *
54
+ * Content is checked separately: where `contentHash` is present, recompute it
55
+ * from the held artifact via the content-binding module and compare.
56
+ *
57
+ * @throws Error prefixed `INVALID_SIGNATURE:` when verification fails.
58
+ */
59
+ export async function verifyReceiptSignature(receipt: ReceiptPayload, publicKeyHex: string): Promise<void> {
60
+ const { signature, ...unsigned } = receipt;
61
+ if (!signature) {
62
+ throw new Error('INVALID_SIGNATURE: receipt carries no signature');
63
+ }
64
+ const bytes = new TextEncoder().encode(canonicalize(unsigned));
65
+ const base64 = signature.replace(/-/g, '+').replace(/_/g, '/');
66
+ const padding = base64.length % 4 === 0 ? '' : '='.repeat(4 - (base64.length % 4));
67
+ const sigBytes = new Uint8Array(Buffer.from(base64 + padding, 'base64'));
68
+ const publicKeyBytes = new Uint8Array(Buffer.from(publicKeyHex, 'hex'));
69
+
70
+ const ok = await ed.verifyAsync(sigBytes, bytes, publicKeyBytes).catch(() => false);
71
+ if (!ok) {
72
+ throw new Error('INVALID_SIGNATURE: receipt signature verification failed');
73
+ }
74
+ }
@@ -19,7 +19,7 @@ export interface ResolvedDomain {
19
19
 
20
20
  export interface AttestationPayload {
21
21
  attestation_id: string;
22
- version: '0.3' | '0.4' | '0.5';
22
+ version: '0.3' | '0.4' | '0.5' | '0.6';
23
23
  profile_id: string;
24
24
  /** v0.3 (deprecated) — hash of the authorization frame */
25
25
  frame_hash?: string;
@@ -67,12 +67,55 @@ export interface AttestationPayload {
67
67
  *
68
68
  * Cryptographically bound in the signed payload so a compromised SP cannot
69
69
  * silently flip 'review' → 'automatic'. Absent on v0.3 attestations.
70
+ * `review_above_cap` (v0.5): automatic below the signed caps, proposal above.
70
71
  */
71
- commitment_mode?: 'automatic' | 'review';
72
+ commitment_mode?: 'automatic' | 'review' | 'review_above_cap';
73
+ /**
74
+ * v0.6 (Owner Mandate Signatures) — the Decision Owner's own signature(s)
75
+ * over the mandate projection ({@link MandateProjection}), one entry per
76
+ * co-signing owner. Carried INSIDE the AS-signed payload, so the AS attests
77
+ * to having received it and cannot strip it without invalidating its own
78
+ * signature. Optional and additive: an attestation without it behaves as
79
+ * before (the v0.5 posture — the AS asserts, nobody co-signs).
80
+ */
81
+ owner_mandates?: OwnerMandate[];
72
82
  issued_at: number;
73
83
  expires_at: number;
74
84
  }
75
85
 
86
+ /** Mandate-assurance axis — what custody signed the mandate. Independent of
87
+ * identity assurance ({@link Subject.method}). */
88
+ export type MandateBinding = 'raw' | 'webauthn' | 'eudi';
89
+
90
+ /** Which surface showed the owner what they signed. A DECLARATION, not a proof
91
+ * — no verifier can check it; see protocol.md → Owner Mandate Signatures. */
92
+ export type SigningSurface = 'gatekeeper_local' | 'as_web' | 'wallet_display';
93
+
94
+ /**
95
+ * v0.6 — one owner's signature over the mandate projection.
96
+ *
97
+ * There is deliberately NO `public_key` field, and it MUST NOT be added: the
98
+ * verification key is carried in the DID itself (key-bearing `did:key`), so a
99
+ * non-key-bearing DID fails STRUCTURALLY instead of validating against a key
100
+ * the AS could have substituted. `alg` is kept only as curve-confusion
101
+ * hygiene; if it disagrees with the DID's key type, the DID is authoritative.
102
+ */
103
+ export interface OwnerMandate {
104
+ /** The signing owner's key-bearing DID. MUST be a member of `resolved_owners`. */
105
+ did: string;
106
+ /** Signature algorithm hint. The DID's multicodec wins on any disagreement. */
107
+ alg: 'EdDSA' | 'ES256';
108
+ /** base64url (no padding) signature over the JCS bytes of the mandate projection. */
109
+ signature: string;
110
+ /** When the owner signed (unix seconds). */
111
+ signed_at: number;
112
+ /** Defence-in-depth against duplicate issuance by an HONEST AS only —
113
+ * AS-side nonce enforcement is no defence against the AS itself. */
114
+ nonce: string;
115
+ binding: MandateBinding;
116
+ signing_surface?: SigningSurface;
117
+ }
118
+
76
119
  /**
77
120
  * v0.6 Identity Assurance — a signed overlay binding a Decision Owner's verified
78
121
  * real-world identity to the attestation, gated by HOW the identity was verified.
@@ -98,8 +141,11 @@ export interface Subject {
98
141
  /** When the underlying verification was performed (unix seconds). */
99
142
  verified_at?: number;
100
143
  /**
101
- * eudi only (Phase 2) the owner's per-event wallet signature, making the
102
- * identity claim non-repudiable independent of the AS. Null/absent otherwise.
144
+ * @deprecated v0.6replaced by {@link AttestationPayload.owner_mandates}.
145
+ * This field signed the wrong object (the identity claim, not what was
146
+ * committed to) and was welded to one method. Implementations MUST NOT emit
147
+ * it; verifiers MAY ignore it on artifacts that carry it. Kept readable for
148
+ * audit of pre-0.6 artifacts only.
103
149
  */
104
150
  owner_signature?: string | null;
105
151
  }
@@ -340,6 +386,15 @@ export interface ProfileContextField {
340
386
  description?: string;
341
387
  displayName?: string;
342
388
  format?: 'email' | 'domain' | 'url' | 'currency';
389
+ /**
390
+ * v0.6 — what this field NAMES on the read path. `counterparty` = the other
391
+ * party to a communication (matched against an item's participants);
392
+ * `resource` = the container an item belongs to (a direct attribute match —
393
+ * and a resource scope enforced on writes MUST also bind reads). Absent →
394
+ * implementations MAY infer `counterparty` from `format: email|domain`
395
+ * (transitional; the explicit declaration is normative).
396
+ */
397
+ scopeKind?: 'counterparty' | 'resource';
343
398
  constraint?: FieldConstraint;
344
399
  enum?: string[];
345
400
  }
@@ -636,7 +691,28 @@ export interface GatekeeperRequest {
636
691
  * Structured error from Gatekeeper verification.
637
692
  */
638
693
  export interface GatekeeperError {
639
- code: 'BOUND_EXCEEDED' | 'CUMULATIVE_LIMIT_EXCEEDED' | 'INVALID_SIGNATURE' | 'TTL_EXPIRED' | 'FRAME_MISMATCH' | 'BOUNDS_MISMATCH' | 'CONTEXT_MISMATCH' | 'DOMAIN_NOT_COVERED' | 'INVALID_PROFILE' | 'MALFORMED_ATTESTATION';
694
+ code:
695
+ | 'BOUND_EXCEEDED'
696
+ | 'CUMULATIVE_LIMIT_EXCEEDED'
697
+ | 'INVALID_SIGNATURE'
698
+ | 'TTL_EXPIRED'
699
+ | 'FRAME_MISMATCH'
700
+ | 'BOUNDS_MISMATCH'
701
+ | 'CONTEXT_MISMATCH'
702
+ | 'DOMAIN_NOT_COVERED'
703
+ | 'INVALID_PROFILE'
704
+ | 'MALFORMED_ATTESTATION'
705
+ // v0.5/v0.6 receipt-path codes a Gatekeeper must recognize as definitive
706
+ // rejections (protocol.md → Pre-flight Receipt Request):
707
+ | 'INVALID_ACTION_TYPE'
708
+ | 'ATTESTATION_REVOKED'
709
+ | 'APPROVAL_REQUIRED'
710
+ | 'IDEMPOTENCY_MISMATCH'
711
+ // v0.6 owner-mandate codes (protocol.md → Owner Mandate Signatures):
712
+ | 'MANDATE_SIGNATURE_REQUIRED'
713
+ | 'MANDATE_SIGNATURE_INVALID'
714
+ | 'APPROVAL_SIGNATURE_REQUIRED'
715
+ | 'APPROVAL_SIGNATURE_INVALID';
640
716
  field?: string;
641
717
  message: string;
642
718
  bound?: string | number;
@@ -0,0 +1,54 @@
1
+ /*!
2
+ * negotiator
3
+ * Copyright(c) 2026 Blake Embrey
4
+ * MIT Licensed
5
+ */
6
+
7
+ 'use strict';
8
+
9
+ var contentType = require('content-type');
10
+
11
+ /**
12
+ * Module exports.
13
+ * @private
14
+ */
15
+
16
+ module.exports = parseAccept;
17
+
18
+ /**
19
+ * Parse an Accept-style header.
20
+ * @private
21
+ */
22
+
23
+ function parseAccept(header) {
24
+ var values = [];
25
+ var index = 0;
26
+
27
+ while (index < header.length) {
28
+ var start = skipOptionalWhitespace(header, index);
29
+ var parsed = contentType.parse(header, { comma: true, start: start });
30
+
31
+ // `content-type` normalizes the type, but accept methods return original casing.
32
+ parsed.type = header.slice(start, start + parsed.type.length);
33
+ values.push(parsed);
34
+
35
+ index = parsed.index + 1;
36
+ }
37
+
38
+ return values;
39
+ }
40
+
41
+ /**
42
+ * Skip optional whitespace.
43
+ * @private
44
+ */
45
+
46
+ function skipOptionalWhitespace(header, index) {
47
+ var cursor = index;
48
+
49
+ while (header.charCodeAt(cursor) === 0x20 || header.charCodeAt(cursor) === 0x09) {
50
+ cursor++;
51
+ }
52
+
53
+ return cursor;
54
+ }