UNPKG

@fordefi/web3-provider

Version:

Web3 Provider and signer compatible with EIP-1193

1,596 lines (1,522 loc) 455 kB
// src/index.ts import { EIP1193EventMap } from "viem"; // src/provider/provider.ts import { EventEmitter } from "events"; import { http, InternalRpcError as InternalRpcError3, InvalidInputRpcError, InvalidParamsRpcError as InvalidParamsRpcError3, isAddressEqual as isAddressEqual2, isHex as isHex2, numberToHex, ProviderDisconnectedError, UnsupportedProviderMethodError } from "viem"; // src/openapi/runtime.ts var BASE_PATH = "http://localhost:8000".replace(/\/+$/, ""); var Configuration = class { constructor(configuration = {}) { this.configuration = configuration; } set config(configuration) { this.configuration = configuration; } get basePath() { return this.configuration.basePath != null ? this.configuration.basePath : BASE_PATH; } get fetchApi() { return this.configuration.fetchApi; } get middleware() { return this.configuration.middleware || []; } get queryParamsStringify() { return this.configuration.queryParamsStringify || querystring; } get username() { return this.configuration.username; } get password() { return this.configuration.password; } get apiKey() { const apiKey = this.configuration.apiKey; if (apiKey) { return typeof apiKey === "function" ? apiKey : () => apiKey; } return void 0; } get accessToken() { const accessToken = this.configuration.accessToken; if (accessToken) { return typeof accessToken === "function" ? accessToken : async () => accessToken; } return void 0; } get headers() { return this.configuration.headers; } get credentials() { return this.configuration.credentials; } }; var DefaultConfig = new Configuration(); var _BaseAPI = class _BaseAPI { constructor(configuration = DefaultConfig) { this.configuration = configuration; this.fetchApi = async (url, init) => { let fetchParams = { url, init }; for (const middleware of this.middleware) { if (middleware.pre) { fetchParams = await middleware.pre({ fetch: this.fetchApi, ...fetchParams }) || fetchParams; } } let response = void 0; try { response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init); } catch (e) { for (const middleware of this.middleware) { if (middleware.onError) { response = await middleware.onError({ fetch: this.fetchApi, url: fetchParams.url, init: fetchParams.init, error: e, response: response ? response.clone() : void 0 }) || response; } } if (response === void 0) { if (e instanceof Error) { throw new FetchError(e, "The request failed and the interceptors did not return an alternative response"); } else { throw e; } } } for (const middleware of this.middleware) { if (middleware.post) { response = await middleware.post({ fetch: this.fetchApi, url: fetchParams.url, init: fetchParams.init, response: response.clone() }) || response; } } return response; }; this.middleware = configuration.middleware; } withMiddleware(...middlewares) { const next = this.clone(); next.middleware = next.middleware.concat(...middlewares); return next; } withPreMiddleware(...preMiddlewares) { const middlewares = preMiddlewares.map((pre) => ({ pre })); return this.withMiddleware(...middlewares); } withPostMiddleware(...postMiddlewares) { const middlewares = postMiddlewares.map((post) => ({ post })); return this.withMiddleware(...middlewares); } /** * Check if the given MIME is a JSON MIME. * JSON MIME examples: * application/json * application/json; charset=UTF8 * APPLICATION/JSON * application/vnd.company+json * @param mime - MIME (Multipurpose Internet Mail Extensions) * @return True if the given MIME is JSON, false otherwise. */ isJsonMime(mime) { if (!mime) { return false; } return _BaseAPI.jsonRegex.test(mime); } async request(context, initOverrides) { const { url, init } = await this.createFetchParams(context, initOverrides); const response = await this.fetchApi(url, init); if (response && (response.status >= 200 && response.status < 300)) { return response; } throw new ResponseError(response, "Response returned an error code"); } async createFetchParams(context, initOverrides) { let url = this.configuration.basePath + context.path; if (context.query !== void 0 && Object.keys(context.query).length !== 0) { url += "?" + this.configuration.queryParamsStringify(context.query); } const headers = Object.assign({}, this.configuration.headers, context.headers); Object.keys(headers).forEach((key) => headers[key] === void 0 ? delete headers[key] : {}); const initOverrideFn = typeof initOverrides === "function" ? initOverrides : async () => initOverrides; const initParams = { method: context.method, headers, body: context.body, credentials: this.configuration.credentials }; const overriddenInit = { ...initParams, ...await initOverrideFn({ init: initParams, context }) }; let body; if (isFormData(overriddenInit.body) || overriddenInit.body instanceof URLSearchParams || isBlob(overriddenInit.body)) { body = overriddenInit.body; } else if (this.isJsonMime(headers["Content-Type"])) { body = JSON.stringify(overriddenInit.body); } else { body = overriddenInit.body; } const init = { ...overriddenInit, body }; return { url, init }; } /** * Create a shallow clone of `this` by constructing a new instance * and then shallow cloning data members. */ clone() { const constructor = this.constructor; const next = new constructor(this.configuration); next.middleware = this.middleware.slice(); return next; } }; _BaseAPI.jsonRegex = new RegExp("^(:?application/json|[^;/ ]+/[^;/ ]+[+]json)[ ]*(:?;.*)?$", "i"); var BaseAPI = _BaseAPI; function isBlob(value) { return typeof Blob !== "undefined" && value instanceof Blob; } function isFormData(value) { return typeof FormData !== "undefined" && value instanceof FormData; } var ResponseError = class extends Error { constructor(response, msg) { super(msg); this.response = response; this.name = "ResponseError"; } }; var FetchError = class extends Error { constructor(cause, msg) { super(msg); this.cause = cause; this.name = "FetchError"; } }; var RequiredError = class extends Error { constructor(field, msg) { super(msg); this.field = field; this.name = "RequiredError"; } }; function querystring(params, prefix = "") { return Object.keys(params).map((key) => querystringSingleKey(key, params[key], prefix)).filter((part) => part.length > 0).join("&"); } function querystringSingleKey(key, value, keyPrefix = "") { const fullKey = keyPrefix + (keyPrefix.length ? `[${key}]` : key); if (value instanceof Array) { const multiValue = value.map((singleValue) => encodeURIComponent(String(singleValue))).join(`&${encodeURIComponent(fullKey)}=`); return `${encodeURIComponent(fullKey)}=${multiValue}`; } if (value instanceof Set) { const valueAsArray = Array.from(value); return querystringSingleKey(key, valueAsArray, keyPrefix); } if (value instanceof Date) { return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`; } if (value instanceof Object) { return querystring(value, fullKey); } return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`; } function mapValues(data, fn) { return Object.keys(data).reduce( (acc, key) => ({ ...acc, [key]: fn(data[key]) }), {} ); } var JSONApiResponse = class { constructor(raw, transformer = (jsonValue) => jsonValue) { this.raw = raw; this.transformer = transformer; } async value() { return this.transformer(await this.raw.json()); } }; // src/openapi/models/ChainSource.ts function ChainSourceFromJSON(json) { return ChainSourceFromJSONTyped(json, false); } function ChainSourceFromJSONTyped(json, _ignoreDiscriminator) { return json; } // src/openapi/models/ChainType.ts var ChainType = { aptos: "aptos", cosmos: "cosmos", evm: "evm", exchange: "exchange", solana: "solana", stacks: "stacks", starknet: "starknet", sui: "sui", ton: "ton", tron: "tron", utxo: "utxo" }; // src/openapi/models/DappInfo.ts function DappInfoToJSON(json) { return DappInfoToJSONTyped(json, false); } function DappInfoToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "url": value["url"], "name": value["name"] }; } // src/openapi/models/EvmChainRequest.ts function EvmChainRequestToJSON(json) { return EvmChainRequestToJSONTyped(json, false); } function EvmChainRequestToJSONTyped(value, _ignoreDiscriminator = false) { return value; } // src/openapi/models/CreateEvmPersonalMessageRequest.ts var CreateEvmPersonalMessageRequestTypeEnum = { personalMessageType: "personal_message_type" }; function CreateEvmPersonalMessageRequestToJSON(json) { return CreateEvmPersonalMessageRequestToJSONTyped(json, false); } function CreateEvmPersonalMessageRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "chain": EvmChainRequestToJSON(value["chain"]), "raw_data": value["rawData"] }; } // src/openapi/models/CreateEvmTypedMessageRequest.ts var CreateEvmTypedMessageRequestTypeEnum = { typedMessageType: "typed_message_type" }; function CreateEvmTypedMessageRequestToJSON(json) { return CreateEvmTypedMessageRequestToJSONTyped(json, false); } function CreateEvmTypedMessageRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "chain": EvmChainRequestToJSON(value["chain"]), "raw_data": value["rawData"] }; } // src/openapi/models/CreateEvmTypedV1MessageRequest.ts function CreateEvmTypedV1MessageRequestToJSON(json) { return CreateEvmTypedV1MessageRequestToJSONTyped(json, false); } function CreateEvmTypedV1MessageRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "chain": EvmChainRequestToJSON(value["chain"]), "raw_data": value["rawData"] }; } // src/openapi/models/CreateEvmMessageRequestDetails.ts function CreateEvmMessageRequestDetailsToJSON(json) { return CreateEvmMessageRequestDetailsToJSONTyped(json, false); } function CreateEvmMessageRequestDetailsToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } switch (value["type"]) { case "personal_message_type": return Object.assign({}, CreateEvmPersonalMessageRequestToJSON(value), { type: "personal_message_type" }); case "typed_message_type": return Object.assign({}, CreateEvmTypedMessageRequestToJSON(value), { type: "typed_message_type" }); case "typed_message_type_v1": return Object.assign({}, CreateEvmTypedV1MessageRequestToJSON(value), { type: "typed_message_type_v1" }); default: throw new Error(`No variant of CreateEvmMessageRequestDetails exists with 'type=${value["type"]}'`); } } // src/openapi/models/SignMode.ts function SignModeFromJSON(json) { return SignModeFromJSONTyped(json, false); } function SignModeFromJSONTyped(json, _ignoreDiscriminator) { return json; } function SignModeToJSON(value) { return value; } // src/openapi/models/SignerType.ts var SignerType = { initiator: "initiator", apiSigner: "api_signer", endUser: "end_user", multipleSigners: "multiple_signers" }; function SignerTypeFromJSON(json) { return SignerTypeFromJSONTyped(json, false); } function SignerTypeFromJSONTyped(json, _ignoreDiscriminator) { return json; } function SignerTypeToJSON(value) { return value; } // src/openapi/models/CreateEvmMessageRequest.ts var CreateEvmMessageRequestTypeEnum = { evmMessage: "evm_message" }; function CreateEvmMessageRequestToJSON(json) { return CreateEvmMessageRequestToJSONTyped(json, false); } function CreateEvmMessageRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "vault_id": value["vaultId"], "note": value["note"], "signer_type": SignerTypeToJSON(value["signerType"]), "sign_mode": SignModeToJSON(value["signMode"]), "dapp_info": DappInfoToJSON(value["dappInfo"]), "type": value["type"], "details": CreateEvmMessageRequestDetailsToJSON(value["details"]) }; } // src/openapi/models/EvmDataRequestBase64.ts function EvmDataRequestBase64ToJSON(json) { return EvmDataRequestBase64ToJSONTyped(json, false); } function EvmDataRequestBase64ToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "raw_data": value["rawData"] }; } // src/openapi/models/EvmDataRequestFullDetails.ts function EvmDataRequestFullDetailsToJSON(json) { return EvmDataRequestFullDetailsToJSONTyped(json, false); } function EvmDataRequestFullDetailsToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "method_name": value["methodName"], "method_arguments": value["methodArguments"] }; } // src/openapi/models/EvmDataRequestHex.ts var EvmDataRequestHexTypeEnum = { hex: "hex" }; function EvmDataRequestHexToJSON(json) { return EvmDataRequestHexToJSONTyped(json, false); } function EvmDataRequestHexToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "hex_data": value["hexData"] }; } // src/openapi/models/EvmDataRequest.ts function EvmDataRequestToJSON(json) { return EvmDataRequestToJSONTyped(json, false); } function EvmDataRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } switch (value["type"]) { case "base64": return Object.assign({}, EvmDataRequestBase64ToJSON(value), { type: "base64" }); case "full_details": return Object.assign({}, EvmDataRequestFullDetailsToJSON(value), { type: "full_details" }); case "hex": return Object.assign({}, EvmDataRequestHexToJSON(value), { type: "hex" }); default: throw new Error(`No variant of EvmDataRequest exists with 'type=${value["type"]}'`); } } // src/openapi/models/DynamicGasRequest.ts var DynamicGasRequestTypeEnum = { dynamic: "dynamic" }; function DynamicGasRequestToJSON(json) { return DynamicGasRequestToJSONTyped(json, false); } function DynamicGasRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "max_priority_fee_per_gas": value["maxPriorityFeePerGas"], "max_fee_per_gas": value["maxFeePerGas"] }; } // src/openapi/models/LegacyGasRequest.ts function LegacyGasRequestToJSON(json) { return LegacyGasRequestToJSONTyped(json, false); } function LegacyGasRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "price": value["price"] }; } // src/openapi/models/CustomGasRequestDetails.ts function CustomGasRequestDetailsToJSON(json) { return CustomGasRequestDetailsToJSONTyped(json, false); } function CustomGasRequestDetailsToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } switch (value["type"]) { case "dynamic": return Object.assign({}, DynamicGasRequestToJSON(value), { type: "dynamic" }); case "legacy": return Object.assign({}, LegacyGasRequestToJSON(value), { type: "legacy" }); default: throw new Error(`No variant of CustomGasRequestDetails exists with 'type=${value["type"]}'`); } } // src/openapi/models/CustomGasRequest.ts var CustomGasRequestTypeEnum = { custom: "custom" }; function CustomGasRequestToJSON(json) { return CustomGasRequestToJSONTyped(json, false); } function CustomGasRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "gas_limit": value["gasLimit"], "type": value["type"], "details": CustomGasRequestDetailsToJSON(value["details"]) }; } // src/openapi/models/GasPriorityLevelRequest.ts var GasPriorityLevelRequest = { low: "low", medium: "medium", high: "high" }; function GasPriorityLevelRequestToJSON(value) { return value; } // src/openapi/models/GasPriorityRequest.ts var GasPriorityRequestTypeEnum = { priority: "priority" }; function GasPriorityRequestToJSON(json) { return GasPriorityRequestToJSONTyped(json, false); } function GasPriorityRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "gas_limit": value["gasLimit"], "type": value["type"], "priority_level": GasPriorityLevelRequestToJSON(value["priorityLevel"]) }; } // src/openapi/models/CreateEvmRawTransactionRequestGas.ts function CreateEvmRawTransactionRequestGasToJSON(json) { return CreateEvmRawTransactionRequestGasToJSONTyped(json, false); } function CreateEvmRawTransactionRequestGasToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } switch (value["type"]) { case "custom": return Object.assign({}, CustomGasRequestToJSON(value), { type: "custom" }); case "priority": return Object.assign({}, GasPriorityRequestToJSON(value), { type: "priority" }); default: throw new Error(`No variant of CreateEvmRawTransactionRequestGas exists with 'type=${value["type"]}'`); } } // src/openapi/models/PushMode.ts var PushMode = { auto: "auto", manual: "manual", deferred: "deferred" }; function PushModeFromJSON(json) { return PushModeFromJSONTyped(json, false); } function PushModeFromJSONTyped(json, _ignoreDiscriminator) { return json; } function PushModeToJSON(value) { return value; } // src/openapi/models/CreateEvmRawTransactionRequest.ts var CreateEvmRawTransactionRequestTypeEnum = { evmRawTransaction: "evm_raw_transaction" }; function CreateEvmRawTransactionRequestToJSON(json) { return CreateEvmRawTransactionRequestToJSONTyped(json, false); } function CreateEvmRawTransactionRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "use_secure_node": value["useSecureNode"], "gas": CreateEvmRawTransactionRequestGasToJSON(value["gas"]), "fail_on_prediction_failure": value["failOnPredictionFailure"], "skip_prediction": value["skipPrediction"], "push_mode": PushModeToJSON(value["pushMode"]), "funder": value["funder"], "chain": EvmChainRequestToJSON(value["chain"]), "to": value["to"], "value": value["value"], "data": EvmDataRequestToJSON(value["data"]) }; } // src/openapi/models/CreateEvmRevokeAllowanceRequest.ts function CreateEvmRevokeAllowanceRequestToJSON(json) { return CreateEvmRevokeAllowanceRequestToJSONTyped(json, false); } function CreateEvmRevokeAllowanceRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "use_secure_node": value["useSecureNode"], "gas": CreateEvmRawTransactionRequestGasToJSON(value["gas"]), "fail_on_prediction_failure": value["failOnPredictionFailure"], "skip_prediction": value["skipPrediction"], "push_mode": PushModeToJSON(value["pushMode"]), "funder": value["funder"], "chain": EvmChainRequestToJSON(value["chain"]), "token": value["token"], "spender": value["spender"] }; } // src/openapi/models/CreateTransferRequestExplicitAmount.ts function CreateTransferRequestExplicitAmountToJSON(json) { return CreateTransferRequestExplicitAmountToJSONTyped(json, false); } function CreateTransferRequestExplicitAmountToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "value": value["value"] }; } // src/openapi/models/CreateTransferRequestMaxAmount.ts function CreateTransferRequestMaxAmountToJSON(json) { return CreateTransferRequestMaxAmountToJSONTyped(json, false); } function CreateTransferRequestMaxAmountToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"] }; } // src/openapi/models/CreateAptosTransferRequestValue.ts function CreateAptosTransferRequestValueToJSON(json) { return CreateAptosTransferRequestValueToJSONTyped(json, false); } function CreateAptosTransferRequestValueToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } switch (value["type"]) { case "max": return Object.assign({}, CreateTransferRequestMaxAmountToJSON(value), { type: "max" }); case "value": return Object.assign({}, CreateTransferRequestExplicitAmountToJSON(value), { type: "value" }); default: throw new Error(`No variant of CreateAptosTransferRequestValue exists with 'type=${value["type"]}'`); } } // src/openapi/models/CreateEvmTransferRequestTo.ts function CreateEvmTransferRequestToToJSON(json) { return CreateEvmTransferRequestToToJSONTyped(json, false); } function CreateEvmTransferRequestToToJSONTyped(value, _ignoreDiscriminator = false) { return value; } // src/openapi/models/EvmAddressRequest.ts function EvmAddressRequestFromJSON(json) { return EvmAddressRequestFromJSONTyped(json, false); } function EvmAddressRequestFromJSONTyped(json, _ignoreDiscriminator) { if (json == null) { return json; } return { "chain": json["chain"], "hexRepr": json["hex_repr"] }; } function EvmAddressRequestToJSON(json) { return EvmAddressRequestToJSONTyped(json, false); } function EvmAddressRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "chain": value["chain"], "hex_repr": value["hexRepr"] }; } // src/openapi/models/EvmErc1155AssetIdentifierRequest.ts function EvmErc1155AssetIdentifierRequestFromJSONTyped(json, _ignoreDiscriminator) { if (json == null) { return json; } return { "type": json["type"], "token": EvmAddressRequestFromJSON(json["token"]), "tokenId": json["token_id"] }; } function EvmErc1155AssetIdentifierRequestToJSON(json) { return EvmErc1155AssetIdentifierRequestToJSONTyped(json, false); } function EvmErc1155AssetIdentifierRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "token": EvmAddressRequestToJSON(value["token"]), "token_id": value["tokenId"] }; } // src/openapi/models/EvmErc20AssetIdentifierRequest.ts function EvmErc20AssetIdentifierRequestFromJSONTyped(json, _ignoreDiscriminator) { if (json == null) { return json; } return { "type": json["type"], "token": EvmAddressRequestFromJSON(json["token"]) }; } function EvmErc20AssetIdentifierRequestToJSON(json) { return EvmErc20AssetIdentifierRequestToJSONTyped(json, false); } function EvmErc20AssetIdentifierRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "token": EvmAddressRequestToJSON(value["token"]) }; } // src/openapi/models/EvmErc721AssetIdentifierRequest.ts function EvmErc721AssetIdentifierRequestFromJSONTyped(json, _ignoreDiscriminator) { if (json == null) { return json; } return { "type": json["type"], "token": EvmAddressRequestFromJSON(json["token"]), "tokenId": json["token_id"] }; } function EvmErc721AssetIdentifierRequestToJSON(json) { return EvmErc721AssetIdentifierRequestToJSONTyped(json, false); } function EvmErc721AssetIdentifierRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "token": EvmAddressRequestToJSON(value["token"]), "token_id": value["tokenId"] }; } // src/openapi/models/EvmHyperLiquidAssetIdentifierRequest.ts function EvmHyperLiquidAssetIdentifierRequestFromJSONTyped(json, _ignoreDiscriminator) { if (json == null) { return json; } return { "type": json["type"], "chain": json["chain"], "tokenId": json["token_id"], "index": json["index"] }; } function EvmHyperLiquidAssetIdentifierRequestToJSON(json) { return EvmHyperLiquidAssetIdentifierRequestToJSONTyped(json, false); } function EvmHyperLiquidAssetIdentifierRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "chain": value["chain"], "token_id": value["tokenId"], "index": value["index"] }; } // src/openapi/models/EvmNativeAssetIdentifierRequest.ts function EvmNativeAssetIdentifierRequestFromJSONTyped(json, _ignoreDiscriminator) { if (json == null) { return json; } return { "type": json["type"], "chain": json["chain"] }; } function EvmNativeAssetIdentifierRequestToJSON(json) { return EvmNativeAssetIdentifierRequestToJSONTyped(json, false); } function EvmNativeAssetIdentifierRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "chain": value["chain"] }; } // src/openapi/models/EvmAssetIdentifierDetails.ts function EvmAssetIdentifierDetailsFromJSON(json) { return EvmAssetIdentifierDetailsFromJSONTyped(json, false); } function EvmAssetIdentifierDetailsFromJSONTyped(json, _ignoreDiscriminator) { if (json == null) { return json; } switch (json["type"]) { case "erc1155": return Object.assign({}, EvmErc1155AssetIdentifierRequestFromJSONTyped(json, true), { type: "erc1155" }); case "erc20": return Object.assign({}, EvmErc20AssetIdentifierRequestFromJSONTyped(json, true), { type: "erc20" }); case "erc721": return Object.assign({}, EvmErc721AssetIdentifierRequestFromJSONTyped(json, true), { type: "erc721" }); case "hyperliquid": return Object.assign({}, EvmHyperLiquidAssetIdentifierRequestFromJSONTyped(json, true), { type: "hyperliquid" }); case "native": return Object.assign({}, EvmNativeAssetIdentifierRequestFromJSONTyped(json, true), { type: "native" }); default: throw new Error(`No variant of EvmAssetIdentifierDetails exists with 'type=${json["type"]}'`); } } function EvmAssetIdentifierDetailsToJSON(json) { return EvmAssetIdentifierDetailsToJSONTyped(json, false); } function EvmAssetIdentifierDetailsToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } switch (value["type"]) { case "erc1155": return Object.assign({}, EvmErc1155AssetIdentifierRequestToJSON(value), { type: "erc1155" }); case "erc20": return Object.assign({}, EvmErc20AssetIdentifierRequestToJSON(value), { type: "erc20" }); case "erc721": return Object.assign({}, EvmErc721AssetIdentifierRequestToJSON(value), { type: "erc721" }); case "hyperliquid": return Object.assign({}, EvmHyperLiquidAssetIdentifierRequestToJSON(value), { type: "hyperliquid" }); case "native": return Object.assign({}, EvmNativeAssetIdentifierRequestToJSON(value), { type: "native" }); default: throw new Error(`No variant of EvmAssetIdentifierDetails exists with 'type=${value["type"]}'`); } } // src/openapi/models/EvmAssetIdentifierRequest.ts function EvmAssetIdentifierRequestToJSON(json) { return EvmAssetIdentifierRequestToJSONTyped(json, false); } function EvmAssetIdentifierRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "details": EvmAssetIdentifierDetailsToJSON(value["details"]) }; } // src/openapi/models/CreateEvmTransferRequest.ts function CreateEvmTransferRequestToJSON(json) { return CreateEvmTransferRequestToJSONTyped(json, false); } function CreateEvmTransferRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "use_secure_node": value["useSecureNode"], "gas": CreateEvmRawTransactionRequestGasToJSON(value["gas"]), "fail_on_prediction_failure": value["failOnPredictionFailure"], "skip_prediction": value["skipPrediction"], "push_mode": PushModeToJSON(value["pushMode"]), "funder": value["funder"], "to": CreateEvmTransferRequestToToJSON(value["to"]), "asset_identifier": EvmAssetIdentifierRequestToJSON(value["assetIdentifier"]), "value": CreateAptosTransferRequestValueToJSON(value["value"]) }; } // src/openapi/models/CreateEvmTransactionRequestDetails.ts function CreateEvmTransactionRequestDetailsToJSON(json) { return CreateEvmTransactionRequestDetailsToJSONTyped(json, false); } function CreateEvmTransactionRequestDetailsToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } switch (value["type"]) { case "evm_raw_transaction": return Object.assign({}, CreateEvmRawTransactionRequestToJSON(value), { type: "evm_raw_transaction" }); case "evm_revoke_allowance": return Object.assign({}, CreateEvmRevokeAllowanceRequestToJSON(value), { type: "evm_revoke_allowance" }); case "evm_transfer": return Object.assign({}, CreateEvmTransferRequestToJSON(value), { type: "evm_transfer" }); default: throw new Error(`No variant of CreateEvmTransactionRequestDetails exists with 'type=${value["type"]}'`); } } // src/openapi/models/CreateEvmTransactionRequest.ts var CreateEvmTransactionRequestTypeEnum = { evmTransaction: "evm_transaction" }; function CreateEvmTransactionRequestToJSON(json) { return CreateEvmTransactionRequestToJSONTyped(json, false); } function CreateEvmTransactionRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "vault_id": value["vaultId"], "note": value["note"], "signer_type": SignerTypeToJSON(value["signerType"]), "sign_mode": SignModeToJSON(value["signMode"]), "dapp_info": DappInfoToJSON(value["dappInfo"]), "type": value["type"], "details": CreateEvmTransactionRequestDetailsToJSON(value["details"]) }; } // src/openapi/models/AptosChainUniqueId.ts function AptosChainUniqueIdFromJSON(json) { return AptosChainUniqueIdFromJSONTyped(json, false); } function AptosChainUniqueIdFromJSONTyped(json, _ignoreDiscriminator) { return json; } function AptosChainUniqueIdToJSON(value) { return value; } // src/openapi/models/AptosPersonalMessageRequest.ts function AptosPersonalMessageRequestToJSON(json) { return AptosPersonalMessageRequestToJSONTyped(json, false); } function AptosPersonalMessageRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "should_include_address": value["shouldIncludeAddress"], "application": value["application"], "should_include_application": value["shouldIncludeApplication"], "chain": AptosChainUniqueIdToJSON(value["chain"]), "should_include_chain": value["shouldIncludeChain"], "message_to_sign": value["messageToSign"], "nonce": value["nonce"] }; } // src/openapi/models/CreateAptosMessageRequest.ts function CreateAptosMessageRequestToJSON(json) { return CreateAptosMessageRequestToJSONTyped(json, false); } function CreateAptosMessageRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "vault_id": value["vaultId"], "note": value["note"], "signer_type": SignerTypeToJSON(value["signerType"]), "sign_mode": SignModeToJSON(value["signMode"]), "dapp_info": DappInfoToJSON(value["dappInfo"]), "type": value["type"], "details": AptosPersonalMessageRequestToJSON(value["details"]) }; } // src/openapi/models/AptosCustomGasPriceRequest.ts function AptosCustomGasPriceRequestToJSON(json) { return AptosCustomGasPriceRequestToJSONTyped(json, false); } function AptosCustomGasPriceRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "price": value["price"] }; } // src/openapi/models/FeePriorityLevelRequest.ts function FeePriorityLevelRequestToJSON(value) { return value; } // src/openapi/models/AptosPriorityGasPriceRequest.ts function AptosPriorityGasPriceRequestToJSON(json) { return AptosPriorityGasPriceRequestToJSONTyped(json, false); } function AptosPriorityGasPriceRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "priority": FeePriorityLevelRequestToJSON(value["priority"]) }; } // src/openapi/models/AptosGasConfigRequestPrice.ts function AptosGasConfigRequestPriceToJSON(json) { return AptosGasConfigRequestPriceToJSONTyped(json, false); } function AptosGasConfigRequestPriceToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } switch (value["type"]) { case "custom": return Object.assign({}, AptosCustomGasPriceRequestToJSON(value), { type: "custom" }); case "priority": return Object.assign({}, AptosPriorityGasPriceRequestToJSON(value), { type: "priority" }); default: throw new Error(`No variant of AptosGasConfigRequestPrice exists with 'type=${value["type"]}'`); } } // src/openapi/models/AptosGasConfigRequest.ts function AptosGasConfigRequestToJSON(json) { return AptosGasConfigRequestToJSONTyped(json, false); } function AptosGasConfigRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "max_gas": value["maxGas"], "price": AptosGasConfigRequestPriceToJSON(value["price"]) }; } // src/openapi/models/CreateAptosSerializedRawTransactionRequest.ts function CreateAptosSerializedRawTransactionRequestToJSON(json) { return CreateAptosSerializedRawTransactionRequestToJSONTyped(json, false); } function CreateAptosSerializedRawTransactionRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "fail_on_prediction_failure": value["failOnPredictionFailure"], "gas_config": AptosGasConfigRequestToJSON(value["gasConfig"]), "chain": AptosChainUniqueIdToJSON(value["chain"]), "serialized_transaction_payload": value["serializedTransactionPayload"], "skip_prediction": value["skipPrediction"], "push_mode": PushModeToJSON(value["pushMode"]) }; } // src/openapi/models/AptosRecipientHex.ts function AptosRecipientHexToJSON(json) { return AptosRecipientHexToJSONTyped(json, false); } function AptosRecipientHexToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "address": value["address"] }; } // src/openapi/models/RecipientVaultId.ts function RecipientVaultIdToJSON(json) { return RecipientVaultIdToJSONTyped(json, false); } function RecipientVaultIdToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "vault_id": value["vaultId"] }; } // src/openapi/models/CreateAptosTransferRequestTo.ts function CreateAptosTransferRequestToToJSON(json) { return CreateAptosTransferRequestToToJSONTyped(json, false); } function CreateAptosTransferRequestToToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } switch (value["type"]) { case "hex": return Object.assign({}, AptosRecipientHexToJSON(value), { type: "hex" }); case "vault_id": return Object.assign({}, RecipientVaultIdToJSON(value), { type: "vault_id" }); default: throw new Error(`No variant of CreateAptosTransferRequestTo exists with 'type=${value["type"]}'`); } } // src/openapi/models/AptosCoinTypeRequest.ts function AptosCoinTypeRequestFromJSON(json) { return AptosCoinTypeRequestFromJSONTyped(json, false); } function AptosCoinTypeRequestFromJSONTyped(json, _ignoreDiscriminator) { if (json == null) { return json; } return { "chain": AptosChainUniqueIdFromJSON(json["chain"]), "coinTypeStr": json["coin_type_str"] }; } function AptosCoinTypeRequestToJSON(json) { return AptosCoinTypeRequestToJSONTyped(json, false); } function AptosCoinTypeRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "chain": AptosChainUniqueIdToJSON(value["chain"]), "coin_type_str": value["coinTypeStr"] }; } // src/openapi/models/AptosCoinAssetIdentifierRequest.ts function AptosCoinAssetIdentifierRequestFromJSONTyped(json, _ignoreDiscriminator) { if (json == null) { return json; } return { "type": json["type"], "coinType": AptosCoinTypeRequestFromJSON(json["coin_type"]) }; } function AptosCoinAssetIdentifierRequestToJSON(json) { return AptosCoinAssetIdentifierRequestToJSONTyped(json, false); } function AptosCoinAssetIdentifierRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "coin_type": AptosCoinTypeRequestToJSON(value["coinType"]) }; } // src/openapi/models/AptosNativeAssetIdentifierRequest.ts function AptosNativeAssetIdentifierRequestFromJSONTyped(json, _ignoreDiscriminator) { if (json == null) { return json; } return { "type": json["type"], "chain": AptosChainUniqueIdFromJSON(json["chain"]) }; } function AptosNativeAssetIdentifierRequestToJSON(json) { return AptosNativeAssetIdentifierRequestToJSONTyped(json, false); } function AptosNativeAssetIdentifierRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "chain": AptosChainUniqueIdToJSON(value["chain"]) }; } // src/openapi/models/AptosNewCoinTypeRequest.ts function AptosNewCoinTypeRequestFromJSON(json) { return AptosNewCoinTypeRequestFromJSONTyped(json, false); } function AptosNewCoinTypeRequestFromJSONTyped(json, _ignoreDiscriminator) { if (json == null) { return json; } return { "chain": AptosChainUniqueIdFromJSON(json["chain"]), "metadataAddress": json["metadata_address"] }; } function AptosNewCoinTypeRequestToJSON(json) { return AptosNewCoinTypeRequestToJSONTyped(json, false); } function AptosNewCoinTypeRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "chain": AptosChainUniqueIdToJSON(value["chain"]), "metadata_address": value["metadataAddress"] }; } // src/openapi/models/AptosNewCoinAssetIdentifierRequest.ts function AptosNewCoinAssetIdentifierRequestFromJSONTyped(json, _ignoreDiscriminator) { if (json == null) { return json; } return { "type": json["type"], "newCoinType": AptosNewCoinTypeRequestFromJSON(json["new_coin_type"]) }; } function AptosNewCoinAssetIdentifierRequestToJSON(json) { return AptosNewCoinAssetIdentifierRequestToJSONTyped(json, false); } function AptosNewCoinAssetIdentifierRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "new_coin_type": AptosNewCoinTypeRequestToJSON(value["newCoinType"]) }; } // src/openapi/models/AptosAssetIdentifierDetails.ts function AptosAssetIdentifierDetailsFromJSON(json) { return AptosAssetIdentifierDetailsFromJSONTyped(json, false); } function AptosAssetIdentifierDetailsFromJSONTyped(json, _ignoreDiscriminator) { if (json == null) { return json; } switch (json["type"]) { case "coin": return Object.assign({}, AptosCoinAssetIdentifierRequestFromJSONTyped(json, true), { type: "coin" }); case "native": return Object.assign({}, AptosNativeAssetIdentifierRequestFromJSONTyped(json, true), { type: "native" }); case "new_coin": return Object.assign({}, AptosNewCoinAssetIdentifierRequestFromJSONTyped(json, true), { type: "new_coin" }); default: throw new Error(`No variant of AptosAssetIdentifierDetails exists with 'type=${json["type"]}'`); } } function AptosAssetIdentifierDetailsToJSON(json) { return AptosAssetIdentifierDetailsToJSONTyped(json, false); } function AptosAssetIdentifierDetailsToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } switch (value["type"]) { case "coin": return Object.assign({}, AptosCoinAssetIdentifierRequestToJSON(value), { type: "coin" }); case "native": return Object.assign({}, AptosNativeAssetIdentifierRequestToJSON(value), { type: "native" }); case "new_coin": return Object.assign({}, AptosNewCoinAssetIdentifierRequestToJSON(value), { type: "new_coin" }); default: throw new Error(`No variant of AptosAssetIdentifierDetails exists with 'type=${value["type"]}'`); } } // src/openapi/models/AptosAssetIdentifierRequest.ts function AptosAssetIdentifierRequestToJSON(json) { return AptosAssetIdentifierRequestToJSONTyped(json, false); } function AptosAssetIdentifierRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "details": AptosAssetIdentifierDetailsToJSON(value["details"]) }; } // src/openapi/models/CreateAptosTransferRequest.ts function CreateAptosTransferRequestToJSON(json) { return CreateAptosTransferRequestToJSONTyped(json, false); } function CreateAptosTransferRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "fail_on_prediction_failure": value["failOnPredictionFailure"], "gas_config": AptosGasConfigRequestToJSON(value["gasConfig"]), "to": CreateAptosTransferRequestToToJSON(value["to"]), "value": CreateAptosTransferRequestValueToJSON(value["value"]), "asset_identifier": AptosAssetIdentifierRequestToJSON(value["assetIdentifier"]), "skip_prediction": value["skipPrediction"], "push_mode": PushModeToJSON(value["pushMode"]) }; } // src/openapi/models/CreateAptosTransactionRequestDetails.ts function CreateAptosTransactionRequestDetailsToJSON(json) { return CreateAptosTransactionRequestDetailsToJSONTyped(json, false); } function CreateAptosTransactionRequestDetailsToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } switch (value["type"]) { case "aptos_serialized_entry_point_payload": return Object.assign({}, CreateAptosSerializedRawTransactionRequestToJSON(value), { type: "aptos_serialized_entry_point_payload" }); case "aptos_transfer": return Object.assign({}, CreateAptosTransferRequestToJSON(value), { type: "aptos_transfer" }); default: throw new Error(`No variant of CreateAptosTransactionRequestDetails exists with 'type=${value["type"]}'`); } } // src/openapi/models/CreateAptosTransactionRequest.ts function CreateAptosTransactionRequestToJSON(json) { return CreateAptosTransactionRequestToJSONTyped(json, false); } function CreateAptosTransactionRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "vault_id": value["vaultId"], "note": value["note"], "signer_type": SignerTypeToJSON(value["signerType"]), "sign_mode": SignModeToJSON(value["signMode"]), "dapp_info": DappInfoToJSON(value["dappInfo"]), "type": value["type"], "details": CreateAptosTransactionRequestDetailsToJSON(value["details"]) }; } // src/openapi/models/BinaryHashPayload.ts function BinaryHashPayloadToJSON(json) { return BinaryHashPayloadToJSONTyped(json, false); } function BinaryHashPayloadToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "format": value["format"], "hash_binary": value["hashBinary"] }; } // src/openapi/models/IntegerHashPayload.ts function IntegerHashPayloadToJSON(json) { return IntegerHashPayloadToJSONTyped(json, false); } function IntegerHashPayloadToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "format": value["format"], "hash_integer": value["hashInteger"] }; } // src/openapi/models/CreateBlackBoxSignatureRequestDetails.ts function CreateBlackBoxSignatureRequestDetailsToJSON(json) { return CreateBlackBoxSignatureRequestDetailsToJSONTyped(json, false); } function CreateBlackBoxSignatureRequestDetailsToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } switch (value["format"]) { case "hash_binary": return Object.assign({}, BinaryHashPayloadToJSON(value), { format: "hash_binary" }); case "hash_integer": return Object.assign({}, IntegerHashPayloadToJSON(value), { format: "hash_integer" }); default: throw new Error(`No variant of CreateBlackBoxSignatureRequestDetails exists with 'format=${value["format"]}'`); } } // src/openapi/models/CreateBlackBoxSignatureRequest.ts function CreateBlackBoxSignatureRequestToJSON(json) { return CreateBlackBoxSignatureRequestToJSONTyped(json, false); } function CreateBlackBoxSignatureRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "vault_id": value["vaultId"], "note": value["note"], "signer_type": SignerTypeToJSON(value["signerType"]), "sign_mode": SignModeToJSON(value["signMode"]), "dapp_info": DappInfoToJSON(value["dappInfo"]), "type": value["type"], "details": CreateBlackBoxSignatureRequestDetailsToJSON(value["details"]) }; } // src/openapi/models/CosmosChainUniqueId.ts function CosmosChainUniqueIdFromJSON(json) { return CosmosChainUniqueIdFromJSONTyped(json, false); } function CosmosChainUniqueIdFromJSONTyped(json, _ignoreDiscriminator) { return json; } function CosmosChainUniqueIdToJSON(value) { return value; } // src/openapi/models/CosmosMessageBase64Data.ts function CosmosMessageBase64DataFromJSONTyped(json, _ignoreDiscriminator) { if (json == null) { return json; } return { "type": json["type"], "data": json["data"] }; } function CosmosMessageBase64DataToJSON(json) { return CosmosMessageBase64DataToJSONTyped(json, false); } function CosmosMessageBase64DataToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "data": value["data"] }; } // src/openapi/models/CosmosMessageStrData.ts function CosmosMessageStrDataFromJSONTyped(json, _ignoreDiscriminator) { if (json == null) { return json; } return { "type": json["type"], "data": json["data"] }; } function CosmosMessageStrDataToJSON(json) { return CosmosMessageStrDataToJSONTyped(json, false); } function CosmosMessageStrDataToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "data": value["data"] }; } // src/openapi/models/CosmosMessageData.ts function CosmosMessageDataFromJSON(json) { return CosmosMessageDataFromJSONTyped(json, false); } function CosmosMessageDataFromJSONTyped(json, _ignoreDiscriminator) { if (json == null) { return json; } switch (json["type"]) { case "base64": return Object.assign({}, CosmosMessageBase64DataFromJSONTyped(json, true), { type: "base64" }); case "string": return Object.assign({}, CosmosMessageStrDataFromJSONTyped(json, true), { type: "string" }); default: throw new Error(`No variant of CosmosMessageData exists with 'type=${json["type"]}'`); } } function CosmosMessageDataToJSON(json) { return CosmosMessageDataToJSONTyped(json, false); } function CosmosMessageDataToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } switch (value["type"]) { case "base64": return Object.assign({}, CosmosMessageBase64DataToJSON(value), { type: "base64" }); case "string": return Object.assign({}, CosmosMessageStrDataToJSON(value), { type: "string" }); default: throw new Error(`No variant of CosmosMessageData exists with 'type=${value["type"]}'`); } } // src/openapi/models/CosmosArbitraryMessageRequest.ts function CosmosArbitraryMessageRequestToJSON(json) { return CosmosArbitraryMessageRequestToJSONTyped(json, false); } function CosmosArbitraryMessageRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "type": value["type"], "chain": CosmosChainUniqueIdToJSON(value["chain"]), "data": CosmosMessageDataToJSON(value["data"]) }; } // src/openapi/models/CreateCosmosMessageRequest.ts function CreateCosmosMessageRequestToJSON(json) { return CreateCosmosMessageRequestToJSONTyped(json, false); } function CreateCosmosMessageRequestToJSONTyped(value, _ignoreDiscriminator = false) { if (value == null) { return value; } return { "vault_id": value["vaultId"], "note": value["note"], "signer_type": SignerTypeToJSON(value["signerType"]), "sign_mode": SignModeToJSON(value["signMode"]), "dapp_info": DappInfoToJSON(value["dappInf