public async Task CreatePrivateKey() { // FIXME: passphrase로 "passphrase" 대신 랜덤 문자열을 사용하면 좋을 것 같습니다. var result = await ExecuteQueryAsync( "mutation { keyStore { createPrivateKey(passphrase: \"passphrase\") { publicKey { address } } } }"); var createdPrivateKeyAddress = result.Data.As <Dictionary <string, object> >()["keyStore"] .As <Dictionary <string, object> >()["createPrivateKey"] .As <Dictionary <string, object> >()["publicKey"] .As <Dictionary <string, object> >()["address"].As <string>(); Assert.Contains(KeyStore.List(), t => t.Item2.Address.ToString() == createdPrivateKeyAddress); }
public WalletManager(BlockChain.BlockChain blockChain, string dbName) { _BlockChain = blockChain; _DBContext = new DBContext(dbName); _KeyStore = new KeyStore(); _TxStore = new TxStore(); TxDeltaList = new List <TxDelta>(); _BlockChainListener = new EventLoopMessageListener <BlockChainMessage>(OnBlockChainMessage, "Wallet Consumer"); OwnResource(MessageProducer <BlockChainMessage> .Instance.AddMessageListener(_BlockChainListener)); OwnResource(_DBContext); using (var dbTx = _DBContext.GetTransactionContext()) { _Keys = _KeyStore.List(dbTx); var purgeList = new List <ulong>(); _TxStore.All(dbTx).ToList().ForEach(item => { switch (item.Item2.TxState) { case TxStateEnum.Confirmed: TxDeltaList.Add(new TxDelta(item.Item2.TxState, item.Item2.TxHash, item.Item2.Tx, item.Item2.AssetDeltas, item.Item2.DateTime)); break; case TxStateEnum.Unconfirmed: purgeList.Add(item.Item1); //TODO: implement 'smarter' mode: only after the node has been synced and is up-to-date, try to revalidate //_BlockChain.HandleTransaction(txData.Tx); break; } foreach (var key in purgeList) { _TxStore.Remove(dbTx, key); } }); } }
public async Task CreatePrivateKeyWithGivenPrivateKey() { // FIXME: passphrase로 "passphrase" 대신 랜덤 문자열을 사용하면 좋을 것 같습니다. var privateKey = new PrivateKey(); var privateKeyHex = ByteUtil.Hex(privateKey.ByteArray); var result = await ExecuteQueryAsync( $"mutation {{ keyStore {{ createPrivateKey(passphrase: \"passphrase\", privateKey: \"{privateKeyHex}\") {{ hex publicKey {{ address }} }} }} }}"); var privateKeyResult = result.Data.As <Dictionary <string, object> >()["keyStore"] .As <Dictionary <string, object> >()["createPrivateKey"] .As <Dictionary <string, object> >(); var createdPrivateKeyHex = privateKeyResult .As <Dictionary <string, object> >()["hex"].As <string>(); var createdPrivateKeyAddress = privateKeyResult .As <Dictionary <string, object> >()["publicKey"] .As <Dictionary <string, object> >()["address"].As <string>(); Assert.Equal(privateKey, new PrivateKey(ByteUtil.ParseHex(createdPrivateKeyHex))); Assert.Contains(KeyStore.List(), t => t.Item2.Address.ToString() == createdPrivateKeyAddress); }
public async Task RevokePrivateKey() { var privateKey = new PrivateKey(); var passphrase = ""; var protectedPrivateKey = ProtectedPrivateKey.Protect(privateKey, passphrase); KeyStore.Add(protectedPrivateKey); var address = privateKey.ToAddress(); var result = await ExecuteQueryAsync( $"mutation {{ keyStore {{ revokePrivateKey(address: \"{address.ToHex()}\") {{ address }} }} }}"); var revokedPrivateKeyAddress = result.Data.As <Dictionary <string, object> >()["keyStore"] .As <Dictionary <string, object> >()["revokePrivateKey"] .As <Dictionary <string, object> >()["address"].As <string>(); Assert.DoesNotContain(KeyStore.List(), t => t.Item2.Address.ToString() == revokedPrivateKeyAddress); Assert.Equal(address.ToString(), revokedPrivateKeyAddress); }