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

thirtyDayPeriodsSinceEpoch fix #276

Closed
wants to merge 2 commits into from
Closed
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 Sources/XMTPiOS/Conversations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,9 @@ public actor Conversations {
}

public func getHmacKeys(request: Xmtp_KeystoreApi_V1_GetConversationHmacKeysRequest? = nil) -> Xmtp_KeystoreApi_V1_GetConversationHmacKeysResponse {
let thirtyDayPeriodsSinceEpoch = Int(Date().timeIntervalSince1970) / (60 * 60 * 24 * 30)
let daysSinceEpoch = Date().timeIntervalSince1970 / (60 * 60 * 24)
let thirtyDayPeriodsSinceEpoch = Int(floor(daysSinceEpoch / 30))
Comment on lines +590 to +591
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JS divides also by 1000 every where but I think that might be a bug in JS @rygine


var hmacKeysResponse = Xmtp_KeystoreApi_V1_GetConversationHmacKeysResponse()

var topics = conversationsByTopic
Expand Down
3 changes: 2 additions & 1 deletion Sources/XMTPiOS/Messages/MessageV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ extension MessageV2 {

let ciphertext = try Crypto.encrypt(keyMaterial, signedBytes, additionalData: headerBytes)

let thirtyDayPeriodsSinceEpoch = Int(date.timeIntervalSince1970 / 60 / 60 / 24 / 30)
let daysSinceEpoch = Date().timeIntervalSince1970 / (60 * 60 * 24)
let thirtyDayPeriodsSinceEpoch = Int(floor(daysSinceEpoch / 30))
let info = "\(thirtyDayPeriodsSinceEpoch)-\(client.address)"
guard let infoEncoded = info.data(using: .utf8) else {
throw MessageV2Error.invalidData
Expand Down
Loading