Skip to content

Commit a0aa21d

Browse files
authored
Merge pull request #121 from lighthouse-web3/v0.4.0
V0.4.0
2 parents f384c27 + 22a80d7 commit a0aa21d

28 files changed

+167
-224
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ yarn.lock
3434
yarn-error.log
3535
dist/
3636
src/coverage/
37+
.DS_Store

README.md

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Lighthouse <img src="https://img.shields.io/badge/BETA-v0.3.7-green"/>
1+
# Lighthouse <img src="https://img.shields.io/badge/v0.4.0-green"/>
22

33
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.
44

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

1313
```bash
14-
# create-wallet
15-
lighthouse-web3 create-wallet
16-
17-
# import-wallet
18-
lighthouse-web3 import-wallet --key <private_key>
19-
20-
# wallet-forget
21-
lighthouse-web3 wallet-forget
22-
23-
# api-key
24-
lighthouse-web3 api-key --new
25-
26-
# balance
27-
lighthouse-web3 balance
28-
29-
# upload
30-
lighthouse-web3 upload <path>
31-
32-
# status
33-
lighthouse-web3 status <cid>
34-
35-
# get-uploads
36-
lighthouse-web3 get-uploads
37-
38-
# wallet
39-
lighthouse-web3 wallet
14+
# Wallet management
15+
lighthouse-web3 create-wallet # Create a new wallet
16+
lighthouse-web3 import-wallet --key <private_key> # Import an existing wallet
17+
lighthouse-web3 wallet-forget # Remove previously saved wallet
18+
lighthouse-web3 reset-password # Change password of your wallet
19+
lighthouse-web3 wallet # Returns wallet public address
20+
21+
# API Key management
22+
lighthouse-web3 api-key --new # Generate a new API key
23+
lighthouse-web3 api-key --import <key> # Import an existing API key
24+
25+
# Storage and uploads
26+
lighthouse-web3 upload <path> # Upload a file
27+
lighthouse-web3 upload-encrypted <path> # Upload a file encrypted
28+
lighthouse-web3 decrypt-file <cid> # Decrypt and download a file
29+
30+
# Data usage and balance
31+
lighthouse-web3 balance # Get your data usage
32+
33+
# File and deal status
34+
lighthouse-web3 deal-status <cid> # Get filecoin deal status of a CID
35+
36+
# File management
37+
lighthouse-web3 get-uploads # Get details of files uploaded
38+
39+
# Sharing and access control
40+
lighthouse-web3 share-file <cid> <address> # Share access to another user
41+
lighthouse-web3 revoke-access <cid> <address> # Revoke access on a file
42+
43+
# IPNS (InterPlanetary Naming System)
44+
lighthouse-web3 ipns --generate-key # Generate IPNS Key
45+
lighthouse-web3 ipns --publish --cid <cid> --key <key> # Publish CID to IPNS
46+
lighthouse-web3 ipns --list # List all IPNS keys
47+
lighthouse-web3 ipns --remove <key> # Remove an IPNS key
48+
49+
# Proof of Data Segment Inclusion (PODSI)
50+
lighthouse-web3 podsi <cid> # Show Proof of Data Segment Inclusion for a CID
4051
```
4152

4253
## NodeJs Example
4354

4455
```javascript
45-
import lighthouse from "@lighthouse-web3/sdk";
56+
import lighthouse from '@lighthouse-web3/sdk'
4657

4758
// Create wallet
48-
const wallet = await lighthouse.createWallet(
49-
"Password for wallet encryption"
50-
);
59+
const wallet = await lighthouse.createWallet('Password for wallet encryption')
5160

5261
// Get wallet balance
53-
const balance = await lighthouse.getBalance(publicKey);
62+
const balance = await lighthouse.getBalance(wallet.data.publicKey)
5463

5564
// Upload File
56-
const uploadResponse = await lighthouse.upload('/home/cosmos/Desktop/wow.jpg', 'YOUR_API_KEY');
57-
58-
```
65+
const uploadResponse = await lighthouse.upload(
66+
'/home/cosmos/Desktop/wow.jpg',
67+
'YOUR_API_KEY'
68+
)
5969

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

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lighthouse-web3/sdk",
3-
"version": "0.3.7",
3+
"version": "0.4.0",
44
"description": "NPM package and CLI tool to interact with lighthouse protocol",
55
"main": "./dist/Lighthouse/index.js",
66
"types": "./dist/Lighthouse/index.d.ts",

src/Commands/deal-status.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ const showResponse = (cid: string, dealStatus: any) => {
66
console.log(
77
yellow('\r\nCID:') +
88
Array(9).fill('\xa0').join('') +
9-
cid +
10-
yellow('\r\nSize:') +
11-
Array(8).fill('\xa0').join('') +
12-
bytesToSize(dealStatus[0]['content']) +
13-
'\r\n'
9+
cid
1410
)
1511

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

2319
for (let i = 0; i < dealStatus.length; i++) {
24-
const gap = 10 + (8 - dealStatus[i]['miner'].length)
20+
const gap = 10 + (8 - dealStatus[i]['Provider'].length)
2521
console.log(
2622
Array(20).fill('\xa0').join('') +
27-
dealStatus[i]['miner'] +
23+
dealStatus[i]['Provider'] +
2824
Array(gap).fill('\xa0').join('') +
29-
dealStatus[i]['dealId']
25+
dealStatus[i]['DealID']
3026
)
3127
}
3228
console.log(
3329
green('\r\nView deals at filfox URL:\r\n') +
3430
Array(4).fill('\xa0').join('') +
3531
'https://filfox.info/en/deal/' +
36-
dealStatus[0]['dealId']
32+
dealStatus[0]['DealID']
3733
)
3834
}
3935

src/Commands/index.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import importWallet from './import-wallet'
1717
import revokeAccess from './revoke-access'
1818
import resetPassword from './reset-password'
1919
import uploadEncrypted from './upload-encrypted'
20-
import podsi from './podsi'
2120

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

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

7473
widgets.addHelpText('before', 'Welcome to lighthouse-web3')
75-
widgets.version('0.3.7')
74+
widgets.version('0.4.0')
7675

7776
widgets
7877
.command('wallet')
@@ -116,12 +115,6 @@ widgets
116115
.description('IPNS service')
117116
.action(ipns)
118117

119-
widgets
120-
.command('podsi')
121-
.description('Show Proof of data segment inclusion')
122-
.argument('<cid>', 'CID of the file previously uploaded')
123-
.action(podsi)
124-
125118
widgets
126119
.command('upload')
127120
.description('Upload a file')

src/Lighthouse/tests/dealStatus.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ describe('dealStatus', () => {
77
'QmaiauHSgTDMy2NtLbsygL3iKmLXBqHf39SBA1nAQFSSey'
88
)
99
).data
10-
11-
expect(response[0]).toHaveProperty('dealStatus')
12-
expect(response[0]).toHaveProperty('dealUUID')
13-
expect(response[0]).toHaveProperty('dealId')
14-
expect(response[0]).toHaveProperty('miner')
10+
11+
expect(response[0]).toHaveProperty('DealID')
12+
expect(response[0]).toHaveProperty('Provider')
1513
}, 20000)
1614

