Understanding Bloque’s URN format for identity and resource identification
Bloque uses URNs (Uniform Resource Names) as a standardized way to identify identities and resources across the platform. URNs provide a consistent, globally unique identifier format.
The SDK automatically constructs URNs when you register or connect to an identity. You can also access the URN building logic:
Automatic URN Construction
import { SDK } from '@bloque/sdk';const sdk = new SDK({ auth: { type: 'apiKey', apiKey: 'key_...' }, origin: 'my-app'});// Register a new identity - URN is constructed automaticallyconst session = await sdk.register('[email protected]', { firstName: 'John', lastName: 'Doe'});// Access the URNconsole.log(session.urn);// Output: "did:bloque:my-app:[email protected]"
The URN construction happens in the SDK’s buildUrn method:
packages/sdk/src/bloque.ts:40-47
private buildUrn(alias: string): string { const origin = this.httpClient.origin; if (!origin) { throw new Error('Origin is required to build a urn'); } return `did:bloque:${origin}:${alias}`;}
The same person can have different URNs across different origins:
Multi-App Scenario
// User in mobile appconst mobileSession = await mobileSdk.connect('[email protected]');// URN: "did:bloque:mobile-app:[email protected]"// Same user in web appconst webSession = await webSdk.connect('[email protected]');// URN: "did:bloque:web-app:[email protected]"// These are separate identities with separate data
When using JWT authentication, the URN is resolved during the authenticate() or connect() flow:
authenticate() - Auto-resolve
connect() - Explicit origin
const sdk = new SDK({ platform: 'browser', auth: { type: 'jwt' } // origin not required - will be resolved});// Authenticate with existing JWTconst session = await sdk.authenticate();// Origin and URN are resolved from the JWTconsole.log(session.urn); // "did:bloque:resolved-origin:[email protected]"