blockintel-gate-sdk 0.3.3 → 0.3.5
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 +80 -6
- package/dist/index.cjs +148 -150
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -2
- package/dist/index.d.ts +16 -2
- package/dist/index.js +147 -149
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# BlockIntel Gate SDK
|
|
2
2
|
|
|
3
|
-
Production-grade TypeScript/Node.js SDK for [BlockIntel Gate](https://
|
|
3
|
+
Production-grade TypeScript/Node.js SDK for [BlockIntel Gate](https://blockintelai.com) Hot Path API.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -13,6 +13,12 @@ npm install @blockintel/gate-sdk
|
|
|
13
13
|
- Node.js >= 18.0.0 (uses global `fetch` API)
|
|
14
14
|
- TypeScript >= 5.0.0 (optional, for type definitions)
|
|
15
15
|
|
|
16
|
+
### Hot Path compatibility
|
|
17
|
+
|
|
18
|
+
- **Mode**: Default is `SHADOW` (Hot Path returns ALLOW with reason codes for would-block decisions). Set `mode: 'ENFORCE'` or `GATE_MODE=ENFORCE` for real BLOCK responses.
|
|
19
|
+
- **signingContext**: Hot Path requires `actorPrincipal` and `signerId`. The SDK defaults them when missing (`gate-sdk-client` or from `signingContext.signerId`).
|
|
20
|
+
- **ESM**: HMAC and SHA-256 use `node:crypto` (no `require('crypto')`), so the SDK works in ESM (`"type": "module"`) and in bundled canary apps.
|
|
21
|
+
|
|
16
22
|
## Quick Start
|
|
17
23
|
|
|
18
24
|
### HMAC Authentication
|
|
@@ -102,6 +108,47 @@ const response = await gate.evaluate({
|
|
|
102
108
|
});
|
|
103
109
|
```
|
|
104
110
|
|
|
111
|
+
### Local Development with Gate Local
|
|
112
|
+
|
|
113
|
+
For local development and testing, use **Gate Local** - a Docker container that emulates the Gate Hot Path:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
# Start Gate Local
|
|
117
|
+
docker pull blockintelai/gate-local:latest
|
|
118
|
+
docker run -d --name gate-local -p 3000:3000 blockintelai/gate-local:latest
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Then configure your client for local mode:
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
import { GateClient } from '@blockintel/gate-sdk';
|
|
125
|
+
|
|
126
|
+
// Local development configuration
|
|
127
|
+
const gate = new GateClient({
|
|
128
|
+
baseUrl: 'http://localhost:3000', // Gate Local endpoint
|
|
129
|
+
tenantId: 'local-dev', // Any tenant ID (ignored in local mode)
|
|
130
|
+
local: true, // Enable local mode (disables auth/heartbeat)
|
|
131
|
+
auth: {
|
|
132
|
+
mode: 'apiKey',
|
|
133
|
+
apiKey: 'local-dev-key' // Any API key (ignored in local mode)
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// Evaluate transactions locally
|
|
138
|
+
const response = await gate.evaluate({
|
|
139
|
+
txIntent: {
|
|
140
|
+
toAddress: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
|
|
141
|
+
value: '1000000000000000000', // 1 ETH in wei
|
|
142
|
+
valueUsd: 2500.0,
|
|
143
|
+
chainId: 1,
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
console.log(`Decision: ${response.decision}`);
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**📚 Full Local Development Guide**: See [Gate Local Quick Start Guide](https://docs.blockintelai.com/gate/local-development) for complete setup instructions, trading bot integration examples, and troubleshooting.
|
|
151
|
+
|
|
105
152
|
### Step-Up Polling
|
|
106
153
|
|
|
107
154
|
```typescript
|
|
@@ -159,9 +206,12 @@ When step-up is disabled, the SDK treats `REQUIRE_STEP_UP` as `BLOCK` by default
|
|
|
159
206
|
|
|
160
207
|
```bash
|
|
161
208
|
# Required
|
|
162
|
-
GATE_BASE_URL=https://gate.blockintelai.
|
|
209
|
+
GATE_BASE_URL=https://gate.blockintelai.com
|
|
163
210
|
GATE_TENANT_ID=your-tenant-id
|
|
164
211
|
|
|
212
|
+
# Heartbeat (required when not using local mode; parity with Python GATE_HEARTBEAT_KEY)
|
|
213
|
+
GATE_HEARTBEAT_KEY=your-heartbeat-key
|
|
214
|
+
|
|
165
215
|
# HMAC Authentication
|
|
166
216
|
GATE_KEY_ID=your-key-id
|
|
167
217
|
GATE_HMAC_SECRET=your-secret
|
|
@@ -335,6 +385,21 @@ The SDK automatically retries failed requests:
|
|
|
335
385
|
- Same `requestId` is used across all retries
|
|
336
386
|
- Ensures idempotency on Gate server
|
|
337
387
|
|
|
388
|
+
## Degraded Mode / X-BlockIntel-Degraded
|
|
389
|
+
|
|
390
|
+
When the SDK is in a degraded situation, it logs `X-BlockIntel-Degraded: true` with a `reason` for **logs and telemetry only**. This is **never sent as an HTTP request header** to the Gate server.
|
|
391
|
+
|
|
392
|
+
**Reasons:** `retry`, `429`, `fail_open`, `fail_safe_allow`.
|
|
393
|
+
|
|
394
|
+
**Example (one line):**
|
|
395
|
+
`[GATE SDK] X-BlockIntel-Degraded: true (reason=retry) attempt=1/3 status=503 err=RATE_LIMITED`
|
|
396
|
+
|
|
397
|
+
**How to observe:**
|
|
398
|
+
- **Logs:** `[GATE SDK] X-BlockIntel-Degraded: true (reason: <reason>)` via `console.warn`. Pipe stderr to your log aggregator.
|
|
399
|
+
- **Metrics:** Use `onMetrics`; metrics include `timeouts`, `errors`, `failOpen`, etc. Correlate with log lines if you ship both.
|
|
400
|
+
|
|
401
|
+
**Manual check (retry):** Point the SDK at an endpoint that returns 5xx; confirm one degraded log per retry attempt including `attempt`, `max`, and `status`/`err`.
|
|
402
|
+
|
|
338
403
|
## Heartbeat System
|
|
339
404
|
|
|
340
405
|
The SDK includes a **Heartbeat Manager** that automatically acquires and refreshes heartbeat tokens from the Gate Control Plane. Heartbeat tokens are required for all signing operations and ensure that Gate is alive and enforcing policy.
|
|
@@ -353,12 +418,12 @@ The heartbeat manager is automatically configured based on your `GateClientConfi
|
|
|
353
418
|
|
|
354
419
|
```typescript
|
|
355
420
|
const gate = new GateClient({
|
|
356
|
-
baseUrl: 'https://gate.blockintelai.
|
|
421
|
+
baseUrl: 'https://gate.blockintelai.com', // Hot Path URL
|
|
357
422
|
tenantId: 'your-tenant-id',
|
|
358
423
|
auth: { mode: 'hmac', ... },
|
|
359
424
|
// Heartbeat manager uses baseUrl to infer Control Plane URL
|
|
360
425
|
// Or explicitly set controlPlaneUrl if different
|
|
361
|
-
controlPlaneUrl: 'https://control-plane.blockintelai.
|
|
426
|
+
controlPlaneUrl: 'https://control-plane.blockintelai.com', // Optional
|
|
362
427
|
signerId: 'my-signer-id', // Optional: signerId for heartbeat (if known upfront)
|
|
363
428
|
heartbeatRefreshIntervalSeconds: 10, // Optional: heartbeat refresh interval (default: 10s)
|
|
364
429
|
});
|
|
@@ -455,13 +520,22 @@ See [examples](./examples) directory for complete examples:
|
|
|
455
520
|
|
|
456
521
|
See [PUBLISHING.md](./PUBLISHING.md) for detailed publishing instructions.
|
|
457
522
|
|
|
523
|
+
**Quick steps:**
|
|
524
|
+
1. Update version in `package.json`
|
|
525
|
+
2. Create GitHub release tag
|
|
526
|
+
3. GitHub Actions publishes to NPM automatically
|
|
527
|
+
|
|
458
528
|
## License
|
|
459
529
|
|
|
460
530
|
MIT License - see [LICENSE](./LICENSE) file.
|
|
461
531
|
|
|
462
532
|
## Support
|
|
463
533
|
|
|
464
|
-
- **Documentation:** https://docs.
|
|
534
|
+
- **Documentation:** https://docs.blockintelai.com
|
|
465
535
|
- **Issues:** https://github.com/4KInc/blockintel-ai/issues
|
|
466
|
-
- **Email:** support@
|
|
536
|
+
- **Email:** support@blockintelai.com
|
|
537
|
+
|
|
538
|
+
## Keywords
|
|
539
|
+
|
|
540
|
+
blockintel, gate, sdk, defense, crypto, security, transaction, evaluation
|
|
467
541
|
|