Colu-node
Colu platform, PHP SDK, (*1)
Install
Install Composer in your project:, (*2)
$curl -s http://getcomposer.org/installer | php
Create a composer.json file in your project root:, (*3)
{
"require": {
"Colu/Colu": "1.0.4"
}
}
Install via Composer, (*4)
$php composer.phar install
Generate keys for your company:
If you create an instance of the Colu class with only the company name, the privateKey will be generated randomly on your machine.
Your privateKey is what defines your company., (*5)
require_once ('vendor/autoload.php');
use Colu\ColuSDK\Colu;
$colu = new Colu('my_company', 'testnet');
// This is your private key, keep it safe!!!
echo 'WIF: '.$colu->getWIF();
Create instance from an existing key:
When you want to use our module in your server you need to generate keys only once. After that you can create an instance of Colu with your key:, (*6)
require_once ('vendor/autoload.php');
use Colu\ColuSDK\Colu;
$privateKey = 'cQQy71GeXGeFWnDtypas2roY2qrk3KWjJLCxoFqc2wibXr2wWxie'; // this is the WIF version of a private key
$colu = new Colu('my_company', 'testnet', $privateKey);
Register a user using 2FA:
There are two methods for registering a user using 2FA, directly by using a Phonenumber or by generating a QR code and then having the user scan the QR with their phone., (*7)
In both methods you need to Create a registration message:, (*8)
php
$username = 'bob';
$registrationMessage = $colu->createRegistrationMessage($username);, (*9)
-
QR registration:, (*10)
$qr = $colu->createRegistrationQR($registrationMessage);
This will return an array containing the QR and the message to be verified:, (*11)
"qr" => $qrCode->getDataUri (), // this is the actual QR image
"code" => $qrRegCode, // send this to the registerUserByCode function
"message" => $message // send this to the registerUserByCode function
Send the registration request:, (*12)
$colu->registerUserByCode ( $code, $message );
This will send a push notification to the user mobile application that will wait until approval is recieved., (*13)
-
Phonenumber Registration:, (*14)
$phonenumber = "+12323455673";
$colu->registerUserByPhonenumber ( $phonenumber, $registrationMessage );
This will send a push notification to the user mobile application that will wait until approval is recieved., (*15)
If successful both cases return an array:, (*16)
"success" => true,
"userId" => $user->getId () // this is the user ID
save the userId for future verifications., (*17)
Verify user:
To verify a user:, (*18)
$username = 'bob';
$userId = 'tpubDCgCu2jpxrR7j9JwFQ959wSkNwPQFNQvJJMFnikg1Sb4tkDnBNYaS3Sc1BxKL71hk3jPkQStEY1VE9mTaQjF8kDfEhzxjWid7eVK5F7nWi5';
if ($colu->verifyUser($username, $userId, 0)) {
echo "verified";
}
else {
echo $colu->error;
// something bad happened
}
}
This will send a push to the user mobile application and prompt him to sign on your message, you will receive the user signature and verify it locally., (*19)