MCPcopy Index your code
hub / github.com/cameri/nostream / createAuthEvent

Function createAuthEvent

test/unit/handlers/auth-message-handler.spec.ts:29–72  ·  view source on GitHub ↗
(overrides: {
    kind?: number
    challenge?: string
    relayUrl?: string
    created_at?: number
    invalidId?: boolean
    invalidSig?: boolean
  } = {})

Source from the content-addressed store, hash-verified

27 const pubkey = getPublicKey(privkey)
28
29 async function createAuthEvent(overrides: {
30 kind?: number
31 challenge?: string
32 relayUrl?: string
33 created_at?: number
34 invalidId?: boolean
35 invalidSig?: boolean
36 } = {}): Promise<AuthMessage> {
37 const kind = overrides.kind ?? EventKinds.AUTH
38 const now = overrides.created_at ?? Math.floor(Date.now() / 1000)
39 const tags = [
40 [EventTags.AuthRelay, overrides.relayUrl ?? relayUrl],
41 [EventTags.Challenge, overrides.challenge ?? challenge],
42 ] as Tag[]
43
44 const identified = await identifyEvent({
45 pubkey,
46 created_at: now,
47 kind,
48 tags,
49 content: '',
50 })
51
52 if (overrides.invalidId) {
53 identified.id = 'f'.repeat(64)
54 }
55
56 const signed = overrides.invalidSig
57 ? { ...identified, sig: '0'.repeat(128) }
58 : await signEvent(privkey)(identified)
59
60 return [
61 MessageType.AUTH,
62 {
63 id: signed.id,
64 pubkey,
65 created_at: now,
66 kind,
67 tags,
68 content: '',
69 sig: signed.sig,
70 },
71 ] as AuthMessage
72 }
73
74 beforeEach(() => {
75 emitStub = Sinon.stub()

Callers 1

Calls 2

identifyEventFunction · 0.90
signEventFunction · 0.90

Tested by

no test coverage detected