Advice and answers from the BitPay Team

A Bitcoin SIN (System Identification Number), also referred to as an ID , is a digital identity using a cryptographic private-public key pair. A Bitcoin SIN is comparable to a Bitcoin address, as they are both able to be derived from the same type of public and private keys.

BitPay offers methods to create a Bitcoin SIN in 5 programming languages:

  • Elixir
  • Java
  • PHP
  • Python
  • Ruby

Elixir

To pair your client using Elixir, you'll first generate a pem  file. A WebClient  can then be created from the pem file. Please note, it is necessary to persist the pem  file for re-use.

To generate a pem file by running the following:

pem = BitPay.KeyUtils.generate_pem

To create your webclient:

webclient = %BitPay.WebClient{pem:pem}

A URI can be added to pair with the test server.

webclient = %BitPay.WebClient{pem:pem, 
uri:"https://test.bitpay.com/"}

Java

The BitPay server requires a public and private key which are used for all client interaction with the server. The public key is used to derive the client identity and to securely sign all API requests from the client. Storing your private key is necessary.

Depending on your circumstances, there are two methods to create a private key, internally or externally (and inject the key into the SDK).

Internal

Create a private key using the SDK:

ECKey key = KeyUtils.createEcKey();

Store the private key, as it is necessary, and inject it into the SDK:

this.bitpay = new BitPay(key);

External

Create the Private Key outside of the SDK:

String privateKey = 
KeyUtils.getKeyStringFromFile(privateKeyFile);
ECKey key = KeyUtils.createEcKeyFromHexString(privateKey);

Inject the private key into the SDK:

this.bitpay = new BitPay(key);

PHP

To create a SIN using PHP, you must first create your keypair - or your private and public key. You will then use your keypair to derive your SIN. When creating your keypair and SIN, you must be sure to save your private key.

First, create your keys.php  file:

<?php

//Include autoload, as it’s a necessary component
include('vendor/autoload.php');

//Create your private_key and public_key objects
$private_key = new \Bitpay\PrivateKey(‘./api.key');
$public_key = new \Bitpay\PublicKey(‘./api.pub');

// Assign a value to the private_key object
$private_key->generate();
// Associate private_key with public_key, and then assign a
 value to the public_key object
$public_key->setPrivateKey($private_key);
$public_key->generate();

// Use the key manager to persist keys
$manager = new \Bitpay\KeyManager(new \Bitpay\Storage\
 FilesystemStorage());
$manager->persist($private_key);
$manager->persist($public_key);

?>

Run  bitpay.php :

$ php bitpay.php

Which will return something like:

Bitpay\Token Object
(
    [token:protected] => RealTokenValueHere
    [resource:protected] =>
    [facade:protected] => merchant
    [createdAt:protected] => DateTime Object
        (
            [date] => 2015-03-13 10:53:20
            [timezone_type] => 3
            [timezone] => America/New_York
        )

    [policies:protected] => Array
        (
            [0] => Array
                (
                    [policy] => id
                    [method] => inactive
                    [params] => Array
                        (
                            [0] => SinHere
                        )

                )

        )

    [pairingCode:protected] => Ag65qWh
    [pairingExpiration:protected] => DateTime Object
        (
            [date] => 2015-03-14 10:53:20
            [timezone_type] => 3
            [timezone] => America/New_York
        )

)

Extract the pairingCode  from the response and use it to approve your API access on your dashboard, e.g.:
https://test.bitpay.com/api-access-request?pairingCode=Ag65qWh 

Python

To create a Bitcoin SIN using Python, you'll first create a pem  file from which you'll derive a Bitcoin SIN. To create a pem  file, you will first need to install the Python library using pip . Packages are available for Python 2.7 and Python 3.

With the package installed, import the BitPay Key Utilities:

import bitpay_key_utils as key_utils

Generate a pem  file by running the following:

pem = key_utils.generate_pem();

Save the pem file:

f = open("temp/local.pem", 'w');
f = write(pem);

Run the following to get the Bitcoin SIN from the pem  file:

sin = get_sin_from_pem(pem);

To pair your Bitcoin SIN, create a function for Merchant Token creation:

def create_merchant_token(self):
   payload = { 'id': self.client_id, 'facade': 'merchant'}
   headers = {"content-type": "application/json", "accept":
     "application/json", "X-accept-version": "2.0.0"}
   try:
     response = requests.post(self.uri + "/tokens", verify=
       self.verify, data=json.dumps(payload), headers=
       headers)
   except Exception as pro:
     raise BitPayConnectionError('Connection refused')
   if response.ok:
     return response.json()
   self.response_error(response)

Running the above code will return a response similar to the following response:

{u'data': [{u'pairingExpiration': 1426204460704,
u'dateCreated': 1426118060704, u'pairingCode': u'QmxX9Cv',
u'token': u'8wYeZP2gsXS9e7qLzP8bjP', u'policies':
[{u'policy': u'id', u'params': [u'TexR5Y32WeEZmHXQocVF9TdDfg6ytapbzHL'], u'method': u'inactive'}], u'facade': u'merchant'}]}

Extract the pairingCode  from the response and use it to approve your API access on your dashboard, e.g.:
https://test.bitpay.com/api-access-request?pairingCode=QmxX9Cv 

Ruby

To create a Bitcoin SIN using Ruby, you must first create a pem file from which you will derive your Bitcoin SIN.

First, install the bitpay-sdk  Ruby gem:

gem install bitpay-sdk

Generate a pem file by running the following:

pem = Bitpay::KeyUtils.generate_pem

Save the pem file:

File.open('path','w') {|f| f.write(pem)}

Run the following to get the SIN from the pem file:

sin = Bitpay::KeyUtils.generate_sin_from_pem(pem)

Pairing a client in Ruby can be done using the PEM, OpenSSL, and the irb  (interactive Ruby) tool. Open the irb tool and import the bitpay_sdk:

irb
require 'bitpay_sdk'

Create your client: (Negate the api_uri parameter to create a client on our live server. Note that for this example, we are pairing to BitPay's Test server.)

client = BitPay::SDK::Client.new(api_uri:
'https://test.bitpay.com', pem: File.read('pem.pem'), insecure: true)

Request pairing using the client:

client.pair_client()

Which will return something like:

 => {"data"=>[{"policies"=>[{"policy"=>"id", "method"=>
"inactive", "params"=>["Tf49SFeiUAtytFEW2EUqZgWj32nP51PK73M"]}], "token"=>"BKQyVdaGQZAArdkkSuvtZN5gcN2355c8vXLj5eFPkfuK", "dateCreated"=>1422474475162, "pairingExpiration"=>1422560875162, "pairingCode"=>"Vy76yTh"}]}

Extract the pairingCode  from the response and use it to approve your API access on your dashboard, e.g.:
https://test.bitpay.com/api-access-request?pairingCode=Vy76yTh 

Did this answer your question?