Lightweight/Simple
Much of the complexity is shunted to the tooling, reducing the complexity of the spec. for easier integration and porting to other languages.
Preview Release
This is a preview release to get developer feedback and (hopefully) identify gaps in the current implementation. CashConnect is still under development and IS NOT yet safe for Production use.
CashConnect is a lightweight templating system that aims to provide a versatile and secure interface for Dapp <-> Wallet communications on Bitcoin Cash.
These templates are serializable to JSON and use CashASM to give them advanced scripting capabilities. They have a structure as follows:
{
name: 'Example Template',
description: 'This is an example template',
actions: {
// ... methods that can be invoked.
},
scripts: {
// ... global scripts that are re-used by Actions.
// E.g. Lock/Unlock scripts.
}
}At their bare-minimum, Actions have params (data-in), instructions (processes) and returns (data-out). In this sense, they operate like a function with instructions being a pipeline of operations that should be performed (usually, by the wallet). This pipeline-esque approach allows templates to generalize to many use-cases that might otherwise be difficult to formalize into a fixed schema.
A very simple send action may look like so:
{
//...
actions: {
// A very simple send action that pays a given sats amount to the provided address
send: {
params: {
receivingAddress: Vars.address('Receiving Address'),
sats: Vars.number('Sats to send'),
},
instructions: [
Instructions.transaction({
name: 'tx',
// Use any available UTXOs from parent wallet.
inputs: ['*'],
outputs: [
{
lockingBytecode: expr`receivingAddress`,
valueSatoshis: expr`sats`,
},
// Append change outputs to parent wallet.
'*',
]
})
],
returns: {
txHash: Vars.transactionHash('Resulting Tx Hash'),
}
}
}
}And then executed as follows:
// ... Instantiate template instance.
// Execute the send action.
const sendResult = templateInstance.executeAction('send', {
receivingAddress: Address.from('bitcoincash:...').toLockscriptBytes(),
sats: Satoshis.fromBCH('0.01').toBigInt(),
});
// The returned data (e.g. for DB persistence) is available under:
// sendResult.data;
// Broadcast the resulting transaction(s).
await blockchain.broadcastTransactions(sendResult.transactions);To ease development and testing of templates, Tooling is provided under a cashconnect-js/templates-dev package. This includes a (nearly full-functional) Mock Blockchain adapter that can be used to test your Template flows.
The intent is that Templates should become their own Repository that includes the Template Building code and a healthy suite of tests to confirm proper functioning of the template.
Auditors can then refer to this repository and compile, test and sign the template so that it can be whitelisted for safe-use.
(In this respect, it's not dissimilar to the current open-source reproducible-builds philosophy in that executables are compiled from source and signed by trusted parties).
See the FAQ for more information.
Once written, Templates can then be leveraged on Dapp frontends (using WalletConnect as a transport) like so:
Uint8Array Params/Returns
Currently, all params must be encoded as Uint8Array - and all data returned as Uint8Array. In future, native JS types (e.g. bigint, string, etc) will be usable but there's some pre-requisite work I still need to do before allowing this. See Roadmap for more information.
INFO
While the initial release of CashConnect targets WalletConnect as a transport, the templates are designed to be transport agnostic. This means that, in future, they can: