35 lines
858 B
TypeScript
35 lines
858 B
TypeScript
import { Event } from 'nostr-tools'
|
|
import { Meta } from '../types'
|
|
|
|
/**
|
|
* This function returns the signature of last signer
|
|
* It will be used in the content of export signature's signedEvent
|
|
*/
|
|
const getLastSignersSig = (
|
|
meta: Meta,
|
|
signers: `npub1${string}`[]
|
|
): string | null => {
|
|
// if there're no signers then use creator's signature
|
|
if (signers.length === 0) {
|
|
try {
|
|
const createSignatureEvent: Event = JSON.parse(meta.createSignature)
|
|
return createSignatureEvent.sig
|
|
} catch (error) {
|
|
return null
|
|
}
|
|
}
|
|
|
|
// get last signer
|
|
const lastSigner = signers[signers.length - 1]
|
|
|
|
// get the signature of last signer
|
|
try {
|
|
const lastSignatureEvent: Event = JSON.parse(meta.docSignatures[lastSigner])
|
|
return lastSignatureEvent.sig
|
|
} catch (error) {
|
|
return null
|
|
}
|
|
}
|
|
|
|
export { getLastSignersSig }
|