From e821563c846a6e286309fbe58c8e8d06c41aa7ca Mon Sep 17 00:00:00 2001 From: Vanssh-k Date: Tue, 1 Apr 2025 01:34:01 +0530 Subject: [PATCH 01/14] Updated parsing of the encrypted response --- src/Lighthouse/uploadEncrypted/encrypt/file/node.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Lighthouse/uploadEncrypted/encrypt/file/node.ts b/src/Lighthouse/uploadEncrypted/encrypt/file/node.ts index 3ffa2e8..9d7dbb3 100644 --- a/src/Lighthouse/uploadEncrypted/encrypt/file/node.ts +++ b/src/Lighthouse/uploadEncrypted/encrypt/file/node.ts @@ -96,7 +96,14 @@ export default async ( } const responseText = await response.text() - const jsondata = JSON.parse(responseText) as IFileUploadedResponse[] + let jsondata: IFileUploadedResponse[] = [] + + const match = responseText.match(/\[.*\]$/s) + if (match) { + jsondata = JSON.parse(match[0]) + } else { + throw new Error('No JSON array found in response') + } const savedKey = await Promise.all( jsondata.map(async (data) => { From 54077429f6ccd335904f552955c1140516503ad9 Mon Sep 17 00:00:00 2001 From: Vanssh-k Date: Wed, 14 May 2025 02:12:50 +0530 Subject: [PATCH 02/14] added support for uploadcar --- src/Lighthouse/index.ts | 3 ++ src/Lighthouse/upload/carfile/browser.ts | 54 ++++++++++++++++++++++++ src/Lighthouse/upload/carfile/index.ts | 41 ++++++++++++++++++ src/Lighthouse/upload/carfile/node.ts | 49 +++++++++++++++++++++ 4 files changed, 147 insertions(+) create mode 100644 src/Lighthouse/upload/carfile/browser.ts create mode 100644 src/Lighthouse/upload/carfile/index.ts create mode 100644 src/Lighthouse/upload/carfile/node.ts diff --git a/src/Lighthouse/index.ts b/src/Lighthouse/index.ts index 1ab2806..1e4c60e 100644 --- a/src/Lighthouse/index.ts +++ b/src/Lighthouse/index.ts @@ -21,6 +21,7 @@ import getAccessConditions from './encryption/getAccessConditions' // Upload import upload from './upload/files' +import uploadCar from './upload/carfile' import uploadText from './upload/text' import uploadBuffer from './upload/buffer' import decryptFile from './uploadEncrypted/decrypt' @@ -54,6 +55,7 @@ export { applyAccessCondition, getAccessConditions, upload, + uploadCar, uploadText, uploadBuffer, uploadEncrypted, @@ -84,6 +86,7 @@ export default { applyAccessCondition, getAccessConditions, upload, + uploadCar, uploadText, uploadBuffer, uploadEncrypted, diff --git a/src/Lighthouse/upload/carfile/browser.ts b/src/Lighthouse/upload/carfile/browser.ts new file mode 100644 index 0000000..6bc3aa1 --- /dev/null +++ b/src/Lighthouse/upload/carfile/browser.ts @@ -0,0 +1,54 @@ +/* istanbul ignore file */ +import { lighthouseConfig } from '../../../lighthouse.config' +import { DealParameters, IUploadProgressCallback } from '../../../types' +import { fetchWithTimeout } from '../../utils/util' + +export default async ( + carFile: File, + apiKey: string, + dealParameters?: DealParameters, + uploadProgressCallback?: (data: IUploadProgressCallback) => void +): Promise => { + try { + const endpoint = lighthouseConfig.lighthouseNode + `/api/v0/dag/import` + const token = 'Bearer ' + apiKey + + const formData = new FormData() + formData.append('file', carFile) + + const headers = new Headers({ + Authorization: token, + 'X-Deal-Parameter': dealParameters + ? JSON.stringify(dealParameters) + : 'null', + }) + + const response = uploadProgressCallback + ? await fetchWithTimeout(endpoint, { + method: 'POST', + body: formData, + headers: headers, + timeout: 7200000, // 2 hour timeout + onProgress: (progress) => { + uploadProgressCallback({ + progress: progress, + }) + }, + }) + : await fetchWithTimeout(endpoint, { + method: 'POST', + body: formData, + headers: headers, + timeout: 7200000, + }) + + if (!response.ok) { + throw new Error(`CAR upload failed: ${response.status}`) + } + + const res = await response.json() + return { data: res } + } catch (error: any) { + throw new Error(error?.message) + } +} diff --git a/src/Lighthouse/upload/carfile/index.ts b/src/Lighthouse/upload/carfile/index.ts new file mode 100644 index 0000000..56d11ea --- /dev/null +++ b/src/Lighthouse/upload/carfile/index.ts @@ -0,0 +1,41 @@ +import uploadCarFile from './node' +import uploadCarFileBrowser from './browser' +import { DealParameters, IUploadProgressCallback } from '../../../types' + +// Type overloads for the function +async function uploadCarFiles( + path: string, + apiKey: string, + dealParameters?: DealParameters, + uploadProgressCallback?: (data: IUploadProgressCallback) => void +): Promise<{ cid: string }> + +async function uploadCarFiles( + path: File, + apiKey: string, + dealParameters?: DealParameters, + uploadProgressCallback?: (data: IUploadProgressCallback) => void +): Promise<{ cid: string }> + +// Actual function implementation +async function uploadCarFiles( + path: string | File, + apiKey: string, + dealParameters?: DealParameters, + uploadProgressCallback?: (data: IUploadProgressCallback) => void +): Promise<{ cid: string }> { + // Upload File to IPFS + //@ts-ignore + if (typeof window === 'undefined') { + return await uploadCarFile(path as string, apiKey, dealParameters) + } else { + return await uploadCarFileBrowser( + path as File, + apiKey, + dealParameters, + uploadProgressCallback + ) + } +} + +export default uploadCarFiles diff --git a/src/Lighthouse/upload/carfile/node.ts b/src/Lighthouse/upload/carfile/node.ts new file mode 100644 index 0000000..a2cd0ce --- /dev/null +++ b/src/Lighthouse/upload/carfile/node.ts @@ -0,0 +1,49 @@ +import { lighthouseConfig } from '../../../lighthouse.config' +import { DealParameters } from '../../../types' +import { fetchWithTimeout } from '../../utils/util' + +export default async ( + carFilePath: string, + apiKey: string, + dealParameters?: DealParameters +): Promise => { + const { createReadStream } = eval(`require`)('fs-extra') + const path = eval(`require`)('path') + + const token = 'Bearer ' + apiKey + + try { + const endpoint = lighthouseConfig.lighthouseNode + `/api/v0/dag/import` + + const stream = createReadStream(carFilePath) + const buffers: Buffer[] = [] + for await (const chunk of stream) { + buffers.push(chunk) + } + const blob = new Blob(buffers) + + const data = new FormData() + data.append('file', blob, path.basename(carFilePath)) + + const response = await fetchWithTimeout(endpoint, { + method: 'POST', + body: data, + timeout: 7200000, + headers: { + Authorization: token, + 'X-Deal-Parameter': dealParameters + ? JSON.stringify(dealParameters) + : 'null', + }, + }) + + if (!response.ok) { + throw new Error(`CAR upload failed: ${response.status}`) + } + + const res = await response.json() + return { data: res } + } catch (error: any) { + throw new Error(error.message) + } +} From bc71eaf3a03a6f559e7e1807f90816a94b02393e Mon Sep 17 00:00:00 2001 From: ravish1729 Date: Thu, 29 May 2025 16:05:07 +0530 Subject: [PATCH 03/14] ds store added --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ff746b1..c5e2c6a 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,4 @@ yarn.lock yarn-error.log dist/ src/coverage/ +.DS_Store \ No newline at end of file From df42238e7eba1ccc7acc1d1a014d9c221ebb5da5 Mon Sep 17 00:00:00 2001 From: ravish1729 Date: Thu, 29 May 2025 16:05:37 +0530 Subject: [PATCH 04/14] remove deal param --- src/types.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/types.ts b/src/types.ts index c677af2..523afe2 100644 --- a/src/types.ts +++ b/src/types.ts @@ -8,15 +8,6 @@ export interface IFileUploadedResponse { Size: string } -export type DealParameters = { - miner: string[] - num_copies: number - repair_threshold: number - renew_threshold: number - deal_duration: number - network: string -} - export type UploadFileReturnType = T extends true ? IFileUploadedResponse[] : IFileUploadedResponse From e687f9418195e960e5075a121f3f859a938e077a Mon Sep 17 00:00:00 2001 From: ravish1729 Date: Fri, 30 May 2025 14:22:59 +0530 Subject: [PATCH 05/14] fix type and res --- src/Lighthouse/upload/buffer/browser.ts | 6 +-- src/Lighthouse/upload/buffer/node.ts | 11 ++--- src/Lighthouse/upload/carfile/browser.ts | 54 ------------------------ src/Lighthouse/upload/carfile/index.ts | 41 ------------------ src/Lighthouse/upload/carfile/node.ts | 49 --------------------- src/Lighthouse/upload/files/browser.ts | 18 +++----- src/Lighthouse/upload/files/index.ts | 9 +--- src/Lighthouse/upload/files/node.ts | 31 +++++--------- src/Lighthouse/upload/text/browser.ts | 6 +-- src/Lighthouse/upload/text/node.ts | 6 +-- 10 files changed, 35 insertions(+), 196 deletions(-) delete mode 100644 src/Lighthouse/upload/carfile/browser.ts delete mode 100644 src/Lighthouse/upload/carfile/index.ts delete mode 100644 src/Lighthouse/upload/carfile/node.ts diff --git a/src/Lighthouse/upload/buffer/browser.ts b/src/Lighthouse/upload/buffer/browser.ts index 0230dd7..807d111 100644 --- a/src/Lighthouse/upload/buffer/browser.ts +++ b/src/Lighthouse/upload/buffer/browser.ts @@ -13,19 +13,19 @@ export default async (blob: any, apiKey: string, mimeType = '') => { method: 'POST', body: formData, headers: { - 'Mime-Type': mimeType, Authorization: token, }, }) if (!response.ok) { - throw new Error(`Request failed with status code ${response.status}`) + const res = (await response.json()) + throw new Error(res.error) } const data = await response.json() return { data } } catch (error: any) { - throw new Error(error?.message) + throw new Error(error) } } diff --git a/src/Lighthouse/upload/buffer/node.ts b/src/Lighthouse/upload/buffer/node.ts index a480bb7..f7f9bfd 100644 --- a/src/Lighthouse/upload/buffer/node.ts +++ b/src/Lighthouse/upload/buffer/node.ts @@ -14,17 +14,18 @@ export default async (buffer: any, apiKey: string, mimeType = '') => { method: 'POST', body: formData, headers: { - Authorization: token, - 'Mime-Type': mimeType, + Authorization: token }, }) - if (!response.ok) - throw new Error(`Request failed with status code ${response.status}`) + if (!response.ok) { + const res = (await response.json()) + throw new Error(res.error) + } const data = await response.json() return { data } } catch (error: any) { - throw new Error(error?.message) + throw new Error(error) } } diff --git a/src/Lighthouse/upload/carfile/browser.ts b/src/Lighthouse/upload/carfile/browser.ts deleted file mode 100644 index 6bc3aa1..0000000 --- a/src/Lighthouse/upload/carfile/browser.ts +++ /dev/null @@ -1,54 +0,0 @@ -/* istanbul ignore file */ -import { lighthouseConfig } from '../../../lighthouse.config' -import { DealParameters, IUploadProgressCallback } from '../../../types' -import { fetchWithTimeout } from '../../utils/util' - -export default async ( - carFile: File, - apiKey: string, - dealParameters?: DealParameters, - uploadProgressCallback?: (data: IUploadProgressCallback) => void -): Promise => { - try { - const endpoint = lighthouseConfig.lighthouseNode + `/api/v0/dag/import` - const token = 'Bearer ' + apiKey - - const formData = new FormData() - formData.append('file', carFile) - - const headers = new Headers({ - Authorization: token, - 'X-Deal-Parameter': dealParameters - ? JSON.stringify(dealParameters) - : 'null', - }) - - const response = uploadProgressCallback - ? await fetchWithTimeout(endpoint, { - method: 'POST', - body: formData, - headers: headers, - timeout: 7200000, // 2 hour timeout - onProgress: (progress) => { - uploadProgressCallback({ - progress: progress, - }) - }, - }) - : await fetchWithTimeout(endpoint, { - method: 'POST', - body: formData, - headers: headers, - timeout: 7200000, - }) - - if (!response.ok) { - throw new Error(`CAR upload failed: ${response.status}`) - } - - const res = await response.json() - return { data: res } - } catch (error: any) { - throw new Error(error?.message) - } -} diff --git a/src/Lighthouse/upload/carfile/index.ts b/src/Lighthouse/upload/carfile/index.ts deleted file mode 100644 index 56d11ea..0000000 --- a/src/Lighthouse/upload/carfile/index.ts +++ /dev/null @@ -1,41 +0,0 @@ -import uploadCarFile from './node' -import uploadCarFileBrowser from './browser' -import { DealParameters, IUploadProgressCallback } from '../../../types' - -// Type overloads for the function -async function uploadCarFiles( - path: string, - apiKey: string, - dealParameters?: DealParameters, - uploadProgressCallback?: (data: IUploadProgressCallback) => void -): Promise<{ cid: string }> - -async function uploadCarFiles( - path: File, - apiKey: string, - dealParameters?: DealParameters, - uploadProgressCallback?: (data: IUploadProgressCallback) => void -): Promise<{ cid: string }> - -// Actual function implementation -async function uploadCarFiles( - path: string | File, - apiKey: string, - dealParameters?: DealParameters, - uploadProgressCallback?: (data: IUploadProgressCallback) => void -): Promise<{ cid: string }> { - // Upload File to IPFS - //@ts-ignore - if (typeof window === 'undefined') { - return await uploadCarFile(path as string, apiKey, dealParameters) - } else { - return await uploadCarFileBrowser( - path as File, - apiKey, - dealParameters, - uploadProgressCallback - ) - } -} - -export default uploadCarFiles diff --git a/src/Lighthouse/upload/carfile/node.ts b/src/Lighthouse/upload/carfile/node.ts deleted file mode 100644 index a2cd0ce..0000000 --- a/src/Lighthouse/upload/carfile/node.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { lighthouseConfig } from '../../../lighthouse.config' -import { DealParameters } from '../../../types' -import { fetchWithTimeout } from '../../utils/util' - -export default async ( - carFilePath: string, - apiKey: string, - dealParameters?: DealParameters -): Promise => { - const { createReadStream } = eval(`require`)('fs-extra') - const path = eval(`require`)('path') - - const token = 'Bearer ' + apiKey - - try { - const endpoint = lighthouseConfig.lighthouseNode + `/api/v0/dag/import` - - const stream = createReadStream(carFilePath) - const buffers: Buffer[] = [] - for await (const chunk of stream) { - buffers.push(chunk) - } - const blob = new Blob(buffers) - - const data = new FormData() - data.append('file', blob, path.basename(carFilePath)) - - const response = await fetchWithTimeout(endpoint, { - method: 'POST', - body: data, - timeout: 7200000, - headers: { - Authorization: token, - 'X-Deal-Parameter': dealParameters - ? JSON.stringify(dealParameters) - : 'null', - }, - }) - - if (!response.ok) { - throw new Error(`CAR upload failed: ${response.status}`) - } - - const res = await response.json() - return { data: res } - } catch (error: any) { - throw new Error(error.message) - } -} diff --git a/src/Lighthouse/upload/files/browser.ts b/src/Lighthouse/upload/files/browser.ts index 4286048..19ec230 100644 --- a/src/Lighthouse/upload/files/browser.ts +++ b/src/Lighthouse/upload/files/browser.ts @@ -2,8 +2,7 @@ import { lighthouseConfig } from '../../../lighthouse.config' import { IUploadProgressCallback, - UploadFileReturnType, - DealParameters, + UploadFileReturnType } from '../../../types' import { fetchWithTimeout } from '../../utils/util' @@ -11,7 +10,6 @@ import { fetchWithTimeout } from '../../utils/util' export default async ( files: any, accessToken: string, - dealParameters: DealParameters | undefined, uploadProgressCallback?: (data: IUploadProgressCallback) => void ): Promise<{ data: UploadFileReturnType }> => { try { @@ -30,10 +28,7 @@ export default async ( const token = 'Bearer ' + accessToken const headers = new Headers({ - Authorization: token, - 'X-Deal-Parameter': dealParameters - ? JSON.stringify(dealParameters) - : 'null', + Authorization: token }) const response = uploadProgressCallback @@ -56,12 +51,13 @@ export default async ( }) if (!response.ok) { - throw new Error(`Request failed with status code ${response.status}`) + const res = (await response.json()) + throw new Error(res.error) } - const responseText = await response.text() - return { data: JSON.parse(responseText) } + const responseData = (await response.json()) + return { data: responseData } } catch (error: any) { - throw new Error(error?.message) + throw new Error(error) } } diff --git a/src/Lighthouse/upload/files/index.ts b/src/Lighthouse/upload/files/index.ts index a436f59..f754ac4 100644 --- a/src/Lighthouse/upload/files/index.ts +++ b/src/Lighthouse/upload/files/index.ts @@ -2,39 +2,34 @@ import uploadFile from './node' import uploadFileBrowser from './browser' import { IUploadProgressCallback, - IFileUploadedResponse, - DealParameters, + IFileUploadedResponse } from '../../../types' async function uploadFiles( sourcePath: string | any, apiKey: string, - dealParameters?: DealParameters, uploadProgressCallback?: (data: IUploadProgressCallback) => void ): Promise<{ data: IFileUploadedResponse }> async function uploadFiles( sourcePath: string | any, apiKey: string, - dealParameters?: DealParameters, uploadProgressCallback?: (data: IUploadProgressCallback) => void ): Promise<{ data: IFileUploadedResponse[] }> async function uploadFiles( path: string | any, apiKey: string, - dealParameters?: DealParameters, uploadProgressCallback?: (data: IUploadProgressCallback) => void ) { // Upload File to IPFS //@ts-ignore if (typeof window === 'undefined') { - return await uploadFile(path, apiKey, dealParameters) + return await uploadFile(path, apiKey) } else { return await uploadFileBrowser( path, apiKey, - dealParameters, uploadProgressCallback ) } diff --git a/src/Lighthouse/upload/files/node.ts b/src/Lighthouse/upload/files/node.ts index 2420571..5a61853 100644 --- a/src/Lighthouse/upload/files/node.ts +++ b/src/Lighthouse/upload/files/node.ts @@ -1,6 +1,6 @@ import basePathConvert from '../../utils/basePathConvert' import { lighthouseConfig } from '../../../lighthouse.config' -import { UploadFileReturnType, DealParameters } from '../../../types' +import { UploadFileReturnType } from '../../../types' import { fetchWithTimeout } from '../../utils/util' export async function walk(dir: string) { @@ -24,8 +24,7 @@ export async function walk(dir: string) { export default async ( sourcePath: string, - apiKey: string, - dealParameters: DealParameters | undefined + apiKey: string ): Promise<{ data: UploadFileReturnType }> => { const { createReadStream, lstatSync } = eval(`require`)('fs-extra') const path = eval(`require`)('path') @@ -52,20 +51,16 @@ export default async ( body: data, timeout: 7200000, headers: { - Authorization: token, - 'X-Deal-Parameter': dealParameters - ? JSON.stringify(dealParameters) - : 'null', + Authorization: token }, }) if (!response.ok) { - throw new Error(`Request failed with status code ${response.status}`) + const res = (await response.json()) + throw new Error(res.error) } - let responseData = (await response.text()) as any - responseData = JSON.parse(responseData) - + const responseData = (await response.json()) return { data: responseData } } else { const files = await walk(sourcePath) @@ -91,23 +86,19 @@ export default async ( body: data, timeout: 7200000, headers: { - Authorization: token, - 'X-Deal-Parameter': dealParameters - ? JSON.stringify(dealParameters) - : 'null', + Authorization: token }, }) if (!response.ok) { - throw new Error(`Request failed with status code ${response.status}`) + const res = (await response.json()) + throw new Error(res.error) } - let responseData = (await response.text()) as any - responseData = JSON.parse(responseData) - + const responseData = (await response.json()) return { data: responseData } } } catch (error: any) { - throw new Error(error.message) + throw new Error(error) } } diff --git a/src/Lighthouse/upload/text/browser.ts b/src/Lighthouse/upload/text/browser.ts index d7d8fdd..dfd042a 100644 --- a/src/Lighthouse/upload/text/browser.ts +++ b/src/Lighthouse/upload/text/browser.ts @@ -16,18 +16,18 @@ export default async (text: string, apiKey: string, name: string) => { body: formData, timeout: 7200000, headers: { - 'Mime-Type': 'text/plain', Authorization: token, }, }) if (!response.ok) { - throw new Error(`Request failed with status code ${response.status}`) + const res = (await response.json()) + throw new Error(res.error) } const data = await response.json() return { data } } catch (error: any) { - throw new Error(error?.message) + throw new Error(error) } } diff --git a/src/Lighthouse/upload/text/node.ts b/src/Lighthouse/upload/text/node.ts index 85bbbc0..5371bdb 100644 --- a/src/Lighthouse/upload/text/node.ts +++ b/src/Lighthouse/upload/text/node.ts @@ -18,18 +18,18 @@ export default async (text: string, apiKey: string, name: string) => { credentials: 'include', timeout: 7200000, headers: { - 'Mime-Type': 'text/plain', Authorization: token, }, }) if (!response.ok) { - throw new Error(`Request failed with status code ${response.status}`) + const res = (await response.json()) + throw new Error(res.error) } const data = await response.json() return { data } } catch (error: any) { - throw new Error(error?.message) + throw new Error(error) } } From ecdccad9985f7e0511dac5374f561e55e0b47aff Mon Sep 17 00:00:00 2001 From: ravish1729 Date: Fri, 30 May 2025 14:23:31 +0530 Subject: [PATCH 06/14] upload url update --- src/lighthouse.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lighthouse.config.ts b/src/lighthouse.config.ts index 7d93b6b..4866896 100644 --- a/src/lighthouse.config.ts +++ b/src/lighthouse.config.ts @@ -1,6 +1,6 @@ const defaultConfig = { lighthouseAPI: 'https://api.lighthouse.storage', - lighthouseNode: 'https://node.lighthouse.storage', + lighthouseNode: 'https://upload.lighthouse.storage', lighthouseGateway: 'https://gateway.lighthouse.storage', lighthouseBLSNode: 'https://encryption.lighthouse.storage', network: 'polygon', From 17331370931cd7e994ce86e9d8ff78732586f7ad Mon Sep 17 00:00:00 2001 From: ravish1729 Date: Fri, 30 May 2025 14:23:57 +0530 Subject: [PATCH 07/14] remove deal param --- src/Lighthouse/index.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Lighthouse/index.ts b/src/Lighthouse/index.ts index 1e4c60e..1ab2806 100644 --- a/src/Lighthouse/index.ts +++ b/src/Lighthouse/index.ts @@ -21,7 +21,6 @@ import getAccessConditions from './encryption/getAccessConditions' // Upload import upload from './upload/files' -import uploadCar from './upload/carfile' import uploadText from './upload/text' import uploadBuffer from './upload/buffer' import decryptFile from './uploadEncrypted/decrypt' @@ -55,7 +54,6 @@ export { applyAccessCondition, getAccessConditions, upload, - uploadCar, uploadText, uploadBuffer, uploadEncrypted, @@ -86,7 +84,6 @@ export default { applyAccessCondition, getAccessConditions, upload, - uploadCar, uploadText, uploadBuffer, uploadEncrypted, From b582cd96f47c6d8296080dd0d074f30171f046be Mon Sep 17 00:00:00 2001 From: ravish1729 Date: Fri, 30 May 2025 14:25:11 +0530 Subject: [PATCH 08/14] version --- README.md | 2 +- package-lock.json | 4 ++-- package.json | 2 +- src/Commands/index.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7b1beae..8156195 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Lighthouse +# Lighthouse 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. diff --git a/package-lock.json b/package-lock.json index 75a90aa..d9f213b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@lighthouse-web3/sdk", - "version": "0.3.7", + "version": "0.3.9", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@lighthouse-web3/sdk", - "version": "0.3.7", + "version": "0.3.9", "license": "MIT", "dependencies": { "@lighthouse-web3/kavach": "^0.1.9", diff --git a/package.json b/package.json index 2c3f716..79584b3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lighthouse-web3/sdk", - "version": "0.3.7", + "version": "0.3.9", "description": "NPM package and CLI tool to interact with lighthouse protocol", "main": "./dist/Lighthouse/index.js", "types": "./dist/Lighthouse/index.d.ts", diff --git a/src/Commands/index.ts b/src/Commands/index.ts index bd8ad81..c83c442 100644 --- a/src/Commands/index.ts +++ b/src/Commands/index.ts @@ -72,7 +72,7 @@ Command.prototype.helpInformation = function (context: any) { } widgets.addHelpText('before', 'Welcome to lighthouse-web3') -widgets.version('0.3.7') +widgets.version('0.3.9') widgets .command('wallet') From deccb2269d94945f9e7d7d1099326f7fed0fca0f Mon Sep 17 00:00:00 2001 From: ravish1729 Date: Fri, 30 May 2025 14:29:49 +0530 Subject: [PATCH 09/14] updated --- src/Commands/deal-status.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/Commands/deal-status.ts b/src/Commands/deal-status.ts index 09bfb61..d8e33ea 100644 --- a/src/Commands/deal-status.ts +++ b/src/Commands/deal-status.ts @@ -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( @@ -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'] ) } From fb2e5ed0611763dbf72e30848efd9b8940f31a40 Mon Sep 17 00:00:00 2001 From: ravish1729 Date: Fri, 30 May 2025 14:31:48 +0530 Subject: [PATCH 10/14] updated --- .../uploadEncrypted/encrypt/file/browser.ts | 20 +++----------- .../uploadEncrypted/encrypt/file/node.ts | 26 ++++++++++--------- 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/src/Lighthouse/uploadEncrypted/encrypt/file/browser.ts b/src/Lighthouse/uploadEncrypted/encrypt/file/browser.ts index a39822c..7e630ab 100644 --- a/src/Lighthouse/uploadEncrypted/encrypt/file/browser.ts +++ b/src/Lighthouse/uploadEncrypted/encrypt/file/browser.ts @@ -98,27 +98,13 @@ export default async ( }, }) if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`) + const res = (await response.json()) + throw new Error(res.error) } - - // const reader = response.body?.getReader() - // let chunks = [] - // while (true) { - // const { done, value } = await reader!.read() - // if (done) { - // break - // } - // chunks.push(value) - // } - - // let responseData = new TextDecoder('utf-8').decode( - // new Uint8Array(chunks.flatMap((chunk) => [...chunk])) - // ) as any + const responseText = await response.text() const jsondata = JSON.parse(responseText) as IFileUploadedResponse[] - // responseData = JSON.parse(responseData) - const savedKey = await Promise.all( jsondata.map(async (data: IFileUploadedResponse) => { return saveShards(publicKey, data.Hash, auth_token, keyMap[data.Name]) diff --git a/src/Lighthouse/uploadEncrypted/encrypt/file/node.ts b/src/Lighthouse/uploadEncrypted/encrypt/file/node.ts index 9d7dbb3..8c53ae0 100644 --- a/src/Lighthouse/uploadEncrypted/encrypt/file/node.ts +++ b/src/Lighthouse/uploadEncrypted/encrypt/file/node.ts @@ -39,24 +39,25 @@ export default async ( }) if (!response.ok) { - throw new Error(`Request failed with status code ${response.status}`) + const res = (await response.json()) + throw new Error(res.error) } const responseData = (await response.json()) as any - const { error } = await saveShards( - publicKey, - responseData[0].Hash, - auth_token, - keyShards - ) - if (error) { - throw new Error('Error encrypting file') - } + // const { error } = await saveShards( + // publicKey, + // responseData[0].Hash, + // auth_token, + // keyShards + // ) + // if (error) { + // throw new Error('Error encrypting file') + // } return { data: responseData } } catch (error: any) { - throw new Error(error.message) + throw new Error(error) } } else { const files = await walk(sourcePath) @@ -92,7 +93,8 @@ export default async ( }) if (!response.ok) { - throw new Error(`Request failed with status code ${response.status}`) + const res = (await response.json()) + throw new Error(res.error) } const responseText = await response.text() From 9fd9ae8122490c0ac995cdecf0ca962185f31903 Mon Sep 17 00:00:00 2001 From: ravish1729 Date: Fri, 30 May 2025 17:10:20 +0530 Subject: [PATCH 11/14] cid version --- src/Lighthouse/upload/buffer/browser.ts | 4 ++-- src/Lighthouse/upload/buffer/index.ts | 6 +++--- src/Lighthouse/upload/buffer/node.ts | 4 ++-- src/Lighthouse/upload/files/browser.ts | 11 ++++++----- src/Lighthouse/upload/files/index.ts | 18 ++++-------------- src/Lighthouse/upload/files/node.ts | 12 ++++++------ src/Lighthouse/upload/text/browser.ts | 4 ++-- src/Lighthouse/upload/text/index.ts | 6 +++--- src/Lighthouse/upload/text/node.ts | 4 ++-- .../uploadEncrypted/encrypt/file/browser.ts | 3 ++- .../uploadEncrypted/encrypt/file/index.ts | 4 +++- .../uploadEncrypted/encrypt/file/node.ts | 5 +++-- 12 files changed, 38 insertions(+), 43 deletions(-) diff --git a/src/Lighthouse/upload/buffer/browser.ts b/src/Lighthouse/upload/buffer/browser.ts index 807d111..fa8543b 100644 --- a/src/Lighthouse/upload/buffer/browser.ts +++ b/src/Lighthouse/upload/buffer/browser.ts @@ -1,9 +1,9 @@ import { lighthouseConfig } from '../../../lighthouse.config' -export default async (blob: any, apiKey: string, mimeType = '') => { +export default async (blob: any, apiKey: string, cidVersion: number) => { try { const token = 'Bearer ' + apiKey - const endpoint = lighthouseConfig.lighthouseNode + '/api/v0/add' + const endpoint = lighthouseConfig.lighthouseNode + `/api/v0/add?cid-version=${cidVersion}` // Upload file const formData = new FormData() diff --git a/src/Lighthouse/upload/buffer/index.ts b/src/Lighthouse/upload/buffer/index.ts index e1761ed..9e79829 100644 --- a/src/Lighthouse/upload/buffer/index.ts +++ b/src/Lighthouse/upload/buffer/index.ts @@ -1,12 +1,12 @@ import uploadBuffer from './node' import uploadTypedArray from './browser' -export default async (buffer: any, apiKey: string) => { +export default async (buffer: any, apiKey: string, cidVersion: number = 1) => { // Upload File to IPFS //@ts-ignore if (typeof window === 'undefined') { - return await uploadBuffer(buffer, apiKey) + return await uploadBuffer(buffer, apiKey, cidVersion) } else { - return await uploadTypedArray(buffer, apiKey) + return await uploadTypedArray(buffer, apiKey, cidVersion) } } diff --git a/src/Lighthouse/upload/buffer/node.ts b/src/Lighthouse/upload/buffer/node.ts index f7f9bfd..11be7f5 100644 --- a/src/Lighthouse/upload/buffer/node.ts +++ b/src/Lighthouse/upload/buffer/node.ts @@ -1,9 +1,9 @@ import { lighthouseConfig } from '../../../lighthouse.config' -export default async (buffer: any, apiKey: string, mimeType = '') => { +export default async (buffer: any, apiKey: string, cidVersion: number) => { try { const token = 'Bearer ' + apiKey - const endpoint = lighthouseConfig.lighthouseNode + '/api/v0/add' + const endpoint = lighthouseConfig.lighthouseNode + `/api/v0/add?cid-version=${cidVersion}` // Upload file const blob = new Blob([buffer]) diff --git a/src/Lighthouse/upload/files/browser.ts b/src/Lighthouse/upload/files/browser.ts index 19ec230..505347d 100644 --- a/src/Lighthouse/upload/files/browser.ts +++ b/src/Lighthouse/upload/files/browser.ts @@ -2,22 +2,23 @@ import { lighthouseConfig } from '../../../lighthouse.config' import { IUploadProgressCallback, - UploadFileReturnType + IFileUploadedResponse } from '../../../types' import { fetchWithTimeout } from '../../utils/util' // eslint-disable-next-line @typescript-eslint/no-empty-function -export default async ( +export default async ( files: any, accessToken: string, + cidVersion: number, uploadProgressCallback?: (data: IUploadProgressCallback) => void -): Promise<{ data: UploadFileReturnType }> => { +): Promise<{ data: IFileUploadedResponse }> => { try { const isDirectory = [...files].some(file => file.webkitRelativePath) - let endpoint = lighthouseConfig.lighthouseNode + `/api/v0/add?wrap-with-directory=false` + let endpoint = lighthouseConfig.lighthouseNode + `/api/v0/add?wrap-with-directory=false&cid-version=${cidVersion}` if(!isDirectory && files.length > 1) { - endpoint = lighthouseConfig.lighthouseNode + `/api/v0/add?wrap-with-directory=true` + endpoint = lighthouseConfig.lighthouseNode + `/api/v0/add?wrap-with-directory=true&cid-version=${cidVersion}` } const formData = new FormData() diff --git a/src/Lighthouse/upload/files/index.ts b/src/Lighthouse/upload/files/index.ts index f754ac4..d55de93 100644 --- a/src/Lighthouse/upload/files/index.ts +++ b/src/Lighthouse/upload/files/index.ts @@ -5,31 +5,21 @@ import { IFileUploadedResponse } from '../../../types' -async function uploadFiles( - sourcePath: string | any, - apiKey: string, - uploadProgressCallback?: (data: IUploadProgressCallback) => void -): Promise<{ data: IFileUploadedResponse }> - -async function uploadFiles( - sourcePath: string | any, - apiKey: string, - uploadProgressCallback?: (data: IUploadProgressCallback) => void -): Promise<{ data: IFileUploadedResponse[] }> - async function uploadFiles( path: string | any, apiKey: string, + cidVersion: number = 1, uploadProgressCallback?: (data: IUploadProgressCallback) => void -) { +): Promise<{ data: IFileUploadedResponse }> { // Upload File to IPFS //@ts-ignore if (typeof window === 'undefined') { - return await uploadFile(path, apiKey) + return await uploadFile(path, apiKey, cidVersion) } else { return await uploadFileBrowser( path, apiKey, + cidVersion, uploadProgressCallback ) } diff --git a/src/Lighthouse/upload/files/node.ts b/src/Lighthouse/upload/files/node.ts index 5a61853..3dfc731 100644 --- a/src/Lighthouse/upload/files/node.ts +++ b/src/Lighthouse/upload/files/node.ts @@ -1,8 +1,7 @@ import basePathConvert from '../../utils/basePathConvert' import { lighthouseConfig } from '../../../lighthouse.config' -import { UploadFileReturnType } from '../../../types' import { fetchWithTimeout } from '../../utils/util' - +import { IFileUploadedResponse } from '../../../types' export async function walk(dir: string) { const { readdir, stat } = eval(`require`)('fs-extra') let results: string[] = [] @@ -22,10 +21,11 @@ export async function walk(dir: string) { return results } -export default async ( +export default async ( sourcePath: string, - apiKey: string -): Promise<{ data: UploadFileReturnType }> => { + apiKey: string, + cidVersion: number +): Promise<{ data: IFileUploadedResponse }> => { const { createReadStream, lstatSync } = eval(`require`)('fs-extra') const path = eval(`require`)('path') @@ -34,7 +34,7 @@ export default async ( try { const endpoint = lighthouseConfig.lighthouseNode + - `/api/v0/add?wrap-with-directory=false` + `/api/v0/add?wrap-with-directory=false&cid-version=${cidVersion}` if (stats.isFile()) { const data = new FormData() const stream = createReadStream(sourcePath) diff --git a/src/Lighthouse/upload/text/browser.ts b/src/Lighthouse/upload/text/browser.ts index dfd042a..f46b90e 100644 --- a/src/Lighthouse/upload/text/browser.ts +++ b/src/Lighthouse/upload/text/browser.ts @@ -1,10 +1,10 @@ import { lighthouseConfig } from '../../../lighthouse.config' import { fetchWithTimeout } from '../../utils/util' -export default async (text: string, apiKey: string, name: string) => { +export default async (text: string, apiKey: string, name: string, cidVersion: number) => { try { const token = 'Bearer ' + apiKey - const endpoint = lighthouseConfig.lighthouseNode + '/api/v0/add' + const endpoint = lighthouseConfig.lighthouseNode + `/api/v0/add?cid-version=${cidVersion}` // Upload file const formData = new FormData() diff --git a/src/Lighthouse/upload/text/index.ts b/src/Lighthouse/upload/text/index.ts index 07c3d0a..4d645a9 100644 --- a/src/Lighthouse/upload/text/index.ts +++ b/src/Lighthouse/upload/text/index.ts @@ -1,12 +1,12 @@ import uploadTextServer from './node' import uploadTextBrowser from './browser' -export default async (text: string, apiKey: string, name = 'text') => { +export default async (text: string, apiKey: string, name = 'text', cidVersion: number = 1) => { // Upload File to IPFS //@ts-ignore if (typeof window === 'undefined') { - return await uploadTextServer(text, apiKey, name) + return await uploadTextServer(text, apiKey, name, cidVersion) } else { - return await uploadTextBrowser(text, apiKey, name) + return await uploadTextBrowser(text, apiKey, name, cidVersion) } } diff --git a/src/Lighthouse/upload/text/node.ts b/src/Lighthouse/upload/text/node.ts index 5371bdb..8c2257c 100644 --- a/src/Lighthouse/upload/text/node.ts +++ b/src/Lighthouse/upload/text/node.ts @@ -1,10 +1,10 @@ import { lighthouseConfig } from '../../../lighthouse.config' import { fetchWithTimeout } from '../../utils/util' -export default async (text: string, apiKey: string, name: string) => { +export default async (text: string, apiKey: string, name: string, cidVersion: number) => { try { const token = 'Bearer ' + apiKey - const endpoint = lighthouseConfig.lighthouseNode + '/api/v0/add' + const endpoint = lighthouseConfig.lighthouseNode + `/api/v0/add?cid-version=${cidVersion}` // Upload file const formData = new FormData() diff --git a/src/Lighthouse/uploadEncrypted/encrypt/file/browser.ts b/src/Lighthouse/uploadEncrypted/encrypt/file/browser.ts index 7e630ab..c833343 100644 --- a/src/Lighthouse/uploadEncrypted/encrypt/file/browser.ts +++ b/src/Lighthouse/uploadEncrypted/encrypt/file/browser.ts @@ -29,6 +29,7 @@ export default async ( apiKey: string, publicKey: string, auth_token: string, + cidVersion: number, uploadProgressCallback?: (data: IUploadProgressCallback) => void ): Promise<{ data: IFileUploadedResponse[] }> => { try { @@ -38,7 +39,7 @@ export default async ( mimeType = files[0].type } const endpoint = - lighthouseConfig.lighthouseNode + '/api/v0/add?wrap-with-directory=false' + lighthouseConfig.lighthouseNode + `/api/v0/add?wrap-with-directory=false&cid-version=${cidVersion}` const token = 'Bearer ' + apiKey const fileArr = [] diff --git a/src/Lighthouse/uploadEncrypted/encrypt/file/index.ts b/src/Lighthouse/uploadEncrypted/encrypt/file/index.ts index aacc026..cb996fe 100644 --- a/src/Lighthouse/uploadEncrypted/encrypt/file/index.ts +++ b/src/Lighthouse/uploadEncrypted/encrypt/file/index.ts @@ -6,18 +6,20 @@ export default async ( apiKey: string, publicKey: string, signedMessage: string, + cidVersion: number = 1, uploadProgressCallback?: (data: any) => void ) => { // Upload File to IPFS //@ts-ignore if (typeof window === 'undefined') { - return await uploadFile(path, apiKey, publicKey, signedMessage) + return await uploadFile(path, apiKey, publicKey, signedMessage, cidVersion) } else { return await browser( path, apiKey, publicKey, signedMessage, + cidVersion, uploadProgressCallback || (() => { return diff --git a/src/Lighthouse/uploadEncrypted/encrypt/file/node.ts b/src/Lighthouse/uploadEncrypted/encrypt/file/node.ts index 8c53ae0..8a43c20 100644 --- a/src/Lighthouse/uploadEncrypted/encrypt/file/node.ts +++ b/src/Lighthouse/uploadEncrypted/encrypt/file/node.ts @@ -9,12 +9,13 @@ export default async ( sourcePath: any, apiKey: string, publicKey: string, - auth_token: string + auth_token: string, + cidVersion: number ): Promise<{ data: IFileUploadedResponse[] }> => { const fs = eval('require')('fs-extra') const token = 'Bearer ' + apiKey const endpoint = - lighthouseConfig.lighthouseNode + '/api/v0/add?wrap-with-directory=false' + lighthouseConfig.lighthouseNode + `/api/v0/add?wrap-with-directory=false&cid-version=${cidVersion}` const stats = fs.lstatSync(sourcePath) if (stats.isFile()) { From e4a7bcfc0c3b7e870beefc2ea94bac3e0457450a Mon Sep 17 00:00:00 2001 From: Aakash Taneja Date: Fri, 30 May 2025 21:40:01 +0530 Subject: [PATCH 12/14] refactor: update README and command structure; remove podsi command and adjust tests for consistency --- README.md | 80 +++++++++++-------- src/Commands/index.ts | 7 -- src/Lighthouse/tests/dealStatus.test.ts | 8 +- src/Lighthouse/tests/encryption.test.ts | 28 ++++--- src/Lighthouse/tests/podsi.test.ts | 23 ------ src/Lighthouse/tests/upload.test.ts | 5 +- src/Lighthouse/tests/uploadBuffer.test.ts | 2 +- src/Lighthouse/tests/uploadText.test.ts | 2 +- .../uploadEncrypted/encrypt/file/node.ts | 25 +++--- .../uploadEncrypted/encrypt/text/node.ts | 2 +- 10 files changed, 83 insertions(+), 99 deletions(-) delete mode 100644 src/Lighthouse/tests/podsi.test.ts diff --git a/README.md b/README.md index 8156195..b223352 100644 --- a/README.md +++ b/README.md @@ -11,52 +11,64 @@ npm install -g @lighthouse-web3/sdk ## CLI Usage ```bash -# create-wallet -lighthouse-web3 create-wallet - -# import-wallet -lighthouse-web3 import-wallet --key - -# wallet-forget -lighthouse-web3 wallet-forget - -# api-key -lighthouse-web3 api-key --new - -# balance -lighthouse-web3 balance - -# upload -lighthouse-web3 upload - -# status -lighthouse-web3 status - -# 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 # 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 # Import an existing API key + +# Storage and uploads +lighthouse-web3 upload # Upload a file +lighthouse-web3 upload-encrypted # Upload a file encrypted +lighthouse-web3 decrypt-file # Decrypt and download a file + +# Data usage and balance +lighthouse-web3 balance # Get your data usage + +# File and deal status +lighthouse-web3 deal-status # 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
# Share access to another user +lighthouse-web3 revoke-access
# Revoke access on a file + +# IPNS (InterPlanetary Naming System) +lighthouse-web3 ipns --generate-key # Generate IPNS Key +lighthouse-web3 ipns --publish --cid --key # Publish CID to IPNS +lighthouse-web3 ipns --list # List all IPNS keys +lighthouse-web3 ipns --remove # Remove an IPNS key + +# Proof of Data Segment Inclusion (PODSI) +lighthouse-web3 podsi # 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/) +> Refer to the [GitBook documentation](https://docs.lighthouse.storage/lighthouse-1/) for more details and advanced usage. ## Contributing diff --git a/src/Commands/index.ts b/src/Commands/index.ts index c83c442..2b73387 100644 --- a/src/Commands/index.ts +++ b/src/Commands/index.ts @@ -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') @@ -116,12 +115,6 @@ widgets .description('IPNS service') .action(ipns) -widgets - .command('podsi') - .description('Show Proof of data segment inclusion') - .argument('', 'CID of the file previously uploaded') - .action(podsi) - widgets .command('upload') .description('Upload a file') diff --git a/src/Lighthouse/tests/dealStatus.test.ts b/src/Lighthouse/tests/dealStatus.test.ts index f352277..ec0295b 100644 --- a/src/Lighthouse/tests/dealStatus.test.ts +++ b/src/Lighthouse/tests/dealStatus.test.ts @@ -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 () => { diff --git a/src/Lighthouse/tests/encryption.test.ts b/src/Lighthouse/tests/encryption.test.ts index 05c409b..9f3660b 100644 --- a/src/Lighthouse/tests/encryption.test.ts +++ b/src/Lighthouse/tests/encryption.test.ts @@ -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' @@ -36,6 +38,7 @@ 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, @@ -43,10 +46,11 @@ describe('encryption', () => { 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( @@ -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 { @@ -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 { @@ -86,7 +90,7 @@ describe('encryption', () => { } catch (error) { expect(error.message).toBe('Invalid Signature') } - }, 60000) + }, 6000) }) describe('shareFile', () => { const publicKey = '0x969e19A952A9aeF004e4F711eE481D72A59470B1' @@ -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 { @@ -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' @@ -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 () => { @@ -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 () => { @@ -194,6 +198,6 @@ describe('encryption', () => { expect(response.data).toHaveProperty('conditions') expect(response.data).toHaveProperty('sharedTo') expect(response.data.cid).toEqual(cid) - }, 20000) + }, 10000) }) }) diff --git a/src/Lighthouse/tests/podsi.test.ts b/src/Lighthouse/tests/podsi.test.ts deleted file mode 100644 index 34a8816..0000000 --- a/src/Lighthouse/tests/podsi.test.ts +++ /dev/null @@ -1,23 +0,0 @@ -import lighthouse from '..' - -describe('podsi', () => { - it('should get PoDSI when CID whose deal is created is provided', async () => { - const response = ( - await lighthouse.posdi('QmaiauHSgTDMy2NtLbsygL3iKmLXBqHf39SBA1nAQFSSey') - ).data - - expect(response).toHaveProperty('pieceCID') - expect(typeof response.dealInfo[0].dealId).toBe('number') - expect(response).toHaveProperty('dealInfo') - }, 20000) - - it('should not get PoDSI when CID whose deal is not created is provided', async () => { - try { - const response = ( - await lighthouse.posdi('QmbnJh4KMARvXcSqNCaz3gv6KuJ8v19RYi55YVqPg4zZV8') - ).data - } catch (error) { - expect(error.message).toBe('Request failed with status code 404') - } - }, 20000) -}) diff --git a/src/Lighthouse/tests/upload.test.ts b/src/Lighthouse/tests/upload.test.ts index 88415bc..4ac22f5 100644 --- a/src/Lighthouse/tests/upload.test.ts +++ b/src/Lighthouse/tests/upload.test.ts @@ -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') @@ -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) }) diff --git a/src/Lighthouse/tests/uploadBuffer.test.ts b/src/Lighthouse/tests/uploadBuffer.test.ts index 671b73c..9bb3d16 100644 --- a/src/Lighthouse/tests/uploadBuffer.test.ts +++ b/src/Lighthouse/tests/uploadBuffer.test.ts @@ -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) }) diff --git a/src/Lighthouse/tests/uploadText.test.ts b/src/Lighthouse/tests/uploadText.test.ts index 6c6e427..4e0671b 100644 --- a/src/Lighthouse/tests/uploadText.test.ts +++ b/src/Lighthouse/tests/uploadText.test.ts @@ -28,7 +28,7 @@ describe('uploadText', () => { await lighthouse.uploadText(text, 'invalid.apiKey', 'sample') ).data } catch (error) { - expect(error.message).toBe('Request failed with status code 500') + expect(error.message).toBe('Error: Authentication failed') } }, 60000) }) diff --git a/src/Lighthouse/uploadEncrypted/encrypt/file/node.ts b/src/Lighthouse/uploadEncrypted/encrypt/file/node.ts index 8a43c20..0a9d803 100644 --- a/src/Lighthouse/uploadEncrypted/encrypt/file/node.ts +++ b/src/Lighthouse/uploadEncrypted/encrypt/file/node.ts @@ -15,7 +15,8 @@ export default async ( const fs = eval('require')('fs-extra') const token = 'Bearer ' + apiKey const endpoint = - lighthouseConfig.lighthouseNode + `/api/v0/add?wrap-with-directory=false&cid-version=${cidVersion}` + lighthouseConfig.lighthouseNode + + `/api/v0/add?wrap-with-directory=false&cid-version=${cidVersion}` const stats = fs.lstatSync(sourcePath) if (stats.isFile()) { @@ -40,21 +41,21 @@ export default async ( }) if (!response.ok) { - const res = (await response.json()) + const res = await response.json() throw new Error(res.error) } const responseData = (await response.json()) as any - // const { error } = await saveShards( - // publicKey, - // responseData[0].Hash, - // auth_token, - // keyShards - // ) - // if (error) { - // throw new Error('Error encrypting file') - // } + const { error } = await saveShards( + publicKey, + responseData[0].Hash, + auth_token, + keyShards + ) + if (error) { + throw new Error('Error encrypting file') + } return { data: responseData } } catch (error: any) { @@ -94,7 +95,7 @@ export default async ( }) if (!response.ok) { - const res = (await response.json()) + const res = await response.json() throw new Error(res.error) } diff --git a/src/Lighthouse/uploadEncrypted/encrypt/text/node.ts b/src/Lighthouse/uploadEncrypted/encrypt/text/node.ts index edf594d..8b42a24 100644 --- a/src/Lighthouse/uploadEncrypted/encrypt/text/node.ts +++ b/src/Lighthouse/uploadEncrypted/encrypt/text/node.ts @@ -47,7 +47,7 @@ export default async ( const { error } = await saveShards( publicKey, - responseData.Hash, + responseData[0].Hash, signedMessage, keyShards ) From ba63561c16bd5cc22725bb5be666a7809d6751f0 Mon Sep 17 00:00:00 2001 From: ravish1729 Date: Sat, 31 May 2025 00:00:35 +0530 Subject: [PATCH 13/14] updated --- src/Lighthouse/tests/uploadEncrypted.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Lighthouse/tests/uploadEncrypted.test.ts b/src/Lighthouse/tests/uploadEncrypted.test.ts index 7ad2651..b5fe18c 100644 --- a/src/Lighthouse/tests/uploadEncrypted.test.ts +++ b/src/Lighthouse/tests/uploadEncrypted.test.ts @@ -81,7 +81,7 @@ describe('uploadEncrypted', () => { signedMessageEncryption ) } catch (error) { - expect(error.message).toBe('Error encrypting file') + expect(error.message).toBe('Error: Error encrypting file') } }, 60000) @@ -96,7 +96,7 @@ describe('uploadEncrypted', () => { signedMessageEncryption ) } catch (error) { - expect(error.message).toBe('Request failed with status code 500') + expect(error.message).toBe('Error: Authentication failed') } }, 60000) }) From 1707fa805f9a737f06a90482aa8d446786c4af7d Mon Sep 17 00:00:00 2001 From: ravish1729 Date: Sat, 31 May 2025 00:03:46 +0530 Subject: [PATCH 14/14] patch --- README.md | 2 +- package-lock.json | 4 ++-- package.json | 2 +- src/Commands/index.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b223352..76e202f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Lighthouse +# Lighthouse 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. diff --git a/package-lock.json b/package-lock.json index d9f213b..39d1d53 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@lighthouse-web3/sdk", - "version": "0.3.9", + "version": "0.4.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@lighthouse-web3/sdk", - "version": "0.3.9", + "version": "0.4.0", "license": "MIT", "dependencies": { "@lighthouse-web3/kavach": "^0.1.9", diff --git a/package.json b/package.json index 79584b3..fa7870a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lighthouse-web3/sdk", - "version": "0.3.9", + "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", diff --git a/src/Commands/index.ts b/src/Commands/index.ts index 2b73387..40014e0 100644 --- a/src/Commands/index.ts +++ b/src/Commands/index.ts @@ -71,7 +71,7 @@ Command.prototype.helpInformation = function (context: any) { } widgets.addHelpText('before', 'Welcome to lighthouse-web3') -widgets.version('0.3.9') +widgets.version('0.4.0') widgets .command('wallet')