1- import { Type , type Static } from "@sinclair/typebox" ;
1+ import { type Static , Type } from "@sinclair/typebox" ;
22import type { FastifyInstance } from "fastify" ;
33import { StatusCodes } from "http-status-codes" ;
44import { prepareContractCall , resolveMethod } from "thirdweb" ;
5- import { parseAbiParams , type AbiFunction } from "thirdweb/utils" ;
5+ import { type AbiFunction , parseAbiParams } from "thirdweb/utils" ;
66import { getContractV5 } from "../../../../shared/utils/cache/get-contractv5" ;
77import { prettifyError } from "../../../../shared/utils/error" ;
88import { queueTransaction } from "../../../../shared/utils/transaction/queue-transation" ;
@@ -16,11 +16,12 @@ import {
1616import { txOverridesWithValueSchema } from "../../../schemas/tx-overrides" ;
1717import {
1818 maybeAddress ,
19- requiredAddress ,
20- walletWithAAHeaderSchema ,
19+ type walletWithAAHeaderSchema ,
20+ walletWithAAOrEnclaveHeaderSchema ,
2121} from "../../../schemas/wallet" ;
2222import { sanitizeAbi , sanitizeFunctionName } from "../../../utils/abi" ;
2323import { getChainIdFromChain } from "../../../utils/chain" ;
24+ import { parseEnclaveHeaders } from "../../../utils/convertor" ;
2425import { parseTransactionOverrides } from "../../../utils/transaction-overrides" ;
2526
2627// INPUT
@@ -60,7 +61,7 @@ export async function writeToContract(fastify: FastifyInstance) {
6061 tags : [ "Contract" ] ,
6162 operationId : "write" ,
6263 params : contractParamSchema ,
63- headers : walletWithAAHeaderSchema ,
64+ headers : walletWithAAOrEnclaveHeaderSchema ,
6465 querystring : requestQuerystringSchema ,
6566 body : writeRequestBodySchema ,
6667 response : {
@@ -72,12 +73,13 @@ export async function writeToContract(fastify: FastifyInstance) {
7273 const { simulateTx } = request . query ;
7374 const { functionName, args, txOverrides, abi } = request . body ;
7475 const {
75- "x-backend-wallet-address" : fromAddress ,
76+ "x-backend-wallet-address" : backendWalletAddress ,
7677 "x-account-address" : accountAddress ,
7778 "x-idempotency-key" : idempotencyKey ,
7879 "x-account-factory-address" : accountFactoryAddress ,
7980 "x-account-salt" : accountSalt ,
8081 } = request . headers as Static < typeof walletWithAAHeaderSchema > ;
82+ const enclave = await parseEnclaveHeaders ( request . headers , chain ) ;
8183
8284 const chainId = await getChainIdFromChain ( chain ) ;
8385 const contract = await getContractV5 ( {
@@ -118,14 +120,18 @@ export async function writeToContract(fastify: FastifyInstance) {
118120 const queueId = await queueTransaction ( {
119121 functionName,
120122 transaction,
121- fromAddress : requiredAddress ( fromAddress , "x-backend-wallet-address" ) ,
123+ fromAddress : maybeAddress (
124+ backendWalletAddress ,
125+ "x-backend-wallet-address" ,
126+ ) ,
122127 toAddress : maybeAddress ( contractAddress , "to" ) ,
123128 accountAddress : maybeAddress ( accountAddress , "x-account-address" ) ,
124129 accountFactoryAddress : maybeAddress (
125130 accountFactoryAddress ,
126131 "x-account-factory-address" ,
127132 ) ,
128133 accountSalt,
134+ enclave,
129135 txOverrides,
130136 idempotencyKey,
131137 shouldSimulate : simulateTx ,
0 commit comments