@aastar/sdk 0.16.23 → 0.17.0

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 (57) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +2 -0
  3. package/package.json +11 -10
  4. package/dist/clients/ExperimentClient.test.d.ts +0 -1
  5. package/dist/clients/ExperimentClient.test.js +0 -53
  6. package/dist/clients/admin.test.d.ts +0 -1
  7. package/dist/clients/admin.test.js +0 -79
  8. package/dist/clients/clients.test.d.ts +0 -1
  9. package/dist/clients/clients.test.js +0 -91
  10. package/dist/clients/community.test.d.ts +0 -1
  11. package/dist/clients/community.test.js +0 -99
  12. package/dist/clients/endUser.test.d.ts +0 -1
  13. package/dist/clients/endUser.test.js +0 -188
  14. package/dist/clients/operator.test.d.ts +0 -1
  15. package/dist/clients/operator.test.js +0 -139
  16. package/dist/core/src/abis/BLSAggregator.json +0 -686
  17. package/dist/core/src/abis/BLSValidator.json +0 -42
  18. package/dist/core/src/abis/DVTValidator.json +0 -368
  19. package/dist/core/src/abis/EntryPoint.json +0 -1382
  20. package/dist/core/src/abis/GToken.json +0 -513
  21. package/dist/core/src/abis/GTokenStaking.json +0 -949
  22. package/dist/core/src/abis/MySBT.json +0 -1518
  23. package/dist/core/src/abis/Paymaster.json +0 -1143
  24. package/dist/core/src/abis/PaymasterFactory.json +0 -640
  25. package/dist/core/src/abis/Registry.json +0 -1942
  26. package/dist/core/src/abis/ReputationSystem.json +0 -699
  27. package/dist/core/src/abis/SimpleAccount.json +0 -560
  28. package/dist/core/src/abis/SimpleAccountFactory.json +0 -111
  29. package/dist/core/src/abis/SuperPaymaster.json +0 -1781
  30. package/dist/core/src/abis/xPNTsFactory.json +0 -718
  31. package/dist/core/src/abis/xPNTsToken.json +0 -1280
  32. package/dist/errors/AAStarError.d.ts +0 -26
  33. package/dist/errors/AAStarError.js +0 -32
  34. package/dist/errors/AAStarError.test.d.ts +0 -1
  35. package/dist/errors/AAStarError.test.js +0 -74
  36. package/dist/errors/decoder.test.d.ts +0 -1
  37. package/dist/errors/decoder.test.js +0 -90
  38. package/dist/node/index.d.ts +0 -7
  39. package/dist/node/index.js +0 -7
  40. package/dist/types/result.d.ts +0 -15
  41. package/dist/types/result.js +0 -23
  42. package/dist/utils/errorHandler.test.d.ts +0 -1
  43. package/dist/utils/errorHandler.test.js +0 -89
  44. package/dist/utils/eventDecoder.d.ts +0 -7
  45. package/dist/utils/eventDecoder.js +0 -54
  46. package/dist/utils/eventDecoder.test.d.ts +0 -1
  47. package/dist/utils/eventDecoder.test.js +0 -48
  48. package/dist/utils/funding.test.d.ts +0 -1
  49. package/dist/utils/funding.test.js +0 -105
  50. package/dist/utils/keys.test.d.ts +0 -1
  51. package/dist/utils/keys.test.js +0 -81
  52. package/dist/utils/roleData.test.d.ts +0 -1
  53. package/dist/utils/roleData.test.js +0 -74
  54. package/dist/utils/testScenarios.test.d.ts +0 -1
  55. package/dist/utils/testScenarios.test.js +0 -68
  56. package/dist/utils/userOp.test.d.ts +0 -1
  57. package/dist/utils/userOp.test.js +0 -152
