-
Notifications
You must be signed in to change notification settings - Fork 6
/
backend.ts
141 lines (133 loc) · 3.38 KB
/
backend.ts
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import axios from 'axios'
const BACKEND_URL = 'https://g4fzh009re.execute-api.us-west-2.amazonaws.com/prod/token-backup'
export async function savePermitData(
permitSignature: string,
// this has to be resolved addresses for ENS values
squad: string[],
owner: string,
chainId: number,
tokens: string[],
nonce: string
) {
try {
const res = await fetch(`${BACKEND_URL}/permit`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
permit: permitSignature,
recoveryAddresses: squad,
owner,
recoveryScheme: {
m: 2,
n: 3,
},
chainId,
tokens,
nonce
}),
})
return await res.json()
} catch (e) {
console.log(e)
throw new Error('Error saving permit data.')
}
}
export async function getPermitData(owner: string) {
try {
const url = `${BACKEND_URL}/permit/${owner}`
const formattedRequest = {
method: 'get',
headers: {
accept: 'application/json, text/plain, */*',
'content-type': 'application/json',
},
url,
}
return await axios(formattedRequest)
} catch (e) {
throw new Error('Error fetching back up from service.')
}
}
export async function startRecovery(owner: string, recipient: string, recoveryId: string) {
try {
const url = `${BACKEND_URL}/recovery/start/${owner}`
const formattedRequest = {
method: 'post',
headers: {
accept: 'application/json, text/plain, */*',
'content-type': 'application/json',
},
data: JSON.stringify({
recipient,
recoveryId,
}),
url,
}
return await axios(formattedRequest)
} catch (e) {
console.log(e)
throw new Error('Error starting recovery from the back up service.')
}
}
export async function signRecovery(uuid: string, signature: string, signer: string) {
try {
const url = `${BACKEND_URL}/recovery/sign`
const formattedRequest = {
method: 'post',
headers: {
accept: 'application/json, text/plain, */*',
'content-type': 'application/json',
},
data: JSON.stringify({
uuid,
signature,
signer,
}),
url,
}
return await axios(formattedRequest)
} catch (e) {
console.log(e)
throw new Error('Error signing recovery from the back up service.')
}
}
export async function completeRecovery(uuid: string, txHash: string) {
try {
const url = `${BACKEND_URL}/recovery/complete`
const formattedRequest = {
method: 'post',
headers: {
accept: 'application/json, text/plain, */*',
'content-type': 'application/json',
},
data: JSON.stringify({
uuid,
txHash,
}),
url,
}
return await axios(formattedRequest)
} catch (e) {
console.log(e)
throw new Error('Error completing recovery from the back up service.')
}
}
export async function getRecoveryData(uuid: string) {
try {
const url = `${BACKEND_URL}/recovery/${uuid}`
const formattedRequest = {
method: 'get',
headers: {
accept: 'application/json, text/plain, */*',
'content-type': 'application/json',
},
url,
}
return await axios(formattedRequest)
} catch (e) {
console.log(e)
throw new Error('Error getting recovery data from the back up service.')
}
}