@@ -3,12 +3,12 @@ import {
33 storagePlugins ,
44 ViemAccountAuthenticator ,
55} from '@lit-protocol/auth' ;
6- import { createLitClient } from '@lit-protocol/lit-client' ;
7- import { Account , PrivateKeyAccount } from 'viem' ;
6+ import { createLitClient , utils as litUtils } from '@lit-protocol/lit-client' ;
87import { generatePrivateKey , privateKeyToAccount } from 'viem/accounts' ;
98import { z } from 'zod' ;
109import { fundAccount } from './helper/fundAccount' ;
1110import { getOrCreatePkp } from './helper/pkp-utils' ;
11+
1212// import { createPkpAuthContext } from './helper/auth-contexts';
1313
1414const SupportedNetworkSchema = z . enum ( [
@@ -17,6 +17,7 @@ const SupportedNetworkSchema = z.enum([
1717 'naga-local' ,
1818 'naga-staging' ,
1919] ) ;
20+
2021type SupportedNetwork = z . infer < typeof SupportedNetworkSchema > ;
2122
2223const LogLevelSchema = z . enum ( [ 'silent' , 'info' , 'debug' ] ) ;
@@ -27,6 +28,9 @@ const LIVE_NETWORK_FUNDING_AMOUNT = '0.01';
2728const LOCAL_NETWORK_FUNDING_AMOUNT = '1' ;
2829const LIVE_NETWORK_LEDGER_DEPOSIT_AMOUNT = '2' ;
2930
31+ const EVE_VALIDATION_IPFS_CID =
32+ 'QmcxWmo3jefFsPUnskJXYBwsJYtiFuMAH1nDQEs99AwzDe' ;
33+
3034export const init = async (
3135 network ?: SupportedNetwork ,
3236 logLevel ?: LogLevel
@@ -42,6 +46,10 @@ export const init = async (
4246 bobViemAccountPkp : any ;
4347 aliceEoaAuthContext : any ;
4448 alicePkpAuthContext : any ;
49+ eveViemAccount : any ;
50+ eveCustomAuthData : Awaited < ReturnType < typeof litUtils . generateAuthData > > ;
51+ eveViemAccountPkp : Awaited < ReturnType < typeof litClient . mintWithCustomAuth > > [ 'pkpData' ] [ 'data' ] ;
52+ eveValidationIpfsCid : string ;
4553 masterDepositForUser : ( userAddress : string ) => Promise < void > ;
4654 // alicePkpViemAccountPermissionsManager: any,
4755} > => {
@@ -66,6 +74,8 @@ export const init = async (
6674 bobViemAccount
6775 ) ;
6876
77+ const eveViemAccount = privateKeyToAccount ( generatePrivateKey ( ) ) ;
78+
6979 /**
7080 * ====================================
7181 * Environment settings
@@ -129,6 +139,11 @@ export const init = async (
129139 thenFundWith : fundingAmount ,
130140 } ) ;
131141
142+ await fundAccount ( eveViemAccount , masterAccount , _networkModule , {
143+ ifLessThan : fundingAmount ,
144+ thenFundWith : fundingAmount ,
145+ } ) ;
146+
132147 /**
133148 * ====================================
134149 * Initialise the LitClient
@@ -184,6 +199,27 @@ export const init = async (
184199 _network
185200 ) ,
186201 ] ) ;
202+ // Use custom auth to create a PKP for Eve
203+ const uniqueDappName = 'e2e-test-dapp' ;
204+
205+ const authMethodConfig = litUtils . generateUniqueAuthMethodType ( {
206+ uniqueDappName : uniqueDappName ,
207+ } ) ;
208+
209+ const eveCustomAuthData = litUtils . generateAuthData ( {
210+ uniqueDappName : uniqueDappName ,
211+ uniqueAuthMethodType : authMethodConfig . bigint ,
212+ userId : 'eve' ,
213+ } ) ;
214+
215+ const { pkpData } = await litClient . mintWithCustomAuth ( {
216+ account : eveViemAccount ,
217+ authData : eveCustomAuthData ,
218+ scope : 'sign-anything' ,
219+ validationIpfsCid : EVE_VALIDATION_IPFS_CID ,
220+ } ) ;
221+
222+ const eveViemAccountPkp = pkpData . data ;
187223
188224 /**
189225 * ====================================
@@ -270,6 +306,12 @@ export const init = async (
270306 // Deposit to the Bob PKP Ledger
271307 await masterDepositForUser ( bobViemAccountPkp . ethAddress ) ;
272308
309+ // Deposit to the Eve EOA Ledger
310+ await masterDepositForUser ( eveViemAccount . address ) ;
311+
312+ // Deposit to the Eve PKP Ledger
313+ await masterDepositForUser ( eveViemAccountPkp . ethAddress ) ;
314+
273315 // const alicePkpViemAccountPermissionsManager = await litClient.getPKPPermissionsManager({
274316 // pkpIdentifier: {
275317 // tokenId: aliceViemAccountPkp.tokenId,
@@ -292,6 +334,10 @@ export const init = async (
292334 bobViemAccount,
293335 bobViemAccountAuthData,
294336 bobViemAccountPkp,
337+ eveViemAccount,
338+ eveCustomAuthData,
339+ eveViemAccountPkp,
340+ eveValidationIpfsCid : EVE_VALIDATION_IPFS_CID ,
295341 aliceEoaAuthContext,
296342 alicePkpAuthContext,
297343 masterDepositForUser,
0 commit comments