@sudobility/types 1.9.39 → 1.9.41
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/index.js +45 -7
- package/dist/index.js.map +1 -1
- package/dist/types/blockchain/common.js +16 -9
- package/dist/types/blockchain/common.js.map +1 -1
- package/dist/types/blockchain/index.js +16 -2
- package/dist/types/blockchain/index.js.map +1 -1
- package/dist/types/blockchain/validation.js +12 -6
- package/dist/types/blockchain/validation.js.map +1 -1
- package/dist/types/business/enums.js +49 -46
- package/dist/types/business/enums.js.map +1 -1
- package/dist/types/business/index.js +31 -2
- package/dist/types/business/index.js.map +1 -1
- package/dist/types/business/wallet-status.js +16 -10
- package/dist/types/business/wallet-status.js.map +1 -1
- package/dist/types/common.js +2 -1
- package/dist/types/common.js.map +1 -1
- package/dist/types/config/app-config.js +2 -1
- package/dist/types/config/app-config.js.map +1 -1
- package/dist/types/config/environment.js +5 -2
- package/dist/types/config/environment.js.map +1 -1
- package/dist/types/config/index.js +5 -1
- package/dist/types/config/index.js.map +1 -1
- package/dist/types/entity/entity.js +9 -6
- package/dist/types/entity/entity.js.map +1 -1
- package/dist/types/entity/index.js +20 -4
- package/dist/types/entity/index.js.map +1 -1
- package/dist/types/entity/permissions.js +14 -9
- package/dist/types/entity/permissions.js.map +1 -1
- package/dist/types/entity/requests.js +2 -1
- package/dist/types/entity/requests.js.map +1 -1
- package/dist/types/entity/responses.js +2 -1
- package/dist/types/entity/responses.js.map +1 -1
- package/dist/types/index.js +23 -7
- package/dist/types/index.js.map +1 -1
- package/dist/types/infrastructure/analytics.js +7 -3
- package/dist/types/infrastructure/analytics.js.map +1 -1
- package/dist/types/infrastructure/api.js +9 -5
- package/dist/types/infrastructure/api.js.map +1 -1
- package/dist/types/infrastructure/index.js +14 -4
- package/dist/types/infrastructure/index.js.map +1 -1
- package/dist/types/infrastructure/navigation.js +2 -1
- package/dist/types/infrastructure/network.js +4 -1
- package/dist/types/infrastructure/network.js.map +1 -1
- package/dist/types/infrastructure/wallet.js +5 -2
- package/dist/types/infrastructure/wallet.js.map +1 -1
- package/dist/types/subscription/index.js +17 -1
- package/dist/types/subscription/index.js.map +1 -1
- package/dist/types/subscription/rate-limits.js +5 -2
- package/dist/types/subscription/rate-limits.js.map +1 -1
- package/dist/utils/async-helpers.js +16 -7
- package/dist/utils/async-helpers.js.map +1 -1
- package/dist/utils/auth/auth.js +24 -14
- package/dist/utils/auth/auth.js.map +1 -1
- package/dist/utils/auth/index.js +12 -1
- package/dist/utils/auth/index.js.map +1 -1
- package/dist/utils/blockchain/address.js +31 -20
- package/dist/utils/blockchain/address.js.map +1 -1
- package/dist/utils/blockchain/event-helpers.js +20 -9
- package/dist/utils/blockchain/event-helpers.js.map +1 -1
- package/dist/utils/blockchain/index.js +26 -3
- package/dist/utils/blockchain/index.js.map +1 -1
- package/dist/utils/constants/application.js +20 -2
- package/dist/utils/constants/application.js.map +1 -1
- package/dist/utils/constants/index.js +23 -2
- package/dist/utils/constants/index.js.map +1 -1
- package/dist/utils/constants/status-values.js +4 -1
- package/dist/utils/constants/status-values.js.map +1 -1
- package/dist/utils/formatting/currency.js +11 -6
- package/dist/utils/formatting/currency.js.map +1 -1
- package/dist/utils/formatting/date.js +16 -7
- package/dist/utils/formatting/date.js.map +1 -1
- package/dist/utils/formatting/index.js +33 -3
- package/dist/utils/formatting/index.js.map +1 -1
- package/dist/utils/formatting/string.js +34 -16
- package/dist/utils/formatting/string.js.map +1 -1
- package/dist/utils/index.js +24 -8
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/logging/index.js +11 -1
- package/dist/utils/logging/index.js.map +1 -1
- package/dist/utils/logging/logger.js +10 -2
- package/dist/utils/logging/logger.js.map +1 -1
- package/dist/utils/url/index.js +8 -1
- package/dist/utils/url/index.js.map +1 -1
- package/dist/utils/url/url-params.js +6 -1
- package/dist/utils/url/url-params.js.map +1 -1
- package/dist/utils/validation/index.js +24 -2
- package/dist/utils/validation/index.js.map +1 -1
- package/dist/utils/validation/type-validation.js +48 -27
- package/dist/utils/validation/type-validation.js.map +1 -1
- package/dist/utils/validation/web3-username-validator.js +10 -6
- package/dist/utils/validation/web3-username-validator.js.map +1 -1
- package/package.json +8 -8
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Common async operation patterns and helpers
|
|
3
4
|
* Reduces boilerplate code for common async operations
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.debounceAsync = exports.clearExpiredCache = exports.withCache = exports.withTimeout = exports.safeParallel = exports.withLoadingState = exports.safeAsync = void 0;
|
|
8
|
+
const logging_1 = require("./logging");
|
|
6
9
|
/**
|
|
7
10
|
* Safely execute an async operation with error handling
|
|
8
11
|
* Returns a result object instead of throwing
|
|
@@ -14,10 +17,11 @@ const safeAsync = async (operation, context) => {
|
|
|
14
17
|
}
|
|
15
18
|
catch (error) {
|
|
16
19
|
const errorObj = error instanceof Error ? error : new Error(String(error));
|
|
17
|
-
logger.error(`Async operation failed: ${errorObj.message}`, context, error);
|
|
20
|
+
logging_1.logger.error(`Async operation failed: ${errorObj.message}`, context, error);
|
|
18
21
|
return { error: errorObj, success: false };
|
|
19
22
|
}
|
|
20
23
|
};
|
|
24
|
+
exports.safeAsync = safeAsync;
|
|
21
25
|
/**
|
|
22
26
|
* Execute async operation with loading state tracking
|
|
23
27
|
*/
|
|
@@ -31,13 +35,14 @@ const withLoadingState = async (operation, setLoading, setError, context) => {
|
|
|
31
35
|
catch (error) {
|
|
32
36
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
33
37
|
setError(errorMessage);
|
|
34
|
-
logger.error(`Operation failed: ${errorMessage}`, context, error);
|
|
38
|
+
logging_1.logger.error(`Operation failed: ${errorMessage}`, context, error);
|
|
35
39
|
return undefined;
|
|
36
40
|
}
|
|
37
41
|
finally {
|
|
38
42
|
setLoading(false);
|
|
39
43
|
}
|
|
40
44
|
};
|
|
45
|
+
exports.withLoadingState = withLoadingState;
|
|
41
46
|
/**
|
|
42
47
|
* Execute multiple async operations in parallel with error handling
|
|
43
48
|
*/
|
|
@@ -48,10 +53,11 @@ const safeParallel = async (operations, context) => {
|
|
|
48
53
|
}
|
|
49
54
|
catch (error) {
|
|
50
55
|
const errorObj = error instanceof Error ? error : new Error(String(error));
|
|
51
|
-
logger.error(`Parallel operations failed: ${errorObj.message}`, context, error);
|
|
56
|
+
logging_1.logger.error(`Parallel operations failed: ${errorObj.message}`, context, error);
|
|
52
57
|
return { error: errorObj, success: false };
|
|
53
58
|
}
|
|
54
59
|
};
|
|
60
|
+
exports.safeParallel = safeParallel;
|
|
55
61
|
/**
|
|
56
62
|
* Execute async operation with timeout
|
|
57
63
|
*/
|
|
@@ -61,10 +67,11 @@ const withTimeout = async (operation, timeoutMs, context) => {
|
|
|
61
67
|
return await Promise.race([operation(), timeoutPromise]);
|
|
62
68
|
}
|
|
63
69
|
catch (error) {
|
|
64
|
-
logger.error(`Timeout operation failed`, context, error);
|
|
70
|
+
logging_1.logger.error(`Timeout operation failed`, context, error);
|
|
65
71
|
throw error;
|
|
66
72
|
}
|
|
67
73
|
};
|
|
74
|
+
exports.withTimeout = withTimeout;
|
|
68
75
|
/**
|
|
69
76
|
* Cache async operation results with TTL
|
|
70
77
|
*/
|
|
@@ -80,6 +87,7 @@ const withCache = async (key, operation, ttlMs = 5 * 60 * 1000 // 5 minutes defa
|
|
|
80
87
|
cache.set(key, { data: result, timestamp: now, ttl: ttlMs });
|
|
81
88
|
return result;
|
|
82
89
|
};
|
|
90
|
+
exports.withCache = withCache;
|
|
83
91
|
/**
|
|
84
92
|
* Clear expired cache entries
|
|
85
93
|
*/
|
|
@@ -91,6 +99,7 @@ const clearExpiredCache = () => {
|
|
|
91
99
|
}
|
|
92
100
|
}
|
|
93
101
|
};
|
|
102
|
+
exports.clearExpiredCache = clearExpiredCache;
|
|
94
103
|
/**
|
|
95
104
|
* Debounce async operations
|
|
96
105
|
*/
|
|
@@ -109,7 +118,7 @@ const debounceAsync = (fn, delay, key) => {
|
|
|
109
118
|
resolve(result);
|
|
110
119
|
}
|
|
111
120
|
catch (error) {
|
|
112
|
-
logger.error(`Debounced operation failed`, key, error);
|
|
121
|
+
logging_1.logger.error(`Debounced operation failed`, key, error);
|
|
113
122
|
resolve(undefined);
|
|
114
123
|
}
|
|
115
124
|
}, delay);
|
|
@@ -117,5 +126,5 @@ const debounceAsync = (fn, delay, key) => {
|
|
|
117
126
|
});
|
|
118
127
|
};
|
|
119
128
|
};
|
|
120
|
-
|
|
129
|
+
exports.debounceAsync = debounceAsync;
|
|
121
130
|
//# sourceMappingURL=async-helpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-helpers.js","sourceRoot":"","sources":["../../src/utils/async-helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG
|
|
1
|
+
{"version":3,"file":"async-helpers.js","sourceRoot":"","sources":["../../src/utils/async-helpers.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,uCAAmC;AASnC;;;GAGG;AACH,MAAM,SAAS,GAAG,KAAK,EACrB,SAA2B,EAC3B,OAAgB,EACS,EAAE;IAC3B,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,SAAS,EAAE,CAAC;QAC/B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IACjC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,QAAQ,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAC3E,gBAAM,CAAC,KAAK,CAAC,2BAA2B,QAAQ,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QAC5E,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK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,CAAC,MAAM,CAAC,CAAC;gBAClB,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,gBAAM,CAAC,KAAK,CAAC,4BAA4B,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;oBACvD,OAAO,CAAC,SAAS,CAAC,CAAC;gBACrB,CAAC;YACH,CAAC,EAAE,KAAK,CAAC,CAAC;YAEV,WAAW,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAChC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;AASA,sCAAa"}
|
package/dist/utils/auth/auth.js
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Authentication utilities for wallet-based authentication
|
|
3
4
|
*/
|
|
4
|
-
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateAuthMessage = generateAuthMessage;
|
|
7
|
+
exports.isAuthExpired = isAuthExpired;
|
|
8
|
+
exports.getAuthStatusText = getAuthStatusText;
|
|
9
|
+
exports.canAccessProtectedFeatures = canAccessProtectedFeatures;
|
|
10
|
+
exports.isAuthStatusConnected = isAuthStatusConnected;
|
|
11
|
+
exports.generateNonce = generateNonce;
|
|
12
|
+
exports.extractNonceFromMessage = extractNonceFromMessage;
|
|
13
|
+
exports.isValidNonce = isValidNonce;
|
|
14
|
+
const enums_1 = require("../../types/business/enums");
|
|
5
15
|
/**
|
|
6
16
|
* Generate an authentication message with a nonce
|
|
7
17
|
* @param emailDomain - The email domain/service name to display in the auth message
|
|
8
18
|
* @param nonce - Optional nonce value. If not provided, a random one will be generated
|
|
9
19
|
* @returns Authentication message string
|
|
10
20
|
*/
|
|
11
|
-
|
|
21
|
+
function generateAuthMessage(emailDomain, nonce) {
|
|
12
22
|
const actualNonce = nonce || `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
13
23
|
return `Authenticate with ${emailDomain}\nNonce: ${actualNonce}`;
|
|
14
24
|
}
|
|
@@ -17,20 +27,20 @@ export function generateAuthMessage(emailDomain, nonce) {
|
|
|
17
27
|
* @param createdAt - The date when authentication was created
|
|
18
28
|
* @param expirationHours - Number of hours until expiration (default: 24)
|
|
19
29
|
*/
|
|
20
|
-
|
|
30
|
+
function isAuthExpired(createdAt, expirationHours = 24) {
|
|
21
31
|
const expirationTime = new Date(createdAt.getTime() + expirationHours * 60 * 60 * 1000);
|
|
22
32
|
return new Date() > expirationTime;
|
|
23
33
|
}
|
|
24
34
|
/**
|
|
25
35
|
* Get human-readable text for authentication status
|
|
26
36
|
*/
|
|
27
|
-
|
|
37
|
+
function getAuthStatusText(status) {
|
|
28
38
|
switch (status) {
|
|
29
|
-
case AuthStatus.DISCONNECTED:
|
|
39
|
+
case enums_1.AuthStatus.DISCONNECTED:
|
|
30
40
|
return 'Not connected';
|
|
31
|
-
case AuthStatus.CONNECTED:
|
|
41
|
+
case enums_1.AuthStatus.CONNECTED:
|
|
32
42
|
return 'Connected - Please verify';
|
|
33
|
-
case AuthStatus.VERIFIED:
|
|
43
|
+
case enums_1.AuthStatus.VERIFIED:
|
|
34
44
|
return 'Authenticated';
|
|
35
45
|
default:
|
|
36
46
|
return 'Unknown status';
|
|
@@ -39,32 +49,32 @@ export function getAuthStatusText(status) {
|
|
|
39
49
|
/**
|
|
40
50
|
* Check if user can access protected features
|
|
41
51
|
*/
|
|
42
|
-
|
|
43
|
-
return status === AuthStatus.VERIFIED;
|
|
52
|
+
function canAccessProtectedFeatures(status) {
|
|
53
|
+
return status === enums_1.AuthStatus.VERIFIED;
|
|
44
54
|
}
|
|
45
55
|
/**
|
|
46
56
|
* Check if auth status indicates wallet is connected (either connected or verified)
|
|
47
57
|
*/
|
|
48
|
-
|
|
49
|
-
return status === AuthStatus.CONNECTED || status === AuthStatus.VERIFIED;
|
|
58
|
+
function isAuthStatusConnected(status) {
|
|
59
|
+
return status === enums_1.AuthStatus.CONNECTED || status === enums_1.AuthStatus.VERIFIED;
|
|
50
60
|
}
|
|
51
61
|
/**
|
|
52
62
|
* Generate a random nonce for authentication
|
|
53
63
|
*/
|
|
54
|
-
|
|
64
|
+
function generateNonce() {
|
|
55
65
|
return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
56
66
|
}
|
|
57
67
|
/**
|
|
58
68
|
* Extract nonce from an authentication message
|
|
59
69
|
*/
|
|
60
|
-
|
|
70
|
+
function extractNonceFromMessage(message) {
|
|
61
71
|
const match = message.match(/Nonce:\s*(.+)$/m);
|
|
62
72
|
return match ? match[1].trim() : undefined;
|
|
63
73
|
}
|
|
64
74
|
/**
|
|
65
75
|
* Validate that a nonce meets basic requirements
|
|
66
76
|
*/
|
|
67
|
-
|
|
77
|
+
function isValidNonce(nonce) {
|
|
68
78
|
if (!nonce || typeof nonce !== 'string') {
|
|
69
79
|
return false;
|
|
70
80
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/utils/auth/auth.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/utils/auth/auth.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAWH,kDAOC;AAOD,sCAKC;AAKD,8CAWC;AAKD,gEAEC;AAKD,sDAEC;AAKD,sCAEC;AAKD,0DAGC;AAKD,oCAwBC;AAtGD,sDAAwD;AAGxD;;;;;GAKG;AACH,SAAgB,mBAAmB,CACjC,WAAmB,EACnB,KAAwB;IAExB,MAAM,WAAW,GACf,KAAK,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;IACtE,OAAO,qBAAqB,WAAW,YAAY,WAAW,EAAE,CAAC;AACnE,CAAC;AAED;;;;GAIG;AACH,SAAgB,aAAa,CAAC,S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B,YAAY,CAAC,KAAa;IACxC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,yCAAyC;IACzC,IAAI,KAAK,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;QACtB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,oEAAoE;IACpE,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/B,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;QACtB,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACzC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;YACtB,6CAA6C;YAC7C,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;YACnD,IAAI,SAAS,GAAG,SAAS,EAAE,CAAC;gBAC1B,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/utils/auth/index.js
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidNonce = exports.isAuthStatusConnected = exports.isAuthExpired = exports.getAuthStatusText = exports.generateNonce = exports.generateAuthMessage = exports.extractNonceFromMessage = exports.canAccessProtectedFeatures = void 0;
|
|
1
4
|
// Authentication utilities
|
|
2
|
-
|
|
5
|
+
var auth_1 = require("./auth");
|
|
6
|
+
Object.defineProperty(exports, "canAccessProtectedFeatures", { enumerable: true, get: function () { return auth_1.canAccessProtectedFeatures; } });
|
|
7
|
+
Object.defineProperty(exports, "extractNonceFromMessage", { enumerable: true, get: function () { return auth_1.extractNonceFromMessage; } });
|
|
8
|
+
Object.defineProperty(exports, "generateAuthMessage", { enumerable: true, get: function () { return auth_1.generateAuthMessage; } });
|
|
9
|
+
Object.defineProperty(exports, "generateNonce", { enumerable: true, get: function () { return auth_1.generateNonce; } });
|
|
10
|
+
Object.defineProperty(exports, "getAuthStatusText", { enumerable: true, get: function () { return auth_1.getAuthStatusText; } });
|
|
11
|
+
Object.defineProperty(exports, "isAuthExpired", { enumerable: true, get: function () { return auth_1.isAuthExpired; } });
|
|
12
|
+
Object.defineProperty(exports, "isAuthStatusConnected", { enumerable: true, get: function () { return auth_1.isAuthStatusConnected; } });
|
|
13
|
+
Object.defineProperty(exports, "isValidNonce", { enumerable: true, get: function () { return auth_1.isValidNonce; } });
|
|
3
14
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/auth/index.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/auth/index.ts"],"names":[],"mappings":";;;AAAA,2BAA2B;AAC3B,+BASgB;AARd,kHAAA,0BAA0B,OAAA;AAC1B,+GAAA,uBAAuB,OAAA;AACvB,2GAAA,mBAAmB,OAAA;AACnB,qGAAA,aAAa,OAAA;AACb,yGAAA,iBAAiB,OAAA;AACjB,qGAAA,aAAa,OAAA;AACb,6GAAA,qBAAqB,OAAA;AACrB,oGAAA,YAAY,OAAA"}
|
|
@@ -1,28 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Blockchain address utilities for multi-chain support
|
|
3
4
|
*
|
|
4
5
|
* Provides validation and detection for various blockchain address formats
|
|
5
6
|
* including EVM addresses, Solana addresses, ENS names, and SNS names.
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.AddressType = void 0;
|
|
10
|
+
exports.isENSName = isENSName;
|
|
11
|
+
exports.isSNSName = isSNSName;
|
|
12
|
+
exports.getAddressType = getAddressType;
|
|
13
|
+
exports.isValidWalletAddress = isValidWalletAddress;
|
|
14
|
+
exports.isValidSignature = isValidSignature;
|
|
15
|
+
exports.parseEmailAddress = parseEmailAddress;
|
|
16
|
+
exports.formatWalletAddress = formatWalletAddress;
|
|
17
|
+
exports.getChainDisplayName = getChainDisplayName;
|
|
18
|
+
const enums_1 = require("../../types/business/enums");
|
|
8
19
|
// Import base validation functions from common types
|
|
9
|
-
|
|
20
|
+
const common_1 = require("../../types/blockchain/common");
|
|
10
21
|
/**
|
|
11
22
|
* Address type enumeration
|
|
12
23
|
*/
|
|
13
|
-
|
|
24
|
+
var AddressType;
|
|
14
25
|
(function (AddressType) {
|
|
15
26
|
AddressType["EVMAddress"] = "EVMAddress";
|
|
16
27
|
AddressType["SolanaAddress"] = "SolanaAddress";
|
|
17
28
|
AddressType["ENSName"] = "ENSName";
|
|
18
29
|
AddressType["SNSName"] = "SNSName";
|
|
19
|
-
})(AddressType || (AddressType = {}));
|
|
30
|
+
})(AddressType || (exports.AddressType = AddressType = {}));
|
|
20
31
|
// Address validation functions are now imported directly from common.ts
|
|
21
32
|
// Use isEvmAddress and isSolanaAddress from '../../types/blockchain/common'
|
|
22
33
|
/**
|
|
23
34
|
* Check if address is an ENS name (.eth or .box)
|
|
24
35
|
*/
|
|
25
|
-
|
|
36
|
+
function isENSName(address) {
|
|
26
37
|
const lowerAddress = address.toLowerCase();
|
|
27
38
|
// ENS names end with .eth or .box
|
|
28
39
|
if (!lowerAddress.endsWith('.eth') && !lowerAddress.endsWith('.box')) {
|
|
@@ -54,7 +65,7 @@ export function isENSName(address) {
|
|
|
54
65
|
* Check if address is an SNS name (Solana name service)
|
|
55
66
|
* Supports: .sol, .abc, .bonk, .poor, .gm, .dao, .defi, .web3
|
|
56
67
|
*/
|
|
57
|
-
|
|
68
|
+
function isSNSName(address) {
|
|
58
69
|
const lowerAddress = address.toLowerCase();
|
|
59
70
|
// List of supported Solana name extensions
|
|
60
71
|
const snsExtensions = [
|
|
@@ -96,13 +107,13 @@ export function isSNSName(address) {
|
|
|
96
107
|
* Determine the address type from a string
|
|
97
108
|
* Case insensitive as addresses/names are often case insensitive
|
|
98
109
|
*/
|
|
99
|
-
|
|
110
|
+
function getAddressType(address, parentAddressType = undefined) {
|
|
100
111
|
// Check for EVM address (0x followed by 40 hex characters)
|
|
101
|
-
if (isEvmAddress(address)) {
|
|
112
|
+
if ((0, common_1.isEvmAddress)(address)) {
|
|
102
113
|
return AddressType.EVMAddress;
|
|
103
114
|
}
|
|
104
115
|
// Check for Solana address (base58 encoded, 32-44 characters)
|
|
105
|
-
if (isSolanaAddress(address)) {
|
|
116
|
+
if ((0, common_1.isSolanaAddress)(address)) {
|
|
106
117
|
return AddressType.SolanaAddress;
|
|
107
118
|
}
|
|
108
119
|
// If parent address type is provided and address contains ".", it's a domain name
|
|
@@ -119,16 +130,16 @@ export function getAddressType(address, parentAddressType = undefined) {
|
|
|
119
130
|
/**
|
|
120
131
|
* Validate a wallet address for a specific chain type
|
|
121
132
|
*/
|
|
122
|
-
|
|
133
|
+
function isValidWalletAddress(address, chainType) {
|
|
123
134
|
if (!address || typeof address !== 'string') {
|
|
124
135
|
return false;
|
|
125
136
|
}
|
|
126
137
|
const addressType = getAddressType(address);
|
|
127
138
|
switch (chainType) {
|
|
128
|
-
case ChainType.EVM:
|
|
139
|
+
case enums_1.ChainType.EVM:
|
|
129
140
|
return (addressType === AddressType.EVMAddress ||
|
|
130
141
|
addressType === AddressType.ENSName);
|
|
131
|
-
case ChainType.SOLANA:
|
|
142
|
+
case enums_1.ChainType.SOLANA:
|
|
132
143
|
return (addressType === AddressType.SolanaAddress ||
|
|
133
144
|
addressType === AddressType.SNSName);
|
|
134
145
|
default:
|
|
@@ -139,15 +150,15 @@ export function isValidWalletAddress(address, chainType) {
|
|
|
139
150
|
/**
|
|
140
151
|
* Check if a signature is valid for a specific chain type
|
|
141
152
|
*/
|
|
142
|
-
|
|
153
|
+
function isValidSignature(signature, chainType) {
|
|
143
154
|
if (!signature || typeof signature !== 'string') {
|
|
144
155
|
return false;
|
|
145
156
|
}
|
|
146
157
|
switch (chainType) {
|
|
147
|
-
case ChainType.EVM:
|
|
158
|
+
case enums_1.ChainType.EVM:
|
|
148
159
|
// EVM signature validation (0x followed by 130 hex characters)
|
|
149
160
|
return /^0x[a-fA-F0-9]{130}$/.test(signature);
|
|
150
|
-
case ChainType.SOLANA:
|
|
161
|
+
case enums_1.ChainType.SOLANA:
|
|
151
162
|
// Solana signature validation (base58 encoded, typically 87-88 characters)
|
|
152
163
|
return /^[1-9A-HJ-NP-Za-km-z]{87,88}$/.test(signature);
|
|
153
164
|
default:
|
|
@@ -158,7 +169,7 @@ export function isValidSignature(signature, chainType) {
|
|
|
158
169
|
/**
|
|
159
170
|
* Parse an email address into its components
|
|
160
171
|
*/
|
|
161
|
-
|
|
172
|
+
function parseEmailAddress(email) {
|
|
162
173
|
if (!email || typeof email !== 'string') {
|
|
163
174
|
return undefined;
|
|
164
175
|
}
|
|
@@ -181,7 +192,7 @@ export function parseEmailAddress(email) {
|
|
|
181
192
|
* Format a wallet address for display
|
|
182
193
|
* Shows first 6 and last 4 characters with ellipsis
|
|
183
194
|
*/
|
|
184
|
-
|
|
195
|
+
function formatWalletAddress(address) {
|
|
185
196
|
if (!address || address.length < 10) {
|
|
186
197
|
return address;
|
|
187
198
|
}
|
|
@@ -198,14 +209,14 @@ export function formatWalletAddress(address) {
|
|
|
198
209
|
/**
|
|
199
210
|
* Get display name for a chain type
|
|
200
211
|
*/
|
|
201
|
-
|
|
212
|
+
function getChainDisplayName(chainType) {
|
|
202
213
|
if (!chainType) {
|
|
203
214
|
return 'Unknown Chain';
|
|
204
215
|
}
|
|
205
216
|
switch (chainType) {
|
|
206
|
-
case ChainType.EVM:
|
|
217
|
+
case enums_1.ChainType.EVM:
|
|
207
218
|
return 'EVM Chain';
|
|
208
|
-
case ChainType.SOLANA:
|
|
219
|
+
case enums_1.ChainType.SOLANA:
|
|
209
220
|
return 'Solana';
|
|
210
221
|
default:
|
|
211
222
|
return 'Blockchain';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.js","sourceRoot":"","sources":["../../../src/utils/blockchain/address.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"address.js","sourceRoot":"","sources":["../../../src/utils/blockchain/address.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAmCH,8BAiCC;AAMD,8BA8CC;AAMD,wCAyBC;AAKD,oDA2BC;AAKD,4CAqBC;AAKD,8CAsBC;AAMD,kDAiBC;AAKD,kDAaC;AAnRD,sDAAuD;AAEvD,qDAAqD;AACrD,0DAA8E;AAE9E;;GAEG;AACH,IAAY,WAKX;AALD,WAAY,WAAW;IACrB,wCAAyB,CAAA;IACzB,8CAA+B,CAAA;IAC/B,kCAAmB,CAAA;IACnB,kCAAmB,CAAA;AACrB,CAAC,EALW,WAAW,2BAAX,WAAW,QAKtB;AAcD,wEAAwE;AACxE,4EAA4E;AAE5E;;GAEG;AACH,SAAgB,SAAS,CAAC,OAAe;IACvC,MAAM,YAAY,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAE3C,kCAAkC;IAClC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACrE,OAAO,KAAK,CAAC;IACf,CAAC;IAED,+CAA+C;IAC/C,MAAM,cAAc,GAAG,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC;QAClD,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC3B,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAE9B,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CA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functions for multi-chain event processing
|
|
@@ -10,6 +11,16 @@
|
|
|
10
11
|
* - Address validation
|
|
11
12
|
* - Testnet detection
|
|
12
13
|
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.createMultiChainId = createMultiChainId;
|
|
16
|
+
exports.createUserMultiChainId = createUserMultiChainId;
|
|
17
|
+
exports.createChainStatsId = createChainStatsId;
|
|
18
|
+
exports.createDelegationId = createDelegationId;
|
|
19
|
+
exports.normalizeAddress = normalizeAddress;
|
|
20
|
+
exports.formatBigInt = formatBigInt;
|
|
21
|
+
exports.isZeroAddress = isZeroAddress;
|
|
22
|
+
exports.isTestNet = isTestNet;
|
|
23
|
+
exports.validateEventArgs = validateEventArgs;
|
|
13
24
|
// ========================================
|
|
14
25
|
// ID GENERATION UTILITIES
|
|
15
26
|
// ========================================
|
|
@@ -27,7 +38,7 @@
|
|
|
27
38
|
* // Result: "1-0x123...-0"
|
|
28
39
|
* ```
|
|
29
40
|
*/
|
|
30
|
-
|
|
41
|
+
function createMultiChainId(chainId, txHash, logIndex) {
|
|
31
42
|
return `${chainId}-${txHash}-${logIndex}`;
|
|
32
43
|
}
|
|
33
44
|
/**
|
|
@@ -43,7 +54,7 @@ export function createMultiChainId(chainId, txHash, logIndex) {
|
|
|
43
54
|
* // Result: "137-0xabc..."
|
|
44
55
|
* ```
|
|
45
56
|
*/
|
|
46
|
-
|
|
57
|
+
function createUserMultiChainId(chainId, address) {
|
|
47
58
|
return `${chainId}-${address.toLowerCase()}`;
|
|
48
59
|
}
|
|
49
60
|
/**
|
|
@@ -52,7 +63,7 @@ export function createUserMultiChainId(chainId, address) {
|
|
|
52
63
|
* @param chainId - Network chain ID
|
|
53
64
|
* @returns Formatted ID: "chainId-global"
|
|
54
65
|
*/
|
|
55
|
-
|
|
66
|
+
function createChainStatsId(chainId) {
|
|
56
67
|
return `${chainId}-global`;
|
|
57
68
|
}
|
|
58
69
|
/**
|
|
@@ -62,7 +73,7 @@ export function createChainStatsId(chainId) {
|
|
|
62
73
|
* @param isTestNet - Whether the chain is a testnet
|
|
63
74
|
* @returns Formatted ID: "delegatorAddress-testNet"
|
|
64
75
|
*/
|
|
65
|
-
|
|
76
|
+
function createDelegationId(delegatorAddress, isTestNet) {
|
|
66
77
|
return `${delegatorAddress.toLowerCase()}-${isTestNet}`;
|
|
67
78
|
}
|
|
68
79
|
// ========================================
|
|
@@ -71,13 +82,13 @@ export function createDelegationId(delegatorAddress, isTestNet) {
|
|
|
71
82
|
/**
|
|
72
83
|
* Normalize address to lowercase
|
|
73
84
|
*/
|
|
74
|
-
|
|
85
|
+
function normalizeAddress(address) {
|
|
75
86
|
return address.toLowerCase();
|
|
76
87
|
}
|
|
77
88
|
/**
|
|
78
89
|
* Format bigint for display
|
|
79
90
|
*/
|
|
80
|
-
|
|
91
|
+
function formatBigInt(value, decimals = 18) {
|
|
81
92
|
const divisor = BigInt(10 ** decimals);
|
|
82
93
|
const whole = value / divisor;
|
|
83
94
|
const fraction = value % divisor;
|
|
@@ -89,7 +100,7 @@ export function formatBigInt(value, decimals = 18) {
|
|
|
89
100
|
/**
|
|
90
101
|
* Check if address is zero address (delegation clearing)
|
|
91
102
|
*/
|
|
92
|
-
|
|
103
|
+
function isZeroAddress(address) {
|
|
93
104
|
return address.toLowerCase() === '0x0000000000000000000000000000000000000000';
|
|
94
105
|
}
|
|
95
106
|
/**
|
|
@@ -97,7 +108,7 @@ export function isZeroAddress(address) {
|
|
|
97
108
|
* @param chainId The blockchain chain ID
|
|
98
109
|
* @returns true if the chain is a testnet, false if mainnet
|
|
99
110
|
*/
|
|
100
|
-
|
|
111
|
+
function isTestNet(chainId) {
|
|
101
112
|
// EVM Testnets (positive chain IDs)
|
|
102
113
|
const evmTestnets = new Set([
|
|
103
114
|
31337, // Hardhat (local development)
|
|
@@ -120,7 +131,7 @@ export function isTestNet(chainId) {
|
|
|
120
131
|
/**
|
|
121
132
|
* Validate event arguments
|
|
122
133
|
*/
|
|
123
|
-
|
|
134
|
+
function validateEventArgs(args, requiredFields) {
|
|
124
135
|
for (const field of requiredFields) {
|
|
125
136
|
if (args[field] === undefined || args[field] === null) {
|
|
126
137
|
console.error(`❌ Missing required field: ${String(field)}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-helpers.js","sourceRoot":"","sources":["../../../src/utils/blockchain/event-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;
|
|
1
|
+
{"version":3,"file":"event-helpers.js","sourceRoot":"","sources":["../../../src/utils/blockchain/event-helpers.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;AAoBH,gDAMC;AAeD,wDAKC;AAQD,gDAEC;AASD,gDAKC;AASD,4CAEC;AAKD,oCAUC;AAKD,sCAEC;AAOD,8BAqBC;AAKD,8CAWC;AAjJD,2CAA2C;AAC3C,0BAA0B;AAC1B,2CAA2C;AAE3C;;;;;;;;;;;;;GAaG;AACH,SAAgB,kBAAkB,CAChC,OAAe,EACf,MAAc,EACd,QAAgB;IAEhB,OAAO,GAAG,OAAO,IAAI,MAAM,IAAI,QAAQ,EAAE,CAAC;AAC5C,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,sBAAsB,CACpC,OAAe,EACf,OAAe;IAEf,OAAO,GAAG,OAAO,IAAI,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;AAC/C,CAAC;AAED;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAC,OAAe;IAChD,OAAO,GAAG,OAAO,SAAS,CAAC;AAC7B,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,kBAAkB,CAChC,gBAAwB,EACxB,SAAkB;IAElB,OAAO,GAAG,gBAAgB,CAAC,WAAW,EAAE,IAAI,SAAS,EAAE,CAAC;AAC1D,CAAC;AAED,2CAA2C;AAC3C,oBAAoB;AACpB,2CAA2C;AAE3C;;GAEG;AACH,SAAgB,gBAAgB,CAAC,OAAe;IAC9C,OAAO,OAAO,CAAC,WAAW,EA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AAC;AACjE,CAAC;AAED;;GAEG;AACH,SAAgB,iBAAiB,CAC/B,IAAO,EACP,cAA2B;IAE3B,KAAK,MAAM,KAAK,IAAI,cAAc,EAAE,CAAC;QACnC,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,SAAS,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC;YACtD,OAAO,CAAC,KAAK,CAAC,6BAA6B,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAC5D,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1,5 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateEventArgs = exports.normalizeAddress = exports.isZeroAddress = exports.isTestNet = exports.formatBigInt = exports.createUserMultiChainId = exports.createMultiChainId = exports.createDelegationId = exports.createChainStatsId = exports.isSolanaAddress = exports.isEvmAddress = exports.parseEmailAddress = exports.isValidWalletAddress = exports.isValidSignature = exports.isSNSName = exports.isENSName = exports.getChainDisplayName = exports.getAddressType = exports.formatWalletAddress = exports.AddressType = void 0;
|
|
4
|
+
var address_1 = require("./address");
|
|
5
|
+
Object.defineProperty(exports, "AddressType", { enumerable: true, get: function () { return address_1.AddressType; } });
|
|
6
|
+
Object.defineProperty(exports, "formatWalletAddress", { enumerable: true, get: function () { return address_1.formatWalletAddress; } });
|
|
7
|
+
Object.defineProperty(exports, "getAddressType", { enumerable: true, get: function () { return address_1.getAddressType; } });
|
|
8
|
+
Object.defineProperty(exports, "getChainDisplayName", { enumerable: true, get: function () { return address_1.getChainDisplayName; } });
|
|
9
|
+
Object.defineProperty(exports, "isENSName", { enumerable: true, get: function () { return address_1.isENSName; } });
|
|
10
|
+
Object.defineProperty(exports, "isSNSName", { enumerable: true, get: function () { return address_1.isSNSName; } });
|
|
11
|
+
Object.defineProperty(exports, "isValidSignature", { enumerable: true, get: function () { return address_1.isValidSignature; } });
|
|
12
|
+
Object.defineProperty(exports, "isValidWalletAddress", { enumerable: true, get: function () { return address_1.isValidWalletAddress; } });
|
|
13
|
+
Object.defineProperty(exports, "parseEmailAddress", { enumerable: true, get: function () { return address_1.parseEmailAddress; } });
|
|
2
14
|
// Export address validation functions from common.ts
|
|
3
|
-
|
|
4
|
-
|
|
15
|
+
var common_1 = require("../../types/blockchain/common");
|
|
16
|
+
Object.defineProperty(exports, "isEvmAddress", { enumerable: true, get: function () { return common_1.isEvmAddress; } });
|
|
17
|
+
Object.defineProperty(exports, "isSolanaAddress", { enumerable: true, get: function () { return common_1.isSolanaAddress; } });
|
|
18
|
+
var event_helpers_1 = require("./event-helpers");
|
|
19
|
+
Object.defineProperty(exports, "createChainStatsId", { enumerable: true, get: function () { return event_helpers_1.createChainStatsId; } });
|
|
20
|
+
Object.defineProperty(exports, "createDelegationId", { enumerable: true, get: function () { return event_helpers_1.createDelegationId; } });
|
|
21
|
+
Object.defineProperty(exports, "createMultiChainId", { enumerable: true, get: function () { return event_helpers_1.createMultiChainId; } });
|
|
22
|
+
Object.defineProperty(exports, "createUserMultiChainId", { enumerable: true, get: function () { return event_helpers_1.createUserMultiChainId; } });
|
|
23
|
+
Object.defineProperty(exports, "formatBigInt", { enumerable: true, get: function () { return event_helpers_1.formatBigInt; } });
|
|
24
|
+
Object.defineProperty(exports, "isTestNet", { enumerable: true, get: function () { return event_helpers_1.isTestNet; } });
|
|
25
|
+
Object.defineProperty(exports, "isZeroAddress", { enumerable: true, get: function () { return event_helpers_1.isZeroAddress; } });
|
|
26
|
+
Object.defineProperty(exports, "normalizeAddress", { enumerable: true, get: function () { return event_helpers_1.normalizeAddress; } });
|
|
27
|
+
Object.defineProperty(exports, "validateEventArgs", { enumerable: true, get: function () { return event_helpers_1.validateEventArgs; } });
|
|
5
28
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/blockchain/index.ts"],"names":[],"mappings":"AAGA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/blockchain/index.ts"],"names":[],"mappings":";;;AAGA,qCAUmB;AATjB,sGAAA,WAAW,OAAA;AACX,8GAAA,mBAAmB,OAAA;AACnB,yGAAA,cAAc,OAAA;AACd,8GAAA,mBAAmB,OAAA;AACnB,oGAAA,SAAS,OAAA;AACT,oGAAA,SAAS,OAAA;AACT,2GAAA,gBAAgB,OAAA;AAChB,+GAAA,oBAAoB,OAAA;AACpB,4GAAA,iBAAiB,OAAA;AAGnB,qDAAqD;AACrD,wDAA8E;AAArE,sGAAA,YAAY,OAAA;AAAE,yGAAA,eAAe,OAAA;AAQtC,iDAUyB;AATvB,mHAAA,kBAAkB,OAAA;AAClB,mHAAA,kBAAkB,OAAA;AAClB,mHAAA,kBAAkB,OAAA;AAClB,uHAAA,sBAAsB,OAAA;AACtB,6GAAA,YAAY,OAAA;AACZ,0GAAA,SAAS,OAAA;AACT,8GAAA,aAAa,OAAA;AACb,iHAAA,gBAAgB,OAAA;AAChB,kHAAA,iBAAiB,OAAA"}
|