Skip to content

Commit

Permalink
Merge pull request #9 from orochi-network/feature/ipfs_storage_engine
Browse files Browse the repository at this point in the history
Feature/ipfs storage engine
  • Loading branch information
chiro-hiro authored May 29, 2023
2 parents 117693a + c20eb17 commit 9e53bc0
Show file tree
Hide file tree
Showing 13 changed files with 846 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,5 @@ dist
.tern-port
.DS_Store
build/

data/
package-lock.json
9 changes: 9 additions & 0 deletions zkdb/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,14 @@ module.exports = {
plugins: ['@typescript-eslint', 'snarkyjs'],
rules: {
'no-constant-condition': 'off',
'no-unused-vars': [
'error',
{
vars: 'all',
args: 'after-used',
ignoreRestSiblings: false,
argsIgnorePattern: '^_',
},
],
},
};
1 change: 1 addition & 0 deletions zkdb/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ coverage

# Never commit keys to Git!
keys
docs/
22 changes: 18 additions & 4 deletions zkdb/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "zkdatabase",
"version": "0.0.1",
"description": "zkDatabase for the future of blockchain",
"description": "zkDatabase for the future of Web3",
"author": "chiro@orochi.network",
"license": "Apache-2.0",
"keywords": [
"zk",
"database",
"zk-database",
"zkdb",
"zkdatabase"
],
Expand Down Expand Up @@ -47,20 +48,33 @@
"eslint": "^8.7.0",
"eslint-plugin-snarkyjs": "^0.1.0",
"husky": "^7.0.1",
"ipfs-core-types": "^0.14.0",
"jest": "^27.3.1",
"lint-staged": "^11.0.1",
"prettier": "^2.3.2",
"ts-jest": "^27.0.7",
"tsconfig-paths": "^4.1.2",
"typedoc": "^0.24.7",
"typescript": "^4.7.2"
},
"peerDependencies": {
"snarkyjs": "^0.8.0"
},
"dependencies": {
"ipfs-core": "^0.18.0",
"multiformats": "^11.0.1",
"@chainsafe/libp2p-noise": "^11.0.4",
"@chainsafe/libp2p-yamux": "^4.0.1",
"@helia/interface": "^1.0.0",
"@helia/ipns": "^1.1.1",
"@helia/unixfs": "^1.2.2",
"@libp2p/kad-dht": "^9.2.0",
"@libp2p/tcp": "^7.0.1",
"@libp2p/websockets": "^6.0.1",
"@multiformats/multiaddr": "^12.1.2",
"blockstore-fs": "^1.1.1",
"bson": "^5.3.0",
"datastore-fs": "^9.1.1",
"helia": "^1.0.4",
"libp2p": "^0.44.0",
"multiformats": "^11.0.2",
"safer-buffer": "^2.1.2",
"snarkyjs": "^0.8.0"
}
Expand Down
2 changes: 1 addition & 1 deletion zkdb/src/Add.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Add } from './Add';
import { Add } from './Add.js';
import {
isReady,
shutdown,
Expand Down
76 changes: 76 additions & 0 deletions zkdb/src/storage-engine/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { CID } from 'multiformats';
import { PeerId } from '@libp2p/interface-peer-id';
import { IPNSEntry } from 'ipns';

/**
* Common interface for file system
* @param S - Content ID could be filename or content ID depends on implementation
* @param T - Content unique ID, it could be uuid or CID depends on implementation
* @param R - Data type, it could be string or Uint8Array depends on implementation
*/
export interface IFileSystem<S, T, R> {
/**
* Write data type R to file system and return content ID
* @param _data Data in bytes
*/
writeBytes(_data: R): Promise<T>;

/**
* Write data type R to file system with a given filename and return content ID
* @param _filename Filename
* @param _data Data in bytes
*/
write(_filename: S, _data: R): Promise<T>;

/**
* Read data type R from file system with a given content ID/filename
* @param _contentID Content ID
* @returns Data in R
*/
read(_filename: S): Promise<R>;

/**
* Remove file from file system with a given content ID/filename
* @param _contentID Content ID or filename
* @returns true if success otherwise false
*/
remove(_filename: S): Promise<boolean>;
}

/**
* Method that performing index and lookup file
* @param S - Peer ID
* @param T - Content ID
* @param R - IPNS entry
*/
export interface IFileIndex<S, T, R> {
/**
* Publish file to IPNS
* @param _contentID Content ID
* @returns An entry from IPNS
*/
publish(_contentID: T): Promise<R>;

/**
* Republish file to IPNS
* @returns An entry from IPNS
*/
republish(): void;

/**
* Resolve file CID from IPNS
* @param _peerID Peer ID of p2p node
* @returns Content ID
*/
resolve(_peerID?: S): Promise<T>;
}

/**
* IPFS file system
*/
export type TIPFSFileSystem = IFileSystem<string, CID, Uint8Array>;

/**
* IPFS file index
*/
export type TIPFSFileIndex = IFileIndex<PeerId, CID, IPNSEntry>;
6 changes: 6 additions & 0 deletions zkdb/src/storage-engine/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @module storage-engine
* @description Storage engine module.
*/
export * from './common.js';
export * from './ipfs.js';
Loading

0 comments on commit 9e53bc0

Please sign in to comment.