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

@vocdoni/signing

v1.16.2

Published

JavaScript/TypeScript signing package

Downloads

15

Readme

@vocdoni/signing

@vocdoni/signing contains signing helpers for the dvote-js library

Installation

Use npm to install @vocdoni/signing.

npm install @vocdoni/signing

Usage

BytesSignature

import { BytesSignature } from "@vocdoni/signing";
import { Wallet } from "@ethersproject/wallet";

const wallet = new Wallet(
  "8d7d56a9efa4158d232edbeaae601021eb3477ad77b5f3c720601fd74e8e04bb",
);

const body = "hello world";
const bodyBytes = new TextEncoder().encode(message);

// Signing messages

const msgSignature = await BytesSignature.signMessage(bodyBytes, wallet);
// returns '0x578ef5489a30afafc89ea1e39154140e73b9cf9d23da11e1eeb9358cd1c862382027e46da51c686ddcde3b0e6f13d82b418c691a1267b285f24f99e0669b23951b'

BytesSignature.isValidMessage(bodyBytes, msgSignature, wallet.publicKey);
// returns 'true'

BytesSignature.recoverMessagePublicKey(bodyBytes, msgSignature);
// returns '0x02cb3cabb521d84fc998b5649d6b59e27a3e27633d31cc0ca6083a00d68833d5ca'

// Signing transactions

const chainId = "production";
const txSignature = await BytesSignature.signTransaction(
  bodyBytes,
  chainId,
  wallet,
);
// returns '0xaccdc8d0537bad80fde86ddd0c28f0f4fa59f1225da4ae18ad73bfe27860d7bf0fb884f659b82a11e08f5875ca9728c07b0bfd30e7c47a8f9b3874b9e25944751c'

BytesSignature.isValidTransaction(
  bodyBytes,
  chainId,
  txSignature,
  wallet.publicKey,
);
// returns 'true'

BytesSignature.recoverTransactionPublicKey(
  bodyBytes,
  chainId,
  txSignature,
);
// returns '0x02cb3cabb521d84fc998b5649d6b59e27a3e27633d31cc0ca6083a00d68833d5ca'

JsonSignature

import { JsonSignature } from "@vocdoni/signing";
import { computePublicKey } from "@ethersproject/signing-key";
import { Wallet } from "@ethersproject/wallet";

const wallet = new Wallet(
  "8d7d56a9efa4158d232edbeaae601021eb3477ad77b5f3c720601fd74e8e04bb",
);
const jsonBody = { a: 1, b: "hi", c: false, d: [1, 2, 3, 4, 5, 6] };

// Signing messages

const msgSignature = await JsonSignature.signMessage(jsonBody, wallet);
// returns '0x40cd233894286b078667361b636e7e961072af579228ef8af3691cd5cdd1e5177984ceb65028a9fa8b0b8230c095cbe1b9dd244d5dee4febba67e01b34242fd41c'

JsonSignature.isValidMessage(jsonBody, msgSignature, wallet.publicKey);
// returns 'true'

JsonSignature.recoverMessagePublicKey(jsonBody, msgSignature);
// returns '0x02cb3cabb521d84fc998b5649d6b59e27a3e27633d31cc0ca6083a00d68833d5ca'

// Signing transactions

const chainId = "production";
const txSignature = await JsonSignature.signTransaction(
  jsonBody,
  chainId,
  wallet,
);
// returns '0xb37f025532f7f2efe41a89f9b037fbca02c00e3594305b9654558fc6c600594d3cabfd72acd1c0d0933756485072a77424bfe7f02f6b0472cd136dbd7ee5e9ca1c'

JsonSignature.isValidTransaction(
  jsonBody,
  chainId,
  txSignature,
  wallet.publicKey,
);
// returns 'true'

JsonSignature.recoverTransactionPublicKey(jsonBody, chainId, txSignature);
// returns '0x02cb3cabb521d84fc998b5649d6b59e27a3e27633d31cc0ca6083a00d68833d5ca'

normalizeJsonToString

import { JsonSignature } from "@vocdoni/signing";

JsonSignature.normalizedJsonString({ a: 1, b: 2 });
// '{"a":2,"b":1}'

JsonSignature.normalizedJsonString({ b: 1, a: 2 });
// '{"a":2,"b":1}'

const strA = JsonSignature.normalizedJsonString({
  a: 1,
  b: [{ a: 10, m: 10, z: 10 }, { b: 11, n: 11, y: 11 }, 4, 5],
});
const strB = JsonSignature.normalizedJsonString({
  b: [{ z: 10, m: 10, a: 10 }, { y: 11, n: 11, b: 11 }, 4, 5],
  a: 1,
});
// strA === strB

sortJson

import { JsonSignature } from "@vocdoni/signing";

JsonSignature.sort({ a: 1, b: 2 });
// {a: 1, b: 2}

JsonSignature.sort({ b: 1, a: 2 });
// {b: 1, a: 2}

const strA = JSON.stringify(
  JsonSignature.sort({
    a: 1,
    b: [{ a: 10, m: 10, z: 10 }, { b: 11, n: 11, y: 11 }, 4, 5],
  }),
);
const strB = JSON.stringify(
  JsonSignature.sort({
    b: [{ z: 10, m: 10, a: 10 }, { y: 11, n: 11, b: 11 }, 4, 5],
    a: 1,
  }),
);
// strA === strB

Testing

To execute library tests just run

npm run test