public Guid Add(ProtectedPrivateKey key) { Guid guid = Guid.NewGuid(); _protectedPrivateKeys.Add(guid, key); return(guid); }
public void Remove_WithNoPassphrase(string passphrase, string inputPassphrase) { PrivateKey privateKey = new PrivateKey(); Guid keyId = _keyStore.Add(ProtectedPrivateKey.Protect(privateKey, passphrase)); Assert.Contains(keyId, _keyStore.ListIds()); _keyCommand.Remove(keyId, passphrase: inputPassphrase, noPassphrase: true); Assert.DoesNotContain(keyId, _keyStore.ListIds()); }
public RandomContractTxSource(IList <IRandomContract> contracts, IEciesCipher eciesCipher, ProtectedPrivateKey cryptoKey, ICryptoRandom cryptoRandom) { _contracts = contracts ?? throw new ArgumentNullException(nameof(contracts)); _eciesCipher = eciesCipher ?? throw new ArgumentNullException(nameof(eciesCipher)); _cryptoKey = cryptoKey ?? throw new ArgumentNullException(nameof(cryptoKey)); _random = cryptoRandom; }
public RandomContractTxSource( IList <IRandomContract> contracts, IEciesCipher eciesCipher, ProtectedPrivateKey cryptoKey, ICryptoRandom cryptoRandom, ILogManager logManager) { _contracts = contracts ?? throw new ArgumentNullException(nameof(contracts)); _eciesCipher = eciesCipher ?? throw new ArgumentNullException(nameof(eciesCipher)); _cryptoKey = cryptoKey ?? throw new ArgumentNullException(nameof(cryptoKey)); _random = cryptoRandom ?? throw new ArgumentNullException(nameof(cryptoRandom)); _logger = logManager?.GetClassLogger <RandomContractTxSource>() ?? throw new ArgumentNullException(nameof(logManager)); }
private void CreateProtectedPrivateKey(PrivateKey privateKey) { var ppk = ProtectedPrivateKey.Protect(privateKey, passPhraseField.text); KeyStore.Add(ppk); _privateKey = privateKey; //[TentuPlay] 가입 기록 TPStashEvent MyStashEvent = new TPStashEvent(); MyStashEvent.Join(player_uuid: _privateKey.PublicKey.ToAddress().ToHex()); MyStashEvent.PlayerLogin(player_uuid: _privateKey.PublicKey.ToAddress().ToHex()); }
public RandomContractTxSource( IList <IRandomContract> contracts, IEciesCipher eciesCipher, ISigner signer, ProtectedPrivateKey previousCryptoKey, // this is for backwards-compability when upgrading validator node ICryptoRandom cryptoRandom, ILogManager logManager) { _contracts = contracts ?? throw new ArgumentNullException(nameof(contracts)); _eciesCipher = eciesCipher ?? throw new ArgumentNullException(nameof(eciesCipher)); _signer = signer ?? throw new ArgumentNullException(nameof(signer)); _previousCryptoKey = previousCryptoKey ?? throw new ArgumentNullException(nameof(previousCryptoKey)); _random = cryptoRandom ?? throw new ArgumentNullException(nameof(cryptoRandom)); _logger = logManager?.GetClassLogger <RandomContractTxSource>() ?? throw new ArgumentNullException(nameof(logManager)); }
public void Load() { string idStr = "c8b0c0b1-82a0-41cd-9528-a22a0f208dee"; Guid id = Guid.Parse(idStr); var path = Path.Combine(KeyStore.Path, $"UTC--2020-03-23T00-00-00Z--{idStr}"); var key = new PrivateKey(); ProtectedPrivateKey ppk = ProtectedPrivateKey.Protect(key, "pass"); using (var f = new FileStream(path, FileMode.Create)) { ppk.WriteJson(f, id); } Assert.Equal(new[] { id }, KeyStore.ListIds()); Assert.Equal(ppk.Address, KeyStore.Get(id).Address); }
private (ProtectedPrivateKey, string) CreateProtectedPrivateKey() { string CreateRandomBase64String() { // TODO: use `CreateRandomBytes()` var random = new Random(); Span <byte> buffer = stackalloc byte[16]; random.NextBytes(buffer); return(Convert.ToBase64String(buffer)); } // 랜덤 문자열을 생성하여 passphrase로 사용합니다. var passphrase = CreateRandomBase64String(); return(ProtectedPrivateKey.Protect(new PrivateKey(), passphrase), passphrase); }
public KeyStoreMutation() { Field <NonNullGraphType <PrivateKeyType> >("createPrivateKey", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <StringGraphType> > { Name = "passphrase", }, new QueryArgument <ByteStringType> { Name = "privateKey", }), resolve: context => { var keyStore = context.Source; var passphrase = context.GetArgument <string>("passphrase"); var privateKeyBytes = context.GetArgument <byte[]>("privateKey"); var privateKey = privateKeyBytes is null ? new PrivateKey() : new PrivateKey(privateKeyBytes); var protectedPrivateKey = ProtectedPrivateKey.Protect(privateKey, passphrase); keyStore.Add(protectedPrivateKey); return(privateKey); }); Field <NonNullGraphType <ProtectedPrivateKeyType> >("revokePrivateKey", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <AddressType> > { Name = "address", }), resolve: context => { var keyStore = context.Source; var address = context.GetArgument <Address>("address"); keyStore.List() .First(guidAndKey => guidAndKey.Item2.Address.Equals(address)) .Deconstruct(out Guid guid, out ProtectedPrivateKey protectedPrivateKey); keyStore.Remove(guid); return(protectedPrivateKey); }); }
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); }
public void List() { Assert.Empty(KeyStore.List()); Assert.Empty(KeyStore.ListIds()); var key = new PrivateKey(); ProtectedPrivateKey ppk = ProtectedPrivateKey.Protect(key, "pass"); Guid id = KeyStore.Add(ppk); Assert.Single(KeyStore.List()); Tuple <Guid, ProtectedPrivateKey> pair = KeyStore.List().First(); Assert.Equal(id, pair.Item1); Assert.Equal(ppk.Address, pair.Item2.Address); Assert.Equal(new[] { id }, KeyStore.ListIds()); var key2 = new PrivateKey(); ProtectedPrivateKey ppk2 = ProtectedPrivateKey.Protect(key2, "pass"); Guid id2 = KeyStore.Add(ppk2); Assert.Equal( new[] { (id, ppk.Address), (id2, ppk2.Address) }.ToHashSet(),
public Signer(ulong chainId, ProtectedPrivateKey key, ILogManager logManager) { _chainId = chainId; _logger = logManager?.GetClassLogger <Signer>() ?? throw new ArgumentNullException(nameof(logManager)); SetSigner(key); }
void OnGUI() { _showPrivateKey = EditorGUILayout.Foldout(_showPrivateKey, "Private Key"); if (_showPrivateKey) { _selectedPrivateKeyIndex = EditorGUILayout.Popup( "Private Key", _selectedPrivateKeyIndex, _privateKeyOptions); if (_selectedPrivateKeyIndex == _privateKeyOptions.Length - 1) { _toggledOnTypePrivateKey = EditorGUILayout.Toggle( "Type New Private Key", _toggledOnTypePrivateKey); if (_toggledOnTypePrivateKey) { _privateKey = EditorGUILayout.PasswordField("New Private Key", _privateKey) ?? string.Empty; ShowError(_privateKey.Any() ? null : "New private key is empty."); } } _privateKeyPassphrase = EditorGUILayout.PasswordField("Passphrase", _privateKeyPassphrase) ?? string.Empty; ShowError(_privateKeyPassphrase.Any() ? null : "Passphrase is empty."); if (_selectedPrivateKeyIndex == _privateKeyOptions.Length - 1) { EditorGUI.BeginDisabledGroup(!_privateKeyPassphrase.Any()); if (GUILayout.Button("Create")) { var privateKey = _toggledOnTypePrivateKey ? new PrivateKey(ByteUtil.ParseHex(_privateKey)) : new PrivateKey(); var ppk = ProtectedPrivateKey.Protect(privateKey, _privateKeyPassphrase); _keyStore.Add(ppk); RefreshPrivateKeys(); _selectedPrivateKeyIndex = Array.IndexOf(_privateKeys, privateKey); } EditorGUI.EndDisabledGroup(); } } HorizontalLine(); _showParameters = EditorGUILayout.Foldout(_showParameters, "Parameters"); if (_showParameters) { _versionString = EditorGUILayout.TextField("Version", _versionString); try { version = int.Parse(_versionString, CultureInfo.InvariantCulture); } catch (Exception e) { ShowError(e.Message); } macOSBinaryUrl = EditorGUILayout.TextField("macOS Binary URL", macOSBinaryUrl); windowsBinaryUrl = EditorGUILayout.TextField("Windows Binary URL", windowsBinaryUrl); } HorizontalLine(); EditorGUI.BeginDisabledGroup( !(_privateKeyPassphrase.Any() && _selectedPrivateKeyIndex < _privateKeyOptions.Length - 1)); if (GUILayout.Button("Sign")) { var appProtocolVersionExtra = new AppProtocolVersionExtra(macOSBinaryUrl, windowsBinaryUrl, _timestamp); PrivateKey key; try { key = _privateKeys[_selectedPrivateKeyIndex].Item2 .Unprotect(_privateKeyPassphrase); } catch (IncorrectPassphraseException) { EditorUtility.DisplayDialog( "Unmatched passphrase", "Private key passphrase is incorrect.", "Retype passphrase" ); _privateKeyPassphrase = string.Empty; return; } _appProtocolVersion = AppProtocolVersion.Sign( key, version, appProtocolVersionExtra.Serialize()); } EditorGUI.EndDisabledGroup(); if (_appProtocolVersion is AppProtocolVersion v) { GUILayout.TextArea(v.Token); } }
public void SetSigner(ProtectedPrivateKey key) { }