Skip to content

naumantariq/SDK-Xamarin

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Activeledger

Activeledger - Xamarin SDK

The Activeledger Xamarin SDK has been built to provide an easy way to connect your Xamarin application to an Activeledger Network

Activeledger

Visit Activeledger.io

Read Activeledgers documentation

Usage

The SDK currently supports the following functionality

  • Connection handling
  • Key generation
  • Key onboarding
  • Transaction building

Connection

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");

Example

ActiveLedgerLib.SDKPreferences.setConnection("http", "testnet-uk.activeledger.io", "5260");

Key

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.

Generating a key

Example
String KeyType = "EC" or "RSA";

AsymmetricCipherKeyPair keypair = ActiveLedgerLib.GenerateKeyPair.GetKeyPair(KeyType);

Exporting Key

Example
 ActiveLedgerLib.Helper.SaveKeyToFile(ActiveLedgerLib.Helper.GetPrivateKey(keypair), "privatekey.pem");
 ActiveLedgerLib.Helper.SaveKeyToFile(ActiveLedgerLib.Helper.GetPublicKey(keypair), "publickey.pem");

Onboarding a key

Once you have a key generated, to use it to sign transactions it must be onboarded to the ledger network

Example
JObject json = ActiveLedgerLib.GenerateTxJson.GetTxJsonForOnboardingKeys(keypair, KeyType);

string json_str = ActiveLedgerLib.Helper.ConvertJsonToString(json);

var response = ActiveLedgerLib.MakeRequest.makeRequestAsync(ActiveLedgerLib.SDKPreferences.url, json_str);

Transaction

Creating a transaction

JObject jObject = ActiveLedgerLib.GenerateTxJson.GetBasicTxJson(JObject tx, Nullable < bool > selfSign, string sigs);

Signing & sending a transaction

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.

Example
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);

License


This project is licensed under the MIT License

About

Activeledger SDK for Xamarin

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%