blockintel-gate-sdk 0.3.10 → 0.3.11

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.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _aws_sdk_client_kms from '@aws-sdk/client-kms';
2
2
  import { SignCommandInput, KMSClient, SigningAlgorithmSpec } from '@aws-sdk/client-kms';
3
- import { G as GateClientConfig, D as DefenseEvaluateRequestV2, a as DefenseEvaluateResponseV2, M as MetricsCollector, S as StepUpStatusResponse, b as StepUpFinalResult, c as SigningContext, A as AttestCompletedRequest, d as AttestCompletedResponse } from './contracts-KKk945Ox.cjs';
4
- export { E as EvaluationMode, e as GateDecision, f as GateMode, h as GateStepUpStatus, g as StepUpMetadata, T as TransactionIntentV2 } from './contracts-KKk945Ox.cjs';
3
+ import { G as GateClientConfig, D as DefenseEvaluateRequestV2, a as DefenseEvaluateResponseV2, M as MetricsCollector, S as StepUpStatusResponse, b as StepUpFinalResult, c as SigningContext, A as AttestCompletedRequest, d as AttestCompletedResponse } from './contracts-Dxb9vt_M.cjs';
4
+ export { E as EvaluationMode, e as GateDecision, f as GateMode, h as GateStepUpStatus, g as StepUpMetadata, T as TransactionIntentV2 } from './contracts-Dxb9vt_M.cjs';
5
5
 
6
6
  /**
7
7
  * Circuit Breaker for SDK
@@ -50,6 +50,36 @@ declare class CircuitBreaker {
50
50
  reset(): void;
51
51
  }
52
52
 
53
+ /**
54
+ * Pluggable metrics sink for Gate SDK sign attempts.
55
+ * Used to compute receipt coverage % (signed_with_receipt / sign_attempts) for underwriting.
56
+ * Default: no-op. Wire to POST /api/v1/gate/metrics/sign for backend aggregation.
57
+ */
58
+ type GateSignMetricName = 'sign_attempt_total' | 'sign_blocked_missing_receipt_total' | 'sign_blocked_invalid_receipt_total' | 'sign_success_with_receipt_total' | 'sign_success_total';
59
+ interface GateMetricEventLabels {
60
+ tenantId?: string;
61
+ signerId?: string;
62
+ adoptionStage?: string;
63
+ env?: string;
64
+ chain?: string;
65
+ kmsKeyId?: string;
66
+ region?: string;
67
+ }
68
+ interface GateMetricEvent {
69
+ name: GateSignMetricName;
70
+ labels: GateMetricEventLabels;
71
+ timestampMs?: number;
72
+ }
73
+ /**
74
+ * Sink for sign metrics. Implement to forward events to your backend (e.g. POST /api/v1/gate/metrics/sign).
75
+ * Default when not provided: no-op.
76
+ */
77
+ interface GateMetricsSink {
78
+ emit(event: GateMetricEvent): void | Promise<void>;
79
+ }
80
+ /** No-op sink (default). */
81
+ declare const noOpMetricsSink: GateMetricsSink;
82
+
53
83
  /**
54
84
  * BlockIntel Gate SDK - AWS SDK v3 KMS Wrapper
55
85
  *
@@ -66,6 +96,11 @@ interface WrapKmsClientOptions {
66
96
  * - "dry-run": Evaluate but always allow KMS call (for testing)
67
97
  */
68
98
  mode?: 'enforce' | 'dry-run';
99
+ /**
100
+ * When true (e.g. HARD_KMS_ATTESTED mode), KMS Sign is only allowed if the evaluate response
101
+ * includes a receipt (or decisionHash). Rejects with RECEIPT_REQUIRED if missing.
102
+ */
103
+ requireReceiptForSign?: boolean;
69
104
  /**
70
105
  * Callback invoked when a decision is made
71
106
  */
@@ -80,6 +115,11 @@ interface WrapKmsClientOptions {
80
115
  chainId?: number;
81
116
  [key: string]: any;
82
117
  };
118
+ /**
119
+ * Optional metrics sink for observability.
120
+ * If not provided, uses no-op sink (metrics are discarded).
121
+ */
122
+ metricsSink?: GateMetricsSink;
83
123
  }
84
124
  /**
85
125
  * Wrapped KMS client type (proxy that intercepts send calls)
@@ -547,19 +587,19 @@ interface HeartbeatToken {
547
587
  declare class HeartbeatManager {
548
588
  private readonly httpClient;
549
589
  private readonly tenantId;
550
- private signerId;
590
+ private defaultSignerId;
551
591
  private readonly environment;
552
592
  private readonly baseRefreshIntervalSeconds;
553
593
  private readonly clientInstanceId;
554
594
  private readonly sdkVersion;
555
595
  private readonly apiKey;
556
- private currentToken;
557
- private refreshTimer;
596
+ private readonly signerEntries;
597
+ private evictionTimer;
558
598
  private started;
559
- private consecutiveFailures;
560
599
  private maxBackoffSeconds;
561
- /** SignerId used for the in-flight request; used to ignore stale responses after updateSignerId(). */
562
- private acquiringForSignerId;
600
+ private readonly maxSigners;
601
+ private readonly signerIdleTtlMs;
602
+ private readonly localRateLimitMs;
563
603
  constructor(options: {
564
604
  httpClient: HttpClient;
565
605
  tenantId: string;
@@ -570,6 +610,9 @@ declare class HeartbeatManager {
570
610
  sdkVersion?: string;
571
611
  /** API key for heartbeat endpoint auth (x-gate-heartbeat-key). Required unless local mode. */
572
612
  apiKey?: string;
613
+ maxSigners?: number;
614
+ signerIdleTtlMs?: number;
615
+ localRateLimitMs?: number;
573
616
  });
574
617
  /**
575
618
  * Start background heartbeat refresher.
@@ -578,37 +621,43 @@ declare class HeartbeatManager {
578
621
  start(options?: {
579
622
  waitForInitial?: boolean;
580
623
  }): void;
624
+ private startEvictionTimer;
581
625
  /**
582
- * Schedule next refresh with jitter and backoff
626
+ * Schedule next refresh with jitter and backoff for a specific signer
583
627
  */
584
- private scheduleNextRefresh;
585
- /**
586
- * Calculate exponential backoff (capped at maxBackoffSeconds)
587
- */
588
- private calculateBackoff;
628
+ private scheduleRefreshForSigner;
589
629
  /**
590
630
  * Stop background heartbeat refresher
591
631
  */
592
632
  stop(): void;
593
633
  /**
594
- * Get current heartbeat token if valid
634
+ * Get current heartbeat token if valid for the default signer
635
+ * @deprecated Use getTokenForSigner() instead.
595
636
  */
596
637
  getToken(): string | null;
597
638
  /**
598
- * Check if current heartbeat token is valid
639
+ * Check if current heartbeat token is valid for the default signer
640
+ * @deprecated Use getTokenForSigner() instead.
599
641
  */
600
642
  isValid(): boolean;
601
643
  /**
602
644
  * Update signer ID (called when signer is known).
603
- * Invalidates current token and triggers an immediate heartbeat acquisition so evaluate() can get a matching token.
645
+ * @deprecated Use getTokenForSigner() signerId changes are handled automatically by the per-signer cache.
604
646
  */
605
647
  updateSignerId(signerId: string): void;
606
648
  /**
607
- * Acquire a new heartbeat token from Control Plane
649
+ * Get a valid heartbeat token for a specific signer.
650
+ * Returns immediately if a cached valid token exists.
651
+ * If no token, triggers acquisition and returns a Promise that resolves
652
+ * when the token is available (or rejects after maxWaitMs).
653
+ */
654
+ getTokenForSigner(signerId: string, maxWaitMs?: number): Promise<string>;
655
+ /**
656
+ * Acquire a new heartbeat token from Control Plane for a specific signer
608
657
  * NEVER logs token value (security)
609
658
  * Requires x-gate-heartbeat-key header (apiKey) for authentication.
610
659
  */
611
- private acquireHeartbeat;
660
+ private acquireHeartbeatForSigner;
612
661
  /**
613
662
  * Get client instance ID (for tracking)
614
663
  */
@@ -895,4 +944,4 @@ declare class GenericHsmSigner implements SignerBackend {
895
944
  close(): Promise<void>;
896
945
  }
897
946
 
898
- export { AttestCompletedRequest, AttestCompletedResponse, AwsKmsSigner, BlockIntelAuthError, BlockIntelBlockedError, BlockIntelStepUpRequiredError, BlockIntelUnavailableError, DefenseEvaluateRequestV2, DefenseEvaluateResponseV2, FireblocksSigner, type FireblocksSignerConfig, Gate, GateClient, GateClientConfig, GateError, GateErrorCode, GcpKmsSigner, GenericHsmSigner, type GenericHsmSignerConfig, HeartbeatManager, type HeartbeatToken, type Pkcs11Session, type Provenance, ProvenanceProvider, type SignRequest, type SignResponse, type SignerBackend, SigningContext, StepUpFinalResult, StepUpNotConfiguredError, StepUpStatusResponse, type TxBindingObject, VaultSigner, type WrapKmsClientOptions, type WrappedKmsClient, buildTxBindingObject, computeTxDigest, createGateClient, GateClient as default, wrapKmsClient };
947
+ export { AttestCompletedRequest, AttestCompletedResponse, AwsKmsSigner, BlockIntelAuthError, BlockIntelBlockedError, BlockIntelStepUpRequiredError, BlockIntelUnavailableError, DefenseEvaluateRequestV2, DefenseEvaluateResponseV2, FireblocksSigner, type FireblocksSignerConfig, Gate, GateClient, GateClientConfig, GateError, GateErrorCode, type GateMetricEvent, type GateMetricEventLabels, type GateMetricsSink, type GateSignMetricName, GcpKmsSigner, GenericHsmSigner, type GenericHsmSignerConfig, HeartbeatManager, type HeartbeatToken, type Pkcs11Session, type Provenance, ProvenanceProvider, type SignRequest, type SignResponse, type SignerBackend, SigningContext, StepUpFinalResult, StepUpNotConfiguredError, StepUpStatusResponse, type TxBindingObject, VaultSigner, type WrapKmsClientOptions, type WrappedKmsClient, buildTxBindingObject, computeTxDigest, createGateClient, GateClient as default, noOpMetricsSink, wrapKmsClient };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _aws_sdk_client_kms from '@aws-sdk/client-kms';
2
2
  import { SignCommandInput, KMSClient, SigningAlgorithmSpec } from '@aws-sdk/client-kms';
3
- import { G as GateClientConfig, D as DefenseEvaluateRequestV2, a as DefenseEvaluateResponseV2, M as MetricsCollector, S as StepUpStatusResponse, b as StepUpFinalResult, c as SigningContext, A as AttestCompletedRequest, d as AttestCompletedResponse } from './contracts-KKk945Ox.js';
4
- export { E as EvaluationMode, e as GateDecision, f as GateMode, h as GateStepUpStatus, g as StepUpMetadata, T as TransactionIntentV2 } from './contracts-KKk945Ox.js';
3
+ import { G as GateClientConfig, D as DefenseEvaluateRequestV2, a as DefenseEvaluateResponseV2, M as MetricsCollector, S as StepUpStatusResponse, b as StepUpFinalResult, c as SigningContext, A as AttestCompletedRequest, d as AttestCompletedResponse } from './contracts-Dxb9vt_M.js';
4
+ export { E as EvaluationMode, e as GateDecision, f as GateMode, h as GateStepUpStatus, g as StepUpMetadata, T as TransactionIntentV2 } from './contracts-Dxb9vt_M.js';
5
5
 
6
6
  /**
7
7
  * Circuit Breaker for SDK
@@ -50,6 +50,36 @@ declare class CircuitBreaker {
50
50
  reset(): void;
51
51
  }
52
52
 
53
+ /**
54
+ * Pluggable metrics sink for Gate SDK sign attempts.
55
+ * Used to compute receipt coverage % (signed_with_receipt / sign_attempts) for underwriting.
56
+ * Default: no-op. Wire to POST /api/v1/gate/metrics/sign for backend aggregation.
57
+ */
58
+ type GateSignMetricName = 'sign_attempt_total' | 'sign_blocked_missing_receipt_total' | 'sign_blocked_invalid_receipt_total' | 'sign_success_with_receipt_total' | 'sign_success_total';
59
+ interface GateMetricEventLabels {
60
+ tenantId?: string;
61
+ signerId?: string;
62
+ adoptionStage?: string;
63
+ env?: string;
64
+ chain?: string;
65
+ kmsKeyId?: string;
66
+ region?: string;
67
+ }
68
+ interface GateMetricEvent {
69
+ name: GateSignMetricName;
70
+ labels: GateMetricEventLabels;
71
+ timestampMs?: number;
72
+ }
73
+ /**
74
+ * Sink for sign metrics. Implement to forward events to your backend (e.g. POST /api/v1/gate/metrics/sign).
75
+ * Default when not provided: no-op.
76
+ */
77
+ interface GateMetricsSink {
78
+ emit(event: GateMetricEvent): void | Promise<void>;
79
+ }
80
+ /** No-op sink (default). */
81
+ declare const noOpMetricsSink: GateMetricsSink;
82
+
53
83
  /**
54
84
  * BlockIntel Gate SDK - AWS SDK v3 KMS Wrapper
55
85
  *
@@ -66,6 +96,11 @@ interface WrapKmsClientOptions {
66
96
  * - "dry-run": Evaluate but always allow KMS call (for testing)
67
97
  */
68
98
  mode?: 'enforce' | 'dry-run';
99
+ /**
100
+ * When true (e.g. HARD_KMS_ATTESTED mode), KMS Sign is only allowed if the evaluate response
101
+ * includes a receipt (or decisionHash). Rejects with RECEIPT_REQUIRED if missing.
102
+ */
103
+ requireReceiptForSign?: boolean;
69
104
  /**
70
105
  * Callback invoked when a decision is made
71
106
  */
@@ -80,6 +115,11 @@ interface WrapKmsClientOptions {
80
115
  chainId?: number;
81
116
  [key: string]: any;
82
117
  };
118
+ /**
119
+ * Optional metrics sink for observability.
120
+ * If not provided, uses no-op sink (metrics are discarded).
121
+ */
122
+ metricsSink?: GateMetricsSink;
83
123
  }
