@ledgerhq/coin-canton 0.9.0-nightly.2 → 0.9.0-nightly.4

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 (145) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.unimportedrc.json +2 -1
  3. package/CHANGELOG.md +28 -0
  4. package/lib/bridge/estimateMaxSpendable.d.ts +2 -2
  5. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
  6. package/lib/bridge/estimateMaxSpendable.js +2 -3
  7. package/lib/bridge/estimateMaxSpendable.js.map +1 -1
  8. package/lib/bridge/getTransactionStatus.d.ts +5 -3
  9. package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
  10. package/lib/bridge/getTransactionStatus.js +26 -5
  11. package/lib/bridge/getTransactionStatus.js.map +1 -1
  12. package/lib/bridge/index.d.ts +2 -2
  13. package/lib/bridge/index.d.ts.map +1 -1
  14. package/lib/bridge/index.js +3 -3
  15. package/lib/bridge/index.js.map +1 -1
  16. package/lib/bridge/onboard.d.ts.map +1 -1
  17. package/lib/bridge/onboard.js +2 -2
  18. package/lib/bridge/onboard.js.map +1 -1
  19. package/lib/bridge/prepareTransaction.js +1 -1
  20. package/lib/bridge/prepareTransaction.js.map +1 -1
  21. package/lib/bridge/serialization.d.ts +4 -0
  22. package/lib/bridge/serialization.d.ts.map +1 -0
  23. package/lib/bridge/serialization.js +36 -0
  24. package/lib/bridge/serialization.js.map +1 -0
  25. package/lib/bridge/signOperation.js +2 -2
  26. package/lib/bridge/signOperation.js.map +1 -1
  27. package/lib/bridge/sync.d.ts.map +1 -1
  28. package/lib/bridge/sync.js +13 -5
  29. package/lib/bridge/sync.js.map +1 -1
  30. package/lib/bridge/transaction.js +1 -1
  31. package/lib/bridge/transaction.js.map +1 -1
  32. package/lib/common-logic/account/getBalance.d.ts +5 -1
  33. package/lib/common-logic/account/getBalance.d.ts.map +1 -1
  34. package/lib/common-logic/account/getBalance.js +2 -0
  35. package/lib/common-logic/account/getBalance.js.map +1 -1
  36. package/lib/common-logic/transaction/craftTransaction.js +1 -1
  37. package/lib/common-logic/transaction/craftTransaction.js.map +1 -1
  38. package/lib/common-logic/transaction/sign.d.ts +2 -2
  39. package/lib/common-logic/transaction/sign.d.ts.map +1 -1
  40. package/lib/common-logic/transaction/sign.js +20 -2
  41. package/lib/common-logic/transaction/sign.js.map +1 -1
  42. package/lib/network/gateway.d.ts +5 -1
  43. package/lib/network/gateway.d.ts.map +1 -1
  44. package/lib/network/gateway.js +4 -2
  45. package/lib/network/gateway.js.map +1 -1
  46. package/lib/test/fixtures.d.ts +5 -0
  47. package/lib/test/fixtures.d.ts.map +1 -0
  48. package/lib/test/fixtures.js +57 -0
  49. package/lib/test/fixtures.js.map +1 -0
  50. package/lib/types/bridge.d.ts +14 -2
  51. package/lib/types/bridge.d.ts.map +1 -1
  52. package/lib/types/errors.d.ts +6 -0
  53. package/lib/types/errors.d.ts.map +1 -1
  54. package/lib/types/errors.js +3 -1
  55. package/lib/types/errors.js.map +1 -1
  56. package/lib/types/index.d.ts +1 -0
  57. package/lib/types/index.d.ts.map +1 -1
  58. package/lib/types/index.js +1 -0
  59. package/lib/types/index.js.map +1 -1
  60. package/lib/types/signer.d.ts +5 -1
  61. package/lib/types/signer.d.ts.map +1 -1
  62. package/lib-es/bridge/estimateMaxSpendable.d.ts +2 -2
  63. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
  64. package/lib-es/bridge/estimateMaxSpendable.js +2 -3
  65. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
  66. package/lib-es/bridge/getTransactionStatus.d.ts +5 -3
  67. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
  68. package/lib-es/bridge/getTransactionStatus.js +26 -5
  69. package/lib-es/bridge/getTransactionStatus.js.map +1 -1
  70. package/lib-es/bridge/index.d.ts +2 -2
  71. package/lib-es/bridge/index.d.ts.map +1 -1
  72. package/lib-es/bridge/index.js +3 -3
  73. package/lib-es/bridge/index.js.map +1 -1
  74. package/lib-es/bridge/onboard.d.ts.map +1 -1
  75. package/lib-es/bridge/onboard.js +2 -2
  76. package/lib-es/bridge/onboard.js.map +1 -1
  77. package/lib-es/bridge/prepareTransaction.js +1 -1
  78. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  79. package/lib-es/bridge/serialization.d.ts +4 -0
  80. package/lib-es/bridge/serialization.d.ts.map +1 -0
  81. package/lib-es/bridge/serialization.js +32 -0
  82. package/lib-es/bridge/serialization.js.map +1 -0
  83. package/lib-es/bridge/signOperation.js +2 -2
  84. package/lib-es/bridge/signOperation.js.map +1 -1
  85. package/lib-es/bridge/sync.d.ts.map +1 -1
  86. package/lib-es/bridge/sync.js +13 -5
  87. package/lib-es/bridge/sync.js.map +1 -1
  88. package/lib-es/bridge/transaction.js +1 -1
  89. package/lib-es/bridge/transaction.js.map +1 -1
  90. package/lib-es/common-logic/account/getBalance.d.ts +5 -1
  91. package/lib-es/common-logic/account/getBalance.d.ts.map +1 -1
  92. package/lib-es/common-logic/account/getBalance.js +2 -0
  93. package/lib-es/common-logic/account/getBalance.js.map +1 -1
  94. package/lib-es/common-logic/transaction/craftTransaction.js +1 -1
  95. package/lib-es/common-logic/transaction/craftTransaction.js.map +1 -1
  96. package/lib-es/common-logic/transaction/sign.d.ts +2 -2
  97. package/lib-es/common-logic/transaction/sign.d.ts.map +1 -1
  98. package/lib-es/common-logic/transaction/sign.js +20 -2
  99. package/lib-es/common-logic/transaction/sign.js.map +1 -1
  100. package/lib-es/network/gateway.d.ts +5 -1
  101. package/lib-es/network/gateway.d.ts.map +1 -1
  102. package/lib-es/network/gateway.js +4 -2
  103. package/lib-es/network/gateway.js.map +1 -1
  104. package/lib-es/test/fixtures.d.ts +5 -0
  105. package/lib-es/test/fixtures.d.ts.map +1 -0
  106. package/lib-es/test/fixtures.js +49 -0
  107. package/lib-es/test/fixtures.js.map +1 -0
  108. package/lib-es/types/bridge.d.ts +14 -2
  109. package/lib-es/types/bridge.d.ts.map +1 -1
  110. package/lib-es/types/errors.d.ts +6 -0
  111. package/lib-es/types/errors.d.ts.map +1 -1
  112. package/lib-es/types/errors.js +2 -0
  113. package/lib-es/types/errors.js.map +1 -1
  114. package/lib-es/types/index.d.ts +1 -0
  115. package/lib-es/types/index.d.ts.map +1 -1
  116. package/lib-es/types/index.js +1 -0
  117. package/lib-es/types/index.js.map +1 -1
  118. package/lib-es/types/signer.d.ts +5 -1
  119. package/lib-es/types/signer.d.ts.map +1 -1
  120. package/package.json +6 -6
  121. package/src/bridge/estimateMaxSpendable.ts +6 -8
  122. package/src/bridge/getTransactionStatus.test.ts +84 -146
  123. package/src/bridge/getTransactionStatus.ts +42 -7
  124. package/src/bridge/index.ts +6 -5
  125. package/src/bridge/onboard.integ.test.ts +8 -31
  126. package/src/bridge/onboard.ts +3 -2
  127. package/src/bridge/prepareTransaction.ts +1 -1
  128. package/src/bridge/serialization.ts +44 -0
  129. package/src/bridge/signOperation.test.ts +24 -15
  130. package/src/bridge/signOperation.ts +2 -2
  131. package/src/bridge/sync.test.ts +4 -0
  132. package/src/bridge/sync.ts +17 -6
  133. package/src/bridge/transaction.ts +1 -1
  134. package/src/common-logic/account/getBalance.ts +12 -2
  135. package/src/common-logic/account/getBalance.unit.test.ts +7 -1
  136. package/src/common-logic/transaction/craftTransaction.ts +1 -1
  137. package/src/common-logic/transaction/sign.test.ts +83 -11
  138. package/src/common-logic/transaction/sign.ts +32 -6
  139. package/src/network/gateway.integ.test.ts +3 -6
  140. package/src/network/gateway.ts +10 -2
  141. package/src/test/fixtures.ts +53 -0
  142. package/src/types/bridge.ts +15 -2
  143. package/src/types/errors.ts +3 -0
  144. package/src/types/index.ts +1 -0
  145. package/src/types/signer.ts +5 -1
