The community has been busy over the past months across many topics. In this post I want to update you on one of the most exciting updates: TypeScript support for smart legal contract template logic: both for drafting (text generation) as well as to implement type-safe logic for contracts.

Notable areas of community work over the past few months have been:

  1. Data modelling support (Concerto); a special thank you to the contributors from Docusign!
  2. UX and UI improvements to Template Playground
  3. And most recently, support for TypeScript template logic!

TypeScript Support

TypeScript is used in two places in Accord Project templates:

  1. As an expression language embedded within template text
  2. As the language for template logic, responding to events from the outside world

TypeScript as a template expression language

TypeScript expressions used in TemplateMark (the Accord Project template language) are enclosed between {{% and %}} and are dynamically evaluated by the template engine.

For example, this expression renders the current date and time as a string into the template output:

TypeScript expressions in templates are transpiled/compiled on the fly to JavaScript and then evaluated either in or out of process.

Accord Project calls the process of merging data to the TemplateMark to produce an AgreementMark output document  DRAFTING.

TypeScript as a template logic language

Accord Project also uses TypeScript as a language to capture the LOGIC of a (piece) of a smart legal contract. The logic has access to the data points for the contract (the agreed terms) and processes events from the outside world to produce responses.

A TypeScript class is defined in the logic folder of the template and exported, for example:

The template logic code imports types generated from the template model and then implements a trigger function that processes the incoming events to produce responses.

Accord Project calls sending a request to a smart legal contract, and running its logic TRIGGERING the smart legal contract.

Architecture

After many years of development, the Accord Project architectural stack is both broad and deep, so a high-level overview may be useful for newcomers.

  1. Start by looking at the demo-template repository. This repository includes a simple index.js script that DRAFTS a contract as well as TRIGGERING it.
  2. The script first loads the template from disk, using the Template class from @accordproject/cicero-core. This repository is responsible for the template archive file format: what files and metadata go into a template and how are the loaded and saved to disk.
  3. Once loaded the template is passed to the TemplateArchiveProcessor class from @accordproject/template-engine, which knows how to merge data with TemplateMark to produce AgreementMark and includes all the TypeScript to JS compilation infrastructure, as well as the in/out of process evaluation of JS code.
    1. TemplateArchiveProcessor uses @accordproject/markdown-transform to transform the output AgreementMark (JSON) document to a variety of output formats: markdown, HTML, PDF etc.
  4. The whole stack makes extensive use of @accordproject/concerto to handle both internal and end-user defined data models. For example, there is a Concerto data model for TemplateMark, as well as the output from the Template Engine (AgreementMark aka CiceroMark). Evaluation of the TypeScript expressions in TemplateMark JIT compiles the template model to TypeScript types using @accordproject/concerto-codegen to ensure that the expressions are type-checked.

 

Summary

Development is very active at the moment, with new capabilities and fixes arriving week-by-week. We welcome all your testing and feedback. Architectural discussions are underway to add support for Rust/Go as well as the REST API binding, which is defined by the APAP server.

Weekly Technology Working Group calls are open to all, don’t hesitate to get involved.