-
Notifications
You must be signed in to change notification settings - Fork 2
C# (.NET 10) port of the API service #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
92063fb
feat(dotnet): C# port foundation — infra, crypto verified against dhi…
b36b459
feat(dotnet): complete handler port — all 115 routes, wallet aggregat…
050b62c
feat(dotnet): explicit rate-limit failover, test suite, parity harnes…
c42b100
docs(dotnet): add measured Node-vs-C# benchmark results
4a023ab
docs(dotnet): full setup/run instructions (SDK, local, Docker, swarm,…
a14be94
ci: build, test and deploy the C# service on merge
440126b
fix(dotnet): review fixes + unify Hive RPC node list
7a89747
fix: dead-endpoint cleanup, request-delete stub, SDK-adopted node fai…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 @@ | ||
| **/bin/ | ||
| **/obj/ | ||
| parity/ | ||
| tools/ | ||
| EcencyApi.Tests/ | ||
| README.md |
This file contains hidden or 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,3 @@ | ||
| bin/ | ||
| obj/ | ||
| *.user |
This file contains hidden or 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,34 @@ | ||
| # Multi-stage build for the C# port of vision-api. | ||
| # Produces a self-contained ASP.NET Core service on the same 4000 port and | ||
| # /healthcheck.json contract as the Node image, so it is a drop-in swap in the | ||
| # vision_vapi stack. | ||
|
|
||
| FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build | ||
| WORKDIR /src | ||
|
|
||
| COPY EcencyApi/EcencyApi.csproj EcencyApi/ | ||
| RUN dotnet restore EcencyApi/EcencyApi.csproj | ||
|
|
||
| COPY EcencyApi/ EcencyApi/ | ||
| RUN dotnet publish EcencyApi/EcencyApi.csproj -c Release -o /app --no-restore | ||
|
|
||
| FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS runtime | ||
| WORKDIR /app | ||
|
|
||
| # Static assets served by express.static in the Node version (public/). | ||
| COPY EcencyApi/public/ ./public/ | ||
| COPY --from=build /app ./ | ||
|
|
||
| # Run as the non-root user the aspnet base image ships; port 4000 is unprivileged. | ||
| RUN chown -R app:app /app | ||
| USER app | ||
|
|
||
| ENV API_PORT=4000 | ||
| ENV ASPNETCORE_URLS= | ||
| EXPOSE 4000 | ||
|
|
||
| # Same health contract the Node healthCheck.js polled. | ||
| HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \ | ||
| CMD ["dotnet", "EcencyApi.dll", "--healthcheck"] | ||
|
|
||
| ENTRYPOINT ["dotnet", "EcencyApi.dll"] | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
This file contains hidden or 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,24 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net10.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <IsPackable>false</IsPackable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" /> | ||
| <PackageReference Include="xunit" Version="2.9.3" /> | ||
| <PackageReference Include="xunit.runner.visualstudio" Version="3.1.1" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="../EcencyApi/EcencyApi.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <None Include="fixtures/**" CopyToOutputDirectory="PreserveNewest" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or 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,159 @@ | ||
| using System.Text.Json; | ||
| using System.Text.Json.Nodes; | ||
| using EcencyApi.Infrastructure; | ||
| using Xunit; | ||
|
|
||
| namespace EcencyApi.Tests; | ||
|
|
||
| /// <summary> | ||
| /// Byte-for-byte verification of the crypto port against golden vectors | ||
| /// generated from the exact dhive/js-base64 versions the Node service uses | ||
| /// (dotnet/tools/gen-vectors.js). | ||
| /// </summary> | ||
| public class HiveCryptoTests | ||
| { | ||
| private static readonly JsonObject Vectors = LoadVectors(); | ||
|
|
||
| private static JsonObject LoadVectors() | ||
| { | ||
| var path = Path.Combine(AppContext.BaseDirectory, "fixtures", "crypto-vectors.json"); | ||
| return (JsonObject)JsonNode.Parse(File.ReadAllText(path))!; | ||
| } | ||
|
|
||
| [Fact] | ||
| public void FromLogin_MatchesDhive() | ||
| { | ||
| foreach (var v in Vectors["fromLogin"]!.AsArray()) | ||
| { | ||
| var username = v!["username"]!.GetValue<string>(); | ||
| var password = v["password"]!.GetValue<string>(); | ||
| var role = v["role"]!.GetValue<string>(); | ||
|
|
||
| var key = HiveCrypto.FromLogin(username, password, role); | ||
|
|
||
| Assert.Equal(v["wif"]!.GetValue<string>(), HiveCrypto.ToWif(key)); | ||
| Assert.Equal(v["publicKey"]!.GetValue<string>(), | ||
| HiveCrypto.PublicKeyToString(key.CreatePubKey())); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Sign_MatchesDhiveByteForByte() | ||
| { | ||
| foreach (var v in Vectors["sign"]!.AsArray()) | ||
| { | ||
| var key = HiveCrypto.FromLogin( | ||
| v!["username"]!.GetValue<string>(), | ||
| v["password"]!.GetValue<string>(), | ||
| v["role"]!.GetValue<string>()); | ||
|
|
||
| var digest = HiveCrypto.Sha256Utf8(v["message"]!.GetValue<string>()); | ||
| Assert.Equal(v["digestHex"]!.GetValue<string>(), Convert.ToHexStringLower(digest)); | ||
|
|
||
| Assert.Equal(v["signature"]!.GetValue<string>(), HiveCrypto.Sign(key, digest)); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Recover_MatchesDhive() | ||
| { | ||
| foreach (var v in Vectors["recover"]!.AsArray()) | ||
| { | ||
| var digest = Convert.FromHexString(v!["digestHex"]!.GetValue<string>()); | ||
| var recovered = HiveCrypto.RecoverPublicKey(v["signature"]!.GetValue<string>(), digest); | ||
|
|
||
| Assert.Equal(v["recoveredPublicKey"]!.GetValue<string>(), recovered); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void B64uEncode_MatchesJsBase64() | ||
| { | ||
| foreach (var v in Vectors["b64u"]!.AsArray()) | ||
| { | ||
| Assert.Equal(v!["encoded"]!.GetValue<string>(), | ||
| B64u.Encode(v["input"]!.GetValue<string>())); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void HsTokenCreate_FullFlow_MatchesNode() | ||
| { | ||
| foreach (var v in Vectors["hsTokenCreate"]!.AsArray()) | ||
| { | ||
| var username = v!["username"]!.GetValue<string>(); | ||
| var password = v["password"]!.GetValue<string>(); | ||
| var app = v["app"]!.GetValue<string>(); | ||
| var timestamp = v["timestamp"]!.GetValue<long>(); | ||
|
|
||
| // Reproduce hsTokenCreate exactly: build the message object with JS | ||
| // property order, hash the JSON.stringify form, sign, then append | ||
| // signatures and b64u-encode. | ||
| var messageObj = new JsonObject | ||
| { | ||
| ["signed_message"] = new JsonObject { ["type"] = "code", ["app"] = app }, | ||
| ["authors"] = new JsonArray(username), | ||
| ["timestamp"] = timestamp, | ||
| }; | ||
|
|
||
| var hash = HiveCrypto.Sha256Utf8(JsJson.Stringify(messageObj)); | ||
| var key = HiveCrypto.FromLogin(username, password, "posting"); | ||
| var signature = HiveCrypto.Sign(key, hash); | ||
| messageObj["signatures"] = new JsonArray(signature); | ||
|
|
||
| var signedJson = JsJson.Stringify(messageObj); | ||
| Assert.Equal(v["signedJson"]!.GetValue<string>(), signedJson); | ||
| Assert.Equal(v["code"]!.GetValue<string>(), B64u.Encode(signedJson)); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ValidateCodeReserialization_MatchesNode() | ||
| { | ||
| foreach (var v in Vectors["validateCodeRaw"]!.AsArray()) | ||
| { | ||
| var token = (JsonObject)JsonNode.Parse(v!["tokenJson"]!.GetValue<string>())!; | ||
|
|
||
| // The exact re-serialization validateCode performs: | ||
| // JSON.stringify({signed_message, authors, timestamp}) with the | ||
| // parsed nodes (nested key order preserved from the token). | ||
| var raw = new JsonObject | ||
| { | ||
| ["signed_message"] = token["signed_message"]!.DeepClone(), | ||
| ["authors"] = token["authors"]!.DeepClone(), | ||
| ["timestamp"] = token["timestamp"]!.DeepClone(), | ||
| }; | ||
|
|
||
| var rawMessage = JsJson.Stringify(raw); | ||
| Assert.Equal(v["rawMessage"]!.GetValue<string>(), rawMessage); | ||
| Assert.Equal(v["digestHex"]!.GetValue<string>(), | ||
| Convert.ToHexStringLower(HiveCrypto.Sha256Utf8(rawMessage))); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void NumberFormatting_MatchesV8() | ||
| { | ||
| foreach (var v in Vectors["numberFormat"]!.AsArray()) | ||
| { | ||
| var value = v!["value"]!.GetValue<double>(); | ||
| var expected = v["text"]!.GetValue<string>(); | ||
| // JSON.stringify path (fixture "value" is V8-serialized, so parsing it | ||
| // and re-serializing must reproduce "text" byte-for-byte) | ||
| Assert.Equal(expected, JsJson.Stringify(JsonValue.Create(value))); | ||
| } | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData("{\"a\":1,\"b\":\"x\"}")] | ||
| [InlineData("{\"b\":2,\"a\":1}")] // property order preserved, not sorted | ||
| [InlineData("[1,2.5,\"s\",true,null,{}]")] | ||
| [InlineData("{\"n\":1751900000.123}")] | ||
| [InlineData("{\"u\":\"caf\\u00e9 漢字\"}")] | ||
| public void JsJson_RoundTripsParsedJson(string json) | ||
| { | ||
| var node = JsonNode.Parse(json); | ||
| var expected = json.Replace("\\u00e9", "é"); // JSON.stringify emits raw unicode | ||
| Assert.Equal(expected, JsJson.Stringify(node)); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.