SmartTokenLabs / TokenScript

TokenScript schema, specs and paper
http://tokenscript.org
MIT License
242 stars 71 forks source link

Web examples #416

Open nicktaras opened 3 years ago

nicktaras commented 3 years ago

Hi @oleggrib

This is my latest update towards merging our work together.

I've added what I understand to the be the steps we should apply to create the hotel demo. Let's review and go from there.

oleggrib commented 3 years ago

Hi, Nick.

Let me describe updated logic

  1. init negotiator with filter Negotiator({ "ticketClass": "VIP"});
  2. ask for tokens negotiator.negotiate().then((tickets) => { this.sendBackendRequestToRerenderProductsAndDiscounts(tickets) })
  3. If user click "useTicket" then webster run const useDevconTicket = await Authenticator.getAuthenticationBlob({ ticket }); // webster sign useDevconTicket with metamask and send it to the smartContract const signedTicket = await Authenticator.signToken(useDevconTicket); // for bogota example: I will add Authenticator method to sign ticket with Metamask and return result object. and you can send that object to the backend for autorization+dicounted checkout. const = this.backendRequestForCheckoutWithDiscount(product, signedTicket); // backend can authorize user based on useDevconTicket signature. also backend have to compare user address in authorization and user signature. it should fit.

Lets download products list JSON (not import), because download JSON is similar to download rendered product list from server.

Lets add few JSONS to simulate different discounts. Like roomTypesDataMock_ticketClass_2.json, roomTypesDataMock_ticketClass_2-3.json

Also we can extend example to show checkout page based on signed ticket. (we can add few JSONs for that too)

oleggrib commented 3 years ago

I have added sample backend https://bogotabackend.herokuapp.com/ "/" GET will answer with products JSON "/" POST send serialized tickets list and it will answer with updated products POST body: tickets:[{"devconId":"6n","ticketId":"48646n","ticketClass":"0n"}]

its nodejs server app, so we can add cone to validate ticket/attestation too.