55 *
66 * Demonstrates how to:
77 * 1. Generate an Ed25519 keypair
8- * 2. Create did:trail DIDs ( self, org, agent)
8+ * 2. Create did:trail DIDs in self, org, and agent modes
99 * 3. Build DID Documents
10- * 4. Resolve a did:trail DID offline (self-mode )
10+ * 4. Resolve a did:trail:self DID locally (offline )
1111 *
1212 * Prerequisites:
1313 * npm install @trailprotocol/core
@@ -29,42 +29,46 @@ async function main() {
2929 // -------------------------------------------------------
3030 // Step 1: Generate an Ed25519 keypair
3131 // -------------------------------------------------------
32+ // This keypair is the cryptographic root of the DID identity.
3233 const keys = generateKeyPair ( ) ;
3334 console . log ( '=== Key Generation ===' ) ;
3435 console . log ( 'Public key (multibase):' , keys . publicKeyMultibase ) ;
3536 console . log ( 'Public key (JWK):' , JSON . stringify ( keys . publicKeyJwk , null , 2 ) ) ;
3637 console . log ( ) ;
3738
3839 // -------------------------------------------------------
39- // Step 2: Create DIDs in all three modes
40+ // Step 2: Create DIDs in all three TRAIL modes
4041 // -------------------------------------------------------
41-
42- // Self DID (Tier 0) - no registry needed, local trust only
4342 const selfDid = createSelfDid ( keys . publicKeyMultibase ) ;
43+ const orgDid = createOrgDid ( 'Acme Corporation' , keys . publicKeyMultibase ) ;
44+ const agentDid = createAgentDid ( 'Sales Assistant' , keys . publicKeyMultibase ) ;
45+
4446 console . log ( '=== DID Creation ===' ) ;
4547 console . log ( 'Self DID: ' , selfDid ) ;
46-
47- // Org DID (Tier 1) - for organizations with KYB attestation
48- const orgDid = createOrgDid ( 'Acme Corporation' , keys . publicKeyMultibase ) ;
4948 console . log ( 'Org DID: ' , orgDid ) ;
50-
51- // Agent DID (Tier 2) - for AI agents with full trust chain
52- const agentDid = createAgentDid ( 'Sales Assistant' , keys . publicKeyMultibase ) ;
5349 console . log ( 'Agent DID:' , agentDid ) ;
5450 console . log ( ) ;
5551
52+ console . log ( 'Mode summary:' ) ;
53+ console . log ( ' self -> local/offline identity using embedded public key' ) ;
54+ console . log ( ' org -> organization identifier format for registry-backed use' ) ;
55+ console . log ( ' agent -> agent/service identifier format, typically linked to a parent org' ) ;
56+ console . log ( ) ;
57+
5658 // -------------------------------------------------------
5759 // Step 3: Build DID Documents
5860 // -------------------------------------------------------
61+ // A DID Document describes the public keys, verification methods,
62+ // and optional services associated with a DID.
5963 console . log ( '=== DID Documents ===' ) ;
6064
61- // Self DID Document - simplest form
65+ // Self DID Document: simplest form, suitable for local/offline verification.
6266 const selfDoc = createDidDocument ( selfDid , keys , { mode : 'self' } ) ;
6367 console . log ( 'Self DID Document:' ) ;
6468 console . log ( JSON . stringify ( selfDoc , null , 2 ) ) ;
6569 console . log ( ) ;
6670
67- // Agent DID Document - with parent organization reference
71+ // Agent DID Document: includes a parent organization reference and registry service.
6872 const agentDoc = createDidDocument ( agentDid , keys , {
6973 mode : 'agent' ,
7074 parentOrganization : orgDid ,
@@ -77,8 +81,8 @@ async function main() {
7781 // -------------------------------------------------------
7882 // Step 4: Resolve a self DID (offline resolution)
7983 // -------------------------------------------------------
80- // Self-mode DIDs can be resolved without a registry because
81- // the public key is embedded in the DID itself .
84+ // Self-mode DIDs can be resolved without a registry because the
85+ // public key is embedded directly in the DID identifier .
8286 console . log ( '=== DID Resolution ===' ) ;
8387 const resolver = new TrailResolver ( ) ;
8488 const result = await resolver . resolve ( selfDid ) ;
@@ -90,10 +94,9 @@ async function main() {
9094 console . log ( ' Trust Tier:' , result . didDocument [ 'trail:trailTrustTier' ] ) ;
9195 console . log ( ) ;
9296
93- // TODO: Add registry-based resolution for org/agent DIDs
94- // (requires a running TRAIL Registry instance)
95-
97+ // Registry-based resolution for org/agent DIDs is typically performed
98+ // via the TRAIL registry HTTP API rather than offline reconstruction.
9699 console . log ( 'Done. All examples completed successfully.' ) ;
97100}
98101
99- main ( ) . catch ( console . error ) ;
102+ main ( ) . catch ( console . error ) ;
0 commit comments