Hedera
Search…
Create a key list
Create a key list key structure where all the keys in the list are required to sign transactions that modify accounts, topics, tokens, smart contracts, or files. A key **** list can contain a Ed25519 or ECDSA (secp256k1_)_ key type.
If all the keys in the key list key structure do not sign, the transaction will fail and return an "INVALID_SIGNATURE" error. A key list can have repeated keys. A signature for the repeated key will count as many times as the key is listed in the key list. For example, a key list has three keys. Two of the three public keys in the list are the same. When a user signs a transaction with the repeated key it will account for two out of the three keys required signature.
V2
V1
Method
Type
Description
KeyList.of(<keys>)
Key
Keys to add to the key list
Java
1
//Generate 3 keys
2
PrivateKey key1 = PrivateKey.generate();
3
PublicKey publicKey1 = key1.getPublicKey();
4
​
5
PrivateKey key2 = PrivateKey.generate();
6
PublicKey publicKey2 = key2.getPublicKey();
7
​
8
PrivateKey key3 = PrivateKey.generate();
9
PublicKey publicKey3 = key3.getPublicKey();
10
​
11
//Create a key list where all 3 keys are required to sign
12
KeyList keyStructure = KeyList.of(key1, key2, key3);
13
​
14
System.println(keyStructure)
15
​
16
//v2.0.0
Copied!
JavaScript
1
//Generate 3 keys
2
const key1 = PrivateKey.generate();
3
const publicKey1 = key1.publicKey;
4
​
5
const key2 = PrivateKey.generate();
6
const publicKey2 = key2.publicKey;
7
​
8
const key3 = PrivateKey.generate();
9
const publicKey3 = key3.publicKey;
10
​
11
//Create a list of the keys
12
const publicKeyList = [];
13
14
publicKeyList.push(publicKey1);
15
publicKeyList.push(publicKey2);
16
publicKeyList.push(publicKey3);
17
​
18
//Create a key list where all 3 keys are required to sign
19
const keys = new KeyList(publicKeyList);
20
//v2.0.13
Copied!
Go
1
//Generate 3 keys
2
key1, err := hedera.GeneratePrivateKey()
3
​
4
if err != nil {
5
panic(err)
6
}
7
​
8
publicKey1, err := key1.PublicKey()
9
​
10
key2, err := hedera.GeneratePrivateKey()
11
​
12
if err != nil {
13
panic(err)
14
}
15
​
16
publicKey2, err := key2.PublicKey()
17
​
18
key3, err := hedera.GeneratePrivateKey()
19
​
20
if err != nil {
21
panic(err)
22
}
23
​
24
publicKey3, err := key3.PublicKey()
25
​
26
//Create a key list where all 3 keys are required to sign
27
keys := make([]hedera.PublicKey, 3)
28
​
29
keys[0] = publicKey1
30
keys[1] = publicKey2
31
keys[2] = publicKey3
32
​
33
keyStructure := hedera.NewKeyList().AddAllPublicKeys(keys)
34
​
35
fmt.Printf("The key list is %v\n", keyStructure)
36
​
37
//v2.0.0
Copied!
Sample Output
1
KeyList{threshold=null,
2
keys=[302e020100300506032b6570042204201cd556de918842179791d9edd75cdd2b5d34c5c73b0239ec0b34c67eedc020fd, 302e020100300506032b6570042204209ca1ce4463b71c72bba0219c37e18347a5145a9797c6546a6c99e50255c54be3, 302e020100300506032b657004220420982bb43f4947e8376e2f0ebfde086d24323b04d731da29446e5bc399ffbe06e1]
3
}
Copied!
``
Method
Type
Description
add(<key>)
Ed25519PublicKey
Add one public key to the key list
addAll(<keys>)
Ed25519PublicKey
Add all keys to the key list
Java
1
//Generate 3 keys
2
Ed25519PrivateKey key1 = Ed25519PrivateKey.generate();
3
Ed25519PublicKey publicKey1 = key1.publicKey;
4
​
5
Ed25519PrivateKey key2 = Ed25519PrivateKey.generate();
6
Ed25519PublicKey publicKey2 = key2.publicKey;
7
​
8
Ed25519PrivateKey key3 = Ed25519PrivateKey.generate();
9
Ed25519PublicKey publicKey3 = key3.publicKey;
10
​
11
//Add they keys to a key list
12
KeyList keyList = new KeyList().add(publicKey1).add(publicKey2).add(publicKey3);
13
​
14
//v1.2.2
Copied!
JavaScript
1
//Generate 3 keys
2
const key1 = await Ed25519PrivateKey.generate();
3
const publicKey1 = key1.publicKey;
4
​
5
const key2 = await Ed25519PrivateKey.generate();
6
const publicKey2 = key2.publicKey;
7
​
8
const key3 = await Ed25519PrivateKey.generate();
9
const publicKey3 = key3.publicKey;
10
​
11
//Add they keys to a key list
12
const keyList = new KeyList().add(publicKey1).add(publicKey2).add(publicKey3);
13
​
14
//v1.4.2
Copied!
Copy link