shogun-core 6.2.4 → 6.3.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 (233) hide show
  1. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js +93 -341
  2. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js.map +1 -1
  3. package/dist/browser/shogun-core.js +138979 -146789
  4. package/dist/browser/shogun-core.js.map +1 -1
  5. package/dist/{core.js → src/core.js} +167 -107
  6. package/dist/src/crypto/asymmetric.js +168 -0
  7. package/dist/src/crypto/double-ratchet.js +908 -0
  8. package/dist/src/crypto/file-encryption.js +352 -0
  9. package/dist/src/crypto/hashing.js +160 -0
  10. package/dist/src/crypto/index.js +18 -0
  11. package/dist/{crypto → src/crypto}/mls-codec.js +24 -34
  12. package/dist/src/crypto/mls.js +734 -0
  13. package/dist/src/crypto/pgp.js +619 -0
  14. package/dist/{crypto → src/crypto}/random-generation.js +125 -103
  15. package/dist/src/crypto/sframe.js +466 -0
  16. package/dist/src/crypto/signal-protocol.js +943 -0
  17. package/dist/src/crypto/symmetric.js +165 -0
  18. package/dist/src/crypto/utils.js +220 -0
  19. package/dist/src/examples/auth-test.js +535 -0
  20. package/dist/src/examples/crypto-identity-example.js +294 -0
  21. package/dist/src/examples/crypto-working-test.js +149 -0
  22. package/dist/src/examples/double-ratchet-test.js +240 -0
  23. package/dist/src/examples/mls-3-member-test.js +183 -0
  24. package/dist/src/examples/mls-multi-member.js +439 -0
  25. package/dist/src/examples/mls-sframe-test.js +491 -0
  26. package/dist/src/examples/mls-simple-test.js +122 -0
  27. package/dist/src/examples/pgp-example.js +354 -0
  28. package/dist/src/examples/random-generation-test.js +191 -0
  29. package/dist/src/examples/shogun-core-example.js +204 -0
  30. package/dist/src/examples/signal-protocol-test.js +82 -0
  31. package/dist/src/examples/zkproof-credentials-example.js +357 -0
  32. package/dist/src/examples/zkproof-example.js +357 -0
  33. package/dist/src/gundb/crypto.js +420 -0
  34. package/dist/src/gundb/db.js +728 -0
  35. package/dist/src/gundb/derive.js +327 -0
  36. package/dist/src/gundb/errors.js +115 -0
  37. package/dist/src/gundb/gun-es.js +8 -0
  38. package/dist/src/gundb/index.js +5 -0
  39. package/dist/{gundb → src/gundb}/rxjs.js +147 -111
  40. package/dist/{gundb → src/gundb}/types.js +1 -2
  41. package/dist/src/index.js +19 -0
  42. package/dist/src/interfaces/events.js +57 -0
  43. package/dist/{interfaces → src/interfaces}/shogun.js +4 -7
  44. package/dist/src/managers/AuthManager.js +301 -0
  45. package/dist/src/managers/CoreInitializer.js +304 -0
  46. package/dist/src/managers/CryptoIdentityManager.js +230 -0
  47. package/dist/{managers → src/managers}/EventManager.js +19 -21
  48. package/dist/{managers → src/managers}/PluginManager.js +123 -89
  49. package/dist/src/plugins/base.js +90 -0
  50. package/dist/src/plugins/index.js +17 -0
  51. package/dist/src/plugins/nostr/index.js +4 -0
  52. package/dist/src/plugins/nostr/nostrConnector.js +539 -0
  53. package/dist/src/plugins/nostr/nostrConnectorPlugin.js +663 -0
  54. package/dist/src/plugins/nostr/nostrSigner.js +414 -0
  55. package/dist/src/plugins/smartwallet/index.js +2 -0
  56. package/dist/src/plugins/smartwallet/smartWalletPlugin.js +824 -0
  57. package/dist/src/plugins/web3/index.js +4 -0
  58. package/dist/src/plugins/web3/types.js +1 -0
  59. package/dist/src/plugins/web3/web3Connector.js +738 -0
  60. package/dist/src/plugins/web3/web3ConnectorPlugin.js +639 -0
  61. package/dist/src/plugins/web3/web3Signer.js +432 -0
  62. package/dist/src/plugins/webauthn/index.js +3 -0
  63. package/dist/{plugins → src/plugins}/webauthn/types.js +2 -5
  64. package/dist/src/plugins/webauthn/webauthn.js +647 -0
  65. package/dist/src/plugins/webauthn/webauthnPlugin.js +689 -0
  66. package/dist/src/plugins/webauthn/webauthnSigner.js +419 -0
  67. package/dist/{plugins → src/plugins}/zkproof/index.js +3 -10
  68. package/dist/src/plugins/zkproof/types.js +1 -0
  69. package/dist/src/plugins/zkproof/zkCredentials.js +287 -0
  70. package/dist/src/plugins/zkproof/zkProofConnector.js +267 -0
  71. package/dist/src/plugins/zkproof/zkProofPlugin.js +405 -0
  72. package/dist/src/storage/storage.js +189 -0
  73. package/dist/src/utils/errorHandler.js +339 -0
  74. package/dist/{utils → src/utils}/eventEmitter.js +26 -26
  75. package/dist/{utils → src/utils}/seedPhrase.js +23 -32
  76. package/dist/{utils → src/utils}/validation.js +14 -21
  77. package/dist/tsconfig.tsbuildinfo +1 -0
  78. package/dist/types/{crypto → src/crypto}/double-ratchet.d.ts +1 -1
  79. package/dist/types/{crypto → src/crypto}/signal-protocol.d.ts +25 -0
  80. package/dist/types/{crypto → src/crypto}/types.d.ts +3 -1
  81. package/dist/types/src/examples/crypto-working-test.d.ts +1 -0
  82. package/dist/types/src/examples/double-ratchet-test.d.ts +1 -0
  83. package/dist/types/src/examples/mls-sframe-test.d.ts +1 -0
  84. package/dist/types/src/examples/random-generation-test.d.ts +1 -0
  85. package/dist/types/src/examples/signal-protocol-test.d.ts +1 -0
  86. package/dist/types/{gundb → src/gundb}/db.d.ts +14 -1
  87. package/dist/types/src/gundb/gun-es.d.ts +8 -0
  88. package/dist/types/src/gundb/min.d.ts +3 -0
  89. package/dist/types/{index.d.ts → src/index.d.ts} +1 -0
  90. package/package.json +14 -11
  91. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_curve_js-node_modules_noble_curves_esm_-1ce4ed.shogun-core.js +0 -1651
  92. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_curve_js-node_modules_noble_curves_esm_-1ce4ed.shogun-core.js.map +0 -1
  93. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_nist_js.shogun-core.js +0 -1608
  94. package/dist/browser/defaultVendors-node_modules_noble_curves_esm_nist_js.shogun-core.js.map +0 -1
  95. package/dist/crypto/asymmetric.js +0 -99
  96. package/dist/crypto/double-ratchet.js +0 -392
  97. package/dist/crypto/file-encryption.js +0 -213
  98. package/dist/crypto/hashing.js +0 -87
  99. package/dist/crypto/index.js +0 -34
  100. package/dist/crypto/mls.js +0 -569
  101. package/dist/crypto/pgp.js +0 -390
  102. package/dist/crypto/sframe.js +0 -352
  103. package/dist/crypto/signal-protocol.js +0 -456
  104. package/dist/crypto/symmetric.js +0 -91
  105. package/dist/crypto/types.js +0 -2
  106. package/dist/crypto/utils.js +0 -140
  107. package/dist/examples/auth-test.js +0 -453
  108. package/dist/examples/crypto-identity-example.js +0 -196
  109. package/dist/examples/crypto-working-test.js +0 -83
  110. package/dist/examples/double-ratchet-test.js +0 -155
  111. package/dist/examples/mls-3-member-test.js +0 -97
  112. package/dist/examples/mls-multi-member.js +0 -153
  113. package/dist/examples/mls-sframe-test.js +0 -307
  114. package/dist/examples/mls-simple-test.js +0 -58
  115. package/dist/examples/pgp-example.js +0 -200
  116. package/dist/examples/random-generation-test.js +0 -151
  117. package/dist/examples/shogun-core-example.js +0 -150
  118. package/dist/examples/signal-protocol-test.js +0 -38
  119. package/dist/examples/zkproof-credentials-example.js +0 -217
  120. package/dist/examples/zkproof-example.js +0 -242
  121. package/dist/gundb/crypto.js +0 -306
  122. package/dist/gundb/db.js +0 -485
  123. package/dist/gundb/derive.js +0 -232
  124. package/dist/gundb/errors.js +0 -76
  125. package/dist/gundb/gun-es.js +0 -12
  126. package/dist/gundb/index.js +0 -21
  127. package/dist/gundb/min.js +0 -10
  128. package/dist/index.esm.js +0 -22
  129. package/dist/index.js +0 -47
  130. package/dist/interfaces/common.js +0 -2
  131. package/dist/interfaces/events.js +0 -40
  132. package/dist/interfaces/plugin.js +0 -2
  133. package/dist/managers/AuthManager.js +0 -226
  134. package/dist/managers/CoreInitializer.js +0 -250
  135. package/dist/managers/CryptoIdentityManager.js +0 -138
  136. package/dist/plugins/base.js +0 -50
  137. package/dist/plugins/index.js +0 -32
  138. package/dist/plugins/nostr/index.js +0 -20
  139. package/dist/plugins/nostr/nostrConnector.js +0 -419
  140. package/dist/plugins/nostr/nostrConnectorPlugin.js +0 -453
  141. package/dist/plugins/nostr/nostrSigner.js +0 -319
  142. package/dist/plugins/nostr/types.js +0 -2
  143. package/dist/plugins/smartwallet/index.js +0 -18
  144. package/dist/plugins/smartwallet/smartWalletPlugin.js +0 -511
  145. package/dist/plugins/smartwallet/types.js +0 -2
  146. package/dist/plugins/web3/index.js +0 -20
  147. package/dist/plugins/web3/types.js +0 -2
  148. package/dist/plugins/web3/web3Connector.js +0 -533
  149. package/dist/plugins/web3/web3ConnectorPlugin.js +0 -455
  150. package/dist/plugins/web3/web3Signer.js +0 -314
  151. package/dist/plugins/webauthn/index.js +0 -19
  152. package/dist/plugins/webauthn/webauthn.js +0 -496
  153. package/dist/plugins/webauthn/webauthnPlugin.js +0 -490
  154. package/dist/plugins/webauthn/webauthnSigner.js +0 -310
  155. package/dist/plugins/zkproof/types.js +0 -2
  156. package/dist/plugins/zkproof/zkCredentials.js +0 -216
  157. package/dist/plugins/zkproof/zkProofConnector.js +0 -198
  158. package/dist/plugins/zkproof/zkProofPlugin.js +0 -272
  159. package/dist/storage/storage.js +0 -145
  160. package/dist/types/gundb/gun-es.d.ts +0 -8
  161. package/dist/utils/errorHandler.js +0 -246
  162. /package/dist/{types/examples/crypto-working-test.d.ts → src/crypto/types.js} +0 -0
  163. /package/dist/{types/gundb/min.d.ts → src/gundb/min.js} +0 -0
  164. /package/dist/{types/examples/double-ratchet-test.d.ts → src/interfaces/common.js} +0 -0
  165. /package/dist/{types/examples/mls-sframe-test.d.ts → src/interfaces/plugin.js} +0 -0
  166. /package/dist/{types/examples/random-generation-test.d.ts → src/plugins/nostr/types.js} +0 -0
  167. /package/dist/{types/examples/signal-protocol-test.d.ts → src/plugins/smartwallet/types.js} +0 -0
  168. /package/dist/types/{core.d.ts → src/core.d.ts} +0 -0
  169. /package/dist/types/{crypto → src/crypto}/asymmetric.d.ts +0 -0
  170. /package/dist/types/{crypto → src/crypto}/file-encryption.d.ts +0 -0
  171. /package/dist/types/{crypto → src/crypto}/hashing.d.ts +0 -0
  172. /package/dist/types/{crypto → src/crypto}/index.d.ts +0 -0
  173. /package/dist/types/{crypto → src/crypto}/mls-codec.d.ts +0 -0
  174. /package/dist/types/{crypto → src/crypto}/mls.d.ts +0 -0
  175. /package/dist/types/{crypto → src/crypto}/pgp.d.ts +0 -0
  176. /package/dist/types/{crypto → src/crypto}/random-generation.d.ts +0 -0
  177. /package/dist/types/{crypto → src/crypto}/sframe.d.ts +0 -0
  178. /package/dist/types/{crypto → src/crypto}/symmetric.d.ts +0 -0
  179. /package/dist/types/{crypto → src/crypto}/utils.d.ts +0 -0
  180. /package/dist/types/{examples → src/examples}/auth-test.d.ts +0 -0
  181. /package/dist/types/{examples → src/examples}/crypto-identity-example.d.ts +0 -0
  182. /package/dist/types/{examples → src/examples}/mls-3-member-test.d.ts +0 -0
  183. /package/dist/types/{examples → src/examples}/mls-multi-member.d.ts +0 -0
  184. /package/dist/types/{examples → src/examples}/mls-simple-test.d.ts +0 -0
  185. /package/dist/types/{examples → src/examples}/pgp-example.d.ts +0 -0
  186. /package/dist/types/{examples → src/examples}/shogun-core-example.d.ts +0 -0
  187. /package/dist/types/{examples → src/examples}/zkproof-credentials-example.d.ts +0 -0
  188. /package/dist/types/{examples → src/examples}/zkproof-example.d.ts +0 -0
  189. /package/dist/types/{gundb → src/gundb}/crypto.d.ts +0 -0
  190. /package/dist/types/{gundb → src/gundb}/derive.d.ts +0 -0
  191. /package/dist/types/{gundb → src/gundb}/errors.d.ts +0 -0
  192. /package/dist/types/{gundb → src/gundb}/index.d.ts +0 -0
  193. /package/dist/types/{gundb → src/gundb}/rxjs.d.ts +0 -0
  194. /package/dist/types/{gundb → src/gundb}/types.d.ts +0 -0
  195. /package/dist/types/{interfaces → src/interfaces}/common.d.ts +0 -0
  196. /package/dist/types/{interfaces → src/interfaces}/events.d.ts +0 -0
  197. /package/dist/types/{interfaces → src/interfaces}/plugin.d.ts +0 -0
  198. /package/dist/types/{interfaces → src/interfaces}/shogun.d.ts +0 -0
  199. /package/dist/types/{managers → src/managers}/AuthManager.d.ts +0 -0
  200. /package/dist/types/{managers → src/managers}/CoreInitializer.d.ts +0 -0
  201. /package/dist/types/{managers → src/managers}/CryptoIdentityManager.d.ts +0 -0
  202. /package/dist/types/{managers → src/managers}/EventManager.d.ts +0 -0
  203. /package/dist/types/{managers → src/managers}/PluginManager.d.ts +0 -0
  204. /package/dist/types/{plugins → src/plugins}/base.d.ts +0 -0
  205. /package/dist/types/{plugins → src/plugins}/index.d.ts +0 -0
  206. /package/dist/types/{plugins → src/plugins}/nostr/index.d.ts +0 -0
  207. /package/dist/types/{plugins → src/plugins}/nostr/nostrConnector.d.ts +0 -0
  208. /package/dist/types/{plugins → src/plugins}/nostr/nostrConnectorPlugin.d.ts +0 -0
  209. /package/dist/types/{plugins → src/plugins}/nostr/nostrSigner.d.ts +0 -0
  210. /package/dist/types/{plugins → src/plugins}/nostr/types.d.ts +0 -0
  211. /package/dist/types/{plugins → src/plugins}/smartwallet/index.d.ts +0 -0
  212. /package/dist/types/{plugins → src/plugins}/smartwallet/smartWalletPlugin.d.ts +0 -0
  213. /package/dist/types/{plugins → src/plugins}/smartwallet/types.d.ts +0 -0
  214. /package/dist/types/{plugins → src/plugins}/web3/index.d.ts +0 -0
  215. /package/dist/types/{plugins → src/plugins}/web3/types.d.ts +0 -0
  216. /package/dist/types/{plugins → src/plugins}/web3/web3Connector.d.ts +0 -0
  217. /package/dist/types/{plugins → src/plugins}/web3/web3ConnectorPlugin.d.ts +0 -0
  218. /package/dist/types/{plugins → src/plugins}/web3/web3Signer.d.ts +0 -0
  219. /package/dist/types/{plugins → src/plugins}/webauthn/index.d.ts +0 -0
  220. /package/dist/types/{plugins → src/plugins}/webauthn/types.d.ts +0 -0
  221. /package/dist/types/{plugins → src/plugins}/webauthn/webauthn.d.ts +0 -0
  222. /package/dist/types/{plugins → src/plugins}/webauthn/webauthnPlugin.d.ts +0 -0
  223. /package/dist/types/{plugins → src/plugins}/webauthn/webauthnSigner.d.ts +0 -0
  224. /package/dist/types/{plugins → src/plugins}/zkproof/index.d.ts +0 -0
  225. /package/dist/types/{plugins → src/plugins}/zkproof/types.d.ts +0 -0
  226. /package/dist/types/{plugins → src/plugins}/zkproof/zkCredentials.d.ts +0 -0
  227. /package/dist/types/{plugins → src/plugins}/zkproof/zkProofConnector.d.ts +0 -0
  228. /package/dist/types/{plugins → src/plugins}/zkproof/zkProofPlugin.d.ts +0 -0
  229. /package/dist/types/{storage → src/storage}/storage.d.ts +0 -0
  230. /package/dist/types/{utils → src/utils}/errorHandler.d.ts +0 -0
  231. /package/dist/types/{utils → src/utils}/eventEmitter.d.ts +0 -0
  232. /package/dist/types/{utils → src/utils}/seedPhrase.d.ts +0 -0
  233. /package/dist/types/{utils → src/utils}/validation.d.ts +0 -0
