@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,99 @@
1
+ import { BigNumber } from "bignumber.js";
2
+ import { formatTransactionStatus } from "@ledgerhq/coin-framework/formatters";
3
+ import {
4
+ fromTransactionCommonRaw,
5
+ fromTransactionStatusRawCommon as fromTransactionStatusRaw,
6
+ toTransactionCommonRaw,
7
+ toTransactionStatusRawCommon as toTransactionStatusRaw,
8
+ } from "@ledgerhq/coin-framework/serialization";
9
+ import type { Account } from "@ledgerhq/types-live";
10
+ import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/formatCurrencyUnit";
11
+ import { getAccountCurrency } from "@ledgerhq/coin-framework/account/helpers";
12
+ import { getAssetCodeIssuer } from "./logic";
13
+ import type { Transaction, TransactionRaw } from "./types";
14
+
15
+ export function formatTransaction(
16
+ { amount, recipient, fees, memoValue, useAllAmount, subAccountId }: Transaction,
17
+ mainAccount: Account,
18
+ ): string {
19
+ const account =
20
+ (subAccountId && (mainAccount.subAccounts || []).find(a => a.id === subAccountId)) ||
21
+ mainAccount;
22
+
23
+ return `
24
+ SEND ${
25
+ useAllAmount
26
+ ? "MAX"
27
+ : formatCurrencyUnit(getAccountCurrency(account).units[0], amount, {
28
+ showCode: true,
29
+ disableRounding: true,
30
+ })
31
+ }
32
+ TO ${recipient}
33
+ with fees=${
34
+ !fees
35
+ ? "?"
36
+ : formatCurrencyUnit(getAccountCurrency(account).units[0], fees, {
37
+ showCode: true,
38
+ disableRounding: true,
39
+ })
40
+ }${memoValue ? "\n memo=" + memoValue : ""}`;
41
+ }
42
+
43
+ function fromTransactionRaw(tr: TransactionRaw): Transaction {
44
+ const common = fromTransactionCommonRaw(tr);
45
+ const { networkInfo } = tr;
46
+ const [assetCode, assetIssuer] = getAssetCodeIssuer(tr);
47
+
48
+ return {
49
+ ...common,
50
+ family: tr.family,
51
+ fees: tr.fees ? new BigNumber(tr.fees) : null,
52
+ baseReserve: tr.baseReserve ? new BigNumber(tr.baseReserve) : null,
53
+ memoValue: tr.memoValue ? tr.memoValue : null,
54
+ memoType: tr.memoType ? tr.memoType : null,
55
+ networkInfo: networkInfo && {
56
+ family: networkInfo.family,
57
+ fees: new BigNumber(networkInfo.fees),
58
+ baseFee: new BigNumber(networkInfo.baseFee),
59
+ baseReserve: new BigNumber(networkInfo.baseReserve),
60
+ networkCongestionLevel: networkInfo.networkCongestionLevel,
61
+ },
62
+ mode: tr.mode,
63
+ assetCode,
64
+ assetIssuer,
65
+ };
66
+ }
67
+
68
+ function toTransactionRaw(transaction: Transaction): TransactionRaw {
69
+ const common = toTransactionCommonRaw(transaction);
70
+ const { networkInfo } = transaction;
71
+ const [assetCode, assetIssuer] = getAssetCodeIssuer(transaction);
72
+ return {
73
+ ...common,
74
+ family: transaction.family,
75
+ fees: transaction.fees ? transaction.fees.toString() : null,
76
+ baseReserve: transaction.baseReserve ? transaction.baseReserve.toString() : null,
77
+ memoValue: transaction.memoValue ? transaction.memoValue.toString() : null,
78
+ memoType: transaction.memoType ? transaction.memoType.toString() : null,
79
+ networkInfo: networkInfo && {
80
+ family: networkInfo.family,
81
+ fees: networkInfo.fees.toString(),
82
+ baseFee: networkInfo.baseFee.toString(),
83
+ baseReserve: networkInfo.baseReserve.toString(),
84
+ networkCongestionLevel: networkInfo.networkCongestionLevel,
85
+ },
86
+ mode: transaction.mode,
87
+ assetCode,
88
+ assetIssuer,
89
+ };
90
+ }
91
+
92
+ export default {
93
+ formatTransaction,
94
+ fromTransactionRaw,
95
+ toTransactionRaw,
96
+ fromTransactionStatusRaw,
97
+ toTransactionStatusRaw,
98
+ formatTransactionStatus,
99
+ };
@@ -0,0 +1,112 @@
1
+ import { Horizon } from "@stellar/stellar-sdk";
2
+ import type { BigNumber } from "bignumber.js";
3
+ import type {
4
+ Account,
5
+ Operation,
6
+ OperationType,
7
+ TransactionCommon,
8
+ TransactionCommonRaw,
9
+ TransactionStatusCommon,
10
+ TransactionStatusCommonRaw,
11
+ } from "@ledgerhq/types-live";
12
+
13
+ export type NetworkInfo = {
14
+ family: "stellar";
15
+ fees: BigNumber;
16
+ baseFee: BigNumber;
17
+ baseReserve: BigNumber;
18
+ networkCongestionLevel?: NetworkCongestionLevel | undefined;
19
+ };
20
+
21
+ export type NetworkInfoRaw = {
22
+ family: "stellar";
23
+ fees: string;
24
+ baseFee: string;
25
+ baseReserve: string;
26
+ networkCongestionLevel?: NetworkCongestionLevel | undefined;
27
+ };
28
+
29
+ export enum NetworkCongestionLevel {
30
+ LOW = "LOW",
31
+ MEDIUM = "MEDIUM",
32
+ HIGH = "HIGH",
33
+ }
34
+
35
+ export const StellarMemoType = ["NO_MEMO", "MEMO_TEXT", "MEMO_ID", "MEMO_HASH", "MEMO_RETURN"];
36
+
37
+ export type StellarTransactionMode = "send" | "changeTrust";
38
+
39
+ export type Transaction = TransactionCommon & {
40
+ family: "stellar";
41
+ networkInfo?: NetworkInfo | null | undefined;
42
+ fees?: BigNumber | null;
43
+ baseReserve?: BigNumber | null;
44
+ memoType?: string | null;
45
+ memoValue?: string | null;
46
+ mode: StellarTransactionMode;
47
+ assetCode?: string;
48
+ assetIssuer?: string;
49
+ };
50
+
51
+ export type TransactionRaw = TransactionCommonRaw & {
52
+ family: "stellar";
53
+ networkInfo?: NetworkInfoRaw | null | undefined;
54
+ fees?: string | null;
55
+ baseReserve?: string | null;
56
+ memoType?: string | null;
57
+ memoValue?: string | null;
58
+ mode: StellarTransactionMode;
59
+ assetCode?: string;
60
+ assetIssuer?: string;
61
+ };
62
+
63
+ export type BalanceAsset = {
64
+ balance: string;
65
+ limit: string;
66
+ buying_liabilities: string;
67
+ selling_liabilities: string;
68
+ last_modified_ledger: number;
69
+ is_authorized: boolean;
70
+ is_authorized_to_maintain_liabilities: boolean;
71
+ asset_type: string;
72
+ asset_code: string;
73
+ asset_issuer: string;
74
+ liquidity_pool_id?: string;
75
+ };
76
+
77
+ export type RawOperation = Horizon.ServerApi.OperationRecord & {
78
+ asset_code?: string;
79
+ asset_issuer?: string;
80
+ from?: string;
81
+ to?: string;
82
+ to_muxed?: string;
83
+ funder?: string;
84
+ trustor?: string;
85
+ account?: string;
86
+ transaction_successful: boolean;
87
+ };
88
+
89
+ export type Signer = {
90
+ weight: number;
91
+ key: string;
92
+ type: string;
93
+ };
94
+
95
+ export type TransactionStatus = TransactionStatusCommon;
96
+
97
+ export type TransactionStatusRaw = TransactionStatusCommonRaw;
98
+
99
+ export type StellarOperation = Operation<StellarOperationExtra>;
100
+
101
+ export type StellarOperationExtra = {
102
+ pagingToken?: string;
103
+ assetCode?: string;
104
+ assetIssuer?: string;
105
+ assetAmount?: string | undefined;
106
+ ledgerOpType: OperationType;
107
+ memo?: string;
108
+ };
109
+
110
+ export type StellarAccount = Account;
111
+
112
+ export * from "./signer";
@@ -0,0 +1,9 @@
1
+ export interface StellarSigner {
2
+ getPublicKey(path: string, display?: boolean): Promise<{ rawPublicKey: Buffer }>;
3
+ signTransaction(
4
+ path: string,
5
+ transaction: Buffer,
6
+ ): Promise<{
7
+ signature: Buffer;
8
+ }>;
9
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "../../../tsconfig.base",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "declarationMap": true,
6
+ "module": "commonjs",
7
+ "downlevelIteration": true,
8
+ "lib": ["es2020", "dom"],
9
+ "outDir": "lib",
10
+ "exactOptionalPropertyTypes": true
11
+ },
12
+ "include": ["src/**/*"]
13
+ }