From 3ae27aa7ee827b2f58a476a8e3b61a9ef72f7a9f Mon Sep 17 00:00:00 2001 From: Vincent Shadbolt Date: Fri, 21 Oct 2022 16:31:46 -0700 Subject: [PATCH 01/21] Added uauth as available login option --- packages/demo/package.json | 1 + packages/demo/src/App.svelte | 10 +- packages/injected/src/icons/core.ts | 2 +- packages/uauth/README.md | 62 ++++++ packages/uauth/package.json | 71 ++++++ packages/uauth/src/icon.ts | 10 + packages/uauth/src/index.ts | 328 ++++++++++++++++++++++++++++ packages/uauth/tsconfig.json | 14 ++ 8 files changed, 496 insertions(+), 2 deletions(-) create mode 100644 packages/uauth/README.md create mode 100644 packages/uauth/package.json create mode 100644 packages/uauth/src/icon.ts create mode 100644 packages/uauth/src/index.ts create mode 100644 packages/uauth/tsconfig.json diff --git a/packages/demo/package.json b/packages/demo/package.json index 75cfad08a..c3cf8e21d 100644 --- a/packages/demo/package.json +++ b/packages/demo/package.json @@ -40,6 +40,7 @@ "@web3-onboard/tallyho": "^2.0.1", "@web3-onboard/walletconnect": "^2.1.3", "@web3-onboard/web3auth": "^2.1.3", + "@web3-onboard/uauth": "^1.0.0", "vconsole": "^3.9.5" }, "license": "MIT", diff --git a/packages/demo/src/App.svelte b/packages/demo/src/App.svelte index 95f3e3ea8..6fcf91ea2 100644 --- a/packages/demo/src/App.svelte +++ b/packages/demo/src/App.svelte @@ -17,6 +17,7 @@ import dcentModule from '@web3-onboard/dcent' import sequenceModule from '@web3-onboard/sequence' import tallyHoModule from '@web3-onboard/tallyho' + import uauthModule from '@web3-onboard/uauth' import { recoverAddress, arrayify, @@ -96,6 +97,12 @@ } const trezor = trezorModule(trezorOptions) + const uauthOptions = { + clientID: "a25c3a65-a1f2-46cc-a515-a46fe7acb78c", + redirectUri: "http://localhost:8080/", +} + const uauth = uauthModule(uauthOptions) + const magic = magicModule({ apiKey: 'pk_live_02207D744E81C2BA' // userEmail: 'test@test.com' @@ -124,7 +131,8 @@ gnosis, dcent, sequence, - tallyho + tallyho, + uauth ], gas, chains: [ diff --git a/packages/injected/src/icons/core.ts b/packages/injected/src/icons/core.ts index 5b8b28927..d08b6b45e 100644 --- a/packages/injected/src/icons/core.ts +++ b/packages/injected/src/icons/core.ts @@ -1,4 +1,4 @@ export default ` -` \ No newline at end of file +` diff --git a/packages/uauth/README.md b/packages/uauth/README.md new file mode 100644 index 000000000..f3bb7ae8a --- /dev/null +++ b/packages/uauth/README.md @@ -0,0 +1,62 @@ +# @web3-onboard/walletconnect + +## Wallet module for connecting Ledger hardware wallets to web3-onboard + +### Install + +`npm i @web3-onboard/uauth` + +## Options + +Follow the [Login Client Congifuration Docs](https://docs.unstoppabledomains.com/login-with-unstoppable/login-integration-guides/login-client-configuration/) on the Unstoppable Domains website to get setup with your clientID and redirectUri. + +```typescript +interface uauthOptions { + clientID: string + redirectUri: string + scope?: string // openid and wallet are required and are the default scopes + shouldLoginWithRedirect?: boolean + bridge?: string // default = 'https://bridge.walletconnect.org' + qrcodeModalOptions?: { + mobileLinks: string[] // set the order and list of mobile linking wallets + } + connectFirstChainId?: boolean // if true, connects to the first network chain provided +} +``` + +## Usage + +```typescript +import Onboard from '@web3-onboard/core' +import uauthModule from '@web3-onboard/uauth' + +// initialize the module with options +const uauth = uauthModule({ + clientID: "YOUR_CLIENT_ID", + redirectUri: "YOUR_REDIRECT_URI", + scope?: "YOUR_SCOPES",// openid and wallet are required and are the default scopes + bridge?: 'YOUR_CUSTOM_BRIDGE_SERVER', + qrcodeModalOptions?: { + mobileLinks: ['rainbow', 'metamask', 'argent', 'trust', 'imtoken', 'pillar'] + }, + connectFirstChainId?: true +}) + +// can also initialize with basic options... +// const uauth = uauthModule({ +// clientID: "YOUR_CLIENT_ID", +// redirectUri: "YOUR_REDIRECT_URI" +// }) + + +const onboard = Onboard({ + // ... other Onboard options + wallets: [ + uauth + //... other wallets + ] +}) + +const connectedWallets = await onboard.connectWallet() +console.log(connectedWallets) +``` diff --git a/packages/uauth/package.json b/packages/uauth/package.json new file mode 100644 index 000000000..1c9e2a19d --- /dev/null +++ b/packages/uauth/package.json @@ -0,0 +1,71 @@ +{ + "name": "@web3-onboard/uauth", + "version": "1.0.0", + "description": "UAuth SDK module for connecting to Web3-Onboard. Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardised spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.", + "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", + "Domain Name", + "Unstoppable Domains", + "Unstoppable" + ], + "repository": { + "type": "git", + "url": "https://github.com/blocknative/web3-onboard.git", + "directory": "packages/uauth" + }, + "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" + }, + "license": "MIT", + "devDependencies": { + "typescript": "^4.5.5" + }, + "dependencies": { + "@uauth/js": "^2.4.0", + "@ethersproject/providers": "^5.5.0", + "@walletconnect/client": "^1.7.1", + "@walletconnect/qrcode-modal": "^1.7.1", + "@web3-onboard/common": "^2.2.3", + "rxjs": "^7.5.2" + } +} diff --git a/packages/uauth/src/icon.ts b/packages/uauth/src/icon.ts new file mode 100644 index 000000000..c1d370754 --- /dev/null +++ b/packages/uauth/src/icon.ts @@ -0,0 +1,10 @@ +export default ` + + + +` diff --git a/packages/uauth/src/index.ts b/packages/uauth/src/index.ts new file mode 100644 index 000000000..c242329e9 --- /dev/null +++ b/packages/uauth/src/index.ts @@ -0,0 +1,328 @@ +/* eslint-disable @typescript-eslint/ban-ts-comment */ +import type { StaticJsonRpcProvider as StaticJsonRpcProviderType } from '@ethersproject/providers' +import UAuth from '@uauth/js' +import type { UserInfo } from '@uauth/js' +import { + WalletInit, + createEIP1193Provider, + EIP1193Provider, + Chain, + ProviderAccounts +} from '@web3-onboard/common' + +interface uauthOptions { + clientID: string + redirectUri: string + scope?: string + shouldLoginWithRedirect?: boolean + bridge?: string + qrcodeModalOptions?: { + mobileLinks: string[] + } + connectFirstChainId?: boolean +} + +function uauth(options: uauthOptions): WalletInit { + return () => { + const { + clientID, + redirectUri, + scope = 'openid wallet', + shouldLoginWithRedirect, + bridge = 'https://bridge.walletconnect.org', + qrcodeModalOptions, + connectFirstChainId + } = options || {} + + if (!clientID || !redirectUri) { + throw new Error( + 'Client ID and Redirect URI are required in uauth options for Unstoppable Connection' + ) + } + + return { + label: 'Unstoppable', + getIcon: async () => + '', + getInterface: async ({ chains, EventEmitter }) => { + const uauthInstance = new UAuth({ + clientID: clientID, + redirectUri: redirectUri, + scope: scope + }) + + let user: UserInfo + try { + user = await uauthInstance.user() + } catch (error) { + if (!uauthInstance.fallbackLoginOptions.scope.includes('wallet')) { + throw new Error( + 'Must request the "wallet" scope for connector to work.' + ) + } + + if (shouldLoginWithRedirect) { + await uauthInstance.login() + // NOTE: We don't want to throw because the page will take some time to + // load the redirect page. + // eslint-disable-next-line @typescript-eslint/no-empty-function + await new Promise(() => {}) + // We need to throw here otherwise typescript won't know that user isn't null. + throw new Error('Should never get here.') + } else { + await uauthInstance.loginWithPopup() + user = await uauthInstance.user() + } + } + + if (!user.wallet_type_hint) { + throw new Error('no wallet type hint') + } + + // @ts-ignore + let provider: EIP1193Provider | EthProvider + + if (['web3', 'injected'].includes(user.wallet_type_hint)) { + provider = + (window as any).ethereum || + ((window as any).web3 && (window as any).web3.currentProvider) + provider = createEIP1193Provider(provider) + } else if (user.wallet_type_hint === 'walletconnect') { + const { StaticJsonRpcProvider } = await import( + '@ethersproject/providers' + ) + + const { ProviderRpcError, ProviderRpcErrorCode } = await import( + '@web3-onboard/common' + ) + + const { default: WalletConnect } = await import( + '@walletconnect/client' + ) + + // This is a cjs module and therefor depending on build tooling + // sometimes it will be nested in the { default } object and + // other times it will be the actual import + // @ts-ignore - It thinks it is missing properties since it expect it to be nested under default + let QRCodeModal: typeof import('@walletconnect/qrcode-modal').default = + await import('@walletconnect/qrcode-modal') + + // @ts-ignore - TS thinks that there is no default property on the `QRCodeModal` but sometimes there is + QRCodeModal = QRCodeModal.default || QRCodeModal + + const { Subject, fromEvent } = await import('rxjs') + const { takeUntil, take } = await import('rxjs/operators') + + const connector = new WalletConnect({ + bridge + }) + + const emitter = new EventEmitter() + + class EthProvider { + public request: EIP1193Provider['request'] + public connector: InstanceType + public chains: Chain[] + public disconnect: EIP1193Provider['disconnect'] + public emit: typeof EventEmitter['emit'] + public on: typeof EventEmitter['on'] + public removeListener: typeof EventEmitter['removeListener'] + + private disconnected$: InstanceType + private providers: Record + + constructor({ + connector, + chains + }: { + connector: InstanceType + chains: Chain[] + }) { + this.emit = emitter.emit.bind(emitter) + this.on = emitter.on.bind(emitter) + this.removeListener = emitter.removeListener.bind(emitter) + + this.connector = connector + this.chains = chains + this.disconnected$ = new Subject() + this.providers = {} + + // @ts-ignore listen for session updates + fromEvent(this.connector, 'session_update', (error, payload) => { + if (error) { + throw error + } + + return payload + }) + .pipe(takeUntil(this.disconnected$)) + .subscribe({ + next: ({ params }) => { + const [{ accounts, chainId }] = params + this.emit('accountsChanged', accounts) + this.emit('chainChanged', `0x${chainId.toString(16)}`) + }, + error: console.warn + }) + + // @ts-ignore listen for disconnect event + fromEvent(this.connector, 'disconnect', (error, payload) => { + if (error) { + throw error + } + + return payload + }) + .pipe(takeUntil(this.disconnected$)) + .subscribe({ + next: () => { + this.emit('accountsChanged', []) + this.disconnected$.next(true) + typeof localStorage !== 'undefined' && + localStorage.removeItem('walletconnect') + }, + error: console.warn + }) + + this.disconnect = () => this.connector.killSession() + + this.request = async ({ method, params }) => { + if (method === 'eth_chainId') { + return `0x${this.connector.chainId.toString(16)}` + } + + if (method === 'eth_requestAccounts') { + return new Promise((resolve, reject) => { + // Check if connection is already established + if (!this.connector.connected) { + // create new session + this.connector + .createSession( + connectFirstChainId + ? { chainId: parseInt(chains[0].id, 16) } + : undefined + ) + .then(() => { + QRCodeModal.open( + this.connector.uri, + () => + reject( + new ProviderRpcError({ + code: 4001, + message: 'User rejected the request.' + }) + ), + qrcodeModalOptions + ) + }) + } else { + const { accounts, chainId } = this.connector.session + this.emit('chainChanged', `0x${chainId.toString(16)}`) + return resolve(accounts) + } + + // @ts-ignore Subscribe to connection events + fromEvent(this.connector, 'connect', (error, payload) => { + if (error) { + throw error + } + + return payload + }) + .pipe(take(1)) + .subscribe({ + next: ({ params }) => { + const [{ accounts, chainId }] = params + this.emit('accountsChanged', accounts) + this.emit('chainChanged', `0x${chainId.toString(16)}`) + QRCodeModal.close() + resolve(accounts) + }, + error: reject + }) + }) + } + + if ( + method === 'wallet_switchEthereumChain' || + method === 'eth_selectAccounts' + ) { + throw new ProviderRpcError({ + code: ProviderRpcErrorCode.UNSUPPORTED_METHOD, + message: `The Provider does not support the requested method: ${method}` + }) + } + + // @ts-ignore + if (method === 'eth_sendTransaction') { + // @ts-ignore + return this.connector.sendTransaction(params[0]) + } + + // @ts-ignore + if (method === 'eth_signTransaction') { + // @ts-ignore + return this.connector.signTransaction(params[0]) + } + + // @ts-ignore + if (method === 'personal_sign') { + // @ts-ignore + return this.connector.signPersonalMessage(params) + } + + // @ts-ignore + if (method === 'eth_sign') { + // @ts-ignore + return this.connector.signMessage(params) + } + + // @ts-ignore + if (method.includes('eth_signTypedData')) { + // @ts-ignore + return this.connector.signTypedData(params) + } + + if (method === 'eth_accounts') { + return this.connector.sendCustomRequest({ + id: 1337, + jsonrpc: '2.0', + method, + params + }) + } + + const chainId = await this.request({ method: 'eth_chainId' }) + + if (!this.providers[chainId]) { + const currentChain = chains.find(({ id }) => id === chainId) + + if (!currentChain) { + throw new ProviderRpcError({ + code: ProviderRpcErrorCode.CHAIN_NOT_ADDED, + message: `The Provider does not have a rpcUrl to make a request for the requested method: ${method}` + }) + } + + this.providers[chainId] = new StaticJsonRpcProvider( + currentChain.rpcUrl + ) + } + + return this.providers[chainId].send( + method, + // @ts-ignore + params + ) + } + } + } + provider = new EthProvider({ chains, connector }) + } + return { provider: provider } + } + } + } +} + +export default uauth diff --git a/packages/uauth/tsconfig.json b/packages/uauth/tsconfig.json new file mode 100644 index 000000000..eb2bd2951 --- /dev/null +++ b/packages/uauth/tsconfig.json @@ -0,0 +1,14 @@ +{ + "extends": "../../tsconfig.json", + "include": ["src/**/*"], + + "compilerOptions": { + "outDir": "dist", + "rootDir": "src", + "declarationDir": "dist", + "paths": { + "*": ["./src/*", "./node_modules/*"] + }, + "typeRoots": ["node_modules/@types"] + } +} From fbc3afae7acea1aac2e8c75b7c8893da9735dfe8 Mon Sep 17 00:00:00 2001 From: Vincent Shadbolt Date: Fri, 21 Oct 2022 16:39:28 -0700 Subject: [PATCH 02/21] added uauth dependencies --- yarn.lock | 214 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 211 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index 83649787c..37cec1687 100644 --- a/yarn.lock +++ b/yarn.lock @@ -549,6 +549,21 @@ "@ethersproject/properties" "^5.6.0" "@ethersproject/strings" "^5.6.1" +"@ethersproject/abi@^5.0.1": + version "5.7.0" + resolved "https://registry.yarnpkg.com/@ethersproject/abi/-/abi-5.7.0.tgz#b3f3e045bbbeed1af3947335c247ad625a44e449" + integrity sha512-351ktp42TiRcYB3H1OP8yajPeAQstMW/yCFokj/AthP9bLHzQFPlOrxOcwYEDkUAICmOHljvN4K39OMTMUa9RA== + dependencies: + "@ethersproject/address" "^5.7.0" + "@ethersproject/bignumber" "^5.7.0" + "@ethersproject/bytes" "^5.7.0" + "@ethersproject/constants" "^5.7.0" + "@ethersproject/hash" "^5.7.0" + "@ethersproject/keccak256" "^5.7.0" + "@ethersproject/logger" "^5.7.0" + "@ethersproject/properties" "^5.7.0" + "@ethersproject/strings" "^5.7.0" + "@ethersproject/abstract-provider@5.5.1", "@ethersproject/abstract-provider@^5.5.0": version "5.5.1" resolved "https://registry.yarnpkg.com/@ethersproject/abstract-provider/-/abstract-provider-5.5.1.tgz#2f1f6e8a3ab7d378d8ad0b5718460f85649710c5" @@ -575,6 +590,19 @@ "@ethersproject/transactions" "^5.6.2" "@ethersproject/web" "^5.6.1" +"@ethersproject/abstract-provider@^5.7.0": + version "5.7.0" + resolved "https://registry.yarnpkg.com/@ethersproject/abstract-provider/-/abstract-provider-5.7.0.tgz#b0a8550f88b6bf9d51f90e4795d48294630cb9ef" + integrity sha512-R41c9UkchKCpAqStMYUpdunjo3pkEvZC3FAwZn5S5MGbXoMQOHIdHItezTETxAO5bevtMApSyEhn9+CHcDsWBw== + dependencies: + "@ethersproject/bignumber" "^5.7.0" + "@ethersproject/bytes" "^5.7.0" + "@ethersproject/logger" "^5.7.0" + "@ethersproject/networks" "^5.7.0" + "@ethersproject/properties" "^5.7.0" + "@ethersproject/transactions" "^5.7.0" + "@ethersproject/web" "^5.7.0" + "@ethersproject/abstract-signer@5.5.0", "@ethersproject/abstract-signer@^5.5.0": version "5.5.0" resolved "https://registry.yarnpkg.com/@ethersproject/abstract-signer/-/abstract-signer-5.5.0.tgz#590ff6693370c60ae376bf1c7ada59eb2a8dd08d" @@ -597,6 +625,17 @@ "@ethersproject/logger" "^5.6.0" "@ethersproject/properties" "^5.6.0" +"@ethersproject/abstract-signer@^5.7.0": + version "5.7.0" + resolved "https://registry.yarnpkg.com/@ethersproject/abstract-signer/-/abstract-signer-5.7.0.tgz#13f4f32117868452191a4649723cb086d2b596b2" + integrity sha512-a16V8bq1/Cz+TGCkE2OPMTOUDLS3grCpdjoJCYNnVBbdYEMSgKrU0+B90s8b6H+ByYTBZN7a3g76jdIJi7UfKQ== + dependencies: + "@ethersproject/abstract-provider" "^5.7.0" + "@ethersproject/bignumber" "^5.7.0" + "@ethersproject/bytes" "^5.7.0" + "@ethersproject/logger" "^5.7.0" + "@ethersproject/properties" "^5.7.0" + "@ethersproject/address@5.5.0", "@ethersproject/address@^5.0.4", "@ethersproject/address@^5.5.0": version "5.5.0" resolved "https://registry.yarnpkg.com/@ethersproject/address/-/address-5.5.0.tgz#bcc6f576a553f21f3dd7ba17248f81b473c9c78f" @@ -619,6 +658,17 @@ "@ethersproject/logger" "^5.6.0" "@ethersproject/rlp" "^5.6.1" +"@ethersproject/address@^5.7.0": + version "5.7.0" + resolved "https://registry.yarnpkg.com/@ethersproject/address/-/address-5.7.0.tgz#19b56c4d74a3b0a46bfdbb6cfcc0a153fc697f37" + integrity sha512-9wYhYt7aghVGo758POM5nqcOMaE168Q6aRLJZwUmiqSrAungkG74gSSeKEIR7ukixesdRZGPgVqme6vmxs1fkA== + dependencies: + "@ethersproject/bignumber" "^5.7.0" + "@ethersproject/bytes" "^5.7.0" + "@ethersproject/keccak256" "^5.7.0" + "@ethersproject/logger" "^5.7.0" + "@ethersproject/rlp" "^5.7.0" + "@ethersproject/base64@5.5.0", "@ethersproject/base64@^5.5.0": version "5.5.0" resolved "https://registry.yarnpkg.com/@ethersproject/base64/-/base64-5.5.0.tgz#881e8544e47ed976930836986e5eb8fab259c090" @@ -633,6 +683,13 @@ dependencies: "@ethersproject/bytes" "^5.6.1" +"@ethersproject/base64@^5.7.0": + version "5.7.0" + resolved "https://registry.yarnpkg.com/@ethersproject/base64/-/base64-5.7.0.tgz#ac4ee92aa36c1628173e221d0d01f53692059e1c" + integrity sha512-Dr8tcHt2mEbsZr/mwTPIQAf3Ai0Bks/7gTw9dSqk1mQvhW3XvRlmDJr/4n+wg1JmCl16NZue17CDh8xb/vZ0sQ== + dependencies: + "@ethersproject/bytes" "^5.7.0" + "@ethersproject/basex@5.5.0", "@ethersproject/basex@^5.5.0": version "5.5.0" resolved "https://registry.yarnpkg.com/@ethersproject/basex/-/basex-5.5.0.tgz#e40a53ae6d6b09ab4d977bd037010d4bed21b4d3" @@ -667,6 +724,15 @@ "@ethersproject/logger" "^5.6.0" bn.js "^5.2.1" +"@ethersproject/bignumber@^5.7.0": + version "5.7.0" + resolved "https://registry.yarnpkg.com/@ethersproject/bignumber/-/bignumber-5.7.0.tgz#e2f03837f268ba655ffba03a57853e18a18dc9c2" + integrity sha512-n1CAdIHRWjSucQO3MC1zPSVgV/6dy/fjL9pMrPP9peL+QxEg9wOsVqwD4+818B6LUEtaXzVHQiuivzRoxPxUGw== + dependencies: + "@ethersproject/bytes" "^5.7.0" + "@ethersproject/logger" "^5.7.0" + bn.js "^5.2.1" + "@ethersproject/bytes@5.5.0", "@ethersproject/bytes@^5.0.4", "@ethersproject/bytes@^5.5.0": version "5.5.0" resolved "https://registry.yarnpkg.com/@ethersproject/bytes/-/bytes-5.5.0.tgz#cb11c526de657e7b45d2e0f0246fb3b9d29a601c" @@ -681,6 +747,13 @@ dependencies: "@ethersproject/logger" "^5.6.0" +"@ethersproject/bytes@^5.7.0": + version "5.7.0" + resolved "https://registry.yarnpkg.com/@ethersproject/bytes/-/bytes-5.7.0.tgz#a00f6ea8d7e7534d6d87f47188af1148d71f155d" + integrity sha512-nsbxwgFXWh9NyYWo+U8atvmMsSdKJprTcICAkvbBffT75qDocbuggBU0SJiVK2MuTrp0q+xvLkTnGMPK1+uA9A== + dependencies: + "@ethersproject/logger" "^5.7.0" + "@ethersproject/constants@5.5.0", "@ethersproject/constants@^5.0.4", "@ethersproject/constants@^5.5.0": version "5.5.0" resolved "https://registry.yarnpkg.com/@ethersproject/constants/-/constants-5.5.0.tgz#d2a2cd7d94bd1d58377d1d66c4f53c9be4d0a45e" @@ -695,6 +768,13 @@ dependencies: "@ethersproject/bignumber" "^5.6.2" +"@ethersproject/constants@^5.7.0": + version "5.7.0" + resolved "https://registry.yarnpkg.com/@ethersproject/constants/-/constants-5.7.0.tgz#df80a9705a7e08984161f09014ea012d1c75295e" + integrity sha512-DHI+y5dBNvkpYUMiRQyxRBYBefZkJfo70VUkUAsRjcPs47muV9evftfZ0PJVCXYbAiCgght0DtcF9srFQmIgWA== + dependencies: + "@ethersproject/bignumber" "^5.7.0" + "@ethersproject/contracts@5.5.0": version "5.5.0" resolved "https://registry.yarnpkg.com/@ethersproject/contracts/-/contracts-5.5.0.tgz#b735260d4bd61283a670a82d5275e2a38892c197" @@ -755,6 +835,21 @@ "@ethersproject/properties" "^5.6.0" "@ethersproject/strings" "^5.6.1" +"@ethersproject/hash@^5.7.0": + version "5.7.0" + resolved "https://registry.yarnpkg.com/@ethersproject/hash/-/hash-5.7.0.tgz#eb7aca84a588508369562e16e514b539ba5240a7" + integrity sha512-qX5WrQfnah1EFnO5zJv1v46a8HW0+E5xuBBDTwMFZLuVTx0tbU2kkx15NqdjxecrLGatQN9FGQKpb1FKdHCt+g== + dependencies: + "@ethersproject/abstract-signer" "^5.7.0" + "@ethersproject/address" "^5.7.0" + "@ethersproject/base64" "^5.7.0" + "@ethersproject/bignumber" "^5.7.0" + "@ethersproject/bytes" "^5.7.0" + "@ethersproject/keccak256" "^5.7.0" + "@ethersproject/logger" "^5.7.0" + "@ethersproject/properties" "^5.7.0" + "@ethersproject/strings" "^5.7.0" + "@ethersproject/hdnode@5.5.0", "@ethersproject/hdnode@^5.5.0": version "5.5.0" resolved "https://registry.yarnpkg.com/@ethersproject/hdnode/-/hdnode-5.5.0.tgz#4a04e28f41c546f7c978528ea1575206a200ddf6" @@ -845,6 +940,14 @@ "@ethersproject/bytes" "^5.6.1" js-sha3 "0.8.0" +"@ethersproject/keccak256@^5.7.0": + version "5.7.0" + resolved "https://registry.yarnpkg.com/@ethersproject/keccak256/-/keccak256-5.7.0.tgz#3186350c6e1cd6aba7940384ec7d6d9db01f335a" + integrity sha512-2UcPboeL/iW+pSg6vZ6ydF8tCnv3Iu/8tUmLLzWWGzxWKFFqOBQFLo6uLUv6BDrLgCDfN28RJ/wtByx+jZ4KBg== + dependencies: + "@ethersproject/bytes" "^5.7.0" + js-sha3 "0.8.0" + "@ethersproject/logger@5.5.0", "@ethersproject/logger@^5.0.5", "@ethersproject/logger@^5.5.0": version "5.5.0" resolved "https://registry.yarnpkg.com/@ethersproject/logger/-/logger-5.5.0.tgz#0c2caebeff98e10aefa5aef27d7441c7fd18cf5d" @@ -855,6 +958,11 @@ resolved "https://registry.yarnpkg.com/@ethersproject/logger/-/logger-5.6.0.tgz#d7db1bfcc22fd2e4ab574cba0bb6ad779a9a3e7a" integrity sha512-BiBWllUROH9w+P21RzoxJKzqoqpkyM1pRnEKG69bulE9TSQD8SAIvTQqIMZmmCO8pUNkgLP1wndX1gKghSpBmg== +"@ethersproject/logger@^5.7.0": + version "5.7.0" + resolved "https://registry.yarnpkg.com/@ethersproject/logger/-/logger-5.7.0.tgz#6ce9ae168e74fecf287be17062b590852c311892" + integrity sha512-0odtFdXu/XHtjQXJYA3u9G0G8btm0ND5Cu8M7i5vhEcE8/HmF4Lbdqanwyv4uQTr2tx6b7fQRmgLrsnpQlmnig== + "@ethersproject/networks@5.5.2", "@ethersproject/networks@^5.5.0": version "5.5.2" resolved "https://registry.yarnpkg.com/@ethersproject/networks/-/networks-5.5.2.tgz#784c8b1283cd2a931114ab428dae1bd00c07630b" @@ -869,6 +977,13 @@ dependencies: "@ethersproject/logger" "^5.6.0" +"@ethersproject/networks@^5.7.0": + version "5.7.1" + resolved "https://registry.yarnpkg.com/@ethersproject/networks/-/networks-5.7.1.tgz#118e1a981d757d45ccea6bb58d9fd3d9db14ead6" + integrity sha512-n/MufjFYv3yFcUyfhnXotyDlNdFb7onmkSy8aQERi2PjNcnWQ66xXxa3XlS8nCcA8aJKJjIIMNJTC7tu80GwpQ== + dependencies: + "@ethersproject/logger" "^5.7.0" + "@ethersproject/pbkdf2@5.5.0", "@ethersproject/pbkdf2@^5.5.0": version "5.5.0" resolved "https://registry.yarnpkg.com/@ethersproject/pbkdf2/-/pbkdf2-5.5.0.tgz#e25032cdf02f31505d47afbf9c3e000d95c4a050" @@ -899,6 +1014,13 @@ dependencies: "@ethersproject/logger" "^5.6.0" +"@ethersproject/properties@^5.7.0": + version "5.7.0" + resolved "https://registry.yarnpkg.com/@ethersproject/properties/-/properties-5.7.0.tgz#a6e12cb0439b878aaf470f1902a176033067ed30" + integrity sha512-J87jy8suntrAkIZtecpxEPxY//szqr1mlBaYlQ0r4RCaiD2hjheqF9s1LVE8vVuJCXisjIP+JgtK/Do54ej4Sw== + dependencies: + "@ethersproject/logger" "^5.7.0" + "@ethersproject/providers@5.5.2": version "5.5.2" resolved "https://registry.yarnpkg.com/@ethersproject/providers/-/providers-5.5.2.tgz#131ccf52dc17afd0ab69ed444b8c0e3a27297d99" @@ -1007,6 +1129,14 @@ "@ethersproject/bytes" "^5.6.1" "@ethersproject/logger" "^5.6.0" +"@ethersproject/rlp@^5.7.0": + version "5.7.0" + resolved "https://registry.yarnpkg.com/@ethersproject/rlp/-/rlp-5.7.0.tgz#de39e4d5918b9d74d46de93af80b7685a9c21304" + integrity sha512-rBxzX2vK8mVF7b0Tol44t5Tb8gomOHkj5guL+HhzQ1yBh/ydjGnpw6at+X6Iw0Kp3OzzzkcKp8N9r0W4kYSs9w== + dependencies: + "@ethersproject/bytes" "^5.7.0" + "@ethersproject/logger" "^5.7.0" + "@ethersproject/sha2@5.5.0", "@ethersproject/sha2@^5.5.0": version "5.5.0" resolved "https://registry.yarnpkg.com/@ethersproject/sha2/-/sha2-5.5.0.tgz#a40a054c61f98fd9eee99af2c3cc6ff57ec24db7" @@ -1049,6 +1179,18 @@ elliptic "6.5.4" hash.js "1.1.7" +"@ethersproject/signing-key@^5.7.0": + version "5.7.0" + resolved "https://registry.yarnpkg.com/@ethersproject/signing-key/-/signing-key-5.7.0.tgz#06b2df39411b00bc57c7c09b01d1e41cf1b16ab3" + integrity sha512-MZdy2nL3wO0u7gkB4nA/pEf8lu1TlFswPNmy8AiYkfKTdO6eXBJyUdmHO/ehm/htHw9K/qF8ujnTyUAD+Ry54Q== + dependencies: + "@ethersproject/bytes" "^5.7.0" + "@ethersproject/logger" "^5.7.0" + "@ethersproject/properties" "^5.7.0" + bn.js "^5.2.1" + elliptic "6.5.4" + hash.js "1.1.7" + "@ethersproject/solidity@5.5.0": version "5.5.0" resolved "https://registry.yarnpkg.com/@ethersproject/solidity/-/solidity-5.5.0.tgz#2662eb3e5da471b85a20531e420054278362f93f" @@ -1091,6 +1233,15 @@ "@ethersproject/constants" "^5.6.1" "@ethersproject/logger" "^5.6.0" +"@ethersproject/strings@^5.7.0": + version "5.7.0" + resolved "https://registry.yarnpkg.com/@ethersproject/strings/-/strings-5.7.0.tgz#54c9d2a7c57ae8f1205c88a9d3a56471e14d5ed2" + integrity sha512-/9nu+lj0YswRNSH0NXYqrh8775XNyEdUQAuf3f+SmOrnVewcJ5SBNAjF7lpgehKi4abvNNXyf+HX86czCdJ8Mg== + dependencies: + "@ethersproject/bytes" "^5.7.0" + "@ethersproject/constants" "^5.7.0" + "@ethersproject/logger" "^5.7.0" + "@ethersproject/transactions@5.5.0", "@ethersproject/transactions@^5.0.0-beta.135", "@ethersproject/transactions@^5.5.0": version "5.5.0" resolved "https://registry.yarnpkg.com/@ethersproject/transactions/-/transactions-5.5.0.tgz#7e9bf72e97bcdf69db34fe0d59e2f4203c7a2908" @@ -1121,6 +1272,21 @@ "@ethersproject/rlp" "^5.6.1" "@ethersproject/signing-key" "^5.6.2" +"@ethersproject/transactions@^5.7.0": + version "5.7.0" + resolved "https://registry.yarnpkg.com/@ethersproject/transactions/-/transactions-5.7.0.tgz#91318fc24063e057885a6af13fdb703e1f993d3b" + integrity sha512-kmcNicCp1lp8qanMTC3RIikGgoJ80ztTyvtsFvCYpSCfkjhD0jZ2LOrnbcuxuToLIUYYf+4XwD1rP+B/erDIhQ== + dependencies: + "@ethersproject/address" "^5.7.0" + "@ethersproject/bignumber" "^5.7.0" + "@ethersproject/bytes" "^5.7.0" + "@ethersproject/constants" "^5.7.0" + "@ethersproject/keccak256" "^5.7.0" + "@ethersproject/logger" "^5.7.0" + "@ethersproject/properties" "^5.7.0" + "@ethersproject/rlp" "^5.7.0" + "@ethersproject/signing-key" "^5.7.0" + "@ethersproject/units@5.5.0": version "5.5.0" resolved "https://registry.yarnpkg.com/@ethersproject/units/-/units-5.5.0.tgz#104d02db5b5dc42cc672cc4587bafb87a95ee45e" @@ -1203,6 +1369,17 @@ "@ethersproject/properties" "^5.6.0" "@ethersproject/strings" "^5.6.1" +"@ethersproject/web@^5.7.0": + version "5.7.1" + resolved "https://registry.yarnpkg.com/@ethersproject/web/-/web-5.7.1.tgz#de1f285b373149bee5928f4eb7bcb87ee5fbb4ae" + integrity sha512-Gueu8lSvyjBWL4cYsWsjh6MtMwM0+H4HvqFPZfB6dV8ctbP9zFAO73VG1cMWae0FLPCtz0peKPpZY8/ugJJX2w== + dependencies: + "@ethersproject/base64" "^5.7.0" + "@ethersproject/bytes" "^5.7.0" + "@ethersproject/logger" "^5.7.0" + "@ethersproject/properties" "^5.7.0" + "@ethersproject/strings" "^5.7.0" + "@ethersproject/wordlists@5.5.0", "@ethersproject/wordlists@^5.5.0": version "5.5.0" resolved "https://registry.yarnpkg.com/@ethersproject/wordlists/-/wordlists-5.5.0.tgz#aac74963aa43e643638e5172353d931b347d584f" @@ -2585,6 +2762,32 @@ "@typescript-eslint/types" "4.33.0" eslint-visitor-keys "^2.0.0" +"@uauth/common@2.3.0": + version "2.3.0" + resolved "https://registry.yarnpkg.com/@uauth/common/-/common-2.3.0.tgz#de0018503614e993af9f6373983bc53828bf9b80" + integrity sha512-RuRYd8UgVN1eotoZjj2YhgHHP7PlEGxPEKSqUbmtJYumb6DLrlR0HNRF+wM8LQz/x4SBBo+hdm0ueC5bAHcXBg== + +"@uauth/js@^2.4.0": + version "2.4.0" + resolved "https://registry.yarnpkg.com/@uauth/js/-/js-2.4.0.tgz#f69d3221f560b0984955432f6de5e6eb089f36a6" + integrity sha512-KYWnEa2+Waa216TNhKmd1M78A8VnEjL6TbfaFHUKtixzKHYMYPIGj3zrD2Am3KHKIyq3bP11++ozoos6551Qrw== + dependencies: + "@uauth/common" "2.3.0" + "@unstoppabledomains/resolution" "^8.0" + global "^4.4.0" + jose "^4.5.0" + +"@unstoppabledomains/resolution@^8.0": + version "8.3.3" + resolved "https://registry.yarnpkg.com/@unstoppabledomains/resolution/-/resolution-8.3.3.tgz#599c5e2f068a36e24bd19c0f9e2f753036264a3b" + integrity sha512-jQ9757Lvx/xqU7Lg7JT4L9WQZuElHkMiJmtph0e6TSwfguIlkv1i5UgzURgVXDvVizVKpDejGS60kuvICkz9ZQ== + dependencies: + "@ethersproject/abi" "^5.0.1" + bn.js "^4.4.0" + cross-fetch "^3.1.4" + crypto-js "^4.1.1" + elliptic "^6.5.4" + "@vue/compiler-core@3.2.31": version "3.2.31" resolved "https://registry.yarnpkg.com/@vue/compiler-core/-/compiler-core-3.2.31.tgz#d38f06c2cf845742403b523ab4596a3fda152e89" @@ -3882,7 +4085,7 @@ bn.js@4.11.8: resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f" integrity sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA== -bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.11.0, bn.js@^4.11.6, bn.js@^4.11.8, bn.js@^4.11.9: +bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.11.0, bn.js@^4.11.6, bn.js@^4.11.8, bn.js@^4.11.9, bn.js@^4.4.0: version "4.12.0" resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.12.0.tgz#775b3f278efbb9718eec7361f483fb36fbbfea88" integrity sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA== @@ -4710,7 +4913,7 @@ crypto-js@^3.1.9-1: resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-3.3.0.tgz#846dd1cce2f68aacfa156c8578f926a609b7976b" integrity sha512-DIT51nX0dCfKltpRiXV+/TVZq+Qq2NgF4644+K7Ttnla7zEzqc+kjJyiB96BHNyUTBxyjzRcZYpUdZa+QAqi6Q== -crypto-js@^4.0.0: +crypto-js@^4.0.0, crypto-js@^4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.1.1.tgz#9e485bcf03521041bd85844786b83fb7619736cf" integrity sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw== @@ -6483,7 +6686,7 @@ glob@^7.1.3, glob@^7.1.6, glob@^7.2.0: once "^1.3.0" path-is-absolute "^1.0.0" -global@~4.4.0: +global@^4.4.0, global@~4.4.0: version "4.4.0" resolved "https://registry.yarnpkg.com/global/-/global-4.4.0.tgz#3e7b105179006a323ed71aafca3e9c57a5cc6406" integrity sha512-wv/LAoHdRE3BeTGz53FAamhGlPLhlssK45usmGFThIi4XqnBmjKQ16u+RNbP7WvigRZDxUsM0J3gcQ5yicaL0w== @@ -7276,6 +7479,11 @@ joi@^17.6.1: "@sideway/formula" "^3.0.0" "@sideway/pinpoint" "^2.0.0" +jose@^4.5.0: + version "4.10.3" + resolved "https://registry.yarnpkg.com/jose/-/jose-4.10.3.tgz#36ffeae395f14624a99961db6ada957476eccb19" + integrity sha512-3S4wQnaoJKSAx9uHSoyf8B/lxjs1qCntHWL6wNFszJazo+FtWe+qD0zVfY0BlqJ5HHK4jcnM98k3BQzVLbzE4g== + js-base64@^3.7.2: version "3.7.2" resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-3.7.2.tgz#816d11d81a8aff241603d19ce5761e13e41d7745" From ca14ab5ad39dc0d7ee39f39f8ec437b305675cbd Mon Sep 17 00:00:00 2001 From: Vincent Shadbolt Date: Fri, 21 Oct 2022 16:50:21 -0700 Subject: [PATCH 03/21] updated uauth readme --- packages/uauth/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/uauth/README.md b/packages/uauth/README.md index f3bb7ae8a..1c46d6501 100644 --- a/packages/uauth/README.md +++ b/packages/uauth/README.md @@ -1,6 +1,6 @@ -# @web3-onboard/walletconnect +# @web3-onboard/uauth -## Wallet module for connecting Ledger hardware wallets to web3-onboard +## Wallet module for connecting Unstoppable Domains to web3-onboard ### Install From 56d5b09e5338867fb7eb1975fce34dfcc28becec Mon Sep 17 00:00:00 2001 From: Vincent Shadbolt Date: Mon, 24 Oct 2022 11:30:32 -0700 Subject: [PATCH 04/21] added function for getting uauth user scopes data --- packages/demo/src/App.svelte | 24 +++++++++++++++++++----- packages/uauth/README.md | 26 +++++++++++++++++--------- packages/uauth/src/index.ts | 29 ++++++++++++++++++++++------- 3 files changed, 58 insertions(+), 21 deletions(-) diff --git a/packages/demo/src/App.svelte b/packages/demo/src/App.svelte index 6fcf91ea2..01c3a8597 100644 --- a/packages/demo/src/App.svelte +++ b/packages/demo/src/App.svelte @@ -17,7 +17,7 @@ import dcentModule from '@web3-onboard/dcent' import sequenceModule from '@web3-onboard/sequence' import tallyHoModule from '@web3-onboard/tallyho' - import uauthModule from '@web3-onboard/uauth' + import uauthModule, { getUauthUser } from '@web3-onboard/uauth' import { recoverAddress, arrayify, @@ -98,9 +98,10 @@ const trezor = trezorModule(trezorOptions) const uauthOptions = { - clientID: "a25c3a65-a1f2-46cc-a515-a46fe7acb78c", - redirectUri: "http://localhost:8080/", -} + clientID: 'a25c3a65-a1f2-46cc-a515-a46fe7acb78c', + redirectUri: 'http://localhost:8080/', + scope: 'openid wallet email:optional humanity_check:optional profile:optional social:optional' + } const uauth = uauthModule(uauthOptions) const magic = magicModule({ @@ -131,7 +132,7 @@ gnosis, dcent, sequence, - tallyho, + tallyho, uauth ], gas, @@ -959,6 +960,19 @@
Chains: {JSON.stringify(chains, null, 2)}
+ {#if label === 'Unstoppable'} + {#await getUauthUser(uauthOptions)} +
Getting Unstoppable User...
+ {:then user} + scope: 'openid wallet email:optional humanity_check:optional profile:optional social:optional' +
Unstoppable User: {user.sub}
+
Unstoppable Wallet: {user.wallet_address}
+
Unstoppable Email: {user.email || ''}
+
Unstoppable Humanity: {user.humanity_check_id || ''}
+
Unstoppable Profile: {user.profile || ''}
+ {/await} + {/if} + {#each accounts as { address, ens, balance }} {#if $wallets$ && !hideForIframe} - {#each $wallets$ as { icon, label, accounts, chains, provider }} + {#each $wallets$ as { icon, label, accounts, chains, provider, instance }}
{@html icon}
@@ -961,16 +961,11 @@
Chains: {JSON.stringify(chains, null, 2)}
{#if label === 'Unstoppable'} - {#await getUauthUser(uauthOptions)} -
Getting Unstoppable User...
- {:then user} - scope: 'openid wallet email:optional humanity_check:optional profile:optional social:optional' -
Unstoppable User: {user.sub}
-
Unstoppable Wallet: {user.wallet_address}
-
Unstoppable Email: {user.email || ''}
-
Unstoppable Humanity: {user.humanity_check_id || ''}
-
Unstoppable Profile: {user.profile || ''}
- {/await} +
Unstoppable User: {instance.user.sub}
+
Unstoppable Wallet: {instance.user.wallet_address}
+
Unstoppable Email: {instance.user.email || ''}
+
Unstoppable Humanity: {instance.user.humanity_check_id || ''}
+
Unstoppable Profile: {instance.user.profile || ''}
{/if} {#each accounts as { address, ens, balance }} diff --git a/packages/uauth/README.md b/packages/uauth/README.md index 44f3205fd..480d1321d 100644 --- a/packages/uauth/README.md +++ b/packages/uauth/README.md @@ -11,7 +11,7 @@ Follow the [Login Client Congifuration Docs](https://docs.unstoppabledomains.com/login-with-unstoppable/login-integration-guides/login-client-configuration/) on the Unstoppable Domains website to get setup with your clientID and redirectUri. ```typescript -interface uauthOptions { +type UauthInitOptions = { clientID: string // required and will throw an error if not included: links dapp to Unstoppable Domains for customization redirectUri: string // required and will throw an error if not included: used for pop-up and callback redirection scope?: string // default = 'openid wallet' @@ -28,7 +28,7 @@ interface uauthOptions { ```typescript import Onboard from '@web3-onboard/core' -import uauthModule, { getUauthUser } from '@web3-onboard/uauth' +import uauthModule from '@web3-onboard/uauth' // initialize the module with options const uauth = uauthModule({ @@ -59,12 +59,20 @@ const onboard = Onboard({ const connectedWallets = await onboard.connectWallet() console.log(connectedWallets) +``` -// after connection, get requested user scopes in an object -const user = await getUauthUser({ - clientID: 'YOUR_CLIENT_ID', - redirectUri: 'YOUR_REDIRECT_URI', - scope?: 'YOUR_SCOPES' -}) -console.log(user) +### Accessing the UAuth configuration + +When Unstoppable Domains is connected the UAuth user instance is exposed. +This can be used to get information related to the user scopes requested through the `UauthInitOptions`. + +```typescript +const [unstoppable] = await onboard.connectWallet() + +try { + const user = unstoppable.instance.user + console.log(user) +} catch { + // Handle errors if required! +} ``` diff --git a/packages/uauth/package.json b/packages/uauth/package.json index f42c9f6ea..2f92ea7d0 100644 --- a/packages/uauth/package.json +++ b/packages/uauth/package.json @@ -1,7 +1,7 @@ { "name": "@web3-onboard/uauth", "version": "2.0.0-alpha.1", - "description": "UAuth SDK module for connecting to Web3-Onboard. Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardised spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.", + "description": "Unstoppable Domains module for connecting to Web3-Onboard. Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardised spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.", "keywords": [ "Ethereum", "Web3", diff --git a/packages/uauth/src/index.ts b/packages/uauth/src/index.ts index f903573a4..61851e677 100644 --- a/packages/uauth/src/index.ts +++ b/packages/uauth/src/index.ts @@ -19,28 +19,6 @@ const isHexString = (value: string | number) => { return true } -export async function getUauthUser(options: UauthInitOptions): Promise { - const UAuth = await import('@uauth/js') - if (options) { - const error = validateUauthInitOptions(options) - - if (error) { - throw error - } - } - const { clientID, redirectUri, scope = 'openid wallet' } = options || {} - - const uauthInstance = new UAuth.default({ - clientID: clientID, - redirectUri: redirectUri, - scope: scope - }) - - return uauthInstance.user().then(user => { - return user - }) -} - function uauth(options: UauthInitOptions): WalletInit { return () => { if (options) { @@ -375,7 +353,12 @@ function uauth(options: UauthInitOptions): WalletInit { } provider = new EthProvider({ chains, connector }) } - return { provider: provider } + return { + provider, + instance: { + user + } + } } } } From c2005ffbd18cbcfb2ffb0c1481c7f4be24ca9f0c Mon Sep 17 00:00:00 2001 From: Adam Carpenter Date: Wed, 16 Nov 2022 16:14:56 -0700 Subject: [PATCH 16/21] Update packages/uauth/README.md --- packages/uauth/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/uauth/README.md b/packages/uauth/README.md index 480d1321d..2a6939e02 100644 --- a/packages/uauth/README.md +++ b/packages/uauth/README.md @@ -4,7 +4,11 @@ ### Install -`npm i @web3-onboard/uauth` +**NPM** +`npm i @web3-onboard/core @web3-onboard/uauth` + +**Yarn** +`yarn add @web3-onboard/core @web3-onboard/uauth` ## Options From 33215f7a4b90ca7f0d3a10660d6ef55ffda5e9dd Mon Sep 17 00:00:00 2001 From: Adam Carpenter Date: Wed, 16 Nov 2022 16:15:47 -0700 Subject: [PATCH 17/21] Update packages/uauth/README.md --- packages/uauth/README.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/uauth/README.md b/packages/uauth/README.md index 2a6939e02..155e628a0 100644 --- a/packages/uauth/README.md +++ b/packages/uauth/README.md @@ -71,12 +71,11 @@ When Unstoppable Domains is connected the UAuth user instance is exposed. This can be used to get information related to the user scopes requested through the `UauthInitOptions`. ```typescript -const [unstoppable] = await onboard.connectWallet() - -try { - const user = unstoppable.instance.user - console.log(user) -} catch { - // Handle errors if required! -} +const wallets$ = onboard.state.select('wallets').pipe(share()) +wallets$.subscribe(wallet => { + const unstoppableUser = wallet.find( + provider => provider.label === 'Unstoppable' + ) + if (unstoppableUser) console.log(unstoppableUser.instance.user) +}) ``` From 796370b5e735b8942264a43ac9baa72063bc1215 Mon Sep 17 00:00:00 2001 From: Adam Carpenter Date: Wed, 16 Nov 2022 16:17:14 -0700 Subject: [PATCH 18/21] Prettier formatting --- packages/demo/src/App.svelte | 20 ++++++++--- packages/uauth/src/index.ts | 61 ++++++++++++++++---------------- packages/uauth/src/types.ts | 19 +++++----- packages/uauth/src/validation.ts | 2 +- 4 files changed, 56 insertions(+), 46 deletions(-) diff --git a/packages/demo/src/App.svelte b/packages/demo/src/App.svelte index 48797952d..0bbc4927e 100644 --- a/packages/demo/src/App.svelte +++ b/packages/demo/src/App.svelte @@ -30,6 +30,7 @@ import blocknativeIcon from './blocknative-icon' import blocknativeLogo from './blocknative-logo' import { onMount } from 'svelte' + import wallets from '@web3-onboard/injected-wallets/dist/wallets' let windowWidth @@ -100,7 +101,8 @@ const uauthOptions = { clientID: 'a25c3a65-a1f2-46cc-a515-a46fe7acb78c', redirectUri: 'http://localhost:8080/', - scope: 'openid wallet email:optional humanity_check:optional profile:optional social:optional' + scope: + 'openid wallet email:optional humanity_check:optional profile:optional social:optional' } const uauth = uauthModule(uauthOptions) @@ -132,7 +134,7 @@ gnosis, dcent, sequence, - tallyho, + tallyho, uauth ], gas, @@ -247,8 +249,8 @@ } }, // containerElements: { - // El must be present at time of JS script execution - // See ../public/index.html for element example + // El must be present at time of JS script execution + // See ../public/index.html for element example // accountCenter: '#sample-container-el' // }, // Sign up for your free api key at www.Blocknative.com @@ -257,6 +259,12 @@ // Subscribe to wallet updates const wallets$ = onboard.state.select('wallets').pipe(share()) + wallets$.subscribe(wallet => { + const unstoppableUser = wallet.find( + provider => provider.label === 'Unstoppable' + ) + if (unstoppableUser) console.log(unstoppableUser.instance.user) + }) const signTransactionMessage = async provider => { const ethersProvider = new ethers.providers.Web3Provider(provider, 'any') @@ -964,7 +972,9 @@
Unstoppable User: {instance.user.sub}
Unstoppable Wallet: {instance.user.wallet_address}
Unstoppable Email: {instance.user.email || ''}
-
Unstoppable Humanity: {instance.user.humanity_check_id || ''}
+
+ Unstoppable Humanity: {instance.user.humanity_check_id || ''} +
Unstoppable Profile: {instance.user.profile || ''}
{/if} diff --git a/packages/uauth/src/index.ts b/packages/uauth/src/index.ts index 61851e677..8158c9342 100644 --- a/packages/uauth/src/index.ts +++ b/packages/uauth/src/index.ts @@ -23,7 +23,7 @@ function uauth(options: UauthInitOptions): WalletInit { return () => { if (options) { const error = validateUauthInitOptions(options) - + if (error) { throw error } @@ -108,7 +108,8 @@ function uauth(options: UauthInitOptions): WalletInit { // This is a cjs module and therefor depending on build tooling // sometimes it will be nested in the { default } object and // other times it will be the actual import - let QRCodeModal = (await import('@walletconnect/qrcode-modal')).default + let QRCodeModal = (await import('@walletconnect/qrcode-modal')) + .default // @ts-ignore - TS thinks that there is no default property on the `QRCodeModal` but sometimes there is QRCodeModal = QRCodeModal.default || QRCodeModal @@ -158,18 +159,18 @@ function uauth(options: UauthInitOptions): WalletInit { return payload }) - .pipe(takeUntil(this.disconnected$)) - .subscribe({ - next: ({ params }) => { - const [{ accounts, chainId }] = params - this.emit('accountsChanged', accounts) - const hexChainId = isHexString(chainId) - ? chainId - : `0x${chainId.toString(16)}` - this.emit('chainChanged', hexChainId) - }, - error: console.warn - }) + .pipe(takeUntil(this.disconnected$)) + .subscribe({ + next: ({ params }) => { + const [{ accounts, chainId }] = params + this.emit('accountsChanged', accounts) + const hexChainId = isHexString(chainId) + ? chainId + : `0x${chainId.toString(16)}` + this.emit('chainChanged', hexChainId) + }, + error: console.warn + }) // @ts-ignore listen for disconnect event fromEvent(this.connector, 'disconnect', (error, payload) => { @@ -240,20 +241,20 @@ function uauth(options: UauthInitOptions): WalletInit { return payload }) - .pipe(take(1)) - .subscribe({ - next: ({ params }) => { - const [{ accounts, chainId }] = params - this.emit('accountsChanged', accounts) - const hexChainId = isHexString(chainId) - ? chainId - : `0x${chainId.toString(16)}` - this.emit('chainChanged', hexChainId) - QRCodeModal.close() - resolve(accounts) - }, - error: reject - }) + .pipe(take(1)) + .subscribe({ + next: ({ params }) => { + const [{ accounts, chainId }] = params + this.emit('accountsChanged', accounts) + const hexChainId = isHexString(chainId) + ? chainId + : `0x${chainId.toString(16)}` + this.emit('chainChanged', hexChainId) + QRCodeModal.close() + resolve(accounts) + }, + error: reject + }) }) } @@ -263,7 +264,7 @@ function uauth(options: UauthInitOptions): WalletInit { message: `The Provider does not support the requested method: ${method}` }) } - + if (method == 'wallet_switchEthereumChain') { if (!params) { throw new ProviderRpcError({ @@ -353,7 +354,7 @@ function uauth(options: UauthInitOptions): WalletInit { } provider = new EthProvider({ chains, connector }) } - return { + return { provider, instance: { user diff --git a/packages/uauth/src/types.ts b/packages/uauth/src/types.ts index 5b8a524ec..718c61b4b 100644 --- a/packages/uauth/src/types.ts +++ b/packages/uauth/src/types.ts @@ -1,12 +1,11 @@ export type UauthInitOptions = { - clientID: string - redirectUri: string - scope?: string - shouldLoginWithRedirect?: boolean - bridge?: string - qrcodeModalOptions?: { - mobileLinks: string[] - } - connectFirstChainId?: boolean + clientID: string + redirectUri: string + scope?: string + shouldLoginWithRedirect?: boolean + bridge?: string + qrcodeModalOptions?: { + mobileLinks: string[] + } + connectFirstChainId?: boolean } - diff --git a/packages/uauth/src/validation.ts b/packages/uauth/src/validation.ts index 63254ce06..e0623819a 100644 --- a/packages/uauth/src/validation.ts +++ b/packages/uauth/src/validation.ts @@ -24,4 +24,4 @@ export const validateUauthInitOptions = ( data: UauthInitOptions ): ValidateReturn => { return validate(uauthOptions, data) -} \ No newline at end of file +} From de17eb12d3c305e059640ea1fc31d707a13203a0 Mon Sep 17 00:00:00 2001 From: Vincent Shadbolt Date: Wed, 16 Nov 2022 16:35:24 -0800 Subject: [PATCH 19/21] updated readme with redirect URI notes --- packages/uauth/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/uauth/README.md b/packages/uauth/README.md index 155e628a0..dd6fe0b88 100644 --- a/packages/uauth/README.md +++ b/packages/uauth/README.md @@ -12,7 +12,7 @@ ## Options -Follow the [Login Client Congifuration Docs](https://docs.unstoppabledomains.com/login-with-unstoppable/login-integration-guides/login-client-configuration/) on the Unstoppable Domains website to get setup with your clientID and redirectUri. +Follow the [Login Client Congifuration Docs](https://docs.unstoppabledomains.com/login-with-unstoppable/login-integration-guides/login-client-configuration/) on the Unstoppable Domains website to get setup with your clientID and redirectUri. Note that the Redirection URI value(s) in the client configuration MUST exactly match the redirect_uri parameter value used in `UauthInitOptions`. More specifics can be found in the [Rules for Redirect URIs Docs](https://docs.unstoppabledomains.com/login-with-unstoppable/login-integration-guides/login-client-configuration/#rules-for-redirect-uris). ```typescript type UauthInitOptions = { From 8248ba8535b7231169f85ad110e51f45b85dc15d Mon Sep 17 00:00:00 2001 From: Adam Carpenter Date: Thu, 17 Nov 2022 10:25:18 -0700 Subject: [PATCH 20/21] Add notes to types for ide dev relay --- packages/uauth/README.md | 3 ++- packages/uauth/src/types.ts | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/uauth/README.md b/packages/uauth/README.md index dd6fe0b88..f18fc0427 100644 --- a/packages/uauth/README.md +++ b/packages/uauth/README.md @@ -12,7 +12,8 @@ ## Options -Follow the [Login Client Congifuration Docs](https://docs.unstoppabledomains.com/login-with-unstoppable/login-integration-guides/login-client-configuration/) on the Unstoppable Domains website to get setup with your clientID and redirectUri. Note that the Redirection URI value(s) in the client configuration MUST exactly match the redirect_uri parameter value used in `UauthInitOptions`. More specifics can be found in the [Rules for Redirect URIs Docs](https://docs.unstoppabledomains.com/login-with-unstoppable/login-integration-guides/login-client-configuration/#rules-for-redirect-uris). +Follow the [Login Client Congifuration Docs](https://docs.unstoppabledomains.com/login-with-unstoppable/login-integration-guides/login-client-configuration/) on the Unstoppable Domains website to get setup with your clientID and redirectUri. +**Note:** The Redirection URI value(s) in the client configuration MUST exactly match the redirect_uri parameter value used in `UauthInitOptions`. More specifics can be found in the [Rules for Redirect URIs Docs](https://docs.unstoppabledomains.com/login-with-unstoppable/login-integration-guides/login-client-configuration/#rules-for-redirect-uris). ```typescript type UauthInitOptions = { diff --git a/packages/uauth/src/types.ts b/packages/uauth/src/types.ts index 718c61b4b..def42a1a1 100644 --- a/packages/uauth/src/types.ts +++ b/packages/uauth/src/types.ts @@ -1,11 +1,32 @@ export type UauthInitOptions = { + /** + * Required and will throw an error if not included: links dapp to Unstoppable Domains for customization + */ clientID: string + /** + * Required and will throw an error if not included: used for pop-up and callback redirection + */ redirectUri: string + /** + * Optional string: Default = 'openid wallet' + */ scope?: string + /** + * Optional boolean: If true, redirects to your callback page + */ shouldLoginWithRedirect?: boolean + /** + * Optional url string: default = 'https://bridge.walletconnect.org' + */ bridge?: string qrcodeModalOptions?: { + /** + * Optional array of strings: Set the order and list of mobile linking wallets + */ mobileLinks: string[] } + /** + * Optional boolean: If true, connects to the first network chain provided + */ connectFirstChainId?: boolean } From d097cd10ec2613bb8f8415e8641968494d54ea4e Mon Sep 17 00:00:00 2001 From: Vincent Shadbolt Date: Thu, 17 Nov 2022 11:13:45 -0800 Subject: [PATCH 21/21] circleci config merge fixes --- .circleci/config.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 21ce8be45..b71ccb054 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -479,6 +479,18 @@ jobs: working_directory: ~/web3-onboard-monorepo/packages/tallyho steps: - node-staging-build-steps + build-staging-enkrypt: + docker: + - image: cimg/node:16.13.1 + working_directory: ~/web3-onboard-monorepo/packages/enkrypt + steps: + - node-staging-build-steps + build-staging-uauth: + docker: + - image: cimg/node:16.13.1 + working_directory: ~/web3-onboard-monorepo/packages/uauth + steps: + - node-staging-build-steps workflows: version: 2 @@ -633,3 +645,15 @@ workflows: <<: *deploy_production_filters - build-staging-tallyho: <<: *deploy_staging_filters + enkrypt: + jobs: + - build-enkrypt: + <<: *deploy_production_filters + - build-staging-enkrypt: + <<: *deploy_staging_filters + uauth: + jobs: + - build-uauth: + <<: *deploy_production_filters + - build-staging-uauth: + <<: *deploy_staging_filters