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

Draft
wants to merge 11 commits into
base: next
Choose a base branch
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
> `Bech32` addresses like `fuel1..` are now deprecated. Use `B256` addresses instead. ([help](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256))

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
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
> `Bech32` addresses like `fuel1..` are now deprecated; please switch to B256 format, for more details see [here](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256).

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
> `Bech32` addresses like `fuel1..` are now deprecated. Use `B256` addresses instead. ([help](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256))

### 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
> `Bech32` addresses like `fuel1..` are now deprecated. Use `B256` addresses instead. ([help](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256))

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
> `Bech32` addresses like `fuel1..` are now deprecated. Use `B256` addresses instead. ([help](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256))

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
> `Bech32` addresses like `fuel1..` are now deprecated. Use `B256` addresses instead. ([help](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256))

# Table of contents

- [Documentation](#documentation)
Expand Down
25 changes: 12 additions & 13 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
* Type `Bech32Address` is now deprecated, as is this property. Use `B256` addresses instead. ([help](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256))
*/
readonly bech32Address: Bech32Address;
// #endregion address-2

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

/**
* Returns the `bech32Address` property
*
* @deprecated
* Type `Bech32Address` is now deprecated, as is this method. Use `B256` addresses instead. ([help](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256))
* @returns The `bech32Address` property
*/
toAddress(): Bech32Address {
Expand All @@ -53,7 +58,6 @@ export default class Address extends AbstractAddress {

/**
* Converts and returns the `bech32Address` property to a 256 bit hash string
*
* @returns The `bech32Address` property as a 256 bit hash string
*/
toB256(): B256Address {
Expand All @@ -62,16 +66,14 @@ export default class Address extends AbstractAddress {

/**
* Converts and returns the `bech32Address` property to a byte array
*
* @returns The `bech32Address` property as a byte array
*/
toBytes(): Uint8Array {
return getBytesFromBech32(this.bech32Address);
}

/**
* Converts
*
* Converts the `bech32Address` property to a 256 bit hash string
* @returns The `bech32Address` property as a 256 bit hash string
*/
toHexString(): B256Address {
Expand All @@ -89,16 +91,14 @@ export default class Address extends AbstractAddress {

/**
* Converts and returns the `bech32Address` property as a string
*
* @returns The `bech32Address` property as a string
* @returns The `bech32Address` property as a JSON string
*/
toJSON(): string {
return this.bech32Address;
}

/**
* Clears the first 12 bytes of the `bech32Address` property and returns it as a `EvmAddress`
*
* @returns The `bech32Address` property as an {@link EvmAddress | `EvmAddress`}
*/
toEvmAddress(): EvmAddress {
Expand All @@ -110,9 +110,8 @@ export default class Address extends AbstractAddress {
}

/**
* Wraps the `bech32Address` property and returns as an `AssetId`.
*
* @returns The `bech32Address` property as an {@link AssetId | `AssetId`}
* Wraps the B256 property and returns as an `AssetId`.
* @returns The B256 property as an {@link AssetId | `AssetId`}
*/
toAssetId(): AssetId {
return {
Expand All @@ -122,7 +121,8 @@ export default class Address extends AbstractAddress {

/**
* Returns the value of the `bech32Address` property
*
* @deprecated
* Type `Bech32Address` is now deprecated, as is this method. Use `B256` addresses instead. ([help](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256))
* @returns The value of `bech32Address` property
*/
valueOf(): string {
Expand All @@ -131,7 +131,6 @@ export default class Address extends AbstractAddress {

/**
* Compares this the `bech32Address` property to another for direct equality
*
* @param other - Another address to compare against
* @returns The equality of the comparison
*/
Expand Down
13 changes: 8 additions & 5 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
* Type `Bech32Address` is now deprecated, as is this function. Use `B256` addresses instead. ([help](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256))
* @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
* Type `Bech32Address` is now deprecated, as is this function. Use `B256` addresses instead. ([help](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256))
* @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
* Type `Bech32Address` is now deprecated, as is this function. Use `B256` addresses instead. ([help](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256))
* @hidden
*/
export function isBech32(address: BytesLike): boolean {
Expand Down Expand Up @@ -84,7 +87,8 @@ export function isEvmAddress(address: string): boolean {

/**
* Takes a Bech32 address and returns the byte data
*
* @deprecated
* The `bech32Address` is now deprecated. Please migrate to B256 format (see https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256 for more details) as this will be the standard going forward.
* @hidden
*/
export function getBytesFromBech32(address: Bech32Address): Uint8Array {
Expand All @@ -93,7 +97,6 @@ export function getBytesFromBech32(address: Bech32Address): Uint8Array {

/**
* Converts a Bech32 address string into B256
*
* @hidden
*/
export function toB256(address: Bech32Address): B256Address {
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
* Type `Bech32Address` is now deprecated, as is this constant. Use `B256` addresses instead. ([help](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256))
*/
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
* Type `Bech32Address` is now deprecated. Use `B256` addresses instead. ([help](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256))
*/
export type Bech32Address = `fuel${string}`;
// #endregion bech32-1
export type B256Address = string;
Expand Down