1715
it('should not retrieve deal status when invalid CID provided', async () => {

src/Lighthouse/tests/encryption.test.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,23 @@ const signAuthMessage = async (privateKey: string) => {
1313
describe('encryption', () => {
1414
describe('getAuthMessage', () => {
1515
it('should get auth message when valid public key is provided', async () => {
16+
console.log('testing getAuthMessage')
1617
const response = await lighthouse.getAuthMessage(
1718
'0x1Ec09D4B3Cb565b7CCe2eEAf71CC90c9b46c5c26'
1819
)
1920
expect(response.data.message).toMatch(
2021
/^Please sign this message to prove/
2122
)
22-
}, 60000)
23+
}, 6000)
2324

2425
it('should not get auth message when invalid public key is provided', async () => {
2526
try {
27+
console.log('testing getAuthMessage with invalid public key')
2628
const response = await lighthouse.getAuthMessage('invalidPublicKey')
2729
} catch (error) {
2830
expect(error.message).toBe('Invalid public Key')
2931
}
30-
}, 60000)
32+
}, 6000)
3133
})
3234
describe('fetchEncryptionKey', () => {
3335
const publicKey = '0xa3c960b3ba29367ecbcaf1430452c6cd7516f588'
@@ -36,17 +38,19 @@ describe('encryption', () => {
3638
const cid = 'QmVkHgHnYVUfvTXsaJisHRgc89zsrgVL6ATh9mSiegRYrX'
3739

3840
it('should fetch encryption key when correct public-private key pair is provided', async () => {
41+
console.log('testing fetchEncryptionKey')
3942
const signed_message = await signAuthMessage(privateKey)
4043
const response = await lighthouse.fetchEncryptionKey(
4144
cid,
4245
publicKey,
4346
signed_message
4447
)
4548
expect(typeof response.data.key).toBe('string')
46-
}, 80000)
49+
}, 8000)
4750

4851
it('should not fetch encryption key when incorrect public-private key pair is provided', async () => {
4952
try {
53+
console.log('testing fetchEncryptionKey with incorrect key pair')
5054
const randomPublicKey = '0x1ccEF158Dcbe6643F1cC577F236af79993F4D066'
5155
const signed_message = await signAuthMessage(privateKey)
5256
const response = await lighthouse.fetchEncryptionKey(
@@ -57,7 +61,7 @@ describe('encryption', () => {
5761
} catch (error) {
5862
expect(typeof error.message).toBe('string')
5963
}
60-
}, 60000)
64+
}, 6000)
6165

6266
it('should not fetch encryption key when incorrect CID is provided', async () => {
6367
try {
@@ -72,7 +76,7 @@ describe('encryption', () => {
7276
} catch (error) {
7377
expect(error).toBe('cid not found')
7478
}
75-
}, 60000)
79+
}, 6000)
7680

7781
it('should not fetch encryption key when incorrect signature is provided', async () => {
7882
try {
@@ -86,7 +90,7 @@ describe('encryption', () => {
8690
} catch (error) {
8791
expect(error.message).toBe('Invalid Signature')
8892
}
89-
}, 60000)
93+
}, 6000)
9094
})
9195
describe('shareFile', () => {
9296
const publicKey = '0x969e19A952A9aeF004e4F711eE481D72A59470B1'
@@ -105,7 +109,7 @@ describe('encryption', () => {
105109
expect(response.data.cid).toEqual(cid)
106110
expect(response.data.shareTo).toEqual(shareTo)
107111
expect(response.data.status).toBe('Success')
108-
}, 60000)
112+
}, 10000)
109113

110114
it('should deny access for sharing file uploaded by other account', async () => {
111115
try {
@@ -118,9 +122,9 @@ describe('encryption', () => {
118122
signed_message
119123
)
120124
} catch (error) {
121-
expect(error.message).toEqual('Access Denied')
125+
expect(error.message.message.message).toEqual('access denied')
122126
}
123-
}, 60000)
127+
}, 10000)
124128
})
125129
describe('applyAccessCondition', () => {
126130
const publicKey = '0x969e19A952A9aeF004e4F711eE481D72A59470B1'
@@ -162,7 +166,7 @@ describe('encryption', () => {
162166
)
163167
expect(response.data.status).toEqual('Success')
164168
expect(response.data.cid).toEqual(cid)
165-
}, 60000)
169+
}, 10000)
166170
})
167171
describe('revokeFileAccess', () => {
168172
it('should revoke file access to provided public address', async () => {
@@ -182,7 +186,7 @@ describe('encryption', () => {
182186
expect(response.data.cid).toEqual(cid)
183187
expect(response.data.status).toEqual('Success')
184188
expect(response.data.revokeTo).toEqual(revokeTo)
185-
}, 20000)
189+
}, 10000)
186190
})
187191
describe('getAccessConditions', () => {
188192
it('should retrieve access conditions from provided cid', async () => {
@@ -194,6 +198,6 @@ describe('encryption', () => {
194198
expect(response.data).toHaveProperty('conditions')
195199
expect(response.data).toHaveProperty('sharedTo')
196200
expect(response.data.cid).toEqual(cid)
197-
}, 20000)
201+
}, 10000)
198202
})
199203
})

src/Lighthouse/tests/podsi.test.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/Lighthouse/tests/upload.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ describe('uploadFiles', () => {
2424

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

3029
const deployResponse = full_deployResponse
3130
expect(deployResponse).toHaveProperty('Name')
@@ -54,7 +53,7 @@ describe('uploadFiles', () => {
5453
)
5554
await lighthouse.upload(path, 'random apiKey')
5655
} catch (error) {
57-
expect(error.message).toBe('Request failed with status code 500')
56+
expect(error.message).toBe('Error: Authentication failed')
5857
}
5958
}, 60000)
6059
})

0 commit comments

Comments
 (0)