UNPKG

@0xfutbol/id

Version:

React component library with shared providers for 0xFutbol ID

128 lines (127 loc) 5.11 kB
'use strict';var index=require('./index-gEYw6hWC.js');require('react'),require('react/jsx-runtime'),require('@0xfutbol/id-sign'),require('react-use'),require('@0xfutbol/constants'),require('thirdweb'),require('@matchain/matchid-sdk-react'),require('@tanstack/react-query'),require('@matchain/matchid-sdk-react/index.css'),require('react-dom');/** * @internal - only exported for testing */ async function prepareOpenZeppelinTransaction({ account, serializableTransaction, transaction, gasless, }) { const forrwaderContract = index.at({ address: gasless.relayerForwarderAddress, chain: transaction.chain, client: transaction.client, }); const nonce = await index.P({ contract: forrwaderContract, method: "function getNonce(address) view returns (uint256)", params: [account.address], }); const [signature, message] = await (async () => { // TODO: handle special case for `approve` -> `permit` transactions if (!serializableTransaction.to) { throw new Error("OpenZeppelin transactions must have a 'to' address"); } if (!serializableTransaction.gas) { throw new Error("OpenZeppelin transactions must have a 'gas' value"); } if (!serializableTransaction.data) { throw new Error("OpenZeppelin transactions must have a 'data' value"); } // chainless support! if (gasless.experimentalChainlessSupport) { const message = { from: account.address, to: serializableTransaction.to, value: 0n, gas: serializableTransaction.gas, nonce: nonce, data: serializableTransaction.data, chainid: BigInt(transaction.chain.id), }; return [ await account.signTypedData({ domain: { name: "GSNv2 Forwarder", version: "0.0.1", verifyingContract: forrwaderContract.address, }, message, primaryType: "ForwardRequest", types: { ForwardRequest: ChainAwareForwardRequest }, }), message, ]; } // else non-chainless support const message = { from: account.address, to: serializableTransaction.to, value: 0n, gas: serializableTransaction.gas, nonce: nonce, data: serializableTransaction.data, }; return [ await account.signTypedData({ domain: { name: gasless.domainName ?? "GSNv2 Forwarder", version: gasless.domainVersion ?? "0.0.1", chainId: transaction.chain.id, verifyingContract: forrwaderContract.address, }, message, primaryType: "ForwardRequest", types: { ForwardRequest }, }), message, ]; })(); // TODO: handle special case for `approve` -> `permit` const messageType = "forward"; return { message, signature, messageType }; } const ForwardRequest = [ { name: "from", type: "address" }, { name: "to", type: "address" }, { name: "value", type: "uint256" }, { name: "gas", type: "uint256" }, { name: "nonce", type: "uint256" }, { name: "data", type: "bytes" }, ]; const ChainAwareForwardRequest = [ { name: "from", type: "address" }, { name: "to", type: "address" }, { name: "value", type: "uint256" }, { name: "gas", type: "uint256" }, { name: "nonce", type: "uint256" }, { name: "data", type: "bytes" }, { name: "chainid", type: "uint256" }, ]; /** * @internal */ async function relayOpenZeppelinTransaction(options) { const { message, messageType, signature } = await prepareOpenZeppelinTransaction(options); const response = await fetch(options.gasless.relayerUrl, { method: "POST", body: index.s({ request: message, type: messageType, signature, forwarderAddress: options.gasless.relayerForwarderAddress, }), }); if (!response.ok) { response.body?.cancel(); throw new Error(`Failed to send transaction: ${await response.text()}`); } const json = await response.json(); if (!json.result) { throw new Error(`Relay transaction failed: ${json.message}`); } const transactionHash = JSON.parse(json.result).txHash; if (index.j(transactionHash)) { return { transactionHash, chain: options.transaction.chain, client: options.transaction.client, }; } throw new Error(`Failed to send transaction: ${index.s(json)}`); }exports.prepareOpenZeppelinTransaction=prepareOpenZeppelinTransaction;exports.relayOpenZeppelinTransaction=relayOpenZeppelinTransaction;//# sourceMappingURL=openzeppelin-D88cYP9k.js.map