Merge pull request #1383 from cosmos/rm-Bech32

Remove Bech32 class
This commit is contained in:
Simon Warta 2023-03-07 15:45:44 +01:00 committed by GitHub
commit fca31fa51a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 6 additions and 28 deletions

View File

@ -26,6 +26,8 @@ and this project adheres to
let it support both Tendermint 0.34 and 0.37 events as input.
- @cosmjs/cosmwasm-stargate: Remove `cosmWasmTypes`. Use
`createWasmAminoConverters()` instead.
- @cosmjs/encoding: Remove previously deprecated `Bech32` class. Please replace
`Bech32.encode`/`.decode` with free the functions `toBech32`/`fromBech32`.
[#1002]: https://github.com/cosmos/cosmjs/issues/1002
[#1240]: https://github.com/cosmos/cosmjs/pull/1240

View File

@ -48,7 +48,7 @@ $ cosmjs-cli
const account = await client.getAccount(faucetAddress);
// Craft a send transaction
const emptyAddress = Bech32.encode("cosmos", Random.getBytes(20));
const emptyAddress = toBech32("cosmos", Random.getBytes(20));
const memo = "My very first tx!";
const msgSend = {
fromAddress: faucetAddress,

View File

@ -2,7 +2,6 @@ import { StdFee, SigningStargateClient } from "@cosmjs/stargate";
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";
import { coins } from "@cosmjs/amino";
import { Bech32 } from "@cosmjs/encoding";
import { Random } from "@cosmjs/crypto";
const defaultHttpUrl = "http://localhost:26658";

View File

@ -71,7 +71,6 @@ export async function main(originalArgs: readonly string[]): Promise<void> {
toBase64,
toHex,
toUtf8,
Bech32,
} from "@cosmjs/encoding";
import { sha512, Bip39, Random } from "@cosmjs/crypto";
import {

View File

@ -26,25 +26,3 @@ export function normalizeBech32(address: string): string {
const { prefix, data } = fromBech32(address);
return toBech32(prefix, data);
}
/**
* @deprecated This class is deprecated and will be removed soon. Please use fromBech32() and toBech32() instead. For more details please refer to https://github.com/cosmos/cosmjs/issues/1053.
*/
export class Bech32 {
/**
* @deprecated This class is deprecated and will be removed soon. Please use fromBech32() and toBech32() instead. For more details please refer to https://github.com/cosmos/cosmjs/issues/1053.
*/
public static encode(prefix: string, data: Uint8Array, limit?: number): string {
return toBech32(prefix, data, limit);
}
/**
* @deprecated This class is deprecated and will be removed soon. Please use fromBech32() and toBech32() instead. For more details please refer to https://github.com/cosmos/cosmjs/issues/1053.
*/
public static decode(
address: string,
limit = Infinity,
): { readonly prefix: string; readonly data: Uint8Array } {
return fromBech32(address, limit);
}
}

View File

@ -1,6 +1,6 @@
export { fromAscii, toAscii } from "./ascii";
export { fromBase64, toBase64 } from "./base64";
export { Bech32, fromBech32, normalizeBech32, toBech32 } from "./bech32";
export { fromBech32, normalizeBech32, toBech32 } from "./bech32";
export { fromHex, toHex } from "./hex";
export { fromRfc3339, toRfc3339 } from "./rfc3339";
export { fromUtf8, toUtf8 } from "./utf8";

View File

@ -1,8 +1,8 @@
import { Bech32 } from "@cosmjs/encoding";
import { fromBech32 } from "@cosmjs/encoding";
export function isValidAddress(input: string, requiredPrefix: string): boolean {
try {
const { prefix, data } = Bech32.decode(input);
const { prefix, data } = fromBech32(input);
if (prefix !== requiredPrefix) {
return false;
}