@aastar/account 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 (96) hide show
  1. package/LICENSE +21 -0
  2. package/dist/account/src/accounts/simple.d.ts +18 -0
  3. package/dist/account/src/accounts/simple.js +49 -0
  4. package/dist/account/src/accounts/simple.test.d.ts +1 -0
  5. package/dist/account/src/accounts/simple.test.js +78 -0
  6. package/dist/account/src/eoa.d.ts +10 -0
  7. package/dist/account/src/eoa.js +21 -0
  8. package/dist/account/src/eoa.test.d.ts +1 -0
  9. package/dist/account/src/eoa.test.js +31 -0
  10. package/dist/account/src/index.d.ts +19 -0
  11. package/dist/account/src/index.js +49 -0
  12. package/dist/account/src/index.test.d.ts +1 -0
  13. package/dist/account/src/index.test.js +29 -0
  14. package/dist/core/src/abis/BLSAggregator.json +686 -0
  15. package/dist/core/src/abis/BLSValidator.json +42 -0
  16. package/dist/core/src/abis/DVTValidator.json +368 -0
  17. package/dist/core/src/abis/EntryPoint.json +1382 -0
  18. package/dist/core/src/abis/GToken.json +513 -0
  19. package/dist/core/src/abis/GTokenStaking.json +949 -0
  20. package/dist/core/src/abis/MySBT.json +1518 -0
  21. package/dist/core/src/abis/Paymaster.json +1143 -0
  22. package/dist/core/src/abis/PaymasterFactory.json +640 -0
  23. package/dist/core/src/abis/Registry.json +1942 -0
  24. package/dist/core/src/abis/ReputationSystem.json +699 -0
  25. package/dist/core/src/abis/SimpleAccount.json +560 -0
  26. package/dist/core/src/abis/SimpleAccountFactory.json +111 -0
  27. package/dist/core/src/abis/SuperPaymaster.json +1781 -0
  28. package/dist/core/src/abis/index.d.ts +1126 -0
  29. package/dist/core/src/abis/index.js +91 -0
  30. package/dist/core/src/abis/xPNTsFactory.json +718 -0
  31. package/dist/core/src/abis/xPNTsToken.json +1280 -0
  32. package/dist/core/src/actions/StateValidator.d.ts +68 -0
  33. package/dist/core/src/actions/StateValidator.js +187 -0
  34. package/dist/core/src/actions/account.d.ts +55 -0
  35. package/dist/core/src/actions/account.js +133 -0
  36. package/dist/core/src/actions/aggregator.d.ts +17 -0
  37. package/dist/core/src/actions/aggregator.js +31 -0
  38. package/dist/core/src/actions/dvt.d.ts +30 -0
  39. package/dist/core/src/actions/dvt.js +41 -0
  40. package/dist/core/src/actions/entryPoint.d.ts +90 -0
  41. package/dist/core/src/actions/entryPoint.js +211 -0
  42. package/dist/core/src/actions/factory.d.ts +215 -0
  43. package/dist/core/src/actions/factory.js +442 -0
  44. package/dist/core/src/actions/faucet.d.ts +48 -0
  45. package/dist/core/src/actions/faucet.js +337 -0
  46. package/dist/core/src/actions/gtokenExtended.d.ts +39 -0
  47. package/dist/core/src/actions/gtokenExtended.js +115 -0
  48. package/dist/core/src/actions/index.d.ts +15 -0
  49. package/dist/core/src/actions/index.js +17 -0
  50. package/dist/core/src/actions/paymasterV4.d.ts +170 -0
  51. package/dist/core/src/actions/paymasterV4.js +334 -0
  52. package/dist/core/src/actions/registry.d.ts +246 -0
  53. package/dist/core/src/actions/registry.js +667 -0
  54. package/dist/core/src/actions/reputation.d.ts +129 -0
  55. package/dist/core/src/actions/reputation.js +281 -0
  56. package/dist/core/src/actions/sbt.d.ts +191 -0
  57. package/dist/core/src/actions/sbt.js +533 -0
  58. package/dist/core/src/actions/staking.d.ts +132 -0
  59. package/dist/core/src/actions/staking.js +330 -0
  60. package/dist/core/src/actions/superPaymaster.d.ts +237 -0
  61. package/dist/core/src/actions/superPaymaster.js +644 -0
  62. package/dist/core/src/actions/tokens.d.ts +229 -0
  63. package/dist/core/src/actions/tokens.js +415 -0
  64. package/dist/core/src/branding.d.ts +30 -0
  65. package/dist/core/src/branding.js +30 -0
  66. package/dist/core/src/clients/BaseClient.d.ts +25 -0
  67. package/dist/core/src/clients/BaseClient.js +66 -0
  68. package/dist/core/src/clients/types.d.ts +60 -0
  69. package/dist/core/src/clients/types.js +1 -0
  70. package/dist/core/src/clients.d.ts +5 -0
  71. package/dist/core/src/clients.js +11 -0
  72. package/dist/core/src/communities.d.ts +52 -0
  73. package/dist/core/src/communities.js +73 -0
  74. package/dist/core/src/config/ContractConfigManager.d.ts +20 -0
  75. package/dist/core/src/config/ContractConfigManager.js +48 -0
  76. package/dist/core/src/constants.d.ts +88 -0
  77. package/dist/core/src/constants.js +125 -0
  78. package/dist/core/src/contract-addresses.d.ts +110 -0
  79. package/dist/core/src/contract-addresses.js +99 -0
  80. package/dist/core/src/contracts.d.ts +424 -0
  81. package/dist/core/src/contracts.js +343 -0
  82. package/dist/core/src/crypto/blsSigner.d.ts +64 -0
  83. package/dist/core/src/crypto/blsSigner.js +98 -0
  84. package/dist/core/src/crypto/index.d.ts +1 -0
  85. package/dist/core/src/crypto/index.js +1 -0
  86. package/dist/core/src/index.d.ts +21 -0
  87. package/dist/core/src/index.js +21 -0
  88. package/dist/core/src/networks.d.ts +127 -0
  89. package/dist/core/src/networks.js +118 -0
  90. package/dist/core/src/requirementChecker.d.ts +38 -0
  91. package/dist/core/src/requirementChecker.js +139 -0
  92. package/dist/core/src/roles.d.ts +204 -0
  93. package/dist/core/src/roles.js +211 -0
  94. package/dist/core/src/utils/validation.d.ts +24 -0
  95. package/dist/core/src/utils/validation.js +56 -0
  96. package/package.json +24 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 AAStar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,18 @@
