@ledgerhq/coin-canton 0.4.0 → 0.4.1-nightly.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 (153) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/jest.config.js +1 -0
  3. package/lib/api/getBalance.integ.test.d.ts +2 -0
  4. package/lib/api/getBalance.integ.test.d.ts.map +1 -0
  5. package/lib/api/getBalance.integ.test.js +24 -0
  6. package/lib/api/getBalance.integ.test.js.map +1 -0
  7. package/lib/api/lastBlock.integ.test.js +3 -1
  8. package/lib/api/lastBlock.integ.test.js.map +1 -1
  9. package/lib/api/listOperations.integ.test.d.ts +2 -0
  10. package/lib/api/listOperations.integ.test.d.ts.map +1 -0
  11. package/lib/api/listOperations.integ.test.js +23 -0
  12. package/lib/api/listOperations.integ.test.js.map +1 -0
  13. package/lib/bridge/signOperation.js +1 -1
  14. package/lib/bridge/signOperation.js.map +1 -1
  15. package/lib/common-logic/account/getBalance.d.ts +1 -1
  16. package/lib/common-logic/account/getBalance.d.ts.map +1 -1
  17. package/lib/common-logic/account/getBalance.js +21 -5
  18. package/lib/common-logic/account/getBalance.js.map +1 -1
  19. package/lib/common-logic/account/getBalance.unit.test.d.ts +2 -0
  20. package/lib/common-logic/account/getBalance.unit.test.d.ts.map +1 -0
  21. package/lib/common-logic/account/getBalance.unit.test.js +88 -0
  22. package/lib/common-logic/account/getBalance.unit.test.js.map +1 -0
  23. package/lib/common-logic/history/lastBlock.d.ts.map +1 -1
  24. package/lib/common-logic/history/lastBlock.js +7 -1
  25. package/lib/common-logic/history/lastBlock.js.map +1 -1
  26. package/lib/common-logic/history/lastBlock.test.d.ts +2 -0
  27. package/lib/common-logic/history/lastBlock.test.d.ts.map +1 -0
  28. package/lib/common-logic/history/lastBlock.test.js +43 -0
  29. package/lib/common-logic/history/lastBlock.test.js.map +1 -0
  30. package/lib/common-logic/history/listOperations.d.ts +3 -4
  31. package/lib/common-logic/history/listOperations.d.ts.map +1 -1
  32. package/lib/common-logic/history/listOperations.js +43 -41
  33. package/lib/common-logic/history/listOperations.js.map +1 -1
  34. package/lib/common-logic/transaction/broadcast.d.ts.map +1 -1
  35. package/lib/common-logic/transaction/broadcast.js +11 -3
  36. package/lib/common-logic/transaction/broadcast.js.map +1 -1
  37. package/lib/common-logic/transaction/broadcast.test.d.ts +2 -0
  38. package/lib/common-logic/transaction/broadcast.test.d.ts.map +1 -0
  39. package/lib/common-logic/transaction/broadcast.test.js +68 -0
  40. package/lib/common-logic/transaction/broadcast.test.js.map +1 -0
  41. package/lib/common-logic/transaction/combine.d.ts +1 -1
  42. package/lib/common-logic/transaction/combine.d.ts.map +1 -1
  43. package/lib/common-logic/transaction/combine.js +6 -3
  44. package/lib/common-logic/transaction/combine.js.map +1 -1
  45. package/lib/common-logic/transaction/combine.test.d.ts +2 -0
  46. package/lib/common-logic/transaction/combine.test.d.ts.map +1 -0
  47. package/lib/common-logic/transaction/combine.test.js +28 -0
  48. package/lib/common-logic/transaction/combine.test.js.map +1 -0
  49. package/lib/common-logic/transaction/estimateFees.d.ts.map +1 -1
  50. package/lib/common-logic/transaction/estimateFees.js +2 -15
  51. package/lib/common-logic/transaction/estimateFees.js.map +1 -1
  52. package/lib/common-logic/utils.d.ts +0 -1
  53. package/lib/common-logic/utils.d.ts.map +1 -1
  54. package/lib/common-logic/utils.js +1 -6
  55. package/lib/common-logic/utils.js.map +1 -1
  56. package/lib/config.d.ts +6 -3
  57. package/lib/config.d.ts.map +1 -1
  58. package/lib/config.js.map +1 -1
  59. package/lib/network/gateway.d.ts +31 -21
  60. package/lib/network/gateway.d.ts.map +1 -1
  61. package/lib/network/gateway.integ.test.js +29 -2
  62. package/lib/network/gateway.integ.test.js.map +1 -1
  63. package/lib/network/gateway.js +33 -9
  64. package/lib/network/gateway.js.map +1 -1
  65. package/lib/network/node.integ.test.js +4 -2
  66. package/lib/network/node.integ.test.js.map +1 -1
  67. package/lib/types/bridge.d.ts.map +1 -1
  68. package/lib-es/api/getBalance.integ.test.d.ts +2 -0
  69. package/lib-es/api/getBalance.integ.test.d.ts.map +1 -0
  70. package/lib-es/api/getBalance.integ.test.js +22 -0
  71. package/lib-es/api/getBalance.integ.test.js.map +1 -0
  72. package/lib-es/api/lastBlock.integ.test.js +3 -1
  73. package/lib-es/api/lastBlock.integ.test.js.map +1 -1
  74. package/lib-es/api/listOperations.integ.test.d.ts +2 -0
  75. package/lib-es/api/listOperations.integ.test.d.ts.map +1 -0
  76. package/lib-es/api/listOperations.integ.test.js +21 -0
  77. package/lib-es/api/listOperations.integ.test.js.map +1 -0
  78. package/lib-es/bridge/signOperation.js +1 -1
  79. package/lib-es/bridge/signOperation.js.map +1 -1
  80. package/lib-es/common-logic/account/getBalance.d.ts +1 -1
  81. package/lib-es/common-logic/account/getBalance.d.ts.map +1 -1
  82. package/lib-es/common-logic/account/getBalance.js +18 -5
  83. package/lib-es/common-logic/account/getBalance.js.map +1 -1
  84. package/lib-es/common-logic/account/getBalance.unit.test.d.ts +2 -0
  85. package/lib-es/common-logic/account/getBalance.unit.test.d.ts.map +1 -0
  86. package/lib-es/common-logic/account/getBalance.unit.test.js +53 -0
  87. package/lib-es/common-logic/account/getBalance.unit.test.js.map +1 -0
  88. package/lib-es/common-logic/history/lastBlock.d.ts.map +1 -1
  89. package/lib-es/common-logic/history/lastBlock.js +5 -2
  90. package/lib-es/common-logic/history/lastBlock.js.map +1 -1
  91. package/lib-es/common-logic/history/lastBlock.test.d.ts +2 -0
  92. package/lib-es/common-logic/history/lastBlock.test.d.ts.map +1 -0
  93. package/lib-es/common-logic/history/lastBlock.test.js +38 -0
  94. package/lib-es/common-logic/history/lastBlock.test.js.map +1 -0
  95. package/lib-es/common-logic/history/listOperations.d.ts +3 -4
  96. package/lib-es/common-logic/history/listOperations.d.ts.map +1 -1
  97. package/lib-es/common-logic/history/listOperations.js +40 -41
  98. package/lib-es/common-logic/history/listOperations.js.map +1 -1
  99. package/lib-es/common-logic/transaction/broadcast.d.ts.map +1 -1
  100. package/lib-es/common-logic/transaction/broadcast.js +8 -3
  101. package/lib-es/common-logic/transaction/broadcast.js.map +1 -1
  102. package/lib-es/common-logic/transaction/broadcast.test.d.ts +2 -0
  103. package/lib-es/common-logic/transaction/broadcast.test.d.ts.map +1 -0
  104. package/lib-es/common-logic/transaction/broadcast.test.js +33 -0
  105. package/lib-es/common-logic/transaction/broadcast.test.js.map +1 -0
  106. package/lib-es/common-logic/transaction/combine.d.ts +1 -1
  107. package/lib-es/common-logic/transaction/combine.d.ts.map +1 -1
  108. package/lib-es/common-logic/transaction/combine.js +6 -3
  109. package/lib-es/common-logic/transaction/combine.js.map +1 -1
  110. package/lib-es/common-logic/transaction/combine.test.d.ts +2 -0
  111. package/lib-es/common-logic/transaction/combine.test.d.ts.map +1 -0
  112. package/lib-es/common-logic/transaction/combine.test.js +26 -0
  113. package/lib-es/common-logic/transaction/combine.test.js.map +1 -0
  114. package/lib-es/common-logic/transaction/estimateFees.d.ts.map +1 -1
  115. package/lib-es/common-logic/transaction/estimateFees.js +2 -15
  116. package/lib-es/common-logic/transaction/estimateFees.js.map +1 -1
  117. package/lib-es/common-logic/utils.d.ts +0 -1
  118. package/lib-es/common-logic/utils.d.ts.map +1 -1
  119. package/lib-es/common-logic/utils.js +0 -4
  120. package/lib-es/common-logic/utils.js.map +1 -1
  121. package/lib-es/config.d.ts +6 -3
  122. package/lib-es/config.d.ts.map +1 -1
  123. package/lib-es/config.js.map +1 -1
  124. package/lib-es/network/gateway.d.ts +31 -21
  125. package/lib-es/network/gateway.d.ts.map +1 -1
  126. package/lib-es/network/gateway.integ.test.js +30 -3
  127. package/lib-es/network/gateway.integ.test.js.map +1 -1
  128. package/lib-es/network/gateway.js +30 -8
  129. package/lib-es/network/gateway.js.map +1 -1
  130. package/lib-es/network/node.integ.test.js +4 -2
  131. package/lib-es/network/node.integ.test.js.map +1 -1
  132. package/lib-es/types/bridge.d.ts.map +1 -1
  133. package/package.json +2 -2
  134. package/src/api/getBalance.integ.test.ts +28 -0
  135. package/src/api/lastBlock.integ.test.ts +3 -1
  136. package/src/api/listOperations.integ.test.ts +27 -0
  137. package/src/bridge/signOperation.ts +1 -1
  138. package/src/common-logic/account/getBalance.ts +20 -5
  139. package/src/common-logic/account/getBalance.unit.test.ts +63 -0
  140. package/src/common-logic/history/lastBlock.test.ts +47 -0
  141. package/src/common-logic/history/lastBlock.ts +6 -2
  142. package/src/common-logic/history/listOperations.ts +43 -52
  143. package/src/common-logic/transaction/broadcast.test.ts +42 -0
  144. package/src/common-logic/transaction/broadcast.ts +7 -3
  145. package/src/common-logic/transaction/combine.test.ts +28 -0
  146. package/src/common-logic/transaction/combine.ts +7 -4
  147. package/src/common-logic/transaction/estimateFees.ts +2 -14
  148. package/src/common-logic/utils.ts +0 -5
  149. package/src/config.ts +8 -2
  150. package/src/network/gateway.integ.test.ts +49 -3
  151. package/src/network/gateway.ts +67 -27
  152. package/src/network/node.integ.test.ts +4 -2
  153. package/src/types/bridge.ts +0 -1
