All pages
Powered by GitBook
1 of 1

Loading...

Agent

Wallet Config

To create an Agent you need to first create a wallet config object to tell the Agent how to initialize your wallet.

val walletConfig: WalletConfig = WalletConfig(
    uri 
let walletConfig = WalletConfig(
    uri:

Mediation Config

Next create a mediation config to pass to our Agent. The reconnection interval in the below section has two values that indicate the min and max amount of time in a back off strategy on which to try and contact the mediator.

val mediationConfig: MediationConfig = MediationConfig(   
    mediatorInvitationUrl 
let mediationConfig = MediationConfig(
    mediatorInvitationUrl:

Pool Config

The pool config is used to indicate what networks/ledgers the Agent can read from. Not all ledgers contain all schemas or credential definitions and some are more volatile than others. The standard way to declare a pool config is shown in the examples below and again the React Native portion of this document.

The first value used to create a pool config is the genesisUrl. This is a url point to the genesis file in a raw string format. This file is used to establish connection and provide data about the network/ledger.

The second value used to create a pool config is the isProduction boolean flag. This indicates to the agent whether to treat the network/ledger as a production environment or not.

The last value needed to create a pool config is the indyNamespace. This string value is the name by which the network/ledger is known and is prepended to schemas and credential definitions to identify what network/ledger they are on. Misspelling this value or having an incorrect variation will cause errors when reading from the ledger.

Once the Agent is created and configured you will have to call agent.start() before you can use the agent for anything. When the app is closing agent.stop() should be called to safely shut the agent down between sessions.

If you want to remove the Agent or reset the wallet you can call agent.delete() to remove all data the agent has saved.

Creating an Agent follows similar steps as Kotlin and Swift but has some additional steps specific to React Native.

Similar to Kotlin and Swift some config object must be created to customize the Agent. Additionally for creating a pool config from a url pointing to genesis files you must pass the ProvenReactNative object imported from the @proven-mobile/react-native package.

The actual Agent is created by passing the created config objects along with some other options. Again the ProvenReactNative object must be included in the Agent constructor along with the provenEventsFactory that facilitates getting events from the Agent to the React Native level.

Once the Agent has been constructed you can start the Agent with the following code. The React Native code allows the use of the Javascript Promise syntax for async operations:

Similarly, the agent.stop() and agent.delete() functions exist on the agent object along with access to all other modules and their respective functions mirroring the Kotlin and Swift implementations.

=
"sqlite://pathWhereYouWantDataStored/local.db"
,
// options are raw(raw random key), kdf:argon2i(Encrypted Key), none(testing only)
keyMethod = "raw",
// Should be randomly generated or derived from a pin or password, must be able to be repeatedly accessed
passkey = "TheActualKeyThatUnlocksTheWallet",
id = "Unique id for this wallet"
)
=
"Mediation connection url for the default mediator you want to use"
,
// Optional parameter to indicate how often, in milliseconds,the Agent should try to reconnect to the mediator
baseMediatorReconnectionIntervalMS = 500,
// Optional parameter to indicate the max amount of time between attempts to contact the mediator
maximumMediatorReconnectionIntervalMS: Int = 10000
)
"
sqlite://pathWhereYouWantDataStored/local.db
"
,
keyMethod: "raw",
passkey: "TheActualKeyThatUnlocksTheWallet",
id: "Unique id for this wallet"
)
"
Mediation connection URL for the default mediator you want to use
"
,
// Optional parameter to indicate how often, in milliseconds, the Agent should try to reconnect to the mediator
baseMediatorReconnectionIntervalMS: 500,
// Optional parameter to indicate the max amount of time between attempts to contact the mediator
maximumMediatorReconnectionIntervalMS: 10000
)

Configuring an Agent

React Native

    val indicioDemoNet = IndyVDRPoolConfig.fromUrl(
        genesisUrl = "https://raw.githubusercontent.com/Indicio-tech/indicio-network/main/genesis_files/pool_transactions_demonet_genesis",
        isProduction = false,
        indyNamespace = "indicio-demo-net"
    )
    let indicioDemoNet = IndyVDRPoolConfig.companion.fromUrl(
        genesisUrl = "https://raw.githubusercontent.com/Indicio-tech/indicio-network/main/genesis_files/pool_transactions_demonet_genesis",
        isProduction = false,
        indyNamespace = "indicio-demo-net"
    )
val agent: Agent = Agent(
    walletConfig = walletConfig,
    mediationConfig = mediationConfig,
    pools = ListOf(
        indicioDemoNet
    ),
    pickupBatchSize = 10, // max number of message that can be picked up at once from the mediator
    defaultConnectionLabel = "Proven SDK", // The label the Agent will use in didComm communication
    enableLogging = false,
    autoAcceptConnections = true, 
    autoAcceptCredentials = false,
    customLogger = null // (message: String)->Unit Callback to use for logging instead of `println()`
)
let agent = Agent(
    walletConfig: walletConfig,
    mediationConfig: mediationConfig,
    pools: [
        indicioDemoNet
    ],
    pickupBatchSize: 10, // max number of message that can be picked up at once from the mediator
    defaultConnectionLabel: "Proven SDK", // The label the Agent will use in didComm communication
    enableLogging: false,
    autoAcceptConnections: true, 
    autoAcceptCredentials: false,
    customLogger: nil // (message: String)->Void Callback to use for logging instead of `println()`
)

// Start agent (KMPNativeCoroutines)
try await asyncFunction(for: agent.start(startUpTimeout: 10000))

// Start agent (Completion handler)
agent.start(startUpTimeout: 10000){error in
    if(error != nil){
        // Handle error
    }
    // Code to be called when agent started
}

// Start agent (Without KMPNativeCoroutines)
let error: ProvenError? = await agent.start(startUpTimeout: 10000)
if(error != nil){
    // Handle error
}
import RNFS from 'react-native-fs';
import ProvenReactNative, {
    provenEventsFactory,
} from '@proven-mobile/react-native';
import {
    Agent,
    IndyPoolConfig,
    type MediationConfig,
    type WalletConfig
} from '@proven-mobile/core';

const walletConfig: WalletConfig = {
    uri: `sqlite://${RNFS.DocumentDirectoryPath}/local.db`,
    keyMethod: 'raw',
    passkey: 'CwNJroKHTSSj3XvE7ZAnuKiTn2C4QkFvxEqfm5rzhNrb',
    id: 'ReactNativeTest',
    profile: 'test',
};

const mediationConfig: MediationConfig = {
    mediatorInvitationUrl:
    'url invite to the mediator you want to use',
    baseMediatorReconnectionIntervalMS: 50,
    maximumMediatorReconnectionIntervalMS: 10000,
};

const poolConfig: IndyVDRPoolConfig = await IndyPoolConfig.fromURL(
    ProvenReactNative,
    'https://raw.githubusercontent.com/Indicio-tech/indicio-network/main/genesis_files/pool_transactions_demonet_genesis',
    false,
    'indicio-demo-net',
);
import ProvenReactNative, {
    provenEventsFactory,
} from '@proven-mobile/react-native';

const agent = new Agent(
    ProvenReactNative,
    provenEventsFactory,
    walletConfig,
    mediationConfig,
    [poolConfig],
    'RN',
    10,
    true,
    true,
    true,
    console.info // (message: string)->Void Callback to use for logging, defaults to console.log
);
await agent.start();