diff --git a/docs/design/COMPANY-CLONE-PARITY.md b/docs/design/COMPANY-CLONE-PARITY.md index 231bd0bf..3cdce4e8 100644 --- a/docs/design/COMPANY-CLONE-PARITY.md +++ b/docs/design/COMPANY-CLONE-PARITY.md @@ -13,7 +13,7 @@ the mother's mailbox; acquired entities retain their previous mailbox origin. Company creation triggers provisioning and the existing reconciler retries it. No message contents are moved or deleted. Full transfer execution is separate work. -Unicorp's explicitly authorised rollout checks its exact slug/name, active deed, +Unicorp's explicitly authorised rollout checks its unique name, active deed, owner unimatrix999 and previously consumed original COM key. One staff Company Royal key upgrades its deed and queues a separate mailbox. The mail reconciler provisions it; repeats create no duplicate key or mailbox. Revocation or lost diff --git a/website/node/company-royal-mail.mjs b/website/node/company-royal-mail.mjs index 053618a1..e184b61a 100644 --- a/website/node/company-royal-mail.mjs +++ b/website/node/company-royal-mail.mjs @@ -2,7 +2,7 @@ import {createHash,randomUUID} from 'node:crypto'; import {STAFF_OFFICE_ACCOUNT_ID,OrganisationKeyError} from './organisation-keys.mjs'; export const COMPANY_ROYAL_MAIL_SCHEMA=`CREATE TABLE IF NOT EXISTS site_company_royal_mail (company_id CHAR(36) PRIMARY KEY,royal_key_id CHAR(36) NOT NULL UNIQUE,mailbox_id CHAR(36) NOT NULL UNIQUE,state VARCHAR(12) NOT NULL,updated_at BIGINT NOT NULL)`; export function separateCompanyMailboxId(id){const h=createHash('sha256').update('dunerealms:royal-company-mail:'+id).digest('hex');return h.slice(0,8)+'-'+h.slice(8,12)+'-4'+h.slice(13,16)+'-8'+h.slice(17,20)+'-'+h.slice(20,32);} -const targetSql="SELECT c.id,c.name,c.slug,c.status,d.owner_account_id,d.charter_kind,d.original_key_id FROM corrino_companies c JOIN site_company_deeds d ON d.company_id=c.id JOIN site_accounts a ON a.id=d.owner_account_id WHERE c.slug='unicorp' AND LOWER(c.name)='unicorp' AND LOWER(a.username)='unimatrix999' AND a.password_hash NOT LIKE '!%'"; +const targetSql="SELECT c.id,c.name,c.slug,c.status,d.owner_account_id,d.charter_kind,d.original_key_id FROM corrino_companies c JOIN site_company_deeds d ON d.company_id=c.id JOIN site_accounts a ON a.id=d.owner_account_id WHERE LOWER(c.name)='unicorp' AND LOWER(a.username)='unimatrix999' AND a.password_hash NOT LIKE '!%'"; const first=(db,sql,args=[])=>typeof db.first==='function'?db.first(sql,args):db.prepare(sql).bind(...args).first(); async function verifyOriginal(tx,c){ const original=c&&await first(tx,"SELECT id FROM organisation_keys WHERE id=? AND key_type='company-founding' AND target_id=? AND used_at IS NOT NULL AND revoked_at IS NULL",[c.original_key_id,c.id]);