Files
self/sdk/qrcode
Javier Cortejoso 522ced4f20 chore: NPM publish using Trusted Publishing (#1729)
* chore: simplify npm publish workflow by removing NPM token checks

- Removed redundant checks for NPM_TOKEN before publishing packages to npm.
- Updated publish result messages to reflect the use of Trusted Publishers (OIDC) for package publishing.
- Streamlined the workflow for better clarity and efficiency.

* chore: update npm publish workflow to use ubuntu-slim

- Changed the runner from 'ubuntu-latest' to 'ubuntu-slim' for improved efficiency and reduced resource usage during the npm publish process.

* chore: enhance npm publish workflow with dry run option

- Added a 'dry_run' input to the npm publish workflow to validate authentication and Trusted Publishers without uploading packages.
- Updated publish result messages to indicate when a dry run is completed, improving feedback during the publishing process.

* chore: refine npm publish workflow by removing strict mode input

- Eliminated the 'strict_mode' input from the npm publish workflow to simplify the process.
- Removed associated error handling comments and environment variable for stricter publish mode.
- Streamlined the workflow for improved clarity and efficiency during package publishing.

* chore: update npm publish workflow to use npx for publishing

- Replaced `yarn npm publish` with `npx npm@latest publish` to ensure the latest npm CLI is used for package publishing.
- Removed unnecessary `yarn config set npmPublishAccess` commands to streamline the workflow.
- Maintained the existing dry run functionality for testing without actual publishing.

* chore: enhance npm publish workflow to include version tagging

- Updated the npm publish workflow to dynamically determine the package version and apply a beta tag for pre-release versions.
- This change ensures that the correct versioning is maintained during the publishing process, improving clarity for users regarding package stability.
- Retained existing dry run functionality for testing without actual publishing.

* chore: remove npm publish command from package.json files

- Eliminated the `publish` script from multiple package.json files across contracts, sdk/core, sdk/qrcode, and sdk/qrcode-angular.
- This change streamlines the package management process by removing unnecessary publish commands, ensuring a cleaner configuration for future development.

* Temporary bump versions for check package publishing

* Revert "Temporary bump versions for check package publishing"

This reverts commit 180f5d538a.

* chore: add version check before npm publishing

- Implemented a version check in the npm publish workflow to prevent publishing of already published package versions.
- This enhancement ensures that developers are notified to bump the version in package.json if the version is already published, improving the publishing process and reducing errors.

* chore: improve npm publish workflow with enhanced outcome handling

- Updated the npm publish workflow to include detailed outcome handling for publish results, including checks for version publication status and improved messaging for skipped or failed publishes.
- This enhancement provides clearer feedback to developers regarding the publishing process, ensuring they are informed about the status of their package versions and necessary actions to take.

* chore: update npm publish workflow to include yarn packing for workspace resolution

- Added steps to pack each workspace using `yarn pack` before publishing to npm, ensuring that the correct package is published from each directory.
- This change resolves issues related to workspace protocol and improves the reliability of the publishing process across multiple packages.

* chore: simplify npm publish workflow by removing version check step

- Removed the version check for publish-msdk, as it did not work for private packages.
- Updated outcome handling to ensure clear messaging for skipped publishes without the version check dependency, improving overall workflow clarity.
2026-02-15 21:04:17 -08:00
..
2025-02-25 13:08:01 -07:00
2026-01-21 23:07:24 +10:00
2026-01-21 23:07:24 +10:00
2026-01-21 23:07:24 +10:00
2026-01-21 23:07:24 +10:00
2026-01-21 23:07:24 +10:00
2025-11-13 01:13:48 +05:30
2026-01-21 23:07:24 +10:00
2026-01-21 23:07:24 +10:00

@selfxyz/qrcode

A React component for generating QR codes for Self passport verification.

Installation

npm install @selfxyz/qrcode
# or
yarn add @selfxyz/qrcode

Basic Usage

1. Import the SelfQRcodeWrapper component

import SelfQRcodeWrapper, { SelfAppBuilder } from '@selfxyz/qrcode';
import type { SelfApp } from '@selfxyz/qrcode';
import { v4 as uuidv4 } from 'uuid';

2. Create a SelfApp instance using SelfAppBuilder

// Generate a unique user ID
const userId = uuidv4();

// Create a SelfApp instance using the builder pattern
const selfApp = new SelfAppBuilder({
  appName: 'My App',
  scope: 'my-app-scope',
  endpoint: 'https://myapp.com/api/verify',
  logoBase64: 'base64EncodedLogo', // Optional
  userId,
  // Optional disclosure requirements
  disclosures: {
    // DG1 disclosures
    issuing_state: true,
    name: true,
    nationality: true,
    date_of_birth: true,
    passport_number: true,
    gender: true,
    expiry_date: true,
    // Custom verification rules
    minimumAge: 18,
    excludedCountries: ['IRN', 'PRK'],
    ofac: true,
  },
}).build();

3. Render the QR code component

function MyComponent() {
  return (
    <SelfQRcodeWrapper
      selfApp={selfApp}
      onSuccess={() => {
        console.log('Verification successful');
        // Perform actions after successful verification
      }}
      darkMode={false} // Optional: set to true for dark mode
      size={300} // Optional: customize QR code size (default: 300)
    />
  );
}

SelfQRcodeWrapper wraps SelfQRcode to prevent server-side rendering when using nextjs. When not using nextjs, SelfQRcode can be used instead.

SelfApp Configuration

The SelfAppBuilder allows you to configure your application's verification requirements:

Parameter Type Required Description
appName string Yes The name of your application
scope string Yes A unique identifier for your application
endpoint string Yes The endpoint that will verify the proof
logoBase64 string No Base64-encoded logo to display in the Self app
userId string Yes Unique identifier for the user
disclosures object No Disclosure and verification requirements

Disclosure Options

The disclosures object can include the following options:

Option Type Description
issuing_state boolean Request disclosure of passport issuing state
name boolean Request disclosure of the user's name
nationality boolean Request disclosure of nationality
date_of_birth boolean Request disclosure of birth date
passport_number boolean Request disclosure of passport number
gender boolean Request disclosure of gender
expiry_date boolean Request disclosure of passport expiry date
minimumAge number Verify the user is at least this age
excludedCountries string[] Array of country codes to exclude
ofac boolean Enable OFAC compliance check

Component Props

The SelfQRcodeWrapper component accepts the following props:

Prop Type Required Default Description
selfApp SelfApp Yes - The SelfApp configuration object
onSuccess () => void Yes - Callback function executed on successful verification
websocketUrl string No WS_DB_RELAYER Custom WebSocket URL for verification
size number No 300 QR code size in pixels
darkMode boolean No false Enable dark mode styling
children React.ReactNode No - Custom children to render

Complete Example

Here's a complete example of how to implement the Self QR code in a React application:

'use client';

import React, { useState, useEffect } from 'react';
import SelfQRcodeWrapper, { SelfAppBuilder } from '@selfxyz/qrcode';
import type { SelfApp } from '@selfxyz/qrcode';
import { v4 as uuidv4 } from 'uuid';

function VerificationPage() {
  const [userId, setUserId] = useState<string | null>(null);

  useEffect(() => {
    // Generate a user ID when the component mounts
    setUserId(uuidv4());
  }, []);

  if (!userId) return null;

  // Create the SelfApp configuration
  const selfApp = new SelfAppBuilder({
    appName: 'My Application',
    scope: 'my-application-scope',
    endpoint: 'https://myapp.com/api/verify',
    userId,
    disclosures: {
      // Request passport information
      name: true,
      nationality: true,
      date_of_birth: true,

      // Set verification rules
      minimumAge: 18,
      excludedCountries: ['IRN', 'PRK', 'RUS'],
      ofac: true,
    },
  }).build();

  return (
    <div className="verification-container">
      <h1>Verify Your Identity</h1>
      <p>Scan this QR code with the Self app to verify your identity</p>

      <SelfQRcodeWrapper
        selfApp={selfApp}
        onSuccess={() => {
          // Handle successful verification
          console.log('Verification successful!');
          // Redirect or update UI
        }}
        size={350}
      />

      <p className="text-sm text-gray-500">User ID: {userId.substring(0, 8)}...</p>
    </div>
  );
}

export default VerificationPage;

Example

For a more comprehensive and interactive example, please refer to the playground.

Verification Flow

  1. Your application displays the QR code to the user
  2. The user scans the QR code with the Self app
  3. The Self app guides the user through the passport verification process
  4. The proof is generated and sent to your verification endpoint
  5. Upon successful verification, the onSuccess callback is triggered

The QR code component displays the current verification status with an LED indicator and changes its appearance based on the verification state.