public static bool TryFromScript(byte[] script, out SecSchnorrPubKeyHash pubKeyHash) { if (script == null) { throw new ArgumentNullException(nameof(script)); } var isSecSchnorrPubKeyHash = 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.SecSchnorrPushData && script[25] == (byte)Opcode.OpChecksigAlt; if (!isSecSchnorrPubKeyHash) { pubKeyHash = null; return(false); } var hash160 = new byte[Ripemd160Hash.Length]; Array.Copy(script, 3, hash160, 0, Ripemd160Hash.Length); pubKeyHash = new SecSchnorrPubKeyHash(script, hash160); return(true); }
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)); }
public static bool TryFromScript(byte[] script, out SecSchnorrPubKeyHash pubKeyHash) { if (script == null) throw new ArgumentNullException(nameof(script)); var isSecSchnorrPubKeyHash = 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.SecSchnorrPushData && script[25] == (byte)Opcode.OpChecksigAlt; if (!isSecSchnorrPubKeyHash) { pubKeyHash = null; return false; } var hash160 = new byte[Ripemd160Hash.Length]; Array.Copy(script, 3, hash160, 0, Ripemd160Hash.Length); pubKeyHash = new SecSchnorrPubKeyHash(script, hash160); return true; }