Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
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.3
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

phog

crypto functions for fognet and the web

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'],
    format: {public:'spki', private:'pkcs8'}
  },
  derive: {
    algo: {name:'ECDH', namedCurve:'P-256'},
    usage: ['deriveKey'],
    format: {public:'spki', private:'pkcs8'}
  },
  encrypt: {
    algo: {name:'AES-GCM', length: 256},
    usage: ['encrypt', 'decrypt'],
    format: {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)

Keywords

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc