@orangecheck/agent-core 1.1.0 → 1.2.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 CHANGED
@@ -165,4 +165,14 @@ declare function hasPrivateScopes<T extends {
165
165
  scopes_encrypted: ScopesEncryptedEnvelope;
166
166
  };
167
167
 
168
- export { ActionEnvelope, ActorRef, AgentError, AgentErrorCode, ChainLink, DEFAULT_MAX_CHAIN_DEPTH, DelegationBond, DelegationEnvelope, DelegationRevocationRef, type FederationDelegationEnvelope, type FederationDescriptor, type FederationGuardian, type FederationPrincipal, type FederationRevocationEnvelope, type FederationSignature, type FederationVerifyResult, RevocationEnvelope, ScopesEncryptedEnvelope, type SealScopesInput, SubdelegationEnvelope, type UnsealScopesInput, type UnsealedScopes, ValidationOptions, type VerifyActionInput, VerifyActionResult, type VerifyBase, type VerifyDelegationInput, VerifyDelegationResult, type VerifyFederationBase, type VerifyFederationDelegationInput, type VerifyFederationRevocationInput, type VerifyRevocationInput, VerifyRevocationResult, type VerifySubdelegationInput, VerifySubdelegationResult, computeFederationDescriptorId, decodeScopesPayload, encodeScopesPayload, federationDescriptorCanonicalMessage, hasPrivateScopes, sealScopes, unsealScopes, verifyAction, verifyDelegation, verifyFederationDelegation, verifyFederationRevocation, verifyRevocation, verifySubdelegation };
168
+ interface ScopeBearingDelegation {
169
+ scopes?: string[];
170
+ scopes_encrypted?: ScopesEncryptedEnvelope;
171
+ }
172
+ declare class ScopeNotGrantedError extends Error {
173
+ readonly reason: 'not_subscope' | 'scopes_encrypted' | 'no_scopes';
174
+ constructor(reason: ScopeNotGrantedError['reason'], message: string);
175
+ }
176
+ declare function assertScopeGranted(delegation: ScopeBearingDelegation, scopeExercised: string, fnName: string): void;
177
+
178
+ export { ActionEnvelope, ActorRef, AgentError, AgentErrorCode, ChainLink, DEFAULT_MAX_CHAIN_DEPTH, DelegationBond, DelegationEnvelope, DelegationRevocationRef, type FederationDelegationEnvelope, type FederationDescriptor, type FederationGuardian, type FederationPrincipal, type FederationRevocationEnvelope, type FederationSignature, type FederationVerifyResult, RevocationEnvelope, type ScopeBearingDelegation, ScopeNotGrantedError, ScopesEncryptedEnvelope, type SealScopesInput, SubdelegationEnvelope, type UnsealScopesInput, type UnsealedScopes, ValidationOptions, type VerifyActionInput, VerifyActionResult, type VerifyBase, type VerifyDelegationInput, VerifyDelegationResult, type VerifyFederationBase, type VerifyFederationDelegationInput, type VerifyFederationRevocationInput, type VerifyRevocationInput, VerifyRevocationResult, type VerifySubdelegationInput, VerifySubdelegationResult, assertScopeGranted, computeFederationDescriptorId, decodeScopesPayload, encodeScopesPayload, federationDescriptorCanonicalMessage, hasPrivateScopes, sealScopes, unsealScopes, verifyAction, verifyDelegation, verifyFederationDelegation, verifyFederationRevocation, verifyRevocation, verifySubdelegation };
package/dist/index.d.ts CHANGED
@@ -165,4 +165,14 @@ declare function hasPrivateScopes<T extends {
165
165
  scopes_encrypted: ScopesEncryptedEnvelope;
166
166
  };
167
167
 
