ErasureJS module comprises of:
- ErasureClient for creating and getting Users,Feeds,Posts,Agreements,Escrows
- Core Erasure modules : ErasureFeed,ErasurePost,ErasureAgreements,ErasureEscrows
- ErasureGraph : for querying Erasure Protocol graph and listening to events
- Use ethers.js for wallet and provider
const {ErasureClient,ErasureGraph,ErasureFeed,ErasurePost,ErasureAgreement,ErasureEscrow,ErasureUtils} = require("erasure-js)
wallet
: Implemented using ethers.js wallet module, which can be converted from JSON key file, private ket, mnemonic, or web3 wallet.- To learn more check out Ethers Docs
provider
: Implemented using ethers.js module, which can be converted from web3Provideripfs
: Default = infura node, format :{host:"",port:"",protocol:"https"}
network
(optional) : only used in development envgraph
: default to ErasureGraph of provider's network, can passed in custom local graph for development
const {VERSION_V1,VERSION_V2,MAINNET,RINKEBY} = ErasureUtils
const client = new ErasureClient({version=VERSION_V2})
const graph = new ErasureGraph({version=VERSION_V1,network=MAINNET})
- If no version and network is specified, defaults are : RINKEBY, VERSION_V2
- Future development will be added if requested
- Erasure Client
- Erasure User
- Erasure Template
- Erasure Feed
- Erasure Agreement
- Erasure Escrow
- Erasure Graph Client
- In development
const client = new ErasureClient({wallet=null, provider=null, ipfs=null:{host:string,post:string,protocol:string},graph=null:string})
- Note :
- If no wallet is specified, a new ethers wallet will be created (when you just want to read data)
- If no provider is specified, mainnet provider from infura will be provided
await client.createUser() -> ErasureUser
await client.createFeed() -> ErasureFeed
await client.getFeed(address) -> ErasureFeed
await client.getPost({proofHash,feedAddress}) -> ErasurePost
await client.createAgreement() -> ErasureAgreement
await client.getAgreement(address) ->ErasureAgreement
await client.createEscrow() -> ErasureEscrow
await client.getEscrow(address) -> ErasureEscrow
await client.getAllUsers()
await client.getUsersCount()
await client.getPaginatedUsers(start,end)
await client.getUserData(address)
await client.getAllFeeds()
await client.getFeedsCount()
await client.getPaginatedFeeds(start,end)
await client.getAllAgreements()
await client.getAgreementsCount()
await client.getPaginatedAgreements(start,end)
await client.getAllEscrows()
await client.getEscrowsCount()
await client.getPaginatedEscrows(start,end)
const erasureUser = new ErasureUser({wallet,provider,ipfs,graph})
const [keypair,confirmedTx] = await erasureUser.createAndRegisterUser({msg,salt=null})
+ How it works:
1. Create new asym keypair
2. Upload pubkey to Erasure_User registry
3. @return keypair
await erasureUser.removeUser()
await client.getUserData(address)
await owner()
await setMetadata(data)
await denounceOperator()
await transferOperator(address)
await operator()
address
- instance's addresscontract
- Contract object
- (extends Template)
const feed = new ErasureFeed({address,wallet,provider,ipfs,graph})
await feed.createPost(rawData)
+ How It works:
1. Create symkey
2. Encrypt rawData with symkey
3. Create metadata object:
{
address: this.wallet.address,
rawDataIpfsHash
symkeyIpfsHash
encryptedIpfsHash
}
4. Upload metadata's multihash digest form to feeds as proofhash
5. Upload metadata and encryptedData to IPFS
await feed.reveal()
: Reveal all postsawait feed.getAllEscrows()
: Get all Escrowsawait feed.offerBuy()
: Create escrow for this feed as buyerawait feed.offerSell()
: Create escrow for this feed as sellerawait feed.offerAsOperator()
: create esrow for this feed as operator- Template Methods
- Get status of feed (if revealed) :
await feed.status()
- Template Methods
const post = new ErasurePost({feedAddress,proofHash})
const success:bool = await post.reveal({symKey})
+ How it works:
1. Get the latest post(== proofHash == ipfs path of metadata) of feed from graph
2. Get metadata from ipfs path
3. Validate symkey and rawData
4. Upload symkey and rawData to IPFS
await post.offerSell()
: Create escrow as sellerawait post.offerBuy()
: Create escrow as buyerawait post.offerAsOperator()
: Create escrow as operator
await post.status()
: Get status if revealedawait post.owner()
await post.proofHash()
await post.getEscrows()
: Get all Escrows that transact this post
const escrow = new ErasureEscrow({address,wallet,provider,ipfs,graph})
await escrow.depositPayment(amount)
await escrow.cancel()
await escrow.timeout()
await escrow.retrieveDataFromSeller()
- How it works:
- Get dataSubmitted of this escrow from the graph
- Decrypt data submitted -> symkey
- Get Metadata( multihash digest form of metadata) from the escrow
- Get metadata from IPfS
- Get encrypted data from metadata.encryptedDataHash
- Decrypt data with symKey
- How it works:
await escrow.depositStake(amount)
await escrow.finalize()
await escrow.cancel()
await escrow.deliverKey({symKey)
- How it works:
- Get Buyer's pubkey from escrow
- Encrypt symKey with Buyer's pubkey
- Submit the new encrypted symKey to escrow contract
- How it works:
await escrow.getAgreement()
: Get ErasureAgreement obj of this escrowawait escrow.buyer()
await escrow.owner()
await escrow.seller()
await escrow.status()
await escrow.data()
const agreement = new ErasureAgreement({address,wallet,provider,ipfs,graph})
await agreement.reward(amount)
await agreement.punish(amount)
await agreement.releaseStake()
await agreement.timeout()
await agreement.cancel()
await agreement.retrieveStake()
(countdown)
await agreement.staker()
await agreement.counterparty()
await agreement.owner()
await agreement.status()
await escrow.data()
const {ErasureGraph} = require("erasureJs")
const erasureGraph = new ErasureGraph({network:ErasureUtils.RINKEBY,version:ErasureUtils.VERSION_V2})
- Network :
mainnet
orrinkery
for accessing Erasure graph public nodeganache
for local node (require having a graph node locally and run deploy graph)
- Queries available
- If no
events
array is passed in, client will listen to all events
erasureGraph.startListening(events=null,cb)
erasrureGraph.query(queryName=null,eventName,opts:Obj,returnData:String)
COMING SOON : Details of all queries available
yarn
yarn ganache
yarn test