public async Task SerializeAndSignMultiActionTx() { var keyStore = new InMemoryKeyStore(); var keyPair = KeyPair.FromString("ed25519:2wyRcSwSuHtRVmkMCGjPwnzZmQLeXLzLLyED1NDMt4BjnKgQL6tF85yBx6Jr26D2dUNeC716RBoTxntVHsegogYw"); await keyStore.SetKeyAsync("test", "test.near", keyPair); var publicKey = keyPair.GetPublicKey(); var actions = new[] { Action.CreateAccount(), Action.DeployContract(new byte[] { 1, 2, 3 }), Action.FunctionCall("qqq", new byte[] { 1, 2, 3 }, 1000, 1000000), Action.Transfer(123), Action.Stake(1000000, publicKey), Action.AddKey(publicKey, AccessKey.FunctionCallAccessKey("zzz", new [] { "www" }, null)), Action.DeleteKey(publicKey), Action.DeleteAccount("123") }; var blockHash = new ByteArray32() { Buffer = Base58.Decode("244ZQ9cgj3CQ6bWBdytfrJMuMQ1jdXLFGnr4HhvtCTnM") }; var signedTransaction = await SignedTransaction.SignTransactionAsync("123", 1, actions, blockHash, new InMemorySigner(keyStore), "test.near", "test"); const string expected = "Fo3MJ9XzKjnKuDuQKhDAC6fra5H2UWawRejFSEpPNk3Y"; var actual = Base58.Encode(signedTransaction.Item1); Assert.AreEqual(expected, actual); }
public async Task SerializeAndSignTransferTx() { var keyStore = new InMemoryKeyStore(); var keyPair = KeyPair.FromString("ed25519:3hoMW1HvnRLSFCLZnvPzWeoGwtdHzke34B2cTHM8rhcbG3TbuLKtShTv3DvyejnXKXKBiV7YPkLeqUHN1ghnqpFv"); await keyStore.SetKeyAsync("test", "test.near", keyPair); var actions = new[] { Action.Transfer(1) }; var blockHash = Base58.Decode("244ZQ9cgj3CQ6bWBdytfrJMuMQ1jdXLFGnr4HhvtCTnM"); var signedTransaction = await SignedTransaction.SignTransactionAsync("whatever.near", 1, actions, new ByteArray32() { Buffer = blockHash }, new InMemorySigner(keyStore), "test.near", "test"); const string expectedBase64String = "lpqDMyGG7pdV5IOTJVJYBuGJo9LSu0tHYOlEQ+l+HE8i3u7wBZqOlxMQDtpuGRRNp+ig735TmyBwi6HY0CG9AQ=="; var actualBase64String = Convert.ToBase64String(signedTransaction.Item2.Signature.Data.Buffer); Assert.AreEqual(expectedBase64String, actualBase64String); const string expectedHexString = "09000000746573742e6e65617200917b3d268d4b58f7fec1b150bd68d69be3ee5d4cc39855e341538465bb77860d01000000000000000d00000077686174657665722e6e6561720fa473fd26901df296be6adc4cc4df34d040efa2435224b6986910e630c2fef601000000030100000000000000000000000000000000969a83332186ee9755e4839325525806e189a3d2d2bb4b4760e94443e97e1c4f22deeef0059a8e9713100eda6e19144da7e8a0ef7e539b20708ba1d8d021bd01"; var serialized = signedTransaction.Item2.ToByteArray(); var actualHexString = BitConverter.ToString(serialized).Replace("-", "").ToLower(); Assert.AreEqual(expectedHexString, actualHexString); }
public static async Task <Near> ConnectAsync(dynamic config) { // Try to find extra key in `KeyPath` if provided. if (config.KeyPath == null) { return(new Near(config)); } try { var accountKeyFile = await UnencryptedFileSystemKeyStore.ReadKeyFile(config.keyPath); if (accountKeyFile[0] != null) { // TODO: Only load key if network ID matches var keyPair = accountKeyFile[1]; var keyPathStore = new InMemoryKeyStore(); await keyPathStore.SetKeyAsync(config.NetworkId, accountKeyFile[0], keyPair); if (config.MasterAccount == null) { config.MasterAccount = accountKeyFile[0]; } config.KeyStore = new MergeKeyStore(new KeyStore[] { config.KeyStore, keyPathStore }); } } catch (Exception error) { Console.WriteLine($"Failed to load master account key from {config.KeyPath}: {error}"); } return(new Near(config)); }
public void keys() { IKeyStore keyStore = new InMemoryKeyStore(); ICryptoEngine crypto = new TokenCryptoEngine("member-id", keyStore); MemberMethodsSample.keys(crypto, member); }
public void KeysTest() { using (Tokenio.Tpp.TokenClient tokenClient = TestUtil.CreateClient()) { IKeyStore keyStore = new InMemoryKeyStore(); ICryptoEngine cryptoEngine = new TokenCryptoEngine("member-id", keyStore); TppMember member = tokenClient.CreateMemberBlocking(TestUtil.RandomAlias()); MemberMethodsSample.Keys(cryptoEngine, member); } }
public void testEqualityOfInMemoryDictionary() { var randomvalues = new Dictionary <string, string> { { "KEYYYYYYY" + Random.value, "valuuuuuuuueeeee" + Random.value }, { "chunky" + Random.value, "monkey" + Random.value }, { "that " + Random.value, "funky" + Random.value }, { "1234", "5678" }, { "abc", "def" }, }; var inMemory = new InMemoryKeyStore(); var playerprefs = new PlayerPrefsKeyStore(); var editor = new EditorKeyStore(); var values = new List <string>(); randomvalues.ForEach((KeyValuePair <string, string> kvp) => { values.Add(kvp.Value); }); string valueStringNewlineDelimited = string.Join("\n", values.ToArray()); var fileProvider = new FileLineBasedKeyStore(getMemoryStream(valueStringNewlineDelimited), values); Assert.IsTrue(inMemory.otherDictionaryIsEqualOrASuperset(inMemory)); Assert.IsTrue(inMemory.otherDictionaryIsEqualOrASuperset(playerprefs)); Assert.IsTrue(inMemory.otherDictionaryIsEqualOrASuperset(editor)); Assert.IsTrue(inMemory.otherDictionaryIsEqualOrASuperset(fileProvider)); foreach (var kvp in randomvalues) { Debug.Log("Setting kvp:" + kvp.Key + " val" + kvp.Value); inMemory.set(kvp.Key, kvp.Value); playerprefs.set(kvp.Key, kvp.Value); editor.set(kvp.Key, kvp.Value); fileProvider.set(kvp.Key, kvp.Value); } standardCheck(inMemory, dictionary); standardCheck(playerprefs, dictionary); standardCheck(editor, dictionary); standardCheck(fileProvider, dictionary); Assert.IsTrue(inMemory.otherDictionaryIsEqualOrASuperset(inMemory)); Assert.IsTrue(inMemory.otherDictionaryIsEqualOrASuperset(playerprefs)); Assert.IsTrue(inMemory.otherDictionaryIsEqualOrASuperset(editor)); Assert.IsTrue(inMemory.otherDictionaryIsEqualOrASuperset(fileProvider)); var provider = new FileBasedCredentialProvider(); Assert.AreEqual(provider.username, "*****@*****.**"); Debug.Log("HELLO" + provider.username); }
public void testEqualityOfInMemoryDictionary() { var randomvalues = new Dictionary<string, string> { {"KEYYYYYYY" + Random.value, "valuuuuuuuueeeee" + Random.value}, {"chunky" + Random.value, "monkey" + Random.value}, {"that " + Random.value, "funky" + Random.value}, {"1234", "5678"}, {"abc", "def"}, }; var inMemory = new InMemoryKeyStore(); var playerprefs = new PlayerPrefsKeyStore(); var editor = new EditorKeyStore(); var values = new List<string>(); randomvalues.ForEach((KeyValuePair<string, string> kvp) => { values.Add(kvp.Value); }); string valueStringNewlineDelimited = string.Join("\n", values.ToArray()); var fileProvider = new FileLineBasedKeyStore(getMemoryStream(valueStringNewlineDelimited), values); Assert.IsTrue(inMemory.otherDictionaryIsEqualOrASuperset(inMemory)); Assert.IsTrue(inMemory.otherDictionaryIsEqualOrASuperset(playerprefs)); Assert.IsTrue(inMemory.otherDictionaryIsEqualOrASuperset(editor)); Assert.IsTrue(inMemory.otherDictionaryIsEqualOrASuperset(fileProvider)); foreach(var kvp in randomvalues) { Debug.Log("Setting kvp:" + kvp.Key + " val" + kvp.Value); inMemory.set(kvp.Key, kvp.Value); playerprefs.set(kvp.Key, kvp.Value); editor.set(kvp.Key, kvp.Value); fileProvider.set(kvp.Key, kvp.Value); } standardCheck(inMemory, dictionary); standardCheck(playerprefs, dictionary); standardCheck(editor, dictionary); standardCheck(fileProvider, dictionary); Assert.IsTrue(inMemory.otherDictionaryIsEqualOrASuperset(inMemory)); Assert.IsTrue(inMemory.otherDictionaryIsEqualOrASuperset(playerprefs)); Assert.IsTrue(inMemory.otherDictionaryIsEqualOrASuperset(editor)); Assert.IsTrue(inMemory.otherDictionaryIsEqualOrASuperset(fileProvider)); var provider = new FileBasedCredentialProvider(); Assert.AreEqual(provider.username, "*****@*****.**"); Debug.Log("HELLO" + provider.username); }
public static async Task <Near> SetUpTestConnection() { var keyStore = new InMemoryKeyStore(); var key = "ed25519:2wyRcSwSuHtRVmkMCGjPwnzZmQLeXLzLLyED1NDMt4BjnKgQL6tF85yBx6Jr26D2dUNeC716RBoTxntVHsegogYw"; var keyPair = KeyPair.FromString(key); await keyStore.SetKeyAsync(NetworkId, TestAccountName, keyPair); var environment = EnvironmentConfig.GetConfig(Environment.CI); var config = new NearConfig() { NetworkId = TestUtils.NetworkId, NodeUrl = environment.NodeUrl.AbsoluteUri, ProviderType = ProviderType.JsonRpc, SignerType = SignerType.InMemory, KeyStore = keyStore, ContractName = "contractId", WalletUrl = environment.NodeUrl.AbsoluteUri }; return(await Near.ConnectAsync(config : config)); }
public void inMemoryKeyStoreCheck() { var store = new InMemoryKeyStore(); standardCheck(store, dictionary); }
public void ClassInit() { _keyStore = new InMemoryKeyStore(); }