refactoed mint and create session
This commit is contained in:
30
src/lib/services/mintPkp/mintPkp.ts
Normal file
30
src/lib/services/mintPkp/mintPkp.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import type { IRelayPKP } from '@lit-protocol/types';
|
||||
import type { IProvider } from '$lib/services/provider/IProvider';
|
||||
import { createMessage } from '$lib/services/messages';
|
||||
|
||||
export async function mintPkp(provider: IProvider, authMethod: any): Promise<IRelayPKP> {
|
||||
createMessage({
|
||||
text: 'Minting started...',
|
||||
sender: '$lib/components/GoogleAuth.svelte',
|
||||
type: 'SYSTEM'
|
||||
});
|
||||
|
||||
const txHash: string = await provider.mintPKPThroughRelayer(authMethod);
|
||||
const response = await provider.relay.pollRequestUntilTerminalState(txHash);
|
||||
if (response.status !== 'Succeeded') {
|
||||
throw new Error('Minting failed');
|
||||
}
|
||||
const newPKP: IRelayPKP = {
|
||||
tokenId: response.pkpTokenId,
|
||||
publicKey: response.pkpPublicKey,
|
||||
ethAddress: response.pkpEthAddress
|
||||
};
|
||||
|
||||
createMessage({
|
||||
text: 'Minted a new PKP.',
|
||||
sender: '$lib/components/GoogleAuth.svelte',
|
||||
type: 'SYSTEM'
|
||||
});
|
||||
|
||||
return newPKP;
|
||||
}
|
Reference in New Issue
Block a user