Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
quetool committed Jun 28, 2024
1 parent 453ae09 commit 6ab65ec
Show file tree
Hide file tree
Showing 7 changed files with 588 additions and 46 deletions.
11 changes: 10 additions & 1 deletion lib/apis/sign_api/models/auth/auth_client_models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,23 @@ class AuthPayloadParams with _$AuthPayloadParams {
}) = _AuthPayloadParams;

factory AuthPayloadParams.fromRequestParams(AuthRequestParams params) {
final now = DateTime.now();
return AuthPayloadParams(
type: params.type ?? CacaoHeader.EIP4361,
chainId: params.chainId,
domain: params.domain,
aud: params.aud,
version: '1',
nonce: params.nonce,
iat: DateTime.now().toIso8601String(),
iat: DateTime.utc(
now.year,
now.month,
now.day,
now.hour,
now.minute,
now.second,
now.millisecond,
).toIso8601String(),
nbf: params.nbf,
exp: params.exp,
statement: params.statement,
Expand Down
75 changes: 30 additions & 45 deletions lib/apis/sign_api/models/auth/session_auth_models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,50 +25,27 @@ class SessionAuthRequestResponse {
});
}

class SessionAuthRequestParams {
final List<String> chains;
final String domain;
final String nonce;
final String uri;
//
final CacaoHeader? type;
final String? nbf;
final String? exp;
final String? statement;
final String? requestId;
final List<String>? resources;
final int? expiry;
final List<String>? methods;
@freezed
class SessionAuthRequestParams with _$SessionAuthRequestParams {
@JsonSerializable(includeIfNull: false)
const factory SessionAuthRequestParams({
required List<String> chains,
required String domain,
required String nonce,
required String uri,
//
CacaoHeader? type,
String? nbf,
String? exp,
String? statement,
String? requestId,
List<String>? resources,
int? expiry,
@Default(<String>[]) List<String>? methods,
}) = _SessionAuthRequestParams;
//

SessionAuthRequestParams({
required this.chains,
required this.domain,
required this.nonce,
required this.uri,
this.type,
this.nbf,
this.exp,
this.statement,
this.requestId,
this.resources,
this.expiry,
this.methods = const <String>[],
});

Map<String, dynamic> toJson() => {
'chains': chains,
'domain': domain,
'nonce': nonce,
'uri': uri,
if (type != null) 'type': type,
if (nbf != null) 'nbf': nbf,
if (exp != null) 'exp': exp,
if (statement != null) 'statement': statement,
if (requestId != null) 'requestId': requestId,
if (resources != null) 'resources': resources,
if (expiry != null) 'expiry': expiry,
};
factory SessionAuthRequestParams.fromJson(Map<String, dynamic> json) =>
_$SessionAuthRequestParamsFromJson(json);
}

@freezed
Expand All @@ -94,15 +71,23 @@ class SessionAuthPayload with _$SessionAuthPayload {
factory SessionAuthPayload.fromRequestParams(
SessionAuthRequestParams params,
) {
final now = DateTime.now();
return SessionAuthPayload(
chains: params.chains,
domain: params.domain,
nonce: params.nonce,
aud: params.uri,
type: params.type?.t ?? 'eip4361',
version: '1',
iat: DateTime.now().toIso8601String(),
//
iat: DateTime.utc(
now.year,
now.month,
now.day,
now.hour,
now.minute,
now.second,
now.millisecond,
).toIso8601String(),
nbf: params.nbf,
exp: params.exp,
statement: params.statement,
Expand Down
Loading

0 comments on commit 6ab65ec

Please sign in to comment.