@ledgerhq/coin-canton 0.7.0-nightly.1 → 0.7.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 (117) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +23 -0
  3. package/lib/api/lastBlock.integ.test.js +0 -15
  4. package/lib/api/lastBlock.integ.test.js.map +1 -1
  5. package/lib/bridge/getTransactionStatus.test.d.ts +2 -0
  6. package/lib/bridge/getTransactionStatus.test.d.ts.map +1 -0
  7. package/lib/bridge/getTransactionStatus.test.js +365 -0
  8. package/lib/bridge/getTransactionStatus.test.js.map +1 -0
  9. package/lib/bridge/index.d.ts.map +1 -1
  10. package/lib/bridge/index.js +2 -5
  11. package/lib/bridge/index.js.map +1 -1
  12. package/lib/bridge/onboard.d.ts +11 -6
  13. package/lib/bridge/onboard.d.ts.map +1 -1
  14. package/lib/bridge/onboard.integ.test.js +49 -27
  15. package/lib/bridge/onboard.integ.test.js.map +1 -1
  16. package/lib/bridge/onboard.js +45 -152
  17. package/lib/bridge/onboard.js.map +1 -1
  18. package/lib/bridge/signOperation.d.ts.map +1 -1
  19. package/lib/bridge/signOperation.js +5 -5
  20. package/lib/bridge/signOperation.js.map +1 -1
  21. package/lib/bridge/sync.d.ts +3 -2
  22. package/lib/bridge/sync.d.ts.map +1 -1
  23. package/lib/bridge/sync.integ.test.js +31 -14
  24. package/lib/bridge/sync.integ.test.js.map +1 -1
  25. package/lib/bridge/sync.js +71 -57
  26. package/lib/bridge/sync.js.map +1 -1
  27. package/lib/common-logic/utils.d.ts.map +1 -1
  28. package/lib/common-logic/utils.js +3 -1
  29. package/lib/common-logic/utils.js.map +1 -1
  30. package/lib/common-logic/utils.test.d.ts +2 -0
  31. package/lib/common-logic/utils.test.d.ts.map +1 -0
  32. package/lib/common-logic/utils.test.js +104 -0
  33. package/lib/common-logic/utils.test.js.map +1 -0
  34. package/lib/config.d.ts +1 -1
  35. package/lib/config.d.ts.map +1 -1
  36. package/lib/network/gateway.d.ts +9 -9
  37. package/lib/network/gateway.d.ts.map +1 -1
  38. package/lib/network/gateway.integ.test.js +31 -17
  39. package/lib/network/gateway.integ.test.js.map +1 -1
  40. package/lib/network/gateway.js +33 -15
  41. package/lib/network/gateway.js.map +1 -1
  42. package/lib/types/bridge.d.ts +6 -16
  43. package/lib/types/bridge.d.ts.map +1 -1
  44. package/lib/types/onboard.d.ts +5 -5
  45. package/lib/types/onboard.d.ts.map +1 -1
  46. package/lib/types/onboard.js +10 -10
  47. package/lib/types/onboard.js.map +1 -1
  48. package/lib-es/api/lastBlock.integ.test.js +0 -15
  49. package/lib-es/api/lastBlock.integ.test.js.map +1 -1
  50. package/lib-es/bridge/getTransactionStatus.test.d.ts +2 -0
  51. package/lib-es/bridge/getTransactionStatus.test.d.ts.map +1 -0
  52. package/lib-es/bridge/getTransactionStatus.test.js +360 -0
  53. package/lib-es/bridge/getTransactionStatus.test.js.map +1 -0
  54. package/lib-es/bridge/index.d.ts.map +1 -1
  55. package/lib-es/bridge/index.js +3 -6
  56. package/lib-es/bridge/index.js.map +1 -1
  57. package/lib-es/bridge/onboard.d.ts +11 -6
  58. package/lib-es/bridge/onboard.d.ts.map +1 -1
  59. package/lib-es/bridge/onboard.integ.test.js +37 -15
  60. package/lib-es/bridge/onboard.integ.test.js.map +1 -1
  61. package/lib-es/bridge/onboard.js +44 -152
  62. package/lib-es/bridge/onboard.js.map +1 -1
  63. package/lib-es/bridge/signOperation.d.ts.map +1 -1
  64. package/lib-es/bridge/signOperation.js +5 -5
  65. package/lib-es/bridge/signOperation.js.map +1 -1
  66. package/lib-es/bridge/sync.d.ts +3 -2
  67. package/lib-es/bridge/sync.d.ts.map +1 -1
  68. package/lib-es/bridge/sync.integ.test.js +26 -9
  69. package/lib-es/bridge/sync.integ.test.js.map +1 -1
  70. package/lib-es/bridge/sync.js +71 -56
  71. package/lib-es/bridge/sync.js.map +1 -1
  72. package/lib-es/common-logic/utils.d.ts.map +1 -1
  73. package/lib-es/common-logic/utils.js +3 -1
  74. package/lib-es/common-logic/utils.js.map +1 -1
  75. package/lib-es/common-logic/utils.test.d.ts +2 -0
  76. package/lib-es/common-logic/utils.test.d.ts.map +1 -0
  77. package/lib-es/common-logic/utils.test.js +99 -0
  78. package/lib-es/common-logic/utils.test.js.map +1 -0
  79. package/lib-es/config.d.ts +1 -1
  80. package/lib-es/config.d.ts.map +1 -1
  81. package/lib-es/network/gateway.d.ts +9 -9
  82. package/lib-es/network/gateway.d.ts.map +1 -1
  83. package/lib-es/network/gateway.integ.test.js +31 -17
  84. package/lib-es/network/gateway.integ.test.js.map +1 -1
  85. package/lib-es/network/gateway.js +33 -15
  86. package/lib-es/network/gateway.js.map +1 -1
  87. package/lib-es/types/bridge.d.ts +6 -16
  88. package/lib-es/types/bridge.d.ts.map +1 -1
  89. package/lib-es/types/onboard.d.ts +5 -5
  90. package/lib-es/types/onboard.d.ts.map +1 -1
  91. package/lib-es/types/onboard.js +9 -9
  92. package/lib-es/types/onboard.js.map +1 -1
  93. package/package.json +5 -4
  94. package/src/api/lastBlock.integ.test.ts +0 -18
  95. package/src/bridge/getTransactionStatus.test.ts +446 -0
  96. package/src/bridge/index.ts +3 -6
  97. package/src/bridge/onboard.integ.test.ts +44 -31
  98. package/src/bridge/onboard.ts +61 -209
  99. package/src/bridge/signOperation.ts +5 -6
  100. package/src/bridge/sync.integ.test.ts +30 -10
  101. package/src/bridge/sync.ts +87 -72
  102. package/src/common-logic/utils.test.ts +108 -0
  103. package/src/common-logic/utils.ts +4 -1
  104. package/src/config.ts +1 -1
  105. package/src/network/gateway.integ.test.ts +48 -21
  106. package/src/network/gateway.ts +49 -34
  107. package/src/types/bridge.ts +8 -19
  108. package/src/types/onboard.ts +5 -5
  109. package/lib/bridge/serialization.d.ts +0 -4
  110. package/lib/bridge/serialization.d.ts.map +0 -1
  111. package/lib/bridge/serialization.js +0 -31
  112. package/lib/bridge/serialization.js.map +0 -1
  113. package/lib-es/bridge/serialization.d.ts +0 -4
  114. package/lib-es/bridge/serialization.d.ts.map +0 -1
  115. package/lib-es/bridge/serialization.js +0 -27
  116. package/lib-es/bridge/serialization.js.map +0 -1
  117. package/src/bridge/serialization.ts +0 -36
