Phase 1 foundations in the Anubis library: - Platform: startup configuration from environment variables (Docker) or config.toml (desktop, in-house TOML subset), data folder layout, secret key custody (ANUBIS_SECRET_KEY, DPAPI on Windows, restricted file elsewhere), installation identity and database fingerprint. - Db: ADO.NET with Npgsql and Microsoft.Data.Sqlite, money as NUMERIC(38,18) or canonical text rounded to 18 decimals, UTC moments, UUIDv7 ids; numbered SQL migrations with type tokens and a version table; engine-independent export/import with count and accounting-total checks; backups keeping 14. - Core: injectable clock, channel event bus, scheduler with fixed, interval and market-relative times, settings with change log, AES-GCM secrets, log redaction, Italian formats. - Access: PBKDF2-SHA512 hashes, RFC 6238 TOTP, hashed session tokens, sign-in attempt limit. SQLitePCLRaw (Apache-2.0) arrives with Microsoft.Data.Sqlite and is declared in DependencyPolicyTests and API-NOTES. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
22 lines
778 B
C#
22 lines
778 B
C#
using System.Security.Cryptography;
|
|
|
|
namespace Anubis.Core;
|
|
|
|
/// <summary>Surrogate keys (SPEC 5.4): UUID version 7, ordered by creation time.</summary>
|
|
public static class Ids
|
|
{
|
|
/// <summary>A new UUIDv7 whose time part comes from the injected clock, so ids follow simulated time too.</summary>
|
|
public static Guid NewId(IClock clock)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(clock);
|
|
return Guid.CreateVersion7(clock.UtcNow);
|
|
}
|
|
|
|
/// <summary>A random token for sessions and fingerprints, URL-safe base64 of 32 bytes.</summary>
|
|
public static string NewToken(int bytes = 32)
|
|
{
|
|
var buffer = RandomNumberGenerator.GetBytes(bytes);
|
|
return Convert.ToBase64String(buffer).TrimEnd('=').Replace('+', '-').Replace('/', '_');
|
|
}
|
|
}
|