Skip to content

Commit 9752d5a

Browse files
committed
Add auth events, add fingerprints to account
1 parent 6f373c8 commit 9752d5a

File tree

10 files changed

+344
-5
lines changed

10 files changed

+344
-5
lines changed

api/lib/src/event/client.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,12 @@ final class ModeChangeRequest extends ClientWorldEvent
157157
ModeChangeRequest(this.location);
158158
ModeChangeRequest.plain() : location = null;
159159
}
160+
161+
@MappableClass()
162+
final class AuthenticateRequest extends ClientWorldEvent
163+
with AuthenticateRequestMappable {
164+
final Uint8List signature;
165+
final Uint8List publicKey;
166+
167+
AuthenticateRequest(this.signature, this.publicKey);
168+
}

api/lib/src/event/event.mapper.dart

Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ class ServerWorldEventMapper extends SubClassMapperBase<ServerWorldEvent> {
135135
DialogsClosedMapper.ensureInitialized();
136136
ImagesUpdatedMapper.ensureInitialized();
137137
ServerStateUpdatedMapper.ensureInitialized();
138+
AuthenticatedRequestedMapper.ensureInitialized();
138139
HybridWorldEventMapper.ensureInitialized();
139140
}
140141
return _instance!;
@@ -1774,6 +1775,138 @@ class _ServerStateUpdatedCopyWithImpl<$R, $Out>
17741775
_ServerStateUpdatedCopyWithImpl<$R2, $Out2>($value, $cast, t);
17751776
}
17761777