@@ -1 +1 @@
1
- {"version":3,"file":"onboard.d.ts","sourceRoot":"","sources":["../../src/types/onboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,oBAAY,aAAa;IACvB,IAAI,IAAA;IACJ,OAAO,IAAA;IACP,IAAI,IAAA;IACJ,MAAM,IAAA;IACN,OAAO,IAAA;IACP,KAAK,IAAA;CACN;AAED,oBAAY,iBAAiB;IAC3B,IAAI,IAAA;IACJ,OAAO,IAAA;IACP,IAAI,IAAA;IACJ,MAAM,IAAA;IACN,OAAO,IAAA;IACP,KAAK,IAAA;CACN;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE,aAAa,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,MAAM,EAAE,iBAAiB,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF;;;GAGG;AAEH,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,gCAAgC,CAAC;IACvC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,0BAA0B;IACzC,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,GAAG,CAAC;IACV,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,wBAAwB;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,yBAAyB;IACxC,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,OAAO,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;CAClB"}
1
+ {"version":3,"file":"onboard.d.ts","sourceRoot":"","sources":["../../src/types/onboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,oBAAY,aAAa;IACvB,IAAI,IAAA;IACJ,OAAO,IAAA;IACP,IAAI,IAAA;IACJ,MAAM,IAAA;IACN,OAAO,IAAA;IACP,KAAK,IAAA;CACN;AAED,oBAAY,eAAe;IACzB,IAAI,IAAA;IACJ,OAAO,IAAA;IACP,IAAI,IAAA;IACJ,MAAM,IAAA;IACN,OAAO,IAAA;IACP,KAAK,IAAA;CACN;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE,aAAa,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,MAAM,EAAE,eAAe,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF;;;GAGG;AAEH,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,gCAAgC,CAAC;IACvC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,0BAA0B;IACzC,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,GAAG,CAAC;IACV,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,wBAAwB;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,yBAAyB;IACxC,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,OAAO,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;CAClB"}
@@ -7,13 +7,13 @@ export var OnboardStatus;
7
7
  OnboardStatus[OnboardStatus["SUCCESS"] = 4] = "SUCCESS";
8
8
  OnboardStatus[OnboardStatus["ERROR"] = 5] = "ERROR";
9
9
  })(OnboardStatus || (OnboardStatus = {}));
