Skip to content

Task/sean/str 249 #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pkg/service/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type SignablePayload struct {

var hexRegex *regexp.Regexp = regexp.MustCompile(`^0x[a-fA-F0-9]{40}$`)

var walletAuthenticationPrefix string = "Thank you for using String! By signing this message you are:\n\n1) Authorizing String to initiate off-chain transactions on your behalf, including your bank account, credit card, or debit card.\n\n2) Confirming that this wallet is owned by you.\n\nThis request will not trigger any blockchain transaction or cost any gas.\n\nNonce: "

type RefreshTokenResponse struct {
Token string `json:"token"`
ExpAt time.Time `json:"expAt"`
Expand Down Expand Up @@ -80,13 +82,13 @@ func (a auth) PayloadToSign(walletAddress string) (SignablePayload, error) {
if err != nil {
return signable, common.StringError(err)
}
return SignablePayload{encrypted}, nil
return SignablePayload{walletAuthenticationPrefix + encrypted}, nil
}

func (a auth) VerifySignedPayload(request model.WalletSignaturePayloadSigned) (UserCreateResponse, error) {
resp := UserCreateResponse{}
key := os.Getenv("STRING_ENCRYPTION_KEY")
payload, err := common.Decrypt[model.WalletSignaturePayload](request.Nonce, key)
payload, err := common.Decrypt[model.WalletSignaturePayload](request.Nonce[len(walletAuthenticationPrefix):], key)
if err != nil {
return resp, common.StringError(err)
}
Expand Down Expand Up @@ -252,7 +254,7 @@ func (a auth) RefreshToken(refreshToken string, walletAddress string) (JWT, erro

func verifyWalletAuthentication(request model.WalletSignaturePayloadSigned) error {
key := os.Getenv("STRING_ENCRYPTION_KEY")
preSignedPayload, err := common.Decrypt[model.WalletSignaturePayload](request.Nonce, key)
preSignedPayload, err := common.Decrypt[model.WalletSignaturePayload](request.Nonce[len(walletAuthenticationPrefix):], key)
if err != nil {
return common.StringError(err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/service/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (u user) GetStatus(userID string) (model.UserOnboardingStatus, error) {
func (u user) Create(request model.WalletSignaturePayloadSigned) (UserCreateResponse, error) {
resp := UserCreateResponse{}
key := os.Getenv("STRING_ENCRYPTION_KEY")
payload, err := common.Decrypt[model.WalletSignaturePayload](request.Nonce, key)
payload, err := common.Decrypt[model.WalletSignaturePayload](request.Nonce[len(walletAuthenticationPrefix):], key)
if err != nil {
return resp, common.StringError(err)
}
Expand Down