Socket
Socket
Sign inDemoInstall

@arcblock/did-connect

Package Overview
Dependencies
393
Maintainers
4
Versions
689
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @arcblock/did-connect

Client side library to work with DID Connect by ArcBlock.


Version published
Maintainers
4
Created

Readme

Source

@arcblock/did-connect

Client side library to work with DID Connect by ArcBlock.

Usage

yarn add @arcblock/did-connect

Then:

import axios from 'axios';

// import each module individually
import DidAddress from '@arcblock/did-connect/lib/Address';
import DidConnect from '@arcblock/did-connect/lib/Connect';
import DidAvatar from '@arcblock/did-connect/lib/Avatar';
import DidButton from '@arcblock/did-connect/lib/Button';
import DidLogo from '@arcblock/did-connect/lib/Logo';
import { SessionProvider, SessionConsumer } from '@arcblock/did-connect/lib/Session';
import SessionManager from '@arcblock/did-connect/lib/SessionManager';

// or use ES6 named imports
import { 
  Address as DidAddress, 
  Connect as DidConnect, 
  Avatar as DidAvatar, 
  Button as DidButton, 
  Logo as DidLogo, 
  Session, 
  SessionManager, 
} from '@arcblock/did-connect/lib';

DidConnect

<DidConnect
  popup
  open={open}
  action="login"
  checkFn={axios.get}
  onClose={() => handleOnClose()}
  onSuccess={() => (window.location.href = '/profile')}
  messages={{
    title: 'login',
    scan: 'Scan QR code with DID Wallet',
    confirm: 'Confirm login on your DID Wallet',
    success: 'You have successfully signed in!',
  }}
/>

Note: DidConnect component has a built-in instance of WebWalletSWKeeper that embeds a wallet iframe in the DOM to keep the service worker of the web wallet alive. When the DidConnect component is destroyed, WebWalletSWKeeper will also be destroyed, so avoid using it like the following:

{open && (
  <DidConnect
    popup
    action="login"
    ...
  />
)}

display DidConnect in popup

const [open, setOpen] = React.useState(false);
const handleOnClose = () => {
  // ...
  setOpen(false);
};

...

<button type="button" onClick={() => setOpen(true)}>
  Open DidConnect
</button>

<DidConnect
  popup
  open={open}
  action="login"
  checkFn={axios.get}
  onClose={() => handleOnClose()}
  onSuccess={() => (window.location.href = '/profile')}
  messages={{
    title: 'login',
    scan: 'Scan QR code with DID Wallet',
    confirm: 'Confirm login on your DID Wallet',
    success: 'You have successfully signed in!',
  }}
  webWalletUrl={webWalletUrl}
/>

DidAvatar

<DidAvatar did={userDid} size={256} />

DidButton

<ConnectButton size="large" />
<ConnectButton size="medium" />
<ConnectButton size="small" />
<ConnectButton>Custom Text</ConnectButton>
<DidLogo size={32} />

DidAddress

<DidAddress did={userDid} size={32} />

SessionManager

<SessionProvider serviceHost={get(window, 'blocklet.prefix', '/')} webWalletUrl={webWalletUrl}>
  <SessionConsumer>{(value) => <SessionManager session={value.session} />}</SessionConsumer>
  ...
</SessionProvider>

Keywords

FAQs

Last updated on 13 May 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc