Skip to content

Commit e4a7bcf

Browse files
committed
refactor: update README and command structure; remove podsi command and adjust tests for consistency
1 parent 9fd9ae8 commit e4a7bcf

File tree

10 files changed

+83
-99
lines changed

10 files changed

+83
-99
lines changed

README.md

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,52 +11,64 @@ 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-
65+
const uploadResponse = await lighthouse.upload(
66+
'/home/cosmos/Desktop/wow.jpg',
67+
'YOUR_API_KEY'
68+
)
69+
```
5870

59-
Refer [GitBook](https://docs.lighthouse.storage/lighthouse-1/)
71+
> Refer to the [GitBook documentation](https://docs.lighthouse.storage/lighthouse-1/) for more details and advanced usage.
6072
6173
## Contributing
6274

src/Commands/index.ts

Lines changed: 0 additions & 7 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

@@ -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
})

src/Lighthouse/tests/uploadBuffer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('uploadBuffer', () => {
2525
await lighthouse.uploadBuffer(image, 'invalid.apiKey')
2626
).data
2727
} catch (error) {
28-
expect(error.message).toBe('Request failed with status code 500')
28+
expect(error.message).toBe('Error: Authentication failed')
2929
}
3030
}, 60000)
3131
})

src/Lighthouse/tests/uploadText.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('uploadText', () => {
2828
await lighthouse.uploadText(text, 'invalid.apiKey', 'sample')
2929
).data
3030
} catch (error) {
31-
expect(error.message).toBe('Request failed with status code 500')
31+
expect(error.message).toBe('Error: Authentication failed')
3232
}
3333
}, 60000)
3434
})

src/Lighthouse/uploadEncrypted/encrypt/file/node.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export default async (
1515
const fs = eval('require')('fs-extra')
1616
const token = 'Bearer ' + apiKey
1717
const endpoint =
18-
lighthouseConfig.lighthouseNode + `/api/v0/add?wrap-with-directory=false&cid-version=${cidVersion}`
18+
lighthouseConfig.lighthouseNode +
19+
`/api/v0/add?wrap-with-directory=false&cid-version=${cidVersion}`
1920
const stats = fs.lstatSync(sourcePath)
2021

2122
if (stats.isFile()) {
@@ -40,21 +41,21 @@ export default async (
4041
})
4142

4243
if (!response.ok) {
43-
const res = (await response.json())
44+
const res = await response.json()
4445
throw new Error(res.error)
4546
}
4647

4748
const responseData = (await response.json()) as any
4849

49-
// const { error } = await saveShards(
50-
// publicKey,
51-
// responseData[0].Hash,
52-
// auth_token,
53-
// keyShards
54-
// )
55-
// if (error) {
56-
// throw new Error('Error encrypting file')
57-
// }
50+
const { error } = await saveShards(
51+
publicKey,
52+
responseData[0].Hash,
53+
auth_token,
54+
keyShards
55+
)
56+
if (error) {
57+
throw new Error('Error encrypting file')
58+
}
5859

5960
return { data: responseData }
6061
} catch (error: any) {
@@ -94,7 +95,7 @@ export default async (
9495
})
9596

9697
if (!response.ok) {
97-
const res = (await response.json())
98+
const res = await response.json()
9899
throw new Error(res.error)
99100
}
100101

src/Lighthouse/uploadEncrypted/encrypt/text/node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default async (
4747

4848
const { error } = await saveShards(
4949
publicKey,
50-
responseData.Hash,
50+
responseData[0].Hash,
5151
signedMessage,
5252
keyShards
5353
)

0 commit comments

Comments
 (0)