Skip to content
Merged
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ yarn.lock
yarn-error.log
dist/
src/coverage/
.DS_Store
80 changes: 45 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Lighthouse <img src="https://img.shields.io/badge/BETA-v0.3.7-green"/>
# Lighthouse <img src="https://img.shields.io/badge/v0.4.0-green"/>

Lighthouse is a permanent decentralized file storage protocol that allows the ability to pay once and store forever. While traditionally, users need to repeatedly keep track and pay for their storage after every fixed amount of time, Lighthouse manages this for them and makes sure that user files are stored forever. The aim is to move users from a rent-based cost model where they are renting their own files on cloud storage to a permanent ownership model. It is built on top of IPFS, Filecoin, and Polygon. It uses the existing miner network and storage capacity of the filecoin network.

Expand All @@ -11,51 +11,61 @@ npm install -g @lighthouse-web3/sdk
## CLI Usage

```bash
# create-wallet
lighthouse-web3 create-wallet

# import-wallet
lighthouse-web3 import-wallet --key <private_key>

# wallet-forget
lighthouse-web3 wallet-forget

# api-key
lighthouse-web3 api-key --new

# balance
lighthouse-web3 balance

# upload
lighthouse-web3 upload <path>

# status
lighthouse-web3 status <cid>

# get-uploads
lighthouse-web3 get-uploads

# wallet
lighthouse-web3 wallet
# Wallet management
lighthouse-web3 create-wallet # Create a new wallet
lighthouse-web3 import-wallet --key <private_key> # Import an existing wallet
lighthouse-web3 wallet-forget # Remove previously saved wallet
lighthouse-web3 reset-password # Change password of your wallet
lighthouse-web3 wallet # Returns wallet public address

# API Key management
lighthouse-web3 api-key --new # Generate a new API key
lighthouse-web3 api-key --import <key> # Import an existing API key

# Storage and uploads
lighthouse-web3 upload <path> # Upload a file
lighthouse-web3 upload-encrypted <path> # Upload a file encrypted
lighthouse-web3 decrypt-file <cid> # Decrypt and download a file

# Data usage and balance
lighthouse-web3 balance # Get your data usage

# File and deal status
lighthouse-web3 deal-status <cid> # Get filecoin deal status of a CID

# File management
lighthouse-web3 get-uploads # Get details of files uploaded

# Sharing and access control
lighthouse-web3 share-file <cid> <address> # Share access to another user
lighthouse-web3 revoke-access <cid> <address> # Revoke access on a file

# IPNS (InterPlanetary Naming System)
lighthouse-web3 ipns --generate-key # Generate IPNS Key
lighthouse-web3 ipns --publish --cid <cid> --key <key> # Publish CID to IPNS
lighthouse-web3 ipns --list # List all IPNS keys
lighthouse-web3 ipns --remove <key> # Remove an IPNS key

# Proof of Data Segment Inclusion (PODSI)
lighthouse-web3 podsi <cid> # Show Proof of Data Segment Inclusion for a CID
```

## NodeJs Example

```javascript
import lighthouse from "@lighthouse-web3/sdk";
import lighthouse from '@lighthouse-web3/sdk'

// Create wallet
const wallet = await lighthouse.createWallet(
"Password for wallet encryption"
);
const wallet = await lighthouse.createWallet('Password for wallet encryption')

// Get wallet balance
const balance = await lighthouse.getBalance(publicKey);
const balance = await lighthouse.getBalance(wallet.data.publicKey)

// Upload File
const uploadResponse = await lighthouse.upload('/home/cosmos/Desktop/wow.jpg', 'YOUR_API_KEY');

```
const uploadResponse = await lighthouse.upload(
'/home/cosmos/Desktop/wow.jpg',
'YOUR_API_KEY'
)

