@private.me/xbind 3.0.0 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/README.md +55 -7
  2. package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1920 -1
  3. package/dist-standalone/_deps/shared/cjs/errors.js +729 -1
  4. package/dist-standalone/_deps/shared/cjs/index.js +463 -1
  5. package/dist-standalone/_deps/shared/cjs/types.js +315 -1
  6. package/dist-standalone/_deps/shared/errors.js +244 -1
  7. package/dist-standalone/_deps/shared/index.js +72 -1
  8. package/dist-standalone/_deps/shared/types.js +86 -1
  9. package/dist-standalone/_deps/ux-helpers/cjs/errors.js +1 -1
  10. package/dist-standalone/_deps/ux-helpers/cjs/index.js +1 -1
  11. package/dist-standalone/_deps/ux-helpers/cjs/pagination.js +1 -1
  12. package/dist-standalone/_deps/ux-helpers/cjs/progress.js +1 -1
  13. package/dist-standalone/_deps/ux-helpers/cjs/search.js +1 -1
  14. package/dist-standalone/_deps/ux-helpers/cjs/types.js +1 -1
  15. package/dist-standalone/_deps/ux-helpers/errors.js +1 -1
  16. package/dist-standalone/_deps/ux-helpers/index.js +1 -1
  17. package/dist-standalone/_deps/ux-helpers/pagination.js +1 -1
  18. package/dist-standalone/_deps/ux-helpers/progress.js +1 -1
  19. package/dist-standalone/_deps/ux-helpers/search.js +1 -1
  20. package/dist-standalone/_deps/xchange/auto-accept.js +1 -1
  21. package/dist-standalone/_deps/xchange/cjs/auto-accept.js +1 -1
  22. package/dist-standalone/_deps/xchange/cjs/errors.js +1 -1
  23. package/dist-standalone/_deps/xchange/cjs/index.js +1 -1
  24. package/dist-standalone/_deps/xchange/cjs/invite-client.js +1 -1
  25. package/dist-standalone/_deps/xchange/cjs/lazy-init.js +1 -1
  26. package/dist-standalone/_deps/xchange/cjs/trust-integration.js +1 -1
  27. package/dist-standalone/_deps/xchange/cjs/xchange.js +1 -1
  28. package/dist-standalone/_deps/xchange/errors.js +1 -1
  29. package/dist-standalone/_deps/xchange/index.js +1 -1
  30. package/dist-standalone/_deps/xchange/invite-client.js +1 -1
  31. package/dist-standalone/_deps/xchange/lazy-init.js +1 -1
  32. package/dist-standalone/_deps/xchange/trust-integration.js +1 -1
  33. package/dist-standalone/_deps/xchange/xchange.js +1 -1
  34. package/dist-standalone/_deps/xregistry/cjs/discovery.js +1 -1
  35. package/dist-standalone/_deps/xregistry/cjs/errors.js +1 -1
  36. package/dist-standalone/_deps/xregistry/cjs/index.js +1 -1
  37. package/dist-standalone/_deps/xregistry/cjs/registry.js +1 -1
  38. package/dist-standalone/_deps/xregistry/cjs/schema.js +1 -1
  39. package/dist-standalone/_deps/xregistry/cjs/types.js +1 -1
  40. package/dist-standalone/_deps/xregistry/discovery.js +1 -1
  41. package/dist-standalone/_deps/xregistry/errors.js +1 -1
  42. package/dist-standalone/_deps/xregistry/index.js +1 -1
  43. package/dist-standalone/_deps/xregistry/registry.js +1 -1
  44. package/dist-standalone/_deps/xregistry/schema.js +1 -1
  45. package/dist-standalone/_deps/xregistry/types.js +1 -1
  46. package/dist-standalone/agent-call.js +659 -1
  47. package/dist-standalone/agent-sdk.js +328 -1
  48. package/dist-standalone/agent.js +1800 -1
  49. package/dist-standalone/approval.js +193 -1
  50. package/dist-standalone/async-iterators.js +382 -1
  51. package/dist-standalone/auth.js +219 -1
  52. package/dist-standalone/auto-accept.js +229 -1
  53. package/dist-standalone/backup-config.js +201 -1
  54. package/dist-standalone/backup.js +326 -1
  55. package/dist-standalone/batch-operations.js +388 -1
  56. package/dist-standalone/cancellation.js +477 -1
  57. package/dist-standalone/checkpoint.js +186 -1
  58. package/dist-standalone/circuit-breaker.js +468 -1
  59. package/dist-standalone/cjs/agent-call.js +701 -1
  60. package/dist-standalone/cjs/agent-sdk.js +332 -1
  61. package/dist-standalone/cjs/agent.js +1837 -1
  62. package/dist-standalone/cjs/approval.js +199 -1
  63. package/dist-standalone/cjs/async-iterators.js +392 -1
  64. package/dist-standalone/cjs/auth.js +225 -1
  65. package/dist-standalone/cjs/auto-accept.js +233 -1
  66. package/dist-standalone/cjs/backup-config.js +207 -1
  67. package/dist-standalone/cjs/backup.js +330 -1
  68. package/dist-standalone/cjs/batch-operations.js +397 -1
  69. package/dist-standalone/cjs/cancellation.js +490 -1
  70. package/dist-standalone/cjs/checkpoint.js +193 -1
  71. package/dist-standalone/cjs/circuit-breaker.js +476 -1
  72. package/dist-standalone/cjs/cli/init.js +492 -1
  73. package/dist-standalone/cjs/config-validation.js +522 -1
  74. package/dist-standalone/cjs/connect.js +312 -1
  75. package/dist-standalone/cjs/connection-pool.js +506 -1
  76. package/dist-standalone/cjs/correlation-id.js +339 -1
  77. package/dist-standalone/cjs/crypto-utils.js +176 -1
  78. package/dist-standalone/cjs/debug-mode.js +534 -1
  79. package/dist-standalone/cjs/did-document.js +101 -1
  80. package/dist-standalone/cjs/did-privateme.js +130 -1
  81. package/dist-standalone/cjs/did-web.js +201 -1
  82. package/dist-standalone/cjs/discovery.js +462 -1
  83. package/dist-standalone/cjs/dual-mode.js +251 -1
  84. package/dist-standalone/cjs/email-templates.js +313 -1
  85. package/dist-standalone/cjs/email-transport.js +239 -1
  86. package/dist-standalone/cjs/envelope.js +538 -1
  87. package/dist-standalone/cjs/errors.js +913 -1
  88. package/dist-standalone/cjs/event-emitter.js +461 -1
  89. package/dist-standalone/cjs/gateway-state.js +55 -1
  90. package/dist-standalone/cjs/gateway-transport.js +120 -1
  91. package/dist-standalone/cjs/graceful-degradation.js +403 -1
  92. package/dist-standalone/cjs/guardrails.js +223 -1
  93. package/dist-standalone/cjs/health-check.js +336 -1
  94. package/dist-standalone/cjs/http-compat.js +272 -1
  95. package/dist-standalone/cjs/http-status-map.js +571 -1
  96. package/dist-standalone/cjs/identity.js +645 -1
  97. package/dist-standalone/cjs/index.js +406 -1
  98. package/dist-standalone/cjs/invitation.js +421 -1
  99. package/dist-standalone/cjs/invite.js +328 -1
  100. package/dist-standalone/cjs/key-agreement.js +335 -1
  101. package/dist-standalone/cjs/lazy-init.js +300 -1
  102. package/dist-standalone/cjs/logger.js +291 -1
  103. package/dist-standalone/cjs/mdns-discovery.js +202 -1
  104. package/dist-standalone/cjs/nonce-store.js +80 -1
  105. package/dist-standalone/cjs/pairing-manager.js +223 -1
  106. package/dist-standalone/cjs/plugin-system.js +264 -1
  107. package/dist-standalone/cjs/plugins/logging.js +168 -1
  108. package/dist-standalone/cjs/plugins/metrics.js +181 -1
  109. package/dist-standalone/cjs/plugins/validation.js +302 -1
  110. package/dist-standalone/cjs/policy.js +320 -1
  111. package/dist-standalone/cjs/progress-callbacks.js +583 -1
  112. package/dist-standalone/cjs/redis-nonce-store.js +76 -1
  113. package/dist-standalone/cjs/registry-middleware.js +50 -1
  114. package/dist-standalone/cjs/retry-strategies.js +544 -1
  115. package/dist-standalone/cjs/retry-transport.js +102 -1
  116. package/dist-standalone/cjs/runtime/browser.js +533 -1
  117. package/dist-standalone/cjs/runtime/edge.js +526 -1
  118. package/dist-standalone/cjs/runtime/react-native.js +394 -1
  119. package/dist-standalone/cjs/security-policy.js +245 -1
  120. package/dist-standalone/cjs/serialization.js +1040 -1
  121. package/dist-standalone/cjs/split-channel.js +225 -1
  122. package/dist-standalone/cjs/subscription-proof.js +230 -1
  123. package/dist-standalone/cjs/succession.js +148 -1
  124. package/dist-standalone/cjs/timeouts.js +412 -1
  125. package/dist-standalone/cjs/trace-context.js +424 -1
  126. package/dist-standalone/cjs/trace-spans.js +495 -1
  127. package/dist-standalone/cjs/transport.js +63 -1
  128. package/dist-standalone/cjs/trust-registry.js +991 -1
  129. package/dist-standalone/cjs/types/error-response.js +56 -1
  130. package/dist-standalone/cjs/vault-auth.js +178 -1
  131. package/dist-standalone/cjs/vault-store-loader.js +194 -1
  132. package/dist-standalone/cjs/verify.js +25 -1
  133. package/dist-standalone/cjs/version-info.js +543 -1
  134. package/dist-standalone/cjs/xfetch.js +340 -1
  135. package/dist-standalone/cli/init.js +455 -1
  136. package/dist-standalone/cli/setup.js +514 -1
  137. package/dist-standalone/cli/types.js +27 -1
  138. package/dist-standalone/cli/xbind.js +148 -1
  139. package/dist-standalone/config-validation.js +513 -1
  140. package/dist-standalone/connect.js +274 -1
  141. package/dist-standalone/connection-pool.js +500 -1
  142. package/dist-standalone/correlation-id.js +326 -1
  143. package/dist-standalone/crypto-utils.js +157 -1
  144. package/dist-standalone/debug-mode.js +510 -1
  145. package/dist-standalone/did-document.js +96 -1
  146. package/dist-standalone/did-privateme.js +121 -1
  147. package/dist-standalone/did-web.js +196 -1
  148. package/dist-standalone/discovery.js +458 -1
  149. package/dist-standalone/dual-mode.js +247 -1
  150. package/dist-standalone/email-templates.js +309 -1
  151. package/dist-standalone/email-transport.js +232 -1
  152. package/dist-standalone/envelope.js +525 -1
  153. package/dist-standalone/errors.js +896 -1
  154. package/dist-standalone/event-emitter.js +456 -1
  155. package/dist-standalone/gateway-state.js +51 -1
  156. package/dist-standalone/gateway-transport.js +116 -1
  157. package/dist-standalone/graceful-degradation.js +396 -1
  158. package/dist-standalone/guardrails.js +216 -1
  159. package/dist-standalone/health-check.js +332 -1
  160. package/dist-standalone/http-compat.js +267 -1
  161. package/dist-standalone/http-status-map.js +561 -1
  162. package/dist-standalone/identity.js +619 -1
  163. package/dist-standalone/index.js +78 -1
  164. package/dist-standalone/invitation.js +415 -1
  165. package/dist-standalone/invite.js +324 -1
  166. package/dist-standalone/key-agreement.js +325 -1
  167. package/dist-standalone/lazy-init.js +295 -1
  168. package/dist-standalone/logger.js +285 -1
  169. package/dist-standalone/mdns-discovery.js +195 -1
  170. package/dist-standalone/nonce-store.js +76 -1
  171. package/dist-standalone/pairing-manager.js +219 -1
  172. package/dist-standalone/plugin-system.js +257 -1
  173. package/dist-standalone/plugins/logging.d.ts +84 -0
  174. package/dist-standalone/plugins/logging.js +163 -0
  175. package/dist-standalone/plugins/metrics.d.ts +111 -0
  176. package/dist-standalone/plugins/metrics.js +176 -0
  177. package/dist-standalone/plugins/validation.d.ts +104 -0
  178. package/dist-standalone/plugins/validation.js +297 -0
  179. package/dist-standalone/policy.js +315 -1
  180. package/dist-standalone/progress-callbacks.js +576 -1
  181. package/dist-standalone/redis-nonce-store.js +72 -1
  182. package/dist-standalone/registry-middleware.js +47 -1
  183. package/dist-standalone/retry-strategies.js +534 -1
  184. package/dist-standalone/retry-transport.js +98 -1
  185. package/dist-standalone/runtime/browser.d.ts +311 -0
  186. package/dist-standalone/runtime/browser.js +516 -0
  187. package/dist-standalone/runtime/edge.d.ts +282 -0
  188. package/dist-standalone/runtime/edge.js +511 -0
  189. package/dist-standalone/runtime/react-native.d.ts +157 -0
  190. package/dist-standalone/runtime/react-native.js +383 -0
  191. package/dist-standalone/security-policy.js +239 -1
  192. package/dist-standalone/serialization.js +1031 -1
  193. package/dist-standalone/split-channel.js +219 -1
  194. package/dist-standalone/subscription-proof.js +224 -1
  195. package/dist-standalone/succession.js +142 -1
  196. package/dist-standalone/timeouts.js +398 -1
  197. package/dist-standalone/trace-context.js +414 -1
  198. package/dist-standalone/trace-spans.js +488 -1
  199. package/dist-standalone/transport.js +59 -1
  200. package/dist-standalone/trust-registry.js +950 -1
  201. package/dist-standalone/types/error-response.d.ts +209 -0
  202. package/dist-standalone/types/error-response.js +52 -0
  203. package/dist-standalone/vault-auth.js +174 -1
  204. package/dist-standalone/vault-store-loader.js +187 -1
  205. package/dist-standalone/verify.js +16 -1
  206. package/dist-standalone/version-info.js +530 -1
  207. package/dist-standalone/xfetch.js +335 -1
  208. package/package.json +4 -10
  209. package/share1.dat +0 -0
  210. package/dist-standalone/_deps/mldsa-wasm/LICENSE +0 -24
  211. package/dist-standalone/_deps/mldsa-wasm/package.json +0 -46
  212. package/dist-standalone/_deps/shared/cjs/package.json +0 -1
  213. package/dist-standalone/_deps/ux-helpers/cjs/package.json +0 -1
  214. package/dist-standalone/_deps/xchange/cjs/package.json +0 -1
  215. package/dist-standalone/_deps/xregistry/cjs/package.json +0 -1
  216. package/dist-standalone/cjs/package.json +0 -3
  217. package/dist-standalone/package.json +0 -10
