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

Big Numbers


Source code: bn.js

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

Because Javascript does not (as of this writing) support big numbers natively, bsv has a wrapper for a big number library (bn.js). This library is used extensively in the cryptography of bsv.

With big numbers you can:

  • Convert to and from buffers, with big endian or little endian, with zero padding or no padding
  • Convert to and from "sign magnitude" format buffers
  • Convert to and from CScriptNum, or ScriptNum, which is a special format used inside Script
  • Convert to and from numbers (with some loss of precision for numbers greater than 53 bits)
  • Convert to and from strings
  • Add, subtract, multiply, divide, and modulus numbers together (add, sub, mul, div, mod, invm)

Normally, you do not need to use the big number library directly. This is used inside bsv for cryptography. It is exposed in case you do need to use a big number library for some other reason and do not wish to include a second big number library.

Here is a way to add two numbers together:

let BN = bsv.crypto.BN
let n = BN.fromNumber(5)
let m = BN.fromNumber(6)
console.log(n.add(m))
// prints 11

The numeric operations you can access are:

OperationDescription
addAdd
mulMultiply
subSubtract
divDivide
modModulus
invmInverse Modulus

You can also compare numbers together:

let BN = bsv.crypto.BN
let n = BN.fromNumber(5)
let m = BN.fromNumber(6)
console.log(n.gt(m))
// prints false

The comparison operators you have access to are:

OperationDescription
eqEqual
gtGreater Than
ltLesser Than
cmpCompare: returns -1, 0, or 1

It is common to want to convert big numbers, strings, numbers, and buffers. Here is an example:

let BN = bsv.crypto.BN
let str = '3847f126769a6c65d281d925f9ff990f431d19c8c314f9180def0ab95b24f062'
let buf = Buffer.from(str, 'hex')
let n = BN.fromBuffer(buf)
console.log(n.toString())
// prints:
// 25456630020100109444707942782143792492829674412994957270434525334028981432418
console.log(n.toBuffer().toString('hex'))
// prints:
// 3847f126769a6c65d281d925f9ff990f431d19c8c314f9180def0ab95b24f062
let n2 = n.add(new BN(1))
console.log(n2.toString())
// prints:
// 25456630020100109444707942782143792492829674412994957270434525334028981432419
console.log(n.add(n2).toString())
// prints:
// 50913260040200218889415885564287584985659348825989914540869050668057962864837
console.log(n.add(n2).toBuffer().toString('hex'))
// prints:
// 708fe24ced34d8cba503b24bf3ff321e863a33918629f2301bde1572b649e0c5
console.log(n.add(n2).toNumber())
// prints:
// 5.091326004020022e+76
← Bitcoin SV Library (bsv)Points (Elliptic Curves) →
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