Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: deprecate bech32 addresses #3204

Closed
wants to merge 11 commits into from
7 changes: 7 additions & 0 deletions .changeset/late-pugs-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@fuel-ts/interfaces": patch
"@fuel-ts/address": patch
"@fuel-ts/errors": patch
---

chore: deprecate bech32 addresses
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Please do not merge this PR until further notice.

This is a hot topic, and there's been some last-minute pondering about this deprecation.

I'll reply to or close this comment with news once there is a consensus about it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Converting this to a draft until we have an consensus around this.

3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ The e2e test can be found at:

The Bech32 address of this wallet is `fuel1x33ajpj0jy5p2wcqqu45e32r75zrwfeh6hwqfv5un670rv4p0mns58enjg`. This address can be funded via the [faucet](https://faucet-testnet.fuel.network/).

> [!NOTE] Note
> The `bech32Address` is now deprecated. Hexadecimal will be the only address format from this point onward.
maschad marked this conversation as resolved.
Show resolved Hide resolved

If you want to run an e2e test locally, you can provide your own wallet address and private key. For obvious security reasons, the private key should not be shared.

These can be overridden by generating an environment file:
Expand Down
3 changes: 3 additions & 0 deletions apps/docs/src/guide/contracts/managing-deployed-contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ The `contractId` property from the [`Contract`](../../api/Program/Contract.md) c

The [`Address`](../../api/Address/Address.md) class wraps all methods from the [`AbstractAddress`](../../api/Interfaces/AbstractAddress.md) class and adds a single property: `bech32Address`. This property is a string encoded in [`Bech32`](../types/bech32.md) format, recognizable by the human-readable prefix `fuel` followed by the separator `1`.

> [!NOTE] Note
> The `bech32Address` is now deprecated. Hexadecimal will be the only address format from this point onward.

When you log the `contractId` property of an instantiated Contract using `console.log`, the output appears as follows:

```console
Expand Down
3 changes: 3 additions & 0 deletions apps/docs/src/guide/types/address.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ To create an [`Address`](../../api/Address/Address.md) from a `Bech32` address,

<<< @/../../docs-snippets/src/guide/types/address.test.ts#address-2{ts:line-numbers}

> [!NOTE] Note
> The `bech32Address` is now deprecated. Hexadecimal will be the only address format from this point onward.

### From a Public Key

To create an [`Address`](../../api/Address/Address.md) from a public key, use the following code snippet:
Expand Down
3 changes: 3 additions & 0 deletions apps/docs/src/guide/types/bech32.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# `Bech32`

> [!NOTE] Note
> The `bech32Address` is now deprecated. Hexadecimal will be the only address format from this point onward.

The SDK uses the `Bech32` type as the core property of the [`Address`](../../api/Address/Address.md) class, specifically through the `bech32Address` property.

Originally designed for Bitcoin, the `Bech32` format offers numerous advantages such as enhanced error detection, simplified integrations, and improved compatibility with future upgrades. Given these benefits, the [`Address`](../../api/Address/Address.md) class is constructed around the `Bech32` type.
Expand Down
3 changes: 3 additions & 0 deletions apps/docs/src/guide/utilities/address-conversion.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The Fuel Network uses the [`Bech32`](../types/bech32.md) address format for its

<<< @/../../docs-snippets/src/guide/types/bech32.test.ts#addresses-1{ts:line-numbers}

> [!NOTE] Note
> The `bech32Address` is now deprecated. Hexadecimal will be the only address format from this point onward.

However, a hexlified [Bits256](../types/bits256.md) (hex) is another common address format; an example can be seen below:

<<< @/../../docs-snippets/src/guide/types/bits256.test.ts#addresses-2{ts:line-numbers}
Expand Down
3 changes: 3 additions & 0 deletions packages/address/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

This module contains the utilities for encoding and decoding address and contract ids between Bech32 and other address formats.

> [!NOTE] Note
> The `bech32Address` is now deprecated. Hexadecimal will be the only address format from this point onward.

# Table of contents

- [Documentation](#documentation)
Expand Down
31 changes: 22 additions & 9 deletions packages/address/src/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ import {
*/
export default class Address extends AbstractAddress {
// #region address-2
/**
* @deprecated
* The `bech32Address` is now deprecated. Hexadecimal will be the only address format from this point onward.
*/
readonly bech32Address: Bech32Address;
// #endregion address-2

Expand All @@ -44,7 +48,8 @@ export default class Address extends AbstractAddress {

/**
* Returns the `bech32Address` property
*
* @deprecated
* The `bech32Address` is now deprecated. Hexadecimal will be the only address format from this point onward.
maschad marked this conversation as resolved.
Show resolved Hide resolved
* @returns The `bech32Address` property
*/
toAddress(): Bech32Address {
Expand All @@ -53,7 +58,8 @@ export default class Address extends AbstractAddress {

/**
* Converts and returns the `bech32Address` property to a 256 bit hash string
*
* @deprecated
* The `bech32Address` is now deprecated. Hexadecimal will be the only address format from this point onward.
maschad marked this conversation as resolved.
Show resolved Hide resolved
* @returns The `bech32Address` property as a 256 bit hash string
*/
toB256(): B256Address {
Expand All @@ -62,7 +68,8 @@ export default class Address extends AbstractAddress {

/**
* Converts and returns the `bech32Address` property to a byte array
*
* @deprecated
* The `bech32Address` is now deprecated. Hexadecimal will be the only address format from this point onward.
* @returns The `bech32Address` property as a byte array
*/
toBytes(): Uint8Array {
Expand All @@ -71,7 +78,8 @@ export default class Address extends AbstractAddress {

/**
* Converts
*
* @deprecated
* The `bech32Address` is now deprecated. Hexadecimal will be the only address format from this point onward.
* @returns The `bech32Address` property as a 256 bit hash string
*/
toHexString(): B256Address {
Expand All @@ -89,7 +97,8 @@ export default class Address extends AbstractAddress {

/**
* Converts and returns the `bech32Address` property as a string
*
* @deprecated
* The `bech32Address` is now deprecated. Hexadecimal will be the only address format from this point onward.
* @returns The `bech32Address` property as a string
*/
toJSON(): string {
Expand All @@ -98,7 +107,8 @@ export default class Address extends AbstractAddress {

/**
* Clears the first 12 bytes of the `bech32Address` property and returns it as a `EvmAddress`
*
* @deprecated
* The `bech32Address` is now deprecated. Hexadecimal will be the only address format from this point onward.
* @returns The `bech32Address` property as an {@link EvmAddress | `EvmAddress`}
*/
toEvmAddress(): EvmAddress {
Expand All @@ -111,7 +121,8 @@ export default class Address extends AbstractAddress {

/**
* Wraps the `bech32Address` property and returns as an `AssetId`.
*
* @deprecated
* The `bech32Address` is now deprecated. Hexadecimal will be the only address format from this point onward.
* @returns The `bech32Address` property as an {@link AssetId | `AssetId`}
*/
toAssetId(): AssetId {
Expand All @@ -122,7 +133,8 @@ export default class Address extends AbstractAddress {

/**
* Returns the value of the `bech32Address` property
*
*@deprecated
* The `bech32Address` is now deprecated. Hexadecimal will be the only address format from this point onward.
* @returns The value of `bech32Address` property
*/
valueOf(): string {
Expand All @@ -131,7 +143,8 @@ export default class Address extends AbstractAddress {

/**
* Compares this the `bech32Address` property to another for direct equality
*
* @deprecated
* The `bech32Address` is now deprecated. Hexadecimal will be the only address format from this point onward.
* @param other - Another address to compare against
* @returns The equality of the comparison
*/
Expand Down
9 changes: 6 additions & 3 deletions packages/address/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export const FUEL_BECH32_HRP_PREFIX = 'fuel';

/**
* Decodes a Bech32 address string into Decoded
*
* @deprecated
* The `bech32Address` is now deprecated. Hexadecimal will be the only address format from this point onward.
* @hidden
*/
export function fromBech32(address: Bech32Address): Decoded {
Expand All @@ -32,7 +33,8 @@ export function fromBech32(address: Bech32Address): Decoded {

/**
* Converts a B256 address string into Bech32
*
* @deprecated
* The `bech32Address` is now deprecated. Hexadecimal will be the only address format from this point onward.
* @hidden
*/
export function toBech32(address: B256Address): Bech32Address {
Expand All @@ -44,7 +46,8 @@ export function toBech32(address: B256Address): Bech32Address {

/**
* Determines if a given string is Bech32 format
*
* @deprecated
* The `bech32Address` is now deprecated. Hexadecimal will be the only address format from this point onward.
* @hidden
*/
export function isBech32(address: BytesLike): boolean {
Expand Down
5 changes: 5 additions & 0 deletions packages/errors/src/error-codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ export enum ErrorCode {
WORKSPACE_NOT_DETECTED = 'workspace-not-detected',

// address
/**
* @deprecated
* The `bech32Address` is now deprecated. Hexadecimal will be the only address format from this point onward.
*/
INVALID_BECH32_ADDRESS = 'invalid-bech32-address',

INVALID_EVM_ADDRESS = 'invalid-evm-address',
INVALID_B256_ADDRESS = 'invalid-b256-address',

Expand Down
4 changes: 4 additions & 0 deletions packages/interfaces/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
*/

// #region bech32-1
/**
* @deprecated
* The `bech32Address` is now deprecated. Hexadecimal will be the only address format from this point onward.
*/
export type Bech32Address = `fuel${string}`;
// #endregion bech32-1
export type B256Address = string;
Expand Down
Loading