Example #1
0
        public static unsafe void GetPublicKey(Span <byte> privateKeyBytes, out Span <byte> publicKeyBytes)
        {
            Span <byte> blsPrivateKey = stackalloc byte[BlsPrivateKeyLength];
            Span <byte> blsPublicKey  = stackalloc byte[BlsPublicKeyLength];

            publicKeyBytes = new byte[PublicKeyLength];

            fixed(byte *privateKeyBytesRef = privateKeyBytes)
            fixed(byte *publicKeyBytesRef = publicKeyBytes)
            fixed(byte *blsPrivateKeyRef  = blsPrivateKey)
            fixed(byte *blsPublicKeyRef   = blsPublicKey)
            {
                DeserializePrivateKey(blsPrivateKeyRef, privateKeyBytesRef);

                switch (Platform)
                {
                case OsPlatform.Windows:
                    Win64Lib.blsGetPublicKey(blsPublicKeyRef, blsPrivateKeyRef);
                    break;

                case OsPlatform.Mac:
                    MacLib.blsGetPublicKey(blsPublicKeyRef, blsPrivateKeyRef);
                    break;

                case OsPlatform.Linux:
                    PosixLib.blsGetPublicKey(blsPublicKeyRef, blsPrivateKeyRef);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(Platform.ToString());
                }

                SerializePublicKey(publicKeyBytesRef, blsPublicKeyRef);
            }
        }