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

Private Keys


Source code: privatekey.js

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

A private key can be used to spend Bitcoin. A private key is to be kept private

  • normally, a user should not share their private key. Anyone who has access to the private key can spend funds. A private key can be used to derive a corresponding public key, and a public key can be used to derive an address.

In bsv, the PrivKey class is wrapper of Big Number. It is a 256 bit big number.

To generate a new, cryptographically secure random private key, use:

let privKey = bsv.PrivKey.fromRandom()

Bitcoin has two networks - mainnet (the real network) and testnet. Use the testnet network for testing. You can create a private key on testnet, which is formatted differently:

let privateKey = bsv.PrivKey.fromRandom('testnet')

Normally, you should output a private key into Wallet Import Format (WIF). This is a Base 58 Check formatted string. It contains an extra byte, 'compressed', to indicate whether the corresponding public key is compressed or not. Normally, the public key is compressed.

To display the WIF private key, use:

console.log(privateKey.toWIF())

// prints:
// Kwn6yDoKobVjH2dqa9UZ4c5yXfUQQo6PxdQCTknbRW85LeyYxTbp
// ...or whatever your randomly generated private key is.

Notice that the WIF key looks like this:

Kwn6yDoKobVjH2dqa9UZ4c5yXfUQQo6PxdQCTknbRW85LeyYxTbp

You can import a private key and export it again:

let str = 'Kwn6yDoKobVjH2dqa9UZ4c5yXfUQQo6PxdQCTknbRW85LeyYxTbp'
let privateKey2 = bsv.PrivKey.fromWif(str)

console.log(privateKey2.toWIF())
// prints:
// Kwn6yDoKobVjH2dqa9UZ4c5yXfUQQo6PxdQCTknbRW85LeyYxTbp
console.log(privateKey.toWIF())
// prints:
// Kwn6yDoKobVjH2dqa9UZ4c5yXfUQQo6PxdQCTknbRW85LeyYxTbp
// ...or whatever your randomly generated private key is.

We can also generate and display a testnet private key:

let privateKey = bsv.PrivKey.fromRandom('testnet')

console.log(privateKey.toWIF())
// prints:
// cRuVA4z4TYdwt4uGYcQxwCTVkwK2VSt5PNrJmDG9QXh4YHWLtTnY
// ...or whatever your randomly generated private key is.

Notice in this case the private key looks like this:

cRuVA4z4TYdwt4uGYcQxwCTVkwK2VSt5PNrJmDG9QXh4YHWLtTnY

Private keys on testnet always start with a 'c' and private keys on mainnet either start with a 'K' or an 'L' when formatted in WIF.

If you would like to see the big number inside a private key, you can do this:

privateKey = bsv.PrivKey.fromString('Kwn6yDoKobVjH2dqa9UZ4c5yXfUQQo6PxdQCTknbRW85LeyYxTbp')
privateKey.bn.toString()

// prints:
// 7537391639902988000652013410090023935060956443631057909604306796118758817057
← Base 58Public Keys →
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