@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.
Files changed (295) hide show
  1. package/AGENTS.md +778 -0
  2. package/LICENSE.md +27 -0
  3. package/README.md +400 -0
  4. package/dist-standalone/_deps/crypto/base64.d.ts +29 -0
  5. package/dist-standalone/_deps/crypto/base64.js +97 -0
  6. package/dist-standalone/_deps/crypto/cjs/base64.js +103 -0
  7. package/dist-standalone/_deps/crypto/cjs/errors.js +119 -0
  8. package/dist-standalone/_deps/crypto/cjs/hmac.js +71 -0
  9. package/dist-standalone/_deps/crypto/cjs/index.js +86 -0
  10. package/dist-standalone/_deps/crypto/cjs/padding.js +57 -0
  11. package/dist-standalone/_deps/crypto/cjs/share-header.js +68 -0
  12. package/dist-standalone/_deps/crypto/cjs/shares.js +152 -0
  13. package/dist-standalone/_deps/crypto/cjs/tlv.js +199 -0
  14. package/dist-standalone/_deps/crypto/cjs/uuid.js +61 -0
  15. package/dist-standalone/_deps/crypto/cjs/verify.js +24 -0
  16. package/dist-standalone/_deps/crypto/cjs/xorida.js +221 -0
  17. package/dist-standalone/_deps/crypto/errors.d.ts +51 -0
  18. package/dist-standalone/_deps/crypto/errors.js +109 -0
  19. package/dist-standalone/_deps/crypto/hmac.d.ts +39 -0
  20. package/dist-standalone/_deps/crypto/hmac.js +66 -0
  21. package/dist-standalone/_deps/crypto/index.d.ts +20 -0
  22. package/dist-standalone/_deps/crypto/index.js +45 -0
  23. package/dist-standalone/_deps/crypto/padding.d.ts +19 -0
  24. package/dist-standalone/_deps/crypto/padding.js +53 -0
  25. package/dist-standalone/_deps/crypto/share-header.d.ts +44 -0
  26. package/dist-standalone/_deps/crypto/share-header.js +63 -0
  27. package/dist-standalone/_deps/crypto/shares.d.ts +27 -0
  28. package/dist-standalone/_deps/crypto/shares.js +148 -0
  29. package/dist-standalone/_deps/crypto/tlv.d.ts +26 -0
  30. package/dist-standalone/_deps/crypto/tlv.js +195 -0
  31. package/dist-standalone/_deps/crypto/uuid.d.ts +22 -0
  32. package/dist-standalone/_deps/crypto/uuid.js +56 -0
  33. package/dist-standalone/_deps/crypto/verify.d.ts +15 -0
  34. package/dist-standalone/_deps/crypto/verify.js +15 -0
  35. package/dist-standalone/_deps/crypto/xorida.d.ts +44 -0
  36. package/dist-standalone/_deps/crypto/xorida.js +215 -0
  37. package/dist-standalone/_deps/mldsa-wasm/LICENSE +24 -0
  38. package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1920 -0
  39. package/dist-standalone/_deps/mldsa-wasm/package.json +46 -0
  40. package/dist-standalone/_deps/mldsa-wasm/types/mldsa.d.ts +30 -0
  41. package/dist-standalone/_deps/shared/cjs/errors.js +582 -0
  42. package/dist-standalone/_deps/shared/cjs/index.js +492 -0
  43. package/dist-standalone/_deps/shared/cjs/package.json +1 -0
  44. package/dist-standalone/_deps/shared/cjs/types.js +403 -0
  45. package/dist-standalone/_deps/shared/errors.d.ts +48 -0
  46. package/dist-standalone/_deps/shared/errors.d.ts.map +1 -0
  47. package/dist-standalone/_deps/shared/errors.js +192 -0
  48. package/dist-standalone/_deps/shared/errors.js.map +1 -0
  49. package/dist-standalone/_deps/shared/index.d.ts +4 -0
  50. package/dist-standalone/_deps/shared/index.d.ts.map +1 -0
  51. package/dist-standalone/_deps/shared/index.js +78 -0
  52. package/dist-standalone/_deps/shared/index.js.map +1 -0
  53. package/dist-standalone/_deps/shared/types.d.ts +1097 -0
  54. package/dist-standalone/_deps/shared/types.d.ts.map +1 -0
  55. package/dist-standalone/_deps/shared/types.js +89 -0
  56. package/dist-standalone/_deps/shared/types.js.map +1 -0
  57. package/dist-standalone/_deps/ux-helpers/cjs/errors.d.ts +115 -0
  58. package/dist-standalone/_deps/ux-helpers/cjs/errors.d.ts.map +1 -0
  59. package/dist-standalone/_deps/ux-helpers/cjs/errors.js +1 -0
  60. package/dist-standalone/_deps/ux-helpers/cjs/errors.js.map +1 -0
  61. package/dist-standalone/_deps/ux-helpers/cjs/index.d.ts +13 -0
  62. package/dist-standalone/_deps/ux-helpers/cjs/index.d.ts.map +1 -0
  63. package/dist-standalone/_deps/ux-helpers/cjs/index.js +1 -0
  64. package/dist-standalone/_deps/ux-helpers/cjs/index.js.map +1 -0
  65. package/dist-standalone/_deps/ux-helpers/cjs/package.json +1 -0
  66. package/dist-standalone/_deps/ux-helpers/cjs/pagination.d.ts +39 -0
  67. package/dist-standalone/_deps/ux-helpers/cjs/pagination.d.ts.map +1 -0
  68. package/dist-standalone/_deps/ux-helpers/cjs/pagination.js +83 -0
  69. package/dist-standalone/_deps/ux-helpers/cjs/pagination.js.map +1 -0
  70. package/dist-standalone/_deps/ux-helpers/cjs/progress.d.ts +99 -0
  71. package/dist-standalone/_deps/ux-helpers/cjs/progress.d.ts.map +1 -0
  72. package/dist-standalone/_deps/ux-helpers/cjs/progress.js +143 -0
  73. package/dist-standalone/_deps/ux-helpers/cjs/progress.js.map +1 -0
  74. package/dist-standalone/_deps/ux-helpers/cjs/search.d.ts +32 -0
  75. package/dist-standalone/_deps/ux-helpers/cjs/search.d.ts.map +1 -0
  76. package/dist-standalone/_deps/ux-helpers/cjs/search.js +119 -0
  77. package/dist-standalone/_deps/ux-helpers/cjs/search.js.map +1 -0
  78. package/dist-standalone/_deps/ux-helpers/cjs/types.d.ts +109 -0
  79. package/dist-standalone/_deps/ux-helpers/cjs/types.d.ts.map +1 -0
  80. package/dist-standalone/_deps/ux-helpers/cjs/types.js +8 -0
  81. package/dist-standalone/_deps/ux-helpers/cjs/types.js.map +1 -0
  82. package/dist-standalone/_deps/ux-helpers/errors.d.ts +115 -0
  83. package/dist-standalone/_deps/ux-helpers/errors.d.ts.map +1 -0
  84. package/dist-standalone/_deps/ux-helpers/errors.js +253 -0
  85. package/dist-standalone/_deps/ux-helpers/errors.js.map +1 -0
  86. package/dist-standalone/_deps/ux-helpers/index.d.ts +13 -0
  87. package/dist-standalone/_deps/ux-helpers/index.d.ts.map +1 -0
  88. package/dist-standalone/_deps/ux-helpers/index.js +16 -0
  89. package/dist-standalone/_deps/ux-helpers/index.js.map +1 -0
  90. package/dist-standalone/_deps/ux-helpers/pagination.d.ts +39 -0
  91. package/dist-standalone/_deps/ux-helpers/pagination.d.ts.map +1 -0
  92. package/dist-standalone/_deps/ux-helpers/pagination.js +79 -0
  93. package/dist-standalone/_deps/ux-helpers/pagination.js.map +1 -0
  94. package/dist-standalone/_deps/ux-helpers/progress.d.ts +99 -0
  95. package/dist-standalone/_deps/ux-helpers/progress.d.ts.map +1 -0
  96. package/dist-standalone/_deps/ux-helpers/progress.js +138 -0
  97. package/dist-standalone/_deps/ux-helpers/progress.js.map +1 -0
  98. package/dist-standalone/_deps/ux-helpers/search.d.ts +32 -0
  99. package/dist-standalone/_deps/ux-helpers/search.d.ts.map +1 -0
  100. package/dist-standalone/_deps/ux-helpers/search.js +116 -0
  101. package/dist-standalone/_deps/ux-helpers/search.js.map +1 -0
  102. package/dist-standalone/_deps/ux-helpers/types.d.ts +109 -0
  103. package/dist-standalone/_deps/ux-helpers/types.d.ts.map +1 -0
  104. package/dist-standalone/_deps/ux-helpers/types.js +7 -0
  105. package/dist-standalone/_deps/ux-helpers/types.js.map +1 -0
  106. package/dist-standalone/_deps/xchange/auto-accept.d.ts +127 -0
  107. package/dist-standalone/_deps/xchange/auto-accept.js +1 -0
  108. package/dist-standalone/_deps/xchange/cjs/auto-accept.js +1 -0
  109. package/dist-standalone/_deps/xchange/cjs/errors.js +1 -0
  110. package/dist-standalone/_deps/xchange/cjs/index.js +1 -0
  111. package/dist-standalone/_deps/xchange/cjs/invite-client.js +1 -0
  112. package/dist-standalone/_deps/xchange/cjs/lazy-init.js +1 -0
  113. package/dist-standalone/_deps/xchange/cjs/package.json +1 -0
  114. package/dist-standalone/_deps/xchange/cjs/trust-integration.js +1 -0
  115. package/dist-standalone/_deps/xchange/cjs/xchange.js +1 -0
  116. package/dist-standalone/_deps/xchange/errors.d.ts +69 -0
  117. package/dist-standalone/_deps/xchange/errors.js +1 -0
  118. package/dist-standalone/_deps/xchange/index.d.ts +15 -0
  119. package/dist-standalone/_deps/xchange/index.js +1 -0
  120. package/dist-standalone/_deps/xchange/invite-client.d.ts +178 -0
  121. package/dist-standalone/_deps/xchange/invite-client.js +1 -0
  122. package/dist-standalone/_deps/xchange/lazy-init.d.ts +176 -0
  123. package/dist-standalone/_deps/xchange/lazy-init.js +1 -0
  124. package/dist-standalone/_deps/xchange/trust-integration.d.ts +102 -0
  125. package/dist-standalone/_deps/xchange/trust-integration.js +1 -0
  126. package/dist-standalone/_deps/xchange/xchange.d.ts +60 -0
  127. package/dist-standalone/_deps/xchange/xchange.js +1 -0
  128. package/dist-standalone/_deps/xregistry/cjs/discovery.js +1 -0
  129. package/dist-standalone/_deps/xregistry/cjs/errors.js +1 -0
  130. package/dist-standalone/_deps/xregistry/cjs/index.js +1 -0
  131. package/dist-standalone/_deps/xregistry/cjs/package.json +1 -0
  132. package/dist-standalone/_deps/xregistry/cjs/registry.js +1 -0
  133. package/dist-standalone/_deps/xregistry/cjs/schema.js +1 -0
  134. package/dist-standalone/_deps/xregistry/cjs/types.js +1 -0
  135. package/dist-standalone/_deps/xregistry/discovery.d.ts +126 -0
  136. package/dist-standalone/_deps/xregistry/discovery.d.ts.map +1 -0
  137. package/dist-standalone/_deps/xregistry/discovery.js +1 -0
  138. package/dist-standalone/_deps/xregistry/discovery.js.map +1 -0
  139. package/dist-standalone/_deps/xregistry/errors.d.ts +41 -0
  140. package/dist-standalone/_deps/xregistry/errors.d.ts.map +1 -0
  141. package/dist-standalone/_deps/xregistry/errors.js +1 -0
  142. package/dist-standalone/_deps/xregistry/errors.js.map +1 -0
  143. package/dist-standalone/_deps/xregistry/index.d.ts +8 -0
  144. package/dist-standalone/_deps/xregistry/index.d.ts.map +1 -0
  145. package/dist-standalone/_deps/xregistry/index.js +1 -0
  146. package/dist-standalone/_deps/xregistry/index.js.map +1 -0
  147. package/dist-standalone/_deps/xregistry/registry.d.ts +85 -0
  148. package/dist-standalone/_deps/xregistry/registry.d.ts.map +1 -0
  149. package/dist-standalone/_deps/xregistry/registry.js +1 -0
  150. package/dist-standalone/_deps/xregistry/registry.js.map +1 -0
  151. package/dist-standalone/_deps/xregistry/schema.d.ts +81 -0
  152. package/dist-standalone/_deps/xregistry/schema.d.ts.map +1 -0
  153. package/dist-standalone/_deps/xregistry/schema.js +1 -0
  154. package/dist-standalone/_deps/xregistry/schema.js.map +1 -0
  155. package/dist-standalone/_deps/xregistry/types.d.ts +95 -0
  156. package/dist-standalone/_deps/xregistry/types.d.ts.map +1 -0
  157. package/dist-standalone/_deps/xregistry/types.js +1 -0
  158. package/dist-standalone/_deps/xregistry/types.js.map +1 -0
  159. package/dist-standalone/agent-call.d.ts +286 -0
  160. package/dist-standalone/agent-call.js +642 -0
  161. package/dist-standalone/agent-sdk.d.ts +207 -0
  162. package/dist-standalone/agent-sdk.js +328 -0
  163. package/dist-standalone/agent.d.ts +670 -0
  164. package/dist-standalone/agent.js +1529 -0
  165. package/dist-standalone/approval.d.ts +145 -0
  166. package/dist-standalone/approval.js +193 -0
  167. package/dist-standalone/auth.d.ts +75 -0
  168. package/dist-standalone/auth.js +219 -0
  169. package/dist-standalone/auto-accept.d.ts +102 -0
  170. package/dist-standalone/auto-accept.js +229 -0
  171. package/dist-standalone/backup-config.d.ts +150 -0
  172. package/dist-standalone/backup-config.js +201 -0
  173. package/dist-standalone/checkpoint.d.ts +125 -0
  174. package/dist-standalone/checkpoint.js +186 -0
  175. package/dist-standalone/cjs/agent-call.js +651 -0
  176. package/dist-standalone/cjs/agent-sdk.js +332 -0
  177. package/dist-standalone/cjs/agent.js +1566 -0
  178. package/dist-standalone/cjs/approval.js +199 -0
  179. package/dist-standalone/cjs/auth.js +225 -0
  180. package/dist-standalone/cjs/auto-accept.js +233 -0
  181. package/dist-standalone/cjs/backup-config.js +207 -0
  182. package/dist-standalone/cjs/checkpoint.js +193 -0
  183. package/dist-standalone/cjs/cli/init.js +487 -0
  184. package/dist-standalone/cjs/connect.js +312 -0
  185. package/dist-standalone/cjs/did-document.js +101 -0
  186. package/dist-standalone/cjs/did-privateme.js +130 -0
  187. package/dist-standalone/cjs/did-web.js +201 -0
  188. package/dist-standalone/cjs/discovery.js +462 -0
  189. package/dist-standalone/cjs/dual-mode.js +251 -0
  190. package/dist-standalone/cjs/email-templates.js +313 -0
  191. package/dist-standalone/cjs/email-transport.js +239 -0
  192. package/dist-standalone/cjs/envelope.js +510 -0
  193. package/dist-standalone/cjs/errors.js +562 -0
  194. package/dist-standalone/cjs/gateway-state.js +55 -0
  195. package/dist-standalone/cjs/gateway-transport.js +120 -0
  196. package/dist-standalone/cjs/guardrails.js +223 -0
  197. package/dist-standalone/cjs/http-compat.js +272 -0
  198. package/dist-standalone/cjs/identity.js +541 -0
  199. package/dist-standalone/cjs/index.js +224 -0
  200. package/dist-standalone/cjs/invitation.js +421 -0
  201. package/dist-standalone/cjs/invite.js +328 -0
  202. package/dist-standalone/cjs/key-agreement.js +246 -0
  203. package/dist-standalone/cjs/lazy-init.js +300 -0
  204. package/dist-standalone/cjs/mdns-discovery.js +202 -0
  205. package/dist-standalone/cjs/nonce-store.js +66 -0
  206. package/dist-standalone/cjs/package.json +3 -0
  207. package/dist-standalone/cjs/pairing-manager.js +223 -0
  208. package/dist-standalone/cjs/policy.js +320 -0
  209. package/dist-standalone/cjs/redis-nonce-store.js +76 -0
  210. package/dist-standalone/cjs/registry-middleware.js +50 -0
  211. package/dist-standalone/cjs/retry-transport.js +102 -0
  212. package/dist-standalone/cjs/security-policy.js +204 -0
  213. package/dist-standalone/cjs/split-channel.js +177 -0
  214. package/dist-standalone/cjs/subscription-proof.js +230 -0
  215. package/dist-standalone/cjs/succession.js +148 -0
  216. package/dist-standalone/cjs/transport.js +63 -0
  217. package/dist-standalone/cjs/trust-registry.js +742 -0
  218. package/dist-standalone/cjs/verify.js +25 -0
  219. package/dist-standalone/cjs/xfetch.js +252 -0
  220. package/dist-standalone/cli/init.d.ts +63 -0
  221. package/dist-standalone/cli/init.js +450 -0
  222. package/dist-standalone/connect.d.ts +143 -0
  223. package/dist-standalone/connect.js +274 -0
  224. package/dist-standalone/did-document.d.ts +65 -0
  225. package/dist-standalone/did-document.js +96 -0
  226. package/dist-standalone/did-privateme.d.ts +70 -0
  227. package/dist-standalone/did-privateme.js +121 -0
  228. package/dist-standalone/did-web.d.ts +73 -0
  229. package/dist-standalone/did-web.js +196 -0
  230. package/dist-standalone/discovery.d.ts +176 -0
  231. package/dist-standalone/discovery.js +458 -0
  232. package/dist-standalone/dual-mode.d.ts +145 -0
  233. package/dist-standalone/dual-mode.js +247 -0
  234. package/dist-standalone/email-templates.d.ts +41 -0
  235. package/dist-standalone/email-templates.js +309 -0
  236. package/dist-standalone/email-transport.d.ts +139 -0
  237. package/dist-standalone/email-transport.js +232 -0
  238. package/dist-standalone/envelope.d.ts +288 -0
  239. package/dist-standalone/envelope.js +497 -0
  240. package/dist-standalone/errors.d.ts +74 -0
  241. package/dist-standalone/errors.js +548 -0
  242. package/dist-standalone/gateway-state.d.ts +32 -0
  243. package/dist-standalone/gateway-state.js +51 -0
  244. package/dist-standalone/gateway-transport.d.ts +59 -0
  245. package/dist-standalone/gateway-transport.js +116 -0
  246. package/dist-standalone/guardrails.d.ts +136 -0
  247. package/dist-standalone/guardrails.js +216 -0
  248. package/dist-standalone/http-compat.d.ts +150 -0
  249. package/dist-standalone/http-compat.js +267 -0
  250. package/dist-standalone/identity.d.ts +176 -0
  251. package/dist-standalone/identity.js +516 -0
  252. package/dist-standalone/index.d.ts +83 -0
  253. package/dist-standalone/index.js +51 -0
  254. package/dist-standalone/invitation.d.ts +211 -0
  255. package/dist-standalone/invitation.js +415 -0
  256. package/dist-standalone/invite.d.ts +192 -0
  257. package/dist-standalone/invite.js +324 -0
  258. package/dist-standalone/key-agreement.d.ts +122 -0
  259. package/dist-standalone/key-agreement.js +236 -0
  260. package/dist-standalone/lazy-init.d.ts +167 -0
  261. package/dist-standalone/lazy-init.js +295 -0
  262. package/dist-standalone/mdns-discovery.d.ts +117 -0
  263. package/dist-standalone/mdns-discovery.js +195 -0
  264. package/dist-standalone/nonce-store.d.ts +39 -0
  265. package/dist-standalone/nonce-store.js +62 -0
  266. package/dist-standalone/package.json +11 -0
  267. package/dist-standalone/pairing-manager.d.ts +147 -0
  268. package/dist-standalone/pairing-manager.js +219 -0
  269. package/dist-standalone/policy.d.ts +150 -0
  270. package/dist-standalone/policy.js +315 -0
  271. package/dist-standalone/redis-nonce-store.d.ts +93 -0
  272. package/dist-standalone/redis-nonce-store.js +72 -0
  273. package/dist-standalone/registry-middleware.d.ts +38 -0
  274. package/dist-standalone/registry-middleware.js +47 -0
  275. package/dist-standalone/retry-transport.d.ts +76 -0
  276. package/dist-standalone/retry-transport.js +98 -0
  277. package/dist-standalone/security-policy.d.ts +146 -0
  278. package/dist-standalone/security-policy.js +198 -0
  279. package/dist-standalone/split-channel.d.ts +69 -0
  280. package/dist-standalone/split-channel.js +171 -0
  281. package/dist-standalone/subscription-proof.d.ts +103 -0
  282. package/dist-standalone/subscription-proof.js +224 -0
  283. package/dist-standalone/succession.d.ts +57 -0
  284. package/dist-standalone/succession.js +142 -0
  285. package/dist-standalone/transport.d.ts +50 -0
  286. package/dist-standalone/transport.js +59 -0
  287. package/dist-standalone/trust-registry.d.ts +286 -0
  288. package/dist-standalone/trust-registry.js +702 -0
  289. package/dist-standalone/verify.d.ts +16 -0
  290. package/dist-standalone/verify.js +16 -0
  291. package/dist-standalone/xfetch.d.ts +129 -0
  292. package/dist-standalone/xfetch.js +247 -0
  293. package/llms.txt +800 -0
  294. package/package.json +79 -0
  295. package/share1.dat +0 -0
package/LICENSE.md ADDED
@@ -0,0 +1,27 @@
1
+ # License
2
+
3
+ **Copyright © 2024-2026 Standard Clouds, Inc. All rights reserved.**
4
+
5
+ This software is proprietary and confidential. Unauthorized copying, distribution, or use of this software, via any medium, is strictly prohibited.
6
+
7
+ **Licensed under:** Proprietary
8
+ **Company:** Standard Clouds, Inc. dba PRIVATE.ME
9
+ **Registry:** Private npm registry
10
+
11
+ For licensing inquiries: contact@private.me
12
+
13
+ ## Export Control Notice
14
+
15
+ This software contains encryption technology (Ed25519, X25519, AES-256-GCM, XorIDA threshold sharing) that may be subject to U.S. export control laws (EAR 15 CFR 730-774). By downloading or using this software, you agree to comply with all applicable export laws and regulations. Export or re-export to embargoed countries or sanctioned entities is prohibited.
16
+
17
+ ## Additional Terms
18
+
19
+ By using this software, you also agree to:
20
+
21
+ - **Terms of Service**: https://private.me/terms
22
+ - **End User License Agreement**: https://private.me/legal/eula
23
+ - **Privacy Policy**: https://private.me/privacy
24
+
25
+ ## Third-Party Dependencies
26
+
27
+ This package includes or depends upon open-source software that is subject to separate license terms. See the package.json file for a list of dependencies and their respective licenses.
package/README.md ADDED
@@ -0,0 +1,400 @@
1
+ # @private.me/xbind
2
+
3
+ ![npm version](https://img.shields.io/npm/v/@private.me/xbind)
4
+ ![version](https://img.shields.io/badge/version-1.2.0-blue)
5
+ ![tests](https://img.shields.io/badge/tests-1245%20passing-brightgreen)
6
+ ![TypeScript](https://img.shields.io/badge/TypeScript-strict-blue)
7
+ ![license](https://img.shields.io/badge/license-Proprietary-blue)
8
+
9
+ **Authenticated agent-to-agent messaging with post-quantum cryptographic identity.**
10
+
11
+ Build AI agents that communicate securely using ML-DSA-65 DID identity, ML-KEM-768 + AES-256-GCM encryption, and information-theoretic split-channel delivery (XorIDA). Every message is signed and encrypted. No API keys, no rotation, no sprawl.
12
+
13
+ Part of the **Private.Me** platform—where APIs have keys, but ACIs have identity.
14
+
15
+ **Version 1.1.7** — **Dependency hardening:** Vendored mldsa-wasm@0.0.4 (eliminates external dependency risk). Previous v1.1.6: CRITICAL SECURITY FIX removed deriveSharedKey() vulnerability. PLAN-3 architecture with post-quantum cryptography (ML-KEM-768, ML-DSA-65), Python SDK, and Full Control protection.
16
+
17
+ ## Install
18
+
19
+ ```bash
20
+ # Node.js / TypeScript
21
+ npm install https://private.me/downloads/private.me-xbind-1.1.7.tgz
22
+
23
+ # Python
24
+ pip install private-me-xbind
25
+ ```
26
+
27
+ **Distribution Model:** xBind uses Full Control IP protection (2-share XorIDA). Share 1 (Store Front) is hosted on private.me and publicly accessible. Share 2 (Vault Store) is payment-gated and requires xBind authentication.
28
+
29
+ [Python SDK documentation](./python/README.md) • [Complete docs](./docs/README.md) • [White paper](https://private.me/docs/xbind.html)
30
+
31
+ ## Security Notice
32
+
33
+ **Post-Quantum Cryptography:** xBind uses `mldsa-wasm@0.0.4` for post-quantum digital signatures (ML-DSA-65/FIPS 204). This package is pre-1.0 beta software. While based on audited upstream cryptography ([PQCA mldsa](https://github.com/dajiaji/mldsa)), it has not been independently audited.
34
+
35
+ **Risk Acceptance:** We have accepted this risk for the following reasons:
36
+ - Based on NIST FIPS 204 standardized algorithm
37
+ - Zero production dependencies (minimal supply chain risk)
38
+ - No known CVEs
39
+ - Version pinned (not using semver range) for stability
40
+
41
+ **Migration Plan:** We plan to migrate to [@noble/post-quantum](https://www.npmjs.com/package/@noble/post-quantum) in Q4 2026 (xBind v2.0.0), which offers broader ecosystem support and maturity.
42
+
43
+ For production deployments requiring formal cryptographic assurance, please contact contact@private.me for enterprise options.
44
+
45
+ ## Dependencies
46
+
47
+ xBind requires the following runtime dependencies for cryptographic operations and network communication:
48
+
49
+ ### Post-Quantum Cryptography
50
+
51
+ - **mlkem** — Post-quantum key encapsulation mechanism (ML-KEM-768, FIPS 203)
52
+ - Purpose: Quantum-resistant key agreement for message encryption
53
+ - Security: NIST-approved lattice-based cryptography, 192-bit security level
54
+ - Usage: Establishes shared secrets between agents resistant to quantum attacks
55
+
56
+ - **mldsa-wasm@0.0.4** — Post-quantum digital signatures (ML-DSA-65, FIPS 204)
57
+ - Purpose: Quantum-resistant DID identity and message signing
58
+ - Security: NIST-approved lattice-based signatures, 192-bit security level
59
+ - Usage: Signs all agent messages and verifies peer identity
60
+
61
+ ### Network Communication
62
+
63
+ - **bonjour-service** — mDNS service discovery (Peer Discovery model)
64
+ - Purpose: Zero-configuration local network device pairing
65
+ - Security: LAN-only discovery with user confirmation and cryptographic verification
66
+ - Usage: Enables IoT devices and offline pairing without internet connectivity
67
+
68
+ - **nodemailer@8.0.7** — Email transport for invitation delivery
69
+ - Purpose: Delivers single-use invite codes for customer onboarding
70
+ - Security: 6-character codes with 24-hour TTL, rate-limited generation
71
+ - Usage: Supports Invite Code connection model for remote agent pairing
72
+
73
+ ### Internal Dependencies (Bundled)
74
+
75
+ The following @private.me/* packages are bundled into xBind's distribution and do not require separate installation:
76
+
77
+ - **@private.me/shared** — Core types and Result<T,E> error handling primitives
78
+ - **@private.me/crypto** — XorIDA threshold sharing, HMAC verification, cryptographic primitives
79
+ - **@private.me/xchange** — Transport envelope formatting and message serialization
80
+ - **@private.me/ux-helpers** — Abuse prevention and rate limiting utilities
81
+ - **@private.me/xregistry** — Trust registry interface and DID resolution
82
+
83
+ These dependencies are compiled into `dist-standalone/` with relative import paths. Users install xBind as a single package - no separate installation of building blocks required.
84
+
85
+ All cryptographic dependencies are production-grade implementations. No test or mock crypto is used in production builds.
86
+
87
+ ## Setup & Configuration
88
+
89
+ ### Environment Variables
90
+
91
+ #### FULL_CONTROL_MASTER_KEY (Required)
92
+
93
+ **Critical for Production:** This key is required for Share 2 decryption in the Full Control vault store. Without it, the package cannot access proprietary XorIDA algorithms.
94
+
95
+ ```bash
96
+ # Generate a new key (one-time setup)
97
+ openssl rand -base64 32
98
+
99
+ # Set in your environment
100
+ export FULL_CONTROL_MASTER_KEY="<generated-key-here>"
101
+
102
+ # Verify length (should be 44 characters)
103
+ echo ${#FULL_CONTROL_MASTER_KEY}
104
+ ```
105
+
106
+ **Key Details:**
107
+ - **Purpose:** Master key for Share 2 decryption in Full Control vault store
108
+ - **Format:** 32-byte random value, base64-encoded (44 characters)
109
+ - **When Required:**
110
+ - ✅ Required in production for Full Control operations
111
+ - ✅ Required for server health checks to pass
112
+ - ⚠️ Optional for basic testing (package will use fallback behavior)
113
+ - **Security:** Store in `.env` file with `chmod 600` permissions
114
+ - **Validation:** Server health check at `/aci/billing/health` validates this key
115
+
116
+ **Troubleshooting:**
117
+
118
+ If you see errors like `FULL_CONTROL_MASTER_KEY not configured` or `Share 2 decryption failed`:
119
+ 1. Verify the key is set: `echo $FULL_CONTROL_MASTER_KEY`
120
+ 2. Check the length is exactly 44 characters
121
+ 3. Ensure `.env` file is loaded (if using dotenv)
122
+ 4. Verify file permissions: `chmod 600 .env`
123
+ 5. For production deployments, confirm the key is set in your deployment configuration
124
+
125
+ See [Configuration Guide](./docs/configuration.md) for complete setup instructions and advanced configuration options.
126
+
127
+ ## Pricing
128
+
129
+ **100,000 operations free per month** — No credit card required. After free tier: $5 per 100,000 operations.
130
+
131
+ **Tiers:**
132
+ - **Basic:** 100k ops/month free
133
+ - **Pro:** $5 per 100k operations (unlimited)
134
+ - **Enterprise:** Volume discounts + dedicated support
135
+
136
+ **Free Trial:** Start with 100k operations free. No signup required until you reach usage limits.
137
+
138
+ See [pricing details](../../docs/pricing-reference.md) for current rates and complete tier comparison.
139
+
140
+ [Subscribe now](https://private.me/subscribe?product=xbind)
141
+
142
+ ## Quick Start
143
+
144
+ **15 seconds to setup:**
145
+
146
+ ```typescript
147
+ import { Agent } from '@private.me/xbind';
148
+
149
+ // Create agent (auto-generates identity)
150
+ const agent = await Agent.lazy({ name: 'my-service' });
151
+
152
+ // Send authenticated message
153
+ const result = await agent.send({
154
+ to: 'did:key:z6Mk...', // recipient DID
155
+ payload: { action: 'createCharge', amount: 100 },
156
+ scope: 'billing'
157
+ });
158
+
159
+ if (!result.ok) {
160
+ console.error(`Failed: ${result.error}`);
161
+ return;
162
+ }
163
+
164
+ console.log('Message sent with cryptographic identity');
165
+ console.log('Agent DID:', agent.did);
166
+ ```
167
+
168
+ **Prerequisites:** The `FULL_CONTROL_MASTER_KEY` environment variable is required for Share 2 operations in production but optional for basic testing. See [Environment Variables](#environment-variables) for setup.
169
+
170
+ [More examples](./docs/examples.md) • [Python examples](./python/README.md)
171
+
172
+ ## Python SDK
173
+
174
+ Complete Python bindings for agent identity and messaging:
175
+
176
+ ```python
177
+ from private_me.xbind import Agent
178
+
179
+ # Create agent from private key
180
+ agent = Agent.from_private_key(private_key_bytes)
181
+
182
+ # Make authenticated call
183
+ result = agent.call('stripe:createCharge', {
184
+ 'amount': 100,
185
+ 'currency': 'usd',
186
+ 'description': 'AI agent purchase'
187
+ })
188
+
189
+ if result['ok']:
190
+ print(f"Charge ID: {result['data']['id']}")
191
+ print(f"Agent DID: {result['audit']['agent']}")
192
+ else:
193
+ print(f"Error: {result['error']['message']}")
194
+ ```
195
+
196
+ See [Python SDK documentation](./python/README.md) for complete API reference and examples.
197
+
198
+ ## Why xBind?
199
+
200
+ Zero key management, zero cascade failures, zero bearer credentials. Cryptographic identity replaces API keys. See [white paper](https://private.me/docs/xbind.html) for architecture details and benchmarks.
201
+
202
+ ## Getting Started
203
+
204
+ **[Guide](../../docs/xbind-integrations/getting-started/index.md)** — Concepts, migration
205
+ **[Quickstart](../../docs/xbind-integrations/getting-started/quickstart.md)** — 15-second setup
206
+
207
+ ## Features
208
+
209
+ Post-quantum cryptography (ML-KEM-768, ML-DSA-65), bilateral authorization, XorIDA split-channel delivery, Python SDK, Full Control IP protection, zero rotation, type safety with `Result<T, E>`, PLAN-3 hybrid signatures, 96 error codes.
210
+
211
+ ## Billing & Metering
212
+
213
+ xBind includes usage-based billing with automated milestone notifications:
214
+
215
+ - **Free Tier:** 100,000 operations/month (no email verification required upfront)
216
+ - **Grace Buffer:** 20,000 additional operations (120K total) if email verified
217
+ - **Hard Cap:** 120,000 operations/month
218
+ - **Pro Tier:** Unlimited operations at $5 per 100K (after first 100K free)
219
+ - **Monthly Reset:** 1st of each month at 00:00 UTC
220
+
221
+ See [pricing](../../docs/pricing-reference.md) for current rates and tier details.
222
+
223
+ ### Milestone Notifications
224
+
225
+ Automated email notifications at usage thresholds:
226
+
227
+ | Threshold | Usage | Progress Bar | CTA |
228
+ |-----------|-------|--------------|-----|
229
+ | 50K | 50% | Green | View Dashboard |
230
+ | 80K | 80% | Orange | Upgrade to Pro |
231
+ | 100K | 100% | Red | Verify Email & Continue |
232
+ | 120K | 120% | Red | Upgrade to Pro Now |
233
+
234
+ **Email verification:** Required at 100K operations to access grace buffer (100K-120K).
235
+
236
+ **Implementation:**
237
+ - Metering logic: `apps/server/src/customer-metering.ts`
238
+ - Milestone system: `apps/server/src/usage-milestone-notifications.ts`
239
+ - Tier pattern: See `docs/gold-package.md` section 7.6.5
240
+
241
+ ## Gateway
242
+
243
+ Non-authoritative coordination for discovery, relay, push notifications, and state checkpoints. Cannot forge identity or decide trust. See [Gateway Architecture](./docs/gateway-architecture.md).
244
+
245
+ ## Connection Models
246
+
247
+ xBind provides four connection models for entity-to-entity authentication: Invite Code (email-based onboarding), QR Code (physical proximity pairing), Trust Registry (pre-authorized enterprise), and Peer Discovery (mDNS local network). All use cryptographic DIDs.
248
+
249
+ | Model | Security | UX | Best For |
250
+ |-------|----------|-----|----------|
251
+ | Invite Code | Single-use, 24h TTL | 6-char code | Customer onboarding |
252
+ | QR Code | Physical proximity, 60s TTL | Scan & tap | Mobile/desktop pairing |
253
+ | Trust Registry | Admin pre-auth, scoped | Zero (automated) | Enterprise/CI/CD |
254
+ | Peer Discovery | LAN proximity, user confirm | Scan & confirm | IoT devices, offline |
255
+
256
+ See [Entity-to-Entity Connection UX Guide](../../docs/ENTITY-TO-ENTITY-CONNECTION-UX.md) for implementation patterns and code examples.
257
+
258
+ ## Configuration
259
+
260
+ ### Basic Setup
261
+
262
+ ```typescript
263
+ import { HttpTrustRegistry } from '@private.me/xbind';
264
+
265
+ // Documentation example - use your actual gateway URL
266
+ const registry = new HttpTrustRegistry({
267
+ baseUrl: 'https://gateway.private.me'
268
+ });
269
+ ```
270
+
271
+ ### Advanced Features
272
+
273
+ Checkpoints, sequence numbers, subscription proofs, XorIDA configuration, key backup (2-of-3 default), DID succession. See [Configuration Guide](./docs/configuration.md) and [Examples](./docs/examples.md).
274
+
275
+ ## Type Safety
276
+
277
+ xbind returns `Result<T, E>` types for type-safe error handling.
278
+
279
+ ```typescript
280
+ import { call, type CallResult } from '@private.me/xbind';
281
+
282
+ interface User { id: number; name: string; email: string; }
283
+
284
+ const result: CallResult<User> = await call('getUser', { id: 123 });
285
+ if (result.ok) {
286
+ console.log(result.value.data.name);
287
+ console.log(result.value.audit.signature);
288
+ } else {
289
+ console.error(result.error.message);
290
+ }
291
+ ```
292
+
293
+ Error types: `ConnectionError`, `AuthenticationError`, `ValidationError`, `RateLimitError`, `ServerError`
294
+
295
+ ## Documentation
296
+
297
+ - **[API Reference](./docs/api-reference.md)** — Complete API documentation
298
+ - **[Configuration Guide](./docs/configuration.md)** — All configuration options
299
+ - **[Examples](./docs/examples.md)** — Common usage patterns
300
+ - **[Troubleshooting](./docs/troubleshooting.md)** — Common issues and solutions
301
+ - **[Advanced Guide](./docs/advanced.md)** — Multi-backend failover, retry strategies
302
+ - **[White Paper](https://private.me/docs/xbind.html)** — Architecture and design
303
+ - **[AGENTS.md](./AGENTS.md)** — AI agent patterns
304
+ - **[SECURITY.md](./SECURITY.md)** — Threat model
305
+
306
+ ## Testing
307
+
308
+ **1,245/1,245 tests passing** — Comprehensive coverage including post-quantum cryptography (ML-KEM-768, ML-DSA-65), hybrid signature verification, DID generation, message encryption, transport layer, multi-agent coordination, error handling, Python SDK bindings, and Full Control protection.
309
+
310
+ ```bash
311
+ pnpm test # All tests
312
+ pnpm test:coverage # Coverage report
313
+ pnpm test:watch # Watch mode
314
+ ```
315
+
316
+ ## IP Protection
317
+
318
+ Full Control protection using Store Front (npm) + Vault Store (EC2). Share 2 requires payment verification. See [IP Protection](./docs/ip-protection.md).
319
+
320
+ ## Data Collection
321
+
322
+ xBind makes network connections for three purposes, each with different security and privacy characteristics:
323
+
324
+ ### 1. Local Network Discovery (Peer Discovery Model Only)
325
+
326
+ **When:** Only when using the Peer Discovery connection model for IoT devices and offline pairing.
327
+
328
+ **What:** Sends mDNS (multicast DNS) broadcast messages on your local network to discover nearby xBind-compatible devices.
329
+
330
+ **Data transmitted:**
331
+ - Device DID (cryptographic identity, public key)
332
+ - Device type identifier
333
+ - Service announcement (port, protocol version)
334
+
335
+ **Security:** Broadcast messages are visible to all devices on the local network. Does NOT transmit private keys, message content, or personal data. Recipients cannot impersonate your device without the private key.
336
+
337
+ **Privacy:** Other connection models (Invite Code, QR Code, Trust Registry) do NOT use local network discovery.
338
+
339
+ ### 2. Gateway Communication (gateway.private.me)
340
+
341
+ **When:** During message delivery, Share 2 retrieval, and connection establishment.
342
+
343
+ **What:** Encrypted communication with gateway.private.me for coordination and IP protection.
344
+
345
+ **Data transmitted:**
346
+ - **Share 2 delivery:** Encrypted share required for Full Control vault store reconstruction (payment-gated)
347
+ - **Usage metrics:** Operation counts, error codes, latency (anonymized, no message content)
348
+ - **Connection metadata:** DID identifiers, sequence numbers, checkpoints (for message ordering)
349
+ - **Push notifications:** Delivery receipts, presence signals (encrypted, no content)
350
+
351
+ **Security:** All communication uses TLS 1.3. Gateway is non-authoritative and cannot forge identity or decrypt messages. See [Gateway Architecture](./docs/gateway-architecture.md).
352
+
353
+ **Privacy:** No message content, API credentials, or plaintext data transmitted. DIDs are pseudonymous identifiers.
354
+
355
+ ### 3. Full Control Share Retrieval
356
+
357
+ **When:** During initial setup and algorithm reconstruction.
358
+
359
+ **What:** Downloads Share 2 (Vault Store) from gateway.private.me after payment verification.
360
+
361
+ **Data transmitted:**
362
+ - Payment proof (Stripe subscription ID)
363
+ - xBind authentication token (cryptographic proof of identity)
364
+ - Package identifier and version
365
+
366
+ **Security:** Share 2 is AES-256-GCM encrypted with FULL_CONTROL_MASTER_KEY. Without both Share 1 (npm) and Share 2 (gateway), the algorithm cannot execute.
367
+
368
+ **Privacy:** Payment verification uses Stripe (see [Stripe Privacy](https://stripe.com/privacy)). xBind does not store credit card data.
369
+
370
+ ### Data Retention
371
+
372
+ - **Usage metrics:** 90 days (aggregated, anonymized)
373
+ - **Connection metadata:** 30 days (sequence numbers, checkpoints)
374
+ - **Share 2 downloads:** Access logs retained per payment verification requirements
375
+
376
+ ### Opt-Out
377
+
378
+ **Local network discovery:** Disable by not using Peer Discovery connection model.
379
+
380
+ **Gateway communication:** Required for message delivery. Self-hosted gateway option available for enterprise (contact contact@private.me).
381
+
382
+ **Usage metrics:** Cannot be disabled (required for billing and abuse prevention).
383
+
384
+ For complete privacy details, see [Privacy Policy](https://private.me/privacy).
385
+
386
+ ## Legal
387
+
388
+ [Terms of Service](https://private.me/terms) • [Privacy Policy](https://private.me/privacy) • [License](./LICENSE.md)
389
+
390
+ ## Export Control Notice
391
+
392
+ This package contains cryptographic software. Export restrictions may apply. Users are responsible for compliance with U.S. Export Administration Regulations (EAR) and jurisdiction-specific export control requirements.
393
+
394
+ ---
395
+
396
+ **License:** Proprietary
397
+
398
+ ---
399
+
400
+ **Questions?** [Documentation](./docs/README.md) • [White paper](https://private.me/docs/xbind.html) • [Issues](https://github.com/xail-io/xail/issues)
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Encode bytes to standard Base64 (RFC 4648).
3
+ *
4
+ * @param data - Bytes to encode
5
+ * @returns Base64-encoded string with padding
6
+ */
7
+ export declare function toBase64(data: Uint8Array): string;
8
+ /**
9
+ * Decode standard Base64 string to bytes.
10
+ *
11
+ * @param str - Base64-encoded string
12
+ * @returns Decoded bytes
13
+ */
14
+ export declare function fromBase64(str: string): Uint8Array;
15
+ /**
16
+ * Encode bytes to Base64url (RFC 4648 Section 5).
17
+ * Uses URL-safe characters (-_ instead of +/) and no padding.
18
+ *
19
+ * @param data - Bytes to encode
20
+ * @returns Base64url-encoded string without padding
21
+ */
22
+ export declare function toBase64Url(data: Uint8Array): string;
23
+ /**
24
+ * Decode Base64url string to bytes.
25
+ *
26
+ * @param str - Base64url-encoded string
27
+ * @returns Decoded bytes
28
+ */
29
+ export declare function fromBase64Url(str: string): Uint8Array;
@@ -0,0 +1,97 @@
1
+ const CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
2
+ const URL_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
3
+ /**
4
+ * Encode bytes to standard Base64 (RFC 4648).
5
+ *
6
+ * @param data - Bytes to encode
7
+ * @returns Base64-encoded string with padding
8
+ */
9
+ export function toBase64(data) {
10
+ return encode(data, CHARS, true);
11
+ }
12
+ /**
13
+ * Decode standard Base64 string to bytes.
14
+ *
15
+ * @param str - Base64-encoded string
16
+ * @returns Decoded bytes
17
+ */
18
+ export function fromBase64(str) {
19
+ return decode(str, CHARS);
20
+ }
21
+ /**
22
+ * Encode bytes to Base64url (RFC 4648 Section 5).
23
+ * Uses URL-safe characters (-_ instead of +/) and no padding.
24
+ *
25
+ * @param data - Bytes to encode
26
+ * @returns Base64url-encoded string without padding
27
+ */
28
+ export function toBase64Url(data) {
29
+ return encode(data, URL_CHARS, false);
30
+ }
31
+ /**
32
+ * Decode Base64url string to bytes.
33
+ *
34
+ * @param str - Base64url-encoded string
35
+ * @returns Decoded bytes
36
+ */
37
+ export function fromBase64Url(str) {
38
+ return decode(str, URL_CHARS);
39
+ }
40
+ /** Encode bytes using the given alphabet. */
41
+ function encode(data, alphabet, pad) {
42
+ let result = '';
43
+ for (let i = 0; i < data.length; i += 3) {
44
+ const a = data[i];
45
+ const b = i + 1 < data.length ? data[i + 1] : 0;
46
+ const c = i + 2 < data.length ? data[i + 2] : 0;
47
+ result += alphabet[(a >> 2)];
48
+ result += alphabet[((a & 0x03) << 4) | (b >> 4)];
49
+ if (i + 1 < data.length) {
50
+ result += alphabet[((b & 0x0f) << 2) | (c >> 6)];
51
+ }
52
+ if (i + 2 < data.length) {
53
+ result += alphabet[c & 0x3f];
54
+ }
55
+ }
56
+ if (pad) {
57
+ const remainder = data.length % 3;
58
+ if (remainder === 1)
59
+ result += '==';
60
+ else if (remainder === 2)
61
+ result += '=';
62
+ }
63
+ return result;
64
+ }
65
+ /** Build a reverse lookup map for a Base64 alphabet. */
66
+ function buildLookup(alphabet) {
67
+ const map = new Map();
68
+ for (let i = 0; i < alphabet.length; i++) {
69
+ map.set(alphabet[i], i);
70
+ }
71
+ return map;
72
+ }
73
+ const STD_LOOKUP = buildLookup(CHARS);
74
+ const URL_LOOKUP = buildLookup(URL_CHARS);
75
+ /** Decode a Base64 string using the given lookup. Tolerates whitespace (RFC 2045). */
76
+ function decode(str, alphabet) {
77
+ const lookup = alphabet === CHARS ? STD_LOOKUP : URL_LOOKUP;
78
+ const stripped = str.replace(/\s/g, '');
79
+ const cleaned = stripped.replace(/=+$/, '');
80
+ const byteLen = Math.floor((cleaned.length * 3) / 4);
81
+ const result = new Uint8Array(byteLen);
82
+ let byteIdx = 0;
83
+ for (let i = 0; i < cleaned.length; i += 4) {
84
+ const a = lookup.get(cleaned[i]) ?? 0;
85
+ const b = lookup.get(cleaned[i + 1]) ?? 0;
86
+ const c = i + 2 < cleaned.length ? (lookup.get(cleaned[i + 2]) ?? 0) : 0;
87
+ const d = i + 3 < cleaned.length ? (lookup.get(cleaned[i + 3]) ?? 0) : 0;
88
+ result[byteIdx++] = (a << 2) | (b >> 4);
89
+ if (i + 2 < cleaned.length) {
90
+ result[byteIdx++] = ((b & 0x0f) << 4) | (c >> 2);
91
+ }
92
+ if (i + 3 < cleaned.length) {
93
+ result[byteIdx++] = ((c & 0x03) << 6) | d;
94
+ }
95
+ }
96
+ return result;
97
+ }
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toBase64 = toBase64;
4
+ exports.fromBase64 = fromBase64;
5
+ exports.toBase64Url = toBase64Url;
6
+ exports.fromBase64Url = fromBase64Url;
7
+ const CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
8
+ const URL_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
9
+ /**
10
+ * Encode bytes to standard Base64 (RFC 4648).
11
+ *
12
+ * @param data - Bytes to encode
13
+ * @returns Base64-encoded string with padding
14
+ */
15
+ function toBase64(data) {
16
+ return encode(data, CHARS, true);
17
+ }
18
+ /**
19
+ * Decode standard Base64 string to bytes.
20
+ *
21
+ * @param str - Base64-encoded string
22
+ * @returns Decoded bytes
23
+ */
24
+ function fromBase64(str) {
25
+ return decode(str, CHARS);
26
+ }
27
+ /**
28
+ * Encode bytes to Base64url (RFC 4648 Section 5).
29
+ * Uses URL-safe characters (-_ instead of +/) and no padding.
30
+ *
31
+ * @param data - Bytes to encode
32
+ * @returns Base64url-encoded string without padding
33
+ */
34
+ function toBase64Url(data) {
35
+ return encode(data, URL_CHARS, false);
36
+ }
37
+ /**
38
+ * Decode Base64url string to bytes.
39
+ *
40
+ * @param str - Base64url-encoded string
41
+ * @returns Decoded bytes
42
+ */
43
+ function fromBase64Url(str) {
44
+ return decode(str, URL_CHARS);
45
+ }
46
+ /** Encode bytes using the given alphabet. */
47
+ function encode(data, alphabet, pad) {
48
+ let result = '';
49
+ for (let i = 0; i < data.length; i += 3) {
50
+ const a = data[i];
51
+ const b = i + 1 < data.length ? data[i + 1] : 0;
52
+ const c = i + 2 < data.length ? data[i + 2] : 0;
53
+ result += alphabet[(a >> 2)];
54
+ result += alphabet[((a & 0x03) << 4) | (b >> 4)];
55
+ if (i + 1 < data.length) {
56
+ result += alphabet[((b & 0x0f) << 2) | (c >> 6)];
57
+ }
58
+ if (i + 2 < data.length) {
59
+ result += alphabet[c & 0x3f];
60
+ }
61
+ }
62
+ if (pad) {
63
+ const remainder = data.length % 3;
64
+ if (remainder === 1)
65
+ result += '==';
66
+ else if (remainder === 2)
67
+ result += '=';
68
+ }
69
+ return result;
70
+ }
71
+ /** Build a reverse lookup map for a Base64 alphabet. */
72
+ function buildLookup(alphabet) {
73
+ const map = new Map();
74
+ for (let i = 0; i < alphabet.length; i++) {
75
+ map.set(alphabet[i], i);
76
+ }
77
+ return map;
78
+ }
79
+ const STD_LOOKUP = buildLookup(CHARS);
80
+ const URL_LOOKUP = buildLookup(URL_CHARS);
81
+ /** Decode a Base64 string using the given lookup. Tolerates whitespace (RFC 2045). */
82
+ function decode(str, alphabet) {
83
+ const lookup = alphabet === CHARS ? STD_LOOKUP : URL_LOOKUP;
84
+ const stripped = str.replace(/\s/g, '');
85
+ const cleaned = stripped.replace(/=+$/, '');
86
+ const byteLen = Math.floor((cleaned.length * 3) / 4);
87
+ const result = new Uint8Array(byteLen);
88
+ let byteIdx = 0;
89
+ for (let i = 0; i < cleaned.length; i += 4) {
90
+ const a = lookup.get(cleaned[i]) ?? 0;
91
+ const b = lookup.get(cleaned[i + 1]) ?? 0;
92
+ const c = i + 2 < cleaned.length ? (lookup.get(cleaned[i + 2]) ?? 0) : 0;
93
+ const d = i + 3 < cleaned.length ? (lookup.get(cleaned[i + 3]) ?? 0) : 0;
94
+ result[byteIdx++] = (a << 2) | (b >> 4);
95
+ if (i + 2 < cleaned.length) {
96
+ result[byteIdx++] = ((b & 0x0f) << 4) | (c >> 2);
97
+ }
98
+ if (i + 3 < cleaned.length) {
99
+ result[byteIdx++] = ((c & 0x03) << 6) | d;
100
+ }
101
+ }
102
+ return result;
103
+ }