@vess-id/ai-identity 0.5.0-alpha.13 → 0.5.0-alpha.14

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
@@ -8605,6 +8605,162 @@ declare function resolveUserTier(tier: string | undefined | null): UserTier;
8605
8605
  */
8606
8606
  declare function getTierLimits(tier: string | undefined | null): TierLimits;
8607
8607
 
8608
+ /**
8609
+ * P1-A14a-1 / Threat Model S4 — canonical-string + signature-header
8610
+ * helpers for HMAC body signing of internal HTTP requests.
8611
+ *
8612
+ * Pure module: no NestJS, no I/O, no side effects. SDK is the
8613
+ * single source of truth (P1-A14a-2d) — api / remote-mcp /
8614
+ * slack-bot all import from `@vess-id/ai-identity`.
8615
+ *
8616
+ * Header format (Q1 = A, Stripe-style versioned):
8617
+ * X-Internal-Signature: v1=<keyId>:<unixSeconds>:<base64(hmac)>
8618
+ *
8619
+ * Canonical string (Q2 = A, no header inclusion):
8620
+ * ${METHOD.toUpperCase()}\n${path}\n${unixSeconds}\n${sha256Hex(rawBody)}
8621
+ *
8622
+ * Replay window (Q3 = A): 300 seconds — enforced by the api guard,
8623
+ * not here. This module is responsible for *constructing* the
8624
+ * canonical string and *parsing* the header; freshness is policy.
8625
+ */
8626
+ declare const SIGNATURE_HEADER = "x-internal-signature";
8627
+ declare const SIGNATURE_VERSION_PREFIX = "v1=";
8628
+ /**
8629
+ * SHA-256 hex digest of an arbitrary buffer or string. Hex (not
8630
+ * base64) so the canonical string is URL-safe and grep-friendly in
8631
+ * logs if a future debug session ever needs to reconstruct it
8632
+ * server-side.
8633
+ */
8634
+ declare function sha256Hex(input: Buffer | string): string;
8635
+ /**
8636
+ * Build the canonical string that gets HMAC'd. The components are
8637
+ * separated by `\n` because no legitimate input contains `\n` (the
8638
+ * method is uppercase ASCII, the path is URL-encoded by the caller,
8639
+ * the timestamp is digits, the body hash is hex). Using `\n` as
8640
+ * separator avoids ambiguity that delimiters like `:` would
8641
+ * introduce when the path contains a colon.
8642
+ *
8643
+ * Whitespace is NOT trimmed — input must be exactly what will land
8644
+ * on the wire. Caller controls case and encoding.
8645
+ */
8646
+ declare function buildCanonicalString(args: {
8647
+ method: string;
8648
+ path: string;
8649
+ unixSeconds: number;
8650
+ rawBody: Buffer | string;
8651
+ }): string;
8652
+ /** Shape of a parsed `X-Internal-Signature` header. */
8653
+ interface ParsedSignature {
8654
+ /** Identifier of the signing key (e.g. `'mcp-v2'`). */
8655
+ keyId: string;
8656
+ /** Unix epoch seconds at signing time. */
8657
+ unixSeconds: number;
8658
+ /** Base64-encoded HMAC-SHA256 digest. */
8659
+ signature: string;
8660
+ }
8661
+ /**
8662
+ * Parse a `X-Internal-Signature` header value. Returns `null` for
8663
+ * any malformed shape rather than throwing — the api guard converts
8664
+ * `null` to a `401 Unauthorized` so a malformed header never
8665
+ * triggers a `500`.
8666
+ *
8667
+ * Accepted: `v1=<keyId>:<digits>:<base64>`
8668
+ *
8669
+ * Defensive checks:
8670
+ * - Must start with `v1=` (Q1: explicit version prefix)
8671
+ * - keyId / signature must be non-empty after split
8672
+ * - timestamp must parse to a finite, non-negative integer
8673
+ * - keyId must be ASCII identifier-safe ([A-Za-z0-9_-]+) so a
8674
+ * malicious header cannot smuggle control chars or whitespace
8675
+ * into log lines / metric labels
8676
+ * - signature must be valid base64 (only base64 alphabet chars)
8677
+ */
8678
+ declare function parseSignatureHeader(headerValue: string | undefined): ParsedSignature | null;
8679
+ /**
8680
+ * Format a ParsedSignature back into a header string. Round-trips
8681
+ * with `parseSignatureHeader` for any validly-shaped input.
8682
+ *
8683
+ * Used by the signing side (HTTP client). Keeping it next to the
8684
+ * parser pins the format in one place.
8685
+ */
8686
+ declare function formatSignatureHeader(parsed: ParsedSignature): string;
8687
+
8688
+ /**
8689
+ * P1-A14a-2d — pure HMAC signer for outbound /api/internal/**
8690
+ * requests. Lives in SDK so remote-mcp and slack-bot (both of which
8691
+ * already depend on `@vess-id/ai-identity`) can attach
8692
+ * `X-Internal-Signature` to every request without dragging the
8693
+ * api package into their dependency graph.
8694
+ *
8695
+ * Pure (no I/O, no Nest). Mirrors the `utils/crypto.ts` profile:
8696
+ * the only Node-builtin used is `crypto.createHmac`.
8697
+ *
8698
+ * Pairing with the verifier
8699
+ * -------------------------
8700
+ * The verifier (api side, `HmacKeyset.verify` →
8701
+ * `buildCanonicalString` → constant-time compare) reads the same
8702
+ * `buildCanonicalString` from this module by construction. As long
8703
+ * as both sides pass the same `(method, path, unixSeconds, rawBody)`
8704
+ * the HMACs match by definition.
8705
+ *
8706
+ * Body bytes
8707
+ * ----------
8708
+ * The caller MUST pass the exact bytes that go on the wire as
8709
+ * `rawBody`. Re-running `JSON.stringify(...)` on each side would
8710
+ * risk a byte mismatch (object key order is implementation-defined
8711
+ * in spec, even though V8 preserves insertion order in practice).
8712
+ * The api-client `makeRequest` helper computes `JSON.stringify`
8713
+ * once, hands the same string to both `signRequest` and `fetch`.
8714
+ */
8715
+ /**
8716
+ * Minimum signer key length in raw bytes. 32 bytes = 256 bits
8717
+ * matches HMAC-SHA256's natural block size and the verifier's
8718
+ * `MIN_KEY_BYTES`. A truncated env var (accidental newline,
8719
+ * copy-paste error) is the realistic failure mode this guards
8720
+ * against.
8721
+ */
8722
+ declare const MIN_SIGNER_KEY_BYTES = 32;
8723
+ interface InternalHmacSignerKey {
8724
+ /** Stable identifier for the key, e.g. `'mcp-v1'`. Embedded in
8725
+ * the X-Internal-Signature header so the verifier can pick the
8726
+ * right key. Must match `/^[A-Za-z0-9_-]+$/`. */
8727
+ keyId: string;
8728
+ /** Raw HMAC secret. >= MIN_SIGNER_KEY_BYTES bytes. */
8729
+ secret: Buffer;
8730
+ }
8731
+ interface SignRequestArgs {
8732
+ /** HTTP method. Will be upper-cased by `buildCanonicalString`,
8733
+ * but callers should pass the uppercase form they use on the
8734
+ * wire so signer and `fetch()` stay in lockstep. */
8735
+ method: string;
8736
+ /** URL path with query string already stripped (verifier does
8737
+ * `request.originalUrl?.split('?')[0]`; signer must mirror).
8738
+ * Path encoding (e.g. `%2F` vs `/`) is caller's responsibility
8739
+ * — the canonical string treats them as different bytes. */
8740
+ path: string;
8741
+ /** Wire bytes. The same string/buffer passed to `fetch({body})`
8742
+ * must be passed here — `JSON.stringify` runs ONCE per request
8743
+ * in the caller. */
8744
+ rawBody: Buffer | string;
8745
+ /** Optional fixed timestamp for testing. Defaults to
8746
+ * `Math.floor(Date.now() / 1000)`. */
8747
+ unixSeconds?: number;
8748
+ }
8749
+ /**
8750
+ * Sign an outbound request and return a fully-formatted
8751
+ * `X-Internal-Signature` header value. The caller sets the header
8752
+ * on the outbound request directly:
8753
+ *
8754
+ * ```ts
8755
+ * headers[SIGNATURE_HEADER] = signRequest(key, { method, path, rawBody })
8756
+ * ```
8757
+ *
8758
+ * Throws if key material is invalid (bad keyId or short secret) —
8759
+ * surfacing misconfiguration loudly at request time rather than
8760
+ * silently producing a header the verifier will reject.
8761
+ */
8762
+ declare function signRequest(key: InternalHmacSignerKey, args: SignRequestArgs): string;
8763
+
8608
8764
  declare const version = "0.0.1";