10
- export var PreApprovalStatus;
11
- (function (PreApprovalStatus) {
12
- PreApprovalStatus[PreApprovalStatus["INIT"] = 0] = "INIT";
13
- PreApprovalStatus[PreApprovalStatus["PREPARE"] = 1] = "PREPARE";
14
- PreApprovalStatus[PreApprovalStatus["SIGN"] = 2] = "SIGN";
15
- PreApprovalStatus[PreApprovalStatus["SUBMIT"] = 3] = "SUBMIT";
16
- PreApprovalStatus[PreApprovalStatus["SUCCESS"] = 4] = "SUCCESS";
17
- PreApprovalStatus[PreApprovalStatus["ERROR"] = 5] = "ERROR";
18
- })(PreApprovalStatus || (PreApprovalStatus = {}));
10
+ export var AuthorizeStatus;
11
+ (function (AuthorizeStatus) {
12
+ AuthorizeStatus[AuthorizeStatus["INIT"] = 0] = "INIT";
13
+ AuthorizeStatus[AuthorizeStatus["PREPARE"] = 1] = "PREPARE";
14
+ AuthorizeStatus[AuthorizeStatus["SIGN"] = 2] = "SIGN";
15
+ AuthorizeStatus[AuthorizeStatus["SUBMIT"] = 3] = "SUBMIT";
16
+ AuthorizeStatus[AuthorizeStatus["SUCCESS"] = 4] = "SUCCESS";
17
+ AuthorizeStatus[AuthorizeStatus["ERROR"] = 5] = "ERROR";
18
+ })(AuthorizeStatus || (AuthorizeStatus = {}));
19
19
  //# sourceMappingURL=onboard.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"onboard.js","sourceRoot":"","sources":["../../src/types/onboard.ts"],"names":[],"mappings":"AAEA,MAAM,CAAN,IAAY,aAOX;AAPD,WAAY,aAAa;IACvB,iDAAI,CAAA;IACJ,uDAAO,CAAA;IACP,iDAAI,CAAA;IACJ,qDAAM,CAAA;IACN,uDAAO,CAAA;IACP,mDAAK,CAAA;AACP,CAAC,EAPW,aAAa,KAAb,aAAa,QAOxB;AAED,MAAM,CAAN,IAAY,iBAOX;AAPD,WAAY,iBAAiB;IAC3B,yDAAI,CAAA;IACJ,+DAAO,CAAA;IACP,yDAAI,CAAA;IACJ,6DAAM,CAAA;IACN,+DAAO,CAAA;IACP,2DAAK,CAAA;AACP,CAAC,EAPW,iBAAiB,KAAjB,iBAAiB,QAO5B"}
1
+ {"version":3,"file":"onboard.js","sourceRoot":"","sources":["../../src/types/onboard.ts"],"names":[],"mappings":"AAEA,MAAM,CAAN,IAAY,aAOX;AAPD,WAAY,aAAa;IACvB,iDAAI,CAAA;IACJ,uDAAO,CAAA;IACP,iDAAI,CAAA;IACJ,qDAAM,CAAA;IACN,uDAAO,CAAA;IACP,mDAAK,CAAA;AACP,CAAC,EAPW,aAAa,KAAb,aAAa,QAOxB;AAED,MAAM,CAAN,IAAY,eAOX;AAPD,WAAY,eAAe;IACzB,qDAAI,CAAA;IACJ,2DAAO,CAAA;IACP,qDAAI,CAAA;IACJ,yDAAM,CAAA;IACN,2DAAO,CAAA;IACP,uDAAK,CAAA;AACP,CAAC,EAPW,eAAe,KAAf,eAAe,QAO1B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/coin-canton",
3
- "version": "0.7.0-nightly.1",
3
+ "version": "0.7.0-nightly.3",
4
4
  "description": "Canton coin integration",
5
5
  "keywords": [
6
6
  "Ledger",
@@ -101,12 +101,13 @@
101
101
  "bignumber.js": "^9.1.2",
102
102
  "invariant": "^2.2.4",
103
103
  "rxjs": "^7.8.1",
104
- "@ledgerhq/coin-framework": "^6.6.0-nightly.1",
105
- "@ledgerhq/cryptoassets": "^13.30.0-nightly.0",
104
+ "@ledgerhq/coin-framework": "^6.6.0-nightly.2",
105
+ "@ledgerhq/cryptoassets": "^13.30.0-nightly.1",
106
106
  "@ledgerhq/devices": "8.6.0",
107
107
  "@ledgerhq/errors": "^6.26.0-nightly.0",
108
108
  "@ledgerhq/live-env": "^2.17.0",
109
109
  "@ledgerhq/live-network": "^2.0.18",
110
+ "@ledgerhq/logs": "^6.13.0",
110
111
  "@ledgerhq/types-live": "^6.86.0-nightly.0"
111
112
  },
112
113
  "devDependencies": {
@@ -117,7 +118,7 @@
117
118
  "jest": "^29.7.0",
118
119
  "ts-jest": "^29.1.1",
119
120
  "typescript": "^5.4.5",
120
- "@ledgerhq/types-cryptoassets": "^7.28.0-nightly.0",
121
+ "@ledgerhq/types-cryptoassets": "^7.28.0-nightly.1",
121
122
  "@ledgerhq/disable-network-setup": "^0.0.0"
122
123
  },
123
124
  "scripts": {
@@ -1,26 +1,8 @@
1
1
  import { AlpacaApi } from "@ledgerhq/coin-framework/lib/api/types";
2
2
  import { createApi } from ".";
3
- import { CantonCoinConfig } from "../config";
4
3
 
5
4
  let api: AlpacaApi;
6
5
 
7
- describe.skip("localnet", () => {
8
- beforeAll(() => {
9
- api = createApi({
10
- nodeUrl: "http://localhost:2975/v2",
11
- nativeInstrumentId: "Amulet",
12
- networkType: "localnet",
13
- } satisfies Partial<CantonCoinConfig>);
14
- });
15
-
16
- describe("lastBlock", () => {
17
- it("should return ledger end", async () => {
18
- const lastBlock = await api.lastBlock();
19
- expect(lastBlock.height).toBeGreaterThan(0);
20
- });
21
- });
22
- });
23
-
24
6
  describe.skip("devnet", () => {
25
7
  beforeAll(() => {
26
8
  api = createApi({
@@ -0,0 +1,446 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { Account } from "@ledgerhq/types-live";
3
+ import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
4
+ import {
5
+ AmountRequired,
6
+ FeeNotLoaded,
7
+ FeeRequired,
8
+ FeeTooHigh,
9
+ InvalidAddress,
10
+ InvalidAddressBecauseDestinationIsAlsoSource,
11
+ NotEnoughBalanceBecauseDestinationNotCreated,
12
+ NotEnoughSpendableBalance,
13
+ RecipientRequired,
14
+ } from "@ledgerhq/errors";
15
+ import { getTransactionStatus } from "./getTransactionStatus";
16
+ import { Transaction } from "../types";
17
+ import coinConfig from "../config";
18
+
19
+ // Mock the coin config
20
+ jest.mock("../config", () => ({
21
+ getCoinConfig: jest.fn(),
22
+ }));
23
+
24
+ const mockCoinConfig = jest.mocked(coinConfig);
25
+
26
+ describe("getTransactionStatus", () => {
27
+ const mockCurrency: CryptoCurrency = {
28
+ id: "canton_network",
29
+ name: "Canton Network",
30
+ family: "canton",
31
+ units: [
32
+ {
33
+ name: "Canton",
34
+ code: "CANTON",
35
+ magnitude: 8,
36
+ },
37
+ ],
38
+ ticker: "CANTON",
39
+ scheme: "canton",
40
+ color: "#000000",
41
+ type: "CryptoCurrency",
42
+ managerAppName: "Canton",
43
+ coinType: 0,
44
+ disableCountervalue: false,
45
+ delisted: false,
46
+ keywords: ["canton"],
47
+ explorerViews: [],
48
+ terminated: {
49
+ link: "",
50
+ },
51
+ };
52
+
53
+ const mockAccount: Account = {
54
+ id: "test-account-id",
55
+ seedIdentifier: "test-seed-identifier",
56
+ currency: mockCurrency,
57
+ balance: new BigNumber(1000), // 1000 units
58
+ spendableBalance: new BigNumber(1000),
59
+ freshAddress: "test::123",
60
+ freshAddressPath: "44'/60'/0'/0/0",
61
+ index: 0,
62
+ derivationMode: "canton",
63
+ used: true,
64
+ operations: [],
65
+ pendingOperations: [],
66
+ lastSyncDate: new Date(),
67
+ creationDate: new Date(),
68
+ operationsCount: 0,
69
+ blockHeight: 100,
70
+ balanceHistoryCache: {
71
+ HOUR: { latestDate: null, balances: [] },
72
+ DAY: { latestDate: null, balances: [] },
73
+ WEEK: { latestDate: null, balances: [] },
74
+ },
75
+ swapHistory: [],
76
+ nfts: [],
77
+ subAccounts: [],
78
+ type: "Account",
79
+ };
80
+
81
+ beforeEach(() => {
82
+ jest.clearAllMocks();
83
+ mockCoinConfig.getCoinConfig.mockReturnValue({
84
+ minReserve: 100, // 100 units minimum reserve
85
+ networkType: "mainnet",
86
+ status: { type: "active" },
87
+ nativeInstrumentId: "Amulet",
88
+ });
89
+ });
90
+
91
+ describe("fee validation", () => {
92
+ it("should return FeeNotLoaded error when fee is not provided", async () => {
93
+ const transaction: Transaction = {
94
+ family: "canton",
95
+ amount: new BigNumber(100),
96
+ recipient: "valid::123",
97
+ fee: null,
98
+ tokenId: "",
99
+ };
100
+
101
+ const result = await getTransactionStatus(mockAccount, transaction);
102
+
103
+ expect(result.errors.fee).toBeInstanceOf(FeeNotLoaded);
104
+ expect(result.warnings).toEqual({});
105
+ });
106
+
107
+ it("should return FeeRequired error when fee is zero", async () => {
108
+ const transaction: Transaction = {
109
+ family: "canton",
110
+ amount: new BigNumber(100),
111
+ recipient: "valid::123",
112
+ fee: new BigNumber(0),
113
+ tokenId: "",
114
+ };
115
+
116
+ const result = await getTransactionStatus(mockAccount, transaction);
117
+
118
+ expect(result.errors.fee).toBeInstanceOf(FeeRequired);
119
+ expect(result.warnings).toEqual({});
120
+ });
121
+
122
+ it("should add FeeTooHigh warning when fee is more than 10 times the amount", async () => {
123
+ const transaction: Transaction = {
124
+ family: "canton",
125
+ amount: new BigNumber(100), // Use larger amount to avoid balance issues
126
+ recipient: "valid::123",
127
+ fee: new BigNumber(1500), // 15x the amount
128
+ tokenId: "",
129
+ };
130
+
131
+ const result = await getTransactionStatus(mockAccount, transaction);
132
+
133
+ expect(result.warnings.feeTooHigh).toBeInstanceOf(FeeTooHigh);
134
+ // Don't check for empty errors since there might be balance issues
135
+ });
136
+
137
+ it("should not add FeeTooHigh warning when fee is reasonable", async () => {
138
+ const transaction: Transaction = {
139
+ family: "canton",
140
+ amount: new BigNumber(100),
141
+ recipient: "valid::123",
142
+ fee: new BigNumber(10), // 0.1x the amount
143
+ tokenId: "",
144
+ };
145
+
146
+ const result = await getTransactionStatus(mockAccount, transaction);
147
+
148
+ expect(result.warnings).toEqual({});
149
+ expect(result.errors).toEqual({});
150
+ });
151
+ });
152
+
153
+ describe("balance validation", () => {
154
+ it("should return NotEnoughSpendableBalance error when total spent exceeds balance minus reserve", async () => {
155
+ const transaction: Transaction = {
156
+ family: "canton",
157
+ amount: new BigNumber(950), // 950 + 10 fee = 960, but balance is 1000 and reserve is 100
158
+ recipient: "valid::123",
159
+ fee: new BigNumber(10),
160
+ tokenId: "",
161
+ };
162
+
163
+ const result = await getTransactionStatus(mockAccount, transaction);
164
+
165
+ expect(result.errors.amount).toBeInstanceOf(NotEnoughSpendableBalance);
166
+ });
167
+
168
+ it("should return NotEnoughBalanceBecauseDestinationNotCreated error when amount is below reserve", async () => {
169
+ const transaction: Transaction = {
170
+ family: "canton",
171
+ amount: new BigNumber(50), // Below reserve amount of 100
172
+ recipient: "valid::123",
173
+ fee: new BigNumber(10),
174
+ tokenId: "",
175
+ };
176
+
177
+ const result = await getTransactionStatus(mockAccount, transaction);
178
+
179
+ expect(result.errors.amount).toBeInstanceOf(NotEnoughBalanceBecauseDestinationNotCreated);
180
+ });
181
+
182
+ it("should pass balance validation when transaction is within limits", async () => {
183
+ const transaction: Transaction = {
184
+ family: "canton",
185
+ amount: new BigNumber(800), // 800 + 10 fee = 810, balance is 1000, reserve is 100, so 900 available
186
+ recipient: "valid::123",
187
+ fee: new BigNumber(10),
188
+ tokenId: "",
189
+ };
190
+
191
+ const result = await getTransactionStatus(mockAccount, transaction);
192
+
193
+ expect(result.errors.amount).toBeUndefined();
194
+ });
195
+ });
196
+
197
+ describe("recipient validation", () => {
198
+ it("should return RecipientRequired error when recipient is missing", async () => {
199
+ const transaction: Transaction = {
200
+ family: "canton",
201
+ amount: new BigNumber(100),
202
+ recipient: "",
203
+ fee: new BigNumber(10),
204
+ tokenId: "",
205
+ };
206
+
207
+ const result = await getTransactionStatus(mockAccount, transaction);
208
+
209
+ expect(result.errors.recipient).toBeInstanceOf(RecipientRequired);
210
+ });
211
+
212
+ it("should return InvalidAddressBecauseDestinationIsAlsoSource error when sending to self", async () => {
213
+ const transaction: Transaction = {
214
+ family: "canton",
215
+ amount: new BigNumber(100),
216
+ recipient: "test::123", // Same as account.freshAddress
217
+ fee: new BigNumber(10),
218
+ tokenId: "",
219
+ };
220
+
221
+ const result = await getTransactionStatus(mockAccount, transaction);
222
+
223
+ expect(result.errors.recipient).toBeInstanceOf(InvalidAddressBecauseDestinationIsAlsoSource);
224
+ });
225
+
226
+ it("should return InvalidAddress error when recipient is invalid", async () => {
227
+ const transaction: Transaction = {
228
+ family: "canton",
229
+ amount: new BigNumber(100),
230
+ recipient: "invalid-address",
231
+ fee: new BigNumber(10),
232
+ tokenId: "",
233
+ };
234
+
235
+ const result = await getTransactionStatus(mockAccount, transaction);
236
+
237
+ expect(result.errors.recipient).toBeInstanceOf(InvalidAddress);
238
+ });
239
+
240
+ it("should pass recipient validation when recipient is valid", async () => {
241
+ const transaction: Transaction = {
242
+ family: "canton",
243
+ amount: new BigNumber(100),
244
+ recipient: "valid::456",
245
+ fee: new BigNumber(10),
246
+ tokenId: "",
247
+ };
248
+
249
+ const result = await getTransactionStatus(mockAccount, transaction);
250
+
251
+ expect(result.errors.recipient).toBeUndefined();
252
+ });
253
+ });
254
+
255
+ describe("amount validation", () => {
256
+ it("should return AmountRequired error when amount is zero", async () => {
257
+ // Create a scenario where there are no other amount errors
258
+ // Use a high balance and amount above reserve to avoid other amount errors
259
+ const accountWithHighBalance = {
260
+ ...mockAccount,
261
+ balance: new BigNumber(10000), // High balance to avoid balance errors
262
+ };
263
+
264
+ // Set a high reserve to avoid the NotEnoughBalanceBecauseDestinationNotCreated error
265
+ mockCoinConfig.getCoinConfig.mockReturnValue({
266
+ minReserve: 0, // Set reserve to 0 to avoid reserve-related errors
267
+ networkType: "mainnet",
268
+ status: { type: "active" },
269
+ nativeInstrumentId: "Amulet",
270
+ });
271
+
272
+ const transaction: Transaction = {
273
+ family: "canton",
274
+ amount: new BigNumber(0),
275
+ recipient: "valid::123",
276
+ fee: new BigNumber(10),
277
+ tokenId: "",
278
+ };
279
+
280
+ const result = await getTransactionStatus(accountWithHighBalance, transaction);
281
+
282
+ expect(result.errors.amount).toBeInstanceOf(AmountRequired);
283
+ });
284
+
285
+ it("should not return AmountRequired error when amount is positive", async () => {
286
+ const transaction: Transaction = {
287
+ family: "canton",
288
+ amount: new BigNumber(100),
289
+ recipient: "valid::123",
290
+ fee: new BigNumber(10),
291
+ tokenId: "",
292
+ };
293
+
294
+ const result = await getTransactionStatus(mockAccount, transaction);
295
+
296
+ expect(result.errors.amount).toBeUndefined();
297
+ });
298
+ });
299
+
300
+ describe("return values", () => {
301
+ it("should return correct estimatedFees, amount, and totalSpent", async () => {
302
+ const transaction: Transaction = {
303
+ family: "canton",
304
+ amount: new BigNumber(100),
305
+ recipient: "valid::123",
306
+ fee: new BigNumber(10),
307
+ tokenId: "",
308
+ };
309
+
310
+ const result = await getTransactionStatus(mockAccount, transaction);
311
+
312
+ expect(result.estimatedFees).toEqual(new BigNumber(10));
313
+ expect(result.amount).toEqual(new BigNumber(100));
314
+ expect(result.totalSpent).toEqual(new BigNumber(110));
315
+ });
316
+
317
+ it("should return empty errors and warnings when transaction is valid", async () => {
318
+ const transaction: Transaction = {
319
+ family: "canton",
320
+ amount: new BigNumber(100),
321
+ recipient: "valid::123",
322
+ fee: new BigNumber(10),
323
+ tokenId: "",
324
+ };
325
+
326
+ const result = await getTransactionStatus(mockAccount, transaction);
327
+
328
+ expect(result.errors).toEqual({});
329
+ expect(result.warnings).toEqual({});
330
+ });
331
+ });
332
+
333
+ describe("edge cases", () => {
334
+ it("should handle account with zero balance", async () => {
335
+ const accountWithZeroBalance = {
336
+ ...mockAccount,
337
+ balance: new BigNumber(0),
338
+ };
339
+
340
+ const transaction: Transaction = {
341
+ family: "canton",
342
+ amount: new BigNumber(50),
343
+ recipient: "valid::123",
344
+ fee: new BigNumber(10),
345
+ tokenId: "",
346
+ };
347
+
348
+ const result = await getTransactionStatus(accountWithZeroBalance, transaction);
349
+
350
+ expect(result.errors.amount).toBeInstanceOf(NotEnoughSpendableBalance);
351
+ });
352
+
353
+ it("should handle account with balance exactly equal to reserve", async () => {
354
+ const accountWithReserveBalance = {
355
+ ...mockAccount,
356
+ balance: new BigNumber(100), // Exactly equal to reserve
357
+ };
358
+
359
+ const transaction: Transaction = {
360
+ family: "canton",
361
+ amount: new BigNumber(50),
362
+ recipient: "valid::123",
363
+ fee: new BigNumber(10),
364
+ tokenId: "",
365
+ };
366
+
367
+ const result = await getTransactionStatus(accountWithReserveBalance, transaction);
368
+
369
+ expect(result.errors.amount).toBeInstanceOf(NotEnoughSpendableBalance);
370
+ });
371
+
372
+ it("should handle zero reserve amount", async () => {
373
+ mockCoinConfig.getCoinConfig.mockReturnValue({
374
+ minReserve: 0,
375
+ networkType: "mainnet",
376
+ status: { type: "active" },
377
+ nativeInstrumentId: "Amulet",
378
+ });
379
+
380
+ const transaction: Transaction = {
381
+ family: "canton",
382
+ amount: new BigNumber(50),
383
+ recipient: "valid::123",
384
+ fee: new BigNumber(10),
385
+ tokenId: "",
386
+ };
387
+
388
+ const result = await getTransactionStatus(mockAccount, transaction);
389
+
390
+ expect(result.errors.amount).toBeUndefined();
391
+ });
392
+
393
+ it("should handle undefined reserve amount", async () => {
394
+ mockCoinConfig.getCoinConfig.mockReturnValue({
395
+ networkType: "mainnet",
396
+ status: { type: "active" },
397
+ nativeInstrumentId: "Amulet",
398
+ });
399
+
400
+ const transaction: Transaction = {
401
+ family: "canton",
402
+ amount: new BigNumber(50),
403
+ recipient: "valid::123",
404
+ fee: new BigNumber(10),
405
+ tokenId: "",
406
+ };
407
+
408
+ const result = await getTransactionStatus(mockAccount, transaction);
409
+
410
+ expect(result.errors.amount).toBeUndefined();
411
+ });
412
+ });
413
+
414
+ describe("multiple validation errors", () => {
415
+ it("should return multiple errors when multiple validations fail", async () => {
416
+ const transaction: Transaction = {
417
+ family: "canton",
418
+ amount: new BigNumber(0), // AmountRequired
419
+ recipient: "", // RecipientRequired
420
+ fee: null, // FeeNotLoaded
421
+ tokenId: "",
422
+ };
423
+
424
+ const result = await getTransactionStatus(mockAccount, transaction);
425
+
426
+ expect(result.errors.amount).toBeInstanceOf(AmountRequired);
427
+ expect(result.errors.recipient).toBeInstanceOf(RecipientRequired);
428
+ expect(result.errors.fee).toBeInstanceOf(FeeNotLoaded);
429
+ });
430
+
431
+ it("should return both errors and warnings", async () => {
432
+ const transaction: Transaction = {
433
+ family: "canton",
434
+ amount: new BigNumber(5), // Small amount
435
+ recipient: "valid::123",
436
+ fee: new BigNumber(100), // High fee relative to amount
437
+ tokenId: "",
438
+ };
439
+
440
+ const result = await getTransactionStatus(mockAccount, transaction);
441
+
442
+ expect(result.warnings.feeTooHigh).toBeInstanceOf(FeeTooHigh);
443
+ expect(result.errors.amount).toBeInstanceOf(NotEnoughBalanceBecauseDestinationNotCreated);
444
+ });
445
+ });
446
+ });
@@ -18,10 +18,9 @@ import { estimateMaxSpendable } from "./estimateMaxSpendable";
18
18
  import { getTransactionStatus } from "./getTransactionStatus";
19
19
  import { prepareTransaction } from "./prepareTransaction";
20
20
  import { buildSignOperation } from "./signOperation";
21
- import { getAccountShape } from "./sync";
21
+ import { makeGetAccountShape } from "./sync";
22
22
  import { updateTransaction } from "./updateTransaction";
23
23
  import { buildOnboardAccount, buildAuthorizePreapproval } from "./onboard";
24
- import { assignFromAccountRaw, assignToAccountRaw } from "./serialization";
25
24
 
26
25
  export function createBridges(
27
26
  signerContext: SignerContext<CantonSigner>,
@@ -33,7 +32,7 @@ export function createBridges(
33
32
  const receive = makeAccountBridgeReceive(getAddressWrapper(getAddress));
34
33
 
35
34
  const scanAccounts = makeScanAccounts({
36
- getAccountShape: getAccountShape,
35
+ getAccountShape: makeGetAccountShape(signerContext),
37
36
  getAddressFn: getAddress,
38
37
  });
39
38
 
@@ -49,7 +48,7 @@ export function createBridges(
49
48
  };
50
49
 
51
50
  const signOperation = buildSignOperation(signerContext);
52
- const sync = makeSync({ getAccountShape });
51
+ const sync = makeSync({ getAccountShape: makeGetAccountShape(signerContext) });
53
52
  // we want one method per file
54
53
  const accountBridge: AccountBridge<Transaction> = {
55
54
  broadcast,
@@ -63,8 +62,6 @@ export function createBridges(
63
62
  sync,
64
63
  receive,
65
64
  signOperation,
66
- assignToAccountRaw,
67
- assignFromAccountRaw,
68
65
  getSerializedAddressParameters,
69
66
  };
70
67