@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,72 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.buildOptimisticOperation = void 0;
16
+ const bignumber_js_1 = __importDefault(require("bignumber.js"));
17
+ const operation_1 = require("@ledgerhq/coin-framework/operation");
18
+ const logic_1 = require("./logic");
19
+ const network_1 = require("./network");
20
+ function buildOptimisticOperation(account, transaction) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ var _a;
23
+ const transactionSequenceNumber = yield (0, network_1.fetchSequence)(account);
24
+ const fees = (_a = transaction.fees) !== null && _a !== void 0 ? _a : new bignumber_js_1.default(0);
25
+ const type = transaction.mode === "changeTrust" ? "OPT_IN" : "OUT";
26
+ const operation = {
27
+ id: (0, operation_1.encodeOperationId)(account.id, "", type),
28
+ hash: "",
29
+ type,
30
+ value: transaction.subAccountId ? fees : (0, logic_1.getAmountValue)(account, transaction, fees),
31
+ fee: fees,
32
+ blockHash: null,
33
+ blockHeight: null,
34
+ senders: [account.freshAddress],
35
+ recipients: [transaction.recipient],
36
+ accountId: account.id,
37
+ date: new Date(),
38
+ transactionSequenceNumber: transactionSequenceNumber === null || transactionSequenceNumber === void 0 ? void 0 : transactionSequenceNumber.plus(1).toNumber(),
39
+ extra: {
40
+ ledgerOpType: type,
41
+ },
42
+ };
43
+ const { subAccountId } = transaction;
44
+ const { subAccounts } = account;
45
+ const tokenAccount = !subAccountId
46
+ ? null
47
+ : subAccounts && subAccounts.find(ta => ta.id === subAccountId);
48
+ if (tokenAccount && subAccountId) {
49
+ operation.subOperations = [
50
+ {
51
+ id: `${subAccountId}--OUT`,
52
+ hash: "",
53
+ type: "OUT",
54
+ value: transaction.useAllAmount ? tokenAccount.balance : transaction.amount,
55
+ fee: new bignumber_js_1.default(0),
56
+ blockHash: null,
57
+ blockHeight: null,
58
+ senders: [account.freshAddress],
59
+ recipients: [transaction.recipient],
60
+ accountId: subAccountId,
61
+ date: new Date(),
62
+ extra: {
63
+ ledgerOpType: type,
64
+ },
65
+ },
66
+ ];
67
+ }
68
+ return operation;
69
+ });
70
+ }
71
+ exports.buildOptimisticOperation = buildOptimisticOperation;
72
+ //# sourceMappingURL=buildOptimisticOperation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildOptimisticOperation.js","sourceRoot":"","sources":["../src/buildOptimisticOperation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,gEAAqC;AAErC,kEAAuE;AAEvE,mCAAyC;AACzC,uCAA0C;AAE1C,SAAsB,wBAAwB,CAC5C,OAAgB,EAChB,WAAwB;;;QAExB,MAAM,yBAAyB,GAAG,MAAM,IAAA,uBAAa,EAAC,OAAO,CAAC,CAAC;QAC/D,MAAM,IAAI,GAAG,MAAA,WAAW,CAAC,IAAI,mCAAI,IAAI,sBAAS,CAAC,CAAC,CAAC,CAAC;QAClD,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,KAAK,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC;QAEnE,MAAM,SAAS,GAAqB;YAClC,EAAE,EAAE,IAAA,6BAAiB,EAAC,OAAO,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC;YAC3C,IAAI,EAAE,EAAE;YACR,IAAI;YACJ,KAAK,EAAE,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAA,sBAAc,EAAC,OAAO,EAAE,WAAW,EAAE,IAAI,CAAC;YACnF,GAAG,EAAE,IAAI;YACT,SAAS,EAAE,IAAI;YACf,WAAW,EAAE,IAAI;YACjB,OAAO,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC;YAC/B,UAAU,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC;YACnC,SAAS,EAAE,OAAO,CAAC,EAAE;YACrB,IAAI,EAAE,IAAI,IAAI,EAAE;YAChB,yBAAyB,EAAE,yBAAyB,aAAzB,yBAAyB,uBAAzB,yBAAyB,CAAE,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE;YACxE,KAAK,EAAE;gBACL,YAAY,EAAE,IAAI;aACnB;SACF,CAAC;QAEF,MAAM,EAAE,YAAY,EAAE,GAAG,WAAW,CAAC;QACrC,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;QAEhC,MAAM,YAAY,GAAG,CAAC,YAAY;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,sBAAS,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;AAvDD,4DAuDC"}
@@ -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,97 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.buildTransaction = void 0;
16
+ const invariant_1 = __importDefault(require("invariant"));
17
+ const stellar_sdk_1 = require("@stellar/stellar-sdk");
18
+ const errors_1 = require("@ledgerhq/errors");
19
+ const network_1 = require("./network");
20
+ const logic_1 = require("./logic");
21
+ const errors_2 = require("./errors");
22
+ /**
23
+ * @param {Account} account
24
+ * @param {Transaction} transaction
25
+ */
26
+ function buildTransaction(account, transaction) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ const { recipient, networkInfo, fees, memoType, memoValue, mode, assetCode, assetIssuer } = transaction;
29
+ if (!fees) {
30
+ throw new errors_1.FeeNotLoaded();
31
+ }
32
+ const source = yield (0, network_1.loadAccount)(account.freshAddress);
33
+ if (!source) {
34
+ throw new errors_1.NetworkDown();
35
+ }
36
+ (0, invariant_1.default)(networkInfo && networkInfo.family === "stellar", "stellar family");
37
+ const transactionBuilder = (0, network_1.buildTransactionBuilder)(source, fees);
38
+ let operation = null;
39
+ if (mode === "changeTrust") {
40
+ if (!assetCode || !assetIssuer) {
41
+ throw new errors_2.StellarAssetRequired("");
42
+ }
43
+ operation = (0, network_1.buildChangeTrustOperation)(assetCode, assetIssuer);
44
+ }
45
+ else {
46
+ // Payment
47
+ const amount = (0, logic_1.getAmountValue)(account, transaction, fees);
48
+ if (!amount) {
49
+ throw new errors_1.AmountRequired();
50
+ }
51
+ const recipientAccount = yield (0, logic_1.getRecipientAccount)({
52
+ account,
53
+ recipient: transaction.recipient,
54
+ });
55
+ if (recipientAccount === null || recipientAccount === void 0 ? void 0 : recipientAccount.id) {
56
+ operation = (0, network_1.buildPaymentOperation)({
57
+ destination: recipient,
58
+ amount,
59
+ assetCode,
60
+ assetIssuer,
61
+ });
62
+ }
63
+ else {
64
+ if (recipientAccount === null || recipientAccount === void 0 ? void 0 : recipientAccount.isMuxedAccount) {
65
+ throw new errors_2.StellarMuxedAccountNotExist("");
66
+ }
67
+ operation = (0, network_1.buildCreateAccountOperation)(recipient, amount);
68
+ }
69
+ }
70
+ transactionBuilder.addOperation(operation);
71
+ let memo = null;
72
+ if (memoType && memoValue) {
73
+ switch (memoType) {
74
+ case "MEMO_TEXT":
75
+ memo = stellar_sdk_1.Memo.text(memoValue);
76
+ break;
77
+ case "MEMO_ID":
78
+ memo = stellar_sdk_1.Memo.id(memoValue);
79
+ break;
80
+ case "MEMO_HASH":
81
+ memo = stellar_sdk_1.Memo.hash(memoValue);
82
+ break;
83
+ case "MEMO_RETURN":
84
+ memo = stellar_sdk_1.Memo.return(memoValue);
85
+ break;
86
+ }
87
+ }
88
+ if (memo) {
89
+ transactionBuilder.addMemo(memo);
90
+ }
91
+ const built = transactionBuilder.setTimeout(0).build();
92
+ return built;
93
+ });
94
+ }
95
+ exports.buildTransaction = buildTransaction;
96
+ exports.default = buildTransaction;
97
+ //# sourceMappingURL=buildTransaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildTransaction.js","sourceRoot":"","sources":["../src/buildTransaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0DAAkC;AAClC,sDAAmF;AACnF,6CAA6E;AAG7E,uCAMmB;AACnB,mCAA8D;AAC9D,qCAA6E;AAE7E;;;GAGG;AACH,SAAsB,gBAAgB,CAAC,OAAgB,EAAE,WAAwB;;QAC/E,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,GACvF,WAAW,CAAC;QAEd,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,qBAAY,EAAE,CAAC;QAC3B,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAA,qBAAW,EAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QAEvD,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,oBAAW,EAAE,CAAC;QAC1B,CAAC;QAED,IAAA,mBAAS,EAAC,WAAW,IAAI,WAAW,CAAC,MAAM,KAAK,SAAS,EAAE,gBAAgB,CAAC,CAAC;QAE7E,MAAM,kBAAkB,GAAG,IAAA,iCAAuB,EAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACjE,IAAI,SAAS,GAA0D,IAAI,CAAC;QAE5E,IAAI,IAAI,KAAK,aAAa,EAAE,CAAC;YAC3B,IAAI,CAAC,SAAS,IAAI,CAAC,WAAW,EAAE,CAAC;gBAC/B,MAAM,IAAI,6BAAoB,CAAC,EAAE,CA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BAER,KAAK,WAAW;oBACd,IAAI,GAAG,kBAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;oBAC5B,MAAM;gBAER,KAAK,aAAa;oBAChB,IAAI,GAAG,kBAAI,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;AApFD,4CAoFC;AAED,kBAAe,gBAAgB,CAAC"}
package/lib/cli.d.ts ADDED
@@ -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/cli.js ADDED
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const invariant_1 = __importDefault(require("invariant"));
7
+ const helpers_1 = require("@ledgerhq/coin-framework/account/helpers");
8
+ const tokens_1 = require("./tokens");
9
+ const options = [
10
+ {
11
+ name: "fee",
12
+ type: String,
13
+ desc: "how much fee",
14
+ },
15
+ {
16
+ name: "memoType",
17
+ type: String,
18
+ desc: "stellar memo type",
19
+ },
20
+ {
21
+ name: "memoValue",
22
+ type: String,
23
+ desc: "stellar memo value",
24
+ },
25
+ {
26
+ name: "mode",
27
+ type: String,
28
+ desc: "change operation type",
29
+ },
30
+ {
31
+ name: "assetIssuer",
32
+ type: String,
33
+ desc: "Asset issuer",
34
+ },
35
+ {
36
+ name: "assetCode",
37
+ type: String,
38
+ desc: "Same as token",
39
+ },
40
+ ];
41
+ function inferTransactions(transactions, opts) {
42
+ return transactions.map(({ transaction, account }) => {
43
+ var _a;
44
+ (0, invariant_1.default)(transaction.family === "stellar", "stellar family");
45
+ 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 });
46
+ });
47
+ }
48
+ function inferAccounts(account, opts) {
49
+ var _a;
50
+ (0, invariant_1.default)(account.currency.family === "stellar", "stellar family");
51
+ if (opts.subAccountId) {
52
+ const assetSubAccount = (_a = account.subAccounts) === null || _a === void 0 ? void 0 : _a.find(a => a.id === opts.subAccountId);
53
+ if (!assetSubAccount) {
54
+ throw new Error(`${opts.subAccountId} asset not found`);
55
+ }
56
+ return [assetSubAccount];
57
+ }
58
+ if (opts.assetCode) {
59
+ const subAccounts = account.subAccounts || [];
60
+ const subAccount = subAccounts.find(sa => {
61
+ const currency = (0, helpers_1.getAccountCurrency)(sa);
62
+ return (opts.assetCode.toLowerCase() === currency.ticker.toLowerCase() ||
63
+ opts.assetCode.toLowerCase() === (0, tokens_1.getAssetIdFromTokenId)(currency.id));
64
+ });
65
+ if (!subAccount) {
66
+ throw new Error("token account '" +
67
+ opts.assetCode +
68
+ "' not found. Available: " +
69
+ subAccounts.map(t => (0, helpers_1.getAccountCurrency)(t).ticker).join(", "));
70
+ }
71
+ return [subAccount];
72
+ }
73
+ return [account];
74
+ }
75
+ function makeCliTools() {
76
+ return {
77
+ options,
78
+ inferTransactions,
79
+ inferAccounts,
80
+ };
81
+ }
82
+ exports.default = makeCliTools;
83
+ //# sourceMappingURL=cli.js.map
package/lib/cli.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;AAAA,0DA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C,CAAC;AACnB,CAAC;AAED,SAAwB,YAAY;IAClC,OAAO;QACL,OAAO;QACP,iBAAiB;QACjB,aAAa;KACd,CAAC;AACJ,CAAC;AAND,+BAMC"}
@@ -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"}
package/lib/config.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCoinConfig = exports.setCoinConfig = void 0;
4
+ const errors_1 = require("@ledgerhq/coin-framework/errors");
5
+ let coinConfig;
6
+ function setCoinConfig(config) {
7
+ coinConfig = config;
8
+ }
9
+ exports.setCoinConfig = setCoinConfig;
10
+ function getCoinConfig() {
11
+ if (!coinConfig) {
12
+ throw new errors_1.MissingCoinConfig();
13
+ }
14
+ return coinConfig();
15
+ }
16
+ exports.getCoinConfig = getCoinConfig;
17
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;AACA,4DAAoE;AAIpE,IAAI,UAAqD,CAAC;AAE1D,SAAgB,aAAa,CAAC,MAAqC;IACjE,UAAU,GAAG,MAAM,CAAC;AACtB,CAAC;AAFD,sCAEC;AAED,SAAgB,aAAa;IAC3B,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,0BAAiB,EAAE,CAAC;IAChC,CAAC;IAED,OAAO,UAAU,EAAE,CAAC;AACtB,CAAC;AAND,sCAMC"}
@@ -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,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTransaction = void 0;
4
+ const bignumber_js_1 = require("bignumber.js");
5
+ /**
6
+ * Create an empty transaction
7
+ *
8
+ * @returns {Transaction}
9
+ */
10
+ const createTransaction = () => ({
11
+ family: "stellar",
12
+ amount: new bignumber_js_1.BigNumber(0),
13
+ baseReserve: null,
14
+ networkInfo: null,
15
+ fees: null,
16
+ recipient: "",
17
+ memoValue: null,
18
+ memoType: null,
19
+ useAllAmount: false,
20
+ mode: "send",
21
+ assetCode: "",
22
+ assetIssuer: "",
23
+ });
24
+ exports.createTransaction = createTransaction;
25
+ exports.default = exports.createTransaction;
26
+ //# sourceMappingURL=createTransaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createTransaction.js","sourceRoot":"","sources":["../src/createTransaction.ts"],"names":[],"mappings":";;;AAAA,+CAAyC;AAIzC;;;;GAIG;AACI,MAAM,iBAAiB,GAAoD,GAAG,EAAE,CAAC,CAAC;IACvF,MAAM,EAAE,SAAS;IACjB,MAAM,EAAE,IAAI,wBAAS,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;AAbU,QAAA,iBAAiB,qBAa3B;AAEH,kBAAe,yBAAiB,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,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function getDeviceTransactionConfig({ status: { amount, estimatedFees }, transaction, }) {
4
+ const { assetCode, assetIssuer } = transaction;
5
+ const fields = [
6
+ {
7
+ type: "stellar.network",
8
+ label: "Network",
9
+ },
10
+ ];
11
+ if (!amount.isZero()) {
12
+ fields.push({
13
+ type: "amount",
14
+ label: "Amount",
15
+ });
16
+ }
17
+ if (assetCode && assetIssuer) {
18
+ fields.push({
19
+ type: "stellar.assetCode",
20
+ label: "Asset",
21
+ });
22
+ fields.push({
23
+ type: "stellar.assetIssuer",
24
+ label: "Asset issuer",
25
+ });
26
+ }
27
+ fields.push({
28
+ type: "stellar.memo",
29
+ label: "Memo",
30
+ });
31
+ //NB device displays [none] for an empty memo
32
+ if (estimatedFees && !estimatedFees.isZero()) {
33
+ fields.push({
34
+ type: "fees",
35
+ label: "Fees",
36
+ });
37
+ }
38
+ return fields;
39
+ }
40
+ exports.default = getDeviceTransactionConfig;
41
+ //# 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,kBAAe,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"}
package/lib/errors.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StellarSourceHasMultiSign = exports.StellarNotEnoughNativeBalanceToAddTrustline = exports.StellarFeeSmallerThanBase = exports.StellarFeeSmallerThanRecommended = exports.StellarNotEnoughNativeBalance = exports.StellarAssetNotFound = exports.StellarAssetNotAccepted = exports.StellarWrongMemoFormat = exports.StellarMemoRecommended = exports.StellarMuxedAccountNotExist = exports.StellarAssetRequired = exports.StellarBurnAddressError = void 0;
4
+ const errors_1 = require("@ledgerhq/errors");
5
+ exports.StellarBurnAddressError = (0, errors_1.createCustomErrorClass)("StellarBurnAddressError");
6
+ exports.StellarAssetRequired = (0, errors_1.createCustomErrorClass)("StellarAssetRequired");
7
+ exports.StellarMuxedAccountNotExist = (0, errors_1.createCustomErrorClass)("StellarMuxedAccountNotExist");
8
+ exports.StellarMemoRecommended = (0, errors_1.createCustomErrorClass)("StellarMemoRecommended");
9
+ exports.StellarWrongMemoFormat = (0, errors_1.createCustomErrorClass)("StellarWrongMemoFormat");
10
+ exports.StellarAssetNotAccepted = (0, errors_1.createCustomErrorClass)("StellarAssetNotAccepted");
11
+ exports.StellarAssetNotFound = (0, errors_1.createCustomErrorClass)("StellarAssetNotFound");
12
+ exports.StellarNotEnoughNativeBalance = (0, errors_1.createCustomErrorClass)("StellarNotEnoughNativeBalance");
13
+ exports.StellarFeeSmallerThanRecommended = (0, errors_1.createCustomErrorClass)("StellarFeeSmallerThanRecommended");
14
+ exports.StellarFeeSmallerThanBase = (0, errors_1.createCustomErrorClass)("StellarFeeSmallerThanBase");
15
+ exports.StellarNotEnoughNativeBalanceToAddTrustline = (0, errors_1.createCustomErrorClass)("StellarNotEnoughNativeBalanceToAddTrustline");
16
+ exports.StellarSourceHasMultiSign = (0, errors_1.createCustomErrorClass)("StellarSourceHasMultiSign");
17
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA,6CAA0D;AAE7C,QAAA,uBAAuB,GAAG,IAAA,+BAAsB,EAAC,yBAAyB,CAAC,CAAC;AAC5E,QAAA,oBAAoB,GAAG,IAAA,+BAAsB,EAAC,sBAAsB,CAAC,CAAC;AACtE,QAAA,2BAA2B,GAAG,IAAA,+BAAsB,EAAC,6BAA6B,CAAC,CAAC;AACpF,QAAA,sBAAsB,GAAG,IAAA,+BAAsB,EAAC,wBAAwB,CAAC,CAAC;AAC1E,QAAA,sBAAsB,GAAG,IAAA,+BAAsB,EAAC,wBAAwB,CAAC,CAAC;AAC1E,QAAA,uBAAuB,GAAG,IAAA,+BAAsB,EAAC,yBAAyB,CAAC,CAAC;AAC5E,QAAA,oBAAoB,GAAG,IAAA,+BAAsB,EAAC,sBAAsB,CAAC,CAAC;AACtE,QAAA,6BAA6B,GAAG,IAAA,+BAAsB,EACjE,+BAA+B,CAChC,CAAC;AACW,QAAA,gCAAgC,GAAG,IAAA,+BAAsB,EACpE,kCAAkC,CACnC,CAAC;AACW,QAAA,yBAAyB,GAAG,IAAA,+BAAsB,EAAC,2BAA2B,CAAC,CAAC;AAChF,QAAA,2CAA2C,GAAG,IAAA,+BAAsB,EAC/E,6CAA6C,CAC9C,CAAC;AACW,QAAA,yBAAyB,GAAG,IAAA,+BAAsB,EAAC,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,32 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.estimateMaxSpendable = void 0;
16
+ const bignumber_js_1 = __importDefault(require("bignumber.js"));
17
+ const account_1 = require("@ledgerhq/coin-framework/account");
18
+ const getTransactionStatus_1 = require("./getTransactionStatus");
19
+ const prepareTransaction_1 = require("./prepareTransaction");
20
+ const createTransaction_1 = require("./createTransaction");
21
+ const notCreatedStellarMockAddress = "GAW46JE3SHIAYLNNNQCAZFQ437WB5ZH7LDRDWR5LVDWHCTHCKYB6RCCH";
22
+ const estimateMaxSpendable = (_a) => __awaiter(void 0, [_a], void 0, function* ({ account, parentAccount, transaction, }) {
23
+ const mainAccount = (0, account_1.getMainAccount)(account, parentAccount);
24
+ const preparedTransaction = yield (0, prepareTransaction_1.prepareTransaction)(mainAccount, Object.assign(Object.assign(Object.assign({}, (0, createTransaction_1.createTransaction)(account)), transaction), { recipient: (transaction === null || transaction === void 0 ? void 0 : transaction.recipient) || notCreatedStellarMockAddress,
25
+ // not used address
26
+ useAllAmount: true }));
27
+ const status = yield (0, getTransactionStatus_1.getTransactionStatus)(mainAccount, preparedTransaction);
28
+ return status.amount.gte(0) ? status.amount : new bignumber_js_1.default(0);
29
+ });
30
+ exports.estimateMaxSpendable = estimateMaxSpendable;
31
+ exports.default = exports.estimateMaxSpendable;
32
+ //# sourceMappingURL=estimateMaxSpendable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"estimateMaxSpendable.js","sourceRoot":"","sources":["../src/estimateMaxSpendable.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,gEAAqC;AAErC,8DAAkE;AAClE,iEAA8D;AAC9D,6DAA0D;AAC1D,2DAAwD;AAGxD,MAAM,4BAA4B,GAAG,0DAA0D,CAAC;AAEzF,MAAM,oBAAoB,GAAuD,KAIrF,EAAE,4CAJ0F,EAC7F,OAAO,EACP,aAAa,EACb,WAAW,GACZ;IACC,MAAM,WAAW,GAAG,IAAA,wBAAc,EAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IAC3D,MAAM,mBAAmB,GAAG,MAAM,IAAA,uCAAkB,EAAC,WAAW,gDAC3D,IAAA,qCAAiB,EAAC,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,IAAA,2CAAoB,EAAC,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,sBAAS,CAAC,CAAC,CAAC,CAAC;AACjE,CAAC,CAAA,CAAC;AAhBW,QAAA,oBAAoB,wBAgB/B;AAEF,kBAAe,4BAAoB,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"}