net.corda.core.crypto

## Class CompositeKey

- net.corda.core.crypto.CompositeKey

- Direct Known Subclasses:
    CompositeKey.Leaf, CompositeKey.Node

      public class CompositeKey

  A tree data structure that enables the representation of composite public keys.

  In the simplest case it may just contain a single node encapsulating a PublicKey – a `class CompositeKey.Leaf`.

  For more complex scenarios, such as "Both Alice and Bob need to sign to consume a state S", we can represent the requirement by creating a tree with a root `class CompositeKey.Node`, and Alice and Bob as children – `class CompositeKey.Leaf`s. The root node would specify weights for each of its children and a threshold – the minimum total weight required (e.g. the minimum number of child signatures required) to satisfy the tree signature requirement.

  Using these constructs we can express e.g. 1 of N (OR) or N of N (AND) signature requirements. By nesting we can create multi-level requirements such as "either the CEO or 3 of 5 of his assistants need to sign".

  See Also:
    PublicKey, `class CompositeKey.Leaf`, `class CompositeKey.Node`, `class CompositeKey.Leaf`

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `CompositeKey.Builder` A helper class for building a `class CompositeKey.Node`.
    `static class` | `CompositeKey.Companion`
    `static class` | `CompositeKey.Leaf` The leaf node of the tree – a wrapper around a PublicKey primitive
    `static class` | `CompositeKey.Node` Represents a node in the key tree. It maintains a list of child nodes – sub-trees, and associated weights carried by child node signatures.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static CompositeKey.Companion` | `Companion`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `containsAny(java.lang.Iterable<? extends java.security.PublicKey> otherKeys)` Checks whether any of the given keys matches a leaf on the tree
    `java.util.Set<java.security.PublicKey>` | `getKeys()` Returns all PublicKeys contained within the tree leaves
    `java.security.PublicKey` | `getSingleKey()` Returns the enclosed PublicKey for a `class CompositeKey` with a single leaf node
    `boolean` | `isFulfilledBy(java.lang.Iterable<? extends java.security.PublicKey> keys)` Checks whether keys match a sufficient amount of leaf nodes
    `boolean` | `isFulfilledBy(java.security.PublicKey key)`
    `java.lang.String` | `toBase58String()` This is generated by serializing the composite key with Kryo, and encoding the resulting bytes in base58. A custom serialization format is being used.

- - ### Field Detail

    - #### Companion

          public static CompositeKey.Companion Companion

  - ### Method Detail

    - #### isFulfilledBy

          public boolean isFulfilledBy(java.lang.Iterable<? extends java.security.PublicKey> keys)

      Checks whether keys match a sufficient amount of leaf nodes

    - #### isFulfilledBy

          public boolean isFulfilledBy(java.security.PublicKey key)

    - #### getKeys

          public java.util.Set<java.security.PublicKey> getKeys()

      Returns all PublicKeys contained within the tree leaves

      See Also:
        PublicKey

    - #### containsAny

          public boolean containsAny(java.lang.Iterable<? extends java.security.PublicKey> otherKeys)

      Checks whether any of the given keys matches a leaf on the tree

    - #### toBase58String

          public java.lang.String toBase58String()

      This is generated by serializing the composite key with Kryo, and encoding the resulting bytes in base58. A custom serialization format is being used.

      TODO: follow the crypto-conditions ASN.1 spec, some changes are needed to be compatible with the condition structure, e.g. mapping a PublicKey to a condition with the specific feature (ED25519).

    - #### getSingleKey

          public java.security.PublicKey getSingleKey()

      Returns the enclosed PublicKey for a `class CompositeKey` with a single leaf node

      Throws:
        - if the `class CompositeKey` contains more than one node
      See Also:
        PublicKey, `class CompositeKey`