简体   繁体   English

在尝试与其共享密钥之前,有什么方法可以验证 @Sign 是否存在?

[英]Is there any way to verify that a @Sign exists before trying to share a key with it?

I am using the @protocol in a Flutter app and was wondering if there was a way to verify if another @sign exists before trying to share a key with it.我在 Flutter 应用程序中使用@protocol,想知道是否有办法在尝试与其共享密钥之前验证是否存在另一个@sign。 For now I made a function that will try to share a key with the specified @sign.现在我制作了一个 function,它将尝试与指定的@sign 共享一个密钥。 If there is an AtLookUpException , I consider the user non-existent:如果有AtLookUpException ,我认为用户不存在:

 /// Check if user exists in this namespace by trying to share a key with them
  Future<bool> checkForUser(String atSign) async {
    /// Do test send to see if @ sign exists
    AtKey testKey = AtKey();
    testKey.key = 'test';

    testKey.sharedWith = atSign;

    try {
      await atProtocolService.atClientImpl.put(testKey, 'Are you there?');
      return true;
    } on AtLookUpException catch (e){
      print('AtLookUpException: '+ e.errorMessage);
      return false;
    }

} }

For further verification, you could check the error message of the AtLookUpException which will look like this:为了进一步验证,您可以检查 AtLookUpException 的错误消息,如下所示:

Secondary server not found: No secondary url found for atsign: @bob未找到辅助服务器:找不到用于 atsign 的辅助 url:@bob

Is this the best or quickest way to do this?这是最好或最快的方法吗?

There is a library available to you that you can use:有一个可供您使用的库:

https://github.com/atsign-foundation/at_libraries/tree/master/at_server_status https://github.com/atsign-foundation/at_libraries/tree/master/at_server_status

Feel free to adapt any part of the code as you like to fit your use case.随意调整代码的任何部分,以适应您的用例。

As always, your feedback is welcome.一如既往,欢迎您的反馈。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM