thirdweb 5.34.0-nightly-f6ff5a78fc2d65f0f250b154f1405210ca57ce0a-20240708000345 → 5.34.0-nightly-95c9d3d92406de619cb1e4cccc61b0766dd2a0d4-20240708205331

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 (186) hide show
  1. package/dist/cjs/auth/core/verify-jwt.js +1 -1
  2. package/dist/cjs/auth/core/verify-jwt.js.map +1 -1
  3. package/dist/cjs/auth/verify-hash.js +98 -0
  4. package/dist/cjs/auth/verify-hash.js.map +1 -0
  5. package/dist/cjs/auth/verify-signature.js +5 -60
  6. package/dist/cjs/auth/verify-signature.js.map +1 -1
  7. package/dist/cjs/auth/verify-typed-data.js +80 -0
  8. package/dist/cjs/auth/verify-typed-data.js.map +1 -0
  9. package/dist/cjs/chains/chain-definitions/blast.js +17 -0
  10. package/dist/cjs/chains/chain-definitions/blast.js.map +1 -0
  11. package/dist/cjs/exports/chains.js +3 -1
  12. package/dist/cjs/exports/chains.js.map +1 -1
  13. package/dist/cjs/exports/extensions/erc20.js +3 -1
  14. package/dist/cjs/exports/extensions/erc20.js.map +1 -1
  15. package/dist/cjs/exports/utils.js +10 -1
  16. package/dist/cjs/exports/utils.js.map +1 -1
  17. package/dist/cjs/exports/wallets/smart.js +10 -1
  18. package/dist/cjs/exports/wallets/smart.js.map +1 -1
  19. package/dist/cjs/extensions/erc1271/checkContractWalletSignature.js +1 -0
  20. package/dist/cjs/extensions/erc1271/checkContractWalletSignature.js.map +1 -1
  21. package/dist/cjs/extensions/erc1271/checkContractWalletSignedTypedData.js +1 -0
  22. package/dist/cjs/extensions/erc1271/checkContractWalletSignedTypedData.js.map +1 -1
  23. package/dist/cjs/extensions/erc20/write/transferBatch.js +61 -0
  24. package/dist/cjs/extensions/erc20/write/transferBatch.js.map +1 -0
  25. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +21 -12
  26. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
  27. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/PayWIthCreditCard.js +1 -1
  28. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.js +4 -4
  29. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatTxDetailsTable.js +1 -1
  30. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.js +1 -3
  31. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.js.map +1 -1
  32. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.js +1 -4
  33. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.js.map +1 -1
  34. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/ConfirmationScreen.js +1 -1
  35. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/Fees.js +4 -4
  36. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/PayWithCrypto.js +1 -1
  37. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/tx-history/BuyTxHistoryButton.js +1 -1
  38. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/tx-history/TokenInfoRow.js +1 -1
  39. package/dist/cjs/utils/hashing/hashTypedData.js +122 -0
  40. package/dist/cjs/utils/hashing/hashTypedData.js.map +1 -0
  41. package/dist/cjs/utils/jwt/decode-jwt.js +2 -2
  42. package/dist/cjs/utils/jwt/decode-jwt.js.map +1 -1
  43. package/dist/cjs/utils/jwt/refresh-jwt.js +1 -1
  44. package/dist/cjs/utils/jwt/refresh-jwt.js.map +1 -1
  45. package/dist/cjs/version.js +1 -1
  46. package/dist/cjs/wallets/smart/index.js +19 -9
  47. package/dist/cjs/wallets/smart/index.js.map +1 -1
  48. package/dist/cjs/wallets/smart/lib/bundler.js +57 -9
  49. package/dist/cjs/wallets/smart/lib/bundler.js.map +1 -1
  50. package/dist/cjs/wallets/smart/lib/calls.js +31 -21
  51. package/dist/cjs/wallets/smart/lib/calls.js.map +1 -1
  52. package/dist/cjs/wallets/smart/lib/paymaster.js +5 -6
  53. package/dist/cjs/wallets/smart/lib/paymaster.js.map +1 -1
  54. package/dist/cjs/wallets/smart/lib/userop.js +45 -21
  55. package/dist/cjs/wallets/smart/lib/userop.js.map +1 -1
  56. package/dist/esm/auth/core/verify-jwt.js +2 -2
  57. package/dist/esm/auth/core/verify-jwt.js.map +1 -1
  58. package/dist/esm/auth/verify-hash.js +95 -0
  59. package/dist/esm/auth/verify-hash.js.map +1 -0
  60. package/dist/esm/auth/verify-signature.js +6 -61
  61. package/dist/esm/auth/verify-signature.js.map +1 -1
  62. package/dist/esm/auth/verify-typed-data.js +77 -0
  63. package/dist/esm/auth/verify-typed-data.js.map +1 -0
  64. package/dist/esm/chains/chain-definitions/blast.js +14 -0
  65. package/dist/esm/chains/chain-definitions/blast.js.map +1 -0
  66. package/dist/esm/exports/chains.js +1 -0
  67. package/dist/esm/exports/chains.js.map +1 -1
  68. package/dist/esm/exports/extensions/erc20.js +1 -0
  69. package/dist/esm/exports/extensions/erc20.js.map +1 -1
  70. package/dist/esm/exports/utils.js +6 -0
  71. package/dist/esm/exports/utils.js.map +1 -1
  72. package/dist/esm/exports/wallets/smart.js +3 -1
  73. package/dist/esm/exports/wallets/smart.js.map +1 -1
  74. package/dist/esm/extensions/erc1271/checkContractWalletSignature.js +1 -0
  75. package/dist/esm/extensions/erc1271/checkContractWalletSignature.js.map +1 -1
  76. package/dist/esm/extensions/erc1271/checkContractWalletSignedTypedData.js +1 -0
  77. package/dist/esm/extensions/erc1271/checkContractWalletSignedTypedData.js.map +1 -1
  78. package/dist/esm/extensions/erc20/write/transferBatch.js +58 -0
  79. package/dist/esm/extensions/erc20/write/transferBatch.js.map +1 -0
  80. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +21 -12
  81. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
  82. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/PayWIthCreditCard.js +1 -1
  83. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.js +4 -4
  84. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatTxDetailsTable.js +1 -1
  85. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.js +1 -3
  86. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.js.map +1 -1
  87. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.js +1 -4
  88. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.js.map +1 -1
  89. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/ConfirmationScreen.js +1 -1
  90. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/Fees.js +4 -4
  91. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/PayWithCrypto.js +1 -1
  92. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/tx-history/BuyTxHistoryButton.js +1 -1
  93. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/tx-history/TokenInfoRow.js +1 -1
  94. package/dist/esm/utils/hashing/hashTypedData.js +118 -0
  95. package/dist/esm/utils/hashing/hashTypedData.js.map +1 -0
  96. package/dist/esm/utils/jwt/decode-jwt.js +1 -1
  97. package/dist/esm/utils/jwt/decode-jwt.js.map +1 -1
  98. package/dist/esm/utils/jwt/refresh-jwt.js +2 -2
  99. package/dist/esm/utils/jwt/refresh-jwt.js.map +1 -1
  100. package/dist/esm/version.js +1 -1
  101. package/dist/esm/wallets/smart/index.js +19 -9
  102. package/dist/esm/wallets/smart/index.js.map +1 -1
  103. package/dist/esm/wallets/smart/lib/bundler.js +56 -8
  104. package/dist/esm/wallets/smart/lib/bundler.js.map +1 -1
  105. package/dist/esm/wallets/smart/lib/calls.js +31 -21
  106. package/dist/esm/wallets/smart/lib/calls.js.map +1 -1
  107. package/dist/esm/wallets/smart/lib/paymaster.js +5 -6
  108. package/dist/esm/wallets/smart/lib/paymaster.js.map +1 -1
  109. package/dist/esm/wallets/smart/lib/userop.js +46 -22
  110. package/dist/esm/wallets/smart/lib/userop.js.map +1 -1
  111. package/dist/types/auth/verify-hash.d.ts +45 -0
  112. package/dist/types/auth/verify-hash.d.ts.map +1 -0
  113. package/dist/types/auth/verify-signature.d.ts.map +1 -1
  114. package/dist/types/auth/verify-typed-data.d.ts +75 -0
  115. package/dist/types/auth/verify-typed-data.d.ts.map +1 -0
  116. package/dist/types/chains/chain-definitions/blast.d.ts +27 -0
  117. package/dist/types/chains/chain-definitions/blast.d.ts.map +1 -0
  118. package/dist/types/exports/chains.d.ts +1 -0
  119. package/dist/types/exports/chains.d.ts.map +1 -1
  120. package/dist/types/exports/extensions/erc20.d.ts +1 -0
  121. package/dist/types/exports/extensions/erc20.d.ts.map +1 -1
  122. package/dist/types/exports/utils.d.ts +4 -0
  123. package/dist/types/exports/utils.d.ts.map +1 -1
  124. package/dist/types/exports/wallets/smart.d.ts +3 -1
  125. package/dist/types/exports/wallets/smart.d.ts.map +1 -1
  126. package/dist/types/extensions/erc1271/checkContractWalletSignature.d.ts +1 -0
  127. package/dist/types/extensions/erc1271/checkContractWalletSignature.d.ts.map +1 -1
  128. package/dist/types/extensions/erc1271/checkContractWalletSignedTypedData.d.ts +1 -0
  129. package/dist/types/extensions/erc1271/checkContractWalletSignedTypedData.d.ts.map +1 -1
  130. package/dist/types/extensions/erc20/write/transferBatch.d.ts +42 -0
  131. package/dist/types/extensions/erc20/write/transferBatch.d.ts.map +1 -0
  132. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.d.ts.map +1 -1
  133. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.d.ts.map +1 -1
  134. package/dist/types/utils/hashing/hashTypedData.d.ts +17 -0
  135. package/dist/types/utils/hashing/hashTypedData.d.ts.map +1 -0
  136. package/dist/types/utils/jwt/decode-jwt.d.ts +1 -1
  137. package/dist/types/utils/jwt/decode-jwt.d.ts.map +1 -1
  138. package/dist/types/version.d.ts +1 -1
  139. package/dist/types/wallets/smart/index.d.ts.map +1 -1
  140. package/dist/types/wallets/smart/lib/bundler.d.ts +53 -5
  141. package/dist/types/wallets/smart/lib/bundler.d.ts.map +1 -1
  142. package/dist/types/wallets/smart/lib/calls.d.ts +25 -7
  143. package/dist/types/wallets/smart/lib/calls.d.ts.map +1 -1
  144. package/dist/types/wallets/smart/lib/paymaster.d.ts +7 -2
  145. package/dist/types/wallets/smart/lib/paymaster.d.ts.map +1 -1
  146. package/dist/types/wallets/smart/lib/userop.d.ts +15 -4
  147. package/dist/types/wallets/smart/lib/userop.d.ts.map +1 -1
  148. package/dist/types/wallets/smart/types.d.ts +4 -2
  149. package/dist/types/wallets/smart/types.d.ts.map +1 -1
  150. package/package.json +1 -1
  151. package/src/auth/core/verify-jwt.ts +2 -2
  152. package/src/auth/verify-hash.test.ts +66 -0
  153. package/src/auth/verify-hash.ts +126 -0
  154. package/src/auth/verify-signature.ts +6 -77
  155. package/src/auth/verify-typed-data.test.ts +82 -0
  156. package/src/auth/verify-typed-data.ts +110 -0
  157. package/src/chains/chain-definitions/blast.ts +14 -0
  158. package/src/exports/chains.ts +1 -0
  159. package/src/exports/extensions/erc20.ts +4 -0
  160. package/src/exports/utils.ts +8 -0
  161. package/src/exports/wallets/smart.ts +14 -1
  162. package/src/extensions/erc1271/checkContractWalletSignature.ts +1 -0
  163. package/src/extensions/erc1271/checkContractWalletSignedTypedData.ts +1 -0
  164. package/src/extensions/erc20/write/transferBatch.ts +78 -0
  165. package/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx +42 -12
  166. package/src/react/web/ui/ConnectWallet/screens/Buy/PayWIthCreditCard.tsx +1 -1
  167. package/src/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.tsx +5 -5
  168. package/src/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatTxDetailsTable.tsx +1 -1
  169. package/src/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.ts +1 -5
  170. package/src/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.ts +1 -6
  171. package/src/react/web/ui/ConnectWallet/screens/Buy/swap/ConfirmationScreen.tsx +2 -2
  172. package/src/react/web/ui/ConnectWallet/screens/Buy/swap/Fees.tsx +4 -4
  173. package/src/react/web/ui/ConnectWallet/screens/Buy/swap/PayWithCrypto.tsx +1 -1
  174. package/src/react/web/ui/ConnectWallet/screens/Buy/tx-history/BuyTxHistoryButton.tsx +1 -1
  175. package/src/react/web/ui/ConnectWallet/screens/Buy/tx-history/TokenInfoRow.tsx +1 -1
  176. package/src/utils/hashing/hashTypedData.test.ts +207 -0
  177. package/src/utils/hashing/hashTypedData.ts +210 -0
  178. package/src/utils/jwt/decode-jwt.ts +1 -1
  179. package/src/utils/jwt/refresh-jwt.ts +2 -2
  180. package/src/version.ts +1 -1
  181. package/src/wallets/smart/index.ts +19 -9
  182. package/src/wallets/smart/lib/bundler.ts +56 -9
  183. package/src/wallets/smart/lib/calls.ts +67 -28
  184. package/src/wallets/smart/lib/paymaster.ts +12 -13
  185. package/src/wallets/smart/lib/userop.ts +74 -30
  186. package/src/wallets/smart/types.ts +6 -6
@@ -0,0 +1,210 @@
1
+ import {
2
+ type AbiParameter,
3
+ type TypedData,
4
+ type TypedDataDefinition,
5
+ concat,
6
+ getTypesForEIP712Domain,
7
+ hashDomain,
8
+ validateTypedData,
9
+ } from "viem";
10
+ import { encodeAbiParameters } from "../abi/encodeAbiParameters.js";
11
+ import { type Hex, toHex } from "../encoding/hex.js";
12
+ import { keccak256 } from "./keccak256.js";
13
+
14
+ type MessageTypeProperty = {
15
+ name: string;
16
+ type: string;
17
+ };
18
+
19
+ export type HashTypedDataParams<
20
+ typedData extends TypedData | Record<string, unknown> = TypedData,
21
+ primaryType extends keyof typedData | "EIP712Domain" = keyof typedData,
22
+ > = TypedDataDefinition<typedData, primaryType>;
23
+
24
+ /**
25
+ * @internal
26
+ */
27
+ export function hashTypedData<
28
+ const typedData extends TypedData | Record<string, unknown>,
29
+ primaryType extends keyof typedData | "EIP712Domain",
30
+ >(parameters: HashTypedDataParams<typedData, primaryType>): Hex {
31
+ const {
32
+ domain = {},
33
+ message,
34
+ primaryType,
35
+ } = parameters as HashTypedDataParams;
36
+ const types = {
37
+ EIP712Domain: getTypesForEIP712Domain({ domain }),
38
+ ...parameters.types,
39
+ };
40
+
41
+ // Need to do a runtime validation check on addresses, byte ranges, integer ranges, etc
42
+ // as we can't statically check this with TypeScript.
43
+ validateTypedData({
44
+ domain,
45
+ message,
46
+ primaryType,
47
+ types,
48
+ });
49
+
50
+ const parts: Hex[] = ["0x1901"];
51
+ if (domain)
52
+ parts.push(
53
+ hashDomain({
54
+ domain,
55
+ types: types as Record<string, MessageTypeProperty[]>,
56
+ }),
57
+ );
58
+
59
+ if (primaryType !== "EIP712Domain") {
60
+ const hashedStruct = (() => {
61
+ const encoded = encodeData({
62
+ data: message,
63
+ primaryType,
64
+ types: types as Record<string, MessageTypeProperty[]>,
65
+ });
66
+ return keccak256(encoded);
67
+ })();
68
+
69
+ parts.push(hashedStruct);
70
+ }
71
+
72
+ return keccak256(concat(parts));
73
+ }
74
+
75
+ function encodeData({
76
+ data,
77
+ primaryType,
78
+ types,
79
+ }: {
80
+ data: Record<string, unknown>;
81
+ primaryType: string;
82
+ types: Record<string, MessageTypeProperty[]>;
83
+ }) {
84
+ const encodedTypes: AbiParameter[] = [{ type: "bytes32" }];
85
+ const encodedValues: unknown[] = [hashType({ primaryType, types })];
86
+
87
+ if (!types[primaryType]) throw new Error("Invalid types");
88
+ for (const field of types[primaryType]) {
89
+ const [type, value] = encodeField({
90
+ types,
91
+ name: field.name,
92
+ type: field.type,
93
+ value: data[field.name],
94
+ });
95
+ encodedTypes.push(type);
96
+ encodedValues.push(value);
97
+ }
98
+
99
+ return encodeAbiParameters(encodedTypes, encodedValues);
100
+ }
101
+
102
+ function hashType({
103
+ primaryType,
104
+ types,
105
+ }: {
106
+ primaryType: string;
107
+ types: Record<string, MessageTypeProperty[]>;
108
+ }) {
109
+ const encodedHashType = toHex(encodeType({ primaryType, types }));
110
+ return keccak256(encodedHashType);
111
+ }
112
+
113
+ export function encodeType({
114
+ primaryType,
115
+ types,
116
+ }: {
117
+ primaryType: string;
118
+ types: Record<string, MessageTypeProperty[]>;
119
+ }) {
120
+ let result = "";
121
+ const unsortedDeps = findTypeDependencies({ primaryType, types });
122
+ unsortedDeps.delete(primaryType);
123
+
124
+ const deps = [primaryType, ...Array.from(unsortedDeps).sort()];
125
+ for (const type of deps) {
126
+ if (!types[type]) throw new Error("Invalid types");
127
+ result += `${type}(${types[type]
128
+ .map(({ name, type: t }) => `${t} ${name}`)
129
+ .join(",")})`;
130
+ }
131
+
132
+ return result;
133
+ }
134
+
135
+ function findTypeDependencies(
136
+ {
137
+ primaryType: primaryType_,
138
+ types,
139
+ }: {
140
+ primaryType: string;
141
+ types: Record<string, MessageTypeProperty[]>;
142
+ },
143
+ results: Set<string> = new Set(),
144
+ ): Set<string> {
145
+ const match = primaryType_.match(/^\w*/u);
146
+ const primaryType = match?.[0] as string;
147
+ if (results.has(primaryType) || types[primaryType] === undefined) {
148
+ return results;
149
+ }
150
+
151
+ results.add(primaryType);
152
+
153
+ for (const field of types[primaryType]) {
154
+ findTypeDependencies({ primaryType: field.type, types }, results);
155
+ }
156
+ return results;
157
+ }
158
+
159
+ function encodeField({
160
+ types,
161
+ name,
162
+ type,
163
+ value,
164
+ }: {
165
+ types: Record<string, MessageTypeProperty[]>;
166
+ name: string;
167
+ type: string;
168
+ // biome-ignore lint/suspicious/noExplicitAny: Can't anticipate types of nested values
169
+ value: any;
170
+ // biome-ignore lint/suspicious/noExplicitAny: Can't anticipate types of nested values
171
+ }): [type: AbiParameter, value: any] {
172
+ if (types[type] !== undefined) {
173
+ return [
174
+ { type: "bytes32" },
175
+ keccak256(encodeData({ data: value, primaryType: type, types })),
176
+ ];
177
+ }
178
+
179
+ if (type === "bytes") {
180
+ const prepend = value.length % 2 ? "0" : "";
181
+ value = `0x${prepend + value.slice(2)}`;
182
+ return [{ type: "bytes32" }, keccak256(value)];
183
+ }
184
+
185
+ if (type === "string") return [{ type: "bytes32" }, keccak256(toHex(value))];
186
+
187
+ if (type.lastIndexOf("]") === type.length - 1) {
188
+ const parsedType = type.slice(0, type.lastIndexOf("["));
189
+ // biome-ignore lint/suspicious/noExplicitAny: Can't anticipate types of nested values
190
+ const typeValuePairs = (value as [AbiParameter, any][]).map((item) =>
191
+ encodeField({
192
+ name,
193
+ type: parsedType,
194
+ types,
195
+ value: item,
196
+ }),
197
+ );
198
+ return [
199
+ { type: "bytes32" },
200
+ keccak256(
201
+ encodeAbiParameters(
202
+ typeValuePairs.map(([t]) => t),
203
+ typeValuePairs.map(([, v]) => v),
204
+ ),
205
+ ),
206
+ ];
207
+ }
208
+
209
+ return [{ type }, value];
210
+ }
@@ -15,7 +15,7 @@ import type { JWTPayload } from "./types.js";
15
15
  * const { payload, signature } = decodeJWT(jwt);
16
16
  * ```
17
17
  */
18
- export function deccodeJWT(jwt: string) {
18
+ export function decodeJWT(jwt: string) {
19
19
  const [encodedHeader, encodedPayload, encodedSignature] = jwt.split(".");
20
20
 
21
21
  if (encodedHeader !== PRECOMPILED_B64_ENCODED_JWT_HEADER) {
@@ -1,5 +1,5 @@
1
1
  import type { Account } from "../../wallets/interfaces/wallet.js";
2
- import { deccodeJWT } from "./decode-jwt.js";
2
+ import { decodeJWT } from "./decode-jwt.js";
3
3
  import { encodeJWT } from "./encode-jwt.js";
4
4
 
5
5
  const DEFAULT_EXPIRATION_TIME = 60 * 60 * 24;
@@ -27,7 +27,7 @@ export type RefreshJWTParams = {
27
27
  */
28
28
  export async function refreshJWT(options: RefreshJWTParams): Promise<string> {
29
29
  const { account, jwt, expirationTime = DEFAULT_EXPIRATION_TIME } = options;
30
- const payload = deccodeJWT(jwt).payload;
30
+ const payload = decodeJWT(jwt).payload;
31
31
  return encodeJWT({
32
32
  payload: {
33
33
  iss: payload.iss,
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "5.34.0-nightly-f6ff5a78fc2d65f0f250b154f1405210ca57ce0a-20240708000345";
1
+ export const version = "5.34.0-nightly-95c9d3d92406de619cb1e4cccc61b0766dd2a0d4-20240708205331";
@@ -110,9 +110,11 @@ export async function connectSmartWallet(
110
110
  });
111
111
 
112
112
  // TODO: listen for chainChanged event on the personal wallet and emit the disconnect event on the smart wallet
113
- const accountAddress = await predictAddress(factoryContract, {
114
- personalAccountAddress: personalAccount.address,
115
- ...options,
113
+ const accountAddress = await predictAddress({
114
+ factoryContract,
115
+ adminAddress: personalAccount.address,
116
+ predictAddressOverride: options.overrides?.predictAddress,
117
+ accountSalt: options.overrides?.accountSalt,
116
118
  })
117
119
  .then((address) => address)
118
120
  .catch((err) => {
@@ -168,8 +170,8 @@ async function createSmartAccount(
168
170
  async sendTransaction(transaction: SendTransactionOption) {
169
171
  const executeTx = prepareExecute({
170
172
  accountContract,
171
- options,
172
173
  transaction,
174
+ executeOverride: options.overrides?.execute,
173
175
  });
174
176
  return _sendUserOp({
175
177
  executeTx,
@@ -179,8 +181,8 @@ async function createSmartAccount(
179
181
  async sendBatchTransaction(transactions: SendTransactionOption[]) {
180
182
  const executeTx = prepareBatchExecute({
181
183
  accountContract,
182
- options,
183
184
  transactions,
185
+ executeBatchOverride: options.overrides?.executeBatch,
184
186
  });
185
187
  return _sendUserOp({
186
188
  executeTx,
@@ -387,8 +389,9 @@ function createZkSyncAccount(args: {
387
389
  const pmData = await getZkPaymasterData({
388
390
  options: {
389
391
  client: connectionOptions.client,
390
- overrides: creationOptions.overrides,
391
392
  chain,
393
+ bundlerUrl: creationOptions.overrides?.bundlerUrl,
394
+ entrypointAddress: creationOptions.overrides?.entrypointAddress,
392
395
  },
393
396
  transaction: serializableTransaction,
394
397
  });
@@ -409,8 +412,9 @@ function createZkSyncAccount(args: {
409
412
  const txHash = await broadcastZkTransaction({
410
413
  options: {
411
414
  client: connectionOptions.client,
412
- overrides: creationOptions.overrides,
413
415
  chain,
416
+ bundlerUrl: creationOptions.overrides?.bundlerUrl,
417
+ entrypointAddress: creationOptions.overrides?.entrypointAddress,
414
418
  },
415
419
  transaction: serializableTransaction,
416
420
  signedTransaction,
@@ -471,10 +475,16 @@ async function _sendUserOp(args: {
471
475
  const { executeTx, options } = args;
472
476
  const unsignedUserOp = await createUnsignedUserOp({
473
477
  transaction: executeTx,
474
- options,
478
+ factoryContract: options.factoryContract,
479
+ accountContract: options.accountContract,
480
+ adminAddress: options.personalAccount.address,
481
+ sponsorGas: options.sponsorGas,
482
+ overrides: options.overrides,
475
483
  });
476
484
  const signedUserOp = await signUserOp({
477
- options,
485
+ chain: options.chain,
486
+ adminAccount: options.personalAccount,
487
+ entrypointAddress: options.overrides?.entrypointAddress,
478
488
  userOp: unsignedUserOp,
479
489
  });
480
490
  const userOpHash = await bundleUserOp({
@@ -21,7 +21,19 @@ import {
21
21
  import { hexlifyUserOp } from "./utils.js";
22
22
 
23
23
  /**
24
- * @internal
24
+ * Bundle a user operation.
25
+ * @param args - The options for bundling a user operation.
26
+ * @returns The bundle hash of the user operation.
27
+ * @example
28
+ * ```ts
29
+ * import { bundleUserOp } from "thirdweb/wallets/smart";
30
+ *
31
+ * const userOpHash = await bundleUserOp({
32
+ * userOp,
33
+ * options,
34
+ * });
35
+ * ```
36
+ * @walletUtils
25
37
  */
26
38
  export async function bundleUserOp(args: {
27
39
  userOp: UserOperation;
@@ -32,13 +44,25 @@ export async function bundleUserOp(args: {
32
44
  operation: "eth_sendUserOperation",
33
45
  params: [
34
46
  hexlifyUserOp(args.userOp),
35
- args.options.overrides?.entrypointAddress ?? ENTRYPOINT_ADDRESS_v0_6,
47
+ args.options.entrypointAddress ?? ENTRYPOINT_ADDRESS_v0_6,
36
48
  ],
37
49
  });
38
50
  }
39
51
 
40
52
  /**
41
- * @internal
53
+ * Estimate the gas cost of a user operation.
54
+ * @param args - The options for estimating the gas cost of a user operation.
55
+ * @returns The estimated gas cost of the user operation.
56
+ * @example
57
+ * ```ts
58
+ * import { estimateUserOpGas } from "thirdweb/wallets/smart";
59
+ *
60
+ * const gasCost = await estimateUserOpGas({
61
+ * userOp,
62
+ * options,
63
+ * });
64
+ * ```
65
+ * @walletUtils
42
66
  */
43
67
  export async function estimateUserOpGas(args: {
44
68
  userOp: UserOperation;
@@ -49,7 +73,7 @@ export async function estimateUserOpGas(args: {
49
73
  operation: "eth_estimateUserOperationGas",
50
74
  params: [
51
75
  hexlifyUserOp(args.userOp),
52
- args.options.overrides?.entrypointAddress ?? ENTRYPOINT_ADDRESS_v0_6,
76
+ args.options.entrypointAddress ?? ENTRYPOINT_ADDRESS_v0_6,
53
77
  ],
54
78
  });
55
79
 
@@ -63,9 +87,20 @@ export async function estimateUserOpGas(args: {
63
87
  }
64
88
 
65
89
  /**
66
- * @internal
90
+ * Get the gas fees of a user operation.
91
+ * @param args - The options for getting the gas price of a user operation.
92
+ * @returns The gas price of the user operation.
93
+ * @example
94
+ * ```ts
95
+ * import { getUserOpGasPrice } from "thirdweb/wallets/smart";
96
+ *
97
+ * const fees = await getUserOpGasPrice({
98
+ * options,
99
+ * });
100
+ * ```
101
+ * @walletUtils
67
102
  */
68
- export async function getUserOpGasPrice(args: {
103
+ export async function getUserOpGasFees(args: {
69
104
  options: BundlerOptions;
70
105
  }): Promise<GasPriceResult> {
71
106
  const res = await sendBundlerRequest({
@@ -81,7 +116,20 @@ export async function getUserOpGasPrice(args: {
81
116
  }
82
117
 
83
118
  /**
84
- * @internal
119
+ * Get the receipt of a user operation.
120
+ * @param args - The options for getting the receipt of a user operation.
121
+ * @returns The receipt of the user operation.
122
+ * @example
123
+ * ```ts
124
+ * import { getUserOpReceipt } from "thirdweb/wallets/smart";
125
+ *
126
+ * const receipt = await getUserOpReceipt({
127
+ * client,
128
+ * chain,
129
+ * userOpHash,
130
+ * });
131
+ * ```
132
+ * @walletUtils
85
133
  */
86
134
  export async function getUserOpReceipt(
87
135
  args: BundlerOptions & {
@@ -176,8 +224,7 @@ async function sendBundlerRequest(args: {
176
224
  console.debug(`>>> sending ${operation} with payload:`, params);
177
225
  }
178
226
 
179
- const bundlerUrl =
180
- options.overrides?.bundlerUrl ?? getDefaultBundlerUrl(options.chain);
227
+ const bundlerUrl = options.bundlerUrl ?? getDefaultBundlerUrl(options.chain);
181
228
  const fetchWithHeaders = getClientFetch(options.client);
182
229
  const response = await fetchWithHeaders(bundlerUrl, {
183
230
  method: "POST",
@@ -4,28 +4,51 @@ import type { PreparedTransaction } from "../../../transaction/prepare-transacti
4
4
  import { readContract } from "../../../transaction/read-contract.js";
5
5
  import { stringToHex } from "../../../utils/encoding/hex.js";
6
6
  import type { SendTransactionOption } from "../../interfaces/wallet.js";
7
- import type { SmartAccountOptions, SmartWalletOptions } from "../types.ts";
8
7
 
9
8
  /**
10
- * @internal
9
+ * Predict the address of a smart account.
10
+ * @param args - The options for predicting the address of a smart account.
11
+ * @returns The predicted address of the smart account.
12
+ * @example
13
+ * ```ts
14
+ * import { predictAddress } from "thirdweb/wallets/smart";
15
+ *
16
+ * const predictedAddress = await predictAddress({
17
+ * factoryContract,
18
+ * adminAddress,
19
+ * accountSalt,
20
+ * });
21
+ * ```
22
+ * @walletUtils
11
23
  */
12
- export async function predictAddress(
13
- factoryContract: ThirdwebContract,
14
- options: SmartWalletOptions & { personalAccountAddress?: string },
15
- ): Promise<string> {
16
- if (options.overrides?.predictAddress) {
17
- return options.overrides.predictAddress(factoryContract);
24
+ export async function predictAddress(args: {
25
+ factoryContract: ThirdwebContract;
26
+ predictAddressOverride?: (
27
+ factoryContract: ThirdwebContract,
28
+ ) => Promise<string>;
29
+ adminAddress: string;
30
+ accountSalt?: string;
31
+ accountAddress?: string;
32
+ }): Promise<string> {
33
+ const {
34
+ factoryContract,
35
+ predictAddressOverride: predictAddress,
36
+ adminAddress,
37
+ accountSalt,
38
+ accountAddress,
39
+ } = args;
40
+ if (predictAddress) {
41
+ return predictAddress(factoryContract);
18
42
  }
19
- if (options.overrides?.accountAddress) {
20
- return options.overrides.accountAddress;
43
+ if (accountAddress) {
44
+ return accountAddress;
21
45
  }
22
- const adminAddress = options.personalAccountAddress;
23
46
  if (!adminAddress) {
24
47
  throw new Error(
25
48
  "Account address is required to predict the smart wallet address.",
26
49
  );
27
50
  }
28
- const extraData = stringToHex(options.overrides?.accountSalt ?? "");
51
+ const extraData = stringToHex(accountSalt ?? "");
29
52
  return readContract({
30
53
  contract: factoryContract,
31
54
  method: "function getAddress(address, bytes) returns (address)",
@@ -38,19 +61,25 @@ export async function predictAddress(
38
61
  */
39
62
  export function prepareCreateAccount(args: {
40
63
  factoryContract: ThirdwebContract;
41
- options: SmartAccountOptions;
64
+ adminAddress: string;
65
+ accountSalt?: string;
66
+ createAccountOverride?: (
67
+ factoryContract: ThirdwebContract,
68
+ ) => PreparedTransaction;
42
69
  }): PreparedTransaction {
43
- const { factoryContract, options } = args;
44
- if (options.overrides?.createAccount) {
45
- return options.overrides.createAccount(factoryContract);
70
+ const {
71
+ adminAddress,
72
+ factoryContract,
73
+ createAccountOverride: createAccount,
74
+ accountSalt,
75
+ } = args;
76
+ if (createAccount) {
77
+ return createAccount(factoryContract);
46
78
  }
47
79
  return prepareContractCall({
48
80
  contract: factoryContract,
49
81
  method: "function createAccount(address, bytes) returns (address)",
50
- params: [
51
- options.personalAccount.address,
52
- stringToHex(options.overrides?.accountSalt ?? ""),
53
- ],
82
+ params: [adminAddress, stringToHex(accountSalt ?? "")],
54
83
  });
55
84
  }
56
85
 
@@ -59,12 +88,15 @@ export function prepareCreateAccount(args: {
59
88
  */
60
89
  export function prepareExecute(args: {
61
90
  accountContract: ThirdwebContract;
62
- options: SmartAccountOptions;
63
91
  transaction: SendTransactionOption;
92
+ executeOverride?: (
93
+ accountContract: ThirdwebContract,
94
+ transaction: SendTransactionOption,
95
+ ) => PreparedTransaction;
64
96
  }): PreparedTransaction {
65
- const { accountContract, options, transaction } = args;
66
- if (options.overrides?.execute) {
67
- return options.overrides.execute(accountContract, transaction);
97
+ const { accountContract, transaction, executeOverride: execute } = args;
98
+ if (execute) {
99
+ return execute(accountContract, transaction);
68
100
  }
69
101
  return prepareContractCall({
70
102
  contract: accountContract,
@@ -82,12 +114,19 @@ export function prepareExecute(args: {
82
114
  */
83
115
  export function prepareBatchExecute(args: {
84
116
  accountContract: ThirdwebContract;
85
- options: SmartAccountOptions;
86
117
  transactions: SendTransactionOption[];
118
+ executeBatchOverride?: (
119
+ accountContract: ThirdwebContract,
120
+ transactions: SendTransactionOption[],
121
+ ) => PreparedTransaction;
87
122
  }): PreparedTransaction {
88
- const { accountContract, options, transactions } = args;
89
- if (options.overrides?.executeBatch) {
90
- return options.overrides.executeBatch(accountContract, transactions);
123
+ const {
124
+ accountContract,
125
+ transactions,
126
+ executeBatchOverride: executeBatch,
127
+ } = args;
128
+ if (executeBatch) {
129
+ return executeBatch(accountContract, transactions);
91
130
  }
92
131
  return prepareContractCall({
93
132
  contract: accountContract,
@@ -1,10 +1,8 @@
1
+ import type { Chain } from "../../../chains/types.js";
2
+ import type { ThirdwebClient } from "../../../client/client.js";
1
3
  import { hexToBigInt } from "../../../utils/encoding/hex.js";
2
4
  import { getClientFetch } from "../../../utils/fetch.js";
3
- import type {
4
- PaymasterResult,
5
- SmartAccountOptions,
6
- UserOperation,
7
- } from "../types.js";
5
+ import type { PaymasterResult, UserOperation } from "../types.js";
8
6
  import {
9
7
  DEBUG,
10
8
  ENTRYPOINT_ADDRESS_v0_6,
@@ -18,22 +16,23 @@ import { hexlifyUserOp } from "./utils.js";
18
16
  */
19
17
  export async function getPaymasterAndData(args: {
20
18
  userOp: UserOperation;
21
- options: SmartAccountOptions;
19
+ client: ThirdwebClient;
20
+ chain: Chain;
21
+ entrypointAddress?: string;
22
+ paymasterOverride?: (userOp: UserOperation) => Promise<PaymasterResult>;
22
23
  }): Promise<PaymasterResult> {
23
- const { userOp, options } = args;
24
+ const { userOp, paymasterOverride, client, chain, entrypointAddress } = args;
24
25
 
25
- if (options.overrides?.paymaster) {
26
- return options.overrides?.paymaster(userOp);
26
+ if (paymasterOverride) {
27
+ return paymasterOverride(userOp);
27
28
  }
28
29
 
29
30
  const headers: Record<string, string> = {
30
31
  "Content-Type": "application/json",
31
32
  };
32
33
 
33
- const client = options.client;
34
- const paymasterUrl = getDefaultPaymasterUrl(options.chain);
35
- const entrypoint =
36
- options.overrides?.entrypointAddress ?? ENTRYPOINT_ADDRESS_v0_6;
34
+ const paymasterUrl = getDefaultPaymasterUrl(chain);
35
+ const entrypoint = entrypointAddress ?? ENTRYPOINT_ADDRESS_v0_6;
37
36
 
38
37
  // Ask the paymaster to sign the transaction and return a valid paymasterAndData value.
39
38
  const fetchWithHeaders = getClientFetch(client);