84
124
  /**
85
125
  * Wrapped KMS client type (proxy that intercepts send calls)
@@ -547,19 +587,19 @@ interface HeartbeatToken {
547
587
  declare class HeartbeatManager {
548
588
  private readonly httpClient;
549
589
  private readonly tenantId;
550
- private signerId;
590
+ private defaultSignerId;
551
591
  private readonly environment;
552
592
  private readonly baseRefreshIntervalSeconds;
553
593
  private readonly clientInstanceId;
554
594
  private readonly sdkVersion;
555
595
  private readonly apiKey;
556
- private currentToken;
557
- private refreshTimer;
596
+ private readonly signerEntries;
597
+ private evictionTimer;
558
598
  private started;
559
- private consecutiveFailures;
560
599
  private maxBackoffSeconds;
561
- /** SignerId used for the in-flight request; used to ignore stale responses after updateSignerId(). */
562
- private acquiringForSignerId;
600
+ private readonly maxSigners;
601
+ private readonly signerIdleTtlMs;
602
+ private readonly localRateLimitMs;
563
603
  constructor(options: {
564
604
  httpClient: HttpClient;
565
605
  tenantId: string;
@@ -570,6 +610,9 @@ declare class HeartbeatManager {
570
610
  sdkVersion?: string;
571
611
  /** API key for heartbeat endpoint auth (x-gate-heartbeat-key). Required unless local mode. */
572
612
  apiKey?: string;
613
+ maxSigners?: number;
614
+ signerIdleTtlMs?: number;
615
+ localRateLimitMs?: number;
573
616
  });
574
617
  /**
575
618
  * Start background heartbeat refresher.
@@ -578,37 +621,43 @@ declare class HeartbeatManager {
578
621
  start(options?: {
579
622
  waitForInitial?: boolean;
580
623
  }): void;
624
+ private startEvictionTimer;
581
625
  /**
582
- * Schedule next refresh with jitter and backoff
626
+ * Schedule next refresh with jitter and backoff for a specific signer
583
627
  */
584
- private scheduleNextRefresh;
585
- /**
586
- * Calculate exponential backoff (capped at maxBackoffSeconds)
587
- */
588
- private calculateBackoff;
628
+ private scheduleRefreshForSigner;
589
629
  /**
590
630
  * Stop background heartbeat refresher
591
631
  */
592
632
  stop(): void;
593
633
  /**
594
- * Get current heartbeat token if valid
634
+ * Get current heartbeat token if valid for the default signer
635
+ * @deprecated Use getTokenForSigner() instead.
595
636
  */
596
637
  getToken(): string | null;
597
638
  /**
598
- * Check if current heartbeat token is valid
639
+ * Check if current heartbeat token is valid for the default signer
640
+ * @deprecated Use getTokenForSigner() instead.
599
641
  */
600
642
  isValid(): boolean;
601
643
  /**
602
644
  * Update signer ID (called when signer is known).
603
- * Invalidates current token and triggers an immediate heartbeat acquisition so evaluate() can get a matching token.
645
+ * @deprecated Use getTokenForSigner() signerId changes are handled automatically by the per-signer cache.
604
646
  */
605
647
  updateSignerId(signerId: string): void;
606
648
  /**
607
- * Acquire a new heartbeat token from Control Plane
649
+ * Get a valid heartbeat token for a specific signer.
650
+ * Returns immediately if a cached valid token exists.
651
+ * If no token, triggers acquisition and returns a Promise that resolves
652
+ * when the token is available (or rejects after maxWaitMs).
653
+ */
654
+ getTokenForSigner(signerId: string, maxWaitMs?: number): Promise<string>;
655
+ /**
656
+ * Acquire a new heartbeat token from Control Plane for a specific signer
608
657
  * NEVER logs token value (security)
609
658
  * Requires x-gate-heartbeat-key header (apiKey) for authentication.
610
659
  */
611
- private acquireHeartbeat;
660
+ private acquireHeartbeatForSigner;
612
661
  /**
613
662
  * Get client instance ID (for tracking)
614
663
  */
@@ -895,4 +944,4 @@ declare class GenericHsmSigner implements SignerBackend {
895
944
  close(): Promise<void>;
896
945
  }
897
946
 
898
- export { AttestCompletedRequest, AttestCompletedResponse, AwsKmsSigner, BlockIntelAuthError, BlockIntelBlockedError, BlockIntelStepUpRequiredError, BlockIntelUnavailableError, DefenseEvaluateRequestV2, DefenseEvaluateResponseV2, FireblocksSigner, type FireblocksSignerConfig, Gate, GateClient, GateClientConfig, GateError, GateErrorCode, GcpKmsSigner, GenericHsmSigner, type GenericHsmSignerConfig, HeartbeatManager, type HeartbeatToken, type Pkcs11Session, type Provenance, ProvenanceProvider, type SignRequest, type SignResponse, type SignerBackend, SigningContext, StepUpFinalResult, StepUpNotConfiguredError, StepUpStatusResponse, type TxBindingObject, VaultSigner, type WrapKmsClientOptions, type WrappedKmsClient, buildTxBindingObject, computeTxDigest, createGateClient, GateClient as default, wrapKmsClient };
947
+ export { AttestCompletedRequest, AttestCompletedResponse, AwsKmsSigner, BlockIntelAuthError, BlockIntelBlockedError, BlockIntelStepUpRequiredError, BlockIntelUnavailableError, DefenseEvaluateRequestV2, DefenseEvaluateResponseV2, FireblocksSigner, type FireblocksSignerConfig, Gate, GateClient, GateClientConfig, GateError, GateErrorCode, type GateMetricEvent, type GateMetricEventLabels, type GateMetricsSink, type GateSignMetricName, GcpKmsSigner, GenericHsmSigner, type GenericHsmSignerConfig, HeartbeatManager, type HeartbeatToken, type Pkcs11Session, type Provenance, ProvenanceProvider, type SignRequest, type SignResponse, type SignerBackend, SigningContext, StepUpFinalResult, StepUpNotConfiguredError, StepUpStatusResponse, type TxBindingObject, VaultSigner, type WrapKmsClientOptions, type WrappedKmsClient, buildTxBindingObject, computeTxDigest, createGateClient, GateClient as default, noOpMetricsSink, wrapKmsClient };