@ledgerhq/coin-canton 0.10.0-nightly.20251120023735 → 0.10.0
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.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +23 -8
- package/lib/bridge/index.d.ts.map +1 -1
- package/lib/bridge/index.js +0 -3
- package/lib/bridge/index.js.map +1 -1
- package/lib/bridge/serialization.d.ts.map +1 -1
- package/lib/bridge/serialization.js +1 -3
- package/lib/bridge/serialization.js.map +1 -1
- package/lib/bridge/sync.d.ts.map +1 -1
- package/lib/bridge/sync.js +0 -4
- package/lib/bridge/sync.js.map +1 -1
- package/lib/network/gateway.d.ts +0 -18
- package/lib/network/gateway.d.ts.map +1 -1
- package/lib/network/gateway.js +6 -26
- package/lib/network/gateway.js.map +1 -1
- package/lib/types/bridge.d.ts +0 -4
- package/lib/types/bridge.d.ts.map +1 -1
- package/lib-es/bridge/index.d.ts.map +1 -1
- package/lib-es/bridge/index.js +0 -3
- package/lib-es/bridge/index.js.map +1 -1
- package/lib-es/bridge/serialization.d.ts.map +1 -1
- package/lib-es/bridge/serialization.js +1 -3
- package/lib-es/bridge/serialization.js.map +1 -1
- package/lib-es/bridge/sync.d.ts.map +1 -1
- package/lib-es/bridge/sync.js +1 -5
- package/lib-es/bridge/sync.js.map +1 -1
- package/lib-es/network/gateway.d.ts +0 -18
- package/lib-es/network/gateway.d.ts.map +1 -1
- package/lib-es/network/gateway.js +6 -22
- package/lib-es/network/gateway.js.map +1 -1
- package/lib-es/types/bridge.d.ts +0 -4
- package/lib-es/types/bridge.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/bridge/getTransactionStatus.test.ts +0 -1
- package/src/bridge/index.ts +0 -3
- package/src/bridge/serialization.ts +1 -3
- package/src/bridge/sync.ts +1 -10
- package/src/network/gateway.ts +6 -60
- package/src/types/bridge.ts +0 -15
- package/lib/bridge/acceptOffer.d.ts +0 -8
- package/lib/bridge/acceptOffer.d.ts.map +0 -1
- package/lib/bridge/acceptOffer.js +0 -18
- package/lib/bridge/acceptOffer.js.map +0 -1
- package/lib-es/bridge/acceptOffer.d.ts +0 -8
- package/lib-es/bridge/acceptOffer.d.ts.map +0 -1
- package/lib-es/bridge/acceptOffer.js +0 -14
- package/lib-es/bridge/acceptOffer.js.map +0 -1
- package/src/bridge/acceptOffer.test.ts +0 -300
- package/src/bridge/acceptOffer.ts +0 -36
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
2
|
-
import type { Account } from "@ledgerhq/types-live";
|
|
3
|
-
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
4
|
-
import { buildTransferInstruction } from "./acceptOffer";
|
|
5
|
-
import * as gateway from "../network/gateway";
|
|
6
|
-
import * as signTransactionModule from "../common-logic/transaction/sign";
|
|
7
|
-
import type { CantonSigner, CantonSignature } from "../types/signer";
|
|
8
|
-
import type { PrepareTransferResponse } from "../network/gateway";
|
|
9
|
-
|
|
10
|
-
jest.mock("../network/gateway");
|
|
11
|
-
jest.mock("../common-logic/transaction/sign");
|
|
12
|
-
|
|
13
|
-
const mockedGateway = gateway as jest.Mocked<typeof gateway>;
|
|
14
|
-
const mockedSignTransaction = signTransactionModule as jest.Mocked<typeof signTransactionModule>;
|
|
15
|
-
|
|
16
|
-
describe("acceptOffer", () => {
|
|
17
|
-
const mockCurrency = {
|
|
18
|
-
id: "canton_network",
|
|
19
|
-
} as unknown as CryptoCurrency;
|
|
20
|
-
|
|
21
|
-
const mockAccount = {
|
|
22
|
-
id: "test-account-id",
|
|
23
|
-
freshAddressPath: "44'/6767'/0'/0'/0'",
|
|
24
|
-
} as unknown as Account;
|
|
25
|
-
|
|
26
|
-
const mockPartyId = "test-party-id";
|
|
27
|
-
const mockContractId = "test-contract-id";
|
|
28
|
-
const mockDeviceId = "test-device-id";
|
|
29
|
-
|
|
30
|
-
const mockPreparedTransaction: PrepareTransferResponse = {
|
|
31
|
-
hash: "test-hash",
|
|
32
|
-
json: {
|
|
33
|
-
transaction: {
|
|
34
|
-
version: "2.1",
|
|
35
|
-
roots: ["0"],
|
|
36
|
-
nodes: [
|
|
37
|
-
{
|
|
38
|
-
nodeId: "0",
|
|
39
|
-
v1: {
|
|
40
|
-
create: {
|
|
41
|
-
lfVersion: "2.1",
|
|
42
|
-
contractId: mockContractId,
|
|
43
|
-
packageName: "test-package",
|
|
44
|
-
templateId: {
|
|
45
|
-
packageId: "test-package-id",
|
|
46
|
-
moduleName: "TestModule",
|
|
47
|
-
entityName: "TestEntity",
|
|
48
|
-
},
|
|
49
|
-
argument: {
|
|
50
|
-
record: {
|
|
51
|
-
recordId: {
|
|
52
|
-
packageId: "test-package-id",
|
|
53
|
-
moduleName: "TestModule",
|
|
54
|
-
entityName: "TestEntity",
|
|
55
|
-
},
|
|
56
|
-
fields: [],
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
],
|
|
63
|
-
},
|
|
64
|
-
metadata: {
|
|
65
|
-
submitterInfo: {
|
|
66
|
-
actAs: [mockPartyId],
|
|
67
|
-
commandId: "test-command-id",
|
|
68
|
-
},
|
|
69
|
-
synchronizerId: "test-synchronizer-id",
|
|
70
|
-
transactionUuid: "test-transaction-uuid",
|
|
71
|
-
submissionTime: "1234567890",
|
|
72
|
-
inputContracts: [],
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
serialized: "serialized-transaction",
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const mockSignature: CantonSignature = {
|
|
79
|
-
signature: "test-signature",
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const mockSigner: CantonSigner = {
|
|
83
|
-
getAddress: jest.fn(),
|
|
84
|
-
signTransaction: jest.fn(),
|
|
85
|
-
} as unknown as CantonSigner;
|
|
86
|
-
|
|
87
|
-
const mockSignerContext: SignerContext<CantonSigner> = jest.fn(
|
|
88
|
-
async (deviceId: string, callback: (signer: CantonSigner) => Promise<CantonSignature>) => {
|
|
89
|
-
return callback(mockSigner);
|
|
90
|
-
},
|
|
91
|
-
) as unknown as SignerContext<CantonSigner>;
|
|
92
|
-
|
|
93
|
-
beforeEach(() => {
|
|
94
|
-
jest.clearAllMocks();
|
|
95
|
-
mockedGateway.prepareTransferInstruction.mockResolvedValue(mockPreparedTransaction);
|
|
96
|
-
mockedSignTransaction.signTransaction.mockResolvedValue(mockSignature);
|
|
97
|
-
mockedGateway.submitTransferInstruction.mockResolvedValue({ update_id: "test-update-id" });
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
describe("buildTransferInstruction", () => {
|
|
101
|
-
it("should accept transfer instruction without reason", async () => {
|
|
102
|
-
// GIVEN
|
|
103
|
-
const transferInstruction = buildTransferInstruction(mockSignerContext);
|
|
104
|
-
|
|
105
|
-
// WHEN
|
|
106
|
-
await transferInstruction(
|
|
107
|
-
mockCurrency,
|
|
108
|
-
mockDeviceId,
|
|
109
|
-
mockAccount,
|
|
110
|
-
mockPartyId,
|
|
111
|
-
mockContractId,
|
|
112
|
-
"accept-transfer-instruction",
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
// THEN
|
|
116
|
-
expect(mockedGateway.prepareTransferInstruction).toHaveBeenCalledWith(
|
|
117
|
-
mockCurrency,
|
|
118
|
-
mockPartyId,
|
|
119
|
-
{
|
|
120
|
-
type: "accept-transfer-instruction",
|
|
121
|
-
contract_id: mockContractId,
|
|
122
|
-
},
|
|
123
|
-
);
|
|
124
|
-
expect(mockedSignTransaction.signTransaction).toHaveBeenCalledWith(
|
|
125
|
-
mockSigner,
|
|
126
|
-
mockAccount.freshAddressPath,
|
|
127
|
-
mockPreparedTransaction,
|
|
128
|
-
);
|
|
129
|
-
expect(mockedGateway.submitTransferInstruction).toHaveBeenCalledWith(
|
|
130
|
-
mockCurrency,
|
|
131
|
-
mockPartyId,
|
|
132
|
-
mockPreparedTransaction.serialized,
|
|
133
|
-
mockSignature.signature,
|
|
134
|
-
);
|
|
135
|
-
expect(mockSignerContext).toHaveBeenCalledWith(mockDeviceId, expect.any(Function));
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it("should accept transfer instruction with reason", async () => {
|
|
139
|
-
// GIVEN
|
|
140
|
-
const reason = "test-reason";
|
|
141
|
-
const transferInstruction = buildTransferInstruction(mockSignerContext);
|
|
142
|
-
|
|
143
|
-
// WHEN
|
|
144
|
-
await transferInstruction(
|
|
145
|
-
mockCurrency,
|
|
146
|
-
mockDeviceId,
|
|
147
|
-
mockAccount,
|
|
148
|
-
mockPartyId,
|
|
149
|
-
mockContractId,
|
|
150
|
-
"accept-transfer-instruction",
|
|
151
|
-
reason,
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
// THEN
|
|
155
|
-
expect(mockedGateway.prepareTransferInstruction).toHaveBeenCalledWith(
|
|
156
|
-
mockCurrency,
|
|
157
|
-
mockPartyId,
|
|
158
|
-
{
|
|
159
|
-
type: "accept-transfer-instruction",
|
|
160
|
-
contract_id: mockContractId,
|
|
161
|
-
reason,
|
|
162
|
-
},
|
|
163
|
-
);
|
|
164
|
-
expect(mockedSignTransaction.signTransaction).toHaveBeenCalledWith(
|
|
165
|
-
mockSigner,
|
|
166
|
-
mockAccount.freshAddressPath,
|
|
167
|
-
mockPreparedTransaction,
|
|
168
|
-
);
|
|
169
|
-
expect(mockedGateway.submitTransferInstruction).toHaveBeenCalledWith(
|
|
170
|
-
mockCurrency,
|
|
171
|
-
mockPartyId,
|
|
172
|
-
mockPreparedTransaction.serialized,
|
|
173
|
-
mockSignature.signature,
|
|
174
|
-
);
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it("should reject transfer instruction", async () => {
|
|
178
|
-
// GIVEN
|
|
179
|
-
const transferInstruction = buildTransferInstruction(mockSignerContext);
|
|
180
|
-
|
|
181
|
-
// WHEN
|
|
182
|
-
await transferInstruction(
|
|
183
|
-
mockCurrency,
|
|
184
|
-
mockDeviceId,
|
|
185
|
-
mockAccount,
|
|
186
|
-
mockPartyId,
|
|
187
|
-
mockContractId,
|
|
188
|
-
"reject-transfer-instruction",
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
// THEN
|
|
192
|
-
expect(mockedGateway.prepareTransferInstruction).toHaveBeenCalledWith(
|
|
193
|
-
mockCurrency,
|
|
194
|
-
mockPartyId,
|
|
195
|
-
{
|
|
196
|
-
type: "reject-transfer-instruction",
|
|
197
|
-
contract_id: mockContractId,
|
|
198
|
-
},
|
|
199
|
-
);
|
|
200
|
-
expect(mockedSignTransaction.signTransaction).toHaveBeenCalled();
|
|
201
|
-
expect(mockedGateway.submitTransferInstruction).toHaveBeenCalled();
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it("should withdraw transfer instruction", async () => {
|
|
205
|
-
// GIVEN
|
|
206
|
-
const transferInstruction = buildTransferInstruction(mockSignerContext);
|
|
207
|
-
|
|
208
|
-
// WHEN
|
|
209
|
-
await transferInstruction(
|
|
210
|
-
mockCurrency,
|
|
211
|
-
mockDeviceId,
|
|
212
|
-
mockAccount,
|
|
213
|
-
mockPartyId,
|
|
214
|
-
mockContractId,
|
|
215
|
-
"withdraw-transfer-instruction",
|
|
216
|
-
);
|
|
217
|
-
|
|
218
|
-
// THEN
|
|
219
|
-
expect(mockedGateway.prepareTransferInstruction).toHaveBeenCalledWith(
|
|
220
|
-
mockCurrency,
|
|
221
|
-
mockPartyId,
|
|
222
|
-
{
|
|
223
|
-
type: "withdraw-transfer-instruction",
|
|
224
|
-
contract_id: mockContractId,
|
|
225
|
-
},
|
|
226
|
-
);
|
|
227
|
-
expect(mockedSignTransaction.signTransaction).toHaveBeenCalled();
|
|
228
|
-
expect(mockedGateway.submitTransferInstruction).toHaveBeenCalled();
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
it("should handle errors from prepareTransferInstruction", async () => {
|
|
232
|
-
// GIVEN
|
|
233
|
-
const error = new Error("Prepare failed");
|
|
234
|
-
mockedGateway.prepareTransferInstruction.mockRejectedValue(error);
|
|
235
|
-
const transferInstruction = buildTransferInstruction(mockSignerContext);
|
|
236
|
-
|
|
237
|
-
// WHEN & THEN
|
|
238
|
-
await expect(
|
|
239
|
-
transferInstruction(
|
|
240
|
-
mockCurrency,
|
|
241
|
-
mockDeviceId,
|
|
242
|
-
mockAccount,
|
|
243
|
-
mockPartyId,
|
|
244
|
-
mockContractId,
|
|
245
|
-
"accept-transfer-instruction",
|
|
246
|
-
),
|
|
247
|
-
).rejects.toThrow("Prepare failed");
|
|
248
|
-
|
|
249
|
-
expect(mockedGateway.prepareTransferInstruction).toHaveBeenCalled();
|
|
250
|
-
expect(mockedSignTransaction.signTransaction).not.toHaveBeenCalled();
|
|
251
|
-
expect(mockedGateway.submitTransferInstruction).not.toHaveBeenCalled();
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it("should handle errors from signTransaction", async () => {
|
|
255
|
-
// GIVEN
|
|
256
|
-
const error = new Error("Sign failed");
|
|
257
|
-
mockedSignTransaction.signTransaction.mockRejectedValue(error);
|
|
258
|
-
const transferInstruction = buildTransferInstruction(mockSignerContext);
|
|
259
|
-
|
|
260
|
-
// WHEN & THEN
|
|
261
|
-
await expect(
|
|
262
|
-
transferInstruction(
|
|
263
|
-
mockCurrency,
|
|
264
|
-
mockDeviceId,
|
|
265
|
-
mockAccount,
|
|
266
|
-
mockPartyId,
|
|
267
|
-
mockContractId,
|
|
268
|
-
"accept-transfer-instruction",
|
|
269
|
-
),
|
|
270
|
-
).rejects.toThrow("Sign failed");
|
|
271
|
-
|
|
272
|
-
expect(mockedGateway.prepareTransferInstruction).toHaveBeenCalled();
|
|
273
|
-
expect(mockedSignTransaction.signTransaction).toHaveBeenCalled();
|
|
274
|
-
expect(mockedGateway.submitTransferInstruction).not.toHaveBeenCalled();
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
it("should handle errors from submitTransferInstruction", async () => {
|
|
278
|
-
// GIVEN
|
|
279
|
-
const error = new Error("Submit failed");
|
|
280
|
-
mockedGateway.submitTransferInstruction.mockRejectedValue(error);
|
|
281
|
-
const transferInstruction = buildTransferInstruction(mockSignerContext);
|
|
282
|
-
|
|
283
|
-
// WHEN & THEN
|
|
284
|
-
await expect(
|
|
285
|
-
transferInstruction(
|
|
286
|
-
mockCurrency,
|
|
287
|
-
mockDeviceId,
|
|
288
|
-
mockAccount,
|
|
289
|
-
mockPartyId,
|
|
290
|
-
mockContractId,
|
|
291
|
-
"accept-transfer-instruction",
|
|
292
|
-
),
|
|
293
|
-
).rejects.toThrow("Submit failed");
|
|
294
|
-
|
|
295
|
-
expect(mockedGateway.prepareTransferInstruction).toHaveBeenCalled();
|
|
296
|
-
expect(mockedSignTransaction.signTransaction).toHaveBeenCalled();
|
|
297
|
-
expect(mockedGateway.submitTransferInstruction).toHaveBeenCalled();
|
|
298
|
-
});
|
|
299
|
-
});
|
|
300
|
-
});
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
2
|
-
import type { Account } from "@ledgerhq/types-live";
|
|
3
|
-
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
4
|
-
|
|
5
|
-
import { prepareTransferInstruction, submitTransferInstruction } from "../network/gateway";
|
|
6
|
-
import { signTransaction } from "../common-logic/transaction/sign";
|
|
7
|
-
import type { CantonSigner } from "../types";
|
|
8
|
-
|
|
9
|
-
type TransferInstructionType =
|
|
10
|
-
| "accept-transfer-instruction"
|
|
11
|
-
| "reject-transfer-instruction"
|
|
12
|
-
| "withdraw-transfer-instruction";
|
|
13
|
-
|
|
14
|
-
export const buildTransferInstruction =
|
|
15
|
-
(signerContext: SignerContext<CantonSigner>) =>
|
|
16
|
-
async (
|
|
17
|
-
currency: CryptoCurrency,
|
|
18
|
-
deviceId: string,
|
|
19
|
-
account: Account,
|
|
20
|
-
partyId: string,
|
|
21
|
-
contractId: string,
|
|
22
|
-
type: TransferInstructionType,
|
|
23
|
-
reason?: string,
|
|
24
|
-
) => {
|
|
25
|
-
const preparedTransaction = await prepareTransferInstruction(currency, partyId, {
|
|
26
|
-
type,
|
|
27
|
-
contract_id: contractId,
|
|
28
|
-
...(reason && { reason }),
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const { signature } = await signerContext(deviceId, async signer => {
|
|
32
|
-
return await signTransaction(signer, account.freshAddressPath, preparedTransaction);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
await submitTransferInstruction(currency, partyId, preparedTransaction.serialized, signature);
|
|
36
|
-
};
|