diff --git a/CHANGELOG.md b/CHANGELOG.md index 64d43e80b4..6ba142dfeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,10 +16,13 @@ and this project adheres to `pbkdf2Sha512Crypto` was removed. Node.js has sufficient support for WebCrypto these days and we still have a pure-JS fallback implementation. This avoids unnecessary problems around importing Node.js modules. ([#1341]) +- @cosmjs/proto-signing: Make input and output of `decodePubkey` non-optional + ([#1289]). [#1002]: https://github.com/cosmos/cosmjs/issues/1002 [#1341]: https://github.com/cosmos/cosmjs/issues/1341 [#1240]: https://github.com/cosmos/cosmjs/pull/1240 +[#1289]: https://github.com/cosmos/cosmjs/issues/1289 ## [0.29.5] - 2022-12-07 diff --git a/packages/proto-signing/src/pubkey.ts b/packages/proto-signing/src/pubkey.ts index 8a07980d51..8fc935f9f2 100644 --- a/packages/proto-signing/src/pubkey.ts +++ b/packages/proto-signing/src/pubkey.ts @@ -57,8 +57,7 @@ export function encodePubkey(pubkey: Pubkey): Any { * Decodes a single pubkey (i.e. not a multisig pubkey) from `Any` into * `SinglePubkey`. * - * In most cases you probably want to use `decodePubkey`, but `anyToSinglePubkey` - * might be preferred in CosmJS 0.29.x due to https://github.com/cosmos/cosmjs/issues/1289. + * In most cases you probably want to use `decodePubkey`. */ export function anyToSinglePubkey(pubkey: Any): SinglePubkey { switch (pubkey.typeUrl) { @@ -75,11 +74,12 @@ export function anyToSinglePubkey(pubkey: Any): SinglePubkey { } } -export function decodePubkey(pubkey?: Any | null): Pubkey | null { - if (!pubkey || !pubkey.value) { - return null; - } - +/** + * Decodes a pubkey from a protobuf `Any` into `Pubkey`. + * This supports single pubkeys such as Cosmos ed25519 and secp256k1 keys + * as well as multisig threshold pubkeys. + */ +export function decodePubkey(pubkey: Any): Pubkey { switch (pubkey.typeUrl) { case "/cosmos.crypto.secp256k1.PubKey": case "/cosmos.crypto.ed25519.PubKey": { diff --git a/packages/stargate/src/accounts.ts b/packages/stargate/src/accounts.ts index 8b5d74a1dd..77ca4f968b 100644 --- a/packages/stargate/src/accounts.ts +++ b/packages/stargate/src/accounts.ts @@ -26,7 +26,7 @@ function uint64FromProto(input: number | Long): Uint64 { function accountFromBaseAccount(input: BaseAccount): Account { const { address, pubKey, accountNumber, sequence } = input; - const pubkey = decodePubkey(pubKey); + const pubkey = pubKey ? decodePubkey(pubKey) : null; return { address: address, pubkey: pubkey, diff --git a/packages/stargate/src/modules/staking/aminomessages.ts b/packages/stargate/src/modules/staking/aminomessages.ts index 38f3131f80..6eb171f817 100644 --- a/packages/stargate/src/modules/staking/aminomessages.ts +++ b/packages/stargate/src/modules/staking/aminomessages.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { AminoMsg, Coin, Pubkey } from "@cosmjs/amino"; import { Decimal } from "@cosmjs/math"; -import { anyToSinglePubkey, encodePubkey } from "@cosmjs/proto-signing"; +import { decodePubkey, encodePubkey } from "@cosmjs/proto-signing"; import { assertDefinedAndNotNull } from "@cosmjs/utils"; import { MsgBeginRedelegate, @@ -206,7 +206,7 @@ export function createStakingAminoConverters( min_self_delegation: minSelfDelegation, delegator_address: delegatorAddress, validator_address: validatorAddress, - pubkey: anyToSinglePubkey(pubkey), + pubkey: decodePubkey(pubkey), value: value, }; },