-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!: signing and the
Signer
trait (#1241)
NOTE: If the user builds without signatures, it is their responsibility to sign the transaction in the right order. For example, if we have `CoinSignedA` then `CoinSignedB`, we need to sign with `WalletA` and then with `WalletB`. This comes from the fact that we need to set the witness indexes while building the transaction. BREAKING CHANGE: - Removed `sign_message` and `sign_transaction` from the `Signer` trait - Added `sign` and `address` methods to the `Signer` trait - `Signer` trait moved do `fuels::core::traits:::Signer` - `Message`, `PublicKey`, `SecretKey` and `Signature` moved to `fuels::crypto::` - Replaced `Transaction`'s `check_without_signatures` with `check` - Renamed `Account`s `add_witnessses` to `add_witnesses` - Removed `Clone` for `TransactionBuilder`s
- Loading branch information
Showing
29 changed files
with
545 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,27 @@ | ||
# Signing | ||
|
||
Once you've instantiated your wallet in an unlocked state using one of the previously discussed methods, you can sign a message with `wallet.sign_message`. Below is a full example of how to sign and recover a message. | ||
Once you've instantiated your wallet in an unlocked state using one of the previously discussed methods, you can sign a message with `wallet.sign`. Below is a full example of how to sign and recover a message. | ||
|
||
```rust,ignore | ||
{{#include ../../../packages/fuels-accounts/src/account.rs:sign_message}} | ||
``` | ||
|
||
## Signing a transaction | ||
## Adding `Signers` to a transaction builder | ||
|
||
Every signed resource in the inputs needs to have a witness index that points to a valid witness. Changing the witness index inside an input will change the transaction ID. This means that we need to set all witness indexes before finally signing the transaction. Previously, the user had to make sure that the witness indexes and the order of the witnesses are correct. To automate this process, the SDK will keep track of the signatures in the transaction builder and resolve the final transaction automatically. This is done by storing the secret keys of all signers until the final transaction is built. | ||
Every signed resource in the inputs needs to have a witness index that points to a valid witness. Changing the witness index inside an input will change the transaction ID. This means that we need to set all witness indexes before finally signing the transaction. Previously, the user had to make sure that the witness indexes and the order of the witnesses are correct. To automate this process, the SDK will keep track of the signers in the transaction builder and resolve the final transaction automatically. This is done by storing signers until the final transaction is built. | ||
|
||
To sign a _transaction builder_ use the `wallet.sign_transaction`. Below is a full example of how to create a transaction and sign it. | ||
Below is a full example of how to create a transaction builder and add signers to it. | ||
|
||
> Note: When you sign a transaction builder the secret key is stored inside it and will not be resolved until you call `build()`! | ||
> Note: When you add a `Signer` to a transaction builder, the signer is stored inside it and the transaction will not be resolved until you call `build()`! | ||
```rust,ignore | ||
{{#include ../../../packages/fuels-accounts/src/account.rs:sign_tx}} | ||
{{#include ../../../packages/fuels-accounts/src/account.rs:sign_tb}} | ||
``` | ||
|
||
## Signing a built transaction | ||
|
||
If you have a built transaction and want to add a signature, you can use the `sign_with` method. | ||
|
||
```rust,ignore | ||
{{#include ../../../packages/fuels/tests/contracts.rs:tx_sign_with}} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.