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

@dazaar/payment-eth

v2.1.1

Published

Dazaar payment provider for ETH and ERC20 tokens

Downloads

11

Readme

@dazaar/payment-eth

Ethereum payment api for Dazaar stream services

Usage

const PaymentETH = require('@dazaar/payment-eth')
const market = require('dazaar/market')
const Index = require('@hyperdivision/eth-transaction-indexer')
const hypercore = require('hypercore')

const index = new Index(hypercore('./tmp/db'), {
  endpoint: 'https://infura...'
})

const m = market('./tmp')
const feed = hypercore('./tmp/data')

const paymentCard = {
  id: 'dazaartest22',
  payment: [{
    method: 'ETH',
    pubKey: '0x50c7d91e74b0e42bd8bce8ad6d199e4a23c0b193',
    currency: 'microether',
    amount: 1,
    unit: 'seconds',
    interval: 1
  }]
}

let payment

// instantiate a seller for a feed and equip it
// with a validate function
const seller = m.sell(feed, {
  validate (remoteKey, cb) {
    payee.validate(remoteKey, cb)
  }
})

seller.ready(function (err) {
  // payment now set up. dazaar logic follows ...
  payment = new PaymentETH(seller, paymentCard, index)
})

Buyer

// instantiate a buyer for a specific feed
const buyer = m.buy(seller.key)

// generate the ethereum adress to pay to for a given stream
const payTo = PaymentETH.tweak(buyer.key, dazaarCard, 'microether')

// pay the desired amount to the address generated

API

const payment = PaymentETH(seller, payment, index)

Create a new eth payment instance associated to a seller. seller should be a dazaar seller instance, payment may either be a dazaar payment card, or a string specifying the per second rate in either ETH, such as 0.0002 ETH/s. index should be a transaction indexer

payment.validate(buyerKey, cb)

A seller can validate the time left for a given buyer. Returns error if there is no time left on the subscription. The method shall check whether the given buyer has a subscription set-up and instantiate one not already present.

payment.buyers([privateKey], cb)

Generate a list of all the buyers with their tweaked accounts they paid to. If you private the private key you get the tweaked private keys out as well, meaning you can sweep the accounts to somewhere yourself.

The result looks like this:

[{
  buyer: <buyer-pub-key>,
  uniqueFeed: <keypair of the hypercore generate for them>,
  eth: <the eth account tweaked for the buyer>
}, ...]

const payTo = PaymentETH.tweak(buyerKey, dazaarCard, [paymentType])

Static method to generate the ETH address to pay to for a given stream. buyerKey is the buyer's dazaar key and dazaarCard give the relevant stream details.

License

MIT