Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianmontero committed Mar 6, 2024
2 parents 125f3aa + 20021c6 commit c0cca92
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@smontero/smartvaults-js-client",
"version": "0.0.60",
"version": "0.0.61",
"description": "SmartVaults javascript client",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
12 changes: 10 additions & 2 deletions src/event-kind-handler/DirectMessagesHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ export class DirecMessagesHandler extends EventKindHandler {
const currentAuthPubKey = this.authenticator.getPublicKey()
const chat = this.getChat()
const policyIds = await this.getPolicyIds()
const sharedKeys = await this.getSharedKeysById()
const maybePolicyIds: string[] = directMessageEvents.filter(e => e.tags.some(t => t[0] === 'e' && policyIds.has(t[1]))).map(e => getTagValue(e, TagType.Event))
let sharedKeys = new Map<string, SharedKeyAuthenticator>()
if (maybePolicyIds.length) {
sharedKeys = await this.getSharedKeysById(maybePolicyIds)
}
let newConversationsIds: string[] = []
const messagesPromises = directMessageEvents.map(async directMessageEvent => {
const storeValue = this.store.get(directMessageEvent.id, 'id')
Expand Down Expand Up @@ -156,7 +160,11 @@ export class DirecMessagesHandler extends EventKindHandler {
const rawDirectMessageEvents: Array<Event<K>> = []
const chat = this.getChat()
const policyIds = await this.getPolicyIds()
const sharedKeys = await this.getSharedKeysById()
const maybePolicyIds: string[] = directMessageEvents.filter(e => e.tags.some(t => t[0] === 'e' && policyIds.has(t[1]))).map(e => getTagValue(e, TagType.Event))
let sharedKeys = new Map<string, SharedKeyAuthenticator>()
if (maybePolicyIds.length) {
sharedKeys = await this.getSharedKeysById(maybePolicyIds)
}
let newConversationsIds: string[] = []
for (const directMessageEvent of directMessageEvents) {
const storeValue = this.store.get(directMessageEvent.id)
Expand Down
11 changes: 7 additions & 4 deletions src/event-kind-handler/TransactionMetadataHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
} from 'nostr-tools'

import { TagType } from '../enum'
import { getTagValues, fromNostrDate } from '../util'
import { fromNostrDate, getTagValue } from '../util'
import { type Store } from '../service'
import { EventKindHandler } from './EventKindHandler'
import {
Expand All @@ -30,21 +30,24 @@ export class TransactionMetadataHandler extends EventKindHandler {
const missingTransactionMetadataIds = this.store.missing(transactionMetadataIds, indexKey)

const missingtransactionMetadataEvents = transactionMetadataEvents.filter(transactionMetadataEvent => missingTransactionMetadataIds.includes(transactionMetadataEvent.id))
const policyIds = missingtransactionMetadataEvents.map(e => getTagValues(e, TagType.Event)[0])
if (!missingtransactionMetadataEvents.length) {
return this.store.getManyAsArray(transactionMetadataIds, indexKey)
}
const policyIds = missingtransactionMetadataEvents.map(e => getTagValue(e, TagType.Event))
const policyIdSharedKeyAuthenticatorMap = await this.getSharedKeysById(policyIds)
const transactionMetadataPromises = missingtransactionMetadataEvents.map(async transactionMetadataEvent => {
const {
id: transactionMetadataEventId
} = transactionMetadataEvent
const transactionMetadataId = getTagValues(transactionMetadataEvent, TagType.Identifier)[0]
const transactionMetadataId = getTagValue(transactionMetadataEvent, TagType.Identifier)
if (this.store.has(transactionMetadataId, "transactionMetadataId")) {
const replacedtransactionMetadata = this.store.get(transactionMetadataId, "transactionMetadataId")
const rawReplacedtransactionMetadataEvent = this.eventsStore.get(replacedtransactionMetadata.id)
this.store.delete(replacedtransactionMetadata)
this.eventsStore.delete(rawReplacedtransactionMetadataEvent)
}

const policyId = getTagValues(transactionMetadataEvent, TagType.Event)[0]
const policyId = getTagValue(transactionMetadataEvent, TagType.Event)
const sharedKeyAuthenticator = policyIdSharedKeyAuthenticatorMap.get(policyId)?.sharedKeyAuthenticator
if (!sharedKeyAuthenticator) return null
const transactionMetadata: TransactionMetadata = await sharedKeyAuthenticator.decryptObj(transactionMetadataEvent.content)
Expand Down
4 changes: 2 additions & 2 deletions src/models/PublishedPolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,11 @@ export class PublishedPolicy {
let trxs: Array<BasicTrxDetails> = [];
let utxos: Array<LabeledUtxo> = [];
try {
[trxs, utxos] = await Promise.all([
[trxs] = await Promise.all([
this.getTrxs(),
this.getLabeledUtxos(),
this.getTransactionMetadataByPolicyId(this.id, {})
]);
utxos = await this.getLabeledUtxos();
} catch (error) {
console.error("Error while fetching augmented transactions:", error);
return [];
Expand Down

0 comments on commit c0cca92

Please sign in to comment.