Skip to content

Commit 720ca41

Browse files
committed
feat(docs): add getDerivedKeyId utility and usage examples for deriving Lit Action public keys
1 parent c7d57d3 commit 720ca41

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

docs/guides/lit-action-sign-as-action.mdx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,21 @@ const { keccak256, arrayify } = ethers.utils;
6969
```
7070

7171
This approach keeps the derivation entirely within the Lit Action context. Because the public key depends only on the Action CID and signing scheme, you can rely on `Lit.Actions.getActionPublicKey` for a deterministic identity without needing to execute the Action externally first.
72+
73+
## Derive the Same Public Key from Client Code
74+
75+
If you prefer to resolve the Lit Action public key outside of the Action runtime—e.g., inside tests or other tooling—the SDK now exposes a helper that calls the on-chain PubkeyRouter contract.
76+
77+
```ts
78+
import { createLitClient } from "@lit-protocol/lit-client";
79+
import { nagaDev } from "@lit-protocol/networks";
80+
import { keccak256, stringToBytes } from "viem";
81+
82+
const litClient = await createLitClient({ network: nagaDev });
83+
const derivedKeyId = keccak256(stringToBytes(`lit_action_${actionIpfsCid}`));
84+
const actionPublicKey = await litClient.utils.getDerivedKeyId(derivedKeyId);
85+
86+
console.log("Derived Lit Action pubkey:", actionPublicKey);
87+
```
88+
89+
Under the hood, `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.

docs/sdk/sdk-reference/lit-client/functions/createLitClient.mdx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,33 @@ Create a Viem-compatible account backed by a PKP.
10461046
</Expandable>
10471047
</ResponseField>
10481048

1049+
### utils.getDerivedKeyId
1050+
1051+
Resolve the uncompressed PKP public key for a given derived key identifier.
1052+
1053+
#### Parameters
1054+
1055+
<ResponseField name="derivedKeyId" type="string" required>
1056+
0x-prefixed bytes32 identifier (for example, <code>keccak256(stringToBytes(`lit_action_${ipfsCid}`))</code>).
1057+
</ResponseField>
1058+
1059+
#### Returns
1060+
1061+
<ResponseField name="result" type="Promise<string>">
1062+
0x-prefixed uncompressed public key as returned by the PubkeyRouter contract.
1063+
</ResponseField>
1064+
1065+
#### Example
1066+
1067+
```ts
1068+
import { keccak256, stringToBytes } from "viem";
1069+
1070+
const derivedKeyId = keccak256(stringToBytes(`lit_action_${ipfsCid}`));
1071+
const derivedPubkey = await litClient.utils.getDerivedKeyId(derivedKeyId);
1072+
```
1073+
1074+
> Note: this helper currently calls `PubkeyRouter.getDerivedPubkey` with the default Naga key set (`naga-keyset1`). See the [Derive Lit Action Public Keys guide](../../../../guides/lit-action-sign-as-action) for an end-to-end workflow.
1075+
10491076
### getChainConfig
10501077

10511078
Returns the chain configuration for the current network.
@@ -1074,4 +1101,4 @@ Stop background state updates and release resources.
10741101
none
10751102

10761103
#### Returns
1077-
void
1104+
void

0 commit comments

Comments
 (0)