@orangecheck/agent-core 2.3.0 → 2.4.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/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +49 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -2
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.mts +6 -1
- package/dist/types.d.ts +6 -1
- package/dist/types.js.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +1 -1
- package/src/federation.test.ts +97 -1
- package/src/federation.ts +75 -1
- package/src/revocation-authority.test.ts +25 -1
- package/src/types.ts +6 -1
- package/src/verify.ts +5 -2
package/dist/index.d.mts
CHANGED
|
@@ -125,6 +125,8 @@ declare function federationDescriptorCanonicalMessage(descriptor: FederationDesc
|
|
|
125
125
|
declare function computeFederationDescriptorId(descriptor: FederationDescriptor): string;
|
|
126
126
|
interface VerifyFederationDelegationInput extends VerifyFederationBase {
|
|
127
127
|
envelope: FederationDelegationEnvelope;
|
|
128
|
+
revocations?: Array<FederationRevocationEnvelope | RevocationEnvelope>;
|
|
129
|
+
skipRevocationCheck?: boolean;
|
|
128
130
|
now?: Date;
|
|
129
131
|
skipTemporalCheck?: boolean;
|
|
130
132
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -125,6 +125,8 @@ declare function federationDescriptorCanonicalMessage(descriptor: FederationDesc
|
|
|
125
125
|
declare function computeFederationDescriptorId(descriptor: FederationDescriptor): string;
|
|
126
126
|
interface VerifyFederationDelegationInput extends VerifyFederationBase {
|
|
127
127
|
envelope: FederationDelegationEnvelope;
|
|
128
|
+
revocations?: Array<FederationRevocationEnvelope | RevocationEnvelope>;
|
|
129
|
+
skipRevocationCheck?: boolean;
|
|
128
130
|
now?: Date;
|
|
129
131
|
skipTemporalCheck?: boolean;
|
|
130
132
|
}
|
package/dist/index.js
CHANGED
|
@@ -686,8 +686,7 @@ async function verifyAction(input) {
|
|
|
686
686
|
if (h === null || hash === null) {
|
|
687
687
|
return err("E_MALFORMED", "confirmed OTS proof missing block_height or block_hash");
|
|
688
688
|
}
|
|
689
|
-
|
|
690
|
-
anchor = { status: "confirmed", blockHeight: h, blockHash: hash, verified };
|
|
689
|
+
anchor = actionAnchor !== null ? { status: "confirmed", blockHeight: h, blockHash: hash, verified: true } : { status: "claimed", blockHeight: h, blockHash: hash, verified: false };
|
|
691
690
|
}
|
|
692
691
|
return {
|
|
693
692
|
ok: true,
|
|
@@ -1098,6 +1097,18 @@ async function verifyFederationDelegation(input) {
|
|
|
1098
1097
|
}
|
|
1099
1098
|
const quorum = await checkFederationQuorum(env.principal, env.sig, env.id, input);
|
|
1100
1099
|
if (!quorum.ok) return quorum;
|
|
1100
|
+
if (!input.skipRevocationCheck && !input.revocations) {
|
|
1101
|
+
return fail(
|
|
1102
|
+
"E_MALFORMED",
|
|
1103
|
+
"verifyFederationDelegation requires `revocations` (fetch kind-30085 by #delegation) or an explicit skipRevocationCheck:true to state that revocation is not being checked"
|
|
1104
|
+
);
|
|
1105
|
+
}
|
|
1106
|
+
for (const rev of input.revocations ?? []) {
|
|
1107
|
+
if (rev?.delegation_id !== env.id) continue;
|
|
1108
|
+
const rr = await verifyRevocationOf(env, rev, input);
|
|
1109
|
+
if (!rr.ok) continue;
|
|
1110
|
+
return fail("E_REVOKED", `delegation ${env.id} was revoked by ${rev.id}`);
|
|
1111
|
+
}
|
|
1101
1112
|
if (!input.skipTemporalCheck) {
|
|
1102
1113
|
const now = input.now ?? /* @__PURE__ */ new Date();
|
|
1103
1114
|
const issued = new Date(env.issued_at);
|
|
@@ -1108,6 +1119,42 @@ async function verifyFederationDelegation(input) {
|
|
|
1108
1119
|
}
|
|
1109
1120
|
return { ok: true, id: env.id, canonicalMessage: delegationCanonicalMessage(canonInput) };
|
|
1110
1121
|
}
|
|
1122
|
+
async function verifyRevocationOf(d, rev, input) {
|
|
1123
|
+
if (rev.signer?.alg === "federation") {
|
|
1124
|
+
return verifyFederationRevocation({
|
|
1125
|
+
envelope: rev,
|
|
1126
|
+
delegation: d,
|
|
1127
|
+
verifyBip322: input.verifyBip322,
|
|
1128
|
+
skipSignatureVerification: input.skipSignatureVerification
|
|
1129
|
+
});
|
|
1130
|
+
}
|
|
1131
|
+
const v1 = rev;
|
|
1132
|
+
const holders = d.revocation?.holders ?? ["principal"];
|
|
1133
|
+
if (!Array.isArray(holders) || !holders.includes("agent")) {
|
|
1134
|
+
return fail("E_REVOKER_UNAUTHORIZED", "only the federation may revoke this delegation");
|
|
1135
|
+
}
|
|
1136
|
+
if (v1.kind !== "agent-revocation" || v1.signer?.address !== d.agent.address) {
|
|
1137
|
+
return fail("E_REVOKER_UNAUTHORIZED", "a single-address revocation must be signed by the agent");
|
|
1138
|
+
}
|
|
1139
|
+
if (typeof v1.reason !== "string" || !ISO_UTC.test(v1.signed_at ?? "")) {
|
|
1140
|
+
return fail("E_MALFORMED", "revocation reason / signed_at invalid");
|
|
1141
|
+
}
|
|
1142
|
+
const canonInput = {
|
|
1143
|
+
address: v1.signer.address,
|
|
1144
|
+
delegation_id: v1.delegation_id,
|
|
1145
|
+
reason: v1.reason,
|
|
1146
|
+
signed_at: v1.signed_at
|
|
1147
|
+
};
|
|
1148
|
+
const id = computeRevocationId(canonInput);
|
|
1149
|
+
if (id !== v1.id) return fail("E_BAD_ID", `reconstructed id (${id}) != revocation.id (${v1.id})`);
|
|
1150
|
+
if (!input.skipSignatureVerification) {
|
|
1151
|
+
if (!input.verifyBip322) return fail("E_BAD_SIG", "no BIP-322 verifier supplied");
|
|
1152
|
+
if (typeof v1.sig?.value !== "string" || !await input.verifyBip322(v1.id, v1.sig.value, v1.signer.address)) {
|
|
1153
|
+
return fail("E_BAD_SIG", "revocation BIP-322 signature did not verify");
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
return { ok: true, id: v1.id, canonicalMessage: revocationCanonicalMessage(canonInput) };
|
|
1157
|
+
}
|
|
1111
1158
|
async function verifyFederationRevocation(input) {
|
|
1112
1159
|
const env = input.envelope;
|
|
1113
1160
|
if (env?.kind !== "agent-revocation") return fail("E_MALFORMED", 'kind must be "agent-revocation"');
|