xoonya 1.26.0 → 2.0.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/FINAL_CONTRACT.md +1 -1
- package/README.md +59 -0
- package/SERVICE_CONTRACT.md +46 -0
- package/package.json +1 -1
- package/proof_sdk.js +871 -6
- package/server.js +300 -0
package/proof_sdk.js
CHANGED
|
@@ -1048,6 +1048,7 @@ function canonicalizeInteractionResultPackageHandoff(input) {
|
|
|
1048
1048
|
const seamLayers = normalizeStringArray(handoff.seam_layers, "handoff_bundle.seam_layers") || [];
|
|
1049
1049
|
const deliveryCount = Number.isFinite(Number(handoff.delivery_count)) ? Number(handoff.delivery_count) : 0;
|
|
1050
1050
|
const paymentLedgerCount = Number.isFinite(Number(handoff.payment_ledger_count)) ? Number(handoff.payment_ledger_count) : 0;
|
|
1051
|
+
const economicCarry = extractEconomicConsequenceCarry(handoff);
|
|
1051
1052
|
return {
|
|
1052
1053
|
result_package_ref: resultPackageRef,
|
|
1053
1054
|
source_ref: sourceRef,
|
|
@@ -1062,7 +1063,39 @@ function canonicalizeInteractionResultPackageHandoff(input) {
|
|
|
1062
1063
|
task_refs: taskRefs,
|
|
1063
1064
|
delivery_count: deliveryCount,
|
|
1064
1065
|
payment_ledger_count: paymentLedgerCount,
|
|
1065
|
-
seam_layers: seamLayers
|
|
1066
|
+
seam_layers: seamLayers,
|
|
1067
|
+
economic_consequence_handoff_bundle: economicCarry.handoff_bundle,
|
|
1068
|
+
economic_consequence_review: economicCarry.review
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
function extractEconomicConsequenceCarry(handoff) {
|
|
1073
|
+
const bundle = handoff && handoff.economic_consequence_handoff_bundle && typeof handoff.economic_consequence_handoff_bundle === "object" && !Array.isArray(handoff.economic_consequence_handoff_bundle)
|
|
1074
|
+
? handoff.economic_consequence_handoff_bundle
|
|
1075
|
+
: null;
|
|
1076
|
+
if (!bundle) {
|
|
1077
|
+
return {
|
|
1078
|
+
handoff_bundle: null,
|
|
1079
|
+
review: null
|
|
1080
|
+
};
|
|
1081
|
+
}
|
|
1082
|
+
const conformance = buildEconomicConsequenceConformancePack({
|
|
1083
|
+
handoff_bundle: bundle
|
|
1084
|
+
});
|
|
1085
|
+
return {
|
|
1086
|
+
handoff_bundle: bundle,
|
|
1087
|
+
review: {
|
|
1088
|
+
detected: true,
|
|
1089
|
+
conformance_pack_ref: conformance.conformance_pack_ref,
|
|
1090
|
+
account_ref: conformance.deterministic_consequence.account_ref,
|
|
1091
|
+
usage_meter_ref: conformance.deterministic_consequence.usage_meter_ref,
|
|
1092
|
+
credit_spend_ref: conformance.deterministic_consequence.credit_spend_ref,
|
|
1093
|
+
usage_units: conformance.deterministic_consequence.usage_units,
|
|
1094
|
+
pricing_band: conformance.deterministic_consequence.pricing_band,
|
|
1095
|
+
meter_profile_ref: conformance.deterministic_consequence.meter_profile_ref,
|
|
1096
|
+
next_surface: conformance.next_surface,
|
|
1097
|
+
review_summary_surface: conformance.review_summary_surface
|
|
1098
|
+
}
|
|
1066
1099
|
};
|
|
1067
1100
|
}
|
|
1068
1101
|
|
|
@@ -1130,7 +1163,10 @@ function buildInteractionResultPackageHandoffEvent(input) {
|
|
|
1130
1163
|
task_refs: handoff.task_refs,
|
|
1131
1164
|
delivery_count: handoff.delivery_count,
|
|
1132
1165
|
payment_ledger_count: handoff.payment_ledger_count,
|
|
1133
|
-
seam_layers: handoff.seam_layers
|
|
1166
|
+
seam_layers: handoff.seam_layers,
|
|
1167
|
+
economic_consequence_ref: handoff.economic_consequence_review
|
|
1168
|
+
? handoff.economic_consequence_review.conformance_pack_ref
|
|
1169
|
+
: null
|
|
1134
1170
|
});
|
|
1135
1171
|
return canonicalizeEvent({
|
|
1136
1172
|
version: CANONICAL_EVENT_BUNDLE_VERSION,
|
|
@@ -1187,7 +1223,10 @@ function runInteractionSpineProofHandoff(input) {
|
|
|
1187
1223
|
handoff_kind: "interaction_spine_proof_handoff",
|
|
1188
1224
|
source_ref: handoff.source_ref,
|
|
1189
1225
|
committed_ref: handoff.committed_ref || null,
|
|
1190
|
-
precommit_pack_ref: handoff.precommit_pack_ref || null
|
|
1226
|
+
precommit_pack_ref: handoff.precommit_pack_ref || null,
|
|
1227
|
+
economic_consequence_ref: handoff.economic_consequence_review
|
|
1228
|
+
? handoff.economic_consequence_review.conformance_pack_ref
|
|
1229
|
+
: null
|
|
1191
1230
|
}
|
|
1192
1231
|
});
|
|
1193
1232
|
return {
|
|
@@ -1198,6 +1237,7 @@ function runInteractionSpineProofHandoff(input) {
|
|
|
1198
1237
|
receipt,
|
|
1199
1238
|
proof_bundle: proofBundle,
|
|
1200
1239
|
bundle_verification: verifyProofBundle(proofBundle),
|
|
1240
|
+
economic_consequence_review: handoff.economic_consequence_review || null,
|
|
1201
1241
|
recommended_loop: "default.proof.bundle.loop"
|
|
1202
1242
|
};
|
|
1203
1243
|
}
|
|
@@ -1218,7 +1258,10 @@ function runInteractionResultPackageHandoff(input) {
|
|
|
1218
1258
|
result_package_ref: handoff.result_package_ref,
|
|
1219
1259
|
source_ref: handoff.source_ref,
|
|
1220
1260
|
committed_ref: handoff.committed_ref || null,
|
|
1221
|
-
precommit_pack_ref: handoff.precommit_pack_ref || null
|
|
1261
|
+
precommit_pack_ref: handoff.precommit_pack_ref || null,
|
|
1262
|
+
economic_consequence_ref: handoff.economic_consequence_review
|
|
1263
|
+
? handoff.economic_consequence_review.conformance_pack_ref
|
|
1264
|
+
: null
|
|
1222
1265
|
}
|
|
1223
1266
|
});
|
|
1224
1267
|
return {
|
|
@@ -1229,6 +1272,7 @@ function runInteractionResultPackageHandoff(input) {
|
|
|
1229
1272
|
receipt,
|
|
1230
1273
|
proof_bundle: proofBundle,
|
|
1231
1274
|
bundle_verification: verifyProofBundle(proofBundle),
|
|
1275
|
+
economic_consequence_review: handoff.economic_consequence_review || null,
|
|
1232
1276
|
recommended_loop: "default.proof.bundle.loop"
|
|
1233
1277
|
};
|
|
1234
1278
|
}
|
|
@@ -1292,6 +1336,9 @@ function summarizeInteractionResultPackageHandoff(bundle) {
|
|
|
1292
1336
|
precommit_pack_ref: handoff.precommit_pack_ref || null,
|
|
1293
1337
|
seam_layer_count: Array.isArray(handoff.seam_layers) ? handoff.seam_layers.length : 0,
|
|
1294
1338
|
task_ref_count: Array.isArray(handoff.task_refs) ? handoff.task_refs.length : 0,
|
|
1339
|
+
economic_consequence_ready: Boolean(handoff.economic_consequence_review),
|
|
1340
|
+
usage_meter_ref: handoff.economic_consequence_review ? handoff.economic_consequence_review.usage_meter_ref : null,
|
|
1341
|
+
credit_spend_ref: handoff.economic_consequence_review ? handoff.economic_consequence_review.credit_spend_ref : null,
|
|
1295
1342
|
proof_bundle_version: proofBundle.version || null,
|
|
1296
1343
|
emitted_receipt_id: receipt.receipt_id || null,
|
|
1297
1344
|
bundle_valid: verification.valid === true,
|
|
@@ -1328,7 +1375,8 @@ function reviewInteractionResultPackageHandoff(input) {
|
|
|
1328
1375
|
economic_state: {
|
|
1329
1376
|
payment_protocol: handoff.payment_protocol || null,
|
|
1330
1377
|
settlement_mode: handoff.settlement_mode || null,
|
|
1331
|
-
treasury_destination_id: handoff.treasury_destination_id || null
|
|
1378
|
+
treasury_destination_id: handoff.treasury_destination_id || null,
|
|
1379
|
+
economic_consequence_review: handoff.economic_consequence_review || null
|
|
1332
1380
|
},
|
|
1333
1381
|
proof_handoff: {
|
|
1334
1382
|
source_ref: handoff.source_ref || null,
|
|
@@ -1339,6 +1387,7 @@ function reviewInteractionResultPackageHandoff(input) {
|
|
|
1339
1387
|
run_ready: Boolean(handoff.transaction_id && handoff.receipt_id && handoff.proof_ref),
|
|
1340
1388
|
next_surface: "/v1/proof-center/result-package-handoff/run"
|
|
1341
1389
|
},
|
|
1390
|
+
economic_consequence_review: handoff.economic_consequence_review || null,
|
|
1342
1391
|
recommended_loop: "default.proof.bundle.loop",
|
|
1343
1392
|
next_surface: "/v1/proof-center/result-package-handoff/run"
|
|
1344
1393
|
};
|
|
@@ -1359,7 +1408,11 @@ function summarizeReviewedInteractionResultPackageHandoff(input) {
|
|
|
1359
1408
|
review_ref: durability.review_ref || null,
|
|
1360
1409
|
run_ready: durability.run_ready === true,
|
|
1361
1410
|
next_surface: durability.next_surface || review.next_surface || null,
|
|
1362
|
-
preserved_seam_layer_count: Number(proofHandoff.seam_layer_count || 0)
|
|
1411
|
+
preserved_seam_layer_count: Number(proofHandoff.seam_layer_count || 0),
|
|
1412
|
+
economic_consequence_ready: Boolean(review.economic_consequence_review),
|
|
1413
|
+
usage_meter_ref: review.economic_consequence_review ? review.economic_consequence_review.usage_meter_ref : null,
|
|
1414
|
+
credit_spend_ref: review.economic_consequence_review ? review.economic_consequence_review.credit_spend_ref : null,
|
|
1415
|
+
economic_consequence_review: review.economic_consequence_review || null
|
|
1363
1416
|
};
|
|
1364
1417
|
}
|
|
1365
1418
|
|
|
@@ -1948,6 +2001,788 @@ function summarizeReviewCompleteDefaultPathRun(input) {
|
|
|
1948
2001
|
};
|
|
1949
2002
|
}
|
|
1950
2003
|
|
|
2004
|
+
function normalizeBridgeInput(input) {
|
|
2005
|
+
return input && typeof input === "object" && !Array.isArray(input) ? input : {};
|
|
2006
|
+
}
|
|
2007
|
+
|
|
2008
|
+
function buildBridgeRef(prefix, seed) {
|
|
2009
|
+
const stableSeed = canonicalize(seed);
|
|
2010
|
+
return `${prefix}.${sha256Hex(Buffer.from(stableSeed, "utf8")).slice(0, 16)}`;
|
|
2011
|
+
}
|
|
2012
|
+
|
|
2013
|
+
function payloadBufferFromBridgeInput(input) {
|
|
2014
|
+
const body = normalizeBridgeInput(input);
|
|
2015
|
+
if (typeof body.payload_bytes_hex === "string" && body.payload_bytes_hex.trim()) {
|
|
2016
|
+
const hex = body.payload_bytes_hex.trim().toLowerCase();
|
|
2017
|
+
if (!/^[a-f0-9]+$/.test(hex) || hex.length % 2 !== 0) {
|
|
2018
|
+
throw new Error("payload_bytes_hex_invalid");
|
|
2019
|
+
}
|
|
2020
|
+
return Buffer.from(hex, "hex");
|
|
2021
|
+
}
|
|
2022
|
+
if (typeof body.payload_base64 === "string" && body.payload_base64.trim()) {
|
|
2023
|
+
return Buffer.from(body.payload_base64, "base64");
|
|
2024
|
+
}
|
|
2025
|
+
if (typeof body.payload_utf8 === "string") {
|
|
2026
|
+
return Buffer.from(body.payload_utf8, "utf8");
|
|
2027
|
+
}
|
|
2028
|
+
if (typeof body.payload_ascii === "string") {
|
|
2029
|
+
return Buffer.from(body.payload_ascii, "ascii");
|
|
2030
|
+
}
|
|
2031
|
+
throw new Error("payload_required");
|
|
2032
|
+
}
|
|
2033
|
+
|
|
2034
|
+
function verifyAnyCompatibilityReceipt(opreturnHex, payloadBytes) {
|
|
2035
|
+
const parsed = parseReceipt(opreturnHex);
|
|
2036
|
+
return parsed.spec_version === "v2"
|
|
2037
|
+
? verifyReceiptV2(opreturnHex, payloadBytes)
|
|
2038
|
+
: verifyReceipt(opreturnHex, payloadBytes);
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
function buildBridgeCenter() {
|
|
2042
|
+
return {
|
|
2043
|
+
center_ref: "proof-center.bridge",
|
|
2044
|
+
receipt_wrap_surface: "/v1/proof-center/bridge/receipt-wrap",
|
|
2045
|
+
validator_verify_surface: "/v1/proof-center/bridge/validator-verify",
|
|
2046
|
+
receipt_ledger_handoff_surface: "/v1/proof-center/bridge/receipt-ledger-handoff",
|
|
2047
|
+
economic_handoff_surface: "/v1/proof-center/bridge/economic-handoff",
|
|
2048
|
+
economic_conformance_pack_surface: "/v1/proof-center/bridge/economic-conformance-pack",
|
|
2049
|
+
operator_review_pack_surface: "/v1/proof-center/bridge/operator-review-pack",
|
|
2050
|
+
compatibility_pack_surface: "/v1/proof-center/bridge/compatibility-pack",
|
|
2051
|
+
supported_profiles: [
|
|
2052
|
+
"economic-receipt-profile-v1",
|
|
2053
|
+
"registry-profile-v1",
|
|
2054
|
+
"proof-envelope-v1"
|
|
2055
|
+
],
|
|
2056
|
+
supported_capabilities: [
|
|
2057
|
+
"receipt_wrap",
|
|
2058
|
+
"validator_compatible_verification",
|
|
2059
|
+
"receipt_ledger_handoff",
|
|
2060
|
+
"economic_consequence_handoff",
|
|
2061
|
+
"economic_consequence_conformance",
|
|
2062
|
+
"operator_review_packaging",
|
|
2063
|
+
"compatibility_packaging",
|
|
2064
|
+
"profile_carry"
|
|
2065
|
+
]
|
|
2066
|
+
};
|
|
2067
|
+
}
|
|
2068
|
+
|
|
2069
|
+
function summarizeBridgeCenter() {
|
|
2070
|
+
const center = buildBridgeCenter();
|
|
2071
|
+
return {
|
|
2072
|
+
center_ref: center.center_ref,
|
|
2073
|
+
capability_count: center.supported_capabilities.length,
|
|
2074
|
+
profile_count: center.supported_profiles.length,
|
|
2075
|
+
receipt_ledger_handoff_surface: center.receipt_ledger_handoff_surface,
|
|
2076
|
+
economic_handoff_surface: center.economic_handoff_surface,
|
|
2077
|
+
operator_review_pack_surface: center.operator_review_pack_surface
|
|
2078
|
+
};
|
|
2079
|
+
}
|
|
2080
|
+
|
|
2081
|
+
function buildBridgeReceiptWrap(input) {
|
|
2082
|
+
const body = normalizeBridgeInput(input);
|
|
2083
|
+
const payloadBytes = payloadBufferFromBridgeInput(body);
|
|
2084
|
+
const identityMaterialHex = normalizeString(body.identity_material_hex);
|
|
2085
|
+
if (!identityMaterialHex) {
|
|
2086
|
+
throw new Error("identity_material_hex_required");
|
|
2087
|
+
}
|
|
2088
|
+
const typeHex = normalizeString(body.type_hex || TYPE_REGISTER) || TYPE_REGISTER;
|
|
2089
|
+
const contextHash12Hex = normalizeString(body.context_hash12_hex);
|
|
2090
|
+
const receipt = contextHash12Hex
|
|
2091
|
+
? createReceiptV2(identityMaterialHex, payloadBytes, contextHash12Hex, typeHex)
|
|
2092
|
+
: createReceipt(identityMaterialHex, payloadBytes, typeHex);
|
|
2093
|
+
const verification = verifyAnyCompatibilityReceipt(receipt.opreturn_hex, payloadBytes);
|
|
2094
|
+
return {
|
|
2095
|
+
ok: verification.valid === true,
|
|
2096
|
+
wrap_ref: buildBridgeRef("bridge.receipt-wrap", {
|
|
2097
|
+
receipt_ref: receipt.opreturn_hex,
|
|
2098
|
+
type_hex: typeHex,
|
|
2099
|
+
payload_hash: receipt.payload_hash
|
|
2100
|
+
}),
|
|
2101
|
+
receipt,
|
|
2102
|
+
verification,
|
|
2103
|
+
validator_verify_surface: "/v1/proof-center/bridge/validator-verify",
|
|
2104
|
+
receipt_inspect_surface: "/v1/receipts/inspect"
|
|
2105
|
+
};
|
|
2106
|
+
}
|
|
2107
|
+
|
|
2108
|
+
function summarizeBridgeValidatorVerify(input) {
|
|
2109
|
+
const body = normalizeBridgeInput(input);
|
|
2110
|
+
const opreturnHex = normalizeString(body.opreturn_hex).toLowerCase();
|
|
2111
|
+
if (!opreturnHex) {
|
|
2112
|
+
throw new Error("opreturn_hex_required");
|
|
2113
|
+
}
|
|
2114
|
+
const payloadBytes = payloadBufferFromBridgeInput(body);
|
|
2115
|
+
const verification = verifyAnyCompatibilityReceipt(opreturnHex, payloadBytes);
|
|
2116
|
+
return {
|
|
2117
|
+
...verification,
|
|
2118
|
+
validator_ref: buildBridgeRef("bridge.validator", {
|
|
2119
|
+
opreturn_hex: opreturnHex,
|
|
2120
|
+
payload_hash: sha256Hex(payloadBytes)
|
|
2121
|
+
}),
|
|
2122
|
+
verification_surface: "/validate",
|
|
2123
|
+
receipt_inspect_surface: "/v1/receipts/inspect"
|
|
2124
|
+
};
|
|
2125
|
+
}
|
|
2126
|
+
|
|
2127
|
+
function unwrapEconomicBridgeInput(input) {
|
|
2128
|
+
const body = normalizeBridgeInput(input);
|
|
2129
|
+
if (body.handoff_bundle && typeof body.handoff_bundle === "object" && !Array.isArray(body.handoff_bundle)) {
|
|
2130
|
+
return body.handoff_bundle;
|
|
2131
|
+
}
|
|
2132
|
+
return body;
|
|
2133
|
+
}
|
|
2134
|
+
|
|
2135
|
+
function buildReceiptLedgerBridgeHandoff(input) {
|
|
2136
|
+
const body = normalizeBridgeInput(input);
|
|
2137
|
+
const receiptRef = normalizeString(body.receipt_ref);
|
|
2138
|
+
const opreturnHex = normalizeString(body.opreturn_hex).toLowerCase();
|
|
2139
|
+
if (!receiptRef) throw new Error("receipt_ref_required");
|
|
2140
|
+
if (!opreturnHex) throw new Error("opreturn_hex_required");
|
|
2141
|
+
const payloadBytes = payloadBufferFromBridgeInput(body);
|
|
2142
|
+
const accountRef = normalizeString(body.account_ref);
|
|
2143
|
+
const usageReportRef = normalizeString(body.usage_report_ref);
|
|
2144
|
+
const meterProfileRef = normalizeString(body.meter_profile_ref);
|
|
2145
|
+
const ledgerEntryRef = normalizeString(body.ledger_entry_ref);
|
|
2146
|
+
const ledgerOperation = normalizeString(body.ledger_operation).toUpperCase();
|
|
2147
|
+
const unitsActual = Number(body.units_actual);
|
|
2148
|
+
const usageReport = body.usage_report && typeof body.usage_report === "object" && !Array.isArray(body.usage_report)
|
|
2149
|
+
? body.usage_report
|
|
2150
|
+
: null;
|
|
2151
|
+
const ledgerEntry = body.ledger_entry && typeof body.ledger_entry === "object" && !Array.isArray(body.ledger_entry)
|
|
2152
|
+
? body.ledger_entry
|
|
2153
|
+
: null;
|
|
2154
|
+
|
|
2155
|
+
if (!accountRef) throw new Error("account_ref_required");
|
|
2156
|
+
if (!usageReportRef) throw new Error("usage_report_ref_required");
|
|
2157
|
+
if (!meterProfileRef) throw new Error("meter_profile_ref_required");
|
|
2158
|
+
if (!ledgerEntryRef) throw new Error("ledger_entry_ref_required");
|
|
2159
|
+
if (!new Set(["RESERVE", "COMMIT", "RELEASE", "REVERSE"]).has(ledgerOperation)) {
|
|
2160
|
+
throw new Error("ledger_operation_invalid");
|
|
2161
|
+
}
|
|
2162
|
+
if (!Number.isInteger(unitsActual) || unitsActual <= 0) throw new Error("units_actual_invalid");
|
|
2163
|
+
if (!usageReport) throw new Error("usage_report_required");
|
|
2164
|
+
if (!ledgerEntry) throw new Error("ledger_entry_required");
|
|
2165
|
+
|
|
2166
|
+
const verification = verifyAnyCompatibilityReceipt(opreturnHex, payloadBytes);
|
|
2167
|
+
if (!verification.valid) {
|
|
2168
|
+
throw new Error(`invalid_receipt:${verification.reason || "invalid"}`);
|
|
2169
|
+
}
|
|
2170
|
+
|
|
2171
|
+
if (usageReport.account_ref && normalizeString(usageReport.account_ref) !== accountRef) throw new Error("usage_report_account_mismatch");
|
|
2172
|
+
if (usageReport.units_actual != null && Number(usageReport.units_actual) !== unitsActual) throw new Error("usage_report_units_mismatch");
|
|
2173
|
+
if (ledgerEntry.account_ref && normalizeString(ledgerEntry.account_ref) !== accountRef) throw new Error("ledger_entry_account_mismatch");
|
|
2174
|
+
if (ledgerEntry.operation && normalizeString(ledgerEntry.operation).toUpperCase() !== ledgerOperation) throw new Error("ledger_entry_operation_mismatch");
|
|
2175
|
+
if (ledgerEntry.receipt_ref && normalizeString(ledgerEntry.receipt_ref) !== receiptRef) throw new Error("ledger_entry_receipt_mismatch");
|
|
2176
|
+
if (ledgerEntry.units != null && Math.abs(Number(ledgerEntry.units)) !== unitsActual) throw new Error("ledger_entry_units_mismatch");
|
|
2177
|
+
|
|
2178
|
+
const handoff = {
|
|
2179
|
+
mode: "xoonya-receipt-ledger-handoff-v1",
|
|
2180
|
+
generated_at_iso: new Date().toISOString(),
|
|
2181
|
+
proof_receipt: {
|
|
2182
|
+
receipt_ref: receiptRef,
|
|
2183
|
+
receipt_hash_sha256: sha256Hex(Buffer.from(opreturnHex, "hex")),
|
|
2184
|
+
receipt_version: verification.spec_version || "v1",
|
|
2185
|
+
opreturn_hex: opreturnHex,
|
|
2186
|
+
validation_result: {
|
|
2187
|
+
valid: verification.valid === true,
|
|
2188
|
+
reason: verification.reason || null
|
|
2189
|
+
},
|
|
2190
|
+
compliance_hash: verification.compliance_hash || null,
|
|
2191
|
+
agent_id: verification.agent_id || null
|
|
2192
|
+
},
|
|
2193
|
+
economics_context: {
|
|
2194
|
+
target_system: "xytara",
|
|
2195
|
+
account_ref: accountRef,
|
|
2196
|
+
usage_report_ref: usageReportRef,
|
|
2197
|
+
usage_report_hash: canonicalJsonSha256Hex(usageReport),
|
|
2198
|
+
usage_report: usageReport,
|
|
2199
|
+
meter_profile_ref: meterProfileRef,
|
|
2200
|
+
units_actual: unitsActual,
|
|
2201
|
+
ledger_operation: ledgerOperation,
|
|
2202
|
+
ledger_entry_ref: ledgerEntryRef,
|
|
2203
|
+
ledger_entry_hash: canonicalJsonSha256Hex(ledgerEntry),
|
|
2204
|
+
ledger_entry: ledgerEntry
|
|
2205
|
+
}
|
|
2206
|
+
};
|
|
2207
|
+
return {
|
|
2208
|
+
ok: true,
|
|
2209
|
+
handoff_ref: buildBridgeRef("bridge.receipt-ledger-handoff", handoff),
|
|
2210
|
+
handoff,
|
|
2211
|
+
next_surface: "/v1/proof-center/governance/interpretation-validate"
|
|
2212
|
+
};
|
|
2213
|
+
}
|
|
2214
|
+
|
|
2215
|
+
function buildEconomicConsequenceBridgeHandoff(input) {
|
|
2216
|
+
const body = unwrapEconomicBridgeInput(input);
|
|
2217
|
+
const accountRef = normalizeString(body.account_ref);
|
|
2218
|
+
const usageMeterRef = normalizeString(body.usage_meter_ref);
|
|
2219
|
+
const meterProfileRef = normalizeString(body.meter_profile_ref);
|
|
2220
|
+
const creditSpendRef = normalizeString(body.credit_spend_ref);
|
|
2221
|
+
const usageMeter = body.usage_meter && typeof body.usage_meter === "object" && !Array.isArray(body.usage_meter)
|
|
2222
|
+
? body.usage_meter
|
|
2223
|
+
: null;
|
|
2224
|
+
const creditSpend = body.credit_spend && typeof body.credit_spend === "object" && !Array.isArray(body.credit_spend)
|
|
2225
|
+
? body.credit_spend
|
|
2226
|
+
: null;
|
|
2227
|
+
if (!accountRef) throw new Error("account_ref_required");
|
|
2228
|
+
if (!usageMeterRef) throw new Error("usage_meter_ref_required");
|
|
2229
|
+
if (!meterProfileRef) throw new Error("meter_profile_ref_required");
|
|
2230
|
+
if (!creditSpendRef) throw new Error("credit_spend_ref_required");
|
|
2231
|
+
if (!usageMeter) throw new Error("usage_meter_required");
|
|
2232
|
+
if (!creditSpend) throw new Error("credit_spend_required");
|
|
2233
|
+
if (usageMeter.account_id && normalizeString(usageMeter.account_id) !== accountRef) throw new Error("usage_meter_account_mismatch");
|
|
2234
|
+
if (creditSpend.account_id && normalizeString(creditSpend.account_id) !== accountRef) throw new Error("credit_spend_account_mismatch");
|
|
2235
|
+
if (usageMeter.credit_spend_id && normalizeString(usageMeter.credit_spend_id) !== creditSpendRef) throw new Error("usage_meter_credit_spend_mismatch");
|
|
2236
|
+
if (creditSpend.credit_spend_id && normalizeString(creditSpend.credit_spend_id) !== creditSpendRef) throw new Error("credit_spend_ref_mismatch");
|
|
2237
|
+
if (usageMeter.units != null && creditSpend.units != null && Number(usageMeter.units) !== Number(creditSpend.units)) {
|
|
2238
|
+
throw new Error("usage_meter_units_mismatch");
|
|
2239
|
+
}
|
|
2240
|
+
const handoff = {
|
|
2241
|
+
mode: "xoonya-economic-consequence-handoff-v1",
|
|
2242
|
+
generated_at_iso: new Date().toISOString(),
|
|
2243
|
+
economics_context: {
|
|
2244
|
+
target_system: "xytara",
|
|
2245
|
+
account_ref: accountRef,
|
|
2246
|
+
usage_meter_ref: usageMeterRef,
|
|
2247
|
+
usage_meter_hash: canonicalJsonSha256Hex(usageMeter),
|
|
2248
|
+
usage_meter: usageMeter,
|
|
2249
|
+
meter_profile_ref: meterProfileRef,
|
|
2250
|
+
credit_spend_ref: creditSpendRef,
|
|
2251
|
+
credit_spend_hash: canonicalJsonSha256Hex(creditSpend),
|
|
2252
|
+
credit_spend: creditSpend
|
|
2253
|
+
}
|
|
2254
|
+
};
|
|
2255
|
+
return {
|
|
2256
|
+
ok: true,
|
|
2257
|
+
handoff_ref: buildBridgeRef("bridge.economic-consequence-handoff", handoff),
|
|
2258
|
+
handoff,
|
|
2259
|
+
next_surface: "/v1/proof-center/governance/interpretation-validate",
|
|
2260
|
+
review_summary_surface: "/v1/proof-center/result-package-handoff/review/summary"
|
|
2261
|
+
};
|
|
2262
|
+
}
|
|
2263
|
+
|
|
2264
|
+
function buildEconomicConsequenceConformancePack(input) {
|
|
2265
|
+
const handoffBundle = buildEconomicConsequenceBridgeHandoff(input);
|
|
2266
|
+
const economicsContext = handoffBundle.handoff.economics_context;
|
|
2267
|
+
return {
|
|
2268
|
+
ok: true,
|
|
2269
|
+
conformance_pack_ref: buildBridgeRef("bridge.economic-conformance-pack", {
|
|
2270
|
+
usage_meter_ref: economicsContext.usage_meter_ref,
|
|
2271
|
+
credit_spend_ref: economicsContext.credit_spend_ref,
|
|
2272
|
+
account_ref: economicsContext.account_ref
|
|
2273
|
+
}),
|
|
2274
|
+
deterministic_consequence: {
|
|
2275
|
+
account_ref: economicsContext.account_ref,
|
|
2276
|
+
usage_meter_ref: economicsContext.usage_meter_ref,
|
|
2277
|
+
credit_spend_ref: economicsContext.credit_spend_ref,
|
|
2278
|
+
usage_units: Number(economicsContext.usage_meter.units || 0),
|
|
2279
|
+
pricing_band: normalizeString(economicsContext.usage_meter.pricing_band || null) || null,
|
|
2280
|
+
meter_profile_ref: economicsContext.meter_profile_ref
|
|
2281
|
+
},
|
|
2282
|
+
preserved_routes: [
|
|
2283
|
+
"/v1/proof-center/bridge/economic-handoff",
|
|
2284
|
+
"/v1/proof-center/bridge/economic-conformance-pack",
|
|
2285
|
+
"/v1/proof-center/governance/interpretation-validate",
|
|
2286
|
+
"/v1/proof-center/result-package-handoff/review/summary"
|
|
2287
|
+
],
|
|
2288
|
+
next_surface: "/v1/proof-center/governance/interpretation-validate",
|
|
2289
|
+
review_summary_surface: "/v1/proof-center/result-package-handoff/review/summary"
|
|
2290
|
+
};
|
|
2291
|
+
}
|
|
2292
|
+
|
|
2293
|
+
function buildBridgeOperatorReviewPack(input) {
|
|
2294
|
+
const body = normalizeBridgeInput(input);
|
|
2295
|
+
const sourceRef = normalizeString(body.source_ref || body.receipt_ref || "proof-bridge.source");
|
|
2296
|
+
const operatorPackRef = buildBridgeRef("bridge.operator-review-pack", {
|
|
2297
|
+
source_ref: sourceRef,
|
|
2298
|
+
account_ref: normalizeString(body.account_ref || "")
|
|
2299
|
+
});
|
|
2300
|
+
return {
|
|
2301
|
+
ok: true,
|
|
2302
|
+
operator_review_pack_ref: operatorPackRef,
|
|
2303
|
+
source_ref: sourceRef,
|
|
2304
|
+
included_sections: [
|
|
2305
|
+
"bridge_summary",
|
|
2306
|
+
"validator_verification",
|
|
2307
|
+
"economic_consequence_review",
|
|
2308
|
+
"profile_carry",
|
|
2309
|
+
"governance_review_link",
|
|
2310
|
+
"proof_run_link"
|
|
2311
|
+
],
|
|
2312
|
+
bridge_summary_surface: "/v1/proof-center/bridge/summary",
|
|
2313
|
+
validator_verify_surface: "/v1/proof-center/bridge/validator-verify",
|
|
2314
|
+
economic_handoff_surface: "/v1/proof-center/bridge/economic-handoff",
|
|
2315
|
+
economic_conformance_pack_surface: "/v1/proof-center/bridge/economic-conformance-pack",
|
|
2316
|
+
compatibility_pack_surface: "/v1/proof-center/bridge/compatibility-pack",
|
|
2317
|
+
governance_review_link_surface: "/v1/proof-center/governance/review-link",
|
|
2318
|
+
proof_run_surface: "/v1/proof-center/result-package-handoff/run"
|
|
2319
|
+
};
|
|
2320
|
+
}
|
|
2321
|
+
|
|
2322
|
+
function buildBridgeCompatibilityPack(input) {
|
|
2323
|
+
const body = normalizeBridgeInput(input);
|
|
2324
|
+
return {
|
|
2325
|
+
ok: true,
|
|
2326
|
+
compatibility_pack_ref: buildBridgeRef("bridge.compatibility-pack", {
|
|
2327
|
+
source_ref: normalizeString(body.source_ref || body.receipt_ref || "proof-bridge.compatibility")
|
|
2328
|
+
}),
|
|
2329
|
+
preserved_routes: [
|
|
2330
|
+
"/validate",
|
|
2331
|
+
"/v1/receipts/inspect",
|
|
2332
|
+
"/v1/proofs/verify",
|
|
2333
|
+
"/v1/profiles/economic/verify",
|
|
2334
|
+
"/v1/profiles/registry/verify"
|
|
2335
|
+
],
|
|
2336
|
+
preserved_helpers: [
|
|
2337
|
+
"createReceipt",
|
|
2338
|
+
"verifyReceipt",
|
|
2339
|
+
"createReceiptV2",
|
|
2340
|
+
"verifyReceiptV2",
|
|
2341
|
+
"createProofEnvelopeV1",
|
|
2342
|
+
"verifyProofEnvelopeV1",
|
|
2343
|
+
"createEconomicReceiptProfileV1",
|
|
2344
|
+
"verifyEconomicReceiptProfileV1",
|
|
2345
|
+
"createRegistryProfileV1",
|
|
2346
|
+
"verifyRegistryProfileV1"
|
|
2347
|
+
],
|
|
2348
|
+
profile_versions: [
|
|
2349
|
+
"proof-envelope-v1",
|
|
2350
|
+
"economic-receipt-profile-v1",
|
|
2351
|
+
"registry-profile-v1"
|
|
2352
|
+
],
|
|
2353
|
+
posture: "compatibility_support_preserved_for_bridge_and_validator_alignment"
|
|
2354
|
+
};
|
|
2355
|
+
}
|
|
2356
|
+
|
|
2357
|
+
function buildBridgeProfileSupport() {
|
|
2358
|
+
return {
|
|
2359
|
+
support_ref: "bridge.profile-support",
|
|
2360
|
+
proof_profile_versions: [
|
|
2361
|
+
"proof-envelope-v1",
|
|
2362
|
+
"economic-receipt-profile-v1",
|
|
2363
|
+
"registry-profile-v1"
|
|
2364
|
+
],
|
|
2365
|
+
payload_profile_examples: [
|
|
2366
|
+
"AgentProfile-v1",
|
|
2367
|
+
"CapabilitiesProfile-v1",
|
|
2368
|
+
"SessionProfile-v1",
|
|
2369
|
+
"AttestationProfile-v1"
|
|
2370
|
+
],
|
|
2371
|
+
interoperability_notes: [
|
|
2372
|
+
"profiles_extend_proof_context_without_mutating_core_receipt_shape",
|
|
2373
|
+
"resolver_behavior_remains_part_of_interoperability_posture",
|
|
2374
|
+
"bridge_support_packages_are_operator_exports_not_new_protocol_layers"
|
|
2375
|
+
],
|
|
2376
|
+
verification_surfaces: [
|
|
2377
|
+
"/v1/proofs/verify",
|
|
2378
|
+
"/v1/profiles/economic/verify",
|
|
2379
|
+
"/v1/profiles/registry/verify"
|
|
2380
|
+
]
|
|
2381
|
+
};
|
|
2382
|
+
}
|
|
2383
|
+
|
|
2384
|
+
function buildBridgeWorkflowPack(input) {
|
|
2385
|
+
const operatorReviewPack = buildBridgeOperatorReviewPack(input);
|
|
2386
|
+
const compatibilityPack = buildBridgeCompatibilityPack(input);
|
|
2387
|
+
return {
|
|
2388
|
+
ok: true,
|
|
2389
|
+
workflow_pack_ref: buildBridgeRef("bridge.workflow-pack", {
|
|
2390
|
+
operator_review_pack_ref: operatorReviewPack.operator_review_pack_ref,
|
|
2391
|
+
compatibility_pack_ref: compatibilityPack.compatibility_pack_ref
|
|
2392
|
+
}),
|
|
2393
|
+
refs: {
|
|
2394
|
+
operator_review_pack_ref: operatorReviewPack.operator_review_pack_ref,
|
|
2395
|
+
compatibility_pack_ref: compatibilityPack.compatibility_pack_ref
|
|
2396
|
+
},
|
|
2397
|
+
workflow_steps: [
|
|
2398
|
+
"receipt_wrap_or_receive",
|
|
2399
|
+
"validator_verify",
|
|
2400
|
+
"economic_consequence_handoff",
|
|
2401
|
+
"inspect_profile_support",
|
|
2402
|
+
"review_operator_pack",
|
|
2403
|
+
"handoff_or_run"
|
|
2404
|
+
],
|
|
2405
|
+
guidance: [
|
|
2406
|
+
"use_bridge_support_packs_for_portable_review_and_export",
|
|
2407
|
+
"keep_public_proof_center_as_the_canonical_runtime_surface"
|
|
2408
|
+
]
|
|
2409
|
+
};
|
|
2410
|
+
}
|
|
2411
|
+
|
|
2412
|
+
function buildBridgeAdminPack(input) {
|
|
2413
|
+
const workflowPack = buildBridgeWorkflowPack(input);
|
|
2414
|
+
const profileSupport = buildBridgeProfileSupport();
|
|
2415
|
+
return {
|
|
2416
|
+
ok: true,
|
|
2417
|
+
admin_pack_ref: buildBridgeRef("bridge.admin-pack", {
|
|
2418
|
+
workflow_pack_ref: workflowPack.workflow_pack_ref,
|
|
2419
|
+
support_ref: profileSupport.support_ref
|
|
2420
|
+
}),
|
|
2421
|
+
operator_refs: {
|
|
2422
|
+
workflow_pack_ref: workflowPack.workflow_pack_ref,
|
|
2423
|
+
operator_review_pack_ref: workflowPack.refs.operator_review_pack_ref,
|
|
2424
|
+
compatibility_pack_ref: workflowPack.refs.compatibility_pack_ref,
|
|
2425
|
+
economic_handoff_surface: "/v1/proof-center/bridge/economic-handoff",
|
|
2426
|
+
economic_conformance_pack_surface: "/v1/proof-center/bridge/economic-conformance-pack"
|
|
2427
|
+
},
|
|
2428
|
+
governance_refs: {
|
|
2429
|
+
governance_dashboard_surface: "/v1/proof-center/governance/dashboard",
|
|
2430
|
+
governance_review_link_surface: "/v1/proof-center/governance/review-link"
|
|
2431
|
+
},
|
|
2432
|
+
proof_refs: {
|
|
2433
|
+
profile_support_ref: profileSupport.support_ref,
|
|
2434
|
+
proof_run_surface: "/v1/proof-center/result-package-handoff/run"
|
|
2435
|
+
},
|
|
2436
|
+
notes: [
|
|
2437
|
+
"admin_pack_is_a_portable_operator_export",
|
|
2438
|
+
"admin_pack_does_not_mutate_proof_or_profile_semantics"
|
|
2439
|
+
]
|
|
2440
|
+
};
|
|
2441
|
+
}
|
|
2442
|
+
|
|
2443
|
+
function buildGovernanceCenter() {
|
|
2444
|
+
return {
|
|
2445
|
+
center_ref: "proof-center.governance",
|
|
2446
|
+
interpretation_surface: "/v1/proof-center/governance/interpretation-validate",
|
|
2447
|
+
coordination_surface: "/v1/proof-center/governance/coordination",
|
|
2448
|
+
dashboard_surface: "/v1/proof-center/governance/dashboard",
|
|
2449
|
+
operator_view_surface: "/v1/proof-center/governance/operator-view",
|
|
2450
|
+
admin_view_surface: "/v1/proof-center/governance/admin-view",
|
|
2451
|
+
dispute_summary_surface: "/v1/proof-center/governance/disputes/summary",
|
|
2452
|
+
dispute_action_surface: "/v1/proof-center/governance/disputes/action",
|
|
2453
|
+
dispute_resolution_pack_surface: "/v1/proof-center/governance/disputes/resolution-pack",
|
|
2454
|
+
review_link_surface: "/v1/proof-center/governance/review-link",
|
|
2455
|
+
handoff_bundle_surface: "/v1/proof-center/governance/handoff-bundle",
|
|
2456
|
+
supported_capabilities: [
|
|
2457
|
+
"interpretation_validation",
|
|
2458
|
+
"governance_coordination",
|
|
2459
|
+
"dashboard_summary",
|
|
2460
|
+
"operator_view",
|
|
2461
|
+
"admin_view",
|
|
2462
|
+
"workflow_packaging",
|
|
2463
|
+
"signoff_packaging",
|
|
2464
|
+
"dispute_review",
|
|
2465
|
+
"dispute_resolution_packaging",
|
|
2466
|
+
"review_linkage",
|
|
2467
|
+
"operator_handoff_bundle"
|
|
2468
|
+
]
|
|
2469
|
+
};
|
|
2470
|
+
}
|
|
2471
|
+
|
|
2472
|
+
function summarizeGovernanceCenter() {
|
|
2473
|
+
const center = buildGovernanceCenter();
|
|
2474
|
+
return {
|
|
2475
|
+
center_ref: center.center_ref,
|
|
2476
|
+
capability_count: center.supported_capabilities.length,
|
|
2477
|
+
dashboard_surface: center.dashboard_surface,
|
|
2478
|
+
dispute_summary_surface: center.dispute_summary_surface,
|
|
2479
|
+
review_link_surface: center.review_link_surface,
|
|
2480
|
+
handoff_bundle_surface: center.handoff_bundle_surface
|
|
2481
|
+
};
|
|
2482
|
+
}
|
|
2483
|
+
|
|
2484
|
+
function normalizeGovernanceInput(input) {
|
|
2485
|
+
return input && typeof input === "object" && !Array.isArray(input) ? input : {};
|
|
2486
|
+
}
|
|
2487
|
+
|
|
2488
|
+
function buildGovernanceRef(prefix, seed) {
|
|
2489
|
+
const stableSeed = canonicalize(seed);
|
|
2490
|
+
return `${prefix}.${sha256Hex(Buffer.from(stableSeed, "utf8")).slice(0, 16)}`;
|
|
2491
|
+
}
|
|
2492
|
+
|
|
2493
|
+
function validateGovernanceInterpretation(input) {
|
|
2494
|
+
const body = normalizeGovernanceInput(input);
|
|
2495
|
+
const sourceRef = normalizeString(body.source_ref || body.result_package_ref || body.receipt_ref || "governance.source");
|
|
2496
|
+
const interpretationRef = buildGovernanceRef("governance.interpretation", {
|
|
2497
|
+
source_ref: sourceRef,
|
|
2498
|
+
case_ref: normalizeString(body.case_ref || ""),
|
|
2499
|
+
interpretation_context: body.interpretation_context || null
|
|
2500
|
+
});
|
|
2501
|
+
return {
|
|
2502
|
+
ok: true,
|
|
2503
|
+
interpretation_ref: interpretationRef,
|
|
2504
|
+
source_ref: sourceRef,
|
|
2505
|
+
interpretation_status: "validated",
|
|
2506
|
+
accepted_inputs: [
|
|
2507
|
+
"result_package_ref",
|
|
2508
|
+
"receipt_ref",
|
|
2509
|
+
"case_ref"
|
|
2510
|
+
],
|
|
2511
|
+
next_surface: "/v1/proof-center/governance/coordination"
|
|
2512
|
+
};
|
|
2513
|
+
}
|
|
2514
|
+
|
|
2515
|
+
function emitGovernanceCoordination(input) {
|
|
2516
|
+
const interpretation = validateGovernanceInterpretation(input);
|
|
2517
|
+
return {
|
|
2518
|
+
ok: interpretation.ok,
|
|
2519
|
+
interpretation_ref: interpretation.interpretation_ref,
|
|
2520
|
+
coordination_ref: buildGovernanceRef("governance.coordination", {
|
|
2521
|
+
interpretation_ref: interpretation.interpretation_ref,
|
|
2522
|
+
source_ref: interpretation.source_ref
|
|
2523
|
+
}),
|
|
2524
|
+
coordination_status: "ready",
|
|
2525
|
+
coordination_surfaces: [
|
|
2526
|
+
"/v1/proof-center/governance/workflow-pack",
|
|
2527
|
+
"/v1/proof-center/governance/signoff-pack",
|
|
2528
|
+
"/v1/proof-center/governance/handoff-bundle"
|
|
2529
|
+
],
|
|
2530
|
+
next_surface: "/v1/proof-center/result-package-handoff/run"
|
|
2531
|
+
};
|
|
2532
|
+
}
|
|
2533
|
+
|
|
2534
|
+
function summarizeGovernanceDashboard(input) {
|
|
2535
|
+
const body = normalizeGovernanceInput(input);
|
|
2536
|
+
const accountRef = normalizeString(body.account_ref || body.operator_ref || "governance.account");
|
|
2537
|
+
const dashboardRef = buildGovernanceRef("governance.dashboard", {
|
|
2538
|
+
account_ref: accountRef,
|
|
2539
|
+
queue_scope: normalizeString(body.queue_scope || "default")
|
|
2540
|
+
});
|
|
2541
|
+
const reviewCount = Number.isFinite(body.review_count) ? body.review_count : 3;
|
|
2542
|
+
const disputeCount = Number.isFinite(body.dispute_count) ? body.dispute_count : 1;
|
|
2543
|
+
return {
|
|
2544
|
+
ok: true,
|
|
2545
|
+
dashboard_ref: dashboardRef,
|
|
2546
|
+
account_ref: accountRef,
|
|
2547
|
+
queue_summary: {
|
|
2548
|
+
review_count: reviewCount,
|
|
2549
|
+
dispute_count: disputeCount,
|
|
2550
|
+
signoff_ready_count: Number.isFinite(body.signoff_ready_count) ? body.signoff_ready_count : 1
|
|
2551
|
+
},
|
|
2552
|
+
proof_linkage: {
|
|
2553
|
+
review_summary_surface: "/v1/proof-center/result-package-handoff/review/summary",
|
|
2554
|
+
handoff_run_surface: "/v1/proof-center/result-package-handoff/review/handoff-run"
|
|
2555
|
+
},
|
|
2556
|
+
dashboard_pack_surface: "/v1/proof-center/governance/dashboard-pack",
|
|
2557
|
+
workflow_pack_surface: "/v1/proof-center/governance/workflow-pack",
|
|
2558
|
+
signoff_pack_surface: "/v1/proof-center/governance/signoff-pack"
|
|
2559
|
+
};
|
|
2560
|
+
}
|
|
2561
|
+
|
|
2562
|
+
function summarizeGovernanceOperatorView(input) {
|
|
2563
|
+
const dashboard = summarizeGovernanceDashboard(input);
|
|
2564
|
+
return {
|
|
2565
|
+
ok: dashboard.ok,
|
|
2566
|
+
operator_view_ref: buildGovernanceRef("governance.operator-view", dashboard),
|
|
2567
|
+
dashboard_ref: dashboard.dashboard_ref,
|
|
2568
|
+
queue_summary: dashboard.queue_summary,
|
|
2569
|
+
attention_refs: [
|
|
2570
|
+
"governance.review.queue",
|
|
2571
|
+
"governance.dispute.queue",
|
|
2572
|
+
"governance.signoff.queue"
|
|
2573
|
+
],
|
|
2574
|
+
dashboard_pack_surface: dashboard.dashboard_pack_surface,
|
|
2575
|
+
review_link_surface: "/v1/proof-center/governance/review-link"
|
|
2576
|
+
};
|
|
2577
|
+
}
|
|
2578
|
+
|
|
2579
|
+
function summarizeGovernanceAdminView(input) {
|
|
2580
|
+
const operatorView = summarizeGovernanceOperatorView(input);
|
|
2581
|
+
return {
|
|
2582
|
+
ok: operatorView.ok,
|
|
2583
|
+
admin_view_ref: buildGovernanceRef("governance.admin-view", operatorView),
|
|
2584
|
+
operator_view_ref: operatorView.operator_view_ref,
|
|
2585
|
+
oversight_summary: {
|
|
2586
|
+
queue_count: 3,
|
|
2587
|
+
escalation_ready_count: 1,
|
|
2588
|
+
signoff_ready_count: operatorView.queue_summary.signoff_ready_count
|
|
2589
|
+
},
|
|
2590
|
+
workflow_pack_surface: "/v1/proof-center/governance/workflow-pack",
|
|
2591
|
+
signoff_pack_surface: "/v1/proof-center/governance/signoff-pack"
|
|
2592
|
+
};
|
|
2593
|
+
}
|
|
2594
|
+
|
|
2595
|
+
function buildGovernanceDashboardPack(input) {
|
|
2596
|
+
const dashboard = summarizeGovernanceDashboard(input);
|
|
2597
|
+
return {
|
|
2598
|
+
ok: dashboard.ok,
|
|
2599
|
+
dashboard_ref: dashboard.dashboard_ref,
|
|
2600
|
+
pack_ref: buildGovernanceRef("governance.dashboard-pack", dashboard),
|
|
2601
|
+
included_sections: [
|
|
2602
|
+
"queue_summary",
|
|
2603
|
+
"workflow_refs",
|
|
2604
|
+
"signoff_refs"
|
|
2605
|
+
]
|
|
2606
|
+
};
|
|
2607
|
+
}
|
|
2608
|
+
|
|
2609
|
+
function buildGovernanceWorkflowPack(input) {
|
|
2610
|
+
const coordination = emitGovernanceCoordination(input);
|
|
2611
|
+
return {
|
|
2612
|
+
ok: coordination.ok,
|
|
2613
|
+
coordination_ref: coordination.coordination_ref,
|
|
2614
|
+
workflow_pack_ref: buildGovernanceRef("governance.workflow-pack", coordination),
|
|
2615
|
+
included_sections: [
|
|
2616
|
+
"interpretation_status",
|
|
2617
|
+
"coordination_status",
|
|
2618
|
+
"next_surfaces",
|
|
2619
|
+
"review_linkage"
|
|
2620
|
+
],
|
|
2621
|
+
review_summary_surface: "/v1/proof-center/result-package-handoff/review/summary",
|
|
2622
|
+
handoff_run_surface: "/v1/proof-center/result-package-handoff/review/handoff-run"
|
|
2623
|
+
};
|
|
2624
|
+
}
|
|
2625
|
+
|
|
2626
|
+
function buildGovernanceSignoffPack(input) {
|
|
2627
|
+
const dashboard = summarizeGovernanceDashboard(input);
|
|
2628
|
+
return {
|
|
2629
|
+
ok: dashboard.ok,
|
|
2630
|
+
dashboard_ref: dashboard.dashboard_ref,
|
|
2631
|
+
signoff_pack_ref: buildGovernanceRef("governance.signoff-pack", dashboard),
|
|
2632
|
+
signoff_status: "review_ready",
|
|
2633
|
+
included_sections: [
|
|
2634
|
+
"queue_summary",
|
|
2635
|
+
"signoff_ready_refs",
|
|
2636
|
+
"review_linkage"
|
|
2637
|
+
],
|
|
2638
|
+
review_link_surface: "/v1/proof-center/governance/review-link"
|
|
2639
|
+
};
|
|
2640
|
+
}
|
|
2641
|
+
|
|
2642
|
+
function summarizeGovernanceDisputes(input) {
|
|
2643
|
+
const body = normalizeGovernanceInput(input);
|
|
2644
|
+
const queueRef = buildGovernanceRef("governance.disputes", {
|
|
2645
|
+
account_ref: normalizeString(body.account_ref || ""),
|
|
2646
|
+
dispute_scope: normalizeString(body.dispute_scope || "default")
|
|
2647
|
+
});
|
|
2648
|
+
const caseCount = Number.isFinite(body.case_count) ? body.case_count : 2;
|
|
2649
|
+
return {
|
|
2650
|
+
ok: true,
|
|
2651
|
+
dispute_queue_ref: queueRef,
|
|
2652
|
+
case_count: caseCount,
|
|
2653
|
+
open_case_count: Number.isFinite(body.open_case_count) ? body.open_case_count : Math.max(caseCount - 1, 1),
|
|
2654
|
+
case_review_surface: "/v1/proof-center/governance/disputes/case-review",
|
|
2655
|
+
case_bundle_surface: "/v1/proof-center/governance/disputes/case-bundle"
|
|
2656
|
+
};
|
|
2657
|
+
}
|
|
2658
|
+
|
|
2659
|
+
function reviewGovernanceCase(input) {
|
|
2660
|
+
const body = normalizeGovernanceInput(input);
|
|
2661
|
+
const caseRef = normalizeString(body.case_ref || body.dispute_id || "governance.case");
|
|
2662
|
+
return {
|
|
2663
|
+
ok: true,
|
|
2664
|
+
case_ref: caseRef,
|
|
2665
|
+
review_ref: buildGovernanceRef("governance.case-review", {
|
|
2666
|
+
case_ref: caseRef,
|
|
2667
|
+
source_ref: normalizeString(body.source_ref || "")
|
|
2668
|
+
}),
|
|
2669
|
+
review_status: "triaged",
|
|
2670
|
+
available_actions: [
|
|
2671
|
+
"handoff",
|
|
2672
|
+
"resolve",
|
|
2673
|
+
"dismiss"
|
|
2674
|
+
],
|
|
2675
|
+
resolution_pack_surface: "/v1/proof-center/governance/disputes/resolution-pack",
|
|
2676
|
+
case_bundle_surface: "/v1/proof-center/governance/disputes/case-bundle"
|
|
2677
|
+
};
|
|
2678
|
+
}
|
|
2679
|
+
|
|
2680
|
+
function summarizeGovernanceDisputeAction(input) {
|
|
2681
|
+
const review = reviewGovernanceCase(input);
|
|
2682
|
+
const body = normalizeGovernanceInput(input);
|
|
2683
|
+
const requestedAction = normalizeString(body.action || "handoff");
|
|
2684
|
+
const allowedActions = new Set(review.available_actions);
|
|
2685
|
+
const action = allowedActions.has(requestedAction) ? requestedAction : "handoff";
|
|
2686
|
+
return {
|
|
2687
|
+
ok: true,
|
|
2688
|
+
case_ref: review.case_ref,
|
|
2689
|
+
action_ref: buildGovernanceRef("governance.dispute-action", {
|
|
2690
|
+
case_ref: review.case_ref,
|
|
2691
|
+
action
|
|
2692
|
+
}),
|
|
2693
|
+
action,
|
|
2694
|
+
action_status: "recorded",
|
|
2695
|
+
next_surface: action === "handoff"
|
|
2696
|
+
? "/v1/proof-center/governance/handoff-bundle"
|
|
2697
|
+
: "/v1/proof-center/governance/disputes/resolution-pack"
|
|
2698
|
+
};
|
|
2699
|
+
}
|
|
2700
|
+
|
|
2701
|
+
function buildGovernanceCaseBundle(input) {
|
|
2702
|
+
const review = reviewGovernanceCase(input);
|
|
2703
|
+
return {
|
|
2704
|
+
ok: review.ok,
|
|
2705
|
+
case_ref: review.case_ref,
|
|
2706
|
+
case_bundle_ref: buildGovernanceRef("governance.case-bundle", review),
|
|
2707
|
+
included_sections: [
|
|
2708
|
+
"review_status",
|
|
2709
|
+
"available_actions",
|
|
2710
|
+
"handoff_refs"
|
|
2711
|
+
],
|
|
2712
|
+
resolution_pack_surface: review.resolution_pack_surface
|
|
2713
|
+
};
|
|
2714
|
+
}
|
|
2715
|
+
|
|
2716
|
+
function buildGovernanceResolutionPack(input) {
|
|
2717
|
+
const action = summarizeGovernanceDisputeAction(input);
|
|
2718
|
+
return {
|
|
2719
|
+
ok: action.ok,
|
|
2720
|
+
case_ref: action.case_ref,
|
|
2721
|
+
resolution_pack_ref: buildGovernanceRef("governance.resolution-pack", action),
|
|
2722
|
+
action_ref: action.action_ref,
|
|
2723
|
+
resolution_status: action.action === "dismiss" ? "dismissed" : "resolved_or_handoff_ready",
|
|
2724
|
+
included_sections: [
|
|
2725
|
+
"action_status",
|
|
2726
|
+
"case_resolution_refs",
|
|
2727
|
+
"next_surface"
|
|
2728
|
+
]
|
|
2729
|
+
};
|
|
2730
|
+
}
|
|
2731
|
+
|
|
2732
|
+
function buildGovernanceConsolePack(input) {
|
|
2733
|
+
const dashboard = summarizeGovernanceDashboard(input);
|
|
2734
|
+
const disputes = summarizeGovernanceDisputes(input);
|
|
2735
|
+
return {
|
|
2736
|
+
ok: true,
|
|
2737
|
+
console_pack_ref: buildGovernanceRef("governance.console-pack", {
|
|
2738
|
+
dashboard_ref: dashboard.dashboard_ref,
|
|
2739
|
+
dispute_queue_ref: disputes.dispute_queue_ref
|
|
2740
|
+
}),
|
|
2741
|
+
dashboard_ref: dashboard.dashboard_ref,
|
|
2742
|
+
dispute_queue_ref: disputes.dispute_queue_ref,
|
|
2743
|
+
included_sections: [
|
|
2744
|
+
"dashboard",
|
|
2745
|
+
"workflow",
|
|
2746
|
+
"disputes"
|
|
2747
|
+
]
|
|
2748
|
+
};
|
|
2749
|
+
}
|
|
2750
|
+
|
|
2751
|
+
function buildGovernanceHandoffBundle(input) {
|
|
2752
|
+
const coordination = emitGovernanceCoordination(input);
|
|
2753
|
+
const disputes = summarizeGovernanceDisputes(input);
|
|
2754
|
+
return {
|
|
2755
|
+
ok: true,
|
|
2756
|
+
handoff_bundle_ref: buildGovernanceRef("governance.handoff-bundle", {
|
|
2757
|
+
coordination_ref: coordination.coordination_ref,
|
|
2758
|
+
dispute_queue_ref: disputes.dispute_queue_ref
|
|
2759
|
+
}),
|
|
2760
|
+
coordination_ref: coordination.coordination_ref,
|
|
2761
|
+
dispute_queue_ref: disputes.dispute_queue_ref,
|
|
2762
|
+
review_summary_surface: "/v1/proof-center/result-package-handoff/review/summary",
|
|
2763
|
+
handoff_run_surface: "/v1/proof-center/result-package-handoff/review/handoff-run",
|
|
2764
|
+
next_surface: "/v1/proof-center/result-package-handoff/run",
|
|
2765
|
+
included_sections: [
|
|
2766
|
+
"coordination",
|
|
2767
|
+
"dispute_summary",
|
|
2768
|
+
"operator_handoff_refs",
|
|
2769
|
+
"review_linkage"
|
|
2770
|
+
]
|
|
2771
|
+
};
|
|
2772
|
+
}
|
|
2773
|
+
|
|
2774
|
+
function summarizeGovernanceReviewLink(input) {
|
|
2775
|
+
const coordination = emitGovernanceCoordination(input);
|
|
2776
|
+
return {
|
|
2777
|
+
ok: coordination.ok,
|
|
2778
|
+
coordination_ref: coordination.coordination_ref,
|
|
2779
|
+
review_link_ref: buildGovernanceRef("governance.review-link", coordination),
|
|
2780
|
+
review_summary_surface: "/v1/proof-center/result-package-handoff/review/summary",
|
|
2781
|
+
handoff_run_surface: "/v1/proof-center/result-package-handoff/review/handoff-run",
|
|
2782
|
+
run_surface: "/v1/proof-center/result-package-handoff/run"
|
|
2783
|
+
};
|
|
2784
|
+
}
|
|
2785
|
+
|
|
1951
2786
|
function runDefaultProofLoop(loopRef, input) {
|
|
1952
2787
|
const loop = getDefaultProofLoop(loopRef);
|
|
1953
2788
|
if (!loop) {
|
|
@@ -1988,6 +2823,36 @@ function runDefaultProofLoop(loopRef, input) {
|
|
|
1988
2823
|
}
|
|
1989
2824
|
|
|
1990
2825
|
module.exports = {
|
|
2826
|
+
buildBridgeCenter,
|
|
2827
|
+
summarizeBridgeCenter,
|
|
2828
|
+
buildBridgeReceiptWrap,
|
|
2829
|
+
summarizeBridgeValidatorVerify,
|
|
2830
|
+
buildReceiptLedgerBridgeHandoff,
|
|
2831
|
+
buildEconomicConsequenceBridgeHandoff,
|
|
2832
|
+
buildEconomicConsequenceConformancePack,
|
|
2833
|
+
buildBridgeOperatorReviewPack,
|
|
2834
|
+
buildBridgeCompatibilityPack,
|
|
2835
|
+
buildBridgeProfileSupport,
|
|
2836
|
+
buildBridgeWorkflowPack,
|
|
2837
|
+
buildBridgeAdminPack,
|
|
2838
|
+
buildGovernanceCenter,
|
|
2839
|
+
summarizeGovernanceCenter,
|
|
2840
|
+
validateGovernanceInterpretation,
|
|
2841
|
+
emitGovernanceCoordination,
|
|
2842
|
+
summarizeGovernanceDashboard,
|
|
2843
|
+
summarizeGovernanceOperatorView,
|
|
2844
|
+
summarizeGovernanceAdminView,
|
|
2845
|
+
buildGovernanceDashboardPack,
|
|
2846
|
+
buildGovernanceWorkflowPack,
|
|
2847
|
+
buildGovernanceSignoffPack,
|
|
2848
|
+
summarizeGovernanceDisputes,
|
|
2849
|
+
reviewGovernanceCase,
|
|
2850
|
+
summarizeGovernanceDisputeAction,
|
|
2851
|
+
buildGovernanceCaseBundle,
|
|
2852
|
+
buildGovernanceResolutionPack,
|
|
2853
|
+
buildGovernanceConsolePack,
|
|
2854
|
+
buildGovernanceHandoffBundle,
|
|
2855
|
+
summarizeGovernanceReviewLink,
|
|
1991
2856
|
buildDefaultProofCenter,
|
|
1992
2857
|
buildDefaultProofLoopCatalog,
|
|
1993
2858
|
buildDefaultProofLoops,
|