@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.
- package/dist/esm/actions/smartAccount/buildUserOperation.d.ts +3 -3
- package/dist/esm/actions/smartAccount/buildUserOperation.js +7 -3
- package/dist/esm/actions/smartAccount/buildUserOperation.js.map +1 -1
- package/dist/esm/actions/smartAccount/buildUserOperationFromTx.d.ts +2 -2
- package/dist/esm/actions/smartAccount/buildUserOperationFromTx.js +4 -2
- package/dist/esm/actions/smartAccount/buildUserOperationFromTx.js.map +1 -1
- package/dist/esm/actions/smartAccount/buildUserOperationFromTxs.d.ts +2 -2
- package/dist/esm/actions/smartAccount/buildUserOperationFromTxs.js +4 -2
- package/dist/esm/actions/smartAccount/buildUserOperationFromTxs.js.map +1 -1
- package/dist/esm/actions/smartAccount/checkGasSponsorshipEligibility.d.ts +2 -2
- package/dist/esm/actions/smartAccount/checkGasSponsorshipEligibility.js +4 -2
- package/dist/esm/actions/smartAccount/checkGasSponsorshipEligibility.js.map +1 -1
- package/dist/esm/actions/smartAccount/dropAndReplaceUserOperation.d.ts +2 -2
- package/dist/esm/actions/smartAccount/dropAndReplaceUserOperation.js +4 -2
- package/dist/esm/actions/smartAccount/dropAndReplaceUserOperation.js.map +1 -1
- package/dist/esm/actions/smartAccount/estimateUserOperationGas.d.ts +2 -2
- package/dist/esm/actions/smartAccount/estimateUserOperationGas.js +4 -2
- package/dist/esm/actions/smartAccount/estimateUserOperationGas.js.map +1 -1
- package/dist/esm/actions/smartAccount/sendTransaction.d.ts +2 -2
- package/dist/esm/actions/smartAccount/sendTransaction.js +4 -2
- package/dist/esm/actions/smartAccount/sendTransaction.js.map +1 -1
- package/dist/esm/actions/smartAccount/sendTransactions.d.ts +2 -2
- package/dist/esm/actions/smartAccount/sendTransactions.js +4 -2
- package/dist/esm/actions/smartAccount/sendTransactions.js.map +1 -1
- package/dist/esm/actions/smartAccount/sendUserOperation.d.ts +2 -2
- package/dist/esm/actions/smartAccount/sendUserOperation.js +4 -2
- package/dist/esm/actions/smartAccount/sendUserOperation.js.map +1 -1
- package/dist/esm/actions/smartAccount/upgradeAccount.js +3 -1
- package/dist/esm/actions/smartAccount/upgradeAccount.js.map +1 -1
- package/dist/esm/actions/smartAccount/waitForUserOperationTransacation.d.ts +1 -1
- package/dist/esm/actions/smartAccount/waitForUserOperationTransacation.js +4 -2
- package/dist/esm/actions/smartAccount/waitForUserOperationTransacation.js.map +1 -1
- package/dist/esm/client/addBreadcrumb.d.ts +13 -0
- package/dist/esm/client/addBreadcrumb.js +22 -0
- package/dist/esm/client/addBreadcrumb.js.map +1 -0
- package/dist/esm/client/smartAccountClient.d.ts +9 -0
- package/dist/esm/client/smartAccountClient.js +14 -4
- package/dist/esm/client/smartAccountClient.js.map +1 -1
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/traceHeader.d.ts +82 -0
- package/dist/esm/utils/traceHeader.js +145 -0
- package/dist/esm/utils/traceHeader.js.map +1 -0
- package/dist/esm/utils/userop.js +4 -4
- package/dist/esm/utils/userop.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/types/actions/smartAccount/buildUserOperation.d.ts +3 -3
- package/dist/types/actions/smartAccount/buildUserOperation.d.ts.map +1 -1
- package/dist/types/actions/smartAccount/buildUserOperationFromTx.d.ts +2 -2
- package/dist/types/actions/smartAccount/buildUserOperationFromTx.d.ts.map +1 -1
- package/dist/types/actions/smartAccount/buildUserOperationFromTxs.d.ts +2 -2
- package/dist/types/actions/smartAccount/buildUserOperationFromTxs.d.ts.map +1 -1
- package/dist/types/actions/smartAccount/checkGasSponsorshipEligibility.d.ts +2 -2
- package/dist/types/actions/smartAccount/checkGasSponsorshipEligibility.d.ts.map +1 -1
- package/dist/types/actions/smartAccount/dropAndReplaceUserOperation.d.ts +2 -2
- package/dist/types/actions/smartAccount/dropAndReplaceUserOperation.d.ts.map +1 -1
- package/dist/types/actions/smartAccount/estimateUserOperationGas.d.ts +2 -2
- package/dist/types/actions/smartAccount/estimateUserOperationGas.d.ts.map +1 -1
- package/dist/types/actions/smartAccount/sendTransaction.d.ts +2 -2
- package/dist/types/actions/smartAccount/sendTransaction.d.ts.map +1 -1
- package/dist/types/actions/smartAccount/sendTransactions.d.ts +2 -2
- package/dist/types/actions/smartAccount/sendTransactions.d.ts.map +1 -1
- package/dist/types/actions/smartAccount/sendUserOperation.d.ts +2 -2
- package/dist/types/actions/smartAccount/sendUserOperation.d.ts.map +1 -1
- package/dist/types/actions/smartAccount/upgradeAccount.d.ts.map +1 -1
- package/dist/types/actions/smartAccount/waitForUserOperationTransacation.d.ts +1 -1
- package/dist/types/actions/smartAccount/waitForUserOperationTransacation.d.ts.map +1 -1
- package/dist/types/client/addBreadcrumb.d.ts +14 -0
- package/dist/types/client/addBreadcrumb.d.ts.map +1 -0
- package/dist/types/client/smartAccountClient.d.ts +9 -0
- package/dist/types/client/smartAccountClient.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/utils/traceHeader.d.ts +83 -0
- package/dist/types/utils/traceHeader.d.ts.map +1 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/actions/smartAccount/buildUserOperation.ts +7 -4
- package/src/actions/smartAccount/buildUserOperationFromTx.ts +4 -2
- package/src/actions/smartAccount/buildUserOperationFromTxs.ts +4 -2
- package/src/actions/smartAccount/checkGasSponsorshipEligibility.ts +4 -2
- package/src/actions/smartAccount/dropAndReplaceUserOperation.ts +4 -2
- package/src/actions/smartAccount/estimateUserOperationGas.ts +4 -2
- package/src/actions/smartAccount/sendTransaction.ts +4 -2
- package/src/actions/smartAccount/sendTransactions.ts +4 -2
- package/src/actions/smartAccount/sendUserOperation.ts +4 -2
- package/src/actions/smartAccount/upgradeAccount.ts +3 -1
- package/src/actions/smartAccount/waitForUserOperationTransacation.ts +4 -2
- package/src/client/addBreadcrumb.ts +25 -0
- package/src/client/smartAccountClient.ts +23 -3
- package/src/index.ts +6 -0
- package/src/utils/traceHeader.ts +151 -0
- package/src/utils/userop.ts +4 -4
- 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
|
+
}
|
package/src/utils/userop.ts
CHANGED
|
@@ -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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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