@ledgerhq/coin-canton 0.9.0-nightly.1 → 0.9.0-nightly.3

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 (97) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +27 -0
  3. package/README.md +75 -0
  4. package/lib/bridge/deviceTransactionConfig.d.ts +1 -1
  5. package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -1
  6. package/lib/bridge/deviceTransactionConfig.js +1 -1
  7. package/lib/bridge/deviceTransactionConfig.js.map +1 -1
  8. package/lib/bridge/onboard.d.ts.map +1 -1
  9. package/lib/bridge/onboard.js +48 -22
  10. package/lib/bridge/onboard.js.map +1 -1
  11. package/lib/bridge/signOperation.d.ts.map +1 -1
  12. package/lib/bridge/signOperation.js +11 -4
  13. package/lib/bridge/signOperation.js.map +1 -1
  14. package/lib/common-logic/index.d.ts +1 -0
  15. package/lib/common-logic/index.d.ts.map +1 -1
  16. package/lib/common-logic/index.js +3 -1
  17. package/lib/common-logic/index.js.map +1 -1
  18. package/lib/common-logic/transaction/sign.d.ts +8 -0
  19. package/lib/common-logic/transaction/sign.d.ts.map +1 -0
  20. package/lib/common-logic/transaction/sign.js +45 -0
  21. package/lib/common-logic/transaction/sign.js.map +1 -0
  22. package/lib/common-logic/transaction/split.d.ts +9 -0
  23. package/lib/common-logic/transaction/split.d.ts.map +1 -0
  24. package/lib/common-logic/transaction/split.js +119 -0
  25. package/lib/common-logic/transaction/split.js.map +1 -0
  26. package/lib/common-logic/utils.js +2 -2
  27. package/lib/common-logic/utils.js.map +1 -1
  28. package/lib/network/gateway.d.ts +5 -1
  29. package/lib/network/gateway.d.ts.map +1 -1
  30. package/lib/network/gateway.js +6 -9
  31. package/lib/network/gateway.js.map +1 -1
  32. package/lib/test/cantonTestUtils.d.ts +4 -9
  33. package/lib/test/cantonTestUtils.d.ts.map +1 -1
  34. package/lib/test/cantonTestUtils.js +736 -27
  35. package/lib/test/cantonTestUtils.js.map +1 -1
  36. package/lib/types/signer.d.ts +15 -2
  37. package/lib/types/signer.d.ts.map +1 -1
  38. package/lib/types/transaction-proto.json +1238 -0
  39. package/lib-es/bridge/deviceTransactionConfig.d.ts +1 -1
  40. package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -1
  41. package/lib-es/bridge/deviceTransactionConfig.js +1 -1
  42. package/lib-es/bridge/deviceTransactionConfig.js.map +1 -1
  43. package/lib-es/bridge/onboard.d.ts.map +1 -1
  44. package/lib-es/bridge/onboard.js +49 -23
  45. package/lib-es/bridge/onboard.js.map +1 -1
  46. package/lib-es/bridge/signOperation.d.ts.map +1 -1
  47. package/lib-es/bridge/signOperation.js +11 -4
  48. package/lib-es/bridge/signOperation.js.map +1 -1
  49. package/lib-es/common-logic/index.d.ts +1 -0
  50. package/lib-es/common-logic/index.d.ts.map +1 -1
  51. package/lib-es/common-logic/index.js +1 -0
  52. package/lib-es/common-logic/index.js.map +1 -1
  53. package/lib-es/common-logic/transaction/sign.d.ts +8 -0
  54. package/lib-es/common-logic/transaction/sign.d.ts.map +1 -0
  55. package/lib-es/common-logic/transaction/sign.js +42 -0
  56. package/lib-es/common-logic/transaction/sign.js.map +1 -0
  57. package/lib-es/common-logic/transaction/split.d.ts +9 -0
  58. package/lib-es/common-logic/transaction/split.d.ts.map +1 -0
  59. package/lib-es/common-logic/transaction/split.js +83 -0
  60. package/lib-es/common-logic/transaction/split.js.map +1 -0
  61. package/lib-es/common-logic/utils.js +2 -2
  62. package/lib-es/common-logic/utils.js.map +1 -1
  63. package/lib-es/network/gateway.d.ts +5 -1
  64. package/lib-es/network/gateway.d.ts.map +1 -1
  65. package/lib-es/network/gateway.js +5 -10
  66. package/lib-es/network/gateway.js.map +1 -1
  67. package/lib-es/test/cantonTestUtils.d.ts +4 -9
  68. package/lib-es/test/cantonTestUtils.d.ts.map +1 -1
  69. package/lib-es/test/cantonTestUtils.js +697 -21
  70. package/lib-es/test/cantonTestUtils.js.map +1 -1
  71. package/lib-es/types/signer.d.ts +15 -2
  72. package/lib-es/types/signer.d.ts.map +1 -1
  73. package/lib-es/types/transaction-proto.json +1238 -0
  74. package/package.json +10 -7
  75. package/scripts/generate.js +261 -0
  76. package/src/bridge/deviceTransactionConfig.test.ts +14 -10
  77. package/src/bridge/deviceTransactionConfig.ts +2 -2
  78. package/src/bridge/getTransactionStatus.test.ts +19 -19
  79. package/src/bridge/onboard.integ.test.ts +0 -20
  80. package/src/bridge/onboard.ts +58 -33
  81. package/src/bridge/signOperation.test.ts +129 -0
  82. package/src/bridge/signOperation.ts +13 -6
  83. package/src/bridge/sync.integ.test.ts +157 -132
  84. package/src/common-logic/index.ts +1 -0
  85. package/src/common-logic/transaction/sign.test.ts +389 -0
  86. package/src/common-logic/transaction/sign.ts +59 -0
  87. package/src/common-logic/transaction/split.test.ts +50 -0
  88. package/src/common-logic/transaction/split.ts +101 -0
  89. package/src/common-logic/utils.test.ts +22 -30
  90. package/src/common-logic/utils.ts +2 -2
  91. package/src/network/gateway.integ.test.ts +5 -6
  92. package/src/network/gateway.ts +12 -10
  93. package/src/test/cantonTestUtils.ts +789 -24
  94. package/src/test/prepare-transfer-serialized.json +26 -0
  95. package/src/test/prepare-transfer.json +3298 -0
  96. package/src/types/signer.ts +21 -3
  97. package/src/types/transaction-proto.json +1238 -0
