shogun-core 6.2.3 → 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 +138850 -146638
  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 -370
  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,405 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ var __assign = (this && this.__assign) || function () {
17
+ __assign = Object.assign || function(t) {
18
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
19
+ s = arguments[i];
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
21
+ t[p] = s[p];
22
+ }
23
+ return t;
24
+ };
25
+ return __assign.apply(this, arguments);
26
+ };
27
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
28
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
29
+ return new (P || (P = Promise))(function (resolve, reject) {
30
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
31
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
32
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
33
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
34
+ });
35
+ };
36
+ var __generator = (this && this.__generator) || function (thisArg, body) {
37
+ 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);
38
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
39
+ function verb(n) { return function (v) { return step([n, v]); }; }
40
+ function step(op) {
41
+ if (f) throw new TypeError("Generator is already executing.");
42
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
43
+ 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;
44
+ if (y = 0, t) op = [op[0] & 2, t.value];
45
+ switch (op[0]) {
46
+ case 0: case 1: t = op; break;
47
+ case 4: _.label++; return { value: op[1], done: false };
48
+ case 5: _.label++; y = op[1]; op = [0]; continue;
49
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
50
+ default:
51
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
52
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
53
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
54
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
55
+ if (t[2]) _.ops.pop();
56
+ _.trys.pop(); continue;
57
+ }
58
+ op = body.call(thisArg, _);
59
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
60
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
61
+ }
62
+ };
63
+ import { BasePlugin } from "../base.js";
64
+ import { ZkProofConnector } from "./zkProofConnector.js";
65
+ import { PluginCategory, } from "../../interfaces/shogun.js";
66
+ import { ErrorHandler, ErrorType, createError } from "../../utils/errorHandler.js";
67
+ /**
68
+ * Plugin for Zero-Knowledge Proof authentication using Semaphore protocol
69
+ *
70
+ * Features:
71
+ * - Anonymous authentication with ZK proofs
72
+ * - Multi-device support via trapdoor backup
73
+ * - Privacy-preserving identity management
74
+ * - Compatible with Gun decentralized storage
75
+ */
76
+ var ZkProofPlugin = /** @class */ (function (_super) {
77
+ __extends(ZkProofPlugin, _super);
78
+ function ZkProofPlugin(config) {
79
+ if (config === void 0) { config = {}; }
80
+ var _this = _super.call(this) || this;
81
+ _this.name = "zkproof";
82
+ _this.version = "1.0.0";
83
+ _this.description = "Zero-Knowledge Proof authentication using Semaphore protocol for ShogunCore";
84
+ _this._category = PluginCategory.Authentication;
85
+ _this.connector = null;
86
+ _this.config = __assign({ defaultGroupId: "shogun-users", deterministic: false, minEntropy: 128 }, config);
87
+ return _this;
88
+ }
89
+ /**
90
+ * Initialize the plugin
91
+ */
92
+ ZkProofPlugin.prototype.initialize = function (core) {
93
+ _super.prototype.initialize.call(this, core);
94
+ this.connector = new ZkProofConnector();
95
+ };
96
+ /**
97
+ * Clean up resources
98
+ */
99
+ ZkProofPlugin.prototype.destroy = function () {
100
+ if (this.connector) {
101
+ this.connector.cleanup();
102
+ }
103
+ this.connector = null;
104
+ _super.prototype.destroy.call(this);
105
+ };
106
+ /**
107
+ * Ensure connector is initialized
108
+ */
109
+ ZkProofPlugin.prototype.assertConnector = function () {
110
+ this.assertInitialized();
111
+ if (!this.connector) {
112
+ throw new Error("ZK-Proof connector not initialized");
113
+ }
114
+ return this.connector;
115
+ };
116
+ /**
117
+ * Generate a new ZK identity
118
+ */
119
+ ZkProofPlugin.prototype.generateIdentity = function (seed) {
120
+ return __awaiter(this, void 0, void 0, function () {
121
+ var error_1;
122
+ return __generator(this, function (_a) {
123
+ switch (_a.label) {
124
+ case 0:
125
+ _a.trys.push([0, 2, , 3]);
126
+ return [4 /*yield*/, this.assertConnector().generateIdentity(seed)];
127
+ case 1: return [2 /*return*/, _a.sent()];
128
+ case 2:
129
+ error_1 = _a.sent();
130
+ throw createError(ErrorType.ENCRYPTION, "ZK_IDENTITY_GENERATION_FAILED", "Failed to generate ZK identity: ".concat(error_1.message));
131
+ case 3: return [2 /*return*/];
132
+ }
133
+ });
134
+ });
135
+ };
136
+ /**
137
+ * Restore identity from trapdoor/seed phrase
138
+ */
139
+ ZkProofPlugin.prototype.restoreIdentity = function (trapdoor) {
140
+ return __awaiter(this, void 0, void 0, function () {
141
+ var error_2;
142
+ return __generator(this, function (_a) {
143
+ switch (_a.label) {
144
+ case 0:
145
+ _a.trys.push([0, 2, , 3]);
146
+ if (!trapdoor || trapdoor.trim().length === 0) {
147
+ throw new Error("Trapdoor is required");
148
+ }
149
+ return [4 /*yield*/, this.assertConnector().restoreIdentity(trapdoor)];
150
+ case 1: return [2 /*return*/, _a.sent()];
151
+ case 2:
152
+ error_2 = _a.sent();
153
+ throw createError(ErrorType.ENCRYPTION, "ZK_IDENTITY_RESTORE_FAILED", "Failed to restore ZK identity: ".concat(error_2.message));
154
+ case 3: return [2 /*return*/];
155
+ }
156
+ });
157
+ });
158
+ };
159
+ /**
160
+ * Generate credentials for Gun authentication
161
+ */
162
+ ZkProofPlugin.prototype.generateCredentials = function (identityData) {
163
+ return __awaiter(this, void 0, void 0, function () {
164
+ var error_3;
165
+ return __generator(this, function (_a) {
166
+ switch (_a.label) {
167
+ case 0:
168
+ _a.trys.push([0, 2, , 3]);
169
+ return [4 /*yield*/, this.assertConnector().generateCredentials(identityData)];
170
+ case 1: return [2 /*return*/, _a.sent()];
171
+ case 2:
172
+ error_3 = _a.sent();
173
+ throw createError(ErrorType.ENCRYPTION, "ZK_CREDENTIAL_GENERATION_FAILED", "Failed to generate credentials: ".concat(error_3.message));
174
+ case 3: return [2 /*return*/];
175
+ }
176
+ });
177
+ });
178
+ };
179
+ /**
180
+ * Generate a zero-knowledge proof
181
+ */
182
+ ZkProofPlugin.prototype.generateProof = function (identityData, options) {
183
+ return __awaiter(this, void 0, void 0, function () {
184
+ var error_4;
185
+ return __generator(this, function (_a) {
186
+ switch (_a.label) {
187
+ case 0:
188
+ _a.trys.push([0, 2, , 3]);
189
+ return [4 /*yield*/, this.assertConnector().generateProof(identityData, options)];
190
+ case 1: return [2 /*return*/, _a.sent()];
191
+ case 2:
192
+ error_4 = _a.sent();
193
+ throw createError(ErrorType.ENCRYPTION, "ZK_PROOF_GENERATION_FAILED", "Failed to generate ZK proof: ".concat(error_4.message));
194
+ case 3: return [2 /*return*/];
195
+ }
196
+ });
197
+ });
198
+ };
199
+ /**
200
+ * Verify a zero-knowledge proof
201
+ */
202
+ ZkProofPlugin.prototype.verifyProof = function (proof_1) {
203
+ return __awaiter(this, arguments, void 0, function (proof, treeDepth) {
204
+ var error_5;
205
+ if (treeDepth === void 0) { treeDepth = 20; }
206
+ return __generator(this, function (_a) {
207
+ switch (_a.label) {
208
+ case 0:
209
+ _a.trys.push([0, 2, , 3]);
210
+ return [4 /*yield*/, this.assertConnector().verifyProof(proof, treeDepth)];
211
+ case 1: return [2 /*return*/, _a.sent()];
212
+ case 2:
213
+ error_5 = _a.sent();
214
+ return [2 /*return*/, {
215
+ success: false,
216
+ verified: false,
217
+ error: error_5.message,
218
+ }];
219
+ case 3: return [2 /*return*/];
220
+ }
221
+ });
222
+ });
223
+ };
224
+ /**
225
+ * Add identity to a group
226
+ */
227
+ ZkProofPlugin.prototype.addToGroup = function (commitment, groupId) {
228
+ var group = groupId || this.config.defaultGroupId || "default";
229
+ this.assertConnector().addToGroup(commitment, group);
230
+ };
231
+ /**
232
+ * Login with ZK proof
233
+ * @param trapdoor - User's trapdoor/seed phrase
234
+ * @returns Authentication result
235
+ */
236
+ ZkProofPlugin.prototype.login = function (trapdoor) {
237
+ return __awaiter(this, void 0, void 0, function () {
238
+ var core, connector, identityData, gunPair, username, loginResult, authError_1, result, error_6, errorType, errorCode, errorMessage;
239
+ return __generator(this, function (_a) {
240
+ switch (_a.label) {
241
+ case 0:
242
+ _a.trys.push([0, 7, , 8]);
243
+ core = this.assertInitialized();
244
+ connector = this.assertConnector();
245
+ if (!trapdoor || trapdoor.trim().length === 0) {
246
+ throw createError(ErrorType.VALIDATION, "TRAPDOOR_REQUIRED", "Trapdoor is required for ZK-Proof login");
247
+ }
248
+ console.log("🔐 ZK-Proof login - restoring identity from trapdoor");
249
+ return [4 /*yield*/, connector.restoreIdentity(trapdoor)];
250
+ case 1:
251
+ identityData = _a.sent();
252
+ console.log("\uD83D\uDD10 ZK-Proof login - identity restored, commitment: ".concat(identityData.commitment.slice(0, 16), "..."));
253
+ return [4 /*yield*/, connector.generateCredentials(identityData)];
254
+ case 2:
255
+ gunPair = _a.sent();
256
+ console.log("\uD83D\uDD10 ZK-Proof login - Gun credentials generated, pub: ".concat(gunPair.pub.slice(0, 16), "..."));
257
+ username = "zk_".concat(identityData.commitment.slice(0, 16));
258
+ _a.label = 3;
259
+ case 3:
260
+ _a.trys.push([3, 5, , 6]);
261
+ return [4 /*yield*/, core.loginWithPair(username, gunPair)];
262
+ case 4:
263
+ loginResult = _a.sent();
264
+ if (!loginResult.success) {
265
+ console.log("🔐 ZK-Proof login - existing account not found, this might be first login");
266
+ }
267
+ else {
268
+ console.log("🔐 ZK-Proof login - Gun authentication successful");
269
+ }
270
+ return [3 /*break*/, 6];
271
+ case 5:
272
+ authError_1 = _a.sent();
273
+ console.log("🔐 ZK-Proof login - existing account not found, this might be first login");
274
+ return [3 /*break*/, 6];
275
+ case 6:
276
+ // Set authentication method
277
+ core.setAuthMethod("zkproof");
278
+ // Add to default group
279
+ this.addToGroup(identityData.commitment);
280
+ result = {
281
+ success: true,
282
+ userPub: gunPair.pub,
283
+ username: username,
284
+ authMethod: "zkproof",
285
+ sea: {
286
+ pub: gunPair.pub,
287
+ priv: gunPair.priv,
288
+ epub: gunPair.epub,
289
+ epriv: gunPair.epriv,
290
+ },
291
+ };
292
+ // Emit login event
293
+ core.emit("auth:login", {
294
+ userPub: gunPair.pub,
295
+ username: username,
296
+ method: "zkproof",
297
+ });
298
+ console.log("🔐 ZK-Proof login - complete");
299
+ return [2 /*return*/, result];
300
+ case 7:
301
+ error_6 = _a.sent();
302
+ errorType = (error_6 === null || error_6 === void 0 ? void 0 : error_6.type) || ErrorType.AUTHENTICATION;
303
+ errorCode = (error_6 === null || error_6 === void 0 ? void 0 : error_6.code) || "ZK_LOGIN_ERROR";
304
+ errorMessage = (error_6 === null || error_6 === void 0 ? void 0 : error_6.message) || "Unknown error during ZK-Proof login";
305
+ ErrorHandler.handle(errorType, errorCode, errorMessage, error_6);
306
+ return [2 /*return*/, { success: false, error: errorMessage }];
307
+ case 8: return [2 /*return*/];
308
+ }
309
+ });
310
+ });
311
+ };
312
+ /**
313
+ * Sign up with new ZK identity
314
+ * @param seed - Optional seed for deterministic generation
315
+ * @returns Authentication result with trapdoor for backup
316
+ */
317
+ ZkProofPlugin.prototype.signUp = function (seed) {
318
+ return __awaiter(this, void 0, void 0, function () {
319
+ var core, connector, identityData, gunPair, username, signUpResult, loginResult, createError_1, result, error_7, errorType, errorCode, errorMessage;
320
+ return __generator(this, function (_a) {
321
+ switch (_a.label) {
322
+ case 0:
323
+ _a.trys.push([0, 9, , 10]);
324
+ core = this.assertInitialized();
325
+ connector = this.assertConnector();
326
+ console.log("🔐 ZK-Proof signup - generating new identity");
327
+ return [4 /*yield*/, connector.generateIdentity(seed)];
328
+ case 1:
329
+ identityData = _a.sent();
330
+ console.log("\uD83D\uDD10 ZK-Proof signup - identity generated, commitment: ".concat(identityData.commitment.slice(0, 16), "..."));
331
+ return [4 /*yield*/, connector.generateCredentials(identityData)];
332
+ case 2:
333
+ gunPair = _a.sent();
334
+ console.log("\uD83D\uDD10 ZK-Proof signup - Gun credentials generated, pub: ".concat(gunPair.pub.slice(0, 16), "..."));
335
+ username = "zk_".concat(identityData.commitment.slice(0, 16));
336
+ _a.label = 3;
337
+ case 3:
338
+ _a.trys.push([3, 7, , 8]);
339
+ return [4 /*yield*/, core.signUp(username, undefined, gunPair)];
340
+ case 4:
341
+ signUpResult = _a.sent();
342
+ if (!!signUpResult.success) return [3 /*break*/, 6];
343
+ return [4 /*yield*/, core.loginWithPair(username, gunPair)];
344
+ case 5:
345
+ loginResult = _a.sent();
346
+ if (!loginResult.success) {
347
+ throw new Error(loginResult.error || "Failed to authenticate");
348
+ }
349
+ _a.label = 6;
350
+ case 6:
351
+ console.log("🔐 ZK-Proof signup - Gun user created/authenticated");
352
+ return [3 /*break*/, 8];
353
+ case 7:
354
+ createError_1 = _a.sent();
355
+ throw createError_1;
356
+ case 8:
357
+ // Set authentication method
358
+ core.setAuthMethod("zkproof");
359
+ // Add to default group
360
+ this.addToGroup(identityData.commitment);
361
+ result = {
362
+ success: true,
363
+ userPub: gunPair.pub,
364
+ username: username,
365
+ authMethod: "zkproof",
366
+ isNewUser: true,
367
+ // CRITICAL: Include trapdoor for user backup (like seed phrase in WebAuthn)
368
+ seedPhrase: identityData.trapdoor,
369
+ sea: {
370
+ pub: gunPair.pub,
371
+ priv: gunPair.priv,
372
+ epub: gunPair.epub,
373
+ epriv: gunPair.epriv,
374
+ },
375
+ };
376
+ // Emit signup event
377
+ core.emit("auth:signup", {
378
+ userPub: gunPair.pub,
379
+ username: username,
380
+ method: "zkproof",
381
+ });
382
+ console.log("🔐 ZK-Proof signup - complete");
383
+ console.log("\u26A0\uFE0F IMPORTANT: Save the trapdoor (seed phrase) for account recovery!");
384
+ return [2 /*return*/, result];
385
+ case 9:
386
+ error_7 = _a.sent();
387
+ errorType = (error_7 === null || error_7 === void 0 ? void 0 : error_7.type) || ErrorType.AUTHENTICATION;
388
+ errorCode = (error_7 === null || error_7 === void 0 ? void 0 : error_7.code) || "ZK_SIGNUP_ERROR";
389
+ errorMessage = (error_7 === null || error_7 === void 0 ? void 0 : error_7.message) || "Unknown error during ZK-Proof signup";
390
+ ErrorHandler.handle(errorType, errorCode, errorMessage, error_7);
391
+ return [2 /*return*/, { success: false, error: errorMessage }];
392
+ case 10: return [2 /*return*/];
393
+ }
394
+ });
395
+ });
396
+ };
397
+ /**
398
+ * Check if ZK-Proof is available
399
+ */
400
+ ZkProofPlugin.prototype.isAvailable = function () {
401
+ return typeof window !== "undefined" || typeof global !== "undefined";
402
+ };
403
+ return ZkProofPlugin;
404
+ }(BasePlugin));
405
+ export { ZkProofPlugin };
@@ -0,0 +1,189 @@
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
+ /**
38
+ * Storage implementation based on StorageMock
39
+ * Provides a unified storage interface that works in both browser and non-browser environments
40
+ * In browser environments, data is persisted to localStorage as a backup
41
+ */
42
+ var ShogunStorage = /** @class */ (function () {
43
+ /**
44
+ * Initializes storage and loads any existing keypair from localStorage if available
45
+ */
46
+ function ShogunStorage(silent) {
47
+ if (silent === void 0) { silent = false; }
48
+ this.store = new Map();
49
+ this.silent = silent;
50
+ this.isTestMode = process.env.NODE_ENV === "test";
51
+ this.useLocalStorage = false;
52
+ // In test mode, don't use localStorage to avoid test pollution
53
+ if (this.isTestMode) {
54
+ this.useLocalStorage = false;
55
+ return;
56
+ }
57
+ if (typeof localStorage !== "undefined") {
58
+ try {
59
+ // Probe localStorage without polluting expectations in tests
60
+ var testKey = "_shogun_test";
61
+ localStorage.setItem(testKey, testKey);
62
+ localStorage.removeItem(testKey);
63
+ this.useLocalStorage = true;
64
+ if (!this.silent) {
65
+ console.log("ShogunStorage: localStorage enabled");
66
+ }
67
+ var storedPair = localStorage.getItem("shogun_keypair");
68
+ if (storedPair) {
69
+ this.store.set("keypair", JSON.parse(storedPair));
70
+ }
71
+ }
72
+ catch (error) {
73
+ this.useLocalStorage = false;
74
+ // Silence logs in tests; tests expect no console.error during constructor
75
+ if (!this.silent) {
76
+ console.log("ShogunStorage: localStorage error:", error.message);
77
+ }
78
+ }
79
+ }
80
+ }
81
+ /**
82
+ * Gets the stored keypair asynchronously
83
+ * @returns Promise resolving to the keypair or null if not found
84
+ */
85
+ ShogunStorage.prototype.getPair = function () {
86
+ return __awaiter(this, void 0, void 0, function () {
87
+ return __generator(this, function (_a) {
88
+ return [2 /*return*/, this.getPairSync()];
89
+ });
90
+ });
91
+ };
92
+ /**
93
+ * Gets the stored keypair synchronously
94
+ * @returns The keypair or null if not found
95
+ */
96
+ ShogunStorage.prototype.getPairSync = function () {
97
+ return this.store.get("keypair") || null;
98
+ };
99
+ /**
100
+ * Stores a keypair both in memory and localStorage if available
101
+ * @param pair - The keypair to store
102
+ */
103
+ ShogunStorage.prototype.setPair = function (pair) {
104
+ return __awaiter(this, void 0, void 0, function () {
105
+ return __generator(this, function (_a) {
106
+ this.store.set("keypair", pair);
107
+ // Also save to localStorage in browser environments
108
+ if (this.useLocalStorage) {
109
+ try {
110
+ localStorage.setItem("shogun_keypair", JSON.stringify(pair));
111
+ }
112
+ catch (error) {
113
+ if (!this.isTestMode) {
114
+ console.error("Error saving data to localStorage:", error);
115
+ }
116
+ }
117
+ }
118
+ return [2 /*return*/];
119
+ });
120
+ });
121
+ };
122
+ /**
123
+ * Clears all stored data from both memory and localStorage
124
+ */
125
+ ShogunStorage.prototype.clearAll = function () {
126
+ this.store.clear();
127
+ // Also clear localStorage in browser environments
128
+ if (this.useLocalStorage) {
129
+ try {
130
+ localStorage.removeItem("shogun_keypair");
131
+ }
132
+ catch (error) {
133
+ if (!this.isTestMode) {
134
+ console.error("Error removing data from localStorage:", error);
135
+ }
136
+ }
137
+ }
138
+ };
139
+ /**
140
+ * Gets an item from storage
141
+ * @param key - The key to retrieve
142
+ * @returns The stored value, or null if not found
143
+ */
144
+ ShogunStorage.prototype.getItem = function (key) {
145
+ var value = this.store.get(key);
146
+ if (value === undefined) {
147
+ return null;
148
+ }
149
+ return value;
150
+ };
151
+ /**
152
+ * Stores an item in both memory and localStorage if available
153
+ * @param key - The key to store under
154
+ * @param value - The value to store (must be JSON stringifiable)
155
+ */
156
+ ShogunStorage.prototype.setItem = function (key, value) {
157
+ // Store the raw value as-is to preserve formatting
158
+ this.store.set(key, value);
159
+ if (this.useLocalStorage) {
160
+ try {
161
+ localStorage.setItem(key, typeof value === "string" ? value : JSON.stringify(value));
162
+ }
163
+ catch (error) {
164
+ if (!this.isTestMode) {
165
+ console.error("Error saving ".concat(key, " to localStorage:"), error);
166
+ }
167
+ }
168
+ }
169
+ };
170
+ /**
171
+ * Removes an item from both memory and localStorage if available
172
+ * @param key - The key to remove
173
+ */
174
+ ShogunStorage.prototype.removeItem = function (key) {
175
+ this.store.delete(key);
176
+ if (this.useLocalStorage) {
177
+ try {
178
+ localStorage.removeItem(key);
179
+ }
180
+ catch (error) {
181
+ if (!this.isTestMode) {
182
+ console.error("Error removing ".concat(key, " from localStorage:"), error);
183
+ }
184
+ }
185
+ }
186
+ };
187
+ return ShogunStorage;
188
+ }());
189
+ export { ShogunStorage };