@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,172 @@
1
+ -- Normalize Accounts claim authority around one serialization domain with many
2
+ -- resource-lease children. The v1 raw-projection installer was never a trusted
3
+ -- production input, so populated v1 state must be explicitly re-attested rather
4
+ -- than silently upgraded into authoritative claim evidence.
5
+
6
+ DO $$
7
+ BEGIN
8
+ IF EXISTS (SELECT 1 FROM infinity.accounts_resource_authority LIMIT 1)
9
+ OR EXISTS (SELECT 1 FROM infinity.accounts_serialization_domains LIMIT 1) THEN
10
+ RAISE EXCEPTION 'accounts v1 projection state requires explicit re-attestation before v2 migration'
11
+ USING ERRCODE = '55000';
12
+ END IF;
13
+ END;
14
+ $$;
15
+
16
+ ALTER TABLE infinity.accounts_serialization_domains
17
+ DROP CONSTRAINT IF EXISTS accounts_serialization_domains_resource_lease_id_key,
18
+ DROP COLUMN resource_lease_id,
19
+ ADD COLUMN resource_id text NOT NULL,
20
+ ADD COLUMN resource_lifecycle_generation bigint NOT NULL
21
+ CHECK (resource_lifecycle_generation > 0),
22
+ ADD CONSTRAINT accounts_serialization_domains_resource_identity_key
23
+ UNIQUE (resource_id, resource_lifecycle_generation);
24
+
25
+ ALTER TABLE infinity.accounts_resource_authority
26
+ DROP CONSTRAINT IF EXISTS accounts_resource_authority_effect_namespace_id_serialization_key_digest_key,
27
+ DROP CONSTRAINT IF EXISTS accounts_resource_authority_effect_namespace_id_serializati_key,
28
+ ADD COLUMN domain_key text NOT NULL
29
+ REFERENCES infinity.accounts_serialization_domains(domain_key) DEFERRABLE INITIALLY DEFERRED,
30
+ ADD COLUMN authority_epoch bigint NOT NULL CHECK (authority_epoch > 0),
31
+ ADD COLUMN provider_account_id text NOT NULL,
32
+ ADD COLUMN owner_ref text NOT NULL,
33
+ ADD COLUMN account_lane_id text NOT NULL,
34
+ ADD COLUMN capacity_pool_id text NOT NULL,
35
+ ADD COLUMN capacity_domain_ref text NOT NULL,
36
+ ADD COLUMN credential_family_id text NOT NULL,
37
+ ADD COLUMN serialization_key text NOT NULL,
38
+ ADD COLUMN route_epoch bigint NOT NULL CHECK (route_epoch > 0),
39
+ ADD COLUMN acquisition_operation_id text NOT NULL,
40
+ ADD COLUMN slot_eligibility_request_digest text NOT NULL
41
+ CHECK (slot_eligibility_request_digest ~ '^sha256:[0-9a-f]{64}$'),
42
+ ADD COLUMN slot_eligibility_id text NOT NULL,
43
+ ADD COLUMN slot_eligibility_digest text NOT NULL
44
+ CHECK (slot_eligibility_digest ~ '^sha256:[0-9a-f]{64}$'),
45
+ ADD COLUMN slot_eligibility_jcs_base64url text NOT NULL,
46
+ ADD COLUMN slot_eligibility_record text NOT NULL,
47
+ ADD COLUMN access_target_digest text NOT NULL
48
+ CHECK (access_target_digest ~ '^sha256:[0-9a-f]{64}$'),
49
+ ADD COLUMN slot_id text NOT NULL,
50
+ ADD COLUMN slot_index bigint NOT NULL CHECK (slot_index >= 0),
51
+ ADD COLUMN capacity_generation bigint NOT NULL CHECK (capacity_generation > 0),
52
+ ADD COLUMN deny_generation bigint NOT NULL CHECK (deny_generation >= 0),
53
+ ADD COLUMN credential_generation bigint NOT NULL CHECK (credential_generation >= 0),
54
+ ADD COLUMN max_concurrency bigint NOT NULL CHECK (max_concurrency > 0),
55
+ ADD COLUMN state text NOT NULL CHECK (state IN ('reserved','released','fenced')),
56
+ ADD COLUMN lease_projection_digest text NOT NULL
57
+ CHECK (lease_projection_digest ~ '^sha256:[0-9a-f]{64}$'),
58
+ ADD COLUMN lease_projection_jcs_base64url text NOT NULL,
59
+ ADD COLUMN lease_projection_record text NOT NULL,
60
+ ADD COLUMN updated_at timestamptz NOT NULL,
61
+ ADD CONSTRAINT accounts_resource_authority_domain_lease_key
62
+ UNIQUE (domain_key, resource_lease_id),
63
+ ADD CONSTRAINT accounts_resource_authority_attempt_key
64
+ UNIQUE (attempt_id, resource_lease_id);
65
+
66
+ CREATE UNIQUE INDEX accounts_resource_authority_live_slot_key
67
+ ON infinity.accounts_resource_authority(account_lane_id, capacity_generation, slot_index)
68
+ WHERE state = 'reserved';
69
+
70
+ ALTER TABLE infinity.accounts_model_call_operations
71
+ DROP CONSTRAINT accounts_model_call_operations_state_check,
72
+ DROP CONSTRAINT IF EXISTS accounts_model_call_operations_check,
73
+ DROP CONSTRAINT IF EXISTS accounts_model_call_operations_check1,
74
+ ADD CONSTRAINT accounts_model_call_operations_state_check
75
+ CHECK (state IN ('PREPARED','CONSUME_BOUND','INVALIDATED')),
76
+ ADD CONSTRAINT accounts_model_call_operations_evidence_check
77
+ CHECK (((state = 'PREPARED' OR state = 'INVALIDATED')
78
+ AND consume_receipt_digest IS NULL AND use_id IS NULL)
79
+ OR (state = 'CONSUME_BOUND' AND consume_receipt_digest IS NOT NULL AND use_id IS NOT NULL)),
80
+ ADD COLUMN resource_lease_id text NOT NULL
81
+ REFERENCES infinity.accounts_resource_authority(resource_lease_id)
82
+ DEFERRABLE INITIALLY DEFERRED;
83
+
84
+ CREATE OR REPLACE FUNCTION infinity.validate_accounts_resource_authority_update() RETURNS trigger
85
+ LANGUAGE plpgsql AS $$
86
+ BEGIN
87
+ IF TG_OP = 'DELETE' THEN
88
+ RAISE EXCEPTION 'accounts resource authority evidence is append-only and cannot be deleted'
89
+ USING ERRCODE = '23514';
90
+ END IF;
91
+ IF NEW.resource_lease_id IS DISTINCT FROM OLD.resource_lease_id
92
+ OR NEW.domain_key IS DISTINCT FROM OLD.domain_key
93
+ OR NEW.effect_namespace_id IS DISTINCT FROM OLD.effect_namespace_id
94
+ OR NEW.serialization_key_digest IS DISTINCT FROM OLD.serialization_key_digest
95
+ OR NEW.resource_id IS DISTINCT FROM OLD.resource_id
96
+ OR NEW.resource_lifecycle_generation IS DISTINCT FROM OLD.resource_lifecycle_generation
97
+ OR NEW.authority_epoch IS DISTINCT FROM OLD.authority_epoch
98
+ OR NEW.provider_account_id IS DISTINCT FROM OLD.provider_account_id
99
+ OR NEW.owner_ref IS DISTINCT FROM OLD.owner_ref
100
+ OR NEW.account_lane_id IS DISTINCT FROM OLD.account_lane_id
101
+ OR NEW.capacity_pool_id IS DISTINCT FROM OLD.capacity_pool_id
102
+ OR NEW.capacity_domain_ref IS DISTINCT FROM OLD.capacity_domain_ref
103
+ OR NEW.credential_family_id IS DISTINCT FROM OLD.credential_family_id
104
+ OR NEW.serialization_key IS DISTINCT FROM OLD.serialization_key
105
+ OR NEW.run_id IS DISTINCT FROM OLD.run_id
106
+ OR NEW.attempt_id IS DISTINCT FROM OLD.attempt_id
107
+ OR NEW.attempt_lease_id IS DISTINCT FROM OLD.attempt_lease_id
108
+ OR NEW.lease_epoch IS DISTINCT FROM OLD.lease_epoch
109
+ OR NEW.route_epoch IS DISTINCT FROM OLD.route_epoch
110
+ OR NEW.acquisition_operation_id IS DISTINCT FROM OLD.acquisition_operation_id
111
+ OR NEW.slot_eligibility_request_digest IS DISTINCT FROM OLD.slot_eligibility_request_digest
112
+ OR NEW.slot_eligibility_id IS DISTINCT FROM OLD.slot_eligibility_id
113
+ OR NEW.slot_eligibility_digest IS DISTINCT FROM OLD.slot_eligibility_digest
114
+ OR NEW.slot_eligibility_jcs_base64url IS DISTINCT FROM OLD.slot_eligibility_jcs_base64url
115
+ OR NEW.slot_eligibility_record IS DISTINCT FROM OLD.slot_eligibility_record
116
+ OR NEW.access_target_digest IS DISTINCT FROM OLD.access_target_digest
117
+ OR NEW.slot_id IS DISTINCT FROM OLD.slot_id
118
+ OR NEW.slot_index IS DISTINCT FROM OLD.slot_index
119
+ OR NEW.capacity_generation IS DISTINCT FROM OLD.capacity_generation
120
+ OR NEW.deny_generation IS DISTINCT FROM OLD.deny_generation
121
+ OR NEW.credential_generation IS DISTINCT FROM OLD.credential_generation
122
+ OR NEW.max_concurrency IS DISTINCT FROM OLD.max_concurrency
123
+ OR NEW.projection_digest IS DISTINCT FROM OLD.projection_digest
124
+ OR NEW.projection_record IS DISTINCT FROM OLD.projection_record
125
+ OR NEW.lease_projection_digest IS DISTINCT FROM OLD.lease_projection_digest
126
+ OR NEW.lease_projection_jcs_base64url IS DISTINCT FROM OLD.lease_projection_jcs_base64url
127
+ OR NEW.lease_projection_record IS DISTINCT FROM OLD.lease_projection_record
128
+ OR NEW.installed_at IS DISTINCT FROM OLD.installed_at
129
+ OR NEW.updated_at <= OLD.updated_at
130
+ OR NOT (OLD.state = 'reserved' AND NEW.state IN ('released','fenced')) THEN
131
+ RAISE EXCEPTION 'accounts resource authority update mutates immutable evidence or is a no-op'
132
+ USING ERRCODE = '23514';
133
+ END IF;
134
+ RETURN NEW;
135
+ END;
136
+ $$;
137
+
138
+ CREATE OR REPLACE FUNCTION infinity.validate_accounts_operation_signer_pin_update() RETURNS trigger
139
+ LANGUAGE plpgsql AS $$
140
+ BEGIN
141
+ IF TG_OP = 'DELETE' THEN
142
+ RAISE EXCEPTION 'accounts signer-history pin is append-only and cannot be deleted'
143
+ USING ERRCODE = '23514';
144
+ END IF;
145
+ IF NEW.trust_anchor_digest IS DISTINCT FROM OLD.trust_anchor_digest
146
+ OR NEW.head_sequence < OLD.head_sequence
147
+ OR (NEW.head_sequence = OLD.head_sequence AND (
148
+ NEW.head_digest IS DISTINCT FROM OLD.head_digest
149
+ OR NEW.pin_digest IS DISTINCT FROM OLD.pin_digest
150
+ OR NEW.pin_record IS DISTINCT FROM OLD.pin_record
151
+ )) THEN
152
+ RAISE EXCEPTION 'accounts signer-history pin update rewinds or equivocates'
153
+ USING ERRCODE = '23514';
154
+ END IF;
155
+ RETURN NEW;
156
+ END;
157
+ $$;
158
+
159
+ DROP TRIGGER accounts_resource_authority_immutable ON infinity.accounts_resource_authority;
160
+ CREATE TRIGGER accounts_resource_authority_update_guard
161
+ BEFORE UPDATE OR DELETE ON infinity.accounts_resource_authority
162
+ FOR EACH ROW EXECUTE FUNCTION infinity.validate_accounts_resource_authority_update();
163
+
164
+ DROP TRIGGER accounts_resource_authority_mutation_capture ON infinity.accounts_resource_authority;
165
+ CREATE TRIGGER accounts_resource_authority_mutation_capture
166
+ AFTER INSERT OR UPDATE ON infinity.accounts_resource_authority
167
+ FOR EACH ROW EXECUTE FUNCTION infinity.capture_authority_mutation_change();
168
+
169
+ DROP TRIGGER accounts_operation_signer_pin_update_guard ON infinity.accounts_operation_signer_pin;
170
+ CREATE TRIGGER accounts_operation_signer_pin_update_guard
171
+ BEFORE UPDATE OR DELETE ON infinity.accounts_operation_signer_pin
172
+ FOR EACH ROW EXECUTE FUNCTION infinity.validate_accounts_operation_signer_pin_update();
@@ -0,0 +1,143 @@
1
+ -- Durable, signed, one-use sandbox dispatch authority. Authorization and
2
+ -- consumption receipts retain exact canonical bytes and every state change is
3
+ -- reconstructed through the external authority mutation journal.
4
+
5
+ CREATE TABLE infinity.sandbox_dispatch_accounts_consume_evidence (
6
+ model_operation_id text PRIMARY KEY
7
+ REFERENCES infinity.accounts_model_call_operations(operation_id),
8
+ bind_operation_id text NOT NULL UNIQUE,
9
+ bind_idempotency_key text NOT NULL,
10
+ consume_receipt_digest text NOT NULL UNIQUE
11
+ CHECK (consume_receipt_digest ~ '^sha256:[0-9a-f]{64}$'),
12
+ consume_tombstone_digest text NOT NULL UNIQUE
13
+ CHECK (consume_tombstone_digest ~ '^sha256:[0-9a-f]{64}$'),
14
+ consume_use_id text NOT NULL UNIQUE
15
+ CHECK (consume_use_id ~ '^sha256:[0-9a-f]{64}$'),
16
+ consume_binding_digest text NOT NULL UNIQUE
17
+ CHECK (consume_binding_digest ~ '^sha256:[0-9a-f]{64}$'),
18
+ evidence_request_digest text NOT NULL UNIQUE
19
+ CHECK (evidence_request_digest ~ '^sha256:[0-9a-f]{64}$'),
20
+ evidence_digest text NOT NULL UNIQUE
21
+ CHECK (evidence_digest ~ '^sha256:[0-9a-f]{64}$'),
22
+ evidence_record text NOT NULL,
23
+ recorded_at timestamptz NOT NULL
24
+ );
25
+
26
+ CREATE TRIGGER sandbox_dispatch_accounts_consume_evidence_immutable
27
+ BEFORE UPDATE OR DELETE ON infinity.sandbox_dispatch_accounts_consume_evidence
28
+ FOR EACH ROW EXECUTE FUNCTION infinity.reject_immutable_mutation();
29
+
30
+ CREATE TRIGGER sandbox_dispatch_accounts_consume_evidence_mutation_capture
31
+ AFTER INSERT ON infinity.sandbox_dispatch_accounts_consume_evidence
32
+ FOR EACH ROW EXECUTE FUNCTION infinity.capture_authority_mutation_change();
33
+
34
+ CREATE TABLE infinity.sandbox_dispatch_authorizations (
35
+ dispatch_id text PRIMARY KEY,
36
+ mint_operation_id text NOT NULL UNIQUE,
37
+ mint_idempotency_key text NOT NULL,
38
+ run_id text NOT NULL REFERENCES infinity.runs(id),
39
+ attempt_id text NOT NULL REFERENCES infinity.attempts(id),
40
+ attempt_lease_id text NOT NULL,
41
+ lease_epoch bigint NOT NULL CHECK (lease_epoch > 0),
42
+ account_lane_id text NOT NULL,
43
+ model_operation_id text NOT NULL
44
+ REFERENCES infinity.accounts_model_call_operations(operation_id),
45
+ authority_epoch bigint NOT NULL CHECK (authority_epoch > 0),
46
+ audience text NOT NULL,
47
+ authorization_request_digest text NOT NULL UNIQUE
48
+ CHECK (authorization_request_digest ~ '^sha256:[0-9a-f]{64}$'),
49
+ authorization_digest text NOT NULL UNIQUE
50
+ CHECK (authorization_digest ~ '^sha256:[0-9a-f]{64}$'),
51
+ authorization_record text NOT NULL,
52
+ state text NOT NULL CHECK (state IN ('AVAILABLE','CONSUMED')),
53
+ consume_operation_id text UNIQUE,
54
+ consume_idempotency_key text,
55
+ consume_request_digest text UNIQUE
56
+ CHECK (consume_request_digest IS NULL OR consume_request_digest ~ '^sha256:[0-9a-f]{64}$'),
57
+ effect_claim_digest text UNIQUE
58
+ CHECK (effect_claim_digest IS NULL OR effect_claim_digest ~ '^sha256:[0-9a-f]{64}$'),
59
+ sandbox_request_digest text UNIQUE
60
+ CHECK (sandbox_request_digest IS NULL OR sandbox_request_digest ~ '^sha256:[0-9a-f]{64}$'),
61
+ dispatch_use_id text UNIQUE
62
+ CHECK (dispatch_use_id IS NULL OR dispatch_use_id ~ '^sha256:[0-9a-f]{64}$'),
63
+ consumption_receipt_digest text UNIQUE
64
+ CHECK (consumption_receipt_digest IS NULL OR consumption_receipt_digest ~ '^sha256:[0-9a-f]{64}$'),
65
+ consumption_receipt_record text,
66
+ issued_at timestamptz NOT NULL,
67
+ expires_at timestamptz NOT NULL CHECK (expires_at > issued_at),
68
+ consumed_at timestamptz,
69
+ provider_contact_expires_at timestamptz,
70
+ updated_at timestamptz NOT NULL CHECK (updated_at >= issued_at),
71
+ FOREIGN KEY (attempt_lease_id, attempt_id, lease_epoch)
72
+ REFERENCES infinity.attempt_lease_grants(attempt_lease_id, attempt_id, lease_epoch),
73
+ FOREIGN KEY (model_operation_id)
74
+ REFERENCES infinity.sandbox_dispatch_accounts_consume_evidence(model_operation_id),
75
+ CHECK (
76
+ (state = 'AVAILABLE'
77
+ AND consume_operation_id IS NULL
78
+ AND consume_idempotency_key IS NULL
79
+ AND consume_request_digest IS NULL
80
+ AND effect_claim_digest IS NULL
81
+ AND sandbox_request_digest IS NULL
82
+ AND dispatch_use_id IS NULL
83
+ AND consumption_receipt_digest IS NULL
84
+ AND consumption_receipt_record IS NULL
85
+ AND consumed_at IS NULL
86
+ AND provider_contact_expires_at IS NULL)
87
+ OR
88
+ (state = 'CONSUMED'
89
+ AND consume_operation_id IS NOT NULL
90
+ AND consume_idempotency_key IS NOT NULL
91
+ AND consume_request_digest IS NOT NULL
92
+ AND effect_claim_digest IS NOT NULL
93
+ AND sandbox_request_digest IS NOT NULL
94
+ AND dispatch_use_id IS NOT NULL
95
+ AND consumption_receipt_digest IS NOT NULL
96
+ AND consumption_receipt_record IS NOT NULL
97
+ AND consumed_at IS NOT NULL
98
+ AND provider_contact_expires_at IS NOT NULL
99
+ AND provider_contact_expires_at > consumed_at
100
+ AND provider_contact_expires_at <= expires_at)
101
+ )
102
+ );
103
+
104
+ CREATE OR REPLACE FUNCTION infinity.validate_sandbox_dispatch_authorization_update() RETURNS trigger
105
+ LANGUAGE plpgsql AS $$
106
+ BEGIN
107
+ IF TG_OP = 'DELETE' THEN
108
+ RAISE EXCEPTION 'sandbox dispatch authority records cannot be deleted'
109
+ USING ERRCODE = '23514';
110
+ END IF;
111
+ IF OLD.state IS DISTINCT FROM 'AVAILABLE'
112
+ OR NEW.state IS DISTINCT FROM 'CONSUMED'
113
+ OR NEW.dispatch_id IS DISTINCT FROM OLD.dispatch_id
114
+ OR NEW.mint_operation_id IS DISTINCT FROM OLD.mint_operation_id
115
+ OR NEW.mint_idempotency_key IS DISTINCT FROM OLD.mint_idempotency_key
116
+ OR NEW.run_id IS DISTINCT FROM OLD.run_id
117
+ OR NEW.attempt_id IS DISTINCT FROM OLD.attempt_id
118
+ OR NEW.attempt_lease_id IS DISTINCT FROM OLD.attempt_lease_id
119
+ OR NEW.lease_epoch IS DISTINCT FROM OLD.lease_epoch
120
+ OR NEW.account_lane_id IS DISTINCT FROM OLD.account_lane_id
121
+ OR NEW.model_operation_id IS DISTINCT FROM OLD.model_operation_id
122
+ OR NEW.authority_epoch IS DISTINCT FROM OLD.authority_epoch
123
+ OR NEW.audience IS DISTINCT FROM OLD.audience
124
+ OR NEW.authorization_request_digest IS DISTINCT FROM OLD.authorization_request_digest
125
+ OR NEW.authorization_digest IS DISTINCT FROM OLD.authorization_digest
126
+ OR NEW.authorization_record IS DISTINCT FROM OLD.authorization_record
127
+ OR NEW.issued_at IS DISTINCT FROM OLD.issued_at
128
+ OR NEW.expires_at IS DISTINCT FROM OLD.expires_at
129
+ OR NEW.updated_at < OLD.updated_at THEN
130
+ RAISE EXCEPTION 'sandbox dispatch update mutates immutable authority or is not one-use'
131
+ USING ERRCODE = '23514';
132
+ END IF;
133
+ RETURN NEW;
134
+ END;
135
+ $$;
136
+
137
+ CREATE TRIGGER sandbox_dispatch_authorization_update_guard
138
+ BEFORE UPDATE OR DELETE ON infinity.sandbox_dispatch_authorizations
139
+ FOR EACH ROW EXECUTE FUNCTION infinity.validate_sandbox_dispatch_authorization_update();
140
+
141
+ CREATE TRIGGER sandbox_dispatch_authorization_mutation_capture
142
+ AFTER INSERT OR UPDATE ON infinity.sandbox_dispatch_authorizations
143
+ FOR EACH ROW EXECUTE FUNCTION infinity.capture_authority_mutation_change();
@@ -0,0 +1,58 @@
1
+ -- V2 makes the Sandboxes PREPARED tuple an immutable part of the signed
2
+ -- Infinity authorization and permits exactly one dispatch authorization for
3
+ -- each durable Accounts CONSUME_BOUND operation. Existing V1 rows cannot be
4
+ -- reinterpreted as V2 because they never signed these fields.
5
+
6
+ DO $$
7
+ BEGIN
8
+ IF EXISTS (SELECT 1 FROM infinity.sandbox_dispatch_authorizations) THEN
9
+ RAISE EXCEPTION 'sandbox dispatch V1 authorization rows cannot be reinterpreted as V2'
10
+ USING ERRCODE = '23514';
11
+ END IF;
12
+ END;
13
+ $$;
14
+
15
+ ALTER TABLE infinity.sandbox_dispatch_authorizations
16
+ RENAME COLUMN sandbox_request_digest TO canonical_intent_digest;
17
+
18
+ ALTER TABLE infinity.sandbox_dispatch_authorizations
19
+ ADD COLUMN authorized_effect_claim_digest text NOT NULL
20
+ UNIQUE CHECK (authorized_effect_claim_digest ~ '^sha256:[0-9a-f]{64}$'),
21
+ ADD COLUMN sandbox_prepare_anchor_digest text NOT NULL
22
+ UNIQUE CHECK (sandbox_prepare_anchor_digest ~ '^sha256:[0-9a-f]{64}$'),
23
+ ADD CONSTRAINT sandbox_dispatch_model_operation_unique UNIQUE (model_operation_id);
24
+
25
+ CREATE OR REPLACE FUNCTION infinity.validate_sandbox_dispatch_authorization_update() RETURNS trigger
26
+ LANGUAGE plpgsql AS $$
27
+ BEGIN
28
+ IF TG_OP = 'DELETE' THEN
29
+ RAISE EXCEPTION 'sandbox dispatch authority records cannot be deleted'
30
+ USING ERRCODE = '23514';
31
+ END IF;
32
+ IF OLD.state IS DISTINCT FROM 'AVAILABLE'
33
+ OR NEW.state IS DISTINCT FROM 'CONSUMED'
34
+ OR NEW.dispatch_id IS DISTINCT FROM OLD.dispatch_id
35
+ OR NEW.mint_operation_id IS DISTINCT FROM OLD.mint_operation_id
36
+ OR NEW.mint_idempotency_key IS DISTINCT FROM OLD.mint_idempotency_key
37
+ OR NEW.run_id IS DISTINCT FROM OLD.run_id
38
+ OR NEW.attempt_id IS DISTINCT FROM OLD.attempt_id
39
+ OR NEW.attempt_lease_id IS DISTINCT FROM OLD.attempt_lease_id
40
+ OR NEW.lease_epoch IS DISTINCT FROM OLD.lease_epoch
41
+ OR NEW.account_lane_id IS DISTINCT FROM OLD.account_lane_id
42
+ OR NEW.model_operation_id IS DISTINCT FROM OLD.model_operation_id
43
+ OR NEW.authority_epoch IS DISTINCT FROM OLD.authority_epoch
44
+ OR NEW.audience IS DISTINCT FROM OLD.audience
45
+ OR NEW.authorized_effect_claim_digest IS DISTINCT FROM OLD.authorized_effect_claim_digest
46
+ OR NEW.sandbox_prepare_anchor_digest IS DISTINCT FROM OLD.sandbox_prepare_anchor_digest
47
+ OR NEW.authorization_request_digest IS DISTINCT FROM OLD.authorization_request_digest
48
+ OR NEW.authorization_digest IS DISTINCT FROM OLD.authorization_digest
49
+ OR NEW.authorization_record IS DISTINCT FROM OLD.authorization_record
50
+ OR NEW.issued_at IS DISTINCT FROM OLD.issued_at
51
+ OR NEW.expires_at IS DISTINCT FROM OLD.expires_at
52
+ OR NEW.updated_at < OLD.updated_at THEN
53
+ RAISE EXCEPTION 'sandbox dispatch update mutates immutable V2 authority or is not one-use'
54
+ USING ERRCODE = '23514';
55
+ END IF;
56
+ RETURN NEW;
57
+ END;
58
+ $$;
@@ -0,0 +1,175 @@
1
+ CREATE SCHEMA IF NOT EXISTS infinity_external_journal;
2
+
3
+ REVOKE ALL ON SCHEMA infinity_external_journal FROM PUBLIC;
4
+
5
+ CREATE TABLE infinity_external_journal.store (
6
+ singleton boolean PRIMARY KEY DEFAULT true CHECK (singleton),
7
+ protection_schema_version text NOT NULL,
8
+ configured_journal_id text NOT NULL,
9
+ journal_id text NOT NULL,
10
+ cluster_system_identifier text NOT NULL CHECK (cluster_system_identifier ~ '^[0-9]+$'),
11
+ database_name text NOT NULL,
12
+ restore_domain_id text NOT NULL,
13
+ encrypted_at_rest boolean NOT NULL CHECK (encrypted_at_rest),
14
+ durability text NOT NULL CHECK (durability = 'durable'),
15
+ signer_principal text NOT NULL,
16
+ signing_key_id text NOT NULL,
17
+ verification_key_digest text NOT NULL CHECK (verification_key_digest ~ '^sha256:[0-9a-f]{64}$'),
18
+ protection_digest text NOT NULL CHECK (protection_digest ~ '^sha256:[0-9a-f]{64}$'),
19
+ protection_record text NOT NULL,
20
+ head_sequence bigint NOT NULL DEFAULT 0 CHECK (head_sequence >= 0),
21
+ head_frontier_digest text CHECK (head_frontier_digest IS NULL OR head_frontier_digest ~ '^sha256:[0-9a-f]{64}$'),
22
+ CHECK ((head_sequence = 0 AND head_frontier_digest IS NULL)
23
+ OR (head_sequence > 0 AND head_frontier_digest IS NOT NULL))
24
+ );
25
+
26
+ CREATE TABLE infinity_external_journal.receipts (
27
+ journal_sequence bigint PRIMARY KEY CHECK (journal_sequence > 0),
28
+ prior_frontier_digest text CHECK (prior_frontier_digest IS NULL OR prior_frontier_digest ~ '^sha256:[0-9a-f]{64}$'),
29
+ record_digest text NOT NULL CHECK (record_digest ~ '^sha256:[0-9a-f]{64}$'),
30
+ frontier_digest text NOT NULL UNIQUE CHECK (frontier_digest ~ '^sha256:[0-9a-f]{64}$'),
31
+ envelope_record text NOT NULL,
32
+ envelope_digest text NOT NULL CHECK (envelope_digest ~ '^sha256:[0-9a-f]{64}$'),
33
+ acknowledgement_digest text NOT NULL CHECK (acknowledgement_digest ~ '^sha256:[0-9a-f]{64}$'),
34
+ receipt_digest text NOT NULL CHECK (receipt_digest ~ '^sha256:[0-9a-f]{64}$'),
35
+ receipt_record text NOT NULL
36
+ );
37
+
38
+ CREATE FUNCTION infinity_external_journal.reject_immutable_mutation()
39
+ RETURNS trigger LANGUAGE plpgsql AS $$
40
+ BEGIN
41
+ RAISE EXCEPTION 'external authority mutation journal rows are immutable';
42
+ END;
43
+ $$;
44
+
45
+ CREATE FUNCTION infinity_external_journal.guard_receipt_insert()
46
+ RETURNS trigger LANGUAGE plpgsql AS $$
47
+ DECLARE
48
+ current_head bigint;
49
+ current_frontier text;
50
+ BEGIN
51
+ SELECT head_sequence, head_frontier_digest
52
+ INTO current_head, current_frontier
53
+ FROM infinity_external_journal.store
54
+ WHERE singleton
55
+ FOR UPDATE;
56
+ IF NOT FOUND THEN
57
+ RAISE EXCEPTION 'external authority mutation journal protection is not initialized';
58
+ END IF;
59
+ IF NEW.journal_sequence <> current_head + 1 THEN
60
+ RAISE EXCEPTION 'external authority mutation journal insert is not contiguous';
61
+ END IF;
62
+ IF NEW.prior_frontier_digest IS DISTINCT FROM current_frontier THEN
63
+ RAISE EXCEPTION 'external authority mutation journal predecessor differs';
64
+ END IF;
65
+ RETURN NEW;
66
+ END;
67
+ $$;
68
+
69
+ CREATE FUNCTION infinity_external_journal.guard_store_update()
70
+ RETURNS trigger LANGUAGE plpgsql AS $$
71
+ BEGIN
72
+ IF ROW(
73
+ NEW.protection_schema_version, NEW.configured_journal_id, NEW.journal_id,
74
+ NEW.cluster_system_identifier, NEW.database_name, NEW.restore_domain_id,
75
+ NEW.encrypted_at_rest, NEW.durability, NEW.signer_principal,
76
+ NEW.signing_key_id, NEW.verification_key_digest,
77
+ NEW.protection_digest, NEW.protection_record
78
+ ) IS DISTINCT FROM ROW(
79
+ OLD.protection_schema_version, OLD.configured_journal_id, OLD.journal_id,
80
+ OLD.cluster_system_identifier, OLD.database_name, OLD.restore_domain_id,
81
+ OLD.encrypted_at_rest, OLD.durability, OLD.signer_principal,
82
+ OLD.signing_key_id, OLD.verification_key_digest,
83
+ OLD.protection_digest, OLD.protection_record
84
+ ) THEN
85
+ RAISE EXCEPTION 'external authority mutation journal protection is immutable';
86
+ END IF;
87
+ IF NEW.head_sequence <> OLD.head_sequence + 1 THEN
88
+ RAISE EXCEPTION 'external authority mutation journal head may only advance by one';
89
+ END IF;
90
+ IF NOT EXISTS (
91
+ SELECT 1 FROM infinity_external_journal.receipts
92
+ WHERE journal_sequence = NEW.head_sequence
93
+ AND frontier_digest = NEW.head_frontier_digest
94
+ ) THEN
95
+ RAISE EXCEPTION 'external authority mutation journal head is not backed by a receipt';
96
+ END IF;
97
+ RETURN NEW;
98
+ END;
99
+ $$;
100
+
101
+ CREATE FUNCTION infinity_external_journal.require_receipt_head_commit()
102
+ RETURNS trigger LANGUAGE plpgsql AS $$
103
+ BEGIN
104
+ IF NOT EXISTS (
105
+ SELECT 1 FROM infinity_external_journal.store
106
+ WHERE singleton
107
+ AND head_sequence = NEW.journal_sequence
108
+ AND head_frontier_digest = NEW.frontier_digest
109
+ ) THEN
110
+ RAISE EXCEPTION 'external authority mutation journal receipt was not atomically committed with its head';
111
+ END IF;
112
+ RETURN NULL;
113
+ END;
114
+ $$;
115
+
116
+ CREATE FUNCTION infinity_external_journal.append_receipt(
117
+ p_journal_sequence bigint,
118
+ p_prior_frontier_digest text,
119
+ p_record_digest text,
120
+ p_frontier_digest text,
121
+ p_envelope_record text,
122
+ p_envelope_digest text,
123
+ p_acknowledgement_digest text,
124
+ p_receipt_digest text,
125
+ p_receipt_record text
126
+ )
127
+ RETURNS void
128
+ LANGUAGE plpgsql
129
+ SECURITY DEFINER
130
+ SET search_path = pg_catalog
131
+ AS $$
132
+ BEGIN
133
+ INSERT INTO infinity_external_journal.receipts
134
+ (journal_sequence, prior_frontier_digest, record_digest, frontier_digest,
135
+ envelope_record, envelope_digest, acknowledgement_digest, receipt_digest,
136
+ receipt_record)
137
+ VALUES
138
+ (p_journal_sequence, p_prior_frontier_digest, p_record_digest, p_frontier_digest,
139
+ p_envelope_record, p_envelope_digest, p_acknowledgement_digest, p_receipt_digest,
140
+ p_receipt_record);
141
+
142
+ UPDATE infinity_external_journal.store
143
+ SET head_sequence = p_journal_sequence,
144
+ head_frontier_digest = p_frontier_digest
145
+ WHERE singleton;
146
+
147
+ IF NOT FOUND THEN
148
+ RAISE EXCEPTION 'external authority mutation journal protection is not initialized';
149
+ END IF;
150
+ END;
151
+ $$;
152
+
153
+ CREATE TRIGGER receipts_insert_guard
154
+ BEFORE INSERT ON infinity_external_journal.receipts
155
+ FOR EACH ROW EXECUTE FUNCTION infinity_external_journal.guard_receipt_insert();
156
+
157
+ CREATE TRIGGER receipts_immutable
158
+ BEFORE UPDATE OR DELETE ON infinity_external_journal.receipts
159
+ FOR EACH ROW EXECUTE FUNCTION infinity_external_journal.reject_immutable_mutation();
160
+
161
+ CREATE CONSTRAINT TRIGGER receipts_require_head_commit
162
+ AFTER INSERT ON infinity_external_journal.receipts
163
+ DEFERRABLE INITIALLY DEFERRED
164
+ FOR EACH ROW EXECUTE FUNCTION infinity_external_journal.require_receipt_head_commit();
165
+
166
+ CREATE TRIGGER store_update_guard
167
+ BEFORE UPDATE ON infinity_external_journal.store
168
+ FOR EACH ROW EXECUTE FUNCTION infinity_external_journal.guard_store_update();
169
+
170
+ CREATE TRIGGER store_delete_guard
171
+ BEFORE DELETE ON infinity_external_journal.store
172
+ FOR EACH ROW EXECUTE FUNCTION infinity_external_journal.reject_immutable_mutation();
173
+
174
+ REVOKE ALL ON ALL TABLES IN SCHEMA infinity_external_journal FROM PUBLIC;
175
+ REVOKE ALL ON ALL FUNCTIONS IN SCHEMA infinity_external_journal FROM PUBLIC;
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@hasna/infinity",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "Infinity V1 reference Run Authority",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/hasna/infinity.git"
9
+ },
10
+ "main": "dist/index.js",
11
+ "types": "dist/types/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/types/index.d.ts",
15
+ "import": "./dist/index.js"
16
+ }
17
+ },
18
+ "bin": {
19
+ "infinity": "dist/cli.js",
20
+ "infinity-api": "dist/http-api.js",
21
+ "infinity-self-hosted": "dist/self-hosted.js",
22
+ "infinity-self-hosted-migrate": "dist/self-hosted-migrate.js",
23
+ "infinity-migrate": "dist/migrate.js"
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "evidence",
28
+ "migrations",
29
+ "README.md",
30
+ "LICENSE"
31
+ ],
32
+ "scripts": {
33
+ "test": "bun test",
34
+ "test:golden:packages": "bun test ./tests/golden-package-loader.integration.ts ./tests/golden-source-pins.integration.ts",
35
+ "test:golden:accounts-pg": "bun test ./tests/golden-accounts-postgres.integration.ts",
36
+ "typecheck": "tsc --noEmit",
37
+ "build": "bun scripts/build.ts",
38
+ "clean": "rm -rf dist",
39
+ "pack": "bun pm pack",
40
+ "audit": "bun audit",
41
+ "migrate": "bun src/persistence/migrate-main.ts"
42
+ },
43
+ "devDependencies": {
44
+ "@types/bun": "1.3.6",
45
+ "typescript": "5.9.3"
46
+ }
47
+ }