Hi all, just an update:
LibAuth Templates
Some of the contracts I’m testing with are quite complex - and after trying many different approaches (and then realizing they can’t do what we’d need it to do), I’ve eventually settled on using LibAuth templates for the signTransaction/compileScripts calls. This has several benefits:
- We will hopefully be able to eventually converge on what BitJSON is building (so we don’t end up with fractured standards).
- CashASM (used by LibAuth Templates) is very flexible/powerful.
- These templates are hashable - thus, we can provide methods for whitelisting a given template.
- Code to handle these is pretty simple/clean.
- With good tooling, it is relatively trivial to convert CashScript Artifacts to LibAuth templates.
On Point 5, I’ve created a rudimentary tool for this here:
https://tools.developers.cash/#/tools/artifacts-to-auth-template
(A more refined and well-thought out version might eventually be integrated direct into CashScript Lib).
Wallet Connect Library
I’m testing the Library I’m building by integrating into a forked version of Cashonize. Cashonize is HTML/VanillaJS and I’m not very efficient at working with that - so it may take me a little longer than anticipated to get a demo out.
However, I just want to give an example of how this library might be used to integrate into other (TS/JS-based) Wallets in future:
const walletConnect = new WalletConnect(
'yourWCProjectId',
{
name: 'Cashonize',
description: 'Cashonize BitcoinCash Web Wallet',
url: 'cashonize.com/',
icons: ['https://cashonize.com/images/favicon.ico'],
},
{
// Session Callbacks.
onSessionProposal: (sessionProposal) => {
// Present UI to approve session.
// Get master WC Private Key from Derivation Path.
// NOTE: Each service will derive its own Sandboxed Private Key from the given Master Key.
// E.g. sandboxedPrivateKey = hash256(Uint8Array([...masterPrivateKey, ...serviceId]);
// Where serviceId is the WC Project ID.
// NOTE: The RPC's are intended to be transport agnostic so, in future, serviceId might refer to a Domain, LibP2P pubkey, etc.
// return { masterPrivateKey }
},
onSessionDelete: {
// Notify user that session was deleted.
},
// RPC Callbacks.
// NOTE: Wallet might choose to auto-approve some RPC calls.
onCompileScriptV0: (session, req, res) => {
// Present UI to approve RPC call.
},
onGetBalanceV0: (session, req, res) => {
// Present UI to approve RPC call.
}
onGetTokensV0: (session, req, res) => {
// Present UI to approve RPC call.
},
onSignTransactionV0: (session, req, res) => {
// Present UI to approve RPC call.
},
// Wallet Connectivity.
getUnspents: () => {
// Provide Unspents from Wallet to WalletConnect.
// return unspents;
},
getSourceOutputs: (sourceOutputs) => {
// Provide Source Outputs to WalletConnect.
// return sourceOutputs;
},
getChangeAddresess: () => {
// Haven't fleshed this one out yet, but will likely need it.
}
}
);
// Start Wallet Connect.
await walletConnect.start();
Note that the above is still being fleshed out - so will likely change quite a bit.