Skip to content

Commit bf814d2

Browse files
committed
init lit-x-lighthouse
1 parent 30a981b commit bf814d2

22 files changed

+2007
-250
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Kickstart your Filecoin dApp using this open-source development stack. This bran
44

55
- uploading files and directories to IPFS.
66
- uploading encrypted files and directories to IPFS.
7-
- Interact with the LighthouseNFT to see the usage of these features
7+
- Interact with the LitEncryptedNFT to see the usage of these features
88

99
## Features
1010

packages/hardhat/contracts/LighthouseNFT.sol renamed to packages/hardhat/contracts/LitEncryptedNFT.sol

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pragma solidity ^0.8.23;
33

44
import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
55

6-
contract LighthouseNFT is ERC721 {
6+
contract LitEncryptedNFT is ERC721 {
77
// Counter for the next token ID
88
uint256 private _tokenIdCounter;
99

@@ -17,23 +17,23 @@ contract LighthouseNFT is ERC721 {
1717
mapping(uint256 => bool) private openAccessTokens;
1818

1919
// Constructor to initialize the ERC721 token with a name and symbol
20-
constructor() ERC721("LighthouseNFT", "LNFT") {}
20+
constructor() ERC721("LitEncryptedNFT", "LNFT") {}
2121

2222
// Function to mint a new token with open access
23-
function mint(string memory lighthouse_cid) public {
23+
function mint(string memory file_cid) public {
2424
_tokenIdCounter++; // Increment the token ID counter
2525
uint256 tokenId = _tokenIdCounter;
2626
_mint(msg.sender, tokenId); // Mint the token to the sender
27-
_tokenURIs[tokenId] = lighthouse_cid; // Set the token URI
27+
_tokenURIs[tokenId] = file_cid; // Set the token URI
2828
openAccessTokens[tokenId] = true; // Mark the token as open access
2929
}
3030

3131
// Function to mint a new token with restricted access
32-
function mintPrivate(string memory lighthouse_cid, address[] memory accessList) public {
32+
function mintPrivate(string memory file_cid, address[] memory accessList) public {
3333
_tokenIdCounter++; // Increment the token ID counter
3434
uint256 tokenId = _tokenIdCounter;
3535
_mint(msg.sender, tokenId); // Mint the token to the sender
36-
_tokenURIs[tokenId] = lighthouse_cid; // Set the token URI
36+
_tokenURIs[tokenId] = file_cid; // Set the token URI
3737
tokenContentAccess[tokenId][msg.sender] = true; // Grant access to the sender
3838
// Grant access to the specified addresses
3939
for (uint i = 0; i < accessList.length; i++) {

packages/hardhat/deploy/00_LighthouseNFT.ts

+10-14
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
77
*
88
* @param hre HardhatRuntimeEnvironment object.
99
*/
10-
const deployLighthouseNFT: DeployFunction = async function (
11-
hre: HardhatRuntimeEnvironment
12-
) {
10+
const deployLitEncryptedNFT: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
1311
/*
1412
On localhost, the deployer account is the one that comes with Hardhat, which is already funded.
1513
@@ -25,7 +23,7 @@ const deployLighthouseNFT: DeployFunction = async function (
2523

2624
const { deploy } = hre.deployments;
2725

28-
const LighthouseNFT = await deploy("LighthouseNFT", {
26+
const LitEncryptedNFT = await deploy("LitEncryptedNFT", {
2927
from: deployer,
3028
// Contract constructor arguments
3129
args: [],
@@ -35,38 +33,36 @@ const deployLighthouseNFT: DeployFunction = async function (
3533
autoMine: true,
3634
});
3735

38-
console.log("🚀 LighthouseNFT deployed at: ", LighthouseNFT.address);
39-
const LighthouseNFTAddress = LighthouseNFT.address;
36+
console.log("🚀 LitEncryptedNFT deployed at: ", LitEncryptedNFT.address);
37+
const LitEncryptedNFTAddress = LitEncryptedNFT.address;
4038

4139
// Check if the --verify flag is present
4240
const shouldVerify = process.env.VERIFY === "true";
4341

4442
if (shouldVerify) {
4543
// Timeout for 10 Seconds to wait for the contract to be indexed on explorer
46-
console.log(
47-
"⏳ Waiting for 15 seconds for the contract to be indexed on the explorer..."
48-
);
49-
await new Promise((resolve) => setTimeout(resolve, 15000));
44+
console.log("⏳ Waiting for 15 seconds for the contract to be indexed on the explorer...");
45+
await new Promise(resolve => setTimeout(resolve, 15000));
5046

5147
console.log("🕵️‍♂️ Verifying the contract on the explorer...");
5248

5349
const filecoinNetworks = ["calibration", "filecoin"];
5450
if (filecoinNetworks.includes(hre.network.name)) {
5551
// Verify the contract on the filfox explorer
5652
await hre.run("verify-contract", {
57-
contractName: "LighthouseNFT",
53+
contractName: "LitEncryptedNFT",
5854
});
5955
} else {
6056
await hre.run("verify:verify", {
61-
address: LighthouseNFTAddress,
57+
address: LitEncryptedNFTAddress,
6258
constructorArguments: [],
6359
});
6460
}
6561
}
6662
};
6763

68-
export default deployLighthouseNFT;
64+
export default deployLitEncryptedNFT;
6965

7066
// Tags are useful if you have multiple deploy files and only want to run one of them.
7167
// e.g. yarn deploy --tags DealClient
72-
deployLighthouseNFT.tags = ["LighthouseNFT"];
68+
deployLitEncryptedNFT.tags = ["LitEncryptedNFT"];

packages/hardhat/hardhat.config.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@ import { HardhatUserConfig } from "hardhat/config";
1212
import "solidity-coverage";
1313

1414
dotenvConfig();
15-
const providerApiKey =
16-
process.env.ALCHEMY_API_KEY || "oKxs-03sij-U_N0iOlrSsZFr29-IqbuF";
15+
const providerApiKey = process.env.ALCHEMY_API_KEY || "oKxs-03sij-U_N0iOlrSsZFr29-IqbuF";
1716
// If not set, it uses the hardhat account 0 private key.
1817
const deployerPrivateKey =
19-
process.env.DEPLOYER_PRIVATE_KEY ??
20-
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
18+
process.env.DEPLOYER_PRIVATE_KEY ?? "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";
2119
// If not set, it uses ours Etherscan default API key.
22-
const etherscanApiKey =
23-
process.env.ETHERSCAN_API_KEY || "DNXJA8RX2Q3VZ4URQIWP7Z68CJXQZSC6AW";
20+
const etherscanApiKey = process.env.ETHERSCAN_API_KEY || "DNXJA8RX2Q3VZ4URQIWP7Z68CJXQZSC6AW";
2421

2522
const config: HardhatUserConfig = {
2623
solidity: {
@@ -52,22 +49,27 @@ const config: HardhatUserConfig = {
5249
filecoin: {
5350
url: "https://rpc.ankr.com/filecoin",
5451
accounts: [deployerPrivateKey],
52+
chainId: 314,
5553
},
5654
calibration: {
5755
url: "https://api.calibration.node.glif.io/rpc/v1 ",
5856
accounts: [deployerPrivateKey],
57+
chainId: 314159,
5958
},
6059
sepolia: {
6160
url: `https://eth-sepolia.g.alchemy.com/v2/${providerApiKey}`,
6261
accounts: [deployerPrivateKey],
62+
chainId: 11155111,
6363
},
6464
arbitrumSepolia: {
6565
url: `https://arb-sepolia.g.alchemy.com/v2/${providerApiKey}`,
6666
accounts: [deployerPrivateKey],
67+
chainId: 421611,
6768
},
6869
optimismSepolia: {
6970
url: `https://opt-sepolia.g.alchemy.com/v2/${providerApiKey}`,
7071
accounts: [deployerPrivateKey],
72+
chainId: 11155420,
7173
},
7274
},
7375
// configuration for harhdat-verify plugin

packages/nextjs/app/lighthouse/_components/LighthouseUpload.tsx renamed to packages/nextjs/app/lit_lighthouse/_components/LighthouseUpload.tsx

+13-54
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { accessControlConditions } from "~~/hooks/lighthouse/types";
2-
import { useLighthouseEncryptedFilesUpload, useLighthouseFilesUpload } from "~~/hooks/lighthouse/useUpload";
1+
import { useLighthouseFilesUpload, useUploadEncryptedFile } from "~~/hooks/lighthouse/useUpload";
32

43
export const LighthouseFileUpload = ({
54
handleGetCID,
@@ -77,19 +76,19 @@ export const LighthouseFolderUpload = ({
7776
);
7877
};
7978

80-
export const LigthouseEnctyptedFileUpload = ({
79+
export const LigthouseLitEnctyptedFileUpload = ({
8180
handleGetCID,
8281
acceptMimeType,
83-
accessControlConditions,
82+
tokenId,
83+
contractAddress,
8484
}: {
8585
handleGetCID: (cid: string) => void;
8686
acceptMimeType?: string;
87-
accessControlConditions: {
88-
conditions: accessControlConditions[];
89-
aggregate: string;
90-
};
87+
tokenId: number;
88+
chain: string;
89+
contractAddress: string;
9190
}) => {
92-
const uploadEncryptedFile = useLighthouseEncryptedFilesUpload({
91+
const uploadEncryptedFile = useUploadEncryptedFile({
9392
onUploadSuccess: cid => {
9493
handleGetCID(cid);
9594
},
@@ -101,7 +100,11 @@ export const LigthouseEnctyptedFileUpload = ({
101100
const handleUpload = async (event: React.ChangeEvent<HTMLInputElement>) => {
102101
const file = event.target.files?.[0];
103102
if (file) {
104-
await uploadEncryptedFile([file], accessControlConditions);
103+
await uploadEncryptedFile({
104+
files: [file],
105+
tokenId,
106+
contractAddress,
107+
});
105108
event.target.value = "";
106109
}
107110
};
@@ -118,47 +121,3 @@ export const LigthouseEnctyptedFileUpload = ({
118121
</>
119122
);
120123
};
121-
122-
export const LighthouseEncryptedFolderUpload = ({
123-
handleGetCID,
124-
acceptMimeType,
125-
accessControlConditions,
126-
}: {
127-
handleGetCID: (cid: string) => void;
128-
acceptMimeType?: string;
129-
accessControlConditions: {
130-
conditions: accessControlConditions[];
131-
aggregate: string;
132-
};
133-
}) => {
134-
const uploadEncryptedFiles = useLighthouseEncryptedFilesUpload({
135-
onUploadSuccess: cid => {
136-
handleGetCID(cid);
137-
},
138-
onUploadError: error => {
139-
console.error("Error uploading files:", error);
140-
},
141-
});
142-
143-
const handleUpload = async (event: React.ChangeEvent<HTMLInputElement>) => {
144-
const fileList = event.target.files;
145-
// Convert FileList to array of files
146-
const files = Array.from(fileList || []);
147-
if (files && files.length > 0) {
148-
await uploadEncryptedFiles(files, accessControlConditions);
149-
event.target.value = "";
150-
}
151-
};
152-
153-
return (
154-
<>
155-
<input
156-
type="file"
157-
multiple
158-
accept={acceptMimeType ?? "*"}
159-
onChange={handleUpload}
160-
className="file-input border-base-300 border shadow-md shadow-secondary rounded-3xl"
161-
/>
162-
</>
163-
);
164-
};

packages/nextjs/app/lighthouse/_components/LighthouseNFTContracts.tsx renamed to packages/nextjs/app/lit_lighthouse/_components/LitEncryptedNFTContracts.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22

33
import { useEffect, useMemo, useState } from "react";
4-
import { LighthouseNFTUI } from "./LighthouseNFTUI";
4+
import { LitEncryptedNFTUI } from "./LitEncryptedNFTUI";
55
import { MintNFTForm } from "./MintNFTForm";
66
import { MintPrivateNFTForm } from "./MintPrivateNFTForm";
77
import { useLocalStorage } from "usehooks-ts";
@@ -11,7 +11,7 @@ import { useAllContracts } from "~~/utils/fil-frame/contractsData";
1111

1212
const selectedContractStorageKey = "FilFrame2.selectedContract";
1313

14-
export function LighthouseNFTContracts() {
14+
export function LitEncryptedNFTContracts() {
1515
const contractsData = useAllContracts();
1616
const contractNames = useMemo(() => Object.keys(contractsData) as ContractName[], [contractsData]);
1717

@@ -85,7 +85,7 @@ export function LighthouseNFTContracts() {
8585
</div>
8686

8787
{contractNames.map(contractName => (
88-
<LighthouseNFTUI
88+
<LitEncryptedNFTUI
8989
key={contractName}
9090
contractName={contractName}
9191
className={contractName === selectedContract ? "" : "hidden"}

packages/nextjs/app/lighthouse/_components/LighthouseNFTUI.tsx renamed to packages/nextjs/app/lit_lighthouse/_components/LitEncryptedNFTUI.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import { useDeployedContractInfo, useNetworkColor } from "~~/hooks/fil-frame";
99
import { useTargetNetwork } from "~~/hooks/fil-frame/useTargetNetwork";
1010
import { ContractName } from "~~/utils/fil-frame/contract";
1111

12-
type LighthouseNFTUIProps = {
12+
type LitEncryptedNFTUIProps = {
1313
contractName: ContractName;
1414
className?: string;
1515
};
1616

1717
/**
1818
* UI component to interface with deployed contracts.
1919
**/
20-
export const LighthouseNFTUI = ({ contractName, className = "" }: LighthouseNFTUIProps) => {
20+
export const LitEncryptedNFTUI = ({ contractName, className = "" }: LitEncryptedNFTUIProps) => {
2121
const [refreshDisplayVariables] = useReducer(value => !value, false);
2222
const { targetNetwork } = useTargetNetwork();
2323
const { data: deployedContractData, isLoading: deployedContractLoading } = useDeployedContractInfo(contractName);

packages/nextjs/app/lighthouse/_components/MintNFTForm.tsx renamed to packages/nextjs/app/lit_lighthouse/_components/MintNFTForm.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import { useAllContracts } from "~~/utils/fil-frame/contractsData";
99
export const MintNFTForm = () => {
1010
const [imageCid, setImageCid] = useState<string | null>(null);
1111
const contractsData = useAllContracts();
12-
// Find the LighthouseNFT contract address
13-
const [LighthouseNFTAddress, Abi] = useMemo(() => {
14-
// Change the contract name to match the contract name in the contractsData object by default it is LighthouseNFT
15-
const lighthouseContract = Object.entries(contractsData).find(([name]) => name === "LighthouseNFT");
16-
return lighthouseContract ? [lighthouseContract[1].address, lighthouseContract[1].abi] : [null, null];
12+
// Find the LitEncryptedNFT contract address
13+
const [LitEncryptedNFTAddress, Abi] = useMemo(() => {
14+
// Change the contract name to match the contract name in the contractsData object by default it is LitEncryptedNFT
15+
const nftContract = Object.entries(contractsData).find(([name]) => name === "LitEncryptedNFT");
16+
return nftContract ? [nftContract[1].address, nftContract[1].abi] : [null, null];
1717
}, [contractsData]);
1818

1919
const handleGetCID = (cid: string) => {
@@ -24,11 +24,11 @@ export const MintNFTForm = () => {
2424
<div className="flex flex-col items-center space-y-4 p-5 w-full bg-base-100 border-base-300 border shadow-md shadow-secondary rounded-3xl px-6 lg:px-8 mb-6 py-4">
2525
<h2 className="text-2xl font-bold">Mint Your NFT</h2>
2626
<LighthouseFileUpload handleGetCID={handleGetCID} acceptMimeType="image/*" />
27-
{imageCid && LighthouseNFTAddress && (
27+
{imageCid && LitEncryptedNFTAddress && (
2828
<WriteContractFunctionForm
2929
abi={Abi}
3030
abiFunction={mintFunction}
31-
contractAddress={LighthouseNFTAddress}
31+
contractAddress={LitEncryptedNFTAddress}
3232
onChange={() => void 0}
3333
functionPropsWithIndexAndValue={[{ index: 0, value: imageCid }]}
3434
/>

packages/nextjs/app/lighthouse/_components/MintPrivateNFTForm.tsx renamed to packages/nextjs/app/lit_lighthouse/_components/MintPrivateNFTForm.tsx

+16-13
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"use client";
22

33
import { useMemo, useState } from "react";
4-
import { getConditions, mintPrivateFunction, useTotalNFTsQuery } from "../utils";
5-
import { LigthouseEnctyptedFileUpload } from "./LighthouseUpload";
4+
import { mintPrivateFunction, useTotalNFTsQuery } from "../utils";
5+
import { LigthouseLitEnctyptedFileUpload } from "./LighthouseUpload";
66
import { WriteContractFunctionForm } from "./WriteContractFunctionForm";
77
import { Hex } from "viem";
88
import { useAccount } from "wagmi";
@@ -12,34 +12,37 @@ export const MintPrivateNFTForm = () => {
1212
const [imageCid, setImageCid] = useState<string | null>(null);
1313
const { chainId } = useAccount();
1414
const contractsData = useAllContracts();
15-
// Find the LighthouseNFT contract address
16-
const [LighthouseNFTAddress, Abi] = useMemo(() => {
17-
// Change the contract name to match the contract name in the contractsData object by default it is LighthouseNFT
18-
const lighthouseContract = Object.entries(contractsData).find(([name]) => name === "LighthouseNFT");
19-
return lighthouseContract ? [lighthouseContract[1].address, lighthouseContract[1].abi] : [null, null];
15+
// Find the LitEncryptedNFT contract address
16+
const [LitEncryptedNFTAddress, Abi] = useMemo(() => {
17+
// Change the contract name to match the contract name in the contractsData object by default it is LitEncryptedNFT
18+
const nftContract = Object.entries(contractsData).find(([name]) => name === "LitEncryptedNFT");
19+
return nftContract ? [nftContract[1].address, nftContract[1].abi] : [null, null];
2020
}, [contractsData]);
2121

2222
const handleGetCID = (cid: string) => {
2323
setImageCid(cid);
2424
};
2525

2626
// Fetch total supply
27-
const { totalNFTs } = useTotalNFTsQuery(LighthouseNFTAddress as Hex, Abi as any);
27+
const { totalNFTs } = useTotalNFTsQuery(LitEncryptedNFTAddress as Hex, Abi as any);
2828
const nextToken = totalNFTs ? Number(totalNFTs) + 1 : 1;
29-
const conditions = getConditions(LighthouseNFTAddress as string, chainId as number, nextToken);
29+
const chain = chainId === 371 ? "filecoin" : "filecoin";
30+
// const conditions = getConditions(LitEncryptedNFTAddress as string, chainId as number, nextToken);
3031
return (
3132
<div className="flex flex-col items-center space-y-4 p-5 w-full bg-base-100 border-base-300 border shadow-md shadow-secondary rounded-3xl px-6 lg:px-8 mb-6 py-4">
3233
<h2 className="text-2xl font-bold">Mint Your Private NFT</h2>
33-
<LigthouseEnctyptedFileUpload
34+
<LigthouseLitEnctyptedFileUpload
3435
handleGetCID={handleGetCID}
3536
acceptMimeType="image/*"
36-
accessControlConditions={{ conditions: conditions.conditions, aggregate: conditions.aggregator }}
37+
tokenId={nextToken}
38+
chain={chain}
39+
contractAddress={LitEncryptedNFTAddress as string}
3740
/>
38-
{imageCid && LighthouseNFTAddress && (
41+
{imageCid && LitEncryptedNFTAddress && (
3942
<WriteContractFunctionForm
4043
abi={Abi}
4144
abiFunction={mintPrivateFunction}
42-
contractAddress={LighthouseNFTAddress}
45+
contractAddress={LitEncryptedNFTAddress}
4346
onChange={() => void 0}
4447
functionPropsWithIndexAndValue={[{ index: 0, value: imageCid }]}
4548
/>

0 commit comments

Comments
 (0)