shogun-core 6.2.4 → 6.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js +93 -341
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_ed448_js.shogun-core.js.map +1 -1
- package/dist/browser/shogun-core.js +138979 -146789
- package/dist/browser/shogun-core.js.map +1 -1
- package/dist/{core.js → src/core.js} +167 -107
- package/dist/src/crypto/asymmetric.js +168 -0
- package/dist/src/crypto/double-ratchet.js +908 -0
- package/dist/src/crypto/file-encryption.js +352 -0
- package/dist/src/crypto/hashing.js +160 -0
- package/dist/src/crypto/index.js +18 -0
- package/dist/{crypto → src/crypto}/mls-codec.js +24 -34
- package/dist/src/crypto/mls.js +734 -0
- package/dist/src/crypto/pgp.js +619 -0
- package/dist/{crypto → src/crypto}/random-generation.js +125 -103
- package/dist/src/crypto/sframe.js +466 -0
- package/dist/src/crypto/signal-protocol.js +943 -0
- package/dist/src/crypto/symmetric.js +165 -0
- package/dist/src/crypto/utils.js +220 -0
- package/dist/src/examples/auth-test.js +535 -0
- package/dist/src/examples/crypto-identity-example.js +294 -0
- package/dist/src/examples/crypto-working-test.js +149 -0
- package/dist/src/examples/double-ratchet-test.js +240 -0
- package/dist/src/examples/mls-3-member-test.js +183 -0
- package/dist/src/examples/mls-multi-member.js +439 -0
- package/dist/src/examples/mls-sframe-test.js +491 -0
- package/dist/src/examples/mls-simple-test.js +122 -0
- package/dist/src/examples/pgp-example.js +354 -0
- package/dist/src/examples/random-generation-test.js +191 -0
- package/dist/src/examples/shogun-core-example.js +204 -0
- package/dist/src/examples/signal-protocol-test.js +82 -0
- package/dist/src/examples/zkproof-credentials-example.js +357 -0
- package/dist/src/examples/zkproof-example.js +357 -0
- package/dist/src/gundb/crypto.js +420 -0
- package/dist/src/gundb/db.js +728 -0
- package/dist/src/gundb/derive.js +327 -0
- package/dist/src/gundb/errors.js +115 -0
- package/dist/src/gundb/gun-es.js +8 -0
- package/dist/src/gundb/index.js +5 -0
- package/dist/{gundb → src/gundb}/rxjs.js +147 -111
- package/dist/{gundb → src/gundb}/types.js +1 -2
- package/dist/src/index.js +19 -0
- package/dist/src/interfaces/events.js +57 -0
- package/dist/{interfaces → src/interfaces}/shogun.js +4 -7
- package/dist/src/managers/AuthManager.js +301 -0
- package/dist/src/managers/CoreInitializer.js +304 -0
- package/dist/src/managers/CryptoIdentityManager.js +230 -0
- package/dist/{managers → src/managers}/EventManager.js +19 -21
- package/dist/{managers → src/managers}/PluginManager.js +123 -89
- package/dist/src/plugins/base.js +90 -0
- package/dist/src/plugins/index.js +17 -0
- package/dist/src/plugins/nostr/index.js +4 -0
- package/dist/src/plugins/nostr/nostrConnector.js +539 -0
- package/dist/src/plugins/nostr/nostrConnectorPlugin.js +663 -0
- package/dist/src/plugins/nostr/nostrSigner.js +414 -0
- package/dist/src/plugins/smartwallet/index.js +2 -0
- package/dist/src/plugins/smartwallet/smartWalletPlugin.js +824 -0
- package/dist/src/plugins/web3/index.js +4 -0
- package/dist/src/plugins/web3/types.js +1 -0
- package/dist/src/plugins/web3/web3Connector.js +738 -0
- package/dist/src/plugins/web3/web3ConnectorPlugin.js +639 -0
- package/dist/src/plugins/web3/web3Signer.js +432 -0
- package/dist/src/plugins/webauthn/index.js +3 -0
- package/dist/{plugins → src/plugins}/webauthn/types.js +2 -5
- package/dist/src/plugins/webauthn/webauthn.js +647 -0
- package/dist/src/plugins/webauthn/webauthnPlugin.js +689 -0
- package/dist/src/plugins/webauthn/webauthnSigner.js +419 -0
- package/dist/{plugins → src/plugins}/zkproof/index.js +3 -10
- package/dist/src/plugins/zkproof/types.js +1 -0
- package/dist/src/plugins/zkproof/zkCredentials.js +287 -0
- package/dist/src/plugins/zkproof/zkProofConnector.js +267 -0
- package/dist/src/plugins/zkproof/zkProofPlugin.js +405 -0
- package/dist/src/storage/storage.js +189 -0
- package/dist/src/utils/errorHandler.js +339 -0
- package/dist/{utils → src/utils}/eventEmitter.js +26 -26
- package/dist/{utils → src/utils}/seedPhrase.js +23 -32
- package/dist/{utils → src/utils}/validation.js +14 -21
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/{crypto → src/crypto}/double-ratchet.d.ts +1 -1
- package/dist/types/{crypto → src/crypto}/signal-protocol.d.ts +25 -0
- package/dist/types/{crypto → src/crypto}/types.d.ts +3 -1
- package/dist/types/src/examples/crypto-working-test.d.ts +1 -0
- package/dist/types/src/examples/double-ratchet-test.d.ts +1 -0
- package/dist/types/src/examples/mls-sframe-test.d.ts +1 -0
- package/dist/types/src/examples/random-generation-test.d.ts +1 -0
- package/dist/types/src/examples/signal-protocol-test.d.ts +1 -0
- package/dist/types/{gundb → src/gundb}/db.d.ts +14 -1
- package/dist/types/src/gundb/gun-es.d.ts +8 -0
- package/dist/types/src/gundb/min.d.ts +3 -0
- package/dist/types/{index.d.ts → src/index.d.ts} +1 -0
- package/package.json +14 -11
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_curve_js-node_modules_noble_curves_esm_-1ce4ed.shogun-core.js +0 -1651
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_abstract_curve_js-node_modules_noble_curves_esm_-1ce4ed.shogun-core.js.map +0 -1
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_nist_js.shogun-core.js +0 -1608
- package/dist/browser/defaultVendors-node_modules_noble_curves_esm_nist_js.shogun-core.js.map +0 -1
- package/dist/crypto/asymmetric.js +0 -99
- package/dist/crypto/double-ratchet.js +0 -392
- package/dist/crypto/file-encryption.js +0 -213
- package/dist/crypto/hashing.js +0 -87
- package/dist/crypto/index.js +0 -34
- package/dist/crypto/mls.js +0 -569
- package/dist/crypto/pgp.js +0 -390
- package/dist/crypto/sframe.js +0 -352
- package/dist/crypto/signal-protocol.js +0 -456
- package/dist/crypto/symmetric.js +0 -91
- package/dist/crypto/types.js +0 -2
- package/dist/crypto/utils.js +0 -140
- package/dist/examples/auth-test.js +0 -453
- package/dist/examples/crypto-identity-example.js +0 -196
- package/dist/examples/crypto-working-test.js +0 -83
- package/dist/examples/double-ratchet-test.js +0 -155
- package/dist/examples/mls-3-member-test.js +0 -97
- package/dist/examples/mls-multi-member.js +0 -153
- package/dist/examples/mls-sframe-test.js +0 -307
- package/dist/examples/mls-simple-test.js +0 -58
- package/dist/examples/pgp-example.js +0 -200
- package/dist/examples/random-generation-test.js +0 -151
- package/dist/examples/shogun-core-example.js +0 -150
- package/dist/examples/signal-protocol-test.js +0 -38
- package/dist/examples/zkproof-credentials-example.js +0 -217
- package/dist/examples/zkproof-example.js +0 -242
- package/dist/gundb/crypto.js +0 -306
- package/dist/gundb/db.js +0 -485
- package/dist/gundb/derive.js +0 -232
- package/dist/gundb/errors.js +0 -76
- package/dist/gundb/gun-es.js +0 -12
- package/dist/gundb/index.js +0 -21
- package/dist/gundb/min.js +0 -10
- package/dist/index.esm.js +0 -22
- package/dist/index.js +0 -47
- package/dist/interfaces/common.js +0 -2
- package/dist/interfaces/events.js +0 -40
- package/dist/interfaces/plugin.js +0 -2
- package/dist/managers/AuthManager.js +0 -226
- package/dist/managers/CoreInitializer.js +0 -250
- package/dist/managers/CryptoIdentityManager.js +0 -138
- package/dist/plugins/base.js +0 -50
- package/dist/plugins/index.js +0 -32
- package/dist/plugins/nostr/index.js +0 -20
- package/dist/plugins/nostr/nostrConnector.js +0 -419
- package/dist/plugins/nostr/nostrConnectorPlugin.js +0 -453
- package/dist/plugins/nostr/nostrSigner.js +0 -319
- package/dist/plugins/nostr/types.js +0 -2
- package/dist/plugins/smartwallet/index.js +0 -18
- package/dist/plugins/smartwallet/smartWalletPlugin.js +0 -511
- package/dist/plugins/smartwallet/types.js +0 -2
- package/dist/plugins/web3/index.js +0 -20
- package/dist/plugins/web3/types.js +0 -2
- package/dist/plugins/web3/web3Connector.js +0 -533
- package/dist/plugins/web3/web3ConnectorPlugin.js +0 -455
- package/dist/plugins/web3/web3Signer.js +0 -314
- package/dist/plugins/webauthn/index.js +0 -19
- package/dist/plugins/webauthn/webauthn.js +0 -496
- package/dist/plugins/webauthn/webauthnPlugin.js +0 -490
- package/dist/plugins/webauthn/webauthnSigner.js +0 -310
- package/dist/plugins/zkproof/types.js +0 -2
- package/dist/plugins/zkproof/zkCredentials.js +0 -216
- package/dist/plugins/zkproof/zkProofConnector.js +0 -198
- package/dist/plugins/zkproof/zkProofPlugin.js +0 -272
- package/dist/storage/storage.js +0 -145
- package/dist/types/gundb/gun-es.d.ts +0 -8
- package/dist/utils/errorHandler.js +0 -246
- /package/dist/{types/examples/crypto-working-test.d.ts → src/crypto/types.js} +0 -0
- /package/dist/{types/gundb/min.d.ts → src/gundb/min.js} +0 -0
- /package/dist/{types/examples/double-ratchet-test.d.ts → src/interfaces/common.js} +0 -0
- /package/dist/{types/examples/mls-sframe-test.d.ts → src/interfaces/plugin.js} +0 -0
- /package/dist/{types/examples/random-generation-test.d.ts → src/plugins/nostr/types.js} +0 -0
- /package/dist/{types/examples/signal-protocol-test.d.ts → src/plugins/smartwallet/types.js} +0 -0
- /package/dist/types/{core.d.ts → src/core.d.ts} +0 -0
- /package/dist/types/{crypto → src/crypto}/asymmetric.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/file-encryption.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/hashing.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/index.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/mls-codec.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/mls.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/pgp.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/random-generation.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/sframe.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/symmetric.d.ts +0 -0
- /package/dist/types/{crypto → src/crypto}/utils.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/auth-test.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/crypto-identity-example.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/mls-3-member-test.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/mls-multi-member.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/mls-simple-test.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/pgp-example.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/shogun-core-example.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/zkproof-credentials-example.d.ts +0 -0
- /package/dist/types/{examples → src/examples}/zkproof-example.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/crypto.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/derive.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/errors.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/index.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/rxjs.d.ts +0 -0
- /package/dist/types/{gundb → src/gundb}/types.d.ts +0 -0
- /package/dist/types/{interfaces → src/interfaces}/common.d.ts +0 -0
- /package/dist/types/{interfaces → src/interfaces}/events.d.ts +0 -0
- /package/dist/types/{interfaces → src/interfaces}/plugin.d.ts +0 -0
- /package/dist/types/{interfaces → src/interfaces}/shogun.d.ts +0 -0
- /package/dist/types/{managers → src/managers}/AuthManager.d.ts +0 -0
- /package/dist/types/{managers → src/managers}/CoreInitializer.d.ts +0 -0
- /package/dist/types/{managers → src/managers}/CryptoIdentityManager.d.ts +0 -0
- /package/dist/types/{managers → src/managers}/EventManager.d.ts +0 -0
- /package/dist/types/{managers → src/managers}/PluginManager.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/base.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/nostr/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/nostr/nostrConnector.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/nostr/nostrConnectorPlugin.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/nostr/nostrSigner.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/nostr/types.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/smartwallet/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/smartwallet/smartWalletPlugin.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/smartwallet/types.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/web3/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/web3/types.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/web3/web3Connector.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/web3/web3ConnectorPlugin.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/web3/web3Signer.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/webauthn/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/webauthn/types.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/webauthn/webauthn.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/webauthn/webauthnPlugin.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/webauthn/webauthnSigner.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/zkproof/index.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/zkproof/types.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/zkproof/zkCredentials.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/zkproof/zkProofConnector.d.ts +0 -0
- /package/dist/types/{plugins → src/plugins}/zkproof/zkProofPlugin.d.ts +0 -0
- /package/dist/types/{storage → src/storage}/storage.d.ts +0 -0
- /package/dist/types/{utils → src/utils}/errorHandler.d.ts +0 -0
- /package/dist/types/{utils → src/utils}/eventEmitter.d.ts +0 -0
- /package/dist/types/{utils → src/utils}/seedPhrase.d.ts +0 -0
- /package/dist/types/{utils → src/utils}/validation.d.ts +0 -0
package/dist/plugins/index.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SmartWalletPlugin = exports.CredentialType = exports.ZkCredentials = exports.ZkProofPlugin = exports.ZkProofConnector = exports.NostrConnectorPlugin = exports.NostrConnector = exports.Web3ConnectorPlugin = exports.Web3Connector = exports.WebauthnPlugin = exports.Webauthn = exports.BasePlugin = void 0;
|
|
4
|
-
// Base plugin interface and types
|
|
5
|
-
var base_1 = require("./base");
|
|
6
|
-
Object.defineProperty(exports, "BasePlugin", { enumerable: true, get: function () { return base_1.BasePlugin; } });
|
|
7
|
-
// WebAuthn plugin exports
|
|
8
|
-
var webauthn_1 = require("./webauthn/webauthn");
|
|
9
|
-
Object.defineProperty(exports, "Webauthn", { enumerable: true, get: function () { return webauthn_1.Webauthn; } });
|
|
10
|
-
var webauthnPlugin_1 = require("./webauthn/webauthnPlugin");
|
|
11
|
-
Object.defineProperty(exports, "WebauthnPlugin", { enumerable: true, get: function () { return webauthnPlugin_1.WebauthnPlugin; } });
|
|
12
|
-
// Ethereum plugin exports
|
|
13
|
-
var web3Connector_1 = require("./web3/web3Connector");
|
|
14
|
-
Object.defineProperty(exports, "Web3Connector", { enumerable: true, get: function () { return web3Connector_1.Web3Connector; } });
|
|
15
|
-
var web3ConnectorPlugin_1 = require("./web3/web3ConnectorPlugin");
|
|
16
|
-
Object.defineProperty(exports, "Web3ConnectorPlugin", { enumerable: true, get: function () { return web3ConnectorPlugin_1.Web3ConnectorPlugin; } });
|
|
17
|
-
// Bitcoin plugin exports
|
|
18
|
-
var nostrConnector_1 = require("./nostr/nostrConnector");
|
|
19
|
-
Object.defineProperty(exports, "NostrConnector", { enumerable: true, get: function () { return nostrConnector_1.NostrConnector; } });
|
|
20
|
-
var nostrConnectorPlugin_1 = require("./nostr/nostrConnectorPlugin");
|
|
21
|
-
Object.defineProperty(exports, "NostrConnectorPlugin", { enumerable: true, get: function () { return nostrConnectorPlugin_1.NostrConnectorPlugin; } });
|
|
22
|
-
// ZK-Proof plugin exports
|
|
23
|
-
var zkProofConnector_1 = require("./zkproof/zkProofConnector");
|
|
24
|
-
Object.defineProperty(exports, "ZkProofConnector", { enumerable: true, get: function () { return zkProofConnector_1.ZkProofConnector; } });
|
|
25
|
-
var zkProofPlugin_1 = require("./zkproof/zkProofPlugin");
|
|
26
|
-
Object.defineProperty(exports, "ZkProofPlugin", { enumerable: true, get: function () { return zkProofPlugin_1.ZkProofPlugin; } });
|
|
27
|
-
var zkCredentials_1 = require("./zkproof/zkCredentials");
|
|
28
|
-
Object.defineProperty(exports, "ZkCredentials", { enumerable: true, get: function () { return zkCredentials_1.ZkCredentials; } });
|
|
29
|
-
Object.defineProperty(exports, "CredentialType", { enumerable: true, get: function () { return zkCredentials_1.CredentialType; } });
|
|
30
|
-
// Smart Wallet plugin exports
|
|
31
|
-
var smartWalletPlugin_1 = require("./smartwallet/smartWalletPlugin");
|
|
32
|
-
Object.defineProperty(exports, "SmartWalletPlugin", { enumerable: true, get: function () { return smartWalletPlugin_1.SmartWalletPlugin; } });
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./nostrConnectorPlugin"), exports);
|
|
18
|
-
__exportStar(require("./nostrConnector"), exports);
|
|
19
|
-
__exportStar(require("./nostrSigner"), exports);
|
|
20
|
-
__exportStar(require("./types"), exports);
|
|
@@ -1,419 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.NostrConnector = exports.MESSAGE_TO_SIGN = void 0;
|
|
7
|
-
exports.deriveNostrKeys = deriveNostrKeys;
|
|
8
|
-
/**
|
|
9
|
-
* The BitcoinWallet class provides functionality for connecting, signing up, and logging in using Bitcoin wallets.
|
|
10
|
-
* Supports Alby and Nostr extensions, as well as manual key management.
|
|
11
|
-
*/
|
|
12
|
-
const ethers_1 = require("ethers");
|
|
13
|
-
const nostr_tools_1 = require("nostr-tools");
|
|
14
|
-
const eventEmitter_1 = require("../../utils/eventEmitter");
|
|
15
|
-
const derive_1 = __importDefault(require("../../gundb/derive"));
|
|
16
|
-
const validation_1 = require("../../utils/validation");
|
|
17
|
-
exports.MESSAGE_TO_SIGN = "I Love Shogun!";
|
|
18
|
-
/**
|
|
19
|
-
* Class for Bitcoin wallet connections and operations
|
|
20
|
-
*/
|
|
21
|
-
class NostrConnector extends eventEmitter_1.EventEmitter {
|
|
22
|
-
constructor(config = {}) {
|
|
23
|
-
super();
|
|
24
|
-
this.DEFAULT_CONFIG = {
|
|
25
|
-
cacheDuration: 24 * 60 * 60 * 1000, // 24 hours instead of 30 minutes for better UX
|
|
26
|
-
maxRetries: 3,
|
|
27
|
-
retryDelay: 1000,
|
|
28
|
-
timeout: 60000,
|
|
29
|
-
network: "mainnet",
|
|
30
|
-
useApi: false,
|
|
31
|
-
};
|
|
32
|
-
this.signatureCache = new Map();
|
|
33
|
-
// Connection state
|
|
34
|
-
this.connectedAddress = null;
|
|
35
|
-
this.connectedType = null;
|
|
36
|
-
this.manualKeyPair = null;
|
|
37
|
-
this.config = { ...this.DEFAULT_CONFIG, ...config };
|
|
38
|
-
this.setupEventListeners();
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Setup event listeners
|
|
42
|
-
*/
|
|
43
|
-
setupEventListeners() {
|
|
44
|
-
// Currently no global events to listen to
|
|
45
|
-
// This would be the place to add listeners for wallet connections/disconnections
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Clear signature cache for a specific address or all addresses
|
|
49
|
-
*/
|
|
50
|
-
clearSignatureCache(address) {
|
|
51
|
-
if (address) {
|
|
52
|
-
// Clear cache for specific address
|
|
53
|
-
this.signatureCache.delete(address);
|
|
54
|
-
try {
|
|
55
|
-
const localStorageKey = `shogun_bitcoin_sig_${address}`;
|
|
56
|
-
localStorage.removeItem(localStorageKey);
|
|
57
|
-
console.log(`Cleared signature cache for address: ${address.substring(0, 10)}...`);
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
console.error("Error clearing signature cache from localStorage:", error);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
// Clear all signature caches
|
|
65
|
-
this.signatureCache.clear();
|
|
66
|
-
try {
|
|
67
|
-
// Find and remove all shogun_bitcoin_sig_ keys
|
|
68
|
-
const keysToRemove = [];
|
|
69
|
-
for (let i = 0; i < localStorage.length; i++) {
|
|
70
|
-
const key = localStorage.key(i);
|
|
71
|
-
if (key && key.startsWith("shogun_bitcoin_sig_")) {
|
|
72
|
-
keysToRemove.push(key);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
keysToRemove.forEach((key) => localStorage.removeItem(key));
|
|
76
|
-
console.log(`Cleared all signature caches (${keysToRemove.length} entries)`);
|
|
77
|
-
}
|
|
78
|
-
catch (error) {
|
|
79
|
-
console.error("Error clearing all signature caches from localStorage:", error);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Check if Nostr extension is available
|
|
85
|
-
*/
|
|
86
|
-
isNostrExtensionAvailable() {
|
|
87
|
-
return typeof window !== "undefined" && !!window.nostr;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Check if any Bitcoin wallet is available
|
|
91
|
-
*/
|
|
92
|
-
isAvailable() {
|
|
93
|
-
return this.isNostrExtensionAvailable() || this.manualKeyPair !== null;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Connect to a wallet type
|
|
97
|
-
*/
|
|
98
|
-
async connectWallet(type = "nostr") {
|
|
99
|
-
console.log(`Connecting to Bitcoin wallet via ${type}...`);
|
|
100
|
-
try {
|
|
101
|
-
let result;
|
|
102
|
-
// Attempt to connect to the specified wallet type
|
|
103
|
-
switch (type) {
|
|
104
|
-
case "alby":
|
|
105
|
-
console.log("[nostrConnector] Alby is deprecated, redirecting to Nostr");
|
|
106
|
-
result = await this.connectNostr();
|
|
107
|
-
break;
|
|
108
|
-
case "nostr":
|
|
109
|
-
result = await this.connectNostr();
|
|
110
|
-
break;
|
|
111
|
-
case "manual":
|
|
112
|
-
result = await this.connectManual();
|
|
113
|
-
break;
|
|
114
|
-
default:
|
|
115
|
-
throw new Error(`Unsupported wallet type: ${type}`);
|
|
116
|
-
}
|
|
117
|
-
if (result.success && result.address) {
|
|
118
|
-
this.connectedAddress = result.address;
|
|
119
|
-
this.connectedType = type;
|
|
120
|
-
console.log(`Successfully connected to ${type} wallet: ${result.address}`);
|
|
121
|
-
this.emit("wallet_connected", {
|
|
122
|
-
address: result.address,
|
|
123
|
-
type: this.connectedType,
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
return result;
|
|
127
|
-
}
|
|
128
|
-
catch (error) {
|
|
129
|
-
console.error(`Error connecting to ${type} wallet:`, error);
|
|
130
|
-
return {
|
|
131
|
-
success: false,
|
|
132
|
-
error: error.message || "Failed to connect to wallet",
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Connect to Nostr extension
|
|
138
|
-
*/
|
|
139
|
-
async connectNostr() {
|
|
140
|
-
if (!this.isNostrExtensionAvailable()) {
|
|
141
|
-
return {
|
|
142
|
-
success: false,
|
|
143
|
-
error: "Nostr extension is not available. Please install a Nostr compatible extension like nos2x, Alby, or Coracle.",
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
try {
|
|
147
|
-
console.log("[nostrConnector] Attempting to connect to Nostr extension...");
|
|
148
|
-
// Get public key from Nostr extension
|
|
149
|
-
const pubKey = await window.nostr.getPublicKey();
|
|
150
|
-
if (!pubKey) {
|
|
151
|
-
throw new Error("Could not get public key from Nostr extension");
|
|
152
|
-
}
|
|
153
|
-
console.log(`[nostrConnector] Successfully connected to Nostr extension: ${pubKey.substring(0, 10)}...`);
|
|
154
|
-
this.connectedAddress = pubKey;
|
|
155
|
-
this.connectedType = "nostr";
|
|
156
|
-
// Emit connected event
|
|
157
|
-
this.emit("connected", { address: pubKey, type: "nostr" });
|
|
158
|
-
const username = `nostr_${pubKey.substring(0, 10)}`;
|
|
159
|
-
return {
|
|
160
|
-
success: true,
|
|
161
|
-
address: pubKey,
|
|
162
|
-
username,
|
|
163
|
-
extensionType: "nostr",
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
catch (error) {
|
|
167
|
-
console.error("[nostrConnector] Nostr connection error:", error);
|
|
168
|
-
// Provide more specific error messages
|
|
169
|
-
if (error.message && error.message.includes("User rejected")) {
|
|
170
|
-
throw new Error("Nostr connection was rejected by the user");
|
|
171
|
-
}
|
|
172
|
-
else if (error.message && error.message.includes("not available")) {
|
|
173
|
-
throw new Error("Nostr extension is not available or not properly installed");
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
throw new Error(`Nostr connection error: ${error.message}`);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Set up manual key pair for connection
|
|
182
|
-
*/
|
|
183
|
-
async connectManual() {
|
|
184
|
-
// For manual connection, we'd need to have a keypair set
|
|
185
|
-
if (!this.manualKeyPair) {
|
|
186
|
-
return {
|
|
187
|
-
success: false,
|
|
188
|
-
error: "No manual key pair configured. Use setKeyPair() first.",
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
this.connectedAddress = this.manualKeyPair.address;
|
|
192
|
-
this.connectedType = "manual";
|
|
193
|
-
// Emit connected event
|
|
194
|
-
this.emit("connected", {
|
|
195
|
-
address: this.manualKeyPair.address,
|
|
196
|
-
type: "manual",
|
|
197
|
-
});
|
|
198
|
-
const username = `btc_${this.manualKeyPair.address.substring(0, 10)}`;
|
|
199
|
-
return {
|
|
200
|
-
success: true,
|
|
201
|
-
address: this.manualKeyPair.address,
|
|
202
|
-
username,
|
|
203
|
-
extensionType: "manual",
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Set a manual key pair for use
|
|
208
|
-
*/
|
|
209
|
-
setKeyPair(keyPair) {
|
|
210
|
-
this.manualKeyPair = keyPair;
|
|
211
|
-
if (keyPair.address) {
|
|
212
|
-
this.connectedAddress = keyPair.address;
|
|
213
|
-
this.connectedType = "manual";
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Generate credentials using Nostr: username deterministico e chiave GunDB derivata dall'address
|
|
218
|
-
*/
|
|
219
|
-
async generateCredentials(address, signature, message) {
|
|
220
|
-
const username = (0, validation_1.generateUsernameFromIdentity)("nostr", { id: address });
|
|
221
|
-
// Usa un hashing robusto di address con keccak256
|
|
222
|
-
const hashedAddress = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(address));
|
|
223
|
-
// Include la signature nel salt per aggiungere un ulteriore livello di sicurezza
|
|
224
|
-
const salt = `${username}_${address}_${message}_${signature}`;
|
|
225
|
-
const key = await (0, derive_1.default)(hashedAddress, salt, { includeP256: true });
|
|
226
|
-
return { username, key, message, signature };
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Generate a password from a signature
|
|
230
|
-
*/
|
|
231
|
-
async generatePassword(signature) {
|
|
232
|
-
if (!signature) {
|
|
233
|
-
throw new Error("Invalid signature");
|
|
234
|
-
}
|
|
235
|
-
try {
|
|
236
|
-
// Create a deterministic hash from the signature using a secure algorithm
|
|
237
|
-
const normalizedSig = signature.toLowerCase().replace(/[^a-f0-9]/g, "");
|
|
238
|
-
const passwordHash = ethers_1.ethers.sha256(ethers_1.ethers.toUtf8Bytes(normalizedSig));
|
|
239
|
-
return passwordHash;
|
|
240
|
-
}
|
|
241
|
-
catch (error) {
|
|
242
|
-
console.error("Error generating password:", error);
|
|
243
|
-
throw new Error("Failed to generate password from signature");
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* Verify a signature
|
|
248
|
-
*/
|
|
249
|
-
async verifySignature(message, signature, address) {
|
|
250
|
-
try {
|
|
251
|
-
// Ensure address is a string
|
|
252
|
-
const addressStr = typeof address === "object"
|
|
253
|
-
? address.address || JSON.stringify(address)
|
|
254
|
-
: String(address);
|
|
255
|
-
console.log(`Verifying signature for address: ${addressStr}`);
|
|
256
|
-
if (!signature || !message || !addressStr) {
|
|
257
|
-
console.error("Invalid message, signature, or address for verification");
|
|
258
|
-
return false;
|
|
259
|
-
}
|
|
260
|
-
// For Nostr wallet type, use nostr-tools for verification
|
|
261
|
-
if (this.connectedType === "nostr" || this.connectedType === "alby") {
|
|
262
|
-
try {
|
|
263
|
-
// Reconstruct the exact event that was signed
|
|
264
|
-
const eventData = {
|
|
265
|
-
kind: 1,
|
|
266
|
-
created_at: 0, // IMPORTANT: Use the same fixed timestamp used for signing
|
|
267
|
-
tags: [],
|
|
268
|
-
content: message,
|
|
269
|
-
pubkey: addressStr,
|
|
270
|
-
};
|
|
271
|
-
const event = {
|
|
272
|
-
...eventData,
|
|
273
|
-
id: (0, nostr_tools_1.getEventHash)(eventData),
|
|
274
|
-
sig: signature,
|
|
275
|
-
};
|
|
276
|
-
return (0, nostr_tools_1.verifyEvent)(event);
|
|
277
|
-
}
|
|
278
|
-
catch (verifyError) {
|
|
279
|
-
console.error("Error in Nostr signature verification:", verifyError);
|
|
280
|
-
return false;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
else if (this.connectedType === "manual" && this.manualKeyPair) {
|
|
284
|
-
console.log("[nostrConnector] Manual verification for keypair");
|
|
285
|
-
// For manual keypairs, we MUST use a secure verification method.
|
|
286
|
-
if (!this.manualKeyPair.privateKey) {
|
|
287
|
-
console.error("Manual verification failed: private key is missing.");
|
|
288
|
-
return false;
|
|
289
|
-
}
|
|
290
|
-
try {
|
|
291
|
-
const eventData = {
|
|
292
|
-
kind: 1,
|
|
293
|
-
created_at: 0, // IMPORTANT: Use the same fixed timestamp used for signing
|
|
294
|
-
tags: [],
|
|
295
|
-
content: message,
|
|
296
|
-
pubkey: addressStr,
|
|
297
|
-
};
|
|
298
|
-
const event = {
|
|
299
|
-
...eventData,
|
|
300
|
-
id: (0, nostr_tools_1.getEventHash)(eventData),
|
|
301
|
-
sig: signature,
|
|
302
|
-
};
|
|
303
|
-
return (0, nostr_tools_1.verifyEvent)(event);
|
|
304
|
-
}
|
|
305
|
-
catch (manualVerifyError) {
|
|
306
|
-
console.error("Error in manual signature verification:", manualVerifyError);
|
|
307
|
-
return false;
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
console.warn("No specific verification method available, signature cannot be fully verified");
|
|
311
|
-
return false;
|
|
312
|
-
}
|
|
313
|
-
catch (error) {
|
|
314
|
-
console.error("Error verifying signature:", error);
|
|
315
|
-
return false;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
/**
|
|
319
|
-
* Get the currently connected address
|
|
320
|
-
*/
|
|
321
|
-
getConnectedAddress() {
|
|
322
|
-
return this.connectedAddress;
|
|
323
|
-
}
|
|
324
|
-
/**
|
|
325
|
-
* Get the currently connected wallet type
|
|
326
|
-
*/
|
|
327
|
-
getConnectedType() {
|
|
328
|
-
return this.connectedType;
|
|
329
|
-
}
|
|
330
|
-
/**
|
|
331
|
-
* Request a signature from the connected wallet
|
|
332
|
-
*/
|
|
333
|
-
async requestSignature(address, message) {
|
|
334
|
-
if (!this.connectedType) {
|
|
335
|
-
throw new Error("No wallet connected");
|
|
336
|
-
}
|
|
337
|
-
try {
|
|
338
|
-
switch (this.connectedType) {
|
|
339
|
-
case "alby":
|
|
340
|
-
case "nostr":
|
|
341
|
-
if (this.connectedType === "alby") {
|
|
342
|
-
console.warn("Alby is deprecated, using Nostr functionality for signature request");
|
|
343
|
-
}
|
|
344
|
-
console.log("[nostrConnector] Requesting Nostr signature for message:", message);
|
|
345
|
-
if (!window.nostr) {
|
|
346
|
-
throw new Error("Nostr extension not available");
|
|
347
|
-
}
|
|
348
|
-
// For Nostr, we need to create an event to sign with a fixed timestamp
|
|
349
|
-
const eventData = {
|
|
350
|
-
kind: 1,
|
|
351
|
-
created_at: 0, // IMPORTANT: Use a fixed timestamp to make signatures verifiable
|
|
352
|
-
tags: [],
|
|
353
|
-
content: message,
|
|
354
|
-
pubkey: address,
|
|
355
|
-
};
|
|
356
|
-
const nostrEvent = {
|
|
357
|
-
...eventData,
|
|
358
|
-
id: (0, nostr_tools_1.getEventHash)(eventData),
|
|
359
|
-
sig: "", // This will be filled by window.nostr.signEvent
|
|
360
|
-
};
|
|
361
|
-
const signedEvent = await window.nostr.signEvent(nostrEvent);
|
|
362
|
-
console.log("Received Nostr signature:", signedEvent.sig.substring(0, 20) + "...");
|
|
363
|
-
return signedEvent.sig;
|
|
364
|
-
case "manual":
|
|
365
|
-
console.log("[nostrConnector] Using manual key pair for signature");
|
|
366
|
-
if (!this.manualKeyPair || !this.manualKeyPair.privateKey) {
|
|
367
|
-
throw new Error("No manual key pair available or private key missing");
|
|
368
|
-
}
|
|
369
|
-
// Use nostr-tools to sign securely
|
|
370
|
-
const manualEventData = {
|
|
371
|
-
kind: 1,
|
|
372
|
-
created_at: 0, // IMPORTANT: Use a fixed timestamp
|
|
373
|
-
tags: [],
|
|
374
|
-
content: message,
|
|
375
|
-
pubkey: this.manualKeyPair.address,
|
|
376
|
-
};
|
|
377
|
-
const eventTemplate = {
|
|
378
|
-
...manualEventData,
|
|
379
|
-
id: (0, nostr_tools_1.getEventHash)(manualEventData),
|
|
380
|
-
sig: "", // This will be filled by finalizeEvent
|
|
381
|
-
};
|
|
382
|
-
const privateKeyBytes = nostr_tools_1.utils.hexToBytes(this.manualKeyPair.privateKey);
|
|
383
|
-
const signedEventManual = await (0, nostr_tools_1.finalizeEvent)(eventTemplate, privateKeyBytes);
|
|
384
|
-
console.log("Generated manual signature:", signedEventManual.sig.substring(0, 20) + "...");
|
|
385
|
-
return signedEventManual.sig;
|
|
386
|
-
default:
|
|
387
|
-
throw new Error(`Unsupported wallet type: ${this.connectedType}`);
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
catch (error) {
|
|
391
|
-
console.error("Error requesting signature:", error);
|
|
392
|
-
throw new Error(`Failed to get signature: ${error.message}`);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
* Cleanup event listeners
|
|
397
|
-
*/
|
|
398
|
-
cleanup() {
|
|
399
|
-
this.removeAllListeners();
|
|
400
|
-
this.connectedAddress = null;
|
|
401
|
-
this.connectedType = null;
|
|
402
|
-
this.manualKeyPair = null;
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
exports.NostrConnector = NostrConnector;
|
|
406
|
-
// Funzione helper per derivare chiavi Nostr/Bitcoin (come per Web3/WebAuthn)
|
|
407
|
-
async function deriveNostrKeys(address, signature, message) {
|
|
408
|
-
// Usa solo l'address per rendere le credenziali deterministiche
|
|
409
|
-
const salt = `${address}_${message}`;
|
|
410
|
-
return await (0, derive_1.default)(address, salt, {
|
|
411
|
-
includeP256: true,
|
|
412
|
-
});
|
|
413
|
-
}
|
|
414
|
-
if (typeof window !== "undefined") {
|
|
415
|
-
window.NostrConnector = NostrConnector;
|
|
416
|
-
}
|
|
417
|
-
else if (typeof global !== "undefined") {
|
|
418
|
-
global.NostrConnector = NostrConnector;
|
|
419
|
-
}
|