@941design/marmot 0.0.0-stage → 0.2.0-alpha.1

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 (206) hide show
  1. package/CHANGELOG.md +739 -0
  2. package/LICENSE +21 -0
  3. package/README.md +33 -2
  4. package/dist/account/admin.d.ts +72 -0
  5. package/dist/account/admin.js +209 -0
  6. package/dist/account/device-deps.d.ts +379 -0
  7. package/dist/account/device-deps.js +36 -0
  8. package/dist/account/device-lineage.d.ts +199 -0
  9. package/dist/account/device-lineage.js +390 -0
  10. package/dist/account/device-registry.d.ts +93 -0
  11. package/dist/account/device-registry.js +1290 -0
  12. package/dist/account/device-rotation.d.ts +61 -0
  13. package/dist/account/device-rotation.js +827 -0
  14. package/dist/account/enrolment.d.ts +339 -0
  15. package/dist/account/enrolment.js +1247 -0
  16. package/dist/account/identity-proof.d.ts +79 -0
  17. package/dist/account/identity-proof.js +264 -0
  18. package/dist/account/index.d.ts +17 -0
  19. package/dist/account/index.js +16 -0
  20. package/dist/account/restore-rotation.d.ts +21 -0
  21. package/dist/account/restore-rotation.js +22 -0
  22. package/dist/account/same-account-authorization.d.ts +86 -0
  23. package/dist/account/same-account-authorization.js +180 -0
  24. package/dist/account/teardown.d.ts +190 -0
  25. package/dist/account/teardown.js +878 -0
  26. package/dist/client/admission-cleanup.d.ts +197 -0
  27. package/dist/client/admission-cleanup.js +635 -0
  28. package/dist/client/adoption-proof.d.ts +39 -0
  29. package/dist/client/adoption-proof.js +102 -0
  30. package/dist/client/before-create-group.d.ts +18 -0
  31. package/dist/client/before-create-group.js +65 -0
  32. package/dist/client/before-publish-hooks.d.ts +121 -0
  33. package/dist/client/before-publish-hooks.js +182 -0
  34. package/dist/client/client-config.d.ts +42 -0
  35. package/dist/client/client-config.js +13 -0
  36. package/dist/client/commit-redrive.d.ts +92 -0
  37. package/dist/client/commit-redrive.js +274 -0
  38. package/dist/client/component-update.d.ts +43 -0
  39. package/dist/client/component-update.js +53 -0
  40. package/dist/client/confirm-hooks.d.ts +55 -0
  41. package/dist/client/confirm-hooks.js +74 -0
  42. package/dist/client/create-client.d.ts +1126 -0
  43. package/dist/client/create-client.js +1232 -0
  44. package/dist/client/group-availability.d.ts +182 -0
  45. package/dist/client/group-availability.js +301 -0
  46. package/dist/client/group-disband.d.ts +28 -0
  47. package/dist/client/group-disband.js +64 -0
  48. package/dist/client/group-history.d.ts +461 -0
  49. package/dist/client/group-history.js +1365 -0
  50. package/dist/client/group-profile.d.ts +31 -0
  51. package/dist/client/group-profile.js +62 -0
  52. package/dist/client/group-records.d.ts +522 -0
  53. package/dist/client/group-records.js +1117 -0
  54. package/dist/client/group-removal.d.ts +36 -0
  55. package/dist/client/group-removal.js +127 -0
  56. package/dist/client/group-remove-member.d.ts +49 -0
  57. package/dist/client/group-remove-member.js +163 -0
  58. package/dist/client/group-runtime.d.ts +415 -0
  59. package/dist/client/group-runtime.js +2811 -0
  60. package/dist/client/group-snapshot.d.ts +104 -0
  61. package/dist/client/group-snapshot.js +474 -0
  62. package/dist/client/history-pages.d.ts +107 -0
  63. package/dist/client/history-pages.js +194 -0
  64. package/dist/client/inbox-send.d.ts +19 -0
  65. package/dist/client/inbox-send.js +71 -0
  66. package/dist/client/index.d.ts +24 -0
  67. package/dist/client/index.js +13 -0
  68. package/dist/client/ingest.d.ts +82 -0
  69. package/dist/client/ingest.js +1584 -0
  70. package/dist/client/invitation-outcomes.d.ts +50 -0
  71. package/dist/client/invitation-outcomes.js +135 -0
  72. package/dist/client/lifecycle-events.d.ts +63 -0
  73. package/dist/client/lifecycle-events.js +35 -0
  74. package/dist/client/opaque-candidates.d.ts +82 -0
  75. package/dist/client/opaque-candidates.js +170 -0
  76. package/dist/client/own-change-outbox.d.ts +66 -0
  77. package/dist/client/own-change-outbox.js +158 -0
  78. package/dist/client/pending-leaf.d.ts +116 -0
  79. package/dist/client/pending-leaf.js +378 -0
  80. package/dist/client/permissions.d.ts +9 -0
  81. package/dist/client/permissions.js +12 -0
  82. package/dist/client/pipeline.d.ts +583 -0
  83. package/dist/client/pipeline.js +3666 -0
  84. package/dist/client/reentrancy-guard.d.ts +102 -0
  85. package/dist/client/reentrancy-guard.js +159 -0
  86. package/dist/client/rekey.d.ts +58 -0
  87. package/dist/client/rekey.js +149 -0
  88. package/dist/client/transport-policy.d.ts +181 -0
  89. package/dist/client/transport-policy.js +214 -0
  90. package/dist/history/admission-lineage.d.ts +186 -0
  91. package/dist/history/admission-lineage.js +589 -0
  92. package/dist/history/equivocation.d.ts +55 -0
  93. package/dist/history/equivocation.js +113 -0
  94. package/dist/history/fencing.d.ts +66 -0
  95. package/dist/history/fencing.js +121 -0
  96. package/dist/history/hex.d.ts +3 -0
  97. package/dist/history/hex.js +10 -0
  98. package/dist/history/index.d.ts +74 -0
  99. package/dist/history/index.js +32 -0
  100. package/dist/history/notifications.d.ts +270 -0
  101. package/dist/history/notifications.js +264 -0
  102. package/dist/history/ordering-key.d.ts +24 -0
  103. package/dist/history/ordering-key.js +101 -0
  104. package/dist/history/own-change-fork.d.ts +112 -0
  105. package/dist/history/own-change-fork.js +196 -0
  106. package/dist/history/own-change.d.ts +118 -0
  107. package/dist/history/own-change.js +146 -0
  108. package/dist/history/policy.d.ts +48 -0
  109. package/dist/history/policy.js +52 -0
  110. package/dist/history/retained-window.d.ts +215 -0
  111. package/dist/history/retained-window.js +565 -0
  112. package/dist/inbox/demux.d.ts +90 -0
  113. package/dist/inbox/demux.js +78 -0
  114. package/dist/inbox/handler-registry.d.ts +42 -0
  115. package/dist/inbox/handler-registry.js +37 -0
  116. package/dist/inbox/index.d.ts +11 -0
  117. package/dist/inbox/index.js +10 -0
  118. package/dist/inbox/seen-set.d.ts +82 -0
  119. package/dist/inbox/seen-set.js +202 -0
  120. package/dist/inbox/subscription.d.ts +236 -0
  121. package/dist/inbox/subscription.js +644 -0
  122. package/dist/index.d.ts +10 -0
  123. package/dist/index.js +9 -0
  124. package/dist/invitations/competing-welcome.d.ts +223 -0
  125. package/dist/invitations/competing-welcome.js +128 -0
  126. package/dist/invitations/decline.d.ts +67 -0
  127. package/dist/invitations/decline.js +149 -0
  128. package/dist/invitations/delivery-evidence.d.ts +288 -0
  129. package/dist/invitations/delivery-evidence.js +766 -0
  130. package/dist/invitations/expect-welcome.d.ts +66 -0
  131. package/dist/invitations/expect-welcome.js +138 -0
  132. package/dist/invitations/index.d.ts +18 -0
  133. package/dist/invitations/index.js +18 -0
  134. package/dist/invitations/invitation-outcome.d.ts +110 -0
  135. package/dist/invitations/invitation-outcome.js +210 -0
  136. package/dist/invitations/invite.d.ts +358 -0
  137. package/dist/invitations/invite.js +1102 -0
  138. package/dist/invitations/offers.d.ts +79 -0
  139. package/dist/invitations/offers.js +115 -0
  140. package/dist/invitations/on-proposal.d.ts +47 -0
  141. package/dist/invitations/on-proposal.js +40 -0
  142. package/dist/invitations/pending-proposal-policy.d.ts +52 -0
  143. package/dist/invitations/pending-proposal-policy.js +139 -0
  144. package/dist/invitations/proposal-deadline.d.ts +133 -0
  145. package/dist/invitations/proposal-deadline.js +164 -0
  146. package/dist/invitations/relay-planes.d.ts +43 -0
  147. package/dist/invitations/relay-planes.js +70 -0
  148. package/dist/invitations/welcome-processor.d.ts +272 -0
  149. package/dist/invitations/welcome-processor.js +1241 -0
  150. package/dist/key-packages/device-key.d.ts +131 -0
  151. package/dist/key-packages/device-key.js +272 -0
  152. package/dist/key-packages/device-rotation-records.d.ts +83 -0
  153. package/dist/key-packages/device-rotation-records.js +173 -0
  154. package/dist/key-packages/group-refs.d.ts +40 -0
  155. package/dist/key-packages/group-refs.js +79 -0
  156. package/dist/key-packages/index.d.ts +18 -0
  157. package/dist/key-packages/index.js +18 -0
  158. package/dist/key-packages/key-package-ref.d.ts +16 -0
  159. package/dist/key-packages/key-package-ref.js +21 -0
  160. package/dist/key-packages/observation-stream.d.ts +4 -0
  161. package/dist/key-packages/observation-stream.js +120 -0
  162. package/dist/key-packages/offer-rumor.d.ts +26 -0
  163. package/dist/key-packages/offer-rumor.js +69 -0
  164. package/dist/key-packages/publisher.d.ts +174 -0
  165. package/dist/key-packages/publisher.js +1247 -0
  166. package/dist/key-packages/select-key-package.d.ts +24 -0
  167. package/dist/key-packages/select-key-package.js +90 -0
  168. package/dist/key-packages/slot-manager.d.ts +167 -0
  169. package/dist/key-packages/slot-manager.js +327 -0
  170. package/dist/key-packages/validate-key-package-event.d.ts +3 -0
  171. package/dist/key-packages/validate-key-package-event.js +49 -0
  172. package/dist/media/cache.d.ts +14 -0
  173. package/dist/media/cache.js +10 -0
  174. package/dist/media/index.d.ts +52 -0
  175. package/dist/media/index.js +71 -0
  176. package/dist/mls.d.ts +15 -0
  177. package/dist/mls.js +15 -0
  178. package/dist/shared/account-pubkey.d.ts +4 -0
  179. package/dist/shared/account-pubkey.js +10 -0
  180. package/dist/shared/errors.d.ts +28 -0
  181. package/dist/shared/errors.js +96 -0
  182. package/dist/shared/hex.d.ts +4 -0
  183. package/dist/shared/hex.js +13 -0
  184. package/dist/shared/index.d.ts +14 -0
  185. package/dist/shared/index.js +14 -0
  186. package/dist/shared/kinds.d.ts +8 -0
  187. package/dist/shared/kinds.js +28 -0
  188. package/dist/shared/publish-classification.d.ts +26 -0
  189. package/dist/shared/publish-classification.js +31 -0
  190. package/dist/storage/envelope.d.ts +39 -0
  191. package/dist/storage/envelope.js +201 -0
  192. package/dist/storage/index.d.ts +237 -0
  193. package/dist/storage/index.js +491 -0
  194. package/dist/storage/indexeddb/idb-types.d.ts +68 -0
  195. package/dist/storage/indexeddb/idb-types.js +1 -0
  196. package/dist/storage/indexeddb/index.d.ts +17 -0
  197. package/dist/storage/indexeddb/index.js +141 -0
  198. package/dist/storage/lease.d.ts +54 -0
  199. package/dist/storage/lease.js +168 -0
  200. package/dist/storage/memory/deterministic-signer.d.ts +27 -0
  201. package/dist/storage/memory/deterministic-signer.js +65 -0
  202. package/dist/storage/memory/index.d.ts +32 -0
  203. package/dist/storage/memory/index.js +87 -0
  204. package/dist/storage/memory/lock-manager.d.ts +8 -0
  205. package/dist/storage/memory/lock-manager.js +71 -0
  206. package/package.json +66 -3
@@ -0,0 +1,66 @@
1
+ import type { KeyValueView } from '../storage/index.js';
2
+ export interface WelcomeManifestInput {
3
+ readonly groupId: string;
4
+ readonly keyPackageRef: string;
5
+ readonly sponsorAccount: string;
6
+ /** Client-clock milliseconds. */
7
+ readonly deadline: number;
8
+ /**
9
+ * Client-clock milliseconds at which the device recorded this manifest with its enrolment request (`requestEnrolment`
10
+ * only; `expectWelcome` never sets it). The time the device asked to be admitted: a forget of the own device that
11
+ * started at or before it is superseded when the Welcome is adopted. Absent: not an enrolment manifest.
12
+ */
13
+ readonly recordedAt?: number;
14
+ }
15
+ export type ManifestStatus = 'waiting' | 'fulfilled' | 'expired';
16
+ export interface ManifestRecord extends WelcomeManifestInput {
17
+ readonly v: 1;
18
+ readonly status: ManifestStatus;
19
+ /** Invitation joined under this manifest (`fulfilled` only). */
20
+ readonly invitationId?: string;
21
+ }
22
+ export declare function manifestKey(groupId: string, keyPackageRef: string): string;
23
+ /** Validates an `expectWelcome` argument (hex ids lower-case, `deadline` after `nowMs`). */
24
+ export declare function validateManifest(manifest: unknown, nowMs: number): WelcomeManifestInput;
25
+ export declare function decodeManifest(key: string, raw: unknown): ManifestRecord;
26
+ export declare function readManifest(tx: {
27
+ artifact(name: 'enrolmentManifests'): KeyValueView;
28
+ }, groupId: string, keyPackageRef: string): Promise<ManifestRecord | undefined>;
29
+ export declare function writeManifest(tx: {
30
+ artifact(name: 'enrolmentManifests'): KeyValueView;
31
+ }, record: ManifestRecord): Promise<void>;
32
+ /**
33
+ * Records `manifest` as `waiting`. A manifest for the same (group,
34
+ * KeyPackageRef) that is still waiting is replaced (a new deadline or
35
+ * sponsor); a fulfilled one is kept — that Welcome is already joined.
36
+ */
37
+ export declare function recordManifest(tx: {
38
+ artifact(name: 'enrolmentManifests'): KeyValueView;
39
+ }, manifest: WelcomeManifestInput): Promise<ManifestRecord>;
40
+ /**
41
+ * Starting a forget of the own device: every WAITING manifest loses its `recordedAt`, so the Welcome of a request made
42
+ * before the forget can never end it (it is not an answer to a decision made after the forget), whatever the clock says.
43
+ * Rows are read loosely; one that does not read is left as it is.
44
+ */
45
+ export declare function stripWaitingRequestTimes(tx: {
46
+ artifact(name: 'enrolmentManifests'): KeyValueView;
47
+ }): Promise<void>;
48
+ /** S9 teardown: the KeyPackageRefs of every manifest of `groupId` (keys are `<groupId>:<ref>`). */
49
+ export declare function manifestRefsOfGroup(tx: {
50
+ artifact(name: 'enrolmentManifests'): KeyValueView;
51
+ }, groupId: string): Promise<string[]>;
52
+ /** S9 teardown: deletes every manifest of `groupId`. */
53
+ export declare function purgeGroupManifests(tx: {
54
+ artifact(name: 'enrolmentManifests'): KeyValueView;
55
+ }, groupId: string): Promise<void>;
56
+ /** What a waiting manifest makes of a joined Welcome candidate. */
57
+ export type ManifestMatch = 'accept' | 'expired' | 'mismatch' | 'none';
58
+ /**
59
+ * AC-WEL-1: `accept` only for a waiting manifest whose sponsor equals the
60
+ * Welcome's sponsor, processed before its deadline; `expired` when the
61
+ * deadline has passed (the caller marks it); `mismatch` when the sponsor
62
+ * differs; `none` without a waiting manifest.
63
+ */
64
+ export declare function matchManifest(manifest: ManifestRecord | undefined, candidate: {
65
+ readonly sponsorAccount: string;
66
+ }, nowMs: number): ManifestMatch;
@@ -0,0 +1,138 @@
1
+ /**
2
+ * `expectWelcome(manifest)` (S6, AC-WEL-1): manifest validation, the
3
+ * account `enrolmentManifests` record codec (ADR-008: one API for
4
+ * application invitations and ADR-003 enrolment, so both share the
5
+ * artifact) and the match rule. Pure helpers; `welcome-processor.ts` runs
6
+ * them on the inbox's serial queue.
7
+ *
8
+ * A manifest auto-accepts a Welcome only when its group id, the consumed
9
+ * KeyPackageRef and the sponsor account all equal the manifest's and it is
10
+ * processed before `deadline` (client-clock milliseconds). One processed at
11
+ * or after the deadline expires the manifest and is surfaced as an
12
+ * unexpected Welcome instead (AC-WEL-5). The sponsor is the account of the
13
+ * leaf that signed the Welcome's GroupInfo, recovered during the join by the
14
+ * engine's `joinGroupFromWelcomeWithSigner` seam; who sealed or forwarded the
15
+ * copy does not matter.
16
+ */
17
+ import { MarmotError } from '../shared/index.js';
18
+ const MANIFESTS = 'enrolmentManifests';
19
+ const HEX = /^[0-9a-f]+$/;
20
+ const PUBKEY = /^[0-9a-f]{64}$/;
21
+ const STATUSES = new Set(['waiting', 'fulfilled', 'expired']);
22
+ export function manifestKey(groupId, keyPackageRef) {
23
+ return `${groupId}:${keyPackageRef}`;
24
+ }
25
+ function invalid(message, reason) {
26
+ return new MarmotError('invalid-options', `expectWelcome: ${message}`, { details: { reason } });
27
+ }
28
+ /** Validates an `expectWelcome` argument (hex ids lower-case, `deadline` after `nowMs`). */
29
+ export function validateManifest(manifest, nowMs) {
30
+ if (typeof manifest !== 'object' || manifest === null)
31
+ throw invalid('manifest must be an object', 'invalid-manifest');
32
+ const { groupId, keyPackageRef, sponsorAccount, deadline } = manifest;
33
+ if (typeof groupId !== 'string' || !HEX.test(groupId))
34
+ throw invalid('manifest.groupId must be a lower-case hex group id', 'invalid-manifest');
35
+ if (typeof keyPackageRef !== 'string' || !HEX.test(keyPackageRef))
36
+ throw invalid('manifest.keyPackageRef must be a lower-case hex KeyPackageRef', 'invalid-manifest');
37
+ if (typeof sponsorAccount !== 'string' || !PUBKEY.test(sponsorAccount))
38
+ throw invalid('manifest.sponsorAccount must be a 64-char lower-case hex pubkey', 'invalid-manifest');
39
+ if (typeof deadline !== 'number' || !Number.isFinite(deadline))
40
+ throw invalid('manifest.deadline must be a finite number (client-clock ms)', 'invalid-manifest');
41
+ if (deadline <= nowMs)
42
+ throw invalid('manifest.deadline has already passed', 'deadline-passed');
43
+ return { groupId, keyPackageRef, sponsorAccount, deadline };
44
+ }
45
+ function malformed(key) {
46
+ return new MarmotError('store-failed', `enrolmentManifests/${key}: malformed record`, { details: { key, malformed: true } });
47
+ }
48
+ export function decodeManifest(key, raw) {
49
+ if (typeof raw !== 'object' || raw === null || Array.isArray(raw))
50
+ throw malformed(key);
51
+ const { v, groupId, keyPackageRef, sponsorAccount, deadline, status, invitationId, recordedAt } = raw;
52
+ if (v !== 1 || typeof groupId !== 'string' || typeof keyPackageRef !== 'string' || typeof sponsorAccount !== 'string' || typeof deadline !== 'number')
53
+ throw malformed(key);
54
+ if (typeof status !== 'string' || !STATUSES.has(status) || (invitationId !== undefined && typeof invitationId !== 'string'))
55
+ throw malformed(key);
56
+ if (manifestKey(groupId, keyPackageRef) !== key)
57
+ throw malformed(key);
58
+ if (recordedAt !== undefined && typeof recordedAt !== 'number')
59
+ throw malformed(key);
60
+ return { v: 1, groupId, keyPackageRef, sponsorAccount, deadline, ...(recordedAt === undefined ? {} : { recordedAt }), status: status, ...(invitationId === undefined ? {} : { invitationId: invitationId }) };
61
+ }
62
+ function encodeManifest(record) {
63
+ return {
64
+ v: 1,
65
+ groupId: record.groupId,
66
+ keyPackageRef: record.keyPackageRef,
67
+ sponsorAccount: record.sponsorAccount,
68
+ deadline: record.deadline,
69
+ ...(record.recordedAt === undefined ? {} : { recordedAt: record.recordedAt }),
70
+ status: record.status,
71
+ ...(record.invitationId === undefined ? {} : { invitationId: record.invitationId }),
72
+ };
73
+ }
74
+ function view(tx) {
75
+ return tx.artifact(MANIFESTS);
76
+ }
77
+ export async function readManifest(tx, groupId, keyPackageRef) {
78
+ const key = manifestKey(groupId, keyPackageRef);
79
+ const raw = await view(tx).get(key);
80
+ return raw === undefined ? undefined : decodeManifest(key, raw);
81
+ }
82
+ export async function writeManifest(tx, record) {
83
+ await view(tx).put(manifestKey(record.groupId, record.keyPackageRef), encodeManifest(record));
84
+ }
85
+ /**
86
+ * Records `manifest` as `waiting`. A manifest for the same (group,
87
+ * KeyPackageRef) that is still waiting is replaced (a new deadline or
88
+ * sponsor); a fulfilled one is kept — that Welcome is already joined.
89
+ */
90
+ export async function recordManifest(tx, manifest) {
91
+ const current = await readManifest(tx, manifest.groupId, manifest.keyPackageRef);
92
+ if (current?.status === 'fulfilled')
93
+ return current;
94
+ const record = { v: 1, ...manifest, status: 'waiting' };
95
+ await writeManifest(tx, record);
96
+ return record;
97
+ }
98
+ /**
99
+ * Starting a forget of the own device: every WAITING manifest loses its `recordedAt`, so the Welcome of a request made
100
+ * before the forget can never end it (it is not an answer to a decision made after the forget), whatever the clock says.
101
+ * Rows are read loosely; one that does not read is left as it is.
102
+ */
103
+ export async function stripWaitingRequestTimes(tx) {
104
+ const v = view(tx);
105
+ for (const key of await v.keys()) {
106
+ const raw = (await v.get(key));
107
+ if (typeof raw !== 'object' || raw === null || Array.isArray(raw))
108
+ continue;
109
+ const { recordedAt, ...rest } = raw;
110
+ if (recordedAt !== undefined && rest.status === 'waiting')
111
+ await v.put(key, rest);
112
+ }
113
+ }
114
+ /** S9 teardown: the KeyPackageRefs of every manifest of `groupId` (keys are `<groupId>:<ref>`). */
115
+ export async function manifestRefsOfGroup(tx, groupId) {
116
+ const prefix = `${groupId}:`;
117
+ return (await view(tx).keys()).filter((k) => k.startsWith(prefix)).map((k) => k.slice(prefix.length));
118
+ }
119
+ /** S9 teardown: deletes every manifest of `groupId`. */
120
+ export async function purgeGroupManifests(tx, groupId) {
121
+ const prefix = `${groupId}:`;
122
+ for (const key of await view(tx).keys())
123
+ if (key.startsWith(prefix))
124
+ await view(tx).delete(key);
125
+ }
126
+ /**
127
+ * AC-WEL-1: `accept` only for a waiting manifest whose sponsor equals the
128
+ * Welcome's sponsor, processed before its deadline; `expired` when the
129
+ * deadline has passed (the caller marks it); `mismatch` when the sponsor
130
+ * differs; `none` without a waiting manifest.
131
+ */
132
+ export function matchManifest(manifest, candidate, nowMs) {
133
+ if (manifest === undefined || manifest.status !== 'waiting')
134
+ return 'none';
135
+ if (nowMs >= manifest.deadline)
136
+ return 'expired';
137
+ return manifest.sponsorAccount === candidate.sponsorAccount ? 'accept' : 'mismatch';
138
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * `invitations` module barrel (S5 inviter side; S6 the invitee side).
3
+ * The in-repo seam `client` imports through (architecture.md
4
+ * dependencies_allowed); the public types are re-exported from the package
5
+ * root by `client/index.ts`.
6
+ */
7
+ export { addProposalsFor, buildWelcomeRumors, cleanupCandidateExists, cleanupCandidateOf, createInvitationsService, declineCandidatePage, DEFAULT_INVITE_RETENTION_MS, STAGED_ADD_LOOKUP_TIMEOUT_MS, hasStagedAdds, stagedAddLeafKeys, purgeGroupInvites, recipientsOfWelcome, stagedAddRecipients, decodeStoredWelcomes, encodeStoredWelcomes, toWelcomeOutcome, validateInvitees, WELCOME_COMMIT_TAG, welcomeCommitTagOf, type InvitationsDeps, type InvitationsService, type Invitee, type StoredWelcome, type WelcomeRecipient, type WelcomeOutcome, } from './invite.js';
8
+ export { decideProposal, defaultDecision, type PendingProposal, type ProposalCallback, type ProposalDecision } from './on-proposal.js';
9
+ export { isAuthorisedCommitter, mustQueue, nextQueueStep, queueBarrier, resolveProposals, stagedProposals, withoutProposals, type ProposalResolution, type QueueStep, type StagedProposals, } from './pending-proposal-policy.js';
10
+ export { DEFAULT_PROPOSAL_DEFERRAL_TIMEOUT_MS, DEFERRED_PROPOSALS_EXTENSION, deferralExpired, deleteDeferral, deleteExclusionEpochs, EXCLUDED_PROPOSALS_EXTENSION, exclusionsAt, planDeferrals, readExclusions, writeExclusion, writeExclusionSnapshot, type ExclusionRecord, type Exclusions, readDeferrals, writeDeferral, type DeferralPlan, type DeferralRecord, } from './proposal-deadline.js';
11
+ export { resolveInboxRelays, type InboxRelayDeps, type InboxRelayResolution } from './relay-planes.js';
12
+ export { carriesBranch, decideCompetingWelcome, judgeCompetingWelcome, otherLeafSignatureKeysOf, terminalClassOf, type CompetingBranch, type CompetingDecision, type CompetingGate, type CompetingVerdict, type CompetingWelcomePorts, type HeldBranch, type HeldScore, type KeepReason, type MissingEvidence, type RebaseRequest, type SwitchState, } from './competing-welcome.js';
13
+ export { createWelcomeService, decodeInvitation, decodeWelcomeRumor, encodeInvitation, purgeGroupInvitations, welcomeIdOf, type InvitationRecord, type InvitationStatus, type JoinEvidenceOfWelcome, type MaintenanceKind, MAX_MAINTENANCE_FAILURES, type PendingInvitation, type WelcomeService, type WelcomeServiceDeps, } from './welcome-processor.js';
14
+ export { classifyInvitationOutcome, groupInvitationRecords, indexEntryView, INVITATION_STATUSES, isMalformedRowError, legacyIndexHolds, outcomeReadsGroupStamps, stampAdoptions, stampsFor, stampsOf, type AdoptionProof, type AdoptionProofs, type AdoptionStamp, type IndexEntryView, type InvitationOutcome, type OutcomeSnapshot, } from './invitation-outcome.js';
15
+ export { manifestKey, manifestRefsOfGroup, matchManifest, purgeGroupManifests, recordManifest, stripWaitingRequestTimes, validateManifest, type ManifestMatch, type ManifestRecord, type ManifestStatus, type WelcomeManifestInput } from './expect-welcome.js';
16
+ export { addAnchorsOf, candidateIdOf, decodeCleanupReference, DECLINE_EVIDENCE_EXTENSION, DECLINE_SCAN_PAGE_MAX, declineScanOptions, DELIVERY_EVIDENCE_EXTENSION, encodeCleanupReference, findDeclineCandidate, matchCandidates, type AddAnchor, type CleanupReference, type DeclineCandidate, type DeclineCandidatePage, type DeclineEvidence, type DeliveryEvidence, } from './delivery-evidence.js';
17
+ export { attemptDeclineDelivery, buildDeclineRumor, type DeclineDeliveryDeps, type DeclineState, type DeclineStatus } from './decline.js';
18
+ export { handleKeyPackageOffer, listKeyPackageOffers, OFFERS_EXTENSION, purgeGroupOffers, sendKeyPackageOffer, validateOfferOptions, type KeyPackageOffer, type OfferDeps, } from './offers.js';
@@ -0,0 +1,18 @@
1
+ /**
2
+ * `invitations` module barrel (S5 inviter side; S6 the invitee side).
3
+ * The in-repo seam `client` imports through (architecture.md
4
+ * dependencies_allowed); the public types are re-exported from the package
5
+ * root by `client/index.ts`.
6
+ */
7
+ export { addProposalsFor, buildWelcomeRumors, cleanupCandidateExists, cleanupCandidateOf, createInvitationsService, declineCandidatePage, DEFAULT_INVITE_RETENTION_MS, STAGED_ADD_LOOKUP_TIMEOUT_MS, hasStagedAdds, stagedAddLeafKeys, purgeGroupInvites, recipientsOfWelcome, stagedAddRecipients, decodeStoredWelcomes, encodeStoredWelcomes, toWelcomeOutcome, validateInvitees, WELCOME_COMMIT_TAG, welcomeCommitTagOf, } from './invite.js';
8
+ export { decideProposal, defaultDecision } from './on-proposal.js';
9
+ export { isAuthorisedCommitter, mustQueue, nextQueueStep, queueBarrier, resolveProposals, stagedProposals, withoutProposals, } from './pending-proposal-policy.js';
10
+ export { DEFAULT_PROPOSAL_DEFERRAL_TIMEOUT_MS, DEFERRED_PROPOSALS_EXTENSION, deferralExpired, deleteDeferral, deleteExclusionEpochs, EXCLUDED_PROPOSALS_EXTENSION, exclusionsAt, planDeferrals, readExclusions, writeExclusion, writeExclusionSnapshot, readDeferrals, writeDeferral, } from './proposal-deadline.js';
11
+ export { resolveInboxRelays } from './relay-planes.js';
12
+ export { carriesBranch, decideCompetingWelcome, judgeCompetingWelcome, otherLeafSignatureKeysOf, terminalClassOf, } from './competing-welcome.js';
13
+ export { createWelcomeService, decodeInvitation, decodeWelcomeRumor, encodeInvitation, purgeGroupInvitations, welcomeIdOf, MAX_MAINTENANCE_FAILURES, } from './welcome-processor.js';
14
+ export { classifyInvitationOutcome, groupInvitationRecords, indexEntryView, INVITATION_STATUSES, isMalformedRowError, legacyIndexHolds, outcomeReadsGroupStamps, stampAdoptions, stampsFor, stampsOf, } from './invitation-outcome.js';
15
+ export { manifestKey, manifestRefsOfGroup, matchManifest, purgeGroupManifests, recordManifest, stripWaitingRequestTimes, validateManifest } from './expect-welcome.js';
16
+ export { addAnchorsOf, candidateIdOf, decodeCleanupReference, DECLINE_EVIDENCE_EXTENSION, DECLINE_SCAN_PAGE_MAX, declineScanOptions, DELIVERY_EVIDENCE_EXTENSION, encodeCleanupReference, findDeclineCandidate, matchCandidates, } from './delivery-evidence.js';
17
+ export { attemptDeclineDelivery, buildDeclineRumor } from './decline.js';
18
+ export { handleKeyPackageOffer, listKeyPackageOffers, OFFERS_EXTENSION, purgeGroupOffers, sendKeyPackageOffer, validateOfferOptions, } from './offers.js';
@@ -0,0 +1,110 @@
1
+ import type { AccountStoreTx } from '../storage/index.js';
2
+ import { type InvitationRecord } from './welcome-processor.js';
3
+ /**
4
+ * The account record's durable stamp that the invitation caused adoption (`InvitationRecord.adoption`). `via`: an
5
+ * ordinary join, or a competing Welcome's branch switch. `source`: the group proof the stamp was taken from (or the
6
+ * normal completion of the adoption itself), or the pre-upgrade index entry's `adoptedBy` (rule 3). `at`: client
7
+ * clock ms.
8
+ */
9
+ export type AdoptionStamp = {
10
+ readonly via: 'join' | 'switch';
11
+ readonly source: 'group-proof' | 'legacy-index';
12
+ readonly at: number;
13
+ };
14
+ /** What `invitations.outcome(id)` reports (architecture SC-7). */
15
+ export type InvitationOutcome = {
16
+ readonly status: 'pending';
17
+ }
18
+ /** `accept(id)` resumes it. */
19
+ | {
20
+ readonly status: 'joining';
21
+ readonly groupId?: string;
22
+ }
23
+ /** A competing Welcome held open, or a join deferred by a restore of its group. */
24
+ | {
25
+ readonly status: 'unresolved';
26
+ readonly groupId: string;
27
+ } | {
28
+ readonly status: 'joined';
29
+ readonly groupId: string;
30
+ readonly via: 'adoption' | 'switch';
31
+ } | {
32
+ readonly status: 'not-joined';
33
+ readonly reason: 'declined' | 'rejected' | 'kept-out';
34
+ readonly detail?: string;
35
+ readonly groupId?: string;
36
+ } | {
37
+ readonly status: 'unknown';
38
+ } | {
39
+ readonly status: 'indeterminate';
40
+ readonly groupId?: string;
41
+ };
42
+ /** One `marmot.adoption` row: the invitation whose Welcome's group transaction wrote the adopted state. */
43
+ export interface AdoptionProof {
44
+ readonly via: 'join';
45
+ /** Hex confirmation tag of the adopted state. */
46
+ readonly tag: string;
47
+ /** Client clock ms of the adoption (the Welcome's arrival). */
48
+ readonly at: number;
49
+ }
50
+ /** The group's adoption proofs, as `client/adoption-proof.ts` `readAdoptionProofs` reads them. */
51
+ export interface AdoptionProofs {
52
+ readonly adoption: ReadonlyMap<string, AdoptionProof>;
53
+ /** Invitation ids whose switch transaction committed (`marmot.branchSwitch`). */
54
+ readonly branchSwitch: ReadonlySet<string>;
55
+ }
56
+ /** The part of the account group index entry (`marmot.groups`) the classification reads. */
57
+ export interface IndexEntryView {
58
+ readonly createdAt: number;
59
+ readonly adoptedBy?: string;
60
+ }
61
+ /** The durable state one classification reads, at one instant (SC-7, SC-8). */
62
+ export interface OutcomeSnapshot {
63
+ readonly record: InvitationRecord | undefined;
64
+ /** `'no-group'`: the record names no group, or the classification runs after the group store was cleared (A2). */
65
+ readonly groupProofs: AdoptionProofs | 'no-group';
66
+ readonly indexEntry: IndexEntryView | undefined;
67
+ /** The stamps of ALL account records of the record's group (own included). */
68
+ readonly groupStamps: ReadonlyMap<string, AdoptionStamp>;
69
+ }
70
+ /** Every stored invitation status, for the exhaustiveness check of the classification (adding one fails its test). */
71
+ export declare const INVITATION_STATUSES: readonly ["pending", "joining", "joined", "declined", "rejected", "competing"];
72
+ /** The classification's view of a stored index entry; throws `store-failed` (`malformed`) on a corrupt one. */
73
+ export declare function indexEntryView(groupId: string, raw: unknown): IndexEntryView | undefined;
74
+ /**
75
+ * Rule 3 (SC-7), per invitation: the pre-upgrade index entry names `id` as its adopter, the group holds no join
76
+ * adoption proof, and no OTHER record of the group carries a join stamp taken from a group proof. Switch proofs and
77
+ * switch stamps of other invitations never suppress it (ADR-019 D7).
78
+ */
79
+ export declare function legacyIndexHolds(snapshot: OutcomeSnapshot, id: string): boolean;
80
+ /**
81
+ * Whether classifying `snapshot` reads `groupStamps` — the stamps of the group's OTHER records, which only rule 3's
82
+ * sibling check consults. False when the record is absent, an exact proof (row 1) or its status decides the row before
83
+ * rule 3, or rule 3 already fails without the siblings: `groupStamps` then cannot change the result, so a reader may
84
+ * skip the account-wide scan that collects them.
85
+ */
86
+ export declare function outcomeReadsGroupStamps(snapshot: Omit<OutcomeSnapshot, 'groupStamps'>): boolean;
87
+ /** First matching row of the SC-7 status table. Total over every `InvitationStatus` and the absent record. */
88
+ export declare function classifyInvitationOutcome(snapshot: OutcomeSnapshot): InvitationOutcome;
89
+ /**
90
+ * The stamps teardown must add for one group (constraint 11): exactly the records the classification reads `joined`
91
+ * through a group proof (row 1, not already stamped) or rule 3 (row 5), each evaluated on its own. `records` are the
92
+ * group's account records; `nowMs` dates a switch stamp (a switch proof carries no time).
93
+ */
94
+ export declare function stampsFor(records: readonly InvitationRecord[], groupProofs: AdoptionProofs | 'no-group', indexEntry: IndexEntryView | undefined, nowMs: number): Map<string, AdoptionStamp>;
95
+ export { isMalformedRowError } from '../shared/index.js';
96
+ /**
97
+ * Every decodable account invitation record naming `groupId`. A record that does not decode — its payload or its
98
+ * envelope — carries no evidence (no stamp can be trusted from it, nor can it be stamped): it is skipped, so it never blocks a teardown or another
99
+ * invitation's read. The record an outcome read is ABOUT is decoded strictly by the reader itself (row 12).
100
+ */
101
+ export declare function groupInvitationRecords(tx: Pick<AccountStoreTx, 'artifact'>, groupId: string): Promise<InvitationRecord[]>;
102
+ /** The stamps of every account record of `groupId` (the classification's `groupStamps`). */
103
+ export declare function stampsOf(records: readonly InvitationRecord[]): Map<string, AdoptionStamp>;
104
+ /**
105
+ * Teardown's classifier-preserving stamping (ADR-019 D8; G6a): inside `tx`, stamps every record of `groupId` that
106
+ * the classification reads `joined` at this instant through a group proof or rule 3 and is not stamped yet. A1 (the
107
+ * watermark transaction, before the clear) passes the proofs the purge read; A2 (the purge transaction, before the
108
+ * index delete and the record purge) passes `'no-group'`. Idempotent. Returns the ids it stamped.
109
+ */
110
+ export declare function stampAdoptions(tx: Pick<AccountStoreTx, 'artifact'>, groupId: string, proofs: AdoptionProofs | 'no-group', indexEntry: IndexEntryView | undefined, nowMs: number): Promise<string[]>;
@@ -0,0 +1,210 @@
1
+ /**
2
+ * Invitation outcomes (epic marmot-invitation-outcomes S2; ADR-019 D7, D8; architecture SC-7).
3
+ *
4
+ * Whether THIS exact Welcome caused the local adoption of its group is answered from durable evidence only:
5
+ *
6
+ * - the group's adoption proofs (`client/adoption-proof.ts`): `marmot.adoption[invitationId]`, written in the
7
+ * adoption's own group transaction, and `marmot.branchSwitch[invitationId]`, written in a competing Welcome's
8
+ * switch transaction;
9
+ * - the invitation record's {@link AdoptionStamp} (`InvitationRecord.adoption`), written when the adoption completes
10
+ * normally and by teardown ({@link stampAdoptions}) before the group store (A1) and the index entry (A2) go;
11
+ * - for a record written before any of these existed: the account group index entry's `adoptedBy` (rule 3,
12
+ * {@link legacyIndexHolds}), evaluated per invitation.
13
+ *
14
+ * The functional core here is pure ({@link classifyInvitationOutcome}, {@link legacyIndexHolds}, {@link stampsFor});
15
+ * {@link stampAdoptions} is the one stamping shell, used by both teardown phases (constraint 11).
16
+ */
17
+ import { isMalformedRowError, MarmotError } from '../shared/index.js';
18
+ import { decodeInvitation, encodeInvitation } from './welcome-processor.js';
19
+ /** Every stored invitation status, for the exhaustiveness check of the classification (adding one fails its test). */
20
+ export const INVITATION_STATUSES = ['pending', 'joining', 'joined', 'declined', 'rejected', 'competing'];
21
+ // ---------------------------------------------------------------------------
22
+ // Codecs (the stamp itself is part of the record codec: `welcome-processor.ts`)
23
+ // ---------------------------------------------------------------------------
24
+ /** The classification's view of a stored index entry; throws `store-failed` (`malformed`) on a corrupt one. */
25
+ export function indexEntryView(groupId, raw) {
26
+ if (raw === undefined)
27
+ return undefined;
28
+ if (typeof raw !== 'object' || raw === null || Array.isArray(raw) || typeof raw.createdAt !== 'number') {
29
+ throw new MarmotError('store-failed', `group index: malformed entry for ${groupId}`, { details: { groupId, malformed: true } });
30
+ }
31
+ const adoptedBy = raw.adoptedBy;
32
+ return { createdAt: raw.createdAt, ...(typeof adoptedBy === 'string' ? { adoptedBy } : {}) };
33
+ }
34
+ // ---------------------------------------------------------------------------
35
+ // The functional core
36
+ // ---------------------------------------------------------------------------
37
+ function isGroupJoinStamp(stamp) {
38
+ return stamp.via === 'join' && stamp.source === 'group-proof';
39
+ }
40
+ /**
41
+ * Rule 3 (SC-7), per invitation: the pre-upgrade index entry names `id` as its adopter, the group holds no join
42
+ * adoption proof, and no OTHER record of the group carries a join stamp taken from a group proof. Switch proofs and
43
+ * switch stamps of other invitations never suppress it (ADR-019 D7).
44
+ */
45
+ export function legacyIndexHolds(snapshot, id) {
46
+ if (!legacyIndexCandidate(snapshot, id))
47
+ return false;
48
+ for (const [other, stamp] of snapshot.groupStamps)
49
+ if (other !== id && isGroupJoinStamp(stamp))
50
+ return false;
51
+ return true;
52
+ }
53
+ /** Rule 3's part that needs no other record: the index names `id` and the group holds no join adoption proof. */
54
+ function legacyIndexCandidate(snapshot, id) {
55
+ if (snapshot.indexEntry?.adoptedBy !== id)
56
+ return false;
57
+ return snapshot.groupProofs === 'no-group' || snapshot.groupProofs.adoption.size === 0;
58
+ }
59
+ /**
60
+ * Whether classifying `snapshot` reads `groupStamps` — the stamps of the group's OTHER records, which only rule 3's
61
+ * sibling check consults. False when the record is absent, an exact proof (row 1) or its status decides the row before
62
+ * rule 3, or rule 3 already fails without the siblings: `groupStamps` then cannot change the result, so a reader may
63
+ * skip the account-wide scan that collects them.
64
+ */
65
+ export function outcomeReadsGroupStamps(snapshot) {
66
+ const record = snapshot.record;
67
+ if (record === undefined || exactProof(snapshot, record) !== undefined)
68
+ return false;
69
+ const reachesRule3 = record.status === 'joining' || (record.status === 'joined' && record.reason === undefined);
70
+ return reachesRule3 && legacyIndexCandidate(snapshot, record.id);
71
+ }
72
+ /** The exact proof of `record` (row 1), if any. */
73
+ function exactProof(snapshot, record) {
74
+ if (record.adoption !== undefined)
75
+ return record.adoption.via === 'join' ? 'adoption' : 'switch';
76
+ if (snapshot.groupProofs === 'no-group')
77
+ return undefined;
78
+ if (snapshot.groupProofs.adoption.has(record.id))
79
+ return 'adoption';
80
+ if (snapshot.groupProofs.branchSwitch.has(record.id))
81
+ return 'switch';
82
+ return undefined;
83
+ }
84
+ /** First matching row of the SC-7 status table. Total over every `InvitationStatus` and the absent record. */
85
+ export function classifyInvitationOutcome(snapshot) {
86
+ const record = snapshot.record;
87
+ // Row 11.
88
+ if (record === undefined)
89
+ return { status: 'unknown' };
90
+ const groupId = record.groupId ?? '';
91
+ const withGroup = record.groupId === undefined ? {} : { groupId: record.groupId };
92
+ // Row 1.
93
+ const exact = exactProof(snapshot, record);
94
+ if (exact !== undefined)
95
+ return { status: 'joined', groupId, via: exact };
96
+ switch (record.status) {
97
+ case 'declined':
98
+ return { status: 'not-joined', reason: 'declined' }; // Row 2.
99
+ case 'rejected':
100
+ return { status: 'not-joined', reason: 'rejected', ...(record.reason === undefined ? {} : { detail: record.reason }) }; // Row 3.
101
+ case 'joined':
102
+ if (record.reason !== undefined)
103
+ return { status: 'not-joined', reason: 'kept-out', detail: record.reason, ...withGroup }; // Row 4.
104
+ if (legacyIndexHolds(snapshot, record.id))
105
+ return { status: 'joined', groupId, via: 'adoption' }; // Row 5.
106
+ return { status: 'indeterminate', ...withGroup }; // Row 6.
107
+ case 'joining':
108
+ if (legacyIndexHolds(snapshot, record.id))
109
+ return { status: 'joined', groupId, via: 'adoption' }; // Row 5.
110
+ if (record.deferred === 'restore-in-flight')
111
+ return { status: 'unresolved', groupId }; // Row 7.
112
+ return { status: 'joining', ...withGroup }; // Row 8.
113
+ case 'competing':
114
+ return { status: 'unresolved', groupId }; // Row 9.
115
+ case 'pending':
116
+ return { status: 'pending' }; // Row 10.
117
+ }
118
+ }
119
+ /**
120
+ * The stamps teardown must add for one group (constraint 11): exactly the records the classification reads `joined`
121
+ * through a group proof (row 1, not already stamped) or rule 3 (row 5), each evaluated on its own. `records` are the
122
+ * group's account records; `nowMs` dates a switch stamp (a switch proof carries no time).
123
+ */
124
+ export function stampsFor(records, groupProofs, indexEntry, nowMs) {
125
+ const groupStamps = new Map();
126
+ for (const r of records)
127
+ if (r.adoption !== undefined)
128
+ groupStamps.set(r.id, r.adoption);
129
+ const out = new Map();
130
+ for (const record of records) {
131
+ if (record.adoption !== undefined)
132
+ continue;
133
+ const snapshot = { record, groupProofs, indexEntry, groupStamps };
134
+ if (classifyInvitationOutcome(snapshot).status !== 'joined')
135
+ continue;
136
+ if (groupProofs !== 'no-group' && groupProofs.adoption.has(record.id)) {
137
+ out.set(record.id, { via: 'join', source: 'group-proof', at: groupProofs.adoption.get(record.id).at });
138
+ }
139
+ else if (groupProofs !== 'no-group' && groupProofs.branchSwitch.has(record.id)) {
140
+ out.set(record.id, { via: 'switch', source: 'group-proof', at: nowMs });
141
+ }
142
+ else {
143
+ out.set(record.id, { via: 'join', source: 'legacy-index', at: indexEntry?.createdAt ?? nowMs });
144
+ }
145
+ }
146
+ return out;
147
+ }
148
+ // ---------------------------------------------------------------------------
149
+ // The stamping shell (teardown A1 and A2)
150
+ // ---------------------------------------------------------------------------
151
+ // `isMalformedRowError` lives in shared/errors.ts (re-exported here for existing importers): it inspects error codes
152
+ // only, and keeping it out of this module avoids a welcome-processor <-> invitation-outcome import cycle.
153
+ export { isMalformedRowError } from '../shared/index.js';
154
+ /**
155
+ * Every decodable account invitation record naming `groupId`. A record that does not decode — its payload or its
156
+ * envelope — carries no evidence (no stamp can be trusted from it, nor can it be stamped): it is skipped, so it never blocks a teardown or another
157
+ * invitation's read. The record an outcome read is ABOUT is decoded strictly by the reader itself (row 12).
158
+ */
159
+ export async function groupInvitationRecords(tx, groupId) {
160
+ const view = tx.artifact('pendingInvitations');
161
+ const out = [];
162
+ for (const key of await view.keys()) {
163
+ let raw;
164
+ try {
165
+ raw = (await view.get(key));
166
+ }
167
+ catch (error) {
168
+ // A row whose envelope does not open names no group we could trust: skipped like an undecodable record.
169
+ if (isMalformedRowError(error))
170
+ continue;
171
+ throw error;
172
+ }
173
+ if (typeof raw !== 'object' || raw === null || raw.groupId !== groupId)
174
+ continue;
175
+ let record;
176
+ try {
177
+ record = decodeInvitation(key, raw);
178
+ }
179
+ catch {
180
+ continue;
181
+ }
182
+ out.push(record);
183
+ }
184
+ return out;
185
+ }
186
+ /** The stamps of every account record of `groupId` (the classification's `groupStamps`). */
187
+ export function stampsOf(records) {
188
+ const out = new Map();
189
+ for (const r of records)
190
+ if (r.adoption !== undefined)
191
+ out.set(r.id, r.adoption);
192
+ return out;
193
+ }
194
+ /**
195
+ * Teardown's classifier-preserving stamping (ADR-019 D8; G6a): inside `tx`, stamps every record of `groupId` that
196
+ * the classification reads `joined` at this instant through a group proof or rule 3 and is not stamped yet. A1 (the
197
+ * watermark transaction, before the clear) passes the proofs the purge read; A2 (the purge transaction, before the
198
+ * index delete and the record purge) passes `'no-group'`. Idempotent. Returns the ids it stamped.
199
+ */
200
+ export async function stampAdoptions(tx, groupId, proofs, indexEntry, nowMs) {
201
+ const records = await groupInvitationRecords(tx, groupId);
202
+ const stamps = stampsFor(records, proofs, indexEntry, nowMs);
203
+ const view = tx.artifact('pendingInvitations');
204
+ for (const record of records) {
205
+ const stamp = stamps.get(record.id);
206
+ if (stamp !== undefined)
207
+ await view.put(record.id, encodeInvitation({ ...record, adoption: stamp }));
208
+ }
209
+ return [...stamps.keys()];
210
+ }