1.6.8 • Published 4 years ago

fluree-cryptography v1.6.8

Weekly downloads
6
License
ISC
Repository
github
Last release
4 years ago

Fluree Cryptography

A collection of Javascript cryptography functions for Fluree

npm install fluree-cryptography 

API

Generate Keys

Returns a hex string of a public and private key pair.

import { generateKeyPair } from 'fluree-cryptography';

const { publicKey, privateKey }  = generateKeyPair();

Get Auth ID from Public Key

Returns the _auth/id that accompanies a given public key.

import { generateKeyPair, getSinFromPublicKey } from 'fluree-cryptography';

const { publicKey }  = generateKeyPair();
const authId = getSinFromPublicKey(publicKey);

Sign Transaction

signTransaction returns an object with the keys: sig, cmd, which should then be sent in the body of a request to the /command endpoint.

import { generateKeyPair, getSinFromPublicKey, signTransaction } from 'fluree-cryptography';

const { publicKey, privateKey }  = generateKeyPair();
const authId = getSinFromPublicKey(publicKey);

const db = "test/one";
const expire = Date.now() + 1000;
const fuel = 100000;
const nonce = 1; 
// Deps is an optional parameter - it is a array of _tx/ids that must have succeeded
// for the current transaction to be accepted.
const deps = null; 

const tx = JSON.stringifiy([{
    "_id": "_tag",
    "id": "tag/test" }])

const command = signTransaction(authId, db, expire, fuel, nonce, privateKey, tx, deps)

const fetchOpts = {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(body)
  };

const fullURI = `https://localhost:8090/fdb/${db}/command`;

fetch(fullURI, fetchOpts)

Sign Query

signQuery returns an object with the keys: header, method, body, which should then be sent to any of the query endpoints (/query, /multi-query, history, block).

import { generateLeyPair, getSinFromPublicKey, signQuery } from 'fluree-cryptography';

const { privateKey }  = generateKeyPair();
const authId = getSinFromPublicKey(publicKey);

const param = JSON.stringify({select: ["*"], from: "_collection"});
const db = "test/one";
const host = "localhost";
const queryType = "query";


const fetchOpts = signQuery(privateKey, param, queryType, host, db)

const fullURI = `https://localhost:8090/fdb/${db}/query`;

fetch(fullURI, fetchOpts)
1.6.8

4 years ago

1.6.7

4 years ago

1.6.6

5 years ago

1.6.5

5 years ago

1.6.4

5 years ago

1.6.3

5 years ago

0.1.0

5 years ago

1.6.2

5 years ago

1.6.1

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago