02. GGS-1 Identity MW API

Identity Management

GGS-1 Identity provides user profile management with privacy-preserving merkle tree verification and blockchain anchoring.

Overview

Purpose: Create and manage verifiable user identities with configurable field privacy levels.

Key Features:

  • Customizable profile fields (name, bio, social links, etc.)

  • Privacy levels per field (private, community, public)

  • Merkle tree for verifiable credentials

  • Blockchain anchoring for tamper-proof verification

  • Profile image upload

Location: src/packages/identity/


API Endpoints

Get Current User's Identity

Fetch the authenticated user's identity profile.

Endpoint: GET /identity/

Authentication: Required (JWT)

Implementation:

Response:

Example Response:

Usage:


Get Public Identity by ID

Fetch another user's public identity information.

Endpoint: GET /identity/public/{id}

Authentication: Not required

Parameters:

  • id (path): Identity UUID

Implementation:

Response: Same structure as GET /identity/ but only includes fields with visibility: 'public'


Get Identity Profile Image

Download the profile image for a specific identity.

Endpoint: GET /identity/public/{id}/image

Authentication: Not required

Parameters:

  • id (path): Gen6 Address

Implementation:

Response: Image object URL string

Usage:


Calculate Identity Merkle Tree

Generate a merkle tree hash for identity verification.

Endpoint: POST /identity/merkle

Authentication: Not required

Purpose: Calculate the root hash before creating/updating identity to ensure data integrity.

Request:

Request Body:

Response:

Example Request:

Example Response:

Usage Flow:

  1. User fills out identity form

  2. Frontend calculates merkle tree via /identity/merkle

  3. Frontend stores hash on blockchain

  4. Frontend creates identity via /identity/ with the same root_hash


Create Identity

Create a new identity profile for the authenticated user.

Endpoint: POST /identity/

Authentication: Required (JWT)

Request:

Request Body:

Response: Created Identity object

Usage:

Important: Always calculate merkle tree and store on blockchain before creating identity.


Update Identity

Update an existing identity profile.

Endpoint: PUT /identity/

Authentication: Required (JWT)

Request:

Request Body: Same as create

Response: Updated Identity object

Note: Updating identity requires recalculating the merkle tree and storing the new hash on blockchain.


Upload Profile Image

Upload or update the user's profile image.

Endpoint: PUT /identity/image

Authentication: Required (JWT)

Request:

Request Body: FormData with image file

Supported Formats: JPEG, PNG, GIF, WebP

File Size Limit: Check backend configuration (typically 5MB)

Response:

Usage:


Blockchain Integration

Store Identity Hash On-Chain

Anchor the identity data hash on the blockchain for tamper-proof verification.

Extrinsic: api.tx.dataRegistry.storeData()

Parameters:

  • projectId: 20250923 (Identity project ID)

  • dataHash: Blake2 hash of the full identity object (from deterministicObjectBlake2Hash)

Implementation:

Usage:

Transaction Flow:

  1. User submits identity form

  2. Frontend calculates Blake2 hash of full identity object for blockchain

  3. Frontend calculates merkle root for database verification

  4. Frontend stores hash on blockchain

  5. Frontend creates identity in database with merkle root

Verification: Anyone can verify the identity by:

  1. Recalculating the Blake2 hash from the identity data

  2. Comparing with the on-chain hash

  3. Additionally, the merkle root in the database can be used for field-level verification


Privacy Levels

Identity fields support three visibility levels:

Private

  • Who can see: Only the identity owner

  • Use case: Sensitive data (email, phone, private notes)

  • Merkle tree: Included in hash but not revealed

Community

  • Who can see: Gen6 community members (authenticated users)

  • Use case: Semi-public data (Discord, Telegram handles)

  • Merkle tree: Included in hash and partially revealed

Public

  • Who can see: Everyone (no authentication required)

  • Use case: Public profile (name, bio, social links)

  • Merkle tree: Included in hash and fully revealed

Configuration Example:


Custom Fields

Add arbitrary key-value pairs to identity profiles.

Implementation:

Privacy: Each custom field has its own visibility configuration.

Ordering: Use custom_fields_order to control display order.


Complete Identity Creation Flow

Step-by-Step Guide

Step 1: Prepare Identity Data

Step 2: Calculate Merkle Tree for Database

Step 3: Store Identity Hash on Blockchain

Step 4: Create Identity in Database

Step 5: Upload Profile Image (Optional)


Query Keys

TanStack Query Keys:


Error Handling

Common Errors

"Identity already exists"

  • Cause: User already has an identity

  • Solution: Use updateIdentity() instead of createIdentity()

"Transaction failed"

  • Cause: Blockchain transaction rejected

  • Solution: Check wallet balance and network status


Best Practices

  1. Always calculate merkle tree first - Ensures data integrity

  2. Store on blockchain before database - Prevents orphaned hashes

  3. Set appropriate visibility levels - Protect sensitive data

  4. Handle errors gracefully - Show user-friendly messages


Next Steps

  • Real-Seal - Sign documents with verified identity

  • Ncrypt - Send messages with identity verification

Last updated

Was this helpful?