Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@vostokplatform/voting-contract-api

Package Overview
Dependencies
Maintainers
9
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vostokplatform/voting-contract-api - npm Package Compare versions

Comparing version 0.2.0-RC1 to 0.2.0-RC2

dist/common/interfaces/IAddMainKey.d.ts

33

dist/index.d.ts

@@ -1,28 +0,5 @@

import { ICreateContractParams, IUpdateServerListParams, IVoteParams, IVotingContractAPICtr, IDkgRoundParams, IUpdateAdminListParams, IAddMainKey, IResultsParams, IDkgCommitParams, IDkgScalarParams, IDkgShadowsParams, IDkgComplaintParams, IDecryptionParams, IModifiedWavesApiResponse, IParticipantParams } from "./interfaces";
export declare class VotingContract {
private readonly weApi;
private readonly keyPair;
private readonly fetchInstance;
private readonly apiUrl;
private readonly STATUS_RESPONSE_TIMEOUT;
private checkStatusTimerId;
private statusResponseTimerId;
private checkStatus;
private waitStatusResponse;
private createOperationParam;
private callDockerContract;
constructor(ctr: IVotingContractAPICtr);
initiateVoting: (params: ICreateContractParams) => Promise<IModifiedWavesApiResponse>;
vote: (params: IVoteParams) => Promise<IModifiedWavesApiResponse>;
updateServerList: (params: IUpdateServerListParams) => Promise<IModifiedWavesApiResponse>;
dkgRound: (params: IDkgRoundParams) => Promise<IModifiedWavesApiResponse>;
updateAdminList: (params: IUpdateAdminListParams) => Promise<IModifiedWavesApiResponse>;
addMainKey: (params: IAddMainKey) => Promise<IModifiedWavesApiResponse>;
results: (params: IResultsParams) => Promise<IModifiedWavesApiResponse>;
dkgCommit: (params: IDkgCommitParams) => Promise<IModifiedWavesApiResponse>;
dkgScalar: (params: IDkgScalarParams) => Promise<IModifiedWavesApiResponse>;
dkgShadows: (params: IDkgShadowsParams) => Promise<IModifiedWavesApiResponse>;
dkgComplaint: (params: IDkgComplaintParams) => Promise<IModifiedWavesApiResponse>;
decryption: (params: IDecryptionParams) => Promise<IModifiedWavesApiResponse>;
addParticipants: (params: IParticipantParams) => Promise<IModifiedWavesApiResponse>;
}
export declare const DEFAULTS: {
statusResponseTimeout: number;
};
export { VotingContract as WeVotingContract } from './we-voting';
export { VotingContract as RtVotingContract } from './rt-voting';

@@ -1,2 +0,2 @@

