# @moneybutton/brfc

> Money Button isomorphic brfc implementation.

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

## Install

```sh
npm install @moneybutton/brfc
pnpm add @moneybutton/brfc
yarn add @moneybutton/brfc
bun add @moneybutton/brfc
```

## 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.38.10 |
| Published | 2022-09-16 |
| First published | 2019-11-14 |
| Weekly downloads | 0 |
| License | Open-BSV |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 8.7 KB |
| Known vulnerabilities | 0 (+3 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Fermatted Drives Limited |
| Maintainers | elijahba, _mind_wire_, eitk |

## Links

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

## Dependencies (4)

- [bsv](https://npm.io/package/bsv.md) 2.0.7
- [moment](https://npm.io/package/moment.md) 2.24.0
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) 7.5.5
- [isomorphic-fetch](https://npm.io/package/isomorphic-fetch.md) 2.2.1

## Recent versions

- 0.38.10 (latest) — 2022-09-16
- 0.38.9 — 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
- … 3 more at https://npm.io/package/@moneybutton/brfc/versions

## README

# BRFC ID generation

It is desirable that a BRFC document be uniquely identified. Without a central authority to issue an identification number, we have chosen to borrow inspiration from Bitcoin and use hashes of content.

## ID Construction

To construct a BRFC ID from a specification, take the UTF8 string value of the `title`, `author` and `version` metadata fields (omit those not present), trim leading and trailing whitespace (leaving whitespace mid-way through the value), concatenate each value, then reinterpret the string as a byte array, and apply a double SHA256 hash.

```js
let hash = sha256d(
  spec.title.trim() +
  (spec.author || '').trim() +
  (spec.version || '').trim()
);
```

Hex-format the hash as per Bitcoin conventions (usually this means reversing the bytes before converting to hex).

```js
let bitcoinDisplayHash = hash
  .reverse()
  .toString('hex');
```

Take the first 12 characters of the Bitcoin-style display hash (representing the last six bytes of the underlying `sha256d` value):

```js
let brfcId = bitcoinDisplayHash.substring(0, 12);
```

## Considerations

Hashing the title, author and version metadata of a specification allows us to generate a unique ID without central authority. Hashing the entire specification was considered, however this was discounted due to the following drawbacks:

* Any change, however minor (like typo fixes) would create an entirely new specification id
* Different platforms handle line endings differently, and different source control and editor software can replace these without warning. This leads to unstable hashes across seemingly identical documents
* Some file formats update metadata even when content remains unchanged. Again, this would lead to unstable hashes over otherwise stable content

## Test Cases

```yaml
title: BRFC Specifications
author: andy (nChain)
version: 1
```

Expected BRFC ID: `57dd1f54fc67`

```yaml
title: bsvalias Payment Addressing (PayTo Protocol Prefix)
author: andy (nChain)
version: 1
```

Expected BRFC ID: `74524c4d6274`

```yaml
title: bsvalias Integration with Simplified Payment Protocol
author: andy (nChain)
version: 1
```

Expected BRFC ID: `0036f9b8860f`

## Usage

### Command line
You can use this as a command line tool:

```
yarn cli "Title" "Author" "Version"
```

### JS/Node

```js
const { brfc } = require('@moneybutton/brfc')

console.log(brfc('Title', 'Author', 'Version'))
```

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