# phog

> Dead simple crypto module for Fognet

Latest version **0.0.3** (published 2019-01-21) · 0 weekly downloads

## Install

```sh
npm install phog
pnpm add phog
yarn add phog
bun add phog
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2019-01-21 |
| First published | 2019-01-21 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 15.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Evan Feenstra |
| Maintainers | fognet |
| Keywords | fognet, crypto, cryptography, encryption, web crypto api, web crypto, iota, digital signature, aes, ecdsa, ecdh, derivation, key |

## Links

- npm: https://www.npmjs.com/package/phog
- npm.io page: https://npm.io/package/phog

## Dependencies (1)

- [simple-base](https://npm.io/package/simple-base.md) ^0.2.1

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 0.0.3 (latest) — 2019-01-21
- 0.0.2 — 2019-01-21
- 0.0.1 — 2019-01-21

## README

# 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
```javascript
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)
```javascript
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)
```javascript
const sig = await phog.sign(txt, key.privateKey)
```
### verify (string, string, CryptoKey)
Verify a signature (returns a bool)
```javascript
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)
```javascript
const secret = await phog.deriveKey(key.privateKey, key.publicKey)
```
### encrypt (string, CryptoKey)
Symmetrically encrypt some data (returns a base58-encoded string)
```javascript
const encrypted = await phog.encrypt(txt, secret)
```
### decrypt (string, CryptoKey)
Decrypt some data (returns a string)
```javascript
const decrypted = await phog.decrypt(encrypted, secret)
```
### exportKey (CryptoKey, object, string)
Export a public key to base58:
```javascript
const keyString = await phog.exportKey(key.publicKey, phog.configs.sign)
```
To export a private key, you must specify 'private' as the last argument:
```javascript
const keyString = await phog.exportKey(key.privateKey, phog.configs.sign, 'private')
```
### importKey (string, object, string)
Import a base58-encoded public key (returns a CryptoKey)
```javascript
const key = await phog.importKey(keyString, phog.configs.sign)
```

---
_Source: https://npm.io/package/phog · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
