@cello-protocol/protocol-types 0.0.54 → 0.0.56

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 (48) hide show
  1. package/dist/document-amendment.d.ts +27 -22
  2. package/dist/document-amendment.d.ts.map +1 -1
  3. package/dist/document-amendment.js +63 -181
  4. package/dist/document-amendment.js.map +1 -1
  5. package/dist/document-derive.d.ts +96 -0
  6. package/dist/document-derive.d.ts.map +1 -0
  7. package/dist/document-derive.js +605 -0
  8. package/dist/document-derive.js.map +1 -0
  9. package/dist/document-envelope.d.ts +18 -8
  10. package/dist/document-envelope.d.ts.map +1 -1
  11. package/dist/document-envelope.js +35 -19
  12. package/dist/document-envelope.js.map +1 -1
  13. package/dist/document-governance.d.ts +1 -1
  14. package/dist/document-governance.d.ts.map +1 -1
  15. package/dist/document-governance.js +41 -6
  16. package/dist/document-governance.js.map +1 -1
  17. package/dist/document-proposal.d.ts +6 -0
  18. package/dist/document-proposal.d.ts.map +1 -1
  19. package/dist/document-proposal.js +21 -0
  20. package/dist/document-proposal.js.map +1 -1
  21. package/dist/document-reconcile.d.ts +100 -0
  22. package/dist/document-reconcile.d.ts.map +1 -0
  23. package/dist/document-reconcile.js +197 -0
  24. package/dist/document-reconcile.js.map +1 -0
  25. package/dist/index.d.ts +10 -12
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +6 -6
  28. package/dist/index.js.map +1 -1
  29. package/dist/session.d.ts +18 -0
  30. package/dist/session.d.ts.map +1 -1
  31. package/dist/session.js.map +1 -1
  32. package/package.json +2 -2
  33. package/dist/document-ack.d.ts +0 -111
  34. package/dist/document-ack.d.ts.map +0 -1
  35. package/dist/document-ack.js +0 -228
  36. package/dist/document-ack.js.map +0 -1
  37. package/dist/document-control.d.ts +0 -74
  38. package/dist/document-control.d.ts.map +0 -1
  39. package/dist/document-control.js +0 -174
  40. package/dist/document-control.js.map +0 -1
  41. package/dist/document-join-answer.d.ts +0 -34
  42. package/dist/document-join-answer.d.ts.map +0 -1
  43. package/dist/document-join-answer.js +0 -100
  44. package/dist/document-join-answer.js.map +0 -1
  45. package/dist/document-join.d.ts +0 -83
  46. package/dist/document-join.d.ts.map +0 -1
  47. package/dist/document-join.js +0 -225
  48. package/dist/document-join.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"document-join-answer.js","sourceRoot":"","sources":["../src/document-join-answer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEnD,sDAAsD;AACtD,MAAM,CAAC,MAAM,2BAA2B,GAAG,+BAA+B,CAAC;AAE3E,MAAM,CAAC,MAAM,8BAA8B,GAAG,GAAG,CAAC;AAgBlD,MAAM,UAAU,0BAA0B,CACxC,MAA0B,EAC1B,OAA8B,EAAE;IAEhC,MAAM,QAAQ,GAAG,UAAU,CAAC;QAC1B,2BAA2B;QAC3B,MAAM,CAAC,WAAW;QAClB,MAAM,CAAC,cAAc;QACrB,MAAM,CAAC,gBAAgB;QACvB,MAAM,CAAC,QAAQ;QACf,MAAM,CAAC,cAAc;QACrB,OAAO,MAAM,CAAC,cAAc,KAAK,QAAQ,IAAI,MAAM,CAAC,cAAc,GAAG,UAAU;YAC7E,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC;YAC/B,CAAC,CAAC,MAAM,CAAC,cAAc;KAC1B,CAAC,CAAC;IACH,IAAI,IAAI,CAAC,OAAO,KAAK,KAAK;QAAE,OAAO,QAAQ,CAAC;IAC5C,OAAO,IAAI,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,MAA0B;IACjE,OAAO,UAAU,CAAC;QAChB,IAAI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,gBAAgB,CAAC;QAC1C,gBAAgB,EAAE,GAAG,CAAC,GAAG,EAAE,kBAAkB,CAAC;QAC9C,QAAQ;QACR,cAAc,EAAE,MAAM;QACtB,cAAc,EAAE,UAAU;QAC1B,SAAS,EAAE,IAAI,UAAU,CAAC,SAAS,CAAC;KACrC,CAAC;AACJ,CAAC"}
