3.7.0 • Published 5 months ago
@dcl/crypto
Licence
Apache-2.0
Version
3.7.0
Deps
3
Size
75 kB
Vulns
0
Weekly
0
@dcl/crypto
Crypto auth for Decentraland. Provides Authenticator utilities, signature validation, and authentication chain helpers used across Decentraland services and clients.
Install
pnpm add @dcl/crypto
Create a new Identity using Ethers
import { Authenticator, AuthIdentity } from '@dcl/crypto'
import { Wallet } from '@ethersproject/wallet'
import { Web3Provider, ExternalProvider } from '@ethersproject/providers'
/**
* @param provider - any ethereum provider (e.g. window.ethereum)
* @param expiration - ttl in minutes of the identity
*/
export async function createIdentity(
provider: ExternalProvider,
expiration: number
): Promise<AuthIdentity> {
const signer = new Web3Provider(provider).getSigner()
const address = await signer.getAddress()
const wallet = Wallet.createRandom()
const payload = {
address: wallet.address,
privateKey: wallet.privateKey,
publicKey: wallet.publicKey
}
return Authenticator.initializeAuthChain(
address,
payload,
expiration,
(message) => new Web3Provider(provider).getSigner().signMessage(message)
)
}