public void TransactionSigningTest()
        {
            var json = JObject.Parse(TxJson);
            var obj  = StObject.FromJson(json);
            var hex  = obj.ToHex();

            // The MessageBytes includes the HashPrefix
            Assert.AreEqual(MessageBytes.Substring(8), hex);
            Seed seed = Seed.FromPassPhrase("niq").SetEd25519();

            // The ed25519 Signature
            var sig         = seed.KeyPair().Sign(B16.Decode(MessageBytes));
            var expectedSig = ExpectedSig;

            Assert.AreEqual(expectedSig, B16.Encode(sig));
        }
Exemple #2
0
        public static AccountId FromString(string value)
        {
            // TODO No valid addresses should ever fail below condition
            if (value.StartsWith("r") && value.Length >= 26)
            {
                return(FromAddress(value));
            }

            if (value.Length == 160 / 4)
            {
                return(FromAddress(B16.Decode(value)));
            }

            // This is potentially dangerous but fromString in
            // generic sense is used by Amount for parsing strings
            return(AccountForPassPhrase(value));
        }
Exemple #3
0
            public override Vector256 FromJsonArray(JArray jsonArray)
            {
                var vector = new Vector256();

                for (int i = 0; i < jsonArray.Count; i++)
                {
                    try
                    {
                        var hex = jsonArray[i].ToObject <string>();
                        vector.Add(new Hash256(B16.Decode(hex)));
                    }
                    catch (JsonException e)
                    {
                        throw new ApplicationException("Json deserialization failed.", e);
                    }
                }

                return(vector);
            }
Exemple #4
0
            public override Currency FromString(string s)
            {
                if (s.Length == 40)
                {
                    return(NewInstance(B16.Decode(s)));
                }

                if (s == "XRP")
                {
                    return(Xrp);
                }

                if (!Regex.IsMatch(s, "[A-Z0-9]{3}"))
                {
                    throw new ApplicationException("Currency code must be 3 characters.");
                }

                return(NewInstance(EncodeCurrency(s)));
            }
Exemple #5
0
        public static Currency FromString(string str)
        {
            if (str == "XRP")
            {
                return(Xrp);
            }
            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (str.Length)
            {
            case 40:
                return(new Currency(B16.Decode(str)));

            case 3:
                return(new Currency(EncodeCurrency(str)));
            }
            throw new InvalidOperationException(
                      "Currency must either be a 3 letter iso code " +
                      "or a 20 byte hash encoded in hexadecimal"
                      );
        }
 public static Uint64 FromJson(JToken token)
 {
     return(Bits.ToUInt64(B16.Decode(token.ToString()), 0));
 }
Exemple #7
0
 public static Blob FromHex(string value)
 {
     return(B16.Decode(value));
 }
Exemple #8
0
 public static Hash128 FromJson(JToken token)
 {
     return(new Hash128(B16.Decode(token.ToString())));
 }
 public BufferParser(string hex) : this(B16.Decode(hex))
 {
 }
Exemple #10
0
        public TransactionResult(JObject json, Source resultMessageSource)
        {
            Message = json;

            try
            {
                if (resultMessageSource == Source.transaction_subscription_notification)
                {
                    EngineResult = TransactionEngineResult.FromString(json.GetValue("engine_result").ToObject <string>());
                    Validated    = json.GetValue("validated").ToObject <bool>();
                    LedgerHash   = Hash256.OutTranslate.FromString(json.GetValue("ledger_hash").ToObject <string>());
                    LedgerIndex  = new UInt32(json.GetValue("ledger_index").ToObject <long>());

                    JToken transaction;
                    if (json.TryGetValue("transaction", out transaction))
                    {
                        Txn  = (Transaction)StObject.FromJObject(transaction.ToObject <JObject>());
                        Hash = Txn[Hash256.hash];
                    }

                    JToken meta;
                    if (json.TryGetValue("meta", out meta))
                    {
                        Meta = (TransactionMeta)StObject.FromJObject(meta.ToObject <JObject>());
                    }
                }
                else if (resultMessageSource == Source.request_tx_result)
                {
                    JToken validated;
                    Validated = json.TryGetValue("validated", out validated) && validated.ToObject <bool>();

                    JToken meta;
                    if (Validated && !json.TryGetValue("meta", out meta))
                    {
                        throw new InvalidOperationException("It's validated, why doesn't it have meta??");
                    }

                    if (Validated)
                    {
                        Meta         = (TransactionMeta)StObject.FromJObject(json.GetValue("meta").ToObject <JObject>());
                        EngineResult = TransactionEngineResult.FromNumber(Meta[UInt8.TransactionResult]);
                        Txn          = (Transaction)StObject.FromJObject(json);
                        Hash         = Txn[Hash256.hash];
                        LedgerHash   = null; // XXXXXX
                    }
                }
                else if (resultMessageSource == Source.request_account_tx)
                {
                    JToken validated;
                    Validated = json.TryGetValue("validated", out validated) && validated.ToObject <bool>();

                    JToken meta;
                    if (Validated && !json.TryGetValue("meta", out meta))
                    {
                        throw new InvalidOperationException("It's validated, why doesn't it have meta??");
                    }

                    if (Validated)
                    {
                        var tx = json.GetValue("tx").ToObject <JObject>();
                        Meta         = (TransactionMeta)StObject.FromJObject(json.GetValue("meta").ToObject <JObject>());
                        EngineResult = TransactionEngineResult.FromNumber(Meta[UInt8.TransactionResult]);
                        Txn          = (Transaction)StObject.FromJObject(tx);
                        Hash         = Txn[Hash256.hash];
                        LedgerIndex  = new UInt32(tx.GetValue("ledger_index").ToObject <long>());
                        LedgerHash   = null;
                    }
                }
                else if (resultMessageSource == Source.request_account_tx_binary)
                {
                    JToken validated;
                    Validated = json.TryGetValue("validated", out validated) && validated.ToObject <bool>();

                    JToken meta;
                    if (Validated && !json.TryGetValue("meta", out meta))
                    {
                        throw new InvalidOperationException("It's validated, why doesn't it have meta??");
                    }

                    if (Validated)
                    {
                        /*
                         * {
                         *  "ledger_index": 3378767,
                         *  "meta": "201 ...",
                         *  "tx_blob": "120 ...",
                         *  "validated": true
                         * },
                         */

                        var    tx        = json.GetValue("tx_blob").ToObject <string>();
                        byte[] decodedTx = B16.Decode(tx);
                        Meta = (TransactionMeta)StObject.OutTranslate.FromHex(json.GetValue("meta").ToObject <string>());
                        Txn  = (Transaction)StObject.OutTranslate.FromBytes(decodedTx);
                        Hash = Hash256.TransactionId(decodedTx);
                        Txn.Add(Field.hash, Hash);

                        EngineResult = Meta.TransactionResult();
                        LedgerIndex  = new UInt32(json.GetValue("ledger_index").ToObject <long>());
                        LedgerHash   = null;
                    }
                }
            }
            catch (JsonException e)
            {
                throw new ApplicationException("Json deserialization failed.", e);
            }
        }
 public static Hash256 FromHex(string token)
 {
     return(new Hash256(B16.Decode(token)));
 }
Exemple #12
0
 public TOut FromHex(string hex)
 {
     return(FromBytes(B16.Decode(hex)));
 }
Exemple #13
0
 public override T FromString(string s)
 {
     return(NewInstance(B16.Decode(s)));
 }
 public BinaryParser(string hex)
     : this(B16.Decode(hex))
 {
 }