1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
use core::{fmt::Debug, hash::Hash};
use std::{
borrow::Cow,
time::{Duration, SystemTime},
};
use crate::{BaseUtils, Cluster, RandomBytes, WalletAccount, WalletBaseError, WalletBaseResult};
/// The Sign In input used as parameters when performing
/// `SignInWithSolana (SIWS)` requests as defined by the
/// [SIWS](https://github.com/phantom/sign-in-with-solana) standard.
/// A backup fork can be found at [https://github.com/JamiiDao/sign-in-with-solana](https://github.com/JamiiDao/sign-in-with-solana)
#[derive(Debug, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct SignInInput<'wa> {
/// Optional EIP-4361 domain requesting the sign-in.
/// If not provided, the wallet must determine the domain to include in the message.
domain: Option<Cow<'wa, str>>,
/// Optional Solana Base58 address performing the sign-in.
/// The address is case-sensitive.
/// If not provided, the wallet must determine the Address to include in the message.
address: Option<Cow<'wa, str>>,
/// Optional EIP-4361 Statement.
/// The statement is a human readable string and should not have new-line characters (\n).
/// If not provided, the wallet does not include Statement in the message.
statement: Option<Cow<'wa, str>>,
/// Optional EIP-4361 URI.
/// The URL that is requesting the sign-in.
/// If not provided, the wallet does not include URI in the message.
uri: Option<Cow<'wa, str>>,
/// Optional EIP-4361 version.
/// If not provided, the wallet does not include Version in the message.
version: Option<Cow<'wa, str>>,
/// Optional EIP-4361 Chain ID.
/// The chainId can be one of the following:
/// mainnet, testnet, devnet, localnet, solana:mainnet, solana:testnet, solana:devnet.
/// If not provided, the wallet does not include Chain ID in the message.
chain_id: Option<Cow<'wa, str>>,
/// Optional EIP-4361 Nonce.
/// It should be an alphanumeric string containing a minimum of 8 characters.
/// If not provided, the wallet does not include Nonce in the message.
nonce: Option<Cow<'wa, str>>,
/// Optional ISO 8601 datetime string.
/// This represents the time at which the sign-in request was issued to the wallet.
/// Note: For Phantom, issuedAt has a threshold and it should be
/// within +- 10 minutes from the timestamp at which verification is taking place.
/// If not provided, the wallet does not include Issued At in the message.
issued_at: Option<Cow<'wa, str>>,
/// Optional ISO 8601 datetime string.
/// This represents the time at which the sign-in request should expire.
/// If not provided, the wallet does not include Expiration Time in the message.
expiration_time: Option<Cow<'wa, str>>,
/// Optional ISO 8601 datetime string.
/// This represents the time at which the sign-in request becomes valid.
/// If not provided, the wallet does not include Not Before in the message.
not_before: Option<Cow<'wa, str>>,
/// Optional EIP-4361 Request ID.
/// In addition to using nonce to avoid replay attacks,
/// dapps can also choose to include a unique signature in the requestId .
/// Once the wallet returns the signed message,
/// dapps can then verify this signature against the state to add an additional,
/// strong layer of security. If not provided, the wallet does not include Request ID in the message.
request_id: Option<Cow<'wa, str>>,
/// Optional EIP-4361 Resources.
/// Usually a list of references in the form of URIs that the
/// dapp wants the user to be aware of.
/// These URIs should be separated by \n-, ie,
/// URIs in new lines starting with the character -.
/// If not provided, the wallet does not include Resources in the message.
resources: Cow<'wa, [Cow<'wa, str>]>,
}
impl<'wa> SignInInput<'_> {
/// Same as `Self::default()` as it initializes [Self] with default values
pub fn new() -> Self {
Self::default()
}
/// An EIP-4361 domain requesting the sign-in.
/// If not provided, the wallet must determine the domain to include in the message.
pub fn set_domain(&mut self, domain: &str) -> &mut Self {
self.domain.replace(Cow::Owned(domain.to_string()));
self
}
/// The Base58 public key address
/// NOTE: Some wallets require this field or
/// an error `MessageResponseMismatch` is returned which is as
/// a result of the sent message not corresponding with the signed message
pub fn set_address(&'_ mut self, address: &str) -> WalletBaseResult<'_, &'_ mut Self> {
let mut buffer = [0u8; 32];
let buffer_written_len = bs58::decode(address).onto(&mut buffer).or(Err(
WalletBaseError::InvalidBase58Address(Cow::Owned(address.to_string())),
))?;
if buffer_written_len != 32 {
return Err(WalletBaseError::InvalidEd25519PublicKeyLen(
buffer_written_len as u8,
));
}
self.address.replace(Cow::Owned(address.to_string()));
Ok(self)
}
/// An EIP-4361 Statement which is a human readable string and should not have new-line characters (\n).
/// Sets the message that is shown to the user during Sign In With Solana
pub fn set_statement(&mut self, statement: &str) -> &mut Self {
self.statement.replace(Cow::Owned(statement.to_string()));
self
}
/// An EIP-4361 URI is automatically set to the `window.location.href`
/// since if it is not the same, the wallet will ignore it and
/// show the user an error.
/// This is the URL that is requesting the sign-in.
pub fn set_uri(&mut self, uri: &str) -> &mut Self {
self.uri.replace(Cow::Owned(uri.to_string()));
self
}
/// An EIP-4361 version.
/// Sets the version
pub fn set_version(&mut self, version: &str) -> &mut Self {
self.version.replace(Cow::Owned(version.to_string()));
self
}
/// An EIP-4361 Chain ID.
/// The chainId can be one of the following:
/// mainnet, testnet, devnet, localnet, solana:mainnet, solana:testnet, solana:devnet.
pub fn set_chain_id(&mut self, cluster: impl Cluster) -> &mut Self {
self.chain_id
.replace(Cow::Owned(cluster.chain().to_string()));
self
}
/// An EIP-4361 Nonce which is an alphanumeric string containing a minimum of 8 characters.
/// This is generated from the Cryptographically Secure Random Number Generator
/// and the bytes converted to hex formatted string.
pub fn set_nonce(&mut self) -> &mut Self {
let random_bytes = RandomBytes::<32>::generate();
self.nonce
.replace(Cow::Owned(blake3::hash(random_bytes.expose()).to_string()));
self
}
/// An EIP-4361 Nonce which is an alphanumeric string containing a minimum of 8 characters.
/// This is generated from the Cryptographically Secure Random Number Generator
/// and the bytes converted to hex formatted string.
pub fn set_custom_nonce(&'_ mut self, nonce: &str) -> WalletBaseResult<'_, &'_ mut Self> {
let nonce_length = nonce.len();
if nonce_length < 8 {
return Err(WalletBaseError::NonceMustBeAtLeast8Characters(
nonce_length as u8,
));
}
self.nonce.replace(Cow::Owned(nonce.to_string()));
Ok(self)
}
/// This represents the time at which the sign-in request was issued to the wallet.
/// Note: For Phantom, issuedAt has a threshold and it should be within +- 10 minutes
/// from the timestamp at which verification is taking place.
/// If not provided, the wallet does not include Issued At in the message.
/// This also follows the ISO 8601 datetime.
pub fn set_issued_at(&mut self, time: SystemTime) -> &mut Self {
self.issued_at.replace(Cow::Owned(
humantime::format_rfc3339_millis(time).to_string(),
));
self
}
/// An ergonomic method for [Self::set_expiration_time()]
/// where you can add milliseconds and [SystemTime] is automatically calculated for you
pub fn set_expiration_time_millis(
&'_ mut self,
now: SystemTime,
expiration_time_milliseconds: u64,
) -> WalletBaseResult<'_, &'_ mut Self> {
let duration = Duration::from_millis(expiration_time_milliseconds);
self.set_expiry_internal(now, duration)
}
/// An ergonomic method for [Self::set_expiration_time()]
/// where you can add seconds and [SystemTime] is automatically calculated for you
pub fn set_expiration_time_seconds(
&'_ mut self,
now: SystemTime,
expiration_time_seconds: u64,
) -> WalletBaseResult<'_, &'_ mut Self> {
let duration = Duration::from_secs(expiration_time_seconds);
self.set_expiry_internal(now, duration)
}
fn set_expiry_internal(
&'_ mut self,
now: SystemTime,
duration: Duration,
) -> WalletBaseResult<'_, &'_ mut Self> {
let expiry_time = if let Some(issued_time) = self.issued_at.as_ref() {
let issued_time = humantime::parse_rfc3339(issued_time).or(Err(
WalletBaseError::InvalidISO8601Timestamp(issued_time.clone()),
))?;
issued_time
.checked_add(duration)
.ok_or(WalletBaseError::SystemTimeCheckedAddOverflow)?
} else {
now
};
self.set_expiration_time(now, expiry_time)
}
/// An ISO 8601 datetime string. This represents the time at which the sign-in request should expire.
/// If not provided, the wallet does not include Expiration Time in the message.
/// Expiration time should be in future or an error will be thrown even before a request to the wallet is sent
pub fn set_expiration_time(
&'_ mut self,
now: SystemTime,
expiration_time: SystemTime,
) -> WalletBaseResult<'_, &'_ mut Self> {
if let Some(issued_at) = self.issued_at.as_ref() {
let issued_at = humantime::parse_rfc3339(issued_at).or(Err(
WalletBaseError::InvalidISO8601Timestamp(issued_at.clone()),
))?;
if issued_at > expiration_time {
let issued = BaseUtils::to_iso860(issued_at).to_string();
let expiry = BaseUtils::to_iso860(expiration_time).to_string();
return Err(WalletBaseError::ExpiryTimeEarlierThanIssuedTime {
issued: issued.into(),
expiry: expiry.into(),
});
}
}
if now > expiration_time {
let now = BaseUtils::to_iso860(now).to_string();
let expiry = BaseUtils::to_iso860(expiration_time).to_string();
return Err(WalletBaseError::ExpirationTimeIsInThePast {
now: now.into(),
expiry: expiry.into(),
});
}
self.expiration_time.replace(Cow::Owned(
humantime::format_rfc3339_millis(expiration_time).to_string(),
));
Ok(self)
}
fn set_not_before_internal(
&'_ mut self,
now: SystemTime,
duration: Duration,
) -> WalletBaseResult<'_, &'_ mut Self> {
let not_before = if let Some(issued_time) = self.issued_at.as_ref() {
let issued_time = humantime::parse_rfc3339(issued_time).or(Err(
WalletBaseError::InvalidISO8601Timestamp(issued_time.clone()),
))?;
issued_time
.checked_add(duration)
.ok_or(WalletBaseError::SystemTimeCheckedAddOverflow)?
} else {
now
};
self.set_not_before_time(now, not_before)
}
/// An ergonomic method for [Self::set_not_before_time()]
/// where you can add milliseconds and [SystemTime] is automatically calculated for you
pub fn set_not_before_time_millis(
&'_ mut self,
now: SystemTime,
expiration_time_milliseconds: u64,
) -> WalletBaseResult<'_, &'_ mut Self> {
let duration = Duration::from_millis(expiration_time_milliseconds);
self.set_not_before_internal(now, duration)
}
/// An ergonomic method for [Self::set_not_before_time()]
/// where you can add seconds and [SystemTime] is automatically calculated for you
pub fn set_not_before_time_seconds(
&'_ mut self,
now: SystemTime,
expiration_time_seconds: u64,
) -> WalletBaseResult<'_, &'_ mut Self> {
let duration = Duration::from_secs(expiration_time_seconds);
self.set_not_before_internal(now, duration)
}
/// An ISO 8601 datetime string.
/// This represents the time at which the sign-in request becomes valid.
/// If not provided, the wallet does not include Not Before in the message.
/// Time must be after `IssuedTime`
pub fn set_not_before_time(
&'_ mut self,
now: SystemTime,
not_before: SystemTime,
) -> WalletBaseResult<'_, &'_ mut Self> {
if let Some(issued_at) = self.issued_at.as_ref() {
let issued_at = humantime::parse_rfc3339(issued_at).or(Err(
WalletBaseError::InvalidISO8601Timestamp(issued_at.clone()),
))?;
if issued_at > not_before {
let issued = BaseUtils::to_iso860(issued_at).to_string();
let not_before = BaseUtils::to_iso860(not_before).to_string();
return Err(WalletBaseError::NotBeforeTimeEarlierThanIssuedTime {
issued_at: issued.into(),
not_before: not_before.into(),
});
}
}
if now > not_before {
let now = BaseUtils::to_iso860(now).to_string();
let not_before = BaseUtils::to_iso860(not_before).to_string();
return Err(WalletBaseError::NotBeforeTimeIsInThePast {
now: now.into(),
not_before: not_before.into(),
});
}
if let Some(expiration_time) = self.expiration_time.as_ref() {
let expiration_time = humantime::parse_rfc3339(expiration_time).or(Err(
WalletBaseError::InvalidISO8601Timestamp(expiration_time.clone()),
))?;
if not_before > expiration_time {
let expiry = BaseUtils::to_iso860(expiration_time).to_string();
let not_before = BaseUtils::to_iso860(not_before).to_string();
return Err(WalletBaseError::NotBeforeTimeLaterThanExpirationTime {
not_before: not_before.into(),
expiry: expiry.into(),
});
}
}
self.not_before.replace(Cow::Owned(
humantime::format_rfc3339_millis(not_before).to_string(),
));
Ok(self)
}
/// Parses the Sign In With Solana (SIWS) result of the Response from a wallet
pub fn parser(input: &'wa str) -> WalletBaseResult<'wa, SignInInput<'wa>> {
let mut signin_input = SignInInput::default();
input
.split_once(" ")
.map(|(left, _right)| signin_input.domain.replace(left.trim().into()));
let split_colon = |value: &str| -> Option<Cow<'_, str>> {
value
.split_once(":")
.map(|(_left, right)| Cow::Owned(right.trim().to_string()))
};
let split_colon_system_time = |value: &str| -> WalletBaseResult<Option<Cow<'_, str>>> {
value
.split_once(":")
.map(|(_left, right)| {
humantime::parse_rfc3339(right.trim()).or(Err(
WalletBaseError::InvalidISO8601Timestamp(right.to_string().into()),
))?;
Ok(Cow::Owned(right.to_string()))
})
.transpose()
};
input
.split("\n")
.enumerate()
.try_for_each(|(index, input)| {
if index == 1 {
signin_input.address.replace(input.trim().into());
}
if index == 3 {
signin_input.statement.replace(input.trim().into());
}
if input.contains("URI") {
signin_input.uri = split_colon(input);
}
if input.contains("Version") {
signin_input.version = split_colon(input);
}
if input.contains("Chain ID") {
if let Some((_left, right)) = input.split_once(":") {
let cluster = right.trim().into();
signin_input.chain_id.replace(cluster);
}
}
if input.contains("Nonce") {
signin_input.nonce = split_colon(input);
}
if input.contains("Issued At") {
signin_input.issued_at = split_colon_system_time(input)?;
}
if input.contains("Expiration") {
signin_input.expiration_time = split_colon_system_time(input)?;
}
if input.contains("Not Before") {
signin_input.not_before = split_colon_system_time(input)?;
}
if input.contains("Request ID") {
signin_input.request_id = split_colon(input);
}
if input.starts_with("-") {
if let Some(value) = input.split("-").nth(1) {
signin_input
.resources
.to_mut()
.push(Cow::Owned(value.trim().to_string()));
}
}
Ok::<(), WalletBaseError>(())
})?;
Ok(signin_input)
}
/// Checks if the response of a Sign In With Solana (SIWS) from the Wallet is the same as the
/// request data sent to the wallet to be signed
pub fn check_eq(&'_ self, other: &'_ Self) -> WalletBaseResult<'_, ()> {
if self.eq(other) {
Ok(())
} else {
Err(WalletBaseError::MessageResponseMismatch)
}
}
/// An EIP-4361 Request ID.
/// In addition to using nonce to avoid replay attacks,
/// dapps can also choose to include a unique signature in the requestId .
/// Once the wallet returns the signed message,
/// dapps can then verify this signature against the state to add an additional,
/// strong layer of security. If not provided, the wallet must not include Request ID in the message.
pub fn set_request_id(&mut self, id: &str) -> &mut Self {
self.request_id.replace(Cow::Owned(id.into()));
self
}
/// An EIP-4361 Resources.
/// Usually a list of references in the form of URIs that the dapp wants the user to be aware of.
/// These URIs should be separated by \n-, ie, URIs in new lines starting with the character -.
/// If not provided, the wallet must not include Resources in the message.
pub fn add_resource(&mut self, resource: &str) -> &mut Self {
self.resources
.to_mut()
.push(Cow::Owned(resource.to_string()));
self
}
/// Helper for [Self::add_resource()] when you want to add multiple resources at the same time
pub fn add_resources(&mut self, resources: &[&str]) -> &mut Self {
resources.iter().for_each(|resource| {
self.resources
.to_mut()
.push(Cow::Owned(resource.to_string()))
});
self
}
/// Get the `domain` field
pub fn domain(&self) -> Option<&str> {
self.domain.as_deref()
}
/// Get the `address` field
pub fn address(&self) -> Option<&str> {
self.address.as_deref()
}
/// Get the `statement` field
pub fn statement(&self) -> Option<&str> {
self.statement.as_deref()
}
/// Get the `uri` field
pub fn uri(&self) -> Option<&str> {
self.uri.as_deref()
}
/// Get the `version` field
pub fn version(&self) -> Option<&str> {
self.version.as_deref()
}
/// Get the `chain_id` field
pub fn chain_id(&self) -> Option<&str> {
self.chain_id.as_deref()
}
/// Get the `nonce` field
pub fn nonce(&self) -> Option<&str> {
self.nonce.as_deref()
}
/// Get the `issued_at` field
pub fn issued_at(&self) -> Option<&Cow<'_, str>> {
self.issued_at.as_ref()
}
/// Get the `expiration_time` field
pub fn expiration_time(&self) -> Option<&Cow<'_, str>> {
self.expiration_time.as_ref()
}
/// Get the `not_before` field
pub fn not_before(&self) -> Option<&Cow<'_, str>> {
self.not_before.as_ref()
}
/// Get the `issued_at` field
pub fn issued_at_system_time(&self) -> Option<SystemTime> {
self.issued_at
.as_ref()
.map(|value| humantime::parse_rfc3339(value).ok())?
}
/// Get the `expiration_time` field
pub fn expiration_time_system_time(&self) -> Option<SystemTime> {
self.expiration_time
.as_ref()
.map(|value| humantime::parse_rfc3339(value).ok())?
}
/// Get the `not_before` field
pub fn not_before_system_time(&self) -> Option<SystemTime> {
self.not_before
.as_ref()
.map(|value| humantime::parse_rfc3339(value).ok())?
}
/// Get the `request_id` field
pub fn request_id(&self) -> Option<&str> {
self.request_id.as_deref()
}
/// Get the `resources` field
pub fn resources(&'wa self) -> &'wa [Cow<'wa, str>] {
&self.resources
}
}
/// The output of Sign In With Solana (SIWS) response from a wallet
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)]
pub struct SignInOutput<T: WalletAccount + Debug + Clone + Hash + Ord + PartialEq + Eq + Default> {
/// A [An Account](WalletAccountData)
pub account: T,
/// The UTF-8 encoded message
pub message: String,
/// The signature as a byte array of 64 bytes in length corresponding to a
/// [Ed25519 Signature](ed25519_dalek::Signature)
pub signature: [u8; 64],
/// The public key as a byte array of 32 bytes in length corresponding to a
/// [Ed25519 Public Key](ed25519_dalek::VerifyingKey)
pub public_key: [u8; 32],
}
#[cfg(test)]
#[cfg(target_arch = "wasm32")]
mod signin_input_sanity_checks {
use super::*;
#[test]
fn set_issued_at() {
let mut signin_input = SigninInput::default();
assert!(signin_input.issued_at().is_none());
signin_input.set_issued_at().unwrap();
assert!(signin_input.issued_at.unwrap() > SystemTime::UNIX_EPOCH)
}
#[test]
fn set_expiration_time() {
let mut signin_input = SigninInput::default();
let now = SigninInput::time_now().unwrap();
let past_time = now.checked_sub(Duration::from_secs(300)).unwrap();
assert_eq!(
Some(WalletError::ExpirationTimeIsInThePast),
signin_input.set_expiration_time(past_time).err()
);
signin_input.set_issued_at().unwrap();
assert_eq!(
Some(WalletError::ExpiryTimeEarlierThanIssuedTime),
signin_input.set_expiration_time(past_time).err()
);
let valid_expiry = now.checked_add(Duration::from_secs(300)).unwrap();
assert!(signin_input.set_expiration_time(valid_expiry).is_ok());
assert!(signin_input.issued_at.unwrap() > SystemTime::UNIX_EPOCH);
assert!(signin_input.set_expiration_time_millis(4000).is_ok());
assert!(signin_input.set_expiration_time_seconds(4).is_ok());
}
#[test]
fn set_not_before_time() {
let mut signin_input = SigninInput::default();
let now = SigninInput::time_now().unwrap();
let past_time = now.checked_sub(Duration::from_secs(300)).unwrap();
assert_eq!(
Some(WalletError::NotBeforeTimeIsInThePast),
signin_input.set_not_before_time(past_time).err()
);
signin_input.set_issued_at().unwrap();
let future_time = now.checked_sub(Duration::from_secs(3000000)).unwrap();
assert_eq!(
Some(WalletError::NotBeforeTimeEarlierThanIssuedTime),
signin_input.set_not_before_time(future_time).err()
);
signin_input.set_issued_at().unwrap();
let future_time = SigninInput::time_now()
.unwrap()
.checked_add(Duration::from_secs(30000))
.unwrap();
signin_input.set_expiration_time(future_time).unwrap();
let future_time = now.checked_add(Duration::from_secs(3000000)).unwrap();
assert_eq!(
Some(WalletError::NotBeforeTimeLaterThanExpirationTime),
signin_input.set_not_before_time(future_time).err()
);
let valid_expiry = now.checked_add(Duration::from_secs(300)).unwrap();
assert!(signin_input.set_not_before_time(valid_expiry).is_ok());
assert!(signin_input.issued_at.unwrap() > SystemTime::UNIX_EPOCH);
assert!(signin_input.set_not_before_time_millis(4000).is_ok());
assert!(signin_input.set_not_before_time_seconds(4).is_ok());
}
}