// FairDice protocol v1 - C# SDK (.NET 6+). Single file, no dependencies. // Produces exactly the same results as the JavaScript and Python SDKs // (see spec/test-vectors.json), so proofs verify on https://fairdice.ir. // // var fd = new FairDice(new FairDiceOptions { Dice = "2d6", Game = "Backgammon" }); // Send(fd.Commitment); // show players before the game // int[] roll = fd.Roll(); // [3, 5] - offline, no API calls // ... // string url = fd.Url(); // https://fairdice.ir/v/ (reveals the seed) // // A FairDice instance is NOT thread-safe: use one per match and lock if several threads roll. using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Text.Encodings.Web; using System.Text.Json; using System.Text.RegularExpressions; namespace FairDiceIR { /// HMAC-SHA256(serverSeed, $"{clientSeed}:{nonce}:{block}") byte stream for one draw. public sealed class ByteStream { private const long Two32 = 4294967296L; private readonly HMACSHA256 _mac; private readonly string _prefix; private long _block; private byte[] _buf = Array.Empty(); private int _pos; public ByteStream(HMACSHA256 mac, string clientSeed, long nonce) { _mac = mac; _prefix = clientSeed + ":" + nonce + ":"; } public int Byte() { if (_pos >= _buf.Length) { _buf = _mac.ComputeHash(Encoding.UTF8.GetBytes(_prefix + _block)); _block++; _pos = 0; } return _buf[_pos++]; } public long UInt32() => ((long)Byte() << 24) | ((long)Byte() << 16) | ((long)Byte() << 8) | (long)Byte(); /// Uniform integer in [0, n) by rejection sampling. n in [1, 2^32]. public long Int(long n) { if (n < 1 || n > Two32) throw new ArgumentOutOfRangeException(nameof(n), "n must be in [1, 2^32]"); if (n == 1) return 0; long limit = Two32 - (Two32 % n); while (true) { long x = UInt32(); if (x < limit) return x % n; } } public double Float() { long a = UInt32() >> 5; long b = UInt32() >> 6; return (a * 67108864.0 + b) / 9007199254740992.0; } } public sealed class DealResult { public List Hands { get; } = new List(); public object[] Rest { get; set; } = Array.Empty(); } public sealed class Draw { public int Index { get; set; } public long Nonce { get; set; } public string Code { get; set; } = ""; public object[] Params { get; set; } = Array.Empty(); public object Result { get; set; } = ""; } public sealed class FairDiceOptions { /// 64 lowercase hex chars. Leave null to generate a secure seed (recommended). public string? ServerSeed { get; set; } /// Player-provided entropy; set before the first draw. public string? ClientSeed { get; set; } public long Nonce { get; set; } /// Default op for Roll(), e.g. "2d6" (backgammon) or "5d6" (Yatzy). public string? Dice { get; set; } public string? Game { get; set; } public Dictionary? Meta { get; set; } public string BaseUrl { get; set; } = "https://fairdice.ir"; public bool KeepHistory { get; set; } = true; } public sealed class Reveal { public string Token { get; set; } = ""; public string Url { get; set; } = ""; public string Commitment { get; set; } = ""; public int Count { get; set; } public string ProofJson { get; set; } = ""; } public sealed class VerifyResult { public string Commitment { get; set; } = ""; public bool? CommitmentMatches { get; set; } public string ServerSeed { get; set; } = ""; public string ClientSeed { get; set; } = ""; public string? Game { get; set; } public List Draws { get; } = new List(); } public static class FairDiceProtocol { public const long Two32 = 4294967296L; public const int MaxCount = 10000; public const int MaxDeck = 100000; public const int MaxPick = 100000; private static readonly Regex SeedRe = new Regex("^[0-9a-f]{64}$", RegexOptions.Compiled); private static readonly string[] Suits = { "S", "H", "D", "C" }; private static readonly string[] Ranks = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K" }; public static bool IsValidServerSeed(string s) => s != null && SeedRe.IsMatch(s); public static string CommitmentOf(string serverSeed) { using var sha = SHA256.Create(); return ToHex(sha.ComputeHash(Encoding.UTF8.GetBytes(serverSeed))); } public static string ToHex(byte[] b) { var sb = new StringBuilder(b.Length * 2); foreach (var x in b) sb.Append(x.ToString("x2")); return sb.ToString(); } // ------------------------------------------------------------ decks private static List Cards(IEnumerable ranks) { var r = ranks.ToArray(); var list = new List(); foreach (var s in Suits) foreach (var k in r) list.Add(k + s); return list; } private static List Dominoes(int max) { var list = new List(); for (int a = 0; a <= max; a++) for (int b = a; b <= max; b++) list.Add(a + "-" + b); return list; } /// std52 | std54 | std36 | std32 | shoe:N | dom6 | dom9 | dom12 | n:N public static List BuildDeck(string spec) { switch (spec) { case "std52": return Cards(Ranks); case "std54": { var d = Cards(Ranks); d.Add("XR"); d.Add("XB"); return d; } case "std36": return Cards(new[] { "A", "6", "7", "8", "9", "T", "J", "Q", "K" }); case "std32": return Cards(new[] { "A", "7", "8", "9", "T", "J", "Q", "K" }); case "dom6": return Dominoes(6); case "dom9": return Dominoes(9); case "dom12": return Dominoes(12); } var m = Regex.Match(spec ?? "", "^shoe:(\\d{1,2})$"); if (m.Success) { int k = int.Parse(m.Groups[1].Value); if (k < 1 || k > 16) throw new ArgumentOutOfRangeException(nameof(spec), "shoe:N supports 1..16"); var one = Cards(Ranks); var list = new List(); for (int i = 0; i < k; i++) list.AddRange(one); return list; } m = Regex.Match(spec ?? "", "^n:(\\d{1,6})$"); if (m.Success) { int n = int.Parse(m.Groups[1].Value); if (n < 1 || n > MaxDeck) throw new ArgumentOutOfRangeException(nameof(spec), "n:N supports 1..100000"); var list = new List(n); for (int i = 1; i <= n; i++) list.Add((long)i); return list; } throw new ArgumentException($"Unknown deck spec \"{spec}\""); } // ------------------------------------------------------------ ops private static long L(object o) => o switch { long l => l, int i => i, double d when d == Math.Floor(d) => (long)d, JsonElement e when e.ValueKind == JsonValueKind.Number => e.GetInt64(), _ => throw new ArgumentException("expected an integer parameter"), }; private static string S(object o) => o switch { string s => s, JsonElement e when e.ValueKind == JsonValueKind.String => e.GetString()!, _ => throw new ArgumentException("expected a string parameter"), }; private static long[] LA(object o) => o switch { long[] a => a, int[] a => a.Select(x => (long)x).ToArray(), IEnumerable a => a.ToArray(), JsonElement e when e.ValueKind == JsonValueKind.Array => e.EnumerateArray().Select(x => x.GetInt64()).ToArray(), _ => throw new ArgumentException("expected an integer array parameter"), }; private static long In(object o, long lo, long hi, string name) { long v = L(o); if (v < lo || v > hi) throw new ArgumentOutOfRangeException(name, $"{name} must be in [{lo}, {hi}]"); return v; } public static void ValidateOp(string code, object[] p) { void Arity(int n) { if (p == null || p.Length != n) throw new ArgumentException($"op \"{code}\" expects {n} params"); } switch (code) { case "d": Arity(2); In(p[0], 2, 1_000_000_000, "sides"); In(p[1], 1, MaxCount, "count"); return; case "c": case "f": Arity(1); In(p[0], 1, MaxCount, "count"); return; case "i": Arity(3); if (L(p[1]) < L(p[0])) throw new ArgumentException("min must be <= max"); if (L(p[1]) - L(p[0]) + 1 > Two32) throw new ArgumentException("range must be <= 2^32"); In(p[2], 1, MaxCount, "count"); return; case "s": Arity(1); BuildDeck(S(p[0])); return; case "dl": { Arity(3); int size = BuildDeck(S(p[0])).Count; long h = In(p[1], 1, 1000, "hands"), per = In(p[2], 1, MaxDeck, "perHand"); if (h * per > size) throw new ArgumentException($"cannot deal {h}x{per} from a deck of {size}"); return; } case "p": { Arity(3); long n = In(p[0], 1, Two32, "n"); In(p[1], 1, Math.Min(n, MaxPick), "k"); In(p[2], -9007199254740991L + Two32, 9007199254740991L - Two32, "offset"); return; } case "w": { Arity(2); var ws = LA(p[0]); if (ws.Length < 1 || ws.Length > 10000) throw new ArgumentException("1..10000 weights"); long total = 0; foreach (var w in ws) { if (w < 0 || w > Two32) throw new ArgumentException("weight out of range"); total += w; } if (total < 1 || total > Two32) throw new ArgumentException("sum of weights must be in [1, 2^32]"); In(p[1], 1, MaxCount, "count"); return; } case "r": Arity(2); if (S(p[0]) != "eu" && S(p[0]) != "us") throw new ArgumentException("variant must be eu or us"); In(p[1], 1, MaxCount, "count"); return; case "b": Arity(1); In(p[0], 1, 4096, "length"); return; default: throw new ArgumentException($"Unknown op code \"{code}\""); } } /// Sparse forward Fisher-Yates: step i swaps i with j = i + int(n - i). public static long[] PickIndices(ByteStream s, long n, long k) { var moved = new Dictionary(); var outp = new long[k]; for (long i = 0; i < k; i++) { long j = i + s.Int(n - i); long atI = moved.TryGetValue(i, out var vi) ? vi : i; long atJ = moved.TryGetValue(j, out var vj) ? vj : j; moved[j] = atI; moved.Remove(i); outp[i] = atJ; } return outp; } /// Executes an op; results are int[] / long[] / string[] / double[] / object[] / DealResult / string. public static object ExecuteOp(ByteStream s, string code, object[] p) { switch (code) { case "d": { long sides = L(p[0]); int count = (int)L(p[1]); var r = new int[count]; for (int i = 0; i < count; i++) r[i] = (int)(1 + s.Int(sides)); return r; } case "c": { int count = (int)L(p[0]); var r = new string[count]; for (int i = 0; i < count; i++) r[i] = s.Int(2) == 0 ? "H" : "T"; return r; } case "i": { long min = L(p[0]), max = L(p[1]); int count = (int)L(p[2]); var r = new long[count]; for (int i = 0; i < count; i++) r[i] = min + s.Int(max - min + 1); return r; } case "f": { int count = (int)L(p[0]); var r = new double[count]; for (int i = 0; i < count; i++) r[i] = s.Float(); return r; } case "s": { var deck = BuildDeck(S(p[0])); return PickIndices(s, deck.Count, deck.Count).Select(i => deck[(int)i]).ToArray(); } case "dl": { var deck = BuildDeck(S(p[0])); int hands = (int)L(p[1]), per = (int)L(p[2]); var sh = PickIndices(s, deck.Count, deck.Count).Select(i => deck[(int)i]).ToArray(); var res = new DealResult(); for (int h = 0; h < hands; h++) res.Hands.Add(sh.Skip(h * per).Take(per).ToArray()); res.Rest = sh.Skip(hands * per).ToArray(); return res; } case "p": { long n = L(p[0]), k = L(p[1]), off = L(p[2]); return PickIndices(s, n, k).Select(i => i + off).ToArray(); } case "w": { var ws = LA(p[0]); int count = (int)L(p[1]); long total = ws.Sum(); var r = new int[count]; for (int c = 0; c < count; c++) { long x = s.Int(total); int idx = 0; while (x >= ws[idx]) { x -= ws[idx]; idx++; } r[c] = idx; } return r; } case "r": { bool us = S(p[0]) == "us"; int count = (int)L(p[1]); var r = new object[count]; for (int i = 0; i < count; i++) { long x = s.Int(us ? 38 : 37); r[i] = x == 37 ? (object)"00" : x; } return r; } case "b": { int len = (int)L(p[0]); var sb = new StringBuilder(len * 2); for (int i = 0; i < len; i++) sb.Append(s.Byte().ToString("x2")); return sb.ToString(); } } throw new ArgumentException($"Unknown op code \"{code}\""); } public static object ComputeDraw(string serverSeed, string clientSeed, long nonce, string code, object[] p) { ValidateOp(code, p); using var mac = new HMACSHA256(Encoding.UTF8.GetBytes(serverSeed)); return ExecuteOp(new ByteStream(mac, clientSeed, nonce), code, p); } public static (int sides, int count) ParseDice(string notation) { var m = Regex.Match(notation ?? "", "^\\s*(\\d*)\\s*[dD]\\s*(\\d+)\\s*$"); if (!m.Success) throw new FormatException($"Invalid dice notation \"{notation}\""); int count = m.Groups[1].Value.Length > 0 ? int.Parse(m.Groups[1].Value) : 1; int sides = int.Parse(m.Groups[2].Value); ValidateOp("d", new object[] { (long)sides, (long)count }); return (sides, count); } // ------------------------------------------------------------ token public static string ToBase64Url(byte[] b) => Convert.ToBase64String(b).TrimEnd('=').Replace('+', '-').Replace('/', '_'); public static byte[] FromBase64Url(string s) { s = s.Trim().Replace('-', '+').Replace('_', '/').TrimEnd('='); return Convert.FromBase64String(s + new string('=', (4 - s.Length % 4) % 4)); } internal static void WriteValue(Utf8JsonWriter w, object v) { switch (v) { case null: w.WriteNullValue(); break; case string s: w.WriteStringValue(s); break; case bool b: w.WriteBooleanValue(b); break; case int i: w.WriteNumberValue(i); break; case long l: w.WriteNumberValue(l); break; case double d: w.WriteNumberValue(d); break; case long[] la: w.WriteStartArray(); foreach (var x in la) w.WriteNumberValue(x); w.WriteEndArray(); break; case int[] ia: w.WriteStartArray(); foreach (var x in ia) w.WriteNumberValue(x); w.WriteEndArray(); break; case JsonElement e: e.WriteTo(w); break; default: throw new ArgumentException("unsupported value type " + v.GetType()); } } private static readonly JsonWriterOptions WriterOptions = new JsonWriterOptions { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping }; public static string ProofJson(string serverSeed, string clientSeed, long firstNonce, IEnumerable<(string code, object[] p, long times)> log, string? game, IDictionary? meta, long? createdAt) { using var ms = new MemoryStream(); using (var w = new Utf8JsonWriter(ms, WriterOptions)) { w.WriteStartObject(); w.WriteNumber("v", 1); w.WriteString("s", serverSeed); w.WriteString("c", clientSeed); w.WriteNumber("n", firstNonce); w.WriteStartArray("o"); foreach (var (code, p, times) in log) { w.WriteStartArray(); w.WriteStringValue(code); w.WriteStartArray(); foreach (var x in p) WriteValue(w, x); w.WriteEndArray(); w.WriteNumberValue(times); w.WriteEndArray(); } w.WriteEndArray(); if (!string.IsNullOrEmpty(game)) w.WriteString("g", game); if (meta != null && meta.Count > 0) { w.WriteStartObject("m"); foreach (var kv in meta) { w.WritePropertyName(kv.Key); WriteValue(w, kv.Value); } w.WriteEndObject(); } if (createdAt.HasValue) w.WriteNumber("t", createdAt.Value); w.WriteEndObject(); } return Encoding.UTF8.GetString(ms.ToArray()); } public static string ExtractToken(string input) { var s = input.Trim(); var m = Regex.Match(s, "/v/([A-Za-z0-9_\\-+/=]+)"); if (m.Success) return m.Groups[1].Value; m = Regex.Match(s, "#([A-Za-z0-9_\\-+/=]+)$"); return m.Success ? m.Groups[1].Value : s; } /// Recompute every draw of a proof token (or https://fairdice.ir/v/... URL). public static VerifyResult Verify(string tokenOrUrl, string? expectedCommitment = null) { var json = Encoding.UTF8.GetString(FromBase64Url(ExtractToken(tokenOrUrl))); using var doc = JsonDocument.Parse(json); var root = doc.RootElement; if (root.GetProperty("v").GetInt32() != 1) throw new FormatException("unsupported proof version"); var seed = root.GetProperty("s").GetString()!; if (!IsValidServerSeed(seed)) throw new FormatException("invalid server seed"); var client = root.GetProperty("c").GetString()!; long n0 = root.GetProperty("n").GetInt64(); var res = new VerifyResult { ServerSeed = seed, ClientSeed = client, Commitment = CommitmentOf(seed), Game = root.TryGetProperty("g", out var g) ? g.GetString() : null, }; if (expectedCommitment != null) res.CommitmentMatches = expectedCommitment.Trim().ToLowerInvariant() == res.Commitment; using var mac = new HMACSHA256(Encoding.UTF8.GetBytes(seed)); int index = 0; foreach (var e in root.GetProperty("o").EnumerateArray()) { var code = e[0].GetString()!; var p = e[1].EnumerateArray().Select(x => (object)x.Clone()).ToArray(); long times = e[2].GetInt64(); ValidateOp(code, p); for (long t = 0; t < times; t++) { long nonce = n0 + index; res.Draws.Add(new Draw { Index = index, Nonce = nonce, Code = code, Params = p, Result = ExecuteOp(new ByteStream(mac, client, nonce), code, p) }); index++; } } return res; } } /// One provably fair session: a match, a table, a round. public sealed class FairDice : IDisposable { public string ServerSeed { get; } public string Commitment { get; } public long FirstNonce { get; } public string? Game { get; } public Dictionary? Meta { get; } public string BaseUrl { get; } public long CreatedAt { get; private set; } public List History { get; } = new List(); public string ClientSeed { get; private set; } public int Count { get; private set; } public long Nonce => FirstNonce + Count; public bool Revealed { get; private set; } private readonly HMACSHA256 _mac; private readonly List<(string code, object[] p, long times)> _log = new List<(string, object[], long)>(); private readonly (int sides, int count)? _defaultDice; private readonly bool _keepHistory; public FairDice(FairDiceOptions? opts = null) { opts ??= new FairDiceOptions(); var seed = (opts.ServerSeed ?? FairDiceProtocol.ToHex(RandomNumberGenerator.GetBytes(32))).ToLowerInvariant(); if (!FairDiceProtocol.IsValidServerSeed(seed)) throw new ArgumentException("ServerSeed must be 64 hex chars"); var client = opts.ClientSeed ?? FairDiceProtocol.ToHex(RandomNumberGenerator.GetBytes(8)); if (client.Length < 1 || client.Length > 256) throw new ArgumentException("ClientSeed must be 1..256 chars"); ServerSeed = seed; Commitment = FairDiceProtocol.CommitmentOf(seed); ClientSeed = client; FirstNonce = opts.Nonce; Game = opts.Game; Meta = opts.Meta; BaseUrl = opts.BaseUrl.TrimEnd('/'); CreatedAt = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); _keepHistory = opts.KeepHistory; _mac = new HMACSHA256(Encoding.UTF8.GetBytes(seed)); if (opts.Dice != null) _defaultDice = FairDiceProtocol.ParseDice(opts.Dice); } public static FairDice Backgammon(string? clientSeed = null) => new FairDice(new FairDiceOptions { Dice = "2d6", Game = "Backgammon", ClientSeed = clientSeed }); public static FairDice Yatzy(string? clientSeed = null) => new FairDice(new FairDiceOptions { Dice = "5d6", Game = "Yatzy", ClientSeed = clientSeed }); /// Set player-provided entropy. Only before the first draw. public FairDice SetClientSeed(string seed) { if (Count > 0) throw new InvalidOperationException("SetClientSeed must be called before the first draw"); if (string.IsNullOrEmpty(seed) || seed.Length > 256) throw new ArgumentException("ClientSeed must be 1..256 chars"); ClientSeed = seed; return this; } /// Combine several players' seeds (order-independent). public FairDice SetPlayerSeeds(IEnumerable seeds) { var joined = string.Join("|", seeds.OrderBy(s => s, StringComparer.Ordinal)); return SetClientSeed(joined.Length > 256 ? joined.Substring(0, 256) : joined); } public object Draw(string code, params object[] p) { if (Revealed) throw new InvalidOperationException("Session was revealed; start a new FairDice"); FairDiceProtocol.ValidateOp(code, p); long nonce = Nonce; var result = FairDiceProtocol.ExecuteOp(new ByteStream(_mac, ClientSeed, nonce), code, p); if (_log.Count > 0 && _log[^1].code == code && SameParams(_log[^1].p, p)) { var last = _log[^1]; _log[^1] = (last.code, last.p, last.times + 1); } else _log.Add((code, (object[])p.Clone(), 1)); if (_keepHistory) History.Add(new Draw { Index = Count, Nonce = nonce, Code = code, Params = p, Result = result }); Count++; return result; } private static bool SameParams(object[] a, object[] b) { if (a.Length != b.Length) return false; for (int i = 0; i < a.Length; i++) { if (a[i] is long[] la && b[i] is long[] lb) { if (!la.SequenceEqual(lb)) return false; } else if (a[i] is int[] ia && b[i] is int[] ib) { if (!ia.SequenceEqual(ib)) return false; } else if (!Equals(a[i], b[i])) return false; } return true; } /// Roll the default dice (from FairDiceOptions.Dice), e.g. two dice for backgammon. public int[] Roll() { if (_defaultDice == null) throw new InvalidOperationException("Set FairDiceOptions.Dice (e.g. \"2d6\") to use Roll()"); return Dice(_defaultDice.Value.sides, _defaultDice.Value.count); } public int[] Dice(int sides = 6, int count = 1) => (int[])Draw("d", (long)sides, (long)count); public string Coin() => ((string[])Draw("c", 1L))[0]; public long Int(long min, long max) => ((long[])Draw("i", min, max, 1L))[0]; public double Float() => ((double[])Draw("f", 1L))[0]; /// Shuffle a deck: std52, std54, std36, std32, shoe:N, dom6, dom9, dom12, n:N. Card codes like "AS", "TH", "XR". public string[] Shuffle(string deck = "std52") => ((object[])Draw("s", deck)).Select(x => x.ToString()!).ToArray(); public DealResult Deal(string deck, int hands, int perHand) => (DealResult)Draw("dl", deck, (long)hands, (long)perHand); /// k distinct numbers from offset..offset+n-1, in draw order. public long[] Sample(long n, int k, long offset = 1) => (long[])Draw("p", n, (long)k, offset); public long[] Lotto(int k, int n) => Sample(n, k, 1); public T Pick(IReadOnlyList items) => items[(int)Sample(items.Count, 1, 0)[0]]; public int Weighted(long[] weights) => ((int[])Draw("w", weights, 1L))[0]; public string Bytes(int length = 32) => (string)Draw("b", (long)length); /// Serialized proof JSON (contains the secret seed) - persist it to resume after restarts. public string StateJson() => FairDiceProtocol.ProofJson(ServerSeed, ClientSeed, FirstNonce, _log, Game, Meta, CreatedAt); public Reveal Reveal() { var json = StateJson(); var token = FairDiceProtocol.ToBase64Url(Encoding.UTF8.GetBytes(json)); Revealed = true; return new Reveal { Token = token, Url = $"{BaseUrl}/v/{token}", Commitment = Commitment, Count = Count, ProofJson = json }; } public string Token() => Reveal().Token; /// https://fairdice.ir/v/<token> - share after the game (reveals the seed). public string Url() => Reveal().Url; public string CommitUrl() => $"{BaseUrl}/c/{Commitment}" + (Game != null ? "?g=" + Uri.EscapeDataString(Game) : ""); /// Resume a session from StateJson(). public static FairDice Restore(string stateJson, string? dice = null) { using var doc = JsonDocument.Parse(stateJson); var r = doc.RootElement; Dictionary? meta = null; if (r.TryGetProperty("m", out var m)) { meta = new Dictionary(); foreach (var p in m.EnumerateObject()) meta[p.Name] = p.Value.Clone(); } var fd = new FairDice(new FairDiceOptions { ServerSeed = r.GetProperty("s").GetString(), ClientSeed = r.GetProperty("c").GetString(), Nonce = r.GetProperty("n").GetInt64(), Game = r.TryGetProperty("g", out var g) ? g.GetString() : null, Meta = meta, Dice = dice, KeepHistory = false, }); foreach (var e in r.GetProperty("o").EnumerateArray()) { var code = e[0].GetString()!; var p = e[1].EnumerateArray().Select(Normalize).ToArray(); long times = e[2].GetInt64(); for (long t = 0; t < times; t++) fd.Draw(code, p); } if (r.TryGetProperty("t", out var ts)) fd.CreatedAt = ts.GetInt64(); return fd; } private static object Normalize(JsonElement x) => x.ValueKind switch { JsonValueKind.String => x.GetString()!, JsonValueKind.Number => x.GetInt64(), JsonValueKind.Array => x.EnumerateArray().Select(y => y.GetInt64()).ToArray(), _ => throw new FormatException("unsupported param"), }; public void Dispose() => _mac.Dispose(); } }