github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/libkb/reset_delete.go (about)

     1  package libkb
     2  
     3  import (
     4  	"errors"
     5  )
     6  
     7  func CancelResetPipeline(mctx MetaContext) (err error) {
     8  	defer mctx.Trace("CancelResetPipeline", &err)()
     9  	_, err = mctx.G().API.Post(mctx, APIArg{
    10  		Endpoint:    "autoreset/cancel",
    11  		SessionType: APISessionTypeREQUIRED,
    12  		Args: HTTPArgs{
    13  			"src": S{Val: "app"},
    14  		},
    15  	})
    16  	return err
    17  }
    18  
    19  func ResetAccount(mctx MetaContext, username NormalizedUsername, passphrase string) (err error) {
    20  	defer mctx.Trace("ResetAccount", &err)()
    21  	return resetOrDeleteAccount(mctx, username, &passphrase, "nuke")
    22  }
    23  
    24  func DeleteAccount(mctx MetaContext, username NormalizedUsername, passphrase *string) (err error) {
    25  	defer mctx.Trace("DeleteAccount", &err)()
    26  	return resetOrDeleteAccount(mctx, username, passphrase, "delete")
    27  }
    28  
    29  func resetOrDeleteAccount(mctx MetaContext, username NormalizedUsername, passphrase *string, endpoint string) (err error) {
    30  	defer mctx.Trace("resetOrDeleteAccount", &err)()
    31  
    32  	arg := APIArg{
    33  		Endpoint:    endpoint,
    34  		SessionType: APISessionTypeREQUIRED,
    35  		Args:        NewHTTPArgs(),
    36  	}
    37  
    38  	if passphrase != nil {
    39  		// If passphrase is provided, create pdpka to authenticate the request.
    40  		// Otherwise, NIST authentication can be used (so no extra work for the
    41  		// client besides providing valid NIST token), but that only works for
    42  		// deleting random_pw accounts.
    43  		mctx = mctx.WithNewProvisionalLoginContext()
    44  		err = PassphraseLoginNoPrompt(mctx, username.String(), *passphrase)
    45  		if err != nil {
    46  			return err
    47  		}
    48  		pps := mctx.PassphraseStream()
    49  		if pps == nil {
    50  			return errors.New("unexpected nil passphrase stream")
    51  		}
    52  
    53  		pdpka, err := ComputeLoginPackage2(mctx, pps)
    54  		if err != nil {
    55  			return err
    56  		}
    57  
    58  		pdpka.PopulateArgs(&arg.Args)
    59  	}
    60  	_, err = mctx.G().API.Post(mctx, arg)
    61  	return err
    62  }