@block_control/blck
v1.0.36
Published
Package to manage data transactions within a Blockcontrol blockchain environment
Downloads
50
Maintainers
Readme
Blockcontrol Project
A simple and complete library to interact with the Blockcontrol blockchain network, written in TypeScript. This package only works in NodeJS environment, not in the browser
Features
- Encrypt transaction signature with the custom private key
- Generate a nonce to prepare data or payment transaction for validation
- Send a data transaction on validation for a Blockcontrol issuers
- Get Genesis Transaction by Currency name
- Get Total Funds for Custom token issuers
- Finish KYC for Custom token issuers
- Generate a nonce to prepare data or payment transaction for validation for custom token issuer
- Send a data transaction on validation for a Custom token issuers
- Send a payment transaction on validation for a Custom token issuer
- Increase total funds for a Custom token issuer
- Get Official Wallets by Currency name
- Get Private key for a Custom token issuer
Get Started
With NPM
npm i @block_control/blck
With Yarn
yarn add @block_control/blck
Examples
Send Data Transaction on Validation for Blockcontrol Issuers
import {
NonceResponse,
encrypter,
getNonceBlck,
EncryptedContent,
TransactionPayload,
TransactionResponse,
dataTransactionValidateBlck
} from "@block_control/blck";
const sendDataTx = async () => {
const publicKey = "Issuer Public Key";
const privateKey = "Issuer Private Key";
# First Get Nonce from the Blockcontrol
const { nonce, iv }: NonceResponse = await getNonceBlck({
publicKey,
environment: "testNet"
});
# check if nonce and iv are defined
if (!nonce) {
throw new Error("Nonce is not available")
}
if (!iv) {
throw new Error("Iv not available")
}
# Generate a transaction signature
# Use IV from the Nonce Response
const { txSignature }: EncryptedContent = encrypter({
content: nonce.toString(),
iv,
key: privateKey
});
# Create a Data Transaction Payload
const payload: TransactionPayload = {
publicKey,
txSignature,
# metaData represent an object with keys and values for various needs
metaData: {
"name": "John",
"age": 30,
"address": {
"city": "New York",
"zip": 10001
},
"is_student": false,
"hobbies": ["reading", "traveling"]
},
environment: "testNet",
# if You want to encrypt metaData content set isPublic on false
# if metaData content can be visible in the blockchain set isPublic on true
isPublic: true,
}
# Send Data Transaction
const { txid, message }: TransactionResponse = await dataTransactionValidateBlck(payload);
console.log(txid); (fa021fc735adafbd806a50d56e2659834882afe89054cd90ab7efad487bde522)
console.log(message); (transaction created successfully)
}
Get Genesis Transactions by Currency name
import { getGenesisByCurrency } from "@block_control/blck"
const getGenesisTx = async () => {
const { total, transactions } = await getGenesisByCurrency({
currency: "BLCK",
environment: "testNet"
});
console.log("Total", total);
console.log("Transactions", transactions);
# Example for Genesis Transactions
Total: 3
Transactions: [
{
txid: '09ecaaace6d5333078c45c7e70152ccc156d932d94223986592820761269f59e',
payload: {
sender: '0',
receiver: '0',
amount: {
$numberDecimal: '0',
},
currency: 'BLCK',
issuer: '0',
started: 1695485496581,
finished: 1695485496581,
data: '0',
blockid: 3,
tx_fee: 0
},
signers: { signing_pub_key: '0', tx_signature: '0' },
tx_status: 'Success',
tx_type: 'Genesis',
meta_payload: {}
},
{
txid: '72fec972881e5762da5180eab229a53804fff990aa15858f13f28332ff860fb5',
payload: {
sender: '0',
receiver: '0',
amount: {
$numberDecimal: '0',
},
currency: 'BLCK',
issuer: 'blck1111111111111111111111111111111111111111111111111111111111111111',
started: 1695485496581,
finished: 1695485496581,
data: '0',
blockid: 3,
tx_fee: 0
},
signers: { signing_pub_key: '0', tx_signature: '0' },
tx_status: 'Success',
tx_type: 'Genesis',
meta_payload: {}
},
{
txid: '0129b596ee0794bbb1fda150b454f6bc9f06eb42350ee5fefcd38b9294be6bd2',
payload: {
sender: '0',
receiver: '0',
amount: {
$numberDecimal: '0',
},
currency: 'BLCK',
issuer: 'blck2222222222222222222222222222222222222222222222222222222222222222',
started: 1695485496581,
finished: 1695485496581,
data: '0',
blockid: 3,
tx_fee: 0
},
signers: { signing_pub_key: '0', tx_signature: '0' },
tx_status: 'Success',
tx_type: 'Genesis',
meta_payload: {}
}
]
}
Finish KYC for Custom token Issuers
import { finishKYC, KYCProps, KYCResponse } from "@block_control/blck";
const finishKYCCustom = async () => {
const publicKey = "Custom token public key";
const privateKey = "Custom token private key";
const payload: KYCProps = {
privateKey,
publicKey,
environment: "testNet",
email: "[email protected]"
};
const { message, wallet_address, public_key }: KYCResponse = await finishKYC(payload);
console.log(wallet_address); (inuax6baf53b557ae7529589abc38829c355be9b03f27e5bab9c708c005fbf17bec7a)
console.log("Issuer public key", public_key); (00006e27c0a8c8598fbfcd3ff35c5384)
console.log(message); (Issuer successfully finished KYC validation)
}
Get Official Wallets by Currency name
import { OfficialWalletResponse, getOfficialWallets } from "@block_control/blck";
const getOfficial = async () => {
const { data }: OfficialWalletResponse = await getOfficialWallets({
currency: "BLCK",
environment: "testNet"
});
console.log(data);
# Data example
[
{
name: 'Official Wallet',
wallet_type: 'Official',
currency: 'BLCK',
wallet_address: 'blck1111111111111111111111111111111111111111111111111111111111111111',
total_funds: { '$numberDecimal': '19999.100000000000' },
owner: null,
public_key: null,
private_key: null
},
{
name: 'Official Transaction Fee Wallet',
wallet_type: 'Fee',
currency: 'BLCK',
wallet_address: 'blck2222222222222222222222222222222222222222222222222222222222222222',
total_funds: { '$numberDecimal': '0.9000000000000000' },
owner: null,
public_key: null,
private_key: null
}
]
}
Get Custom token Issuer Private Key
import {
CustomPrivateKeyProps,
CustomPrivateKeyResponse,
getPrivateKeyCustomIssuer
} from "@block_control/blck";
const revealPrivateKey = async () => {
const publicKey = "Custom token Public Key";
const privateKey = "Custom token Private Key";
const payload: CustomPrivateKeyProps = {
publicKey,
privateKey,
walletAddress: "Custom token Issuer wallet address",
environment: "testNet"
};
const { private_key, message }: CustomPrivateKeyResponse = await getPrivateKeyCustomIssuer(payload);
console.log(message); (Private key successfully revealed)
console.log(private_key); (e377de1b2d0a09478a931a6ef0a9f534)
}
Get Custom token Issuer Total Funds
import {
TotalFundsPayload,
TotalFundsResponse,
getTotalFundsCustom
} from "@block_control/blck";
const getTotalFunds = async () => {
const publicKey = "Custom token public key";
const privateKey = "Custom token private key";
const payload: TotalFundsPayload = {
privateKey,
publicKey,
walletAddress: "Custom token Issuer wallet address",
environment: "testNet",
};
const { total_funds }: TotalFundsResponse = await getTotalFundsCustom(payload);
console.log("Total funds: ", total_funds); (Total funds: 2464.95)
}
Increase Custom token Issuer Total Funds
import {
FundsProps,
FundsResponse,
increaseFundsCustomIssuer
} from "@block_control/blck"
const increaseFunds = async () => {
const publicKey = "Custom token public key";
const privateKey = "Custom token private key";
const payload: FundsProps = {
publicKey,
privateKey,
walletAddress: "Custom token Issuer Wallet address",
# amount in custom token currency
amount: 550,
environment: "testNet"
};
const { message, txid }: FundsResponse = await increaseFundsCustomIssuer(payload);
console.log(message); (You have increased total funds successfully)
console.log(txid); (bdfc8c8840c035cb126f2f5beb607f536ac9666007d1e05661b13e38c4c1168b)
}
Roll Custom token Issuer Security Keys
import {
RollKeysPayload,
RollKeysResponse,
rollSecurityKeysCustom
} from "@block_control/blck";
const rollSecurityKeys = async () => {
const publicKey = "Custom token Public Key";
const privateKey = "Custom token Private Key";
const payload: RollKeysPayload = {
publicKey,
privateKey,
walletAddress: "Custom token Issuer wallet address",
environment: "testNet"
};
const { public_key, message }: RollKeysResponse = await rollSecurityKeysCustom(payload);
console.log(message); (Roll keys finished successfully)
console.log(public_key); (e377de1b2d0a09478a931a6ef0a9f534)
}
Send Data Transaction on Validation for Custom token Issuers
import {
DataCustomPayload,
TransactionResponse,
EncryptedContent,
NonceCustomResponse,
dataTransactionValidateCustom,
encrypter,
getNonceCustomB2C
} from "@block_control/blck";
const dataTxCustom = async () => {
const publicKey = "Custom token Issuer Public Key";
const privateKey = "Custom token Issuer Private Key";
# First Get Nonce from the Blockcontrol
const { nonce, iv }: NonceCustomResponse = await getNonceCustomB2C({
publicKey,
privateKey,
environment: "testNet"
});
# check if nonce and iv are defined
if (!nonce) {
throw new Error("Nonce is not available")
}
if (!iv) {
throw new Error("Iv not available")
}
# Generate a transaction signature
# Use IV from the Nonce Custom Response
const { txSignature }: EncryptedContent = encrypter({
content: nonce.toString(),
iv,
key: privateKey
});
# Create a Data Transaction Payload
const payload: TransactionPayload = {
publicKey,
txSignature,
# metaData represent an object with keys and values for various needs
metaData: {
"name": "John",
"age": 30,
"address": {
"city": "New York",
"zip": 10001
},
"is_student": false,
"hobbies": ["reading", "traveling"]
},
# set the transaction fee
fee: 0.02,
environment: "testNet",
# if You want to encrypt metaData content set isPublic on false
# if metaData content can be visible in the blockchain set isPublic on true
isPublic: true,
}
# Send Data Transaction
const { txid, message }: TransactionResponse = await dataTransactionValidateCustom(payload);
console.log(txid); (bdfc8c8840c035cb126f2f5beb607f536ac9666007d1e05661b13e38c4c1168b)
console.log(message); (transaction created successfully)
}
Send Payment Transaction on Validation for Custom token Issuers
import {
PaymentCustomPayload,
TransactionResponse,
EncryptedContent,
NonceCustomResponse,
paymentTransactionValidateCustom,
encrypter,
getNonceCustom
} from "@block_control/blck";
const paymentTxCustom = async () => {
const publicKey = "Custom token Public Key";
const privateKey = "Custom token Private Key";
# First Get Nonce from the Blockcontrol
const { nonce, iv }: NonceCustomResponse = await getNonceCustom({
publicKey,
privateKey,
environment: "testNet"
});
# check if nonce and iv are defined
if (!nonce) {
throw new Error("Nonce is not available")
}
if (!iv) {
throw new Error("Iv not available")
}
# Generate a transaction signature
# Use IV from the Nonce Custom Response
const { txSignature }: EncryptedContent = encrypter({
content: nonce.toString(),
iv,
key: privateKey
});
# Create a Data Transaction Payload
const payload: PaymentCustomPayload = {
publicKey,
txSignature,
sender: "Sender Custom token Issuer wallet address",
receiver: "Receiver Custom token Issuer wallet address",
# Amount that sender wants to transfer to the receiver
value: 50,
# set the transaction fee
fee: 0.02,
environment: "testNet",
# you have to provide a socketID to listen validated transactions
socketId: "your socketID"
};
# Send Data Transaction
const { txid, message }: TransactionResponse = await paymentTransactionValidateCustom(payload);
console.log(txid); (acea695063f91ea86810c00804fad7af3aefb5492ff6acf06d8e2bf57c94a9b6)
console.log(message); (Payment transaction sent to validation successfully)
}
Send Payment Transaction on Validation for BLCK B2C Issuers
import {
ValidateB2CTxPayload,
TransactionResponse,
EncryptedContent,
NonceResponse,
validateB2CTx,
encrypter,
getNonceBlck
} from "@block_control/blck";
const paymentB2CTx = async () => {
const publicKey = "BLCK Issuer Public Key";
const privateKey = "BLCK Issuer Private Key";
# First Get Nonce from the Blockcontrol
const { nonce, iv }: NonceResponse = await getNonceBlck({
publicKey,
environment: "testNet"
});
# check if nonce and iv are defined
if (!nonce) {
throw new Error("Nonce is not available")
}
if (!iv) {
throw new Error("Iv not available")
}
# Generate a transaction signature
# Use IV from the Nonce Response
const { txSignature }: EncryptedContent = encrypter({
content: nonce.toString(),
iv,
key: privateKey
});
# Create a Data Transaction Payload
const payload: ValidateB2CTxPayload = {
publicKey,
txSignature,
sender: "Sender Issuer wallet address",
confirmationToken: "Security confirmation token from the BLCK Wallet",
# Amount that sender wants to pay in BLCK
value: 50,
environment: "testNet",
# you have to provide a socketID to listen validated transactions
socketId: "your socketID"
};
# Send Data Transaction
const { txid, message }: TransactionResponse = await validateB2CTx(payload);
console.log(txid); (acea695063f91ea86810c00804fad7af3aefb5492ff6acf06d8e2bf57c94a9b6)
console.log(message); (Payment transaction sent to validation successfully)
}
Send Payment Transaction on Validation for BLCK B2B Issuers
import {
ValidateB2BTxPayload,
TransactionResponse,
EncryptedContent,
NonceResponse,
validateB2CTx,
encrypter,
getNonceBlck
} from "@block_control/blck";
const paymentB2CTx = async () => {
const publicKey = "BLCK Issuer Public Key";
const privateKey = "BLCK Issuer Private Key";
# First Get Nonce from the Blockcontrol
const { nonce, iv }: NonceResponse = await getNonceBlck({
publicKey,
environment: "testNet"
});
# check if nonce and iv are defined
if (!nonce) {
throw new Error("Nonce is not available")
}
if (!iv) {
throw new Error("Iv not available")
}
# Generate a transaction signature
# Use IV from the Nonce Response
const { txSignature }: EncryptedContent = encrypter({
content: nonce.toString(),
iv,
key: privateKey
});
# Create a Data Transaction Payload
const payload: ValidateB2BTxPayload = {
publicKey,
txSignature,
sender: "Sender Issuer wallet address",
recipient: "Recipient Issuer wallet address",
confirmationToken: "Security confirmation token from the BLCK Wallet",
# Amount that sender wants to pay in BLCK
value: 50,
# Additional fee for payment processing
additionalFee: 0.03,
environment: "testNet",
# you have to provide a socketID to listen validated transactions
socketId: "your socketID"
};
# Send Data Transaction
const { txid, message }: TransactionResponse = await validateB2CTx(payload);
console.log(txid); (acea695063f91ea86810c00804fad7af3aefb5492ff6acf06d8e2bf57c94a9b6)
console.log(message); (Payment transaction sent to validation successfully)
}
Generate security confirmation token for external issuers
import {
generateExternalConfirmationToken,
ConfirmationTokenPayload,
ConfirmationTokenResponse
} from "@block_control/blck";
const generateConfirmationToken = async () => {
const publicKey = "External Official Public Key";
const privateKey = "External Official Private Key";
const walletAddress = "External wallet address"
const payload: ConfirmationTokenPayload = {
publicKey,
privateKey,
walletAddress,
environment: "test"
};
# Generate Security confirmation token
const { conftoken, message, error }: ConfirmationTokenResponse = await generateExternalConfirmationToken(payload);
if (error) {
# do something with error
}
console.log(conftoken); ("conftoken": { "code_expiration": 1707078101138, "code": "LWIXMC" })
console.log(message); (Confirmation token generated successfully)
}
Get security confirmation token for external issuers
import {
getExternalConfirmationToken,
ConfirmationTokenPayload,
ConfirmationTokenResponse
} from "@block_control/blck";
const getConfirmationToken = async () => {
const publicKey = "External Official Public Key";
const privateKey = "External Official Private Key";
const walletAddress = "External wallet address"
const payload: ConfirmationTokenPayload = {
publicKey,
privateKey,
walletAddress,
environment: "test"
};
# Get Security confirmation token
const { conftoken, message, error }: ConfirmationTokenResponse = await getExternalConfirmationToken(payload);
if (error) {
# do something with error
}
console.log(conftoken); ("conftoken": { "code_expiration": 1707078101138, "code": "LWIXMC" })
console.log(message); (Confirmation token generated successfully)
}
Send Payment Transaction on Validation for External B2C Issuers
You can use this method if you have 3rd party services that are using your custom token. In this case sender does not pays transaction fee, issuer or transaction holder will receive sender`s value, and will pay transaction fee.
import {
ValidateExternalB2CTxPayload,
TransactionResponse,
EncryptedContent,
NonceResponse,
validateExternalB2CTx,
encrypter,
getNonceBlck
} from "@block_control/blck";
const paymentExternalB2CTx = async () => {
const publicKey = "External Official Public Key";
const privateKey = "External Official Private Key";
# First Get Nonce from the Blockcontrol
const { nonce, iv }: NonceResponse = await getNonceBlck({
publicKey,
environment: "testNet"
});
# check if nonce and iv are defined
if (!nonce) {
throw new Error("Nonce is not available")
}
if (!iv) {
throw new Error("Iv not available")
}
# Generate a transaction signature
# Use IV from the Nonce Response
const { txSignature }: EncryptedContent = encrypter({
content: nonce.toString(),
iv,
key: privateKey
});
# Create a Data Transaction Payload
const payload: ValidateExternalB2CTxPayload = {
publicKey,
txSignature,
sender: "External Sender wallet address",
issuer: "External Issuer wallet address - Transaction holder",
confirmationToken: "External security confirmation token",
# Amount that sender wants to pay in custom token
value: 50,
# Payment processing fee
fee: 0.03,
environment: "testNet",
# you have to provide a socketID to listen validated transactions
socketId: "your socketID"
};
# Send Payment Transaction
const { txid, message }: TransactionResponse = await validateExternalB2CTx(payload);
console.log(txid); (acea695063f91ea86810c00804fad7af3aefb5492ff6acf06d8e2bf57c94a9b6)
console.log(message); (Payment transaction sent to validation successfully)
}
Send Payment Transaction on Validation for External B2B Issuers
You can use this method if you have 3rd party services that are using your custom token. In this case sender pays transaction fee and additional fee, recipient will receive the value from the sender, and issuer will receive additional fee.
import {
ValidateExternalB2BTxPayload,
TransactionResponse,
EncryptedContent,
NonceResponse,
validateExternalB2BTx,
encrypter,
getNonceBlck
} from "@block_control/blck";
const paymentExternalB2CTx = async () => {
const publicKey = "External Official Public Key";
const privateKey = "External Official Private Key";
# First Get Nonce from the Blockcontrol
const { nonce, iv }: NonceResponse = await getNonceBlck({
publicKey,
environment: "testNet"
});
# check if nonce and iv are defined
if (!nonce) {
throw new Error("Nonce is not available")
}
if (!iv) {
throw new Error("Iv not available")
}
# Generate a transaction signature
# Use IV from the Nonce Response
const { txSignature }: EncryptedContent = encrypter({
content: nonce.toString(),
iv,
key: privateKey
});
# Create a Data Transaction Payload
const payload: ValidateExternalB2BTxPayload = {
publicKey,
txSignature,
sender: "External Sender wallet address",
recipient: "External Recipient wallet address",
issuer: "External Issuer wallet address - Transaction holder",
confirmationToken: "External security confirmation token",
# Amount that sender wants to pay in custom token
value: 50,
# Payment processing fee
fee: 0.03,
# Payment processing fee determined by issuer
additionalFee: 0.01,
environment: "testNet",
# you have to provide a socketID to listen validated transactions
socketId: "your socketID"
};
# Send Payment Transaction
const { txid, message }: TransactionResponse = await validateExternalB2BTx(payload);
console.log(txid); (acea695063f91ea86810c00804fad7af3aefb5492ff6acf06d8e2bf57c94a9b6)
console.log(message); (Payment transaction sent to validation successfully)
}
Listen payment data transactions status for Custom token
For all payment transactions sent to validation it is necessary to listen for the transaction status updates. Set the Socket service to listen events. This is example how to do it with the Express framework.
import express from 'express';
import http from 'http';
import { Server, Socket } from 'socket.io';
import { connect } from 'socket.io-client';
const app = express();
const server = http.createServer(app);
const ioServer = new Server(server);
# Connect to the Blockcontrol Socket
const ioClient = connect('https://socket-external.blockcontrol.xyz', {
# it is mandatory to set transports only on websocket
transports: ["websocket"],
});
const publicKey = "Custom token public key";
ioClient.on('connect', () => {
console.log('Server Custom: Connected to the Blockcontrol network.');
# Send public key to the Blockcontrol
ioClient.emit("connect_server", ({ publicKey }));
# Listen "transaction_validated" channel
ioClient.on('transaction_validated', ({ txid, status }) => {
console.log(`Transaction status is ${status} for txid ${txid}`);
});
});
server.listen(8900, () => {
console.log('Server Custom listening on port 8900');
});