
Security News
Scaling Socket from Zero to 10,000+ Organizations
Socket CEO Feross Aboukhadijeh shares lessons from scaling a developer security startup to 10,000+ organizations in this founder interview.
@iota/persistence
Advanced tools
Persistence module allows to persist a state of last key index, bundles and CDAs*.
Access to a database is done with adapters that implement the PersistenceAdapter interface. An implementation of it is @iota/persistence-adapter-level which uses an :abstract-level store (leveldown, leveljs, memdown or others...).
* CDAs = Conditional Deposit Adresses
import { persistence, persistenceID } from '@iota/persistence'
import { createPersistenceAdapter } from '@iota/persistence-adapter-level'
import leveldown from 'leveldown'
;(async function (seed) {
const adapter = persistenceAdapter({
persistenceID: persistenceID(seed),
persistencePath: './test/temp', // test directory
store: leveldown // default store
})
try {
const {
nextIndex,
writeBundle,
deleteBundle,
writeCDA,
deleteCDA,
batch,
state.read,
createStateReadStream,
history.read,
history.delete,
createHistoryReadStream,
} = await persistence(adapter)
return nextIndex()
} catch (error) {
// deal with errors here...
return error
}
})('SOME9SEED') // Shoud output 1
export interface PersistenceAdapter<K = Buffer, V = Buffer> {
readonly read: (key: K) => Promise<V>
readonly write: (key: K, value: V) => Promise<void>
readonly delete: (key: K) => Promise<void>
readonly batch: (ops: ReadonlyArray<PersistenceAdapterBatch<K, V>>) => Promise<void>
readonly createReadStream: (options?: PersistenceIteratorOptions) => NodeJS.ReadableStream
}
createReadStream() reads & streams persisted bundles & CDAs as key-value pairs.
import { CDA_LENGTH, deserializeCDA } from '@iota/cda'
import { isMultipleOfTransactionLength } from '@iota/transaction'
createReadStream
.on('data', value => {
if (value.length === CDA_LENGTH) {
// It's a CDA
const {
address,
timeoutAt,
expectedBalance,
checksum,
index,
security,
} = deserializeCDA(value)
} else if (isMultipleOfTransactionLength(value)) {
// It's a bundle
const bundle = transaction.bundle(value)
}
})
.on('error', error => {
// handle errors here
})
.on('close', () => {})
.on('end', () => {})
Persistence module emits events after every sucessful modification of the state.
persistence.on('writeBundle', bundle => {})
persistence.on('deleteBundle', bundle => {})
persistence.on('writeCDA', cda => {})
persistence.on('deleteCDA', cda => {})
FAQs
iota.js persistence inteface
We found that @iota/persistence demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh shares lessons from scaling a developer security startup to 10,000+ organizations in this founder interview.

Research
Socket Threat Research maps a rare inside look at OtterCookie’s npm-Vercel-GitHub chain, adding 197 malicious packages and evidence of North Korean operators.

Research
Socket researchers identified a malicious Chrome extension that manipulates Raydium swaps to inject an undisclosed SOL transfer, quietly routing fees to an attacker wallet.