-
Notifications
You must be signed in to change notification settings - Fork 26
/
app.go
66 lines (62 loc) · 1.7 KB
/
app.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package bot
import (
"context"
"encoding/json"
"fmt"
"time"
)
type App struct {
Type string `json:"type"`
AppId string `json:"app_id"`
AppNumber string `json:"app_number"`
RedirectURI string `json:"redirect_uri"`
HomeURI string `json:"home_uri"`
Name string `json:"name"`
IconURL string `json:"icon_url"`
Description string `json:"description"`
Capabilities []string `json:"capabilities"`
ResourcePatterns []string `json:"resource_patterns"`
Category string `json:"category"`
CreatorId string `json:"creator_id"`
UpdatedAt time.Time `json:"updated_at"`
IsVerified bool `json:"is_verified"`
}
func Migrate(ctx context.Context, receiver string, user *SafeUser) (*App, error) {
tipBody := TipBodyForOwnershipTransfer(receiver)
pin, err := signTipBody(tipBody, user.SpendPrivateKey)
if err != nil {
return nil, err
}
encryptedPIN, err := EncryptEd25519PIN(pin, uint64(time.Now().UnixNano()), user)
if err != nil {
return nil, err
}
data, err := json.Marshal(map[string]string{
"user_id": receiver,
"pin_base64": encryptedPIN,
})
if err != nil {
return nil, err
}
path := fmt.Sprintf("/apps/%s/transfer", uid)
token, err := SignAuthenticationToken("POST", path, string(data), user)
if err != nil {
return nil, err
}
body, err := Request(ctx, "POST", path, data, token)
if err != nil {
return nil, err
}
var resp struct {
Data *App `json:"data"`
Error Error `json:"error"`
}
err = json.Unmarshal(body, &resp)
if err != nil {
return nil, BadDataError(ctx)
}
if resp.Error.Code > 0 {
return nil, resp.Error
}
return resp.Data, nil
}