Money Button Documentation

Money Button Documentation

  • Money Button
  • API
  • Examples
  • Paymail
  • bsv

›Bitcoin SV Library (bsv)

Money Button

  • Money Button Overview
  • HTML
  • Javascript
  • React
  • Crypto Operations
  • Invisible Money Button
  • Paymail Signatures
  • Paymail Encryption

API

  • API Overview
  • Apps
  • Webhooks
  • Tokens
  • Currencies
  • Javascript Client
  • Authentication

    • Authentication Overview
    • OAuth
    • OAuth With JS Client

    API v1

    • Get User Identity
    • Get User Profile
    • Get User Balance
    • Get Payments
    • Get Payment By ID

    API v2

    • Get User Balances
    • Get Payments
    • Get Payment By ID
    • Get Assets
    • Create Asset
    • Modify Asset

Simple Fabriik Protocol for Tokens

  • Protocol Overview
  • Wallets Integration Guide
  • SFP Paymail Extension Build Action
  • SFP Paymail Extension Authorise Action

Examples

  • Examples Overview
  • OP_RETURN Scripts
  • Assets

Paymail

  • Paymail Overview
  • Paymail Video Series
  • Paymail Introduction
  • BRFC Specifications
  • Specification Documents
  • BRFC ID Assignment
  • Service Discovery
  • Host Discovery
  • Capability Discovery
  • Public Key Infrastructure
  • Payment Addressing
  • Payment Addressing (Basic Address Resolution)
  • Payment Addressing (Payer Validation)
  • Payment Addressing (Payee Approvals)
  • Payment Addressing (PayTo Protocol Prefix)
  • Verify Public Key Owner
  • P2P Transactions
  • P2P Payment Destination
  • P2P Payment Destination with Tokens Support
  • Asset Information
  • Recommendations

Bitcoin SV Library (bsv)

  • Bitcoin SV Library (bsv)
  • Big Numbers
  • Points (Elliptic Curves)
  • Hash Functions
  • Base 58
  • Private Keys
  • Public Keys
  • Addresses
  • ECDSA
  • Bitcoin Signed Messages
  • Signatures
  • HD Private Keys (BIP32)
  • HD Public Keys (BIP32)
  • Mnemonics (BIP39)
  • Script

Signatures


Source code: signature.js

Note that signatures are handled automatically by Money Button behind the scenes and it is not necessary to deal with signatures directly unless you are building an advanced application.

An ECDSA signature consists of two numbers, r and s, both of which are big numbers. A signature is produced from a private key and a message and a signature is verified using a public key, a signature and the message. Only the person with the private key can produce a signature for a corresponding public key, and anyone with the public key can verify the authenticity of the signature.

In a Bitcoin transaction, another value called the SIGHASH type is added to a signature. The SIGHASH type specifies what operation is used to create and verify the signature. A signature inside a Bitcoin transaction is encoded in DER format followed by a single byte indicated the SIGHASH type. The DER format itself includes several header bytes.

A DER formatted signature looks like this:

[header, length, rheader, rlength, r, sheader, slength, s]

Where these fields are defined as:

fieldexplanation
header0x30
lengthThe total length of what follows, including all headers and r and s value
rheader0x02
rlengthThe length of r
rr encoded in big endian sign magnitude format
sheader0x02
slengthThe length of s
ss encoded in big endian sign magnitude format

A signature inside a Bitcoin transaction looks like this:

[der, sighash]

Where "der" is formatted according to the above definition, and sighash is a single byte that can be SIGHASH_ALL, SIGHASH_SINGLE, SIGHASH_ANYONECANPAY, or SIGHASH_NONE.

In a Bitcoin Signed Message, signatures are formatted differently than inside a Bitcoin transaction. Firstly, the message is hashed using a "Bitcoin Signed Message:\n" prefix, and secondly, the signature itself is formatted as a base64 representation of two 256 bit numbers, r and s, which is quite different from DER format.

Here is an example building a DER signature (found inside a Bitcoin transction) and a compact signature (found inside a Bitcoin Signed Message):

var data = 'my data'
var privateKey = bsv.PrivKey.fromRandom()
var hash = bsv.crypto.Hash.sha256(Buffer.from(data))
var sig1 = bsv.crypto.ECDSA.sign(hash, privateKey)
console.log(sig1.toString('hex'))
// prints:
// 30440220683f3c385edc42223c4efa00493c34532379ac88c1d2fa57997d903de44a7e9302202175d70f029515f0013c1d10de82b116984c7511f3f52928470ddfb49505ac00
var sig2 = bsv.crypto.ECDSA.signWithCalcI(hash, privateKey)
console.log(sig2.toCompact().toString('base64'))
// prints:
// H2g/PDhe3EIiPE76AEk8NFMjeayIwdL6V5l9kD3kSn6TIXXXDwKVFfABPB0Q3oKxFphMdRHz9SkoRw3ftJUFrAA=
← Bitcoin Signed MessagesHD Private Keys (BIP32) →
Money Button Documentation
Docs
Money ButtonAPIDesignbsv
Community
redditYoutubeTelegramTwitter
More
BlogInstagramGitHubStar
See an error in our documentation? Issue a pull request to fix it.
Copyright © 2022 Fermatted Drives Limited