edge-core-js 2.45.0 → 2.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/android/src/main/assets/edge-core-js/edge-core.js +1 -1
- package/lib/core/account/account-api.js +35 -1
- package/lib/core/account/memory-wallet.js +2 -1
- package/lib/core/actions.js +15 -0
- package/lib/core/currency/wallet/currency-wallet-api.js +16 -0
- package/lib/core/currency/wallet/currency-wallet-cleaners.js +4 -0
- package/lib/core/currency/wallet/currency-wallet-files.js +57 -3
- package/lib/core/currency/wallet/currency-wallet-pixie.js +36 -6
- package/lib/core/currency/wallet/currency-wallet-reducer.js +14 -0
- package/lib/core/login/splitting.js +5 -9
- package/lib/node/index.js +4682 -4546
- package/lib/types/types.js +9 -0
- package/package.json +1 -6
- package/src/types/types.ts +9 -0
- package/lib/flow/error.js +0 -448
- package/lib/flow/exports.js +0 -140
- package/lib/flow/fake-types.js +0 -187
- package/lib/flow/server-cleaners.js +0 -444
- package/lib/flow/server-types.js +0 -342
- package/lib/flow/type-helpers.js +0 -60
- package/lib/flow/types.js +0 -2250
- package/lib/node/index.js.flow +0 -4
- package/types.js.flow +0 -4
package/lib/flow/server-types.js
DELETED
|
@@ -1,342 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
import type { EdgePendingVoucher } from "./types";
|
|
4
|
-
|
|
5
|
-
// ---------------------------------------------------------------------
|
|
6
|
-
// internal Edge types
|
|
7
|
-
// ---------------------------------------------------------------------
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Edge-format encrypted data.
|
|
11
|
-
*/
|
|
12
|
-
export type EdgeBox = {
|
|
13
|
-
encryptionType: number;
|
|
14
|
-
data_base64: Uint8Array;
|
|
15
|
-
iv_hex: Uint8Array;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Encrypted wallet private keys along with a creation date.
|
|
20
|
-
*/
|
|
21
|
-
export type EdgeKeyBox = {
|
|
22
|
-
...$Exact<EdgeBox>;
|
|
23
|
-
created: Date | void;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Edge-format scrypt parameters.
|
|
28
|
-
*/
|
|
29
|
-
export type EdgeSnrp = {
|
|
30
|
-
salt_hex: Uint8Array;
|
|
31
|
-
n: number;
|
|
32
|
-
r: number;
|
|
33
|
-
p: number;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* The barcode creator uploads this request.
|
|
38
|
-
*/
|
|
39
|
-
export type EdgeLobbyRequest = {
|
|
40
|
-
loginRequest?: { appId: string };
|
|
41
|
-
publicKey: Uint8Array;
|
|
42
|
-
timeout?: number;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* The barcode scanner sends this reply (if the user approves).
|
|
47
|
-
*/
|
|
48
|
-
export type EdgeLobbyReply = {
|
|
49
|
-
publicKey: Uint8Array;
|
|
50
|
-
box: EdgeBox;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// ---------------------------------------------------------------------
|
|
54
|
-
// top-level request & response bodies
|
|
55
|
-
// ---------------------------------------------------------------------
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Data sent to authenticate with the login server.
|
|
59
|
-
*/
|
|
60
|
-
export type LoginRequestBody = {
|
|
61
|
-
// The request payload:
|
|
62
|
-
data?: mixed;
|
|
63
|
-
|
|
64
|
-
// Common fields for all login methods:
|
|
65
|
-
challengeId?: string;
|
|
66
|
-
deviceDescription?: string;
|
|
67
|
-
otp?: string;
|
|
68
|
-
syncToken?: string;
|
|
69
|
-
voucherId?: string;
|
|
70
|
-
voucherAuth?: Uint8Array;
|
|
71
|
-
|
|
72
|
-
// Secret-key login:
|
|
73
|
-
loginId?: Uint8Array;
|
|
74
|
-
loginAuth?: Uint8Array;
|
|
75
|
-
|
|
76
|
-
// Password login:
|
|
77
|
-
userId?: Uint8Array;
|
|
78
|
-
passwordAuth?: Uint8Array;
|
|
79
|
-
|
|
80
|
-
// PIN login:
|
|
81
|
-
pin2Id?: Uint8Array;
|
|
82
|
-
pin2Auth?: Uint8Array;
|
|
83
|
-
|
|
84
|
-
// Recovery login:
|
|
85
|
-
recovery2Id?: Uint8Array;
|
|
86
|
-
recovery2Auth?: Uint8Array[];
|
|
87
|
-
|
|
88
|
-
// Messages:
|
|
89
|
-
loginIds?: Uint8Array[];
|
|
90
|
-
|
|
91
|
-
// OTP reset:
|
|
92
|
-
otpResetAuth?: string;
|
|
93
|
-
|
|
94
|
-
// Legacy:
|
|
95
|
-
did?: string;
|
|
96
|
-
l1?: Uint8Array;
|
|
97
|
-
lp1?: Uint8Array;
|
|
98
|
-
lpin1?: Uint8Array;
|
|
99
|
-
lra1?: Uint8Array;
|
|
100
|
-
recoveryAuth?: Uint8Array; // lra1
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export type LoginResponseBody = {
|
|
104
|
-
// The response payload:
|
|
105
|
-
results?: mixed;
|
|
106
|
-
|
|
107
|
-
// What of response is this (success or failure)?:
|
|
108
|
-
status_code: number;
|
|
109
|
-
message: string;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// ---------------------------------------------------------------------
|
|
113
|
-
// request payloads
|
|
114
|
-
// ---------------------------------------------------------------------
|
|
115
|
-
|
|
116
|
-
export type ChangeOtpPayload = {
|
|
117
|
-
otpTimeout: number; // seconds
|
|
118
|
-
otpKey: Uint8Array;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export type ChangePasswordPayload = {
|
|
122
|
-
passwordAuth: Uint8Array;
|
|
123
|
-
passwordAuthBox: EdgeBox;
|
|
124
|
-
passwordAuthSnrp: EdgeSnrp;
|
|
125
|
-
passwordBox: EdgeBox;
|
|
126
|
-
passwordKeySnrp: EdgeSnrp;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export type ChangePin2IdPayload = {
|
|
130
|
-
pin2Id: Uint8Array;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export type ChangePin2Payload = {
|
|
134
|
-
pin2Id?: Uint8Array;
|
|
135
|
-
pin2Auth?: Uint8Array;
|
|
136
|
-
pin2Box?: EdgeBox;
|
|
137
|
-
pin2KeyBox?: EdgeBox;
|
|
138
|
-
pin2TextBox: EdgeBox;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export type ChangeRecovery2IdPayload = {
|
|
142
|
-
recovery2Id: Uint8Array;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export type ChangeRecovery2Payload = {
|
|
146
|
-
recovery2Id: Uint8Array;
|
|
147
|
-
recovery2Auth: Uint8Array[];
|
|
148
|
-
recovery2Box: EdgeBox;
|
|
149
|
-
recovery2KeyBox: EdgeBox;
|
|
150
|
-
question2Box: EdgeBox;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export type ChangeSecretPayload = {
|
|
154
|
-
loginAuthBox: EdgeBox;
|
|
155
|
-
loginAuth: Uint8Array;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export type ChangeUsernamePayload = {
|
|
159
|
-
userId: Uint8Array;
|
|
160
|
-
userTextBox: EdgeBox;
|
|
161
|
-
|
|
162
|
-
// Also includes fields from these payloads if the login methods exist:
|
|
163
|
-
// - ChangePasswordPayload
|
|
164
|
-
// - ChangePin2IdPayload
|
|
165
|
-
// - ChangeRecovery2IdPayload
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export type ChangeVouchersPayload = {
|
|
169
|
-
approvedVouchers?: string[];
|
|
170
|
-
rejectedVouchers?: string[];
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export type CreateKeysPayload = {
|
|
174
|
-
allowExisting: boolean;
|
|
175
|
-
keyBoxes: EdgeBox[];
|
|
176
|
-
newSyncKeys: string[];
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export type CreateLoginPayload = {
|
|
180
|
-
appId: string;
|
|
181
|
-
loginId: Uint8Array;
|
|
182
|
-
parentBox?: EdgeBox;
|
|
183
|
-
|
|
184
|
-
// The creation payload can also include fields
|
|
185
|
-
// from any of these other types, so the server should try
|
|
186
|
-
// those cleaners one-by-one and incorporate the ones that work:
|
|
187
|
-
// ...ChangeOtpPayload
|
|
188
|
-
// ...ChangePasswordPayload
|
|
189
|
-
// ...ChangePin2Payload
|
|
190
|
-
// ...ChangeRecovery2Payload
|
|
191
|
-
// ...ChangeSecretPayload
|
|
192
|
-
// ...ChangeUsernamePayload
|
|
193
|
-
// ...CreateKeysPayload
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// ---------------------------------------------------------------------
|
|
197
|
-
// response payloads
|
|
198
|
-
// ---------------------------------------------------------------------
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Data sent back when logging in requires a CAPTCHA.
|
|
202
|
-
*/
|
|
203
|
-
export type ChallengeErrorPayload = {
|
|
204
|
-
challengeId: string;
|
|
205
|
-
challengeUri: string;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Data sent back when preemptively requesting a CAPTCHA.
|
|
210
|
-
*/
|
|
211
|
-
export type CreateChallengePayload = {
|
|
212
|
-
challengeId: string;
|
|
213
|
-
challengeUri?: string;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Data sent back when looking up a login barcode.
|
|
218
|
-
*/
|
|
219
|
-
export type LobbyPayload = {
|
|
220
|
-
request: EdgeLobbyRequest;
|
|
221
|
-
replies: EdgeLobbyReply[];
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Data sent back upon successful login.
|
|
226
|
-
*/
|
|
227
|
-
export type LoginPayload = {
|
|
228
|
-
// Identity:
|
|
229
|
-
appId: string;
|
|
230
|
-
created: Date;
|
|
231
|
-
loginId: Uint8Array;
|
|
232
|
-
syncToken?: string;
|
|
233
|
-
|
|
234
|
-
// Nested logins:
|
|
235
|
-
children?: LoginPayload[];
|
|
236
|
-
parentBox?: EdgeBox;
|
|
237
|
-
|
|
238
|
-
// 2-factor login:
|
|
239
|
-
otpKey?: Uint8Array | true;
|
|
240
|
-
otpResetDate?: Date;
|
|
241
|
-
otpTimeout?: number;
|
|
242
|
-
|
|
243
|
-
// Password login:
|
|
244
|
-
passwordAuthBox?: EdgeBox;
|
|
245
|
-
passwordAuthSnrp?: EdgeSnrp;
|
|
246
|
-
passwordBox?: EdgeBox | true;
|
|
247
|
-
passwordKeySnrp?: EdgeSnrp;
|
|
248
|
-
|
|
249
|
-
// PIN v2 login:
|
|
250
|
-
pin2Box?: EdgeBox | true;
|
|
251
|
-
pin2KeyBox?: EdgeBox;
|
|
252
|
-
pin2TextBox?: EdgeBox;
|
|
253
|
-
|
|
254
|
-
// Recovery v2 login:
|
|
255
|
-
question2Box?: EdgeBox;
|
|
256
|
-
recovery2Box?: EdgeBox | true;
|
|
257
|
-
recovery2KeyBox?: EdgeBox;
|
|
258
|
-
|
|
259
|
-
// Secret-key login:
|
|
260
|
-
loginAuthBox?: EdgeBox;
|
|
261
|
-
|
|
262
|
-
// Username:
|
|
263
|
-
userId?: Uint8Array;
|
|
264
|
-
userTextBox?: EdgeBox;
|
|
265
|
-
|
|
266
|
-
// Voucher login:
|
|
267
|
-
pendingVouchers: EdgePendingVoucher[];
|
|
268
|
-
|
|
269
|
-
// Resources:
|
|
270
|
-
keyBoxes?: EdgeKeyBox[];
|
|
271
|
-
mnemonicBox?: EdgeBox;
|
|
272
|
-
rootKeyBox?: EdgeBox;
|
|
273
|
-
syncKeyBox?: EdgeBox;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Account status information sent back by the login server.
|
|
278
|
-
*/
|
|
279
|
-
export type MessagesPayload = Array<{
|
|
280
|
-
loginId: Uint8Array;
|
|
281
|
-
otpResetPending: boolean;
|
|
282
|
-
pendingVouchers: EdgePendingVoucher[];
|
|
283
|
-
recovery2Corrupt: boolean;
|
|
284
|
-
}>;
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Returned when the 2fa authentication fails.
|
|
288
|
-
*/
|
|
289
|
-
export type OtpErrorPayload = {
|
|
290
|
-
// This should usually be present:
|
|
291
|
-
login_id?: Uint8Array;
|
|
292
|
-
|
|
293
|
-
// Use this to request an OTP reset (if enabled):
|
|
294
|
-
otp_reset_auth?: string;
|
|
295
|
-
|
|
296
|
-
// Set if an OTP reset has already been requested:
|
|
297
|
-
otp_timeout_date?: Date;
|
|
298
|
-
|
|
299
|
-
// We might also get a different reason:
|
|
300
|
-
reason: "ip" | "otp";
|
|
301
|
-
|
|
302
|
-
// We might also get a login voucher:
|
|
303
|
-
voucher_activates?: Date;
|
|
304
|
-
voucher_auth?: Uint8Array;
|
|
305
|
-
voucher_id?: string;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* Returned when requesting a 2fa reset.
|
|
310
|
-
*/
|
|
311
|
-
export type OtpResetPayload = {
|
|
312
|
-
otpResetDate: Date;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* Returned when the password authentication fails.
|
|
317
|
-
*/
|
|
318
|
-
export type PasswordErrorPayload = {
|
|
319
|
-
wait_seconds?: number;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* Returned when fetching the recovery questions for an account.
|
|
324
|
-
*/
|
|
325
|
-
export type Recovery2InfoPayload = {
|
|
326
|
-
question2Box: EdgeBox;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
* Returned when fetching the password hashing options for an account.
|
|
331
|
-
*/
|
|
332
|
-
export type UsernameInfoPayload = {
|
|
333
|
-
loginId: Uint8Array;
|
|
334
|
-
|
|
335
|
-
// Password login:
|
|
336
|
-
passwordAuthSnrp?: EdgeSnrp;
|
|
337
|
-
|
|
338
|
-
// Recovery v1 login:
|
|
339
|
-
questionBox?: EdgeBox;
|
|
340
|
-
questionKeySnrp?: EdgeSnrp;
|
|
341
|
-
recoveryAuthSnrp?: EdgeSnrp;
|
|
342
|
-
}
|
package/lib/flow/type-helpers.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
EdgeCurrencyInfo,
|
|
5
|
-
EdgeSwapQuote,
|
|
6
|
-
EdgeTokenId,
|
|
7
|
-
EdgeTokenMap,
|
|
8
|
-
EdgeTransaction,
|
|
9
|
-
} from "./types";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Translates a currency code to a tokenId,
|
|
13
|
-
* and then back again for bi-directional backwards compatibility.
|
|
14
|
-
*/
|
|
15
|
-
export function upgradeCurrencyCode(opts: {
|
|
16
|
-
allTokens: EdgeTokenMap;
|
|
17
|
-
currencyInfo: EdgeCurrencyInfo;
|
|
18
|
-
currencyCode?: string;
|
|
19
|
-
tokenId?: EdgeTokenId;
|
|
20
|
-
}): { currencyCode: string; tokenId: EdgeTokenId } {
|
|
21
|
-
const { currencyInfo, allTokens } = opts;
|
|
22
|
-
|
|
23
|
-
// Find the tokenId:
|
|
24
|
-
let tokenId = opts.tokenId;
|
|
25
|
-
if (
|
|
26
|
-
tokenId === undefined &&
|
|
27
|
-
opts.currencyCode != null &&
|
|
28
|
-
opts.currencyCode !== currencyInfo.currencyCode
|
|
29
|
-
) {
|
|
30
|
-
tokenId = Object.keys(allTokens).find(
|
|
31
|
-
(tokenId) => allTokens[tokenId].currencyCode === opts.currencyCode,
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Get the currency code:
|
|
36
|
-
const { currencyCode } = tokenId == null ? currencyInfo : allTokens[tokenId];
|
|
37
|
-
|
|
38
|
-
return { currencyCode, tokenId: tokenId ?? null };
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function upgradeSwapQuote(quote: EdgeSwapQuote): EdgeSwapQuote {
|
|
42
|
-
if (quote.networkFee != null && quote.networkFee.tokenId === undefined) {
|
|
43
|
-
quote.networkFee.tokenId = null;
|
|
44
|
-
}
|
|
45
|
-
return quote;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export const upgradeTxNetworkFees = (tx: EdgeTransaction): void => {
|
|
49
|
-
if (tx.networkFees == null || tx.networkFees.length === 0) {
|
|
50
|
-
tx.networkFees = [
|
|
51
|
-
{
|
|
52
|
-
tokenId: tx.tokenId,
|
|
53
|
-
nativeAmount: tx.networkFee,
|
|
54
|
-
},
|
|
55
|
-
];
|
|
56
|
-
if (tx.parentNetworkFee != null) {
|
|
57
|
-
tx.networkFees.push({ tokenId: null, nativeAmount: tx.parentNetworkFee });
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
};
|