@aa-sdk/core 4.21.0 → 4.23.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 (97) hide show
  1. package/dist/esm/actions/smartAccount/buildUserOperation.d.ts +3 -3
  2. package/dist/esm/actions/smartAccount/buildUserOperation.js +7 -3
  3. package/dist/esm/actions/smartAccount/buildUserOperation.js.map +1 -1
  4. package/dist/esm/actions/smartAccount/buildUserOperationFromTx.d.ts +2 -2
  5. package/dist/esm/actions/smartAccount/buildUserOperationFromTx.js +4 -2
  6. package/dist/esm/actions/smartAccount/buildUserOperationFromTx.js.map +1 -1
  7. package/dist/esm/actions/smartAccount/buildUserOperationFromTxs.d.ts +2 -2
  8. package/dist/esm/actions/smartAccount/buildUserOperationFromTxs.js +4 -2
  9. package/dist/esm/actions/smartAccount/buildUserOperationFromTxs.js.map +1 -1
  10. package/dist/esm/actions/smartAccount/checkGasSponsorshipEligibility.d.ts +2 -2
  11. package/dist/esm/actions/smartAccount/checkGasSponsorshipEligibility.js +4 -2
  12. package/dist/esm/actions/smartAccount/checkGasSponsorshipEligibility.js.map +1 -1
  13. package/dist/esm/actions/smartAccount/dropAndReplaceUserOperation.d.ts +2 -2
  14. package/dist/esm/actions/smartAccount/dropAndReplaceUserOperation.js +4 -2
  15. package/dist/esm/actions/smartAccount/dropAndReplaceUserOperation.js.map +1 -1
  16. package/dist/esm/actions/smartAccount/estimateUserOperationGas.d.ts +2 -2
  17. package/dist/esm/actions/smartAccount/estimateUserOperationGas.js +4 -2
  18. package/dist/esm/actions/smartAccount/estimateUserOperationGas.js.map +1 -1
  19. package/dist/esm/actions/smartAccount/sendTransaction.d.ts +2 -2
  20. package/dist/esm/actions/smartAccount/sendTransaction.js +4 -2
  21. package/dist/esm/actions/smartAccount/sendTransaction.js.map +1 -1
  22. package/dist/esm/actions/smartAccount/sendTransactions.d.ts +2 -2
  23. package/dist/esm/actions/smartAccount/sendTransactions.js +4 -2
  24. package/dist/esm/actions/smartAccount/sendTransactions.js.map +1 -1
  25. package/dist/esm/actions/smartAccount/sendUserOperation.d.ts +2 -2
  26. package/dist/esm/actions/smartAccount/sendUserOperation.js +4 -2
  27. package/dist/esm/actions/smartAccount/sendUserOperation.js.map +1 -1
  28. package/dist/esm/actions/smartAccount/upgradeAccount.js +3 -1
  29. package/dist/esm/actions/smartAccount/upgradeAccount.js.map +1 -1
  30. package/dist/esm/actions/smartAccount/waitForUserOperationTransacation.d.ts +1 -1
  31. package/dist/esm/actions/smartAccount/waitForUserOperationTransacation.js +4 -2
  32. package/dist/esm/actions/smartAccount/waitForUserOperationTransacation.js.map +1 -1
  33. package/dist/esm/client/addBreadcrumb.d.ts +13 -0
  34. package/dist/esm/client/addBreadcrumb.js +22 -0
  35. package/dist/esm/client/addBreadcrumb.js.map +1 -0
  36. package/dist/esm/client/smartAccountClient.d.ts +9 -0
  37. package/dist/esm/client/smartAccountClient.js +14 -4
  38. package/dist/esm/client/smartAccountClient.js.map +1 -1
  39. package/dist/esm/index.d.ts +2 -0
  40. package/dist/esm/index.js +2 -0
  41. package/dist/esm/index.js.map +1 -1
  42. package/dist/esm/utils/traceHeader.d.ts +82 -0
  43. package/dist/esm/utils/traceHeader.js +145 -0
  44. package/dist/esm/utils/traceHeader.js.map +1 -0
  45. package/dist/esm/utils/userop.js +4 -4
  46. package/dist/esm/utils/userop.js.map +1 -1
  47. package/dist/esm/version.d.ts +1 -1
  48. package/dist/esm/version.js +1 -1
  49. package/dist/esm/version.js.map +1 -1
  50. package/dist/types/actions/smartAccount/buildUserOperation.d.ts +3 -3
  51. package/dist/types/actions/smartAccount/buildUserOperation.d.ts.map +1 -1
  52. package/dist/types/actions/smartAccount/buildUserOperationFromTx.d.ts +2 -2
  53. package/dist/types/actions/smartAccount/buildUserOperationFromTx.d.ts.map +1 -1
  54. package/dist/types/actions/smartAccount/buildUserOperationFromTxs.d.ts +2 -2
  55. package/dist/types/actions/smartAccount/buildUserOperationFromTxs.d.ts.map +1 -1
  56. package/dist/types/actions/smartAccount/checkGasSponsorshipEligibility.d.ts +2 -2
  57. package/dist/types/actions/smartAccount/checkGasSponsorshipEligibility.d.ts.map +1 -1
  58. package/dist/types/actions/smartAccount/dropAndReplaceUserOperation.d.ts +2 -2
  59. package/dist/types/actions/smartAccount/dropAndReplaceUserOperation.d.ts.map +1 -1
  60. package/dist/types/actions/smartAccount/estimateUserOperationGas.d.ts +2 -2
  61. package/dist/types/actions/smartAccount/estimateUserOperationGas.d.ts.map +1 -1
  62. package/dist/types/actions/smartAccount/sendTransaction.d.ts +2 -2
  63. package/dist/types/actions/smartAccount/sendTransaction.d.ts.map +1 -1
  64. package/dist/types/actions/smartAccount/sendTransactions.d.ts +2 -2
  65. package/dist/types/actions/smartAccount/sendTransactions.d.ts.map +1 -1
  66. package/dist/types/actions/smartAccount/sendUserOperation.d.ts +2 -2
  67. package/dist/types/actions/smartAccount/sendUserOperation.d.ts.map +1 -1
  68. package/dist/types/actions/smartAccount/upgradeAccount.d.ts.map +1 -1
  69. package/dist/types/actions/smartAccount/waitForUserOperationTransacation.d.ts +1 -1
  70. package/dist/types/actions/smartAccount/waitForUserOperationTransacation.d.ts.map +1 -1
  71. package/dist/types/client/addBreadcrumb.d.ts +14 -0
  72. package/dist/types/client/addBreadcrumb.d.ts.map +1 -0
  73. package/dist/types/client/smartAccountClient.d.ts +9 -0
  74. package/dist/types/client/smartAccountClient.d.ts.map +1 -1
  75. package/dist/types/index.d.ts +2 -0
  76. package/dist/types/index.d.ts.map +1 -1
  77. package/dist/types/utils/traceHeader.d.ts +83 -0
  78. package/dist/types/utils/traceHeader.d.ts.map +1 -0
  79. package/dist/types/version.d.ts +1 -1
  80. package/package.json +2 -2
  81. package/src/actions/smartAccount/buildUserOperation.ts +7 -4
  82. package/src/actions/smartAccount/buildUserOperationFromTx.ts +4 -2
  83. package/src/actions/smartAccount/buildUserOperationFromTxs.ts +4 -2
  84. package/src/actions/smartAccount/checkGasSponsorshipEligibility.ts +4 -2
  85. package/src/actions/smartAccount/dropAndReplaceUserOperation.ts +4 -2
  86. package/src/actions/smartAccount/estimateUserOperationGas.ts +4 -2
  87. package/src/actions/smartAccount/sendTransaction.ts +4 -2
  88. package/src/actions/smartAccount/sendTransactions.ts +4 -2
  89. package/src/actions/smartAccount/sendUserOperation.ts +4 -2
  90. package/src/actions/smartAccount/upgradeAccount.ts +3 -1
  91. package/src/actions/smartAccount/waitForUserOperationTransacation.ts +4 -2
  92. package/src/client/addBreadcrumb.ts +25 -0
  93. package/src/client/smartAccountClient.ts +23 -3
  94. package/src/index.ts +6 -0
  95. package/src/utils/traceHeader.ts +151 -0
  96. package/src/utils/userop.ts +4 -4
  97. package/src/version.ts +1 -1
