-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* preparing SIWS parsing with tests * bit of cleaning * siws sdk updates (prelim, needs work) * sign in working! * centralize sign in payload logic * add some more tests * garrrrr fix bad refactor in test code * ui tests * simulate sign in not supported (fallback on sign message)
- Loading branch information
1 parent
ac83e6d
commit f3f5739
Showing
29 changed files
with
1,702 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
.../common/src/main/java/com/solana/mobilewalletadapter/common/datetime/Iso8601DateTime.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.solana.mobilewalletadapter.common.datetime; | ||
|
||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
import java.util.Locale; | ||
import java.util.TimeZone; | ||
|
||
public class Iso8601DateTime { | ||
|
||
static final String ISO_8601_FORMAT_STRING = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; | ||
static final String ISO_8601_FORMAT_STRING_NO_ZONE = "yyyy-MM-dd'T'HH:mm:ss.SSS"; | ||
|
||
public static String now() { | ||
return formatUtc(new Date()); | ||
} | ||
|
||
public static String formatUtc(Date date) { | ||
SimpleDateFormat format = new SimpleDateFormat(ISO_8601_FORMAT_STRING_NO_ZONE, Locale.US); | ||
format.setTimeZone(TimeZone.getTimeZone("UTC")); | ||
return format.format(date) + "Z"; | ||
} | ||
|
||
public static Date parse(String iso8601String) throws ParseException { | ||
SimpleDateFormat format = new SimpleDateFormat(ISO_8601_FORMAT_STRING, Locale.US); | ||
try { | ||
String formattedDate = iso8601String; | ||
if (formattedDate.endsWith("Z")) { | ||
// SimpleDateFormat does not comprehend "Z" (UTC), so replace it | ||
formattedDate = formattedDate.replace("Z", "+0000"); | ||
} else { | ||
// SimpleDateFormat requires zone to be in +/-hhmm, so remove ":" | ||
formattedDate = formattedDate.replaceAll("([+-]\\d\\d):(\\d\\d)\\s*$", "$1$2"); | ||
} | ||
// add microseconds field if missing | ||
formattedDate = formattedDate.replaceAll("(T\\d\\d)(:\\d\\d)(:\\d\\d)([+-])", "$1$2$3.000$4"); | ||
|
||
return format.parse(formattedDate); | ||
} catch (ParseException e) { | ||
throw new ParseException("Failed to parse input as ISO 8601", e.getErrorOffset()); | ||
} | ||
} | ||
|
||
private Iso8601DateTime() {} | ||
} |
Oops, something went wrong.