0.8.0 • Published 6 years ago
@repux/repux-lib v0.8.0
RepuX Lib
This library helps developers using RepuX protocol. It supports file encryption, decryption and storage (including in-browser uploading and downloading) of files on IPFS.
Quickstart
Installation
npm install @repux/repux-lib
Usage
import IpfsAPI from 'ipfs-api';
import { RepuxLib } from '@repux/repux-lib';
const repux = new RepuxLib(new IpfsAPI({
host: 'marketplace-ipfs.repux.io',
port: 443,
protocol: 'https'
}));
const version = repux.getVersion();
console.log(version);
API Reference
API Reference is available here
How it works
- Data seller should generate RSA key pair using RepuxLib.generateAsymmetricKeyPair() function. This key pair should be stored on user local device.
- Data seller should generate AES symmetric key using RepuxLib.generateSymmetricKey() function. This key should be generated per file and should be also stored on user local device.
- Data seller uploads file using RepuxLib.createFileUploader().upload() function with symmetricKey, publicKey and file in parameters.
- Library reads file partially encrypts it symmetrically using AES-PCBC algorithm.
- Library encrypts first 190 bytes of file asymmetrically using seller publicKey.
- Library uploads all file parts to ipfs storage.
- Library uploads meta file containing all file parts, size, name and other meta data to ipfs storage.
- Library emits progress event with uploading progress.
- Library emits finish event with ipfs hash to meta file after upload is finished.
- Data buyer should generate RSA key pair using RepuxLib.generateAsymmetricKeyPair() function. This key pair should be stored on user local device.
- Data buyer communicates somehow with data seller and sends him his publicKey.
- Data seller re-encrypts first part of file using RepuxLib.createFileReencryptor().reencrypt() function with his privateKey and buyer publicKey and meta file hash.
- Library fetches meta file.
- Library fetches first file part.
- Library decrypts first file part using seller privateKey.
- Library encrypts first file part using buyer publicKey.
- Library uploads new meta file (with changed first part) to ipfs and emits progress and finish events as uploadFile function.
- Data seller encrypts file symmetricKey using buyer publicKey.
- Data seller communicates somehow with data buyer and sends him re-encrypted file meta hash and encrypted file symmetricKey
- Data buyer decrypts file symmetricKey with his privateKey.
- Data buyer downloads file using RepuxLib.createFileDownloader().download() function with symmetricKey, privateKey and re-encrypted file meta hash.
- Library downloads meta file
- Library downloads first file part, decrypts it using buyer privateKey and after that using symmetricKey
- Library downloads other file part and decrypts them using symmetricKey
- Library emits progress event with downloading progress.
- Library joins all file parts into one file and exposes url to file in finish event.
Browser compatibility
Browser | Type | Is supported | Max file size | Notes |
---|---|---|---|---|
Chrome | Desktop | ✓ | 100GB | Access to the WebCrypto API is restricted to secure origins (which is to say https:// pages). |
Firefox | Desktop | ✓ | 2GB(64-bit) 1GB(32-bit) | |
Safari | Desktop | ✓ | 2GB(64-bit) 1GB(32-bit) | |
Opera | Desktop | ✓ | 100GB | |
Brave | Desktop | ✓ | 100GB | |
IE | Desktop | ✗ | - | Web Crypto API must be prefixed, needs async/await polyfill |
Edge | Desktop | ✗ | - | Web Crypto API is not supported insize a Web Worker (https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/7607496/), needs TextEncryptor/TextDecryptor polyfill |
Chrome | Mobile | ✓ | 100MB | Access to the WebCrypto API is restricted to secure origins (which is to say https:// pages). |
Firefox | Mobile | ✓ | 100MB | |
Safari | Mobile | Not tested | - |
Want to help?
Want to file a bug, contribute some code, or improve documentation? Excellent! Read up on our guidelines for contributing