Skip to content

Commit

Permalink
Derive topic identifier instead of using wallet address
Browse files Browse the repository at this point in the history
  • Loading branch information
nakajima committed Oct 13, 2023
1 parent 87c1df3 commit fb6166e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
"location" : "https://github.com/xmtp/xmtp-rust-swift",
"state" : {
"branch" : "main",
"revision" : "d1aaac47fc7c57645a6fe9e06972b957b3efa33c"
"revision" : "e857176b7e368c51e1dadcbbcce648bb20432f26"
}
}
],
Expand Down
12 changes: 8 additions & 4 deletions Sources/XMTP/Contacts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ class AllowList {
var entries: [String: AllowState] = [:]

static func load(from client: Client) async throws -> AllowList {
let envelopes = try await client.query(topic: .allowList(client.address))
let publicKey = client.privateKeyBundleV1.identityKey.publicKey.secp256K1Uncompressed.bytes
let privateKey = client.privateKeyBundleV1.identityKey.secp256K1.bytes

let identifier = try XMTPRust.generate_private_preferences_topic_identifier(RustVec(privateKey)).toString()
let envelopes = try await client.query(topic: .allowList(identifier))
let allowList = AllowList()

for envelope in envelopes.envelopes {
let publicKey = client.privateKeyBundleV1.identityKey.publicKey.secp256K1Uncompressed.bytes
let privateKey = client.privateKeyBundleV1.identityKey.secp256K1.bytes


let payload = try XMTPRust.ecies_decrypt_k256_sha3_256(
RustVec(publicKey),
Expand All @@ -60,6 +63,7 @@ class AllowList {

let publicKey = client.privateKeyBundleV1.identityKey.publicKey.secp256K1Uncompressed.bytes
let privateKey = client.privateKeyBundleV1.identityKey.secp256K1.bytes
let identifier = try XMTPRust.generate_private_preferences_topic_identifier(RustVec(privateKey)).toString()

let message = try XMTPRust.ecies_encrypt_k256_sha3_256(
RustVec(publicKey),
Expand All @@ -68,7 +72,7 @@ class AllowList {
)

let envelope = Envelope(
topic: Topic.allowList(client.address),
topic: Topic.allowList(identifier),
timestamp: Date(),
message: Data(message)
)
Expand Down

0 comments on commit fb6166e

Please sign in to comment.