!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("@vostokplatform/waves-api"),require("moment"));else if("function"==typeof define&&define.amd)define(["@vostokplatform/waves-api","moment"],e);else{var a="object"==typeof exports?e(require("@vostokplatform/waves-api"),require("moment")):e(t["@vostokplatform/waves-api"],t.moment);for(var r in a)("object"==typeof exports?exports:t)[r]=a[r]}}(this,(function(t,e){return function(t){var e={};function a(r){if(e[r])return e[r].exports;var n=e[r]={i:r,l:!1,exports:{}};return t[r].call(n.exports,n,n.exports,a),n.l=!0,n.exports}return a.m=t,a.c=e,a.d=function(t,e,r){a.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},a.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},a.t=function(t,e){if(1&e&&(t=a(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(a.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)a.d(r,n,function(e){return t[e]}.bind(null,n));return r},a.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return a.d(e,"a",e),e},a.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},a.p="",a(a.s=2)}([function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.ParamType=void 0,function(t){t.string="string",t.integer="integer",t.boolean="boolean"}(e.ParamType||(e.ParamType={}))},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.MapContractParamsError=void 0;class r extends Error{constructor(t){super(`Error. Cannot map contract params. Unknown type for key: ${t}.`),this.name="MapContractParamsError"}}e.MapContractParamsError=r},function(t,e,a){"use strict";var r=this&&this.__awaiter||function(t,e,a,r){return new(a||(a=Promise))((function(n,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function o(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?n(t.value):(e=t.value,e instanceof a?e:new a((function(t){t(e)}))).then(s,o)}c((r=r.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.VotingContract=void 0;const n=a(3),i=a(0),s=a(4),o={statusResponseTimeout:2e4};e.VotingContract=class{constructor(t){this.checkStatusTimerId=null,this.statusResponseTimerId=null,this.checkStatus=t=>r(this,void 0,void 0,(function*(){const e=yield this.fetchInstance(`${this.apiUrl}/contracts/status/${t}`,{method:"GET"}),a=yield e.json();return 200===e.status?Object.assign(Object.assign({},e),{success:!0,data:a}):Object.assign(Object.assign({},e),{success:!1,data:a})})),this.waitStatusResponse=t=>(...e)=>r(this,void 0,void 0,(function*(){const a=yield t(...e);return new Promise(t=>{let e=!1,n=[];this.statusResponseTimerId=setTimeout(()=>{null!==this.checkStatusTimerId&&clearTimeout(this.checkStatusTimerId),e=!0,t({success:!1,data:a,status:n[n.length-1]}),n=[]},this.STATUS_RESPONSE_TIMEOUT);const i=()=>r(this,void 0,void 0,(function*(){const r=yield this.checkStatus(a.id);n.push(r.data),r.success&&r.data.some(t=>"Success"===t.status)&&(n=[],e=!0,null!==this.statusResponseTimerId&&clearTimeout(this.statusResponseTimerId),t({success:!0,data:a,status:r.data})),e||(this.checkStatusTimerId=setTimeout(i,1e3))}));i()})})),this.createOperationParam=t=>({type:i.ParamType.string,key:"operation",value:t}),this.callDockerContract=(t,e,a)=>{const{txParams:{contractId:r,fee:n},contractParams:i}=e,s={senderPublicKey:this.keyPair.publicKey,authorPublicKey:this.keyPair.publicKey,contractId:r,timestamp:Date.now(),params:[t,...Object.entries(i).map(a)],fee:n};return this.weApi.API.Node.transactions.broadcastFromClientAddress("dockerCall",s,this.keyPair)},this.initiateVoting=t=>r(this,void 0,void 0,(function*(){const{txParams:{fee:e,contractName:a,image:r,imageHash:n},contractParams:i}=t,o={senderPublicKey:this.keyPair.publicKey,timestamp:Date.now(),image:r,imageHash:n,contractName:a,params:Object.entries(i).map(s.mapCreateContractParams),fee:e};return this.weApi.API.Node.transactions.broadcastFromClientAddress("dockerCreateV2",o,this.keyPair)})),this.vote=t=>this.callDockerContract(this.createOperationParam("vote"),t,s.mapVoteParams),this.updateServerList=t=>this.callDockerContract(this.createOperationParam("updateServerList"),t,s.mapUpdateServerListParams),this.dkgRound=t=>this.callDockerContract(this.createOperationParam("dkgRound"),t,s.mapDkgRoundParams),this.updateAdminList=t=>this.callDockerContract(this.createOperationParam("updateAdminList"),t,s.mapUpdateAdminListParams),this.addMainKey=t=>this.callDockerContract(this.createOperationParam("addMainKey"),t,s.mapAddMainKeyParams),this.results=t=>this.callDockerContract(this.createOperationParam("results"),t,s.mapResultsParams),this.dkgCommit=t=>this.callDockerContract(this.createOperationParam("dkgCommit"),t,s.mapDkgCommitParams),this.dkgScalar=t=>this.callDockerContract(this.createOperationParam("dkgScalar"),t,s.mapDkgScalarParams),this.dkgShadows=t=>this.callDockerContract(this.createOperationParam("dkgShadows"),t,s.mapDkgShadowsParams),this.dkgComplaint=t=>this.callDockerContract(this.createOperationParam("dkgComplaint"),t,s.mapDkgComplaintParams),this.decryption=t=>this.callDockerContract(this.createOperationParam("decryption"),t,s.mapDecryptionParams),this.addParticipants=t=>this.callDockerContract(this.createOperationParam("addParticipants"),t,s.mapAddParticipantsParams);const{weApiConfig:e,fetchInstance:a,keyPair:c,statusResponseTimeout:u}=Object.assign(Object.assign({},o),t);this.STATUS_RESPONSE_TIMEOUT=u,this.fetchInstance=a,this.apiUrl=e.nodeAddress.replace(/\/$/,""),this.keyPair=c,this.weApi=n.create({initialConfiguration:e,fetchInstance:a}),this.initiateVoting=this.waitStatusResponse(this.initiateVoting),this.callDockerContract=this.waitStatusResponse(this.callDockerContract)}}},function(e,a){e.exports=t},function(t,e,a){"use strict";var r=this&&this.__createBinding||(Object.create?function(t,e,a,r){void 0===r&&(r=a),Object.defineProperty(t,r,{enumerable:!0,get:function(){return e[a]}})}:function(t,e,a,r){void 0===r&&(r=a),t[r]=e[a]}),n=this&&this.__exportStar||function(t,e){for(var a in t)"default"===a||e.hasOwnProperty(a)||r(e,t,a)};Object.defineProperty(e,"__esModule",{value:!0}),n(a(5),e),n(a(9),e),n(a(10),e),n(a(11),e),n(a(12),e),n(a(13),e),n(a(14),e),n(a(15),e),n(a(16),e),n(a(17),e),n(a(18),e),n(a(19),e),n(a(20),e)},function(t,e,a){"use strict";var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.mapCreateContractParams=void 0;const n=r(a(6)),i=a(0),s=a(7),o=a(8),c=a(1);e.mapCreateContractParams=t=>{const[e,a]=t;if("string"==typeof a)return{type:i.ParamType.string,key:e,value:a};if(s.isDateInstance(a))return{type:i.ParamType.string,key:e,value:n.default.utc(a).format(o.DateFormat)};if(Array.isArray(a))return"docs"===e?{type:i.ParamType.string,key:e,value:JSON.stringify(a.map(t=>(t.dateUpload=n.default.utc(t.dateUpload).format(o.DateFormat),t)))}:{type:i.ParamType.string,key:e,value:JSON.stringify(a)};if("number"==typeof a)return{type:i.ParamType.integer,key:e,value:a};throw new c.MapContractParamsError(e)}},function(t,a){t.exports=e},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.isDateInstance=void 0,e.isDateInstance=function(t){return t instanceof Date&&!isNaN(t.valueOf())}},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.DateFormat=void 0,e.DateFormat="DD-MM-YYYY HH:mm:ss"},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.mapUpdateServerListParams=void 0;const r=a(0),n=a(1);e.mapUpdateServerListParams=t=>{const[e,a]=t;if("string"==typeof a)return{type:r.ParamType.string,key:e,value:a};if(Array.isArray(a))return{type:r.ParamType.string,key:e,value:JSON.stringify(a)};if("number"==typeof a)return{type:r.ParamType.integer,key:e,value:a};throw new n.MapContractParamsError(e)}},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.mapVoteParams=void 0;const r=a(0),n=a(1);e.mapVoteParams=function(t){const[e,a]=t;if("string"==typeof a)return{type:r.ParamType.string,key:e,value:a};throw new n.MapContractParamsError(e)}},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.mapDkgRoundParams=void 0;const r=a(0),n=a(1);e.mapDkgRoundParams=function(t){const[e,a]=t;if("number"==typeof a)return{type:r.ParamType.integer,key:e,value:a};throw new n.MapContractParamsError(e)}},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.mapUpdateAdminListParams=void 0;const r=a(0),n=a(1);e.mapUpdateAdminListParams=function(t){const[e,a]=t;if(Array.isArray(a))return{type:r.ParamType.string,key:e,value:JSON.stringify(a)};throw new n.MapContractParamsError(e)}},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.mapAddMainKeyParams=void 0;const r=a(0),n=a(1);e.mapAddMainKeyParams=function(t){const[e,a]=t;if("string"==typeof a)return{type:r.ParamType.string,key:e,value:a};if("number"==typeof a)return{type:r.ParamType.integer,key:e,value:a};throw new n.MapContractParamsError(e)}},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.mapResultsParams=void 0;const r=a(0),n=a(1);e.mapResultsParams=function(t){const[e,a]=t;if("string"==typeof a)return{type:r.ParamType.string,key:e,value:a};throw new n.MapContractParamsError(e)}},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.mapDkgCommitParams=void 0;const r=a(0),n=a(1);e.mapDkgCommitParams=function(t){const[e,a]=t;if("number"==typeof a)return{type:r.ParamType.integer,key:e,value:a};if("object"==typeof a)return{type:r.ParamType.string,key:e,value:JSON.stringify(a)};throw new n.MapContractParamsError(e)}},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.mapDkgScalarParams=void 0;const r=a(0),n=a(1);e.mapDkgScalarParams=function(t){const[e,a]=t;if("number"==typeof a)return{type:r.ParamType.integer,key:e,value:a};if("string"==typeof a)return{type:r.ParamType.string,key:e,value:a};throw new n.MapContractParamsError(e)}},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.mapDkgShadowsParams=void 0;const r=a(0),n=a(1);e.mapDkgShadowsParams=function(t){const[e,a]=t;if("object"==typeof a)return{type:r.ParamType.string,key:e,value:JSON.stringify(a)};if("number"==typeof a)return{type:r.ParamType.integer,key:e,value:a};throw new n.MapContractParamsError(e)}},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.mapDkgComplaintParams=void 0;const r=a(0),n=a(1);e.mapDkgComplaintParams=function(t){const[e,a]=t;if("number"==typeof a)return{type:r.ParamType.integer,key:e,value:a};if("string"==typeof a)return{type:r.ParamType.string,key:e,value:a};throw new n.MapContractParamsError(e)}},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.mapDecryptionParams=void 0;const r=a(0),n=a(1);e.mapDecryptionParams=function(t){const[e,a]=t;if("string"==typeof a)return{type:r.ParamType.string,key:e,value:a};throw new n.MapContractParamsError(e)}},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.mapAddParticipantsParams=void 0;const r=a(0),n=a(1);e.mapAddParticipantsParams=t=>{const[e,a]=t;if(Array.isArray(a))return{type:r.ParamType.string,key:e,value:JSON.stringify(a)};throw new n.MapContractParamsError(e)}}])}));
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("@vostokplatform/waves-api"),require("moment"));else if("function"==typeof define&&define.amd)define(["@vostokplatform/waves-api","moment"],e);else{var a="object"==typeof exports?e(require("@vostokplatform/waves-api"),require("moment")):e(t["@vostokplatform/waves-api"],t.moment);for(var r in a)("object"==typeof exports?exports:t)[r]=a[r]}}(this,(function(t,e){return function(t){var e={};function a(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,a),i.l=!0,i.exports}return a.m=t,a.c=e,a.d=function(t,e,r){a.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},a.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},a.t=function(t,e){if(1&e&&(t=a(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(a.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)a.d(r,i,function(e){return t[e]}.bind(null,i));return r},a.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return a.d(e,"a",e),e},a.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},a.p="",a(a.s=2)}([function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.ParamType=void 0,function(t){t.string="string",t.integer="integer",t.boolean="boolean"}(e.ParamType||(e.ParamType={}))},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.MapContractParamsError=void 0;class r extends Error{constructor(t){super(`Error. Cannot map contract params. Unknown type for key: ${t}.`),this.name="MapContractParamsError"}}e.MapContractParamsError=r},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.DEFAULTS=void 0,e.DEFAULTS={statusResponseTimeout:2e4};var r=a(8);Object.defineProperty(e,"WeVotingContract",{enumerable:!0,get:function(){return r.VotingContract}});var i=a(23);Object.defineProperty(e,"RtVotingContract",{enumerable:!0,get:function(){return i.VotingContract}})},function(e,a){e.exports=t},function(t,e,a){"use strict";var r=this&&this.__createBinding||(Object.create?function(t,e,a,r){void 0===r&&(r=a),Object.defineProperty(t,r,{enumerable:!0,get:function(){return e[a]}})}:function(t,e,a,r){void 0===r&&(r=a),t[r]=e[a]}),i=this&&this.__exportStar||function(t,e){for(var a in t)"default"===a||e.hasOwnProperty(a)||r(e,t,a)};Object.defineProperty(e,"__esModule",{value:!0}),i(a(9),e),i(a(10),e),i(a(11),e),i(a(12),e),i(a(13),e),i(a(14),e),i(a(15),e),i(a(16),e),i(a(17),e),i(a(18),e)},function(t,a){t.exports=e},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.isDateInstance=void 0,e.isDateInstance=function(t){return t instanceof Date&&!isNaN(t.valueOf())}},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.DateFormat=void 0,e.DateFormat="DD-MM-YYYY HH:mm:ss"},function(t,e,a){"use strict";var r=this&&this.__awaiter||function(t,e,a,r){return new(a||(a=Promise))((function(i,s){function n(t){try{c(r.next(t))}catch(t){s(t)}}function o(t){try{c(r.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof a?e:new a((function(t){t(e)}))).then(n,o)}c((r=r.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.VotingContract=void 0;const i=a(3),s=a(4),n=a(0),o=a(2),c=a(19);e.VotingContract=class{constructor(t){this.checkStatusTimerId=null,this.statusResponseTimerId=null,this.checkStatus=t=>r(this,void 0,void 0,(function*(){const e=yield this.fetchInstance(`${this.apiUrl}/contracts/status/${t}`,{method:"GET"}),a=yield e.json();return 200===e.status?Object.assign(Object.assign({},e),{success:!0,data:a}):Object.assign(Object.assign({},e),{success:!1,data:a})})),this.waitStatusResponse=t=>(...e)=>r(this,void 0,void 0,(function*(){const a=yield t(...e);return new Promise(t=>{let e=!1,i=[];this.statusResponseTimerId=setTimeout(()=>{null!==this.checkStatusTimerId&&clearTimeout(this.checkStatusTimerId),e=!0,t({success:!1,data:a,status:i[i.length-1]}),i=[]},this.STATUS_RESPONSE_TIMEOUT);const s=()=>r(this,void 0,void 0,(function*(){const r=yield this.checkStatus(a.id);i.push(r.data),r.success&&r.data.some(t=>"Success"===t.status)&&(i=[],e=!0,null!==this.statusResponseTimerId&&clearTimeout(this.statusResponseTimerId),t({success:!0,data:a,status:r.data})),e||(this.checkStatusTimerId=setTimeout(s,1e3))}));s()})})),this.createOperationParam=t=>({type:n.ParamType.string,key:"operation",value:t}),this.callDockerContract=(t,e,a)=>{const{txParams:{contractId:r,fee:i},contractParams:s}=e,n={senderPublicKey:this.keyPair.publicKey,authorPublicKey:this.keyPair.publicKey,contractId:r,timestamp:Date.now(),params:[t,...Object.entries(s).map(a)],fee:i};return this.weApi.API.Node.transactions.broadcastFromClientAddress("dockerCall",n,this.keyPair)},this.initiateVoting=t=>r(this,void 0,void 0,(function*(){const{txParams:{fee:e,contractName:a,image:r,imageHash:i},contractParams:s}=t,n={senderPublicKey:this.keyPair.publicKey,timestamp:Date.now(),image:r,imageHash:i,contractName:a,params:Object.entries(s).map(c.mapCreateContractParams),fee:e};return this.weApi.API.Node.transactions.broadcastFromClientAddress("dockerCreateV2",n,this.keyPair)})),this.vote=t=>this.callDockerContract(this.createOperationParam("vote"),t,s.mapVoteParams),this.updateServerList=t=>this.callDockerContract(this.createOperationParam("updateServerList"),t,s.mapUpdateServerListParams),this.dkgRound=t=>this.callDockerContract(this.createOperationParam("dkgRound"),t,s.mapDkgRoundParams),this.updateAdminList=t=>this.callDockerContract(this.createOperationParam("updateAdminList"),t,c.mapUpdateAdminListParams),this.addMainKey=t=>this.callDockerContract(this.createOperationParam("addMainKey"),t,s.mapAddMainKeyParams),this.results=t=>this.callDockerContract(this.createOperationParam("results"),t,s.mapResultsParams),this.dkgCommit=t=>this.callDockerContract(this.createOperationParam("dkgCommit"),t,s.mapDkgCommitParams),this.dkgScalar=t=>this.callDockerContract(this.createOperationParam("dkgScalar"),t,s.mapDkgScalarParams),this.dkgShadows=t=>this.callDockerContract(this.createOperationParam("dkgShadows"),t,s.mapDkgShadowsParams),this.dkgComplaint=t=>this.callDockerContract(this.createOperationParam("dkgComplaint"),t,s.mapDkgComplaintParams),this.decryption=t=>this.callDockerContract(this.createOperationParam("decryption"),t,s.mapDecryptionParams),this.addParticipants=t=>this.callDockerContract(this.createOperationParam("addParticipants"),t,c.mapAddParticipantsParams);const{weApiConfig:e,fetchInstance:a,keyPair:u,statusResponseTimeout:p}=Object.assign(Object.assign({},o.DEFAULTS),t);this.STATUS_RESPONSE_TIMEOUT=p,this.fetchInstance=a,this.apiUrl=e.nodeAddress.replace(/\/$/,""),this.keyPair=u,this.weApi=i.create({initialConfiguration:e,fetchInstance:a}),this.initiateVoting=this.waitStatusResponse(this.initiateVoting),this.callDockerContract=this.waitStatusResponse(this.callDockerContract)}}},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.mapUpdateServerListParams=void 0;const r=a(0),i=a(1);e.mapUpdateServerListParams=t=>{const[e,a]=t;if("string"==typeof a)return{type:r.ParamType.string,key:e,value:a};if(Array.isArray(a))return{type:r.ParamType.string,key:e,value:JSON.stringify(a)};if("number"==typeof a)return{type:r.ParamType.integer,key:e,value:a};throw new i.MapContractParamsError(e)}},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.mapVoteParams=void 0;const r=a(0),i=a(1);e.mapVoteParams=function(t){const[e,a]=t;if("string"==typeof a)return{type:r.ParamType.string,key:e,value:a};throw new i.MapContractParamsError(e)}},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.mapDkgRoundParams=void 0;const r=a(0),i=a(1);e.mapDkgRoundParams=function(t){const[e,a]=t;if("number"==typeof a)return{type:r.ParamType.integer,key:e,value:a};throw new i.MapContractParamsError(e)}},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.mapAddMainKeyParams=void 0;const r=a(0),i=a(1);e.mapAddMainKeyParams=function(t){const[e,a]=t;if("string"==typeof a)return{type:r.ParamType.string,key:e,value:a};if("number"==typeof a)return{type:r.ParamType.integer,key:e,value:a};throw new i.MapContractParamsError(e)}},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.mapResultsParams=void 0;const r=a(0),i=a(1);e.mapResultsParams=function(t){const[e,a]=t;if("string"==typeof a)return{type:r.ParamType.string,key:e,value:a};throw new i.MapContractParamsError(e)}},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.mapDkgCommitParams=void 0;const r=a(0),i=a(1);e.mapDkgCommitParams=function(t){const[e,a]=t;if("number"==typeof a)return{type:r.ParamType.integer,key:e,value:a};if("object"==typeof a)return{type:r.ParamType.string,key:e,value:JSON.stringify(a)};throw new i.MapContractParamsError(e)}},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.mapDkgScalarParams=void 0;const r=a(0),i=a(1);e.mapDkgScalarParams=function(t){const[e,a]=t;if("number"==typeof a)return{type:r.ParamType.integer,key:e,value:a};if("string"==typeof a)return{type:r.ParamType.string,key:e,value:a};throw new i.MapContractParamsError(e)}},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.mapDkgShadowsParams=void 0;const r=a(0),i=a(1);e.mapDkgShadowsParams=function(t){const[e,a]=t;if("object"==typeof a)return{type:r.ParamType.string,key:e,value:JSON.stringify(a)};if("number"==typeof a)return{type:r.ParamType.integer,key:e,value:a};throw new i.MapContractParamsError(e)}},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.mapDkgComplaintParams=void 0;const r=a(0),i=a(1);e.mapDkgComplaintParams=function(t){const[e,a]=t;if("number"==typeof a)return{type:r.ParamType.integer,key:e,value:a};if("string"==typeof a)return{type:r.ParamType.string,key:e,value:a};throw new i.MapContractParamsError(e)}},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.mapDecryptionParams=void 0;const r=a(0),i=a(1);e.mapDecryptionParams=function(t){const[e,a]=t;if("string"==typeof a)return{type:r.ParamType.string,key:e,value:a};throw new i.MapContractParamsError(e)}},function(t,e,a){"use strict";var r=this&&this.__createBinding||(Object.create?function(t,e,a,r){void 0===r&&(r=a),Object.defineProperty(t,r,{enumerable:!0,get:function(){return e[a]}})}:function(t,e,a,r){void 0===r&&(r=a),t[r]=e[a]}),i=this&&this.__exportStar||function(t,e){for(var a in t)"default"===a||e.hasOwnProperty(a)||r(e,t,a)};Object.defineProperty(e,"__esModule",{value:!0}),i(a(20),e),i(a(21),e),i(a(22),e)},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.mapUpdateAdminListParams=void 0;const r=a(0),i=a(1);e.mapUpdateAdminListParams=function(t){const[e,a]=t;if(Array.isArray(a))return{type:r.ParamType.string,key:e,value:JSON.stringify(a)};throw new i.MapContractParamsError(e)}},function(t,e,a){"use strict";var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.mapCreateContractParams=void 0;const i=r(a(5)),s=a(0),n=a(6),o=a(7),c=a(1);e.mapCreateContractParams=t=>{const[e,a]=t;if("string"==typeof a)return{type:s.ParamType.string,key:e,value:a};if(n.isDateInstance(a))return{type:s.ParamType.string,key:e,value:i.default.utc(a).format(o.DateFormat)};if(Array.isArray(a))return"docs"===e?{type:s.ParamType.string,key:e,value:JSON.stringify(a.map(t=>(t.dateUpload=i.default.utc(t.dateUpload).format(o.DateFormat),t)))}:{type:s.ParamType.string,key:e,value:JSON.stringify(a)};if("number"==typeof a)return{type:s.ParamType.integer,key:e,value:a};throw new c.MapContractParamsError(e)}},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.mapAddParticipantsParams=void 0;const r=a(0),i=a(1);e.mapAddParticipantsParams=t=>{const[e,a]=t;if(Array.isArray(a))return{type:r.ParamType.string,key:e,value:JSON.stringify(a)};throw new i.MapContractParamsError(e)}},function(t,e,a){"use strict";var r=this&&this.__awaiter||function(t,e,a,r){return new(a||(a=Promise))((function(i,s){function n(t){try{c(r.next(t))}catch(t){s(t)}}function o(t){try{c(r.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof a?e:new a((function(t){t(e)}))).then(n,o)}c((r=r.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.VotingContract=void 0;const i=a(3),s=a(4),n=a(24),o=a(0),c=a(2);e.VotingContract=class{constructor(t){this.checkStatusTimerId=null,this.statusResponseTimerId=null,this.checkStatus=t=>r(this,void 0,void 0,(function*(){const e=yield this.fetchInstance(`${this.apiUrl}/contracts/status/${t}`,{method:"GET"}),a=yield e.json();return 200===e.status?Object.assign(Object.assign({},e),{success:!0,data:a}):Object.assign(Object.assign({},e),{success:!1,data:a})})),this.waitStatusResponse=t=>(...e)=>r(this,void 0,void 0,(function*(){const a=yield t(...e);return new Promise(t=>{let e=!1,i=[];this.statusResponseTimerId=setTimeout(()=>{null!==this.checkStatusTimerId&&clearTimeout(this.checkStatusTimerId),e=!0,t({success:!1,data:a,status:i[i.length-1]}),i=[]},this.STATUS_RESPONSE_TIMEOUT);const s=()=>r(this,void 0,void 0,(function*(){const r=yield this.checkStatus(a.id);i.push(r.data),r.success&&r.data.some(t=>"Success"===t.status)&&(i=[],e=!0,null!==this.statusResponseTimerId&&clearTimeout(this.statusResponseTimerId),t({success:!0,data:a,status:r.data})),e||(this.checkStatusTimerId=setTimeout(s,1e3))}));s()})})),this.createOperationParam=t=>({type:o.ParamType.string,key:"operation",value:t}),this.callDockerContract=(t,e,a)=>{const{txParams:{contractId:r,fee:i},contractParams:s}=e,n=[t];void 0!==a&&n.push(...Object.entries(s).map(a));const o={senderPublicKey:this.keyPair.publicKey,authorPublicKey:this.keyPair.publicKey,contractId:r,timestamp:Date.now(),params:n,fee:i};return this.weApi.API.Node.transactions.broadcastFromClientAddress("dockerCall",o,this.keyPair)},this.initiateVoting=t=>r(this,void 0,void 0,(function*(){const{txParams:{fee:e,contractName:a,image:r,imageHash:i},contractParams:s}=t,o={senderPublicKey:this.keyPair.publicKey,timestamp:Date.now(),image:r,imageHash:i,contractName:a,params:Object.entries(s).map(n.mapCreateContractParams),fee:e};return this.weApi.API.Node.transactions.broadcastFromClientAddress("dockerCreateV2",o,this.keyPair)})),this.vote=t=>this.callDockerContract(this.createOperationParam("vote"),t,s.mapVoteParams),this.updateServerList=t=>this.callDockerContract(this.createOperationParam("updateServerList"),t,s.mapUpdateServerListParams),this.dkgRound=t=>this.callDockerContract(this.createOperationParam("dkgRound"),t,s.mapDkgRoundParams),this.addMainKey=t=>this.callDockerContract(this.createOperationParam("addMainKey"),t,s.mapAddMainKeyParams),this.results=t=>this.callDockerContract(this.createOperationParam("results"),t,s.mapResultsParams),this.dkgCommit=t=>this.callDockerContract(this.createOperationParam("dkgCommit"),t,s.mapDkgCommitParams),this.dkgScalar=t=>this.callDockerContract(this.createOperationParam("dkgScalar"),t,s.mapDkgScalarParams),this.dkgShadows=t=>this.callDockerContract(this.createOperationParam("dkgShadows"),t,s.mapDkgShadowsParams),this.dkgComplaint=t=>this.callDockerContract(this.createOperationParam("dkgComplaint"),t,s.mapDkgComplaintParams),this.decryption=t=>this.callDockerContract(this.createOperationParam("decryption"),t,s.mapDecryptionParams),this.finishVoting=t=>this.callDockerContract(this.createOperationParam("finishVoting"),t);const{weApiConfig:e,fetchInstance:a,keyPair:u,statusResponseTimeout:p}=Object.assign(Object.assign({},c.DEFAULTS),t);this.STATUS_RESPONSE_TIMEOUT=p,this.fetchInstance=a,this.apiUrl=e.nodeAddress.replace(/\/$/,""),this.keyPair=u,this.weApi=i.create({initialConfiguration:e,fetchInstance:a}),this.initiateVoting=this.waitStatusResponse(this.initiateVoting),this.callDockerContract=this.waitStatusResponse(this.callDockerContract)}}},function(t,e,a){"use strict";var r=this&&this.__createBinding||(Object.create?function(t,e,a,r){void 0===r&&(r=a),Object.defineProperty(t,r,{enumerable:!0,get:function(){return e[a]}})}:function(t,e,a,r){void 0===r&&(r=a),t[r]=e[a]}),i=this&&this.__exportStar||function(t,e){for(var a in t)"default"===a||e.hasOwnProperty(a)||r(e,t,a)};Object.defineProperty(e,"__esModule",{value:!0}),i(a(25),e)},function(t,e,a){"use strict";var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.mapCreateContractParams=void 0;const i=r(a(5)),s=a(0),n=a(6),o=a(7),c=a(1);e.mapCreateContractParams=t=>{const[e,a]=t;if("string"==typeof a)return{type:s.ParamType.string,key:e,value:a};if(n.isDateInstance(a))return{type:s.ParamType.string,key:e,value:i.default.utc(a).format(o.DateFormat)};if(Array.isArray(a))return{type:s.ParamType.string,key:e,value:JSON.stringify(a)};if("number"==typeof a)return{type:s.ParamType.integer,key:e,value:a};throw new c.MapContractParamsError(e)}}])}));
//# sourceMappingURL=index.js.map
{
"name": "@vostokplatform/voting-contract-api",
"version": "0.2.0-RC1",
"version": "0.2.0-RC2",
"description": "",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc