Files

The Files SDK offers developers the functionality of an encrypted IPFS drive. It creates a list of references and secret keys to files stored on IPFS, where each file is encrypted with its own secret. This way, if one secret key is compromised, there is no compromise of the entire drive.

Note: The list of files and secrets is only visible to the Wallet.

Here is a step-by-step guide on how to work with files in NotVault using TypeScript:

  1. Import the necessary libraries:

    import { NotVault, Files, FileEntry } from '@notcentralised/notvault-sdk';
  2. Instantiate the NotVault and Files classes:

    const vault = new NotVault();
    const files = new Files(vault);
  3. Add a new file:

    • Use the add method of the files instance to add a file to the vault.

    • The method requires the filename and the content of the file. The content should be in Base64 format when dealing with binary data.

    • The method also accepts a callback function that reports the progress of the upload operation.

    const newFilesList : FileEntry[] = await files.add(
        '... File Name ...', 
        '... Super secret text, usually in Base64 format when dealing with binary data ...', 
        (event: any) => {
            const percent = Math.floor((event.loaded / event.total) * 100);
            console.log(`Progress ${percent}%`);
        }
    );
  4. Retrieve the contents of a file given its CID:

    • Use the get method of the files instance to retrieve a file from the vault using its Content Identifier (CID).

    const retrievedFile : FileEntry = await files.get(`... File CID in IPFS ...`);
  5. List all the files linked to a specific wallet:

    • Use the list method of the files instance to retrieve a list of all files linked to the specific wallet in the vault.

    const allFiles : FileEntry[] = await files.list();
  6. Remove a file from a private list:

    • Use the remove method of the files instance to remove a file from the vault using its Content Identifier (CID).

    const newFilesAfterRemoval : FileEntry[] = await files.remove(`... File CID in IPFS ...`);

By following these steps, you can manage your files within the NotVault environment securely and efficiently.

Last updated