DID Manager
@ismelabs/did-manager
provides a series of components and hooks for React, which is a more advanced package for @ismelabs/client
ISMEProvider
you need to use 'ISMEProvider' at the react root component in order to use '@ismelabs/did-manager'
Props
silent
:boolean
,Switch if render with the built-in UI components, the default isfalse
, that is, the built-in components will be usedendpoint
:string
,ISME Gateway address
example code
import ReactDOM from 'react-dom/client'
import { ISMEProvider } from '@ismelabs/did-manager'
import App from './pages/App'
const endpoint = 'https://t0.onebitdev.com/nft3-gateway/'
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<ISMEProvider endpoint={endpoint} silent>
<App />
</ISMEProvider>
)
useISME
useISME
is the hook function for react,include wallet connection, states management, calling useISME()
to get the status,sample code as below
import { useISME } from '@ismelabs/did-manager'
export default function App() {
const { account, identifier, selectWallet, client } = useISME()
}
account
string
,wallet address for current connection
client
ISMEClient
instance
didname
ISME DID name part,for example 'didname' of the did:nft3:bob
is bob
identifier
The full DID name, for example did:nft3:bob
connect
TYPE
interface ISMEContext {
connect: () => void
}
Details
Connect the wallet, if silent
is specified, it will not have any effect, otherwise the built-in wallet selector will pop up.
login
Type
interface LoginResult {
result: boolean
needRegister: boolean
identifier?: string
}
interface ISMEContext {
login: () => Promise<LoginResult>
}
Details
If login success, result
is 'true`,If the current address doesn't have the registered DID, then return 'false'
{
result: false,
needRegister: true
}
register
Type
interface ISMEContext {
register: (didname: string) => Promise<string>
}
Details
Pass the 'didname' when register the DID account, this function will call the wallet for signature, if register success, then it will return the full DID.
logout
type
interface ISMEContext {
logout: () => void
}
Details
This method will clean the login status of SDK.
checkLogin
Type
interface ISMEContext {
checkLogin: () => Promise<string | undefined>
}
Details
This method will check the current DID login status, if it is effective, then return the whole DID.=
eagerConnect
Type
interface ISMEContext {
eagerConnect: () => void
}
Details
This method will try to connect wallet in silence, normally it is used when the web page during initialization, it will not work if previously doesn't authorization.
disconnect
Type
interface ISMEContext {
disconnect: () => void
}
Details
This method will be use to disconnect with wallet when switch wallet.
disconnect
and logout
are different,disconnect
only be used to disconnect with wallet,it will not clean the login status.
selectWallet
Type
type WalletType = 'MetaMask' | 'Phantom' | 'Petra'
interface ISMEContext {
selectWallet: (wallet: WalletType) => Promise<string>
}
Detail This method to select wallet to connect.