1. make `knip` a part of `packages/thirdweb`
2. clean up all the things
3. ???
4. profit
<!-- start pr-codex -->
---
## PR-Codex overview
This PR focuses on removing unused files, updating types, and deprecating constants.
### Detailed summary
- Removed unused files related to benchmarks, wallets, and UI components
- Updated type definitions in various files
- Deprecated and replaced constant `ADDRESS_ZERO` with `ZERO_ADDRESS`
> The following files were skipped due to too many changes: `packages/thirdweb/src/react/web/ui/ConnectWallet/Details.tsx`, `packages/thirdweb/src/pay/utils/definitions.ts`, `packages/thirdweb/src/utils/hashing/sha256.ts`, `packages/thirdweb/src/wallets/eip5792/show-calls-status.ts`, `packages/thirdweb/src/extensions/modules/ClaimableERC20/mint.ts`, `packages/thirdweb/src/react/web/wallets/shared/ConnectWalletSocialOptions.tsx`, `apps/portal/package.json`, `packages/thirdweb/src/extensions/modules/ClaimableERC721/mint.ts`, `packages/thirdweb/src/utils/hashing/hashMessage.ts`, `packages/thirdweb/src/react/native/ui/components/text.tsx`, `packages/thirdweb/src/utils/promise/resolve-promised-value.ts`, `packages/thirdweb/src/auth/core/verify-jwt.ts`, `packages/thirdweb/src/utils/hashing/keccak256.ts`, `packages/thirdweb/src/utils/uint8-array.ts`, `packages/thirdweb/src/react/core/design-system/CustomThemeProvider.tsx`, `packages/thirdweb/src/react/native/ui/connect/SendScreen.tsx`, `packages/thirdweb/src/react/web/ui/MediaRenderer/MediaRenderer.tsx`, `packages/thirdweb/src/gas/estimate-l1-fee.ts`, `packages/thirdweb/src/react/web/ui/ConnectWallet/WalletSelector.tsx`, `packages/thirdweb/src/extensions/modules/MintableERC721/mintWithSignature.ts`, `packages/thirdweb/src/react/native/ui/connect/ExternalWalletsList.tsx`, `packages/thirdweb/src/exports/extensions/erc1155.ts`, `packages/thirdweb/src/extensions/modules/ClaimableERC1155/mint.ts`, `packages/thirdweb/src/extensions/modules/MintableERC1155/mintWithSignature.ts`, `packages/thirdweb/src/utils/encoding/helpers/trim.ts`, `packages/thirdweb/src/wallets/utils/getTokenBalance.ts`, `apps/dashboard/knip.json`, `packages/thirdweb/src/react/native/ui/connect/TokenListScreen.tsx`, `packages/thirdweb/src/extensions/vote/write/executeProposal.ts`, `packages/thirdweb/src/react/native/ui/components/spinner.tsx`, `packages/thirdweb/src/react/web/ui/MediaRenderer/ModelViewer.tsx`, `packages/thirdweb/src/transaction/extract-error.ts`, `packages/thirdweb/src/react/native/ui/components/button.tsx`, `packages/thirdweb/src/extensions/erc1155/write/updateTokenURI.ts`, `packages/thirdweb/src/wallets/interfaces/wallet.ts`, `packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/useSwapSupportedChains.ts`, `packages/thirdweb/src/utils/storage/walletStorage.ts`, `packages/thirdweb/src/wallets/in-app/native/native-connector.ts`, `packages/thirdweb/src/extensions/erc20/write/sigMint.ts`, `packages/thirdweb/src/extensions/erc721/write/updateTokenURI.ts`, `packages/thirdweb/src/react/web/wallets/ecosystem/EcosystemWalletFormUI.tsx`, `packages/thirdweb/src/wallets/eip5792/wait-for-bundle.ts`, `packages/thirdweb/src/utils/jwt/jwt-header.ts`, `packages/thirdweb/src/extensions/modules/MintableERC20/mintWithSignature.ts`, `packages/thirdweb/src/exports/modules.ts`, `packages/thirdweb/src/react/web/wallets/in-app/InAppWalletFormUI.tsx`, `packages/thirdweb/src/transaction/actions/wait-for-tx-receipt.ts`, `packages/thirdweb/src/auth/core/generate-jwt.ts`, `packages/thirdweb/src/react/core/hooks/transaction/useSendTransaction.ts`, `packages/thirdweb/src/exports/extensions/erc1271.ts`, `packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/main/useBuyTxStates.ts`, `packages/thirdweb/src/contract/deployment/publisher.ts`, `packages/thirdweb/src/extensions/erc721/drops/write/updateMetadata.ts`, `packages/thirdweb/src/extensions/erc1155/drops/write/updateMetadata.ts`, `packages/thirdweb/src/extensions/prebuilts/deploy-marketplace.ts`, `packages/thirdweb/src/wallets/in-app/native/auth/index.ts`, `packages/thirdweb/src/wallets/in-app/native/helpers/auth/middleware.ts`, `packages/thirdweb/src/utils/platform.ts`, `.github/CODEOWNERS`, `packages/thirdweb/src/wallets/in-app/web/lib/auth/index.ts`, `packages/thirdweb/src/react/core/utils/structuralSharing.ts`, `packages/thirdweb/src/react/core/hooks/transaction/useSendAndConfirmTransaction.ts`, `packages/thirdweb/src/extensions/prebuilts/get-required-transactions.ts`, `packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/FiatDetailsScreen.tsx`, `packages/thirdweb/src/extensions/ens/resolve-l2-name.ts`, `packages/thirdweb/src/utils/any-evm/deploy-metadata.ts`, `packages/thirdweb/src/cli/commands/generate/utils.ts`, `packages/thirdweb/src/extensions/farcaster/eip712Signatures/keyRequestSignature.ts`, `packages/thirdweb/src/extensions/airdrop/write/airdropERC20WithSignature.ts`, `packages/thirdweb/src/extensions/airdrop/write/airdropERC721WithSignature.ts`, `packages/thirdweb/src/transaction/actions/zksync/send-eip712-transaction.ts`, `packages/thirdweb/src/wallets/in-app/web/utils/iFrameCommunication/InAppWalletIframeCommunicator.ts`, `packages/thirdweb/src/utils/any-evm/zksync/constants.ts`, `packages/thirdweb/src/extensions/marketplace/direct-listings/utils.ts`, `packages/thirdweb/src/transaction/actions/gasless/send-gasless-transaction.ts`, `packages/thirdweb/src/extensions/prebuilts/deploy-vote.ts`, `packages/thirdweb/src/react/web/ui/components/Drawer.tsx`, `packages/thirdweb/src/extensions/airdrop/write/airdropERC1155WithSignature.ts`, `packages/thirdweb/src/react/core/hooks/others/useWalletBalance.ts`, `packages/thirdweb/src/extensions/permissions/utils.ts`, `packages/thirdweb/src/wallets/in-app/native/helpers/auth/logout.ts`, `packages/thirdweb/src/wallets/smart/lib/utils.ts`, `packages/thirdweb/src/react/web/ui/components/buttons.tsx`, `packages/thirdweb/src/react/web/ui/prebuilt/thirdweb/ClaimButton/index.tsx`, `packages/thirdweb/src/wallets/wallet-connect/receiver/index.ts`, `packages/thirdweb/src/transaction/actions/gasless/providers/engine.ts`, `packages/thirdweb/src/transaction/actions/gasless/providers/openzeppelin.ts`, `packages/thirdweb/src/wallets/in-app/web/types.ts`, `packages/thirdweb/src/extensions/airdrop/write/claimERC20.ts`, `packages/thirdweb/test/globalSetup.ts`, `packages/thirdweb/src/extensions/erc721/read/getAllOwners.ts`, `packages/thirdweb/src/wallets/smart/lib/userop.ts`, `packages/thirdweb/src/wallets/in-app/native/helpers/wallet/retrieval.ts`, `packages/thirdweb/src/wallets/in-app/web/lib/iframe-wallet.ts`, `packages/thirdweb/src/react/web/ui/TransactionButton/TransactionModal.tsx`, `packages/thirdweb/src/react/native/ui/connect/ConnectedModal.tsx`, `packages/thirdweb/src/extensions/erc4337/account/common.ts`, `packages/thirdweb/test/vitest.config.ts`, `packages/thirdweb/src/exports/extensions/farcaster.ts`, `packages/thirdweb/src/exports/chains.ts`, `packages/thirdweb/src/extensions/erc4337/account/permissions.test.ts`, `packages/thirdweb/src/wallets/in-app/core/constants/settings.ts`, `packages/thirdweb/scripts/typedoc.mjs`, `packages/thirdweb/src/extensions/airdrop/write/merkleInfoERC20.ts`, `packages/thirdweb/src/utils/extensions/drops/hash-entry.ts`, `packages/thirdweb/src/extensions/farcaster/eip712Signatures/registerSignature.ts`, `packages/thirdweb/src/react/native/ui/icons/svgs.ts`, `packages/thirdweb/src/transaction/actions/gasless/providers/biconomy.ts`, `packages/thirdweb/src/extensions/farcaster/eip712Signatures/addSignature.ts`, `packages/thirdweb/src/react/web/ui/AutoConnect/AutoConnect.tsx`, `packages/thirdweb/src/react/native/ui/AutoConnect/AutoConnect.tsx`, `packages/service-utils/package.json`, `packages/thirdweb/src/stories/utils.tsx`, `packages/thirdweb/src/react/core/utils/defaultTokens.ts`, `package.json`, `packages/thirdweb/knip.json`, `packages/thirdweb/src/pay/buyWithCrypto/getStatus.ts`, `packages/thirdweb/src/exports/extensions/marketplace.ts`, `packages/thirdweb/src/utils/semver.ts`, `packages/thirdweb/src/extensions/uniswap/read/getUniswapV3Pools.ts`, `apps/dashboard/package.json`, `packages/thirdweb/src/utils/royalty-engine.ts`, `packages/react-native-adapter/package.json`, `packages/thirdweb/src/wallets/in-app/core/authentication/types.ts`, `packages/thirdweb/src/contract/deployment/deploy-deterministic.ts`, `packages/thirdweb/src/contract/deployment/utils/infra.ts`, `packages/thirdweb/src/wallets/injected/index.ts`, `packages/thirdweb/src/wallets/smart/lib/packUserOp.ts`, `packages/thirdweb/src/wallets/in-app/native/helpers/storage/local.ts`, `packages/thirdweb/src/react/web/ui/components/ChainIcon.tsx`, `packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/pay-transactions/BuyTxHistory.tsx`, `packages/thirdweb/src/wallets/in-app/native/helpers/constants.ts`, `packages/thirdweb/src/wallets/in-app/native/helpers/api/fetchers.ts`, `packages/thirdweb/package.json`, `packages/thirdweb/src/react/core/utils/walletIcon.ts`, `pnpm-lock.yaml`
> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}`
<!-- end pr-codex -->
227 lines
6.7 KiB
TypeScript
227 lines
6.7 KiB
TypeScript
import type { Address } from "abitype";
|
|
import { encodeAbiParameters } from "../../../utils/abi/encodeAbiParameters.js";
|
|
import type { Hex } from "../../../utils/encoding/hex.js";
|
|
import type { Prettify } from "../../../utils/type-utils.js";
|
|
import type { Account } from "../../../wallets/interfaces/wallet.js";
|
|
import { SIGNED_KEY_REQUEST_VALIDATOR_ADDRESS } from "../constants.js";
|
|
|
|
const SIGNED_KEY_REQUEST_VALIDATOR_EIP_712_DOMAIN = {
|
|
name: "Farcaster SignedKeyRequestValidator", // EIP-712 domain data for the SignedKeyRequestValidator.
|
|
version: "1",
|
|
chainId: 10,
|
|
verifyingContract: SIGNED_KEY_REQUEST_VALIDATOR_ADDRESS,
|
|
} as const;
|
|
|
|
const SIGNED_KEY_REQUEST_TYPE = [
|
|
{ name: "requestFid", type: "uint256" },
|
|
{ name: "key", type: "bytes" },
|
|
{ name: "deadline", type: "uint256" },
|
|
];
|
|
|
|
const SIGNED_KEY_REQUEST_VALIDATOR_EIP_712_TYPES = {
|
|
domain: SIGNED_KEY_REQUEST_VALIDATOR_EIP_712_DOMAIN,
|
|
types: { SignedKeyRequest: SIGNED_KEY_REQUEST_TYPE },
|
|
} as const;
|
|
|
|
const SIGNED_KEY_REQUEST_METADATA_ABI = [
|
|
{
|
|
components: [
|
|
{
|
|
name: "requestFid",
|
|
type: "uint256",
|
|
},
|
|
{
|
|
name: "requestSigner",
|
|
type: "address",
|
|
},
|
|
{
|
|
name: "signature",
|
|
type: "bytes",
|
|
},
|
|
{
|
|
name: "deadline",
|
|
type: "uint256",
|
|
},
|
|
],
|
|
name: "SignedKeyRequestMetadata",
|
|
type: "tuple",
|
|
},
|
|
] as const;
|
|
|
|
/**
|
|
* @extension FARCASTER
|
|
*/
|
|
export type SignedKeyRequestMessage = {
|
|
/** FID of user or app requesting key */
|
|
requestFid: bigint;
|
|
/** Signer public key */
|
|
key: Hex;
|
|
/** Unix timestamp when this message expires */
|
|
deadline: bigint;
|
|
};
|
|
|
|
/**
|
|
* @extension FARCASTER
|
|
*/
|
|
export type SignKeyRequestOptions = {
|
|
account: Account;
|
|
message: SignedKeyRequestMessage;
|
|
};
|
|
|
|
/**
|
|
* Prepares the data required for signing a key request using EIP-712 typed data signing.
|
|
* This includes the domain, types, primary type, and the message to be signed.
|
|
* @param message - The message to be signed, containing the request FID, key, and deadline.
|
|
* @returns An object containing the domain, types, primary type, and the message for EIP-712 signing.
|
|
* @extension FARCASTER
|
|
* @example
|
|
* ```ts
|
|
* const message = {
|
|
* requestFid: 123456789n,
|
|
* key: "0x04bfc...",
|
|
* deadline: 1657758061n,
|
|
* };
|
|
* const eip712Data = getKeyRequestData(message);
|
|
* ```
|
|
*/
|
|
export function getKeyRequestData(message: SignedKeyRequestMessage) {
|
|
return {
|
|
...SIGNED_KEY_REQUEST_VALIDATOR_EIP_712_TYPES,
|
|
primaryType: "SignedKeyRequest" as const,
|
|
message,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Signs a key request message using EIP-712 typed data signing.
|
|
* This function prepares the data for signing, signs it with the provided account, and returns the signature.
|
|
* @param options - The options for signing the key request, including the account and the message.
|
|
* @returns A promise that resolves to the signature of the key request.
|
|
* @extension FARCASTER
|
|
* @example
|
|
* ```ts
|
|
* const message = {
|
|
* requestFid: 123456789n,
|
|
* key: "0x04bfc...",
|
|
* deadline: 1657758061n,
|
|
* };
|
|
*
|
|
* const signature = signKeyRequest({ account: signerAccount, message });
|
|
* ```
|
|
*/
|
|
export async function signKeyRequest(
|
|
options: SignKeyRequestOptions,
|
|
): Promise<Hex> {
|
|
const data = getKeyRequestData(options.message);
|
|
return options.account.signTypedData(data);
|
|
}
|
|
|
|
/**
|
|
* @extension FARCASTER
|
|
*/
|
|
export type SignedKeyRequestMetadataOptions = Prettify<
|
|
{
|
|
message: SignedKeyRequestMessage;
|
|
} & (
|
|
| {
|
|
account: Account;
|
|
}
|
|
| { keyRequestSignature: Hex; accountAddress: Address }
|
|
)
|
|
>;
|
|
|
|
/**
|
|
* Encodes the signed key request metadata into a hexadecimal string.
|
|
* This function takes in the request signer's address, the key request signature, the request Fid, and the deadline,
|
|
* and returns the encoded ABI parameters as a hexadecimal string. It's used to prepare the metadata for transactions
|
|
* involving signed key requests.
|
|
* @param options - The options for encoding the signed key request metadata.
|
|
* @param options.requestSigner - The address of the new signer.
|
|
* @param options.keyRequestSignature - The hexadecimal string of the key request signature.
|
|
* @param options.requestFid - The Fid of the app account.
|
|
* @param options.deadline - The deadline of the request.
|
|
* @returns The encoded ABI parameters as a hexadecimal string.
|
|
* @extension FARCASTER
|
|
* @example
|
|
* ```ts
|
|
* const encodedMetadata = encodeSignedKeyRequestMetadata({
|
|
* requestSigner: "0x123...",
|
|
* keyRequestSignature: "0xabcd...",
|
|
* requestFid: 123456789n,
|
|
* deadline: 1657758061n,
|
|
* });
|
|
* ```
|
|
*/
|
|
export function encodeSignedKeyRequestMetadata(options: {
|
|
requestSigner: Address;
|
|
keyRequestSignature: Hex;
|
|
requestFid: bigint;
|
|
deadline: bigint;
|
|
}): Hex {
|
|
return encodeAbiParameters(SIGNED_KEY_REQUEST_METADATA_ABI, [
|
|
{
|
|
requestFid: options.requestFid,
|
|
requestSigner: options.requestSigner,
|
|
signature: options.keyRequestSignature,
|
|
deadline: options.deadline,
|
|
},
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Generates the signed key request metadata to add a signer to an account.
|
|
* This function can either sign a new key request using an account object or use an existing key request signature.
|
|
* It prepares the metadata necessary for transactions involving signed key requests.
|
|
* @param options - The options for signing the key request or using an existing signature.
|
|
* @returns A promise that resolves to the hexadecimal string of the encoded ABI parameters.
|
|
* @extension FARCASTER
|
|
* @example
|
|
* ```ts
|
|
* import { getSignedKeyRequestMetadata } from "thirdweb/extensions/farcaster";
|
|
*
|
|
* // Using an existing signature
|
|
* const signedMetadata = await getSignedKeyRequestMetadata({
|
|
* keyRequestSignature: "0xabcd...",
|
|
* accountAddress: "0x123...",
|
|
* message: {
|
|
* requestFid: 123456789n,
|
|
* deadline: 1657758061n,
|
|
* },
|
|
* });
|
|
*
|
|
* // Signing a new key request
|
|
* const signedMetadata = await getSignedKeyRequestMetadata({
|
|
* account,
|
|
* message: {
|
|
* requestFid: 123456789n,
|
|
* deadline: 1657758061n,
|
|
* },
|
|
* });
|
|
* ```
|
|
*/
|
|
export async function getSignedKeyRequestMetadata(
|
|
options: SignedKeyRequestMetadataOptions,
|
|
): Promise<Hex> {
|
|
let signature: Hex;
|
|
if ("keyRequestSignature" in options) {
|
|
signature = options.keyRequestSignature;
|
|
} else if ("account" in options) {
|
|
signature = await signKeyRequest({
|
|
account: options.account,
|
|
message: options.message,
|
|
});
|
|
} else {
|
|
throw new Error(
|
|
"Invalid options, expected an account or key request signature to be provided",
|
|
);
|
|
}
|
|
|
|
return encodeSignedKeyRequestMetadata({
|
|
requestSigner:
|
|
"account" in options ? options.account.address : options.accountAddress,
|
|
keyRequestSignature: signature,
|
|
requestFid: options.message.requestFid,
|
|
deadline: options.message.deadline,
|
|
});
|
|
}
|