shogun-core 1.1.4 → 1.2.2
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/README.md +61 -1327
- package/dist/browser/shogun-core.js +1 -1
- package/dist/browser/shogun-core.js.LICENSE.txt +0 -9
- package/dist/browser/shogun-core.light.js +1 -1
- package/dist/browser/shogun-core.vendors.light.js +1 -1
- package/dist/browser.js +27 -11
- package/dist/core.js +603 -0
- package/dist/{gun → gundb}/crypto.js +38 -8
- package/dist/gundb/gun.js +676 -0
- package/dist/{gun → gundb}/index.js +0 -5
- package/dist/{gun → gundb}/utils.js +6 -0
- package/dist/index.js +1 -807
- package/dist/plugins/index.js +15 -28
- package/dist/plugins/{stealth → nostr}/index.js +3 -4
- package/dist/plugins/nostr/nostrConnector.js +656 -0
- package/dist/plugins/nostr/nostrConnectorPlugin.js +259 -0
- package/dist/plugins/{metamask → web3}/index.js +2 -2
- package/dist/plugins/{metamask/metamask.js → web3/web3Connector.js} +8 -8
- package/dist/plugins/{metamask/metamaskPlugin.js → web3/web3ConnectorPlugin.js} +32 -42
- package/dist/plugins/webauthn/webauthnPlugin.js +4 -0
- package/dist/types/browser.d.ts +9 -4
- package/dist/types/core.d.ts +221 -0
- package/dist/types/{gun → gundb}/crypto.d.ts +20 -5
- package/dist/types/{gun → gundb}/gun.d.ts +56 -28
- package/dist/types/gundb/index.d.ts +1 -0
- package/dist/types/{gun → gundb}/utils.d.ts +1 -0
- package/dist/types/index.d.ts +1 -282
- package/dist/types/plugins/index.d.ts +7 -10
- package/dist/types/plugins/nostr/index.d.ts +3 -0
- package/dist/types/plugins/nostr/nostrConnector.d.ts +111 -0
- package/dist/types/plugins/nostr/nostrConnectorPlugin.d.ts +87 -0
- package/dist/types/plugins/nostr/types.d.ts +122 -0
- package/dist/types/plugins/web3/index.d.ts +3 -0
- package/dist/types/plugins/{metamask → web3}/types.d.ts +4 -4
- package/dist/types/plugins/{metamask/metamask.d.ts → web3/web3Connector.d.ts} +7 -7
- package/dist/types/plugins/{metamask/metamaskPlugin.d.ts → web3/web3ConnectorPlugin.d.ts} +4 -4
- package/dist/types/shogun.js +40 -15
- package/dist/types/types/shogun.d.ts +67 -67
- package/dist/types/utils/errorHandler.d.ts +39 -36
- package/dist/types/utils/utility.d.ts +0 -4
- package/dist/utils/errorHandler.js +43 -40
- package/dist/utils/utility.js +0 -8
- package/package.json +2 -2
- package/dist/config.js +0 -18
- package/dist/gun/gun.js +0 -542
- package/dist/plugins/stealth/stealth.js +0 -176
- package/dist/plugins/stealth/stealthPlugin.js +0 -113
- package/dist/plugins/stealth/types.js +0 -2
- package/dist/plugins/utils/stubs/didStub.js +0 -35
- package/dist/plugins/utils/stubs/stealthStub.js +0 -35
- package/dist/plugins/utils/stubs/webauthnStub.js +0 -29
- package/dist/plugins/wallet/index.js +0 -20
- package/dist/plugins/wallet/types.js +0 -15
- package/dist/plugins/wallet/walletManager.js +0 -1832
- package/dist/plugins/wallet/walletPlugin.js +0 -236
- package/dist/types/config.d.ts +0 -15
- package/dist/types/gun/index.d.ts +0 -6
- package/dist/types/gun/types.d.ts +0 -2
- package/dist/types/plugins/metamask/index.d.ts +0 -3
- package/dist/types/plugins/stealth/index.d.ts +0 -3
- package/dist/types/plugins/stealth/stealth.d.ts +0 -93
- package/dist/types/plugins/stealth/stealthPlugin.d.ts +0 -60
- package/dist/types/plugins/stealth/types.d.ts +0 -93
- package/dist/types/plugins/utils/stubs/didStub.d.ts +0 -15
- package/dist/types/plugins/utils/stubs/stealthStub.d.ts +0 -15
- package/dist/types/plugins/utils/stubs/webauthnStub.d.ts +0 -13
- package/dist/types/plugins/wallet/index.d.ts +0 -3
- package/dist/types/plugins/wallet/types.d.ts +0 -167
- package/dist/types/plugins/wallet/walletManager.d.ts +0 -306
- package/dist/types/plugins/wallet/walletPlugin.d.ts +0 -126
- package/dist/types/utils/stubs/didStub.d.ts +0 -15
- package/dist/types/utils/stubs/stealthStub.d.ts +0 -15
- package/dist/types/utils/stubs/webauthnStub.d.ts +0 -13
- package/dist/utils/stubs/didStub.js +0 -35
- package/dist/utils/stubs/stealthStub.js +0 -35
- package/dist/utils/stubs/webauthnStub.js +0 -29
- /package/dist/{gun → gundb}/errors.js +0 -0
- /package/dist/{gun → gundb}/rxjs-integration.js +0 -0
- /package/dist/{gun → plugins/nostr}/types.js +0 -0
- /package/dist/plugins/{metamask → web3}/types.js +0 -0
- /package/dist/types/{gun → gundb}/errors.d.ts +0 -0
- /package/dist/types/{gun → gundb}/rxjs-integration.d.ts +0 -0
|
@@ -5,7 +5,7 @@ exports.createError = createError;
|
|
|
5
5
|
exports.handleError = handleError;
|
|
6
6
|
const logger_1 = require("./logger");
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Types of errors that can occur in the application
|
|
9
9
|
*/
|
|
10
10
|
var ErrorType;
|
|
11
11
|
(function (ErrorType) {
|
|
@@ -28,14 +28,17 @@ var ErrorType;
|
|
|
28
28
|
ErrorType["CONNECTOR"] = "CONNECTOR";
|
|
29
29
|
ErrorType["GENERAL"] = "GENERAL";
|
|
30
30
|
ErrorType["CONTRACT"] = "CONTRACT";
|
|
31
|
+
ErrorType["BIP32"] = "BIP32Error";
|
|
32
|
+
ErrorType["ETHEREUM"] = "EthereumError";
|
|
33
|
+
ErrorType["BITCOIN"] = "BitcoinError";
|
|
31
34
|
})(ErrorType || (exports.ErrorType = ErrorType = {}));
|
|
32
35
|
/**
|
|
33
|
-
* Wrapper
|
|
34
|
-
* @param type -
|
|
35
|
-
* @param code -
|
|
36
|
-
* @param message -
|
|
37
|
-
* @param originalError -
|
|
38
|
-
* @returns
|
|
36
|
+
* Wrapper to standardize errors
|
|
37
|
+
* @param type - Error type
|
|
38
|
+
* @param code - Error code
|
|
39
|
+
* @param message - Error message
|
|
40
|
+
* @param originalError - Original error
|
|
41
|
+
* @returns A structured error object
|
|
39
42
|
*/
|
|
40
43
|
function createError(type, code, message, originalError) {
|
|
41
44
|
return {
|
|
@@ -47,23 +50,23 @@ function createError(type, code, message, originalError) {
|
|
|
47
50
|
};
|
|
48
51
|
}
|
|
49
52
|
/**
|
|
50
|
-
*
|
|
51
|
-
* @param error -
|
|
52
|
-
* @param options -
|
|
53
|
-
* @returns
|
|
53
|
+
* Utility function to handle errors consistently
|
|
54
|
+
* @param error - The error to handle
|
|
55
|
+
* @param options - Configuration options
|
|
56
|
+
* @returns Operation result or callback result
|
|
54
57
|
*/
|
|
55
58
|
function handleError(error, options = {}) {
|
|
56
|
-
//
|
|
59
|
+
// Default settings
|
|
57
60
|
const { message = error instanceof Error ? error.message : String(error), throwError = false, logError = true, callback, } = options;
|
|
58
|
-
// Log
|
|
61
|
+
// Log the error if requested
|
|
59
62
|
if (logError) {
|
|
60
63
|
console.error(`[ERROR] ${message}`, error);
|
|
61
64
|
}
|
|
62
|
-
//
|
|
65
|
+
// If a callback was provided, execute it and return its result
|
|
63
66
|
if (typeof callback === "function") {
|
|
64
67
|
return callback(error);
|
|
65
68
|
}
|
|
66
|
-
//
|
|
69
|
+
// If requested to throw the error, throw it
|
|
67
70
|
if (throwError) {
|
|
68
71
|
if (error instanceof Error) {
|
|
69
72
|
throw error;
|
|
@@ -72,7 +75,7 @@ function handleError(error, options = {}) {
|
|
|
72
75
|
throw new Error(message);
|
|
73
76
|
}
|
|
74
77
|
}
|
|
75
|
-
//
|
|
78
|
+
// Otherwise return a standard result object
|
|
76
79
|
return {
|
|
77
80
|
success: false,
|
|
78
81
|
message,
|
|
@@ -80,34 +83,34 @@ function handleError(error, options = {}) {
|
|
|
80
83
|
};
|
|
81
84
|
}
|
|
82
85
|
/**
|
|
83
|
-
*
|
|
86
|
+
* Centralized error handler
|
|
84
87
|
*/
|
|
85
88
|
class ErrorHandler {
|
|
86
89
|
static errors = [];
|
|
87
90
|
static maxErrors = 100;
|
|
88
91
|
static listeners = [];
|
|
89
92
|
/**
|
|
90
|
-
*
|
|
91
|
-
* @param error -
|
|
93
|
+
* Handles an error by logging it and notifying listeners
|
|
94
|
+
* @param error - The error to handle
|
|
92
95
|
*/
|
|
93
96
|
static handleError(error) {
|
|
94
|
-
// Log
|
|
97
|
+
// Log the error
|
|
95
98
|
(0, logger_1.logError)(`[${error.type}] ${error.code}: ${error.message}`);
|
|
96
|
-
//
|
|
99
|
+
// Store the error in memory
|
|
97
100
|
this.errors.push(error);
|
|
98
|
-
//
|
|
101
|
+
// Keep only the last maxErrors
|
|
99
102
|
if (this.errors.length > this.maxErrors) {
|
|
100
103
|
this.errors = this.errors.slice(-this.maxErrors);
|
|
101
104
|
}
|
|
102
|
-
//
|
|
105
|
+
// Notify listeners
|
|
103
106
|
this.notifyListeners(error);
|
|
104
107
|
}
|
|
105
108
|
/**
|
|
106
|
-
*
|
|
107
|
-
* @param type -
|
|
108
|
-
* @param code -
|
|
109
|
-
* @param message -
|
|
110
|
-
* @param originalError -
|
|
109
|
+
* Handles a raw error by converting it to ShogunError
|
|
110
|
+
* @param type - Error type
|
|
111
|
+
* @param code - Error code
|
|
112
|
+
* @param message - Error message
|
|
113
|
+
* @param originalError - Original error
|
|
111
114
|
*/
|
|
112
115
|
static handle(type, code, message, originalError, logLevel = "error") {
|
|
113
116
|
// Create a formatted error message
|
|
@@ -138,23 +141,23 @@ class ErrorHandler {
|
|
|
138
141
|
return error;
|
|
139
142
|
}
|
|
140
143
|
/**
|
|
141
|
-
*
|
|
142
|
-
* @param count -
|
|
143
|
-
* @returns
|
|
144
|
+
* Retrieves the last N errors
|
|
145
|
+
* @param count - Number of errors to retrieve
|
|
146
|
+
* @returns List of most recent errors
|
|
144
147
|
*/
|
|
145
148
|
static getRecentErrors(count = 10) {
|
|
146
149
|
return this.errors.slice(-Math.min(count, this.errors.length));
|
|
147
150
|
}
|
|
148
151
|
/**
|
|
149
|
-
*
|
|
150
|
-
* @param listener -
|
|
152
|
+
* Adds a listener for errors
|
|
153
|
+
* @param listener - Function that will be called when an error occurs
|
|
151
154
|
*/
|
|
152
155
|
static addListener(listener) {
|
|
153
156
|
this.listeners.push(listener);
|
|
154
157
|
}
|
|
155
158
|
/**
|
|
156
|
-
*
|
|
157
|
-
* @param listener -
|
|
159
|
+
* Removes an error listener
|
|
160
|
+
* @param listener - Function to remove
|
|
158
161
|
*/
|
|
159
162
|
static removeListener(listener) {
|
|
160
163
|
const index = this.listeners.indexOf(listener);
|
|
@@ -163,8 +166,8 @@ class ErrorHandler {
|
|
|
163
166
|
}
|
|
164
167
|
}
|
|
165
168
|
/**
|
|
166
|
-
*
|
|
167
|
-
* @param error -
|
|
169
|
+
* Notifies all listeners of an error
|
|
170
|
+
* @param error - Error to notify
|
|
168
171
|
*/
|
|
169
172
|
static notifyListeners(error) {
|
|
170
173
|
for (const listener of this.listeners) {
|
|
@@ -177,9 +180,9 @@ class ErrorHandler {
|
|
|
177
180
|
}
|
|
178
181
|
}
|
|
179
182
|
/**
|
|
180
|
-
*
|
|
181
|
-
* @param error -
|
|
182
|
-
* @returns
|
|
183
|
+
* Helper function to format error messages from native errors
|
|
184
|
+
* @param error - Error to format
|
|
185
|
+
* @returns Formatted error message
|
|
183
186
|
*/
|
|
184
187
|
static formatError(error) {
|
|
185
188
|
if (!error) {
|
package/dist/utils/utility.js
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isPlatformWeb = void 0;
|
|
4
3
|
exports.delay = delay;
|
|
5
4
|
exports.errorAfter = errorAfter;
|
|
6
5
|
exports.randomString = randomString;
|
|
7
|
-
/**
|
|
8
|
-
* Checks if the application is running in a web environment
|
|
9
|
-
*/
|
|
10
|
-
const isPlatformWeb = () => {
|
|
11
|
-
return typeof window !== "undefined";
|
|
12
|
-
};
|
|
13
|
-
exports.isPlatformWeb = isPlatformWeb;
|
|
14
6
|
/**
|
|
15
7
|
* Delays execution for the specified time
|
|
16
8
|
* @param ms - Milliseconds to delay
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shogun-core",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "SHOGUN SDK -
|
|
3
|
+
"version": "1.2.2",
|
|
4
|
+
"description": "SHOGUN SDK - Core library for Shogun SDK",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
7
7
|
"types": "./dist/types/index.d.ts",
|
package/dist/config.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CONFIG = void 0;
|
|
4
|
-
exports.CONFIG = {
|
|
5
|
-
TIMEOUT: {
|
|
6
|
-
AUTH: 60000,
|
|
7
|
-
GUN: 5000,
|
|
8
|
-
WALLET: 30000,
|
|
9
|
-
},
|
|
10
|
-
PATHS: {
|
|
11
|
-
DERIVATION_BASE: "m/44'/60'/0'/0/",
|
|
12
|
-
DEFAULT_INDEX: 0,
|
|
13
|
-
},
|
|
14
|
-
PREFIX: "⚔️ ShogunSDK:",
|
|
15
|
-
PEERS: [],
|
|
16
|
-
MESSAGE_TO_SIGN: "Access With Shogun",
|
|
17
|
-
};
|
|
18
|
-
exports.default = exports.CONFIG;
|