@hydrawallet-sdk/core 0.0.2

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 (59) hide show
  1. package/dist/constants/chain.d.ts +11 -0
  2. package/dist/constants/chain.d.ts.map +1 -0
  3. package/dist/constants/cost-models.d.ts +4 -0
  4. package/dist/constants/cost-models.d.ts.map +1 -0
  5. package/dist/constants/index.d.ts +7 -0
  6. package/dist/constants/index.d.ts.map +1 -0
  7. package/dist/constants/placeholder.d.ts +4 -0
  8. package/dist/constants/placeholder.d.ts.map +1 -0
  9. package/dist/constants/protocol-parameters.d.ts +5 -0
  10. package/dist/constants/protocol-parameters.d.ts.map +1 -0
  11. package/dist/embedded.d.ts +84 -0
  12. package/dist/embedded.d.ts.map +1 -0
  13. package/dist/index.d.ts +15 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +1339 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/index.mjs +1259 -0
  18. package/dist/index.mjs.map +1 -0
  19. package/dist/types/cardano/asset-metadata.d.ts +48 -0
  20. package/dist/types/cardano/asset-metadata.d.ts.map +1 -0
  21. package/dist/types/cardano/asset.d.ts +8 -0
  22. package/dist/types/cardano/asset.d.ts.map +1 -0
  23. package/dist/types/cardano/data-signature.d.ts +5 -0
  24. package/dist/types/cardano/data-signature.d.ts.map +1 -0
  25. package/dist/types/cardano/data.d.ts +5 -0
  26. package/dist/types/cardano/data.d.ts.map +1 -0
  27. package/dist/types/cardano/era.d.ts +2 -0
  28. package/dist/types/cardano/era.d.ts.map +1 -0
  29. package/dist/types/cardano/index.d.ts +7 -0
  30. package/dist/types/cardano/index.d.ts.map +1 -0
  31. package/dist/types/cardano/tx-output.d.ts +60 -0
  32. package/dist/types/cardano/tx-output.d.ts.map +1 -0
  33. package/dist/types/cardano/utxo.d.ts +63 -0
  34. package/dist/types/cardano/utxo.d.ts.map +1 -0
  35. package/dist/types/protocol.d.ts +25 -0
  36. package/dist/types/protocol.d.ts.map +1 -0
  37. package/dist/types/wallet/fetcher.d.ts +5 -0
  38. package/dist/types/wallet/fetcher.d.ts.map +1 -0
  39. package/dist/types/wallet/index.d.ts +20 -0
  40. package/dist/types/wallet/index.d.ts.map +1 -0
  41. package/dist/types/wallet/signer.d.ts +7 -0
  42. package/dist/types/wallet/signer.d.ts.map +1 -0
  43. package/dist/types/wallet/submitter.d.ts +4 -0
  44. package/dist/types/wallet/submitter.d.ts.map +1 -0
  45. package/dist/utils/cardano-wasm/build-keys.d.ts +47 -0
  46. package/dist/utils/cardano-wasm/build-keys.d.ts.map +1 -0
  47. package/dist/utils/cardano-wasm/converter.d.ts +4 -0
  48. package/dist/utils/cardano-wasm/converter.d.ts.map +1 -0
  49. package/dist/utils/cardano-wasm/deserializer.d.ts +7 -0
  50. package/dist/utils/cardano-wasm/deserializer.d.ts.map +1 -0
  51. package/dist/utils/cardano-wasm/resolver.d.ts +9 -0
  52. package/dist/utils/cardano-wasm/resolver.d.ts.map +1 -0
  53. package/dist/utils/cardano-wasm/serializer.d.ts +2 -0
  54. package/dist/utils/cardano-wasm/serializer.d.ts.map +1 -0
  55. package/dist/utils/parser.d.ts +43 -0
  56. package/dist/utils/parser.d.ts.map +1 -0
  57. package/dist/wallet.d.ts +21 -0
  58. package/dist/wallet.d.ts.map +1 -0
  59. package/package.json +58 -0