> Refer [GitBook](https://docs.lighthouse.storage/lighthouse-1/)

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lighthouse-web3/sdk",
"version": "0.3.7",
"version": "0.4.0",
"description": "NPM package and CLI tool to interact with lighthouse protocol",
"main": "./dist/Lighthouse/index.js",
"types": "./dist/Lighthouse/index.d.ts",
Expand Down
14 changes: 5 additions & 9 deletions src/Commands/deal-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ const showResponse = (cid: string, dealStatus: any) => {
console.log(
yellow('\r\nCID:') +
Array(9).fill('\xa0').join('') +
cid +
yellow('\r\nSize:') +
Array(8).fill('\xa0').join('') +
bytesToSize(dealStatus[0]['content']) +
'\r\n'
cid
)

console.log(
Expand All @@ -21,19 +17,19 @@ const showResponse = (cid: string, dealStatus: any) => {
)

for (let i = 0; i < dealStatus.length; i++) {
const gap = 10 + (8 - dealStatus[i]['miner'].length)
const gap = 10 + (8 - dealStatus[i]['Provider'].length)
console.log(
Array(20).fill('\xa0').join('') +
dealStatus[i]['miner'] +
dealStatus[i]['Provider'] +
Array(gap).fill('\xa0').join('') +
dealStatus[i]['dealId']
dealStatus[i]['DealID']
)
}
console.log(
green('\r\nView deals at filfox URL:\r\n') +
Array(4).fill('\xa0').join('') +
'https://filfox.info/en/deal/' +
dealStatus[0]['dealId']
dealStatus[0]['DealID']
)
}

Expand Down
9 changes: 1 addition & 8 deletions src/Commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import importWallet from './import-wallet'
import revokeAccess from './revoke-access'
import resetPassword from './reset-password'
import uploadEncrypted from './upload-encrypted'
import podsi from './podsi'

const widgets = new Command('lighthouse-web3')

Expand Down Expand Up @@ -72,7 +71,7 @@ Command.prototype.helpInformation = function (context: any) {
}

widgets.addHelpText('before', 'Welcome to lighthouse-web3')
widgets.version('0.3.7')
widgets.version('0.4.0')

widgets
.command('wallet')
Expand Down Expand Up @@ -116,12 +115,6 @@ widgets
.description('IPNS service')
.action(ipns)

widgets
.command('podsi')
.description('Show Proof of data segment inclusion')
.argument('<cid>', 'CID of the file previously uploaded')
.action(podsi)

widgets
.command('upload')
.description('Upload a file')
Expand Down
8 changes: 3 additions & 5 deletions src/Lighthouse/tests/dealStatus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ describe('dealStatus', () => {
'QmaiauHSgTDMy2NtLbsygL3iKmLXBqHf39SBA1nAQFSSey'
)
).data

expect(response[0]).toHaveProperty('dealStatus')
expect(response[0]).toHaveProperty('dealUUID')
expect(response[0]).toHaveProperty('dealId')
expect(response[0]).toHaveProperty('miner')

expect(response[0]).toHaveProperty('DealID')
expect(response[0]).toHaveProperty('Provider')
}, 20000)

