Skip to content

Instantly share code, notes, and snippets.

@jcramer
Last active November 7, 2018 19:43
Show Gist options
  • Save jcramer/0133786a0d811fcd4d10fa86b5930710 to your computer and use it in GitHub Desktop.
Save jcramer/0133786a0d811fcd4d10fa86b5930710 to your computer and use it in GitHub Desktop.
Introduction to the P2SH.cash System

P2SH.cash System Features

P2SH.cash is a d-app and SLP token system for simplifying P2SH workflows. P2SH creation and spending is currently cumbersome for both users and wallets to manage, which has led to underwhelming P2SH usage and adoption. For this reason we present the P2SH.cash system described herein.

In summary, the P2SH.cash system provides the following key components:

  • A new JSON schema for a Bitcoin Script Template (BST) bst.schema.json,
  • A web GUI for calculating the proper P2SH address from a BST,
  • A web GUI for easily sending funds to a calculated P2SH address,
  • A web GUI for spending an existing P2SH balance using a BST,
  • A web GUI for a for writting and validating a new BST document,

The SLP token system for communicating the requirements for reconstructing a P2SH pre-image includes the following components:

  • A new JSON schema for P2SH.cash SLP Token Document p2sh.token.schema.json,
  • Required ticker symbol for a SLP token using the P2SH.cash tracking system

Note: P2SH.cash is not a script interpreter and does not provide execution of code. All code execution should be tested on mainet, testnet, or regtest for determining script validity.

Warning: P2SH.cash or any of its affiliates are not responsible for loss of funds for any reason.

The Script Template JSON Schema

A Bitcoin Script Template (BST) JSON defines the general structure of a Script. It is intended to include user defined opcodes, hard-coded opcodes, user defined data pushes, hard-coded data pushes, repeating user defined data pushes controlled by the user defined opcodes. Anyone can create their own BST for a custom script by learning the simple BST JSON Schema.

BST json must follows the BST JSON schema bst.schema.json which defines the requirements for the BST JSON. The following BST JSON sections are required for any new template implementation:

(1) name of the template (section "n"),
(2) user defined variables (section "v"),
(3) locking script template (section "l")

The unlocking script section "u" is defined by the Schema document but it is not required to be implemented. Each of these sections have unique schema requirements, so the bst.schema.json file should be used as the primary resource to understand how to create a new BST JSON document.

The following presents a simplified version of the BST JSON schema bst.schema.json:

{
    "v": { 
        "description": "BST schema version", 
        "type": "integer" 
    },
    "n": { 
        "description": "Name of script template", 
        "type": "string" 
    },
    "x": { 
        "description": "User defined variables used in locking and unlocking sections", 
        "type": "array",
        "items": // see schema for requirements
    },
    "u": {
        "description": "Unlocking script template definitions (can be more than one unlocking template)",
        "type": "array",
        "items": // see schema for requirements
    },
    "l": {
        "description": "Locking script template definition",
        "type": "array",
        "items": // see schema for requirements
    }
}

A System for wallets to track P2SH details using SLP Tokens

A simple system using SLP tokens can be used by wallets to keep track of P2SH outputs that the wallet's owner may have a claim or interest in. The system uses SLP tokens with a specifically formated token document containing all of the information required to reconstruct a P2SH pre-image for one or more outputs of a single transaction. The tokens can be distributed to any stakeholder of the subject P2SH outputs.

The SLP tokens for this system should meet the following requirements:

  1. The token's ticker should be p2sh.cash (all lowercase),
  2. The token document shall follow the p2sh.cash.schema.json JSON schema

Obviously, the input requirements for the unlocking script template are left out of the token document, as the stakeholders will be responsible for generating the proper unlocking script on their own.

The following presents a simplified version of the SLP Token Document p2sh.cash.schema.json:

"o": {
    "type": "array", 
    "description": "Array of P2SH outputs being specified within this token document",
    "items":{
        "type":"objects",
        "properties": {
            "vout": {
                "type": "integer",
                "description": "The output indext",
                "pattern": "[0-9]+"
            },
            "txid": {
                "type": "string",
                "description": "If the P2SH outputs are not included with the token Genesis then the txid containing the P2SH outputs may be defined.",
                "pattern": "[a-f]|[A-F]|[0-9]{64}"
            },
            "bst": {
                "type" : "object",
                "description" : "Properties for the BST template defining the P2SH output",
                "properties" : {
                    "uri" : {
                        "type" : "string",
                        "description" : "Storage location of the BST document.",
                        "pattern" : "^(bitcoinfile:)|^(http:)|^(https:)"
                    },
                    "req" : {
                        "type" : "array",
                        "description" : "Sequential input requirements for the BST to reconstructing the P2SH pre-image",
                        "items": // see schema for requirements
                    }
                }
            }
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment