Skip to content

Commit 2b77322

Browse files
committed
V4.2.0
- Added support for aptos addresses using Secp256k1, Secp256r1, Multikey and MultiEd25519. - Fix sui multisig address validator
1 parent f892e30 commit 2b77322

File tree

4 files changed

+47
-8
lines changed

4 files changed

+47
-8
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 4.2.0
2+
3+
- Added support for aptos addresses using Secp256k1, Secp256r1, Multikey and MultiEd25519.
4+
- Fix sui multisig address validator
5+
16
## 4.1.0
27

38
- Added support for Sui addresses using Secp256k1, Secp256r1, Ed25519, and MultiSig.

lib/bip/address/aptos_addr.dart

+23-5
Original file line numberDiff line numberDiff line change
@@ -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,

lib/bip/address/sui.dart

+18-2
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ class SuiPublicKeyAndWeight {
1515
{required this.publicKey, required this.weight});
1616
factory SuiPublicKeyAndWeight(
1717
{required IPublicKey publicKey, required int weight}) {
18-
if (weight < 1 || weight >= mask8) {
18+
if (weight < 1 || weight > mask8) {
1919
throw AddressConverterException(
2020
"Invalid signer wieght. weight must be between 1 and $mask8 .");
2121
}
2222
switch (publicKey.curve) {
2323
case EllipticCurveTypes.ed25519:
2424
case EllipticCurveTypes.secp256k1:
2525
case EllipticCurveTypes.nist256p1:
26+
case EllipticCurveTypes.nist256p1Hybrid:
2627
break;
2728
default:
2829
throw AddressConverterException(
@@ -62,6 +63,12 @@ class SuiAddrConst {
6263

6364
/// A multi-key signing scheme flag where multiple different types of keys are involved
6465
static const int multisigAddressFlag = 3;
66+
67+
static const int multisigAccountMaxThreshold = mask16;
68+
static const int multisigAccountMinThreshold = 1;
69+
static const int multisigAccountMaxPublicKey = 10;
70+
static const int multisigAccountPublicKeyMaxWeight = 255;
71+
static const int multisigAccountPublicKeyMinWeight = 1;
6572
}
6673

6774
class SuiAddressUtils {
@@ -144,8 +151,17 @@ class SuiAddressUtils {
144151
if (keys.length != publicKeys.length) {
145152
throw AddressConverterException("Duplicate public key detected.");
146153
}
154+
if (keys.length > SuiAddrConst.multisigAccountMaxPublicKey) {
155+
throw AddressConverterException(
156+
"Exceeded the maximum allowed public keys for a multisig account.",
157+
details: {
158+
"maximum": SuiAddrConst.multisigAccountMaxPublicKey,
159+
"length": publicKeys.length
160+
});
161+
}
147162

148-
if (threshold < 1 || threshold >= mask16) {
163+
if (threshold < SuiAddrConst.multisigAccountMinThreshold ||
164+
threshold > SuiAddrConst.multisigAccountMaxThreshold) {
149165
throw AddressConverterException(
150166
"Invalid threshold. threshold must be between 1 and $mask16 .");
151167
}

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: blockchain_utils
22
description: Comprehensive Crypto & Blockchain Toolkit, Pure Dart, Cross-Platform, Encoding, Cryptography, Addresses, Mnemonics, & More.
3-
version: 4.1.0
3+
version: 4.2.0
44
homepage: "https://github.com/mrtnetwork/blockchain_utils"
55
repository: "https://github.com/mrtnetwork/blockchain_utils"
66

0 commit comments

Comments
 (0)