Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed deprecated env. #396

Merged
merged 3 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion example/integration_test/libpolygonid_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ void main() {
(WidgetTester tester) async {
expect(
pidCoreIdentity.calculateGenesisId(
PolygonIdCoreMocks.calculateGenesisIdInputJson),
PolygonIdCoreMocks.calculateGenesisIdInputJson,
PolygonIdCoreMocks.environmentConfigJson,
),
equals(PolygonIdCoreMocks.calculateGenesisIdOutputJson));
});

Expand Down
21 changes: 21 additions & 0 deletions example/integration_test/polygonidcore_mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@ class PolygonIdCoreMocks {
"blockchain": "polygon",
"network": "mumbai"
}
''';

static String environmentConfigJson = '''
{
"rpcUrl": "https://polygon-mumbai.infura.io/v3/YOUR_WEB3_API_KEY",
"idStateContract": "0x134B1BE34911E39A8397ec6289782989729807a4",
"ipfsUrl": "https://[YOUR-IPFS-API-KEY]:[YOUR-IPFS-API-KEY-SECRET]@ipfs.infura.io:5001",
"pushUrl": "https://push-staging.polygonid.com/api/v1",
"chainConfigs": {
"137": {
"rpcUrl": "https://polygon-mainnet.infura.io/v3/YOUR_WEB3_API_KEY",
"stateContractAddr": "0x624ce98D2d27b20b8f8d521723Df8fC4db71D79D"
},
"80001": {
"rpcUrl": "https://polygon-mumbai.infura.io/v3/YOUR_WEB3_API_KEY",
"stateContractAddr": "0x134B1BE34911E39A8397ec6289782989729807a4"
}
},
"didMethods": [],
"stacktraceEncryptionKey": "ENCRYPTION_KEY"
}
''';

static String calculateGenesisIdOutputJson = '''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void registerEnv() {
String pinataGateway = Env.pinataGateway;
String pinataGatewayToken = Env.pinataGatewayToken;

EnvEntity envV1 = EnvEntity.fromJsonV1(defaultEnv);
EnvEntity envV1 = EnvEntity.fromJson(defaultEnv);
if (stacktraceEncryptionKey.isNotEmpty) {
envV1 = envV1.copyWith(stacktraceEncryptionKey: stacktraceEncryptionKey);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/common/data/repositories/config_repository_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ConfigRepositoryImpl implements ConfigRepository {
return Future.error(EnvNotSetException());
}

return EnvEntity.fromJsonV1(value);
return EnvEntity.fromJson(value);
});
}

Expand Down
85 changes: 2 additions & 83 deletions lib/common/domain/entities/env_entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,6 @@ import 'package:polygonid_flutter_sdk/common/domain/entities/did_method_entity.d
import 'package:polygonid_flutter_sdk/common/domain/entities/env_config_entity.dart';

