You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/docs/src/guide/wallets/signing.md
+28-4Lines changed: 28 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,15 +2,39 @@
2
2
3
3
## Signing Messages
4
4
5
-
Signing messages with a wallet is a fundamental security practice in a blockchain environment. It verifies ownership and ensures the integrity of data. Here's how to use the `wallet.signMessage` method to sign messages:
5
+
Signing messages with a wallet is a fundamental security practice in a blockchain environment. It can be used to verify ownership and ensure the integrity of data.
6
+
7
+
Here's how to use the `wallet.signMessage` method to sign messages (as string):
The `wallet.signMessage` method internally hashes the message using the SHA-256 algorithm, then signs the hashed message, returning the signature as a hex string.
11
+
The `signMessage` method internally:
12
+
13
+
- Hashes the message (via `hashMessage`)
14
+
- Signs the hashed message using the wallet's private key
15
+
- Returns the signature as a hex string
16
+
17
+
The `hashMessage` helper will:
18
+
19
+
- Performs a SHA-256 hash on the UTF-8 encoded message.
20
+
21
+
The `recoverAddress` method from the `Signer` class will take the hashed message and the signature to recover the signer's address. This confirms that the signature was created by the holder of the private key associated with that address, ensuring the authenticity and integrity of the signed message.
22
+
23
+
## Signing Personal Message
24
+
25
+
We can also sign arbitrary data, not just strings. This is possible by passing an object containing the `personalSign` property to the `hashMessage` and `signMessage` methods:
The primary difference between this [personal message signing](#signing-personal-message) and [message signing](#signing-messages) is the underlying hashing format.
30
+
31
+
To format the message, we use a similar approach to a [EIP-191](https://eips.ethereum.org/EIPS/eip-191):
10
32
11
-
The `hashMessage` helper gives us the hash of the original message. This is crucial to ensure that the hash used during signing matches the one used during the address recovery process.
33
+
```console
34
+
\x19Fuel Signed Message:\n<message length><message>
35
+
```
12
36
13
-
The `recoverAddress` method from the `Signer` class takes the hashed message and the signature to recover the signer's address. This confirms that the signature was created by the holder of the private key associated with that address, ensuring the authenticity and integrity of the signed message.
37
+
> **Note**: We still hash using `SHA-256`, unlike Ethereum's [EIP-191](https://eips.ethereum.org/EIPS/eip-191) which uses `Keccak-256`.
0 commit comments