Skip to content

Commit

Permalink
dev-release/1.0.11 (#226)
Browse files Browse the repository at this point in the history
* [Fix] Added new fn for logout (#223)

* [Feature] Custom provider (#224)

* [Fix] made EIP6963 false by default and added param to enable it

* [Fix] Added userDIDToken field to getUser(), fixed path to type

* [Fix] Removed pnpm usage, updated typedoc dependencies

* [Fix] updated typedoc dependencies pointed out by @shaloo
  • Loading branch information
makylfang committed Jul 2, 2024
1 parent 816a0c4 commit 51928b2
Show file tree
Hide file tree
Showing 9 changed files with 1,064 additions and 2,111 deletions.
3,080 changes: 999 additions & 2,081 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@arcana/auth",
"version": "1.0.10",
"version": "1.0.11-beta.6",
"description": "Arcana Auth",
"main": "dist/index.js",
"type": "module",
Expand All @@ -9,7 +9,7 @@
"unpkg": "dist/standalone/auth.umd.js",
"exports": {
".": {
"types": "./types/index.d.ts",
"types": "./dist/types/index.d.ts",
"require": "./dist/index.js",
"import": "./dist/index.js"
}
Expand Down Expand Up @@ -81,14 +81,14 @@
"rimraf": "^3.0.2",
"rollup": "^2.75.7",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-terser": "^7.0.2",
"@rollup/plugin-terser": "^0.4.4",
"ts-jest": "^29.0.3",
"typedoc": "^0.25.7",
"typedoc": "^0.26.3",
"typedoc-plugin-extras": "^3.0.0",
"typedoc-plugin-markdown": "^3.12.1",
"typedoc-plugin-missing-exports": "^2.1.0",
"typedoc-plugin-rename-defaults": "^0.7.0",
"typedoc-theme-hierarchy": "^4.1.2",
"typedoc-plugin-missing-exports": "^3.0.0",
"typedoc-plugin-rename-defaults": "^0.7.1",
"typedoc-theme-hierarchy": "^5.0.0",
"typescript": "^4.5.2"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion rollup.base.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import nodeResolve from '@rollup/plugin-node-resolve'
import typescript from '@rollup/plugin-typescript'
import commonjs from '@rollup/plugin-commonjs'
import { terser } from 'rollup-plugin-terser'
import terser from '@rollup/plugin-terser'
import { handleCircularDependancyWarning } from 'node-stdlib-browser/helpers/rollup/plugin'
import stdLibBrowser from 'node-stdlib-browser'
import inject from '@rollup/plugin-inject'
Expand Down
1 change: 0 additions & 1 deletion src/iframeWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ export default class IframeWrapper {
}

public handleDisconnect() {
this.widgetIframe.src = this.getIframeUrl()
this.clearSessionID()
}

Expand Down
25 changes: 21 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
BearerAuthentication,
ChainType,
ConstructorParams,
CustomProviderParams,
EIP6963ProviderInfo,
EthereumProvider,
FirebaseBearer,
Expand Down Expand Up @@ -143,6 +144,20 @@ class AuthProvider {
}
}

/**
* A function to trigger custom login in the wallet
*/
loginWithCustomProvider = async (
params: CustomProviderParams
): Promise<EthereumProvider> => {
await this.init()
if (await this.isLoggedIn()) {
return this._provider
}
await this._provider.initCustomLogin(params)
return await this.waitForConnect()
}

/**
* A function to finish otp login
*/
Expand Down Expand Up @@ -322,7 +337,7 @@ class AuthProvider {
*/
public logout() {
if (this.initStatus === InitStatus.DONE) {
return this._provider.triggerLogout()
return this._provider.logout()
}
throw ErrorNotInitialized
}
Expand Down Expand Up @@ -547,10 +562,12 @@ class AuthProvider {
}
}

this.announceProvider()
window.addEventListener('eip6963:requestProvider', () => {
if (this.params.useEIP6963) {
this.announceProvider()
})
window.addEventListener('eip6963:requestProvider', () => {
this.announceProvider()
})
}
})
}
}
Expand Down
23 changes: 9 additions & 14 deletions src/provider.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
ChildMethods,
CustomProviderParams,
EthereumProvider,
JsonRpcError,
JsonRpcId,
JsonRpcRequest,
JsonRpcResponse,
JsonRpcSuccess,
} from './typings'
import { Connection } from 'penpal'
import { ethErrors } from 'eth-rpc-errors'
Expand Down Expand Up @@ -33,16 +33,6 @@ class ProviderError extends Error implements JsonRpcError {
}
}

