Create Holder
This function allows you to create a holder from a Baby JubJub key and a specific method did.
It is recommended that your holders use the available wallets (wallets by default already create your did, manage did recovery, manage credentials...), this function is intended to simulate the creation of a holder to test your integration.
Therefore, we recommend that the Baby JubJub key be a Local one, to be free of charge.
Examples
- Typescript
- Python
- Java
- PHP
- Golang
import { Bloock, KeyClient, IdentityClient, KeyType, DidMethod, Key } from '@bloock/sdk';
try {
// we set the API key and create a client
Bloock.setApiKey(process.env['API_KEY'] || "");
// we set de identity managed API host you have deployed
Bloock.setIdentityApiHost(process.env['IDENTITY_MANAGED_API_HOST'] || "");
// initialize the Key Client
const keyClient = new KeyClient();
// initialize the IdentityClient
const identityClient = new IdentityClient();
// create the Baby JubJub local key
const localKey = await keyClient.newLocalKey(KeyType.Bjj);
// we create the holder, passing the Baby JubJub key and holder did method
const holderKey = new Key(localKey)
const hodlerDidMethod = DidMethod.PolygonID
const holder = await identityClient.createHolder(holderKey, hodlerDidMethod)
console.log(holder.did.did) // will print the Holder DID public identifier. Ex: did:polygonid:polygon:main:2qCU58EJgrELSJT6EzT27Rw9DhvwamAdbMLpePztYq
console.log(holder.did.didMethod) // will return the DID method we chosed. Ex: identity.PolygonID
console.log(holder.key) // will return the Key BJJ object associated to the Holder.
} catch (e) {
console.log(e);
}
import os
import bloock
from bloock.client.identity import IdentityClient
from bloock.client.key import KeyClient
from bloock.entity.key.key_type import KeyType
from bloock.entity.key.key import Key
from bloock.entity.identity.did_method import DidMethod
# we set the API key and create a client
bloock.api_key = os.environ["API_KEY"]
# we set de identity managed API host you have deployed
bloock.identity_api_host = os.environ["IDENTITY_MANAGED_API_HOST"]
# initialize the Key Client
key_client = KeyClient()
# initialize the IdentityClient
identity_client = IdentityClient()
# create the Baby JubJub local key
local_key = key_client.new_local_key(KeyType.Bjj)
# we create the holder, passing the Baby JubJub key and holder did method
holder_key = Key(local_key)
holder_did_method = DidMethod.PolygonID
holder = identity_client.create_holder(holder_key, holder_did_method)
# will print the Holder DID public identifier.
# Ex: did:polygonid:polygon:main:2qCU58EJgrELSJT6EzT27Rw9DhvwamAdbMLpePztYq
print(holder.did)
# will return the DID method we chosed. Ex: identity.PolygonID
print(holder.did_method)
# will return the Key BJJ object associated to the Holder.
print(holder.key)
import java.io.IOException;
import com.bloock.sdk.Bloock;
import com.bloock.sdk.client.IdentityClient;
import com.bloock.sdk.client.KeyClient;
import com.bloock.sdk.entity.identity.DidMethod;
import com.bloock.sdk.entity.key.Key;
import com.bloock.sdk.entity.identity.Holder;
import com.bloock.sdk.entity.key.KeyType;
import com.bloock.sdk.entity.key.LocalKey;
public class CreateHolder {
public static void main(String[] args) throws Exception {
try {
// we set the API key and create a client
Bloock.apiKey = System.getenv("API_KEY");
// we set de identity managed API host you have deployed
Bloock.identityApiHost = System.getenv("IDENTITY_MANAGED_API_HOST");
// initialize the Key Client
KeyClient keyClient = new KeyClient();
// initialize the IdentityClient
IdentityClient identityClient = new IdentityClient();
// create the Baby JubJub local key
LocalKey localKey = keyClient.newLocalKey(KeyType.Bjj);
// we create the holder, passing the Baby JubJub key and holder did method
Key holderKey = new Key(localKey);
DidMethod holderDidMethod = DidMethod.PolygonID;
Holder holder = identityClient.createHolder(holderKey, holderDidMethod);
// will print the Holder DID public identifier. Ex:
// did:polygonid:polygon:main:2qCU58EJgrELSJT6EzT27Rw9DhvwamAdbMLpePztYq
System.out.println(holder.getDid().getDid());
// will return the DID method we chosed. Ex: identity.PolygonID
System.out.println(holder.getDid().getDidMethod());
// will return the Key BJJ object associated to the Holder.
System.out.println(holder.getKey());
} catch (Exception e) {
System.out.println(e);
}
}
}
<?php
use Bloock\Bloock;
use Bloock\Client\KeyClient;
use Bloock\Client\IdentityClient;
use Bloock\Entity\Key\KeyType;
use Bloock\Entity\Key\Key;
use Bloock\Entity\Identity\DidMethod;
require "./vendor/autoload.php";
// we set the API key and create a client
Bloock::$apiKey = getenv("API_KEY") ?: "";
// we set de identity managed API host you have deployed
Bloock::$identityApiHost = getenv("IDENTITY_MANAGED_API_HOST") ?: "";
// initialize the Key Client
$keyClient = new KeyClient();
// initialize the IdentityClient
$identityClient = new IdentityClient();
// create the Baby JubJub local
$localKey = $keyClient->newLocalKey(KeyType::Bjj);
// we create the holder, passing the Baby JubJub key and holder did method
$holderKey = new Key($localKey);
$holderDidMethod = DidMethod::PolygonID;
$holder = $identityClient->createHolder($holderKey, $holderDidMethod);
$createdHolderDid = $holder->getDid()->getDid(); // will print the Holder DID public identifier. Ex: did:polygonid:polygon:main:2qCU58EJgrELSJT6EzT27Rw9DhvwamAdbMLpePztYq
$createdHolderDidMethod = $holder->getDid()->getDidMethod(); // will return the DID method we chosed. Ex: identity.PolygonID
$createdHolderKey = $holder->getKey(); // will return the Key BJJ object associated to the Holder.
package main
import (
"log"
"os"
"github.com/bloock/bloock-sdk-go/v2"
"github.com/bloock/bloock-sdk-go/v2/client"
"github.com/bloock/bloock-sdk-go/v2/entity/identity"
"github.com/bloock/bloock-sdk-go/v2/entity/key"
)
func main() {
// we set the API key and create a client
bloock.ApiKey = os.Getenv("API_KEY")
// we set de identity managed API host you have deployed
bloock.IdentityApiHost = os.Getenv("IDENTITY_MANAGED_API_HOST")
// initialize the Key Client
keyClient := client.NewKeyClient()
// initialize the IdentityClient
identityClient := client.NewIdentityClient()
// create the Baby JubJub local key
localKey, err := keyClient.NewLocalKey(key.Bjj)
if err != nil {
log.Fatalln(err)
}
// we create the holder, passing the Baby JubJub key and holder did method
holderKey := key.Key{LocalKey: &localKey}
holderDidMethod := identity.PolygonID
holder, err := identityClient.CreateHolder(holderKey, holderDidMethod)
if err != nil {
log.Fatalln(err)
}
log.Println(holder.Did.Did) // will print the Holder DID public identifier. Ex: did:polygonid:polygon:main:2qCU58EJgrELSJT6EzT27Rw9DhvwamAdbMLpePztYq
log.Println(holder.Did.DidMethod) // will return the DID method we chosed. Ex: identity.PolygonID
log.Println(holder.Key) // will return the Key BJJ object associated to the Holder.
}