# pushdrop

> A package for creating and redeeming Bitcoin tokens with arbitrary signed payloads stored on the stack

Latest version **0.1.64** (published 2024-10-01) · Open BSV License license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install pushdrop
pnpm add pushdrop
yarn add pushdrop
bun add pushdrop
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.64 |
| Published | 2024-10-01 |
| First published | 2022-05-25 |
| Weekly downloads | 0 |
| License | Open BSV License |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 987.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Peer-to-peer Privacy Systems Research LLC |
| Maintainers | tonesnotes, braydude, tyeverett |
| Keywords | BSV, token |

## Links

- npm: https://www.npmjs.com/package/pushdrop
- Repository: https://github.com/p2ppsr/pushdrop
- Homepage: https://github.com/p2ppsr/pushdrop#readme
- Issues: https://github.com/p2ppsr/pushdrop/issues
- npm.io page: https://npm.io/package/pushdrop

## Dependencies (2)

- [babbage-bsv](https://npm.io/package/babbage-bsv.md) ^0.2.5
- [@babbage/sdk-ts](https://npm.io/package/@babbage/sdk-ts.md) ^0.2.54

## Recent versions

- 0.1.64 (latest) — 2024-10-01
- 0.1.63 — 2024-09-21
- 0.1.61 — 2024-07-17
- 0.1.59 — 2024-07-07
- 0.1.58 — 2024-06-19
- 0.1.57 — 2024-06-07
- 0.1.56 — 2024-05-11
- 0.1.55 — 2024-05-07
- 0.1.54 — 2024-05-04
- 0.1.53 — 2024-05-04
- 0.1.52 — 2024-05-01
- 0.1.51 — 2024-04-24
- 0.1.50 — 2024-04-23
- 0.1.49 — 2024-04-11
- 0.1.48 — 2024-04-11
- … 45 more at https://npm.io/package/pushdrop/versions

## README

# pushdrop

A package for creating and redeeming Bitcoin tokens with arbitrary signed payloads stored on the stack

The code is hosted [on GitHub](https://github.com/p2ppsr/pushdrop) and the package is available [through NPM](https://www.npmjs.com/package/pushdrop).

## Installation

    npm i pushdrop

## Example Usage

```js
const pushdrop = require('pushdrop')

const token_payload = [
  Buffer.from(...),
  Buffer.from(...),
  Buffer.from(...),
  ...
]

const pushdrop_script = await pushdrop.create({
  fields: token_payload,
  key: bsv.PrivateKey.fromHex(key)
})

const unlocking_script = await pushdrop.redeem({
  prevTxId: txid,
  outputIndex: 0,
  outputAmount: amount,
  key: bsv.PrivateKey.fromHex(key),
  lockingScript: script.toHex()
})
```

## API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

#### Table of Contents

*   [create](#create)
    *   [Parameters](#parameters)
*   [redeem](#redeem)
    *   [Parameters](#parameters-1)
*   [decode](#decode)
    *   [Parameters](#parameters-2)

### create

Creates a script that pays to a public key and includes "PUSH DROP" data signed with the corresponding private key

#### Parameters

*   `obj` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** All parameters are given in an object (optional, default `{}`)

    *   `obj.fields` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<([Buffer](https://nodejs.org/api/buffer.html) | [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String))>** The token payload fields to push and drop. Each field is given as a Buffer, or a utf8 string.
    *   `obj.key` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | PrivateKey)** The private key that will sign the token payload. Given in WIF or an instance of bsv PrivateKey. If no key is provided, the BabbageSDK will be used as a signing strategy.
    *   `obj.ownerKey` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | PublicKey)?** The owner's public key, whose private key can unlock the token using the `redeem` function. If not provided, the signing key will be used. Given in DER (33- or 65-byte hex), or an instance of bsv1 PublicKey. If no signing private key is provided, the BabbageSDK will be used to derive the ownerKey.
    *   `obj.protocolID` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Specify an identifier for the protocol under which this operation is being performed.
    *   `obj.keyID` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** An identifier for the message being signed. During verification, or when retrieving the public key used, the same message ID will be required. This can be used to prevent key re-use, even when the same user is using the same protocol to sign multiple messages.
    *   `obj.counterparty` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** If specified, the user with this identity key will also be able to verify the signature, as long as they specify the current user's identity key as their counterparty. Must be a hexadecimal string representing a 33-byte or 65-byte value, "self" or "anyone". (optional, default `self`)
    *   `obj.ownedByCreator` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** DEPRECATED - use counterpartyCanVerifyMyOwnership. Retained for backward-compatibility (optional, default `false`)
    *   `obj.counterpartyCanVerifyMyOwnership` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Indicates whether the token is owned by its creator, assuming `protocolID` and `keyID` are being used. (optional, default `false`)
    *   `obj.privileged` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** This indicates whether the privileged keyring should be used for signing, as opposed to the primary keyring. (optional, default `false`)
    *   `obj.description` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Describe the high-level operation being performed, so that the user can make an informed decision if permission is needed.
    *   `obj.disableSignature` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** If provided, no signature will be applied to the PushDrop token payload.
    *   `obj.lockBefore` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** If set to false, the lock will be after the push and drop parts of the script. (optional, default `true`)
    *   `obj.customLock` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** If provided, the lock portion of the script will be set to this custom value, and the normal P2PK lock will not be used.

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** A Bitcoin script hex string containing a P2PK lock and the PUSH DROP data, with a signature over the fields

### redeem

Redeems a PushDrop transaction output

#### Parameters

*   `obj` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** All parameters are given in an object

    *   `obj.prevTxId` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The ID of the transaction to redeem
    *   `obj.outputIndex` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The index of the transaction output to redeem
    *   `obj.lockingScript` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | bsv.Script)** The locking script of the output to redeem. Given as a hex string or an instance of bsv1 Script.
    *   `obj.outputAmount` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Number of satoshis in the PushDrop UTXO
    *   `obj.key` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | bsv.PrivateKey)** Private key that can unlock the PushDrop UTXO's P2PK lock. Given as a WIF string or an instance of bsv1 PrivateKey.
    *   `obj.protocolID` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Specify an identifier for the protocol under which this operation is being performed.
    *   `obj.keyID` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** An identifier for the message being signed. During verification, or when retrieving the public key used, the same message ID will be required. This can be used to prevent key re-use, even when the same user is using the same protocol to sign multiple messages.
    *   `obj.description` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Describe the high-level operation being performed, so that the user can make an informed decision if permission is needed.
    *   `obj.counterparty` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** If specified, the user with this identity key will also be able to verify the signature, as long as they specify the current user's identity key as their counterparty. Must be a hexadecimal string representing a 33-byte or 65-byte value, "self" or "anyone". (optional, default `self`)
    *   `obj.privileged` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** This indicates whether the privileged keyring should be used for signing, as opposed to the primary keyring. (optional, default `false`)
    *   `obj.signSingleOutput` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** If provided, uses SIGHASH_SINGLE instead of SIGHASH_NONE. The input index must be the same as the output index of this output in the transaction.

        *   `obj.signSingleOutput.satoshis` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Number of satoshis in the single output to sign
        *   `obj.signSingleOutput.script` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | bsv.Script)?** Output script of the single output to sign (this COULD be another PushDrop script created with the `create` function, allowing you to continue/spend/update the token). Given as a hex string or an instance of bsv1 Script.
    *   `obj.inputIndex` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The input in the spending transaction that will unlock the PushDrop UTXO (optional, default `0`)

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** Unlocking script that spends the PushDrop UTXO

### decode

Given a PushDrop locking script, returns the fields and lockingKey that were used to create it.

If an invalid (non-PushDrop) script is provided, the return value is **undefined**. Only valid PushDrop scripts will be properly decoded.

#### Parameters

*   `obj` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** All parameters are given in an object

    *   `obj.script` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The PushDrop locking script to decode
    *   `obj.fieldFormat` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The format of the fields, either "hex", "base64", "utf8" or "buffer" (optional, default `hex`)

Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The decoded object, containing `fields`, `signature` and `lockingPublicKey`

## License

The license for the code in this repository is the Open BSV License.

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