# @moneybutton/paymail-client

> Money Button isomorphic Paymail utilities.

Latest version **0.39.0** (published 2022-09-16) · Open-BSV license · 0 weekly downloads

## Install

```sh
npm install @moneybutton/paymail-client
pnpm add @moneybutton/paymail-client
yarn add @moneybutton/paymail-client
bun add @moneybutton/paymail-client
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.39.0 |
| Published | 2022-09-16 |
| First published | 2019-06-01 |
| Weekly downloads | 0 |
| License | Open-BSV |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 8 |
| Unpacked size | 162 KB |
| Known vulnerabilities | 0 (+3 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 25 |
| Author | Fermatted Drives Limited |
| Maintainers | elijahba, _mind_wire_, eitk |

## Links

- npm: https://www.npmjs.com/package/@moneybutton/paymail-client
- Repository: https://github.com/moneybutton/paymail-client
- Homepage: https://github.com/moneybutton/paymail-client#readme
- Issues: https://github.com/moneybutton/paymail-client/issues
- npm.io page: https://npm.io/package/@moneybutton/paymail-client

## Dependencies (8)

- [bsv](https://npm.io/package/bsv.md) 2.0.7
- [moment](https://npm.io/package/moment.md) 2.24.0
- [pure-cache](https://npm.io/package/pure-cache.md) ^1.0.6
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) 7.5.5
- [abort-controller](https://npm.io/package/abort-controller.md) 3.0.0
- [isomorphic-fetch](https://npm.io/package/isomorphic-fetch.md) 2.2.1
- [@moneybutton/brfc](https://npm.io/package/@moneybutton/brfc.md) ^0.38.9
- [http-status-codes](https://npm.io/package/http-status-codes.md) ^2.1.4

## Recent versions

- 0.39.0 (latest) — 2022-09-16
- 0.38.8 — 2021-08-04
- 0.38.7 — 2021-07-08
- 0.38.6 — 2021-05-17
- 0.38.4 — 2020-05-21
- 0.38.3 — 2020-05-04
- 0.38.2 — 2020-04-29
- 0.38.1 — 2020-04-06
- 0.37.0 — 2020-03-20
- 0.36.0 — 2020-03-06
- 0.35.0 — 2020-02-28
- 0.34.0 — 2020-02-26
- 0.33.0 — 2020-02-24
- 0.32.0 — 2019-12-19
- 0.31.3 — 2019-11-15
- … 21 more at https://npm.io/package/@moneybutton/paymail-client/versions

## README

# @moneybutton/paymail-client

## Description

Javascript client to interact with BSV paymail protocol.

See the [docs](docs/paymail-overview.md)

## Ussage.

``` javascript
import { PaymailClient, Verifi } from '@moneybutton/paymail-client'
import fetch from 'isomorphic-fetch'
import dns from 'dns'
import PrivKey from 'bsv/lib/priv-key'
import PubKey from 'bsv/lib/pub-key'

const client = new PaymailClient(dns, fetch) // Any implementation of fetch can be used.
const somePaymailAddress = 'some_name@moneybutton.com'
client.getPublicKey(somePaymailAddress).then(pubkey => {
  console.log(`Current public key for ${somePaymailAddress} is ${pubkey}`)
})

// You can look for someones public identity key.
const senderPrivateKey = 'L3kZEuaEgdfsV7BXCrwhs8E9BuJaN67HvdkSNTfy3CmKjbXkBEjX'
client.getOutputFor(somePaymailAddress, {
    senderHandle: 'sender@moneybutton.com',
    amount: 10000, // Amount in satoshis
    senderName: 'Mr. Sender',
    purpose: 'Pay for your services.',
    pubkey: '03aa44757af33e7c9c9ceb1d5655741867ef8efea00bbc3f498424c91a16c85779'
}, senderPrivateKey).then( output => {
  console.log(`Now I can send money to ${somePaymailAddress} using this output: ${output}`)
})

// You can also use a previously created signature instead of passing in the private key.
import { VerifiableMessage } from '@moneybutton/paymail-client'

const timestamp = new Date().toISOString()
const preMadeSignature = VerifiableMessage.forBasicAddressResolution({
  senderHandle: 'sender@moneybutton.com',
  amount: 10000,
  dt: timestamp,
  purpose: 'Pay for your services.'
}).sign('senderPrivateKey')

client.getOutputFor(somePaymailAddress, {
  senderHandle: 'sender@moneybutton.com',
  amount: 10000, // Amount in satoshis
  senderName: 'Mr. Sender',
  purpose: 'Pay for your services.',
  pubkey: '03aa44757af33e7c9c9ceb1d5655741867ef8efea00bbc3f498424c91a16c85779',
  signature: preMadeSignature
}).then( output => {
  console.log(`Now I can send money to ${somePaymailAddress} using this output: ${output}`)
})

// You can check if a given key belongs to a given paymail
const somePubKey = PubKey.fromPrivKey(PrivKey.fromRandom()).toString()
client.verifyPubkeyOwner(somePubKey, 'someuser@moneybutton.com').then(aBoolean => {
  console.log(`The key ${somePubKey} ${aBoleean ? 'does' : 'doesn\'t'} belongs to someuser@moneybutton.com`)
})


// Lastly it lets you verify if certain signature is valid for certain paymail address.
const aMessage = new VerifiableMessage(['very', 'important', 'message'])
const aSignature = 'some signature for the message'
client.isValidSignature (aMessage, aSignature, 'someone@moneybutton.com').then( aBoolean => {
  if (aBoolean) {
    console.log('the signature is valid, yey!')
  } else {
    console.log('the signature is invalid, don\'t trust them')
  }
})
```

---
_Source: https://npm.io/package/@moneybutton/paymail-client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
