@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
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module http-compat
|
|
3
|
+
* HTTP client compatibility adapters for xBind auto-upgrade
|
|
4
|
+
*
|
|
5
|
+
* Provides drop-in replacements for popular HTTP clients (fetch, axios, got)
|
|
6
|
+
* that transparently upgrade to xBind when both parties support it.
|
|
7
|
+
*/
|
|
8
|
+
import { xfetch } from './xfetch.js';
|
|
9
|
+
/**
|
|
10
|
+
* Create axios-compatible HTTP client with xBind auto-upgrade
|
|
11
|
+
*
|
|
12
|
+
* Drop-in replacement for axios that transparently upgrades to xBind.
|
|
13
|
+
*
|
|
14
|
+
* @returns Axios-compatible client
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { createAxiosCompat } from '@private.me/xbind/http-compat';
|
|
19
|
+
*
|
|
20
|
+
* const axios = createAxiosCompat();
|
|
21
|
+
*
|
|
22
|
+
* // Auto-upgrades to xBind if supported
|
|
23
|
+
* const response = await axios.get('https://api.example.com/data');
|
|
24
|
+
* console.log('Used xBind?', response.xbind?.used);
|
|
25
|
+
* console.log('Data:', response.data);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function createAxiosCompat() {
|
|
29
|
+
async function request(config) {
|
|
30
|
+
// Normalize config
|
|
31
|
+
const cfg = typeof config === 'string' ? { url: config } : config;
|
|
32
|
+
const method = cfg.method?.toUpperCase() ?? 'GET';
|
|
33
|
+
const url = cfg.baseURL
|
|
34
|
+
? new URL(cfg.url ?? '', cfg.baseURL).toString()
|
|
35
|
+
: cfg.url ?? '';
|
|
36
|
+
// Build headers
|
|
37
|
+
const headers = { ...cfg.headers };
|
|
38
|
+
// Build URL with query params
|
|
39
|
+
let finalUrl = url;
|
|
40
|
+
if (cfg.params) {
|
|
41
|
+
const params = new URLSearchParams();
|
|
42
|
+
for (const [key, value] of Object.entries(cfg.params)) {
|
|
43
|
+
params.append(key, String(value));
|
|
44
|
+
}
|
|
45
|
+
finalUrl = `${url}?${params.toString()}`;
|
|
46
|
+
}
|
|
47
|
+
// Build request body
|
|
48
|
+
let body;
|
|
49
|
+
if (cfg.data) {
|
|
50
|
+
if (typeof cfg.data === 'string') {
|
|
51
|
+
body = cfg.data;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
body = JSON.stringify(cfg.data);
|
|
55
|
+
headers['Content-Type'] = 'application/json';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Convert to xfetch options
|
|
59
|
+
const xfetchOpts = {
|
|
60
|
+
method,
|
|
61
|
+
headers,
|
|
62
|
+
body,
|
|
63
|
+
timeout: cfg.timeout,
|
|
64
|
+
forceXBind: cfg.forceXBind,
|
|
65
|
+
disableXBind: cfg.disableXBind,
|
|
66
|
+
};
|
|
67
|
+
// Make request via xfetch
|
|
68
|
+
const response = await xfetch(finalUrl, xfetchOpts);
|
|
69
|
+
// Parse response body based on responseType
|
|
70
|
+
let data;
|
|
71
|
+
const responseType = cfg.responseType ?? 'json';
|
|
72
|
+
switch (responseType) {
|
|
73
|
+
case 'json':
|
|
74
|
+
data = (await response.json());
|
|
75
|
+
break;
|
|
76
|
+
case 'text':
|
|
77
|
+
data = (await response.text());
|
|
78
|
+
break;
|
|
79
|
+
case 'blob':
|
|
80
|
+
data = (await response.blob());
|
|
81
|
+
break;
|
|
82
|
+
case 'arraybuffer':
|
|
83
|
+
data = (await response.arrayBuffer());
|
|
84
|
+
break;
|
|
85
|
+
default:
|
|
86
|
+
data = (await response.json());
|
|
87
|
+
}
|
|
88
|
+
// Validate status if custom validator provided
|
|
89
|
+
if (cfg.validateStatus && !cfg.validateStatus(response.status)) {
|
|
90
|
+
throw new Error(`Request failed with status ${response.status}`);
|
|
91
|
+
}
|
|
92
|
+
// Convert headers to object
|
|
93
|
+
const responseHeaders = {};
|
|
94
|
+
response.headers.forEach((value, key) => {
|
|
95
|
+
responseHeaders[key] = value;
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
data,
|
|
99
|
+
status: response.status,
|
|
100
|
+
statusText: response.statusText,
|
|
101
|
+
headers: responseHeaders,
|
|
102
|
+
config: cfg,
|
|
103
|
+
xbind: {
|
|
104
|
+
used: response.usedXBind,
|
|
105
|
+
protocol: response.transport.protocol,
|
|
106
|
+
latency: response.transport.latency,
|
|
107
|
+
peerDID: response.transport.peerDID,
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
// Convenience methods
|
|
112
|
+
async function get(url, config) {
|
|
113
|
+
return request({ ...config, url, method: 'GET' });
|
|
114
|
+
}
|
|
115
|
+
async function post(url, data, config) {
|
|
116
|
+
return request({ ...config, url, method: 'POST', data });
|
|
117
|
+
}
|
|
118
|
+
async function put(url, data, config) {
|
|
119
|
+
return request({ ...config, url, method: 'PUT', data });
|
|
120
|
+
}
|
|
121
|
+
async function patch(url, data, config) {
|
|
122
|
+
return request({ ...config, url, method: 'PATCH', data });
|
|
123
|
+
}
|
|
124
|
+
async function del(url, config) {
|
|
125
|
+
return request({ ...config, url, method: 'DELETE' });
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
request,
|
|
129
|
+
get,
|
|
130
|
+
post,
|
|
131
|
+
put,
|
|
132
|
+
patch,
|
|
133
|
+
delete: del,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Create got-compatible HTTP client with xBind auto-upgrade
|
|
138
|
+
*
|
|
139
|
+
* Drop-in replacement for got that transparently upgrades to xBind.
|
|
140
|
+
*
|
|
141
|
+
* @returns Got-compatible client
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* import { createGotCompat } from '@private.me/xbind/http-compat';
|
|
146
|
+
*
|
|
147
|
+
* const got = createGotCompat();
|
|
148
|
+
*
|
|
149
|
+
* // Auto-upgrades to xBind if supported
|
|
150
|
+
* const response = await got('https://api.example.com/data', {
|
|
151
|
+
* responseType: 'json',
|
|
152
|
+
* });
|
|
153
|
+
* console.log('Used xBind?', response.xbind?.used);
|
|
154
|
+
* console.log('Body:', response.body);
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export function createGotCompat() {
|
|
158
|
+
async function got(url, options) {
|
|
159
|
+
// Normalize options
|
|
160
|
+
const opts = typeof url === 'string' ? { ...options, url } : url;
|
|
161
|
+
const method = opts.method?.toUpperCase() ?? 'GET';
|
|
162
|
+
const finalUrl = opts.url ?? '';
|
|
163
|
+
// Build headers
|
|
164
|
+
const headers = { ...opts.headers };
|
|
165
|
+
// Build URL with search params
|
|
166
|
+
let urlWithParams = finalUrl;
|
|
167
|
+
if (opts.searchParams) {
|
|
168
|
+
const params = new URLSearchParams();
|
|
169
|
+
for (const [key, value] of Object.entries(opts.searchParams)) {
|
|
170
|
+
params.append(key, String(value));
|
|
171
|
+
}
|
|
172
|
+
urlWithParams = `${finalUrl}?${params.toString()}`;
|
|
173
|
+
}
|
|
174
|
+
// Build request body
|
|
175
|
+
let body;
|
|
176
|
+
if (opts.json) {
|
|
177
|
+
body = JSON.stringify(opts.json);
|
|
178
|
+
headers['Content-Type'] = 'application/json';
|
|
179
|
+
}
|
|
180
|
+
else if (opts.body) {
|
|
181
|
+
// Convert Buffer to string for compatibility with xfetch
|
|
182
|
+
// SAFETY: After instanceof check, both branches produce string type
|
|
183
|
+
body = (opts.body instanceof Buffer ? opts.body.toString() : opts.body);
|
|
184
|
+
}
|
|
185
|
+
// Extract timeout
|
|
186
|
+
const timeout = typeof opts.timeout === 'number'
|
|
187
|
+
? opts.timeout
|
|
188
|
+
: opts.timeout?.request;
|
|
189
|
+
// Convert to xfetch options
|
|
190
|
+
const xfetchOpts = {
|
|
191
|
+
method,
|
|
192
|
+
headers,
|
|
193
|
+
body,
|
|
194
|
+
timeout,
|
|
195
|
+
forceXBind: opts.forceXBind,
|
|
196
|
+
disableXBind: opts.disableXBind,
|
|
197
|
+
};
|
|
198
|
+
// Make request via xfetch
|
|
199
|
+
const response = await xfetch(urlWithParams, xfetchOpts);
|
|
200
|
+
// Parse response body based on responseType
|
|
201
|
+
let responseBody;
|
|
202
|
+
const responseType = opts.responseType ?? 'text';
|
|
203
|
+
switch (responseType) {
|
|
204
|
+
case 'json':
|
|
205
|
+
responseBody = (await response.json());
|
|
206
|
+
break;
|
|
207
|
+
case 'text':
|
|
208
|
+
responseBody = (await response.text());
|
|
209
|
+
break;
|
|
210
|
+
case 'buffer':
|
|
211
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
212
|
+
responseBody = Buffer.from(arrayBuffer);
|
|
213
|
+
break;
|
|
214
|
+
default:
|
|
215
|
+
responseBody = (await response.text());
|
|
216
|
+
}
|
|
217
|
+
// Convert headers to object
|
|
218
|
+
const responseHeaders = {};
|
|
219
|
+
response.headers.forEach((value, key) => {
|
|
220
|
+
responseHeaders[key] = value;
|
|
221
|
+
});
|
|
222
|
+
return {
|
|
223
|
+
body: responseBody,
|
|
224
|
+
statusCode: response.status,
|
|
225
|
+
headers: responseHeaders,
|
|
226
|
+
url: response.url,
|
|
227
|
+
requestUrl: urlWithParams,
|
|
228
|
+
xbind: {
|
|
229
|
+
used: response.usedXBind,
|
|
230
|
+
protocol: response.transport.protocol,
|
|
231
|
+
latency: response.transport.latency,
|
|
232
|
+
peerDID: response.transport.peerDID,
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
// Convenience methods
|
|
237
|
+
got.get = (url, options) => got(url, { ...options, method: 'GET' });
|
|
238
|
+
got.post = (url, options) => got(url, { ...options, method: 'POST' });
|
|
239
|
+
got.put = (url, options) => got(url, { ...options, method: 'PUT' });
|
|
240
|
+
got.patch = (url, options) => got(url, { ...options, method: 'PATCH' });
|
|
241
|
+
got.delete = (url, options) => got(url, { ...options, method: 'DELETE' });
|
|
242
|
+
return got;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Wrap existing fetch implementation with xBind auto-upgrade
|
|
246
|
+
*
|
|
247
|
+
* Use this to upgrade an existing fetch instance (like node-fetch, cross-fetch, etc.)
|
|
248
|
+
*
|
|
249
|
+
* @param fetchImpl - Fetch implementation to wrap
|
|
250
|
+
* @returns Wrapped fetch with xBind support
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```typescript
|
|
254
|
+
* import { wrapFetch } from '@private.me/xbind/http-compat';
|
|
255
|
+
* import nodeFetch from 'node-fetch';
|
|
256
|
+
*
|
|
257
|
+
* const fetch = wrapFetch(nodeFetch);
|
|
258
|
+
*
|
|
259
|
+
* // Uses xBind if supported, falls back to node-fetch
|
|
260
|
+
* const response = await fetch('https://api.example.com/data');
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
export function wrapFetch(fetchImpl) {
|
|
264
|
+
// Return xfetch (which already handles auto-upgrade and fallback)
|
|
265
|
+
// The original fetchImpl is not used because xfetch uses global fetch
|
|
266
|
+
return xfetch;
|
|
267
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import type { Result } from '@private.me/shared';
|
|
2
|
+
/** Agent cryptographic identity backed by Ed25519 keypair. */
|
|
3
|
+
export interface AgentIdentity {
|
|
4
|
+
/** Decentralized identifier: did:key:z6Mk... */
|
|
5
|
+
readonly did: string;
|
|
6
|
+
/** Web Crypto public key handle */
|
|
7
|
+
readonly publicKey: CryptoKey;
|
|
8
|
+
/** Web Crypto private key handle */
|
|
9
|
+
readonly privateKey: CryptoKey;
|
|
10
|
+
/** Raw 32-byte Ed25519 public key */
|
|
11
|
+
readonly rawPublicKey: Uint8Array;
|
|
12
|
+
/** Web Crypto X25519 private key for ECDH forward secrecy. */
|
|
13
|
+
readonly x25519PrivateKey: CryptoKey;
|
|
14
|
+
/** Web Crypto X25519 public key for ECDH forward secrecy. */
|
|
15
|
+
readonly x25519PublicKey: CryptoKey;
|
|
16
|
+
/** Raw 32-byte X25519 public key for wire transport. */
|
|
17
|
+
readonly rawX25519PublicKey: Uint8Array;
|
|
18
|
+
/** ML-KEM-768 public key (1184 bytes) for hybrid post-quantum KEM. */
|
|
19
|
+
readonly mlKemPublicKey?: Uint8Array;
|
|
20
|
+
/** ML-KEM-768 secret key (2400 bytes) for hybrid post-quantum KEM. */
|
|
21
|
+
readonly mlKemSecretKey?: Uint8Array;
|
|
22
|
+
/** ML-DSA-65 public key (1952 bytes) for hybrid post-quantum signatures. */
|
|
23
|
+
readonly mlDsaPublicKey?: Uint8Array;
|
|
24
|
+
/** ML-DSA-65 secret key (4032 bytes) for hybrid post-quantum signatures. */
|
|
25
|
+
readonly mlDsaSecretKey?: Uint8Array;
|
|
26
|
+
}
|
|
27
|
+
/** Error codes for identity operations. */
|
|
28
|
+
export type IdentityError = 'KEYGEN_FAILED' | 'SIGN_FAILED' | 'VERIFY_FAILED' | 'INVALID_DID' | 'INVALID_KEY_LENGTH' | 'EXPORT_FAILED' | 'IMPORT_FAILED';
|
|
29
|
+
/**
|
|
30
|
+
* Generate a new Ed25519 agent identity.
|
|
31
|
+
* Creates keypair via Web Crypto API, derives did:key DID.
|
|
32
|
+
*/
|
|
33
|
+
export declare function generateIdentity(opts?: {
|
|
34
|
+
postQuantumSig?: boolean;
|
|
35
|
+
}): Promise<Result<AgentIdentity, IdentityError>>;
|
|
36
|
+
/**
|
|
37
|
+
* Sign data with an Ed25519 private key.
|
|
38
|
+
* @returns 64-byte Ed25519 signature.
|
|
39
|
+
*/
|
|
40
|
+
export declare function sign(privateKey: CryptoKey, data: Uint8Array): Promise<Result<Uint8Array, IdentityError>>;
|
|
41
|
+
/**
|
|
42
|
+
* Verify an Ed25519 signature.
|
|
43
|
+
* @returns true if valid, false if invalid (not an error).
|
|
44
|
+
*/
|
|
45
|
+
export declare function verify(publicKey: CryptoKey, signature: Uint8Array, data: Uint8Array): Promise<Result<boolean, IdentityError>>;
|
|
46
|
+
/**
|
|
47
|
+
* Import a raw 32-byte Ed25519 public key into a CryptoKey.
|
|
48
|
+
*/
|
|
49
|
+
export declare function importPublicKey(rawPublicKey: Uint8Array): Promise<Result<CryptoKey, IdentityError>>;
|
|
50
|
+
/**
|
|
51
|
+
* Convert 32-byte Ed25519 public key to did:key DID.
|
|
52
|
+
* Format: did:key:z + base58btc(0xed01 || publicKey).
|
|
53
|
+
*/
|
|
54
|
+
export declare function publicKeyToDid(rawPublicKey: Uint8Array): string;
|
|
55
|
+
/**
|
|
56
|
+
* Extract raw 32-byte public key bytes from a did:key DID.
|
|
57
|
+
*/
|
|
58
|
+
export declare function didToPublicKeyBytes(did: string): Result<Uint8Array, IdentityError>;
|
|
59
|
+
/**
|
|
60
|
+
* Export an Ed25519 private key as PKCS8 DER bytes.
|
|
61
|
+
*
|
|
62
|
+
* Use this to persist an agent identity across restarts.
|
|
63
|
+
* Node 20 does not support raw export for Ed25519 private keys —
|
|
64
|
+
* PKCS8 is the portable format.
|
|
65
|
+
*
|
|
66
|
+
* @param privateKey - Ed25519 CryptoKey (must be extractable).
|
|
67
|
+
* @returns PKCS8 DER bytes or error.
|
|
68
|
+
*/
|
|
69
|
+
export declare function exportPKCS8(privateKey: CryptoKey): Promise<Result<Uint8Array, IdentityError>>;
|
|
70
|
+
/**
|
|
71
|
+
* Export an X25519 private key as PKCS8 DER bytes.
|
|
72
|
+
*
|
|
73
|
+
* @param privateKey - X25519 CryptoKey (must be extractable).
|
|
74
|
+
* @returns PKCS8 DER bytes or error.
|
|
75
|
+
*/
|
|
76
|
+
export declare function exportX25519PKCS8(privateKey: CryptoKey): Promise<Result<Uint8Array, IdentityError>>;
|
|
77
|
+
/**
|
|
78
|
+
* Import an Ed25519 identity from PKCS8 DER bytes.
|
|
79
|
+
*
|
|
80
|
+
* Generates a new X25519 keypair for forward secrecy.
|
|
81
|
+
* Use this when you only persisted the Ed25519 key.
|
|
82
|
+
*
|
|
83
|
+
* @param pkcs8 - PKCS8-encoded Ed25519 private key bytes.
|
|
84
|
+
* @returns Full AgentIdentity or error.
|
|
85
|
+
*/
|
|
86
|
+
export declare function importFromPKCS8(pkcs8: Uint8Array): Promise<Result<AgentIdentity, IdentityError>>;
|
|
87
|
+
/**
|
|
88
|
+
* Import a full identity from both PKCS8 blobs (Ed25519 + X25519).
|
|
89
|
+
*
|
|
90
|
+
* Use this when you persisted both keys for full identity restoration
|
|
91
|
+
* including the original X25519 key (preserves registered key agreement).
|
|
92
|
+
*
|
|
93
|
+
* @param ed25519Pkcs8 - PKCS8-encoded Ed25519 private key bytes.
|
|
94
|
+
* @param x25519Pkcs8 - PKCS8-encoded X25519 private key bytes.
|
|
95
|
+
* @returns Full AgentIdentity or error.
|
|
96
|
+
*/
|
|
97
|
+
export declare function importIdentity(ed25519Pkcs8: Uint8Array, x25519Pkcs8: Uint8Array, mlKemSecretKey?: Uint8Array, mlKemPublicKey?: Uint8Array, mlDsaSecretKey?: Uint8Array, mlDsaPublicKey?: Uint8Array): Promise<Result<AgentIdentity, IdentityError>>;
|
|
98
|
+
/**
|
|
99
|
+
* Export ML-KEM-768 secret key bytes from an identity.
|
|
100
|
+
*
|
|
101
|
+
* @param identity - Agent identity with ML-KEM keys.
|
|
102
|
+
* @returns Raw 2400-byte ML-KEM secret key or undefined if not available.
|
|
103
|
+
*/
|
|
104
|
+
export declare function exportMlKemSecretKey(identity: AgentIdentity): Uint8Array | undefined;
|
|
105
|
+
/**
|
|
106
|
+
* Export ML-KEM-768 public key bytes from an identity.
|
|
107
|
+
*
|
|
108
|
+
* @param identity - Agent identity with ML-KEM keys.
|
|
109
|
+
* @returns Raw 1184-byte ML-KEM public key or undefined if not available.
|
|
110
|
+
*/
|
|
111
|
+
export declare function exportMlKemPublicKey(identity: AgentIdentity): Uint8Array | undefined;
|
|
112
|
+
/** ML-DSA-65 signature length in bytes. */
|
|
113
|
+
export declare const ML_DSA65_SIG_BYTES = 3309;
|
|
114
|
+
/** ML-DSA-65 public key length in bytes. */
|
|
115
|
+
export declare const ML_DSA65_PK_BYTES = 1952;
|
|
116
|
+
/** ML-DSA-65 secret key seed length in bytes (using seed format for storage). */
|
|
117
|
+
export declare const ML_DSA65_SK_BYTES = 32;
|
|
118
|
+
/**
|
|
119
|
+
* Sign data with an ML-DSA-65 secret key (FIPS 204).
|
|
120
|
+
* @param secretKey - 32-byte ML-DSA-65 secret key seed.
|
|
121
|
+
* @param data - Data to sign.
|
|
122
|
+
* @returns 3309-byte ML-DSA-65 signature.
|
|
123
|
+
*/
|
|
124
|
+
export declare function signMlDsa65(secretKey: Uint8Array, data: Uint8Array): Promise<Result<Uint8Array, IdentityError>>;
|
|
125
|
+
/**
|
|
126
|
+
* Verify an ML-DSA-65 signature (FIPS 204).
|
|
127
|
+
* @param publicKey - 1952-byte ML-DSA-65 public key.
|
|
128
|
+
* @param signature - 3309-byte ML-DSA-65 signature.
|
|
129
|
+
* @param data - Data that was signed.
|
|
130
|
+
* @returns true if valid, false if invalid (not an error).
|
|
131
|
+
*/
|
|
132
|
+
export declare function verifyMlDsa65(publicKey: Uint8Array, signature: Uint8Array, data: Uint8Array): Promise<Result<boolean, IdentityError>>;
|
|
133
|
+
/**
|
|
134
|
+
* Export ML-DSA-65 secret key bytes from an identity.
|
|
135
|
+
*
|
|
136
|
+
* @param identity - Agent identity with ML-DSA keys.
|
|
137
|
+
* @returns Raw 4032-byte ML-DSA-65 secret key or undefined if not available.
|
|
138
|
+
*/
|
|
139
|
+
export declare function exportMlDsaSecretKey(identity: AgentIdentity): Uint8Array | undefined;
|
|
140
|
+
/**
|
|
141
|
+
* Export ML-DSA-65 public key bytes from an identity.
|
|
142
|
+
*
|
|
143
|
+
* @param identity - Agent identity with ML-DSA keys.
|
|
144
|
+
* @returns Raw 1952-byte ML-DSA-65 public key or undefined if not available.
|
|
145
|
+
*/
|
|
146
|
+
export declare function exportMlDsaPublicKey(identity: AgentIdentity): Uint8Array | undefined;
|
|
147
|
+
/**
|
|
148
|
+
* Derive a deterministic AgentIdentity from a 32-byte seed.
|
|
149
|
+
*
|
|
150
|
+
* Uses HKDF-SHA256 to derive separate Ed25519 and X25519 private keys
|
|
151
|
+
* from the seed. The same seed always produces the same identity (same DID).
|
|
152
|
+
*
|
|
153
|
+
* @param seed - Exactly 32 bytes of high-entropy key material.
|
|
154
|
+
* @returns Full AgentIdentity or error.
|
|
155
|
+
*/
|
|
156
|
+
export declare function identityFromSeed(seed: Uint8Array, opts?: {
|
|
157
|
+
postQuantumSig?: boolean;
|
|
158
|
+
}): Promise<Result<AgentIdentity, IdentityError>>;
|
|
159
|
+
/**
|
|
160
|
+
* Extract the raw 32-byte Ed25519 private key from a PKCS8 DER blob.
|
|
161
|
+
*
|
|
162
|
+
* Strips the 16-byte ASN.1 header. Validates prefix matches Ed25519 OID.
|
|
163
|
+
*
|
|
164
|
+
* @param pkcs8 - 48-byte PKCS8 DER for Ed25519.
|
|
165
|
+
* @returns 32-byte raw private key or error.
|
|
166
|
+
*/
|
|
167
|
+
export declare function extractRawEd25519(pkcs8: Uint8Array): Result<Uint8Array, IdentityError>;
|
|
168
|
+
/**
|
|
169
|
+
* Extract the raw 32-byte X25519 private key from a PKCS8 DER blob.
|
|
170
|
+
*
|
|
171
|
+
* Strips the 16-byte ASN.1 header. Validates prefix matches X25519 OID.
|
|
172
|
+
*
|
|
173
|
+
* @param pkcs8 - 48-byte PKCS8 DER for X25519.
|
|
174
|
+
* @returns 32-byte raw private key or error.
|
|
175
|
+
*/
|
|
176
|
+
export declare function extractRawX25519(pkcs8: Uint8Array): Result<Uint8Array, IdentityError>;
|