edge-core-js 2.45.0 → 2.46.1
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 +10 -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 +2 -7
- 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/types/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "edge-core-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.46.1",
|
|
4
4
|
"description": "Edge account & wallet management library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bitcoin",
|
|
@@ -54,7 +54,6 @@
|
|
|
54
54
|
"/README.md",
|
|
55
55
|
"/src/types/",
|
|
56
56
|
"/types.d.ts",
|
|
57
|
-
"/types.js.flow",
|
|
58
57
|
"/types.js",
|
|
59
58
|
"/types.mjs"
|
|
60
59
|
],
|
|
@@ -62,7 +61,6 @@
|
|
|
62
61
|
"build.lib": "sucrase ./src -q -d ./lib -t typescript,jsx",
|
|
63
62
|
"build.node": "rollup -c",
|
|
64
63
|
"build.react-native": "webpack",
|
|
65
|
-
"build.types": "node -r sucrase/register ./scripts/make-types.ts && flow",
|
|
66
64
|
"clean": "rimraf lib android/src/main/assets",
|
|
67
65
|
"fix.android": "(cd android; ./format-java.sh)",
|
|
68
66
|
"fix.ios": "swift-format format -i ios/*.swift",
|
|
@@ -98,7 +96,7 @@
|
|
|
98
96
|
"rfc4648": "^1.5.3",
|
|
99
97
|
"scrypt-js": "^2.0.3",
|
|
100
98
|
"serverlet": "^0.1.2",
|
|
101
|
-
"yaob": "^0.
|
|
99
|
+
"yaob": "^0.4.0",
|
|
102
100
|
"yavent": "^0.1.5"
|
|
103
101
|
},
|
|
104
102
|
"devDependencies": {
|
|
@@ -129,14 +127,12 @@
|
|
|
129
127
|
"copy-webpack-plugin": "^13.0.1",
|
|
130
128
|
"eslint": "^7.32.0",
|
|
131
129
|
"eslint-config-standard-kit": "0.15.1",
|
|
132
|
-
"eslint-plugin-flowtype": "^5.2.0",
|
|
133
130
|
"eslint-plugin-import": "^2.25.3",
|
|
134
131
|
"eslint-plugin-node": "^11.1.0",
|
|
135
132
|
"eslint-plugin-prettier": "^5.0.0",
|
|
136
133
|
"eslint-plugin-promise": "^4.2.1",
|
|
137
134
|
"eslint-plugin-react": "^7.20.6",
|
|
138
135
|
"eslint-plugin-simple-import-sort": "^6.0.1",
|
|
139
|
-
"flow-bin": "^0.89.0",
|
|
140
136
|
"husky": "^7.0.0",
|
|
141
137
|
"lint-staged": "^10.2.11",
|
|
142
138
|
"mocha": "^10.6.0",
|
|
@@ -145,7 +141,6 @@
|
|
|
145
141
|
"process": "^0.11.10",
|
|
146
142
|
"rimraf": "^3.0.2",
|
|
147
143
|
"rollup": "^2.80.0",
|
|
148
|
-
"rollup-plugin-flow-entry": "^0.3.6",
|
|
149
144
|
"rollup-plugin-mjs-entry": "^0.1.1",
|
|
150
145
|
"stream-browserify": "^3.0.0",
|
|
151
146
|
"sucrase": "^3.20.0",
|
package/src/types/types.ts
CHANGED
|
@@ -543,6 +543,7 @@ export interface EdgeCurrencyInfo {
|
|
|
543
543
|
unsafeMakeSpend?: boolean
|
|
544
544
|
unsafeSyncNetwork?: boolean
|
|
545
545
|
usesChangeServer?: boolean
|
|
546
|
+
hasWalletSettings?: boolean
|
|
546
547
|
|
|
547
548
|
/** Show the total sync percentage with this many decimal digits */
|
|
548
549
|
syncDisplayPrecision?: number
|
|
@@ -1043,10 +1044,12 @@ export interface EdgeCurrencyEngineOptions {
|
|
|
1043
1044
|
customTokens: EdgeTokenMap
|
|
1044
1045
|
enabledTokenIds: string[]
|
|
1045
1046
|
userSettings: JsonObject | undefined
|
|
1047
|
+
walletSettings: JsonObject
|
|
1046
1048
|
}
|
|
1047
1049
|
|
|
1048
1050
|
export interface EdgeCurrencyEngine {
|
|
1049
1051
|
readonly changeUserSettings: (settings: JsonObject) => Promise<void>
|
|
1052
|
+
readonly changeWalletSettings?: (settings: JsonObject) => Promise<void>
|
|
1050
1053
|
|
|
1051
1054
|
/**
|
|
1052
1055
|
* Starts any persistent resources the engine needs, such as WebSockets.
|
|
@@ -1329,6 +1332,7 @@ export interface EdgeCurrencyWallet {
|
|
|
1329
1332
|
readonly created: Date | undefined
|
|
1330
1333
|
readonly disklet: Disklet
|
|
1331
1334
|
readonly id: string
|
|
1335
|
+
readonly imported: boolean
|
|
1332
1336
|
readonly localDisklet: Disklet
|
|
1333
1337
|
readonly publicWalletInfo: EdgeWalletInfo
|
|
1334
1338
|
readonly sync: () => Promise<void>
|
|
@@ -1346,6 +1350,10 @@ export interface EdgeCurrencyWallet {
|
|
|
1346
1350
|
readonly currencyConfig: EdgeCurrencyConfig // eslint-disable-line no-use-before-define
|
|
1347
1351
|
readonly currencyInfo: EdgeCurrencyInfo
|
|
1348
1352
|
|
|
1353
|
+
// User settings for this wallet:
|
|
1354
|
+
readonly walletSettings: JsonObject
|
|
1355
|
+
readonly changeWalletSettings: (settings: JsonObject) => Promise<void>
|
|
1356
|
+
|
|
1349
1357
|
// Chain state:
|
|
1350
1358
|
readonly balanceMap: EdgeBalanceMap
|
|
1351
1359
|
readonly balances: EdgeBalances
|
|
@@ -1652,6 +1660,7 @@ export interface EdgeCreateCurrencyWalletOptions {
|
|
|
1652
1660
|
enabledTokenIds?: string[]
|
|
1653
1661
|
fiatCurrencyCode?: string
|
|
1654
1662
|
name?: string
|
|
1663
|
+
walletSettings?: JsonObject
|
|
1655
1664
|
|
|
1656
1665
|
// Create a private key from some text:
|
|
1657
1666
|
importText?: string
|
package/lib/flow/error.js
DELETED
|
@@ -1,448 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
import type { Cleaner } from "cleaners";
|
|
4
|
-
import { asMaybe } from "cleaners";
|
|
5
|
-
import { base64 } from "rfc4648";
|
|
6
|
-
|
|
7
|
-
import { asOtpErrorPayload, asPasswordErrorPayload } from "./server-cleaners";
|
|
8
|
-
import type { ChallengeErrorPayload } from "./server-types";
|
|
9
|
-
import type { EdgeSwapInfo, EdgeSwapRequest, EdgeTokenId } from "./types";
|
|
10
|
-
|
|
11
|
-
/*
|
|
12
|
-
* These are errors the core knows about.
|
|
13
|
-
*
|
|
14
|
-
* The GUI should handle these errors in an "intelligent" way, such as by
|
|
15
|
-
* displaying a localized error message or asking the user for more info.
|
|
16
|
-
* All these errors have a `name` field, which the GUI can use to select
|
|
17
|
-
* the appropriate response.
|
|
18
|
-
*
|
|
19
|
-
* Other errors are possible, of course, since the Javascript language
|
|
20
|
-
* itself can generate exceptions. Those errors won't have a `type` field,
|
|
21
|
-
* and the GUI should just show them with a stack trace & generic message,
|
|
22
|
-
* since the program has basically crashed at that point.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Thrown when the login server requires a CAPTCHA.
|
|
27
|
-
*
|
|
28
|
-
* After showing the WebView with the challengeUri,
|
|
29
|
-
* pass the challengeId to the login method
|
|
30
|
-
* (such as loginWithPassword) to complete the login.
|
|
31
|
-
*
|
|
32
|
-
* The challengeUri web page will signal that it is done by navigating
|
|
33
|
-
* to a new location that ends with either /success or /failure,
|
|
34
|
-
* such as https://login.edge.app/challenge/success
|
|
35
|
-
* The login UI can use this as a signal to close the WebView.
|
|
36
|
-
*/
|
|
37
|
-
export class ChallengeError extends Error {
|
|
38
|
-
name: string;
|
|
39
|
-
challengeId: string;
|
|
40
|
-
challengeUri: string;
|
|
41
|
-
|
|
42
|
-
constructor(
|
|
43
|
-
resultsJson: ChallengeErrorPayload,
|
|
44
|
-
message: string = "Login requires a CAPTCHA",
|
|
45
|
-
) {
|
|
46
|
-
super(message);
|
|
47
|
-
this.name = "ChallengeError";
|
|
48
|
-
this.challengeId = resultsJson.challengeId;
|
|
49
|
-
this.challengeUri = resultsJson.challengeUri;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Trying to spend an uneconomically small amount of money.
|
|
55
|
-
*/
|
|
56
|
-
export class DustSpendError extends Error {
|
|
57
|
-
name: string;
|
|
58
|
-
|
|
59
|
-
constructor(message: string = "Please send a larger amount") {
|
|
60
|
-
super(message);
|
|
61
|
-
this.name = "DustSpendError";
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
type InsufficientFundsErrorOpts = {
|
|
66
|
-
// The currency we need more of:
|
|
67
|
-
tokenId: EdgeTokenId;
|
|
68
|
-
// If we don't have enough funds for a token send:
|
|
69
|
-
networkFee?: string;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Trying to spend more money than the wallet contains.
|
|
74
|
-
*/
|
|
75
|
-
export class InsufficientFundsError extends Error {
|
|
76
|
-
name: string;
|
|
77
|
-
+tokenId: EdgeTokenId;
|
|
78
|
-
+networkFee: string | void;
|
|
79
|
-
|
|
80
|
-
// Passing a string is deprecated
|
|
81
|
-
constructor(opts: InsufficientFundsErrorOpts) {
|
|
82
|
-
const { tokenId = null, networkFee } = opts ?? {};
|
|
83
|
-
super(`Insufficient ${tokenId ?? "funds"}`);
|
|
84
|
-
this.tokenId = tokenId;
|
|
85
|
-
this.networkFee = networkFee;
|
|
86
|
-
this.name = "InsufficientFundsError";
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Could not reach the server at all.
|
|
92
|
-
*/
|
|
93
|
-
export class NetworkError extends Error {
|
|
94
|
-
name: string;
|
|
95
|
-
|
|
96
|
-
constructor(message: string = "Cannot reach the network") {
|
|
97
|
-
super(message);
|
|
98
|
-
this.name = "NetworkError";
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Attempting to create a MakeSpend without specifying an amount of currency to send
|
|
104
|
-
*/
|
|
105
|
-
export class NoAmountSpecifiedError extends Error {
|
|
106
|
-
name: string;
|
|
107
|
-
|
|
108
|
-
constructor(message: string = "Unable to create zero-amount transaction.") {
|
|
109
|
-
super(message);
|
|
110
|
-
this.name = "NoAmountSpecifiedError";
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* The endpoint on the server is obsolete, and the app needs to be upgraded.
|
|
116
|
-
*/
|
|
117
|
-
export class ObsoleteApiError extends Error {
|
|
118
|
-
name: string;
|
|
119
|
-
|
|
120
|
-
constructor(message: string = "The application is too old. Please upgrade.") {
|
|
121
|
-
super(message);
|
|
122
|
-
this.name = "ObsoleteApiError";
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* The OTP token was missing / incorrect.
|
|
128
|
-
*
|
|
129
|
-
* The error object should include a `resetToken` member,
|
|
130
|
-
* which can be used to reset OTP protection on the account.
|
|
131
|
-
*
|
|
132
|
-
* The error object may include a `resetDate` member,
|
|
133
|
-
* which indicates that an OTP reset is already pending,
|
|
134
|
-
* and when it will complete.
|
|
135
|
-
*/
|
|
136
|
-
export class OtpError extends Error {
|
|
137
|
-
name: string;
|
|
138
|
-
+loginId: string | void; // base64, to avoid a breaking change
|
|
139
|
-
+reason: "ip" | "otp";
|
|
140
|
-
+resetDate: Date | void;
|
|
141
|
-
+resetToken: string | void;
|
|
142
|
-
+voucherId: string | void;
|
|
143
|
-
+voucherAuth: string | void; // base64, to avoid a breaking change
|
|
144
|
-
+voucherActivates: Date | void;
|
|
145
|
-
|
|
146
|
-
constructor(resultsJson: mixed, message: string = "Invalid OTP token") {
|
|
147
|
-
super(message);
|
|
148
|
-
this.name = "OtpError";
|
|
149
|
-
this.reason = "otp";
|
|
150
|
-
|
|
151
|
-
const clean = asMaybe(asOtpErrorPayload)(resultsJson);
|
|
152
|
-
if (clean == null) return;
|
|
153
|
-
|
|
154
|
-
if (clean.login_id != null) {
|
|
155
|
-
this.loginId = base64.stringify(clean.login_id);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
this.resetToken = clean.otp_reset_auth;
|
|
159
|
-
this.reason = clean.reason;
|
|
160
|
-
this.resetDate = clean.otp_timeout_date;
|
|
161
|
-
|
|
162
|
-
this.voucherActivates = clean.voucher_activates;
|
|
163
|
-
if (clean.voucher_auth != null) {
|
|
164
|
-
this.voucherAuth = base64.stringify(clean.voucher_auth);
|
|
165
|
-
}
|
|
166
|
-
this.voucherId = clean.voucher_id;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* The provided authentication is incorrect.
|
|
172
|
-
*
|
|
173
|
-
* Reasons could include:
|
|
174
|
-
* - Password login: wrong password
|
|
175
|
-
* - PIN login: wrong PIN
|
|
176
|
-
* - Recovery login: wrong answers
|
|
177
|
-
*
|
|
178
|
-
* The error object may include a `wait` member,
|
|
179
|
-
* which is the number of seconds the user must wait before trying again.
|
|
180
|
-
*/
|
|
181
|
-
export class PasswordError extends Error {
|
|
182
|
-
name: string;
|
|
183
|
-
+wait: number | void; // seconds
|
|
184
|
-
|
|
185
|
-
constructor(resultsJson: mixed, message: string = "Invalid password") {
|
|
186
|
-
super(message);
|
|
187
|
-
this.name = "PasswordError";
|
|
188
|
-
|
|
189
|
-
const clean = asMaybe(asPasswordErrorPayload)(resultsJson);
|
|
190
|
-
if (clean == null) return;
|
|
191
|
-
|
|
192
|
-
this.wait = clean.wait_seconds;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* PIN login is not enabled for this account on this device.
|
|
198
|
-
*/
|
|
199
|
-
export class PinDisabledError extends Error {
|
|
200
|
-
name: string;
|
|
201
|
-
|
|
202
|
-
constructor(message: string) {
|
|
203
|
-
super(message);
|
|
204
|
-
this.name = "PinDisabledError";
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Trying to spend funds that are not yet confirmed.
|
|
210
|
-
*/
|
|
211
|
-
export class PendingFundsError extends Error {
|
|
212
|
-
name: string;
|
|
213
|
-
|
|
214
|
-
constructor(message: string = "Not enough confirmed funds") {
|
|
215
|
-
super(message);
|
|
216
|
-
this.name = "PendingFundsError";
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Attempting to shape shift between two wallets of same currency.
|
|
222
|
-
*/
|
|
223
|
-
export class SameCurrencyError extends Error {
|
|
224
|
-
name: string;
|
|
225
|
-
|
|
226
|
-
constructor(message: string = "Wallets can not be the same currency") {
|
|
227
|
-
super(message);
|
|
228
|
-
this.name = "SameCurrencyError";
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Trying to spend to an address of the source wallet
|
|
234
|
-
*/
|
|
235
|
-
export class SpendToSelfError extends Error {
|
|
236
|
-
name: string;
|
|
237
|
-
|
|
238
|
-
constructor(message: string = "Spending to self") {
|
|
239
|
-
super(message);
|
|
240
|
-
this.name = "SpendToSelfError";
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Trying to swap an amount that is either too low or too high.
|
|
246
|
-
* @param nativeMax the maximum supported amount, in the currency specified
|
|
247
|
-
* by the direction (defaults to "from" currency)
|
|
248
|
-
*/
|
|
249
|
-
export class SwapAboveLimitError extends Error {
|
|
250
|
-
name: string;
|
|
251
|
-
|
|
252
|
-
/** @deprecated use swapPluginId */
|
|
253
|
-
+pluginId: string;
|
|
254
|
-
+swapPluginId: string;
|
|
255
|
-
|
|
256
|
-
/** This will be '' if the limit is not known */
|
|
257
|
-
+nativeMax: string;
|
|
258
|
-
+direction: "from" | "to";
|
|
259
|
-
|
|
260
|
-
constructor(
|
|
261
|
-
swapInfo: EdgeSwapInfo,
|
|
262
|
-
nativeMax: string | void,
|
|
263
|
-
direction: "from" | "to" = "from",
|
|
264
|
-
) {
|
|
265
|
-
super("Amount is too high");
|
|
266
|
-
this.name = "SwapAboveLimitError";
|
|
267
|
-
this.pluginId = swapInfo.pluginId;
|
|
268
|
-
this.swapPluginId = swapInfo.pluginId;
|
|
269
|
-
this.nativeMax = nativeMax ?? "";
|
|
270
|
-
this.direction = direction;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Trying to swap an amount that is either too low or too high.
|
|
276
|
-
* @param nativeMin the minimum supported amount, in the currency specified
|
|
277
|
-
* by the direction (defaults to "from" currency)
|
|
278
|
-
*/
|
|
279
|
-
export class SwapBelowLimitError extends Error {
|
|
280
|
-
name: string;
|
|
281
|
-
|
|
282
|
-
/** @deprecated use swapPluginId */
|
|
283
|
-
+pluginId: string;
|
|
284
|
-
+swapPluginId: string;
|
|
285
|
-
|
|
286
|
-
/** This will be '' if the limit is not known */
|
|
287
|
-
+nativeMin: string;
|
|
288
|
-
+direction: "from" | "to";
|
|
289
|
-
|
|
290
|
-
constructor(
|
|
291
|
-
swapInfo: EdgeSwapInfo,
|
|
292
|
-
nativeMin: string | void,
|
|
293
|
-
direction: "from" | "to" = "from",
|
|
294
|
-
) {
|
|
295
|
-
super("Amount is too low");
|
|
296
|
-
this.name = "SwapBelowLimitError";
|
|
297
|
-
this.pluginId = swapInfo.pluginId;
|
|
298
|
-
this.swapPluginId = swapInfo.pluginId;
|
|
299
|
-
this.nativeMin = nativeMin ?? "";
|
|
300
|
-
this.direction = direction;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* The swap plugin does not support this currency pair.
|
|
306
|
-
*/
|
|
307
|
-
export class SwapCurrencyError extends Error {
|
|
308
|
-
name: string;
|
|
309
|
-
+pluginId: string;
|
|
310
|
-
+fromTokenId: EdgeTokenId;
|
|
311
|
-
+toTokenId: EdgeTokenId;
|
|
312
|
-
|
|
313
|
-
constructor(swapInfo: EdgeSwapInfo, request: EdgeSwapRequest) {
|
|
314
|
-
const { fromWallet, toWallet, fromTokenId, toTokenId } = request;
|
|
315
|
-
const fromPluginId = fromWallet.currencyConfig.currencyInfo.pluginId;
|
|
316
|
-
const toPluginId = toWallet.currencyConfig.currencyInfo.pluginId;
|
|
317
|
-
|
|
318
|
-
const fromString = `${fromPluginId}:${String(fromTokenId)}`;
|
|
319
|
-
const toString = `${toPluginId}:${String(toTokenId)}`;
|
|
320
|
-
|
|
321
|
-
super(
|
|
322
|
-
`${swapInfo.displayName} does not support ${fromString} to ${toString}`,
|
|
323
|
-
);
|
|
324
|
-
this.name = "SwapCurrencyError";
|
|
325
|
-
this.pluginId = swapInfo.pluginId;
|
|
326
|
-
this.fromTokenId = fromTokenId ?? null;
|
|
327
|
-
this.toTokenId = toTokenId ?? null;
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
type SwapPermissionReason =
|
|
332
|
-
| "geoRestriction"
|
|
333
|
-
| "noVerification"
|
|
334
|
-
| "needsActivation";
|
|
335
|
-
|
|
336
|
-
/**
|
|
337
|
-
* The user is not allowed to swap these coins for some reason
|
|
338
|
-
* (no KYC, restricted IP address, etc...).
|
|
339
|
-
* @param reason A string giving the reason for the denial.
|
|
340
|
-
* - 'geoRestriction': The IP address is in a restricted region
|
|
341
|
-
* - 'noVerification': The user needs to provide KYC credentials
|
|
342
|
-
* - 'needsActivation': The user needs to log into the service.
|
|
343
|
-
*/
|
|
344
|
-
export class SwapPermissionError extends Error {
|
|
345
|
-
name: string;
|
|
346
|
-
+pluginId: string;
|
|
347
|
-
+reason: SwapPermissionReason | void;
|
|
348
|
-
|
|
349
|
-
constructor(swapInfo: EdgeSwapInfo, reason?: SwapPermissionReason) {
|
|
350
|
-
if (reason != null) super(reason);
|
|
351
|
-
else super("You are not allowed to make this trade");
|
|
352
|
-
this.name = "SwapPermissionError";
|
|
353
|
-
this.pluginId = swapInfo.pluginId;
|
|
354
|
-
this.reason = reason;
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
// Address requirements for certain swap flows (extend as needed):
|
|
359
|
-
export type SwapAddressReason = "mustMatch" | "mustBeActivated";
|
|
360
|
-
|
|
361
|
-
export class SwapAddressError extends Error {
|
|
362
|
-
name: string;
|
|
363
|
-
+swapPluginId: string;
|
|
364
|
-
+reason: SwapAddressReason;
|
|
365
|
-
|
|
366
|
-
constructor(swapInfo: EdgeSwapInfo, opts: { reason: SwapAddressReason }) {
|
|
367
|
-
const { reason } = opts;
|
|
368
|
-
switch (reason) {
|
|
369
|
-
case "mustMatch":
|
|
370
|
-
super(
|
|
371
|
-
"This swap requires from and to wallets to have the same address",
|
|
372
|
-
);
|
|
373
|
-
break;
|
|
374
|
-
case "mustBeActivated":
|
|
375
|
-
super("The destination wallet must be activated to receive this swap.");
|
|
376
|
-
break;
|
|
377
|
-
default:
|
|
378
|
-
super("Invalid swap address");
|
|
379
|
-
}
|
|
380
|
-
this.name = "SwapAddressError";
|
|
381
|
-
this.swapPluginId = swapInfo.pluginId;
|
|
382
|
-
this.reason = reason;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* Cannot find a login with that id.
|
|
388
|
-
*
|
|
389
|
-
* Reasons could include:
|
|
390
|
-
* - Password login: wrong username
|
|
391
|
-
* - PIN login: wrong PIN key
|
|
392
|
-
* - Recovery login: wrong username, or wrong recovery key
|
|
393
|
-
*/
|
|
394
|
-
export class UsernameError extends Error {
|
|
395
|
-
name: string;
|
|
396
|
-
|
|
397
|
-
constructor(message: string = "Invalid username") {
|
|
398
|
-
super(message);
|
|
399
|
-
this.name = "UsernameError";
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
function asMaybeError<T>(name: string): Cleaner<T | void> {
|
|
404
|
-
return function asError(raw) {
|
|
405
|
-
if (raw instanceof Error && raw.name === name) {
|
|
406
|
-
const typeHack: any = raw;
|
|
407
|
-
return typeHack;
|
|
408
|
-
}
|
|
409
|
-
};
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
export const asMaybeChallengeError =
|
|
413
|
-
asMaybeError<ChallengeError>("ChallengeError");
|
|
414
|
-
export const asMaybeDustSpendError =
|
|
415
|
-
asMaybeError<DustSpendError>("DustSpendError");
|
|
416
|
-
export const asMaybeInsufficientFundsError =
|
|
417
|
-
asMaybeError<InsufficientFundsError>("InsufficientFundsError");
|
|
418
|
-
export const asMaybeNetworkError = asMaybeError<NetworkError>("NetworkError");
|
|
419
|
-
export const asMaybeNoAmountSpecifiedError =
|
|
420
|
-
asMaybeError<NoAmountSpecifiedError>("NoAmountSpecifiedError");
|
|
421
|
-
export const asMaybeObsoleteApiError =
|
|
422
|
-
asMaybeError<ObsoleteApiError>("ObsoleteApiError");
|
|
423
|
-
export const asMaybeOtpError = asMaybeError<OtpError>("OtpError");
|
|
424
|
-
export const asMaybePasswordError =
|
|
425
|
-
asMaybeError<PasswordError>("PasswordError");
|
|
426
|
-
export const asMaybePinDisabledError =
|
|
427
|
-
asMaybeError<PinDisabledError>("PinDisabledError");
|
|
428
|
-
export const asMaybePendingFundsError =
|
|
429
|
-
asMaybeError<PendingFundsError>("PendingFundsError");
|
|
430
|
-
export const asMaybeSameCurrencyError =
|
|
431
|
-
asMaybeError<SameCurrencyError>("SameCurrencyError");
|
|
432
|
-
export const asMaybeSpendToSelfError =
|
|
433
|
-
asMaybeError<SpendToSelfError>("SpendToSelfError");
|
|
434
|
-
export const asMaybeSwapAboveLimitError = asMaybeError<SwapAboveLimitError>(
|
|
435
|
-
"SwapAboveLimitError",
|
|
436
|
-
);
|
|
437
|
-
export const asMaybeSwapBelowLimitError = asMaybeError<SwapBelowLimitError>(
|
|
438
|
-
"SwapBelowLimitError",
|
|
439
|
-
);
|
|
440
|
-
export const asMaybeSwapCurrencyError =
|
|
441
|
-
asMaybeError<SwapCurrencyError>("SwapCurrencyError");
|
|
442
|
-
export const asMaybeSwapPermissionError = asMaybeError<SwapPermissionError>(
|
|
443
|
-
"SwapPermissionError",
|
|
444
|
-
);
|
|
445
|
-
export const asMaybeSwapAddressError =
|
|
446
|
-
asMaybeError<SwapAddressError>("SwapAddressError");
|
|
447
|
-
export const asMaybeUsernameError =
|
|
448
|
-
asMaybeError<UsernameError>("UsernameError");
|
package/lib/flow/exports.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
EdgeContext,
|
|
5
|
-
EdgeContextOptions,
|
|
6
|
-
EdgeCorePlugins,
|
|
7
|
-
EdgeCorePluginsInit,
|
|
8
|
-
EdgeCrashReporter,
|
|
9
|
-
EdgeFakeUser,
|
|
10
|
-
EdgeFakeWorld,
|
|
11
|
-
EdgeFakeWorldOptions,
|
|
12
|
-
EdgeIo,
|
|
13
|
-
EdgeLoginMessage,
|
|
14
|
-
EdgeLogSettings,
|
|
15
|
-
EdgeNativeIo,
|
|
16
|
-
EdgeOnLog,
|
|
17
|
-
} from "./types";
|
|
18
|
-
|
|
19
|
-
export * from "./types";
|
|
20
|
-
|
|
21
|
-
declare export function addEdgeCorePlugins(plugins: EdgeCorePlugins): void;
|
|
22
|
-
declare export function lockEdgeCorePlugins(): void;
|
|
23
|
-
declare export function closeEdge(): void;
|
|
24
|
-
declare export function makeFakeIo(): EdgeIo;
|
|
25
|
-
|
|
26
|
-
// System-specific io exports:
|
|
27
|
-
declare export function makeBrowserIo(): EdgeIo;
|
|
28
|
-
declare export function makeNodeIo(path: string): EdgeIo;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Initializes the Edge core library,
|
|
32
|
-
* automatically selecting the appropriate platform.
|
|
33
|
-
*/
|
|
34
|
-
declare export function makeEdgeContext(
|
|
35
|
-
opts: EdgeContextOptions,
|
|
36
|
-
): Promise<EdgeContext>;
|
|
37
|
-
|
|
38
|
-
declare export function makeFakeEdgeWorld(
|
|
39
|
-
users?: EdgeFakeUser[],
|
|
40
|
-
opts?: EdgeFakeWorldOptions,
|
|
41
|
-
): Promise<EdgeFakeWorld>;
|
|
42
|
-
|
|
43
|
-
// ---------------------------------------------------------------------
|
|
44
|
-
// react-native
|
|
45
|
-
// ---------------------------------------------------------------------
|
|
46
|
-
|
|
47
|
-
type CommonProps = {
|
|
48
|
-
// Allows the Chrome debugger to attach to the Android WebView.
|
|
49
|
-
// This is mainly useful for debugging plugins,
|
|
50
|
-
// since the `debug` prop also activates Chrome debugging.
|
|
51
|
-
allowDebugging?: boolean;
|
|
52
|
-
|
|
53
|
-
// Enable core debugging.
|
|
54
|
-
// You must call `yarn start` in the edge-core-js project for this to work:
|
|
55
|
-
debug?: boolean;
|
|
56
|
-
|
|
57
|
-
// React Native modules to pass over the bridge to the plugins:
|
|
58
|
-
nativeIo?: EdgeNativeIo;
|
|
59
|
-
|
|
60
|
-
// Extra JavaScript files to load into the core as plugins.
|
|
61
|
-
// Relative URL's resolve to the app's default asset location:
|
|
62
|
-
pluginUris?: string[];
|
|
63
|
-
|
|
64
|
-
// Called if something goes wrong when starting the core:
|
|
65
|
-
// This will change to `(error: mixed) => void`
|
|
66
|
-
onError?: (error: any) => mixed;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export type EdgeContextProps = {
|
|
70
|
-
...$Exact<CommonProps>;
|
|
71
|
-
/**
|
|
72
|
-
* Called once the core finishes loading.
|
|
73
|
-
* The return type will change to `=> void`
|
|
74
|
-
*/
|
|
75
|
-
onLoad: (context: EdgeContext) => mixed;
|
|
76
|
-
|
|
77
|
-
// EdgeFakeWorldOptions:
|
|
78
|
-
crashReporter?: EdgeCrashReporter;
|
|
79
|
-
onLog?: EdgeOnLog;
|
|
80
|
-
|
|
81
|
-
// EdgeContextOptions:
|
|
82
|
-
airbitzSupport?: boolean;
|
|
83
|
-
apiKey?: string;
|
|
84
|
-
apiSecret?: Uint8Array;
|
|
85
|
-
appId?: string;
|
|
86
|
-
appVersion?: string;
|
|
87
|
-
osType?: string;
|
|
88
|
-
osVersion?: string;
|
|
89
|
-
changeServer?: string | string[];
|
|
90
|
-
infoServer?: string | string[];
|
|
91
|
-
loginServer?: string | string[]; // Do not include `/api` in the path
|
|
92
|
-
syncServer?: string | string[];
|
|
93
|
-
deviceDescription?: string;
|
|
94
|
-
hideKeys?: boolean;
|
|
95
|
-
logSettings?: $Rest<EdgeLogSettings, { ... }>;
|
|
96
|
-
plugins?: EdgeCorePluginsInit;
|
|
97
|
-
skipBlockHeight?: boolean;
|
|
98
|
-
|
|
99
|
-
/** @deprecated Use `loginServer` instead */
|
|
100
|
-
authServer?: string;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export type EdgeFakeWorldProps = {
|
|
104
|
-
...$Exact<CommonProps>;
|
|
105
|
-
/**
|
|
106
|
-
* Called once the core finishes loading.
|
|
107
|
-
* The return type will change to `=> void`
|
|
108
|
-
*/
|
|
109
|
-
onLoad: (world: EdgeFakeWorld) => mixed;
|
|
110
|
-
users?: EdgeFakeUser[];
|
|
111
|
-
|
|
112
|
-
// EdgeFakeWorldOptions:
|
|
113
|
-
crashReporter?: EdgeCrashReporter;
|
|
114
|
-
onLog?: EdgeOnLog;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* We don't want this library to depend on `@types/react`,
|
|
119
|
-
* since that isn't relevant for our Node or browser builds.
|
|
120
|
-
*/
|
|
121
|
-
type ComponentType<Props> = (props: Props) => {
|
|
122
|
-
type: any;
|
|
123
|
-
props: any;
|
|
124
|
-
key: string | null;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* React Native component for creating an EdgeContext.
|
|
129
|
-
*/
|
|
130
|
-
declare export var MakeEdgeContext: React$ComponentType<EdgeContextProps>;
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* React Native component for creating an EdgeFakeWorld for testing.
|
|
134
|
-
*/
|
|
135
|
-
declare export var MakeFakeEdgeWorld: React$ComponentType<EdgeFakeWorldProps>;
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* React Native function for getting login alerts without a context:
|
|
139
|
-
*/
|
|
140
|
-
declare export function fetchLoginMessages(apiKey: string): EdgeLoginMessage[];
|