@ledgerhq/coin-xrp 6.2.0-nightly.2 → 6.2.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 (190) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.unimportedrc.json +1 -3
  3. package/CHANGELOG.md +64 -11
  4. package/lib/api/index.d.ts +11 -2
  5. package/lib/api/index.d.ts.map +1 -1
  6. package/lib/api/index.integ.test.js +7 -24
  7. package/lib/api/index.integ.test.js.map +1 -1
  8. package/lib/api/index.js +5 -15
  9. package/lib/api/index.js.map +1 -1
  10. package/lib/api/index.test.js +9 -18
  11. package/lib/api/index.test.js.map +1 -1
  12. package/lib/bridge/broadcast.d.ts +4 -0
  13. package/lib/bridge/broadcast.d.ts.map +1 -0
  14. package/lib/bridge/broadcast.js +11 -0
  15. package/lib/bridge/broadcast.js.map +1 -0
  16. package/lib/bridge/createTransaction.d.ts +4 -0
  17. package/lib/bridge/createTransaction.d.ts.map +1 -0
  18. package/lib/bridge/createTransaction.js +18 -0
  19. package/lib/bridge/createTransaction.js.map +1 -0
  20. package/lib/bridge/estimateMaxSpendable.d.ts +4 -0
  21. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
  22. package/lib/bridge/estimateMaxSpendable.js +26 -0
  23. package/lib/bridge/estimateMaxSpendable.js.map +1 -0
  24. package/lib/bridge/getTransactionStatus.d.ts +4 -0
  25. package/lib/bridge/getTransactionStatus.d.ts.map +1 -0
  26. package/lib/{logic → bridge}/getTransactionStatus.js +19 -15
  27. package/lib/bridge/getTransactionStatus.js.map +1 -0
  28. package/lib/bridge/index.d.ts +11 -0
  29. package/lib/bridge/index.d.ts.map +1 -0
  30. package/lib/bridge/index.js +47 -0
  31. package/lib/bridge/index.js.map +1 -0
  32. package/lib/bridge/prepareTransaction.d.ts +4 -0
  33. package/lib/bridge/prepareTransaction.d.ts.map +1 -0
  34. package/lib/bridge/prepareTransaction.js +14 -0
  35. package/lib/bridge/prepareTransaction.js.map +1 -0
  36. package/lib/bridge/signOperation.d.ts +5 -0
  37. package/lib/bridge/signOperation.d.ts.map +1 -0
  38. package/lib/bridge/signOperation.js +76 -0
  39. package/lib/bridge/signOperation.js.map +1 -0
  40. package/lib/bridge/synchronization.d.ts +3 -0
  41. package/lib/bridge/synchronization.d.ts.map +1 -0
  42. package/lib/bridge/synchronization.js +85 -0
  43. package/lib/bridge/synchronization.js.map +1 -0
  44. package/lib/bridge/synchronization.test.d.ts +2 -0
  45. package/lib/bridge/synchronization.test.d.ts.map +1 -0
  46. package/lib/bridge/synchronization.test.js +140 -0
  47. package/lib/bridge/synchronization.test.js.map +1 -0
  48. package/lib/{transaction.d.ts → bridge/transaction.d.ts} +1 -1
  49. package/lib/bridge/transaction.d.ts.map +1 -0
  50. package/lib/bridge/transaction.js.map +1 -0
  51. package/lib/index.d.ts +1 -0
  52. package/lib/index.d.ts.map +1 -1
  53. package/lib/index.js +3 -0
  54. package/lib/index.js.map +1 -1
  55. package/lib/logic/combine.d.ts.map +1 -1
  56. package/lib/logic/combine.js +3 -8
  57. package/lib/logic/combine.js.map +1 -1
  58. package/lib/logic/getBalance.d.ts.map +1 -1
  59. package/lib/logic/getBalance.js +1 -13
  60. package/lib/logic/getBalance.js.map +1 -1
  61. package/lib/logic/getBalance.test.js +1 -14
  62. package/lib/logic/getBalance.test.js.map +1 -1
  63. package/lib/logic/index.d.ts +1 -2
  64. package/lib/logic/index.d.ts.map +1 -1
  65. package/lib/logic/index.js +2 -3
  66. package/lib/logic/index.js.map +1 -1
  67. package/lib/logic/utils.d.ts +1 -0
  68. package/lib/logic/utils.d.ts.map +1 -1
  69. package/lib/logic/utils.js +10 -14
  70. package/lib/logic/utils.js.map +1 -1
  71. package/lib/test/bridgeDatasetTest.d.ts.map +1 -1
  72. package/lib/test/bridgeDatasetTest.js +7 -7
  73. package/lib/test/bridgeDatasetTest.js.map +1 -1
  74. package/lib/types/model.d.ts +0 -7
  75. package/lib/types/model.d.ts.map +1 -1
  76. package/lib-es/api/index.d.ts +11 -2
  77. package/lib-es/api/index.d.ts.map +1 -1
  78. package/lib-es/api/index.integ.test.js +7 -24
  79. package/lib-es/api/index.integ.test.js.map +1 -1
  80. package/lib-es/api/index.js +6 -16
  81. package/lib-es/api/index.js.map +1 -1
  82. package/lib-es/api/index.test.js +9 -18
  83. package/lib-es/api/index.test.js.map +1 -1
  84. package/lib-es/bridge/broadcast.d.ts +4 -0
  85. package/lib-es/bridge/broadcast.d.ts.map +1 -0
  86. package/lib-es/bridge/broadcast.js +7 -0
  87. package/lib-es/bridge/broadcast.js.map +1 -0
  88. package/lib-es/bridge/createTransaction.d.ts +4 -0
  89. package/lib-es/bridge/createTransaction.d.ts.map +1 -0
  90. package/lib-es/bridge/createTransaction.js +11 -0
  91. package/lib-es/bridge/createTransaction.js.map +1 -0
  92. package/lib-es/bridge/estimateMaxSpendable.d.ts +4 -0
  93. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
  94. package/lib-es/bridge/estimateMaxSpendable.js +19 -0
  95. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
  96. package/lib-es/bridge/getTransactionStatus.d.ts +4 -0
  97. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -0
  98. package/lib-es/{logic → bridge}/getTransactionStatus.js +14 -13
  99. package/lib-es/bridge/getTransactionStatus.js.map +1 -0
  100. package/lib-es/bridge/index.d.ts +11 -0
  101. package/lib-es/bridge/index.d.ts.map +1 -0
  102. package/lib-es/bridge/index.js +41 -0
  103. package/lib-es/bridge/index.js.map +1 -0
  104. package/lib-es/bridge/prepareTransaction.d.ts +4 -0
  105. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
  106. package/lib-es/bridge/prepareTransaction.js +10 -0
  107. package/lib-es/bridge/prepareTransaction.js.map +1 -0
  108. package/lib-es/bridge/signOperation.d.ts +5 -0
  109. package/lib-es/bridge/signOperation.d.ts.map +1 -0
  110. package/lib-es/bridge/signOperation.js +72 -0
  111. package/lib-es/bridge/signOperation.js.map +1 -0
  112. package/lib-es/bridge/synchronization.d.ts +3 -0
  113. package/lib-es/bridge/synchronization.d.ts.map +1 -0
  114. package/lib-es/bridge/synchronization.js +78 -0
  115. package/lib-es/bridge/synchronization.js.map +1 -0
  116. package/lib-es/bridge/synchronization.test.d.ts +2 -0
  117. package/lib-es/bridge/synchronization.test.d.ts.map +1 -0
  118. package/lib-es/bridge/synchronization.test.js +135 -0
  119. package/lib-es/bridge/synchronization.test.js.map +1 -0
  120. package/lib-es/{transaction.d.ts → bridge/transaction.d.ts} +1 -1
  121. package/lib-es/bridge/transaction.d.ts.map +1 -0
  122. package/lib-es/bridge/transaction.js.map +1 -0
  123. package/lib-es/index.d.ts +1 -0
  124. package/lib-es/index.d.ts.map +1 -1
  125. package/lib-es/index.js +1 -0
  126. package/lib-es/index.js.map +1 -1
  127. package/lib-es/logic/combine.d.ts.map +1 -1
  128. package/lib-es/logic/combine.js +3 -8
  129. package/lib-es/logic/combine.js.map +1 -1
  130. package/lib-es/logic/getBalance.d.ts.map +1 -1
  131. package/lib-es/logic/getBalance.js +2 -14
  132. package/lib-es/logic/getBalance.js.map +1 -1
  133. package/lib-es/logic/getBalance.test.js +1 -14
  134. package/lib-es/logic/getBalance.test.js.map +1 -1
  135. package/lib-es/logic/index.d.ts +1 -2
  136. package/lib-es/logic/index.d.ts.map +1 -1
  137. package/lib-es/logic/index.js +1 -2
  138. package/lib-es/logic/index.js.map +1 -1
  139. package/lib-es/logic/utils.d.ts +1 -0
  140. package/lib-es/logic/utils.d.ts.map +1 -1
  141. package/lib-es/logic/utils.js +8 -13
  142. package/lib-es/logic/utils.js.map +1 -1
  143. package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -1
  144. package/lib-es/test/bridgeDatasetTest.js +7 -7
  145. package/lib-es/test/bridgeDatasetTest.js.map +1 -1
  146. package/lib-es/types/model.d.ts +0 -7
  147. package/lib-es/types/model.d.ts.map +1 -1
  148. package/package.json +10 -10
  149. package/src/api/index.integ.test.ts +8 -24
  150. package/src/api/index.test.ts +22 -23
  151. package/src/api/index.ts +19 -28
  152. package/src/bridge/broadcast.ts +11 -0
  153. package/src/bridge/createTransaction.ts +13 -0
  154. package/src/bridge/estimateMaxSpendable.ts +25 -0
  155. package/src/{logic → bridge}/getTransactionStatus.ts +21 -18
  156. package/src/bridge/index.ts +59 -0
  157. package/src/bridge/prepareTransaction.ts +18 -0
  158. package/src/bridge/signOperation.ts +100 -0
  159. package/src/bridge/synchronization.test.ts +153 -0
  160. package/src/bridge/synchronization.ts +108 -0
  161. package/src/{transaction.ts → bridge/transaction.ts} +1 -1
  162. package/src/index.ts +1 -0
  163. package/src/logic/combine.ts +3 -10
  164. package/src/logic/getBalance.test.ts +1 -14
  165. package/src/logic/getBalance.ts +2 -18
  166. package/src/logic/index.ts +6 -2
  167. package/src/logic/utils.ts +8 -24
  168. package/src/test/bridgeDatasetTest.ts +7 -8
  169. package/src/types/model.ts +0 -11
  170. package/lib/logic/getTransactionStatus.d.ts +0 -3
  171. package/lib/logic/getTransactionStatus.d.ts.map +0 -1
  172. package/lib/logic/getTransactionStatus.js.map +0 -1
  173. package/lib/logic/getTransactionStatus.test.d.ts +0 -2
  174. package/lib/logic/getTransactionStatus.test.d.ts.map +0 -1
  175. package/lib/logic/getTransactionStatus.test.js +0 -184
  176. package/lib/logic/getTransactionStatus.test.js.map +0 -1
  177. package/lib/transaction.d.ts.map +0 -1
  178. package/lib/transaction.js.map +0 -1
  179. package/lib-es/logic/getTransactionStatus.d.ts +0 -3
  180. package/lib-es/logic/getTransactionStatus.d.ts.map +0 -1
  181. package/lib-es/logic/getTransactionStatus.js.map +0 -1
  182. package/lib-es/logic/getTransactionStatus.test.d.ts +0 -2
  183. package/lib-es/logic/getTransactionStatus.test.d.ts.map +0 -1
  184. package/lib-es/logic/getTransactionStatus.test.js +0 -159
  185. package/lib-es/logic/getTransactionStatus.test.js.map +0 -1
  186. package/lib-es/transaction.d.ts.map +0 -1
  187. package/lib-es/transaction.js.map +0 -1
  188. package/src/logic/getTransactionStatus.test.ts +0 -215
  189. /package/lib/{transaction.js → bridge/transaction.js} +0 -0
  190. /package/lib-es/{transaction.js → bridge/transaction.js} +0 -0
