fetchAgent static method
Implementation
static Future<List<Object>> fetchAgent(
Map<String, String> queryParams, bool local) async {
String delegationString = queryParams['del'].toString();
String decodedDelegation = Uri.decodeComponent(delegationString);
DelegationChain delegationChain =
DelegationChain.fromJSON(jsonDecode(decodedDelegation));
DelegationIdentity delegationIdentity =
DelegationIdentity(_newIdentity!, delegationChain);
// Storing keys in local for autoLogin
SecureStore.writeSecureData(
"pubKey", bytesToHex(_newIdentity!.getKeyPair().publicKey.toDer()));
SecureStore.writeSecureData(
"privKey", bytesToHex(_newIdentity!.getKeyPair().secretKey));
SecureStore.writeSecureData("delegation", delegationString);
_principalId = delegationIdentity.getPrincipal().toText();
_newAgent = local
? HttpAgent(
options: HttpAgentOptions(
identity: delegationIdentity,
),
defaultHost: 'localhost',
defaultPort: 4943,
defaultProtocol: 'http',
)
: HttpAgent(
options: HttpAgentOptions(
identity: delegationIdentity,
host: 'icp-api.io',
),
);
return [_newAgent!, delegationIdentity];
}