@@ -9,17 +9,15 @@ import org.xmtp.android.library.messages.walletAddress
9
9
import org.xmtp.proto.message.contents.PrivatePreferences.PrivatePreferencesAction
10
10
import java.util.Date
11
11
12
- typealias MessageType = PrivatePreferencesAction .MessageTypeCase
13
-
14
- enum class AllowState {
15
- ALLOW ,
16
- BLOCK ,
12
+ enum class ConsentState {
13
+ ALLOWED ,
14
+ BLOCKED ,
17
15
UNKNOWN
18
16
}
19
- data class AllowListEntry (
17
+ data class ConsentListEntry (
20
18
val value : String ,
21
19
val entryType : EntryType ,
22
- val permissionType : AllowState ,
20
+ val consentType : ConsentState ,
23
21
) {
24
22
enum class EntryType {
25
23
ADDRESS
@@ -28,18 +26,18 @@ data class AllowListEntry(
28
26
companion object {
29
27
fun address (
30
28
address : String ,
31
- type : AllowState = AllowState .UNKNOWN ,
32
- ): AllowListEntry {
33
- return AllowListEntry (address, EntryType .ADDRESS , type)
29
+ type : ConsentState = ConsentState .UNKNOWN ,
30
+ ): ConsentListEntry {
31
+ return ConsentListEntry (address, EntryType .ADDRESS , type)
34
32
}
35
33
}
36
34
37
35
val key: String
38
36
get() = " ${entryType.name} -$value "
39
37
}
40
38
41
- class AllowList (val client : Client ) {
42
- private val entries: MutableMap <String , AllowState > = mutableMapOf ()
39
+ class ConsentList (val client : Client ) {
40
+ private val entries: MutableMap <String , ConsentState > = mutableMapOf ()
43
41
private val publicKey =
44
42
client.privateKeyBundleV1.identityKey.publicKey.secp256K1Uncompressed.bytes
45
43
private val privateKey = client.privateKeyBundleV1.identityKey.secp256K1.bytes
@@ -50,9 +48,9 @@ class AllowList(val client: Client) {
50
48
)
51
49
52
50
@OptIn(ExperimentalUnsignedTypes ::class )
53
- suspend fun load (): AllowList {
51
+ suspend fun load (): ConsentList {
54
52
val envelopes = client.query(Topic .preferenceList(identifier))
55
- val allowList = AllowList (client)
53
+ val consentList = ConsentList (client)
56
54
val preferences: MutableList <PrivatePreferencesAction > = mutableListOf ()
57
55
58
56
for (envelope in envelopes.envelopesList) {
@@ -71,22 +69,22 @@ class AllowList(val client: Client) {
71
69
72
70
preferences.iterator().forEach { preference ->
73
71
preference.allow?.walletAddressesList?.forEach { address ->
74
- allowList .allow(address)
72
+ consentList .allow(address)
75
73
}
76
74
preference.block?.walletAddressesList?.forEach { address ->
77
- allowList .block(address)
75
+ consentList .block(address)
78
76
}
79
77
}
80
- return allowList
78
+ return consentList
81
79
}
82
80
83
81
@OptIn(ExperimentalUnsignedTypes ::class )
84
- fun publish (entry : AllowListEntry ) {
82
+ fun publish (entry : ConsentListEntry ) {
85
83
val payload = PrivatePreferencesAction .newBuilder().also {
86
- when (entry.permissionType ) {
87
- AllowState . ALLOW -> it.setAllow(PrivatePreferencesAction .Allow .newBuilder().addWalletAddresses(entry.value))
88
- AllowState . BLOCK -> it.setBlock(PrivatePreferencesAction .Block .newBuilder().addWalletAddresses(entry.value))
89
- AllowState .UNKNOWN -> it.clearMessageType()
84
+ when (entry.consentType ) {
85
+ ConsentState . ALLOWED -> it.setAllow(PrivatePreferencesAction .Allow .newBuilder().addWalletAddresses(entry.value))
86
+ ConsentState . BLOCKED -> it.setBlock(PrivatePreferencesAction .Block .newBuilder().addWalletAddresses(entry.value))
87
+ ConsentState .UNKNOWN -> it.clearMessageType()
90
88
}
91
89
}.build()
92
90
@@ -105,22 +103,22 @@ class AllowList(val client: Client) {
105
103
client.publish(listOf (envelope))
106
104
}
107
105
108
- fun allow (address : String ): AllowListEntry {
109
- entries[AllowListEntry .address(address).key] = AllowState . ALLOW
106
+ fun allow (address : String ): ConsentListEntry {
107
+ entries[ConsentListEntry .address(address).key] = ConsentState . ALLOWED
110
108
111
- return AllowListEntry .address(address, AllowState . ALLOW )
109
+ return ConsentListEntry .address(address, ConsentState . ALLOWED )
112
110
}
113
111
114
- fun block (address : String ): AllowListEntry {
115
- entries[AllowListEntry .address(address).key] = AllowState . BLOCK
112
+ fun block (address : String ): ConsentListEntry {
113
+ entries[ConsentListEntry .address(address).key] = ConsentState . BLOCKED
116
114
117
- return AllowListEntry .address(address, AllowState . BLOCK )
115
+ return ConsentListEntry .address(address, ConsentState . BLOCKED )
118
116
}
119
117
120
- fun state (address : String ): AllowState {
121
- val state = entries[AllowListEntry .address(address).key]
118
+ fun state (address : String ): ConsentState {
119
+ val state = entries[ConsentListEntry .address(address).key]
122
120
123
- return state ? : AllowState .UNKNOWN
121
+ return state ? : ConsentState .UNKNOWN
124
122
}
125
123
}
126
124
@@ -130,31 +128,31 @@ data class Contacts(
130
128
val hasIntroduced : MutableMap <String , Boolean > = mutableMapOf(),
131
129
) {
132
130
133
- var allowList : AllowList = AllowList (client)
131
+ var consentList : ConsentList = ConsentList (client)
134
132
135
- fun refreshAllowList () {
133
+ fun refreshConsentList () {
136
134
runBlocking {
137
- allowList = AllowList (client).load()
135
+ consentList = ConsentList (client).load()
138
136
}
139
137
}
140
138
141
139
fun isAllowed (address : String ): Boolean {
142
- return allowList .state(address) == AllowState . ALLOW
140
+ return consentList .state(address) == ConsentState . ALLOWED
143
141
}
144
142
145
143
fun isBlocked (address : String ): Boolean {
146
- return allowList .state(address) == AllowState . BLOCK
144
+ return consentList .state(address) == ConsentState . BLOCKED
147
145
}
148
146
149
147
fun allow (addresses : List <String >) {
150
148
for (address in addresses) {
151
- AllowList (client).publish(allowList .allow(address))
149
+ ConsentList (client).publish(consentList .allow(address))
152
150
}
153
151
}
154
152
155
153
fun block (addresses : List <String >) {
156
154
for (address in addresses) {
157
- AllowList (client).publish(allowList .block(address))
155
+ ConsentList (client).publish(consentList .block(address))
158
156
}
159
157
}
160
158
0 commit comments