@meshsdk/core-csl 1.9.0-beta.0 → 1.9.0-beta.10
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/index.cjs +75 -97
- package/dist/index.d.cts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +74 -97
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -72,6 +72,7 @@ __export(index_exports, {
|
|
|
72
72
|
fromUTF8: () => fromUTF8,
|
|
73
73
|
getDRepIds: () => getDRepIds,
|
|
74
74
|
getTransactionInputs: () => getTransactionInputs,
|
|
75
|
+
getTransactionOutputs: () => getTransactionOutputs,
|
|
75
76
|
getV2ScriptHash: () => getV2ScriptHash,
|
|
76
77
|
keyHashToRewardAddress: () => keyHashToRewardAddress,
|
|
77
78
|
meshTxBuilderBodyToObj: () => meshTxBuilderBodyToObj,
|
|
@@ -152,10 +153,10 @@ var POLICY_ID_LENGTH = 56;
|
|
|
152
153
|
|
|
153
154
|
// src/deser/converter.ts
|
|
154
155
|
var import_json_bigint = __toESM(require("json-bigint"), 1);
|
|
155
|
-
var toAddress = (
|
|
156
|
-
var toBaseAddress = (
|
|
157
|
-
var toEnterpriseAddress = (
|
|
158
|
-
var toRewardAddress = (
|
|
156
|
+
var toAddress = (bech32) => csl.Address.from_bech32(bech32);
|
|
157
|
+
var toBaseAddress = (bech32) => csl.BaseAddress.from_address(toAddress(bech32));
|
|
158
|
+
var toEnterpriseAddress = (bech32) => csl.EnterpriseAddress.from_address(toAddress(bech32));
|
|
159
|
+
var toRewardAddress = (bech32) => csl.RewardAddress.from_address(toAddress(bech32));
|
|
159
160
|
var fromBytes = (bytes) => Buffer.from(bytes).toString("hex");
|
|
160
161
|
var toBytes = (hex) => {
|
|
161
162
|
if (hex.length % 2 === 0 && /^[0-9A-F]*$/i.test(hex))
|
|
@@ -294,14 +295,14 @@ var deserializeValue = (value) => csl.Value.from_bytes(toBytes(value));
|
|
|
294
295
|
|
|
295
296
|
// src/deser/resolver.ts
|
|
296
297
|
var import_common = require("@meshsdk/common");
|
|
297
|
-
var resolveStakeKeyHash = (
|
|
298
|
+
var resolveStakeKeyHash = (bech32) => {
|
|
298
299
|
try {
|
|
299
300
|
const stakeKeyHash = [
|
|
300
|
-
toBaseAddress(
|
|
301
|
-
toRewardAddress(
|
|
301
|
+
toBaseAddress(bech32)?.stake_cred().to_keyhash(),
|
|
302
|
+
toRewardAddress(bech32)?.payment_cred().to_keyhash()
|
|
302
303
|
].find((kh) => kh !== void 0);
|
|
303
304
|
if (stakeKeyHash !== void 0) return stakeKeyHash.to_hex();
|
|
304
|
-
throw new Error(`Couldn't resolve stake key hash from address: ${
|
|
305
|
+
throw new Error(`Couldn't resolve stake key hash from address: ${bech32}`);
|
|
305
306
|
} catch (error) {
|
|
306
307
|
throw new Error(`An error occurred during resolveStakeKeyHash: ${error}.`);
|
|
307
308
|
}
|
|
@@ -341,9 +342,9 @@ var resolveNativeScriptHash = (script) => {
|
|
|
341
342
|
var resolveScriptHashDRepId = (scriptHash) => {
|
|
342
343
|
return csl.DRep.new_script_hash(
|
|
343
344
|
csl.ScriptHash.from_hex(scriptHash)
|
|
344
|
-
).to_bech32();
|
|
345
|
+
).to_bech32(true);
|
|
345
346
|
};
|
|
346
|
-
var resolveRewardAddress = (
|
|
347
|
+
var resolveRewardAddress = (bech32) => {
|
|
347
348
|
const buildRewardAddress = (networkId, stakeKeyHash) => {
|
|
348
349
|
return csl.RewardAddress.new(
|
|
349
350
|
networkId,
|
|
@@ -351,12 +352,12 @@ var resolveRewardAddress = (bech322) => {
|
|
|
351
352
|
);
|
|
352
353
|
};
|
|
353
354
|
try {
|
|
354
|
-
const address = toAddress(
|
|
355
|
-
const baseAddress = toBaseAddress(
|
|
355
|
+
const address = toAddress(bech32);
|
|
356
|
+
const baseAddress = toBaseAddress(bech32);
|
|
356
357
|
const stakeKeyHash = baseAddress?.stake_cred().to_keyhash();
|
|
357
358
|
if (stakeKeyHash !== void 0)
|
|
358
359
|
return buildRewardAddress(address.network_id(), stakeKeyHash).to_address().to_bech32();
|
|
359
|
-
throw new Error(`Couldn't resolve reward address from address: ${
|
|
360
|
+
throw new Error(`Couldn't resolve reward address from address: ${bech32}`);
|
|
360
361
|
} catch (error) {
|
|
361
362
|
throw new Error(`An error occurred during resolveRewardAddress: ${error}.`);
|
|
362
363
|
}
|
|
@@ -375,8 +376,8 @@ var serializePoolId = (hash) => {
|
|
|
375
376
|
var resolveScriptRef = (script) => {
|
|
376
377
|
return toScriptRef(script).to_hex();
|
|
377
378
|
};
|
|
378
|
-
var resolveEd25519KeyHash = (
|
|
379
|
-
return csl.Ed25519KeyHash.from_bech32(
|
|
379
|
+
var resolveEd25519KeyHash = (bech32) => {
|
|
380
|
+
return csl.Ed25519KeyHash.from_bech32(bech32).to_hex();
|
|
380
381
|
};
|
|
381
382
|
|
|
382
383
|
// src/utils/scripts.ts
|
|
@@ -401,14 +402,14 @@ var serialzeAddress = (deserializedAddress, networkId = 0) => {
|
|
|
401
402
|
const addressObj = isPaymentScript ? (0, import_common2.scriptAddress)(paymentHash, stakeHash, isStakeScript) : (0, import_common2.pubKeyAddress)(paymentHash, stakeHash, isStakeScript);
|
|
402
403
|
return serializeAddressObj(addressObj, networkId);
|
|
403
404
|
};
|
|
404
|
-
var addrBech32ToPlutusDataHex = (
|
|
405
|
-
const hexAddress = csl.Address.from_bech32(
|
|
405
|
+
var addrBech32ToPlutusDataHex = (bech32) => {
|
|
406
|
+
const hexAddress = csl.Address.from_bech32(bech32).to_hex();
|
|
406
407
|
const cslAddress = csl.Address.from_hex(hexAddress);
|
|
407
408
|
const hex = csl.PlutusData.from_address(cslAddress).to_hex();
|
|
408
409
|
return hex;
|
|
409
410
|
};
|
|
410
|
-
var addrBech32ToPlutusDataObj = (
|
|
411
|
-
const hexAddress = csl.Address.from_bech32(
|
|
411
|
+
var addrBech32ToPlutusDataObj = (bech32) => {
|
|
412
|
+
const hexAddress = csl.Address.from_bech32(bech32).to_hex();
|
|
412
413
|
const cslAddress = csl.Address.from_hex(hexAddress);
|
|
413
414
|
const json = JSON.parse(csl.PlutusData.from_address(cslAddress).to_json(1));
|
|
414
415
|
return json;
|
|
@@ -507,6 +508,9 @@ var keyHashToRewardAddress = (keyHashHex, network = 1) => {
|
|
|
507
508
|
return rewardAddress;
|
|
508
509
|
};
|
|
509
510
|
|
|
511
|
+
// src/utils/transaction.ts
|
|
512
|
+
var import_sidan_csl_rs_nodejs = require("@sidan-lab/sidan-csl-rs-nodejs");
|
|
513
|
+
|
|
510
514
|
// src/wasm.ts
|
|
511
515
|
var parseWasmResult = (result) => {
|
|
512
516
|
if (result.get_status() !== "success") {
|
|
@@ -534,13 +538,16 @@ var signTransaction = (txHex, signingKeys) => {
|
|
|
534
538
|
const result = csl.js_sign_transaction(txHex, cslSigningKeys);
|
|
535
539
|
return parseWasmResult(result);
|
|
536
540
|
};
|
|
537
|
-
var evaluateTransaction = (txHex, resolvedUtxos, network, slotConfig) => {
|
|
541
|
+
var evaluateTransaction = (txHex, resolvedUtxos, chainedTxs, network, slotConfig) => {
|
|
538
542
|
const additionalTxs = csl.JsVecString.new();
|
|
543
|
+
for (const tx of chainedTxs) {
|
|
544
|
+
additionalTxs.add(tx);
|
|
545
|
+
}
|
|
539
546
|
const mappedUtxos = csl.JsVecString.new();
|
|
540
547
|
for (const utxo of resolvedUtxos) {
|
|
541
548
|
mappedUtxos.add(JSON.stringify(utxo));
|
|
542
549
|
}
|
|
543
|
-
const result = csl.
|
|
550
|
+
const result = csl.js_evaluate_tx_scripts(
|
|
544
551
|
txHex,
|
|
545
552
|
mappedUtxos,
|
|
546
553
|
additionalTxs,
|
|
@@ -605,7 +612,7 @@ var getTransactionInputs = (txHex) => {
|
|
|
605
612
|
const input = cslInputs.get(i);
|
|
606
613
|
inputs.push({
|
|
607
614
|
txHash: input.transaction_id().to_hex(),
|
|
608
|
-
|
|
615
|
+
outputIndex: input.index()
|
|
609
616
|
});
|
|
610
617
|
}
|
|
611
618
|
const cslCollaterals = body.collateral();
|
|
@@ -614,7 +621,7 @@ var getTransactionInputs = (txHex) => {
|
|
|
614
621
|
const collateral = cslCollaterals.get(i);
|
|
615
622
|
inputs.push({
|
|
616
623
|
txHash: collateral.transaction_id().to_hex(),
|
|
617
|
-
|
|
624
|
+
outputIndex: collateral.index()
|
|
618
625
|
});
|
|
619
626
|
}
|
|
620
627
|
}
|
|
@@ -624,12 +631,17 @@ var getTransactionInputs = (txHex) => {
|
|
|
624
631
|
const refInput = cslRefInputs.get(i);
|
|
625
632
|
inputs.push({
|
|
626
633
|
txHash: refInput.transaction_id().to_hex(),
|
|
627
|
-
|
|
634
|
+
outputIndex: refInput.index()
|
|
628
635
|
});
|
|
629
636
|
}
|
|
630
637
|
}
|
|
631
638
|
return inputs;
|
|
632
639
|
};
|
|
640
|
+
var getTransactionOutputs = (txHex) => {
|
|
641
|
+
const outputs = (0, import_sidan_csl_rs_nodejs.js_get_tx_outs_utxo)(txHex).get_data();
|
|
642
|
+
const utxos = JSON.parse(outputs);
|
|
643
|
+
return utxos;
|
|
644
|
+
};
|
|
633
645
|
|
|
634
646
|
// src/utils/aiken.ts
|
|
635
647
|
var applyParamsToScript = (rawScript, params, type = "Mesh") => {
|
|
@@ -669,63 +681,12 @@ var applyCborEncoding = (rawScript) => {
|
|
|
669
681
|
};
|
|
670
682
|
|
|
671
683
|
// src/utils/drep.ts
|
|
672
|
-
var import_base32_encoding = __toESM(require("base32-encoding"), 1);
|
|
673
|
-
var import_bech32 = require("bech32");
|
|
674
684
|
var getDRepIds = (dRepId) => {
|
|
685
|
+
const cslDrep = csl.DRep.from_bech32(dRepId);
|
|
675
686
|
let result = {
|
|
676
|
-
cip105:
|
|
677
|
-
cip129:
|
|
687
|
+
cip105: cslDrep.to_bech32(false),
|
|
688
|
+
cip129: cslDrep.to_bech32(true)
|
|
678
689
|
};
|
|
679
|
-
if (dRepId.length === 58) {
|
|
680
|
-
result.cip129 = dRepId;
|
|
681
|
-
const { prefix, words } = import_bech32.bech32.decode(dRepId);
|
|
682
|
-
if (prefix !== "drep") {
|
|
683
|
-
throw new Error("Malformed CIP129 DRepId");
|
|
684
|
-
}
|
|
685
|
-
const bytes = import_base32_encoding.default.decode(new Uint8Array(words));
|
|
686
|
-
if (bytes[0] === 34) {
|
|
687
|
-
result.cip105 = csl.DRep.new_key_hash(
|
|
688
|
-
csl.Ed25519KeyHash.from_hex(bytes.subarray(1).toString("hex"))
|
|
689
|
-
).to_bech32();
|
|
690
|
-
} else if (bytes[0] === 35) {
|
|
691
|
-
result.cip105 = csl.DRep.new_script_hash(
|
|
692
|
-
csl.ScriptHash.from_hex(bytes.subarray(1).toString("hex"))
|
|
693
|
-
).to_bech32();
|
|
694
|
-
} else {
|
|
695
|
-
throw new Error("Malformed CIP129 DRepId");
|
|
696
|
-
}
|
|
697
|
-
} else {
|
|
698
|
-
result.cip105 = dRepId;
|
|
699
|
-
try {
|
|
700
|
-
const cslDRep = csl.DRep.from_bech32(dRepId);
|
|
701
|
-
if (cslDRep.kind() === csl.DRepKind.KeyHash) {
|
|
702
|
-
let rawBytes = cslDRep.to_key_hash()?.to_bytes();
|
|
703
|
-
if (!rawBytes) {
|
|
704
|
-
throw new Error("Malformed key hash in DRepId");
|
|
705
|
-
}
|
|
706
|
-
let rawBytesWithPrefix = new Uint8Array(rawBytes.length + 1);
|
|
707
|
-
rawBytesWithPrefix.set([34]);
|
|
708
|
-
rawBytesWithPrefix.set(rawBytes, 1);
|
|
709
|
-
let base32RawBytes = import_base32_encoding.default.encode(rawBytesWithPrefix);
|
|
710
|
-
result.cip129 = import_bech32.bech32.encode("drep", base32RawBytes);
|
|
711
|
-
} else if (cslDRep.kind() === csl.DRepKind.ScriptHash) {
|
|
712
|
-
let rawBytes = cslDRep.to_script_hash()?.to_bytes();
|
|
713
|
-
if (!rawBytes) {
|
|
714
|
-
throw new Error("Malformed script hash in DRepId");
|
|
715
|
-
}
|
|
716
|
-
let rawBytesWithPrefix = new Uint8Array(rawBytes.length + 1);
|
|
717
|
-
rawBytesWithPrefix.set([35]);
|
|
718
|
-
rawBytesWithPrefix.set(rawBytes, 1);
|
|
719
|
-
let base32RawBytes = import_base32_encoding.default.encode(rawBytesWithPrefix);
|
|
720
|
-
result.cip129 = import_bech32.bech32.encode("drep", base32RawBytes);
|
|
721
|
-
} else {
|
|
722
|
-
throw new Error("Can only calculate DRepIds for script/key DReps");
|
|
723
|
-
}
|
|
724
|
-
} catch (e) {
|
|
725
|
-
console.error(e);
|
|
726
|
-
throw new Error("Malformed DRepId");
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
690
|
return result;
|
|
730
691
|
};
|
|
731
692
|
|
|
@@ -1413,7 +1374,12 @@ var CSLSerializer = class {
|
|
|
1413
1374
|
this.protocolParams = protocolParams || import_common4.DEFAULT_PROTOCOL_PARAMETERS;
|
|
1414
1375
|
this.verbose = verbose;
|
|
1415
1376
|
}
|
|
1416
|
-
serializeTxBody(txBody, protocolParams) {
|
|
1377
|
+
serializeTxBody(txBody, protocolParams, balanced = true) {
|
|
1378
|
+
if (!balanced) {
|
|
1379
|
+
throw new Error(
|
|
1380
|
+
"Unbalanced transactions are not supported with CSL serializer"
|
|
1381
|
+
);
|
|
1382
|
+
}
|
|
1417
1383
|
const txBodyJson = import_json_bigint3.default.stringify(meshTxBuilderBodyToObj(txBody));
|
|
1418
1384
|
const params = import_json_bigint3.default.stringify(protocolParams || this.protocolParams);
|
|
1419
1385
|
if (this.verbose) {
|
|
@@ -1445,8 +1411,8 @@ var CSLSerializer = class {
|
|
|
1445
1411
|
}
|
|
1446
1412
|
deserializer = {
|
|
1447
1413
|
key: {
|
|
1448
|
-
deserializeAddress: function(
|
|
1449
|
-
return deserializeBech32Address(
|
|
1414
|
+
deserializeAddress: function(bech32) {
|
|
1415
|
+
return deserializeBech32Address(bech32);
|
|
1450
1416
|
}
|
|
1451
1417
|
},
|
|
1452
1418
|
script: {
|
|
@@ -1472,17 +1438,17 @@ var CSLSerializer = class {
|
|
|
1472
1438
|
};
|
|
1473
1439
|
resolver = {
|
|
1474
1440
|
keys: {
|
|
1475
|
-
resolveStakeKeyHash: function(
|
|
1476
|
-
return rewardAddressToKeyHash(
|
|
1441
|
+
resolveStakeKeyHash: function(bech32) {
|
|
1442
|
+
return rewardAddressToKeyHash(bech32) || deserializeBech32Address(bech32).stakeCredentialHash;
|
|
1477
1443
|
},
|
|
1478
1444
|
resolvePrivateKey: function(words) {
|
|
1479
1445
|
return resolvePrivateKey(words);
|
|
1480
1446
|
},
|
|
1481
|
-
resolveRewardAddress: function(
|
|
1482
|
-
return resolveRewardAddress(
|
|
1447
|
+
resolveRewardAddress: function(bech32) {
|
|
1448
|
+
return resolveRewardAddress(bech32);
|
|
1483
1449
|
},
|
|
1484
|
-
resolveEd25519KeyHash: function(
|
|
1485
|
-
return resolveEd25519KeyHash(
|
|
1450
|
+
resolveEd25519KeyHash: function(bech32) {
|
|
1451
|
+
return resolveEd25519KeyHash(bech32);
|
|
1486
1452
|
}
|
|
1487
1453
|
},
|
|
1488
1454
|
tx: {
|
|
@@ -1540,36 +1506,47 @@ var OfflineEvaluator = class {
|
|
|
1540
1506
|
* - budget: Memory units and CPU steps required
|
|
1541
1507
|
* @throws Error if any required UTXOs cannot be resolved or if script evaluation fails
|
|
1542
1508
|
*/
|
|
1543
|
-
async evaluateTx(tx) {
|
|
1544
|
-
const
|
|
1509
|
+
async evaluateTx(tx, additionalUtxos, additionalTxs) {
|
|
1510
|
+
const foundUtxos = /* @__PURE__ */ new Set();
|
|
1511
|
+
for (const utxo of additionalUtxos) {
|
|
1512
|
+
foundUtxos.add(`${utxo.input.txHash}:${utxo.input.outputIndex}`);
|
|
1513
|
+
}
|
|
1514
|
+
for (const tx2 of additionalTxs) {
|
|
1515
|
+
const outputs = getTransactionOutputs(tx2);
|
|
1516
|
+
for (const output of outputs) {
|
|
1517
|
+
foundUtxos.add(`${output.input.txHash}:${output.input.outputIndex}`);
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
const inputsToResolve = getTransactionInputs(tx).filter(
|
|
1521
|
+
(input) => !foundUtxos.has(`${input.txHash}:${input.outputIndex}`)
|
|
1522
|
+
);
|
|
1545
1523
|
const txHashesSet = new Set(inputsToResolve.map((input) => input.txHash));
|
|
1546
|
-
const resolvedUTXOs = [];
|
|
1547
1524
|
for (const txHash of txHashesSet) {
|
|
1548
1525
|
const utxos = await this.fetcher.fetchUTxOs(txHash);
|
|
1549
1526
|
for (const utxo of utxos) {
|
|
1550
1527
|
if (utxo) {
|
|
1551
1528
|
if (inputsToResolve.find(
|
|
1552
|
-
(input) => input.txHash === txHash && input.
|
|
1529
|
+
(input) => input.txHash === txHash && input.outputIndex === utxo.input.outputIndex
|
|
1553
1530
|
)) {
|
|
1554
|
-
|
|
1531
|
+
additionalUtxos.push(utxo);
|
|
1532
|
+
foundUtxos.add(`${utxo.input.txHash}:${utxo.input.outputIndex}`);
|
|
1555
1533
|
}
|
|
1556
1534
|
}
|
|
1557
1535
|
}
|
|
1558
1536
|
}
|
|
1559
1537
|
const missing = inputsToResolve.filter(
|
|
1560
|
-
(input) => !
|
|
1561
|
-
(utxo) => utxo.input.txHash === input.txHash && utxo.input.outputIndex === input.index
|
|
1562
|
-
)
|
|
1538
|
+
(input) => !foundUtxos.has(`${input.txHash}:${input.outputIndex}`)
|
|
1563
1539
|
);
|
|
1564
1540
|
if (missing.length > 0) {
|
|
1565
|
-
const missingList = missing.map((m) => `${m.txHash}:${m.
|
|
1541
|
+
const missingList = missing.map((m) => `${m.txHash}:${m.outputIndex}`).join(", ");
|
|
1566
1542
|
throw new Error(
|
|
1567
1543
|
`Can't resolve these UTXOs to execute plutus scripts: ${missingList}`
|
|
1568
1544
|
);
|
|
1569
1545
|
}
|
|
1570
1546
|
return evaluateTransaction(
|
|
1571
1547
|
tx,
|
|
1572
|
-
|
|
1548
|
+
additionalUtxos,
|
|
1549
|
+
additionalTxs,
|
|
1573
1550
|
this.network,
|
|
1574
1551
|
this.slotConfig
|
|
1575
1552
|
);
|
|
@@ -1619,6 +1596,7 @@ var OfflineEvaluator = class {
|
|
|
1619
1596
|
fromUTF8,
|
|
1620
1597
|
getDRepIds,
|
|
1621
1598
|
getTransactionInputs,
|
|
1599
|
+
getTransactionOutputs,
|
|
1622
1600
|
getV2ScriptHash,
|
|
1623
1601
|
keyHashToRewardAddress,
|
|
1624
1602
|
meshTxBuilderBodyToObj,
|
package/dist/index.d.cts
CHANGED
|
@@ -30,11 +30,12 @@ declare const keyHashToRewardAddress: (keyHashHex: string, network?: number) =>
|
|
|
30
30
|
|
|
31
31
|
declare const calculateTxHash: (txHex: string) => string;
|
|
32
32
|
declare const signTransaction: (txHex: string, signingKeys: string[]) => string;
|
|
33
|
-
declare const evaluateTransaction: (txHex: string, resolvedUtxos: UTxO[], network: Network, slotConfig: Omit<Omit<SlotConfig, "startEpoch">, "epochLength">) => Omit<Action, "data">[];
|
|
33
|
+
declare const evaluateTransaction: (txHex: string, resolvedUtxos: UTxO[], chainedTxs: string[], network: Network, slotConfig: Omit<Omit<SlotConfig, "startEpoch">, "epochLength">) => Omit<Action, "data">[];
|
|
34
34
|
declare const getTransactionInputs: (txHex: string) => {
|
|
35
35
|
txHash: string;
|
|
36
|
-
|
|
36
|
+
outputIndex: number;
|
|
37
37
|
}[];
|
|
38
|
+
declare const getTransactionOutputs: (txHex: string) => UTxO[];
|
|
38
39
|
|
|
39
40
|
/**
|
|
40
41
|
* Apply parameters to a given script blueprint.
|
|
@@ -66,7 +67,7 @@ declare class CSLSerializer implements IMeshTxSerializer {
|
|
|
66
67
|
protocolParams: Protocol;
|
|
67
68
|
meshTxBuilderBody: MeshTxBuilderBody;
|
|
68
69
|
constructor(protocolParams?: Protocol, verbose?: boolean);
|
|
69
|
-
serializeTxBody(txBody: MeshTxBuilderBody, protocolParams?: Protocol): string;
|
|
70
|
+
serializeTxBody(txBody: MeshTxBuilderBody, protocolParams?: Protocol, balanced?: Boolean): string;
|
|
70
71
|
addSigningKeys(txHex: string, signingKeys: string[]): string;
|
|
71
72
|
serializeData(data: BuilderData): string;
|
|
72
73
|
serializeAddress(address: Partial<DeserializedAddress>, networkId?: number): string;
|
|
@@ -264,7 +265,7 @@ declare class OfflineEvaluator implements IEvaluator {
|
|
|
264
265
|
* - budget: Memory units and CPU steps required
|
|
265
266
|
* @throws Error if any required UTXOs cannot be resolved or if script evaluation fails
|
|
266
267
|
*/
|
|
267
|
-
evaluateTx(tx: string): Promise<Omit<Action, "data">[]>;
|
|
268
|
+
evaluateTx(tx: string, additionalUtxos: UTxO[], additionalTxs: string[]): Promise<Omit<Action, "data">[]>;
|
|
268
269
|
}
|
|
269
270
|
|
|
270
|
-
export { CSLSerializer, LANGUAGE_VERSIONS, OfflineEvaluator, POLICY_ID_LENGTH, REDEEMER_TAGS, addrBech32ToPlutusDataHex, addrBech32ToPlutusDataObj, applyCborEncoding, applyParamsToScript, baseAddressToStakeAddress, baseCertToObj, builderDataToCbor, calculateTxHash, castDataToPlutusData, castRawDataToJsonString, certificateToObj, collateralTxInToObj, deserializeAddress, deserializeBech32Address, deserializeBip32PrivateKey, deserializeDataHash, deserializeEd25519KeyHash, deserializeEd25519Signature, deserializeNativeScript, deserializePlutusData, deserializePlutusScript, deserializePublicKey, deserializeScriptHash, deserializeScriptRef, deserializeTx, deserializeTxBody, deserializeTxHash, deserializeTxUnspentOutput, deserializeTxWitnessSet, deserializeValue, evaluateTransaction, fromBytes, fromLovelace, fromUTF8, getDRepIds, getTransactionInputs, getV2ScriptHash, keyHashToRewardAddress, meshTxBuilderBodyToObj, mintItemToObj, mintParametersObj, nativeMintItemToObj, outputToObj, parseDatumCbor, parseInlineDatum, plutusMintItemToObj, poolIdBech32ToHex, poolIdHexToBech32, poolMetadataToObj, poolParamsToObj, redeemerToObj, relayToObj, resolveDataHash, resolveEd25519KeyHash, resolveNativeScriptAddress, resolveNativeScriptHash, resolveNativeScriptHex, resolvePlutusScriptAddress, resolvePrivateKey, resolveRewardAddress, resolveScriptHashDRepId, resolveScriptRef, resolveStakeKeyHash, rewardAddressToKeyHash, scriptHashToBech32, scriptHashToRewardAddress, scriptSourceToObj, scriptTxInParameterToObj, serializeAddressObj, serializePlutusAddressToBech32, serializePoolId, serialzeAddress, signTransaction, simpleScriptSourceToObj, simpleScriptTxInParameterToObj, skeyToPubKeyHash, toAddress, toBaseAddress, toBytes, toEnterpriseAddress, toLovelace, toNativeScript, toPlutusData, toRewardAddress, toScriptRef, toUTF8, txInParameterToObj, txInToObj, utxoToObj, v2ScriptToBech32, withdrawalToObj };
|
|
271
|
+
export { CSLSerializer, LANGUAGE_VERSIONS, OfflineEvaluator, POLICY_ID_LENGTH, REDEEMER_TAGS, addrBech32ToPlutusDataHex, addrBech32ToPlutusDataObj, applyCborEncoding, applyParamsToScript, baseAddressToStakeAddress, baseCertToObj, builderDataToCbor, calculateTxHash, castDataToPlutusData, castRawDataToJsonString, certificateToObj, collateralTxInToObj, deserializeAddress, deserializeBech32Address, deserializeBip32PrivateKey, deserializeDataHash, deserializeEd25519KeyHash, deserializeEd25519Signature, deserializeNativeScript, deserializePlutusData, deserializePlutusScript, deserializePublicKey, deserializeScriptHash, deserializeScriptRef, deserializeTx, deserializeTxBody, deserializeTxHash, deserializeTxUnspentOutput, deserializeTxWitnessSet, deserializeValue, evaluateTransaction, fromBytes, fromLovelace, fromUTF8, getDRepIds, getTransactionInputs, getTransactionOutputs, getV2ScriptHash, keyHashToRewardAddress, meshTxBuilderBodyToObj, mintItemToObj, mintParametersObj, nativeMintItemToObj, outputToObj, parseDatumCbor, parseInlineDatum, plutusMintItemToObj, poolIdBech32ToHex, poolIdHexToBech32, poolMetadataToObj, poolParamsToObj, redeemerToObj, relayToObj, resolveDataHash, resolveEd25519KeyHash, resolveNativeScriptAddress, resolveNativeScriptHash, resolveNativeScriptHex, resolvePlutusScriptAddress, resolvePrivateKey, resolveRewardAddress, resolveScriptHashDRepId, resolveScriptRef, resolveStakeKeyHash, rewardAddressToKeyHash, scriptHashToBech32, scriptHashToRewardAddress, scriptSourceToObj, scriptTxInParameterToObj, serializeAddressObj, serializePlutusAddressToBech32, serializePoolId, serialzeAddress, signTransaction, simpleScriptSourceToObj, simpleScriptTxInParameterToObj, skeyToPubKeyHash, toAddress, toBaseAddress, toBytes, toEnterpriseAddress, toLovelace, toNativeScript, toPlutusData, toRewardAddress, toScriptRef, toUTF8, txInParameterToObj, txInToObj, utxoToObj, v2ScriptToBech32, withdrawalToObj };
|
package/dist/index.d.ts
CHANGED
|
@@ -30,11 +30,12 @@ declare const keyHashToRewardAddress: (keyHashHex: string, network?: number) =>
|
|
|
30
30
|
|
|
31
31
|
declare const calculateTxHash: (txHex: string) => string;
|
|
32
32
|
declare const signTransaction: (txHex: string, signingKeys: string[]) => string;
|
|
33
|
-
declare const evaluateTransaction: (txHex: string, resolvedUtxos: UTxO[], network: Network, slotConfig: Omit<Omit<SlotConfig, "startEpoch">, "epochLength">) => Omit<Action, "data">[];
|
|
33
|
+
declare const evaluateTransaction: (txHex: string, resolvedUtxos: UTxO[], chainedTxs: string[], network: Network, slotConfig: Omit<Omit<SlotConfig, "startEpoch">, "epochLength">) => Omit<Action, "data">[];
|
|
34
34
|
declare const getTransactionInputs: (txHex: string) => {
|
|
35
35
|
txHash: string;
|
|
36
|
-
|
|
36
|
+
outputIndex: number;
|
|
37
37
|
}[];
|
|
38
|
+
declare const getTransactionOutputs: (txHex: string) => UTxO[];
|
|
38
39
|
|
|
39
40
|
/**
|
|
40
41
|
* Apply parameters to a given script blueprint.
|
|
@@ -66,7 +67,7 @@ declare class CSLSerializer implements IMeshTxSerializer {
|
|
|
66
67
|
protocolParams: Protocol;
|
|
67
68
|
meshTxBuilderBody: MeshTxBuilderBody;
|
|
68
69
|
constructor(protocolParams?: Protocol, verbose?: boolean);
|
|
69
|
-
serializeTxBody(txBody: MeshTxBuilderBody, protocolParams?: Protocol): string;
|
|
70
|
+
serializeTxBody(txBody: MeshTxBuilderBody, protocolParams?: Protocol, balanced?: Boolean): string;
|
|
70
71
|
addSigningKeys(txHex: string, signingKeys: string[]): string;
|
|
71
72
|
serializeData(data: BuilderData): string;
|
|
72
73
|
serializeAddress(address: Partial<DeserializedAddress>, networkId?: number): string;
|
|
@@ -264,7 +265,7 @@ declare class OfflineEvaluator implements IEvaluator {
|
|
|
264
265
|
* - budget: Memory units and CPU steps required
|
|
265
266
|
* @throws Error if any required UTXOs cannot be resolved or if script evaluation fails
|
|
266
267
|
*/
|
|
267
|
-
evaluateTx(tx: string): Promise<Omit<Action, "data">[]>;
|
|
268
|
+
evaluateTx(tx: string, additionalUtxos: UTxO[], additionalTxs: string[]): Promise<Omit<Action, "data">[]>;
|
|
268
269
|
}
|
|
269
270
|
|
|
270
|
-
export { CSLSerializer, LANGUAGE_VERSIONS, OfflineEvaluator, POLICY_ID_LENGTH, REDEEMER_TAGS, addrBech32ToPlutusDataHex, addrBech32ToPlutusDataObj, applyCborEncoding, applyParamsToScript, baseAddressToStakeAddress, baseCertToObj, builderDataToCbor, calculateTxHash, castDataToPlutusData, castRawDataToJsonString, certificateToObj, collateralTxInToObj, deserializeAddress, deserializeBech32Address, deserializeBip32PrivateKey, deserializeDataHash, deserializeEd25519KeyHash, deserializeEd25519Signature, deserializeNativeScript, deserializePlutusData, deserializePlutusScript, deserializePublicKey, deserializeScriptHash, deserializeScriptRef, deserializeTx, deserializeTxBody, deserializeTxHash, deserializeTxUnspentOutput, deserializeTxWitnessSet, deserializeValue, evaluateTransaction, fromBytes, fromLovelace, fromUTF8, getDRepIds, getTransactionInputs, getV2ScriptHash, keyHashToRewardAddress, meshTxBuilderBodyToObj, mintItemToObj, mintParametersObj, nativeMintItemToObj, outputToObj, parseDatumCbor, parseInlineDatum, plutusMintItemToObj, poolIdBech32ToHex, poolIdHexToBech32, poolMetadataToObj, poolParamsToObj, redeemerToObj, relayToObj, resolveDataHash, resolveEd25519KeyHash, resolveNativeScriptAddress, resolveNativeScriptHash, resolveNativeScriptHex, resolvePlutusScriptAddress, resolvePrivateKey, resolveRewardAddress, resolveScriptHashDRepId, resolveScriptRef, resolveStakeKeyHash, rewardAddressToKeyHash, scriptHashToBech32, scriptHashToRewardAddress, scriptSourceToObj, scriptTxInParameterToObj, serializeAddressObj, serializePlutusAddressToBech32, serializePoolId, serialzeAddress, signTransaction, simpleScriptSourceToObj, simpleScriptTxInParameterToObj, skeyToPubKeyHash, toAddress, toBaseAddress, toBytes, toEnterpriseAddress, toLovelace, toNativeScript, toPlutusData, toRewardAddress, toScriptRef, toUTF8, txInParameterToObj, txInToObj, utxoToObj, v2ScriptToBech32, withdrawalToObj };
|
|
271
|
+
export { CSLSerializer, LANGUAGE_VERSIONS, OfflineEvaluator, POLICY_ID_LENGTH, REDEEMER_TAGS, addrBech32ToPlutusDataHex, addrBech32ToPlutusDataObj, applyCborEncoding, applyParamsToScript, baseAddressToStakeAddress, baseCertToObj, builderDataToCbor, calculateTxHash, castDataToPlutusData, castRawDataToJsonString, certificateToObj, collateralTxInToObj, deserializeAddress, deserializeBech32Address, deserializeBip32PrivateKey, deserializeDataHash, deserializeEd25519KeyHash, deserializeEd25519Signature, deserializeNativeScript, deserializePlutusData, deserializePlutusScript, deserializePublicKey, deserializeScriptHash, deserializeScriptRef, deserializeTx, deserializeTxBody, deserializeTxHash, deserializeTxUnspentOutput, deserializeTxWitnessSet, deserializeValue, evaluateTransaction, fromBytes, fromLovelace, fromUTF8, getDRepIds, getTransactionInputs, getTransactionOutputs, getV2ScriptHash, keyHashToRewardAddress, meshTxBuilderBodyToObj, mintItemToObj, mintParametersObj, nativeMintItemToObj, outputToObj, parseDatumCbor, parseInlineDatum, plutusMintItemToObj, poolIdBech32ToHex, poolIdHexToBech32, poolMetadataToObj, poolParamsToObj, redeemerToObj, relayToObj, resolveDataHash, resolveEd25519KeyHash, resolveNativeScriptAddress, resolveNativeScriptHash, resolveNativeScriptHex, resolvePlutusScriptAddress, resolvePrivateKey, resolveRewardAddress, resolveScriptHashDRepId, resolveScriptRef, resolveStakeKeyHash, rewardAddressToKeyHash, scriptHashToBech32, scriptHashToRewardAddress, scriptSourceToObj, scriptTxInParameterToObj, serializeAddressObj, serializePlutusAddressToBech32, serializePoolId, serialzeAddress, signTransaction, simpleScriptSourceToObj, simpleScriptTxInParameterToObj, skeyToPubKeyHash, toAddress, toBaseAddress, toBytes, toEnterpriseAddress, toLovelace, toNativeScript, toPlutusData, toRewardAddress, toScriptRef, toUTF8, txInParameterToObj, txInToObj, utxoToObj, v2ScriptToBech32, withdrawalToObj };
|
package/dist/index.js
CHANGED
|
@@ -23,10 +23,10 @@ var POLICY_ID_LENGTH = 56;
|
|
|
23
23
|
|
|
24
24
|
// src/deser/converter.ts
|
|
25
25
|
import JSONbig from "json-bigint";
|
|
26
|
-
var toAddress = (
|
|
27
|
-
var toBaseAddress = (
|
|
28
|
-
var toEnterpriseAddress = (
|
|
29
|
-
var toRewardAddress = (
|
|
26
|
+
var toAddress = (bech32) => csl.Address.from_bech32(bech32);
|
|
27
|
+
var toBaseAddress = (bech32) => csl.BaseAddress.from_address(toAddress(bech32));
|
|
28
|
+
var toEnterpriseAddress = (bech32) => csl.EnterpriseAddress.from_address(toAddress(bech32));
|
|
29
|
+
var toRewardAddress = (bech32) => csl.RewardAddress.from_address(toAddress(bech32));
|
|
30
30
|
var fromBytes = (bytes) => Buffer.from(bytes).toString("hex");
|
|
31
31
|
var toBytes = (hex) => {
|
|
32
32
|
if (hex.length % 2 === 0 && /^[0-9A-F]*$/i.test(hex))
|
|
@@ -167,14 +167,14 @@ var deserializeValue = (value) => csl.Value.from_bytes(toBytes(value));
|
|
|
167
167
|
import {
|
|
168
168
|
mnemonicToEntropy
|
|
169
169
|
} from "@meshsdk/common";
|
|
170
|
-
var resolveStakeKeyHash = (
|
|
170
|
+
var resolveStakeKeyHash = (bech32) => {
|
|
171
171
|
try {
|
|
172
172
|
const stakeKeyHash = [
|
|
173
|
-
toBaseAddress(
|
|
174
|
-
toRewardAddress(
|
|
173
|
+
toBaseAddress(bech32)?.stake_cred().to_keyhash(),
|
|
174
|
+
toRewardAddress(bech32)?.payment_cred().to_keyhash()
|
|
175
175
|
].find((kh) => kh !== void 0);
|
|
176
176
|
if (stakeKeyHash !== void 0) return stakeKeyHash.to_hex();
|
|
177
|
-
throw new Error(`Couldn't resolve stake key hash from address: ${
|
|
177
|
+
throw new Error(`Couldn't resolve stake key hash from address: ${bech32}`);
|
|
178
178
|
} catch (error) {
|
|
179
179
|
throw new Error(`An error occurred during resolveStakeKeyHash: ${error}.`);
|
|
180
180
|
}
|
|
@@ -214,9 +214,9 @@ var resolveNativeScriptHash = (script) => {
|
|
|
214
214
|
var resolveScriptHashDRepId = (scriptHash) => {
|
|
215
215
|
return csl.DRep.new_script_hash(
|
|
216
216
|
csl.ScriptHash.from_hex(scriptHash)
|
|
217
|
-
).to_bech32();
|
|
217
|
+
).to_bech32(true);
|
|
218
218
|
};
|
|
219
|
-
var resolveRewardAddress = (
|
|
219
|
+
var resolveRewardAddress = (bech32) => {
|
|
220
220
|
const buildRewardAddress = (networkId, stakeKeyHash) => {
|
|
221
221
|
return csl.RewardAddress.new(
|
|
222
222
|
networkId,
|
|
@@ -224,12 +224,12 @@ var resolveRewardAddress = (bech322) => {
|
|
|
224
224
|
);
|
|
225
225
|
};
|
|
226
226
|
try {
|
|
227
|
-
const address = toAddress(
|
|
228
|
-
const baseAddress = toBaseAddress(
|
|
227
|
+
const address = toAddress(bech32);
|
|
228
|
+
const baseAddress = toBaseAddress(bech32);
|
|
229
229
|
const stakeKeyHash = baseAddress?.stake_cred().to_keyhash();
|
|
230
230
|
if (stakeKeyHash !== void 0)
|
|
231
231
|
return buildRewardAddress(address.network_id(), stakeKeyHash).to_address().to_bech32();
|
|
232
|
-
throw new Error(`Couldn't resolve reward address from address: ${
|
|
232
|
+
throw new Error(`Couldn't resolve reward address from address: ${bech32}`);
|
|
233
233
|
} catch (error) {
|
|
234
234
|
throw new Error(`An error occurred during resolveRewardAddress: ${error}.`);
|
|
235
235
|
}
|
|
@@ -248,8 +248,8 @@ var serializePoolId = (hash) => {
|
|
|
248
248
|
var resolveScriptRef = (script) => {
|
|
249
249
|
return toScriptRef(script).to_hex();
|
|
250
250
|
};
|
|
251
|
-
var resolveEd25519KeyHash = (
|
|
252
|
-
return csl.Ed25519KeyHash.from_bech32(
|
|
251
|
+
var resolveEd25519KeyHash = (bech32) => {
|
|
252
|
+
return csl.Ed25519KeyHash.from_bech32(bech32).to_hex();
|
|
253
253
|
};
|
|
254
254
|
|
|
255
255
|
// src/utils/scripts.ts
|
|
@@ -274,14 +274,14 @@ var serialzeAddress = (deserializedAddress, networkId = 0) => {
|
|
|
274
274
|
const addressObj = isPaymentScript ? scriptAddress(paymentHash, stakeHash, isStakeScript) : pubKeyAddress(paymentHash, stakeHash, isStakeScript);
|
|
275
275
|
return serializeAddressObj(addressObj, networkId);
|
|
276
276
|
};
|
|
277
|
-
var addrBech32ToPlutusDataHex = (
|
|
278
|
-
const hexAddress = csl.Address.from_bech32(
|
|
277
|
+
var addrBech32ToPlutusDataHex = (bech32) => {
|
|
278
|
+
const hexAddress = csl.Address.from_bech32(bech32).to_hex();
|
|
279
279
|
const cslAddress = csl.Address.from_hex(hexAddress);
|
|
280
280
|
const hex = csl.PlutusData.from_address(cslAddress).to_hex();
|
|
281
281
|
return hex;
|
|
282
282
|
};
|
|
283
|
-
var addrBech32ToPlutusDataObj = (
|
|
284
|
-
const hexAddress = csl.Address.from_bech32(
|
|
283
|
+
var addrBech32ToPlutusDataObj = (bech32) => {
|
|
284
|
+
const hexAddress = csl.Address.from_bech32(bech32).to_hex();
|
|
285
285
|
const cslAddress = csl.Address.from_hex(hexAddress);
|
|
286
286
|
const json = JSON.parse(csl.PlutusData.from_address(cslAddress).to_json(1));
|
|
287
287
|
return json;
|
|
@@ -380,6 +380,9 @@ var keyHashToRewardAddress = (keyHashHex, network = 1) => {
|
|
|
380
380
|
return rewardAddress;
|
|
381
381
|
};
|
|
382
382
|
|
|
383
|
+
// src/utils/transaction.ts
|
|
384
|
+
import { js_get_tx_outs_utxo } from "@sidan-lab/sidan-csl-rs-nodejs";
|
|
385
|
+
|
|
383
386
|
// src/wasm.ts
|
|
384
387
|
var parseWasmResult = (result) => {
|
|
385
388
|
if (result.get_status() !== "success") {
|
|
@@ -407,13 +410,16 @@ var signTransaction = (txHex, signingKeys) => {
|
|
|
407
410
|
const result = csl.js_sign_transaction(txHex, cslSigningKeys);
|
|
408
411
|
return parseWasmResult(result);
|
|
409
412
|
};
|
|
410
|
-
var evaluateTransaction = (txHex, resolvedUtxos, network, slotConfig) => {
|
|
413
|
+
var evaluateTransaction = (txHex, resolvedUtxos, chainedTxs, network, slotConfig) => {
|
|
411
414
|
const additionalTxs = csl.JsVecString.new();
|
|
415
|
+
for (const tx of chainedTxs) {
|
|
416
|
+
additionalTxs.add(tx);
|
|
417
|
+
}
|
|
412
418
|
const mappedUtxos = csl.JsVecString.new();
|
|
413
419
|
for (const utxo of resolvedUtxos) {
|
|
414
420
|
mappedUtxos.add(JSON.stringify(utxo));
|
|
415
421
|
}
|
|
416
|
-
const result = csl.
|
|
422
|
+
const result = csl.js_evaluate_tx_scripts(
|
|
417
423
|
txHex,
|
|
418
424
|
mappedUtxos,
|
|
419
425
|
additionalTxs,
|
|
@@ -478,7 +484,7 @@ var getTransactionInputs = (txHex) => {
|
|
|
478
484
|
const input = cslInputs.get(i);
|
|
479
485
|
inputs.push({
|
|
480
486
|
txHash: input.transaction_id().to_hex(),
|
|
481
|
-
|
|
487
|
+
outputIndex: input.index()
|
|
482
488
|
});
|
|
483
489
|
}
|
|
484
490
|
const cslCollaterals = body.collateral();
|
|
@@ -487,7 +493,7 @@ var getTransactionInputs = (txHex) => {
|
|
|
487
493
|
const collateral = cslCollaterals.get(i);
|
|
488
494
|
inputs.push({
|
|
489
495
|
txHash: collateral.transaction_id().to_hex(),
|
|
490
|
-
|
|
496
|
+
outputIndex: collateral.index()
|
|
491
497
|
});
|
|
492
498
|
}
|
|
493
499
|
}
|
|
@@ -497,12 +503,17 @@ var getTransactionInputs = (txHex) => {
|
|
|
497
503
|
const refInput = cslRefInputs.get(i);
|
|
498
504
|
inputs.push({
|
|
499
505
|
txHash: refInput.transaction_id().to_hex(),
|
|
500
|
-
|
|
506
|
+
outputIndex: refInput.index()
|
|
501
507
|
});
|
|
502
508
|
}
|
|
503
509
|
}
|
|
504
510
|
return inputs;
|
|
505
511
|
};
|
|
512
|
+
var getTransactionOutputs = (txHex) => {
|
|
513
|
+
const outputs = js_get_tx_outs_utxo(txHex).get_data();
|
|
514
|
+
const utxos = JSON.parse(outputs);
|
|
515
|
+
return utxos;
|
|
516
|
+
};
|
|
506
517
|
|
|
507
518
|
// src/utils/aiken.ts
|
|
508
519
|
var applyParamsToScript = (rawScript, params, type = "Mesh") => {
|
|
@@ -542,63 +553,12 @@ var applyCborEncoding = (rawScript) => {
|
|
|
542
553
|
};
|
|
543
554
|
|
|
544
555
|
// src/utils/drep.ts
|
|
545
|
-
import base32 from "base32-encoding";
|
|
546
|
-
import { bech32 } from "bech32";
|
|
547
556
|
var getDRepIds = (dRepId) => {
|
|
557
|
+
const cslDrep = csl.DRep.from_bech32(dRepId);
|
|
548
558
|
let result = {
|
|
549
|
-
cip105:
|
|
550
|
-
cip129:
|
|
559
|
+
cip105: cslDrep.to_bech32(false),
|
|
560
|
+
cip129: cslDrep.to_bech32(true)
|
|
551
561
|
};
|
|
552
|
-
if (dRepId.length === 58) {
|
|
553
|
-
result.cip129 = dRepId;
|
|
554
|
-
const { prefix, words } = bech32.decode(dRepId);
|
|
555
|
-
if (prefix !== "drep") {
|
|
556
|
-
throw new Error("Malformed CIP129 DRepId");
|
|
557
|
-
}
|
|
558
|
-
const bytes = base32.decode(new Uint8Array(words));
|
|
559
|
-
if (bytes[0] === 34) {
|
|
560
|
-
result.cip105 = csl.DRep.new_key_hash(
|
|
561
|
-
csl.Ed25519KeyHash.from_hex(bytes.subarray(1).toString("hex"))
|
|
562
|
-
).to_bech32();
|
|
563
|
-
} else if (bytes[0] === 35) {
|
|
564
|
-
result.cip105 = csl.DRep.new_script_hash(
|
|
565
|
-
csl.ScriptHash.from_hex(bytes.subarray(1).toString("hex"))
|
|
566
|
-
).to_bech32();
|
|
567
|
-
} else {
|
|
568
|
-
throw new Error("Malformed CIP129 DRepId");
|
|
569
|
-
}
|
|
570
|
-
} else {
|
|
571
|
-
result.cip105 = dRepId;
|
|
572
|
-
try {
|
|
573
|
-
const cslDRep = csl.DRep.from_bech32(dRepId);
|
|
574
|
-
if (cslDRep.kind() === csl.DRepKind.KeyHash) {
|
|
575
|
-
let rawBytes = cslDRep.to_key_hash()?.to_bytes();
|
|
576
|
-
if (!rawBytes) {
|
|
577
|
-
throw new Error("Malformed key hash in DRepId");
|
|
578
|
-
}
|
|
579
|
-
let rawBytesWithPrefix = new Uint8Array(rawBytes.length + 1);
|
|
580
|
-
rawBytesWithPrefix.set([34]);
|
|
581
|
-
rawBytesWithPrefix.set(rawBytes, 1);
|
|
582
|
-
let base32RawBytes = base32.encode(rawBytesWithPrefix);
|
|
583
|
-
result.cip129 = bech32.encode("drep", base32RawBytes);
|
|
584
|
-
} else if (cslDRep.kind() === csl.DRepKind.ScriptHash) {
|
|
585
|
-
let rawBytes = cslDRep.to_script_hash()?.to_bytes();
|
|
586
|
-
if (!rawBytes) {
|
|
587
|
-
throw new Error("Malformed script hash in DRepId");
|
|
588
|
-
}
|
|
589
|
-
let rawBytesWithPrefix = new Uint8Array(rawBytes.length + 1);
|
|
590
|
-
rawBytesWithPrefix.set([35]);
|
|
591
|
-
rawBytesWithPrefix.set(rawBytes, 1);
|
|
592
|
-
let base32RawBytes = base32.encode(rawBytesWithPrefix);
|
|
593
|
-
result.cip129 = bech32.encode("drep", base32RawBytes);
|
|
594
|
-
} else {
|
|
595
|
-
throw new Error("Can only calculate DRepIds for script/key DReps");
|
|
596
|
-
}
|
|
597
|
-
} catch (e) {
|
|
598
|
-
console.error(e);
|
|
599
|
-
throw new Error("Malformed DRepId");
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
562
|
return result;
|
|
603
563
|
};
|
|
604
564
|
|
|
@@ -1289,7 +1249,12 @@ var CSLSerializer = class {
|
|
|
1289
1249
|
this.protocolParams = protocolParams || DEFAULT_PROTOCOL_PARAMETERS;
|
|
1290
1250
|
this.verbose = verbose;
|
|
1291
1251
|
}
|
|
1292
|
-
serializeTxBody(txBody, protocolParams) {
|
|
1252
|
+
serializeTxBody(txBody, protocolParams, balanced = true) {
|
|
1253
|
+
if (!balanced) {
|
|
1254
|
+
throw new Error(
|
|
1255
|
+
"Unbalanced transactions are not supported with CSL serializer"
|
|
1256
|
+
);
|
|
1257
|
+
}
|
|
1293
1258
|
const txBodyJson = JSONbig3.stringify(meshTxBuilderBodyToObj(txBody));
|
|
1294
1259
|
const params = JSONbig3.stringify(protocolParams || this.protocolParams);
|
|
1295
1260
|
if (this.verbose) {
|
|
@@ -1321,8 +1286,8 @@ var CSLSerializer = class {
|
|
|
1321
1286
|
}
|
|
1322
1287
|
deserializer = {
|
|
1323
1288
|
key: {
|
|
1324
|
-
deserializeAddress: function(
|
|
1325
|
-
return deserializeBech32Address(
|
|
1289
|
+
deserializeAddress: function(bech32) {
|
|
1290
|
+
return deserializeBech32Address(bech32);
|
|
1326
1291
|
}
|
|
1327
1292
|
},
|
|
1328
1293
|
script: {
|
|
@@ -1348,17 +1313,17 @@ var CSLSerializer = class {
|
|
|
1348
1313
|
};
|
|
1349
1314
|
resolver = {
|
|
1350
1315
|
keys: {
|
|
1351
|
-
resolveStakeKeyHash: function(
|
|
1352
|
-
return rewardAddressToKeyHash(
|
|
1316
|
+
resolveStakeKeyHash: function(bech32) {
|
|
1317
|
+
return rewardAddressToKeyHash(bech32) || deserializeBech32Address(bech32).stakeCredentialHash;
|
|
1353
1318
|
},
|
|
1354
1319
|
resolvePrivateKey: function(words) {
|
|
1355
1320
|
return resolvePrivateKey(words);
|
|
1356
1321
|
},
|
|
1357
|
-
resolveRewardAddress: function(
|
|
1358
|
-
return resolveRewardAddress(
|
|
1322
|
+
resolveRewardAddress: function(bech32) {
|
|
1323
|
+
return resolveRewardAddress(bech32);
|
|
1359
1324
|
},
|
|
1360
|
-
resolveEd25519KeyHash: function(
|
|
1361
|
-
return resolveEd25519KeyHash(
|
|
1325
|
+
resolveEd25519KeyHash: function(bech32) {
|
|
1326
|
+
return resolveEd25519KeyHash(bech32);
|
|
1362
1327
|
}
|
|
1363
1328
|
},
|
|
1364
1329
|
tx: {
|
|
@@ -1418,36 +1383,47 @@ var OfflineEvaluator = class {
|
|
|
1418
1383
|
* - budget: Memory units and CPU steps required
|
|
1419
1384
|
* @throws Error if any required UTXOs cannot be resolved or if script evaluation fails
|
|
1420
1385
|
*/
|
|
1421
|
-
async evaluateTx(tx) {
|
|
1422
|
-
const
|
|
1386
|
+
async evaluateTx(tx, additionalUtxos, additionalTxs) {
|
|
1387
|
+
const foundUtxos = /* @__PURE__ */ new Set();
|
|
1388
|
+
for (const utxo of additionalUtxos) {
|
|
1389
|
+
foundUtxos.add(`${utxo.input.txHash}:${utxo.input.outputIndex}`);
|
|
1390
|
+
}
|
|
1391
|
+
for (const tx2 of additionalTxs) {
|
|
1392
|
+
const outputs = getTransactionOutputs(tx2);
|
|
1393
|
+
for (const output of outputs) {
|
|
1394
|
+
foundUtxos.add(`${output.input.txHash}:${output.input.outputIndex}`);
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
const inputsToResolve = getTransactionInputs(tx).filter(
|
|
1398
|
+
(input) => !foundUtxos.has(`${input.txHash}:${input.outputIndex}`)
|
|
1399
|
+
);
|
|
1423
1400
|
const txHashesSet = new Set(inputsToResolve.map((input) => input.txHash));
|
|
1424
|
-
const resolvedUTXOs = [];
|
|
1425
1401
|
for (const txHash of txHashesSet) {
|
|
1426
1402
|
const utxos = await this.fetcher.fetchUTxOs(txHash);
|
|
1427
1403
|
for (const utxo of utxos) {
|
|
1428
1404
|
if (utxo) {
|
|
1429
1405
|
if (inputsToResolve.find(
|
|
1430
|
-
(input) => input.txHash === txHash && input.
|
|
1406
|
+
(input) => input.txHash === txHash && input.outputIndex === utxo.input.outputIndex
|
|
1431
1407
|
)) {
|
|
1432
|
-
|
|
1408
|
+
additionalUtxos.push(utxo);
|
|
1409
|
+
foundUtxos.add(`${utxo.input.txHash}:${utxo.input.outputIndex}`);
|
|
1433
1410
|
}
|
|
1434
1411
|
}
|
|
1435
1412
|
}
|
|
1436
1413
|
}
|
|
1437
1414
|
const missing = inputsToResolve.filter(
|
|
1438
|
-
(input) => !
|
|
1439
|
-
(utxo) => utxo.input.txHash === input.txHash && utxo.input.outputIndex === input.index
|
|
1440
|
-
)
|
|
1415
|
+
(input) => !foundUtxos.has(`${input.txHash}:${input.outputIndex}`)
|
|
1441
1416
|
);
|
|
1442
1417
|
if (missing.length > 0) {
|
|
1443
|
-
const missingList = missing.map((m) => `${m.txHash}:${m.
|
|
1418
|
+
const missingList = missing.map((m) => `${m.txHash}:${m.outputIndex}`).join(", ");
|
|
1444
1419
|
throw new Error(
|
|
1445
1420
|
`Can't resolve these UTXOs to execute plutus scripts: ${missingList}`
|
|
1446
1421
|
);
|
|
1447
1422
|
}
|
|
1448
1423
|
return evaluateTransaction(
|
|
1449
1424
|
tx,
|
|
1450
|
-
|
|
1425
|
+
additionalUtxos,
|
|
1426
|
+
additionalTxs,
|
|
1451
1427
|
this.network,
|
|
1452
1428
|
this.slotConfig
|
|
1453
1429
|
);
|
|
@@ -1496,6 +1472,7 @@ export {
|
|
|
1496
1472
|
fromUTF8,
|
|
1497
1473
|
getDRepIds,
|
|
1498
1474
|
getTransactionInputs,
|
|
1475
|
+
getTransactionOutputs,
|
|
1499
1476
|
getV2ScriptHash,
|
|
1500
1477
|
keyHashToRewardAddress,
|
|
1501
1478
|
meshTxBuilderBodyToObj,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshsdk/core-csl",
|
|
3
|
-
"version": "1.9.0-beta.
|
|
3
|
+
"version": "1.9.0-beta.10",
|
|
4
4
|
"description": "Types and utilities functions between Mesh and cardano-serialization-lib",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@meshsdk/configs": "*",
|
|
34
|
-
"@meshsdk/provider": "1.9.0-beta.
|
|
34
|
+
"@meshsdk/provider": "1.9.0-beta.10",
|
|
35
35
|
"@types/json-bigint": "^1.0.4",
|
|
36
36
|
"eslint": "^8.57.0",
|
|
37
37
|
"ts-jest": "^29.1.4",
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"typescript": "^5.3.3"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@meshsdk/common": "1.9.0-beta.
|
|
43
|
-
"@sidan-lab/sidan-csl-rs-browser": "0.9.
|
|
44
|
-
"@sidan-lab/sidan-csl-rs-nodejs": "0.9.
|
|
42
|
+
"@meshsdk/common": "1.9.0-beta.10",
|
|
43
|
+
"@sidan-lab/sidan-csl-rs-browser": "0.9.21",
|
|
44
|
+
"@sidan-lab/sidan-csl-rs-nodejs": "0.9.21",
|
|
45
45
|
"@types/base32-encoding": "^1.0.2",
|
|
46
46
|
"base32-encoding": "^1.0.0",
|
|
47
47
|
"bech32": "^2.0.0",
|
|
@@ -59,4 +59,4 @@
|
|
|
59
59
|
"blockchain",
|
|
60
60
|
"sdk"
|
|
61
61
|
]
|
|
62
|
-
}
|
|
62
|
+
}
|