@aboutcircles/sdk-rpc 0.1.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 (68) hide show
  1. package/README.md +169 -0
  2. package/dist/client.d.ts +58 -0
  3. package/dist/client.d.ts.map +1 -0
  4. package/dist/client.js +194 -0
  5. package/dist/errors.d.ts +44 -0
  6. package/dist/errors.d.ts.map +1 -0
  7. package/dist/errors.js +63 -0
  8. package/dist/events/index.d.ts +8 -0
  9. package/dist/events/index.d.ts.map +1 -0
  10. package/dist/events/index.js +8 -0
  11. package/dist/events/observable.d.ts +23 -0
  12. package/dist/events/observable.d.ts.map +1 -0
  13. package/dist/events/observable.js +37 -0
  14. package/dist/events/parser.d.ts +10 -0
  15. package/dist/events/parser.d.ts.map +1 -0
  16. package/dist/events/parser.js +103 -0
  17. package/dist/events/types.d.ts +7 -0
  18. package/dist/events/types.d.ts.map +1 -0
  19. package/dist/events/types.js +11 -0
  20. package/dist/index.d.ts +12 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +2654 -0
  23. package/dist/methods/avatar.d.ts +51 -0
  24. package/dist/methods/avatar.d.ts.map +1 -0
  25. package/dist/methods/avatar.js +64 -0
  26. package/dist/methods/balance.d.ts +37 -0
  27. package/dist/methods/balance.d.ts.map +1 -0
  28. package/dist/methods/balance.js +50 -0
  29. package/dist/methods/group.d.ts +145 -0
  30. package/dist/methods/group.d.ts.map +1 -0
  31. package/dist/methods/group.js +380 -0
  32. package/dist/methods/index.d.ts +11 -0
  33. package/dist/methods/index.d.ts.map +1 -0
  34. package/dist/methods/index.js +10 -0
  35. package/dist/methods/invitation.d.ts +61 -0
  36. package/dist/methods/invitation.d.ts.map +1 -0
  37. package/dist/methods/invitation.js +230 -0
  38. package/dist/methods/pathfinder.d.ts +41 -0
  39. package/dist/methods/pathfinder.d.ts.map +1 -0
  40. package/dist/methods/pathfinder.js +53 -0
  41. package/dist/methods/profile.d.ts +109 -0
  42. package/dist/methods/profile.d.ts.map +1 -0
  43. package/dist/methods/profile.js +166 -0
  44. package/dist/methods/query.d.ts +79 -0
  45. package/dist/methods/query.d.ts.map +1 -0
  46. package/dist/methods/query.js +87 -0
  47. package/dist/methods/token.d.ts +61 -0
  48. package/dist/methods/token.d.ts.map +1 -0
  49. package/dist/methods/token.js +99 -0
  50. package/dist/methods/transaction.d.ts +41 -0
  51. package/dist/methods/transaction.d.ts.map +1 -0
  52. package/dist/methods/transaction.js +111 -0
  53. package/dist/methods/trust.d.ts +114 -0
  54. package/dist/methods/trust.d.ts.map +1 -0
  55. package/dist/methods/trust.js +245 -0
  56. package/dist/pagedQuery.d.ts +106 -0
  57. package/dist/pagedQuery.d.ts.map +1 -0
  58. package/dist/pagedQuery.js +254 -0
  59. package/dist/rpc.d.ts +61 -0
  60. package/dist/rpc.d.ts.map +1 -0
  61. package/dist/rpc.js +76 -0
  62. package/dist/types.d.ts +82 -0
  63. package/dist/types.d.ts.map +1 -0
  64. package/dist/types.js +1 -0
  65. package/dist/utils.d.ts +27 -0
  66. package/dist/utils.d.ts.map +1 -0
  67. package/dist/utils.js +111 -0
  68. package/package.json +32 -0
