Skip to content

Commit

Permalink
Lighthouse docs added (#464)
Browse files Browse the repository at this point in the history
* Lighthouse docs added

* Update mint-nfts-lighthouse.md

* add titles; remove from xcm section

---------

Co-authored-by: Gregory Luneau <greg@astar.network>
Co-authored-by: Megan Skye Phoenix <58894568+meganskye@users.noreply.github.com>
  • Loading branch information
3 people committed Oct 26, 2023
1 parent 43739a4 commit f5e0f23
Show file tree
Hide file tree
Showing 4 changed files with 352 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/build/EVM/precompiles/xcm/xcm.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ XCM.Multilocation memory asset = XCM.Multilocation({

#### Builder Guides

Three builder guides on the subject of EVM XCM are available in Builder section:
Three builder guides on the subject of EVM XCM are available in the Builder section:

- [How to create and interact with a mintable XC20 asset via Solidity smart contract](../../../builder-guides/leverage_parachains/interact_with_xc20.md)
- [Harnessing Crust Network for NFT Minting: A Developer's Guide](../../../builder-guides/leverage_parachains/mint-nfts-crust.md)
Expand Down
214 changes: 214 additions & 0 deletions docs/build/builder-guides/leverage_parachains/lighthouse-encryption.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
---
title: Lighthouse Encryption
---

# Utilizing Lighthouse Encryption on Astar for Enhanced Security: A Developer's Guide

The realm of digital data has grown immensely, both in terms of volume and significance. As the usage of digital assets like NFTs increases, there's a compelling need to ensure that these assets are stored securely and accessibly. This guide introduces a new dimension of security, detailing how to encrypt data using Lighthouse Storage and then store and retrieve it on the Astar Network EVM. The focus is on leveraging Lighthouse Encryption in tandem with the blockchain capabilities of Astar Network.

## Introduction

#### Lighthouse Encryption
With an increasing volume of sensitive and important data being stored online, data encryption has become crucial. Lighthouse offers a robust encryption service, ensuring data remains confidential and secure. Their encryption approach goes beyond traditional methods, making data access seamless yet guarded.

#### Why Lighthouse Encryption?
* **Guarded Yet Accessible**: Lighthouse encryption ensures that while data is securely encrypted, it remains accessible to those with the right credentials.
* **Immutable and Distributed**: Leveraging the decentralization principles of blockchain, Lighthouse ensures that encrypted data remains tamper-proof and spread across a wide network.
* **Developer-Friendly**: Like its storage counterpart, Lighthouse Encryption comes with a suite of developer tools, including SDKs in various languages and a CLI for streamlined operations.

#### Getting Started with Lighthouse Encryption
* Website: https://lighthouse.storage
* Sign into [Files Dapp](https://files.lighthouse.storage/) with your wallet or your GitHub account to start uploading files to Lighthouse.
* Optionally:
* Get [Lighthouse CLI](https://lighthouse-1.gitbook.io/lighthouse-1/cli-tool/overview)
* Get [Lighthouse Javascript SDK](https://lighthouse-1.gitbook.io/lighthouse-1/lighthouse-sdk/overview)
* Get [Python SDK](https://pypi.org/project/lighthouseweb3/)

For this tutorial, we will employ the Lighthouse Javascript SDK to encrypt and decrypt data using Lighthouse.


## Encrypting Data with Lighthouse

Lighthouse provides a simple yet robust solution for encrypting data on the IPFS network.

**Step 1:** **Install the required dependencies:**

```shell
npm install dotenv ethers @lighthouse-web3/sdk
```

**Step 2:** **Use lighthouse-SDK to upload encrypted data on the IPFS and get the Hash:**

*Note: In this example, we are using ES6 so we have to save the file as filename.mjs or define "type": "module", in the package.json file.*

```javascript
import * as dotenv from 'dotenv';
dotenv.config();
import { ethers } from "ethers";
import lighthouse from '@lighthouse-web3/sdk';

const signAuthMessage = async (publicKey, privateKey) => {
const provider = new ethers.JsonRpcProvider();
const signer = new ethers.Wallet(privateKey, provider);
const messageRequested = (await lighthouse.getAuthMessage(publicKey)).data.message;
const signedMessage = await signer.signMessage(messageRequested);
return signedMessage;
}

const deployEncrypted = async () => {
const path = "/mnt/c/Users/ravis/Pictures/Screenshots/flow1.png"; // Provide the absolute path to the file
const apiKey = process.env.API_KEY;
const publicKey = "0xa3c960b3ba29367ecbcaf1430452c6cd7516f588";
const privateKey = process.env.PRIVATE_KEY;
const signedMessage = await signAuthMessage(publicKey, privateKey);

const response = await lighthouse.uploadEncrypted(
path,
apiKey,
publicKey,
signedMessage
);

// Display response
console.log(response);
}
deployEncrypted();
```

**Expected Response:**

```bash
{
data: [{
Name: 'flow1.png',
Hash: 'QmQqfuFH77vsau5xpVHUfJ6mJQgiG8kDmR62rF98iSPRes',
Size: '31735'
}]
}
```

**Step 3:** **Customize the code:**

* Update the `path` variable with the actual absolute path to the file you want to upload.
* Replace `0xa3c960b3ba29367ecbcaf1430452c6cd7516f588` with your own public key.
* Ensure you have the corresponding private key stored in the `PRIVATE_KEY` environment variable.

**Step 4:** **Configure the API key and the Private Key:**

* Create a .env file in your project's root directory.
* Add the following content to the .env file:

```makefile
API_KEY=YOUR_API_KEY
PRIVATE_KEY=YOUR_PRIVATE_KEY
```

* Replace `YOUR_API_KEY` with your actual API key obtained from [Lighthouse API Key Node Application](https://docs.lighthouse.storage/lighthouse-1/lighthouse-sdk/code-examples/nodejs-backend/api-key) or using the [Lighthouse CLI command](https://docs.lighthouse.storage/lighthouse-1/cli-tool/cli-commands/api-key) `lighthouse-web3 api-key --new`.
* Replace `YOUR_PRIVATE_KEY` with your own private key corresponding to the public key used in the code (Can be obtained from the wallet.json file made while [creating a wallet](https://docs.lighthouse.storage/lighthouse-1/cli-tool/cli-commands/create-wallet)).

**Step 5:** **Run the Node.js application to upload the file:**

* In the terminal, while in the `lighthouse-encryption-app` directory, run the following command:

```shell
node app.js
```

## Storing Encrypted Data on Astar Network

Once encrypted, this data can now be stored safely on the Astar Network.

```javascript
async function storeOnAstar(key, encryptedHash) {
// Assuming you have a contract with a setData function to store data
const txResponse = await yourContract.setData(key, encryptedHash);
const txReceipt = await txResponse.wait();

console.log("Data stored successfully on Astar Network!");
}
```

## Retrieving and Decrypting Data

To read back your encrypted data from the Astar Network and decrypt it:

**Step 1: Retrieve data from the Astar Chain:**
```javascript
async function getFromAstar(key) {
// Assuming you have a contract with a setData function to store data
const txResponse = await yourContract.getData(key);

console.log("Data retrieved successfully from Astar Network: ", txResponse);
}
```

**Step 2: Retrieve and Decrypt data from the Lighthouse Storage:**

```javascript

const signAuthMessage = async (publicKey, privateKey) => {
const provider = new ethers.JsonRpcProvider();
const signer = new ethers.Wallet(privateKey, provider);
const messageRequested = (await lighthouse.getAuthMessage(publicKey)).data.message;
const signedMessage = await signer.signMessage(messageRequested);
return signedMessage;
}

const decrypt = async () => {
const cid = txResponse; //Example: 'QmbGN1YcBM25s6Ry9V2iMMsBpDEAPzWRiYQQwCTx7PPXRZ'
const publicKey = "YOUR_PUBLIC_KEY"; //Example: '0xa3c960b3ba29367ecbcaf1430452c6cd7516f588'
const privateKey = process.env.PRIVATE_KEY;

// Get file encryption key
const signedMessage = await signAuthMessage(publicKey, privateKey);
const fileEncryptionKey = await lighthouse.fetchEncryptionKey(
cid,
publicKey,
signedMessage
);

// Decrypt File
const decrypted = await lighthouse.decryptFile(
cid,
fileEncryptionKey.data.key
);

// Save File
fs.createWriteStream("fileName.txt").write(Buffer.from(decrypted));
}

decrypt();
```
---
## Advanced Features of Lighthouse SDK: Access Control & File Sharing

* **Access Control:**
Lighthouse SDK doesn't just stop at encryption. It also provides a range of advanced features, allowing developers to implement various access control mechanisms. Here's a quick look at some of the types of access control conditions supported:

**Types of Access Control conditions:**

1. **NFTs and Tokens**
* **ERC20**: Standard for fungible tokens, allowing a seamless integration for token-based access control.
* **ERC721**: Often used for NFTs, granting unique asset-based access.
* **ERC1155**: A multi-token standard, allowing for both fungible and non-fungible tokens.

2. **Custom Contracts Deployed**: Integration with your custom smart contracts, granting or restricting access based on specific contract conditions.

3. **Native Chain Token (like ETH)**: Implement access control based on native blockchain assets.

4. **Time-based Access**: Grant or restrict access based on specific time constraints, allowing for temporary permissions.

* **Sharing Files Using Lighthouse Node**:
The Lighthouse SDK also provides the ability to share encrypted files with other users. This feature can be especially useful when you want to provide access to a specific piece of data without revealing your encryption keys or compromising security.

**For more in-depth information on implementaion and practical examples, Lighthouse's official documentation is a treasure trove:**

* [Access Control](https://docs.lighthouse.storage/lighthouse-1/lighthouse-sdk/code-examples/nodejs-backend/access-control-node)
* [Access Control Conditions](https://docs.lighthouse.storage/lighthouse-1/lighthouse-sdk/code-examples/access-conditions)
* [Sharing File](https://docs.lighthouse.storage/lighthouse-1/lighthouse-sdk/code-examples/nodejs-backend/share-file-nodejs)

## Conclusion

By harnessing the power of Lighthouse Encryption combined with the Astar Network's decentralized capabilities, developers can ensure that data remains both accessible and confidential. As we move into an era where data is the new gold, tools and practices like these will become fundamental in the evolving digital landscape.

---
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
title: Mint NFTs with Crust
---

# Harnessing Crust Network for NFT Minting: A Developer's Guide

![](https://hackmd.io/_uploads/r12FVSxHn.jpg)
Expand Down
133 changes: 133 additions & 0 deletions docs/build/builder-guides/leverage_parachains/mint-nfts-lighthouse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
---
title: Mint NFTs with Lighthouse
---

# NFT Minting Simplified: A Developer’s Guide to Lighthouse and Astar Network

The world of Non-Fungible Tokens (NFTs) has revolutionized the digital realm, offering unique opportunities for creators and enthusiasts. Entering this domain can be challenging, especially when integrating with blockchain technology. This guide simplifies the process, detailing how to create and manage NFTs using the Astar Network EVM and Lighthouse Storage while leveraging the XCM protocol communication.

## Introduction
#### Lighthouse Storage
In an era defined by digital data, a reliable and enduring file storage solution is of paramount importance. Lighthouse emerges as a front-runner in this domain, offering a storage model designed for the long haul. It uses the miner network and storage capacity of the Filecoin network and the IPFS content-addressing system. Lighthouse's reliance on IPFS ensures widespread file replications across a myriad of Filecoin miners, effectively bolstering data reliability and simplifying the nuances of sustainable, long-term, and perpetual storage.

#### Understanding Lighthouse
Before diving deep into the steps, let's get a clear picture of Lighthouse:

* **Sustainable Storage**: With an eye on the future, Lighthouse's storage model emphasizes longevity and resilience.
* **Encrypted Data**: Developers benefit from storing encrypted data on Lighthouse, paving the way to craft token-gated applications.
* **Developer-Centric**: Lighthouse not only values data security but also ensures ease of integration by offering a variety of SDKs in various languages and a dedicated CLI.

#### Setting Up Lighthouse
* Website: https://lighthouse.storage
* Sign into [Files Dapp](https://files.lighthouse.storage/) with your wallet or your GitHub account to start uploading files to Lighthouse.
* Optionally:
* Get [Lighthouse CLI](https://lighthouse-1.gitbook.io/lighthouse-1/cli-tool/overview)
* Get [Lighthouse Javascript SDK](https://lighthouse-1.gitbook.io/lighthouse-1/lighthouse-sdk/overview)
* Get [Python SDK](https://pypi.org/project/lighthouseweb3/)

In this tutorial we will be using the Lighthouse Javascript SDK to upload a file using Lighthouse.



## Step 1: Setting Up an EVM Wallet
Before crafting your NFT, ensure you have a Web3 wallet ready. This wallet bridges traditional web browsers with the Ethereum blockchain, a renowned platform for NFTs. Popular choices include Metamask, Talisman, and Subwallet.
- Start by connecting your Web3 wallet.

```javascript
async connect() {
const connect = await this.onboard.connectWallet();
this.wallet = await this.onboard.connectedWallet;

if (this.wallet) {
this.provider = new ethers.providers.Web3Provider(this.wallet.provider);
this.signer = this.provider.getSigner();
this.address = await this.signer.getAddress();
this.set();
}

return { connect };
}
```

For a comprehensive understanding of the onboard wallet provider, refer to [this article](https://astar.network/blog/one-small-piece-of-code-one-giant-leap-for-web3-37760/).

## Step 2: Digital Signatures
With a connection established, you'll need to sign a message. This signature is crucial for Lighthouse's API to authenticate your EVM address. Consider it your digital stamp, verifying your blockchain identity.
- Click the "Sign" button to authenticate.

```javascript
async sign() {
this.sig = await this.signer.signMessage(this.address);
}
```

## Step 3: Uploading to Lighthouse - Your First Major Move
With your signature ready, it's time to upload your image and metadata to the Lighthouse network. This decentralized platform ensures your data's safety and accessibility.
- Click the "Upload" button to begin.

```javascript
import * as dotenv from 'dotenv';
dotenv.config();
import lighthouse from '@lighthouse-web3/sdk';

const uploadFile = async () => {
const path = "path/to/your/file"; // Provide the path to the file
const apiKey = process.env.API_KEY;
// Generate the API key from https://files.lighthouse.storage/
//or using CLI (lighthouse-web3 api-key --new)

// Both files and folders are supported by the upload function
const response = await lighthouse.upload(path, apiKey);

console.log(response);
console.log("Visit at: https://gateway.lighthouse.storage/ipfs/" + response.data.Hash);
return `https://gateway.lighthouse.storage/ipfs/${response.data.Hash}`
}

let tokenURI = uploadFile();

```

## Step 4: Minting Your NFT
With your data pinned, you're set to mint your NFT. This step transforms your digital asset into a unique, blockchain-certified NFT.
- Click the "Mint" button to finalize.

```javascript
import * as dotenv from 'dotenv';
dotenv.config();

const abi = [....] //your contract ABI

const contractAddress = process.env.CONTRACT_ADDRESS;
const privateKey = process.env.PRIVATE_KEY;

async mint() {
// Get signer and provider
const provider = new ethers.JsonRpcProvider();
const signer = new ethers.Wallet(privateKey, provider);

const contract = new ethers.Contract(
contractAddress,
abi, //write a smart contract to handle minting of NFT
signer
);

// Mint the NFT
const txResponse = await contract.mintNFT(this.tokenURI);
const txReceipt = await txResponse.wait();
const [transferEvent] = txReceipt.events;
const { tokenId } = transferEvent.args;
console.log("NFT minted successfully!");
console.log(`NFT tokenId: ${tokenId}`);

const tokenURIonchain = await contract.tokenURI(tokenId);
console.log("tokenURI", tokenURIonchain);
}
```

Congratulations on minting your NFT!

## Conclusion
This guide offers a step-by-step introduction to NFT creation and management using the Astar Network EVM and Lighthouse Network. As you familiarize yourself with these steps, you'll be better equipped to delve deeper into the dynamic world of NFTs. Welcome to the digital frontier!

---

0 comments on commit f5e0f23

Please sign in to comment.