Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/farukterzioglu/hdwallet

A generic HD wallet for Elliptic Curve (Secp256k1) and Edwards-curve (Ed25519) based crypto currencies like Bitcoin, Ethereum, Cosmos, Tezos, Tron, Cardano, Polkadot, Avalanche, FileCoin and more.
https://github.com/farukterzioglu/hdwallet

avalanche bip32 bitcoin cardano cosmos crypto-currency ed25519 filecoin hd-wallet polkadot secp256k1 tezos tron

Last synced: 3 days ago
JSON representation

A generic HD wallet for Elliptic Curve (Secp256k1) and Edwards-curve (Ed25519) based crypto currencies like Bitcoin, Ethereum, Cosmos, Tezos, Tron, Cardano, Polkadot, Avalanche, FileCoin and more.

Awesome Lists containing this project

README

        

[![NuGet](https://img.shields.io/nuget/v/HDWallet.Secp256k1)](https://www.nuget.org/packages/HDWallet.Secp256k1/)
[![Build status](https://ci.appveyor.com/api/projects/status/20y31c79trpa6gim?svg=true)](https://ci.appveyor.com/project/farukterzioglu/hdwallet)

## HD Wallet

A generic HD wallet for Elliptic Curves (Secp256k1/Secp256r1) and Edwards-curve (Ed25519) based crypto currencies.

#### Supported blockchains

- Avalanche
- Bitcoin
- Cardano
- Ethereum
- FileCoin
- Neo3
- Polkadot
- Solana
- Stacks
- Terra
- Tezos
- Tron
- Bitcoin-like (Litecoin, Dash, Doge, ...) (WIP)

HD wallets can be generated from mnemonic (w/ or w/o passphrase) or from extended private key (xprv) and non-hd wallets can be generated directly from private key.

HD wallets can derive sub accounts, and from that accounts external (deposit) wallets or internal (change) wallets can be derived. Using generated wallets, addresses can be retrived by implementing address generators for related crypto currency.

### SDK (.Net Core)
An SDK for wallet creation in a hierarchical and deterministic way. From one mnemonic, multiple wallets can be created for multiple blockchains. You don't need to store private keys for multiple crypto addresses. They can be re-created deterministically.
.Net developers can use this SDK to create HD wallet within their programs. This SDK doesn't store secrets or manage wallet. Mnemonic (or seed/private key) need to be given for wallet creation.
Also regular wallet can be created from private keys.

### SDK for new blockchains (.Net Core)
By using HDWallet.Secp256k1 project, any Elliptic Curve (Secp256k1) based crypto currency wallet can be generated by defining the purpose (e.g. BIP44) and the coin type (e.g. 195 for Tron).
HDWallet.Tron project is already ready to go HD wallet for Tron (TRX) which uses HDWallet.Secp256k1 project.

By using HDWallet.Ed25519 project, any Edwards-curve (Ed25519) based crypto currency wallet can be generated by defining purpose (e.g. BIP44) and coin type (e.g. 1852 for Cardano).

### API
An API can be hosted as Docker container or run as .Net Core app and will receive requests for address generation. Generated addresses (or private keys) won't be stored and will be re-generated when ever queried.

### Sign server (WIP)
If activated within config, a sign server with receive messages to be signed and in reponse, signature and public key that signed the message will be returned.

## How To
### How to use the SDK
Sample for generating an HD Wallet for Bitcoin (purpose: BIP84, coin type: 0) from mnemonic and getting the first account's first deposit wallet;
```csharp
IHDWallet bitcoinHDWallet = new BitcoinHDWallet("conduct stadium ask orange vast impose depend assume income sail chunk tomorrow life grape dutch", "");
var depositWallet0 = bitcoinHDWallet.GetAccount(0).GetExternalWallet(0);
var address = depositWallet0.Address;
```

Sample for generating HD Wallet (m/44'/0'/0') from extended private key;
```csharp
var accountExtendedPrivateKey = "xprv9xyvwx1jBEBKwjZtXYogBwDyfXTyTa3Af6urV2dU843CyBxLu9J5GLQL4vMWvaW4q3skqAtarUvdGmBoWQZnU2RBLnmJdCM4FnbMa72xWNy";
IAccount accountWallet = new Account(accountExtendedPrivateKey);

var depositWallet0 = accountWallet.GetExternalWallet(0);
```

### How to use the API
#### For multiple accounts
```bash
curl 'https://localhost:5001/bitcoin/0/external/0'
curl 'https://localhost:5001/bitcoin/0/external/1'
curl 'https://localhost:5001/bitcoin/0/internal/0'
curl 'https://localhost:5001/bitcoin/0/internal/1'
```

#### For single account
```bash
curl 'https://localhost:5001/bitcoin/account/external/0'
curl 'https://localhost:5001/bitcoin/account/internal/0'
```

#### Signing (WIP)
```bash
curl -X POST 'https://localhost:8080/api/v1/tron/account/0/address/0/sign' --header 'Content-Type: application/json' --data-raw '{
"message":"MESSAGE-TO-SIGN"
}'

{
"signature" : "[SIGNATURE]",
"publickey" : "[PUBLICKEY]"
}
```

### How to Run
With Docker [WIP]
```bash
➜ ~ docker run -e mnemonic="conduct stadium ask orange vast impose depend assume income sail chunk tomorrow life grape dutch" -e passphrase=P@55PHR@S3 -p 8080:80 hdwallet-api

➜ ~ docker run -e accounthdkey=xprv9xyvwx1jBEBKwjZtXYogBwDyfXTyTa3Af6urV2dU843CyBxLu9J5GLQL4vMWvaW4q3skqAtarUvdGmBoWQZnU2RBLnmJdCM4FnbMa72xWNy -p 8080:80 hdwallet-api
```

From terminal
```bash
➜ ~ dotnet hdwallet-api.dll
```

### Authentication
Cookie based [WIP]
Cookie based authentication activated by default. As the application starts, a cookie file created at `~/.hdwallet/.cookie` (can be configured w/ `--cookiefile` flag). Api user can authenticate with Basic Authentication using credentials in cookie file.

If one wants to activate sign server feature, a flag is needed as `--signserver`

### Configuration
#### from appSettings.json
```json
{
"mnemonic" : "conduct stadium ask orange vast impose depend assume income sail chunk tomorrow life grape dutch",
"passphrase" : "P@55PHR@S3"
}

{
"accounthdkey" : "xprv9xyvwx1jBEBKwjZtXYogBwDyfXTyTa3Af6urV2dU843CyBxLu9J5GLQL4vMWvaW4q3skqAtarUvdGmBoWQZnU2RBLnmJdCM4FnbMa72xWNy"
}
```

#### from Environment
```bash
➜ ~ export MNEMONIC="conduct stadium ask orange vast impose depend assume income sail chunk tomorrow life grape dutch"
➜ ~ export PASSPHRASE=P@55PHR@S3
➜ ~ export ACCOUNTHDKEY=xprv9xyvwx1jBEBKwjZtXYogBwDyfXTyTa3Af6urV2dU843CyBxLu9J5GLQL4vMWvaW4q3skqAtarUvdGmBoWQZnU2RBLnmJdCM4FnbMa72xWNy

➜ ~ dotnet hdwallet-api.dll
```
#### from parameters
```bash
➜ ~ dotnet hdwallet-api.dll --mnemonic "conduct stadium ask orange vast impose depend assume income sail chunk tomorrow life grape dutch" --passphrase P@55PHR@S3

➜ ~ dotnet hdwallet-api.dll --accounthdkey xprv9xyvwx1jBEBKwjZtXYogBwDyfXTyTa3Af6urV2dU843CyBxLu9J5GLQL4vMWvaW4q3skqAtarUvdGmBoWQZnU2RBLnmJdCM4FnbMa72xWNy
```

Sample for signing messages with generated wallets;
```csharp
...
var signature = depositWallet0.Sign(messageBytes);
```

### Build the api
```bash
docker build -f src/HDWallet.Api/Dockerfile -t hdwallet-api .
```