const permissionedMethod = [
'eth_sendTransaction',
'eth_signTransaction',
'eth_sign',
'eth_signTypedData_v3',
'eth_signTypedData_v4',
'personal_sign',
'eth_decrypt',
]

interface AuthProvider {
loginWithSocial(loginType: string): void
loginWithLink(email: string): void
Expand Down Expand Up @@ -123,6 +113,11 @@ export class ArcanaProvider
return available
}

public async initCustomLogin(params: CustomProviderParams) {
const c = await this.getCommunication('triggerCustomLogin')
return await c.triggerCustomLogin(params)
}

public async requestUserInfo() {
const c = await this.getCommunication('getUserInfo')
const isLoggedIn = await c.isLoggedIn()
Expand Down Expand Up @@ -159,9 +154,9 @@ export class ArcanaProvider
return logins
}

public async triggerLogout() {
const c = await this.getCommunication('triggerLogout')
await c.triggerLogout(true)
public async logout() {
const c = await this.getCommunication('logout')
await c.logout()
}

public async initPasswordlessLogin(email: string) {
Expand Down
14 changes: 14 additions & 0 deletions src/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export interface UserInfo {
address: string
publicKey: string
loginToken: string
userDIDToken: string
}
export type Logins =
| 'google'
Expand Down Expand Up @@ -139,6 +140,12 @@ export interface ChildMethods {
addToActivity: (req: object) => Promise<void>
getPublicKey: (email: string, verifier: string) => Promise<string>
triggerLogout: (isV2?: boolean) => Promise<void>
logout: () => Promise<void>
triggerCustomLogin: (params: {
token: string
userID: string
provider: string
}) => Promise<string>
getUserInfo: () => Promise<UserInfo>
initSocialLogin(kind: string): Promise<string>
initPasswordlessLogin: (email: string) =>
Expand Down Expand Up @@ -224,6 +231,7 @@ export interface ConstructorParams {
position: Position
setWindowProvider: boolean
appMode?: AppMode
useEIP6963: boolean
connectOptions: ConnectOptions
}

Expand All @@ -242,3 +250,9 @@ export type EIP6963ProviderInfo = {
icon: string
rdns: string
}

export type CustomProviderParams = {
provider: string
userID: string
token: string
}
10 changes: 8 additions & 2 deletions src/ui/components.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { StateUpdater, useEffect, useState, useRef } from 'preact/hooks'
import {
StateUpdater,
useEffect,
useState,
useRef,
Dispatch,
} from 'preact/hooks'
import { ARCANA_LOGO, getSocialLogo } from './icons'
import { ICONS } from '../utils'
import { ModalParams } from './typings'
Expand Down Expand Up @@ -47,7 +53,7 @@ const EmailLogin = ({
setEmail,
}: {
email: string
setEmail: StateUpdater<string>
setEmail: Dispatch<StateUpdater<string>>
} & Pick<ModalParams, 'loginWithOTPStart'>) => {
const [disabled, setDisabled] = useState(true)
const onInput: JSXInternal.GenericEventHandler<HTMLInputElement> = (e) => {
Expand Down
6 changes: 5 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ const getConstructorParams = (initParams?: Partial<ConstructorParams>) => {
theme: 'dark',
alwaysVisible: true,
setWindowProvider: false,
useEIP6963: false,
connectOptions: {
compact: false,
},
Expand All @@ -186,6 +187,9 @@ const getConstructorParams = (initParams?: Partial<ConstructorParams>) => {
if (initParams?.connectOptions?.compact !== undefined) {
p.connectOptions.compact = initParams.connectOptions.compact
}
if (initParams?.useEIP6963 !== undefined) {
p.useEIP6963 = initParams.useEIP6963
}

if (p.network == 'testnet' || p.network == 'dev') {
console.log(
Expand All @@ -207,7 +211,7 @@ function preLoadIframe(url: string, appId: string) {
try {
if (typeof document === 'undefined') return
const iframeLink = document.createElement('link')
iframeLink.href = `${url}/${appId}/login`
iframeLink.href = `${url}/${appId}/v2/login`
iframeLink.type = 'text/html'
iframeLink.rel = 'prefetch'
document.head.appendChild(iframeLink)
Expand Down

0 comments on commit 51928b2

Please sign in to comment.