Skip to content

Commit

Permalink
Merge pull request #89 from DiscreetNetwork/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
BrandonKoerner authored Feb 24, 2024
2 parents bfe8fcf + 58d1a3e commit 9214452
Show file tree
Hide file tree
Showing 219 changed files with 12,757 additions and 12,617 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/staging-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:

- name: Publish [WIN-x64]
run: |
dotnet publish --configuration Release --runtime win-x64 --framework net6.0 --self-contained true -p:ReadyToRun=true -p:Version=${{ steps.versionResponse.outputs.response }}
dotnet publish --configuration Release --runtime win-x64 --framework net6.0 -p:ReadyToRun=true -p:Version=${{ steps.versionResponse.outputs.response }}
if: ${{ github.event.pull_request.merged == true }}

- name: Install zip
Expand All @@ -101,7 +101,7 @@ jobs:

- name: Publish [LINUX-x64]
run: |
dotnet publish --configuration Release --runtime linux-x64 --framework net6.0 --self-contained true -p:Version=${{ steps.versionResponse.outputs.response }}
dotnet publish --configuration Release --runtime linux-x64 --framework net6.0 -p:Version=${{ steps.versionResponse.outputs.response }}
if: ${{ github.event.pull_request.merged == true }}

- name: Tar bz2 [LINUX-x64]
Expand Down
10 changes: 10 additions & 0 deletions Discreet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 17.1.32210.238
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discreet", "Discreet\Discreet.csproj", "{3C12BD93-4A6F-4E62-A47E-91A8ED8AD5B4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiscreetUnit", "DiscreetUnit\DiscreetUnit.csproj", "{A44E4EF6-77AF-4922-B600-70E707BA9ADB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +23,14 @@ Global
{3C12BD93-4A6F-4E62-A47E-91A8ED8AD5B4}.Release|Any CPU.Build.0 = Release|Any CPU
{3C12BD93-4A6F-4E62-A47E-91A8ED8AD5B4}.Release|x64.ActiveCfg = Release|x64
{3C12BD93-4A6F-4E62-A47E-91A8ED8AD5B4}.Release|x64.Build.0 = Release|x64
{A44E4EF6-77AF-4922-B600-70E707BA9ADB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A44E4EF6-77AF-4922-B600-70E707BA9ADB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A44E4EF6-77AF-4922-B600-70E707BA9ADB}.Debug|x64.ActiveCfg = Debug|Any CPU
{A44E4EF6-77AF-4922-B600-70E707BA9ADB}.Debug|x64.Build.0 = Debug|Any CPU
{A44E4EF6-77AF-4922-B600-70E707BA9ADB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A44E4EF6-77AF-4922-B600-70E707BA9ADB}.Release|Any CPU.Build.0 = Release|Any CPU
{A44E4EF6-77AF-4922-B600-70E707BA9ADB}.Release|x64.ActiveCfg = Release|Any CPU
{A44E4EF6-77AF-4922-B600-70E707BA9ADB}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion Discreet/Cipher/Bulletproof.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public static bool Verify(Bulletproof bp)
return rv;
}

public Bulletproof(Coin.Bulletproof bp, Key[] comms)
public Bulletproof(Coin.Models.Bulletproof bp, Key[] comms)
{
A = bp.A;
S = bp.S;
Expand Down
2 changes: 1 addition & 1 deletion Discreet/Cipher/BulletproofPlus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public static bool Verify(BulletproofPlus bp)
return rv;
}

public BulletproofPlus(Coin.BulletproofPlus bp, Key[] comms)
public BulletproofPlus(Coin.Models.BulletproofPlus bp, Key[] comms)
{
A = bp.A;
A1 = bp.A1;
Expand Down
19 changes: 13 additions & 6 deletions Discreet/Cipher/Key.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ public Key(Stream s)
/// <returns></returns>
public static Key Zero()
{
return Z;
return Clone(Z);
}

public static Key Clone(Key k)
{
var c = new Key(new byte[32]);
Array.Copy(k.bytes, c.bytes, 32);
return c;
}

/// <summary>
Expand All @@ -56,7 +63,7 @@ public static Key Zero()
/// <param name="k"></param>
public static void Zero(Key k)
{
Array.Copy(Key.Zero().bytes, k.bytes, 32);
Array.Copy(Z.bytes, k.bytes, 32);
}

/// <summary>
Expand All @@ -65,7 +72,7 @@ public static void Zero(Key k)
/// <returns></returns>
public static Key Identity()
{
return I;
return Clone(I);
}

/// <summary>
Expand All @@ -74,7 +81,7 @@ public static Key Identity()
/// <param name="k"></param>
public static void Identity(Key k)
{
Array.Copy(Key.Identity().bytes, k.bytes, 32);
Array.Copy(I.bytes, k.bytes, 32);
}

/// <summary>
Expand All @@ -83,7 +90,7 @@ public static void Identity(Key k)
/// <returns></returns>
public static Key CurveOrder()
{
return L;
return Clone(L);
}

/// <summary>
Expand All @@ -92,7 +99,7 @@ public static Key CurveOrder()
/// <returns></returns>
public static void CurveOrder(Key k)
{
Array.Copy(Key.CurveOrder().bytes, k.bytes, 32);
Array.Copy(L.bytes, k.bytes, 32);
}

/// <summary>
Expand Down
51 changes: 46 additions & 5 deletions Discreet/Cipher/KeyOps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ namespace Discreet.Cipher
public static class KeyOps
{
public static void GenerateKeypair(ref Key sk, ref Key pk) => Native.Native.Instance.GenerateKeypair(ref sk, ref pk);
public static (Key Sk, Key Pk) GenerateKeypair()
{
Key sk = new(new byte[32]);
Key pk = new(new byte[32]);

GenerateKeypair(ref sk, ref pk);

return (sk, pk);
}

public static void ScalarmultKey(ref Key ap, ref Key p, ref Key a) => Native.Native.Instance.ScalarmultKey(ref ap, ref p, ref a);
public static void DKSAP(ref Key R, ref Key T, ref Key pv, ref Key ps, int index) => Native.Native.Instance.DKSAP(ref R, ref T, ref pv, ref ps, index);
public static void DKSAPRecover(ref Key t, ref Key R, ref Key sv, ref Key ss, int index) => Native.Native.Instance.DKSAPRecover(ref t, ref R, ref sv, ref ss, index);
Expand All @@ -29,6 +39,13 @@ public static Key ScalarmultBase(ref Key a)
return ag;
}

public static Key ScalarmultBase(Key a)
{
Key ag = new Key(new byte[32]);
ScalarmultBase(ref ag, ref a);
return ag;
}

public static void GenCommitment(ref Key c, ref Key a, ulong amount) => Native.Native.Instance.GenCommitment(ref c, ref a, amount);
public static Key Commit(ref Key a, ulong amount) => Native.Native.Instance.Commit(ref a, amount);
public static Key CommitToZero(ulong amount) => Native.Native.Instance.CommitToZero(amount);
Expand All @@ -48,21 +65,45 @@ public static Key ScalarmultKey(ref Key p, ref Key a)

public static ulong XOR8(ref Key g, ulong amount)
{
byte[] amountBytes = Coin.Serialization.UInt64(amount);
byte[] amountBytes = Common.Serialization.UInt64(amount);

for (int i = 0; i < 8; i++)
{
amountBytes[i] ^= g.bytes[i];
}

return Coin.Serialization.GetUInt64(amountBytes, 0);
return Common.Serialization.GetUInt64(amountBytes, 0);
}

public static ulong GenAmountMask(ref Key r, ref Key pv, int i, ulong amount)
{
byte[] cdata = new byte[36];
Array.Copy(ScalarmultKey(ref pv, ref r).bytes, cdata, 32);
Coin.Serialization.CopyData(cdata, 32, i);
Common.Serialization.CopyData(cdata, 32, i);

Key c = new Key(new byte[32]);
HashOps.HashToScalar(ref c, cdata, 36);

byte[] gdata = new byte[38];
gdata[0] = (byte)'a';
gdata[1] = (byte)'m';
gdata[2] = (byte)'o';
gdata[3] = (byte)'u';
gdata[4] = (byte)'n';
gdata[5] = (byte)'t';
Array.Copy(c.bytes, 0, gdata, 6, 32);

Key g = new Key(new byte[32]);
HashOps.HashData(ref g, gdata, 38);

return XOR8(ref g, amount);
}

public static ulong GenAmountMaskRecover(ref Key R, ref Key sv, int i, ulong amount)
{
byte[] cdata = new byte[36];
Array.Copy(ScalarmultKey(ref R, ref sv).bytes, cdata, 32);
Common.Serialization.CopyData(cdata, 32, i);

Key c = new Key(new byte[32]);
HashOps.HashToScalar(ref c, cdata, 36);
Expand Down Expand Up @@ -100,7 +141,7 @@ public static Key GenCommitmentMask(ref Key r, ref Key pv, int i)
{
byte[] cdata = new byte[36];
Array.Copy(ScalarmultKey(ref pv, ref r).bytes, cdata, 32);
Coin.Serialization.CopyData(cdata, 32, i);
Common.Serialization.CopyData(cdata, 32, i);

Key c = new Key(new byte[32]);
HashOps.HashToScalar(ref c, cdata, 36);
Expand All @@ -116,7 +157,7 @@ public static Key GenCommitmentMaskRecover(ref Key R, ref Key sv, int i)
{
byte[] cdata = new byte[36];
Array.Copy(ScalarmultKey(ref R, ref sv).bytes, cdata, 32);
Coin.Serialization.CopyData(cdata, 32, i);
Common.Serialization.CopyData(cdata, 32, i);

Key c = new Key(new byte[32]);
HashOps.HashToScalar(ref c, cdata, 36);
Expand Down
8 changes: 4 additions & 4 deletions Discreet/Cipher/SHA256.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,23 @@ public SHA256(byte[] data, uint offset)
public SHA256(ulong num)
{
bytes = new byte[32];
Coin.Serialization.CopyData(bytes, 24, num);
Common.Serialization.CopyData(bytes, 24, num);
}

public SHA256(long num)
{
bytes = new byte[32];
Coin.Serialization.CopyData(bytes, 24, num);
Common.Serialization.CopyData(bytes, 24, num);
}

public ulong ToUInt64()
{
return Coin.Serialization.GetUInt64(bytes, 24);
return Common.Serialization.GetUInt64(bytes, 24);
}

public long ToInt64()
{
return Coin.Serialization.GetInt64(bytes, 24);
return Common.Serialization.GetInt64(bytes, 24);
}

public bool IsLong()
Expand Down
19 changes: 18 additions & 1 deletion Discreet/Cipher/Signature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
using Discreet.Common.Serialize;

namespace Discreet.Cipher
{
[StructLayout(LayoutKind.Sequential)]
public struct Signature
public struct Signature : ISerializable
{
[MarshalAs(UnmanagedType.Struct)]
public Key s;
Expand Down Expand Up @@ -153,5 +154,21 @@ internal bool IsNull()
{
return s.Equals(Key.Z) && e.Equals(Key.Z);
}

public int Size => 96;

public void Serialize(BEBinaryWriter writer)
{
writer.WriteKey(s);
writer.WriteKey(e);
writer.WriteKey(y);
}

public void Deserialize(ref MemoryReader reader)
{
s = reader.ReadKey();
e = reader.ReadKey();
y = reader.ReadKey();
}
}
}
2 changes: 1 addition & 1 deletion Discreet/Cipher/Triptych.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public struct Triptych
[MarshalAs(UnmanagedType.Struct)]
public Key zA, zC, z;

public Triptych(Coin.Triptych proof, Key linkingTag)
public Triptych(Coin.Models.Triptych proof, Key linkingTag)
{
J = linkingTag;
K = proof.K;
Expand Down
10 changes: 1 addition & 9 deletions Discreet/Coin/Address.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Runtime.InteropServices;
using Discreet.Common;
using System.IO;
using Discreet.Common.Exceptions;

namespace Discreet.Coin
{
Expand All @@ -30,19 +31,15 @@ public static class AddressVersion
public static byte VERSION = 1;
}

[StructLayout(LayoutKind.Sequential)]
/**
* TAddress is the Discreet Transparent address class.
*/
public class TAddress: IAddress
{
[MarshalAs(UnmanagedType.U1)]
public byte version;

[MarshalAs(UnmanagedType.Struct)]
public Cipher.RIPEMD160 hash;

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public byte[] checksum;

public TAddress(Cipher.Key pk)
Expand Down Expand Up @@ -190,22 +187,17 @@ public bool CheckAddressBytes(Cipher.Key pk)
}
}

[StructLayout(LayoutKind.Sequential)]
/**
* StealthAddress is the Discreet shielded/private address class (i.e. dual key wallet).
*/
public class StealthAddress : IAddress
{
[MarshalAs(UnmanagedType.U1)]
public byte version;

[MarshalAs(UnmanagedType.Struct)]
public Cipher.Key spend;

[MarshalAs(UnmanagedType.Struct)]
public Cipher.Key view;

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public byte[] checksum;

public StealthAddress(Cipher.Key vk, Cipher.Key sk)
Expand Down
Loading

0 comments on commit 9214452

Please sign in to comment.