@adcp/sdk 15.9.0 → 16.0.0-beta.1
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.
- package/bin/adcp-identity.js +74 -0
- package/bin/adcp.js +2 -0
- package/dist/lib/adapters/keyed-account-backend.d.mts +37 -0
- package/dist/lib/adapters/keyed-account-backend.d.ts +37 -0
- package/dist/lib/adapters/keyed-account-backend.js +121 -0
- package/dist/lib/adapters/keyed-account-backend.mjs +94 -0
- package/dist/lib/adapters/keyed-account-store.d.mts +28 -0
- package/dist/lib/adapters/keyed-account-store.d.ts +28 -0
- package/dist/lib/adapters/keyed-account-store.js +227 -0
- package/dist/lib/adapters/keyed-account-store.mjs +203 -0
- package/dist/lib/core/SingleAgentClient.d.mts +16 -2
- package/dist/lib/core/SingleAgentClient.d.ts +16 -2
- package/dist/lib/core/SingleAgentClient.js +259 -62
- package/dist/lib/core/SingleAgentClient.mjs +261 -57
- package/dist/lib/core/TaskExecutor.d.mts +6 -0
- package/dist/lib/core/TaskExecutor.d.ts +6 -0
- package/dist/lib/core/TaskExecutor.js +66 -5
- package/dist/lib/core/TaskExecutor.mjs +71 -5
- package/dist/lib/core/postgres-webhook-registration-store.js +32 -5
- package/dist/lib/core/postgres-webhook-registration-store.mjs +32 -5
- package/dist/lib/core/redis-webhook-registration-store.js +23 -1
- package/dist/lib/core/redis-webhook-registration-store.mjs +23 -1
- package/dist/lib/core/webhook-registration.d.mts +7 -1
- package/dist/lib/core/webhook-registration.d.ts +7 -1
- package/dist/lib/core/webhook-registration.js +24 -2
- package/dist/lib/core/webhook-registration.mjs +23 -2
- package/dist/lib/identity-3.3/index.d.mts +10 -0
- package/dist/lib/identity-3.3/index.d.ts +10 -0
- package/dist/lib/identity-3.3/index.js +75 -0
- package/dist/lib/identity-3.3/index.mjs +46 -0
- package/dist/lib/identity-3.3/lifecycle.d.mts +113 -0
- package/dist/lib/identity-3.3/lifecycle.d.ts +113 -0
- package/dist/lib/identity-3.3/lifecycle.js +267 -0
- package/dist/lib/identity-3.3/lifecycle.mjs +240 -0
- package/dist/lib/identity-3.3/revocation.d.mts +50 -0
- package/dist/lib/identity-3.3/revocation.d.ts +50 -0
- package/dist/lib/identity-3.3/revocation.js +238 -0
- package/dist/lib/identity-3.3/revocation.mjs +216 -0
- package/dist/lib/identity-3.3/schemas.draft.d.mts +2472 -0
- package/dist/lib/identity-3.3/schemas.draft.d.ts +2472 -0
- package/dist/lib/identity-3.3/schemas.draft.js +1448 -0
- package/dist/lib/identity-3.3/schemas.draft.mjs +1428 -0
- package/dist/lib/identity-3.3/server.d.mts +34 -0
- package/dist/lib/identity-3.3/server.d.ts +34 -0
- package/dist/lib/identity-3.3/server.js +219 -0
- package/dist/lib/identity-3.3/server.mjs +194 -0
- package/dist/lib/identity-3.3/store.d.mts +24 -0
- package/dist/lib/identity-3.3/store.d.ts +24 -0
- package/dist/lib/identity-3.3/store.js +191 -0
- package/dist/lib/identity-3.3/store.mjs +169 -0
- package/dist/lib/identity-3.3/trust.d.mts +94 -0
- package/dist/lib/identity-3.3/trust.d.ts +94 -0
- package/dist/lib/identity-3.3/trust.js +278 -0
- package/dist/lib/identity-3.3/trust.mjs +239 -0
- package/dist/lib/identity-3.3/types.d.mts +127 -0
- package/dist/lib/identity-3.3/types.d.ts +127 -0
- package/dist/lib/identity-3.3/types.js +16 -0
- package/dist/lib/identity-3.3/types.mjs +0 -0
- package/dist/lib/identity-3.3/validation.d.mts +2 -0
- package/dist/lib/identity-3.3/validation.d.ts +2 -0
- package/dist/lib/identity-3.3/validation.js +125 -0
- package/dist/lib/identity-3.3/validation.mjs +91 -0
- package/dist/lib/index.d.mts +1 -1
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/reporting/azure/index.d.mts +5 -0
- package/dist/lib/reporting/azure/index.d.ts +5 -0
- package/dist/lib/reporting/azure/index.js +26 -7
- package/dist/lib/reporting/azure/index.mjs +26 -7
- package/dist/lib/reporting/bigquery/index.d.mts +80 -25
- package/dist/lib/reporting/bigquery/index.d.ts +80 -25
- package/dist/lib/reporting/bigquery/index.js +184 -81
- package/dist/lib/reporting/bigquery/index.mjs +182 -80
- package/dist/lib/reporting/gcs/adapter.d.mts +8 -1
- package/dist/lib/reporting/gcs/adapter.d.ts +8 -1
- package/dist/lib/reporting/gcs/errors.d.mts +6 -0
- package/dist/lib/reporting/gcs/errors.d.ts +6 -0
- package/dist/lib/reporting/gcs/fence.d.mts +5 -0
- package/dist/lib/reporting/gcs/fence.d.ts +5 -0
- package/dist/lib/reporting/gcs/index.d.mts +9 -0
- package/dist/lib/reporting/gcs/index.d.ts +9 -0
- package/dist/lib/reporting/gcs/reader.d.mts +27 -3
- package/dist/lib/reporting/gcs/reader.d.ts +27 -3
- package/dist/lib/reporting/gcs/row-provider.d.mts +7 -0
- package/dist/lib/reporting/gcs/row-provider.d.ts +7 -0
- package/dist/lib/reporting/gcs/row-provider.js +34 -14
- package/dist/lib/reporting/gcs/row-provider.mjs +34 -14
- package/dist/lib/reporting/ledger/change-feed.d.mts +22 -1
- package/dist/lib/reporting/ledger/change-feed.d.ts +22 -1
- package/dist/lib/reporting/ledger/index.d.mts +11 -0
- package/dist/lib/reporting/ledger/index.d.ts +11 -0
- package/dist/lib/reporting/ledger/managed-postgres.d.mts +8 -0
- package/dist/lib/reporting/ledger/managed-postgres.d.ts +8 -0
- package/dist/lib/reporting/ledger/managed-router.d.mts +27 -2
- package/dist/lib/reporting/ledger/managed-router.d.ts +27 -2
- package/dist/lib/reporting/ledger/managed.d.mts +86 -6
- package/dist/lib/reporting/ledger/managed.d.ts +86 -6
- package/dist/lib/reporting/ledger/notification-activity.d.mts +65 -3
- package/dist/lib/reporting/ledger/notification-activity.d.ts +65 -3
- package/dist/lib/reporting/ledger/object-writes.d.mts +64 -5
- package/dist/lib/reporting/ledger/object-writes.d.ts +64 -5
- package/dist/lib/reporting/ledger/postgres.d.mts +43 -9
- package/dist/lib/reporting/ledger/postgres.d.ts +43 -9
- package/dist/lib/reporting/ledger/postgres.js +43 -27
- package/dist/lib/reporting/ledger/postgres.mjs +43 -27
- package/dist/lib/reporting/ledger/row-encoding.d.mts +92 -6
- package/dist/lib/reporting/ledger/row-encoding.d.ts +92 -6
- package/dist/lib/reporting/ledger/row-encoding.js +8 -4
- package/dist/lib/reporting/ledger/row-encoding.mjs +6 -3
- package/dist/lib/reporting/ledger/row-storage-errors.d.mts +11 -1
- package/dist/lib/reporting/ledger/row-storage-errors.d.ts +11 -1
- package/dist/lib/reporting/ledger/row-storage-migration.d.mts +19 -1
- package/dist/lib/reporting/ledger/row-storage-migration.d.ts +19 -1
- package/dist/lib/reporting/ledger/row-storage-migration.js +133 -18
- package/dist/lib/reporting/ledger/row-storage-migration.mjs +133 -18
- package/dist/lib/reporting/ledger/row-storage-object.d.mts +103 -12
- package/dist/lib/reporting/ledger/row-storage-object.d.ts +103 -12
- package/dist/lib/reporting/ledger/row-storage-object.js +106 -31
- package/dist/lib/reporting/ledger/row-storage-object.mjs +104 -31
- package/dist/lib/reporting/ledger/row-storage.d.mts +87 -20
- package/dist/lib/reporting/ledger/row-storage.d.ts +87 -20
- package/dist/lib/reporting/ledger/row-storage.js +126 -66
- package/dist/lib/reporting/ledger/row-storage.mjs +129 -67
- package/dist/lib/reporting/ledger/schedule.d.mts +13 -0
- package/dist/lib/reporting/ledger/schedule.d.ts +13 -0
- package/dist/lib/reporting/ledger/schedule.js +24 -0
- package/dist/lib/reporting/ledger/schedule.mjs +23 -0
- package/dist/lib/reporting/ledger/types.d.mts +23 -1
- package/dist/lib/reporting/ledger/types.d.ts +23 -1
- package/dist/lib/reporting/s3/index.d.mts +5 -0
- package/dist/lib/reporting/s3/index.d.ts +5 -0
- package/dist/lib/reporting/s3/index.js +37 -14
- package/dist/lib/reporting/s3/index.mjs +37 -14
- package/dist/lib/reporting/service/index.d.mts +10 -0
- package/dist/lib/reporting/service/index.d.ts +10 -0
- package/dist/lib/reporting/service/maintenance.d.mts +28 -2
- package/dist/lib/reporting/service/maintenance.d.ts +28 -2
- package/dist/lib/schemas-data/v2.5/_provenance.json +1 -1
- package/dist/lib/server/account-sync-contract.d.mts +14 -0
- package/dist/lib/server/account-sync-contract.d.ts +14 -0
- package/dist/lib/server/account-sync-contract.js +225 -0
- package/dist/lib/server/account-sync-contract.mjs +197 -0
- package/dist/lib/server/adcp-server.js +5 -0
- package/dist/lib/server/adcp-server.mjs +10 -0
- package/dist/lib/server/auth-signature.d.mts +10 -0
- package/dist/lib/server/auth-signature.d.ts +10 -0
- package/dist/lib/server/auth-signature.js +61 -2
- package/dist/lib/server/auth-signature.mjs +65 -2
- package/dist/lib/server/auth.d.mts +6 -0
- package/dist/lib/server/auth.d.ts +6 -0
- package/dist/lib/server/auth.js +6 -0
- package/dist/lib/server/auth.mjs +6 -0
- package/dist/lib/server/create-adcp-server.d.mts +19 -5
- package/dist/lib/server/create-adcp-server.d.ts +19 -5
- package/dist/lib/server/create-adcp-server.js +238 -19
- package/dist/lib/server/create-adcp-server.mjs +240 -10
- package/dist/lib/server/decisioning/account.d.mts +24 -1
- package/dist/lib/server/decisioning/account.d.ts +24 -1
- package/dist/lib/server/decisioning/index.d.mts +1 -1
- package/dist/lib/server/decisioning/index.d.ts +1 -1
- package/dist/lib/server/decisioning/runtime/from-platform.d.mts +0 -50
- package/dist/lib/server/decisioning/runtime/from-platform.d.ts +0 -50
- package/dist/lib/server/decisioning/runtime/from-platform.js +61 -11
- package/dist/lib/server/decisioning/runtime/from-platform.mjs +65 -12
- package/dist/lib/server/index.d.mts +2 -0
- package/dist/lib/server/index.d.ts +2 -0
- package/dist/lib/server/index.js +12 -0
- package/dist/lib/server/index.mjs +12 -0
- package/dist/lib/server/notification-subscriptions/runtime.js +9 -1
- package/dist/lib/server/notification-subscriptions/runtime.mjs +9 -1
- package/dist/lib/server/notification-subscriptions/types.d.mts +5 -0
- package/dist/lib/server/notification-subscriptions/types.d.ts +5 -0
- package/dist/lib/server/principal/types.d.mts +1 -1
- package/dist/lib/server/principal/types.d.ts +1 -1
- package/dist/lib/server/serve.js +5 -0
- package/dist/lib/server/serve.mjs +5 -0
- package/dist/lib/server/webhook-delivery/recovery.d.mts +1 -0
- package/dist/lib/server/webhook-delivery/recovery.d.ts +1 -0
- package/dist/lib/server/webhook-delivery/recovery.js +4 -0
- package/dist/lib/server/webhook-delivery/recovery.mjs +4 -0
- package/dist/lib/server/webhook-emitter.d.mts +10 -0
- package/dist/lib/server/webhook-emitter.d.ts +10 -0
- package/dist/lib/server/webhook-emitter.js +22 -0
- package/dist/lib/server/webhook-emitter.mjs +22 -0
- package/dist/lib/signing/agent-context.d.mts +0 -5
- package/dist/lib/signing/agent-context.d.ts +0 -5
- package/dist/lib/signing/agent-context.js +9 -1
- package/dist/lib/signing/agent-context.mjs +9 -1
- package/dist/lib/signing/agent-fetch.js +27 -2
- package/dist/lib/signing/agent-fetch.mjs +32 -2
- package/dist/lib/signing/agent-resolver/canonicalize.d.mts +10 -15
- package/dist/lib/signing/agent-resolver/canonicalize.d.ts +10 -15
- package/dist/lib/signing/agent-resolver/canonicalize.js +17 -5
- package/dist/lib/signing/agent-resolver/canonicalize.mjs +16 -5
- package/dist/lib/signing/agent-resolver/index.d.mts +1 -0
- package/dist/lib/signing/agent-resolver/index.d.ts +1 -0
- package/dist/lib/signing/agent-resolver/index.js +5 -0
- package/dist/lib/signing/agent-resolver/index.mjs +3 -0
- package/dist/lib/signing/agent-resolver/resolved-agent-jwks.d.mts +3 -2
- package/dist/lib/signing/agent-resolver/resolved-agent-jwks.d.ts +3 -2
- package/dist/lib/signing/agent-resolver/resolved-agent-jwks.js +30 -3
- package/dist/lib/signing/agent-resolver/resolved-agent-jwks.mjs +30 -3
- package/dist/lib/signing/agent-resolver/strict-json.d.mts +2 -2
- package/dist/lib/signing/agent-resolver/strict-json.d.ts +2 -2
- package/dist/lib/signing/agent-resolver/strict-json.js +5 -3
- package/dist/lib/signing/agent-resolver/strict-json.mjs +5 -3
- package/dist/lib/signing/brand-jwks.d.mts +2 -2
- package/dist/lib/signing/brand-jwks.d.ts +2 -2
- package/dist/lib/signing/brand-jwks.js +4 -4
- package/dist/lib/signing/brand-jwks.mjs +4 -4
- package/dist/lib/signing/client.d.mts +1 -0
- package/dist/lib/signing/client.d.ts +1 -0
- package/dist/lib/signing/client.js +5 -0
- package/dist/lib/signing/client.mjs +3 -0
- package/dist/lib/signing/jwks-https.d.mts +1 -1
- package/dist/lib/signing/jwks-https.d.ts +1 -1
- package/dist/lib/signing/jwks-https.js +1 -1
- package/dist/lib/signing/jwks-https.mjs +1 -1
- package/dist/lib/signing/jwks.d.mts +11 -3
- package/dist/lib/signing/jwks.d.ts +11 -3
- package/dist/lib/signing/jwks.js +1 -1
- package/dist/lib/signing/jwks.mjs +1 -1
- package/dist/lib/signing/parser.d.mts +1 -1
- package/dist/lib/signing/parser.d.ts +1 -1
- package/dist/lib/signing/parser.js +5 -3
- package/dist/lib/signing/parser.mjs +6 -4
- package/dist/lib/signing/revocation.d.mts +4 -1
- package/dist/lib/signing/revocation.d.ts +4 -1
- package/dist/lib/signing/revocation.js +33 -3
- package/dist/lib/signing/revocation.mjs +31 -2
- package/dist/lib/signing/server.d.mts +1 -1
- package/dist/lib/signing/server.d.ts +1 -1
- package/dist/lib/signing/server.js +4 -0
- package/dist/lib/signing/server.mjs +4 -0
- package/dist/lib/signing/types.d.mts +3 -0
- package/dist/lib/signing/types.d.ts +3 -0
- package/dist/lib/signing/web-bot-auth.d.mts +117 -0
- package/dist/lib/signing/web-bot-auth.d.ts +117 -0
- package/dist/lib/signing/web-bot-auth.js +660 -0
- package/dist/lib/signing/web-bot-auth.mjs +624 -0
- package/dist/lib/testing/client.d.mts +1 -4
- package/dist/lib/testing/client.d.ts +1 -4
- package/dist/lib/testing/client.js +141 -20
- package/dist/lib/testing/client.mjs +137 -19
- package/dist/lib/testing/compliance/comply.js +29 -10
- package/dist/lib/testing/compliance/comply.mjs +37 -11
- package/dist/lib/testing/storyboard/account-sync-contract.d.mts +3 -0
- package/dist/lib/testing/storyboard/account-sync-contract.d.ts +3 -0
- package/dist/lib/testing/storyboard/account-sync-contract.js +79 -0
- package/dist/lib/testing/storyboard/account-sync-contract.mjs +55 -0
- package/dist/lib/testing/storyboard/default-invariants.js +2 -0
- package/dist/lib/testing/storyboard/default-invariants.mjs +2 -0
- package/dist/lib/testing/storyboard/runner.js +23 -8
- package/dist/lib/testing/storyboard/runner.mjs +24 -8
- package/dist/lib/testing/storyboard/validations.d.mts +1 -1
- package/dist/lib/testing/storyboard/validations.d.ts +1 -1
- package/dist/lib/types/adcp.d.mts +4 -0
- package/dist/lib/types/adcp.d.ts +4 -0
- package/dist/lib/types/schemas.generated.d.ts +6 -6
- package/dist/lib/utils/capabilities.d.mts +1 -0
- package/dist/lib/utils/capabilities.d.ts +1 -0
- package/dist/lib/utils/capabilities.js +5 -0
- package/dist/lib/utils/capabilities.mjs +5 -0
- package/dist/lib/v2/projection/creative-delivery.d.mts +3 -1
- package/dist/lib/v2/projection/creative-delivery.d.ts +3 -1
- package/dist/lib/v2/projection/creative-delivery.js +26 -10
- package/dist/lib/v2/projection/creative-delivery.mjs +26 -10
- package/dist/lib/v2/projection/index.d.mts +1 -1
- package/dist/lib/v2/projection/index.d.ts +1 -1
- package/dist/lib/v2/projection/legacy-routes.d.mts +24 -2
- package/dist/lib/v2/projection/legacy-routes.d.ts +24 -2
- package/dist/lib/v2/projection/legacy-routes.js +28 -2
- package/dist/lib/v2/projection/legacy-routes.mjs +26 -2
- package/dist/lib/validation/schema-loader.d.mts +2 -0
- package/dist/lib/validation/schema-loader.d.ts +2 -0
- package/dist/lib/validation/schema-loader.js +43 -4
- package/dist/lib/validation/schema-loader.mjs +39 -3
- package/dist/lib/version.d.mts +3 -3
- package/dist/lib/version.d.ts +3 -3
- package/dist/lib/version.js +3 -3
- package/dist/lib/version.mjs +3 -3
- package/docs/TYPE-SUMMARY.md +2 -2
- package/docs/guides/DISCOVERY-CACHE-AND-SESSION-REUSE.md +4 -0
- package/docs/guides/REPORTING-LEDGER-CUTOVER.md +1 -1
- package/docs/guides/REPORTING-LEDGER.md +132 -46
- package/docs/guides/REPORTING-OPERATIONS.md +25 -4
- package/docs/guides/REPORTING-STABILITY.md +76 -0
- package/docs/guides/account-resolution.md +101 -0
- package/docs/llms.txt +3 -2
- package/docs/migration-12-to-13.md +7 -0
- package/docs/migration-14.x-rc-worksheet.md +4 -4
- package/docs/migration-agent-identity-3.3.md +355 -0
- package/docs/migration-agent-resolution-3.3.md +5 -0
- package/docs/migration-reporting-row-storage-alignment.md +137 -0
- package/examples/storyboards/account-sync-contract.yaml +57 -0
- package/package.json +15 -1
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var store_exports = {};
|
|
20
|
+
__export(store_exports, {
|
|
21
|
+
createIdentity33StateStores: () => createIdentity33StateStores
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(store_exports);
|
|
24
|
+
var import_crypto = require("crypto");
|
|
25
|
+
var import_canonicalize = require('../signing/agent-resolver/canonicalize.js');
|
|
26
|
+
var import_etld = require('../signing/agent-resolver/etld.js');
|
|
27
|
+
var import_trust = require('./trust.js');
|
|
28
|
+
var import_revocation = require('./revocation.js');
|
|
29
|
+
function createIdentity33StateStores(options) {
|
|
30
|
+
const { store, tenantId } = options, collection = options.collection ?? "identity33";
|
|
31
|
+
if (!tenantId || tenantId.length > 255 || !store.getWithVersion || !store.putIfMatch)
|
|
32
|
+
throw new TypeError("Identity stores require trusted tenantId and atomic getWithVersion/putIfMatch");
|
|
33
|
+
const revocationLimits = {
|
|
34
|
+
keys: 1e5,
|
|
35
|
+
origins: 1e4,
|
|
36
|
+
operatorKeys: 16384,
|
|
37
|
+
operatorOrigins: 256,
|
|
38
|
+
originKeys: 16384,
|
|
39
|
+
...options.revocationLimits
|
|
40
|
+
};
|
|
41
|
+
if (Object.values(revocationLimits).some((value) => !Number.isSafeInteger(value) || value < 1))
|
|
42
|
+
throw new TypeError("Revocation limits must be positive safe integers");
|
|
43
|
+
const id = (kind, key) => (0, import_crypto.createHash)("sha256").update(JSON.stringify([tenantId, kind, key])).digest("hex");
|
|
44
|
+
async function update(kind, key, change) {
|
|
45
|
+
const keyId = id(kind, key);
|
|
46
|
+
for (let attempt = 0; attempt < 10; attempt++) {
|
|
47
|
+
const prior = await store.getWithVersion(collection, keyId);
|
|
48
|
+
if (prior && prior.data.tenantId !== tenantId) throw new import_trust.IdentityAuthorizationError();
|
|
49
|
+
const next = await change(prior?.data ?? null);
|
|
50
|
+
if ((await store.putIfMatch(collection, keyId, next, prior?.version ?? null)).ok) return next;
|
|
51
|
+
}
|
|
52
|
+
throw new import_trust.IdentityAuthorizationError();
|
|
53
|
+
}
|
|
54
|
+
function operatorOf(origin) {
|
|
55
|
+
try {
|
|
56
|
+
return (0, import_etld.eTldPlusOne)(origin);
|
|
57
|
+
} catch {
|
|
58
|
+
return void 0;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async function readLedger(operator) {
|
|
62
|
+
const row = await store.get(collection, id("operator", operator));
|
|
63
|
+
if (row && (row.schemaVersion !== 1 || row.tenantId !== tenantId || row.operator !== operator || !row.bindings || typeof row.bindings !== "object"))
|
|
64
|
+
throw new import_trust.IdentityAuthorizationError();
|
|
65
|
+
return row;
|
|
66
|
+
}
|
|
67
|
+
async function writeBinding(binding, quota) {
|
|
68
|
+
if ((0, import_canonicalize.canonicalAgentOrigin)(binding.origin) !== binding.origin || operatorOf(binding.origin) !== binding.operator || !binding.principalId || !binding.audit?.approvedBy || !binding.audit.reason || !Number.isFinite(Date.parse(binding.audit.approvedAt)))
|
|
69
|
+
throw new import_trust.IdentityAuthorizationError();
|
|
70
|
+
const ledger = await update("operator", binding.operator, (prior) => {
|
|
71
|
+
if (prior && (prior.schemaVersion !== 1 || prior.operator !== binding.operator || !prior.bindings))
|
|
72
|
+
throw new import_trust.IdentityAuthorizationError();
|
|
73
|
+
const value = prior ?? { schemaVersion: 1, tenantId, operator: binding.operator, bindings: {} };
|
|
74
|
+
const existing = value.bindings[binding.origin];
|
|
75
|
+
if (existing) {
|
|
76
|
+
if (quota !== void 0 || JSON.stringify(existing) !== JSON.stringify(binding))
|
|
77
|
+
throw new import_trust.IdentityAuthorizationError();
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
if (quota !== void 0 && (!binding.openAccess || !Number.isInteger(quota) || quota < 1 || Object.values(value.bindings).filter((b) => b.openAccess).length >= quota))
|
|
81
|
+
throw new import_trust.IdentityAuthorizationError();
|
|
82
|
+
return { ...value, bindings: { ...value.bindings, [binding.origin]: structuredClone(binding) } };
|
|
83
|
+
});
|
|
84
|
+
return structuredClone(ledger.bindings[binding.origin]);
|
|
85
|
+
}
|
|
86
|
+
const identity = {
|
|
87
|
+
async getBinding(origin) {
|
|
88
|
+
origin = (0, import_canonicalize.canonicalAgentOrigin)(origin);
|
|
89
|
+
const operator = operatorOf(origin);
|
|
90
|
+
if (!operator) return void 0;
|
|
91
|
+
const binding = (await readLedger(operator))?.bindings[origin];
|
|
92
|
+
return binding && structuredClone(binding);
|
|
93
|
+
},
|
|
94
|
+
async bind(binding) {
|
|
95
|
+
await writeBinding(binding);
|
|
96
|
+
},
|
|
97
|
+
bindOpen: (binding, quota) => writeBinding(binding, quota),
|
|
98
|
+
async getApplication(origin) {
|
|
99
|
+
const row = await store.get(collection, id("application", (0, import_canonicalize.canonicalAgentOrigin)(origin)));
|
|
100
|
+
if (!row) return void 0;
|
|
101
|
+
if (row.tenantId !== tenantId || row.schemaVersion !== 1 || row.origin !== (0, import_canonicalize.canonicalAgentOrigin)(origin) || !row.application)
|
|
102
|
+
throw new import_trust.IdentityAuthorizationError();
|
|
103
|
+
return structuredClone(row.application);
|
|
104
|
+
},
|
|
105
|
+
async compareAndSetApplication(origin, expectedRevision, application) {
|
|
106
|
+
origin = (0, import_canonicalize.canonicalAgentOrigin)(origin);
|
|
107
|
+
const keyId = id("application", origin);
|
|
108
|
+
const prior = await store.getWithVersion(collection, keyId);
|
|
109
|
+
if (prior && (prior.data.tenantId !== tenantId || prior.data.origin !== origin))
|
|
110
|
+
throw new import_trust.IdentityAuthorizationError();
|
|
111
|
+
const current = prior?.data.application;
|
|
112
|
+
if (current?.revision !== expectedRevision || application.revision !== (expectedRevision ?? 0) + 1) return false;
|
|
113
|
+
return (await store.putIfMatch(
|
|
114
|
+
collection,
|
|
115
|
+
keyId,
|
|
116
|
+
{ schemaVersion: 1, tenantId, origin, application: structuredClone(application) },
|
|
117
|
+
prior?.version ?? null
|
|
118
|
+
)).ok;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
const authorityHistory = {
|
|
122
|
+
async has(operator) {
|
|
123
|
+
return (await readLedger((0, import_etld.eTldPlusOne)(operator)))?.authoritativeTrustSeen === true;
|
|
124
|
+
},
|
|
125
|
+
async mark(operator) {
|
|
126
|
+
operator = (0, import_etld.eTldPlusOne)(operator);
|
|
127
|
+
await update("operator", operator, (prior) => ({
|
|
128
|
+
...prior ?? { schemaVersion: 1, tenantId, operator, bindings: {} },
|
|
129
|
+
authoritativeTrustSeen: true
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
async function reserveRevocationBudget(origin, keys) {
|
|
134
|
+
const operator = (0, import_etld.eTldPlusOne)(origin);
|
|
135
|
+
const binding = await identity.getBinding(origin);
|
|
136
|
+
const hasBinding = !!binding && !binding.openAccess;
|
|
137
|
+
await update("revocation-budget", "tenant", (prior) => {
|
|
138
|
+
const budget = prior ?? { schemaVersion: 1, tenantId, origins: {}, keys: 0 };
|
|
139
|
+
if (budget.schemaVersion !== 1 || !budget.origins || !Number.isSafeInteger(budget.keys) || budget.boundKeys !== void 0 && !Number.isSafeInteger(budget.boundKeys))
|
|
140
|
+
throw new import_trust.IdentityAuthorizationError();
|
|
141
|
+
const previous = budget.origins[origin], desired = Math.max(previous?.keys ?? 0, keys), delta = desired - (previous?.keys ?? 0), bound = previous?.bound === true || hasBinding, boundKeys = (budget.boundKeys ?? 0) + (bound ? desired - (previous?.bound ? previous.keys : 0) : 0), totalKeys = budget.keys + delta;
|
|
142
|
+
const entries = Object.values(budget.origins), pool = entries.filter((entry) => entry.bound === true === bound), owned = pool.filter((entry) => entry.operator === operator), newPoolMember = !previous || previous.bound === true !== bound;
|
|
143
|
+
if (newPoolMember && (pool.length >= revocationLimits.origins || owned.length >= revocationLimits.operatorOrigins) || (bound ? boundKeys : totalKeys - boundKeys) > revocationLimits.keys || owned.reduce((sum, entry) => sum + entry.keys, 0) + (newPoolMember ? desired : delta) > revocationLimits.operatorKeys)
|
|
144
|
+
throw new import_trust.IdentityAuthorizationError();
|
|
145
|
+
return {
|
|
146
|
+
...budget,
|
|
147
|
+
keys: totalKeys,
|
|
148
|
+
boundKeys,
|
|
149
|
+
origins: { ...budget.origins, [origin]: { operator, keys: desired, bound } }
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
const revocations = {
|
|
154
|
+
async get(origin, keyid) {
|
|
155
|
+
origin = (0, import_canonicalize.canonicalAgentOrigin)(origin);
|
|
156
|
+
const row = await store.get(collection, id("revocations", origin));
|
|
157
|
+
if (row && (row.schemaVersion !== 1 || row.tenantId !== tenantId || row.origin !== origin || !row.revoked))
|
|
158
|
+
throw new import_trust.IdentityAuthorizationError();
|
|
159
|
+
const detail = row && Object.hasOwn(row.revoked, keyid) ? row.revoked[keyid] : void 0;
|
|
160
|
+
return detail && { ...detail };
|
|
161
|
+
},
|
|
162
|
+
async merge(origin, snapshot) {
|
|
163
|
+
origin = (0, import_canonicalize.canonicalAgentOrigin)(origin);
|
|
164
|
+
if (!snapshot.revoked_kids.length) return;
|
|
165
|
+
await update("revocations", origin, async (prior) => {
|
|
166
|
+
if (prior && (prior.schemaVersion !== 1 || prior.origin !== origin || !prior.revoked))
|
|
167
|
+
throw new import_trust.IdentityAuthorizationError();
|
|
168
|
+
const revoked = { ...prior?.revoked ?? {} };
|
|
169
|
+
const additions = new Set(snapshot.revoked_kids.filter((kid) => !Object.hasOwn(revoked, kid)));
|
|
170
|
+
if (Object.keys(revoked).length + additions.size > revocationLimits.originKeys)
|
|
171
|
+
throw new import_trust.IdentityAuthorizationError();
|
|
172
|
+
for (const kid of snapshot.revoked_kids) {
|
|
173
|
+
const previous = Object.hasOwn(revoked, kid) ? revoked[kid] : void 0;
|
|
174
|
+
Object.defineProperty(revoked, kid, {
|
|
175
|
+
value: (0, import_revocation.mergeRevocationDetail)(previous, snapshot.revocation_details?.[kid] ?? {}),
|
|
176
|
+
enumerable: true,
|
|
177
|
+
configurable: true,
|
|
178
|
+
writable: true
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
await reserveRevocationBudget(origin, Object.keys(revoked).length);
|
|
182
|
+
return { schemaVersion: 1, tenantId, origin, revoked };
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
return { identity, authorityHistory, revocations };
|
|
187
|
+
}
|
|
188
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
189
|
+
0 && (module.exports = {
|
|
190
|
+
createIdentity33StateStores
|
|
191
|
+
});
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { createHash } from "crypto";
|
|
2
|
+
import { canonicalAgentOrigin } from "../signing/agent-resolver/canonicalize.mjs";
|
|
3
|
+
import { eTldPlusOne } from "../signing/agent-resolver/etld.mjs";
|
|
4
|
+
import { IdentityAuthorizationError } from "./trust.mjs";
|
|
5
|
+
import {
|
|
6
|
+
mergeRevocationDetail
|
|
7
|
+
} from "./revocation.mjs";
|
|
8
|
+
function createIdentity33StateStores(options) {
|
|
9
|
+
const { store, tenantId } = options, collection = options.collection ?? "identity33";
|
|
10
|
+
if (!tenantId || tenantId.length > 255 || !store.getWithVersion || !store.putIfMatch)
|
|
11
|
+
throw new TypeError("Identity stores require trusted tenantId and atomic getWithVersion/putIfMatch");
|
|
12
|
+
const revocationLimits = {
|
|
13
|
+
keys: 1e5,
|
|
14
|
+
origins: 1e4,
|
|
15
|
+
operatorKeys: 16384,
|
|
16
|
+
operatorOrigins: 256,
|
|
17
|
+
originKeys: 16384,
|
|
18
|
+
...options.revocationLimits
|
|
19
|
+
};
|
|
20
|
+
if (Object.values(revocationLimits).some((value) => !Number.isSafeInteger(value) || value < 1))
|
|
21
|
+
throw new TypeError("Revocation limits must be positive safe integers");
|
|
22
|
+
const id = (kind, key) => createHash("sha256").update(JSON.stringify([tenantId, kind, key])).digest("hex");
|
|
23
|
+
async function update(kind, key, change) {
|
|
24
|
+
const keyId = id(kind, key);
|
|
25
|
+
for (let attempt = 0; attempt < 10; attempt++) {
|
|
26
|
+
const prior = await store.getWithVersion(collection, keyId);
|
|
27
|
+
if (prior && prior.data.tenantId !== tenantId) throw new IdentityAuthorizationError();
|
|
28
|
+
const next = await change(prior?.data ?? null);
|
|
29
|
+
if ((await store.putIfMatch(collection, keyId, next, prior?.version ?? null)).ok) return next;
|
|
30
|
+
}
|
|
31
|
+
throw new IdentityAuthorizationError();
|
|
32
|
+
}
|
|
33
|
+
function operatorOf(origin) {
|
|
34
|
+
try {
|
|
35
|
+
return eTldPlusOne(origin);
|
|
36
|
+
} catch {
|
|
37
|
+
return void 0;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async function readLedger(operator) {
|
|
41
|
+
const row = await store.get(collection, id("operator", operator));
|
|
42
|
+
if (row && (row.schemaVersion !== 1 || row.tenantId !== tenantId || row.operator !== operator || !row.bindings || typeof row.bindings !== "object"))
|
|
43
|
+
throw new IdentityAuthorizationError();
|
|
44
|
+
return row;
|
|
45
|
+
}
|
|
46
|
+
async function writeBinding(binding, quota) {
|
|
47
|
+
if (canonicalAgentOrigin(binding.origin) !== binding.origin || operatorOf(binding.origin) !== binding.operator || !binding.principalId || !binding.audit?.approvedBy || !binding.audit.reason || !Number.isFinite(Date.parse(binding.audit.approvedAt)))
|
|
48
|
+
throw new IdentityAuthorizationError();
|
|
49
|
+
const ledger = await update("operator", binding.operator, (prior) => {
|
|
50
|
+
if (prior && (prior.schemaVersion !== 1 || prior.operator !== binding.operator || !prior.bindings))
|
|
51
|
+
throw new IdentityAuthorizationError();
|
|
52
|
+
const value = prior ?? { schemaVersion: 1, tenantId, operator: binding.operator, bindings: {} };
|
|
53
|
+
const existing = value.bindings[binding.origin];
|
|
54
|
+
if (existing) {
|
|
55
|
+
if (quota !== void 0 || JSON.stringify(existing) !== JSON.stringify(binding))
|
|
56
|
+
throw new IdentityAuthorizationError();
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
if (quota !== void 0 && (!binding.openAccess || !Number.isInteger(quota) || quota < 1 || Object.values(value.bindings).filter((b) => b.openAccess).length >= quota))
|
|
60
|
+
throw new IdentityAuthorizationError();
|
|
61
|
+
return { ...value, bindings: { ...value.bindings, [binding.origin]: structuredClone(binding) } };
|
|
62
|
+
});
|
|
63
|
+
return structuredClone(ledger.bindings[binding.origin]);
|
|
64
|
+
}
|
|
65
|
+
const identity = {
|
|
66
|
+
async getBinding(origin) {
|
|
67
|
+
origin = canonicalAgentOrigin(origin);
|
|
68
|
+
const operator = operatorOf(origin);
|
|
69
|
+
if (!operator) return void 0;
|
|
70
|
+
const binding = (await readLedger(operator))?.bindings[origin];
|
|
71
|
+
return binding && structuredClone(binding);
|
|
72
|
+
},
|
|
73
|
+
async bind(binding) {
|
|
74
|
+
await writeBinding(binding);
|
|
75
|
+
},
|
|
76
|
+
bindOpen: (binding, quota) => writeBinding(binding, quota),
|
|
77
|
+
async getApplication(origin) {
|
|
78
|
+
const row = await store.get(collection, id("application", canonicalAgentOrigin(origin)));
|
|
79
|
+
if (!row) return void 0;
|
|
80
|
+
if (row.tenantId !== tenantId || row.schemaVersion !== 1 || row.origin !== canonicalAgentOrigin(origin) || !row.application)
|
|
81
|
+
throw new IdentityAuthorizationError();
|
|
82
|
+
return structuredClone(row.application);
|
|
83
|
+
},
|
|
84
|
+
async compareAndSetApplication(origin, expectedRevision, application) {
|
|
85
|
+
origin = canonicalAgentOrigin(origin);
|
|
86
|
+
const keyId = id("application", origin);
|
|
87
|
+
const prior = await store.getWithVersion(collection, keyId);
|
|
88
|
+
if (prior && (prior.data.tenantId !== tenantId || prior.data.origin !== origin))
|
|
89
|
+
throw new IdentityAuthorizationError();
|
|
90
|
+
const current = prior?.data.application;
|
|
91
|
+
if (current?.revision !== expectedRevision || application.revision !== (expectedRevision ?? 0) + 1) return false;
|
|
92
|
+
return (await store.putIfMatch(
|
|
93
|
+
collection,
|
|
94
|
+
keyId,
|
|
95
|
+
{ schemaVersion: 1, tenantId, origin, application: structuredClone(application) },
|
|
96
|
+
prior?.version ?? null
|
|
97
|
+
)).ok;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
const authorityHistory = {
|
|
101
|
+
async has(operator) {
|
|
102
|
+
return (await readLedger(eTldPlusOne(operator)))?.authoritativeTrustSeen === true;
|
|
103
|
+
},
|
|
104
|
+
async mark(operator) {
|
|
105
|
+
operator = eTldPlusOne(operator);
|
|
106
|
+
await update("operator", operator, (prior) => ({
|
|
107
|
+
...prior ?? { schemaVersion: 1, tenantId, operator, bindings: {} },
|
|
108
|
+
authoritativeTrustSeen: true
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
async function reserveRevocationBudget(origin, keys) {
|
|
113
|
+
const operator = eTldPlusOne(origin);
|
|
114
|
+
const binding = await identity.getBinding(origin);
|
|
115
|
+
const hasBinding = !!binding && !binding.openAccess;
|
|
116
|
+
await update("revocation-budget", "tenant", (prior) => {
|
|
117
|
+
const budget = prior ?? { schemaVersion: 1, tenantId, origins: {}, keys: 0 };
|
|
118
|
+
if (budget.schemaVersion !== 1 || !budget.origins || !Number.isSafeInteger(budget.keys) || budget.boundKeys !== void 0 && !Number.isSafeInteger(budget.boundKeys))
|
|
119
|
+
throw new IdentityAuthorizationError();
|
|
120
|
+
const previous = budget.origins[origin], desired = Math.max(previous?.keys ?? 0, keys), delta = desired - (previous?.keys ?? 0), bound = previous?.bound === true || hasBinding, boundKeys = (budget.boundKeys ?? 0) + (bound ? desired - (previous?.bound ? previous.keys : 0) : 0), totalKeys = budget.keys + delta;
|
|
121
|
+
const entries = Object.values(budget.origins), pool = entries.filter((entry) => entry.bound === true === bound), owned = pool.filter((entry) => entry.operator === operator), newPoolMember = !previous || previous.bound === true !== bound;
|
|
122
|
+
if (newPoolMember && (pool.length >= revocationLimits.origins || owned.length >= revocationLimits.operatorOrigins) || (bound ? boundKeys : totalKeys - boundKeys) > revocationLimits.keys || owned.reduce((sum, entry) => sum + entry.keys, 0) + (newPoolMember ? desired : delta) > revocationLimits.operatorKeys)
|
|
123
|
+
throw new IdentityAuthorizationError();
|
|
124
|
+
return {
|
|
125
|
+
...budget,
|
|
126
|
+
keys: totalKeys,
|
|
127
|
+
boundKeys,
|
|
128
|
+
origins: { ...budget.origins, [origin]: { operator, keys: desired, bound } }
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
const revocations = {
|
|
133
|
+
async get(origin, keyid) {
|
|
134
|
+
origin = canonicalAgentOrigin(origin);
|
|
135
|
+
const row = await store.get(collection, id("revocations", origin));
|
|
136
|
+
if (row && (row.schemaVersion !== 1 || row.tenantId !== tenantId || row.origin !== origin || !row.revoked))
|
|
137
|
+
throw new IdentityAuthorizationError();
|
|
138
|
+
const detail = row && Object.hasOwn(row.revoked, keyid) ? row.revoked[keyid] : void 0;
|
|
139
|
+
return detail && { ...detail };
|
|
140
|
+
},
|
|
141
|
+
async merge(origin, snapshot) {
|
|
142
|
+
origin = canonicalAgentOrigin(origin);
|
|
143
|
+
if (!snapshot.revoked_kids.length) return;
|
|
144
|
+
await update("revocations", origin, async (prior) => {
|
|
145
|
+
if (prior && (prior.schemaVersion !== 1 || prior.origin !== origin || !prior.revoked))
|
|
146
|
+
throw new IdentityAuthorizationError();
|
|
147
|
+
const revoked = { ...prior?.revoked ?? {} };
|
|
148
|
+
const additions = new Set(snapshot.revoked_kids.filter((kid) => !Object.hasOwn(revoked, kid)));
|
|
149
|
+
if (Object.keys(revoked).length + additions.size > revocationLimits.originKeys)
|
|
150
|
+
throw new IdentityAuthorizationError();
|
|
151
|
+
for (const kid of snapshot.revoked_kids) {
|
|
152
|
+
const previous = Object.hasOwn(revoked, kid) ? revoked[kid] : void 0;
|
|
153
|
+
Object.defineProperty(revoked, kid, {
|
|
154
|
+
value: mergeRevocationDetail(previous, snapshot.revocation_details?.[kid] ?? {}),
|
|
155
|
+
enumerable: true,
|
|
156
|
+
configurable: true,
|
|
157
|
+
writable: true
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
await reserveRevocationBudget(origin, Object.keys(revoked).length);
|
|
161
|
+
return { schemaVersion: 1, tenantId, origin, revoked };
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
return { identity, authorityHistory, revocations };
|
|
166
|
+
}
|
|
167
|
+
export {
|
|
168
|
+
createIdentity33StateStores
|
|
169
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { type SsrfFetchOptions } from '../net/index.mjs';
|
|
2
|
+
import type { TrustRecord, TrustAgent, AgentGrantDeniedDetails } from './types.mjs';
|
|
3
|
+
export declare function validateIdentity33Schema(id: string, value: unknown): boolean;
|
|
4
|
+
export declare class IdentityAuthorizationError extends Error {
|
|
5
|
+
readonly code = "PERMISSION_DENIED";
|
|
6
|
+
readonly details: AgentGrantDeniedDetails | undefined;
|
|
7
|
+
constructor(reason?: 'authorization_failed' | 'grant_absent');
|
|
8
|
+
}
|
|
9
|
+
/** Schema plus semantic checks; publication never includes identity keys. */
|
|
10
|
+
export declare function validateTrustRecord(value: unknown): asserts value is TrustRecord;
|
|
11
|
+
export declare function createTrustRecord(record: TrustRecord): TrustRecord;
|
|
12
|
+
export type TrustFetchResult = {
|
|
13
|
+
status: 'present';
|
|
14
|
+
operator: string;
|
|
15
|
+
record: TrustRecord;
|
|
16
|
+
checkedAt: number;
|
|
17
|
+
freshUntil: number;
|
|
18
|
+
} | {
|
|
19
|
+
status: 'absent';
|
|
20
|
+
operator: string;
|
|
21
|
+
checkedAt: number;
|
|
22
|
+
freshUntil: number;
|
|
23
|
+
};
|
|
24
|
+
export interface TrustEvaluatorOptions {
|
|
25
|
+
/** Matches configured revocation polling: one minute through thirty minutes. */
|
|
26
|
+
pollingIntervalSeconds?: number;
|
|
27
|
+
now?: () => number;
|
|
28
|
+
fetchOptions?: Pick<SsrfFetchOptions, 'lookup' | 'trustedFetchFn'>;
|
|
29
|
+
maxEntries?: number;
|
|
30
|
+
maxConcurrentFetches?: number;
|
|
31
|
+
/** Share authoritative-history across restarts/replicas when legacy fallback is enabled. */
|
|
32
|
+
authorityHistory?: {
|
|
33
|
+
has(operator: string): Promise<boolean>;
|
|
34
|
+
mark(operator: string): Promise<void>;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** Used by binding/grants/onboarding, never by cryptographic verification. */
|
|
38
|
+
export declare class TrustEvaluator {
|
|
39
|
+
private readonly options;
|
|
40
|
+
private readonly cache;
|
|
41
|
+
private readonly negative;
|
|
42
|
+
private readonly pending;
|
|
43
|
+
private readonly urlRequests;
|
|
44
|
+
private readonly hostRates;
|
|
45
|
+
private readonly authoritativeOperators;
|
|
46
|
+
private authorityHistoryOverflowed;
|
|
47
|
+
readonly pollingIntervalSeconds: number;
|
|
48
|
+
constructor(options?: TrustEvaluatorOptions);
|
|
49
|
+
get(domainOrOrigin: string, force?: boolean): Promise<TrustFetchResult>;
|
|
50
|
+
match(origin: string, role: string, countries?: readonly string[]): Promise<{
|
|
51
|
+
operator: string;
|
|
52
|
+
agent: TrustAgent;
|
|
53
|
+
record: TrustRecord;
|
|
54
|
+
freshUntil: number;
|
|
55
|
+
}>;
|
|
56
|
+
invalidate(domain: string): void;
|
|
57
|
+
hasAuthoritativeRecord(domain: string): boolean;
|
|
58
|
+
private now;
|
|
59
|
+
private request;
|
|
60
|
+
private fetch;
|
|
61
|
+
}
|
|
62
|
+
export interface DemandGrantClaim {
|
|
63
|
+
/** Only pass identity from an actual verifier. */
|
|
64
|
+
signerOrigin: string;
|
|
65
|
+
brand: {
|
|
66
|
+
domain: string;
|
|
67
|
+
brand_id?: string;
|
|
68
|
+
countries?: readonly string[];
|
|
69
|
+
};
|
|
70
|
+
accountOperator: string;
|
|
71
|
+
scope: string;
|
|
72
|
+
}
|
|
73
|
+
export interface DemandGrantAuthorization {
|
|
74
|
+
source: 'implicit' | 'trust' | 'seller' | 'legacy';
|
|
75
|
+
operator: string;
|
|
76
|
+
expiresAt?: number;
|
|
77
|
+
checkedAt: number;
|
|
78
|
+
chain: string[];
|
|
79
|
+
}
|
|
80
|
+
export interface DemandGrantOptions {
|
|
81
|
+
evaluator: TrustEvaluator;
|
|
82
|
+
now?: () => number;
|
|
83
|
+
/** Only evaluated for nonexclusive uncovered claims, never fetch failures. */
|
|
84
|
+
sellerAuthorization?: (claim: DemandGrantClaim) => Promise<boolean>;
|
|
85
|
+
/** Only for authoritative absence; never after a 200 or an exclusive record. */
|
|
86
|
+
legacyAuthorization?: (claim: DemandGrantClaim) => Promise<boolean>;
|
|
87
|
+
/** Seller-verified brand identity resolution, including the house's child-brand ID. Never accept a buyer-selected authorizer. */
|
|
88
|
+
resolveBrandHouse?: (brand: DemandGrantClaim['brand']) => Promise<{
|
|
89
|
+
domain: string;
|
|
90
|
+
brand_id: string;
|
|
91
|
+
} | undefined>;
|
|
92
|
+
}
|
|
93
|
+
/** Always invoke before sync_accounts side effects and before spend. No account mutation. */
|
|
94
|
+
export declare function authorizeDemandGrant(claim: DemandGrantClaim, options: DemandGrantOptions): Promise<DemandGrantAuthorization>;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { type SsrfFetchOptions } from '../net';
|
|
2
|
+
import type { TrustRecord, TrustAgent, AgentGrantDeniedDetails } from './types';
|
|
3
|
+
export declare function validateIdentity33Schema(id: string, value: unknown): boolean;
|
|
4
|
+
export declare class IdentityAuthorizationError extends Error {
|
|
5
|
+
readonly code = "PERMISSION_DENIED";
|
|
6
|
+
readonly details: AgentGrantDeniedDetails | undefined;
|
|
7
|
+
constructor(reason?: 'authorization_failed' | 'grant_absent');
|
|
8
|
+
}
|
|
9
|
+
/** Schema plus semantic checks; publication never includes identity keys. */
|
|
10
|
+
export declare function validateTrustRecord(value: unknown): asserts value is TrustRecord;
|
|
11
|
+
export declare function createTrustRecord(record: TrustRecord): TrustRecord;
|
|
12
|
+
export type TrustFetchResult = {
|
|
13
|
+
status: 'present';
|
|
14
|
+
operator: string;
|
|
15
|
+
record: TrustRecord;
|
|
16
|
+
checkedAt: number;
|
|
17
|
+
freshUntil: number;
|
|
18
|
+
} | {
|
|
19
|
+
status: 'absent';
|
|
20
|
+
operator: string;
|
|
21
|
+
checkedAt: number;
|
|
22
|
+
freshUntil: number;
|
|
23
|
+
};
|
|
24
|
+
export interface TrustEvaluatorOptions {
|
|
25
|
+
/** Matches configured revocation polling: one minute through thirty minutes. */
|
|
26
|
+
pollingIntervalSeconds?: number;
|
|
27
|
+
now?: () => number;
|
|
28
|
+
fetchOptions?: Pick<SsrfFetchOptions, 'lookup' | 'trustedFetchFn'>;
|
|
29
|
+
maxEntries?: number;
|
|
30
|
+
maxConcurrentFetches?: number;
|
|
31
|
+
/** Share authoritative-history across restarts/replicas when legacy fallback is enabled. */
|
|
32
|
+
authorityHistory?: {
|
|
33
|
+
has(operator: string): Promise<boolean>;
|
|
34
|
+
mark(operator: string): Promise<void>;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** Used by binding/grants/onboarding, never by cryptographic verification. */
|
|
38
|
+
export declare class TrustEvaluator {
|
|
39
|
+
private readonly options;
|
|
40
|
+
private readonly cache;
|
|
41
|
+
private readonly negative;
|
|
42
|
+
private readonly pending;
|
|
43
|
+
private readonly urlRequests;
|
|
44
|
+
private readonly hostRates;
|
|
45
|
+
private readonly authoritativeOperators;
|
|
46
|
+
private authorityHistoryOverflowed;
|
|
47
|
+
readonly pollingIntervalSeconds: number;
|
|
48
|
+
constructor(options?: TrustEvaluatorOptions);
|
|
49
|
+
get(domainOrOrigin: string, force?: boolean): Promise<TrustFetchResult>;
|
|
50
|
+
match(origin: string, role: string, countries?: readonly string[]): Promise<{
|
|
51
|
+
operator: string;
|
|
52
|
+
agent: TrustAgent;
|
|
53
|
+
record: TrustRecord;
|
|
54
|
+
freshUntil: number;
|
|
55
|
+
}>;
|
|
56
|
+
invalidate(domain: string): void;
|
|
57
|
+
hasAuthoritativeRecord(domain: string): boolean;
|
|
58
|
+
private now;
|
|
59
|
+
private request;
|
|
60
|
+
private fetch;
|
|
61
|
+
}
|
|
62
|
+
export interface DemandGrantClaim {
|
|
63
|
+
/** Only pass identity from an actual verifier. */
|
|
64
|
+
signerOrigin: string;
|
|
65
|
+
brand: {
|
|
66
|
+
domain: string;
|
|
67
|
+
brand_id?: string;
|
|
68
|
+
countries?: readonly string[];
|
|
69
|
+
};
|
|
70
|
+
accountOperator: string;
|
|
71
|
+
scope: string;
|
|
72
|
+
}
|
|
73
|
+
export interface DemandGrantAuthorization {
|
|
74
|
+
source: 'implicit' | 'trust' | 'seller' | 'legacy';
|
|
75
|
+
operator: string;
|
|
76
|
+
expiresAt?: number;
|
|
77
|
+
checkedAt: number;
|
|
78
|
+
chain: string[];
|
|
79
|
+
}
|
|
80
|
+
export interface DemandGrantOptions {
|
|
81
|
+
evaluator: TrustEvaluator;
|
|
82
|
+
now?: () => number;
|
|
83
|
+
/** Only evaluated for nonexclusive uncovered claims, never fetch failures. */
|
|
84
|
+
sellerAuthorization?: (claim: DemandGrantClaim) => Promise<boolean>;
|
|
85
|
+
/** Only for authoritative absence; never after a 200 or an exclusive record. */
|
|
86
|
+
legacyAuthorization?: (claim: DemandGrantClaim) => Promise<boolean>;
|
|
87
|
+
/** Seller-verified brand identity resolution, including the house's child-brand ID. Never accept a buyer-selected authorizer. */
|
|
88
|
+
resolveBrandHouse?: (brand: DemandGrantClaim['brand']) => Promise<{
|
|
89
|
+
domain: string;
|
|
90
|
+
brand_id: string;
|
|
91
|
+
} | undefined>;
|
|
92
|
+
}
|
|
93
|
+
/** Always invoke before sync_accounts side effects and before spend. No account mutation. */
|
|
94
|
+
export declare function authorizeDemandGrant(claim: DemandGrantClaim, options: DemandGrantOptions): Promise<DemandGrantAuthorization>;
|