@@ -1,64 +1,55 @@
1
1
  import type { Operation, Pagination } from "@ledgerhq/coin-framework/api/index";
2
- import { getTransactions } from "../../network/indexer";
3
- import { BoilerplateOperation } from "../../network/types";
2
+ import { CreatedEvent, getTransactions, TxInfo } from "../../network/gateway";
3
+ import coinConfig from "../../config";
4
+
5
+ const getNativeContractId = () =>
6
+ coinConfig.getCoinConfig().nativeInstrumentId !== undefined
7
+ ? coinConfig.getCoinConfig().nativeInstrumentId?.split(".")[0]
8
+ : "";
4
9
 
5
10
  /**
6
11
  * Returns list of operations associated to an account.
7
- * @param address Account address
12
+ * @param partyId Account partyId
8
13
  * @param pagination Pagination options
9
14
  * @returns Operations found and the next "id" or "index" to use for pagination (i.e. `start` property).\
10
- * If `0` is returns, no pagination needed.
11
- * This "id" or "index" value, thus it has functional meaning, is different for each blockchain.
15
+ * Impl to finalize when backend is ready
12
16
  */
13
17
  export async function listOperations(
14
- address: string,
18
+ partyId: string,
15
19
  page: Pagination,
16
20
  ): Promise<[Operation[], string]> {
17
- const transactions = await getTransactions(address, { from: page.minHeight });
18
- return [transactions.map(convertToCoreOperation(address)), ""];
19
- }
20
-
21
- const convertToCoreOperation =
22
- (address: string) =>
23
- (operation: BoilerplateOperation): Operation => {
24
- const {
25
- meta: { delivered_amount },
26
- tx: { Fee, hash, inLedger, date, Account, Destination },
27
- } = operation;
28
-
29
- const type = Account === address ? "OUT" : "IN";
30
- let value =
31
- delivered_amount && typeof delivered_amount === "string"
32
- ? BigInt(delivered_amount)
33
- : BigInt(0);
34
-
35
- const feeValue = BigInt(Fee);
36
- if (type === "OUT") {
37
- if (!Number.isNaN(feeValue)) {
38
- value = value + feeValue;
21
+ const { transactions, next } = await getTransactions(partyId, {
22
+ cursor: page.pagingToken !== undefined ? parseInt(page.pagingToken) : undefined,
23
+ minOffset: page.minHeight,
24
+ limit: page.limit,
25
+ });
26
+ const ops: Operation[] = [];
27
+ for (const tx of transactions) {
28
+ for (let i = 0; i < tx.events.length; i++) {
29
+ const event: CreatedEvent = tx.events[i]["CantonCreatedEvent"] as CreatedEvent;
30
+ if (event && event.template_id.module_name === "Splice.Amulet") {
31
+ ops.push({
32
+ id: tx.update_id + "-" + i,
33
+ type: event.signatories.includes(partyId) ? "OUT" : "IN",
34
+ value: BigInt(0), // to be finalized when details are available on backend
35
+ senders: event.signatories.includes(partyId) ? [partyId] : [],
36
+ recipients: event.signatories.includes(partyId) ? [] : [partyId],
37
+ asset:
38
+ event.contract_id === getNativeContractId()
39
+ ? { type: "native" }
40
+ : { type: "token", assetReference: event.contract_id },
41
+ tx: {
42
+ hash: tx.update_id,
43
+ fees: BigInt(0), // to be finalized when details are available on backend
44
+ date: new Date(tx.record_time.seconds),
45
+ block: {
46
+ height: tx.offset,
47
+ time: new Date(tx.effective_at.seconds),
48
+ },
49
+ },
50
+ });
39
51
  }
40
52
  }
41
-
42
- return {
43
- /**
44
- * Note: The operation ID must be concatenated with another
45
- * value if the transaction hash is not enough to identify it
46
- */
47
- id: hash,
48
- asset: { type: "native" },
49
- tx: {
50
- hash,
51
- fees: feeValue,
52
- date: new Date(date),
53
- block: {
54
- height: inLedger,
55
- hash,
56
- time: new Date(date),
57
- },
58
- },
59
- type,
60
- value,
61
- senders: [Account],
62
- recipients: [Destination],
63
- };
64
- };
53
+ }
54
+ return [ops, next + ""];
55
+ }
@@ -0,0 +1,42 @@
1
+ import { submit } from "../../network/gateway";
2
+ import * as coinConfigModule from "../../config";
3
+ import { broadcast } from "./broadcast";
4
+
5
+ jest.mock("../../network/gateway", () => ({
6
+ submit: jest.fn(),
7
+ }));
8
+
9
+ const mockSerialized = JSON.stringify({
10
+ serialized: "serialized-tx",
11
+ signature: "signature",
12
+ });
13
+
14
+ describe("broadcast", () => {
15
+ const mockGetCoinConfig = jest.spyOn(coinConfigModule.default, "getCoinConfig");
16
+
17
+ afterEach(() => {
18
+ jest.clearAllMocks();
19
+ });
20
+
21
+ it("should broadcast", async () => {
22
+ mockGetCoinConfig.mockReturnValue({
23
+ useGateway: true,
24
+ } as any);
25
+
26
+ (submit as jest.Mock).mockResolvedValue({ updateId: "my-update-id" });
27
+
28
+ const result = await broadcast(mockSerialized);
29
+
30
+ expect(submit).toHaveBeenCalledWith("serialized-tx", "signature");
31
+ expect(result).toEqual("my-update-id");
32
+ });
33
+
34
+ it("should throw an error when useGateway is false (not implemented with node)", async () => {
35
+ mockGetCoinConfig.mockReturnValue({
36
+ useGateway: false,
37
+ } as any);
38
+
39
+ await expect(broadcast(mockSerialized)).rejects.toThrow("Not implemented");
40
+ expect(submit).not.toHaveBeenCalled();
41
+ });
42
+ });
@@ -1,6 +1,10 @@
1
- import { submit } from "../../network/node";
1
+ import coinConfig from "../../config";
2
+ import { submit } from "../../network/gateway";
3
+
4
+ const useGateway = () => coinConfig.getCoinConfig().useGateway === true;
2
5
 
3
6
  export async function broadcast(signedTx: string): Promise<string> {
4
- const submittedPayment = await submit(signedTx);
5
- return submittedPayment.tx_hash;
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");
6
10
  }
@@ -0,0 +1,28 @@
1
+ import { combine } from "./combine";
2
+
3
+ describe("combine", () => {
4
+ it("responds with a Stringify version of the payload to broadcast", () => {
5
+ // GIVEN
6
+ const transaction = {
7
+ transaction: {
8
+ serialized: "SERIALIZED",
9
+ json: "JSON",
10
+ hash: "HASH",
11
+ },
12
+ };
13
+ const signature = "SIGNATURE";
14
+
15
+ // WHEN
16
+ const result = combine(JSON.stringify(transaction), signature);
17
+
18
+ // THEN
19
+ expect(JSON.parse(result)).toEqual({
20
+ transaction: {
21
+ serialized: "SERIALIZED",
22
+ json: "JSON",
23
+ hash: "HASH",
24
+ },
25
+ signature: "SIGNATURE",
26
+ });
27
+ });
28
+ });
@@ -1,6 +1,9 @@
1
- import { encode } from "../utils";
2
-
3
1
  // Combines signature with raw transaction
4
- export function combine(transaction: string, signature: string, publicKey?: string): string {
5
- return encode(transaction, signature, publicKey || "");
2
+ export function combine(transaction: string, signature: string): string {
3
+ const tx = JSON.parse(transaction);
4
+
5
+ return JSON.stringify({
6
+ ...tx,
7
+ signature,
8
+ });
6
9
  }
@@ -1,16 +1,4 @@
1
- import { simulate } from "../../network/node";
2
- import { SimulationError } from "../../types/errors";
3
-
1
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
4
2
  export async function estimateFees(serializedTransaction: string): Promise<bigint> {
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
- }
3
+ return Promise.resolve(BigInt(10_000)); // TODO replace with real implementation
16
4
  }
@@ -11,8 +11,3 @@ 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,16 +1,22 @@
1
- import buildCoinConfig, { type CurrencyConfig } from "@ledgerhq/coin-framework/config";
1
+ import buildCoinConfig, { CoinConfig, type CurrencyConfig } from "@ledgerhq/coin-framework/config";
2
+ import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
2
3
 
3
4
  export type CantonConfig = {
4
5
  nodeUrl?: string;
6
+ nodeId?: string;
5
7
  gatewayUrl?: string;
6
8
  // TODELETE
7
9
  minReserve?: number;
8
10
  networkType: "mainnet" | "devnet" | "localnet";
9
11
  useGateway?: boolean;
12
+ nativeInstrumentId?: string;
10
13
  };
11
14
 
12
15
  export type CantonCoinConfig = CurrencyConfig & CantonConfig;
13
16
 
14
- const coinConfig = buildCoinConfig<CantonCoinConfig>();
17
+ const coinConfig: {
18
+ setCoinConfig: (config: CoinConfig<CantonCoinConfig>) => void;
19
+ getCoinConfig: (currency?: CryptoCurrency) => CantonCoinConfig;
20
+ } = buildCoinConfig<CantonCoinConfig>();
15
21
 
16
22
  export default coinConfig;
@@ -1,32 +1,78 @@
1
1
  import coinConfig from "../config";
2
- import { getLedgerEnd, prepareOnboarding } from "./gateway";
2
+ import {
3
+ getLedgerEnd,
4
+ prepareOnboarding,
5
+ getBalance,
6
+ getTransactions,
7
+ getPartyById,
8
+ getPartyByPubKey,
9
+ } from "./gateway";
3
10
 
4
11
  describe("gateway (devnet)", () => {
5
12
  beforeAll(() => {
6
13
  coinConfig.setCoinConfig(() => ({
7
14
  gatewayUrl: "https://canton-gateway.api.live.ledger-test.com",
15
+ useGateway: true,
8
16
  networkType: "devnet",
9
17
  status: {
10
18
  type: "active",
11
19
  },
12
20
  }));
13
21
  });
22
+
14
23
  describe("prepareOnboarding", () => {
15
24
  it("should prepare onboarding", async () => {
16
25
  const response = await prepareOnboarding(
17
- "0x043b462de34ec31fba274f2a381947aef26697912194312fc289c46cc1b2b4f6b00828dc1e4f96001b10463083edf85f2e0550862a3dc99ed411ca6d25f2bc19a8",
26
+ "c59f7f29374d24506dd6490a5db472cf00958e195e146f3dc9c97f96d5c51097",
18
27
  "ed25519",
19
28
  );
20
29
  expect(response).toHaveProperty("party_id");
21
30
  expect(response).toHaveProperty("party_name");
22
31
  expect(response).toHaveProperty("public_key_fingerprint");
23
32
  expect(response).toHaveProperty("topology_transactions_hash");
24
- });
33
+ }, 30000);
25
34
  });
35
+
26
36
  describe("getLedgerEnd", () => {
27
37
  it("should return ledger end", async () => {
28
38
  const end = await getLedgerEnd();
29
39
  expect(end).toBeGreaterThanOrEqual(0);
30
40
  });
31
41
  });
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
+ });
32
78
  });
