🚨 Active Supply Chain Attack:node-ipc Package Compromised.Learn More
Socket
Book a DemoSign in
Socket

@etherplay/alchemy

Package Overview
Dependencies
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@etherplay/alchemy

Alchemy Mechanism For Deterministic Account Generation - provides social login mechanisms including email OTP, OAuth (Google, Facebook, Auth0), and mnemonic phrase authentication

latest
Source
npmnpm
Version
0.0.17
Version published
Maintainers
2
Created
Source

@etherplay/alchemy

Alchemy mechanism for deterministic account generation in the @etherplay/connect ecosystem. This package provides social login mechanisms including email OTP, OAuth (Google, Facebook, Auth0), and mnemonic phrase authentication using Alchemy's Account Kit infrastructure.

Installation

npm install @etherplay/alchemy
# or
pnpm add @etherplay/alchemy
# or
yarn add @etherplay/alchemy

Features

  • Email OTP Login: Authenticate users via email with one-time passwords
  • OAuth Support: Login via Google, Facebook, or Auth0 providers
  • Mnemonic Login: Direct authentication using BIP-39 mnemonic phrases
  • Deterministic Account Generation: Generate consistent accounts from social login credentials
  • Origin-Based Account Isolation: Create isolated session accounts per origin for security
  • Svelte Integration: Built-in Svelte store support for reactive state management

Peer Dependencies

This package requires Svelte 5.x as a peer dependency:

npm install svelte@^5.0.0

Usage

Basic Setup

import {createAlchemyConnection} from '@etherplay/alchemy';
import {EthereumWalletConnector} from '@etherplay/wallet-connector-ethereum';

const connector = new EthereumWalletConnector();

const connection = createAlchemyConnection({
	alchemy: {
		apiKey: 'YOUR_ALCHEMY_API_KEY',
		// Additional Alchemy configuration
	},
	accountGenerator: connector.accountGenerator,
	windowOrigin: window.location.origin,
	signingOrigin: 'https://your-app.com',
	autoInitialise: true,
});

// Subscribe to connection state changes (Svelte store)
connection.subscribe((state) => {
	console.log('Connection state:', state?.step);
});

Email OTP Login

// Start email authentication
await connection.connect({
	type: 'email',
	mode: 'otp',
	email: 'user@example.com',
});

// After user receives OTP
await connection.provideOTP('123456');

OAuth Login (Google/Facebook)

// Using popup
await connection.connect({
	type: 'oauth',
	provider: {id: 'google'},
	usePopup: true,
});

// Then confirm the OAuth flow
await connection.confirmOAuth();

OAuth Login (Auth0)

await connection.connect({
	type: 'oauth',
	provider: {id: 'auth0', connection: 'your-auth0-connection'},
	usePopup: true,
});

Mnemonic Login

await connection.connect({
	type: 'mnemonic',
	mnemonic: 'your twelve word mnemonic phrase goes here and more words',
	index: 0,
});

Connection States

The connection follows a state machine with the following steps:

StepDescription
InitialisingConnection is being initialized
InitialisedSigner is ready
MechanismToChooseWaiting for mechanism selection
MechanismChosenMechanism selected, processing
EmailToProvideWaiting for email input
WaitingForOTPEmail sent, waiting for OTP
VerifyingOTPVerifying the provided OTP
ConfirmOAuthOAuth popup ready, needs confirmation
WaitingForOAuthResponseWaiting for OAuth provider response
MnemonicIndexToProvideWaiting for mnemonic index
GeneratingAccountCreating the account
SignedInSuccessfully authenticated

Origin Account Generation

Generate isolated accounts for specific origins:

connection.subscribe(async (state) => {
	if (state?.step === 'SignedIn') {
		const originAccount = await connection.generateOriginAccount('https://game.example.com', state.account);

		console.log('Origin account address:', originAccount.signer.address);
		console.log('Origin public key:', originAccount.signer.publicKey);
	}
});

Types

AlchemyMechanism

type AlchemyMechanism = EmailMechanism<string | undefined> | OauthMechanism | MnemonicMechanism<number | undefined>;

EtherplayAccount

type EtherplayAccount = {
	localAccount: {
		address: `0x${string}`;
		index: number;
		key: `0x${string}`;
	};
	signer: {
		mechanismUsed: AlchemyMechanism;
		user: AlchemyUser;
	};
	accountType: string;
};

OriginAccount

type OriginAccount = {
	address: `0x${string}`;
	signer: {
		origin: string;
		address: `0x${string}`;
		publicKey: `0x${string}`;
		privateKey: `0x${string}`;
		mnemonicKey: `0x${string}`;
	};
	metadata: {
		email?: string;
	};
	mechanismUsed: AlchemyMechanism | {type: string};
	savedPublicKeyPublicationSignature?: `0x${string}`;
	accountType: string;
};

AlchemyUser

type AlchemyUser = {
	email?: string;
	orgId: string;
	userId: string;
	address: `0x${string}`;
	credentialId?: string;
	idToken?: string;
	claims?: Record<string, unknown>;
};

API Reference

createAlchemyConnection

function createAlchemyConnection(settings: {
	alchemy: AlchemySettings;
	autoInitialise?: boolean;
	alwaysUsePopupForOAuth?: boolean;
	accountGenerator: AccountGenerator;
	windowOrigin: string;
	signingOrigin: string;
}): AlchemyConnectionStore;

AlchemyConnectionStore Methods

MethodDescription
subscribeSubscribe to connection state changes
connect(mechanism?)Start authentication with optional mechanism
confirmOAuth()Confirm OAuth popup authentication
provideEmail(email)Provide email for OTP authentication
provideOTP(otp)Submit OTP code
provideMnemonicIndex(index)Provide account index for mnemonic
generateOriginAccount(origin, account)Generate origin-specific account
completeOAuthWithBundle(...)Complete OAuth with redirect bundle
confirmOriginAccess()Confirm cross-origin access

Utility Functions

// Generate mnemonic from entropy key
fromEntropyKeyToMnemonic(key: `0x${string}`): string;

// Generate key from signature
fromSignatureToKey(signature: `0x${string}`): `0x${string}`;

// Message templates
originKeyMessage(origin: string): string;
localKeyMessage(): string;
originPublicKeyPublicationMessage(origin: string, publicKey: `0x${string}`): string;

Security Considerations

  • Local Key Message: Users should never sign the local key generation message outside of the Etherplay wallet
  • Origin Isolation: Each origin gets a unique derived account to prevent cross-site account correlation
  • OTP Verification: Email OTP provides secure passwordless authentication
  • OAuth Tokens: OAuth tokens are handled securely through Alchemy's infrastructure
  • @etherplay/wallet-connector - Core wallet connector interfaces
  • @etherplay/wallet-connector-ethereum - Ethereum wallet connector
  • @etherplay/connect - Main connection library

License

MIT

Keywords

alchemy

FAQs

Package last updated on 22 Mar 2026

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