| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,5 @@ | |||
| 1 | + --- | ||
| 2 | + "thirdweb": patch | ||
| 3 | + --- | ||
| 4 | + | ||
| 5 | + Migrated underlying functionality to Ox | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,7 @@ name: Auto Author Assign | |||
| 2 | 2 | ||
| 3 | 3 | on: | |
| 4 | 4 | pull_request: | |
| 5 | - types: [opened, reopened] | ||
| 5 | + types: [opened, reopened, ready_for_review, draft] | ||
| 6 | 6 | ||
| 7 | 7 | permissions: | |
| 8 | 8 | pull-requests: write | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,4 @@ | |||
| 1 | - import { sliceHex } from "viem"; | ||
| 1 | + import * as ox__Hex from "ox/Hex"; | ||
| 2 | 2 | import type { Hex } from "../utils/encoding/hex.js"; | |
| 3 | 3 | import { ERC_6492_MAGIC_VALUE } from "./constants.js"; | |
| 4 | 4 | ||
@@ -19,5 +19,5 @@ import { ERC_6492_MAGIC_VALUE } from "./constants.js"; | |||
| 19 | 19 | * @auth | |
| 20 | 20 | */ | |
| 21 | 21 | export function isErc6492Signature(signature: Hex): boolean { | |
| 22 | - return sliceHex(signature, -32) === ERC_6492_MAGIC_VALUE; | ||
| 22 | + return ox__Hex.slice(signature, -32) === ERC_6492_MAGIC_VALUE; | ||
| 23 | 23 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,6 @@ | |||
| 1 | - import { decodeAbiParameters, isErc6492Signature } from "viem"; | ||
| 1 | + import * as ox__AbiParameters from "ox/AbiParameters"; | ||
| 2 | + import * as ox__Address from "ox/Address"; | ||
| 3 | + import { WrappedSignature as ox__WrappedSignature } from "ox/erc6492"; | ||
| 2 | 4 | import type { Hex } from "../utils/encoding/hex.js"; | |
| 3 | 5 | import type { OneOf } from "../utils/type-utils.js"; | |
| 4 | 6 | import type { Erc6492Signature } from "./types.js"; | |
@@ -29,13 +31,17 @@ export type ParseErc6492SignatureReturnType = OneOf< | |||
| 29 | 31 | export function parseErc6492Signature( | |
| 30 | 32 | signature: Hex, | |
| 31 | 33 | ): ParseErc6492SignatureReturnType { | |
| 32 | - if (!isErc6492Signature(signature)) { | ||
| 34 | + if (!ox__WrappedSignature.validate(signature)) { | ||
| 33 | 35 | return { signature }; | |
| 34 | 36 | } | |
| 35 | 37 | ||
| 36 | - const [address, data, originalSignature] = decodeAbiParameters( | ||
| 38 | + const [address, data, originalSignature] = ox__AbiParameters.decode( | ||
| 37 | 39 | [{ type: "address" }, { type: "bytes" }, { type: "bytes" }], | |
| 38 | 40 | signature, | |
| 39 | 41 | ); | |
| 40 | - return { address: address, data, signature: originalSignature }; | ||
| 42 | + return { | ||
| 43 | + address: ox__Address.checksum(address), | ||
| 44 | + data, | ||
| 45 | + signature: originalSignature, | ||
| 46 | + }; | ||
| 41 | 47 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,12 +1,8 @@ | |||
| 1 | - import { | ||
| 2 | - type Signature, | ||
| 3 | - encodeDeployData, | ||
| 4 | - encodeFunctionData, | ||
| 5 | - isErc6492Signature, | ||
| 6 | - serializeSignature, | ||
| 7 | - universalSignatureValidatorAbi, | ||
| 8 | - universalSignatureValidatorByteCode, | ||
| 9 | - } from "viem"; | ||
| 1 | + import * as ox__Abi from "ox/Abi"; | ||
| 2 | + import * as ox__AbiConstructor from "ox/AbiConstructor"; | ||
| 3 | + import * as ox__AbiFunction from "ox/AbiFunction"; | ||
| 4 | + import * as ox__Signature from "ox/Signature"; | ||
| 5 | + import { WrappedSignature as ox__WrappedSignature } from "ox/erc6492"; | ||
| 10 | 6 | import type { Chain } from "../chains/types.js"; | |
| 11 | 7 | import type { ThirdwebClient } from "../client/client.js"; | |
| 12 | 8 | import { type ThirdwebContract, getContract } from "../contract/contract.js"; | |
@@ -20,7 +16,7 @@ import { serializeErc6492Signature } from "./serialize-erc6492-signature.js"; | |||
| 20 | 16 | ||
| 21 | 17 | export type VerifyHashParams = { | |
| 22 | 18 | hash: Hex; | |
| 23 | - signature: string | Uint8Array | Signature; | ||
| 19 | + signature: string | Uint8Array | ox__Signature.Signature; | ||
| 24 | 20 | address: string; | |
| 25 | 21 | client: ThirdwebClient; | |
| 26 | 22 | chain: Chain; | |
@@ -71,7 +67,7 @@ export async function verifyHash({ | |||
| 71 | 67 | const signatureHex = (() => { | |
| 72 | 68 | if (isHex(signature)) return signature; | |
| 73 | 69 | if (typeof signature === "object" && "r" in signature && "s" in signature) | |
| 74 | - return serializeSignature(signature); | ||
| 70 | + return ox__Signature.toHex(signature); | ||
| 75 | 71 | if (signature instanceof Uint8Array) return fromBytes(signature, "hex"); | |
| 76 | 72 | // We should never hit this but TS doesn't know that | |
| 77 | 73 | throw new Error( | |
@@ -85,7 +81,7 @@ export async function verifyHash({ | |||
| 85 | 81 | if (!accountFactory) return signatureHex; | |
| 86 | 82 | ||
| 87 | 83 | // If this sigature was already wrapped for ERC-6492, carry on | |
| 88 | - if (isErc6492Signature(signatureHex)) return signatureHex; | ||
| 84 | + if (ox__WrappedSignature.validate(signatureHex)) return signatureHex; | ||
| 89 | 85 | ||
| 90 | 86 | // Otherwise, serialize the signature for ERC-6492 validation | |
| 91 | 87 | return serializeErc6492Signature({ | |
@@ -100,23 +96,23 @@ export async function verifyHash({ | |||
| 100 | 96 | data: Hex; | |
| 101 | 97 | }; | |
| 102 | 98 | const zkSyncChain = await isZkSyncChain(chain); | |
| 99 | + const abi = ox__Abi.from(ox__WrappedSignature.universalSignatureValidatorAbi); | ||
| 103 | 100 | if (zkSyncChain) { | |
| 104 | 101 | // zksync chains dont support deploying code with eth_call | |
| 105 | 102 | // need to call a deployed contract instead | |
| 106 | 103 | verificationData = { | |
| 107 | 104 | to: ZKSYNC_VALIDATOR_ADDRESS, | |
| 108 | - data: encodeFunctionData({ | ||
| 109 | - abi: universalSignatureValidatorAbi, | ||
| 110 | - functionName: "isValidSig", | ||
| 111 | - args: [address, hash, wrappedSignature], | ||
| 112 | - }), | ||
| 105 | + data: ox__AbiFunction.encodeData( | ||
| 106 | + ox__AbiFunction.fromAbi(abi, "isValidSig"), | ||
| 107 | + [address, hash, wrappedSignature], | ||
| 108 | + ), | ||
| 113 | 109 | }; | |
| 114 | 110 | } else { | |
| 111 | + const validatorConstructor = ox__AbiConstructor.fromAbi(abi); | ||
| 115 | 112 | verificationData = { | |
| 116 | - data: encodeDeployData({ | ||
| 117 | - abi: universalSignatureValidatorAbi, | ||
| 113 | + data: ox__AbiConstructor.encode(validatorConstructor, { | ||
| 118 | 114 | args: [address, hash, wrappedSignature], | |
| 119 | - bytecode: universalSignatureValidatorByteCode, | ||
| 115 | + bytecode: ox__WrappedSignature.universalSignatureValidatorBytecode, | ||
| 120 | 116 | }), | |
| 121 | 117 | }; | |
| 122 | 118 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,10 +1,16 @@ | |||
| 1 | + import * as ox__Bytes from "ox/Bytes"; | ||
| 1 | 2 | import { describe, expect, it, test } from "vitest"; | |
| 2 | 3 | import { FORKED_ETHEREUM_CHAIN } from "../../test/src/chains.js"; | |
| 3 | 4 | import { TEST_CLIENT } from "../../test/src/test-clients.js"; | |
| 4 | 5 | import { TEST_ACCOUNT_A } from "../../test/src/test-wallets.js"; | |
| 5 | - import { mainnet } from "../chains/chain-definitions/ethereum.js"; | ||
| 6 | + import { ethereum, mainnet } from "../chains/chain-definitions/ethereum.js"; | ||
| 6 | 7 | import { sepolia } from "../chains/chain-definitions/sepolia.js"; | |
| 7 | - import { verifyEOASignature, verifySignature } from "./verify-signature.js"; | ||
| 8 | + import { smartWallet } from "../wallets/smart/smart-wallet.js"; | ||
| 9 | + import { | ||
| 10 | + verifyContractWalletSignature, | ||
| 11 | + verifyEOASignature, | ||
| 12 | + verifySignature, | ||
| 13 | + } from "./verify-signature.js"; | ||
| 8 | 14 | ||
| 9 | 15 | describe("verifyEOASignature", () => { | |
| 10 | 16 | test("should return true for a valid signature", async () => { | |
@@ -98,3 +104,43 @@ describe.runIf(process.env.TW_SECRET_KEY)( | |||
| 98 | 104 | }); | |
| 99 | 105 | }, | |
| 100 | 106 | ); | |
| 107 | + | ||
| 108 | + describe.runIf(process.env.TW_SECRET_KEY)( | ||
| 109 | + "verifyContractWalletSignature", | ||
| 110 | + async () => { | ||
| 111 | + const message = "Hakuna matata"; | ||
| 112 | + const wallet = smartWallet({ | ||
| 113 | + chain: ethereum, | ||
| 114 | + gasless: true, | ||
| 115 | + }); | ||
| 116 | + const smartAccount = await wallet.connect({ | ||
| 117 | + client: TEST_CLIENT, | ||
| 118 | + personalAccount: TEST_ACCOUNT_A, | ||
| 119 | + }); | ||
| 120 | + | ||
| 121 | + test("should verify a smart account signature", async () => { | ||
| 122 | + const rawSignature = await smartAccount.signMessage({ message }); | ||
| 123 | + const result = await verifyContractWalletSignature({ | ||
| 124 | + signature: rawSignature, | ||
| 125 | + message, | ||
| 126 | + address: smartAccount.address, | ||
| 127 | + chain: ethereum, | ||
| 128 | + client: TEST_CLIENT, | ||
| 129 | + }); | ||
| 130 | + expect(result).toBe(true); | ||
| 131 | + }); | ||
| 132 | + | ||
| 133 | + test("should verify a smart account signature as bytes", async () => { | ||
| 134 | + const rawSignature = await smartAccount.signMessage({ message }); | ||
| 135 | + const bytesSignature = ox__Bytes.fromHex(rawSignature); | ||
| 136 | + const result = await verifyContractWalletSignature({ | ||
| 137 | + signature: bytesSignature, | ||
| 138 | + message, | ||
| 139 | + address: smartAccount.address, | ||
| 140 | + chain: ethereum, | ||
| 141 | + client: TEST_CLIENT, | ||
| 142 | + }); | ||
| 143 | + expect(result).toBe(true); | ||
| 144 | + }); | ||
| 145 | + }, | ||
| 146 | + ); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,17 +1,26 @@ | |||
| 1 | - import { type SignableMessage, type Signature, recoverAddress } from "viem"; | ||
| 1 | + import * as ox__Bytes from "ox/Bytes"; | ||
| 2 | + import * as ox__Secp256k1 from "ox/Secp256k1"; | ||
| 3 | + import * as ox__Signature from "ox/Signature"; | ||
| 2 | 4 | import type { Chain } from "../chains/types.js"; | |
| 3 | 5 | import type { ThirdwebClient } from "../client/client.js"; | |
| 4 | 6 | import { type Hex, isHex } from "../utils/encoding/hex.js"; | |
| 5 | 7 | import { hashMessage } from "../utils/hashing/hashMessage.js"; | |
| 6 | 8 | import type { Prettify } from "../utils/type-utils.js"; | |
| 7 | 9 | import { verifyHash } from "./verify-hash.js"; | |
| 8 | 10 | ||
| 11 | + type Message = Prettify< | ||
| 12 | + | string | ||
| 13 | + | { | ||
| 14 | + raw: Hex | Uint8Array; | ||
| 15 | + } | ||
| 16 | + >; | ||
| 17 | + | ||
| 9 | 18 | /** | |
| 10 | 19 | * @auth | |
| 11 | 20 | */ | |
| 12 | 21 | export type VerifyEOASignatureParams = { | |
| 13 | - message: string | SignableMessage; | ||
| 14 | - signature: string | Uint8Array | Signature; | ||
| 22 | + message: string | Message; | ||
| 23 | + signature: string | Uint8Array; | ||
| 15 | 24 | address: string; | |
| 16 | 25 | }; | |
| 17 | 26 | ||
@@ -39,9 +48,9 @@ export async function verifyEOASignature(options: VerifyEOASignatureParams) { | |||
| 39 | 48 | return false; | |
| 40 | 49 | } | |
| 41 | 50 | ||
| 42 | - const recoveredAddress = await recoverAddress({ | ||
| 43 | - hash: messageHash, | ||
| 44 | - signature: options.signature, | ||
| 51 | + const recoveredAddress = ox__Secp256k1.recoverAddress({ | ||
| 52 | + payload: messageHash, | ||
| 53 | + signature: ox__Signature.fromHex(options.signature), | ||
| 45 | 54 | }); | |
| 46 | 55 | ||
| 47 | 56 | if (recoveredAddress.toLowerCase() === options.address.toLowerCase()) { | |
@@ -103,9 +112,17 @@ export async function verifyContractWalletSignature({ | |||
| 103 | 112 | accountFactory, | |
| 104 | 113 | }: VerifyContractWalletSignatureParams) { | |
| 105 | 114 | const messageHash = hashMessage(message); | |
| 115 | + | ||
| 116 | + const parsedSignature = (() => { | ||
| 117 | + if (ox__Bytes.validate(signature)) { | ||
| 118 | + return ox__Bytes.toHex(signature); | ||
| 119 | + } | ||
| 120 | + return signature; | ||
| 121 | + })(); | ||
| 122 | + | ||
| 106 | 123 | return verifyHash({ | |
| 107 | 124 | hash: messageHash, | |
| 108 | - signature, | ||
| 125 | + signature: parsedSignature, | ||
| 109 | 126 | address, | |
| 110 | 127 | client, | |
| 111 | 128 | chain, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,18 +1,20 @@ | |||
| 1 | - import type { Signature, TypedData, TypedDataDefinition } from "viem"; | ||
| 2 | - import { hashTypedData } from "viem"; | ||
| 1 | + import type * as ox__Signature from "ox/Signature"; | ||
| 2 | + import * as ox__TypedData from "ox/TypedData"; | ||
| 3 | 3 | import type { Chain } from "../chains/types.js"; | |
| 4 | 4 | import type { ThirdwebClient } from "../client/client.js"; | |
| 5 | 5 | import type { Hex } from "../utils/encoding/hex.js"; | |
| 6 | 6 | import type { HashTypedDataParams } from "../utils/hashing/hashTypedData.js"; | |
| 7 | 7 | import { type VerifyHashParams, verifyHash } from "./verify-hash.js"; | |
| 8 | 8 | ||
| 9 | 9 | export type VerifyTypedDataParams< | |
| 10 | - typedData extends TypedData | Record<string, unknown> = TypedData, | ||
| 10 | + typedData extends | ||
| 11 | + | ox__TypedData.TypedData | ||
| 12 | + | Record<string, unknown> = ox__TypedData.TypedData, | ||
| 11 | 13 | primaryType extends keyof typedData | "EIP712Domain" = keyof typedData, | |
| 12 | 14 | > = Omit<VerifyHashParams, "hash"> & | |
| 13 | - TypedDataDefinition<typedData, primaryType> & { | ||
| 15 | + ox__TypedData.Definition<typedData, primaryType> & { | ||
| 14 | 16 | address: string; | |
| 15 | - signature: string | Uint8Array | Signature; | ||
| 17 | + signature: string | Uint8Array | ox__Signature.Signature; | ||
| 16 | 18 | client: ThirdwebClient; | |
| 17 | 19 | chain: Chain; | |
| 18 | 20 | accountFactory?: { | |
@@ -80,7 +82,7 @@ export type VerifyTypedDataParams< | |||
| 80 | 82 | * @auth | |
| 81 | 83 | */ | |
| 82 | 84 | export async function verifyTypedData< | |
| 83 | - typedData extends TypedData | Record<string, unknown>, | ||
| 85 | + typedData extends ox__TypedData.TypedData | Record<string, unknown>, | ||
| 84 | 86 | primaryType extends keyof typedData | "EIP712Domain", | |
| 85 | 87 | >({ | |
| 86 | 88 | address, | |
@@ -93,7 +95,7 @@ export async function verifyTypedData< | |||
| 93 | 95 | primaryType, | |
| 94 | 96 | types, | |
| 95 | 97 | }: VerifyTypedDataParams<typedData, primaryType>): Promise<boolean> { | |
| 96 | - const messageHash = hashTypedData({ | ||
| 98 | + const messageHash = ox__TypedData.getSignPayload({ | ||
| 97 | 99 | message, | |
| 98 | 100 | domain, | |
| 99 | 101 | primaryType, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,12 @@ | |||
| 1 | - import { getContractAddress } from "viem"; | ||
| 1 | + import * as ox__ContractAddress from "ox/ContractAddress"; | ||
| 2 | 2 | import { getGasPrice } from "../../../gas/get-gas-price.js"; | |
| 3 | 3 | import { eth_getBalance } from "../../../rpc/actions/eth_getBalance.js"; | |
| 4 | 4 | import { eth_sendRawTransaction } from "../../../rpc/actions/eth_sendRawTransaction.js"; | |
| 5 | 5 | import { getRpcClient } from "../../../rpc/rpc.js"; | |
| 6 | 6 | import { sendTransaction } from "../../../transaction/actions/send-transaction.js"; | |
| 7 | 7 | import { waitForReceipt } from "../../../transaction/actions/wait-for-tx-receipt.js"; | |
| 8 | 8 | import { prepareTransaction } from "../../../transaction/prepare-transaction.js"; | |
| 9 | + import { getAddress } from "../../../utils/address.js"; | ||
| 9 | 10 | import { isEIP155Enforced } from "../../../utils/any-evm/is-eip155-enforced.js"; | |
| 10 | 11 | import { getKeylessTransaction } from "../../../utils/any-evm/keyless-transaction.js"; | |
| 11 | 12 | import { isContractDeployed } from "../../../utils/bytecode/is-contract-deployed.js"; | |
@@ -226,15 +227,15 @@ async function _getCreate2FactoryDeploymentInfo( | |||
| 226 | 227 | }, | |
| 227 | 228 | signature: SIGNATURE, | |
| 228 | 229 | }); | |
| 229 | - const create2FactoryAddress = getContractAddress({ | ||
| 230 | + const create2FactoryAddress = ox__ContractAddress.from({ | ||
| 230 | 231 | from: deploymentTransaction.signerAddress, | |
| 231 | 232 | nonce: 0n, | |
| 232 | 233 | }); | |
| 233 | 234 | ||
| 234 | 235 | return { | |
| 235 | 236 | ...deploymentTransaction, | |
| 236 | 237 | valueToSend: gasPrice * gas, | |
| 237 | - predictedAddress: create2FactoryAddress, | ||
| 238 | + predictedAddress: getAddress(create2FactoryAddress), | ||
| 238 | 239 | }; | |
| 239 | 240 | } | |
| 240 | 241 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,6 @@ | |||
| 1 | - import type { Abi } from "abitype"; | ||
| 2 | - import { decodeAbiParameters } from "viem"; | ||
| 1 | + import type * as ox__Abi from "ox/Abi"; | ||
| 2 | + import * as ox__AbiConstructor from "ox/AbiConstructor"; | ||
| 3 | + import * as ox__AbiParameters from "ox/AbiParameters"; | ||
| 3 | 4 | import { eth_getTransactionByHash } from "../../rpc/actions/eth_getTransactionByHash.js"; | |
| 4 | 5 | import { getRpcClient } from "../../rpc/rpc.js"; | |
| 5 | 6 | import type { ThirdwebContract } from "../contract.js"; | |
@@ -10,19 +11,9 @@ type FetchConstructorParamsOptions = { | |||
| 10 | 11 | contract: ThirdwebContract; | |
| 11 | 12 | explorerApiUrl: string; | |
| 12 | 13 | explorerApiKey: string; | |
| 13 | - abi: Abi; | ||
| 14 | + abi: ox__Abi.Abi; | ||
| 14 | 15 | }; | |
| 15 | 16 | ||
| 16 | - // TODO: move to abi helpers (?) | ||
| 17 | - function extractConstructorParamsFromAbi(abi: Abi) { | ||
| 18 | - for (const input of abi) { | ||
| 19 | - if (input.type === "constructor") { | ||
| 20 | - return input.inputs || []; | ||
| 21 | - } | ||
| 22 | - } | ||
| 23 | - return []; | ||
| 24 | - } | ||
| 25 | - | ||
| 26 | 17 | const RequestStatus = { | |
| 27 | 18 | OK: "1", | |
| 28 | 19 | NOTOK: "0", | |
@@ -37,7 +28,8 @@ const RequestStatus = { | |||
| 37 | 28 | export async function fetchConstructorParams( | |
| 38 | 29 | options: FetchConstructorParamsOptions, | |
| 39 | 30 | ): Promise<string> { | |
| 40 | - const constructorParamTypes = extractConstructorParamsFromAbi(options.abi); | ||
| 31 | + const abiConstructor = ox__AbiConstructor.fromAbi(options.abi); | ||
| 32 | + const constructorParamTypes = ox__AbiParameters.from(abiConstructor.inputs); | ||
| 41 | 33 | if (constructorParamTypes.length === 0) { | |
| 42 | 34 | return ""; | |
| 43 | 35 | } | |
@@ -114,7 +106,8 @@ export async function fetchConstructorParams( | |||
| 114 | 106 | try { | |
| 115 | 107 | // sanity check that the constructor params are valid | |
| 116 | 108 | // TODO: should we sanity check after each attempt? | |
| 117 | - decodeAbiParameters(constructorParamTypes, `0x${constructorArgs}`); | ||
| 109 | + | ||
| 110 | + ox__AbiParameters.decode(constructorParamTypes, `0x${constructorArgs}`); | ||
| 118 | 111 | } catch { | |
| 119 | 112 | throw new Error( | |
| 120 | 113 | "Verifying this contract requires it to be published. Run `npx thirdweb publish` to publish this contract, then try again.", | |
| Back | FazBrowse Home | New Git URL |
0 commit comments