StricaHQ / typhonjs

Pure javascript Cardano wallet library
Apache License 2.0
61 stars 12 forks source link

createPlutusDataCbor doesn't accept certain acceptable structures to cardano-cli #8

Closed eselkin closed 2 years ago

eselkin commented 2 years ago

This structure is not accepted:

import { encode } from 'cborg';
import {utils} from "@strictahq/typhonjs"

const pkh = Buffer.from(await getPubKeyHash());
const pkhCBORed = Buffer.from(encode(pkh));

utils.createPlutusDataCbor({
  "fields": [
    {
      "fields": [ pkhCBORed ],
      "constructor": 0
    }
  ],
  "constructor": 0
}) 

or with the bytes tag and the CBOR as a string (as it is accepted in cardano-cli)

ashisherc commented 2 years ago
  1. the encode import looks different, are you trying to use @stricahq/cbors?
  2. pkh doesn't need to be cbor encoded (unless you are trying to do something specific)
  3. I think you need to do Buffer.from(value, 'hex'), unless you know what the value is

and do verify the accepted type once here, https://docs.strica.io/lib/typhonjs/modules/utils.html#createPlutusDataCbor

eselkin commented 2 years ago

That was it. The data should just be the bytes of the PKH not CBOR encoded bytes. Hash comes out the same as cardano-cli with the CBOR string in JSON.