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

@dhealth/qr-library

v1.0.0

Published

QR Codes library for dHealth Network

Downloads

5

Readme

@dhealth/qr-library

npm version Discord

Library to generate QR codes for dHealth Network.

NOTE: The author of this package cannot be held responsible for any loss of money or any malintentioned usage forms of this package. Please use this package with caution.

Features

The software allows you to create the following QR types:

  • TransactionRequest: QR to prepare transactions ready to be signed.
  • Address: QR to share the account address with others.
  • Contact: QR to share the account address and public key with others.
  • Mnemonic: QR to generate account mnemonic backups (encrypted | plain).
  • Account: QR to generate account private key backups (encrypted | plain).
  • Object: QR to export a custom object.

Requirements

  • Node.js 12 LTS

Installation

npm install @dhealth/qr-library

Usage

Generate QRCode for a Transaction Request

import { QRCodeGenerator, TransactionQR } from '@dhealth/qr-library';
import { Address, Deadline, Mosaic, NamespaceId, NetworkType, PlainMessage, TransferTransaction, UInt64 } from "@dhealth/sdk";

// (Optional) create transfer transaction (or read from network)
const transfer = TransferTransaction.create(
  Deadline.create(),
  Address.createFromPublicKey(
    'C5C55181284607954E56CD46DE85F4F3EF4CC713CC2B95000FA741998558D268',
    NetworkType.MAIN_NET
  ),
  [new Mosaic(new NamespaceId('dhealth.dhp'), UInt64.fromUint(10000000))],
  PlainMessage.create('Welcome to dHealth!'),
  NetworkType.MAIN_NET
);

// generation hash of the connected network
const generationHash = 'ED5761EA890A096C50D3F50B7C2F0CCB4B84AFC9EA870F381E84DDE36D04EF16'

// create QR Code base64
const qrCode: TransactionQR = QRCodeGenerator.createTransactionRequest(transfer, NetworkType.MAIN_NET, generationHash);

// get base64 notation for <img> HTML attribute
const base64 = qrCode.toBase64();

Generate AddressQR code

import { QRCodeGenerator, AddressQR } from '@dhealth/qr-library';
import { NetworkType } from '@dhealth/sdk';

const name = 'test-address-1';
const contactAddress = 'TA6QZTYPOIYQYR5NRY4WQ2WRQUX2FN5UK2DO6DI'

// generation hash of the connected network
const generationHash = 'ED5761EA890A096C50D3F50B7C2F0CCB4B84AFC9EA870F381E84DDE36D04EF16'

// create QR Code base64
const qrCode: AddressQR = QRCodeGenerator.createExportAddress(name, contactAddress, NetworkType.MAIN_NET, generationHash);

// get base64 notation for <img> HTML attribute
const base64 = qrCode.toBase64();

Generate ContactQR code

import { QRCodeGenerator, ContactQR } from '@dhealth/qr-library';
import { NetworkType } from '@dhealth/sdk';

const name = 'test-contact-1';
const accountPublicKey = 'C5C55181284607954E56CD46DE85F4F3EF4CC713CC2B95000FA741998558D268'

// generation hash of the connected network
const generationHash = 'ED5761EA890A096C50D3F50B7C2F0CCB4B84AFC9EA870F381E84DDE36D04EF16'

// create QR Code base64
const qrCode: ContactQR = QRCodeGenerator.createAddContact(name, accountPublicKey, NetworkType.MAIN_NET, generationHash);

// get base64 notation for <img> HTML attribute
const base64 = qrCode.toBase64();

Generate QRCode for a Mnemonic data

import { QRCodeGenerator, MnemonicQR } from '@dhealth/qr-library';
import { NetworkType } from '@dhealth/sdk';
import { MnemonicPassPhrase } from '@dhealth/hd-wallets';

// create a mnemonic and password.
const mnemonic = MnemonicPassPhrase.createRandom();

// generation hash of the connected network
const generationHash = 'ED5761EA890A096C50D3F50B7C2F0CCB4B84AFC9EA870F381E84DDE36D04EF16'

// create QR Code base64
const encryptedMnemonicQR: MnemonicQR = new MnemonicQR(mnemonic.plain, NetworkType.MAIN_NET, generationHash, 'password');
// or
const plainMnemonicQR: MnemonicQR = new MnemonicQR(mnemonic.plain, NetworkType.MAIN_NET, generationHash); // no password

// get base64 notation for <img> HTML attribute
const base64 = encryptedMnemonicQR.toBase64();

The produced Base64 encoded payload can be used to display the QR Code. An example of display can be done easily with HTML, as follows:

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Transfer Transaction QR code" />

Generate QRCode for an Account Private Key

import { QRCodeGenerator, AccountQR } from '@dhealth/qr-library';
import { NetworkType } from '@dhealth/sdk';

const accountPrivateKey = 'F97AE23C2A28ECEDE6F8D6C447C0A10B55C92DDE9316CCD36C3177B073906978'

// generation hash of the connected network
const generationHash = 'ED5761EA890A096C50D3F50B7C2F0CCB4B84AFC9EA870F381E84DDE36D04EF16'

// create QR Code base64
const encryptedAccountQR: AccountQR = QRCodeGenerator.createExportAccount(accountPrivateKey, NetworkType.MAIN_NET, generationHash, 'password')
const plainAccountQR: AccountQR = QRCodeGenerator.createExportAccount(accountPrivateKey, NetworkType.MAIN_NET, generationHash) // no password

// get base64 notation for <img> HTML attribute
const base64 = encryptedAccountQR.toBase64();

Generate QRCode for a custom object

import { QRCodeGenerator, ObjectQR } from '@dhealth/qr-library';
import { NetworkType } from '@dhealth/sdk';

// define custom object to suit your application use case.
const object = {"obj": "test"};

// generation hash of the connected network
const generationHash = 'ED5761EA890A096C50D3F50B7C2F0CCB4B84AFC9EA870F381E84DDE36D04EF16'

// create QR Code base64
const qrCode: ObjectQR = QRCodeGenerator.createExportObject(object, NetworkType.MAIN_NET, generationHash);

// get base64 notation for <img> HTML attribute
const base64 = qrCode.toBase64();

Getting help

Use the following available resources to get help:

Contributing

Contributions are welcome and appreciated. Check CONTRIBUTING for information on how to contribute.

License

Copyright (c) 2022-present, Grégory Saive for dHealth Network, All rights reserved.

Licensed under the Apache License 2.0