/ x / datastructure@1.2.1 / blockChain

BlockChain Api

sha256 has been used for creating Hashes.

// Each block type
type BlockType = {
    index: number
    data: DataType<any>
    time: Date
    hash: string
    prevHash: null|string

// data type
DataType<T> = {
    key: string
    value: T

// static method that creates a instance of `BlockChain` class.

// Time Complexity: O(1)
length: number;

// *generator function, it returens an iterator.
// loop through all blocks in the chain
iterator(): Generator

// Time Complexity: O(n)
// check for "the blockChain is corrupted/manipulated or valid". 
checkValidation(): boolean

// Time Complexity: O(1)
createBlock(data: DataType<any>): boolean

// Time Complexity: O(1)
latestBlock(): boolean|BlockType

// Time Complexity:
//  log all: O(n)
//  log by key: O(n)
//  log by index: O(1)
log(key: null|string = null, index: null|number = null): void;

// Time Complexity: 
//  search by key: O(n)
//  search by index: O(1)
search(key: null|string, index: null|number = null): boolean|BlockType


import { BlockChain } from "";

const blockChain = BlockChain.createBlockChain()

// iterator method returns a *generator function
const iterator = blockChain.iterator()
let iteratorNext =
// console.log(,;
while (iteratorNext.done === false) {
    iteratorNext =

// length or count of total blocks.

// create a new block in the blockChain.
blockChain.createBlock({key: 'sourav', value: {name: "Sourav"}})
blockChain.createBlock({key: 'abm', value: "AbmSourav"})
blockChain.createBlock({key: 'JS', value: ['JS', 'TS']})

// get latest created block

// console all values
// console the block that has key: 'abm'
// console then block which is index: 3
blockChain.log(null, 3)

// searching block by key'JS')
// searching block by index, 2)
Implement different Data Structures using TypeScript. Deno Third-party Module.
GitHub RepositoryAbmSourav/dataStructure
GitHub Stars

Version Info

Tagged at
10 months ago