it('should not retrieve deal status when invalid CID provided', async () => {
Expand Down
28 changes: 16 additions & 12 deletions src/Lighthouse/tests/encryption.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,23 @@ const signAuthMessage = async (privateKey: string) => {
describe('encryption', () => {
describe('getAuthMessage', () => {
it('should get auth message when valid public key is provided', async () => {
console.log('testing getAuthMessage')
const response = await lighthouse.getAuthMessage(
'0x1Ec09D4B3Cb565b7CCe2eEAf71CC90c9b46c5c26'
)
expect(response.data.message).toMatch(
/^Please sign this message to prove/
)
}, 60000)
}, 6000)

it('should not get auth message when invalid public key is provided', async () => {
try {
console.log('testing getAuthMessage with invalid public key')
const response = await lighthouse.getAuthMessage('invalidPublicKey')
} catch (error) {
expect(error.message).toBe('Invalid public Key')
}
}, 60000)
}, 6000)
})
describe('fetchEncryptionKey', () => {
const publicKey = '0xa3c960b3ba29367ecbcaf1430452c6cd7516f588'
Expand All @@ -36,17 +38,19 @@ describe('encryption', () => {
const cid = 'QmVkHgHnYVUfvTXsaJisHRgc89zsrgVL6ATh9mSiegRYrX'

it('should fetch encryption key when correct public-private key pair is provided', async () => {
console.log('testing fetchEncryptionKey')
const signed_message = await signAuthMessage(privateKey)
const response = await lighthouse.fetchEncryptionKey(
cid,
publicKey,
signed_message
)
expect(typeof response.data.key).toBe('string')
}, 80000)
}, 8000)

it('should not fetch encryption key when incorrect public-private key pair is provided', async () => {
try {
console.log('testing fetchEncryptionKey with incorrect key pair')
const randomPublicKey = '0x1ccEF158Dcbe6643F1cC577F236af79993F4D066'
const signed_message = await signAuthMessage(privateKey)
const response = await lighthouse.fetchEncryptionKey(
Expand All @@ -57,7 +61,7 @@ describe('encryption', () => {
} catch (error) {
expect(typeof error.message).toBe('string')
}
}, 60000)
}, 6000)

it('should not fetch encryption key when incorrect CID is provided', async () => {
try {
Expand All @@ -72,7 +76,7 @@ describe('encryption', () => {
} catch (error) {
expect(error).toBe('cid not found')
}
}, 60000)
}, 6000)

it('should not fetch encryption key when incorrect signature is provided', async () => {
try {
Expand All @@ -86,7 +90,7 @@ describe('encryption', () => {
} catch (error) {
expect(error.message).toBe('Invalid Signature')
}
}, 60000)
}, 6000)
})
describe('shareFile', () => {
const publicKey = '0x969e19A952A9aeF004e4F711eE481D72A59470B1'
Expand All @@ -105,7 +109,7 @@ describe('encryption', () => {
expect(response.data.cid).toEqual(cid)
expect(response.data.shareTo).toEqual(shareTo)
expect(response.data.status).toBe('Success')
}, 60000)
}, 10000)

it('should deny access for sharing file uploaded by other account', async () => {
try {
Expand All @@ -118,9 +122,9 @@ describe('encryption', () => {
signed_message
)
} catch (error) {
expect(error.message).toEqual('Access Denied')
expect(error.message.message.message).toEqual('access denied')
}
}, 60000)
}, 10000)
})
describe('applyAccessCondition', () => {
const publicKey = '0x969e19A952A9aeF004e4F711eE481D72A59470B1'
Expand Down Expand Up @@ -162,7 +166,7 @@ describe('encryption', () => {
)
expect(response.data.status).toEqual('Success')
expect(response.data.cid).toEqual(cid)
}, 60000)
}, 10000)
})
describe('revokeFileAccess', () => {
it('should revoke file access to provided public address', async () => {
Expand All @@ -182,7 +186,7 @@ describe('encryption', () => {
expect(response.data.cid).toEqual(cid)
expect(response.data.status).toEqual('Success')
expect(response.data.revokeTo).toEqual(revokeTo)
}, 20000)
}, 10000)
})
describe('getAccessConditions', () => {
it('should retrieve access conditions from provided cid', async () => {
Expand All @@ -194,6 +198,6 @@ describe('encryption', () => {
expect(response.data).toHaveProperty('conditions')
expect(response.data).toHaveProperty('sharedTo')
expect(response.data.cid).toEqual(cid)
}, 20000)
}, 10000)
})
})
23 changes: 0 additions & 23 deletions src/Lighthouse/tests/podsi.test.ts

This file was deleted.

5 changes: 2 additions & 3 deletions src/Lighthouse/tests/upload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ describe('uploadFiles', () => {

it('should upload folder to ipfs when correct path is provided', async () => {
const path = resolve(process.cwd(), 'src/Lighthouse/tests/testImages')
const full_deployResponse = (await lighthouse.upload(path, apiKey))
.data
const full_deployResponse = (await lighthouse.upload(path, apiKey)).data

const deployResponse = full_deployResponse
expect(deployResponse).toHaveProperty('Name')
Expand Down Expand Up @@ -54,7 +53,7 @@ describe('uploadFiles', () => {
)
await lighthouse.upload(path, 'random apiKey')
} catch (error) {
expect(error.message).toBe('Request failed with status code 500')
expect(error.message).toBe('Error: Authentication failed')
}
}, 60000)
})
2 changes: 1 addition & 1 deletion src/Lighthouse/tests/uploadBuffer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('uploadBuffer', () => {
await lighthouse.uploadBuffer(image, 'invalid.apiKey')
).data
} catch (error) {
expect(error.message).toBe('Request failed with status code 500')
expect(error.message).toBe('Error: Authentication failed')
}
}, 60000)
})
Loading
Loading