@ledgerhq/coin-canton 0.10.0-nightly.20251119110540 → 0.10.0-nightly.20251120135143

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 (48) hide show
  1. package/CHANGELOG.md +9 -7
  2. package/lib/bridge/acceptOffer.d.ts +8 -0
  3. package/lib/bridge/acceptOffer.d.ts.map +1 -0
  4. package/lib/bridge/acceptOffer.js +18 -0
  5. package/lib/bridge/acceptOffer.js.map +1 -0
  6. package/lib/bridge/index.d.ts.map +1 -1
  7. package/lib/bridge/index.js +3 -0
  8. package/lib/bridge/index.js.map +1 -1
  9. package/lib/bridge/serialization.d.ts.map +1 -1
  10. package/lib/bridge/serialization.js +3 -1
  11. package/lib/bridge/serialization.js.map +1 -1
  12. package/lib/bridge/sync.d.ts.map +1 -1
  13. package/lib/bridge/sync.js +4 -0
  14. package/lib/bridge/sync.js.map +1 -1
  15. package/lib/network/gateway.d.ts +18 -0
  16. package/lib/network/gateway.d.ts.map +1 -1
  17. package/lib/network/gateway.js +26 -6
  18. package/lib/network/gateway.js.map +1 -1
  19. package/lib/types/bridge.d.ts +4 -0
  20. package/lib/types/bridge.d.ts.map +1 -1
  21. package/lib-es/bridge/acceptOffer.d.ts +8 -0
  22. package/lib-es/bridge/acceptOffer.d.ts.map +1 -0
  23. package/lib-es/bridge/acceptOffer.js +14 -0
  24. package/lib-es/bridge/acceptOffer.js.map +1 -0
  25. package/lib-es/bridge/index.d.ts.map +1 -1
  26. package/lib-es/bridge/index.js +3 -0
  27. package/lib-es/bridge/index.js.map +1 -1
  28. package/lib-es/bridge/serialization.d.ts.map +1 -1
  29. package/lib-es/bridge/serialization.js +3 -1
  30. package/lib-es/bridge/serialization.js.map +1 -1
  31. package/lib-es/bridge/sync.d.ts.map +1 -1
  32. package/lib-es/bridge/sync.js +5 -1
  33. package/lib-es/bridge/sync.js.map +1 -1
  34. package/lib-es/network/gateway.d.ts +18 -0
  35. package/lib-es/network/gateway.d.ts.map +1 -1
  36. package/lib-es/network/gateway.js +22 -6
  37. package/lib-es/network/gateway.js.map +1 -1
  38. package/lib-es/types/bridge.d.ts +4 -0
  39. package/lib-es/types/bridge.d.ts.map +1 -1
  40. package/package.json +7 -7
  41. package/src/bridge/acceptOffer.test.ts +300 -0
  42. package/src/bridge/acceptOffer.ts +36 -0
  43. package/src/bridge/getTransactionStatus.test.ts +1 -0
  44. package/src/bridge/index.ts +3 -0
  45. package/src/bridge/serialization.ts +3 -1
  46. package/src/bridge/sync.ts +10 -1
  47. package/src/network/gateway.ts +60 -6
  48. package/src/types/bridge.ts +15 -0
