示例#1
0
        public void OpenCreatedWalletSuccessfully()
        {
            IPool pool = IndyDotNet.Pool.Factory.GetPool("OpenCreatedWalletPool", _genesisFileName);

            pool.Create();
            pool.Open();

            _poolsCreated.Add(pool);

            WalletConfig config = new WalletConfig()
            {
                Id = "OpenCreateWalletID"
            };

            WalletCredentials credentials = new WalletCredentials()
            {
                Key = "8dvfYSt5d1taSd6yJdpjq4emkwsPDDLYxkNFysFD2cZY",
                KeyDerivationMethod = KeyDerivationMethod.RAW
            };

            IWallet wallet = IndyDotNet.Wallet.Factory.GetWallet(config, credentials);

            wallet.Create();
            _walletsCreated.Add(wallet);

            wallet.Open();
        }
示例#2
0
        static IWallet CreateWallet(WalletConfig cfg, string walletType)
        {
            walletType = walletType.ToUpper();
            var network = cfg.Mainnet ? "mainnet" : "testnet";

            GetLogger().LogDebug($"Creating wallet ({walletType}) for {network} using db: '{cfg.DbName}', node: '{cfg.Node}'");

            // create db context and apply migrations
            var db = GetWalletContext(cfg.DbName, cfg.ShowSQL, true);

            db.Database.Migrate();

            if (walletType == BtcWallet.TYPE)
            {
                return(new BtcWallet(GetLogger(), db, cfg.Mainnet, new Uri(cfg.Node)));
            }
            else if (walletType == EthWallet.TYPE)
            {
                return(new EthWallet(GetLogger(), db, cfg.Mainnet, cfg.Node, "http://localhost:5001" /*TODO: get this from cmdline/env*/));
            }
            else if (walletType == WavWallet.TYPE)
            {
                return(new WavWallet(GetLogger(), db, cfg.Mainnet, new Uri(cfg.Node)));
            }
            else if (walletType == ZapWallet.TYPE)
            {
                return(new ZapWallet(GetLogger(), db, cfg.Mainnet, new Uri(cfg.Node)));
            }
            else
            {
                throw new Exception("Wallet type not recognised");
            }
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PoolConfig"/> class.
        /// </summary>
        /// <param name="config">The configuration.</param>
        /// <param name="coinConfig"></param>
        public PoolConfig(dynamic config, ICoinConfig coinConfig)
        {
            try
            {
                Enabled = config.enabled ? config.enabled : false;

                if (Enabled == false) // if the configuration is not enabled
                {
                    return;           // just skip reading rest of the parameters.
                }
                Coin = coinConfig;    // assign the coin config.

                // load the sections.
                Daemon   = new DaemonConfig(config.daemon);
                Meta     = new MetaConfig(config.meta);
                Wallet   = new WalletConfig(config.wallet);
                Rewards  = new RewardsConfig(config.rewards);
                Payments = new PaymentConfig(config.payments);
                Miner    = new MinerConfig(config.miner);
                Job      = new JobConfig(config.job);
                Stratum  = new StratumServerConfig(config.stratum);
                Banning  = new BanConfig(config.banning);
                Storage  = new RedisConfig(config.storage.redis);
                Vanilla  = new VanillaServerConfig(config.vanilla);

                Valid = true;
            }
            catch (Exception e)
            {
                Valid = false;
                Log.Logger.ForContext <PoolConfig>().Error(e, "Error loading pool configuration");
            }
        }
        public void Initialize()
        {
            string file = Environment.GetEnvironmentVariable("POOL_GENESIS_FILE");

            // throw new Exception($"environment variable POOL_GENESIS_FILE is {file}");

            if (string.IsNullOrEmpty(file))
            {
                file = PoolUtils.GenerateGenesisFile();
                _filesCreated.Add(file);
            }

            _pool = IndyDotNet.Pool.Factory.GetPool("IssueCredentialDemoPool", file);
            _pool.Create();
            _pool.Open();

            WalletConfig config = new WalletConfig()
            {
                Id = "IssueCredentialDemoWalletId"
            };

            _wallet = IndyDotNet.Wallet.Factory.GetWallet(config, _credentials);
            _wallet.Create();
            _wallet.Open();
        }
示例#5
0
        static IWallet2 CreateWalletFast(WalletConfig cfg, string walletType)
        {
            walletType = walletType.ToUpper();
            var db = GetWalletContext(cfg.DbName, false, false);

            return(new FastWallet(GetLogger(), db, cfg.Mainnet, walletType));
        }
示例#6
0
 /// <summary>
 /// Not a public constructor! Allows work with ContextBuilder
 ///</summary>
 public Context(
     WalletConfig walletConfig,
     string version,
     string verityUrl,
     string verityPublicDID,
     string verityPublicVerKey,
     string domainDID,
     string verityAgentVerKey,
     string sdkVerKeyId,
     string sdkVerKey,
     string endpointUrl
     )
 {
     this.walletConfig       = walletConfig;
     this.version            = version;
     this.verityUrl          = verityUrl;
     this.verityPublicDID    = verityPublicDID;
     this.verityPublicVerKey = verityPublicVerKey;
     this.domainDID          = domainDID;
     this.verityAgentVerKey  = verityAgentVerKey;
     this.sdkVerKeyId        = sdkVerKeyId;
     this.sdkVerKey          = sdkVerKey;
     this.endpointUrl        = endpointUrl;
     this.walletHandle       = OpenWallet();
 }
示例#7
0
        // Not a public constructor! Allows work with ContextBuilder
        public Context(
            WalletConfig walletConfig,
            string version,
            string verityUrl,
            string verityPublicDID,
            string verityPublicVerKey,
            string domainDID,
            string verityAgentVerKey,
            string sdkVerKeyId,
            string sdkVerKey,
            string endpointUrl,
            Wallet handle
            )
        {
            if (handle == null)
            {
                throw new WalletOpenException("Context can not be constructed without wallet handle");
            }

            this.walletConfig       = walletConfig;
            this.version            = version;
            this.verityUrl          = verityUrl;
            this.verityPublicDID    = verityPublicDID;
            this.verityPublicVerKey = verityPublicVerKey;
            this.domainDID          = domainDID;
            this.verityAgentVerKey  = verityAgentVerKey;
            this.sdkVerKeyId        = sdkVerKeyId;
            this.sdkVerKey          = sdkVerKey;
            this.endpointUrl        = endpointUrl;
            this.walletHandle       = handle;
        }
示例#8
0
        private static void RunCreateWallet(string fileName)
        {
            if (!fileName.EndsWith(".json", StringComparison.InvariantCultureIgnoreCase))
            {
                Console.WriteLine("Wallet file name must end with .json");
                return;
            }
            if (File.Exists(fileName))
            {
                Console.WriteLine("A wallet file with this name already exists.");
                return;
            }

            var          keys   = KeySignature.GenerateKeyPairs();
            WalletConfig wallet = new WalletConfig()
            {
                PrivateKey = keys.PrivateKey,
                PublicKey  = keys.PublicKey
            };

            var json = Newtonsoft.Json.JsonConvert.SerializeObject(wallet, Formatting.Indented);

            File.WriteAllText(fileName, json);

            Console.WriteLine("Wallet created successfully");
        }
示例#9
0
 public ServerController(CoinbaseHandler coinbasehandler, WalletReceiver.WalletReceiver walletReceiver, WalletConfig config, Keychain keychain)
 {
     this.coinbasehandler = coinbasehandler;
     this.walletReceiver  = walletReceiver;
     this.config          = config;
     this.keychain        = keychain;
 }
示例#10
0
        public void WalletConfigSerializesToJsonCorrectly()
        {
            WalletConfig config = new WalletConfig
            {
                Id            = "Id",
                StorageType   = "StorageType",
                StorageConfig = new WalletStorageConfig()
                {
                    Path = "Path"
                }
            };

            string json = config.ToJson();

            const string result = @"{
                    ""id"": ""Id"",
                    ""storage_type"": ""StorageType"",
                    ""storage_config"": {
                        ""path"": ""Path""
                        }
                    }";

            var resultObject = JValue.Parse(result);

            Assert.AreEqual(config.Id, resultObject["id"], "Id did not match");
            Assert.AreEqual(config.StorageType, resultObject["storage_type"], "StorageType did not match");
        }
示例#11
0
        public void Initialize()
        {
            string file = Environment.GetEnvironmentVariable("POOL_GENESIS_FILE");

            if (string.IsNullOrEmpty(file))
            {
                file = PoolUtils.GenerateGenesisFile();
                _filesCreated.Add(file);
            }

            _pool = IndyDotNet.Pool.Factory.GetPool("WriteDidAndQueryVeryKeyDemoPool", file);
            _pool.Create();
            _pool.Open();

            WalletConfig config = new WalletConfig()
            {
                Id = "WriteDidAndQueryVeryKeyDemoWalletId"
            };

            WalletCredentials credentials = new WalletCredentials()
            {
                Key = "8dvfYSt5d1taSd6yJdpjq4emkwsPDDLYxkNFysFD2cZY",
                KeyDerivationMethod = KeyDerivationMethod.RAW
            };

            _wallet = IndyDotNet.Wallet.Factory.GetWallet(config, credentials);
            _wallet.Create();
            _wallet.Open();
        }
示例#12
0
        public void Initialize()
        {
            string file = PoolUtils.GenerateGenesisFile();

            _filesCreated.Add(file);

            _pool = IndyDotNet.Pool.Factory.GetPool("AllPaymentsTestsPool", file);
            _pool.Create();
            _pool.Open();

            WalletConfig config = new WalletConfig()
            {
                Id = "AllPaymentsTestWalletId"
            };

            WalletCredentials credentials = new WalletCredentials()
            {
                Key = "8dvfYSt5d1taSd6yJdpjq4emkwsPDDLYxkNFysFD2cZY",
                KeyDerivationMethod = KeyDerivationMethod.RAW
            };

            _wallet = IndyDotNet.Wallet.Factory.GetWallet(config, credentials);
            _wallet.Create();
            _wallet.Open();
        }
示例#13
0
 /// <summary>
 /// Initializes a ContextBuilder from scratch for a verity-sdk that is using an already provisioned agent on
 /// the verity-application. This involves three main steps. First, a new local wallet is created
 /// using the given wallet config. Second, a new local key-pair is created in the new created wallet that will
 /// be used by the verity-sdk. Third, the verity-application public DID and verkey a retrieved from the
 /// verity-application instance referenced by the given verkey url. After these two step, a given fields are loaded
 /// into a blank ContextBuilder and returned.
 /// </summary>
 /// <param name="walletConfig">the wallet config for accessing the local wallet</param>
 /// <param name="verityUrl">the url for the targeted instance of the verity-application</param>
 /// <param name="domainDID">the domain DID for the agent already provisioned</param>
 /// <param name="verityAgentVerKey">the verkey for the agent already provisioned</param>
 /// <return>a ContextBuilder with given, retrieved and created fields</return>
 public static Context fromScratch(WalletConfig walletConfig,
                                   string verityUrl,
                                   string domainDID,
                                   string verityAgentVerKey)
 {
     return(fromScratch(walletConfig, verityUrl, domainDID, verityAgentVerKey, null));
 }
示例#14
0
 /// <summary>
 /// Initializes a ContextBuilder from scratch for a verity-sdk without a provisioned agent on the
 /// verity-application. This involves three main steps. First, a new local wallet is created
 /// using the given wallet config. Second, a new local key-pair is created in the new created wallet that will
 /// be used by the verity-sdk. Third, the verity-application public DID and verkey a retrieved from the
 /// verity-application instance referenced by the given verkey url. After these two step, a given fields are loaded
 /// into a blank ContextBuilder and returned.
 /// </summary>
 /// <param name="walletConfig">the wallet config for accessing the local wallet</param>
 /// <param name="verityUrl">the url for the targeted instance of the verity-application</param>
 /// <param name="seed">the seed used to generate the local key-pair</param>
 /// <return>a ContextBuilder with given, retrieved and created fields</return>
 public static Context fromScratch(WalletConfig walletConfig,
                                   string verityUrl,
                                   string seed)
 {
     WalletUtil.tryCreateWallet(walletConfig);
     return(scratchContext(walletConfig, verityUrl, seed));
 }
示例#15
0
        public void Initialize()
        {
            string file = PoolUtils.GenerateGenesisFile();

            _filesCreated.Add(file);

            _pool = IndyDotNet.Pool.Factory.GetPool("AllCryptoTestsPool", file);
            _pool.Create();
            _pool.Open();

            WalletConfig config = new WalletConfig()
            {
                Id = "AllCryptoTestsWalletId"
            };

            WalletCredentials credentials = new WalletCredentials()
            {
                Key = "8dvfYSt5d1taSd6yJdpjq4emkwsPDDLYxkNFysFD2cZY",
                KeyDerivationMethod = KeyDerivationMethod.RAW
            };

            _wallet = IndyDotNet.Wallet.Factory.GetWallet(config, credentials);
            _wallet.Create();
            _wallet.Open();

            IdentitySeed seed = new IdentitySeed()
            {
                Seed = "00000000000000000000000000000My1"
            };

            _senderDid = IndyDotNet.Did.Factory.CreateMyDid(_pool, _wallet, seed);
        }
示例#16
0
        public WalletInstall(HttpClientFactory httpClientFactory, GeneralConfig generalConfig, WalletConfig walletConfig, ILog logger)
        {
            _httpClientFactory = httpClientFactory;
            _walletConfig      = walletConfig;
            _logger            = logger;

            _walletInstallerPath = Path.Combine(generalConfig.UserConfig.UserDataPath, _walletConfig.InstallerDir);
        }
        public WalletBootstrap(HttpClientFactory httpClientFactory, GeneralConfig generalConfig, WalletConfig walletConfig, ILog logger)
        {
            _httpClientFactory = httpClientFactory;
            _walletConfig      = walletConfig;
            _logger            = logger;

            _bootstrapFilePath = Path.Combine(generalConfig.UserConfig.UserDataPath, _walletConfig.BootstrapDir, _walletConfig.BootstrapFilename);
            _bootstrapPath     = Path.Combine(generalConfig.UserConfig.UserDataPath, _walletConfig.BootstrapDir);
        }
示例#18
0
 private static void GetConfig(out WalletConfig config)
 {
     config = null;
     if (!CommonWalletHelper.TryToOpenWalletConfig(out config))
     {
         CommonWalletHelper.CreateWalletConfigFile();
         config = new WalletConfig();
     }
 }
示例#19
0
        public static string GetCreateWalletConfig(string walletName)
        {
            WalletConfig config = new WalletConfig()
            {
                id = walletName
            };

            return(JsonConvert.SerializeObject(config, Formatting.Indented));
        }
示例#20
0
        public static void issue_burn_tx(
            WalletConfig config,
            Keychain keychain,
            ulong amount,
            ulong minimumConfirmations,
            uint maxOutputs
            )
        {
            keychain = Keychain.Burn_enabled(keychain, Identifier.Zero());

            var chainTip      = Checker.get_tip_from_node(config);
            var currentHeight = chainTip.Height;

            var _ = Checker.refresh_outputs(config, keychain);

            var keyId = keychain.Root_key_id();

// select some spendable coins from the walvar
            var coins = WalletData.Read_wallet(
                config.DataFileDir, walletData => walletData.Select(
                    keyId.Clone(),
                    amount,
                    currentHeight,
                    minimumConfirmations,
                    maxOutputs,
                    false));


            Log.Debug("selected some coins - {}", coins.Length);

            var(partsArray, _) = inputs_and_change(coins, config, keychain, amount);

            var parts = partsArray.ToList();

            // add burn output and fees
            var fee = Types.tx_fee((uint)coins.Length, 2, null);

            parts.Add(c => c.Output(amount - fee, Identifier.Zero()));

            // finalize the burn transaction and send
            var(txBurn, _) = Build.Transaction(parts.ToArray(), keychain);
            txBurn.Validate(keychain.Secp);

            var txHex = HexUtil.to_hex(Ser.Ser_vec(txBurn));

            var url = $"{config.CheckNodeApiHttpAddr}/v1/pool/push";

            var json = JsonConvert.SerializeObject(new TxWrapper {
                TxHex = txHex
            });

            var res = ApiClient.PostContentAsync(url, new StringContent(json, Encoding.UTF8, "application/json")).Result;

            Log.Debug("{StatusCode}", res.StatusCode);
        }
示例#21
0
        /// <summary>
        /// Initializes a ContextBuilder from scratch for a verity-sdk that is using an already provisioned agent on
        /// the verity-application. This involves three main steps. First, a new local wallet is created
        /// using the given wallet config. Second, a new local key-pair is created in the new created wallet that will
        /// be used by the verity-sdk. Third, the verity-application public DID and verkey a retrieved from the
        /// verity-application instance referenced by the given verkey url. After these two step, a given fields are loaded
        /// into a blank ContextBuilder and returned.
        /// </summary>
        /// <param name="walletConfig">the wallet config for accessing the local wallet</param>
        /// <param name="verityUrl">the url for the targeted instance of the verity-application</param>
        /// <param name="domainDID">the domain DID for the agent already provisioned</param>
        /// <param name="verityAgentVerKey">the verkey for the agent already provisioned</param>
        /// <param name="seed">the seed used to generate the local key-pair</param>
        /// <return>a ContextBuilder with given, retrieved and created fields</return>
        public static Context fromScratch(WalletConfig walletConfig,
                                          string verityUrl,
                                          string domainDID,
                                          string verityAgentVerKey,
                                          string seed)
        {
            WalletUtil.tryCreateWallet(walletConfig);
            Context inter = scratchContext(walletConfig, verityUrl, seed);

            return(withProvisionedAgent(inter, domainDID, verityAgentVerKey));
        }
示例#22
0
 public static void CreateWalletConfigFile()
 {
     using (var writter = new StreamWriter(_walletConfigFileName))
     {
         var newWallet = new WalletConfig()
         {
             WalletLastAddressIndexUsed = new Dictionary <string, int>()
         };
         writter.WriteLine(JsonConvert.SerializeObject(newWallet));
     }
 }
示例#23
0
 public static void TryUpdateConfig(WalletConfig config)
 {
     if (File.Exists(_walletConfigFileName))
     {
         File.Delete(_walletConfigFileName);
         using (var writter = new StreamWriter(_walletConfigFileName))
         {
             writter.WriteLine(JsonConvert.SerializeObject(config));
         }
     }
 }
示例#24
0
 public static Wallet openIndyWallet(WalletConfig walletConfig)
 {
     try
     {
         return(Wallet.OpenWalletAsync(walletConfig.config(), walletConfig.credential()).GetAwaiter().GetResult());
     }
     catch (IndyException e)
     {
         throw new WalletOpenException("Wallet failed to open", e);
     }
 }
示例#25
0
 public static void AddNewRecordInWalletConfig(WalletConfig config, string sha256PublicKey)
 {
     if (IsWalletSavedInConfig(config, sha256PublicKey))
     {
         config.WalletLastAddressIndexUsed[sha256PublicKey] += 1;
     }
     else
     {
         config.WalletLastAddressIndexUsed.Add(sha256PublicKey, 1);
     }
     TryUpdateConfig(config);
 }
示例#26
0
 public static void cleanup(Context context)
 {
     if (context != null)
     {
         if (!context.WalletIsClosed())
         {
             context.CloseWallet();
         }
         WalletConfig config = context.WalletConfig();
         Wallet.DeleteWalletAsync(config.config(), config.credential()).GetAwaiter().GetResult();
     }
 }
示例#27
0
        public async Task TestCreateWalletWorks()
        {
            WalletConfig config = new WalletConfig()
            {
                id = WALLET
            };
            Credentials cred = new Credentials()
            {
                key = WALLET_KEY
            };

            await Wallet.CreateWalletAsync(config, cred);
        }
示例#28
0
        public async Task TestOpenWalletWorksForNotCreated()
        {
            WalletConfig config = new WalletConfig()
            {
                id = OPEN_WALLET_NAME
            };
            Credentials cred = new Credentials()
            {
                key = WALLET_KEY
            };

            var ex = await Assert.ThrowsExceptionAsync <WalletValueNotFoundException>(() =>
                                                                                      Wallet.OpenWalletAsync(config, cred)
                                                                                      );
        }
示例#29
0
        public async Task CreateWallet()
        {
            WalletConfig config = new WalletConfig()
            {
                id = CLOSE_WALLET_NAME
            };
            Credentials cred = new Credentials()
            {
                key = WALLET_KEY
            };

            await Wallet.CreateWalletAsync(config, cred);

            _closeWallet = await Wallet.OpenWalletAsync(config, cred);
        }
示例#30
0
        public static Context scratchContext(WalletConfig wallet, string verityUrl, Did verityDid, string seed)
        {
            Context inter = new ContextBuilder()
                            .verityPublicDID(verityDid.did)
                            .verityPublicVerKey(verityDid.verkey)
                            .walletConfig(wallet)
                            .verityUrl(verityUrl)
                            .build();

            Did mime = Did.createNewDid(inter.WalletHandle(), seed);

            return(inter.ToContextBuilder()
                   .sdkVerKeyId(mime.did)
                   .sdkVerKey(mime.verkey)
                   .build());
        }