0.9.4 • Published 4 years ago

@questnetwork/quest-crypto-js v0.9.4

Weekly downloads
-
License
AGPL-3.0
Repository
github
Last release
4 years ago

Quest Crypto JS

Shared Crypto Interface For The Quest Network

Lead Maintainer

StationedInTheField

Description

The Crypto class for the Quest Network Operating System offers shared crypto functionality.

Installation & Usage

npm install @questnetwork/quest-utilities-js@0.9.4

API

aes

generatePassphrase(length)

Returns a new secure AES passphrase.

let pwd = <os>.crypto.aes.generatePassphrase(length);

hashSecret(message,newSecret, rounds = 10)

Hashes a secret for the specified amount of rounds, anything below 5000 rounds will default to 5000.

let hashed = <os>.crypto.aes.hashSecret(message,newSecret, rounds = 10);

encrypt(utf8OrObject, whistle = undefined)

Encrypts an object or utf8 string either with the whistle supplied or with a generated new whistle. Returns Base64.

let { secret, aesEncryptedB64 } = <os>.crypto.aes.encrypt('test');

decryptB64(aesEncryptedB64, secret, format = 'utf8')

Decrypts a B64 string with the whistle Returns String or Object.

let { secret, aesEncryptedB64 } = <os>.crypto.aes.decryptB64(aesEncryptedB64, secret, format = 'utf8')

decryptHex(enc,secret, format = 'utf8'

Decrypts a Hex string with the whistle Returns String or Object.

let { secret, aesEncryptedB64 } = <os>.crypto.aes.decryptHex(aesEncryptedHex, secret, format = 'utf8')

convert

stringToArrayBuffer(string,format)

Returns an ArrayBuffer of the input string.

let aB = <os>.crypto.convert.stringToArrayBuffer(string,'utf8');

bufferToArrayBuffer(buf)

Returns an ArrayBuffer of the input butter

let hashed = <os>.crypto.convert.bufferToArrayBuffer(buf);

async importKey(alg,format,keyenc,key)

Imports a key for WebCrypto.

await <os>.crypto.convert.importKey(alg,format,keyenc,key);

ec

async digest(algo,data)

Digests data using the supplied algorithm.

let digest = await <os>.crypto.ec.digest('SHA-256',data);

async generateKeyPair()

Generates an EC keypair with maximum security according to the Quest Network protocol.

let keys = await <os>.crypto.ec.generateKeyPair();

async sign(obj, keyHex)

Signs an object with an EC private Hex key according to the Quest Network protocol.

let signedObject = await <os>.crypto.ec.sign(obj,keyHex);

verify(obj, keyHex)

Verifies a signed object with an EC public Hex key according to the Quest Network protocol.

if(await <os>.crypto.ec.verify(obj,keyHex)){
  console.log('Signature Checks Out!');
}

rsa

async generateKeyPair()

Generates an RSA keypair with maximum security according to the Quest Network protocol.

let keys = await <os>.crypto.rsa.generateKeyPair();

async fullEncrypt(plain,pubKey)

Encrypts a string with an RSA private key

let encrypted = await <os>.crypto.rsa.fullEncrypt(plain,pubKey);

async fullDecrypt(enc,pk)

Decrypts a string with an RSA public key

let decrypted = await <os>.crypto.rsa.fullDecrypt(encrypted,pk);

Support Us

Please consider supporting us, so that we can build a non-profit for this project (ツ)

EthereumBitcoin
0xBC2A050E7B87610Bc29657e7e7901DdBA6f2D34Ebc1qujrqa3s34r5h0exgmmcuf8ejhyydm8wwja4fmq

License

GNU AGPLv3