@@ -1,81 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest';
2
- import { KeyManager, parseKey } from './keys.js';
3
- import * as fs from 'fs';
4
- import { isAddress } from 'viem';
5
- vi.mock('fs');
6
- describe('KeyManager', () => {
7
- beforeEach(() => {
8
- vi.clearAllMocks();
9
- });
10
- it('should generate a single key pair', () => {
11
- const key = KeyManager.generateKeyPair('Test');
12
- expect(key.name).toBe('Test');
13
- expect(key.privateKey).toMatch(/^0x/);
14
- expect(isAddress(key.address)).toBe(true);
15
- });
16
- it('should generate multiple key pairs', () => {
17
- const keys = KeyManager.generateMultiple(3, 'Op');
18
- expect(keys.length).toBe(3);
19
- expect(keys[0].name).toBe('Op_1');
20
- expect(keys[2].name).toBe('Op_3');
21
- });
22
- it('should save keys to env file', () => {
23
- const keys = [
24
- { name: 'Admin', privateKey: '0x1', address: '0x1' }
25
- ];
26
- fs.existsSync.mockReturnValue(false);
27
- KeyManager.saveToEnvFile('/mock/.env', keys);
28
- expect(fs.writeFileSync).toHaveBeenCalledWith('/mock/.env', expect.stringContaining('ADMIN_PRIVATE_KEY=0x1'), expect.objectContaining({ mode: 0o600 }));
29
- });
30
- it('should load keys from env file', () => {
31
- const mockEnv = 'ADMIN_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80\n';
32
- fs.existsSync.mockReturnValue(true);
33
- fs.readFileSync.mockReturnValue(mockEnv);
34
- const keys = KeyManager.loadFromEnvFile('/mock/.env');
35
- expect(keys.length).toBe(1);
36
- expect(keys[0].name).toBe('admin');
37
- expect(keys[0].privateKey).toBe('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80');
38
- });
39
- it('should save and load keys from json file', () => {
40
- const keys = [
41
- { name: 'Test', privateKey: '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80', address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266' }
42
- ];
43
- fs.existsSync.mockReturnValueOnce(false).mockReturnValueOnce(true);
44
- fs.readFileSync.mockReturnValue(JSON.stringify({ keys }));
45
- KeyManager.saveToJsonFile('/mock/keys.json', keys);
46
- expect(fs.writeFileSync).toHaveBeenCalled();
47
- const loaded = KeyManager.loadFromJsonFile('/mock/keys.json');
48
- expect(loaded).toEqual(keys);
49
- });
50
- it('should parse keys with and without prefix', () => {
51
- expect(parseKey('abc')).toBe('0xabc');
52
- expect(parseKey('0xabc')).toBe('0xabc');
53
- });
54
- it('should throw if json file exists and overwrite is false', () => {
55
- fs.existsSync.mockReturnValue(true);
56
- expect(() => KeyManager.saveToJsonFile('/mock/keys.json', [], false)).toThrow(/File already exists/);
57
- });
58
- it('should throw if json file not found', () => {
59
- fs.existsSync.mockReturnValue(false);
60
- expect(() => KeyManager.loadFromJsonFile('/mock/missing.json')).toThrow(/File not found/);
61
- });
62
- it('should print keys with masked private key', () => {
63
- const consoleSpy = vi.spyOn(console, 'log');
64
- const keys = [
65
- { name: 'Admin', privateKey: '0x1234567890123456789012345678901234567890', address: '0xAddress' }
66
- ];
67
- KeyManager.printKeys(keys, false);
68
- expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('Generated Keys'));
69
- // Check for masked key format (start...end)
70
- expect(consoleSpy).toHaveBeenCalledWith(expect.stringMatching(/Private Key: 0x12345678\.\.\.34567890/));
71
- expect(consoleSpy).not.toHaveBeenCalledWith(expect.stringContaining('0x1234567890123456789012345678901234567890'));
72
- });
73
- it('should print keys with full private key', () => {
74
- const consoleSpy = vi.spyOn(console, 'log');
75
- const keys = [
76
- { name: 'Admin', privateKey: '0x1234567890123456789012345678901234567890', address: '0xAddress' }
77
- ];
78
- KeyManager.printKeys(keys, true);
79
- expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('0x1234567890123456789012345678901234567890'));
80
- });
81
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,74 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { RoleDataFactory, RoleIds } from './roleData.js';
3
- import { zeroAddress } from 'viem';
4
- describe('RoleDataFactory', () => {
5
- it('should have correct role ids', () => {
6
- expect(RoleIds.COMMUNITY).toBeDefined();
7
- expect(RoleIds.ENDUSER).toBeDefined();
8
- });
9
- it('should encode and decode community data', () => {
10
- const params = {
11
- name: 'MyCommunity',
12
- ensName: 'my.eth',
13
- website: 'https://my.com',
14
- description: 'desc',
15
- logoURI: 'logo',
16
- stakeAmount: 100n
17
- };
18
- const encoded = RoleDataFactory.community(params);
19
- const decoded = RoleDataFactory.decodeCommunity(encoded);
20
- expect(decoded.name).toBe(params.name);
21
- expect(decoded.stakeAmount).toBe(params.stakeAmount);
22
- });
23
- it('should encode and decode community data with different params', () => {
24
- const params = {
25
- name: 'VibeCommunity',
26
- ensName: 'vibe.eth',
27
- website: 'https://vibe.io',
28
- description: 'Good vibes only',
29
- logoURI: 'ipfs://logo',
30
- stakeAmount: 100n
31
- };
32
- const encoded = RoleDataFactory.community(params);
33
- const decoded = RoleDataFactory.decodeCommunity(encoded);
34
- expect(decoded.name).toBe(params.name);
35
- expect(decoded.ensName).toBe(params.ensName);
36
- expect(decoded.stakeAmount).toBe(params.stakeAmount);
37
- });
38
- it('should encode community with default values', () => {
39
- const encoded = RoleDataFactory.community();
40
- const decoded = RoleDataFactory.decodeCommunity(encoded);
41
- expect(decoded.name).toBe('TestCommunity');
42
- expect(decoded.stakeAmount).toBe(0n);
43
- });
44
- it('should use default values for community', () => {
45
- const encoded = RoleDataFactory.community();
46
- const decoded = RoleDataFactory.decodeCommunity(encoded);
47
- expect(decoded.name).toBe('TestCommunity');
48
- expect(decoded.stakeAmount).toBe(0n);
49
- });
50
- it('should encode and decode endUser data', () => {
51
- const params = {
52
- account: '0x1111111111111111111111111111111111111111',
53
- community: '0x2222222222222222222222222222222222222222',
54
- avatarURI: 'avatar',
55
- ensName: 'user.eth',
56
- stakeAmount: 50n
57
- };
58
- const encoded = RoleDataFactory.endUser(params);
59
- const decoded = RoleDataFactory.decodeEndUser(encoded);
60
- expect(decoded.account).toBe(params.account);
61
- expect(decoded.community).toBe(params.community);
62
- expect(decoded.stakeAmount).toBe(params.stakeAmount);
63
- });
64
- it('should encode endUser with default values', () => {
65
- const encoded = RoleDataFactory.endUser();
66
- const decoded = RoleDataFactory.decodeEndUser(encoded);
67
- expect(decoded.account).toBe(zeroAddress);
68
- expect(decoded.stakeAmount).toBe(0n);
69
- });
70
- it('should handle paymasterSuper and dvt (empty data)', () => {
71
- expect(RoleDataFactory.paymasterSuper()).toBe('0x');
72
- expect(RoleDataFactory.dvt()).toBe('0x');
73
- });
74
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,68 +0,0 @@
1
- import { describe, it, expect, vi } from 'vitest';
2
- import { UserOpScenarioBuilder, UserOpScenarioType } from './testScenarios.js';
3
- describe('UserOpScenarioBuilder', () => {
4
- it('should build NATIVE transfer scenario', async () => {
5
- const mockPublicClient = {
6
- readContract: vi.fn().mockResolvedValue(0n),
7
- chain: { id: 1 }
8
- };
9
- const params = {
10
- sender: '0x0000000000000000000000000000000000000001',
11
- ownerAccount: { signMessage: vi.fn().mockResolvedValue('0xsig') },
12
- recipient: '0x0000000000000000000000000000000000000002',
13
- tokenAddress: '0x0000000000000000000000000000000000000003',
14
- amount: 100n,
15
- entryPoint: '0x0000000000000000000000000000000000000004',
16
- chainId: 1,
17
- publicClient: mockPublicClient
18
- };
19
- const result = await UserOpScenarioBuilder.buildTransferScenario(UserOpScenarioType.NATIVE, params);
20
- expect(result.userOp.paymasterAndData).toBe('0x');
21
- expect(result.userOp.signature).toBe('0xsig');
22
- });
23
- it('should build GASLESS_V4 transfer scenario', async () => {
24
- const mockPublicClient = {
25
- readContract: vi.fn().mockResolvedValue(0n),
26
- chain: { id: 1 }
27
- };
28
- const params = {
29
- sender: '0x0000000000000000000000000000000000000001',
30
- ownerAccount: { signMessage: vi.fn().mockResolvedValue('0xsig') },
31
- recipient: '0x0000000000000000000000000000000000000002',
32
- tokenAddress: '0x0000000000000000000000000000000000000003',
33
- amount: 100n,
34
- entryPoint: '0x0000000000000000000000000000000000000004',
35
- chainId: 1,
36
- publicClient: mockPublicClient,
37
- paymaster: '0x0000000000000000000000000000000000000005'
38
- };
39
- const result = await UserOpScenarioBuilder.buildTransferScenario(UserOpScenarioType.GASLESS_V4, params);
40
- expect(result.userOp.paymasterAndData).toBeDefined();
41
- expect(result.userOp.paymasterAndData).not.toBe('0x');
42
- });
43
- it('should throw if paymaster missing for v4', async () => {
44
- const params = { publicClient: { readContract: vi.fn() }, sender: '0x0000000000000000000000000000000000000001' };
45
- await expect(UserOpScenarioBuilder.buildTransferScenario(UserOpScenarioType.GASLESS_V4, params))
46
- .rejects.toThrow();
47
- });
48
- it('should build SUPER_BPNT scenario', async () => {
49
- const mockPublicClient = {
50
- readContract: vi.fn().mockResolvedValue(0n),
51
- chain: { id: 1 }
52
- };
53
- const params = {
54
- sender: '0x0000000000000000000000000000000000000001',
55
- ownerAccount: { signMessage: vi.fn().mockResolvedValue('0xsig') },
56
- recipient: '0x0000000000000000000000000000000000000002',
57
- tokenAddress: '0x0000000000000000000000000000000000000003',
58
- amount: 100n,
59
- entryPoint: '0x0000000000000000000000000000000000000004',
60
- chainId: 1,
61
- publicClient: mockPublicClient,
62
- paymaster: '0x0000000000000000000000000000000000000005',
63
- operator: '0x0000000000000000000000000000000000000006'
64
- };
65
- const result = await UserOpScenarioBuilder.buildTransferScenario(UserOpScenarioType.SUPER_BPNT, params);
66
- expect(result.userOp.paymasterAndData).toContain('0x');
67
- });
68
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,152 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { UserOperationBuilder } from './userOp.js';
3
- import { concat } from 'viem';
4
- describe('UserOperationBuilder', () => {
5
- const MOCK_ADDR = '0x1111111111111111111111111111111111111111';
6
- const MOCK_PM = '0x2222222222222222222222222222222222222222';
7
- const MOCK_TOKEN = '0x3333333333333333333333333333333333333333';
8
- describe('Gas Packing', () => {
9
- it('should pack account gas limits', () => {
10
- const packed = UserOperationBuilder.packAccountGasLimits(100000n, 200000n);
11
- expect(packed).toBeDefined();
12
- expect(packed.length).toBeGreaterThan(2);
13
- });
14
- it('should pack gas fees', () => {
15
- const packed = UserOperationBuilder.packGasFees(1000000000n, 2000000000n);
16
- expect(packed).toBeDefined();
17
- expect(packed.length).toBeGreaterThan(2);
18
- });
19
- it('should pack paymaster and data', () => {
20
- const packed = UserOperationBuilder.packPaymasterAndData(MOCK_PM, 250000n, 50000n, '0x1234');
21
- expect(packed).toBeDefined();
22
- expect(packed.startsWith(MOCK_PM.toLowerCase())).toBe(true);
23
- });
24
- it('should pack PaymasterV4 deposit data', () => {
25
- const validUntil = BigInt(Math.floor(Date.now() / 1000) + 3600);
26
- const validAfter = BigInt(Math.floor(Date.now() / 1000));
27
- const packed = UserOperationBuilder.packPaymasterV4DepositData(MOCK_PM, 250000n, 50000n, MOCK_TOKEN, validUntil, validAfter);
28
- expect(packed).toBeDefined();
29
- expect(packed.length).toBeGreaterThan(100);
30
- });
31
- });
32
- describe('UserOp Formatting', () => {
33
- it('should jsonify UserOp', () => {
34
- const userOp = {
35
- sender: MOCK_ADDR,
36
- nonce: 0n,
37
- initCode: '0x',
38
- callData: '0x',
39
- accountGasLimits: UserOperationBuilder.packAccountGasLimits(100000n, 200000n),
40
- preVerificationGas: 50000n,
41
- gasFees: UserOperationBuilder.packGasFees(1000000000n, 2000000000n),
42
- paymasterAndData: '0x',
43
- signature: '0x'
44
- };
45
- const jsonified = UserOperationBuilder.jsonifyUserOp(userOp);
46
- expect(jsonified).toBeDefined();
47
- expect(jsonified.sender).toBe(MOCK_ADDR);
48
- });
49
- it('should convert to Alchemy format', () => {
50
- const userOp = {
51
- sender: MOCK_ADDR,
52
- nonce: '0x0',
53
- initCode: '0x',
54
- callData: '0x',
55
- accountGasLimits: UserOperationBuilder.packAccountGasLimits(100000n, 200000n),
56
- preVerificationGas: '0xc350',
57
- gasFees: UserOperationBuilder.packGasFees(1000000000n, 2000000000n),
58
- paymasterAndData: '0x', // no paymaster
59
- signature: '0x'
60
- };
61
- const alchemy = UserOperationBuilder.toAlchemyUserOperation(userOp);
62
- expect(alchemy).toBeDefined();
63
- expect(alchemy.sender).toBe(MOCK_ADDR);
64
- expect(alchemy.verificationGasLimit).toBeDefined();
65
- expect(alchemy.callGasLimit).toBeDefined();
66
- });
67
- it('should unpack paymaster and data (full v0.7 format)', () => {
68
- const pmData = UserOperationBuilder.packPaymasterAndData(MOCK_PM, 300000n, 100000n, '0x12345678');
69
- const userOp = {
70
- sender: MOCK_ADDR,
71
- nonce: '0x0',
72
- initCode: '0x',
73
- callData: '0x',
74
- accountGasLimits: '0x',
75
- preVerificationGas: '0x0',
76
- gasFees: '0x',
77
- paymasterAndData: pmData,
78
- signature: '0x'
79
- };
80
- const alchemy = UserOperationBuilder.toAlchemyUserOperation(userOp);
81
- expect(alchemy.paymaster).toBe(MOCK_PM);
82
- expect(alchemy.paymasterVerificationGasLimit).toBeDefined();
83
- expect(alchemy.paymasterPostOpGasLimit).toBeDefined();
84
- expect(alchemy.paymasterData).toBe('0x12345678');
85
- });
86
- it('should unpack paymaster and data (legacy format fallback)', () => {
87
- // Not enough bytes for Gas Limits, treated as paymaster + data
88
- const legacyPmData = concat([MOCK_PM, '0xabcdef']);
89
- const userOp = {
90
- sender: MOCK_ADDR,
91
- nonce: '0x0',
92
- initCode: '0x',
93
- callData: '0x',
94
- accountGasLimits: '0x',
95
- preVerificationGas: '0x0',
96
- gasFees: '0x',
97
- paymasterAndData: legacyPmData,
98
- signature: '0x'
99
- };
100
- const alchemy = UserOperationBuilder.toAlchemyUserOperation(userOp);
101
- expect(alchemy.paymaster).toBe(MOCK_PM);
102
- expect(alchemy.paymasterData).toBe('0xabcdef');
103
- expect(alchemy.paymasterVerificationGasLimit).toBeDefined(); // defaults
104
- });
105
- it('should unpack initCode into factory and factoryData', () => {
106
- const factory = MOCK_ADDR;
107
- const factoryData = '0xdeadbeef';
108
- const initCode = concat([factory, factoryData]);
109
- const userOp = {
110
- sender: MOCK_ADDR,
111
- nonce: '0x0',
112
- initCode: initCode,
113
- callData: '0x',
114
- accountGasLimits: '0x',
115
- preVerificationGas: '0x0',
116
- gasFees: '0x',
117
- paymasterAndData: '0x',
118
- signature: '0x'
119
- };
120
- const alchemy = UserOperationBuilder.toAlchemyUserOperation(userOp);
121
- expect(alchemy.factory.toLowerCase()).toBe(factory.toLowerCase());
122
- expect(alchemy.factoryData).toBe(factoryData);
123
- });
124
- it('should jsonify various types', () => {
125
- const userOp = {
126
- sender: MOCK_ADDR,
127
- nonce: 123, // number
128
- initCode: '0x',
129
- callData: '0x',
130
- accountGasLimits: '0x',
131
- preVerificationGas: '0x10', // string
132
- gasFees: '0x',
133
- paymasterAndData: '0x',
134
- signature: '0x'
135
- };
136
- const json = UserOperationBuilder.jsonifyUserOp(userOp);
137
- expect(json.nonce).toBe('0x7b');
138
- expect(json.preVerificationGas).toBe('0x10');
139
- });
140
- it('should handle leading zeros in string quantities for Alchemy', () => {
141
- const userOp = {
142
- sender: MOCK_ADDR,
143
- nonce: '0x0001', // leading zeros
144
- preVerificationGas: '0x0', // valid zero
145
- // ... others
146
- };
147
- const json = UserOperationBuilder.jsonifyUserOp(userOp);
148
- expect(json.nonce).toBe('0x1'); // compact
149
- expect(json.preVerificationGas).toBe('0x0');
150
- });
151
- });
152
- });