示例#1
0
            public static bool TryFromScript(byte[] script, out Ed25519PubKeyHash pubKeyHash)
            {
                if (script == null)
                {
                    throw new ArgumentNullException(nameof(script));
                }

                var isEd25519PubKeyHash =
                    script.Length == ScriptLength &&
                    script[0] == (byte)Opcode.OpDup &&
                    script[1] == (byte)Opcode.OpHash160 &&
                    script[2] == (byte)Opcode.OpData20 &&
                    script[23] == (byte)Opcode.OpEqualVerify &&
                    script[24] == SignatureAlgorithm.Ed25519PushData &&
                    script[25] == (byte)Opcode.OpChecksigAlt;

                if (!isEd25519PubKeyHash)
                {
                    pubKeyHash = null;
                    return(false);
                }

                var hash160 = new byte[Ripemd160Hash.Length];

                Array.Copy(script, 3, hash160, 0, Ripemd160Hash.Length);
                pubKeyHash = new Ed25519PubKeyHash(script, hash160);
                return(true);
            }
示例#2
0
        public static OutputScript ParseScript(byte[] script)
        {
            Secp256k1PubKeyHash secp256k1PubKeyHash;

            if (Secp256k1PubKeyHash.TryFromScript(script, out secp256k1PubKeyHash))
            {
                return(secp256k1PubKeyHash);
            }

            Ed25519PubKeyHash ed25519PubKeyHash;

            if (Ed25519PubKeyHash.TryFromScript(script, out ed25519PubKeyHash))
            {
                return(ed25519PubKeyHash);
            }

            SecSchnorrPubKeyHash secSchnorrPubKeyHash;

            if (SecSchnorrPubKeyHash.TryFromScript(script, out secSchnorrPubKeyHash))
            {
                return(secSchnorrPubKeyHash);
            }

            ScriptHash scriptHash;

            if (ScriptHash.TryFromScript(script, out scriptHash))
            {
                return(scriptHash);
            }

            return(new Unrecognized(script));
        }
示例#3
0
            public static bool TryFromScript(byte[] script, out Ed25519PubKeyHash pubKeyHash)
            {
                if (script == null)
                    throw new ArgumentNullException(nameof(script));

                var isEd25519PubKeyHash =
                    script.Length == ScriptLength &&
                    script[0] == (byte)Opcode.OpDup &&
                    script[1] == (byte)Opcode.OpHash160 &&
                    script[2] == (byte)Opcode.OpData20 &&
                    script[23] == (byte)Opcode.OpEqualVerify &&
                    script[24] == SignatureAlgorithm.Ed25519PushData &&
                    script[25] == (byte)Opcode.OpChecksigAlt;
                if (!isEd25519PubKeyHash)
                {
                    pubKeyHash = null;
                    return false;
                }

                var hash160 = new byte[Ripemd160Hash.Length];
                Array.Copy(script, 3, hash160, 0, Ripemd160Hash.Length);
                pubKeyHash = new Ed25519PubKeyHash(script, hash160);
                return true;
            }