@@ -1,215 +0,0 @@
1
- import { getTransactionStatus } from "./getTransactionStatus";
2
- import * as logic from "./index";
3
-
4
- const mockGetServerInfos = jest.fn();
5
- const mockCachedRecipientIsNew = jest.fn();
6
-
7
- jest.mock("../network", () => ({
8
- getServerInfos: () => mockGetServerInfos(),
9
- }));
10
-
11
- jest.spyOn(logic, "cachedRecipientIsNew").mockImplementation(addr => {
12
- if (addr === RECIPIENT_NEW) {
13
- return Promise.resolve(true);
14
- }
15
- return Promise.resolve(false);
16
- });
17
-
18
- const reserveBase = 10_000_000n; // 10 XRP (drops)
19
-
20
- const SENDER = "rPSCfmnX3t9jQJG5RNcZtSaP5UhExZDue4";
21
- const RECIPIENT = "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe";
22
- const RECIPIENT_NEW = "rDKsbvy9uaNpPtvVFraJyNGfjvTw8xivgK";
23
-
24
- const account = {
25
- address: SENDER,
26
- balance: 50_000_000n,
27
- currencyUnit: {
28
- code: "XRP",
29
- magnitude: 6,
30
- name: "XRP",
31
- symbol: "XRP",
32
- },
33
- currencyName: "XRP",
34
- };
35
-
36
- describe("getTransactionStatus", () => {
37
- afterEach(() => {
38
- mockGetServerInfos.mockReset();
39
- mockCachedRecipientIsNew.mockReset();
40
- });
41
-
42
- it("returns no errors on valid transaction", async () => {
43
- mockGetServerInfos.mockResolvedValue({
44
- info: {
45
- validated_ledger: {
46
- reserve_base_xrp: reserveBase / 1_000_000n, // XRP value, not drops
47
- },
48
- },
49
- });
50
-
51
- mockCachedRecipientIsNew.mockResolvedValue(false);
52
-
53
- const result = await getTransactionStatus(
54
- account as any,
55
- {
56
- amount: 20_000_000n,
57
- fee: 10_000n,
58
- recipient: RECIPIENT,
59
- } as any,
60
- );
61
-
62
- expect(result.errors).toEqual({});
63
- expect(result.warnings).toEqual({});
64
- expect(result.totalSpent).toBe(20_010_000n);
65
- });
66
-
67
- it("throws FeeTooHigh warning when fee is >10% of amount", async () => {
68
- mockGetServerInfos.mockResolvedValue({
69
- info: {
70
- validated_ledger: {
71
- reserve_base_xrp: reserveBase / 1_000_000n,
72
- },
73
- },
74
- });
75
-
76
- const result = await getTransactionStatus(
77
- account as any,
78
- {
79
- amount: 1_000_000n,
80
- fee: 200_000n, // 20%
81
- recipient: RECIPIENT,
82
- } as any,
83
- );
84
-
85
- expect(result.warnings.feeTooHigh).toBeInstanceOf(Error);
86
- expect(result.errors).toEqual({});
87
- });
88
-
89
- it("errors when fee is missing", async () => {
90
- mockGetServerInfos.mockResolvedValue({
91
- info: {
92
- validated_ledger: {
93
- reserve_base_xrp: reserveBase / 1_000_000n,
94
- },
95
- },
96
- });
97
-
98
- const result = await getTransactionStatus(
99
- account as any,
100
- {
101
- amount: 10_000_000n,
102
- recipient: RECIPIENT,
103
- } as any,
104
- );
105
-
106
- expect(result.errors.fee?.name).toBe("FeeNotLoaded");
107
- });
108
-
109
- it("errors if recipient is same as sender", async () => {
110
- mockGetServerInfos.mockResolvedValue({
111
- info: {
112
- validated_ledger: {
113
- reserve_base_xrp: reserveBase / 1_000_000n,
114
- },
115
- },
116
- });
117
-
118
- const result = await getTransactionStatus(
119
- account as any,
120
- {
121
- amount: 10_000_000n,
122
- fee: 10_000n,
123
- recipient: SENDER,
124
- } as any,
125
- );
126
-
127
- expect(result.errors.recipient?.name).toBe("InvalidAddressBecauseDestinationIsAlsoSource");
128
- });
129
-
130
- it("errors if recipient is new and amount is too low", async () => {
131
- mockGetServerInfos.mockResolvedValue({
132
- info: {
133
- validated_ledger: {
134
- reserve_base_xrp: reserveBase / 1_000_000n,
135
- },
136
- },
137
- });
138
-
139
- mockCachedRecipientIsNew.mockResolvedValue(true);
140
-
141
- const result = await getTransactionStatus(
142
- account as any,
143
- {
144
- amount: 5_000_000n,
145
- fee: 10_000n,
146
- recipient: RECIPIENT_NEW,
147
- } as any,
148
- );
149
-
150
- expect(result.errors.amount?.name).toBe("NotEnoughBalanceBecauseDestinationNotCreated");
151
- });
152
-
153
- it("errors if amount is zero", async () => {
154
- mockGetServerInfos.mockResolvedValue({
155
- info: {
156
- validated_ledger: {
157
- reserve_base_xrp: reserveBase / 1_000_000n,
158
- },
159
- },
160
- });
161
-
162
- const result = await getTransactionStatus(
163
- account as any,
164
- {
165
- amount: 0n,
166
- fee: 10_000n,
167
- recipient: RECIPIENT,
168
- } as any,
169
- );
170
-
171
- expect(result.errors.amount?.name).toBe("AmountRequired");
172
- });
173
-
174
- it("errors if recipient is invalid", async () => {
175
- mockGetServerInfos.mockResolvedValue({
176
- info: {
177
- validated_ledger: {
178
- reserve_base_xrp: reserveBase / 1_000_000n,
179
- },
180
- },
181
- });
182
-
183
- const result = await getTransactionStatus(
184
- account as any,
185
- {
186
- amount: 1_000_000n,
187
- fee: 10_000n,
188
- recipient: "not-an-address",
189
- } as any,
190
- );
191
-
192
- expect(result.errors.recipient?.name).toBe("InvalidAddress");
193
- });
194
-
195
- it("errors if recipient is missing", async () => {
196
- mockGetServerInfos.mockResolvedValue({
197
- info: {
198
- validated_ledger: {
199
- reserve_base_xrp: reserveBase / 1_000_000n,
200
- },
201
- },
202
- });
203
-
204
- const result = await getTransactionStatus(
205
- account as any,
206
- {
207
- amount: 1_000_000n,
208
- fee: 10_000n,
209
- recipient: "",
210
- } as any,
211
- );
212
-
213
- expect(result.errors.recipient?.name).toBe("RecipientRequired");
214
- });
215
- });
File without changes