Create a threshold key

Create a key structure that requires the defined threshold value to sign. A threshold key can contain a Ed25519 or ECDSA (secp256k1_)_ key type. You can use either the public key or the private key to create the key structure. If the threshold requirement is not met when signing transactions, the network will return an "INVALID_SIGNATURE" error.

Method

Type

Description

KeyList.withThreshold(<thresholdValue>)

int

The number of keys required to sign transactions to modify the account i.e. transfers, update, etc

//Generate 3 keys
PrivateKey key1 = PrivateKey.generate();.
PublicKey publicKey1 = key1.getPublicKey();

PrivateKey key2 = PrivateKey.generate();
PublicKey publicKey2 = key2.getPublicKey();

PrivateKey key3 = PrivateKey.generate();
PublicKey publicKey3 = key3.getPublicKey();

PrivateKey[] keys = new PrivateKey[3]; //You can also use the 3 public keys here

keys[0] = key1;
keys[1] = key2;
keys[2] = key3;


//A key structure that requires one of the 3 keys to sign
KeyList thresholdKey = KeyList.withThreshold(1);

//Add the three keys to the thresholdKey
Collections.addAll(thresholdKey, keys);

System.out.println("The 1/3 threshold key structure" +thresholdKey);

//v2.0.0

Sample Output:

KeyList{threshold=1,  
keys=[

302e020100300506032b657004220420984bd6b4e0cac783654f30c8797655953c6ab432e78bc09a34fbda594c6395ed, 

302e020100300506032b657004220420a4a7bd506f33868416d53eff55b3e8a254e17accf6cb37f44975792ededac120, 

302e020100300506032b657004220420f8a6f2ba3174391e619a87506fb0b86c6e481809563a797f4f84715d1a471695]  
}

Last updated