| 66 | } |
| 67 | |
| 68 | export function buildImmutableRuntimePrefix( |
| 69 | identity: RuntimePrefixIdentityV1, |
| 70 | rows: readonly RuntimePrefixRowV1[], |
| 71 | ): ImmutableRuntimePrefixV1 { |
| 72 | const canonicalRows = canonicalizePrefixRows(identity, rows); |
| 73 | const last = canonicalRows.at(-1); |
| 74 | if (!last) throw new Error('immutable RuntimeEvent prefix is empty'); |
| 75 | return { |
| 76 | protocol: 'immutable_runtime_prefix_v1', |
| 77 | identity: { ...identity }, |
| 78 | position: { |
| 79 | lastEventSeq: last.eventSeq, |
| 80 | eventCount: canonicalRows.length, |
| 81 | lastEventId: last.event.id, |
| 82 | }, |
| 83 | prefixDigest: digestCanonicalRuntimePrefix(identity, canonicalRows), |
| 84 | events: canonicalRows.map((row) => row.event), |
| 85 | }; |
| 86 | } |
| 87 | |
| 88 | export function digestRuntimePrefix( |
| 89 | identity: RuntimePrefixIdentityV1, |