From 89a05b4b4a9947616d6b540a8806cf0de9245c6b Mon Sep 17 00:00:00 2001 From: Anirban Mukherjee <168822311+finoaamukherjee@users.noreply.github.com> Date: Wed, 14 Aug 2024 21:34:00 +0200 Subject: [PATCH] Integration of FinoaConnect wallet connector service into Web3Onboard (#2188) * impl: integration into existing package * Update packages/finoaconnect/package.json * Update packages/demo/package.json * Update .circleci/config.yml * fix: added comments and mock examplers in packages//README * chore: update comment on unhandled error * Update +page.md * Update README.md * Update packages/finoaconnect/README.md * Update docs/src/routes/docs/[...4]wallets/[...36]finoaconnect/+page.md * fix: renamed icon name to FinoaConnect and added finoaconnect to services/onboard for choice in dapp * fix: update typescript version in finoaconnect package * fix: all unsupported methods to return error code 4200 * chore: cleaned up commented code and unnecessary lock files * chore: removed unused code * fix: updated finoaconnect sdk version * Merge in upstream and yarn --------- Co-authored-by: Adam Carpenter --- .circleci/config.yml | 18 +++++ README.md | 1 + docs/src/lib/services/onboard.js | 5 ++ .../[...36]finoaconnect/+page.md | 57 +++++++++++++++ docs/yarn.lock | 14 ++++ packages/demo/package.json | 1 + packages/demo/src/App.svelte | 3 + packages/finoaconnect/README.md | 51 +++++++++++++ packages/finoaconnect/package.json | 66 +++++++++++++++++ packages/finoaconnect/src/icon.ts | 6 ++ packages/finoaconnect/src/index.ts | 72 +++++++++++++++++++ packages/finoaconnect/tsconfig.json | 15 ++++ yarn.lock | 5 ++ 13 files changed, 314 insertions(+) create mode 100644 docs/src/routes/docs/[...4]wallets/[...36]finoaconnect/+page.md create mode 100644 packages/finoaconnect/README.md create mode 100644 packages/finoaconnect/package.json create mode 100644 packages/finoaconnect/src/icon.ts create mode 100644 packages/finoaconnect/src/index.ts create mode 100644 packages/finoaconnect/tsconfig.json diff --git a/.circleci/config.yml b/.circleci/config.yml index aa511a3ff..84e7397fc 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -454,6 +454,12 @@ jobs: working_directory: ~/web3-onboard-monorepo/packages/particle-network steps: - node-build-steps + build-finoaconnect: + docker: + - image: cimg/node:18.0.0 + working_directory: ~/web3-onboard-monorepo/packages/finoaconnect + steps: + - node-build-steps build-wagmi: docker: - image: cimg/node:18.0.0 @@ -780,6 +786,12 @@ jobs: working_directory: ~/web3-onboard-monorepo/packages/bloom steps: - node-staging-build-steps + build-staging-finoaconnect: + docker: + - image: cimg/node:18.0.0 + working_directory: ~/web3-onboard-monorepo/packages/finoaconnect + steps: + - node-staging-build-steps workflows: version: 2 @@ -1091,3 +1103,9 @@ workflows: <<: *deploy_production_filters - build-staging-bloom: <<: *deploy_staging_filters + finoaconnect: + jobs: + - build-finoaconnect: + <<: *deploy_production_filters + - build-staging-finoaconnect: + <<: *deploy_staging_filters diff --git a/README.md b/README.md index d93baef3c..b483974f9 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,7 @@ For full documentation, check out the README.md for each package or the [docs pa - [Particle Network](packages/particle-network/README.md) - [MetaMask](packages/metamask/README.md) - [Bitget](packages/bitget/README.md) +- [FinoaConnect](packages/finoaconnect/README.md) **Hardware Wallets** diff --git a/docs/src/lib/services/onboard.js b/docs/src/lib/services/onboard.js index 987d7fa31..b57b0d9f2 100644 --- a/docs/src/lib/services/onboard.js +++ b/docs/src/lib/services/onboard.js @@ -59,6 +59,7 @@ const intiOnboard = async (theme) => { const { default: bloctoModule } = await import('@web3-onboard/blocto') const { default: venlyModule } = await import('@web3-onboard/venly') const { default: bitgetModule } = await import('@web3-onboard/bitget') + const { default: finoaConnectModule } = await import('@web3-onboard/finoaconnect') const { default: capsuleModule, Environment } = await import('@web3-onboard/capsule') const { default: particleAuthModule } = await import('@web3-onboard/particle-network') const INFURA_ID = '8b60d52405694345a99bcb82e722e0af' @@ -113,6 +114,9 @@ const intiOnboard = async (theme) => { } const trezor = trezorModule(trezorOptions) + const finoaConnectOptions = {}; + const finoaconnect = finoaConnectModule(finoaConnectOptions); + const uauthOptions = { clientID: 'a25c3a65-a1f2-46cc-a515-a46fe7acb78c', redirectUri: 'http://localhost:8080/', @@ -177,6 +181,7 @@ const intiOnboard = async (theme) => { blocto, particle, venly, + finoaconnect, capsule ], chains: [ diff --git a/docs/src/routes/docs/[...4]wallets/[...36]finoaconnect/+page.md b/docs/src/routes/docs/[...4]wallets/[...36]finoaconnect/+page.md new file mode 100644 index 000000000..555dca1cf --- /dev/null +++ b/docs/src/routes/docs/[...4]wallets/[...36]finoaconnect/+page.md @@ -0,0 +1,57 @@ +--- +title: FinoaConnect +--- + +## Wallet module for connecting FinoaConnect SDK to web3-onboard + +## Install + + + + +```sh copy +yarn add @web3-onboard/core @web3-onboard/finoaconnect +``` + + + + +```sh copy +npm install @web3-onboard/core @web3-onboard/finoaconnect +``` + + + + +## Usage + +Optional initialization object +```typescript +/** Optional object provided to the initiation of the wallet connector. + * When not included, the wallet connector service connects to FinoaConnect production systems. + * @field {url} URL of the FinoaConnect backend systems to be used + * @field {labelSuffix} arbitrary string label to denote the context of the URL field */ +export interface FinoaWalletOption { + url?: string + labelSuffix?: string +} +``` + +```typescript +import Onboard from '@web3-onboard/core' +import finoaConnectModule from '@web3-onboard/finoaconnect' + +// initialize the module with options +const finoaConnect = finoaConnectModule() + +const onboard = Onboard({ + // ... other Onboard options + wallets: [ + finoaConnect + //... other wallets + ] +}) + +const connectedWallets = await onboard.connectWallet() +console.log(connectedWallets) +``` diff --git a/docs/yarn.lock b/docs/yarn.lock index 379289a7c..5c045f94b 100644 --- a/docs/yarn.lock +++ b/docs/yarn.lock @@ -2544,6 +2544,20 @@ resolved "https://registry.yarnpkg.com/@metamask/safe-event-emitter/-/safe-event-emitter-3.1.1.tgz#e89b840a7af8097a8ed4953d8dc8470d1302d3ef" integrity sha512-ihb3B0T/wJm1eUuArYP4lCTSEoZsClHhuWyfo/kMX3m/odpqNcPfsz5O2A3NT7dXCAgWPGDQGPqygCpgeniKMw== +"@metamask/sdk-communication-layer@0.14.3": + version "0.14.3" + resolved "https://registry.yarnpkg.com/@metamask/sdk-communication-layer/-/sdk-communication-layer-0.14.3.tgz#0e7ec8e472641273da5802f3b357687ce12369c3" + integrity sha512-yjSbj8y7fFbQXv2HBzUX6D9C8BimkCYP6BDV7hdw53W8b/GlYCtXVxUFajQ9tuO1xPTRjR/xt/dkdr2aCi6WGw== + dependencies: + bufferutil "^4.0.8" + cross-fetch "^3.1.5" + date-fns "^2.29.3" + eciesjs "^0.3.16" + eventemitter2 "^6.4.5" + socket.io-client "^4.5.1" + utf-8-validate "^6.0.3" + uuid "^8.3.2" + "@metamask/sdk-communication-layer@0.20.2": version "0.20.2" resolved "https://registry.yarnpkg.com/@metamask/sdk-communication-layer/-/sdk-communication-layer-0.20.2.tgz#7f7fd334b2d26abd1a5a1ec1ffadf823a9589344" diff --git a/packages/demo/package.json b/packages/demo/package.json index 8daa719d7..8ab7ce6ea 100644 --- a/packages/demo/package.json +++ b/packages/demo/package.json @@ -38,6 +38,7 @@ "@web3-onboard/coinbase": "^2.4.1", "@web3-onboard/dcent": "^2.2.7", "@web3-onboard/enkrypt": "^2.1.1", + "@web3-onboard/finoaconnect": "2.0.0-alpha.1", "@web3-onboard/fortmatic": "^2.1.1", "@web3-onboard/frame": "^2.1.1", "@web3-onboard/frontier": "^2.1.1", diff --git a/packages/demo/src/App.svelte b/packages/demo/src/App.svelte index 2cd234f0e..cfbc5de47 100644 --- a/packages/demo/src/App.svelte +++ b/packages/demo/src/App.svelte @@ -38,6 +38,7 @@ import bitgetModule from '@web3-onboard/bitget' import bloomModule from '@web3-onboard/bloom' import particleAuthModule from '@web3-onboard/particle-network' + import finoaConnectModule from '@web3-onboard/finoaconnect' import keplrModule from '@web3-onboard/keplr' import capsuleModule, { Environment, @@ -228,6 +229,7 @@ fallbackProvider: '' // insert your alchemy / infura url here // encryptionSecret: '' // encryption secret is optional, but advised to securely store values in browser storage }) + const finoaConnect = finoaConnectModule() const trezorOptions = { email: 'test@test.com', @@ -325,6 +327,7 @@ venly, particle, passport, + finoaConnect, keplr ], transactionPreview, diff --git a/packages/finoaconnect/README.md b/packages/finoaconnect/README.md new file mode 100644 index 000000000..046db71ef --- /dev/null +++ b/packages/finoaconnect/README.md @@ -0,0 +1,51 @@ +# @web3-onboard/finoaconnect + +## Wallet module for connecting FinoaConnect SDK to web3-onboard + +#### Install + +`npm i @web3-onboard/core @web3-onboard/finoaconnect` + +## Usage + +Optional initialization object +```typescript +/** Optional object provided to the initiation of the wallet connector. + * When not included, the wallet connector service connects to FinoaConnect production systems. + * @field {url} URL of the FinoaConnect backend systems to be used + * @field {labelSuffix} arbitrary string label to denote the context of the URL field */ +export interface FinoaWalletOption { + url?: string + labelSuffix?: string +} +``` + +```typescript +import Onboard from '@web3-onboard/core'; +import finoaConnectModule from '@web3-onboard/finoaconnect'; + +const onboard = Onboard({ + // ... other Onboard options + wallets: [ + finoaConnectModule() + //... other wallets + ] +}) + +// alternatively to connect to a localised development environment +const onboard = Onboard({ + // ... other Onboard options + wallets: [ + finoaConnectModule([ + { + labelSuffix: 'localhost', + url: 'http://localhost:8080', + } + ]) + //... other wallets + ] +}) + +const connectedWallets = await onboard.connectWallet() +console.log(connectedWallets) +``` diff --git a/packages/finoaconnect/package.json b/packages/finoaconnect/package.json new file mode 100644 index 000000000..07ea10987 --- /dev/null +++ b/packages/finoaconnect/package.json @@ -0,0 +1,66 @@ +{ + "name": "@web3-onboard/finoaconnect", + "version": "2.0.0-alpha.1", + "description": "FinoaConnect enables DApp users to use Finoa's Institutional Custody services.", + "keywords": [ + "Ethereum", + "Web3", + "EVM", + "dapp", + "Multichain", + "Wallet", + "Transaction", + "Provider", + "Hardware Wallet", + "Notifications", + "React", + "Svelte", + "Vue", + "Next", + "Nuxt", + "MetaMask", + "Coinbase", + "WalletConnect", + "Ledger", + "Trezor", + "Connect Wallet", + "Ethereum Hooks", + "Blocknative", + "Mempool", + "pending", + "confirmed", + "Injected Wallet", + "Crypto", + "Crypto Wallet", + "Tally Ho", + "FinoaConnect" + ], + "repository": { + "type": "git", + "url": "https://github.com/blocknative/web3-onboard.git", + "directory": "packages/finoaconnect" + }, + "homepage": "https://onboard.blocknative.com", + "bugs": "https://github.com/blocknative/web3-onboard/issues", + "module": "dist/index.js", + "browser": "dist/index.js", + "main": "dist/index.js", + "type": "module", + "typings": "dist/index.d.ts", + "files": [ + "dist" + ], + "scripts": { + "build": "tsc", + "dev": "tsc -w", + "type-check": "tsc --noEmit" + }, + "devDependencies": { + "typescript": "^5.4.5" + }, + "dependencies": { + "@finoa/finoa-connect-sdk": "^1.0.4", + "@web3-onboard/core": "^2.20.4" + } + + } \ No newline at end of file diff --git a/packages/finoaconnect/src/icon.ts b/packages/finoaconnect/src/icon.ts new file mode 100644 index 000000000..2282313a8 --- /dev/null +++ b/packages/finoaconnect/src/icon.ts @@ -0,0 +1,6 @@ +export default ` + + + + +` \ No newline at end of file diff --git a/packages/finoaconnect/src/index.ts b/packages/finoaconnect/src/index.ts new file mode 100644 index 000000000..f49015a3c --- /dev/null +++ b/packages/finoaconnect/src/index.ts @@ -0,0 +1,72 @@ +import { FinoaEIP1193Provider } from '@finoa/finoa-connect-sdk' +import { ProviderRpcError, ProviderRpcErrorCode, type WalletInit } from '@web3-onboard/common' + +/** Optional object provided to the initiation of the wallet connector. + * When not included, the wallet connector service connects to FinoaConnect production systems. + * @field {url} URL of the FinoaConnect backend systems to be used + * @field {labelSuffix} arbitrary string label to denote the context of the URL field */ +export interface FinoaWalletOption { + url?: string + labelSuffix?: string +} + +function finoaConnect(option?: string | FinoaWalletOption): WalletInit { + const { url, labelSuffix }: FinoaWalletOption = + typeof option === 'string' ? { url: option } : !option ? {} : option + + return () => { + return { + label: `FinoaConnect${labelSuffix == null ? '' : ' - ' + labelSuffix}`, + getIcon: async () => (await import('./icon')).default, + getInterface: async ({ chains }) => { + const { + FinoaEIP1193Provider, + FinoaBrowserClient, + UnsupportedRequestError + } = await import('@finoa/finoa-connect-sdk') + + const client = new FinoaBrowserClient({ + windowUrl: url + }) + const provider = new FinoaEIP1193Provider({ + client + }) + + const proxyProvider = new Proxy(provider, { + get(target, property: keyof FinoaEIP1193Provider) { + const source = target[property] + if (property === 'request') { + return async function ( + this: FinoaEIP1193Provider, + ...args: Parameters + ) { + + try { + return await (source as FinoaEIP1193Provider['request']).call( + this, + ...args + ) + } catch (err) { + if (err instanceof UnsupportedRequestError) { + throw new ProviderRpcError({ + code: ProviderRpcErrorCode.UNSUPPORTED_METHOD, + message: `FinoaConnect Provider does not support the requested method: ${args[0].method}` + }) + } + throw err + } + } + } + return source + } + }) + + return { + provider: proxyProvider + } + } + } + } +} + +export default finoaConnect \ No newline at end of file diff --git a/packages/finoaconnect/tsconfig.json b/packages/finoaconnect/tsconfig.json new file mode 100644 index 000000000..ec0c86c1f --- /dev/null +++ b/packages/finoaconnect/tsconfig.json @@ -0,0 +1,15 @@ +{ + "extends": "../../tsconfig.json", + "include": ["src/**/*"], + + "compilerOptions": { + "outDir": "dist", + "rootDir": "src", + "declaration": true, + "declarationDir": "dist", + "allowSyntheticDefaultImports": true, + "paths": { + "*": ["./src/*", "./node_modules/*"] + } + } + } \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 0a8849011..8937cdbcb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1770,6 +1770,11 @@ dependencies: keccak "^3.0.0" +"@finoa/finoa-connect-sdk@^1.0.4": + version "1.0.5" + resolved "https://registry.yarnpkg.com/@finoa/finoa-connect-sdk/-/finoa-connect-sdk-1.0.5.tgz#95e9707a8382e8c80b44342aa49e74b07eb04e28" + integrity sha512-Dzp8fCZVODtG+xirXjy7JFAqvOgU9fRMFISiUr5N53XW+hsOsjYTi7IO/HApoXSAq9vFtVw7CMHG2+M0PlX+wg== + "@formatjs/ecma402-abstract@1.11.3": version "1.11.3" resolved "https://registry.yarnpkg.com/@formatjs/ecma402-abstract/-/ecma402-abstract-1.11.3.tgz#f25276dfd4ef3dac90da667c3961d8aa9732e384"