private IActionResult ConfirmAddresses(WalletSetupViewModel vm, DerivationSchemeSettings strategy) { vm.DerivationScheme = strategy.AccountDerivation.ToString(); var deposit = new NBXplorer.KeyPathTemplates(null).GetKeyPathTemplate(DerivationFeature.Deposit); if (!string.IsNullOrEmpty(vm.DerivationScheme)) { var line = strategy.AccountDerivation.GetLineFor(deposit); for (uint i = 0; i < 10; i++) { var keyPath = deposit.GetKeyPath(i); var rootedKeyPath = vm.GetAccountKeypath()?.Derive(keyPath); var derivation = line.Derive(i); var address = strategy.Network.NBXplorerNetwork.CreateAddress(strategy.AccountDerivation, line.KeyPathTemplate.GetKeyPath(i), derivation.ScriptPubKey).ToString(); vm.AddressSamples.Add((keyPath.ToString(), address, rootedKeyPath)); } } vm.Confirmation = true; ModelState.Remove(nameof(vm.Config)); // Remove the cached value return(View("ImportWallet/ConfirmAddresses", vm)); }
public IActionResult GetProposedOnChainPaymentMethodPreview( string storeId, string cryptoCode, [FromBody] OnChainPaymentMethodDataPreview paymentMethodData, int offset = 0, int amount = 10) { if (!GetCryptoCodeWallet(cryptoCode, out var network, out BTCPayWallet _)) { return(NotFound()); } if (string.IsNullOrEmpty(paymentMethodData?.DerivationScheme)) { ModelState.AddModelError(nameof(OnChainPaymentMethodData.DerivationScheme), "Missing derivationScheme"); } if (!ModelState.IsValid) { return(this.CreateValidationError(ModelState)); } DerivationSchemeSettings strategy; try { strategy = DerivationSchemeSettings.Parse(paymentMethodData.DerivationScheme, network); } catch { ModelState.AddModelError(nameof(OnChainPaymentMethodData.DerivationScheme), "Invalid Derivation Scheme"); return(this.CreateValidationError(ModelState)); } var deposit = new NBXplorer.KeyPathTemplates(null).GetKeyPathTemplate(DerivationFeature.Deposit); var line = strategy.AccountDerivation.GetLineFor(deposit); var result = new OnChainPaymentMethodPreviewResultData(); for (var i = offset; i < amount; i++) { var derivation = line.Derive((uint)i); result.Addresses.Add( new OnChainPaymentMethodPreviewResultData. OnChainPaymentMethodPreviewResultAddressItem() { KeyPath = deposit.GetKeyPath((uint)i).ToString(), Address = strategy.Network.NBXplorerNetwork.CreateAddress(strategy.AccountDerivation, line.KeyPathTemplate.GetKeyPath((uint)i), derivation.ScriptPubKey).ToString() }); } return(Ok(result)); }
public IActionResult GetOnChainPaymentMethodPreview( string storeId, string cryptoCode, int offset = 0, int amount = 10) { if (!GetCryptoCodeWallet(cryptoCode, out var network, out BTCPayWallet _)) { return(NotFound()); } var paymentMethod = GetExistingBtcLikePaymentMethod(cryptoCode); if (string.IsNullOrEmpty(paymentMethod?.DerivationScheme)) { return(NotFound()); } try { var strategy = DerivationSchemeSettings.Parse(paymentMethod.DerivationScheme, network); var deposit = new NBXplorer.KeyPathTemplates(null).GetKeyPathTemplate(DerivationFeature.Deposit); var line = strategy.AccountDerivation.GetLineFor(deposit); var result = new OnChainPaymentMethodPreviewResultData(); for (var i = offset; i < amount; i++) { var address = line.Derive((uint)i); result.Addresses.Add( new OnChainPaymentMethodPreviewResultData.OnChainPaymentMethodPreviewResultAddressItem() { KeyPath = deposit.GetKeyPath((uint)i).ToString(), Address = address.ScriptPubKey.GetDestinationAddress(strategy.Network.NBitcoinNetwork) .ToString() }); } return(Ok(result)); } catch { ModelState.AddModelError(nameof(OnChainPaymentMethodData.DerivationScheme), "Invalid Derivation Scheme"); return(this.CreateValidationError(ModelState)); } }
private IActionResult ShowAddresses(DerivationSchemeViewModel vm, DerivationSchemeSettings strategy) { vm.DerivationScheme = strategy.AccountDerivation.ToString(); var deposit = new NBXplorer.KeyPathTemplates(null).GetKeyPathTemplate(DerivationFeature.Deposit); if (!string.IsNullOrEmpty(vm.DerivationScheme)) { var line = strategy.AccountDerivation.GetLineFor(deposit); for (int i = 0; i < 10; i++) { var address = line.Derive((uint)i); vm.AddressSamples.Add((deposit.GetKeyPath((uint)i).ToString(), address.ScriptPubKey.GetDestinationAddress(strategy.Network.NBitcoinNetwork).ToString())); } } vm.Confirmation = true; ModelState.Remove(nameof(vm.Config)); // Remove the cached value return(View(vm)); }
private static void ShowAddresses(DerivationSchemeSettings strategy, Network network) { Dictionary <string, string> keyPath2Addresses = new Dictionary <string, string>(); var deposit = new NBXplorer.KeyPathTemplates(null).GetKeyPathTemplate(DerivationFeature.Deposit); // var deposit = new NBXplorer.KeyPathTemplates(new NBXplorer.KeyPathTemplate(new NBitcoin.KeyPath("m/44'/60'/0'/0"), new NBitcoin.KeyPath("m/44'/60'/0'/0"))).GetKeyPathTemplate(DerivationFeature.Deposit); //var deposit = new NBXplorer.KeyPathTemplates(new NBXplorer.KeyPathTemplate(new NBitcoin.KeyPath("m/44'/60'/0'/0"), new NBitcoin.KeyPath("m/44'/60'/0'/0"))).GetKeyPathTemplate(new NBitcoin.KeyPath("m/44'/60'/0'/0")); var line = strategy.AccountDerivation.GetLineFor(deposit); //var line1 = strategy.AccountDerivation.GetDerivation(new NBitcoin.KeyPath("m/44/60/0/0")); var d = strategy.AccountDerivation.GetDerivation(new NBitcoin.KeyPath("m/44/60/0/0/2")).ScriptPubKey.GetDestinationAddress(network).ToString(); Console.WriteLine("d ::: " + d); for (int i = 0; i < 10; i++) { var address = line.Derive((uint)i); string keyPath = deposit.GetKeyPath((uint)i).ToString(); string destinationAddress = address.ScriptPubKey.GetDestinationAddress(network).ToString(); Console.WriteLine($" keyPath {keyPath} , destinationAddress {destinationAddress}"); } }