UNPKG

interchainjs

Version:

InterchainJS is a JavaScript library for interacting with Cosmos SDK based blockchains.

91 lines (90 loc) 3.04 kB
import { BinaryReader, BinaryWriter } from "../../../../binary"; import { bytesFromBase64, base64FromBytes } from "../../../../helpers"; function createBaseMerklePath() { return { keyPath: [] }; } /** * MerklePath is the path used to verify commitment proofs, which can be an * arbitrary structured object (defined by a commitment type). * MerklePath is represented from root-to-leaf * @name MerklePath * @package ibc.core.commitment.v2 * @see proto type: ibc.core.commitment.v2.MerklePath */ export const MerklePath = { typeUrl: "/ibc.core.commitment.v2.MerklePath", aminoType: "cosmos-sdk/MerklePath", is(o) { return o && (o.$typeUrl === MerklePath.typeUrl || Array.isArray(o.keyPath) && (!o.keyPath.length || o.keyPath[0] instanceof Uint8Array || typeof o.keyPath[0] === "string")); }, isAmino(o) { return o && (o.$typeUrl === MerklePath.typeUrl || Array.isArray(o.key_path) && (!o.key_path.length || o.key_path[0] instanceof Uint8Array || typeof o.key_path[0] === "string")); }, encode(message, writer = BinaryWriter.create()) { for (const v of message.keyPath) { writer.uint32(10).bytes(v); } return writer; }, decode(input, length) { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; const message = createBaseMerklePath(); while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { case 1: message.keyPath.push(reader.bytes()); break; default: reader.skipType(tag & 7); break; } } return message; }, fromPartial(object) { const message = createBaseMerklePath(); message.keyPath = object.keyPath?.map(e => e) || []; return message; }, fromAmino(object) { const message = createBaseMerklePath(); message.keyPath = object.key_path?.map(e => bytesFromBase64(e)) || []; return message; }, toAmino(message) { const obj = {}; if (message.keyPath) { obj.key_path = message.keyPath.map(e => base64FromBytes(e)); } else { obj.key_path = message.keyPath; } return obj; }, fromAminoMsg(object) { return MerklePath.fromAmino(object.value); }, toAminoMsg(message) { return { type: "cosmos-sdk/MerklePath", value: MerklePath.toAmino(message) }; }, fromProtoMsg(message) { return MerklePath.decode(message.value); }, toProto(message) { return MerklePath.encode(message).finish(); }, toProtoMsg(message) { return { typeUrl: "/ibc.core.commitment.v2.MerklePath", value: MerklePath.encode(message).finish() }; }, registerTypeUrl() { } };