Events 3.0: auto-connect, demo people in Accounts, e2e; import.finish checks the subs

- contracts 1.8.0 / Accounts 1.1.0: import.finish lists the subs the product
  relies on; Accounts checks each is held, not deleted and known to it (the
  count+hash failed a second move after Undo once someone had joined
  through Accounts).
- Events: connects to the church's Accounts once the Hub lists it;
  moveNewPeople (demo data, people added after the move); set-demo moves
  demo people; e2e/sign-in-accounts.spec.ts with Accounts in memory and an
  e2e-only /api rewrite. test:accounts 14/14; Jest auto-connect tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 14:28:54 +02:00
co-authored by Claude Opus 5.5
parent c627c61de1
commit 63d36c3ecf
24 changed files with 466 additions and 63 deletions
@@ -3,6 +3,7 @@
"actor": "8d2e4f6a-1b3c-4d5e-8f7a-9b0c1d2e3f4a",
"requestId": "2d8a3b4c-5e6f-4a7b-8c1d-2e3f4a5b6c7d",
"type": "import.finish",
"count": 1,
"idsHash": "9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f9f"
"subs": [
"5f0c7d2a-3b1e-4c8f-9a6d-2e4b1c7f8a90"
]
}
@@ -421,14 +421,14 @@
"type": "string",
"const": "import.finish"
},
"count": {
"type": "integer",
"minimum": 0,
"maximum": 9007199254740991
},
"idsHash": {
"type": "string",
"pattern": "^[0-9a-f]{64}$"
"subs": {
"maxItems": 50000,
"type": "array",
"items": {
"type": "string",
"format": "uuid",
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
}
}
},
"required": [
@@ -436,8 +436,7 @@
"requestId",
"actor",
"type",
"count",
"idsHash"
"subs"
]
},
{
@@ -14,11 +14,21 @@
"type": "integer",
"minimum": 0,
"maximum": 9007199254740991
},
"missing": {
"maxItems": 100,
"type": "array",
"items": {
"type": "string",
"format": "uuid",
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
}
}
},
"required": [
"schema",
"matched",
"count"
"count",
"missing"
]
}
+12 -12
View File
@@ -97,14 +97,18 @@ export const importBatchSchema = base.extend({
people: z.array(importPersonSchema).min(1).max(IMPORT_BATCH_MAX),
});
/** At most this many subs in an `import.finish`. */
export const IMPORT_FINISH_MAX = 50_000;
/**
* Ends a move: Accounts compares the count and the hash (`importIdsHash`) of the **subs** it gave
* back (`created`, `updated` and `linked`) with the people it holds as moved from this product.
* Ends a move: every account the product now relies on (each of its users' `sub`). Accounts checks
* each is an account it holds, not deleted, and known to this product (moved in, added, or signed
* in through it), and only then ends the move. So people who signed up through Accounts since an
* earlier move, or a move run again after a failure, check out too.
*/
export const importFinishSchema = base.extend({
type: z.literal("import.finish"),
count: z.int().nonnegative(),
idsHash: z.string().regex(/^[0-9a-f]{64}$/),
subs: z.array(idSchema).max(IMPORT_FINISH_MAX),
});
export const importAbortSchema = base.extend({ type: z.literal("import.abort") });
@@ -172,8 +176,12 @@ export const importBatchReplySchema = z.object({
export const importFinishReplySchema = z.object({
schema: z.literal(IDENTITY_REQUEST_SCHEMA),
/** Every sub checked out; the move has ended. */
matched: z.boolean(),
/** How many of the subs Accounts holds for this product. */
count: z.int().nonnegative(),
/** Some of the subs that didn't check out (at most 100). */
missing: z.array(idSchema).max(100),
});
export const peopleEnsureReplySchema = z.object({
@@ -188,11 +196,3 @@ export const okReplySchema = z.object({ schema: z.literal(IDENTITY_REQUEST_SCHEM
export const IDENTITY_REQUEST_ERROR_CODES = [
"NOT_LINKED", "BAD_SIGNATURE", "STALE_REQUEST", "INVALID_REQUEST", "NOT_MOVING", "WRONG_PRODUCT", "UNKNOWN_PERSON", "EMAIL_TAKEN", "NOT_ALLOWED",
] as const;
/**
* The hash `import.finish` carries: SHA-256 (hex) of the sorted ids joined by "\n". Pure JS so it
* works in the browser build too; products compute it over the ids they sent (not `refused`).
*/
export function importIdsInput(ids: Iterable<string>): string {
return [...ids].sort().join("\n");
}
-7
View File
@@ -1,7 +1,6 @@
import {
createCipheriv,
createDecipheriv,
createHash,
createHmac,
createPrivateKey,
createPublicKey,
@@ -16,7 +15,6 @@ import {
} from "node:crypto";
import { AGENT_HEADERS, type Sealed } from "./agent";
import { canonicalJson } from "./canonical";
import { importIdsInput } from "./identity-request";
export { canonicalJson } from "./canonical";
@@ -324,8 +322,3 @@ export function openLinkValue(linkSecret: string, sealed: string): string {
decipher.setAuthTag(raw.subarray(raw.length - 16));
return Buffer.concat([decipher.update(raw.subarray(12, raw.length - 16)), decipher.final()]).toString("utf8");
}
/** The `idsHash` of `import.finish`: SHA-256 (hex) of the sorted ids joined by "\n". */
export function importIdsHash(ids: Iterable<string>): string {
return createHash("sha256").update(importIdsInput(ids)).digest("hex");
}
@@ -1,5 +1,5 @@
import { identityRequestSchema, importPersonSchema, sealedValueSchema } from "../src";
import { importIdsHash, newLinkSecret, openLinkValue, sealLinkValue } from "../src/signing";
import { newLinkSecret, openLinkValue, sealLinkValue } from "../src/signing";
import { sample } from "./helpers";
describe("crosscode.identity-request/1", () => {
@@ -15,11 +15,10 @@ describe("crosscode.identity-request/1", () => {
expect(() => openLinkValue(secret, tampered)).toThrow();
});
test("the ids hash doesn't depend on order", () => {
const a = ["b8f1c2d3-0000-4000-8000-000000000002", "a7e0b1c2-0000-4000-8000-000000000001"];
expect(importIdsHash(a)).toBe(importIdsHash([...a].reverse()));
expect(importIdsHash(a)).toMatch(/^[0-9a-f]{64}$/);
expect(importIdsHash(a)).not.toBe(importIdsHash(a.slice(0, 1)));
test("import.finish lists the subs (uuids)", () => {
const finish = sample<{ subs: string[] }>("import-finish.json");
expect(identityRequestSchema.safeParse(finish).success).toBe(true);
expect(identityRequestSchema.safeParse({ ...finish, subs: ["not-a-uuid"] }).success).toBe(false);
});
test("an unsealed password hash is refused", () => {