168
- export { ActionEnvelope, ActorRef, AgentError, AgentErrorCode, ChainLink, DEFAULT_MAX_CHAIN_DEPTH, DelegationBond, DelegationEnvelope, DelegationRevocationRef, type FederationDelegationEnvelope, type FederationDescriptor, type FederationGuardian, type FederationPrincipal, type FederationRevocationEnvelope, type FederationSignature, type FederationVerifyResult, RevocationEnvelope, ScopesEncryptedEnvelope, type SealScopesInput, SubdelegationEnvelope, type UnsealScopesInput, type UnsealedScopes, ValidationOptions, type VerifyActionInput, VerifyActionResult, type VerifyBase, type VerifyDelegationInput, VerifyDelegationResult, type VerifyFederationBase, type VerifyFederationDelegationInput, type VerifyFederationRevocationInput, type VerifyRevocationInput, VerifyRevocationResult, type VerifySubdelegationInput, VerifySubdelegationResult, computeFederationDescriptorId, decodeScopesPayload, encodeScopesPayload, federationDescriptorCanonicalMessage, hasPrivateScopes, sealScopes, unsealScopes, verifyAction, verifyDelegation, verifyFederationDelegation, verifyFederationRevocation, verifyRevocation, verifySubdelegation };
168
+ interface ScopeBearingDelegation {
169
+ scopes?: string[];
170
+ scopes_encrypted?: ScopesEncryptedEnvelope;
171
+ }
172
+ declare class ScopeNotGrantedError extends Error {
173
+ readonly reason: 'not_subscope' | 'scopes_encrypted' | 'no_scopes';
174
+ constructor(reason: ScopeNotGrantedError['reason'], message: string);
175
+ }
176
+ declare function assertScopeGranted(delegation: ScopeBearingDelegation, scopeExercised: string, fnName: string): void;
177
+
178
+ export { ActionEnvelope, ActorRef, AgentError, AgentErrorCode, ChainLink, DEFAULT_MAX_CHAIN_DEPTH, DelegationBond, DelegationEnvelope, DelegationRevocationRef, type FederationDelegationEnvelope, type FederationDescriptor, type FederationGuardian, type FederationPrincipal, type FederationRevocationEnvelope, type FederationSignature, type FederationVerifyResult, RevocationEnvelope, type ScopeBearingDelegation, ScopeNotGrantedError, ScopesEncryptedEnvelope, type SealScopesInput, SubdelegationEnvelope, type UnsealScopesInput, type UnsealedScopes, ValidationOptions, type VerifyActionInput, VerifyActionResult, type VerifyBase, type VerifyDelegationInput, VerifyDelegationResult, type VerifyFederationBase, type VerifyFederationDelegationInput, type VerifyFederationRevocationInput, type VerifyRevocationInput, VerifyRevocationResult, type VerifySubdelegationInput, VerifySubdelegationResult, assertScopeGranted, computeFederationDescriptorId, decodeScopesPayload, encodeScopesPayload, federationDescriptorCanonicalMessage, hasPrivateScopes, sealScopes, unsealScopes, verifyAction, verifyDelegation, verifyFederationDelegation, verifyFederationRevocation, verifyRevocation, verifySubdelegation };
package/dist/index.js CHANGED
@@ -1102,6 +1102,37 @@ function fail(code, message) {
1102
1102
  return { ok: false, code, message };
1103
1103
  }
1104
1104
 
1105
+ // src/assert-scope.ts
1106
+ var ScopeNotGrantedError = class extends Error {
1107
+ constructor(reason, message) {
1108
+ super(message);
1109
+ this.name = "ScopeNotGrantedError";
1110
+ this.reason = reason;
1111
+ }
1112
+ };
1113
+ function assertScopeGranted(delegation, scopeExercised, fnName) {
1114
+ if (hasPrivateScopes(delegation)) {
1115
+ throw new ScopeNotGrantedError(
1116
+ "scopes_encrypted",
1117
+ `${fnName}: this delegation uses v1.2 private scopes \u2014 \`scopes_encrypted\` is set and \`scopes\` is absent, so the granted set cannot be read here. Decrypt it with decryptPrivateScopes() using a matching device key and pass the recovered scopes as \`delegation.scopes\`. Refusing to stamp \`${scopeExercised}\` against an unreadable grant.`
1118
+ );
1119
+ }
1120
+ const scopes = delegation.scopes;
1121
+ if (scopes === void 0 || scopes.length === 0) {
1122
+ throw new ScopeNotGrantedError(
1123
+ "no_scopes",
1124
+ `${fnName}: delegation grants no scopes, so \`${scopeExercised}\` cannot be exercised. An absent or empty \`scopes\` means nothing is granted, never everything.`
1125
+ );
1126
+ }
1127
+ const exercised = parseScope(scopeExercised);
1128
+ if (!scopes.map(parseScope).some((g) => isSubScope(exercised, g))) {
1129
+ throw new ScopeNotGrantedError(
1130
+ "not_subscope",
1131
+ `${fnName}: scope_exercised (${scopeExercised}) is not a sub-scope of any granted scope (${scopes.join(", ")})`
1132
+ );
1133
+ }
1134
+ }
1135
+
1105
1136
  Object.defineProperty(exports, "canonicalize", {
1106
1137
  enumerable: true,
1107
1138
  get: function () { return canonical.canonicalize; }
@@ -1114,9 +1145,11 @@ exports.AgentError = AgentError;
1114
1145
  exports.DEFAULT_MAX_CHAIN_DEPTH = DEFAULT_MAX_CHAIN_DEPTH;
1115
1146
  exports.ENVELOPE_VERSION = ENVELOPE_VERSION;
1116
1147
  exports.REGISTERED_SCOPES = REGISTERED_SCOPES;
1148
+ exports.ScopeNotGrantedError = ScopeNotGrantedError;
1117
1149
  exports.ScopeParseError = ScopeParseError;
1118
1150
  exports.actionCanonicalBytes = actionCanonicalBytes;
1119
1151
  exports.actionCanonicalMessage = actionCanonicalMessage;
1152
+ exports.assertScopeGranted = assertScopeGranted;
1120
1153
  exports.canonicalActionBytes = canonicalActionBytes;
1121
1154
  exports.canonicalDelegationBytes = canonicalDelegationBytes;
1122
1155
  exports.canonicalRevocationBytes = canonicalRevocationBytes;