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

@soulwallet/keyvault

v0.2.0

Published

A lightweight private key management library

Downloads

311

Readme

Table of Contents

Installing

Using npm:

$ npm install @soulwallet/keyvault

Using yarn:

$ yarn add @soulwallet/keyvault

Using pnpm:

$ pnpm add @soulwallet/keyvault

Once the package is installed, you can import the library using import approach:

import { Vault, VaultEvents, SignData } from "@soulwallet/keyvault";

Example

import { Component, OnInit } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
import { Vault, VaultEvents, SignData, Ok, Err, Result } from '@soulwallet/keyvault';
import { SoulWallet } from '@soulwallet/sdk';
@Component({
  selector: 'app-keyvault',
  templateUrl: './keyvault.page.html',
  styleUrls: ['./keyvault.page.scss'],
})
export class KeyvaultPage implements OnInit {

  isInitialized: boolean = false;
  isLocked: boolean = false;
  Signers: string[] = [];

  password: string = 'password';
  privateKey: string = '0x4f7ef884a2fff8bcbfbe2377dd055e95acfae573a85d0217eb887b40c0ffa4d8';
  message: string = '0x426d3189d9ed64fbfab235f05d9a0e102d575939a951a93ec8bbdeef05cd707b';

  signData: Map<string, string> = new Map<string, string>();

  eventLog = '';

  vault: Vault;

  constructor(protected sanitizer: DomSanitizer) {
    this.vault = new Vault();
    /* 
      Initialized
      ReInitialized
      Locked
      Unlocked
      AccountAdded
      AccountRemoved
      Sign
      PersonalSign
      */
    this.vault.on('Initialized', () => {
      const ts = "<font color='red'>" + new Date().toLocaleTimeString() + "</font>";
      this.eventLog += ts + '&nbsp;' + 'Initialized<br/>-----<br/>';
    });
    this.vault.on('ReInitialized', () => {
      const ts = "<font color='red'>" + new Date().toLocaleTimeString() + "</font>";
      this.eventLog += ts + '&nbsp;' + 'ReInitialized<br/>-----<br/>';
    });

    this.vault.on('Locked', () => {
      const ts = "<font color='red'>" + new Date().toLocaleTimeString() + "</font>";
      this.eventLog += ts + '&nbsp;' + 'Locked<br/>-----<br/>';
    });

    this.vault.on('Unlocked', () => {
      const ts = "<font color='red'>" + new Date().toLocaleTimeString() + "</font>";
      this.eventLog += ts + '&nbsp;' + 'Unlocked<br/>-----<br/>';
    });

    this.vault.on('AccountAdded', (account: string) => {
      const ts = "<font color='red'>" + new Date().toLocaleTimeString() + "</font>";
      this.eventLog += ts + '&nbsp;' + 'AccountAdded:' + account + '<br/>-----<br/>';
    });

    this.vault.on('AccountRemoved', (account: string) => {
      const ts = "<font color='red'>" + new Date().toLocaleTimeString() + "</font>";
      this.eventLog += ts + '&nbsp;' + 'AccountRemoved:<br/>' + account + '<br/>-----<br/>';
    });

    this.vault.on('Sign', (signData: SignData) => {
      const ts = "<font color='red'>" + new Date().toLocaleTimeString() + "</font>";
      this.eventLog += ts + '&nbsp;' + 'Sign:<br/>' + JSON.stringify(signData) + '<br/>-----<br/>';
    });

    this.vault.on('PersonalSign', (signData: SignData) => {
      const ts = "<font color='red'>" + new Date().toLocaleTimeString() + "</font>";
      this.eventLog += ts + 'PersonalSign' + JSON.stringify(signData) + '<br/>-----<br/>';
    });
  }

  async ngOnInit() {
    await this.reload();
  }

  async reload() {
    this.isInitialized = (await this.vault.isInitialized()).OK;
    this.isLocked = (await this.vault.isLocked()).OK;
    this.Signers = (await this.vault.listSigners()).OK;
  }

  async init(enforce: boolean) {

    const re = await this.vault.init(this.password, enforce);
    if (re.isErr()) {
      alert(re.ERR.message);
    }

    await this.reload();
  }

  async unlock() {
    const re = await this.vault.unlock(this.password);
    if (re.isErr()) {
      alert(re.ERR.message);
    }
    await this.reload();
  }

  async lock() {
    const re = await this.vault.lock();
    if (re.isErr()) {
      alert(re.ERR.message);
    }
    await this.reload();
  }

  async importSigner() {
    const re = await this.vault.importSigner(this.privateKey);
    if (re.isErr()) {
      alert(re.ERR.message);
    } else {
      alert('address:' + re.OK);
    }
    await this.reload();
  }

  async createSigner() {
    const re = await this.vault.createSigner();
    if (re.isErr()) {
      alert(re.ERR.message);
    } else {
      alert('address:' + re.OK);
    }
    await this.reload();
  }

  async removeSigner(signer: string) {
    const re = await this.vault.removeSigner(signer);
    if (re.isErr()) {
      alert(re.ERR.message);
    }
    await this.reload();
  }

  async sign(signer: string) {
    const re = await this.vault.rawSign(signer, this.message);
    if (re.isErr()) {
      alert(re.ERR.message);
    } else {
      this.signData.set(signer + 'raw', re.OK);
      alert('signature:' + re.OK);
    }
    await this.reload();
  }

  getRawSign(signer: string): string {
    const key = signer + 'raw';
    if (this.signData.has(key)) {
      return this.signData.get(key)!;
    } else {
      return '--';
    }
  }

  async personalSign(signer: string) {
    const re = await this.vault.personalSign(signer, this.message);
    if (re.isErr()) {
      alert(re.ERR.message);
    } else {
      this.signData.set(signer + 'personal', re.OK);
      alert('signature:' + re.OK);
    }
    await this.reload();
  }
  getPersonalSign(signer: string): string {
    const key = signer + 'personal';
    if (this.signData.has(key)) {
      return this.signData.get(key)!;
    } else {
      return '--';
    }
  }

  getEventLog(): SafeHtml {
    return this.sanitizer.bypassSecurityTrustHtml(this.eventLog);
  }
}

License

ISC