Git Product home page Git Product logo

ledger-dotnet-api's Introduction

Ledger Wallet Client API

NuGet

The is a .NET library to build application relying on the ledger Nano S.

  • Use the LedgerClient class for the Ledger Bitcoin App.
  • Use the U2FClient class for the U2F Ledger App.
  • Use a custom transport protocol to talk to your ledger (Example: having a HTTP proxy to talk to a remote ledger connected to your server)
  • You can easily build your own client for your custom App.
  • Support Segwit

Support only Windows for the time being. Supporting other plateform is theorically possible if you can compile hidapi library by yourself.

How to use ?

  1. Reference the nuget package in your project.
  2. Plug your ledger
  3. Open Bitcoin app

Then you can easily sign:

var ledger = LedgerClient.GetHIDLedgers().First();

var walletPubKey = ledger.GetWalletPubKey(new KeyPath("1'/0"));
var address1 = walletPubKey.Address.ScriptPubKey;
var walletPubKey2 = ledger.GetWalletPubKey(new KeyPath("1'/0"));
var address2 =walletPubKey2.Address.ScriptPubKey;

var changeAddress = (BitcoinAddress)ledger.GetWalletPubKey(new KeyPath("1'/1")).Address;

Transaction funding = new Transaction();
funding.AddInput(Network.Main.GetGenesis().Transactions[0].Inputs[0]);
funding.Outputs.Add(new TxOut(Money.Coins(1.1m), address1));
funding.Outputs.Add(new TxOut(Money.Coins(1.0m), address1));
funding.Outputs.Add(new TxOut(Money.Coins(1.2m), address2));

var coins = funding.Outputs.AsCoins();

var spending = new Transaction();
spending.LockTime = 1;
spending.Inputs.AddRange(coins.Select(o => new TxIn(o.Outpoint, Script.Empty)));
spending.Inputs[0].Sequence = 1;
spending.Outputs.Add(new TxOut(Money.Coins(0.5m), BitcoinAddress.Create("15sYbVpRh6dyWycZMwPdxJWD4xbfxReeHe")));
spending.Outputs.Add(new TxOut(Money.Coins(0.8m), changeAddress));
spending.Outputs.Add(new TxOut(Money.Zero, TxNullDataTemplate.Instance.GenerateScriptPubKey(new byte[] { 1, 2 })));


var requests = new SignatureRequest[]{
	new SignatureRequest()
	{
		InputCoin = new Coin(funding, 0),
		InputTransaction = funding,
		KeyPath = new KeyPath("1'/0")
	},
	new SignatureRequest()
	{
		InputCoin = new Coin(funding, 1),
		InputTransaction = funding,
		KeyPath = new KeyPath("1'/0")
	},
	new SignatureRequest()
	{
		InputCoin = new Coin(funding, 2),
		InputTransaction = funding,
		KeyPath = new KeyPath("1'/0")
	},
};

//should show 0.5 and 2.0 btc in fee
var signed = ledger.SignTransaction(requests, spending, new KeyPath("1'/1"));
Console.WriteLine(signed);
foreach(var req in requests)
{
    Console.WriteLine(req.Signature);
}

You can check the tests NanoSTests and U2FTests for additional informations.

ledger-dotnet-api's People

Contributors

nicolasdorier avatar danielcrenna avatar mbalous avatar

Watchers

James Cloos avatar  avatar

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.