Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fcl] Adds WalletConnect Adapter Package and support for client plugin services #1352

Merged
merged 80 commits into from
Aug 23, 2022

Conversation

gregsantos
Copy link
Contributor

@gregsantos gregsantos commented Aug 8, 2022

In order to add support for WalletConnect and other client configured authentication services, FCL can use a service plugin registry or config to extend it's service methods. Client configured services, including extensions and plugins can be sent to Discovery for display and selection by the user.

import * as fcl from '@onflow/fcl'
import { initFclWc } from '@onflow/fcl-wc'

const { FclConnectServicePlugin, client } = await initFclWc({
  projectId: PROJECT_ID
})

fcl.pluginRegistry.add(FclConnectServicePlugin)

A Discovery Service Plugin should be an object consist of a name: String, type: String, discoveryServices: Array.
Each service needs a service definition of f_type: "Service" and a corresponding service strategy for the service definition's Method.
A Service strategy should return a function that returns a Promise that resolves to a PollingResponse.

name: "fcl-service-walletconnect",
type: "discovery-service",
dicoveryServices: [
    {
      definition: {
        f_type: "Service",
        f_vsn: "1.0.0",
        type: "authn",
        method: "WC/RPC",
        uid: "wc#authn",
        endpoint: "flow_authn",
        optIn: false,
        provider: {
          address: "WalletConnect",
          name: "WalletConnect",
          uid: null,
          icon: "https://avatars.githubusercontent.com/u/37784886",
          description: "WalletConnect Generic Provider",
          website: "https://walletconnect.com/",
          color: null,
          supportEmail: null,
        },
      },
      strategy: Promise,
    }

pluginRegistry.add will accept one or an array of plugins of type "discovery-service"

Greg Santos added 30 commits August 2, 2022 09:28
@gregsantos gregsantos force-pushed the gsantos/wc-service-plugin branch from f497e0d to 0a77bea Compare August 22, 2022 18:39
@gregsantos gregsantos changed the title [fcl] Adds support for client plugin services [fcl] Adds WalletConnect Adapter Package and support for client plugin services Aug 22, 2022
packages/fcl-wc/src/service.js Show resolved Hide resolved
packages/fcl-wc/src/service.js Outdated Show resolved Hide resolved
@gregsantos
Copy link
Contributor Author

@JeffreyDoyle We need the topic id from an existing paired wallet. This topic is sent with the wallet connect request, to skip QR code.
I added it to a new field on the generated service -> provider.uid
This should work, but we also need each service generated to have a different address I think.

packages/fcl-wc/src/service.js Outdated Show resolved Hide resolved
@gregsantos gregsantos dismissed stale reviews from chasefleming and JeffreyDoyle August 23, 2022 00:09

resolved for alpha

@gregsantos gregsantos merged commit e33fa8d into master Aug 23, 2022
@gregsantos gregsantos deleted the gsantos/wc-service-plugin branch August 23, 2022 00:09
huyndo pushed a commit that referenced this pull request Sep 24, 2022
…n services (#1352)

* PKG -- [fcl-wc] Create pkg, add WC deps

* PKG -- [fcl-wc] Add init, wc utils

* PKG -- [fcl-wc] Update wc beta, add fcl-bundle

* PKG -- [fcl-wc] Remove default WalletConnect projectId

* PKG -- [fcl-wc] Add README

* PKG -- [fcl-wc] Update to WalletConnect 2.0.0-beta.102

* PKG -- [fcl-wc] Update jest version

* PKG -- [fcl-js] Add wc-rpc strategy

* PKG -- [fcl-js] Add wc pairings to execService config

* PKG -- [fcl-js] Normalize data sent in client request

* PKG -- [fcl-js] Update request to switch on service.endpoint

* PKG -- [fcl-js] Add case for flow_user_sign endpoint

* PKG -- [fcl-js] Remove switch and set chainId

* PKG -- [fcl-js] Add fallback for config.get client

* PKG -- [fcl-wc] Create pkg, add WC deps

* PKG -- [fcl-wc] Add init, wc utils

* PKG -- [fcl-wc] Update wc beta, add fcl-bundle

* PKG -- [fcl-wc] Remove default WalletConnect projectId

* PKG -- [fcl-wc] Add README

* PKG -- [fcl-wc] Update to WalletConnect 2.0.0-beta.102

* PKG -- [fcl-wc] Update jest version

* PKG -- [fcl-wc] Update Walletconnect to 2.0.0-rc.0

* PKG -- [fcl] add default client on exec discovery config

* PKG -- [fcl-js] Add discoveryServices to execService, remove wc pairings

* PKG -- [fcl-wc] Add servicePlugin

* PKG -- [fcl-wc] Add servicePlugin

* PKG -- [fcl-wc] update service def and strategy

* PKG -- [fcl-wc] add fcl config and full service strategy

* PKG -- [fcl] update service strategy args to obj, remove client

* PKG -- [fcl] move config to authn, remove client.extensions

* PKG -- [fcl] add execStrategy and service registry

* PKG -- [fcl-wc] update service with qrcode modal, remove @onflow/config

* PKG -- [fcl] add WC/RPC back to core strategies

* PKG -- [fcl] add plugin registry and wire up in execService

* PKG -- [fcl] update plugin registry to new service format

* PKG -- [fcl-wc] update service name and combine definition with strategy

* PKG -- [fcl] remove wc-rpc, replaced with plugin strategy

* PKG -- [fcl-wc] update README

* PKG -- [fcl-wc] add better-sqlite3, update package-lock.json

* PKG -- [fcl-wc] add better-sqlite3 as dev dep

* PKG -- [fcl] update supported plugins and setServices method to remove dupe

* PKG -- [fcl-wc] update Service name and type

* PKG -- [fcl-wc] update init client test

* PKG -- [fcl-wc] update walletconnect deps to rc.0

* PKG -- [fcl-wc] update walletconnect to 2.0.0-rc.2

* PKG -- [root] update package-lock.json

* PKG -- [root] merge master and update package-lock.json

* PKG -- [fcl-wc] update pairing and service provider address to placeholder,

* PKG -- [fcl-wc] add network from config

* PKG -- [fcl-wc] add util-logger

* PKG -- [fcl] add plugin validation

* PKG -- [fcl] add client services to discovery api

* PKG -- [fcl] add logger to discovery authn

* PKG -- [fcl] update naming of discoveryServices to clientServices

* PKG -- [root] update changeset for fcl-wc

* PKG -- [fcl-wc] add provider.uid to service and use as pairing topic

* PKG -- [fcl] move makeDiscoveryServices to discovery utils

* PKG -- [fcl-wc] update servicePlugin fiel from services to discoveryServices

* PKG -- [fcl] add validation

* PKG -- [fcl-wc] add util-logger to service strategy

* PKG -- [fcl-wc] update isMobile util to include iPad

* PKG -- [fcl-wc] add f_type to service plugin

* PKG -- [fcl] add validation for ServicePlugin f_type

* PKG -- [fcl-wc] change pairing service provider.address to null

* PKG -- [fcl-wc] update console.logs to use logger

* PKG -- [fcl-wc] update version for alpha release
@github-actions github-actions bot mentioned this pull request Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants