Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@xmtp/xmtp-js

Package Overview
Dependencies
Maintainers
0
Versions
251
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xmtp/xmtp-js - npm Package Compare versions

Comparing version 12.0.1 to 12.1.0

2

package.json
{
"name": "@xmtp/xmtp-js",
"version": "12.0.1",
"version": "12.1.0",
"description": "XMTP client SDK for interacting with XMTP networks.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -16,3 +16,3 @@ import { createConsentMessage } from '@xmtp/consent-proof-signature'

export type ConsentListEntryType = 'address'
export type ConsentListEntryType = 'address' | 'groupId' | 'inboxId'

@@ -22,2 +22,10 @@ export type PrivatePreferencesAction =

type PrivatePreferencesActionKey = keyof PrivatePreferencesAction
type PrivatePreferencesActionValueKey = {
[K in PrivatePreferencesActionKey]: keyof NonNullable<
PrivatePreferencesAction[K]
>
}[PrivatePreferencesActionKey]
export class ConsentListEntry {

@@ -48,2 +56,16 @@ value: string

}
static fromGroupId(
groupId: string,
permissionType: ConsentState = 'unknown'
): ConsentListEntry {
return new ConsentListEntry(groupId, 'groupId', permissionType)
}
static fromInboxId(
inboxId: string,
permissionType: ConsentState = 'unknown'
): ConsentListEntry {
return new ConsentListEntry(inboxId, 'inboxId', permissionType)
}
}

@@ -74,2 +96,26 @@

allowGroup(groupId: string) {
const entry = ConsentListEntry.fromGroupId(groupId, 'allowed')
this.entries.set(entry.key, 'allowed')
return entry
}
denyGroup(groupId: string) {
const entry = ConsentListEntry.fromGroupId(groupId, 'denied')
this.entries.set(entry.key, 'denied')
return entry
}
allowInboxId(inboxId: string) {
const entry = ConsentListEntry.fromInboxId(inboxId, 'allowed')
this.entries.set(entry.key, 'allowed')
return entry
}
denyInboxId(inboxId: string) {
const entry = ConsentListEntry.fromInboxId(inboxId, 'denied')
this.entries.set(entry.key, 'denied')
return entry
}
state(address: string) {

@@ -80,2 +126,12 @@ const entry = ConsentListEntry.fromAddress(address)

groupState(groupId: string) {
const entry = ConsentListEntry.fromGroupId(groupId)
return this.entries.get(entry.key) ?? 'unknown'
}
inboxIdState(inboxId: string) {
const entry = ConsentListEntry.fromInboxId(inboxId)
return this.entries.get(entry.key) ?? 'unknown'
}
async getIdentifier(): Promise<string> {

@@ -122,2 +178,14 @@ if (!this._identifier) {

})
action.allowGroup?.groupIds.forEach((groupId) => {
entries.push(this.allowGroup(groupId))
})
action.denyGroup?.groupIds.forEach((groupId) => {
entries.push(this.denyGroup(groupId))
})
action.allowInboxId?.inboxIds.forEach((inboxId) => {
entries.push(this.allowInboxId(inboxId))
})
action.denyInboxId?.inboxIds.forEach((inboxId) => {
entries.push(this.denyInboxId(inboxId))
})
})

@@ -188,33 +256,51 @@

// encoded actions
const actions = entries.reduce((result, entry) => {
// only handle address entries for now
if (entry.entryType === 'address') {
const action: PrivatePreferencesAction = {
allowAddress:
entry.permissionType === 'allowed'
? {
walletAddresses: [entry.value],
}
: undefined,
denyAddress:
entry.permissionType === 'denied'
? {
walletAddresses: [entry.value],
}
: undefined,
allowGroup: undefined,
denyGroup: undefined,
allowInboxId: undefined,
denyInboxId: undefined,
// this reduce is purposefully verbose for type safety
const action = entries.reduce((result, entry) => {
let actionKey: PrivatePreferencesActionKey
let valueKey: PrivatePreferencesActionValueKey
let values: string[]
// ignore unknown permission types
if (entry.permissionType === 'unknown') {
return result
}
switch (entry.entryType) {
case 'address': {
actionKey =
entry.permissionType === 'allowed' ? 'allowAddress' : 'denyAddress'
valueKey = 'walletAddresses'
values = result[actionKey]?.[valueKey] ?? []
break
}
return result.concat(
privatePreferences.PrivatePreferencesAction.encode(action).finish()
)
case 'groupId': {
actionKey =
entry.permissionType === 'allowed' ? 'allowGroup' : 'denyGroup'
valueKey = 'groupIds'
values = result[actionKey]?.[valueKey] ?? []
break
}
case 'inboxId': {
actionKey =
entry.permissionType === 'allowed' ? 'allowInboxId' : 'denyInboxId'
valueKey = 'inboxIds'
values = result[actionKey]?.[valueKey] ?? []
break
}
default:
return result
}
return result
}, [] as Uint8Array[])
return {
...result,
[actionKey]: {
[valueKey]: [...values, entry.value],
},
}
}, {} as PrivatePreferencesAction)
// encoded action
const payload =
privatePreferences.PrivatePreferencesAction.encode(action).finish()
// encrypt payload
const { responses } = await this.client.keystore.selfEncrypt({
requests: actions.map((action) => ({ payload: action })),
requests: [{ payload }],
})

@@ -239,3 +325,3 @@

// publish entries
// publish private preferences update
await this.client.publishEnvelopes(envelopes)

@@ -372,2 +458,18 @@

isGroupAllowed(groupId: string) {
return this.consentList.groupState(groupId) === 'allowed'
}
isGroupDenied(groupId: string) {
return this.consentList.groupState(groupId) === 'denied'
}
isInboxAllowed(inboxId: string) {
return this.consentList.inboxIdState(inboxId) === 'allowed'
}
isInboxDenied(inboxId: string) {
return this.consentList.inboxIdState(inboxId) === 'denied'
}
consentState(address: string) {

@@ -377,2 +479,10 @@ return this.consentList.state(address)

groupConsentState(groupId: string) {
return this.consentList.groupState(groupId)
}
inboxConsentState(inboxId: string) {
return this.consentList.inboxIdState(inboxId)
}
async allow(addresses: string[]) {

@@ -393,2 +503,30 @@ await this.consentList.publish(

}
async allowGroups(groupIds: string[]) {
await this.consentList.publish(
groupIds.map((groupId) =>
ConsentListEntry.fromGroupId(groupId, 'allowed')
)
)
}
async denyGroups(groupIds: string[]) {
await this.consentList.publish(
groupIds.map((groupId) => ConsentListEntry.fromGroupId(groupId, 'denied'))
)
}
async allowInboxes(inboxIds: string[]) {
await this.consentList.publish(
inboxIds.map((inboxId) =>
ConsentListEntry.fromInboxId(inboxId, 'allowed')
)
)
}
async denyInboxes(inboxIds: string[]) {
await this.consentList.publish(
inboxIds.map((inboxId) => ConsentListEntry.fromInboxId(inboxId, 'denied'))
)
}
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc