@onekeyfe/cardano-coin-selection-asmjs 1.1.10-alpha.2 → 1.1.10-alpha.6
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/lib/cjs/utils/onekey/dapp.d.ts +2 -2
- package/lib/cjs/utils/onekey/dapp.js +3 -13
- package/lib/cjs/utils/onekey/txToOneKey.d.ts +9 -2
- package/lib/cjs/utils/onekey/txToOneKey.js +41 -16
- package/lib/cjs/utils/onekey/types.d.ts +7 -1
- package/lib/esm/utils/onekey/dapp.d.ts +2 -2
- package/lib/esm/utils/onekey/dapp.js +3 -13
- package/lib/esm/utils/onekey/txToOneKey.d.ts +9 -2
- package/lib/esm/utils/onekey/txToOneKey.js +40 -15
- package/lib/esm/utils/onekey/types.d.ts +7 -1
- package/package.json +1 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as CardanoWasm from '@emurgo/cardano-serialization-lib-asmjs';
|
|
2
|
-
import { IAdaAmount, IAdaUTXO,
|
|
2
|
+
import { IAdaAmount, IAdaUTXO, IEncodedTxADA, IConvertCborTxParams } from './types';
|
|
3
3
|
export declare const assetsToValue: (assets: IAdaAmount[]) => Promise<CardanoWasm.Value>;
|
|
4
4
|
export declare const extractKeyHash: (address: string) => Promise<string>;
|
|
5
5
|
export declare const dAppUtils: {
|
|
6
6
|
getBalance: (balances: IAdaAmount[]) => Promise<string>;
|
|
7
7
|
getAddresses: (addresses: string[]) => Promise<string[]>;
|
|
8
8
|
getUtxos: (address: string, utxos: IAdaUTXO[], amount?: string) => Promise<string[] | null | undefined>;
|
|
9
|
-
convertCborTxToEncodeTx: (txHex
|
|
9
|
+
convertCborTxToEncodeTx: ({ txHex, utxos, addresses, changeAddress, isSignOnly, }: IConvertCborTxParams) => Promise<IEncodedTxADA>;
|
|
10
10
|
signData: (address: string, payload: string, xprv: string, accountIndex: number) => Promise<{
|
|
11
11
|
signature: string;
|
|
12
12
|
key: string;
|
|
@@ -87,31 +87,24 @@ const getUtxos = async (address, utxos, amount) => {
|
|
|
87
87
|
}
|
|
88
88
|
return converted === null || converted === void 0 ? void 0 : converted.map(utxo => Buffer.from(utxo.to_bytes(), 'hex').toString('hex'));
|
|
89
89
|
};
|
|
90
|
-
const convertCborTxToEncodeTx = async (txHex, utxos, addresses, changeAddress) => {
|
|
90
|
+
const convertCborTxToEncodeTx = async ({ txHex, utxos, addresses, changeAddress, isSignOnly, }) => {
|
|
91
91
|
var _a, _b, _c, _d;
|
|
92
92
|
let body;
|
|
93
93
|
let rawTxHex;
|
|
94
|
-
let originalBodyHex;
|
|
95
|
-
let isBodyOnly = false;
|
|
96
94
|
console.log('CARDANO LOCAL_VERSION : 1');
|
|
97
95
|
try {
|
|
98
96
|
const tx = CardanoWasm.Transaction.from_bytes(Buffer.from(txHex, 'hex'));
|
|
99
97
|
body = tx.body();
|
|
100
98
|
rawTxHex = txHex;
|
|
101
|
-
// No originalBodyHex needed for full Transaction
|
|
102
99
|
}
|
|
103
100
|
catch (_e) {
|
|
104
101
|
// Input is TransactionBody only (e.g., from staking providers like stakefish)
|
|
105
|
-
//
|
|
106
|
-
isBodyOnly = true;
|
|
107
|
-
originalBodyHex = txHex; // Save original body hex
|
|
102
|
+
// Build a complete Transaction with empty witness set
|
|
108
103
|
body = CardanoWasm.TransactionBody.from_bytes(Buffer.from(txHex, 'hex'));
|
|
109
|
-
// For rawTxHex, we need to build a Transaction for compatibility
|
|
110
104
|
const emptyWitnessSet = CardanoWasm.TransactionWitnessSet.new();
|
|
111
105
|
const tx = CardanoWasm.Transaction.new(body, emptyWitnessSet);
|
|
112
106
|
rawTxHex = Buffer.from(tx.to_bytes(), 'hex').toString('hex');
|
|
113
107
|
}
|
|
114
|
-
console.log('[convertCborTxToEncodeTx] isBodyOnly:', isBodyOnly, 'originalBodyHex:', !!originalBodyHex);
|
|
115
108
|
// Fee
|
|
116
109
|
const fee = body.fee().to_str();
|
|
117
110
|
const totalFeeInNative = new bignumber_js_1.default(fee).shiftedBy(-1 * 6).toFixed();
|
|
@@ -266,11 +259,8 @@ const convertCborTxToEncodeTx = async (txHex, utxos, addresses, changeAddress) =
|
|
|
266
259
|
.to_hex(),
|
|
267
260
|
size: 0,
|
|
268
261
|
rawTxHex,
|
|
269
|
-
// Original body hex from external provider, use this for signing
|
|
270
|
-
// to preserve CBOR encoding (important for Conway era transactions)
|
|
271
|
-
originalBodyHex,
|
|
272
262
|
},
|
|
273
|
-
signOnly:
|
|
263
|
+
signOnly: isSignOnly,
|
|
274
264
|
staking: stakingInfo,
|
|
275
265
|
};
|
|
276
266
|
console.log('Cardano DApp EncodedTx: ', encodedTx);
|
|
@@ -22,7 +22,14 @@ export declare enum CardanoCertificateType {
|
|
|
22
22
|
STAKE_REGISTRATION = 0,
|
|
23
23
|
STAKE_DEREGISTRATION = 1,
|
|
24
24
|
STAKE_DELEGATION = 2,
|
|
25
|
-
STAKE_POOL_REGISTRATION = 3
|
|
25
|
+
STAKE_POOL_REGISTRATION = 3,
|
|
26
|
+
VOTE_DELEGATION = 9
|
|
27
|
+
}
|
|
28
|
+
export declare enum CardanoDRepType {
|
|
29
|
+
KEY_HASH = 0,
|
|
30
|
+
SCRIPT_HASH = 1,
|
|
31
|
+
ABSTAIN = 2,
|
|
32
|
+
NO_CONFIDENCE = 3
|
|
26
33
|
}
|
|
27
34
|
export declare enum CardanoPoolRelayType {
|
|
28
35
|
SINGLE_HOST_IP = 0,
|
|
@@ -39,7 +46,7 @@ type Keys = {
|
|
|
39
46
|
};
|
|
40
47
|
/**
|
|
41
48
|
*
|
|
42
|
-
* @param {Transaction
|
|
49
|
+
* @param {Transaction} tx
|
|
43
50
|
*/
|
|
44
51
|
export declare const txToOneKey: (rawTx: string, network: number, initKeys: Keys, xpub: string, changeAddress: IChangeAddress) => Promise<{
|
|
45
52
|
signingMode: CardanoTxSigningMode.ORDINARY_TRANSACTION | CardanoTxSigningMode.POOL_REGISTRATION_AS_OWNER | CardanoTxSigningMode.PLUTUS_TRANSACTION;
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.txToOneKey = exports.CardanoPoolRelayType = exports.CardanoCertificateType = exports.CardanoTxSigningMode = exports.CardanoAddressType = void 0;
|
|
26
|
+
exports.txToOneKey = exports.CardanoPoolRelayType = exports.CardanoDRepType = exports.CardanoCertificateType = exports.CardanoTxSigningMode = exports.CardanoAddressType = void 0;
|
|
27
27
|
// @ts-nocheck
|
|
28
28
|
const CardanoWasm = __importStar(require("@emurgo/cardano-serialization-lib-asmjs"));
|
|
29
29
|
var CardanoAddressType;
|
|
@@ -53,7 +53,15 @@ var CardanoCertificateType;
|
|
|
53
53
|
CardanoCertificateType[CardanoCertificateType["STAKE_DEREGISTRATION"] = 1] = "STAKE_DEREGISTRATION";
|
|
54
54
|
CardanoCertificateType[CardanoCertificateType["STAKE_DELEGATION"] = 2] = "STAKE_DELEGATION";
|
|
55
55
|
CardanoCertificateType[CardanoCertificateType["STAKE_POOL_REGISTRATION"] = 3] = "STAKE_POOL_REGISTRATION";
|
|
56
|
+
CardanoCertificateType[CardanoCertificateType["VOTE_DELEGATION"] = 9] = "VOTE_DELEGATION";
|
|
56
57
|
})(CardanoCertificateType || (exports.CardanoCertificateType = CardanoCertificateType = {}));
|
|
58
|
+
var CardanoDRepType;
|
|
59
|
+
(function (CardanoDRepType) {
|
|
60
|
+
CardanoDRepType[CardanoDRepType["KEY_HASH"] = 0] = "KEY_HASH";
|
|
61
|
+
CardanoDRepType[CardanoDRepType["SCRIPT_HASH"] = 1] = "SCRIPT_HASH";
|
|
62
|
+
CardanoDRepType[CardanoDRepType["ABSTAIN"] = 2] = "ABSTAIN";
|
|
63
|
+
CardanoDRepType[CardanoDRepType["NO_CONFIDENCE"] = 3] = "NO_CONFIDENCE";
|
|
64
|
+
})(CardanoDRepType || (exports.CardanoDRepType = CardanoDRepType = {}));
|
|
57
65
|
var CardanoPoolRelayType;
|
|
58
66
|
(function (CardanoPoolRelayType) {
|
|
59
67
|
CardanoPoolRelayType[CardanoPoolRelayType["SINGLE_HOST_IP"] = 0] = "SINGLE_HOST_IP";
|
|
@@ -194,23 +202,12 @@ const outputsToOneKey = (outputs, changeAddress) => {
|
|
|
194
202
|
};
|
|
195
203
|
/**
|
|
196
204
|
*
|
|
197
|
-
* @param {Transaction
|
|
205
|
+
* @param {Transaction} tx
|
|
198
206
|
*/
|
|
199
207
|
const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
200
|
-
var _a;
|
|
208
|
+
var _a, _b, _c;
|
|
201
209
|
const keys = generateKeys(initKeys, xpub);
|
|
202
|
-
|
|
203
|
-
let tx;
|
|
204
|
-
try {
|
|
205
|
-
tx = CardanoWasm.Transaction.from_bytes(Buffer.from(rawTx, 'hex'));
|
|
206
|
-
}
|
|
207
|
-
catch (_b) {
|
|
208
|
-
// Input is TransactionBody only, wrap it with empty witness set
|
|
209
|
-
const body = CardanoWasm.TransactionBody.from_bytes(Buffer.from(rawTx, 'hex'));
|
|
210
|
-
const emptyWitnessSet = CardanoWasm.TransactionWitnessSet.new();
|
|
211
|
-
tx = CardanoWasm.Transaction.new(body, emptyWitnessSet);
|
|
212
|
-
console.log('[txToOneKey] Input is TransactionBody, wrapped with empty witness set');
|
|
213
|
-
}
|
|
210
|
+
const tx = CardanoWasm.Transaction.from_bytes(Buffer.from(rawTx, 'hex'));
|
|
214
211
|
let signingMode = CardanoTxSigningMode.ORDINARY_TRANSACTION;
|
|
215
212
|
const outputs = tx.body().outputs();
|
|
216
213
|
const onekeyOutputs = outputsToOneKey(outputs, changeAddress);
|
|
@@ -341,6 +338,35 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
|
341
338
|
metadata,
|
|
342
339
|
};
|
|
343
340
|
}
|
|
341
|
+
else if (certKind === 15) {
|
|
342
|
+
// VoteDelegation (CertificateKind.VoteDelegation = 15 in WASM lib)
|
|
343
|
+
const voteDelegation = cert.as_vote_delegation();
|
|
344
|
+
const credential = voteDelegation.stake_credential();
|
|
345
|
+
certificate.type = CardanoCertificateType.VOTE_DELEGATION;
|
|
346
|
+
if (credential.kind() === 0) {
|
|
347
|
+
certificate.path = keys.stake.path;
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
const scriptHash = Buffer.from(credential.to_scripthash().to_bytes()).toString('hex');
|
|
351
|
+
certificate.scriptHash = scriptHash;
|
|
352
|
+
}
|
|
353
|
+
// Parse DRep
|
|
354
|
+
const drep = voteDelegation.drep();
|
|
355
|
+
const drepKind = drep.kind();
|
|
356
|
+
// DRepKind: KeyHash = 0, ScriptHash = 1, AlwaysAbstain = 2, AlwaysNoConfidence = 3
|
|
357
|
+
certificate.dRep = {
|
|
358
|
+
type: drepKind,
|
|
359
|
+
};
|
|
360
|
+
if (drepKind === 0) {
|
|
361
|
+
// KEY_HASH
|
|
362
|
+
certificate.dRep.keyHash = (_b = drep.to_key_hash()) === null || _b === void 0 ? void 0 : _b.to_hex();
|
|
363
|
+
}
|
|
364
|
+
else if (drepKind === 1) {
|
|
365
|
+
// SCRIPT_HASH
|
|
366
|
+
certificate.dRep.scriptHash = (_c = drep.to_script_hash()) === null || _c === void 0 ? void 0 : _c.to_hex();
|
|
367
|
+
}
|
|
368
|
+
// ABSTAIN (2) and NO_CONFIDENCE (3) don't need additional fields
|
|
369
|
+
}
|
|
344
370
|
else {
|
|
345
371
|
// Skip unsupported certificate types (kind 4, 5, 6, etc.)
|
|
346
372
|
// Don't push empty certificate objects
|
|
@@ -519,7 +545,6 @@ const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
|
519
545
|
};
|
|
520
546
|
Object.keys(onekeyTx).forEach(key => !onekeyTx[key] && onekeyTx[key] != 0 && delete onekeyTx[key]);
|
|
521
547
|
console.log('format onekey cardano hardware Tx =====>>> : ', onekeyTx);
|
|
522
|
-
console.log('[txToOneKey] certificates detail:', JSON.stringify(onekeyCertificates, null, 2));
|
|
523
548
|
return Promise.resolve(onekeyTx);
|
|
524
549
|
};
|
|
525
550
|
exports.txToOneKey = txToOneKey;
|
|
@@ -45,7 +45,6 @@ type ITxInfo = {
|
|
|
45
45
|
hash: string;
|
|
46
46
|
size: number;
|
|
47
47
|
rawTxHex?: string;
|
|
48
|
-
originalBodyHex?: string;
|
|
49
48
|
};
|
|
50
49
|
export type IEncodedTxADA = {
|
|
51
50
|
inputs: IEncodeInput[];
|
|
@@ -95,4 +94,11 @@ export type ICardanoCertificate = {
|
|
|
95
94
|
stakeCredential?: string;
|
|
96
95
|
poolKeyHash?: string;
|
|
97
96
|
};
|
|
97
|
+
export type IConvertCborTxParams = {
|
|
98
|
+
txHex: string;
|
|
99
|
+
utxos: IAdaUTXO[];
|
|
100
|
+
addresses: string[];
|
|
101
|
+
changeAddress: IChangeAddress;
|
|
102
|
+
isSignOnly: boolean;
|
|
103
|
+
};
|
|
98
104
|
export {};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as CardanoWasm from '@emurgo/cardano-serialization-lib-asmjs';
|
|
2
|
-
import { IAdaAmount, IAdaUTXO,
|
|
2
|
+
import { IAdaAmount, IAdaUTXO, IEncodedTxADA, IConvertCborTxParams } from './types';
|
|
3
3
|
export declare const assetsToValue: (assets: IAdaAmount[]) => Promise<CardanoWasm.Value>;
|
|
4
4
|
export declare const extractKeyHash: (address: string) => Promise<string>;
|
|
5
5
|
export declare const dAppUtils: {
|
|
6
6
|
getBalance: (balances: IAdaAmount[]) => Promise<string>;
|
|
7
7
|
getAddresses: (addresses: string[]) => Promise<string[]>;
|
|
8
8
|
getUtxos: (address: string, utxos: IAdaUTXO[], amount?: string) => Promise<string[] | null | undefined>;
|
|
9
|
-
convertCborTxToEncodeTx: (txHex
|
|
9
|
+
convertCborTxToEncodeTx: ({ txHex, utxos, addresses, changeAddress, isSignOnly, }: IConvertCborTxParams) => Promise<IEncodedTxADA>;
|
|
10
10
|
signData: (address: string, payload: string, xprv: string, accountIndex: number) => Promise<{
|
|
11
11
|
signature: string;
|
|
12
12
|
key: string;
|
|
@@ -57,31 +57,24 @@ const getUtxos = async (address, utxos, amount) => {
|
|
|
57
57
|
}
|
|
58
58
|
return converted === null || converted === void 0 ? void 0 : converted.map(utxo => Buffer.from(utxo.to_bytes(), 'hex').toString('hex'));
|
|
59
59
|
};
|
|
60
|
-
const convertCborTxToEncodeTx = async (txHex, utxos, addresses, changeAddress) => {
|
|
60
|
+
const convertCborTxToEncodeTx = async ({ txHex, utxos, addresses, changeAddress, isSignOnly, }) => {
|
|
61
61
|
var _a, _b, _c, _d;
|
|
62
62
|
let body;
|
|
63
63
|
let rawTxHex;
|
|
64
|
-
let originalBodyHex;
|
|
65
|
-
let isBodyOnly = false;
|
|
66
64
|
console.log('CARDANO LOCAL_VERSION : 1');
|
|
67
65
|
try {
|
|
68
66
|
const tx = CardanoWasm.Transaction.from_bytes(Buffer.from(txHex, 'hex'));
|
|
69
67
|
body = tx.body();
|
|
70
68
|
rawTxHex = txHex;
|
|
71
|
-
// No originalBodyHex needed for full Transaction
|
|
72
69
|
}
|
|
73
70
|
catch (_e) {
|
|
74
71
|
// Input is TransactionBody only (e.g., from staking providers like stakefish)
|
|
75
|
-
//
|
|
76
|
-
isBodyOnly = true;
|
|
77
|
-
originalBodyHex = txHex; // Save original body hex
|
|
72
|
+
// Build a complete Transaction with empty witness set
|
|
78
73
|
body = CardanoWasm.TransactionBody.from_bytes(Buffer.from(txHex, 'hex'));
|
|
79
|
-
// For rawTxHex, we need to build a Transaction for compatibility
|
|
80
74
|
const emptyWitnessSet = CardanoWasm.TransactionWitnessSet.new();
|
|
81
75
|
const tx = CardanoWasm.Transaction.new(body, emptyWitnessSet);
|
|
82
76
|
rawTxHex = Buffer.from(tx.to_bytes(), 'hex').toString('hex');
|
|
83
77
|
}
|
|
84
|
-
console.log('[convertCborTxToEncodeTx] isBodyOnly:', isBodyOnly, 'originalBodyHex:', !!originalBodyHex);
|
|
85
78
|
// Fee
|
|
86
79
|
const fee = body.fee().to_str();
|
|
87
80
|
const totalFeeInNative = new BigNumber(fee).shiftedBy(-1 * 6).toFixed();
|
|
@@ -236,11 +229,8 @@ const convertCborTxToEncodeTx = async (txHex, utxos, addresses, changeAddress) =
|
|
|
236
229
|
.to_hex(),
|
|
237
230
|
size: 0,
|
|
238
231
|
rawTxHex,
|
|
239
|
-
// Original body hex from external provider, use this for signing
|
|
240
|
-
// to preserve CBOR encoding (important for Conway era transactions)
|
|
241
|
-
originalBodyHex,
|
|
242
232
|
},
|
|
243
|
-
signOnly:
|
|
233
|
+
signOnly: isSignOnly,
|
|
244
234
|
staking: stakingInfo,
|
|
245
235
|
};
|
|
246
236
|
console.log('Cardano DApp EncodedTx: ', encodedTx);
|
|
@@ -22,7 +22,14 @@ export declare enum CardanoCertificateType {
|
|
|
22
22
|
STAKE_REGISTRATION = 0,
|
|
23
23
|
STAKE_DEREGISTRATION = 1,
|
|
24
24
|
STAKE_DELEGATION = 2,
|
|
25
|
-
STAKE_POOL_REGISTRATION = 3
|
|
25
|
+
STAKE_POOL_REGISTRATION = 3,
|
|
26
|
+
VOTE_DELEGATION = 9
|
|
27
|
+
}
|
|
28
|
+
export declare enum CardanoDRepType {
|
|
29
|
+
KEY_HASH = 0,
|
|
30
|
+
SCRIPT_HASH = 1,
|
|
31
|
+
ABSTAIN = 2,
|
|
32
|
+
NO_CONFIDENCE = 3
|
|
26
33
|
}
|
|
27
34
|
export declare enum CardanoPoolRelayType {
|
|
28
35
|
SINGLE_HOST_IP = 0,
|
|
@@ -39,7 +46,7 @@ type Keys = {
|
|
|
39
46
|
};
|
|
40
47
|
/**
|
|
41
48
|
*
|
|
42
|
-
* @param {Transaction
|
|
49
|
+
* @param {Transaction} tx
|
|
43
50
|
*/
|
|
44
51
|
export declare const txToOneKey: (rawTx: string, network: number, initKeys: Keys, xpub: string, changeAddress: IChangeAddress) => Promise<{
|
|
45
52
|
signingMode: CardanoTxSigningMode.ORDINARY_TRANSACTION | CardanoTxSigningMode.POOL_REGISTRATION_AS_OWNER | CardanoTxSigningMode.PLUTUS_TRANSACTION;
|
|
@@ -27,7 +27,15 @@ export var CardanoCertificateType;
|
|
|
27
27
|
CardanoCertificateType[CardanoCertificateType["STAKE_DEREGISTRATION"] = 1] = "STAKE_DEREGISTRATION";
|
|
28
28
|
CardanoCertificateType[CardanoCertificateType["STAKE_DELEGATION"] = 2] = "STAKE_DELEGATION";
|
|
29
29
|
CardanoCertificateType[CardanoCertificateType["STAKE_POOL_REGISTRATION"] = 3] = "STAKE_POOL_REGISTRATION";
|
|
30
|
+
CardanoCertificateType[CardanoCertificateType["VOTE_DELEGATION"] = 9] = "VOTE_DELEGATION";
|
|
30
31
|
})(CardanoCertificateType || (CardanoCertificateType = {}));
|
|
32
|
+
export var CardanoDRepType;
|
|
33
|
+
(function (CardanoDRepType) {
|
|
34
|
+
CardanoDRepType[CardanoDRepType["KEY_HASH"] = 0] = "KEY_HASH";
|
|
35
|
+
CardanoDRepType[CardanoDRepType["SCRIPT_HASH"] = 1] = "SCRIPT_HASH";
|
|
36
|
+
CardanoDRepType[CardanoDRepType["ABSTAIN"] = 2] = "ABSTAIN";
|
|
37
|
+
CardanoDRepType[CardanoDRepType["NO_CONFIDENCE"] = 3] = "NO_CONFIDENCE";
|
|
38
|
+
})(CardanoDRepType || (CardanoDRepType = {}));
|
|
31
39
|
export var CardanoPoolRelayType;
|
|
32
40
|
(function (CardanoPoolRelayType) {
|
|
33
41
|
CardanoPoolRelayType[CardanoPoolRelayType["SINGLE_HOST_IP"] = 0] = "SINGLE_HOST_IP";
|
|
@@ -168,23 +176,12 @@ const outputsToOneKey = (outputs, changeAddress) => {
|
|
|
168
176
|
};
|
|
169
177
|
/**
|
|
170
178
|
*
|
|
171
|
-
* @param {Transaction
|
|
179
|
+
* @param {Transaction} tx
|
|
172
180
|
*/
|
|
173
181
|
export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress) => {
|
|
174
|
-
var _a;
|
|
182
|
+
var _a, _b, _c;
|
|
175
183
|
const keys = generateKeys(initKeys, xpub);
|
|
176
|
-
|
|
177
|
-
let tx;
|
|
178
|
-
try {
|
|
179
|
-
tx = CardanoWasm.Transaction.from_bytes(Buffer.from(rawTx, 'hex'));
|
|
180
|
-
}
|
|
181
|
-
catch (_b) {
|
|
182
|
-
// Input is TransactionBody only, wrap it with empty witness set
|
|
183
|
-
const body = CardanoWasm.TransactionBody.from_bytes(Buffer.from(rawTx, 'hex'));
|
|
184
|
-
const emptyWitnessSet = CardanoWasm.TransactionWitnessSet.new();
|
|
185
|
-
tx = CardanoWasm.Transaction.new(body, emptyWitnessSet);
|
|
186
|
-
console.log('[txToOneKey] Input is TransactionBody, wrapped with empty witness set');
|
|
187
|
-
}
|
|
184
|
+
const tx = CardanoWasm.Transaction.from_bytes(Buffer.from(rawTx, 'hex'));
|
|
188
185
|
let signingMode = CardanoTxSigningMode.ORDINARY_TRANSACTION;
|
|
189
186
|
const outputs = tx.body().outputs();
|
|
190
187
|
const onekeyOutputs = outputsToOneKey(outputs, changeAddress);
|
|
@@ -315,6 +312,35 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
|
|
|
315
312
|
metadata,
|
|
316
313
|
};
|
|
317
314
|
}
|
|
315
|
+
else if (certKind === 15) {
|
|
316
|
+
// VoteDelegation (CertificateKind.VoteDelegation = 15 in WASM lib)
|
|
317
|
+
const voteDelegation = cert.as_vote_delegation();
|
|
318
|
+
const credential = voteDelegation.stake_credential();
|
|
319
|
+
certificate.type = CardanoCertificateType.VOTE_DELEGATION;
|
|
320
|
+
if (credential.kind() === 0) {
|
|
321
|
+
certificate.path = keys.stake.path;
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
const scriptHash = Buffer.from(credential.to_scripthash().to_bytes()).toString('hex');
|
|
325
|
+
certificate.scriptHash = scriptHash;
|
|
326
|
+
}
|
|
327
|
+
// Parse DRep
|
|
328
|
+
const drep = voteDelegation.drep();
|
|
329
|
+
const drepKind = drep.kind();
|
|
330
|
+
// DRepKind: KeyHash = 0, ScriptHash = 1, AlwaysAbstain = 2, AlwaysNoConfidence = 3
|
|
331
|
+
certificate.dRep = {
|
|
332
|
+
type: drepKind,
|
|
333
|
+
};
|
|
334
|
+
if (drepKind === 0) {
|
|
335
|
+
// KEY_HASH
|
|
336
|
+
certificate.dRep.keyHash = (_b = drep.to_key_hash()) === null || _b === void 0 ? void 0 : _b.to_hex();
|
|
337
|
+
}
|
|
338
|
+
else if (drepKind === 1) {
|
|
339
|
+
// SCRIPT_HASH
|
|
340
|
+
certificate.dRep.scriptHash = (_c = drep.to_script_hash()) === null || _c === void 0 ? void 0 : _c.to_hex();
|
|
341
|
+
}
|
|
342
|
+
// ABSTAIN (2) and NO_CONFIDENCE (3) don't need additional fields
|
|
343
|
+
}
|
|
318
344
|
else {
|
|
319
345
|
// Skip unsupported certificate types (kind 4, 5, 6, etc.)
|
|
320
346
|
// Don't push empty certificate objects
|
|
@@ -493,7 +519,6 @@ export const txToOneKey = async (rawTx, network, initKeys, xpub, changeAddress)
|
|
|
493
519
|
};
|
|
494
520
|
Object.keys(onekeyTx).forEach(key => !onekeyTx[key] && onekeyTx[key] != 0 && delete onekeyTx[key]);
|
|
495
521
|
console.log('format onekey cardano hardware Tx =====>>> : ', onekeyTx);
|
|
496
|
-
console.log('[txToOneKey] certificates detail:', JSON.stringify(onekeyCertificates, null, 2));
|
|
497
522
|
return Promise.resolve(onekeyTx);
|
|
498
523
|
};
|
|
499
524
|
const bytesToIp = bytes => {
|
|
@@ -45,7 +45,6 @@ type ITxInfo = {
|
|
|
45
45
|
hash: string;
|
|
46
46
|
size: number;
|
|
47
47
|
rawTxHex?: string;
|
|
48
|
-
originalBodyHex?: string;
|
|
49
48
|
};
|
|
50
49
|
export type IEncodedTxADA = {
|
|
51
50
|
inputs: IEncodeInput[];
|
|
@@ -95,4 +94,11 @@ export type ICardanoCertificate = {
|
|
|
95
94
|
stakeCredential?: string;
|
|
96
95
|
poolKeyHash?: string;
|
|
97
96
|
};
|
|
97
|
+
export type IConvertCborTxParams = {
|
|
98
|
+
txHex: string;
|
|
99
|
+
utxos: IAdaUTXO[];
|
|
100
|
+
addresses: string[];
|
|
101
|
+
changeAddress: IChangeAddress;
|
|
102
|
+
isSignOnly: boolean;
|
|
103
|
+
};
|
|
98
104
|
export {};
|