@@ -1,83 +0,0 @@
1
- /**
2
- * DOD-MP-JOIN-1 — the join offer: how a third party enters an existing document.
3
- *
4
- * The offer is a courier, not an authority. It carries the RECEIVED BYTES of the genesis
5
- * proposal, the full amendment chain (the pending `add_holder` last), and the envelope-log
6
- * snapshot — and the invitee's daemon DERIVES the arrangement from those bytes through the same
7
- * replay every holder runs. The invitee consents to what they computed, never to what they were
8
- * told: an offer whose chain does not replay admits nobody, whatever its prose.
9
- *
10
- * ── WHY THE SIGNATURE BINDS EVERY CARRIED BYTE ────────────────────────────────────────────────
11
- *
12
- * The TBS commits to the hash of the genesis bytes, of each amendment, and of each log envelope.
13
- * Each carried payload is ALSO independently verifiable (the genesis by its proposer's
14
- * signature, each amendment by its collection, each envelope by its sender) — the offer-level
15
- * binding exists so the inviter cannot assemble a misleading BUNDLE out of individually-valid
16
- * pieces and later disown the assembly. Who showed the invitee what is on the record.
17
- *
18
- * ── NEITHER ALONE ADMITS ANYONE ───────────────────────────────────────────────────────────────
19
- *
20
- * A valid offer makes a join POSSIBLE; the invitee's signed accept makes it REAL (the daemon
21
- * unit wires that consent through the settle-once ack pattern). This module rules only on the
22
- * offer's validity — GOVERN-1's dispositioned consent clause lands in the daemon receive path.
23
- */
24
- import { type DocumentProposalEnvelope } from "./document-proposal.js";
25
- import { type Arrangement, type ArrangementGenesis, type DocumentAmendmentEnvelope, type SignerPolicy } from "./document-amendment.js";
26
- /** Domain tag in slot 0 of the to-be-signed array. Sibling of the other CELLO-DOCUMENT-* tags. */
27
- export declare const DOCUMENT_JOIN_OFFER_DOMAIN = "CELLO-DOCUMENT-JOIN-OFFER-v1";
28
- export interface DocumentJoinOffer {
29
- type: "document_join_offer";
30
- feature_version: number;
31
- /** The admin authoring this offer — must be a claimed signer of the pending amendment. */
32
- inviter_agent_id: string;
33
- invitee_agent_id: string;
34
- document_id: string;
35
- /** The genesis proposal AS RECEIVED — the invitee re-derives `document_id` from these bytes. */
36
- genesis: Uint8Array;
37
- /** The full amendment chain as received bytes, ordered, the pending `add_holder` LAST. */
38
- amendments: Uint8Array[];
39
- /** The update-envelope log snapshot (D1's cheap path) — may be empty for a young document. */
40
- envelope_log: Uint8Array[];
41
- offered_at_ms: number;
42
- /** Ed25519 (RFC 8032) by the inviter over `buildDocumentJoinOfferTbs`. */
43
- signature: Uint8Array;
44
- }
45
- /**
46
- * The canonical to-be-signed preimage. Payloads enter as HASHES (arrays of 32-byte digests are
47
- * deterministic CBOR — the multisig precedent), so the signature binds every carried byte
48
- * without re-encoding megabytes into the preimage.
49
- */
50
- export declare function buildDocumentJoinOfferTbs(offer: DocumentJoinOffer, opts?: {
51
- preHash?: boolean;
52
- }): Uint8Array;
53
- export declare function encodeDocumentJoinOffer(offer: DocumentJoinOffer): Uint8Array;
54
- export declare function decodeDocumentJoinOffer(input: Uint8Array): DocumentJoinOffer;
55
- /**
56
- * The replay's starting facts, computed from a decoded genesis proposal — ONE implementation for
57
- * every consumer (join validation, the daemon's amendment receive and accept paths), because two
58
- * copies of the everyone-admin default is how two holders derive different arrangements from one
59
- * genesis. Absent `admin_set` means both genesis participants govern (the bilateral default);
60
- * `admin_set` itself lives on the ARRANGEMENT, not in the scalar properties bag the replay
61
- * derives `change_property` against.
62
- */
63
- export declare function arrangementGenesisFromProposal(genesis: DocumentProposalEnvelope): ArrangementGenesis;
64
- export type JoinOfferValidation = {
65
- ok: true;
66
- /** Derived by REPLAY of the carried bytes — the consent surface, computed not trusted. */
67
- arrangement: Arrangement;
68
- genesis: DocumentProposalEnvelope;
69
- amendments: DocumentAmendmentEnvelope[];
70
- /** Hex hash of the pending `add_holder` — the settle key for the invitee's answer. */
71
- pendingAmendmentHash: string;
72
- } | {
73
- ok: false;
74
- reason: string;
75
- };
76
- /**
77
- * The invitee's ruling on an offer. Order is the disclosure-and-trust boundary: the version
78
- * answer first (a mismatched build must get a sentence, not a failed signature), then the
79
- * inviter's signature (nothing else is worth computing on an unauthenticated bundle), then the
80
- * carried payloads each on their own signatures, then the replay.
81
- */
82
- export declare function validateDocumentJoinOffer(offer: DocumentJoinOffer, policy: SignerPolicy, verify: (agentId: string, tbs: Uint8Array, signature: Uint8Array) => boolean): JoinOfferValidation;
83
- //# sourceMappingURL=document-join.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"document-join.d.ts","sourceRoot":"","sources":["../src/document-join.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAIH,OAAO,EAKL,KAAK,wBAAwB,EAC9B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAGL,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,EAC9B,KAAK,YAAY,EAClB,MAAM,yBAAyB,CAAC;AAEjC,kGAAkG;AAClG,eAAO,MAAM,0BAA0B,iCAAiC,CAAC;AAEzE,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,qBAAqB,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,0FAA0F;IAC1F,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,gGAAgG;IAChG,OAAO,EAAE,UAAU,CAAC;IACpB,0FAA0F;IAC1F,UAAU,EAAE,UAAU,EAAE,CAAC;IACzB,8FAA8F;IAC9F,YAAY,EAAE,UAAU,EAAE,CAAC;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,0EAA0E;IAC1E,SAAS,EAAE,UAAU,CAAC;CACvB;AAMD;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,iBAAiB,EACxB,IAAI,GAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAO,GAC/B,UAAU,CAgBZ;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,iBAAiB,GAAG,UAAU,CAa5E;AAiCD,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,UAAU,GAAG,iBAAiB,CA8B5E;AAED;;;;;;;GAOG;AACH,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,wBAAwB,GAChC,kBAAkB,CAgBpB;AAED,MAAM,MAAM,mBAAmB,GAC3B;IACE,EAAE,EAAE,IAAI,CAAC;IACT,0FAA0F;IAC1F,WAAW,EAAE,WAAW,CAAC;IACzB,OAAO,EAAE,wBAAwB,CAAC;IAClC,UAAU,EAAE,yBAAyB,EAAE,CAAC;IACxC,sFAAsF;IACtF,oBAAoB,EAAE,MAAM,CAAC;CAC9B,GACD;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAMlC;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,iBAAiB,EACxB,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,KAAK,OAAO,GAC3E,mBAAmB,CAyFrB"}
@@ -1,225 +0,0 @@
1
- /**
2
- * DOD-MP-JOIN-1 — the join offer: how a third party enters an existing document.
3
- *
4
- * The offer is a courier, not an authority. It carries the RECEIVED BYTES of the genesis
5
- * proposal, the full amendment chain (the pending `add_holder` last), and the envelope-log
6
- * snapshot — and the invitee's daemon DERIVES the arrangement from those bytes through the same
7
- * replay every holder runs. The invitee consents to what they computed, never to what they were
8
- * told: an offer whose chain does not replay admits nobody, whatever its prose.
9
- *
10
- * ── WHY THE SIGNATURE BINDS EVERY CARRIED BYTE ────────────────────────────────────────────────
11
- *
12
- * The TBS commits to the hash of the genesis bytes, of each amendment, and of each log envelope.
13
- * Each carried payload is ALSO independently verifiable (the genesis by its proposer's
14
- * signature, each amendment by its collection, each envelope by its sender) — the offer-level
15
- * binding exists so the inviter cannot assemble a misleading BUNDLE out of individually-valid
16
- * pieces and later disown the assembly. Who showed the invitee what is on the record.
17
- *
18
- * ── NEITHER ALONE ADMITS ANYONE ───────────────────────────────────────────────────────────────
19
- *
20
- * A valid offer makes a join POSSIBLE; the invitee's signed accept makes it REAL (the daemon
21
- * unit wires that consent through the settle-once ack pattern). This module rules only on the
22
- * offer's validity — GOVERN-1's dispositioned consent clause lands in the daemon receive path.
23
- */
24
- import { createHash } from "node:crypto";
25
- import { encodeCbor, decodeCbor } from "./cbor.js";
26
- import { DOCUMENT_FEATURE_VERSION, decodeDocumentProposal, documentIdFromProposal, buildDocumentProposalTbs, } from "./document-proposal.js";
27
- import { decodeDocumentAmendment, deriveArrangement, } from "./document-amendment.js";
28
- /** Domain tag in slot 0 of the to-be-signed array. Sibling of the other CELLO-DOCUMENT-* tags. */
29
- export const DOCUMENT_JOIN_OFFER_DOMAIN = "CELLO-DOCUMENT-JOIN-OFFER-v1";
30
- function sha256(bytes) {
31
- return new Uint8Array(createHash("sha256").update(bytes).digest());
32
- }
33
- /**
34
- * The canonical to-be-signed preimage. Payloads enter as HASHES (arrays of 32-byte digests are
35
- * deterministic CBOR — the multisig precedent), so the signature binds every carried byte
36
- * without re-encoding megabytes into the preimage.
37
- */
38
- export function buildDocumentJoinOfferTbs(offer, opts = {}) {
39
- const preimage = encodeCbor([
40
- DOCUMENT_JOIN_OFFER_DOMAIN,
41
- offer.feature_version,
42
- offer.inviter_agent_id,
43
- offer.invitee_agent_id,
44
- offer.document_id,
45
- sha256(offer.genesis),
46
- offer.amendments.map(sha256),
47
- offer.envelope_log.map(sha256),
48
- typeof offer.offered_at_ms === "number" && offer.offered_at_ms > 0xffffffff
49
- ? BigInt(offer.offered_at_ms)
50
- : offer.offered_at_ms,
51
- ]);
52
- if (opts.preHash === false)
53
- return preimage;
54
- return sha256(preimage);
55
- }
56
- export function encodeDocumentJoinOffer(offer) {
57
- return encodeCbor({
58
- type: offer.type,
59
- feature_version: offer.feature_version,
60
- inviter_agent_id: offer.inviter_agent_id,
61
- invitee_agent_id: offer.invitee_agent_id,
62
- document_id: offer.document_id,
63
- genesis: offer.genesis,
64
- amendments: offer.amendments,
65
- envelope_log: offer.envelope_log,
66
- offered_at_ms: offer.offered_at_ms,
67
- signature: offer.signature,
68
- });
69
- }
70
- function present(map, field) {
71
- if (!(field in map)) {
72
- throw new Error(`document_join_missing_field: ${field} is mandatory and was not present`);
73
- }
74
- return map[field];
75
- }
76
- function str(map, field) {
77
- const v = present(map, field);
78
- if (typeof v !== "string" || v.length === 0) {
79
- throw new Error(`document_join_field_type: ${field} must be a non-empty text string`);
80
- }
81
- return v;
82
- }
83
- function bytes(map, field) {
84
- const v = present(map, field);
85
- if (!(v instanceof Uint8Array)) {
86
- throw new Error(`document_join_field_type: ${field} must be a CBOR byte string`);
87
- }
88
- return new Uint8Array(v);
89
- }
90
- function byteArray(map, field) {
91
- const v = present(map, field);
92
- if (!Array.isArray(v) || v.some((e) => !(e instanceof Uint8Array))) {
93
- throw new Error(`document_join_field_type: ${field} must be an array of CBOR byte strings`);
94
- }
95
- return v.map((e) => new Uint8Array(e));
96
- }
97
- export function decodeDocumentJoinOffer(input) {
98
- const decoded = decodeCbor(input);
99
- if (typeof decoded !== "object" || decoded === null || Array.isArray(decoded)) {
100
- throw new Error("document_join_malformed: not a CBOR map");
101
- }
102
- const map = decoded;
103
- const type = str(map, "type");
104
- if (type !== "document_join_offer") {
105
- throw new Error(`document_join_type: expected document_join_offer, got ${type}`);
106
- }
107
- const featureVersion = present(map, "feature_version");
108
- if (typeof featureVersion !== "number" || !Number.isInteger(featureVersion) || featureVersion < 1) {
109
- throw new Error("document_join_field_type: feature_version must be a positive integer");
110
- }
111
- const offeredAt = present(map, "offered_at_ms");
112
- if (typeof offeredAt !== "number" || !Number.isInteger(offeredAt)) {
113
- throw new Error("document_join_field_type: offered_at_ms must be an integer");
114
- }
115
- return {
116
- type: "document_join_offer",
117
- feature_version: featureVersion,
118
- inviter_agent_id: str(map, "inviter_agent_id"),
119
- invitee_agent_id: str(map, "invitee_agent_id"),
120
- document_id: str(map, "document_id"),
121
- genesis: bytes(map, "genesis"),
122
- amendments: byteArray(map, "amendments"),
123
- envelope_log: byteArray(map, "envelope_log"),
124
- offered_at_ms: offeredAt,
125
- signature: bytes(map, "signature"),
126
- };
127
- }
128
- /**
129
- * The replay's starting facts, computed from a decoded genesis proposal — ONE implementation for
130
- * every consumer (join validation, the daemon's amendment receive and accept paths), because two
131
- * copies of the everyone-admin default is how two holders derive different arrangements from one
132
- * genesis. Absent `admin_set` means both genesis participants govern (the bilateral default);
133
- * `admin_set` itself lives on the ARRANGEMENT, not in the scalar properties bag the replay
134
- * derives `change_property` against.
135
- */
136
- export function arrangementGenesisFromProposal(genesis) {
137
- return {
138
- documentId: documentIdFromProposal(genesis),
139
- proposerAgentId: genesis.proposer_agent_id,
140
- peerAgentId: genesis.peer_agent_id,
141
- adminSet: genesis.properties.admin_set ?? [genesis.proposer_agent_id, genesis.peer_agent_id],
142
- properties: {
143
- assurance_tier: genesis.properties.assurance_tier,
144
- schema_enforcement: genesis.properties.schema_enforcement,
145
- topology: genesis.properties.topology,
146
- append_only: genesis.properties.append_only,
147
- ...(genesis.properties.content_profile !== undefined
148
- ? { content_profile: genesis.properties.content_profile }
149
- : {}),
150
- },
151
- };
152
- }
153
- function refuse(reason) {
154
- return { ok: false, reason };
155
- }
156
- /**
157
- * The invitee's ruling on an offer. Order is the disclosure-and-trust boundary: the version
158
- * answer first (a mismatched build must get a sentence, not a failed signature), then the
159
- * inviter's signature (nothing else is worth computing on an unauthenticated bundle), then the
160
- * carried payloads each on their own signatures, then the replay.
161
- */
162
- export function validateDocumentJoinOffer(offer, policy, verify) {
163
- if (offer.feature_version !== DOCUMENT_FEATURE_VERSION) {
164
- const side = offer.feature_version > DOCUMENT_FEATURE_VERSION
165
- ? "upgrade this client to join it"
166
- : "ask the inviter to upgrade theirs";
167
- return refuse(`join_feature_version: the offer speaks document feature version ${offer.feature_version} ` +
168
- `and this build speaks ${DOCUMENT_FEATURE_VERSION} — ${side}`);
169
- }
170
- if (!verify(offer.inviter_agent_id, buildDocumentJoinOfferTbs(offer), offer.signature)) {
171
- return refuse(`join_signature_invalid: the offer claims to come from ${offer.inviter_agent_id} but its ` +
172
- `signature does not verify against that agent — nothing about the bundle is trustworthy`);
173
- }
174
- let genesis;
175
- try {
176
- genesis = decodeDocumentProposal(offer.genesis);
177
- }
178
- catch (err) {
179
- return refuse(`join_genesis_undecodable: ${err instanceof Error ? err.message : String(err)}`);
180
- }
181
- if (documentIdFromProposal(genesis) !== offer.document_id) {
182
- return refuse(`join_genesis_mismatch: the carried genesis hashes to a different document than the offer ` +
183
- `names — the anchor cannot be swapped`);
184
- }
185
- if (!verify(genesis.proposer_agent_id, buildDocumentProposalTbs(genesis), genesis.signature)) {
186
- return refuse(`join_genesis_signature_invalid: the genesis proposal does not verify against its named ` +
187
- `proposer ${genesis.proposer_agent_id}`);
188
- }
189
- if (offer.amendments.length === 0) {
190
- return refuse("join_no_pending_amendment: an offer must carry the amendment chain ending in the " +
191
- "add_holder that admits the invitee — an empty chain admits nobody");
192
- }
193
- let amendments;
194
- try {
195
- amendments = offer.amendments.map((a) => decodeDocumentAmendment(a));
196
- }
197
- catch (err) {
198
- return refuse(`join_amendment_undecodable: ${err instanceof Error ? err.message : String(err)}`);
199
- }
200
- const derived = deriveArrangement(arrangementGenesisFromProposal(genesis), amendments, policy, verify);
201
- if (!derived.ok) {
202
- // The replay's reason IS the diagnosis — passed through, never substituted.
203
- return refuse(derived.reason);
204
- }
205
- const pending = amendments[amendments.length - 1];
206
- if (pending.body.kind !== "add_holder" || pending.body.subject_agent_id !== offer.invitee_agent_id) {
207
- return refuse(`join_not_for_invitee: the chain's last amendment does not admit ${offer.invitee_agent_id} — ` +
208
- `an offer is addressed to the holder its pending amendment names`);
209
- }
210
- if (!pending.collection.required_signers.includes(offer.inviter_agent_id)) {
211
- return refuse(`join_inviter_not_signer: ${offer.inviter_agent_id} authored the offer but is not a claimed ` +
212
- `signer of the admitting amendment — the offer's author must be behind the admission`);
213
- }
214
- return {
215
- ok: true,
216
- arrangement: derived.arrangement,
217
- genesis,
218
- amendments,
219
- // Unconditional: after a successful replay the subject_hash provably equals the amendment
220
- // hash, and a conditional empty-string key would collide every document on "" if the
221
- // invariant ever broke — better to emit the hex of whatever verified.
222
- pendingAmendmentHash: Buffer.from(pending.collection.subject_hash).toString("hex"),
223
- };
224
- }
225
- //# sourceMappingURL=document-join.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"document-join.js","sourceRoot":"","sources":["../src/document-join.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,EACtB,wBAAwB,GAEzB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,uBAAuB,EACvB,iBAAiB,GAKlB,MAAM,yBAAyB,CAAC;AAEjC,kGAAkG;AAClG,MAAM,CAAC,MAAM,0BAA0B,GAAG,8BAA8B,CAAC;AAoBzE,SAAS,MAAM,CAAC,KAAiB;IAC/B,OAAO,IAAI,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;AACrE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CACvC,KAAwB,EACxB,OAA8B,EAAE;IAEhC,MAAM,QAAQ,GAAG,UAAU,CAAC;QAC1B,0BAA0B;QAC1B,KAAK,CAAC,eAAe;QACrB,KAAK,CAAC,gBAAgB;QACtB,KAAK,CAAC,gBAAgB;QACtB,KAAK,CAAC,WA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