add nip-26 support
This commit is contained in:
@@ -6,7 +6,7 @@ import {
|
||||
getPublicKey,
|
||||
nip19
|
||||
} from 'nostr-tools'
|
||||
import {nip04} from 'nostr-tools'
|
||||
import {nip04, nip26} from 'nostr-tools'
|
||||
import {Mutex} from 'async-mutex'
|
||||
|
||||
import {
|
||||
@@ -142,6 +142,11 @@ async function handleContentScriptMessage({type, params, host}) {
|
||||
let {peer, ciphertext} = params
|
||||
return decrypt(sk, peer, ciphertext)
|
||||
}
|
||||
case 'nip26.delegate': {
|
||||
let { delegateePubkey, conditionsJson } = params
|
||||
let parameters = { pubkey: delegateePubkey, ...conditionsJson }
|
||||
return nip26.createDelegation(sk, parameters)
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
return {error: {message: error.message, stack: error.stack}}
|
||||
|
||||
@@ -8,14 +8,16 @@ export const PERMISSIONS_REQUIRED = {
|
||||
getPublicKey: 1,
|
||||
getRelays: 5,
|
||||
signEvent: 10,
|
||||
'nip26.delegate': 10,
|
||||
'nip04.encrypt': 20,
|
||||
'nip04.decrypt': 20
|
||||
'nip04.decrypt': 20,
|
||||
}
|
||||
|
||||
const ORDERED_PERMISSIONS = [
|
||||
[1, ['getPublicKey']],
|
||||
[5, ['getRelays']],
|
||||
[10, ['signEvent']],
|
||||
[10, ['nip26.delegate']],
|
||||
[20, ['nip04.encrypt']],
|
||||
[20, ['nip04.decrypt']]
|
||||
]
|
||||
@@ -25,7 +27,8 @@ const PERMISSION_NAMES = {
|
||||
getRelays: 'read your list of preferred relays',
|
||||
signEvent: 'sign events using your private key',
|
||||
'nip04.encrypt': 'encrypt messages to peers',
|
||||
'nip04.decrypt': 'decrypt messages from peers'
|
||||
'nip04.decrypt': 'decrypt messages from peers',
|
||||
'nip26.delegate': 'create key delegation tokens',
|
||||
}
|
||||
|
||||
export function getAllowedCapabilities(permission) {
|
||||
|
||||
@@ -26,6 +26,12 @@ window.nostr = {
|
||||
}
|
||||
},
|
||||
|
||||
nip26: {
|
||||
async delegate(delegateePubkey, conditionsJson) {
|
||||
return window.nostr._call('nip26.delegate', {delegateePubkey, conditionsJson})
|
||||
}
|
||||
},
|
||||
|
||||
_call(type, params) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let id = Math.random().toString().slice(4)
|
||||
|
||||
Reference in New Issue
Block a user