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

@huma-shan/transaction-manager

v0.31.0

Published

Request Network transaction layer, handle signature and encryption for the transaction.

Downloads

16

Readme

@huma-shan/transaction-manager

@huma-shan/transaction-manager is a typescript library part of the Request Network protocol. It is the default implementation of the Transaction layer. It creates transactions to be sent to Data Access. When privacy is implemented, this package will handle the encryption.

Installation

npm install @huma-shan/transaction-manager

Usage

Note on the decryption provider

In order to decrypt encrypted transactions, you must provide a decryption provider. You can see the specification of decryption provider here.

An example of implementation of a decryption provider is available in the package: epk-decryption

import EthereumPrivateKeyDecryptionProvider from '@huma-shan/epk-decryption';
import { TransactionManager } from '@huma-shan/transaction-manager';

// Decryption provider setup
const decryptionProvider = new EthereumPrivateKeyDecryptionProvider({
  key: '0x04674d2e53e0e14653487d7323cc5f0a7959c83067f5654cafe4094bde90fa8a',
  method: EncryptionTypes.METHOD.ECIES,
});

// Potentially add another decryption key
decryptionProvider.addDecryptionParameters({
  key: '0x0906ff14227cead2b25811514302d57706e7d5013fcc40eca5985b216baeb998',
  method: EncryptionTypes.METHOD.ECIES,
});

const transactionManager = new TransactionManager(dataAccess, decryptionProvider);

Persist a clear transaction

import { DataAccessTypes, SignatureTypes } from '@huma-shan/types';
import { TransactionManager } from '@huma-shan/transaction-manager';

const dataAccess: DataAccessTypes.IDataAccess; // A Data Access implementation, for example @huma-shan/data-access

const transactionManager = new TransactionManager(dataAccess);

const data = '{ what: "ever", it: "is,", this: "must", work: true }';
const channelId = 'myRequest';
const channelTopics = ['stakeholder1', 'stakeholder2'];

const { result } = await transactionManager.persistTransaction(data, channelId, channelTopics);

Persist an encrypted transaction

import { DataAccessTypes, SignatureTypes } from '@huma-shan/types';
import { TransactionManager } from '@huma-shan/transaction-manager';

const dataAccess: DataAccessTypes.IDataAccess; // A Data Access implementation, for example @huma-shan/data-access

const transactionManager = new TransactionManager(dataAccess, decryptionProvider);

const data = '{ what: "ever", it: "is,", this: "must", work: true }';
const channelId = 'myRequest';
const channelTopics = ['stakeholder1','stakeholder2'];
const encryptionParameters: EncryptionTypes.IEncryptionParameters[] = [
  {
    key:
      '299708c07399c9b28e9870c4e643742f65c94683f35d1b3fc05d0478344ee0cc5a6a5e23f78b5ff8c93a04254232b32350c8672d2873677060d5095184dad422',
    method: EncryptionTypes.METHOD.ECIES,
  },
  {
    key:
      '9008306d319755055226827c22f4b95552c799bae7af0e99780cf1b5500d9d1ecbdbcf6f27cdecc72c97fef3703c54b717bca613894212e0b2525cbb2d1161b9',
    method: EncryptionTypes.METHOD.ECIES,
  }
]);

const { result } = await transactionManager.persistTransaction(data, channelId, channelTopics, encryptionParameters);

Get Transactions from channel id

import EthereumPrivateKeyDecryptionProvider from '@huma-shan/epk-decryption';
import { DataAccessTypes, SignatureTypes } from '@huma-shan/types';
import { TransactionManager } from '@huma-shan/transaction-manager';

const dataAccess: DataAccessTypes.IDataAccess; // A Data Access implementation, for example @huma-shan/data-access

// Decryption provider setup if needed
const decryptionProvider = new EthereumPrivateKeyDecryptionProvider({
  key: '0x04674d2e53e0e14653487d7323cc5f0a7959c83067f5654cafe4094bde90fa8a',
  method: EncryptionTypes.METHOD.ECIES,
});

const transactionManager = new TransactionManager(dataAccess, decryptionProvider);

const channelId = 'myRequest';

const {
  result: { transactions },
} = await transactionManager.getTransactionsByChannelId(channelId);

Get Transactions from topic

import EthereumPrivateKeyDecryptionProvider from '@huma-shan/epk-decryption';
import { DataAccessTypes, SignatureTypes } from '@huma-shan/types';
import { TransactionManager } from '@huma-shan/transaction-manager';

const dataAccess: DataAccessTypes.IDataAccess; // A Data Access implementation, for example @huma-shan/data-access

// Decryption provider setup if needed
const decryptionProvider = new EthereumPrivateKeyDecryptionProvider({
  key: '0x04674d2e53e0e14653487d7323cc5f0a7959c83067f5654cafe4094bde90fa8a',
  method: EncryptionTypes.METHOD.ECIES,
});

const transactionManager = new TransactionManager(dataAccess, decryptionProvider);

const channelTopic = 'stakeholder1';

const {
  result: { transactions },
} = await transactionManager.getTransactionsByTopic(channelTopic);

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Read the contributing guide

License

MIT