From ba41d0be23497d4fdf1b57f4457ad9d096160270 Mon Sep 17 00:00:00 2001 From: Anson Date: Mon, 24 Jun 2024 16:06:08 +0100 Subject: [PATCH 1/8] test: add RestClient endpoint tests --- requests/get-status-:requestId.http | 5 +++++ requests/mint-next-and-add-auth-methods.http | 14 ++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 requests/get-status-:requestId.http create mode 100644 requests/mint-next-and-add-auth-methods.http diff --git a/requests/get-status-:requestId.http b/requests/get-status-:requestId.http new file mode 100644 index 0000000..d617ea0 --- /dev/null +++ b/requests/get-status-:requestId.http @@ -0,0 +1,5 @@ +# Poll status of minting PKP transaction +# GET /auth/status/:requestId + +GET http://127.0.0.1:6380/auth/status/0xeff5cf00752705bf9ff8af007dd4cd9fd6568a1623d97cd1d9a7b12a4938ef5f +api-key: your-api-key-value diff --git a/requests/mint-next-and-add-auth-methods.http b/requests/mint-next-and-add-auth-methods.http new file mode 100644 index 0000000..38cde38 --- /dev/null +++ b/requests/mint-next-and-add-auth-methods.http @@ -0,0 +1,14 @@ +POST http://127.0.0.1:6380/api/v2/mint-next-and-add-auth-methods +Content-Type: application/json +api-key: your-api-key-value + +{ + "keyType": 2, + "permittedAuthMethodTypes": [2], + "permittedAuthMethodIds": ["ENTER YOUR AUTH METHOD ID HERE"], + "permittedAuthMethodPubkeys": ["0x"], + "permittedAuthMethodScopes": [[1]], + "addPkpEthAddressAsPermittedAddress": true, + "sendPkpToItself": true +} + From 722b26ad00d6447c1b8b8d36171d2f23345c22ee Mon Sep 17 00:00:00 2001 From: Anson Date: Mon, 24 Jun 2024 16:07:04 +0100 Subject: [PATCH 2/8] feat: add new `v2` endpoint for `mintNextAndAddAuthMethodsHandler` --- index.ts | 3 ++ lit.ts | 86 +++++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 75 insertions(+), 14 deletions(-) diff --git a/index.ts b/index.ts index 708c09a..4727691 100644 --- a/index.ts +++ b/index.ts @@ -216,6 +216,9 @@ app.post("/store-condition", storeConditionHandler); // --- Mint PKP for authorized account app.post("/mint-next-and-add-auth-methods", mintNextAndAddAuthMethodsHandler); +// -- (V2) Mint PKP for authorized account (using ThirdWeb) +app.post("/api/v2/mint-next-and-add-auth-methods", mintNextAndAddAuthMethodsHandler); + // --- Fetch PKPs tied to authorized account app.post("/fetch-pkps-by-auth-method", fetchPKPsHandler); diff --git a/lit.ts b/lit.ts index 1309221..35088af 100644 --- a/lit.ts +++ b/lit.ts @@ -8,6 +8,8 @@ import { Sequencer } from "./lib/sequencer"; import { parseEther } from "ethers/lib/utils"; import { LitNodeClientNodeJs } from "@lit-protocol/lit-node-client-nodejs"; import { CapacityToken } from "lit"; +import { VersionStrategy } from "./routes/versionStrategy"; +import { ThirdWebLib } from "./lib/thirdweb/ThirdWebLib"; const MANZANO_CONTRACT_ADDRESSES = 'https://lit-general-worker.getlit.dev/manzano-contract-addresses'; const HABANERO_CONTRACT_ADDRESSES = 'https://lit-general-worker.getlit.dev/habanero-contract-addresses'; @@ -238,6 +240,7 @@ export async function mintPKPV2({ permittedAuthMethodScopes, addPkpEthAddressAsPermittedAddress, sendPkpToItself, + versionStrategy, }: { keyType: string; permittedAuthMethodTypes: string[]; @@ -246,6 +249,7 @@ export async function mintPKPV2({ permittedAuthMethodScopes: string[][]; addPkpEthAddressAsPermittedAddress: boolean; sendPkpToItself: boolean; + versionStrategy?: VersionStrategy, }): Promise { console.log( "In mintPKPV2", @@ -260,23 +264,77 @@ export async function mintPKPV2({ console.log('config.network:', config.network); + // -- contracts to be used const pkpHelper = await getPkpHelperContract(); const pkpNft = await getPkpNftContract(); + + // -- contract functions to be called + const pkpNftFunctions = { + mintCost: 'mintCost', + } - // first get mint cost - const mintCost = await pkpNft.mintCost(); - const tx = await pkpHelper.mintNextAndAddAuthMethods( - keyType, - permittedAuthMethodTypes, - permittedAuthMethodIds, - permittedAuthMethodPubkeys, - permittedAuthMethodScopes, - addPkpEthAddressAsPermittedAddress, - sendPkpToItself, - { value: mintCost }, - ); - console.log("tx", tx); - return tx; + const pkpHelperFunctions = { + mintNextAndAddAuthMethods: 'mintNextAndAddAuthMethods', + } + + // version strategy is required + if(!versionStrategy){ + throw new Error("versionStrategy is required"); + } + + // must contain the value in the VersionStrategy enum + if(!Object.values(VersionStrategy).includes(versionStrategy)){ + throw new Error(`Invalid version strategy. Must be one of: ${Object.values(VersionStrategy).join(", ")}`); + } + + if(versionStrategy === VersionStrategy.DEFAULT){ + // first get mint cost + const mintCost = await pkpNft[pkpNftFunctions.mintCost](); + + const tx = await pkpHelper[pkpHelperFunctions.mintNextAndAddAuthMethods]( + keyType, + permittedAuthMethodTypes, + permittedAuthMethodIds, + permittedAuthMethodPubkeys, + permittedAuthMethodScopes, + addPkpEthAddressAsPermittedAddress, + sendPkpToItself, + { value: mintCost }, + ); + console.log("tx", tx); + return tx; + } + + if(versionStrategy === VersionStrategy.FORWARD_TO_THIRDWEB){ + + const mintCost = await ThirdWebLib.Contract.read({ + contractAddress: pkpNft.address, + functionName: pkpNftFunctions.mintCost, + }); + + console.log("mintCost", mintCost); + + const res = await ThirdWebLib.Contract.write({ + contractAddress: pkpHelper.address, + functionName: pkpHelperFunctions.mintNextAndAddAuthMethods, + args: [ + keyType, + permittedAuthMethodTypes, + permittedAuthMethodIds, + permittedAuthMethodPubkeys, + permittedAuthMethodScopes, + addPkpEthAddressAsPermittedAddress, + sendPkpToItself, + ], + backendWalletAddress: "0x05Dffce4D37ffEeb758b01fE3d1f0468a78fD58D", + }); + + console.log(res); + + return res as any; + } + + throw new Error("Invalid version strategy"); } export async function mintPKP({ From 09ecfceeea51ae0a18b44970c12a0c9a807f7c6e Mon Sep 17 00:00:00 2001 From: Anson Date: Mon, 24 Jun 2024 16:07:42 +0100 Subject: [PATCH 3/8] feat: introduced `VersionStrategy` to run different logic based on the provided URL. --- routes/VersionStrategy.ts | 32 ++++++++++++++++++++++++++++++++ routes/auth/mintAndFetch.ts | 13 ++++++++++--- 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 routes/VersionStrategy.ts diff --git a/routes/VersionStrategy.ts b/routes/VersionStrategy.ts new file mode 100644 index 0000000..87be79c --- /dev/null +++ b/routes/VersionStrategy.ts @@ -0,0 +1,32 @@ +/** + * Enum representing the version strategy for the relay server. + */ +export enum VersionStrategy { + /** + * The default version strategy. Use the relay server to process the request. + */ + DEFAULT = "default", + + /** + * Forward the request to ThirdWeb for processing. + */ + FORWARD_TO_THIRDWEB = "thirdweb", +} + +/** + * Determines the version strategy based on the provided URL. + * @param url - The URL to check for the version. + * @returns The version strategy based on the URL. + */ +export function getVersionStrategy(url: string): VersionStrategy { + const versionRegex = /\/api\/v(\d+)\//; + const match = url.match(versionRegex); + const version = match ? parseInt(match[1], 10) : null; + + switch (version) { + case 2: + return VersionStrategy.FORWARD_TO_THIRDWEB; + default: + return VersionStrategy.DEFAULT; + } +} diff --git a/routes/auth/mintAndFetch.ts b/routes/auth/mintAndFetch.ts index f765e6c..9f0219a 100644 --- a/routes/auth/mintAndFetch.ts +++ b/routes/auth/mintAndFetch.ts @@ -8,6 +8,7 @@ import { MintNextAndAddAuthMethodsRequest, MintNextAndAddAuthMethodsResponse, } from "../../models"; +import { getVersionStrategy } from "../versionStrategy"; export async function mintNextAndAddAuthMethodsHandler( req: Request< @@ -23,9 +24,15 @@ export async function mintNextAndAddAuthMethodsHandler( number >, ) { + const versionStrategy = getVersionStrategy(req.url); + // mint PKP for user try { - const mintTx = await mintPKPV2(req.body); + const mintTx = await mintPKPV2({ + ...req.body, + versionStrategy, + }); + console.info("Minted PKP", { requestId: mintTx.hash, }); @@ -33,11 +40,11 @@ export async function mintNextAndAddAuthMethodsHandler( requestId: mintTx.hash, }); } catch (err) { - console.error("Unable to mint PKP", { + console.error("[mintNextAndAddAuthMethodsHandler] Unable to mint PKP", { err, }); return res.status(500).json({ - error: `Unable to mint PKP`, + error: `[mintNextAndAddAuthMethodsHandler] Unable to mint PKP ${err}`, }); } } From 4e05cfc3e28086c2a9c9c2660c665a0e1039a506 Mon Sep 17 00:00:00 2001 From: Anson Date: Mon, 24 Jun 2024 16:08:06 +0100 Subject: [PATCH 4/8] feat: add `ThirdWeb` lib --- lib/thirdweb/ThirdWebLib.spec.ts | 135 +++++++++++++ lib/thirdweb/ThirdWebLib.ts | 325 +++++++++++++++++++++++++++++++ 2 files changed, 460 insertions(+) create mode 100644 lib/thirdweb/ThirdWebLib.spec.ts create mode 100644 lib/thirdweb/ThirdWebLib.ts diff --git a/lib/thirdweb/ThirdWebLib.spec.ts b/lib/thirdweb/ThirdWebLib.spec.ts new file mode 100644 index 0000000..face900 --- /dev/null +++ b/lib/thirdweb/ThirdWebLib.spec.ts @@ -0,0 +1,135 @@ +import { expect, test } from "bun:test"; +import { ThirdWebLib } from "./ThirdWebLib"; +import { ethers } from "ethers"; + +// bun test --test-name-pattern 'getAllWallets' +test("getAllWallets", async () => { + const wallets = await ThirdWebLib.Action.getAllWallets({ limit: 500 }); + console.log("total wallets:", wallets.length); + + expect(wallets.length).toBeGreaterThan(0); +}); + +// bun test --test-name-pattern 'createWallet' +test("createWallet", async () => { + const res = await ThirdWebLib.Action.createWallet("test-wallet"); + console.log(res); + + expect(res).toHaveProperty("walletAddress"); + expect(res.status).toBe("success"); +}); + +// bun test --test-name-pattern 'create 500 wallets' --timeout 300000 +test("create 500 wallets", async () => { + const totalWallets = 500; + const currentTotalWallets = await ThirdWebLib.Action.getAllWallets(); + + const neededWallets = totalWallets - currentTotalWallets.length; + console.log("neededWallets:", neededWallets); + + for (let i = 0; i < neededWallets; i++) { + const label = `wallet-${neededWallets - i}`; + const res = await ThirdWebLib.Action.createWallet(label); + console.log(`${label}:`, res); + + expect(res).toHaveProperty("walletAddress"); + expect(res.status).toBe("success"); + } +}); + +// Used this to create a master wallet address +// // bun test --test-name-pattern 'ethers generate private key' +// // 0x05Dffce4D37ffEeb758b01fE3d1f0468a78fD58D +// test("ethers generate private key", async () => { +// const privateKey = ethers.Wallet.createRandom().privateKey; +// console.log("privateKey:", privateKey); +// }); + +// bun test --test-name-pattern 'ethers check balance' +// 10 LIT = 10000000000000000000 wei +// test("ethers check balance", async () => { +// const address = "0x05Dffce4D37ffEeb758b01fE3d1f0468a78fD58D"; +// const rpc = "https://chain-rpc.litprotocol.com/http"; +// const provider = new ethers.providers.JsonRpcProvider(rpc); +// const balance = await provider.getBalance(address); +// const parsedBalance = ethers.utils.formatEther(balance); +// const originalBalance = ethers.utils.parseEther(parsedBalance); +// console.log("balance:", parsedBalance); +// console.log("balance in wei:", balance.toString()); +// console.log("originalBalance:", originalBalance.toString()); + +// expect(balance.toString()).toBe(originalBalance.toString()); +// }); + +// bun test --test-name-pattern 'maintainBalances' --timeout 300000 +test("maintainBalances", async () => { + // -- config + const masterAddress = process.env.MASTER_WALLET_ADDRESS as string; + if (!masterAddress) { + throw new Error("MASTER_WALLET_ADDRESS is not set"); + } + + const queueIds = await ThirdWebLib.Action.maintainBalances({ + minimumBalance: "0.001", + funderAddress: masterAddress, + }); + + const funded = queueIds.filter((q) => q.queueId === ""); + const funding = 500 - funded.length; + console.log("funded:", funded.length); + console.log("funding:", funding); +}); + +// bun test --test-name-pattern 'get all transactions' +test("get all transactions", async () => { + const queuedTxs = await ThirdWebLib.Action.getAllTransactions(); + const totalTxs = queuedTxs.length; + const totalQueueingTxs = queuedTxs.filter( + (tx: any) => tx.status === "queued", + ).length; + console.log("totalTxs:", totalTxs); + console.log("totalQueueingTxs:", totalQueueingTxs); +}); + +// bun test --test-name-pattern 'get balances' --timeout 300000 +test("get balances", async () => { + const wallets = await ThirdWebLib.Action.getAllWallets({ + limit: 500, + }); + + const balancePromises = wallets.map((wallet) => { + return ThirdWebLib.Action.getBalance(wallet.address); + }); + + const balances = await Promise.all(balancePromises); + + // check how many wallets have a balance of 0 + const zeroBalances = balances.filter((balance) => { + return parseInt(balance.value) <= 0; + }).length; + + const greaterThanZeroBalances = balances.filter((balance) => { + return parseInt(balance.value) > 0; + }); + + console.log("zeroBalances:", zeroBalances); + console.log("greaterThanZeroBalances:", greaterThanZeroBalances.length); +}); + +// bun test --test-name-pattern 'read contract' --timeout 300000 +test("read contract", async () => { + const read = await ThirdWebLib.Fetch.get( + "/contract/lit-protocol/0x3c3ad2d238757Ea4AF87A8624c716B11455c1F9A/read?functionName=mintCost", + ); + + console.log("read:", read); +}); + +// bun test --test-name-pattern 'read lit' --timeout 300000 +test("read lit", async () => { + const read = await ThirdWebLib.Fetch.get( + "/contract/lit-protocol", + ); + + console.log("read:", read); +}); diff --git a/lib/thirdweb/ThirdWebLib.ts b/lib/thirdweb/ThirdWebLib.ts new file mode 100644 index 0000000..ee4af8b --- /dev/null +++ b/lib/thirdweb/ThirdWebLib.ts @@ -0,0 +1,325 @@ +import { ethers } from "ethers"; + +// -- thirdweb config +const THIRDWEB_ENGINE_URL = process.env.THIRDWEB_ENGINE_URL; +const THIRDWEB_ACCESS_TOKEN = process.env.THIRDWEB_ACCESS_TOKEN; +const AUTH_HEADERS = { + authorization: `Bearer ${THIRDWEB_ACCESS_TOKEN}`, +}; + +// -- chain config +const LIT_CHAIN_ID = 175177; +const LIT_SLUG = "lit-protocol"; + +export namespace ThirdWebLib { + export namespace Fetch { + /** + * Fetches data from the specified path using a GET request. + * @param path - The path to fetch data from. + * @returns A Promise that resolves to the fetched data. + */ + export async function get(path: string) { + const res = await ( + await fetch(`${THIRDWEB_ENGINE_URL}${path}`, { + headers: AUTH_HEADERS, + }) + ) + .json() + .catch((err) => { + console.error("Error fetching chain:", err); + }); + + return res.result; + } + + /** + * Fetches data from the server using the POST method. + * + * @param path - The path of the API endpoint. + * @param body - The request body. + * @param extraHeaders - Additional headers to be included in the request. + * @returns A Promise that resolves to the response data from the server. + */ + export async function post(path: string, body: any, extraHeaders = {}) { + const res = await ( + await fetch(`${THIRDWEB_ENGINE_URL}${path}`, { + method: "POST", + headers: { + "Content-Type": "application/json", + ...AUTH_HEADERS, + ...extraHeaders, + }, + body: JSON.stringify(body), + }) + ) + .json() + .catch((err) => { + console.error("Error fetching chain:", err); + }); + + return res; + } + } + + /** + * Action is an abstraction of using the ThirdWeb API endpoints. + */ + export namespace Action { + /** + * Retrieves all wallets from the backend server. + * @returns A promise that resolves to an array of wallet objects. + * Each wallet object contains the address, type, and label (if available). + * @throws If there is an error fetching the wallets from the backend server. + */ + export async function getAllWallets( + { + limit, + }: { + limit: number; + } = { limit: 1000 }, + ): Promise< + { + address: string; + type: "local"; + label: string | null; + }[] + > { + try { + const wallets = await Fetch.get( + `/backend-wallet/get-all?page=1&limit=${limit}`, + ); + return wallets; + } catch (e: any) { + throw new Error("[ThirdWebLib] Error fetching wallets:", e); + } + } + + /** + * Creates a wallet with the specified name. + * @param name - The name of the wallet. + * @returns A promise that resolves to an object containing the wallet address and status. + * @throws If there is an error creating the wallet. + */ + export async function createWallet(name: string): Promise<{ + walletAddress: string; + status: "success" | "error"; + }> { + try { + const res = await ThirdWebLib.Fetch.post( + "/backend-wallet/create", + { + label: name, + }, + ); + + return res.result; + } catch (e: any) { + throw new Error("[ThirdWebLib] Error creating wallet:", e); + } + } + + /** + * Retrieves the balance of a wallet address. + * @param address - The wallet address to retrieve the balance for. + * @returns A promise that resolves to an object containing the wallet address, name, symbol, decimals, value, and displayValue. + * @throws If there is an error retrieving the balance. + */ + export async function getBalance(address: string): Promise<{ + walletAddress: string; + name: "LitProtocol"; + symbol: "LIT"; + decimals: 18; + value: string; + displayValue: string; + }> { + try { + const balance = await Fetch.get( + `/backend-wallet/${LIT_SLUG}/${address}/get-balance`, + ); + return balance; + } catch (e: any) { + throw new Error("[ThirdWebLib] Error getting balance:", e); + } + } + + /** + * Funds a wallet by sending a transaction from one address to another. + * @param funder - The address of the funder. + * @param fundee - The address of the fundee. + * @param amount - The amount to be funded. + * @returns A promise that resolves to an object containing the queue ID of the transaction. + * @throws If there is an error while funding the wallet. + */ + export async function fundWallet({ + funder, + fundee, + amount, + }: { + funder: string; + fundee: string; + amount: string; + }): Promise<{ queueId: string }> { + try { + const res = await ThirdWebLib.Fetch.post( + `/backend-wallet/${LIT_SLUG}/send-transaction`, + { + toAddress: fundee, + data: "0x", + value: amount, + }, + { + "x-backend-wallet-address": funder, + }, + ); + + return { + queueId: res.result.queueId, + }; + } catch (e: any) { + throw new Error("[ThirdWebLib] Error funding wallet:", e); + } + } + + /** + * Maintains balances of wallets by funding them if their balance is below a minimum threshold. + * @param {Object} options - The options for maintaining balances. + * @param {string} options.funderAddress - The address of the funder. + * @param {string} options.minimumBalance - The minimum balance threshold. + * @param {number} [options.maxWallets] - The maximum number of wallets to consider. + * @returns {Promise>} - A promise that resolves to an array of funding promises. + */ + export async function maintainBalances({ + minimumBalance, + funderAddress, + maxWallets, + }: { + funderAddress: string; + minimumBalance: string; + maxWallets?: number; + }): Promise<{ queueId: string }[]> { + const wallets = await ThirdWebLib.Action.getAllWallets({ + limit: maxWallets || 500, + }); + + // -- get all balances + const balancePromises = wallets.map((wallet) => { + return ThirdWebLib.Action.getBalance(wallet.address); + }); + + const balances = await Promise.all(balancePromises); + + // -- get all funding promises + const fundPromises = balances.map((balance, i) => { + const currentBalance = ethers.utils.parseEther(balance.value); + const diff = ethers.utils + .parseEther(minimumBalance) + .sub(currentBalance); + + if (diff.gt(0)) { + const diffInWei = diff.toString(); + + return ThirdWebLib.Action.fundWallet({ + funder: funderAddress, + fundee: balance.walletAddress, + amount: diffInWei, + }); + } else { + console.log( + `[${i}]: no need to fund ${balance.walletAddress}`, + ); + return Promise.resolve({ queueId: "" }); + } + }); + + // queue all funding promises + return await Promise.all(fundPromises); + } + + export async function getAllTransactions() { + try { + const data = await Fetch.get( + `/transaction/get-all?limit=10000`, + ); + return data.transactions; + } catch (e: any) { + throw new Error( + "[ThirdWebLib] Error fetching transactions:", + e, + ); + } + } + } + + export namespace Contract { + + export async function lit(){ + try{ + const res = await ThirdWebLib.Fetch.get( + `/contract/${LIT_SLUG}`, + ); + return res; + }catch(e: any){ + throw new Error("[ThirdWebLib] Error reading contract:", e); + } + } + + export async function read({ + contractAddress, + functionName, + }: { + contractAddress: string; + functionName: string; + }) { + try { + const res = await ThirdWebLib.Fetch.get( + `/contract/${LIT_SLUG}/${contractAddress}/read?functionName=${functionName}`, + ); + + return res; + } catch (e: any) { + throw new Error("[ThirdWebLib] Error reading contract:", e); + } + } + + export async function write({ + contractAddress, + functionName, + args, + backendWalletAddress, + options, + }: { + contractAddress: string; + functionName: string; + args: any[]; + backendWalletAddress: string; + options?: { + simulateTx?: boolean; + }; + }) { + try { + const res = await ThirdWebLib.Fetch.post( + `/contract/${LIT_SLUG}/${contractAddress}/write?chain`, + { + functionName, + args, + // args: [ + // "string", + // ["string", "string"], + // {}, + // ["string"], + // "string", + // ], + }, + { + "x-backend-wallet-address": backendWalletAddress, + }, + ); + + return res; + } catch (e: any) { + throw new Error("[ThirdWebLib] Error writing contract:", e); + } + } + + } +} From 032154b56b66ba1a80fe916067c0b6db8b624466 Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 25 Jun 2024 16:34:46 +0100 Subject: [PATCH 5/8] wip: adding a request id source to the response. Did it get processed by the relayer or from ThirdWeb? --- lib/thirdweb/ThirdWebLib.ts | 7 ------- lit.ts | 19 ++++++++++++++++--- routes/auth/mintAndFetch.ts | 6 ++++++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/thirdweb/ThirdWebLib.ts b/lib/thirdweb/ThirdWebLib.ts index ee4af8b..9cfe711 100644 --- a/lib/thirdweb/ThirdWebLib.ts +++ b/lib/thirdweb/ThirdWebLib.ts @@ -302,13 +302,6 @@ export namespace ThirdWebLib { { functionName, args, - // args: [ - // "string", - // ["string", "string"], - // {}, - // ["string"], - // "string", - // ], }, { "x-backend-wallet-address": backendWalletAddress, diff --git a/lit.ts b/lit.ts index 35088af..f77c20e 100644 --- a/lit.ts +++ b/lit.ts @@ -301,6 +301,18 @@ export async function mintPKPV2({ sendPkpToItself, { value: mintCost }, ); + + console.log("PRINT THIS OUT TO SEE THE TX OBJECT"); + console.log( + keyType, + permittedAuthMethodTypes, + permittedAuthMethodIds, + permittedAuthMethodPubkeys, + permittedAuthMethodScopes, + addPkpEthAddressAsPermittedAddress, + sendPkpToItself, + { value: mintCost } + ); console.log("tx", tx); return tx; } @@ -312,8 +324,6 @@ export async function mintPKPV2({ functionName: pkpNftFunctions.mintCost, }); - console.log("mintCost", mintCost); - const res = await ThirdWebLib.Contract.write({ contractAddress: pkpHelper.address, functionName: pkpHelperFunctions.mintNextAndAddAuthMethods, @@ -325,11 +335,14 @@ export async function mintPKPV2({ permittedAuthMethodScopes, addPkpEthAddressAsPermittedAddress, sendPkpToItself, + { + value: mintCost + } ], backendWalletAddress: "0x05Dffce4D37ffEeb758b01fE3d1f0468a78fD58D", }); - console.log(res); + console.log("res:", res); return res as any; } diff --git a/routes/auth/mintAndFetch.ts b/routes/auth/mintAndFetch.ts index 9f0219a..b16dace 100644 --- a/routes/auth/mintAndFetch.ts +++ b/routes/auth/mintAndFetch.ts @@ -33,8 +33,14 @@ export async function mintNextAndAddAuthMethodsHandler( versionStrategy, }); + console.log("mintTx:", mintTx); + + const source = mintTx.hash ? 'lit-relayer' : 'thirdweb'; + + console.info("Minted PKP", { requestId: mintTx.hash, + source, }); return res.status(200).json({ requestId: mintTx.hash, From f27391e513ffc30f60b51ad24dbda801b2d29d1c Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 25 Jun 2024 16:35:48 +0100 Subject: [PATCH 6/8] feat(test): add RestClient tests on minting --- requests/mint-next-and-add-auth-methods-v2.http | 13 +++++++++++++ requests/mint-next-and-add-auth-methods.http | 7 +++---- 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 requests/mint-next-and-add-auth-methods-v2.http diff --git a/requests/mint-next-and-add-auth-methods-v2.http b/requests/mint-next-and-add-auth-methods-v2.http new file mode 100644 index 0000000..c58c75b --- /dev/null +++ b/requests/mint-next-and-add-auth-methods-v2.http @@ -0,0 +1,13 @@ +POST http://127.0.0.1:6380/api/v2/mint-next-and-add-auth-methods +Content-Type: application/json +api-key: your-api-key-value + +{ + "keyType": 2, + "permittedAuthMethodTypes": [2], + "permittedAuthMethodIds": ["0x4825e3caf11a273792ad0405524820410cd15d6323ae4621537f0a89c1322a74"], + "permittedAuthMethodPubkeys": ["0x"], + "permittedAuthMethodScopes": [[1]], + "addPkpEthAddressAsPermittedAddress": true, + "sendPkpToItself": true +} \ No newline at end of file diff --git a/requests/mint-next-and-add-auth-methods.http b/requests/mint-next-and-add-auth-methods.http index 38cde38..0405e90 100644 --- a/requests/mint-next-and-add-auth-methods.http +++ b/requests/mint-next-and-add-auth-methods.http @@ -1,14 +1,13 @@ -POST http://127.0.0.1:6380/api/v2/mint-next-and-add-auth-methods +POST http://127.0.0.1:6380/mint-next-and-add-auth-methods Content-Type: application/json api-key: your-api-key-value { "keyType": 2, "permittedAuthMethodTypes": [2], - "permittedAuthMethodIds": ["ENTER YOUR AUTH METHOD ID HERE"], + "permittedAuthMethodIds": [""], "permittedAuthMethodPubkeys": ["0x"], "permittedAuthMethodScopes": [[1]], "addPkpEthAddressAsPermittedAddress": true, "sendPkpToItself": true -} - +} \ No newline at end of file From c48005d46d5c18163b3b63d1acc2e35c0f062a0c Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 25 Jun 2024 16:36:12 +0100 Subject: [PATCH 7/8] feat(package.json): add bun to devDependencies --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 63c434a..53caead 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "uint8arrays": "^3.0.0" }, "devDependencies": { + "@types/bun": "^1.1.5", "@types/cbor": "^6.0.0", "@types/cors": "^2.8.12", "@types/elliptic": "^6.4.14", From edd692455ff066b1f4806ee9bc1b28697e229eb5 Mon Sep 17 00:00:00 2001 From: Anson Date: Wed, 10 Jul 2024 19:17:51 +0100 Subject: [PATCH 8/8] chore: change file name to make it compatible to different OSs --- .../{get-status-:requestId.http => get-status-requestId.http} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename requests/{get-status-:requestId.http => get-status-requestId.http} (100%) diff --git a/requests/get-status-:requestId.http b/requests/get-status-requestId.http similarity index 100% rename from requests/get-status-:requestId.http rename to requests/get-status-requestId.http