Skip to content

jayrbolton/wot-crypto

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wot-crypto

Utility wrapper around libsodium (via sodium-universal) for use in node-wot.

See the test file for usage examples

id(length)

Returns a hex string, which will have a character length double of the length you passed in

hashPass(pass, salt, callback)

pass is a utf8 string

salt is optional -- if absent, it will be created. You should save it for re-hashing; it is not private. salt is a hex string

callback is a function that receives (err, {salt, secret}). salt and secret are both hex strings.

encrypt(secret, plainText)

Symmetric encryption of some text using a secret key.

secret should be the secret generated by hashPass and received in the callback -- it is a hex string

plainText is a utf8 string

Returns a hex string

decrypt(secret, encrypted)

Symmetric decryption of some text using the same secret key you encrypted it with.

secret should be the secret generated by hashPass and received in the callback -- it is a hex string.

encrypted is a hex string returned by encrypt

Throws an error if the decryption fails.

Returns a utf8 string of the original plaintext

createSignKeypair(seed)

seed should be the secret generated by hashPass and received in the callback -- it is a hex string.

Returns an object of {pk, sk} where pk is their public signing key and sk is their secret signing key. Both are hex strings.

createBoxKeypair(seed)

seed should be the secret generated by hashPass and received in the callback -- it is a hex string.

Returns an object of {pk, sk} where pk is their public encryption key and sk is their secret encryption key. Both are hex strings.

sign(message, sk)

message is a utf8 string

sk is the signing secret key returned by createSignKeypair -- it is a hex string

Returns a signed message (hex string)

openSigned(signedMessage, publicKey)

signedMessage is a hex string returned by sign

pk is the public signing key returned by createSignKeypair -- it is a hex string

Throws an error if the signature can't be verified.

Returns a utf8 string of the original unsigned message.

createBox(message, pk, sk)

message is a utf8 string

pk is the public encryption key returned by createBoxKeypair -- it is a hex string

sk is the secret encryption key returned by createBoxKeypair -- it is a hex string

Returns a hex string

openBox(encryptedMessage, pk, sk)

encryptedMessage is a hex string returned by createBox

pk is the public encryption key returned by createBoxKeypair -- it is a hex string

sk is the secret encryption key returned by createBoxKeypair -- it is a hex string

Throws an error if the decryption fails.

Returns a utf8 string of the original plaintext message.

hash(message)

message is a utf8 string

Returns a hex string

hashAndSign(message, sk)

message is a utf8 string

sk is the signing secret key returned by createSignKeypair -- it is a hex string

Returns a hex string

unhashAndVerify(signedHash, originalMessage, pk)

signedHash is a hex string returned by hashAndSign

originalMessage is a utf8 string that exactly matches the message passed into hashAndSign

pk is the public signing key returned by createSignKeypair -- it is a hex string

Throws an error if the hash does not match the original message, or if the signature can't be verified.

Returns the unsigned hash (hex string)

About

Crypto utils for node-wot using libsodium

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published