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