@@ -0,0 +1,151 @@
1
+ function generateRandomHexString(numBytes: number) {
2
+ const hexPairs = new Array(numBytes).fill(0).map(() =>
3
+ Math.floor(Math.random() * 16)
4
+ .toString(16)
5
+ .padStart(2, "0")
6
+ );
7
+ return hexPairs.join("");
8
+ }
9
+
10
+ /**
11
+ * These are the headers that are used in the trace headers, could be found in the spec
12
+ *
13
+ * @see https://www.w3.org/TR/trace-context/#design-overview
14
+ */
15
+
16
+ export const TRACE_HEADER_NAME = "traceparent";
17
+ /**
18
+ * These are the headers that are used in the trace headers, could be found in the spec
19
+ *
20
+ * @see https://www.w3.org/TR/trace-context/#design-overview
21
+ */
22
+ export const TRACE_HEADER_STATE = "tracestate";
23
+
24
+ const clientTraceId = generateRandomHexString(16);
25
+ /**
26
+ * Some tools that are useful when dealing with the values
27
+ * of the trace header. Follows the W3C trace context standard.
28
+ *
29
+ * @see https://www.w3.org/TR/trace-context/
30
+ */
31
+ export class TraceHeader {
32
+ readonly traceId: string;
33
+ readonly parentId: string;
34
+ readonly traceFlags: string;
35
+ readonly traceState: Record<string, string>;
36
+
37
+ /**
38
+ * Initializes a new instance with the provided trace identifiers and state information.
39
+ *
40
+ * @param {string} traceId The unique identifier for the trace
41
+ * @param {string} parentId The identifier of the parent trace
42
+ * @param {string} traceFlags Flags containing trace-related options
43
+ * @param {TraceHeader["traceState"]} traceState The trace state information for additional trace context
44
+ */
45
+ constructor(
46
+ traceId: string,
47
+ parentId: string,
48
+ traceFlags: string,
49
+ traceState: TraceHeader["traceState"]
50
+ ) {
51
+ this.traceId = traceId;
52
+ this.parentId = parentId;
53
+ this.traceFlags = traceFlags;
54
+ this.traceState = traceState;
55
+ }
56
+
57
+ /**
58
+ * Creating a default trace id that is a random setup for both trace id and parent id
59
+ *
60
+ * @example ```ts
61
+ * const traceHeader = TraceHeader.fromTraceHeader(headers) || TraceHeader.default();
62
+ * ```
63
+ *
64
+ * @returns {TraceHeader} A default trace header
65
+ */
66
+ static default() {
67
+ return new TraceHeader(
68
+ clientTraceId,
69
+ generateRandomHexString(8),
70
+ "00", //Means no flag have been set, and no sampled state https://www.w3.org/TR/trace-context/#trace-flags
71
+ {}
72
+ );
73
+ }
74
+ /**
75
+ * Should be able to consume a trace header from the headers of an http request
76
+ *
77
+ * @example ```ts
78
+ * const traceHeader = TraceHeader.fromTraceHeader(headers);
79
+ * ```
80
+ *
81
+ * @param {Record<string,string>} headers The headers from the http request
82
+ * @returns {TraceHeader | undefined} The trace header object, or nothing if not found
83
+ */
84
+ static fromTraceHeader(
85
+ headers: Record<string, string>
86
+ ): TraceHeader | undefined {
87
+ if (!headers[TRACE_HEADER_NAME]) {
88
+ return undefined;
89
+ }
90
+ const [version, traceId, parentId, traceFlags] =
91
+ headers[TRACE_HEADER_NAME]?.split("-");
92
+
93
+ const traceState =
94
+ headers[TRACE_HEADER_STATE]?.split(",").reduce((acc, curr) => {
95
+ const [key, value] = curr.split("=");
96
+ acc[key] = value;
97
+ return acc;
98
+ }, {} as Record<string, string>) || {};
99
+ if (version !== "00") {
100
+ console.debug(
101
+ new Error(
102
+ `Invalid version for traceheader: ${headers[TRACE_HEADER_NAME]}`
103
+ )
104
+ );
105
+ return undefined;
106
+ }
107
+ return new TraceHeader(traceId, parentId, traceFlags, traceState);
108
+ }
109
+
110
+ /**
111
+ * Should be able to convert the trace header to the format that is used in the headers of an http request
112
+ *
113
+ * @example ```ts
114
+ * const traceHeader = TraceHeader.fromTraceHeader(headers) || TraceHeader.default();
115
+ * const headers = traceHeader.toTraceHeader();
116
+ * ```
117
+ *
118
+ * @returns {{traceparent: string, tracestate: string}} The trace header in the format of a record, used in our http client
119
+ */
120
+ toTraceHeader() {
121
+ return {
122
+ [TRACE_HEADER_NAME]: `00-${this.traceId}-${this.parentId}-${this.traceFlags}`,
123
+ [TRACE_HEADER_STATE]: Object.entries(this.traceState)
124
+ .map(([key, value]) => `${key}=${value}`)
125
+ .join(","),
126
+ } as const;
127
+ }
128
+
129
+ /**
130
+ * Should be able to create a new trace header with a new event in the trace state,
131
+ * as the key of the eventName as breadcrumbs appending onto previous breadcrumbs with the - infix if exists. And the
132
+ * trace parent gets updated as according to the docs
133
+ *
134
+ * @example ```ts
135
+ * const traceHeader = TraceHeader.fromTraceHeader(headers) || TraceHeader.default();
136
+ * const newTraceHeader = traceHeader.withEvent("newEvent");
137
+ * ```
138
+ *
139
+ * @param {string} eventName The key of the new event
140
+ * @returns {TraceHeader} The new trace header
141
+ */
142
+ withEvent(eventName: string): TraceHeader {
143
+ const breadcrumbs = this.traceState.breadcrumbs
144
+ ? `${this.traceState.breadcrumbs}-${eventName}`
145
+ : eventName;
146
+ return new TraceHeader(this.traceId, this.parentId, this.traceFlags, {
147
+ ...this.traceState,
148
+ breadcrumbs,
149
+ });
150
+ }
151
+ }
@@ -26,10 +26,10 @@ export function isValidRequest<
26
26
  ): request is UserOperationRequest<TEntryPointVersion> {
27
27
  // These are the only ones marked as optional in the interface above
28
28
  return (
29
- BigInt(request.callGasLimit || 0n) > 0n &&
30
- BigInt(request.maxFeePerGas || 0n) > 0n &&
31
- BigInt(request.preVerificationGas || 0n) > 0n &&
32
- BigInt(request.verificationGasLimit || 0n) > 0n &&
29
+ request.callGasLimit != null &&
30
+ request.preVerificationGas != null &&
31
+ request.verificationGasLimit != null &&
32
+ request.maxFeePerGas != null &&
33
33
  request.maxPriorityFeePerGas != null &&
34
34
  isValidPaymasterAndData(request) &&
35
35
  isValidFactoryAndData(request)
package/src/version.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  // This file is autogenerated by inject-version.ts. Any changes will be
2
2
  // overwritten on commit!
3
- export const VERSION = "4.21.0";
3
+ export const VERSION = "4.23.0";