Apollo
@hyperledger/identus-sdk v7.0.0
@hyperledger/identus-sdk / overview / Apollo
Class: Apollo
Defined in: src/apollo/Apollo.ts:107
Apollo defines the set of cryptographic operations.
We by default are implementing Secp256k1, Ed25519 and X25519 Private and Public key from our generic abstractions. When you are using one of those type of keys, for example with:
 const privateKey = apollo.createPrivateKey({
   curve: Curve.ED25519,
 });
All the properties you pass to the createPrivateKey are just the default keyProperty keys and the values are strings, buffers are represented in hex format also as strings to simplify conversion later
You can know check if this key can sign with:
if (privateKey.isSignable()) {
 //the sign method will be available inside this if
 privateKey.sign(message)
}
//not outside
const signature = privateKey.isSignable() && privateKey.sign(message)
//This last one would also would but if your key was not signable would return false
PublicKeys follow the same concept, imagine you already have an instance of a publicKey, then..
if (publicKey.canVerify()) {
 privateKey.verify(challenge, signature)
}
//not outside
All keys know also have a generic list of properties which can be accessed at any stage, for example:
privateKey.getProperty(KeyProperties.curve)
Would give your the Curve value.
Find below all the complete list of KeyProperties that are available.
export enum KeyProperties {
  /// The 'kid'  represents a key's identifier.
  kid = "kid",
  /// The 'algorithm'  corresponds to the cryptographic algorithm associated with the key.,
  algorithm = "algorithm",
  /// The 'curve'  represents the elliptic curve used for an elliptic-curve key.,
  curve = "curve",
  /// The 'seed'  corresponds to the seed value from which a key is derived.,
  seed = "seed",
  /// The 'rawKey'  refers to the raw binary form of the key.,
  rawKey = "raw",
  /// The 'derivationPath'  refers to the path used to derive a key in a hierarchical deterministic (HD) key generation scheme.,
  derivationPath = "derivationPath",
  index = "index",
  /// The 'type'  denotes the type of the key.,
  type = "type",
  /// The 'curvePointX'  represents the x-coordinate of a curve point for an elliptic-curve key.,
  curvePointX = "curvePoint.x",
  /// The 'curvePointY'  represents the y-coordinate of a curve point for an elliptic-curve key.,
  curvePointY = "curvePoint.y",
}
Apollo
Implements
Constructors
Constructor
new Apollo():
Apollo
Returns
Apollo
Properties
| Property | Modifier | Type | Default value | Defined in | 
|---|---|---|---|---|
| Ed25519PrivateKey | static | typeof Ed25519PrivateKey | Ed25519PrivateKey | src/apollo/Apollo.ts:110 | 
| Secp256k1PrivateKey | static | typeof Secp256k1PrivateKey | Secp256k1PrivateKey | src/apollo/Apollo.ts:109 | 
| X25519PrivateKey | static | typeof X25519PrivateKey | X25519PrivateKey | src/apollo/Apollo.ts:111 | 
Methods
createPrivateKey()
createPrivateKey(
parameters: {[name:string]:any; }):PrivateKey
Defined in: src/apollo/Apollo.ts:291
Creates a private key based on the current cryptographic abstraction
Parameters
| Parameter | Type | Description | 
|---|---|---|
| parameters | {[ name:string]:any; } | 
Returns
Examples
Create an EC Key with secp256k1 curve
 const privateKey = apollo.createPrivateKey({
   curve: Curve.SECP256K1,
   seed: Buffer.from(seed.value).toString("hex"),
 });
Create an EC Key with secp256k1 curve, but also specify a derivationPath
 const privateKey = apollo.createPrivateKey({
   curve: Curve.SECP256K1,
   seed: Buffer.from(seed.value).toString("hex"),
   derivationPath: "m/0'/0'/0'"
 });
Create an EC Key with ed25519 curve, ED25519 keys do not use derivation, passing the seed or derivation path will make no effect. Calling this function just generates a new random privateKey for that curve
 const privateKey = apollo.createPrivateKey({
   curve: Curve.ED25519,
 });
Create an EC Key with X25519 curve, X25519 keys do not use derivation, passing the seed or derivation path will make no effect. Calling this function just generates a new random privateKey for that curve
 const privateKey = apollo.createPrivateKey({
   curve: Curve.X25519,
 });
Implementation of
createPublicKey()
createPublicKey(
parameters: {[name:string]:any; }):PublicKey
Defined in: src/apollo/Apollo.ts:202
Creates a public key based on the current cryptographic abstraction
Parameters
| Parameter | Type | Description | 
|---|---|---|
| parameters | {[ name:string]:any; } | 
Returns
Example
Create an EC Key with secp256k1 curve
 const privateKey = apollo.createPublicKey({
   curve: Curve.SECP256K1,
   raw: Buffer.from(new Arra(64).fill(1)),
 });
Implementation of
createRandomMnemonics()
createRandomMnemonics():
MnemonicWordList
Defined in: src/apollo/Apollo.ts:125
Creates a random set of mnemonic phrases that can be used as a seed for generating a private key.
Returns
Example
This function creates a random mnemonic phrase whose usage is as a seed for generating a private key.
 const mnemonics = apollo.createRandomMnemonics();
Implementation of
createRandomSeed()
createRandomSeed(
passphrase?:string):SeedWords
Defined in: src/apollo/Apollo.ts:174
Creates a random seed and a corresponding set of mnemonic phrases.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| passphrase? | string | 
Returns
Example
This function creates a random mnemonic phrase and seed.
 const {mnemonics, seed} = apollo.createRandomSeed();
Implementation of
createSeed()
createSeed(
mnemonics:MnemonicWordList,passphrase?:string):Seed
Defined in: src/apollo/Apollo.ts:143
Takes in a set of mnemonics and a passphrase, and returns a seed object used to generate a private key.
Parameters
| Parameter | Type | Description | 
|---|---|---|
| mnemonics | MnemonicWordList | |
| passphrase? | string | 
Returns
Example
This function takes mnemonics and passphrases and creates a seed object to generate a private key. It may throw an error if the mnemonics are invalid.
 const seed = apollo.createSeed(mnemonics, "my-secret-passphrase");
Implementation of
restorePrivateKey()
restorePrivateKey(
key:StorableKey):PrivateKey
Defined in: src/apollo/Apollo.ts:405
Restores a PrivateKey from the given StorableKey
Parameters
| Parameter | Type | Description | 
|---|---|---|
| key | StorableKey | 
Returns
PrivateKey instance
Throws
if the restoration process fails
Implementation of
KeyRestoration.restorePrivateKey
restorePublicKey()
restorePublicKey(
key:StorableKey):PublicKey
Defined in: src/apollo/Apollo.ts:420
Restores a PublicKey from the given StorableKey
Parameters
| Parameter | Type | Description | 
|---|---|---|
| key | StorableKey | 
Returns
PublicKey instance
Throws
if the restoration process fails, this method throws an error