@ledgerhq/coin-canton 0.4.0-nightly.2 → 0.4.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 (154) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +21 -26
  3. package/jest.config.js +0 -1
  4. package/lib/api/lastBlock.integ.test.js +1 -3
  5. package/lib/api/lastBlock.integ.test.js.map +1 -1
  6. package/lib/bridge/signOperation.js +1 -1
  7. package/lib/bridge/signOperation.js.map +1 -1
  8. package/lib/common-logic/account/getBalance.d.ts +1 -1
  9. package/lib/common-logic/account/getBalance.d.ts.map +1 -1
  10. package/lib/common-logic/account/getBalance.js +5 -21
  11. package/lib/common-logic/account/getBalance.js.map +1 -1
  12. package/lib/common-logic/history/lastBlock.d.ts.map +1 -1
  13. package/lib/common-logic/history/lastBlock.js +1 -7
  14. package/lib/common-logic/history/lastBlock.js.map +1 -1
  15. package/lib/common-logic/history/listOperations.d.ts +4 -3
  16. package/lib/common-logic/history/listOperations.d.ts.map +1 -1
  17. package/lib/common-logic/history/listOperations.js +41 -43
  18. package/lib/common-logic/history/listOperations.js.map +1 -1
  19. package/lib/common-logic/transaction/broadcast.d.ts.map +1 -1
  20. package/lib/common-logic/transaction/broadcast.js +3 -11
  21. package/lib/common-logic/transaction/broadcast.js.map +1 -1
  22. package/lib/common-logic/transaction/combine.d.ts +1 -1
  23. package/lib/common-logic/transaction/combine.d.ts.map +1 -1
  24. package/lib/common-logic/transaction/combine.js +3 -6
  25. package/lib/common-logic/transaction/combine.js.map +1 -1
  26. package/lib/common-logic/transaction/estimateFees.d.ts.map +1 -1
  27. package/lib/common-logic/transaction/estimateFees.js +15 -2
  28. package/lib/common-logic/transaction/estimateFees.js.map +1 -1
  29. package/lib/common-logic/utils.d.ts +1 -0
  30. package/lib/common-logic/utils.d.ts.map +1 -1
  31. package/lib/common-logic/utils.js +6 -1
  32. package/lib/common-logic/utils.js.map +1 -1
  33. package/lib/config.d.ts +3 -6
  34. package/lib/config.d.ts.map +1 -1
  35. package/lib/config.js.map +1 -1
  36. package/lib/network/gateway.d.ts +21 -31
  37. package/lib/network/gateway.d.ts.map +1 -1
  38. package/lib/network/gateway.integ.test.js +2 -29
  39. package/lib/network/gateway.integ.test.js.map +1 -1
  40. package/lib/network/gateway.js +9 -33
  41. package/lib/network/gateway.js.map +1 -1
  42. package/lib/network/node.integ.test.js +2 -4
  43. package/lib/network/node.integ.test.js.map +1 -1
  44. package/lib/types/bridge.d.ts.map +1 -1
  45. package/lib-es/api/lastBlock.integ.test.js +1 -3
  46. package/lib-es/api/lastBlock.integ.test.js.map +1 -1
  47. package/lib-es/bridge/signOperation.js +1 -1
  48. package/lib-es/bridge/signOperation.js.map +1 -1
  49. package/lib-es/common-logic/account/getBalance.d.ts +1 -1
  50. package/lib-es/common-logic/account/getBalance.d.ts.map +1 -1
  51. package/lib-es/common-logic/account/getBalance.js +5 -18
  52. package/lib-es/common-logic/account/getBalance.js.map +1 -1
  53. package/lib-es/common-logic/history/lastBlock.d.ts.map +1 -1
  54. package/lib-es/common-logic/history/lastBlock.js +2 -5
  55. package/lib-es/common-logic/history/lastBlock.js.map +1 -1
  56. package/lib-es/common-logic/history/listOperations.d.ts +4 -3
  57. package/lib-es/common-logic/history/listOperations.d.ts.map +1 -1
  58. package/lib-es/common-logic/history/listOperations.js +41 -40
  59. package/lib-es/common-logic/history/listOperations.js.map +1 -1
  60. package/lib-es/common-logic/transaction/broadcast.d.ts.map +1 -1
  61. package/lib-es/common-logic/transaction/broadcast.js +3 -8
  62. package/lib-es/common-logic/transaction/broadcast.js.map +1 -1
  63. package/lib-es/common-logic/transaction/combine.d.ts +1 -1
  64. package/lib-es/common-logic/transaction/combine.d.ts.map +1 -1
  65. package/lib-es/common-logic/transaction/combine.js +3 -6
  66. package/lib-es/common-logic/transaction/combine.js.map +1 -1
  67. package/lib-es/common-logic/transaction/estimateFees.d.ts.map +1 -1
  68. package/lib-es/common-logic/transaction/estimateFees.js +15 -2
  69. package/lib-es/common-logic/transaction/estimateFees.js.map +1 -1
  70. package/lib-es/common-logic/utils.d.ts +1 -0
  71. package/lib-es/common-logic/utils.d.ts.map +1 -1
  72. package/lib-es/common-logic/utils.js +4 -0
  73. package/lib-es/common-logic/utils.js.map +1 -1
  74. package/lib-es/config.d.ts +3 -6
  75. package/lib-es/config.d.ts.map +1 -1
  76. package/lib-es/config.js.map +1 -1
  77. package/lib-es/network/gateway.d.ts +21 -31
  78. package/lib-es/network/gateway.d.ts.map +1 -1
  79. package/lib-es/network/gateway.integ.test.js +3 -30
  80. package/lib-es/network/gateway.integ.test.js.map +1 -1
  81. package/lib-es/network/gateway.js +8 -30
  82. package/lib-es/network/gateway.js.map +1 -1
  83. package/lib-es/network/node.integ.test.js +2 -4
  84. package/lib-es/network/node.integ.test.js.map +1 -1
  85. package/lib-es/types/bridge.d.ts.map +1 -1
  86. package/package.json +9 -9
  87. package/src/api/lastBlock.integ.test.ts +1 -3
  88. package/src/bridge/signOperation.ts +1 -1
  89. package/src/common-logic/account/getBalance.ts +5 -20
  90. package/src/common-logic/history/lastBlock.ts +2 -6
  91. package/src/common-logic/history/listOperations.ts +52 -43
  92. package/src/common-logic/transaction/broadcast.ts +3 -7
  93. package/src/common-logic/transaction/combine.ts +4 -7
  94. package/src/common-logic/transaction/estimateFees.ts +14 -2
  95. package/src/common-logic/utils.ts +5 -0
  96. package/src/config.ts +2 -8
  97. package/src/network/gateway.integ.test.ts +3 -49
  98. package/src/network/gateway.ts +27 -67
  99. package/src/network/node.integ.test.ts +2 -4
  100. package/src/types/bridge.ts +1 -0
  101. package/lib/api/getBalance.integ.test.d.ts +0 -2
  102. package/lib/api/getBalance.integ.test.d.ts.map +0 -1
  103. package/lib/api/getBalance.integ.test.js +0 -24
  104. package/lib/api/getBalance.integ.test.js.map +0 -1
  105. package/lib/api/listOperations.integ.test.d.ts +0 -2
  106. package/lib/api/listOperations.integ.test.d.ts.map +0 -1
  107. package/lib/api/listOperations.integ.test.js +0 -23
  108. package/lib/api/listOperations.integ.test.js.map +0 -1
  109. package/lib/common-logic/account/getBalance.unit.test.d.ts +0 -2
  110. package/lib/common-logic/account/getBalance.unit.test.d.ts.map +0 -1
  111. package/lib/common-logic/account/getBalance.unit.test.js +0 -88
  112. package/lib/common-logic/account/getBalance.unit.test.js.map +0 -1
  113. package/lib/common-logic/history/lastBlock.test.d.ts +0 -2
  114. package/lib/common-logic/history/lastBlock.test.d.ts.map +0 -1
  115. package/lib/common-logic/history/lastBlock.test.js +0 -43
  116. package/lib/common-logic/history/lastBlock.test.js.map +0 -1
  117. package/lib/common-logic/transaction/broadcast.test.d.ts +0 -2
  118. package/lib/common-logic/transaction/broadcast.test.d.ts.map +0 -1
  119. package/lib/common-logic/transaction/broadcast.test.js +0 -68
  120. package/lib/common-logic/transaction/broadcast.test.js.map +0 -1
  121. package/lib/common-logic/transaction/combine.test.d.ts +0 -2
  122. package/lib/common-logic/transaction/combine.test.d.ts.map +0 -1
  123. package/lib/common-logic/transaction/combine.test.js +0 -28
  124. package/lib/common-logic/transaction/combine.test.js.map +0 -1
  125. package/lib-es/api/getBalance.integ.test.d.ts +0 -2
  126. package/lib-es/api/getBalance.integ.test.d.ts.map +0 -1
  127. package/lib-es/api/getBalance.integ.test.js +0 -22
  128. package/lib-es/api/getBalance.integ.test.js.map +0 -1
  129. package/lib-es/api/listOperations.integ.test.d.ts +0 -2
  130. package/lib-es/api/listOperations.integ.test.d.ts.map +0 -1
  131. package/lib-es/api/listOperations.integ.test.js +0 -21
  132. package/lib-es/api/listOperations.integ.test.js.map +0 -1
  133. package/lib-es/common-logic/account/getBalance.unit.test.d.ts +0 -2
  134. package/lib-es/common-logic/account/getBalance.unit.test.d.ts.map +0 -1
  135. package/lib-es/common-logic/account/getBalance.unit.test.js +0 -53
  136. package/lib-es/common-logic/account/getBalance.unit.test.js.map +0 -1
  137. package/lib-es/common-logic/history/lastBlock.test.d.ts +0 -2
  138. package/lib-es/common-logic/history/lastBlock.test.d.ts.map +0 -1
  139. package/lib-es/common-logic/history/lastBlock.test.js +0 -38
  140. package/lib-es/common-logic/history/lastBlock.test.js.map +0 -1
  141. package/lib-es/common-logic/transaction/broadcast.test.d.ts +0 -2
  142. package/lib-es/common-logic/transaction/broadcast.test.d.ts.map +0 -1
  143. package/lib-es/common-logic/transaction/broadcast.test.js +0 -33
  144. package/lib-es/common-logic/transaction/broadcast.test.js.map +0 -1
  145. package/lib-es/common-logic/transaction/combine.test.d.ts +0 -2
  146. package/lib-es/common-logic/transaction/combine.test.d.ts.map +0 -1
  147. package/lib-es/common-logic/transaction/combine.test.js +0 -26
  148. package/lib-es/common-logic/transaction/combine.test.js.map +0 -1
  149. package/src/api/getBalance.integ.test.ts +0 -28
  150. package/src/api/listOperations.integ.test.ts +0 -27
  151. package/src/common-logic/account/getBalance.unit.test.ts +0 -63
  152. package/src/common-logic/history/lastBlock.test.ts +0 -47
  153. package/src/common-logic/transaction/broadcast.test.ts +0 -42
  154. package/src/common-logic/transaction/combine.test.ts +0 -28
@@ -1,10 +1,6 @@
1
- import coinConfig from "../../config";
2
- import { submit } from "../../network/gateway";
3
-
4
- const useGateway = () => coinConfig.getCoinConfig().useGateway === true;
1
+ import { submit } from "../../network/node";
5
2
 
6
3
  export async function broadcast(signedTx: string): Promise<string> {
7
- const parsed: { serialized: string; signature: string } = JSON.parse(signedTx);
8
- if (useGateway()) return (await submit(parsed.serialized, parsed.signature)).updateId;
9
- else throw new Error("Not implemented");
4
+ const submittedPayment = await submit(signedTx);
5
+ return submittedPayment.tx_hash;
10
6
  }
@@ -1,9 +1,6 @@
1
- // Combines signature with raw transaction
2
- export function combine(transaction: string, signature: string): string {
3
- const tx = JSON.parse(transaction);
1
+ import { encode } from "../utils";
4
2
 
5
- return JSON.stringify({
6
- ...tx,
7
- signature,
8
- });
3
+ // Combines signature with raw transaction
4
+ export function combine(transaction: string, signature: string, publicKey?: string): string {
5
+ return encode(transaction, signature, publicKey || "");
9
6
  }
@@ -1,4 +1,16 @@
1
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1
+ import { simulate } from "../../network/node";
2
+ import { SimulationError } from "../../types/errors";
3
+
2
4
  export async function estimateFees(serializedTransaction: string): Promise<bigint> {
3
- return Promise.resolve(BigInt(10_000)); // TODO replace with real implementation
5
+ try {
6
+ // We call the node to do a dry run and estimate fees
7
+ return BigInt(await simulate(serializedTransaction));
8
+ } catch (e) {
9
+ // default value is required in case of simulation error, else user will encounter an error in the flow
10
+ if (e instanceof SimulationError) {
11
+ return BigInt(1000);
12
+ } else {
13
+ throw new Error("Unexpected error while estimating fees.");
14
+ }
15
+ }
4
16
  }
@@ -11,3 +11,8 @@ export const validateTag = (tag: BigNumber) => {
11
11
  export function isRecipientValid(recipient: string): boolean {
12
12
  return recipient.length > 0;
13
13
  }
14
+
15
+ export const encode = (transaction: string, signature: string, publicKey?: string) => {
16
+ // sample encoding
17
+ return `${transaction}${publicKey}${signature}encodedTx`;
18
+ };
package/src/config.ts CHANGED
@@ -1,22 +1,16 @@
1
- import buildCoinConfig, { CoinConfig, type CurrencyConfig } from "@ledgerhq/coin-framework/config";
2
- import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
1
+ import buildCoinConfig, { type CurrencyConfig } from "@ledgerhq/coin-framework/config";
3
2
 
4
3
  export type CantonConfig = {
5
4
  nodeUrl?: string;
6
- nodeId?: string;
7
5
  gatewayUrl?: string;
8
6
  // TODELETE
9
7
  minReserve?: number;
10
8
  networkType: "mainnet" | "devnet" | "localnet";
11
9
  useGateway?: boolean;
12
- nativeInstrumentId?: string;
13
10
  };
14
11
 
15
12
  export type CantonCoinConfig = CurrencyConfig & CantonConfig;
16
13
 
17
- const coinConfig: {
18
- setCoinConfig: (config: CoinConfig<CantonCoinConfig>) => void;
19
- getCoinConfig: (currency?: CryptoCurrency) => CantonCoinConfig;
20
- } = buildCoinConfig<CantonCoinConfig>();
14
+ const coinConfig = buildCoinConfig<CantonCoinConfig>();
21
15
 
22
16
  export default coinConfig;
@@ -1,78 +1,32 @@
1
1
  import coinConfig from "../config";
2
- import {
3
- getLedgerEnd,
4
- prepareOnboarding,
5
- getBalance,
6
- getTransactions,
7
- getPartyById,
8
- getPartyByPubKey,
9
- } from "./gateway";
2
+ import { getLedgerEnd, prepareOnboarding } from "./gateway";
10
3
 
11
4
  describe("gateway (devnet)", () => {
12
5
  beforeAll(() => {
13
6
  coinConfig.setCoinConfig(() => ({
14
7
  gatewayUrl: "https://canton-gateway.api.live.ledger-test.com",
15
- useGateway: true,
16
8
  networkType: "devnet",
17
9
  status: {
18
10
  type: "active",
19
11
  },
20
12
  }));
21
13
  });
22
-
23
14
  describe("prepareOnboarding", () => {
24
15
  it("should prepare onboarding", async () => {
25
16
  const response = await prepareOnboarding(
26
- "c59f7f29374d24506dd6490a5db472cf00958e195e146f3dc9c97f96d5c51097",
17
+ "0x043b462de34ec31fba274f2a381947aef26697912194312fc289c46cc1b2b4f6b00828dc1e4f96001b10463083edf85f2e0550862a3dc99ed411ca6d25f2bc19a8",
27
18
  "ed25519",
28
19
  );
29
20
  expect(response).toHaveProperty("party_id");
30
21
  expect(response).toHaveProperty("party_name");
31
22
  expect(response).toHaveProperty("public_key_fingerprint");
32
23
  expect(response).toHaveProperty("topology_transactions_hash");
33
- }, 30000);
24
+ });
34
25
  });
35
-
36
26
  describe("getLedgerEnd", () => {
37
27
  it("should return ledger end", async () => {
38
28
  const end = await getLedgerEnd();
39
29
  expect(end).toBeGreaterThanOrEqual(0);
40
30
  });
41
31
  });
42
-
43
- describe("getBalance", () => {
44
- it("should return user balance", async () => {
45
- const balance = await getBalance(
46
- "party-4f2e1485107adf5f::122027c6dbbbdbffe0fa3122ae05175f3b9328e879e9ce96b670354deb64a45683c1",
47
- );
48
- expect(balance.length).toBeGreaterThanOrEqual(1);
49
- expect(balance[0].amount).toBeGreaterThanOrEqual(0);
50
- expect(balance[0].instrument_id.includes("Splice")).toBe(true);
51
- });
52
- });
53
-
54
- describe("getPartyById", () => {
55
- it.skip("should return party info", async () => {
56
- const party = await getPartyById("4f2e1485107adf5f");
57
- expect(party).toBeDefined();
58
- });
59
- });
60
-
61
- describe("getPartyByPubKey", () => {
62
- it.skip("should return party info", async () => {
63
- const party = await getPartyByPubKey(
64
- "122027c6dbbbdbffe0fa3122ae05175f3b9328e879e9ce96b670354deb64a45683c1",
65
- );
66
- expect(party).toBeDefined();
67
- });
68
- });
69
-
70
- describe("getTransactions", () => {
71
- it("should return user transactions", async () => {
72
- const { transactions } = await getTransactions(
73
- "party-5f29bb32e9939939::12202becd8062a1d170209956cfd977fca76fcb4d2a892d08c77a7483f35a11d6440",
74
- );
75
- expect(transactions.length).toBeGreaterThanOrEqual(0);
76
- });
77
- });
78
32
  });
@@ -26,15 +26,8 @@ type OnboardingSubmitResponse = {
26
26
  };
27
27
  };
28
28
 
29
- type TransactionSubmitRequest = {
30
- serialized: string;
31
- signature: string;
32
- };
33
-
34
- type TransactionSubmitResponse = { updateId: string };
35
-
36
- export type InstrumentBalance = {
37
- instrument_id: string;
29
+ type InstrumentBalance = {
30
+ instrumentId: string;
38
31
  amount: number;
39
32
  locked: boolean;
40
33
  };
@@ -51,47 +44,46 @@ type Timestamp = {
51
44
 
52
45
  type BaseEvent = {
53
46
  type: string;
54
- contract_id: string;
47
+ contractId: string;
55
48
  details: string;
56
49
  };
57
50
 
58
- export type CreatedEvent = BaseEvent & {
59
- template_id: {
60
- package_id: string;
61
- module_name: string;
62
- entity_name: string;
51
+ type CreatedEvent = BaseEvent & {
52
+ templateId: {
53
+ packageId: string;
54
+ moduleName: string;
55
+ entityName: string;
63
56
  };
64
57
  signatories: string[];
65
58
  observers: string[];
66
59
  };
67
60
 
68
61
  type ExercisedEvent = BaseEvent & {
69
- template_id: {
62
+ templateId: {
70
63
  packageId: string;
71
64
  moduleName: string;
72
65
  entityName: string;
73
66
  };
74
67
  choice: string;
75
68
  consuming: boolean;
76
- acting_parties: string[];
69
+ actingParties: string[];
77
70
  };
78
71
 
79
72
  type Event = BaseEvent | CreatedEvent | ExercisedEvent;
80
73
 
81
- export type TxInfo = {
82
- update_id: string;
83
- command_id: string;
84
- workflow_id: string;
85
- effective_at: Timestamp;
74
+ type TxInfo = {
75
+ updateId: string;
76
+ commandId: string;
77
+ workflowId: string;
78
+ effectiveAt: Timestamp;
86
79
  offset: number;
87
- synchronizer_id: string;
88
- record_time: Timestamp;
89
- events: Record<string, Event>[];
90
- trace_context: string;
80
+ synchronizerId: string;
81
+ recordTime: Timestamp;
82
+ events: Event[];
83
+ traceContext: string;
91
84
  };
92
85
 
93
86
  const getGatewayUrl = () => coinConfig.getCoinConfig().gatewayUrl;
94
- const getNodeId = () => coinConfig.getCoinConfig().nodeId || "ledger-live-devnet-prd";
95
87
 
96
88
  export async function prepareOnboarding(
97
89
  pubKey: string,
@@ -99,7 +91,7 @@ export async function prepareOnboarding(
99
91
  ): Promise<OnboardingPrepareResponse> {
100
92
  const { data } = await network<OnboardingPrepareResponse>({
101
93
  method: "POST",
102
- url: `${getGatewayUrl()}/v1/node/${getNodeId()}/onboarding/prepare`,
94
+ url: `${getGatewayUrl()}/v1/node/0/onboarding/prepare`,
103
95
  data: {
104
96
  public_key: pubKey,
105
97
  public_key_type: pubKeyType,
@@ -115,7 +107,7 @@ export async function submitOnboarding(
115
107
  ) {
116
108
  const { data } = await network<OnboardingSubmitResponse>({
117
109
  method: "POST",
118
- url: `${getGatewayUrl()}/v1/node/${getNodeId()}/onboarding/submit`,
110
+ url: `${getGatewayUrl()}/v1/node/0/onboarding/submit`,
119
111
  data: {
120
112
  prepare_request: prepareRequest,
121
113
  prepare_response: prepareResponse,
@@ -125,54 +117,23 @@ export async function submitOnboarding(
125
117
  return data;
126
118
  }
127
119
 
128
- export async function submit(serializedTx: string, signature: string) {
129
- const { data } = await network<TransactionSubmitResponse>({
130
- method: "POST",
131
- url: `${getGatewayUrl()}/v1/node/${getNodeId()}/transaction/submit`,
132
- data: {
133
- serialized: serializedTx,
134
- signature,
135
- } satisfies TransactionSubmitRequest,
136
- });
137
- return data;
138
- }
139
-
140
120
  export async function getBalance(partyId: string): Promise<InstrumentBalance[]> {
141
121
  const { data } = await network<InstrumentBalance[]>({
142
122
  method: "GET",
143
- url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/balance`,
123
+ url: `${getGatewayUrl()}/v1/node/0/party/${partyId}/balance`,
144
124
  });
145
125
  return data;
146
126
  }
147
127
 
148
- export async function getPartyById(partyId: string): Promise<PartyInfo> {
149
- return await getParty(partyId, "ID");
150
- }
151
-
152
- export async function getPartyByPubKey(pubKey: string): Promise<PartyInfo> {
153
- return await getParty(pubKey, "PK");
154
- }
155
-
156
- async function getParty(identifier: string, by: "ID" | "PK"): Promise<PartyInfo> {
128
+ export async function getParty(partyId: string): Promise<PartyInfo> {
157
129
  const { data } = await network<PartyInfo>({
158
130
  method: "GET",
159
- url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${identifier}`,
160
- data: {
161
- by,
162
- },
131
+ url: `${getGatewayUrl()}/v1/node/0/party/${partyId}`,
163
132
  });
164
133
  return data;
165
134
  }
166
135
 
167
- export async function getTransactions(
168
- partyId: string,
169
- options?: {
170
- cursor?: number | undefined;
171
- minOffset?: number | undefined;
172
- maxOffset?: number | undefined;
173
- limit?: number | undefined;
174
- },
175
- ): Promise<{
136
+ export async function getTransactions(partyId: string): Promise<{
176
137
  next: number;
177
138
  transactions: TxInfo[];
178
139
  }> {
@@ -181,8 +142,7 @@ export async function getTransactions(
181
142
  transactions: TxInfo[];
182
143
  }>({
183
144
  method: "GET",
184
- url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transactions`,
185
- data: options,
145
+ url: `${getGatewayUrl()}/v1/node/0/party/${partyId}/transactions`,
186
146
  });
187
147
  return data;
188
148
  }
@@ -190,7 +150,7 @@ export async function getTransactions(
190
150
  export async function getLedgerEnd(): Promise<number> {
191
151
  const { data } = await network<number>({
192
152
  method: "GET",
193
- url: `${getGatewayUrl()}/v1/node/${getNodeId()}/ledger-end`,
153
+ url: `${getGatewayUrl()}/v1/node/0/ledger-end`,
194
154
  });
195
155
  return data;
196
156
  }
@@ -1,8 +1,7 @@
1
1
  import coinConfig from "../config";
2
2
  import { getLedgerEnd } from "./node";
3
3
 
4
- // enable manually, as it requires a running node locally
5
- describe.skip("Node (localnet)", () => {
4
+ describe("Node (localnet)", () => {
6
5
  beforeAll(() => {
7
6
  coinConfig.setCoinConfig(() => ({
8
7
  gatewayUrl: "http://gateway.url",
@@ -20,8 +19,7 @@ describe.skip("Node (localnet)", () => {
20
19
  });
21
20
  });
22
21
 
23
- // enable manually, as it requires an auth token in env variable
24
- describe.skip("Node (devnet)", () => {
22
+ describe("Node (devnet)", () => {
25
23
  beforeAll(() => {
26
24
  coinConfig.setCoinConfig(() => ({
27
25
  nodeUrl: "https://wallet-validator-devnet-canton.ledger-test.com/v2",
@@ -1,4 +1,5 @@
1
1
  import type { BigNumber } from "bignumber.js";
2
+ import type { Unit } from "@ledgerhq/types-cryptoassets";
2
3
  import type {
3
4
  TransactionCommon,
4
5
  TransactionCommonRaw,
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=getBalance.integ.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getBalance.integ.test.d.ts","sourceRoot":"","sources":["../../src/api/getBalance.integ.test.ts"],"names":[],"mappings":""}
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const _1 = require(".");
4
- let api;
5
- describe("devnet", () => {
6
- beforeAll(() => {
7
- api = (0, _1.createApi)({
8
- nodeUrl: "https://wallet-validator-devnet-canton.ledger-test.com/v2",
9
- networkType: "devnet",
10
- gatewayUrl: "https://canton-gateway.api.live.ledger-test.com",
11
- useGateway: true,
12
- nativeInstrumentId: "6e9fc50fb94e56751b49f09ba2dc84da53a9d7cff08115ebb4f6b7a12d0c990c:Splice.Amulet:Amulet",
13
- });
14
- });
15
- describe("getBalance", () => {
16
- it("should return user balance", async () => {
17
- const balance = await api.getBalance("party-4f2e1485107adf5f::122027c6dbbbdbffe0fa3122ae05175f3b9328e879e9ce96b670354deb64a45683c1");
18
- expect(balance.length).toBeGreaterThanOrEqual(1);
19
- const nativeBalance = balance.find(b => b.asset.type === "native");
20
- expect(nativeBalance?.value).toBeGreaterThanOrEqual(0);
21
- });
22
- });
23
- });
24
- //# sourceMappingURL=getBalance.integ.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getBalance.integ.test.js","sourceRoot":"","sources":["../../src/api/getBalance.integ.test.ts"],"names":[],"mappings":";;AACA,wBAA8B;AAE9B,IAAI,GAAc,CAAC;AAEnB,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;IACtB,SAAS,CAAC,GAAG,EAAE;QACb,GAAG,GAAG,IAAA,YAAS,EAAC;YACd,OAAO,EAAE,2DAA2D;YACpE,WAAW,EAAE,QAAQ;YACrB,UAAU,EAAE,iDAAiD;YAC7D,UAAU,EAAE,IAAI;YAChB,kBAAkB,EAChB,uFAAuF;SAC1F,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;QAC1B,EAAE,CAAC,4BAA4B,EAAE,KAAK,IAAI,EAAE;YAC1C,MAAM,OAAO,GAAG,MAAM,GAAG,CAAC,UAAU,CAClC,8FAA8F,CAC/F,CAAC;YACF,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC;YACjD,MAAM,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC;YACnE,MAAM,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC;QACzD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=listOperations.integ.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"listOperations.integ.test.d.ts","sourceRoot":"","sources":["../../src/api/listOperations.integ.test.ts"],"names":[],"mappings":""}
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const _1 = require(".");
4
- let api;
5
- describe("devnet", () => {
6
- beforeAll(() => {
7
- api = (0, _1.createApi)({
8
- nodeUrl: "https://wallet-validator-devnet-canton.ledger-test.com/v2",
9
- networkType: "devnet",
10
- gatewayUrl: "https://canton-gateway.api.live.ledger-test.com",
11
- useGateway: true,
12
- });
13
- });
14
- describe("listOperations", () => {
15
- it("should return ops", async () => {
16
- const ops = await api.listOperations("party-4f2e1485107adf5f::122027c6dbbbdbffe0fa3122ae05175f3b9328e879e9ce96b670354deb64a45683c1", {
17
- minHeight: 0,
18
- });
19
- expect(ops.length).toBeGreaterThan(0);
20
- });
21
- });
22
- });
23
- //# sourceMappingURL=listOperations.integ.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"listOperations.integ.test.js","sourceRoot":"","sources":["../../src/api/listOperations.integ.test.ts"],"names":[],"mappings":";;AACA,wBAA8B;AAE9B,IAAI,GAAc,CAAC;AAEnB,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;IACtB,SAAS,CAAC,GAAG,EAAE;QACb,GAAG,GAAG,IAAA,YAAS,EAAC;YACd,OAAO,EAAE,2DAA2D;YACpE,WAAW,EAAE,QAAQ;YACrB,UAAU,EAAE,iDAAiD;YAC7D,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;QAC9B,EAAE,CAAC,mBAAmB,EAAE,KAAK,IAAI,EAAE;YACjC,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,cAAc,CAClC,8FAA8F,EAC9F;gBACE,SAAS,EAAE,CAAC;aACb,CACF,CAAC;YACF,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=getBalance.unit.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getBalance.unit.test.d.ts","sourceRoot":"","sources":["../../../src/common-logic/account/getBalance.unit.test.ts"],"names":[],"mappings":""}
@@ -1,88 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- const gateway_1 = require("../../network/gateway");
37
- const coinConfigModule = __importStar(require("../../config"));
38
- const getBalance_1 = require("./getBalance");
39
- jest.mock("../../network/gateway", () => ({
40
- getBalance: jest.fn(),
41
- }));
42
- describe("getBalance", () => {
43
- const mockGetCoinConfig = jest.spyOn(coinConfigModule.default, "getCoinConfig");
44
- afterEach(() => {
45
- jest.clearAllMocks();
46
- });
47
- it("should return adapted balances when useGateway is true", async () => {
48
- mockGetCoinConfig.mockReturnValue({
49
- useGateway: true,
50
- nativeInstrumentId: "native-id",
51
- });
52
- const mockInstruments = [
53
- {
54
- instrument_id: "native-id",
55
- amount: "1000",
56
- locked: false,
57
- },
58
- {
59
- instrument_id: "token-123",
60
- amount: "5000",
61
- locked: true,
62
- },
63
- ];
64
- gateway_1.getBalance.mockResolvedValue(mockInstruments);
65
- const result = await (0, getBalance_1.getBalance)("party-id");
66
- expect(gateway_1.getBalance).toHaveBeenCalledWith("party-id");
67
- expect(result).toEqual([
68
- {
69
- value: BigInt(1000),
70
- locked: BigInt(0),
71
- asset: { type: "native" },
72
- },
73
- {
74
- value: BigInt(5000),
75
- locked: BigInt(5000),
76
- asset: { type: "token", assetReference: "token-123" },
77
- },
78
- ]);
79
- });
80
- it("should throw an error when useGateway is false (not implemented with node)", async () => {
81
- mockGetCoinConfig.mockReturnValue({
82
- useGateway: false,
83
- });
84
- await expect((0, getBalance_1.getBalance)("party-id")).rejects.toThrow("Not implemented");
85
- expect(gateway_1.getBalance).not.toHaveBeenCalled();
86
- });
87
- });
88
- //# sourceMappingURL=getBalance.unit.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getBalance.unit.test.js","sourceRoot":"","sources":["../../../src/common-logic/account/getBalance.unit.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAA4E;AAC5E,+DAAiD;AACjD,6CAA0C;AAG1C,IAAI,CAAC,IAAI,CAAC,uBAAuB,EAAE,GAAG,EAAE,CAAC,CAAC;IACxC,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE;CACtB,CAAC,CAAC,CAAC;AAEJ,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,MAAM,iBAAiB,GAAG,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;IAEhF,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,wDAAwD,EAAE,KAAK,IAAI,EAAE;QACtE,iBAAiB,CAAC,eAAe,CAAC;YAChC,UAAU,EAAE,IAAI;YAChB,kBAAkB,EAAE,WAAW;SACzB,CAAC,CAAC;QAEV,MAAM,eAAe,GAAG;YACtB;gBACE,aAAa,EAAE,WAAW;gBAC1B,MAAM,EAAE,MAAM;gBACd,MAAM,EAAE,KAAK;aACd;YACD;gBACE,aAAa,EAAE,WAAW;gBAC1B,MAAM,EAAE,MAAM;gBACd,MAAM,EAAE,IAAI;aACb;SACF,CAAC;QAED,oBAAmC,CAAC,iBAAiB,CAAC,eAAe,CAAC,CAAC;QAExE,MAAM,MAAM,GAAG,MAAM,IAAA,uBAAU,EAAC,UAAU,CAAC,CAAC;QAE5C,MAAM,CAAC,oBAAqB,CAAC,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC;QAC/D,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAY;YAChC;gBACE,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC;gBACnB,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;gBACjB,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;aAC1B;YACD;gBACE,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC;gBACnB,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC;gBACpB,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE;aACtD;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4EAA4E,EAAE,KAAK,IAAI,EAAE;QAC1F,iBAAiB,CAAC,eAAe,CAAC;YAChC,UAAU,EAAE,KAAK;SACX,CAAC,CAAC;QAEV,MAAM,MAAM,CAAC,IAAA,uBAAU,EAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;QACxE,MAAM,CAAC,oBAAqB,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;IACvD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=lastBlock.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lastBlock.test.d.ts","sourceRoot":"","sources":["../../../src/common-logic/history/lastBlock.test.ts"],"names":[],"mappings":""}
@@ -1,43 +0,0 @@
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 lastBlock_1 = require("./lastBlock");
7
- const gateway_1 = require("../../network/gateway");
8
- const node_1 = require("../../network/node");
9
- jest.mock("../../network/gateway", () => ({
10
- getLedgerEnd: jest.fn(),
11
- }));
12
- jest.mock("../../network/node", () => ({
13
- getLedgerEnd: jest.fn(),
14
- }));
15
- jest.mock("../../config", () => ({
16
- __esModule: true,
17
- default: {
18
- getCoinConfig: jest.fn(),
19
- },
20
- }));
21
- const config_1 = __importDefault(require("../../config"));
22
- describe("lastBlock", () => {
23
- beforeEach(() => {
24
- jest.clearAllMocks();
25
- });
26
- it("should use gateway.getLedgerEnd when useGateway is true", async () => {
27
- config_1.default.getCoinConfig.mockReturnValue({ useGateway: true });
28
- gateway_1.getLedgerEnd.mockResolvedValue(100);
29
- const result = await (0, lastBlock_1.lastBlock)();
30
- expect(result).toEqual({ height: 100 });
31
- expect(gateway_1.getLedgerEnd).toHaveBeenCalledTimes(1);
32
- expect(node_1.getLedgerEnd).not.toHaveBeenCalled();
33
- });
34
- it("should use node.getLedgerEnd when useGateway is false", async () => {
35
- config_1.default.getCoinConfig.mockReturnValue({ useGateway: false });
36
- node_1.getLedgerEnd.mockResolvedValue(200);
37
- const result = await (0, lastBlock_1.lastBlock)();
38
- expect(result).toEqual({ height: 200 });
39
- expect(node_1.getLedgerEnd).toHaveBeenCalledTimes(1);
40
- expect(gateway_1.getLedgerEnd).not.toHaveBeenCalled();
41
- });
42
- });
43
- //# sourceMappingURL=lastBlock.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lastBlock.test.js","sourceRoot":"","sources":["../../../src/common-logic/history/lastBlock.test.ts"],"names":[],"mappings":";;;;;AAAA,2CAAwC;AACxC,mDAA4E;AAC5E,6CAAsE;AAEtE,IAAI,CAAC,IAAI,CAAC,uBAAuB,EAAE,GAAG,EAAE,CAAC,CAAC;IACxC,YAAY,EAAE,IAAI,CAAC,EAAE,EAAE;CACxB,CAAC,CAAC,CAAC;AACJ,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,GAAG,EAAE,CAAC,CAAC;IACrC,YAAY,EAAE,IAAI,CAAC,EAAE,EAAE;CACxB,CAAC,CAAC,CAAC;AAEJ,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,GAAG,EAAE,CAAC,CAAC;IAC/B,UAAU,EAAE,IAAI;IAChB,OAAO,EAAE;QACP,aAAa,EAAE,IAAI,CAAC,EAAE,EAAE;KACzB;CACF,CAAC,CAAC,CAAC;AAEJ,0DAAsC;AAEtC,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,UAAU,CAAC,GAAG,EAAE;QACd,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yDAAyD,EAAE,KAAK,IAAI,EAAE;QACtE,gBAAU,CAAC,aAA2B,CAAC,eAAe,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;QAC7E,sBAAiC,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;QAE1D,MAAM,MAAM,GAAG,MAAM,IAAA,qBAAS,GAAE,CAAC;QAEjC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;QACxC,MAAM,CAAC,sBAAmB,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QACrD,MAAM,CAAC,mBAAgB,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;IAClD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uDAAuD,EAAE,KAAK,IAAI,EAAE;QACpE,gBAAU,CAAC,aAA2B,CAAC,eAAe,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;QAC9E,mBAA8B,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;QAEvD,MAAM,MAAM,GAAG,MAAM,IAAA,qBAAS,GAAE,CAAC;QAEjC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;QACxC,MAAM,CAAC,mBAAgB,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAClD,MAAM,CAAC,sBAAmB,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;IACrD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=broadcast.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"broadcast.test.d.ts","sourceRoot":"","sources":["../../../src/common-logic/transaction/broadcast.test.ts"],"names":[],"mappings":""}