JSPM

ara-secret-storage

0.2.1
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 5
    • Score
      100M100P100Q47422F
    • License LGPL-3.0

    ARA RFC 0001 Secret Storage implementation

    Package Exports

    • ara-secret-storage
    • ara-secret-storage/decrypt
    • ara-secret-storage/encrypt

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ara-secret-storage) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    ara-secret-storage

    This module implements ARA RFC 0001.

    Status

    Stable

    Installation

    $ npm install arablocks/ara-secret-storage

    From Source

    Please make sure have the latest version of nodejs and make installed on your machine. This will only work for Linux and macOS users.

    $ git clone git@github.com:AraBlocks/ara-secret-storage.git
    $ cd ara-secret-storage
    $ make
    $ make install # you may need sudo

    API

    storage.encrypt(value, opts)

    Encrypts value into a "crypto" object configured by an initialization vector (iv) and secret key (key) with optional cipher and digest algorithms.

    const storage = require('ara-secret-storage')
    const crypto = require('ara-crypto')
    
    const message = Buffer.from('hello')
    const key = Buffer.alloc(16).fill('key')
    const iv = crypto.randomBytes(16)
    const enc = storage.encrypt(message, { key, iv })
    console.log(enc)

    Should output:

    { id: 'a83f4ea0-f486-4d32-82ec-8a047bd085a7',
      version: 0,
      crypto:
        { cipherparams: { iv: 'a292924998b67cf8d1abcb5f1174e7de' },
          ciphertext: '5e46475c92',
          cipher: 'aes-128-ctr',
          digest: 'sha1',
          mac: '702deecad7b3bf12ae9bcff7cfd13ee24e43cd13' } }
    

    storage.decrypt(value, opts)

    Decrypt an encrypted "crypto" object into the originally encoded buffer.

    Where

    • value - is a JSON object from the output of storage.encrypt()
    • opts - An object containing parameters used for decryption that can overload the cipher parameters found in the secret storage JSON object.
    const storage = require('ara-secret-storage')
    const crypto = require('ara-crypto')
    
    const message = Buffer.from('hello')
    const key = Buffer.alloc(16).fill('key')
    const iv = crypto.randomBytes(16)
    const enc = storage.encrypt(message, { key, iv })
    const dec = storage.decrypt(enc, { key })
    assert(0 == Buffer.compare(dec, message))

    Contributing

    Releases follow Semantic Versioning

    See Also

    License

    LGPL-3.0