npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jolocom/vaulted-key-provider

v0.8.0

Published

<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-refresh-toc --> **Table of Contents**

Downloads

116

Readme

Vaulted Key Provider

Table of Contents

Vaulted Key Provider implements a simple, secure key store based on an encrypted UniversalWallet2020 instance and a set of utility functions implementing operations on the wallet, along with a simple crypto utility interface for anoncryption and signature verification. An implementation of the EncryptedWalletUtils and CryptoUtils is currently available with the @jolocom/native-core module. It builds upon a Rust implementation of the UniversalWallet2020 spec.

Usage

Wallet and Key Creation

import { walletUtils } from '@jolocom/native-core'
import { SoftwareKeyProvider } from '@jolocom/vaulted-key-provider'

// create an empty wallet
const id = "my_id"
const wallet = await SoftwareKeyProvider.newEmptyWallet(
    walletUtils,
    id,
    password
)

// or create from an existing encrypted wallet
const wallet = new SoftwareKeyProvider(walletUtils, encryptedWalletBuffer, id)

// add a new randomly generated secp256k1 signing key pair to the wallet
const newSigningKey = await wallet.newKeyPair(
    password,
    KeyTypes.ecdsaSecp256k1VerificationKey2019,
    `signing-key-1`
)
/*
{
   id: "urn:some-urn-identifier",
   publicKeyHex: "hex-encoded public key",
   type: "EcdsaSecp256k1VerificationKey2019",
   controller: ["signing-key-1"]
 }
 **/
 
// add a new randomly generated x25519 key agreement key pair to the wallet
const newEncryptionKey = await wallet.newKeyPair(
    password,
    KeyTypes.x25519KeyAgreementKey2019,
    `encryption-key-1`
)
/*
{
   id: "urn:some-urn-identifier",
   publicKeyHex: "hex-encoded public key",
   type: "X25519KeyAgreementKey2019",
   controller: ["encryption-key-1"]
 }
 **/

Signing and Verification

import { cryptoUtils } from '@jolocom/native-core'
import { getCryptoProvider } from '@jolocom/vaulted-key-provider'

const crypto = getCryptoProvider(cryptoUtils)

const data = Buffer.from("some arbitrary data")

// create a signature using newSigningKey generated previously
const signature = await wallet.sign({
    encryptionPass: password,
    keyRef: "signing-key-1"
}, data)

const isValid = await crypto.verify(
    Buffer.from(newSigningKey.publicKeyHex, 'hex'),
    newSigningKey.type,
    data,
    signature
)
// true

Encryption and Decryption

const plaintext = Buffer.from("some arbitrary data")

// encrypt to newEncryptionKey generated previously
const ciphertext = await crypto.encrypt(
    Buffer.from(newEncryptionKey.publicKeyHex, 'hex'),
    KeyTypes.x25519KeyAgreementKey2019,
    plaintext
)

// decrypt using newEncryptionKey generated previously
const decrypted = await wallet.decrypt({
    encryptionPass: password,
    keyRef: "encryption-key-1"
}, ciphertext)

// decrypted.toString() === "some arbitrary data"

Structure

This package defines two purely functional APIs for performing crypto operations:

  • CryptoUtils: Public Key crypto operations (anoncryption + verification)
  • EncryptedWalletUtils: Private Key crypto operations (decryption + signing)

Additionally it exposes two higher level idiomatic Typescript interfaces:

  • ICryptoProvider: A general purpose Public Key crypto provider. Intended to be used as a high-level, simple API for anoncryption, signature verification and random number generation. Implementations should be fully stateless.
  • IVaultedKeyProvider: (implemented by SoftwareKeyProvider): A secure encrypted Key store and Private Key crypto provider. This interface is intended to be implemented by a class with two internal state objects, an ID and an encrypted state buffer.

Finally, these interfaces are implemented by two components which consume implementations of the lower-level APIs:

  • getCryptoProvider: Take a CryptoUtils implementation and returns an ICryptoProvider implementation.
  • SoftwareKeyProvider: A class which takes an EncryptedWalletUtils implementation and (combined with internal state) implements a simple, easy to use, secure key store implementing IVaultedKeyProvider.