Skip to content

Commit 59c2bef

Browse files
committed
feat(docs): add delegation auth signature functions and examples
1 parent 0a80342 commit 59c2bef

File tree

5 files changed

+179
-1
lines changed

5 files changed

+179
-1
lines changed

docs/docs.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@
109109
{
110110
"group": "@lit-protocol/auth",
111111
"pages": [
112-
"sdk/sdk-reference/auth/functions/createAuthManager"
112+
"sdk/sdk-reference/auth/functions/createAuthManager",
113+
"sdk/sdk-reference/auth/functions/generatePkpDelegationAuthSig",
114+
"sdk/sdk-reference/auth/functions/generateEoaDelegationAuthSig",
115+
"sdk/sdk-reference/auth/functions/validateDelegationAuthSig",
116+
"sdk/sdk-reference/auth/functions/getPkpAuthContextFromPreGeneratedAdapter"
113117
]
114118
},
115119
{
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: generateEoaDelegationAuthSig
3+
---
4+
5+
# Function
6+
7+
> **generateEoaDelegationAuthSig**(`params`)
8+
9+
Creates a delegation signature for an EOA-based session. The EOA wallet signs the session delegation message directly, enabling pre-generated session materials for server-side reuse.
10+
11+
## Parameters
12+
13+
<ParamField path="params.account" type="Account | WalletClient | Signer" required>
14+
EOA used to sign the delegation message.
15+
</ParamField>
16+
17+
<ParamField path="params.sessionKeyPair" type="SessionKeyPair" required>
18+
Session keypair generated with `generateSessionKeyPair`.
19+
</ParamField>
20+
21+
<ParamField path="params.authConfig" type="AuthConfigV2" required>
22+
Resources and expiration scoped to the delegated session.
23+
</ParamField>
24+
25+
## Returns
26+
27+
<ResponseField name="delegationAuthSig" type="AuthSig">
28+
Delegation signature that can be paired with the session keypair.
29+
</ResponseField>
30+
31+
## Example
32+
33+
```ts
34+
import {
35+
generateEoaDelegationAuthSig,
36+
generateSessionKeyPair,
37+
} from '@lit-protocol/auth';
38+
39+
const sessionKeyPair = generateSessionKeyPair();
40+
41+
const delegationAuthSig = await generateEoaDelegationAuthSig({
42+
account: myViemAccount,
43+
sessionKeyPair,
44+
authConfig: {
45+
resources: [ ['lit-action-execution', '*'] ],
46+
expiration: new Date(Date.now() + 10 * 60 * 1000).toISOString(),
47+
},
48+
});
49+
```
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
title: generatePkpDelegationAuthSig
3+
---
4+
5+
# Function
6+
7+
> **generatePkpDelegationAuthSig**(`params`)
8+
9+
Creates a delegation signature that authorises a session key to act on behalf of a PKP. Use this in server or pre-generation flows where you want to prepare session materials ahead of time.
10+
11+
## Parameters
12+
13+
<ParamField path="params.pkpPublicKey" type="string" required>
14+
Hex-encoded PKP public key.
15+
</ParamField>
16+
17+
<ParamField path="params.authData" type="AuthData" required>
18+
Authentication data for the PKP owner (e.g., from `ViemAccountAuthenticator.authenticate`).
19+
</ParamField>
20+
21+
<ParamField path="params.sessionKeyPair" type="SessionKeyPair" required>
22+
Session keypair generated with `generateSessionKeyPair`.
23+
</ParamField>
24+
25+
<ParamField path="params.authConfig" type="AuthConfigV2" required>
26+
Configures resources and expiration scoped to the delegation.
27+
</ParamField>
28+
29+
<ParamField path="params.litClient" type="LitClient" required>
30+
Lit client used to reach the network and request the delegation signature.
31+
</ParamField>
32+
33+
## Returns
34+
35+
<ResponseField name="delegationAuthSig" type="AuthSig">
36+
Signed delegation that can be shipped alongside the session keypair.
37+
</ResponseField>
38+
39+
## Example
40+
41+
```ts
42+
import { generatePkpDelegationAuthSig, generateSessionKeyPair } from '@lit-protocol/auth';
43+
44+
const sessionKeyPair = generateSessionKeyPair();
45+
46+
const delegationAuthSig = await generatePkpDelegationAuthSig({
47+
pkpPublicKey,
48+
authData,
49+
sessionKeyPair,
50+
authConfig: {
51+
resources: [ ['pkp-signing', '*'], ['lit-action-execution', '*'] ],
52+
expiration: new Date(Date.now() + 15 * 60 * 1000).toISOString(),
53+
},
54+
litClient,
55+
});
56+
```
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: getPkpAuthContextFromPreGeneratedAdapter
3+
---
4+
5+
# Function
6+
7+
> **getPkpAuthContextFromPreGeneratedAdapter**(`params`)
8+
9+
Creates a PKP auth context from pre-generated session materials. This streamlined adapter is ideal for server flows where you ship `{ sessionKeyPair, delegationAuthSig }` and want to hydrate an auth context without re-specifying the auth config.
10+
11+
## Parameters
12+
13+
<ParamField path="params.pkpPublicKey" type="string" required />
14+
<ParamField path="params.sessionKeyPair" type="SessionKeyPair" required />
15+
<ParamField path="params.delegationAuthSig" type="AuthSig" required />
16+
<ParamField path="params.authData" type="AuthData">
17+
Optional if embedded in the delegation. Provide when you need to override or enrich the auth context.
18+
</ParamField>
19+
20+
## Returns
21+
22+
<ResponseField name="authContext" type="AuthContext">
23+
PKP auth context ready to use with `litClient` helpers or to derive session signatures.
24+
</ResponseField>
25+
26+
## Example
27+
28+
```ts
29+
import { getPkpAuthContextFromPreGeneratedAdapter } from '@lit-protocol/auth';
30+
31+
const authContext = await getPkpAuthContextFromPreGeneratedAdapter({
32+
pkpPublicKey,
33+
sessionKeyPair,
34+
delegationAuthSig,
35+
});
36+
```
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: validateDelegationAuthSig
3+
---
4+
5+
# Function
6+
7+
> **validateDelegationAuthSig**(`params`)
8+
9+
Ensures a delegation signature is valid for the supplied session key. Run this on the server before trusting materials received over the wire.
10+
11+
## Parameters
12+
13+
<ParamField path="params.delegationAuthSig" type="AuthSig" required />
14+
<ParamField path="params.sessionKeyUri" type="string" required>
15+
The public component (`sessionKeyPair.publicKey`).
16+
</ParamField>
17+
18+
## Returns
19+
20+
<ResponseField name="void" type="void">
21+
Throws if validation fails.
22+
</ResponseField>
23+
24+
## Example
25+
26+
```ts
27+
import { validateDelegationAuthSig } from '@lit-protocol/auth';
28+
29+
validateDelegationAuthSig({
30+
delegationAuthSig,
31+
sessionKeyUri: sessionKeyPair.publicKey,
32+
});
33+
```

0 commit comments

Comments
 (0)