8609
8765
 
8610
- export { type ABACPolicyEngine, ACTION_PARAMS_MAX_SIZE, ACTION_PREFIXES, ACTION_REGISTRY, AIdentityClient, type AIdentityConfig, AIdentityError, type APIAgent, type APICredential, APIVCManager, type AbacDecision, type AbacInput, type AcceptInvitationRequest, type AckEventResponse, type ActionInputSchema, type ActionMapping, type ActionMeta, type ActionParamDisplay, type ActionRegistry, type ActionRiskLevel, type Agent, type AgentCreateOptions, type AgentDIDConfig, AgentDIDManager, AgentManager, AgentStatus, AgentType, type AgentWithId, AllowAllAbac, type AnyProvider, type ApiKeyValidationResult, type AuditEvent, type AuditQuery, AuthProvider, type AuthState, AuthenticationError, type AutoApproveConfig, type BindingSource, CANONICAL_PROVIDERS, type CanonicalProvider, type CapabilityMeta, type CheckGrantPermissionRequest, type CheckGrantPermissionResult, type CheckPermissionInput, type CheckPermissionResult, type CollectContextRequest, type ConfirmGrantSuggestionRequest, type ConnectorAction, type ConnectorConfig, type ConnectorExecutionContext, type ConnectorResponse, type ConnectorResponseMetadata, type ConnectorTokenConfig, type ConstraintEvaluationResult, ConstraintEvaluator, type ConstraintEvaluatorOptions, type ConstraintViolation, type ConstraintWarning, type ContextBindingSource, type ContextProvider, type CreateGrantRequest, type CreateInvitationRequest, type CreateReceiptRequest, type CredentialRef, CredentialStatus, type CredentialStore, CredentialType, DEFAULT_CONSTRAINTS_BY_RISK, type DIDDocument, type DataAccessVC, type DecisionTrace, type DelegationVC, DeviceEnrollManager, type DeviceEnrollPollResult, type DeviceEnrollServerSideParams, type DeviceEnrollStartParams, type DeviceEnrollStartResult, type DisclosureFields, DummyCreds, DummyVpVerifier, type EmployeeVPRequest, type EvaluationContext, type ExternalActionRequest, FilesystemKeyStorage, GATEWAY_ERROR_CODE, GatewayClient, GatewayError, type GatewayErrorCode, type GatewayEvent, type GetEventsOptions, type GetEventsResponse, type GitHubConfig, type GoogleConfig, type Grant, type GrantConstraints, type GrantResource, GrantResourceType, GrantScope, GrantStatus, type GrantUsage, type IConnectorService, type IStateStore, type Intent, type IntentEvaluationResult, type IntentObligation, type IntentResource, InvalidVPError, type Invitation, type InvitationRole, InvitationStatus, type IssueSDJWTVCRequest, type IssueSDJWTVCResult, type JiraBoard, type JiraConfig, type JiraIssue, type JiraIssueType, type JiraProject, type JiraSprint, type JiraStatus, type JiraUser, type JiraWorklog, type JsonSchema, JsonStateStore, KeyManager, type KeyPairGenerationResult, type KeyStorageConfig, type KeyStorageProvider, LEGACY_RESOURCE_TYPE_MAP, type MemoryDocument, MemoryKeyStorage, MemoryManager, type MemoryQuery, type MemoryQueryResult, NetworkError, type NormalizeIntentRequest, type NormalizedIntent, type OAuthAuthorizeRequest, type OAuthCallbackParams, type OAuthConnection, OAuthProvider, type OAuthToken, type OrganizationConfig, type OrganizationPermission, type OrganizationPolicy, type OrganizationVC, PROVIDER_ALIASES, type ParamBindingSource, type ParsedResourceType, type PermissionConstraints, type PermissionMode, type PermissionResource, type PermissionRule, type PermissionTimeConstraint, type PermissionVcClaims, type PlanDelegationInput, type PlanDelegationResult, type PolicyCondition, type PolicyEvaluationResult, type PolicyInput, type PolicyRule, type PolicyTarget, type Provider, REAUTH_REQUIRED_ACTION, RESOURCE_TYPES, type ReBACChecker, type Receipt, type ReceiptListResult, type ReceiptOutcome, type ReceiptSearchQuery, ReceiptStatus, type Relation, type ResolvedTargets, type ResourceIdBinding, type ResourceRef, type ResourceScope, type ResourceType, type RiskAssessmentResult, type RiskFactor, type RiskLevel, SDJwtClient, ScopeUnmatchedError, type SecondaryBinding, SimpleRebac, type SlackConfig, StandardActionCategory, type SuggestGrantRequest, type SuggestedAction, type SuggestedConstraints, type SuggestedGrant, type SuggestedResource, type SuggestionRiskLevel, TIER_LIMITS, type TargetBindings, type TargetConstraint, TargetResolver, type TierLimits, type TimeWindowCheckResult, type TimeWindowConstraint, type ToolDefinition, type ToolInvocation, ToolManager, type ToolPermissionRequest, type ToolPermissionVC, type UnifiedResourceType, type UpdateGrantRequest, type UserIdentity, type UserIdentityConfig, type UserIdentityCreateOptions, UserIdentityManager, UserKeyPairManager, type UserTier, VALID_MCP_ACTIONS, VALID_MCP_TOOLS, VCExpiredError, VCManager, VCRevokedError, VCStatus, type VCTemplate, VCType, VPManager, type VPRequest, type VerifiablePresentation, type VerificationMethod, type VerifiedVcClaims, type VerifyInvitationResponse, type VerifyReceiptRequest, type VerifyReceiptResult, type VerifySDJWTVCResult, type VpVerifier, WRITE_ACTION_NAMES, type WeeklyReportData, type WeeklyReportSummary, buildGrantIdFields, canonicalizeAction, checkPermissionWithVP, configure, createAjv, createDidJwk, credentialStatusToVCStatus, defaultConstraintEvaluator, evaluateConstraints, extractProjectKey, extractPublicKey, extractPublicKeyFromDid, generateActionParamsDisplay, generateActionSummary, generateKeyPair, generateNonce, getActionAliases, getAllActionForms, getAllValidMcpActionNames, getClient, getDefaultDisclosureFields, getKeyIdFromDid, getRequiredRelations, getRequiredScopes, getTierLimits, getValidMcpActionNames, grantConstraintsToPermissionConstraints, grantToPermissionRules, indexActions, indexCapabilities, isActionEquivalent, isCanonicalProvider, isUnlimited, isValidDidJwk, isValidProvider, isWriteAction, loadActionRegistryFromFile, loadActionRegistryFromObject, normalizeMcpActionName, parseGrantAction, parseGrantResourceType, planDelegationForVC, publicKeysMatch, resolveActionsFromSelection, resolveProvider, resolveResourceType, resolveUserTier, signJWT, validateRegistryObject, vcStatusToCredentialStatus, verifyJWT, version };
8766
+ export { type ABACPolicyEngine, ACTION_PARAMS_MAX_SIZE, ACTION_PREFIXES, ACTION_REGISTRY, AIdentityClient, type AIdentityConfig, AIdentityError, type APIAgent, type APICredential, APIVCManager, type AbacDecision, type AbacInput, type AcceptInvitationRequest, type AckEventResponse, type ActionInputSchema, type ActionMapping, type ActionMeta, type ActionParamDisplay, type ActionRegistry, type ActionRiskLevel, type Agent, type AgentCreateOptions, type AgentDIDConfig, AgentDIDManager, AgentManager, AgentStatus, AgentType, type AgentWithId, AllowAllAbac, type AnyProvider, type ApiKeyValidationResult, type AuditEvent, type AuditQuery, AuthProvider, type AuthState, AuthenticationError, type AutoApproveConfig, type BindingSource, CANONICAL_PROVIDERS, type CanonicalProvider, type CapabilityMeta, type CheckGrantPermissionRequest, type CheckGrantPermissionResult, type CheckPermissionInput, type CheckPermissionResult, type CollectContextRequest, type ConfirmGrantSuggestionRequest, type ConnectorAction, type ConnectorConfig, type ConnectorExecutionContext, type ConnectorResponse, type ConnectorResponseMetadata, type ConnectorTokenConfig, type ConstraintEvaluationResult, ConstraintEvaluator, type ConstraintEvaluatorOptions, type ConstraintViolation, type ConstraintWarning, type ContextBindingSource, type ContextProvider, type CreateGrantRequest, type CreateInvitationRequest, type CreateReceiptRequest, type CredentialRef, CredentialStatus, type CredentialStore, CredentialType, DEFAULT_CONSTRAINTS_BY_RISK, type DIDDocument, type DataAccessVC, type DecisionTrace, type DelegationVC, DeviceEnrollManager, type DeviceEnrollPollResult, type DeviceEnrollServerSideParams, type DeviceEnrollStartParams, type DeviceEnrollStartResult, type DisclosureFields, DummyCreds, DummyVpVerifier, type EmployeeVPRequest, type EvaluationContext, type ExternalActionRequest, FilesystemKeyStorage, GATEWAY_ERROR_CODE, GatewayClient, GatewayError, type GatewayErrorCode, type GatewayEvent, type GetEventsOptions, type GetEventsResponse, type GitHubConfig, type GoogleConfig, type Grant, type GrantConstraints, type GrantResource, GrantResourceType, GrantScope, GrantStatus, type GrantUsage, type IConnectorService, type IStateStore, type Intent, type IntentEvaluationResult, type IntentObligation, type IntentResource, type InternalHmacSignerKey, InvalidVPError, type Invitation, type InvitationRole, InvitationStatus, type IssueSDJWTVCRequest, type IssueSDJWTVCResult, type JiraBoard, type JiraConfig, type JiraIssue, type JiraIssueType, type JiraProject, type JiraSprint, type JiraStatus, type JiraUser, type JiraWorklog, type JsonSchema, JsonStateStore, KeyManager, type KeyPairGenerationResult, type KeyStorageConfig, type KeyStorageProvider, LEGACY_RESOURCE_TYPE_MAP, MIN_SIGNER_KEY_BYTES, type MemoryDocument, MemoryKeyStorage, MemoryManager, type MemoryQuery, type MemoryQueryResult, NetworkError, type NormalizeIntentRequest, type NormalizedIntent, type OAuthAuthorizeRequest, type OAuthCallbackParams, type OAuthConnection, OAuthProvider, type OAuthToken, type OrganizationConfig, type OrganizationPermission, type OrganizationPolicy, type OrganizationVC, PROVIDER_ALIASES, type ParamBindingSource, type ParsedResourceType, type ParsedSignature, type PermissionConstraints, type PermissionMode, type PermissionResource, type PermissionRule, type PermissionTimeConstraint, type PermissionVcClaims, type PlanDelegationInput, type PlanDelegationResult, type PolicyCondition, type PolicyEvaluationResult, type PolicyInput, type PolicyRule, type PolicyTarget, type Provider, REAUTH_REQUIRED_ACTION, RESOURCE_TYPES, type ReBACChecker, type Receipt, type ReceiptListResult, type ReceiptOutcome, type ReceiptSearchQuery, ReceiptStatus, type Relation, type ResolvedTargets, type ResourceIdBinding, type ResourceRef, type ResourceScope, type ResourceType, type RiskAssessmentResult, type RiskFactor, type RiskLevel, SDJwtClient, SIGNATURE_HEADER, SIGNATURE_VERSION_PREFIX, ScopeUnmatchedError, type SecondaryBinding, type SignRequestArgs, SimpleRebac, type SlackConfig, StandardActionCategory, type SuggestGrantRequest, type SuggestedAction, type SuggestedConstraints, type SuggestedGrant, type SuggestedResource, type SuggestionRiskLevel, TIER_LIMITS, type TargetBindings, type TargetConstraint, TargetResolver, type TierLimits, type TimeWindowCheckResult, type TimeWindowConstraint, type ToolDefinition, type ToolInvocation, ToolManager, type ToolPermissionRequest, type ToolPermissionVC, type UnifiedResourceType, type UpdateGrantRequest, type UserIdentity, type UserIdentityConfig, type UserIdentityCreateOptions, UserIdentityManager, UserKeyPairManager, type UserTier, VALID_MCP_ACTIONS, VALID_MCP_TOOLS, VCExpiredError, VCManager, VCRevokedError, VCStatus, type VCTemplate, VCType, VPManager, type VPRequest, type VerifiablePresentation, type VerificationMethod, type VerifiedVcClaims, type VerifyInvitationResponse, type VerifyReceiptRequest, type VerifyReceiptResult, type VerifySDJWTVCResult, type VpVerifier, WRITE_ACTION_NAMES, type WeeklyReportData, type WeeklyReportSummary, buildCanonicalString, buildGrantIdFields, canonicalizeAction, checkPermissionWithVP, configure, createAjv, createDidJwk, credentialStatusToVCStatus, defaultConstraintEvaluator, evaluateConstraints, extractProjectKey, extractPublicKey, extractPublicKeyFromDid, formatSignatureHeader, generateActionParamsDisplay, generateActionSummary, generateKeyPair, generateNonce, getActionAliases, getAllActionForms, getAllValidMcpActionNames, getClient, getDefaultDisclosureFields, getKeyIdFromDid, getRequiredRelations, getRequiredScopes, getTierLimits, getValidMcpActionNames, grantConstraintsToPermissionConstraints, grantToPermissionRules, indexActions, indexCapabilities, isActionEquivalent, isCanonicalProvider, isUnlimited, isValidDidJwk, isValidProvider, isWriteAction, loadActionRegistryFromFile, loadActionRegistryFromObject, normalizeMcpActionName, parseGrantAction, parseGrantResourceType, parseSignatureHeader, planDelegationForVC, publicKeysMatch, resolveActionsFromSelection, resolveProvider, resolveResourceType, resolveUserTier, sha256Hex, signJWT, signRequest, validateRegistryObject, vcStatusToCredentialStatus, verifyJWT, version };
package/dist/index.d.ts CHANGED
@@ -31,5 +31,6 @@ export { TargetResolver, extractProjectKey } from './resolver/target-resolver';
31
31
  export * from './types';
32
32
  export { isWriteAction, WRITE_ACTION_NAMES } from './utils/action-classifier';
33
33
  export { resolveUserTier, getTierLimits, isUnlimited } from './utils/tier-utils';
34
+ export * from './internal-signature';
34
35
  export declare const version = "0.0.1";
35
36
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGrD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAGrD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAA;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAA;AACrE,YAAY,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAA;AAC/E,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,4BAA4B,EAC5B,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACjE,OAAO,EACL,aAAa,EACb,cAAc,EACd,WAAW,EACX,iBAAiB,GAClB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,0BAA0B,CAAA;AAGzD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACtE,YAAY,EACV,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,0BAA0B,CAAA;AAGjC,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACnD,YAAY,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAErD,cAAc,YAAY,CAAA;AAG1B,OAAO,EAAE,qBAAqB,EAAE,2BAA2B,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAA;AACtH,YAAY,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAGnE,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AACnF,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAGlD,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,uBAAuB,EACvB,aAAa,EACb,eAAe,EACf,eAAe,GAChB,MAAM,iBAAiB,CAAA;AAGxB,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAA;AAG9E,cAAc,SAAS,CAAA;AAGvB,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAG7E,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAKhF,cAAc,sBAAsB,CAAA;AAGpC,eAAO,MAAM,OAAO,UAAU,CAAA"}
package/dist/index.js CHANGED
@@ -63,6 +63,7 @@ __export(index_exports, {
63
63
  JsonStateStore: () => JsonStateStore,
64
64
  KeyManager: () => KeyManager,
65
65
  LEGACY_RESOURCE_TYPE_MAP: () => LEGACY_RESOURCE_TYPE_MAP,
66
+ MIN_SIGNER_KEY_BYTES: () => MIN_SIGNER_KEY_BYTES,
66
67
  MemoryKeyStorage: () => MemoryKeyStorage,
67
68
  MemoryManager: () => MemoryManager,
68
69
  NetworkError: () => NetworkError,
@@ -72,6 +73,8 @@ __export(index_exports, {
72
73
  RESOURCE_TYPES: () => RESOURCE_TYPES,
73
74
  ReceiptStatus: () => ReceiptStatus,
74
75
  SDJwtClient: () => SDJwtClient,
76
+ SIGNATURE_HEADER: () => SIGNATURE_HEADER,
77
+ SIGNATURE_VERSION_PREFIX: () => SIGNATURE_VERSION_PREFIX,
75
78
  ScopeUnmatchedError: () => ScopeUnmatchedError,
76
79
  SimpleRebac: () => SimpleRebac,
77
80
  StandardActionCategory: () => StandardActionCategory,
@@ -89,6 +92,7 @@ __export(index_exports, {
89
92
  VCType: () => VCType,
90
93
  VPManager: () => VPManager,
91
94
  WRITE_ACTION_NAMES: () => WRITE_ACTION_NAMES,
95
+ buildCanonicalString: () => buildCanonicalString,
92
96
  buildGrantIdFields: () => buildGrantIdFields,
93
97
  canonicalizeAction: () => canonicalizeAction,
94
98
  checkPermissionWithVP: () => checkPermissionWithVP,
@@ -101,6 +105,7 @@ __export(index_exports, {
101
105
  extractProjectKey: () => extractProjectKey,
102
106
  extractPublicKey: () => extractPublicKey,
103
107
  extractPublicKeyFromDid: () => extractPublicKeyFromDid,
108
+ formatSignatureHeader: () => formatSignatureHeader,
104
109
  generateActionParamsDisplay: () => generateActionParamsDisplay,
105
110
  generateActionSummary: () => generateActionSummary,
106
111
  generateKeyPair: () => generateKeyPair,
@@ -130,13 +135,16 @@ __export(index_exports, {
130
135
  normalizeMcpActionName: () => normalizeMcpActionName,
131
136
  parseGrantAction: () => parseGrantAction,
132
137
  parseGrantResourceType: () => parseGrantResourceType,
138
+ parseSignatureHeader: () => parseSignatureHeader,
133
139
  planDelegationForVC: () => planDelegationForVC,
134
140
  publicKeysMatch: () => publicKeysMatch,
135
141
  resolveActionsFromSelection: () => resolveActionsFromSelection,
136
142
  resolveProvider: () => resolveProvider,
137
143
  resolveResourceType: () => resolveResourceType,
138
144
  resolveUserTier: () => resolveUserTier,
145
+ sha256Hex: () => sha256Hex,
139
146
  signJWT: () => signJWT,
147
+ signRequest: () => signRequest,
140
148
  validateRegistryObject: () => validateRegistryObject,
141
149
  vcStatusToCredentialStatus: () => vcStatusToCredentialStatus,
142
150
  verifyJWT: () => verifyJWT,
@@ -6184,6 +6192,70 @@ function getTierLimits(tier) {
6184
6192
  return TIER_LIMITS[resolveUserTier(tier)];
6185
6193
  }
6186
6194
 
6195
+ // src/internal-signature/canonical.ts
6196
+ var import_crypto3 = require("crypto");
6197
+ var SIGNATURE_HEADER = "x-internal-signature";
6198
+ var SIGNATURE_VERSION_PREFIX = "v1=";
6199
+ function sha256Hex(input) {
6200
+ return (0, import_crypto3.createHash)("sha256").update(input).digest("hex");
6201
+ }
6202
+ function buildCanonicalString(args) {
6203
+ const { method, path: path4, unixSeconds, rawBody } = args;
6204
+ return [method.toUpperCase(), path4, String(unixSeconds), sha256Hex(rawBody)].join("\n");
6205
+ }
6206
+ function parseSignatureHeader(headerValue) {
6207
+ if (typeof headerValue !== "string" || !headerValue.startsWith(SIGNATURE_VERSION_PREFIX)) {
6208
+ return null;
6209
+ }
6210
+ const payload = headerValue.slice(SIGNATURE_VERSION_PREFIX.length);
6211
+ const parts = payload.split(":");
6212
+ if (parts.length !== 3) return null;
6213
+ const [keyId, tsStr, signature] = parts;
6214
+ if (!keyId || !tsStr || !signature) return null;
6215
+ if (!/^[A-Za-z0-9_-]+$/.test(keyId)) return null;
6216
+ if (!/^\d+$/.test(tsStr)) return null;
6217
+ const unixSeconds = Number(tsStr);
6218
+ if (!Number.isFinite(unixSeconds) || unixSeconds < 0) return null;
6219
+ if (!/^[A-Za-z0-9+/]+=*$/.test(signature)) return null;
6220
+ return { keyId, unixSeconds, signature };
6221
+ }
6222
+ function formatSignatureHeader(parsed) {
6223
+ return `${SIGNATURE_VERSION_PREFIX}${parsed.keyId}:${parsed.unixSeconds}:${parsed.signature}`;
6224
+ }
6225
+
6226
+ // src/internal-signature/signer.ts
6227
+ var import_crypto4 = require("crypto");
6228
+ var MIN_SIGNER_KEY_BYTES = 32;
6229
+ function signRequest(key, args) {
6230
+ assertKeyMaterial(key);
6231
+ const unixSeconds = args.unixSeconds ?? Math.floor(Date.now() / 1e3);
6232
+ const canonical = buildCanonicalString({
6233
+ method: args.method,
6234
+ path: args.path,
6235
+ unixSeconds,
6236
+ rawBody: args.rawBody
6237
+ });
6238
+ const signature = (0, import_crypto4.createHmac)("sha256", key.secret).update(canonical).digest("base64");
6239
+ const parsed = {
6240
+ keyId: key.keyId,
6241
+ unixSeconds,
6242
+ signature
6243
+ };
6244
+ return formatSignatureHeader(parsed);
6245
+ }
6246
+ function assertKeyMaterial(k) {
6247
+ if (!k.keyId || !/^[A-Za-z0-9_-]+$/.test(k.keyId)) {
6248
+ throw new Error(
6249
+ `internal-signature signer: invalid keyId ${JSON.stringify(k.keyId)} (must match /^[A-Za-z0-9_-]+$/)`
6250
+ );
6251
+ }
6252
+ if (!Buffer.isBuffer(k.secret) || k.secret.length < MIN_SIGNER_KEY_BYTES) {
6253
+ throw new Error(
6254
+ `internal-signature signer: secret too short for keyId=${k.keyId} (${Buffer.isBuffer(k.secret) ? k.secret.length : "not a Buffer"} bytes; minimum ${MIN_SIGNER_KEY_BYTES} required)`
6255
+ );
6256
+ }
6257
+ }
6258
+
6187
6259
  // src/index.ts
6188
6260
  var version = "0.0.1";
6189
6261
  // Annotate the CommonJS export names for ESM import in node:
@@ -6221,6 +6293,7 @@ var version = "0.0.1";
6221
6293
  JsonStateStore,
6222
6294
  KeyManager,
6223
6295
  LEGACY_RESOURCE_TYPE_MAP,
6296
+ MIN_SIGNER_KEY_BYTES,
6224
6297
  MemoryKeyStorage,
6225
6298
  MemoryManager,
6226
6299
  NetworkError,
@@ -6230,6 +6303,8 @@ var version = "0.0.1";
6230
6303
  RESOURCE_TYPES,
6231
6304
  ReceiptStatus,
6232
6305
  SDJwtClient,
6306
+ SIGNATURE_HEADER,
6307
+ SIGNATURE_VERSION_PREFIX,
6233
6308
  ScopeUnmatchedError,
6234
6309
  SimpleRebac,
6235
6310
  StandardActionCategory,
@@ -6247,6 +6322,7 @@ var version = "0.0.1";
6247
6322
  VCType,
6248
6323
  VPManager,
6249
6324
  WRITE_ACTION_NAMES,
6325
+ buildCanonicalString,
6250
6326
  buildGrantIdFields,
6251
6327
  canonicalizeAction,
6252
6328
  checkPermissionWithVP,
@@ -6259,6 +6335,7 @@ var version = "0.0.1";
6259
6335
  extractProjectKey,
6260
6336
  extractPublicKey,
6261
6337
  extractPublicKeyFromDid,
6338
+ formatSignatureHeader,
6262
6339
  generateActionParamsDisplay,
6263
6340
  generateActionSummary,
6264
6341
  generateKeyPair,
@@ -6288,13 +6365,16 @@ var version = "0.0.1";
6288
6365
  normalizeMcpActionName,
6289
6366
  parseGrantAction,
6290
6367
  parseGrantResourceType,
6368
+ parseSignatureHeader,
6291
6369
  planDelegationForVC,
6292
6370
  publicKeysMatch,
6293
6371
  resolveActionsFromSelection,
6294
6372
  resolveProvider,
6295
6373
  resolveResourceType,
6296
6374
  resolveUserTier,
6375
+ sha256Hex,
6297
6376
  signJWT,
6377
+ signRequest,
6298
6378
  validateRegistryObject,
6299
6379
  vcStatusToCredentialStatus,
6300
6380
  verifyJWT,