MultiSigPublicKey constructor
MultiSigPublicKey(
- MultiSigPublicKeyStruct value
Implementation
MultiSigPublicKey(MultiSigPublicKeyStruct value) {
_multisigPublicKey = value;
_rawBytes = bcs.ser("MultiSigPublicKey", value).toBytes();
if (_multisigPublicKey.threshold < 1) {
throw ArgumentError("Invalid threshold");
}
final seenPublicKeys = <String>{};
publicKeys = _multisigPublicKey.pks.map((e) {
final scheme = e.pubKey.keys.first;
final bytes = e.pubKey[scheme].cast<int>();
final publicKeyStr = Uint8List.fromList(bytes).toString();
if (seenPublicKeys.contains(publicKeyStr)) {
throw ArgumentError("Multisig does not support duplicate public keys");
}
seenPublicKeys.add(publicKeyStr);
if (e.weight < 1) {
throw ArgumentError("Invalid weight");
}
return PublicKeyWeight(e.weight, publicKeyFromRawBytes(scheme, Uint8List.fromList(bytes)));
}).toList();
final totalWeight = publicKeys.isEmpty ? 0 : publicKeys.map((p) => p.weight).reduce((x, y) => x + y);
if (_multisigPublicKey.threshold > totalWeight) {
throw ArgumentError("Unreachable threshold");
}
if (publicKeys.length > MAX_SIGNER_IN_MULTISIG) {
throw ArgumentError("Max number of signers in a multisig is $MAX_SIGNER_IN_MULTISIG");
}
if (publicKeys.length < MIN_SIGNER_IN_MULTISIG) {
throw ArgumentError("Min number of signers in a multisig is $MIN_SIGNER_IN_MULTISIG");
}
}