Skip to content

Commit

Permalink
Merge pull request #1 from Sol-Net/dev
Browse files Browse the repository at this point in the history
Early release baseline
  • Loading branch information
hoakbuilds committed May 28, 2021
2 parents e5758c4 + c80dc08 commit 9e50542
Show file tree
Hide file tree
Showing 116 changed files with 5,742 additions and 711 deletions.
74 changes: 65 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,76 @@
![solnet](docs/assets/solnet-horizontal.png)

# Solnet

Technical support, chat and collaboration at the [Solnet Discord]().

# What is Solnet?

Solnet is Solana's .NET integration library.

Solnet was developed targeting net 5.0 because we believe a modern decentralized platform deserves a modern technology framework to go along with it, although we are actively working on targeting earlier versions such as:

- netstandard 1.1
- netstandard 2.0
- netcore 2.1
- netcore 3.1
- net451
## Requirements
- net 5.0

## Dependencies
- NBitcoin
- Chaos.NaCl.Standard
- Portable.BouncyCastle

## Examples

The [Solnet.Examples](https://github.com/bmresearch/Solnet/src/Solnet.Examples/) project contains some code examples, but essentially we're trying very hard to
make it intuitive and easy to use the library.

### Initializing both wallets from Sollet and solana-keygen

```c#
// To initialize a wallet and have access to the same keys generated in solana-keygen
var wallet = new Wallet("mnemonic words ...", Wordlist.English, "passphrase");

// To initialize a wallet and have access to the same keys generated in sollet
var sollet = new Wallet("mnemonic words ...", Wordlist.English);
// Retrieve accounts by derivation path index
var account = sollet.GetAccount(10);

// Or initialize a mnemonic from NBitcoin before and use it
var mnemonic = new Mnemonic("mnemonic words ...");
var wallet = new Wallet(mnemonic);

```

### Sending a transaction

```c#
// Initialize the rpc client and a wallet
var rpcClient = new SolanaRpcClient("https://testnet.solana.com");
var wallet = new Wallet.Wallet();
// Get the source account
var fromAccount = wallet.GetAccount(0);
// Get the destination account
var toAccount = wallet.GetAccount(1);
// Get a recent block hash to include in the transaction
var blockHash = rpcClient.GetRecentBlockHash();

// Initialize a transaction builder and chain as many instructions as you want before building the message
var tx = new TransactionBuilder().
SetRecentBlockHash(blockHash.Result.Value.Blockhash).
AddInstruction(MemoProgram.NewMemo(fromAccount, "Hello from Sol.Net :)")).
AddInstruction(SystemProgram.Transfer(fromAccount.GetPublicKey, toAccount.GetPublicKey, 100000)).
Build(fromAccount);

var firstSig = rpcClient.SendTransaction(tx);
```


## Contribution

We encourage everyone to contribute, submit issues, PRs, discuss. Every kind of help is welcome.

## Contributors

* **Hugo** - *Maintainer* - [murlokito](https://github.com/murlokito)
* **Tiago** - *Maintainer* - [tiago](https://github.com/tiago18c)

See also the list of [contributors](https://github.com/bmresearch/Solnet/contributors) who participated in this project.

## License

This project is licensed under the MIT License - see the [LICENSE.md](https://github.com/bmresearch/Solnet/LICENSE.md) file for details
61 changes: 29 additions & 32 deletions Solnet.sln
Original file line number Diff line number Diff line change
@@ -1,59 +1,38 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Solnet.Web3", "src\Solnet.Web3\Solnet.Web3.csproj", "{9185CC62-0674-48B2-9FFC-09D4887E3BAA}"
# Visual Studio Version 16
VisualStudioVersion = 16.0.31129.286
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Solnet.Rpc", "src\Solnet.Rpc\Solnet.Rpc.csproj", "{FE8D270F-30AE-4818-AC7B-030591820419}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Solnet.Web3.Accounts", "src\Solnet.Web3.Accounts\Solnet.Web3.Accounts.csproj", "{750E6A53-38C2-4A54-A37F-0F76CC9616BB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Solnet.Models", "src\Solnet.Models\Solnet.Models.csproj", "{8B503BC5-F1C8-4F87-8C53-AD4D6CEFFCF4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Solnet.Rpc", "src\Solnet.Rpc\Solnet.Rpc.csproj", "{FE8D270F-30AE-4818-AC7B-030591820419}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Solnet.KeyStore", "src\Solnet.KeyStore\Solnet.KeyStore.csproj", "{BA5BFA52-8010-4438-BC87-153A34464CAA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Solnet.Accounts", "src\Solnet.Accounts\Solnet.Accounts.csproj", "{B1FB0091-A25A-4B6C-AAC6-68BB0409D2EE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Solnet.Wallet", "src\Solnet.Wallet\Solnet.Wallet.csproj", "{DA22B717-4FD7-4D08-A546-DFF3B21B7BAE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Solnet.Models", "src\Solnet.Models\Solnet.Models.csproj", "{8B503BC5-F1C8-4F87-8C53-AD4D6CEFFCF4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Solnet.Examples", "src\Solnet.Examples\Solnet.Examples.csproj", "{1198ED67-B1F1-4DE9-BDE8-AE6C96DA33A6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Solnet.Hex", "src\Solnet.Hex\Solnet.Hex.csproj", "{E1E63AAD-23DC-494B-9C8F-7912EB9784EA}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Solnet.Util", "src\Solnet.Util\Solnet.Util.csproj", "{5B8896C9-4B06-41C9-B0F9-05B9F6190CA5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Solnet.Signer", "src\Solnet.Signer\Solnet.Signer.csproj", "{48E0662C-A237-469E-B60A-FD472D92E012}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Solnet.Rpc.Test", "test\Solnet.Rpc.Test\Solnet.Rpc.Test.csproj", "{E907F659-7FDE-4B98-85CD-1FBC6B1656CD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Solnet.KeyStore", "src\Solnet.KeyStore\Solnet.KeyStore.csproj", "{BA5BFA52-8010-4438-BC87-153A34464CAA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Solnet.Wallet", "src\Solnet.Wallet\Solnet.Wallet.csproj", "{DA22B717-4FD7-4D08-A546-DFF3B21B7BAE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Solnet.Examples", "src\Solnet.Examples\Solnet.Examples.csproj", "{1198ED67-B1F1-4DE9-BDE8-AE6C96DA33A6}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Solnet.Programs", "src\Solnet.Programs\Solnet.Programs.csproj", "{45D7F47F-4807-4918-BD78-F9EB2863B5A2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9185CC62-0674-48B2-9FFC-09D4887E3BAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9185CC62-0674-48B2-9FFC-09D4887E3BAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9185CC62-0674-48B2-9FFC-09D4887E3BAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9185CC62-0674-48B2-9FFC-09D4887E3BAA}.Release|Any CPU.Build.0 = Release|Any CPU
{750E6A53-38C2-4A54-A37F-0F76CC9616BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{750E6A53-38C2-4A54-A37F-0F76CC9616BB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{750E6A53-38C2-4A54-A37F-0F76CC9616BB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{750E6A53-38C2-4A54-A37F-0F76CC9616BB}.Release|Any CPU.Build.0 = Release|Any CPU
{FE8D270F-30AE-4818-AC7B-030591820419}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FE8D270F-30AE-4818-AC7B-030591820419}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FE8D270F-30AE-4818-AC7B-030591820419}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FE8D270F-30AE-4818-AC7B-030591820419}.Release|Any CPU.Build.0 = Release|Any CPU
{B1FB0091-A25A-4B6C-AAC6-68BB0409D2EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B1FB0091-A25A-4B6C-AAC6-68BB0409D2EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B1FB0091-A25A-4B6C-AAC6-68BB0409D2EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B1FB0091-A25A-4B6C-AAC6-68BB0409D2EE}.Release|Any CPU.Build.0 = Release|Any CPU
{8B503BC5-F1C8-4F87-8C53-AD4D6CEFFCF4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8B503BC5-F1C8-4F87-8C53-AD4D6CEFFCF4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8B503BC5-F1C8-4F87-8C53-AD4D6CEFFCF4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8B503BC5-F1C8-4F87-8C53-AD4D6CEFFCF4}.Release|Any CPU.Build.0 = Release|Any CPU
{E1E63AAD-23DC-494B-9C8F-7912EB9784EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E1E63AAD-23DC-494B-9C8F-7912EB9784EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E1E63AAD-23DC-494B-9C8F-7912EB9784EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E1E63AAD-23DC-494B-9C8F-7912EB9784EA}.Release|Any CPU.Build.0 = Release|Any CPU
{48E0662C-A237-469E-B60A-FD472D92E012}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{48E0662C-A237-469E-B60A-FD472D92E012}.Debug|Any CPU.Build.0 = Debug|Any CPU
{48E0662C-A237-469E-B60A-FD472D92E012}.Release|Any CPU.ActiveCfg = Release|Any CPU
{48E0662C-A237-469E-B60A-FD472D92E012}.Release|Any CPU.Build.0 = Release|Any CPU
{BA5BFA52-8010-4438-BC87-153A34464CAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BA5BFA52-8010-4438-BC87-153A34464CAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BA5BFA52-8010-4438-BC87-153A34464CAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -66,5 +45,23 @@ Global
{1198ED67-B1F1-4DE9-BDE8-AE6C96DA33A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1198ED67-B1F1-4DE9-BDE8-AE6C96DA33A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1198ED67-B1F1-4DE9-BDE8-AE6C96DA33A6}.Release|Any CPU.Build.0 = Release|Any CPU
{5B8896C9-4B06-41C9-B0F9-05B9F6190CA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5B8896C9-4B06-41C9-B0F9-05B9F6190CA5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5B8896C9-4B06-41C9-B0F9-05B9F6190CA5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5B8896C9-4B06-41C9-B0F9-05B9F6190CA5}.Release|Any CPU.Build.0 = Release|Any CPU
{E907F659-7FDE-4B98-85CD-1FBC6B1656CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E907F659-7FDE-4B98-85CD-1FBC6B1656CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E907F659-7FDE-4B98-85CD-1FBC6B1656CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E907F659-7FDE-4B98-85CD-1FBC6B1656CD}.Release|Any CPU.Build.0 = Release|Any CPU
{45D7F47F-4807-4918-BD78-F9EB2863B5A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{45D7F47F-4807-4918-BD78-F9EB2863B5A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{45D7F47F-4807-4918-BD78-F9EB2863B5A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{45D7F47F-4807-4918-BD78-F9EB2863B5A2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BE3287F3-8CBC-4793-8CC9-A1AE4B8266ED}
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions Solnet.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=Blockhash/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Lamports/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Solana/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Solnet/@EntryIndexedValue">True</s:Boolean>
</wpf:ResourceDictionary>
73 changes: 0 additions & 73 deletions src/Solnet.Accounts/Account.cs

This file was deleted.

109 changes: 109 additions & 0 deletions src/Solnet.Examples/PrefixedKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using System;
using System.Text;
using System.Threading.Tasks;
using NBitcoin;
using NBitcoin.DataEncoders;
using Org.BouncyCastle.Crypto.Digests;
using Solnet.Wallet;

namespace Solnet.Examples
{
public class PrefixedKey
{
public class Generator
{
public readonly object indexLock = new object();
public readonly object stopLock = new object();

public long index;
public bool stop;

public Mnemonic _mnemonic;
public Wallet.Wallet _wallet;
public string _passphrase;

public Generator(Mnemonic mnemonic, Wallet.Wallet wallet, string passphrase)
{
_mnemonic = mnemonic;
_wallet = wallet;
_passphrase = passphrase;

}

public long Index()
{
lock (indexLock)
{
return index;
}
}

public Account Generate()
{
lock (stopLock)
{
if (stop) return null;
}
lock (indexLock)
{
return _wallet.GetAccount((int)++index);
}
}
}

/// <summary>
/// Performs sha256 and ripemd160 for bech32 address.
/// </summary>
/// <param name="publicKey"></param>
/// <returns></returns>
public static byte[] Hashed(byte[] publicKey)
{
var sha256 = new Sha256Digest();
sha256.BlockUpdate(publicKey, 0, publicKey.Length);
byte[] shaHash = new byte[sha256.GetDigestSize()];
sha256.DoFinal (shaHash, 0);

var ripe160 = new RipeMD160Digest();
ripe160.BlockUpdate(shaHash, 0, shaHash.Length);
byte[] ripHash = new byte[ripe160.GetDigestSize()];
ripe160.DoFinal(ripHash, 0);
return ripHash;
}

static async Task Prefixer(string[] args)
{
var b64Enc = new Base64Encoder();
var passphrase = Hashed(Encoding.ASCII.GetBytes("hoaktrades"));
var encodedPassphrase = b64Enc.EncodeData(passphrase);
var mnemonic = new Mnemonic(Wordlist.English, WordCount.TwentyFour);
var wallet = new Wallet.Wallet(mnemonic);
var generator = new Generator(mnemonic, wallet, encodedPassphrase);
Console.WriteLine($"Mnemonic: {mnemonic} Passphrase: {encodedPassphrase}");

var tasks = new Task[24];

for (int i = 0; i < tasks.Length; i++)
{
tasks[i] = Task.Run(() => Run(generator));
}
await Task.WhenAll(tasks);
Console.WriteLine($"Mnemonic: {mnemonic} Passphrase: {encodedPassphrase}");
}

static void Run(Generator generator)
{
Account acc = generator.Generate();

while (acc != null && !acc.GetPublicKey.StartsWith("oak"))
{
acc = generator.Generate();
Console.WriteLine($"Account: {generator.Index()} PrivateKey: {acc.GetPrivateKey} PublicKey {acc.GetPublicKey}");
}
lock (generator.stopLock)
{
generator.stop = true;
}
Console.WriteLine($"Account: {generator.Index()} PrivateKey: {acc.GetPrivateKey} PublicKey {acc.GetPublicKey}");
}
}
}
Loading

0 comments on commit 9e50542

Please sign in to comment.