public static string ArrayBuilder(string arrayName, IKeyPair keyPair, int keyCount) { var stringBuilder = new StringBuilder("new[] { "); for (var i = 0; i < keyPair.LowKey; i++) { stringBuilder.Append(arrayName + "[" + i + "], "); } stringBuilder.Append(arrayName + "[" + keyPair.HiKey + "], "); for (var i = keyPair.LowKey + 1; i < keyPair.HiKey; i++) { stringBuilder.Append(arrayName + "[" + i + "], "); } stringBuilder.Append((keyPair.HiKey == keyCount - 1) ? arrayName + "[" + keyPair.LowKey + "] " : arrayName + "[" + keyPair.LowKey + "], "); for (var i = keyPair.HiKey + 1; i < keyCount; i++) { stringBuilder.Append(arrayName + "[" + i + "]" + ((i == keyCount - 1) ? "" : ", ")); } return(stringBuilder.Append(" }").ToString()); }
public Transaction GenerateCustomTransaction(IKeyPair owner, ProofOfWork pow, Chain chain, Func<byte[]> scriptGenerator) { var script = scriptGenerator(); var tx = MakeTransaction(owner, pow, chain, script); return tx; }
public static String ComputeAddress(String secret) { byte[] pubBytes = null; IKeyPair keyPair = Seed.GetKeyPair(secret); pubBytes = HashUtils.SHA256_RIPEMD160(keyPair.Pub.ToByteArray()); return(Config.GetB58IdentiferCodecs().EncodeAddress(pubBytes)); }
// Starting Xrp Balance/Lines/Offers etc private TestAccount(string alias, AccountId id, IKeyPair keyPair, string secret) { Id = id; Secret = secret; SetSigningKey(keyPair); NextSequence = 1; Alias = alias; }
public static ISorterStager AppendKeyPair(this ISorterStager sorterStager, IKeyPair keyPair) { return (sorterStager.Current.KeyPairs.Any(kp => kp.Overlaps(keyPair)) ? new SorterStagerImpl(sorterStager.Current, SorterStage.Empty) : new SorterStagerImpl(sorterStager.Current, sorterStager.Current.AppendKeyPair(keyPair))); }
public IEnumerator SignAndSendTransactionWithPayload(IKeyPair keys, string nexus, byte[] script, string chain, byte[] payload, Action <string> callback, Action <EPHANTASMA_SDK_ERROR_TYPE, string> errorHandlingCallback = null, Func <byte[], byte[], byte[], byte[]> customSignFunction = null) { Log.Write("Sending transaction..."); var tx = new Blockchain.Transaction(nexus, chain, script, DateTime.UtcNow + TimeSpan.FromMinutes(20), payload); tx.Sign(keys, customSignFunction); yield return(SendRawTransaction(Base16.Encode(tx.ToByteArray(true)), callback, errorHandlingCallback)); }
public static bool Overlaps(this IKeyPair lhs, IKeyPair rhs) { return((lhs.LowKey == rhs.LowKey) || (lhs.LowKey == rhs.HiKey) || (lhs.HiKey == rhs.LowKey) || (lhs.HiKey == rhs.HiKey)); }
public static ConfigurationValue FromKey(IKeyPair keyPair) { var bytes = keyPair.AsBinaryData(); return(new ConfigurationValue { Type = ConfigurationValueType.Bytes, BytesValue = bytes, Value = bytes }); }
//switchExpr = a => ((a & Mask0To1) == CShift0) ? new Tuple<ushort, bool>((ushort) (a^Mask0To1), true) : new Tuple<ushort, bool>(a, false); public static string SwitchExpression(string dataType, IKeyPair keyPair) { return(String.Format ( "new Func<{3}, Tuple<{3}, bool>>({0} => (({0} & {1}) == {2}) ? new Tuple<{3}, bool>(({3}) ({0} ^ {1}), true) : new Tuple<{3}, bool>({0}, false))", "a", KeyPairMaskName(keyPair), ShiftName(keyPair.LowKey), dataType )); }
public void testDerivationFromString() { IKeyPair keyPairFromSeed = AccountId.KeyPairFromSeed(TestFixtures.MasterSeed); Assert.AreEqual( "0330E7FC9D56BB25D6893BA3F317AE5BCF33B3291BD63DB32654A313222F7FD020", keyPairFromSeed.PubHex()); Assert.AreEqual( "1ACAAEDECE405B2A958212629E16F2EB46B153EEE94CDD350FDEFF52795525B7", keyPairFromSeed.PrivHex()); }
static KeyPairRepository() { keyPairs = new IKeyPair[KeyPairSetSizeForKeyCount(MaxKeyCount)]; for (var hiKey = 1; hiKey < MaxKeyCount; hiKey++) { for (var lowKey = 0; lowKey < hiKey; lowKey++) { var keyPairIndex = KeyPairIndex(lowKey, hiKey); keyPairs[keyPairIndex] = new KeyPair(keyPairIndex, lowKey, hiKey); } } }
public SwitchGraphicVm ( IKeyPair keyPair, int keyCount, List <Brush> lineBrushes, int width ) { _keyPair = keyPair; _keyCount = keyCount; _lineBrushes = lineBrushes; _width = width; }
public static ECDsaSignature Generate(IKeyPair keypair, byte[] message, ECDsaCurve curve) { Throw.If(curve != ECDsaCurve.Secp256r1, "curve support not implemented for " + curve); if (keypair.PublicKey.Length != 33) { throw new System.Exception("public key must be 33 bytes"); } var signature = CryptoExtensions.SignECDsa(message, keypair.PrivateKey, keypair.PublicKey); return(new ECDsaSignature(signature, curve)); }
private static IKeyPair ExtractKeyPair(PrivateKeyFileDataReader privateKeySectionReader) { var keyType = privateKeySectionReader.ReadString(Encoding.UTF8); IKeyPair keyPair = null; if (keyType == KeyTypes.ED25519) { var publicKey = privateKeySectionReader.ReadBytes(privateKeySectionReader.ReadInt32()); privateKeySectionReader.ReadInt32(); //length of private + public key var privateKey = privateKeySectionReader.ReadBytes(32); privateKeySectionReader.ReadBytes(32); //public key (again) var comment = privateKeySectionReader.ReadString(Encoding.UTF8); keyPair = new Ed25519KeyPair(comment, publicKey, privateKey); } else if (keyType == KeyTypes.RSA) { var n = privateKeySectionReader.ReadBigInteger(); //Modulus var e = privateKeySectionReader.ReadBigInteger(); //Public Exponent var d = privateKeySectionReader.ReadBigInteger(); //Private Exponent var iqmp = privateKeySectionReader.ReadBigInteger(); //q^-1 mod p var p = privateKeySectionReader.ReadBigInteger(); //Prime 1 var q = privateKeySectionReader.ReadBigInteger(); //Prime 2 var comment = privateKeySectionReader.ReadString(Encoding.UTF8); keyPair = new RsaKeyPair(comment, n, e, d, iqmp, p, q); } else if (keyType == KeyTypes.ECDSA256 || keyType == KeyTypes.ECDSA384 || keyType == KeyTypes.ECDSA521) { int curveLength = privateKeySectionReader.ReadInt32(); var curve = Encoding.ASCII.GetString(privateKeySectionReader.ReadBytes(curveLength)); var publicKey = privateKeySectionReader.ReadBytes(privateKeySectionReader.ReadInt32()); var privateKey = privateKeySectionReader.ReadBytes(privateKeySectionReader.ReadInt32()); var comment = privateKeySectionReader.ReadString(Encoding.UTF8); keyPair = new EcdsaKeyPair(keyType, comment, curve, publicKey, privateKey); } else if (keyType == KeyTypes.DSA) { var p = privateKeySectionReader.ReadBigInteger(); var q = privateKeySectionReader.ReadBigInteger(); var g = privateKeySectionReader.ReadBigInteger(); var y = privateKeySectionReader.ReadBigInteger(); var x = privateKeySectionReader.ReadBigInteger(); var comment = privateKeySectionReader.ReadString(Encoding.UTF8); keyPair = new DsaKeyPair(comment, p, q, g, y, x); } else { throw new OpenSshKeyParseException($"key type '{keyType}' is not supported by this parser"); } return(keyPair); }
public void Sign(IKeyPair keypair, Func <byte[], byte[], byte[], byte[]> customSignFunction = null) { Throw.If(keypair == null, "invalid keypair"); var msg = this.ToByteArray(false); Signature sig = keypair.Sign(msg, customSignFunction); var sigs = new List <Signature>(); if (this.Signatures != null && this.Signatures.Length > 0) { sigs.AddRange(this.Signatures); } sigs.Add(sig); this.Signatures = sigs.ToArray(); }
public void Prepare(IKeyPair keyPair, Amount fee, UInt32 sequence, UInt32 lastLedgerSequence) { // This won't always be specified if (lastLedgerSequence != null) { Txn.Add(UInt32.LastLedgerSequence, lastLedgerSequence); } Txn.Add(UInt32.Sequence, sequence); Txn.Add(Amount.Fee, fee); Txn.Add(VariableLength.SigningPubKey, keyPair.PubBytes()); if (Transaction.CanonicalFlagDeployed) { Txn.SetCanonicalSignatureFlag(); } SigningHash = Txn.SigningHash(); if (PreviousSigningHash != null && SigningHash.Equals(PreviousSigningHash)) { return; } try { byte[] signature = keyPair.Sign(SigningHash.Bytes); Txn.Add(VariableLength.TxnSignature, signature); var blob = new BytesList(); Hash256.HalfSha512 id = Hash256.Prefixed256(HashPrefix.TransactionId); Txn.ToBytesSink(new MultiSink(blob, id)); TxBlob = blob.BytesHex(); Hash = id.Finish(); } catch (Exception e) { // electric paranoia PreviousSigningHash = null; throw new ApplicationException("Something went wrong.", e); } PreviousSigningHash = SigningHash; }
public static ECDsaSignature Generate(IKeyPair keypair, byte[] message, ECDsaCurve curve, Func <byte[], byte[], byte[], byte[]> customSignFunction = null) { if (keypair.PublicKey.Length != 32 && keypair.PublicKey.Length != 33 && keypair.PublicKey.Length != 64) { throw new System.Exception($"public key must be 32, 33 or 64 bytes, given key's length: {keypair.PublicKey.Length}"); } byte[] signature; if (customSignFunction != null) { signature = customSignFunction(message, keypair.PrivateKey, keypair.PublicKey); } else { signature = CryptoExtensions.SignECDsa(message, keypair.PrivateKey, keypair.PublicKey, curve); } return(new ECDsaSignature(signature, curve)); }
public static Address FromKey(IKeyPair key) { var bytes = new byte[LengthInBytes]; bytes[0] = (byte)AddressKind.User; if (key.PublicKey.Length == 32) { ByteArrayUtils.CopyBytes(key.PublicKey, 0, bytes, 2, 32); } else if (key.PublicKey.Length == 33) { ByteArrayUtils.CopyBytes(key.PublicKey, 0, bytes, 1, 33); } else { throw new Exception("Invalid public key length"); } return(new Address(bytes)); }
private Wallet(string address, string secret) { Address = address; Secret = secret; _keyPair = Seed.GetKeyPair(secret); }
protected RecordHandler(IKeyPair secureConnection, TlsVersion recordVersion, IPipeWriter output) { _recordVersion = recordVersion; _connection = secureConnection; _output = output; }
public static Ed25519Signature Generate(IKeyPair keypair, byte[] message) { var sign = Ed25519.Sign(message, Ed25519.ExpandedPrivateKeyFromSeed(keypair.PrivateKey)); return(new Ed25519Signature(sign)); }
public KeyPairVm(IKeyPair keyPair, Brush switchBrush, int position) { _switchBrush = switchBrush; _position = position; _keyPair = keyPair; }
private void SetSigningKey(IKeyPair keyPair) { KeyPair = keyPair; Signer = TxSigner.FromKeyPair(keyPair); }
public DependentKeyPair(IKeyPair keyPair) { _keyPair = keyPair; IsUsed = IsDisabled = false; }
private Transaction MakeTransaction(IKeyPair source, ProofOfWork pow, Chain chain, byte[] script) { return(MakeTransaction(new IKeyPair[] { source }, pow, chain, script)); }
public static TxSigner FromKeyPair(IKeyPair keyPair) { return new TxSigner(keyPair); }
public static byte[] PubKeyHash(this IKeyPair pair) { return(HashUtils.PublicKeyHash(pair.CanonicalPubBytes())); }
public void Sign(IKeyPair keys) { var msg = this.ToByteArray(false); this.Signature = keys.Sign(msg); }
public static TxSigner FromKeyPair(IKeyPair keyPair) { return(new TxSigner(keyPair)); }
private TxSigner(IKeyPair keyPair) { _keyPair = keyPair; }
public Transaction GenerateCustomTransaction(IKeyPair owner, ProofOfWork pow, Func <byte[]> scriptGenerator) { return(GenerateCustomTransaction(owner, pow, Nexus.RootChain, scriptGenerator)); }