2019-05-15 08:00:09 +02:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2019-05-14 18:03:48 +02:00
|
|
|
using System.ComponentModel.DataAnnotations;
|
2019-05-15 08:00:09 +02:00
|
|
|
using NBitcoin;
|
2019-05-14 18:03:48 +02:00
|
|
|
|
|
|
|
namespace BTCPayServer.Models.WalletViewModels
|
|
|
|
{
|
|
|
|
public class SignWithSeedViewModel
|
|
|
|
{
|
|
|
|
[Required]
|
|
|
|
public string PSBT { get; set; }
|
2019-05-17 07:42:28 +02:00
|
|
|
[Required][Display(Name = "BIP39 Seed (12/24 word mnemonic phrase) or HD private key (xprv...)")]
|
2019-05-14 18:03:48 +02:00
|
|
|
public string SeedOrKey { get; set; }
|
|
|
|
|
|
|
|
[Display(Name = "Optional seed passphrase")]
|
2019-12-23 14:32:33 +01:00
|
|
|
[DataType(DataType.Password)]
|
2019-05-14 18:03:48 +02:00
|
|
|
public string Passphrase { get; set; }
|
|
|
|
|
2019-05-15 08:00:09 +02:00
|
|
|
public ExtKey GetExtKey(Network network)
|
|
|
|
{
|
|
|
|
ExtKey extKey = null;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var mnemonic = new Mnemonic(SeedOrKey);
|
|
|
|
extKey = mnemonic.DeriveExtKey(Passphrase);
|
|
|
|
}
|
|
|
|
catch (Exception)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
if (extKey == null)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
extKey = ExtKey.Parse(SeedOrKey, network);
|
|
|
|
}
|
|
|
|
catch (Exception)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return extKey;
|
|
|
|
}
|
2019-05-14 18:03:48 +02:00
|
|
|
}
|
|
|
|
}
|