npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@credo-ts/transport-ble

v0.3.0

Published

Bluetooth Low Energy transport for Credo

Downloads

23

Readme

The Credo BLE Transport package provides a simple way to add Bluetooth Low Energy (BLE) data transport into Credo React Native mobile agents.

It implements the same transport interface as the outbound transports in @credo-ts/core, and the inbound transports in @credo-ts/node.

With this transport enabled, Credo React Native mobile agents gain the ability to do offline DIDComm exchanges using Bluetooth Low Energy (BLE).

To keep this transport implementation focused on the 'DIDComm' wrapper needed to make it useful to Credo agents, this transport package is built on this BLE DIDComm SDK.

The BLE DIDComm SDK implements the core Bluetooth hardware interface for Android (in Kotlin) and iOS (Swift), and exposes the simple APIs that this BLE transport implementation uses.

And to keep the implementation simple, this transport only implements the core message listening and receiving functionality, and leaves the powerful startup and service controls provided by the BLE DIDComm SDK, to user control and discretion.

We're this discussing if this is the best approach to use in future versions. If after using this first version and you have strong opinions on this, kindly join the conversation here.

Installing the required dependencies

yarn add @credo-ts/transport-ble @credo-ts/core @credo-ts/react-native @animo-id/react-native-ble-didcomm

Configuration

Configuring your agent to use the transport is simple; all you need is to import the transports, BleOutboundTransport and BleInboundTransport, from the package, and register them on the agent, either before or after agent initialization.

The only difference is that unlike HTTP and WebSockets, an agent can only register one of either outbound, BleOutboundTransport, or inbound, BleInboundTransport, transport, depending on which role the agent wants to take in the BLE DIDComm exchange.

The BLE DIDComm SDK provides two controllers: Central, to be used by the agent who will be initiating the exchange (creating and sending the out-of-band invitation), and Peripheral, for the agent who will be receiving and accepting the invitation.

This means that the agent acting as the connection initiator should use the Central controller with BleInboundTransport, while the agent acting as the connection receptor uses the Peripheral controller with BleOutboundTransport.

// If you want to register the transports only after initializing the agent, you can do this anywhere else in your app, and just leave out the agent config and initialization

import { BleOutboundTransport, BleInboundTransport } from '@credo-ts/transport-ble'
import { Agent } from '@credo-ts/core'
import { agentDependencies } from '@credo-ts/react-native'
import {
  Central,
  Peripheral,
  DEFAULT_DIDCOMM_SERVICE_CHARACTERISTIC_UUID,
  DEFAULT_DIDCOMM_MESSAGE_CHARACTERISTIC_UUID,
  DEFAULT_DIDCOMM_INDICATE_CHARACTERISTIC_UUID,
} from '@animo-id/react-native-ble-didcomm'

const createAgent = async () => {
  const agent = new Agent({
    config: {
      // ... Credo Config ... //
    },
    modules: {
      // ... Credo Module config
    },
    dependencies: agentDependencies,
  })

  // Instantiate the BLE controller you want
  const central = new Central() // const peripheral = new Peripheral() for the peripheral agent

  // It is important that you start the BLE controllers before you use/register them on your agent
  await central.start() // await peripheral.start()

  /* IMPORTANT: Setting up the service, messaging and indication UUIDs. 
  The values passed must be the same in the central and peripheral, 
  as this is how both devices will be able to recognize each other. 
  There are default values for these that can be imported, 
  but if you want to maintain control over the sessions and/or prevent collisions 
  (due to multiple other devices broadcasting using these same values), 
  you might want to generate your own serviceUUID and share it across both mobile agents 
  (using a scannable QR code or something similar that allows easy sharing with little overhead)
  
  This can be done anywhere after starting the controller (step above), 
  even after registering the controller as a transport on the agent (step below) */

  const uuid = '56847593-40ea-4a92-bd8c-e1514dca1c61'
  await central.setService({
    serviceUUID: uuid || DEFAULT_DIDCOMM_SERVICE_CHARACTERISTIC_UUID,
    messagingUUID: DEFAULT_DIDCOMM_MESSAGE_CHARACTERISTIC_UUID,
    indicationUUID: DEFAULT_DIDCOMM_INDICATE_CHARACTERISTIC_UUID,
  })

  /* On the peripheral agent
    await peripheral.setService({
      serviceUUID: uuid || DEFAULT_DIDCOMM_SERVICE_CHARACTERISTIC_UUID,
      messagingUUID: DEFAULT_DIDCOMM_MESSAGE_CHARACTERISTIC_UUID,
      indicationUUID: DEFAULT_DIDCOMM_INDICATE_CHARACTERISTIC_UUID
    })
  */

  // Registering the controller as a transport on the agent
  const bleInboundTransport = new BleInboundTransport(central) // const bleOutboundTransport = new BleOutboundTransport(peripheral)
  agent.registerInboundTransport(bleInboundTransport) // agent.registerOutboundTransport(bleOutboundTransport)

  await agent.initialize()

  return agent
}

// Inside your React Native app/component
const agent = await createAgent()