Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Lighthouse <img src="https://img.shields.io/badge/v0.4.6-green"/>
# Lighthouse <img src="https://img.shields.io/badge/v0.4.7-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 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.4.6",
"version": "0.4.7",
"description": "NPM package and CLI tool to interact with lighthouse protocol",
"main": "./dist/Lighthouse/index.js",
"types": "./dist/Lighthouse/index.d.ts",
Expand Down
9 changes: 8 additions & 1 deletion src/Commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import shareFile from './share-file'
import getUploads from './get-uploads'
import deleteFile from './delete-file'
import dealStatus from './deal-status'
import walrusBlobs from './walrus-blobs'
import decryptFile from './decrypt-file'
import createWallet from './create-wallet'
import walletForget from './wallet-forget'
Expand Down Expand Up @@ -72,7 +73,7 @@ Command.prototype.helpInformation = function (context: any) {
}

widgets.addHelpText('before', 'Welcome to lighthouse-web3')
widgets.version('0.4.6')
widgets.version('0.4.7')

widgets
.command('wallet')
Expand Down Expand Up @@ -160,6 +161,12 @@ widgets
.description('Get filecoin deal status of a CID')
.action(dealStatus)

widgets
.command('walrus-blobs')
.argument('<cid>', 'File Cid')
.description('Get walrus blob IDs for a CID')
.action(walrusBlobs)

widgets
.command('get-uploads')
.description('Get details of file uploaded')
Expand Down
36 changes: 36 additions & 0 deletions src/Commands/walrus-blobs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { yellow, red } from 'kleur'
import lighthouse from '../Lighthouse'

export default async function (cid: string) {
try {
if (!cid) {
throw new Error('Please provide a CID.')
}

const { blobIds } = await lighthouse.walrusBlobs(cid)

console.log(
yellow('\r\nCID:') + Array(9).fill('\xa0').join('') + cid
)

if (blobIds.length === 0) {
console.log(yellow('\r\nNo walrus blobs found for this CID'))
return
}

console.log(
'\r\n' +
Array(4).fill('\xa0').join('') +
yellow('Blob ID')
)

for (let i = 0; i < blobIds.length; i++) {
console.log(
Array(4).fill('\xa0').join('') + blobIds[i] + '\r\n'
)
}
} catch (error: any) {
console.log(red(error.message))
process.exit(0)
}
}
40 changes: 40 additions & 0 deletions src/Lighthouse/deleteFileWalrus/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { lighthouseConfig } from '../../lighthouse.config'

export type deleteFileResponseType = {
data: {
message: string
}
}

export default async (
authToken: string,
fileId: string
): Promise<deleteFileResponseType> => {
try {
const response = await fetch(
`${lighthouseConfig.lighthouseAPI}/api/user/delete_file_walrus?id=${fileId}`,
{
method: 'DELETE',
headers: {
Authorization: `Bearer ${authToken}`,
'Content-Type': 'application/json',
},
}
)

if (!response.ok) {
throw new Error(`Request failed with status code ${response.status}`)
}

const result = (await response.json()) as any
/*
Example response:
{
"message": "File deleted successfully."
}
*/
return { data: result }
} catch (error: any) {
throw new Error(error.message)
}
}
5 changes: 3 additions & 2 deletions src/Lighthouse/getUploads/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ export type uploadsResponseType = {

export default async (
authToken: string,
lastKey: string | null = null
lastKey: string | null = null,
fileType: string = 'all'
): Promise<uploadsResponseType> => {
try {
const response = await fetch(
lighthouseConfig.lighthouseAPI +
`/api/user/files_uploaded?lastKey=${lastKey}`,
`/api/user/files_uploaded?lastKey=${lastKey}&fileType=${fileType}`,
{
headers: {
Authorization: `Bearer ${authToken}`,
Expand Down
7 changes: 6 additions & 1 deletion src/Lighthouse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import getUploads from './getUploads'
import getFileInfo from './getFileInfo'
import createWallet from './createWallet'
import deleteFile from './deleteFile'

import walrusBlobs from './walrusBlobs'
import deleteFileWalrus from './deleteFileWalrus'
import shareFile from './encryption/shareFile'
import getAuthMessage from './encryption/getAuthMessage'
import revokeFileAccess from './encryption/revokeFileAccess'
Expand Down Expand Up @@ -53,6 +54,8 @@ export {
getAllKeys,
removeKey,
deleteFile,
walrusBlobs,
deleteFileWalrus,
}

export default {
Expand Down Expand Up @@ -81,4 +84,6 @@ export default {
getAllKeys,
removeKey,
deleteFile,
walrusBlobs,
deleteFileWalrus,
}
21 changes: 21 additions & 0 deletions src/Lighthouse/walrusBlobs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { lighthouseConfig } from '../../lighthouse.config'

export type walrusBlobsResponse = {
blobIds: string[]
}

export default async (cid: string): Promise<walrusBlobsResponse> => {
try {
const response = await fetch(
`${lighthouseConfig.lighthouseAPI}/api/lighthouse/walrus_blobs?cid=${cid}`
)
if (!response.ok) {
throw new Error(`Request failed with status code ${response.status}`)
}
const walrusBlobs: walrusBlobsResponse = (await response.json()) as walrusBlobsResponse

return { blobIds: walrusBlobs.blobIds }
} catch (error: any) {
throw new Error(error.message)
}
}
Loading