package/dist/index.js ADDED
@@ -0,0 +1,1339 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ AppWallet: () => AppWallet,
34
+ ChainDerivation: () => ChainDerivation,
35
+ CoinTypes: () => CoinTypes,
36
+ DEFAULT_PROTOCOL_PARAMETERS: () => DEFAULT_PROTOCOL_PARAMETERS,
37
+ DEFAULT_V1_COST_MODEL_LIST: () => DEFAULT_V1_COST_MODEL_LIST,
38
+ DEFAULT_V2_COST_MODEL_LIST: () => DEFAULT_V2_COST_MODEL_LIST,
39
+ DEFAULT_V3_COST_MODEL_LIST: () => DEFAULT_V3_COST_MODEL_LIST,
40
+ DREP_DEPOSIT: () => DREP_DEPOSIT,
41
+ EmbeddedWallet: () => EmbeddedWallet,
42
+ HARDENED_KEY_START: () => HARDENED_KEY_START,
43
+ LANGUAGE_VERSIONS: () => LANGUAGE_VERSIONS,
44
+ NETWORK_ID: () => NETWORK_ID,
45
+ NETWORK_MAGIC: () => NETWORK_MAGIC,
46
+ PLACEHOLDER_ADDRESS: () => PLACEHOLDER_ADDRESS,
47
+ Purpose: () => Purpose,
48
+ WalletStaticMethods: () => WalletStaticMethods,
49
+ buildBaseAddress: () => buildBaseAddress,
50
+ buildDRepID: () => buildDRepID,
51
+ buildEnterpriseAddress: () => buildEnterpriseAddress,
52
+ buildKeys: () => buildKeys,
53
+ buildRewardAddress: () => buildRewardAddress,
54
+ bytesToHex: () => bytesToHex,
55
+ castProtocol: () => castProtocol,
56
+ clampScalar: () => clampScalar,
57
+ convertUTxOObjectToUTxO: () => convertUTxOObjectToUTxO,
58
+ convertUTxOToUTxOObject: () => convertUTxOToUTxOObject,
59
+ deserializeAssetUnit: () => deserializeAssetUnit,
60
+ deserializeTx: () => deserializeTx,
61
+ fromUTF8: () => fromUTF8,
62
+ fungibleAssetKeys: () => fungibleAssetKeys,
63
+ hexToBytes: () => hexToBytes,
64
+ hexToString: () => hexToString,
65
+ mergeAssets: () => mergeAssets,
66
+ metadataStandardKeys: () => metadataStandardKeys,
67
+ metadataToCip68: () => metadataToCip68,
68
+ resolveTxBodyHash: () => resolveTxBodyHash,
69
+ resolveTxFees: () => resolveTxFees,
70
+ resolveTxHash: () => resolveTxHash,
71
+ royaltiesStandardKeys: () => royaltiesStandardKeys,
72
+ serializeAssetUnit: () => serializeAssetUnit,
73
+ stringToHex: () => stringToHex,
74
+ stripExtendedKey: () => stripExtendedKey,
75
+ toBytes: () => toBytes,
76
+ toUTF8: () => toUTF8
77
+ });
78
+ module.exports = __toCommonJS(src_exports);
79
+
80
+ // src/embedded.ts
81
+ var BaseEncoding = __toESM(require("@scure/base"));
82
+ var import_bip39 = require("bip39");
83
+ var import_cardano_wasm4 = require("@hydrawallet-sdk/cardano-wasm");
84
+
85
+ // src/utils/cardano-wasm/build-keys.ts
86
+ var import_cardano_wasm2 = require("@hydrawallet-sdk/cardano-wasm");
87
+
88
+ // src/constants/chain.ts
89
+ var import_cardano_wasm = require("@hydrawallet-sdk/cardano-wasm");
90
+ var NETWORK_ID = {
91
+ MAINNET: import_cardano_wasm.CardanoWASM.NetworkInfo.mainnet().network_id(),
92
+ PREPROD: import_cardano_wasm.CardanoWASM.NetworkInfo.testnet_preprod().network_id(),
93
+ PREVIEW: import_cardano_wasm.CardanoWASM.NetworkInfo.testnet_preview().network_id()
94
+ };
95
+ var NETWORK_MAGIC = {
96
+ MAINNET: import_cardano_wasm.CardanoWASM.NetworkInfo.mainnet().protocol_magic(),
97
+ PREPROD: import_cardano_wasm.CardanoWASM.NetworkInfo.testnet_preprod().protocol_magic(),
98
+ PREVIEW: import_cardano_wasm.CardanoWASM.NetworkInfo.testnet_preview().protocol_magic()
99
+ };
100
+
101
+ // src/utils/cardano-wasm/build-keys.ts
102
+ var buildBaseAddress = (networkId, paymentKeyHash, stakeKeyHash) => {
103
+ const paymentCredential = import_cardano_wasm2.CardanoWASM.Credential.from_keyhash(paymentKeyHash);
104
+ const stakeCredential = import_cardano_wasm2.CardanoWASM.Credential.from_keyhash(stakeKeyHash);
105
+ return import_cardano_wasm2.CardanoWASM.BaseAddress.new(networkId, paymentCredential, stakeCredential);
106
+ };
107
+ var buildEnterpriseAddress = (networkId, paymentKeyHash) => {
108
+ const paymentCredential = import_cardano_wasm2.CardanoWASM.Credential.from_keyhash(paymentKeyHash);
109
+ return import_cardano_wasm2.CardanoWASM.EnterpriseAddress.new(networkId, paymentCredential);
110
+ };
111
+ var buildRewardAddress = (networkId, stakeKeyHash) => {
112
+ const stakeCredential = import_cardano_wasm2.CardanoWASM.Credential.from_keyhash(stakeKeyHash);
113
+ return import_cardano_wasm2.CardanoWASM.RewardAddress.new(networkId, stakeCredential);
114
+ };
115
+ var buildDRepID = (dRepKey, networkId = NETWORK_ID.MAINNET) => {
116
+ console.log("buildDRepID", dRepKey.to_hex(), networkId);
117
+ return null;
118
+ };
119
+ var Purpose = /* @__PURE__ */ ((Purpose2) => {
120
+ Purpose2[Purpose2["CIP1852"] = 1852] = "CIP1852";
121
+ return Purpose2;
122
+ })(Purpose || {});
123
+ var CoinTypes = /* @__PURE__ */ ((CoinTypes2) => {
124
+ CoinTypes2[CoinTypes2["CARDANO"] = 1815] = "CARDANO";
125
+ return CoinTypes2;
126
+ })(CoinTypes || {});
127
+ var ChainDerivation = /* @__PURE__ */ ((ChainDerivation2) => {
128
+ ChainDerivation2[ChainDerivation2["EXTERNAL"] = 0] = "EXTERNAL";
129
+ ChainDerivation2[ChainDerivation2["INTERNAL"] = 1] = "INTERNAL";
130
+ ChainDerivation2[ChainDerivation2["CHIMERIC"] = 2] = "CHIMERIC";
131
+ ChainDerivation2[ChainDerivation2["DREP"] = 3] = "DREP";
132
+ return ChainDerivation2;
133
+ })(ChainDerivation || {});
134
+ function harden(num) {
135
+ return 2147483648 + num;
136
+ }
137
+ var buildKeys = (privateKeyHex, accountIndex, keyIndex = 0) => {
138
+ if (Array.isArray(privateKeyHex)) {
139
+ return {
140
+ // TODO: need to verify this
141
+ accountKey: import_cardano_wasm2.CardanoWASM.Bip32PrivateKey.from_hex(privateKeyHex[0]),
142
+ paymentKey: import_cardano_wasm2.CardanoWASM.Bip32PrivateKey.from_hex(privateKeyHex[0]),
143
+ stakeKey: import_cardano_wasm2.CardanoWASM.Bip32PrivateKey.from_hex(privateKeyHex[1])
144
+ };
145
+ }
146
+ const privateKey = import_cardano_wasm2.CardanoWASM.Bip32PrivateKey.from_hex(privateKeyHex);
147
+ const accountKey = privateKey.derive(harden(1852 /* CIP1852 */)).derive(harden(1815 /* CARDANO */)).derive(harden(accountIndex));
148
+ const paymentKey = accountKey.derive(0 /* EXTERNAL */).derive(keyIndex);
149
+ const stakeKey = accountKey.derive(2 /* CHIMERIC */).derive(keyIndex);
150
+ const dRepKey = accountKey.derive(3 /* DREP */).derive(keyIndex);
151
+ return { accountKey, paymentKey, stakeKey, dRepKey };
152
+ };
153
+ var clampScalar = (scalar) => {
154
+ if (scalar[0] !== void 0) {
155
+ scalar[0] &= 248;
156
+ }
157
+ if (scalar[31] !== void 0) {
158
+ scalar[31] &= 31;
159
+ scalar[31] |= 64;
160
+ }
161
+ return scalar;
162
+ };
163
+ var stripExtendedKey = (extendedKeyHex) => {
164
+ if (extendedKeyHex.length !== 192) {
165
+ throw new Error("Extended key must be 192 hex characters (96 bytes)");
166
+ }
167
+ const strippedKeyHex = extendedKeyHex.slice(0, 128);
168
+ return strippedKeyHex;
169
+ };
170
+
171
+ // src/utils/cardano-wasm/resolver.ts
172
+ var import_cardano_wasm3 = require("@hydrawallet-sdk/cardano-wasm");
173
+ var resolveTxHash = (cborHex) => {
174
+ return import_cardano_wasm3.CardanoWASM.FixedTransaction.from_hex(cborHex).transaction_hash().to_hex();
175
+ };
176
+ var resolveTxBodyHash = (txBody) => {
177
+ const tx = import_cardano_wasm3.CardanoWASM.FixedTransaction.new_from_body_bytes(txBody.to_bytes());
178
+ return tx.transaction_hash();
179
+ };
180
+
181
+ // src/utils/parser.ts
182
+ var bytesToHex = (bytes) => {
183
+ if (Buffer.isBuffer(bytes)) {
184
+ return bytes.toString("hex");
185
+ }
186
+ if (bytes instanceof ArrayBuffer) {
187
+ return Buffer.from(bytes).toString("hex");
188
+ }
189
+ return Buffer.from(bytes).toString("hex");
190
+ };
191
+ var hexToBytes = (hex) => Buffer.from(hex, "hex");
192
+ var stringToHex = (str) => Buffer.from(str, "utf8").toString("hex");
193
+ var hexToString = (hex) => Buffer.from(hex, "hex").toString("utf8");
194
+ var toBytes = (hex) => {
195
+ if (hex.length % 2 === 0 && /^[0-9A-F]*$/i.test(hex))
196
+ return Buffer.from(hex, "hex");
197
+ return Buffer.from(hex, "utf-8");
198
+ };
199
+ var fromUTF8 = (utf8) => {
200
+ return Buffer.from(utf8, "utf-8").toString("hex");
201
+ };
202
+ var toUTF8 = (hex) => Buffer.from(hex, "hex").toString("utf-8");
203
+
204
+ // src/embedded.ts
205
+ var WalletStaticMethods = class {
206
+ static privateKeyBech32ToPrivateKeyHex(_bech32) {
207
+ const bech32DecodedBytes = BaseEncoding.bech32.decodeToBytes(_bech32).bytes;
208
+ const bip32PrivateKey = import_cardano_wasm4.CardanoWASM.Bip32PrivateKey.from_bytes(bech32DecodedBytes);
209
+ return bip32PrivateKey.to_hex();
210
+ }
211
+ static mnemonicToPrivateKeyHex(words, password = "") {
212
+ const entropy = (0, import_bip39.mnemonicToEntropy)(words.join(" "));
213
+ const bip32PrivateKey = import_cardano_wasm4.CardanoWASM.Bip32PrivateKey.from_bip39_entropy(toBytes(entropy), toBytes(password));
214
+ return bip32PrivateKey.to_hex();
215
+ }
216
+ static privateKeyHexToBech32(privateKeyHex) {
217
+ const bip32PrivateKey = import_cardano_wasm4.CardanoWASM.Bip32PrivateKey.from_hex(privateKeyHex);
218
+ return bip32PrivateKey.to_bech32();
219
+ }
220
+ static signingKeyToHexes(paymentKey, stakeKey) {
221
+ return [
222
+ paymentKey.startsWith("5820") ? paymentKey.slice(4) : paymentKey,
223
+ stakeKey.startsWith("5820") ? stakeKey.slice(4) : stakeKey
224
+ ];
225
+ }
226
+ static bip32BytesToPrivateKeyHex(bip32Bytes) {
227
+ const bip32PrivateKey = import_cardano_wasm4.CardanoWASM.Bip32PrivateKey.from_bytes(bip32Bytes);
228
+ return bip32PrivateKey.to_hex();
229
+ }
230
+ static getAddresses(paymentKey, stakingKey, networkId = 0) {
231
+ const baseAddress = buildBaseAddress(
232
+ networkId,
233
+ paymentKey.to_public().to_raw_key().hash(),
234
+ stakingKey.to_public().to_raw_key().hash()
235
+ ).to_address();
236
+ const enterpriseAddress = buildEnterpriseAddress(networkId, paymentKey.to_public().to_raw_key().hash()).to_address();
237
+ const rewardAddress = buildRewardAddress(networkId, stakingKey.to_public().to_raw_key().hash()).to_address();
238
+ return {
239
+ baseAddress,
240
+ enterpriseAddress,
241
+ rewardAddress
242
+ };
243
+ }
244
+ static generateMnemonic(strength = 256) {
245
+ const mnemonic = (0, import_bip39.generateMnemonic)(strength);
246
+ return mnemonic.split(" ");
247
+ }
248
+ // static getDRepKey(
249
+ // dRepKey: Ed25519PrivateKey,
250
+ // networkId = 0
251
+ // ): {
252
+ // pubDRepKey: string
253
+ // dRepIDBech32: DRepID
254
+ // dRepIDHash: Ed25519KeyHashHex
255
+ // } {
256
+ // const pubDRepKey = dRepKey.toPublic().hex().toString()
257
+ // const dRepIDBech32 = buildDRepID(Ed25519PublicKeyHex(pubDRepKey), networkId)
258
+ // const dRep = DRep.newKeyHash(dRepKey.toPublic().hash().hex())
259
+ // const dRepIDHash = dRep.toKeyHash()!
260
+ // return {
261
+ // pubDRepKey,
262
+ // dRepIDBech32,
263
+ // dRepIDHash
264
+ // }
265
+ // }
266
+ };
267
+ var EmbeddedWallet = class extends WalletStaticMethods {
268
+ constructor(options) {
269
+ super();
270
+ this._networkId = options.networkId;
271
+ switch (options.key.type) {
272
+ case "mnemonic":
273
+ this._walletSecret = WalletStaticMethods.mnemonicToPrivateKeyHex(options.key.words);
274
+ break;
275
+ case "root":
276
+ this._walletSecret = WalletStaticMethods.privateKeyBech32ToPrivateKeyHex(options.key.bech32);
277
+ break;
278
+ case "cli":
279
+ this._walletSecret = WalletStaticMethods.signingKeyToHexes(
280
+ options.key.payment,
281
+ options.key.stake ?? "f0".repeat(32)
282
+ );
283
+ break;
284
+ case "bip32Bytes":
285
+ this._walletSecret = WalletStaticMethods.bip32BytesToPrivateKeyHex(options.key.bip32Bytes);
286
+ break;
287
+ }
288
+ }
289
+ getPrivateKeyHex() {
290
+ if (this._walletSecret == void 0)
291
+ throw new Error("[EmbeddedWallet] No keys initialized");
292
+ return this._walletSecret;
293
+ }
294
+ getAccount(accountIndex = 0, keyIndex = 0) {
295
+ if (this._walletSecret == void 0)
296
+ throw new Error("[EmbeddedWallet] No keys initialized");
297
+ const { paymentKey, stakeKey } = buildKeys(this._walletSecret, accountIndex, keyIndex);
298
+ const { baseAddress, enterpriseAddress, rewardAddress } = WalletStaticMethods.getAddresses(
299
+ paymentKey,
300
+ stakeKey,
301
+ this._networkId
302
+ );
303
+ const _account = {
304
+ baseAddress,
305
+ enterpriseAddress,
306
+ rewardAddress,
307
+ baseAddressBech32: baseAddress.to_bech32(),
308
+ enterpriseAddressBech32: enterpriseAddress.to_bech32(),
309
+ rewardAddressBech32: rewardAddress.to_bech32(),
310
+ paymentKey,
311
+ stakeKey,
312
+ paymentKeyHex: stripExtendedKey(paymentKey.to_hex()),
313
+ stakeKeyHex: stripExtendedKey(stakeKey.to_hex()),
314
+ extendedPaymentKeyHex: paymentKey.to_hex(),
315
+ extendedStakeKeyHex: stakeKey.to_hex()
316
+ };
317
+ return _account;
318
+ }
319
+ /**
320
+ * Get wallet network ID.
321
+ *
322
+ * @returns network ID
323
+ */
324
+ getNetworkId() {
325
+ return this._networkId;
326
+ }
327
+ /**
328
+ * This endpoints sign the provided transaction (unsignedTx) with the private key of the owner.
329
+ *
330
+ * @param unsignedTx - a transaction in CBOR
331
+ * @param accountIndex account index (default: 0)
332
+ * @param keyIndex key index (default: 0)
333
+ * @returns VkeyWitness
334
+ */
335
+ signTx(unsignedTx, accountIndex = 0, keyIndex = 0) {
336
+ try {
337
+ const txHashHex = resolveTxHash(unsignedTx);
338
+ const { paymentKey } = this.getAccount(accountIndex, keyIndex);
339
+ const privateSigningKey = paymentKey.to_raw_key();
340
+ const vkeyWitness = import_cardano_wasm4.CardanoWASM.make_vkey_witness(import_cardano_wasm4.CardanoWASM.TransactionHash.from_hex(txHashHex), privateSigningKey);
341
+ return vkeyWitness;
342
+ } catch (error) {
343
+ throw new Error(`[EmbeddedWallet] An error occurred during signTx: ${error}.`);
344
+ }
345
+ }
346
+ // /**
347
+ // * This endpoint utilizes the [CIP-8 - Message Signing](https://cips.cardano.org/cips/cip8/) to sign arbitrary data, to verify the data was signed by the owner of the private key.
348
+ // *
349
+ // * @param address - bech32 address to sign the data with
350
+ // * @param payload - the data to be signed
351
+ // * @param accountIndex account index (default: 0)
352
+ // * @returns a signature
353
+ // */
354
+ // signData(address: string, payload: string, accountIndex = 0, keyIndex = 0): DataSignature {
355
+ // try {
356
+ // const { baseAddress, enterpriseAddress, rewardAddress, paymentKey } = this.getAccount(accountIndex, keyIndex)
357
+ // const foundAddress = [baseAddress, enterpriseAddress, rewardAddress].find(a => a.toBech32() === address)
358
+ // if (foundAddress === undefined)
359
+ // throw new Error(`[EmbeddedWallet] Address: ${address} doesn't belong to this account.`)
360
+ // // todo tw
361
+ // return signData(payload, {
362
+ // address: Address.fromBech32(address),
363
+ // key: paymentKey
364
+ // })
365
+ // } catch (error) {
366
+ // throw new Error(`[EmbeddedWallet] An error occurred during signData: ${error}.`)
367
+ // }
368
+ // }
369
+ };
370
+
371
+ // src/utils/cardano-wasm/deserializer.ts
372
+ var import_cardano_wasm5 = require("@hydrawallet-sdk/cardano-wasm");
373
+ var deserializeTx = (txCborHex) => {
374
+ return import_cardano_wasm5.CardanoWASM.FixedTransaction.from_bytes(Buffer.from(txCborHex, "hex"));
375
+ };
376
+ var deserializeAssetUnit = (assetUnit) => {
377
+ const policyId = assetUnit.substring(0, 56);
378
+ const assetName = assetUnit.substring(56);
379
+ return { policyId, assetName };
380
+ };
381
+
382
+ // src/wallet.ts
383
+ var AppWallet = class {
384
+ constructor(options) {
385
+ this._fetcher = options.fetcher;
386
+ this._submitter = options.submitter;
387
+ switch (options.key.type) {
388
+ case "mnemonic":
389
+ this._wallet = new EmbeddedWallet({
390
+ networkId: options.networkId,
391
+ key: {
392
+ type: "mnemonic",
393
+ words: options.key.words
394
+ }
395
+ });
396
+ break;
397
+ case "root":
398
+ this._wallet = new EmbeddedWallet({
399
+ networkId: options.networkId,
400
+ key: {
401
+ type: "root",
402
+ bech32: options.key.bech32
403
+ }
404
+ });
405
+ break;
406
+ case "cli":
407
+ this._wallet = new EmbeddedWallet({
408
+ networkId: options.networkId,
409
+ key: {
410
+ type: "cli",
411
+ payment: options.key.payment,
412
+ stake: options.key.stake
413
+ }
414
+ });
415
+ }
416
+ }
417
+ getAccount(accountIndex = 0, keyIndex = 0) {
418
+ return this._wallet.getAccount(accountIndex, keyIndex);
419
+ }
420
+ getEnterpriseAddress(accountIndex = 0, keyIndex = 0) {
421
+ const account = this._wallet.getAccount(accountIndex, keyIndex);
422
+ return account.enterpriseAddressBech32;
423
+ }
424
+ getPaymentAddress(accountIndex = 0, keyIndex = 0) {
425
+ const account = this._wallet.getAccount(accountIndex, keyIndex);
426
+ return account.baseAddressBech32;
427
+ }
428
+ getRewardAddress(accountIndex = 0, keyIndex = 0) {
429
+ const account = this._wallet.getAccount(accountIndex, keyIndex);
430
+ return account.rewardAddressBech32;
431
+ }
432
+ getNetworkId() {
433
+ return this._wallet.getNetworkId();
434
+ }
435
+ async signTx(unsignedTx, partialSign = false, accountIndex = 0, keyIndex = 0) {
436
+ try {
437
+ const tx = deserializeTx(unsignedTx);
438
+ if (!partialSign && tx.witness_set().vkeys() !== void 0 && tx.witness_set().vkeys()?.len() !== 0)
439
+ throw new Error("Signatures already exist in the transaction in a non partial sign call");
440
+ const prvSigningKey = this._wallet.getAccount(accountIndex, keyIndex).paymentKey.to_raw_key();
441
+ tx.sign_and_add_vkey_signature(prvSigningKey);
442
+ return tx.to_hex();
443
+ } catch (error) {
444
+ throw new Error(`[AppWallet] An error occurred during signTx: ${error}.`);
445
+ }
446
+ }
447
+ static brew(strength = 256) {
448
+ return EmbeddedWallet.generateMnemonic(strength);
449
+ }
450
+ async signData(address, payload, accountIndex = 0, keyIndex = 0) {
451
+ try {
452
+ console.log(">>> signData", address, payload, accountIndex, keyIndex);
453
+ return new Promise(() => {
454
+ throw new Error(`[AppWallet] signData() is not implemented.`);
455
+ });
456
+ } catch (error) {
457
+ throw new Error(`[AppWallet] An error occurred during signData: ${error}.`);
458
+ }
459
+ }
460
+ signTxs(unsignedTxs, partialSign) {
461
+ console.log(">>> signTxs", unsignedTxs, partialSign);
462
+ throw new Error(`[AppWallet] signTxs() is not implemented.`);
463
+ }
464
+ submitTx(tx) {
465
+ console.log(">>> submitTx", tx);
466
+ throw new Error(`[AppWallet] submitTx() is not implemented.`);
467
+ }
468
+ };
469
+
470
+ // src/constants/cost-models.ts
471
+ var DEFAULT_V1_COST_MODEL_LIST = [
472
+ 100788,
473
+ 420,
474
+ 1,
475
+ 1,
476
+ 1e3,
477
+ 173,
478
+ 0,
479
+ 1,
480
+ 1e3,
481
+ 59957,
482
+ 4,
483
+ 1,
484
+ 11183,
485
+ 32,
486
+ 201305,
487
+ 8356,
488
+ 4,
489
+ 16e3,
490
+ 100,
491
+ 16e3,
492
+ 100,
493
+ 16e3,
494
+ 100,
495
+ 16e3,
496
+ 100,
497
+ 16e3,
498
+ 100,
499
+ 16e3,
500
+ 100,
501
+ 100,
502
+ 100,
503
+ 16e3,
504
+ 100,
505
+ 94375,
506
+ 32,
507
+ 132994,
508
+ 32,
509
+ 61462,
510
+ 4,
511
+ 72010,
512
+ 178,
513
+ 0,
514
+ 1,
515
+ 22151,
516
+ 32,
517
+ 91189,
518
+ 769,
519
+ 4,
520
+ 2,
521
+ 85848,
522
+ 228465,
523
+ 122,
524
+ 0,
525
+ 1,
526
+ 1,
527
+ 1e3,
528
+ 42921,
529
+ 4,
530
+ 2,
531
+ 24548,
532
+ 29498,
533
+ 38,
534
+ 1,
535
+ 898148,
536
+ 27279,
537
+ 1,
538
+ 51775,
539
+ 558,
540
+ 1,
541
+ 39184,
542
+ 1e3,
543
+ 60594,
544
+ 1,
545
+ 141895,
546
+ 32,
547
+ 83150,
548
+ 32,
549
+ 15299,
550
+ 32,
551
+ 76049,
552
+ 1,
553
+ 13169,
554
+ 4,
555
+ 22100,
556
+ 10,
557
+ 28999,
558
+ 74,
559
+ 1,
560
+ 28999,
561
+ 74,
562
+ 1,
563
+ 43285,
564
+ 552,
565
+ 1,
566
+ 44749,
567
+ 541,
568
+ 1,
569
+ 33852,
570
+ 32,
571
+ 68246,
572
+ 32,
573
+ 72362,
574
+ 32,
575
+ 7243,
576
+ 32,
577
+ 7391,
578
+ 32,
579
+ 11546,
580
+ 32,
581
+ 85848,
582
+ 228465,
583
+ 122,
584
+ 0,
585
+ 1,
586
+ 1,
587
+ 90434,
588
+ 519,
589
+ 0,
590
+ 1,
591
+ 74433,
592
+ 32,
593
+ 85848,
594
+ 228465,
595
+ 122,
596
+ 0,
597
+ 1,
598
+ 1,
599
+ 85848,
600
+ 228465,
601
+ 122,
602
+ 0,
603
+ 1,
604
+ 1,
605
+ 270652,
606
+ 22588,
607
+ 4,
608
+ 1457325,
609
+ 64566,
610
+ 4,
611
+ 20467,
612
+ 1,
613
+ 4,
614
+ 0,
615
+ 141992,
616
+ 32,
617
+ 100788,
618
+ 420,
619
+ 1,
620
+ 1,
621
+ 81663,
622
+ 32,
623
+ 59498,
624
+ 32,
625
+ 20142,
626
+ 32,
627
+ 24588,
628
+ 32,
629
+ 20744,
630
+ 32,
631
+ 25933,
632
+ 32,
633
+ 24623,
634
+ 32,
635
+ 53384111,
636
+ 14333,
637
+ 10
638
+ ];
639
+ var DEFAULT_V2_COST_MODEL_LIST = [
640
+ 100788,
641
+ 420,
642
+ 1,
643
+ 1,
644
+ 1e3,
645
+ 173,
646
+ 0,
647
+ 1,
648
+ 1e3,
649
+ 59957,
650
+ 4,
651
+ 1,
652
+ 11183,
653
+ 32,
654
+ 201305,
655
+ 8356,
656
+ 4,
657
+ 16e3,
658
+ 100,
659
+ 16e3,
660
+ 100,
661
+ 16e3,
662
+ 100,
663
+ 16e3,
664
+ 100,
665
+ 16e3,
666
+ 100,
667
+ 16e3,
668
+ 100,
669
+ 100,
670
+ 100,
671
+ 16e3,
672
+ 100,
673
+ 94375,
674
+ 32,
675
+ 132994,
676
+ 32,
677
+ 61462,
678
+ 4,
679
+ 72010,
680
+ 178,
681
+ 0,
682
+ 1,
683
+ 22151,
684
+ 32,
685
+ 91189,
686
+ 769,
687
+ 4,
688
+ 2,
689
+ 85848,
690
+ 228465,
691
+ 122,
692
+ 0,
693
+ 1,
694
+ 1,
695
+ 1e3,
696
+ 42921,
697
+ 4,
698
+ 2,
699
+ 24548,
700
+ 29498,
701
+ 38,
702
+ 1,
703
+ 898148,
704
+ 27279,
705
+ 1,
706
+ 51775,
707
+ 558,
708
+ 1,
709
+ 39184,
710
+ 1e3,
711
+ 60594,
712
+ 1,
713
+ 141895,
714
+ 32,
715
+ 83150,
716
+ 32,
717
+ 15299,
718
+ 32,
719
+ 76049,
720
+ 1,
721
+ 13169,
722
+ 4,
723
+ 22100,
724
+ 10,
725
+ 28999,
726
+ 74,
727
+ 1,
728
+ 28999,
729
+ 74,
730
+ 1,
731
+ 43285,
732
+ 552,
733
+ 1,
734
+ 44749,
735
+ 541,
736
+ 1,
737
+ 33852,
738
+ 32,
739
+ 68246,
740
+ 32,
741
+ 72362,
742
+ 32,
743
+ 7243,
744
+ 32,
745
+ 7391,
746
+ 32,
747
+ 11546,
748
+ 32,
749
+ 85848,
750
+ 228465,
751
+ 122,
752
+ 0,
753
+ 1,
754
+ 1,
755
+ 90434,
756
+ 519,
757
+ 0,
758
+ 1,
759
+ 74433,
760
+ 32,
761
+ 85848,
762
+ 228465,
763
+ 122,
764
+ 0,
765
+ 1,
766
+ 1,
767
+ 85848,
768
+ 228465,
769
+ 122,
770
+ 0,
771
+ 1,
772
+ 1,
773
+ 955506,
774
+ 213312,
775
+ 0,
776
+ 2,
777
+ 270652,
778
+ 22588,
779
+ 4,
780
+ 1457325,
781
+ 64566,
782
+ 4,
783
+ 20467,
784
+ 1,
785
+ 4,
786
+ 0,
787
+ 141992,
788
+ 32,
789
+ 100788,
790
+ 420,
791
+ 1,
792
+ 1,
793
+ 81663,
794
+ 32,
795
+ 59498,
796
+ 32,
797
+ 20142,
798
+ 32,
799
+ 24588,
800
+ 32,
801
+ 20744,
802
+ 32,
803
+ 25933,
804
+ 32,
805
+ 24623,
806
+ 32,
807
+ 43053543,
808
+ 10,
809
+ 53384111,
810
+ 14333,
811
+ 10,
812
+ 43574283,
813
+ 26308,
814
+ 10
815
+ ];
816
+ var DEFAULT_V3_COST_MODEL_LIST = [
817
+ 100788,
818
+ 420,
819
+ 1,
820
+ 1,
821
+ 1e3,
822
+ 173,
823
+ 0,
824
+ 1,
825
+ 1e3,
826
+ 59957,
827
+ 4,
828
+ 1,
829
+ 11183,
830
+ 32,
831
+ 201305,
832
+ 8356,
833
+ 4,
834
+ 16e3,
835
+ 100,
836
+ 16e3,
837
+ 100,
838
+ 16e3,
839
+ 100,
840
+ 16e3,
841
+ 100,
842
+ 16e3,
843
+ 100,
844
+ 16e3,
845
+ 100,
846
+ 100,
847
+ 100,
848
+ 16e3,
849
+ 100,
850
+ 94375,
851
+ 32,
852
+ 132994,
853
+ 32,
854
+ 61462,
855
+ 4,
856
+ 72010,
857
+ 178,
858
+ 0,
859
+ 1,
860
+ 22151,
861
+ 32,
862
+ 91189,
863
+ 769,
864
+ 4,
865
+ 2,
866
+ 85848,
867
+ 123203,
868
+ 7305,
869
+ -900,
870
+ 1716,
871
+ 549,
872
+ 57,
873
+ 85848,
874
+ 0,
875
+ 1,
876
+ 1,
877
+ 1e3,
878
+ 42921,
879
+ 4,
880
+ 2,
881
+ 24548,
882
+ 29498,
883
+ 38,
884
+ 1,
885
+ 898148,
886
+ 27279,
887
+ 1,
888
+ 51775,
889
+ 558,
890
+ 1,
891
+ 39184,
892
+ 1e3,
893
+ 60594,
894
+ 1,
895
+ 141895,
896
+ 32,
897
+ 83150,
898
+ 32,
899
+ 15299,
900
+ 32,
901
+ 76049,
902
+ 1,
903
+ 13169,
904
+ 4,
905
+ 22100,
906
+ 10,
907
+ 28999,
908
+ 74,
909
+ 1,
910
+ 28999,
911
+ 74,
912
+ 1,
913
+ 43285,
914
+ 552,
915
+ 1,
916
+ 44749,
917
+ 541,
918
+ 1,
919
+ 33852,
920
+ 32,
921
+ 68246,
922
+ 32,
923
+ 72362,
924
+ 32,
925
+ 7243,
926
+ 32,
927
+ 7391,
928
+ 32,
929
+ 11546,
930
+ 32,
931
+ 85848,
932
+ 123203,
933
+ 7305,
934
+ -900,
935
+ 1716,
936
+ 549,
937
+ 57,
938
+ 85848,
939
+ 0,
940
+ 1,
941
+ 90434,
942
+ 519,
943
+ 0,
944
+ 1,
945
+ 74433,
946
+ 32,
947
+ 85848,
948
+ 123203,
949
+ 7305,
950
+ -900,
951
+ 1716,
952
+ 549,
953
+ 57,
954
+ 85848,
955
+ 0,
956
+ 1,
957
+ 1,
958
+ 85848,
959
+ 123203,
960
+ 7305,
961
+ -900,
962
+ 1716,
963
+ 549,
964
+ 57,
965
+ 85848,
966
+ 0,
967
+ 1,
968
+ 955506,
969
+ 213312,
970
+ 0,
971
+ 2,
972
+ 270652,
973
+ 22588,
974
+ 4,
975
+ 1457325,
976
+ 64566,
977
+ 4,
978
+ 20467,
979
+ 1,
980
+ 4,
981
+ 0,
982
+ 141992,
983
+ 32,
984
+ 100788,
985
+ 420,
986
+ 1,
987
+ 1,
988
+ 81663,
989
+ 32,
990
+ 59498,
991
+ 32,
992
+ 20142,
993
+ 32,
994
+ 24588,
995
+ 32,
996
+ 20744,
997
+ 32,
998
+ 25933,
999
+ 32,
1000
+ 24623,
1001
+ 32,
1002
+ 43053543,
1003
+ 10,
1004
+ 53384111,
1005
+ 14333,
1006
+ 10,
1007
+ 43574283,
1008
+ 26308,
1009
+ 10,
1010
+ 16e3,
1011
+ 100,
1012
+ 16e3,
1013
+ 100,
1014
+ 962335,
1015
+ 18,
1016
+ 2780678,
1017
+ 6,
1018
+ 442008,
1019
+ 1,
1020
+ 52538055,
1021
+ 3756,
1022
+ 18,
1023
+ 267929,
1024
+ 18,
1025
+ 76433006,
1026
+ 8868,
1027
+ 18,
1028
+ 52948122,
1029
+ 18,
1030
+ 1995836,
1031
+ 36,
1032
+ 3227919,
1033
+ 12,
1034
+ 901022,
1035
+ 1,
1036
+ 166917843,
1037
+ 4307,
1038
+ 36,
1039
+ 284546,
1040
+ 36,
1041
+ 158221314,
1042
+ 26549,
1043
+ 36,
1044
+ 74698472,
1045
+ 36,
1046
+ 333849714,
1047
+ 1,
1048
+ 254006273,
1049
+ 72,
1050
+ 2174038,
1051
+ 72,
1052
+ 2261318,
1053
+ 64571,
1054
+ 4,
1055
+ 207616,
1056
+ 8310,
1057
+ 4,
1058
+ 1293828,
1059
+ 28716,
1060
+ 63,
1061
+ 0,
1062
+ 1,
1063
+ 1006041,
1064
+ 43623,
1065
+ 251,
1066
+ 0,
1067
+ 1,
1068
+ 100181,
1069
+ 726,
1070
+ 719,
1071
+ 0,
1072
+ 1,
1073
+ 100181,
1074
+ 726,
1075
+ 719,
1076
+ 0,
1077
+ 1,
1078
+ 100181,
1079
+ 726,
1080
+ 719,
1081
+ 0,
1082
+ 1,
1083
+ 107878,
1084
+ 680,
1085
+ 0,
1086
+ 1,
1087
+ 95336,
1088
+ 1,
1089
+ 281145,
1090
+ 18848,
1091
+ 0,
1092
+ 1,
1093
+ 180194,
1094
+ 159,
1095
+ 1,
1096
+ 1,
1097
+ 158519,
1098
+ 8942,
1099
+ 0,
1100
+ 1,
1101
+ 159378,
1102
+ 8813,
1103
+ 0,
1104
+ 1,
1105
+ 107490,
1106
+ 3298,
1107
+ 1,
1108
+ 106057,
1109
+ 655,
1110
+ 1,
1111
+ 1964219,
1112
+ 24520,
1113
+ 3
1114
+ ];
1115
+
1116
+ // src/constants/placeholder.ts
1117
+ var import_cardano_wasm6 = require("@hydrawallet-sdk/cardano-wasm");
1118
+ var PLACEHOLDER_ADDRESS = {
1119
+ [import_cardano_wasm6.CardanoWASM.NetworkInfo.mainnet().network_id()]: "addr1qrsx72hrv8ens90hwkezg7ysyhwvcjmyzdveyf88ppq7a0lwu7gv0wuuf9lhzm7wclvj5ntgcfa53j0rqxmu237x20xspeqa7n",
1120
+ [import_cardano_wasm6.CardanoWASM.NetworkInfo.testnet_preprod().network_id()]: "addr_test1qrsx72hrv8ens90hwkezg7ysyhwvcjmyzdveyf88ppq7a0lwu7gv0wuuf9lhzm7wclvj5ntgcfa53j0rqxmu237x20xsne56q3",
1121
+ [import_cardano_wasm6.CardanoWASM.NetworkInfo.testnet_preview().network_id()]: "addr_test1qruhen60uwzpwnnr7gjs50z2v8u9zyfw6zunet4k42zrpr54mrlv55f93rs6j48wt29w90hlxt4rvpvshe55k5r9mpvqjv2wt4"
1122
+ };
1123
+
1124
+ // src/constants/protocol-parameters.ts
1125
+ var DEFAULT_PROTOCOL_PARAMETERS = {
1126
+ epoch: 0,
1127
+ coinsPerUtxoSize: 4310,
1128
+ priceMem: 0.0577,
1129
+ priceStep: 721e-7,
1130
+ minFeeA: 44,
1131
+ minFeeB: 155381,
1132
+ keyDeposit: 2e6,
1133
+ maxTxSize: 16384,
1134
+ maxValSize: 5e3,
1135
+ poolDeposit: 5e8,
1136
+ maxCollateralInputs: 3,
1137
+ decentralisation: 0,
1138
+ maxBlockSize: 98304,
1139
+ collateralPercent: 150,
1140
+ maxBlockHeaderSize: 1100,
1141
+ minPoolCost: "340000000",
1142
+ maxTxExMem: "16000000",
1143
+ maxTxExSteps: "10000000000",
1144
+ maxBlockExMem: "80000000",
1145
+ maxBlockExSteps: "40000000000",
1146
+ minFeeRefScriptCostPerByte: 15
1147
+ };
1148
+ var DREP_DEPOSIT = "500000000";
1149
+ var resolveTxFees = (txSize, minFeeA = DEFAULT_PROTOCOL_PARAMETERS.minFeeA, minFeeB = DEFAULT_PROTOCOL_PARAMETERS.minFeeB) => {
1150
+ const fees = BigInt(minFeeA) * BigInt(txSize) + BigInt(minFeeB);
1151
+ return fees.toString();
1152
+ };
1153
+
1154
+ // src/constants/index.ts
1155
+ var LANGUAGE_VERSIONS = {
1156
+ V1: "V1",
1157
+ V2: "V2",
1158
+ V3: "V3"
1159
+ };
1160
+ var HARDENED_KEY_START = 2147483648;
1161
+
1162
+ // src/types/cardano/asset.ts
1163
+ var mergeAssets = (assets) => {
1164
+ const merged = [];
1165
+ assets.forEach((asset) => {
1166
+ const existing = merged.find((a) => a.unit === asset.unit);
1167
+ if (existing) {
1168
+ existing.quantity = (BigInt(existing.quantity) + BigInt(asset.quantity)).toString();
1169
+ } else {
1170
+ merged.push(asset);
1171
+ }
1172
+ });
1173
+ return merged;
1174
+ };
1175
+
1176
+ // src/types/cardano/asset-metadata.ts
1177
+ var royaltiesStandardKeys = ["rate", "address"];
1178
+ var metadataStandardKeys = [
1179
+ "name",
1180
+ "image",
1181
+ "mediaType",
1182
+ "description",
1183
+ "instagram",
1184
+ "twitter",
1185
+ "discord",
1186
+ "website"
1187
+ ];
1188
+ var fungibleAssetKeys = ["ticker", "decimals"];
1189
+ var metadataToCip68 = (metadata) => {
1190
+ switch (typeof metadata) {
1191
+ case "object":
1192
+ if (metadata instanceof Array) {
1193
+ return metadata.map((item) => metadataToCip68(item));
1194
+ }
1195
+ const metadataMap = /* @__PURE__ */ new Map();
1196
+ const keys = Object.keys(metadata);
1197
+ keys.forEach((key) => {
1198
+ metadataMap.set(key, metadataToCip68(metadata[key]));
1199
+ });
1200
+ return {
1201
+ alternative: 0,
1202
+ fields: [metadataMap, 1]
1203
+ };
1204
+ default:
1205
+ return metadata;
1206
+ }
1207
+ };
1208
+
1209
+ // src/types/protocol.ts
1210
+ var castProtocol = (data) => {
1211
+ const result = {};
1212
+ for (const rawKey in DEFAULT_PROTOCOL_PARAMETERS) {
1213
+ const key = rawKey;
1214
+ const defaultValue = DEFAULT_PROTOCOL_PARAMETERS[key];
1215
+ const value = data[key];
1216
+ if (typeof defaultValue === "number") {
1217
+ result[key] = !value && value !== 0 ? defaultValue : Number(value);
1218
+ } else if (typeof defaultValue === "string") {
1219
+ result[key] = !value && value !== "" ? defaultValue : value.toString();
1220
+ }
1221
+ }
1222
+ return result;
1223
+ };
1224
+
1225
+ // src/utils/cardano-wasm/serializer.ts
1226
+ var serializeAssetUnit = (policyId, assetName) => {
1227
+ return policyId + assetName;
1228
+ };
1229
+
1230
+ // src/utils/cardano-wasm/converter.ts
1231
+ var import_cardano_wasm7 = require("@hydrawallet-sdk/cardano-wasm");
1232
+ var convertUTxOToUTxOObject = (utxos) => {
1233
+ return utxos.reduce((acc, cur) => {
1234
+ acc[`${cur.input.txHash}#${cur.input.outputIndex}`] = {
1235
+ address: cur.output.address,
1236
+ datum: cur.output.datum ? cur.output.datum.to_hex() : null,
1237
+ datumhash: cur.output.datumHash || null,
1238
+ inlineDatum: cur.output.inlineDatum ? cur.output.inlineDatum.to_json(import_cardano_wasm7.CardanoWASM.PlutusDatumSchema.DetailedSchema) : null,
1239
+ inlineDatumRaw: cur.output.inlineDatum ? cur.output.inlineDatum.to_hex() : null,
1240
+ // TODO: update it if using scriptRef
1241
+ referenceScript: null,
1242
+ value: cur.output.amount.reduce(
1243
+ (acc2, cur2) => {
1244
+ if (cur2.unit === "lovelace") {
1245
+ acc2.lovelace = Number(cur2.quantity);
1246
+ } else {
1247
+ const { policyId, assetName } = deserializeAssetUnit(cur2.unit);
1248
+ if (!acc2[policyId]) {
1249
+ acc2[policyId] = {};
1250
+ }
1251
+ acc2[policyId][assetName] = Number(cur2.quantity);
1252
+ }
1253
+ return acc2;
1254
+ },
1255
+ {}
1256
+ )
1257
+ };
1258
+ return acc;
1259
+ }, {});
1260
+ };
1261
+ var convertUTxOObjectToUTxO = (utxoObject) => {
1262
+ return Object.keys(utxoObject).map((txHash) => {
1263
+ const [txId, txIndex] = txHash.split("#");
1264
+ const outputIndex = Number(txIndex);
1265
+ const utxo = utxoObject[txHash];
1266
+ const amount = [{ unit: "lovelace", quantity: String(utxo.value.lovelace) }];
1267
+ for (const [policyId, assets] of Object.entries(utxo.value)) {
1268
+ for (const [assetName, quantity] of Object.entries(assets)) {
1269
+ amount.push({
1270
+ unit: `${policyId}${assetName}`,
1271
+ quantity: String(quantity)
1272
+ });
1273
+ }
1274
+ }
1275
+ return {
1276
+ input: {
1277
+ outputIndex,
1278
+ txHash: txId
1279
+ },
1280
+ output: {
1281
+ address: utxo.address,
1282
+ amount,
1283
+ datum: void 0,
1284
+ datumHash: utxo.datumhash,
1285
+ inlineDatum: void 0,
1286
+ scriptRef: void 0,
1287
+ scriptHash: void 0
1288
+ }
1289
+ };
1290
+ });
1291
+ };
1292
+ // Annotate the CommonJS export names for ESM import in node:
1293
+ 0 && (module.exports = {
1294
+ AppWallet,
1295
+ ChainDerivation,
1296
+ CoinTypes,
1297
+ DEFAULT_PROTOCOL_PARAMETERS,
1298
+ DEFAULT_V1_COST_MODEL_LIST,
1299
+ DEFAULT_V2_COST_MODEL_LIST,
1300
+ DEFAULT_V3_COST_MODEL_LIST,
1301
+ DREP_DEPOSIT,
1302
+ EmbeddedWallet,
1303
+ HARDENED_KEY_START,
1304
+ LANGUAGE_VERSIONS,
1305
+ NETWORK_ID,
1306
+ NETWORK_MAGIC,
1307
+ PLACEHOLDER_ADDRESS,
1308
+ Purpose,
1309
+ WalletStaticMethods,
1310
+ buildBaseAddress,
1311
+ buildDRepID,
1312
+ buildEnterpriseAddress,
1313
+ buildKeys,
1314
+ buildRewardAddress,
1315
+ bytesToHex,
1316
+ castProtocol,
1317
+ clampScalar,
1318
+ convertUTxOObjectToUTxO,
1319
+ convertUTxOToUTxOObject,
1320
+ deserializeAssetUnit,
1321
+ deserializeTx,
1322
+ fromUTF8,
1323
+ fungibleAssetKeys,
1324
+ hexToBytes,
1325
+ hexToString,
1326
+ mergeAssets,
1327
+ metadataStandardKeys,
1328
+ metadataToCip68,
1329
+ resolveTxBodyHash,
1330
+ resolveTxFees,
1331
+ resolveTxHash,
1332
+ royaltiesStandardKeys,
1333
+ serializeAssetUnit,
1334
+ stringToHex,
1335
+ stripExtendedKey,
1336
+ toBytes,
1337
+ toUTF8
1338
+ });
1339
+ //# sourceMappingURL=index.js.map