The Activeledger Xamarin SDK has been built to provide an easy way to connect your Xamarin application to an Activeledger Network
Read Activeledgers documentation
The SDK currently supports the following functionality
- Connection handling
- Key generation
- Key onboarding
- Transaction building
When sending a transaction, you must pass a connection that provides the information needed to establish a link to the network and specified node.
To do this a connection object must be created. This object must be passed the protocol, address, and port.
ActiveLedgerLib.SDKPreferences.setConnection("protocol", "url", "port");
ActiveLedgerLib.SDKPreferences.setConnection("http", "testnet-uk.activeledger.io", "5260");
There are two key types that can be generated currently, more are planned and will be implemented into Activeledger first. These types are RSA and Elliptic Curve.
String KeyType = "EC" or "RSA";
AsymmetricCipherKeyPair keypair = ActiveLedgerLib.GenerateKeyPair.GetKeyPair(KeyType);
ActiveLedgerLib.Helper.SaveKeyToFile(ActiveLedgerLib.Helper.GetPrivateKey(keypair), "privatekey.pem");
ActiveLedgerLib.Helper.SaveKeyToFile(ActiveLedgerLib.Helper.GetPublicKey(keypair), "publickey.pem");
Once you have a key generated, to use it to sign transactions it must be onboarded to the ledger network
JObject json = ActiveLedgerLib.GenerateTxJson.GetTxJsonForOnboardingKeys(keypair, KeyType);
string json_str = ActiveLedgerLib.Helper.ConvertJsonToString(json);
var response = ActiveLedgerLib.MakeRequest.makeRequestAsync(ActiveLedgerLib.SDKPreferences.url, json_str);
Creating a transaction
JObject jObject = ActiveLedgerLib.GenerateTxJson.GetBasicTxJson(JObject tx, Nullable < bool > selfSign, string sigs);
When signing a transaction you must send the finished version of it. No changes can be made after signing as this will cause the ledger to reject it.
The key must be one that has been successfully onboarded to the ledger which the transaction is being sent to.
JObject tx = <transaction to send>
string tx_str = Helper.ConvertJsonToString(tx);
//converting transaction in to byte Array
byte[] originalData = Helper.ConvertStringToByteArray(tx_str);
//signing the transaction
if (keyType == "RSA")
{
RsaKeyParameters priKey = (RsaKeyParameters)keypair.Private;
byte[] signedData = GenerateSignature.GetSignatureRSA(originalData, priKey);
}
else
{
ECKeyParameters priECKey = (ECKeyParameters)keypair.Private;
byte[] signedData = GenerateSignature.GetSignatureEC(originalData, priECKey);
}
//sending the transaction to ActiveLedger
var response = ActiveLedgerLib.MakeRequest.makeRequestAsync(ActiveLedgerLib.SDKPreferences.url, json_str);
This project is licensed under the MIT License