ERC-191 Ethereum Signed Data
ERC-191 Ethereum Signed Data でエンコードされたメッセージは、以下のように作成・署名できます。ERC-712 構造化データ署名
ERC-712 構造化データ も同様の方法で署名できます。検証
署名はウォレットのisValidSignature メソッドを呼び出して検証できます。
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Sequence ウォレットは、トランザクションやメッセージの署名に ERC-1271 標準コントラクト署名検証をサポートしています。メッセージは ERC-191 Ethereum Signed Data または ERC-712 Structured Data Signatures でエンコードできます。
import { Wallet } from '@0xsequence/wallet'
// Construct your Sequence Wallet (out of scope for this section)
const wallet: Wallet
const message = "Hello, World!"
const prefixedMessage = "\x19Ethereum Signed Message:\n" + len(message) + message
const signature = await wallet.signMessage(prefixedMessage)
import { Wallet } from '@0xsequence/wallet'
import { encodeTypedDataDigest } from '@0xsequence/utils'
// Construct your Sequence Wallet (out of scope for this section)
const wallet: Wallet
// Encode the typed data
const chainId = 1
const typedData = {
types: {
Person: [
{ name: 'name', type: 'string' },
{ name: 'wallet', type: 'address' },
{ name: 'count', type: 'uint8' }
]
},
primaryType: 'Person' as const,
domain: {
name: 'Ether Mail',
version: '1',
chainId: chainId,
verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC'
},
message: {
name: 'Bob',
wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
count: 4
}
}
const hashedData = encodeTypedDataDigest(typedData)
const signature = await wallet.signMessage(hashedData)
isValidSignature メソッドを呼び出して検証できます。
/**
* @notice Verifies whether the provided signature is valid with respect to the provided hash
* @dev MUST return the correct magic value if the signature provided is valid for the provided hash
* > The bytes4 magic value to return when signature is valid is 0x1626ba7e : bytes4(keccak256("isValidSignature(bytes32,bytes)"))
* @param _hash keccak256 hash that was signed
* @param _signatures Signature byte array associated with _data.
* Encoded as abi.encode(Signature[], Configs)
* @return magicValue Magic value 0x1626ba7e if the signature is valid and 0x0 otherwise
*/
function isValidSignature(
bytes32 _hash,
bytes calldata _signatures
) public override virtual view returns (bytes4) {
// Validate signatures
(bool isValid,) = _signatureValidation(_hash, _signatures);
if (isValid) {
return SELECTOR_ERC1271_BYTES32_BYTES;
}
return bytes4(0);
}
このページは役に立ちましたか?