@@ -4,7 +4,12 @@ import { encodeAccountId } from "@ledgerhq/coin-framework/account/index";
4
4
  import { GetAccountShape, mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
5
5
  import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
6
6
  import { SignerContext } from "@ledgerhq/coin-framework/signer";
7
- import { getLedgerEnd, getOperations, type OperationInfo } from "../network/gateway";
7
+ import {
8
+ getLedgerEnd,
9
+ getOperations,
10
+ type OperationInfo,
11
+ getPendingTransferProposals,
12
+ } from "../network/gateway";
8
13
  import { getBalance, type CantonBalance } from "../common-logic/account/getBalance";
9
14
  import coinConfig from "../config";
10
15
  import resolver from "../signer";
@@ -107,6 +112,9 @@ export function makeGetAccountShape(
107
112
 
108
113
  const { nativeInstrumentId } = coinConfig.getCoinConfig(currency);
109
114
  const balances = xpubOrAddress ? await getBalance(currency, xpubOrAddress) : [];
115
+ const pendingTransferProposals = xpubOrAddress
116
+ ? await getPendingTransferProposals(currency, xpubOrAddress)
117
+ : [];
110
118
 
111
119
  const balancesData = (balances || []).reduce(
112
120
  (acc, balance) => {
@@ -169,6 +177,7 @@ export function makeGetAccountShape(
169
177
  used,
170
178
  cantonResources: {
171
179
  instrumentUtxoCounts,
180
+ pendingTransferProposals,
172
181
  },
173
182
  };
174
183
 
@@ -58,6 +58,25 @@ export type PrepareTransferRequest = {
58
58
  reason?: string;
59
59
  };
60
60
 
61
+ export type PrepareTransferInstructionRequest = {
62
+ type:
63
+ | "accept-transfer-instruction"
64
+ | "reject-transfer-instruction"
65
+ | "withdraw-transfer-instruction";
66
+ contract_id: string;
67
+ reason?: string;
68
+ };
69
+
70
+ export type TransferProposal = {
71
+ contract_id: string;
72
+ sender: string;
73
+ receiver: string;
74
+ amount: string;
75
+ instrument_id: string;
76
+ memo: string;
77
+ expires_at_micros: number;
78
+ };
79
+
61
80
  type OnboardingSubmitRequest = {
62
81
  prepare_request: OnboardingPrepareRequest;
63
82
  prepare_response: OnboardingPrepareResponse;
@@ -380,6 +399,22 @@ export async function submit(
380
399
  return data;
381
400
  }
382
401
 
402
+ export async function prepare(
403
+ currency: CryptoCurrency,
404
+ partyId: string,
405
+ params: PrepareTransferRequest | PrepareTransferInstructionRequest,
406
+ ) {
407
+ const { data } = await gatewayNetwork<
408
+ PrepareTransferResponse,
409
+ PrepareTransferRequest | PrepareTransferInstructionRequest
410
+ >({
411
+ method: "POST",
412
+ url: `${getGatewayUrl(currency)}/v1/node/${getNodeId(currency)}/party/${partyId}/transaction/prepare`,
413
+ data: params,
414
+ });
415
+ return data;
416
+ }
417
+
383
418
  export async function getBalance(currency: CryptoCurrency, partyId: string) {
384
419
  const { data } = await gatewayNetwork<GetBalanceResponse>({
385
420
  method: "GET",
@@ -502,13 +537,15 @@ export async function prepareTransferRequest(
502
537
  partyId: string,
503
538
  params: PrepareTransferRequest,
504
539
  ) {
505
- const { data } = await gatewayNetwork<PrepareTransferResponse, PrepareTransferRequest>({
506
- method: "POST",
507
- url: `${getGatewayUrl(currency)}/v1/node/${getNodeId(currency)}/party/${partyId}/transaction/prepare`,
508
- data: params,
509
- });
540
+ return prepare(currency, partyId, params);
541
+ }
510
542
 
511
- return data;
543
+ export async function prepareTransferInstruction(
544
+ currency: CryptoCurrency,
545
+ partyId: string,
546
+ params: PrepareTransferInstructionRequest,
547
+ ) {
548
+ return prepare(currency, partyId, params);
512
549
  }
513
550
 
514
551
  export async function getLedgerEnd(currency: CryptoCurrency): Promise<number> {
@@ -553,6 +590,15 @@ export async function submitPreApprovalTransaction(
553
590
  } satisfies PreApprovalResult;
554
591
  }
555
592
 
593
+ export async function submitTransferInstruction(
594
+ currency: CryptoCurrency,
595
+ partyId: string,
596
+ serialized: string,
597
+ signature: string,
598
+ ) {
599
+ return submit(currency, partyId, serialized, signature);
600
+ }
601
+
556
602
  type GetTransferPreApprovalResponse = {
557
603
  contract_id: string;
558
604
  receiver: string;
@@ -569,3 +615,11 @@ export async function getTransferPreApproval(currency: CryptoCurrency, partyId:
569
615
  });
570
616
  return data;
571
617
  }
618
+
619
+ export async function getPendingTransferProposals(currency: CryptoCurrency, partyId: string) {
620
+ const { data } = await gatewayNetwork<TransferProposal[]>({
621
+ method: "GET",
622
+ url: `${getGatewayUrl(currency)}/v1/node/${getNodeId(currency)}/party/${partyId}/transfer-proposals?timestamp=${Date.now()}`,
623
+ });
624
+ return data;
625
+ }
@@ -16,6 +16,7 @@ import type {
16
16
  CantonAuthorizeProgress,
17
17
  CantonAuthorizeResult,
18
18
  } from "./onboard";
19
+ import type { TransferProposal } from "../network/gateway";
19
20
 
20
21
  export interface CantonCurrencyBridge extends CurrencyBridge {
21
22
  onboardAccount: (
@@ -29,6 +30,18 @@ export interface CantonCurrencyBridge extends CurrencyBridge {
29
30
  creatableAccount: Account,
30
31
  partyId: string,
31
32
  ) => Observable<CantonAuthorizeProgress | CantonAuthorizeResult>;
33
+ transferInstruction: (
34
+ currency: CryptoCurrency,
35
+ deviceId: string,
36
+ account: Account,
37
+ partyId: string,
38
+ contractId: string,
39
+ type:
40
+ | "accept-transfer-instruction"
41
+ | "reject-transfer-instruction"
42
+ | "withdraw-transfer-instruction",
43
+ reason?: string,
44
+ ) => Promise<void>;
32
45
  }
33
46
 
34
47
  export type NetworkInfo = {
@@ -64,9 +77,11 @@ export type TransactionStatusRaw = TransactionStatusCommonRaw;
64
77
 
65
78
  export type CantonResources = {
66
79
  instrumentUtxoCounts: Record<string, number>;
80
+ pendingTransferProposals: TransferProposal[];
67
81
  };
68
82
  export type CantonResourcesRaw = {
69
83
  instrumentUtxoCounts: Record<string, number>;
84
+ pendingTransferProposals: TransferProposal[];
70
85
  };
71
86
 
72
87
  export type CantonAccount = Account & {