-
Notifications
You must be signed in to change notification settings - Fork 24
perf(PAYINS-1388): Add native AOT support #372
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
base: main
Are you sure you want to change the base?
Conversation
|
/pretag |
|
Created pre-tag v0.3.2-pre0 (View in CircleCi) |
|
/pretag |
|
Created pre-tag v0.3.2-pre1 (View in CircleCi) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds Native AOT (Ahead-of-Time) compilation support to the TrueLayer.Signing library by removing reflection-based dependencies and implementing custom AOT-compatible alternatives for JWT operations.
Key Changes
- Removed Jose.JWT dependency and replaced with custom Base64Url encoding and JWS signature verification
- Added JSON Source Generation context (
SigningJsonContext) for AOT-compatible serialization on .NET 5.0+ - Configured AOT and trimming settings in the project file with framework-specific dependency versions
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| csharp/test/UsageTest.cs | Removed unused Jose.JWT import |
| csharp/test/SigningFunction.cs | Removed unused Jose.JWT import |
| csharp/test/ErrorTest.cs | Removed unused Jose.JWT import |
| csharp/src/truelayer-signing.csproj | Added AOT compatibility flags and reorganized dependencies by target framework with version updates |
| csharp/src/Verifier.cs | Replaced Jose.JWT with custom JWS header parsing and signature verification using direct cryptographic operations |
| csharp/src/Util.cs | Added SigningJsonContext for source generation, enhanced GetString() to handle JsonElement deserialization |
| csharp/src/Signer.cs | Replaced Jose.JWT signing with custom JWS creation using manual Base64Url encoding and hash signing, added XML documentation |
| csharp/src/Base64Url.cs | New custom Base64Url encoder/decoder implementation for AOT compatibility |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
csharp/src/Verifier.cs
Outdated
| // Build the signing input: base64url(header).base64url(payload) | ||
| // For detached signatures, we reconstruct using the provided payload | ||
| var payloadB64 = Base64Url.Encode(payload); | ||
| var signingInput = new byte[headerB64.Length + 1 + payloadB64.Length]; | ||
| #if NET5_0_OR_GREATER | ||
| // Use Span-based API for better performance on modern .NET | ||
| Encoding.ASCII.GetBytes(headerB64, signingInput.AsSpan(0, headerB64.Length)); | ||
| signingInput[headerB64.Length] = (byte)'.'; | ||
| Encoding.ASCII.GetBytes(payloadB64, signingInput.AsSpan(headerB64.Length + 1)); | ||
| #else | ||
| Encoding.UTF8.GetBytes(headerB64, 0, headerB64.Length, signingInput, 0); | ||
| signingInput[headerB64.Length] = (byte)'.'; | ||
| Encoding.UTF8.GetBytes(payloadB64, 0, payloadB64.Length, signingInput, headerB64.Length + 1); | ||
| #endif | ||
|
|
||
| // Compute SHA-512 hash of the signing input (ES512 uses SHA-512) | ||
| #if NET5_0_OR_GREATER | ||
| var hash = SHA512.HashData(signingInput); | ||
| #else | ||
| byte[] hash; | ||
| using (var sha512 = SHA512.Create()) | ||
| { | ||
| hash = sha512.ComputeHash(signingInput); | ||
| } | ||
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code seems shared between the Signer and Verifier, could we extract to a Util?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also we differ between ASCII and UTF8 encoding in the if block, why is that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the output in this case is the same as base64url is producing ASCII only but better to align both paths
Summary
This PR adds Native AOT (Ahead-of-Time) compilation support to the TrueLayer.Signing library, enabling better performance and reduced startup times for .NET applications.
Key Changes
SigningJsonContextfor AOT-compatible JSON serializationIsAotCompatible,IsTrimmable,EnableTrimAnalyzer, andEnableSingleFileAnalyzerpropertiesBenchmark (net10/small payment)
current:
v0.2.5 - jose-jwt:
v0.1.16