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

@akord/crypto

v0.21.56

Published

In browser en-/decryption API

Downloads

1,310

Readme

@akord/crypto

In browser en-/decryption API

Module is helping in bringing the client apps into end-2-end encrypted, privacy-first world. No reinventig APIs, just facading well known libs to make those more developer friendly for majority of business cases.

e2e encryption

See here to learn more about e2e encryption @Akord

Installation

npm i @akord/crypto

Usage

  1. Configure the module:
  • for a new user - create wallet based on password (creates new wallet and backup phrase)
        Crypto.configure(
            { 
                password: "test"
            }
        )
  • for existing user with password adn backup phrase
        Crypto.configure(
            { 
                password: "test",
                encBackupPhrase: "yExlksth..."
            }
        )
  1. Use public api of the module to de/-encrypt:
  • decorators
  • functions

Decorators

Decorators are a way to go to abstract encryption from business logic. The goal of decorators API is really to "decorate" client side app with encryption

Use two high-level functions (encrypt & decrypt) as decorators like:

class User extends Encryptable {
    @encrypted()
    name: string;
    
    @encrypted()
    profileImageUrl: string;

    id: string

    constructor(name: string, profileImageUrl: string, keys: Array<Keys>, publicKey: string) {
        super(keys, publicKey);
        this.name = name;
        this.profileImageUrl = profileImageUrl;
    }    
}
const user = new User("yExlksth...", "https:/profile-image...", [{encPrivateKey: "yJbmdor...", publicKey: "yHklouu.." }], "yHuyks...")
await user.encrypt()

Same rules apply to methods and their parameters

    saveFooBar(
        @encrypted foo: string, 
        bar: string) {
        ...
    }

In the above foo param will be end up as encrypted string in method body. bar param will stay untouched.

Complex structures are supported:

    saveFooBar(
        @encrypted(attributes="encAttr1,encAttr2") foo: Foo, 
        bar: string) {
        ...
    }

    Foo {
        id: string
        encAttr1: string
        encAttr2: string
    }

and decryption goes like

class User extends Encryptable {
    
    @encrypted()
    name: string;
    
    @encrypted()
    profileImageUrl: string;

    id: string

    constructor(name: string, profileImageUrl: string, keys: Array<Keys>){
        this.name = name;
        this.profileImageUrl = profileImageUrl;
    }    
}

const user = new User("yExlksth...", [{encPrivateKey: "yJbmdor...", publicKey: "yHklouu.." }])
await user.decrypt()
    fetchBar(
        @decrypted param1: string,
        param2: HeaderParams
        ) {
        ...
    }

in the above param1 will be decreypted, param2 will not be touched. No need to refactor the code to split complex parameters into single string params:

    fetchBar(
        @decrypted(attributes="encAttr1,encAttr2") param1: QueryParams,
        param2: HeaderParams
        ) {
        ...
    }

    QueryParams {
        id: string
        encAttr1: string
        encAttr2: string
    }

In the above id from QueryParams will not be decrypted. Obviously HeaderParams will also stay untouched

Use as simple functions

...

Development

yarn install
yarn build

To run all tests:

yarn test

To run single test file:

yarn test <path-to-test-file>

yarn test ./src/__tests__/encrypt.test.ts

To run single test file with direct log output:

node --inspect node_modules/.bin/jest ./src/__tests__/wallet.test.ts