@openzeppelin/contracts-ui-builder-adapter-stellar
Version:
Stellar Adapter for Contracts UI Builder
444 lines (423 loc) • 14.9 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
// src/index.ts
var index_exports = {};
__export(index_exports, {
StellarAdapter: () => StellarAdapter,
stellarAdapterConfig: () => stellarAdapterConfig,
stellarMainnetNetworks: () => stellarMainnetNetworks,
stellarNetworks: () => stellarNetworks,
stellarPublic: () => stellarPublic,
stellarTestnet: () => stellarTestnet,
stellarTestnetNetworks: () => stellarTestnetNetworks
});
module.exports = __toCommonJS(index_exports);
// src/configuration/execution.ts
var import_contracts_ui_builder_utils = require("@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() {
import_contracts_ui_builder_utils.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) {
import_contracts_ui_builder_utils.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
var import_contracts_ui_builder_utils2 = require("@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
var import_contracts_ui_builder_utils3 = require("@openzeppelin/contracts-ui-builder-utils");
function validateStellarRpcEndpoint(_rpcConfig) {
import_contracts_ui_builder_utils3.logger.info("validateStellarRpcEndpoint", "Stellar RPC validation not yet implemented");
return true;
}
async function testStellarRpcConnection(_rpcConfig) {
import_contracts_ui_builder_utils3.logger.info("testStellarRpcConnection", "TODO: Implement RPC connection testing");
return { success: true };
}
// src/adapter.ts
var import_contracts_ui_builder_types = require("@openzeppelin/contracts-ui-builder-types");
var import_contracts_ui_builder_utils8 = require("@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
var import_contracts_ui_builder_utils4 = require("@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;
import_contracts_ui_builder_utils4.logger.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
var import_contracts_ui_builder_utils5 = require("@openzeppelin/contracts-ui-builder-utils");
function formatStellarTransactionData(_contractSchema, _functionId, _submittedInputs, _fields) {
import_contracts_ui_builder_utils5.logger.warn(
"adapter-stellar",
"formatTransactionData not implemented, returning placeholder data."
);
return { data: "stellar_formatted_placeholder" };
}
// src/transaction/sender.ts
var import_contracts_ui_builder_utils6 = require("@openzeppelin/contracts-ui-builder-utils");
var SYSTEM_LOG_TAG = "adapter-stellar";
function signAndBroadcastStellarTransaction(_transactionData, executionConfig) {
import_contracts_ui_builder_utils6.logger.info(
SYSTEM_LOG_TAG,
"Stellar signAndBroadcast called with executionConfig:",
executionConfig
);
return Promise.resolve({ txHash: "stellar_placeholder_tx" });
}
// src/transform/input-parser.ts
var import_contracts_ui_builder_utils7 = require("@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 (!(0, import_contracts_ui_builder_types.isStellarNetworkConfig)(networkConfig)) {
throw new Error("StellarAdapter requires a valid Stellar network configuration.");
}
this.networkConfig = networkConfig;
this.initialAppServiceKitName = "custom";
import_contracts_ui_builder_utils8.logger.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) {
import_contracts_ui_builder_utils8.logger.warn("StellarAdapter", "getRelayers is not implemented for the Stellar adapter yet.");
return Promise.resolve([]);
}
async getRelayer(_serviceUrl, _accessToken, _relayerId) {
import_contracts_ui_builder_utils8.logger.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',
}
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
StellarAdapter,
stellarAdapterConfig,
stellarMainnetNetworks,
stellarNetworks,
stellarPublic,
stellarTestnet,
stellarTestnetNetworks
});
//# sourceMappingURL=index.cjs.map