@hasna/infinity 0.1.0

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 (112) hide show
  1. package/LICENSE +3 -0
  2. package/README.md +331 -0
  3. package/dist/cli.js +2965 -0
  4. package/dist/http-api.js +6448 -0
  5. package/dist/index.js +28536 -0
  6. package/dist/migrate.js +346 -0
  7. package/dist/self-hosted-migrate.js +2064 -0
  8. package/dist/self-hosted.js +13180 -0
  9. package/dist/types/authcapsules/codewith-local.d.ts +109 -0
  10. package/dist/types/authcapsules/infinity-agent-policy.d.ts +57 -0
  11. package/dist/types/authcapsules/os-isolated-runner.d.ts +87 -0
  12. package/dist/types/authority/authority.d.ts +342 -0
  13. package/dist/types/authority/effect-journal.d.ts +205 -0
  14. package/dist/types/authority/mutation-journal.d.ts +163 -0
  15. package/dist/types/authority/mutation-tuple.d.ts +26 -0
  16. package/dist/types/authority/state.d.ts +75 -0
  17. package/dist/types/authority/store.d.ts +15 -0
  18. package/dist/types/brokers/checkpoint/archive.d.ts +21 -0
  19. package/dist/types/brokers/checkpoint/bundle.d.ts +22 -0
  20. package/dist/types/brokers/checkpoint/bytes.d.ts +4 -0
  21. package/dist/types/brokers/checkpoint/clean-verifier-finalization.d.ts +62 -0
  22. package/dist/types/brokers/checkpoint/clean-verifier.d.ts +145 -0
  23. package/dist/types/brokers/checkpoint/final-trust-authority.d.ts +55 -0
  24. package/dist/types/brokers/checkpoint/idempotency.d.ts +25 -0
  25. package/dist/types/brokers/checkpoint/journaled-store.d.ts +9 -0
  26. package/dist/types/brokers/checkpoint/manifest-signature.d.ts +135 -0
  27. package/dist/types/brokers/checkpoint/manifest.d.ts +57 -0
  28. package/dist/types/brokers/checkpoint/s3-store.d.ts +215 -0
  29. package/dist/types/brokers/checkpoint/seal-authority.d.ts +86 -0
  30. package/dist/types/brokers/checkpoint/service.d.ts +198 -0
  31. package/dist/types/brokers/checkpoint/signing-message.d.ts +22 -0
  32. package/dist/types/brokers/checkpoint/store.d.ts +76 -0
  33. package/dist/types/brokers/checkpoint/verifier-cleanup-authority.d.ts +108 -0
  34. package/dist/types/brokers/checkpoint/verifier-cleanup.d.ts +391 -0
  35. package/dist/types/brokers/checkpoint/verifier.d.ts +225 -0
  36. package/dist/types/brokers/composition.d.ts +86 -0
  37. package/dist/types/brokers/git/github-app.d.ts +216 -0
  38. package/dist/types/brokers/git/promotion.d.ts +418 -0
  39. package/dist/types/brokers/persistence/contracts.d.ts +77 -0
  40. package/dist/types/brokers/persistence/memory.d.ts +5 -0
  41. package/dist/types/brokers/persistence/migration.d.ts +6 -0
  42. package/dist/types/brokers/persistence/postgres.d.ts +74 -0
  43. package/dist/types/cli/main.d.ts +2 -0
  44. package/dist/types/cli/operation-journal.d.ts +47 -0
  45. package/dist/types/cli/run.d.ts +15 -0
  46. package/dist/types/client/operator-client.d.ts +100 -0
  47. package/dist/types/contracts/dtos.d.ts +198 -0
  48. package/dist/types/contracts/events.d.ts +45 -0
  49. package/dist/types/contracts/fence.d.ts +39 -0
  50. package/dist/types/contracts/operations.d.ts +91 -0
  51. package/dist/types/contracts/runspec.d.ts +75 -0
  52. package/dist/types/contracts/validators.d.ts +8 -0
  53. package/dist/types/core/clock.d.ts +12 -0
  54. package/dist/types/core/errors.d.ts +18 -0
  55. package/dist/types/core/ids.d.ts +10 -0
  56. package/dist/types/core/int64.d.ts +7 -0
  57. package/dist/types/core/strict-json.d.ts +8 -0
  58. package/dist/types/core/validation.d.ts +25 -0
  59. package/dist/types/golden/disposable-task.d.ts +108 -0
  60. package/dist/types/golden/source-pins.d.ts +77 -0
  61. package/dist/types/http/api.d.ts +52 -0
  62. package/dist/types/http/bearer-auth.d.ts +8 -0
  63. package/dist/types/http/main.d.ts +3 -0
  64. package/dist/types/http/self-hosted-main.d.ts +17 -0
  65. package/dist/types/index.d.ts +65 -0
  66. package/dist/types/mcp/schema.d.ts +7 -0
  67. package/dist/types/node-agent/agent.d.ts +174 -0
  68. package/dist/types/node-agent/contracts.d.ts +119 -0
  69. package/dist/types/node-agent/macos-service.d.ts +33 -0
  70. package/dist/types/node-agent/service-cli.d.ts +26 -0
  71. package/dist/types/persistence/composition.d.ts +49 -0
  72. package/dist/types/persistence/migrate-main.d.ts +2 -0
  73. package/dist/types/persistence/migrations.d.ts +30 -0
  74. package/dist/types/persistence/postgres-accounts-operation.d.ts +26 -0
  75. package/dist/types/persistence/postgres-authority.d.ts +69 -0
  76. package/dist/types/persistence/postgres-external-mutation-journal.d.ts +22 -0
  77. package/dist/types/persistence/postgres-json.d.ts +1 -0
  78. package/dist/types/persistence/postgres-mutation-journal.d.ts +31 -0
  79. package/dist/types/persistence/postgres-reconciler.d.ts +34 -0
  80. package/dist/types/persistence/postgres-sandbox-dispatch-authority.d.ts +9 -0
  81. package/dist/types/persistence/self-hosted-migrate-main.d.ts +2 -0
  82. package/dist/types/ports/accounts-operation.d.ts +336 -0
  83. package/dist/types/ports/accounts.d.ts +293 -0
  84. package/dist/types/ports/sandbox-dispatch-authority.d.ts +154 -0
  85. package/dist/types/ports/sandboxes.d.ts +40 -0
  86. package/dist/types/providers/sandbox-dispatch.d.ts +143 -0
  87. package/dist/types/runtime/config.d.ts +61 -0
  88. package/dist/types/runtime/postgres.d.ts +18 -0
  89. package/dist/types/runtime/provider-activation.d.ts +45 -0
  90. package/dist/types/runtime/server.d.ts +68 -0
  91. package/dist/types/testing/accounts-fake.d.ts +31 -0
  92. package/dist/types/testing/fakes.d.ts +2 -0
  93. package/dist/types/testing/node-control-plane-fake.d.ts +20 -0
  94. package/dist/types/testing/reference.d.ts +27 -0
  95. package/dist/types/testing/sandboxes-fake.d.ts +22 -0
  96. package/evidence/provider-live-daytona-v3.json +1 -0
  97. package/evidence/provider-live-e2b-v3.json +1 -0
  98. package/evidence/provider-production-route-daytona-v1.json +1 -0
  99. package/evidence/provider-production-route-e2b-v1.json +1 -0
  100. package/migrations/0001_authority.sql +689 -0
  101. package/migrations/0002_effect_step_global_owner.sql +2 -0
  102. package/migrations/0003_effect_journal_observed_head.sql +34 -0
  103. package/migrations/0004_authority_mutation_journal_binding.sql +15 -0
  104. package/migrations/20260710_checkpoint_broker_v1.sql +163 -0
  105. package/migrations/20260711_accounts_operation_v1.sql +137 -0
  106. package/migrations/20260711_checkpoint_trust_v2.sql +17 -0
  107. package/migrations/20260711_verifier_cleanup_v2.sql +169 -0
  108. package/migrations/20260711_z_accounts_claim_authority_v2.sql +172 -0
  109. package/migrations/20260711_zz_sandbox_dispatch_authority_v1.sql +143 -0
  110. package/migrations/20260712_sandbox_dispatch_authority_v2.sql +58 -0
  111. package/migrations/external-journal/0001_external_authority_mutation_journal.sql +175 -0
  112. package/package.json +47 -0
@@ -0,0 +1,2 @@
1
+ ALTER TABLE infinity.effect_operation_steps
2
+ ADD CONSTRAINT effect_operation_steps_global_id_unique UNIQUE (operation_step_id);
@@ -0,0 +1,34 @@
1
+ CREATE TABLE infinity.effect_journal_observed_head (
2
+ singleton boolean PRIMARY KEY DEFAULT true CHECK (singleton),
3
+ journal_sequence bigint NOT NULL CHECK (journal_sequence >= 0),
4
+ frontier_digest text CHECK (frontier_digest IS NULL OR frontier_digest ~ '^sha256:[0-9a-f]{64}$'),
5
+ head_receipt jsonb NOT NULL,
6
+ updated_at timestamptz NOT NULL,
7
+ CHECK ((journal_sequence = 0) = (frontier_digest IS NULL))
8
+ );
9
+
10
+ CREATE OR REPLACE FUNCTION infinity.validate_effect_journal_observed_head_update() RETURNS trigger
11
+ LANGUAGE plpgsql AS $$
12
+ BEGIN
13
+ IF TG_OP = 'DELETE' THEN
14
+ RAISE EXCEPTION 'effect journal observed head cannot be deleted' USING ERRCODE = '55000';
15
+ END IF;
16
+ IF TG_OP = 'UPDATE' AND (
17
+ NEW.singleton IS DISTINCT FROM OLD.singleton
18
+ OR NEW.journal_sequence < OLD.journal_sequence
19
+ OR (NEW.journal_sequence = OLD.journal_sequence
20
+ AND NEW.frontier_digest IS DISTINCT FROM OLD.frontier_digest)
21
+ ) THEN
22
+ RAISE EXCEPTION 'effect journal observed head cannot roll back or equivocate' USING ERRCODE = '23514';
23
+ END IF;
24
+ IF (NEW.head_receipt->>'journal_sequence')::bigint IS DISTINCT FROM NEW.journal_sequence
25
+ OR NEW.head_receipt->>'frontier_digest' IS DISTINCT FROM NEW.frontier_digest THEN
26
+ RAISE EXCEPTION 'effect journal observed head columns differ from signed receipt' USING ERRCODE = '23514';
27
+ END IF;
28
+ RETURN NEW;
29
+ END;
30
+ $$;
31
+
32
+ CREATE TRIGGER effect_journal_observed_head_guard
33
+ BEFORE INSERT OR UPDATE OR DELETE ON infinity.effect_journal_observed_head
34
+ FOR EACH ROW EXECUTE FUNCTION infinity.validate_effect_journal_observed_head_update();
@@ -0,0 +1,15 @@
1
+ CREATE TABLE infinity.authority_mutation_journal_binding (
2
+ singleton boolean PRIMARY KEY DEFAULT true CHECK (singleton),
3
+ journal_id text NOT NULL,
4
+ restore_domain_id text NOT NULL,
5
+ durability text NOT NULL CHECK (durability = 'durable'),
6
+ encrypted_at_rest boolean NOT NULL CHECK (encrypted_at_rest),
7
+ signer_principal text NOT NULL,
8
+ signing_key_id text NOT NULL,
9
+ protection_digest text NOT NULL CHECK (protection_digest ~ '^sha256:[0-9a-f]{64}$'),
10
+ bound_at timestamptz NOT NULL
11
+ );
12
+
13
+ CREATE TRIGGER authority_mutation_journal_binding_immutable
14
+ BEFORE UPDATE OR DELETE ON infinity.authority_mutation_journal_binding
15
+ FOR EACH ROW EXECUTE FUNCTION infinity.reject_immutable_mutation();
@@ -0,0 +1,163 @@
1
+ CREATE TABLE IF NOT EXISTS infinity_schema_migrations (
2
+ migration_id text PRIMARY KEY,
3
+ applied_at timestamptz NOT NULL DEFAULT clock_timestamp()
4
+ );
5
+
6
+ CREATE TABLE IF NOT EXISTS infinity_broker_operations (
7
+ operation_id text PRIMARY KEY,
8
+ operation_digest text NOT NULL CHECK (operation_digest ~ '^sha256:[0-9a-f]{64}$'),
9
+ fence_canonical_json text NOT NULL,
10
+ state text NOT NULL CHECK (state IN ('in_flight', 'committed', 'unknown_requires_review')),
11
+ owner_execution_id uuid NOT NULL,
12
+ execution_expires_at timestamptz NOT NULL,
13
+ result_canonical_json text,
14
+ unknown_reason_code text,
15
+ reconciliation_evidence_sha256 text CHECK (reconciliation_evidence_sha256 IS NULL OR reconciliation_evidence_sha256 ~ '^sha256:[0-9a-f]{64}$'),
16
+ reconciled_at timestamptz,
17
+ created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
18
+ updated_at timestamptz NOT NULL DEFAULT clock_timestamp(),
19
+ CHECK (state <> 'committed' OR result_canonical_json IS NOT NULL),
20
+ CHECK (state <> 'in_flight' OR result_canonical_json IS NULL),
21
+ CHECK (state <> 'unknown_requires_review' OR unknown_reason_code IS NOT NULL),
22
+ CHECK ((reconciliation_evidence_sha256 IS NULL) = (reconciled_at IS NULL))
23
+ );
24
+
25
+ CREATE TABLE IF NOT EXISTS infinity_provider_steps (
26
+ operation_id text NOT NULL REFERENCES infinity_broker_operations(operation_id) ON DELETE RESTRICT,
27
+ step_key text NOT NULL,
28
+ step_digest text NOT NULL CHECK (step_digest ~ '^sha256:[0-9a-f]{64}$'),
29
+ action text NOT NULL,
30
+ fence_canonical_json text NOT NULL,
31
+ request_canonical_json text NOT NULL,
32
+ state text NOT NULL CHECK (state IN ('prepared', 'dispatched', 'succeeded', 'failed_no_effect', 'unknown_requires_review')),
33
+ owner_execution_id uuid NOT NULL,
34
+ parent_owner_execution_id uuid NOT NULL,
35
+ execution_expires_at timestamptz NOT NULL,
36
+ resource_generation_before numeric(19, 0) NOT NULL CHECK (resource_generation_before > 0 AND resource_generation_before <= 9223372036854775807),
37
+ resource_generation_after numeric(19, 0) NOT NULL CHECK (resource_generation_after > 0 AND resource_generation_after <= 9223372036854775807),
38
+ provider_request_id text,
39
+ provider_client_token_fingerprint text CHECK (provider_client_token_fingerprint IS NULL OR provider_client_token_fingerprint ~ '^sha256:[0-9a-f]{64}$'),
40
+ result_canonical_json text,
41
+ unknown_reason_code text,
42
+ reconciliation_provider_request_id text,
43
+ reconciliation_evidence_sha256 text CHECK (reconciliation_evidence_sha256 IS NULL OR reconciliation_evidence_sha256 ~ '^sha256:[0-9a-f]{64}$'),
44
+ reconciled_at timestamptz,
45
+ effect_anchor_id text,
46
+ effect_anchor_event_id text,
47
+ effect_anchor_core_sha256 text CHECK (effect_anchor_core_sha256 IS NULL OR effect_anchor_core_sha256 ~ '^sha256:[0-9a-f]{64}$'),
48
+ effect_anchor_receipt_sha256 text CHECK (effect_anchor_receipt_sha256 IS NULL OR effect_anchor_receipt_sha256 ~ '^sha256:[0-9a-f]{64}$'),
49
+ effect_anchor_signing_key_id text,
50
+ effect_anchor_signature_sha256 text CHECK (effect_anchor_signature_sha256 IS NULL OR effect_anchor_signature_sha256 ~ '^sha256:[0-9a-f]{64}$'),
51
+ effect_anchor_committed_at timestamptz,
52
+ effect_anchor_authority_witness_sha256 text CHECK (effect_anchor_authority_witness_sha256 IS NULL OR effect_anchor_authority_witness_sha256 ~ '^sha256:[0-9a-f]{64}$'),
53
+ effect_anchor_cancellation_witness_sha256 text CHECK (effect_anchor_cancellation_witness_sha256 IS NULL OR effect_anchor_cancellation_witness_sha256 ~ '^sha256:[0-9a-f]{64}$'),
54
+ prepared_at timestamptz NOT NULL DEFAULT clock_timestamp(),
55
+ dispatched_at timestamptz,
56
+ completed_at timestamptz,
57
+ created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
58
+ updated_at timestamptz NOT NULL DEFAULT clock_timestamp(),
59
+ PRIMARY KEY (operation_id, step_key),
60
+ CHECK (state <> 'succeeded' OR result_canonical_json IS NOT NULL),
61
+ CHECK (state NOT IN ('prepared', 'dispatched', 'failed_no_effect') OR result_canonical_json IS NULL),
62
+ CHECK ((state IN ('dispatched', 'succeeded', 'failed_no_effect', 'unknown_requires_review')) = (dispatched_at IS NOT NULL)),
63
+ CHECK ((state IN ('succeeded', 'failed_no_effect', 'unknown_requires_review')) = (completed_at IS NOT NULL)),
64
+ CHECK (state <> 'unknown_requires_review' OR unknown_reason_code IS NOT NULL),
65
+ CHECK (
66
+ (reconciliation_provider_request_id IS NULL AND reconciliation_evidence_sha256 IS NULL AND reconciled_at IS NULL)
67
+ OR
68
+ (reconciliation_provider_request_id IS NOT NULL AND reconciliation_evidence_sha256 IS NOT NULL AND reconciled_at IS NOT NULL)
69
+ ),
70
+ CHECK (
71
+ (state = 'prepared'
72
+ AND effect_anchor_id IS NULL
73
+ AND effect_anchor_event_id IS NULL
74
+ AND effect_anchor_core_sha256 IS NULL
75
+ AND effect_anchor_receipt_sha256 IS NULL
76
+ AND effect_anchor_signing_key_id IS NULL
77
+ AND effect_anchor_signature_sha256 IS NULL
78
+ AND effect_anchor_committed_at IS NULL
79
+ AND effect_anchor_authority_witness_sha256 IS NULL
80
+ AND effect_anchor_cancellation_witness_sha256 IS NULL)
81
+ OR
82
+ (state <> 'prepared'
83
+ AND effect_anchor_id IS NOT NULL
84
+ AND effect_anchor_event_id IS NOT NULL
85
+ AND effect_anchor_core_sha256 IS NOT NULL
86
+ AND effect_anchor_receipt_sha256 IS NOT NULL
87
+ AND effect_anchor_signing_key_id IS NOT NULL
88
+ AND effect_anchor_signature_sha256 IS NOT NULL
89
+ AND effect_anchor_committed_at IS NOT NULL
90
+ AND effect_anchor_authority_witness_sha256 IS NOT NULL
91
+ AND effect_anchor_cancellation_witness_sha256 IS NOT NULL
92
+ AND effect_anchor_committed_at < execution_expires_at)
93
+ )
94
+ );
95
+
96
+ CREATE INDEX IF NOT EXISTS infinity_provider_steps_state_idx
97
+ ON infinity_provider_steps (state, execution_expires_at);
98
+
99
+ CREATE TABLE IF NOT EXISTS infinity_checkpoint_seals (
100
+ checkpoint_id text PRIMARY KEY,
101
+ operation_id text NOT NULL UNIQUE REFERENCES infinity_broker_operations(operation_id) ON DELETE RESTRICT,
102
+ seal_core_digest text NOT NULL UNIQUE CHECK (seal_core_digest ~ '^sha256:[0-9a-f]{64}$'),
103
+ manifest_digest text NOT NULL CHECK (manifest_digest ~ '^sha256:[0-9a-f]{64}$'),
104
+ fence_canonical_json text NOT NULL,
105
+ authority_transaction_id text NOT NULL UNIQUE,
106
+ authority_event_id text NOT NULL UNIQUE,
107
+ signing_key_id text NOT NULL,
108
+ signature_sha256 text NOT NULL CHECK (signature_sha256 ~ '^sha256:[0-9a-f]{64}$'),
109
+ seal_receipt_canonical_json text NOT NULL,
110
+ committed_at timestamptz NOT NULL,
111
+ created_at timestamptz NOT NULL DEFAULT clock_timestamp()
112
+ );
113
+
114
+ CREATE TABLE IF NOT EXISTS infinity_checkpoint_events (
115
+ event_id text PRIMARY KEY,
116
+ operation_id text NOT NULL REFERENCES infinity_broker_operations(operation_id) ON DELETE RESTRICT,
117
+ checkpoint_id text NOT NULL REFERENCES infinity_checkpoint_seals(checkpoint_id) ON DELETE RESTRICT,
118
+ event_type text NOT NULL CHECK (event_type = 'checkpoint_sealed'),
119
+ event_digest text NOT NULL UNIQUE CHECK (event_digest ~ '^sha256:[0-9a-f]{64}$'),
120
+ fence_canonical_json text NOT NULL,
121
+ payload_canonical_json text NOT NULL,
122
+ created_at timestamptz NOT NULL
123
+ );
124
+
125
+ DO $$
126
+ BEGIN
127
+ IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'infinity_checkpoint_seals_event_fk') THEN
128
+ ALTER TABLE infinity_checkpoint_seals
129
+ ADD CONSTRAINT infinity_checkpoint_seals_event_fk
130
+ FOREIGN KEY (authority_event_id) REFERENCES infinity_checkpoint_events(event_id)
131
+ DEFERRABLE INITIALLY DEFERRED;
132
+ END IF;
133
+ END;
134
+ $$;
135
+
136
+ CREATE OR REPLACE FUNCTION infinity_reject_checkpoint_seal_mutation()
137
+ RETURNS trigger
138
+ LANGUAGE plpgsql
139
+ AS $$
140
+ BEGIN
141
+ RAISE EXCEPTION 'infinity checkpoint seals are append-only';
142
+ END;
143
+ $$;
144
+
145
+ DROP TRIGGER IF EXISTS infinity_checkpoint_seals_append_only ON infinity_checkpoint_seals;
146
+ CREATE TRIGGER infinity_checkpoint_seals_append_only
147
+ BEFORE UPDATE OR DELETE ON infinity_checkpoint_seals
148
+ FOR EACH ROW EXECUTE FUNCTION infinity_reject_checkpoint_seal_mutation();
149
+
150
+ DROP TRIGGER IF EXISTS infinity_checkpoint_events_append_only ON infinity_checkpoint_events;
151
+ CREATE TRIGGER infinity_checkpoint_events_append_only
152
+ BEFORE UPDATE OR DELETE ON infinity_checkpoint_events
153
+ FOR EACH ROW EXECUTE FUNCTION infinity_reject_checkpoint_seal_mutation();
154
+
155
+ DROP TRIGGER IF EXISTS infinity_checkpoint_seals_no_truncate ON infinity_checkpoint_seals;
156
+ CREATE TRIGGER infinity_checkpoint_seals_no_truncate
157
+ BEFORE TRUNCATE ON infinity_checkpoint_seals
158
+ FOR EACH STATEMENT EXECUTE FUNCTION infinity_reject_checkpoint_seal_mutation();
159
+
160
+ DROP TRIGGER IF EXISTS infinity_checkpoint_events_no_truncate ON infinity_checkpoint_events;
161
+ CREATE TRIGGER infinity_checkpoint_events_no_truncate
162
+ BEFORE TRUNCATE ON infinity_checkpoint_events
163
+ FOR EACH STATEMENT EXECUTE FUNCTION infinity_reject_checkpoint_seal_mutation();
@@ -0,0 +1,137 @@
1
+ -- Durable Accounts operation authority. Every mutable projection is captured by
2
+ -- the existing authority mutation journal; signed evidence and frontier members
3
+ -- are append-only and retain their exact canonical bytes.
4
+
5
+ CREATE TABLE infinity.accounts_resource_authority (
6
+ resource_lease_id text PRIMARY KEY,
7
+ effect_namespace_id text NOT NULL,
8
+ serialization_key_digest text NOT NULL CHECK (serialization_key_digest ~ '^sha256:[0-9a-f]{64}$'),
9
+ resource_id text NOT NULL,
10
+ resource_lifecycle_generation bigint NOT NULL CHECK (resource_lifecycle_generation > 0),
11
+ run_id text NOT NULL REFERENCES infinity.runs(id),
12
+ attempt_id text NOT NULL REFERENCES infinity.attempts(id),
13
+ attempt_lease_id text NOT NULL,
14
+ lease_epoch bigint NOT NULL CHECK (lease_epoch > 0),
15
+ projection_digest text NOT NULL UNIQUE CHECK (projection_digest ~ '^sha256:[0-9a-f]{64}$'),
16
+ projection_record text NOT NULL,
17
+ installed_at timestamptz NOT NULL,
18
+ UNIQUE (effect_namespace_id, serialization_key_digest),
19
+ FOREIGN KEY (attempt_lease_id, attempt_id, lease_epoch)
20
+ REFERENCES infinity.attempt_lease_grants(attempt_lease_id, attempt_id, lease_epoch)
21
+ );
22
+
23
+ CREATE TABLE infinity.accounts_operation_signer_pin (
24
+ singleton boolean PRIMARY KEY DEFAULT true CHECK (singleton),
25
+ trust_anchor_digest text NOT NULL CHECK (trust_anchor_digest ~ '^sha256:[0-9a-f]{64}$'),
26
+ head_sequence bigint NOT NULL CHECK (head_sequence > 0),
27
+ head_digest text NOT NULL CHECK (head_digest ~ '^sha256:[0-9a-f]{64}$'),
28
+ pin_digest text NOT NULL CHECK (pin_digest ~ '^sha256:[0-9a-f]{64}$'),
29
+ pin_record text NOT NULL,
30
+ updated_at timestamptz NOT NULL
31
+ );
32
+
33
+ CREATE OR REPLACE FUNCTION infinity.validate_accounts_operation_signer_pin_update() RETURNS trigger
34
+ LANGUAGE plpgsql AS $$
35
+ BEGIN
36
+ IF NEW.trust_anchor_digest IS DISTINCT FROM OLD.trust_anchor_digest
37
+ OR NEW.head_sequence < OLD.head_sequence
38
+ OR (NEW.head_sequence = OLD.head_sequence AND (
39
+ NEW.head_digest IS DISTINCT FROM OLD.head_digest
40
+ OR NEW.pin_digest IS DISTINCT FROM OLD.pin_digest
41
+ OR NEW.pin_record IS DISTINCT FROM OLD.pin_record
42
+ )) THEN
43
+ RAISE EXCEPTION 'accounts signer-history pin update rewinds or equivocates'
44
+ USING ERRCODE = '23514';
45
+ END IF;
46
+ RETURN NEW;
47
+ END;
48
+ $$;
49
+
50
+ CREATE TABLE infinity.accounts_serialization_domains (
51
+ domain_key text PRIMARY KEY CHECK (domain_key ~ '^sha256:[0-9a-f]{64}$'),
52
+ effect_namespace_id text NOT NULL,
53
+ serialization_key_digest text NOT NULL CHECK (serialization_key_digest ~ '^sha256:[0-9a-f]{64}$'),
54
+ resource_lease_id text NOT NULL UNIQUE REFERENCES infinity.accounts_resource_authority(resource_lease_id),
55
+ active_model_operation_id text,
56
+ revision bigint NOT NULL CHECK (revision > 0),
57
+ state_digest text NOT NULL CHECK (state_digest ~ '^sha256:[0-9a-f]{64}$'),
58
+ state_record text NOT NULL,
59
+ created_at timestamptz NOT NULL,
60
+ updated_at timestamptz NOT NULL CHECK (updated_at >= created_at),
61
+ UNIQUE (effect_namespace_id, serialization_key_digest)
62
+ );
63
+
64
+ CREATE TABLE infinity.accounts_serialization_frontier_heads (
65
+ domain_key text NOT NULL REFERENCES infinity.accounts_serialization_domains(domain_key),
66
+ frontier_kind text NOT NULL CHECK (frontier_kind IN ('RESOURCE_LEASE','MODEL_EFFECT','DELIVERY')),
67
+ frontier_sequence bigint NOT NULL CHECK (frontier_sequence >= 0),
68
+ predecessor_frontier_hash text NOT NULL CHECK (predecessor_frontier_hash ~ '^sha256:[0-9a-f]{64}$'),
69
+ last_record_digest text NOT NULL CHECK (last_record_digest ~ '^sha256:[0-9a-f]{64}$'),
70
+ head_digest text NOT NULL UNIQUE CHECK (head_digest ~ '^sha256:[0-9a-f]{64}$'),
71
+ head_jcs_base64url text NOT NULL,
72
+ head_record text NOT NULL,
73
+ recorded_at timestamptz NOT NULL,
74
+ PRIMARY KEY (domain_key, frontier_kind, frontier_sequence)
75
+ );
76
+
77
+ CREATE TABLE infinity.accounts_model_call_operations (
78
+ operation_id text PRIMARY KEY,
79
+ domain_key text NOT NULL REFERENCES infinity.accounts_serialization_domains(domain_key),
80
+ prepare_input_digest text NOT NULL CHECK (prepare_input_digest ~ '^sha256:[0-9a-f]{64}$'),
81
+ state text NOT NULL CHECK (state IN ('PREPARED','CONSUME_BOUND')),
82
+ consume_receipt_digest text UNIQUE CHECK (consume_receipt_digest IS NULL OR consume_receipt_digest ~ '^sha256:[0-9a-f]{64}$'),
83
+ use_id text UNIQUE CHECK (use_id IS NULL OR use_id ~ '^sha256:[0-9a-f]{64}$'),
84
+ projection_digest text NOT NULL CHECK (projection_digest ~ '^sha256:[0-9a-f]{64}$'),
85
+ projection_record text NOT NULL,
86
+ created_at timestamptz NOT NULL,
87
+ updated_at timestamptz NOT NULL CHECK (updated_at >= created_at),
88
+ CHECK ((state = 'PREPARED' AND consume_receipt_digest IS NULL AND use_id IS NULL)
89
+ OR (state = 'CONSUME_BOUND' AND consume_receipt_digest IS NOT NULL AND use_id IS NOT NULL))
90
+ );
91
+
92
+ CREATE TABLE infinity.accounts_model_effect_journal (
93
+ domain_key text NOT NULL REFERENCES infinity.accounts_serialization_domains(domain_key),
94
+ journal_sequence bigint NOT NULL CHECK (journal_sequence > 0),
95
+ operation_id text NOT NULL REFERENCES infinity.accounts_model_call_operations(operation_id),
96
+ record_kind text NOT NULL CHECK (record_kind IN ('PREPARED','CONSUME_BOUND')),
97
+ prior_frontier_hash text NOT NULL CHECK (prior_frontier_hash ~ '^sha256:[0-9a-f]{64}$'),
98
+ record_digest text NOT NULL UNIQUE CHECK (record_digest ~ '^sha256:[0-9a-f]{64}$'),
99
+ frontier_hash text NOT NULL UNIQUE CHECK (frontier_hash ~ '^sha256:[0-9a-f]{64}$'),
100
+ entry_digest text NOT NULL CHECK (entry_digest ~ '^sha256:[0-9a-f]{64}$'),
101
+ entry_record text NOT NULL,
102
+ recorded_at timestamptz NOT NULL,
103
+ PRIMARY KEY (domain_key, journal_sequence),
104
+ UNIQUE (operation_id, record_kind)
105
+ );
106
+
107
+ CREATE TRIGGER accounts_resource_authority_immutable
108
+ BEFORE UPDATE OR DELETE ON infinity.accounts_resource_authority
109
+ FOR EACH ROW EXECUTE FUNCTION infinity.reject_immutable_mutation();
110
+ CREATE TRIGGER accounts_operation_signer_pin_update_guard
111
+ BEFORE UPDATE ON infinity.accounts_operation_signer_pin
112
+ FOR EACH ROW EXECUTE FUNCTION infinity.validate_accounts_operation_signer_pin_update();
113
+ CREATE TRIGGER accounts_frontier_heads_immutable
114
+ BEFORE UPDATE OR DELETE ON infinity.accounts_serialization_frontier_heads
115
+ FOR EACH ROW EXECUTE FUNCTION infinity.reject_immutable_mutation();
116
+ CREATE TRIGGER accounts_model_effect_journal_immutable
117
+ BEFORE UPDATE OR DELETE ON infinity.accounts_model_effect_journal
118
+ FOR EACH ROW EXECUTE FUNCTION infinity.reject_immutable_mutation();
119
+
120
+ CREATE TRIGGER accounts_resource_authority_mutation_capture
121
+ AFTER INSERT ON infinity.accounts_resource_authority
122
+ FOR EACH ROW EXECUTE FUNCTION infinity.capture_authority_mutation_change();
123
+ CREATE TRIGGER accounts_operation_signer_pin_mutation_capture
124
+ AFTER INSERT OR UPDATE ON infinity.accounts_operation_signer_pin
125
+ FOR EACH ROW EXECUTE FUNCTION infinity.capture_authority_mutation_change();
126
+ CREATE TRIGGER accounts_serialization_domains_mutation_capture
127
+ AFTER INSERT OR UPDATE ON infinity.accounts_serialization_domains
128
+ FOR EACH ROW EXECUTE FUNCTION infinity.capture_authority_mutation_change();
129
+ CREATE TRIGGER accounts_frontier_heads_mutation_capture
130
+ AFTER INSERT ON infinity.accounts_serialization_frontier_heads
131
+ FOR EACH ROW EXECUTE FUNCTION infinity.capture_authority_mutation_change();
132
+ CREATE TRIGGER accounts_model_call_operations_mutation_capture
133
+ AFTER INSERT OR UPDATE ON infinity.accounts_model_call_operations
134
+ FOR EACH ROW EXECUTE FUNCTION infinity.capture_authority_mutation_change();
135
+ CREATE TRIGGER accounts_model_effect_journal_mutation_capture
136
+ AFTER INSERT ON infinity.accounts_model_effect_journal
137
+ FOR EACH ROW EXECUTE FUNCTION infinity.capture_authority_mutation_change();
@@ -0,0 +1,17 @@
1
+ CREATE TABLE IF NOT EXISTS infinity_manifest_signing_trust_current (
2
+ trust_anchor_sha256 text PRIMARY KEY CHECK (trust_anchor_sha256 ~ '^sha256:[0-9a-f]{64}$'),
3
+ head_sequence numeric(19, 0) NOT NULL CHECK (head_sequence > 0 AND head_sequence <= 9223372036854775807),
4
+ observation_sequence numeric(19, 0) NOT NULL UNIQUE CHECK (observation_sequence > 0 AND observation_sequence <= 9223372036854775807),
5
+ head_canonical_json text NOT NULL,
6
+ updated_at timestamptz NOT NULL DEFAULT clock_timestamp()
7
+ );
8
+
9
+ CREATE TABLE IF NOT EXISTS infinity_verification_final_trust_authorizations (
10
+ signed_receipt_sha256 text PRIMARY KEY CHECK (signed_receipt_sha256 ~ '^sha256:[0-9a-f]{64}$'),
11
+ manifest_signing_key_id text NOT NULL,
12
+ trust_anchor_sha256 text NOT NULL REFERENCES infinity_manifest_signing_trust_current(trust_anchor_sha256) ON DELETE RESTRICT,
13
+ signing_trust_head_sha256 text NOT NULL CHECK (signing_trust_head_sha256 ~ '^sha256:[0-9a-f]{64}$'),
14
+ authorization_canonical_json text NOT NULL,
15
+ authorized_at timestamptz NOT NULL,
16
+ created_at timestamptz NOT NULL DEFAULT clock_timestamp()
17
+ );
@@ -0,0 +1,169 @@
1
+ CREATE TABLE IF NOT EXISTS infinity_verifier_cleanup_grants (
2
+ grant_sha256 text PRIMARY KEY CHECK (grant_sha256 ~ '^sha256:[0-9a-f]{64}$'),
3
+ grant_request_sha256 text NOT NULL CHECK (grant_request_sha256 ~ '^sha256:[0-9a-f]{64}$'),
4
+ supersedes_grant_sha256 text UNIQUE REFERENCES infinity_verifier_cleanup_grants(grant_sha256) ON DELETE RESTRICT,
5
+ cleanup_nonce text NOT NULL UNIQUE,
6
+ consumption_transaction_id text NOT NULL UNIQUE,
7
+ verification_operation_id text NOT NULL,
8
+ cleanup_operation_id text NOT NULL UNIQUE REFERENCES infinity_broker_operations(operation_id) ON DELETE RESTRICT,
9
+ resource_id text NOT NULL,
10
+ resource_lease_id text NOT NULL,
11
+ resource_generation_before numeric(19, 0) NOT NULL CHECK (
12
+ resource_generation_before > 0 AND resource_generation_before <= 9223372036854775807
13
+ ),
14
+ resource_generation_after numeric(19, 0) NOT NULL CHECK (
15
+ resource_generation_after > 0 AND resource_generation_after <= 9223372036854775807
16
+ ),
17
+ grant_canonical_json text NOT NULL,
18
+ issued_at timestamptz NOT NULL,
19
+ expires_at timestamptz NOT NULL,
20
+ created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
21
+ CHECK (resource_generation_after = resource_generation_before + 1),
22
+ CHECK (issued_at < expires_at)
23
+ );
24
+
25
+ CREATE INDEX IF NOT EXISTS infinity_verifier_cleanup_grants_request_idx
26
+ ON infinity_verifier_cleanup_grants (grant_request_sha256, issued_at DESC);
27
+
28
+ CREATE TABLE IF NOT EXISTS infinity_verifier_cleanup_resource_heads (
29
+ resource_id text PRIMARY KEY,
30
+ resource_lease_id text NOT NULL,
31
+ resource_generation numeric(19, 0) NOT NULL CHECK (
32
+ resource_generation > 0 AND resource_generation <= 9223372036854775807
33
+ ),
34
+ current_fence_canonical_json text NOT NULL,
35
+ advanced_by_cleanup_operation_id text UNIQUE REFERENCES infinity_broker_operations(operation_id) ON DELETE RESTRICT,
36
+ updated_at timestamptz NOT NULL
37
+ );
38
+
39
+ CREATE TABLE IF NOT EXISTS infinity_verifier_cleanup_consumptions (
40
+ consumption_transaction_id text PRIMARY KEY,
41
+ cleanup_nonce text NOT NULL UNIQUE,
42
+ grant_sha256 text NOT NULL UNIQUE REFERENCES infinity_verifier_cleanup_grants(grant_sha256) ON DELETE RESTRICT,
43
+ verification_operation_id text NOT NULL,
44
+ cleanup_operation_id text NOT NULL UNIQUE REFERENCES infinity_broker_operations(operation_id) ON DELETE RESTRICT,
45
+ resource_id text NOT NULL,
46
+ resource_generation_before numeric(19, 0) NOT NULL CHECK (
47
+ resource_generation_before > 0 AND resource_generation_before <= 9223372036854775807
48
+ ),
49
+ resource_generation_after numeric(19, 0) NOT NULL CHECK (
50
+ resource_generation_after > 0 AND resource_generation_after <= 9223372036854775807
51
+ ),
52
+ sandboxes_receipt_sha256 text NOT NULL UNIQUE CHECK (sandboxes_receipt_sha256 ~ '^sha256:[0-9a-f]{64}$'),
53
+ receipt_canonical_json text NOT NULL,
54
+ receipt_bytes_sha256 text NOT NULL CHECK (receipt_bytes_sha256 ~ '^sha256:[0-9a-f]{64}$'),
55
+ commit_canonical_json text NOT NULL,
56
+ logical_cleanup_state text NOT NULL CHECK (logical_cleanup_state = 'committed'),
57
+ promotion_gate text NOT NULL CHECK (promotion_gate IN ('open', 'closed')),
58
+ authority_transaction_id text NOT NULL UNIQUE,
59
+ authority_event_id text NOT NULL UNIQUE,
60
+ committed_at timestamptz NOT NULL,
61
+ created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
62
+ UNIQUE (resource_id, resource_generation_before),
63
+ CHECK (resource_generation_after = resource_generation_before + 1)
64
+ );
65
+
66
+ CREATE INDEX IF NOT EXISTS infinity_verifier_cleanup_consumptions_resource_idx
67
+ ON infinity_verifier_cleanup_consumptions (resource_id, resource_generation_after DESC);
68
+
69
+ CREATE TABLE IF NOT EXISTS infinity_verifier_completion_preparations (
70
+ verification_operation_id text PRIMARY KEY,
71
+ handoff_sha256 text NOT NULL CHECK (handoff_sha256 ~ '^sha256:[0-9a-f]{64}$'),
72
+ completion_input_canonical_json text NOT NULL,
73
+ created_at timestamptz NOT NULL
74
+ );
75
+
76
+ CREATE TABLE IF NOT EXISTS infinity_verifier_passing_receipts (
77
+ verification_operation_id text PRIMARY KEY,
78
+ handoff_sha256 text NOT NULL CHECK (handoff_sha256 ~ '^sha256:[0-9a-f]{64}$'),
79
+ cleanup_consumption_transaction_id text NOT NULL UNIQUE REFERENCES infinity_verifier_cleanup_consumptions(consumption_transaction_id) ON DELETE RESTRICT,
80
+ cleanup_commit_sha256 text NOT NULL UNIQUE CHECK (cleanup_commit_sha256 ~ '^sha256:[0-9a-f]{64}$'),
81
+ receipt_sha256 text NOT NULL UNIQUE CHECK (receipt_sha256 ~ '^sha256:[0-9a-f]{64}$'),
82
+ receipt_canonical_json text NOT NULL,
83
+ created_at timestamptz NOT NULL
84
+ );
85
+
86
+ CREATE TABLE IF NOT EXISTS infinity_verifier_quarantine_receipts (
87
+ quarantine_receipt_sha256 text PRIMARY KEY CHECK (quarantine_receipt_sha256 ~ '^sha256:[0-9a-f]{64}$'),
88
+ verification_operation_id text NOT NULL,
89
+ quarantine_reason text NOT NULL CHECK (quarantine_reason IN ('invalid_allocation', 'cleanup_failure')),
90
+ resource_id text NOT NULL,
91
+ resource_lease_id text NOT NULL,
92
+ resource_generation numeric(19, 0) NOT NULL CHECK (
93
+ resource_generation > 0 AND resource_generation <= 9223372036854775807
94
+ ),
95
+ quarantine_subject_sha256 text NOT NULL CHECK (quarantine_subject_sha256 ~ '^sha256:[0-9a-f]{64}$'),
96
+ receipt_canonical_json text NOT NULL,
97
+ receipt_bytes_sha256 text NOT NULL CHECK (receipt_bytes_sha256 ~ '^sha256:[0-9a-f]{64}$'),
98
+ recorded_at timestamptz NOT NULL,
99
+ created_at timestamptz NOT NULL DEFAULT clock_timestamp()
100
+ );
101
+
102
+ CREATE OR REPLACE FUNCTION infinity_reject_verifier_cleanup_consumption_mutation()
103
+ RETURNS trigger
104
+ LANGUAGE plpgsql
105
+ AS $$
106
+ BEGIN
107
+ RAISE EXCEPTION 'infinity verifier cleanup consumptions are append-only';
108
+ END;
109
+ $$;
110
+
111
+ DROP TRIGGER IF EXISTS infinity_verifier_cleanup_consumptions_append_only
112
+ ON infinity_verifier_cleanup_consumptions;
113
+ CREATE TRIGGER infinity_verifier_cleanup_consumptions_append_only
114
+ BEFORE UPDATE OR DELETE ON infinity_verifier_cleanup_consumptions
115
+ FOR EACH ROW EXECUTE FUNCTION infinity_reject_verifier_cleanup_consumption_mutation();
116
+
117
+ DROP TRIGGER IF EXISTS infinity_verifier_cleanup_grants_append_only
118
+ ON infinity_verifier_cleanup_grants;
119
+ CREATE TRIGGER infinity_verifier_cleanup_grants_append_only
120
+ BEFORE UPDATE OR DELETE ON infinity_verifier_cleanup_grants
121
+ FOR EACH ROW EXECUTE FUNCTION infinity_reject_verifier_cleanup_consumption_mutation();
122
+
123
+ DROP TRIGGER IF EXISTS infinity_verifier_quarantine_receipts_append_only
124
+ ON infinity_verifier_quarantine_receipts;
125
+ CREATE TRIGGER infinity_verifier_quarantine_receipts_append_only
126
+ BEFORE UPDATE OR DELETE ON infinity_verifier_quarantine_receipts
127
+ FOR EACH ROW EXECUTE FUNCTION infinity_reject_verifier_cleanup_consumption_mutation();
128
+
129
+ DROP TRIGGER IF EXISTS infinity_verifier_passing_receipts_append_only
130
+ ON infinity_verifier_passing_receipts;
131
+ CREATE TRIGGER infinity_verifier_passing_receipts_append_only
132
+ BEFORE UPDATE OR DELETE ON infinity_verifier_passing_receipts
133
+ FOR EACH ROW EXECUTE FUNCTION infinity_reject_verifier_cleanup_consumption_mutation();
134
+
135
+ DROP TRIGGER IF EXISTS infinity_verifier_completion_preparations_append_only
136
+ ON infinity_verifier_completion_preparations;
137
+ CREATE TRIGGER infinity_verifier_completion_preparations_append_only
138
+ BEFORE UPDATE OR DELETE ON infinity_verifier_completion_preparations
139
+ FOR EACH ROW EXECUTE FUNCTION infinity_reject_verifier_cleanup_consumption_mutation();
140
+
141
+ DROP TRIGGER IF EXISTS infinity_verifier_cleanup_consumptions_no_truncate
142
+ ON infinity_verifier_cleanup_consumptions;
143
+ CREATE TRIGGER infinity_verifier_cleanup_consumptions_no_truncate
144
+ BEFORE TRUNCATE ON infinity_verifier_cleanup_consumptions
145
+ FOR EACH STATEMENT EXECUTE FUNCTION infinity_reject_verifier_cleanup_consumption_mutation();
146
+
147
+ DROP TRIGGER IF EXISTS infinity_verifier_cleanup_grants_no_truncate
148
+ ON infinity_verifier_cleanup_grants;
149
+ CREATE TRIGGER infinity_verifier_cleanup_grants_no_truncate
150
+ BEFORE TRUNCATE ON infinity_verifier_cleanup_grants
151
+ FOR EACH STATEMENT EXECUTE FUNCTION infinity_reject_verifier_cleanup_consumption_mutation();
152
+
153
+ DROP TRIGGER IF EXISTS infinity_verifier_quarantine_receipts_no_truncate
154
+ ON infinity_verifier_quarantine_receipts;
155
+ CREATE TRIGGER infinity_verifier_quarantine_receipts_no_truncate
156
+ BEFORE TRUNCATE ON infinity_verifier_quarantine_receipts
157
+ FOR EACH STATEMENT EXECUTE FUNCTION infinity_reject_verifier_cleanup_consumption_mutation();
158
+
159
+ DROP TRIGGER IF EXISTS infinity_verifier_passing_receipts_no_truncate
160
+ ON infinity_verifier_passing_receipts;
161
+ CREATE TRIGGER infinity_verifier_passing_receipts_no_truncate
162
+ BEFORE TRUNCATE ON infinity_verifier_passing_receipts
163
+ FOR EACH STATEMENT EXECUTE FUNCTION infinity_reject_verifier_cleanup_consumption_mutation();
164
+
165
+ DROP TRIGGER IF EXISTS infinity_verifier_completion_preparations_no_truncate
166
+ ON infinity_verifier_completion_preparations;
167
+ CREATE TRIGGER infinity_verifier_completion_preparations_no_truncate
168
+ BEFORE TRUNCATE ON infinity_verifier_completion_preparations
169
+ FOR EACH STATEMENT EXECUTE FUNCTION infinity_reject_verifier_cleanup_consumption_mutation();