[DEPRECATED] Go implementation of plcbundle

did resolver optimalizations

+27 -16
+1 -1
bundle/did_index.go
··· 97 shardDir: shardDir, 98 configPath: configPath, 99 shardCache: make(map[uint8]*mmapShard), 100 - maxCache: 10, // Keep 20 hot shards in memory (~120 MB) 101 evictionThreshold: 25, 102 config: config, 103 logger: logger,
··· 97 shardDir: shardDir, 98 configPath: configPath, 99 shardCache: make(map[uint8]*mmapShard), 100 + maxCache: 25, // Keep 20 hot shards in memory (~120 MB) 101 evictionThreshold: 25, 102 config: config, 103 logger: logger,
+26 -15
plc/resolver.go
··· 76 77 // Initialize state on first operation 78 if state == nil { 79 - state = &DIDState{DID: did} 80 } 81 82 // Apply operation to state ··· 132 133 // Handle legacy handle format 134 if handle, ok := opData["handle"].(string); ok { 135 if len(state.AlsoKnownAs) == 0 { 136 state.AlsoKnownAs = []string{"at://" + handle} 137 } ··· 166 167 // StateToDIDDocument converts internal PLC state to W3C DID document format 168 func StateToDIDDocument(state *DIDState) *DIDDocument { 169 - // Detect key types to determine correct @context 170 - contexts := []string{"https://www.w3.org/ns/did/v1"} 171 172 - hasMultikey := false 173 hasSecp256k1 := false 174 hasP256 := false 175 176 - // Check verification method key types 177 for _, didKey := range state.VerificationMethods { 178 keyType := detectKeyType(didKey) 179 switch keyType { ··· 181 hasSecp256k1 = true 182 case "p256": 183 hasP256 = true 184 - default: 185 - hasMultikey = true 186 } 187 } 188 189 - // Add appropriate context URLs 190 - if hasMultikey || hasSecp256k1 || hasP256 { 191 - contexts = append(contexts, "https://w3id.org/security/multikey/v1") 192 - } 193 if hasSecp256k1 { 194 contexts = append(contexts, "https://w3id.org/security/suites/secp256k1-2019/v1") 195 } ··· 198 } 199 200 doc := &DIDDocument{ 201 - Context: contexts, 202 - ID: state.DID, 203 - AlsoKnownAs: state.AlsoKnownAs, 204 } 205 206 // Convert services ··· 212 }) 213 } 214 215 - // Keep verification methods with full DID (they're correct): 216 for id, didKey := range state.VerificationMethods { 217 doc.VerificationMethod = append(doc.VerificationMethod, VerificationMethod{ 218 ID: state.DID + "#" + id,
··· 76 77 // Initialize state on first operation 78 if state == nil { 79 + state = &DIDState{ 80 + DID: did, 81 + RotationKeys: []string{}, 82 + VerificationMethods: make(map[string]string), 83 + AlsoKnownAs: []string{}, 84 + Services: make(map[string]ServiceDefinition), 85 + } 86 } 87 88 // Apply operation to state ··· 138 139 // Handle legacy handle format 140 if handle, ok := opData["handle"].(string); ok { 141 + // Only set if alsoKnownAs is empty 142 if len(state.AlsoKnownAs) == 0 { 143 state.AlsoKnownAs = []string{"at://" + handle} 144 } ··· 173 174 // StateToDIDDocument converts internal PLC state to W3C DID document format 175 func StateToDIDDocument(state *DIDState) *DIDDocument { 176 + // Base contexts - ALWAYS include multikey (matches PLC directory behavior) 177 + contexts := []string{ 178 + "https://www.w3.org/ns/did/v1", 179 + "https://w3id.org/security/multikey/v1", // ← Always include this 180 + } 181 182 hasSecp256k1 := false 183 hasP256 := false 184 185 + // Check verification method key types for additional contexts 186 for _, didKey := range state.VerificationMethods { 187 keyType := detectKeyType(didKey) 188 switch keyType { ··· 190 hasSecp256k1 = true 191 case "p256": 192 hasP256 = true 193 } 194 } 195 196 + // Add suite-specific contexts only if those key types are present 197 if hasSecp256k1 { 198 contexts = append(contexts, "https://w3id.org/security/suites/secp256k1-2019/v1") 199 } ··· 202 } 203 204 doc := &DIDDocument{ 205 + Context: contexts, 206 + ID: state.DID, 207 + AlsoKnownAs: []string{}, // ← Empty slice 208 + VerificationMethod: []VerificationMethod{}, // ← Empty slice 209 + Service: []Service{}, // ← Empty slice 210 + } 211 + 212 + // Copy alsoKnownAs if present 213 + if len(state.AlsoKnownAs) > 0 { 214 + doc.AlsoKnownAs = state.AlsoKnownAs 215 } 216 217 // Convert services ··· 223 }) 224 } 225 226 + // Keep verification methods with full DID 227 for id, didKey := range state.VerificationMethods { 228 doc.VerificationMethod = append(doc.VerificationMethod, VerificationMethod{ 229 ID: state.DID + "#" + id,