1778+
class AuthenticatedRequestedMapper
1779+
extends SubClassMapperBase<AuthenticatedRequested> {
1780+
AuthenticatedRequestedMapper._();
1781+
1782+
static AuthenticatedRequestedMapper? _instance;
1783+
static AuthenticatedRequestedMapper ensureInitialized() {
1784+
if (_instance == null) {
1785+
MapperContainer.globals.use(_instance = AuthenticatedRequestedMapper._());
1786+
ServerWorldEventMapper.ensureInitialized().addSubMapper(_instance!);
1787+
}
1788+
return _instance!;
1789+
}
1790+
1791+
@override
1792+
final String id = 'AuthenticatedRequested';
1793+
1794+
static Uint8List _$challenge(AuthenticatedRequested v) => v.challenge;
1795+
static const Field<AuthenticatedRequested, Uint8List> _f$challenge =
1796+
Field('challenge', _$challenge);
1797+
static bool _$isRequired(AuthenticatedRequested v) => v.isRequired;
1798+
static const Field<AuthenticatedRequested, bool> _f$isRequired =
1799+
Field('isRequired', _$isRequired, opt: true, def: true);
1800+
1801+
@override
1802+
final MappableFields<AuthenticatedRequested> fields = const {
1803+
#challenge: _f$challenge,
1804+
#isRequired: _f$isRequired,
1805+
};
1806+
1807+
@override
1808+
final String discriminatorKey = 'type';
1809+
@override
1810+
final dynamic discriminatorValue = 'AuthenticatedRequested';
1811+
@override
1812+
late final ClassMapperBase superMapper =
1813+
ServerWorldEventMapper.ensureInitialized();
1814+
1815+
static AuthenticatedRequested _instantiate(DecodingData data) {
1816+
return AuthenticatedRequested(data.dec(_f$challenge),
1817+
isRequired: data.dec(_f$isRequired));
1818+
}
1819+
1820+
@override
1821+
final Function instantiate = _instantiate;
1822+
1823+
static AuthenticatedRequested fromMap(Map<String, dynamic> map) {
1824+
return ensureInitialized().decodeMap<AuthenticatedRequested>(map);
1825+
}
1826+
1827+
static AuthenticatedRequested fromJson(String json) {
1828+
return ensureInitialized().decodeJson<AuthenticatedRequested>(json);
1829+
}
1830+
}
1831+
1832+
mixin AuthenticatedRequestedMappable {
1833+
String toJson() {
1834+
return AuthenticatedRequestedMapper.ensureInitialized()
1835+
.encodeJson<AuthenticatedRequested>(this as AuthenticatedRequested);
1836+
}
1837+
1838+
Map<String, dynamic> toMap() {
1839+
return AuthenticatedRequestedMapper.ensureInitialized()
1840+
.encodeMap<AuthenticatedRequested>(this as AuthenticatedRequested);
1841+
}
1842+
1843+
AuthenticatedRequestedCopyWith<AuthenticatedRequested, AuthenticatedRequested,
1844+
AuthenticatedRequested>
1845+
get copyWith => _AuthenticatedRequestedCopyWithImpl<
1846+
AuthenticatedRequested, AuthenticatedRequested>(
1847+
this as AuthenticatedRequested, $identity, $identity);
1848+
@override
1849+
String toString() {
1850+
return AuthenticatedRequestedMapper.ensureInitialized()
1851+
.stringifyValue(this as AuthenticatedRequested);
1852+
}
1853+
1854+
@override
1855+
bool operator ==(Object other) {
1856+
return AuthenticatedRequestedMapper.ensureInitialized()
1857+
.equalsValue(this as AuthenticatedRequested, other);
1858+
}
1859+
1860+
@override
1861+
int get hashCode {
1862+
return AuthenticatedRequestedMapper.ensureInitialized()
1863+
.hashValue(this as AuthenticatedRequested);
1864+
}
1865+
}
1866+
1867+
extension AuthenticatedRequestedValueCopy<$R, $Out>
1868+
on ObjectCopyWith<$R, AuthenticatedRequested, $Out> {
1869+
AuthenticatedRequestedCopyWith<$R, AuthenticatedRequested, $Out>
1870+
get $asAuthenticatedRequested => $base.as((v, t, t2) =>
1871+
_AuthenticatedRequestedCopyWithImpl<$R, $Out>(v, t, t2));
1872+
}
1873+
1874+
abstract class AuthenticatedRequestedCopyWith<
1875+
$R,
1876+
$In extends AuthenticatedRequested,
1877+
$Out> implements ServerWorldEventCopyWith<$R, $In, $Out> {
1878+
@override
1879+
$R call({Uint8List? challenge, bool? isRequired});
1880+
AuthenticatedRequestedCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(
1881+
Then<$Out2, $R2> t);
1882+
}
1883+
1884+
class _AuthenticatedRequestedCopyWithImpl<$R, $Out>
1885+
extends ClassCopyWithBase<$R, AuthenticatedRequested, $Out>
1886+
implements
1887+
AuthenticatedRequestedCopyWith<$R, AuthenticatedRequested, $Out> {
1888+
_AuthenticatedRequestedCopyWithImpl(super.value, super.then, super.then2);
1889+
1890+
@override
1891+
late final ClassMapperBase<AuthenticatedRequested> $mapper =
1892+
AuthenticatedRequestedMapper.ensureInitialized();
1893+
@override
1894+
$R call({Uint8List? challenge, bool? isRequired}) =>
1895+
$apply(FieldCopyWithData({
1896+
if (challenge != null) #challenge: challenge,
1897+
if (isRequired != null) #isRequired: isRequired
1898+
}));
1899+
@override
1900+
AuthenticatedRequested $make(CopyWithData data) =>
1901+
AuthenticatedRequested(data.get(#challenge, or: $value.challenge),
1902+
isRequired: data.get(#isRequired, or: $value.isRequired));
1903+
1904+
@override
1905+
AuthenticatedRequestedCopyWith<$R2, AuthenticatedRequested, $Out2>
1906+
$chain<$R2, $Out2>(Then<$Out2, $R2> t) =>
1907+
_AuthenticatedRequestedCopyWithImpl<$R2, $Out2>($value, $cast, t);
1908+
}
1909+
17771910
class ClientWorldEventMapper extends SubClassMapperBase<ClientWorldEvent> {
17781911
ClientWorldEventMapper._();
17791912

@@ -1794,6 +1927,7 @@ class ClientWorldEventMapper extends SubClassMapperBase<ClientWorldEvent> {
17941927
DialogCloseRequestMapper.ensureInitialized();
17951928
ImagesRequestMapper.ensureInitialized();
17961929
ModeChangeRequestMapper.ensureInitialized();
1930+
AuthenticateRequestMapper.ensureInitialized();
17971931
HybridWorldEventMapper.ensureInitialized();
17981932
}
17991933
return _instance!;
@@ -3368,6 +3502,133 @@ class _ModeChangeRequestCopyWithImpl<$R, $Out>
33683502
_ModeChangeRequestCopyWithImpl<$R2, $Out2>($value, $cast, t);
33693503
}
33703504

3505+
class AuthenticateRequestMapper
3506+
extends SubClassMapperBase<AuthenticateRequest> {
3507+
AuthenticateRequestMapper._();
3508+
3509+
static AuthenticateRequestMapper? _instance;
3510+
static AuthenticateRequestMapper ensureInitialized() {
3511+
if (_instance == null) {
3512+
MapperContainer.globals.use(_instance = AuthenticateRequestMapper._());
3513+
ClientWorldEventMapper.ensureInitialized().addSubMapper(_instance!);
3514+
}
3515+
return _instance!;
3516+
}
3517+
3518+
@override
3519+
final String id = 'AuthenticateRequest';
3520+
3521+
static Uint8List _$signature(AuthenticateRequest v) => v.signature;
3522+
static const Field<AuthenticateRequest, Uint8List> _f$signature =
3523+
Field('signature', _$signature);
3524+
static Uint8List _$publicKey(AuthenticateRequest v) => v.publicKey;
3525+
static const Field<AuthenticateRequest, Uint8List> _f$publicKey =
3526+
Field('publicKey', _$publicKey);
3527+
3528+
@override
3529+
final MappableFields<AuthenticateRequest> fields = const {
3530+
#signature: _f$signature,
3531+
#publicKey: _f$publicKey,
3532+
};
3533+
3534+
@override
3535+
final String discriminatorKey = 'type';
3536+
@override
3537+
final dynamic discriminatorValue = 'AuthenticateRequest';
3538+
@override
3539+
late final ClassMapperBase superMapper =
3540+
ClientWorldEventMapper.ensureInitialized();
3541+
3542+
static AuthenticateRequest _instantiate(DecodingData data) {
3543+
return AuthenticateRequest(data.dec(_f$signature), data.dec(_f$publicKey));
3544+
}
3545+
3546+
@override
3547+
final Function instantiate = _instantiate;
3548+
3549+
static AuthenticateRequest fromMap(Map<String, dynamic> map) {
3550+
return ensureInitialized().decodeMap<AuthenticateRequest>(map);
3551+
}
3552+
3553+
static AuthenticateRequest fromJson(String json) {
3554+
return ensureInitialized().decodeJson<AuthenticateRequest>(json);
3555+
}
3556+
}
3557+
3558+
mixin AuthenticateRequestMappable {
3559+
String toJson() {
3560+
return AuthenticateRequestMapper.ensureInitialized()
3561+
.encodeJson<AuthenticateRequest>(this as AuthenticateRequest);
3562+
}
3563+
3564+
Map<String, dynamic> toMap() {
3565+
return AuthenticateRequestMapper.ensureInitialized()
3566+
.encodeMap<AuthenticateRequest>(this as AuthenticateRequest);
3567+
}
3568+
3569+
AuthenticateRequestCopyWith<AuthenticateRequest, AuthenticateRequest,
3570+
AuthenticateRequest> get copyWith => _AuthenticateRequestCopyWithImpl<
3571+
AuthenticateRequest, AuthenticateRequest>(
3572+
this as AuthenticateRequest, $identity, $identity);
3573+
@override
3574+
String toString() {
3575+
return AuthenticateRequestMapper.ensureInitialized()
3576+
.stringifyValue(this as AuthenticateRequest);
3577+
}
3578+
3579+
@override
3580+
bool operator ==(Object other) {
3581+
return AuthenticateRequestMapper.ensureInitialized()
3582+
.equalsValue(this as AuthenticateRequest, other);
3583+
}
3584+
3585+
@override
3586+
int get hashCode {
3587+
return AuthenticateRequestMapper.ensureInitialized()
3588+
.hashValue(this as AuthenticateRequest);
3589+
}
3590+
}
3591+
3592+
extension AuthenticateRequestValueCopy<$R, $Out>
3593+
on ObjectCopyWith<$R, AuthenticateRequest, $Out> {
3594+
AuthenticateRequestCopyWith<$R, AuthenticateRequest, $Out>
3595+
get $asAuthenticateRequest => $base.as(
3596+
(v, t, t2) => _AuthenticateRequestCopyWithImpl<$R, $Out>(v, t, t2));
3597+
}
3598+
3599+
abstract class AuthenticateRequestCopyWith<$R, $In extends AuthenticateRequest,
3600+
$Out> implements ClientWorldEventCopyWith<$R, $In, $Out> {
3601+
@override
3602+
$R call({Uint8List? signature, Uint8List? publicKey});
3603+
AuthenticateRequestCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(
3604+
Then<$Out2, $R2> t);
3605+
}
3606+
3607+
class _AuthenticateRequestCopyWithImpl<$R, $Out>
3608+
extends ClassCopyWithBase<$R, AuthenticateRequest, $Out>
3609+
implements AuthenticateRequestCopyWith<$R, AuthenticateRequest, $Out> {
3610+
_AuthenticateRequestCopyWithImpl(super.value, super.then, super.then2);
3611+
3612+
@override
3613+
late final ClassMapperBase<AuthenticateRequest> $mapper =
3614+
AuthenticateRequestMapper.ensureInitialized();
3615+
@override
3616+
$R call({Uint8List? signature, Uint8List? publicKey}) =>
3617+
$apply(FieldCopyWithData({
3618+
if (signature != null) #signature: signature,
3619+
if (publicKey != null) #publicKey: publicKey
3620+
}));
3621+
@override
3622+
AuthenticateRequest $make(CopyWithData data) => AuthenticateRequest(
3623+
data.get(#signature, or: $value.signature),
3624+
data.get(#publicKey, or: $value.publicKey));
3625+
3626+
@override
3627+
AuthenticateRequestCopyWith<$R2, AuthenticateRequest, $Out2>
3628+
$chain<$R2, $Out2>(Then<$Out2, $R2> t) =>
3629+
_AuthenticateRequestCopyWithImpl<$R2, $Out2>($value, $cast, t);
3630+
}
3631+
33713632
class HybridWorldEventMapper extends SubClassMapperBase<HybridWorldEvent> {
33723633
HybridWorldEventMapper._();
33733634

api/lib/src/event/process/client.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,5 +279,7 @@ ServerResponse? processClientEvent(
279279
: assetManager.getPack(location.namespace)?.getMode(location.id);
280280
return ServerResponse.builder(
281281
WorldInitialized.fromMode(mode, state), channel);
282+
case AuthenticateRequest():
283+
return null;
282284
}
283285
}

api/lib/src/event/process/server.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,5 +349,9 @@ ServerProcessed processServerEvent(
349349
return ServerProcessed(state.copyWith(
350350
serverState: event.state,
351351
));
352+
case AuthenticatedRequested():
353+
return ServerProcessed(state.copyWith(
354+
authRequest: event,
355+
));
352356
}
353357
}

api/lib/src/event/server.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,12 @@ final class ServerStateUpdated extends ServerWorldEvent
224224

225225
const ServerStateUpdated(this.state);
226226
}
227+
228+
@MappableClass()
229+
final class AuthenticatedRequested extends ServerWorldEvent
230+
with AuthenticatedRequestedMappable {
231+
final Uint8List challenge;
232+
final bool isRequired;
233+
234+
const AuthenticatedRequested(this.challenge, {this.isRequired = true});
235+
}

api/lib/src/event/state.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import '../models/meta.dart';
1111
import '../models/server.dart';
1212
import '../models/table.dart';
1313
import '../models/vector.dart';
14+
import 'event.dart';
1415

1516
part 'state.mapper.dart';
1617

@@ -34,6 +35,7 @@ final class WorldState with WorldStateMappable {
3435
final List<GameDialog> dialogs;
3536
final Map<String, Uint8List> images;
3637
final ServerState serverState;
38+
final AuthenticatedRequested? authRequest;
3739

3840
const WorldState({
3941
this.name,
@@ -47,6 +49,7 @@ final class WorldState with WorldStateMappable {
4749
this.dialogs = const [],
4850
this.images = const {},
4951
this.serverState = const ServerState(),
52+
this.authRequest,
5053
required this.data,
5154
});
5255

0 commit comments

Comments
 (0)