Esempio n. 1
0
        public static bool ValidatePublicKeyRecord(string key, byte[] value)
        {
            if (key.Length < 5)
            {
                return(false);
            }

            var prefix = key.Substring(0, 4);

            if (prefix != "/pk/")
            {
                return(false);
            }

            Multihash mh;

            if (!Multihash.TryParse(key.Substring(4), out mh))
            {
                return(false);
            }

            var pkh = Multihash.Sum <SHA2_256>(value);

            return(mh.Equals(pkh));
        }
Esempio n. 2
0
        public void CanDecodeFromMultibase()
        {
            var hex = Multibase.Base58.Decode("8Vtkv2tdQ43bNGdWN9vNx9GVS9wrbXHk4ZW8kmucPmaYJwwedXir52kti9wJhcik4HehyqgLrQ1hBuirviLhxgRBNv");
            var mb  = Multibase.Base32.Encode(hex);

            Assert.True(Multihash.TryParse(mb, out var mh));
            Assert.Equal(mh.ToBytes(), hex);
        }
Esempio n. 3
0
        public static PeerId Decode(string s)
        {
            Multihash mh;

            return(Multihash.TryParse(s, out mh) ? new PeerId(mh) : new PeerId(Multibase.DecodeRaw <Base16Encoding>(s.ToUpper())));
        }