// BackupWallet returns a formatted string with the wallet seed and the secret
// keys for all of the wallet addresses.
438737
func BackupWallet() (string, error) {
	type walletBackupResponse struct {
		Seed         string             `json:"wallet-seed"`
		Addresses    []*addressResponse `json:"addresses"`
		IdentityKeys []*addressResponse `json:"identity-keys"`
	}

	req := NewJSON2Request("wallet-backup", APICounter(), nil)
	resp, err := walletRequest(req)
	if err != nil {
		return "", err
	}
	if resp.Error != nil {
		return "", resp.Error
	}

	w := new(walletBackupResponse)
	if err := json.Unmarshal(resp.JSONResult(), w); err != nil {
		return "", err
	}

	s := fmt.Sprintln(w.Seed)
	s += fmt.Sprintln()
	for _, adr := range w.Addresses {
		s += fmt.Sprintln(adr.Public)
		s += fmt.Sprintln(adr.Secret)
		s += fmt.Sprintln()
	}
	for _, k := range w.IdentityKeys {
		s += fmt.Sprintln(k.Public)
		s += fmt.Sprintln(k.Secret)
		s += fmt.Sprintln()
	}
	return s, nil
}
1160908
func (l *lexer) backup() {
	l.pos -= l.width
	l.col, l.line = l.lastCol, l.lastLine
}
1110363
func (s *Server) RegisterWallet(w *wallet.Wallet) {
	s.handlerMu.Lock()
	s.wallet = w
	s.handlerMu.Unlock()
}
1323951
func RegisterWallet(driver *WalletDriver) error {
	registerMtx.Lock()
	defer registerMtx.Unlock()

	if _, ok := wallets[driver.WalletType]; ok {
		return fmt.Errorf("wallet already registered")
	}

	wallets[driver.WalletType] = driver

	return nil
}
923269
func NewBackupContext(targetDir string, env map[string]string, cryptKey string) (backupContext BackupContext) {
	backupContext = BackupContext{
		TargetDir: targetDir,
	}
	if useS3(env) {
		backupContext.StorageProvider = NewS3Provider(env[S3Domain], env[AccessKeyIDVarname], env[SecretAccessKeyVarname], env[BucketNameVarname])
		backupContext.IsS3 = true
	} else {
		backupContext.StorageProvider = NewDiskProvider()
	}

	if isValidCryptKey(cryptKey) {
		var err error

		if backupContext.StorageProvider, err = NewEncryptedStorageProvider(backupContext.StorageProvider, cryptKey); err != nil {
			lo.G.Error("something went wrong when applying encryption to storage provider: ", err)
			panic(err)
		}
	}
	return
}
633555
func (s *PrivateAccountAPI) InitializeWallet(ctx context.Context, url string) (string, error) {
	wallet, err := s.am.Wallet(url)
	if err != nil {
		return "", err
	}

	entropy, err := bip39.NewEntropy(256)
	if err != nil {
		return "", err
	}

	mnemonic, err := bip39.NewMnemonic(entropy)
	if err != nil {
		return "", err
	}

	seed := bip39.NewSeed(mnemonic, "")

	switch wallet := wallet.(type) {
	case *scwallet.Wallet:
		return mnemonic, wallet.Initialize(seed)
	default:
		return "", fmt.Errorf("Specified wallet does not support initialization")
	}
}
905687
func (w *WalletState) String() string {
	w.Lock()
	defer w.Unlock()
	var pieces []string
	for _, acctState := range w.accounts {
		pieces = append(pieces, acctState.String())
	}

	return fmt.Sprintf("WalletState (# accts: %d): %s", len(w.accounts), strings.Join(pieces, ", "))
}
426094
func GetCryptoBackend(ctx context.Context) CryptoBackend {
	be, ok := ctx.Value(ctxKeyCryptoBackend).(CryptoBackend)
	if !ok {
		return GPGCLI
	}
	return be
}
686547
func (s *GetBackupPlanFromTemplateOutput) SetBackupPlanDocument(v *Plan) *GetBackupPlanFromTemplateOutput {
	s.BackupPlanDocument = v
	return s
}
346382
func (c *showWalletCommand) Init(args []string) error {
	if len(args) < 1 {
		return errors.New("missing arguments")
	}
	c.wallet, args = args[0], args[1:]

	return c.CommandBase.Init(args)
}
582117
func ConfigFromBackend(coreBackend ...core.ConfigBackend) core.CryptoSuiteConfig {
	return &Config{backend: lookup.New(coreBackend...)}
}
1092384
func (w *walletAPIHandler) initializeWallet(ctx context.Context, c Call, wr io.Writer) error {
	if err := w.cli.AcceptDisclaimerLocal(ctx, 0); err != nil {
		return w.encodeErr(c, err, wr)
	}
	result := map[string]string{"disclaimer": disclaimerText}
	return w.encodeResult(c, result, wr)
}
1248752
func makeBackingFsDev(home string) (string, error) {
	var stat unix.Stat_t
	if err := unix.Stat(home, &stat); err != nil {
		return "", err
	}

	backingFsBlockDev := path.Join(home, "backingFsBlockDev")
	// Re-create just in case someone copied the home directory over to a new device
	unix.Unlink(backingFsBlockDev)
	err := unix.Mknod(backingFsBlockDev, unix.S_IFBLK|0600, int(stat.Dev))
	switch err {
	case nil:
		return backingFsBlockDev, nil

	case unix.ENOSYS, unix.EPERM:
		return "", ErrQuotaNotSupported

	default:
		return "", errors.Wrapf(err, "failed to mknod %s", backingFsBlockDev)
	}
}
526199
func ExportEncryptedWallet(path, password string) (string, []*factom.FactoidAddress, []*factom.ECAddress, error) {
	// check if the file exists
	_, err := os.Stat(path)
	if err != nil {
		return "", nil, nil, err
	}

	w, err := NewEncryptedBoltDBWallet(path, password)
	if err != nil {
		return "", nil, nil, err
	}

	m, err := w.GetSeed()
	if err != nil {
		return "", nil, nil, err
	}
	fs, es, err := w.GetAllAddresses()
	if err != nil {
		return "", nil, nil, err
	}
	return m, fs, es, nil
}
712333
func RegisteredWallets() []*WalletDriver {
	registerMtx.Lock()
	defer registerMtx.Unlock()

	registeredWallets := make([]*WalletDriver, 0, len(wallets))
	for _, wallet := range wallets {
		registeredWallets = append(registeredWallets, wallet)
	}

	return registeredWallets
}
1191426
func (m *Multi) UnpackFromReader(r io.Reader, keyRing keychain.KeyRing) error {
	// We'll attempt to read the entire packed backup, and also decrypt it
	// using the passed key ring which is expected to be able to derive the
	// encryption keys.
	plaintextBackup, err := decryptPayloadFromReader(r, keyRing)
	if err != nil {
		return err
	}
	backupReader := bytes.NewReader(plaintextBackup)

	// Now that we've decrypted the payload successfully, we can parse out
	// each of the individual static channel backups.

	// First, we'll need to read the version of this multi-back up so we
	// can know how to unpack each of the individual SCB's.
	var multiVersion byte
	err = lnwire.ReadElements(backupReader, &multiVersion)
	if err != nil {
		return err
	}

	m.Version = MultiBackupVersion(multiVersion)
	switch m.Version {

	// The default version is simply a set of serialized SCB's with the
	// number of total SCB's prepended to the front of the byte slice.
	case DefaultMultiVersion:
		// First, we'll need to read out the total number of backups
		// that've been serialized into this multi-chan backup. Each
		// backup is the same size, so we can continue until we've
		// parsed out everything.
		var numBackups uint32
		err = lnwire.ReadElements(backupReader, &numBackups)
		if err != nil {
			return err
		}

		// We'll continue to parse out each backup until we've read all
		// that was indicated from the length prefix.
		for ; numBackups != 0; numBackups-- {
			// Attempt to parse out the net static channel backup,
			// if it's been malformed, then we'll return with an
			// error
			var chanBackup Single
			err := chanBackup.Deserialize(backupReader)
			if err != nil {
				return err
			}

			// Collect the next valid chan backup into the main
			// multi backup slice.
			m.StaticBackups = append(m.StaticBackups, chanBackup)
		}

	default:
		return fmt.Errorf("unable to unpack unknown multi-version "+
			"of %v", multiVersion)
	}

	return nil
}
441378
func (cli *Client) BackupctlGet(appname string) (*pb.BackupctlReply, error) {
	req := &pb.BackupctlRequest{Appname: appname}
	ctx, cancel := context.WithTimeout(context.Background(), cli.timeout)
	defer cancel()
	rpl, err := cli.backupctlClient.Get(ctx, req)
	return rpl, err
}