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.
- package/dist/cjs/auth/core/verify-jwt.js +1 -1
- package/dist/cjs/auth/core/verify-jwt.js.map +1 -1
- package/dist/cjs/auth/verify-hash.js +98 -0
- package/dist/cjs/auth/verify-hash.js.map +1 -0
- package/dist/cjs/auth/verify-signature.js +5 -60
- package/dist/cjs/auth/verify-signature.js.map +1 -1
- package/dist/cjs/auth/verify-typed-data.js +80 -0
- package/dist/cjs/auth/verify-typed-data.js.map +1 -0
- package/dist/cjs/chains/chain-definitions/blast.js +17 -0
- package/dist/cjs/chains/chain-definitions/blast.js.map +1 -0
- package/dist/cjs/exports/chains.js +3 -1
- package/dist/cjs/exports/chains.js.map +1 -1
- package/dist/cjs/exports/extensions/erc20.js +3 -1
- package/dist/cjs/exports/extensions/erc20.js.map +1 -1
- package/dist/cjs/exports/utils.js +10 -1
- package/dist/cjs/exports/utils.js.map +1 -1
- package/dist/cjs/exports/wallets/smart.js +10 -1
- package/dist/cjs/exports/wallets/smart.js.map +1 -1
- package/dist/cjs/extensions/erc1271/checkContractWalletSignature.js +1 -0
- package/dist/cjs/extensions/erc1271/checkContractWalletSignature.js.map +1 -1
- package/dist/cjs/extensions/erc1271/checkContractWalletSignedTypedData.js +1 -0
- package/dist/cjs/extensions/erc1271/checkContractWalletSignedTypedData.js.map +1 -1
- package/dist/cjs/extensions/erc20/write/transferBatch.js +61 -0
- package/dist/cjs/extensions/erc20/write/transferBatch.js.map +1 -0
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +21 -12
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/PayWIthCreditCard.js +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.js +4 -4
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatTxDetailsTable.js +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.js +1 -3
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.js +1 -4
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/ConfirmationScreen.js +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/Fees.js +4 -4
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/PayWithCrypto.js +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/tx-history/BuyTxHistoryButton.js +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/tx-history/TokenInfoRow.js +1 -1
- package/dist/cjs/utils/hashing/hashTypedData.js +122 -0
- package/dist/cjs/utils/hashing/hashTypedData.js.map +1 -0
- package/dist/cjs/utils/jwt/decode-jwt.js +2 -2
- package/dist/cjs/utils/jwt/decode-jwt.js.map +1 -1
- package/dist/cjs/utils/jwt/refresh-jwt.js +1 -1
- package/dist/cjs/utils/jwt/refresh-jwt.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/wallets/smart/index.js +19 -9
- package/dist/cjs/wallets/smart/index.js.map +1 -1
- package/dist/cjs/wallets/smart/lib/bundler.js +57 -9
- package/dist/cjs/wallets/smart/lib/bundler.js.map +1 -1
- package/dist/cjs/wallets/smart/lib/calls.js +31 -21
- package/dist/cjs/wallets/smart/lib/calls.js.map +1 -1
- package/dist/cjs/wallets/smart/lib/paymaster.js +5 -6
- package/dist/cjs/wallets/smart/lib/paymaster.js.map +1 -1
- package/dist/cjs/wallets/smart/lib/userop.js +45 -21
- package/dist/cjs/wallets/smart/lib/userop.js.map +1 -1
- package/dist/esm/auth/core/verify-jwt.js +2 -2
- package/dist/esm/auth/core/verify-jwt.js.map +1 -1
- package/dist/esm/auth/verify-hash.js +95 -0
- package/dist/esm/auth/verify-hash.js.map +1 -0
- package/dist/esm/auth/verify-signature.js +6 -61
- package/dist/esm/auth/verify-signature.js.map +1 -1
- package/dist/esm/auth/verify-typed-data.js +77 -0
- package/dist/esm/auth/verify-typed-data.js.map +1 -0
- package/dist/esm/chains/chain-definitions/blast.js +14 -0
- package/dist/esm/chains/chain-definitions/blast.js.map +1 -0
- package/dist/esm/exports/chains.js +1 -0
- package/dist/esm/exports/chains.js.map +1 -1
- package/dist/esm/exports/extensions/erc20.js +1 -0
- package/dist/esm/exports/extensions/erc20.js.map +1 -1
- package/dist/esm/exports/utils.js +6 -0
- package/dist/esm/exports/utils.js.map +1 -1
- package/dist/esm/exports/wallets/smart.js +3 -1
- package/dist/esm/exports/wallets/smart.js.map +1 -1
- package/dist/esm/extensions/erc1271/checkContractWalletSignature.js +1 -0
- package/dist/esm/extensions/erc1271/checkContractWalletSignature.js.map +1 -1
- package/dist/esm/extensions/erc1271/checkContractWalletSignedTypedData.js +1 -0
- package/dist/esm/extensions/erc1271/checkContractWalletSignedTypedData.js.map +1 -1
- package/dist/esm/extensions/erc20/write/transferBatch.js +58 -0
- package/dist/esm/extensions/erc20/write/transferBatch.js.map +1 -0
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js +21 -12
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/PayWIthCreditCard.js +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.js +4 -4
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatTxDetailsTable.js +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.js +1 -3
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.js +1 -4
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/ConfirmationScreen.js +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/Fees.js +4 -4
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/PayWithCrypto.js +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/tx-history/BuyTxHistoryButton.js +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/tx-history/TokenInfoRow.js +1 -1
- package/dist/esm/utils/hashing/hashTypedData.js +118 -0
- package/dist/esm/utils/hashing/hashTypedData.js.map +1 -0
- package/dist/esm/utils/jwt/decode-jwt.js +1 -1
- package/dist/esm/utils/jwt/decode-jwt.js.map +1 -1
- package/dist/esm/utils/jwt/refresh-jwt.js +2 -2
- package/dist/esm/utils/jwt/refresh-jwt.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/wallets/smart/index.js +19 -9
- package/dist/esm/wallets/smart/index.js.map +1 -1
- package/dist/esm/wallets/smart/lib/bundler.js +56 -8
- package/dist/esm/wallets/smart/lib/bundler.js.map +1 -1
- package/dist/esm/wallets/smart/lib/calls.js +31 -21
- package/dist/esm/wallets/smart/lib/calls.js.map +1 -1
- package/dist/esm/wallets/smart/lib/paymaster.js +5 -6
- package/dist/esm/wallets/smart/lib/paymaster.js.map +1 -1
- package/dist/esm/wallets/smart/lib/userop.js +46 -22
- package/dist/esm/wallets/smart/lib/userop.js.map +1 -1
- package/dist/types/auth/verify-hash.d.ts +45 -0
- package/dist/types/auth/verify-hash.d.ts.map +1 -0
- package/dist/types/auth/verify-signature.d.ts.map +1 -1
- package/dist/types/auth/verify-typed-data.d.ts +75 -0
- package/dist/types/auth/verify-typed-data.d.ts.map +1 -0
- package/dist/types/chains/chain-definitions/blast.d.ts +27 -0
- package/dist/types/chains/chain-definitions/blast.d.ts.map +1 -0
- package/dist/types/exports/chains.d.ts +1 -0
- package/dist/types/exports/chains.d.ts.map +1 -1
- package/dist/types/exports/extensions/erc20.d.ts +1 -0
- package/dist/types/exports/extensions/erc20.d.ts.map +1 -1
- package/dist/types/exports/utils.d.ts +4 -0
- package/dist/types/exports/utils.d.ts.map +1 -1
- package/dist/types/exports/wallets/smart.d.ts +3 -1
- package/dist/types/exports/wallets/smart.d.ts.map +1 -1
- package/dist/types/extensions/erc1271/checkContractWalletSignature.d.ts +1 -0
- package/dist/types/extensions/erc1271/checkContractWalletSignature.d.ts.map +1 -1
- package/dist/types/extensions/erc1271/checkContractWalletSignedTypedData.d.ts +1 -0
- package/dist/types/extensions/erc1271/checkContractWalletSignedTypedData.d.ts.map +1 -1
- package/dist/types/extensions/erc20/write/transferBatch.d.ts +42 -0
- package/dist/types/extensions/erc20/write/transferBatch.d.ts.map +1 -0
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.d.ts.map +1 -1
- package/dist/types/utils/hashing/hashTypedData.d.ts +17 -0
- package/dist/types/utils/hashing/hashTypedData.d.ts.map +1 -0
- package/dist/types/utils/jwt/decode-jwt.d.ts +1 -1
- package/dist/types/utils/jwt/decode-jwt.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/wallets/smart/index.d.ts.map +1 -1
- package/dist/types/wallets/smart/lib/bundler.d.ts +53 -5
- package/dist/types/wallets/smart/lib/bundler.d.ts.map +1 -1
- package/dist/types/wallets/smart/lib/calls.d.ts +25 -7
- package/dist/types/wallets/smart/lib/calls.d.ts.map +1 -1
- package/dist/types/wallets/smart/lib/paymaster.d.ts +7 -2
- package/dist/types/wallets/smart/lib/paymaster.d.ts.map +1 -1
- package/dist/types/wallets/smart/lib/userop.d.ts +15 -4
- package/dist/types/wallets/smart/lib/userop.d.ts.map +1 -1
- package/dist/types/wallets/smart/types.d.ts +4 -2
- package/dist/types/wallets/smart/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/auth/core/verify-jwt.ts +2 -2
- package/src/auth/verify-hash.test.ts +66 -0
- package/src/auth/verify-hash.ts +126 -0
- package/src/auth/verify-signature.ts +6 -77
- package/src/auth/verify-typed-data.test.ts +82 -0
- package/src/auth/verify-typed-data.ts +110 -0
- package/src/chains/chain-definitions/blast.ts +14 -0
- package/src/exports/chains.ts +1 -0
- package/src/exports/extensions/erc20.ts +4 -0
- package/src/exports/utils.ts +8 -0
- package/src/exports/wallets/smart.ts +14 -1
- package/src/extensions/erc1271/checkContractWalletSignature.ts +1 -0
- package/src/extensions/erc1271/checkContractWalletSignedTypedData.ts +1 -0
- package/src/extensions/erc20/write/transferBatch.ts +78 -0
- package/src/react/web/ui/ConnectWallet/screens/Buy/BuyScreen.tsx +42 -12
- package/src/react/web/ui/ConnectWallet/screens/Buy/PayWIthCreditCard.tsx +1 -1
- package/src/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatSteps.tsx +5 -5
- package/src/react/web/ui/ConnectWallet/screens/Buy/fiat/FiatTxDetailsTable.tsx +1 -1
- package/src/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.ts +1 -5
- package/src/react/web/ui/ConnectWallet/screens/Buy/main/useUISelectionStates.ts +1 -6
- package/src/react/web/ui/ConnectWallet/screens/Buy/swap/ConfirmationScreen.tsx +2 -2
- package/src/react/web/ui/ConnectWallet/screens/Buy/swap/Fees.tsx +4 -4
- package/src/react/web/ui/ConnectWallet/screens/Buy/swap/PayWithCrypto.tsx +1 -1
- package/src/react/web/ui/ConnectWallet/screens/Buy/tx-history/BuyTxHistoryButton.tsx +1 -1
- package/src/react/web/ui/ConnectWallet/screens/Buy/tx-history/TokenInfoRow.tsx +1 -1
- package/src/utils/hashing/hashTypedData.test.ts +207 -0
- package/src/utils/hashing/hashTypedData.ts +210 -0
- package/src/utils/jwt/decode-jwt.ts +1 -1
- package/src/utils/jwt/refresh-jwt.ts +2 -2
- package/src/version.ts +1 -1
- package/src/wallets/smart/index.ts +19 -9
- package/src/wallets/smart/lib/bundler.ts +56 -9
- package/src/wallets/smart/lib/calls.ts +67 -28
- package/src/wallets/smart/lib/paymaster.ts +12 -13
- package/src/wallets/smart/lib/userop.ts +74 -30
- package/src/wallets/smart/types.ts +6 -6
@@ -1,7 +1,10 @@
|
|
1
|
+
import type { Chain } from "../../../chains/types.js";
|
2
|
+
import type { ThirdwebContract } from "../../../contract/contract.js";
|
1
3
|
import type { PreparedTransaction } from "../../../transaction/prepare-transaction.js";
|
2
4
|
import type { TransactionReceipt } from "../../../transaction/types.js";
|
3
5
|
import type { Hex } from "../../../utils/encoding/hex.js";
|
4
|
-
import type {
|
6
|
+
import type { Account } from "../../interfaces/wallet.js";
|
7
|
+
import type { BundlerOptions, SmartWalletOptions, UserOperation } from "../types.js";
|
5
8
|
/**
|
6
9
|
* Wait for the user operation to be mined.
|
7
10
|
* @param args - The options and user operation hash
|
@@ -36,14 +39,20 @@ export declare function waitForUserOpReceipt(args: BundlerOptions & {
|
|
36
39
|
*
|
37
40
|
* const userOp = await createUnsignedUserOp({
|
38
41
|
* transaction,
|
39
|
-
*
|
42
|
+
* accountContract,
|
43
|
+
* sponsorGas,
|
44
|
+
* overrides,
|
40
45
|
* });
|
41
46
|
* ```
|
42
47
|
* @walletUtils
|
43
48
|
*/
|
44
49
|
export declare function createUnsignedUserOp(args: {
|
45
50
|
transaction: PreparedTransaction;
|
46
|
-
|
51
|
+
factoryContract: ThirdwebContract;
|
52
|
+
accountContract: ThirdwebContract;
|
53
|
+
adminAddress: string;
|
54
|
+
sponsorGas: boolean;
|
55
|
+
overrides?: SmartWalletOptions["overrides"];
|
47
56
|
}): Promise<UserOperation>;
|
48
57
|
/**
|
49
58
|
* Sign a user operation.
|
@@ -64,6 +73,8 @@ export declare function createUnsignedUserOp(args: {
|
|
64
73
|
*/
|
65
74
|
export declare function signUserOp(args: {
|
66
75
|
userOp: UserOperation;
|
67
|
-
|
76
|
+
chain: Chain;
|
77
|
+
entrypointAddress?: string;
|
78
|
+
adminAccount: Account;
|
68
79
|
}): Promise<UserOperation>;
|
69
80
|
//# sourceMappingURL=userop.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"userop.d.ts","sourceRoot":"","sources":["../../../../../src/wallets/smart/lib/userop.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"userop.d.ts","sourceRoot":"","sources":["../../../../../src/wallets/smart/lib/userop.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAGtE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6CAA6C,CAAC;AACvF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAGxE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gCAAgC,CAAC;AAK1D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,KAAK,EACV,cAAc,EACd,kBAAkB,EAClB,aAAa,EACd,MAAM,aAAa,CAAC;AAerB;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,cAAc,GAAG;IACrB,UAAU,EAAE,GAAG,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GACA,OAAO,CAAC,kBAAkB,CAAC,CAY7B;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE;IAC/C,WAAW,EAAE,mBAAmB,CAAC;IACjC,eAAe,EAAE,gBAAgB,CAAC;IAClC,eAAe,EAAE,gBAAgB,CAAC;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,kBAAkB,CAAC,WAAW,CAAC,CAAC;CAC7C,GAAG,OAAO,CAAC,aAAa,CAAC,CAyIzB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE;IACrC,MAAM,EAAE,aAAa,CAAC;IACtB,KAAK,EAAE,KAAK,CAAC;IACb,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,YAAY,EAAE,OAAO,CAAC;CACvB,GAAG,OAAO,CAAC,aAAa,CAAC,CAmBzB"}
|
@@ -36,10 +36,12 @@ export type SmartAccountOptions = Prettify<Omit<SmartWalletOptions, "chain" | "g
|
|
36
36
|
accountContract: ThirdwebContract;
|
37
37
|
client: ThirdwebClient;
|
38
38
|
}>;
|
39
|
-
export type BundlerOptions =
|
39
|
+
export type BundlerOptions = {
|
40
|
+
bundlerUrl?: string;
|
41
|
+
entrypointAddress?: string;
|
40
42
|
chain: Chain;
|
41
43
|
client: ThirdwebClient;
|
42
|
-
}
|
44
|
+
};
|
43
45
|
export type SmartWalletConnectionOptions = {
|
44
46
|
personalAccount: Account;
|
45
47
|
client: ThirdwebClient;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/wallets/smart/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,KAAK,EAAE,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
2
2
|
"name": "thirdweb",
|
3
|
-
"version": "5.34.0-nightly-
|
3
|
+
"version": "5.34.0-nightly-95c9d3d92406de619cb1e4cccc61b0766dd2a0d4-20240708205331",
|
4
4
|
"repository": {
|
5
5
|
"type": "git",
|
6
6
|
"url": "git+https://github.com/thirdweb-dev/js.git#main"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { decodeJWT } from "../../utils/jwt/decode-jwt.js";
|
2
2
|
import type { JWTPayload } from "../../utils/jwt/types.js";
|
3
3
|
import { verifyEOASignature } from "../verify-signature.js";
|
4
4
|
import type { AuthOptions } from "./types.js";
|
@@ -26,7 +26,7 @@ export type VerifyJWTResult =
|
|
26
26
|
*/
|
27
27
|
export function verifyJWT(options: AuthOptions) {
|
28
28
|
return async (params: VerifyJWTParams): Promise<VerifyJWTResult> => {
|
29
|
-
const { payload, signature } =
|
29
|
+
const { payload, signature } = decodeJWT(params.jwt);
|
30
30
|
|
31
31
|
if (!options.adminAccount) {
|
32
32
|
throw new Error("No admin account provided. Cannot verify JWT.");
|
@@ -0,0 +1,66 @@
|
|
1
|
+
import { parseSignature } from "viem";
|
2
|
+
import { describe, expect, test } from "vitest";
|
3
|
+
import { FORKED_ETHEREUM_CHAIN } from "../../test/src/chains.js";
|
4
|
+
import { TEST_CLIENT } from "../../test/src/test-clients.js";
|
5
|
+
import { ANVIL_PKEY_A, TEST_ACCOUNT_A } from "../../test/src/test-wallets.js";
|
6
|
+
import { toBytes } from "../utils/encoding/to-bytes.js";
|
7
|
+
import { hashMessage } from "../utils/hashing/hashMessage.js";
|
8
|
+
import { signMessage } from "../utils/signatures/sign-message.js";
|
9
|
+
import { verifyHash } from "./verify-hash.js";
|
10
|
+
|
11
|
+
describe("verifyHash", async () => {
|
12
|
+
describe("EOA", async () => {
|
13
|
+
test("hex", async () => {
|
14
|
+
const signature = signMessage({
|
15
|
+
message: "hello world",
|
16
|
+
privateKey: ANVIL_PKEY_A,
|
17
|
+
});
|
18
|
+
|
19
|
+
expect(
|
20
|
+
verifyHash({
|
21
|
+
address: TEST_ACCOUNT_A.address,
|
22
|
+
hash: hashMessage("hello world"),
|
23
|
+
signature,
|
24
|
+
client: TEST_CLIENT,
|
25
|
+
chain: FORKED_ETHEREUM_CHAIN,
|
26
|
+
}),
|
27
|
+
).resolves.toBe(true);
|
28
|
+
});
|
29
|
+
|
30
|
+
test("bytes", async () => {
|
31
|
+
const signature = signMessage({
|
32
|
+
message: "hello world",
|
33
|
+
privateKey: ANVIL_PKEY_A,
|
34
|
+
});
|
35
|
+
|
36
|
+
expect(
|
37
|
+
verifyHash({
|
38
|
+
address: TEST_ACCOUNT_A.address,
|
39
|
+
hash: hashMessage("hello world"),
|
40
|
+
signature: toBytes(signature),
|
41
|
+
client: TEST_CLIENT,
|
42
|
+
chain: FORKED_ETHEREUM_CHAIN,
|
43
|
+
}),
|
44
|
+
).resolves.toBe(true);
|
45
|
+
});
|
46
|
+
|
47
|
+
test("object", async () => {
|
48
|
+
const signature = signMessage({
|
49
|
+
message: "hello world",
|
50
|
+
privateKey: ANVIL_PKEY_A,
|
51
|
+
});
|
52
|
+
|
53
|
+
expect(
|
54
|
+
verifyHash({
|
55
|
+
address: TEST_ACCOUNT_A.address,
|
56
|
+
hash: hashMessage("hello world"),
|
57
|
+
signature: parseSignature(signature),
|
58
|
+
client: TEST_CLIENT,
|
59
|
+
chain: FORKED_ETHEREUM_CHAIN,
|
60
|
+
}),
|
61
|
+
).resolves.toBe(true);
|
62
|
+
});
|
63
|
+
});
|
64
|
+
});
|
65
|
+
|
66
|
+
// TODO: Create utilities to mock smart accounts on anvil so we can test them here
|
@@ -0,0 +1,126 @@
|
|
1
|
+
import { equalBytes } from "@noble/curves/abstract/utils";
|
2
|
+
import { type Signature, encodeDeployData, serializeSignature } from "viem";
|
3
|
+
import type { Chain } from "../chains/types.js";
|
4
|
+
import type { ThirdwebClient } from "../client/client.js";
|
5
|
+
import { getContract } from "../contract/contract.js";
|
6
|
+
import { eth_call } from "../rpc/actions/eth_call.js";
|
7
|
+
import { getRpcClient } from "../rpc/rpc.js";
|
8
|
+
import { fromBytes } from "../utils/encoding/from-bytes.js";
|
9
|
+
import { type Hex, isHex } from "../utils/encoding/hex.js";
|
10
|
+
import { toBytes } from "../utils/encoding/to-bytes.js";
|
11
|
+
import { DEFAULT_ACCOUNT_FACTORY } from "../wallets/smart/lib/constants.js";
|
12
|
+
import {
|
13
|
+
universalSignatureValidatorAbi,
|
14
|
+
universalSignatureValidatorByteCode,
|
15
|
+
} from "./constants.js";
|
16
|
+
import { isErc6492Signature } from "./is-erc6492-signature.js";
|
17
|
+
import { serializeErc6492Signature } from "./serialize-erc6492-signature.js";
|
18
|
+
|
19
|
+
export type VerifyHashParams = {
|
20
|
+
hash: Hex;
|
21
|
+
signature: string | Uint8Array | Signature;
|
22
|
+
address: string;
|
23
|
+
client: ThirdwebClient;
|
24
|
+
chain: Chain;
|
25
|
+
accountFactory?: {
|
26
|
+
address: string;
|
27
|
+
verificationCalldata: Hex;
|
28
|
+
};
|
29
|
+
};
|
30
|
+
|
31
|
+
/**
|
32
|
+
* @description Verify that an address created the provided signature for a given hash using [ERC-6492](https://eips.ethereum.org/EIPS/eip-6492). This function is interoperable with all wallet types, including EOAs.
|
33
|
+
* This function should rarely be used directly, instead use @see {import("./verify-signature.js")} and @see {import("./verify-typed-data.js")}}
|
34
|
+
*
|
35
|
+
* @param {Hex} options.hash The hash that was signed
|
36
|
+
* @param {string | Uint8Array | Signature} options.signature The signature that was signed
|
37
|
+
* @param {string} options.address The address that signed the hash
|
38
|
+
* @param {ThirdwebClient} options.client The Thirdweb client
|
39
|
+
* @param {Chain} options.chain The chain that the address is on. For an EOA, this can be any chain.
|
40
|
+
* @param {string} [options.accountFactory.address] The address of the account factory that created the account if using a smart account with a custom account factory
|
41
|
+
* @param {Hex} [options.accountFactory.verificationCalldata] The calldata that was used to create the account if using a smart account with a custom account factory
|
42
|
+
*
|
43
|
+
* @returns {Promise<boolean>} A promise that resolves to `true` if the signature is valid, or `false` otherwise.
|
44
|
+
*
|
45
|
+
* @example
|
46
|
+
* ```ts
|
47
|
+
* import { verifyHash } from "thirdweb/utils";
|
48
|
+
* const isValid = await verifyHash({
|
49
|
+
* hash: "0x1234",
|
50
|
+
* signature: "0x1234",
|
51
|
+
* address: "0x1234",
|
52
|
+
* client,
|
53
|
+
* chain,
|
54
|
+
* });
|
55
|
+
* ```
|
56
|
+
*
|
57
|
+
* @auth
|
58
|
+
*/
|
59
|
+
export async function verifyHash({
|
60
|
+
hash,
|
61
|
+
signature,
|
62
|
+
address,
|
63
|
+
client,
|
64
|
+
chain,
|
65
|
+
accountFactory,
|
66
|
+
}: VerifyHashParams): Promise<boolean> {
|
67
|
+
const signatureHex = (() => {
|
68
|
+
if (isHex(signature)) return signature;
|
69
|
+
if (typeof signature === "object" && "r" in signature && "s" in signature)
|
70
|
+
return serializeSignature(signature);
|
71
|
+
if (signature instanceof Uint8Array) return fromBytes(signature, "hex");
|
72
|
+
// We should never hit this but TS doesn't know that
|
73
|
+
throw new Error(
|
74
|
+
`Invalid signature type for signature ${signature}: ${typeof signature}`,
|
75
|
+
);
|
76
|
+
})();
|
77
|
+
|
78
|
+
const accountContract = getContract({
|
79
|
+
address,
|
80
|
+
chain,
|
81
|
+
client,
|
82
|
+
});
|
83
|
+
|
84
|
+
const wrappedSignature = await (async () => {
|
85
|
+
// If this sigature was already wrapped for ERC-6492, carry on
|
86
|
+
if (isErc6492Signature(signatureHex)) return signatureHex;
|
87
|
+
|
88
|
+
// If the contract is already deployed, return the original signature
|
89
|
+
const { isContractDeployed } = await import(
|
90
|
+
"../utils/bytecode/is-contract-deployed.js"
|
91
|
+
);
|
92
|
+
const isDeployed = await isContractDeployed(accountContract);
|
93
|
+
if (!isDeployed) return signatureHex;
|
94
|
+
|
95
|
+
// Otherwise, serialize the signature for ERC-6492 validation
|
96
|
+
return serializeErc6492Signature({
|
97
|
+
address: accountFactory?.address ?? DEFAULT_ACCOUNT_FACTORY,
|
98
|
+
data: accountFactory?.verificationCalldata ?? "0x",
|
99
|
+
signature: signatureHex,
|
100
|
+
});
|
101
|
+
})();
|
102
|
+
|
103
|
+
const verificationData = encodeDeployData({
|
104
|
+
abi: universalSignatureValidatorAbi,
|
105
|
+
args: [address, hash, wrappedSignature],
|
106
|
+
bytecode: universalSignatureValidatorByteCode,
|
107
|
+
});
|
108
|
+
|
109
|
+
const rpcRequest = getRpcClient({
|
110
|
+
chain,
|
111
|
+
client,
|
112
|
+
});
|
113
|
+
|
114
|
+
try {
|
115
|
+
const result = await eth_call(rpcRequest, {
|
116
|
+
data: verificationData,
|
117
|
+
});
|
118
|
+
|
119
|
+
const hexResult = isHex(result) ? toBytes(result) : result;
|
120
|
+
return equalBytes(hexResult, toBytes("0x1"));
|
121
|
+
} catch (error) {
|
122
|
+
// TODO: Improve overall RPC error handling so we can tell if this was an actual verification failure or some other error
|
123
|
+
// Verification failed somehow
|
124
|
+
return false;
|
125
|
+
}
|
126
|
+
}
|
@@ -1,27 +1,10 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
3
|
-
type Signature,
|
4
|
-
encodeDeployData,
|
5
|
-
recoverAddress,
|
6
|
-
serializeSignature,
|
7
|
-
} from "viem";
|
1
|
+
import { type Signature, recoverAddress } from "viem";
|
8
2
|
import type { Chain } from "../chains/types.js";
|
9
3
|
import type { ThirdwebClient } from "../client/client.js";
|
10
|
-
import { getContract } from "../contract/contract.js";
|
11
|
-
import { eth_call } from "../rpc/actions/eth_call.js";
|
12
|
-
import { getRpcClient } from "../rpc/rpc.js";
|
13
|
-
import { fromBytes } from "../utils/encoding/from-bytes.js";
|
14
4
|
import { type Hex, isHex } from "../utils/encoding/hex.js";
|
15
|
-
import { toBytes } from "../utils/encoding/to-bytes.js";
|
16
5
|
import { hashMessage } from "../utils/hashing/hashMessage.js";
|
17
6
|
import type { Prettify } from "../utils/type-utils.js";
|
18
|
-
import {
|
19
|
-
import {
|
20
|
-
universalSignatureValidatorAbi,
|
21
|
-
universalSignatureValidatorByteCode,
|
22
|
-
} from "./constants.js";
|
23
|
-
import { isErc6492Signature } from "./is-erc6492-signature.js";
|
24
|
-
import { serializeErc6492Signature } from "./serialize-erc6492-signature.js";
|
7
|
+
import { verifyHash } from "./verify-hash.js";
|
25
8
|
|
26
9
|
export type VerifyEOASignatureParams = {
|
27
10
|
message: string;
|
@@ -113,69 +96,15 @@ export async function verifyContractWalletSignature({
|
|
113
96
|
client,
|
114
97
|
accountFactory,
|
115
98
|
}: VerifyContractWalletSignatureParams) {
|
116
|
-
console.log("verifyContractWalletSignature");
|
117
99
|
const messageHash = hashMessage(message);
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
if (typeof signature === "object" && "r" in signature && "s" in signature)
|
122
|
-
return serializeSignature(signature);
|
123
|
-
if (signature instanceof Uint8Array) return fromBytes(signature, "hex");
|
124
|
-
// We should never hit this but TS doesn't know that
|
125
|
-
throw new Error(
|
126
|
-
`Invalid signature type for signature ${signature}: ${typeof signature}`,
|
127
|
-
);
|
128
|
-
})();
|
129
|
-
|
130
|
-
const accountContract = getContract({
|
100
|
+
return verifyHash({
|
101
|
+
hash: messageHash,
|
102
|
+
signature,
|
131
103
|
address,
|
132
|
-
chain,
|
133
104
|
client,
|
134
|
-
});
|
135
|
-
|
136
|
-
const wrappedSignature = await (async () => {
|
137
|
-
// If this sigature was already wrapped for ERC-6492, carry on
|
138
|
-
if (isErc6492Signature(signatureHex)) return signatureHex;
|
139
|
-
|
140
|
-
// If the contract is already deployed, return the original signature
|
141
|
-
const { isContractDeployed } = await import(
|
142
|
-
"../utils/bytecode/is-contract-deployed.js"
|
143
|
-
);
|
144
|
-
const isDeployed = await isContractDeployed(accountContract);
|
145
|
-
if (!isDeployed) return signatureHex;
|
146
|
-
|
147
|
-
// Otherwise, serialize the signature for ERC-6492 validation
|
148
|
-
return serializeErc6492Signature({
|
149
|
-
address: accountFactory?.address ?? DEFAULT_ACCOUNT_FACTORY,
|
150
|
-
data: accountFactory?.verificationCalldata ?? "0x",
|
151
|
-
signature: signatureHex,
|
152
|
-
});
|
153
|
-
})();
|
154
|
-
|
155
|
-
const verificationData = encodeDeployData({
|
156
|
-
abi: universalSignatureValidatorAbi,
|
157
|
-
args: [address, messageHash, wrappedSignature],
|
158
|
-
bytecode: universalSignatureValidatorByteCode,
|
159
|
-
});
|
160
|
-
|
161
|
-
const rpcRequest = getRpcClient({
|
162
105
|
chain,
|
163
|
-
|
106
|
+
accountFactory,
|
164
107
|
});
|
165
|
-
|
166
|
-
try {
|
167
|
-
const result = await eth_call(rpcRequest, {
|
168
|
-
data: verificationData,
|
169
|
-
});
|
170
|
-
|
171
|
-
const hexResult = isHex(result) ? toBytes(result) : result;
|
172
|
-
return equalBytes(hexResult, toBytes("0x1"));
|
173
|
-
} catch (error) {
|
174
|
-
console.log("error", error);
|
175
|
-
// TODO: Improve overall RPC error handling so we can tell if this was an actual verification failure or some other error
|
176
|
-
// Verification failed somehow
|
177
|
-
return false;
|
178
|
-
}
|
179
108
|
}
|
180
109
|
|
181
110
|
export type VerifySignatureParams = Prettify<
|
@@ -0,0 +1,82 @@
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
2
|
+
import { TEST_CLIENT } from "../../test/src/test-clients.js";
|
3
|
+
import { ANVIL_PKEY_A, TEST_ACCOUNT_A } from "../../test/src/test-wallets.js";
|
4
|
+
import { typedData } from "../../test/src/typed-data.js";
|
5
|
+
import { mainnet } from "../chains/chain-definitions/ethereum.js";
|
6
|
+
import { signTypedData } from "../utils/signatures/sign-typed-data.js";
|
7
|
+
import { verifyTypedData } from "./verify-typed-data.js";
|
8
|
+
|
9
|
+
describe("verifyTypedData", async () => {
|
10
|
+
test("valid EOA signature", async () => {
|
11
|
+
const signature = signTypedData({
|
12
|
+
...typedData.basic,
|
13
|
+
primaryType: "Mail",
|
14
|
+
privateKey: ANVIL_PKEY_A,
|
15
|
+
});
|
16
|
+
|
17
|
+
expect(
|
18
|
+
await verifyTypedData({
|
19
|
+
...typedData.basic,
|
20
|
+
primaryType: "Mail",
|
21
|
+
address: TEST_ACCOUNT_A.address,
|
22
|
+
signature,
|
23
|
+
chain: mainnet,
|
24
|
+
client: TEST_CLIENT,
|
25
|
+
}),
|
26
|
+
).toBe(true);
|
27
|
+
});
|
28
|
+
|
29
|
+
test("invalid EOA signature", async () => {
|
30
|
+
expect(
|
31
|
+
await verifyTypedData({
|
32
|
+
...typedData.basic,
|
33
|
+
primaryType: "Mail",
|
34
|
+
address: TEST_ACCOUNT_A.address,
|
35
|
+
signature: "0xdead",
|
36
|
+
chain: mainnet,
|
37
|
+
client: TEST_CLIENT,
|
38
|
+
}),
|
39
|
+
).toBe(false);
|
40
|
+
});
|
41
|
+
|
42
|
+
test("valid smart account signature", async () => {
|
43
|
+
expect(
|
44
|
+
await verifyTypedData({
|
45
|
+
...typedData.basic,
|
46
|
+
primaryType: "Mail",
|
47
|
+
address: "0x3FCf42e10CC70Fe75A62EB3aDD6D305Aa840d145",
|
48
|
+
signature:
|
49
|
+
"0x79d756d805073dc97b7bc885b0d56ddf319a2599530fe1e178c2a7de5be88980068d24f20a79b318ea0a84d33ae06f93db77e4235e5d9eeb8b1d7a63922ada3e1c",
|
50
|
+
chain: mainnet,
|
51
|
+
client: TEST_CLIENT,
|
52
|
+
}),
|
53
|
+
).toBe(true);
|
54
|
+
});
|
55
|
+
|
56
|
+
test("invalid smart account signature", async () => {
|
57
|
+
expect(
|
58
|
+
await verifyTypedData({
|
59
|
+
...typedData.basic,
|
60
|
+
primaryType: "Mail",
|
61
|
+
address: "0x3FCf42e10CC70Fe75A62EB3aDD6D305Aa840d145",
|
62
|
+
signature: "0xdead",
|
63
|
+
chain: mainnet,
|
64
|
+
client: TEST_CLIENT,
|
65
|
+
}),
|
66
|
+
).toBe(false);
|
67
|
+
});
|
68
|
+
|
69
|
+
test("non-existent account", async () => {
|
70
|
+
expect(
|
71
|
+
await verifyTypedData({
|
72
|
+
...typedData.basic,
|
73
|
+
primaryType: "Mail",
|
74
|
+
address: "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
|
75
|
+
signature:
|
76
|
+
"0x79d756d805073dc97b7bc885b0d56ddf319a2599530fe1e178c2a7de5be88980068d24f20a79b318ea0a84d33ae06f93db77e4235e5d9eeb8b1d7a63922ada3e1c",
|
77
|
+
chain: mainnet,
|
78
|
+
client: TEST_CLIENT,
|
79
|
+
}),
|
80
|
+
).toBe(false);
|
81
|
+
});
|
82
|
+
});
|
@@ -0,0 +1,110 @@
|
|
1
|
+
import type { Signature, TypedData, TypedDataDefinition } from "viem";
|
2
|
+
import { hashTypedData } from "viem";
|
3
|
+
import type { Chain } from "../chains/types.js";
|
4
|
+
import type { ThirdwebClient } from "../client/client.js";
|
5
|
+
import type { Hex } from "../utils/encoding/hex.js";
|
6
|
+
import type { HashTypedDataParams } from "../utils/hashing/hashTypedData.js";
|
7
|
+
import { type VerifyHashParams, verifyHash } from "./verify-hash.js";
|
8
|
+
|
9
|
+
export type VerifyTypedDataParams<
|
10
|
+
typedData extends TypedData | Record<string, unknown> = TypedData,
|
11
|
+
primaryType extends keyof typedData | "EIP712Domain" = keyof typedData,
|
12
|
+
> = Omit<VerifyHashParams, "hash"> &
|
13
|
+
TypedDataDefinition<typedData, primaryType> & {
|
14
|
+
address: string;
|
15
|
+
signature: string | Uint8Array | Signature;
|
16
|
+
client: ThirdwebClient;
|
17
|
+
chain: Chain;
|
18
|
+
accountFactory?: {
|
19
|
+
address: string;
|
20
|
+
verificationCalldata: Hex;
|
21
|
+
};
|
22
|
+
};
|
23
|
+
|
24
|
+
/**
|
25
|
+
* @description Verify am [EIP-712](https://eips.ethereum.org/EIPS/eip-712) typed data signature. This function is interoperable with all wallet types (smart accounts or EOAs).
|
26
|
+
*
|
27
|
+
* @param {string} options.address The address that signed the typed data
|
28
|
+
* @param {string | Uint8Array | Signature} options.signature The signature that was signed
|
29
|
+
* @param {ThirdwebClient} options.client The Thirdweb client
|
30
|
+
* @param {Chain} options.chain The chain that the address is on. For an EOA, this can be any chain.
|
31
|
+
* @param {string} [options.accountFactory.address] The address of the account factory that created the account if using a smart account with a custom account factory
|
32
|
+
* @param {Hex} [options.accountFactory.verificationCalldata] The calldata that was used to create the account if using a smart account with a custom account factory
|
33
|
+
* @param {typeof VerifyTypedDataParams.message} options.message The EIP-712 message that was signed.
|
34
|
+
* @param {typeof VerifyTypedDataParams.domain} options.domain The EIP-712 domain that was signed.
|
35
|
+
* @param {typeof VerifyTypedDataParams.primaryType} options.primaryType The EIP-712 primary type that was signed.
|
36
|
+
* @param {typeof VerifyTypedDataParams.types} options.types The EIP-712 types that were signed.
|
37
|
+
*
|
38
|
+
* @returns {Promise<boolean>} A promise that resolves to `true` if the signature is valid, or `false` otherwise.
|
39
|
+
*
|
40
|
+
* @example
|
41
|
+
* ```ts
|
42
|
+
* import { verifyTypedData } from "thirdweb/utils";
|
43
|
+
* const isValid = await verifyTypedData({
|
44
|
+
* address: "0x...",
|
45
|
+
* signature: "0x...",
|
46
|
+
* client,
|
47
|
+
* chain,
|
48
|
+
* domain: {
|
49
|
+
name: "Ether Mail",
|
50
|
+
version: "1",
|
51
|
+
chainId: 1,
|
52
|
+
verifyingContract: "0x0000000000000000000000000000000000000000",
|
53
|
+
},
|
54
|
+
* primaryType: "Mail",
|
55
|
+
* types: {
|
56
|
+
Person: [
|
57
|
+
{ name: "name", type: "string" },
|
58
|
+
{ name: "wallet", type: "address" },
|
59
|
+
],
|
60
|
+
Mail: [
|
61
|
+
{ name: "from", type: "Person" },
|
62
|
+
{ name: "to", type: "Person" },
|
63
|
+
{ name: "contents", type: "string" },
|
64
|
+
],
|
65
|
+
},
|
66
|
+
message: {
|
67
|
+
from: {
|
68
|
+
name: "Cow",
|
69
|
+
wallet: "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
|
70
|
+
},
|
71
|
+
to: {
|
72
|
+
name: "Bob",
|
73
|
+
wallet: "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB",
|
74
|
+
},
|
75
|
+
contents: "Hello, Bob!",
|
76
|
+
},
|
77
|
+
* });
|
78
|
+
* ```
|
79
|
+
*
|
80
|
+
* @auth
|
81
|
+
*/
|
82
|
+
export async function verifyTypedData<
|
83
|
+
typedData extends TypedData | Record<string, unknown>,
|
84
|
+
primaryType extends keyof typedData | "EIP712Domain",
|
85
|
+
>({
|
86
|
+
address,
|
87
|
+
signature,
|
88
|
+
client,
|
89
|
+
chain,
|
90
|
+
accountFactory,
|
91
|
+
message,
|
92
|
+
domain,
|
93
|
+
primaryType,
|
94
|
+
types,
|
95
|
+
}: VerifyTypedDataParams<typedData, primaryType>): Promise<boolean> {
|
96
|
+
const messageHash = hashTypedData({
|
97
|
+
message,
|
98
|
+
domain,
|
99
|
+
primaryType,
|
100
|
+
types,
|
101
|
+
} as HashTypedDataParams);
|
102
|
+
return verifyHash({
|
103
|
+
hash: messageHash,
|
104
|
+
signature,
|
105
|
+
address,
|
106
|
+
chain,
|
107
|
+
client,
|
108
|
+
accountFactory,
|
109
|
+
});
|
110
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { defineChain } from "../utils.js";
|
2
|
+
|
3
|
+
export const blast = /* @__PURE__ */ defineChain({
|
4
|
+
id: 81457,
|
5
|
+
name: "Blast",
|
6
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
7
|
+
blockExplorers: [
|
8
|
+
{
|
9
|
+
name: "Blastscan",
|
10
|
+
url: "https://blastscan.io",
|
11
|
+
apiUrl: "https://api.blastscan.io/api",
|
12
|
+
},
|
13
|
+
],
|
14
|
+
});
|
package/src/exports/chains.ts
CHANGED
@@ -21,6 +21,7 @@ export { baseSepolia } from "../chains/chain-definitions/base-sepolia.js";
|
|
21
21
|
export { base } from "../chains/chain-definitions/base.js";
|
22
22
|
// mainnet = alias for ethereum
|
23
23
|
export { ethereum, mainnet } from "../chains/chain-definitions/ethereum.js";
|
24
|
+
export { blast } from "../chains/chain-definitions/blast.js";
|
24
25
|
export { optimismSepolia } from "../chains/chain-definitions/optimism-sepolia.js";
|
25
26
|
export { optimism } from "../chains/chain-definitions/optimism.js";
|
26
27
|
export { lineaSepolia } from "../chains/chain-definitions/linea-sepolia.js";
|
@@ -33,6 +33,10 @@ export {
|
|
33
33
|
transferFrom,
|
34
34
|
type TransferFromParams,
|
35
35
|
} from "../../extensions/erc20/write/transferFrom.js";
|
36
|
+
export {
|
37
|
+
transferBatch,
|
38
|
+
type TransferBatchParams,
|
39
|
+
} from "../../extensions/erc20/write/transferBatch.js";
|
36
40
|
export {
|
37
41
|
approve,
|
38
42
|
type ApproveParams,
|
package/src/exports/utils.ts
CHANGED
@@ -149,3 +149,11 @@ export { stringify } from "../utils/json.js";
|
|
149
149
|
// values
|
150
150
|
// ------------------------------------------------
|
151
151
|
export { maxUint256 } from "viem";
|
152
|
+
|
153
|
+
// ------------------------------------------------
|
154
|
+
// jwt
|
155
|
+
// ------------------------------------------------
|
156
|
+
export { decodeJWT } from "../utils/jwt/decode-jwt.js";
|
157
|
+
export { encodeJWT, type JWTPayloadInput } from "../utils/jwt/encode-jwt.js";
|
158
|
+
export { refreshJWT, type RefreshJWTParams } from "../utils/jwt/refresh-jwt.js";
|
159
|
+
export type { JWTPayload } from "../utils/jwt/types.js";
|
@@ -1,6 +1,19 @@
|
|
1
1
|
export { smartWallet } from "../../wallets/smart/smart-wallet.js";
|
2
2
|
|
3
|
-
export {
|
3
|
+
export {
|
4
|
+
waitForUserOpReceipt,
|
5
|
+
createUnsignedUserOp,
|
6
|
+
signUserOp,
|
7
|
+
} from "../../wallets/smart/lib/userop.js";
|
8
|
+
|
9
|
+
export {
|
10
|
+
getUserOpReceipt,
|
11
|
+
bundleUserOp,
|
12
|
+
getUserOpGasFees,
|
13
|
+
estimateUserOpGas,
|
14
|
+
} from "../../wallets/smart/lib/bundler.js";
|
15
|
+
|
16
|
+
export { predictAddress } from "../../wallets/smart/lib/calls.js";
|
4
17
|
|
5
18
|
export type {
|
6
19
|
SmartWalletConnectionOptions,
|