blockintel-gate-sdk 0.3.1 → 0.3.2
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/README.md +5 -3
- package/dist/index.cjs +552 -66
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +200 -4
- package/dist/index.d.ts +200 -4
- package/dist/index.js +552 -67
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -14,6 +14,8 @@ interface Metrics {
|
|
|
14
14
|
timeoutsTotal: number;
|
|
15
15
|
errorsTotal: number;
|
|
16
16
|
circuitBreakerOpenTotal: number;
|
|
17
|
+
wouldBlockTotal: number;
|
|
18
|
+
failOpenTotal: number;
|
|
17
19
|
latencyMs: number[];
|
|
18
20
|
}
|
|
19
21
|
type MetricsHook = (metrics: Metrics) => void | Promise<void>;
|
|
@@ -28,13 +30,15 @@ declare class MetricsCollector {
|
|
|
28
30
|
private timeoutsTotal;
|
|
29
31
|
private errorsTotal;
|
|
30
32
|
private circuitBreakerOpenTotal;
|
|
33
|
+
private wouldBlockTotal;
|
|
34
|
+
private failOpenTotal;
|
|
31
35
|
private latencyMs;
|
|
32
36
|
private readonly maxSamples;
|
|
33
37
|
private readonly hooks;
|
|
34
38
|
/**
|
|
35
39
|
* Record a request
|
|
36
40
|
*/
|
|
37
|
-
recordRequest(decision: 'ALLOW' | 'BLOCK' | 'REQUIRE_STEP_UP', latencyMs: number): void;
|
|
41
|
+
recordRequest(decision: 'ALLOW' | 'BLOCK' | 'REQUIRE_STEP_UP' | 'WOULD_BLOCK' | 'FAIL_OPEN', latencyMs: number): void;
|
|
38
42
|
/**
|
|
39
43
|
* Record a timeout
|
|
40
44
|
*/
|
|
@@ -111,6 +115,13 @@ interface DefenseEvaluateRequestV2 {
|
|
|
111
115
|
signingContext?: SigningContext;
|
|
112
116
|
requestId?: string;
|
|
113
117
|
timestampMs?: number;
|
|
118
|
+
/**
|
|
119
|
+
* Enable transaction simulation (optional, defaults to false)
|
|
120
|
+
*
|
|
121
|
+
* When true, Hot Path will simulate the transaction after static policy evaluation.
|
|
122
|
+
* Adds 300-800ms latency but provides additional security checks.
|
|
123
|
+
*/
|
|
124
|
+
simulate?: boolean;
|
|
114
125
|
}
|
|
115
126
|
/**
|
|
116
127
|
* Gate decision types
|
|
@@ -132,6 +143,18 @@ interface DefenseEvaluateResponseV2 {
|
|
|
132
143
|
policyVersion?: string;
|
|
133
144
|
correlationId?: string;
|
|
134
145
|
stepUp?: StepUpMetadata;
|
|
146
|
+
/**
|
|
147
|
+
* Whether the decision was enforced (false in SHADOW mode)
|
|
148
|
+
*/
|
|
149
|
+
enforced?: boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Whether shadow mode would have blocked (true if mode=SHADOW and decision=BLOCK)
|
|
152
|
+
*/
|
|
153
|
+
shadowWouldBlock?: boolean;
|
|
154
|
+
/**
|
|
155
|
+
* Gate mode used for this evaluation
|
|
156
|
+
*/
|
|
157
|
+
mode?: GateMode;
|
|
135
158
|
}
|
|
136
159
|
/**
|
|
137
160
|
* Step-up status types
|
|
@@ -162,9 +185,23 @@ interface StepUpFinalResult {
|
|
|
162
185
|
correlationId?: string;
|
|
163
186
|
}
|
|
164
187
|
/**
|
|
165
|
-
* Fail-safe mode for SDK
|
|
188
|
+
* Fail-safe mode for SDK (deprecated - use onConnectionFailure instead)
|
|
166
189
|
*/
|
|
167
190
|
type FailSafeMode = 'ALLOW_ON_TIMEOUT' | 'BLOCK_ON_TIMEOUT' | 'BLOCK_ON_ANOMALY';
|
|
191
|
+
/**
|
|
192
|
+
* Gate Mode
|
|
193
|
+
*
|
|
194
|
+
* SHADOW: Evaluate and log, but always allow (monitor-only)
|
|
195
|
+
* ENFORCE: Evaluate and enforce decisions (block if policy violation)
|
|
196
|
+
*/
|
|
197
|
+
type GateMode = 'SHADOW' | 'ENFORCE';
|
|
198
|
+
/**
|
|
199
|
+
* Connection Failure Strategy
|
|
200
|
+
*
|
|
201
|
+
* FAIL_OPEN: Allow transaction if hotpath is unreachable
|
|
202
|
+
* FAIL_CLOSED: Block transaction if hotpath is unreachable (security-first)
|
|
203
|
+
*/
|
|
204
|
+
type ConnectionFailureStrategy = 'FAIL_OPEN' | 'FAIL_CLOSED';
|
|
168
205
|
/**
|
|
169
206
|
* Circuit breaker configuration
|
|
170
207
|
*/
|
|
@@ -191,6 +228,20 @@ interface GateClientConfig {
|
|
|
191
228
|
clockSkewMs?: number;
|
|
192
229
|
retries?: number;
|
|
193
230
|
failSafeMode?: FailSafeMode;
|
|
231
|
+
/**
|
|
232
|
+
* Gate mode (default: SHADOW for safety)
|
|
233
|
+
*
|
|
234
|
+
* SHADOW: Monitor-only - evaluate and log, but always allow
|
|
235
|
+
* ENFORCE: Enforce decisions - block if policy violation
|
|
236
|
+
*/
|
|
237
|
+
mode?: GateMode;
|
|
238
|
+
/**
|
|
239
|
+
* Connection failure strategy (default: based on mode)
|
|
240
|
+
*
|
|
241
|
+
* FAIL_OPEN: Allow on connection failure (default in SHADOW mode)
|
|
242
|
+
* FAIL_CLOSED: Block on connection failure (default in ENFORCE mode)
|
|
243
|
+
*/
|
|
244
|
+
onConnectionFailure?: ConnectionFailureStrategy;
|
|
194
245
|
circuitBreaker?: CircuitBreakerConfig$1;
|
|
195
246
|
enableStepUp?: boolean;
|
|
196
247
|
stepUp?: {
|
|
@@ -199,6 +250,20 @@ interface GateClientConfig {
|
|
|
199
250
|
treatRequireStepUpAsBlockWhenDisabled?: boolean;
|
|
200
251
|
};
|
|
201
252
|
onMetrics?: (metrics: Metrics) => void | Promise<void>;
|
|
253
|
+
signerId?: string;
|
|
254
|
+
heartbeatRefreshIntervalSeconds?: number;
|
|
255
|
+
/**
|
|
256
|
+
* Break-glass token (optional, for emergency override)
|
|
257
|
+
*
|
|
258
|
+
* JWT token issued by Control Plane for time-bound policy bypass.
|
|
259
|
+
* Only valid if explicitly activated via break-glass endpoint.
|
|
260
|
+
*/
|
|
261
|
+
breakglassToken?: string;
|
|
262
|
+
/**
|
|
263
|
+
* Local development mode - disables auth, heartbeat, and break-glass
|
|
264
|
+
* Set to true when using gate-local emulator
|
|
265
|
+
*/
|
|
266
|
+
local?: boolean;
|
|
202
267
|
}
|
|
203
268
|
|
|
204
269
|
/**
|
|
@@ -344,11 +409,16 @@ declare class GateClient {
|
|
|
344
409
|
private readonly stepUpPoller?;
|
|
345
410
|
private readonly circuitBreaker?;
|
|
346
411
|
private readonly metrics;
|
|
412
|
+
private readonly heartbeatManager;
|
|
413
|
+
private readonly mode;
|
|
414
|
+
private readonly onConnectionFailure;
|
|
347
415
|
constructor(config: GateClientConfig);
|
|
348
416
|
/**
|
|
349
417
|
* Evaluate a transaction defense request
|
|
350
418
|
*
|
|
351
419
|
* Implements:
|
|
420
|
+
* - Shadow Mode (SHADOW: monitor-only, ENFORCE: enforce decisions)
|
|
421
|
+
* - Connection failure strategy (FAIL_OPEN vs FAIL_CLOSED)
|
|
352
422
|
* - Circuit breaker protection
|
|
353
423
|
* - Fail-safe modes (ALLOW_ON_TIMEOUT, BLOCK_ON_TIMEOUT, BLOCK_ON_ANOMALY)
|
|
354
424
|
* - Metrics collection
|
|
@@ -428,7 +498,11 @@ declare enum GateErrorCode {
|
|
|
428
498
|
STEP_UP_TIMEOUT = "STEP_UP_TIMEOUT",
|
|
429
499
|
BLOCKED = "BLOCKED",
|
|
430
500
|
SERVICE_UNAVAILABLE = "SERVICE_UNAVAILABLE",
|
|
431
|
-
AUTH_ERROR = "AUTH_ERROR"
|
|
501
|
+
AUTH_ERROR = "AUTH_ERROR",
|
|
502
|
+
HEARTBEAT_MISSING = "HEARTBEAT_MISSING",
|
|
503
|
+
HEARTBEAT_EXPIRED = "HEARTBEAT_EXPIRED",
|
|
504
|
+
HEARTBEAT_INVALID = "HEARTBEAT_INVALID",
|
|
505
|
+
HEARTBEAT_MISMATCH = "HEARTBEAT_MISMATCH"
|
|
432
506
|
}
|
|
433
507
|
/**
|
|
434
508
|
* Base Gate error class
|
|
@@ -534,4 +608,126 @@ declare class ProvenanceProvider {
|
|
|
534
608
|
static isEnabled(): boolean;
|
|
535
609
|
}
|
|
536
610
|
|
|
537
|
-
|
|
611
|
+
/**
|
|
612
|
+
* BlockIntel Gate SDK - HTTP Client
|
|
613
|
+
*
|
|
614
|
+
* Fetch wrapper with timeout, retry, and error handling.
|
|
615
|
+
*/
|
|
616
|
+
interface HttpClientConfig {
|
|
617
|
+
baseUrl: string;
|
|
618
|
+
timeoutMs?: number;
|
|
619
|
+
userAgent?: string;
|
|
620
|
+
retryOptions?: {
|
|
621
|
+
maxAttempts?: number;
|
|
622
|
+
baseDelayMs?: number;
|
|
623
|
+
maxDelayMs?: number;
|
|
624
|
+
factor?: number;
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
interface RequestOptions {
|
|
628
|
+
method: string;
|
|
629
|
+
path: string;
|
|
630
|
+
headers?: Record<string, string>;
|
|
631
|
+
body?: unknown;
|
|
632
|
+
requestId?: string;
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* HTTP client with retry and timeout support
|
|
636
|
+
*/
|
|
637
|
+
declare class HttpClient {
|
|
638
|
+
private readonly baseUrl;
|
|
639
|
+
private readonly timeoutMs;
|
|
640
|
+
private readonly userAgent;
|
|
641
|
+
private readonly retryOptions;
|
|
642
|
+
constructor(config: HttpClientConfig);
|
|
643
|
+
/**
|
|
644
|
+
* Make an HTTP request with retry and timeout
|
|
645
|
+
*/
|
|
646
|
+
request<T>(options: RequestOptions): Promise<T>;
|
|
647
|
+
/**
|
|
648
|
+
* Map HTTP status code to GateErrorCode
|
|
649
|
+
*/
|
|
650
|
+
private statusToErrorCode;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* Gate SDK - Heartbeat Manager
|
|
655
|
+
*
|
|
656
|
+
* Manages heartbeat token acquisition and validation.
|
|
657
|
+
* Heartbeat tokens prove Gate is alive and enforcing policy.
|
|
658
|
+
* Required for all signing operations.
|
|
659
|
+
*
|
|
660
|
+
* Features:
|
|
661
|
+
* - Automatic refresh with jitter
|
|
662
|
+
* - Exponential backoff on failures
|
|
663
|
+
* - Client instance metadata tracking
|
|
664
|
+
*/
|
|
665
|
+
|
|
666
|
+
interface HeartbeatToken {
|
|
667
|
+
token: string;
|
|
668
|
+
expiresAt: number;
|
|
669
|
+
jti?: string;
|
|
670
|
+
policyHash?: string;
|
|
671
|
+
}
|
|
672
|
+
declare class HeartbeatManager {
|
|
673
|
+
private readonly httpClient;
|
|
674
|
+
private readonly tenantId;
|
|
675
|
+
private signerId;
|
|
676
|
+
private readonly environment;
|
|
677
|
+
private readonly baseRefreshIntervalSeconds;
|
|
678
|
+
private readonly clientInstanceId;
|
|
679
|
+
private readonly sdkVersion;
|
|
680
|
+
private currentToken;
|
|
681
|
+
private refreshTimer;
|
|
682
|
+
private started;
|
|
683
|
+
private consecutiveFailures;
|
|
684
|
+
private maxBackoffSeconds;
|
|
685
|
+
constructor(options: {
|
|
686
|
+
httpClient: HttpClient;
|
|
687
|
+
tenantId: string;
|
|
688
|
+
signerId: string;
|
|
689
|
+
environment?: string;
|
|
690
|
+
refreshIntervalSeconds?: number;
|
|
691
|
+
clientInstanceId?: string;
|
|
692
|
+
sdkVersion?: string;
|
|
693
|
+
});
|
|
694
|
+
/**
|
|
695
|
+
* Start background heartbeat refresher
|
|
696
|
+
*/
|
|
697
|
+
start(): void;
|
|
698
|
+
/**
|
|
699
|
+
* Schedule next refresh with jitter and backoff
|
|
700
|
+
*/
|
|
701
|
+
private scheduleNextRefresh;
|
|
702
|
+
/**
|
|
703
|
+
* Calculate exponential backoff (capped at maxBackoffSeconds)
|
|
704
|
+
*/
|
|
705
|
+
private calculateBackoff;
|
|
706
|
+
/**
|
|
707
|
+
* Stop background heartbeat refresher
|
|
708
|
+
*/
|
|
709
|
+
stop(): void;
|
|
710
|
+
/**
|
|
711
|
+
* Get current heartbeat token if valid
|
|
712
|
+
*/
|
|
713
|
+
getToken(): string | null;
|
|
714
|
+
/**
|
|
715
|
+
* Check if current heartbeat token is valid
|
|
716
|
+
*/
|
|
717
|
+
isValid(): boolean;
|
|
718
|
+
/**
|
|
719
|
+
* Update signer ID (called when signer is known)
|
|
720
|
+
*/
|
|
721
|
+
updateSignerId(signerId: string): void;
|
|
722
|
+
/**
|
|
723
|
+
* Acquire a new heartbeat token from Control Plane
|
|
724
|
+
* NEVER logs token value (security)
|
|
725
|
+
*/
|
|
726
|
+
private acquireHeartbeat;
|
|
727
|
+
/**
|
|
728
|
+
* Get client instance ID (for tracking)
|
|
729
|
+
*/
|
|
730
|
+
getClientInstanceId(): string;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
export { BlockIntelAuthError, BlockIntelBlockedError, BlockIntelStepUpRequiredError, BlockIntelUnavailableError, type DefenseEvaluateRequestV2, type DefenseEvaluateResponseV2, GateClient, type GateClientConfig, type GateDecision, GateError, GateErrorCode, type GateStepUpStatus, HeartbeatManager, type HeartbeatToken, type Provenance, ProvenanceProvider, type SigningContext, type StepUpFinalResult, type StepUpMetadata, StepUpNotConfiguredError, type StepUpStatusResponse, type TransactionIntentV2, type WrapKmsClientOptions, type WrappedKmsClient, createGateClient, GateClient as default, wrapKmsClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ interface Metrics {
|
|
|
14
14
|
timeoutsTotal: number;
|
|
15
15
|
errorsTotal: number;
|
|
16
16
|
circuitBreakerOpenTotal: number;
|
|
17
|
+
wouldBlockTotal: number;
|
|
18
|
+
failOpenTotal: number;
|
|
17
19
|
latencyMs: number[];
|
|
18
20
|
}
|
|
19
21
|
type MetricsHook = (metrics: Metrics) => void | Promise<void>;
|
|
@@ -28,13 +30,15 @@ declare class MetricsCollector {
|
|
|
28
30
|
private timeoutsTotal;
|
|
29
31
|
private errorsTotal;
|
|
30
32
|
private circuitBreakerOpenTotal;
|
|
33
|
+
private wouldBlockTotal;
|
|
34
|
+
private failOpenTotal;
|
|
31
35
|
private latencyMs;
|
|
32
36
|
private readonly maxSamples;
|
|
33
37
|
private readonly hooks;
|
|
34
38
|
/**
|
|
35
39
|
* Record a request
|
|
36
40
|
*/
|
|
37
|
-
recordRequest(decision: 'ALLOW' | 'BLOCK' | 'REQUIRE_STEP_UP', latencyMs: number): void;
|
|
41
|
+
recordRequest(decision: 'ALLOW' | 'BLOCK' | 'REQUIRE_STEP_UP' | 'WOULD_BLOCK' | 'FAIL_OPEN', latencyMs: number): void;
|
|
38
42
|
/**
|
|
39
43
|
* Record a timeout
|
|
40
44
|
*/
|
|
@@ -111,6 +115,13 @@ interface DefenseEvaluateRequestV2 {
|
|
|
111
115
|
signingContext?: SigningContext;
|
|
112
116
|
requestId?: string;
|
|
113
117
|
timestampMs?: number;
|
|
118
|
+
/**
|
|
119
|
+
* Enable transaction simulation (optional, defaults to false)
|
|
120
|
+
*
|
|
121
|
+
* When true, Hot Path will simulate the transaction after static policy evaluation.
|
|
122
|
+
* Adds 300-800ms latency but provides additional security checks.
|
|
123
|
+
*/
|
|
124
|
+
simulate?: boolean;
|
|
114
125
|
}
|
|
115
126
|
/**
|
|
116
127
|
* Gate decision types
|
|
@@ -132,6 +143,18 @@ interface DefenseEvaluateResponseV2 {
|
|
|
132
143
|
policyVersion?: string;
|
|
133
144
|
correlationId?: string;
|
|
134
145
|
stepUp?: StepUpMetadata;
|
|
146
|
+
/**
|
|
147
|
+
* Whether the decision was enforced (false in SHADOW mode)
|
|
148
|
+
*/
|
|
149
|
+
enforced?: boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Whether shadow mode would have blocked (true if mode=SHADOW and decision=BLOCK)
|
|
152
|
+
*/
|
|
153
|
+
shadowWouldBlock?: boolean;
|
|
154
|
+
/**
|
|
155
|
+
* Gate mode used for this evaluation
|
|
156
|
+
*/
|
|
157
|
+
mode?: GateMode;
|
|
135
158
|
}
|
|
136
159
|
/**
|
|
137
160
|
* Step-up status types
|
|
@@ -162,9 +185,23 @@ interface StepUpFinalResult {
|
|
|
162
185
|
correlationId?: string;
|
|
163
186
|
}
|
|
164
187
|
/**
|
|
165
|
-
* Fail-safe mode for SDK
|
|
188
|
+
* Fail-safe mode for SDK (deprecated - use onConnectionFailure instead)
|
|
166
189
|
*/
|
|
167
190
|
type FailSafeMode = 'ALLOW_ON_TIMEOUT' | 'BLOCK_ON_TIMEOUT' | 'BLOCK_ON_ANOMALY';
|
|
191
|
+
/**
|
|
192
|
+
* Gate Mode
|
|
193
|
+
*
|
|
194
|
+
* SHADOW: Evaluate and log, but always allow (monitor-only)
|
|
195
|
+
* ENFORCE: Evaluate and enforce decisions (block if policy violation)
|
|
196
|
+
*/
|
|
197
|
+
type GateMode = 'SHADOW' | 'ENFORCE';
|
|
198
|
+
/**
|
|
199
|
+
* Connection Failure Strategy
|
|
200
|
+
*
|
|
201
|
+
* FAIL_OPEN: Allow transaction if hotpath is unreachable
|
|
202
|
+
* FAIL_CLOSED: Block transaction if hotpath is unreachable (security-first)
|
|
203
|
+
*/
|
|
204
|
+
type ConnectionFailureStrategy = 'FAIL_OPEN' | 'FAIL_CLOSED';
|
|
168
205
|
/**
|
|
169
206
|
* Circuit breaker configuration
|
|
170
207
|
*/
|
|
@@ -191,6 +228,20 @@ interface GateClientConfig {
|
|
|
191
228
|
clockSkewMs?: number;
|
|
192
229
|
retries?: number;
|
|
193
230
|
failSafeMode?: FailSafeMode;
|
|
231
|
+
/**
|
|
232
|
+
* Gate mode (default: SHADOW for safety)
|
|
233
|
+
*
|
|
234
|
+
* SHADOW: Monitor-only - evaluate and log, but always allow
|
|
235
|
+
* ENFORCE: Enforce decisions - block if policy violation
|
|
236
|
+
*/
|
|
237
|
+
mode?: GateMode;
|
|
238
|
+
/**
|
|
239
|
+
* Connection failure strategy (default: based on mode)
|
|
240
|
+
*
|
|
241
|
+
* FAIL_OPEN: Allow on connection failure (default in SHADOW mode)
|
|
242
|
+
* FAIL_CLOSED: Block on connection failure (default in ENFORCE mode)
|
|
243
|
+
*/
|
|
244
|
+
onConnectionFailure?: ConnectionFailureStrategy;
|
|
194
245
|
circuitBreaker?: CircuitBreakerConfig$1;
|
|
195
246
|
enableStepUp?: boolean;
|
|
196
247
|
stepUp?: {
|
|
@@ -199,6 +250,20 @@ interface GateClientConfig {
|
|
|
199
250
|
treatRequireStepUpAsBlockWhenDisabled?: boolean;
|
|
200
251
|
};
|
|
201
252
|
onMetrics?: (metrics: Metrics) => void | Promise<void>;
|
|
253
|
+
signerId?: string;
|
|
254
|
+
heartbeatRefreshIntervalSeconds?: number;
|
|
255
|
+
/**
|
|
256
|
+
* Break-glass token (optional, for emergency override)
|
|
257
|
+
*
|
|
258
|
+
* JWT token issued by Control Plane for time-bound policy bypass.
|
|
259
|
+
* Only valid if explicitly activated via break-glass endpoint.
|
|
260
|
+
*/
|
|
261
|
+
breakglassToken?: string;
|
|
262
|
+
/**
|
|
263
|
+
* Local development mode - disables auth, heartbeat, and break-glass
|
|
264
|
+
* Set to true when using gate-local emulator
|
|
265
|
+
*/
|
|
266
|
+
local?: boolean;
|
|
202
267
|
}
|
|
203
268
|
|
|
204
269
|
/**
|
|
@@ -344,11 +409,16 @@ declare class GateClient {
|
|
|
344
409
|
private readonly stepUpPoller?;
|
|
345
410
|
private readonly circuitBreaker?;
|
|
346
411
|
private readonly metrics;
|
|
412
|
+
private readonly heartbeatManager;
|
|
413
|
+
private readonly mode;
|
|
414
|
+
private readonly onConnectionFailure;
|
|
347
415
|
constructor(config: GateClientConfig);
|
|
348
416
|
/**
|
|
349
417
|
* Evaluate a transaction defense request
|
|
350
418
|
*
|
|
351
419
|
* Implements:
|
|
420
|
+
* - Shadow Mode (SHADOW: monitor-only, ENFORCE: enforce decisions)
|
|
421
|
+
* - Connection failure strategy (FAIL_OPEN vs FAIL_CLOSED)
|
|
352
422
|
* - Circuit breaker protection
|
|
353
423
|
* - Fail-safe modes (ALLOW_ON_TIMEOUT, BLOCK_ON_TIMEOUT, BLOCK_ON_ANOMALY)
|
|
354
424
|
* - Metrics collection
|
|
@@ -428,7 +498,11 @@ declare enum GateErrorCode {
|
|
|
428
498
|
STEP_UP_TIMEOUT = "STEP_UP_TIMEOUT",
|
|
429
499
|
BLOCKED = "BLOCKED",
|
|
430
500
|
SERVICE_UNAVAILABLE = "SERVICE_UNAVAILABLE",
|
|
431
|
-
AUTH_ERROR = "AUTH_ERROR"
|
|
501
|
+
AUTH_ERROR = "AUTH_ERROR",
|
|
502
|
+
HEARTBEAT_MISSING = "HEARTBEAT_MISSING",
|
|
503
|
+
HEARTBEAT_EXPIRED = "HEARTBEAT_EXPIRED",
|
|
504
|
+
HEARTBEAT_INVALID = "HEARTBEAT_INVALID",
|
|
505
|
+
HEARTBEAT_MISMATCH = "HEARTBEAT_MISMATCH"
|
|
432
506
|
}
|
|
433
507
|
/**
|
|
434
508
|
* Base Gate error class
|
|
@@ -534,4 +608,126 @@ declare class ProvenanceProvider {
|
|
|
534
608
|
static isEnabled(): boolean;
|
|
535
609
|
}
|
|
536
610
|
|
|
537
|
-
|
|
611
|
+
/**
|
|
612
|
+
* BlockIntel Gate SDK - HTTP Client
|
|
613
|
+
*
|
|
614
|
+
* Fetch wrapper with timeout, retry, and error handling.
|
|
615
|
+
*/
|
|
616
|
+
interface HttpClientConfig {
|
|
617
|
+
baseUrl: string;
|
|
618
|
+
timeoutMs?: number;
|
|
619
|
+
userAgent?: string;
|
|
620
|
+
retryOptions?: {
|
|
621
|
+
maxAttempts?: number;
|
|
622
|
+
baseDelayMs?: number;
|
|
623
|
+
maxDelayMs?: number;
|
|
624
|
+
factor?: number;
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
interface RequestOptions {
|
|
628
|
+
method: string;
|
|
629
|
+
path: string;
|
|
630
|
+
headers?: Record<string, string>;
|
|
631
|
+
body?: unknown;
|
|
632
|
+
requestId?: string;
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* HTTP client with retry and timeout support
|
|
636
|
+
*/
|
|
637
|
+
declare class HttpClient {
|
|
638
|
+
private readonly baseUrl;
|
|
639
|
+
private readonly timeoutMs;
|
|
640
|
+
private readonly userAgent;
|
|
641
|
+
private readonly retryOptions;
|
|
642
|
+
constructor(config: HttpClientConfig);
|
|
643
|
+
/**
|
|
644
|
+
* Make an HTTP request with retry and timeout
|
|
645
|
+
*/
|
|
646
|
+
request<T>(options: RequestOptions): Promise<T>;
|
|
647
|
+
/**
|
|
648
|
+
* Map HTTP status code to GateErrorCode
|
|
649
|
+
*/
|
|
650
|
+
private statusToErrorCode;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* Gate SDK - Heartbeat Manager
|
|
655
|
+
*
|
|
656
|
+
* Manages heartbeat token acquisition and validation.
|
|
657
|
+
* Heartbeat tokens prove Gate is alive and enforcing policy.
|
|
658
|
+
* Required for all signing operations.
|
|
659
|
+
*
|
|
660
|
+
* Features:
|
|
661
|
+
* - Automatic refresh with jitter
|
|
662
|
+
* - Exponential backoff on failures
|
|
663
|
+
* - Client instance metadata tracking
|
|
664
|
+
*/
|
|
665
|
+
|
|
666
|
+
interface HeartbeatToken {
|
|
667
|
+
token: string;
|
|
668
|
+
expiresAt: number;
|
|
669
|
+
jti?: string;
|
|
670
|
+
policyHash?: string;
|
|
671
|
+
}
|
|
672
|
+
declare class HeartbeatManager {
|
|
673
|
+
private readonly httpClient;
|
|
674
|
+
private readonly tenantId;
|
|
675
|
+
private signerId;
|
|
676
|
+
private readonly environment;
|
|
677
|
+
private readonly baseRefreshIntervalSeconds;
|
|
678
|
+
private readonly clientInstanceId;
|
|
679
|
+
private readonly sdkVersion;
|
|
680
|
+
private currentToken;
|
|
681
|
+
private refreshTimer;
|
|
682
|
+
private started;
|
|
683
|
+
private consecutiveFailures;
|
|
684
|
+
private maxBackoffSeconds;
|
|
685
|
+
constructor(options: {
|
|
686
|
+
httpClient: HttpClient;
|
|
687
|
+
tenantId: string;
|
|
688
|
+
signerId: string;
|
|
689
|
+
environment?: string;
|
|
690
|
+
refreshIntervalSeconds?: number;
|
|
691
|
+
clientInstanceId?: string;
|
|
692
|
+
sdkVersion?: string;
|
|
693
|
+
});
|
|
694
|
+
/**
|
|
695
|
+
* Start background heartbeat refresher
|
|
696
|
+
*/
|
|
697
|
+
start(): void;
|
|
698
|
+
/**
|
|
699
|
+
* Schedule next refresh with jitter and backoff
|
|
700
|
+
*/
|
|
701
|
+
private scheduleNextRefresh;
|
|
702
|
+
/**
|
|
703
|
+
* Calculate exponential backoff (capped at maxBackoffSeconds)
|
|
704
|
+
*/
|
|
705
|
+
private calculateBackoff;
|
|
706
|
+
/**
|
|
707
|
+
* Stop background heartbeat refresher
|
|
708
|
+
*/
|
|
709
|
+
stop(): void;
|
|
710
|
+
/**
|
|
711
|
+
* Get current heartbeat token if valid
|
|
712
|
+
*/
|
|
713
|
+
getToken(): string | null;
|
|
714
|
+
/**
|
|
715
|
+
* Check if current heartbeat token is valid
|
|
716
|
+
*/
|
|
717
|
+
isValid(): boolean;
|
|
718
|
+
/**
|
|
719
|
+
* Update signer ID (called when signer is known)
|
|
720
|
+
*/
|
|
721
|
+
updateSignerId(signerId: string): void;
|
|
722
|
+
/**
|
|
723
|
+
* Acquire a new heartbeat token from Control Plane
|
|
724
|
+
* NEVER logs token value (security)
|
|
725
|
+
*/
|
|
726
|
+
private acquireHeartbeat;
|
|
727
|
+
/**
|
|
728
|
+
* Get client instance ID (for tracking)
|
|
729
|
+
*/
|
|
730
|
+
getClientInstanceId(): string;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
export { BlockIntelAuthError, BlockIntelBlockedError, BlockIntelStepUpRequiredError, BlockIntelUnavailableError, type DefenseEvaluateRequestV2, type DefenseEvaluateResponseV2, GateClient, type GateClientConfig, type GateDecision, GateError, GateErrorCode, type GateStepUpStatus, HeartbeatManager, type HeartbeatToken, type Provenance, ProvenanceProvider, type SigningContext, type StepUpFinalResult, type StepUpMetadata, StepUpNotConfiguredError, type StepUpStatusResponse, type TransactionIntentV2, type WrapKmsClientOptions, type WrappedKmsClient, createGateClient, GateClient as default, wrapKmsClient };
|