Skip to content

Commit

Permalink
Merge pull request #73 from richardschneider/ed25519-key
Browse files Browse the repository at this point in the history
test: a node with an ed25519 key
  • Loading branch information
richardschneider authored Apr 2, 2019
2 parents e6e85fe + 92db6f6 commit 4e72f2b
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 4 deletions.
9 changes: 6 additions & 3 deletions doc/articles/repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ or the [Repository Options](xref:Ipfs.Engine.RepositoryOptions).

## Creating

The repository will be automatically created if it does not already exist. At creation time
a cryptograhic key named `self` is created and is used to uniquely identify this node
in IPFS network.
The repository will be automatically created if it does not already exist.

At creation time
a [cryptograhic key](key.md) named `self` is created and is used to uniquely identify this node
in the IPFS network. The [keychain options](xref:Ipfs.Engine.Cryptography.KeyChainOptions) are used to control the type of key that
is generated; by default it is RSA with 2048 bits.

## Contents

Expand Down
2 changes: 1 addition & 1 deletion src/Cryptography/KeyChainOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class KeyChainOptions
/// The default key type, when generating a key.
/// </summary>
/// <value>
/// Defaults to "rsa".
/// "rsa", "ed25519" or "secp256k1". Defaults to "rsa".
/// </value>
public string DefaultKeyType { get; set; } = "rsa";

Expand Down
85 changes: 85 additions & 0 deletions test/Ed25519NodeTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;

namespace Ipfs.Engine
{
[TestClass]
public class Ed25519NodeTest
{
[TestMethod]
public async Task Can_Create()
{
var ed = await CreateNode();
try
{
Assert.IsNotNull(ed);
var node = await ed.LocalPeer;
Assert.IsNotNull(node);
}
finally
{
DeleteNode(ed);
}
}

[TestMethod]
public async Task CanConnect()
{
var ed = await CreateNode();
try
{
await ed.StartAsync();
var node = await ed.LocalPeer;
Assert.AreNotEqual(0, node.Addresses.Count());
var addr = node.Addresses.First();

var ipfs = TestFixture.Ipfs;
await ipfs.StartAsync();
try
{
await ipfs.Swarm.ConnectAsync(addr);
var peers = await ipfs.Swarm.PeersAsync();
Assert.IsTrue(peers.Any(p => p.Id == addr.PeerId));
await ipfs.Swarm.DisconnectAsync(addr);
}
finally
{
await ipfs.StopAsync();
}
}
finally
{
await ed.StopAsync();
DeleteNode(ed);
}
}

async Task<IpfsEngine> CreateNode()
{
const string passphrase = "this is not a secure pass phrase";
var ipfs = new IpfsEngine(passphrase.ToCharArray());
ipfs.Options.Repository.Folder = Path.Combine(Path.GetTempPath(), "ipfs-ed255129-test");
ipfs.Options.KeyChain.DefaultKeyType = "ed25519";
await ipfs.Config.SetAsync(
"Addresses.Swarm",
JToken.FromObject(new string[] { "/ip4/0.0.0.0/tcp/0" })
);
return ipfs;
}

void DeleteNode(IpfsEngine ipfs)
{
if (Directory.Exists(ipfs.Options.Repository.Folder))
{
Directory.Delete(ipfs.Options.Repository.Folder, true);
}
}

}
}

0 comments on commit 4e72f2b

Please sign in to comment.