From 0351a46d9786325a7c16c2f8e4f91128a59e0f04 Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Tue, 7 Mar 2023 15:06:29 +0100 Subject: [PATCH] Remove Bech32 class --- CHANGELOG.md | 2 ++ packages/cli/README.md | 2 +- packages/cli/examples/local_faucet.ts | 1 - packages/cli/src/cli.ts | 1 - packages/encoding/src/bech32.ts | 22 ---------------------- packages/encoding/src/index.ts | 2 +- packages/faucet/src/addresses.ts | 4 ++-- 7 files changed, 6 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 522ed14357..dece7b1a05 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/cli/README.md b/packages/cli/README.md index 28775e05d7..c590b4c05e 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -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, diff --git a/packages/cli/examples/local_faucet.ts b/packages/cli/examples/local_faucet.ts index dd314be36b..0a9bc6e0dc 100644 --- a/packages/cli/examples/local_faucet.ts +++ b/packages/cli/examples/local_faucet.ts @@ -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"; diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index c247f31907..0dcd9e5aa3 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -71,7 +71,6 @@ export async function main(originalArgs: readonly string[]): Promise { toBase64, toHex, toUtf8, - Bech32, } from "@cosmjs/encoding"; import { sha512, Bip39, Random } from "@cosmjs/crypto"; import { diff --git a/packages/encoding/src/bech32.ts b/packages/encoding/src/bech32.ts index d333611a93..7af6c97378 100644 --- a/packages/encoding/src/bech32.ts +++ b/packages/encoding/src/bech32.ts @@ -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); - } -} diff --git a/packages/encoding/src/index.ts b/packages/encoding/src/index.ts index 9ca7cc196f..a2dc4771f2 100644 --- a/packages/encoding/src/index.ts +++ b/packages/encoding/src/index.ts @@ -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"; diff --git a/packages/faucet/src/addresses.ts b/packages/faucet/src/addresses.ts index bafe414bb0..6792a5414d 100644 --- a/packages/faucet/src/addresses.ts +++ b/packages/faucet/src/addresses.ts @@ -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; }