@cardano-sdk/key-management 0.2.0-nightly.9 → 0.2.1-nightly.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/dist/cjs/InMemoryKeyAgent.js +3 -3
- package/dist/cjs/KeyAgentBase.d.ts +2 -2
- package/dist/cjs/KeyAgentBase.js +8 -8
- package/dist/cjs/LedgerKeyAgent.d.ts.map +1 -1
- package/dist/cjs/LedgerKeyAgent.js +8 -3
- package/dist/cjs/LedgerKeyAgent.js.map +1 -1
- package/dist/cjs/TrezorKeyAgent.d.ts.map +1 -1
- package/dist/cjs/TrezorKeyAgent.js +8 -3
- package/dist/cjs/TrezorKeyAgent.js.map +1 -1
- package/dist/cjs/cip8/cip30signData.d.ts.map +1 -1
- package/dist/cjs/cip8/cip30signData.js +4 -3
- package/dist/cjs/cip8/cip30signData.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/cjs/util/key.d.ts +3 -3
- package/dist/cjs/util/key.js +4 -4
- package/dist/cjs/util/mapHardwareSigningData.d.ts +3 -3
- package/dist/cjs/util/mapHardwareSigningData.d.ts.map +1 -1
- package/dist/cjs/util/mapHardwareSigningData.js +198 -160
- package/dist/cjs/util/mapHardwareSigningData.js.map +1 -1
- package/dist/cjs/util/ownSignatureKeyPaths.d.ts.map +1 -1
- package/dist/cjs/util/ownSignatureKeyPaths.js +3 -1
- package/dist/cjs/util/ownSignatureKeyPaths.js.map +1 -1
- package/dist/esm/InMemoryKeyAgent.js +4 -4
- package/dist/esm/KeyAgentBase.d.ts +2 -2
- package/dist/esm/KeyAgentBase.js +9 -9
- package/dist/esm/LedgerKeyAgent.d.ts.map +1 -1
- package/dist/esm/LedgerKeyAgent.js +7 -2
- package/dist/esm/LedgerKeyAgent.js.map +1 -1
- package/dist/esm/TrezorKeyAgent.d.ts.map +1 -1
- package/dist/esm/TrezorKeyAgent.js +7 -2
- package/dist/esm/TrezorKeyAgent.js.map +1 -1
- package/dist/esm/cip8/cip30signData.d.ts.map +1 -1
- package/dist/esm/cip8/cip30signData.js +5 -4
- package/dist/esm/cip8/cip30signData.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/util/key.d.ts +3 -3
- package/dist/esm/util/key.js +5 -5
- package/dist/esm/util/mapHardwareSigningData.d.ts +3 -3
- package/dist/esm/util/mapHardwareSigningData.d.ts.map +1 -1
- package/dist/esm/util/mapHardwareSigningData.js +199 -161
- package/dist/esm/util/mapHardwareSigningData.js.map +1 -1
- package/dist/esm/util/ownSignatureKeyPaths.d.ts.map +1 -1
- package/dist/esm/util/ownSignatureKeyPaths.js +3 -1
- package/dist/esm/util/ownSignatureKeyPaths.js.map +1 -1
- package/package.json +9 -6
|
@@ -32,8 +32,8 @@ const trezor = __importStar(require("trezor-connect"));
|
|
|
32
32
|
const types_1 = require("../types");
|
|
33
33
|
const core_1 = require("@cardano-sdk/core");
|
|
34
34
|
const errors_1 = require("../errors");
|
|
35
|
-
const key_1 = require("./key");
|
|
36
35
|
const util_1 = require("@cardano-sdk/util");
|
|
36
|
+
const key_1 = require("./key");
|
|
37
37
|
const concat_1 = __importDefault(require("lodash/concat"));
|
|
38
38
|
const uniq_1 = __importDefault(require("lodash/uniq"));
|
|
39
39
|
const sortTokensCanonically = (tokens) => {
|
|
@@ -48,10 +48,13 @@ const sortTokensCanonically = (tokens) => {
|
|
|
48
48
|
return -1;
|
|
49
49
|
});
|
|
50
50
|
};
|
|
51
|
-
const getRewardAccountKeyHash = (rewardAccount) =>
|
|
52
|
-
.
|
|
53
|
-
.
|
|
54
|
-
.
|
|
51
|
+
const getRewardAccountKeyHash = (rewardAccount) => (0, util_1.usingAutoFree)((scope) => {
|
|
52
|
+
const address = scope.manage(core_1.CML.Address.from_bech32(rewardAccount.toString()));
|
|
53
|
+
const rewardAddress = scope.manage(core_1.CML.RewardAddress.from_address(address));
|
|
54
|
+
const paymentCred = scope.manage(rewardAddress.payment_cred());
|
|
55
|
+
const keyHash = scope.manage(paymentCred.to_keyhash());
|
|
56
|
+
return Buffer.from(keyHash.to_bytes()).toString('hex');
|
|
57
|
+
});
|
|
55
58
|
const bytesToIp = (bytes) => {
|
|
56
59
|
if (!bytes)
|
|
57
60
|
return null;
|
|
@@ -73,14 +76,16 @@ const matchGroupedAddress = (knownAddresses, outputAddress) => {
|
|
|
73
76
|
return knownAddresses.find(({ address }) => address.toString() === outputAddressBech32);
|
|
74
77
|
};
|
|
75
78
|
const prepareTrezorInputs = async (inputs, inputResolver, knownAddresses) => {
|
|
79
|
+
const scope = new util_1.ManagedFreeableScope();
|
|
76
80
|
const trezorInputs = [];
|
|
77
81
|
for (let i = 0; i < inputs.len(); i++) {
|
|
78
|
-
const input = inputs.get(i);
|
|
79
|
-
const
|
|
82
|
+
const input = scope.manage(inputs.get(i));
|
|
83
|
+
const inputTxId = scope.manage(input.transaction_id());
|
|
84
|
+
const coreInput = core_1.cmlToCore.txIn(input);
|
|
80
85
|
const paymentAddress = await inputResolver.resolveInputAddress(coreInput);
|
|
81
86
|
let trezorInput = {
|
|
82
|
-
prev_hash: Buffer.from(
|
|
83
|
-
prev_index: input.index()
|
|
87
|
+
prev_hash: Buffer.from(inputTxId.to_bytes()).toString('hex'),
|
|
88
|
+
prev_index: Number(scope.manage(input.index()).to_str())
|
|
84
89
|
};
|
|
85
90
|
let paymentKeyPath = null;
|
|
86
91
|
if (paymentAddress) {
|
|
@@ -101,23 +106,28 @@ const prepareTrezorInputs = async (inputs, inputResolver, knownAddresses) => {
|
|
|
101
106
|
}
|
|
102
107
|
trezorInputs.push(trezorInput);
|
|
103
108
|
}
|
|
109
|
+
scope.dispose();
|
|
104
110
|
return trezorInputs;
|
|
105
111
|
};
|
|
106
|
-
const prepareTrezorOutputs = (outputs, knownAddresses) => {
|
|
112
|
+
const prepareTrezorOutputs = (outputs, knownAddresses) => (0, util_1.usingAutoFree)((scope) => {
|
|
107
113
|
const trezorOutputs = [];
|
|
108
114
|
for (let i = 0; i < outputs.len(); i++) {
|
|
109
|
-
const output = outputs.get(i);
|
|
110
|
-
const
|
|
115
|
+
const output = scope.manage(outputs.get(i));
|
|
116
|
+
const outputAmount = scope.manage(output.amount());
|
|
117
|
+
const outputAddress = scope.manage(output.address());
|
|
118
|
+
const multiAsset = scope.manage(outputAmount.multiasset());
|
|
111
119
|
const tokenBundle = [];
|
|
112
120
|
if (multiAsset) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const
|
|
121
|
+
const multiAssetKeys = scope.manage(multiAsset.keys());
|
|
122
|
+
for (let j = 0; j < multiAssetKeys.len(); j++) {
|
|
123
|
+
const policy = scope.manage(multiAssetKeys.get(j));
|
|
124
|
+
const assets = scope.manage(multiAsset.get(policy));
|
|
116
125
|
const tokens = [];
|
|
117
126
|
if (assets) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const
|
|
127
|
+
const assetsKeys = scope.manage(assets.keys());
|
|
128
|
+
for (let k = 0; k < assetsKeys.len(); k++) {
|
|
129
|
+
const assetName = scope.manage(assetsKeys.get(k));
|
|
130
|
+
const amount = scope.manage(assets.get(assetName));
|
|
121
131
|
if (assetName && amount) {
|
|
122
132
|
tokens.push({
|
|
123
133
|
amount: amount.to_str(),
|
|
@@ -133,8 +143,8 @@ const prepareTrezorOutputs = (outputs, knownAddresses) => {
|
|
|
133
143
|
});
|
|
134
144
|
}
|
|
135
145
|
}
|
|
136
|
-
const
|
|
137
|
-
const ownAddress = matchGroupedAddress(knownAddresses,
|
|
146
|
+
const outputAddressBytes = Buffer.from(outputAddress.to_bytes());
|
|
147
|
+
const ownAddress = matchGroupedAddress(knownAddresses, outputAddressBytes);
|
|
138
148
|
const destination = ownAddress
|
|
139
149
|
? {
|
|
140
150
|
addressParameters: {
|
|
@@ -144,26 +154,27 @@ const prepareTrezorOutputs = (outputs, knownAddresses) => {
|
|
|
144
154
|
}
|
|
145
155
|
}
|
|
146
156
|
: {
|
|
147
|
-
address:
|
|
157
|
+
address: outputAddress.to_bech32()
|
|
148
158
|
};
|
|
149
159
|
const outputRes = {
|
|
150
160
|
...destination,
|
|
151
|
-
amount:
|
|
161
|
+
amount: scope.manage(outputAmount.coin()).to_str(),
|
|
152
162
|
tokenBundle
|
|
153
163
|
};
|
|
154
164
|
trezorOutputs.push(outputRes);
|
|
155
165
|
}
|
|
156
166
|
return trezorOutputs;
|
|
157
|
-
};
|
|
158
|
-
const prepareTrezorCertificates = (certificates, rewardAccountKeyPath, rewardAccountKeyHash) => {
|
|
167
|
+
});
|
|
168
|
+
const prepareTrezorCertificates = (certificates, rewardAccountKeyPath, rewardAccountKeyHash) => (0, util_1.usingAutoFree)((scope) => {
|
|
159
169
|
let signingMode;
|
|
160
170
|
const certs = [];
|
|
161
171
|
for (let i = 0; i < certificates.len(); i++) {
|
|
162
|
-
const cert = certificates.get(i);
|
|
172
|
+
const cert = scope.manage(certificates.get(i));
|
|
163
173
|
const certificate = {};
|
|
164
174
|
if (cert.kind() === 0) {
|
|
165
|
-
const
|
|
166
|
-
const
|
|
175
|
+
const stakeRegistration = scope.manage(cert.as_stake_registration());
|
|
176
|
+
const credential = scope.manage(stakeRegistration?.stake_credential());
|
|
177
|
+
const credentialScriptHash = scope.manage(credential?.to_scripthash());
|
|
167
178
|
certificate.type = trezor.CardanoCertificateType.STAKE_REGISTRATION;
|
|
168
179
|
if (credential?.kind() === 0) {
|
|
169
180
|
certificate.path = rewardAccountKeyPath;
|
|
@@ -173,8 +184,9 @@ const prepareTrezorCertificates = (certificates, rewardAccountKeyPath, rewardAcc
|
|
|
173
184
|
}
|
|
174
185
|
}
|
|
175
186
|
else if (cert.kind() === 1) {
|
|
176
|
-
const
|
|
177
|
-
const
|
|
187
|
+
const stakeDeregistration = scope.manage(cert.as_stake_deregistration());
|
|
188
|
+
const credential = scope.manage(stakeDeregistration?.stake_credential());
|
|
189
|
+
const credentialScriptHash = scope.manage(credential?.to_scripthash());
|
|
178
190
|
certificate.type = trezor.CardanoCertificateType.STAKE_DEREGISTRATION;
|
|
179
191
|
if (credential?.kind() === 0) {
|
|
180
192
|
certificate.path = rewardAccountKeyPath;
|
|
@@ -184,10 +196,10 @@ const prepareTrezorCertificates = (certificates, rewardAccountKeyPath, rewardAcc
|
|
|
184
196
|
}
|
|
185
197
|
}
|
|
186
198
|
else if (cert.kind() === 2) {
|
|
187
|
-
const delegation = cert.as_stake_delegation();
|
|
188
|
-
const delegationPoolKeyHash = delegation?.pool_keyhash();
|
|
189
|
-
const credential = delegation?.stake_credential();
|
|
190
|
-
const credentialScriptHash = credential?.to_scripthash();
|
|
199
|
+
const delegation = scope.manage(cert.as_stake_delegation());
|
|
200
|
+
const delegationPoolKeyHash = scope.manage(delegation?.pool_keyhash());
|
|
201
|
+
const credential = scope.manage(delegation?.stake_credential());
|
|
202
|
+
const credentialScriptHash = scope.manage(credential?.to_scripthash());
|
|
191
203
|
certificate.type = trezor.CardanoCertificateType.STAKE_DELEGATION;
|
|
192
204
|
if (credential?.kind() === 0) {
|
|
193
205
|
certificate.path = rewardAccountKeyPath;
|
|
@@ -200,16 +212,18 @@ const prepareTrezorCertificates = (certificates, rewardAccountKeyPath, rewardAcc
|
|
|
200
212
|
}
|
|
201
213
|
}
|
|
202
214
|
else if (cert.kind() === 3) {
|
|
203
|
-
const
|
|
215
|
+
const poolRegistration = scope.manage(cert.as_pool_registration());
|
|
216
|
+
const params = scope.manage(poolRegistration?.pool_params());
|
|
204
217
|
if (!params) {
|
|
205
218
|
throw new errors_1.HwMappingError('Missing pool registration pool parameters.');
|
|
206
219
|
}
|
|
207
220
|
certificate.type = trezor.CardanoCertificateType.STAKE_POOL_REGISTRATION;
|
|
208
|
-
const owners = params?.pool_owners();
|
|
221
|
+
const owners = scope.manage(params?.pool_owners());
|
|
209
222
|
const poolOwners = [];
|
|
210
223
|
if (owners) {
|
|
211
224
|
for (let j = 0; j < owners.len(); j++) {
|
|
212
|
-
const
|
|
225
|
+
const owner = scope.manage(owners.get(j));
|
|
226
|
+
const keyHash = Buffer.from(owner.to_bytes()).toString('hex');
|
|
213
227
|
if (keyHash === rewardAccountKeyHash) {
|
|
214
228
|
signingMode = trezor.CardanoTxSigningMode.POOL_REGISTRATION_AS_OWNER;
|
|
215
229
|
poolOwners.push({
|
|
@@ -223,17 +237,19 @@ const prepareTrezorCertificates = (certificates, rewardAccountKeyPath, rewardAcc
|
|
|
223
237
|
}
|
|
224
238
|
}
|
|
225
239
|
}
|
|
226
|
-
const relays = params?.relays();
|
|
240
|
+
const relays = scope.manage(params?.relays());
|
|
227
241
|
const trezorRelays = [];
|
|
228
242
|
if (relays) {
|
|
229
243
|
for (let k = 0; k < relays.len(); k++) {
|
|
230
|
-
const relay = relays.get(k);
|
|
244
|
+
const relay = scope.manage(relays.get(k));
|
|
231
245
|
if (relay.kind() === 0) {
|
|
232
|
-
const singleHostAddr = relay.as_single_host_addr();
|
|
246
|
+
const singleHostAddr = scope.manage(relay.as_single_host_addr());
|
|
233
247
|
const type = trezor.CardanoPoolRelayType.SINGLE_HOST_IP;
|
|
234
248
|
const port = singleHostAddr?.port();
|
|
235
|
-
const
|
|
236
|
-
const
|
|
249
|
+
const ipv4 = scope.manage(singleHostAddr?.ipv4());
|
|
250
|
+
const ipv4Address = ipv4 ? bytesToIp(ipv4?.ip()) : null;
|
|
251
|
+
const ipv6 = scope.manage(singleHostAddr?.ipv6());
|
|
252
|
+
const ipv6Address = ipv6 ? bytesToIp(ipv6?.ip()) : null;
|
|
237
253
|
trezorRelays.push({
|
|
238
254
|
ipv4Address: ipv4Address || undefined,
|
|
239
255
|
ipv6Address: ipv6Address || undefined,
|
|
@@ -243,10 +259,10 @@ const prepareTrezorCertificates = (certificates, rewardAccountKeyPath, rewardAcc
|
|
|
243
259
|
}
|
|
244
260
|
else if (relay.kind() === 1) {
|
|
245
261
|
const type = trezor.CardanoPoolRelayType.SINGLE_HOST_NAME;
|
|
246
|
-
const singleHostName = relay.as_single_host_name();
|
|
262
|
+
const singleHostName = scope.manage(relay.as_single_host_name());
|
|
247
263
|
if (singleHostName) {
|
|
248
264
|
const port = singleHostName.port();
|
|
249
|
-
const hostName = singleHostName.dns_name().record();
|
|
265
|
+
const hostName = scope.manage(singleHostName.dns_name()).record();
|
|
250
266
|
trezorRelays.push({
|
|
251
267
|
hostName,
|
|
252
268
|
port,
|
|
@@ -256,8 +272,8 @@ const prepareTrezorCertificates = (certificates, rewardAccountKeyPath, rewardAcc
|
|
|
256
272
|
}
|
|
257
273
|
else if (relay.kind() === 2) {
|
|
258
274
|
const type = trezor.CardanoPoolRelayType.MULTIPLE_HOST_NAME;
|
|
259
|
-
const multiHostName = relay.as_multi_host_name();
|
|
260
|
-
const hostName = multiHostName?.dns_name()
|
|
275
|
+
const multiHostName = scope.manage(relay.as_multi_host_name());
|
|
276
|
+
const hostName = scope.manage(multiHostName?.dns_name())?.record();
|
|
261
277
|
if (hostName) {
|
|
262
278
|
trezorRelays.push({
|
|
263
279
|
hostName,
|
|
@@ -267,20 +283,21 @@ const prepareTrezorCertificates = (certificates, rewardAccountKeyPath, rewardAcc
|
|
|
267
283
|
}
|
|
268
284
|
}
|
|
269
285
|
}
|
|
270
|
-
const cost = params?.cost().to_str();
|
|
271
|
-
const margin = params?.margin();
|
|
272
|
-
const pledge = params?.pledge().to_str();
|
|
273
|
-
const poolId = Buffer.from(params.operator().to_bytes()).toString('hex');
|
|
274
|
-
const poolMetadata = params.pool_metadata();
|
|
286
|
+
const cost = scope.manage(params?.cost()).to_str();
|
|
287
|
+
const margin = scope.manage(params?.margin());
|
|
288
|
+
const pledge = scope.manage(params?.pledge()).to_str();
|
|
289
|
+
const poolId = Buffer.from(scope.manage(params.operator()).to_bytes()).toString('hex');
|
|
290
|
+
const poolMetadata = scope.manage(params.pool_metadata());
|
|
275
291
|
if (!poolMetadata) {
|
|
276
292
|
throw new errors_1.HwMappingError('Missing pool metadata.');
|
|
277
293
|
}
|
|
278
294
|
const metadata = {
|
|
279
|
-
hash: Buffer.from(poolMetadata.pool_metadata_hash().to_bytes()).toString('hex'),
|
|
280
|
-
url: poolMetadata.url().url()
|
|
295
|
+
hash: Buffer.from(scope.manage(poolMetadata.pool_metadata_hash()).to_bytes()).toString('hex'),
|
|
296
|
+
url: scope.manage(poolMetadata.url()).url()
|
|
281
297
|
};
|
|
282
|
-
const rewardAccount = params.reward_account()
|
|
283
|
-
const
|
|
298
|
+
const rewardAccount = scope.manage(params.reward_account());
|
|
299
|
+
const rewardAccountBech32 = scope.manage(rewardAccount.to_address()).to_bech32();
|
|
300
|
+
const vrfKeyHash = Buffer.from(scope.manage(params.vrf_keyhash()).to_bytes()).toString('hex');
|
|
284
301
|
certificate.poolParameters = {
|
|
285
302
|
cost,
|
|
286
303
|
margin: {
|
|
@@ -292,7 +309,7 @@ const prepareTrezorCertificates = (certificates, rewardAccountKeyPath, rewardAcc
|
|
|
292
309
|
pledge,
|
|
293
310
|
poolId,
|
|
294
311
|
relays: trezorRelays,
|
|
295
|
-
rewardAccount,
|
|
312
|
+
rewardAccount: rewardAccountBech32,
|
|
296
313
|
vrfKeyHash
|
|
297
314
|
};
|
|
298
315
|
}
|
|
@@ -302,21 +319,22 @@ const prepareTrezorCertificates = (certificates, rewardAccountKeyPath, rewardAcc
|
|
|
302
319
|
certs,
|
|
303
320
|
signingMode
|
|
304
321
|
};
|
|
305
|
-
};
|
|
306
|
-
const prepareTrezorWithdrawals = (withdrawals, rewardAccountKeyPath) => {
|
|
322
|
+
});
|
|
323
|
+
const prepareTrezorWithdrawals = (withdrawals, rewardAccountKeyPath) => (0, util_1.usingAutoFree)((scope) => {
|
|
307
324
|
const trezorWithdrawals = [];
|
|
308
|
-
|
|
325
|
+
const withdrawalsKeys = scope.manage(withdrawals.keys());
|
|
326
|
+
for (let i = 0; i < withdrawalsKeys.len(); i++) {
|
|
309
327
|
const withdrawal = {};
|
|
310
|
-
const rewardAddress =
|
|
311
|
-
const paymentCredentials = rewardAddress.payment_cred();
|
|
312
|
-
const paymentCredentialsScriptHash = paymentCredentials.to_scripthash();
|
|
313
|
-
if (
|
|
328
|
+
const rewardAddress = scope.manage(withdrawalsKeys.get(i));
|
|
329
|
+
const paymentCredentials = scope.manage(rewardAddress.payment_cred());
|
|
330
|
+
const paymentCredentialsScriptHash = scope.manage(paymentCredentials.to_scripthash());
|
|
331
|
+
if (paymentCredentials.kind() === 0) {
|
|
314
332
|
withdrawal.path = rewardAccountKeyPath;
|
|
315
333
|
}
|
|
316
334
|
else if (paymentCredentialsScriptHash) {
|
|
317
335
|
withdrawal.scriptHash = Buffer.from(paymentCredentialsScriptHash.to_bytes()).toString('hex');
|
|
318
336
|
}
|
|
319
|
-
const withdrawalAmount = withdrawals.get(rewardAddress);
|
|
337
|
+
const withdrawalAmount = scope.manage(withdrawals.get(rewardAddress));
|
|
320
338
|
if (!withdrawalAmount) {
|
|
321
339
|
throw new errors_1.HwMappingError('Withdrawal amount is not defined.');
|
|
322
340
|
}
|
|
@@ -324,20 +342,22 @@ const prepareTrezorWithdrawals = (withdrawals, rewardAccountKeyPath) => {
|
|
|
324
342
|
trezorWithdrawals.push(withdrawal);
|
|
325
343
|
}
|
|
326
344
|
return trezorWithdrawals;
|
|
327
|
-
};
|
|
328
|
-
const prepareTrezorMintBundle = (mint, paymentKeyPaths, rewardAccountKeyPath) => {
|
|
345
|
+
});
|
|
346
|
+
const prepareTrezorMintBundle = (mint, paymentKeyPaths, rewardAccountKeyPath) => (0, util_1.usingAutoFree)((scope) => {
|
|
329
347
|
const additionalWitnessPaths = [];
|
|
330
348
|
const mintAssetsGroup = [];
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const
|
|
349
|
+
const mintKeys = scope.manage(mint.keys());
|
|
350
|
+
for (let j = 0; j < mintKeys.len(); j++) {
|
|
351
|
+
const policy = scope.manage(mintKeys.get(j));
|
|
352
|
+
const assets = scope.manage(mint.get(policy));
|
|
334
353
|
const tokens = [];
|
|
335
354
|
if (assets) {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
const
|
|
339
|
-
const
|
|
340
|
-
const
|
|
355
|
+
const assetsKeys = scope.manage(assets.keys());
|
|
356
|
+
for (let k = 0; k < assetsKeys.len(); k++) {
|
|
357
|
+
const assetName = scope.manage(assetsKeys.get(k));
|
|
358
|
+
const amount = scope.manage(assets.get(assetName));
|
|
359
|
+
const positiveAmount = scope.manage(amount?.as_positive())?.to_str();
|
|
360
|
+
const negativeAmount = scope.manage(amount?.as_negative())?.to_str();
|
|
341
361
|
if (!amount || !positiveAmount || !negativeAmount) {
|
|
342
362
|
throw new errors_1.HwMappingError('Missing token amount.');
|
|
343
363
|
}
|
|
@@ -361,12 +381,13 @@ const prepareTrezorMintBundle = (mint, paymentKeyPaths, rewardAccountKeyPath) =>
|
|
|
361
381
|
additionalWitnessPaths,
|
|
362
382
|
mintAssetsGroup
|
|
363
383
|
};
|
|
364
|
-
};
|
|
384
|
+
});
|
|
365
385
|
const prepareLedgerInputs = async (inputs, inputResolver, knownAddresses) => {
|
|
386
|
+
const scope = new util_1.ManagedFreeableScope();
|
|
366
387
|
const ledgerInputs = [];
|
|
367
388
|
for (let i = 0; i < inputs.len(); i++) {
|
|
368
|
-
const input = inputs.get(i);
|
|
369
|
-
const coreInput = core_1.
|
|
389
|
+
const input = scope.manage(inputs.get(i));
|
|
390
|
+
const coreInput = core_1.cmlToCore.txIn(input);
|
|
370
391
|
const paymentAddress = await inputResolver.resolveInputAddress(coreInput);
|
|
371
392
|
let paymentKeyPath = null;
|
|
372
393
|
if (paymentAddress) {
|
|
@@ -382,28 +403,32 @@ const prepareLedgerInputs = async (inputs, inputResolver, knownAddresses) => {
|
|
|
382
403
|
}
|
|
383
404
|
}
|
|
384
405
|
ledgerInputs.push({
|
|
385
|
-
outputIndex: input.index(),
|
|
406
|
+
outputIndex: Number(scope.manage(input.index()).to_str()),
|
|
386
407
|
path: paymentKeyPath,
|
|
387
|
-
txHashHex: Buffer.from(input.transaction_id().to_bytes()).toString('hex')
|
|
408
|
+
txHashHex: Buffer.from(scope.manage(input.transaction_id()).to_bytes()).toString('hex')
|
|
388
409
|
});
|
|
389
410
|
}
|
|
411
|
+
scope.dispose();
|
|
390
412
|
return ledgerInputs;
|
|
391
413
|
};
|
|
392
|
-
const prepareLedgerOutputs = (outputs, knownAddresses) => {
|
|
414
|
+
const prepareLedgerOutputs = (outputs, knownAddresses) => (0, util_1.usingAutoFree)((scope) => {
|
|
393
415
|
const ledgerOutputs = [];
|
|
394
416
|
for (let i = 0; i < outputs.len(); i++) {
|
|
395
|
-
const output = outputs.get(i);
|
|
396
|
-
const
|
|
417
|
+
const output = scope.manage(outputs.get(i));
|
|
418
|
+
const outputAmount = scope.manage(output.amount());
|
|
419
|
+
const multiAsset = scope.manage(outputAmount.multiasset());
|
|
397
420
|
const tokenBundle = [];
|
|
398
421
|
if (multiAsset) {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
const
|
|
422
|
+
const multiAssetKeys = scope.manage(multiAsset.keys());
|
|
423
|
+
for (let j = 0; j < multiAssetKeys.len(); j++) {
|
|
424
|
+
const policy = scope.manage(multiAssetKeys.get(j));
|
|
425
|
+
const assets = scope.manage(multiAsset.get(policy));
|
|
402
426
|
const tokens = [];
|
|
403
427
|
if (assets) {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
const
|
|
428
|
+
const assetsKeys = scope.manage(assets.keys());
|
|
429
|
+
for (let k = 0; k < assetsKeys.len(); k++) {
|
|
430
|
+
const assetName = scope.manage(assetsKeys.get(k));
|
|
431
|
+
const amount = scope.manage(assets.get(assetName));
|
|
407
432
|
if (assetName && amount) {
|
|
408
433
|
tokens.push({
|
|
409
434
|
amount: amount.to_str(),
|
|
@@ -419,7 +444,7 @@ const prepareLedgerOutputs = (outputs, knownAddresses) => {
|
|
|
419
444
|
});
|
|
420
445
|
}
|
|
421
446
|
}
|
|
422
|
-
const outputAddress = Buffer.from(output.address().to_bytes());
|
|
447
|
+
const outputAddress = Buffer.from(scope.manage(output.address()).to_bytes());
|
|
423
448
|
const ownAddress = matchGroupedAddress(knownAddresses, outputAddress);
|
|
424
449
|
const destination = ownAddress
|
|
425
450
|
? {
|
|
@@ -450,10 +475,10 @@ const prepareLedgerOutputs = (outputs, knownAddresses) => {
|
|
|
450
475
|
},
|
|
451
476
|
type: ledger.TxOutputDestinationType.THIRD_PARTY
|
|
452
477
|
};
|
|
453
|
-
const outputDataHash = output.
|
|
478
|
+
const outputDataHash = scope.manage(scope.manage(output.datum())?.as_data_hash());
|
|
454
479
|
const datumHashHex = outputDataHash ? Buffer.from(outputDataHash.to_bytes()).toString('hex') : null;
|
|
455
480
|
const outputRes = {
|
|
456
|
-
amount:
|
|
481
|
+
amount: scope.manage(outputAmount.coin()).to_str(),
|
|
457
482
|
datumHashHex,
|
|
458
483
|
destination,
|
|
459
484
|
tokenBundle
|
|
@@ -461,16 +486,17 @@ const prepareLedgerOutputs = (outputs, knownAddresses) => {
|
|
|
461
486
|
ledgerOutputs.push(outputRes);
|
|
462
487
|
}
|
|
463
488
|
return ledgerOutputs;
|
|
464
|
-
};
|
|
465
|
-
const prepareLedgerCertificates = (certificates, knownAddresses, rewardAccountKeyPath, rewardAccountKeyHash) => {
|
|
489
|
+
});
|
|
490
|
+
const prepareLedgerCertificates = (certificates, knownAddresses, rewardAccountKeyPath, rewardAccountKeyHash) => (0, util_1.usingAutoFree)((scope) => {
|
|
466
491
|
let signingMode;
|
|
467
492
|
const certs = [];
|
|
468
493
|
for (let i = 0; i < certificates.len(); i++) {
|
|
469
|
-
const cert = certificates.get(i);
|
|
494
|
+
const cert = scope.manage(certificates.get(i));
|
|
470
495
|
const certificate = {};
|
|
471
496
|
if (cert.kind() === 0) {
|
|
472
|
-
const
|
|
473
|
-
const
|
|
497
|
+
const stakeRegistration = scope.manage(cert.as_stake_registration());
|
|
498
|
+
const credential = scope.manage(stakeRegistration?.stake_credential());
|
|
499
|
+
const credentialScriptHash = scope.manage(credential?.to_scripthash());
|
|
474
500
|
certificate.type = ledger.CertificateType.STAKE_REGISTRATION;
|
|
475
501
|
if (credential?.kind() === 0) {
|
|
476
502
|
certificate.params = {
|
|
@@ -491,8 +517,9 @@ const prepareLedgerCertificates = (certificates, knownAddresses, rewardAccountKe
|
|
|
491
517
|
}
|
|
492
518
|
}
|
|
493
519
|
else if (cert.kind() === 1) {
|
|
494
|
-
const
|
|
495
|
-
const
|
|
520
|
+
const stakeDeregistration = scope.manage(cert.as_stake_deregistration());
|
|
521
|
+
const credential = scope.manage(stakeDeregistration?.stake_credential());
|
|
522
|
+
const credentialScriptHash = scope.manage(credential?.to_scripthash());
|
|
496
523
|
certificate.type = ledger.CertificateType.STAKE_DEREGISTRATION;
|
|
497
524
|
if (credential?.kind() === 0) {
|
|
498
525
|
certificate.params = {
|
|
@@ -513,10 +540,10 @@ const prepareLedgerCertificates = (certificates, knownAddresses, rewardAccountKe
|
|
|
513
540
|
}
|
|
514
541
|
}
|
|
515
542
|
else if (cert.kind() === 2) {
|
|
516
|
-
const delegation = cert.as_stake_delegation();
|
|
517
|
-
const delegationPoolKeyHash = delegation?.pool_keyhash();
|
|
518
|
-
const credential = delegation?.stake_credential();
|
|
519
|
-
const credentialScriptHash = credential?.to_scripthash();
|
|
543
|
+
const delegation = scope.manage(cert.as_stake_delegation());
|
|
544
|
+
const delegationPoolKeyHash = scope.manage(delegation?.pool_keyhash());
|
|
545
|
+
const credential = scope.manage(delegation?.stake_credential());
|
|
546
|
+
const credentialScriptHash = scope.manage(credential?.to_scripthash());
|
|
520
547
|
certificate.type = ledger.CertificateType.STAKE_DELEGATION;
|
|
521
548
|
if (credential?.kind() === 0) {
|
|
522
549
|
certificate.params = {
|
|
@@ -543,16 +570,17 @@ const prepareLedgerCertificates = (certificates, knownAddresses, rewardAccountKe
|
|
|
543
570
|
}
|
|
544
571
|
}
|
|
545
572
|
else if (cert.kind() === 3) {
|
|
546
|
-
const
|
|
573
|
+
const poolRegistration = scope.manage(cert.as_pool_registration());
|
|
574
|
+
const params = scope.manage(poolRegistration?.pool_params());
|
|
547
575
|
if (!params) {
|
|
548
576
|
throw new errors_1.HwMappingError('Missing pool registration pool parameters.');
|
|
549
577
|
}
|
|
550
578
|
certificate.type = ledger.CertificateType.STAKE_POOL_REGISTRATION;
|
|
551
|
-
const owners = params?.pool_owners();
|
|
579
|
+
const owners = scope.manage(params?.pool_owners());
|
|
552
580
|
const poolOwners = [];
|
|
553
581
|
if (owners) {
|
|
554
582
|
for (let j = 0; j < owners.len(); j++) {
|
|
555
|
-
const keyHash = Buffer.from(owners.get(j).to_bytes()).toString('hex');
|
|
583
|
+
const keyHash = Buffer.from(scope.manage(owners.get(j)).to_bytes()).toString('hex');
|
|
556
584
|
if (keyHash === rewardAccountKeyHash) {
|
|
557
585
|
signingMode = ledger.TransactionSigningMode.POOL_REGISTRATION_AS_OWNER;
|
|
558
586
|
poolOwners.push({
|
|
@@ -572,25 +600,27 @@ const prepareLedgerCertificates = (certificates, knownAddresses, rewardAccountKe
|
|
|
572
600
|
}
|
|
573
601
|
}
|
|
574
602
|
}
|
|
575
|
-
const relays = params?.relays();
|
|
603
|
+
const relays = scope.manage(params?.relays());
|
|
576
604
|
const ledgerRelays = [];
|
|
577
605
|
if (relays) {
|
|
578
606
|
for (let k = 0; k < relays.len(); k++) {
|
|
579
|
-
const relay = relays.get(k);
|
|
607
|
+
const relay = scope.manage(relays.get(k));
|
|
580
608
|
if (relay.kind() === 0) {
|
|
581
|
-
const singleHostAddr = relay.as_single_host_addr();
|
|
609
|
+
const singleHostAddr = scope.manage(relay.as_single_host_addr());
|
|
582
610
|
const type = 0;
|
|
583
611
|
const portNumber = singleHostAddr?.port();
|
|
584
|
-
const ipv4 = singleHostAddr?.ipv4()
|
|
585
|
-
const ipv6 = singleHostAddr?.ipv6()
|
|
586
|
-
|
|
612
|
+
const ipv4 = scope.manage(singleHostAddr?.ipv4());
|
|
613
|
+
const ipv6 = scope.manage(singleHostAddr?.ipv6());
|
|
614
|
+
const ipv4Address = ipv4 ? bytesToIp(ipv4.ip()) : null;
|
|
615
|
+
const ipv6Address = ipv6 ? bytesToIp(ipv6.ip()) : null;
|
|
616
|
+
ledgerRelays.push({ params: { ipv4: ipv4Address, ipv6: ipv6Address, portNumber }, type });
|
|
587
617
|
}
|
|
588
618
|
else if (relay.kind() === 1) {
|
|
589
619
|
const type = 1;
|
|
590
|
-
const singleHostName = relay.as_single_host_name();
|
|
620
|
+
const singleHostName = scope.manage(relay.as_single_host_name());
|
|
591
621
|
if (singleHostName) {
|
|
592
622
|
const portNumber = singleHostName.port();
|
|
593
|
-
const dnsName = singleHostName.dns_name().record();
|
|
623
|
+
const dnsName = scope.manage(singleHostName.dns_name()).record();
|
|
594
624
|
ledgerRelays.push({
|
|
595
625
|
params: { dnsName, portNumber },
|
|
596
626
|
type
|
|
@@ -599,8 +629,8 @@ const prepareLedgerCertificates = (certificates, knownAddresses, rewardAccountKe
|
|
|
599
629
|
}
|
|
600
630
|
else if (relay.kind() === 2) {
|
|
601
631
|
const type = 2;
|
|
602
|
-
const multiHostName = relay.as_multi_host_name();
|
|
603
|
-
const dnsName = multiHostName?.dns_name()
|
|
632
|
+
const multiHostName = scope.manage(relay.as_multi_host_name());
|
|
633
|
+
const dnsName = scope.manage(multiHostName?.dns_name())?.record();
|
|
604
634
|
if (dnsName) {
|
|
605
635
|
ledgerRelays.push({
|
|
606
636
|
params: { dnsName },
|
|
@@ -610,10 +640,10 @@ const prepareLedgerCertificates = (certificates, knownAddresses, rewardAccountKe
|
|
|
610
640
|
}
|
|
611
641
|
}
|
|
612
642
|
}
|
|
613
|
-
const cost = params?.cost().to_str();
|
|
614
|
-
const margin = params?.margin();
|
|
615
|
-
const pledge = params?.pledge().to_str();
|
|
616
|
-
const operator = Buffer.from(params.operator().to_bytes()).toString('hex');
|
|
643
|
+
const cost = scope.manage(params?.cost()).to_str();
|
|
644
|
+
const margin = scope.manage(params?.margin());
|
|
645
|
+
const pledge = scope.manage(params?.pledge()).to_str();
|
|
646
|
+
const operator = Buffer.from(scope.manage(params.operator()).to_bytes()).toString('hex');
|
|
617
647
|
let poolKey;
|
|
618
648
|
if (operator === rewardAccountKeyHash) {
|
|
619
649
|
signingMode = ledger.TransactionSigningMode.POOL_REGISTRATION_AS_OPERATOR;
|
|
@@ -628,14 +658,15 @@ const prepareLedgerCertificates = (certificates, knownAddresses, rewardAccountKe
|
|
|
628
658
|
type: ledger.PoolKeyType.THIRD_PARTY
|
|
629
659
|
};
|
|
630
660
|
}
|
|
631
|
-
const poolMetadata = params.pool_metadata();
|
|
661
|
+
const poolMetadata = scope.manage(params.pool_metadata());
|
|
632
662
|
const metadata = poolMetadata
|
|
633
663
|
? {
|
|
634
|
-
metadataHashHex: Buffer.from(poolMetadata.pool_metadata_hash().to_bytes()).toString('hex'),
|
|
635
|
-
metadataUrl: poolMetadata.url().url()
|
|
664
|
+
metadataHashHex: Buffer.from(scope.manage(poolMetadata.pool_metadata_hash()).to_bytes()).toString('hex'),
|
|
665
|
+
metadataUrl: scope.manage(poolMetadata.url()).url()
|
|
636
666
|
}
|
|
637
667
|
: null;
|
|
638
|
-
const
|
|
668
|
+
const poolRewardAccount = scope.manage(params.reward_account());
|
|
669
|
+
const rewardAccountBytes = Buffer.from(scope.manage(poolRewardAccount.to_address()).to_bytes());
|
|
639
670
|
const isDeviceOwned = knownAddresses.some(({ address }) => address.toString() === ledger.utils.bech32_encodeAddress(rewardAccountBytes));
|
|
640
671
|
const rewardAccount = isDeviceOwned
|
|
641
672
|
? {
|
|
@@ -646,12 +677,12 @@ const prepareLedgerCertificates = (certificates, knownAddresses, rewardAccountKe
|
|
|
646
677
|
params: { rewardAccountHex: rewardAccountBytes.toString('hex') },
|
|
647
678
|
type: ledger.PoolRewardAccountType.THIRD_PARTY
|
|
648
679
|
};
|
|
649
|
-
const vrfKeyHashHex = Buffer.from(params.vrf_keyhash().to_bytes()).toString('hex');
|
|
680
|
+
const vrfKeyHashHex = Buffer.from(scope.manage(params.vrf_keyhash()).to_bytes()).toString('hex');
|
|
650
681
|
certificate.params = {
|
|
651
682
|
cost,
|
|
652
683
|
margin: {
|
|
653
|
-
denominator: margin.denominator().to_str(),
|
|
654
|
-
numerator: margin.numerator().to_str()
|
|
684
|
+
denominator: scope.manage(margin.denominator()).to_str(),
|
|
685
|
+
numerator: scope.manage(margin.numerator()).to_str()
|
|
655
686
|
},
|
|
656
687
|
metadata,
|
|
657
688
|
pledge,
|
|
@@ -668,15 +699,16 @@ const prepareLedgerCertificates = (certificates, knownAddresses, rewardAccountKe
|
|
|
668
699
|
certs,
|
|
669
700
|
signingMode
|
|
670
701
|
};
|
|
671
|
-
};
|
|
672
|
-
const prepareLedgerWithdrawals = (withdrawals, rewardAccountKeyPath) => {
|
|
702
|
+
});
|
|
703
|
+
const prepareLedgerWithdrawals = (withdrawals, rewardAccountKeyPath) => (0, util_1.usingAutoFree)((scope) => {
|
|
673
704
|
const ledgerWithdrawals = [];
|
|
674
|
-
|
|
705
|
+
const withdrawalsKeys = scope.manage(withdrawals.keys());
|
|
706
|
+
for (let i = 0; i < withdrawalsKeys.len(); i++) {
|
|
675
707
|
const withdrawal = { stakeCredential: {} };
|
|
676
|
-
const rewardAddress =
|
|
677
|
-
const paymentCredentials = rewardAddress.payment_cred();
|
|
678
|
-
const paymentCredentialsScriptHash = paymentCredentials.to_scripthash();
|
|
679
|
-
if (
|
|
708
|
+
const rewardAddress = scope.manage(withdrawalsKeys.get(i));
|
|
709
|
+
const paymentCredentials = scope.manage(rewardAddress.payment_cred());
|
|
710
|
+
const paymentCredentialsScriptHash = scope.manage(paymentCredentials.to_scripthash());
|
|
711
|
+
if (paymentCredentials.kind() === 0) {
|
|
680
712
|
const stakeCredential = {
|
|
681
713
|
keyPath: rewardAccountKeyPath,
|
|
682
714
|
type: ledger.StakeCredentialParamsType.KEY_PATH
|
|
@@ -690,7 +722,7 @@ const prepareLedgerWithdrawals = (withdrawals, rewardAccountKeyPath) => {
|
|
|
690
722
|
};
|
|
691
723
|
withdrawal.stakeCredential = stakeCredential;
|
|
692
724
|
}
|
|
693
|
-
const withdrawalAmount = withdrawals.get(rewardAddress);
|
|
725
|
+
const withdrawalAmount = scope.manage(withdrawals.get(rewardAddress));
|
|
694
726
|
if (!withdrawalAmount) {
|
|
695
727
|
throw new errors_1.HwMappingError('Withdrawal amount is not defined.');
|
|
696
728
|
}
|
|
@@ -700,20 +732,22 @@ const prepareLedgerWithdrawals = (withdrawals, rewardAccountKeyPath) => {
|
|
|
700
732
|
});
|
|
701
733
|
}
|
|
702
734
|
return ledgerWithdrawals;
|
|
703
|
-
};
|
|
704
|
-
const prepareLedgerMintBundle = (mint, paymentKeyPaths, rewardAccountKeyPath) => {
|
|
735
|
+
});
|
|
736
|
+
const prepareLedgerMintBundle = (mint, paymentKeyPaths, rewardAccountKeyPath) => (0, util_1.usingAutoFree)((scope) => {
|
|
705
737
|
const additionalWitnessPaths = [];
|
|
706
738
|
const mintAssetsGroup = [];
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
const
|
|
739
|
+
const mintKeys = scope.manage(mint.keys());
|
|
740
|
+
for (let j = 0; j < mintKeys.len(); j++) {
|
|
741
|
+
const policy = scope.manage(mintKeys.get(j));
|
|
742
|
+
const assets = scope.manage(mint.get(policy));
|
|
710
743
|
const tokens = [];
|
|
711
744
|
if (assets) {
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
const
|
|
715
|
-
const
|
|
716
|
-
const
|
|
745
|
+
const assetsKeys = assets.keys();
|
|
746
|
+
for (let k = 0; k < assetsKeys.len(); k++) {
|
|
747
|
+
const assetName = scope.manage(assetsKeys.get(k));
|
|
748
|
+
const amount = scope.manage(assets.get(assetName));
|
|
749
|
+
const positiveAmount = scope.manage(amount?.as_positive())?.to_str();
|
|
750
|
+
const negativeAmount = scope.manage(amount?.as_negative())?.to_str();
|
|
717
751
|
if (!amount || !positiveAmount || !negativeAmount) {
|
|
718
752
|
throw new errors_1.HwMappingError('Missing token amount.');
|
|
719
753
|
}
|
|
@@ -737,8 +771,9 @@ const prepareLedgerMintBundle = (mint, paymentKeyPaths, rewardAccountKeyPath) =>
|
|
|
737
771
|
additionalWitnessPaths,
|
|
738
772
|
mintAssetsGroup
|
|
739
773
|
};
|
|
740
|
-
};
|
|
774
|
+
});
|
|
741
775
|
const txToLedger = async ({ cslTxBody, networkId, inputResolver: inputAddressResolver, knownAddresses, protocolMagic }) => {
|
|
776
|
+
const scope = new util_1.ManagedFreeableScope();
|
|
742
777
|
const accountAddress = knownAddresses[0];
|
|
743
778
|
const rewardAccount = accountAddress.rewardAccount;
|
|
744
779
|
const rewardAccountKeyHash = getRewardAccountKeyHash(rewardAccount);
|
|
@@ -749,19 +784,19 @@ const txToLedger = async ({ cslTxBody, networkId, inputResolver: inputAddressRes
|
|
|
749
784
|
key_1.STAKE_KEY_DERIVATION_PATH.role,
|
|
750
785
|
key_1.STAKE_KEY_DERIVATION_PATH.index
|
|
751
786
|
];
|
|
752
|
-
const ledgerInputs = await prepareLedgerInputs(cslTxBody.inputs(), inputAddressResolver, knownAddresses);
|
|
753
|
-
const ledgerOutputs = prepareLedgerOutputs(cslTxBody.outputs(), knownAddresses);
|
|
754
|
-
const cslWithdrawals = cslTxBody.withdrawals();
|
|
787
|
+
const ledgerInputs = await prepareLedgerInputs(scope.manage(cslTxBody.inputs()), inputAddressResolver, knownAddresses);
|
|
788
|
+
const ledgerOutputs = prepareLedgerOutputs(scope.manage(cslTxBody.outputs()), knownAddresses);
|
|
789
|
+
const cslWithdrawals = scope.manage(cslTxBody.withdrawals());
|
|
755
790
|
const ledgerWithdrawals = cslWithdrawals ? prepareLedgerWithdrawals(cslWithdrawals, rewardAccountKeyPath) : null;
|
|
756
|
-
const cslCertificates = cslTxBody.certs();
|
|
791
|
+
const cslCertificates = scope.manage(cslTxBody.certs());
|
|
757
792
|
const ledgerCertificatesData = cslCertificates
|
|
758
793
|
? prepareLedgerCertificates(cslCertificates, knownAddresses, rewardAccountKeyPath, rewardAccountKeyHash.toString())
|
|
759
794
|
: null;
|
|
760
795
|
const signingMode = ledgerCertificatesData?.signingMode || ledger.TransactionSigningMode.ORDINARY_TRANSACTION;
|
|
761
|
-
const fee = cslTxBody.fee().to_str();
|
|
762
|
-
const ttl = cslTxBody.ttl();
|
|
763
|
-
const validityStartInterval = cslTxBody.validity_start_interval();
|
|
764
|
-
const txBodyAuxDataHash = cslTxBody.auxiliary_data_hash();
|
|
796
|
+
const fee = scope.manage(cslTxBody.fee()).to_str();
|
|
797
|
+
const ttl = Number(scope.manage(cslTxBody.ttl())?.to_str());
|
|
798
|
+
const validityStartInterval = Number(scope.manage(cslTxBody.validity_start_interval())?.to_str());
|
|
799
|
+
const txBodyAuxDataHash = scope.manage(cslTxBody.auxiliary_data_hash());
|
|
765
800
|
const auxiliaryData = txBodyAuxDataHash
|
|
766
801
|
? {
|
|
767
802
|
params: {
|
|
@@ -770,7 +805,7 @@ const txToLedger = async ({ cslTxBody, networkId, inputResolver: inputAddressRes
|
|
|
770
805
|
type: ledger.TxAuxiliaryDataType.ARBITRARY_HASH
|
|
771
806
|
}
|
|
772
807
|
: null;
|
|
773
|
-
const cslMint = cslTxBody.multiassets();
|
|
808
|
+
const cslMint = scope.manage(cslTxBody.multiassets());
|
|
774
809
|
let ledgerMintBundle = null;
|
|
775
810
|
if (cslMint) {
|
|
776
811
|
const paymentKeyPaths = (0, uniq_1.default)(ledgerInputs.map((ledgerInput) => ledgerInput.path).filter(util_1.isNotNil));
|
|
@@ -796,6 +831,7 @@ const txToLedger = async ({ cslTxBody, networkId, inputResolver: inputAddressRes
|
|
|
796
831
|
const objKey = key;
|
|
797
832
|
!ledgerTx[objKey] && ledgerTx[objKey] !== 0 && delete ledgerTx[objKey];
|
|
798
833
|
}
|
|
834
|
+
scope.dispose();
|
|
799
835
|
return {
|
|
800
836
|
additionalWitnessPaths,
|
|
801
837
|
signingMode,
|
|
@@ -804,6 +840,7 @@ const txToLedger = async ({ cslTxBody, networkId, inputResolver: inputAddressRes
|
|
|
804
840
|
};
|
|
805
841
|
exports.txToLedger = txToLedger;
|
|
806
842
|
const txToTrezor = async ({ cslTxBody, networkId, inputResolver: inputAddressResolver, knownAddresses, protocolMagic }) => {
|
|
843
|
+
const scope = new util_1.ManagedFreeableScope();
|
|
807
844
|
const accountAddress = knownAddresses[0];
|
|
808
845
|
const rewardAccount = accountAddress.rewardAccount;
|
|
809
846
|
const rewardAccountKeyHash = getRewardAccountKeyHash(rewardAccount);
|
|
@@ -814,36 +851,37 @@ const txToTrezor = async ({ cslTxBody, networkId, inputResolver: inputAddressRes
|
|
|
814
851
|
key_1.STAKE_KEY_DERIVATION_PATH.role,
|
|
815
852
|
key_1.STAKE_KEY_DERIVATION_PATH.index
|
|
816
853
|
];
|
|
817
|
-
const trezorInputs = await prepareTrezorInputs(cslTxBody.inputs(), inputAddressResolver, knownAddresses);
|
|
818
|
-
const trezorOutputs = prepareTrezorOutputs(cslTxBody.outputs(), knownAddresses);
|
|
819
|
-
const cslWithdrawals = cslTxBody.withdrawals();
|
|
854
|
+
const trezorInputs = await prepareTrezorInputs(scope.manage(cslTxBody.inputs()), inputAddressResolver, knownAddresses);
|
|
855
|
+
const trezorOutputs = prepareTrezorOutputs(scope.manage(cslTxBody.outputs()), knownAddresses);
|
|
856
|
+
const cslWithdrawals = scope.manage(cslTxBody.withdrawals());
|
|
820
857
|
const trezorWithdrawals = cslWithdrawals ? prepareTrezorWithdrawals(cslWithdrawals, rewardAccountKeyPath) : undefined;
|
|
821
|
-
const cslCertificates = cslTxBody.certs();
|
|
858
|
+
const cslCertificates = scope.manage(cslTxBody.certs());
|
|
822
859
|
let trezorCertificatesData;
|
|
823
860
|
if (cslCertificates) {
|
|
824
861
|
trezorCertificatesData = prepareTrezorCertificates(cslCertificates, rewardAccountKeyPath, rewardAccountKeyHash.toString());
|
|
825
862
|
}
|
|
826
863
|
const signingMode = trezorCertificatesData?.signingMode || trezor.CardanoTxSigningMode.ORDINARY_TRANSACTION;
|
|
827
|
-
const fee = cslTxBody.fee().to_str();
|
|
864
|
+
const fee = scope.manage(cslTxBody.fee()).to_str();
|
|
828
865
|
let ttl;
|
|
829
866
|
const cslTTL = cslTxBody.ttl();
|
|
830
867
|
if (cslTTL) {
|
|
831
868
|
ttl = cslTTL.toString();
|
|
832
869
|
}
|
|
833
870
|
const validityIntervalStart = cslTxBody.validity_start_interval();
|
|
834
|
-
const txBodyAuxDataHash = cslTxBody.auxiliary_data_hash();
|
|
871
|
+
const txBodyAuxDataHash = scope.manage(cslTxBody.auxiliary_data_hash());
|
|
835
872
|
let auxiliaryData;
|
|
836
873
|
if (txBodyAuxDataHash) {
|
|
837
874
|
auxiliaryData = {
|
|
838
875
|
hash: Buffer.from(txBodyAuxDataHash.to_bytes()).toString('hex')
|
|
839
876
|
};
|
|
840
877
|
}
|
|
841
|
-
const cslMint = cslTxBody.multiassets();
|
|
878
|
+
const cslMint = scope.manage(cslTxBody.multiassets());
|
|
842
879
|
let trezorMintBundle = null;
|
|
843
880
|
if (cslMint) {
|
|
844
881
|
const paymentKeyPaths = (0, uniq_1.default)(trezorInputs.map((trezorInput) => trezorInput.path).filter(util_1.isNotNil));
|
|
845
882
|
trezorMintBundle = prepareTrezorMintBundle(cslMint, paymentKeyPaths, rewardAccountKeyPath);
|
|
846
883
|
}
|
|
884
|
+
scope.dispose();
|
|
847
885
|
return {
|
|
848
886
|
additionalWitnessRequests: trezorMintBundle?.additionalWitnessPaths,
|
|
849
887
|
auxiliaryData,
|