0.0.4 • Published 8 months ago

@dulcetlabs/suglink v0.0.4

Weekly downloads
-
License
MIT AND Commons-C...
Repository
github
Last release
8 months ago

SugLink

DULCET LABS INTERNAL PACKAGE

⚠️ IMPORTANT: PERMISSION REQUIRED FOR USE ⚠️

This software requires explicit written permission from Dulcet Labs before any commercial use, including but not limited to production deployment, incorporation into commercial products, or use by competing businesses.

SugLink is an internal Dulcet Labs library that enables easy onboarding and Solana wallet creation using existing social accounts (Google, TikTok, and Snapchat). It provides a seamless way to generate deterministic Solana keypairs based on their social accounts.

Features

  • Social Login Integration: Supports Google, TikTok, and Snapchat.
  • Deterministic Keypair Generation: Generates Solana keypairs based on social credentials.
  • Secure OAuth Flow Handling: Manages OAuth securely with environment variable support.
  • TypeScript Support: Includes TypeScript definitions for better development experience.
  • Dual Module Support: Compatible with both ESM and CommonJS.

Installation

Install the package using npm, yarn, or pnpm:

# Using npm
npm install @dulcetlabs/suglink @solana/web3.js

# Using yarn
yarn add @dulcetlabs/suglink @solana/web3.js

# Using pnpm
pnpm add @dulcetlabs/suglink @solana/web3.js

Setup

Environment Variables

Create a .env file in your project root and add your OAuth credentials:

# Google OAuth Configuration
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
GOOGLE_REDIRECT_URI=your_redirect_uri

# TikTok OAuth Configuration
TIKTOK_CLIENT_ID=your_tiktok_client_id
TIKTOK_CLIENT_SECRET=your_tiktok_client_secret
TIKTOK_REDIRECT_URI=your_redirect_uri

# Snapchat OAuth Configuration
SNAPCHAT_CLIENT_ID=your_snapchat_client_id
SNAPCHAT_CLIENT_SECRET=your_snapchat_client_secret
SNAPCHAT_REDIRECT_URI=your_redirect_uri

Loading Environment Variables

Ensure that the dotenv package is used to load these variables:

import * as dotenv from 'dotenv';

// Load environment variables from .env file
dotenv.config();

Usage

React Application Example

import React, { useState } from 'react';
import { SugLink } from '@dulcetlabs/suglink';

const App = () => {
  const [publicKey, setPublicKey] = useState<string | null>(null);
  const sugLink = new SugLink();

  const handleLogin = async (platform: 'google' | 'tiktok' | 'snapchat', code: string) => {
    try {
      await sugLink.login(platform, code);
      setPublicKey(sugLink.getPublicKey());
    } catch (error) {
      console.error('Login failed:', error);
    }
  };

  return (
    <div>
      <button onClick={() => handleLogin('google', 'auth_code')}>Login with Google</button>
      <button onClick={() => handleLogin('tiktok', 'auth_code')}>Login with TikTok</button>
      <button onClick={() => handleLogin('snapchat', 'auth_code')}>Login with Snapchat</button>
      {publicKey && <p>Public Key: {publicKey}</p>}
    </div>
  );
};

export default App;

TypeScript Application Example

import { SugLink } from '@dulcetlabs/suglink';

const sugLink = new SugLink();

async function loginAndFetchPublicKey(platform: 'google' | 'tiktok' | 'snapchat', code: string) {
  try {
    await sugLink.login(platform, code);
    const publicKey = sugLink.getPublicKey();
    console.log('Public Key:', publicKey);
  } catch (error) {
    console.error('Error during login:', error);
  }
}

async function logout() {
  sugLink.logout();
  console.log('Logged out successfully');
}

Plain HTML/JavaScript Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SugLink Example</title>
    <script type="module">
        import { SugLink } from './node_modules/@dulcetlabs/suglink/dist/esm/index.js';

        const sugLink = new SugLink();

        async function handleLogin(platform, code) {
            try {
                await sugLink.login(platform, code);
                const publicKey = sugLink.getPublicKey();
                document.getElementById('publicKey').innerText = `Public Key: ${publicKey}`;
            } catch (error) {
                console.error('Login failed:', error);
            }
        }

        window.handleLogin = handleLogin;
    </script>
</head>
<body>
    <button onclick="handleLogin('google', 'auth_code')">Login with Google</button>
    <button onclick="handleLogin('tiktok', 'auth_code')">Login with TikTok</button>
    <button onclick="handleLogin('snapchat', 'auth_code')">Login with Snapchat</button>
    <p id="publicKey"></p>
</body>
</html>

Direct OAuth Configuration

You can also set the OAuth configuration directly in your code:

import { SugLink } from '@dulcetlabs/suglink';

const sugLink = new SugLink();

const customConfig = {
  clientId: 'your_custom_client_id',
  clientSecret: 'your_custom_client_secret',
  redirectUri: 'your_custom_redirect_uri'
};

async function handleLogin(platform: 'google' | 'tiktok' | 'snapchat', code: string) {
  try {
    const keypair = await sugLink.login(platform, code, customConfig);
    console.log('Keypair generated:', keypair.publicKey.toString());
  } catch (error) {
    console.error('Login failed:', error);
  }
}

API Reference

SugLink Class

Constructor

new SugLink()

Methods

  • login(platform, code, config?): Logs in using social platform credentials and generates a keypair.

    • platform: 'google' | 'tiktok' | 'snapchat'
    • code: OAuth authorization code
    • config: Optional OAuth configuration object
    • Returns: Promise
  • getKeypair(): Returns the current Solana keypair.

  • getPublicKey(): Returns the public key as a base-58 string.

  • getPrivateKey(): Returns the private key as a Uint8Array.

  • logout(): Clears the current keypair, effectively logging out.

Security Considerations

  • Never expose your OAuth client secrets in client-side code.
  • Always use environment variables for sensitive configuration.
  • Implement proper OAuth flow with state verification.
  • Store keypairs securely and never expose private keys.
  • Use HTTPS for all OAuth redirects.
  • Implement proper session management.

License

This package is provided under the MIT License with Commons Clause.

Usage Requirements

  • Permission Required: You MUST obtain explicit written permission from Dulcet Labs before using the software in production environments or incorporating it into commercial products.

Support

For support, please open an issue in the GitHub repository or contact the maintainers.

Platform Support

SugLink supports the following platforms:

  • Google
  • TikTok
  • Snapchat

Each platform requires its own OAuth credentials and proper setup in their respective developer consoles.

Potential Improvements

  • Enhanced Key Generation: Add salt to the buildTimeKey generation process for additional security.
  • Network Security: Add timeout settings for axios POST requests to prevent hanging connections.
  • Type Safety and Validation: Implement TypeScript strict null checks for better type safety.
  • Keypair Verification: Add methods to verify keypair generation correctness.
  • Error Handling: Enhance error messages with more detailed information.

These improvements are planned for future releases. Contributions are welcome!

0.0.4

8 months ago

0.0.3

8 months ago

0.0.2

8 months ago

0.0.1

8 months ago