Integrating policy script generated by CLI in cardano-serialization-lib

For what it’s worth:

policy-script.json:

{
    "type": "all",
    "scripts":
    [
        {
            "type": "before",
            "slot": 66013091
        },
        {
            "type": "sig",
            "keyHash": "0e2ddcb532c75431d714f792209c6b800aeed728f6f52912362c3132"
        }
    ]
}
$ cardano-cli transaction policyid --script-file policy-script.json
e66e5a0ce00d69fb6ee9ac8ae62c34858a55a1976a0647a7efed81be

policy-script.js:

"use strict"

const CSL = require("@emurgo/cardano-serialization-lib-nodejs/cardano_serialization_lib")

const keyBytes = Buffer.from('0e2ddcb532c75431d714f792209c6b800aeed728f6f52912362c3132', 'hex')
const keyHash = CSL.Ed25519KeyHash.from_bytes(keyBytes)

const nativeScripts = CSL.NativeScripts.new()

const lockScript = CSL.NativeScript.new_timelock_expiry(
    CSL.TimelockExpiry.new(66013091))
nativeScripts.add(lockScript)

const sigScript = CSL.NativeScript.new_script_pubkey(
    CSL.ScriptPubkey.new(keyHash))
nativeScripts.add(sigScript)

const allScript = CSL.NativeScript.new_script_all(
    CSL.ScriptAll.new(nativeScripts))

console.log(Buffer.from(allScript.hash().to_bytes()).toString('hex'))
$ node policy-script.js
e66e5a0ce00d69fb6ee9ac8ae62c34858a55a1976a0647a7efed81be
1 Like