@harmoniclabs/buildooor
Version:
Cardano transaction builder in typescript
67 lines (66 loc) • 2.82 kB
JavaScript
;
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.estimateMaxSignersNeeded = exports.scriptTypeToDataVersion = void 0;
var cardano_ledger_ts_1 = require("@harmoniclabs/cardano-ledger-ts");
function scriptTypeToDataVersion(scriptType) {
// if( scriptType === ScriptType.NativeScript ) return undefined;
if (scriptType === cardano_ledger_ts_1.ScriptType.PlutusV1)
return "v1";
if (scriptType === cardano_ledger_ts_1.ScriptType.PlutusV2)
return "v2";
if (scriptType === cardano_ledger_ts_1.ScriptType.PlutusV3)
return "v3";
return undefined;
}
exports.scriptTypeToDataVersion = scriptTypeToDataVersion;
function estimateMaxSignersNeeded(tx) {
var _a;
var bodySigners = (0, cardano_ledger_ts_1.getAllRequiredSigners)(tx.body)
.map(function (hash) { return hash.toString(); })
.filter(function (elem, i, thisArr) { return thisArr.indexOf(elem) === i; });
var allSigners = getAllNativeScriptSigners(((_a = tx.witnesses.nativeScripts) !== null && _a !== void 0 ? _a : [])
.map(function (script) { return script.toJson(); }))
.filter(function (native) { return native.type === "sig"; })
.map(function (native) { return native.keyHash.toString(); })
.concat(bodySigners)
.filter(function (elem, i, thisArr) { return thisArr.indexOf(elem) === i; });
return allSigners.length <= 0 ? 1 : allSigners.length;
}
exports.estimateMaxSignersNeeded = estimateMaxSignersNeeded;
function getAllNativeScriptSigners(natives) {
return natives
.reduce(function (accum, native) {
if (native.type === "sig")
accum.push(native);
if (native.type === "all" ||
native.type === "any" ||
native.type === "atLeast")
accum.push.apply(accum, __spreadArray([], __read(getAllNativeScriptSigners(native.scripts)), false));
return accum;
}, []);
}