Module crypto
Source - EvmWallet
- An EVM-compatible wallet with keccak256 derived address, zero-padded to B256.
- Wallet
- A Fuel-native wallet with SHA-256 derived B256 address.
- SECP256K1_ORDER 🔒
- Full secp256k1 group order.
- SECP256K1_ORDER_HALF 🔒
- Half of the secp256k1 group order, used for low-s normalization.
- SignableWallet
- Trait for wallets that can sign messages for O2 Exchange operations.
- address_from_pubkey
- Derive a Fuel B256 address from a public key (65 bytes, 0x04 prefix).
- evm_address_from_pubkey
- Derive an EVM address from a public key (65 bytes, 0x04 prefix).
- evm_personal_sign
- Sign using Ethereum’s personal_sign format (for EVM owner session creation).
prefix = “\x19Ethereum Signed Message:\n” + str(len(message))
digest = keccak256(prefix_bytes + message)
- fuel_compact_sign
- Sign a 32-byte digest and return a 64-byte Fuel compact signature.
- generate_evm_keypair
- Generate an EVM-compatible keypair.
EVM address = last 20 bytes of keccak256(uncompressed_pubkey[1..65])
B256 address = 12 zero bytes + 20 EVM address bytes
- generate_keypair
- Generate a Fuel-native secp256k1 keypair.
Address = SHA-256(uncompressed_pubkey[1..65])
- gt_be 🔒
- Compare two 32-byte big-endian numbers: returns true if a > b.
- load_evm_wallet
- Load an EVM wallet from a private key.
- load_wallet
- Load a Fuel-native wallet from a private key.
- negate_s 🔒
- Negate a 32-byte big-endian number modulo the secp256k1 order.
result = ORDER - value
- parse_hex_32
- Parse a “0x”-prefixed hex string into a 32-byte array.
- personal_sign
- Sign using Fuel’s personalSign format (for session creation).
prefix = b“\x19Fuel Signed Message:\n“ + str(len(message)) + message
digest = sha256(prefix)
- raw_sign
- Sign using raw SHA-256 hash, no prefix (for session actions).
digest = sha256(message)
- to_hex_string
- Format a 32-byte array as a “0x”-prefixed hex string.