shogun-core 5.2.0 → 5.2.1
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.
- package/dist/browser/defaultVendors-node_modules_hpke_chacha20poly1305_esm_mod_js.shogun-core.js +1220 -0
- package/dist/browser/defaultVendors-node_modules_hpke_chacha20poly1305_esm_mod_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_hpke_hybridkem-x-wing_esm_mod_js.shogun-core.js +844 -0
- package/dist/browser/defaultVendors-node_modules_hpke_hybridkem-x-wing_esm_mod_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_mlkem_esm_mod_js.shogun-core.js +2335 -0
- package/dist/browser/defaultVendors-node_modules_mlkem_esm_mod_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_noble_ciphers_chacha_js.shogun-core.js +999 -0
- package/dist/browser/defaultVendors-node_modules_noble_ciphers_chacha_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_curve_js-node_modules_noble_curves_esm_-1ce4ed.shogun-core.js +1651 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_curve_js-node_modules_noble_curves_esm_-1ce4ed.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_edwards_js-node_modules_noble_curves_es-a82056.shogun-core.js +825 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_edwards_js-node_modules_noble_curves_es-a82056.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed25519_js.shogun-core.js +508 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed25519_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js +747 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_nist_js.shogun-core.js +1608 -0
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_nist_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_noble_post-quantum_ml-dsa_js.shogun-core.js +2117 -0
- package/dist/browser/defaultVendors-node_modules_noble_post-quantum_ml-dsa_js.shogun-core.js.map +1 -0
- package/dist/browser/defaultVendors-node_modules_openpgp_dist_openpgp_min_mjs.shogun-core.js +86 -0
- package/dist/browser/defaultVendors-node_modules_openpgp_dist_openpgp_min_mjs.shogun-core.js.map +1 -0
- package/dist/browser/node_modules_hpke_ml-kem_esm_mod_js.shogun-core.js +539 -0
- package/dist/browser/node_modules_hpke_ml-kem_esm_mod_js.shogun-core.js.map +1 -0
- package/dist/browser/shogun-core.js +160386 -0
- package/dist/browser/shogun-core.js.map +1 -0
- package/dist/config/simplified-config.js +236 -0
- package/dist/core.js +329 -0
- package/dist/crypto/asymmetric.js +99 -0
- package/dist/crypto/double-ratchet.js +370 -0
- package/dist/crypto/file-encryption.js +213 -0
- package/dist/crypto/hashing.js +87 -0
- package/dist/crypto/index.js +34 -0
- package/dist/crypto/mls-codec.js +202 -0
- package/dist/crypto/mls.js +550 -0
- package/dist/crypto/pgp.js +390 -0
- package/dist/crypto/random-generation.js +341 -0
- package/dist/crypto/sframe.js +350 -0
- package/dist/crypto/signal-protocol.js +376 -0
- package/dist/crypto/symmetric.js +91 -0
- package/dist/crypto/types.js +2 -0
- package/dist/crypto/utils.js +140 -0
- package/dist/examples/auth-test.js +253 -0
- package/dist/examples/crypto-identity-example.js +151 -0
- package/dist/examples/crypto-working-test.js +83 -0
- package/dist/examples/double-ratchet-test.js +155 -0
- package/dist/examples/mls-advanced-example.js +294 -0
- package/dist/examples/mls-sframe-test.js +304 -0
- package/dist/examples/pgp-example.js +200 -0
- package/dist/examples/quick-auth-test.js +61 -0
- package/dist/examples/random-generation-test.js +151 -0
- package/dist/examples/signal-protocol-test.js +38 -0
- package/dist/examples/simple-api-test.js +114 -0
- package/dist/examples/simple-crypto-identity-example.js +84 -0
- package/dist/examples/timeout-test.js +227 -0
- package/dist/examples/zkproof-credentials-example.js +212 -0
- package/dist/examples/zkproof-example.js +201 -0
- package/dist/gundb/api.js +435 -0
- package/dist/gundb/crypto.js +283 -0
- package/dist/gundb/db.js +1946 -0
- package/dist/gundb/derive.js +232 -0
- package/dist/gundb/errors.js +76 -0
- package/dist/gundb/index.js +22 -0
- package/dist/gundb/rxjs.js +447 -0
- package/dist/gundb/types.js +5 -0
- package/dist/index.js +58 -0
- package/dist/interfaces/common.js +2 -0
- package/dist/interfaces/events.js +40 -0
- package/dist/interfaces/plugin.js +2 -0
- package/dist/interfaces/shogun.js +37 -0
- package/dist/managers/AuthManager.js +226 -0
- package/dist/managers/CoreInitializer.js +228 -0
- package/dist/managers/CryptoIdentityManager.js +366 -0
- package/dist/managers/EventManager.js +70 -0
- package/dist/managers/PluginManager.js +299 -0
- package/dist/plugins/base.js +50 -0
- package/dist/plugins/index.js +32 -0
- package/dist/plugins/nostr/index.js +20 -0
- package/dist/plugins/nostr/nostrConnector.js +419 -0
- package/dist/plugins/nostr/nostrConnectorPlugin.js +453 -0
- package/dist/plugins/nostr/nostrSigner.js +319 -0
- package/dist/plugins/nostr/types.js +2 -0
- package/dist/plugins/smartwallet/index.js +18 -0
- package/dist/plugins/smartwallet/smartWalletPlugin.js +511 -0
- package/dist/plugins/smartwallet/types.js +2 -0
- package/dist/plugins/web3/index.js +20 -0
- package/dist/plugins/web3/types.js +2 -0
- package/dist/plugins/web3/web3Connector.js +533 -0
- package/dist/plugins/web3/web3ConnectorPlugin.js +455 -0
- package/dist/plugins/web3/web3Signer.js +314 -0
- package/dist/plugins/webauthn/index.js +19 -0
- package/dist/plugins/webauthn/types.js +14 -0
- package/dist/plugins/webauthn/webauthn.js +496 -0
- package/dist/plugins/webauthn/webauthnPlugin.js +489 -0
- package/dist/plugins/webauthn/webauthnSigner.js +310 -0
- package/dist/plugins/zkproof/index.js +53 -0
- package/dist/plugins/zkproof/types.js +2 -0
- package/dist/plugins/zkproof/zkCredentials.js +213 -0
- package/dist/plugins/zkproof/zkProofConnector.js +198 -0
- package/dist/plugins/zkproof/zkProofPlugin.js +272 -0
- package/dist/storage/storage.js +145 -0
- package/dist/types/config/simplified-config.d.ts +114 -0
- package/dist/types/core.d.ts +305 -0
- package/dist/types/crypto/asymmetric.d.ts +6 -0
- package/dist/types/crypto/double-ratchet.d.ts +22 -0
- package/dist/types/crypto/file-encryption.d.ts +19 -0
- package/dist/types/crypto/hashing.d.ts +9 -0
- package/dist/types/crypto/index.d.ts +13 -0
- package/dist/types/crypto/mls-codec.d.ts +39 -0
- package/dist/types/crypto/mls.d.ts +130 -0
- package/dist/types/crypto/pgp.d.ts +95 -0
- package/dist/types/crypto/random-generation.d.ts +35 -0
- package/dist/types/crypto/sframe.d.ts +102 -0
- package/dist/types/crypto/signal-protocol.d.ts +26 -0
- package/dist/types/crypto/symmetric.d.ts +9 -0
- package/dist/types/crypto/types.d.ts +144 -0
- package/dist/types/crypto/utils.d.ts +22 -0
- package/dist/types/examples/auth-test.d.ts +8 -0
- package/dist/types/examples/crypto-identity-example.d.ts +5 -0
- package/dist/types/examples/crypto-working-test.d.ts +1 -0
- package/dist/types/examples/double-ratchet-test.d.ts +1 -0
- package/dist/types/examples/mls-advanced-example.d.ts +53 -0
- package/dist/types/examples/mls-sframe-test.d.ts +1 -0
- package/dist/types/examples/pgp-example.d.ts +75 -0
- package/dist/types/examples/quick-auth-test.d.ts +8 -0
- package/dist/types/examples/random-generation-test.d.ts +1 -0
- package/dist/types/examples/signal-protocol-test.d.ts +1 -0
- package/dist/types/examples/simple-api-test.d.ts +10 -0
- package/dist/types/examples/simple-crypto-identity-example.d.ts +6 -0
- package/dist/types/examples/timeout-test.d.ts +8 -0
- package/dist/types/examples/zkproof-credentials-example.d.ts +12 -0
- package/dist/types/examples/zkproof-example.d.ts +11 -0
- package/dist/types/gundb/api.d.ts +185 -0
- package/dist/types/gundb/crypto.d.ts +95 -0
- package/dist/types/gundb/db.d.ts +397 -0
- package/dist/types/gundb/derive.d.ts +21 -0
- package/dist/types/gundb/errors.d.ts +42 -0
- package/dist/types/gundb/index.d.ts +3 -0
- package/dist/types/gundb/rxjs.d.ts +110 -0
- package/dist/types/gundb/types.d.ts +255 -0
- package/dist/types/index.d.ts +16 -0
- package/dist/types/interfaces/common.d.ts +85 -0
- package/dist/types/interfaces/events.d.ts +131 -0
- package/dist/types/interfaces/plugin.d.ts +162 -0
- package/dist/types/interfaces/shogun.d.ts +208 -0
- package/dist/types/managers/AuthManager.d.ts +72 -0
- package/dist/types/managers/CoreInitializer.d.ts +40 -0
- package/dist/types/managers/CryptoIdentityManager.d.ts +102 -0
- package/dist/types/managers/EventManager.d.ts +49 -0
- package/dist/types/managers/PluginManager.d.ts +145 -0
- package/dist/types/plugins/base.d.ts +35 -0
- package/dist/types/plugins/index.d.ts +18 -0
- package/dist/types/plugins/nostr/index.d.ts +4 -0
- package/dist/types/plugins/nostr/nostrConnector.d.ts +119 -0
- package/dist/types/plugins/nostr/nostrConnectorPlugin.d.ts +163 -0
- package/dist/types/plugins/nostr/nostrSigner.d.ts +105 -0
- package/dist/types/plugins/nostr/types.d.ts +122 -0
- package/dist/types/plugins/smartwallet/index.d.ts +2 -0
- package/dist/types/plugins/smartwallet/smartWalletPlugin.d.ts +67 -0
- package/dist/types/plugins/smartwallet/types.d.ts +80 -0
- package/dist/types/plugins/web3/index.d.ts +4 -0
- package/dist/types/plugins/web3/types.d.ts +107 -0
- package/dist/types/plugins/web3/web3Connector.d.ts +129 -0
- package/dist/types/plugins/web3/web3ConnectorPlugin.d.ts +160 -0
- package/dist/types/plugins/web3/web3Signer.d.ts +114 -0
- package/dist/types/plugins/webauthn/index.d.ts +3 -0
- package/dist/types/plugins/webauthn/types.d.ts +183 -0
- package/dist/types/plugins/webauthn/webauthn.d.ts +129 -0
- package/dist/types/plugins/webauthn/webauthnPlugin.d.ts +179 -0
- package/dist/types/plugins/webauthn/webauthnSigner.d.ts +91 -0
- package/dist/types/plugins/zkproof/index.d.ts +48 -0
- package/dist/types/plugins/zkproof/types.d.ts +123 -0
- package/dist/types/plugins/zkproof/zkCredentials.d.ts +112 -0
- package/dist/types/plugins/zkproof/zkProofConnector.d.ts +46 -0
- package/dist/types/plugins/zkproof/zkProofPlugin.d.ts +76 -0
- package/dist/types/storage/storage.d.ts +51 -0
- package/dist/types/utils/errorHandler.d.ts +119 -0
- package/dist/types/utils/eventEmitter.d.ts +39 -0
- package/dist/types/utils/seedPhrase.d.ts +50 -0
- package/dist/types/utils/validation.d.ts +27 -0
- package/dist/utils/errorHandler.js +246 -0
- package/dist/utils/eventEmitter.js +79 -0
- package/dist/utils/seedPhrase.js +97 -0
- package/dist/utils/validation.js +81 -0
- package/package.json +10 -1
|
@@ -0,0 +1,453 @@
|
|
|
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;
|