GithubHelp home page GithubHelp logo

fibercrypto / libskyfiber-dotnet Goto Github PK

View Code? Open in Web Editor NEW
1.0 5.0 4.0 1.62 MB

Skycoin client libraries for .NET ( C# )

C# 61.78% Makefile 0.34% Dockerfile 0.10% Shell 0.45% C 37.28% Batchfile 0.05%
skycoin client-library rest-client restapi rest-api swagger openapi swig dotnet dotnet-library

libskyfiber-dotnet's Introduction

Libskycoin for .Net

Build Status

.Net client library for Skycoin API. This library is a .Net composed assembly generated with SWIG and OPENAPI to access Skycoin API from .Net.

Table of Contents

LibSkycoinNet wrappers for the Skycoin cipher

LibSkycoinNet is an assembly that provides wrappers to the Skycoin core cipher API's, implemented in golang, hence linking directly to the original node code. No transpilation involved.

Installation

Before installing, make sure you understand the choices available to install a Nuget package and the level of support in your platform for each possible configuration. For instance, in case of installing Nuget client tools the process would look like this, using dotnet add package command.

dotnet add package LibSkycoinNet

... or using Nuget install command ...

nuget install LibSkycoinNet

It is possible to install the package using Visual Studio Package Manager Console by executing the following command and then follow the instructions to install and use a package in Visual Studio.

Install-Package LibSkycoinNet

For getting similar results using a graphical IDE interface consider package name to be LibSkycoinNet and consult the articles listed below:

Install from sources

Download the repository from http://github.com/simelo/libskycoin-dotnet.git. Execute (nuget restore LibskycoinNet.sln) to install the library. Although executing (nuget install NUnit.Runners -Version 2.6.4 -OutputDirectory testrunner) is a better choice for making changes to the library. However, when using tox these commands are not required at all because calling tox will make any necessary installation and execute the tests.

Usage

Naming

The exported function in Libskycoin .NET have the following naming format: SKY_package_func_name where package is replace by the package where the original Skycoin function is and func_name is the name of the function. For example, LoadConfig function from cli package is called in .Net SKY_cli_LoadConfig

Parameters

All skycoin exported functions return an error object as the last of the return parameters. In .NET error is return as an uint and it is the first return parameter. The rest of the parameters are returned in the same order.

Receivers in Skycoin are the first of the input parameters. Simple types, like integer, float, string will be used as the corresponding types in .NET, except what act as pointers.

Handles

Some of Skycoin types are too complex to be exported to a scripting language. So, handles are used instead. Therefore all functions taking a complex type will receive a handle instead of the original Skycoin type. For example, having these functions exported from Skycoin:

  func LoadConfig() (Config, error)
  func (c Config) FullWalletPath() string

Config is a struct type that is treated as a handle in Libskycoin .Net . The usage in .Net will be:

using skycoin;
namespace LibskycoinNet
{
    public class Skycoin : skycoin.skycoin
    {
    public function main(){
      var configHandle = new_Config_HandlePtr();
      var err = SKY_cli_LoadConfig(configHandle);
      if(err == SKY_OK) {
        // SkY_OK means no error
        var fullWalletPath = new _GoString()_;
        err = SKY_cli_FullWalletPath(configHandle,fullWallerPath);
        Assert.AreEqual(err,SKY_OK);
        Console.WriteLine(fullWallerPath.p);

        //Close the handle after using the it
        //so the garbage collector can delete the object associated with  it.
        SKY_handle_close( configHandle );
      } else {
        #Error
        Console.WriteLine(err);
      }
    }
  }
}
Byte slices

Parameters of type byte[] will treated as string . Example, this function in Skycoin:

func (s ScryptChacha20poly1305) Encrypt(data, password []byte) ([]byte, error)

... should be invoked like this:

var encrypt_settings = new encrypt__ScryptChacha20poly1305();
var data = new GoSlice(); //It will be passed as a parameter of type []byte
var pwd = new GoSlice(); //As []byte too
var dataStr = new _GoString();
var pwdStr = new _GoString();
var encrypted = new GoSlice();

dataStr.setString("Data to encrypt" );
data.convertString(dataStr);
pwdStr.SetString("password");
pwd.convertString(pwdStr);

var err = SKY_encrypt_ScryptChacha20poly1305_Encrypt(encrypt_settings, data, pwd,encrypted);
if(err == SKY_OK){
  Console.WriteLine(encrypted.getString().p); //Encrypted is GoSlice
}
Structures

Structures that are not exported as handles are treated like .NET classes. In the previous example type ScryptChacha20poly1305 is created in .NET like:

var encrypt_settings = new encrypt__ScryptChacha20poly1305()

And passed as first parameter in call to SKY_encrypt_ScryptChacha20poly1305_Encrypt.

Fixed Sized Arrays

Parameters of fixed size array are wrapped in structures when called from .NET.

Given these types in Skycoin and this exported function:

  type PubKey [33]byte
  type SecKey [32]byte

  func GenerateDeterministicKeyPair(seed []byte) (PubKey, SecKey)

This is a way to use them to write assertions in .NET:

//Generates random seed
var data = new GoSlice();
var err = SKY_cipher_RandByte(32,data);

Assert.AreEqual(err,SKY_OK);

var pubkey = new cipher_PubKey();
var seckey = new cipher_SecKey();

err = SKY_cipher_GenerateDeterministicKeyPair(data, pubkey,seckey);

In the example above pubkey and seckey are objects of an structure type containing a field named data holding the corresponding instance of PubKey and SecKey. Something like:

  cipher_PubKey struct{
    data [33]byte;
  } cipher_PubKey;

  cipher_SecKey struct{
    data [32]byte;
  } ;
Other Slices

Other slices of base type different from byte are indeed wrapped inside classes. Let's see how to call the following function:

func GenerateDeterministicKeyPairs(seed []byte, n int) []SecKey

In C# this how it should be used to generate a deterministic sequence of pairs of public / private keys given a random seed:

//Generates random seed
var seed = new GoSlice();
var err = SKY_cipher_RandByte(32,seed);
var seckeys = new cipher__SecKeys();

err = SKY_cipher_GenerateDeterministicKeyPairs(seed, 2,seckeys);

for(int i=0;i<seckeys.count,i++){
  var pubkey = new cipher_PubKey();
  var seckey = new cipher_SecKey();
  seckeys.getAt(seckey,i);

  SKY_cipher_PubKeyFromSecKey(seckey, pubkey);
  err = SKY_cipher_PubKey_Verify(pubkey);
  Assert.AreEqual(err,SKY_OK);
}

Memory Management

Memory management is transparent to the user. Any object allocated inside the library is left to be managed by the .NET garbage collector.

SkyApi wrapper for Skycoin REST API

This wrapper is Auto generated by openapi-generator directly from Skycoin Api code for version v0.25.1.

For further details of usage of RestCsharp wrapper for Skycoin Api see Autogenerated documentation

Specific Node Address

For use a specific node of Skycoin, you just need to create a instance of ApiClient passing the node address:

var restSharpClient = new ApiClient("specific_node_address")

Then in restSharpClient you can use all methods related to Api Client.

Make Rules

The following make rules are available after git checkout of this repository. They all require Skycoin to be checked out as a git submodule of libskycoin .NET .

$ make help

configure                      Setup build environment
build-libc                     Build libskycoin static C client library
build-swig                     Generate csharp source code from SWIG interface definitions
build-libsky-shared            Build shared library including SWIG wrappers
install-deps-libsky            Install development dependencies for LibSkycoinNet
build-libsky                   Build LibSkycoinNet Assembly
build-skyapi                   Build SkyApi Assembly
build                          Build library
test-libsky                    Run LibSkycoinNet test suite
test-skyapi                    Run SkyApi test suite
test                           Run all tests

Development setup

It is highly recommended for developers to setup their environment using the available Docker images. Read the LibSkycoinNet Docker docs for further details.

The project has two branches: master and develop.

  • develop is the default branch and will always have the latest code. The submodule at gopath/src/github.com/skycoin/skycoin has to be in sync with skycoin/skycoin develop branch.
  • master will always be equal to the current stable release on the website, and should correspond with the latest release tag. The submodule at gopath/src/github.com/skycoin/skycoin has to be in sync with skycoin/skycoin master branch.

Separate stable development branches will be created to work on releases for supporting the most recent stable version of Skycoin. The name of these branches should be the Skycoin major and minor version numbers followed by dev suffix e.g. 0.25dev. These branches may be forked out of either master or develop branches, and the submodule at gopath/src/github.com/skycoin/skycoin has to be in sync with the corresponding tag of skycoin/skycoin official repository.

Stable development branches are created most of the time for the following reasons:

  • A Skycoin release increasing patch version number.
  • Enhanced support and bug fixes for a version of LibSkycoinNet compiled against an stable version of Skycoin
  • Backporting useful features added in develop.

Running tests

$ make test

Releases

Update the version

  1. If the master branch has commits that are not in develop (e.g. due to a hotfix applied to master), merge master into develop (and fix any build or test failures)
  2. Switch to a new release branch named release-X.Y.Z for preparing the release.
  3. Ensure that the submodule at gopath/src/github.com/skycoin/skycoin is in sync with respect to the corresponding tag in https://github.com/skycoin/skycoin repository.
  4. Update package version (LibskycoinNet/LibskycoinNet.csproj)
  5. Run make build to make sure that the code base is up to date
  6. Update CHANGELOG.md: move the "unreleased" changes to the version and add the date.
  7. Follow the steps in pre-release testing
  8. Make a PR merging the release branch into master
  9. Review the PR and merge it
  10. Update files in https://github.com/skycoin/repo-info/tree/master/repos/skycoin/remote for skycoin/skycoindev-dotnet Docker image, adding a new file for the new version and adjusting any configuration text that may have changed
  11. Tag the master branch with the version number. Version tags start with v, e.g. v0.20.0. Sign the tag. If you have your GPG key in github, creating a release on the Github website will automatically tag the release. It can be tagged from the command line with git tag -as v0.20.0 $COMMIT_ID, but Github will not recognize it as a "release".
  12. Release builds are created and uploaded by travis. To do it manually, checkout the master branch and follow the create release builds instructions.
  13. Checkout develop branch and bump package up to next dev version number.

Pre-release testing

Perform these actions before releasing:

make test

Creating release builds

Release builds should be created from master branch . After updating release version it is necessary to follow these steps

Requirements

Have installed the mono for the creation of the package.

https://www.mono-project.com/download/stable/

Building
msbuild /p:Configuration=Release LibskycoinNet.sln

Final results are placed in the LibskycoinNet/bin/Release/ folder.

libskyfiber-dotnet's People

Contributors

olemis avatar stdevalden avatar stdevmac avatar stdevyuniers avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

libskyfiber-dotnet's Issues

Tests for the .NET REST API wrappers

Expected Behavior

Same tests run for SKY_api_* functions shall be used for .NET API wrappers .

Actual Behavior

... see #37

Specifications

  • Version: 0.25.0
  • Platform: all
  • Subsystem: all exported API sets

Possible Solution

Reuse existing API test code, if any, and parameterize the invocation .

.NET API wrapper for the Skycoin node API

Expected Behavior

Access to the Skycoin node REST API implemented in .NET code or as a .NET assembly.

Actual Behavior

Right now this is only possible using code generated by SWIG , which requires memory handles

Specifications

  • Version: 0.25.0
  • Platform: all
  • Subsystem: all exported API sets

Possible Solution

Generate with Swagger (share more info, please) . Beware of CSRF .

  • Use Skycoin node Swagger spec to generate initial C# REST API client
  • Add make target to automate generation in ./build
  • Aforementioned target should copy / merge relevant files into source code tree
  • README explaining the process
  • Mention in CHANGELOG
  • Patch the result Swagger-gen REST client to support specifying node address
  • Update package metadata
  • Run basic Swagger tests in Travis
  • Unify testing code if multiple frameworks are used across source tree
  • Beware of CSRF auth

Update libskycoin submodule to 0.27.0

Feature description

Update the libskycoin submodule to 0.27.0

Actual Behavior

Submodule tracks skycoin/[email protected] .

Specifications

  • Version: 0.27.0
  • Platform: all
  • Subsystem: all

Possible Solution

Update the libskycoin submodule to 0.27.0

Feature request template

Expected Behavior

Feature request form pre-filled with default text and values

Actual Behavior

All issues initialized as bug requests

Update libskycoin submodule to 0.26.0

Feature description

Update the libskycoin submodule to 0.26.0

Actual Behavior

Submodule tracks skycoin/[email protected] .

Specifications

  • Version: 0.26.0
  • Platform: all
  • Subsystem: all

Possible Solution

Update the libskycoin submodule to 0.26.0

Travis deploy to NuGet and Chocolatey for git tags

Expected Behavior

At the end of the release process LibSkycoinNet binary packages should be uploaded to NuGet and Chocolatey . Source package should be uploaded onto github as well .

Actual Behavior

Manual release workflow

Specifications

  • Version: all
  • Platform: GNU/Linux , MacOS , Windows . Raspbian and ARMbian would be nice to have , but optional . If ARM releases are complicated this should be done in a separate issue for next release.
  • Frameworks : mono and dotnetcore should be supported .

Possible Solution

Read how to make Travis deploy onto Github Releases. Found no reference for integration neither with Chocolatey nor NuGet though .

[docker] Virtualize workspaces for developers of Skycoin .NET apps

Image name simelotech/skycoindev-dotnet and a single develop tag.

  • .NET CLI tools built FROM skycoin/skycoindev-cli:develop
  • .NET CLI tools and Docker built FROM skycoin/skycoindev-cli:dind
  • .NET tools and VS Code IDE built FROM skycoin/skycoindev-vscode:develop
  • .NET tools, Docker and VS Code IDE built FROM skycoin/skycoindev-vscode:dind

Add deploy for skyapi

Describe the solution you'd like
Deploy of skyapi library on release

Describe alternatives you've considered
Deploy to nuget packages of skyapi

Additional context
Only deploy on release

Test for wrapper for Skycoin REST API

Describe the solution you'd like
Re implement in dotnet test for Skycoin REST API using the wrapper

Describe alternatives you've considered
Use UnitTest

Build C library from skycoin/libskycoin

Expected Behavior

Since Skycoin 0.25.1 the C client library, SWIG, etc are developed in a separate repository (see skycoin/libskycoin#1) . LibSkycoinNet should use code in that repository .

Actual Behavior

Submodule tracks skycoin/[email protected] .

Specifications

  • Version: 0.25.0
  • Platform: GNU/Linux
  • Subsystem: all

Possible Solution

Add skycoin/libskycoin as submodule and update GOPATH accordingly in Makefile, for instance ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.