Cardano Peer Connect
This library aims to provide simple interfaces to implement CIP-0045 for dApps and wallets.
If you want to see cardano-peer-connect
in action, please visit the cip-0045-demo-implementation repository.
Getting Started
npm i @fabianbormann/cardano-peer-connect
Infos for usage in the wallet
Extend the base CardanoPeerConnect class for your wallet:
class BoostPeerConnect extends CardanoPeerConnect {
constructor(name: string, apiVersion: string, icon: string) {
super({
name: name,
version: apiVersion,
icon: icon,
});
}
getRewardAddresses(): Promise<Cbor[]> {
return new Promise((resolve, reject) => {
const rewardAddresses = [
'e1820506cb0ce54ae75.....7265e8792cb86afc94e0872',
];
return resolve(rewardAddresses);
});
}
}
Then create an instance of that class in your code and add a callback to let your wallet know about the connection status.
import {
CardanoPeerConnect,
DAppPeerConnect,
} from '@fabianbormann/cardano-peer-connect';
import { IConnectMessage } from '@fabianbormann/cardano-peer-connect/dist/src/types';
const dAppIdentifier = 'bYUh6Bn6A........388LR1JCrED';
peerConnect.value = new BoostPeerConnect(
'Your wallet name',
'1.0.1',
'<img src="data:image/png;base64,iVB.....>'
);
peerConnect.value.setOnConnect((message: IConnectMessage) => {
connectStatus.value = message;
if (!message.dApp.address) {
}
if (message.dApp.address !== dAppIdentifier) {
}
if (message.error) {
}
});
const seed = peerConnect.value.connect(
dAppIdentifier,
[
'https://pro.passwordchaos.gimbalabs.io',
'wss://tracker.files.fm:7073/announce',
'wss://tracker.btorrent.xyz',
'ws://tracker.files.fm:7072/announce',
'wss://tracker.openwebtorrent.com:443/announce',
],
getPeerSeed()
);
Infos for usage in DApp site
This is the necessary minimal implementation a DApp provider has to do, to get his app connected to peer connect.
<script src="https://fabianbormann.github.io/cardano-peer-connect/latest/index.js"></script>
<script>
const dAppInfo: IDAppInfos = {
name: 'An awesome DApp',
url: 'http://an-awesome-dapp-url.tld/'
}
const verifyConnection = (
walletInfo: IWalletInfo,
callback: (granted: boolean) => void
) => {
callback(
window.confirm(`Do you want to connect to wallet ${walletInfo.name} (${walletInfo.address})?`)
);
const dAppConnect = new DAppPeerConnect({
dAppInfo: dAppInfo,
verifyConnection: verifyConnection,
onApiInject: onApiInject,
onApiEject: onApiEject,
});
const clientConnectCode = dAppConnect.getAddress()
dAppConnect.generateQRCode(document.getElementById('qr-code'));
</script>