1.2.0 • Published 5 years ago

signun v1.2.0

Weekly downloads
3
License
Apache-2.0
Repository
github
Last release
5 years ago

signun

NPM version Build Status

signun provides sync and async N-API bindings to the following crypto libraries:

  • secp256k1
    • privateKeyVerify,
    • publicKeyCreate,
    • sign
      • Note: custom nonce function not yet supported for async, however it works with sync.
    • verify.

Install

Install with npm or yarn:

npm i signun --save
yarn add signun

Please keep in mind, that you must have GMP installed (signun will not fallback to JS-only implementations).

Examples

secp256k1 ECDSA

Sync

const { randomBytes } = require('crypto');
const { secp256k1 } = require('signun');


let privateKey;

do {
    privateKey = randomBytes(32)
} while (!secp256k1.privateKeyVerifySync(privateKey));

const publicKey = secp256k1.publicKeyCreateSync(privateKey);

const message = randomBytes(32);

const signOptions = {
    // 32 bytes of custom data.
    data: null,
    // Custom nonce function.
    noncefn: null
}

const signResult =  secp256k1.signSync(message, privateKey, signOptions);

const verifyResult =  secp256k1.verifySync(message, signResult.signature, publicKey);

console.log(verifyResult);

Async

const { randomBytes } = require('crypto');
const { secp256k1 } = require('signun');


(async function main() {
    let privateKey;

    do {
        privateKey = randomBytes(32)
    } while (!(await secp256k1.privateKeyVerify(privateKey)));
    
    const publicKey = await secp256k1.publicKeyCreate(privateKey);
    
    const message = randomBytes(32);
    
    // Custom nonce function is not supported yet for async.
    const signOptions = {
        // 32 bytes of custom data.
        data: null
    }
    
    const signResult =  await secp256k1.sign(message, privateKey, signOptions);
    
    const verifyResult =  await secp256k1.verify(message, signResult.signature, publicKey);
    
    console.log(verifyResult);    
})();

Acknowledgements

This project is kindly supported by:

I'd like to give special thanks to Viktor Simkó and Tibor Balla for helping me out when I was lost :unicorn:

License

signun is licensed under Apache-2.0.

Licenses of dependencies:

1.2.0

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago