cashscript
cashscript copied to clipboard
Export a Libauth template from a Contract instance
The main primitive used in Libauth's flexible transaction generation API is the AuthenticationTemplate. It would be useful if the CashScript SDK enables a Contract instance to export a libauth template based on the contract. From a quick exploration it looks like an AuthenticationTemplate includes a bit more semantic information than the plain CashScript contract (e.g. entities
), so we'll have to figure out an ergonomic way for the user to provide the extra information to generate a complete AuthenticationTemplate.
cc @bitjson
In the past two weeks I've been looking into Authentication Templates more. When considering a CashScript source file, there is a number of things that can be generated and a number of things that cannot be generated from just the CashScript source code.
- $schema - Can be hardcoded
- description - Cannot be derived from CashScript source code
- entities - Cannot be derived from aashScript source code
- name - Can be taken from the contract name
- scenarios - Cannot be derived from CashScript source code
- scripts - Cannot be derived from CashScript source code because it depends on entities
- scripts (if we disregard entities)
- lock - Can be taken from the compiled source code + constructor parameters
- unlocking - Can be taken from the contract functions
- supported - Can be hardcoded
- version - Needs to be hardcoded
So from this overview we see that the main things that we need to solve are the description, entities and scenarios. @monsterbitar suggested that we might be able to use JSdoc/natspec like annotations that could be used to supply the missing information. This should very easily work for the description and any other description tags that are needed (e.g. in scripts). I'm pretty positive that this should work for entities as well. What would be harder is sophisticated scenarios, which might not be needed for generalised usage. The most important scenario to have would be an estimation scenario though, so we should make an extra effort to see if we can at least integrate an estimation scenario for all scripts.
This would be great to have so debugging the compiled scripts in the Bitauth IDE is possible! Meep used to be the tool for that but it's unmaintained and doesn't support native introspection & is not upgrading to add the CashTokens functionality.
mainnet.cash v1.1.0 adds support for libauth template generation. A scenario with the contract and function parameters (which is expected to pass) is added to this template too. see more info https://t.me/mainnetcash/1218