Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@arcana/auth

Package Overview
Dependencies
Maintainers
8
Versions
115
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arcana/auth

Arcana Auth

  • 0.0.9-beta5
  • beta5
  • npm
  • Socket score

Version published
Weekly downloads
1K
increased by7.68%
Maintainers
8
Weekly downloads
 
Created
Source

Arcana Auth

Installation

Using NPM/Yarn

npm install --save @arcana/auth
yarn add @arcana/auth

Using CDN

<script src="https://cdn.jsdelivr.net/npm/@arcana/auth"></script>
<script src="https://unpkg.com/@arcana/auth"></script>

Usage

Import

const { AuthProvider } = window.arcana.auth
// or
import { AuthProvider } from '@arcana/auth'

Initialize

import { AppMode } from '@arcana/auth'
const auth = new AuthProvider(`${appId}`)

const position = 'left' // values - 'left' or 'right'

await auth.init({ appMode: AppMode.Widget, position })

provider = auth.provider
// or
provider = window.arcana.provider
// or
provider = window.ethereum

Auth API’s

Login/logout

Social login

await auth.loginWithSocial(`${verifier}`)

Email link login

await auth.loginWithLink(`${email}`)

Check is logged in

const loggedIn = await auth.isLoggedIn()

User Info

const info = await auth.getUser()
/* 
interface UserInfo {
  id: string
  email?: string
  name?: string
  picture?: string
}
*/

Logout

await auth.logout()

Get public key

await auth.getPublicKey(`${email}`)

Utils

ECIES encryption

import { encryptWithPublicKey } from '@arcana/auth'

encryptWithPublicKey({
  publicKey: '',
  message: 'test-message',
}).then((ciphertext) => {
  // Do something with ciphertext
})

Compute Address

import { computeAddress } from '@arcana/auth'

const address = computeAddress(publicKey: string);

Events

Subscribing

provider.on('chainChanged', handler: (chainId: number) => void);
provider.on('accountsChanged', handler: (accounts: string[]) => void);
provider.on('connect', handler: ({ chainId: number }) => void);
provider.isConnected(): Promise<boolean>;

Unsubscribing

provider.removeListener(`${eventName}`, handler)

Using with web3/ethers

Ethers JS

Installation

npm install --save ethers

Usage

import { ethers } from 'ethers'

const provider = new ethers.providers.Web3Provider(auth.provider)

const signer = provider.getSigner()

const signedMessage = await signer.signMessage('sample_message')

Web3 JS

Installation

npm install --save web3

Usage

import Web3 from 'web3'

const provider = new Web3(auth.provider)

const signer = provider.getSigner()

const signedMessage = await signer.signMessage('sample_message')

RPC API’s

eth_accounts

provider.request({ method: 'eth_accounts' }).then((accounts) => {
  // Set default account to accounts[0]
  from = accounts[0]
})

eth_sign

provider
  .request({
    method: 'eth_sign',
    params: [from, 'some_random_data'],
  })
  .then((signature) => {
    // Use signature
  })

personal_sign

provider
  .request({
    method: 'personal_sign',
    params: ['some personal signing data', from],
  })
  .then((personalSignature) => {
    // Use personal signature
  })

eth_getEncryptionPublicKey

provider
  .request({
    method: 'eth_getEncryptionPublicKey',
    params: [from],
  })
  .then((publicKey) => {
    // Use public key
  })

eth_decrypt

provider
  .request({
    method: 'eth_decrypt',
    params: [ciphertext, from],
  })
  .then((plaintext) => {
    // Use plaintext
  })

eth_signTypedData_v4

provider
  .request({
    method: 'eth_signTypedData_v4',
    params: [from, msgParams],
  })
  .then((signature) => {
    // Use signature
  })

FAQs

Package last updated on 20 Jun 2022

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc