Skip to content

Commit ed6ed68

Browse files
authored
Merge branch 'naga' into feature/jss-132-naga-test-allow-naga-local-configuration
2 parents bd5d24c + 458d189 commit ed6ed68

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed

docs/docs.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://mintlify.com/docs.json",
33
"theme": "mint",
4-
"name": "Lit JS SDK Documentation",
4+
"name": "Lit Protocol Documentation",
55
"colors": {
66
"primary": "#EA580C",
77
"light": "#F97316",
@@ -126,6 +126,12 @@
126126
"sdk/resources/network-status"
127127
]
128128
},
129+
{
130+
"group": "Guides",
131+
"pages": [
132+
"guides/lit-action-sign-as-action"
133+
]
134+
},
129135
{
130136
"group": "FAQ",
131137
"pages": [
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
title: 'Derive Lit Action Public Keys'
3+
description: 'How to deterministically derive and verify a Lit Action identity without executing it externally.'
4+
---
5+
6+
# Derive a Lit Action Public Key Locally
7+
8+
## Question
9+
10+
I want to call `Lit.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 of the Action runtime. `Lit.Actions.getActionPublicKey` works within the Action, while `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?
11+
12+
## Answer
13+
14+
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:
15+
16+
1. Produce the 32-byte message hash the Lit nodes expect.
17+
2. Call `Lit.Actions.signAsAction` to sign that message with the Action identity.
18+
3. Derive the Action public key via `Lit.Actions.getActionPublicKey`, passing the Action CID and signing scheme.
19+
4. Optionally verify the signature with `Lit.Actions.verifyActionSignature`.
20+
21+
```js
22+
const { sigName, toSign } = jsParams; // 'publicKey' not required; derive it from the Action IPFS CID
23+
const { keccak256, arrayify } = ethers.utils;
24+
25+
(async () => {
26+
// 1) Produce a 32-byte hash of the input (Lit Actions expect a 32-byte message for ECDSA schemes)
27+
const msgBytes = new TextEncoder().encode(toSign);
28+
const msgHashHex = keccak256(msgBytes); // 0x-prefixed hex string
29+
const msgHashBytes = arrayify(msgHashHex); // Uint8Array
30+
31+
// 2) Sign as the current Lit Action (deterministic Action identity, not a PKP)
32+
// Supported schemes include 'EcdsaK256Sha256' (secp256k1) among others.
33+
const signingScheme = 'EcdsaK256Sha256';
34+
const signature = await Lit.Actions.signAsAction({
35+
toSign: msgHashBytes,
36+
sigName,
37+
signingScheme,
38+
});
39+
40+
// 3) Derive this Action's public key deterministically from its IPFS CID + scheme
41+
// This does not require a PKP and is always the same for a given (CID, scheme).
42+
const actionIpfsCid = Lit.Auth.actionIpfsIdStack[0];
43+
const actionPublicKey = await Lit.Actions.getActionPublicKey({
44+
signingScheme,
45+
actionIpfsCid,
46+
});
47+
48+
// 4) (Optional) Verify that the signature was produced by this Action identity
49+
const verified = await Lit.Actions.verifyActionSignature({
50+
signingScheme,
51+
actionIpfsCid,
52+
toSign: msgHashBytes,
53+
signOutput: signature,
54+
});
55+
56+
// 5) Return a structured response for clients to consume
57+
Lit.Actions.setResponse({
58+
response: JSON.stringify({
59+
sigName,
60+
signingScheme,
61+
message: toSign,
62+
messageHash: msgHashHex,
63+
signature, // string; format depends on scheme
64+
actionPublicKey, // string; hex or JSON depending on scheme
65+
verified, // boolean
66+
}),
67+
});
68+
})();
69+
```
70+
71+
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.

0 commit comments

Comments
 (0)