class EnvEntity {
@Deprecated("Use EnvEntity.v1 instead of EnvEntity")
final String web3Url;
@Deprecated("Use EnvEntity.v1 instead of EnvEntity")
final String web3ApiKey;
@Deprecated("Use EnvEntity.v1 instead of EnvEntity")
final String web3RdpUrl;
@Deprecated("Use EnvEntity.v1 instead of EnvEntity")
final String blockchain;
@Deprecated("Use EnvEntity.v1 instead of EnvEntity")
final String network;
@Deprecated("Use EnvEntity.v1 instead of EnvEntity")
final String rpcUrl;
@Deprecated("Use EnvEntity.v1 instead of EnvEntity")
final String idStateContract;

final String pushUrl;
final String ipfsUrl;

Expand All @@ -30,13 +15,6 @@ class EnvEntity {
final String? pinataGatewayToken;

EnvEntity._({
this.web3Url = '',
this.web3ApiKey = '',
this.web3RdpUrl = '',
this.blockchain = '',
this.network = '',
this.idStateContract = '',
this.rpcUrl = '',
required this.pushUrl,
required this.ipfsUrl,
this.chainConfigs = const {},
Expand All @@ -46,61 +24,18 @@ class EnvEntity {
this.pinataGatewayToken,
});

@Deprecated("Use EnvEntity.v1 instead of EnvEntity")
EnvEntity({
required this.blockchain,
required this.network,
required this.web3Url,
required this.web3ApiKey,
this.web3RdpUrl = '',
required this.idStateContract,
required this.pushUrl,
required this.ipfsUrl,
this.stacktraceEncryptionKey,
this.pinataGateway,
this.pinataGatewayToken,
}) : rpcUrl = web3Url + web3ApiKey,
chainConfigs = const {},
didMethods = const [] {}

EnvEntity.v1({
required this.pushUrl,
required this.ipfsUrl,
required this.chainConfigs,
required this.didMethods,
this.stacktraceEncryptionKey,
this.pinataGateway,
this.pinataGatewayToken,
@Deprecated("Use chainConfig") this.blockchain = '',
@Deprecated("Use chainConfig") this.network = '',
@Deprecated("Use chainConfig") this.web3Url = '',
@Deprecated("Use chainConfig") this.web3ApiKey = '',
@Deprecated("Use chainConfig") this.idStateContract = '',
}) : rpcUrl = '',
web3RdpUrl = '';
});

factory EnvEntity.fromJson(Map<String, dynamic> json) {
return EnvEntity(
blockchain: json['blockchain'],
network: json['network'],
web3Url: json['web3Url'],
web3ApiKey: json['web3ApiKey'],
idStateContract: json['idStateContract'],
pushUrl: json['pushUrl'],
ipfsUrl: json['ipfsUrl'],
stacktraceEncryptionKey: json['stacktraceEncryptionKey'],
pinataGateway: json['pinataGateway'],
pinataGatewayToken: json['pinataGatewayToken'],
);
}

factory EnvEntity.fromJsonV1(Map<String, dynamic> json) {
return EnvEntity.v1(
blockchain: json['blockchain'] ?? '',
network: json['network'] ?? '',
web3Url: json['web3Url'] ?? '',
web3ApiKey: json['web3ApiKey'] ?? '',
idStateContract: json['idStateContract'] ?? '',
pushUrl: json['pushUrl'],
ipfsUrl: json['ipfsUrl'],
chainConfigs: (json['chainConfigs'] as Map<String, dynamic>).map(
Expand All @@ -120,13 +55,6 @@ class EnvEntity {

@override
Map<String, dynamic> toJson() => {
// TODO: Remove these fields with new release
'blockchain': blockchain,
'network': network,
'web3Url': web3Url,
'web3ApiKey': web3ApiKey,
'idStateContract': idStateContract,

'pushUrl': pushUrl,
'ipfsUrl': ipfsUrl,
'chainConfigs': chainConfigs.map(
Expand All @@ -143,17 +71,13 @@ class EnvEntity {

@override
String toString() {
return 'EnvEntity{blockchain: $blockchain, network: $network, rpcUrl: $rpcUrl, idStateContract: $idStateContract, pushUrl: $pushUrl, ipfsUrl: $ipfsUrl, chainConfig: $chainConfigs, didMethods: $didMethods, stacktraceEncryptionKey: $stacktraceEncryptionKey, , pinataGateway: $pinataGateway, pinataGatewayToken: $pinataGatewayToken}';
return 'EnvEntity{pushUrl: $pushUrl, ipfsUrl: $ipfsUrl, chainConfig: $chainConfigs, didMethods: $didMethods, stacktraceEncryptionKey: $stacktraceEncryptionKey, , pinataGateway: $pinataGateway, pinataGatewayToken: $pinataGatewayToken}';
}

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is EnvEntity &&
blockchain == other.blockchain &&
network == other.network &&
rpcUrl == other.rpcUrl &&
idStateContract == other.idStateContract &&
pushUrl == other.pushUrl &&
ipfsUrl == other.ipfsUrl &&
mapEquals(chainConfigs, other.chainConfigs) &&
Expand All @@ -179,11 +103,6 @@ class EnvEntity {
String? pinataGatewayToken,
}) {
return EnvEntity._(
blockchain: blockchain ?? this.blockchain,
network: network ?? this.network,
web3Url: rpcUrl ?? this.rpcUrl,
web3ApiKey: rpcUrl ?? this.rpcUrl,
idStateContract: idStateContract ?? this.idStateContract,
pushUrl: pushUrl ?? this.pushUrl,
ipfsUrl: ipfsUrl ?? this.ipfsUrl,
chainConfigs: chainConfigs ?? this.chainConfigs,
Expand Down
10 changes: 6 additions & 4 deletions lib/common/domain/use_cases/get_selected_chain_use_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ class GetSelectedChainUseCase extends FutureUseCase<void, ChainConfigEntity> {
}
}

final defaultChain = env.chainConfigs.entries.first.value;

return ChainConfigEntity(
blockchain: env.blockchain,
network: env.network,
rpcUrl: env.rpcUrl,
stateContractAddr: env.idStateContract,
blockchain: defaultChain.blockchain,
network: defaultChain.network,
rpcUrl: defaultChain.rpcUrl,
stateContractAddr: defaultChain.stateContractAddr,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,7 @@ class CredentialProposalRequest
@override
bool operator ==(Object other) =>
super == other && other is CredentialProposalRequest;

@override
int get hashCode => id.hashCode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,10 @@ class LibPolygonIdCoreIdentityDataSource {
this._polygonIdCoreIdentity,
);

@Deprecated("Use newGenesisId instead of calculateGenesisId.")
String calculateGenesisId(
String claimsTreeRoot,
String blockchain,
String network,
) {
String input = jsonEncode({
"claimsTreeRoot": claimsTreeRoot,
//"8174871235721986756013575194888048894328426483724665491825528183806540196001",
"blockchain": blockchain,
//"polygon",
"network": network,
//"mumbai"
});

String output = _polygonIdCoreIdentity.calculateGenesisId(input);
logger().d("calculateGenesisId: $output");

return jsonDecode(output)["did"];
}

String newGenesisId(
String claimsTreeRoot,
String blockchain,
String network,
Map<String, dynamic> config,
) {
String input = jsonEncode({
Expand All @@ -49,7 +28,7 @@ class LibPolygonIdCoreIdentityDataSource {

String cfg = jsonEncode(config);

String output = _polygonIdCoreIdentity.newGenesisId(input, cfg);
String output = _polygonIdCoreIdentity.calculateGenesisId(input, cfg);
logger().d("calculateGenesisId: $output");

return jsonDecode(output)["did"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class IdentityRepositoryImpl extends IdentityRepository {
}) {
try {
// Get the genesis id
final genesisDid = _libPolygonIdCoreIdentityDataSource.newGenesisId(
final genesisDid = _libPolygonIdCoreIdentityDataSource.calculateGenesisId(
claimsRoot,
blockchain,
network,
Expand Down
36 changes: 1 addition & 35 deletions lib/identity/libs/polygonidcore/pidcore_identity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,7 @@ import '../../../common/libs/polygonidcore/native_polygonidcore.dart';

@injectable
class PolygonIdCoreIdentity extends PolygonIdCore {
@Deprecated('Use newGenesisId instead of calculateGenesisId.')
String calculateGenesisId(String input) {
ffi.Pointer<ffi.Char> in1 = input.toNativeUtf8().cast<ffi.Char>();
ffi.Pointer<ffi.Pointer<ffi.Char>> response =
malloc<ffi.Pointer<ffi.Char>>();
ffi.Pointer<ffi.Pointer<PLGNStatus>> status =
malloc<ffi.Pointer<PLGNStatus>>();

freeAllocatedMemory() {
malloc.free(response);
malloc.free(status);
}

int res = PolygonIdCore.nativePolygonIdCoreLib
.PLGNCalculateGenesisID(response, in1, status);
if (res == 0) {
String? consumedStatus = consumeStatus(status, "");
// ignore: unnecessary_null_comparison
if (consumedStatus != null) {
freeAllocatedMemory();
throw IdentityInputsException(consumedStatus);
}
}
String result = "";
ffi.Pointer<ffi.Char> jsonResponse = response.value;
ffi.Pointer<Utf8> jsonString = jsonResponse.cast<Utf8>();
if (jsonString != ffi.nullptr) {
result = jsonString.toDartString();
}

freeAllocatedMemory();
return result;
}

String newGenesisId(String input, String config) {
String calculateGenesisId(String input, String config) {
ffi.Pointer<ffi.Char> in1 = input.toNativeUtf8().cast<ffi.Char>();
ffi.Pointer<ffi.Char> cfg = config.toNativeUtf8().cast<ffi.Char>();
ffi.Pointer<ffi.Pointer<ffi.Char>> response =
Expand Down
27 changes: 13 additions & 14 deletions lib/sdk/di/injector.config.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/sdk/proof.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class Proof implements PolygonIdSdkProof {
Future<String?> preCacheGistProof({
required String genesisDid,
required EnvEntity env,
required String stateContractAddress,
}) async {
try {
List<String> splittedDid = genesisDid.split(":");
Expand All @@ -171,7 +172,7 @@ class Proof implements PolygonIdSdkProof {
ContractAbi contractAbi = ContractAbi.fromJson(
jsonEncode(jsonDecode(stateAbiJson)["abi"]), 'State');
EthereumAddress ethereumAddress =
EthereumAddress.fromHex(env.idStateContract);
EthereumAddress.fromHex(stateContractAddress);
DeployedContract contract =
DeployedContract(contractAbi, ethereumAddress);
String? cachedGistProof = await GistProofCache().getGistProof(
Expand Down
Loading
Loading