@apophis-sdk/core
package contains definitions for protobuf, and the @apophis-sdk/cosmos
package contains definitions for Amino, a Cosmos-specific encoding format. Cosmos messages generally
have to support both formats. To do so, the Messages concept was introduced. However, messages are
not a concrete class or interface. Instead, they hook into the encoding middleware.
Following is the definition of the Encoding Middleware:
Implicit Interfaces
The default built-in ProtoBuf and Amino encodings used for the Cosmos integration use a concept of implicit interfaces - i.e. types are made compatible without expressly implementing a TypeScript interface. This is done because it is not the class instance that needs to adhere to a specific interface, but the class itself, but theimplements
keyword gives no such assurance over the
actual class.
The ProtoBuf and Amino encodings use the registerDefaultProtobuf
and registerDefaultAmino
methods respectively. The signature of these methods ensures a class is actually compatible. These
methods use the following definitions:
@apophis-sdk/core/encoding/protobuf/any.ts
@apophis-sdk/cosmos/encoding/amino.ts
Specialization: Public Keys
As Web3 is built fundamentally on asymmetric cryptography, public and private keys are a core concept vital to all contemporary blockchains. However, just because two blockchains happen to use the ed25519 or secp256k1 curves doesn’t mean they use the same binary representation for transmission or internal storage. Thus, the@apophis-sdk/core
package only contains a rudimentary, generic
class with generalized public key types, and the @apophis-sdk/cosmos
package implements their
encodings as follows:
@apophis-sdk/core/crypto/pubkey.ts
@apophis-sdk/cosmos/crypto/pubkey.ts
PublicKey
base class. Note that, of course, the
middleware has to be registered with mw.use
(though it is included in DefaultCosmosMiddlewares
).
As you can see, it also defines how these public keys are converted to addresses for specific
networks. A real use case for this is the Injective blockchain which uses a different elliptic
curve for its key pairs in order to be compatible with the EVM, and thus arrives at a different
address format.