Skip to content

Commit

Permalink
Fix Vale errors
Browse files Browse the repository at this point in the history
  • Loading branch information
germartinez committed Jan 12, 2024
1 parent 317a712 commit e8e5e6b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pages/smart-account-signatures.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ To be able to use `eth_sign` we need to take the parameters `r`, `s` and `v` fro

`{32-bytes signature verifier}{32-bytes data position}{1-byte signature type}`

**Signature verifier** - Padded address of the contract that implements the EIP 1271 interface to verify the signature
**Signature verifier** - Padded address of the contract that implements the EIP-1271 interface to verify the signature

**Data position** - Position of the start of the signature data (offset relative to the beginning of the signature data)

Expand Down
40 changes: 20 additions & 20 deletions pages/smart-account-signatures/eip-1271.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ This doc explains signing and verifying messages off-chain. All examples use [Wa

## Signing messages

It is possible to sign [EIP-191](https://eips.ethereum.org/EIPS/eip-191) compliant messages as well as [EIP-712](https://eips.ethereum.org/EIPS/eip-712) typed data messages.
It's possible to sign [EIP-191](https://eips.ethereum.org/EIPS/eip-191) compliant messages as well as [EIP-712](https://eips.ethereum.org/EIPS/eip-712) typed data messages.

### Restrictions

- Only Safe contracts of version `>=1.1.0` are supported.
- Signing off-chain messages with smart contract wallets is not yet supported.
- Signing off-chain messages with smart contract wallets isn't yet supported.

### Enabling off-chain signing

Multiple dApps rely on on-chain signing.
Multiple dapps rely on on-chain signing.
However, off-chain signing is the new default for Safe Apps that use the [safe-apps-sdk](https://www.npmjs.com/package/@safe-global/safe-apps-sdk) version `>=7.11`.
In order to enable off-chain signing in a Safe App, the `safe-apps-sdk` package needs to be updated.

### EIP-191 messages

To sign a message we have to call the `signMessage` function and pass in the message as hex string.
To sign a message we've to call the `signMessage` function and pass in the message as hex string.

The signing request will be blocked until the message is fully signed and then return the `signature` as a string.
As Safe{Wallet} is a multi signature wallet, this process can take some time because multiple signers may need to sign the message.

#### Example: sign message
#### Example: Sign message

```typescript
import { hashMessage, hexlify, toUtf8Bytes } from 'ethers/lib/utils'
Expand All @@ -41,12 +41,12 @@ After signing a message it will be available in the Safe's Message list (Transac

### EIP-712 typed data

To sign typed data we have to call the `signTypedData` function and pass in the typed data object.
To sign typed data we've to call the `signTypedData` function and pass in the typed data object.

The signing request will be blocked until the message is fully signed and then return the `signature` as a string.
As Safe{Wallet} is a multi signature wallet, this process can take some time because multiple signers may need to sign the message.

### Example: sign typed data
### Example: Sign typed data

```typescript
const getExampleData = () => {
Expand Down Expand Up @@ -88,9 +88,9 @@ After signing, the message will be available in the Safe's Message list (Transac

You can fetch the signature asynchronously instead of waiting for the RPC response via the [Safe Transaction Service](https://github.com/safe-global/safe-transaction-service).

To do so we have to generate a hash of the `message` or `typedData` using ethers `hashMessage(message)` or `_TypedDataEncoder.hash(domain, types, message)` and then compute the `Safe message hash` by calling `getMessageHash(messageHash)` on the Safe contract.
To do so we've to generate a hash of the `message` or `typedData` using ethers `hashMessage(message)` or `_TypedDataEncoder.hash(domain, types, message)` and then compute the `Safe message hash` by calling `getMessageHash(messageHash)` on the Safe contract.

### Example: get Safe message hash
### Example: Get Safe message hash

```typescript
const getSafeInterface = () => {
Expand Down Expand Up @@ -121,13 +121,13 @@ const getSafeMessageHash = async (
}
```

Then we can query the state of the message from the network-specific transaction service endpoint for messages: `https://safe-transaction-<NETWORK>.safe.global/api/v1/messages/<SAFE_MSG_HASH>`.
Then we can query the state of the message from the network-specific Transaction Service endpoint for messages: `https://safe-transaction-<NETWORK>.safe.global/api/v1/messages/<SAFE_MSG_HASH>`.

An example message on Goerli can be found here: `https://safe-transaction-goerli.safe.global/api/v1/messages/0x7f4032fd13f27c5fce4694a1a6b79f65c68656da4eee4347a414f5bcec915b39/`.

For other network endpoints, see [Available Services](../../safe-core-api/supported-networks.md).

### Example: Loading message from transaction service
### Example: Loading message from Transaction Service

```typescript
const fetchMessage = async (
Expand Down Expand Up @@ -181,9 +181,9 @@ The signature of the message will be returned in the `preparedSignature` field.

We verify the signature by calling the Safe contract's `isValidSignature(hash, signature)` function on-chain. This function returns the `MAGIC VALUE BYTES 0x20c13b0b` if the `signature` is correct for the `messageHash`.

_Note: A common pitfall is to pass the `safeMessageHash` to the `isValidSignature` call which is not correct. It needs to be the hash of the original message._
_Note: A common pitfall is to pass the `safeMessageHash` to the `isValidSignature` call which isn't correct. It needs to be the hash of the original message._

### Example: verify signature
### Example: Verify signature

```typescript
const MAGIC_VALUE_BYTES = '0x20c13b0b'
Expand All @@ -209,22 +209,22 @@ const isValidSignature = async (
}
```

### Example dApps
### Example dapps

- [Small test dApp](https://github.com/5afe/eip-1271-dapp)
- [Small test dapp](https://github.com/5afe/eip-1271-dapp)

## Troubleshooting

### Off-chain signing is not being used
### Off-chain signing isn't being used

If your signing requests fallback to on-chain signing this could be because of multiple reasons:

- The Safe App is not using `safe-apps-sdk` version `>=7.11.0`.
- The Safe App isn't using `safe-apps-sdk` version `>=7.11.0`.
- The Safe{Wallet} is set to always use on-chain signing. This can be toggled in the Settings of the Safe{Wallet} (Settings -> Safe Apps).
- The connected Safe does not have a _fallback handler_ set. This can happen if Safes were not created through the official interface such as a CLI or third party interface.
- The Safe version is not compatible - off-chain signing is only available for Safes with version `>1.0.0`
- The connected Safe doesn't have a _fallback handler_ set. This can happen if Safes weren't created through the official interface such as a CLI or third party interface.
- The Safe version isn't compatible - off-chain signing is only available for Safes with version `>1.0.0`

### Confusion of messageHash and safeMessageHash
### Confusion of `messageHash` and `safeMessageHash`

`message`, `messageHash` and `safeMessageHash` often get mixed up:

Expand Down

0 comments on commit e8e5e6b

Please sign in to comment.