Skip to content

Commit fbe2cce

Browse files
committed
feat:
- move pkp config to context to allow for dynamic switching of pkps - add support from capacityCreditTokens and therefore paid Lit networks - add pkp and capacity credit nft minting states - restricted state machine public interface - use verrors in remaining normal errors
1 parent 2c26270 commit fbe2cce

File tree

7 files changed

+477
-318
lines changed

7 files changed

+477
-318
lines changed

packages/automation/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './lib/listeners';
22
export * from './lib/states';
3-
export * from './lib/transitions';
43
export * from './lib/state-machine';
4+
export * from './lib/transitions';
5+
export * from './lib/types';

packages/automation/src/lib/litActions.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ethers } from 'ethers';
22

33
import { LitActionResource } from '@lit-protocol/auth-helpers';
4-
import { LIT_ABILITY } from '@lit-protocol/constants';
4+
import { LIT_ABILITY, LIT_NETWORK } from '@lit-protocol/constants';
55
import { EthWalletProvider } from '@lit-protocol/lit-auth-client';
66
import { LitNodeClient } from '@lit-protocol/lit-node-client';
77

@@ -17,6 +17,8 @@ export const signWithLitActionCode = `(async () => {
1717

1818
interface ExecuteLitAction {
1919
litNodeClient: LitNodeClient;
20+
capacityTokenId?: string;
21+
pkpEthAddress: string;
2022
pkpPublicKey: string;
2123
authSigner: ethers.Wallet;
2224
ipfsId?: string;
@@ -28,20 +30,38 @@ const ONE_MINUTE = 1 * 60 * 1000;
2830

2931
export async function executeLitAction({
3032
litNodeClient,
33+
capacityTokenId,
34+
pkpEthAddress,
3135
pkpPublicKey,
3236
authSigner,
3337
ipfsId,
3438
code,
3539
jsParams,
3640
}: ExecuteLitAction) {
41+
let capacityDelegationAuthSig;
42+
if (litNodeClient.config.litNetwork !== LIT_NETWORK.DatilDev) {
43+
const capacityDelegationAuthSigRes =
44+
await litNodeClient.createCapacityDelegationAuthSig({
45+
dAppOwnerWallet: authSigner,
46+
capacityTokenId,
47+
delegateeAddresses: [pkpEthAddress],
48+
uses: '1',
49+
});
50+
capacityDelegationAuthSig =
51+
capacityDelegationAuthSigRes.capacityDelegationAuthSig;
52+
}
53+
54+
const expiration = new Date(Date.now() + ONE_MINUTE).toISOString();
3755
const pkpSessionSigs = await litNodeClient.getPkpSessionSigs({
3856
pkpPublicKey,
39-
capabilityAuthSigs: [],
57+
capabilityAuthSigs: capacityDelegationAuthSig
58+
? [capacityDelegationAuthSig]
59+
: [],
4060
authMethods: [
4161
await EthWalletProvider.authenticate({
4262
signer: authSigner,
4363
litNodeClient: litNodeClient,
44-
expiration: new Date(Date.now() + ONE_MINUTE).toISOString(),
64+
expiration,
4565
}),
4666
],
4767
resourceAbilityRequests: [
@@ -50,6 +70,7 @@ export async function executeLitAction({
5070
ability: LIT_ABILITY.LitActionExecution,
5171
},
5272
],
73+
expiration,
5374
});
5475

5576
const executeJsResponse = await litNodeClient.executeJs({

packages/automation/src/lib/state-machine.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const litNodeClient = new LitNodeClient({
1313
const stateMachineParams: BaseStateMachineParams = {
1414
litContracts,
1515
litNodeClient,
16+
privateKey: '0xPRIVATE_KEY',
1617
};
1718

1819
describe('StateMachine', () => {

0 commit comments

Comments
 (0)