-
Notifications
You must be signed in to change notification settings - Fork 12
/
KeyHelper.sol
48 lines (42 loc) · 1.66 KB
/
KeyHelper.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.5.0 <0.9.0;
pragma experimental ABIEncoderV2;
import "./HederaTokenService.sol";
contract KeyHelper is HederaTokenService {
uint constant INHERIT_ACCOUNT_KEY = 1;
uint constant CONTRACT_ID_KEY = 2;
uint constant ED25519_KEY = 3;
uint constant ECDSA_SECPK2561K1_KEY = 4;
uint constant DELEGATABLE_CONTRACT_ID_KEY = 5;
function createSingleKey(
uint keyType,
uint keyValueType,
bytes memory key
) internal view returns (IHederaTokenService.TokenKey memory tokenKey) {
tokenKey = IHederaTokenService.TokenKey(keyType, createKeyValueType(keyValueType, key, address(0)));
}
function createSingleKey(
uint keyType,
uint keyValueType,
address key
) internal view returns (IHederaTokenService.TokenKey memory tokenKey) {
tokenKey = IHederaTokenService.TokenKey(keyType, createKeyValueType(keyValueType, "", key));
}
function createKeyValueType(
uint keyValueType,
bytes memory key,
address keyAddress
) internal view returns (IHederaTokenService.KeyValue memory keyValue) {
if (keyValueType == INHERIT_ACCOUNT_KEY) {
keyValue.inheritAccountKey = true;
} else if (keyValueType == CONTRACT_ID_KEY) {
keyValue.contractId = keyAddress;
} else if (keyValueType == ED25519_KEY) {
keyValue.ed25519 = key;
} else if (keyValueType == ECDSA_SECPK2561K1_KEY) {
keyValue.ECDSA_secp256k1 = key;
} else if (keyValueType == DELEGATABLE_CONTRACT_ID_KEY) {
keyValue.delegatableContractId = keyAddress;
}
}
}