@lit-protocol/e2e
Version:
Lit Protocol E2E testing package for running comprehensive integration tests
47 lines • 1.48 kB
JavaScript
import { ScopeStringSchema } from '@lit-protocol/schemas';
// Configuration constants
const PAGINATION_LIMIT = 5;
const PKP_SCOPES = [ScopeStringSchema.enum['sign-anything']];
/**
* Gets an existing PKP or creates a new one if none exists
*
* @param litClient - The Lit Protocol client instance
* @param authData - Authentication data for the account
* @param account - The account to associate with the PKP
* @param storagePath - Local storage path for PKP tokens
* @param networkName - Name of the network being used
* @returns Promise<PKP> - The existing or newly created PKP
*/
export const getOrCreatePkp = async (litClient, authData, account) => {
// Check for existing PKPs
const { pkps } = await litClient.viewPKPsByAuthData({
authData,
pagination: {
limit: PAGINATION_LIMIT,
},
});
// If PKP exists, return it
if (pkps && pkps[0]) {
return pkps[0];
}
// Otherwise mint new PKP
try {
await litClient.mintWithAuth({
authData,
account,
scopes: PKP_SCOPES,
});
}
catch (e) {
throw new Error(`❌ Error minting PKP: ${e}`);
}
// Query again to get the newly minted PKP in the expected format
const { pkps: newPkps } = await litClient.viewPKPsByAuthData({
authData,
pagination: {
limit: PAGINATION_LIMIT,
},
});
return newPkps[0];
};
//# sourceMappingURL=pkp-utils.js.map