lighter.pubkey
Documentation for eth_defi.lighter.pubkey Python module.
Lighter API-key registration (changePubKey) for a Safe-controlled account.
Creating a Lighter API key is two steps:
Generate the API keypair off-chain with
eth_defi.lighter.api_key.generate_lighter_api_key(); no L1 private key is needed. Use indices 4-254 for automated keys; Lighter’s dedicated API-key documentation reserves indices 0-3 for the web/mobile UI.Register its public key with the Lighter account on L1 via
ZkLighter.changePubKey(accountIndex, apiKeyIndex, pubKey). For a Gnosis Safe / Lagoon vault this is done as a Safe transaction — Lighter explicitly recommends the onchainChangePubKey“if you’re running a multi-sig” (the SDK’s EOAsign_change_api_keypath needs a raw private key, which a Safe does not have).
This module covers step 2 for a Safe: validating the pubkey, encoding the
changePubKey call, and building / executing the Safe transaction. To collect
multisig signatures, print the transaction with
scripts/lighter/lagoon-lighter-change-pubkey.py and use the Safe{Wallet}
Transaction Builder.
Note
changePubKey is intentionally not part of the asset-manager guard
whitelist (eth_defi.lighter LighterLib). It is a privileged
setup action performed by the Safe owners (governance), so it goes
directly through the Safe, not the TradingStrategyModule’s
restricted performCall path. The asset-manager hot wallet cannot rotate
trading keys.
Authoritative docs:
Lighter API keys: https://apidocs.lighter.xyz/docs/api-keys
Module Attributes
Required Lighter API-key public-key length in bytes. |
|
Goldilocks field modulus ( |
|
Maximum API-key index. |
|
Minimum user API-key index. |
Functions
|
Build an (unsigned) Safe transaction calling |
|
Encode a |
|
Build, sign and execute the |
|
Validate a Lighter API-key public key client-side. |
- PUB_KEY_BYTES_SIZE = 40
Required Lighter API-key public-key length in bytes.
5 Goldilocks field limbs of 8 bytes each. From
ZkLighter.PUB_KEY_BYTES_SIZE.
- GOLDILOCKS_MODULUS = 18446744069414584321
Goldilocks field modulus (
2**64 - 2**32 + 1).Each 8-byte little-endian limb of the pubkey must be strictly below this. From
ZkLighter.GOLDILOCKS_MODULUS(0xffffffff00000001).
- MAX_API_KEY_INDEX = 254
Maximum API-key index. From
ZkLighter.MAX_API_KEY_INDEX.
- MIN_API_KEY_INDEX = 4
Minimum user API-key index.
Indices 0-3 are reserved for the Lighter web/mobile interfaces; user keys are 4-254. We refuse to build a transaction targeting a reserved slot.
- validate_lighter_pubkey(pubkey)
Validate a Lighter API-key public key client-side.
Mirrors the onchain checks in
ZkLighter.changePubKeyso callers fail fast before submitting a transaction: the pubkey must be exactlyPUB_KEY_BYTES_SIZEbytes, each 8-byte little-endian limb must be strictly belowGOLDILOCKS_MODULUS, and it must not be all-zero.- Parameters
pubkey (bytes) – The API-key public key produced by the native key generator.
- Raises
ValueError – If the pubkey is malformed.
- Return type
None
- encode_change_pubkey(web3, account_index, api_key_index, pubkey, zk_lighter='0x3B4D794a66304F130a4Db8F2551B0070dfCf5ca7')
Encode a
ZkLighter.changePubKey(accountIndex, apiKeyIndex, pubKey)call.Validates
api_key_indexandpubkeybefore encoding.- Parameters
web3 (web3.main.Web3) – Web3 connection (for the ABI / encoding).
account_index (int) – The Lighter account index whose key is being set.
api_key_index (int) – The API-key slot (4-254 for automated user keys).
pubkey (bytes) – The API-key public key (see
validate_lighter_pubkey()).zk_lighter (Union[eth_typing.evm.HexAddress, str]) – The
ZkLighterL1 contract address.
- Returns
(zk_lighter_address, calldata).- Return type
tuple[eth_typing.evm.HexAddress, hexbytes.main.HexBytes]
- build_change_pubkey_safe_tx(web3, safe, account_index, api_key_index, pubkey, zk_lighter='0x3B4D794a66304F130a4Db8F2551B0070dfCf5ca7')
Build an (unsigned) Safe transaction calling
ZkLighter.changePubKey.The Safe is the Lighter account’s L1 owner. Sign and execute the result with the Safe owners, or submit the encoded transaction through the Safe Transaction Service.
- execute_change_pubkey(web3, safe, owner_private_key, account_index, api_key_index, pubkey, zk_lighter='0x3B4D794a66304F130a4Db8F2551B0070dfCf5ca7', hot_wallet=None)
Build, sign and execute the
changePubKeySafe transaction immediately.For a single-owner Safe (or local simulation). For a real multisig, build the transaction with
build_change_pubkey_safe_tx()(or print it withscripts/lighter/lagoon-lighter-change-pubkey.py) and collect the owner signatures in the Safe UI.- Parameters
owner_private_key (str) – The executing owner’s hexadecimal private key, with or without a
0xprefix.hot_wallet (Optional[eth_defi.hotwallet.HotWallet]) – Optional owner wallet for nonce allocation. Use this in scripts that already submit transactions through
HotWalletto avoid stale RPC nonce reads.web3 (web3.main.Web3) –
safe (safe_eth.safe.safe.Safe) –
account_index (int) –
api_key_index (int) –
pubkey (bytes) –
zk_lighter (Union[eth_typing.evm.HexAddress, str]) –
- Returns
The executed transaction hash.
- Return type
hexbytes.main.HexBytes