Skip to content

Commit 4b1e399

Browse files
committed
Fix some wallet SDK examples issues found in review
1 parent a83a9d8 commit 4b1e399

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

source/mainnet/net/guides/wallet-sdk/wallet-sdk-credential-deployment.rst

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ The following example demonstrates how a credential deployment transaction is cr
3333
const identity: IdentityObjectV1 = ...;
3434
3535
// The identity provider that was used when creating the identity.
36-
const identityProvider: IdentityProvider = ...;
36+
const identity: IdentityProvider = ...;
37+
const identityProviderIndex = identityProvider.ipInfo.ipIdentity;
3738
3839
// Set up the wallet.
3940
const seedPhrase = 'fence tongue sell large master side flock bronze ice accident what humble bring heart swear record valley party jar caution horn cushion endorse position';
@@ -109,12 +110,12 @@ The following example demonstrates how a credential deployment transaction is cr
109110
import java.util.Collections
110111
import java.util.EnumMap
111112
112-
fun createCredentialDeploymentTransaction(): CredentialDeploymentDetails {
113+
fun createCredentialDeploymentTransaction(identityIndex: Int, credentialCounter: Int): CredentialDeploymentDetails {
113114
// The identity object created previously. See the identity creation section.
114115
val identity: IdentityObject = ...
115116
116-
// The identity provider that was used for creating the identity.
117-
val ipIdentity = ...
117+
// The index of the identity provider that was used for creating the identity.
118+
val identityProviderIndex = ...
118119
119120
val connection = Connection.newBuilder()
120121
.host(nodeAddress)
@@ -125,7 +126,7 @@ The following example demonstrates how a credential deployment transaction is cr
125126
126127
val anonymityRevokers = Iterable { client.getAnonymityRevokers(BlockQuery.BEST) }.associateBy { it.arIdentity.toString() }
127128
val providers = client.getIdentityProviders(BlockQuery.BEST)
128-
val provider = Iterable { providers }.find { it.ipIdentity.value == ipIdentity }!!
129+
val provider = Iterable { providers }.find { it.ipIdentity.value == identityProviderIndex }!!
129130
val global = client.getCryptographicParameters(BlockQuery.BEST)
130131
131132
val seedPhrase = "fence tongue sell large master side flock bronze ice accident what humble bring heart swear record valley party jar caution horn cushion endorse position"
@@ -136,24 +137,24 @@ The following example demonstrates how a credential deployment transaction is cr
136137
val attributeRandomness: MutableMap<AttributeType, String> = EnumMap(AttributeType::class.java)
137138
for (attrType in identity.attributeList.chosenAttributes.keys) {
138139
attributeRandomness[attrType] = wallet.getAttributeCommitmentRandomness(
139-
ipIdentity,
140-
Constants.IDENTITY_INDEX,
141-
Constants.CREDENTIAL_COUNTER,
140+
identityProviderIndex,
141+
identityIndex,
142+
credentialCounter,
142143
attrType.ordinal
143144
)
144145
}
145146
146-
val blindingRandomness = wallet.getSignatureBlindingRandomness(ipIdentity, Constants.IDENTITY_INDEX)
147-
val idCredSec = wallet.getIdCredSec(ipIdentity, Constants.IDENTITY_INDEX)
148-
val prfKey = wallet.getPrfKey(ipIdentity, Constants.IDENTITY_INDEX)
147+
val blindingRandomness = wallet.getSignatureBlindingRandomness(identityProviderIndex, identityIndex)
148+
val idCredSec = wallet.getIdCredSec(identityProviderIndex, identityIndex)
149+
val prfKey = wallet.getPrfKey(identityProviderIndex, identityIndex)
149150
150151
val publicKeys = CredentialPublicKeys.from(
151152
Collections.singletonMap(
152153
Index.from(0),
153154
wallet.getAccountPublicKey(
154-
ipIdentity,
155-
Constants.IDENTITY_INDEX,
156-
Constants.CREDENTIAL_COUNTER
155+
identityProviderIndex,
156+
identityIndex,
157+
credentialCounter
157158
)
158159
), 1
159160
)
@@ -163,7 +164,7 @@ The following example demonstrates how a credential deployment transaction is cr
163164
.globalContext(global)
164165
.arsInfos(anonymityRevokers)
165166
.idObject(identity)
166-
.credNumber(Constants.CREDENTIAL_COUNTER)
167+
.credNumber(credentialCounter)
167168
.attributeRandomness(attributeRandomness)
168169
.blindingRandomness(blindingRandomness)
169170
.credentialPublicKeys(publicKeys)
@@ -241,11 +242,20 @@ is the signing key that corresponds to the public key used when creating the tra
241242
val seedAsHex = Mnemonics.MnemonicCode(seedPhrase.toCharArray()).toSeed().toHexString()
242243
val wallet = ConcordiumHdWallet.fromHex(seedAsHex, Network.TESTNET)
243244
245+
// The credentialCounter and the identityIndex must identical to what was used when deriving
246+
// the keys to create the credential deployment transaction.
247+
val credentialCounter = 0
248+
val identityIndex = 0
249+
250+
// The indentityProvider index must be indentical to the index of the identity provider
251+
// that was used to create the identity that the credential is for.
252+
val identityProviderIndex = 0
253+
244254
val credentialDeploymentSignDigest = Credential.getCredentialDeploymentSignDigest(credentialDeployment)
245255
val signingKey = wallet.getAccountSigningKey(
246-
ipIdentity,
247-
Constants.IDENTITY_INDEX,
248-
Constants.CREDENTIAL_COUNTER
256+
identityProviderIndex,
257+
identityIndex,
258+
credentialCounter
249259
)
250260
251261
return signingKey.sign(credentialDeploymentSignDigest)

source/mainnet/net/guides/wallet-sdk/wallet-sdk-identity-creation.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ The first step is to create the actual identity request. To do this, you need th
8787
8888
import cash.z.ecc.android.bip39.Mnemonics
8989
import cash.z.ecc.android.bip39.toSeed
90-
import com.concordium.example.wallet.services.ConcordiumWalletProxyService
9190
import com.concordium.sdk.ClientV2
9291
import com.concordium.sdk.Connection
9392
import com.concordium.sdk.TLSConfig
@@ -118,7 +117,7 @@ The first step is to create the actual identity request. To do this, you need th
118117
val seedPhrase = "fence tongue sell large master side flock bronze ice accident what humble bring heart swear record valley party jar caution horn cushion endorse position"
119118
@OptIn(ExperimentalStdlibApi::class)
120119
val seedAsHex = Mnemonics.MnemonicCode(seedPhrase.toCharArray()).toSeed().toHexString()
121-
val wallet = ConcordiumHdWallet.fromHex(seedAsHex, Network.TESTNET)
120+
val wallet = ConcordiumHdWallet.fromHex(seedAsHex, Network.TESTNET) // Or Network.MAINNET, if working on mainnet.
122121
123122
val identityProviderIndex = identityProvider.ipInfo.ipIdentity.value
124123
val idCredSec = wallet.getIdCredSec(identityProviderIndex, identityIndex)

0 commit comments

Comments
 (0)