Details
Lit.Actions.signAsAction enables a Lit Action to generate signatures that authenticate data without needing external keys.
Any system can later verify these signatures using Lit.Actions.verifyActionSignature, or retrieve the associated public key with Lit.Actions.getActionPublicKey and perform verification independently.
Derive a Lit Action Public Key Locally
Question
I want to callLit.Actions.signAsAction. I know the action identity is derived from the Action’s IPFS CID, but I cannot find a way to obtain the public key outside the Action runtime. Lit.Actions.getActionPublicKey works within the Action. However, executeJs only exposes signatures.<name>.publicKey after a signing operation. Is there a way to deterministically derive the Action’s public key locally without running the Action?
Answer
Yes. Inside the Lit Action you can deterministically derive the Action identity (and therefore its public key) from the same inputs the nodes use: the Action’s IPFS CID and the signing scheme. The snippet below shows the complete flow:- Produce the 32-byte message hash the Lit nodes expect.
- Call
Lit.Actions.signAsActionto sign that message with the Action identity. - Optionally derive the action public key via
Lit.Actions.getActionPublicKey, passing the Action IPFS CID and signing scheme. - Optionally verify the signature with
Lit.Actions.verifyActionSignature. - NOTE:
Lit.Actions.getActionPublicKeyandLit.Actions.verifyActionSignaturecan be called from any Lit Action to verify signatures, not just from the same Action that calledLit.Actions.signAsAction.
Lit.Actions.getActionPublicKey for a deterministic identity without needing to execute the Action externally first.
Derive the Same Public Key from Client Code
If you prefer to resolve the Lit Action public key outside the Action runtime - e.g., inside tests or other tooling—the SDK now exposes a helper that calls the on-chain PubkeyRouter contract.getDerivedKeyId routes through PubkeyRouter.getDerivedPubkey, passing the staking contract address and the default Naga key set (naga-keyset1) (will be dynamic in the future). This mirrors the same key derivation the nodes perform, letting you confirm identities or signatures without re-running the Lit Action.