@sudobility/types 1.8.21
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/CLAUDE.md +285 -0
- package/README.md +310 -0
- package/dist/index.cjs +62 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +62 -0
- package/dist/index.js.map +1 -0
- package/dist/types/blockchain/common.cjs +102 -0
- package/dist/types/blockchain/common.d.ts +262 -0
- package/dist/types/blockchain/common.d.ts.map +1 -0
- package/dist/types/blockchain/common.js +102 -0
- package/dist/types/blockchain/common.js.map +1 -0
- package/dist/types/blockchain/index.cjs +18 -0
- package/dist/types/blockchain/index.d.ts +4 -0
- package/dist/types/blockchain/index.d.ts.map +1 -0
- package/dist/types/blockchain/index.js +18 -0
- package/dist/types/blockchain/index.js.map +1 -0
- package/dist/types/blockchain/validation.cjs +88 -0
- package/dist/types/blockchain/validation.d.ts +9 -0
- package/dist/types/blockchain/validation.d.ts.map +1 -0
- package/dist/types/blockchain/validation.js +88 -0
- package/dist/types/blockchain/validation.js.map +1 -0
- package/dist/types/business/enums.cjs +314 -0
- package/dist/types/business/enums.d.ts +227 -0
- package/dist/types/business/enums.d.ts.map +1 -0
- package/dist/types/business/enums.js +314 -0
- package/dist/types/business/enums.js.map +1 -0
- package/dist/types/business/index.cjs +33 -0
- package/dist/types/business/index.d.ts +5 -0
- package/dist/types/business/index.d.ts.map +1 -0
- package/dist/types/business/index.js +33 -0
- package/dist/types/business/index.js.map +1 -0
- package/dist/types/business/wallet-status.cjs +38 -0
- package/dist/types/business/wallet-status.d.ts +32 -0
- package/dist/types/business/wallet-status.d.ts.map +1 -0
- package/dist/types/business/wallet-status.js +38 -0
- package/dist/types/business/wallet-status.js.map +1 -0
- package/dist/types/common.cjs +6 -0
- package/dist/types/common.d.ts +142 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +6 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/config/app-config.cjs +6 -0
- package/dist/types/config/app-config.d.ts +67 -0
- package/dist/types/config/app-config.d.ts.map +1 -0
- package/dist/types/config/app-config.js +6 -0
- package/dist/types/config/app-config.js.map +1 -0
- package/dist/types/config/environment.cjs +24 -0
- package/dist/types/config/environment.d.ts +68 -0
- package/dist/types/config/environment.d.ts.map +1 -0
- package/dist/types/config/environment.js +24 -0
- package/dist/types/config/environment.js.map +1 -0
- package/dist/types/config/index.cjs +6 -0
- package/dist/types/config/index.d.ts +4 -0
- package/dist/types/config/index.d.ts.map +1 -0
- package/dist/types/config/index.js +6 -0
- package/dist/types/config/index.js.map +1 -0
- package/dist/types/index.cjs +35 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +35 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/indexer/index.cjs +19 -0
- package/dist/types/indexer/index.d.ts +3 -0
- package/dist/types/indexer/index.d.ts.map +1 -0
- package/dist/types/indexer/index.js +19 -0
- package/dist/types/indexer/index.js.map +1 -0
- package/dist/types/indexer/indexer-guards.cjs +145 -0
- package/dist/types/indexer/indexer-guards.d.ts +26 -0
- package/dist/types/indexer/indexer-guards.d.ts.map +1 -0
- package/dist/types/indexer/indexer-guards.js +145 -0
- package/dist/types/indexer/indexer-guards.js.map +1 -0
- package/dist/types/indexer/indexer-responses.cjs +8 -0
- package/dist/types/indexer/indexer-responses.d.ts +136 -0
- package/dist/types/indexer/indexer-responses.d.ts.map +1 -0
- package/dist/types/indexer/indexer-responses.js +8 -0
- package/dist/types/indexer/indexer-responses.js.map +1 -0
- package/dist/types/infrastructure/analytics.cjs +212 -0
- package/dist/types/infrastructure/analytics.d.ts +449 -0
- package/dist/types/infrastructure/analytics.d.ts.map +1 -0
- package/dist/types/infrastructure/analytics.js +212 -0
- package/dist/types/infrastructure/analytics.js.map +1 -0
- package/dist/types/infrastructure/api.cjs +17 -0
- package/dist/types/infrastructure/api.d.ts +152 -0
- package/dist/types/infrastructure/api.d.ts.map +1 -0
- package/dist/types/infrastructure/api.js +17 -0
- package/dist/types/infrastructure/api.js.map +1 -0
- package/dist/types/infrastructure/index.cjs +14 -0
- package/dist/types/infrastructure/index.d.ts +9 -0
- package/dist/types/infrastructure/index.d.ts.map +1 -0
- package/dist/types/infrastructure/index.js +14 -0
- package/dist/types/infrastructure/index.js.map +1 -0
- package/dist/types/infrastructure/navigation.cjs +3 -0
- package/dist/types/infrastructure/navigation.d.ts +56 -0
- package/dist/types/infrastructure/navigation.d.ts.map +1 -0
- package/dist/types/infrastructure/navigation.js +3 -0
- package/dist/types/infrastructure/navigation.js.map +1 -0
- package/dist/types/infrastructure/network.cjs +18 -0
- package/dist/types/infrastructure/network.d.ts +48 -0
- package/dist/types/infrastructure/network.d.ts.map +1 -0
- package/dist/types/infrastructure/network.js +18 -0
- package/dist/types/infrastructure/network.js.map +1 -0
- package/dist/types/infrastructure/wallet.cjs +37 -0
- package/dist/types/infrastructure/wallet.d.ts +33 -0
- package/dist/types/infrastructure/wallet.d.ts.map +1 -0
- package/dist/types/infrastructure/wallet.js +37 -0
- package/dist/types/infrastructure/wallet.js.map +1 -0
- package/dist/types/kyc/index.cjs +19 -0
- package/dist/types/kyc/index.d.ts +2 -0
- package/dist/types/kyc/index.d.ts.map +1 -0
- package/dist/types/kyc/index.js +19 -0
- package/dist/types/kyc/index.js.map +1 -0
- package/dist/types/kyc/kyc-types.cjs +12 -0
- package/dist/types/kyc/kyc-types.d.ts +260 -0
- package/dist/types/kyc/kyc-types.d.ts.map +1 -0
- package/dist/types/kyc/kyc-types.js +12 -0
- package/dist/types/kyc/kyc-types.js.map +1 -0
- package/dist/types/mailer/index.cjs +19 -0
- package/dist/types/mailer/index.d.ts +2 -0
- package/dist/types/mailer/index.d.ts.map +1 -0
- package/dist/types/mailer/index.js +19 -0
- package/dist/types/mailer/index.js.map +1 -0
- package/dist/types/mailer/mail-types.cjs +38 -0
- package/dist/types/mailer/mail-types.d.ts +296 -0
- package/dist/types/mailer/mail-types.d.ts.map +1 -0
- package/dist/types/mailer/mail-types.js +38 -0
- package/dist/types/mailer/mail-types.js.map +1 -0
- package/dist/types/wildduck/index.cjs +19 -0
- package/dist/types/wildduck/index.d.ts +2 -0
- package/dist/types/wildduck/index.d.ts.map +1 -0
- package/dist/types/wildduck/index.js +19 -0
- package/dist/types/wildduck/index.js.map +1 -0
- package/dist/types/wildduck/wildduck-types.cjs +48 -0
- package/dist/types/wildduck/wildduck-types.d.ts +1239 -0
- package/dist/types/wildduck/wildduck-types.d.ts.map +1 -0
- package/dist/types/wildduck/wildduck-types.js +48 -0
- package/dist/types/wildduck/wildduck-types.js.map +1 -0
- package/dist/utils/async-helpers.cjs +130 -0
- package/dist/utils/async-helpers.d.ts +35 -0
- package/dist/utils/async-helpers.d.ts.map +1 -0
- package/dist/utils/async-helpers.js +130 -0
- package/dist/utils/async-helpers.js.map +1 -0
- package/dist/utils/auth/auth.cjs +96 -0
- package/dist/utils/auth/auth.d.ts +40 -0
- package/dist/utils/auth/auth.d.ts.map +1 -0
- package/dist/utils/auth/auth.js +96 -0
- package/dist/utils/auth/auth.js.map +1 -0
- package/dist/utils/auth/index.cjs +14 -0
- package/dist/utils/auth/index.d.ts +2 -0
- package/dist/utils/auth/index.d.ts.map +1 -0
- package/dist/utils/auth/index.js +14 -0
- package/dist/utils/auth/index.js.map +1 -0
- package/dist/utils/blockchain/address.cjs +231 -0
- package/dist/utils/blockchain/address.d.ts +65 -0
- package/dist/utils/blockchain/address.d.ts.map +1 -0
- package/dist/utils/blockchain/address.js +231 -0
- package/dist/utils/blockchain/address.js.map +1 -0
- package/dist/utils/blockchain/event-helpers.cjs +143 -0
- package/dist/utils/blockchain/event-helpers.d.ts +87 -0
- package/dist/utils/blockchain/event-helpers.d.ts.map +1 -0
- package/dist/utils/blockchain/event-helpers.js +143 -0
- package/dist/utils/blockchain/event-helpers.js.map +1 -0
- package/dist/utils/blockchain/index.cjs +30 -0
- package/dist/utils/blockchain/index.d.ts +8 -0
- package/dist/utils/blockchain/index.d.ts.map +1 -0
- package/dist/utils/blockchain/index.js +30 -0
- package/dist/utils/blockchain/index.js.map +1 -0
- package/dist/utils/blockchain/rpc-helpers.cjs +865 -0
- package/dist/utils/blockchain/rpc-helpers.d.ts +251 -0
- package/dist/utils/blockchain/rpc-helpers.d.ts.map +1 -0
- package/dist/utils/blockchain/rpc-helpers.js +865 -0
- package/dist/utils/blockchain/rpc-helpers.js.map +1 -0
- package/dist/utils/constants/application.cjs +158 -0
- package/dist/utils/constants/application.d.ts +119 -0
- package/dist/utils/constants/application.d.ts.map +1 -0
- package/dist/utils/constants/application.js +158 -0
- package/dist/utils/constants/application.js.map +1 -0
- package/dist/utils/constants/index.cjs +30 -0
- package/dist/utils/constants/index.d.ts +7 -0
- package/dist/utils/constants/index.d.ts.map +1 -0
- package/dist/utils/constants/index.js +30 -0
- package/dist/utils/constants/index.js.map +1 -0
- package/dist/utils/constants/status-values.cjs +14 -0
- package/dist/utils/constants/status-values.d.ts +12 -0
- package/dist/utils/constants/status-values.d.ts.map +1 -0
- package/dist/utils/constants/status-values.js +14 -0
- package/dist/utils/constants/status-values.js.map +1 -0
- package/dist/utils/formatting/currency.cjs +36 -0
- package/dist/utils/formatting/currency.d.ts +26 -0
- package/dist/utils/formatting/currency.d.ts.map +1 -0
- package/dist/utils/formatting/currency.js +36 -0
- package/dist/utils/formatting/currency.js.map +1 -0
- package/dist/utils/formatting/date.cjs +138 -0
- package/dist/utils/formatting/date.d.ts +33 -0
- package/dist/utils/formatting/date.d.ts.map +1 -0
- package/dist/utils/formatting/date.js +138 -0
- package/dist/utils/formatting/date.js.map +1 -0
- package/dist/utils/formatting/index.cjs +37 -0
- package/dist/utils/formatting/index.d.ts +4 -0
- package/dist/utils/formatting/index.d.ts.map +1 -0
- package/dist/utils/formatting/index.js +37 -0
- package/dist/utils/formatting/index.js.map +1 -0
- package/dist/utils/formatting/string.cjs +193 -0
- package/dist/utils/formatting/string.d.ts +69 -0
- package/dist/utils/formatting/string.d.ts.map +1 -0
- package/dist/utils/formatting/string.js +193 -0
- package/dist/utils/formatting/string.js.map +1 -0
- package/dist/utils/index.cjs +28 -0
- package/dist/utils/index.d.ts +12 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +28 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logging/index.cjs +16 -0
- package/dist/utils/logging/index.d.ts +5 -0
- package/dist/utils/logging/index.d.ts.map +1 -0
- package/dist/utils/logging/index.js +16 -0
- package/dist/utils/logging/index.js.map +1 -0
- package/dist/utils/logging/logger.cjs +92 -0
- package/dist/utils/logging/logger.d.ts +70 -0
- package/dist/utils/logging/logger.d.ts.map +1 -0
- package/dist/utils/logging/logger.js +92 -0
- package/dist/utils/logging/logger.js.map +1 -0
- package/dist/utils/url/index.cjs +13 -0
- package/dist/utils/url/index.d.ts +5 -0
- package/dist/utils/url/index.d.ts.map +1 -0
- package/dist/utils/url/index.js +13 -0
- package/dist/utils/url/index.js.map +1 -0
- package/dist/utils/url/url-params.cjs +128 -0
- package/dist/utils/url/url-params.d.ts +36 -0
- package/dist/utils/url/url-params.d.ts.map +1 -0
- package/dist/utils/url/url-params.js +128 -0
- package/dist/utils/url/url-params.js.map +1 -0
- package/dist/utils/validation/index.cjs +25 -0
- package/dist/utils/validation/index.d.ts +5 -0
- package/dist/utils/validation/index.d.ts.map +1 -0
- package/dist/utils/validation/index.js +25 -0
- package/dist/utils/validation/index.js.map +1 -0
- package/dist/utils/validation/type-validation.cjs +167 -0
- package/dist/utils/validation/type-validation.d.ts +68 -0
- package/dist/utils/validation/type-validation.d.ts.map +1 -0
- package/dist/utils/validation/type-validation.js +167 -0
- package/dist/utils/validation/type-validation.js.map +1 -0
- package/dist/utils/validation/web3-username-validator.cjs +132 -0
- package/dist/utils/validation/web3-username-validator.d.ts +43 -0
- package/dist/utils/validation/web3-username-validator.d.ts.map +1 -0
- package/dist/utils/validation/web3-username-validator.js +132 -0
- package/dist/utils/validation/web3-username-validator.js.map +1 -0
- package/package.json +80 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Authentication utilities for wallet-based authentication
|
|
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");
|
|
15
|
+
/**
|
|
16
|
+
* Generate an authentication message with a nonce
|
|
17
|
+
*/
|
|
18
|
+
function generateAuthMessage(nonce) {
|
|
19
|
+
const actualNonce = nonce || `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
20
|
+
return `Authenticate with 0xMail\nNonce: ${actualNonce}`;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Check if authentication is expired
|
|
24
|
+
* @param createdAt - The date when authentication was created
|
|
25
|
+
* @param expirationHours - Number of hours until expiration (default: 24)
|
|
26
|
+
*/
|
|
27
|
+
function isAuthExpired(createdAt, expirationHours = 24) {
|
|
28
|
+
const expirationTime = new Date(createdAt.getTime() + expirationHours * 60 * 60 * 1000);
|
|
29
|
+
return new Date() > expirationTime;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get human-readable text for authentication status
|
|
33
|
+
*/
|
|
34
|
+
function getAuthStatusText(status) {
|
|
35
|
+
switch (status) {
|
|
36
|
+
case enums_1.AuthStatus.DISCONNECTED:
|
|
37
|
+
return 'Not connected';
|
|
38
|
+
case enums_1.AuthStatus.CONNECTED:
|
|
39
|
+
return 'Connected - Please verify';
|
|
40
|
+
case enums_1.AuthStatus.VERIFIED:
|
|
41
|
+
return 'Authenticated';
|
|
42
|
+
default:
|
|
43
|
+
return 'Unknown status';
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Check if user can access protected features
|
|
48
|
+
*/
|
|
49
|
+
function canAccessProtectedFeatures(status) {
|
|
50
|
+
return status === enums_1.AuthStatus.VERIFIED;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Check if auth status indicates wallet is connected (either connected or verified)
|
|
54
|
+
*/
|
|
55
|
+
function isAuthStatusConnected(status) {
|
|
56
|
+
return status === enums_1.AuthStatus.CONNECTED || status === enums_1.AuthStatus.VERIFIED;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Generate a random nonce for authentication
|
|
60
|
+
*/
|
|
61
|
+
function generateNonce() {
|
|
62
|
+
return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Extract nonce from an authentication message
|
|
66
|
+
*/
|
|
67
|
+
function extractNonceFromMessage(message) {
|
|
68
|
+
const match = message.match(/Nonce:\s*(.+)$/m);
|
|
69
|
+
return match ? match[1].trim() : undefined;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Validate that a nonce meets basic requirements
|
|
73
|
+
*/
|
|
74
|
+
function isValidNonce(nonce) {
|
|
75
|
+
if (!nonce || typeof nonce !== 'string') {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
// Nonce should be at least 10 characters
|
|
79
|
+
if (nonce.length < 10) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
// Nonce should not be too old (check if it starts with a timestamp)
|
|
83
|
+
const parts = nonce.split('-');
|
|
84
|
+
if (parts.length >= 2) {
|
|
85
|
+
const timestamp = parseInt(parts[0], 10);
|
|
86
|
+
if (!isNaN(timestamp)) {
|
|
87
|
+
// Check if timestamp is within last 24 hours
|
|
88
|
+
const oneDayAgo = Date.now() - 24 * 60 * 60 * 1000;
|
|
89
|
+
if (timestamp < oneDayAgo) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/utils/auth/auth.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +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;
|
|
4
|
+
// Authentication utilities
|
|
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; } });
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/auth/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,0BAA0B,EAC1B,uBAAuB,EACvB,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,qBAAqB,EACrB,YAAY,GACb,MAAM,QAAQ,CAAC"}
|
|
@@ -0,0 +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;
|
|
4
|
+
// Authentication utilities
|
|
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; } });
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Blockchain address utilities for multi-chain support
|
|
4
|
+
*
|
|
5
|
+
* Provides validation and detection for various blockchain address formats
|
|
6
|
+
* including EVM addresses, Solana addresses, ENS names, and SNS names.
|
|
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");
|
|
19
|
+
// Import base validation functions from common types
|
|
20
|
+
const common_1 = require("../../types/blockchain/common");
|
|
21
|
+
/**
|
|
22
|
+
* Address type enumeration
|
|
23
|
+
*/
|
|
24
|
+
var AddressType;
|
|
25
|
+
(function (AddressType) {
|
|
26
|
+
AddressType["EVMAddress"] = "EVMAddress";
|
|
27
|
+
AddressType["SolanaAddress"] = "SolanaAddress";
|
|
28
|
+
AddressType["ENSName"] = "ENSName";
|
|
29
|
+
AddressType["SNSName"] = "SNSName";
|
|
30
|
+
AddressType["Unknown"] = "Unknown";
|
|
31
|
+
})(AddressType || (exports.AddressType = AddressType = {}));
|
|
32
|
+
// Address validation functions are now imported directly from common.ts
|
|
33
|
+
// Use isEvmAddress and isSolanaAddress from '../../types/blockchain/common'
|
|
34
|
+
/**
|
|
35
|
+
* Check if address is an ENS name (.eth or .box)
|
|
36
|
+
*/
|
|
37
|
+
function isENSName(address) {
|
|
38
|
+
const lowerAddress = address.toLowerCase();
|
|
39
|
+
// ENS names end with .eth or .box
|
|
40
|
+
if (!lowerAddress.endsWith('.eth') && !lowerAddress.endsWith('.box')) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
// Extract the name part (without .eth or .box)
|
|
44
|
+
const nameWithoutTLD = lowerAddress.endsWith('.eth')
|
|
45
|
+
? lowerAddress.slice(0, -4)
|
|
46
|
+
: lowerAddress.slice(0, -4);
|
|
47
|
+
if (nameWithoutTLD.length === 0) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
// ENS names can have multiple labels separated by dots
|
|
51
|
+
const labels = nameWithoutTLD.split('.');
|
|
52
|
+
// Each label must be valid
|
|
53
|
+
const validLabelRegex = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/;
|
|
54
|
+
for (const label of labels) {
|
|
55
|
+
if (label.length === 0 || !validLabelRegex.test(label)) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
// No consecutive hyphens allowed
|
|
59
|
+
if (label.includes('--')) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Check if address is an SNS name (Solana name service)
|
|
67
|
+
* Supports: .sol, .abc, .bonk, .poor, .gm, .dao, .defi, .web3
|
|
68
|
+
*/
|
|
69
|
+
function isSNSName(address) {
|
|
70
|
+
const lowerAddress = address.toLowerCase();
|
|
71
|
+
// List of supported Solana name extensions
|
|
72
|
+
const snsExtensions = [
|
|
73
|
+
'.sol',
|
|
74
|
+
'.abc',
|
|
75
|
+
'.bonk',
|
|
76
|
+
'.poor',
|
|
77
|
+
'.gm',
|
|
78
|
+
'.dao',
|
|
79
|
+
'.defi',
|
|
80
|
+
'.web3',
|
|
81
|
+
];
|
|
82
|
+
// Check if address ends with any supported extension
|
|
83
|
+
const matchingExtension = snsExtensions.find((ext) => lowerAddress.endsWith(ext));
|
|
84
|
+
if (!matchingExtension) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
// Extract the name part (without the extension)
|
|
88
|
+
const nameWithoutTLD = lowerAddress.slice(0, -matchingExtension.length);
|
|
89
|
+
if (nameWithoutTLD.length === 0) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
// SNS names can have multiple labels separated by dots
|
|
93
|
+
const labels = nameWithoutTLD.split('.');
|
|
94
|
+
// Each label must be valid
|
|
95
|
+
const validLabelRegex = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/;
|
|
96
|
+
for (const label of labels) {
|
|
97
|
+
if (label.length === 0 || !validLabelRegex.test(label)) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
// No consecutive hyphens allowed
|
|
101
|
+
if (label.includes('--')) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Determine the address type from a string
|
|
109
|
+
* Case insensitive as addresses/names are often case insensitive
|
|
110
|
+
*/
|
|
111
|
+
function getAddressType(address) {
|
|
112
|
+
if (!address || typeof address !== 'string') {
|
|
113
|
+
return AddressType.Unknown;
|
|
114
|
+
}
|
|
115
|
+
// Convert to lowercase for case-insensitive comparison
|
|
116
|
+
const trimmedAddress = address.trim();
|
|
117
|
+
const lowerAddress = trimmedAddress.toLowerCase();
|
|
118
|
+
// Check for ENS names (.eth or .box domains)
|
|
119
|
+
if (isENSName(lowerAddress)) {
|
|
120
|
+
return AddressType.ENSName;
|
|
121
|
+
}
|
|
122
|
+
// Check for SNS names (.sol domain)
|
|
123
|
+
if (isSNSName(lowerAddress)) {
|
|
124
|
+
return AddressType.SNSName;
|
|
125
|
+
}
|
|
126
|
+
// Check for EVM address (0x followed by 40 hex characters)
|
|
127
|
+
if ((0, common_1.isEvmAddress)(trimmedAddress)) {
|
|
128
|
+
return AddressType.EVMAddress;
|
|
129
|
+
}
|
|
130
|
+
// Check for Solana address (base58 encoded, 32-44 characters)
|
|
131
|
+
if ((0, common_1.isSolanaAddress)(trimmedAddress)) {
|
|
132
|
+
return AddressType.SolanaAddress;
|
|
133
|
+
}
|
|
134
|
+
return AddressType.Unknown;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Validate a wallet address for a specific chain type
|
|
138
|
+
*/
|
|
139
|
+
function isValidWalletAddress(address, chainType) {
|
|
140
|
+
if (!address || typeof address !== 'string') {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
const addressType = getAddressType(address);
|
|
144
|
+
switch (chainType) {
|
|
145
|
+
case enums_1.ChainType.EVM:
|
|
146
|
+
return (addressType === AddressType.EVMAddress ||
|
|
147
|
+
addressType === AddressType.ENSName);
|
|
148
|
+
case enums_1.ChainType.SOLANA:
|
|
149
|
+
return (addressType === AddressType.SolanaAddress ||
|
|
150
|
+
addressType === AddressType.SNSName);
|
|
151
|
+
default:
|
|
152
|
+
// Unknown chain type, accept any known address format
|
|
153
|
+
return addressType !== AddressType.Unknown;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Check if a signature is valid for a specific chain type
|
|
158
|
+
*/
|
|
159
|
+
function isValidSignature(signature, chainType) {
|
|
160
|
+
if (!signature || typeof signature !== 'string') {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
switch (chainType) {
|
|
164
|
+
case enums_1.ChainType.EVM:
|
|
165
|
+
// EVM signature validation (0x followed by 130 hex characters)
|
|
166
|
+
return /^0x[a-fA-F0-9]{130}$/.test(signature);
|
|
167
|
+
case enums_1.ChainType.SOLANA:
|
|
168
|
+
// Solana signature validation (base58 encoded, typically 87-88 characters)
|
|
169
|
+
return /^[1-9A-HJ-NP-Za-km-z]{87,88}$/.test(signature);
|
|
170
|
+
default:
|
|
171
|
+
// Basic validation for unknown chain types
|
|
172
|
+
return signature.length > 50;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Parse an email address into its components
|
|
177
|
+
*/
|
|
178
|
+
function parseEmailAddress(email) {
|
|
179
|
+
if (!email || typeof email !== 'string') {
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
const parts = email.split('@');
|
|
183
|
+
if (parts.length !== 2) {
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
const [address, domain] = parts;
|
|
187
|
+
if (!address || !domain) {
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
190
|
+
const type = getAddressType(address);
|
|
191
|
+
return {
|
|
192
|
+
address,
|
|
193
|
+
domain,
|
|
194
|
+
type,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Format a wallet address for display
|
|
199
|
+
* Shows first 6 and last 4 characters with ellipsis
|
|
200
|
+
*/
|
|
201
|
+
function formatWalletAddress(address) {
|
|
202
|
+
if (!address || address.length < 10) {
|
|
203
|
+
return address;
|
|
204
|
+
}
|
|
205
|
+
// For ENS/SNS names, show them in full if they're short enough
|
|
206
|
+
const addressType = getAddressType(address);
|
|
207
|
+
if ((addressType === AddressType.ENSName ||
|
|
208
|
+
addressType === AddressType.SNSName) &&
|
|
209
|
+
address.length <= 20) {
|
|
210
|
+
return address;
|
|
211
|
+
}
|
|
212
|
+
// Show first 6 and last 4 characters with ellipsis
|
|
213
|
+
return `${address.slice(0, 6)}...${address.slice(-4)}`;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Get display name for a chain type
|
|
217
|
+
*/
|
|
218
|
+
function getChainDisplayName(chainType) {
|
|
219
|
+
if (!chainType) {
|
|
220
|
+
return 'Unknown Chain';
|
|
221
|
+
}
|
|
222
|
+
switch (chainType) {
|
|
223
|
+
case enums_1.ChainType.EVM:
|
|
224
|
+
return 'EVM Chain';
|
|
225
|
+
case enums_1.ChainType.SOLANA:
|
|
226
|
+
return 'Solana';
|
|
227
|
+
default:
|
|
228
|
+
return 'Blockchain';
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=address.js.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Blockchain address utilities for multi-chain support
|
|
3
|
+
*
|
|
4
|
+
* Provides validation and detection for various blockchain address formats
|
|
5
|
+
* including EVM addresses, Solana addresses, ENS names, and SNS names.
|
|
6
|
+
*/
|
|
7
|
+
import { ChainType } from '../../types/business/enums';
|
|
8
|
+
import { Optional } from '../../types/common';
|
|
9
|
+
/**
|
|
10
|
+
* Address type enumeration
|
|
11
|
+
*/
|
|
12
|
+
export declare enum AddressType {
|
|
13
|
+
EVMAddress = "EVMAddress",
|
|
14
|
+
SolanaAddress = "SolanaAddress",
|
|
15
|
+
ENSName = "ENSName",
|
|
16
|
+
SNSName = "SNSName",
|
|
17
|
+
Unknown = "Unknown"
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Parsed email address structure
|
|
21
|
+
*/
|
|
22
|
+
export type ParsedEmailAddress = {
|
|
23
|
+
/** The address part (before @) */
|
|
24
|
+
address: string;
|
|
25
|
+
/** The domain part (after @) */
|
|
26
|
+
domain: string;
|
|
27
|
+
/** The detected type of the address */
|
|
28
|
+
type: AddressType;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Check if address is an ENS name (.eth or .box)
|
|
32
|
+
*/
|
|
33
|
+
export declare function isENSName(address: string): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Check if address is an SNS name (Solana name service)
|
|
36
|
+
* Supports: .sol, .abc, .bonk, .poor, .gm, .dao, .defi, .web3
|
|
37
|
+
*/
|
|
38
|
+
export declare function isSNSName(address: string): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Determine the address type from a string
|
|
41
|
+
* Case insensitive as addresses/names are often case insensitive
|
|
42
|
+
*/
|
|
43
|
+
export declare function getAddressType(address: string): AddressType;
|
|
44
|
+
/**
|
|
45
|
+
* Validate a wallet address for a specific chain type
|
|
46
|
+
*/
|
|
47
|
+
export declare function isValidWalletAddress(address: string, chainType: ChainType): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Check if a signature is valid for a specific chain type
|
|
50
|
+
*/
|
|
51
|
+
export declare function isValidSignature(signature: string, chainType: ChainType): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Parse an email address into its components
|
|
54
|
+
*/
|
|
55
|
+
export declare function parseEmailAddress(email: string): Optional<ParsedEmailAddress>;
|
|
56
|
+
/**
|
|
57
|
+
* Format a wallet address for display
|
|
58
|
+
* Shows first 6 and last 4 characters with ellipsis
|
|
59
|
+
*/
|
|
60
|
+
export declare function formatWalletAddress(address: string): string;
|
|
61
|
+
/**
|
|
62
|
+
* Get display name for a chain type
|
|
63
|
+
*/
|
|
64
|
+
export declare function getChainDisplayName(chainType?: Optional<ChainType>): string;
|
|
65
|
+
//# sourceMappingURL=address.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../../src/utils/blockchain/address.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAI9C;;GAEG;AACH,oBAAY,WAAW;IACrB,UAAU,eAAe;IACzB,aAAa,kBAAkB;IAC/B,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,OAAO,YAAY;CACpB;AAED;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,gCAAgC;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,uCAAuC;IACvC,IAAI,EAAE,WAAW,CAAC;CACnB,CAAC;AAKF;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAiClD;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CA8ClD;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,CA8B3D;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,SAAS,GACnB,OAAO,CAwBT;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,SAAS,GACnB,OAAO,CAkBT;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,CAAC,kBAAkB,CAAC,CAsB7E;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAiB3D;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,GAAG,MAAM,CAa3E"}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Blockchain address utilities for multi-chain support
|
|
4
|
+
*
|
|
5
|
+
* Provides validation and detection for various blockchain address formats
|
|
6
|
+
* including EVM addresses, Solana addresses, ENS names, and SNS names.
|
|
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");
|
|
19
|
+
// Import base validation functions from common types
|
|
20
|
+
const common_1 = require("../../types/blockchain/common");
|
|
21
|
+
/**
|
|
22
|
+
* Address type enumeration
|
|
23
|
+
*/
|
|
24
|
+
var AddressType;
|
|
25
|
+
(function (AddressType) {
|
|
26
|
+
AddressType["EVMAddress"] = "EVMAddress";
|
|
27
|
+
AddressType["SolanaAddress"] = "SolanaAddress";
|
|
28
|
+
AddressType["ENSName"] = "ENSName";
|
|
29
|
+
AddressType["SNSName"] = "SNSName";
|
|
30
|
+
AddressType["Unknown"] = "Unknown";
|
|
31
|
+
})(AddressType || (exports.AddressType = AddressType = {}));
|
|
32
|
+
// Address validation functions are now imported directly from common.ts
|
|
33
|
+
// Use isEvmAddress and isSolanaAddress from '../../types/blockchain/common'
|
|
34
|
+
/**
|
|
35
|
+
* Check if address is an ENS name (.eth or .box)
|
|
36
|
+
*/
|
|
37
|
+
function isENSName(address) {
|
|
38
|
+
const lowerAddress = address.toLowerCase();
|
|
39
|
+
// ENS names end with .eth or .box
|
|
40
|
+
if (!lowerAddress.endsWith('.eth') && !lowerAddress.endsWith('.box')) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
// Extract the name part (without .eth or .box)
|
|
44
|
+
const nameWithoutTLD = lowerAddress.endsWith('.eth')
|
|
45
|
+
? lowerAddress.slice(0, -4)
|
|
46
|
+
: lowerAddress.slice(0, -4);
|
|
47
|
+
if (nameWithoutTLD.length === 0) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
// ENS names can have multiple labels separated by dots
|
|
51
|
+
const labels = nameWithoutTLD.split('.');
|
|
52
|
+
// Each label must be valid
|
|
53
|
+
const validLabelRegex = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/;
|
|
54
|
+
for (const label of labels) {
|
|
55
|
+
if (label.length === 0 || !validLabelRegex.test(label)) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
// No consecutive hyphens allowed
|
|
59
|
+
if (label.includes('--')) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Check if address is an SNS name (Solana name service)
|
|
67
|
+
* Supports: .sol, .abc, .bonk, .poor, .gm, .dao, .defi, .web3
|
|
68
|
+
*/
|
|
69
|
+
function isSNSName(address) {
|
|
70
|
+
const lowerAddress = address.toLowerCase();
|
|
71
|
+
// List of supported Solana name extensions
|
|
72
|
+
const snsExtensions = [
|
|
73
|
+
'.sol',
|
|
74
|
+
'.abc',
|
|
75
|
+
'.bonk',
|
|
76
|
+
'.poor',
|
|
77
|
+
'.gm',
|
|
78
|
+
'.dao',
|
|
79
|
+
'.defi',
|
|
80
|
+
'.web3',
|
|
81
|
+
];
|
|
82
|
+
// Check if address ends with any supported extension
|
|
83
|
+
const matchingExtension = snsExtensions.find((ext) => lowerAddress.endsWith(ext));
|
|
84
|
+
if (!matchingExtension) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
// Extract the name part (without the extension)
|
|
88
|
+
const nameWithoutTLD = lowerAddress.slice(0, -matchingExtension.length);
|
|
89
|
+
if (nameWithoutTLD.length === 0) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
// SNS names can have multiple labels separated by dots
|
|
93
|
+
const labels = nameWithoutTLD.split('.');
|
|
94
|
+
// Each label must be valid
|
|
95
|
+
const validLabelRegex = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/;
|
|
96
|
+
for (const label of labels) {
|
|
97
|
+
if (label.length === 0 || !validLabelRegex.test(label)) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
// No consecutive hyphens allowed
|
|
101
|
+
if (label.includes('--')) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Determine the address type from a string
|
|
109
|
+
* Case insensitive as addresses/names are often case insensitive
|
|
110
|
+
*/
|
|
111
|
+
function getAddressType(address) {
|
|
112
|
+
if (!address || typeof address !== 'string') {
|
|
113
|
+
return AddressType.Unknown;
|
|
114
|
+
}
|
|
115
|
+
// Convert to lowercase for case-insensitive comparison
|
|
116
|
+
const trimmedAddress = address.trim();
|
|
117
|
+
const lowerAddress = trimmedAddress.toLowerCase();
|
|
118
|
+
// Check for ENS names (.eth or .box domains)
|
|
119
|
+
if (isENSName(lowerAddress)) {
|
|
120
|
+
return AddressType.ENSName;
|
|
121
|
+
}
|
|
122
|
+
// Check for SNS names (.sol domain)
|
|
123
|
+
if (isSNSName(lowerAddress)) {
|
|
124
|
+
return AddressType.SNSName;
|
|
125
|
+
}
|
|
126
|
+
// Check for EVM address (0x followed by 40 hex characters)
|
|
127
|
+
if ((0, common_1.isEvmAddress)(trimmedAddress)) {
|
|
128
|
+
return AddressType.EVMAddress;
|
|
129
|
+
}
|
|
130
|
+
// Check for Solana address (base58 encoded, 32-44 characters)
|
|
131
|
+
if ((0, common_1.isSolanaAddress)(trimmedAddress)) {
|
|
132
|
+
return AddressType.SolanaAddress;
|
|
133
|
+
}
|
|
134
|
+
return AddressType.Unknown;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Validate a wallet address for a specific chain type
|
|
138
|
+
*/
|
|
139
|
+
function isValidWalletAddress(address, chainType) {
|
|
140
|
+
if (!address || typeof address !== 'string') {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
const addressType = getAddressType(address);
|
|
144
|
+
switch (chainType) {
|
|
145
|
+
case enums_1.ChainType.EVM:
|
|
146
|
+
return (addressType === AddressType.EVMAddress ||
|
|
147
|
+
addressType === AddressType.ENSName);
|
|
148
|
+
case enums_1.ChainType.SOLANA:
|
|
149
|
+
return (addressType === AddressType.SolanaAddress ||
|
|
150
|
+
addressType === AddressType.SNSName);
|
|
151
|
+
default:
|
|
152
|
+
// Unknown chain type, accept any known address format
|
|
153
|
+
return addressType !== AddressType.Unknown;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Check if a signature is valid for a specific chain type
|
|
158
|
+
*/
|
|
159
|
+
function isValidSignature(signature, chainType) {
|
|
160
|
+
if (!signature || typeof signature !== 'string') {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
switch (chainType) {
|
|
164
|
+
case enums_1.ChainType.EVM:
|
|
165
|
+
// EVM signature validation (0x followed by 130 hex characters)
|
|
166
|
+
return /^0x[a-fA-F0-9]{130}$/.test(signature);
|
|
167
|
+
case enums_1.ChainType.SOLANA:
|
|
168
|
+
// Solana signature validation (base58 encoded, typically 87-88 characters)
|
|
169
|
+
return /^[1-9A-HJ-NP-Za-km-z]{87,88}$/.test(signature);
|
|
170
|
+
default:
|
|
171
|
+
// Basic validation for unknown chain types
|
|
172
|
+
return signature.length > 50;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Parse an email address into its components
|
|
177
|
+
*/
|
|
178
|
+
function parseEmailAddress(email) {
|
|
179
|
+
if (!email || typeof email !== 'string') {
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
const parts = email.split('@');
|
|
183
|
+
if (parts.length !== 2) {
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
const [address, domain] = parts;
|
|
187
|
+
if (!address || !domain) {
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
190
|
+
const type = getAddressType(address);
|
|
191
|
+
return {
|
|
192
|
+
address,
|
|
193
|
+
domain,
|
|
194
|
+
type,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Format a wallet address for display
|
|
199
|
+
* Shows first 6 and last 4 characters with ellipsis
|
|
200
|
+
*/
|
|
201
|
+
function formatWalletAddress(address) {
|
|
202
|
+
if (!address || address.length < 10) {
|
|
203
|
+
return address;
|
|
204
|
+
}
|
|
205
|
+
// For ENS/SNS names, show them in full if they're short enough
|
|
206
|
+
const addressType = getAddressType(address);
|
|
207
|
+
if ((addressType === AddressType.ENSName ||
|
|
208
|
+
addressType === AddressType.SNSName) &&
|
|
209
|
+
address.length <= 20) {
|
|
210
|
+
return address;
|
|
211
|
+
}
|
|
212
|
+
// Show first 6 and last 4 characters with ellipsis
|
|
213
|
+
return `${address.slice(0, 6)}...${address.slice(-4)}`;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Get display name for a chain type
|
|
217
|
+
*/
|
|
218
|
+
function getChainDisplayName(chainType) {
|
|
219
|
+
if (!chainType) {
|
|
220
|
+
return 'Unknown Chain';
|
|
221
|
+
}
|
|
222
|
+
switch (chainType) {
|
|
223
|
+
case enums_1.ChainType.EVM:
|
|
224
|
+
return 'EVM Chain';
|
|
225
|
+
case enums_1.ChainType.SOLANA:
|
|
226
|
+
return 'Solana';
|
|
227
|
+
default:
|
|
228
|
+
return 'Blockchain';
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=address.js.map
|