From 84cab1709322e29d6761360c1dd8cb807d2614f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Mon, 22 Jan 2024 09:11:13 -0300 Subject: [PATCH] docs: add API ref links (#1664) --- .changeset/silent-schools-accept.md | 2 ++ apps/docs/spell-check-custom-words.txt | 7 ++++- apps/docs/src/glossary.md | 2 +- apps/docs/src/guide/addresses/conversion.md | 10 +++---- .../contracts/calls-with-different-wallets.md | 2 +- .../src/guide/contracts/contract-balance.md | 4 +-- .../src/guide/contracts/cost-estimation.md | 2 +- .../guide/contracts/deploying-contracts.md | 2 +- .../contracts/managing-deployed-contracts.md | 8 +++--- .../src/guide/cookbook/custom-transactions.md | 4 +-- apps/docs/src/guide/predicates/index.md | 2 +- .../send-and-spend-funds-from-predicates.md | 4 +-- apps/docs/src/guide/providers/index.md | 2 +- apps/docs/src/guide/types/address.md | 22 ++++++++-------- apps/docs/src/guide/types/bech32.md | 4 +-- apps/docs/src/guide/types/bits256.md | 2 +- apps/docs/src/guide/wallets/access.md | 26 +++++++++---------- .../encrypting-and-decrypting-json-wallets.md | 8 +++--- 18 files changed, 60 insertions(+), 53 deletions(-) create mode 100644 .changeset/silent-schools-accept.md diff --git a/.changeset/silent-schools-accept.md b/.changeset/silent-schools-accept.md new file mode 100644 index 00000000000..a845151cc84 --- /dev/null +++ b/.changeset/silent-schools-accept.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/apps/docs/spell-check-custom-words.txt b/apps/docs/spell-check-custom-words.txt index bfd718d9b3a..d1702363b1c 100644 --- a/apps/docs/spell-check-custom-words.txt +++ b/apps/docs/spell-check-custom-words.txt @@ -288,4 +288,9 @@ cryptographically Config config configs -WSL \ No newline at end of file +WSL +WalletUnlocked +WalletLocked +AbstractAddress +ContractFactory +ScriptTransactionRequest diff --git a/apps/docs/src/glossary.md b/apps/docs/src/glossary.md index 94d7c83dbd8..cb6e3fff6b0 100644 --- a/apps/docs/src/glossary.md +++ b/apps/docs/src/glossary.md @@ -12,4 +12,4 @@ A Provider is a Class that provides an abstraction for a connection to a Fuel no ## Wallet and signer -A `Wallet` is a Class with direct or indirect access to a private key. You can use a `Wallet` to sign messages and transactions to authorize the network to charge your account to perform operations. The terms wallet and signer in the SDK are often used interchangeably, but, technically, a `Signer` enables the signing of transactions and messages; the `Wallet` implements the `Signer` functionality. +A [`Wallet`](./api/Wallet/Wallet.md) is a Class with direct or indirect access to a private key. You can use a [`Wallet`](./api/Wallet/Wallet.md) to sign messages and transactions to authorize the network to charge your account to perform operations. The terms wallet and signer in the SDK are often used interchangeably, but, technically, a `Signer` enables the signing of transactions and messages; the [`Wallet`](./api/Wallet/Wallet.md) implements the `Signer` functionality. diff --git a/apps/docs/src/guide/addresses/conversion.md b/apps/docs/src/guide/addresses/conversion.md index 13bb6a0b5a8..b49b49983c9 100644 --- a/apps/docs/src/guide/addresses/conversion.md +++ b/apps/docs/src/guide/addresses/conversion.md @@ -4,7 +4,7 @@ This guide demonstrates how to convert between address formats and Sway Standard ## From `Bech32` to `b256` -By instantiating an `Address`, we can validate a `Bech32` address and easily convert it to a `b256`: +By instantiating an [`Address`](../../api/Address/Address.md), we can validate a `Bech32` address and easily convert it to a `b256`: <<< @/../../docs-snippets/src/guide/types/conversion.test.ts#conversion-5{ts:line-numbers} @@ -14,7 +14,7 @@ Or, if you'd prefer to use utility functions directly for validation and convers ## From `b256` to `Bech32` -In a similar fashion, we have both class functions on the `Address` and utilities available for `b256` validation and conversion: +In a similar fashion, we have both class functions on the [`Address`](../../api/Address/Address.md) and utilities available for `b256` validation and conversion: <<< @/../../docs-snippets/src/guide/types/conversion.test.ts#conversion-7{ts:line-numbers} @@ -24,18 +24,18 @@ And by using the `isB256` and `toBech32` utilities: ## Converting a Contract ID -The Contract `id` property has the [`AbstractAddress`](../types/address#abstractaddress-class) type. Therefore, it can be converted using the `Address` class functions such as `toAddress` and `toB256`: +The Contract `id` property has the [`AbstractAddress`](../types/address#abstractaddress-class) type. Therefore, it can be converted using the [`Address`](../../api/Address/Address.md) class functions such as `toAddress` and `toB256`: <<< @/../../docs-snippets/src/guide/types/conversion.test.ts#conversion-2{ts:line-numbers} ## Converting a Wallet Address -Similarly, the Wallet `address` property is also of type [`AbstractAddress`](../types/address#abstractaddress-class) and can therefore use the same `Address` class functions for conversion: +Similarly, the Wallet `address` property is also of type [`AbstractAddress`](../types/address#abstractaddress-class) and can therefore use the same [`Address`](../../api/Address/Address.md) class functions for conversion: <<< @/../../docs-snippets/src/guide/types/conversion.test.ts#conversion-3{ts:line-numbers} ## Converting an Asset ID -[Asset IDs](../types/asset-id.md) are a wrapped [b256](../types/bits256.md) value. The following example shows how to create an `Address` from a `b256` type: +[Asset IDs](../types/asset-id.md) are a wrapped [b256](../types/bits256.md) value. The following example shows how to create an [`Address`](../../api/Address/Address.md) from a `b256` type: <<< @/../../docs-snippets/src/guide/types/conversion.test.ts#conversion-4{ts:line-numbers} diff --git a/apps/docs/src/guide/contracts/calls-with-different-wallets.md b/apps/docs/src/guide/contracts/calls-with-different-wallets.md index 958fafb7afc..7b4cd78e106 100644 --- a/apps/docs/src/guide/contracts/calls-with-different-wallets.md +++ b/apps/docs/src/guide/contracts/calls-with-different-wallets.md @@ -1,6 +1,6 @@ # Making Calls with Different Wallets or Providers -This guide demonstrates how to make contract calls using different wallets and providers by passing either an `Account` or a `Provider` to the contract on instantiation. +This guide demonstrates how to make contract calls using different wallets and providers by passing either an [`Account`](../../api/Wallet/Account.md) or a [`Provider`](../../api/Providers/Provider.md) to the contract on instantiation. ## Changing Wallets diff --git a/apps/docs/src/guide/contracts/contract-balance.md b/apps/docs/src/guide/contracts/contract-balance.md index 35de00e85a9..8bd08f0dc4f 100644 --- a/apps/docs/src/guide/contracts/contract-balance.md +++ b/apps/docs/src/guide/contracts/contract-balance.md @@ -1,10 +1,10 @@ # Contract Balance -When working with contracts, it's crucial to be aware of the available contract balance of an asset while paying for costly operations. This guide will explain the `getBalance` method in the `Contract` class, which allows you to check a contract's available balance. +When working with contracts, it's crucial to be aware of the available contract balance of an asset while paying for costly operations. This guide will explain the `getBalance` method in the [Contract](../../api/Program/Contract.md) class, which allows you to check a contract's available balance. ## The `getBalance` Method -The `Contract` class includes a method called `getBalance` that retrieves the available balance of a specific asset for a contract. This method is particularly useful for determining the remaining balance after sending assets to a contract and executing contract calls. +The [`Contract`](../../api/Program/Contract.md) class includes a method called `getBalance` that retrieves the available balance of a specific asset for a contract. This method is particularly useful for determining the remaining balance after sending assets to a contract and executing contract calls. <<< @/../../../packages/program/src/contract.ts#contract-balance-1{ts:line-numbers} diff --git a/apps/docs/src/guide/contracts/cost-estimation.md b/apps/docs/src/guide/contracts/cost-estimation.md index a396b8870fc..83f8d034b3b 100644 --- a/apps/docs/src/guide/contracts/cost-estimation.md +++ b/apps/docs/src/guide/contracts/cost-estimation.md @@ -1,6 +1,6 @@ # Estimating Contract Call Cost -The `getTransactionCost` function provided by the `provider` allows you to estimate the cost of a specific contract call. The return type, `TransactionCost`, is an object containing relevant information for the estimation: +The `getTransactionCost` function provided by the [Provider](../../api/Providers/Provider.md) allows you to estimate the cost of a specific contract call. The return type, `TransactionCost`, is an object containing relevant information for the estimation: <<< @/../../../packages/providers/src/provider.ts#cost-estimation-1{ts:line-numbers} diff --git a/apps/docs/src/guide/contracts/deploying-contracts.md b/apps/docs/src/guide/contracts/deploying-contracts.md index ac4a30ca132..f9edf0df2a4 100644 --- a/apps/docs/src/guide/contracts/deploying-contracts.md +++ b/apps/docs/src/guide/contracts/deploying-contracts.md @@ -27,7 +27,7 @@ Load the contract bytecode and JSON ABI, generated from the Sway source, into th ## 4. Deploying the Contract -Initialize a `ContractFactory` with the bytecode, ABI, and wallet. Deploy the contract and use its methods. +Initialize a [`ContractFactory`](../../api/Contract/ContractFactory.md) with the bytecode, ABI, and wallet. Deploy the contract and use its methods. <<< @/../../docs-snippets/src/guide/contracts/deploying-contracts.test.ts#contract-setup-3{ts:line-numbers} diff --git a/apps/docs/src/guide/contracts/managing-deployed-contracts.md b/apps/docs/src/guide/contracts/managing-deployed-contracts.md index b32f367d8b5..dc13f7a19a0 100644 --- a/apps/docs/src/guide/contracts/managing-deployed-contracts.md +++ b/apps/docs/src/guide/contracts/managing-deployed-contracts.md @@ -4,9 +4,9 @@ To interact with a deployed contract using the SDK without redeploying it, you o ## Contract ID -The `contractId` property from the `Contract` class is of type `AbstractAddress`, an abstract class that is exclusively extended by the `Address` class. +The `contractId` property from the [`Contract`](../../api/Program/Contract.md) class is of type [`AbstractAddress`](../../api/Interfaces/AbstractAddress.md), an abstract class that is exclusively extended by the [`Address`](../../api/Address/Address.md) class. -The `Address` class wraps all methods from the `AbstractAddress` 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`. +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`. When you log the `contractId` property of an instantiated Contract using `console.log`, the output appears as follows: @@ -22,10 +22,10 @@ If you have already an instantiated and deployed contract in hands you can creat <<< @/../../docs-snippets/src/guide/contracts/managing-deployed-contracts.test.ts#managing-deployed-contracts-1{ts:line-numbers} -The previous example assumes that you have a `Contract` instance at hand. However, some Fuel tools and Sway use the [`b256`](../types/bits256.md) type format, a hex-encoded string-like type, for contract IDs. +The previous example assumes that you have a [`Contract`](../../api/Program/Contract.md) instance at hand. However, some Fuel tools and Sway use the [`b256`](../types/bits256.md) type format, a hex-encoded string-like type, for contract IDs. You might have this format instead, for example, if you have deployed your contract with `forc deploy`. -The process of instantiating a `Contract` remains the same when using a contract ID of type `b256`: +The process of instantiating a [`Contract`](../../api/Program/Contract.md) remains the same when using a contract ID of type `b256`: <<< @/../../docs-snippets/src/guide/contracts/managing-deployed-contracts.test.ts#managing-deployed-contracts-2{ts:line-numbers} diff --git a/apps/docs/src/guide/cookbook/custom-transactions.md b/apps/docs/src/guide/cookbook/custom-transactions.md index a684c2c5323..15e92873875 100644 --- a/apps/docs/src/guide/cookbook/custom-transactions.md +++ b/apps/docs/src/guide/cookbook/custom-transactions.md @@ -1,11 +1,11 @@ # Custom Transactions -There may be scenarios where you need to build out transactions that involve multiple program types and assets; this can be done by instantiating a `ScriptTransactionRequest`. This class allows you to a append multiple program types and assets to a single transaction. +There may be scenarios where you need to build out transactions that involve multiple program types and assets; this can be done by instantiating a [`ScriptTransactionRequest`](../../api/Providers/ScriptTransactionRequest.md). This class allows you to a append multiple program types and assets to a single transaction. Consider the following script that transfers multiple assets to a contract: <<< @/../../docs-snippets/test/fixtures/forc-projects/script-transfer-to-contract/src/main.sw#custom-transactions-1{ts:line-numbers} -This script can be executed by creating a `ScriptTransactionRequest`, appending the resource and contract inputs/outputs and then sending the transaction, as follows: +This script can be executed by creating a [`ScriptTransactionRequest`](../../api/Providers/ScriptTransactionRequest.md), appending the resource and contract inputs/outputs and then sending the transaction, as follows: <<< @/../../docs-snippets/src/guide/scripts/script-custom-transaction.test.ts#custom-transactions-2{ts:line-numbers} diff --git a/apps/docs/src/guide/predicates/index.md b/apps/docs/src/guide/predicates/index.md index e3f632cf90b..1fede44dfac 100644 --- a/apps/docs/src/guide/predicates/index.md +++ b/apps/docs/src/guide/predicates/index.md @@ -31,7 +31,7 @@ After compiling, you will obtain the binary of the predicate and its JSON ABI (A <<< @/../../docs-snippets/src/guide/predicates/index.test.ts#predicate-index-2{ts:line-numbers} -The created `Predicate` instance, among other things, has three important properties: the predicate `bytes` (byte code), the `chainId`, and the predicate `address`. +The created [`Predicate`](../../api/Predicate/Predicate.md) instance, among other things, has three important properties: the predicate `bytes` (byte code), the `chainId`, and the predicate `address`. This address, generated from the byte code, corresponds to the Pay-to-Script-Hash (P2SH) address used in Bitcoin. diff --git a/apps/docs/src/guide/predicates/send-and-spend-funds-from-predicates.md b/apps/docs/src/guide/predicates/send-and-spend-funds-from-predicates.md index 5a14c559e73..ddb90cafd13 100644 --- a/apps/docs/src/guide/predicates/send-and-spend-funds-from-predicates.md +++ b/apps/docs/src/guide/predicates/send-and-spend-funds-from-predicates.md @@ -26,7 +26,7 @@ With the predicate instantiated, we can transfer funds to its address. This requ Now that our predicate holds funds, we can use it to validate a transaction. -First, we need to set its data. Note that the `main` function in our predicate example requires a parameter called `input_address` of type `b256`. We achieve this using the `Predicate` class method `setData`. +First, we need to set its data. Note that the `main` function in our predicate example requires a parameter called `input_address` of type `b256`. We achieve this using the [`Predicate`](../../api/Predicate/Predicate.md) class method `setData`. <<< @/../../docs-snippets/src/guide/predicates/send-and-spend-funds-from-predicates.test.ts#send-and-spend-funds-from-predicates-4{ts:line-numbers} @@ -40,7 +40,7 @@ Once the predicate resolves with a return value `true` based on its predefined c --- -In a similar approach, you can use the `createTransfer` method, which returns a `ScriptTransactionRequest`. Then, we can submit this transaction request by calling the `sendTransaction` method. +In a similar approach, you can use the `createTransfer` method, which returns a [`ScriptTransactionRequest`](../../api/Providers/ScriptTransactionRequest.md). Then, we can submit this transaction request by calling the `sendTransaction` method. This can be useful if you need the transaction ID before actually submitting it to the node. diff --git a/apps/docs/src/guide/providers/index.md b/apps/docs/src/guide/providers/index.md index 4c3c07e5735..8ff0697bf6b 100644 --- a/apps/docs/src/guide/providers/index.md +++ b/apps/docs/src/guide/providers/index.md @@ -1,5 +1,5 @@ # Providers -An instance of the `Provider` class lets you connect to a Fuel node. It provides read-only access to the blockchain state. You can use this provider as-is or through a `Wallet` instance. +An instance of the [`Provider`](../../api/Providers/Provider.md) class lets you connect to a Fuel node. It provides read-only access to the blockchain state. You can use this provider as-is or through a [`Wallet`](../../api/Wallet/Wallet.md) instance. <<< @/../../../packages/providers/test/provider.test.ts#provider-definition{ts:line-numbers} diff --git a/apps/docs/src/guide/types/address.md b/apps/docs/src/guide/types/address.md index 4e69d6f6526..c6b7eb1b63d 100644 --- a/apps/docs/src/guide/types/address.md +++ b/apps/docs/src/guide/types/address.md @@ -1,50 +1,50 @@ # Address -In Sway, the `Address` type serves as a type-safe wrapper around the primitive `b256` type. The SDK takes a different approach and has its own abstraction for the `Address` type. +In Sway, the [`Address`](../../api/Address/Address.md) type serves as a type-safe wrapper around the primitive `b256` type. The SDK takes a different approach and has its own abstraction for the [Address](../../api/Address/Address.md) type. -## `AbstractAddress` Class +## [`AbstractAddress`](../../api/Interfaces/AbstractAddress.md) Class -The SDK defines the `AbstractAddress` class, which provides a set of utility functions for easy manipulation and conversion between address formats. +The SDK defines the [AbstractAddress](../../api/Interfaces/AbstractAddress.md) class, which provides a set of utility functions for easy manipulation and conversion between address formats. <<< @/../../../packages/interfaces/src/index.ts#address-1{ts:line-numbers} ## Address Class -Besides conforming to the interface of the `AbstractAddress`, the `Address` also defines one property; `bech32Address`, which is of the [`Bech32`](./bech32.md) type. +Besides conforming to the interface of the [`AbstractAddress`](../../api/Interfaces/AbstractAddress.md), the [`Address`](../../api/Address/Address.md) class also defines one property; `bech32Address`, which is of the [`Bech32`](./bech32.md) type. <<< @/../../../packages/address/src/address.ts#address-2{ts:line-numbers} ## Creating an Address -Thanks to the utility functions provided by the `AbstractAddress` class, there are several ways to create an `Address` instance: +Thanks to the utility functions provided by the [`AbstractAddress`](../../api/Interfaces/AbstractAddress.md) class, there are several ways to create an [`Address`](../../api/Address/Address.md) instance: ### From a `Bech32` Address -To create an `Address` from a `Bech32` address, use the following code snippet: +To create an [`Address`](../../api/Address/Address.md) from a `Bech32` address, use the following code snippet: <<< @/../../docs-snippets/src/guide/types/address.test.ts#address-2{ts:line-numbers} ### From a Public Key -To create an `Address` from a public key, use the following code snippet: +To create an [`Address`](../../api/Address/Address.md) from a public key, use the following code snippet: <<< @/../../docs-snippets/src/guide/types/address.test.ts#address-3{ts:line-numbers} ### From a 256-bit Address -To create an `Address` from a 256-bit address, use the following code snippet: +To create an [`Address`](../../api/Address/Address.md) from a 256-bit address, use the following code snippet: <<< @/../../docs-snippets/src/guide/types/address.test.ts#address-4{ts:line-numbers} ## Utility Functions -The `Address` class also provides some practical utility functions: +The [`Address`](../../api/Address/Address.md) class also provides some practical utility functions: -1. `fromString`: Create a new `Address` from an ambiguous source that may be a `Bech32` or `B256` address: +1. `fromString`: Create a new [`Address`](../../api/Address/Address.md) from an ambiguous source that may be a `Bech32` or `B256` address: <<< @/../../docs-snippets/src/guide/types/address.test.ts#address-5{ts:line-numbers} -2. `fromDynamicInput`: Create a new `Address` when the address source is unknown: +2. `fromDynamicInput`: Create a new [`Address`](../../api/Address/Address.md) when the address source is unknown: <<< @/../../docs-snippets/src/guide/types/address.test.ts#address-6{ts:line-numbers} diff --git a/apps/docs/src/guide/types/bech32.md b/apps/docs/src/guide/types/bech32.md index 01fdb557af2..cd9fb847c1b 100644 --- a/apps/docs/src/guide/types/bech32.md +++ b/apps/docs/src/guide/types/bech32.md @@ -1,8 +1,8 @@ # `Bech32` -The SDK uses the `Bech32` type as the core property of the `Address` class, specifically through the `bech32Address` property. +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` class is constructed around the `Bech32` type. +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. You can read more about the `Bech32` type [here](https://thebitcoinmanual.com/articles/btc-bech32-address/). diff --git a/apps/docs/src/guide/types/bits256.md b/apps/docs/src/guide/types/bits256.md index 6f739f937c0..41c7a3dfc8c 100644 --- a/apps/docs/src/guide/types/bits256.md +++ b/apps/docs/src/guide/types/bits256.md @@ -16,6 +16,6 @@ To convert between a `b256` hexlified string and a `Uint8Array`, you can use the ## Support from `Address` Class -A `b256` value is also supported as part of the `Address` class, providing seamless integration with other components of your application. To create an `Address` instance from a b256 value, use the `Address.fromB256()` method: +A `b256` value is also supported as part of the [`Address`](../../api/Address/Address.md) class, providing seamless integration with other components of your application. To create an [`Address`](../../api/Address/Address.md) instance from a b256 value, use the `Address.fromB256()` method: <<< @/../../docs-snippets/src/guide/types/bits256.test.ts#bits256-3{ts:line-numbers} diff --git a/apps/docs/src/guide/wallets/access.md b/apps/docs/src/guide/wallets/access.md index 290169c11ec..df6facfcbcf 100644 --- a/apps/docs/src/guide/wallets/access.md +++ b/apps/docs/src/guide/wallets/access.md @@ -1,26 +1,26 @@ # Wallet Access -The kinds of operations we can perform with a `Wallet` instance depend on +The kinds of operations we can perform with a [`Wallet`](../../api/Wallet/Wallet.md) instance depend on whether or not we have access to the wallet's private key. -In order to differentiate between `Wallet` instances that know their private key -and those that do not, we use the `WalletUnlocked` and `WalletLocked` types +In order to differentiate between [`Wallet`](../../api/Wallet/Wallet.md) instances that know their private key +and those that do not, we use the [`WalletUnlocked`](../../api/Wallet/WalletUnlocked.md) and [`WalletLocked`](../../api/Wallet/WalletLocked.md) types respectively. ## Wallet States -The `WalletUnlocked` type represents a wallet whose private key is known and -stored internally in memory. A wallet must be of type `WalletUnlocked` in order +The [`WalletUnlocked`](../../api/Wallet/WalletUnlocked.md) type represents a wallet whose private key is known and +stored internally in memory. A wallet must be of type [`WalletUnlocked`](../../api/Wallet/WalletUnlocked.md) in order to perform operations that involve [signing messages or transactions](./signing.md). -The `WalletLocked` type represents a wallet whose private key is _not_ known or stored -in memory. Instead, `WalletLocked` only knows its public address. A `WalletLocked` cannot be +The [`WalletLocked`](../../api/Wallet/WalletLocked.md) type represents a wallet whose private key is _not_ known or stored +in memory. Instead, [`WalletLocked`](../../api/Wallet/WalletLocked.md) only knows its public address. A [`WalletLocked`](../../api/Wallet/WalletLocked.md) cannot be used to sign transactions, however it may still perform a whole suite of useful operations including listing transactions, assets, querying balances, and so on. -Note that the `WalletUnlocked` type implements most methods available on the `WalletLocked` -type. In other words, `WalletUnlocked` can be thought of as a thin wrapper around `WalletLocked` that +Note that the [`WalletUnlocked`](../../api/Wallet/WalletUnlocked.md) type implements most methods available on the [`WalletLocked`](../../api/Wallet/WalletLocked.md) +type. In other words, [`WalletUnlocked`](../../api/Wallet/WalletUnlocked.md) can be thought of as a thin wrapper around [`WalletLocked`](../../api/Wallet/WalletLocked.md) that provides greater access via its private key. ## Basic Example @@ -29,16 +29,16 @@ provides greater access via its private key. ## Transitioning States -A `WalletLocked` instance can be unlocked by providing the private key: +A [`WalletLocked`](../../api/Wallet/WalletLocked.md) instance can be unlocked by providing the private key: <<< @/../../../packages/fuel-gauge/src/doc-examples.test.ts#wallet-locked-to-unlocked{ts:line-numbers} -A `WalletUnlocked` instance can be locked using the `lock` method: +A [`WalletUnlocked`](../../api/Wallet/WalletUnlocked.md) instance can be locked using the `lock` method: <<< @/../../../packages/fuel-gauge/src/doc-examples.test.ts#wallet-unlocked-to-locked{ts:line-numbers} Most wallet constructors that create or generate a new wallet are provided on -the `WalletUnlocked` type. Consider locking the wallet with the `lock` method after the new private +the [`WalletUnlocked`](../../api/Wallet/WalletUnlocked.md) type. Consider locking the wallet with the `lock` method after the new private key has been handled in order to reduce the scope in which the wallet's private key is stored in memory. @@ -46,6 +46,6 @@ key is stored in memory. When designing APIs that accept a wallet as an input, we should think carefully about the kind of access that we require. API developers should aim to minimise -their usage of `WalletUnlocked` in order to ensure private keys are stored in +their usage of [`WalletUnlocked`](../../api/Wallet/WalletUnlocked.md) in order to ensure private keys are stored in memory no longer than necessary to reduce the surface area for attacks and vulnerabilities in downstream libraries and applications. diff --git a/apps/docs/src/guide/wallets/encrypting-and-decrypting-json-wallets.md b/apps/docs/src/guide/wallets/encrypting-and-decrypting-json-wallets.md index 4d5f54f1943..b9ca6391707 100644 --- a/apps/docs/src/guide/wallets/encrypting-and-decrypting-json-wallets.md +++ b/apps/docs/src/guide/wallets/encrypting-and-decrypting-json-wallets.md @@ -4,23 +4,23 @@ JSON wallets are a standardized way of storing wallets securely. They follow a s ## Encrypting a Wallet -We will be calling `encrypt` from the `WalletUnlocked` instance which will take a password as the argument. It will encrypt the private key using a cipher and returns the JSON keystore wallet. You can then securely store this JSON wallet. +We will be calling `encrypt` from the [`WalletUnlocked`](../../api/Wallet/WalletUnlocked.md) instance which will take a password as the argument. It will encrypt the private key using a cipher and returns the JSON keystore wallet. You can then securely store this JSON wallet. Here is an example of how you can accomplish this: <<< @/../../docs-snippets/src/guide/wallets/encrypting-and-decrypting-json-wallets.test.ts#encrypting-and-decrypting-json-wallets-1{ts:line-numbers} -Please note that `encrypt` must be called within an instance of `WalletUnlocked`. This instance can only be achieved through passing a private key or mnemonic phrase to a locked wallet. +Please note that `encrypt` must be called within an instance of [`WalletUnlocked`](../../api/Wallet/WalletUnlocked.md). This instance can only be achieved through passing a private key or mnemonic phrase to a locked wallet. ## Decrypting a Wallet -To decrypt the JSON wallet and retrieve your private key, you can call `fromEncryptedJson` on a `Wallet` instance. It takes the encrypted JSON wallet and the password as its arguments, and returns the decrypted wallet. +To decrypt the JSON wallet and retrieve your private key, you can call `fromEncryptedJson` on a [Wallet](../../api/Wallet/Wallet.md) instance. It takes the encrypted JSON wallet and the password as its arguments, and returns the decrypted wallet. Here is an example: <<< @/../../docs-snippets/src/guide/wallets/encrypting-and-decrypting-json-wallets.test.ts#encrypting-and-decrypting-json-wallets-2{ts:line-numbers} -In this example, `decryptedWallet` is an instance of `WalletUnlocked` class, now available for use. +In this example, `decryptedWallet` is an instance of [`WalletUnlocked`](../../api/Wallet/WalletUnlocked.md) class, now available for use. ## Important