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

pii-agent-ts

v1.2.35

Published

FABD Horizontal PII Agent Libraries

Downloads

548

Readme

AGENT PII (TypeScript)

API Client

  • [x] encryptWithAes
  • [x] decryptWithAes
  • [x] DBColumn
  • [x] BidxCol
  • [x] TxtHeapTable
  • [x] buildBlindIndex
  • [x] searchContents
  • [x] searchContentFullText
  • [x] split
  • [x] AesCipher

Installation this package to your project

  1. Run npm or yarn to install:

    npm i pii-agent-ts
  2. Set the keys in your .env file:

    CRYPTO_AES_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    CRYPTO_HMAC_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    
    DB_AUTH_HOST=localhost
    DB_AUTH_PORT=5xxx
    DB_AUTH_USERNAME=username
    DB_AUTH_PASSWORD=password
    DB_AUTH_DATABASE=db_name

Usage Examples

Create Table Text Heap in Your DB

CREATE TABLE IF NOT EXISTS "npwp_text_heap" (
	"id" UUID NOT NULL DEFAULT uuid_generate_v4(),
	"content" VARCHAR NOT NULL,
	"hash" VARCHAR NOT NULL,
	PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "name_text_heap" (
	"id" UUID NOT NULL DEFAULT uuid_generate_v4(),
	"content" VARCHAR NOT NULL,
	"hash" VARCHAR NOT NULL,
	PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "phone_text_heap" (
	"id" UUID NOT NULL DEFAULT uuid_generate_v4(),
	"content" VARCHAR NOT NULL,
	"hash" VARCHAR NOT NULL,
	PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "email_text_heap" (
	"id" UUID NOT NULL DEFAULT uuid_generate_v4(),
	"content" VARCHAR NOT NULL,
	"hash" VARCHAR NOT NULL,
	PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "address_text_heap" (
	"id" UUID NOT NULL DEFAULT uuid_generate_v4(),
	"content" VARCHAR NOT NULL,
	"hash" VARCHAR NOT NULL,
	PRIMARY KEY ("id")
);

CREATE TABLE IF NOT EXISTS "nik_text_heap" (
	"id" UUID NOT NULL DEFAULT uuid_generate_v4(),
	"content" VARCHAR NOT NULL,
	"hash" VARCHAR NOT NULL,
	PRIMARY KEY ("id")
);

Define Column Encrypt

// entity.ts
import { AesCipher } from '../../crypto-ts/lib/types';
import CryptoTs from '../../index';
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";

@Entity('users')
export class User {
    @PrimaryGeneratedColumn('uuid')
    @CryptoTs.DBColumn('id')
    id: string;

    @Column('bytea')
    @CryptoTs.DBColumn('name')
    @CryptoTs.BidxCol('name_bidx')
    @CryptoTs.TxtHeapTable('name_text_heap')
    name: Buffer;

    @Column()
    name_bidx: string;

    @Column('bytea')
    @CryptoTs.DBColumn('email')
    @CryptoTs.BidxCol('email_bidx')
    @CryptoTs.TxtHeapTable('email_text_heap')
    email: Buffer;

    @Column()
    email_bidx: string;

    @Column('bytea')
    @CryptoTs.DBColumn('address')
    @CryptoTs.BidxCol('address_bidx')
    @CryptoTs.TxtHeapTable('address_text_heap')
    address: Buffer;

    @Column()
    address_bidx: string;

    @Column({ type: 'int', nullable: true, default: 25 }) // Define 'age' column as nullable
    @CryptoTs.DBColumn('age')
    age: number | null; // Adjust the type to accept null values

    @Column()
    @CryptoTs.DBColumn('password')
    password: string;

	@Column('bytea')
    @CryptoTs.DBColumn('phone')
    @CryptoTs.BidxCol('phone_bidx')
    @CryptoTs.TxtHeapTable('phone_text_heap')
    phone: Buffer;

    @Column()
    phone_bidx: string;

    @Column('bytea')
    @CryptoTs.DBColumn('nik')
    @CryptoTs.BidxCol('nik_bidx')
    @CryptoTs.TxtHeapTable('nik_text_heap')
    nik: Buffer;

    @Column()
    nik_bidx: string;

    @Column('bytea')
    @CryptoTs.DBColumn('npwp')
    @CryptoTs.BidxCol('npwp_bidx')
    @CryptoTs.TxtHeapTable('npwp_text_heap')
    npwp: Buffer;

    @Column()
    npwp_bidx: string;
}

Test Query

// index.ts
import CryptoTs from '../index';
import { User } from './entity/user_entity';

// Example usage
const main = async () => {

	const user = new User();
    user.name = CryptoTs.encryptWithAes('AES_256_CBC','Mohamad Ali Farhan');
    user.email = CryptoTs.encryptWithAes('AES_256_CBC','[email protected]');
    user.address = CryptoTs.encryptWithAes('AES_256_CBC', 'address yang rahasia');
	user.phone = CryptoTs.encryptWithAes('AES_256_CBC', '0899361349');
    user.nik = CryptoTs.encryptWithAes('AES_256_CBC', '3215012506200007');
    user.npwp = CryptoTs.encryptWithAes('AES_256_CBC', '311501230697000');
    user.age = 25;
    user.password = 'securepassword';

    const saveToHeap = await CryptoTs.buildBlindIndex(user);

	console.log('Insert With Heap :', saveToHeap);

};

main();

Test Search Content

import CryptoTs from '../index';

async function exampleGetHeapsByContent() {
	try {
        const inputValue = "Dy";
        const result = await CryptoTs.searchContents('name_text_heap', {content: inputValue});
        console.log('Result:', result);
    } catch (error) {
        console.error('Error fetching heaps by content:', error);
    }
}

exampleGetHeapsByContent();

Test Search Full Content

import CryptoTs from '../index';

async function exampleGetHeapsByFullContent() {
	try {
		const inputValue = "[email protected]"
		const splitValue = CryptoTs.split(inputValue)
        const result = await CryptoTs.searchContentFullText('email_text_heap', { contents: splitValue});
        console.log('Result:', result);
    } catch (error) {
        console.error('Error fetching heaps by content:', error);
    }
}

exampleGetHeapsByFullContent();

Test Encrypt and Decrypt

import CryptoTs from "../index";

const data = "Dyaksa";

// Encrypt
const encryptedHex = CryptoTs.encryptWithAes("AES_256_CBC", data);
console.log('Encrypted Data (Hex):', encryptedHex);

// Decrypt
const decryptedData =  CryptoTs.decryptWithAes("AES_256_CBC", encryptedHex.Value);
console.log('Encrypted Data:', decryptedData);

Change Log

See Changelog for more information.

Contributing

Contributions are welcome! See Contributing.

Author

License

Licensed under the MIT License - see the LICENSE file for details.