A simple, lightweight library to "permapin" IPFS files into Arweave blockchain.
This library is written closely to the official ipfs js library and provides easy integration with existing ipfs apps to permapin their data in arweave.
IPFS+Arweave Hackathon
This project is part of IPFS+Arweave Hackathon:-
This project contains three repos:
arweave-ipfs - Cross-Compatible (js client & node server) library to easily integrate IPFS+Arweave in your apps.
importArweaveIpfsfrom'arweave-ipfs';constar=newArweaveIpfs();// Or specify your own optionsconstar=newArweaveIpfs({//ipfs optshost: 'ipfs.infura.io',port: 5001,protocol: 'https'},{//arweave optshost: 'arweave.net',port: 443,protocol: 'https'});
Example
This example shows integration with existing ipfs apps.
The snippet is taken from ipfs/interface-js-ipfs-core
constfiles=[{path: '/tmp/myfile.txt',content: Ipfs.Buffer.from('ABC')}]constresults=awaitipfs.add(files)// just add this single line to permapin to arweaveconstarweave_result=awaitar.add(results);
Usage
add
add takes ipfs hashes, stores the raw bytes of files and returns the respective arweave txid. It also does additional checks to ensure same data is not stored multiple times.
Note: jwk is the json of arweave wallet keyfile see arweave docs for more info
const result = await ar.add(["Qmy...", "Qmx.."], jwk);
get
get takes ipfs hashes or valid IPFS-Add arweave tx ids and returns data as raw bytes.
It first looks for data in arweave blockchain if not found it fetches it from ipfs node.
If the ipfs data is not found in arweave blockchain it automagically permapins the data in arweave blockchain provided the jwk is given.
constresults=awaitar.get("Qmx...");// orconstresults=awaitar.get(["Qmx...","Qmy..."]);// it also accepts arweave tx idsconstresults=awaitar.get(["1U5...","Qmx..."]);
get also accepts a second parameter jwk which is an arweave key. when jwk is supplied any ipfs hash not found in arweave is stored in the blockchain.
// you get the data and the hash is stored in arweave next time someone tries to fetch itconstresult=awaitar.get("Qm...notinarweavehash",jwk)
For more details see documentation or generate locally using typedoc --out docs src in project root.
Arweave-IPFS Server
If you want to provide a centralized service where users would be able to upload ipfs hashes into permaweb without requiring arweave keyfile then take a look at arweave-ipfs-server
请发表评论