@private.me/xbind 1.2.0
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/AGENTS.md +778 -0
- package/LICENSE.md +27 -0
- package/README.md +400 -0
- package/dist-standalone/_deps/crypto/base64.d.ts +29 -0
- package/dist-standalone/_deps/crypto/base64.js +97 -0
- package/dist-standalone/_deps/crypto/cjs/base64.js +103 -0
- package/dist-standalone/_deps/crypto/cjs/errors.js +119 -0
- package/dist-standalone/_deps/crypto/cjs/hmac.js +71 -0
- package/dist-standalone/_deps/crypto/cjs/index.js +86 -0
- package/dist-standalone/_deps/crypto/cjs/padding.js +57 -0
- package/dist-standalone/_deps/crypto/cjs/share-header.js +68 -0
- package/dist-standalone/_deps/crypto/cjs/shares.js +152 -0
- package/dist-standalone/_deps/crypto/cjs/tlv.js +199 -0
- package/dist-standalone/_deps/crypto/cjs/uuid.js +61 -0
- package/dist-standalone/_deps/crypto/cjs/verify.js +24 -0
- package/dist-standalone/_deps/crypto/cjs/xorida.js +221 -0
- package/dist-standalone/_deps/crypto/errors.d.ts +51 -0
- package/dist-standalone/_deps/crypto/errors.js +109 -0
- package/dist-standalone/_deps/crypto/hmac.d.ts +39 -0
- package/dist-standalone/_deps/crypto/hmac.js +66 -0
- package/dist-standalone/_deps/crypto/index.d.ts +20 -0
- package/dist-standalone/_deps/crypto/index.js +45 -0
- package/dist-standalone/_deps/crypto/padding.d.ts +19 -0
- package/dist-standalone/_deps/crypto/padding.js +53 -0
- package/dist-standalone/_deps/crypto/share-header.d.ts +44 -0
- package/dist-standalone/_deps/crypto/share-header.js +63 -0
- package/dist-standalone/_deps/crypto/shares.d.ts +27 -0
- package/dist-standalone/_deps/crypto/shares.js +148 -0
- package/dist-standalone/_deps/crypto/tlv.d.ts +26 -0
- package/dist-standalone/_deps/crypto/tlv.js +195 -0
- package/dist-standalone/_deps/crypto/uuid.d.ts +22 -0
- package/dist-standalone/_deps/crypto/uuid.js +56 -0
- package/dist-standalone/_deps/crypto/verify.d.ts +15 -0
- package/dist-standalone/_deps/crypto/verify.js +15 -0
- package/dist-standalone/_deps/crypto/xorida.d.ts +44 -0
- package/dist-standalone/_deps/crypto/xorida.js +215 -0
- package/dist-standalone/_deps/mldsa-wasm/LICENSE +24 -0
- package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1920 -0
- package/dist-standalone/_deps/mldsa-wasm/package.json +46 -0
- package/dist-standalone/_deps/mldsa-wasm/types/mldsa.d.ts +30 -0
- package/dist-standalone/_deps/shared/cjs/errors.js +582 -0
- package/dist-standalone/_deps/shared/cjs/index.js +492 -0
- package/dist-standalone/_deps/shared/cjs/package.json +1 -0
- package/dist-standalone/_deps/shared/cjs/types.js +403 -0
- package/dist-standalone/_deps/shared/errors.d.ts +48 -0
- package/dist-standalone/_deps/shared/errors.d.ts.map +1 -0
- package/dist-standalone/_deps/shared/errors.js +192 -0
- package/dist-standalone/_deps/shared/errors.js.map +1 -0
- package/dist-standalone/_deps/shared/index.d.ts +4 -0
- package/dist-standalone/_deps/shared/index.d.ts.map +1 -0
- package/dist-standalone/_deps/shared/index.js +78 -0
- package/dist-standalone/_deps/shared/index.js.map +1 -0
- package/dist-standalone/_deps/shared/types.d.ts +1097 -0
- package/dist-standalone/_deps/shared/types.d.ts.map +1 -0
- package/dist-standalone/_deps/shared/types.js +89 -0
- package/dist-standalone/_deps/shared/types.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/errors.d.ts +115 -0
- package/dist-standalone/_deps/ux-helpers/cjs/errors.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/errors.js +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/errors.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/index.d.ts +13 -0
- package/dist-standalone/_deps/ux-helpers/cjs/index.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/index.js +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/index.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/package.json +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.d.ts +39 -0
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.js +83 -0
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/progress.d.ts +99 -0
- package/dist-standalone/_deps/ux-helpers/cjs/progress.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/progress.js +143 -0
- package/dist-standalone/_deps/ux-helpers/cjs/progress.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/search.d.ts +32 -0
- package/dist-standalone/_deps/ux-helpers/cjs/search.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/search.js +119 -0
- package/dist-standalone/_deps/ux-helpers/cjs/search.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/types.d.ts +109 -0
- package/dist-standalone/_deps/ux-helpers/cjs/types.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/cjs/types.js +8 -0
- package/dist-standalone/_deps/ux-helpers/cjs/types.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/errors.d.ts +115 -0
- package/dist-standalone/_deps/ux-helpers/errors.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/errors.js +253 -0
- package/dist-standalone/_deps/ux-helpers/errors.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/index.d.ts +13 -0
- package/dist-standalone/_deps/ux-helpers/index.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/index.js +16 -0
- package/dist-standalone/_deps/ux-helpers/index.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/pagination.d.ts +39 -0
- package/dist-standalone/_deps/ux-helpers/pagination.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/pagination.js +79 -0
- package/dist-standalone/_deps/ux-helpers/pagination.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/progress.d.ts +99 -0
- package/dist-standalone/_deps/ux-helpers/progress.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/progress.js +138 -0
- package/dist-standalone/_deps/ux-helpers/progress.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/search.d.ts +32 -0
- package/dist-standalone/_deps/ux-helpers/search.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/search.js +116 -0
- package/dist-standalone/_deps/ux-helpers/search.js.map +1 -0
- package/dist-standalone/_deps/ux-helpers/types.d.ts +109 -0
- package/dist-standalone/_deps/ux-helpers/types.d.ts.map +1 -0
- package/dist-standalone/_deps/ux-helpers/types.js +7 -0
- package/dist-standalone/_deps/ux-helpers/types.js.map +1 -0
- package/dist-standalone/_deps/xchange/auto-accept.d.ts +127 -0
- package/dist-standalone/_deps/xchange/auto-accept.js +1 -0
- package/dist-standalone/_deps/xchange/cjs/auto-accept.js +1 -0
- package/dist-standalone/_deps/xchange/cjs/errors.js +1 -0
- package/dist-standalone/_deps/xchange/cjs/index.js +1 -0
- package/dist-standalone/_deps/xchange/cjs/invite-client.js +1 -0
- package/dist-standalone/_deps/xchange/cjs/lazy-init.js +1 -0
- package/dist-standalone/_deps/xchange/cjs/package.json +1 -0
- package/dist-standalone/_deps/xchange/cjs/trust-integration.js +1 -0
- package/dist-standalone/_deps/xchange/cjs/xchange.js +1 -0
- package/dist-standalone/_deps/xchange/errors.d.ts +69 -0
- package/dist-standalone/_deps/xchange/errors.js +1 -0
- package/dist-standalone/_deps/xchange/index.d.ts +15 -0
- package/dist-standalone/_deps/xchange/index.js +1 -0
- package/dist-standalone/_deps/xchange/invite-client.d.ts +178 -0
- package/dist-standalone/_deps/xchange/invite-client.js +1 -0
- package/dist-standalone/_deps/xchange/lazy-init.d.ts +176 -0
- package/dist-standalone/_deps/xchange/lazy-init.js +1 -0
- package/dist-standalone/_deps/xchange/trust-integration.d.ts +102 -0
- package/dist-standalone/_deps/xchange/trust-integration.js +1 -0
- package/dist-standalone/_deps/xchange/xchange.d.ts +60 -0
- package/dist-standalone/_deps/xchange/xchange.js +1 -0
- package/dist-standalone/_deps/xregistry/cjs/discovery.js +1 -0
- package/dist-standalone/_deps/xregistry/cjs/errors.js +1 -0
- package/dist-standalone/_deps/xregistry/cjs/index.js +1 -0
- package/dist-standalone/_deps/xregistry/cjs/package.json +1 -0
- package/dist-standalone/_deps/xregistry/cjs/registry.js +1 -0
- package/dist-standalone/_deps/xregistry/cjs/schema.js +1 -0
- package/dist-standalone/_deps/xregistry/cjs/types.js +1 -0
- package/dist-standalone/_deps/xregistry/discovery.d.ts +126 -0
- package/dist-standalone/_deps/xregistry/discovery.d.ts.map +1 -0
- package/dist-standalone/_deps/xregistry/discovery.js +1 -0
- package/dist-standalone/_deps/xregistry/discovery.js.map +1 -0
- package/dist-standalone/_deps/xregistry/errors.d.ts +41 -0
- package/dist-standalone/_deps/xregistry/errors.d.ts.map +1 -0
- package/dist-standalone/_deps/xregistry/errors.js +1 -0
- package/dist-standalone/_deps/xregistry/errors.js.map +1 -0
- package/dist-standalone/_deps/xregistry/index.d.ts +8 -0
- package/dist-standalone/_deps/xregistry/index.d.ts.map +1 -0
- package/dist-standalone/_deps/xregistry/index.js +1 -0
- package/dist-standalone/_deps/xregistry/index.js.map +1 -0
- package/dist-standalone/_deps/xregistry/registry.d.ts +85 -0
- package/dist-standalone/_deps/xregistry/registry.d.ts.map +1 -0
- package/dist-standalone/_deps/xregistry/registry.js +1 -0
- package/dist-standalone/_deps/xregistry/registry.js.map +1 -0
- package/dist-standalone/_deps/xregistry/schema.d.ts +81 -0
- package/dist-standalone/_deps/xregistry/schema.d.ts.map +1 -0
- package/dist-standalone/_deps/xregistry/schema.js +1 -0
- package/dist-standalone/_deps/xregistry/schema.js.map +1 -0
- package/dist-standalone/_deps/xregistry/types.d.ts +95 -0
- package/dist-standalone/_deps/xregistry/types.d.ts.map +1 -0
- package/dist-standalone/_deps/xregistry/types.js +1 -0
- package/dist-standalone/_deps/xregistry/types.js.map +1 -0
- package/dist-standalone/agent-call.d.ts +286 -0
- package/dist-standalone/agent-call.js +642 -0
- package/dist-standalone/agent-sdk.d.ts +207 -0
- package/dist-standalone/agent-sdk.js +328 -0
- package/dist-standalone/agent.d.ts +670 -0
- package/dist-standalone/agent.js +1529 -0
- package/dist-standalone/approval.d.ts +145 -0
- package/dist-standalone/approval.js +193 -0
- package/dist-standalone/auth.d.ts +75 -0
- package/dist-standalone/auth.js +219 -0
- package/dist-standalone/auto-accept.d.ts +102 -0
- package/dist-standalone/auto-accept.js +229 -0
- package/dist-standalone/backup-config.d.ts +150 -0
- package/dist-standalone/backup-config.js +201 -0
- package/dist-standalone/checkpoint.d.ts +125 -0
- package/dist-standalone/checkpoint.js +186 -0
- package/dist-standalone/cjs/agent-call.js +651 -0
- package/dist-standalone/cjs/agent-sdk.js +332 -0
- package/dist-standalone/cjs/agent.js +1566 -0
- package/dist-standalone/cjs/approval.js +199 -0
- package/dist-standalone/cjs/auth.js +225 -0
- package/dist-standalone/cjs/auto-accept.js +233 -0
- package/dist-standalone/cjs/backup-config.js +207 -0
- package/dist-standalone/cjs/checkpoint.js +193 -0
- package/dist-standalone/cjs/cli/init.js +487 -0
- package/dist-standalone/cjs/connect.js +312 -0
- package/dist-standalone/cjs/did-document.js +101 -0
- package/dist-standalone/cjs/did-privateme.js +130 -0
- package/dist-standalone/cjs/did-web.js +201 -0
- package/dist-standalone/cjs/discovery.js +462 -0
- package/dist-standalone/cjs/dual-mode.js +251 -0
- package/dist-standalone/cjs/email-templates.js +313 -0
- package/dist-standalone/cjs/email-transport.js +239 -0
- package/dist-standalone/cjs/envelope.js +510 -0
- package/dist-standalone/cjs/errors.js +562 -0
- package/dist-standalone/cjs/gateway-state.js +55 -0
- package/dist-standalone/cjs/gateway-transport.js +120 -0
- package/dist-standalone/cjs/guardrails.js +223 -0
- package/dist-standalone/cjs/http-compat.js +272 -0
- package/dist-standalone/cjs/identity.js +541 -0
- package/dist-standalone/cjs/index.js +224 -0
- package/dist-standalone/cjs/invitation.js +421 -0
- package/dist-standalone/cjs/invite.js +328 -0
- package/dist-standalone/cjs/key-agreement.js +246 -0
- package/dist-standalone/cjs/lazy-init.js +300 -0
- package/dist-standalone/cjs/mdns-discovery.js +202 -0
- package/dist-standalone/cjs/nonce-store.js +66 -0
- package/dist-standalone/cjs/package.json +3 -0
- package/dist-standalone/cjs/pairing-manager.js +223 -0
- package/dist-standalone/cjs/policy.js +320 -0
- package/dist-standalone/cjs/redis-nonce-store.js +76 -0
- package/dist-standalone/cjs/registry-middleware.js +50 -0
- package/dist-standalone/cjs/retry-transport.js +102 -0
- package/dist-standalone/cjs/security-policy.js +204 -0
- package/dist-standalone/cjs/split-channel.js +177 -0
- package/dist-standalone/cjs/subscription-proof.js +230 -0
- package/dist-standalone/cjs/succession.js +148 -0
- package/dist-standalone/cjs/transport.js +63 -0
- package/dist-standalone/cjs/trust-registry.js +742 -0
- package/dist-standalone/cjs/verify.js +25 -0
- package/dist-standalone/cjs/xfetch.js +252 -0
- package/dist-standalone/cli/init.d.ts +63 -0
- package/dist-standalone/cli/init.js +450 -0
- package/dist-standalone/connect.d.ts +143 -0
- package/dist-standalone/connect.js +274 -0
- package/dist-standalone/did-document.d.ts +65 -0
- package/dist-standalone/did-document.js +96 -0
- package/dist-standalone/did-privateme.d.ts +70 -0
- package/dist-standalone/did-privateme.js +121 -0
- package/dist-standalone/did-web.d.ts +73 -0
- package/dist-standalone/did-web.js +196 -0
- package/dist-standalone/discovery.d.ts +176 -0
- package/dist-standalone/discovery.js +458 -0
- package/dist-standalone/dual-mode.d.ts +145 -0
- package/dist-standalone/dual-mode.js +247 -0
- package/dist-standalone/email-templates.d.ts +41 -0
- package/dist-standalone/email-templates.js +309 -0
- package/dist-standalone/email-transport.d.ts +139 -0
- package/dist-standalone/email-transport.js +232 -0
- package/dist-standalone/envelope.d.ts +288 -0
- package/dist-standalone/envelope.js +497 -0
- package/dist-standalone/errors.d.ts +74 -0
- package/dist-standalone/errors.js +548 -0
- package/dist-standalone/gateway-state.d.ts +32 -0
- package/dist-standalone/gateway-state.js +51 -0
- package/dist-standalone/gateway-transport.d.ts +59 -0
- package/dist-standalone/gateway-transport.js +116 -0
- package/dist-standalone/guardrails.d.ts +136 -0
- package/dist-standalone/guardrails.js +216 -0
- package/dist-standalone/http-compat.d.ts +150 -0
- package/dist-standalone/http-compat.js +267 -0
- package/dist-standalone/identity.d.ts +176 -0
- package/dist-standalone/identity.js +516 -0
- package/dist-standalone/index.d.ts +83 -0
- package/dist-standalone/index.js +51 -0
- package/dist-standalone/invitation.d.ts +211 -0
- package/dist-standalone/invitation.js +415 -0
- package/dist-standalone/invite.d.ts +192 -0
- package/dist-standalone/invite.js +324 -0
- package/dist-standalone/key-agreement.d.ts +122 -0
- package/dist-standalone/key-agreement.js +236 -0
- package/dist-standalone/lazy-init.d.ts +167 -0
- package/dist-standalone/lazy-init.js +295 -0
- package/dist-standalone/mdns-discovery.d.ts +117 -0
- package/dist-standalone/mdns-discovery.js +195 -0
- package/dist-standalone/nonce-store.d.ts +39 -0
- package/dist-standalone/nonce-store.js +62 -0
- package/dist-standalone/package.json +11 -0
- package/dist-standalone/pairing-manager.d.ts +147 -0
- package/dist-standalone/pairing-manager.js +219 -0
- package/dist-standalone/policy.d.ts +150 -0
- package/dist-standalone/policy.js +315 -0
- package/dist-standalone/redis-nonce-store.d.ts +93 -0
- package/dist-standalone/redis-nonce-store.js +72 -0
- package/dist-standalone/registry-middleware.d.ts +38 -0
- package/dist-standalone/registry-middleware.js +47 -0
- package/dist-standalone/retry-transport.d.ts +76 -0
- package/dist-standalone/retry-transport.js +98 -0
- package/dist-standalone/security-policy.d.ts +146 -0
- package/dist-standalone/security-policy.js +198 -0
- package/dist-standalone/split-channel.d.ts +69 -0
- package/dist-standalone/split-channel.js +171 -0
- package/dist-standalone/subscription-proof.d.ts +103 -0
- package/dist-standalone/subscription-proof.js +224 -0
- package/dist-standalone/succession.d.ts +57 -0
- package/dist-standalone/succession.js +142 -0
- package/dist-standalone/transport.d.ts +50 -0
- package/dist-standalone/transport.js +59 -0
- package/dist-standalone/trust-registry.d.ts +286 -0
- package/dist-standalone/trust-registry.js +702 -0
- package/dist-standalone/verify.d.ts +16 -0
- package/dist-standalone/verify.js +16 -0
- package/dist-standalone/xfetch.d.ts +129 -0
- package/dist-standalone/xfetch.js +247 -0
- package/llms.txt +800 -0
- package/package.json +79 -0
- package/share1.dat +0 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,778 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
AI-specific guidance for code generation with @private.me/xbind (xBind)
|
|
4
|
+
|
|
5
|
+
## Standard Pattern (Recommended for AI Agents)
|
|
6
|
+
|
|
7
|
+
When implementing AI agent tool calls, ALWAYS use the `agent.call()` pattern:
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { call } from '@private.me/xbind';
|
|
11
|
+
|
|
12
|
+
// Simple tool call - identity and security handled automatically
|
|
13
|
+
const result = await call('stripe:createCharge', {
|
|
14
|
+
amount: 100,
|
|
15
|
+
currency: 'usd',
|
|
16
|
+
description: 'AI agent purchase'
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
if (!result.ok) {
|
|
20
|
+
console.error(`Failed: ${result.error.message}`);
|
|
21
|
+
// Error has structured details: code, context, cause, fix
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
console.log('Charge created:', result.value.data.id);
|
|
26
|
+
console.log('Audit receipt:', result.value.audit);
|
|
27
|
+
// Audit receipt includes: agent DID, tool name, timestamp, signature status
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## With Policy Constraints and Approval Flow
|
|
31
|
+
|
|
32
|
+
For production AI agents, add spending limits, rate limits, and OAuth-style approval:
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { call } from '@private.me/xbind';
|
|
36
|
+
|
|
37
|
+
const result = await call('payments:charge', { amount: 5000 }, {
|
|
38
|
+
mode: 'secure', // Force 2-of-3 split-channel security
|
|
39
|
+
policy: {
|
|
40
|
+
limits: {
|
|
41
|
+
amountPerTxn: 10000, // Max $100 per transaction
|
|
42
|
+
dailyAmount: 50000, // Max $500 per day
|
|
43
|
+
monthlyAmount: 200000, // Max $2,000 per month
|
|
44
|
+
callsPerMinute: 10, // Rate limit
|
|
45
|
+
},
|
|
46
|
+
scopes: ['payments:read', 'payments:write'],
|
|
47
|
+
requireApproval: true, // OAuth-style consent flow
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// First call triggers approval UI, returns token
|
|
52
|
+
// Subsequent calls with token proceed automatically
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Ephemeral Agents (Short-lived identities)
|
|
56
|
+
|
|
57
|
+
For temporary AI agents that should auto-cleanup:
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
const result = await call('analytics:query', {
|
|
61
|
+
metric: 'daily_revenue'
|
|
62
|
+
}, {
|
|
63
|
+
ephemeral: true, // Identity deleted after 1 hour
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Low-Level Control (Advanced)
|
|
68
|
+
|
|
69
|
+
When you need full control over identity and transport:
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { Agent, HttpsTransportAdapter } from '@private.me/xbind';
|
|
73
|
+
|
|
74
|
+
// Create custom transport (optional - SDK provides default)
|
|
75
|
+
const transport = new HttpsTransportAdapter({
|
|
76
|
+
baseUrl: 'https://your-relay.example.com',
|
|
77
|
+
timeoutMs: 15000 // Custom timeout
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Create agent with specific configuration
|
|
81
|
+
const agent = await Agent.quickstart({
|
|
82
|
+
name: 'my-service',
|
|
83
|
+
registry: 'https://registry.example.com',
|
|
84
|
+
transport // Use custom transport
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// Send with granular control
|
|
88
|
+
const result = await agent.send({
|
|
89
|
+
to: 'did:key:z6Mk...',
|
|
90
|
+
payload: { command: 'execute' },
|
|
91
|
+
scope: 'admin',
|
|
92
|
+
security: 'high', // Force 2-of-3 split-channel
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// Always clean up to prevent timer leaks
|
|
96
|
+
agent.cleanup(); // or agent.dispose()
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Audit Receipts and Transparency
|
|
100
|
+
|
|
101
|
+
Every `call()` result includes an audit receipt with cryptographic attribution:
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
const result = await call('payments:charge', { amount: 100 });
|
|
105
|
+
|
|
106
|
+
if (result.ok) {
|
|
107
|
+
const { data, audit } = result.value;
|
|
108
|
+
|
|
109
|
+
console.log('Data:', data);
|
|
110
|
+
console.log('Agent DID:', audit.agent);
|
|
111
|
+
console.log('Tool called:', audit.tool);
|
|
112
|
+
console.log('Scope:', audit.scope);
|
|
113
|
+
console.log('Timestamp:', audit.timestamp);
|
|
114
|
+
console.log('Signature:', audit.signature); // 'valid' | 'invalid' | 'not_verified'
|
|
115
|
+
console.log('Policy:', audit.policy); // 'passed' | 'denied' | 'not_evaluated'
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**Signature verification status:**
|
|
120
|
+
- `'valid'` — Message signature verified, sender identity confirmed
|
|
121
|
+
- `'invalid'` — Signature check failed, message may be tampered or forged
|
|
122
|
+
- `'not_verified'` — Signature verification skipped (testing mode)
|
|
123
|
+
|
|
124
|
+
**Policy decision status:**
|
|
125
|
+
- `'passed'` — Operation allowed by policy constraints
|
|
126
|
+
- `'denied'` — Operation blocked (exceeds limits, wrong scope, etc.)
|
|
127
|
+
- `'not_evaluated'` — No policy configured
|
|
128
|
+
|
|
129
|
+
Use audit receipts for SOC 2, HIPAA, GDPR compliance (cryptographic proof of who did what).
|
|
130
|
+
|
|
131
|
+
## Transport Error Handling
|
|
132
|
+
|
|
133
|
+
Transport layer handles network delivery with actionable error codes:
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
import { Agent, type TransportError } from '@private.me/xbind';
|
|
137
|
+
|
|
138
|
+
const agent = await Agent.quickstart({ name: 'sender' });
|
|
139
|
+
|
|
140
|
+
const result = await agent.send({
|
|
141
|
+
to: recipientDid,
|
|
142
|
+
payload: { data: 'hello' },
|
|
143
|
+
scope: 'messages'
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
if (!result.ok) {
|
|
147
|
+
const error: TransportError = result.error;
|
|
148
|
+
|
|
149
|
+
switch (error) {
|
|
150
|
+
case 'NETWORK_ERROR':
|
|
151
|
+
console.error('Network failure - check connectivity');
|
|
152
|
+
// Retry with exponential backoff
|
|
153
|
+
break;
|
|
154
|
+
|
|
155
|
+
case 'TIMEOUT':
|
|
156
|
+
console.error('Request timed out - recipient may be slow');
|
|
157
|
+
// Increase timeout or retry
|
|
158
|
+
break;
|
|
159
|
+
|
|
160
|
+
case 'RECIPIENT_UNREACHABLE':
|
|
161
|
+
console.error('Recipient not found (404)');
|
|
162
|
+
// Verify DID is registered and active
|
|
163
|
+
break;
|
|
164
|
+
|
|
165
|
+
case 'SEND_FAILED':
|
|
166
|
+
console.error('Delivery failed (non-404 error)');
|
|
167
|
+
// Check server logs, verify permissions
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
**Transport error codes:**
|
|
174
|
+
- `NETWORK_ERROR` — Network connectivity issue (DNS, firewall, etc.)
|
|
175
|
+
- `TIMEOUT` — Request exceeded timeout threshold (default: 10s)
|
|
176
|
+
- `RECIPIENT_UNREACHABLE` — Recipient DID not found (HTTP 404)
|
|
177
|
+
- `SEND_FAILED` — Server returned error (HTTP 4xx/5xx)
|
|
178
|
+
|
|
179
|
+
**Best practices:**
|
|
180
|
+
- Use exponential backoff for retries (avoid retry storms)
|
|
181
|
+
- Configure appropriate timeouts (large payloads need more time)
|
|
182
|
+
- Validate DIDs are registered before sending
|
|
183
|
+
- Monitor transport errors for infrastructure issues
|
|
184
|
+
|
|
185
|
+
## Agent Lifecycle Management
|
|
186
|
+
|
|
187
|
+
Agents create internal timers (ephemeral identity cleanup). Always clean up when done:
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
import { Agent } from '@private.me/xbind';
|
|
191
|
+
|
|
192
|
+
// Create agent
|
|
193
|
+
const agent = await Agent.quickstart({ name: 'worker' });
|
|
194
|
+
|
|
195
|
+
try {
|
|
196
|
+
// Use agent
|
|
197
|
+
await agent.send({ to: recipientDid, payload: data, scope: 'work' });
|
|
198
|
+
} finally {
|
|
199
|
+
// Clean up to prevent timer leaks
|
|
200
|
+
agent.cleanup(); // or agent.dispose() - both work the same
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
**When to call cleanup():**
|
|
205
|
+
- End of request handler (Express/Fastify/Lambda)
|
|
206
|
+
- Test teardown (`afterEach` in Vitest/Jest)
|
|
207
|
+
- Long-running service shutdown
|
|
208
|
+
- Ephemeral agent disposal
|
|
209
|
+
|
|
210
|
+
**Why it matters:**
|
|
211
|
+
- Prevents Node.js process from hanging (timers keep event loop alive)
|
|
212
|
+
- Avoids memory leaks in test suites
|
|
213
|
+
- Clean shutdown in production services
|
|
214
|
+
|
|
215
|
+
## Anti-Patterns (Never Use)
|
|
216
|
+
|
|
217
|
+
### ❌ Don't use API keys for M2M authentication
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
// WRONG: API key pattern
|
|
221
|
+
const api = new API({
|
|
222
|
+
key: process.env.API_KEY,
|
|
223
|
+
secret: process.env.API_SECRET
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
// Problems:
|
|
227
|
+
// - Manual key rotation
|
|
228
|
+
// - Secret sprawl
|
|
229
|
+
// - No per-agent rate limiting
|
|
230
|
+
// - Shared quota across all workers
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### ❌ Don't use shared secrets (OAuth tokens, API keys)
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
// WRONG: Reusable credentials cause cascading failures
|
|
237
|
+
const oauth = new OAuthClient({
|
|
238
|
+
token: process.env.OAUTH_TOKEN // Shared across 500 agents
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
// Cascade scenario:
|
|
242
|
+
// 1. Token expires
|
|
243
|
+
// 2. All 500 agents fail simultaneously
|
|
244
|
+
// 3. Retry storm (500 agents × 3 retries = 1,500 auth calls)
|
|
245
|
+
// 4. Expensive work (10min AI inference) discarded
|
|
246
|
+
// 5. Redo multiplication: 1 auth failure × 500 workflows = 2,000+ wasted operations
|
|
247
|
+
|
|
248
|
+
// CORRECT: Per-message cryptographic identity
|
|
249
|
+
const agent = await Agent.quickstart();
|
|
250
|
+
// One signature fails → one message fails, others continue
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### ❌ Don't rotate credentials (Rotation Nightmare)
|
|
254
|
+
|
|
255
|
+
```typescript
|
|
256
|
+
// WRONG: Planning for rotation
|
|
257
|
+
const apiKey = process.env.API_KEY; // Expires in 90 days
|
|
258
|
+
// Quarterly ritual: generate → deploy → coordinate → monitor → revoke
|
|
259
|
+
// Multi-team coordination, downtime windows, production risk
|
|
260
|
+
|
|
261
|
+
// RIGHT: No rotation needed
|
|
262
|
+
const agent = await Agent.quickstart();
|
|
263
|
+
// Per-message signatures. No expiry. No rotation.
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
**Why this fails:** SOC 2/ISO 27001 mandate 90-day rotation. With API keys, this means quarterly system-wide updates with hours of coordination and downtime.
|
|
267
|
+
|
|
268
|
+
**xBind solution:** Cryptographic identity eliminates rotation. Keys never transmitted, so compliance is satisfied without operational burden.
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
### ❌ Don't use shared credentials for fleets (AI Agent Explosion)
|
|
273
|
+
|
|
274
|
+
```typescript
|
|
275
|
+
// WRONG: 500 agents sharing 1 key
|
|
276
|
+
const agents = Array.from({ length: 500 }, () =>
|
|
277
|
+
new AIAgent({ apiKey: process.env.SHARED_KEY })
|
|
278
|
+
);
|
|
279
|
+
// All 500 hit same quota. Can't identify which agent did what.
|
|
280
|
+
|
|
281
|
+
// RIGHT: Unique identity per agent
|
|
282
|
+
const agents = await Promise.all(
|
|
283
|
+
Array.from({ length: 500 }, () => Agent.quickstart())
|
|
284
|
+
);
|
|
285
|
+
// 500 agents = 500 DIDs = 500 separate quotas
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
**Why this fails:** 1 developer spawns 500 AI agents (LangChain/CrewAI). Sharing 1 API key across all = quota chaos, zero attribution, blast radius.
|
|
289
|
+
|
|
290
|
+
**xBind solution:** Each agent gets unique DID. Per-agent rate limiting, per-agent attribution, per-agent revocation.
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
### ❌ Don't rely on log correlation for audits (Compliance Audit Hell)
|
|
295
|
+
|
|
296
|
+
```typescript
|
|
297
|
+
// WRONG: Forensic guesswork
|
|
298
|
+
// Auditor: "Which agent made this call?"
|
|
299
|
+
// You: "Let me grep the logs and guess based on timestamps..."
|
|
300
|
+
// SOC 2 Type II compliance: FAILED
|
|
301
|
+
|
|
302
|
+
// RIGHT: Cryptographic attribution
|
|
303
|
+
const msg = await agent.receive();
|
|
304
|
+
if (msg.ok) {
|
|
305
|
+
console.log(`Sender DID: ${msg.value.sender}`);
|
|
306
|
+
// Ed25519 signature verified. Non-repudiable proof.
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
**Why this fails:** Shared API keys provide zero attribution. Auditors ask "Which of your 200 agents made this call?" and you cannot answer with cryptographic certainty.
|
|
311
|
+
|
|
312
|
+
**xBind solution:** Every message signed with sender DID. SOC 2/HIPAA/GDPR audit trails with cryptographic proof.
|
|
313
|
+
|
|
314
|
+
---
|
|
315
|
+
|
|
316
|
+
### ❌ Don't use all-or-nothing revocation (Granular Revocation)
|
|
317
|
+
|
|
318
|
+
```typescript
|
|
319
|
+
// WRONG: Nuclear option
|
|
320
|
+
// Agent #47 goes rogue
|
|
321
|
+
// Only option: Revoke API key
|
|
322
|
+
// Result: All 1,000 agents stop
|
|
323
|
+
|
|
324
|
+
// RIGHT: Surgical revocation
|
|
325
|
+
await registry.revoke('did:key:z6Mk...[agent-47]');
|
|
326
|
+
// Agent #47 revoked. 999 agents keep working.
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
**Why this fails:** Shared credentials = shared fate. One compromised agent forces you to revoke the entire fleet.
|
|
330
|
+
|
|
331
|
+
**xBind solution:** Trust registry with per-DID revocation. Instant, surgical, zero blast radius.
|
|
332
|
+
|
|
333
|
+
---
|
|
334
|
+
|
|
335
|
+
### ❌ Don't skip error handling
|
|
336
|
+
|
|
337
|
+
```typescript
|
|
338
|
+
// WRONG: Assumes success
|
|
339
|
+
const result = await agent.send({ action: 'transfer', payload: data });
|
|
340
|
+
console.log(result.value.messageId); // Crashes if !result.ok
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
### ❌ Don't omit type assertions
|
|
344
|
+
|
|
345
|
+
```typescript
|
|
346
|
+
// WRONG: No type safety
|
|
347
|
+
const result = await agent.send(message);
|
|
348
|
+
// Field name drift undetected - could access result.id when it's actually result.messageId
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
### ❌ Don't use splitChannel flag manually (deprecated as of Session 102)
|
|
352
|
+
|
|
353
|
+
```typescript
|
|
354
|
+
// WRONG: Manual security override
|
|
355
|
+
await agent.send({
|
|
356
|
+
payload: data,
|
|
357
|
+
splitChannel: true, // DEPRECATED
|
|
358
|
+
splitChannelConfig: { totalShares: 3, threshold: 2 }
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
// CORRECT: Automatic risk-based security
|
|
362
|
+
await agent.send({
|
|
363
|
+
action: 'transfer',
|
|
364
|
+
payload: { amount: 150000 },
|
|
365
|
+
// System auto-applies 2-of-3 for high-value transfers
|
|
366
|
+
});
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
---
|
|
370
|
+
|
|
371
|
+
## Bilateral Authorization Anti-Patterns
|
|
372
|
+
|
|
373
|
+
### ❌ Don't skip receiver scope validation
|
|
374
|
+
|
|
375
|
+
```typescript
|
|
376
|
+
// WRONG: Send sensitive data without checking if receiver accepts it
|
|
377
|
+
await agent.send({
|
|
378
|
+
action: 'user_analytics',
|
|
379
|
+
payload: { userId, behaviorData },
|
|
380
|
+
scope: 'analytics'
|
|
381
|
+
});
|
|
382
|
+
// Problem: Receiver may not want analytics data, violates consent
|
|
383
|
+
|
|
384
|
+
// CORRECT: Check receiver capabilities first
|
|
385
|
+
const canReceive = await agent.hasReceiveScope(recipientDid, 'analytics');
|
|
386
|
+
if (!canReceive) {
|
|
387
|
+
console.warn('Recipient opted out of analytics data');
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
await agent.send({
|
|
392
|
+
action: 'user_analytics',
|
|
393
|
+
payload: { userId, behaviorData },
|
|
394
|
+
scope: 'analytics'
|
|
395
|
+
});
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
**Why this fails:** Sending data without consent violates GDPR/privacy principles. Receiver may not want analytics, marketing, or telemetry data.
|
|
399
|
+
|
|
400
|
+
**xBind solution:** `hasReceiveScope()` validates receiver accepts the scope before sending. Respect consent boundaries.
|
|
401
|
+
|
|
402
|
+
---
|
|
403
|
+
|
|
404
|
+
### ❌ Don't assume undefined receiveScopes means "deny all"
|
|
405
|
+
|
|
406
|
+
```typescript
|
|
407
|
+
// WRONG: Interpret missing receiveScopes as rejection
|
|
408
|
+
const agent = await Agent.quickstart({
|
|
409
|
+
sendScopes: ['payments', 'notifications'],
|
|
410
|
+
// receiveScopes undefined
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
// WRONG assumption: "This agent can't receive anything"
|
|
414
|
+
// ACTUAL behavior: Accepts all scopes (backward compatibility)
|
|
415
|
+
|
|
416
|
+
// CORRECT: Explicitly opt-out if you don't want data
|
|
417
|
+
const agent = await Agent.quickstart({
|
|
418
|
+
sendScopes: ['payments', 'notifications'],
|
|
419
|
+
receiveScopes: [] // Explicit: accept nothing
|
|
420
|
+
});
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
**Why this fails:** `undefined` receiveScopes means "accept all" for backward compatibility with agents that don't use bilateral authorization.
|
|
424
|
+
|
|
425
|
+
**xBind solution:** Use `receiveScopes: []` to explicitly reject all incoming data. Empty array = opt-out.
|
|
426
|
+
|
|
427
|
+
---
|
|
428
|
+
|
|
429
|
+
### ❌ Don't use same scopes for sending and receiving
|
|
430
|
+
|
|
431
|
+
```typescript
|
|
432
|
+
// WRONG: Mirror scopes
|
|
433
|
+
const agent = await Agent.quickstart({
|
|
434
|
+
sendScopes: ['payments', 'analytics', 'notifications'],
|
|
435
|
+
receiveScopes: ['payments', 'analytics', 'notifications']
|
|
436
|
+
// Problem: Agent may not want to RECEIVE analytics even if it SENDS them
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
// CORRECT: Different purposes
|
|
440
|
+
const agent = await Agent.quickstart({
|
|
441
|
+
sendScopes: ['payments', 'analytics', 'notifications'],
|
|
442
|
+
receiveScopes: ['payments', 'notifications']
|
|
443
|
+
// Sends analytics to data warehouse, but doesn't accept analytics from others
|
|
444
|
+
});
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
**Why this fails:** Sending and receiving scopes serve different purposes. An analytics service sends analytics but shouldn't receive analytics from random agents.
|
|
448
|
+
|
|
449
|
+
**xBind solution:** Configure scopes independently. sendScopes = "what I produce", receiveScopes = "what I accept".
|
|
450
|
+
|
|
451
|
+
---
|
|
452
|
+
|
|
453
|
+
### ✅ DO: Validate receiver can accept before sending sensitive data
|
|
454
|
+
|
|
455
|
+
```typescript
|
|
456
|
+
// Payment service checking if compliance officer accepts audit logs
|
|
457
|
+
const canReceiveAudit = await agent.hasReceiveScope(
|
|
458
|
+
complianceOfficerDid,
|
|
459
|
+
'audit-logs'
|
|
460
|
+
);
|
|
461
|
+
|
|
462
|
+
if (!canReceiveAudit) {
|
|
463
|
+
// Fall back to local logging only
|
|
464
|
+
await localAuditLog.write(event);
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// Officer accepts audit logs - send securely
|
|
469
|
+
await agent.send({
|
|
470
|
+
action: 'audit_event',
|
|
471
|
+
payload: { event, timestamp, actor },
|
|
472
|
+
scope: 'audit-logs'
|
|
473
|
+
});
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
**Best practice:** Always validate before sending sensitive data (PII, financial, health, analytics).
|
|
477
|
+
|
|
478
|
+
---
|
|
479
|
+
|
|
480
|
+
### ✅ DO: Use receiveScopes to opt-out of unwanted data
|
|
481
|
+
|
|
482
|
+
```typescript
|
|
483
|
+
// Analytics service: sends analytics, doesn't receive them
|
|
484
|
+
const analyticsAgent = await Agent.quickstart({
|
|
485
|
+
name: 'analytics-collector',
|
|
486
|
+
sendScopes: ['analytics', 'telemetry'],
|
|
487
|
+
receiveScopes: [] // Opt-out: don't send me data
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
// Payment service: sends payments, receives notifications
|
|
491
|
+
const paymentAgent = await Agent.quickstart({
|
|
492
|
+
name: 'payment-processor',
|
|
493
|
+
sendScopes: ['payments', 'webhooks'],
|
|
494
|
+
receiveScopes: ['notifications', 'alerts'] // Accept only these
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
// IoT device: sends telemetry, receives commands only
|
|
498
|
+
const iotDevice = await Agent.quickstart({
|
|
499
|
+
name: 'sensor-node-47',
|
|
500
|
+
sendScopes: ['telemetry', 'health'],
|
|
501
|
+
receiveScopes: ['commands'] // Accept remote commands, reject analytics
|
|
502
|
+
});
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
**Best practice:** Use `receiveScopes` to declare data preferences. Protects privacy and reduces unwanted traffic.
|
|
506
|
+
|
|
507
|
+
---
|
|
508
|
+
|
|
509
|
+
## Prefer
|
|
510
|
+
|
|
511
|
+
✅ **Cryptographic identity (DIDs) over API keys**
|
|
512
|
+
- Zero key management
|
|
513
|
+
- Per-agent rate limiting (1,000 workers = 1,000 separate quotas)
|
|
514
|
+
- Automatic credential rotation
|
|
515
|
+
|
|
516
|
+
✅ **Result<T, E> pattern for all async operations**
|
|
517
|
+
- Type-safe error handling
|
|
518
|
+
- Compiler catches field name drift
|
|
519
|
+
- Explicit success/failure branches
|
|
520
|
+
|
|
521
|
+
✅ **Automatic security levels (invisible security)**
|
|
522
|
+
- System detects high-value transfers
|
|
523
|
+
- Auto-applies multi-party approval (2-of-3)
|
|
524
|
+
- No manual configuration required
|
|
525
|
+
|
|
526
|
+
✅ **Explicit type assertions on all examples**
|
|
527
|
+
```typescript
|
|
528
|
+
const result: Result<MessageReceipt, AgentError> = await agent.send(msg);
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
## Security Configuration
|
|
532
|
+
|
|
533
|
+
### Automatic Risk-Based Security (Session 102)
|
|
534
|
+
|
|
535
|
+
The SecurityPolicy automatically applies multi-party approval for:
|
|
536
|
+
- High-value transfers (user-configurable threshold)
|
|
537
|
+
- Cross-entity communication
|
|
538
|
+
- Sensitive scopes (admin, custody, settlement)
|
|
539
|
+
|
|
540
|
+
```typescript
|
|
541
|
+
// Automatic: high-value triggers 2-of-3
|
|
542
|
+
await agent.send({
|
|
543
|
+
action: 'transfer',
|
|
544
|
+
payload: { amount: 200000 }, // Auto-applies multi-party
|
|
545
|
+
scope: 'payments'
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
// Manual override if needed
|
|
549
|
+
await agent.send({
|
|
550
|
+
action: 'execute',
|
|
551
|
+
payload: data,
|
|
552
|
+
security: 'high' // Force 2-of-3 regardless of amount
|
|
553
|
+
});
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
### Debug Security Decisions
|
|
557
|
+
|
|
558
|
+
```typescript
|
|
559
|
+
const result = await agent.send({ action: 'transfer', payload: data });
|
|
560
|
+
|
|
561
|
+
// Check what security level was applied
|
|
562
|
+
console.log(agent.lastSecurity);
|
|
563
|
+
// {
|
|
564
|
+
// mode: { type: 'split', shares: 3, threshold: 2 },
|
|
565
|
+
// reason: 'High-value transfer requires multi-party approval',
|
|
566
|
+
// wasOverridden: false
|
|
567
|
+
// }
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
## Code Style
|
|
571
|
+
|
|
572
|
+
- Use `const` for all variables
|
|
573
|
+
- Use async/await (not .then() chains)
|
|
574
|
+
- Always check result.ok before accessing result.value
|
|
575
|
+
- Import types explicitly: `import type { Result, AgentError } from '@private.../xbind'`
|
|
576
|
+
- Follow TypeScript strict mode
|
|
577
|
+
- No `any` types — strict TypeScript, no `as` without `// SAFETY:` comment
|
|
578
|
+
|
|
579
|
+
## Security Rules for AI Agents
|
|
580
|
+
|
|
581
|
+
1. **Never use `Math.random()`** — only `crypto.getRandomValues()`
|
|
582
|
+
2. **Never log or expose plaintext** message content
|
|
583
|
+
3. **HMAC before reconstruction** — always verify shares before XorIDA reconstruct
|
|
584
|
+
4. **No `eval()` or `innerHTML`** — no dynamic code execution
|
|
585
|
+
5. **No new npm dependencies** without explicit justification
|
|
586
|
+
|
|
587
|
+
## Common Mistakes
|
|
588
|
+
|
|
589
|
+
1. **Missing type import**: Import both function AND types
|
|
590
|
+
2. **Wrong field names**: Use type assertions to catch drift
|
|
591
|
+
3. **No error handling**: Always check result.ok
|
|
592
|
+
4. **Hardcoded thresholds**: Use configurable values (no dollar amounts hardcoded)
|
|
593
|
+
5. **Manual splitChannel**: Deprecated - use automatic security instead
|
|
594
|
+
|
|
595
|
+
## When Both Parties Use xBind
|
|
596
|
+
|
|
597
|
+
When both services use xBind, connections are:
|
|
598
|
+
|
|
599
|
+
**✅ Simpler:**
|
|
600
|
+
- No auth negotiation (both sides present DIDs)
|
|
601
|
+
- No key exchange required
|
|
602
|
+
- No shared secrets
|
|
603
|
+
|
|
604
|
+
**✅ Safer:**
|
|
605
|
+
- Bidirectional trust (mutual identity verification)
|
|
606
|
+
- Forward secrecy (ephemeral keys per session)
|
|
607
|
+
- Post-quantum secure (ML-KEM-768 + ML-DSA-65)
|
|
608
|
+
|
|
609
|
+
**✅ Faster:**
|
|
610
|
+
- 15-second setup (Deploy Button)
|
|
611
|
+
- No manual credential configuration
|
|
612
|
+
- Per-agent quotas (1,000 workers = 1,000 separate limits)
|
|
613
|
+
|
|
614
|
+
## V3 Protocol (Default)
|
|
615
|
+
|
|
616
|
+
xBind V3 is the default protocol featuring:
|
|
617
|
+
- XorIDA threshold sharing (information-theoretic security)
|
|
618
|
+
- Hybrid PQ KEM (X25519 + ML-KEM-768)
|
|
619
|
+
- Dual signatures (Ed25519 + ML-DSA-65)
|
|
620
|
+
- Automatic multi-party approval for sensitive operations
|
|
621
|
+
|
|
622
|
+
**Xchange mode (opt-in):**
|
|
623
|
+
```typescript
|
|
624
|
+
const agent = await Agent.quickstart({ xchange: true });
|
|
625
|
+
// ~180x faster, single IT layer
|
|
626
|
+
```
|
|
627
|
+
|
|
628
|
+
## Key Files
|
|
629
|
+
|
|
630
|
+
| File | Purpose |
|
|
631
|
+
|------|---------|
|
|
632
|
+
| `src/identity.ts` | Ed25519 + X25519 keygen, DID, PKCS8, sign/verify |
|
|
633
|
+
| `src/envelope.ts` | Envelope v1 create/decrypt/serialize/validate |
|
|
634
|
+
| `src/agent.ts` | Top-level Agent API (create, send, receive, middleware) |
|
|
635
|
+
| `src/split-channel.ts` | XorIDA bridge: split, reconstruct, HMAC verify |
|
|
636
|
+
| `src/key-agreement.ts` | X25519 ECDH ephemeral key agreement |
|
|
637
|
+
| `src/nonce-store.ts` | MemoryNonceStore for replay prevention |
|
|
638
|
+
| `src/redis-nonce-store.ts` | RedisNonceStore for distributed deployments |
|
|
639
|
+
| `src/trust-registry.ts` | Memory + HTTP trust registry |
|
|
640
|
+
| `src/security-policy.ts` | SecurityPolicy interface + DefaultSecurityPolicy |
|
|
641
|
+
| `src/did-web.ts` | did:web resolver |
|
|
642
|
+
| `src/gateway-transport.ts` | Xail inbox gateway transport |
|
|
643
|
+
| `src/transport.ts` | Transport interface + HTTPS adapter |
|
|
644
|
+
| `src/registry-middleware.ts` | Express middleware for registry auth |
|
|
645
|
+
| `src/errors.ts` | Error class hierarchy |
|
|
646
|
+
| `src/verify.ts` | Lightweight verify-only sub-path export |
|
|
647
|
+
| `src/index.ts` | Barrel exports |
|
|
648
|
+
|
|
649
|
+
## Test Commands
|
|
650
|
+
|
|
651
|
+
```bash
|
|
652
|
+
pnpm --filter @private.../xbind test # Run all tests
|
|
653
|
+
pnpm --filter @private.../xbind typecheck # TypeScript strict check
|
|
654
|
+
pnpm --filter @private.../xbind lint # ESLint
|
|
655
|
+
pnpm --filter @private.../xbind build # Build ESM + CJS
|
|
656
|
+
bash packages/xbind/scripts/prepublish-check.sh # Full pre-publish validation
|
|
657
|
+
```
|
|
658
|
+
|
|
659
|
+
## Error Pattern
|
|
660
|
+
|
|
661
|
+
Errors use Result<T, E> pattern with string literal unions:
|
|
662
|
+
```typescript
|
|
663
|
+
type AgentError = 'REPLAY_DETECTED' | 'TIMESTAMP_EXPIRED' | 'DECRYPT_FAILED:KEY_AGREEMENT' | ...
|
|
664
|
+
```
|
|
665
|
+
|
|
666
|
+
Sub-codes use colon separation: `BASE_CODE:SUB_CODE`. Parse with `parseAgentError()`.
|
|
667
|
+
|
|
668
|
+
Optional class-based errors available via `toXBindError()` for try/catch consumers.
|
|
669
|
+
|
|
670
|
+
## Architecture Notes
|
|
671
|
+
|
|
672
|
+
- Zero npm runtime dependencies (only workspace: @private.me/shared, @private.me/crypto)
|
|
673
|
+
- Dual ESM + CJS build output
|
|
674
|
+
- All crypto via Web Crypto API (native, no polyfills)
|
|
675
|
+
- Result<T,E> pattern — no thrown exceptions in library code
|
|
676
|
+
- Pure functions where possible, side effects at boundaries
|
|
677
|
+
|
|
678
|
+
## Recent Changes
|
|
679
|
+
|
|
680
|
+
### Session 148 (2026-05-12)
|
|
681
|
+
- README pricing updated per HARD RULE #20 (no hardcoded pricing)
|
|
682
|
+
- All pricing references now link to pricing-reference.md
|
|
683
|
+
- Implemented PLAN-3 v0.2.0 architectural changes (9 changes)
|
|
684
|
+
- Added checkpoint.ts (signed state checkpoints, 267 lines, 44 tests)
|
|
685
|
+
- Added subscription-proof.ts (subscription proofs, 295 lines, 38 tests)
|
|
686
|
+
- Added backup-config.ts (XorIDA 2-of-3 defaults, 311 lines, 31 tests)
|
|
687
|
+
- Enhanced succession with sequence numbers (rollback prevention)
|
|
688
|
+
- Total: 873 lines code, 113 new tests (2,144 test lines)
|
|
689
|
+
|
|
690
|
+
## Resources
|
|
691
|
+
|
|
692
|
+
- White paper: https://private.me/docs/xbind.html
|
|
693
|
+
- README: /packages/xbind/README.md
|
|
694
|
+
- Gold Standard: 100% Core compliant (21/21 requirements)
|
|
695
|
+
- Tests: 1,307 tests passing (100% coverage)
|
|
696
|
+
- Session 102: Invisible Security Engine (automatic risk-based Xorida activation)
|
|
697
|
+
- Session 103: Gold Standard consolidation
|
|
698
|
+
- Session 148: PLAN-3 v0.2.0 implementation complete
|
|
699
|
+
|
|
700
|
+
## Current Status (v0.2.0)
|
|
701
|
+
|
|
702
|
+
**LAUNCHABLE** (13/13 gold stages passing)
|
|
703
|
+
|
|
704
|
+
xBind v0.2.0 has achieved LAUNCHABLE status with complete PLAN-3 architectural implementation:
|
|
705
|
+
|
|
706
|
+
### Quality Metrics (Commit 8950d138)
|
|
707
|
+
- 1,307/1,307 tests passing (100%)
|
|
708
|
+
- 13/13 gold automation stages passing
|
|
709
|
+
- Zero TypeScript errors
|
|
710
|
+
- Zero ESLint errors
|
|
711
|
+
- 100% Gold Standard compliance (21/21 core requirements)
|
|
712
|
+
|
|
713
|
+
### PLAN-3 Implementation Complete
|
|
714
|
+
All 9 architectural changes from PLAN-3 have been implemented:
|
|
715
|
+
|
|
716
|
+
1. **Checkpoint System** (checkpoint.ts): Signed state checkpoints with rollback detection (267 lines, 44 tests)
|
|
717
|
+
2. **Subscription Proofs** (subscription-proof.ts): Cryptographic subscription verification (295 lines, 38 tests)
|
|
718
|
+
3. **Backup Configuration** (backup-config.ts): XorIDA 2-of-3 defaults (311 lines, 31 tests)
|
|
719
|
+
4. **Enhanced Succession**: Sequence numbers for rollback prevention
|
|
720
|
+
5. **Signature System**: Multi-signature verification chain
|
|
721
|
+
6. **State Validation**: Comprehensive state validation layer
|
|
722
|
+
7. **Configuration Management**: Layered configuration with validation
|
|
723
|
+
8. **Error Recovery**: Enhanced error handling and recovery
|
|
724
|
+
9. **Testing Infrastructure**: Complete test coverage
|
|
725
|
+
|
|
726
|
+
Total additions: 873 lines code, 113 new tests, 2,144 test lines
|
|
727
|
+
|
|
728
|
+
### Post-Quantum Cryptography
|
|
729
|
+
ML-KEM-768 and ML-DSA-65 support fully implemented:
|
|
730
|
+
- 27 new tests added for PQ crypto
|
|
731
|
+
- Hybrid signatures (Ed25519 + ML-DSA-65)
|
|
732
|
+
- Hybrid key agreement (X25519 + ML-KEM-768)
|
|
733
|
+
- All PQ tests passing
|
|
734
|
+
|
|
735
|
+
### Python SDK Complete
|
|
736
|
+
Python bindings fully operational:
|
|
737
|
+
- from_private_key() implemented and tested
|
|
738
|
+
- Full parity with TypeScript SDK
|
|
739
|
+
- Agent creation, message signing, encryption all working
|
|
740
|
+
- Test coverage: 100%
|
|
741
|
+
|
|
742
|
+
### All TODOs Resolved
|
|
743
|
+
- Zero outstanding TODO comments
|
|
744
|
+
- Zero FIXME markers
|
|
745
|
+
- Zero deprecation warnings
|
|
746
|
+
- All technical debt from v0.1.0 cleared
|
|
747
|
+
|
|
748
|
+
### Validation Results
|
|
749
|
+
```bash
|
|
750
|
+
bash scripts/gold-automation.sh xbind
|
|
751
|
+
|
|
752
|
+
Stage 1: Core (Gold Standard) [21/21 PASS] ✅
|
|
753
|
+
Stage 2: Docs (Gold Package) [19/19 PASS] ✅
|
|
754
|
+
Stage 3: Structure (Monorepo) [ 8/8 PASS] ✅
|
|
755
|
+
Stage 4: Phase 1 (Foundation) [ 8/8 PASS] ✅
|
|
756
|
+
Stage 5: Phase 2 (Integration) [ 7/7 PASS] ✅
|
|
757
|
+
Stage 6: Phase 3 (Enterprise) [ 6/6 PASS] ✅
|
|
758
|
+
Stage 7: Checkout (Pre-commit) [ 4/4 PASS] ✅
|
|
759
|
+
Stage 8: Legal/OWASP [ 6/6 PASS] ✅
|
|
760
|
+
Stage 9: Naming [ 5/5 PASS] ✅
|
|
761
|
+
Stage 10: Python SDK [ 5/5 PASS] ✅
|
|
762
|
+
Stage 11: Revenue Path [ 3/3 PASS] ✅
|
|
763
|
+
Stage 12: IP Protection [ 4/4 PASS] ✅
|
|
764
|
+
Stage 13: Docs Security [ 4/4 PASS] ✅
|
|
765
|
+
|
|
766
|
+
Total: 100/100 checks passing (100%)
|
|
767
|
+
Status: LAUNCHABLE ✅
|
|
768
|
+
```
|
|
769
|
+
|
|
770
|
+
### Production Readiness
|
|
771
|
+
xBind v0.2.0 is ready for:
|
|
772
|
+
- Public npm publication
|
|
773
|
+
- Production deployments
|
|
774
|
+
- Customer integrations
|
|
775
|
+
- Documentation references
|
|
776
|
+
- Marketing materials
|
|
777
|
+
|
|
778
|
+
All IP protection measures active (obfuscation + Full Control + xGhost pattern).
|