public BbsPublicKey GeneratePublicKey(uint messageCount) { unsafe { using var context = new UnmanagedMemoryContext(); context.Reference(Key.ToArray(), out var dPublicKey); NativeMethods.bls_public_key_to_bbs_key(&dPublicKey, messageCount, out var publicKey, out var error); error.ThrowIfNeeded(); context.Dereference(publicKey, out var pk); return(new BbsPublicKey { Key = new ReadOnlyCollection <byte>(pk), MessageCount = messageCount }); } }
/// <summary> /// Creates new <see cref="BlsSecretKey"/> using a input seed as byte array. /// </summary> /// <param name="seed">The seed.</param> /// <returns></returns> public static BlsSecretKey Generate(byte[] seed) { using var context = new UnmanagedMemoryContext(); unsafe { context.Reference(seed, out var seed_); var result = NativeMethods.bls_generate_key(&seed_, out var pk, out var sk, out var error); context.Dereference(pk, out var publicKey); context.Dereference(sk, out var secretKey); return(result switch { 0 => new BlsSecretKey { Key = new ReadOnlyCollection <byte>(secretKey) }, _ => throw error.Dereference() });
/// <summary> /// Gets the deterministic public key. /// </summary> /// <returns></returns> public BlsDeterministicPublicKey GetDeterministicPublicKey() { using var context = new UnmanagedMemoryContext(); if (_dPublicKey != null) { return(_dPublicKey); } context.Reference(Key.ToArray(), out var secretKey); unsafe { NativeMethods.bls_get_public_key(&secretKey, out var publicKey, out var error); error.ThrowIfNeeded(); context.Dereference(publicKey, out var pk); return(_dPublicKey = new BlsDeterministicPublicKey { Key = new ReadOnlyCollection <byte>(pk) }); } }