mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 13:47:12 +00:00
Make input and output of decodePubkey
non-optional
This commit is contained in:
parent
6b05c122fd
commit
866a831dca
@ -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
|
||||
|
||||
|
@ -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": {
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
};
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user