@aastar/core 0.16.7
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/LICENSE +21 -0
- package/dist/abis/BLSAggregator.json +686 -0
- package/dist/abis/BLSValidator.json +42 -0
- package/dist/abis/DVTValidator.json +368 -0
- package/dist/abis/Eip7702Support.json +24 -0
- package/dist/abis/EntryPoint.json +1382 -0
- package/dist/abis/GToken.json +513 -0
- package/dist/abis/GTokenStaking.json +949 -0
- package/dist/abis/LegacyAccount.json +625 -0
- package/dist/abis/MySBT.json +1518 -0
- package/dist/abis/Paymaster.json +1143 -0
- package/dist/abis/PaymasterFactory.json +640 -0
- package/dist/abis/Registry.json +1942 -0
- package/dist/abis/ReputationSystem.json +699 -0
- package/dist/abis/SenderCreator.json +99 -0
- package/dist/abis/Simple7702Account.json +395 -0
- package/dist/abis/SimpleAccount.json +560 -0
- package/dist/abis/SimpleAccountFactory.json +111 -0
- package/dist/abis/SimpleAccountFactoryV08.json +87 -0
- package/dist/abis/SimpleAccountV08.json +557 -0
- package/dist/abis/SuperPaymaster.json +1781 -0
- package/dist/abis/UserOperationLib.json +57 -0
- package/dist/abis/abi.config.json +24 -0
- package/dist/abis/index.d.ts +1126 -0
- package/dist/abis/index.js +91 -0
- package/dist/abis/xPNTsFactory.json +718 -0
- package/dist/abis/xPNTsToken.json +1280 -0
- package/dist/actions/StateValidator.d.ts +68 -0
- package/dist/actions/StateValidator.js +187 -0
- package/dist/actions/StateValidator.test.d.ts +1 -0
- package/dist/actions/StateValidator.test.js +144 -0
- package/dist/actions/account.d.ts +55 -0
- package/dist/actions/account.js +133 -0
- package/dist/actions/account.test.d.ts +1 -0
- package/dist/actions/account.test.js +118 -0
- package/dist/actions/aggregator.d.ts +17 -0
- package/dist/actions/aggregator.js +31 -0
- package/dist/actions/aggregator.test.d.ts +1 -0
- package/dist/actions/aggregator.test.js +67 -0
- package/dist/actions/dvt.d.ts +30 -0
- package/dist/actions/dvt.js +41 -0
- package/dist/actions/dvt.test.d.ts +1 -0
- package/dist/actions/dvt.test.js +98 -0
- package/dist/actions/entryPoint.d.ts +90 -0
- package/dist/actions/entryPoint.js +211 -0
- package/dist/actions/entryPoint.test.d.ts +1 -0
- package/dist/actions/entryPoint.test.js +139 -0
- package/dist/actions/factory.d.ts +215 -0
- package/dist/actions/factory.js +442 -0
- package/dist/actions/factory.test.d.ts +1 -0
- package/dist/actions/factory.test.js +197 -0
- package/dist/actions/faucet.d.ts +48 -0
- package/dist/actions/faucet.js +337 -0
- package/dist/actions/faucet.test.d.ts +1 -0
- package/dist/actions/faucet.test.js +120 -0
- package/dist/actions/gtokenExtended.d.ts +39 -0
- package/dist/actions/gtokenExtended.js +115 -0
- package/dist/actions/gtokenExtended.test.d.ts +1 -0
- package/dist/actions/gtokenExtended.test.js +118 -0
- package/dist/actions/index.d.ts +15 -0
- package/dist/actions/index.js +17 -0
- package/dist/actions/paymasterV4.d.ts +170 -0
- package/dist/actions/paymasterV4.js +334 -0
- package/dist/actions/paymasterV4.test.d.ts +1 -0
- package/dist/actions/paymasterV4.test.js +159 -0
- package/dist/actions/registry.d.ts +246 -0
- package/dist/actions/registry.js +667 -0
- package/dist/actions/registry.test.d.ts +1 -0
- package/dist/actions/registry.test.js +360 -0
- package/dist/actions/reputation.d.ts +129 -0
- package/dist/actions/reputation.js +281 -0
- package/dist/actions/reputation.test.d.ts +1 -0
- package/dist/actions/reputation.test.js +169 -0
- package/dist/actions/sbt.d.ts +191 -0
- package/dist/actions/sbt.js +533 -0
- package/dist/actions/sbt.test.d.ts +1 -0
- package/dist/actions/sbt.test.js +256 -0
- package/dist/actions/staking.d.ts +132 -0
- package/dist/actions/staking.js +330 -0
- package/dist/actions/staking.test.d.ts +1 -0
- package/dist/actions/staking.test.js +223 -0
- package/dist/actions/superPaymaster.d.ts +237 -0
- package/dist/actions/superPaymaster.js +644 -0
- package/dist/actions/superPaymaster.test.d.ts +1 -0
- package/dist/actions/superPaymaster.test.js +287 -0
- package/dist/actions/tokens.d.ts +229 -0
- package/dist/actions/tokens.js +415 -0
- package/dist/actions/tokens.test.d.ts +1 -0
- package/dist/actions/tokens.test.js +53 -0
- package/dist/actions/validators.d.ts +194 -0
- package/dist/actions/validators.js +433 -0
- package/dist/actions/validators.test.d.ts +1 -0
- package/dist/actions/validators.test.js +215 -0
- package/dist/branding.d.ts +30 -0
- package/dist/branding.js +30 -0
- package/dist/clients/BaseClient.d.ts +25 -0
- package/dist/clients/BaseClient.js +66 -0
- package/dist/clients/types.d.ts +60 -0
- package/dist/clients/types.js +1 -0
- package/dist/clients.d.ts +5 -0
- package/dist/clients.js +11 -0
- package/dist/communities.d.ts +52 -0
- package/dist/communities.js +73 -0
- package/dist/config/ContractConfigManager.d.ts +20 -0
- package/dist/config/ContractConfigManager.js +48 -0
- package/dist/constants.d.ts +88 -0
- package/dist/constants.js +125 -0
- package/dist/contract-addresses.d.ts +110 -0
- package/dist/contract-addresses.js +99 -0
- package/dist/contracts.d.ts +424 -0
- package/dist/contracts.js +343 -0
- package/dist/contracts.test.d.ts +1 -0
- package/dist/contracts.test.js +40 -0
- package/dist/crypto/blsSigner.d.ts +64 -0
- package/dist/crypto/blsSigner.js +98 -0
- package/dist/crypto/index.d.ts +1 -0
- package/dist/crypto/index.js +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +21 -0
- package/dist/networks.d.ts +127 -0
- package/dist/networks.js +118 -0
- package/dist/requirementChecker.d.ts +38 -0
- package/dist/requirementChecker.js +139 -0
- package/dist/requirementChecker.test.d.ts +1 -0
- package/dist/requirementChecker.test.js +60 -0
- package/dist/roles.d.ts +204 -0
- package/dist/roles.js +211 -0
- package/dist/roles.test.d.ts +1 -0
- package/dist/roles.test.js +23 -0
- package/dist/utils/validation.d.ts +24 -0
- package/dist/utils/validation.js +56 -0
- package/dist/utils/validation.test.d.ts +1 -0
- package/dist/utils/validation.test.js +40 -0
- package/dist/utils.d.ts +12 -0
- package/dist/utils.js +14 -0
- package/package.json +33 -0
package/dist/roles.js
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Role constants and utilities for AAstar SDK
|
|
3
|
+
* @remarks
|
|
4
|
+
* All role hashes and configurations match exactly with Registry.sol v3.0.0
|
|
5
|
+
*
|
|
6
|
+
* **Source**: /contracts/src/core/Registry.sol
|
|
7
|
+
*/
|
|
8
|
+
import { keccak256, toHex } from 'viem';
|
|
9
|
+
// ========== Role Hash Constants (from Registry.sol lines 32-38) ==========
|
|
10
|
+
/**
|
|
11
|
+
* Default Admin Role (OpenZeppelin AccessControl)
|
|
12
|
+
* @remarks
|
|
13
|
+
* - **Description**: Highest privilege, can grant/revoke all roles
|
|
14
|
+
* - **Permission**: Protocol governance only
|
|
15
|
+
* - **Source**: OpenZeppelin AccessControl DEFAULT_ADMIN_ROLE
|
|
16
|
+
*/
|
|
17
|
+
export const DEFAULT_ADMIN_ROLE = '0x0000000000000000000000000000000000000000000000000000000000000000';
|
|
18
|
+
/**
|
|
19
|
+
* Community Role
|
|
20
|
+
* @remarks
|
|
21
|
+
* - **Description**: Community administrator, can issue xPNTs, configure SBT rules
|
|
22
|
+
* - **Permission**: Community-level governance
|
|
23
|
+
* - **Requirement**: minStake: 30 GT, entryBurn: 3 GT (line 99)
|
|
24
|
+
* - **Exit Fee**: 5% (500 basis points), min 1 GT
|
|
25
|
+
* - **Lock Duration**: 30 days
|
|
26
|
+
* - **Source**: Registry.sol line 32: ROLE_COMMUNITY = keccak256("COMMUNITY")
|
|
27
|
+
*/
|
|
28
|
+
export const ROLE_COMMUNITY = keccak256(toHex('COMMUNITY'));
|
|
29
|
+
/**
|
|
30
|
+
* End User Role
|
|
31
|
+
* @remarks
|
|
32
|
+
* - **Description**: Community member, can participate and use gasless transactions
|
|
33
|
+
* - **Permission**: Basic user level
|
|
34
|
+
* - **Requirement**: minStake: 0.3 GT, entryBurn: 0.05 GT (line 100)
|
|
35
|
+
* - **Additional Requirement**: Must hold MySBT from community
|
|
36
|
+
* - **Exit Fee**: 10% (1000 basis points), min 0.05 GT
|
|
37
|
+
* - **Lock Duration**: 7 days
|
|
38
|
+
* - **Source**: Registry.sol line 33: ROLE_ENDUSER = keccak256("ENDUSER")
|
|
39
|
+
*/
|
|
40
|
+
export const ROLE_ENDUSER = keccak256(toHex('ENDUSER'));
|
|
41
|
+
/**
|
|
42
|
+
* Paymaster AOA Role (Account Ownership Authentication)
|
|
43
|
+
* @remarks
|
|
44
|
+
* - **Description**: Basic Paymaster node operator with account-based auth
|
|
45
|
+
* - **Permission**: Infrastructure operator
|
|
46
|
+
* - **Requirement**: minStake: 30 GT, entryBurn: 3 GT (line 92)
|
|
47
|
+
* - **Exit Fee**: 10% (1000 basis points), min 1 GT
|
|
48
|
+
* - **Lock Duration**: 30 days
|
|
49
|
+
* - **Source**: Registry.sol line 34: ROLE_PAYMASTER_AOA = keccak256("PAYMASTER_AOA")
|
|
50
|
+
*/
|
|
51
|
+
export const ROLE_PAYMASTER_AOA = keccak256(toHex('PAYMASTER_AOA'));
|
|
52
|
+
/**
|
|
53
|
+
* Paymaster Super Role
|
|
54
|
+
* @remarks
|
|
55
|
+
* - **Description**: Advanced Paymaster operator, can use SuperPaymaster with aPNTs collateral
|
|
56
|
+
* - **Permission**: Infrastructure operator (higher tier)
|
|
57
|
+
* - **Requirement**: minStake: 50 GT, entryBurn: 5 GT (line 93)
|
|
58
|
+
* - **Additional Requirement**: aPNTs collateral in SuperPaymaster contract
|
|
59
|
+
* - **Exit Fee**: 10% (1000 basis points), min 2 GT
|
|
60
|
+
* - **Lock Duration**: 30 days
|
|
61
|
+
* - **Source**: Registry.sol line 35: ROLE_PAYMASTER_SUPER = keccak256("PAYMASTER_SUPER")
|
|
62
|
+
*/
|
|
63
|
+
export const ROLE_PAYMASTER_SUPER = keccak256(toHex('PAYMASTER_SUPER'));
|
|
64
|
+
/**
|
|
65
|
+
* DVT Role (Distributed Validator Technology)
|
|
66
|
+
* @remarks
|
|
67
|
+
* - **Description**: DVT node operator for consensus validation
|
|
68
|
+
* - **Permission**: Infrastructure operator
|
|
69
|
+
* - **Requirement**: minStake: 30 GT, entryBurn: 3 GT (line 94)
|
|
70
|
+
* - **Exit Fee**: 10% (1000 basis points), min 1 GT
|
|
71
|
+
* - **Lock Duration**: 30 days
|
|
72
|
+
* - **Source**: Registry.sol line 36: ROLE_DVT = keccak256("DVT")
|
|
73
|
+
*/
|
|
74
|
+
export const ROLE_DVT = keccak256(toHex('DVT'));
|
|
75
|
+
/**
|
|
76
|
+
* ANODE Role (Anonymous Node)
|
|
77
|
+
* @remarks
|
|
78
|
+
* - **Description**: Anonymous infrastructure node operator
|
|
79
|
+
* - **Permission**: Infrastructure operator
|
|
80
|
+
* - **Requirement**: minStake: 20 GT, entryBurn: 2 GT (line 95)
|
|
81
|
+
* - **Exit Fee**: 10% (1000 basis points), min 1 GT
|
|
82
|
+
* - **Lock Duration**: 30 days
|
|
83
|
+
* - **Source**: Registry.sol line 37: ROLE_ANODE = keccak256("ANODE")
|
|
84
|
+
*/
|
|
85
|
+
export const ROLE_ANODE = keccak256(toHex('ANODE'));
|
|
86
|
+
/**
|
|
87
|
+
* KMS Role (Key Management Service)
|
|
88
|
+
* @remarks
|
|
89
|
+
* - **Description**: KMS operator for secure key storage and management
|
|
90
|
+
* - **Permission**: Infrastructure operator (highest stake)
|
|
91
|
+
* - **Requirement**: minStake: 100 GT, entryBurn: 10 GT (line 98)
|
|
92
|
+
* - **Exit Fee**: 10% (1000 basis points), min 5 GT
|
|
93
|
+
* - **Lock Duration**: 30 days
|
|
94
|
+
* - **Source**: Registry.sol line 38: ROLE_KMS = keccak256("KMS")
|
|
95
|
+
*/
|
|
96
|
+
export const ROLE_KMS = keccak256(toHex('KMS'));
|
|
97
|
+
// ========== Role Name Mapping ==========
|
|
98
|
+
export const ROLE_NAMES = {
|
|
99
|
+
[DEFAULT_ADMIN_ROLE]: 'Default Admin',
|
|
100
|
+
[ROLE_COMMUNITY]: 'Community Admin',
|
|
101
|
+
[ROLE_ENDUSER]: 'End User',
|
|
102
|
+
[ROLE_PAYMASTER_AOA]: 'Paymaster (AOA)',
|
|
103
|
+
[ROLE_PAYMASTER_SUPER]: 'Paymaster (Super)',
|
|
104
|
+
[ROLE_DVT]: 'DVT Operator',
|
|
105
|
+
[ROLE_ANODE]: 'Anonymous Node',
|
|
106
|
+
[ROLE_KMS]: 'KMS Operator'
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Get human-readable role name
|
|
110
|
+
*/
|
|
111
|
+
export function getRoleName(roleHash) {
|
|
112
|
+
return ROLE_NAMES[roleHash] || 'Unknown Role';
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Role permission levels (for UI sorting/filtering)
|
|
116
|
+
*/
|
|
117
|
+
export var RolePermissionLevel;
|
|
118
|
+
(function (RolePermissionLevel) {
|
|
119
|
+
RolePermissionLevel[RolePermissionLevel["PROTOCOL"] = 100] = "PROTOCOL";
|
|
120
|
+
RolePermissionLevel[RolePermissionLevel["KMS"] = 80] = "KMS";
|
|
121
|
+
RolePermissionLevel[RolePermissionLevel["OPERATOR"] = 50] = "OPERATOR";
|
|
122
|
+
RolePermissionLevel[RolePermissionLevel["COMMUNITY"] = 30] = "COMMUNITY";
|
|
123
|
+
RolePermissionLevel[RolePermissionLevel["USER"] = 10] = "USER"; // End Users
|
|
124
|
+
})(RolePermissionLevel || (RolePermissionLevel = {}));
|
|
125
|
+
export const ROLE_PERMISSION_LEVELS = {
|
|
126
|
+
[DEFAULT_ADMIN_ROLE]: RolePermissionLevel.PROTOCOL,
|
|
127
|
+
[ROLE_KMS]: RolePermissionLevel.KMS,
|
|
128
|
+
[ROLE_PAYMASTER_SUPER]: RolePermissionLevel.OPERATOR,
|
|
129
|
+
[ROLE_PAYMASTER_AOA]: RolePermissionLevel.OPERATOR,
|
|
130
|
+
[ROLE_DVT]: RolePermissionLevel.OPERATOR,
|
|
131
|
+
[ROLE_ANODE]: RolePermissionLevel.OPERATOR,
|
|
132
|
+
[ROLE_COMMUNITY]: RolePermissionLevel.COMMUNITY,
|
|
133
|
+
[ROLE_ENDUSER]: RolePermissionLevel.USER
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Exact stake requirements from Registry.sol constructor (lines 92-100)
|
|
137
|
+
* @remarks
|
|
138
|
+
* **Warning**: These are initial values, always query contract for current configuration
|
|
139
|
+
*/
|
|
140
|
+
export const INITIAL_ROLE_STAKES = {
|
|
141
|
+
[ROLE_PAYMASTER_AOA]: {
|
|
142
|
+
minStake: '30 GT',
|
|
143
|
+
entryBurn: '3 GT',
|
|
144
|
+
exitFeePercent: '10%',
|
|
145
|
+
minExitFee: '1 GT',
|
|
146
|
+
lockDuration: '30 days',
|
|
147
|
+
line: 92
|
|
148
|
+
},
|
|
149
|
+
[ROLE_PAYMASTER_SUPER]: {
|
|
150
|
+
minStake: '50 GT',
|
|
151
|
+
entryBurn: '5 GT',
|
|
152
|
+
exitFeePercent: '10%',
|
|
153
|
+
minExitFee: '2 GT',
|
|
154
|
+
lockDuration: '30 days',
|
|
155
|
+
additionalRequirement: 'aPNTs collateral in SuperPaymaster',
|
|
156
|
+
line: 93
|
|
157
|
+
},
|
|
158
|
+
[ROLE_DVT]: {
|
|
159
|
+
minStake: '30 GT',
|
|
160
|
+
entryBurn: '3 GT',
|
|
161
|
+
exitFeePercent: '10%',
|
|
162
|
+
minExitFee: '1 GT',
|
|
163
|
+
lockDuration: '30 days',
|
|
164
|
+
line: 94
|
|
165
|
+
},
|
|
166
|
+
[ROLE_ANODE]: {
|
|
167
|
+
minStake: '20 GT',
|
|
168
|
+
entryBurn: '2 GT',
|
|
169
|
+
exitFeePercent: '10%',
|
|
170
|
+
minExitFee: '1 GT',
|
|
171
|
+
lockDuration: '30 days',
|
|
172
|
+
line: 95
|
|
173
|
+
},
|
|
174
|
+
[ROLE_KMS]: {
|
|
175
|
+
minStake: '100 GT',
|
|
176
|
+
entryBurn: '10 GT',
|
|
177
|
+
exitFeePercent: '10%',
|
|
178
|
+
minExitFee: '5 GT',
|
|
179
|
+
lockDuration: '30 days',
|
|
180
|
+
line: 98
|
|
181
|
+
},
|
|
182
|
+
[ROLE_COMMUNITY]: {
|
|
183
|
+
minStake: '30 GT',
|
|
184
|
+
entryBurn: '3 GT',
|
|
185
|
+
exitFeePercent: '5%',
|
|
186
|
+
minExitFee: '1 GT',
|
|
187
|
+
lockDuration: '30 days',
|
|
188
|
+
line: 99
|
|
189
|
+
},
|
|
190
|
+
[ROLE_ENDUSER]: {
|
|
191
|
+
minStake: '0.3 GT',
|
|
192
|
+
entryBurn: '0.05 GT',
|
|
193
|
+
exitFeePercent: '10%',
|
|
194
|
+
minExitFee: '0.05 GT',
|
|
195
|
+
lockDuration: '7 days',
|
|
196
|
+
additionalRequirement: 'Must hold MySBT from community',
|
|
197
|
+
line: 100
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* All defined roles array (for iteration)
|
|
202
|
+
*/
|
|
203
|
+
export const ALL_ROLES = [
|
|
204
|
+
ROLE_COMMUNITY,
|
|
205
|
+
ROLE_ENDUSER,
|
|
206
|
+
ROLE_PAYMASTER_AOA,
|
|
207
|
+
ROLE_PAYMASTER_SUPER,
|
|
208
|
+
ROLE_DVT,
|
|
209
|
+
ROLE_ANODE,
|
|
210
|
+
ROLE_KMS
|
|
211
|
+
];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { ROLE_COMMUNITY, ROLE_ENDUSER, getRoleName, ROLE_PERMISSION_LEVELS, RolePermissionLevel, ALL_ROLES } from './roles.js';
|
|
3
|
+
describe('Roles', () => {
|
|
4
|
+
it('should have consistent role hashes', () => {
|
|
5
|
+
expect(ROLE_COMMUNITY).toBeDefined();
|
|
6
|
+
expect(ROLE_ENDUSER).toBeDefined();
|
|
7
|
+
expect(ROLE_COMMUNITY.startsWith('0x')).toBe(true);
|
|
8
|
+
});
|
|
9
|
+
it('should return correct role names', () => {
|
|
10
|
+
expect(getRoleName(ROLE_COMMUNITY)).toBe('Community Admin');
|
|
11
|
+
expect(getRoleName(ROLE_ENDUSER)).toBe('End User');
|
|
12
|
+
expect(getRoleName('0x123')).toBe('Unknown Role');
|
|
13
|
+
});
|
|
14
|
+
it('should have correct permission levels', () => {
|
|
15
|
+
expect(ROLE_PERMISSION_LEVELS[ROLE_COMMUNITY]).toBe(RolePermissionLevel.COMMUNITY);
|
|
16
|
+
expect(ROLE_PERMISSION_LEVELS[ROLE_ENDUSER]).toBe(RolePermissionLevel.USER);
|
|
17
|
+
});
|
|
18
|
+
it('should include all roles in ALL_ROLES', () => {
|
|
19
|
+
expect(ALL_ROLES.length).toBeGreaterThan(0);
|
|
20
|
+
expect(ALL_ROLES).toContain(ROLE_COMMUNITY);
|
|
21
|
+
expect(ALL_ROLES).toContain(ROLE_ENDUSER);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare class AAStarValidationError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Validates an Ethereum address.
|
|
6
|
+
* Throws AAStarValidationError if invalid.
|
|
7
|
+
*/
|
|
8
|
+
export declare function validateAddress(address: string, fieldName?: string): `0x${string}`;
|
|
9
|
+
/**
|
|
10
|
+
* Validates a BigInt amount.
|
|
11
|
+
* @param amount The value to check
|
|
12
|
+
* @param fieldName Name for error messages
|
|
13
|
+
* @param min Minimum value (default 0n)
|
|
14
|
+
* @param max Maximum value (optional)
|
|
15
|
+
*/
|
|
16
|
+
export declare function validateAmount(amount: bigint, fieldName?: string, min?: bigint, max?: bigint): bigint;
|
|
17
|
+
/**
|
|
18
|
+
* Validates a UINT128 value (Common in Paymaster Data).
|
|
19
|
+
*/
|
|
20
|
+
export declare function validateUint128(value: bigint, fieldName?: string): bigint;
|
|
21
|
+
/**
|
|
22
|
+
* Validates a Hex string.
|
|
23
|
+
*/
|
|
24
|
+
export declare function validateHex(value: string, fieldName?: string): `0x${string}`;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { isAddress, getAddress } from 'viem';
|
|
2
|
+
export class AAStarValidationError extends Error {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = 'AAStarValidationError';
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Validates an Ethereum address.
|
|
10
|
+
* Throws AAStarValidationError if invalid.
|
|
11
|
+
*/
|
|
12
|
+
export function validateAddress(address, fieldName = 'Address') {
|
|
13
|
+
if (!address) {
|
|
14
|
+
throw new AAStarValidationError(`${fieldName} is required.`);
|
|
15
|
+
}
|
|
16
|
+
if (!isAddress(address)) {
|
|
17
|
+
throw new AAStarValidationError(`${fieldName} must be a valid Ethereum address. Got: ${address}`);
|
|
18
|
+
}
|
|
19
|
+
return getAddress(address); // Returns checksummed address
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Validates a BigInt amount.
|
|
23
|
+
* @param amount The value to check
|
|
24
|
+
* @param fieldName Name for error messages
|
|
25
|
+
* @param min Minimum value (default 0n)
|
|
26
|
+
* @param max Maximum value (optional)
|
|
27
|
+
*/
|
|
28
|
+
export function validateAmount(amount, fieldName = 'Amount', min = 0n, max) {
|
|
29
|
+
if (amount < min) {
|
|
30
|
+
throw new AAStarValidationError(`${fieldName} must be >= ${min}. Got: ${amount}`);
|
|
31
|
+
}
|
|
32
|
+
if (max !== undefined && amount > max) {
|
|
33
|
+
throw new AAStarValidationError(`${fieldName} must be <= ${max}. Got: ${amount}`);
|
|
34
|
+
}
|
|
35
|
+
return amount;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Validates a UINT128 value (Common in Paymaster Data).
|
|
39
|
+
*/
|
|
40
|
+
export function validateUint128(value, fieldName = 'Value') {
|
|
41
|
+
const MAX_UINT128 = (1n << 128n) - 1n;
|
|
42
|
+
return validateAmount(value, fieldName, 0n, MAX_UINT128);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Validates a Hex string.
|
|
46
|
+
*/
|
|
47
|
+
export function validateHex(value, fieldName = 'Hex') {
|
|
48
|
+
if (!value.startsWith('0x')) {
|
|
49
|
+
throw new AAStarValidationError(`${fieldName} must start with 0x. Got: ${value}`);
|
|
50
|
+
}
|
|
51
|
+
const hexRegex = /^0x[0-9a-fA-F]*$/;
|
|
52
|
+
if (!hexRegex.test(value)) {
|
|
53
|
+
throw new AAStarValidationError(`${fieldName} must be a valid hex string.`);
|
|
54
|
+
}
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { validateAddress, validateAmount, validateHex, AAStarValidationError } from './validation.js';
|
|
3
|
+
describe('Validation Utils', () => {
|
|
4
|
+
describe('validateAddress', () => {
|
|
5
|
+
it('should pass for valid Ethereum addresses', () => {
|
|
6
|
+
const validAddr = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045';
|
|
7
|
+
expect(validateAddress(validAddr)).toBe(validAddr);
|
|
8
|
+
});
|
|
9
|
+
it('should throw for invalid addresses', () => {
|
|
10
|
+
expect(() => validateAddress('0xInvalid')).toThrow(AAStarValidationError);
|
|
11
|
+
});
|
|
12
|
+
it('should checksum address', () => {
|
|
13
|
+
const lower = '0xd8da6bf26964af9d7eed9e03e53415d37aa96045';
|
|
14
|
+
const checksummed = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045';
|
|
15
|
+
expect(validateAddress(lower)).toBe(checksummed);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
describe('validateAmount', () => {
|
|
19
|
+
it('should pass for positive amounts', () => {
|
|
20
|
+
expect(validateAmount(100n)).toBe(100n);
|
|
21
|
+
});
|
|
22
|
+
it('should throw for negative amounts', () => {
|
|
23
|
+
expect(() => validateAmount(-1n)).toThrow(AAStarValidationError);
|
|
24
|
+
});
|
|
25
|
+
it('should throw if exceeds max', () => {
|
|
26
|
+
expect(() => validateAmount(100n, 'Test', 0n, 50n)).toThrow(AAStarValidationError);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
describe('validateHex', () => {
|
|
30
|
+
it('should pass for valid hex strings', () => {
|
|
31
|
+
expect(validateHex('0x1234')).toBe('0x1234');
|
|
32
|
+
});
|
|
33
|
+
it('should throw if missing 0x prefix', () => {
|
|
34
|
+
expect(() => validateHex('1234')).toThrow(AAStarValidationError);
|
|
35
|
+
});
|
|
36
|
+
it('should throw for non-hex characters', () => {
|
|
37
|
+
expect(() => validateHex('0xZZZZ')).toThrow(AAStarValidationError);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Hex, type Address } from 'viem';
|
|
2
|
+
export type PaymasterAndData = {
|
|
3
|
+
paymaster: Address;
|
|
4
|
+
verificationGasLimit: bigint;
|
|
5
|
+
postOpGasLimit: bigint;
|
|
6
|
+
operator: Address;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Format PaymasterAndData for SuperPaymaster V3
|
|
10
|
+
* Layout: [Paymaster(20)] [VerGas(16)] [PostOpGas(16)] [Operator(20)]
|
|
11
|
+
*/
|
|
12
|
+
export declare function encodePaymasterData(params: PaymasterAndData): Hex;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { concat, pad, toHex } from 'viem';
|
|
2
|
+
/**
|
|
3
|
+
* Format PaymasterAndData for SuperPaymaster V3
|
|
4
|
+
* Layout: [Paymaster(20)] [VerGas(16)] [PostOpGas(16)] [Operator(20)]
|
|
5
|
+
*/
|
|
6
|
+
export function encodePaymasterData(params) {
|
|
7
|
+
// strict length checks can be added here
|
|
8
|
+
return concat([
|
|
9
|
+
params.paymaster,
|
|
10
|
+
pad(toHex(params.verificationGasLimit), { size: 16 }),
|
|
11
|
+
pad(toHex(params.postOpGasLimit), { size: 16 }),
|
|
12
|
+
params.operator
|
|
13
|
+
]);
|
|
14
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aastar/core",
|
|
3
|
+
"version": "0.16.7",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@noble/curves": "^1.6.0",
|
|
12
|
+
"viem": "2.43.3"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@vitest/coverage-v8": "4.0.17",
|
|
16
|
+
"abitype": "1.2.3",
|
|
17
|
+
"typescript": "5.7.2",
|
|
18
|
+
"vitest": "4.0.17"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"scripts": {
|
|
25
|
+
"clean": "find src -name '*.js' -o -name '*.d.ts' -o -name '*.map' | xargs rm -f",
|
|
26
|
+
"build": "pnpm clean && tsc",
|
|
27
|
+
"test": "vitest run",
|
|
28
|
+
"test:coverage": "vitest run --coverage",
|
|
29
|
+
"lint": "ESLINT_USE_FLAT_CONFIG=false eslint src --ext .ts",
|
|
30
|
+
"lint:fix": "ESLINT_USE_FLAT_CONFIG=false eslint src --ext .ts --fix",
|
|
31
|
+
"audit:abi": "npx tsx scripts/audit-abi-coverage.ts"
|
|
32
|
+
}
|
|
33
|
+
}
|