UNPKG

@openzeppelin/contracts-ui-builder-adapter-stellar

Version:
413 lines (393 loc) 13.1 kB
var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); // src/configuration/execution.ts import { logger } from "@openzeppelin/contracts-ui-builder-utils"; // src/utils/validator.ts function isValidAddress(address) { return /^G[A-Z0-9]{55}$/.test(address); } // src/configuration/execution.ts function getStellarSupportedExecutionMethods() { logger.warn( "StellarExecutionConfig", "getSupportedExecutionMethods is using placeholder implementation." ); return Promise.resolve([ { type: "eoa", name: "Stellar Account", description: "Execute using a standard Stellar account address." } ]); } function validateStellarExecutionConfig(config) { logger.warn( "StellarExecutionConfig", "validateExecutionConfig is using placeholder implementation." ); if (config.method === "eoa") { if (!config.allowAny && !config.specificAddress) { return Promise.resolve("Specific Stellar account address is required."); } if (!config.allowAny && config.specificAddress && !isValidAddress(config.specificAddress)) { return Promise.resolve("Invalid account address format for Stellar."); } return Promise.resolve(true); } else { return Promise.resolve( `Execution method '${config.method}' is not yet supported by this adapter implementation.` ); } } // src/configuration/explorer.ts import { logger as logger2 } from "@openzeppelin/contracts-ui-builder-utils"; function getStellarExplorerAddressUrl(address, networkConfig) { if (!address || !networkConfig.explorerUrl) { return null; } const baseUrl = networkConfig.explorerUrl.replace(/\/+$/, ""); return `${baseUrl}/account/${address}`; } function getStellarExplorerTxUrl(txHash, networkConfig) { if (!txHash || !networkConfig.explorerUrl) { return null; } const baseUrl = networkConfig.explorerUrl.replace(/\/+$/, ""); return `${baseUrl}/tx/${txHash}`; } // src/configuration/rpc.ts import { logger as logger3 } from "@openzeppelin/contracts-ui-builder-utils"; function validateStellarRpcEndpoint(_rpcConfig) { logger3.info("validateStellarRpcEndpoint", "Stellar RPC validation not yet implemented"); return true; } async function testStellarRpcConnection(_rpcConfig) { logger3.info("testStellarRpcConnection", "TODO: Implement RPC connection testing"); return { success: true }; } // src/adapter.ts import { isStellarNetworkConfig } from "@openzeppelin/contracts-ui-builder-types"; import { logger as logger8 } from "@openzeppelin/contracts-ui-builder-utils"; // src/mapping/type-mapper.ts function mapStellarParameterTypeToFieldType(_parameterType) { return "text"; } function getStellarCompatibleFieldTypes(_parameterType) { return [ "text", "number", "checkbox", "radio", "select", "textarea", "date", "email", "password", "blockchain-address", "amount", "hidden" ]; } // src/mapping/field-generator.ts function generateStellarDefaultField(parameter) { const fieldType = "text"; return { id: Math.random().toString(36).substring(2, 11), name: parameter.name || "placeholder", label: parameter.displayName || parameter.name || "Placeholder Field", type: fieldType, placeholder: "Placeholder - Stellar adapter not fully implemented yet", helperText: "Stellar adapter is not fully implemented yet", defaultValue: "", validation: { required: true }, width: "full" }; } // src/query/handler.ts import { logger as logger4 } from "@openzeppelin/contracts-ui-builder-utils"; async function queryStellarViewFunction(_contractAddress, _functionId, networkConfig, _params = [], _contractSchema) { if (networkConfig.ecosystem !== "stellar") { throw new Error("Invalid network configuration for Stellar query."); } const stellarConfig = networkConfig; logger4.warn( "queryStellarViewFunction", `Not implemented for network: ${stellarConfig.name} (Horizon: ${stellarConfig.horizonUrl})` ); throw new Error("Stellar view function queries not yet implemented"); } // src/query/view-checker.ts function isStellarViewFunction(_functionDetails) { return false; } // src/transaction/formatter.ts import { logger as logger5 } from "@openzeppelin/contracts-ui-builder-utils"; function formatStellarTransactionData(_contractSchema, _functionId, _submittedInputs, _fields) { logger5.warn( "adapter-stellar", "formatTransactionData not implemented, returning placeholder data." ); return { data: "stellar_formatted_placeholder" }; } // src/transaction/sender.ts import { logger as logger6 } from "@openzeppelin/contracts-ui-builder-utils"; var SYSTEM_LOG_TAG = "adapter-stellar"; function signAndBroadcastStellarTransaction(_transactionData, executionConfig) { logger6.info( SYSTEM_LOG_TAG, "Stellar signAndBroadcast called with executionConfig:", executionConfig ); return Promise.resolve({ txHash: "stellar_placeholder_tx" }); } // src/transform/input-parser.ts import { logger as logger7 } from "@openzeppelin/contracts-ui-builder-utils"; // src/transform/output-formatter.ts function formatStellarFunctionResult(result, _functionDetails) { if (result === null || result === void 0) { return "No data"; } return String(result); } // src/wallet/connection.ts function supportsStellarWalletConnection() { return false; } async function getStellarAvailableConnectors() { return []; } async function connectStellarWallet(_connectorId) { return { connected: false, error: "Stellar adapter does not support wallet connection." }; } async function disconnectStellarWallet() { return { disconnected: false, error: "Stellar adapter does not support wallet connection." }; } function getStellarWalletConnectionStatus() { return { isConnected: false }; } // src/adapter.ts var StellarAdapter = class { constructor(networkConfig) { __publicField(this, "networkConfig"); __publicField(this, "initialAppServiceKitName"); if (!isStellarNetworkConfig(networkConfig)) { throw new Error("StellarAdapter requires a valid Stellar network configuration."); } this.networkConfig = networkConfig; this.initialAppServiceKitName = "custom"; logger8.info( "StellarAdapter", `Adapter initialized for network: ${networkConfig.name} (ID: ${networkConfig.id})` ); } // --- Contract Loading --- // getContractDefinitionInputs() { return [ { id: "contractAddress", name: "contractAddress", label: "Contract ID", type: "blockchain-address", validation: { required: true }, placeholder: "G...", helperText: "Enter the Stellar contract ID." } ]; } async loadContract(artifacts) { if (typeof artifacts.contractAddress !== "string") { throw new Error("A contract address must be provided."); } return { name: "StellarContract", address: artifacts.contractAddress, ecosystem: "stellar", functions: [], events: [] }; } getWritableFunctions(contractSchema) { return contractSchema.functions.filter((fn) => fn.modifiesState); } // --- Type Mapping & Field Generation --- // mapParameterTypeToFieldType(parameterType) { return mapStellarParameterTypeToFieldType(parameterType); } getCompatibleFieldTypes(parameterType) { return getStellarCompatibleFieldTypes(parameterType); } generateDefaultField(parameter) { return generateStellarDefaultField(parameter); } // --- Transaction Formatting & Execution --- // formatTransactionData(contractSchema, functionId, submittedInputs, fields) { return formatStellarTransactionData(contractSchema, functionId, submittedInputs, fields); } async signAndBroadcast(transactionData, executionConfig) { return signAndBroadcastStellarTransaction(transactionData, executionConfig); } // NOTE: waitForTransactionConfirmation? is optional in the interface. // Since the imported function is currently undefined, we omit the method here. // If implemented in ./transaction/sender.ts later, add the method back: // async waitForTransactionConfirmation?(...) { ... } // --- View Function Querying --- // isViewFunction(functionDetails) { return isStellarViewFunction(functionDetails); } // Implement queryViewFunction with the correct signature from ContractAdapter async queryViewFunction(contractAddress, functionId, params = [], contractSchema) { return queryStellarViewFunction( contractAddress, functionId, this.networkConfig, params, contractSchema ); } formatFunctionResult(decodedValue, functionDetails) { return formatStellarFunctionResult(decodedValue, functionDetails); } // --- Wallet Interaction --- // supportsWalletConnection() { return supportsStellarWalletConnection(); } async getAvailableConnectors() { return getStellarAvailableConnectors(); } async connectWallet(connectorId) { return connectStellarWallet(connectorId); } async disconnectWallet() { return disconnectStellarWallet(); } getWalletConnectionStatus() { return getStellarWalletConnectionStatus(); } // Optional: onWalletConnectionChange(...) implementation would go here // --- Configuration & Metadata --- // async getSupportedExecutionMethods() { return getStellarSupportedExecutionMethods(); } async validateExecutionConfig(config) { return validateStellarExecutionConfig(config); } // Implement getExplorerUrl with the correct signature from ContractAdapter getExplorerUrl(address) { return getStellarExplorerAddressUrl(address, this.networkConfig); } // Implement getExplorerTxUrl with the correct signature from ContractAdapter getExplorerTxUrl(txHash) { if (getStellarExplorerTxUrl) { return getStellarExplorerTxUrl(txHash, this.networkConfig); } return null; } // --- Validation --- // isValidAddress(address) { return isValidAddress(address); } async getAvailableUiKits() { return [ { id: "custom", name: "OpenZeppelin Custom", configFields: [] } ]; } async getRelayers(_serviceUrl, _accessToken) { logger8.warn("StellarAdapter", "getRelayers is not implemented for the Stellar adapter yet."); return Promise.resolve([]); } async getRelayer(_serviceUrl, _accessToken, _relayerId) { logger8.warn("StellarAdapter", "getRelayer is not implemented for the Stellar adapter yet."); return Promise.resolve({}); } /** * @inheritdoc */ async validateRpcEndpoint(rpcConfig) { return validateStellarRpcEndpoint(rpcConfig); } /** * @inheritdoc */ async testRpcConnection(rpcConfig) { return testStellarRpcConnection(rpcConfig); } }; // src/networks/mainnet.ts var stellarPublic = { id: "stellar-public", exportConstName: "stellarPublic", name: "Stellar", ecosystem: "stellar", network: "stellar", type: "mainnet", isTestnet: false, horizonUrl: "https://horizon.stellar.org", networkPassphrase: "Public Global Stellar Network ; September 2015", explorerUrl: "https://stellar.expert/explorer/public", icon: "stellar" }; // src/networks/testnet.ts var stellarTestnet = { id: "stellar-testnet", exportConstName: "stellarTestnet", name: "Stellar Testnet", ecosystem: "stellar", network: "stellar", type: "testnet", isTestnet: true, horizonUrl: "https://horizon-testnet.stellar.org", networkPassphrase: "Test SDF Network ; September 2015", explorerUrl: "https://stellar.expert/explorer/testnet", icon: "stellar" }; // src/networks/index.ts var stellarMainnetNetworks = [stellarPublic]; var stellarTestnetNetworks = [stellarTestnet]; var stellarNetworks = [ ...stellarMainnetNetworks, ...stellarTestnetNetworks ]; // src/config.ts var stellarAdapterConfig = { /** * Dependencies required by the Stellar adapter * These will be included in exported projects that use this adapter */ dependencies: { // TODO: Review and update with real, verified dependencies and versions before production release // Runtime dependencies runtime: { // Core Stellar libraries "stellar-sdk": "^10.4.1", "@stellar/freighter-api": "^1.5.1", // Stellar wallet integration "@stellar/design-system": "^0.5.1", "@stellar/wallet-sdk": "^0.11.2", // Utilities for Stellar development "bignumber.js": "^9.1.1", "js-xdr": "^1.3.0" }, // Development dependencies dev: { // Testing utilities for Stellar "@stellar/typescript-wallet-sdk": "^1.9.0" // Soroban contract SDK for Stellar // '@stellar/soroban-sdk': '^0.7.0', } } }; export { StellarAdapter, stellarAdapterConfig, stellarMainnetNetworks, stellarNetworks, stellarPublic, stellarTestnet, stellarTestnetNetworks }; //# sourceMappingURL=index.js.map