New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@akord/crypto

Package Overview
Dependencies
Maintainers
4
Versions
154
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@akord/crypto

In browser en-/decryption API

latest
Source
npmnpm
Version
0.21.56
Version published
Maintainers
4
Created
Source

@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

  • 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..."
            }
        )
  • 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

Keywords

cryptography

FAQs

Package last updated on 27 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts