@xpla/xpla
Version:
<p align="center"> <img src="https://user-images.githubusercontent.com/545047/188804067-28e67e5e-0214-4449-ab04-2e0c564a6885.svg" width="80"> </p>
78 lines (76 loc) • 3.37 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
const require_signers_signature_processor = require('./signature-processor.cjs');
let deepmerge = require("deepmerge");
deepmerge = require_runtime.__toESM(deepmerge);
let _interchainjs_cosmos_types = require("@interchainjs/cosmos-types");
let _interchainjs_amino = require("@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: _interchainjs_cosmos_types.CosmosCryptoSecp256k1PubKey.encode(_interchainjs_cosmos_types.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: require_signers_signature_processor.PRESET_COSMOS_EVM_SIGNATURE_FORMATS["compact"] },
unordered: false,
extensionOptions: [],
nonCriticalExtensionOptions: [],
encodePublicKey: encodeCosmosEvmPublicKey,
pubkeyDecoders: {
"/cosmos.evm.crypto.v1.ethsecp256k1.PubKey": (pubkey) => {
const { key } = _interchainjs_cosmos_types.CosmosCryptoSecp256k1PubKey.decode(pubkey.value);
return (0, _interchainjs_amino.encodeSecp256k1Pubkey)(key);
},
"/ethermint.crypto.v1.ethsecp256k1.PubKey": (pubkey) => {
const { key } = _interchainjs_cosmos_types.CosmosCryptoSecp256k1PubKey.decode(pubkey.value);
return (0, _interchainjs_amino.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 = (0, deepmerge.default)(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 (0, deepmerge.default)(baseConfig, operationOptions, {
arrayMerge: (_destinationArray, sourceArray) => sourceArray,
clone: true
});
}
//#endregion
exports.DEFAULT_COSMOS_EVM_SIGNER_CONFIG = DEFAULT_COSMOS_EVM_SIGNER_CONFIG;
exports.createCosmosEvmSignerConfig = createCosmosEvmSignerConfig;
exports.encodeCosmosEvmPublicKey = encodeCosmosEvmPublicKey;
exports.mergeCosmosEvmSignerOptions = mergeCosmosEvmSignerOptions;