@harmoniclabs/pluts-emulator
Version:
Cardano emulator for offchian testing
41 lines (40 loc) • 1.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createInitialUTxO = exports.generateRandomTxHash = exports.generateRandomBech32Address = void 0;
const plu_ts_1 = require("@harmoniclabs/plu-ts");
const crypto_1 = require("crypto");
/**
* Generate a random Bech32 address.
*/
function generateRandomBech32Address() {
const hash28i = (0, crypto_1.getRandomValues)(new Uint8Array(28));
const testnetAddr = new plu_ts_1.Address("testnet", plu_ts_1.Credential.keyHash(hash28i));
return testnetAddr.toString();
}
exports.generateRandomBech32Address = generateRandomBech32Address;
/**
* Generate a random transaction hash for testing
*/
function generateRandomTxHash(salt = 0) {
// Create a predictable but unique hash based on salt
return Array.from({ length: 64 }, (_, i) => "0123456789abcdef"[(i + salt) % 16]).join("");
}
exports.generateRandomTxHash = generateRandomTxHash;
/**
* Create an initial UTxO for the emulator
*/
function createInitialUTxO(lovelaces, address, txHash) {
return {
utxoRef: {
id: txHash,
index: 0
},
resolved: {
address: address,
value: plu_ts_1.Value.lovelaces(lovelaces),
datum: undefined,
refScript: undefined
}
};
}
exports.createInitialUTxO = createInitialUTxO;