Exemple #1
0
 /// <summary>
 /// Returns this seed value in the XRP Ledger's base58-encoded format.
 /// </summary>
 /// <returns>
 /// This seed value in the XRP Ledger's base58-encoded format.
 /// </returns>
 public override string ToString()
 {
     if (_type == KeyType.Secp256k1)
     {
         Span <byte> content = stackalloc byte[17];
         content[0] = 0x21;
         UnsafeAsSpan(ref this).CopyTo(content.Slice(1));
         return(Base58Check.ConvertTo(content));
     }
     else
     {
         Span <byte> content = stackalloc byte[19];
         content[0] = 0x01;
         content[1] = 0xE1;
         content[2] = 0x4B;
         UnsafeAsSpan(ref this).CopyTo(content.Slice(3));
         return(Base58Check.ConvertTo(content));
     }
 }
Exemple #2
0
        public Seed(string base58) : this()
        {
            Span <byte> content = stackalloc byte[19];

            Base58Check.ConvertFrom(base58, content);
            if (content[0] == 0x21)
            {
                _type = KeyType.Secp256k1;
                content.Slice(1, 16).CopyTo(UnsafeAsSpan(ref this));
            }
            else if (content[0] == 0x01 && content[1] == 0xE1 && content[2] == 0x4B)
            {
                _type = KeyType.Ed25519;
                content.Slice(3, 16).CopyTo(UnsafeAsSpan(ref this));
            }
            else
            {
                throw new Exception("Expected prefix of either 0x21 or 0x01, 0xE1, 0x4B");
            }
        }