@ledgerhq/coin-sui 0.15.0 → 0.16.0-nightly.1

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 (102) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +22 -0
  3. package/lib/api/index.d.ts.map +1 -1
  4. package/lib/api/index.integration.test.js +1 -0
  5. package/lib/api/index.integration.test.js.map +1 -1
  6. package/lib/api/index.js +10 -2
  7. package/lib/api/index.js.map +1 -1
  8. package/lib/api/index.test.js +1 -1
  9. package/lib/api/index.test.js.map +1 -1
  10. package/lib/bridge/buildTransaction.d.ts.map +1 -1
  11. package/lib/bridge/buildTransaction.js +1 -0
  12. package/lib/bridge/buildTransaction.js.map +1 -1
  13. package/lib/bridge/buildTransaction.test.js +2 -0
  14. package/lib/bridge/buildTransaction.test.js.map +1 -1
  15. package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
  16. package/lib/bridge/getFeesForTransaction.js +4 -0
  17. package/lib/bridge/getFeesForTransaction.js.map +1 -1
  18. package/lib/bridge/index.d.ts.map +1 -1
  19. package/lib/bridge/index.js +3 -0
  20. package/lib/bridge/index.js.map +1 -1
  21. package/lib/logic/craftTransaction.d.ts +1 -1
  22. package/lib/logic/craftTransaction.d.ts.map +1 -1
  23. package/lib/logic/craftTransaction.integration.test.js +42 -0
  24. package/lib/logic/craftTransaction.integration.test.js.map +1 -1
  25. package/lib/logic/craftTransaction.js +3 -4
  26. package/lib/logic/craftTransaction.js.map +1 -1
  27. package/lib/logic/craftTransaction.test.js +19 -5
  28. package/lib/logic/craftTransaction.test.js.map +1 -1
  29. package/lib/logic/estimateFees.integration.test.js +4 -1
  30. package/lib/logic/estimateFees.integration.test.js.map +1 -1
  31. package/lib/logic/estimateFees.test.js +2 -0
  32. package/lib/logic/estimateFees.test.js.map +1 -1
  33. package/lib/network/index.d.ts +1 -1
  34. package/lib/network/sdk.d.ts +8 -4
  35. package/lib/network/sdk.d.ts.map +1 -1
  36. package/lib/network/sdk.integration.test.js +2 -2
  37. package/lib/network/sdk.integration.test.js.map +1 -1
  38. package/lib/network/sdk.js +78 -31
  39. package/lib/network/sdk.js.map +1 -1
  40. package/lib/network/sdk.test.js +148 -333
  41. package/lib/network/sdk.test.js.map +1 -1
  42. package/lib/types/model.d.ts +3 -0
  43. package/lib/types/model.d.ts.map +1 -1
  44. package/lib-es/api/index.d.ts.map +1 -1
  45. package/lib-es/api/index.integration.test.js +1 -0
  46. package/lib-es/api/index.integration.test.js.map +1 -1
  47. package/lib-es/api/index.js +10 -2
  48. package/lib-es/api/index.js.map +1 -1
  49. package/lib-es/api/index.test.js +1 -1
  50. package/lib-es/api/index.test.js.map +1 -1
  51. package/lib-es/bridge/buildTransaction.d.ts.map +1 -1
  52. package/lib-es/bridge/buildTransaction.js +1 -0
  53. package/lib-es/bridge/buildTransaction.js.map +1 -1
  54. package/lib-es/bridge/buildTransaction.test.js +2 -0
  55. package/lib-es/bridge/buildTransaction.test.js.map +1 -1
  56. package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
  57. package/lib-es/bridge/getFeesForTransaction.js +4 -0
  58. package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
  59. package/lib-es/bridge/index.d.ts.map +1 -1
  60. package/lib-es/bridge/index.js +3 -0
  61. package/lib-es/bridge/index.js.map +1 -1
  62. package/lib-es/logic/craftTransaction.d.ts +1 -1
  63. package/lib-es/logic/craftTransaction.d.ts.map +1 -1
  64. package/lib-es/logic/craftTransaction.integration.test.js +42 -0
  65. package/lib-es/logic/craftTransaction.integration.test.js.map +1 -1
  66. package/lib-es/logic/craftTransaction.js +3 -4
  67. package/lib-es/logic/craftTransaction.js.map +1 -1
  68. package/lib-es/logic/craftTransaction.test.js +19 -5
  69. package/lib-es/logic/craftTransaction.test.js.map +1 -1
  70. package/lib-es/logic/estimateFees.integration.test.js +4 -1
  71. package/lib-es/logic/estimateFees.integration.test.js.map +1 -1
  72. package/lib-es/logic/estimateFees.test.js +2 -0
  73. package/lib-es/logic/estimateFees.test.js.map +1 -1
  74. package/lib-es/network/index.d.ts +1 -1
  75. package/lib-es/network/sdk.d.ts +8 -4
  76. package/lib-es/network/sdk.d.ts.map +1 -1
  77. package/lib-es/network/sdk.integration.test.js +2 -2
  78. package/lib-es/network/sdk.integration.test.js.map +1 -1
  79. package/lib-es/network/sdk.js +75 -29
  80. package/lib-es/network/sdk.js.map +1 -1
  81. package/lib-es/network/sdk.test.js +148 -333
  82. package/lib-es/network/sdk.test.js.map +1 -1
  83. package/lib-es/types/model.d.ts +3 -0
  84. package/lib-es/types/model.d.ts.map +1 -1
  85. package/package.json +7 -7
  86. package/src/api/index.integration.test.ts +1 -0
  87. package/src/api/index.test.ts +1 -1
  88. package/src/api/index.ts +15 -2
  89. package/src/bridge/buildTransaction.test.ts +2 -0
  90. package/src/bridge/buildTransaction.ts +1 -0
  91. package/src/bridge/getFeesForTransaction.ts +4 -0
  92. package/src/bridge/index.ts +3 -0
  93. package/src/logic/craftTransaction.integration.test.ts +52 -0
  94. package/src/logic/craftTransaction.test.ts +55 -25
  95. package/src/logic/craftTransaction.ts +25 -20
  96. package/src/logic/estimateFees.integration.test.ts +4 -1
  97. package/src/logic/estimateFees.test.ts +2 -0
  98. package/src/network/sdk.integration.test.ts +2 -2
  99. package/src/network/sdk.test.ts +210 -369
  100. package/src/network/sdk.ts +114 -36
  101. package/src/types/model.ts +4 -0
  102. package/index.d.ts +0 -0
