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