# @repux/repux-lib

> RepuX encryption/decryption library

Latest version **0.8.0** (published 2018-09-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install @repux/repux-lib
pnpm add @repux/repux-lib
yarn add @repux/repux-lib
bun add @repux/repux-lib
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.8.0 |
| Published | 2018-09-21 |
| First published | 2018-09-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 394.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | RepuX |
| Maintainers | davo22 |
| Keywords | repux, data, marketplace, protocol |

## Links

- npm: https://www.npmjs.com/package/@repux/repux-lib
- Repository: https://github.com/repux/repux-lib
- Homepage: https://github.com/repux/repux-lib#readme
- Issues: https://github.com/repux/repux-lib/issues
- npm.io page: https://npm.io/package/@repux/repux-lib

## Dependencies (5)

- [buffer](https://npm.io/package/buffer.md) 5.1.0
- [threads](https://npm.io/package/threads.md) ^0.10.1
- [ipfs-api](https://npm.io/package/ipfs-api.md) ^20.0.0
- [@types/node](https://npm.io/package/@types/node.md) ^10.3.0
- [@types/filesystem](https://npm.io/package/@types/filesystem.md) ^0.0.28

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 0.8.0 (latest) — 2018-09-21
- 0.7.1 — 2018-09-18

## README

# 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
```bash
npm install @repux/repux-lib
```

### Usage
```javascript
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](https://github.com/repux/repux-lib/tree/master/docs/README.md)

### How it works
1. Data seller should generate RSA key pair using RepuxLib.generateAsymmetricKeyPair() function. This key pair should be stored on user local device.
2. 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.
3. 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.
4. Data buyer should generate RSA key pair using RepuxLib.generateAsymmetricKeyPair() function. This key pair should be stored on user local device.
5. Data buyer communicates somehow with data seller and sends him his publicKey.
6. 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.
7. Data seller encrypts file symmetricKey using buyer publicKey.
8. Data seller communicates somehow with data buyer and sends him re-encrypted file meta hash and encrypted file symmetricKey
9. Data buyer decrypts file symmetricKey with his privateKey.
10. 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 | &check;      | 100GB                   | Access to the WebCrypto API is restricted to secure origins (which is to say https:// pages). |
| Firefox | Desktop | &check;      | 2GB(64-bit) 1GB(32-bit) |       |
| Safari  | Desktop | &check;      | 2GB(64-bit) 1GB(32-bit) |       |
| Opera   | Desktop | &check;      | 100GB                   |       |
| Brave   | Desktop | &check;      | 100GB                   |       |
| IE      | Desktop | &cross;      | -                       | Web Crypto API must be prefixed, needs async/await polyfill |
| Edge    | Desktop | &cross;      | -                       | 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  | &check;      | 100MB                   | Access to the WebCrypto API is restricted to secure origins (which is to say https:// pages). |
| Firefox | Mobile  | &check;      | 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](https://github.com/repux/repux-lib/tree/master/CONTRIBUTING.md)

---
_Source: https://npm.io/package/@repux/repux-lib · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