@@ -10,7 +10,7 @@ describe("craftTransaction", () => {
10
10
 
11
11
  beforeEach(() => {
12
12
  jest.clearAllMocks();
13
- mockCreateTransaction.mockResolvedValue(mockUnsignedTx);
13
+ mockCreateTransaction.mockResolvedValue({ unsigned: mockUnsignedTx });
14
14
  });
15
15
 
16
16
  it("should create a transaction with correct parameters", async () => {
@@ -18,8 +18,10 @@ describe("craftTransaction", () => {
18
18
  const amount = BigInt("1000000000");
19
19
  const recipient = "0x456";
20
20
  const type = "send";
21
+ const intentType = "transaction";
21
22
 
22
23
  const result = await craftTransaction({
24
+ intentType,
23
25
  sender,
24
26
  amount,
25
27
  recipient,
@@ -27,12 +29,17 @@ describe("craftTransaction", () => {
27
29
  asset: { type: "native" },
28
30
  });
29
31
 
30
- expect(mockCreateTransaction).toHaveBeenCalledWith(sender, {
31
- amount: new BigNumber(amount.toString()),
32
- recipient,
33
- mode: type,
34
- coinType: "0x2::sui::SUI",
35
- });
32
+ expect(mockCreateTransaction).toHaveBeenCalledWith(
33
+ sender,
34
+ {
35
+ intentType,
36
+ amount: new BigNumber(amount.toString()),
37
+ recipient,
38
+ mode: type,
39
+ coinType: "0x2::sui::SUI",
40
+ },
41
+ false,
42
+ );
36
43
  expect(result).toEqual({ unsigned: mockUnsignedTx });
37
44
  });
38
45
 
@@ -41,8 +48,10 @@ describe("craftTransaction", () => {
41
48
  const amount = BigInt("500000000");
42
49
  const recipient = "0x456";
43
50
  const type = "send";
51
+ const intentType = "transaction";
44
52
 
45
53
  const result = await craftTransaction({
54
+ intentType,
46
55
  sender,
47
56
  amount,
48
57
  recipient,
@@ -50,12 +59,17 @@ describe("craftTransaction", () => {
50
59
  asset: { type: "native" },
51
60
  });
52
61
 
53
- expect(mockCreateTransaction).toHaveBeenCalledWith(sender, {
54
- amount: new BigNumber(amount.toString()),
55
- recipient,
56
- mode: type,
57
- coinType: "0x2::sui::SUI",
58
- });
62
+ expect(mockCreateTransaction).toHaveBeenCalledWith(
63
+ sender,
64
+ {
65
+ intentType,
66
+ amount: new BigNumber(amount.toString()),
67
+ recipient,
68
+ mode: type,
69
+ coinType: "0x2::sui::SUI",
70
+ },
71
+ false,
72
+ );
59
73
  expect(result).toEqual({ unsigned: mockUnsignedTx });
60
74
  });
61
75
 
@@ -64,8 +78,10 @@ describe("craftTransaction", () => {
64
78
  const amount = BigInt("0");
65
79
  const recipient = "0x456";
66
80
  const type = "send";
81
+ const intentType = "transaction";
67
82
 
68
83
  const result = await craftTransaction({
84
+ intentType,
69
85
  sender,
70
86
  amount,
71
87
  recipient,
@@ -73,12 +89,17 @@ describe("craftTransaction", () => {
73
89
  asset: { type: "native" },
74
90
  });
75
91
 
76
- expect(mockCreateTransaction).toHaveBeenCalledWith(sender, {
77
- amount: new BigNumber(amount.toString()),
78
- recipient,
79
- mode: type,
80
- coinType: "0x2::sui::SUI",
81
- });
92
+ expect(mockCreateTransaction).toHaveBeenCalledWith(
93
+ sender,
94
+ {
95
+ intentType,
96
+ amount: new BigNumber(amount.toString()),
97
+ recipient,
98
+ mode: type,
99
+ coinType: "0x2::sui::SUI",
100
+ },
101
+ false,
102
+ );
82
103
  expect(result).toEqual({ unsigned: mockUnsignedTx });
83
104
  });
84
105
 
@@ -87,8 +108,10 @@ describe("craftTransaction", () => {
87
108
  const amount = BigInt("1000000000000000000"); // 1 SUI (assuming 9 decimals)
88
109
  const recipient = "0x456";
89
110
  const type = "send";
111
+ const intentType = "transaction";
90
112
 
91
113
  const result = await craftTransaction({
114
+ intentType,
92
115
  sender,
93
116
  amount,
94
117
  recipient,
@@ -96,12 +119,17 @@ describe("craftTransaction", () => {
96
119
  asset: { type: "native" },
97
120
  });
98
121
 
99
- expect(mockCreateTransaction).toHaveBeenCalledWith(sender, {
100
- amount: new BigNumber(amount.toString()),
101
- recipient,
102
- mode: type,
103
- coinType: "0x2::sui::SUI",
104
- });
122
+ expect(mockCreateTransaction).toHaveBeenCalledWith(
123
+ sender,
124
+ {
125
+ intentType,
126
+ amount: new BigNumber(amount.toString()),
127
+ recipient,
128
+ mode: type,
129
+ coinType: "0x2::sui::SUI",
130
+ },
131
+ false,
132
+ );
105
133
  expect(result).toEqual({ unsigned: mockUnsignedTx });
106
134
  });
107
135
 
@@ -113,9 +141,11 @@ describe("craftTransaction", () => {
113
141
  const amount = BigInt("1000000000");
114
142
  const recipient = "0x456";
115
143
  const type = "send";
144
+ const intentType = "transaction";
116
145
 
117
146
  await expect(
118
147
  craftTransaction({
148
+ intentType,
119
149
  sender,
120
150
  amount,
121
151
  recipient,
@@ -4,28 +4,33 @@ import type { SuiTransactionMode, CoreTransaction } from "../types";
4
4
  import suiAPI from "../network";
5
5
  import { DEFAULT_COIN_TYPE } from "../network/sdk";
6
6
 
7
- export async function craftTransaction({
8
- amount,
9
- asset,
10
- recipient,
11
- sender,
12
- type,
13
- ...extra
14
- }: TransactionIntent & {
15
- useAllAmount?: boolean;
16
- stakedSuiId?: string;
17
- }): Promise<CoreTransaction> {
7
+ export async function craftTransaction(
8
+ {
9
+ amount,
10
+ asset,
11
+ recipient,
12
+ sender,
13
+ type,
14
+ ...extra
15
+ }: TransactionIntent & {
16
+ useAllAmount?: boolean;
17
+ stakedSuiId?: string;
18
+ },
19
+ withObjects: boolean = false,
20
+ ): Promise<CoreTransaction> {
18
21
  let coinType = DEFAULT_COIN_TYPE;
19
22
  if (asset.type === "token" && asset.assetReference) {
20
23
  coinType = asset.assetReference;
21
24
  }
22
- const unsigned = await suiAPI.createTransaction(sender, {
23
- amount: BigNumber(amount.toString()),
24
- coinType,
25
- mode: type as SuiTransactionMode,
26
- recipient,
27
- ...extra,
28
- });
29
-
30
- return { unsigned };
25
+ return suiAPI.createTransaction(
26
+ sender,
27
+ {
28
+ amount: BigNumber(amount.toString()),
29
+ coinType,
30
+ mode: type as SuiTransactionMode,
31
+ recipient,
32
+ ...extra,
33
+ },
34
+ withObjects,
35
+ );
31
36
  }
@@ -3,7 +3,7 @@ import { getFullnodeUrl } from "@mysten/sui/client";
3
3
  import coinConfig from "../config";
4
4
  import { estimateFees } from "./estimateFees";
5
5
 
6
- const SENDER = "0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0";
6
+ const SENDER = "0xad79719ac7edb44f6e253f1f771e8291e281a6aaf1e4789b52bf85336f525e8e";
7
7
  const RECIPIENT = "0x33444cf803c690db96527cec67e3c9ab512596f4ba2d4eace43f0b4f716e0164";
8
8
 
9
9
  describe("estimateFees", () => {
@@ -20,6 +20,7 @@ describe("estimateFees", () => {
20
20
 
21
21
  it("should estimate fees for native SUI transaction", async () => {
22
22
  const transactionIntent: TransactionIntent = {
23
+ intentType: "transaction",
23
24
  sender: SENDER,
24
25
  recipient: RECIPIENT,
25
26
  amount: BigInt(1000),
@@ -39,6 +40,7 @@ describe("estimateFees", () => {
39
40
  "0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT";
40
41
 
41
42
  const transactionIntent: TransactionIntent = {
43
+ intentType: "transaction",
42
44
  sender: SENDER,
43
45
  recipient: RECIPIENT,
44
46
  amount: BigInt(1000),
@@ -58,6 +60,7 @@ describe("estimateFees", () => {
58
60
 
59
61
  it("should handle concurrent fee estimations", async () => {
60
62
  const transactionIntent: TransactionIntent = {
63
+ intentType: "transaction",
61
64
  sender: SENDER,
62
65
  recipient: RECIPIENT,
63
66
  amount: BigInt(1000),
@@ -23,6 +23,7 @@ describe("estimateFees", () => {
23
23
  });
24
24
 
25
25
  const transactionIntent = {
26
+ intentType: "transaction" as const,
26
27
  sender: "0x123",
27
28
  recipient: "0x456",
28
29
  amount: BigInt("1000000000"),
@@ -50,6 +51,7 @@ describe("estimateFees", () => {
50
51
  });
51
52
 
52
53
  const transactionIntent = {
54
+ intentType: "transaction" as const,
53
55
  sender: "0x123",
54
56
  recipient: "0x456",
55
57
  amount: BigInt("0"),
@@ -155,14 +155,14 @@ describe("SUI SDK Integration tests", () => {
155
155
  recipient: "0x33444cf803c690db96527cec67e3c9ab512596f4ba2d4eace43f0b4f716e0164",
156
156
  errors: {},
157
157
  };
158
- const tx = await createTransaction(address, transaction);
158
+ const { unsigned: tx } = await createTransaction(address, transaction);
159
159
  expect(tx).toBeInstanceOf(Uint8Array);
160
160
  });
161
161
  });
162
162
 
163
163
  describe("paymentInfo", () => {
164
164
  test("paymentInfo should return gas budget and fees", async () => {
165
- const sender = "0x6e143fe0a8ca010a86580dafac44298e5b1b7d73efc345356a59a15f0d7824f0";
165
+ const sender = "0xad79719ac7edb44f6e253f1f771e8291e281a6aaf1e4789b52bf85336f525e8e";
166
166
  const fakeTransaction = {
167
167
  mode: "send" as const,
168
168
  family: "sui" as const,