Xecrets.Slip39.Extensions.md

May 26, 2026 · View on GitHub

Xecrets.Slip39

Xecrets.Slip39

Extensions Class

A set of useful extensions.

public static class Extensions

Inheritance System.Object → Extensions

Methods

Extensions.ArrayConcat(this T, T[]) Method

A convenience method to contatenate a first element with an array.

public static T[] ArrayConcat<T>(this T first, T[] second);

Type parameters

T

The type of the elements.

Parameters

first T

The first element.

second T[]

The second array.

Returns

T[]
A third array consisting of the concatenated result.

Extensions.ArrayConcat(this T[], T[]) Method

Contatenate two arrays.

public static T[] ArrayConcat<T>(this T[] first, T[] second);

Type parameters

T

The type of the elements.

Parameters

first T[]

The first array.

second T[]

The second array.

Returns

T[]
A third array consisting of the concatenated result.

Extensions.CombineShares(this IShamirsSecretSharing, Share[]) Method

Convenience method to recover a master secret from a set of shares, without a password.

public static Xecrets.Slip39.GroupedShares CombineShares(this Xecrets.Slip39.IShamirsSecretSharing sss, Xecrets.Slip39.Share[] shares);

Parameters

sss IShamirsSecretSharing

The IShamirsSecretSharing instance.

shares Share[]

The shares to to recover from.

Returns

GroupedShares
The recovered master secret.

Extensions.FromBip39(this string) Method

Convert a bip 39 mnemonic string master secret to a byte array. See https://bips.dev/39/ .

public static byte[] FromBip39(this string mnemonic);

Parameters

mnemonic System.String

The list of mnemonic words.

Returns

System.Byte[]
The converted bytes.

Extensions.FromHex(this string) Method

Convert a hex string to a byte array.

public static byte[] FromHex(this string hex);

Parameters

hex System.String

The string to convert.

Returns

System.Byte[]
The converted bytes.

Extensions.FromUrlSafeBase64(this string) Method

Convert a URL-safe base64 string to a byte array.

public static byte[] FromUrlSafeBase64(this string base64);

Parameters

base64 System.String

The string to convert.

Returns

System.Byte[]
The converted bytes.

Extensions.GenerateShares(this IShamirsSecretSharing, int, int, byte[]) Method

Convenience method to generate shares for the simple case of a single group of shares with a single threshold, and no encryption.

public static Xecrets.Slip39.Share[] GenerateShares(this Xecrets.Slip39.IShamirsSecretSharing sss, int memberThreshold, int memberCount, byte[] masterSecret);

Parameters

sss IShamirsSecretSharing

The IShamirsSecretSharing instance.

memberThreshold System.Int32

The member threshold.

memberCount System.Int32

The total number of members.

masterSecret System.Byte[]

The master secret to share.

Returns

Share[]
The set of shares, of which memberThreshold are required to recover the secret.

Extensions.GenerateShares(this IShamirsSecretSharing, int, int, string) Method

Convenience method to generate shares for the simple case of a single group of shares with a single threshold, and no encryption.

public static Xecrets.Slip39.Share[] GenerateShares(this Xecrets.Slip39.IShamirsSecretSharing sss, int memberThreshold, int memberCount, string masterSecret);

Parameters

sss IShamirsSecretSharing

The IShamirsSecretSharing instance.

memberThreshold System.Int32

The member threshold.

memberCount System.Int32

The total number of members.

masterSecret System.String

The master secret to share as a string.

Returns

Share[]
The set of shares, of which memberThreshold are required to recover the secret.

Remarks

The master secret is encoded as a System.Byte[] with UTF-8 encoded bytes, and if required padded with 0xff to fulfil the requirements. When recovering the secret, any trailing 0xff bytes thus need to be trimmed before producing the original master secret string, .

Extensions.GenerateShares(this IShamirsSecretSharing, int, int, string, StringEncoding) Method

Convenience method to generate shares for the simple case of a single group of shares with a single threshold, and no encryption.

public static Xecrets.Slip39.Share[] GenerateShares(this Xecrets.Slip39.IShamirsSecretSharing sss, int memberThreshold, int memberCount, string masterSecret, Xecrets.Slip39.StringEncoding encoding);

Parameters

sss IShamirsSecretSharing

The IShamirsSecretSharing instance.

memberThreshold System.Int32

The member threshold.

memberCount System.Int32

The total number of members.

masterSecret System.String

The master secret to share as a string.

encoding StringEncoding

The type of StringEncoding of the string master secret.

Returns

Share[]
The set of shares, of which memberThreshold are required to recover the secret.

Remarks

The master secret is encoded as a System.Byte[] of UTF-8 encoded bytes, and if required padded with 0xff to fulfil the requirements. When recovering the secret, any trailing 0xff bytes thus need to be trimmed before producing the original master secret string, .

Extensions.ToBip39(this byte[]) Method

Convert a master secret byte array to a BIP-39 mnemonic string. See https://bips.dev/39/ .

public static string ToBip39(this byte[] entropy);

Parameters

entropy System.Byte[]

The bytes to convert.

Returns

System.String
The BIP 39 mnemonic string.

Extensions.ToHex(this byte[]) Method

Convert a byte array to a hex string.

public static string ToHex(this byte[] bytes);

Parameters

bytes System.Byte[]

The bytes to convert.

Returns

System.String
The hex string.

Extensions.ToSecretBytes(this string, StringEncoding) Method

Take a master secret string, and using the specified StringEncoding convert it to a byte array.

public static byte[] ToSecretBytes(this string masterSecret, Xecrets.Slip39.StringEncoding stringEncoding);

Parameters

masterSecret System.String

The string representation of the master secret.

stringEncoding StringEncoding

How the string is encoded and should be interpreted.

Returns

System.Byte[]
The raw byte[] representation of the master secret.

Exceptions

System.InvalidOperationException
If an unknown encoding is specified.

Extensions.ToSecretString(this byte[]) Method

Convert a recovered binary master secret to a UTF-8 encoded string, assuming it has been padded with 0xFF bytes. If it can't be interpreted as a valid UTF-8 string, it will be converted to a BIP-39 mnemonic

public static string ToSecretString(this byte[] masterSecret);

Parameters

masterSecret System.Byte[]

The binary secret.

Returns

System.String
The original unpadded string, or a BIP-39 mnemonic.

Extensions.ToUrlSafeBase64(this byte[]) Method

Convert a byte array to a URL-safe base64 string.

public static string ToUrlSafeBase64(this byte[] bytes);

Parameters

bytes System.Byte[]

The bytes to convert.

Returns

System.String
The URL-safe base64 string.

Extensions.TryParse(this string, Share) Method

Try to parse a string into a Share instance.

public static bool TryParse(this string value, out Xecrets.Slip39.Share share);

Parameters

value System.String

The string value to try to parse.

share Share

The resulting Share if successful.

Returns

System.Boolean
True if the parse was successful.