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.
- 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 +138850 -146638
- 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 -370
- 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
|
@@ -0,0 +1,663 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
if (typeof b !== "function" && b !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
+
extendStatics(d, b);
|
|
12
|
+
function __() { this.constructor = d; }
|
|
13
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
var __assign = (this && this.__assign) || function () {
|
|
17
|
+
__assign = Object.assign || function(t) {
|
|
18
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
19
|
+
s = arguments[i];
|
|
20
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
21
|
+
t[p] = s[p];
|
|
22
|
+
}
|
|
23
|
+
return t;
|
|
24
|
+
};
|
|
25
|
+
return __assign.apply(this, arguments);
|
|
26
|
+
};
|
|
27
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
28
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
29
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
30
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
31
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
32
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
33
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
37
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
38
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
39
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
40
|
+
function step(op) {
|
|
41
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
42
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
43
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
44
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
45
|
+
switch (op[0]) {
|
|
46
|
+
case 0: case 1: t = op; break;
|
|
47
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
48
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
49
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
50
|
+
default:
|
|
51
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
52
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
53
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
54
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
55
|
+
if (t[2]) _.ops.pop();
|
|
56
|
+
_.trys.pop(); continue;
|
|
57
|
+
}
|
|
58
|
+
op = body.call(thisArg, _);
|
|
59
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
60
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
64
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
65
|
+
if (!m) return o;
|
|
66
|
+
var i = m.call(o), r, ar = [], e;
|
|
67
|
+
try {
|
|
68
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
69
|
+
}
|
|
70
|
+
catch (error) { e = { error: error }; }
|
|
71
|
+
finally {
|
|
72
|
+
try {
|
|
73
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
74
|
+
}
|
|
75
|
+
finally { if (e) throw e.error; }
|
|
76
|
+
}
|
|
77
|
+
return ar;
|
|
78
|
+
};
|
|
79
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
80
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
81
|
+
if (ar || !(i in from)) {
|
|
82
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
83
|
+
ar[i] = from[i];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
87
|
+
};
|
|
88
|
+
import { BasePlugin } from "../base.js";
|
|
89
|
+
import { NostrConnector, MESSAGE_TO_SIGN, deriveNostrKeys, } from "./nostrConnector.js";
|
|
90
|
+
import { NostrSigner } from "./nostrSigner.js";
|
|
91
|
+
import { ErrorHandler, ErrorType, createError } from "../../utils/errorHandler.js";
|
|
92
|
+
/**
|
|
93
|
+
* Plugin for managing Bitcoin wallet functionality in ShogunCore
|
|
94
|
+
* Supports Alby, Nostr extensions, or direct key management
|
|
95
|
+
*/
|
|
96
|
+
var NostrConnectorPlugin = /** @class */ (function (_super) {
|
|
97
|
+
__extends(NostrConnectorPlugin, _super);
|
|
98
|
+
function NostrConnectorPlugin() {
|
|
99
|
+
var _this = _super.apply(this, __spreadArray([], __read(arguments), false)) || this;
|
|
100
|
+
_this.name = "nostr";
|
|
101
|
+
_this.version = "1.0.0";
|
|
102
|
+
_this.description = "Provides Bitcoin wallet connection and authentication for ShogunCore";
|
|
103
|
+
_this.bitcoinConnector = null;
|
|
104
|
+
_this.signer = null;
|
|
105
|
+
return _this;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* @inheritdoc
|
|
109
|
+
*/
|
|
110
|
+
NostrConnectorPlugin.prototype.initialize = function (core) {
|
|
111
|
+
_super.prototype.initialize.call(this, core);
|
|
112
|
+
// Initialize the Bitcoin wallet module
|
|
113
|
+
this.bitcoinConnector = new NostrConnector();
|
|
114
|
+
this.signer = new NostrSigner(this.bitcoinConnector);
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* @inheritdoc
|
|
118
|
+
*/
|
|
119
|
+
NostrConnectorPlugin.prototype.destroy = function () {
|
|
120
|
+
if (this.bitcoinConnector) {
|
|
121
|
+
this.bitcoinConnector.cleanup();
|
|
122
|
+
}
|
|
123
|
+
this.bitcoinConnector = null;
|
|
124
|
+
this.signer = null;
|
|
125
|
+
_super.prototype.destroy.call(this);
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Ensure that the Bitcoin wallet module is initialized
|
|
129
|
+
* @private
|
|
130
|
+
*/
|
|
131
|
+
NostrConnectorPlugin.prototype.assertBitcoinConnector = function () {
|
|
132
|
+
this.assertInitialized();
|
|
133
|
+
if (!this.bitcoinConnector) {
|
|
134
|
+
throw new Error("Bitcoin wallet module not initialized");
|
|
135
|
+
}
|
|
136
|
+
return this.bitcoinConnector;
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Assicura che il signer sia inizializzato
|
|
140
|
+
* @private
|
|
141
|
+
*/
|
|
142
|
+
NostrConnectorPlugin.prototype.assertSigner = function () {
|
|
143
|
+
this.assertInitialized();
|
|
144
|
+
if (!this.signer) {
|
|
145
|
+
throw new Error("Nostr signer not initialized");
|
|
146
|
+
}
|
|
147
|
+
return this.signer;
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* @inheritdoc
|
|
151
|
+
*/
|
|
152
|
+
NostrConnectorPlugin.prototype.isAvailable = function () {
|
|
153
|
+
return this.assertBitcoinConnector().isAvailable();
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Check if Nostr extension is available
|
|
157
|
+
*/
|
|
158
|
+
NostrConnectorPlugin.prototype.isNostrExtensionAvailable = function () {
|
|
159
|
+
return this.assertBitcoinConnector().isNostrExtensionAvailable();
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Connect to Nostr wallet automatically
|
|
163
|
+
* This is a convenience method for easy wallet connection
|
|
164
|
+
*/
|
|
165
|
+
NostrConnectorPlugin.prototype.connectNostrWallet = function () {
|
|
166
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
167
|
+
var result, error_1;
|
|
168
|
+
return __generator(this, function (_a) {
|
|
169
|
+
switch (_a.label) {
|
|
170
|
+
case 0:
|
|
171
|
+
_a.trys.push([0, 2, , 3]);
|
|
172
|
+
if (!this.isNostrExtensionAvailable()) {
|
|
173
|
+
return [2 /*return*/, {
|
|
174
|
+
success: false,
|
|
175
|
+
error: "Nostr extension not available. Please install a Nostr extension like nos2x, Alby, or Coracle.",
|
|
176
|
+
}];
|
|
177
|
+
}
|
|
178
|
+
return [4 /*yield*/, this.connectBitcoinWallet("nostr")];
|
|
179
|
+
case 1:
|
|
180
|
+
result = _a.sent();
|
|
181
|
+
if (result.success) {
|
|
182
|
+
}
|
|
183
|
+
return [2 /*return*/, result];
|
|
184
|
+
case 2:
|
|
185
|
+
error_1 = _a.sent();
|
|
186
|
+
console.error("[nostrConnectorPlugin] Error connecting to Nostr wallet:", error_1);
|
|
187
|
+
return [2 /*return*/, {
|
|
188
|
+
success: false,
|
|
189
|
+
error: error_1.message || "Unknown error connecting to Nostr wallet",
|
|
190
|
+
}];
|
|
191
|
+
case 3: return [2 /*return*/];
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* @inheritdoc
|
|
198
|
+
*/
|
|
199
|
+
NostrConnectorPlugin.prototype.connectBitcoinWallet = function () {
|
|
200
|
+
return __awaiter(this, arguments, void 0, function (type) {
|
|
201
|
+
if (type === void 0) { type = "nostr"; }
|
|
202
|
+
return __generator(this, function (_a) {
|
|
203
|
+
// Prioritize nostr over alby (since they are functionally identical)
|
|
204
|
+
// If type is alby, try to use nostr instead
|
|
205
|
+
if (type === "alby") {
|
|
206
|
+
type = "nostr";
|
|
207
|
+
}
|
|
208
|
+
return [2 /*return*/, this.assertBitcoinConnector().connectWallet(type)];
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* @inheritdoc
|
|
214
|
+
*/
|
|
215
|
+
NostrConnectorPlugin.prototype.generateCredentials = function (address, signature, message) {
|
|
216
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
217
|
+
return __generator(this, function (_a) {
|
|
218
|
+
return [2 /*return*/, this.assertBitcoinConnector().generateCredentials(address, signature, message)];
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
};
|
|
222
|
+
/**
|
|
223
|
+
* @inheritdoc
|
|
224
|
+
*/
|
|
225
|
+
NostrConnectorPlugin.prototype.cleanup = function () {
|
|
226
|
+
this.assertBitcoinConnector().cleanup();
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
229
|
+
* @inheritdoc
|
|
230
|
+
*/
|
|
231
|
+
NostrConnectorPlugin.prototype.verifySignature = function (message, signature, address) {
|
|
232
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
233
|
+
return __generator(this, function (_a) {
|
|
234
|
+
return [2 /*return*/, this.assertBitcoinConnector().verifySignature(message, signature, address)];
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
/**
|
|
239
|
+
* @inheritdoc
|
|
240
|
+
*/
|
|
241
|
+
NostrConnectorPlugin.prototype.generatePassword = function (signature) {
|
|
242
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
243
|
+
return __generator(this, function (_a) {
|
|
244
|
+
return [2 /*return*/, this.assertBitcoinConnector().generatePassword(signature)];
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
};
|
|
248
|
+
// === NOSTR SIGNER METHODS ===
|
|
249
|
+
/**
|
|
250
|
+
* Creates a new Nostr signing credential
|
|
251
|
+
* CONSISTENT with normal Nostr approach
|
|
252
|
+
*/
|
|
253
|
+
NostrConnectorPlugin.prototype.createSigningCredential = function (address) {
|
|
254
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
255
|
+
var conn, error_2;
|
|
256
|
+
return __generator(this, function (_a) {
|
|
257
|
+
switch (_a.label) {
|
|
258
|
+
case 0:
|
|
259
|
+
_a.trys.push([0, 4, , 5]);
|
|
260
|
+
conn = this.assertBitcoinConnector();
|
|
261
|
+
if (!(typeof conn.createSigningCredential === "function")) return [3 /*break*/, 2];
|
|
262
|
+
return [4 /*yield*/, conn.createSigningCredential(address)];
|
|
263
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
264
|
+
case 2: return [4 /*yield*/, this.assertSigner().createSigningCredential(address)];
|
|
265
|
+
case 3: return [2 /*return*/, _a.sent()];
|
|
266
|
+
case 4:
|
|
267
|
+
error_2 = _a.sent();
|
|
268
|
+
console.error("Error creating Nostr signing credential: ".concat(error_2.message));
|
|
269
|
+
throw error_2;
|
|
270
|
+
case 5: return [2 /*return*/];
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
};
|
|
275
|
+
/**
|
|
276
|
+
* Creates an authenticator function for Nostr signing
|
|
277
|
+
*/
|
|
278
|
+
NostrConnectorPlugin.prototype.createAuthenticator = function (address) {
|
|
279
|
+
try {
|
|
280
|
+
var conn = this.assertBitcoinConnector();
|
|
281
|
+
if (typeof conn.createAuthenticator === "function") {
|
|
282
|
+
return conn.createAuthenticator(address);
|
|
283
|
+
}
|
|
284
|
+
return this.assertSigner().createAuthenticator(address);
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
console.error("Error creating Nostr authenticator: ".concat(error.message));
|
|
288
|
+
throw error;
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
/**
|
|
292
|
+
* Creates a derived key pair from Nostr credential
|
|
293
|
+
*/
|
|
294
|
+
NostrConnectorPlugin.prototype.createDerivedKeyPair = function (address, extra) {
|
|
295
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
296
|
+
var conn, error_3;
|
|
297
|
+
return __generator(this, function (_a) {
|
|
298
|
+
switch (_a.label) {
|
|
299
|
+
case 0:
|
|
300
|
+
_a.trys.push([0, 4, , 5]);
|
|
301
|
+
conn = this.assertBitcoinConnector();
|
|
302
|
+
if (!(typeof conn.createDerivedKeyPair === "function")) return [3 /*break*/, 2];
|
|
303
|
+
return [4 /*yield*/, conn.createDerivedKeyPair(address, extra)];
|
|
304
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
305
|
+
case 2: return [4 /*yield*/, this.assertSigner().createDerivedKeyPair(address, extra)];
|
|
306
|
+
case 3: return [2 /*return*/, _a.sent()];
|
|
307
|
+
case 4:
|
|
308
|
+
error_3 = _a.sent();
|
|
309
|
+
console.error("Error creating derived key pair: ".concat(error_3.message));
|
|
310
|
+
throw error_3;
|
|
311
|
+
case 5: return [2 /*return*/];
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
};
|
|
316
|
+
/**
|
|
317
|
+
* Signs data with derived keys after Nostr verification
|
|
318
|
+
*/
|
|
319
|
+
NostrConnectorPlugin.prototype.signWithDerivedKeys = function (data, address, extra) {
|
|
320
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
321
|
+
var conn, error_4;
|
|
322
|
+
return __generator(this, function (_a) {
|
|
323
|
+
switch (_a.label) {
|
|
324
|
+
case 0:
|
|
325
|
+
_a.trys.push([0, 4, , 5]);
|
|
326
|
+
conn = this.assertBitcoinConnector();
|
|
327
|
+
if (!(typeof conn.signWithDerivedKeys === "function")) return [3 /*break*/, 2];
|
|
328
|
+
return [4 /*yield*/, conn.signWithDerivedKeys(data, address, extra)];
|
|
329
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
330
|
+
case 2: return [4 /*yield*/, this.assertSigner().signWithDerivedKeys(data, address, extra)];
|
|
331
|
+
case 3: return [2 /*return*/, _a.sent()];
|
|
332
|
+
case 4:
|
|
333
|
+
error_4 = _a.sent();
|
|
334
|
+
console.error("Error signing with derived keys: ".concat(error_4.message));
|
|
335
|
+
throw error_4;
|
|
336
|
+
case 5: return [2 /*return*/];
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
};
|
|
341
|
+
/**
|
|
342
|
+
* Get signing credential by address
|
|
343
|
+
*/
|
|
344
|
+
NostrConnectorPlugin.prototype.getSigningCredential = function (address) {
|
|
345
|
+
var conn = this.assertBitcoinConnector();
|
|
346
|
+
if (typeof conn.getSigningCredential === "function") {
|
|
347
|
+
return conn.getSigningCredential(address);
|
|
348
|
+
}
|
|
349
|
+
return this.assertSigner().getCredential(address);
|
|
350
|
+
};
|
|
351
|
+
/**
|
|
352
|
+
* List all signing credentials
|
|
353
|
+
*/
|
|
354
|
+
NostrConnectorPlugin.prototype.listSigningCredentials = function () {
|
|
355
|
+
var conn = this.assertBitcoinConnector();
|
|
356
|
+
if (typeof conn.listSigningCredentials === "function") {
|
|
357
|
+
return conn.listSigningCredentials();
|
|
358
|
+
}
|
|
359
|
+
return this.assertSigner().listCredentials();
|
|
360
|
+
};
|
|
361
|
+
/**
|
|
362
|
+
* Remove a signing credential
|
|
363
|
+
*/
|
|
364
|
+
NostrConnectorPlugin.prototype.removeSigningCredential = function (address) {
|
|
365
|
+
var conn = this.assertBitcoinConnector();
|
|
366
|
+
if (typeof conn.removeSigningCredential === "function") {
|
|
367
|
+
return conn.removeSigningCredential(address);
|
|
368
|
+
}
|
|
369
|
+
return this.assertSigner().removeCredential(address);
|
|
370
|
+
};
|
|
371
|
+
// === CONSISTENCY METHODS ===
|
|
372
|
+
/**
|
|
373
|
+
* Creates a Gun user from Nostr signing credential
|
|
374
|
+
* This ensures the SAME user is created as with normal approach
|
|
375
|
+
*/
|
|
376
|
+
NostrConnectorPlugin.prototype.createGunUserFromSigningCredential = function (address) {
|
|
377
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
378
|
+
var conn, core, error_5;
|
|
379
|
+
return __generator(this, function (_a) {
|
|
380
|
+
switch (_a.label) {
|
|
381
|
+
case 0:
|
|
382
|
+
_a.trys.push([0, 4, , 5]);
|
|
383
|
+
conn = this.assertBitcoinConnector();
|
|
384
|
+
if (!(typeof conn.createGunUserFromSigningCredential === "function")) return [3 /*break*/, 2];
|
|
385
|
+
return [4 /*yield*/, conn.createGunUserFromSigningCredential(address)];
|
|
386
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
387
|
+
case 2:
|
|
388
|
+
core = this.assertInitialized();
|
|
389
|
+
return [4 /*yield*/, this.assertSigner().createGunUser(address, core.gun)];
|
|
390
|
+
case 3: return [2 /*return*/, _a.sent()];
|
|
391
|
+
case 4:
|
|
392
|
+
error_5 = _a.sent();
|
|
393
|
+
console.error("Error creating Gun user from Nostr signing credential: ".concat(error_5.message));
|
|
394
|
+
throw error_5;
|
|
395
|
+
case 5: return [2 /*return*/];
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
});
|
|
399
|
+
};
|
|
400
|
+
/**
|
|
401
|
+
* Get the Gun user public key for a signing credential
|
|
402
|
+
*/
|
|
403
|
+
NostrConnectorPlugin.prototype.getGunUserPubFromSigningCredential = function (address) {
|
|
404
|
+
var conn = this.assertBitcoinConnector();
|
|
405
|
+
if (typeof conn.getGunUserPubFromSigningCredential === "function") {
|
|
406
|
+
return conn.getGunUserPubFromSigningCredential(address);
|
|
407
|
+
}
|
|
408
|
+
return this.assertSigner().getGunUserPub(address);
|
|
409
|
+
};
|
|
410
|
+
/**
|
|
411
|
+
* Get the password (for consistency checking)
|
|
412
|
+
*/
|
|
413
|
+
NostrConnectorPlugin.prototype.getPassword = function (address) {
|
|
414
|
+
var conn = this.assertBitcoinConnector();
|
|
415
|
+
if (typeof conn.getPassword === "function") {
|
|
416
|
+
return conn.getPassword(address);
|
|
417
|
+
}
|
|
418
|
+
return this.assertSigner().getPassword(address);
|
|
419
|
+
};
|
|
420
|
+
/**
|
|
421
|
+
* Verify consistency between oneshot and normal approaches
|
|
422
|
+
* This ensures both approaches create the same Gun user
|
|
423
|
+
*/
|
|
424
|
+
NostrConnectorPlugin.prototype.verifyConsistency = function (address, expectedUserPub) {
|
|
425
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
426
|
+
var conn, error_6;
|
|
427
|
+
return __generator(this, function (_a) {
|
|
428
|
+
switch (_a.label) {
|
|
429
|
+
case 0:
|
|
430
|
+
_a.trys.push([0, 4, , 5]);
|
|
431
|
+
conn = this.assertBitcoinConnector();
|
|
432
|
+
if (!(typeof conn.verifyConsistency === "function")) return [3 /*break*/, 2];
|
|
433
|
+
return [4 /*yield*/, conn.verifyConsistency(address, expectedUserPub)];
|
|
434
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
435
|
+
case 2: return [4 /*yield*/, this.assertSigner().verifyConsistency(address, expectedUserPub)];
|
|
436
|
+
case 3: return [2 /*return*/, _a.sent()];
|
|
437
|
+
case 4:
|
|
438
|
+
error_6 = _a.sent();
|
|
439
|
+
console.error("Error verifying Nostr consistency: ".concat(error_6.message));
|
|
440
|
+
return [2 /*return*/, { consistent: false }];
|
|
441
|
+
case 5: return [2 /*return*/];
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
});
|
|
445
|
+
};
|
|
446
|
+
/**
|
|
447
|
+
* Complete oneshot workflow that creates the SAME Gun user as normal approach
|
|
448
|
+
* This is the recommended method for oneshot signing with full consistency
|
|
449
|
+
*/
|
|
450
|
+
NostrConnectorPlugin.prototype.setupConsistentOneshotSigning = function (address) {
|
|
451
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
452
|
+
var conn, credential, authenticator, gunUser, error_7;
|
|
453
|
+
return __generator(this, function (_a) {
|
|
454
|
+
switch (_a.label) {
|
|
455
|
+
case 0:
|
|
456
|
+
_a.trys.push([0, 5, , 6]);
|
|
457
|
+
conn = this.assertBitcoinConnector();
|
|
458
|
+
if (!(typeof conn.setupConsistentOneshotSigning === "function")) return [3 /*break*/, 2];
|
|
459
|
+
return [4 /*yield*/, conn.setupConsistentOneshotSigning(address)];
|
|
460
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
461
|
+
case 2: return [4 /*yield*/, this.createSigningCredential(address)];
|
|
462
|
+
case 3:
|
|
463
|
+
credential = _a.sent();
|
|
464
|
+
authenticator = this.createAuthenticator(address);
|
|
465
|
+
return [4 /*yield*/, this.createGunUserFromSigningCredential(address)];
|
|
466
|
+
case 4:
|
|
467
|
+
gunUser = _a.sent();
|
|
468
|
+
return [2 /*return*/, {
|
|
469
|
+
credential: credential,
|
|
470
|
+
authenticator: authenticator,
|
|
471
|
+
gunUser: gunUser,
|
|
472
|
+
username: credential.username,
|
|
473
|
+
password: credential.password,
|
|
474
|
+
}];
|
|
475
|
+
case 5:
|
|
476
|
+
error_7 = _a.sent();
|
|
477
|
+
console.error("Error setting up consistent Nostr oneshot signing: ".concat(error_7.message));
|
|
478
|
+
throw error_7;
|
|
479
|
+
case 6: return [2 /*return*/];
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
});
|
|
483
|
+
};
|
|
484
|
+
// === EXISTING METHODS ===
|
|
485
|
+
/**
|
|
486
|
+
* Login with Bitcoin wallet
|
|
487
|
+
* @param address - Bitcoin address
|
|
488
|
+
* @returns {Promise<AuthResult>} Authentication result
|
|
489
|
+
* @description Authenticates the user using Bitcoin wallet credentials after signature verification
|
|
490
|
+
*/
|
|
491
|
+
NostrConnectorPlugin.prototype.login = function (address) {
|
|
492
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
493
|
+
var core, message, signature, credentials, isValid, k, loginResult, error_8, errorType, errorCode, errorMessage;
|
|
494
|
+
return __generator(this, function (_a) {
|
|
495
|
+
switch (_a.label) {
|
|
496
|
+
case 0:
|
|
497
|
+
_a.trys.push([0, 6, , 7]);
|
|
498
|
+
core = this.assertInitialized();
|
|
499
|
+
if (!address) {
|
|
500
|
+
throw createError(ErrorType.VALIDATION, "ADDRESS_REQUIRED", "Bitcoin address required for login");
|
|
501
|
+
}
|
|
502
|
+
if (!this.isAvailable()) {
|
|
503
|
+
throw createError(ErrorType.ENVIRONMENT, "BITCOIN_WALLET_UNAVAILABLE", "No Bitcoin wallet available in the browser");
|
|
504
|
+
}
|
|
505
|
+
message = MESSAGE_TO_SIGN;
|
|
506
|
+
return [4 /*yield*/, this.assertBitcoinConnector().requestSignature(address, message)];
|
|
507
|
+
case 1:
|
|
508
|
+
signature = _a.sent();
|
|
509
|
+
return [4 /*yield*/, this.generateCredentials(address, signature, message)];
|
|
510
|
+
case 2:
|
|
511
|
+
credentials = _a.sent();
|
|
512
|
+
if (!(credentials === null || credentials === void 0 ? void 0 : credentials.username) ||
|
|
513
|
+
!(credentials === null || credentials === void 0 ? void 0 : credentials.key) ||
|
|
514
|
+
!credentials.message ||
|
|
515
|
+
!credentials.signature) {
|
|
516
|
+
throw createError(ErrorType.AUTHENTICATION, "CREDENTIAL_GENERATION_FAILED", "Bitcoin wallet credentials not generated correctly or signature missing");
|
|
517
|
+
}
|
|
518
|
+
return [4 /*yield*/, this.verifySignature(credentials.message, credentials.signature, address)];
|
|
519
|
+
case 3:
|
|
520
|
+
isValid = _a.sent();
|
|
521
|
+
if (!isValid) {
|
|
522
|
+
console.error("Signature verification failed for address: ".concat(address));
|
|
523
|
+
throw createError(ErrorType.SECURITY, "SIGNATURE_VERIFICATION_FAILED", "Bitcoin wallet signature verification failed");
|
|
524
|
+
}
|
|
525
|
+
return [4 /*yield*/, deriveNostrKeys(address, signature, message)];
|
|
526
|
+
case 4:
|
|
527
|
+
k = _a.sent();
|
|
528
|
+
// Set authentication method to nostr before login
|
|
529
|
+
core.setAuthMethod("nostr");
|
|
530
|
+
return [4 /*yield*/, core.login(credentials.username, "", k)];
|
|
531
|
+
case 5:
|
|
532
|
+
loginResult = _a.sent();
|
|
533
|
+
if (!loginResult.success) {
|
|
534
|
+
throw createError(ErrorType.AUTHENTICATION, "BITCOIN_LOGIN_FAILED", loginResult.error || "Failed to log in with Bitcoin credentials");
|
|
535
|
+
}
|
|
536
|
+
// Emit login event
|
|
537
|
+
core.emit("auth:login", {
|
|
538
|
+
userPub: loginResult.userPub || "",
|
|
539
|
+
username: credentials.username,
|
|
540
|
+
method: "nostr",
|
|
541
|
+
});
|
|
542
|
+
return [2 /*return*/, loginResult];
|
|
543
|
+
case 6:
|
|
544
|
+
error_8 = _a.sent();
|
|
545
|
+
errorType = (error_8 === null || error_8 === void 0 ? void 0 : error_8.type) || ErrorType.AUTHENTICATION;
|
|
546
|
+
errorCode = (error_8 === null || error_8 === void 0 ? void 0 : error_8.code) || "BITCOIN_LOGIN_ERROR";
|
|
547
|
+
errorMessage = (error_8 === null || error_8 === void 0 ? void 0 : error_8.message) || "Unknown error during Bitcoin wallet login";
|
|
548
|
+
ErrorHandler.handle(errorType, errorCode, errorMessage, error_8);
|
|
549
|
+
return [2 /*return*/, { success: false, error: errorMessage }];
|
|
550
|
+
case 7: return [2 /*return*/];
|
|
551
|
+
}
|
|
552
|
+
});
|
|
553
|
+
});
|
|
554
|
+
};
|
|
555
|
+
/**
|
|
556
|
+
* Register new user with Nostr wallet
|
|
557
|
+
* @param address - Nostr address
|
|
558
|
+
* @returns {Promise<SignUpResult>} Registration result
|
|
559
|
+
*/
|
|
560
|
+
NostrConnectorPlugin.prototype.signUp = function (address) {
|
|
561
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
562
|
+
var core, message, signature, credentials, isValid, k, signupResult, authResult, authResult, error_9, errorType, errorCode, errorMessage;
|
|
563
|
+
return __generator(this, function (_a) {
|
|
564
|
+
switch (_a.label) {
|
|
565
|
+
case 0:
|
|
566
|
+
_a.trys.push([0, 11, , 12]);
|
|
567
|
+
core = this.assertInitialized();
|
|
568
|
+
if (!address) {
|
|
569
|
+
throw createError(ErrorType.VALIDATION, "ADDRESS_REQUIRED", "Bitcoin address required for signup");
|
|
570
|
+
}
|
|
571
|
+
if (!this.isAvailable()) {
|
|
572
|
+
throw createError(ErrorType.ENVIRONMENT, "BITCOIN_WALLET_UNAVAILABLE", "No Bitcoin wallet available in the browser");
|
|
573
|
+
}
|
|
574
|
+
message = MESSAGE_TO_SIGN;
|
|
575
|
+
return [4 /*yield*/, this.assertBitcoinConnector().requestSignature(address, message)];
|
|
576
|
+
case 1:
|
|
577
|
+
signature = _a.sent();
|
|
578
|
+
return [4 /*yield*/, this.generateCredentials(address, signature, message)];
|
|
579
|
+
case 2:
|
|
580
|
+
credentials = _a.sent();
|
|
581
|
+
if (!(credentials === null || credentials === void 0 ? void 0 : credentials.username) ||
|
|
582
|
+
!(credentials === null || credentials === void 0 ? void 0 : credentials.key) ||
|
|
583
|
+
!credentials.message ||
|
|
584
|
+
!credentials.signature) {
|
|
585
|
+
throw createError(ErrorType.AUTHENTICATION, "CREDENTIAL_GENERATION_FAILED", "Bitcoin wallet credentials not generated correctly or signature missing");
|
|
586
|
+
}
|
|
587
|
+
return [4 /*yield*/, this.verifySignature(credentials.message, credentials.signature, address)];
|
|
588
|
+
case 3:
|
|
589
|
+
isValid = _a.sent();
|
|
590
|
+
if (!isValid) {
|
|
591
|
+
console.error("Signature verification failed for address: ".concat(address));
|
|
592
|
+
throw createError(ErrorType.SECURITY, "SIGNATURE_VERIFICATION_FAILED", "Bitcoin wallet signature verification failed");
|
|
593
|
+
}
|
|
594
|
+
return [4 /*yield*/, deriveNostrKeys(address, signature, message)];
|
|
595
|
+
case 4:
|
|
596
|
+
k = _a.sent();
|
|
597
|
+
// Set authentication method to nostr before signup
|
|
598
|
+
core.setAuthMethod("nostr");
|
|
599
|
+
return [4 /*yield*/, core.signUp(credentials.username, undefined, k)];
|
|
600
|
+
case 5:
|
|
601
|
+
signupResult = _a.sent();
|
|
602
|
+
if (!signupResult.success) return [3 /*break*/, 7];
|
|
603
|
+
return [4 /*yield*/, core.login(credentials.username, "", k)];
|
|
604
|
+
case 6:
|
|
605
|
+
authResult = _a.sent();
|
|
606
|
+
if (authResult.success) {
|
|
607
|
+
console.log("Bitcoin wallet registration and login completed for user: ".concat(credentials.username));
|
|
608
|
+
// Emetti eventi
|
|
609
|
+
core.emit("auth:signup", {
|
|
610
|
+
userPub: authResult.userPub || "",
|
|
611
|
+
username: credentials.username,
|
|
612
|
+
method: "nostr",
|
|
613
|
+
});
|
|
614
|
+
return [2 /*return*/, __assign({}, authResult)];
|
|
615
|
+
}
|
|
616
|
+
else {
|
|
617
|
+
return [2 /*return*/, __assign(__assign({}, signupResult), { error: "User created but login failed" })];
|
|
618
|
+
}
|
|
619
|
+
return [3 /*break*/, 10];
|
|
620
|
+
case 7:
|
|
621
|
+
if (!(signupResult.error &&
|
|
622
|
+
signupResult.error.toLowerCase().includes("exist"))) return [3 /*break*/, 9];
|
|
623
|
+
return [4 /*yield*/, core.login(credentials.username, "", k)];
|
|
624
|
+
case 8:
|
|
625
|
+
authResult = _a.sent();
|
|
626
|
+
return [2 /*return*/, __assign({}, authResult)];
|
|
627
|
+
case 9: return [2 /*return*/, signupResult];
|
|
628
|
+
case 10: return [3 /*break*/, 12];
|
|
629
|
+
case 11:
|
|
630
|
+
error_9 = _a.sent();
|
|
631
|
+
errorType = (error_9 === null || error_9 === void 0 ? void 0 : error_9.type) || ErrorType.AUTHENTICATION;
|
|
632
|
+
errorCode = (error_9 === null || error_9 === void 0 ? void 0 : error_9.code) || "BITCOIN_SIGNUP_ERROR";
|
|
633
|
+
errorMessage = (error_9 === null || error_9 === void 0 ? void 0 : error_9.message) || "Unknown error during Bitcoin wallet signup";
|
|
634
|
+
ErrorHandler.handle(errorType, errorCode, errorMessage, error_9);
|
|
635
|
+
return [2 /*return*/, { success: false, error: errorMessage }];
|
|
636
|
+
case 12: return [2 /*return*/];
|
|
637
|
+
}
|
|
638
|
+
});
|
|
639
|
+
});
|
|
640
|
+
};
|
|
641
|
+
/**
|
|
642
|
+
* Convenience method that matches the interface pattern
|
|
643
|
+
*/
|
|
644
|
+
NostrConnectorPlugin.prototype.loginWithBitcoinWallet = function (address) {
|
|
645
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
646
|
+
return __generator(this, function (_a) {
|
|
647
|
+
return [2 /*return*/, this.login(address)];
|
|
648
|
+
});
|
|
649
|
+
});
|
|
650
|
+
};
|
|
651
|
+
/**
|
|
652
|
+
* Convenience method that matches the interface pattern
|
|
653
|
+
*/
|
|
654
|
+
NostrConnectorPlugin.prototype.signUpWithBitcoinWallet = function (address) {
|
|
655
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
656
|
+
return __generator(this, function (_a) {
|
|
657
|
+
return [2 /*return*/, this.signUp(address)];
|
|
658
|
+
});
|
|
659
|
+
});
|
|
660
|
+
};
|
|
661
|
+
return NostrConnectorPlugin;
|
|
662
|
+
}(BasePlugin));
|
|
663
|
+
export { NostrConnectorPlugin };
|