npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

qcp

v0.3.0

Published

Quick Cryptico Protocol

Downloads

17

Readme

qcp - Quick Cryptico Protocol

Maintainability Test Coverage Build Status Commitizen friendly

QCP developed for those who use encryption in their apps. Basically it's class which can co-work with any kind of encryption library. But for examples we'll use cryptico

Installation

    # with yarn:
    yarn add qcp
    # with npm:
    npm i --save qcp

Usage

Import

    import {QuickCrypticoProtocol} from 'qcp';

or

    const QuickCrypticoProtocol = require('qcp').QuickCrypticoProtocol;

API

QCP goes through passed data, looking for private objects, takes them into hash map, replaces private objects to hash map id, serializes hash map and then encrypts it. And vice versa.

To mark object as private just add private: true property. Example:

    // this object won't be encrypted
    const example1 = {
        foo: 'bar'
    };

    // but this one will
    const example2 = {
        private: true,
        foo: 'bar'
    };

encrypt

Main method for encryption of object by protocol. Examples:

Primitives:

const example = 'test string';
const encoded = qcp.encode(example); // {public: 'test string'}

Arrays:

Array without private fields:
const example = ['test string'];
const encoded = qcp.encode(example); // {public: ['test string']}
Array with private fields:
const example = [
 {
   foo: 'bar',
   test: 1,
   private: true
 },
 {
   foo: 'bar',
   test: 2,
   private: true
 },
 'test'
];
const encoded = qcp.encode(example);
// {
//     public: ['0[Bsnz2rSBvg]', '1[hqusXQO7hi]', 'test'],
//     private: "{\"0[Bsnz2rSBvg]\":{\"foo\":\"bar\",\"test\":1,\"private\":true},\"1[hqusXQO7hi]\":{\"foo\":\"bar\",\"test\":2,\"private\":true}}"
// }

Objects:

Objects without private fields:
 const example = {foo: 'bar'};
 const encoded = qcp.encode(example); // {public: {foo: 'bar'}}
Root objects with private fields:
 const example = {
   foo: 'bar',
   private: true
 };
 const encoded = qcp.encode(example);
// {
//     public: 'public[odwHIurT6p]',
//     private: "{\"public[odwHIurT6p]\":{\"foo\":\"bar\",\"private\":true}}"
// }
Objects with nested private fields:
 const example = {
      foo: 'bar',
      test1: {
        foo: 'bar',
        test: 1,
        private: true
      },
      test2: {
        foo: 'bar',
        test: 2,
        private: true
      }
    };
 const encoded = qcp.encode(example);
// {
//     public: {
//        "foo": "bar",
//        "test1": "test1[b0HcZPqCFz]",
//        "test2": "test2[5_ZGyNtUhD]",
//     },
//     private: "{\"test1[b0HcZPqCFz]\":{\"foo\":\"bar\",\"test\":1,\"private\":true},\"test2[5_ZGyNtUhD]\":{\"foo\":\"bar\",\"test\":2,\"private\":true}}"
// }

decrypt

Main method for decryption of object by protocol. Works the same as encrypt method but in reverse order. Not throwing error if passed data is not by protocol.

encryptor/decryptor

Methods that should be overwritten to support encryption. Example:

import {QuickCrypticoProtocol} from 'qcp';
import * as cryptico from 'cryptico';

export class Protocol extends QuickCrypticoProtocol {
	constructor (private privateKey: string, private publicKey: string) {
		super();
	}

// `encryptor` - method for data encrypt.
// By default returns the same data as was passed.
	public encryptor (data: string) {
		return cryptico.encrypt(data, this.publicKey).cipher;
	}
// `decryptor` - method for data decrypt.
// By default returns the same data as was passed.
	public decryptor (data: string) {
		return cryptico.decrypt(data, this.privateKey).plaintext;
	}
}

Id Generation and Interpolation

Method that generates id for replaced object. For prevent ids collision, it adds random string. Interpolation can be enabled by specifying interpolationStart and interpolationEnd properties.

Serialize/Deserialize

Methods which serialize/deserialize data before encryption. By default JSON.stringify/JSON.parse used.

Copyright 2019 I. Panarin

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.