-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmintPkp.ts
55 lines (50 loc) · 1.72 KB
/
mintPkp.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import {
AuthMethodScope,
AuthMethodType,
LitNetwork,
} from "@lit-protocol/constants";
import bs58 from "bs58";
import { type GitHubUser } from "./types";
import {
getEthersSigner,
getGithubAuthMethodInfo,
getLitActionCodeIpfsCid,
getLitContractsClient,
getPkpInfoFromMintReceipt,
getPkpMintCost,
} from "./utils";
const LIT_NETWORK =
LitNetwork[import.meta.env.VITE_LIT_NETWORK as keyof typeof LitNetwork];
export const mintPkp = async (githubUser: GitHubUser) => {
try {
const ethersSigner = await getEthersSigner();
const litContracts = await getLitContractsClient(ethersSigner, LIT_NETWORK);
const pkpMintCost = await getPkpMintCost(litContracts);
const {
authMethodType: githubAuthMethodType,
authMethodId: githubAuthMethodId,
} = getGithubAuthMethodInfo(githubUser);
console.log("🔄 Minting new PKP...");
const tx =
await litContracts.pkpHelperContract.write.mintNextAndAddAuthMethods(
AuthMethodType.LitAction, // keyType
[AuthMethodType.LitAction, githubAuthMethodType], // permittedAuthMethodTypes
[
`0x${Buffer.from(
bs58.decode(await getLitActionCodeIpfsCid())
).toString("hex")}`,
githubAuthMethodId,
], // permittedAuthMethodIds
["0x", "0x"], // permittedAuthMethodPubkeys
[[AuthMethodScope.SignAnything], [AuthMethodScope.NoPermissions]], // permittedAuthMethodScopes
true, // addPkpEthAddressAsPermittedAddress
true, // sendPkpToItself
{ value: pkpMintCost }
);
const receipt = await tx.wait();
console.log(`✅ Minted new PKP`);
return getPkpInfoFromMintReceipt(receipt, litContracts);
} catch (error) {
console.error(error);
}
};