@@ -0,0 +1,51 @@
1
+ import type { RpcClient } from '../client';
2
+ import type { Address, AvatarInfo, NetworkSnapshot } from '@aboutcircles/sdk-types';
3
+ /**
4
+ * Avatar and network RPC methods
5
+ */
6
+ export declare class AvatarMethods {
7
+ private client;
8
+ constructor(client: RpcClient);
9
+ /**
10
+ * Get information about a specific avatar
11
+ *
12
+ * @param address - The avatar address to query
13
+ * @returns Avatar information
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const info = await rpc.avatar.getAvatarInfo('0xde374ece6fa50e781e81aac78e811b33d16912c7');
18
+ * console.log(info);
19
+ * ```
20
+ */
21
+ getAvatarInfo(address: Address): Promise<AvatarInfo | undefined>;
22
+ /**
23
+ * Get information about multiple avatars in batch
24
+ *
25
+ * @param addresses - Array of avatar addresses to query
26
+ * @returns Array of avatar information objects
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * const infos = await rpc.avatar.getAvatarInfoBatch([
31
+ * '0xde374ece6fa50e781e81aac78e811b33d16912c7',
32
+ * '0xc3a1428c04c426cdf513c6fc8e09f55ddaf50cd7'
33
+ * ]);
34
+ * ```
35
+ */
36
+ getAvatarInfoBatch(addresses: Address[]): Promise<AvatarInfo[]>;
37
+ /**
38
+ * Download a full snapshot of the Circles network state
39
+ * (current trust relations and balances)
40
+ *
41
+ * @returns Network snapshot with trust relations and balances
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * const snapshot = await rpc.avatar.getNetworkSnapshot();
46
+ * console.log(snapshot);
47
+ * ```
48
+ */
49
+ getNetworkSnapshot(): Promise<NetworkSnapshot>;
50
+ }
51
+ //# sourceMappingURL=avatar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"avatar.d.ts","sourceRoot":"","sources":["../../src/methods/avatar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAGpF;;GAEG;AACH,qBAAa,aAAa;IACZ,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,SAAS;IAErC;;;;;;;;;;;OAWG;IACG,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAKtE;;;;;;;;;;;;;OAaG;IACG,kBAAkB,CAAC,SAAS,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAcrE;;;;;;;;;;;OAWG;IACG,kBAAkB,IAAI,OAAO,CAAC,eAAe,CAAC;CAOrD"}
@@ -0,0 +1,64 @@
1
+ import { normalizeAddress, checksumAddresses } from '../utils';
2
+ /**
3
+ * Avatar and network RPC methods
4
+ */
5
+ export class AvatarMethods {
6
+ client;
7
+ constructor(client) {
8
+ this.client = client;
9
+ }
10
+ /**
11
+ * Get information about a specific avatar
12
+ *
13
+ * @param address - The avatar address to query
14
+ * @returns Avatar information
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const info = await rpc.avatar.getAvatarInfo('0xde374ece6fa50e781e81aac78e811b33d16912c7');
19
+ * console.log(info);
20
+ * ```
21
+ */
22
+ async getAvatarInfo(address) {
23
+ const results = await this.getAvatarInfoBatch([address]);
24
+ return results.length > 0 ? results[0] : undefined;
25
+ }
26
+ /**
27
+ * Get information about multiple avatars in batch
28
+ *
29
+ * @param addresses - Array of avatar addresses to query
30
+ * @returns Array of avatar information objects
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * const infos = await rpc.avatar.getAvatarInfoBatch([
35
+ * '0xde374ece6fa50e781e81aac78e811b33d16912c7',
36
+ * '0xc3a1428c04c426cdf513c6fc8e09f55ddaf50cd7'
37
+ * ]);
38
+ * ```
39
+ */
40
+ async getAvatarInfoBatch(addresses) {
41
+ if (addresses.length === 0) {
42
+ return [];
43
+ }
44
+ const normalizedAddresses = addresses.map(addr => normalizeAddress(addr));
45
+ const result = await this.client.call('circles_getAvatarInfoBatch', [normalizedAddresses]);
46
+ return checksumAddresses(result);
47
+ }
48
+ /**
49
+ * Download a full snapshot of the Circles network state
50
+ * (current trust relations and balances)
51
+ *
52
+ * @returns Network snapshot with trust relations and balances
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * const snapshot = await rpc.avatar.getNetworkSnapshot();
57
+ * console.log(snapshot);
58
+ * ```
59
+ */
60
+ async getNetworkSnapshot() {
61
+ const result = await this.client.call('circles_getNetworkSnapshot', []);
62
+ return checksumAddresses(result);
63
+ }
64
+ }
@@ -0,0 +1,37 @@
1
+ import type { RpcClient } from '../client';
2
+ import type { Address, TokenBalance } from '@aboutcircles/sdk-types';
3
+ /**
4
+ * Balance query RPC methods
5
+ */
6
+ export declare class BalanceMethods {
7
+ private client;
8
+ constructor(client: RpcClient);
9
+ /**
10
+ * Get the total v2 Circles balance of an account
11
+ *
12
+ * @param address - The avatar address to query
13
+ * @param asTimeCircles - Whether to return balance as TimeCircles (default: true)
14
+ * @returns The total v2 balance in attoCircles (10^18 per Circle) as bigint
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const balance = await rpc.balance.getTotalBalance('0xcadd4ea3bcc361fc4af2387937d7417be8d7dfc2');
19
+ * console.log(balance); // 1000000000000000000n (1 Circle in attoCircles)
20
+ * ```
21
+ */
22
+ getTotalBalance(address: Address, asTimeCircles?: boolean): Promise<bigint>;
23
+ /**
24
+ * Query the balance breakdown of a specific avatar address
25
+ *
26
+ * @param address - The avatar address to query
27
+ * @returns Array of token balances (amounts as bigint)
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const balances = await rpc.balance.getTokenBalances('0x7cadf434b692ca029d950607a4b3f139c30d4e98');
32
+ * console.log(balances);
33
+ * ```
34
+ */
35
+ getTokenBalances(address: Address): Promise<TokenBalance[]>;
36
+ }
37
+ //# sourceMappingURL=balance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"balance.d.ts","sourceRoot":"","sources":["../../src/methods/balance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAIrE;;GAEG;AACH,qBAAa,cAAc;IACb,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,SAAS;IAErC;;;;;;;;;;;;OAYG;IACG,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,aAAa,GAAE,OAAc,GAAG,OAAO,CAAC,MAAM,CAAC;IAQvF;;;;;;;;;;;OAWG;IACG,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;CAOlE"}
@@ -0,0 +1,50 @@
1
+ import { normalizeAddress, parseStringsToBigInt, checksumAddresses } from '../utils';
2
+ import { CirclesConverter } from '@aboutcircles/sdk-utils';
3
+ /**
4
+ * Balance query RPC methods
5
+ */
6
+ export class BalanceMethods {
7
+ client;
8
+ constructor(client) {
9
+ this.client = client;
10
+ }
11
+ /**
12
+ * Get the total v2 Circles balance of an account
13
+ *
14
+ * @param address - The avatar address to query
15
+ * @param asTimeCircles - Whether to return balance as TimeCircles (default: true)
16
+ * @returns The total v2 balance in attoCircles (10^18 per Circle) as bigint
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const balance = await rpc.balance.getTotalBalance('0xcadd4ea3bcc361fc4af2387937d7417be8d7dfc2');
21
+ * console.log(balance); // 1000000000000000000n (1 Circle in attoCircles)
22
+ * ```
23
+ */
24
+ async getTotalBalance(address, asTimeCircles = true) {
25
+ const result = await this.client.call('circlesV2_getTotalBalance', [
26
+ normalizeAddress(address),
27
+ asTimeCircles,
28
+ ]);
29
+ return CirclesConverter.circlesToAttoCircles(result);
30
+ }
31
+ /**
32
+ * Query the balance breakdown of a specific avatar address
33
+ *
34
+ * @param address - The avatar address to query
35
+ * @returns Array of token balances (amounts as bigint)
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const balances = await rpc.balance.getTokenBalances('0x7cadf434b692ca029d950607a4b3f139c30d4e98');
40
+ * console.log(balances);
41
+ * ```
42
+ */
43
+ async getTokenBalances(address) {
44
+ const result = await this.client.call('circles_getTokenBalances', [
45
+ normalizeAddress(address),
46
+ ]);
47
+ const parsed = result.map(item => parseStringsToBigInt(item));
48
+ return checksumAddresses(parsed);
49
+ }
50
+ }
@@ -0,0 +1,145 @@
1
+ import type { RpcClient } from '../client';
2
+ import type { Address, GroupRow, GroupMembershipRow, GroupQueryParams } from '@aboutcircles/sdk-types';
3
+ import type { GroupTokenHolderRow } from '../types';
4
+ import { PagedQuery } from '../pagedQuery';
5
+ /**
6
+ * Group query RPC methods
7
+ */
8
+ export declare class GroupMethods {
9
+ private client;
10
+ constructor(client: RpcClient);
11
+ /**
12
+ * Find groups with optional filters
13
+ *
14
+ * This is a convenience method that fetches all pages using cursor-based pagination
15
+ * and returns the combined results up to the specified limit.
16
+ *
17
+ * @param limit - Maximum number of groups to return (default: 50)
18
+ * @param params - Optional query parameters to filter groups
19
+ * @returns Array of group rows
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * // Find all groups
24
+ * const allGroups = await rpc.group.findGroups(50);
25
+ *
26
+ * // Find groups by name prefix
27
+ * const groups = await rpc.group.findGroups(50, {
28
+ * nameStartsWith: 'Community'
29
+ * });
30
+ *
31
+ * // Find groups by owner (single)
32
+ * const myGroups = await rpc.group.findGroups(50, {
33
+ * ownerIn: ['0xde374ece6fa50e781e81aac78e811b33d16912c7']
34
+ * });
35
+ *
36
+ * // Find groups by multiple owners (OR query)
37
+ * const multiOwnerGroups = await rpc.group.findGroups(50, {
38
+ * ownerIn: ['0xOwner1...', '0xOwner2...']
39
+ * });
40
+ * ```
41
+ */
42
+ findGroups(limit?: number, params?: GroupQueryParams): Promise<GroupRow[]>;
43
+ /**
44
+ * Get group memberships for an avatar using cursor-based pagination
45
+ *
46
+ * @param avatar - Avatar address to query group memberships for
47
+ * @param limit - Number of memberships per page (default: 50)
48
+ * @param sortOrder - Sort order for results (default: 'DESC')
49
+ * @returns PagedQuery instance for iterating through memberships
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * const query = rpc.group.getGroupMemberships(
54
+ * '0xde374ece6fa50e781e81aac78e811b33d16912c7',
55
+ * 50
56
+ * );
57
+ * await query.queryNextPage();
58
+ * console.log(query.currentPage.results);
59
+ * ```
60
+ */
61
+ getGroupMemberships(avatar: Address, limit?: number, sortOrder?: 'ASC' | 'DESC'): PagedQuery<GroupMembershipRow>;
62
+ /**
63
+ * Get holders of a group token using cursor-based pagination
64
+ *
65
+ * Returns a PagedQuery instance that can be used to fetch holders page by page.
66
+ * Results are ordered by totalBalance DESC (highest first), with holder address as tie-breaker.
67
+ *
68
+ * Note: Pagination uses holder address as cursor because totalBalance (BigInt) values
69
+ * cannot be reliably passed through JSON-RPC filters. This means pagination boundaries
70
+ * are based on holder addresses, not balances.
71
+ *
72
+ * @param groupAddress - The address of the group token
73
+ * @param limit - Number of holders per page (default: 100)
74
+ * @returns PagedQuery instance for iterating through group token holders
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * const query = rpc.group.getGroupHolders('0xGroupAddress...', 50);
79
+ *
80
+ * // Get first page (ordered by totalBalance DESC)
81
+ * await query.queryNextPage();
82
+ * console.log(query.currentPage.results[0]); // Holder with highest balance
83
+ *
84
+ * // Get next page if available
85
+ * if (query.currentPage.hasMore) {
86
+ * await query.queryNextPage();
87
+ * }
88
+ * ```
89
+ */
90
+ getGroupHolders(groupAddress: Address, limit?: number): PagedQuery<GroupTokenHolderRow>;
91
+ /**
92
+ * Get members of a group using cursor-based pagination
93
+ *
94
+ * Returns a PagedQuery instance that can be used to fetch members page by page
95
+ * using cursor-based pagination.
96
+ *
97
+ * @param groupAddress - The address of the group to query members for
98
+ * @param limit - Number of members per page (default: 100)
99
+ * @param sortOrder - Sort order for results (default: 'DESC')
100
+ * @returns PagedQuery instance for iterating through group members
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * const query = rpc.group.getGroupMembers('0xGroupAddress...', 100);
105
+ *
106
+ * // Get first page
107
+ * await query.queryNextPage();
108
+ * console.log(query.currentPage.results);
109
+ *
110
+ * // Get next page if available
111
+ * if (query.currentPage.hasMore) {
112
+ * await query.queryNextPage();
113
+ * console.log(query.currentPage.results);
114
+ * }
115
+ * ```
116
+ */
117
+ getGroupMembers(groupAddress: Address, limit?: number, sortOrder?: 'ASC' | 'DESC'): PagedQuery<GroupMembershipRow>;
118
+ /**
119
+ * Get groups using cursor-based pagination
120
+ *
121
+ * Returns a PagedQuery instance that can be used to fetch groups page by page
122
+ * using cursor-based pagination.
123
+ *
124
+ * @param limit - Number of groups per page (default: 50)
125
+ * @param params - Optional query parameters to filter groups
126
+ * @param sortOrder - Sort order for results (default: 'DESC')
127
+ * @returns PagedQuery instance for iterating through groups
128
+ *
129
+ * @example
130
+ * ```typescript
131
+ * // Query all groups
132
+ * const query = rpc.group.getGroups(50);
133
+ *
134
+ * // Query groups by owner(s)
135
+ * const myGroupsQuery = rpc.group.getGroups(50, {
136
+ * ownerIn: ['0xMyAddress...']
137
+ * });
138
+ *
139
+ * await myGroupsQuery.queryNextPage();
140
+ * console.log(myGroupsQuery.currentPage.results);
141
+ * ```
142
+ */
143
+ getGroups(limit?: number, params?: GroupQueryParams, sortOrder?: 'ASC' | 'DESC'): PagedQuery<GroupRow>;
144
+ }
145
+ //# sourceMappingURL=group.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../../src/methods/group.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,gBAAgB,EAAU,MAAM,yBAAyB,CAAC;AAC/G,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEpD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C;;GAEG;AACH,qBAAa,YAAY;IACX,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,SAAS;IAErC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACG,UAAU,CACd,KAAK,GAAE,MAAW,EAClB,MAAM,CAAC,EAAE,gBAAgB,GACxB,OAAO,CAAC,QAAQ,EAAE,CAAC;IAwBtB;;;;;;;;;;;;;;;;;OAiBG;IACH,mBAAmB,CACjB,MAAM,EAAE,OAAO,EACf,KAAK,GAAE,MAAW,EAClB,SAAS,GAAE,KAAK,GAAG,MAAe,GACjC,UAAU,CAAC,kBAAkB,CAAC;IAiCjC;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,eAAe,CACb,YAAY,EAAE,OAAO,EACrB,KAAK,GAAE,MAAY,GAClB,UAAU,CAAC,mBAAmB,CAAC;IAuClC;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,eAAe,CACb,YAAY,EAAE,OAAO,EACrB,KAAK,GAAE,MAAY,EACnB,SAAS,GAAE,KAAK,GAAG,MAAe,GACjC,UAAU,CAAC,kBAAkB,CAAC;IAiCjC;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,SAAS,CACP,KAAK,GAAE,MAAW,EAClB,MAAM,CAAC,EAAE,gBAAgB,EACzB,SAAS,GAAE,KAAK,GAAG,MAAe,GACjC,UAAU,CAAC,QAAQ,CAAC;CAiJxB"}