Creating Signatures

Signature

A signature helps us to verify that a piece of data was signed by a specific wallet account. There are two types of signatures used in Gluwa API:
  1. 1.
    Address Signature
  2. 2.
    Transaction Signature

Address Signature

Address signature is used to verify the ownership of a cryptocurrency (e.g., Bitcoin or Ethereum) wallet. A cryptocurrency wallet is a set of a private key and a public key. To generate a signature, you sign a message (or a piece of data) with your private key, and then anyone with your public key can verify the integrity of your signature. To prevent the same signature used over and over again, our APIs mandates the users to use Unix timestamp as the message. The server will check if the timestamp was created no more than 10 minutes ago, and if it has been over 10 minutes, it will deny the request.

Generating Address Signature for Gluwacoins (USD-G, KRW-G, NGN-G)

Since Gluwacoins, such as USD-G, KRW-G and NGN-G, are ERC20 tokens, you can sign a message just like you would on any Ethereum based address. There are libraries out there that can help you create signatures. Some examples include:
  1. 1.
    web3.js. (JavaScript)
  2. 2.
    Nethereum (C#)
JavaScript (web.js)
C# (Nethereum)
1
var Web3 = require('web3');
2
3
...
4
5
// replace with your own message and privakey
6
var message = "1587674497";
7
var privateKey = "0x18cffe0cd4eb63809d0e55ed8dd1aa29e3ac660088e82f7a82977c458f334d8b";
8
9
var web3 = new Web3(Web3.givenProvider);
10
var obj = web3.eth.accounts.sign(message , privateKey);
11
12
// signature: 0x96322ca1b963c98e33fe1296b504d3c7adfcfd4e8473bf92f6ee24b560497d16390404a4f9f241d9efdd02cf1fea79d0ebf45d4aa2ef47a4c97fa06750e242301c
13
var signature = obj.signature;
14
15
Copied!
1
using Nethereum.Signer;
2
3
...
4
5
// replace with your own message and privakey
6
string message = "1587674497";
7
string privateKey = "0x18cffe0cd4eb63809d0e55ed8dd1aa29e3ac660088e82f7a82977c458f334d8b";
8
9
EthereumMessageSigner signer = new EthereumMessageSigner();
10
11
// signature: 0x96322ca1b963c98e33fe1296b504d3c7adfcfd4e8473bf92f6ee24b560497d16390404a4f9f241d9efdd02cf1fea79d0ebf45d4aa2ef47a4c97fa06750e242301c
12
string signature = signer.EncodeUTF8AndSign(message, new EthECKey(privateKey));
13
14
Copied!
In production environment, your private key should never be hard coded like above. Private keys must be kept secret and be handled with utmost care.

Generating Address Signature for Bitcoin

There are unofficial Bitcoin libraries you can use to create the signature. Some examples include:
  1. 1.
    BitcoinJS (JavaScript)
  2. 2.
    NBitcoin (C#)
BitcoinJS (JavaScript)
NBitcoin (C#)
1
var bitcoin = require('bitcoinjs-lib');
2
var bitcoinMessage = require('bitcoinjs-message');
3
4
...
5
6
// replace with your own message and privakey
7
var network = bitcoin.networks.bitcoin;
8
var message = "1587674497";
9
var privateKeyString = "KwJfd6xHiqtEFBawy8tKPyJ9TFKQCqHpMr8DQVJ9LbUBj21jqFjE";
10
11
var keyPair = bitcoin.ECPair.fromWIF(privateKeyString, network);
12
var privateKey = keyPair.privateKey;
13
14
// signature: H8Gc4g7/X+JsHZyV/qjQSMg9ivoopMztzx9efeV+a+eAJ7Y45OnEi3qmhVWaL743jofge4gQVapzAVsHFSSpBSk=
15
var signature = bitcoinMessage
16
.sign(message, privateKey, keyPair.compressed)
17
.toString('base64');
18
19
Copied!
1
using NBitcoin;
2
3
...
4
5
// replace with your own message and privakey
6
string message = "1587674497";
7
string privateKey = "KwJfd6xHiqtEFBawy8tKPyJ9TFKQCqHpMr8DQVJ9LbUBj21jqFjE";
8
9
BitcoinSecret secret = Network.Main.CreateBitcoinSecret(privateKey);
10
11
// signature: H1iG0zN+TmigcsHDUw2XQo0Wd0LKXbDVG8yr104I0g64cB1kq6WUPKUiI1oNc9Uo9hCRFlfZ3UcALJZNCSy1ZjY=
12
string signature = secret.PrivateKey.SignMessage(message);
13
14
// OR you don't have to force low R. Both format is accepted
15
// signature: H8Gc4g7/X+JsHZyV/qjQSMg9ivoopMztzx9efeV+a+eAJ7Y45OnEi3qmhVWaL743jofge4gQVapzAVsHFSSpBSk=
16
signature = secret.PrivateKey.SignMessage(Encoding.UTF8.GetBytes(message), false);
17
18
Copied!

Transaction Signature

To create a transaction, you must create a signature of the transfer information so that Gluwa can submit it to the blockchain as a proof-of-intention. Think of signature as a signed contract. You send the contract to Gluwa to submit it to the blockchain for you. The authority (Gluwacoin smart contract or Bitcoin blockchain in this case) can verify that the information in the contract is genuine with your signature.

Generating Transaction Signature for Gluwacoins (USD-G, KRW-G, NGN-G)

Gluwacoin is an ERC-20 token. Users can transfer Gluwacoin as they would transfer any other ERC-20 token. To move tokens on the blockchain, you would normally have to spend Ether to cover the gas for the transaction. However, Gluwacoin allows you to move the coins by paying gas in Gluwacoin instead of Ether. We call this ETHless transfer.
You are going to need the contract addresses to make a transaction signature. Use the following addresses.
Production
Sandbox
ERC20 Contract Addresses
ERC20 Contract Addresses
To create a Transaction Signature, you can use well known libraries like web.js or Nethereum.
web3.js (JavaScript)
Nethereum (C#)
1
var Web3 = require('web3');
2
3
...
4
5
// replace the values below with your own values
6
var contractAddress = "0xfb0aaa0432112779d9ac483d9d5e3961ece18eec"; // USD-G contract
7
var sourceAddress = "0x3E6d16c11497aD1A2F47a6594d995f1FaaE727d9";
8
var sourcePrivateKey = "0x18cffe0cd4eb63809d0e55ed8dd1aa29e3ac660088e82f7a82977c458f334d8b";
9
var targetAddress = "0xc4f7fDf5EB4a1204dCa3BeC609f9E457C4fF9844";
10
var amount = 100; // sending 100 USD-G
11
var fee = 0.5; // fee is 0.5 USD-G
12
var nonce = 1;
13
14
var web3 = new Web3(Web3.givenProvider);
15
16
var hash = web3.utils.soliditySha3({ t: 'address', v: contractAddress },
17
{ t: 'address', v: sourceAddress },
18
{ t: 'address', v: targetAddress },
19
{ t: 'uint256', v: web3.utils.toWei(amount.toString(), 'ether') },
20
{ t: 'uint256', v: web3.utils.toWei(fee.toString(), 'ether') },
21
{ t: 'uint256', v: nonce });
22
23
var obj = web3.eth.accounts.sign(hash , sourcePrivateKey);
24
25
// signature: 0x8fa899ec93a3f20b5294bed40ab33bac0913b0c9670a48795b99ff8f994526b95e6ff5d7e8ef2ab99c4b1edaf70569b549ba3747e7b4e43ade28405035777bfb1b
26
var signature = obj.signature;
27
28
29
Copied!
1
using Nethereum.ABI;
2
using Nethereum.Signer;
3
using Nethereum.Util;
4
using Nethereum.Web3;
5
using System.Numerics;
6
7
...
8
9
// replace the values below with your own values
10
string contractAddress = "0xfb0aaa0432112779d9ac483d9d5e3961ece18eec"; // USD-G contract
11
string sourceAddress = "0x3E6d16c11497aD1A2F47a6594d995f1FaaE727d9";
12
string sourcePrivateKey = "0x18cffe0cd4eb63809d0e55ed8dd1aa29e3ac660088e82f7a82977c458f334d8b"; string targetAddress = "0xc4f7fDf5EB4a1204dCa3BeC609f9E457C4fF9844";
13
decimal amount = 100m; // sending 100 USD-G
14
decimal fee = 0.5m; // fee is 0.5 USD-G
15
BigInteger nonce = new BigInteger(1);
16
17
18
ABIEncode abiEncode = new ABIEncode();
19
20
byte[] hash = abiEncode.GetSha3ABIEncodedPacked(
21
new ABIValue("address", contractAddress),
22
new ABIValue("address", sourceAddress),
23
new ABIValue("address", targetAddress),
24
new ABIValue("uint256", Web3.Convert.ToWei(amount, UnitConversion.EthUnit.Ether)),
25
new ABIValue("uint256", Web3.Convert.ToWei(fee, UnitConversion.EthUnit.Ether)),
26
new ABIValue("uint256", nonce)
27
);
28
29
EthereumMessageSigner messageSigner = new EthereumMessageSigner();
30
31
// signature: 0x8fa899ec93a3f20b5294bed40ab33bac0913b0c9670a48795b99ff8f994526b95e6ff5d7e8ef2ab99c4b1edaf70569b549ba3747e7b4e43ade28405035777bfb1b
32
string signature = messageSigner.Sign(hash, sourcePrivateKey );
33
Copied!
Note that when you generate the transaction signature, you must multiply the amount and the fee by 10^18 (1,000,000,000,000,000,000). For example, if you want to transfer 10 USD-G, the value for the amount when you create transaction signature must be 10,000,000,000,000,000,000. However, the amount in the transaction request body must be 10.

Generating Transaction Signature for Bitcoin

Create and sign Bitcoin transaction like you normally would. You can use well known libraries like BitcoinJS or NBitcoin.
BitcoinJS (JavaScript)
NBitcoin (C#)
1
var bitcoin = require('bitcoinjs-lib');
2
var bitcoinMessage = require('bitcoinjs-message');
3
4
...
5
6
7
var btcToSatoshi = 100000000;
8
9
// replace the values below with your own values
10
var network = bitcoin.networks.bitcoin;
11
var sourceAddressString = "12koEsMzrdxuZ71ATU1a5jgZyUYtf3debA";
12
var sourceAddressPrivateKey = "KwJfd6xHiqtEFBawy8tKPyJ9TFKQCqHpMr8DQVJ9LbUBj21jqFjE";
13
var targetAddressString = "14NYL22gWLrVPEdjM6W5oJXcWyu496kZCQ";
14
var amountToSend = 0.001;
15
var fee = 0.00006;
16
var previousTxnHash = "e52fd66f35c48e690d8caada1a881ebb11912c479783f51f839a8827a9afcad4";
17
var unspentOutputAmount = 0.03800757;
18
var unspentOutputIndex = 1;
19
20
var keyPair = bitcoin.ECPair.fromWIF(sourceAddressPrivateKey, network);
21
22
var txnBuilder = new bitcoin.TransactionBuilder(network);
23
txnBuilder.addInput(previousTxnHash, unspentOutputIndex);
24
txnBuilder.addOutput(sourceAddressString, (unspentOutputAmount - amountToSend - fee) * btcToSatoshi);
25
txnBuilder.addOutput(targetAddressString, amountToSend * btcToSatoshi);
26
txnBuilder.sign(0, keyPair);
27
28
var txn = txnBuilder.build();
29
30
// signature: 0200000001d4caafa927889a831ff58397472c9111bb1e881adaaa8c0d698ec4356fd62fe5010000006b483045022100f5e8970b5cb154e96d5696f8fa2c36fabb3e86caf2cd681490448b38403ee92b0220797a0f61f869173d4dbf65894b772cb953349defe2b6275872f0a0b3bc01b86a0121034274d104b6d68ebf109ae3cd35cd53e8b8cd359bedf5598a92033292ae7f76a4ffffffff02a5603800000000001976a91413409c509b056480b21e54d0c5d2b87965eff65188aca0860100000000001976a91424fb438587b31ffd7612f4fbf6d67e21f4bb3ec788ac00000000
31
var signature = txn.toHex();
32
33
Copied!
1
using NBitcoin;
2
3
...
4
5
// replace the values below with your own values
6
Network network = Network.Main;
7
string sourceAddressString = "12koEsMzrdxuZ71ATU1a5jgZyUYtf3debA";
8
string sourceAddressPrivateKey = "KwJfd6xHiqtEFBawy8tKPyJ9TFKQCqHpMr8DQVJ9LbUBj21jqFjE";
9
string targetAddressString = "14NYL22gWLrVPEdjM6W5oJXcWyu496kZCQ";
10
decimal amountToSend = 0.001m;
11
decimal fee = 0.00006m;
12
string previousTxnHash = "e52fd66f35c48e690d8caada1a881ebb11912c479783f51f839a8827a9afcad4";
13
string previousTxnScriptPubKey = "76a914b797bc584c969a2b6b5e613c5ab86b5de57c07ec88ac";
14
Money unspentOutputAmount = Money.Parse("0.03800757");
15
uint unspentOutputIndex = 1;
16
17
BitcoinAddress sourceAddress = BitcoinAddress.Create(sourceAddressString, network);
18
BitcoinAddress targetAddress = BitcoinAddress.Create(targetAddressString, network);
19
BitcoinSecret secret = new BitcoinSecret(sourceAddressPrivateKey, network);
20
21
TransactionBuilder builder = network.CreateTransactionBuilder();
22
Transaction txn = builder
23
.AddKeys(secret)
24
.AddCoins(
25
new Coin(
26
fromTxHash: new uint256(previousTxnHash),
27
fromOutputIndex: unspentOutputIndex,
28
amount: unspentOutputAmount,
29
scriptPubKey: Script.FromHex(previousTxnScriptPubKey)
30
)
31
)
32
.Send(targetAddress, amountToSend.ToString())
33
.SetChange(sourceAddress)
34
.SendFees(fee.ToString())
35
.BuildTransaction(true);
36
37
// signature: 0100000001d4caafa927889a831ff58397472c9111bb1e881adaaa8c0d698ec4356fd62fe50100000000ffffffff02a0860100000000001976a91424fb438587b31ffd7612f4fbf6d67e21f4bb3ec788aca5603800000000001976a91413409c509b056480b21e54d0c5d2b87965eff65188ac00000000
38
string signature = txn.ToHex();
39
40
Copied!
Note that the above is just an example. The number of inputs and outputs may differ for each transaction so you may have to rearrange inputs and outputs accordingly.

Reserve Signature

When a market consumer and a market provider agree to exchange currencies, they need to lock the amount that they promised to send to each other so that those funds are available when the exchange actually happens. This process is called “Reserving.”
Since we don’t save the private keys of any user in our system, the user has to give us the txn signature for the reserving funds. There are two types of reservation:
Gluwacoin reservation
Bitcoin reservation

Execute Signature

Reclaim Signature

Last modified 1yr ago