-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Sol-Net/dev
Early release baseline
- Loading branch information
Showing
116 changed files
with
5,742 additions
and
711 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"); | ||
} | ||
} | ||
} |
Oops, something went wrong.