1
+ import { type Address, type Hex, type LocalAccount } from 'viem';
2
+ export type SimpleSmartAccount = LocalAccount & {
3
+ signUserOperation: (userOp: any) => Promise<Hex>;
4
+ getInitCode: () => Promise<Hex>;
5
+ getDummySignature: () => Promise<Hex>;
6
+ entryPoint: Address;
7
+ };
8
+ export declare function toSimpleSmartAccount(parameters: {
9
+ client: any;
10
+ owner: LocalAccount;
11
+ factoryAddress: Address;
12
+ entryPoint: {
13
+ address: Address;
14
+ version: '0.6' | '0.7';
15
+ };
16
+ salt?: bigint;
17
+ index?: bigint;
18
+ }): Promise<SimpleSmartAccount>;
@@ -0,0 +1,49 @@
1
+ import { concatHex, encodeFunctionData, } from 'viem';
2
+ import { SimpleAccountFactoryABI } from '@aastar/core';
3
+ import { getUserOpHash } from '../index.js';
4
+ export async function toSimpleSmartAccount(parameters) {
5
+ const { client, owner, factoryAddress, entryPoint, index = 0n, salt = 0n } = parameters;
6
+ // Calculate initCode
7
+ const factoryData = encodeFunctionData({
8
+ abi: SimpleAccountFactoryABI,
9
+ functionName: 'createAccount',
10
+ args: [owner.address, salt]
11
+ });
12
+ const initCode = concatHex([factoryAddress, factoryData]);
13
+ // Calculate counterfactual address
14
+ const address = await client.readContract({
15
+ address: factoryAddress,
16
+ abi: SimpleAccountFactoryABI,
17
+ functionName: 'getAddress',
18
+ args: [owner.address, salt]
19
+ });
20
+ return {
21
+ address,
22
+ publicKey: owner.address,
23
+ source: 'custom',
24
+ type: 'local',
25
+ entryPoint: entryPoint.address,
26
+ async signMessage({ message }) {
27
+ // validating signature for smart account usually involves EIP-1271,
28
+ // but here we just sign with owner for SimpleAccount which validates owner sig
29
+ return owner.signMessage({ message });
30
+ },
31
+ async signTypedData(typedData) {
32
+ return owner.signTypedData(typedData);
33
+ },
34
+ async signTransaction(transaction) {
35
+ throw new Error('Smart Accounts cannot sign transactions directly. Use UserOperations.');
36
+ },
37
+ async signUserOperation(userOp) {
38
+ const chainId = client.chain?.id || 31337; // Default to local anvil if not found
39
+ const hash = getUserOpHash(userOp, entryPoint.address, chainId);
40
+ return owner.signMessage({ message: { raw: hash } });
41
+ },
42
+ async getInitCode() {
43
+ return initCode;
44
+ },
45
+ async getDummySignature() {
46
+ return '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff';
47
+ }
48
+ };
49
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,78 @@
1
+ import { describe, it, expect, vi } from 'vitest';
2
+ import { toSimpleSmartAccount } from './simple.js';
3
+ describe('SimpleSmartAccount', () => {
4
+ const MOCK_OWNER = {
5
+ address: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
6
+ signMessage: vi.fn().mockResolvedValue('0xsignature'),
7
+ signTypedData: vi.fn(),
8
+ };
9
+ const MOCK_FACTORY = '0x1111111111111111111111111111111111111111';
10
+ const MOCK_SMART_ACCOUNT = '0x2222222222222222222222222222222222222222';
11
+ const MOCK_EP = '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789';
12
+ it('should create simple smart account wrapper', async () => {
13
+ const mockClient = {
14
+ readContract: vi.fn().mockResolvedValue(MOCK_SMART_ACCOUNT),
15
+ chain: { id: 31337 }
16
+ };
17
+ const account = await toSimpleSmartAccount({
18
+ client: mockClient,
19
+ owner: MOCK_OWNER,
20
+ factoryAddress: MOCK_FACTORY,
21
+ entryPoint: { address: MOCK_EP, version: '0.6' }
22
+ });
23
+ expect(account.address).toBe(MOCK_SMART_ACCOUNT);
24
+ expect(account.entryPoint).toBe(MOCK_EP);
25
+ const initCode = await account.getInitCode();
26
+ expect(initCode.startsWith(MOCK_FACTORY)).toBe(true);
27
+ const dummy = await account.getDummySignature();
28
+ expect(dummy).toBeDefined();
29
+ });
30
+ it('should sign user operation', async () => {
31
+ const mockClient = {
32
+ readContract: vi.fn().mockResolvedValue(MOCK_SMART_ACCOUNT),
33
+ chain: { id: 31337 }
34
+ };
35
+ const account = await toSimpleSmartAccount({
36
+ client: mockClient,
37
+ owner: MOCK_OWNER,
38
+ factoryAddress: MOCK_FACTORY,
39
+ entryPoint: { address: MOCK_EP, version: '0.6' }
40
+ });
41
+ const userOp = {
42
+ sender: MOCK_SMART_ACCOUNT,
43
+ nonce: 0n,
44
+ initCode: '0x',
45
+ callData: '0x',
46
+ accountGasLimits: '0x0000000000000000000000000000000000000000000000000000000000000000',
47
+ preVerificationGas: 0n,
48
+ gasFees: '0x0000000000000000000000000000000000000000000000000000000000000000',
49
+ paymasterAndData: '0x'
50
+ };
51
+ const sig = await account.signUserOperation(userOp);
52
+ expect(sig).toBe('0xsignature');
53
+ expect(MOCK_OWNER.signMessage).toHaveBeenCalled();
54
+ });
55
+ it('should sign message and typed data', async () => {
56
+ const mockClient = { readContract: vi.fn().mockResolvedValue(MOCK_SMART_ACCOUNT) };
57
+ const account = await toSimpleSmartAccount({
58
+ client: mockClient,
59
+ owner: MOCK_OWNER,
60
+ factoryAddress: MOCK_FACTORY,
61
+ entryPoint: { address: MOCK_EP, version: '0.6' }
62
+ });
63
+ await account.signMessage({ message: 'hello' });
64
+ expect(MOCK_OWNER.signMessage).toHaveBeenCalled();
65
+ await account.signTypedData({});
66
+ expect(MOCK_OWNER.signTypedData).toHaveBeenCalled();
67
+ });
68
+ it('should throw on signTransaction', async () => {
69
+ const mockClient = { readContract: vi.fn().mockResolvedValue(MOCK_SMART_ACCOUNT) };
70
+ const account = await toSimpleSmartAccount({
71
+ client: mockClient,
72
+ owner: MOCK_OWNER,
73
+ factoryAddress: MOCK_FACTORY,
74
+ entryPoint: { address: MOCK_EP, version: '0.6' }
75
+ });
76
+ await expect(account.signTransaction({})).rejects.toThrow('UserOperations');
77
+ });
78
+ });
@@ -0,0 +1,10 @@
1
+ import { type WalletClient, type Address, type Chain, type Transport, type Hash, type Hex } from 'viem';
2
+ export type EOAWalletClient = WalletClient & {
3
+ sendTransaction: (args: {
4
+ to: Address;
5
+ value?: bigint;
6
+ data?: Hex;
7
+ }) => Promise<Hash>;
8
+ getAddress: () => Address;
9
+ };
10
+ export declare const createEOAWalletClient: (privateKey: Hex, chain: Chain, transport?: Transport) => EOAWalletClient;
@@ -0,0 +1,21 @@
1
+ import { createWalletClient, http } from 'viem';
2
+ import { privateKeyToAccount } from 'viem/accounts';
3
+ export const createEOAWalletClient = (privateKey, chain, transport = http()) => {
4
+ const account = privateKeyToAccount(privateKey);
5
+ const client = createWalletClient({
6
+ account,
7
+ chain,
8
+ transport
9
+ });
10
+ const baseSendTransaction = client.sendTransaction.bind(client);
11
+ return Object.assign(client, {
12
+ async sendTransaction(args) {
13
+ return baseSendTransaction({
14
+ ...args,
15
+ account,
16
+ chain
17
+ });
18
+ },
19
+ getAddress: () => account.address
20
+ });
21
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,31 @@
1
+ import { describe, it, expect, vi } from 'vitest';
2
+ import { createEOAWalletClient } from './eoa.js';
3
+ import * as viem from 'viem';
4
+ import { mainnet } from 'viem/chains';
5
+ vi.mock('viem', async () => {
6
+ const actual = await vi.importActual('viem');
7
+ return {
8
+ ...actual,
9
+ createWalletClient: vi.fn(),
10
+ };
11
+ });
12
+ describe('EOAWalletClient', () => {
13
+ const MOCK_KEY = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80';
14
+ const MOCK_ADDR = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266';
15
+ it('should create and use EOA wallet client', async () => {
16
+ const sendTransactionSpy = vi.fn().mockResolvedValue('0xhash');
17
+ const mockViemClient = {
18
+ sendTransaction: sendTransactionSpy,
19
+ account: { address: MOCK_ADDR }
20
+ };
21
+ viem.createWalletClient.mockReturnValue(mockViemClient);
22
+ const client = createEOAWalletClient(MOCK_KEY, mainnet);
23
+ expect(client.getAddress()).toBe(MOCK_ADDR);
24
+ const hash = await client.sendTransaction({ to: MOCK_ADDR, value: 100n });
25
+ expect(hash).toBe('0xhash');
26
+ expect(sendTransactionSpy).toHaveBeenCalledWith(expect.objectContaining({
27
+ to: MOCK_ADDR,
28
+ value: 100n
29
+ }));
30
+ });
31
+ });
@@ -0,0 +1,19 @@
1
+ import { type Hex, type Address } from 'viem';
2
+ export * from './eoa.js';
3
+ export * from './accounts/simple.js';
4
+ /**
5
+ * Common Pack Logic for v0.7 UserOperations
6
+ */
7
+ export declare function packUserOpLimits(high: bigint, low: bigint): Hex;
8
+ /**
9
+ * Local implementation of EntryPoint v0.7 getUserOpHash
10
+ */
11
+ export declare function getUserOpHash(op: any, ep: Address, chainId: number): Hex;
12
+ /**
13
+ * UserOperation Client for handling high-level flows
14
+ */
15
+ export declare class UserOpClient {
16
+ static estimateGas(bundler: any, op: any, entryPoint: Address): Promise<any>;
17
+ static sendUserOp(bundler: any, op: any, entryPoint: Address): Promise<any>;
18
+ static getReceipt(bundler: any, hash: Hex): Promise<any>;
19
+ }
@@ -0,0 +1,49 @@
1
+ import { encodeAbiParameters, keccak256 } from 'viem';
2
+ export * from './eoa.js';
3
+ export * from './accounts/simple.js';
4
+ /**
5
+ * Common Pack Logic for v0.7 UserOperations
6
+ */
7
+ export function packUserOpLimits(high, low) {
8
+ return `0x${((high << 128n) | low).toString(16).padStart(64, '0')}`;
9
+ }
10
+ /**
11
+ * Local implementation of EntryPoint v0.7 getUserOpHash
12
+ */
13
+ export function getUserOpHash(op, ep, chainId) {
14
+ const packed = encodeAbiParameters([
15
+ { type: 'address' }, { type: 'uint256' }, { type: 'bytes32' }, { type: 'bytes32' },
16
+ { type: 'bytes32' }, { type: 'uint256' }, { type: 'bytes32' }, { type: 'bytes32' }
17
+ ], [
18
+ op.sender, BigInt(op.nonce),
19
+ keccak256(op.initCode && op.initCode !== "0x" ? op.initCode : '0x'),
20
+ keccak256(op.callData),
21
+ op.accountGasLimits, BigInt(op.preVerificationGas), op.gasFees,
22
+ keccak256(op.paymasterAndData)
23
+ ]);
24
+ const enc = encodeAbiParameters([{ type: 'bytes32' }, { type: 'address' }, { type: 'uint256' }], [keccak256(packed), ep, BigInt(chainId)]);
25
+ return keccak256(enc);
26
+ }
27
+ /**
28
+ * UserOperation Client for handling high-level flows
29
+ */
30
+ export class UserOpClient {
31
+ static async estimateGas(bundler, op, entryPoint) {
32
+ return bundler.request({
33
+ method: 'eth_estimateUserOperationGas',
34
+ params: [op, entryPoint]
35
+ });
36
+ }
37
+ static async sendUserOp(bundler, op, entryPoint) {
38
+ return bundler.request({
39
+ method: 'eth_sendUserOperation',
40
+ params: [op, entryPoint]
41
+ });
42
+ }
43
+ static async getReceipt(bundler, hash) {
44
+ return bundler.request({
45
+ method: 'eth_getUserOperationReceipt',
46
+ params: [hash]
47
+ });
48
+ }
49
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,29 @@
1
+ import { describe, it, expect, vi } from 'vitest';
2
+ import { packUserOpLimits, UserOpClient } from './index.js';
3
+ describe('Account Utils', () => {
4
+ it('should pack user op limits', () => {
5
+ const packed = packUserOpLimits(100n, 200n);
6
+ expect(packed).toBeDefined();
7
+ expect(packed.length).toBe(66); // 0x + 64 chars
8
+ });
9
+ describe('UserOpClient', () => {
10
+ const mockBundler = {
11
+ request: vi.fn()
12
+ };
13
+ it('should estimate gas', async () => {
14
+ mockBundler.request.mockResolvedValue({ preVerificationGas: 1000n });
15
+ const res = await UserOpClient.estimateGas(mockBundler, {}, '0x1');
16
+ expect(res.preVerificationGas).toBe(1000n);
17
+ });
18
+ it('should send user operation', async () => {
19
+ mockBundler.request.mockResolvedValue('0xhash');
20
+ const res = await UserOpClient.sendUserOp(mockBundler, {}, '0x1');
21
+ expect(res).toBe('0xhash');
22
+ });
23
+ it('should get receipt', async () => {
24
+ mockBundler.request.mockResolvedValue({ success: true });
25
+ const res = await UserOpClient.getReceipt(mockBundler, '0xhash');
26
+ expect(res.success).toBe(true);
27
+ });
28
+ });
29
+ });