@ledgerhq/live-common 22.0.3 → 22.1.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.
Files changed (95) hide show
  1. package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.dogecoin.test.d.ts +2 -0
  2. package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.dogecoin.test.d.ts.map +1 -0
  3. package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.dogecoin.test.js +147 -0
  4. package/lib/__tests__/families/bitcoin/wallet-btc/xpub.txs.dogecoin.test.js.map +1 -0
  5. package/lib/api/Ripple.d.ts +17 -21
  6. package/lib/api/Ripple.d.ts.map +1 -1
  7. package/lib/api/Ripple.js +117 -176
  8. package/lib/api/Ripple.js.map +1 -1
  9. package/lib/api/index.d.ts.map +1 -1
  10. package/lib/api/index.js +1 -5
  11. package/lib/api/index.js.map +1 -1
  12. package/lib/env.d.ts +6 -6
  13. package/lib/env.d.ts.map +1 -1
  14. package/lib/env.js +3 -3
  15. package/lib/env.js.map +1 -1
  16. package/lib/env.react.d.ts +1 -1
  17. package/lib/env.react.d.ts.map +1 -1
  18. package/lib/errors.d.ts +3 -0
  19. package/lib/errors.d.ts.map +1 -1
  20. package/lib/errors.js +2 -1
  21. package/lib/errors.js.map +1 -1
  22. package/lib/families/bitcoin/getAccountNetworkInfo.d.ts.map +1 -1
  23. package/lib/families/bitcoin/getAccountNetworkInfo.js +4 -2
  24. package/lib/families/bitcoin/getAccountNetworkInfo.js.map +1 -1
  25. package/lib/families/bitcoin/specs.d.ts.map +1 -1
  26. package/lib/families/bitcoin/specs.js +5 -2
  27. package/lib/families/bitcoin/specs.js.map +1 -1
  28. package/lib/families/bitcoin/wallet-btc/utils.d.ts +2 -0
  29. package/lib/families/bitcoin/wallet-btc/utils.d.ts.map +1 -1
  30. package/lib/families/bitcoin/wallet-btc/utils.js +9 -1
  31. package/lib/families/bitcoin/wallet-btc/utils.js.map +1 -1
  32. package/lib/families/bitcoin/wallet-btc/wallet.d.ts.map +1 -1
  33. package/lib/families/bitcoin/wallet-btc/wallet.js +11 -11
  34. package/lib/families/bitcoin/wallet-btc/wallet.js.map +1 -1
  35. package/lib/families/cosmos/js-prepareTransaction.d.ts.map +1 -1
  36. package/lib/families/cosmos/js-prepareTransaction.js +29 -5
  37. package/lib/families/cosmos/js-prepareTransaction.js.map +1 -1
  38. package/lib/families/cosmos/js-signOperation.d.ts.map +1 -1
  39. package/lib/families/cosmos/js-signOperation.js +76 -39
  40. package/lib/families/cosmos/js-signOperation.js.map +1 -1
  41. package/lib/families/cosmos/validators.js +1 -1
  42. package/lib/families/ripple/bridge/js.d.ts +2 -1
  43. package/lib/families/ripple/bridge/js.d.ts.map +1 -1
  44. package/lib/families/ripple/bridge/js.js +96 -466
  45. package/lib/families/ripple/bridge/js.js.map +1 -1
  46. package/lib/families/ripple/bridge.test.js +0 -48
  47. package/lib/families/ripple/bridge.test.js.map +1 -1
  48. package/lib/families/ripple/js-synchronization.d.ts +10 -0
  49. package/lib/families/ripple/js-synchronization.d.ts.map +1 -0
  50. package/lib/families/ripple/js-synchronization.js +156 -0
  51. package/lib/families/ripple/js-synchronization.js.map +1 -0
  52. package/lib/families/ripple/test-dataset.d.ts.map +1 -1
  53. package/lib/families/ripple/test-dataset.js +1 -1
  54. package/lib/families/ripple/test-dataset.js.map +1 -1
  55. package/lib/families/ripple/types.api.d.ts +24 -0
  56. package/lib/families/ripple/types.api.d.ts.map +1 -0
  57. package/lib/families/ripple/types.api.js +3 -0
  58. package/lib/families/ripple/types.api.js.map +1 -0
  59. package/lib/families/solana/api/chain/instruction/token/types.d.ts +3 -3
  60. package/lib/featureFlags/defaultFeatures.d.ts.map +1 -1
  61. package/lib/featureFlags/defaultFeatures.js +46 -0
  62. package/lib/featureFlags/defaultFeatures.js.map +1 -1
  63. package/lib/featureFlags/types.d.ts +2 -1
  64. package/lib/featureFlags/types.d.ts.map +1 -1
  65. package/lib/platform/providers/GlobalCatalogProvider/api/mock.json +0 -26
  66. package/lib/platform/providers/RemoteLiveAppProvider/api/mock.json +0 -63
  67. package/lib/types/nft.d.ts +1 -1
  68. package/lib/types/nft.d.ts.map +1 -1
  69. package/package.json +7 -7
  70. package/src/__tests__/families/bitcoin/wallet-btc/xpub.txs.dogecoin.test.ts +96 -0
  71. package/src/api/Ripple.ts +95 -160
  72. package/src/api/index.ts +0 -2
  73. package/src/currencies/__snapshots__/sortByMarketcap.test.ts.snap +47 -3
  74. package/src/env.ts +3 -3
  75. package/src/errors.ts +4 -0
  76. package/src/families/bitcoin/getAccountNetworkInfo.ts +4 -2
  77. package/src/families/bitcoin/specs.ts +4 -5
  78. package/src/families/bitcoin/wallet-btc/utils.ts +8 -0
  79. package/src/families/bitcoin/wallet-btc/wallet.ts +24 -12
  80. package/src/families/cosmos/__snapshots__/bridge.test.ts.snap +128 -7
  81. package/src/families/cosmos/js-prepareTransaction.ts +7 -5
  82. package/src/families/cosmos/js-signOperation.ts +54 -36
  83. package/src/families/cosmos/validators.ts +1 -1
  84. package/src/families/ripple/bridge/js.ts +89 -494
  85. package/src/families/ripple/bridge.test.ts +0 -6
  86. package/src/families/ripple/js-synchronization.ts +153 -0
  87. package/src/families/ripple/test-dataset.ts +2 -0
  88. package/src/families/ripple/types.api.ts +23 -0
  89. package/src/featureFlags/defaultFeatures.ts +47 -0
  90. package/src/featureFlags/types.ts +7 -1
  91. package/src/platform/providers/GlobalCatalogProvider/api/mock.json +0 -26
  92. package/src/platform/providers/RemoteLiveAppProvider/api/mock.json +0 -63
  93. package/src/types/nft.ts +1 -1
  94. package/src/.DS_Store +0 -0
  95. package/src/__tests__/.DS_Store +0 -0
