blockintel-gate-sdk 0.3.9 → 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,17 +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;
600
+ private readonly maxSigners;
601
+ private readonly signerIdleTtlMs;
602
+ private readonly localRateLimitMs;
561
603
  constructor(options: {
562
604
  httpClient: HttpClient;
563
605
  tenantId: string;
@@ -568,6 +610,9 @@ declare class HeartbeatManager {
568
610
  sdkVersion?: string;
569
611
  /** API key for heartbeat endpoint auth (x-gate-heartbeat-key). Required unless local mode. */
570
612
  apiKey?: string;
613
+ maxSigners?: number;
614
+ signerIdleTtlMs?: number;
615
+ localRateLimitMs?: number;
571
616
  });
572
617
  /**
573
618
  * Start background heartbeat refresher.
@@ -576,36 +621,43 @@ declare class HeartbeatManager {
576
621
  start(options?: {
577
622
  waitForInitial?: boolean;
578
623
  }): void;
624
+ private startEvictionTimer;
579
625
  /**
580
- * Schedule next refresh with jitter and backoff
626
+ * Schedule next refresh with jitter and backoff for a specific signer
581
627
  */
582
- private scheduleNextRefresh;
583
- /**
584
- * Calculate exponential backoff (capped at maxBackoffSeconds)
585
- */
586
- private calculateBackoff;
628
+ private scheduleRefreshForSigner;
587
629
  /**
588
630
  * Stop background heartbeat refresher
589
631
  */
590
632
  stop(): void;
591
633
  /**
592
- * Get current heartbeat token if valid
634
+ * Get current heartbeat token if valid for the default signer
635
+ * @deprecated Use getTokenForSigner() instead.
593
636
  */
594
637
  getToken(): string | null;
595
638
  /**
596
- * Check if current heartbeat token is valid
639
+ * Check if current heartbeat token is valid for the default signer
640
+ * @deprecated Use getTokenForSigner() instead.
597
641
  */
598
642
  isValid(): boolean;
599
643
  /**
600
- * Update signer ID (called when signer is known)
644
+ * Update signer ID (called when signer is known).
645
+ * @deprecated Use getTokenForSigner() — signerId changes are handled automatically by the per-signer cache.
601
646
  */
602
647
  updateSignerId(signerId: string): void;
603
648
  /**
604
- * 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
605
657
  * NEVER logs token value (security)
606
658
  * Requires x-gate-heartbeat-key header (apiKey) for authentication.
607
659
  */
608
- private acquireHeartbeat;
660
+ private acquireHeartbeatForSigner;
609
661
  /**
610
662
  * Get client instance ID (for tracking)
611
663
  */
@@ -892,4 +944,4 @@ declare class GenericHsmSigner implements SignerBackend {
892
944
  close(): Promise<void>;
893
945
  }
894
946
 
895
- 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,17 +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;
600
+ private readonly maxSigners;
601
+ private readonly signerIdleTtlMs;
602
+ private readonly localRateLimitMs;
561
603
  constructor(options: {
562
604
  httpClient: HttpClient;
563
605
  tenantId: string;
@@ -568,6 +610,9 @@ declare class HeartbeatManager {
568
610
  sdkVersion?: string;
569
611
  /** API key for heartbeat endpoint auth (x-gate-heartbeat-key). Required unless local mode. */
570
612
  apiKey?: string;
613
+ maxSigners?: number;
614
+ signerIdleTtlMs?: number;
615
+ localRateLimitMs?: number;
571
616
  });
572
617
  /**
573
618
  * Start background heartbeat refresher.
@@ -576,36 +621,43 @@ declare class HeartbeatManager {
576
621
  start(options?: {
577
622
  waitForInitial?: boolean;
578
623
  }): void;
624
+ private startEvictionTimer;
579
625
  /**
580
- * Schedule next refresh with jitter and backoff
626
+ * Schedule next refresh with jitter and backoff for a specific signer
581
627
  */
582
- private scheduleNextRefresh;
583
- /**
584
- * Calculate exponential backoff (capped at maxBackoffSeconds)
585
- */
586
- private calculateBackoff;
628
+ private scheduleRefreshForSigner;
587
629
  /**
588
630
  * Stop background heartbeat refresher
589
631
  */
590
632
  stop(): void;
591
633
  /**
592
- * Get current heartbeat token if valid
634
+ * Get current heartbeat token if valid for the default signer
635
+ * @deprecated Use getTokenForSigner() instead.
593
636
  */
594
637
  getToken(): string | null;
595
638
  /**
596
- * Check if current heartbeat token is valid
639
+ * Check if current heartbeat token is valid for the default signer
640
+ * @deprecated Use getTokenForSigner() instead.
597
641
  */
598
642
  isValid(): boolean;
599
643
  /**
600
- * Update signer ID (called when signer is known)
644
+ * Update signer ID (called when signer is known).
645
+ * @deprecated Use getTokenForSigner() — signerId changes are handled automatically by the per-signer cache.
601
646
  */
602
647
  updateSignerId(signerId: string): void;
603
648
  /**
604
- * 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
605
657
  * NEVER logs token value (security)
606
658
  * Requires x-gate-heartbeat-key header (apiKey) for authentication.
607
659
  */
608
- private acquireHeartbeat;
660
+ private acquireHeartbeatForSigner;
609
661
  /**
610
662
  * Get client instance ID (for tracking)
611
663
  */
@@ -892,4 +944,4 @@ declare class GenericHsmSigner implements SignerBackend {
892
944
  close(): Promise<void>;
893
945
  }
894
946
 
895
- 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 };