fabianbormann / cardano-peer-connect

This library aims to provide simple interfaces to implement CIP-0045 for dApps and wallets
Apache License 2.0
12 stars 4 forks source link

feat: Allow injection of experimental features as defined in CIP30 #22

Closed marcuspuchalla closed 1 year ago

marcuspuchalla commented 1 year ago

Wallets can now add experimental api features for the window.cardano['walletname'].experimental and the (await window.cardano['walletname'].enable()).experimental endpoint.

To do so they should use setExperimentalApi and setEnableExperimentalApi in their implementation of CardanoPeerConnect.

Functions and basic/simple data types can be injected as a key-value map into an object instance of ExperimentalContainer.

To make all this work, the ExperimentalContainer was added to the lib folder. This has lot of documentation about its internals.

In simple terms, the ExperimentalContainer is a utility that enables the serialization of an object's structure, properties, and functions, allowing it to be transferred to a remote system. This serialized information, referred to as a TypeMapping, can be used by the remote system to interact with the object without prior knowledge of the object's structure or implementation details.

In simpler terms, the ExperimentalContainer captures the blueprint of an object, including its properties and functions, and converts it into a format that can be easily shared between different systems. The receiving system can then use this blueprint to interact with the object as if it had direct knowledge of the object's structure.

Non-function properties are transferred to the remote system on api injection. So if a wallet changes these parameters after connecting to a DApp, the DApp will only get the new values when a new connection has been established. Functiosn however work as before and provide a real rpc call to the wallet and can get any data.

In the future, these new functions might be used for the normal cip30 functions, as they make the codebase smaller. For now I left them how they are.

A demo implementation of this will follow shortly on the demo repo.