@real-life/trust-protocol 0.3.1 → 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 +58 -11
  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 -70
  250. package/dist/probe/introduce.d.ts.map +0 -1
  251. package/dist/probe/introduce.js +0 -295
  252. package/dist/probe/introduce.js.map +0 -1
  253. package/dist/probe/membership.d.ts +0 -90
  254. package/dist/probe/membership.d.ts.map +0 -1
  255. package/dist/probe/membership.js +0 -450
  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 @@
1
+ {"version":3,"file":"mapping.js","sourceRoot":"","sources":["../../src/trust/mapping.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,0EAA0E;AAC1E,wEAAwE;AACxE,oEAAoE;AACpE,8BAA8B;AAC9B,EAAE;AACF,uEAAuE;AACvE,EAAE;AACF,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,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,iBAAiB,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9F,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,eAAe,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QACrG,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;QAC7C,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,qEAAqE;QACrE,MAAM,EAAE,CAAC,KAA4B,EAAE,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC;KAChE,CAAC,CAAA;AACJ,CAAC","sourcesContent":["// trust/mapping — the Trust Layer's anchor mapping on the holder (lib\n// Stage 2, PR 4a): the trust act and the class settings (Section 2a), the\n// issuance of anchor-mapping@4 (6.1, 6300/6310, 6420), its verification\n// (6.3) and the entry commit of the deliverable set (Section 2), on\n// HolderState and the engine.\n//\n// Rule numbers: bare four-digit numbers are RLTP-TRU (trust-layer.md).\n//\n// What the module registers (createHolder builds it in):\n// commands trust.set {contactId, on} the Trust button: the\n// anchor mapping class `on` (2770) or `off` (2840); human\n// trust.setClass {contactId, cls, setting} 2780/2810; human\n// trust.setGroupClass {contactId, groupId, setting} 2830; human\n// trust.pause {contactId, paused} the pause of 5.4: star\n// and blinded group star `off`, or back to `default`; human\n// trust.recover {} 2240: entries re-commit\n// from verified mappings recovered without them; non-human\n// task anchor-mapping/0.3 (proof absent): conditions 1–7 in the\n// preparation (stage 8), condition 8 and the transition in\n// apply (stage 9): mappingIn on the arrival tuple, links and\n// bindings at chain level (6610), the counterpart head, the\n// entry commit (2060) or its update in place (2070)\n// duties class-on/1 (2850) and reissue-mapping/1 (6370, 6596): issue\n// the current anchor-mapping@4 on one relationship; class-on of\n// the star classes is discharged by the reconciliation (5.4);\n// class-on of the profile and profile/1 (6455) issue profile@1\n// (trust/profile.ts, PR 6)\n// and, from trust/star.ts and trust/group-star.ts (PR 4b): the tasks\n// star/0.2 and group-star/0.1, the sweeps trust.star and\n// trust.groupStar run by resume, and their ack handlers\n// and, from trust/profile.ts (PR 6): the command profile.set (human),\n// the task profile/0.1 and the profile's duties\n// and, from trust/entries.ts (PR 4c): the commands trust.merge and\n// trust.depart and the duty merge/1; from trust/continuity.ts\n// (PR 4c): the tasks continuity-probe/0.1 and\n// continuity-mapping/0.1, the duty continuity/1, their ack and\n// failure handlers\n//\n// Choices this file makes where note and spec leave them open:\n// - a relationship's verifications go to the entry its active tuple's\n// entryId names (2145), else the one its identity (contactId) names\n// (trust/state.ts entryOf); it sends under that entry's settings\n// (2146). An entry whose relationships hold incomparable anchor heads\n// (a manual merge, 6640, before its split) keeps its anchor head where\n// it is among the newest, else takes the verifying relationship's head\n// - an accepted mapping runs, in order: the split of 2080 (the first\n// mapping on a hand-merged relationship that shares no anchor with\n// the entry), the entry commit, and the merge duties of the net and of\n// 2145 (trust/entries.ts), which merge after this commit (2230)\n// - mappingIn.body and mappingOut.body hold the mapping's body (the\n// artifact without its MACs): the revision rule compares bodies (6270),\n// 6310 compares the issued body\n// - an equal revision with an identical body (6270 repeat, a resend under\n// a new document id) is acknowledged and changes nothing, except that\n// it re-commits an entry lost with state loss (2240); a lower revision,\n// an equivocation and an unlinked change of self (6170) are\n// failed(validation-failed) at stage 9 with the rule as ref\n// - a document carrying ceremony.enactment is failed(validation-failed):\n// a mapping has no material to recompute it against (Delivery §3)\n// - trust.received is announced at the entry commit of a verification,\n// contact.verified at every verification that changed the state; the\n// re-commit of trust.recover (no verification) announces nothing\n// - the admission bound is the constant 10¹⁸−1 (2050); trustModule takes\n// another bound for tests only, as the probe's admissionBound did\n// - an entry committed at a full set is deliverable-pending (2250);\n// trust.recover, a merge and a departure admit pending entries in\n// position order while the set has room (trust/entries.ts)\n// - the entry commit of 2240 runs on trust.recover and on any accepted\n// mapping of the relationship, the repeat included\n// - issuance needs a community anchor (register.community): without one\n// the Trust act is refused as no-community, a duty stays refused\n// - the community key agrees through the KeyProvider under a release the\n// module derives from the register (the current generation's label),\n// not from `addresses`: it is no delivery address (Delivery §5)\n// - the class duties (2850, 6410, 6595, 6596) open, drop and move by the\n// one follow rule of trust/duties.ts, run after every settings change,\n// verification, merge, split, departure and chaining. A class-on duty\n// of the anchor mapping finding the class off, its relationship gone\n// or lagging is fulfilled without sending; ceasing to lag opens a new\n// one (2850). A re-issue duty sends whether or not the relationship\n// lags now (6596) and is dropped while the class is off (6410)\n// - every issuance on a relationship fulfils every open class-on duty of\n// the anchor mapping and every re-issue owed on it (6596: one delivery\n// meets every re-issue still owed)\n// - the star, the blinded and the sealed group star are delivered by the\n// reconciliation of 5.4 (trust/star.ts), which sees every settings\n// change through its view, so changing their settings opens no class-on\n// duty; a class-on duty of one of them (from elsewhere) is fulfilled\n// without sending, since the sweep runs in the same resume after the\n// duties. The profile's class-on and revision duties issue profile@1\n// (trust/profile.ts)\n// - trust.pause sets star and blinded group star `off`, unpausing back to\n// `default`; it needs no trust (2780)\n// - setGroupClass to `default` removes the per-group entry; turning the\n// sealed group star class `off` resets every per-group `on` (5450), on\n// that transition only: a group set `on` afterwards stays, and setting\n// `off` while it is off resets nothing\nimport { jcs, iso, makeValidator, calOK } from '../core.js'\nimport type { Json } from '../core.js'\nimport { digestDoc, xRawOfMk } from '../crypto.js'\nimport { seal } from '../delivery.js'\nimport { communityLabel } from '../identity.js'\nimport { SCHEMAS } from '../schemas.js'\nimport {\n LINEAGE_MAX, MAPPING_CONDITION_RULE, assembleAnchorMapping, bindingOf, classifyMapping, lineageLinks,\n mappingBindings, rawProofValue, verifyAnchorMappingWith,\n} from '../anchor.js'\nimport { tupleByRkid } from '../receive.js'\nimport type { Arrival, ReceivedDocument, TaskRefusal } from '../receive.js'\nimport type { Applied, CommandDef, DutyHandler, EventDraft, HolderModule, OutboundDraft, PrepareCtx, Refusal } from '../engine.js'\nimport type { KeyRelease } from '../ports.js'\nimport type { ClassOnDuty, Contact, Dec, Duty, HolderState, ReissueMappingDuty, Relationship, Setting, TrustClass, Tuple } from '../state.js'\nimport {\n ADMISSION_BOUND, CLASSES, activeTuple, classOnToward, entryOf, entryRelationships, findContact, lags, liveRel, unionBindings,\n} from './state.js'\nimport { admitPending, entryCommands, mergeDutiesAfter, mergeDuty, settleHead, splitIfUnlinked } from './entries.js'\nimport { classOnHandler, followClasses, owedOn } from './duties.js'\nimport { profileIssueDuty, profileParts } from './profile.js'\nimport { ASSEMBLY_LIMIT, STAR, STAR_TYPE, ackOf, rematchStars, retainInflight, starBlinds, sweepOf, taskOf } from './star.js'\nimport type { StarBlinds } from './star.js'\nimport { GROUP_STAR, GROUP_STAR_TYPE } from './group-star.js'\nimport { continuityParts } from './continuity.js'\n\nconst te = new TextEncoder()\nconst V = makeValidator(SCHEMAS)\nconst mappingSchemaOk = (m: unknown): boolean =>\n V.validate(m, SCHEMAS['visibility-anchor-mapping.schema.json'], SCHEMAS['visibility-anchor-mapping.schema.json']).length === 0\n\n/** The registered task type that carries anchor-mapping@4 (Delivery §4.4). */\nexport const ANCHOR_MAPPING_TYPE = 'https://real-life.org/trust-tasks/anchor-mapping/0.3'\n\n/** The trust module's command names. */\nexport const TRUST_COMMANDS = Object.freeze({\n set: 'trust.set', setClass: 'trust.setClass', setGroupClass: 'trust.setGroupClass', pause: 'trust.pause', recover: 'trust.recover',\n} as const)\n\nexport interface TrustSetInput { contactId: string, on: boolean }\nexport interface TrustSetClassInput { contactId: string, cls: TrustClass, setting: Setting }\nexport interface TrustSetGroupClassInput { contactId: string, groupId: string, setting: Setting }\nexport interface TrustPauseInput { contactId: string, paused: boolean }\n\n/** The mapping body as verified (6020). */\ninterface MappingBody {\n type: 'anchor-mapping@4', pair: string, self: string, to: string\n card: { body: { type: 'self-card@2', anchor: string, keyAgreement: string, commit: string }, proof: { proofValue: string } }\n lineage: Json[], revision: Dec, issuedAt: string\n}\ninterface AnchorMapping { body: MappingBody, proof: { mac1: string, mac2: string } }\n\nconst SETTINGS: readonly Setting[] = ['default', 'on', 'off']\nconst inc = (d: Dec): Dec => (BigInt(d) + 1n).toString()\n\n// ── the community anchor and its lineage ───────────────────────────────\n\ninterface Community { genesis: string, gen: number, label: string, nextLabel: string }\n\n/** The current generation's label and the next one's (Identity §5.4). */\nfunction communityOf (state: Readonly<HolderState>): Community | null {\n const c = state.register.community\n if (c === null) return null\n const gen = Number(c.head)\n if (!Number.isSafeInteger(gen) || gen < 1 || gen + 1 > Number.MAX_SAFE_INTEGER) throw new Error(`trust: community head ${c.head} outside [1, 2^53 − 2] (Identity §5.4)`)\n return { genesis: c.genesis, gen, label: communityLabel(c.genesis, gen), nextLabel: communityLabel(c.genesis, gen + 1) }\n}\n\n/**\n * The lineage a mapping on one relationship carries (6020, 6420): empty\n * where nothing was issued there under an earlier anchor, otherwise the\n * holder's lineage from the element that leaves the relationship's\n * earliest anchor (2285) to `self`, at most the LINEAGE_MAX most recent.\n */\nexport function lineageSegment (lineage: readonly Json[], earliest: string | null, self: string): Json[] {\n if (earliest === null || earliest === self) return []\n const at = lineage.findIndex((r) => (r as { body?: { prev?: unknown } })?.body?.prev === earliest)\n if (at < 0) throw new Error('trust: a relationship\\'s earliest anchor is not in the register lineage (2285, 6420)')\n const seg = lineage.slice(at)\n if ((seg[seg.length - 1] as { body: { next: string } }).body.next !== self) throw new Error('trust: the register lineage does not end at the current community anchor')\n return structuredClone(seg.slice(-LINEAGE_MAX))\n}\n\n// ── issuance (6.1, 6300/6310) ──────────────────────────────────────────\n\ntype Blocked = 'gone' | 'off' | 'deactivated' | 'lagging' | 'no-community' | 'scope-exhausted'\n\n/** Whether the anchor mapping can go out on `relId` toward `contactId` now. */\nfunction issuable (state: Readonly<HolderState>, contactId: string, relId: string, lagMatters: boolean):\n { ok: true, contact: Contact, rel: Relationship, tuple: Tuple } | { ok: false, why: Blocked } {\n const contact = findContact(state, contactId)\n const rel = Object.hasOwn(state.relationships, relId) ? state.relationships[relId] : undefined\n if (!contact || !rel || rel.chainedInto !== null || !contact.relIds.includes(rel.id)) return { ok: false, why: 'gone' }\n if (entryOf(state, rel)?.id !== contact.id) return { ok: false, why: 'gone' } // 2146: it sends under the other entry\n if (!classOnToward(contact, 'anchorMapping')) return { ok: false, why: 'off' } // 6410\n const tuple = activeTuple(rel)\n if (!tuple || tuple.deactivated) return { ok: false, why: 'deactivated' } // 6240\n if (lagMatters && lags(rel, entryRelationships(state, contact))) return { ok: false, why: 'lagging' } // 6595\n if (state.register.community === null) return { ok: false, why: 'no-community' }\n if (BigInt(tuple.mappingOut.rev) + 1n > ADMISSION_BOUND) return { ok: false, why: 'scope-exhausted' } // 2.1\n return { ok: true, contact, rel, tuple }\n}\n\n/** An issuance prepared against a snapshot: the next revision of the\n * tuple's scope and the sealed document. */\ninterface Issue {\n relId: string\n tuple: string\n /** the scope's revision the issuance follows; apply re-checks it (6300) */\n baseRev: Dec\n rev: Dec\n body: MappingBody\n underAnchor: string\n outbound: OutboundDraft\n}\n\n/** Build and seal the current anchor-mapping@4 for one relationship. */\nasync function prepareIssue (ctx: PrepareCtx, contactId: string, relId: string, lagMatters: boolean): Promise<Issue | null> {\n const st = ctx.snapshot\n const chk = issuable(st, contactId, relId, lagMatters)\n if (!chk.ok) return null\n const { contact, rel, tuple: t } = chk\n const S = ctx.crypto.subtle\n const com = communityOf(st)!\n const self = await ctx.keys.anchorOf(com.label)\n const next = await ctx.keys.anchorOf(com.nextLabel)\n const own = await ctx.keys.anchorOf(t.ownPairLabel)\n // self-card@2 under the current generation, bound to the next (6.2)\n const cardBody = { type: 'self-card@2' as const, anchor: self.anchor, keyAgreement: self.keyAgreement, commit: await bindingOf(next.anchor, S) }\n const card = { body: cardBody, proof: { proofValue: rawProofValue(await ctx.keys.sign(com.label, te.encode(jcs(cardBody)))) } }\n const rev = inc(t.mappingOut.rev)\n const body: MappingBody = {\n type: 'anchor-mapping@4', pair: own.anchor, self: self.anchor, to: t.counterpartAnchor, card,\n lineage: lineageSegment(st.register.lineage, rel.earliestAnchor, self.anchor), revision: rev, issuedAt: iso(ctx.when),\n }\n const theirX = xRawOfMk(t.counterpartKeyAgreement)\n if (!theirX) return null\n // mac1 under the tuple's own pair key, mac2 under the community key (6030)\n const sh1 = await ctx.keys.agree(t.rkid, theirX, ctx.release)\n const communityRelease: KeyRelease = (rkid) => (rkid === self.keyAgreement ? { status: 'live', label: com.label } : { status: 'unknown' })\n const sh2 = await ctx.keys.agree(self.keyAgreement, theirX, communityRelease)\n if (sh1.status !== 'available' || sh2.status !== 'available') return null\n const mapping = await assembleAnchorMapping(body, sh1.shared, sh2.shared, S)\n const threadId = ctx.entropy.id('thread.id')\n const doc = {\n id: ctx.entropy.id('doc.id'), type: ANCHOR_MAPPING_TYPE, issuer: own.anchor, recipient: t.counterpartAnchor,\n threadId, issuedAt: iso(ctx.when), payload: mapping as unknown as Json,\n }\n const envelope = await seal(doc, t.counterpartKeyAgreement, { ephSeed: ctx.entropy.bytes('seal.eph', 32), nonce: ctx.entropy.bytes('seal.nonce', 12) }, S)\n return {\n relId: rel.id, tuple: t.ownPairLabel, baseRev: t.mappingOut.rev, rev, body, underAnchor: self.anchor,\n outbound: {\n digest: await digestDoc(doc, S), envelope, type: ANCHOR_MAPPING_TYPE, threadId,\n recipient: { contactId: contact.id, rkid: t.rkid, keyAgreement: t.counterpartKeyAgreement },\n },\n }\n}\n\n\n/** The issuance's commit: revision and body persisted in one step (6300),\n * the earliest anchor (2285), every duty the delivery meets (6596); null\n * where the scope moved since the preparation. */\nfunction commitIssue (state: Readonly<HolderState>, p: Issue): Applied | null {\n const rel = state.relationships[p.relId]\n const i = rel.tuples.findIndex((t) => t.ownPairLabel === p.tuple)\n if (i < 0 || rel.tuples[i].mappingOut.rev !== p.baseRev) return null\n const tuples = rel.tuples.map((t, j) => (j === i ? { ...t, mappingOut: { rev: p.rev, body: p.body as unknown as Json, underAnchor: p.underAnchor } } : t))\n const duties: Record<string, Duty> = {}\n for (const [id, d] of Object.entries(state.duties)) if (!owedOn(d, p.relId, 'anchorMapping')) duties[id] = d\n return {\n state: {\n ...state,\n relationships: { ...state.relationships, [rel.id]: { ...rel, tuples, earliestAnchor: rel.earliestAnchor ?? p.underAnchor } },\n duties,\n },\n outbound: [p.outbound],\n }\n}\n\n// ── the entry commit (Section 2) ───────────────────────────────────────\n\n\n/**\n * After a verified mapping on `relId` (or on recovery): the entry commit\n * where the entry has none (2060: next position, admitted, or pending at\n * the bound, 2250) and the entry's anchor head (6560). The class duties\n * that follow (a relationship that ceased to lag, 2850) are the caller's,\n * by the follow rule (trust/duties.ts).\n */\nfunction commitEntry (state: Readonly<HolderState>, relId: string, bound: bigint): { state: HolderState, committed: Contact | null, contact: Contact } {\n const rel = state.relationships[relId]\n const c0 = entryOf(state, rel)\n if (!c0) throw new Error(`trust: relationship ${relId} maps to no entry`)\n let c: Contact = { ...c0 }\n let entryOrder = state.entryOrder\n let committed: Contact | null = null\n if (c.pos === null) {\n const admitted = BigInt(Object.values(state.contacts).filter((x) => x.status === 'admitted').length)\n c = { ...c, pos: entryOrder.nextPos, status: admitted < bound ? 'admitted' : 'pending' }\n entryOrder = { ...entryOrder, nextPos: inc(entryOrder.nextPos) }\n committed = c\n }\n const s1: HolderState = { ...state, contacts: { ...state.contacts, [c.id]: c }, entryOrder }\n c = settleHead(s1, c, rel.heldCounterpartHead)\n return { state: { ...s1, contacts: { ...s1.contacts, [c.id]: c } }, committed, contact: c }\n}\n\n/** First, pending entries are admitted in position order while the set\n * has room (2250): they hold earlier positions than any re-commit. Then\n * (2240) every relationship holding a verified mapping on a tuple whose\n * entry holds no position re-commits that entry, in the order of\n * entryOrder.heads (2180), then by relationship id, at the next position,\n * admitted or pending by what room is left. */\nexport function recommitEntries (state: Readonly<HolderState>, bound: bigint = ADMISSION_BOUND): Applied {\n const order = Object.keys(state.relationships).sort((a, b) => {\n const ia = state.entryOrder.heads.indexOf(a), ib = state.entryOrder.heads.indexOf(b)\n return ((ia < 0 ? Infinity : ia) - (ib < 0 ? Infinity : ib)) || (a < b ? -1 : a > b ? 1 : 0)\n })\n let cur = admitPending(state, bound)\n for (const id of order) {\n const rel = cur.relationships[id]\n if (!rel.tuples.some((t) => t.mappingIn.body !== null) || entryOf(cur, rel)?.pos !== null) continue\n cur = commitEntry(cur, id, bound).state\n }\n const f = followClasses(state, cur)\n return { state: f.state, ...(f.duties.length ? { duties: f.duties } : {}) }\n}\n\n// ── reception (6.3, Section 2) ─────────────────────────────────────────\n\nconst refuse = (reason: TaskRefusal['reason'], ref?: string): TaskRefusal => ({ ok: false, reason, ...(ref ? { ref } : {}) })\n\n/** The arrival tuple, if it is the active head of a live relationship (6190, 6240). */\nconst arrivalTuple = (state: Readonly<HolderState>, rkid: string): { rel: Relationship, tuple: Tuple } | null => {\n const at = tupleByRkid(state, rkid)\n if (!at || at.tuple.deactivated || at.rel.chainedInto !== null || at.rel.activeHead !== at.tuple.ownPairLabel) return null\n return at\n}\n\nfunction mappingTask (bound: bigint) {\n return {\n proof: 'absent' as const,\n // stage 7: the payload schema, calendar-valid issuedAt (6070)\n decode (payload: unknown): AnchorMapping | TaskRefusal {\n if (!mappingSchemaOk(payload) || !calOK((payload as AnchorMapping).body.issuedAt)) return refuse('malformed', 'RLTP-TRU-6070')\n return payload as AnchorMapping\n },\n // stage 8: conditions 1–7 against the arrival tuple and the bindings\n // its relationship holds (6118), then the bindings the mapping states\n async prepare (ctx: PrepareCtx, doc: ReceivedDocument<AnchorMapping>, arrival: Arrival): Promise<{ bindings: Record<string, string>, stars: StarBlinds } | TaskRefusal> {\n if ((doc.ceremony as { enactment?: unknown } | undefined)?.enactment !== undefined) return refuse('validation-failed')\n const at = arrivalTuple(ctx.snapshot, arrival.rkid)\n if (!at) return refuse('validation-failed', 'RLTP-TRU-6240')\n const S = ctx.crypto.subtle\n const own = await ctx.keys.anchorOf(at.tuple.ownPairLabel)\n // 6118 against every binding held: an anchor the chain holds two\n // bindings for (6610) admits no card and no successor, since none\n // can meet both\n const b0 = doc.payload.body\n const conflicted = new Set(Object.entries(at.rel.bindings).filter(([, v]) => v.length > 1).map(([k]) => k))\n if (conflicted.has(b0.card.body.anchor) || b0.lineage.some((r) => conflicted.has((r as { body: { prev: string } }).body.prev))) return refuse('validation-failed', 'RLTP-TRU-6118')\n let infra: unknown = null\n const v = await verifyAnchorMappingWith(doc.payload, {\n ownAnchor: own.anchor, pair: at.tuple.counterpartAnchor, pairKeyAgreement: at.tuple.counterpartKeyAgreement,\n held: new Map(Object.entries(at.rel.bindings).filter(([, x]) => x.length === 1).map(([k, x]) => [k, x[0]])),\n agree: async (theirX) => {\n try {\n const a = await ctx.keys.agree(at.tuple.rkid, theirX, ctx.release)\n return a.status === 'available' ? a.shared : null\n } catch (e) { infra = e; throw e }\n },\n }, S)\n if (infra !== null) throw infra // a provider failure is no verdict on the mapping\n if (!v.ok) return refuse('validation-failed', v.rule ?? MAPPING_CONDITION_RULE[v.step])\n // the anchors this mapping makes held (self, both ends of its links),\n // blinded under every accepted star for the re-match of 6160\n const anchors = [...new Set([doc.payload.body.self, ...lineageLinks(doc.payload.body.lineage).flat()])]\n return { bindings: Object.fromEntries(await mappingBindings(doc.payload.body, S)), stars: await starBlinds(ctx, anchors) }\n },\n // stage 9: condition 8 (6150–6170) and the transition\n apply (state: Readonly<HolderState>, prepared: { value: { bindings: Record<string, string>, stars: StarBlinds } }, doc: ReceivedDocument<AnchorMapping>, arrival: Arrival): Applied | TaskRefusal {\n const at = arrivalTuple(state, arrival.rkid)\n if (!at) return refuse('validation-failed', 'RLTP-TRU-6240')\n const { rel, tuple: t } = at\n const b = doc.payload.body\n const rev = BigInt(b.revision)\n const cur = BigInt(t.mappingIn.rev)\n // the generic revision rule within the scope (pair, to) = this tuple (6270, 6280)\n if (rev === cur) {\n if (t.mappingIn.body === null || jcs(b) !== jcs(t.mappingIn.body)) return refuse('validation-failed', 'RLTP-TRU-6270')\n // a repeat: ignored, except an entry lost with state loss re-commits (2240)\n return entryOf(state, rel)?.pos === null ? { state: commitEntry(state, rel.id, bound).state } : { state: state as HolderState }\n }\n if (rev < cur) return refuse('validation-failed', 'RLTP-TRU-6270')\n // condition 8 against the self this relationship holds (6150), never the entry's head\n if (classifyMapping(rel.heldCounterpartHead ?? undefined, b) === 'rejected') return refuse('validation-failed', 'RLTP-TRU-6170')\n const tuples = rel.tuples.map((x) => (x.ownPairLabel === t.ownPairLabel\n ? { ...x, mappingIn: { rev: b.revision, body: b as unknown as Json, self: b.self, card: b.card as unknown as Json } }\n : x))\n // links and bindings accumulate at chain level (6610)\n const links = [...rel.links]\n for (const [prev, next] of lineageLinks(b.lineage)) if (!links.some((l) => l.prev === prev && l.next === next)) links.push({ prev, next })\n const nextRel: Relationship = {\n ...rel, tuples, links, bindings: unionBindings(rel.bindings, Object.fromEntries(Object.entries(prepared.value.bindings).map(([k, x]) => [k, [x]]))), heldCounterpartHead: b.self,\n // 2190: the verification commit's place in the one total order\n firstVerified: rel.firstVerified ?? inc(state.commitSeq),\n }\n let mid: HolderState = { ...state, relationships: { ...state.relationships, [rel.id]: nextRel } }\n const events: EventDraft[] = []\n // 2080: a manual merge the first mapping contradicts splits, atomically\n const split = splitIfUnlinked(state, mid, rel.id)\n if (split) { mid = split.state; events.push(split.event) }\n const e = commitEntry(mid, rel.id, bound)\n if (e.committed) events.push({ type: 'trust.received', contactId: e.contact.id })\n events.push({ type: 'contact.verified', contactId: e.contact.id, relationshipId: rel.id })\n // 6160: stars already accepted are tested against the anchors now held\n // the net (6520–6605) and 2145: a merge this verification admits runs\n // after its commit, as a persisted continuation (2230)\n const m = mergeDutiesAfter(state, rematchStars(e.state, e.contact.id, prepared.value.stars), rel.id, { net: true })\n // the class duties that follow (2850: a relationship that ceased to\n // lag, a split's drop of 2115) — trust/duties.ts\n const f = followClasses(state, m.state, m.duties)\n const after = f.state\n const duties: Duty[] = f.duties\n return { state: after, events, ...(duties.length ? { duties } : {}), ...(split?.renames.length ? { renames: split.renames } : {}) }\n },\n }\n}\n\n// ── settings (Section 2a) ──────────────────────────────────────────────\n\nconst paused = (c: Readonly<Contact>): boolean => c.settings.star === 'off' && c.settings.groupStar === 'off'\n\n/** One change of a contact's settings: 2840 and 5450 follow from it, the\n * class duties of 2850 and 6410 by the follow rule (trust/duties.ts), the\n * events. */\nfunction changeSettings (state: Readonly<HolderState>, c: Readonly<Contact>, settings: Record<TrustClass, Setting>, groupSettings: Record<string, Setting>): Applied {\n // 5450: turning the sealed group star off resets every per-group on to\n // default — on the transition only, so a group set on afterwards stays (2830)\n let groups = groupSettings\n if (c.settings.sealedGroupStar !== 'off' && settings.sealedGroupStar === 'off') groups = Object.fromEntries(Object.entries(groups).filter(([, s]) => s !== 'on'))\n const next: Contact = { ...c, settings, groupSettings: groups }\n const events: EventDraft[] = []\n if (!classOnToward(c, 'anchorMapping') && classOnToward(next, 'anchorMapping')) events.push({ type: 'trust.given', contactId: next.id })\n if (paused(c) !== paused(next)) events.push({ type: 'trust.paused', contactId: next.id, paused: paused(next) })\n const f = followClasses(state, { ...state, contacts: { ...state.contacts, [c.id]: next } })\n return { state: f.state, events, ...(f.duties.length ? { duties: f.duties } : {}) }\n}\n\nconst needString = (x: unknown, what: string): string => {\n if (typeof x !== 'string' || x === '') throw new TypeError(`${what} must be a non-empty string`)\n return x\n}\nconst needSetting = (x: unknown): Setting => {\n if (!(SETTINGS as readonly unknown[]).includes(x)) throw new TypeError(`setting must be default, on or off, got ${String(x)}`)\n return x as Setting\n}\nconst needInput = (x: unknown, name: string): Record<string, unknown> => {\n if (x === null || typeof x !== 'object' || Array.isArray(x)) throw new TypeError(`${name} needs an input object`)\n return x as Record<string, unknown>\n}\n\n/** A class setting through the one transition; `on` of the anchor mapping\n * needs a community anchor to issue under. */\nfunction setClass (state: Readonly<HolderState>, contactId: string, cls: TrustClass, setting: Setting): Applied | Refusal {\n const c = findContact(state, contactId)\n if (!c) return { ok: false, code: 'unknown-contact' }\n const settings = { ...c.settings, [cls]: setting }\n if (cls === 'anchorMapping' && setting === 'on' && state.register.community === null) return { ok: false, code: 'no-community' }\n return changeSettings(state, c, settings, c.groupSettings)\n}\n\nconst commands: Record<string, CommandDef> = {\n // the Trust button: on (2770), or withdrawn (2840)\n [TRUST_COMMANDS.set]: {\n human: true,\n apply (state, _p, input: TrustSetInput) {\n const i = needInput(input, TRUST_COMMANDS.set)\n const contactId = needString(i.contactId, 'contactId')\n if (typeof i.on !== 'boolean') throw new TypeError('trust.set: on must be a boolean')\n const c = findContact(state, contactId)\n if (!c) return { ok: false, code: 'unknown-contact' }\n if (i.on && c.settings.anchorMapping === 'on') return { ok: false, code: 'already-given' }\n return setClass(state, contactId, 'anchorMapping', i.on ? 'on' : 'off')\n },\n } satisfies CommandDef<TrustSetInput>,\n [TRUST_COMMANDS.setClass]: {\n human: true,\n apply (state, _p, input: TrustSetClassInput) {\n const i = needInput(input, TRUST_COMMANDS.setClass)\n if (!(CLASSES as readonly unknown[]).includes(i.cls)) throw new TypeError(`trust.setClass: unknown class ${String(i.cls)}`)\n return setClass(state, needString(i.contactId, 'contactId'), i.cls as TrustClass, needSetting(i.setting))\n },\n } satisfies CommandDef<TrustSetClassInput>,\n [TRUST_COMMANDS.setGroupClass]: {\n human: true,\n apply (state, _p, input: TrustSetGroupClassInput) {\n const i = needInput(input, TRUST_COMMANDS.setGroupClass)\n const groupId = needString(i.groupId, 'groupId')\n const setting = needSetting(i.setting)\n const c = findContact(state, needString(i.contactId, 'contactId'))\n if (!c) return { ok: false, code: 'unknown-contact' }\n const groups = { ...c.groupSettings }\n if (setting === 'default') delete groups[groupId]\n else groups[groupId] = setting\n return changeSettings(state, c, c.settings, groups)\n },\n } satisfies CommandDef<TrustSetGroupClassInput>,\n // the pause of 5.4: star and blinded group star off (2780)\n [TRUST_COMMANDS.pause]: {\n human: true,\n apply (state, _p, input: TrustPauseInput) {\n const i = needInput(input, TRUST_COMMANDS.pause)\n if (typeof i.paused !== 'boolean') throw new TypeError('trust.pause: paused must be a boolean')\n const c = findContact(state, needString(i.contactId, 'contactId'))\n if (!c) return { ok: false, code: 'unknown-contact' }\n const s: Setting = i.paused ? 'off' : 'default'\n return changeSettings(state, c, { ...c.settings, star: s, groupStar: s }, c.groupSettings)\n },\n } satisfies CommandDef<TrustPauseInput>,\n}\n\n// ── duties ─────────────────────────────────────────────────────────────\n\n/** What a blocked issuance means for a duty: fulfilled without sending\n * (the class is off, the relationship gone or lagging), or kept. */\nconst blocked = (state: Readonly<HolderState>, why: Blocked): Applied | Refusal =>\n why === 'no-community' ? { ok: false, code: 'no-community' }\n : why === 'scope-exhausted' ? { ok: false, code: 'scope-exhausted', ref: 'RLTP-TRU-6310' }\n : { state: state as HolderState }\n\n/** Issue the anchor mapping on a duty's relationship: class-on/1 of the\n * anchor mapping (through classOnHandler) and reissue-mapping/1. */\nconst issueDuty = (lagMatters: boolean): DutyHandler<Issue | null> => ({\n v: 1,\n prepare: (ctx, duty) => {\n const d = duty as ClassOnDuty | ReissueMappingDuty\n return prepareIssue(ctx, d.contactId, d.relId, lagMatters)\n },\n apply (state, duty, ctx) {\n const d = duty as ClassOnDuty | ReissueMappingDuty\n const chk = issuable(state, d.contactId, d.relId, lagMatters)\n if (!chk.ok) return blocked(state, chk.why)\n const p = ctx.prepared.value\n if (p === null) return { ok: false, code: 'no-own-channel', ref: 'RLTP-TRU-6140' } // no usable key agreement\n return commitIssue(state, p) ?? 'not-due'\n },\n})\n\n/** 6596: an owed re-issue waits until its relationship presents the\n * awaited head H as its anchor head, or a later anchor whose links carry\n * H as a prev. A relationship gone releases the duty, which then drops. */\nconst reissueAwaits = (state: Readonly<HolderState>, duty: Duty): boolean => {\n const d = duty as ReissueMappingDuty\n if (!Object.hasOwn(state.relationships, d.relId)) return true\n const rel = state.relationships[d.relId]\n return d.awaitHead === null || rel.heldCounterpartHead === d.awaitHead || rel.links.some((l) => l.prev === d.awaitHead)\n}\n\n// ── the module ─────────────────────────────────────────────────────────\n\nexport interface TrustModuleOptions {\n /** the deliverable set's bound (2050); another value is for tests only */\n admissionBound?: bigint\n /** the receiver's resource limit of 5365 (highest seq of an open\n * assembly) for star, group star and probe; default ASSEMBLY_LIMIT,\n * another value is for tests only */\n assemblyLimit?: number\n}\n\n/** The trust module createHolder builds in (see the header). */\nexport function trustModule (opts: TrustModuleOptions = {}): HolderModule {\n const bound = opts.admissionBound ?? ADMISSION_BOUND\n if (typeof bound !== 'bigint' || bound < 0n || bound > ADMISSION_BOUND) throw new RangeError('admissionBound must be a bigint within [0, 10^18 − 1]')\n const limit = opts.assemblyLimit\n if (limit !== undefined && (!Number.isSafeInteger(limit) || limit < 1)) throw new RangeError('assemblyLimit must be a positive integer')\n const cont = continuityParts(bound, limit ?? ASSEMBLY_LIMIT.probe)\n return Object.freeze({\n name: 'trust',\n commands: Object.freeze({\n ...commands,\n ...entryCommands(bound),\n ...profileParts.commands,\n [TRUST_COMMANDS.recover]: { human: false, apply: (state: Readonly<HolderState>) => recommitEntries(state, bound) } satisfies CommandDef<unknown>,\n }),\n tasks: Object.freeze({\n [ANCHOR_MAPPING_TYPE]: mappingTask(bound),\n [STAR_TYPE]: taskOf(STAR, limit ?? ASSEMBLY_LIMIT.star),\n [GROUP_STAR_TYPE]: taskOf(GROUP_STAR, limit ?? ASSEMBLY_LIMIT.groupStar),\n ...profileParts.tasks,\n ...cont.tasks,\n }),\n duties: Object.freeze({\n // 2850: per class — the anchor mapping and the profile issue, the\n // reconciled classes go by their sweep (trust/duties.ts)\n 'class-on': classOnHandler({ anchorMapping: issueDuty(true), profile: profileIssueDuty }),\n 'reissue-mapping': { ...issueDuty(false), awaitHolds: reissueAwaits },\n profile: profileIssueDuty,\n merge: mergeDuty(bound),\n ...cont.duties,\n }),\n // 5.4: the star first, then the group star, each its own scope (5730)\n sweeps: Object.freeze({ 'trust.star': sweepOf(STAR), 'trust.groupStar': sweepOf(GROUP_STAR) }),\n acks: Object.freeze({ [STAR_TYPE]: ackOf(STAR), [GROUP_STAR_TYPE]: ackOf(GROUP_STAR), ...cont.acks }),\n failures: Object.freeze({ ...cont.failures }),\n ownRetries: cont.ownRetries,\n keepKeys: cont.keepKeys,\n // in-flight deliveries whose outbox items are all gone leave on tick\n retain: (state: Readonly<HolderState>) => retainInflight(state),\n })\n}\n\n"]}
@@ -0,0 +1,25 @@
1
+ import type { ProfileArtifact, ProfileContent } from '../profile.js';
2
+ import type { CommandDef, DutyHandler, OutboundDraft, TaskHandler } from '../engine.js';
3
+ import type { Dec } from '../state.js';
4
+ /** The profile module's command name. */
5
+ export declare const PROFILE_SET = "profile.set";
6
+ interface Issue {
7
+ relId: string;
8
+ tuple: string;
9
+ rev: Dec;
10
+ outbound: OutboundDraft;
11
+ }
12
+ /** profile/1 and class-on/1 of the profile class (through classOnHandler). */
13
+ export declare const profileIssueDuty: DutyHandler<Issue | null>;
14
+ export declare const profileTask: TaskHandler<ProfileArtifact, null>;
15
+ /** What the trust module registers for the profile. */
16
+ export declare const profileParts: Readonly<{
17
+ commands: Readonly<{
18
+ "profile.set": CommandDef<ProfileContent, any>;
19
+ }>;
20
+ tasks: Readonly<{
21
+ "https://real-life.org/trust-tasks/profile/0.1": TaskHandler<ProfileArtifact, null>;
22
+ }>;
23
+ }>;
24
+ export {};
25
+ //# sourceMappingURL=profile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../../src/trust/profile.ts"],"names":[],"mappings":"AA4DA,OAAO,KAAK,EAAE,eAAe,EAAe,cAAc,EAAE,MAAM,eAAe,CAAA;AAGjF,OAAO,KAAK,EAAW,UAAU,EAAE,WAAW,EAAE,aAAa,EAAuB,WAAW,EAAE,MAAM,cAAc,CAAA;AACrH,OAAO,KAAK,EAAe,GAAG,EAAuD,MAAM,aAAa,CAAA;AAIxG,yCAAyC;AACzC,eAAO,MAAM,WAAW,gBAAgB,CAAA;AA8DxC,UAAU,KAAK;IAAG,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,GAAG,CAAC;IAAC,QAAQ,EAAE,aAAa,CAAA;CAAE;AAuCnF,8EAA8E;AAC9E,eAAO,MAAM,gBAAgB,EAAE,WAAW,CAAC,KAAK,GAAG,IAAI,CAYtD,CAAA;AAaD,eAAO,MAAM,WAAW,EAAE,WAAW,CAAC,eAAe,EAAE,IAAI,CAwC1D,CAAA;AAED,uDAAuD;AACvD,eAAO,MAAM,YAAY;;;;;;;EAGvB,CAAA"}
@@ -0,0 +1,249 @@
1
+ // trust/profile — profile@1 on the holder (lib Stage 2, PR 6; Trust Layer
2
+ // 0.31 §6b): the human act that sets the own profile, its delivery on the
3
+ // class and follow-up gates of Section 2a (trust/duties.ts), and its
4
+ // reception. The wire (k_pr, MAC, bounds, the picture's header) is
5
+ // profile.ts. Wired into the trust module (trust/mapping.ts), like the
6
+ // continuity parts.
7
+ //
8
+ // Rule numbers: bare four-digit numbers are RLTP-TRU (trust-layer.md).
9
+ //
10
+ // command profile.set {name, image?, text?} the own profile; human
11
+ // (holder.setProfile): validated against 6430/6435 and the
12
+ // picture's header (6475) before anything commits, the one
13
+ // counter takes its next value (6450), state.profile holds the
14
+ // content and the revision in one step (6300), and a profile/1
15
+ // duty opens on every relationship the class is on for (6455)
16
+ // duties profile/1 (6455) and class-on/1 of the profile class (2850,
17
+ // 6465): issue the current profile@1 on one relationship
18
+ // task profile/0.1 (proof absent, 6495): conditions in the
19
+ // preparation (stage 8), the revision rule in apply (stage 9)
20
+ //
21
+ // Choices this file makes where note and spec leave them open:
22
+ // - state.profile.body is the content {name, image?, text?}; the wire body
23
+ // adds type and the revision. Setting the content the profile already
24
+ // has is ok and changes nothing: no revision, no delivery
25
+ // - a profile duty carries the revision that opened it; whichever profile
26
+ // duty runs issues the current profile (the newest content), so an older
27
+ // duty never sends an older revision. One issuance on a relationship
28
+ // meets every profile and profile class-on duty owed there. A newer
29
+ // revision supersedes the one still owed: two changes before a resume
30
+ // deliver the second only. This reads 6455 ("each new revision") through
31
+ // its rationale — a revision whose delivery fails for good stays
32
+ // undelivered until the next one, the profile replaces itself, and the
33
+ // receiver keeps only the newest (6460) — rather than its letter; the
34
+ // wording is a Trust 0.32 follow-up
35
+ // - the tuple keeps the revision last issued in its scope (profileOut,
36
+ // 6300); a class turning on again sends the current revision once more,
37
+ // which the receiver takes as a repeat (6270)
38
+ // - a duty whose relationship lags, is gone, or whose class is off is
39
+ // fulfilled without sending (6455: not on a lagging relationship; the
40
+ // follow rule opens a class-on duty once it ceases to lag, 2850)
41
+ // - 6480: the document is checked against the 65 536-byte plaintext
42
+ // limit before sealing; one over it is refused (profile-invalid), which
43
+ // the bounds of 6435 make unreachable for a valid body
44
+ // - reception: the schema at stage 7 (6430), then at stage 8 the arrival
45
+ // tuple as an active head (6190, 6461), the issuer as its counterpart,
46
+ // the picture's header (6475, before any decoding and before the MAC is
47
+ // computed), the MAC under k_pr (6440); at stage 9 the revision rule
48
+ // within the tuple's scope (6270, 6460): a higher revision replaces the
49
+ // held one (verifiedSeq: this commit), an equal identical body is a
50
+ // repeat (acked, nothing changes), an equal different body and a lower
51
+ // revision are failed(validation-failed). profile.updated names the
52
+ // entry the relationship's verifications go to
53
+ // - re-encoding the picture without metadata (6445) and showing only its
54
+ // pixels (6485) are the app's: the library reads headers only
55
+ import { iso, jcs } from '../core.js';
56
+ import { digestDoc, xRawOfMk } from '../crypto.js';
57
+ import { seal } from '../delivery.js';
58
+ import { PLAINTEXT_MAX } from '../star.js';
59
+ import { PROFILE_TYPE, assembleProfile, profileMacOk, profileProblem, profileSchemaOk } from '../profile.js';
60
+ import { tupleByRkid } from '../receive.js';
61
+ import { ADMISSION_BOUND, activeTuple, entryOf, findContact } from './state.js';
62
+ import { onFor, owedOn, profileDutyId } from './duties.js';
63
+ /** The profile module's command name. */
64
+ export const PROFILE_SET = 'profile.set';
65
+ const te = new TextEncoder();
66
+ const inc = (d) => (BigInt(d) + 1n).toString();
67
+ /** A placeholder mac of the schema's form, to validate a body before it has one. */
68
+ const NO_MAC = 'u' + 'A'.repeat(43);
69
+ /** The content as the act takes it: exactly name, image?, text? (6430). */
70
+ function contentOf(x) {
71
+ if (x === null || typeof x !== 'object' || Array.isArray(x))
72
+ throw new TypeError(`${PROFILE_SET} needs an input object`);
73
+ const i = x;
74
+ const out = { name: i.name };
75
+ if (i.image !== undefined)
76
+ out.image = i.image;
77
+ if (i.text !== undefined)
78
+ out.text = i.text;
79
+ return out;
80
+ }
81
+ const bodyOf = (content, revision) => ({ ...content, type: 'profile@1', revision });
82
+ // ── the act ────────────────────────────────────────────────────────────
83
+ /** profile/1 on every live relationship the class is on for (6455): the
84
+ * duty of each, at `rev`, replacing an older one. */
85
+ function profileDuties(state, rev) {
86
+ const duties = { ...state.duties };
87
+ for (const id of Object.keys(state.relationships).sort()) {
88
+ const r = state.relationships[id];
89
+ if (!onFor(state, r, 'profile'))
90
+ continue;
91
+ const d = { kind: 'profile', v: 1, id: profileDutyId(id), contactId: entryOf(state, r).id, relId: id, rev };
92
+ duties[d.id] = d;
93
+ }
94
+ return { ...state, duties };
95
+ }
96
+ const setCommand = {
97
+ human: true,
98
+ apply(state, _p, input) {
99
+ const content = contentOf(input);
100
+ const revision = inc(state.profile.revision);
101
+ // 6430, 6435, 6475 before anything commits
102
+ const problem = profileProblem({ body: bodyOf(content, revision), proof: { mac: NO_MAC } });
103
+ if (problem !== null)
104
+ return { ok: false, code: 'profile-invalid', ref: problem };
105
+ if (state.profile.body !== null && jcs(state.profile.body) === jcs(content))
106
+ return { state: state };
107
+ if (BigInt(revision) > ADMISSION_BOUND)
108
+ return { ok: false, code: 'scope-exhausted', ref: 'RLTP-TRU-6310' };
109
+ const next = { ...state, profile: { body: content, revision } };
110
+ return { state: profileDuties(next, revision), events: [{ type: 'profile.updated', contactId: null }] };
111
+ },
112
+ };
113
+ // ── issuance (6455) ────────────────────────────────────────────────────
114
+ /** Whether the profile can go out on `relId` toward `contactId` now: the
115
+ * relationship there, the class on for it (live, not lagging), a profile. */
116
+ function issuable(state, contactId, relId) {
117
+ const c = findContact(state, contactId);
118
+ const rel = Object.hasOwn(state.relationships, relId) ? state.relationships[relId] : undefined;
119
+ if (!c || !rel || rel.chainedInto !== null || !c.relIds.includes(rel.id) || entryOf(state, rel)?.id !== c.id)
120
+ return null;
121
+ if (state.profile.body === null || !onFor(state, rel, 'profile'))
122
+ return null;
123
+ const tuple = activeTuple(rel);
124
+ return tuple && !tuple.deactivated ? { rel, tuple, contactId: c.id } : null;
125
+ }
126
+ async function prepareIssue(ctx, duty) {
127
+ const d = duty;
128
+ const st = ctx.snapshot;
129
+ const at = issuable(st, d.contactId, d.relId);
130
+ if (!at)
131
+ return null;
132
+ const t = at.tuple;
133
+ const theirX = xRawOfMk(t.counterpartKeyAgreement);
134
+ if (!theirX)
135
+ return null;
136
+ const sh = await ctx.keys.agree(t.rkid, theirX, ctx.release);
137
+ if (sh.status !== 'available')
138
+ return null;
139
+ const S = ctx.crypto.subtle;
140
+ const own = await ctx.keys.anchorOf(t.ownPairLabel);
141
+ const artifact = await assembleProfile(bodyOf(st.profile.body, st.profile.revision), sh.shared, own.anchor, t.counterpartAnchor, S);
142
+ const threadId = ctx.entropy.id('thread.id');
143
+ const doc = {
144
+ id: ctx.entropy.id('doc.id'), type: PROFILE_TYPE, issuer: own.anchor, recipient: t.counterpartAnchor,
145
+ threadId, issuedAt: iso(ctx.when), payload: artifact,
146
+ };
147
+ // 6480: one unchunked document within the plaintext limit
148
+ if (te.encode(jcs(doc)).length > PLAINTEXT_MAX)
149
+ return null;
150
+ const envelope = await seal(doc, t.counterpartKeyAgreement, { ephSeed: ctx.entropy.bytes('seal.eph', 32), nonce: ctx.entropy.bytes('seal.nonce', 12) }, S);
151
+ return {
152
+ relId: at.rel.id, tuple: t.ownPairLabel, rev: st.profile.revision,
153
+ outbound: { digest: await digestDoc(doc, S), envelope, type: PROFILE_TYPE, threadId, recipient: { contactId: at.contactId, rkid: t.rkid, keyAgreement: t.counterpartKeyAgreement } },
154
+ };
155
+ }
156
+ /** The issuance's commit: the scope's revision (6300) and every profile
157
+ * duty owed on the relationship met by this one delivery. */
158
+ function commitIssue(state, p) {
159
+ const rel = state.relationships[p.relId];
160
+ const tuples = rel.tuples.map((t) => (t.ownPairLabel === p.tuple && BigInt(p.rev) > BigInt(t.profileOut.rev) ? { ...t, profileOut: { rev: p.rev } } : t));
161
+ const duties = {};
162
+ for (const [id, d] of Object.entries(state.duties))
163
+ if (!owedOn(d, p.relId, 'profile'))
164
+ duties[id] = d;
165
+ return { state: { ...state, relationships: { ...state.relationships, [rel.id]: { ...rel, tuples } }, duties }, outbound: [p.outbound] };
166
+ }
167
+ /** profile/1 and class-on/1 of the profile class (through classOnHandler). */
168
+ export const profileIssueDuty = {
169
+ v: 1,
170
+ prepare: (ctx, duty) => prepareIssue(ctx, duty),
171
+ apply(state, duty, ctx) {
172
+ const d = duty;
173
+ const at = issuable(state, d.contactId, d.relId);
174
+ if (!at)
175
+ return { state: state }; // off, gone, lagging, no profile: nothing owed
176
+ const p = ctx.prepared.value;
177
+ if (p === null)
178
+ return { ok: false, code: 'no-own-channel', ref: 'RLTP-TRU-6440' };
179
+ if (p.rev !== state.profile.revision || p.tuple !== at.tuple.ownPairLabel)
180
+ return 'not-due';
181
+ return commitIssue(state, p);
182
+ },
183
+ };
184
+ // ── reception (6b.2, 6b.3) ─────────────────────────────────────────────
185
+ const refuse = (reason, ref) => ({ ok: false, reason, ...(ref ? { ref } : {}) });
186
+ /** The arrival tuple, if it is the active head of a live relationship (6190, 6461). */
187
+ const arrivalTuple = (state, rkid) => {
188
+ const at = tupleByRkid(state, rkid);
189
+ if (!at || at.tuple.deactivated || at.rel.chainedInto !== null || at.rel.activeHead !== at.tuple.ownPairLabel)
190
+ return null;
191
+ return at;
192
+ };
193
+ export const profileTask = {
194
+ proof: 'absent',
195
+ // stage 7: the closed body and proof with their bounds (6430, 6435)
196
+ decode: (payload) => (profileSchemaOk(payload) ? payload : refuse('malformed', 'RLTP-TRU-6430')),
197
+ // stage 8: the arrival tuple, the picture's header, the MAC
198
+ async prepare(ctx, doc, arrival) {
199
+ if (doc.ceremony?.enactment !== undefined)
200
+ return refuse('validation-failed');
201
+ const at = arrivalTuple(ctx.snapshot, arrival.rkid);
202
+ if (!at)
203
+ return refuse('validation-failed', 'RLTP-TRU-6190');
204
+ if (doc.issuer !== at.tuple.counterpartAnchor)
205
+ return refuse('validation-failed', 'RLTP-TRU-6440');
206
+ const problem = profileProblem(doc.payload);
207
+ if (problem !== null)
208
+ return refuse('validation-failed', problem);
209
+ const theirX = xRawOfMk(at.tuple.counterpartKeyAgreement);
210
+ if (!theirX)
211
+ return refuse('validation-failed', 'RLTP-TRU-6440');
212
+ const sh = await ctx.keys.agree(at.tuple.rkid, theirX, ctx.release);
213
+ if (sh.status !== 'available')
214
+ return refuse('validation-failed', 'RLTP-TRU-6440');
215
+ const own = await ctx.keys.anchorOf(at.tuple.ownPairLabel);
216
+ if (!(await profileMacOk(doc.payload, sh.shared, at.tuple.counterpartAnchor, own.anchor, ctx.crypto.subtle)))
217
+ return refuse('validation-failed', 'RLTP-TRU-6440');
218
+ return null;
219
+ },
220
+ // stage 9: the revision rule within the tuple's scope (6270, 6460)
221
+ apply(state, _p, doc, arrival) {
222
+ const at = arrivalTuple(state, arrival.rkid);
223
+ if (!at)
224
+ return refuse('validation-failed', 'RLTP-TRU-6190');
225
+ const { rel, tuple: t } = at;
226
+ const b = doc.payload.body;
227
+ const rev = BigInt(b.revision), cur = BigInt(t.profileIn.rev);
228
+ if (rev === cur) {
229
+ if (t.profileIn.body === null || jcs(b) !== jcs(t.profileIn.body))
230
+ return refuse('validation-failed', 'RLTP-TRU-6270');
231
+ return { state: state }; // a repeat
232
+ }
233
+ if (rev < cur)
234
+ return refuse('validation-failed', 'RLTP-TRU-6460');
235
+ const tuples = rel.tuples.map((x) => (x.ownPairLabel === t.ownPairLabel
236
+ ? { ...x, profileIn: { rev: b.revision, body: b, verifiedSeq: inc(state.commitSeq) } }
237
+ : x));
238
+ return {
239
+ state: { ...state, relationships: { ...state.relationships, [rel.id]: { ...rel, tuples } } },
240
+ events: [{ type: 'profile.updated', contactId: entryOf(state, rel)?.id ?? rel.contactId }],
241
+ };
242
+ },
243
+ };
244
+ /** What the trust module registers for the profile. */
245
+ export const profileParts = Object.freeze({
246
+ commands: Object.freeze({ [PROFILE_SET]: setCommand }),
247
+ tasks: Object.freeze({ [PROFILE_TYPE]: profileTask }),
248
+ });
249
+ //# sourceMappingURL=profile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profile.js","sourceRoot":"","sources":["../../src/trust/profile.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,0EAA0E;AAC1E,qEAAqE;AACrE,mEAAmE;AACnE,uEAAuE;AACvE,oBAAoB;AACpB,EAAE;AACF,uEAAuE;AACvE,EAAE;AACF,wEAAwE;AACxE,wEAAwE;AACxE,wEAAwE;AACxE,4EAA4E;AAC5E,4EAA4E;AAC5E,2EAA2E;AAC3E,yEAAyE;AACzE,sEAAsE;AACtE,iEAAiE;AACjE,2EAA2E;AAC3E,EAAE;AACF,+DAA+D;AAC/D,6EAA6E;AAC7E,0EAA0E;AAC1E,8DAA8D;AAC9D,4EAA4E;AAC5E,6EAA6E;AAC7E,yEAAyE;AACzE,wEAAwE;AACxE,0EAA0E;AAC1E,6EAA6E;AAC7E,qEAAqE;AACrE,2EAA2E;AAC3E,0EAA0E;AAC1E,wCAAwC;AACxC,yEAAyE;AACzE,4EAA4E;AAC5E,kDAAkD;AAClD,wEAAwE;AACxE,0EAA0E;AAC1E,qEAAqE;AACrE,sEAAsE;AACtE,4EAA4E;AAC5E,2DAA2D;AAC3D,2EAA2E;AAC3E,2EAA2E;AAC3E,4EAA4E;AAC5E,yEAAyE;AACzE,4EAA4E;AAC5E,wEAAwE;AACxE,2EAA2E;AAC3E,wEAAwE;AACxE,mDAAmD;AACnD,2EAA2E;AAC3E,kEAAkE;AAClE,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AAE,CAAC,EAAE,EAAE,GAAG,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE;YAC5F,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,SAAS,EAAE,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,EAAE,IAAI,GAAG,CAAC,SAAS,EAAE,CAAC;SAC3F,CAAA;IACH,CAAC;CACF,CAAA;AAED,uDAAuD;AACvD,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC;IACxC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IACtD,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,YAAY,CAAC,EAAE,WAAW,EAAE,CAAC;CACtD,CAAC,CAAA","sourcesContent":["// trust/profile — profile@1 on the holder (lib Stage 2, PR 6; Trust Layer\n// 0.31 §6b): the human act that sets the own profile, its delivery on the\n// class and follow-up gates of Section 2a (trust/duties.ts), and its\n// reception. The wire (k_pr, MAC, bounds, the picture's header) is\n// profile.ts. Wired into the trust module (trust/mapping.ts), like the\n// continuity parts.\n//\n// Rule numbers: bare four-digit numbers are RLTP-TRU (trust-layer.md).\n//\n// command profile.set {name, image?, text?} the own profile; human\n// (holder.setProfile): validated against 6430/6435 and the\n// picture's header (6475) before anything commits, the one\n// counter takes its next value (6450), state.profile holds the\n// content and the revision in one step (6300), and a profile/1\n// duty opens on every relationship the class is on for (6455)\n// duties profile/1 (6455) and class-on/1 of the profile class (2850,\n// 6465): issue the current profile@1 on one relationship\n// task profile/0.1 (proof absent, 6495): conditions in the\n// preparation (stage 8), the revision rule in apply (stage 9)\n//\n// Choices this file makes where note and spec leave them open:\n// - state.profile.body is the content {name, image?, text?}; the wire body\n// adds type and the revision. Setting the content the profile already\n// has is ok and changes nothing: no revision, no delivery\n// - a profile duty carries the revision that opened it; whichever profile\n// duty runs issues the current profile (the newest content), so an older\n// duty never sends an older revision. One issuance on a relationship\n// meets every profile and profile class-on duty owed there. A newer\n// revision supersedes the one still owed: two changes before a resume\n// deliver the second only. This reads 6455 (\"each new revision\") through\n// its rationale — a revision whose delivery fails for good stays\n// undelivered until the next one, the profile replaces itself, and the\n// receiver keeps only the newest (6460) — rather than its letter; the\n// wording is a Trust 0.32 follow-up\n// - the tuple keeps the revision last issued in its scope (profileOut,\n// 6300); a class turning on again sends the current revision once more,\n// which the receiver takes as a repeat (6270)\n// - a duty whose relationship lags, is gone, or whose class is off is\n// fulfilled without sending (6455: not on a lagging relationship; the\n// follow rule opens a class-on duty once it ceases to lag, 2850)\n// - 6480: the document is checked against the 65 536-byte plaintext\n// limit before sealing; one over it is refused (profile-invalid), which\n// the bounds of 6435 make unreachable for a valid body\n// - reception: the schema at stage 7 (6430), then at stage 8 the arrival\n// tuple as an active head (6190, 6461), the issuer as its counterpart,\n// the picture's header (6475, before any decoding and before the MAC is\n// computed), the MAC under k_pr (6440); at stage 9 the revision rule\n// within the tuple's scope (6270, 6460): a higher revision replaces the\n// held one (verifiedSeq: this commit), an equal identical body is a\n// repeat (acked, nothing changes), an equal different body and a lower\n// revision are failed(validation-failed). profile.updated names the\n// entry the relationship's verifications go to\n// - re-encoding the picture without metadata (6445) and showing only its\n// pixels (6485) are the app's: the library reads headers only\nimport { iso, jcs } from '../core.js'\nimport type { Json } from '../core.js'\nimport { digestDoc, xRawOfMk } from '../crypto.js'\nimport { seal } from '../delivery.js'\nimport { PLAINTEXT_MAX } from '../star.js'\nimport { PROFILE_TYPE, assembleProfile, profileMacOk, profileProblem, profileSchemaOk } from '../profile.js'\nimport type { ProfileArtifact, ProfileBody, ProfileContent } from '../profile.js'\nimport { tupleByRkid } from '../receive.js'\nimport type { Arrival, ReceivedDocument, TaskRefusal } from '../receive.js'\nimport type { Applied, CommandDef, DutyHandler, OutboundDraft, PrepareCtx, Refusal, TaskHandler } from '../engine.js'\nimport type { ClassOnDuty, Dec, Duty, HolderState, ProfileDuty, Relationship, Tuple } from '../state.js'\nimport { ADMISSION_BOUND, activeTuple, entryOf, findContact } from './state.js'\nimport { onFor, owedOn, profileDutyId } from './duties.js'\n\n/** The profile module's command name. */\nexport const PROFILE_SET = 'profile.set'\n\nconst te = new TextEncoder()\nconst inc = (d: Dec): Dec => (BigInt(d) + 1n).toString()\n/** A placeholder mac of the schema's form, to validate a body before it has one. */\nconst NO_MAC = 'u' + 'A'.repeat(43)\n\n/** The content as the act takes it: exactly name, image?, text? (6430). */\nfunction contentOf (x: unknown): ProfileContent {\n if (x === null || typeof x !== 'object' || Array.isArray(x)) throw new TypeError(`${PROFILE_SET} needs an input object`)\n const i = x as Record<string, unknown>\n const out: ProfileContent = { name: i.name as string }\n if (i.image !== undefined) out.image = i.image as string\n if (i.text !== undefined) out.text = i.text as string\n return out\n}\n\nconst bodyOf = (content: Json, revision: Dec): ProfileBody => ({ ...(content as unknown as ProfileContent), type: 'profile@1', revision })\n\n// ── the act ────────────────────────────────────────────────────────────\n\n/** profile/1 on every live relationship the class is on for (6455): the\n * duty of each, at `rev`, replacing an older one. */\nfunction profileDuties (state: HolderState, rev: Dec): HolderState {\n const duties = { ...state.duties }\n for (const id of Object.keys(state.relationships).sort()) {\n const r = state.relationships[id]\n if (!onFor(state, r, 'profile')) continue\n const d: ProfileDuty = { kind: 'profile', v: 1, id: profileDutyId(id), contactId: entryOf(state, r)!.id, relId: id, rev }\n duties[d.id] = d\n }\n return { ...state, duties }\n}\n\nconst setCommand: CommandDef<ProfileContent> = {\n human: true,\n apply (state, _p, input) {\n const content = contentOf(input)\n const revision = inc(state.profile.revision)\n // 6430, 6435, 6475 before anything commits\n const problem = profileProblem({ body: bodyOf(content as unknown as Json, revision), proof: { mac: NO_MAC } })\n if (problem !== null) return { ok: false, code: 'profile-invalid', ref: problem } satisfies Refusal\n if (state.profile.body !== null && jcs(state.profile.body) === jcs(content)) return { state: state as HolderState }\n if (BigInt(revision) > ADMISSION_BOUND) return { ok: false, code: 'scope-exhausted', ref: 'RLTP-TRU-6310' }\n const next: HolderState = { ...state, profile: { body: content as unknown as Json, revision } }\n return { state: profileDuties(next, revision), events: [{ type: 'profile.updated', contactId: null }] }\n },\n}\n\n// ── issuance (6455) ────────────────────────────────────────────────────\n\n/** Whether the profile can go out on `relId` toward `contactId` now: the\n * relationship there, the class on for it (live, not lagging), a profile. */\nfunction issuable (state: Readonly<HolderState>, contactId: string, relId: string): { rel: Relationship, tuple: Tuple, contactId: string } | null {\n const c = findContact(state, contactId)\n const rel = Object.hasOwn(state.relationships, relId) ? state.relationships[relId] : undefined\n if (!c || !rel || rel.chainedInto !== null || !c.relIds.includes(rel.id) || entryOf(state, rel)?.id !== c.id) return null\n if (state.profile.body === null || !onFor(state, rel, 'profile')) return null\n const tuple = activeTuple(rel)\n return tuple && !tuple.deactivated ? { rel, tuple, contactId: c.id } : null\n}\n\ninterface Issue { relId: string, tuple: string, rev: Dec, outbound: OutboundDraft }\n\nasync function prepareIssue (ctx: PrepareCtx, duty: Duty): Promise<Issue | null> {\n const d = duty as ProfileDuty | ClassOnDuty\n const st = ctx.snapshot\n const at = issuable(st, d.contactId, d.relId)\n if (!at) return null\n const t = at.tuple\n const theirX = xRawOfMk(t.counterpartKeyAgreement)\n if (!theirX) return null\n const sh = await ctx.keys.agree(t.rkid, theirX, ctx.release)\n if (sh.status !== 'available') return null\n const S = ctx.crypto.subtle\n const own = await ctx.keys.anchorOf(t.ownPairLabel)\n const artifact = await assembleProfile(bodyOf(st.profile.body!, st.profile.revision), sh.shared, own.anchor, t.counterpartAnchor, S)\n const threadId = ctx.entropy.id('thread.id')\n const doc = {\n id: ctx.entropy.id('doc.id'), type: PROFILE_TYPE, issuer: own.anchor, recipient: t.counterpartAnchor,\n threadId, issuedAt: iso(ctx.when), payload: artifact as unknown as Json,\n }\n // 6480: one unchunked document within the plaintext limit\n if (te.encode(jcs(doc)).length > PLAINTEXT_MAX) return null\n const envelope = await seal(doc, t.counterpartKeyAgreement, { ephSeed: ctx.entropy.bytes('seal.eph', 32), nonce: ctx.entropy.bytes('seal.nonce', 12) }, S)\n return {\n relId: at.rel.id, tuple: t.ownPairLabel, rev: st.profile.revision,\n outbound: { digest: await digestDoc(doc, S), envelope, type: PROFILE_TYPE, threadId, recipient: { contactId: at.contactId, rkid: t.rkid, keyAgreement: t.counterpartKeyAgreement } },\n }\n}\n\n/** The issuance's commit: the scope's revision (6300) and every profile\n * duty owed on the relationship met by this one delivery. */\nfunction commitIssue (state: Readonly<HolderState>, p: Issue): Applied {\n const rel = state.relationships[p.relId]\n const tuples = rel.tuples.map((t) => (t.ownPairLabel === p.tuple && BigInt(p.rev) > BigInt(t.profileOut.rev) ? { ...t, profileOut: { rev: p.rev } } : t))\n const duties: Record<string, Duty> = {}\n for (const [id, d] of Object.entries(state.duties)) if (!owedOn(d, p.relId, 'profile')) duties[id] = d\n return { state: { ...state, relationships: { ...state.relationships, [rel.id]: { ...rel, tuples } }, duties }, outbound: [p.outbound] }\n}\n\n/** profile/1 and class-on/1 of the profile class (through classOnHandler). */\nexport const profileIssueDuty: DutyHandler<Issue | null> = {\n v: 1,\n prepare: (ctx, duty) => prepareIssue(ctx, duty),\n apply (state, duty, ctx) {\n const d = duty as ProfileDuty | ClassOnDuty\n const at = issuable(state, d.contactId, d.relId)\n if (!at) return { state: state as HolderState } // off, gone, lagging, no profile: nothing owed\n const p = ctx.prepared.value\n if (p === null) return { ok: false, code: 'no-own-channel', ref: 'RLTP-TRU-6440' }\n if (p.rev !== state.profile.revision || p.tuple !== at.tuple.ownPairLabel) return 'not-due'\n return commitIssue(state, p)\n },\n}\n\n// ── reception (6b.2, 6b.3) ─────────────────────────────────────────────\n\nconst refuse = (reason: TaskRefusal['reason'], ref?: string): TaskRefusal => ({ ok: false, reason, ...(ref ? { ref } : {}) })\n\n/** The arrival tuple, if it is the active head of a live relationship (6190, 6461). */\nconst arrivalTuple = (state: Readonly<HolderState>, rkid: string): { rel: Relationship, tuple: Tuple } | null => {\n const at = tupleByRkid(state, rkid)\n if (!at || at.tuple.deactivated || at.rel.chainedInto !== null || at.rel.activeHead !== at.tuple.ownPairLabel) return null\n return at\n}\n\nexport const profileTask: TaskHandler<ProfileArtifact, null> = {\n proof: 'absent',\n // stage 7: the closed body and proof with their bounds (6430, 6435)\n decode: (payload) => (profileSchemaOk(payload) ? payload as ProfileArtifact : refuse('malformed', 'RLTP-TRU-6430')),\n // stage 8: the arrival tuple, the picture's header, the MAC\n async prepare (ctx, doc: ReceivedDocument<ProfileArtifact>, arrival: Arrival) {\n if ((doc.ceremony as { enactment?: unknown } | undefined)?.enactment !== undefined) return refuse('validation-failed')\n const at = arrivalTuple(ctx.snapshot, arrival.rkid)\n if (!at) return refuse('validation-failed', 'RLTP-TRU-6190')\n if (doc.issuer !== at.tuple.counterpartAnchor) return refuse('validation-failed', 'RLTP-TRU-6440')\n const problem = profileProblem(doc.payload)\n if (problem !== null) return refuse('validation-failed', problem)\n const theirX = xRawOfMk(at.tuple.counterpartKeyAgreement)\n if (!theirX) return refuse('validation-failed', 'RLTP-TRU-6440')\n const sh = await ctx.keys.agree(at.tuple.rkid, theirX, ctx.release)\n if (sh.status !== 'available') return refuse('validation-failed', 'RLTP-TRU-6440')\n const own = await ctx.keys.anchorOf(at.tuple.ownPairLabel)\n if (!(await profileMacOk(doc.payload, sh.shared, at.tuple.counterpartAnchor, own.anchor, ctx.crypto.subtle))) return refuse('validation-failed', 'RLTP-TRU-6440')\n return null\n },\n // stage 9: the revision rule within the tuple's scope (6270, 6460)\n apply (state, _p, doc: ReceivedDocument<ProfileArtifact>, arrival: Arrival) {\n const at = arrivalTuple(state, arrival.rkid)\n if (!at) return refuse('validation-failed', 'RLTP-TRU-6190')\n const { rel, tuple: t } = at\n const b = doc.payload.body\n const rev = BigInt(b.revision), cur = BigInt(t.profileIn.rev)\n if (rev === cur) {\n if (t.profileIn.body === null || jcs(b) !== jcs(t.profileIn.body)) return refuse('validation-failed', 'RLTP-TRU-6270')\n return { state: state as HolderState } // a repeat\n }\n if (rev < cur) return refuse('validation-failed', 'RLTP-TRU-6460')\n const tuples = rel.tuples.map((x) => (x.ownPairLabel === t.ownPairLabel\n ? { ...x, profileIn: { rev: b.revision, body: b as unknown as Json, verifiedSeq: inc(state.commitSeq) } }\n : x))\n return {\n state: { ...state, relationships: { ...state.relationships, [rel.id]: { ...rel, tuples } } },\n events: [{ type: 'profile.updated', contactId: entryOf(state, rel)?.id ?? rel.contactId }],\n }\n },\n}\n\n/** What the trust module registers for the profile. */\nexport const profileParts = Object.freeze({\n commands: Object.freeze({ [PROFILE_SET]: setCommand }),\n tasks: Object.freeze({ [PROFILE_TYPE]: profileTask }),\n})\n"]}