@ledgerhq/coin-canton 0.5.0-nightly.1 → 0.5.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.
- package/.turbo/turbo-build.log +1 -1
- package/.unimportedrc.json +12 -4
- package/CHANGELOG.md +32 -0
- package/lib/api/getBalance.integ.test.js +1 -1
- package/lib/api/getBalance.integ.test.js.map +1 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +11 -8
- package/lib/api/index.js.map +1 -1
- package/lib/bridge/broadcast.d.ts.map +1 -1
- package/lib/bridge/broadcast.js +2 -1
- package/lib/bridge/broadcast.js.map +1 -1
- package/lib/bridge/createTransaction.test.js +1 -1
- package/lib/bridge/createTransaction.test.js.map +1 -1
- package/lib/bridge/index.d.ts +3 -3
- package/lib/bridge/index.d.ts.map +1 -1
- package/lib/bridge/index.js +9 -1
- package/lib/bridge/index.js.map +1 -1
- package/lib/bridge/onboard.d.ts +10 -0
- package/lib/bridge/onboard.d.ts.map +1 -0
- package/lib/bridge/onboard.integ.test.d.ts +2 -0
- package/lib/bridge/onboard.integ.test.d.ts.map +1 -0
- package/lib/bridge/onboard.integ.test.js +156 -0
- package/lib/bridge/onboard.integ.test.js.map +1 -0
- package/lib/bridge/onboard.js +139 -0
- package/lib/bridge/onboard.js.map +1 -0
- package/lib/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib/bridge/prepareTransaction.js +5 -7
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/signOperation.d.ts.map +1 -1
- package/lib/bridge/signOperation.js +7 -9
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/bridge/sync.d.ts.map +1 -1
- package/lib/bridge/sync.integ.test.d.ts +2 -0
- package/lib/bridge/sync.integ.test.d.ts.map +1 -0
- package/lib/bridge/sync.integ.test.js +175 -0
- package/lib/bridge/sync.integ.test.js.map +1 -0
- package/lib/bridge/sync.js +40 -36
- package/lib/bridge/sync.js.map +1 -1
- package/lib/bridge/updateTransaction.d.ts.map +1 -1
- package/lib/bridge/updateTransaction.js +0 -4
- package/lib/bridge/updateTransaction.js.map +1 -1
- package/lib/common-logic/history/listOperations.d.ts.map +1 -1
- package/lib/common-logic/history/listOperations.js +19 -31
- package/lib/common-logic/history/listOperations.js.map +1 -1
- package/lib/common-logic/transaction/broadcast.d.ts.map +1 -1
- package/lib/common-logic/transaction/broadcast.js +2 -1
- package/lib/common-logic/transaction/broadcast.js.map +1 -1
- package/lib/common-logic/transaction/broadcast.test.js +3 -3
- package/lib/common-logic/transaction/broadcast.test.js.map +1 -1
- package/lib/common-logic/transaction/combine.d.ts +1 -1
- package/lib/common-logic/transaction/combine.d.ts.map +1 -1
- package/lib/common-logic/transaction/combine.js +2 -3
- package/lib/common-logic/transaction/combine.js.map +1 -1
- package/lib/common-logic/transaction/combine.test.js +3 -13
- package/lib/common-logic/transaction/combine.test.js.map +1 -1
- package/lib/common-logic/transaction/craftTransaction.d.ts +5 -3
- package/lib/common-logic/transaction/craftTransaction.d.ts.map +1 -1
- package/lib/common-logic/transaction/craftTransaction.js +11 -12
- package/lib/common-logic/transaction/craftTransaction.js.map +1 -1
- package/lib/network/gateway.d.ts +196 -5
- package/lib/network/gateway.d.ts.map +1 -1
- package/lib/network/gateway.integ.test.js +121 -11
- package/lib/network/gateway.integ.test.js.map +1 -1
- package/lib/network/gateway.js +99 -21
- package/lib/network/gateway.js.map +1 -1
- package/lib/network/node.d.ts +2 -2
- package/lib/network/node.d.ts.map +1 -1
- package/lib/network/node.js.map +1 -1
- package/lib/network/types.d.ts +1 -1
- package/lib/network/types.d.ts.map +1 -1
- package/lib/signer/getAddress.d.ts.map +1 -1
- package/lib/signer/getAddress.js +2 -2
- package/lib/signer/getAddress.js.map +1 -1
- package/lib/test/cantonTestUtils.d.ts +33 -0
- package/lib/test/cantonTestUtils.d.ts.map +1 -0
- package/lib/test/cantonTestUtils.js +159 -0
- package/lib/test/cantonTestUtils.js.map +1 -0
- package/lib/types/bridge.d.ts +7 -1
- package/lib/types/bridge.d.ts.map +1 -1
- package/lib/types/index.d.ts +1 -10
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js +1 -0
- package/lib/types/index.js.map +1 -1
- package/lib/types/onboard.d.ts +55 -0
- package/lib/types/onboard.d.ts.map +1 -0
- package/lib/types/onboard.js +22 -0
- package/lib/types/onboard.js.map +1 -0
- package/lib-es/api/getBalance.integ.test.js +1 -1
- package/lib-es/api/getBalance.integ.test.js.map +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +12 -9
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/bridge/broadcast.d.ts.map +1 -1
- package/lib-es/bridge/broadcast.js +2 -1
- package/lib-es/bridge/broadcast.js.map +1 -1
- package/lib-es/bridge/createTransaction.test.js +1 -1
- package/lib-es/bridge/createTransaction.test.js.map +1 -1
- package/lib-es/bridge/index.d.ts +3 -3
- package/lib-es/bridge/index.d.ts.map +1 -1
- package/lib-es/bridge/index.js +9 -1
- package/lib-es/bridge/index.js.map +1 -1
- package/lib-es/bridge/onboard.d.ts +10 -0
- package/lib-es/bridge/onboard.d.ts.map +1 -0
- package/lib-es/bridge/onboard.integ.test.d.ts +2 -0
- package/lib-es/bridge/onboard.integ.test.d.ts.map +1 -0
- package/lib-es/bridge/onboard.integ.test.js +151 -0
- package/lib-es/bridge/onboard.integ.test.js.map +1 -0
- package/lib-es/bridge/onboard.js +133 -0
- package/lib-es/bridge/onboard.js.map +1 -0
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +6 -8
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/signOperation.d.ts.map +1 -1
- package/lib-es/bridge/signOperation.js +8 -10
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/bridge/sync.d.ts.map +1 -1
- package/lib-es/bridge/sync.integ.test.d.ts +2 -0
- package/lib-es/bridge/sync.integ.test.d.ts.map +1 -0
- package/lib-es/bridge/sync.integ.test.js +137 -0
- package/lib-es/bridge/sync.integ.test.js.map +1 -0
- package/lib-es/bridge/sync.js +39 -35
- package/lib-es/bridge/sync.js.map +1 -1
- package/lib-es/bridge/updateTransaction.d.ts.map +1 -1
- package/lib-es/bridge/updateTransaction.js +0 -4
- package/lib-es/bridge/updateTransaction.js.map +1 -1
- package/lib-es/common-logic/history/listOperations.d.ts.map +1 -1
- package/lib-es/common-logic/history/listOperations.js +20 -29
- package/lib-es/common-logic/history/listOperations.js.map +1 -1
- package/lib-es/common-logic/transaction/broadcast.d.ts.map +1 -1
- package/lib-es/common-logic/transaction/broadcast.js +2 -1
- package/lib-es/common-logic/transaction/broadcast.js.map +1 -1
- package/lib-es/common-logic/transaction/broadcast.test.js +3 -3
- package/lib-es/common-logic/transaction/broadcast.test.js.map +1 -1
- package/lib-es/common-logic/transaction/combine.d.ts +1 -1
- package/lib-es/common-logic/transaction/combine.d.ts.map +1 -1
- package/lib-es/common-logic/transaction/combine.js +2 -3
- package/lib-es/common-logic/transaction/combine.js.map +1 -1
- package/lib-es/common-logic/transaction/combine.test.js +3 -13
- package/lib-es/common-logic/transaction/combine.test.js.map +1 -1
- package/lib-es/common-logic/transaction/craftTransaction.d.ts +5 -3
- package/lib-es/common-logic/transaction/craftTransaction.d.ts.map +1 -1
- package/lib-es/common-logic/transaction/craftTransaction.js +11 -12
- package/lib-es/common-logic/transaction/craftTransaction.js.map +1 -1
- package/lib-es/network/gateway.d.ts +196 -5
- package/lib-es/network/gateway.d.ts.map +1 -1
- package/lib-es/network/gateway.integ.test.js +122 -12
- package/lib-es/network/gateway.integ.test.js.map +1 -1
- package/lib-es/network/gateway.js +93 -20
- package/lib-es/network/gateway.js.map +1 -1
- package/lib-es/network/node.d.ts +2 -2
- package/lib-es/network/node.d.ts.map +1 -1
- package/lib-es/network/node.js.map +1 -1
- package/lib-es/network/types.d.ts +1 -1
- package/lib-es/network/types.d.ts.map +1 -1
- package/lib-es/signer/getAddress.d.ts.map +1 -1
- package/lib-es/signer/getAddress.js +2 -2
- package/lib-es/signer/getAddress.js.map +1 -1
- package/lib-es/test/cantonTestUtils.d.ts +33 -0
- package/lib-es/test/cantonTestUtils.d.ts.map +1 -0
- package/lib-es/test/cantonTestUtils.js +151 -0
- package/lib-es/test/cantonTestUtils.js.map +1 -0
- package/lib-es/types/bridge.d.ts +7 -1
- package/lib-es/types/bridge.d.ts.map +1 -1
- package/lib-es/types/index.d.ts +1 -10
- package/lib-es/types/index.d.ts.map +1 -1
- package/lib-es/types/index.js +1 -0
- package/lib-es/types/index.js.map +1 -1
- package/lib-es/types/onboard.d.ts +55 -0
- package/lib-es/types/onboard.d.ts.map +1 -0
- package/lib-es/types/onboard.js +19 -0
- package/lib-es/types/onboard.js.map +1 -0
- package/package.json +7 -7
- package/src/api/getBalance.integ.test.ts +1 -2
- package/src/api/index.ts +33 -26
- package/src/bridge/broadcast.ts +2 -3
- package/src/bridge/createTransaction.test.ts +1 -1
- package/src/bridge/index.ts +14 -4
- package/src/bridge/onboard.integ.test.ts +219 -0
- package/src/bridge/onboard.ts +220 -0
- package/src/bridge/prepareTransaction.ts +6 -15
- package/src/bridge/signOperation.ts +9 -16
- package/src/bridge/sync.integ.test.ts +180 -0
- package/src/bridge/sync.ts +61 -49
- package/src/bridge/updateTransaction.ts +0 -5
- package/src/common-logic/history/listOperations.ts +20 -31
- package/src/common-logic/transaction/broadcast.test.ts +3 -3
- package/src/common-logic/transaction/broadcast.ts +2 -1
- package/src/common-logic/transaction/combine.test.ts +3 -13
- package/src/common-logic/transaction/combine.ts +2 -4
- package/src/common-logic/transaction/craftTransaction.ts +15 -17
- package/src/network/gateway.integ.test.ts +156 -17
- package/src/network/gateway.ts +337 -30
- package/src/network/node.ts +3 -3
- package/src/network/types.ts +1 -1
- package/src/signer/getAddress.ts +3 -5
- package/src/test/cantonTestUtils.ts +181 -0
- package/src/types/bridge.ts +20 -0
- package/src/types/index.ts +1 -11
- package/src/types/onboard.ts +65 -0
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
import coinConfig from "../config";
|
|
2
|
+
import { generateMockKeyPair } from "../test/cantonTestUtils";
|
|
2
3
|
import {
|
|
3
4
|
getLedgerEnd,
|
|
4
5
|
prepareOnboarding,
|
|
5
6
|
getBalance,
|
|
6
|
-
|
|
7
|
+
getOperations,
|
|
7
8
|
getPartyById,
|
|
8
9
|
getPartyByPubKey,
|
|
10
|
+
submitOnboarding,
|
|
11
|
+
prepareTapRequest,
|
|
12
|
+
submitTapRequest,
|
|
13
|
+
preparePreApprovalTransaction,
|
|
14
|
+
submitPreApprovalTransaction,
|
|
9
15
|
} from "./gateway";
|
|
10
16
|
|
|
11
17
|
describe("gateway (devnet)", () => {
|
|
12
|
-
|
|
18
|
+
let onboardedAccount: {
|
|
19
|
+
keyPair: ReturnType<typeof generateMockKeyPair>;
|
|
20
|
+
partyId: string;
|
|
21
|
+
} | null = null;
|
|
22
|
+
|
|
23
|
+
beforeAll(async () => {
|
|
13
24
|
coinConfig.setCoinConfig(() => ({
|
|
14
25
|
gatewayUrl: "https://canton-gateway.api.live.ledger-test.com",
|
|
15
26
|
useGateway: true,
|
|
@@ -18,18 +29,63 @@ describe("gateway (devnet)", () => {
|
|
|
18
29
|
type: "active",
|
|
19
30
|
},
|
|
20
31
|
}));
|
|
21
|
-
});
|
|
32
|
+
}, 60000);
|
|
33
|
+
|
|
34
|
+
const getOnboardedAccount = () => {
|
|
35
|
+
if (!onboardedAccount) {
|
|
36
|
+
throw new Error("Shared onboarded account not available. Check beforeAll setup.");
|
|
37
|
+
}
|
|
38
|
+
return onboardedAccount;
|
|
39
|
+
};
|
|
22
40
|
|
|
23
41
|
describe("prepareOnboarding", () => {
|
|
24
42
|
it("should prepare onboarding", async () => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
43
|
+
// GIVEN
|
|
44
|
+
const keyPair = generateMockKeyPair();
|
|
45
|
+
|
|
46
|
+
// Save onboarded account for all tests that need a valid party ID
|
|
47
|
+
onboardedAccount = {
|
|
48
|
+
keyPair,
|
|
49
|
+
partyId: "", // set in next test
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// WHEN
|
|
53
|
+
const response = await prepareOnboarding(keyPair.publicKeyHex, "ed25519");
|
|
54
|
+
|
|
55
|
+
// THEN
|
|
29
56
|
expect(response).toHaveProperty("party_id");
|
|
30
57
|
expect(response).toHaveProperty("party_name");
|
|
31
58
|
expect(response).toHaveProperty("public_key_fingerprint");
|
|
32
|
-
expect(response).toHaveProperty("
|
|
59
|
+
expect(response).toHaveProperty("transactions");
|
|
60
|
+
expect(response.transactions).toHaveProperty("combined_hash");
|
|
61
|
+
expect(response.party_name).toBe(keyPair.publicKeyHex);
|
|
62
|
+
|
|
63
|
+
expect(response.public_key_fingerprint).toBe(keyPair.fingerprint);
|
|
64
|
+
}, 30000);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe("submitOnboarding", () => {
|
|
68
|
+
it("should submit onboarding with proper signature", async () => {
|
|
69
|
+
// GIVEN
|
|
70
|
+
const { keyPair } = getOnboardedAccount();
|
|
71
|
+
const prepareRequest = { public_key: keyPair.publicKeyHex, public_key_type: "ed25519" };
|
|
72
|
+
const prepareResponse = await prepareOnboarding(keyPair.publicKeyHex, "ed25519");
|
|
73
|
+
const signature = keyPair.sign(prepareResponse.transactions.combined_hash);
|
|
74
|
+
|
|
75
|
+
// WHEN
|
|
76
|
+
const response = await submitOnboarding(prepareRequest, prepareResponse, signature);
|
|
77
|
+
|
|
78
|
+
// Save onboarded account for all tests that need a valid party ID
|
|
79
|
+
onboardedAccount = {
|
|
80
|
+
keyPair,
|
|
81
|
+
partyId: response.party.party_id,
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// THEN
|
|
85
|
+
expect(response).toHaveProperty("party");
|
|
86
|
+
expect(response.party).toHaveProperty("party_id");
|
|
87
|
+
expect(response.party).toHaveProperty("public_key");
|
|
88
|
+
expect(response.party.public_key).toBe(keyPair.publicKeyHex);
|
|
33
89
|
}, 30000);
|
|
34
90
|
});
|
|
35
91
|
|
|
@@ -42,12 +98,13 @@ describe("gateway (devnet)", () => {
|
|
|
42
98
|
|
|
43
99
|
describe("getBalance", () => {
|
|
44
100
|
it("should return user balance", async () => {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
101
|
+
const { partyId } = getOnboardedAccount();
|
|
102
|
+
const balance = await getBalance(partyId);
|
|
103
|
+
expect(balance.length).toBeGreaterThanOrEqual(0);
|
|
104
|
+
if (balance.length > 0) {
|
|
105
|
+
expect(balance[0].amount).toBeGreaterThanOrEqual(0);
|
|
106
|
+
expect(balance[0]).toHaveProperty("instrument_id");
|
|
107
|
+
}
|
|
51
108
|
});
|
|
52
109
|
});
|
|
53
110
|
|
|
@@ -67,12 +124,94 @@ describe("gateway (devnet)", () => {
|
|
|
67
124
|
});
|
|
68
125
|
});
|
|
69
126
|
|
|
70
|
-
describe("
|
|
127
|
+
describe("getOperations", () => {
|
|
71
128
|
it("should return user transactions", async () => {
|
|
72
|
-
const {
|
|
129
|
+
const { operations } = await getOperations(
|
|
73
130
|
"party-5f29bb32e9939939::12202becd8062a1d170209956cfd977fca76fcb4d2a892d08c77a7483f35a11d6440",
|
|
74
131
|
);
|
|
75
|
-
expect(
|
|
132
|
+
expect(operations.length).toBeGreaterThanOrEqual(0);
|
|
76
133
|
});
|
|
77
134
|
});
|
|
135
|
+
|
|
136
|
+
describe("prepareTapRequest", () => {
|
|
137
|
+
it("should prepare tap request for onboarded party", async () => {
|
|
138
|
+
// GIVEN
|
|
139
|
+
const { partyId } = getOnboardedAccount();
|
|
140
|
+
const amount = 1000;
|
|
141
|
+
|
|
142
|
+
// WHEN
|
|
143
|
+
const response = await prepareTapRequest({ partyId, amount });
|
|
144
|
+
|
|
145
|
+
// THEN
|
|
146
|
+
expect(response).toHaveProperty("serialized");
|
|
147
|
+
expect(response).toHaveProperty("hash");
|
|
148
|
+
expect(typeof response.serialized).toBe("string");
|
|
149
|
+
expect(typeof response.hash).toBe("string");
|
|
150
|
+
}, 30000);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe("submitTapRequest", () => {
|
|
154
|
+
it("should submit tap request with proper signature", async () => {
|
|
155
|
+
// GIVEN
|
|
156
|
+
const { keyPair, partyId } = getOnboardedAccount();
|
|
157
|
+
const tapPrepareResponse = await prepareTapRequest({
|
|
158
|
+
partyId,
|
|
159
|
+
amount: 1000,
|
|
160
|
+
});
|
|
161
|
+
const tapSignature = keyPair.sign(tapPrepareResponse.hash);
|
|
162
|
+
|
|
163
|
+
// WHEN
|
|
164
|
+
const response = await submitTapRequest({
|
|
165
|
+
partyId,
|
|
166
|
+
serialized: tapPrepareResponse.serialized,
|
|
167
|
+
signature: tapSignature,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// THEN
|
|
171
|
+
expect(response).toHaveProperty("submission_id");
|
|
172
|
+
expect(response).toHaveProperty("update_id");
|
|
173
|
+
expect(typeof response.submission_id).toBe("string");
|
|
174
|
+
expect(typeof response.update_id).toBe("string");
|
|
175
|
+
}, 30000);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
describe("preparePreApprovalTransaction", () => {
|
|
179
|
+
it("should prepare pre-approval transaction for onboarded party", async () => {
|
|
180
|
+
// GIVEN
|
|
181
|
+
const { partyId } = getOnboardedAccount();
|
|
182
|
+
|
|
183
|
+
// WHEN
|
|
184
|
+
const response = await preparePreApprovalTransaction(partyId);
|
|
185
|
+
|
|
186
|
+
// THEN
|
|
187
|
+
expect(response).toHaveProperty("serialized");
|
|
188
|
+
expect(response).toHaveProperty("hash");
|
|
189
|
+
expect(typeof response.serialized).toBe("string");
|
|
190
|
+
expect(typeof response.hash).toBe("string");
|
|
191
|
+
}, 30000);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
describe("submitPreApprovalTransaction", () => {
|
|
195
|
+
it("should submit pre-approval transaction with proper signature", async () => {
|
|
196
|
+
// GIVEN
|
|
197
|
+
const { keyPair, partyId } = getOnboardedAccount();
|
|
198
|
+
const preparedTransaction = await preparePreApprovalTransaction(partyId);
|
|
199
|
+
const preApprovalSignature = keyPair.sign(preparedTransaction.hash);
|
|
200
|
+
|
|
201
|
+
// WHEN
|
|
202
|
+
const response = await submitPreApprovalTransaction(
|
|
203
|
+
partyId,
|
|
204
|
+
preparedTransaction,
|
|
205
|
+
preApprovalSignature,
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
// THEN
|
|
209
|
+
expect(response).toHaveProperty("isApproved");
|
|
210
|
+
expect(response).toHaveProperty("submissionId");
|
|
211
|
+
expect(response).toHaveProperty("updateId");
|
|
212
|
+
expect(response.isApproved).toBe(true);
|
|
213
|
+
expect(typeof response.submissionId).toBe("string");
|
|
214
|
+
expect(typeof response.updateId).toBe("string");
|
|
215
|
+
}, 30000);
|
|
216
|
+
});
|
|
78
217
|
});
|
package/src/network/gateway.ts
CHANGED
|
@@ -1,11 +1,37 @@
|
|
|
1
1
|
import network from "@ledgerhq/live-network";
|
|
2
|
+
import type { LiveNetworkRequest } from "@ledgerhq/live-network/network";
|
|
3
|
+
import { getEnv } from "@ledgerhq/live-env";
|
|
2
4
|
import coinConfig from "../config";
|
|
5
|
+
import {
|
|
6
|
+
PrepareTransactionRequest,
|
|
7
|
+
PrepareTransactionResponse,
|
|
8
|
+
SubmitTransactionRequest,
|
|
9
|
+
SubmitTransactionResponse,
|
|
10
|
+
PreApprovalResult,
|
|
11
|
+
} from "../types/onboard";
|
|
3
12
|
|
|
4
13
|
type OnboardingPrepareResponse = {
|
|
5
14
|
party_id: string;
|
|
6
15
|
party_name: string;
|
|
7
16
|
public_key_fingerprint: string;
|
|
8
|
-
|
|
17
|
+
transactions: {
|
|
18
|
+
namespace_transaction: {
|
|
19
|
+
serialized: string;
|
|
20
|
+
json: object;
|
|
21
|
+
hash: string;
|
|
22
|
+
};
|
|
23
|
+
party_to_key_transaction: {
|
|
24
|
+
serialized: string;
|
|
25
|
+
json: object;
|
|
26
|
+
hash: string;
|
|
27
|
+
};
|
|
28
|
+
party_to_participant_transaction: {
|
|
29
|
+
serialized: string;
|
|
30
|
+
json: object;
|
|
31
|
+
hash: string;
|
|
32
|
+
};
|
|
33
|
+
combined_hash: string;
|
|
34
|
+
};
|
|
9
35
|
};
|
|
10
36
|
|
|
11
37
|
type OnboardingPrepareRequest = {
|
|
@@ -13,6 +39,31 @@ type OnboardingPrepareRequest = {
|
|
|
13
39
|
public_key_type: string;
|
|
14
40
|
};
|
|
15
41
|
|
|
42
|
+
export type PrepareTransferResponse = {
|
|
43
|
+
hash: string;
|
|
44
|
+
json: any; // The actual structure is complex, using any for now
|
|
45
|
+
serialized: string;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type PrepareTransferRequest = {
|
|
49
|
+
type: "token-transfer-request";
|
|
50
|
+
amount: number;
|
|
51
|
+
recipient: string;
|
|
52
|
+
execute_before_secs: number;
|
|
53
|
+
instrument_id: string;
|
|
54
|
+
reason?: string;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export type PrepareTapRequest = {
|
|
58
|
+
type: "tap-request";
|
|
59
|
+
amount: number;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export type PreparePreapprovalRequest = {
|
|
63
|
+
type: "transfer-pre-approval-proposal";
|
|
64
|
+
receiver: string;
|
|
65
|
+
};
|
|
66
|
+
|
|
16
67
|
type OnboardingSubmitRequest = {
|
|
17
68
|
prepare_request: OnboardingPrepareRequest;
|
|
18
69
|
prepare_response: OnboardingPrepareResponse;
|
|
@@ -31,7 +82,7 @@ type TransactionSubmitRequest = {
|
|
|
31
82
|
signature: string;
|
|
32
83
|
};
|
|
33
84
|
|
|
34
|
-
type TransactionSubmitResponse = {
|
|
85
|
+
type TransactionSubmitResponse = { update_id: string };
|
|
35
86
|
|
|
36
87
|
export type InstrumentBalance = {
|
|
37
88
|
instrument_id: string;
|
|
@@ -63,6 +114,9 @@ export type CreatedEvent = BaseEvent & {
|
|
|
63
114
|
};
|
|
64
115
|
signatories: string[];
|
|
65
116
|
observers: string[];
|
|
117
|
+
details: {
|
|
118
|
+
createArguments: { fields: unknown[] };
|
|
119
|
+
};
|
|
66
120
|
};
|
|
67
121
|
|
|
68
122
|
type ExercisedEvent = BaseEvent & {
|
|
@@ -90,21 +144,165 @@ export type TxInfo = {
|
|
|
90
144
|
trace_context: string;
|
|
91
145
|
};
|
|
92
146
|
|
|
147
|
+
export type OperationInfo =
|
|
148
|
+
| {
|
|
149
|
+
uid: string;
|
|
150
|
+
transaction_hash: string;
|
|
151
|
+
transaction_timestamp: string;
|
|
152
|
+
status: "Success";
|
|
153
|
+
type: "Initialize";
|
|
154
|
+
senders: string[];
|
|
155
|
+
recipients: string[];
|
|
156
|
+
transfers: [
|
|
157
|
+
{
|
|
158
|
+
address: string;
|
|
159
|
+
type: "Initialize";
|
|
160
|
+
value: string;
|
|
161
|
+
asset: string;
|
|
162
|
+
details: {
|
|
163
|
+
type: "pre-approval";
|
|
164
|
+
};
|
|
165
|
+
},
|
|
166
|
+
];
|
|
167
|
+
block: {
|
|
168
|
+
height: number;
|
|
169
|
+
time: string;
|
|
170
|
+
hash: string;
|
|
171
|
+
};
|
|
172
|
+
fee: {
|
|
173
|
+
value: string;
|
|
174
|
+
asset: {
|
|
175
|
+
type: "native";
|
|
176
|
+
issuer: null;
|
|
177
|
+
};
|
|
178
|
+
details: {
|
|
179
|
+
type: string;
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
asset: {
|
|
183
|
+
type: "token";
|
|
184
|
+
issuer: string;
|
|
185
|
+
};
|
|
186
|
+
details: {
|
|
187
|
+
type: "pre-approval";
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
| {
|
|
191
|
+
uid: string;
|
|
192
|
+
transaction_hash: string;
|
|
193
|
+
transaction_timestamp: string;
|
|
194
|
+
status: "Success";
|
|
195
|
+
type: "Receive";
|
|
196
|
+
senders: string[];
|
|
197
|
+
recipients: string[];
|
|
198
|
+
transfers: [
|
|
199
|
+
{
|
|
200
|
+
address: string;
|
|
201
|
+
type: "Receive";
|
|
202
|
+
value: string;
|
|
203
|
+
asset: string;
|
|
204
|
+
details: {
|
|
205
|
+
type: "tap";
|
|
206
|
+
};
|
|
207
|
+
},
|
|
208
|
+
];
|
|
209
|
+
block: {
|
|
210
|
+
height: number;
|
|
211
|
+
time: string;
|
|
212
|
+
hash: string;
|
|
213
|
+
};
|
|
214
|
+
fee: {
|
|
215
|
+
value: string;
|
|
216
|
+
asset: {
|
|
217
|
+
type: "native";
|
|
218
|
+
issuer: null;
|
|
219
|
+
};
|
|
220
|
+
details: {
|
|
221
|
+
type: string;
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
asset: {
|
|
225
|
+
type: "native";
|
|
226
|
+
issuer: null;
|
|
227
|
+
};
|
|
228
|
+
details: {
|
|
229
|
+
type: "tap";
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
| {
|
|
233
|
+
uid: string;
|
|
234
|
+
transaction_hash: string;
|
|
235
|
+
transaction_timestamp: string;
|
|
236
|
+
status: "Success";
|
|
237
|
+
type: "Send";
|
|
238
|
+
senders: string[];
|
|
239
|
+
recipients: string[];
|
|
240
|
+
transfers: [
|
|
241
|
+
{
|
|
242
|
+
address: string;
|
|
243
|
+
type: "Send";
|
|
244
|
+
value: string;
|
|
245
|
+
asset: string;
|
|
246
|
+
details: {
|
|
247
|
+
type: "transfer";
|
|
248
|
+
};
|
|
249
|
+
},
|
|
250
|
+
];
|
|
251
|
+
block: {
|
|
252
|
+
height: number;
|
|
253
|
+
time: string;
|
|
254
|
+
hash: string;
|
|
255
|
+
};
|
|
256
|
+
fee: {
|
|
257
|
+
value: string;
|
|
258
|
+
asset: {
|
|
259
|
+
type: "native";
|
|
260
|
+
issuer: null;
|
|
261
|
+
};
|
|
262
|
+
details: {
|
|
263
|
+
type: string;
|
|
264
|
+
};
|
|
265
|
+
};
|
|
266
|
+
asset: {
|
|
267
|
+
type: "native";
|
|
268
|
+
issuer: null;
|
|
269
|
+
};
|
|
270
|
+
details: {
|
|
271
|
+
type: "transfer";
|
|
272
|
+
};
|
|
273
|
+
};
|
|
274
|
+
|
|
93
275
|
const getGatewayUrl = () => coinConfig.getCoinConfig().gatewayUrl;
|
|
94
|
-
const getNodeId = () => coinConfig.getCoinConfig().nodeId || "ledger-
|
|
276
|
+
const getNodeId = () => coinConfig.getCoinConfig().nodeId || "ledger-devnet-stg";
|
|
277
|
+
|
|
278
|
+
const gatewayNetwork = <T, U = unknown>(req: LiveNetworkRequest<U>) => {
|
|
279
|
+
const API_KEY = getEnv("CANTON_API_KEY");
|
|
280
|
+
return network<T, U>({
|
|
281
|
+
...req,
|
|
282
|
+
headers: {
|
|
283
|
+
...(req.headers || {}),
|
|
284
|
+
...(API_KEY && { "X-Ledger-Canton-Api-Key": API_KEY }),
|
|
285
|
+
},
|
|
286
|
+
});
|
|
287
|
+
};
|
|
95
288
|
|
|
96
289
|
export async function prepareOnboarding(
|
|
97
290
|
pubKey: string,
|
|
98
291
|
pubKeyType: string,
|
|
99
292
|
): Promise<OnboardingPrepareResponse> {
|
|
100
|
-
const
|
|
293
|
+
const gatewayUrl = getGatewayUrl();
|
|
294
|
+
const nodeId = getNodeId();
|
|
295
|
+
const fullUrl = `${gatewayUrl}/v1/node/${nodeId}/onboarding/prepare`;
|
|
296
|
+
|
|
297
|
+
const { data } = await gatewayNetwork<OnboardingPrepareResponse, OnboardingPrepareRequest>({
|
|
101
298
|
method: "POST",
|
|
102
|
-
url:
|
|
299
|
+
url: fullUrl,
|
|
103
300
|
data: {
|
|
104
301
|
public_key: pubKey,
|
|
105
302
|
public_key_type: pubKeyType,
|
|
106
|
-
}
|
|
303
|
+
},
|
|
107
304
|
});
|
|
305
|
+
|
|
108
306
|
return data;
|
|
109
307
|
}
|
|
110
308
|
|
|
@@ -113,58 +311,56 @@ export async function submitOnboarding(
|
|
|
113
311
|
prepareResponse: OnboardingPrepareResponse,
|
|
114
312
|
signature: string,
|
|
115
313
|
) {
|
|
116
|
-
const { data } = await
|
|
314
|
+
const { data } = await gatewayNetwork<OnboardingSubmitResponse, OnboardingSubmitRequest>({
|
|
117
315
|
method: "POST",
|
|
118
316
|
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/onboarding/submit`,
|
|
119
317
|
data: {
|
|
120
318
|
prepare_request: prepareRequest,
|
|
121
319
|
prepare_response: prepareResponse,
|
|
122
320
|
signature,
|
|
123
|
-
}
|
|
321
|
+
},
|
|
124
322
|
});
|
|
125
323
|
return data;
|
|
126
324
|
}
|
|
127
325
|
|
|
128
|
-
export async function submit(
|
|
129
|
-
const { data } = await
|
|
326
|
+
export async function submit(partyId: string, serialized: string, signature: string) {
|
|
327
|
+
const { data } = await gatewayNetwork<TransactionSubmitResponse, TransactionSubmitRequest>({
|
|
130
328
|
method: "POST",
|
|
131
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/transaction/submit`,
|
|
329
|
+
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/submit`,
|
|
132
330
|
data: {
|
|
133
|
-
serialized
|
|
331
|
+
serialized,
|
|
134
332
|
signature,
|
|
135
|
-
}
|
|
333
|
+
},
|
|
136
334
|
});
|
|
137
335
|
return data;
|
|
138
336
|
}
|
|
139
337
|
|
|
140
338
|
export async function getBalance(partyId: string): Promise<InstrumentBalance[]> {
|
|
141
|
-
const { data } = await
|
|
339
|
+
const { data } = await gatewayNetwork<InstrumentBalance[]>({
|
|
142
340
|
method: "GET",
|
|
143
|
-
|
|
341
|
+
// TODO: we need better solution ?
|
|
342
|
+
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId.replace(/_/g, ":")}/balance`,
|
|
144
343
|
});
|
|
145
344
|
return data;
|
|
146
345
|
}
|
|
147
346
|
|
|
148
347
|
export async function getPartyById(partyId: string): Promise<PartyInfo> {
|
|
149
|
-
return await getParty(partyId, "
|
|
348
|
+
return await getParty(partyId, "party-id");
|
|
150
349
|
}
|
|
151
350
|
|
|
152
351
|
export async function getPartyByPubKey(pubKey: string): Promise<PartyInfo> {
|
|
153
|
-
return await getParty(pubKey, "
|
|
352
|
+
return await getParty(pubKey, "public-key");
|
|
154
353
|
}
|
|
155
354
|
|
|
156
|
-
async function getParty(identifier: string, by: "
|
|
157
|
-
const { data } = await
|
|
355
|
+
async function getParty(identifier: string, by: "party-id" | "public-key"): Promise<PartyInfo> {
|
|
356
|
+
const { data } = await gatewayNetwork<PartyInfo>({
|
|
158
357
|
method: "GET",
|
|
159
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${identifier}`,
|
|
160
|
-
data: {
|
|
161
|
-
by,
|
|
162
|
-
},
|
|
358
|
+
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${identifier}?by=${by}`,
|
|
163
359
|
});
|
|
164
360
|
return data;
|
|
165
361
|
}
|
|
166
362
|
|
|
167
|
-
export async function
|
|
363
|
+
export async function getOperations(
|
|
168
364
|
partyId: string,
|
|
169
365
|
options?: {
|
|
170
366
|
cursor?: number | undefined;
|
|
@@ -174,23 +370,134 @@ export async function getTransactions(
|
|
|
174
370
|
},
|
|
175
371
|
): Promise<{
|
|
176
372
|
next: number;
|
|
177
|
-
|
|
373
|
+
operations: OperationInfo[];
|
|
178
374
|
}> {
|
|
179
|
-
const { data } = await
|
|
375
|
+
const { data } = await gatewayNetwork<{
|
|
180
376
|
next: number;
|
|
181
|
-
|
|
377
|
+
operations: OperationInfo[];
|
|
182
378
|
}>({
|
|
183
379
|
method: "GET",
|
|
184
|
-
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/
|
|
185
|
-
|
|
380
|
+
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId.replace(/_/g, ":")}/operations`,
|
|
381
|
+
params: options,
|
|
382
|
+
});
|
|
383
|
+
return data;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
type PrepareTapRequestRequest = {
|
|
387
|
+
partyId: string;
|
|
388
|
+
amount?: number;
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
type PrepareTapRequestResponse = {
|
|
392
|
+
serialized: "string";
|
|
393
|
+
json: null;
|
|
394
|
+
hash: "string";
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
enum TransactionType {
|
|
398
|
+
TAP_REQUEST = "tap-request",
|
|
399
|
+
TRANSFER_PRE_APPROVAL_PROPOSAL = "transfer-pre-approval-proposal",
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
export async function prepareTapRequest({
|
|
403
|
+
partyId,
|
|
404
|
+
amount = 1000000,
|
|
405
|
+
}: PrepareTapRequestRequest): Promise<PrepareTapRequestResponse> {
|
|
406
|
+
const { data } = await gatewayNetwork<
|
|
407
|
+
PrepareTapRequestResponse,
|
|
408
|
+
{ amount: number; type: string }
|
|
409
|
+
>({
|
|
410
|
+
method: "POST",
|
|
411
|
+
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/prepare`,
|
|
412
|
+
data: {
|
|
413
|
+
amount: parseInt(amount.toString(), 10), // Convert to integer to avoid scientific notation
|
|
414
|
+
type: TransactionType.TAP_REQUEST,
|
|
415
|
+
},
|
|
416
|
+
});
|
|
417
|
+
return data;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
type SubmitTapRequestRequest = {
|
|
421
|
+
partyId: string;
|
|
422
|
+
serialized: string;
|
|
423
|
+
signature: string;
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
type SubmitTapRequestResponse = {
|
|
427
|
+
submission_id: string;
|
|
428
|
+
update_id: string;
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
export async function submitTapRequest({
|
|
432
|
+
partyId,
|
|
433
|
+
serialized,
|
|
434
|
+
signature,
|
|
435
|
+
}: SubmitTapRequestRequest): Promise<SubmitTapRequestResponse> {
|
|
436
|
+
const { data } = await gatewayNetwork<
|
|
437
|
+
SubmitTapRequestResponse,
|
|
438
|
+
Omit<SubmitTapRequestRequest, "partyId">
|
|
439
|
+
>({
|
|
440
|
+
method: "POST",
|
|
441
|
+
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/submit`,
|
|
442
|
+
data: {
|
|
443
|
+
serialized,
|
|
444
|
+
signature,
|
|
445
|
+
},
|
|
446
|
+
});
|
|
447
|
+
return data;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
export async function prepareTransferRequest(
|
|
451
|
+
partyId: string,
|
|
452
|
+
params: PrepareTransferRequest,
|
|
453
|
+
): Promise<PrepareTransferResponse> {
|
|
454
|
+
const { data } = await network<PrepareTransferResponse>({
|
|
455
|
+
method: "POST",
|
|
456
|
+
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/prepare`,
|
|
457
|
+
data: params,
|
|
186
458
|
});
|
|
187
459
|
return data;
|
|
188
460
|
}
|
|
189
461
|
|
|
190
462
|
export async function getLedgerEnd(): Promise<number> {
|
|
191
|
-
const { data } = await
|
|
463
|
+
const { data } = await gatewayNetwork<number>({
|
|
192
464
|
method: "GET",
|
|
193
465
|
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/ledger-end`,
|
|
194
466
|
});
|
|
195
467
|
return data;
|
|
196
468
|
}
|
|
469
|
+
|
|
470
|
+
export async function preparePreApprovalTransaction(
|
|
471
|
+
partyId: string,
|
|
472
|
+
): Promise<PrepareTransactionResponse> {
|
|
473
|
+
const { data } = await gatewayNetwork<PrepareTransactionResponse, PrepareTransactionRequest>({
|
|
474
|
+
method: "POST",
|
|
475
|
+
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/prepare`,
|
|
476
|
+
data: {
|
|
477
|
+
type: TransactionType.TRANSFER_PRE_APPROVAL_PROPOSAL,
|
|
478
|
+
receiver: partyId,
|
|
479
|
+
},
|
|
480
|
+
});
|
|
481
|
+
return data;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
export async function submitPreApprovalTransaction(
|
|
485
|
+
partyId: string,
|
|
486
|
+
{ serialized }: PrepareTransactionResponse,
|
|
487
|
+
signature: string,
|
|
488
|
+
): Promise<PreApprovalResult> {
|
|
489
|
+
const { data } = await gatewayNetwork<SubmitTransactionResponse, SubmitTransactionRequest>({
|
|
490
|
+
method: "POST",
|
|
491
|
+
url: `${getGatewayUrl()}/v1/node/${getNodeId()}/party/${partyId}/transaction/submit`,
|
|
492
|
+
data: {
|
|
493
|
+
serialized,
|
|
494
|
+
signature,
|
|
495
|
+
},
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
return {
|
|
499
|
+
isApproved: true,
|
|
500
|
+
submissionId: data.submission_id,
|
|
501
|
+
updateId: data.update_id,
|
|
502
|
+
};
|
|
503
|
+
}
|