@ledgerhq/coin-stellar 0.2.0-next.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 (233) hide show
  1. package/.eslintrc.js +20 -0
  2. package/.turbo/turbo-build.log +4 -0
  3. package/.unimportedrc.json +35 -0
  4. package/CHANGELOG.md +18 -0
  5. package/LICENSE.txt +21 -0
  6. package/jest.config.js +8 -0
  7. package/lib/bridge/bridge.integration.test.d.ts +4 -0
  8. package/lib/bridge/bridge.integration.test.d.ts.map +1 -0
  9. package/lib/bridge/bridge.integration.test.js +317 -0
  10. package/lib/bridge/bridge.integration.test.js.map +1 -0
  11. package/lib/bridge/index.d.ts +10 -0
  12. package/lib/bridge/index.d.ts.map +1 -0
  13. package/lib/bridge/index.js +72 -0
  14. package/lib/bridge/index.js.map +1 -0
  15. package/lib/broadcast.d.ts +9 -0
  16. package/lib/broadcast.d.ts.map +1 -0
  17. package/lib/broadcast.js +26 -0
  18. package/lib/broadcast.js.map +1 -0
  19. package/lib/buildOptimisticOperation.d.ts +4 -0
  20. package/lib/buildOptimisticOperation.d.ts.map +1 -0
  21. package/lib/buildOptimisticOperation.js +72 -0
  22. package/lib/buildOptimisticOperation.js.map +1 -0
  23. package/lib/buildTransaction.d.ts +10 -0
  24. package/lib/buildTransaction.d.ts.map +1 -0
  25. package/lib/buildTransaction.js +97 -0
  26. package/lib/buildTransaction.js.map +1 -0
  27. package/lib/cli.d.ts +38 -0
  28. package/lib/cli.d.ts.map +1 -0
  29. package/lib/cli.js +83 -0
  30. package/lib/cli.js.map +1 -0
  31. package/lib/config.d.ts +5 -0
  32. package/lib/config.d.ts.map +1 -0
  33. package/lib/config.js +17 -0
  34. package/lib/config.js.map +1 -0
  35. package/lib/createTransaction.d.ts +10 -0
  36. package/lib/createTransaction.d.ts.map +1 -0
  37. package/lib/createTransaction.js +26 -0
  38. package/lib/createTransaction.js.map +1 -0
  39. package/lib/deviceTransactionConfig.d.ts +24 -0
  40. package/lib/deviceTransactionConfig.d.ts.map +1 -0
  41. package/lib/deviceTransactionConfig.js +41 -0
  42. package/lib/deviceTransactionConfig.js.map +1 -0
  43. package/lib/errors.d.ts +37 -0
  44. package/lib/errors.d.ts.map +1 -0
  45. package/lib/errors.js +17 -0
  46. package/lib/errors.js.map +1 -0
  47. package/lib/estimateMaxSpendable.d.ts +5 -0
  48. package/lib/estimateMaxSpendable.d.ts.map +1 -0
  49. package/lib/estimateMaxSpendable.js +32 -0
  50. package/lib/estimateMaxSpendable.js.map +1 -0
  51. package/lib/getTransactionStatus.d.ts +5 -0
  52. package/lib/getTransactionStatus.d.ts.map +1 -0
  53. package/lib/getTransactionStatus.js +170 -0
  54. package/lib/getTransactionStatus.js.map +1 -0
  55. package/lib/hw-getAddress.d.ts +6 -0
  56. package/lib/hw-getAddress.d.ts.map +1 -0
  57. package/lib/hw-getAddress.js +28 -0
  58. package/lib/hw-getAddress.js.map +1 -0
  59. package/lib/logic.d.ts +36 -0
  60. package/lib/logic.d.ts.map +1 -0
  61. package/lib/logic.js +289 -0
  62. package/lib/logic.js.map +1 -0
  63. package/lib/network/horizon.d.ts +71 -0
  64. package/lib/network/horizon.d.ts.map +1 -0
  65. package/lib/network/horizon.js +300 -0
  66. package/lib/network/horizon.js.map +1 -0
  67. package/lib/network/index.d.ts +2 -0
  68. package/lib/network/index.d.ts.map +1 -0
  69. package/lib/network/index.js +20 -0
  70. package/lib/network/index.js.map +1 -0
  71. package/lib/prepareTransaction.d.ts +5 -0
  72. package/lib/prepareTransaction.d.ts.map +1 -0
  73. package/lib/prepareTransaction.js +41 -0
  74. package/lib/prepareTransaction.js.map +1 -0
  75. package/lib/signOperation.d.ts +6 -0
  76. package/lib/signOperation.d.ts.map +1 -0
  77. package/lib/signOperation.js +56 -0
  78. package/lib/signOperation.js.map +1 -0
  79. package/lib/specs.d.ts +7 -0
  80. package/lib/specs.d.ts.map +1 -0
  81. package/lib/specs.js +234 -0
  82. package/lib/specs.js.map +1 -0
  83. package/lib/speculos-deviceActions.d.ts +4 -0
  84. package/lib/speculos-deviceActions.d.ts.map +1 -0
  85. package/lib/speculos-deviceActions.js +99 -0
  86. package/lib/speculos-deviceActions.js.map +1 -0
  87. package/lib/synchronization.d.ts +4 -0
  88. package/lib/synchronization.d.ts.map +1 -0
  89. package/lib/synchronization.js +73 -0
  90. package/lib/synchronization.js.map +1 -0
  91. package/lib/tokens.d.ts +12 -0
  92. package/lib/tokens.d.ts.map +1 -0
  93. package/lib/tokens.js +58 -0
  94. package/lib/tokens.js.map +1 -0
  95. package/lib/transaction.d.ts +15 -0
  96. package/lib/transaction.d.ts.map +1 -0
  97. package/lib/transaction.js +63 -0
  98. package/lib/transaction.js.map +1 -0
  99. package/lib/types/index.d.ts +89 -0
  100. package/lib/types/index.d.ts.map +1 -0
  101. package/lib/types/index.js +26 -0
  102. package/lib/types/index.js.map +1 -0
  103. package/lib/types/signer.d.ts +10 -0
  104. package/lib/types/signer.d.ts.map +1 -0
  105. package/lib/types/signer.js +3 -0
  106. package/lib/types/signer.js.map +1 -0
  107. package/lib-es/bridge/bridge.integration.test.d.ts +4 -0
  108. package/lib-es/bridge/bridge.integration.test.d.ts.map +1 -0
  109. package/lib-es/bridge/bridge.integration.test.js +311 -0
  110. package/lib-es/bridge/bridge.integration.test.js.map +1 -0
  111. package/lib-es/bridge/index.d.ts +10 -0
  112. package/lib-es/bridge/index.d.ts.map +1 -0
  113. package/lib-es/bridge/index.js +65 -0
  114. package/lib-es/bridge/index.js.map +1 -0
  115. package/lib-es/broadcast.d.ts +9 -0
  116. package/lib-es/broadcast.d.ts.map +1 -0
  117. package/lib-es/broadcast.js +22 -0
  118. package/lib-es/broadcast.js.map +1 -0
  119. package/lib-es/buildOptimisticOperation.d.ts +4 -0
  120. package/lib-es/buildOptimisticOperation.d.ts.map +1 -0
  121. package/lib-es/buildOptimisticOperation.js +65 -0
  122. package/lib-es/buildOptimisticOperation.js.map +1 -0
  123. package/lib-es/buildTransaction.d.ts +10 -0
  124. package/lib-es/buildTransaction.d.ts.map +1 -0
  125. package/lib-es/buildTransaction.js +90 -0
  126. package/lib-es/buildTransaction.js.map +1 -0
  127. package/lib-es/cli.d.ts +38 -0
  128. package/lib-es/cli.d.ts.map +1 -0
  129. package/lib-es/cli.js +77 -0
  130. package/lib-es/cli.js.map +1 -0
  131. package/lib-es/config.d.ts +5 -0
  132. package/lib-es/config.d.ts.map +1 -0
  133. package/lib-es/config.js +12 -0
  134. package/lib-es/config.js.map +1 -0
  135. package/lib-es/createTransaction.d.ts +10 -0
  136. package/lib-es/createTransaction.d.ts.map +1 -0
  137. package/lib-es/createTransaction.js +22 -0
  138. package/lib-es/createTransaction.js.map +1 -0
  139. package/lib-es/deviceTransactionConfig.d.ts +24 -0
  140. package/lib-es/deviceTransactionConfig.d.ts.map +1 -0
  141. package/lib-es/deviceTransactionConfig.js +39 -0
  142. package/lib-es/deviceTransactionConfig.js.map +1 -0
  143. package/lib-es/errors.d.ts +37 -0
  144. package/lib-es/errors.d.ts.map +1 -0
  145. package/lib-es/errors.js +14 -0
  146. package/lib-es/errors.js.map +1 -0
  147. package/lib-es/estimateMaxSpendable.d.ts +5 -0
  148. package/lib-es/estimateMaxSpendable.d.ts.map +1 -0
  149. package/lib-es/estimateMaxSpendable.js +25 -0
  150. package/lib-es/estimateMaxSpendable.js.map +1 -0
  151. package/lib-es/getTransactionStatus.d.ts +5 -0
  152. package/lib-es/getTransactionStatus.d.ts.map +1 -0
  153. package/lib-es/getTransactionStatus.js +166 -0
  154. package/lib-es/getTransactionStatus.js.map +1 -0
  155. package/lib-es/hw-getAddress.d.ts +6 -0
  156. package/lib-es/hw-getAddress.d.ts.map +1 -0
  157. package/lib-es/hw-getAddress.js +26 -0
  158. package/lib-es/hw-getAddress.js.map +1 -0
  159. package/lib-es/logic.d.ts +36 -0
  160. package/lib-es/logic.d.ts.map +1 -0
  161. package/lib-es/logic.js +274 -0
  162. package/lib-es/logic.js.map +1 -0
  163. package/lib-es/network/horizon.d.ts +71 -0
  164. package/lib-es/network/horizon.d.ts.map +1 -0
  165. package/lib-es/network/horizon.js +285 -0
  166. package/lib-es/network/horizon.js.map +1 -0
  167. package/lib-es/network/index.d.ts +2 -0
  168. package/lib-es/network/index.d.ts.map +1 -0
  169. package/lib-es/network/index.js +2 -0
  170. package/lib-es/network/index.js.map +1 -0
  171. package/lib-es/prepareTransaction.d.ts +5 -0
  172. package/lib-es/prepareTransaction.d.ts.map +1 -0
  173. package/lib-es/prepareTransaction.js +34 -0
  174. package/lib-es/prepareTransaction.js.map +1 -0
  175. package/lib-es/signOperation.d.ts +6 -0
  176. package/lib-es/signOperation.d.ts.map +1 -0
  177. package/lib-es/signOperation.js +52 -0
  178. package/lib-es/signOperation.js.map +1 -0
  179. package/lib-es/specs.d.ts +7 -0
  180. package/lib-es/specs.d.ts.map +1 -0
  181. package/lib-es/specs.js +229 -0
  182. package/lib-es/specs.js.map +1 -0
  183. package/lib-es/speculos-deviceActions.d.ts +4 -0
  184. package/lib-es/speculos-deviceActions.d.ts.map +1 -0
  185. package/lib-es/speculos-deviceActions.js +96 -0
  186. package/lib-es/speculos-deviceActions.js.map +1 -0
  187. package/lib-es/synchronization.d.ts +4 -0
  188. package/lib-es/synchronization.d.ts.map +1 -0
  189. package/lib-es/synchronization.js +69 -0
  190. package/lib-es/synchronization.js.map +1 -0
  191. package/lib-es/tokens.d.ts +12 -0
  192. package/lib-es/tokens.d.ts.map +1 -0
  193. package/lib-es/tokens.js +50 -0
  194. package/lib-es/tokens.js.map +1 -0
  195. package/lib-es/transaction.d.ts +15 -0
  196. package/lib-es/transaction.d.ts.map +1 -0
  197. package/lib-es/transaction.js +59 -0
  198. package/lib-es/transaction.js.map +1 -0
  199. package/lib-es/types/index.d.ts +89 -0
  200. package/lib-es/types/index.d.ts.map +1 -0
  201. package/lib-es/types/index.js +9 -0
  202. package/lib-es/types/index.js.map +1 -0
  203. package/lib-es/types/signer.d.ts +10 -0
  204. package/lib-es/types/signer.d.ts.map +1 -0
  205. package/lib-es/types/signer.js +2 -0
  206. package/lib-es/types/signer.js.map +1 -0
  207. package/package.json +80 -0
  208. package/src/bridge/bridge.integration.test.ts +373 -0
  209. package/src/bridge/index.ts +77 -0
  210. package/src/broadcast.ts +20 -0
  211. package/src/buildOptimisticOperation.ts +63 -0
  212. package/src/buildTransaction.ts +106 -0
  213. package/src/cli.ts +107 -0
  214. package/src/config.ts +18 -0
  215. package/src/createTransaction.ts +25 -0
  216. package/src/deviceTransactionConfig.ts +75 -0
  217. package/src/errors.ts +20 -0
  218. package/src/estimateMaxSpendable.ts +29 -0
  219. package/src/getTransactionStatus.ts +207 -0
  220. package/src/hw-getAddress.ts +24 -0
  221. package/src/logic.ts +371 -0
  222. package/src/network/horizon.ts +352 -0
  223. package/src/network/index.ts +17 -0
  224. package/src/prepareTransaction.ts +35 -0
  225. package/src/signOperation.ts +58 -0
  226. package/src/specs.ts +290 -0
  227. package/src/speculos-deviceActions.ts +117 -0
  228. package/src/synchronization.ts +80 -0
  229. package/src/tokens.ts +98 -0
  230. package/src/transaction.ts +99 -0
  231. package/src/types/index.ts +112 -0
  232. package/src/types/signer.ts +9 -0
  233. package/tsconfig.json +13 -0
