@intentrax/sdk 1.2.0 → 1.3.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.
- package/README.md +37 -0
- package/cli/intentrax.mjs +1 -1
- package/index.d.ts +21 -2
- package/index.js +79 -8
- package/index.ts +79 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -223,3 +223,40 @@ validity, or regenerate a proof — `verified` is exactly the backend's
|
|
|
223
223
|
`"pass"`), never a raw signature; a value that looks like raw signing material
|
|
224
224
|
is refused so it can never leak. An absent or malformed envelope yields a safe,
|
|
225
225
|
non-verified reading rather than throwing.
|
|
226
|
+
|
|
227
|
+
Binding the rendered output to a proof (execute request `/1.1`):
|
|
228
|
+
|
|
229
|
+
```js
|
|
230
|
+
import { bindIntentExecuteOutput, verificationPointerMetaTag } from "@intentrax/sdk";
|
|
231
|
+
import { executeIntentHttp } from "@intentrax/sdk/http";
|
|
232
|
+
|
|
233
|
+
// Bind exactly the text the page will show inside its data-intentrax-output
|
|
234
|
+
// region(s). The request becomes schema /1.1 with an output_binding block.
|
|
235
|
+
const request = bindIntentExecuteOutput({
|
|
236
|
+
intent_id: "intent-refund-8812",
|
|
237
|
+
tenant_id: process.env.INTENTRAX_TENANT_ID,
|
|
238
|
+
action: "APPROVE_REFUND",
|
|
239
|
+
idempotency_key: "refund-8812-v1",
|
|
240
|
+
proof_chain_fixture_ref: "intent-execute",
|
|
241
|
+
schema_version: "intentrax.runtime.intent_execute.request/1.0",
|
|
242
|
+
}, renderedOutput);
|
|
243
|
+
|
|
244
|
+
const result = await executeIntentHttp(request, transport, {
|
|
245
|
+
base_url: process.env.INTENTRAX_BASE_URL,
|
|
246
|
+
api_key: process.env.INTENTRAX_API_KEY,
|
|
247
|
+
});
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
The engine seals the binding inside the signed proof (`aep.output_binding`,
|
|
251
|
+
`binding_source: PRODUCER_DECLARED_AT_ISSUANCE`), and the public verifier
|
|
252
|
+
relays it only from that signed proof. The browser extension recomputes the
|
|
253
|
+
`intentrax-content/1.0` hash over the page's visible marked output and shows the
|
|
254
|
+
green Verification Mark only when the proof is valid and the hashes match. A
|
|
255
|
+
copy of the proof id on different content stays neutral.
|
|
256
|
+
|
|
257
|
+
`validateIntentExecuteRequest` mirrors the engine: `output_binding` is accepted
|
|
258
|
+
only under `/1.1` (a `/1.0` body carrying it is refused as `body`), is decoded
|
|
259
|
+
strictly (exactly `content_hash`, `hash_algorithm`, `normalization`), and its
|
|
260
|
+
`content_hash` must be 64 lowercase hex, optionally `sha256:`-prefixed. `/1.0`
|
|
261
|
+
requests are unchanged. The execute lane is fail-closed per tenant (HTTP 423
|
|
262
|
+
until live execution is enabled, HTTP 403 until the tenant is allowlisted).
|
package/cli/intentrax.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
|
5
5
|
import { pathToFileURL } from "node:url";
|
|
6
6
|
import { buildAgentGatewayAdmissionEnvelope } from "../index.js";
|
|
7
7
|
|
|
8
|
-
const VERSION = "1.
|
|
8
|
+
const VERSION = "1.3.0";
|
|
9
9
|
const ADMISSION_SCHEMA_VERSION = "intentrax.runtime.agent_admission_request/1.0";
|
|
10
10
|
const INIT_SCHEMA_VERSION = "intentrax.onboarding.agent_adapter_init/1.0";
|
|
11
11
|
const ACTION_RECEIPT_SCHEMA_VERSION = "intentrax.onboarding.agent_adapter_action_receipt/1.0";
|
package/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export declare const AGENT_GATEWAY_ADMISSION_REQUEST_HASH_DOMAIN: "INTENTRAX_AGE
|
|
|
6
6
|
export declare const AGENT_ADMISSION_SCHEMA_VERSION: "intentrax.runtime.agent_admission_request/1.0";
|
|
7
7
|
export declare const AGENT_ADMISSION_ENDPOINT: "/v1/agent/admissions";
|
|
8
8
|
export declare const INTENT_EXECUTE_REQUEST_SCHEMA_VERSION: "intentrax.runtime.intent_execute.request/1.0";
|
|
9
|
+
export declare const INTENT_EXECUTE_REQUEST_SCHEMA_VERSION_V11: "intentrax.runtime.intent_execute.request/1.1";
|
|
9
10
|
export declare const INTENT_EXECUTE_ENDPOINT: "/v1/intents/execute";
|
|
10
11
|
export declare const INTENT_EXECUTE_MAX_REQUEST_BYTES: 4096;
|
|
11
12
|
export declare const RECEIPT_VERIFICATION_REQUEST_SCHEMA_VERSION: "intentrax.runtime.proof_verification.request/1.0";
|
|
@@ -45,14 +46,28 @@ export type AgentGatewayAdmissionRequest = {
|
|
|
45
46
|
idempotency_key_hash: string;
|
|
46
47
|
};
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
schema_version: "intentrax.runtime.intent_execute.request/1.0";
|
|
49
|
+
type IntentExecuteRequestFields = {
|
|
50
50
|
intent_id: string;
|
|
51
51
|
tenant_id: string;
|
|
52
52
|
action: string;
|
|
53
53
|
idempotency_key: string;
|
|
54
54
|
proof_chain_fixture_ref: string;
|
|
55
55
|
};
|
|
56
|
+
export type IntentExecuteRequestV10 = IntentExecuteRequestFields & {
|
|
57
|
+
schema_version: "intentrax.runtime.intent_execute.request/1.0";
|
|
58
|
+
};
|
|
59
|
+
// /1.1: the /1.0 fields plus an optional producer-declared output_binding that
|
|
60
|
+
// the engine seals into the signed proof. content_hash may be the bare 64
|
|
61
|
+
// lowercase hex buildOutputBinding emits or the same with a "sha256:" prefix.
|
|
62
|
+
export type IntentExecuteRequestV11 = IntentExecuteRequestFields & {
|
|
63
|
+
schema_version: "intentrax.runtime.intent_execute.request/1.1";
|
|
64
|
+
output_binding?: {
|
|
65
|
+
content_hash: string;
|
|
66
|
+
hash_algorithm: "SHA-256";
|
|
67
|
+
normalization: "intentrax-content/1.0";
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
export type IntentExecuteRequest = IntentExecuteRequestV10 | IntentExecuteRequestV11;
|
|
56
71
|
|
|
57
72
|
export type ReceiptVerificationRequest = {
|
|
58
73
|
schema_version: "intentrax.runtime.proof_verification.request/1.0";
|
|
@@ -208,6 +223,10 @@ export declare function buildVerifierHandoffEnvelope(request: VerifierHandoffReq
|
|
|
208
223
|
error: SDKError;
|
|
209
224
|
};
|
|
210
225
|
export declare function validateIntentExecuteRequest(request: unknown): string[];
|
|
226
|
+
export declare function bindIntentExecuteOutput(
|
|
227
|
+
request: IntentExecuteRequestFields & { schema_version?: string },
|
|
228
|
+
renderedOutput: string | readonly string[],
|
|
229
|
+
): IntentExecuteRequestV11 & { output_binding: OutputBinding };
|
|
211
230
|
export declare function buildIntentExecuteEnvelope(request: IntentExecuteRequest): {
|
|
212
231
|
status: "PASS";
|
|
213
232
|
output: {
|
package/index.js
CHANGED
|
@@ -12,6 +12,12 @@ export const AGENT_ADMISSION_ENDPOINT = "/v1/agent/admissions";
|
|
|
12
12
|
// (HTTP 423 until LiveExecutionEnabled, HTTP 403 until the tenant is
|
|
13
13
|
// allowlisted). See engine/internal/runtime/intentexecute/intentexecute.go.
|
|
14
14
|
export const INTENT_EXECUTE_REQUEST_SCHEMA_VERSION = "intentrax.runtime.intent_execute.request/1.0";
|
|
15
|
+
// /1.1 adds exactly one OPTIONAL field to /1.0: output_binding, the
|
|
16
|
+
// producer-declared `intentrax-content/1.0` hash of the rendered output. The
|
|
17
|
+
// engine seals it into the signed proof (aep.output_binding,
|
|
18
|
+
// binding_source PRODUCER_DECLARED_AT_ISSUANCE); see
|
|
19
|
+
// engine/internal/runtime/intentexecute/output_binding.go.
|
|
20
|
+
export const INTENT_EXECUTE_REQUEST_SCHEMA_VERSION_V11 = "intentrax.runtime.intent_execute.request/1.1";
|
|
15
21
|
export const INTENT_EXECUTE_ENDPOINT = "/v1/intents/execute";
|
|
16
22
|
// Mirrors intentexecute.MaxRequestBytes: the engine rejects a canonical body
|
|
17
23
|
// larger than this with HTTP 400.
|
|
@@ -65,6 +71,10 @@ const INTENT_EXECUTE_REQUIRED_FIELDS = [
|
|
|
65
71
|
"proof_chain_fixture_ref",
|
|
66
72
|
];
|
|
67
73
|
|
|
74
|
+
// The engine decodes a /1.1 output_binding with DisallowUnknownFields into
|
|
75
|
+
// exactly these three string fields (intentexecute.OutputBinding).
|
|
76
|
+
const INTENT_EXECUTE_OUTPUT_BINDING_FIELDS = ["content_hash", "hash_algorithm", "normalization"];
|
|
77
|
+
|
|
68
78
|
const RECEIPT_VERIFICATION_REQUIRED_FIELDS = [
|
|
69
79
|
"schema_version",
|
|
70
80
|
"receipt_id",
|
|
@@ -562,25 +572,31 @@ export function buildAgentGatewayAdmissionEnvelope(request) {
|
|
|
562
572
|
}
|
|
563
573
|
|
|
564
574
|
// validateIntentExecuteRequest mirrors the engine's intentexecute.validateRequest
|
|
565
|
-
// (and its DecodeRequest strictness): exactly the six fields
|
|
566
|
-
// action, and a canonical body
|
|
567
|
-
// NO proof/hash truth —
|
|
568
|
-
// response_hash are the
|
|
575
|
+
// (and its DecodeRequest strictness): exactly the six fields (plus an optional
|
|
576
|
+
// output_binding under /1.1 only), an UPPER_SNAKE action, and a canonical body
|
|
577
|
+
// no larger than the engine's limit. It computes NO proof/hash truth —
|
|
578
|
+
// receipt_id, request_hash, registry_proof_id, and response_hash are the
|
|
579
|
+
// engine's to produce.
|
|
569
580
|
export function validateIntentExecuteRequest(request) {
|
|
570
581
|
if (request === null || typeof request !== "object" || Array.isArray(request)) {
|
|
571
582
|
return ["intent_execute_request"];
|
|
572
583
|
}
|
|
573
584
|
const invalid = [];
|
|
585
|
+
const isV11 = request.schema_version === INTENT_EXECUTE_REQUEST_SCHEMA_VERSION_V11;
|
|
574
586
|
// Unknown fields are a 400 at the engine (DisallowUnknownFields); reject them
|
|
575
|
-
// here too so the SDK never emits a body the engine would refuse.
|
|
587
|
+
// here too so the SDK never emits a body the engine would refuse. A /1.0 body
|
|
588
|
+
// carrying output_binding is such an unknown field.
|
|
576
589
|
for (const key of Object.keys(request)) {
|
|
577
|
-
if (!INTENT_EXECUTE_REQUIRED_FIELDS.includes(key)) {
|
|
590
|
+
if (!INTENT_EXECUTE_REQUIRED_FIELDS.includes(key) && !(isV11 && key === "output_binding")) {
|
|
578
591
|
invalid.push("body");
|
|
579
592
|
}
|
|
580
593
|
}
|
|
581
|
-
if (request.schema_version !== INTENT_EXECUTE_REQUEST_SCHEMA_VERSION) {
|
|
594
|
+
if (request.schema_version !== INTENT_EXECUTE_REQUEST_SCHEMA_VERSION && !isV11) {
|
|
582
595
|
invalid.push("schema_version");
|
|
583
596
|
}
|
|
597
|
+
if (isV11 && Object.prototype.hasOwnProperty.call(request, "output_binding")) {
|
|
598
|
+
invalid.push(...validateIntentExecuteOutputBinding(request.output_binding));
|
|
599
|
+
}
|
|
584
600
|
if (!isNonEmptyStable(request.intent_id)) {
|
|
585
601
|
invalid.push("intent_id");
|
|
586
602
|
}
|
|
@@ -598,7 +614,10 @@ export function validateIntentExecuteRequest(request) {
|
|
|
598
614
|
if (!isNonEmptyStable(request.proof_chain_fixture_ref)) {
|
|
599
615
|
invalid.push("proof_chain_fixture_ref");
|
|
600
616
|
}
|
|
601
|
-
|
|
617
|
+
// Size-check only an otherwise-valid body: an invalid field (e.g. an explicit
|
|
618
|
+
// `undefined`) may not be canonicalizable, and must surface as a structured
|
|
619
|
+
// FAIL naming that field rather than a canonical_json throw.
|
|
620
|
+
if (invalid.length === 0) {
|
|
602
621
|
const canonicalBytes = Buffer.byteLength(canonicalJson(request), "utf8");
|
|
603
622
|
if (canonicalBytes > INTENT_EXECUTE_MAX_REQUEST_BYTES) {
|
|
604
623
|
invalid.push("body");
|
|
@@ -607,6 +626,58 @@ export function validateIntentExecuteRequest(request) {
|
|
|
607
626
|
return [...new Set(invalid)].sort();
|
|
608
627
|
}
|
|
609
628
|
|
|
629
|
+
// validateIntentExecuteOutputBinding mirrors the engine's decodeOutputBinding +
|
|
630
|
+
// validateOutputBinding: a non-null object of exactly the three string fields
|
|
631
|
+
// (anything else is a decode error, reported as "output_binding"), then a
|
|
632
|
+
// sealable content_hash, the SHA-256 algorithm and the intentrax-content/1.0
|
|
633
|
+
// normalization.
|
|
634
|
+
function validateIntentExecuteOutputBinding(binding) {
|
|
635
|
+
if (binding === null || typeof binding !== "object" || Array.isArray(binding)) {
|
|
636
|
+
return ["output_binding"];
|
|
637
|
+
}
|
|
638
|
+
for (const key of Object.keys(binding)) {
|
|
639
|
+
if (!INTENT_EXECUTE_OUTPUT_BINDING_FIELDS.includes(key) || typeof binding[key] !== "string") {
|
|
640
|
+
return ["output_binding"];
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
const invalid = [];
|
|
644
|
+
if (!isSealableOutputContentHash(binding.content_hash)) {
|
|
645
|
+
invalid.push("output_binding.content_hash");
|
|
646
|
+
}
|
|
647
|
+
if (binding.hash_algorithm !== CANONICAL_OUTPUT_HASH_ALGORITHM) {
|
|
648
|
+
invalid.push("output_binding.hash_algorithm");
|
|
649
|
+
}
|
|
650
|
+
if (binding.normalization !== CANONICAL_OUTPUT_NORMALIZATION) {
|
|
651
|
+
invalid.push("output_binding.normalization");
|
|
652
|
+
}
|
|
653
|
+
return invalid;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
// isSealableOutputContentHash mirrors the engine's sealedContentHash: the bare
|
|
657
|
+
// 64 lowercase hex the SDK emits, or the same with a "sha256:" prefix. Uppercase,
|
|
658
|
+
// other prefixes, other lengths, and a degenerate digest (one repeated digit)
|
|
659
|
+
// are refused.
|
|
660
|
+
function isSealableOutputContentHash(value) {
|
|
661
|
+
if (typeof value !== "string") return false;
|
|
662
|
+
const digest = value.startsWith("sha256:") ? value.slice("sha256:".length) : value;
|
|
663
|
+
if (!SHA256_RE.test(digest)) return false;
|
|
664
|
+
return digest.split("").some((char) => char !== digest[0]);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
// bindIntentExecuteOutput returns a NEW /1.1 execute request: the caller's
|
|
668
|
+
// request with schema_version /1.1 and output_binding = buildOutputBinding of
|
|
669
|
+
// the output the producer is about to render. The input is not mutated. Pass
|
|
670
|
+
// the result to buildIntentExecuteEnvelope / executeIntentHttp, which validate
|
|
671
|
+
// it. Bind exactly what the page will show inside its data-intentrax-output
|
|
672
|
+
// region(s): the browser extension recomputes this hash over that visible text.
|
|
673
|
+
export function bindIntentExecuteOutput(request, renderedOutput) {
|
|
674
|
+
return {
|
|
675
|
+
...request,
|
|
676
|
+
schema_version: INTENT_EXECUTE_REQUEST_SCHEMA_VERSION_V11,
|
|
677
|
+
output_binding: buildOutputBinding(renderedOutput),
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
|
|
610
681
|
// buildIntentExecuteEnvelope is a THIN envelope builder: it validates and
|
|
611
682
|
// passes the caller-supplied body through verbatim. It performs no hashing and
|
|
612
683
|
// asserts no proof truth.
|
package/index.ts
CHANGED
|
@@ -12,6 +12,12 @@ export const AGENT_ADMISSION_ENDPOINT = "/v1/agent/admissions";
|
|
|
12
12
|
// (HTTP 423 until LiveExecutionEnabled, HTTP 403 until the tenant is
|
|
13
13
|
// allowlisted). See engine/internal/runtime/intentexecute/intentexecute.go.
|
|
14
14
|
export const INTENT_EXECUTE_REQUEST_SCHEMA_VERSION = "intentrax.runtime.intent_execute.request/1.0";
|
|
15
|
+
// /1.1 adds exactly one OPTIONAL field to /1.0: output_binding, the
|
|
16
|
+
// producer-declared `intentrax-content/1.0` hash of the rendered output. The
|
|
17
|
+
// engine seals it into the signed proof (aep.output_binding,
|
|
18
|
+
// binding_source PRODUCER_DECLARED_AT_ISSUANCE); see
|
|
19
|
+
// engine/internal/runtime/intentexecute/output_binding.go.
|
|
20
|
+
export const INTENT_EXECUTE_REQUEST_SCHEMA_VERSION_V11 = "intentrax.runtime.intent_execute.request/1.1";
|
|
15
21
|
export const INTENT_EXECUTE_ENDPOINT = "/v1/intents/execute";
|
|
16
22
|
// Mirrors intentexecute.MaxRequestBytes: the engine rejects a canonical body
|
|
17
23
|
// larger than this with HTTP 400.
|
|
@@ -65,6 +71,10 @@ const INTENT_EXECUTE_REQUIRED_FIELDS = [
|
|
|
65
71
|
"proof_chain_fixture_ref",
|
|
66
72
|
];
|
|
67
73
|
|
|
74
|
+
// The engine decodes a /1.1 output_binding with DisallowUnknownFields into
|
|
75
|
+
// exactly these three string fields (intentexecute.OutputBinding).
|
|
76
|
+
const INTENT_EXECUTE_OUTPUT_BINDING_FIELDS = ["content_hash", "hash_algorithm", "normalization"];
|
|
77
|
+
|
|
68
78
|
const RECEIPT_VERIFICATION_REQUIRED_FIELDS = [
|
|
69
79
|
"schema_version",
|
|
70
80
|
"receipt_id",
|
|
@@ -562,25 +572,31 @@ export function buildAgentGatewayAdmissionEnvelope(request) {
|
|
|
562
572
|
}
|
|
563
573
|
|
|
564
574
|
// validateIntentExecuteRequest mirrors the engine's intentexecute.validateRequest
|
|
565
|
-
// (and its DecodeRequest strictness): exactly the six fields
|
|
566
|
-
// action, and a canonical body
|
|
567
|
-
// NO proof/hash truth —
|
|
568
|
-
// response_hash are the
|
|
575
|
+
// (and its DecodeRequest strictness): exactly the six fields (plus an optional
|
|
576
|
+
// output_binding under /1.1 only), an UPPER_SNAKE action, and a canonical body
|
|
577
|
+
// no larger than the engine's limit. It computes NO proof/hash truth —
|
|
578
|
+
// receipt_id, request_hash, registry_proof_id, and response_hash are the
|
|
579
|
+
// engine's to produce.
|
|
569
580
|
export function validateIntentExecuteRequest(request) {
|
|
570
581
|
if (request === null || typeof request !== "object" || Array.isArray(request)) {
|
|
571
582
|
return ["intent_execute_request"];
|
|
572
583
|
}
|
|
573
584
|
const invalid = [];
|
|
585
|
+
const isV11 = request.schema_version === INTENT_EXECUTE_REQUEST_SCHEMA_VERSION_V11;
|
|
574
586
|
// Unknown fields are a 400 at the engine (DisallowUnknownFields); reject them
|
|
575
|
-
// here too so the SDK never emits a body the engine would refuse.
|
|
587
|
+
// here too so the SDK never emits a body the engine would refuse. A /1.0 body
|
|
588
|
+
// carrying output_binding is such an unknown field.
|
|
576
589
|
for (const key of Object.keys(request)) {
|
|
577
|
-
if (!INTENT_EXECUTE_REQUIRED_FIELDS.includes(key)) {
|
|
590
|
+
if (!INTENT_EXECUTE_REQUIRED_FIELDS.includes(key) && !(isV11 && key === "output_binding")) {
|
|
578
591
|
invalid.push("body");
|
|
579
592
|
}
|
|
580
593
|
}
|
|
581
|
-
if (request.schema_version !== INTENT_EXECUTE_REQUEST_SCHEMA_VERSION) {
|
|
594
|
+
if (request.schema_version !== INTENT_EXECUTE_REQUEST_SCHEMA_VERSION && !isV11) {
|
|
582
595
|
invalid.push("schema_version");
|
|
583
596
|
}
|
|
597
|
+
if (isV11 && Object.prototype.hasOwnProperty.call(request, "output_binding")) {
|
|
598
|
+
invalid.push(...validateIntentExecuteOutputBinding(request.output_binding));
|
|
599
|
+
}
|
|
584
600
|
if (!isNonEmptyStable(request.intent_id)) {
|
|
585
601
|
invalid.push("intent_id");
|
|
586
602
|
}
|
|
@@ -598,7 +614,10 @@ export function validateIntentExecuteRequest(request) {
|
|
|
598
614
|
if (!isNonEmptyStable(request.proof_chain_fixture_ref)) {
|
|
599
615
|
invalid.push("proof_chain_fixture_ref");
|
|
600
616
|
}
|
|
601
|
-
|
|
617
|
+
// Size-check only an otherwise-valid body: an invalid field (e.g. an explicit
|
|
618
|
+
// `undefined`) may not be canonicalizable, and must surface as a structured
|
|
619
|
+
// FAIL naming that field rather than a canonical_json throw.
|
|
620
|
+
if (invalid.length === 0) {
|
|
602
621
|
const canonicalBytes = Buffer.byteLength(canonicalJson(request), "utf8");
|
|
603
622
|
if (canonicalBytes > INTENT_EXECUTE_MAX_REQUEST_BYTES) {
|
|
604
623
|
invalid.push("body");
|
|
@@ -607,6 +626,58 @@ export function validateIntentExecuteRequest(request) {
|
|
|
607
626
|
return [...new Set(invalid)].sort();
|
|
608
627
|
}
|
|
609
628
|
|
|
629
|
+
// validateIntentExecuteOutputBinding mirrors the engine's decodeOutputBinding +
|
|
630
|
+
// validateOutputBinding: a non-null object of exactly the three string fields
|
|
631
|
+
// (anything else is a decode error, reported as "output_binding"), then a
|
|
632
|
+
// sealable content_hash, the SHA-256 algorithm and the intentrax-content/1.0
|
|
633
|
+
// normalization.
|
|
634
|
+
function validateIntentExecuteOutputBinding(binding) {
|
|
635
|
+
if (binding === null || typeof binding !== "object" || Array.isArray(binding)) {
|
|
636
|
+
return ["output_binding"];
|
|
637
|
+
}
|
|
638
|
+
for (const key of Object.keys(binding)) {
|
|
639
|
+
if (!INTENT_EXECUTE_OUTPUT_BINDING_FIELDS.includes(key) || typeof binding[key] !== "string") {
|
|
640
|
+
return ["output_binding"];
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
const invalid = [];
|
|
644
|
+
if (!isSealableOutputContentHash(binding.content_hash)) {
|
|
645
|
+
invalid.push("output_binding.content_hash");
|
|
646
|
+
}
|
|
647
|
+
if (binding.hash_algorithm !== CANONICAL_OUTPUT_HASH_ALGORITHM) {
|
|
648
|
+
invalid.push("output_binding.hash_algorithm");
|
|
649
|
+
}
|
|
650
|
+
if (binding.normalization !== CANONICAL_OUTPUT_NORMALIZATION) {
|
|
651
|
+
invalid.push("output_binding.normalization");
|
|
652
|
+
}
|
|
653
|
+
return invalid;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
// isSealableOutputContentHash mirrors the engine's sealedContentHash: the bare
|
|
657
|
+
// 64 lowercase hex the SDK emits, or the same with a "sha256:" prefix. Uppercase,
|
|
658
|
+
// other prefixes, other lengths, and a degenerate digest (one repeated digit)
|
|
659
|
+
// are refused.
|
|
660
|
+
function isSealableOutputContentHash(value) {
|
|
661
|
+
if (typeof value !== "string") return false;
|
|
662
|
+
const digest = value.startsWith("sha256:") ? value.slice("sha256:".length) : value;
|
|
663
|
+
if (!SHA256_RE.test(digest)) return false;
|
|
664
|
+
return digest.split("").some((char) => char !== digest[0]);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
// bindIntentExecuteOutput returns a NEW /1.1 execute request: the caller's
|
|
668
|
+
// request with schema_version /1.1 and output_binding = buildOutputBinding of
|
|
669
|
+
// the output the producer is about to render. The input is not mutated. Pass
|
|
670
|
+
// the result to buildIntentExecuteEnvelope / executeIntentHttp, which validate
|
|
671
|
+
// it. Bind exactly what the page will show inside its data-intentrax-output
|
|
672
|
+
// region(s): the browser extension recomputes this hash over that visible text.
|
|
673
|
+
export function bindIntentExecuteOutput(request, renderedOutput) {
|
|
674
|
+
return {
|
|
675
|
+
...request,
|
|
676
|
+
schema_version: INTENT_EXECUTE_REQUEST_SCHEMA_VERSION_V11,
|
|
677
|
+
output_binding: buildOutputBinding(renderedOutput),
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
|
|
610
681
|
// buildIntentExecuteEnvelope is a THIN envelope builder: it validates and
|
|
611
682
|
// passes the caller-supplied body through verbatim. It performs no hashing and
|
|
612
683
|
// asserts no proof truth.
|