Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/actions/setup-dotn…
Browse files Browse the repository at this point in the history
…et-4
  • Loading branch information
Arlodotexe authored Jan 24, 2024
2 parents 38a832d + f7cca48 commit 7b41985
Show file tree
Hide file tree
Showing 7 changed files with 296 additions and 100 deletions.
27 changes: 11 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ The core objects and interfaces of the [IPFS](https://github.com/ipfs/ipfs) (Int

The interplanetary file system is the permanent web. It is a new hypermedia distribution protocol, addressed by content and identities. IPFS enables the creation of completely distributed applications. It aims to make the web faster, safer, and more open.

It supports .NET Standard 2.0.
This library supports .NET Standard 2.0.

### 🚧 NOTICE 🚧
We've only [just](https://github.com/richardschneider/net-ipfs-http-client/issues/72) moved into the shipyard, reviving a project that has been abandoned since 2019.
## Install

**We're actively working to make it usable again.**
Published releases are available on [NuGet](https://www.nuget.org/packages/IpfsShipyard.Ipfs.Core). To install, run the following command in the [Package Manager Console](https://docs.nuget.org/docs/start-here/using-the-package-manager-console).

PM> Install-Package IpfsShipyard.Ipfs.Core

Or using [dotnet](https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet)

> dotnet add package IpfsShipyard.Ipfs.Core

## Major objects

Expand All @@ -38,22 +43,12 @@ The [DagNode](https://richardschneider.github.io/net-ipfs-core/api/Ipfs.DagNode.
the objects themselves, and that every object contains a secure
representation of its children.

Every Merkle is a directed acyclic graph (DAG) because each node is accessed via its name (the hash of `DagNode`). Each branch of Merkle is the hash of its local content (data and links); naming children by their hash instead of their full contents. So after creation there is no way to edit a DagNode. This prevents cycles (assuming there are no hash collisions) since one can not link the first created node to the last note to create the last reference.

## Base58

Most binary data (objects) in IPFS is represented as a [Base-58](https://en.wikipedia.org/wiki/Base58) string; the BitCoin alphabet is used.

> Base58 is a group of binary-to-text encoding schemes used to represent large integers as alphanumeric text. It is similar to Base64 but has been modified to avoid both non-alphanumeric characters and letters which might look ambiguous when printed. It is therefore designed for human users who manually enter the data, copying from some visual source, but also allows easy copy and paste because a double-click will usually select the whole string.
Every Merkle is a directed acyclic graph (DAG) because each node is accessed via its name (the hash of `DagNode`). Each branch of Merkle is the hash of its local content (data and links); naming children by their hash instead of their full contents. So after creation there is no way to edit a DagNode. This prevents cycles (assuming there are no hash collisions) since one can not link the first created node to the last note to create the last reference.

## Related Projects

- [IPFS DSL](https://github.com/cloveekprojeqt/ipfs-dsl) - A declarative embedded language for building compositional programs and protocols over the InterPlanetary File System.
- [IPFS HTTP Client](https://github.com/ipfs-shipyard/net-ipfs-http-client) - A .Net client library for the IPFS HTTP API.
- [IPFS HTTP Gateway](https://github.com/richardschneider/net-ipfs-http-gateway) - Serves IPFS files/directories via HTTP.
- [IPFS Engine](https://github.com/richardschneider/net-ipfs-engine) - Implements the Core API.
- [Peer Talk](https://github.com/richardschneider/peer-talk) - Peer to peer communication.

## License
The IPFS Core library is licensed under the [MIT](http://www.opensource.org/licenses/mit-license.php "Read more about the MIT license form") license. Refer to the [LICENSE](https://github.com/richardschneider/net-ipfs-core/blob/master/LICENSE) file for more information.
The IPFS Core library is licensed under the [MIT](http://www.opensource.org/licenses/mit-license.php "Read more about the MIT license form") license. Refer to the [LICENSE](LICENSE) file for more information.

156 changes: 75 additions & 81 deletions src/Base32.cs
Original file line number Diff line number Diff line change
@@ -1,91 +1,85 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Ipfs;

namespace Ipfs
/// <summary>
/// A codec for Base-32.
/// </summary>
/// <remarks>
/// <para>
/// A codec for Base-32, <see cref="Encode"/> and <see cref="Decode"/>. Adds the extension method <see cref="ToBase32"/>
/// to encode a byte array and <see cref="FromBase32"/> to decode a Base-32 string.
/// </para>
/// <para>
/// <see cref="Encode"/> and <see cref="ToBase32"/> produce the lower case form of
/// <see href="https://tools.ietf.org/html/rfc4648"/> with no padding.
/// <see cref="Decode"/> and <see cref="FromBase32"/> are case-insensitive and
/// allow optional padding.
/// </para>
/// <para>
/// A thin wrapper around <see href="https://github.com/ssg/SimpleBase"/>.
/// </para>
/// </remarks>
public static class Base32
{
/// <summary>
/// A codec for Base-32.
/// Converts an array of 8-bit unsigned integers to its equivalent string representation that is
/// encoded with base-32 characters.
/// </summary>s
/// <param name="input">
/// An array of 8-bit unsigned integers.
/// </param>
/// <returns>
/// The string representation, in base 32, of the contents of <paramref name="input"/>.
/// </returns>
public static string Encode(byte[] input)
{
return SimpleBase.Base32.Rfc4648.Encode(input, false).ToLowerInvariant();
}

/// <summary>
/// Converts an array of 8-bit unsigned integers to its equivalent string representation that is
/// encoded with base-32 digits.
/// </summary>
/// <param name="bytes">
/// An array of 8-bit unsigned integers.
/// </param>
/// <returns>
/// The string representation, in base 32, of the contents of <paramref name="bytes"/>.
/// </returns>
public static string ToBase32(this byte[] bytes)
{
return Encode(bytes);
}

/// <summary>
/// Converts the specified <see cref="string"/>, which encodes binary data as base 32 digits,
/// to an equivalent 8-bit unsigned integer array.
/// </summary>
/// <param name="input">
/// The base 32 string to convert.
/// </param>
/// <returns>
/// An array of 8-bit unsigned integers that is equivalent to <paramref name="input"/>.
/// </returns>
/// <remarks>
/// <para>
/// A codec for Base-32, <see cref="Encode"/> and <see cref="Decode"/>. Adds the extension method <see cref="ToBase32"/>
/// to encode a byte array and <see cref="FromBase32"/> to decode a Base-32 string.
/// </para>
/// <para>
/// <see cref="Encode"/> and <see cref="ToBase32"/> produce the lower case form of
/// <see href="https://tools.ietf.org/html/rfc4648"/> with no padding.
/// <see cref="Decode"/> and <see cref="FromBase32"/> are case-insensitive and
/// allow optional padding.
/// </para>
/// <para>
/// A thin wrapper around <see href="https://github.com/ssg/SimpleBase"/>.
/// </para>
/// <paramref name="input"/> is case-insensitive and allows padding.
/// </remarks>
public static class Base32
public static byte[] Decode(string input)
{
/// <summary>
/// Converts an array of 8-bit unsigned integers to its equivalent string representation that is
/// encoded with base-32 characters.
/// </summary>s
/// <param name="input">
/// An array of 8-bit unsigned integers.
/// </param>
/// <returns>
/// The string representation, in base 32, of the contents of <paramref name="input"/>.
/// </returns>
public static string Encode(byte[] input)
{
return SimpleBase.Base32.Rfc4648.Encode(input, false).ToLowerInvariant();
}

/// <summary>
/// Converts an array of 8-bit unsigned integers to its equivalent string representation that is
/// encoded with base-32 digits.
/// </summary>
/// <param name="bytes">
/// An array of 8-bit unsigned integers.
/// </param>
/// <returns>
/// The string representation, in base 32, of the contents of <paramref name="bytes"/>.
/// </returns>
public static string ToBase32(this byte[] bytes)
{
return Encode(bytes);
}

/// <summary>
/// Converts the specified <see cref="string"/>, which encodes binary data as base 32 digits,
/// to an equivalent 8-bit unsigned integer array.
/// </summary>
/// <param name="input">
/// The base 32 string to convert.
/// </param>
/// <returns>
/// An array of 8-bit unsigned integers that is equivalent to <paramref name="input"/>.
/// </returns>
/// <remarks>
/// <paramref name="input"/> is case-insensitive and allows padding.
/// </remarks>
public static byte[] Decode(string input)
{
return SimpleBase.Base32.Rfc4648.Decode(input);
}
return SimpleBase.Base32.Rfc4648.Decode(input);
}

/// <summary>
/// Converts the specified <see cref="string"/>, which encodes binary data as base 32 digits,
/// to an equivalent 8-bit unsigned integer array.
/// </summary>
/// <param name="s">
/// The base 32 string to convert; case-insensitive and allows padding.
/// </param>
/// <returns>
/// An array of 8-bit unsigned integers that is equivalent to <paramref name="s"/>.
/// </returns>
public static byte[] FromBase32(this string s)
{
return Decode(s);
}
/// <summary>
/// Converts the specified <see cref="string"/>, which encodes binary data as base 32 digits,
/// to an equivalent 8-bit unsigned integer array.
/// </summary>
/// <param name="s">
/// The base 32 string to convert; case-insensitive and allows padding.
/// </param>
/// <returns>
/// An array of 8-bit unsigned integers that is equivalent to <paramref name="s"/>.
/// </returns>
public static byte[] FromBase32(this string s)
{
return Decode(s);
}
}
Loading

0 comments on commit 7b41985

Please sign in to comment.