resolve conflicts

This commit is contained in:
Bekbolsun
2024-01-29 21:21:21 +06:00
11 changed files with 236 additions and 118 deletions

View File

@@ -1,5 +1,6 @@
import { nip19 } from 'nostr-tools'
import { NIP46_RELAYS } from '../consts'
import { ACTION_TYPE, NIP46_RELAYS } from '../consts'
import { DbPending } from '@/modules/db'
export async function log(s: string) {
const log = document.getElementById('log')
@@ -15,7 +16,7 @@ export async function call(cb: () => any) {
}
export const getShortenNpub = (npub = '') => {
return npub.substring(0, 10) + '...' + npub.slice(-6)
return npub.substring(0, 10) + '...' + npub.slice(-4)
}
export const getBunkerLink = (npub = '') => {
@@ -39,3 +40,41 @@ export async function askNotificationPermission() {
}
})
}
export function getSignReqKind(req: DbPending): number | undefined {
try {
const data = JSON.parse(JSON.parse(req.params)[0])
return data.kind
} catch {}
return undefined
}
export function getReqPerm(req: DbPending): string {
if (req.method === 'sign_event') {
const kind = getSignReqKind(req)
if (kind !== undefined) return `${req.method}:${kind}`
}
return req.method
}
export function isPackagePerm(perm: string, reqPerm: string) {
if (perm === ACTION_TYPE.BASIC) {
switch (reqPerm) {
case 'connect':
case 'get_public_key':
case 'nip04_decrypt':
case 'nip04_encrypt':
case 'sign_event:0':
case 'sign_event:1':
case 'sign_event:3':
case 'sign_event:6':
case 'sign_event:7':
case 'sign_event:9734':
case 'sign_event:10002':
case 'sign_event:30023':
case 'sign_event:10000':
return true
}
}
return false
}