@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,103 @@
1
+ /**
2
+ * Helper to convert hex string to bigint
3
+ */
4
+ const hexToBigInt = (hex) => BigInt(hex);
5
+ /**
6
+ * Helper to convert hex string to number
7
+ */
8
+ const hexToNumber = (hex) => parseInt(hex, 16);
9
+ /**
10
+ * Helper to convert hex string to Uint8Array
11
+ */
12
+ const hexToUint8Array = (hex) => {
13
+ if (hex.startsWith('0x')) {
14
+ hex = hex.slice(2);
15
+ }
16
+ if (hex.length % 2 !== 0) {
17
+ throw new Error('Invalid hex string');
18
+ }
19
+ const array = new Uint8Array(hex.length / 2);
20
+ for (let i = 0; i < hex.length; i += 2) {
21
+ array[i / 2] = parseInt(hex.substr(i, 2), 16);
22
+ }
23
+ return array;
24
+ };
25
+ /**
26
+ * Smart value parser - tries to infer the best type for a hex value
27
+ */
28
+ function parseValue(key, value) {
29
+ // Check if it's a hex string
30
+ if (typeof value === 'string' && value.startsWith('0x')) {
31
+ const hex = value.slice(2);
32
+ // If it's 40 chars (20 bytes), it's likely an address
33
+ if (hex.length === 40) {
34
+ return value; // Return as address string
35
+ }
36
+ // If it's 64 chars (32 bytes), could be bytes32 or uint256
37
+ if (hex.length === 64) {
38
+ // Names like 'metadataDigest', 'cidV0Digest', 'data' are likely bytes
39
+ if (key.toLowerCase().includes('digest') ||
40
+ key.toLowerCase().includes('data') ||
41
+ key.toLowerCase().includes('bytes')) {
42
+ return hexToUint8Array(value);
43
+ }
44
+ // Otherwise treat as uint256
45
+ try {
46
+ return hexToBigInt(value);
47
+ }
48
+ catch {
49
+ return value;
50
+ }
51
+ }
52
+ // For other hex values, try to parse as number/bigint
53
+ try {
54
+ const num = hexToNumber(value);
55
+ // If it's small enough, return as number
56
+ if (num < Number.MAX_SAFE_INTEGER) {
57
+ return num;
58
+ }
59
+ // Otherwise return as bigint
60
+ return hexToBigInt(value);
61
+ }
62
+ catch {
63
+ return value;
64
+ }
65
+ }
66
+ // Boolean values
67
+ if (value === 'true')
68
+ return true;
69
+ if (value === 'false')
70
+ return false;
71
+ // Return as-is for other values
72
+ return value;
73
+ }
74
+ /**
75
+ * Parse a single RPC subscription event into a CirclesEvent
76
+ */
77
+ export function parseRpcEvent(rpcEvent) {
78
+ const { event, values } = rpcEvent;
79
+ // Parse the base event fields
80
+ const circlesEvent = {
81
+ $event: event, // Will be typed as CirclesEventType
82
+ blockNumber: values.blockNumber ? hexToNumber(values.blockNumber) : 0,
83
+ timestamp: values.timestamp ? hexToNumber(values.timestamp) : undefined,
84
+ transactionIndex: values.transactionIndex ? hexToNumber(values.transactionIndex) : 0,
85
+ logIndex: values.logIndex ? hexToNumber(values.logIndex) : 0,
86
+ transactionHash: values.transactionHash,
87
+ };
88
+ // Parse all other fields dynamically
89
+ for (const [key, value] of Object.entries(values)) {
90
+ // Skip base fields we already processed
91
+ if (['blockNumber', 'timestamp', 'transactionIndex', 'logIndex', 'transactionHash'].includes(key)) {
92
+ continue;
93
+ }
94
+ circlesEvent[key] = parseValue(key, value);
95
+ }
96
+ return circlesEvent;
97
+ }
98
+ /**
99
+ * Parse an array of RPC subscription events
100
+ */
101
+ export function parseRpcSubscriptionMessage(message) {
102
+ return message.map(parseRpcEvent);
103
+ }
@@ -0,0 +1,7 @@
1
+ import type { CirclesEvent } from '@aboutcircles/sdk-types';
2
+ /**
3
+ * Type guard to check if an object is a CirclesEvent
4
+ */
5
+ export declare function isCirclesEvent(obj: any): obj is CirclesEvent;
6
+ export type { CirclesBaseEvent, CirclesEventType, CirclesEvent, CirclesEventOfType, RpcSubscriptionEvent } from '@aboutcircles/sdk-types';
7
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/events/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE5D;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,YAAY,CAS5D;AAGD,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,YAAY,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Type guard to check if an object is a CirclesEvent
3
+ */
4
+ export function isCirclesEvent(obj) {
5
+ return (obj &&
6
+ typeof obj === 'object' &&
7
+ typeof obj.$event === 'string' &&
8
+ typeof obj.blockNumber === 'number' &&
9
+ typeof obj.transactionIndex === 'number' &&
10
+ typeof obj.logIndex === 'number');
11
+ }
@@ -0,0 +1,12 @@
1
+ export { CirclesRpc } from './rpc';
2
+ export { RpcClient } from './client';
3
+ export { PathfinderMethods, QueryMethods, TrustMethods, BalanceMethods, AvatarMethods, ProfileMethods, TokenMethods, InvitationMethods, TransactionMethods, GroupMethods, } from './methods';
4
+ export type { TransactionHistoryRow, SearchResultProfile, GroupTokenHolderRow, CursorColumn, FlexiblePagedResult, } from './types';
5
+ export type { TrustRelationType, AggregatedTrustRelation } from '@aboutcircles/sdk-types';
6
+ export { RpcError } from './errors';
7
+ export type { RpcErrorSource } from './errors';
8
+ export { normalizeAddress, normalizeAddresses, parseStringsToBigInt } from './utils';
9
+ export { PagedQuery } from './pagedQuery';
10
+ export { Observable, parseRpcEvent, parseRpcSubscriptionMessage, isCirclesEvent, } from './events';
11
+ export type { CirclesEvent, CirclesEventType, CirclesBaseEvent, CirclesEventOfType, RpcSubscriptionEvent, } from './events';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAGnC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAGrC,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,aAAa,EACb,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,GACb,MAAM,WAAW,CAAC;AAGnB,YAAY,EACV,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,GACpB,MAAM,SAAS,CAAC;AAGjB,YAAY,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAG1F,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG/C,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAGrF,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,OAAO,EACL,UAAU,EACV,aAAa,EACb,2BAA2B,EAC3B,cAAc,GACf,MAAM,UAAU,CAAC;AAElB,YAAY,EACV,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,UAAU,CAAC"}