Socket
Socket
Sign inDemoInstall

asymmetric-crypto

Package Overview
Dependencies
4
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.1 to 1.0.2

src/index.js

15

package.json
{
"name": "asymmetric-crypto",
"version": "1.0.1",
"version": "1.0.2",
"description": "Encryption and signing using public-key cryptography (via tweetnacl)",
"main": "./build/index.js",
"main": "./src/index.js",
"scripts": {
"build": "abc build",
"test": "abc test && abc lint",
"version": "abc build"
"test": "jest --coverage && standard"
},

@@ -20,8 +18,9 @@ "author": "queicherius@gmail.com",

"fast-memoize": "^2.0.2",
"tweetnacl": "^0.14.5",
"tweetnacl-util": "^0.13.5"
"tweetnacl": "^1.0.0",
"tweetnacl-util": "^0.15.0"
},
"devDependencies": {
"abc-environment": "^1.0.5"
"jest": "^23.6.0",
"standard": "^12.0.1"
}
}
# asymmetric-crypto
[![Build Status](https://img.shields.io/travis/queicherius/asymmetric-crypto.svg?style=flat-square)](https://travis-ci.org/queicherius/asymmetric-crypto)
[![Coverage Status](https://img.shields.io/codecov/c/github/queicherius/asymmetric-crypto/master.svg?style=flat-square)](https://codecov.io/github/queicherius/asymmetric-crypto)
[![Coverage Status](https://img.shields.io/codecov/c/github/queicherius/asymmetric-crypto/master.svg?style=flat-square)](https://codecov.io/github/queicherius/asymmetric-crypto) [![Greenkeeper badge](https://badges.greenkeeper.io/queicherius/asymmetric-crypto.svg)](https://greenkeeper.io/)

@@ -19,3 +19,3 @@ > Encryption and signing using public-key cryptography (via [`tweetnacl`](https://github.com/dchest/tweetnacl-js))

```js
import * as crypto from 'asymmetric-crypto'
const crypto = require('asymmetric-crypto')

@@ -22,0 +22,0 @@ // Generate a key pair

@@ -1,16 +0,15 @@

/* eslint-env node, mocha */
import { expect } from 'chai'
import * as module from '../src/index.js'
/* eslint-env jest */
const crypto = require('../src/index.js')
describe('key generation', () => {
it('generates a key pair', () => {
const keyPair = module.keyPair()
expect(keyPair.secretKey).to.be.a('string')
expect(keyPair.publicKey).to.be.a('string')
const keyPair = crypto.keyPair()
expect(typeof keyPair.secretKey).toEqual('string')
expect(typeof keyPair.publicKey).toEqual('string')
})
it('generates a key pair from the secret key', () => {
const keyPair = module.keyPair()
const keyPairFromSecretKey = module.fromSecretKey(keyPair.secretKey)
expect(keyPair).to.deep.equal(keyPairFromSecretKey)
const keyPair = crypto.keyPair()
const keyPairFromSecretKey = crypto.fromSecretKey(keyPair.secretKey)
expect(keyPair).toEqual(keyPairFromSecretKey)
})

@@ -21,19 +20,19 @@ })

it('encrypts and decrypts', () => {
const myKeyPair = module.keyPair()
const theirKeyPair = module.keyPair()
const myKeyPair = crypto.keyPair()
const theirKeyPair = crypto.keyPair()
const data = 'some data to encrypt'
const encrypted = module.encrypt(data, theirKeyPair.publicKey, myKeyPair.secretKey)
expect(encrypted.data).to.be.a('string')
expect(encrypted.nonce).to.be.a('string')
const encrypted = crypto.encrypt(data, theirKeyPair.publicKey, myKeyPair.secretKey)
expect(typeof encrypted.data).toEqual('string')
expect(typeof encrypted.nonce).toEqual('string')
const decrypted = module.decrypt(encrypted.data, encrypted.nonce, myKeyPair.publicKey, theirKeyPair.secretKey)
expect(decrypted).to.equal(data)
const decrypted = crypto.decrypt(encrypted.data, encrypted.nonce, myKeyPair.publicKey, theirKeyPair.secretKey)
expect(decrypted).toEqual(data)
const decrypted2 = module.decrypt(encrypted.data, encrypted.nonce, myKeyPair.publicKey, theirKeyPair.secretKey)
expect(decrypted2).to.equal(data)
const decrypted2 = crypto.decrypt(encrypted.data, encrypted.nonce, myKeyPair.publicKey, theirKeyPair.secretKey)
expect(decrypted2).toEqual(data)
})
it('fails decryption when using the wrong key', () => {
const randomKeyPair = module.keyPair()
const randomKeyPair = crypto.keyPair()
const publicKey = 'J2rbR/Be2ukJuf6od+amUufeb4iN3pnF8hOHTprfUgY='

@@ -46,4 +45,4 @@ const encrypted = {

expect(() => {
module.decrypt(encrypted.data, encrypted.nonce, publicKey, randomKeyPair.secretKey)
}).to.throw('failed opening nacl.box')
crypto.decrypt(encrypted.data, encrypted.nonce, publicKey, randomKeyPair.secretKey)
}).toThrow('failed opening nacl.box')
})

@@ -54,21 +53,21 @@ })

it('signs and verifies', () => {
const myKeyPair = module.keyPair()
const myKeyPair = crypto.keyPair()
const data = 'some data to sign'
const signed = module.sign(data, myKeyPair.secretKey)
expect(signed).to.be.a('string')
const signed = crypto.sign(data, myKeyPair.secretKey)
expect(typeof signed).toEqual('string')
const verified = module.verify(data, signed, myKeyPair.publicKey)
expect(verified).to.equal(true)
const verified = crypto.verify(data, signed, myKeyPair.publicKey)
expect(verified).toEqual(true)
})
it('fails verification for the wrong key', () => {
const myKeyPair = module.keyPair()
const otherKeyPair = module.keyPair()
const myKeyPair = crypto.keyPair()
const otherKeyPair = crypto.keyPair()
const data = 'some data to sign'
const signed = module.sign(data, myKeyPair.secretKey)
const signed = crypto.sign(data, myKeyPair.secretKey)
const verified = module.verify(data, signed, otherKeyPair.publicKey)
expect(verified).to.equal(false)
const verified = crypto.verify(data, signed, otherKeyPair.publicKey)
expect(verified).toEqual(false)
})
})

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc