private static string forge_source(string value) { var prefix = value.Substring(0, 3); string res = Base58Check.Decode(value).ToHexString().Substring(6); if (prefix == "tz1") { res = "00" + res; } else if (prefix == "tz2") { res = "01" + res; } else if (prefix == "tz3") { res = "02" + res; } else { throw new Exception($"Value source exception. Invalid prefix {prefix}"); } return(res); }
private static string forge_public_key(string value) { var prefix = value.Substring(0, 4); string res = Base58Check.Decode(value).ToHexString().Substring(8); if (prefix == "edpk") { res = "00" + res; } else if (prefix == "sppk") { res = "01" + res; } else if (prefix == "p2pk") { res = "02" + res; } else { throw new Exception($"Value public_key exception. Invalid prefix {prefix}"); } return(res); }
public static string ForgeAddress(string value) { var prefix = value.Substring(0, 3); string res = Base58Check.Decode(value).ToHexString().Substring(6); if (prefix == "tz1") { res = "0000" + res; } else if (prefix == "tz2") { res = "0001" + res; } else if (prefix == "tz3") { res = "0002" + res; } else if (prefix == "KT1") { res = "01" + res + "00"; } else { throw new Exception($"Value address exception. Invalid prefix {prefix}"); } return(res); }
public static bool CheckAddress(string address, byte[] prefix) { try { Base58Check.Decode(address, prefix); return(true); } catch { return(false); } }
public static string ForgeAddress(string value) { var prefix = value.Substring(0, 3); var res = Base58Check.Decode(value).ToHexString().Substring(6); return(prefix switch { "tz1" => "0000" + res, "tz2" => "0001" + res, "tz3" => "0002" + res, "KT1" => "01" + res + "00", _ => throw new Exception($"Value address exception. Invalid prefix {prefix}") });
public static byte[] Deserialize(Network network, string wif) { var extendedKeyCheck = Base58Check.Decode(wif); var prefix = ExtractPrefix(extendedKeyCheck); var isValidWifForNetwork = network.AddressPrefix.All.Any(p => p.SequenceEqual(prefix.networkPrefix)); if (!isValidWifForNetwork) { throw new InvalidDataException( $"Wif is not valid for network {network.Name}. Unrecognized prefix {Hex.ToHexString(prefix.networkPrefix)}"); } return(extendedKeyCheck.Skip(PrefixLength).Take(KeyLength).ToArray()); }
public void TestEncodeDecode() { // Without checksum string encoded = Base58Check.EncodePlain(testValue); Assert.AreEqual(encoded, testValueEncoded); byte[] decoded = Base58Check.DecodePlain(encoded); CollectionAssert.AreEqual(decoded, testValue); // With checksum encoded = Base58Check.Encode(testValue); Assert.AreEqual(encoded, testValueWithChecksumEncoded); decoded = Base58Check.Decode(encoded); CollectionAssert.AreEqual(decoded, testValue); }
public static JToken ForgeOperationsLocal(string blockHeadHash, JToken operations) { if (!(operations is JArray arrOps)) { arrOps = new JArray(operations); } var res = blockHeadHash != null ? Base58Check.Decode(blockHeadHash, Prefix.b).ToHexString() : ""; foreach (JObject op in arrOps) { switch (op["kind"].ToString()) { case "reveal": res += ForgeReveal(op); break; case "transaction": res += ForgeTransaction(op); break; //todo: //case "activate_account": // res += forge_activate_account(op); // break; //case "origination": // res += forge_origination(op); // break; case "delegation": res += ForgeDelegation(op); break; default: Log.Error("Not implemented forge error"); // break; } } res = res.ToLower(); return(res); }
private async Task <List <OperationResult> > SendOperations( JToken operations, Keys keys, JObject head = null) { if (head == null) { head = await GetHeader() .ConfigureAwait(false); } if (!(operations is JArray arrOps)) { arrOps = new JArray(operations); } var forgedOpGroup = await ForgeOperations(head, arrOps) .ConfigureAwait(false); SignedMessage signedOpGroup; if (keys == null) { signedOpGroup = new SignedMessage { SignedBytes = forgedOpGroup + "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", EncodedSignature = "edsigtXomBKi5CTRf5cjATJWSyaRvhfYNHqSUGrn4SdbYRcGwQrUGjzEfQDTuqHhuA8b2d8NarZjz8TRf65WkpQmo423BtomS8Q" }; } else { var privateKey = Base58Check.Decode(keys.DecryptPrivateKey(), Prefix.Edsk); signedOpGroup = TezosSigner.SignHash( data: Hex.FromString(forgedOpGroup.ToString()), privateKey: privateKey, watermark: Watermark.Generic, isExtendedKey: privateKey.Length == 64); privateKey.Clear(); } var opResults = await PreApplyOperations(head, arrOps, signedOpGroup.EncodedSignature) .ConfigureAwait(false); /////deleting too big contractCode from response //foreach (var opResult in opResults) //{ // if (opResult.Data?["metadata"]?["operation_result"]?["status"]?.ToString() == "failed") // { // foreach (JObject error in opResult.Data["metadata"]["operation_result"]["errors"]) // { // if (error["contractCode"]?.ToString().Length > 1000) // error["contractCode"] = ""; // } // } //} if (opResults.Any() && opResults.All(op => op.Succeeded)) { var injectedOperation = await InjectOperations(signedOpGroup.SignedBytes) .ConfigureAwait(false); opResults.Last().Data["op_hash"] = injectedOperation.ToString(); } return(opResults); }
public void GetPublicKey(out byte[] publicKey) { // todo: dot not store key in heap publicKey = Base58Check.Decode(Keys.DecryptPublicKey(), Prefix.Edpk); }