@@ -0,0 +1,352 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
23
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ var __read = (this && this.__read) || function (o, n) {
49
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
50
+ if (!m) return o;
51
+ var i = m.call(o), r, ar = [], e;
52
+ try {
53
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
54
+ }
55
+ catch (error) { e = { error: error }; }
56
+ finally {
57
+ try {
58
+ if (r && !r.done && (m = i["return"])) m.call(i);
59
+ }
60
+ finally { if (e) throw e.error; }
61
+ }
62
+ return ar;
63
+ };
64
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
65
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
66
+ if (ar || !(i in from)) {
67
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
68
+ ar[i] = from[i];
69
+ }
70
+ }
71
+ return to.concat(ar || Array.prototype.slice.call(from));
72
+ };
73
+ var __values = (this && this.__values) || function(o) {
74
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
75
+ if (m) return m.call(o);
76
+ if (o && typeof o.length === "number") return {
77
+ next: function () {
78
+ if (o && i >= o.length) o = void 0;
79
+ return { value: o && o[i++], done: !o };
80
+ }
81
+ };
82
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
83
+ };
84
+ import { deriveKeyFromPassword } from "./symmetric.js";
85
+ import { arrayBufferToBase64, base64ToArrayBuffer } from "./hashing.js";
86
+ export var encryptFile = function (fileContent_1, password_1) {
87
+ var args_1 = [];
88
+ for (var _i = 2; _i < arguments.length; _i++) {
89
+ args_1[_i - 2] = arguments[_i];
90
+ }
91
+ return __awaiter(void 0, __spreadArray([fileContent_1, password_1], __read(args_1), false), void 0, function (fileContent, password, fileName) {
92
+ var _a, key, salt, iv, dataToEncrypt, encryptedData, error_1;
93
+ if (fileName === void 0) { fileName = ""; }
94
+ return __generator(this, function (_b) {
95
+ switch (_b.label) {
96
+ case 0:
97
+ _b.trys.push([0, 8, , 9]);
98
+ return [4 /*yield*/, deriveKeyFromPassword(password)];
99
+ case 1:
100
+ _a = _b.sent(), key = _a.key, salt = _a.salt;
101
+ iv = crypto.getRandomValues(new Uint8Array(12));
102
+ dataToEncrypt = void 0;
103
+ if (!(typeof fileContent === "string")) return [3 /*break*/, 2];
104
+ dataToEncrypt = new TextEncoder().encode(fileContent).buffer;
105
+ return [3 /*break*/, 6];
106
+ case 2:
107
+ if (!(fileContent instanceof ArrayBuffer)) return [3 /*break*/, 3];
108
+ dataToEncrypt = fileContent;
109
+ return [3 /*break*/, 6];
110
+ case 3:
111
+ if (!(fileContent instanceof File)) return [3 /*break*/, 5];
112
+ return [4 /*yield*/, fileContent.arrayBuffer()];
113
+ case 4:
114
+ dataToEncrypt = _b.sent();
115
+ return [3 /*break*/, 6];
116
+ case 5: throw new Error("Unsupported file content type");
117
+ case 6: return [4 /*yield*/, crypto.subtle.encrypt({
118
+ name: "AES-GCM",
119
+ iv: iv,
120
+ }, key, dataToEncrypt)];
121
+ case 7:
122
+ encryptedData = _b.sent();
123
+ // Return encrypted package
124
+ return [2 /*return*/, {
125
+ encryptedData: arrayBufferToBase64(encryptedData),
126
+ iv: arrayBufferToBase64(iv.buffer),
127
+ salt: arrayBufferToBase64(salt),
128
+ fileName: fileName,
129
+ timestamp: new Date().toISOString(),
130
+ originalSize: dataToEncrypt.byteLength,
131
+ }];
132
+ case 8:
133
+ error_1 = _b.sent();
134
+ console.error("Error encrypting file:", error_1);
135
+ throw error_1 instanceof Error ? error_1 : new Error("Unknown error occurred");
136
+ case 9: return [2 /*return*/];
137
+ }
138
+ });
139
+ });
140
+ };
141
+ export var decryptFile = function (encryptedPackage, password) { return __awaiter(void 0, void 0, void 0, function () {
142
+ var encryptedData, iv, salt, fileName, originalSize, saltBuffer, ivBuffer, dataBuffer, key, decryptedData, error_2;
143
+ return __generator(this, function (_a) {
144
+ switch (_a.label) {
145
+ case 0:
146
+ _a.trys.push([0, 3, , 4]);
147
+ encryptedData = encryptedPackage.encryptedData, iv = encryptedPackage.iv, salt = encryptedPackage.salt, fileName = encryptedPackage.fileName, originalSize = encryptedPackage.originalSize;
148
+ saltBuffer = base64ToArrayBuffer(salt);
149
+ ivBuffer = base64ToArrayBuffer(iv);
150
+ dataBuffer = base64ToArrayBuffer(encryptedData);
151
+ return [4 /*yield*/, deriveKeyFromPassword(password, saltBuffer)];
152
+ case 1:
153
+ key = (_a.sent()).key;
154
+ return [4 /*yield*/, crypto.subtle.decrypt({
155
+ name: "AES-GCM",
156
+ iv: ivBuffer,
157
+ }, key, dataBuffer)];
158
+ case 2:
159
+ decryptedData = _a.sent();
160
+ return [2 /*return*/, {
161
+ data: decryptedData,
162
+ fileName: fileName,
163
+ originalSize: originalSize,
164
+ decryptedSize: decryptedData.byteLength,
165
+ }];
166
+ case 3:
167
+ error_2 = _a.sent();
168
+ console.error("Error decrypting file:", error_2);
169
+ throw new Error("Failed to decrypt file. Check password and try again.");
170
+ case 4: return [2 /*return*/];
171
+ }
172
+ });
173
+ }); };
174
+ export var encryptTextFile = function (textContent_1, password_1) {
175
+ var args_1 = [];
176
+ for (var _i = 2; _i < arguments.length; _i++) {
177
+ args_1[_i - 2] = arguments[_i];
178
+ }
179
+ return __awaiter(void 0, __spreadArray([textContent_1, password_1], __read(args_1), false), void 0, function (textContent, password, fileName) {
180
+ if (fileName === void 0) { fileName = "encrypted.txt"; }
181
+ return __generator(this, function (_a) {
182
+ switch (_a.label) {
183
+ case 0: return [4 /*yield*/, encryptFile(textContent, password, fileName)];
184
+ case 1: return [2 /*return*/, _a.sent()];
185
+ }
186
+ });
187
+ });
188
+ };
189
+ export var decryptTextFile = function (encryptedPackage, password) { return __awaiter(void 0, void 0, void 0, function () {
190
+ var result, textContent;
191
+ return __generator(this, function (_a) {
192
+ switch (_a.label) {
193
+ case 0: return [4 /*yield*/, decryptFile(encryptedPackage, password)];
194
+ case 1:
195
+ result = _a.sent();
196
+ textContent = new TextDecoder().decode(result.data);
197
+ return [2 /*return*/, __assign(__assign({}, result), { textContent: textContent })];
198
+ }
199
+ });
200
+ }); };
201
+ export var encryptBinaryFile = function (file, password) { return __awaiter(void 0, void 0, void 0, function () {
202
+ var encryptedPackage;
203
+ return __generator(this, function (_a) {
204
+ switch (_a.label) {
205
+ case 0:
206
+ if (!(file instanceof File)) {
207
+ throw new Error("Expected File object for binary encryption");
208
+ }
209
+ return [4 /*yield*/, encryptFile(file, password, file.name)];
210
+ case 1:
211
+ encryptedPackage = _a.sent();
212
+ return [2 /*return*/, __assign(__assign({}, encryptedPackage), { mimeType: file.type, fileSize: file.size })];
213
+ }
214
+ });
215
+ }); };
216
+ export var decryptBinaryFile = function (encryptedPackage, password) { return __awaiter(void 0, void 0, void 0, function () {
217
+ var result;
218
+ return __generator(this, function (_a) {
219
+ switch (_a.label) {
220
+ case 0: return [4 /*yield*/, decryptFile(encryptedPackage, password)];
221
+ case 1:
222
+ result = _a.sent();
223
+ return [2 /*return*/, __assign(__assign({}, result), { blob: new Blob([result.data], {
224
+ type: encryptedPackage.mimeType || "application/octet-stream",
225
+ }), mimeType: encryptedPackage.mimeType })];
226
+ }
227
+ });
228
+ }); };
229
+ export var createSecureFileDownload = function (data, fileName, mimeType) {
230
+ if (mimeType === void 0) { mimeType = "application/octet-stream"; }
231
+ var blob;
232
+ if (data instanceof ArrayBuffer) {
233
+ blob = new Blob([data], { type: mimeType });
234
+ }
235
+ else if (typeof data === "string") {
236
+ blob = new Blob([data], { type: "text/plain" });
237
+ }
238
+ else {
239
+ blob = data; // Assume it's already a Blob
240
+ }
241
+ var url = URL.createObjectURL(blob);
242
+ var a = document.createElement("a");
243
+ a.href = url;
244
+ a.download = fileName;
245
+ document.body.appendChild(a);
246
+ a.click();
247
+ document.body.removeChild(a);
248
+ URL.revokeObjectURL(url);
249
+ };
250
+ export var parseEncryptedFilePackage = function (file) { return __awaiter(void 0, void 0, void 0, function () {
251
+ var content, parsed, requiredProperties, requiredProperties_1, requiredProperties_1_1, prop, error_3;
252
+ var e_1, _a;
253
+ return __generator(this, function (_b) {
254
+ switch (_b.label) {
255
+ case 0:
256
+ _b.trys.push([0, 2, , 3]);
257
+ return [4 /*yield*/, file.text()];
258
+ case 1:
259
+ content = _b.sent();
260
+ parsed = JSON.parse(content);
261
+ requiredProperties = [
262
+ "encryptedData",
263
+ "iv",
264
+ "salt",
265
+ "fileName",
266
+ "timestamp",
267
+ "originalSize",
268
+ ];
269
+ try {
270
+ for (requiredProperties_1 = __values(requiredProperties), requiredProperties_1_1 = requiredProperties_1.next(); !requiredProperties_1_1.done; requiredProperties_1_1 = requiredProperties_1.next()) {
271
+ prop = requiredProperties_1_1.value;
272
+ if (!parsed.hasOwnProperty(prop)) {
273
+ throw new Error("Missing required property: ".concat(prop));
274
+ }
275
+ }
276
+ }
277
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
278
+ finally {
279
+ try {
280
+ if (requiredProperties_1_1 && !requiredProperties_1_1.done && (_a = requiredProperties_1.return)) _a.call(requiredProperties_1);
281
+ }
282
+ finally { if (e_1) throw e_1.error; }
283
+ }
284
+ // Validate data types
285
+ if (typeof parsed.encryptedData !== "string") {
286
+ throw new Error("encryptedData must be a base64 string");
287
+ }
288
+ if (typeof parsed.iv !== "string") {
289
+ throw new Error("iv must be a base64 string");
290
+ }
291
+ if (typeof parsed.salt !== "string") {
292
+ throw new Error("salt must be a base64 string");
293
+ }
294
+ if (typeof parsed.fileName !== "string") {
295
+ throw new Error("fileName must be a string");
296
+ }
297
+ if (typeof parsed.originalSize !== "number") {
298
+ throw new Error("originalSize must be a number");
299
+ }
300
+ return [2 /*return*/, {
301
+ isValid: true,
302
+ package: parsed,
303
+ metadata: {
304
+ fileName: parsed.fileName,
305
+ originalSize: parsed.originalSize,
306
+ timestamp: parsed.timestamp,
307
+ type: parsed.type || "unknown",
308
+ mimeType: parsed.mimeType || null,
309
+ },
310
+ }];
311
+ case 2:
312
+ error_3 = _b.sent();
313
+ return [2 /*return*/, {
314
+ isValid: false,
315
+ error: error_3 instanceof Error ? error_3.message : "Unknown error occurred",
316
+ package: undefined,
317
+ metadata: undefined,
318
+ }];
319
+ case 3: return [2 /*return*/];
320
+ }
321
+ });
322
+ }); };
323
+ export var decryptUploadedFile = function (encryptedFilePackage, password) { return __awaiter(void 0, void 0, void 0, function () {
324
+ var validation, pkg, metadata, decryptedResult, error_4, errorMessage;
325
+ var _a;
326
+ return __generator(this, function (_b) {
327
+ switch (_b.label) {
328
+ case 0:
329
+ _b.trys.push([0, 3, , 4]);
330
+ return [4 /*yield*/, parseEncryptedFilePackage(encryptedFilePackage)];
331
+ case 1:
332
+ validation = _b.sent();
333
+ if (!validation.isValid) {
334
+ throw new Error("Invalid encrypted file package: ".concat(validation.error));
335
+ }
336
+ pkg = validation.package, metadata = validation.metadata;
337
+ return [4 /*yield*/, decryptFile(pkg, password)];
338
+ case 2:
339
+ decryptedResult = _b.sent();
340
+ // Return enhanced result with metadata
341
+ return [2 /*return*/, __assign(__assign({}, decryptedResult), { isTextFile: (metadata === null || metadata === void 0 ? void 0 : metadata.type) === "text" || ((_a = metadata === null || metadata === void 0 ? void 0 : metadata.mimeType) === null || _a === void 0 ? void 0 : _a.startsWith("text/")), textContent: (metadata === null || metadata === void 0 ? void 0 : metadata.type) === "text"
342
+ ? new TextDecoder().decode(decryptedResult.data)
343
+ : undefined })];
344
+ case 3:
345
+ error_4 = _b.sent();
346
+ console.error("Error decrypting uploaded file:", error_4);
347
+ errorMessage = error_4 instanceof Error ? error_4.message : "Unknown error occurred";
348
+ throw new Error("Failed to decrypt uploaded file: ".concat(errorMessage));
349
+ case 4: return [2 /*return*/];
350
+ }
351
+ });
352
+ }); };
@@ -0,0 +1,160 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ var __values = (this && this.__values) || function(o) {
38
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
39
+ if (m) return m.call(o);
40
+ if (o && typeof o.length === "number") return {
41
+ next: function () {
42
+ if (o && i >= o.length) o = void 0;
43
+ return { value: o && o[i++], done: !o };
44
+ }
45
+ };
46
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
47
+ };
48
+ // Cryptographically Random String Generator
49
+ export var randomString = function (additionalSalt) {
50
+ if (additionalSalt === void 0) { additionalSalt = ""; }
51
+ var randomStringLength = 16;
52
+ var randomValues = crypto.getRandomValues(new Uint8Array(randomStringLength));
53
+ var randomHex = Array.from(randomValues)
54
+ .map(function (byte) { return byte.toString(16).padStart(2, "0"); })
55
+ .join("");
56
+ return additionalSalt ? additionalSalt + randomHex : randomHex;
57
+ };
58
+ // Hashing Methods
59
+ export var sha256Hash = function (input) { return __awaiter(void 0, void 0, void 0, function () {
60
+ var inputString, encoder, data, hashBuffer, hashArray;
61
+ return __generator(this, function (_a) {
62
+ switch (_a.label) {
63
+ case 0:
64
+ inputString = JSON.stringify(input);
65
+ encoder = new TextEncoder();
66
+ data = encoder.encode(inputString);
67
+ return [4 /*yield*/, crypto.subtle.digest("SHA-256", data)];
68
+ case 1:
69
+ hashBuffer = _a.sent();
70
+ hashArray = Array.from(new Uint8Array(hashBuffer));
71
+ return [2 /*return*/, hashArray.map(function (byte) { return byte.toString(16).padStart(2, "0"); }).join("")];
72
+ }
73
+ });
74
+ }); };
75
+ export var sha512Hash = function (input) { return __awaiter(void 0, void 0, void 0, function () {
76
+ var inputString, encoder, data, hashBuffer, hashArray;
77
+ return __generator(this, function (_a) {
78
+ switch (_a.label) {
79
+ case 0:
80
+ inputString = JSON.stringify(input);
81
+ encoder = new TextEncoder();
82
+ data = encoder.encode(inputString);
83
+ return [4 /*yield*/, crypto.subtle.digest("SHA-512", data)];
84
+ case 1:
85
+ hashBuffer = _a.sent();
86
+ hashArray = Array.from(new Uint8Array(hashBuffer));
87
+ return [2 /*return*/, hashArray.map(function (byte) { return byte.toString(16).padStart(2, "0"); }).join("")];
88
+ }
89
+ });
90
+ }); };
91
+ export var sha3_512Hash = function (input) { return __awaiter(void 0, void 0, void 0, function () {
92
+ var inputString, encoder, data, hashBuffer, hashArray;
93
+ return __generator(this, function (_a) {
94
+ switch (_a.label) {
95
+ case 0:
96
+ inputString = JSON.stringify(input);
97
+ encoder = new TextEncoder();
98
+ data = encoder.encode(inputString);
99
+ return [4 /*yield*/, crypto.subtle.digest("SHA-512", data)];
100
+ case 1:
101
+ hashBuffer = _a.sent();
102
+ hashArray = Array.from(new Uint8Array(hashBuffer));
103
+ return [2 /*return*/, hashArray.map(function (byte) { return byte.toString(16).padStart(2, "0"); }).join("")];
104
+ }
105
+ });
106
+ }); };
107
+ // Utility functions for crypto operations
108
+ export var bufferToHex = function (buffer) {
109
+ return Array.from(new Uint8Array(buffer))
110
+ .map(function (b) { return b.toString(16).padStart(2, "0"); })
111
+ .join("");
112
+ };
113
+ export var hexToBuffer = function (hex) {
114
+ var bytes = new Uint8Array(hex.length / 2);
115
+ for (var i = 0; i < hex.length; i += 2) {
116
+ bytes[i / 2] = parseInt(hex.substr(i, 2), 16);
117
+ }
118
+ return bytes.buffer;
119
+ };
120
+ export var concatArrayBuffers = function () {
121
+ var e_1, _a;
122
+ var buffers = [];
123
+ for (var _i = 0; _i < arguments.length; _i++) {
124
+ buffers[_i] = arguments[_i];
125
+ }
126
+ var totalLength = buffers.reduce(function (sum, buf) { return sum + buf.byteLength; }, 0);
127
+ var result = new Uint8Array(totalLength);
128
+ var offset = 0;
129
+ try {
130
+ for (var buffers_1 = __values(buffers), buffers_1_1 = buffers_1.next(); !buffers_1_1.done; buffers_1_1 = buffers_1.next()) {
131
+ var buffer = buffers_1_1.value;
132
+ result.set(new Uint8Array(buffer), offset);
133
+ offset += buffer.byteLength;
134
+ }
135
+ }
136
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
137
+ finally {
138
+ try {
139
+ if (buffers_1_1 && !buffers_1_1.done && (_a = buffers_1.return)) _a.call(buffers_1);
140
+ }
141
+ finally { if (e_1) throw e_1.error; }
142
+ }
143
+ return result.buffer;
144
+ };
145
+ export var base64ToArrayBuffer = function (base64) {
146
+ var binaryString = atob(base64);
147
+ var bytes = new Uint8Array(binaryString.length);
148
+ for (var i = 0; i < binaryString.length; i++) {
149
+ bytes[i] = binaryString.charCodeAt(i);
150
+ }
151
+ return bytes.buffer;
152
+ };
153
+ export var arrayBufferToBase64 = function (buffer) {
154
+ var bytes = new Uint8Array(buffer);
155
+ var binary = "";
156
+ for (var i = 0; i < bytes.byteLength; i++) {
157
+ binary += String.fromCharCode(bytes[i]);
158
+ }
159
+ return btoa(binary);
160
+ };
@@ -0,0 +1,18 @@
1
+ // Crypto module exports for shogun-core
2
+ export * from "./symmetric.js";
3
+ export * from "./asymmetric.js";
4
+ export * from "./hashing.js";
5
+ export * from "./file-encryption.js";
6
+ export * from "./signal-protocol.js";
7
+ export * from "./double-ratchet.js";
8
+ export * from "./random-generation.js";
9
+ // RFC-compliant MLS and SFrame implementations
10
+ export * from "./mls.js";
11
+ export * from "./mls-codec.js";
12
+ export * from "./sframe.js";
13
+ // PGP/OpenPGP implementation
14
+ export * from "./pgp.js";
15
+ export * from "./types.js";
16
+ export * from "./utils.js";
17
+ // Main crypto provider (only for React apps)
18
+ // export { CryptoProvider, useCrypto } from './provider.js';
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * MLS Message encoding/decoding utilities
4
3
  *
@@ -6,15 +5,6 @@
6
5
  * we'll use JSON serialization with Uint8Array and BigInt conversion for transmission.
7
6
  * This works for KeyPackage, Welcome, Commit, and other MLS messages.
8
7
  */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.encodeKeyPackage = encodeKeyPackage;
11
- exports.decodeKeyPackage = decodeKeyPackage;
12
- exports.encodeWelcome = encodeWelcome;
13
- exports.decodeWelcome = decodeWelcome;
14
- exports.encodeCommit = encodeCommit;
15
- exports.decodeCommit = decodeCommit;
16
- exports.encodeRatchetTree = encodeRatchetTree;
17
- exports.decodeRatchetTree = decodeRatchetTree;
18
8
  /**
19
9
  * Convert Uint8Array and BigInt to regular array/string recursively
20
10
  */
@@ -33,8 +23,8 @@ function uint8ArrayToArray(obj) {
33
23
  return obj.map(uint8ArrayToArray);
34
24
  }
35
25
  if (typeof obj === "object") {
36
- const result = {};
37
- for (const key in obj) {
26
+ var result = {};
27
+ for (var key in obj) {
38
28
  if (obj.hasOwnProperty(key)) {
39
29
  result[key] = uint8ArrayToArray(obj[key]);
40
30
  }
@@ -65,15 +55,15 @@ function arrayToUint8Array(obj) {
65
55
  }
66
56
  if (typeof obj === "object") {
67
57
  // Check if this is an array-like object with sequential numeric keys
68
- const keys = Object.keys(obj);
69
- const isArrayLike = keys.length > 0 && keys.every((key, index) => key === String(index));
58
+ var keys = Object.keys(obj);
59
+ var isArrayLike = keys.length > 0 && keys.every(function (key, index) { return key === String(index); });
70
60
  if (isArrayLike) {
71
61
  // Convert object with numeric keys back to array
72
62
  console.log("🔧 [mlsCodec] Converting array-like object to array, length:", keys.length);
73
- return keys.map((key) => arrayToUint8Array(obj[key]));
63
+ return keys.map(function (key) { return arrayToUint8Array(obj[key]); });
74
64
  }
75
- const result = {};
76
- for (const key in obj) {
65
+ var result = {};
66
+ for (var key in obj) {
77
67
  if (obj.hasOwnProperty(key)) {
78
68
  result[key] = arrayToUint8Array(obj[key]);
79
69
  }
@@ -85,59 +75,59 @@ function arrayToUint8Array(obj) {
85
75
  /**
86
76
  * Encode a KeyPackage to JSON string for transmission
87
77
  */
88
- function encodeKeyPackage(keyPackage) {
78
+ export function encodeKeyPackage(keyPackage) {
89
79
  // Convert Uint8Arrays to regular arrays so they can be JSON serialized
90
- const serializable = uint8ArrayToArray(keyPackage);
80
+ var serializable = uint8ArrayToArray(keyPackage);
91
81
  return JSON.stringify(serializable);
92
82
  }
93
83
  /**
94
84
  * Decode JSON string back to a KeyPackage object
95
85
  */
96
- function decodeKeyPackage(encoded) {
97
- const parsed = JSON.parse(encoded);
86
+ export function decodeKeyPackage(encoded) {
87
+ var parsed = JSON.parse(encoded);
98
88
  // Convert arrays back to Uint8Arrays
99
89
  return arrayToUint8Array(parsed);
100
90
  }
101
91
  /**
102
92
  * Encode a Welcome message to JSON string for transmission
103
93
  */
104
- function encodeWelcome(welcome) {
105
- const serializable = uint8ArrayToArray(welcome);
94
+ export function encodeWelcome(welcome) {
95
+ var serializable = uint8ArrayToArray(welcome);
106
96
  return JSON.stringify(serializable);
107
97
  }
108
98
  /**
109
99
  * Decode JSON string back to a Welcome object
110
100
  */
111
- function decodeWelcome(encoded) {
112
- const parsed = JSON.parse(encoded);
101
+ export function decodeWelcome(encoded) {
102
+ var parsed = JSON.parse(encoded);
113
103
  return arrayToUint8Array(parsed);
114
104
  }
115
105
  /**
116
106
  * Encode a Commit message to JSON string for transmission
117
107
  */
118
- function encodeCommit(commit) {
119
- const serializable = uint8ArrayToArray(commit);
108
+ export function encodeCommit(commit) {
109
+ var serializable = uint8ArrayToArray(commit);
120
110
  return JSON.stringify(serializable);
121
111
  }
122
112
  /**
123
113
  * Decode JSON string back to a Commit object
124
114
  */
125
- function decodeCommit(encoded) {
126
- const parsed = JSON.parse(encoded);
115
+ export function decodeCommit(encoded) {
116
+ var parsed = JSON.parse(encoded);
127
117
  return arrayToUint8Array(parsed);
128
118
  }
129
119
  /**
130
120
  * Encode a RatchetTree to JSON string for transmission
131
121
  */
132
- function encodeRatchetTree(ratchetTree) {
133
- const serializable = uint8ArrayToArray(ratchetTree);
122
+ export function encodeRatchetTree(ratchetTree) {
123
+ var serializable = uint8ArrayToArray(ratchetTree);
134
124
  return JSON.stringify(serializable);
135
125
  }
136
126
  /**
137
127
  * Decode JSON string back to a RatchetTree
138
128
  */
139
- function decodeRatchetTree(encoded) {
140
- const parsed = JSON.parse(encoded);
129
+ export function decodeRatchetTree(encoded) {
130
+ var parsed = JSON.parse(encoded);
141
131
  console.log("========================================");
142
132
  console.log("🔍 [mlsCodec] AFTER JSON.PARSE:");
143
133
  console.log(" Type:", typeof parsed);
@@ -166,7 +156,7 @@ function decodeRatchetTree(encoded) {
166
156
  console.log(" - Keys:", Object.keys(parsed[2]).slice(0, 10));
167
157
  console.log(" - Has nodeType:", "nodeType" in parsed[2]);
168
158
  }
169
- const result = arrayToUint8Array(parsed);
159
+ var result = arrayToUint8Array(parsed);
170
160
  console.log("----------------------------------------");
171
161
  console.log("🔍 [mlsCodec] AFTER ARRAY_TO_UINT8ARRAY:");
172
162
  console.log(" Type:", typeof result);