@@ -1 +1,394 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BufferPolyfill=exports.AsyncStorageAdapter=void 0,exports.detectCrypto=detectCrypto,exports.getRandomBytes=getRandomBytes,exports.sha256=sha256,exports.isReactNative=isReactNative,exports.detectPlatform=detectPlatform,exports.initializeReactNative=initializeReactNative;const shared_1=require("../../_deps/shared/index.js");class AsyncStorageAdapter{storage;prefix;debug;constructor(t){this.storage=t.storage,this.prefix=t.storagePrefix||"@xbind:",this.debug=t.debug||!1}async get(t){try{const e=this.prefix+t,r=await this.storage.getItem(e);return this.debug&&console.log(`[AsyncStorage] GET ${e}:`,r?"found":"not found"),(0,shared_1.ok)(r)}catch(t){return(0,shared_1.err)(new Error(`AsyncStorage get failed: ${t}`))}}async set(t,e){try{const r=this.prefix+t;return await this.storage.setItem(r,e),this.debug&&console.log(`[AsyncStorage] SET ${r}:`,e.length,"bytes"),(0,shared_1.ok)(void 0)}catch(t){return(0,shared_1.err)(new Error(`AsyncStorage set failed: ${t}`))}}async remove(t){try{const e=this.prefix+t;return await this.storage.removeItem(e),this.debug&&console.log(`[AsyncStorage] REMOVE ${e}`),(0,shared_1.ok)(void 0)}catch(t){return(0,shared_1.err)(new Error(`AsyncStorage remove failed: ${t}`))}}async keys(){try{const t=(await this.storage.getAllKeys()).filter(t=>t.startsWith(this.prefix)).map(t=>t.substring(this.prefix.length));return this.debug&&console.log("[AsyncStorage] KEYS:",t.length,"items"),(0,shared_1.ok)(t)}catch(t){return(0,shared_1.err)(new Error(`AsyncStorage keys failed: ${t}`))}}async multiGet(t){try{const e=t.map(t=>this.prefix+t),r=(await this.storage.multiGet(e)).map(([t,e])=>[t.substring(this.prefix.length),e]);return this.debug&&console.log("[AsyncStorage] MULTI_GET:",t.length,"keys"),(0,shared_1.ok)(r)}catch(t){return(0,shared_1.err)(new Error(`AsyncStorage multiGet failed: ${t}`))}}async multiSet(t){try{const e=t.map(([t,e])=>[this.prefix+t,e]);return await this.storage.multiSet(e),this.debug&&console.log("[AsyncStorage] MULTI_SET:",t.length,"pairs"),(0,shared_1.ok)(void 0)}catch(t){return(0,shared_1.err)(new Error(`AsyncStorage multiSet failed: ${t}`))}}async clear(){try{const t=await this.keys();if(!t.ok)return(0,shared_1.err)(t.error);const e=t.value.map(t=>this.prefix+t);return e.length>0&&await this.storage.multiRemove(e),this.debug&&console.log("[AsyncStorage] CLEAR:",e.length,"items removed"),(0,shared_1.ok)(void 0)}catch(t){return(0,shared_1.err)(new Error(`AsyncStorage clear failed: ${t}`))}}}function detectCrypto(){if("undefined"!=typeof global&&global.crypto)return global.crypto;try{return require("react-native-quick-crypto")}catch{}try{const t=require("expo-crypto");return{getRandomValues:e=>{const r=t.getRandomBytes(e.length);e.set(r)}}}catch{}return null}function getRandomBytes(t,e){const r=e||detectCrypto();if(!r)throw new Error("No crypto implementation available. Install react-native-quick-crypto or expo-crypto.");const o=new Uint8Array(t);return r.getRandomValues(o),o}async function sha256(t,e){const r=e||detectCrypto();if(!r?.subtle)throw new Error("No SubtleCrypto implementation available. Install react-native-quick-crypto.");const o=new Uint8Array(t).buffer,a=await r.subtle.digest("SHA-256",o);return new Uint8Array(a)}exports.AsyncStorageAdapter=AsyncStorageAdapter;class BufferPolyfill{static isBuffer(t){return t instanceof Uint8Array}static from(t,e){if("string"==typeof t){if("base64"===e)return this.fromBase64(t);if("hex"===e)return this.fromHex(t);return(new TextEncoder).encode(t)}return Array.isArray(t),new Uint8Array(t)}static toString(t,e){if("base64"===e)return this.toBase64(t);if("hex"===e)return this.toHex(t);return(new TextDecoder).decode(t)}static concat(t){const e=t.reduce((t,e)=>t+e.length,0),r=new Uint8Array(e);let o=0;for(const e of t)r.set(e,o),o+=e.length;return r}static alloc(t,e){const r=new Uint8Array(t);return void 0!==e&&r.fill(e),r}static fromBase64(t){const e=atob(t),r=new Uint8Array(e.length);for(let t=0;t<e.length;t++)r[t]=e.charCodeAt(t);return r}static toBase64(t){let e="";for(let r=0;r<t.length;r++){const o=t[r];void 0!==o&&(e+=String.fromCharCode(o))}return btoa(e)}static fromHex(t){const e=new Uint8Array(t.length/2);for(let r=0;r<e.length;r++)e[r]=parseInt(t.substr(2*r,2),16);return e}static toHex(t){return Array.from(t).map(t=>t.toString(16).padStart(2,"0")).join("")}}function isReactNative(){return"undefined"!=typeof navigator&&"ReactNative"===navigator.product}function detectPlatform(){if("undefined"==typeof navigator)return"unknown";const t=navigator.userAgent||"";return/iPhone|iPad|iPod/.test(t)?"ios":/Android/.test(t)?"android":"unknown"}function initializeReactNative(t){try{if(!t.storage)return(0,shared_1.err)(new Error("AsyncStorage is required for React Native runtime"));const e=t.crypto||detectCrypto();return e?(global.crypto||(global.crypto=e),global.Buffer||(global.Buffer=BufferPolyfill),t.debug&&console.log("[xBind] React Native runtime initialized:",{platform:detectPlatform(),crypto:e.subtle?"full":"basic",storage:"AsyncStorage",prefix:t.storagePrefix||"@xbind:"}),(0,shared_1.ok)(void 0)):(0,shared_1.err)(new Error("No crypto implementation found. Install react-native-quick-crypto or expo-crypto."))}catch(t){return(0,shared_1.err)(new Error(`React Native initialization failed: ${t}`))}}exports.BufferPolyfill=BufferPolyfill,exports.default={AsyncStorageAdapter:AsyncStorageAdapter,detectCrypto:detectCrypto,getRandomBytes:getRandomBytes,sha256:sha256,BufferPolyfill:BufferPolyfill,isReactNative:isReactNative,detectPlatform:detectPlatform,initializeReactNative:initializeReactNative};
1
+ "use strict";
2
+ /**
3
+ * React Native Runtime Support for xBind
4
+ *
5
+ * Provides compatibility layer for React Native environments:
6
+ * - Polyfills for missing Node.js APIs
7
+ * - AsyncStorage adapter for persistence
8
+ * - Native crypto module integration
9
+ * - Cross-platform crypto primitives
10
+ *
11
+ * @module runtime/react-native
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.BufferPolyfill = exports.AsyncStorageAdapter = void 0;
15
+ exports.detectCrypto = detectCrypto;
16
+ exports.getRandomBytes = getRandomBytes;
17
+ exports.sha256 = sha256;
18
+ exports.isReactNative = isReactNative;
19
+ exports.detectPlatform = detectPlatform;
20
+ exports.initializeReactNative = initializeReactNative;
21
+ const shared_1 = require("../../_deps/shared/index.js");
22
+ /* ── Storage Adapter ── */
23
+ /**
24
+ * AsyncStorage adapter for xBind persistence
25
+ *
26
+ * Provides cross-platform storage for:
27
+ * - Agent identities (Ed25519/X25519 keys)
28
+ * - Nonce store (replay protection)
29
+ * - Trust registry cache
30
+ * - Connection metadata
31
+ */
32
+ class AsyncStorageAdapter {
33
+ storage;
34
+ prefix;
35
+ debug;
36
+ constructor(config) {
37
+ this.storage = config.storage;
38
+ this.prefix = config.storagePrefix || '@xbind:';
39
+ this.debug = config.debug || false;
40
+ }
41
+ /**
42
+ * Get value by key
43
+ */
44
+ async get(key) {
45
+ try {
46
+ const prefixedKey = this.prefix + key;
47
+ const value = await this.storage.getItem(prefixedKey);
48
+ if (this.debug) {
49
+ console.log(`[AsyncStorage] GET ${prefixedKey}:`, value ? 'found' : 'not found');
50
+ }
51
+ return (0, shared_1.ok)(value);
52
+ }
53
+ catch (error) {
54
+ return (0, shared_1.err)(new Error(`AsyncStorage get failed: ${error}`));
55
+ }
56
+ }
57
+ /**
58
+ * Set key-value pair
59
+ */
60
+ async set(key, value) {
61
+ try {
62
+ const prefixedKey = this.prefix + key;
63
+ await this.storage.setItem(prefixedKey, value);
64
+ if (this.debug) {
65
+ console.log(`[AsyncStorage] SET ${prefixedKey}:`, value.length, 'bytes');
66
+ }
67
+ return (0, shared_1.ok)(undefined);
68
+ }
69
+ catch (error) {
70
+ return (0, shared_1.err)(new Error(`AsyncStorage set failed: ${error}`));
71
+ }
72
+ }
73
+ /**
74
+ * Remove key
75
+ */
76
+ async remove(key) {
77
+ try {
78
+ const prefixedKey = this.prefix + key;
79
+ await this.storage.removeItem(prefixedKey);
80
+ if (this.debug) {
81
+ console.log(`[AsyncStorage] REMOVE ${prefixedKey}`);
82
+ }
83
+ return (0, shared_1.ok)(undefined);
84
+ }
85
+ catch (error) {
86
+ return (0, shared_1.err)(new Error(`AsyncStorage remove failed: ${error}`));
87
+ }
88
+ }
89
+ /**
90
+ * Get all keys with prefix
91
+ */
92
+ async keys() {
93
+ try {
94
+ const allKeys = await this.storage.getAllKeys();
95
+ const filteredKeys = allKeys
96
+ .filter(key => key.startsWith(this.prefix))
97
+ .map(key => key.substring(this.prefix.length));
98
+ if (this.debug) {
99
+ console.log(`[AsyncStorage] KEYS:`, filteredKeys.length, 'items');
100
+ }
101
+ return (0, shared_1.ok)(filteredKeys);
102
+ }
103
+ catch (error) {
104
+ return (0, shared_1.err)(new Error(`AsyncStorage keys failed: ${error}`));
105
+ }
106
+ }
107
+ /**
108
+ * Get multiple keys (batch operation)
109
+ */
110
+ async multiGet(keys) {
111
+ try {
112
+ const prefixedKeys = keys.map(key => this.prefix + key);
113
+ const results = await this.storage.multiGet(prefixedKeys);
114
+ // Remove prefix from results
115
+ const unprefixedResults = results.map(([key, value]) => [
116
+ key.substring(this.prefix.length),
117
+ value
118
+ ]);
119
+ if (this.debug) {
120
+ console.log(`[AsyncStorage] MULTI_GET:`, keys.length, 'keys');
121
+ }
122
+ return (0, shared_1.ok)(unprefixedResults);
123
+ }
124
+ catch (error) {
125
+ return (0, shared_1.err)(new Error(`AsyncStorage multiGet failed: ${error}`));
126
+ }
127
+ }
128
+ /**
129
+ * Set multiple key-value pairs (batch operation)
130
+ */
131
+ async multiSet(pairs) {
132
+ try {
133
+ const prefixedPairs = pairs.map(([key, value]) => [
134
+ this.prefix + key,
135
+ value
136
+ ]);
137
+ await this.storage.multiSet(prefixedPairs);
138
+ if (this.debug) {
139
+ console.log(`[AsyncStorage] MULTI_SET:`, pairs.length, 'pairs');
140
+ }
141
+ return (0, shared_1.ok)(undefined);
142
+ }
143
+ catch (error) {
144
+ return (0, shared_1.err)(new Error(`AsyncStorage multiSet failed: ${error}`));
145
+ }
146
+ }
147
+ /**
148
+ * Clear all xBind data
149
+ */
150
+ async clear() {
151
+ try {
152
+ const keysResult = await this.keys();
153
+ if (!keysResult.ok) {
154
+ return (0, shared_1.err)(keysResult.error);
155
+ }
156
+ const prefixedKeys = keysResult.value.map((key) => this.prefix + key);
157
+ if (prefixedKeys.length > 0) {
158
+ await this.storage.multiRemove(prefixedKeys);
159
+ }
160
+ if (this.debug) {
161
+ console.log(`[AsyncStorage] CLEAR:`, prefixedKeys.length, 'items removed');
162
+ }
163
+ return (0, shared_1.ok)(undefined);
164
+ }
165
+ catch (error) {
166
+ return (0, shared_1.err)(new Error(`AsyncStorage clear failed: ${error}`));
167
+ }
168
+ }
169
+ }
170
+ exports.AsyncStorageAdapter = AsyncStorageAdapter;
171
+ /* ── Crypto Polyfills ── */
172
+ /**
173
+ * Detect available crypto implementation
174
+ */
175
+ function detectCrypto() {
176
+ // Check for global crypto (React Native 0.63+)
177
+ if (typeof global !== 'undefined' && global.crypto) {
178
+ return global.crypto;
179
+ }
180
+ // Check for react-native-quick-crypto
181
+ try {
182
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
183
+ const quickCrypto = require('react-native-quick-crypto');
184
+ return quickCrypto;
185
+ }
186
+ catch {
187
+ // Not available
188
+ }
189
+ // Check for expo-crypto
190
+ try {
191
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
192
+ const expoCrypto = require('expo-crypto');
193
+ return {
194
+ getRandomValues: (array) => {
195
+ const bytes = expoCrypto.getRandomBytes(array.length);
196
+ array.set(bytes);
197
+ }
198
+ };
199
+ }
200
+ catch {
201
+ // Not available
202
+ }
203
+ return null;
204
+ }
205
+ /**
206
+ * Get random bytes (cross-platform)
207
+ */
208
+ function getRandomBytes(length, crypto) {
209
+ const cryptoImpl = crypto || detectCrypto();
210
+ if (!cryptoImpl) {
211
+ throw new Error('No crypto implementation available. Install react-native-quick-crypto or expo-crypto.');
212
+ }
213
+ const array = new Uint8Array(length);
214
+ cryptoImpl.getRandomValues(array);
215
+ return array;
216
+ }
217
+ /**
218
+ * SHA-256 hash (cross-platform)
219
+ */
220
+ async function sha256(data, crypto) {
221
+ const cryptoImpl = crypto || detectCrypto();
222
+ if (!cryptoImpl?.subtle) {
223
+ throw new Error('No SubtleCrypto implementation available. Install react-native-quick-crypto.');
224
+ }
225
+ // SAFETY: Create clean ArrayBuffer for Web Crypto API compatibility
226
+ const cleanBuffer = new Uint8Array(data).buffer;
227
+ const hash = await cryptoImpl.subtle.digest('SHA-256', cleanBuffer);
228
+ return new Uint8Array(hash);
229
+ }
230
+ /* ── Buffer Polyfill ── */
231
+ /**
232
+ * Buffer polyfill for React Native
233
+ *
234
+ * Uses global Buffer if available, otherwise provides minimal implementation
235
+ */
236
+ class BufferPolyfill {
237
+ static isBuffer(obj) {
238
+ return obj instanceof Uint8Array;
239
+ }
240
+ static from(data, encoding) {
241
+ if (typeof data === 'string') {
242
+ if (encoding === 'base64') {
243
+ return this.fromBase64(data);
244
+ }
245
+ else if (encoding === 'hex') {
246
+ return this.fromHex(data);
247
+ }
248
+ else {
249
+ // Default to UTF-8
250
+ const encoder = new TextEncoder();
251
+ return encoder.encode(data);
252
+ }
253
+ }
254
+ if (Array.isArray(data)) {
255
+ return new Uint8Array(data);
256
+ }
257
+ return new Uint8Array(data);
258
+ }
259
+ static toString(buffer, encoding) {
260
+ if (encoding === 'base64') {
261
+ return this.toBase64(buffer);
262
+ }
263
+ else if (encoding === 'hex') {
264
+ return this.toHex(buffer);
265
+ }
266
+ else {
267
+ // Default to UTF-8
268
+ const decoder = new TextDecoder();
269
+ return decoder.decode(buffer);
270
+ }
271
+ }
272
+ static concat(buffers) {
273
+ const totalLength = buffers.reduce((sum, buf) => sum + buf.length, 0);
274
+ const result = new Uint8Array(totalLength);
275
+ let offset = 0;
276
+ for (const buf of buffers) {
277
+ result.set(buf, offset);
278
+ offset += buf.length;
279
+ }
280
+ return result;
281
+ }
282
+ static alloc(size, fill) {
283
+ const buffer = new Uint8Array(size);
284
+ if (fill !== undefined) {
285
+ buffer.fill(fill);
286
+ }
287
+ return buffer;
288
+ }
289
+ static fromBase64(str) {
290
+ const binaryString = atob(str);
291
+ const bytes = new Uint8Array(binaryString.length);
292
+ for (let i = 0; i < binaryString.length; i++) {
293
+ bytes[i] = binaryString.charCodeAt(i);
294
+ }
295
+ return bytes;
296
+ }
297
+ static toBase64(buffer) {
298
+ let binaryString = '';
299
+ for (let i = 0; i < buffer.length; i++) {
300
+ const byte = buffer[i];
301
+ if (byte !== undefined) {
302
+ binaryString += String.fromCharCode(byte);
303
+ }
304
+ }
305
+ return btoa(binaryString);
306
+ }
307
+ static fromHex(str) {
308
+ const bytes = new Uint8Array(str.length / 2);
309
+ for (let i = 0; i < bytes.length; i++) {
310
+ bytes[i] = parseInt(str.substr(i * 2, 2), 16);
311
+ }
312
+ return bytes;
313
+ }
314
+ static toHex(buffer) {
315
+ return Array.from(buffer)
316
+ .map(b => b.toString(16).padStart(2, '0'))
317
+ .join('');
318
+ }
319
+ }
320
+ exports.BufferPolyfill = BufferPolyfill;
321
+ /* ── Platform Detection ── */
322
+ /**
323
+ * Detect React Native runtime
324
+ */
325
+ function isReactNative() {
326
+ return (typeof navigator !== 'undefined' &&
327
+ navigator.product === 'ReactNative');
328
+ }
329
+ /**
330
+ * Detect platform (iOS/Android)
331
+ */
332
+ function detectPlatform() {
333
+ if (typeof navigator === 'undefined') {
334
+ return 'unknown';
335
+ }
336
+ const userAgent = navigator.userAgent || '';
337
+ if (/iPhone|iPad|iPod/.test(userAgent)) {
338
+ return 'ios';
339
+ }
340
+ if (/Android/.test(userAgent)) {
341
+ return 'android';
342
+ }
343
+ return 'unknown';
344
+ }
345
+ /* ── Module Initialization ── */
346
+ /**
347
+ * Initialize React Native runtime environment
348
+ *
349
+ * Sets up polyfills and validates required dependencies
350
+ */
351
+ function initializeReactNative(config) {
352
+ try {
353
+ // Validate storage
354
+ if (!config.storage) {
355
+ return (0, shared_1.err)(new Error('AsyncStorage is required for React Native runtime'));
356
+ }
357
+ // Validate crypto
358
+ const crypto = config.crypto || detectCrypto();
359
+ if (!crypto) {
360
+ return (0, shared_1.err)(new Error('No crypto implementation found. Install react-native-quick-crypto or expo-crypto.'));
361
+ }
362
+ // Ensure global.crypto is available
363
+ if (!global.crypto) {
364
+ global.crypto = crypto;
365
+ }
366
+ // Ensure global.Buffer is available
367
+ if (!global.Buffer) {
368
+ global.Buffer = BufferPolyfill;
369
+ }
370
+ if (config.debug) {
371
+ console.log('[xBind] React Native runtime initialized:', {
372
+ platform: detectPlatform(),
373
+ crypto: !!crypto.subtle ? 'full' : 'basic',
374
+ storage: 'AsyncStorage',
375
+ prefix: config.storagePrefix || '@xbind:'
376
+ });
377
+ }
378
+ return (0, shared_1.ok)(undefined);
379
+ }
380
+ catch (error) {
381
+ return (0, shared_1.err)(new Error(`React Native initialization failed: ${error}`));
382
+ }
383
+ }
384
+ /* ── Exports ── */
385
+ exports.default = {
386
+ AsyncStorageAdapter,
387
+ detectCrypto,
388
+ getRandomBytes,
389
+ sha256,
390
+ BufferPolyfill,
391
+ isReactNative,
392
+ detectPlatform,
393
+ initializeReactNative
394
+ };
@@ -1 +1,245 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DefaultSecurityPolicy=void 0,exports.describeSecurityMode=describeSecurityMode,exports.describeSecurityModeStructured=describeSecurityModeStructured;class DefaultSecurityPolicy{options;constructor(e={}){this.options=e}classify(e){const{action:r,params:t,securityOverride:s}=e,i=this.options.highValueThreshold??1e5,a=this.options.criticalValueThreshold??1e6;if("critical"===s)return{mode:{type:"split",shares:5,threshold:3},reason:"User requested critical security level (5 shares, 3-of-5 threshold)",wasOverridden:!0};if("high"===s)return{mode:{type:"split",shares:3,threshold:2},reason:"User requested high security level (3 shares, 2-of-3 threshold)",wasOverridden:!0};if("standard"===s)return{mode:{type:"standard"},reason:"User requested standard security level (encrypted transport)",wasOverridden:!0};const o="string"==typeof t.risk?t.risk.toLowerCase():void 0;if(o){if("critical"===o||"high"===o)return{mode:{type:"split",shares:5,threshold:3},reason:`Explicit risk tag "${o}" requires 3-of-5 threshold`,wasOverridden:!1};if("medium"===o)return{mode:{type:"split",shares:3,threshold:2},reason:'Explicit risk tag "medium" requires 2-of-3 threshold',wasOverridden:!1};if("low"===o)return{mode:{type:"split",shares:2,threshold:2},reason:'Explicit risk tag "low" requires 2-of-2 threshold',wasOverridden:!1}}if(("transfer"===r||"execute"===r)&&"number"==typeof t.amount){const e="string"==typeof t.currency?t.currency.toUpperCase():"USD";if(["USD","EUR","GBP"].includes(e)){if(t.amount>=a)return{mode:{type:"split",shares:5,threshold:3},reason:`Critical-value transfer (${e} ${t.amount.toLocaleString()}) requires 3-of-5 threshold`,wasOverridden:!1};if(t.amount>=i)return{mode:{type:"split",shares:3,threshold:2},reason:`High-value transfer (${e} ${t.amount.toLocaleString()}) requires 2-of-3 threshold`,wasOverridden:!1}}}return!0===t.crossEntity?{mode:{type:"split",shares:3,threshold:2},reason:"Cross-organization communication requires multi-party approval (2 of 3)",wasOverridden:!1}:e.scope.includes("admin")||e.scope.includes("custody")||e.scope.includes("settlement")?{mode:{type:"split",shares:3,threshold:2},reason:`Sensitive scope "${e.scope}" requires multi-party approval (2 of 3)`,wasOverridden:!1}:this.options.enableXchange&&!0===t.xchange?{mode:{type:"xchange"},reason:"Xchange mode enabled for performance (~180x faster)",wasOverridden:!1}:{mode:{type:"standard"},reason:"Standard encrypted transport (hybrid post-quantum)",wasOverridden:!1}}}function describeSecurityMode(e){switch(e.type){case"standard":return"Standard (encrypted)";case"split":return`Multi-party approval (${e.threshold} of ${e.shares})`;case"xchange":return"Xchange (fast mode)"}}function describeSecurityModeStructured(e){let r,t,s,i,a;switch(e.type){case"standard":r="standard",t="Security Level: Standard\nMode: Encrypted transport (hybrid post-quantum)",s="standard | encrypted",i="**Security Level:** Standard\n\n**Mode:** Encrypted transport (hybrid post-quantum)";break;case"split":r=e.shares>=5?"critical":"high",a={total:e.shares,threshold:e.threshold},t=`Security Level: ${"critical"===r?"Critical":"High"}\nMode: Split-channel (XorIDA)\nShares: ${e.shares} total, ${e.threshold} required`,s=`${r} | split | ${e.threshold}-of-${e.shares}`,i=`**Security Level:** ${"critical"===r?"Critical":"High"}\n\n**Mode:** Split-channel (XorIDA)\n\n**Shares:** ${e.shares} total, ${e.threshold} required`;break;case"xchange":r="performance",t="Security Level: Performance\nMode: Xchange (single IT layer, ~180x faster)",s="performance | xchange",i="**Security Level:** Performance\n\n**Mode:** Xchange (single IT layer, ~180x faster)"}const o={type:e.type,level:r};a&&(o.shares=a);const n=JSON.stringify(o);return{type:e.type,level:r,shares:a,formats:{multiline:t,singleline:s,json:n,markdown:i}}}exports.DefaultSecurityPolicy=DefaultSecurityPolicy;
1
+ "use strict";
2
+ /**
3
+ * Security policy interface for automatic risk-based Xorida activation.
4
+ *
5
+ * Determines when to apply information-theoretic security (XorIDA split-channel)
6
+ * vs standard encrypted transport based on action semantics and parameters.
7
+ *
8
+ * Design principle: Security should be invisible to users. The policy classifies
9
+ * risk automatically so developers don't need to understand threshold cryptography.
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.DefaultSecurityPolicy = void 0;
13
+ exports.describeSecurityMode = describeSecurityMode;
14
+ exports.describeSecurityModeStructured = describeSecurityModeStructured;
15
+ /**
16
+ * Default security policy for basic XBind.
17
+ *
18
+ * Rules:
19
+ * - Explicit risk tags: low → 2-of-2, medium → 2-of-3, high/critical → 3-of-5
20
+ * - Fiat transfers: USD/EUR/GBP >$100k → 2-of-3, >$1M → 3-of-5
21
+ * - Crypto transfers: Require explicit risk tag (no numeric auto-detection)
22
+ * - Sensitive scopes: custody/admin/settlement → 2-of-3
23
+ * - Cross-entity communication: 2-of-3
24
+ * - Explicit 'high' override: 2-of-3, 'critical' override: 3-of-5
25
+ * - Everything else: Standard encrypted transport (V3 hybrid PQ)
26
+ *
27
+ * Enterprise and Government variants extend this with custom rules.
28
+ */
29
+ class DefaultSecurityPolicy {
30
+ options;
31
+ /**
32
+ * Create a default security policy.
33
+ *
34
+ * @param options - Optional configuration
35
+ * @param options.highValueThreshold - Amount threshold for high security (default: 100000)
36
+ * @param options.criticalValueThreshold - Amount threshold for critical security (default: 1000000)
37
+ * @param options.enableXchange - Allow Xchange mode for performance (default: false)
38
+ */
39
+ constructor(options = {}) {
40
+ this.options = options;
41
+ }
42
+ classify(context) {
43
+ const { action, params, securityOverride } = context;
44
+ const highThreshold = this.options.highValueThreshold ?? 100_000;
45
+ const criticalThreshold = this.options.criticalValueThreshold ?? 1_000_000;
46
+ // Explicit override: critical
47
+ if (securityOverride === 'critical') {
48
+ return {
49
+ mode: { type: 'split', shares: 5, threshold: 3 },
50
+ reason: 'User requested critical security level (5 shares, 3-of-5 threshold)',
51
+ wasOverridden: true,
52
+ };
53
+ }
54
+ // Explicit override: high
55
+ if (securityOverride === 'high') {
56
+ return {
57
+ mode: { type: 'split', shares: 3, threshold: 2 },
58
+ reason: 'User requested high security level (3 shares, 2-of-3 threshold)',
59
+ wasOverridden: true,
60
+ };
61
+ }
62
+ // Explicit override: standard
63
+ if (securityOverride === 'standard') {
64
+ return {
65
+ mode: { type: 'standard' },
66
+ reason: 'User requested standard security level (encrypted transport)',
67
+ wasOverridden: true,
68
+ };
69
+ }
70
+ // Risk tag detection (preferred for crypto: BTC, ETH, etc.)
71
+ const riskTag = typeof params.risk === 'string' ? params.risk.toLowerCase() : undefined;
72
+ if (riskTag) {
73
+ if (riskTag === 'critical' || riskTag === 'high') {
74
+ return {
75
+ mode: { type: 'split', shares: 5, threshold: 3 },
76
+ reason: `Explicit risk tag "${riskTag}" requires 3-of-5 threshold`,
77
+ wasOverridden: false,
78
+ };
79
+ }
80
+ else if (riskTag === 'medium') {
81
+ return {
82
+ mode: { type: 'split', shares: 3, threshold: 2 },
83
+ reason: `Explicit risk tag "medium" requires 2-of-3 threshold`,
84
+ wasOverridden: false,
85
+ };
86
+ }
87
+ else if (riskTag === 'low') {
88
+ return {
89
+ mode: { type: 'split', shares: 2, threshold: 2 },
90
+ reason: `Explicit risk tag "low" requires 2-of-2 threshold`,
91
+ wasOverridden: false,
92
+ };
93
+ }
94
+ }
95
+ // Numeric thresholds ONLY for fiat currencies (USD, EUR, GBP)
96
+ // Crypto (BTC, ETH) should use risk tags instead
97
+ if ((action === 'transfer' || action === 'execute') && typeof params.amount === 'number') {
98
+ const currency = typeof params.currency === 'string' ? params.currency.toUpperCase() : 'USD';
99
+ const isFiat = ['USD', 'EUR', 'GBP'].includes(currency);
100
+ if (isFiat) {
101
+ if (params.amount >= criticalThreshold) {
102
+ return {
103
+ mode: { type: 'split', shares: 5, threshold: 3 },
104
+ reason: `Critical-value transfer (${currency} ${params.amount.toLocaleString()}) requires 3-of-5 threshold`,
105
+ wasOverridden: false,
106
+ };
107
+ }
108
+ else if (params.amount >= highThreshold) {
109
+ return {
110
+ mode: { type: 'split', shares: 3, threshold: 2 },
111
+ reason: `High-value transfer (${currency} ${params.amount.toLocaleString()}) requires 2-of-3 threshold`,
112
+ wasOverridden: false,
113
+ };
114
+ }
115
+ }
116
+ }
117
+ // Auto-detection: Cross-entity communication
118
+ if (params.crossEntity === true) {
119
+ return {
120
+ mode: { type: 'split', shares: 3, threshold: 2 },
121
+ reason: 'Cross-organization communication requires multi-party approval (2 of 3)',
122
+ wasOverridden: false,
123
+ };
124
+ }
125
+ // Auto-detection: Sensitive scopes
126
+ if (context.scope.includes('admin') ||
127
+ context.scope.includes('custody') ||
128
+ context.scope.includes('settlement')) {
129
+ return {
130
+ mode: { type: 'split', shares: 3, threshold: 2 },
131
+ reason: `Sensitive scope "${context.scope}" requires multi-party approval (2 of 3)`,
132
+ wasOverridden: false,
133
+ };
134
+ }
135
+ // Xchange mode: opt-in performance mode (if enabled)
136
+ if (this.options.enableXchange && params.xchange === true) {
137
+ return {
138
+ mode: { type: 'xchange' },
139
+ reason: 'Xchange mode enabled for performance (~180x faster)',
140
+ wasOverridden: false,
141
+ };
142
+ }
143
+ // Default: Standard encrypted transport
144
+ return {
145
+ mode: { type: 'standard' },
146
+ reason: 'Standard encrypted transport (hybrid post-quantum)',
147
+ wasOverridden: false,
148
+ };
149
+ }
150
+ }
151
+ exports.DefaultSecurityPolicy = DefaultSecurityPolicy;
152
+ /**
153
+ * Get a human-readable security mode description.
154
+ *
155
+ * Used for logging and user feedback.
156
+ *
157
+ * @param mode - Security mode
158
+ * @returns User-friendly description
159
+ *
160
+ * @deprecated Use describeSecurityModeStructured() for new code. This function remains for backward compatibility.
161
+ */
162
+ function describeSecurityMode(mode) {
163
+ switch (mode.type) {
164
+ case 'standard':
165
+ return 'Standard (encrypted)';
166
+ case 'split':
167
+ return `Multi-party approval (${mode.threshold} of ${mode.shares})`;
168
+ case 'xchange':
169
+ return 'Xchange (fast mode)';
170
+ }
171
+ }
172
+ /**
173
+ * Get a structured security mode description with multiple formats.
174
+ *
175
+ * Returns an object with the security classification and formatted descriptions
176
+ * optimized for different use cases (display, logging, APIs, docs).
177
+ *
178
+ * @param mode - Security mode
179
+ * @returns Security mode description with formats
180
+ *
181
+ * @example
182
+ * ```typescript
183
+ * const mode: SecurityMode = { type: 'split', shares: 3, threshold: 2 };
184
+ * const description = describeSecurityModeStructured(mode);
185
+ *
186
+ * console.log(description.formats.singleline);
187
+ * // "high | split | 2-of-3"
188
+ *
189
+ * console.log(description.formats.multiline);
190
+ * // "Security Level: High
191
+ * // Mode: Split-channel (XorIDA)
192
+ * // Shares: 3 total, 2 required"
193
+ *
194
+ * console.log(description.shares);
195
+ * // { total: 3, threshold: 2 }
196
+ * ```
197
+ */
198
+ function describeSecurityModeStructured(mode) {
199
+ let level;
200
+ let multiline;
201
+ let singleline;
202
+ let markdown;
203
+ let shares;
204
+ switch (mode.type) {
205
+ case 'standard':
206
+ level = 'standard';
207
+ multiline = 'Security Level: Standard\nMode: Encrypted transport (hybrid post-quantum)';
208
+ singleline = 'standard | encrypted';
209
+ markdown = '**Security Level:** Standard\n\n**Mode:** Encrypted transport (hybrid post-quantum)';
210
+ break;
211
+ case 'split':
212
+ // Classify split mode as high or critical based on threshold
213
+ level = mode.shares >= 5 ? 'critical' : 'high';
214
+ shares = { total: mode.shares, threshold: mode.threshold };
215
+ multiline = `Security Level: ${level === 'critical' ? 'Critical' : 'High'}\nMode: Split-channel (XorIDA)\nShares: ${mode.shares} total, ${mode.threshold} required`;
216
+ singleline = `${level} | split | ${mode.threshold}-of-${mode.shares}`;
217
+ markdown = `**Security Level:** ${level === 'critical' ? 'Critical' : 'High'}\n\n**Mode:** Split-channel (XorIDA)\n\n**Shares:** ${mode.shares} total, ${mode.threshold} required`;
218
+ break;
219
+ case 'xchange':
220
+ level = 'performance';
221
+ multiline = 'Security Level: Performance\nMode: Xchange (single IT layer, ~180x faster)';
222
+ singleline = 'performance | xchange';
223
+ markdown = '**Security Level:** Performance\n\n**Mode:** Xchange (single IT layer, ~180x faster)';
224
+ break;
225
+ }
226
+ const jsonObj = {
227
+ type: mode.type,
228
+ level,
229
+ };
230
+ if (shares) {
231
+ jsonObj.shares = shares;
232
+ }
233
+ const json = JSON.stringify(jsonObj);
234
+ return {
235
+ type: mode.type,
236
+ level,
237
+ shares,
238
+ formats: {
239
+ multiline,
240
+ singleline,
241
+ json,
242
+ markdown,
243
+ },
244
+ };
245
+ }