Skip to content

Commit 2f880fd

Browse files
committed
remove wallet backup
1 parent 4395bbd commit 2f880fd

12 files changed

+1
-875
lines changed

api/openapi.json

-82
Original file line numberDiff line numberDiff line change
@@ -414,18 +414,6 @@
414414
},
415415
"description": "a list of account ids"
416416
},
417-
"Backup": {
418-
"content": {
419-
"application/octet-stream": {
420-
"schema": {
421-
"format": "binary",
422-
"type": "string"
423-
}
424-
}
425-
},
426-
"description": "Information for saving backup",
427-
"required": true
428-
},
429417
"BatchBoc": {
430418
"content": {
431419
"application/json": {
@@ -10467,76 +10455,6 @@
1046710455
]
1046810456
}
1046910457
},
10470-
"/v2/wallet/backup": {
10471-
"get": {
10472-
"description": "Get backup info",
10473-
"operationId": "getWalletBackup",
10474-
"parameters": [
10475-
{
10476-
"in": "header",
10477-
"name": "X-TonConnect-Auth",
10478-
"required": true,
10479-
"schema": {
10480-
"type": "string"
10481-
}
10482-
}
10483-
],
10484-
"responses": {
10485-
"200": {
10486-
"content": {
10487-
"application/json": {
10488-
"schema": {
10489-
"properties": {
10490-
"dump": {
10491-
"type": "string"
10492-
}
10493-
},
10494-
"required": [
10495-
"dump"
10496-
],
10497-
"type": "object"
10498-
}
10499-
}
10500-
},
10501-
"description": "get wallet dump"
10502-
},
10503-
"default": {
10504-
"$ref": "#/components/responses/Error"
10505-
}
10506-
},
10507-
"tags": [
10508-
"Wallet"
10509-
]
10510-
},
10511-
"put": {
10512-
"description": "Set backup info",
10513-
"operationId": "setWalletBackup",
10514-
"parameters": [
10515-
{
10516-
"in": "header",
10517-
"name": "X-TonConnect-Auth",
10518-
"required": true,
10519-
"schema": {
10520-
"type": "string"
10521-
}
10522-
}
10523-
],
10524-
"requestBody": {
10525-
"$ref": "#/components/requestBodies/Backup"
10526-
},
10527-
"responses": {
10528-
"200": {
10529-
"description": "success"
10530-
},
10531-
"default": {
10532-
"$ref": "#/components/responses/Error"
10533-
}
10534-
},
10535-
"tags": [
10536-
"Wallet"
10537-
]
10538-
}
10539-
},
1054010458
"/v2/wallet/emulate": {
1054110459
"post": {
1054210460
"description": "Emulate sending message to blockchain",

api/openapi.yml

-53
Original file line numberDiff line numberDiff line change
@@ -1931,51 +1931,6 @@ paths:
19311931
$ref: '#/components/schemas/AccountInfoByStateInit'
19321932
'default':
19331933
$ref: '#/components/responses/Error'
1934-
1935-
/v2/wallet/backup:
1936-
get:
1937-
description: Get backup info
1938-
operationId: getWalletBackup
1939-
tags:
1940-
- Wallet
1941-
parameters:
1942-
- in: header
1943-
name: X-TonConnect-Auth
1944-
schema:
1945-
type: string
1946-
required: true
1947-
responses:
1948-
'200':
1949-
description: get wallet dump
1950-
content:
1951-
application/json:
1952-
schema:
1953-
type: object
1954-
required:
1955-
- dump
1956-
properties:
1957-
dump:
1958-
type: string
1959-
'default':
1960-
$ref: '#/components/responses/Error'
1961-
put:
1962-
description: Set backup info
1963-
operationId: setWalletBackup
1964-
tags:
1965-
- Wallet
1966-
parameters:
1967-
- in: header
1968-
name: X-TonConnect-Auth
1969-
schema:
1970-
type: string
1971-
required: true
1972-
requestBody:
1973-
$ref: "#/components/requestBodies/Backup"
1974-
responses:
1975-
'200':
1976-
description: success
1977-
'default':
1978-
$ref: '#/components/responses/Error'
19791934
/v2/wallet/auth/proof:
19801935
post:
19811936
description: Account verification and token issuance
@@ -3337,14 +3292,6 @@ components:
33373292
state_init:
33383293
type: string
33393294
format: cell-base64
3340-
Backup:
3341-
description: "Information for saving backup"
3342-
required: true
3343-
content:
3344-
application/octet-stream:
3345-
schema:
3346-
type: string
3347-
format: binary
33483295
TonConnectStateInit:
33493296
description: "Data that is expected"
33503297
required: true

pkg/api/wallet_handlers.go

+1-111
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,11 @@ package api
22

33
import (
44
"context"
5-
"crypto/hmac"
6-
"crypto/sha256"
7-
"encoding/base64"
85
"encoding/hex"
96
"errors"
107
"fmt"
11-
"io"
12-
"net/http"
13-
"os"
14-
"time"
15-
168
"github.com/tonkeeper/opentonapi/pkg/core"
17-
18-
"github.com/tonkeeper/tongo/ton"
9+
"net/http"
1910

2011
"github.com/tonkeeper/opentonapi/pkg/oas"
2112
"github.com/tonkeeper/opentonapi/pkg/wallet"
@@ -25,107 +16,6 @@ import (
2516
tongoWallet "github.com/tonkeeper/tongo/wallet"
2617
)
2718

28-
func (h *Handler) SetWalletBackup(ctx context.Context, request oas.SetWalletBackupReq, params oas.SetWalletBackupParams) error {
29-
pubKey, verify, err := checkTonConnectToken(params.XTonConnectAuth, h.tonConnect.GetSecret())
30-
if err != nil {
31-
return toError(http.StatusBadRequest, err)
32-
}
33-
if !verify {
34-
return toError(http.StatusBadRequest, fmt.Errorf("failed verify"))
35-
}
36-
37-
walletBalance, err := getTotalBalances(ctx, h.storage, pubKey)
38-
if err != nil {
39-
return toError(http.StatusInternalServerError, err)
40-
}
41-
if walletBalance < int64(ton.OneTON) {
42-
return toError(http.StatusBadRequest, fmt.Errorf("wallet must have more than 1 TON"))
43-
}
44-
45-
fileName := fmt.Sprintf("%x.dump", pubKey)
46-
tempFileName := fileName + fmt.Sprintf(".temp%v", time.Now().Nanosecond()+time.Now().Second())
47-
file, err := os.Create(tempFileName)
48-
if err != nil {
49-
return toError(http.StatusInternalServerError, err)
50-
}
51-
defer file.Close()
52-
_, err = io.Copy(file, io.LimitReader(request.Data, 640*1024)) //640K ought to be enough for anybody
53-
if err != nil {
54-
return toError(http.StatusInternalServerError, err)
55-
}
56-
file.Close()
57-
err = os.Rename(tempFileName, fileName)
58-
if err != nil {
59-
return toError(http.StatusInternalServerError, err)
60-
}
61-
return nil
62-
}
63-
64-
func (h *Handler) GetWalletBackup(ctx context.Context, params oas.GetWalletBackupParams) (*oas.GetWalletBackupOK, error) {
65-
pubKey, verify, err := checkTonConnectToken(params.XTonConnectAuth, h.tonConnect.GetSecret())
66-
if err != nil {
67-
return nil, toError(http.StatusBadRequest, err)
68-
}
69-
if !verify {
70-
return nil, toError(http.StatusBadRequest, fmt.Errorf("failed verify"))
71-
}
72-
73-
dump, err := os.ReadFile(fmt.Sprintf("%v.dump", hex.EncodeToString(pubKey)))
74-
if err != nil {
75-
return nil, toError(http.StatusInternalServerError, err)
76-
}
77-
78-
return &oas.GetWalletBackupOK{Dump: string(dump)}, nil
79-
}
80-
81-
func checkTonConnectToken(authToken, secret string) ([]byte, bool, error) {
82-
decodedData, err := base64.URLEncoding.DecodeString(authToken)
83-
if err != nil {
84-
return nil, false, err
85-
}
86-
if len(decodedData) <= 32 {
87-
return nil, false, fmt.Errorf("invalid payload length")
88-
}
89-
pubKey := decodedData[:32]
90-
signature := decodedData[32:]
91-
92-
hmacHash := hmac.New(sha256.New, []byte(secret))
93-
hmacHash.Write(pubKey)
94-
computedSignature := hmacHash.Sum(nil)
95-
if !hmac.Equal(signature, computedSignature) {
96-
return nil, false, nil
97-
}
98-
99-
return pubKey, true, nil
100-
}
101-
102-
func getTotalBalances(ctx context.Context, storage storage, pubKey []byte) (int64, error) {
103-
var balance int64
104-
versions := []tongoWallet.Version{
105-
tongoWallet.V1R1, tongoWallet.V1R2, tongoWallet.V1R3,
106-
tongoWallet.V2R1, tongoWallet.V2R2,
107-
tongoWallet.V3R1, tongoWallet.V3R2,
108-
tongoWallet.V4R1, tongoWallet.V4R2,
109-
tongoWallet.V5Beta,
110-
}
111-
var walletAddresses []tongo.AccountID
112-
for _, version := range versions {
113-
walletAddress, err := tongoWallet.GenerateWalletAddress(pubKey, version, nil, 0, nil)
114-
if err != nil {
115-
continue
116-
}
117-
walletAddresses = append(walletAddresses, walletAddress)
118-
}
119-
for _, address := range walletAddresses {
120-
account, err := storage.GetRawAccount(ctx, address)
121-
if err != nil {
122-
continue
123-
}
124-
balance += account.TonBalance
125-
}
126-
return balance, nil
127-
}
128-
12919
func (h *Handler) GetWalletsByPublicKey(ctx context.Context, params oas.GetWalletsByPublicKeyParams) (*oas.Accounts, error) {
13020
publicKey, err := hex.DecodeString(params.PublicKey)
13121
if err != nil {

0 commit comments

Comments
 (0)