@real-life/trust-protocol 0.3.2 → 0.4.0

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 (264) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +187 -78
  3. package/dist/ack.d.ts +84 -0
  4. package/dist/ack.d.ts.map +1 -0
  5. package/dist/ack.js +114 -0
  6. package/dist/ack.js.map +1 -0
  7. package/dist/adapters/vti-mediator.d.ts +154 -0
  8. package/dist/adapters/vti-mediator.d.ts.map +1 -0
  9. package/dist/adapters/vti-mediator.js +621 -0
  10. package/dist/adapters/vti-mediator.js.map +1 -0
  11. package/dist/anchor.d.ts +226 -0
  12. package/dist/anchor.d.ts.map +1 -0
  13. package/dist/anchor.js +347 -0
  14. package/dist/anchor.js.map +1 -0
  15. package/dist/{holder.d.ts → carrier-holder.d.ts} +1 -1
  16. package/dist/carrier-holder.d.ts.map +1 -0
  17. package/dist/{holder.js → carrier-holder.js} +5 -4
  18. package/dist/carrier-holder.js.map +1 -0
  19. package/dist/carrier-identity.js +4 -4
  20. package/dist/carrier-identity.js.map +1 -1
  21. package/dist/carrier.d.ts.map +1 -1
  22. package/dist/carrier.js +4 -3
  23. package/dist/carrier.js.map +1 -1
  24. package/dist/ceremony.d.ts +3 -2
  25. package/dist/ceremony.d.ts.map +1 -1
  26. package/dist/ceremony.js +16 -26
  27. package/dist/ceremony.js.map +1 -1
  28. package/dist/codec.d.ts +46 -0
  29. package/dist/codec.d.ts.map +1 -0
  30. package/dist/codec.js +410 -0
  31. package/dist/codec.js.map +1 -0
  32. package/dist/continuity.d.ts +67 -0
  33. package/dist/continuity.d.ts.map +1 -0
  34. package/dist/continuity.js +110 -0
  35. package/dist/continuity.js.map +1 -0
  36. package/dist/core.d.ts +4 -0
  37. package/dist/core.d.ts.map +1 -1
  38. package/dist/core.js.map +1 -1
  39. package/dist/crypto.d.ts +23 -7
  40. package/dist/crypto.d.ts.map +1 -1
  41. package/dist/crypto.js +54 -20
  42. package/dist/crypto.js.map +1 -1
  43. package/dist/delivery.d.ts +31 -3
  44. package/dist/delivery.d.ts.map +1 -1
  45. package/dist/delivery.js +75 -28
  46. package/dist/delivery.js.map +1 -1
  47. package/dist/encounter/ceremony.d.ts +37 -0
  48. package/dist/encounter/ceremony.d.ts.map +1 -0
  49. package/dist/encounter/ceremony.js +662 -0
  50. package/dist/encounter/ceremony.js.map +1 -0
  51. package/dist/encounter.d.ts +91 -1
  52. package/dist/encounter.d.ts.map +1 -1
  53. package/dist/encounter.js +191 -12
  54. package/dist/encounter.js.map +1 -1
  55. package/dist/engine.d.ts +291 -0
  56. package/dist/engine.d.ts.map +1 -0
  57. package/dist/engine.js +1395 -0
  58. package/dist/engine.js.map +1 -0
  59. package/dist/entropy.d.ts +28 -0
  60. package/dist/entropy.d.ts.map +1 -0
  61. package/dist/entropy.js +96 -0
  62. package/dist/entropy.js.map +1 -0
  63. package/dist/events.d.ts +177 -0
  64. package/dist/events.d.ts.map +1 -0
  65. package/dist/events.js +2 -0
  66. package/dist/events.js.map +1 -0
  67. package/dist/fixtures.d.ts +30 -0
  68. package/dist/fixtures.d.ts.map +1 -0
  69. package/dist/fixtures.js +155 -0
  70. package/dist/fixtures.js.map +1 -0
  71. package/dist/forge.d.ts +47 -0
  72. package/dist/forge.d.ts.map +1 -0
  73. package/dist/forge.js +20 -0
  74. package/dist/forge.js.map +1 -0
  75. package/dist/group-star.d.ts +251 -0
  76. package/dist/group-star.d.ts.map +1 -0
  77. package/dist/group-star.js +348 -0
  78. package/dist/group-star.js.map +1 -0
  79. package/dist/holder-api.d.ts +137 -0
  80. package/dist/holder-api.d.ts.map +1 -0
  81. package/dist/holder-api.js +132 -0
  82. package/dist/holder-api.js.map +1 -0
  83. package/dist/holder-state-v1.d.ts +801 -0
  84. package/dist/holder-state-v1.d.ts.map +1 -0
  85. package/dist/holder-state-v1.js +2 -0
  86. package/dist/holder-state-v1.js.map +1 -0
  87. package/dist/identity-state.d.ts +43 -0
  88. package/dist/identity-state.d.ts.map +1 -0
  89. package/dist/identity-state.js +345 -0
  90. package/dist/identity-state.js.map +1 -0
  91. package/dist/identity.d.ts +24 -2
  92. package/dist/identity.d.ts.map +1 -1
  93. package/dist/identity.js +70 -11
  94. package/dist/identity.js.map +1 -1
  95. package/dist/index.d.ts +26 -1
  96. package/dist/index.d.ts.map +1 -1
  97. package/dist/index.js +77 -29
  98. package/dist/index.js.map +1 -1
  99. package/dist/internal.d.ts +36 -0
  100. package/dist/internal.d.ts.map +1 -0
  101. package/dist/internal.js +22 -0
  102. package/dist/internal.js.map +1 -0
  103. package/dist/introduction/holder.d.ts +18 -0
  104. package/dist/introduction/holder.d.ts.map +1 -0
  105. package/dist/introduction/holder.js +757 -0
  106. package/dist/introduction/holder.js.map +1 -0
  107. package/dist/introduction.d.ts +101 -0
  108. package/dist/introduction.d.ts.map +1 -0
  109. package/dist/introduction.js +132 -0
  110. package/dist/introduction.js.map +1 -0
  111. package/dist/invariants.d.ts +43 -0
  112. package/dist/invariants.d.ts.map +1 -0
  113. package/dist/invariants.js +883 -0
  114. package/dist/invariants.js.map +1 -0
  115. package/dist/keys-seed.d.ts +7 -0
  116. package/dist/keys-seed.d.ts.map +1 -0
  117. package/dist/keys-seed.js +133 -0
  118. package/dist/keys-seed.js.map +1 -0
  119. package/dist/log-memory.d.ts +12 -0
  120. package/dist/log-memory.d.ts.map +1 -0
  121. package/dist/log-memory.js +101 -0
  122. package/dist/log-memory.js.map +1 -0
  123. package/dist/membership/holder.d.ts +35 -0
  124. package/dist/membership/holder.d.ts.map +1 -0
  125. package/dist/membership/holder.js +852 -0
  126. package/dist/membership/holder.js.map +1 -0
  127. package/dist/membership.d.ts +92 -0
  128. package/dist/membership.d.ts.map +1 -0
  129. package/dist/membership.js +157 -0
  130. package/dist/membership.js.map +1 -0
  131. package/dist/ports.d.ts +237 -0
  132. package/dist/ports.d.ts.map +1 -0
  133. package/dist/ports.js +2 -0
  134. package/dist/ports.js.map +1 -0
  135. package/dist/profile.d.ts +56 -0
  136. package/dist/profile.d.ts.map +1 -0
  137. package/dist/profile.js +193 -0
  138. package/dist/profile.js.map +1 -0
  139. package/dist/prompts.d.ts +14 -0
  140. package/dist/prompts.d.ts.map +1 -0
  141. package/dist/prompts.js +69 -0
  142. package/dist/prompts.js.map +1 -0
  143. package/dist/receive.d.ts +133 -0
  144. package/dist/receive.d.ts.map +1 -0
  145. package/dist/receive.js +298 -0
  146. package/dist/receive.js.map +1 -0
  147. package/dist/results.d.ts +158 -0
  148. package/dist/results.d.ts.map +1 -0
  149. package/dist/results.js +21 -0
  150. package/dist/results.js.map +1 -0
  151. package/dist/schemas.d.ts.map +1 -1
  152. package/dist/schemas.js +42 -38
  153. package/dist/schemas.js.map +1 -1
  154. package/dist/sha256.d.ts +3 -0
  155. package/dist/sha256.d.ts.map +1 -0
  156. package/dist/sha256.js +69 -0
  157. package/dist/sha256.js.map +1 -0
  158. package/dist/star.d.ts +31 -0
  159. package/dist/star.d.ts.map +1 -0
  160. package/dist/star.js +56 -0
  161. package/dist/star.js.map +1 -0
  162. package/dist/state-builder.d.ts +42 -0
  163. package/dist/state-builder.d.ts.map +1 -0
  164. package/dist/state-builder.js +100 -0
  165. package/dist/state-builder.js.map +1 -0
  166. package/dist/state.d.ts +853 -0
  167. package/dist/state.d.ts.map +1 -0
  168. package/dist/state.js +36 -0
  169. package/dist/state.js.map +1 -0
  170. package/dist/store-contract.d.ts +11 -0
  171. package/dist/store-contract.d.ts.map +1 -0
  172. package/dist/store-contract.js +189 -0
  173. package/dist/store-contract.js.map +1 -0
  174. package/dist/store-memory.d.ts +8 -0
  175. package/dist/store-memory.d.ts.map +1 -0
  176. package/dist/store-memory.js +17 -0
  177. package/dist/store-memory.js.map +1 -0
  178. package/dist/testing.d.ts +22 -0
  179. package/dist/testing.d.ts.map +1 -0
  180. package/dist/testing.js +21 -0
  181. package/dist/testing.js.map +1 -0
  182. package/dist/trust/continuity.d.ts +71 -0
  183. package/dist/trust/continuity.d.ts.map +1 -0
  184. package/dist/trust/continuity.js +1216 -0
  185. package/dist/trust/continuity.js.map +1 -0
  186. package/dist/trust/duties.d.ts +67 -0
  187. package/dist/trust/duties.d.ts.map +1 -0
  188. package/dist/trust/duties.js +179 -0
  189. package/dist/trust/duties.js.map +1 -0
  190. package/dist/trust/entries.d.ts +139 -0
  191. package/dist/trust/entries.d.ts.map +1 -0
  192. package/dist/trust/entries.js +694 -0
  193. package/dist/trust/entries.js.map +1 -0
  194. package/dist/trust/group-star.d.ts +43 -0
  195. package/dist/trust/group-star.d.ts.map +1 -0
  196. package/dist/trust/group-star.js +188 -0
  197. package/dist/trust/group-star.js.map +1 -0
  198. package/dist/trust/mapping.d.ts +56 -0
  199. package/dist/trust/mapping.d.ts.map +1 -0
  200. package/dist/trust/mapping.js +584 -0
  201. package/dist/trust/mapping.js.map +1 -0
  202. package/dist/trust/profile.d.ts +25 -0
  203. package/dist/trust/profile.d.ts.map +1 -0
  204. package/dist/trust/profile.js +249 -0
  205. package/dist/trust/profile.js.map +1 -0
  206. package/dist/trust/star.d.ts +208 -0
  207. package/dist/trust/star.d.ts.map +1 -0
  208. package/dist/trust/star.js +588 -0
  209. package/dist/trust/star.js.map +1 -0
  210. package/dist/trust/state.d.ts +83 -0
  211. package/dist/trust/state.d.ts.map +1 -0
  212. package/dist/trust/state.js +154 -0
  213. package/dist/trust/state.js.map +1 -0
  214. package/dist/util-freeze.d.ts +3 -0
  215. package/dist/util-freeze.d.ts.map +1 -0
  216. package/dist/util-freeze.js +11 -0
  217. package/dist/util-freeze.js.map +1 -0
  218. package/dist/views.d.ts +147 -0
  219. package/dist/views.d.ts.map +1 -0
  220. package/dist/views.js +268 -0
  221. package/dist/views.js.map +1 -0
  222. package/dist/visibility.d.ts +5 -5
  223. package/dist/visibility.d.ts.map +1 -1
  224. package/dist/visibility.js +22 -28
  225. package/dist/visibility.js.map +1 -1
  226. package/dist/wire.d.ts +178 -84
  227. package/dist/wire.d.ts.map +1 -1
  228. package/dist/wire.js.map +1 -1
  229. package/package.json +56 -10
  230. package/schemas/holder-state-v1.schema.json +3880 -0
  231. package/dist/holder.d.ts.map +0 -1
  232. package/dist/holder.js.map +0 -1
  233. package/dist/probe/acks.d.ts +0 -27
  234. package/dist/probe/acks.d.ts.map +0 -1
  235. package/dist/probe/acks.js +0 -152
  236. package/dist/probe/acks.js.map +0 -1
  237. package/dist/probe/continuity.d.ts +0 -20
  238. package/dist/probe/continuity.d.ts.map +0 -1
  239. package/dist/probe/continuity.js +0 -805
  240. package/dist/probe/continuity.js.map +0 -1
  241. package/dist/probe/deps.d.ts +0 -61
  242. package/dist/probe/deps.d.ts.map +0 -1
  243. package/dist/probe/deps.js +0 -54
  244. package/dist/probe/deps.js.map +0 -1
  245. package/dist/probe/encounter.d.ts +0 -26
  246. package/dist/probe/encounter.d.ts.map +0 -1
  247. package/dist/probe/encounter.js +0 -938
  248. package/dist/probe/encounter.js.map +0 -1
  249. package/dist/probe/introduce.d.ts +0 -62
  250. package/dist/probe/introduce.d.ts.map +0 -1
  251. package/dist/probe/introduce.js +0 -306
  252. package/dist/probe/introduce.js.map +0 -1
  253. package/dist/probe/membership.d.ts +0 -96
  254. package/dist/probe/membership.d.ts.map +0 -1
  255. package/dist/probe/membership.js +0 -467
  256. package/dist/probe/membership.js.map +0 -1
  257. package/dist/probe/trust.d.ts +0 -156
  258. package/dist/probe/trust.d.ts.map +0 -1
  259. package/dist/probe/trust.js +0 -1233
  260. package/dist/probe/trust.js.map +0 -1
  261. package/dist/probe.d.ts +0 -7
  262. package/dist/probe.d.ts.map +0 -1
  263. package/dist/probe.js +0 -42
  264. package/dist/probe.js.map +0 -1
