JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q55263F
  • License Apache-2.0

Web extensions for Nuwa Identity Kit

Package Exports

  • @nuwa-ai/identity-kit-web
  • @nuwa-ai/identity-kit-web/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@nuwa-ai/identity-kit-web) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@nuwa-ai/identity-kit-web

Web extensions for Nuwa Identity Kit, providing browser-friendly implementations and utilities.

Features

  • Multiple KeyStore implementations:
    • LocalStorageKeyStore - Uses browser's localStorage for key storage
    • IndexedDBKeyStore - Uses IndexedDB for key storage, supports CryptoKey objects
  • DeepLinkManager - Manages deep link authentication flow
  • NuwaIdentityKitWeb - High-level API for web applications
  • React hooks (optional) - useNuwaIdentityKit hook for React applications

Installation

npm install @nuwa-ai/identity-kit-web

Usage

Basic Usage

import { NuwaIdentityKitWeb } from '@nuwa-ai/identity-kit-web';

// Initialize the SDK
const nuwa = await NuwaIdentityKitWeb.init();

// Connect to Cadop
await nuwa.connect();

// Handle callback (in your callback page)
await nuwa.handleCallback(location.search);

// Sign a payload
const sig = await nuwa.sign({ hello: 'world' });

// Verify a signature
const isValid = await nuwa.verify(sig);

// Logout
await nuwa.logout();

React Hook

import { useNuwaIdentityKit } from '@nuwa-ai/identity-kit-web';

function MyComponent() {
  const { state, connect, sign, verify, logout } = useNuwaIdentityKit();

  if (state.isConnecting) {
    return <div>Connecting...</div>;
  }

  if (!state.isConnected) {
    return <button onClick={connect}>Connect</button>;
  }

  return (
    <div>
      <p>Connected as: {state.agentDid}</p>
      <button onClick={logout}>Logout</button>
    </div>
  );
}

Advanced Usage

import { 
  NuwaIdentityKitWeb, 
  IndexedDBKeyStore, 
  KeyManager 
} from '@nuwa-ai/identity-kit-web';

// Custom KeyStore with protection strategy
const store = new IndexedDBKeyStore();

// Custom KeyManager
const keyManager = new KeyManager({ store });

// Initialize SDK with custom components
const nuwa = await NuwaIdentityKitWeb.init({
  cadopDomain: 'https://my-cadop-instance.com',
  keyManager
});

License

MIT