verifactu-sdk API / HashStore
Interface: HashStore
Defined in: src/store/HashStore.ts:46
Pluggable hash-chain store.
Implementations must be read-modify-write safe: the SDK calls getLast immediately before computing the next hash and calls append immediately after the AEAT acknowledges the submission. If your store is shared across processes, wrap the pair in a transaction or a mutex so two concurrent submissions can never observe the same previous hash.
Example
class FileHashStore implements HashStore {
async getLast(nif: string) { return readJson(`./chains/${nif}.json`); }
async append(nif: string, entry: HashStoreEntry) { writeJson(`./chains/${nif}.json`, entry); }
}Methods
getLast()
getLast(
taxpayerNif):HashStoreEntry|Promise<HashStoreEntry|null> |null
Defined in: src/store/HashStore.ts:54
Return the last appended entry for the given taxpayer.
Parameters
taxpayerNif
string
NIF of the taxpayer whose chain is being read.
Returns
HashStoreEntry | Promise<HashStoreEntry | null> | null
The last entry, or null if the taxpayer has no previous record (i.e. the next submission must be marked PrimerRegistro='S').
append()
append(
taxpayerNif,entry):void|Promise<void>
Defined in: src/store/HashStore.ts:62
Persist a freshly computed hash as the new tail of the chain.
Parameters
taxpayerNif
string
NIF of the taxpayer the chain belongs to.
entry
The newly created record's identifier and hash.
Returns
void | Promise<void>