@@ -83,12 +83,9 @@ describe("gateway (devnet)", () => {
83
83
  const signature = keyPair.sign(prepareResponse.transactions.combined_hash);
84
84
 
85
85
  // WHEN
86
- const response = await submitOnboarding(
87
- mockCurrency,
88
- keyPair.publicKeyHex,
89
- prepareResponse,
86
+ const response = await submitOnboarding(mockCurrency, keyPair.publicKeyHex, prepareResponse, {
90
87
  signature,
91
- );
88
+ });
92
89
 
93
90
  // Save onboarded account for next tests that need a valid party ID
94
91
  onboardedAccount = {
@@ -107,6 +104,8 @@ describe("gateway (devnet)", () => {
107
104
  testIfPrepared(
108
105
  "should not throw when already onboarded",
109
106
  async () => {
107
+ // Add delay to ensure previous operations are complete
108
+ await new Promise(resolve => setTimeout(resolve, 10000));
110
109
  // GIVEN
111
110
  const { keyPair } = getOnboardedAccount();
112
111
  const signature = keyPair.sign(prepareResponse!.transactions.combined_hash);
@@ -116,7 +115,7 @@ describe("gateway (devnet)", () => {
116
115
  mockCurrency,
117
116
  keyPair.publicKeyHex,
118
117
  prepareResponse!,
119
- signature,
118
+ { signature },
120
119
  );
121
120
 
122
121
  // THEN
@@ -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 = {
@@ -283,7 +287,8 @@ export type OperationInfo =
283
287
  const getGatewayUrl = (currency: CryptoCurrency) => coinConfig.getCoinConfig(currency).gatewayUrl;
284
288
  const getNodeId = (currency: CryptoCurrency) =>
285
289
  coinConfig.getCoinConfig(currency).nodeId || "ledger-live-devnet";
286
- const getNetworkType = (currency: CryptoCurrency) => coinConfig.getCoinConfig(currency).networkType;
290
+ export const getNetworkType = (currency: CryptoCurrency) =>
291
+ coinConfig.getCoinConfig(currency).networkType;
287
292
 
288
293
  const gatewayNetwork = <T, U = unknown>(req: LiveNetworkRequest<U>) => {
289
294
  const API_KEY = getEnv("CANTON_API_KEY");
@@ -324,7 +329,7 @@ export async function submitOnboarding(
324
329
  currency: CryptoCurrency,
325
330
  publicKey: string,
326
331
  prepareResponse: OnboardingPrepareResponse,
327
- signature: string,
332
+ { signature, applicationSignature }: CantonSignature,
328
333
  ) {
329
334
  try {
330
335
  const { data } = await gatewayNetwork<OnboardingSubmitResponse, OnboardingSubmitRequest>({
@@ -337,6 +342,7 @@ export async function submitOnboarding(
337
342
  },
338
343
  prepare_response: prepareResponse,
339
344
  signature,
345
+ ...(applicationSignature ? { application_signature: applicationSignature } : {}),
340
346
  },
341
347
  });
342
348
  return data;
@@ -448,18 +454,13 @@ export async function prepareTapRequest(
448
454
  currency: CryptoCurrency,
449
455
  { partyId, amount = 1000000 }: PrepareTapRequest,
450
456
  ) {
451
- if (getNetworkType(currency) === "mainnet") {
452
- return {
453
- serialized: "",
454
- json: null,
455
- hash: "",
456
- };
457
- }
457
+ const fixedPointAmount = BigInt(amount) * BigInt(10) ** BigInt(38);
458
+
458
459
  const { data } = await gatewayNetwork<PrepareTapResponse, { amount: string; type: string }>({
459
460
  method: "POST",
460
461
  url: `${getGatewayUrl(currency)}/v1/node/${getNodeId(currency)}/party/${partyId}/transaction/prepare`,
461
462
  data: {
462
- amount: amount.toString(),
463
+ amount: fixedPointAmount.toString(),
463
464
  type: TransactionType.TAP_REQUEST,
464
465
  },
465
466
  });
@@ -505,6 +506,7 @@ export async function prepareTransferRequest(
505
506
  url: `${getGatewayUrl(currency)}/v1/node/${getNodeId(currency)}/party/${partyId}/transaction/prepare`,
506
507
  data: params,
507
508
  });
509
+
508
510
  return data;
509
511
  }
510
512