Identity
IC4J Java Agent currently supports 3 different identity mechanisms. To learn more about the Internet Computer identity mechanisms refer to the Dfinity documentation.
If BasicIndentity or Secp256k1Identity is being used, define Bouncy Castle as the Java security provider in the code, before an Identity is created.
AnonymousIdentity is the default mechanism in the IC4J Agent ; this means that if the identity is not specified explicitly , AnonymousIdentity will be assigned implicitly.
Identity identity = new AnonymousIdentity();
dfx identity new alice
cp ~/.config/dfx/identity/xxx/identity.pem alice.pem
Either the Java Reader or Java Path can be used to read the ED22219 PEM resource to create the BasicIdentity object.
Reader sourceReader = new InputStreamReader(Main.class.getClassLoader().getResourceAsStream(ED25519_IDENTITY_FILE));
identity = BasicIdentity.fromPEMFile(sourceReader);
Path path = Paths.get(getClass().getClassLoader().getResource(ED25519_IDENTITY_FILE).getPath());
Identity identity = BasicIdentity.fromPEMFile(path);
KeyPair keyPair = KeyPairGenerator.getInstance("Ed25519").generateKeyPair();
Identity identity = BasicIdentity.fromKeyPair(keyPair);
The Java byte[] array can also be used as an input parameter.
byte[] input;
Identity identity = BasicIdentity.fromPEM(input);
Either Java Reader or Java Path can be used to read the Secp256k1 PEM resource to create the Secp256k1Identity object.
Reader sourceReader = new InputStreamReader(Main.class.getClassLoader().getResourceAsStream(ED25519_IDENTITY_FILE));
identity = Secp256k1Identity.fromPEMFile(sourceReader);
Path path = Paths.get(getClass().getClassLoader().getResource(ED25519_IDENTITY_FILE).getPath());
Identity identity = Secp256k1Identity.fromPEMFile(path);
Identity identity = Secp256k1Identity.fromKeyPair(keyPair);
Last modified 8mo ago