public void Signature(byte[] privatekey) { ECKey ec_key = ECKey.FromPrivateKey(privatekey); ECDSASignature signature = ec_key.Sign(GetRawHash().Hash); this.transaction.Signature.Add(ByteString.CopyFrom(signature.ToByteArray())); }
public void AddSignature(byte[] privatekey, AccountStore account_store) { Transaction.Types.Contract contract = this.transaction.RawData.Contract[0]; byte[] owner = GetOwner(contract); int permission_id = contract.PermissionId; AccountCapsule account = account_store.Get(owner); if (account == null) { throw new PermissionException("Account is not exist."); } Permission permission = account.GetPermissionById(permission_id); if (permission == null) { throw new PermissionException("Permission is not exist"); } if (permission_id != 0) { if (permission.Type != Permission.Types.PermissionType.Active) { throw new PermissionException("Permission type is error"); } if (Wallet.CheckPermissionOperations(permission, contract)) { throw new PermissionException("Invalid permission"); } } List <ByteString> approves = new List <ByteString>(); ECKey ec_key = ECKey.FromPrivateKey(privatekey); byte[] address = Wallet.PublickKeyToAddress(ec_key.PublicKey); if (this.transaction.Signature.Count > 0) { CheckWeight(permission, new List <ByteString>(this.transaction.Signature), this.GetRawHash().Hash, approves); if (approves.Contains(ByteString.CopyFrom(address))) { throw new PermissionException(Wallet.AddressToBase58(address) + "had signed!"); } } long weight = GetWeight(permission, address); if (weight == 0) { throw new PermissionException( privatekey.ToHexString() + " address is " + Wallet.AddressToBase58(address) + "but it is not contained of permission."); } ECDSASignature signature = ec_key.Sign(this.GetRawHash().Hash); this.transaction.Signature.Add(ByteString.CopyFrom(signature.ToByteArray())); }
public void IsValidPrivateKey() { ECKey key = ECKey.FromPrivateKey(privatekey); this.privatekey.SequenceEqual(key.PrivateKey).Should().BeTrue(); this.publickey.SequenceEqual(key.PublicKey).Should().BeTrue(); }
public void Init() { if (Args.Instance.LocalWitness.GetPrivateKey().IsNullOrEmpty()) { return; } byte[] privatekey = Args.Instance.LocalWitness.GetPrivateKey(); byte[] witness_address = Args.Instance.LocalWitness.GetWitnessAccountAddress(); byte[] privatekey_address = Wallet.PublickKeyToAddress(ECKey.FromPrivateKey(privatekey).PublicKey); WitnessCapsule witness = Manager.Instance.DBManager.Witness.Get(witness_address); if (witness == null) { Logger.Warning( string.Format("WitnessCapsule[{0}] is not in witnessStore", witness_address)); witness = new WitnessCapsule(ByteString.CopyFrom(witness_address)); } this.privatekeys.Add(witness.Address, privatekey); this.local_witness_states.Add(witness.Address, witness); this.privatekey_addresses.Add(privatekey, privatekey_address); }
public void Sign(byte[] privatekey) { ECKey ec_key = ECKey.FromPrivateKey(privatekey); ECDSASignature signature = ec_key.Sign(this.GetRawHash().Hash); this.block.BlockHeader.WitnessSignature = ByteString.CopyFrom(signature.ToByteArray()); }
public void InitWitnessAccountAddress() { if (this.witness_account_address == null) { ECKey key = ECKey.FromPrivateKey(GetPrivateKey()); this.witness_account_address = Wallet.PublickKeyToAddress(key.PublicKey); } }
public void Signature() { ECKey key = ECKey.FromPrivateKey(this.privatekey); ECDSASignature signature = key.Sign(signature_message); signature.Should().NotBeNull(); key.Verify(signature_message, signature).Should().BeTrue(); }
public void RecoverySignature() { ECKey key = ECKey.FromPrivateKey(this.privatekey); ECDSASignature signature = key.Sign(signature_message); signature.Should().NotBeNull(); key.Verify(signature_message, signature).Should().BeTrue(); ECKey.RecoverFromSignature(signature, signature_message, false).PublicKey.SequenceEqual(key.PublicKey).Should().BeTrue(); }
public byte[] GetWitnessAccountAddress() { if (this.witness_account_address == null) { byte[] privatekey = GetPrivateKey(); if (privatekey.IsNotNullOrEmpty()) { ECKey key = ECKey.FromPrivateKey(privatekey); this.witness_account_address = Wallet.PublickKeyToAddress(key.PublicKey); } } return(this.witness_account_address); }
public static RpcApiResult ImportWallet(string password, string privatekey) { if (password.IsNullOrEmpty() || privatekey.IsNullOrEmpty()) { Console.WriteLine("Invalide password and privatekey"); return(new RpcApiResult(false, RpcMessage.INVALID_PASSWORD, "Invalide password and privatekey")); } try { byte[] pk = privatekey.HexToBytes(); if (pk.Length != 32) { return(new RpcApiResult(false, RpcMessage.INVALID_PRIVATEKEY, "Invalid privatekey. Privatekey must be 32 bytes.")); } ECKey key = ECKey.FromPrivateKey(pk); string address = Wallet.AddressToBase58(Wallet.PublickKeyToAddress(key.PublicKey)); if (!KeyStoreService.GenerateKeyStore(RpcApi.FILE_PATH, password, pk, address, out _)) { Console.WriteLine(); return(new RpcApiResult(false, RpcMessage.INTERNAL_ERROR, "Faild to generate keystore file.")); } } catch (System.Exception e) { throw e; } return(RpcApiResult.Success); }
public void TestSetup() { this.key = ECKey.FromPrivateKey(privatekey); }