@@ -26,8 +26,15 @@ type OnboardingSubmitResponse = {
26
26
  };
27
27
  };
28
28
 
29
- type InstrumentBalance = {
30
- instrumentId: string;
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;
31
38
  amount: number;
32
39
  locked: boolean;
33
40
  };
@@ -44,46 +51,47 @@ type Timestamp = {
44
51
 
45
52
  type BaseEvent = {
46
53
  type: string;
47
- contractId: string;
54
+ contract_id: string;
48
55
  details: string;
49
56
  };
50
57
 
51
- type CreatedEvent = BaseEvent & {
52
- templateId: {
53
- packageId: string;
54
- moduleName: string;
55
- entityName: string;
58
+ export type CreatedEvent = BaseEvent & {
59
+ template_id: {
60
+ package_id: string;
61
+ module_name: string;
62
+ entity_name: string;
56
63
  };
57
64
  signatories: string[];
58
65
  observers: string[];
59
66
  };
60
67
 
61
68
  type ExercisedEvent = BaseEvent & {
62
- templateId: {
69
+ template_id: {
63
70
  packageId: string;
64
71
  moduleName: string;
65
72
  entityName: string;
66
73
  };
67
74
  choice: string;
68
75
  consuming: boolean;
69
- actingParties: string[];
76
+ acting_parties: string[];
70
77
  };
71
78
 
72
79
  type Event = BaseEvent | CreatedEvent | ExercisedEvent;
73
80
 
74
- type TxInfo = {
75
- updateId: string;
76
- commandId: string;
77
- workflowId: string;
78
- effectiveAt: Timestamp;
81
+ export type TxInfo = {
82
+ update_id: string;
83
+ command_id: string;
84
+ workflow_id: string;
85
+ effective_at: Timestamp;
79
86
  offset: number;
80
- synchronizerId: string;
81
- recordTime: Timestamp;
82
- events: Event[];
83
- traceContext: string;
87
+ synchronizer_id: string;
88
+ record_time: Timestamp;
89
+ events: Record<string, Event>[];
90
+ trace_context: string;
84
91
  };
85
92
 
86
93
  const getGatewayUrl = () => coinConfig.getCoinConfig().gatewayUrl;
94
+ const getNodeId = () => coinConfig.getCoinConfig().nodeId || "ledger-live-devnet-prd";
87
95
 
88
96
  export async function prepareOnboarding(
89
97
  pubKey: string,
@@ -91,7 +99,7 @@ export async function prepareOnboarding(
91
99
  ): Promise<OnboardingPrepareResponse> {
92
100
  const { data } = await network<OnboardingPrepareResponse>({
93
101
  method: "POST",
94
- url: `${getGatewayUrl()}/v1/node/0/onboarding/prepare`,
102
+ url: `${getGatewayUrl()}/v1/node/${getNodeId()}/onboarding/prepare`,
95
103
  data: {
96
104
  public_key: pubKey,
97
105
  public_key_type: pubKeyType,
@@ -107,7 +115,7 @@ export async function submitOnboarding(
107
115
  ) {
108
116
  const { data } = await network<OnboardingSubmitResponse>({
109
117
  method: "POST",
110
- url: `${getGatewayUrl()}/v1/node/0/onboarding/submit`,
118
+ url: `${getGatewayUrl()}/v1/node/${getNodeId()}/onboarding/submit`,
111
119
  data: {
112
120
  prepare_request: prepareRequest,
113
121
  prepare_response: prepareResponse,
@@ -117,23 +125,54 @@ export async function submitOnboarding(
117
125
  return data;
118
126
  }
119
127
 
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
+
120
140
  export async function getBalance(partyId: string): Promise<InstrumentBalance[]> {
121
141
  const { data } = await network<InstrumentBalance[]>({
122
142
  method: "GET",
123
- url: `${getGatewayUrl()}/v1/node/0/party/${partyId}/balance`,
143
+ url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/balance`,
124
144
  });
125
145
  return data;
126
146
  }
127
147
 
128
- export async function getParty(partyId: string): Promise<PartyInfo> {
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> {
129
157
  const { data } = await network<PartyInfo>({
130
158
  method: "GET",
131
- url: `${getGatewayUrl()}/v1/node/0/party/${partyId}`,
159
+ url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${identifier}`,
160
+ data: {
161
+ by,
162
+ },
132
163
  });
133
164
  return data;
134
165
  }
135
166
 
136
- export async function getTransactions(partyId: string): Promise<{
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<{
137
176
  next: number;
138
177
  transactions: TxInfo[];
139
178
  }> {
@@ -142,7 +181,8 @@ export async function getTransactions(partyId: string): Promise<{
142
181
  transactions: TxInfo[];
143
182
  }>({
144
183
  method: "GET",
145
- url: `${getGatewayUrl()}/v1/node/0/party/${partyId}/transactions`,
184
+ url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transactions`,
185
+ data: options,
146
186
  });
147
187
  return data;
148
188
  }
@@ -150,7 +190,7 @@ export async function getTransactions(partyId: string): Promise<{
150
190
  export async function getLedgerEnd(): Promise<number> {
151
191
  const { data } = await network<number>({
152
192
  method: "GET",
153
- url: `${getGatewayUrl()}/v1/node/0/ledger-end`,
193
+ url: `${getGatewayUrl()}/v1/node/${getNodeId()}/ledger-end`,
154
194
  });
155
195
  return data;
156
196
  }
@@ -1,7 +1,8 @@
1
1
  import coinConfig from "../config";
2
2
  import { getLedgerEnd } from "./node";
3
3
 
4
- describe("Node (localnet)", () => {
4
+ // enable manually, as it requires a running node locally
5
+ describe.skip("Node (localnet)", () => {
5
6
  beforeAll(() => {
6
7
  coinConfig.setCoinConfig(() => ({
7
8
  gatewayUrl: "http://gateway.url",
@@ -19,7 +20,8 @@ describe("Node (localnet)", () => {
19
20
  });
20
21
  });
21
22
 
22
- describe("Node (devnet)", () => {
23
+ // enable manually, as it requires an auth token in env variable
24
+ describe.skip("Node (devnet)", () => {
23
25
  beforeAll(() => {
24
26
  coinConfig.setCoinConfig(() => ({
25
27
  nodeUrl: "https://wallet-validator-devnet-canton.ledger-test.com/v2",
@@ -1,5 +1,4 @@
1
1
  import type { BigNumber } from "bignumber.js";
2
- import type { Unit } from "@ledgerhq/types-cryptoassets";
3
2
  import type {
4
3
  TransactionCommon,
5
4
  TransactionCommonRaw,