Giter Club home page Giter Club logo

Comments (1)

hazryder avatar hazryder commented on June 14, 2024

After a fair bit of digging I've managed to resolve this;

I realised the crux of my issue was that the NativeScript instantiation was expecting a CBOR hex, not a hex string conversion of the JSON script, and so I wrote a few functions to leverage the cardano-multiplatform-lib to serialise my JSON into the required CBOR format, resulting in a NativeScript obj.

I then extended tx with a function to directly attach a NativeScript obj, and finally repeated a similar process for the signing keys since I had local vkey/skey files which needed converting.

Ultimately I was successful and have been able to refactor my cardanocli-js minting application to use Lucid instead.

My relevant code for converting a simple cardano native script .json to NativeScript cbor:

lucid/utils.js

     nativeScriptFromJson(json){
        if(json.type === "all") {
            var scripts = json.scripts.map(e => this.nativeScriptFromJson(e))
            return {
                root: this.buildMultiIssuerAllScripts(scripts.map(s => s.root)), 
                scripts: scripts
            }
        }
        if(json.type === "sig") {
            var keyHash = C.Ed25519KeyHash.from_bytes(Buffer.from(json.keyHash, "hex"))

            return {
                root: this.buildSingleIssuerScript(keyHash),
                keyHash: Buffer.from(keyHash.to_bytes()).toString("hex"),
                scripts: []
            }
        }
    }

    buildSingleIssuerScript(keyHash) {
        var scriptPubKey = C.ScriptPubkey.new(keyHash)

        return C.NativeScript.new_script_pubkey(scriptPubKey)
    }

    buildMultiIssuerAllScripts(scripts) {
        var nativeScripts = this.buildNativeScripts(scripts)

        var scriptAll = C.ScriptAll.new(nativeScripts)

        return C.NativeScript.new_script_all(scriptAll)
    }

    buildNativeScripts(scripts) {
        var nativeScripts = C.NativeScripts.new()

        for(const script of scripts) {
            nativeScripts.add(script)
        }

        return nativeScripts
    }

from lucid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.