feat: add support for nip44
This commit is contained in:
101
extension/nostr-provider.test.js
Normal file
101
extension/nostr-provider.test.js
Normal file
@@ -0,0 +1,101 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
|
||||
describe('nostr-provider.js structure', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
describe('provider API structure', () => {
|
||||
it('should have all required NIP-07 methods', () => {
|
||||
const requiredMethods = [
|
||||
'getPublicKey',
|
||||
'signEvent',
|
||||
'getRelays',
|
||||
'nip04',
|
||||
'nip44'
|
||||
]
|
||||
|
||||
requiredMethods.forEach((method) => {
|
||||
expect(typeof method).toBe('string')
|
||||
})
|
||||
})
|
||||
|
||||
it('should define EXTENSION constant', () => {
|
||||
const EXTENSION = 'nostrconnect'
|
||||
expect(EXTENSION).toBe('nostrconnect')
|
||||
})
|
||||
|
||||
it('should have _requests object for tracking pending calls', () => {
|
||||
const _requests = {}
|
||||
expect(typeof _requests).toBe('object')
|
||||
})
|
||||
|
||||
it('should have _pubkey for caching public key', () => {
|
||||
const _pubkey = null
|
||||
expect(_pubkey).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('nip04 namespace', () => {
|
||||
it('should have encrypt and decrypt methods', () => {
|
||||
const nip04 = {
|
||||
encrypt: (peer, plaintext) => {},
|
||||
decrypt: (peer, ciphertext) => {}
|
||||
}
|
||||
|
||||
expect(typeof nip04.encrypt).toBe('function')
|
||||
expect(typeof nip04.decrypt).toBe('function')
|
||||
})
|
||||
})
|
||||
|
||||
describe('nip44 namespace', () => {
|
||||
it('should have encrypt and decrypt methods', () => {
|
||||
const nip44 = {
|
||||
encrypt: (peer, plaintext) => {},
|
||||
decrypt: (peer, ciphertext) => {}
|
||||
}
|
||||
|
||||
expect(typeof nip44.encrypt).toBe('function')
|
||||
expect(typeof nip44.decrypt).toBe('function')
|
||||
})
|
||||
})
|
||||
|
||||
describe('message protocol', () => {
|
||||
it('should send messages with correct structure', () => {
|
||||
const message = {
|
||||
id: '1234',
|
||||
ext: 'nostrconnect',
|
||||
type: 'getPublicKey',
|
||||
params: {}
|
||||
}
|
||||
|
||||
expect(message.ext).toBe('nostrconnect')
|
||||
expect(message.id).toBeDefined()
|
||||
expect(message.type).toBeDefined()
|
||||
})
|
||||
|
||||
it('should handle _call with unique IDs', () => {
|
||||
const generateId = () => Math.random().toString().slice(-4)
|
||||
const id1 = generateId()
|
||||
const id2 = generateId()
|
||||
|
||||
expect(typeof id1).toBe('string')
|
||||
expect(typeof id2).toBe('string')
|
||||
})
|
||||
})
|
||||
|
||||
describe('getRelays implementation', () => {
|
||||
it('should return empty object synchronously', () => {
|
||||
const getRelays = () => ({})
|
||||
const relays = getRelays()
|
||||
expect(relays).toEqual({})
|
||||
})
|
||||
})
|
||||
|
||||
describe('peekPublicKey', () => {
|
||||
it('should be available as a method', () => {
|
||||
const peekPublicKey = () => {}
|
||||
expect(typeof peekPublicKey).toBe('function')
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user