<commit_before># Crypto Profiles

[![npm](https://img.shields.io/npm/l/crypto-profiles.svg)](https://www.npmjs.com/package/crypto-profiles)
[![npm](https://img.shields.io/npm/v/crypto-profiles.svg)](https://www.npmjs.com/package/crypto-profiles)
[![npm](https://img.shields.io/npm/dm/crypto-profiles.svg)](https://www.npmjs.com/package/crypto-profiles)
[![Slack](http://slack.blockstack.org/badge.svg)](http://slack.blockstack.org/)

A library for working with cryptographically-signed JSON profiles.

This library can be used to:

1. transform a JSON profile into signed tokens
1. recover a JSON profile from signed tokens
1. validate signed profile tokens

### Installation

```
$ npm install crypto-profiles
```

### Module importing

#### ES6

```es6
import { signProfileTokens, getProfileFromTokens } from 'crypto-profiles'
import { PrivateKeychain, PublicKeychain } from 'elliptic-keychain'
```

#### Javascript

```js
var signProfileTokens = require('crypto-profiles').signProfileTokens,
    getProfileFromTokens = require('crypto-profiles').getProfileFromTokens

var PrivateKeychain = require('elliptic-keychain').PrivateKeychain,
    PublicKeychain = require('elliptic-keychain').PublicKeychain
```

### Create a profile

```js
var balloonDog = {
  "@context": "http://schema.org/",
  "@type": "CreativeWork",
  "name": "Balloon Dog",
  "creator": [
    {
      "@type": "Person",
      "name": "<NAME>",
      "id": "therealjeffkoons.id"
    }
  ],
  "dateCreated": "1994-05-09T00:00:00-0400",
  "datePublished": "2015-12-10T14:44:26-0500"
}
```

### Transform the profile to signed tokens

```js
> var privateKeychain = new PrivateKeychain()
> var tokenRecords = signProfileTokens([balloonDog], privateKeychain)
> console.log(tokenRecords)
[
  {
    "token": "<KEY>",
    "data": {
      "header": {
        "typ": "JWT",
        "alg": "ES256K"
      },
      "payload": {
        "claim": {
          "@context": "http://schema.org/",
          "@type": "CreativeWork",
          "name": "<NAME>",
          "creator": [
            {
              "@type": "Person",
              "name": "<NAME>",
              "id": "therealjeffkoons.id"
            }
          ],
          "dateCreated": "1994-05-09T00:00:00-0400",
          "datePublished": "2015-12-10T14:44:26-0500"
        },
        "subject": "<KEY>",
        "issuedAt": "2016-02-03T06:24:43.745Z",
        "expiresAt": 1486103083745
      },
      "signature": "lpw10Jy--NMe2Tn_Rc1AXYm6TcFw1TdbVZ_dBECte5tKTDIbnNNO80mvNkrofT3YZEQb36jLEfiijiao7gM0Cw"
    },
    "publicKey": "<KEY>",
    "parentPublicKey": "<KEY>",
    "derivationEntropy": "e15dfbe9986d8914fac948a131426c57a940185e298368e22ad34fedeb47a110",
    "encrypted": false
  }
]
```

### Recover the profile from the tokens

```js
> var publicKeychain = privateKeychain.publicKeychain()
> var recoveredProfile = getProfileFromTokens(tokenRecords, publicKeychain)
> console.log(recoveredProfile)
{ '@context': 'http://schema.org/',
  '@type': 'CreativeWork',
  name: '<NAME>',
  creator: 
   [ { '@type': 'Person',
       name: '<NAME>',
       id: 'therealjeffkoons.id' } ],
  dateCreated: '1994-05-09T00:00:00-0400',
  datePublished: '2015-12-10T14:44:26-0500' }
```<commit_msg>update README to include zonefile interface<commit_after># Crypto Profiles

[![npm](https://img.shields.io/npm/l/crypto-profiles.svg)](https://www.npmjs.com/package/crypto-profiles)
[![npm](https://img.shields.io/npm/v/crypto-profiles.svg)](https://www.npmjs.com/package/crypto-profiles)
[![npm](https://img.shields.io/npm/dm/crypto-profiles.svg)](https://www.npmjs.com/package/crypto-profiles)
[![Slack](http://slack.blockstack.org/badge.svg)](http://slack.blockstack.org/)

A library for working with cryptographically-signed JSON profiles.

This library can be used to:

1. transform a JSON profile into signed tokens
1. recover a JSON profile from signed tokens
1. validate signed profile tokens

### Installation

```
$ npm install crypto-profiles
```

### Module importing

#### ES6

```es6
import { signProfileTokens, getProfileFromTokens } from 'crypto-profiles'
import { PrivateKeychain, PublicKeychain } from 'elliptic-keychain'
```

#### Javascript

```js
var signProfileTokens = require('crypto-profiles').signProfileTokens,
    getProfileFromTokens = require('crypto-profiles').getProfileFromTokens

var PrivateKeychain = require('elliptic-keychain').PrivateKeychain,
    PublicKeychain = require('elliptic-keychain').PublicKeychain
```

### Create a profile

```js
var balloonDog = {
  "@context": "http://schema.org/",
  "@type": "CreativeWork",
  "name": "Balloon Dog",
  "creator": [
    {
      "@type": "Person",
      "name": "<NAME>",
      "id": "therealjeffkoons.id"
    }
  ],
  "dateCreated": "1994-05-09T00:00:00-0400",
  "datePublished": "2015-12-10T14:44:26-0500"
}
```

### Transform the profile to signed tokens

```js
> var privateKeychain = new PrivateKeychain()
> var tokenRecords = signProfileTokens([balloonDog], privateKeychain)
> console.log(tokenRecords)
[
  {
    "token": "<KEY>",
    "data": {
      "header": {
        "typ": "JWT",
        "alg": "ES256K"
      },
      "payload": {
        "claim": {
          "@context": "http://schema.org/",
          "@type": "CreativeWork",
          "name": "<NAME>",
          "creator": [
            {
              "@type": "Person",
              "name": "<NAME>",
              "id": "therealjeffkoons.id"
            }
          ],
          "dateCreated": "1994-05-09T00:00:00-0400",
          "datePublished": "2015-12-10T14:44:26-0500"
        },
        "subject": "<KEY>",
        "issuedAt": "2016-02-03T06:24:43.745Z",
        "expiresAt": 1486103083745
      },
      "signature": "lpw10Jy--NMe2Tn_Rc1AXYm6TcFw1TdbVZ_dBECte5tKTDIbnNNO80mvNkrofT3YZEQb36jLEfiijiao7gM0Cw"
    },
    "publicKey": "<KEY>",
    "parentPublicKey": "<KEY>",
    "derivationEntropy": "e15dfbe9986d8914fac948a131426c57a940185e298368e22ad34fedeb47a110",
    "encrypted": false
  }
]
```

### Recover the profile from the tokens

```js
> var publicKeychain = privateKeychain.publicKeychain()
> var recoveredProfile = getProfileFromTokens(tokenRecords, publicKeychain)
> console.log(recoveredProfile)
{ '@context': 'http://schema.org/',
  '@type': 'CreativeWork',
  name: 'Balloon Dog',
  creator: 
   [ { '@type': 'Person',
       name: '<NAME>',
       id: 'therealjeffkoons.id' } ],
  dateCreated: '1994-05-09T00:00:00-0400',
  datePublished: '2015-12-10T14:44:26-0500' }
```

## Dealing with zonefiles

### Create a zonefile object

```js
var zonefile = new Zonefile(zonefileStringInput)
```

### Output the zonefile to JSON

```js
var zonefileJson = zonefile.toJSON()
```

### Output the zonefile as a string

```js
var zonefileString = zonefile.toString()
```
{'fraction_non_alphanumeric': 0.1738744075829384, 'fraction_numerical': 0.059834123222748815, 'mean_word_length': 3.559756920999325, 'pattern_counts': {'":': 66, '<': 20, '<?xml version=': 0, '>': 32, 'https://': 12, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1286589', 'n_tokens_mistral': 2645, 'n_tokens_neox': 2368, 'n_words': 411}