@stellar-fox/cryptops
v1.0.6
Published
Crypto building blocks.
Downloads
13
Readme
cryptops
Crypto building blocks.
$ npm i @stellar-fox/cryptops
index
foreword
Cryptography is hard. Cryptography is important. Cryptography should be more accessible.
This library aims to tackle the last of the above sencences - it provides coherent API to use in browser as well as in server environment.
All the "heavy lifting" was done by the authors of the following, magnificent projects:
cryptops just wraps and combines some of their parts without adding anything that might lessen the security level.
Go ahead, inspect the source and see for yourself.
documentation
play in your browser
encrypting text using a passphrase:
https://runkit.com/xcmats/cryptops.passphraseencrypt
decrypting text using a passphrase:
https://runkit.com/xcmats/cryptops.passphrasedecrypt
use the package
install
$ mkdir playground
$ cd playground/
$ npm init
...
$ npm i @stellar-fox/cryptops
...
Three builds are provided:
play in node.js
$ node
>
cryptops = require("@stellar-fox/cryptops")
example use in your code
For utf8-string
<-> bytes
<-> hex-string
<-> b64-string
encoding and decoding @xcmats/js-toolbox can
be used.
import { passphraseEncrypt } from "@stellar-fox/cryptops"
import { newAddress } from "@stellar-fox/redshift"
import { codec } from "@xcmats/js-toolbox"
let
myPassphrase = "H0cus P0cus Open Sesam3 4brakadabra",
myPreciousSecret = newAddress().keypair.secret()
passphraseEncrypt(myPassphrase, codec.stringToBytes(myPreciousSecret))
.then((ciphertext) => {
console.log("Now I can sleep peacefully: ", ciphertext)
})
use the source
$ git clone [email protected]:stellar-fox/cryptops.git
Cloning into 'cryptops'...
$ cd cryptops
$ npm i
$ npm start
Compiling for 'production' ...
Hash: b6a8d4e126caf6f893b8
Version: webpack 4.40.2
Time: 2988ms
Built at: 09/15/2019 5:14:14 PM
Asset Size Chunks Chunk Names
cryptops.js 24.9 KiB 0 [emitted] cryptops
Entrypoint cryptops = cryptops.js
[0] external "@xcmats/js-toolbox" 42 bytes {0} [built]
[1] external "sjcl" 42 bytes {0} [built]
[2] external "tweetnacl" 42 bytes {0} [built]
[3] external "@babel/runtime/regenerator" 42 bytes {0} [built]
[4] external "@babel/runtime/helpers/asyncToGenerator" ...
[5] external "crypto-browserify" 42 bytes {0} [built]
[6] ./package.json 4.26 KiB {0} [built]
[7] external "scrypt-js" 42 bytes {0} [built]
[8] ./src/index.js 11.5 KiB {0} [built]
namespace
cryptops
{ random: [Function], sha256: [Function], salt32: [Function: salt32], genKey: [Function: genKey], sha512: { [Function] hashLength: 64 }, salt64: [Function: salt64], deriveKey: [Function: deriveKey], timestamp: [Function: timestamp], genUUID: [Function: genUUID], decodeUUID: [Function: decodeUUID], salsaNonce: [Function: salsaNonce], salsaEncrypt: [Function: salsaEncrypt], salsaDecrypt: [Function: salsaDecrypt], aesNonce: [Function: aesNonce], aesEncrypt: [Function: aesEncrypt], aesDecrypt: [Function: aesDecrypt], encrypt: { [Function: encrypt] }, decrypt: { [Function: decrypt] }, passphraseEncrypt: [Function: passphraseEncrypt], passphraseDecrypt: [Function: passphraseDecrypt], version: '1.0.6' }
tests
$ npm run test
uuid test
✓ should generate uuid
✓ should decode uuid
passphrase encrypt/decrypt test
✓ should generate content (5386ms)
✓ should encrypt (2407ms)
✓ should have different ciphertexts
✓ should decrypt (7258ms)
✓ should match content (67ms)
✓ should not decrypt with a wrong passphrase (2922ms)
8 passing (18s)
support
You can support this project via stellar network:
- Payment address: xcmats*keybase.io
- Stellar account ID:
GBYUN4PMACWBJ2CXVX2KID3WQOONPKZX2UL4J6ODMIRFCYOB3Z3C44UZ
license
cryptops are released under the Apache License, Version 2.0. See the LICENSE for more details.