You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

phog

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

phog

Dead simple crypto module for Fognet

0.0.2
npmnpm
Version published
Weekly downloads
1
-83.33%
Maintainers
1
Weekly downloads
 
Created
Source

phog

dead simple crypto functions for fognet

phog uses the Web Crypto API and base 58 encoding

open test.html in any browser to test

phog configs

const configs = {
  sign: {
    algo: {name: 'ECDSA', namedCurve: 'P-256'},
    usage: ['sign', 'verify'],
    export: {public:'spki', private:'pkcs8'}
  },
  derive: {
    algo: {name:'ECDH', namedCurve:'P-256'},
    usage: ['deriveKey'],
    export: {public:'spki', private:'pkcs8'}
  },
  encrypt: {
    algo: {name:'AES-GCM', length: 256},
    usage: ['encrypt', 'decrypt'],
    export: {public:'raw', private:'raw'},
    ivFunc: () => window.crypto.getRandomValues(new Uint8Array(12))
  }
}

api

keyGen (object)

Generate a key (returns a CryptoKey pair)

const key = await phog.keyGen(phog.configs.sign) // for signing
const key = await phog.keyGen(phog.configs.derive) // for deriving shared keys
// returns { publicKey:CryptoKey{}, privateKey:CryptoKey{} }

sign (string, CryptoKey)

Sign some text (returns base58-encoded signature string)

const sig = await phog.sign(txt, key.privateKey)

verify (string, string, CryptoKey)

Verify a signature (returns a bool)

const verified = await phog.verify(txt, sig, importedPubKey)

deriveKey (CryptoKey, CryptoKey)

Derive a shared symmetric key from your private key and another person's public key. (returns a CryptoKey)

const secret = await phog.deriveKey(key.privateKey, key.publicKey)

encrypt (string, CryptoKey)

Symmetrically encrypt some data (returns a base58-encoded string)

const encrypted = await phog.encrypt(txt, secret)

decrypt (string, CryptoKey)

Decrypt some data (returns a string)

const decrypted = await phog.decrypt(encrypted, secret)

exportKey (CryptoKey, object, string)

Export a public key to base58:

const keyString = await phog.exportKey(key.publicKey, phog.configs.sign)

To export a private key, you must specify 'private' as the last argument:

const keyString = await phog.exportKey(key.privateKey, phog.configs.sign, 'private')

importKey (string, object, string)

Import a base58-encoded public key (returns a CryptoKey)

const key = await phog.importKey(keyString, phog.configs.sign)

FAQs

Package last updated on 21 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts