Takes a typeUrl/value pair and encodes the value to protobuf if the given type was previously registered.
If the value has to be wrapped in an Any, this needs to be done
manually after this call. Or use encodeAsAny
instead.
Takes a typeUrl/value pair and encodes the value to an Any if the given type was previously registered.
Looks up a type that was previously added to the registry.
The generator information (ts-proto or pbjs) gets lost along the way. If you need to work with the result type in TypeScript, you can use:
import { assert } from "@cosmjs/utils";
const Coin = registry.lookupType("/cosmos.base.v1beta1.Coin");
assert(Coin); // Ensures not unset
assert(isTsProtoGeneratedType(Coin)); // Ensures this is the type we expect
// Coin is typed TsProtoGeneratedType now.
Generated using TypeDoc
Creates a new Registry for mapping protobuf type identifiers/type URLs to actual implementations. Those implementations are typically generated with ts-proto but we also support protobuf.js as a type generator.
If there is no parameter given, a
new Registry()
adds the typesCoin
andMsgSend
for historic reasons. Those can be overriden by customTypes.There are currently two methods for adding new types:
register()
method