@@ -37,6 +37,11 @@ class AptosAddrConst {
37
37
38
38
static const int shortAddressLength = 63 ;
39
39
40
+ static const int multikeyMinPublicKey = 1 ;
41
+ static const int multikeyMaxPublicKey = mask32;
42
+
43
+ static const int multiKeyMaxSignature = 32 ;
44
+
40
45
/// Bcs layout for encdoing multikey address
41
46
static final multiKeyAddressLayout = LayoutConst .struct ([
42
47
LayoutConst .bcsVector (
@@ -154,6 +159,10 @@ class AptosAddressUtils {
154
159
static List <int > encodeMultiEd25519Key (
155
160
List <Ed25519PublicKey > publicKeys, int threshold) {
156
161
try {
162
+ final keys = publicKeys.toSet ();
163
+ if (keys.length != publicKeys.length) {
164
+ throw AddressConverterException ("Duplicate public key detected." );
165
+ }
157
166
if (publicKeys.length < AptosAddrConst .minPublicKeys ||
158
167
publicKeys.length > AptosAddrConst .maximumPublicKeys) {
159
168
throw AddressConverterException (
@@ -191,15 +200,24 @@ class AptosAddressUtils {
191
200
"Unsupported public key: Aptos Multikey address can only be generated from secp256k1 or ed25519 public keys." )
192
201
};
193
202
}).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) {
196
209
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 }." );
198
211
}
212
+
199
213
if (requiredSignature < AptosAddrConst .minthreshold ||
200
- requiredSignature > publicKeys.length ) {
214
+ requiredSignature > AptosAddrConst .multiKeyMaxSignature ) {
201
215
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." );
203
221
}
204
222
final layoutStruct = {
205
223
"requiredSignature" : requiredSignature,
0 commit comments