@openzeppelin/contracts-ui-builder-adapter-midnight
Version:
Midnight Adapter for Contracts UI Builder
130 lines (123 loc) • 5.7 kB
TypeScript
import { ContractAdapter, MidnightNetworkConfig, UiKitConfiguration, EcosystemReactUiProviderProps, EcosystemSpecificReactHooks, EcosystemWalletComponents, Connector, FormFieldType, ContractSchema, ContractFunction, FieldType, FunctionParameter, ExecutionConfig, ExecutionMethodDetail, AvailableUiKit, RelayerDetails, RelayerDetailsRich, UserRpcProviderConfig } from '@openzeppelin/contracts-ui-builder-types';
/**
* Midnight-specific adapter.
*
* Implements the full ContractAdapter interface to integrate with the builder application.
* Wallet-related functionalities are implemented, while contract-specific methods
* are placeholders to be built out in later phases.
*/
declare class MidnightAdapter implements ContractAdapter {
readonly networkConfig: MidnightNetworkConfig;
readonly initialAppServiceKitName: UiKitConfiguration['kitName'];
private artifacts;
constructor(networkConfig: MidnightNetworkConfig);
getEcosystemReactUiContextProvider(): React.FC<EcosystemReactUiProviderProps>;
getEcosystemReactHooks(): EcosystemSpecificReactHooks;
getEcosystemWalletComponents(): EcosystemWalletComponents;
supportsWalletConnection(): boolean;
getAvailableConnectors(): Promise<Connector[]>;
connectWallet(_connectorId: string): Promise<{
connected: boolean;
address?: string;
error?: string;
}>;
disconnectWallet(): Promise<{
disconnected: boolean;
error?: string;
}>;
getWalletConnectionStatus(): {
isConnected: boolean;
address?: string;
chainId?: string;
};
getContractDefinitionInputs(): FormFieldType[];
loadContract(source: string | Record<string, unknown>): Promise<ContractSchema>;
getWritableFunctions(contractSchema: ContractSchema): ContractFunction[];
mapParameterTypeToFieldType(_parameterType: string): FieldType;
getCompatibleFieldTypes(_parameterType: string): FieldType[];
generateDefaultField(parameter: FunctionParameter): FormFieldType;
formatTransactionData(_contractSchema: ContractSchema, _functionId: string, _submittedInputs: Record<string, unknown>, _fields: FormFieldType[]): unknown;
signAndBroadcast(_transactionData: unknown, _executionConfig?: ExecutionConfig): Promise<{
txHash: string;
}>;
isViewFunction(functionDetails: ContractFunction): boolean;
queryViewFunction(_contractAddress: string, _functionId: string, _params: unknown[], _contractSchema?: ContractSchema): Promise<unknown>;
formatFunctionResult(decodedValue: unknown): string;
getSupportedExecutionMethods(): Promise<ExecutionMethodDetail[]>;
validateExecutionConfig(_config: ExecutionConfig): Promise<true | string>;
getExplorerUrl(_address: string): string | null;
getExplorerTxUrl(_txHash: string): string | null;
isValidAddress(_address: string): boolean;
getAvailableUiKits(): Promise<AvailableUiKit[]>;
getRelayers(_serviceUrl: string, _accessToken: string): Promise<RelayerDetails[]>;
getRelayer(_serviceUrl: string, _accessToken: string, _relayerId: string): Promise<RelayerDetailsRich>;
/**
* @inheritdoc
*/
validateRpcEndpoint(rpcConfig: UserRpcProviderConfig): Promise<boolean>;
/**
* @inheritdoc
*/
testRpcConnection(rpcConfig: UserRpcProviderConfig): Promise<{
success: boolean;
latency?: number;
error?: string;
}>;
}
/**
* Midnight-specific contract artifacts interface
* Defines the structure of data needed to load Midnight contracts
*/
interface MidnightContractArtifacts {
/** The deployed contract address (required, Bech32m format) */
contractAddress: string;
/** Unique identifier for private state instance (required) */
privateStateId: string;
/** TypeScript interface definition from contract.d.ts (required) */
contractSchema: string;
/** Optional compiled contract code from contract.cjs */
contractModule?: string;
/** Optional witness functions for zero-knowledge proofs */
witnessCode?: string;
}
/**
* Type guard to check if an object matches MidnightContractArtifacts structure
*/
declare function isMidnightContractArtifacts(obj: unknown): obj is MidnightContractArtifacts;
declare const midnightTestnet: MidnightNetworkConfig;
declare const midnightTestnetNetworks: MidnightNetworkConfig[];
declare const midnightNetworks: MidnightNetworkConfig[];
/**
* Configuration for the Midnight adapter
*
* This file defines the dependencies required by the Midnight adapter
* when generating exported projects. It follows the AdapterConfig
* interface to provide a structured approach to dependency management.
*/
declare const midnightAdapterConfig: {
/**
* Default app name to display in the wallet connection UI.
*/
appName: string;
/**
* Dependencies required by the Midnight adapter
* These will be included in exported projects that use this adapter
*/
dependencies: {
runtime: {
'@midnight-protocol/sdk': string;
'@midnight-protocol/client': string;
'libsodium-wrappers': string;
'@openzeppelin/contracts-upgradeable': string;
'js-sha256': string;
'bn.js': string;
'@midnight-ntwrk/dapp-connector-api': string;
};
dev: {
'@midnight-protocol/testing': string;
'@types/libsodium-wrappers': string;
'@types/bn.js': string;
};
};
};
export { MidnightAdapter, type MidnightContractArtifacts, MidnightAdapter as default, isMidnightContractArtifacts, midnightAdapterConfig, midnightNetworks, midnightTestnet, midnightTestnetNetworks };