@@ -10,6 +10,7 @@ import {
10
10
  PreApprovalResult,
11
11
  } from "../types/onboard";
12
12
  import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
13
+ import type { CantonSignature } from "../types/signer";
13
14
 
14
15
  export type OnboardingPrepareResponse = {
15
16
  party_id: string;
@@ -33,6 +34,8 @@ export type OnboardingPrepareResponse = {
33
34
  };
34
35
  combined_hash: string;
35
36
  };
37
+ challenge_nonce?: string;
38
+ challenge_deadline?: number;
36
39
  };
37
40
 
38
41
  type OnboardingPrepareRequest = {
@@ -59,6 +62,7 @@ type OnboardingSubmitRequest = {
59
62
  prepare_request: OnboardingPrepareRequest;
60
63
  prepare_response: OnboardingPrepareResponse;
61
64
  signature: string;
65
+ application_signature?: string;
62
66
  };
63
67
 
64
68
  type OnboardingSubmitResponse = {
@@ -87,6 +91,7 @@ export type InstrumentBalance = {
87
91
  instrument_id: string;
88
92
  amount: string;
89
93
  locked: boolean;
94
+ utxo_count: number;
90
95
  };
91
96
 
92
97
  type PartyInfo = {
@@ -325,7 +330,7 @@ export async function submitOnboarding(
325
330
  currency: CryptoCurrency,
326
331
  publicKey: string,
327
332
  prepareResponse: OnboardingPrepareResponse,
328
- signature: string,
333
+ { signature, applicationSignature }: CantonSignature,
329
334
  ) {
330
335
  try {
331
336
  const { data } = await gatewayNetwork<OnboardingSubmitResponse, OnboardingSubmitRequest>({
@@ -338,6 +343,7 @@ export async function submitOnboarding(
338
343
  },
339
344
  prepare_response: prepareResponse,
340
345
  signature,
346
+ ...(applicationSignature ? { application_signature: applicationSignature } : {}),
341
347
  },
342
348
  });
343
349
  return data;
@@ -449,11 +455,13 @@ export async function prepareTapRequest(
449
455
  currency: CryptoCurrency,
450
456
  { partyId, amount = 1000000 }: PrepareTapRequest,
451
457
  ) {
458
+ const fixedPointAmount = BigInt(amount) * BigInt(10) ** BigInt(38);
459
+
452
460
  const { data } = await gatewayNetwork<PrepareTapResponse, { amount: string; type: string }>({
453
461
  method: "POST",
454
462
  url: `${getGatewayUrl(currency)}/v1/node/${getNodeId(currency)}/party/${partyId}/transaction/prepare`,
455
463
  data: {
456
- amount: amount.toString(),
464
+ amount: fixedPointAmount.toString(),
457
465
  type: TransactionType.TAP_REQUEST,
458
466
  },
459
467
  });
@@ -0,0 +1,53 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { Account } from "@ledgerhq/types-live";
3
+ import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
4
+ import { getDerivationScheme, runDerivationScheme } from "@ledgerhq/coin-framework/derivation";
5
+ import { createEmptyHistoryCache } from "@ledgerhq/coin-framework/account";
6
+
7
+ export const createMockCantonCurrency = (): CryptoCurrency => {
8
+ const mockCurrency = {
9
+ id: "canton_network",
10
+ name: "Canton",
11
+ type: "CryptoCurrency",
12
+ family: "canton",
13
+ units: [{ name: "Canton", code: "CANTON", magnitude: 38 }],
14
+ ticker: "CANTON",
15
+ scheme: "canton",
16
+ color: "#000000",
17
+ managerAppName: "Canton",
18
+ coinType: 6767,
19
+ explorerViews: [],
20
+ } satisfies CryptoCurrency;
21
+ return mockCurrency;
22
+ };
23
+
24
+ export const createMockAccount = (overrides: Partial<Account> = {}): Account => {
25
+ const currency = createMockCantonCurrency();
26
+ const derivationMode = "canton" as const;
27
+ const scheme = getDerivationScheme({ derivationMode, currency });
28
+ const freshAddressPath = runDerivationScheme(scheme, currency, { account: 0 });
29
+
30
+ return {
31
+ id: "js:2:canton_network:test-address:canton",
32
+ type: "Account",
33
+ used: true,
34
+ currency,
35
+ derivationMode,
36
+ index: 0,
37
+ freshAddress: "test_address",
38
+ freshAddressPath,
39
+ creationDate: new Date(),
40
+ lastSyncDate: new Date(),
41
+ balance: new BigNumber(0),
42
+ spendableBalance: new BigNumber(0),
43
+ seedIdentifier: "test_seed",
44
+ blockHeight: 0,
45
+ operationsCount: 0,
46
+ operations: [],
47
+ pendingOperations: [],
48
+ balanceHistoryCache: createEmptyHistoryCache(),
49
+ swapHistory: [],
50
+ subAccounts: [],
51
+ ...overrides,
52
+ };
53
+ };
@@ -48,6 +48,7 @@ export type Transaction = TransactionCommon & {
48
48
  fee: BigNumber | null | undefined;
49
49
  memo?: string;
50
50
  tokenId: string;
51
+ expireInSeconds?: number;
51
52
  };
52
53
 
53
54
  export type TransactionRaw = TransactionCommonRaw & {
@@ -55,10 +56,22 @@ export type TransactionRaw = TransactionCommonRaw & {
55
56
  fee: string | null | undefined;
56
57
  memo?: string;
57
58
  tokenId: string;
59
+ expireInSeconds?: number;
58
60
  };
59
61
 
60
62
  export type TransactionStatus = TransactionStatusCommon;
61
63
  export type TransactionStatusRaw = TransactionStatusCommonRaw;
62
64
 
63
- export type CantonAccount = Account;
64
- export type CantonAccountRaw = AccountRaw;
65
+ export type CantonResources = {
66
+ instrumentUtxoCounts: Record<string, number>;
67
+ };
68
+ export type CantonResourcesRaw = {
69
+ instrumentUtxoCounts: Record<string, number>;
70
+ };
71
+
72
+ export type CantonAccount = Account & {
73
+ cantonResources: CantonResources;
74
+ };
75
+ export type CantonAccountRaw = AccountRaw & {
76
+ cantonResources: CantonResourcesRaw;
77
+ };
@@ -1,3 +1,6 @@
1
1
  import { createCustomErrorClass } from "@ledgerhq/errors";
2
2
 
3
3
  export const SimulationError = createCustomErrorClass("SimulationError");
4
+
5
+ export const TooManyUtxosCritical = createCustomErrorClass("TooManyUtxosCritical");
6
+ export const TooManyUtxosWarning = createCustomErrorClass("TooManyUtxosWarning");
@@ -1,3 +1,4 @@
1
1
  export * from "./bridge";
2
+ export * from "./errors";
2
3
  export * from "./onboard";
3
4
  export * from "./signer";
@@ -4,7 +4,10 @@ export type CantonAddress = {
4
4
  path: string;
5
5
  };
6
6
 
7
- export type CantonSignature = string;
7
+ export type CantonSignature = {
8
+ signature: string;
9
+ applicationSignature?: string;
10
+ };
8
11
 
9
12
  export interface CantonPreparedTransaction {
10
13
  damlTransaction: Uint8Array;
@@ -15,6 +18,7 @@ export interface CantonPreparedTransaction {
15
18
 
16
19
  export interface CantonUntypedVersionedMessage {
17
20
  transactions: string[];
21
+ challenge?: string;
18
22
  }
19
23
 
20
24
  export interface CantonSigner {