Noodles, Poodles and More!

    @tradle/kiki

    1.1.14 • Public • Published

    kiki

    Wrappers for DSA, EC, Bitcoin and other keys to provide a common API for signing/verifying/importing/exporting

    this module is used by Tradle

    Usage

    var kiki = require('kiki');
    var Keys = kiki.Keys
    
    // load ec public key
    var ecPubKey = new Keys.EC({
      pub: '022ee9fefd1b275d4ee1e7c41157cd4753ad4cbd0cbfdc76eef85ebae230bf27ee'
    })
    
    // load ec private key
    var ecPrivKey = new Keys.EC({
      priv: '01762d59097688a1f1cd241aadee4cb1bd3d37017f71501b28e85ecdab5349c2'
    })
    
    // new ec private key
    var newECKey = Keys.EC.gen({
      curve: 'ed25519'
    })
    
    // new bitcoin key
    var btcKey = Keys.Bitcoin.gen({
      networkName: 'bitcoin'
    })
    
    // new dsa key
    var dsaKey = Keys.DSA.gen()
    
    // keys with metadata
    btcKey = Keys.Bitcoin.gen({
      networkName: 'testnet',
      // arbitrary metadata
      label: 'most excellent key',
      purpose: 'messaging'
    })

    sync API (may not be supported for some keys)

    var sig = ecKey.signSync('hey ho') 
    var verified = ecKey.verifySync('hey ho', sig)

    async API (supported for all keys)

    ecKey.sign('hey ho', function (err, sig) {
      // async is supported for all
      ecKey.verify('hey ho', function (err, verified) {
        // verified is a boolean
      })
    })

    export

    var pub = ecKey.exportPublic()
    var priv = ecKey.exportPrivate()

    pub

    {
      "curve": "ed25519",
      "fingerprint": "de26dffa5dc9e3866ea23d9120578b768b945b1385d8393d275d715470dd6056",
      "type": "ec",
      "value": "022ee9fefd1b275d4ee1e7c41157cd4753ad4cbd0cbfdc76eef85ebae230bf27ee",
      // whatever metadata you added
      "purpose": "sign",
      "label": "one key to rule them all"
    }

    priv

    {
      "curve": "ed25519",
      "fingerprint": "de26dffa5dc9e3866ea23d9120578b768b945b1385d8393d275d715470dd6056",
      "priv": "01762d59097688a1f1cd241aadee4cb1bd3d37017f71501b28e85ecdab5349c2",
      "type": "ec",
      "value": "022ee9fefd1b275d4ee1e7c41157cd4753ad4cbd0cbfdc76eef85ebae230bf27ee",
      // whatever metadata you added
      "purpose": "sign",
      "label": "one key to rule them all"
    }

    import

    // recover to typed instance (ECKey/DSAKey/etc.)
    var ecKey = kiki.toKey(pub || priv) 

    Key API

    (static) gen(options)

    Generate a new key. Different keys may have different required properties (this asymmetry can't be avoided.)

    hasDeterministicSig()

    Some keys have deterministic signatures - same outputs for the same inputs. Some don't.

    parsePub(pubKeyString)

    parsePriv(privKeyString)

    fingerprint()

    pubKeyString()

    exportPublic()

    exportPrivate()

    mock "secure element" API

    Simple mock for a "secure element" type API, where you don't have access to the private keys. Give it a public key, an operation and data, and it will perform signing, decrypting, etc.

    var kiki = require('kiki').kiki
    var secureEl = kiki(privKeys) // setup the mock secure element
    secureEl.sign(pubKey, msg, callback)
    secureEl.ecdh(ecPubKey1, ecPubKey2, callback)

    Keywords

    none

    Install

    npm i @tradle/kiki

    DownloadsWeekly Downloads

    43

    Version

    1.1.14

    License

    MIT

    Last publish

    Collaborators

    • leichtgewicht
    • tenaciousmv
    • pgmemk
    • spwilko
    • genevayngrib