@@ -10,6 +10,25 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || function (mod) {
26
+ if (mod && mod.__esModule) return mod;
27
+ var result = {};
28
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
+ __setModuleDefault(result, mod);
30
+ return result;
31
+ };
13
32
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
33
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
34
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -46,75 +65,28 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
65
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
66
  }
48
67
  };
49
- var __values = (this && this.__values) || function(o) {
50
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
51
- if (m) return m.call(o);
52
- if (o && typeof o.length === "number") return {
53
- next: function () {
54
- if (o && i >= o.length) o = void 0;
55
- return { value: o && o[i++], done: !o };
56
- }
57
- };
58
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
59
- };
60
- var __read = (this && this.__read) || function (o, n) {
61
- var m = typeof Symbol === "function" && o[Symbol.iterator];
62
- if (!m) return o;
63
- var i = m.call(o), r, ar = [], e;
64
- try {
65
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
66
- }
67
- catch (error) { e = { error: error }; }
68
- finally {
69
- try {
70
- if (r && !r.done && (m = i["return"])) m.call(i);
71
- }
72
- finally { if (e) throw e.error; }
73
- }
74
- return ar;
75
- };
76
68
  var __importDefault = (this && this.__importDefault) || function (mod) {
77
69
  return (mod && mod.__esModule) ? mod : { "default": mod };
78
70
  };
79
71
  exports.__esModule = true;
72
+ exports.NEW_ACCOUNT_ERROR_MESSAGE = void 0;
80
73
  /* eslint-disable no-param-reassign */
81
- var invariant_1 = __importDefault(require("invariant"));
74
+ var errors_1 = require("@ledgerhq/errors");
82
75
  var bignumber_js_1 = require("bignumber.js");
83
- var rxjs_1 = require("rxjs");
76
+ var invariant_1 = __importDefault(require("invariant"));
84
77
  var ripple_bs58check_1 = __importDefault(require("ripple-bs58check"));
85
- var errors_1 = require("@ledgerhq/errors");
86
- var derivation_1 = require("../../../derivation");
87
- var currencies_1 = require("../../../currencies");
88
- var operation_1 = require("../../../operation");
78
+ var rxjs_1 = require("rxjs");
89
79
  var account_1 = require("../../../account");
90
- var account_2 = require("../../../account");
91
- var getAddress_1 = __importDefault(require("../../../hw/getAddress"));
92
- var deviceAccess_1 = require("../../../hw/deviceAccess");
93
- var Ripple_1 = require("../../../api/Ripple");
94
- var signTransaction_1 = __importDefault(require("../../../hw/signTransaction"));
80
+ var Ripple_1 = __importStar(require("../../../api/Ripple"));
95
81
  var jsHelpers_1 = require("../../../bridge/jsHelpers");
96
- var Ripple_2 = require("../../../api/Ripple");
97
- // true if the error should be forwarded and is not a "not found" case
98
- var checkAccountNotFound = function (e) {
99
- return (!e.data || (e.message !== "actNotFound" && e.data.error !== "actNotFound"));
100
- };
82
+ var currencies_1 = require("../../../currencies");
83
+ var signTransaction_1 = __importDefault(require("../../../hw/signTransaction"));
84
+ var deviceAccess_1 = require("../../../hw/deviceAccess");
85
+ var operation_1 = require("../../../operation");
86
+ var js_synchronization_1 = require("../js-synchronization");
87
+ exports.NEW_ACCOUNT_ERROR_MESSAGE = "actNotFound";
88
+ var LEDGER_OFFSET = 20;
101
89
  var receive = (0, jsHelpers_1.makeAccountBridgeReceive)();
