0.3.71 • Published 5 years ago

standard-file-js v0.3.71

Weekly downloads
344
License
-
Repository
-
Last release
5 years ago

SFJS

SFJS is a client-side JavaScript library for Standard File that handles user key generation and item encryption/decryption.

This library can be used in any JavaScript environment, including web, desktop, native, and mobile (via React Native).

Installation

npm install --save standard-file-js

Integrating in a web app

  1. Import these two files in your page, either via a packager like Grunt or Webpack, or via regular HTML script tags:
<script src="regenerator.js"></script>
<script src="sfjs.js"></script>

(regenerator.js is only required in web environments. If in native environment, install the package independently via npm install --save regenerator-runtime and include it in your build.)

Usage

On the web, SFJS will be available as a global window variable accessible via window.SFJS or just SFJS.

If in a module environment, you can import it via:

import { StandardFile } from 'standard-file-js';
let SFJS = new StandardFile();

Generating keys for user

New user (registration):

SFJS.generateInitialKeysAndAuthParamsForUser(email, password).then((results) => {
  let keys = results.keys;
  let authParams = results.authParams;

  let serverPassword = keys.pw;
  let encryptionKey = keys.mk;
  let authenticationKey = keys.ak;
});

Existing user (sign in):

let authParams = getPreviouslyCreatedAuthParams();
SFJS.computeEncryptionKeysForUser(password, authParams).then((keys) => {
  let serverPassword = keys.pw;
  let encryptionKey = keys.mk;
  let authenticationKey = keys.ak;
});

Key descriptions:

pw: sent to the server for authentication.

mk: encrypts and decrypts items. Never sent to the server.

ak: authenticates the encryption and decryption of items. Never sent to the server.

Encrypting and decrypting items

Use SFJS.itemTransformer to encrypt and decrypt items. Use the SFItemParams as a wrapper over the item transformer. The SFItemParams class allows you to pass an SFItem object, encryption keys, and auth params, and will return the encrypted result.

Encrypt:

let keys = getKeys(); // keys is a hash which should have properties mk and ak.
SFJS.itemTransformer.encryptItem(item, keys, authParams).then(() => {
 // item.content is now encrypted
})

Decrypt:

let keys = getKeys(); // keys is a hash which should have properties mk and ak.
SFJS.itemTransformer.decryptItem(item, keys).then(() => {
 // item.content is now decrypted
})

Notes

  • SFJS uses an asynchronous API. All functions are asynchronous, and return immediately even if they have not finished. Add .then() to every call to be notified of the result, or use await if you don't want to use callbacks.

Help

Join the #dev channel in our Slack group for help and discussion.

0.3.71

5 years ago

0.3.70

5 years ago

0.3.69

5 years ago

0.3.68

5 years ago

0.3.67

5 years ago

1.0.0-alpha.0

5 years ago

0.3.66

5 years ago

0.3.65

5 years ago

0.3.64

5 years ago

0.3.63

5 years ago

0.3.62

5 years ago

0.3.61

5 years ago

0.3.60

5 years ago

0.3.58

5 years ago

0.3.57

5 years ago

0.3.56

5 years ago

0.3.55

5 years ago

0.3.54

5 years ago

0.3.53

5 years ago

0.3.52

5 years ago

0.3.51

5 years ago

0.3.50

5 years ago

0.3.49

5 years ago

0.3.48

5 years ago

0.3.47

5 years ago

0.3.46

5 years ago

0.3.45

5 years ago

0.3.44

5 years ago

0.3.43

5 years ago

0.3.42

5 years ago

0.3.41

5 years ago

0.3.40

5 years ago

0.3.39

5 years ago

0.3.38

5 years ago

0.3.37

5 years ago

0.3.36

5 years ago

0.3.35

5 years ago

0.3.34

5 years ago

0.3.33

5 years ago

0.3.32

5 years ago

0.3.31

5 years ago

0.3.30

5 years ago

0.3.29

5 years ago

0.3.28

5 years ago

0.3.27

5 years ago

0.3.26

5 years ago

0.3.25

5 years ago

0.3.24

5 years ago

0.3.23

5 years ago

0.3.22

5 years ago

0.3.21

5 years ago

0.3.20

5 years ago

0.3.19

6 years ago

0.3.18

6 years ago

0.3.17

6 years ago

0.3.16

6 years ago

0.3.15

6 years ago

0.3.14

6 years ago

0.3.14-beta1

6 years ago

0.3.13

6 years ago

0.3.12

6 years ago

0.3.11

6 years ago

0.3.10

6 years ago

0.3.9

6 years ago

0.3.8

6 years ago

0.3.7

6 years ago

0.3.6

6 years ago

0.3.5

6 years ago

0.3.4

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago