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
@@ -1,453 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NostrConnectorPlugin = void 0;
4
- const base_1 = require("../base");
5
- const nostrConnector_1 = require("./nostrConnector");
6
- const nostrSigner_1 = require("./nostrSigner");
7
- const errorHandler_1 = require("../../utils/errorHandler");
8
- /**
9
- * Plugin for managing Bitcoin wallet functionality in ShogunCore
10
- * Supports Alby, Nostr extensions, or direct key management
11
- */
12
- class NostrConnectorPlugin extends base_1.BasePlugin {
13
- constructor() {
14
- super(...arguments);
15
- this.name = "nostr";
16
- this.version = "1.0.0";
17
- this.description = "Provides Bitcoin wallet connection and authentication for ShogunCore";
18
- this.bitcoinConnector = null;
19
- this.signer = null;
20
- }
21
- /**
22
- * @inheritdoc
23
- */
24
- initialize(core) {
25
- super.initialize(core);
26
- // Initialize the Bitcoin wallet module
27
- this.bitcoinConnector = new nostrConnector_1.NostrConnector();
28
- this.signer = new nostrSigner_1.NostrSigner(this.bitcoinConnector);
29
- }
30
- /**
31
- * @inheritdoc
32
- */
33
- destroy() {
34
- if (this.bitcoinConnector) {
35
- this.bitcoinConnector.cleanup();
36
- }
37
- this.bitcoinConnector = null;
38
- this.signer = null;
39
- super.destroy();
40
- }
41
- /**
42
- * Ensure that the Bitcoin wallet module is initialized
43
- * @private
44
- */
45
- assertBitcoinConnector() {
46
- this.assertInitialized();
47
- if (!this.bitcoinConnector) {
48
- throw new Error("Bitcoin wallet module not initialized");
49
- }
50
- return this.bitcoinConnector;
51
- }
52
- /**
53
- * Assicura che il signer sia inizializzato
54
- * @private
55
- */
56
- assertSigner() {
57
- this.assertInitialized();
58
- if (!this.signer) {
59
- throw new Error("Nostr signer not initialized");
60
- }
61
- return this.signer;
62
- }
63
- /**
64
- * @inheritdoc
65
- */
66
- isAvailable() {
67
- return this.assertBitcoinConnector().isAvailable();
68
- }
69
- /**
70
- * Check if Nostr extension is available
71
- */
72
- isNostrExtensionAvailable() {
73
- return this.assertBitcoinConnector().isNostrExtensionAvailable();
74
- }
75
- /**
76
- * Connect to Nostr wallet automatically
77
- * This is a convenience method for easy wallet connection
78
- */
79
- async connectNostrWallet() {
80
- try {
81
- if (!this.isNostrExtensionAvailable()) {
82
- return {
83
- success: false,
84
- error: "Nostr extension not available. Please install a Nostr extension like nos2x, Alby, or Coracle.",
85
- };
86
- }
87
- const result = await this.connectBitcoinWallet("nostr");
88
- if (result.success) {
89
- }
90
- return result;
91
- }
92
- catch (error) {
93
- console.error("[nostrConnectorPlugin] Error connecting to Nostr wallet:", error);
94
- return {
95
- success: false,
96
- error: error.message || "Unknown error connecting to Nostr wallet",
97
- };
98
- }
99
- }
100
- /**
101
- * @inheritdoc
102
- */
103
- async connectBitcoinWallet(type = "nostr") {
104
- // Prioritize nostr over alby (since they are functionally identical)
105
- // If type is alby, try to use nostr instead
106
- if (type === "alby") {
107
- type = "nostr";
108
- }
109
- return this.assertBitcoinConnector().connectWallet(type);
110
- }
111
- /**
112
- * @inheritdoc
113
- */
114
- async generateCredentials(address, signature, message) {
115
- return this.assertBitcoinConnector().generateCredentials(address, signature, message);
116
- }
117
- /**
118
- * @inheritdoc
119
- */
120
- cleanup() {
121
- this.assertBitcoinConnector().cleanup();
122
- }
123
- /**
124
- * @inheritdoc
125
- */
126
- async verifySignature(message, signature, address) {
127
- return this.assertBitcoinConnector().verifySignature(message, signature, address);
128
- }
129
- /**
130
- * @inheritdoc
131
- */
132
- async generatePassword(signature) {
133
- return this.assertBitcoinConnector().generatePassword(signature);
134
- }
135
- // === NOSTR SIGNER METHODS ===
136
- /**
137
- * Creates a new Nostr signing credential
138
- * CONSISTENT with normal Nostr approach
139
- */
140
- async createSigningCredential(address) {
141
- try {
142
- const conn = this.assertBitcoinConnector();
143
- if (typeof conn.createSigningCredential === "function") {
144
- return await conn.createSigningCredential(address);
145
- }
146
- return await this.assertSigner().createSigningCredential(address);
147
- }
148
- catch (error) {
149
- console.error(`Error creating Nostr signing credential: ${error.message}`);
150
- throw error;
151
- }
152
- }
153
- /**
154
- * Creates an authenticator function for Nostr signing
155
- */
156
- createAuthenticator(address) {
157
- try {
158
- const conn = this.assertBitcoinConnector();
159
- if (typeof conn.createAuthenticator === "function") {
160
- return conn.createAuthenticator(address);
161
- }
162
- return this.assertSigner().createAuthenticator(address);
163
- }
164
- catch (error) {
165
- console.error(`Error creating Nostr authenticator: ${error.message}`);
166
- throw error;
167
- }
168
- }
169
- /**
170
- * Creates a derived key pair from Nostr credential
171
- */
172
- async createDerivedKeyPair(address, extra) {
173
- try {
174
- const conn = this.assertBitcoinConnector();
175
- if (typeof conn.createDerivedKeyPair === "function") {
176
- return await conn.createDerivedKeyPair(address, extra);
177
- }
178
- return await this.assertSigner().createDerivedKeyPair(address, extra);
179
- }
180
- catch (error) {
181
- console.error(`Error creating derived key pair: ${error.message}`);
182
- throw error;
183
- }
184
- }
185
- /**
186
- * Signs data with derived keys after Nostr verification
187
- */
188
- async signWithDerivedKeys(data, address, extra) {
189
- try {
190
- const conn = this.assertBitcoinConnector();
191
- if (typeof conn.signWithDerivedKeys === "function") {
192
- return await conn.signWithDerivedKeys(data, address, extra);
193
- }
194
- return await this.assertSigner().signWithDerivedKeys(data, address, extra);
195
- }
196
- catch (error) {
197
- console.error(`Error signing with derived keys: ${error.message}`);
198
- throw error;
199
- }
200
- }
201
- /**
202
- * Get signing credential by address
203
- */
204
- getSigningCredential(address) {
205
- const conn = this.assertBitcoinConnector();
206
- if (typeof conn.getSigningCredential === "function") {
207
- return conn.getSigningCredential(address);
208
- }
209
- return this.assertSigner().getCredential(address);
210
- }
211
- /**
212
- * List all signing credentials
213
- */
214
- listSigningCredentials() {
215
- const conn = this.assertBitcoinConnector();
216
- if (typeof conn.listSigningCredentials === "function") {
217
- return conn.listSigningCredentials();
218
- }
219
- return this.assertSigner().listCredentials();
220
- }
221
- /**
222
- * Remove a signing credential
223
- */
224
- removeSigningCredential(address) {
225
- const conn = this.assertBitcoinConnector();
226
- if (typeof conn.removeSigningCredential === "function") {
227
- return conn.removeSigningCredential(address);
228
- }
229
- return this.assertSigner().removeCredential(address);
230
- }
231
- // === CONSISTENCY METHODS ===
232
- /**
233
- * Creates a Gun user from Nostr signing credential
234
- * This ensures the SAME user is created as with normal approach
235
- */
236
- async createGunUserFromSigningCredential(address) {
237
- try {
238
- const conn = this.assertBitcoinConnector();
239
- if (typeof conn.createGunUserFromSigningCredential === "function") {
240
- return await conn.createGunUserFromSigningCredential(address);
241
- }
242
- const core = this.assertInitialized();
243
- return await this.assertSigner().createGunUser(address, core.gun);
244
- }
245
- catch (error) {
246
- console.error(`Error creating Gun user from Nostr signing credential: ${error.message}`);
247
- throw error;
248
- }
249
- }
250
- /**
251
- * Get the Gun user public key for a signing credential
252
- */
253
- getGunUserPubFromSigningCredential(address) {
254
- const conn = this.assertBitcoinConnector();
255
- if (typeof conn.getGunUserPubFromSigningCredential === "function") {
256
- return conn.getGunUserPubFromSigningCredential(address);
257
- }
258
- return this.assertSigner().getGunUserPub(address);
259
- }
260
- /**
261
- * Get the password (for consistency checking)
262
- */
263
- getPassword(address) {
264
- const conn = this.assertBitcoinConnector();
265
- if (typeof conn.getPassword === "function") {
266
- return conn.getPassword(address);
267
- }
268
- return this.assertSigner().getPassword(address);
269
- }
270
- /**
271
- * Verify consistency between oneshot and normal approaches
272
- * This ensures both approaches create the same Gun user
273
- */
274
- async verifyConsistency(address, expectedUserPub) {
275
- try {
276
- const conn = this.assertBitcoinConnector();
277
- if (typeof conn.verifyConsistency === "function") {
278
- return await conn.verifyConsistency(address, expectedUserPub);
279
- }
280
- return await this.assertSigner().verifyConsistency(address, expectedUserPub);
281
- }
282
- catch (error) {
283
- console.error(`Error verifying Nostr consistency: ${error.message}`);
284
- return { consistent: false };
285
- }
286
- }
287
- /**
288
- * Complete oneshot workflow that creates the SAME Gun user as normal approach
289
- * This is the recommended method for oneshot signing with full consistency
290
- */
291
- async setupConsistentOneshotSigning(address) {
292
- try {
293
- const conn = this.assertBitcoinConnector();
294
- if (typeof conn.setupConsistentOneshotSigning === "function") {
295
- return await conn.setupConsistentOneshotSigning(address);
296
- }
297
- const credential = await this.createSigningCredential(address);
298
- const authenticator = this.createAuthenticator(address);
299
- const gunUser = await this.createGunUserFromSigningCredential(address);
300
- return {
301
- credential,
302
- authenticator,
303
- gunUser,
304
- username: credential.username,
305
- password: credential.password,
306
- };
307
- }
308
- catch (error) {
309
- console.error(`Error setting up consistent Nostr oneshot signing: ${error.message}`);
310
- throw error;
311
- }
312
- }
313
- // === EXISTING METHODS ===
314
- /**
315
- * Login with Bitcoin wallet
316
- * @param address - Bitcoin address
317
- * @returns {Promise<AuthResult>} Authentication result
318
- * @description Authenticates the user using Bitcoin wallet credentials after signature verification
319
- */
320
- async login(address) {
321
- try {
322
- const core = this.assertInitialized();
323
- if (!address) {
324
- throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.VALIDATION, "ADDRESS_REQUIRED", "Bitcoin address required for login");
325
- }
326
- if (!this.isAvailable()) {
327
- throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.ENVIRONMENT, "BITCOIN_WALLET_UNAVAILABLE", "No Bitcoin wallet available in the browser");
328
- }
329
- const message = nostrConnector_1.MESSAGE_TO_SIGN;
330
- const signature = await this.assertBitcoinConnector().requestSignature(address, message);
331
- const credentials = await this.generateCredentials(address, signature, message);
332
- if (!credentials?.username ||
333
- !credentials?.key ||
334
- !credentials.message ||
335
- !credentials.signature) {
336
- throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.AUTHENTICATION, "CREDENTIAL_GENERATION_FAILED", "Bitcoin wallet credentials not generated correctly or signature missing");
337
- }
338
- const isValid = await this.verifySignature(credentials.message, credentials.signature, address);
339
- if (!isValid) {
340
- console.error(`Signature verification failed for address: ${address}`);
341
- throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.SECURITY, "SIGNATURE_VERIFICATION_FAILED", "Bitcoin wallet signature verification failed");
342
- }
343
- // Deriva le chiavi da address, signature, message
344
- const k = await (0, nostrConnector_1.deriveNostrKeys)(address, signature, message);
345
- // Set authentication method to nostr before login
346
- core.setAuthMethod("nostr");
347
- // Usa le chiavi derivate per login
348
- const loginResult = await core.login(credentials.username, "", k);
349
- if (!loginResult.success) {
350
- throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.AUTHENTICATION, "BITCOIN_LOGIN_FAILED", loginResult.error || "Failed to log in with Bitcoin credentials");
351
- }
352
- // Emit login event
353
- core.emit("auth:login", {
354
- userPub: loginResult.userPub || "",
355
- username: credentials.username,
356
- method: "nostr",
357
- });
358
- return loginResult;
359
- }
360
- catch (error) {
361
- // Handle both ShogunError and generic errors
362
- const errorType = error?.type || errorHandler_1.ErrorType.AUTHENTICATION;
363
- const errorCode = error?.code || "BITCOIN_LOGIN_ERROR";
364
- const errorMessage = error?.message || "Unknown error during Bitcoin wallet login";
365
- errorHandler_1.ErrorHandler.handle(errorType, errorCode, errorMessage, error);
366
- return { success: false, error: errorMessage };
367
- }
368
- }
369
- /**
370
- * Register new user with Nostr wallet
371
- * @param address - Nostr address
372
- * @returns {Promise<SignUpResult>} Registration result
373
- */
374
- async signUp(address) {
375
- try {
376
- const core = this.assertInitialized();
377
- if (!address) {
378
- throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.VALIDATION, "ADDRESS_REQUIRED", "Bitcoin address required for signup");
379
- }
380
- if (!this.isAvailable()) {
381
- throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.ENVIRONMENT, "BITCOIN_WALLET_UNAVAILABLE", "No Bitcoin wallet available in the browser");
382
- }
383
- const message = nostrConnector_1.MESSAGE_TO_SIGN;
384
- const signature = await this.assertBitcoinConnector().requestSignature(address, message);
385
- const credentials = await this.generateCredentials(address, signature, message);
386
- if (!credentials?.username ||
387
- !credentials?.key ||
388
- !credentials.message ||
389
- !credentials.signature) {
390
- throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.AUTHENTICATION, "CREDENTIAL_GENERATION_FAILED", "Bitcoin wallet credentials not generated correctly or signature missing");
391
- }
392
- // Verify signature
393
- const isValid = await this.verifySignature(credentials.message, credentials.signature, address);
394
- if (!isValid) {
395
- console.error(`Signature verification failed for address: ${address}`);
396
- throw (0, errorHandler_1.createError)(errorHandler_1.ErrorType.SECURITY, "SIGNATURE_VERIFICATION_FAILED", "Bitcoin wallet signature verification failed");
397
- }
398
- // Deriva le chiavi da address, signature, message
399
- const k = await (0, nostrConnector_1.deriveNostrKeys)(address, signature, message);
400
- // Set authentication method to nostr before signup
401
- core.setAuthMethod("nostr");
402
- // Usa le chiavi derivate per signup
403
- const signupResult = await core.signUp(credentials.username, undefined, k);
404
- if (signupResult.success) {
405
- // Dopo la creazione, autentica subito
406
- const authResult = await core.login(credentials.username, "", k);
407
- if (authResult.success) {
408
- console.log(`Bitcoin wallet registration and login completed for user: ${credentials.username}`);
409
- // Emetti eventi
410
- core.emit("auth:signup", {
411
- userPub: authResult.userPub || "",
412
- username: credentials.username,
413
- method: "nostr",
414
- });
415
- return { ...authResult };
416
- }
417
- else {
418
- return { ...signupResult, error: "User created but login failed" };
419
- }
420
- }
421
- else {
422
- // Se l'errore è che l'utente esiste già, prova direttamente l'auth
423
- if (signupResult.error &&
424
- signupResult.error.toLowerCase().includes("exist")) {
425
- const authResult = await core.login(credentials.username, "", k);
426
- return { ...authResult };
427
- }
428
- return signupResult;
429
- }
430
- }
431
- catch (error) {
432
- // Handle both ShogunError and generic errors
433
- const errorType = error?.type || errorHandler_1.ErrorType.AUTHENTICATION;
434
- const errorCode = error?.code || "BITCOIN_SIGNUP_ERROR";
435
- const errorMessage = error?.message || "Unknown error during Bitcoin wallet signup";
436
- errorHandler_1.ErrorHandler.handle(errorType, errorCode, errorMessage, error);
437
- return { success: false, error: errorMessage };
438
- }
439
- }
440
- /**
441
- * Convenience method that matches the interface pattern
442
- */
443
- async loginWithBitcoinWallet(address) {
444
- return this.login(address);
445
- }
446
- /**
447
- * Convenience method that matches the interface pattern
448
- */
449
- async signUpWithBitcoinWallet(address) {
450
- return this.signUp(address);
451
- }
452
- }
453
- exports.NostrConnectorPlugin = NostrConnectorPlugin;