3.2.7 • Published 5 months ago

@casual-simulation/crypto-node v3.2.7

Weekly downloads
28
License
MIT
Repository
github
Last release
5 months ago

Crypto Node

npm (scoped)

An implementation of the @casual-simulation/crypto package for Node.js.

Installation

npm install @casual-simulation/crypto-node

Usage

// ES6-style imports are required.
// If you are running in an environment that does not support ES Modules,
// then use Webpack or Babel to transpile to the format you want. (like CommonJS)
import { NodeSigningCryptoImpl } from '@casual-simulation/crypto-node';

// Async is optional. Every method returns a promise.
async function demo() {
    // Currently ECDSA-SHA256-NISTP256 is the only supported
    // algorithm.
    let algorithm = 'ECDSA-SHA256-NISTP256';
    let crypto = new NodeSigningCryptoImpl(algorithm);

    console.log('Crypto Supported: ', crypto.supported());

    // Generate a public-private key pair.
    let [publicKey, privateKey] = await crypto.generateKeyPair();

    // You can export the public and private keys to
    // share them with other devices. (But really only share the public key)
    let exportedPubKey = await crypto.exportKey(publicKey);
    let exportedPrivateKey = await crypto.exportKey(privateKey);

    // You can import keys that were exported using exportKey()
    // via the importPrivateKey() and importPublicKey() methods.

    console.log('Public Key: ', exportedPubKey);
    console.log('Private Key: ', exportedPrivateKey);
    // TODO: Save/share keys

    // Any ArrayBuffer will work
    let data = new Int32Array(100);

    // If you're using webpack, enable the Buffer polyfil.
    // This will let you convert strings to ArrayBuffer compatible
    // objects using Buffer.from(str).
    // Read More: https://webpack.js.org/configuration/node/

    // Fill with pseudo-random data.
    for (let i = 0; i < data.length; i++) {
        data[i] = Math.floor(Math.random() * 100);
    }

    // Sign the data
    let signature = crypto.sign(privateKey, data);

    // TODO: Send or store the signature and data

    // Verify the signature.
    // Note that the data must be provided as well.
    // This is because the signature does not store the data
    // in a usable format.
    let valid = crypto.verify(publicKey, signature, data);
    console.log('Valid: ', valid);
}

demo();
3.2.7

5 months ago

3.2.0

10 months ago

3.1.23

1 year ago

3.1.11

1 year ago

3.0.14

2 years ago

3.0.0

2 years ago

2.0.22

2 years ago

2.0.14

3 years ago

2.0.12

3 years ago

2.0.0

3 years ago

1.5.11-alpha.42

3 years ago

1.5.11-alpha.41

3 years ago

1.5.11-alpha.40

3 years ago

1.5.11-alpha.39

3 years ago

1.5.7

3 years ago

1.5.0

3 years ago

1.4.7-alpha.33

3 years ago

1.4.7-alpha.32

3 years ago

1.4.4

3 years ago

1.2.2

4 years ago

1.2.0

4 years ago

1.0.24

4 years ago

1.0.0

4 years ago

0.11.20

4 years ago

0.11.8

4 years ago

0.11.0

5 years ago

0.10.0

5 years ago

0.9.7

5 years ago

0.9.1

5 years ago

0.8.10

5 years ago

0.8.0

5 years ago

0.7.0

5 years ago

0.6.5

5 years ago

0.6.0

5 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago