Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
@fabianbormann/cardano-peer-connect
Advanced tools
This library aims to provide an abstract class to simplify to wallet implementation for CIP-????
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.
npm i @fabianbormann/cardano-peer-connect
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,
});
//further actions to let you wallet know about the new connection
// ...
}
// and implement all CIP-30 functions
getRewardAddresses(): Promise<Cbor[]> {
return new Promise((resolve, reject) => {
//in here you determine the reward addresses for yur wallet used
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/types';
// the id the dapp is showing you.
const dAppIdentifier = 'bYUh6Bn6A........388LR1JCrED';
peerConnect.value = new BoostPeerConnect(
'Your wallet name',
'1.0.1',
'<img src="data:image/png;base64,iVB.....>' //your wallet logo
);
/**
* Define a callback to handle all connection attempts. This will be called by the DApp when a connection is
* tried to be established.
*/
peerConnect.value.setOnConnect((message: IConnectMessage) => {
connectStatus.value = message;
if (!message.dApp.address) {
// every dapp should send some infos about it.
}
if (message.dApp.address !== dAppIdentifier) {
// the connected dapp id should match the one that the user requested
}
if (message.error) {
//handle the connection error (message.errorMessage)
}
//now handle the message and show which dapp was connected to your wallet
});
// finally try to connect to the dapp
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()
);
//seed will be the unique connection id between you and the dapp
//The connection is not yet established. The user needs to grant the permission to establish the connection on the
//dapp side. See next section on how a DApp must implement this.
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/bundle.min.js"></script>
<script>
// Give your app some basic information that will be displayed to the client wallet when he is connecting to your DApp.
const dAppInfo: IDAppInfos = {
name: 'An awesome DApp',
url: 'http://an-awesome-dapp-url.tld/'
}
// Define a function that will be called when the client tries to connect to your DApp.
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, // will be call when api was successfully injected
onApiEject: onApiEject, // will be call when api was ejected
});
// This is the code (identifier) that the client needs to enter into the wallet to connect to your dapp
const clientConnectCode = dAppConnect.getAddress()
// Create and insert a QR code on your DApp, so the user can scan it easily in their app
dAppConnect.generateQRCode(document.getElementById('qr-code'));
//after the api was injected you cann call all cip-30 function on window.cardanop2p as you would on window.cardano
</script>
FAQs
This library aims to provide an abstract class to simplify to wallet implementation for CIP-0045
We found that @fabianbormann/cardano-peer-connect demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.