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,419 @@
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 __read = (this && this.__read) || function (o, n) {
38
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
39
+ if (!m) return o;
40
+ var i = m.call(o), r, ar = [], e;
41
+ try {
42
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
43
+ }
44
+ catch (error) { e = { error: error }; }
45
+ finally {
46
+ try {
47
+ if (r && !r.done && (m = i["return"])) m.call(i);
48
+ }
49
+ finally { if (e) throw e.error; }
50
+ }
51
+ return ar;
52
+ };
53
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
54
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
55
+ if (ar || !(i in from)) {
56
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
57
+ ar[i] = from[i];
58
+ }
59
+ }
60
+ return to.concat(ar || Array.prototype.slice.call(from));
61
+ };
62
+ import { Webauthn } from "./webauthn.js";
63
+ import { p256 } from "@noble/curves/p256";
64
+ import { sha256 } from "@noble/hashes/sha256";
65
+ import derive from "../../gundb/derive.js";
66
+ import { ethers } from "ethers";
67
+ /**
68
+ * Base64URL encoding utilities
69
+ */
70
+ var base64url = {
71
+ encode: function (buffer) {
72
+ var bytes = new Uint8Array(buffer);
73
+ return btoa(String.fromCharCode.apply(String, __spreadArray([], __read(bytes), false)))
74
+ .replace(/\+/g, "-")
75
+ .replace(/\//g, "_")
76
+ .replace(/=/g, "");
77
+ },
78
+ decode: function (str) {
79
+ str = str.replace(/-/g, "+").replace(/_/g, "/");
80
+ while (str.length % 4)
81
+ str += "=";
82
+ var binary = atob(str);
83
+ return new Uint8Array(binary.split("").map(function (c) { return c.charCodeAt(0); }));
84
+ },
85
+ };
86
+ /**
87
+ * WebAuthn Signer - Provides oneshot signing functionality
88
+ * Similar to webauthn.js but integrated with our architecture
89
+ * CONSISTENT with normal WebAuthn approach
90
+ */
91
+ var WebAuthnSigner = /** @class */ (function () {
92
+ function WebAuthnSigner(webauthn) {
93
+ this.credentials = new Map();
94
+ this.webauthn = webauthn || new Webauthn();
95
+ }
96
+ /**
97
+ * Creates a new WebAuthn credential for signing
98
+ * Similar to webauthn.js create functionality but CONSISTENT with normal approach
99
+ */
100
+ WebAuthnSigner.prototype.createSigningCredential = function (username) {
101
+ return __awaiter(this, void 0, void 0, function () {
102
+ var credential, response, publicKey, rawKey, xCoord, yCoord, x, y, pub, hashedCredentialId, signingCredential, error_1;
103
+ return __generator(this, function (_a) {
104
+ switch (_a.label) {
105
+ case 0:
106
+ _a.trys.push([0, 2, , 3]);
107
+ return [4 /*yield*/, navigator.credentials.create({
108
+ publicKey: {
109
+ challenge: crypto.getRandomValues(new Uint8Array(32)),
110
+ rp: {
111
+ id: window.location.hostname === "localhost"
112
+ ? "localhost"
113
+ : window.location.hostname,
114
+ name: "Shogun Wallet",
115
+ },
116
+ user: {
117
+ id: new TextEncoder().encode(username),
118
+ name: username,
119
+ displayName: username,
120
+ },
121
+ // Use the same algorithms as webauthn.js for SEA compatibility
122
+ pubKeyCredParams: [
123
+ { type: "public-key", alg: -7 }, // ECDSA, P-256 curve, for signing
124
+ { type: "public-key", alg: -25 }, // ECDH, P-256 curve, for creating shared secrets
125
+ { type: "public-key", alg: -257 },
126
+ ],
127
+ authenticatorSelection: {
128
+ userVerification: "preferred",
129
+ },
130
+ timeout: 60000,
131
+ attestation: "none",
132
+ },
133
+ })];
134
+ case 1:
135
+ credential = (_a.sent());
136
+ if (!credential) {
137
+ throw new Error("Failed to create WebAuthn credential");
138
+ }
139
+ response = credential.response;
140
+ publicKey = response.getPublicKey();
141
+ if (!publicKey) {
142
+ throw new Error("Failed to get public key from credential");
143
+ }
144
+ rawKey = new Uint8Array(publicKey);
145
+ xCoord = rawKey.slice(27, 59);
146
+ yCoord = rawKey.slice(59, 91);
147
+ x = base64url.encode(xCoord);
148
+ y = base64url.encode(yCoord);
149
+ pub = "".concat(x, ".").concat(y);
150
+ hashedCredentialId = ethers.keccak256(ethers.toUtf8Bytes(credential.id));
151
+ signingCredential = {
152
+ id: credential.id,
153
+ rawId: credential.rawId,
154
+ publicKey: { x: x, y: y },
155
+ pub: pub,
156
+ hashedCredentialId: hashedCredentialId,
157
+ };
158
+ // Store credential for later use
159
+ this.credentials.set(credential.id, signingCredential);
160
+ return [2 /*return*/, signingCredential];
161
+ case 2:
162
+ error_1 = _a.sent();
163
+ console.error("Error creating signing credential:", error_1);
164
+ throw new Error("Failed to create signing credential: ".concat(error_1.message));
165
+ case 3: return [2 /*return*/];
166
+ }
167
+ });
168
+ });
169
+ };
170
+ /**
171
+ * Creates an authenticator function compatible with SEA.sign
172
+ * This is the key function that makes it work like webauthn.js
173
+ */
174
+ WebAuthnSigner.prototype.createAuthenticator = function (credentialId) {
175
+ var _this = this;
176
+ var credential = this.credentials.get(credentialId);
177
+ if (!credential) {
178
+ throw new Error("Credential ".concat(credentialId, " not found"));
179
+ }
180
+ return function (data) { return __awaiter(_this, void 0, void 0, function () {
181
+ var challenge, options, assertion, error_2;
182
+ return __generator(this, function (_a) {
183
+ switch (_a.label) {
184
+ case 0:
185
+ _a.trys.push([0, 2, , 3]);
186
+ challenge = new TextEncoder().encode(JSON.stringify(data));
187
+ options = {
188
+ challenge: challenge,
189
+ rpId: window.location.hostname === "localhost"
190
+ ? "localhost"
191
+ : window.location.hostname,
192
+ userVerification: "preferred",
193
+ allowCredentials: [
194
+ {
195
+ type: "public-key",
196
+ id: credential.rawId,
197
+ },
198
+ ],
199
+ timeout: 60000,
200
+ };
201
+ return [4 /*yield*/, navigator.credentials.get({
202
+ publicKey: options,
203
+ })];
204
+ case 1:
205
+ assertion = (_a.sent());
206
+ if (!assertion) {
207
+ throw new Error("WebAuthn assertion failed");
208
+ }
209
+ return [2 /*return*/, assertion.response];
210
+ case 2:
211
+ error_2 = _a.sent();
212
+ console.error("WebAuthn assertion error:", error_2);
213
+ throw error_2;
214
+ case 3: return [2 /*return*/];
215
+ }
216
+ });
217
+ }); };
218
+ };
219
+ /**
220
+ * Creates a derived key pair from WebAuthn credential
221
+ * CONSISTENT with normal approach: uses hashedCredentialId as password
222
+ */
223
+ WebAuthnSigner.prototype.createDerivedKeyPair = function (credentialId, username, extra) {
224
+ return __awaiter(this, void 0, void 0, function () {
225
+ var credential, derivedKeys, error_3;
226
+ return __generator(this, function (_a) {
227
+ switch (_a.label) {
228
+ case 0:
229
+ credential = this.credentials.get(credentialId);
230
+ if (!credential) {
231
+ throw new Error("Credential ".concat(credentialId, " not found"));
232
+ }
233
+ _a.label = 1;
234
+ case 1:
235
+ _a.trys.push([1, 3, , 4]);
236
+ return [4 /*yield*/, derive(credential.hashedCredentialId, // This is the key change!
237
+ extra, { includeP256: true })];
238
+ case 2:
239
+ derivedKeys = _a.sent();
240
+ return [2 /*return*/, {
241
+ pub: derivedKeys.pub,
242
+ priv: derivedKeys.priv,
243
+ epub: derivedKeys.epub,
244
+ epriv: derivedKeys.epriv,
245
+ }];
246
+ case 3:
247
+ error_3 = _a.sent();
248
+ console.error("Error deriving keys from WebAuthn credential:", error_3);
249
+ throw error_3;
250
+ case 4: return [2 /*return*/];
251
+ }
252
+ });
253
+ });
254
+ };
255
+ /**
256
+ * Creates a Gun user from WebAuthn credential
257
+ * This ensures the SAME user is created as with normal approach
258
+ * FIX: Use derived pair instead of username/password for GunDB auth
259
+ */
260
+ WebAuthnSigner.prototype.createGunUser = function (credentialId, username, gunInstance) {
261
+ return __awaiter(this, void 0, void 0, function () {
262
+ var credential, derivedPair_1, error_4;
263
+ var _this = this;
264
+ return __generator(this, function (_a) {
265
+ switch (_a.label) {
266
+ case 0:
267
+ credential = this.credentials.get(credentialId);
268
+ if (!credential) {
269
+ throw new Error("Credential ".concat(credentialId, " not found"));
270
+ }
271
+ _a.label = 1;
272
+ case 1:
273
+ _a.trys.push([1, 3, , 4]);
274
+ return [4 /*yield*/, this.createDerivedKeyPair(credentialId, username)];
275
+ case 2:
276
+ derivedPair_1 = _a.sent();
277
+ return [2 /*return*/, new Promise(function (resolve) {
278
+ // Use the derived pair directly for GunDB auth
279
+ gunInstance.user().create(derivedPair_1, function (ack) {
280
+ if (ack.err) {
281
+ // Try to login if user already exists
282
+ gunInstance.user().auth(derivedPair_1, function (authAck) {
283
+ if (authAck.err) {
284
+ resolve({ success: false, error: authAck.err });
285
+ }
286
+ else {
287
+ var userPub = authAck.pub;
288
+ // Update credential with Gun user pub
289
+ credential.gunUserPub = userPub;
290
+ _this.credentials.set(credentialId, credential);
291
+ resolve({ success: true, userPub: userPub });
292
+ }
293
+ });
294
+ }
295
+ else {
296
+ // User created, now login
297
+ gunInstance.user().auth(derivedPair_1, function (authAck) {
298
+ if (authAck.err) {
299
+ resolve({ success: false, error: authAck.err });
300
+ }
301
+ else {
302
+ var userPub = authAck.pub;
303
+ // Update credential with Gun user pub
304
+ credential.gunUserPub = userPub;
305
+ _this.credentials.set(credentialId, credential);
306
+ resolve({ success: true, userPub: userPub });
307
+ }
308
+ });
309
+ }
310
+ });
311
+ })];
312
+ case 3:
313
+ error_4 = _a.sent();
314
+ console.error("Error creating Gun user:", error_4);
315
+ return [2 /*return*/, { success: false, error: error_4.message }];
316
+ case 4: return [2 /*return*/];
317
+ }
318
+ });
319
+ });
320
+ };
321
+ /**
322
+ * Signs data using WebAuthn + derived keys
323
+ * This provides a hybrid approach: WebAuthn for user verification + derived keys for actual signing
324
+ * CONSISTENT with normal approach
325
+ */
326
+ WebAuthnSigner.prototype.signWithDerivedKeys = function (data, credentialId, username, extra) {
327
+ return __awaiter(this, void 0, void 0, function () {
328
+ var authenticator, keyPair, message, messageHash, privKeyBytes, signature, seaSignature, error_5;
329
+ return __generator(this, function (_a) {
330
+ switch (_a.label) {
331
+ case 0:
332
+ _a.trys.push([0, 3, , 4]);
333
+ authenticator = this.createAuthenticator(credentialId);
334
+ return [4 /*yield*/, authenticator(data)];
335
+ case 1:
336
+ _a.sent(); // This verifies the user
337
+ return [4 /*yield*/, this.createDerivedKeyPair(credentialId, username, extra)];
338
+ case 2:
339
+ keyPair = _a.sent();
340
+ message = JSON.stringify(data);
341
+ messageHash = sha256(new TextEncoder().encode(message));
342
+ privKeyBytes = base64url.decode(keyPair.priv);
343
+ signature = p256.sign(messageHash, privKeyBytes);
344
+ seaSignature = {
345
+ m: message,
346
+ s: base64url.encode(signature.toCompactRawBytes()),
347
+ };
348
+ return [2 /*return*/, "SEA" + JSON.stringify(seaSignature)];
349
+ case 3:
350
+ error_5 = _a.sent();
351
+ console.error("Error signing with derived keys:", error_5);
352
+ throw error_5;
353
+ case 4: return [2 /*return*/];
354
+ }
355
+ });
356
+ });
357
+ };
358
+ /**
359
+ * Get the Gun user public key for a credential
360
+ * This allows checking if the same user would be created
361
+ */
362
+ WebAuthnSigner.prototype.getGunUserPub = function (credentialId) {
363
+ var credential = this.credentials.get(credentialId);
364
+ return credential === null || credential === void 0 ? void 0 : credential.gunUserPub;
365
+ };
366
+ /**
367
+ * Get the hashed credential ID (for consistency checking)
368
+ */
369
+ WebAuthnSigner.prototype.getHashedCredentialId = function (credentialId) {
370
+ var credential = this.credentials.get(credentialId);
371
+ return credential === null || credential === void 0 ? void 0 : credential.hashedCredentialId;
372
+ };
373
+ /**
374
+ * Check if this credential would create the same Gun user as normal approach
375
+ */
376
+ WebAuthnSigner.prototype.verifyConsistency = function (credentialId, username, expectedUserPub) {
377
+ return __awaiter(this, void 0, void 0, function () {
378
+ var credential, derivedKeys;
379
+ return __generator(this, function (_a) {
380
+ switch (_a.label) {
381
+ case 0:
382
+ credential = this.credentials.get(credentialId);
383
+ if (!credential) {
384
+ return [2 /*return*/, { consistent: false }];
385
+ }
386
+ return [4 /*yield*/, this.createDerivedKeyPair(credentialId, username)];
387
+ case 1:
388
+ derivedKeys = _a.sent();
389
+ return [2 /*return*/, {
390
+ consistent: expectedUserPub ? derivedKeys.pub === expectedUserPub : true,
391
+ actualUserPub: derivedKeys.pub,
392
+ expectedUserPub: expectedUserPub,
393
+ }];
394
+ }
395
+ });
396
+ });
397
+ };
398
+ /**
399
+ * Get credential by ID
400
+ */
401
+ WebAuthnSigner.prototype.getCredential = function (credentialId) {
402
+ return this.credentials.get(credentialId);
403
+ };
404
+ /**
405
+ * List all stored credentials
406
+ */
407
+ WebAuthnSigner.prototype.listCredentials = function () {
408
+ return Array.from(this.credentials.values());
409
+ };
410
+ /**
411
+ * Remove a credential
412
+ */
413
+ WebAuthnSigner.prototype.removeCredential = function (credentialId) {
414
+ return this.credentials.delete(credentialId);
415
+ };
416
+ return WebAuthnSigner;
417
+ }());
418
+ export { WebAuthnSigner };
419
+ export default WebAuthnSigner;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  /**
3
2
  * ZK-Proof Plugin for Shogun Core
4
3
  *
@@ -42,12 +41,6 @@
42
41
  *
43
42
  * @module zkproof
44
43
  */
45
- Object.defineProperty(exports, "__esModule", { value: true });
46
- exports.CredentialType = exports.ZkCredentials = exports.ZkProofConnector = exports.ZkProofPlugin = void 0;
47
- var zkProofPlugin_1 = require("./zkProofPlugin");
48
- Object.defineProperty(exports, "ZkProofPlugin", { enumerable: true, get: function () { return zkProofPlugin_1.ZkProofPlugin; } });
49
- var zkProofConnector_1 = require("./zkProofConnector");
50
- Object.defineProperty(exports, "ZkProofConnector", { enumerable: true, get: function () { return zkProofConnector_1.ZkProofConnector; } });
51
- var zkCredentials_1 = require("./zkCredentials");
52
- Object.defineProperty(exports, "ZkCredentials", { enumerable: true, get: function () { return zkCredentials_1.ZkCredentials; } });
53
- Object.defineProperty(exports, "CredentialType", { enumerable: true, get: function () { return zkCredentials_1.CredentialType; } });
44
+ export { ZkProofPlugin } from "./zkProofPlugin.js";
45
+ export { ZkProofConnector } from "./zkProofConnector.js";
46
+ export { ZkCredentials, CredentialType } from "./zkCredentials.js";
@@ -0,0 +1 @@
1
+ export {};