GithubHelp home page GithubHelp logo

paratii-video / paratii-js Goto Github PK

View Code? Open in Web Editor NEW
35.0 35.0 10.0 21.58 MB

JS library for clients to interact with deployed contracts, with wallet functionality, access to blockchain data and convenience functions.

License: GNU General Public License v3.0

JavaScript 100.00%

paratii-js's People

Contributors

aeftimia avatar bent0b0x avatar devzl avatar eliawk avatar enricocicconi avatar felipegaucho avatar geckoslair avatar jellegerbrandy avatar lorenzo-dev1 avatar milankragujevic avatar mrocha94 avatar ya7ya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

paratii-js's Issues

Implement events POC

This does not work on testrpc, so we will need to have the lib work with parity first. This is tracked in issue #26

implement authentication tools

What we'd like is some way to do simple "authentication" in the following way:

Client likes to authanticate with a webservice (or prove his identity)

  1. webservice sends a challenge (a nonce)
  2. client signs the nonce
  3. webservice derives the public key (i.e. address) from the signed message

In particular, we'd like:

  1. Webservice calls paratii.utils.newChallenge() (can be just a random string on first iteration). (The logistiscs of sending the challenge over http or whatever is in scope of the paratii-db project and not in paratiilib)
  2. Client calls paratii.utils.signMessage(messageToSign) which returns a utf encoded string that can be sent to the server. This function will just be based on hashMessage or sign functions of web3 (not sure which one is the appropriate one to use here): http://web3js.readthedocs.io/en/1.0/web3-eth-accounts.html#hashmessage.
  3. Webservice recieves the message and checks it ussing paratii.utils.recoverAccount(msg), whch returns the ethereum address used to sign the message (based on http://web3js.readthedocs.io/en/1.0/web3-eth-accounts.html#recover)`ut

I'm not sure about the utils name space (which is not there yet)

The tasks are:

  • document these 3 functions
  • test them
  • implement these 3 functions

Implement playlists logic

This needs to be defined, still. Here is a first idea:

 `paratii.core.playlists.get(playlistId)`
 `paratii.core.playlists.create(...)`
 `paratii.core.playlists.update(playlistId, {fiedls:to, update:foo})`
 `paratii.core.playlists.search(qry)`

Gettings videos of a playlist:

 `paratii.core.vids.search({ playlist: playlistId })`

Get playlist of a video:

  `paratii.core.playlists.search( { video: videoId })`

Clean up deployment/installation process

Problem

  • Currently, this library is not easy to install and use. It requires installing the dev branch of this repo, npm link-ing, and then manually running npm run pack to bundle the lib.

  • another issue is that when another module includes paratii-lib in its bundle via webpack, it includes paratii.ipfs.uploader.js (which should only run on node). This leads to an error that the 'fs' module cannot be resolved. paratii-lib tries to handle this with this line, but it does not seem to work w/ webpack.

Proposed Solution(s) (once dev is merged into master)
Either automatically bundle the lib on postInstall, or publish the lib to npm and handle bundling automatically via a prePublish hook

cc @ya7ya

create paratii.core.vids.like(videoId) and disLike

Implement the following functions:

paratii.core.vids.like(videoId)
paratii.eth.vids.like(videoId)
paratii.core.vids.dislike(videoId)
paratii.eth.vids.dislike(videoId)

Registers the 'like' in the blockcahin (i.e. calls paratii.eth.vids.like(videoId), which calls the likes.likeVideo(..) contract. (See paratii-contracts for detaisl on thsi contract)

create paratii.core.update() function

 paratii.core.vids.update(videoId, {foo: bar })

Set the value fo foo of the video given to videoId to bar (and leave all other values untouched). Returns an object representing the new data. Cf. paratii.eth.vids.update for the general idea.

create a "Header" component

i.e. something reactive instead of what is no in Play.js:

    <Header>
      <Logo src={logo} alt='logo' />
    </Header>

utilities for authentication

We have two different but similar use cases:

  1. Do user authentication (in meteor) by proving you have the private key for an account

Given that each user corresponds to an ethereum account, the idea is that a client can authenticate not by sending the password, but sending a signed message that proves she controls an ethereum account.

  1. Check the identity of accounts in API calls.

For example, the idea is that http://paratii.video/rip?url=http://youtu.be/videoId&account=0x123455&signature=0x1234.. is only a valid call if the signature is a signed message that includes (a hash) of the other provided arguments - there garanteeing that an attacker cannot tamper with the parameters). But perhaps this pattern can be simplified (e.g. if we include the parameters in the signed message, we do not need to send them over separately)

This functinoality will be based on the web3.eth.accounts.sign and .recover functionality.

The exact API we want may change depending on what we learn during implementation, but could look like this:

// initialize a Paratii object
// // we need to implement wallet handling and locking and things, but for the purposes of this issue
// we just pass the private key directly
paratii = new Paratii({privateKey: 0x124555}) 

// signs the message with the given key (for use by the client)
// returns a string that we can include in http requests
paratii.utils.signMessage(msg)

// extract the account from a messag signed with the call above
// returns an ethereum account
// this function just wrap web3.eth.accounts.recover
paratii.utils.recoverAccount(msg)

// check if a request in the style of case (2) above is valid
paratii.utils.isValidRequest({arg1: 'x', arg2: 'y', signature: '0x143545..'})

evaluate using an alternative to `default-options`

We now use the default-options npm package to do some argument checking for all functions.

this has been a hasty choice - (not necessarily bad, but made without much thought).

So we should see if there is abetter alternative, probably here in the comments is a good place.

What we are looking for is:

  • quick specs for type checking, default values, options vs obligatory args
  • clear but customizable error handling

Clear up mechanism for CRUD operations on videos

Problem
Currently, the only (I think) way to use paratii-lib to get data about a video (given the video ID) is to use ParatiiEth. To instantiate ParatiiEth, you need an ethereum address (along w/ some other config). However, I think you should be able to retrieve info about a video w/o having any particular user's eth address.

@jellegerbrandy does this make sense? If yes, we can figure out how to expose this api (and potentially others that should not require an address). If not, please inform me of the appropriate way to fetch this data/use the lib ๐Ÿ˜„

cc @ya7ya

Error: Private key suspiciously small: < 16 bytes. Aborting!

yarn test doesn't pass, shows this: Error: Private key suspiciously small: < 16 bytes. Aborting!. Full output:

Milans-MacBook-Air:paratii-lib milankragujevic$ yarn test
yarn run v1.3.2
$ mocha --require babel.js --exit --timeout 10000 test/*.js


  Paratii API:
    โœ“ deployContracts should deploy and register all contracts (497ms)

  Paratii API:
    โœ“ diagnose() should run without errors (318ms)

  Paratii API:
4
    โœ“ example session from ../docs/example-session.md should work (235ms)

  Paratii configuration:
    โœ“ paratii.config should return the configuration with default values
    โœ“ testnet configuration should be recognized
    โœ“ should be possible to create a second Paratii object with the same settings (244ms)
    โœ“ should be possible to create a Paratii instance without an address or registryAddress
    โœ“ setAccount should set the account
    โœ“ paratii.eth.web3 should be available

  paratii.core API: :
    โœ“ should be configured
    - core.users.create() should work as expected
    - core.users.get() should work as expected

  paratii.core.vids:
bitswap options:  { maxMessageSize: 32768 }
    โœ“ core.vids.create() and get() should work as expected (5024ms)
bitswap options:  { maxMessageSize: 32768 }
    โœ“ core.vids.create() should accept ipfsHash as argument (5435ms)
bitswap options:  { maxMessageSize: 32768 }
    โœ“ core.vids.update() should work as expected (1567ms)
    - core.vids.delete() should work as expected
    - core.vids.like() should work as expected
    - core.vids.dislike() should work as expected
    - core.vids.view() should work as expected
    - core.vids.buy() should work as expected
    - core.vids.search() should work as expected

  paratii.db API: :
    โœ“ should be configured
    - db.vids.get() should work as expected
    - db.users.get() should work as expected
    - db.vids.search() should work as expected
    โœ“ should be available as an attribute on Paratii instances

  paratii.eth.events API: :
    โœ“ subscription to Tranfer PTI events should work as expected (70ms)
    โœ“ subscription to Create Video events should work as expected (45ms)

  paratii.eth API: :
    โœ“ getContracts() should return the contracts
    โœ“ contracts should have their address set (70ms)
    โœ“ getContract() should return the correct contract
    1) balanceOf() should return the right balances
    โœ“ transfer ETH should work as expected
    โœ“ transfer PTI should work as expected
    โœ“ deployContract should throw a sensible error if address is not set

  paratii.eth.users: :
    โœ“ users.create(),  .get(), .update() and .delete() should work (83ms)
    - missing or wrong arguments in users.create() should trhow meaningful errors

  paratii.eth.vids:
    โœ“ vids.create(),  .get(), .update() and .delete() should work (83ms)
    - vids.create() should throw meaningful errors
    - vids.create() should create a fresh id if no id wat provided

  paratii.eth.wallet: :
    โœ“ init account is added to wallet
    โœ“ if no account is given, the wallet accounts are empty
    โœ“ wallet.create() works (165ms)
    โœ“ wallet.create() does not create a new wallet object (156ms)
    โœ“ wallet.create() creates a new mnenomic if not mnomic is given (49ms)
    โœ“ wallet.encrypt() and decrypt() works (546ms)
    โœ“ send() should fail if no wallet is present
    โœ“ send() should succeed if a  private key is passed to the constructor (43ms)
    โœ“ send() should succeed if a  private key is passed to the constructor (44ms)
    โœ“ eth.wallet.isValidMnemonic() should work as expected
    โœ“ eth.wallet.newMnemonic() should work as expected
    โœ“ eth.wallet.create() should throw if a wallet already has an account
    โœ“ eth.wallet.getMnemonic() should work as expected (71ms)

  ParatiiIPFS: :
    โœ“ should exist
bitswap options:  { maxMessageSize: 32768 }
    โœ“ should create an instance without trouble (2914ms)
bitswap options:  { maxMessageSize: 32768 }
    โœ“ should allow for simple add() and get() of files (778ms)
bitswap options:  { maxMessageSize: 32768 }
    โœ“ put a JSON object and get it back (3370ms)
bitswap options:  { maxMessageSize: 32768 }
    โœ“ should exist and work as an attribute on the Paratii object (870ms)

  ParatiiIPFS: :
{ onDone: [Function: onDone], onError: [Function: onError] }
bitswap options:  { maxMessageSize: 32768 }
Adding  test/data/some-file.txt
Adding QmS8yinWCD1vm7WJx34tg81FpjEXbdYXf3Y5XcCeh29C6K finished
uploader Finished [ undefined ]
    โœ“ should allow for file upload (3444ms)
bitswap options:  { maxMessageSize: 32768 }
reading file  genericJson.json
reading file  some-file.txt
this is the hash to return 
    โœ“ should add a directory to IPFS (3270ms)
bitswap options:  { maxMessageSize: 32768 }
uploader Finished []
_signalTranscoder Got an empty Array. files:  []
    โœ“ addAndTranscode() should work as expected (6580ms)
    - should be able to grab a youtube video and upload it
    - should be able to grab a vimeo video and upload it

  Paratii API:
    โœ“ paratii exists..


  47 passing (41s)
  16 pending
  1 failing

  1) paratii.eth API: :
       balanceOf() should return the right balances:
     Error: Private key suspiciously small: < 16 bytes. Aborting!
      at Wallet.create$ (lib/paratii.eth.wallet.js:36:17)
      at tryCatch (node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:62:40)
      at Generator.invoke [as _invoke] (node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:296:22)
      at Generator.prototype.(anonymous function) [as next] (node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:114:21)
      at tryCatch (node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:62:40)
      at invoke (node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:152:20)
      at node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:195:11
      at new Promise (<anonymous>)
      at callInvokeWithMethodAndArg (node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:194:16)
      at AsyncIterator.enqueue (node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:217:13)
      at AsyncIterator.prototype.(anonymous function) [as next] (node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:114:21)
      at Object.runtime.async (node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:241:14)
      at Wallet.create (lib/paratii.eth.wallet.js:7:3)
      at Context._callee5$ (test/paratii.eth.js:76:45)
      at tryCatch (node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:62:40)
      at Generator.invoke [as _invoke] (node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:296:22)
      at Generator.prototype.(anonymous function) [as next] (node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:114:21)
      at tryCatch (node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:62:40)
      at invoke (node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:152:20)
      at node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:195:11
      at new Promise (<anonymous>)
      at callInvokeWithMethodAndArg (node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:194:16)
      at AsyncIterator.enqueue (node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:217:13)
      at AsyncIterator.prototype.(anonymous function) [as next] (node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:114:21)
      at Object.runtime.async (node_modules/babel-runtime/node_modules/regenerator-runtime/runtime.js:241:14)
      at Context._callee5 (test/paratii.eth.js:72:54)
      at <anonymous>



error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Milans-MacBook-Air:paratii-lib milankragujevic$ 

On macOS 10.13 with 8GB of RAM.

Cannot install this package

So far I am the only confirmed affected user, but:

A fresh npm i in paratii-portal and a fresh yarn within this package fail because of an error within youtube-dl.

From within this lib:

/Users/benjaminbaum/Desktop/Development/paratii-lib/node_modules/youtube-dl/lib/downloader.js:20
        if (res.statusCode !== 302) {
                ^

TypeError: Cannot read property 'statusCode' of undefined
    at Request._callback (/Users/benjaminbaum/Desktop/Development/paratii-lib/node_modules/youtube-dl/lib/downloader.js:20:17)

From paratii-portal:

41153 error code ELIFECYCLE
41154 error errno 1
41155 error [email protected] postinstall: `node ./scripts/download.js`
41155 error Exit status 1
41156 error Failed at the [email protected] postinstall script.
41156 error This is probably not a problem with npm. There is likely additional logging output above.

cc @jellegerbrandy @ya7ya

videoStore.buyVideo should work

Buying a video is a complex operation. At the moment, this is handled by code it he paratii-player repostory, which should be migrated here.

Implement vids.search

The exact API is still te be decided, the first iteration should at least implement:

 paratii.core.vids.search({keyword: some-keyword})

Which will just be a call to:

paratii.db.vids.search(...)

The logic can be taken from the code in paratii-player.

Note that this issue depends on having a functioning database index. This will be developed here: https://github.com/Paratii-Video/paratii-db

Get the example session to work

There is an example that runs through some standard operations on the Paratii library.

The main point of that document is to define the way we interact with the library. (which means that we can change the specs if we discover, working with the lib, that the API is not well-defined)

the example is here:

https://github.com/Paratii-Video/paratii-lib/blob/master/docs/example-session.md

With a correspnoding test that runs each fo these steps:

https://github.com/Paratii-Video/paratii-lib/blob/master/test/example-session.js

This issue tracks progress on implementing that session:

  • Paratii constructor should work
  • deployContracts should work
  • getContract shoudl return a contract
  • contracts.UserRegistry.registerUser(..) and similar evocations should work #2
  • buyVideo(...) should work #3

`contracts.UserRegistry.registerUser(..)` and similar evocations should work

At the moment, contracts.UserRegistry` is the interface constructed from the ABI - so it has no error handling, each function call at most a single transaction, etc.

The idea is that userRegistry.registerUser first does some typechecking fo arguments, and then calls the ABI method on userRegistry.methods.registerUser(...).send() )

Concretely, the approach is that for each contract that is accessible from the Paratii object, there will be a js class that will extend the class created by web3.eth.Contract(ABISPECS).

For a first iteration we can do the minimum required for #1, and just map userRegistry.registerUser(...args) to userRegistry.method.registerUser(...args).send() directly

Cannot install this lib with yarn

$ yarn add github:Paratii-Video/paratii-lib#master

error [email protected]: The engine "node" is incompatible with this module. Expected version ">=8.9.0".
error Found incompatible module

You can work around this with yarn --ignore-engines, but I'm not sure that this is a great workaround.

create, test, and document CRUD for user management

This is the paratii.cure.users; it can be written using the exact same pattern as paratii.core.vids

All the contracts should already be in place, so this is not hard to implement.

See docs/paratii-core.md for a (very short) sketch of the API

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.