@@ -37,6 +37,11 @@ class AptosAddrConst {
3737
3838 static const int shortAddressLength = 63 ;
3939
40+ static const int multikeyMinPublicKey = 1 ;
41+ static const int multikeyMaxPublicKey = mask32;
42+
43+ static const int multiKeyMaxSignature = 32 ;
44+
4045 /// Bcs layout for encdoing multikey address
4146 static final multiKeyAddressLayout = LayoutConst .struct ([
4247 LayoutConst .bcsVector (
@@ -154,6 +159,10 @@ class AptosAddressUtils {
154159 static List <int > encodeMultiEd25519Key (
155160 List <Ed25519PublicKey > publicKeys, int threshold) {
156161 try {
162+ final keys = publicKeys.toSet ();
163+ if (keys.length != publicKeys.length) {
164+ throw AddressConverterException ("Duplicate public key detected." );
165+ }
157166 if (publicKeys.length < AptosAddrConst .minPublicKeys ||
158167 publicKeys.length > AptosAddrConst .maximumPublicKeys) {
159168 throw AddressConverterException (
@@ -191,15 +200,24 @@ class AptosAddressUtils {
191200 "Unsupported public key: Aptos Multikey address can only be generated from secp256k1 or ed25519 public keys." )
192201 };
193202 }).toList ();
194- if (publicKeys.length < AptosAddrConst .minPublicKeys ||
195- publicKeys.length > AptosAddrConst .maximumPublicKeys) {
203+ final keys = publicKeys.toSet ();
204+ if (keys.length != publicKeys.length) {
205+ throw AddressConverterException ("Duplicate public key detected." );
206+ }
207+ if (publicKeys.length < AptosAddrConst .multikeyMinPublicKey ||
208+ publicKeys.length > AptosAddrConst .multikeyMaxPublicKey) {
196209 throw AddressConverterException (
197- "The number of public keys provided is invalid. It must be between ${AptosAddrConst .minPublicKeys } and ${AptosAddrConst .maximumPublicKeys }." );
210+ "The number of public keys provided is invalid. It must be between ${AptosAddrConst .multikeyMinPublicKey } and ${AptosAddrConst .multikeyMaxPublicKey }." );
198211 }
212+
199213 if (requiredSignature < AptosAddrConst .minthreshold ||
200- requiredSignature > publicKeys.length ) {
214+ requiredSignature > AptosAddrConst .multiKeyMaxSignature ) {
201215 throw AddressConverterException (
202- "Invalid threshold. The threshold must be between ${AptosAddrConst .minthreshold } and the number of provided public keys (${publicKeys .length })." );
216+ "Invalid threshold. The threshold must be between ${AptosAddrConst .minthreshold } and ${AptosAddrConst .multiKeyMaxSignature }." );
217+ }
218+ if (publicKeys.length < requiredSignature) {
219+ throw AddressConverterException (
220+ "The number of public keys must be at least equal to the required signatures." );
203221 }
204222 final layoutStruct = {
205223 "requiredSignature" : requiredSignature,
0 commit comments