102
- var getSequenceNumber = function (account) { return __awaiter(void 0, void 0, void 0, function () {
103
- var lastOp, info;
104
- return __generator(this, function (_a) {
105
- switch (_a.label) {
106
- case 0:
107
- lastOp = account.operations.find(function (op) { return op.type === "OUT"; });
108
- if (lastOp && lastOp.transactionSequenceNumber) {
109
- return [2 /*return*/, (lastOp.transactionSequenceNumber + account.pendingOperations.length + 1)];
110
- }
111
- return [4 /*yield*/, (0, Ripple_2.getAccountInfo)(account.freshAddress)];
112
- case 1:
113
- info = _a.sent();
114
- return [2 /*return*/, info.sequence + account.pendingOperations.length];
115
- }
116
- });
117
- }); };
118
90
  var uint32maxPlus1 = new bignumber_js_1.BigNumber(2).pow(32);
119
91
  var validateTag = function (tag) {
120
92
  return (!tag.isNaN() &&
@@ -123,6 +95,17 @@ var validateTag = function (tag) {
123
95
  tag.isPositive() &&
124
96
  tag.lt(uint32maxPlus1));
125
97
  };
98
+ var getNextValidSequence = function (account) { return __awaiter(void 0, void 0, void 0, function () {
99
+ var accInfo;
100
+ return __generator(this, function (_a) {
101
+ switch (_a.label) {
102
+ case 0: return [4 /*yield*/, (0, Ripple_1.getAccountInfo)(account.freshAddress, true)];
103
+ case 1:
104
+ accInfo = _a.sent();
105
+ return [2 /*return*/, accInfo.account_data.Sequence];
106
+ }
107
+ });
108
+ }); };
126
109
  var signOperation = function (_a) {
127
110
  var account = _a.account, transaction = _a.transaction, deviceId = _a.deviceId;
128
111
  return (0, deviceAccess_1.withDevice)(deviceId)(function (transport) {
@@ -133,49 +116,45 @@ var signOperation = function (_a) {
133
116
  throw new errors_1.FeeNotLoaded();
134
117
  function main() {
135
118
  return __awaiter(this, void 0, void 0, function () {
136
- var amount, tag, payment, instruction, prepared, signature, hash, operation, e_1;
119
+ var tag, nextSequenceNumber, payment, signature, hash, operation, e_1;
137
120
  var _a;
138
121
  return __generator(this, function (_b) {
139
122
  switch (_b.label) {
140
123
  case 0:
141
- amount = (0, Ripple_1.formatAPICurrencyXRP)(transaction.amount);
124
+ _b.trys.push([0, 4, , 5]);
142
125
  tag = transaction.tag ? transaction.tag : undefined;
143
- payment = {
144
- source: {
145
- address: account.freshAddress,
146
- amount: amount
147
- },
148
- destination: {
149
- address: transaction.recipient,
150
- minAmount: amount,
151
- tag: tag
152
- }
153
- };
154
- instruction = {
155
- fee: (0, Ripple_1.formatAPICurrencyXRP)(fee).value,
156
- maxLedgerVersionOffset: 12
126
+ return [4 /*yield*/, getNextValidSequence(account)];
127
+ case 1:
128
+ nextSequenceNumber = _b.sent();
129
+ _a = {
130
+ TransactionType: "Payment",
131
+ Account: account.freshAddress,
132
+ Amount: transaction.amount.toString(),
133
+ Destination: transaction.recipient,
134
+ DestinationTag: tag,
135
+ Fee: fee.toString(),
136
+ Flags: 2147483648,
137
+ Sequence: nextSequenceNumber
157
138
  };
139
+ return [4 /*yield*/, (0, Ripple_1["default"])()];
140
+ case 2:
141
+ payment = (_a.LastLedgerSequence = (_b.sent()) + LEDGER_OFFSET,
142
+ _a);
158
143
  if (tag)
159
144
  (0, invariant_1["default"])(validateTag(new bignumber_js_1.BigNumber(tag)), "tag is set but is not in a valid format, should be between [0 - ".concat(uint32maxPlus1
160
145
  .minus(1)
161
146
  .toString(), "]"));
162
- return [4 /*yield*/, (0, Ripple_2.preparePayment)(account.freshAddress, payment, instruction)];
163
- case 1:
164
- prepared = _b.sent();
165
- _b.label = 2;
166
- case 2:
167
- _b.trys.push([2, 5, , 6]);
168
147
  o.next({
169
148
  type: "device-signature-requested"
170
149
  });
171
- return [4 /*yield*/, (0, signTransaction_1["default"])(account.currency, transport, account.freshAddressPath, JSON.parse(prepared.txJSON))];
150
+ return [4 /*yield*/, (0, signTransaction_1["default"])(account.currency, transport, account.freshAddressPath, payment)];
172
151
  case 3:
173
152
  signature = _b.sent();
174
153
  o.next({
175
154
  type: "device-signature-granted"
176
155
  });
177
156
  hash = "";
178
- _a = {
157
+ operation = {
179
158
  id: "".concat(account.id, "-").concat(hash, "-OUT"),
180
159
  hash: hash,
181
160
  accountId: account.id,
@@ -186,18 +165,10 @@ var signOperation = function (_a) {
186
165
  blockHeight: null,
187
166
  senders: [account.freshAddress],
188
167
  recipients: [transaction.recipient],
189
- date: new Date()
168
+ date: new Date(),
169
+ transactionSequenceNumber: nextSequenceNumber,
170
+ extra: {}
190
171
  };
191
- return [4 /*yield*/, getSequenceNumber(account)];
192
- case 4:
193
- operation = (
194
- // we probably can't get it so it's a predictive value
195
- _a.transactionSequenceNumber = _b.sent(),
196
- _a.extra = {},
197
- _a);
198
- if (transaction.tag) {
199
- operation.extra.tag = transaction.tag;
200
- }
201
172
  o.next({
202
173
  type: "signed",
203
174
  signedOperation: {
@@ -206,14 +177,14 @@ var signOperation = function (_a) {
206
177
  expirationDate: null
207
178
  }
208
179
  });
209
- return [3 /*break*/, 6];
210
- case 5:
180
+ return [3 /*break*/, 5];
181
+ case 4:
211
182
  e_1 = _b.sent();
212
183
  if (e_1 && e_1.name === "RippledError" && e_1.data.resultMessage) {
213
184
  throw new Error(e_1.data.resultMessage);
214
185
  }
215
186
  throw e_1;
216
- case 6: return [2 /*return*/];
187
+ case 5: return [2 /*return*/];
217
188
  }
218
189
  });
219
190
  });
@@ -228,7 +199,7 @@ var broadcast = function (_a) {
228
199
  var submittedPayment, hash;
229
200
  return __generator(this, function (_c) {
230
201
  switch (_c.label) {
231
- case 0: return [4 /*yield*/, (0, Ripple_2.submit)(signature)];
202
+ case 0: return [4 /*yield*/, (0, Ripple_1.submit)(signature)];
232
203
  case 1:
233
204
  submittedPayment = _c.sent();
234
205
  if (submittedPayment.engine_result !== "tesSUCCESS" &&
@@ -250,61 +221,20 @@ function isRecipientValid(recipient) {
250
221
  return false;
251
222
  }
252
223
  }
253
- var txToOperation = function (account) {
254
- return function (_a) {
255
- var id = _a.id, sequence = _a.sequence, _b = _a.outcome, fee = _b.fee, deliveredAmount = _b.deliveredAmount, ledgerVersion = _b.ledgerVersion, timestamp = _b.timestamp, _c = _a.specification, source = _c.source, destination = _c.destination;
256
- var type = source.address === account.freshAddress ? "OUT" : "IN";
257
- var value = deliveredAmount
258
- ? (0, Ripple_1.parseAPICurrencyObject)(deliveredAmount)
259
- : new bignumber_js_1.BigNumber(0);
260
- var feeValue = (0, Ripple_1.parseAPIValue)(fee);
261
- if (type === "OUT") {
262
- if (!Number.isNaN(feeValue)) {
263
- value = value.plus(feeValue);
264
- }
265
- }
266
- var op = {
267
- id: "".concat(account.id, "-").concat(id, "-").concat(type),
268
- hash: id,
269
- accountId: account.id,
270
- type: type,
271
- value: value,
272
- fee: feeValue,
273
- blockHash: null,
274
- blockHeight: ledgerVersion,
275
- senders: [source.address],
276
- recipients: [destination.address],
277
- date: new Date(timestamp),
278
- transactionSequenceNumber: sequence,
279
- extra: {}
280
- };
281
- if (destination.tag) {
282
- op.extra.tag = destination.tag;
283
- }
284
- return op;
285
- };
286
- };
287
- var recipientIsNew = function (endpointConfig, recipient) { return __awaiter(void 0, void 0, void 0, function () {
288
- var e_2;
224
+ var recipientIsNew = function (recipient) { return __awaiter(void 0, void 0, void 0, function () {
225
+ var info;
289
226
  return __generator(this, function (_a) {
290
227
  switch (_a.label) {
291
228
  case 0:
292
229
  if (!isRecipientValid(recipient))
293
230
  return [2 /*return*/, false];
294
- _a.label = 1;
231
+ return [4 /*yield*/, (0, Ripple_1.getAccountInfo)(recipient)];
295
232
  case 1:
296
- _a.trys.push([1, 3, , 4]);
297
- return [4 /*yield*/, (0, Ripple_2.getAccountInfo)(recipient, endpointConfig)];
298
- case 2:
299
- _a.sent();
300
- return [2 /*return*/, false];
301
- case 3:
302
- e_2 = _a.sent();
303
- if (checkAccountNotFound(e_2)) {
304
- throw e_2;
233
+ info = _a.sent();
234
+ if (info.error === exports.NEW_ACCOUNT_ERROR_MESSAGE) {
235
+ return [2 /*return*/, true];
305
236
  }
306
- return [2 /*return*/, true];
307
- case 4: return [2 /*return*/];
237
+ return [2 /*return*/, false];
308
238
  }
309
239
  });
310
240
  }); };
@@ -318,319 +248,16 @@ var remapError = function (error) {
318
248
  return error;
319
249
  };
320
250
  var cacheRecipientsNew = {};
321
- var cachedRecipientIsNew = function (endpointConfig, recipient) {
251
+ var cachedRecipientIsNew = function (recipient) {
322
252
  if (recipient in cacheRecipientsNew)
323
253
  return cacheRecipientsNew[recipient];
324
- cacheRecipientsNew[recipient] = recipientIsNew(endpointConfig, recipient);
254
+ cacheRecipientsNew[recipient] = recipientIsNew(recipient);
325
255
  return cacheRecipientsNew[recipient];
326
256
  };
327
257
  var currencyBridge = {
328
258
  preload: function () { return Promise.resolve({}); },
329
259
  hydrate: function () { },
330
- scanAccounts: function (_a) {
331
- var currency = _a.currency, deviceId = _a.deviceId;
332
- return (0, deviceAccess_1.withDevice)(deviceId)(function (transport) {
333
- return new rxjs_1.Observable(function (o) {
334
- var finished = false;
335
- var unsubscribe = function () {
336
- finished = true;
337
- };
338
- function main() {
339
- return __awaiter(this, void 0, void 0, function () {
340
- var serverInfo, ledgers, minLedgerVersion, maxLedgerVersion, derivationModes, derivationModes_1, derivationModes_1_1, derivationMode, derivationScheme, stopAt, index, freshAddressPath, address, accountId, info, e_3, freshAddress, balance, transactions, account, e_4_1, e_5;
341
- var e_4, _a;
342
- return __generator(this, function (_b) {
343
- switch (_b.label) {
344
- case 0:
345
- _b.trys.push([0, 17, , 18]);
346
- return [4 /*yield*/, (0, Ripple_2.getServerInfo)()];
347
- case 1:
348
- serverInfo = _b.sent();
349
- ledgers = serverInfo.completeLedgers.split("-");
350
- minLedgerVersion = Number(ledgers[0]);
351
- maxLedgerVersion = Number(ledgers[1]);
352
- derivationModes = (0, derivation_1.getDerivationModesForCurrency)(currency);
353
- _b.label = 2;
354
- case 2:
355
- _b.trys.push([2, 14, 15, 16]);
356
- derivationModes_1 = __values(derivationModes), derivationModes_1_1 = derivationModes_1.next();
357
- _b.label = 3;
358
- case 3:
359
- if (!!derivationModes_1_1.done) return [3 /*break*/, 13];
360
- derivationMode = derivationModes_1_1.value;
361
- derivationScheme = (0, derivation_1.getDerivationScheme)({
362
- derivationMode: derivationMode,
363
- currency: currency
364
- });
365
- stopAt = (0, derivation_1.isIterableDerivationMode)(derivationMode)
366
- ? 255
367
- : 1;
368
- index = 0;
369
- _b.label = 4;
370
- case 4:
371
- if (!(index < stopAt)) return [3 /*break*/, 12];
372
- if (!(0, derivation_1.derivationModeSupportsIndex)(derivationMode, index))
373
- return [3 /*break*/, 11];
374
- freshAddressPath = (0, derivation_1.runDerivationScheme)(derivationScheme, currency, {
375
- account: index
376
- });
377
- return [4 /*yield*/, (0, getAddress_1["default"])(transport, {
378
- currency: currency,
379
- path: freshAddressPath,
380
- derivationMode: derivationMode
381
- })];
382
- case 5:
383
- address = (_b.sent()).address;
384
- if (finished)
385
- return [2 /*return*/];
386
- accountId = "ripplejs:2:".concat(currency.id, ":").concat(address, ":").concat(derivationMode);
387
- info = void 0;
388
- _b.label = 6;
389
- case 6:
390
- _b.trys.push([6, 8, , 9]);
391
- return [4 /*yield*/, (0, Ripple_2.getAccountInfo)(address)];
392
- case 7:
393
- info = _b.sent();
394
- return [3 /*break*/, 9];
395
- case 8:
396
- e_3 = _b.sent();
397
- if (checkAccountNotFound(e_3)) {
398
- throw e_3;
399
- }
400
- return [3 /*break*/, 9];
401
- case 9:
402
- freshAddress = address;
403
- if (!info) {
404
- // account does not exist in Ripple server
405
- // we are generating a new account locally
406
- if (derivationMode === "") {
407
- o.next({
408
- type: "discovered",
409
- account: {
410
- type: "Account",
411
- id: accountId,
412
- seedIdentifier: freshAddress,
413
- derivationMode: derivationMode,
414
- name: (0, account_2.getNewAccountPlaceholderName)({
415
- currency: currency,
416
- index: index,
417
- derivationMode: derivationMode
418
- }),
419
- starred: false,
420
- used: false,
421
- freshAddress: freshAddress,
422
- freshAddressPath: freshAddressPath,
423
- freshAddresses: [
424
- {
425
- address: freshAddress,
426
- derivationPath: freshAddressPath
427
- },
428
- ],
429
- balance: new bignumber_js_1.BigNumber(0),
430
- spendableBalance: new bignumber_js_1.BigNumber(0),
431
- blockHeight: maxLedgerVersion,
432
- index: index,
433
- currency: currency,
434
- operationsCount: 0,
435
- operations: [],
436
- pendingOperations: [],
437
- unit: currency.units[0],
438
- // @ts-expect-error archived does not exists on type Account
439
- archived: false,
440
- lastSyncDate: new Date(),
441
- creationDate: new Date(),
442
- swapHistory: [],
443
- balanceHistoryCache: account_2.emptyHistoryCache
444
- }
445
- });
446
- }
447
- return [3 /*break*/, 12];
448
- }
449
- if (finished)
450
- return [2 /*return*/];
451
- balance = (0, Ripple_1.parseAPIValue)(info.xrpBalance);
452
- (0, invariant_1["default"])(!balance.isNaN() && balance.isFinite(), "Ripple: invalid balance=".concat(balance.toString(), " for address ").concat(address));
453
- return [4 /*yield*/, (0, Ripple_2.getTransactions)(address, {
454
- minLedgerVersion: minLedgerVersion,
455
- maxLedgerVersion: maxLedgerVersion,
456
- types: ["payment"]
457
- })];
458
- case 10:
459
- transactions = _b.sent();
460
- if (finished)
461
- return [2 /*return*/];
462
- account = {
463
- type: "Account",
464
- id: accountId,
465
- seedIdentifier: freshAddress,
466
- derivationMode: derivationMode,
467
- name: (0, account_2.getAccountPlaceholderName)({
468
- currency: currency,
469
- index: index,
470
- derivationMode: derivationMode
471
- }),
472
- starred: false,
473
- used: true,
474
- freshAddress: freshAddress,
475
- freshAddressPath: freshAddressPath,
476
- freshAddresses: [
477
- {
478
- address: freshAddress,
479
- derivationPath: freshAddressPath
480
- },
481
- ],
482
- balance: balance,
483
- spendableBalance: balance,
484
- // TODO calc with base reserve
485
- blockHeight: maxLedgerVersion,
486
- index: index,
487
- currency: currency,
488
- operationsCount: 0,
489
- operations: [],
490
- pendingOperations: [],
491
- unit: currency.units[0],
492
- lastSyncDate: new Date(),
493
- creationDate: new Date(),
494
- swapHistory: [],
495
- balanceHistoryCache: account_2.emptyHistoryCache
496
- };
497
- account.operations = transactions
498
- .map(txToOperation(account))
499
- .filter(Boolean);
500
- account.operationsCount = account.operations.length;
501
- if (account.operations.length > 0) {
502
- account.creationDate =
503
- account.operations[account.operations.length - 1].date;
504
- }
505
- o.next({
506
- type: "discovered",
507
- account: account
508
- });
509
- _b.label = 11;
510
- case 11:
511
- index++;
512
- return [3 /*break*/, 4];
513
- case 12:
514
- derivationModes_1_1 = derivationModes_1.next();
515
- return [3 /*break*/, 3];
516
- case 13: return [3 /*break*/, 16];
517
- case 14:
518
- e_4_1 = _b.sent();
519
- e_4 = { error: e_4_1 };
520
- return [3 /*break*/, 16];
521
- case 15:
522
- try {
523
- if (derivationModes_1_1 && !derivationModes_1_1.done && (_a = derivationModes_1["return"])) _a.call(derivationModes_1);
524
- }
525
- finally { if (e_4) throw e_4.error; }
526
- return [7 /*endfinally*/];
527
- case 16:
528
- o.complete();
529
- return [3 /*break*/, 18];
530
- case 17:
531
- e_5 = _b.sent();
532
- o.error(e_5);
533
- return [3 /*break*/, 18];
534
- case 18: return [2 /*return*/];
535
- }
536
- });
537
- });
538
- }
539
- main();
540
- return unsubscribe;
541
- });
542
- });
543
- }
544
- };
545
- var sync = function (_a) {
546
- var endpointConfig = _a.endpointConfig, freshAddress = _a.freshAddress, blockHeight = _a.blockHeight, operations = _a.operations;
547
- return new rxjs_1.Observable(function (o) {
548
- var finished = false;
549
- var currentOpsLength = operations ? operations.length : 0;
550
- var unsubscribe = function () {
551
- finished = true;
552
- };
553
- function main() {
554
- return __awaiter(this, void 0, void 0, function () {
555
- var serverInfo, ledgers, minLedgerVersion, maxLedgerVersion_1, info, e_6, balance_1, transactions_1, e_7;
556
- return __generator(this, function (_a) {
557
- switch (_a.label) {
558
- case 0:
559
- _a.trys.push([0, 7, , 8]);
560
- if (finished)
561
- return [2 /*return*/];
562
- return [4 /*yield*/, (0, Ripple_2.getServerInfo)(endpointConfig)];
563
- case 1:
564
- serverInfo = _a.sent();
565
- if (finished)
566
- return [2 /*return*/];
567
- ledgers = serverInfo.completeLedgers.split("-");
568
- minLedgerVersion = Number(ledgers[0]);
569
- maxLedgerVersion_1 = Number(ledgers[1]);
570
- info = void 0;
571
- _a.label = 2;
572
- case 2:
573
- _a.trys.push([2, 4, , 5]);
574
- return [4 /*yield*/, (0, Ripple_2.getAccountInfo)(freshAddress)];
575
- case 3:
576
- info = _a.sent();
577
- return [3 /*break*/, 5];
578
- case 4:
579
- e_6 = _a.sent();
580
- if (checkAccountNotFound(e_6)) {
581
- throw e_6;
582
- }
583
- return [3 /*break*/, 5];
584
- case 5:
585
- if (finished)
586
- return [2 /*return*/];
587
- if (!info) {
588
- // account does not exist, we have nothing to sync but to update the last sync date
589
- o.next(function (a) { return (__assign(__assign({}, a), { lastSyncDate: new Date() })); });
590
- o.complete();
591
- return [2 /*return*/];
592
- }
593
- balance_1 = (0, Ripple_1.parseAPIValue)(info.xrpBalance);
594
- (0, invariant_1["default"])(!balance_1.isNaN() && balance_1.isFinite(), "Ripple: invalid balance=".concat(balance_1.toString(), " for address ").concat(freshAddress));
595
- return [4 /*yield*/, (0, Ripple_2.getTransactions)(freshAddress, {
596
- minLedgerVersion: Math.max(currentOpsLength === 0 ? 0 : blockHeight, // if there is no ops, it might be after a clear and we prefer to pull from the oldest possible history
597
- minLedgerVersion),
598
- maxLedgerVersion: maxLedgerVersion_1,
599
- types: ["payment"]
600
- })];
601
- case 6:
602
- transactions_1 = _a.sent();
603
- if (finished)
604
- return [2 /*return*/];
605
- o.next(function (a) {
606
- var newOps = transactions_1.map(txToOperation(a));
607
- var operations = (0, jsHelpers_1.mergeOps)(a.operations, newOps);
608
- var _a = __read(operations, 1), last = _a[0];
609
- var pendingOperations = a.pendingOperations.filter(function (oo) {
610
- return !operations.some(function (op) { return oo.hash === op.hash; }) &&
611
- last &&
612
- last.transactionSequenceNumber &&
613
- oo.transactionSequenceNumber &&
614
- oo.transactionSequenceNumber > last.transactionSequenceNumber;
615
- });
616
- return __assign(__assign({}, a), { balance: balance_1, spendableBalance: balance_1,
617
- // TODO use reserve
618
- operations: operations, pendingOperations: pendingOperations, blockHeight: maxLedgerVersion_1, lastSyncDate: new Date() });
619
- });
620
- o.complete();
621
- return [3 /*break*/, 8];
622
- case 7:
623
- e_7 = _a.sent();
624
- o.error(remapError(e_7));
625
- return [3 /*break*/, 8];
626
- case 8: return [2 /*return*/];
627
- }
628
- });
629
- });
630
- }
631
- main();
632
- return unsubscribe;
633
- });
260
+ scanAccounts: js_synchronization_1.scanAccounts
634
261
  };
635
262
  var createTransaction = function () { return ({
636
263
  family: "ripple",
@@ -643,7 +270,7 @@ var createTransaction = function () { return ({
643
270
  }); };
644
271
  var updateTransaction = function (t, patch) { return (__assign(__assign({}, t), patch)); };
645
272
  var prepareTransaction = function (a, t) { return __awaiter(void 0, void 0, void 0, function () {
646
- var networkInfo, info, serverFee, e_8, fee;
273
+ var networkInfo, info, serverFee, e_2, fee;
647
274
  return __generator(this, function (_a) {
648
275
  switch (_a.label) {
649
276
  case 0:
@@ -652,10 +279,10 @@ var prepareTransaction = function (a, t) { return __awaiter(void 0, void 0, void
652
279
  _a.label = 1;
653
280
  case 1:
654
281
  _a.trys.push([1, 3, , 4]);
655
- return [4 /*yield*/, (0, Ripple_2.getServerInfo)(a.endpointConfig)];
282
+ return [4 /*yield*/, (0, Ripple_1.getServerInfo)(a.endpointConfig)];
656
283
  case 2:
657
284
  info = _a.sent();
658
- serverFee = (0, Ripple_1.parseAPIValue)(info.validatedLedger.baseFeeXRP);
285
+ serverFee = (0, Ripple_1.parseAPIValue)(info.info.validated_ledger.base_fee_xrp.toString());
659
286
  networkInfo = {
660
287
  family: "ripple",
661
288
  serverFee: serverFee,
@@ -663,8 +290,8 @@ var prepareTransaction = function (a, t) { return __awaiter(void 0, void 0, void
663
290
  };
664
291
  return [3 /*break*/, 4];
665
292
  case 3:
666
- e_8 = _a.sent();
667
- throw remapError(e_8);
293
+ e_2 = _a.sent();
294
+ throw remapError(e_2);
668
295
  case 4:
669
296
  fee = t.fee || networkInfo.serverFee;
670
297
  if (t.networkInfo !== networkInfo || t.fee !== fee) {
@@ -675,16 +302,16 @@ var prepareTransaction = function (a, t) { return __awaiter(void 0, void 0, void
675
302
  });
676
303
  }); };
677
304
  var getTransactionStatus = function (a, t) { return __awaiter(void 0, void 0, void 0, function () {
678
- var errors, warnings, r, reserveBaseXRP, estimatedFees, totalSpent, amount, _a, f;
305
+ var errors, warnings, r, reserveBaseXRP, estimatedFees, totalSpent, amount, _a;
679
306
  return __generator(this, function (_b) {
680
307
  switch (_b.label) {
681
308
  case 0:
682
309
  errors = {};
683
310
  warnings = {};
684
- return [4 /*yield*/, (0, Ripple_2.getServerInfo)(a.endpointConfig)];
311
+ return [4 /*yield*/, (0, Ripple_1.getServerInfo)(a.endpointConfig)];
685
312
  case 1:
686
313
  r = _b.sent();
687
- reserveBaseXRP = (0, Ripple_1.parseAPIValue)(r.validatedLedger.reserveBaseXRP);
314
+ reserveBaseXRP = (0, Ripple_1.parseAPIValue)(r.info.validated_ledger.reserve_base_xrp.toString());
688
315
  estimatedFees = new bignumber_js_1.BigNumber(t.fee || 0);
689
316
  totalSpent = new bignumber_js_1.BigNumber(t.amount).plus(estimatedFees);
690
317
  amount = new bignumber_js_1.BigNumber(t.amount);
@@ -711,16 +338,19 @@ var getTransactionStatus = function (a, t) { return __awaiter(void 0, void 0, vo
711
338
  case 4:
712
339
  _a = t.recipient;
713
340
  if (!_a) return [3 /*break*/, 6];
714
- return [4 /*yield*/, cachedRecipientIsNew(a.endpointConfig, t.recipient)];
341
+ return [4 /*yield*/, cachedRecipientIsNew(t.recipient)];
715
342
  case 5:
716
343
  _a = (_b.sent());
717
344
  _b.label = 6;
718
345
  case 6:
719
346
  if (_a &&
720
347
  t.amount.lt(reserveBaseXRP)) {
721
- f = (0, Ripple_1.formatAPICurrencyXRP)(reserveBaseXRP);
722
348
  errors.amount = new errors_1.NotEnoughBalanceBecauseDestinationNotCreated("", {
723
- minimalAmount: "".concat(f.currency, " ").concat(new bignumber_js_1.BigNumber(f.value).toFixed())
349
+ minimalAmount: (0, currencies_1.formatCurrencyUnit)(a.currency.units[0], reserveBaseXRP, {
350
+ disableRounding: true,
351
+ useGrouping: false,
352
+ showCode: true
353
+ })
724
354
  });
725
355
  }
726
356
  _b.label = 7;
@@ -762,10 +392,10 @@ var estimateMaxSpendable = function (_a) {
762
392
  switch (_b.label) {
763
393
  case 0:
764
394
  mainAccount = (0, account_1.getMainAccount)(account, parentAccount);
765
- return [4 /*yield*/, (0, Ripple_2.getServerInfo)(mainAccount.endpointConfig)];
395
+ return [4 /*yield*/, (0, Ripple_1.getServerInfo)(mainAccount.endpointConfig)];
766
396
  case 1:
767
397
  r = _b.sent();
768
- reserveBaseXRP = (0, Ripple_1.parseAPIValue)(r.validatedLedger.reserveBaseXRP);
398
+ reserveBaseXRP = (0, Ripple_1.parseAPIValue)(r.info.validated_ledger.reserve_base_xrp.toString());
769
399
  return [4 /*yield*/, prepareTransaction(mainAccount, __assign(__assign(__assign({}, createTransaction()), transaction), { recipient: (transaction === null || transaction === void 0 ? void 0 : transaction.recipient) || "rHsMGQEkVNJmpGWs8XUBoTBiAAbwxZN5v3",
770
400
  // public testing seed abandonx11,about
771
401
  amount: new bignumber_js_1.BigNumber(0) }))];
@@ -785,7 +415,7 @@ var accountBridge = {
785
415
  prepareTransaction: prepareTransaction,
786
416
  getTransactionStatus: getTransactionStatus,
787
417
  estimateMaxSpendable: estimateMaxSpendable,
788
- sync: sync,
418
+ sync: js_synchronization_1.sync,
789
419
  receive: receive,
790
420
  signOperation: signOperation,
791
421
  broadcast: broadcast