@aastar/identity 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.
Files changed (88) hide show
  1. package/LICENSE +21 -0
  2. package/dist/core/src/abis/BLSAggregator.json +686 -0
  3. package/dist/core/src/abis/BLSValidator.json +42 -0
  4. package/dist/core/src/abis/DVTValidator.json +368 -0
  5. package/dist/core/src/abis/EntryPoint.json +1382 -0
  6. package/dist/core/src/abis/GToken.json +513 -0
  7. package/dist/core/src/abis/GTokenStaking.json +949 -0
  8. package/dist/core/src/abis/MySBT.json +1518 -0
  9. package/dist/core/src/abis/Paymaster.json +1143 -0
  10. package/dist/core/src/abis/PaymasterFactory.json +640 -0
  11. package/dist/core/src/abis/Registry.json +1942 -0
  12. package/dist/core/src/abis/ReputationSystem.json +699 -0
  13. package/dist/core/src/abis/SimpleAccount.json +560 -0
  14. package/dist/core/src/abis/SimpleAccountFactory.json +111 -0
  15. package/dist/core/src/abis/SuperPaymaster.json +1781 -0
  16. package/dist/core/src/abis/index.d.ts +1126 -0
  17. package/dist/core/src/abis/index.js +91 -0
  18. package/dist/core/src/abis/xPNTsFactory.json +718 -0
  19. package/dist/core/src/abis/xPNTsToken.json +1280 -0
  20. package/dist/core/src/actions/StateValidator.d.ts +68 -0
  21. package/dist/core/src/actions/StateValidator.js +187 -0
  22. package/dist/core/src/actions/account.d.ts +55 -0
  23. package/dist/core/src/actions/account.js +133 -0
  24. package/dist/core/src/actions/aggregator.d.ts +17 -0
  25. package/dist/core/src/actions/aggregator.js +31 -0
  26. package/dist/core/src/actions/dvt.d.ts +30 -0
  27. package/dist/core/src/actions/dvt.js +41 -0
  28. package/dist/core/src/actions/entryPoint.d.ts +90 -0
  29. package/dist/core/src/actions/entryPoint.js +211 -0
  30. package/dist/core/src/actions/factory.d.ts +215 -0
  31. package/dist/core/src/actions/factory.js +442 -0
  32. package/dist/core/src/actions/faucet.d.ts +48 -0
  33. package/dist/core/src/actions/faucet.js +337 -0
  34. package/dist/core/src/actions/gtokenExtended.d.ts +39 -0
  35. package/dist/core/src/actions/gtokenExtended.js +115 -0
  36. package/dist/core/src/actions/index.d.ts +15 -0
  37. package/dist/core/src/actions/index.js +17 -0
  38. package/dist/core/src/actions/paymasterV4.d.ts +170 -0
  39. package/dist/core/src/actions/paymasterV4.js +334 -0
  40. package/dist/core/src/actions/registry.d.ts +246 -0
  41. package/dist/core/src/actions/registry.js +667 -0
  42. package/dist/core/src/actions/reputation.d.ts +129 -0
  43. package/dist/core/src/actions/reputation.js +281 -0
  44. package/dist/core/src/actions/sbt.d.ts +191 -0
  45. package/dist/core/src/actions/sbt.js +533 -0
  46. package/dist/core/src/actions/staking.d.ts +132 -0
  47. package/dist/core/src/actions/staking.js +330 -0
  48. package/dist/core/src/actions/superPaymaster.d.ts +237 -0
  49. package/dist/core/src/actions/superPaymaster.js +644 -0
  50. package/dist/core/src/actions/tokens.d.ts +229 -0
  51. package/dist/core/src/actions/tokens.js +415 -0
  52. package/dist/core/src/branding.d.ts +30 -0
  53. package/dist/core/src/branding.js +30 -0
  54. package/dist/core/src/clients/BaseClient.d.ts +25 -0
  55. package/dist/core/src/clients/BaseClient.js +66 -0
  56. package/dist/core/src/clients/types.d.ts +60 -0
  57. package/dist/core/src/clients/types.js +1 -0
  58. package/dist/core/src/clients.d.ts +5 -0
  59. package/dist/core/src/clients.js +11 -0
  60. package/dist/core/src/communities.d.ts +52 -0
  61. package/dist/core/src/communities.js +73 -0
  62. package/dist/core/src/config/ContractConfigManager.d.ts +20 -0
  63. package/dist/core/src/config/ContractConfigManager.js +48 -0
  64. package/dist/core/src/constants.d.ts +88 -0
  65. package/dist/core/src/constants.js +125 -0
  66. package/dist/core/src/contract-addresses.d.ts +110 -0
  67. package/dist/core/src/contract-addresses.js +99 -0
  68. package/dist/core/src/contracts.d.ts +424 -0
  69. package/dist/core/src/contracts.js +343 -0
  70. package/dist/core/src/crypto/blsSigner.d.ts +64 -0
  71. package/dist/core/src/crypto/blsSigner.js +98 -0
  72. package/dist/core/src/crypto/index.d.ts +1 -0
  73. package/dist/core/src/crypto/index.js +1 -0
  74. package/dist/core/src/index.d.ts +21 -0
  75. package/dist/core/src/index.js +21 -0
  76. package/dist/core/src/networks.d.ts +127 -0
  77. package/dist/core/src/networks.js +118 -0
  78. package/dist/core/src/requirementChecker.d.ts +38 -0
  79. package/dist/core/src/requirementChecker.js +139 -0
  80. package/dist/core/src/roles.d.ts +204 -0
  81. package/dist/core/src/roles.js +211 -0
  82. package/dist/core/src/utils/validation.d.ts +24 -0
  83. package/dist/core/src/utils/validation.js +56 -0
  84. package/dist/identity/src/index.d.ts +46 -0
  85. package/dist/identity/src/index.js +94 -0
  86. package/dist/identity/src/mysbt.d.ts +13 -0
  87. package/dist/identity/src/mysbt.js +37 -0
  88. package/package.json +26 -0
@@ -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,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,46 @@
1
+ export * from './mysbt.js';
2
+ import { type Address, type PublicClient, type Hash, type WalletClient } from 'viem';
3
+ export declare class ReputationClient {
4
+ private client;
5
+ private reputationAddress;
6
+ private walletClient?;
7
+ constructor(client: PublicClient, reputationAddress: Address, walletClient?: WalletClient);
8
+ /**
9
+ * Compute reputation score for a user
10
+ */
11
+ computeScore(user: Address, communities: Address[], ruleIds: `0x${string}`[][], activities: bigint[][]): Promise<bigint>;
12
+ /**
13
+ * Get global reputation score for a user
14
+ * @param user User address
15
+ * @returns Reputation score
16
+ */
17
+ getGlobalReputation(user: Address): Promise<number>;
18
+ /**
19
+ * Get credit limit based on reputation
20
+ * @param user User address
21
+ * @returns Credit limit in wei (Mock logic closely tied to Reputation)
22
+ */
23
+ getCreditLimit(user: Address): Promise<bigint>;
24
+ /**
25
+ * Get reputation score breakdown
26
+ * @param user User address
27
+ * @returns Detailed reputation breakdown (Mock implementation awaiting contract V4)
28
+ */
29
+ getReputationBreakdown(user: Address): Promise<{
30
+ baseScore: number;
31
+ stakingBonus: number;
32
+ activityBonus: number;
33
+ penaltyDeduction: number;
34
+ total: number;
35
+ }>;
36
+ /**
37
+ * Submit reputation proof (off-chain data to on-chain)
38
+ * @param params Proof parameters
39
+ * @returns Transaction hash
40
+ */
41
+ submitReputationProof(params: {
42
+ proofType: 'github' | 'twitter' | 'on-chain-activity';
43
+ proofData: string;
44
+ signature: Hash;
45
+ }): Promise<Hash>;
46
+ }
@@ -0,0 +1,94 @@
1
+ export * from './mysbt.js';
2
+ import { ReputationSystemABI } from '@aastar/core';
3
+ import { parseAbi } from 'viem';
4
+ export class ReputationClient {
5
+ client;
6
+ reputationAddress;
7
+ walletClient;
8
+ constructor(client, reputationAddress, walletClient) {
9
+ this.client = client;
10
+ this.reputationAddress = reputationAddress;
11
+ this.walletClient = walletClient;
12
+ }
13
+ /**
14
+ * Compute reputation score for a user
15
+ */
16
+ async computeScore(user, communities, ruleIds, activities) {
17
+ return this.client.readContract({
18
+ address: this.reputationAddress,
19
+ abi: ReputationSystemABI,
20
+ functionName: 'computeScore',
21
+ args: [user, communities, ruleIds, activities]
22
+ });
23
+ }
24
+ /**
25
+ * Get global reputation score for a user
26
+ * @param user User address
27
+ * @returns Reputation score
28
+ */
29
+ async getGlobalReputation(user) {
30
+ // Try to read score, if fails (e.g. invalid contract), return 0
31
+ try {
32
+ const score = await this.computeScore(user, [], [], []);
33
+ return Number(score);
34
+ }
35
+ catch (e) {
36
+ console.warn('Failed to read reputation from contract, defaulting to 0');
37
+ return 0;
38
+ }
39
+ }
40
+ /**
41
+ * Get credit limit based on reputation
42
+ * @param user User address
43
+ * @returns Credit limit in wei (Mock logic closely tied to Reputation)
44
+ */
45
+ async getCreditLimit(user) {
46
+ const reputation = await this.getGlobalReputation(user);
47
+ // Dynamic Credit Limit Logic:
48
+ // Base: 0
49
+ // Score > 50: +0.01 ETH
50
+ // Score > 100: +0.05 ETH
51
+ let limit = 0n;
52
+ if (reputation > 50)
53
+ limit += 10000000000000000n; // 0.01 ETH
54
+ if (reputation > 100)
55
+ limit += 40000000000000000n; // +0.04 -> 0.05 ETH
56
+ return limit;
57
+ }
58
+ /**
59
+ * Get reputation score breakdown
60
+ * @param user User address
61
+ * @returns Detailed reputation breakdown (Mock implementation awaiting contract V4)
62
+ */
63
+ async getReputationBreakdown(user) {
64
+ const total = await this.getGlobalReputation(user);
65
+ // Heuristic breakdown
66
+ return {
67
+ baseScore: Math.floor(total * 0.5),
68
+ stakingBonus: Math.floor(total * 0.3),
69
+ activityBonus: Math.floor(total * 0.2),
70
+ penaltyDeduction: 0,
71
+ total
72
+ };
73
+ }
74
+ /**
75
+ * Submit reputation proof (off-chain data to on-chain)
76
+ * @param params Proof parameters
77
+ * @returns Transaction hash
78
+ */
79
+ async submitReputationProof(params) {
80
+ if (!this.walletClient || !this.walletClient.account) {
81
+ throw new Error("Wallet client required to submit proofs");
82
+ }
83
+ // Using a generic 'submitProof' signature for now
84
+ // In reality this would target the ReputationOracle or similar
85
+ return this.walletClient.writeContract({
86
+ address: this.reputationAddress,
87
+ abi: parseAbi(['function submitProof(string,bytes32)']),
88
+ functionName: 'submitProof',
89
+ args: [params.proofData, params.signature],
90
+ chain: this.walletClient.chain,
91
+ account: this.walletClient.account
92
+ });
93
+ }
94
+ }
@@ -0,0 +1,13 @@
1
+ import { type Address, type PublicClient } from 'viem';
2
+ /**
3
+ * Check if user holds MySBT token (identity verification).
4
+ */
5
+ export declare function checkMySBT(client: PublicClient, sbtAddress: Address, user: Address): Promise<{
6
+ hasSBT: boolean;
7
+ balance?: bigint;
8
+ }>;
9
+ /**
10
+ * Fetch MySBT token ID for a specific user (if unique/SBT).
11
+ * Note: Depends on whether the contract supports getTokenId or similar.
12
+ */
13
+ export declare function getMySBTId(client: PublicClient, sbtAddress: Address, user: Address): Promise<bigint | null>;
@@ -0,0 +1,37 @@
1
+ import { MySBTABI } from '@aastar/core';
2
+ /**
3
+ * Check if user holds MySBT token (identity verification).
4
+ */
5
+ export async function checkMySBT(client, sbtAddress, user) {
6
+ try {
7
+ const balance = await client.readContract({
8
+ address: sbtAddress,
9
+ abi: MySBTABI,
10
+ functionName: 'balanceOf',
11
+ args: [user]
12
+ });
13
+ return {
14
+ hasSBT: balance > 0n,
15
+ balance: balance
16
+ };
17
+ }
18
+ catch (e) {
19
+ console.warn('MySBT check failed:', e);
20
+ return { hasSBT: false };
21
+ }
22
+ }
23
+ /**
24
+ * Fetch MySBT token ID for a specific user (if unique/SBT).
25
+ * Note: Depends on whether the contract supports getTokenId or similar.
26
+ */
27
+ export async function getMySBTId(client, sbtAddress, user) {
28
+ try {
29
+ // Implementation depends on the specific contract.
30
+ // Most SBTs use ownerOf or similar if mapping is known.
31
+ // For standard SBT balances, we usually just need hasSBT.
32
+ return null;
33
+ }
34
+ catch (e) {
35
+ return null;
36
+ }
37
+ }
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@aastar/identity",
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
+ "viem": "2.43.3",
12
+ "@aastar/core": "0.16.7"
13
+ },
14
+ "devDependencies": {
15
+ "typescript": "5.7.2"
16
+ },
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "license": "MIT",
21
+ "scripts": {
22
+ "clean": "find src -name '*.js' -o -name '*.d.ts' -o -name '*.map' | xargs rm -f",
23
+ "prebuild": "pnpm clean",
24
+ "build": "tsc"
25
+ }
26
+ }