getDid method
Returns the DID associated with hdPath
.
Implementation
Future<String> getDid(String hdPath,
[KeyType keyType = KeyType.secp256k1]) async {
if (keyType == KeyType.secp256k1) {
var master = BIP32.fromSeed(_keyBox!.get('seed'));
var key = master.derivePath(hdPath);
return _bip32KeyToDid(key);
} else if (keyType == KeyType.ed25519) {
var key = await ED25519_HD_KEY.derivePath(
hdPath, _keyBox!.get('seed').toList());
return await _edKeyToDid(key);
} else if (keyType == KeyType.x25519) {
var key = await ED25519_HD_KEY.derivePath(
hdPath, _keyBox!.get('seed').toList());
return await _edKeyToXKeyDid(key);
} else if (keyType == KeyType.p384 ||
keyType == KeyType.p256 ||
keyType == KeyType.p521) {
Curve c;
List<int> prefix;
if (keyType == KeyType.p521) {
c = getP521();
prefix = [130, 36];
} else if (keyType == KeyType.p384) {
c = getP384();
prefix = [129, 36];
} else {
c = getP256();
prefix = [128, 36];
}
var k = PrivateKey(c, hexToInt(hdPath));
return 'did:key:z${base58BitcoinEncode(Uint8List.fromList(prefix + hexToBytes(k.publicKey.toCompressedHex())))}';
} else {
throw Exception('Unknown KeyType');
}
}