resolve method
Resolves a handle (alice.example, optionally @/at:// prefixed) or a
DID (did:plc: / did:web:) to its atproto identity.
Implementation
@override
Future<ResolvedIdentity> resolve(final String identity) async {
var normalized = identity.trim();
if (normalized.startsWith('at://')) {
normalized = normalized.substring('at://'.length);
}
if (normalized.startsWith('@')) normalized = normalized.substring(1);
if (normalized.isEmpty) {
throw ArgumentError.value(identity, 'identity', 'must not be empty');
}
final String did;
final String? handle;
if (normalized.startsWith('did:')) {
did = normalized;
handle = null;
} else {
handle = normalized.toLowerCase();
did = await _resolveHandle(handle);
}
final didDocument = await _resolveDidDocument(did);
if (handle != null) {
final alsoKnownAs = didDocument['alsoKnownAs'];
final claimsHandle =
alsoKnownAs is List &&
alsoKnownAs.whereType<String>().any(
(final aka) => aka.toLowerCase() == 'at://$handle',
);
if (!claimsHandle) {
throw IdentityException(
'Bidirectional handle verification failed: the DID document for '
'"$did" does not list "at://$handle" in "alsoKnownAs"',
);
}
}
return ResolvedIdentity(
did: did,
pds: _extractPdsEndpoint(didDocument, did),
handle: handle,
signingKey: signingKeyOf(didDocument, did),
);
}