shogun-core 2.0.0 → 2.0.3
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/shogun-core.js +74126 -91893
- package/dist/browser/shogun-core.js.map +1 -1
- package/dist/core.js +32 -36
- package/dist/gundb/crypto.js +17 -32
- package/dist/gundb/db.js +35 -82
- package/dist/gundb/derive.js +16 -19
- package/dist/gundb/errors.js +7 -17
- package/dist/gundb/index.js +1 -17
- package/dist/gundb/restricted-put.js +5 -11
- package/dist/gundb/rxjs.js +15 -19
- package/dist/gundb/types.js +1 -2
- package/dist/index.js +9 -34
- package/dist/plugins/base.js +2 -6
- package/dist/plugins/index.js +10 -36
- package/dist/plugins/nostr/index.js +4 -20
- package/dist/plugins/nostr/nostrConnector.js +22 -29
- package/dist/plugins/nostr/nostrConnectorPlugin.js +24 -28
- package/dist/plugins/nostr/nostrSigner.js +8 -15
- package/dist/plugins/nostr/types.js +1 -2
- package/dist/plugins/oauth/index.js +2 -7
- package/dist/plugins/oauth/oauthConnector.js +9 -16
- package/dist/plugins/oauth/oauthPlugin.js +21 -25
- package/dist/plugins/oauth/types.js +1 -2
- package/dist/plugins/web3/index.js +4 -20
- package/dist/plugins/web3/types.js +1 -2
- package/dist/plugins/web3/web3Connector.js +21 -27
- package/dist/plugins/web3/web3ConnectorPlugin.js +17 -21
- package/dist/plugins/web3/web3Signer.js +15 -22
- package/dist/plugins/webauthn/index.js +3 -19
- package/dist/plugins/webauthn/types.js +2 -5
- package/dist/plugins/webauthn/webauthn.js +21 -29
- package/dist/plugins/webauthn/webauthnPlugin.js +9 -13
- package/dist/plugins/webauthn/webauthnSigner.js +12 -19
- package/dist/storage/storage.js +1 -5
- package/dist/types/common.js +1 -2
- package/dist/types/events.js +2 -6
- package/dist/types/gundb/db.d.ts +2 -0
- package/dist/types/plugin.js +1 -2
- package/dist/types/shogun.js +4 -7
- package/dist/utils/errorHandler.js +4 -9
- package/dist/utils/eventEmitter.js +1 -5
- package/dist/utils/validation.js +7 -14
- package/package.json +9 -11
package/dist/gundb/errors.js
CHANGED
|
@@ -1,73 +1,63 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Error classes for Gun and Auth
|
|
4
3
|
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.NetworkError = exports.MultipleAuthError = exports.TimeoutError = exports.UserExists = exports.InvalidCredentials = exports.AuthError = exports.GunError = void 0;
|
|
7
4
|
/**
|
|
8
5
|
* Base error for Gun
|
|
9
6
|
*/
|
|
10
|
-
class GunError extends Error {
|
|
7
|
+
export class GunError extends Error {
|
|
11
8
|
constructor(message) {
|
|
12
9
|
super(message);
|
|
13
10
|
this.name = "GunError";
|
|
14
11
|
}
|
|
15
12
|
}
|
|
16
|
-
exports.GunError = GunError;
|
|
17
13
|
/**
|
|
18
14
|
* Generic authentication error
|
|
19
15
|
*/
|
|
20
|
-
class AuthError extends GunError {
|
|
16
|
+
export class AuthError extends GunError {
|
|
21
17
|
constructor(message) {
|
|
22
18
|
super(message);
|
|
23
19
|
this.name = "AuthError";
|
|
24
20
|
}
|
|
25
21
|
}
|
|
26
|
-
exports.AuthError = AuthError;
|
|
27
22
|
/**
|
|
28
23
|
* Invalid credentials error
|
|
29
24
|
*/
|
|
30
|
-
class InvalidCredentials extends AuthError {
|
|
25
|
+
export class InvalidCredentials extends AuthError {
|
|
31
26
|
constructor(message = "Credenziali non valide") {
|
|
32
27
|
super(message);
|
|
33
28
|
this.name = "InvalidCredentials";
|
|
34
29
|
}
|
|
35
30
|
}
|
|
36
|
-
exports.InvalidCredentials = InvalidCredentials;
|
|
37
31
|
/**
|
|
38
32
|
* User already exists error
|
|
39
33
|
*/
|
|
40
|
-
class UserExists extends AuthError {
|
|
34
|
+
export class UserExists extends AuthError {
|
|
41
35
|
constructor(message = "Utente già esistente") {
|
|
42
36
|
super(message);
|
|
43
37
|
this.name = "UserExists";
|
|
44
38
|
}
|
|
45
39
|
}
|
|
46
|
-
exports.UserExists = UserExists;
|
|
47
40
|
/**
|
|
48
41
|
* Timeout error
|
|
49
42
|
*/
|
|
50
|
-
class TimeoutError extends GunError {
|
|
43
|
+
export class TimeoutError extends GunError {
|
|
51
44
|
constructor(message = "Timeout durante l'operazione") {
|
|
52
45
|
super(message);
|
|
53
46
|
this.name = "TimeoutError";
|
|
54
47
|
}
|
|
55
48
|
}
|
|
56
|
-
exports.TimeoutError = TimeoutError;
|
|
57
49
|
/**
|
|
58
50
|
* Multiple authentication error
|
|
59
51
|
*/
|
|
60
|
-
class MultipleAuthError extends AuthError {
|
|
52
|
+
export class MultipleAuthError extends AuthError {
|
|
61
53
|
constructor(message = "Autenticazione multipla in corso") {
|
|
62
54
|
super(message);
|
|
63
55
|
this.name = "MultipleAuthError";
|
|
64
56
|
}
|
|
65
57
|
}
|
|
66
|
-
exports.MultipleAuthError = MultipleAuthError;
|
|
67
58
|
/** Base error related to the network. */
|
|
68
|
-
class NetworkError extends GunError {
|
|
59
|
+
export class NetworkError extends GunError {
|
|
69
60
|
}
|
|
70
|
-
exports.NetworkError = NetworkError;
|
|
71
61
|
const withDefaultMessage = (args, defaultMessage) => {
|
|
72
62
|
if (args.length === 0 || (args.length === 1 && !args[0])) {
|
|
73
63
|
args = [defaultMessage];
|
package/dist/gundb/index.js
CHANGED
|
@@ -1,18 +1,2 @@
|
|
|
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
1
|
// Export the main class
|
|
18
|
-
|
|
2
|
+
export * from "./db";
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getToken = exports.setToken = exports.restrictedPut = void 0;
|
|
4
1
|
// Functional programming style implementation
|
|
5
2
|
const gunHeaderModule = (Gun) => {
|
|
6
3
|
// Closure for token state
|
|
@@ -52,36 +49,33 @@ let moduleInstance;
|
|
|
52
49
|
* @param Gun - Gun instance
|
|
53
50
|
* @param token - Optional authentication token
|
|
54
51
|
*/
|
|
55
|
-
const restrictedPut = (Gun, token) => {
|
|
52
|
+
export const restrictedPut = (Gun, token) => {
|
|
56
53
|
moduleInstance = gunHeaderModule(Gun);
|
|
57
54
|
if (token) {
|
|
58
55
|
moduleInstance.setToken(token);
|
|
59
56
|
}
|
|
60
57
|
};
|
|
61
|
-
exports.restrictedPut = restrictedPut;
|
|
62
58
|
/**
|
|
63
59
|
* Set the authentication token for Gun requests
|
|
64
60
|
* @param newToken - Token to set
|
|
65
61
|
*/
|
|
66
|
-
const setToken = (newToken) => {
|
|
62
|
+
export const setToken = (newToken) => {
|
|
67
63
|
if (!moduleInstance) {
|
|
68
64
|
throw new Error("Gun headers module not initialized. Call init(Gun, token) first.");
|
|
69
65
|
}
|
|
70
66
|
return moduleInstance.setToken(newToken);
|
|
71
67
|
};
|
|
72
|
-
exports.setToken = setToken;
|
|
73
68
|
/**
|
|
74
69
|
* Get the current authentication token
|
|
75
70
|
*/
|
|
76
|
-
const getToken = () => {
|
|
71
|
+
export const getToken = () => {
|
|
77
72
|
if (!moduleInstance) {
|
|
78
73
|
throw new Error("Gun headers module not initialized. Call init(Gun, token) first.");
|
|
79
74
|
}
|
|
80
75
|
return moduleInstance.getToken();
|
|
81
76
|
};
|
|
82
|
-
exports.getToken = getToken;
|
|
83
77
|
// Export the functions to global window (if in browser environment)
|
|
84
78
|
if (typeof window !== "undefined") {
|
|
85
|
-
window.setToken =
|
|
86
|
-
window.getToken =
|
|
79
|
+
window.setToken = setToken;
|
|
80
|
+
window.getToken = getToken;
|
|
87
81
|
}
|
package/dist/gundb/rxjs.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.RxJS = void 0;
|
|
4
|
-
const rxjs_1 = require("rxjs");
|
|
5
|
-
const operators_1 = require("rxjs/operators");
|
|
1
|
+
import { Observable } from "rxjs";
|
|
2
|
+
import { distinctUntilChanged } from "rxjs/operators";
|
|
6
3
|
/**
|
|
7
4
|
* RxJS Integration for GunDB
|
|
8
5
|
* Provides reactive programming capabilities for GunDB data
|
|
9
6
|
*/
|
|
10
|
-
class RxJS {
|
|
7
|
+
export class RxJS {
|
|
11
8
|
gun;
|
|
12
9
|
user;
|
|
13
10
|
/**
|
|
@@ -38,7 +35,7 @@ class RxJS {
|
|
|
38
35
|
* @returns Observable that emits whenever the node changes
|
|
39
36
|
*/
|
|
40
37
|
observe(path) {
|
|
41
|
-
return new
|
|
38
|
+
return new Observable((subscriber) => {
|
|
42
39
|
let node;
|
|
43
40
|
if (Array.isArray(path)) {
|
|
44
41
|
// Support array paths by chaining get calls
|
|
@@ -75,7 +72,7 @@ class RxJS {
|
|
|
75
72
|
}
|
|
76
73
|
node.off();
|
|
77
74
|
};
|
|
78
|
-
}).pipe(
|
|
75
|
+
}).pipe(distinctUntilChanged((prev, curr) => {
|
|
79
76
|
return JSON.stringify(prev) === JSON.stringify(curr);
|
|
80
77
|
}));
|
|
81
78
|
}
|
|
@@ -86,7 +83,7 @@ class RxJS {
|
|
|
86
83
|
* @returns Observable array of matched items
|
|
87
84
|
*/
|
|
88
85
|
match(path, matchFn) {
|
|
89
|
-
return new
|
|
86
|
+
return new Observable((subscriber) => {
|
|
90
87
|
if (!path) {
|
|
91
88
|
subscriber.next([]);
|
|
92
89
|
subscriber.complete();
|
|
@@ -126,7 +123,7 @@ class RxJS {
|
|
|
126
123
|
* @returns Observable that completes when the put is acknowledged
|
|
127
124
|
*/
|
|
128
125
|
put(path, data) {
|
|
129
|
-
return new
|
|
126
|
+
return new Observable((subscriber) => {
|
|
130
127
|
const performPut = (target, value) => {
|
|
131
128
|
target.put(value, (ack) => {
|
|
132
129
|
if (ack.err) {
|
|
@@ -161,7 +158,7 @@ class RxJS {
|
|
|
161
158
|
* Backward-compatible overload that accepts optional callback like tests expect
|
|
162
159
|
*/
|
|
163
160
|
putCompat(data, callback) {
|
|
164
|
-
return new
|
|
161
|
+
return new Observable((subscriber) => {
|
|
165
162
|
this.gun.put(data, (ack) => {
|
|
166
163
|
if (callback)
|
|
167
164
|
callback(ack);
|
|
@@ -182,7 +179,7 @@ class RxJS {
|
|
|
182
179
|
* @returns Observable that completes when the set is acknowledged
|
|
183
180
|
*/
|
|
184
181
|
set(path, data) {
|
|
185
|
-
return new
|
|
182
|
+
return new Observable((subscriber) => {
|
|
186
183
|
const performSet = (target, value) => {
|
|
187
184
|
target.set(value, (ack) => {
|
|
188
185
|
if (ack.err) {
|
|
@@ -212,7 +209,7 @@ class RxJS {
|
|
|
212
209
|
});
|
|
213
210
|
}
|
|
214
211
|
setCompat(data, callback) {
|
|
215
|
-
return new
|
|
212
|
+
return new Observable((subscriber) => {
|
|
216
213
|
this.gun.set(data, (ack) => {
|
|
217
214
|
if (callback)
|
|
218
215
|
callback(ack);
|
|
@@ -242,7 +239,7 @@ class RxJS {
|
|
|
242
239
|
else {
|
|
243
240
|
node = this.gun;
|
|
244
241
|
}
|
|
245
|
-
return new
|
|
242
|
+
return new Observable((subscriber) => {
|
|
246
243
|
node.once((data) => {
|
|
247
244
|
if (data === undefined || data === null) {
|
|
248
245
|
subscriber.next(null);
|
|
@@ -270,7 +267,7 @@ class RxJS {
|
|
|
270
267
|
return source;
|
|
271
268
|
});
|
|
272
269
|
// Combine the latest values from all sources
|
|
273
|
-
return new
|
|
270
|
+
return new Observable((subscriber) => {
|
|
274
271
|
let values = new Array(sources.length).fill(undefined);
|
|
275
272
|
let completed = new Array(sources.length).fill(false);
|
|
276
273
|
const subscriptions = observables.map((obs, index) => {
|
|
@@ -310,7 +307,7 @@ class RxJS {
|
|
|
310
307
|
* @returns Observable that completes when the put is acknowledged
|
|
311
308
|
*/
|
|
312
309
|
userPut(dataOrPath, maybeData, callback) {
|
|
313
|
-
return new
|
|
310
|
+
return new Observable((subscriber) => {
|
|
314
311
|
const user = this.gun.user();
|
|
315
312
|
if (typeof dataOrPath === "string") {
|
|
316
313
|
user.get(dataOrPath).put(maybeData, (ack) => {
|
|
@@ -348,7 +345,7 @@ class RxJS {
|
|
|
348
345
|
* @returns Observable that completes when the set is acknowledged
|
|
349
346
|
*/
|
|
350
347
|
userSet(dataOrPath, maybeData, callback) {
|
|
351
|
-
return new
|
|
348
|
+
return new Observable((subscriber) => {
|
|
352
349
|
const user = this.gun.user();
|
|
353
350
|
if (typeof dataOrPath === "string") {
|
|
354
351
|
user.get(dataOrPath).set(maybeData, (ack) => {
|
|
@@ -385,7 +382,7 @@ class RxJS {
|
|
|
385
382
|
* @returns Observable that emits the data once
|
|
386
383
|
*/
|
|
387
384
|
userOnce(path, callback) {
|
|
388
|
-
return new
|
|
385
|
+
return new Observable((subscriber) => {
|
|
389
386
|
const user = this.gun.user();
|
|
390
387
|
const target = path ? user.get(path) : user;
|
|
391
388
|
target.once((data, ack) => {
|
|
@@ -446,4 +443,3 @@ class RxJS {
|
|
|
446
443
|
return cleanObj;
|
|
447
444
|
}
|
|
448
445
|
}
|
|
449
|
-
exports.RxJS = RxJS;
|
package/dist/gundb/types.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,35 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.ShogunCore = exports.Gun = exports.DataBase = exports.GunErrors = exports.derive = exports.crypto = exports.RxJS = exports.SEA = void 0;
|
|
21
|
-
const core_1 = require("./core");
|
|
22
|
-
Object.defineProperty(exports, "ShogunCore", { enumerable: true, get: function () { return core_1.ShogunCore; } });
|
|
23
|
-
const db_1 = require("./gundb/db");
|
|
24
|
-
Object.defineProperty(exports, "SEA", { enumerable: true, get: function () { return db_1.SEA; } });
|
|
25
|
-
Object.defineProperty(exports, "RxJS", { enumerable: true, get: function () { return db_1.RxJS; } });
|
|
26
|
-
Object.defineProperty(exports, "crypto", { enumerable: true, get: function () { return db_1.crypto; } });
|
|
27
|
-
Object.defineProperty(exports, "derive", { enumerable: true, get: function () { return db_1.derive; } });
|
|
28
|
-
Object.defineProperty(exports, "GunErrors", { enumerable: true, get: function () { return db_1.GunErrors; } });
|
|
29
|
-
Object.defineProperty(exports, "DataBase", { enumerable: true, get: function () { return db_1.DataBase; } });
|
|
1
|
+
import { ShogunCore } from "./core";
|
|
2
|
+
import { SEA, RxJS, crypto, derive, GunErrors, DataBase } from "./gundb/db";
|
|
30
3
|
// Import Gun as default export
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
4
|
+
import Gun from "./gundb/db";
|
|
5
|
+
export * from "./utils/errorHandler";
|
|
6
|
+
export * from "./plugins";
|
|
7
|
+
export * from "./types/shogun";
|
|
8
|
+
export { SEA, RxJS, crypto, derive, GunErrors, DataBase };
|
|
9
|
+
export { Gun };
|
|
10
|
+
export { ShogunCore };
|
package/dist/plugins/base.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BasePlugin = void 0;
|
|
4
|
-
const eventEmitter_1 = require("../utils/eventEmitter");
|
|
1
|
+
import { EventEmitter } from "../utils/eventEmitter";
|
|
5
2
|
/**
|
|
6
3
|
* Classe base per tutti i plugin di ShogunCore
|
|
7
4
|
* Fornisce funzionalità comuni e implementazione base dell'interfaccia ShogunPlugin
|
|
8
5
|
*/
|
|
9
|
-
class BasePlugin extends
|
|
6
|
+
export class BasePlugin extends EventEmitter {
|
|
10
7
|
/** Descrizione opzionale del plugin */
|
|
11
8
|
description;
|
|
12
9
|
/** Categoria del plugin */
|
|
@@ -48,4 +45,3 @@ class BasePlugin extends eventEmitter_1.EventEmitter {
|
|
|
48
45
|
return this.core;
|
|
49
46
|
}
|
|
50
47
|
}
|
|
51
|
-
exports.BasePlugin = BasePlugin;
|
package/dist/plugins/index.js
CHANGED
|
@@ -1,41 +1,15 @@
|
|
|
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
|
-
exports.OAuthPlugin = exports.OAuthConnector = exports.NostrConnectorPlugin = exports.NostrConnector = exports.Web3ConnectorPlugin = exports.Web3Connector = exports.WebauthnPlugin = exports.Webauthn = exports.BasePlugin = void 0;
|
|
18
1
|
// Base plugin interface and types
|
|
19
|
-
|
|
20
|
-
Object.defineProperty(exports, "BasePlugin", { enumerable: true, get: function () { return base_1.BasePlugin; } });
|
|
2
|
+
export { BasePlugin } from "./base";
|
|
21
3
|
// WebAuthn plugin exports
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var webauthnPlugin_1 = require("./webauthn/webauthnPlugin");
|
|
25
|
-
Object.defineProperty(exports, "WebauthnPlugin", { enumerable: true, get: function () { return webauthnPlugin_1.WebauthnPlugin; } });
|
|
4
|
+
export { Webauthn } from "./webauthn/webauthn";
|
|
5
|
+
export { WebauthnPlugin } from "./webauthn/webauthnPlugin";
|
|
26
6
|
// Ethereum plugin exports
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var web3ConnectorPlugin_1 = require("./web3/web3ConnectorPlugin");
|
|
30
|
-
Object.defineProperty(exports, "Web3ConnectorPlugin", { enumerable: true, get: function () { return web3ConnectorPlugin_1.Web3ConnectorPlugin; } });
|
|
7
|
+
export { Web3Connector } from "./web3/web3Connector";
|
|
8
|
+
export { Web3ConnectorPlugin } from "./web3/web3ConnectorPlugin";
|
|
31
9
|
// Bitcoin plugin exports
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var nostrConnectorPlugin_1 = require("./nostr/nostrConnectorPlugin");
|
|
35
|
-
Object.defineProperty(exports, "NostrConnectorPlugin", { enumerable: true, get: function () { return nostrConnectorPlugin_1.NostrConnectorPlugin; } });
|
|
10
|
+
export { NostrConnector } from "./nostr/nostrConnector";
|
|
11
|
+
export { NostrConnectorPlugin } from "./nostr/nostrConnectorPlugin";
|
|
36
12
|
// OAuth plugin exports
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
Object.defineProperty(exports, "OAuthPlugin", { enumerable: true, get: function () { return oauthPlugin_1.OAuthPlugin; } });
|
|
41
|
-
__exportStar(require("./oauth/types"), exports);
|
|
13
|
+
export { OAuthConnector } from "./oauth/oauthConnector";
|
|
14
|
+
export { OAuthPlugin } from "./oauth/oauthPlugin";
|
|
15
|
+
export * from "./oauth/types";
|
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
+
export * from "./nostrConnectorPlugin";
|
|
2
|
+
export * from "./nostrConnector";
|
|
3
|
+
export * from "./nostrSigner";
|
|
4
|
+
export * from "./types";
|
|
@@ -1,24 +1,17 @@
|
|
|
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
1
|
/**
|
|
9
2
|
* The BitcoinWallet class provides functionality for connecting, signing up, and logging in using Bitcoin wallets.
|
|
10
3
|
* Supports Alby and Nostr extensions, as well as manual key management.
|
|
11
4
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
5
|
+
import { ethers } from "ethers";
|
|
6
|
+
import { verifyEvent, finalizeEvent, utils as nostrUtils, getEventHash, } from "nostr-tools";
|
|
7
|
+
import { EventEmitter } from "../../utils/eventEmitter";
|
|
8
|
+
import derive from "../../gundb/derive";
|
|
9
|
+
import { generateUsernameFromIdentity } from "../../utils/validation";
|
|
10
|
+
export const MESSAGE_TO_SIGN = "I Love Shogun!";
|
|
18
11
|
/**
|
|
19
12
|
* Class for Bitcoin wallet connections and operations
|
|
20
13
|
*/
|
|
21
|
-
class NostrConnector extends
|
|
14
|
+
class NostrConnector extends EventEmitter {
|
|
22
15
|
DEFAULT_CONFIG = {
|
|
23
16
|
cacheDuration: 24 * 60 * 60 * 1000, // 24 hours instead of 30 minutes for better UX
|
|
24
17
|
maxRetries: 3,
|
|
@@ -218,12 +211,12 @@ class NostrConnector extends eventEmitter_1.EventEmitter {
|
|
|
218
211
|
* Generate credentials using Nostr: username deterministico e chiave GunDB derivata dall'address
|
|
219
212
|
*/
|
|
220
213
|
async generateCredentials(address, signature, message) {
|
|
221
|
-
const username =
|
|
214
|
+
const username = generateUsernameFromIdentity("nostr", { id: address });
|
|
222
215
|
// Usa un hashing robusto di address con keccak256
|
|
223
|
-
const hashedAddress =
|
|
216
|
+
const hashedAddress = ethers.keccak256(ethers.toUtf8Bytes(address));
|
|
224
217
|
// Include la signature nel salt per aggiungere un ulteriore livello di sicurezza
|
|
225
218
|
const salt = `${username}_${address}_${message}_${signature}`;
|
|
226
|
-
const key = await (
|
|
219
|
+
const key = await derive(hashedAddress, salt, { includeP256: true });
|
|
227
220
|
return { username, key, message, signature };
|
|
228
221
|
}
|
|
229
222
|
/**
|
|
@@ -236,7 +229,7 @@ class NostrConnector extends eventEmitter_1.EventEmitter {
|
|
|
236
229
|
try {
|
|
237
230
|
// Create a deterministic hash from the signature using a secure algorithm
|
|
238
231
|
const normalizedSig = signature.toLowerCase().replace(/[^a-f0-9]/g, "");
|
|
239
|
-
const passwordHash =
|
|
232
|
+
const passwordHash = ethers.sha256(ethers.toUtf8Bytes(normalizedSig));
|
|
240
233
|
return passwordHash;
|
|
241
234
|
}
|
|
242
235
|
catch (error) {
|
|
@@ -271,10 +264,10 @@ class NostrConnector extends eventEmitter_1.EventEmitter {
|
|
|
271
264
|
};
|
|
272
265
|
const event = {
|
|
273
266
|
...eventData,
|
|
274
|
-
id:
|
|
267
|
+
id: getEventHash(eventData),
|
|
275
268
|
sig: signature,
|
|
276
269
|
};
|
|
277
|
-
return
|
|
270
|
+
return verifyEvent(event);
|
|
278
271
|
}
|
|
279
272
|
catch (verifyError) {
|
|
280
273
|
console.error("Error in Nostr signature verification:", verifyError);
|
|
@@ -298,10 +291,10 @@ class NostrConnector extends eventEmitter_1.EventEmitter {
|
|
|
298
291
|
};
|
|
299
292
|
const event = {
|
|
300
293
|
...eventData,
|
|
301
|
-
id:
|
|
294
|
+
id: getEventHash(eventData),
|
|
302
295
|
sig: signature,
|
|
303
296
|
};
|
|
304
|
-
return
|
|
297
|
+
return verifyEvent(event);
|
|
305
298
|
}
|
|
306
299
|
catch (manualVerifyError) {
|
|
307
300
|
console.error("Error in manual signature verification:", manualVerifyError);
|
|
@@ -356,7 +349,7 @@ class NostrConnector extends eventEmitter_1.EventEmitter {
|
|
|
356
349
|
};
|
|
357
350
|
const nostrEvent = {
|
|
358
351
|
...eventData,
|
|
359
|
-
id:
|
|
352
|
+
id: getEventHash(eventData),
|
|
360
353
|
sig: "", // This will be filled by window.nostr.signEvent
|
|
361
354
|
};
|
|
362
355
|
const signedEvent = await window.nostr.signEvent(nostrEvent);
|
|
@@ -377,11 +370,11 @@ class NostrConnector extends eventEmitter_1.EventEmitter {
|
|
|
377
370
|
};
|
|
378
371
|
const eventTemplate = {
|
|
379
372
|
...manualEventData,
|
|
380
|
-
id:
|
|
373
|
+
id: getEventHash(manualEventData),
|
|
381
374
|
sig: "", // This will be filled by finalizeEvent
|
|
382
375
|
};
|
|
383
|
-
const privateKeyBytes =
|
|
384
|
-
const signedEventManual = await
|
|
376
|
+
const privateKeyBytes = nostrUtils.hexToBytes(this.manualKeyPair.privateKey);
|
|
377
|
+
const signedEventManual = await finalizeEvent(eventTemplate, privateKeyBytes);
|
|
385
378
|
console.log("Generated manual signature:", signedEventManual.sig.substring(0, 20) + "...");
|
|
386
379
|
return signedEventManual.sig;
|
|
387
380
|
default:
|
|
@@ -403,12 +396,11 @@ class NostrConnector extends eventEmitter_1.EventEmitter {
|
|
|
403
396
|
this.manualKeyPair = null;
|
|
404
397
|
}
|
|
405
398
|
}
|
|
406
|
-
exports.NostrConnector = NostrConnector;
|
|
407
399
|
// Funzione helper per derivare chiavi Nostr/Bitcoin (come per Web3/WebAuthn)
|
|
408
|
-
async function deriveNostrKeys(address, signature, message) {
|
|
400
|
+
export async function deriveNostrKeys(address, signature, message) {
|
|
409
401
|
// Usa solo l'address per rendere le credenziali deterministiche
|
|
410
402
|
const salt = `${address}_${message}`;
|
|
411
|
-
return await (
|
|
403
|
+
return await derive(address, salt, {
|
|
412
404
|
includeP256: true,
|
|
413
405
|
});
|
|
414
406
|
}
|
|
@@ -418,3 +410,4 @@ if (typeof window !== "undefined") {
|
|
|
418
410
|
else if (typeof global !== "undefined") {
|
|
419
411
|
global.NostrConnector = NostrConnector;
|
|
420
412
|
}
|
|
413
|
+
export { NostrConnector };
|