@onekeyfe/cardano-coin-selection-asmjs 1.1.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.
Files changed (79) hide show
  1. package/CHANGELOG.MD +25 -0
  2. package/README.md +183 -0
  3. package/lib/cjs/constants/index.d.ts +40 -0
  4. package/lib/cjs/constants/index.js +69 -0
  5. package/lib/cjs/index.d.ts +6 -0
  6. package/lib/cjs/index.js +101 -0
  7. package/lib/cjs/methods/largestFirst.d.ts +2 -0
  8. package/lib/cjs/methods/largestFirst.js +201 -0
  9. package/lib/cjs/methods/randomImprove.d.ts +2 -0
  10. package/lib/cjs/methods/randomImprove.js +187 -0
  11. package/lib/cjs/types/trezor.d.ts +45 -0
  12. package/lib/cjs/types/trezor.js +8 -0
  13. package/lib/cjs/types/types.d.ts +116 -0
  14. package/lib/cjs/types/types.js +17 -0
  15. package/lib/cjs/utils/common.d.ts +46 -0
  16. package/lib/cjs/utils/common.js +514 -0
  17. package/lib/cjs/utils/errors.d.ts +8 -0
  18. package/lib/cjs/utils/errors.js +13 -0
  19. package/lib/cjs/utils/logger.d.ts +5 -0
  20. package/lib/cjs/utils/logger.js +27 -0
  21. package/lib/cjs/utils/onekey/dapp.d.ts +14 -0
  22. package/lib/cjs/utils/onekey/dapp.js +247 -0
  23. package/lib/cjs/utils/onekey/error.d.ts +28 -0
  24. package/lib/cjs/utils/onekey/error.js +25 -0
  25. package/lib/cjs/utils/onekey/index.d.ts +48 -0
  26. package/lib/cjs/utils/onekey/index.js +15 -0
  27. package/lib/cjs/utils/onekey/signTx.d.ts +26 -0
  28. package/lib/cjs/utils/onekey/signTx.js +296 -0
  29. package/lib/cjs/utils/onekey/transaction.d.ts +5 -0
  30. package/lib/cjs/utils/onekey/transaction.js +49 -0
  31. package/lib/cjs/utils/onekey/txToOneKey.d.ts +67 -0
  32. package/lib/cjs/utils/onekey/txToOneKey.js +504 -0
  33. package/lib/cjs/utils/onekey/types.d.ts +79 -0
  34. package/lib/cjs/utils/onekey/types.js +16 -0
  35. package/lib/cjs/utils/trezor/index.d.ts +3 -0
  36. package/lib/cjs/utils/trezor/index.js +9 -0
  37. package/lib/cjs/utils/trezor/sign.d.ts +5 -0
  38. package/lib/cjs/utils/trezor/sign.js +69 -0
  39. package/lib/cjs/utils/trezor/transformations.d.ts +17 -0
  40. package/lib/cjs/utils/trezor/transformations.js +66 -0
  41. package/lib/esm/constants/index.d.ts +40 -0
  42. package/lib/esm/constants/index.js +43 -0
  43. package/lib/esm/index.d.ts +6 -0
  44. package/lib/esm/index.js +73 -0
  45. package/lib/esm/methods/largestFirst.d.ts +2 -0
  46. package/lib/esm/methods/largestFirst.js +174 -0
  47. package/lib/esm/methods/randomImprove.d.ts +2 -0
  48. package/lib/esm/methods/randomImprove.js +160 -0
  49. package/lib/esm/types/trezor.d.ts +45 -0
  50. package/lib/esm/types/trezor.js +5 -0
  51. package/lib/esm/types/types.d.ts +116 -0
  52. package/lib/esm/types/types.js +14 -0
  53. package/lib/esm/utils/common.d.ts +46 -0
  54. package/lib/esm/utils/common.js +460 -0
  55. package/lib/esm/utils/errors.d.ts +8 -0
  56. package/lib/esm/utils/errors.js +9 -0
  57. package/lib/esm/utils/logger.d.ts +5 -0
  58. package/lib/esm/utils/logger.js +23 -0
  59. package/lib/esm/utils/onekey/dapp.d.ts +14 -0
  60. package/lib/esm/utils/onekey/dapp.js +216 -0
  61. package/lib/esm/utils/onekey/error.d.ts +28 -0
  62. package/lib/esm/utils/onekey/error.js +22 -0
  63. package/lib/esm/utils/onekey/index.d.ts +48 -0
  64. package/lib/esm/utils/onekey/index.js +11 -0
  65. package/lib/esm/utils/onekey/signTx.d.ts +26 -0
  66. package/lib/esm/utils/onekey/signTx.js +266 -0
  67. package/lib/esm/utils/onekey/transaction.d.ts +5 -0
  68. package/lib/esm/utils/onekey/transaction.js +42 -0
  69. package/lib/esm/utils/onekey/txToOneKey.d.ts +67 -0
  70. package/lib/esm/utils/onekey/txToOneKey.js +477 -0
  71. package/lib/esm/utils/onekey/types.d.ts +79 -0
  72. package/lib/esm/utils/onekey/types.js +15 -0
  73. package/lib/esm/utils/trezor/index.d.ts +3 -0
  74. package/lib/esm/utils/trezor/index.js +3 -0
  75. package/lib/esm/utils/trezor/sign.d.ts +5 -0
  76. package/lib/esm/utils/trezor/sign.js +42 -0
  77. package/lib/esm/utils/trezor/transformations.d.ts +17 -0
  78. package/lib/esm/utils/trezor/transformations.js +60 -0
  79. package/package.json +61 -0
@@ -0,0 +1,187 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.randomImprove = void 0;
27
+ const constants_1 = require("../constants");
28
+ const CardanoWasm = __importStar(require("@emurgo/cardano-serialization-lib-asmjs"));
29
+ const common_1 = require("../utils/common");
30
+ const errors_1 = require("../utils/errors");
31
+ const logger_1 = require("../utils/logger");
32
+ // Heavily inspired by https://github.com/input-output-hk/cardano-js-sdk
33
+ const improvesSelection = (utxoAlreadySelected, input, minimumTarget, asset) => {
34
+ const oldQuantity = (0, common_1.getUtxoQuantity)(utxoAlreadySelected, asset);
35
+ // We still haven't reached the minimum target of
36
+ // 100%. Therefore, we consider any potential input
37
+ // to be an improvement:
38
+ if (oldQuantity.compare(minimumTarget) < 0)
39
+ return true;
40
+ const newQuantity = oldQuantity.checked_add((0, common_1.getUtxoQuantity)([input], asset));
41
+ const idealTarget = minimumTarget.checked_mul((0, common_1.bigNumFromStr)('2'));
42
+ const newDistance = idealTarget.compare(newQuantity) > 0
43
+ ? idealTarget.clamped_sub(newQuantity)
44
+ : newQuantity.clamped_sub(idealTarget);
45
+ const oldDistance = idealTarget.compare(oldQuantity) > 0
46
+ ? idealTarget.clamped_sub(oldQuantity)
47
+ : oldQuantity.clamped_sub(idealTarget);
48
+ // Using this input will move us closer to the
49
+ // ideal target of 200%, so we treat this as an improvement:
50
+ if (newDistance.compare(oldDistance) < 0)
51
+ return true;
52
+ // Adding the selected input would move us further
53
+ // away from the target of 200%. Reaching this case
54
+ // means we have already covered the minimum target
55
+ // of 100%, and therefore it is safe to not consider
56
+ // this token any further:
57
+ return false;
58
+ };
59
+ const selection = (utxos, outputs, txBuilder, dummyAddress) => {
60
+ const utxoSelected = [];
61
+ const utxoRemaining = JSON.parse(JSON.stringify(utxos));
62
+ const preparedOutputs = (0, common_1.setMinUtxoValueForOutputs)(txBuilder, outputs, dummyAddress);
63
+ preparedOutputs.forEach(output => {
64
+ const txOutput = (0, common_1.buildTxOutput)(output, dummyAddress);
65
+ txBuilder.add_output(txOutput);
66
+ });
67
+ // Check for UTXO_BALANCE_INSUFFICIENT comparing provided inputs with requested outputs
68
+ const assetsRemaining = (0, common_1.getUnsatisfiedAssets)(utxoSelected, preparedOutputs);
69
+ assetsRemaining.forEach(asset => {
70
+ const outputQuantity = (0, common_1.getOutputQuantity)(preparedOutputs, asset);
71
+ const utxosQuantity = (0, common_1.getUtxoQuantity)(utxos, asset);
72
+ if (outputQuantity.compare(utxosQuantity) > 0) {
73
+ throw new errors_1.CoinSelectionError(constants_1.ERROR.UTXO_BALANCE_INSUFFICIENT);
74
+ }
75
+ });
76
+ while (assetsRemaining.length > 0) {
77
+ assetsRemaining.forEach((asset, assetIndex) => {
78
+ const assetUtxos = (0, common_1.filterUtxos)(utxoRemaining, asset);
79
+ if (assetUtxos.length > 0) {
80
+ const inputIdx = Math.floor(Math.random() * assetUtxos.length);
81
+ const utxo = assetUtxos[inputIdx];
82
+ if (improvesSelection(utxoSelected, utxo, (0, common_1.getOutputQuantity)(preparedOutputs, asset), asset)) {
83
+ utxoSelected.push(utxo);
84
+ const { input, address, amount } = (0, common_1.buildTxInput)(utxo);
85
+ txBuilder.add_input(address, input, amount);
86
+ utxoRemaining.splice(utxoRemaining.indexOf(utxo), 1);
87
+ }
88
+ else {
89
+ // The selection was not improved by including
90
+ // this input. If we've reached this point, it
91
+ // means that we've already covered the minimum
92
+ // target of 100%, and therefore it is safe to
93
+ // not consider this token any further.
94
+ assetsRemaining.splice(assetIndex, 1);
95
+ }
96
+ }
97
+ else {
98
+ // The attempt to select an input failed (there were
99
+ // no inputs remaining that contained the token).
100
+ // This means that we've already covered the minimum
101
+ // quantity required (due to the pre-condition), and
102
+ // therefore it is safe to not consider this token
103
+ // any further:
104
+ assetsRemaining.splice(assetIndex, 1);
105
+ }
106
+ });
107
+ }
108
+ return { utxoSelected, utxoRemaining, preparedOutputs };
109
+ };
110
+ const calculateChange = (utxoSelected, utxoRemaining, preparedOutputs, changeAddress, maxTokensPerOutput, txBuilder) => {
111
+ const totalFeesAmount = txBuilder.min_fee();
112
+ const totalUserOutputsAmount = (0, common_1.getUserOutputQuantityWithDeposit)(preparedOutputs, 0);
113
+ const singleChangeOutput = (0, common_1.prepareChangeOutput)(txBuilder, utxoSelected, preparedOutputs, changeAddress, (0, common_1.getUtxoQuantity)(utxoSelected, 'lovelace'), (0, common_1.getUserOutputQuantityWithDeposit)(preparedOutputs, 0), totalFeesAmount, () => (0, common_1.getRandomUtxo)(txBuilder, utxoRemaining, utxoSelected));
114
+ const changeOutputs = singleChangeOutput
115
+ ? (0, common_1.splitChangeOutput)(txBuilder, singleChangeOutput, changeAddress, maxTokensPerOutput)
116
+ : [];
117
+ let requiredAmount = totalFeesAmount.checked_add(totalUserOutputsAmount);
118
+ changeOutputs.forEach(changeOutput => {
119
+ // we need to cover amounts and fees for change outputs
120
+ requiredAmount = requiredAmount
121
+ .checked_add(changeOutput.output.amount().coin())
122
+ .checked_add(changeOutput.outputFee);
123
+ });
124
+ if (requiredAmount.compare((0, common_1.getUtxoQuantity)(utxoSelected, 'lovelace')) > 0) {
125
+ const randomUtxo = (0, common_1.getRandomUtxo)(txBuilder, utxoRemaining, utxoSelected);
126
+ if (randomUtxo === null || randomUtxo === void 0 ? void 0 : randomUtxo.utxo) {
127
+ randomUtxo.addUtxo();
128
+ const { changeOutputs } = calculateChange(utxoSelected, utxoRemaining, preparedOutputs, changeAddress, maxTokensPerOutput, txBuilder);
129
+ return { changeOutputs };
130
+ }
131
+ else {
132
+ throw new errors_1.CoinSelectionError(constants_1.ERROR.UTXO_BALANCE_INSUFFICIENT);
133
+ }
134
+ }
135
+ else {
136
+ return { changeOutputs };
137
+ }
138
+ };
139
+ const randomImprove = (params, options) => {
140
+ var _a;
141
+ const { utxos, outputs, changeAddress, ttl } = params;
142
+ const logger = (0, logger_1.getLogger)(!!(options === null || options === void 0 ? void 0 : options.debug));
143
+ if (outputs.length > utxos.length) {
144
+ logger.debug('There are more outputs than utxos. Random-improve alg needs to have number of utxos same or larger than number of outputs');
145
+ throw new errors_1.CoinSelectionError(constants_1.ERROR.UTXO_NOT_FRAGMENTED_ENOUGH);
146
+ }
147
+ const txBuilder = (0, common_1.getTxBuilder)((_a = options === null || options === void 0 ? void 0 : options.feeParams) === null || _a === void 0 ? void 0 : _a.a);
148
+ if (ttl) {
149
+ txBuilder.set_ttl(ttl);
150
+ }
151
+ const { utxoSelected, utxoRemaining, preparedOutputs } = selection(utxos, outputs, txBuilder, changeAddress);
152
+ // compute change and adjust for fee
153
+ const { changeOutputs } = calculateChange(utxoSelected, utxoRemaining, preparedOutputs, changeAddress, options === null || options === void 0 ? void 0 : options._maxTokensPerOutput, txBuilder);
154
+ const finalOutputs = JSON.parse(JSON.stringify(preparedOutputs));
155
+ changeOutputs.forEach(change => {
156
+ const ch = {
157
+ isChange: true,
158
+ amount: change.output.amount().coin().to_str(),
159
+ address: changeAddress,
160
+ assets: (0, common_1.multiAssetToArray)(change.output.amount().multiasset()),
161
+ };
162
+ finalOutputs.push(ch);
163
+ txBuilder.add_output((0, common_1.buildTxOutput)(ch, changeAddress));
164
+ });
165
+ const totalUserOutputsAmount = (0, common_1.getUserOutputQuantityWithDeposit)(preparedOutputs, 0);
166
+ const totalInput = (0, common_1.getUtxoQuantity)(utxoSelected, 'lovelace');
167
+ const totalOutput = (0, common_1.getOutputQuantity)(finalOutputs, 'lovelace');
168
+ const fee = totalInput.checked_sub(totalOutput);
169
+ const totalSpent = totalUserOutputsAmount.checked_add(fee);
170
+ txBuilder.set_fee(fee);
171
+ const txBody = txBuilder.build();
172
+ const txHash = Buffer.from(CardanoWasm.hash_transaction(txBody).to_bytes()).toString('hex');
173
+ const txBodyHex = Buffer.from(txBody.to_bytes()).toString('hex');
174
+ // reorder inputs to match order within tx
175
+ const orderedInputs = (0, common_1.orderInputs)(utxoSelected, txBody);
176
+ return {
177
+ tx: { body: txBodyHex, hash: txHash, size: txBuilder.full_size() },
178
+ inputs: orderedInputs,
179
+ outputs: finalOutputs,
180
+ fee: fee.to_str(),
181
+ totalSpent: totalSpent.to_str(),
182
+ deposit: '0',
183
+ withdrawal: '0',
184
+ ttl,
185
+ };
186
+ };
187
+ exports.randomImprove = randomImprove;
@@ -0,0 +1,45 @@
1
+ import { CardanoAddressType } from './types';
2
+ export interface CardanoInput {
3
+ path: string | number[];
4
+ prev_hash: string;
5
+ prev_index: number;
6
+ }
7
+ export declare type CardanoToken = {
8
+ assetNameBytes: string;
9
+ amount: string;
10
+ };
11
+ export declare type CardanoAssetGroup = {
12
+ policyId: string;
13
+ tokenAmounts: CardanoToken[];
14
+ };
15
+ export interface CardanoCertificatePointer {
16
+ blockIndex: number;
17
+ txIndex: number;
18
+ certificateIndex: number;
19
+ }
20
+ export interface CardanoAddressParameters {
21
+ addressType: CardanoAddressType;
22
+ path: string | number[];
23
+ stakingPath?: string | number[];
24
+ stakingKeyHash?: string;
25
+ certificatePointer?: CardanoCertificatePointer;
26
+ }
27
+ export declare type CardanoOutput = {
28
+ addressParameters: CardanoAddressParameters;
29
+ amount: string;
30
+ tokenBundle?: CardanoAssetGroup[];
31
+ } | {
32
+ address: string;
33
+ amount: string;
34
+ tokenBundle?: CardanoAssetGroup[];
35
+ };
36
+ export declare enum CardanoTxWitnessType {
37
+ BYRON_WITNESS = 0,
38
+ SHELLEY_WITNESS = 1
39
+ }
40
+ export declare type CardanoSignedTxWitness = {
41
+ type: CardanoTxWitnessType;
42
+ pubKey: string;
43
+ signature: string;
44
+ chainCode?: string | null;
45
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CardanoTxWitnessType = void 0;
4
+ var CardanoTxWitnessType;
5
+ (function (CardanoTxWitnessType) {
6
+ CardanoTxWitnessType[CardanoTxWitnessType["BYRON_WITNESS"] = 0] = "BYRON_WITNESS";
7
+ CardanoTxWitnessType[CardanoTxWitnessType["SHELLEY_WITNESS"] = 1] = "SHELLEY_WITNESS";
8
+ })(CardanoTxWitnessType = exports.CardanoTxWitnessType || (exports.CardanoTxWitnessType = {}));
@@ -0,0 +1,116 @@
1
+ import * as CardanoWasm from '@emurgo/cardano-serialization-lib-asmjs';
2
+ import { BigNum } from '@emurgo/cardano-serialization-lib-asmjs';
3
+ import { CertificateType } from '../constants';
4
+ export interface Asset {
5
+ unit: string;
6
+ quantity: string;
7
+ }
8
+ export interface Utxo {
9
+ address: string;
10
+ txHash: string;
11
+ outputIndex: number;
12
+ amount: Asset[];
13
+ }
14
+ export interface CardanoCertificatePointer {
15
+ blockIndex: number;
16
+ txIndex: number;
17
+ certificateIndex: number;
18
+ }
19
+ export interface BaseOutput {
20
+ setMax?: boolean;
21
+ isChange?: boolean;
22
+ assets: Asset[];
23
+ }
24
+ export interface ExternalOutput extends BaseOutput {
25
+ amount: string;
26
+ address: string;
27
+ setMax?: false;
28
+ }
29
+ export interface ExternalOutputIncomplete extends BaseOutput {
30
+ amount?: string | undefined;
31
+ address?: string;
32
+ setMax: boolean;
33
+ }
34
+ export interface ChangeOutput extends BaseOutput {
35
+ amount: string;
36
+ address: string;
37
+ isChange: true;
38
+ }
39
+ export declare type FinalOutput = ExternalOutput | ChangeOutput;
40
+ export declare type UserOutput = ExternalOutput | ExternalOutputIncomplete;
41
+ export declare type Output = FinalOutput | ExternalOutputIncomplete;
42
+ export interface OutputCost {
43
+ output: CardanoWasm.TransactionOutput;
44
+ outputFee: BigNum;
45
+ minOutputAmount: BigNum;
46
+ }
47
+ export declare enum CardanoAddressType {
48
+ BASE = 0,
49
+ BASE_SCRIPT_KEY = 1,
50
+ BASE_KEY_SCRIPT = 2,
51
+ BASE_SCRIPT_SCRIPT = 3,
52
+ POINTER = 4,
53
+ POINTER_SCRIPT = 5,
54
+ ENTERPRISE = 6,
55
+ ENTERPRISE_SCRIPT = 7,
56
+ BYRON = 8,
57
+ REWARD = 14,
58
+ REWARD_SCRIPT = 15
59
+ }
60
+ export interface CoinSelectionResult {
61
+ tx: {
62
+ body: string;
63
+ hash: string;
64
+ size: number;
65
+ };
66
+ inputs: Utxo[];
67
+ outputs: Output[];
68
+ fee: string;
69
+ totalSpent: string;
70
+ deposit: string;
71
+ withdrawal: string;
72
+ ttl?: number;
73
+ max?: string;
74
+ }
75
+ export declare type PrecomposedTransaction = ({
76
+ type: 'final';
77
+ outputs: FinalOutput[];
78
+ } & Omit<CoinSelectionResult, 'outputs'>) | ({
79
+ type: 'nonfinal';
80
+ } & Pick<CoinSelectionResult, 'fee' | 'totalSpent' | 'deposit' | 'withdrawal' | 'max'>);
81
+ export interface Withdrawal {
82
+ stakeAddress: string;
83
+ amount: string;
84
+ }
85
+ export declare type CertificateTypeType = typeof CertificateType;
86
+ export interface CertificateStakeRegistration {
87
+ type: CertificateTypeType['STAKE_REGISTRATION'] | CertificateTypeType['STAKE_DEREGISTRATION'];
88
+ stakingKeyHash?: string;
89
+ }
90
+ export interface CertificateStakeDelegation {
91
+ type: CertificateTypeType['STAKE_DELEGATION'];
92
+ stakingKeyHash?: string;
93
+ pool: string;
94
+ }
95
+ export interface CertificateStakePoolRegistration {
96
+ type: CertificateTypeType['STAKE_POOL_REGISTRATION'];
97
+ pool_parameters: Record<string, unknown>;
98
+ }
99
+ export declare type Certificate = CertificateStakeRegistration | CertificateStakeDelegation | CertificateStakePoolRegistration;
100
+ export interface Options {
101
+ feeParams?: {
102
+ a: string;
103
+ };
104
+ debug?: boolean;
105
+ forceLargestFirstSelection?: boolean;
106
+ _maxTokensPerOutput?: number;
107
+ }
108
+ export interface CoinSelectionParams {
109
+ utxos: Utxo[];
110
+ outputs: UserOutput[];
111
+ changeAddress: string;
112
+ certificates: Certificate[];
113
+ withdrawals: Withdrawal[];
114
+ accountPubKey: string;
115
+ ttl?: number;
116
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CardanoAddressType = void 0;
4
+ var CardanoAddressType;
5
+ (function (CardanoAddressType) {
6
+ CardanoAddressType[CardanoAddressType["BASE"] = 0] = "BASE";
7
+ CardanoAddressType[CardanoAddressType["BASE_SCRIPT_KEY"] = 1] = "BASE_SCRIPT_KEY";
8
+ CardanoAddressType[CardanoAddressType["BASE_KEY_SCRIPT"] = 2] = "BASE_KEY_SCRIPT";
9
+ CardanoAddressType[CardanoAddressType["BASE_SCRIPT_SCRIPT"] = 3] = "BASE_SCRIPT_SCRIPT";
10
+ CardanoAddressType[CardanoAddressType["POINTER"] = 4] = "POINTER";
11
+ CardanoAddressType[CardanoAddressType["POINTER_SCRIPT"] = 5] = "POINTER_SCRIPT";
12
+ CardanoAddressType[CardanoAddressType["ENTERPRISE"] = 6] = "ENTERPRISE";
13
+ CardanoAddressType[CardanoAddressType["ENTERPRISE_SCRIPT"] = 7] = "ENTERPRISE_SCRIPT";
14
+ CardanoAddressType[CardanoAddressType["BYRON"] = 8] = "BYRON";
15
+ CardanoAddressType[CardanoAddressType["REWARD"] = 14] = "REWARD";
16
+ CardanoAddressType[CardanoAddressType["REWARD_SCRIPT"] = 15] = "REWARD_SCRIPT";
17
+ })(CardanoAddressType = exports.CardanoAddressType || (exports.CardanoAddressType = {}));
@@ -0,0 +1,46 @@
1
+ import * as CardanoWasm from '@emurgo/cardano-serialization-lib-asmjs';
2
+ import { CARDANO_PARAMS } from '../constants';
3
+ import { Certificate, Output, Utxo, Withdrawal, OutputCost, UserOutput, Asset } from '../types/types';
4
+ export declare const bigNumFromStr: (num: string) => CardanoWasm.BigNum;
5
+ export declare const getProtocolMagic: (tesnet?: boolean) => (typeof CARDANO_PARAMS.PROTOCOL_MAGICS)['mainnet'] | (typeof CARDANO_PARAMS.PROTOCOL_MAGICS)['testnet'];
6
+ export declare const getNetworkId: (testnet?: boolean) => (typeof CARDANO_PARAMS.NETWORK_IDS)['mainnet'] | (typeof CARDANO_PARAMS.NETWORK_IDS)['testnet'];
7
+ export declare const parseAsset: (hex: string) => {
8
+ policyId: string;
9
+ assetNameInHex: string;
10
+ };
11
+ export declare const buildMultiAsset: (assets: Asset[]) => CardanoWasm.MultiAsset;
12
+ export declare const multiAssetToArray: (multiAsset: CardanoWasm.MultiAsset | undefined) => Asset[];
13
+ export declare const getAssetAmount: (obj: Pick<Utxo, 'amount'>, asset?: string) => string;
14
+ export declare const getUtxoQuantity: (utxos: Utxo[], asset?: string) => CardanoWasm.BigNum;
15
+ export declare const getOutputQuantity: (outputs: Output[], asset?: string) => CardanoWasm.BigNum;
16
+ export declare const sortUtxos: (utxos: Utxo[], asset?: string) => Utxo[];
17
+ export declare const buildTxInput: (utxo: Utxo) => {
18
+ input: CardanoWasm.TransactionInput;
19
+ address: CardanoWasm.Address;
20
+ amount: CardanoWasm.Value;
21
+ };
22
+ export declare const buildTxOutput: (output: Output, dummyAddress: string) => CardanoWasm.TransactionOutput;
23
+ export declare const getOutputCost: (txBuilder: CardanoWasm.TransactionBuilder, output: Output, dummyAddress: string) => OutputCost;
24
+ export declare const prepareWithdrawals: (withdrawals: Withdrawal[]) => CardanoWasm.Withdrawals;
25
+ export declare const prepareCertificates: (certificates: Certificate[], accountKey: CardanoWasm.Bip32PublicKey) => CardanoWasm.Certificates;
26
+ export declare const calculateRequiredDeposit: (certificates: Certificate[]) => number;
27
+ export declare const setMinUtxoValueForOutputs: (txBuilder: CardanoWasm.TransactionBuilder, outputs: UserOutput[], dummyAddress: string) => UserOutput[];
28
+ export declare const splitChangeOutput: (txBuilder: CardanoWasm.TransactionBuilder, singleChangeOutput: OutputCost, changeAddress: string, maxTokensPerOutput?: number) => OutputCost[];
29
+ export declare const prepareChangeOutput: (txBuilder: CardanoWasm.TransactionBuilder, usedUtxos: Utxo[], preparedOutputs: Output[], changeAddress: string, utxosTotalAmount: CardanoWasm.BigNum, totalOutputAmount: CardanoWasm.BigNum, totalFeesAmount: CardanoWasm.BigNum, pickAdditionalUtxo?: () => ReturnType<typeof getRandomUtxo>) => OutputCost | null;
30
+ export declare const getTxBuilder: (a?: string) => CardanoWasm.TransactionBuilder;
31
+ export declare const getUnsatisfiedAssets: (selectedUtxos: Utxo[], outputs: Output[]) => string[];
32
+ export declare const getInitialUtxoSet: (utxos: Utxo[], maxOutput: UserOutput | undefined) => {
33
+ used: Utxo[];
34
+ remaining: Utxo[];
35
+ };
36
+ export declare const setMaxOutput: (maxOutput: UserOutput, changeOutput: OutputCost | null) => {
37
+ maxOutput: UserOutput;
38
+ };
39
+ export declare const getUserOutputQuantityWithDeposit: (outputs: UserOutput[], deposit: number, asset?: string) => CardanoWasm.BigNum;
40
+ export declare const filterUtxos: (utxos: Utxo[], asset: string) => Utxo[];
41
+ export declare const getRandomUtxo: (txBuilder: CardanoWasm.TransactionBuilder, utxoRemaining: Utxo[], utxoSelected: Utxo[]) => {
42
+ utxo: Utxo;
43
+ addUtxo: () => void;
44
+ } | null;
45
+ export declare const calculateUserOutputsFee: (txBuilder: CardanoWasm.TransactionBuilder, userOutputs: UserOutput[], changeAddress: string) => CardanoWasm.BigNum;
46
+ export declare const orderInputs: (inputsToOrder: Utxo[], txBody: CardanoWasm.TransactionBody) => Utxo[];