open-index/open-npm huggingface dataset:
npm package: @mem-cash/core
Description: Node engine, subscription manager, and mempool acceptance for mem-cash
Latest version: 0.0.4

# @mem-cash/core

Node engine, subscription manager, and mempool acceptance for mem-cash.

## Node

`createNode()` wires together in-memory storage with an optional transaction verifier:

```typescript
import { createNode } from "@mem-cash/core";
import { createTxVerifier } from "@mem-cash/validation";

const verifier = await createTxVerifier({ standard: false });
const node = createNode({ verifier });

node.setChainTip(200, 1700000000);
node.addUtxo({ txid, vout: 0, satoshis: 10_000n, scriptHash, height: 100 });

const result = node.submitTransaction(rawHex);
// { success: true, txid, fee, size, affectedScriptHashes }

// Debug without accepting to mempool (per-input VM traces)
const debug = node.debugTransaction(rawHex);
// { success: true, txid, fee, size, inputResults: [...] }
```

## Subscription Manager

Tracks scripthash and header subscriptions, detects status changes, and dispatches notifications:

```typescript
const consumerId = node.subscriptions.addConsumer((notification) => {
  if (notification.type === "scripthash") {
    console.log(notification.scriptHash, notification.status);
  } else {
    console.log("new tip:", notification.header.height);
  }
});
```

Subscriber callbacks are isolated with try-catch -- a throwing callback is logged via `console.error` but does not prevent other subscribers from receiving their notifications.

## Mempool Acceptance

Two-phase pattern: the verifier validates (read-only), then `acceptToMempool` performs storage mutations and returns affected scripthashes for notification dispatch.
npm package: @mem-cash/storage
Description: In-memory storage implementation for mem-cash
Latest version: 0.0.4

# @mem-cash/storage

In-memory implementation of the `Storage` interface from `@mem-cash/types`.

## Usage

```typescript
import { createMemoryStorage } from "@mem-cash/storage";

const storage = createMemoryStorage();

// StorageReader methods
storage.getHeader(height);
storage.getHistory(scriptHash);
storage.getBalance(scriptHash);
storage.getUtxos(scriptHash);
storage.getScriptHashStatus(scriptHash);

// StorageWriter methods
storage.applyBlock(block);
storage.undoBlock(height);
storage.addMempoolTx(tx);
```

## Defensive Copies

All reader methods that return `UtxoEntry` objects (`getUtxos`, `getUtxoByOutpoint`, `getMempoolUtxo`) return cloned entries with copied `lockingBytecode` buffers. This prevents external code from mutating internal storage state. `getTxidsAtHeight` also returns a shallow copy.

Undo snapshots created during `applyBlock` clone spent UTXOs so that reorgs restore clean data even if callers mutated returned entries.

## Mempool Child Removal

`removeMempoolTx` uses iterative traversal (not recursion) to cascade-delete descendant transactions, preventing stack overflow on deep chains.

## Test Helpers

`createMemoryStorage()` returns a `TestableStorage` with a `_test` namespace for direct state manipulation:

```typescript
storage._test.utxo.add({ txid, vout, satoshis, scriptHash, height });
storage._test.header.add({ hash, height, timestamp });
storage._test.mempool.add({ txid, fee, size, inputs, outputs });
storage._test.tx.add({ txid, height, rawHex });
storage._test.history.add({ scriptHash, entries });
storage._test.reset();
```
npm package: @mem-cash/types
Description: Shared primitives, data types, and storage interfaces for mem-cash
Latest version: 0.0.4

# @mem-cash/types

Shared primitives, data types, and interfaces for the mem-cash monorepo.

## Contents

- **Primitives** -- `ScriptHash`, `Txid`, `BlockHash`, `OutpointKey` type aliases; `parseOutpointKey` validates vout as an integer in `[0, 0xFFFFFFFF]`
- **Data types** -- `BlockHeader`, `UtxoEntry`, `HistoryEntry`, `MempoolTx`, `TransactionRecord`, `Balance`, `TokenData`
- **Storage interfaces** -- `StorageReader`, `StorageWriter`, `Storage` for pluggable backends
- **Merkle utilities** -- `computeTxMerkleBranch`, `computeHeaderMerkleBranch` for SPV proofs; input validation rejects empty hash lists, out-of-bounds indices, and non-32-byte hashes
- **MTP** -- `computeMedianTimePast` (BIP113)
- **Reject codes** -- BCHN-compatible `REJECT_INVALID`, `REJECT_NONSTANDARD`, etc.
npm package: @mem-cash/validation
Description: Stateless BCH transaction evaluator with BCHN-compatible consensus and policy checks
Latest version: 0.0.4

# @mem-cash/validation

Stateless transaction evaluator for Bitcoin Cash. Validates raw transaction hex against consensus rules, policy checks, and libauth VM script verification.

## Usage

```typescript
import { createTxVerifier } from "@mem-cash/validation";

const verifier = await createTxVerifier({
  vmVersion: "BCH_2025_05",
  standard: true,
});

const result = verifier.verify(rawHex, sourceOutputs, chainState);
if (result.success) {
  console.log(result.txid, result.fee, result.validatedTx);
} else {
  console.log(result.code, result.error); // BCHN reject code + reason
}
```

## Verification Pipeline

Matches BCHN's `AcceptToMemoryPool` order:

1. Decode transaction hex
2. Null prevout check (`bad-txns-prevout-null`)
3. Validate sourceOutputs count matches inputs (`bad-txns-inputs-missingorspent`)
4. Locktime finality (`bad-txns-nonfinal`)
5. Coinbase maturity (`bad-txns-premature-spend-of-coinbase`)
6. Unspendable inputs (`bad-txns-input-scriptpubkey-unspendable`)
7. Input value ranges (`bad-txns-inputvalues-outofrange`)
8. Output value ranges and fee computation (`bad-txns-outputvalues-outofrange`, `bad-txns-in-belowout`) -- per-output and cumulative sum checked against `MAX_MONEY`
9. BIP68 sequence locks (`non-BIP68-final`)
10. Min relay fee (`min relay fee not met`)
11. Absurd fee guard (`absurdly-high-fee`)
12. Dust check (`dust`)
13. VM script verification (`mandatory-script-verify-flag-failed` / `non-mandatory-script-verify-flag`)

All error strings and reject codes match BCHN exactly. The verifier implements BCHN's two-pass script verification to distinguish mandatory from non-mandatory failures.

## Config Validation

`createTxVerifier` rejects non-positive `minRelayFeePerKb` and `maxFee` values at construction time to prevent bypassing fee policy checks.
npm package: @mem4/pattern-lib
Description: A current preview (based on tag "preview") is available at [http://167.172.182.63:8093/](http://167.172.182.63:8093/)
Latest version: 0.0.3

# Memberhip4 Pattern Lib / Components

A current preview (based on tag "preview") is available at 
[http://167.172.182.63:8093/](http://167.172.182.63:8093/) 

## Introduction / Guidlines

### Atomic Design
Components must be structured according to the [Atomic Design Methodology](https://atomicdesign.bradfrost.com/chapter-2/)

### Coding style guidlines for vue components
Vue Components should adhear to the [VUEJS style guidlines](https://vuejs.org/v2/style-guide/)

### CSS class nameing
Class names should be named / organized according to the [BEM Methodology](http://getbem.com/naming/)

### Component naming
To avoid conflicts with html elements or external vue components all component names must be prefixed with "M4".
Example: M4Button

## Used tools
* [vue-cli](https://cli.vuejs.org/) - Standard Tooling for Vue.js Development
* [vue-styleguidist](https://vue-styleguidist.github.io/) - Documentation generation


## Building styleguid

### Dev
```sh
yarn styleguide
```

```sh
yarn styleguide:watch
```

### Prod
```sh
yarn styleguide:build
```

## Building library
```sh
yarn build
```


## Format code on save with prettier 
[Guide for php/webstrom](https://prettier.io/docs/en/webstorm.html#running-prettier-on-save-using-file-watcher)


## Use Package in a Project with yarn/npm link

https://medium.com/@the1mills/how-to-test-your-npm-module-without-publishing-it-every-5-minutes-1c4cb4b369be

Run this in mem4-patter-lib and follow instructions:
```sh
yarn link
```

add "mem4-patter-lib": "latest" to dependencies in you package.json file.

**Attention:** Yarn / Npm tries to find the package in their registries, 
that's why you have to remove "mem4-patter-lib" form the package.json before you run ```yarn add``` and ```yarn install```
This can be fixed if by publishing "mem4-patter-lib" to npm or a private npm repository.

Import of a component:
```js
import { M4Button } from 'mem4-pattern-lib'
```

SASS Import:
```
@import "node_modules/mem4-pattern-lib/src/index";
```