getPublicKey method
Implementation
Future<TrezorPublicKey> getPublicKey({
required List<int> addressN,
Future<String> Function()? onPinRequest,
Future<String> Function()? onPassphraseRequest,
}) async {
if (_session == null) {
throw StateError('Not connected - call connectDevice() first');
}
var (msgType, payload) = await call(
TrezorMsgType.getPublicKey,
buildGetPublicKey(addressN: addressN),
);
while (true) {
if (msgType == TrezorMsgType.pinMatrixRequest) {
if (onPinRequest == null) {
throw StateError(
'PIN requested but no onPinRequest callback provided',
);
}
final pin = await onPinRequest();
(msgType, payload) = await call(
TrezorMsgType.pinMatrixAck,
buildPinMatrixAck(pin),
);
} else if (msgType == TrezorMsgType.passphraseRequest) {
final passphrase =
onPassphraseRequest != null ? await onPassphraseRequest() : '';
(msgType, payload) = await call(
TrezorMsgType.passphraseAck,
buildPassphraseAck(passphrase: passphrase),
);
} else if (msgType == TrezorMsgType.buttonRequest) {
(msgType, payload) = await call(
TrezorMsgType.buttonAck,
buildButtonAck(),
);
} else if (msgType == TrezorMsgType.publicKey) {
return parsePublicKey(payload);
} else if (msgType == TrezorMsgType.failure) {
final failure = parseFailure(payload);
throw StateError(
'Device returned failure (code ${failure.code}): ${failure.message}',
);
} else {
throw StateError('Unexpected message type: $msgType');
}
}
}