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

pivx-shield

v1.2.0

Published

WASM library for interoperation with the PIVX Shield sapling protocol.

Downloads

506

Readme

PIVX Shield

WASM library for interoperation with the PIVX Shield sapling protocol. It supports:

  • Generating addresses with the zip32 protocol,
  • Shield and transparent transactions,
  • Multicore support with backwards compatibility for older browsers
  • Transaction progress status
  • The ability to save and load the sync status

Getting started

Install

To install the library, simply run npm i pivx-shield. Then import it in your project with

import { PIVXShield } from "pivx-shield";

Examples

To use the class, it must first be synced with:

import { PIVXShield as Shield } from "pivx-shield";

// This is an array of 64 random bytes, usually derived from a Seed phrase
// For instance with https://github.com/bitcoinjs/bip39
const yourSeed = ...;
const shield = await Shield.create({
	seed: yourSeed,
	// This should be the block of birth of the wallet.
	// Put 0 if you don't know when it was created,
	// If you have to guess, pick a date when you definetely
	// didn't have the wallet
	blockHeight: 1164767,
	coinType: 1, // Testnet
	accoutnIndex: 0,
});
// getLastSyncedBlock will start from the first checkpoint it finds. 
for (let block = shield.getLastSyncedBlock();  block < current_block_height; block++)  {
	// You need to provide a function that fetches block information
	// For example with a simple GET request to a blockbook explorer
	// https://testnet.rockdev.org/api/v2/block/1164637
	const blockData = your_fetch_block_function(block);
	await shield.handleBlock(blockData);
}
console.log(shield.getBalance());
console.log(await shield.getNewAddress());

You can also save and load the public data, for a faster sync

// This return a string with the public shield data
const data = await shield.save();
localStorage.setItem("shield", data);
const data = localStorage.getItem("shield");
const seed = ...;
const shield = await Shield.create({
	data,
	seed,
	// testnet
	coinType: 1,
	accountIndex: 0,
});

// Will return the block from when save was called
console.log(shield.getLastSyncedBlock());

To create a transaction,

import { PIVXShield as Shield } from "pivx-shield";

const shield = await Shield.create({...});
// Sync omitted

// The library provides a hex encoded signed transaction, ready to be broadcast to the network.
// For example, with a standard PIVX node, `sendrawtransaction` can be used
// For more info,
// https://github.com/PIVX-Project/PIVX/wiki/Raw-Transactions#user-content-createrawtransaction_txidtxidvoutn_addressamount
const { hex, txid }  = await shield.createTransaction({
	// Transparent addresses are supported as well
	address: "ptestsapling1s23gkjxqnedkptdvp8qn3m57z0meq2530qxwe8w7x9sdz05xg5yu8wh7534memvjwqntw8mzr3w",
	// 50 tPIV
	amount: 50 * 10**8,
	useShieldInputs: true,
});

const success = your_send_transaction_method(hex);
if (success) {
	shield.finalizeTransaction(txid);
} else {
	shield.discardTransaction(txid);
}

Contribuiting

PRs are welcome! Write tests and then make sure to run cargo fmt before submitting

Compile

To compile, run make. This will generate two versions: pkg/ and pkg_multicore/. Then, run npm i /path/to/this/project/js/, to install the javascript wrapper in your project.

License

See LICENSE for licensing information