@orangecheck/agent-core 2.5.1 → 2.6.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 +1 -1
- package/dist/index.js +13 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/delegation-window.test.ts +82 -0
- package/src/federation.test.ts +21 -1
- package/src/federation.ts +3 -1
- package/src/private-scope.test.ts +4 -2
- package/src/scope.test.ts +20 -0
- package/src/test-vectors.test.ts +21 -0
- package/src/verify.ts +14 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @orangecheck/agent-core
|
|
2
2
|
|
|
3
|
-
> **Full reference:** [
|
|
3
|
+
> **Full reference:** [ochk.io/docs/sdk/agent-core](https://ochk.io/docs/sdk/agent-core) — auto-generated from the TypeScript source on every release.
|
|
4
4
|
> Hand-written prose below is the high-level overview; the docs site is the source of truth for every export, type, and signature.
|
|
5
5
|
|
|
6
6
|
|
package/dist/index.js
CHANGED
|
@@ -533,7 +533,6 @@ async function verifyDelegation(input) {
|
|
|
533
533
|
const now = input.now ?? /* @__PURE__ */ new Date();
|
|
534
534
|
const issued = new Date(env.issued_at);
|
|
535
535
|
const expires = new Date(env.expires_at);
|
|
536
|
-
if (expires <= issued) return err("E_MALFORMED", "expires_at <= issued_at");
|
|
537
536
|
if (now < issued) return err("E_NOT_YET_VALID", `delegation not valid until ${env.issued_at}`);
|
|
538
537
|
if (now >= expires) return err("E_EXPIRED", `delegation expired at ${env.expires_at}`);
|
|
539
538
|
}
|
|
@@ -798,11 +797,22 @@ function checkDelegationShape(env) {
|
|
|
798
797
|
}
|
|
799
798
|
if (!isIsoUtc(env.issued_at)) return err("E_MALFORMED", "issued_at must be ISO 8601 UTC");
|
|
800
799
|
if (!isIsoUtc(env.expires_at)) return err("E_MALFORMED", "expires_at must be ISO 8601 UTC");
|
|
800
|
+
const windowError = delegationWindowError(env.issued_at, env.expires_at);
|
|
801
|
+
if (windowError) return err("E_MALFORMED", windowError);
|
|
801
802
|
if (!/^[0-9a-f]{32}$/.test(env.nonce)) return err("E_MALFORMED", "nonce must be 32 lowercase hex chars");
|
|
802
803
|
if (env.sig?.alg !== "bip322" || typeof env.sig.value !== "string") return err("E_MALFORMED", "sig invalid");
|
|
803
804
|
if (env.sig.pubkey !== env.principal.address) return err("E_MALFORMED", "sig.pubkey must equal principal.address");
|
|
804
805
|
return null;
|
|
805
806
|
}
|
|
807
|
+
var MAX_DELEGATION_MS = 365 * 864e5;
|
|
808
|
+
function delegationWindowError(issuedAt, expiresAt) {
|
|
809
|
+
const issued = Date.parse(issuedAt);
|
|
810
|
+
const expires = Date.parse(expiresAt);
|
|
811
|
+
if (Number.isNaN(issued) || Number.isNaN(expires)) return "issued_at / expires_at must be real UTC times";
|
|
812
|
+
if (expires <= issued) return "expires_at must be after issued_at";
|
|
813
|
+
if (expires - issued > MAX_DELEGATION_MS) return "expires_at is more than 365 days after issued_at (SPEC \xA74.4)";
|
|
814
|
+
return null;
|
|
815
|
+
}
|
|
806
816
|
function checkActionShape(a) {
|
|
807
817
|
if (a.kind !== "agent-action") return err("E_MALFORMED", 'kind must be "agent-action"');
|
|
808
818
|
if (!isHex64(a.id)) return err("E_MALFORMED", "id must be 64 lowercase hex chars");
|
|
@@ -1074,6 +1084,8 @@ async function verifyFederationDelegation(input) {
|
|
|
1074
1084
|
if (!ISO_UTC.test(env.issued_at) || !ISO_UTC.test(env.expires_at)) {
|
|
1075
1085
|
return fail("E_MALFORMED", "issued_at / expires_at must be ISO 8601 UTC");
|
|
1076
1086
|
}
|
|
1087
|
+
const windowError = delegationWindowError(env.issued_at, env.expires_at);
|
|
1088
|
+
if (windowError) return fail("E_MALFORMED", windowError);
|
|
1077
1089
|
if (!/^[0-9a-f]{32}$/.test(env.nonce)) return fail("E_MALFORMED", "nonce must be 32 hex chars");
|
|
1078
1090
|
let canonicalScopes;
|
|
1079
1091
|
try {
|
|
@@ -1118,7 +1130,6 @@ async function verifyFederationDelegation(input) {
|
|
|
1118
1130
|
const now = input.now ?? /* @__PURE__ */ new Date();
|
|
1119
1131
|
const issued = new Date(env.issued_at);
|
|
1120
1132
|
const expires = new Date(env.expires_at);
|
|
1121
|
-
if (expires <= issued) return fail("E_MALFORMED", "expires_at <= issued_at");
|
|
1122
1133
|
if (now < issued) return fail("E_NOT_YET_VALID", `delegation not valid until ${env.issued_at}`);
|
|
1123
1134
|
if (now >= expires) return fail("E_EXPIRED", `delegation expired at ${env.expires_at}`);
|
|
1124
1135
|
}
|