@@ -0,0 +1,65 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import BigNumber from "bignumber.js";
11
+ import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
12
+ import { getAmountValue } from "./logic";
13
+ import { fetchSequence } from "./network";
14
+ export function buildOptimisticOperation(account, transaction) {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ var _a;
17
+ const transactionSequenceNumber = yield fetchSequence(account);
18
+ const fees = (_a = transaction.fees) !== null && _a !== void 0 ? _a : new BigNumber(0);
19
+ const type = transaction.mode === "changeTrust" ? "OPT_IN" : "OUT";
20
+ const operation = {
21
+ id: encodeOperationId(account.id, "", type),
22
+ hash: "",
23
+ type,
24
+ value: transaction.subAccountId ? fees : getAmountValue(account, transaction, fees),
25
+ fee: fees,
26
+ blockHash: null,
27
+ blockHeight: null,
28
+ senders: [account.freshAddress],
29
+ recipients: [transaction.recipient],
30
+ accountId: account.id,
31
+ date: new Date(),
32
+ transactionSequenceNumber: transactionSequenceNumber === null || transactionSequenceNumber === void 0 ? void 0 : transactionSequenceNumber.plus(1).toNumber(),
33
+ extra: {
34
+ ledgerOpType: type,
35
+ },
36
+ };
37
+ const { subAccountId } = transaction;
38
+ const { subAccounts } = account;
39
+ const tokenAccount = !subAccountId
40
+ ? null
41
+ : subAccounts && subAccounts.find(ta => ta.id === subAccountId);
42
+ if (tokenAccount && subAccountId) {
43
+ operation.subOperations = [
44
+ {
45
+ id: `${subAccountId}--OUT`,
46
+ hash: "",
47
+ type: "OUT",
48
+ value: transaction.useAllAmount ? tokenAccount.balance : transaction.amount,
49
+ fee: new BigNumber(0),
50
+ blockHash: null,
51
+ blockHeight: null,
52
+ senders: [account.freshAddress],
53
+ recipients: [transaction.recipient],
54
+ accountId: subAccountId,
55
+ date: new Date(),
56
+ extra: {
57
+ ledgerOpType: type,
58
+ },
59
+ },
60
+ ];
61
+ }
62
+ return operation;
63
+ });
64
+ }
65
+ //# sourceMappingURL=buildOptimisticOperation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildOptimisticOperation.js","sourceRoot":"","sources":["../src/buildOptimisticOperation.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAo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AY;YAChC,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,WAAW,IAAI,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,YAAY,CAAC,CAAC;QAElE,IAAI,YAAY,IAAI,YAAY,EAAE,CAAC;YACjC,SAAS,CAAC,aAAa,GAAG;gBACxB;oBACE,EAAE,EAAE,GAAG,YAAY,OAAO;oBAC1B,IAAI,EAAE,EAAE;oBACR,IAAI,EAAE,KAAK;oBACX,KAAK,EAAE,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM;oBAC3E,GAAG,EAAE,IAAI,SAAS,CAAC,CAAC,CAAC;oBACrB,SAAS,EAAE,IAAI;oBACf,WAAW,EAAE,IAAI;oBACjB,OAAO,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC;oBAC/B,UAAU,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC;oBACnC,SAAS,EAAE,YAAY;oBACvB,IAAI,EAAE,IAAI,IAAI,EAAE;oBAChB,KAAK,EAAE;wBACL,YAAY,EAAE,IAAI;qBACnB;iBACF;aACF,CAAC;QACJ,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CAAA"}
@@ -0,0 +1,10 @@
1
+ import { Memo, Operation as StellarSdkOperation } from "@stellar/stellar-sdk";
2
+ import type { Account } from "@ledgerhq/types-live";
3
+ import type { Transaction } from "./types";
4
+ /**
5
+ * @param {Account} account
6
+ * @param {Transaction} transaction
7
+ */
8
+ export declare function buildTransaction(account: Account, transaction: Transaction): Promise<import("@stellar/stellar-sdk").Transaction<Memo<import("@stellar/stellar-sdk").MemoType>, StellarSdkOperation[]>>;
9
+ export default buildTransaction;
10
+ //# sourceMappingURL=buildTransaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildTransaction.d.ts","sourceRoot":"","sources":["../src/buildTransaction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,SAAS,IAAI,mBAAmB,EAAO,MAAM,sBAAsB,CAAC;AAEnF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAW3C;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,6HAoFhF;AAED,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,90 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import invariant from "invariant";
11
+ import { Memo } from "@stellar/stellar-sdk";
12
+ import { AmountRequired, FeeNotLoaded, NetworkDown } from "@ledgerhq/errors";
13
+ import { buildPaymentOperation, buildCreateAccountOperation, buildTransactionBuilder, buildChangeTrustOperation, loadAccount, } from "./network";
14
+ import { getRecipientAccount, getAmountValue } from "./logic";
15
+ import { StellarAssetRequired, StellarMuxedAccountNotExist } from "./errors";
16
+ /**
17
+ * @param {Account} account
18
+ * @param {Transaction} transaction
19
+ */
20
+ export function buildTransaction(account, transaction) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ const { recipient, networkInfo, fees, memoType, memoValue, mode, assetCode, assetIssuer } = transaction;
23
+ if (!fees) {
24
+ throw new FeeNotLoaded();
25
+ }
26
+ const source = yield loadAccount(account.freshAddress);
27
+ if (!source) {
28
+ throw new NetworkDown();
29
+ }
30
+ invariant(networkInfo && networkInfo.family === "stellar", "stellar family");
31
+ const transactionBuilder = buildTransactionBuilder(source, fees);
32
+ let operation = null;
33
+ if (mode === "changeTrust") {
34
+ if (!assetCode || !assetIssuer) {
35
+ throw new StellarAssetRequired("");
36
+ }
37
+ operation = buildChangeTrustOperation(assetCode, assetIssuer);
38
+ }
39
+ else {
40
+ // Payment
41
+ const amount = getAmountValue(account, transaction, fees);
42
+ if (!amount) {
43
+ throw new AmountRequired();
44
+ }
45
+ const recipientAccount = yield getRecipientAccount({
46
+ account,
47
+ recipient: transaction.recipient,
48
+ });
49
+ if (recipientAccount === null || recipientAccount === void 0 ? void 0 : recipientAccount.id) {
50
+ operation = buildPaymentOperation({
51
+ destination: recipient,
52
+ amount,
53
+ assetCode,
54
+ assetIssuer,
55
+ });
56
+ }
57
+ else {
58
+ if (recipientAccount === null || recipientAccount === void 0 ? void 0 : recipientAccount.isMuxedAccount) {
59
+ throw new StellarMuxedAccountNotExist("");
60
+ }
61
+ operation = buildCreateAccountOperation(recipient, amount);
62
+ }
63
+ }
64
+ transactionBuilder.addOperation(operation);
65
+ let memo = null;
66
+ if (memoType && memoValue) {
67
+ switch (memoType) {
68
+ case "MEMO_TEXT":
69
+ memo = Memo.text(memoValue);
70
+ break;
71
+ case "MEMO_ID":
72
+ memo = Memo.id(memoValue);
73
+ break;
74
+ case "MEMO_HASH":
75
+ memo = Memo.hash(memoValue);
76
+ break;
77
+ case "MEMO_RETURN":
78
+ memo = Memo.return(memoValue);
79
+ break;
80
+ }
81
+ }
82
+ if (memo) {
83
+ transactionBuilder.addMemo(memo);
84
+ }
85
+ const built = transactionBuilder.setTimeout(0).build();
86
+ return built;
87
+ });
88
+ }
89
+ export default buildTransaction;
90
+ //# sourceMappingURL=buildTransaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildTransaction.js","sourceRoot":"","sources":["../src/buildTransaction.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,E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CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;oBAC9B,MAAM;YACV,CAAC;QACH,CAAC;QAED,IAAI,IAAI,EAAE,CAAC;YACT,kBAAkB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACnC,CAAC;QAED,MAAM,KAAK,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;QACvD,OAAO,KAAK,CAAC;IACf,CAAC;CAAA;AAED,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { AccountLike, Account, AccountLikeArray } from "@ledgerhq/types-live";
2
+ import type { Transaction } from "./types";
3
+ declare function inferTransactions(transactions: Array<{
4
+ account: AccountLike;
5
+ transaction: Transaction;
6
+ }>, opts: Record<string, any>): Transaction[];
7
+ declare function inferAccounts(account: Account, opts: Record<string, any>): AccountLikeArray;
8
+ export default function makeCliTools(): {
9
+ options: readonly [{
10
+ readonly name: "fee";
11
+ readonly type: StringConstructor;
12
+ readonly desc: "how much fee";
13
+ }, {
14
+ readonly name: "memoType";
15
+ readonly type: StringConstructor;
16
+ readonly desc: "stellar memo type";
17
+ }, {
18
+ readonly name: "memoValue";
19
+ readonly type: StringConstructor;
20
+ readonly desc: "stellar memo value";
21
+ }, {
22
+ readonly name: "mode";
23
+ readonly type: StringConstructor;
24
+ readonly desc: "change operation type";
25
+ }, {
26
+ readonly name: "assetIssuer";
27
+ readonly type: StringConstructor;
28
+ readonly desc: "Asset issuer";
29
+ }, {
30
+ readonly name: "assetCode";
31
+ readonly type: StringConstructor;
32
+ readonly desc: "Same as token";
33
+ }];
34
+ inferTransactions: typeof inferTransactions;
35
+ inferAccounts: typeof inferAccounts;
36
+ };
37
+ export {};
38
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAEnF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAoC3C,iBAAS,iBAAiB,CACxB,YAAY,EAAE,KAAK,CAAC;IAClB,OAAO,EAAE,WAAW,CAAC;IACrB,WAAW,EAAE,WAAW,CAAC;CAC1B,CAAC,EACF,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACxB,WAAW,EAAE,CAcf;AAED,iBAAS,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,gBAAgB,CAqCpF;AAED,MAAM,CAAC,OAAO,UAAU,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAMnC"}
package/lib-es/cli.js ADDED
@@ -0,0 +1,77 @@
1
+ import invariant from "invariant";
2
+ import { getAccountCurrency } from "@ledgerhq/coin-framework/account/helpers";
3
+ import { getAssetIdFromTokenId } from "./tokens";
4
+ const options = [
5
+ {
6
+ name: "fee",
7
+ type: String,
8
+ desc: "how much fee",
9
+ },
10
+ {
11
+ name: "memoType",
12
+ type: String,
13
+ desc: "stellar memo type",
14
+ },
15
+ {
16
+ name: "memoValue",
17
+ type: String,
18
+ desc: "stellar memo value",
19
+ },
20
+ {
21
+ name: "mode",
22
+ type: String,
23
+ desc: "change operation type",
24
+ },
25
+ {
26
+ name: "assetIssuer",
27
+ type: String,
28
+ desc: "Asset issuer",
29
+ },
30
+ {
31
+ name: "assetCode",
32
+ type: String,
33
+ desc: "Same as token",
34
+ },
35
+ ];
36
+ function inferTransactions(transactions, opts) {
37
+ return transactions.map(({ transaction, account }) => {
38
+ var _a;
39
+ invariant(transaction.family === "stellar", "stellar family");
40
+ return Object.assign(Object.assign({}, transaction), { subAccountId: account.type === "TokenAccount" ? account.id : null, memoType: opts.memoType, memoValue: opts.memoValue, mode: (_a = opts.mode) !== null && _a !== void 0 ? _a : "send", assetCode: opts.token, assetIssuer: opts.assetIssuer });
41
+ });
42
+ }
43
+ function inferAccounts(account, opts) {
44
+ var _a;
45
+ invariant(account.currency.family === "stellar", "stellar family");
46
+ if (opts.subAccountId) {
47
+ const assetSubAccount = (_a = account.subAccounts) === null || _a === void 0 ? void 0 : _a.find(a => a.id === opts.subAccountId);
48
+ if (!assetSubAccount) {
49
+ throw new Error(`${opts.subAccountId} asset not found`);
50
+ }
51
+ return [assetSubAccount];
52
+ }
53
+ if (opts.assetCode) {
54
+ const subAccounts = account.subAccounts || [];
55
+ const subAccount = subAccounts.find(sa => {
56
+ const currency = getAccountCurrency(sa);
57
+ return (opts.assetCode.toLowerCase() === currency.ticker.toLowerCase() ||
58
+ opts.assetCode.toLowerCase() === getAssetIdFromTokenId(currency.id));
59
+ });
60
+ if (!subAccount) {
61
+ throw new Error("token account '" +
62
+ opts.assetCode +
63
+ "' not found. Available: " +
64
+ subAccounts.map(t => getAccountCurrency(t).ticker).join(", "));
65
+ }
66
+ return [subAccount];
67
+ }
68
+ return [account];
69
+ }
70
+ export default function makeCliTools() {
71
+ return {
72
+ options,
73
+ inferTransactions,
74
+ inferAccounts,
75
+ };
76
+ }
77
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AAE9E,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAEjD,MAAM,OAAO,GAAG;IACd;QACE,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,cAAc;KACrB;IACD;QACE,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,mBAAmB;KAC1B;IACD;QACE,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,oB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CAAC,GAAG,IAAI,CAAC,YAAY,kBAAkB,CAAC,CAAC;QAC1D,CAAC;QAED,OAAO,CAAC,eAAe,CAAC,CAAC;IAC3B,CAAC;IAED,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;QACnB,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,EAAE,CAAC;QAE9C,MAAM,UAAU,GAAG,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;YACvC,MAAM,QAAQ,GAAG,kBAAkB,CAAC,EAAE,CAAC,CAAC;YACxC,OAAO,CACL,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,KAAK,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE;gBAC9D,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,KAAK,qBAAqB,CAAC,QAAQ,CAAC,EAAE,CAAC,CACpE,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CACb,iBAAiB;gBACf,IAAI,CAAC,SAAS;gBACd,0BAA0B;gBAC1B,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAChE,CAAC;QACJ,CAAC;QAED,OAAO,CAAC,UAAU,CAAC,CAAC;IACtB,CAAC;IAED,OAAO,CAAC,OAAO,CAAC,CAAC;AACnB,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,YAAY;IAClC,OAAO;QACL,OAAO;QACP,iBAAiB;QACjB,aAAa;KACd,CAAC;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { CurrencyConfig, CoinConfig } from "@ledgerhq/coin-framework/config";
2
+ export type StellarCoinConfig = CurrencyConfig;
3
+ export declare function setCoinConfig(config: CoinConfig<StellarCoinConfig>): void;
4
+ export declare function getCoinConfig(): StellarCoinConfig;
5
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAG7E,MAAM,MAAM,iBAAiB,GAAG,cAAc,CAAC;AAI/C,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,iBAAiB,CAAC,GAAG,IAAI,CAEzE;AAED,wBAAgB,aAAa,IAAI,iBAAiB,CAMjD"}
@@ -0,0 +1,12 @@
1
+ import { MissingCoinConfig } from "@ledgerhq/coin-framework/errors";
2
+ let coinConfig;
3
+ export function setCoinConfig(config) {
4
+ coinConfig = config;
5
+ }
6
+ export function getCoinConfig() {
7
+ if (!coinConfig) {
8
+ throw new MissingCoinConfig();
9
+ }
10
+ return coinConfig();
11
+ }
12
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAIpE,IAAI,UAAqD,CAAC;AAE1D,MAAM,UAAU,aAAa,CAAC,MAAqC;IACjE,UAAU,GAAG,MAAM,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,iBAAiB,EAAE,CAAC;IAChC,CAAC;IAED,OAAO,UAAU,EAAE,CAAC;AACtB,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { AccountBridge } from "@ledgerhq/types-live";
2
+ import type { Transaction } from "./types";
3
+ /**
4
+ * Create an empty transaction
5
+ *
6
+ * @returns {Transaction}
7
+ */
8
+ export declare const createTransaction: AccountBridge<Transaction>["createTransaction"];
9
+ export default createTransaction;
10
+ //# sourceMappingURL=createTransaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createTransaction.d.ts","sourceRoot":"","sources":["../src/createTransaction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC,mBAAmB,CAa5E,CAAC;AAEH,eAAe,iBAAiB,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { BigNumber } from "bignumber.js";
2
+ /**
3
+ * Create an empty transaction
4
+ *
5
+ * @returns {Transaction}
6
+ */
7
+ export const createTransaction = () => ({
8
+ family: "stellar",
9
+ amount: new BigNumber(0),
10
+ baseReserve: null,
11
+ networkInfo: null,
12
+ fees: null,
13
+ recipient: "",
14
+ memoValue: null,
15
+ memoType: null,
16
+ useAllAmount: false,
17
+ mode: "send",
18
+ assetCode: "",
19
+ assetIssuer: "",
20
+ });
21
+ export default createTransaction;
22
+ //# sourceMappingURL=createTransaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createTransaction.js","sourceRoot":"","sources":["../src/createTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAIzC;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAoD,GAAG,EAAE,CAAC,CAAC;IACvF,MAAM,EAAE,SAAS;IACjB,MAAM,EAAE,IAAI,SAAS,CAAC,CAAC,CAAC;IACxB,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;IACjB,IAAI,EAAE,IAAI;IACV,SAAS,EAAE,EAAE;IACb,SAAS,EAAE,IAAI;IACf,QAAQ,EAAE,IAAI;IACd,YAAY,EAAE,KAAK;IACnB,IAAI,EAAE,MAAM;IACZ,SAAS,EAAE,EAAE;IACb,WAAW,EAAE,EAAE;CAChB,CAAC,CAAC;AAEH,eAAe,iBAAiB,CAAC"}
@@ -0,0 +1,24 @@
1
+ import type { AccountLike, Account } from "@ledgerhq/types-live";
2
+ import type { CommonDeviceTransactionField as DeviceTransactionField } from "@ledgerhq/coin-framework/transaction/common";
3
+ import type { Transaction, TransactionStatus } from "./types";
4
+ export type ExtraDeviceTransactionField = {
5
+ type: "stellar.memo";
6
+ label: string;
7
+ } | {
8
+ type: "stellar.network";
9
+ label: string;
10
+ } | {
11
+ type: "stellar.assetCode";
12
+ label: string;
13
+ } | {
14
+ type: "stellar.assetIssuer";
15
+ label: string;
16
+ };
17
+ declare function getDeviceTransactionConfig({ status: { amount, estimatedFees }, transaction, }: {
18
+ account: AccountLike;
19
+ parentAccount: Account | null | undefined;
20
+ transaction: Transaction;
21
+ status: TransactionStatus;
22
+ }): Array<DeviceTransactionField | ExtraDeviceTransactionField>;
23
+ export default getDeviceTransactionConfig;
24
+ //# sourceMappingURL=deviceTransactionConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deviceTransactionConfig.d.ts","sourceRoot":"","sources":["../src/deviceTransactionConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,KAAK,EAAE,4BAA4B,IAAI,sBAAsB,EAAE,MAAM,6CAA6C,CAAC;AAC1H,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE9D,MAAM,MAAM,2BAA2B,GACnC;IACE,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACf,GACD;IACE,IAAI,EAAE,iBAAiB,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;CACf,GACD;IACE,IAAI,EAAE,mBAAmB,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;CACf,GACD;IACE,IAAI,EAAE,qBAAqB,CAAC;IAC5B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEN,iBAAS,0BAA0B,CAAC,EAClC,MAAM,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,EACjC,WAAW,GACZ,EAAE;IACD,OAAO,EAAE,WAAW,CAAC;IACrB,aAAa,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;IAC1C,WAAW,EAAE,WAAW,CAAC;IACzB,MAAM,EAAE,iBAAiB,CAAC;CAC3B,GAAG,KAAK,CAAC,sBAAsB,GAAG,2BAA2B,CAAC,CA0C9D;AAED,eAAe,0BAA0B,CAAC"}
@@ -0,0 +1,39 @@
1
+ function getDeviceTransactionConfig({ status: { amount, estimatedFees }, transaction, }) {
2
+ const { assetCode, assetIssuer } = transaction;
3
+ const fields = [
4
+ {
5
+ type: "stellar.network",
6
+ label: "Network",
7
+ },
8
+ ];
9
+ if (!amount.isZero()) {
10
+ fields.push({
11
+ type: "amount",
12
+ label: "Amount",
13
+ });
14
+ }
15
+ if (assetCode && assetIssuer) {
16
+ fields.push({
17
+ type: "stellar.assetCode",
18
+ label: "Asset",
19
+ });
20
+ fields.push({
21
+ type: "stellar.assetIssuer",
22
+ label: "Asset issuer",
23
+ });
24
+ }
25
+ fields.push({
26
+ type: "stellar.memo",
27
+ label: "Memo",
28
+ });
29
+ //NB device displays [none] for an empty memo
30
+ if (estimatedFees && !estimatedFees.isZero()) {
31
+ fields.push({
32
+ type: "fees",
33
+ label: "Fees",
34
+ });
35
+ }
36
+ return fields;
37
+ }
38
+ export default getDeviceTransactionConfig;
39
+ //# sourceMappingURL=deviceTransactionConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deviceTransactionConfig.js","sourceRoot":"","sources":["../src/deviceTransactionConfig.ts"],"names":[],"mappings":"AAsBA,SAAS,0BAA0B,CAAC,EAClC,MAAM,EAAE,EAAE,MAAM,EAAE,aAAa,EAAE,EACjC,WAAW,GAMZ;IACC,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,WAAW,CAAC;IAE/C,MAAM,MAAM,GAAgE;QAC1E;YACE,IAAI,EAAE,iBAAiB;YACvB,KAAK,EAAE,SAAS;SACjB;KACF,CAAC;IAEF,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC;QACrB,MAAM,CAAC,IAAI,CAAC;YACV,IAAI,EAAE,QAAQ;YACd,KAAK,EAAE,QAAQ;SAChB,CAAC,CAAC;IACL,CAAC;IAED,IAAI,SAAS,IAAI,WAAW,EAAE,CAAC;QAC7B,MAAM,CAAC,IAAI,CAAC;YACV,IAAI,EAAE,mBAAmB;YACzB,KAAK,EAAE,OAAO;SACf,CAAC,CAAC;QACH,MAAM,CAAC,IAAI,CAAC;YACV,IAAI,EAAE,qBAAqB;YAC3B,KAAK,EAAE,cAAc;SACtB,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,IAAI,CAAC;QACV,IAAI,EAAE,cAAc;QACpB,KAAK,EAAE,MAAM;KACd,CAAC,CAAC;IAEH,6CAA6C;IAC7C,IAAI,aAAa,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,EAAE,CAAC;QAC7C,MAAM,CAAC,IAAI,CAAC;YACV,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,MAAM;SACd,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,eAAe,0BAA0B,CAAC"}
@@ -0,0 +1,37 @@
1
+ export declare const StellarBurnAddressError: import("@ledgerhq/errors/lib/helpers").LedgerErrorConstructor<{
2
+ [key: string]: unknown;
3
+ }>;
4
+ export declare const StellarAssetRequired: import("@ledgerhq/errors/lib/helpers").LedgerErrorConstructor<{
5
+ [key: string]: unknown;
6
+ }>;
7
+ export declare const StellarMuxedAccountNotExist: import("@ledgerhq/errors/lib/helpers").LedgerErrorConstructor<{
8
+ [key: string]: unknown;
9
+ }>;
10
+ export declare const StellarMemoRecommended: import("@ledgerhq/errors/lib/helpers").LedgerErrorConstructor<{
11
+ [key: string]: unknown;
12
+ }>;
13
+ export declare const StellarWrongMemoFormat: import("@ledgerhq/errors/lib/helpers").LedgerErrorConstructor<{
14
+ [key: string]: unknown;
15
+ }>;
16
+ export declare const StellarAssetNotAccepted: import("@ledgerhq/errors/lib/helpers").LedgerErrorConstructor<{
17
+ [key: string]: unknown;
18
+ }>;
19
+ export declare const StellarAssetNotFound: import("@ledgerhq/errors/lib/helpers").LedgerErrorConstructor<{
20
+ [key: string]: unknown;
21
+ }>;
22
+ export declare const StellarNotEnoughNativeBalance: import("@ledgerhq/errors/lib/helpers").LedgerErrorConstructor<{
23
+ [key: string]: unknown;
24
+ }>;
25
+ export declare const StellarFeeSmallerThanRecommended: import("@ledgerhq/errors/lib/helpers").LedgerErrorConstructor<{
26
+ [key: string]: unknown;
27
+ }>;
28
+ export declare const StellarFeeSmallerThanBase: import("@ledgerhq/errors/lib/helpers").LedgerErrorConstructor<{
29
+ [key: string]: unknown;
30
+ }>;
31
+ export declare const StellarNotEnoughNativeBalanceToAddTrustline: import("@ledgerhq/errors/lib/helpers").LedgerErrorConstructor<{
32
+ [key: string]: unknown;
33
+ }>;
34
+ export declare const StellarSourceHasMultiSign: import("@ledgerhq/errors/lib/helpers").LedgerErrorConstructor<{
35
+ [key: string]: unknown;
36
+ }>;
37
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,uBAAuB;;EAAoD,CAAC;AACzF,eAAO,MAAM,oBAAoB;;EAAiD,CAAC;AACnF,eAAO,MAAM,2BAA2B;;EAAwD,CAAC;AACjG,eAAO,MAAM,sBAAsB;;EAAmD,CAAC;AACvF,eAAO,MAAM,sBAAsB;;EAAmD,CAAC;AACvF,eAAO,MAAM,uBAAuB;;EAAoD,CAAC;AACzF,eAAO,MAAM,oBAAoB;;EAAiD,CAAC;AACnF,eAAO,MAAM,6BAA6B;;EAEzC,CAAC;AACF,eAAO,MAAM,gCAAgC;;EAE5C,CAAC;AACF,eAAO,MAAM,yBAAyB;;EAAsD,CAAC;AAC7F,eAAO,MAAM,2CAA2C;;EAEvD,CAAC;AACF,eAAO,MAAM,yBAAyB;;EAAsD,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { createCustomErrorClass } from "@ledgerhq/errors";
2
+ export const StellarBurnAddressError = createCustomErrorClass("StellarBurnAddressError");
3
+ export const StellarAssetRequired = createCustomErrorClass("StellarAssetRequired");
4
+ export const StellarMuxedAccountNotExist = createCustomErrorClass("StellarMuxedAccountNotExist");
5
+ export const StellarMemoRecommended = createCustomErrorClass("StellarMemoRecommended");
6
+ export const StellarWrongMemoFormat = createCustomErrorClass("StellarWrongMemoFormat");
7
+ export const StellarAssetNotAccepted = createCustomErrorClass("StellarAssetNotAccepted");
8
+ export const StellarAssetNotFound = createCustomErrorClass("StellarAssetNotFound");
9
+ export const StellarNotEnoughNativeBalance = createCustomErrorClass("StellarNotEnoughNativeBalance");
10
+ export const StellarFeeSmallerThanRecommended = createCustomErrorClass("StellarFeeSmallerThanRecommended");
11
+ export const StellarFeeSmallerThanBase = createCustomErrorClass("StellarFeeSmallerThanBase");
12
+ export const StellarNotEnoughNativeBalanceToAddTrustline = createCustomErrorClass("StellarNotEnoughNativeBalanceToAddTrustline");
13
+ export const StellarSourceHasMultiSign = createCustomErrorClass("StellarSourceHasMultiSign");
14
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,MAAM,CAAC,MAAM,uBAAuB,GAAG,sBAAsB,CAAC,yBAAyB,CAAC,CAAC;AACzF,MAAM,CAAC,MAAM,oBAAoB,GAAG,sBAAsB,CAAC,sBAAsB,CAAC,CAAC;AACnF,MAAM,CAAC,MAAM,2BAA2B,GAAG,sBAAsB,CAAC,6BAA6B,CAAC,CAAC;AACjG,MAAM,CAAC,MAAM,sBAAsB,GAAG,sBAAsB,CAAC,wBAAwB,CAAC,CAAC;AACvF,MAAM,CAAC,MAAM,sBAAsB,GAAG,sBAAsB,CAAC,wBAAwB,CAAC,CAAC;AACvF,MAAM,CAAC,MAAM,uBAAuB,GAAG,sBAAsB,CAAC,yBAAyB,CAAC,CAAC;AACzF,MAAM,CAAC,MAAM,oBAAoB,GAAG,sBAAsB,CAAC,sBAAsB,CAAC,CAAC;AACnF,MAAM,CAAC,MAAM,6BAA6B,GAAG,sBAAsB,CACjE,+BAA+B,CAChC,CAAC;AACF,MAAM,CAAC,MAAM,gCAAgC,GAAG,sBAAsB,CACpE,kCAAkC,CACnC,CAAC;AACF,MAAM,CAAC,MAAM,yBAAyB,GAAG,sBAAsB,CAAC,2BAA2B,CAAC,CAAC;AAC7F,MAAM,CAAC,MAAM,2CAA2C,GAAG,sBAAsB,CAC/E,6CAA6C,CAC9C,CAAC;AACF,MAAM,CAAC,MAAM,yBAAyB,GAAG,sBAAsB,CAAC,2BAA2B,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { AccountBridge } from "@ledgerhq/types-live";
2
+ import type { Transaction } from "./types";
3
+ export declare const estimateMaxSpendable: AccountBridge<Transaction>["estimateMaxSpendable"];
4
+ export default estimateMaxSpendable;
5
+ //# sourceMappingURL=estimateMaxSpendable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"estimateMaxSpendable.d.ts","sourceRoot":"","sources":["../src/estimateMaxSpendable.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAK1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAI3C,eAAO,MAAM,oBAAoB,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC,sBAAsB,CAgBnF,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
@@ -0,0 +1,25 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import BigNumber from "bignumber.js";
11
+ import { getMainAccount } from "@ledgerhq/coin-framework/account";
12
+ import { getTransactionStatus } from "./getTransactionStatus";
13
+ import { prepareTransaction } from "./prepareTransaction";
14
+ import { createTransaction } from "./createTransaction";
15
+ const notCreatedStellarMockAddress = "GAW46JE3SHIAYLNNNQCAZFQ437WB5ZH7LDRDWR5LVDWHCTHCKYB6RCCH";
16
+ export const estimateMaxSpendable = (_a) => __awaiter(void 0, [_a], void 0, function* ({ account, parentAccount, transaction, }) {
17
+ const mainAccount = getMainAccount(account, parentAccount);
18
+ const preparedTransaction = yield prepareTransaction(mainAccount, Object.assign(Object.assign(Object.assign({}, createTransaction(account)), transaction), { recipient: (transaction === null || transaction === void 0 ? void 0 : transaction.recipient) || notCreatedStellarMockAddress,
19
+ // not used address
20
+ useAllAmount: true }));
21
+ const status = yield getTransactionStatus(mainAccount, preparedTransaction);
22
+ return status.amount.gte(0) ? status.amount : new BigNumber(0);
23
+ });
24
+ export default estimateMaxSpendable;
25
+ //# sourceMappingURL=estimateMaxSpendable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"estimateMaxSpendable.js","sourceRoot":"","sources":["../src/estimateMaxSpendable.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD,MAAM,4BAA4B,GAAG,0DAA0D,CAAC;AAEhG,MAAM,CAAC,MAAM,oBAAoB,GAAuD,KAIrF,EAAE,4CAJ0F,EAC7F,OAAO,EACP,aAAa,EACb,WAAW,GACZ;IACC,MAAM,WAAW,GAAG,cAAc,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAC3D,MAAM,mBAAmB,GAAG,MAAM,kBAAkB,CAAC,WAAW,gDAC3D,iBAAiB,CAAC,OAAO,CAAC,GAC1B,WAAW,KACd,SAAS,EAAE,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,SAAS,KAAI,4BAA4B;QACjE,mBAAmB;QACnB,YAAY,EAAE,IAAI,IAClB,CAAC;IAEH,MAAM,MAAM,GAAG,MAAM,oBAAoB,CAAC,WAAW,EAAE,mBAAmB,CAAC,CAAC;IAC5E,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC;AACjE,CAAC,CAAA,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { AccountBridge } from "@ledgerhq/types-live";
2
+ import type { Transaction } from "./types";
3
+ export declare const getTransactionStatus: AccountBridge<Transaction>["getTransactionStatus"];
4
+ export default getTransactionStatus;
5
+ //# sourceMappingURL=getTransactionStatus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getTransactionStatus.d.ts","sourceRoot":"","sources":["../src/getTransactionStatus.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAK1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAc3C,eAAO,MAAM,oBAAoB,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC,sBAAsB,CA6KnF,CAAC;AAEF,eAAe,oBAAoB,CAAC"}