Skip to content

Commit 2d43900

Browse files
authored
Merge pull request #76 from String-xyz/task/sean/str-249
Task/sean/str 249
2 parents 8bae94a + 68f7b06 commit 2d43900

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

pkg/service/auth.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ type SignablePayload struct {
2222

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

25+
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: "
26+
2527
type RefreshTokenResponse struct {
2628
Token string `json:"token"`
2729
ExpAt time.Time `json:"expAt"`
@@ -80,13 +82,13 @@ func (a auth) PayloadToSign(walletAddress string) (SignablePayload, error) {
8082
if err != nil {
8183
return signable, common.StringError(err)
8284
}
83-
return SignablePayload{encrypted}, nil
85+
return SignablePayload{walletAuthenticationPrefix + encrypted}, nil
8486
}
8587

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

253255
func verifyWalletAuthentication(request model.WalletSignaturePayloadSigned) error {
254256
key := os.Getenv("STRING_ENCRYPTION_KEY")
255-
preSignedPayload, err := common.Decrypt[model.WalletSignaturePayload](request.Nonce, key)
257+
preSignedPayload, err := common.Decrypt[model.WalletSignaturePayload](request.Nonce[len(walletAuthenticationPrefix):], key)
256258
if err != nil {
257259
return common.StringError(err)
258260
}

pkg/service/user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (u user) GetStatus(userID string) (model.UserOnboardingStatus, error) {
6363
func (u user) Create(request model.WalletSignaturePayloadSigned) (UserCreateResponse, error) {
6464
resp := UserCreateResponse{}
6565
key := os.Getenv("STRING_ENCRYPTION_KEY")
66-
payload, err := common.Decrypt[model.WalletSignaturePayload](request.Nonce, key)
66+
payload, err := common.Decrypt[model.WalletSignaturePayload](request.Nonce[len(walletAuthenticationPrefix):], key)
6767
if err != nil {
6868
return resp, common.StringError(err)
6969
}

0 commit comments

Comments
 (0)