Пример #1
0
        public HdPubKey(PubKey pubKey, KeyPath fullKeyPath, SmartLabel label, KeyState keyState)
        {
            PubKey      = Guard.NotNull(nameof(pubKey), pubKey);
            FullKeyPath = Guard.NotNull(nameof(fullKeyPath), fullKeyPath);
            _cluster    = new Cluster(this);
            SetLabel(label, null);
            KeyState = keyState;

            P2pkScript           = PubKey.ScriptPubKey;
            P2pkhScript          = PubKey.Hash.ScriptPubKey;
            P2wpkhScript         = PubKey.WitHash.ScriptPubKey;
            P2shOverP2wpkhScript = P2wpkhScript.Hash.ScriptPubKey;

            PubKeyHash = PubKey.Hash;
            HashCode   = PubKeyHash.GetHashCode();

            Index = (int)FullKeyPath.Indexes[4];
            NonHardenedKeyPath = new KeyPath(FullKeyPath[3], FullKeyPath[4]);

            int change = (int)FullKeyPath.Indexes[3];

            if (change == 0)
            {
                IsInternal = false;
            }
            else if (change == 1)
            {
                IsInternal = true;
            }
            else
            {
                throw new ArgumentException(nameof(FullKeyPath));
            }
        }
Пример #2
0
        public static OutputScript ParseScript(byte[] script)
        {
            PubKeyHash pubKeyHash;

            if (PubKeyHash.TryFromScript(script, out pubKeyHash))
            {
                return(pubKeyHash);
            }

            ScriptHash scriptHash;

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

            PubKey pubKey;

            if (PubKey.TryFromScript(script, out pubKey))
            {
                return(pubKey);
            }

            return(new Unrecognized(script));
        }
Пример #3
0
            public static bool TryFromScript(byte[] script, out PubKeyHash pubKeyHash)
            {
                if (script == null)
                {
                    throw new ArgumentNullException(nameof(script));
                }

                var isPubKeyHash =
                    script.Length == 25 &&
                    script[0] == (byte)Opcode.OpDup &&
                    script[1] == (byte)Opcode.OpHash160 &&
                    script[2] == (byte)Opcode.OpData20 &&
                    script[23] == (byte)Opcode.OpEqualVerify &&
                    script[24] == (byte)Opcode.OpChecksig;

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

                var hash160 = new byte[Ripemd160Hash.Length];

                Array.Copy(script, 3, hash160, 0, Ripemd160Hash.Length);
                pubKeyHash = new PubKeyHash(script, hash160);
                return(true);
            }
Пример #4
0
            public static bool TryFromScript(byte[] script, out PubKeyHash pubKeyHash)
            {
                if (script == null)
                    throw new ArgumentNullException(nameof(script));

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

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