Private Keys

Creating a new Private Key

You can create a new Private Key by using the default constructor of the SVPrivateKey class.


//create a private key using the default constructor
var privateKey = SVPrivateKey();

The SVPrivateKey constructor accepts a parameter to select which network the key is meant to be used with.


//override the default networkType parameter in the constructor invocation
var pk = SVPrivateKey(networkType: NetworkType.REGTEST);

Private Keys do not directly have anything to do with network selection. However, the SVPrivateKey() class has convenience methods for directly generating Bitcoin Addresses. Bitcoin Addresses are network-specific. I.e. wallets will generally check whether a specified Bitcoin Address is valid for the intended network.

You can select from the following networks (note that all the TEST networks are functionally equivalent in terms of Private Keys. i.e. selecting any of them results in the same Bitcoin Address)

NetworkType Description
MAIN The Bitcoin Mainnet
REGTEST The Regression Test Network (local node)
TEST The Public Test network
SCALING_TESTNET The Public High-volume test network

Exporting to WIF

The Wallet-import-format (WIF) is a widely used standard for serialising private keys to strings of letters and numbers in a way that make them less prone to fat-fingering since they include a built-in checksum.

var pk = SVPrivateKey(networkType: NetworkType.REGTEST);
var wifString = pk.toWIF();

Importing from WIF

SVPrivateKey privateKey = SVPrivateKey.fromWIF('L3T1s1TYP9oyhHpXgkyLoJFGniEgkv2Jhi138d7R2yJ9F4QdDU2m');