@xpla/xpla
Version:
<p align="center"> <img src="https://user-images.githubusercontent.com/545047/188804067-28e67e5e-0214-4449-ab04-2e0c564a6885.svg" width="80"> </p>
72 lines (70 loc) • 2.81 kB
JavaScript
import { PRESET_COSMOS_EVM_SIGNATURE_FORMATS } from "./signature-processor.js";
import deepmerge from "deepmerge";
import { CosmosCryptoSecp256k1PubKey } from "@interchainjs/cosmos-types";
import { encodeSecp256k1Pubkey } from "@interchainjs/amino";
//#region src/signers/config.ts
/**
* Encode public key for CosmosEvm
* Uses the CosmosEvm-specific public key type URL
*/
const encodeCosmosEvmPublicKey = (publicKey) => {
return {
typeUrl: "/cosmos.evm.crypto.v1.ethsecp256k1.PubKey",
value: CosmosCryptoSecp256k1PubKey.encode(CosmosCryptoSecp256k1PubKey.fromPartial({ key: publicKey })).finish()
};
};
/**
* Default configuration for CosmosEvm signers
* Provides CosmosEvm-specific defaults for fee calculation, signing options, and transaction options
*/
const DEFAULT_COSMOS_EVM_SIGNER_CONFIG = {
multiplier: 1.3,
gasPrice: "280000000000axpla",
addressPrefix: "xpla",
message: { hash: "keccak256" },
signature: { format: PRESET_COSMOS_EVM_SIGNATURE_FORMATS["compact"] },
unordered: false,
extensionOptions: [],
nonCriticalExtensionOptions: [],
encodePublicKey: encodeCosmosEvmPublicKey,
pubkeyDecoders: {
"/cosmos.evm.crypto.v1.ethsecp256k1.PubKey": (pubkey) => {
const { key } = CosmosCryptoSecp256k1PubKey.decode(pubkey.value);
return encodeSecp256k1Pubkey(key);
},
"/ethermint.crypto.v1.ethsecp256k1.PubKey": (pubkey) => {
const { key } = CosmosCryptoSecp256k1PubKey.decode(pubkey.value);
return encodeSecp256k1Pubkey(key);
}
}
};
/**
* Creates a complete CosmosEvm signer configuration by merging user-provided config with defaults
* @param userConfig - User-provided configuration (must include required EndpointOptions)
* @returns Complete CosmosSignerConfig with CosmosEvm defaults applied
*/
function createCosmosEvmSignerConfig(userConfig) {
if (!userConfig.queryClient) throw new Error("queryClient is required in signer configuration");
const queryClient = userConfig.queryClient;
const mergedConfig = deepmerge(DEFAULT_COSMOS_EVM_SIGNER_CONFIG, userConfig, {
arrayMerge: (_destinationArray, sourceArray) => sourceArray,
clone: true
});
mergedConfig.queryClient = queryClient;
return mergedConfig;
}
/**
* Creates a partial configuration for use in sign operations
* Merges the base signer config with operation-specific options
* @param baseConfig - Base signer configuration
* @param operationOptions - Operation-specific options (from sign args)
* @returns Merged configuration for the operation
*/
function mergeCosmosEvmSignerOptions(baseConfig, operationOptions = {}) {
return deepmerge(baseConfig, operationOptions, {
arrayMerge: (_destinationArray, sourceArray) => sourceArray,
clone: true
});
}
//#endregion
export { DEFAULT_COSMOS_EVM_SIGNER_CONFIG, createCosmosEvmSignerConfig, encodeCosmosEvmPublicKey, mergeCosmosEvmSignerOptions };