# Id helper

Id helper allows to easily perform all the operations related to the commercio.network id module.

# Provided operations

  1. Returns the DidDocument associated with the given did, or null if no Did Document was found.
    suspend fun getDidDocument(did: Did, wallet: Wallet): DidDocument?
    
    1
  2. Performs a transaction setting the specified didDocument as being associated with the address present inside the specified wallet. Optionally fee and broadcasting mode parameters can be specified.
    suspend fun setDidDocument(        
       didDocument: DidDocument,
       wallet: Wallet,
       fee: StdFee? = null,
       mode: BroadcastingMode? = null
    ): TxResponse
    
    1
    2
    3
    4
    5
    6
  3. Performs a transaction setting the didDocuments list as being associated with the address present inside the specified wallet. Optionally fee and broadcasting mode parameters can be specified.
    suspend fun setDidDocumentsList(
       didDocuments: List<DidDocument>,
       wallet: Wallet,
       fee: StdFee? = null,
       mode: BroadcastingMode? = null
    ): TxResponse 
    
    1
    2
    3
    4
    5
    6
  4. Creates a new Did power up request from wallet address for the given pairwiseDid and of the given amount.
    Signs everything that needs to be signed (i.e. the signature JSON inside the payload) with the private key contained inside the given wallet and the private key. Optionally fee and broadcasting mode parameters can be specified.
    suspend fun requestDidPowerUp(
        pairwiseDid: Did,
        amount: List<StdCoin>,
        wallet: Wallet,
        privateKey: RSAPrivateKey,
        fee: StdFee? = null,
        mode: BroadcastingMode? = null
    ): TxResponse
    
    1
    2
    3
    4
    5
    6
    7
    8
  5. Sends a new transaction from the sender wallet to request a list of Did PowerUp requestDidPowerUpsList. Optionally fee and broadcasting mode parameters can be specified.
    suspend fun requestDidPowerUpsList(
       requestDidPowerUps: List<RequestDidPowerUp>,
       wallet: Wallet,
       fee: StdFee? = null,
       mode: BroadcastingMode? = null
    ): TxResponse
    
    1
    2
    3
    4
    5
    6

# Usage examples

    val info = NetworkInfo(
        bech32Hrp = "did:com:", 
        lcdUrl = "http://localhost:1317"
    )

    val userMnemonic = listOf(
        "will",
        "hard",
        "topic",
        "spray",
        "beyond",
        "ostrich",
        "moral",
        "morning",
        "gas",
        "loyal",
        "couch",
        "horn",
        "boss",
        "across",
        "age",
        "post",
        "october",
        "blur",
        "piece",
        "wheel",
        "film",
        "notable",
        "word",
        "man"
    )
    
    val userWallet = Wallet.derive(mnemonic = userMnemonic, networkInfo = info)
    

    // Create did document
    val rsaVerificationKeyPair = KeysHelper.generateRsaKeyPair()
    val rsaSignatureKeyPair = KeysHelper.generateRsaKeyPair(type = "RsaSignatureKey2018")

    val didDocument = DidDocumentHelper.fromWallet(
        wallet, 
        listOf(rsaVerificationKeyPair.publicKey, rsaSignatureKeyPair.publicKey)
    )

    try {
      
        // Set the did document
        val response = IdHelper.setDidDocument(didDocument, userWallet)
    
        // Send Power Up to the Tumbler
        val msgDeposit = listOf(
            MsgSend(
                amount = listOf(StdCoin(denom = "ucommercio", amount = "100")),
                fromAddress = userWallet.bech32Address,
                toAddress = "did:com:14ttg3eyu88jda8udvxpwjl2pwxemh72w0grsau"
            )
        )

        TxHelper.createSignAndSendTx(
            msgs = msgDeposit,
            wallet = wallet
        )
    
        // Request a did power up
        val pairwiseMnemonic = listOf(
                "push",
                "grace",
                "power",
                "desk",
                "arrive",
                "horror",
                "gallery",
                "physical",
                "kingdom",
                "ecology",
                "fat",
                "firm",
                "future",
                "service",
                "table",
                "little",
                "live",
                "reason",
                "maximum",
                "short",
                "motion",
                "planet",
                "stage",
                "second"
        )
         
        val pairwiseWallet = Wallet.derive(
            mnemonic = pairwiseMnemonic, 
            networkInfo = info
        )
        
        val depositAmount = listOf(StdCoin(denom = "ucommercio", amount = "100"))
         
        IdHelper.requestDidPowerUp(
            pairwiseDid = Did(pairwiseWallet.bech32Address),
            amount = depositAmount,
            wallet = userWallet,
            privateKey = rsaSignatureKeyPair.privateKey
        )
    } catch (e: Exception){
        throw e
    }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107