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('user@example.com', { firstName: 'John', lastName: 'Doe'});// Access the URNconsole.log(session.urn);// Output: "did:bloque:my-app:user@example.com"
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}`;}
Resources (like accounts) are automatically associated with the authenticated identity’s URN:
const session = await sdk.connect('user@example.com');// session.urn = "did:bloque:my-app:user@example.com"// Create account - automatically associated with the URNconst account = await session.accounts.virtual.create({ currency: 'USD'});// Account is owned by the identity with this URNconsole.log(account.holderUrn); // "did:bloque:my-app:user@example.com"
The same person can have different URNs across different origins:
Multi-App Scenario
// User in mobile appconst mobileSession = await mobileSdk.connect('user@example.com');// URN: "did:bloque:mobile-app:user@example.com"// Same user in web appconst webSession = await webSdk.connect('user@example.com');// URN: "did:bloque:web-app:user@example.com"// 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:user@example.com"