@@ -0,0 +1,110 @@
1
+ // continuity — continuity-probe@1 and continuity-mapping@1 (Trust Layer
2
+ // 0.31 §6a, tasks continuity-probe/0.1 and continuity-mapping/0.1): the
3
+ // pure wire constructions over raw X25519 shared secrets (lib Stage 2,
4
+ // PR 4c). The holder's trust module (trust/continuity.ts) builds and
5
+ // verifies through these with secrets from its KeyProvider. Byte-compatible
6
+ // with the continuity cases of vectors/visibility.json
7
+ // (test/trust-continuity.test.mjs).
8
+ //
9
+ // k_p = HKDF(X25519(newPairX_sender, newPairX_recipient),
10
+ // "rltp/visibility/blind/probe/" || senderNewPair || "/" || recipientNewPair) (6720)
11
+ // entry = HMAC(k_p, ownPriorPairAnchor bytes) (6730)
12
+ // chunk = { body: { type: "continuity-probe@1", probe, seq, last, blinded[256] },
13
+ // proof: { mac: HMAC(k_p, JCS(body)) } } (6670)
14
+ // mac1 = HMAC(HKDF(X25519(priorPairX_sender, priorPairX_addressee), "rltp/visibility/mac/cont1"), JCS(body))
15
+ // mac2 = HMAC(HKDF(X25519(newPairX_sender, newPairX_addressee), "rltp/visibility/mac/cont2"), JCS(body)) (6880)
16
+ //
17
+ // The entries are padded with random 32-byte values in the MAC encoding
18
+ // to the next multiple of 256 (an empty set to 256: one all-padding
19
+ // chunk), a padding value colliding with any other value resampled; the
20
+ // padded union is sorted once and sliced into 256-entry chunks, seq 1…n,
21
+ // exactly one last (6760–6780). Padding bytes come from the caller's
22
+ // `pad`, so vectors replay; this module draws none itself.
23
+ import { jcs, makeValidator, calOK } from './core.js';
24
+ import { SCHEMAS } from './schemas.js';
25
+ import { b64uOf, hkdf, platformSubtle } from './crypto.js';
26
+ import { macU } from './anchor.js';
27
+ const VAL = makeValidator(SCHEMAS);
28
+ const schemaOk = (file, data) => VAL.validate(data, SCHEMAS[file], SCHEMAS[file]).length === 0;
29
+ /** Exactly this many entries per probe chunk (6670, 6760). */
30
+ export const PROBE_CHUNK = 256;
31
+ const nonZero = (shared) => {
32
+ if (shared.every((b) => b === 0))
33
+ throw new Error('all-zero shared secret (Trust 6970)');
34
+ };
35
+ /** k_p of one direction from the new pair secret (6720). */
36
+ export async function probeKeyOf(shared, sender, recipient, subtle = platformSubtle()) {
37
+ nonZero(shared);
38
+ return hkdf(shared, `rltp/visibility/blind/probe/${sender}/${recipient}`, 32, subtle);
39
+ }
40
+ /** One probe entry: HMAC(k_p, anchor) in its u form (6730, 6800). */
41
+ export const blindPrior = (k, anchor, subtle) => macU(k, anchor, subtle);
42
+ /** A padding value: 32 random bytes in the MAC encoding (6760). */
43
+ export const padValue = (bytes) => {
44
+ if (bytes.length !== 32)
45
+ throw new RangeError('a probe padding value is 32 bytes');
46
+ return 'u' + b64uOf(bytes);
47
+ };
48
+ /**
49
+ * The chunks of one probe: the own prior pair anchors blinded under k_p,
50
+ * padded to the next multiple of 256 by values from `pad` (each called
51
+ * again where its value collides), sorted once, sliced by 256 (6730,
52
+ * 6760–6780). `probe` is the probe sequence in its wire form (6680).
53
+ */
54
+ export async function buildProbeChunks(k, probe, priors, pad, subtle = platformSubtle()) {
55
+ const entries = [];
56
+ for (const anchor of new Set(priors))
57
+ entries.push(await blindPrior(k, anchor, subtle));
58
+ const used = new Set(entries);
59
+ const total = Math.max(PROBE_CHUNK, Math.ceil(entries.length / PROBE_CHUNK) * PROBE_CHUNK);
60
+ while (entries.length < total) {
61
+ let v = padValue(pad());
62
+ while (used.has(v))
63
+ v = padValue(pad());
64
+ used.add(v);
65
+ entries.push(v);
66
+ }
67
+ entries.sort();
68
+ const chunks = [];
69
+ for (let i = 0; i * PROBE_CHUNK < entries.length; i++) {
70
+ const body = { type: 'continuity-probe@1', probe, seq: String(i + 1), last: (i + 1) * PROBE_CHUNK >= entries.length, blinded: entries.slice(i * PROBE_CHUNK, (i + 1) * PROBE_CHUNK) };
71
+ chunks.push({ body, proof: { mac: await macU(k, jcs(body), subtle) } });
72
+ }
73
+ return chunks;
74
+ }
75
+ /** Is this a schema-valid continuity-probe@1 chunk (exactly 256 unique entries)? */
76
+ export const probeChunkOk = (chunk) => schemaOk('visibility-continuity-probe.schema.json', chunk);
77
+ /** Does the chunk's MAC verify under k_p? */
78
+ export async function probeChunkMacOk(k, chunk, subtle) {
79
+ return (await macU(k, jcs(chunk.body), subtle)) === chunk.proof.mac;
80
+ }
81
+ /** The two MAC keys of a continuity mapping (6880): mac1 under the prior
82
+ * relationship secret, mac2 under the new one. */
83
+ export async function continuityMacKeys(sharedPrior, sharedNew, subtle) {
84
+ nonZero(sharedPrior);
85
+ nonZero(sharedNew);
86
+ return { k1: await hkdf(sharedPrior, 'rltp/visibility/mac/cont1', 32, subtle), k2: await hkdf(sharedNew, 'rltp/visibility/mac/cont2', 32, subtle) };
87
+ }
88
+ /** continuity-mapping@1 over its body (6880): the sender's prior and new
89
+ * pair secrets toward the addressee. */
90
+ export async function assembleContinuityMapping(body, sharedPrior, sharedNew, subtle) {
91
+ const { k1, k2 } = await continuityMacKeys(sharedPrior, sharedNew, subtle);
92
+ const msg = jcs(body);
93
+ return { body, proof: { mac1: await macU(k1, msg, subtle), mac2: await macU(k2, msg, subtle) } };
94
+ }
95
+ /** Do both MACs verify (6970 step 5), under the receiver's prior and new
96
+ * pair secrets toward the sender? */
97
+ export async function continuityMacsOk(m, sharedPrior, sharedNew, subtle) {
98
+ const { k1, k2 } = await continuityMacKeys(sharedPrior, sharedNew, subtle);
99
+ const msg = jcs(m.body);
100
+ return (await macU(k1, msg, subtle)) === m.proof.mac1 && (await macU(k2, msg, subtle)) === m.proof.mac2;
101
+ }
102
+ /** Step 1 of 6940: the schema and a calendar-valid issuedAt. */
103
+ export const continuityMappingOk = (m) => schemaOk('visibility-continuity-mapping.schema.json', m) && calOK(m.body.issuedAt);
104
+ /** 2290: the record side of a fresh tuple is the party whose new pair
105
+ * anchor is the smaller by byte order (did:key strings are ASCII). Either
106
+ * party can grind its anchor to take either side, so being the record
107
+ * side grants nothing: neither side chains without the counterpart's
108
+ * mapping verified under the prior key (trust/continuity.ts, follow-up 14). */
109
+ export const isRecordSide = (ownNew, counterpartNew) => ownNew < counterpartNew;
110
+ //# sourceMappingURL=continuity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"continuity.js","sourceRoot":"","sources":["../src/continuity.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,wEAAwE;AACxE,uEAAuE;AACvE,qEAAq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AAI,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,IAAI,CAAA;AACzG,CAAC;AAED,gEAAgE;AAChE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAU,EAAW,EAAE,CACzD,QAAQ,CAAC,2CAA2C,EAAE,CAAC,CAAC,IAAI,KAAK,CAAE,CAAuB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;AAE3G;;;;gFAIgF;AAChF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAc,EAAE,cAAsB,EAAW,EAAE,CAAC,MAAM,GAAG,cAAc,CAAA","sourcesContent":["// continuity — continuity-probe@1 and continuity-mapping@1 (Trust Layer\n// 0.31 §6a, tasks continuity-probe/0.1 and continuity-mapping/0.1): the\n// pure wire constructions over raw X25519 shared secrets (lib Stage 2,\n// PR 4c). The holder's trust module (trust/continuity.ts) builds and\n// verifies through these with secrets from its KeyProvider. Byte-compatible\n// with the continuity cases of vectors/visibility.json\n// (test/trust-continuity.test.mjs).\n//\n// k_p = HKDF(X25519(newPairX_sender, newPairX_recipient),\n// \"rltp/visibility/blind/probe/\" || senderNewPair || \"/\" || recipientNewPair) (6720)\n// entry = HMAC(k_p, ownPriorPairAnchor bytes) (6730)\n// chunk = { body: { type: \"continuity-probe@1\", probe, seq, last, blinded[256] },\n// proof: { mac: HMAC(k_p, JCS(body)) } } (6670)\n// mac1 = HMAC(HKDF(X25519(priorPairX_sender, priorPairX_addressee), \"rltp/visibility/mac/cont1\"), JCS(body))\n// mac2 = HMAC(HKDF(X25519(newPairX_sender, newPairX_addressee), \"rltp/visibility/mac/cont2\"), JCS(body)) (6880)\n//\n// The entries are padded with random 32-byte values in the MAC encoding\n// to the next multiple of 256 (an empty set to 256: one all-padding\n// chunk), a padding value colliding with any other value resampled; the\n// padded union is sorted once and sliced into 256-entry chunks, seq 1…n,\n// exactly one last (6760–6780). Padding bytes come from the caller's\n// `pad`, so vectors replay; this module draws none itself.\nimport { jcs, makeValidator, calOK } from './core.js'\nimport { SCHEMAS } from './schemas.js'\nimport { b64uOf, hkdf, platformSubtle } from './crypto.js'\nimport { macU } from './anchor.js'\n\nconst VAL = makeValidator(SCHEMAS)\nconst schemaOk = (file: string, data: unknown): boolean => VAL.validate(data, SCHEMAS[file]!, SCHEMAS[file]!).length === 0\n\n/** Exactly this many entries per probe chunk (6670, 6760). */\nexport const PROBE_CHUNK = 256\n\nexport type ProbeChunk = { body: { type: 'continuity-probe@1', probe: string, seq: string, last: boolean, blinded: string[] }, proof: { mac: string } }\nexport type ContinuityMappingBody = { type: 'continuity-mapping@1', prior: string, next: string, to: string, revision: string, issuedAt: string }\nexport type ContinuityMapping = { body: ContinuityMappingBody, proof: { mac1: string, mac2: string } }\n\nconst nonZero = (shared: Uint8Array): void => {\n if (shared.every((b) => b === 0)) throw new Error('all-zero shared secret (Trust 6970)')\n}\n\n/** k_p of one direction from the new pair secret (6720). */\nexport async function probeKeyOf (shared: Uint8Array, sender: string, recipient: string, subtle: SubtleCrypto = platformSubtle()): Promise<Uint8Array> {\n nonZero(shared)\n return hkdf(shared, `rltp/visibility/blind/probe/${sender}/${recipient}`, 32, subtle)\n}\n\n/** One probe entry: HMAC(k_p, anchor) in its u form (6730, 6800). */\nexport const blindPrior = (k: Uint8Array, anchor: string, subtle?: SubtleCrypto): Promise<string> => macU(k, anchor, subtle)\n\n/** A padding value: 32 random bytes in the MAC encoding (6760). */\nexport const padValue = (bytes: Uint8Array): string => {\n if (bytes.length !== 32) throw new RangeError('a probe padding value is 32 bytes')\n return 'u' + b64uOf(bytes)\n}\n\n/**\n * The chunks of one probe: the own prior pair anchors blinded under k_p,\n * padded to the next multiple of 256 by values from `pad` (each called\n * again where its value collides), sorted once, sliced by 256 (6730,\n * 6760–6780). `probe` is the probe sequence in its wire form (6680).\n */\nexport async function buildProbeChunks (k: Uint8Array, probe: string, priors: Iterable<string>, pad: () => Uint8Array, subtle: SubtleCrypto = platformSubtle()): Promise<ProbeChunk[]> {\n const entries: string[] = []\n for (const anchor of new Set(priors)) entries.push(await blindPrior(k, anchor, subtle))\n const used = new Set(entries)\n const total = Math.max(PROBE_CHUNK, Math.ceil(entries.length / PROBE_CHUNK) * PROBE_CHUNK)\n while (entries.length < total) {\n let v = padValue(pad())\n while (used.has(v)) v = padValue(pad())\n used.add(v)\n entries.push(v)\n }\n entries.sort()\n const chunks: ProbeChunk[] = []\n for (let i = 0; i * PROBE_CHUNK < entries.length; i++) {\n const body = { type: 'continuity-probe@1' as const, probe, seq: String(i + 1), last: (i + 1) * PROBE_CHUNK >= entries.length, blinded: entries.slice(i * PROBE_CHUNK, (i + 1) * PROBE_CHUNK) }\n chunks.push({ body, proof: { mac: await macU(k, jcs(body), subtle) } })\n }\n return chunks\n}\n\n/** Is this a schema-valid continuity-probe@1 chunk (exactly 256 unique entries)? */\nexport const probeChunkOk = (chunk: unknown): boolean => schemaOk('visibility-continuity-probe.schema.json', chunk)\n\n/** Does the chunk's MAC verify under k_p? */\nexport async function probeChunkMacOk (k: Uint8Array, chunk: ProbeChunk, subtle?: SubtleCrypto): Promise<boolean> {\n return (await macU(k, jcs(chunk.body), subtle)) === chunk.proof.mac\n}\n\n/** The two MAC keys of a continuity mapping (6880): mac1 under the prior\n * relationship secret, mac2 under the new one. */\nexport async function continuityMacKeys (sharedPrior: Uint8Array, sharedNew: Uint8Array, subtle?: SubtleCrypto): Promise<{ k1: Uint8Array, k2: Uint8Array }> {\n nonZero(sharedPrior); nonZero(sharedNew)\n return { k1: await hkdf(sharedPrior, 'rltp/visibility/mac/cont1', 32, subtle), k2: await hkdf(sharedNew, 'rltp/visibility/mac/cont2', 32, subtle) }\n}\n\n/** continuity-mapping@1 over its body (6880): the sender's prior and new\n * pair secrets toward the addressee. */\nexport async function assembleContinuityMapping (body: ContinuityMappingBody, sharedPrior: Uint8Array, sharedNew: Uint8Array, subtle?: SubtleCrypto): Promise<ContinuityMapping> {\n const { k1, k2 } = await continuityMacKeys(sharedPrior, sharedNew, subtle)\n const msg = jcs(body)\n return { body, proof: { mac1: await macU(k1, msg, subtle), mac2: await macU(k2, msg, subtle) } }\n}\n\n/** Do both MACs verify (6970 step 5), under the receiver's prior and new\n * pair secrets toward the sender? */\nexport async function continuityMacsOk (m: ContinuityMapping, sharedPrior: Uint8Array, sharedNew: Uint8Array, subtle?: SubtleCrypto): Promise<boolean> {\n const { k1, k2 } = await continuityMacKeys(sharedPrior, sharedNew, subtle)\n const msg = jcs(m.body)\n return (await macU(k1, msg, subtle)) === m.proof.mac1 && (await macU(k2, msg, subtle)) === m.proof.mac2\n}\n\n/** Step 1 of 6940: the schema and a calendar-valid issuedAt. */\nexport const continuityMappingOk = (m: unknown): boolean =>\n schemaOk('visibility-continuity-mapping.schema.json', m) && calOK((m as ContinuityMapping).body.issuedAt)\n\n/** 2290: the record side of a fresh tuple is the party whose new pair\n * anchor is the smaller by byte order (did:key strings are ASCII). Either\n * party can grind its anchor to take either side, so being the record\n * side grants nothing: neither side chains without the counterpart's\n * mapping verified under the prior key (trust/continuity.ts, follow-up 14). */\nexport const isRecordSide = (ownNew: string, counterpartNew: string): boolean => ownNew < counterpartNew\n"]}
package/dist/core.d.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  export type Json = string | number | boolean | null | Json[] | {
2
2
  [k: string]: Json;
3
3
  };
4
+ /** A JSON object (the codec's `anyObj`: an object, contents open). */
5
+ export type JsonObject = {
6
+ [field: string]: Json;
7
+ };
4
8
  /** RFC 8785 subset for the ASCII I-JSON forms this stack ships. */
5
9
  export declare const jcs: (o: unknown) => string;
6
10
  export declare const B58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
@@ -1 +1 @@
1
- {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAeA,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,I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AAC,MAAM,KAAK,CAAC,CAAA;YAC9D,IAAI,GAAG,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS;gBAAE,IAAI,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;YAC3F,IAAI,CAAC,GAAG,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS;gBAAE,IAAI,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;QAC9F,CAAC;QACD,KAAK,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAa;YAAE,IAAI,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;QACjG,OAAO,IAAI,CAAA;IACb,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;AAChD,CAAC","sourcesContent":["// core — the form layer: the canonical rules every RLTP artifact obeys.\n//\n// One implementation of the canonical form (JCS subset, multibase\n// encodings, digest equality over DECODED bytes, timestamp\n// normalization) and the JSON-Schema subset validator. The conformance\n// runner, the reference engine and every simulator delegate here.\n//\n// Predicates exist ONCE — that is the point. Weakening a rule here fails\n// the conformance runner's self-tests rather than silently changing what\n// some user interface accepts.\n//\n// Dependency-free and environment-free: no node:*, no DOM, no WebCrypto.\n// Everything here is synchronous and pure.\n\n// ── JCS (RFC 8785 subset for the ASCII I-JSON forms this stack ships) ──\nexport type Json = string | number | boolean | null | Json[] | { [k: string]: Json }\n\n/** RFC 8785 subset for the ASCII I-JSON forms this stack ships. */\nexport const jcs = (o: unknown): string => {\n if (o === undefined) throw new Error('jcs: undefined is not serializable')\n // RFC 8785 operates on Unicode strings — a lone surrogate is not one,\n // and a conformant implementation MUST error rather than canonicalize\n // it (review 3, B-1: divergent digests between implementations)\n if (typeof o === 'string' && !(o as unknown as { isWellFormed(): boolean }).isWellFormed()) throw new Error('jcs: lone surrogate')\n if (typeof o === 'number' && !Number.isFinite(o)) throw new Error('jcs: non-finite number')\n if (Array.isArray(o)) {\n // a sparse array is not a JSON value: map() skips holes and join()\n // erases them, so [empty] and [] would COLLIDE on one digest\n // (review 4, B-3) — reject instead of silently canonicalizing\n for (let i = 0; i < o.length; i++) if (!(i in o)) throw new Error('jcs: sparse array')\n // non-index own properties (arr.x = 1) and symbol keys would be\n // silently DROPPED and collide with the bare array (review 6, B-2)\n if (Object.getOwnPropertyNames(o).length !== o.length + 1 /* 'length' itself */ || Object.getOwnPropertySymbols(o).length > 0) throw new Error('jcs: array with extra own properties')\n return '[' + o.map(jcs).join(',') + ']'\n }\n if (o && typeof o === 'object') {\n // only PLAIN objects are JSON values: a Date, Map or class instance\n // would serialize by its enumerable keys alone and collide with {}\n // (review 5, B-3) — reject at the edge of the digest domain\n const proto = Object.getPrototypeOf(o)\n if (proto !== null && proto !== Object.prototype) throw new Error('jcs: not a plain JSON object')\n // symbol-keyed own properties would be silently dropped — the object\n // would collide with its symbol-free twin (review 6, B-2)\n if (Object.getOwnPropertySymbols(o).length > 0) throw new Error('jcs: object with symbol keys')\n // non-enumerable own properties are invisible to Object.keys and\n // would collide with the bare twin (review 7, B-4)\n if (Object.getOwnPropertyNames(o).length !== Object.keys(o).length) throw new Error('jcs: object with non-enumerable own properties')\n const rec = o as Record<string, unknown>\n return '{' + Object.keys(rec).sort().map((k) => {\n if (rec[k] === undefined) throw new Error('jcs: undefined property ' + k)\n if (!(k as unknown as { isWellFormed(): boolean }).isWellFormed()) throw new Error('jcs: lone surrogate in key')\n return JSON.stringify(k) + ':' + jcs(rec[k])\n }).join(',') + '}'\n }\n const s = JSON.stringify(o)\n // M-4 (review 1): symbols and functions stringify to undefined — the\n // invariant \"jcs returns a string\" is enforced at the API edge, not\n // silently violated downstream in a digest.\n if (typeof s !== 'string') throw new Error('jcs: value is not JSON-representable')\n return s\n}\n\n// ── multibase encodings ─────────────────────────────────────────────────\nexport const B58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'\nexport function base58 (bytes: Uint8Array): string {\n let n = 0n\n for (const b of bytes) n = n * 256n + BigInt(b)\n let out = ''\n while (n > 0n) { out = B58[Number(n % 58n)] + out; n /= 58n }\n for (const b of bytes) { if (b === 0) out = '1' + out; else break }\n return out\n}\nexport function fromBase58 (s: string): Uint8Array | null {\n let n = 0n\n for (const c of s) {\n const i = B58.indexOf(c)\n if (i < 0) return null\n n = n * 58n + BigInt(i)\n }\n const out: number[] = []\n while (n > 0n) { out.unshift(Number(n % 256n)); n /= 256n }\n for (const c of s) { if (c === '1') out.unshift(0); else break }\n return new Uint8Array(out)\n}\nexport const b64uOf = (bytes: Uint8Array): string => {\n let s = ''\n for (const b of bytes) s += String.fromCharCode(b)\n const btoaFn: (x: string) => string = typeof btoa === 'function'\n ? btoa\n : (x) => (globalThis as any).Buffer.from(x, 'binary').toString('base64')\n return btoaFn(s).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '')\n}\nexport const fromB64u = (s: string): Uint8Array => {\n const atobFn: (x: string) => string = typeof atob === 'function'\n ? atob\n : (x) => (globalThis as any).Buffer.from(x, 'base64').toString('binary')\n const bin = atobFn(s.replace(/-/g, '+').replace(/_/g, '/'))\n return Uint8Array.from(bin, (c) => c.charCodeAt(0))\n}\n\n// ── digest equality over decoded multihash bytes (Encounter 2.3) ────────\n// toU: strict multibase bridge — prefix, sha2-256 multihash header and\n// length, AND canonical-form round-trip; returns the canonical u rendering\n// or null. A u input is checked for header/length too.\nexport const toU = (v: unknown): string | null => {\n if (typeof v !== 'string' || v.length < 2) return null\n let bytes: Uint8Array | null\n if (v[0] === 'u') {\n try { bytes = fromB64u(v.slice(1)) } catch { return null }\n // canonical base64url only — padding or non-zero trailing bits make a\n // DIFFERENT string decode to the same bytes, and equality is decided\n // over bytes; without this check 16 spellings of one digest verify\n // (B-1, review 1; the shipped reject vectors demand exactly this).\n if (bytes && 'u' + b64uOf(bytes) !== v) return null\n } else if (v[0] === 'z') {\n bytes = fromBase58(v.slice(1))\n if (bytes && 'z' + base58(bytes) !== v) return null // canonical base58btc only\n } else return null\n if (!bytes || bytes.length !== 34 || bytes[0] !== 0x12 || bytes[1] !== 0x20) return null\n return 'u' + b64uOf(bytes)\n}\nexport const sameDigest = (a: unknown, b: unknown): boolean => { const na = toU(a); return na !== null && na === toU(b) }\n\n/** Whole-second ISO rendering — the timestamp form every artifact carries. */\nexport const iso = (ms: number): string => new Date(ms).toISOString().replace(/\\.\\d{3}Z$/, 'Z')\n\n// ── timestamps (Encounter 2.3) ──────────────────────────────────────────\n// tsec: whole-second truncation of EVERY comparison operand (incl. now).\nexport const tsec = (v: string | number): number => Math.floor((typeof v === 'number' ? v : Date.parse(v)) / 1000) * 1000\n// calOK: calendar-valid round-trip AND the ≤3-fractional-digit cap —\n// Date.parse silently normalizes impossible dates, so demand the round-trip.\nexport const calOK = (t: unknown): boolean => {\n if (typeof t !== 'string') return false\n if (!/^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]{1,3})?Z$/.test(t)) return false\n const d = new Date(t)\n return !Number.isNaN(d.getTime()) && d.toISOString().slice(0, 19) === t.slice(0, 19)\n}\n\n// ── THE JSON-Schema subset validator (exactly the keywords we ship) ─────\n// makeValidator(schemaMap): schemaMap is { filename → parsed schema }.\n// Returns { validate, resolveRef, SCHEMAS, BYID } bound to that map.\nexport type Schema = boolean | { [k: string]: any }\nexport type SchemaMap = Record<string, Schema>\nexport interface Validator {\n validate: (data: unknown, schema: Schema, root: Schema, path?: string) => string[]\n resolveRef: (ref: string, root: Schema) => { node: Schema, root: Schema }\n SCHEMAS: SchemaMap\n BYID: SchemaMap\n}\n\n/** Builds a validator bound to one schema map ({ filename → parsed schema }). */\nexport function makeValidator (SCHEMAS: SchemaMap): Validator {\n const BYID: SchemaMap = {}\n for (const s of Object.values(SCHEMAS)) if (typeof s === 'object' && s.$id) BYID[s.$id] = s\n const walk = (node: any, parts: string[]): any => { let n = node; for (const p of parts) n = n[p]; return n }\n const resolveRef = (ref: string, root: Schema) => {\n if (ref.startsWith('#')) return { node: walk(root, ref.slice(2).split('/')), root }\n const [base, frag] = ref.split('#')\n const target = SCHEMAS[base!] || BYID[base!]\n if (!target) throw new Error('unresolvable $ref ' + ref)\n if (!frag) return { node: target, root: target }\n return { node: walk(target, frag.slice(1).split('/')), root: target }\n }\n function validate (data: unknown, schema: Schema, root: Schema, path = '$'): string[] {\n const errs: string[] = []\n const E = (m: string) => errs.push(`${path}: ${m}`)\n if (schema === false) { E('schema false'); return errs }\n if (schema === true || schema == null) return errs\n if (schema.$ref) { const { node, root: r } = resolveRef(schema.$ref, root); return validate(data, node, r, path) }\n const anyData = data as any\n if (schema.const !== undefined && jcs(data) !== jcs(schema.const)) E('const mismatch')\n if (schema.enum && !schema.enum.some((v: unknown) => jcs(v) === jcs(data))) E('enum mismatch')\n if (schema.type) {\n const t = Array.isArray(data) ? 'array' : data === null ? 'null' : typeof data\n const want: string[] = ([] as string[]).concat(schema.type)\n const okT = want.some((w) => w === t || (w === 'integer' && t === 'number' && Number.isInteger(data)))\n if (!okT) { E(`type ${t} != ${schema.type}`); return errs }\n }\n if (typeof data === 'string') {\n if (schema.pattern && !new RegExp(schema.pattern).test(data)) E('pattern')\n // JSON Schema misst Stringlänge in CODEPUNKTEN, nicht UTF-16-\n // Einheiten (Review 4, M-2: 101 Emoji sind 101 Zeichen, nicht 202)\n const cpLen = (schema.minLength != null || schema.maxLength != null) ? [...data].length : 0\n if (schema.minLength != null && cpLen < schema.minLength) E('minLength')\n if (schema.maxLength != null && cpLen > schema.maxLength) E('maxLength')\n }\n if (Array.isArray(data)) {\n if (schema.minItems != null && data.length < schema.minItems) E('minItems')\n if (schema.maxItems != null && data.length > schema.maxItems) E('maxItems')\n if (schema.uniqueItems && new Set(data.map(jcs)).size !== data.length) E('uniqueItems')\n if (schema.prefixItems) {\n schema.prefixItems.forEach((ps: Schema, i: number) => { if (i < data.length) errs.push(...validate(data[i], ps, root, `${path}[${i}]`)) })\n if (schema.items === false && data.length > schema.prefixItems.length) E('items false beyond prefixItems')\n } else if (schema.items !== undefined && schema.items !== true) {\n data.forEach((d: unknown, i: number) => errs.push(...validate(d, schema.items, root, `${path}[${i}]`)))\n }\n if (schema.contains && !data.some((d: unknown) => validate(d, schema.contains, root, path).length === 0)) E('contains unmatched')\n }\n if (data && typeof data === 'object' && !Array.isArray(data)) {\n const keys = Object.keys(anyData)\n if (schema.minProperties != null && keys.length < schema.minProperties) E('minProperties')\n if (schema.maxProperties != null && keys.length > schema.maxProperties) E('maxProperties')\n for (const r of schema.required || []) if (!Object.hasOwn(anyData, r)) E(`missing required ${r}`)\n for (const [k, deps] of Object.entries(schema.dependentRequired || {} as Record<string, string[]>)) {\n if (Object.hasOwn(anyData, k)) for (const d of deps as string[]) if (!Object.hasOwn(anyData, d)) E(`dependentRequired ${k}→${d}`)\n }\n if (schema.propertyNames) for (const k of keys) errs.push(...validate(k, schema.propertyNames, root, `${path}.<name:${k}>`))\n for (const k of keys) {\n if (schema.properties && Object.hasOwn(schema.properties, k)) errs.push(...validate(anyData[k], schema.properties[k], root, `${path}.${k}`))\n else if (schema.additionalProperties === false) E(`additionalProperty ${k}`)\n else if (schema.additionalProperties && typeof schema.additionalProperties === 'object') errs.push(...validate(anyData[k], schema.additionalProperties, root, `${path}.${k}`))\n }\n }\n if (typeof data === 'number') {\n if (schema.minimum != null && data < schema.minimum) E('minimum')\n if (schema.maximum != null && data > schema.maximum) E('maximum')\n if (schema.exclusiveMinimum != null && data <= schema.exclusiveMinimum) E('exclusiveMinimum')\n if (schema.exclusiveMaximum != null && data >= schema.exclusiveMaximum) E('exclusiveMaximum')\n if (schema.multipleOf != null && (data / schema.multipleOf) % 1 !== 0) E('multipleOf')\n }\n if (schema.anyOf && !schema.anyOf.some((s2: Schema) => validate(data, s2, root, path).length === 0)) E('anyOf unmatched')\n if (schema.oneOf) { const n = schema.oneOf.filter((s2: Schema) => validate(data, s2, root, path).length === 0).length; if (n !== 1) E(`oneOf matched ${n}`) }\n if (schema.not !== undefined && validate(data, schema.not, root, path).length === 0) E('not matched')\n if (schema.if !== undefined) {\n const hit = validate(data, schema.if, root, path).length === 0\n if (hit && schema.then !== undefined) errs.push(...validate(data, schema.then, root, path))\n if (!hit && schema.else !== undefined) errs.push(...validate(data, schema.else, root, path))\n }\n for (const sub of (schema.allOf || []) as Schema[]) errs.push(...validate(data, sub, root, path))\n return errs\n }\n return { validate, resolveRef, SCHEMAS, BYID }\n}\n"]}
1
+ {"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,EAAE;AACF,kEAAkE;AAClE,2DAA2D;AAC3D,uEAAuE;AACvE,kEAAkE;AAClE,EAAE;AACF,yEAAyE;AACzE,yEAAyE;AACzE,+BAA+B;AAC/B,EAAE;AACF,yEAAyE;AACzE,2CAA2C;AAO3C,mEAAmE;AACnE,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,CAAU,EAAU,EAAE;IACxC,IAAI,CAAC,KAAK,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAA;IAC1E,sEAAsE;IACtE,sEAAsE;IACtE,gEAAgE;IAChE,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAE,CAA4C,CAAC,YAAY,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;IAClI,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAA;IAC3F,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,C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AAS;gBAAE,IAAI,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;QAC9F,CAAC;QACD,KAAK,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAa;YAAE,IAAI,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;QACjG,OAAO,IAAI,CAAA;IACb,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;AAChD,CAAC","sourcesContent":["// core — the form layer: the canonical rules every RLTP artifact obeys.\n//\n// One implementation of the canonical form (JCS subset, multibase\n// encodings, digest equality over DECODED bytes, timestamp\n// normalization) and the JSON-Schema subset validator. The conformance\n// runner, the reference engine and every simulator delegate here.\n//\n// Predicates exist ONCE — that is the point. Weakening a rule here fails\n// the conformance runner's self-tests rather than silently changing what\n// some user interface accepts.\n//\n// Dependency-free and environment-free: no node:*, no DOM, no WebCrypto.\n// Everything here is synchronous and pure.\n\n// ── JCS (RFC 8785 subset for the ASCII I-JSON forms this stack ships) ──\nexport type Json = string | number | boolean | null | Json[] | { [k: string]: Json }\n/** A JSON object (the codec's `anyObj`: an object, contents open). */\nexport type JsonObject = { [field: string]: Json }\n\n/** RFC 8785 subset for the ASCII I-JSON forms this stack ships. */\nexport const jcs = (o: unknown): string => {\n if (o === undefined) throw new Error('jcs: undefined is not serializable')\n // RFC 8785 operates on Unicode strings — a lone surrogate is not one,\n // and a conformant implementation MUST error rather than canonicalize\n // it (review 3, B-1: divergent digests between implementations)\n if (typeof o === 'string' && !(o as unknown as { isWellFormed(): boolean }).isWellFormed()) throw new Error('jcs: lone surrogate')\n if (typeof o === 'number' && !Number.isFinite(o)) throw new Error('jcs: non-finite number')\n if (Array.isArray(o)) {\n // a sparse array is not a JSON value: map() skips holes and join()\n // erases them, so [empty] and [] would COLLIDE on one digest\n // (review 4, B-3) — reject instead of silently canonicalizing\n for (let i = 0; i < o.length; i++) if (!(i in o)) throw new Error('jcs: sparse array')\n // non-index own properties (arr.x = 1) and symbol keys would be\n // silently DROPPED and collide with the bare array (review 6, B-2)\n if (Object.getOwnPropertyNames(o).length !== o.length + 1 /* 'length' itself */ || Object.getOwnPropertySymbols(o).length > 0) throw new Error('jcs: array with extra own properties')\n return '[' + o.map(jcs).join(',') + ']'\n }\n if (o && typeof o === 'object') {\n // only PLAIN objects are JSON values: a Date, Map or class instance\n // would serialize by its enumerable keys alone and collide with {}\n // (review 5, B-3) — reject at the edge of the digest domain\n const proto = Object.getPrototypeOf(o)\n if (proto !== null && proto !== Object.prototype) throw new Error('jcs: not a plain JSON object')\n // symbol-keyed own properties would be silently dropped — the object\n // would collide with its symbol-free twin (review 6, B-2)\n if (Object.getOwnPropertySymbols(o).length > 0) throw new Error('jcs: object with symbol keys')\n // non-enumerable own properties are invisible to Object.keys and\n // would collide with the bare twin (review 7, B-4)\n if (Object.getOwnPropertyNames(o).length !== Object.keys(o).length) throw new Error('jcs: object with non-enumerable own properties')\n const rec = o as Record<string, unknown>\n return '{' + Object.keys(rec).sort().map((k) => {\n if (rec[k] === undefined) throw new Error('jcs: undefined property ' + k)\n if (!(k as unknown as { isWellFormed(): boolean }).isWellFormed()) throw new Error('jcs: lone surrogate in key')\n return JSON.stringify(k) + ':' + jcs(rec[k])\n }).join(',') + '}'\n }\n const s = JSON.stringify(o)\n // M-4 (review 1): symbols and functions stringify to undefined — the\n // invariant \"jcs returns a string\" is enforced at the API edge, not\n // silently violated downstream in a digest.\n if (typeof s !== 'string') throw new Error('jcs: value is not JSON-representable')\n return s\n}\n\n// ── multibase encodings ─────────────────────────────────────────────────\nexport const B58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'\nexport function base58 (bytes: Uint8Array): string {\n let n = 0n\n for (const b of bytes) n = n * 256n + BigInt(b)\n let out = ''\n while (n > 0n) { out = B58[Number(n % 58n)] + out; n /= 58n }\n for (const b of bytes) { if (b === 0) out = '1' + out; else break }\n return out\n}\nexport function fromBase58 (s: string): Uint8Array | null {\n let n = 0n\n for (const c of s) {\n const i = B58.indexOf(c)\n if (i < 0) return null\n n = n * 58n + BigInt(i)\n }\n const out: number[] = []\n while (n > 0n) { out.unshift(Number(n % 256n)); n /= 256n }\n for (const c of s) { if (c === '1') out.unshift(0); else break }\n return new Uint8Array(out)\n}\nexport const b64uOf = (bytes: Uint8Array): string => {\n let s = ''\n for (const b of bytes) s += String.fromCharCode(b)\n const btoaFn: (x: string) => string = typeof btoa === 'function'\n ? btoa\n : (x) => (globalThis as any).Buffer.from(x, 'binary').toString('base64')\n return btoaFn(s).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '')\n}\nexport const fromB64u = (s: string): Uint8Array => {\n const atobFn: (x: string) => string = typeof atob === 'function'\n ? atob\n : (x) => (globalThis as any).Buffer.from(x, 'base64').toString('binary')\n const bin = atobFn(s.replace(/-/g, '+').replace(/_/g, '/'))\n return Uint8Array.from(bin, (c) => c.charCodeAt(0))\n}\n\n// ── digest equality over decoded multihash bytes (Encounter 2.3) ────────\n// toU: strict multibase bridge — prefix, sha2-256 multihash header and\n// length, AND canonical-form round-trip; returns the canonical u rendering\n// or null. A u input is checked for header/length too.\nexport const toU = (v: unknown): string | null => {\n if (typeof v !== 'string' || v.length < 2) return null\n let bytes: Uint8Array | null\n if (v[0] === 'u') {\n try { bytes = fromB64u(v.slice(1)) } catch { return null }\n // canonical base64url only — padding or non-zero trailing bits make a\n // DIFFERENT string decode to the same bytes, and equality is decided\n // over bytes; without this check 16 spellings of one digest verify\n // (B-1, review 1; the shipped reject vectors demand exactly this).\n if (bytes && 'u' + b64uOf(bytes) !== v) return null\n } else if (v[0] === 'z') {\n bytes = fromBase58(v.slice(1))\n if (bytes && 'z' + base58(bytes) !== v) return null // canonical base58btc only\n } else return null\n if (!bytes || bytes.length !== 34 || bytes[0] !== 0x12 || bytes[1] !== 0x20) return null\n return 'u' + b64uOf(bytes)\n}\nexport const sameDigest = (a: unknown, b: unknown): boolean => { const na = toU(a); return na !== null && na === toU(b) }\n\n/** Whole-second ISO rendering — the timestamp form every artifact carries. */\nexport const iso = (ms: number): string => new Date(ms).toISOString().replace(/\\.\\d{3}Z$/, 'Z')\n\n// ── timestamps (Encounter 2.3) ──────────────────────────────────────────\n// tsec: whole-second truncation of EVERY comparison operand (incl. now).\nexport const tsec = (v: string | number): number => Math.floor((typeof v === 'number' ? v : Date.parse(v)) / 1000) * 1000\n// calOK: calendar-valid round-trip AND the ≤3-fractional-digit cap —\n// Date.parse silently normalizes impossible dates, so demand the round-trip.\nexport const calOK = (t: unknown): boolean => {\n if (typeof t !== 'string') return false\n if (!/^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]{1,3})?Z$/.test(t)) return false\n const d = new Date(t)\n return !Number.isNaN(d.getTime()) && d.toISOString().slice(0, 19) === t.slice(0, 19)\n}\n\n// ── THE JSON-Schema subset validator (exactly the keywords we ship) ─────\n// makeValidator(schemaMap): schemaMap is { filename → parsed schema }.\n// Returns { validate, resolveRef, SCHEMAS, BYID } bound to that map.\nexport type Schema = boolean | { [k: string]: any }\nexport type SchemaMap = Record<string, Schema>\nexport interface Validator {\n validate: (data: unknown, schema: Schema, root: Schema, path?: string) => string[]\n resolveRef: (ref: string, root: Schema) => { node: Schema, root: Schema }\n SCHEMAS: SchemaMap\n BYID: SchemaMap\n}\n\n/** Builds a validator bound to one schema map ({ filename → parsed schema }). */\nexport function makeValidator (SCHEMAS: SchemaMap): Validator {\n const BYID: SchemaMap = {}\n for (const s of Object.values(SCHEMAS)) if (typeof s === 'object' && s.$id) BYID[s.$id] = s\n const walk = (node: any, parts: string[]): any => { let n = node; for (const p of parts) n = n[p]; return n }\n const resolveRef = (ref: string, root: Schema) => {\n if (ref.startsWith('#')) return { node: walk(root, ref.slice(2).split('/')), root }\n const [base, frag] = ref.split('#')\n const target = SCHEMAS[base!] || BYID[base!]\n if (!target) throw new Error('unresolvable $ref ' + ref)\n if (!frag) return { node: target, root: target }\n return { node: walk(target, frag.slice(1).split('/')), root: target }\n }\n function validate (data: unknown, schema: Schema, root: Schema, path = '$'): string[] {\n const errs: string[] = []\n const E = (m: string) => errs.push(`${path}: ${m}`)\n if (schema === false) { E('schema false'); return errs }\n if (schema === true || schema == null) return errs\n if (schema.$ref) { const { node, root: r } = resolveRef(schema.$ref, root); return validate(data, node, r, path) }\n const anyData = data as any\n if (schema.const !== undefined && jcs(data) !== jcs(schema.const)) E('const mismatch')\n if (schema.enum && !schema.enum.some((v: unknown) => jcs(v) === jcs(data))) E('enum mismatch')\n if (schema.type) {\n const t = Array.isArray(data) ? 'array' : data === null ? 'null' : typeof data\n const want: string[] = ([] as string[]).concat(schema.type)\n const okT = want.some((w) => w === t || (w === 'integer' && t === 'number' && Number.isInteger(data)))\n if (!okT) { E(`type ${t} != ${schema.type}`); return errs }\n }\n if (typeof data === 'string') {\n if (schema.pattern && !new RegExp(schema.pattern).test(data)) E('pattern')\n // JSON Schema misst Stringlänge in CODEPUNKTEN, nicht UTF-16-\n // Einheiten (Review 4, M-2: 101 Emoji sind 101 Zeichen, nicht 202)\n const cpLen = (schema.minLength != null || schema.maxLength != null) ? [...data].length : 0\n if (schema.minLength != null && cpLen < schema.minLength) E('minLength')\n if (schema.maxLength != null && cpLen > schema.maxLength) E('maxLength')\n }\n if (Array.isArray(data)) {\n if (schema.minItems != null && data.length < schema.minItems) E('minItems')\n if (schema.maxItems != null && data.length > schema.maxItems) E('maxItems')\n if (schema.uniqueItems && new Set(data.map(jcs)).size !== data.length) E('uniqueItems')\n if (schema.prefixItems) {\n schema.prefixItems.forEach((ps: Schema, i: number) => { if (i < data.length) errs.push(...validate(data[i], ps, root, `${path}[${i}]`)) })\n if (schema.items === false && data.length > schema.prefixItems.length) E('items false beyond prefixItems')\n } else if (schema.items !== undefined && schema.items !== true) {\n data.forEach((d: unknown, i: number) => errs.push(...validate(d, schema.items, root, `${path}[${i}]`)))\n }\n if (schema.contains && !data.some((d: unknown) => validate(d, schema.contains, root, path).length === 0)) E('contains unmatched')\n }\n if (data && typeof data === 'object' && !Array.isArray(data)) {\n const keys = Object.keys(anyData)\n if (schema.minProperties != null && keys.length < schema.minProperties) E('minProperties')\n if (schema.maxProperties != null && keys.length > schema.maxProperties) E('maxProperties')\n for (const r of schema.required || []) if (!Object.hasOwn(anyData, r)) E(`missing required ${r}`)\n for (const [k, deps] of Object.entries(schema.dependentRequired || {} as Record<string, string[]>)) {\n if (Object.hasOwn(anyData, k)) for (const d of deps as string[]) if (!Object.hasOwn(anyData, d)) E(`dependentRequired ${k}→${d}`)\n }\n if (schema.propertyNames) for (const k of keys) errs.push(...validate(k, schema.propertyNames, root, `${path}.<name:${k}>`))\n for (const k of keys) {\n if (schema.properties && Object.hasOwn(schema.properties, k)) errs.push(...validate(anyData[k], schema.properties[k], root, `${path}.${k}`))\n else if (schema.additionalProperties === false) E(`additionalProperty ${k}`)\n else if (schema.additionalProperties && typeof schema.additionalProperties === 'object') errs.push(...validate(anyData[k], schema.additionalProperties, root, `${path}.${k}`))\n }\n }\n if (typeof data === 'number') {\n if (schema.minimum != null && data < schema.minimum) E('minimum')\n if (schema.maximum != null && data > schema.maximum) E('maximum')\n if (schema.exclusiveMinimum != null && data <= schema.exclusiveMinimum) E('exclusiveMinimum')\n if (schema.exclusiveMaximum != null && data >= schema.exclusiveMaximum) E('exclusiveMaximum')\n if (schema.multipleOf != null && (data / schema.multipleOf) % 1 !== 0) E('multipleOf')\n }\n if (schema.anyOf && !schema.anyOf.some((s2: Schema) => validate(data, s2, root, path).length === 0)) E('anyOf unmatched')\n if (schema.oneOf) { const n = schema.oneOf.filter((s2: Schema) => validate(data, s2, root, path).length === 0).length; if (n !== 1) E(`oneOf matched ${n}`) }\n if (schema.not !== undefined && validate(data, schema.not, root, path).length === 0) E('not matched')\n if (schema.if !== undefined) {\n const hit = validate(data, schema.if, root, path).length === 0\n if (hit && schema.then !== undefined) errs.push(...validate(data, schema.then, root, path))\n if (!hit && schema.else !== undefined) errs.push(...validate(data, schema.else, root, path))\n }\n for (const sub of (schema.allOf || []) as Schema[]) errs.push(...validate(data, sub, root, path))\n return errs\n }\n return { validate, resolveRef, SCHEMAS, BYID }\n}\n"]}
package/dist/crypto.d.ts CHANGED
@@ -1,23 +1,27 @@
1
1
  import { base58, fromBase58, b64uOf, fromB64u } from './core.js';
2
2
  export { b64uOf, fromB64u, base58, fromBase58 };
3
+ /** The platform's SubtleCrypto, read at call time — never at import, so
4
+ * the library loads in a runtime without WebCrypto and fails only where
5
+ * it is used (note §3 Crypto). */
6
+ export declare const platformSubtle: () => SubtleCrypto;
3
7
  export declare const cat: (...bs: Uint8Array[]) => Uint8Array;
4
8
  export declare const rand: (n: number) => Uint8Array;
5
- export declare const sha: (bytes: Uint8Array) => Promise<Uint8Array>;
6
- export declare const hkdf: (ikm: Uint8Array, info: string, len?: number) => Promise<Uint8Array>;
7
- export declare const digestBytes: (bytes: Uint8Array) => Promise<string>;
8
- export declare const digestDoc: (obj: unknown) => Promise<string>;
9
+ export declare const sha: (bytes: Uint8Array, subtle?: SubtleCrypto) => Promise<Uint8Array>;
10
+ export declare const hkdf: (ikm: Uint8Array, info: string, len?: number, subtle?: SubtleCrypto) => Promise<Uint8Array>;
11
+ export declare const digestBytes: (bytes: Uint8Array, subtle?: SubtleCrypto) => Promise<string>;
12
+ export declare const digestDoc: (obj: unknown, subtle?: SubtleCrypto) => Promise<string>;
9
13
  /** A key pair as this library carries it: the private CryptoKey plus the raw public bytes. */
10
14
  export interface KeyPair {
11
15
  priv: CryptoKey;
12
16
  pubRaw: Uint8Array;
13
17
  }
14
18
  export declare function edFromSeed(seed: Uint8Array): Promise<KeyPair>;
15
- export declare function xFromSeed(seed: Uint8Array): Promise<KeyPair>;
19
+ export declare function xFromSeed(seed: Uint8Array, subtle?: SubtleCrypto): Promise<KeyPair>;
16
20
  export declare const anchorOfEd: (pubRaw: Uint8Array) => string;
17
21
  export declare const mkOfX: (pubRaw: Uint8Array) => string;
18
22
  export declare const edRawOfAnchor: (did: unknown) => Uint8Array | null;
19
23
  export declare const xRawOfMk: (mk: unknown) => Uint8Array | null;
20
- export declare const ecdh: (xPriv: CryptoKey, theirPubRaw: Uint8Array) => Promise<Uint8Array>;
24
+ export declare const ecdh: (xPriv: CryptoKey, theirPubRaw: Uint8Array, subtle?: SubtleCrypto) => Promise<Uint8Array>;
21
25
  /** What a signer must offer: its anchor and its Ed25519 key. A full identity Context satisfies this. */
22
26
  export interface Signer {
23
27
  anchor: string;
@@ -28,5 +32,17 @@ export interface Signer {
28
32
  export declare function diSign<T extends Record<string, any>>(ctx: Signer, doc: T, created: string): Promise<T & {
29
33
  proof: Record<string, any>;
30
34
  }>;
31
- export declare function diVerify(doc: any, expectedAnchor?: string): Promise<boolean>;
35
+ /**
36
+ * The same eddsa-jcs-2022 proof as diSign, with the signature from a
37
+ * signing function instead of a private key: the holder signs through
38
+ * its KeyProvider (`keys.sign(label, bytes)`, raw Ed25519 over the
39
+ * hashData), so modules never hold a key. Ed25519 is deterministic: for
40
+ * the same key, document and `created` the result is byte-identical to
41
+ * diSign's.
42
+ */
43
+ export declare function diSignWith<T extends Record<string, any>>(anchor: string, sign: (hashData: Uint8Array) => Promise<Uint8Array>, doc: T, created: string, subtle?: SubtleCrypto): Promise<T & {
44
+ proof: Record<string, any>;
45
+ }>;
46
+ /** `subtle`: the holder's resolved handle; without one the platform's, at call time. */
47
+ export declare function diVerify(doc: any, expectedAnchor?: string, subtle?: SubtleCrypto): Promise<boolean>;
32
48
  //# sourceMappingURL=crypto.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAcA,OAAO,EAAO,MAAM,EAAE,UAAU,EAA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G;AACH,wBAAsB,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC5D,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,QAAQ,EAAE,UAAU,KAAK,OAAO,CAAC,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,YAAY,GAClH,OAAO,CAAC,CAAC,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAAE,CAAC,CAO7C;AACD,wFAAwF;AACxF,wBAAsB,QAAQ,CAAE,GAAG,EAAE,GAAG,EAAE,cAAc,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CA0B1G"}
package/dist/crypto.js CHANGED
@@ -8,14 +8,28 @@
8
8
  // by the layer that issues it. Runs on globalThis.crypto.subtle in
9
9
  // browsers, Node >= 20, Deno and Bun alike.
10
10
  //
11
+ // Every primitive below runs on the platform's SubtleCrypto unless the
12
+ // caller hands its own (the holder passes the handle it resolved at
13
+ // construction, note §3 Crypto).
14
+ //
11
15
  // Determinism: every construction takes its entropy from the CALLER
12
16
  // (nonces, ephemeral seeds). Random helpers exist, but nothing here
13
17
  // calls them implicitly — that is what makes the whole stack replayable
14
18
  // and vector-testable.
15
19
  import { jcs, base58, fromBase58, b64uOf, fromB64u, calOK } from './core.js';
20
+ import { CryptoUnavailableError } from './results.js';
16
21
  export { b64uOf, fromB64u, base58, fromBase58 };
17
22
  const te = new TextEncoder();
18
- const S = globalThis.crypto.subtle;
23
+ /** The platform's SubtleCrypto, read at call time — never at import, so
24
+ * the library loads in a runtime without WebCrypto and fails only where
25
+ * it is used (note §3 Crypto). */
26
+ export const platformSubtle = () => {
27
+ const s = globalThis.crypto?.subtle;
28
+ if (!s)
29
+ throw new CryptoUnavailableError(['subtle']);
30
+ return s;
31
+ };
32
+ const S = platformSubtle;
19
33
  // ── bytes ───────────────────────────────────────────────────────────────
20
34
  export const cat = (...bs) => {
21
35
  const o = new Uint8Array(bs.reduce((n, b) => n + b.length, 0));
@@ -28,26 +42,26 @@ export const cat = (...bs) => {
28
42
  };
29
43
  export const rand = (n) => globalThis.crypto.getRandomValues(new Uint8Array(n));
30
44
  // ── hashes, KDF, digests ────────────────────────────────────────────────
31
- export const sha = async (bytes) => new Uint8Array(await S.digest('SHA-256', bytes));
32
- export const hkdf = async (ikm, info, len = 32) => {
33
- const k = await S.importKey('raw', ikm, 'HKDF', false, ['deriveBits']);
34
- return new Uint8Array(await S.deriveBits({ name: 'HKDF', hash: 'SHA-256', salt: new Uint8Array(0), info: te.encode(info) }, k, len * 8));
45
+ export const sha = async (bytes, subtle = S()) => new Uint8Array(await subtle.digest('SHA-256', bytes));
46
+ export const hkdf = async (ikm, info, len = 32, subtle = S()) => {
47
+ const k = await subtle.importKey('raw', ikm, 'HKDF', false, ['deriveBits']);
48
+ return new Uint8Array(await subtle.deriveBits({ name: 'HKDF', hash: 'SHA-256', salt: new Uint8Array(0), info: te.encode(info) }, k, len * 8));
35
49
  };
36
50
  // multibase multihash (u, sha2-256) over raw BYTES — pair labels digest the nonce bytes
37
- export const digestBytes = async (bytes) => 'u' + b64uOf(cat(Uint8Array.from([0x12, 0x20]), await sha(bytes)));
51
+ export const digestBytes = async (bytes, subtle) => 'u' + b64uOf(cat(Uint8Array.from([0x12, 0x20]), await sha(bytes, subtle)));
38
52
  // …and over the JCS of a document — the document digest of the stack
39
- export const digestDoc = async (obj) => digestBytes(te.encode(jcs(obj)));
53
+ export const digestDoc = async (obj, subtle) => digestBytes(te.encode(jcs(obj)), subtle);
40
54
  // ── keys (Ed25519 signing, X25519 agreement; did:key / multikey) ────────
41
55
  const ED_PKCS8 = Uint8Array.from([0x30, 0x2e, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70, 0x04, 0x22, 0x04, 0x20]);
42
56
  const X_PKCS8 = Uint8Array.from([0x30, 0x2e, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x6e, 0x04, 0x22, 0x04, 0x20]);
43
- const jwkX = async (priv) => fromB64u((await S.exportKey('jwk', priv)).x);
57
+ const jwkX = async (priv, subtle = S()) => fromB64u((await subtle.exportKey('jwk', priv)).x);
44
58
  export async function edFromSeed(seed) {
45
- const priv = await S.importKey('pkcs8', cat(ED_PKCS8, seed), { name: 'Ed25519' }, true, ['sign']);
59
+ const priv = await S().importKey('pkcs8', cat(ED_PKCS8, seed), { name: 'Ed25519' }, true, ['sign']);
46
60
  return { priv, pubRaw: await jwkX(priv) };
47
61
  }
48
- export async function xFromSeed(seed) {
49
- const priv = await S.importKey('pkcs8', cat(X_PKCS8, seed), { name: 'X25519' }, true, ['deriveBits']);
50
- return { priv, pubRaw: await jwkX(priv) };
62
+ export async function xFromSeed(seed, subtle = S()) {
63
+ const priv = await subtle.importKey('pkcs8', cat(X_PKCS8, seed), { name: 'X25519' }, true, ['deriveBits']);
64
+ return { priv, pubRaw: await jwkX(priv, subtle) };
51
65
  }
52
66
  export const anchorOfEd = (pubRaw) => 'did:key:z' + base58(cat(Uint8Array.from([0xed, 0x01]), pubRaw));
53
67
  export const mkOfX = (pubRaw) => 'z' + base58(cat(Uint8Array.from([0xec, 0x01]), pubRaw));
@@ -63,19 +77,38 @@ export const xRawOfMk = (mk) => {
63
77
  const b = fromBase58(mk.slice(1));
64
78
  return (b && b.length === 34 && b[0] === 0xec && b[1] === 0x01) ? b.subarray(2) : null;
65
79
  };
66
- export const ecdh = async (xPriv, theirPubRaw) => {
67
- const pub = await S.importKey('raw', theirPubRaw, { name: 'X25519' }, false, []);
68
- return new Uint8Array(await S.deriveBits({ name: 'X25519', public: pub }, xPriv, 256));
80
+ export const ecdh = async (xPriv, theirPubRaw, subtle = S()) => {
81
+ const pub = await subtle.importKey('raw', theirPubRaw, { name: 'X25519' }, false, []);
82
+ return new Uint8Array(await subtle.deriveBits({ name: 'X25519', public: pub }, xPriv, 256));
69
83
  };
70
84
  export async function diSign(ctx, doc, created) {
71
85
  const cfg = { type: 'DataIntegrityProof', cryptosuite: 'eddsa-jcs-2022', created, verificationMethod: ctx.anchor + '#' + ctx.anchor.slice(8), proofPurpose: 'assertionMethod' };
72
86
  if ('@context' in doc)
73
87
  cfg['@context'] = doc['@context'];
74
88
  const hashData = cat(await sha(te.encode(jcs(cfg))), await sha(te.encode(jcs(doc))));
75
- const sig = new Uint8Array(await S.sign({ name: 'Ed25519' }, ctx.ed.priv, hashData));
89
+ const sig = new Uint8Array(await S().sign({ name: 'Ed25519' }, ctx.ed.priv, hashData));
90
+ return { ...doc, proof: { ...cfg, proofValue: 'z' + base58(sig) } };
91
+ }
92
+ /**
93
+ * The same eddsa-jcs-2022 proof as diSign, with the signature from a
94
+ * signing function instead of a private key: the holder signs through
95
+ * its KeyProvider (`keys.sign(label, bytes)`, raw Ed25519 over the
96
+ * hashData), so modules never hold a key. Ed25519 is deterministic: for
97
+ * the same key, document and `created` the result is byte-identical to
98
+ * diSign's.
99
+ */
100
+ export async function diSignWith(anchor, sign, doc, created, subtle) {
101
+ const cfg = { type: 'DataIntegrityProof', cryptosuite: 'eddsa-jcs-2022', created, verificationMethod: anchor + '#' + anchor.slice(8), proofPurpose: 'assertionMethod' };
102
+ if ('@context' in doc)
103
+ cfg['@context'] = doc['@context'];
104
+ const hashData = cat(await sha(te.encode(jcs(cfg)), subtle), await sha(te.encode(jcs(doc)), subtle));
105
+ const sig = await sign(hashData);
106
+ if (!(sig instanceof Uint8Array) || sig.length !== 64)
107
+ throw new Error('diSignWith: the signer must answer a 64-byte Ed25519 signature');
76
108
  return { ...doc, proof: { ...cfg, proofValue: 'z' + base58(sig) } };
77
109
  }
78
- export async function diVerify(doc, expectedAnchor) {
110
+ /** `subtle`: the holder's resolved handle; without one the platform's, at call time. */
111
+ export async function diVerify(doc, expectedAnchor, subtle) {
79
112
  const { proof, ...rest } = doc ?? {};
80
113
  if (typeof proof?.proofValue !== 'string' || typeof proof?.verificationMethod !== 'string')
81
114
  return false;
@@ -107,8 +140,9 @@ export async function diVerify(doc, expectedAnchor) {
107
140
  if (!sig || sig.length !== 64 || 'z' + base58(sig) !== zsig)
108
141
  return false;
109
142
  const { proofValue, ...cfg } = proof;
110
- const hashData = cat(await sha(te.encode(jcs(cfg))), await sha(te.encode(jcs(rest))));
111
- const pub = await S.importKey('raw', raw, { name: 'Ed25519' }, false, ['verify']);
112
- return S.verify({ name: 'Ed25519' }, pub, sig, hashData);
143
+ const SS = subtle ?? S();
144
+ const hashData = cat(await sha(te.encode(jcs(cfg)), SS), await sha(te.encode(jcs(rest)), SS));
145
+ const pub = await SS.importKey('raw', raw, { name: 'Ed25519' }, false, ['verify']);
146
+ return SS.verify({ name: 'Ed25519' }, pub, sig, hashData);
113
147
  }
114
148
  //# sourceMappingURL=crypto.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"crypto.js","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,EAAE;AACF,iEAAiE;AACjE,iEAAiE;AACjE,qEAAqE;AACrE,EAAE;AACF,yEAAyE;AACzE,mEAAmE;AACnE,4CAA4C;AAC5C,EAAE;AACF,oEAAoE;AACpE,oEAAoE;AACpE,wEAAwE;AACxE,uBAAuB;AACvB,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AAC5E,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,CAAA;AAE/C,MAAM,EAAE,GAAG,IAAI,WAAW,EAAE,CAAA;AAC5B,MAAM,CAAC,GAAG,UAAU,CAAC,MAAM,CAAC,MAAM,CAAA;AAElC,2EAA2E;AAC3E,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,GAAG,EAAgB,EAAc,EAAE;IACrD,MAAM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,KAAK,CAAA;IACpC,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;IACrF,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAA;IACjF,OAAO,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAA;AAC1D,CAAC","sourcesContent":["// crypto — the primitives, and nothing above them.\n//\n// Byte helpers, hashes, HKDF, key pairs (Ed25519 signing, X25519\n// agreement), the did:key / multikey renderings, ECDH — plus the\n// eddsa-jcs-2022 Data Integrity proof, which every layer signs with.\n//\n// This module answers \"how\", never \"what\": what a proof MEANS is decided\n// by the layer that issues it. Runs on globalThis.crypto.subtle in\n// browsers, Node >= 20, Deno and Bun alike.\n//\n// Determinism: every construction takes its entropy from the CALLER\n// (nonces, ephemeral seeds). Random helpers exist, but nothing here\n// calls them implicitly — that is what makes the whole stack replayable\n// and vector-testable.\nimport { jcs, base58, fromBase58, b64uOf, fromB64u, calOK } from './core.js'\nexport { b64uOf, fromB64u, base58, fromBase58 }\n\nconst te = new TextEncoder()\nconst S = globalThis.crypto.subtle\n\n// ── bytes ───────────────────────────────────────────────────────────────\nexport const cat = (...bs: Uint8Array[]): Uint8Array => {\n const o = new Uint8Array(bs.reduce((n, b) => n + b.length, 0))\n let i = 0; for (const b of bs) { o.set(b, i); i += b.length }\n return o\n}\nexport const rand = (n: number): Uint8Array => globalThis.crypto.getRandomValues(new Uint8Array(n))\n\n// ── hashes, KDF, digests ────────────────────────────────────────────────\nexport const sha = async (bytes: Uint8Array): Promise<Uint8Array> => new Uint8Array(await S.digest('SHA-256', bytes))\nexport const hkdf = async (ikm: Uint8Array, info: string, len = 32): Promise<Uint8Array> => {\n const k = await S.importKey('raw', ikm, 'HKDF', false, ['deriveBits'])\n return new Uint8Array(await S.deriveBits({ name: 'HKDF', hash: 'SHA-256', salt: new Uint8Array(0), info: te.encode(info) }, k, len * 8))\n}\n// multibase multihash (u, sha2-256) over raw BYTES — pair labels digest the nonce bytes\nexport const digestBytes = async (bytes: Uint8Array): Promise<string> => 'u' + b64uOf(cat(Uint8Array.from([0x12, 0x20]), await sha(bytes)))\n// …and over the JCS of a document — the document digest of the stack\nexport const digestDoc = async (obj: unknown): Promise<string> => digestBytes(te.encode(jcs(obj)))\n\n// ── keys (Ed25519 signing, X25519 agreement; did:key / multikey) ────────\nconst ED_PKCS8 = Uint8Array.from([0x30, 0x2e, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70, 0x04, 0x22, 0x04, 0x20])\nconst X_PKCS8 = Uint8Array.from([0x30, 0x2e, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x6e, 0x04, 0x22, 0x04, 0x20])\nconst jwkX = async (priv: CryptoKey): Promise<Uint8Array> => fromB64u((await S.exportKey('jwk', priv)).x!)\n/** A key pair as this library carries it: the private CryptoKey plus the raw public bytes. */\nexport interface KeyPair { priv: CryptoKey, pubRaw: Uint8Array }\n\nexport async function edFromSeed (seed: Uint8Array): Promise<KeyPair> {\n const priv = await S.importKey('pkcs8', cat(ED_PKCS8, seed), { name: 'Ed25519' }, true, ['sign'])\n return { priv, pubRaw: await jwkX(priv) }\n}\nexport async function xFromSeed (seed: Uint8Array): Promise<KeyPair> {\n const priv = await S.importKey('pkcs8', cat(X_PKCS8, seed), { name: 'X25519' }, true, ['deriveBits'])\n return { priv, pubRaw: await jwkX(priv) }\n}\nexport const anchorOfEd = (pubRaw: Uint8Array): string => 'did:key:z' + base58(cat(Uint8Array.from([0xed, 0x01]), pubRaw))\nexport const mkOfX = (pubRaw: Uint8Array): string => 'z' + base58(cat(Uint8Array.from([0xec, 0x01]), pubRaw))\nexport const edRawOfAnchor = (did: unknown): Uint8Array | null => {\n if (typeof did !== 'string' || !did.startsWith('did:key:z')) return null\n const b = fromBase58(did.slice('did:key:z'.length))\n return (b && b.length === 34 && b[0] === 0xed && b[1] === 0x01) ? b.subarray(2) : null\n}\nexport const xRawOfMk = (mk: unknown): Uint8Array | null => {\n if (typeof mk !== 'string' || mk[0] !== 'z') return null\n const b = fromBase58(mk.slice(1))\n return (b && b.length === 34 && b[0] === 0xec && b[1] === 0x01) ? b.subarray(2) : null\n}\nexport const ecdh = async (xPriv: CryptoKey, theirPubRaw: Uint8Array): Promise<Uint8Array> => {\n const pub = await S.importKey('raw', theirPubRaw, { name: 'X25519' }, false, [])\n return new Uint8Array(await S.deriveBits({ name: 'X25519', public: pub }, xPriv, 256))\n}\n\n// ── eddsa-jcs-2022 Data Integrity (W3C-true; Encounter §2.3) ──────────\n// hashData = SHA256(JCS(proofConfig incl. @context where the document has\n// one)) || SHA256(JCS(document without proof)); Ed25519 over hashData;\n// proofValue = z-base58btc of the exactly-64-byte signature.\n/** What a signer must offer: its anchor and its Ed25519 key. A full identity Context satisfies this. */\nexport interface Signer { anchor: string, ed: { priv: CryptoKey } }\n\nexport async function diSign<T extends Record<string, any>> (ctx: Signer, doc: T, created: string): Promise<T & { proof: Record<string, any> }> {\n const cfg: Record<string, any> = { type: 'DataIntegrityProof', cryptosuite: 'eddsa-jcs-2022', created, verificationMethod: ctx.anchor + '#' + ctx.anchor.slice(8), proofPurpose: 'assertionMethod' }\n if ('@context' in doc) cfg['@context'] = doc['@context']\n const hashData = cat(await sha(te.encode(jcs(cfg))), await sha(te.encode(jcs(doc))))\n const sig = new Uint8Array(await S.sign({ name: 'Ed25519' }, ctx.ed.priv, hashData))\n return { ...doc, proof: { ...cfg, proofValue: 'z' + base58(sig) } }\n}\nexport async function diVerify (doc: any, expectedAnchor?: string): Promise<boolean> {\n const { proof, ...rest } = doc ?? {}\n if (typeof proof?.proofValue !== 'string' || typeof proof?.verificationMethod !== 'string') return false\n // M-3 (review 1): this predicate verifies THE RLTP proof, not any\n // signature that happens to be valid under the key — a config with a\n // foreign type, suite, purpose or timestamp form is false here, whether\n // or not a schema runs first.\n if (proof.type !== 'DataIntegrityProof' || proof.cryptosuite !== 'eddsa-jcs-2022') return false\n if (proof.proofPurpose !== 'assertionMethod') return false\n if (typeof proof.created !== 'string' || !calOK(proof.created)) return false\n const vmDid = proof.verificationMethod.split('#')[0] as string\n if (proof.verificationMethod !== vmDid + '#' + vmDid.slice(8)) return false\n if (expectedAnchor && vmDid !== expectedAnchor) return false\n if ('@context' in rest && jcs(proof['@context'] ?? null) !== jcs(rest['@context'])) return false\n const raw = edRawOfAnchor(vmDid)\n if (!raw) return false\n const zsig = proof.proofValue\n if (typeof zsig !== 'string' || zsig[0] !== 'z') return false\n const sig = fromBase58(zsig.slice(1))\n // exactly 64 bytes, canonical base58btc — no left-pad repair (Encounter 2.3)\n if (!sig || sig.length !== 64 || 'z' + base58(sig) !== zsig) return false\n const { proofValue, ...cfg } = proof\n const hashData = cat(await sha(te.encode(jcs(cfg))), await sha(te.encode(jcs(rest))))\n const pub = await S.importKey('raw', raw, { name: 'Ed25519' }, false, ['verify'])\n return S.verify({ name: 'Ed25519' }, pub, sig, hashData)\n}\n\n"]}
1
+ {"version":3,"file":"crypto.js","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,EAAE;AACF,iEAAiE;AACjE,iEAAiE;AACjE,qEAAqE;AACrE,EAAE;AACF,yEAAyE;AACzE,mEAAmE;AACnE,4CAA4C;AAC5C,EAAE;AACF,uEAAuE;AACvE,oEAAoE;AACpE,iCAAiC;AACjC,EAAE;AACF,oEAAoE;AACpE,oEAAoE;AACpE,wEAAwE;AACxE,uBAAuB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E,QAAQ,CAAC,CAAA;AAC3D,CAAC","sourcesContent":["// crypto — the primitives, and nothing above them.\n//\n// Byte helpers, hashes, HKDF, key pairs (Ed25519 signing, X25519\n// agreement), the did:key / multikey renderings, ECDH — plus the\n// eddsa-jcs-2022 Data Integrity proof, which every layer signs with.\n//\n// This module answers \"how\", never \"what\": what a proof MEANS is decided\n// by the layer that issues it. Runs on globalThis.crypto.subtle in\n// browsers, Node >= 20, Deno and Bun alike.\n//\n// Every primitive below runs on the platform's SubtleCrypto unless the\n// caller hands its own (the holder passes the handle it resolved at\n// construction, note §3 Crypto).\n//\n// Determinism: every construction takes its entropy from the CALLER\n// (nonces, ephemeral seeds). Random helpers exist, but nothing here\n// calls them implicitly — that is what makes the whole stack replayable\n// and vector-testable.\nimport { jcs, base58, fromBase58, b64uOf, fromB64u, calOK } from './core.js'\nimport { CryptoUnavailableError } from './results.js'\nexport { b64uOf, fromB64u, base58, fromBase58 }\n\nconst te = new TextEncoder()\n/** The platform's SubtleCrypto, read at call time — never at import, so\n * the library loads in a runtime without WebCrypto and fails only where\n * it is used (note §3 Crypto). */\nexport const platformSubtle = (): SubtleCrypto => {\n const s = globalThis.crypto?.subtle\n if (!s) throw new CryptoUnavailableError(['subtle'])\n return s\n}\nconst S = platformSubtle\n\n// ── bytes ───────────────────────────────────────────────────────────────\nexport const cat = (...bs: Uint8Array[]): Uint8Array => {\n const o = new Uint8Array(bs.reduce((n, b) => n + b.length, 0))\n let i = 0; for (const b of bs) { o.set(b, i); i += b.length }\n return o\n}\nexport const rand = (n: number): Uint8Array => globalThis.crypto.getRandomValues(new Uint8Array(n))\n\n// ── hashes, KDF, digests ────────────────────────────────────────────────\nexport const sha = async (bytes: Uint8Array, subtle: SubtleCrypto = S()): Promise<Uint8Array> => new Uint8Array(await subtle.digest('SHA-256', bytes))\nexport const hkdf = async (ikm: Uint8Array, info: string, len = 32, subtle: SubtleCrypto = S()): Promise<Uint8Array> => {\n const k = await subtle.importKey('raw', ikm, 'HKDF', false, ['deriveBits'])\n return new Uint8Array(await subtle.deriveBits({ name: 'HKDF', hash: 'SHA-256', salt: new Uint8Array(0), info: te.encode(info) }, k, len * 8))\n}\n// multibase multihash (u, sha2-256) over raw BYTES — pair labels digest the nonce bytes\nexport const digestBytes = async (bytes: Uint8Array, subtle?: SubtleCrypto): Promise<string> => 'u' + b64uOf(cat(Uint8Array.from([0x12, 0x20]), await sha(bytes, subtle)))\n// …and over the JCS of a document — the document digest of the stack\nexport const digestDoc = async (obj: unknown, subtle?: SubtleCrypto): Promise<string> => digestBytes(te.encode(jcs(obj)), subtle)\n\n// ── keys (Ed25519 signing, X25519 agreement; did:key / multikey) ────────\nconst ED_PKCS8 = Uint8Array.from([0x30, 0x2e, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70, 0x04, 0x22, 0x04, 0x20])\nconst X_PKCS8 = Uint8Array.from([0x30, 0x2e, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x6e, 0x04, 0x22, 0x04, 0x20])\nconst jwkX = async (priv: CryptoKey, subtle: SubtleCrypto = S()): Promise<Uint8Array> => fromB64u((await subtle.exportKey('jwk', priv)).x!)\n/** A key pair as this library carries it: the private CryptoKey plus the raw public bytes. */\nexport interface KeyPair { priv: CryptoKey, pubRaw: Uint8Array }\n\nexport async function edFromSeed (seed: Uint8Array): Promise<KeyPair> {\n const priv = await S().importKey('pkcs8', cat(ED_PKCS8, seed), { name: 'Ed25519' }, true, ['sign'])\n return { priv, pubRaw: await jwkX(priv) }\n}\nexport async function xFromSeed (seed: Uint8Array, subtle: SubtleCrypto = S()): Promise<KeyPair> {\n const priv = await subtle.importKey('pkcs8', cat(X_PKCS8, seed), { name: 'X25519' }, true, ['deriveBits'])\n return { priv, pubRaw: await jwkX(priv, subtle) }\n}\nexport const anchorOfEd = (pubRaw: Uint8Array): string => 'did:key:z' + base58(cat(Uint8Array.from([0xed, 0x01]), pubRaw))\nexport const mkOfX = (pubRaw: Uint8Array): string => 'z' + base58(cat(Uint8Array.from([0xec, 0x01]), pubRaw))\nexport const edRawOfAnchor = (did: unknown): Uint8Array | null => {\n if (typeof did !== 'string' || !did.startsWith('did:key:z')) return null\n const b = fromBase58(did.slice('did:key:z'.length))\n return (b && b.length === 34 && b[0] === 0xed && b[1] === 0x01) ? b.subarray(2) : null\n}\nexport const xRawOfMk = (mk: unknown): Uint8Array | null => {\n if (typeof mk !== 'string' || mk[0] !== 'z') return null\n const b = fromBase58(mk.slice(1))\n return (b && b.length === 34 && b[0] === 0xec && b[1] === 0x01) ? b.subarray(2) : null\n}\nexport const ecdh = async (xPriv: CryptoKey, theirPubRaw: Uint8Array, subtle: SubtleCrypto = S()): Promise<Uint8Array> => {\n const pub = await subtle.importKey('raw', theirPubRaw, { name: 'X25519' }, false, [])\n return new Uint8Array(await subtle.deriveBits({ name: 'X25519', public: pub }, xPriv, 256))\n}\n\n// ── eddsa-jcs-2022 Data Integrity (W3C-true; Encounter §2.3) ──────────\n// hashData = SHA256(JCS(proofConfig incl. @context where the document has\n// one)) || SHA256(JCS(document without proof)); Ed25519 over hashData;\n// proofValue = z-base58btc of the exactly-64-byte signature.\n/** What a signer must offer: its anchor and its Ed25519 key. A full identity Context satisfies this. */\nexport interface Signer { anchor: string, ed: { priv: CryptoKey } }\n\nexport async function diSign<T extends Record<string, any>> (ctx: Signer, doc: T, created: string): Promise<T & { proof: Record<string, any> }> {\n const cfg: Record<string, any> = { type: 'DataIntegrityProof', cryptosuite: 'eddsa-jcs-2022', created, verificationMethod: ctx.anchor + '#' + ctx.anchor.slice(8), proofPurpose: 'assertionMethod' }\n if ('@context' in doc) cfg['@context'] = doc['@context']\n const hashData = cat(await sha(te.encode(jcs(cfg))), await sha(te.encode(jcs(doc))))\n const sig = new Uint8Array(await S().sign({ name: 'Ed25519' }, ctx.ed.priv, hashData))\n return { ...doc, proof: { ...cfg, proofValue: 'z' + base58(sig) } }\n}\n/**\n * The same eddsa-jcs-2022 proof as diSign, with the signature from a\n * signing function instead of a private key: the holder signs through\n * its KeyProvider (`keys.sign(label, bytes)`, raw Ed25519 over the\n * hashData), so modules never hold a key. Ed25519 is deterministic: for\n * the same key, document and `created` the result is byte-identical to\n * diSign's.\n */\nexport async function diSignWith<T extends Record<string, any>> (\n anchor: string, sign: (hashData: Uint8Array) => Promise<Uint8Array>, doc: T, created: string, subtle?: SubtleCrypto,\n): Promise<T & { proof: Record<string, any> }> {\n const cfg: Record<string, any> = { type: 'DataIntegrityProof', cryptosuite: 'eddsa-jcs-2022', created, verificationMethod: anchor + '#' + anchor.slice(8), proofPurpose: 'assertionMethod' }\n if ('@context' in doc) cfg['@context'] = doc['@context']\n const hashData = cat(await sha(te.encode(jcs(cfg)), subtle), await sha(te.encode(jcs(doc)), subtle))\n const sig = await sign(hashData)\n if (!(sig instanceof Uint8Array) || sig.length !== 64) throw new Error('diSignWith: the signer must answer a 64-byte Ed25519 signature')\n return { ...doc, proof: { ...cfg, proofValue: 'z' + base58(sig) } }\n}\n/** `subtle`: the holder's resolved handle; without one the platform's, at call time. */\nexport async function diVerify (doc: any, expectedAnchor?: string, subtle?: SubtleCrypto): Promise<boolean> {\n const { proof, ...rest } = doc ?? {}\n if (typeof proof?.proofValue !== 'string' || typeof proof?.verificationMethod !== 'string') return false\n // M-3 (review 1): this predicate verifies THE RLTP proof, not any\n // signature that happens to be valid under the key — a config with a\n // foreign type, suite, purpose or timestamp form is false here, whether\n // or not a schema runs first.\n if (proof.type !== 'DataIntegrityProof' || proof.cryptosuite !== 'eddsa-jcs-2022') return false\n if (proof.proofPurpose !== 'assertionMethod') return false\n if (typeof proof.created !== 'string' || !calOK(proof.created)) return false\n const vmDid = proof.verificationMethod.split('#')[0] as string\n if (proof.verificationMethod !== vmDid + '#' + vmDid.slice(8)) return false\n if (expectedAnchor && vmDid !== expectedAnchor) return false\n if ('@context' in rest && jcs(proof['@context'] ?? null) !== jcs(rest['@context'])) return false\n const raw = edRawOfAnchor(vmDid)\n if (!raw) return false\n const zsig = proof.proofValue\n if (typeof zsig !== 'string' || zsig[0] !== 'z') return false\n const sig = fromBase58(zsig.slice(1))\n // exactly 64 bytes, canonical base58btc — no left-pad repair (Encounter 2.3)\n if (!sig || sig.length !== 64 || 'z' + base58(sig) !== zsig) return false\n const { proofValue, ...cfg } = proof\n const SS = subtle ?? S()\n const hashData = cat(await sha(te.encode(jcs(cfg)), SS), await sha(te.encode(jcs(rest)), SS))\n const pub = await SS.importKey('raw', raw, { name: 'Ed25519' }, false, ['verify'])\n return SS.verify({ name: 'Ed25519' }, pub, sig, hashData)\n}\n\n"]}