diff --git a/.gitignore b/.gitignore index 77fe0bc..c0c7dc6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ node_modules dist package-lock.json pnpm-lock.yaml +lib +types +.DS_Store \ No newline at end of file diff --git a/lib/index.d.ts b/lib/index.d.ts deleted file mode 100644 index d3169af..0000000 --- a/lib/index.d.ts +++ /dev/null @@ -1,238 +0,0 @@ -import { AESKey, RSAKey } from '@daotl/cryptico'; -import { AxiosRequestConfig } from 'axios'; -import { KeyPairHex } from 'sm-crypto'; - -declare function aesEncrypt(data: string, aesKey: AESKey): string; -declare function rsaEncrypt(data: string, rsaKey: { - n: string; - e1: string; -}): string; -declare function loadRSAKey(rsaKey: string): RSAKey; -declare function encryptReq(reqContent: { - contractID: string; -}, pubKey: RSAKey): { - action: string | null; - contractID: string; - arg: string; - requester: string; -}; - -type ClientResponse = Omit & { - data?: Data; -}; -type PingResponse = ClientResponse<'pong'>; -interface SaveFileRequest { - content: string; - isAppend: boolean; - isPrivate: boolean; - path: string; -} -interface ListProjectPermissionRequest { - isPrivate: boolean; - path: string; -} -interface ListProjectPermissionResponseData { - permissions: string[]; - ypk: string; -} -interface StartContractByYpkRequest { - isPrivate: boolean; - path: string; - script: string; -} -interface ListAllUsersResponseDataListItem { - key: string; - value: string; -} -interface ListAllUsersResponseData { - kv: ListAllUsersResponseDataListItem[]; - time: ListAllUsersResponseDataListItem[]; -} -interface OnlineContractsItem { - contractID: string; - contractName: string; - isMaster: boolean; - type: string; - yjsType: string; - [key: string]: unknown; -} -interface OnlineItem { - cimanager: string; - contractVersion: number; - events: number; - ipPort: string; - masterAddress: string; - nodeName: string; - peerID: string; - pubKey: string; - contracts: OnlineContractsItem[]; -} -interface ListNodesResponse { - action: string; - offline: string[]; - online: OnlineItem[]; -} -interface DistributeContractResponse { - action: string; - progress: string; -} -interface ExecuteContractArgs extends RequestInit { - method?: 'POST' | 'GET'; - withSignature?: boolean; - withDynamicAnalysis?: boolean; -} -interface ExecuteContractResponse { - status?: boolean; - data?: Data; - executeTime?: number; - cid?: string; - isPrivate?: boolean; - [key: string]: unknown; -} -interface ConfigNodeArgs { - nodeName?: string; - dataChain?: string; - masterAddress?: string; - nodeCenter?: string; - LHSProxyAddress?: string; - [K: string]: string | undefined; -} -interface LoadNodeConfigResponseData { - doipConfig: string; - [K: string]: string; -} - -declare class HttpClient { - private baseUrl; - private sm2Key; - private fetch; - constructor(baseUrl: string, sm2Key: KeyPairHex, config?: AxiosRequestConfig); - requestWithSignature(path: string, init?: Partial, sm2Key?: KeyPairHex): Promise>; - retryRequestWithSignature(retryTimes: number, path: string, init?: Partial, sm2Key?: KeyPairHex): Promise>; - sign(data: string, privateKey?: string): string; - ping(): Promise; - startContract(code: string): Promise>; - startContractByYPK(_request: StartContractByYpkRequest): Promise>; - executeContract(contractID: string, operation: string, arg: string, { method, withDynamicAnalysis, withSignature, }?: ExecuteContractArgs): Promise>>; - killContractProcess(contractID: string, requestID?: string): Promise>; - killAllContract(): Promise>; - applyNodeRole(role: string): Promise>; - authNodeRole(isAccept: boolean, authorizedPubKey: string, managerPair?: KeyPairHex): Promise>; - distributeContract(nodeIDs: string, projectName: string, isPrivate: boolean): void; - saveFile(_request: SaveFileRequest): Promise>; - listProjectPermission(_request: ListProjectPermissionRequest): Promise>; - startContractMultiPoint(peersID: string, type: number, selectUnitNum: number, projectName: string, isPrivate: boolean, sponsorPeerID: string): Promise>; - loadNodeConfig(): Promise>; - updateConfig(key: string, val: string): Promise>; - resetNodeManager(): Promise; - lockEdit(): Promise>; - unlockEdit(): Promise>; - addNode(nodePubKey: string): Promise>; - applyRole(role: string): Promise>; - authNodeManager(isAccept: boolean, authorizedPubKey: string): Promise>; - listAllUsers(): Promise>; - listNodes(): Promise; - createTrustUnit(data: { - nodeName: string; - pubkey: string; - }[], Msg: string): Promise<{ - action: string; - status: string; - }>; - listTrustUnits(): Promise>; - listContractProcess(): Promise>; - downloadContract(projectName: string, isPrivate: boolean, timestamp: number): Promise>; - configNode(args: ConfigNodeArgs): Promise; -} - -interface WsEvent { - data: string; -} -type OnOpenHandler = (this: WebSocket, ev: Event) => void; -type WsHandler = (ev: WsEvent, ws?: WebSocket) => void; -interface SegmentData { - action: 'sendSeg'; - cid: string; - data: string; -} -declare class WsSocket { - private handlerList; - private toSend; - private isSending; - private sendList; - private toReceive; - private wssocket; - constructor(wsurl: string, onopen: OnOpenHandler, handler?: WsHandler); - status(): WebSocket['CLOSED' | 'CLOSING' | 'CONNECTING' | 'OPEN']; - sendNextSegment(): void; - receiveSeg(obj: SegmentData): void; - monitor(): void; - send(data: string): void; - addHandler(handler: WsHandler): void; -} - -interface ResponseData { - action: string; - responseID?: string; - status: true | false | string; - result?: unknown; - data: string; - [K: string]: unknown; -} -declare class WsClient { - private readonly sm2Key; - private readonly wssocket; - private readonly promiseCallbackPairs; - private readonly sessionPromise; - private sessionResolve; - private readonly loginPromise; - private loginResolve; - constructor(url: string, onopen: OnOpenHandler, handler: WsHandler, sm2Key?: KeyPairHex); - status(): WebSocket['CLOSED' | 'CLOSING' | 'CONNECTING' | 'OPEN']; - sessionReceived(): Promise; - login(): Promise; - loggedIn(): Promise; - matchCID(contractID: string): Promise; - getMetabyCID(contractID: string): Promise; - getMetabyReadme(keyword: string, page?: string, pageSize?: string): Promise; - getMetabyPubkey(pubkey: string): Promise; - segmentWord(words: string): Promise; - getMetabyOwner(owner: string, page?: string, pageSize?: string): Promise; - getDependentContract(contractName: string): Promise; - queryContractLogByDate(start: number): Promise; - queryDataByHash(hash: string): Promise; - executeContract(contractID: string, method: string, arg: unknown): Promise; - getSessionID(): Promise; - listTheContractProcess(contractID: string): Promise; - getMask(contractID: string): Promise; - setMask(contractID: string, operation: string, arg: string): Promise; - getMock(contractID: string): Promise; - setMock(contractID: string, operation: string, arg: string): Promise; - queryHashByOffset(offset: number, count: number): Promise; - loadNodeConfig(): Promise; - queryUserStat(): Promise; - listNodes(): Promise; - killContractProcess(id: string): Promise; - distributeYPK(projectName: string, nodeIDs: string): Promise; - listYPKs(): Promise; - deleteFile(file: string): Promise; - startContractByYPK(project: string): Promise; - initBDServer(host: string, username: string, password: string, name: string, clusterHost: string): Promise; - initBDCluster(host: string, username: string, password: string, name: string, sm2Key: string, agents: []): Promise; - listCompiledFiles(): Promise; - getManagerPubkey(): Promise; - getClusterName(): Promise; - setClusterName(name: string): Promise; -} - -export { ClientResponse, ConfigNodeArgs, DistributeContractResponse, ExecuteContractArgs, ExecuteContractResponse, HttpClient, ListAllUsersResponseData, ListAllUsersResponseDataListItem, ListNodesResponse, ListProjectPermissionRequest, ListProjectPermissionResponseData, LoadNodeConfigResponseData, OnOpenHandler, OnlineContractsItem, OnlineItem, PingResponse, SaveFileRequest, StartContractByYpkRequest, WsClient, WsEvent, WsHandler, WsSocket, aesEncrypt, encryptReq, loadRSAKey, rsaEncrypt }; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index fe96a4a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,2 +0,0 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@daotl/cryptico"),require("@lifeomic/axios-fetch"),require("axios"),require("sm-crypto")):"function"==typeof define&&define.amd?define(["exports","@daotl/cryptico","@lifeomic/axios-fetch","axios","sm-crypto"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).bdcontract={},e.cryptico,e.axiosFetch,e.axios,e.smCrypto)}(this,(function(e,t,s,i,r){"use strict";function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=a(i);function o(e,s){const i=s.slice(0);t.aes.ExpandKey(i);let r=t.cryptico.string2bytes(e);r=t.cryptico.pad16(r),t.aes.Encrypt(r,i);let a=t.cryptico.bytes2string(r);return a=t.cryptico.b256to64(a),a}const c=e=>Object.entries(e).map((([e,t])=>`${e}=${String(t)}`)).join("&");class h{handlerList=[];toSend="";isSending=!1;sendList=[];toReceive="";wssocket;constructor(e,t,s){console.log(`[createWS.js] createWssocket : ${e}`),s&&this.handlerList.push(s),this.monitor();const i=this,r=this.wssocket=new WebSocket(e);r.onerror=function(e){console.log(e)},r.onopen=t;const a=function(e){const t=JSON.parse(e.data);switch(t.action){case"sendNextSegment":i.sendNextSegment();break;case"sendSeg":i.receiveSeg(t);break;default:i.handlerList.forEach((t=>t(e,this)))}};r.onmessage=a;const n=function(){setTimeout((()=>{console.log("[createWS.js] try to reconnect");const s=i.wssocket=new WebSocket(e);s.onclose=n,s.onmessage=a,s.onopen=t}),1e3)};r.onclose=n}status(){return this.wssocket.readyState}sendNextSegment(){const e=this.toSend;if(e.length>1024){this.toSend=e.substr(1024);const t={isSegment:!0,data:e.substr(0,1024)};this.wssocket.send(JSON.stringify(t))}else{this.toSend="";const t={isSegment:!1,data:e};let s;this.wssocket.send(JSON.stringify(t)),this.isSending=!1,(s=this.sendList.pop())&&this.send(s)}}receiveSeg(e){if("start"===e.cid&&(this.toReceive=""),this.toReceive+=e.data,"done"===e.cid){console.log(`[receiveSeg] Received AllData:${this.toReceive}`);const e={data:this.toReceive};this.toReceive="",this.handlerList.forEach((t=>t(e,this.wssocket)))}}monitor(){if(!this.isSending){let e;(e=this.sendList.pop())&&this.send(e)}setTimeout((()=>this.monitor()),1e3)}send(e){if(this.isSending)this.sendList.push(e);else if(e.length>1024){this.isSending=!0,this.toSend=e.substr(1024);const t={isSegment:!0,data:e.substr(0,1024)};this.wssocket.send(JSON.stringify(t))}else this.wssocket.send(e)}addHandler(e){this.handlerList.push(e)}}e.HttpClient=class{baseUrl;sm2Key;fetch;constructor(e,t,i={}){this.baseUrl=e,this.sm2Key=t;const r=n.default.create({baseURL:"https://some-domain.com/api/",timeout:1e4,...i});this.fetch=s.buildAxiosFetch(r)}async requestWithSignature(e,t,s){return new Promise(((i,r)=>{const a=this.baseUrl+e,n=`${a}${e.includes("?")?"&":"?"}pubKey=${s?.publicKey??this.sm2Key.publicKey}`,o=this.sign(n.substring(n.indexOf("?")+1),s?.privateKey);this.fetch("post"===t?.method?.toLowerCase()?a:`${encodeURI(n)}&sign=${o}`,{...t,..."POST"===t?.method?{body:{...t?.body,sign:o}}:{}}).then((async e=>{const t=e;t.data=await e.text(),setTimeout((()=>{i(t)}),1)})).catch((e=>{setTimeout((()=>{r(e)}),1)}))}))}async retryRequestWithSignature(e,t,s,i){let r=new Error;for(let a=0;at));await Promise.all([...t.map((([e,t])=>this.updateConfig(e,t))),this.applyNodeRole("ContractProvider"),this.applyNodeRole("ContractUser"),this.applyNodeRole("ContractInstanceManager"),this.authNodeRole(!0,this.sm2Key.publicKey)]);const s=(await this.loadNodeConfig()).data;return!!s&&t.every((([e,t])=>s[function(e){if("dataChain"===e)return"bdledger";return e}(e)]===t))}},e.WsClient=class{sm2Key;wssocket;promiseCallbackPairs={};sessionPromise;sessionResolve;loginPromise;loginResolve;constructor(e,t,s,i=r.sm2.generateKeyPairHex()){this.sm2Key=i,this.sessionPromise=new Promise(((e,t)=>{this.sessionResolve=e})),this.loginPromise=new Promise(((e,t)=>{this.loginResolve=e}));const a=this;this.wssocket=new h(e,t,(function(e,t){const i=JSON.parse(e.data);switch(i.action){case"onSessionID":a.sessionResolve(i.session);break;case"onLogin":{const e="string"==typeof i.status&&i.status.toLowerCase().includes("failed");a.loginResolve(!e)}}const r=i.responseID;let n;r&&(n=a.promiseCallbackPairs[r])&&(i?n.resolve(i):n.reject(i)),s(e,this)}))}status(){return this.wssocket.status()}sessionReceived(){return this.sessionPromise}async login(){const e=await this.sessionPromise,t={action:"login",pubKey:this.sm2Key.publicKey,signature:r.sm2.doSignature(e,this.sm2Key.privateKey,{hash:!0,der:!0})};return this.wssocket.send(JSON.stringify(t)),this.loginPromise}loggedIn(){return this.loginPromise}matchCID(e){const t=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,s={action:"matchCID",contractID:e};return this.wssocket.send(JSON.stringify(s)),new Promise(((e,s)=>{this.promiseCallbackPairs[t]={resolve:e,reject:s}}))}getMetabyCID(e){const t=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,s={action:"getMetabyCID",contractID:e,requestID:t};return this.wssocket.send(JSON.stringify(s)),new Promise(((e,s)=>{this.promiseCallbackPairs[t]={resolve:e,reject:s}}))}getMetabyReadme(e,t,s){const i=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,r={action:"getMetabyReadme",page:t,pageSize:s,keyword:e,requestID:i};return this.wssocket.send(JSON.stringify(r)),new Promise(((e,t)=>{this.promiseCallbackPairs[i]={resolve:e,reject:t}}))}getMetabyPubkey(e){const t=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,s={action:"getMetabyPubkey",pubkey:e,requestID:t};return this.wssocket.send(JSON.stringify(s)),new Promise(((e,s)=>{this.promiseCallbackPairs[t]={resolve:e,reject:s}}))}segmentWord(e){const t=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,s={words:e,action:"segmentWord",requestID:t};return this.wssocket.send(JSON.stringify(s)),new Promise(((e,s)=>{this.promiseCallbackPairs[t]={resolve:e,reject:s}}))}getMetabyOwner(e,t,s){const i=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,r={action:"getMetabyOwner",owner:e,page:t,pageSize:s,requestID:i};return this.wssocket.send(JSON.stringify(r)),new Promise(((e,t)=>{this.promiseCallbackPairs[i]={resolve:e,reject:t}}))}getDependentContract(e){const t=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,s={action:"getDependentContract",requestID:t,contractName:e};return this.wssocket.send(JSON.stringify(s)),new Promise(((e,s)=>{this.promiseCallbackPairs[t]={resolve:e,reject:s}}))}queryContractLogByDate(e){const t=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,s={action:"queryContractLogByDate",requestID:t,start:e};return this.wssocket.send(JSON.stringify(s)),new Promise(((e,s)=>{this.promiseCallbackPairs[t]={resolve:e,reject:s}}))}queryDataByHash(e){const t=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,s={action:"queryDataByHash",requestID:t,hash:e};return this.wssocket.send(JSON.stringify(s)),new Promise(((e,s)=>{this.promiseCallbackPairs[t]={resolve:e,reject:s}}))}executeContract(e,t,s){const i=this.sm2Key,a=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,n="object"==typeof s?JSON.stringify(s):s+"",o={action:"executeContract",requestID:a,contractID:e,operation:t,arg:s,...i?{pubkey:i.publicKey,signature:r.sm2.doSignature(`${e}|${t}|${n}|${i.publicKey}`,i.privateKey,{hash:!0,der:!0})}:{}};return this.wssocket.send(JSON.stringify(o)),new Promise(((e,t)=>{this.promiseCallbackPairs[a]={resolve:e,reject:t}}))}getSessionID(){const e=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,t={action:"getSessionID",requestID:e};return this.wssocket.send(JSON.stringify(t)),new Promise(((t,s)=>{this.promiseCallbackPairs[e]={resolve:t,reject:s}}))}listTheContractProcess(e){const t=this.sm2Key,s=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,i={action:"listTheContractProcess",requestID:s,contractID:e,...t?{pubkey:t.publicKey,signature:r.sm2.doSignature(`${e}|${t.publicKey}`,t.privateKey,{hash:!0,der:!0})}:{}};return this.wssocket.send(JSON.stringify(i)),new Promise(((e,t)=>{this.promiseCallbackPairs[s]={resolve:e,reject:t}}))}getMask(e){const t=this.sm2Key,s=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,i={action:"getMask",requestID:s,contractID:e,...t?{pubkey:t.publicKey,signature:r.sm2.doSignature(`${e}|${t.publicKey}`,t.privateKey,{hash:!0,der:!0})}:{}};return this.wssocket.send(JSON.stringify(i)),new Promise(((e,t)=>{this.promiseCallbackPairs[s]={resolve:e,reject:t}}))}setMask(e,t,s){const i=this.sm2Key,a=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,n={action:"setMask",requestID:a,contractID:e,operation:t,arg:s,...i?{pubkey:i.publicKey,signature:r.sm2.doSignature(`${e}|${i.publicKey}`,i.privateKey,{hash:!0,der:!0})}:{}};return this.wssocket.send(JSON.stringify(n)),new Promise(((e,t)=>{this.promiseCallbackPairs[a]={resolve:e,reject:t}}))}getMock(e){const t=this.sm2Key,s=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,i={action:"getMock",requestID:s,contractID:e,...t?{pubkey:t.publicKey,signature:r.sm2.doSignature(`${e}|${t.publicKey}`,t.privateKey,{hash:!0,der:!0})}:{}};return this.wssocket.send(JSON.stringify(i)),new Promise(((e,t)=>{this.promiseCallbackPairs[s]={resolve:e,reject:t}}))}setMock(e,t,s){const i=this.sm2Key,a=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,n={action:"setMock",requestID:a,contractID:e,operation:t,arg:s,...i?{pubkey:i.publicKey,signature:r.sm2.doSignature(`${e}|${i.publicKey}`,i.privateKey,{hash:!0,der:!0})}:{}};return this.wssocket.send(JSON.stringify(n)),new Promise(((e,t)=>{this.promiseCallbackPairs[a]={resolve:e,reject:t}}))}queryHashByOffset(e,t){const s=this.sm2Key,i=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,r={action:"queryHashByOffset",requestID:i,offset:e,count:t,...s?{pubkey:s.publicKey}:{}};return this.wssocket.send(JSON.stringify(r)),new Promise(((e,t)=>{this.promiseCallbackPairs[i]={resolve:e,reject:t}}))}loadNodeConfig(){const e=this.sm2Key,t=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,s={action:"loadNodeConfig",requestID:t,...e?{pubkey:e.publicKey,signature:r.sm2.doSignature(e.publicKey,e.privateKey,{hash:!0,der:!0})}:{}};return this.wssocket.send(JSON.stringify(s)),new Promise(((e,s)=>{this.promiseCallbackPairs[t]={resolve:e,reject:s}}))}queryUserStat(){const e=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,t={action:"queryUserStat",requestID:e};return this.wssocket.send(JSON.stringify(t)),new Promise(((t,s)=>{this.promiseCallbackPairs[e]={resolve:t,reject:s}}))}listNodes(){const e=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,t={action:"listNodes",requestID:e};return this.wssocket.send(JSON.stringify(t)),new Promise(((t,s)=>{this.promiseCallbackPairs[e]={resolve:t,reject:s}}))}killContractProcess(e){const t=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,s={action:"killContractProcess",requestID:t,id:e};return this.wssocket.send(JSON.stringify(s)),new Promise(((e,s)=>{this.promiseCallbackPairs[t]={resolve:e,reject:s}}))}distributeYPK(e,t){const s=this.sm2Key,i=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,a={action:"distributeYPK",requestID:i,pubKey:s.publicKey,projectName:e,nodeIDs:t,signature:r.sm2.doSignature(`DistributeYPK|${e}|${s.publicKey}`,s.privateKey,{hash:!0,der:!0})};return this.wssocket.send(JSON.stringify(a)),new Promise(((e,t)=>{this.promiseCallbackPairs[i]={resolve:e,reject:t}}))}listYPKs(){const e=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,t={action:"listYPKs",requestID:e};return this.wssocket.send(JSON.stringify(t)),new Promise(((t,s)=>{this.promiseCallbackPairs[e]={resolve:t,reject:s}}))}deleteFile(e){const t=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,s={action:"deleteFile",requestID:t,file:e};return this.wssocket.send(JSON.stringify(s)),new Promise(((e,s)=>{this.promiseCallbackPairs[t]={resolve:e,reject:s}}))}startContractByYPK(e){const t=this.sm2Key,s=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,i={action:"startContractByYPK",isPrivate:!0,requestID:s,owner:t.publicKey,path:`/${e}`,signature:r.sm2.doSignature(`Fixed|${e}|${t.publicKey}`,t.privateKey)};return this.wssocket.send(JSON.stringify(i)),new Promise(((e,t)=>{this.promiseCallbackPairs[s]={resolve:e,reject:t}}))}initBDServer(e,t,s,i,r){const a=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,n={action:"initBDServer",requestID:a,host:e,username:t,password:s,name:i,sm2Key:JSON.stringify(this.sm2Key),clusterHost:r};return this.wssocket.send(JSON.stringify(n)),new Promise(((e,t)=>{this.promiseCallbackPairs[a]={resolve:e,reject:t}}))}initBDCluster(e,t,s,i,r,a){const n=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,o={action:"initBDCluster",requestID:n,host:e,username:t,password:s,name:i,sm2Key:r,agents:a};return this.wssocket.send(JSON.stringify(o)),new Promise(((e,t)=>{this.promiseCallbackPairs[n]={resolve:e,reject:t}}))}listCompiledFiles(){const e=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,t={action:"listCompiledFiles",requestID:e,isPrivate:!0};return this.wssocket.send(JSON.stringify(t)),new Promise(((t,s)=>{this.promiseCallbackPairs[e]={resolve:t,reject:s}}))}getManagerPubkey(){const e=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,t={action:"getManagerPubkey",requestID:e};return this.wssocket.send(JSON.stringify(t)),new Promise(((t,s)=>{this.promiseCallbackPairs[e]={resolve:t,reject:s}}))}getClusterName(){const e=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,t={action:"getClusterName",requestID:e};return this.wssocket.send(JSON.stringify(t)),new Promise(((t,s)=>{this.promiseCallbackPairs[e]={resolve:t,reject:s}}))}setClusterName(e){const t=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,s={action:"setClusterName",requestID:t,name:e};return this.wssocket.send(JSON.stringify(s)),new Promise(((e,s)=>{this.promiseCallbackPairs[t]={resolve:e,reject:s}}))}},e.WsSocket=h,e.aesEncrypt=o,e.encryptReq=function(e,s){const i={key:t.cryptico.generateAESKey()},r=JSON.stringify(i),{contractID:a}=e,n={...e,contractID:void 0};return{action:s.decrypt(r),contractID:a,arg:o(JSON.stringify(n),i.key),requester:t.cryptico.b256to64(`${s.n.toString(16)},${s.e.toString(16)},0`)}},e.loadRSAKey=function(e){const s=t.cryptico.b64to256(e).split(","),i=new t.RSAKey;return i.setPrivate(s[0],s[0],s[0]),i},e.rsaEncrypt=function(e,s){const i=new t.RSAKey;return i.setPublic(s.n,s.e1),i.encrypt(e)},Object.defineProperty(e,"__esModule",{value:!0})})); -//# sourceMappingURL=index.js.map diff --git a/lib/index.js.map b/lib/index.js.map deleted file mode 100644 index fddf2f1..0000000 --- a/lib/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sources":["../src/crypto.ts","../src/httpClient.ts","../src/wssocket.ts","../src/wsClient.ts"],"sourcesContent":["// export function aesDecrypt(data: base64) {\n// const dataAscii = cryptico.b64to256(data)\n// const encryptedBlocks = cryptico.string2bytes(dataAscii)\n// const exkey = global.aesKey.slice(0)\n// aes.ExpandKey(exkey)\n// aes.Decrypt(encryptedBlocks, exkey)\n// return cryptico.bytes2string(encryptedBlocks)\n// }\n\nimport type { AESKey } from '@daotl/cryptico'\nimport { aes, cryptico, RSAKey } from '@daotl/cryptico'\n\nexport function aesEncrypt(data: string, aesKey: AESKey): string {\n const exkey = aesKey.slice(0)\n aes.ExpandKey(exkey)\n let blocks = cryptico.string2bytes(data)\n blocks = cryptico.pad16(blocks)\n aes.Encrypt(blocks, exkey)\n let ciphertext = cryptico.bytes2string(blocks)\n ciphertext = cryptico.b256to64(ciphertext)\n return ciphertext\n}\n\nexport function rsaEncrypt(\n data: string,\n rsaKey: { n: string; e1: string },\n): string {\n const rsa = new RSAKey()\n rsa.setPublic(rsaKey.n, rsaKey.e1)\n return rsa.encrypt(data)\n}\n\nexport function loadRSAKey(rsaKey: string): RSAKey {\n const str = cryptico.b64to256(rsaKey)\n const strs = str.split(',')\n const key = new RSAKey()\n key.setPrivate(strs[0], strs[0], strs[0])\n return key\n}\n\n// function testRSA() {\n// pubKey = loadRSAKey(global.privKey)\n// reqContent = {}\n// reqContent.action = 'main'\n// reqContent.arg = '[{\"score\":20},{\"score\":20}]'\n// reqContent.contractID = 'abc'\n// eReq = encryptReq(reqContent, pubKey)\n// url =\n// 'http://localhost:8080/SCIDE/SCManager?action=executeContractEncrypted&contractRequest=' +\n// encodeURIComponent(JSON.stringify(eReq))\n// }\n\nexport function encryptReq(\n reqContent: { contractID: string },\n pubKey: RSAKey,\n): {\n action: string | null\n contractID: string\n arg: string\n requester: string\n} {\n const aes = {\n key: cryptico.generateAESKey(),\n }\n const aesObj = JSON.stringify(aes)\n const { contractID } = reqContent\n const reqContentNoId = { ...reqContent, contractID: undefined }\n const encrypedReq = {\n action: pubKey.decrypt(aesObj),\n contractID,\n arg: aesEncrypt(JSON.stringify(reqContentNoId), aes.key),\n requester: cryptico.b256to64(\n `${pubKey.n.toString(16)},${pubKey.e.toString(16)},0`,\n ),\n }\n return encrypedReq\n}\n","import { buildAxiosFetch } from '@lifeomic/axios-fetch'\nimport axios, { type AxiosRequestConfig } from 'axios'\nimport type { KeyPairHex } from 'sm-crypto'\nimport { sm2 } from 'sm-crypto'\n\nimport type {\n ClientResponse,\n ConfigNodeArgs,\n ExecuteContractArgs,\n ListAllUsersResponseData,\n ListNodesResponse,\n ListProjectPermissionRequest,\n ListProjectPermissionResponseData,\n LoadNodeConfigResponseData,\n ExecuteContractResponse,\n PingResponse,\n SaveFileRequest,\n StartContractByYpkRequest,\n} from './types'\n\nconst genUrlParamsFromObject = (obj: Record): string => {\n return Object.entries(obj)\n .map(([key, value]) => `${key}=${String(value)}`)\n .join('&')\n}\n\nexport * from './types'\n\nexport class HttpClient {\n private fetch: (input: RequestInfo, init?: RequestInit) => Promise\n\n constructor(\n private baseUrl: string,\n private sm2Key: KeyPairHex,\n config = {} as AxiosRequestConfig,\n ) {\n const axiosInstance = axios.create({\n baseURL: 'https://some-domain.com/api/',\n timeout: 10000,\n // headers: {'X-Custom-Header': 'foobar'}\n ...config,\n })\n\n this.fetch = buildAxiosFetch(\n axiosInstance /* , function (config) {\n config.timeout = 1000;\n return config;\n } */,\n )\n }\n\n async requestWithSignature(\n path: string,\n init?: Partial,\n sm2Key?: KeyPairHex,\n ): Promise> {\n return new Promise>((resolve, reject) => {\n const rawUrl = this.baseUrl + path\n const url = `${rawUrl}${path.includes('?') ? '&' : '?'}pubKey=${\n sm2Key?.publicKey ?? this.sm2Key.publicKey\n }`\n\n // console.log('privateKey:', this.sm2Key.privateKey)\n\n // console.log('publicKey:', this.sm2Key.publicKey)\n\n // console.log('to sign:', url.substring(url.indexOf('?') + 1))\n\n const sign = this.sign(\n url.substring(url.indexOf('?') + 1),\n sm2Key?.privateKey,\n )\n\n // console.log(\n // 'url:',\n // init?.method?.toLowerCase() === 'post'\n // ? rawUrl\n // : `${encodeURI(url)}&sign=${sign}`,\n // )\n\n this.fetch(\n init?.method?.toLowerCase() === 'post'\n ? rawUrl\n : `${encodeURI(url)}&sign=${sign}`,\n {\n ...init,\n ...(init?.method === 'POST'\n ? {\n body: {\n ...(init?.body as unknown as Record),\n sign,\n } as unknown as Request['body'],\n }\n : {}),\n },\n )\n .then(async (res) => {\n // console.log(res.url,'请求成功')\n const clientRes = res as unknown as ClientResponse\n clientRes.data = (await res.text()) as Data\n // Workaround for the issue causing the 2nd consecutive request to fail:\n // https://github.com/nodejs/undici/issues/1415\n setTimeout(() => {\n resolve(clientRes)\n }, 1)\n })\n .catch((err) => {\n // const clientRes = err as unknown as ClientResponse\n // clientRes.data = (await err.text()) as Data\n // console.log(err,'errerrerrerrerrerrerrerrerrerrerrerrerrerrerr')\n setTimeout(() => {\n reject(err)\n }, 1)\n })\n })\n }\n\n async retryRequestWithSignature(retryTimes: number, path: string, init?: Partial, sm2Key?: KeyPairHex ) {\n let err: Error = new Error()\n for (let i = 0; i(path, init, sm2Key)\n } catch (e) {\n if (i < retryTimes) {\n console.log('1')\n continue\n }\n err = e as Error\n }\n }\n throw err\n }\n\n sign(data: string, privateKey?: string): string {\n return sm2.doSignature(data, privateKey ?? this.sm2Key.privateKey, {\n hash: true,\n der: true,\n })\n }\n\n // ping\n // https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id15\n ping(): Promise {\n return this.requestWithSignature('/SCManager?action=ping')\n }\n\n // 启动合约\n // https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id60\n startContract(code: string): Promise> {\n const params = { action: 'startContract', script: code }\n return this.requestWithSignature(\n `/SCManager?${genUrlParamsFromObject(params)}`,\n )\n }\n\n // 启动合约\n // https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id13\n startContractByYPK(\n _request: StartContractByYpkRequest,\n ): Promise> {\n return this.requestWithSignature(\n `/SCManager?${genUrlParamsFromObject({\n action: 'startContractByYPK',\n ..._request,\n owner: this.sm2Key.publicKey,\n aim: 'onStartContract',\n signature: sm2.doSignature(\n `Fixed|${_request.path}|${this.sm2Key.publicKey}`,\n this.sm2Key.privateKey,\n {\n hash: true,\n der: true,\n },\n ),\n })}`,\n )\n }\n\n // 调用合约\n // https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id69\n executeContract(\n contractID: string,\n operation: string,\n arg: string,\n {\n method = 'POST',\n withDynamicAnalysis = false,\n withSignature = false,\n } = {} as ExecuteContractArgs,\n ): Promise>> {\n let request = {}\n if (withDynamicAnalysis === undefined) {\n request = {\n action: 'executeContract',\n contractID,\n operation,\n arg,\n }\n } else {\n request = {\n action: 'executeContract',\n contractID,\n operation,\n withDynamicAnalysis,\n arg,\n }\n }\n if (withSignature) {\n request = {\n ...request,\n pubkey: this.sm2Key.publicKey,\n signature: this.sign(\n `${contractID}|${operation}|${arg ?? ''}|${this.sm2Key.publicKey}`,\n ),\n }\n }\n\n return this.retryRequestWithSignature(\n 3,\n `/SCManager${\n method === 'GET' ? `?${genUrlParamsFromObject(request)}` : ''\n }`,\n {\n method,\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n ...(method === 'POST' ? ({ body: request } as Request) : {}),\n },\n )\n }\n\n // 停止合约\n // https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id122\n killContractProcess(\n contractID: string,\n requestID?: string,\n ): Promise> {\n const _request: Record = {\n action: 'killContractProcess',\n id: contractID,\n }\n requestID && (_request.requestID = requestID!)\n return this.requestWithSignature(\n `/SCManager?${genUrlParamsFromObject(_request)}`,\n )\n }\n\n // 停止所有合约\n // 地址 http://39.104.205.122:18010/SCIDE\n // https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id131\n killAllContract(): Promise> {\n return this.requestWithSignature('/SCManager?action=killAllContract')\n }\n\n // 申请角色\n // https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html\n applyNodeRole(\n role: string,\n ): Promise> {\n const _request = {\n action: 'applyNodeRole',\n role,\n }\n return this.requestWithSignature(\n `/SCManager?${genUrlParamsFromObject(_request)}`,\n )\n }\n\n // 授权角色\n // https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html\n authNodeRole(\n isAccept: boolean,\n authorizedPubKey: string,\n managerPair?: KeyPairHex,\n ): Promise> {\n const _request = {\n action: 'authNodeRole',\n isAccept,\n authorizedPubKey,\n }\n return this.requestWithSignature(\n `/SCManager?${genUrlParamsFromObject(_request)}`,\n undefined,\n managerPair,\n )\n }\n\n // https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html\n // 用sse获取 问题未解决!!!\n distributeContract(\n nodeIDs: string,\n projectName: string,\n isPrivate: boolean,\n ): void {\n const signature = sm2.doSignature(\n `DistributeContract|${projectName}|${this.sm2Key.publicKey}`,\n this.sm2Key.privateKey,\n { hash: true, der: true },\n )\n\n const _request = {\n action: 'distributeContract',\n nodeIDs,\n projectName,\n isPrivate,\n signature,\n }\n\n const path = `/SCManager?${genUrlParamsFromObject(_request)}`\n const url = `${this.baseUrl + path}${\n path.includes('?') ? '&' : '?'\n }pubKey=${this.sm2Key.publicKey}`\n const sig = sm2.doSignature(\n url.substring(url.indexOf('?') + 1),\n this.sm2Key.privateKey,\n {\n hash: true,\n der: true,\n },\n )\n const source = new EventSource(\n `${this.baseUrl}${path}&pubKey=${this.sm2Key.publicKey}&sign=${sig}`,\n )\n source.addEventListener(\n 'message',\n function (_event) {\n // const data = event.data as DistributeContractResponse[]\n // console.log(data, 'dd')\n // handle message\n },\n false,\n )\n }\n\n saveFile(_request: SaveFileRequest): Promise> {\n return this.requestWithSignature(\n `/SCManager?${genUrlParamsFromObject({\n action: 'saveFile',\n ..._request,\n })}`,\n )\n }\n\n listProjectPermission(\n _request: ListProjectPermissionRequest,\n ): Promise> {\n return this.requestWithSignature(\n `/SCManager?${genUrlParamsFromObject({\n action: 'listProjectPermission',\n ..._request,\n })}`,\n )\n }\n\n startContractMultiPoint(\n peersID: string,\n type: number,\n selectUnitNum: number,\n projectName: string,\n isPrivate: boolean,\n sponsorPeerID: string,\n ): Promise> {\n const _request = {\n // peerID是节点的公钥,以逗号间隔开\n peersID,\n type,\n selectUnitNum,\n projectName,\n isPrivate,\n sponsorPeerID,\n }\n return this.requestWithSignature(\n `/SCManager?${genUrlParamsFromObject({\n action: 'startContractMultiPoint',\n ..._request,\n })}`,\n )\n }\n\n // 获取节点配置信息\n async loadNodeConfig(): Promise> {\n const res = await this.requestWithSignature(\n `/SCManager?${genUrlParamsFromObject({\n action: 'loadNodeConfig',\n })}`,\n )\n return { ...res, data: (res.status === 200 && res.data ? JSON.parse( res.data).data : {}) as LoadNodeConfigResponseData}\n }\n\n // 支持的key包括:{licence,projectDir,yjsPath,dataChain,doipConfig,nodeCenter,nodeName,masterAddress,resetNodeCenterWS}\n async updateConfig(\n key: string,\n val: string,\n ): Promise> {\n return this.requestWithSignature(\n `/SCManager?${genUrlParamsFromObject({\n action: 'updateConfig',\n key,\n val,\n })}`,\n )\n }\n\n // 设置pubkey为node manager\n async resetNodeManager(): Promise {\n const res = await this.requestWithSignature(\n `/SCManager?${genUrlParamsFromObject({\n action: 'resetNodeManager',\n })}`,\n )\n if (!res.data) {\n return false\n }\n const parsed = JSON.parse(res.data)\n return parsed.data === 'success'\n }\n\n // 锁定某个用户的的私有目录编辑功能\n lockEdit(): Promise> {\n return this.requestWithSignature(\n `/SCManager?${genUrlParamsFromObject({\n action: 'lockEdit',\n })}`,\n )\n }\n\n // 解锁某个用户的的私有目录编辑功能\n unlockEdit(): Promise> {\n return this.requestWithSignature(\n `/SCManager?${genUrlParamsFromObject({\n action: 'unlockEdit',\n })}`,\n )\n }\n\n addNode(nodePubKey: string): Promise> {\n return this.requestWithSignature(\n `?${genUrlParamsFromObject({\n action: 'addNode',\n nodePubKey,\n })}`,\n )\n }\n\n // 申请角色\n applyRole(role: string): Promise> {\n return this.requestWithSignature(\n `?${genUrlParamsFromObject({\n action: 'applyRole',\n role,\n })}`,\n )\n }\n\n authNodeManager(\n isAccept: boolean,\n authorizedPubKey: string,\n ): Promise> {\n return this.requestWithSignature(\n `?${genUrlParamsFromObject({\n action: 'authNodeManager',\n isAccept,\n authorizedPubKey,\n })}`,\n )\n }\n\n listAllUsers(): Promise> {\n return this.requestWithSignature(\n `?${genUrlParamsFromObject({\n action: 'listAllUsers',\n })}`,\n )\n }\n\n // 查看节点列表\n listNodes(): Promise {\n return this.requestWithSignature(\n `?${genUrlParamsFromObject({\n action: 'listNodes',\n })}`,\n ) as unknown as Promise\n }\n\n // 建立可信执行集群\n async createTrustUnit(\n data: { nodeName: string; pubkey: string }[],\n Msg: string,\n ): Promise<{ action: string; status: string }> {\n const toSign = `action=createTrustUnit&data=${JSON.stringify(\n data,\n )}&msg=${Msg}&pubKey=04303718771b9323c204e607639f14469f9a94e55b0964a408ad3b3864b0493b645d7070da0d550f0c54b934275a8e88dedc3024467b0566db5c1108b1baeaae27`\n const sig = sm2.doSignature(toSign, this.sm2Key.privateKey, {\n hash: true,\n der: true,\n })\n\n const body = {\n action: 'createTrustUnit',\n data,\n msg: Msg,\n pubKey:\n '04303718771b9323c204e607639f14469f9a94e55b0964a408ad3b3864b0493b645d7070da0d550f0c54b934275a8e88dedc3024467b0566db5c1108b1baeaae27',\n sign: sig,\n }\n return (await this.requestWithSignature('', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(body),\n })) as unknown as { action: string; status: string }\n }\n\n // 查看可信执行集群列表\n listTrustUnits(): Promise> {\n return this.requestWithSignature(\n `?${genUrlParamsFromObject({\n action: 'listTrustUnits',\n })}`,\n )\n }\n\n // listContractProcess 查询合约实例列表\n listContractProcess(): Promise> {\n return this.requestWithSignature(\n `/SCManager?${genUrlParamsFromObject({\n action: 'listContractProcess',\n })}`,\n )\n }\n\n // 下载合约\n downloadContract(\n projectName: string,\n isPrivate: boolean,\n timestamp: number\n ): Promise> {\n const _request = {\n action: 'downloadContract',\n projectName,\n isPrivate,\n timestamp,\n }\n return this.requestWithSignature(\n `/CMManager?${genUrlParamsFromObject(_request)}`)\n }\n\n // 配置合约引擎节点,若节点没有设置过node manager,将当前key设置为node manager\n async configNode(\n args: ConfigNodeArgs,\n ): Promise {\n if (!(await this.resetNodeManager())) {\n return false\n }\n\n const kvs: [string, string][] = Object.entries(args).filter(([_k, v]) => v) as [string, string][]\n\n await Promise.all([\n ...kvs.map(([k, v]) => this.updateConfig(k, v!)),\n this.applyNodeRole('ContractProvider'),\n this.applyNodeRole('ContractUser'),\n this.applyNodeRole('ContractInstanceManager'),\n this.authNodeRole(true, this.sm2Key.publicKey),\n ])\n\n const config = (await this.loadNodeConfig()).data\n if (!config) {\n return false\n }\n\n return kvs.every(([k, v]) => config[remapNodeConfigKey(k)] === v)\n }\n}\n\nfunction remapNodeConfigKey(k: string) {\n switch (k) {\n case 'dataChain':\n return 'bdledger'\n default:\n return k\n }\n}\n","/* eslint-disable no-console,no-cond-assign */\n\nexport interface WsEvent {\n data: string\n}\n\nexport type OnOpenHandler = (this: WebSocket, ev: Event) => void\nexport type WsHandler = (ev: WsEvent, ws?: WebSocket) => void\n\ninterface SegmentData {\n action: 'sendSeg'\n cid: string\n data: string\n}\n\nexport class WsSocket {\n private handlerList: WsHandler[] = []\n private toSend = ''\n private isSending = false\n private sendList: string[] = []\n private toReceive = ''\n private wssocket: WebSocket\n\n constructor(wsurl: string, onopen: OnOpenHandler, handler?: WsHandler) {\n console.log(`[createWS.js] createWssocket : ${wsurl}`)\n if (handler) {\n this.handlerList.push(handler)\n }\n\n // TODO: we don't need monitor at all?\n this.monitor()\n\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const that = this\n\n const wssocket = (this.wssocket = new WebSocket(wsurl))\n wssocket.onerror = function (error): void {\n console.log(error)\n }\n wssocket.onopen = onopen\n\n const onmessage = function (this: WebSocket, event: MessageEvent): void {\n const obj = JSON.parse(event.data as string) as { action: string }\n switch (obj.action) {\n case 'sendNextSegment':\n that.sendNextSegment()\n break\n case 'sendSeg':\n that.receiveSeg(obj as SegmentData)\n break\n default:\n that.handlerList.forEach((h) => h(event, this))\n }\n }\n wssocket.onmessage = onmessage\n\n const reconnect = function (): void {\n setTimeout(() => {\n console.log('[createWS.js] try to reconnect')\n const wssocket = (that.wssocket = new WebSocket(wsurl))\n wssocket.onclose = reconnect\n wssocket.onmessage = onmessage\n wssocket.onopen = onopen\n }, 1000)\n }\n wssocket.onclose = reconnect\n }\n\n status(): WebSocket['CLOSED' | 'CLOSING' | 'CONNECTING' | 'OPEN'] {\n return this.wssocket.readyState\n }\n\n sendNextSegment(): void {\n const str = this.toSend\n if (str.length > 1024) {\n this.toSend = str.substr(1024)\n const obj = {\n isSegment: true,\n data: str.substr(0, 1024),\n }\n this.wssocket.send(JSON.stringify(obj))\n } else {\n this.toSend = ''\n const obj = {\n isSegment: false,\n data: str,\n }\n this.wssocket.send(JSON.stringify(obj))\n this.isSending = false\n let data\n if ((data = this.sendList.pop())) {\n this.send(data)\n }\n }\n }\n\n receiveSeg(obj: SegmentData): void {\n if (obj.cid === 'start') {\n this.toReceive = ''\n }\n this.toReceive += obj.data\n if (obj.cid === 'done') {\n console.log(`[receiveSeg] Received AllData:${this.toReceive}`)\n const event: WsEvent = {\n data: this.toReceive,\n }\n this.toReceive = ''\n this.handlerList.forEach((h) => h(event, this.wssocket))\n }\n }\n\n monitor(): void {\n if (!this.isSending) {\n let data\n if ((data = this.sendList.pop())) {\n this.send(data)\n }\n }\n setTimeout(() => this.monitor(), 1000)\n }\n\n send(data: string): void {\n if (this.isSending) {\n this.sendList.push(data)\n return\n }\n if (data.length > 1024) {\n this.isSending = true\n this.toSend = data.substr(1024)\n const obj = {\n isSegment: true,\n data: data.substr(0, 1024),\n }\n this.wssocket.send(JSON.stringify(obj))\n } else {\n this.wssocket.send(data)\n }\n }\n\n addHandler(handler: WsHandler): void {\n this.handlerList.push(handler)\n }\n}\n","/* eslint-disable no-cond-assign */\n\nimport type { KeyPairHex } from 'sm-crypto'\nimport { sm2 } from 'sm-crypto'\n\nimport type { OnOpenHandler, WsHandler } from './wssocket'\nimport { WsSocket } from './wssocket'\n\ninterface ResponseData {\n action: string\n responseID?: string\n status: true | false | string // 'Success' | 'Exception' | 'Error' | 'failed: no session'\n result?: unknown\n data: string\n [K: string]: unknown\n}\n\n// interface ListResponseData {\n// action: string\n// data: string\n// status: true | false\n// }\n\ninterface PromiseCallbackPair {\n resolve: (value: ResponseData | PromiseLike) => void\n reject: (reason?: unknown) => void\n}\n\nexport class WsClient {\n private readonly sm2Key: KeyPairHex\n private readonly wssocket: WsSocket\n private readonly promiseCallbackPairs: Record =\n {}\n\n private readonly sessionPromise: Promise\n private sessionResolve!: (value: string | PromiseLike) => void\n private readonly loginPromise: Promise\n private loginResolve!: (value: boolean | PromiseLike) => void\n\n constructor(\n url: string,\n onopen: OnOpenHandler,\n handler: WsHandler,\n sm2Key: KeyPairHex = sm2.generateKeyPairHex(),\n ) {\n this.sm2Key = sm2Key\n this.sessionPromise = new Promise((resolve, _reject) => {\n this.sessionResolve = resolve\n })\n this.loginPromise = new Promise((resolve, _reject) => {\n this.loginResolve = resolve\n })\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const that = this\n this.wssocket = new WsSocket(url, onopen, function (\n this: WebSocket,\n event,\n _,\n ) {\n const data = JSON.parse(event.data) as ResponseData\n\n switch (data.action) {\n case 'onSessionID':\n that.sessionResolve(data.session as string)\n break\n case 'onLogin':\n {\n const failed =\n typeof data.status === 'string' &&\n data.status.toLowerCase().includes('failed')\n that.loginResolve(!failed)\n }\n break\n }\n\n const reqId = data.responseID\n let pc: PromiseCallbackPair | undefined\n if (reqId && (pc = that.promiseCallbackPairs[reqId])) {\n if (data) {\n pc.resolve(data)\n } else {\n pc.reject(data)\n }\n }\n handler(event, this)\n })\n }\n\n status(): WebSocket['CLOSED' | 'CLOSING' | 'CONNECTING' | 'OPEN'] {\n return this.wssocket.status()\n }\n\n sessionReceived(): Promise {\n return this.sessionPromise\n }\n\n async login(): Promise {\n const session = await this.sessionPromise\n const request = {\n action: 'login',\n pubKey: this.sm2Key.publicKey,\n signature: sm2.doSignature(session, this.sm2Key.privateKey, {\n hash: true,\n der: true,\n }),\n }\n this.wssocket.send(JSON.stringify(request))\n return this.loginPromise\n }\n\n loggedIn(): Promise {\n return this.loginPromise\n }\n\n matchCID(contractID: string): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'matchCID',\n contractID,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n getMetabyCID(contractID: string): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'getMetabyCID',\n contractID,\n requestID,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n getMetabyReadme(\n keyword: string,\n page?: string,\n pageSize?: string,\n ): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'getMetabyReadme',\n page,\n pageSize,\n keyword,\n requestID,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n getMetabyPubkey(pubkey: string): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'getMetabyPubkey',\n pubkey,\n requestID,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n segmentWord(words: string): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n words,\n action: 'segmentWord',\n requestID,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n getMetabyOwner(\n owner: string,\n page?: string,\n pageSize?: string,\n ): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'getMetabyOwner',\n owner,\n page,\n pageSize,\n requestID,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n getDependentContract(contractName: string): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'getDependentContract',\n requestID,\n contractName,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n queryContractLogByDate(start: number): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'queryContractLogByDate',\n requestID,\n start,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n queryDataByHash(hash: string): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'queryDataByHash',\n requestID,\n hash,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n executeContract(\n contractID: string,\n method: string,\n arg: unknown,\n ): Promise {\n const sm2Key = this.sm2Key\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const argStr = (typeof arg) == 'object' ? JSON.stringify(arg):arg+\"\";\n const request = {\n action: 'executeContract',\n requestID,\n contractID,\n operation: method,\n arg: arg,\n ...(sm2Key\n ? {\n pubkey: sm2Key.publicKey,\n signature: sm2.doSignature(\n `${contractID}|${method}|${argStr}|${sm2Key.publicKey}`,\n sm2Key.privateKey,\n { hash: true, der: true },\n ),\n }\n : {}),\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n getSessionID(): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'getSessionID',\n requestID,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n listTheContractProcess(contractID: string): Promise {\n const sm2Key = this.sm2Key\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'listTheContractProcess',\n requestID,\n contractID,\n ...(sm2Key\n ? {\n pubkey: sm2Key.publicKey,\n signature: sm2.doSignature(\n `${contractID}|${sm2Key.publicKey}`,\n sm2Key.privateKey,\n { hash: true, der: true },\n ),\n }\n : {}),\n }\n this.wssocket.send(JSON.stringify(request))\n\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n getMask(\n contractID: string,\n // operation: string,\n ): Promise {\n const sm2Key = this.sm2Key\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'getMask',\n requestID,\n contractID,\n // operation,\n ...(sm2Key\n ? {\n pubkey: sm2Key.publicKey,\n signature: sm2.doSignature(\n `${contractID}|${sm2Key.publicKey}`,\n sm2Key.privateKey,\n { hash: true, der: true },\n ),\n }\n : {}),\n }\n\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n setMask(\n contractID: string,\n operation: string,\n arg: string,\n ): Promise {\n const sm2Key = this.sm2Key\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'setMask',\n requestID,\n contractID,\n operation,\n arg,\n ...(sm2Key\n ? {\n pubkey: sm2Key.publicKey,\n signature: sm2.doSignature(\n `${contractID}|${sm2Key.publicKey}`,\n sm2Key.privateKey,\n { hash: true, der: true },\n ),\n }\n : {}),\n }\n\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n getMock(\n contractID: string,\n // operation: string,\n ): Promise {\n const sm2Key = this.sm2Key\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'getMock',\n requestID,\n contractID,\n // operation,\n ...(sm2Key\n ? {\n pubkey: sm2Key.publicKey,\n signature: sm2.doSignature(\n `${contractID}|${sm2Key.publicKey}`,\n sm2Key.privateKey,\n { hash: true, der: true },\n ),\n }\n : {}),\n }\n\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n setMock(\n contractID: string,\n operation: string,\n arg: string,\n ): Promise {\n const sm2Key = this.sm2Key\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'setMock',\n requestID,\n contractID,\n operation,\n arg,\n ...(sm2Key\n ? {\n pubkey: sm2Key.publicKey,\n signature: sm2.doSignature(\n `${contractID}|${sm2Key.publicKey}`,\n sm2Key.privateKey,\n { hash: true, der: true },\n ),\n }\n : {}),\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n queryHashByOffset(offset: number, count: number): Promise {\n const sm2Key = this.sm2Key\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'queryHashByOffset',\n requestID,\n offset,\n count,\n ...(sm2Key\n ? {\n pubkey: sm2Key.publicKey,\n /* signature: sm2.doSignature(\n id + '|' + sm2Key.publicKey,\n sm2Key.privateKey,\n { hash: true, der: true },\n ), */\n }\n : {}),\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n loadNodeConfig(): Promise {\n const sm2Key = this.sm2Key\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'loadNodeConfig',\n requestID,\n\n ...(sm2Key\n ? {\n pubkey: sm2Key.publicKey,\n signature: sm2.doSignature(sm2Key.publicKey, sm2Key.privateKey, {\n hash: true,\n der: true,\n }),\n }\n : {}),\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n queryUserStat(): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'queryUserStat',\n requestID,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n listNodes(): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'listNodes',\n requestID,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n killContractProcess(id: string): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'killContractProcess',\n requestID,\n id,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n distributeYPK(projectName: string, nodeIDs: string): Promise {\n const sm2Key = this.sm2Key\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'distributeYPK',\n requestID,\n pubKey: sm2Key.publicKey,\n projectName,\n nodeIDs,\n signature: sm2.doSignature(\n `DistributeYPK|${projectName}|${sm2Key.publicKey}`,\n sm2Key.privateKey,\n { hash: true, der: true },\n ),\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n listYPKs(): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'listYPKs',\n requestID,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n deleteFile(file: string): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'deleteFile',\n requestID,\n file,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n startContractByYPK(project: string): Promise {\n const sm2Key = this.sm2Key\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'startContractByYPK',\n isPrivate: true,\n requestID,\n owner: sm2Key.publicKey,\n path: `/${project}`,\n signature: sm2.doSignature(\n `Fixed|${project}|${sm2Key.publicKey}`,\n sm2Key.privateKey,\n ),\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n initBDServer(\n host: string,\n username: string,\n password: string,\n name: string,\n clusterHost: string,\n ): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'initBDServer',\n requestID,\n host,\n username,\n password,\n name,\n sm2Key: JSON.stringify(this.sm2Key),\n clusterHost,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n initBDCluster(\n host: string,\n username: string,\n password: string,\n name: string,\n sm2Key: string,\n agents: [],\n ): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'initBDCluster',\n requestID,\n host,\n username,\n password,\n name,\n sm2Key,\n agents,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n listCompiledFiles(): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'listCompiledFiles',\n requestID,\n isPrivate: true,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n getManagerPubkey(): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'getManagerPubkey',\n requestID,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n getClusterName(): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'getClusterName',\n requestID,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n setClusterName(name: string): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'setClusterName',\n requestID,\n name,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n}\n"],"names":["aesEncrypt","data","aesKey","exkey","slice","aes","ExpandKey","blocks","cryptico","string2bytes","pad16","Encrypt","ciphertext","bytes2string","b256to64","genUrlParamsFromObject","obj","Object","entries","map","key","value","String","join","WsSocket","handlerList","toSend","isSending","sendList","toReceive","wssocket","constructor","wsurl","onopen","handler","console","log","this","push","monitor","that","WebSocket","onerror","error","onmessage","event","JSON","parse","action","sendNextSegment","receiveSeg","forEach","h","reconnect","setTimeout","onclose","status","readyState","str","length","substr","isSegment","send","stringify","pop","cid","addHandler","baseUrl","sm2Key","fetch","config","axiosInstance","axios","create","baseURL","timeout","buildAxiosFetch","async","path","init","Promise","resolve","reject","rawUrl","url","includes","publicKey","sign","substring","indexOf","privateKey","method","toLowerCase","encodeURI","body","then","res","clientRes","text","catch","err","retryTimes","Error","i","requestWithSignature","e","sm2","doSignature","hash","der","ping","startContract","code","params","script","startContractByYPK","_request","owner","aim","signature","executeContract","contractID","operation","arg","withDynamicAnalysis","withSignature","request","undefined","pubkey","retryRequestWithSignature","killContractProcess","requestID","id","killAllContract","applyNodeRole","role","authNodeRole","isAccept","authorizedPubKey","managerPair","distributeContract","nodeIDs","projectName","isPrivate","sig","EventSource","addEventListener","_event","saveFile","listProjectPermission","startContractMultiPoint","peersID","type","selectUnitNum","sponsorPeerID","val","lockEdit","unlockEdit","addNode","nodePubKey","applyRole","authNodeManager","listAllUsers","listNodes","Msg","toSign","msg","pubKey","headers","listTrustUnits","listContractProcess","downloadContract","timestamp","args","resetNodeManager","kvs","filter","_k","v","all","k","updateConfig","loadNodeConfig","every","remapNodeConfigKey","promiseCallbackPairs","sessionPromise","sessionResolve","loginPromise","loginResolve","generateKeyPairHex","_reject","_","session","failed","reqId","responseID","pc","sessionReceived","loggedIn","matchCID","Date","getTime","Math","floor","random","getMetabyCID","getMetabyReadme","keyword","page","pageSize","getMetabyPubkey","segmentWord","words","getMetabyOwner","getDependentContract","contractName","queryContractLogByDate","start","queryDataByHash","argStr","getSessionID","listTheContractProcess","getMask","setMask","getMock","setMock","queryHashByOffset","offset","count","queryUserStat","distributeYPK","listYPKs","deleteFile","file","project","initBDServer","host","username","password","name","clusterHost","initBDCluster","agents","listCompiledFiles","getManagerPubkey","getClusterName","setClusterName","reqContent","generateAESKey","aesObj","reqContentNoId","decrypt","requester","n","toString","rsaKey","strs","b64to256","split","RSAKey","setPrivate","rsa","setPublic","e1","encrypt"],"mappings":"whBAYgB,SAAAA,EAAWC,EAAcC,GACvC,MAAMC,EAAQD,EAAOE,MAAM,GAC3BC,MAAIC,UAAUH,GACd,IAAII,EAASC,EAAAA,SAASC,aAAaR,GACnCM,EAASC,EAAQA,SAACE,MAAMH,GACxBF,EAAAA,IAAIM,QAAQJ,EAAQJ,GACpB,IAAIS,EAAaJ,EAAAA,SAASK,aAAaN,GAEvC,OADAK,EAAaJ,EAAQA,SAACM,SAASF,GACxBA,CACT,CCDA,MAAMG,EAA0BC,GACvBC,OAAOC,QAAQF,GACnBG,KAAI,EAAEC,EAAKC,KAAW,GAAGD,KAAOE,OAAOD,OACvCE,KAAK,WCRGC,EACHC,YAA2B,GAC3BC,OAAS,GACTC,WAAY,EACZC,SAAqB,GACrBC,UAAY,GACZC,SAERC,YAAYC,EAAeC,EAAuBC,GAChDC,QAAQC,IAAI,kCAAkCJ,KAC1CE,GACFG,KAAKZ,YAAYa,KAAKJ,GAIxBG,KAAKE,UAGL,MAAMC,EAAOH,KAEPP,EAAYO,KAAKP,SAAW,IAAIW,UAAUT,GAChDF,EAASY,QAAU,SAAUC,GAC3BR,QAAQC,IAAIO,EACd,EACAb,EAASG,OAASA,EAElB,MAAMW,EAAY,SAA2BC,GAC3C,MAAM7B,EAAM8B,KAAKC,MAAMF,EAAM5C,MAC7B,OAAQe,EAAIgC,QACV,IAAK,kBACHR,EAAKS,kBACL,MACF,IAAK,UACHT,EAAKU,WAAWlC,GAChB,MACF,QACEwB,EAAKf,YAAY0B,SAASC,GAAMA,EAAEP,EAAOR,QAE/C,EACAP,EAASc,UAAYA,EAErB,MAAMS,EAAY,WAChBC,YAAW,KACTnB,QAAQC,IAAI,kCACZ,MAAMN,EAAYU,EAAKV,SAAW,IAAIW,UAAUT,GAChDF,EAASyB,QAAUF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AqBC,GACzB,MACMC,EADMzP,EAAAA,SAAS0P,SAASF,GACbG,MAAM,KACjB/O,EAAM,IAAIgP,EAAAA,OAEhB,OADAhP,EAAIiP,WAAWJ,EAAK,GAAIA,EAAK,GAAIA,EAAK,IAC/B7O,CACT,eAfgB,SACdnB,EACA+P,GAEA,MAAMM,EAAM,IAAIF,EAAAA,OAEhB,OADAE,EAAIC,UAAUP,EAAOF,EAAGE,EAAOQ,IACxBF,EAAIG,QAAQxQ,EACrB"} \ No newline at end of file diff --git a/lib/index.mjs b/lib/index.mjs deleted file mode 100644 index 96bc5b6..0000000 --- a/lib/index.mjs +++ /dev/null @@ -1,2 +0,0 @@ -import{aes as e,cryptico as t,RSAKey as s}from"@daotl/cryptico";import{buildAxiosFetch as i}from"@lifeomic/axios-fetch";import r from"axios";import{sm2 as a}from"sm-crypto";function n(s,i){const r=i.slice(0);e.ExpandKey(r);let a=t.string2bytes(s);a=t.pad16(a),e.Encrypt(a,r);let n=t.bytes2string(a);return n=t.b256to64(n),n}function o(e,t){const i=new s;return i.setPublic(t.n,t.e1),i.encrypt(e)}function c(e){const i=t.b64to256(e).split(","),r=new s;return r.setPrivate(i[0],i[0],i[0]),r}function h(e,s){const i={key:t.generateAESKey()},r=JSON.stringify(i),{contractID:a}=e,o={...e,contractID:void 0};return{action:s.decrypt(r),contractID:a,arg:n(JSON.stringify(o),i.key),requester:t.b256to64(`${s.n.toString(16)},${s.e.toString(16)},0`)}}const u=e=>Object.entries(e).map((([e,t])=>`${e}=${String(t)}`)).join("&");class l{baseUrl;sm2Key;fetch;constructor(e,t,s={}){this.baseUrl=e,this.sm2Key=t;const a=r.create({baseURL:"https://some-domain.com/api/",timeout:1e4,...s});this.fetch=i(a)}async requestWithSignature(e,t,s){return new Promise(((i,r)=>{const a=this.baseUrl+e,n=`${a}${e.includes("?")?"&":"?"}pubKey=${s?.publicKey??this.sm2Key.publicKey}`,o=this.sign(n.substring(n.indexOf("?")+1),s?.privateKey);this.fetch("post"===t?.method?.toLowerCase()?a:`${encodeURI(n)}&sign=${o}`,{...t,..."POST"===t?.method?{body:{...t?.body,sign:o}}:{}}).then((async e=>{const t=e;t.data=await e.text(),setTimeout((()=>{i(t)}),1)})).catch((e=>{setTimeout((()=>{r(e)}),1)}))}))}async retryRequestWithSignature(e,t,s,i){let r=new Error;for(let a=0;at));await Promise.all([...t.map((([e,t])=>this.updateConfig(e,t))),this.applyNodeRole("ContractProvider"),this.applyNodeRole("ContractUser"),this.applyNodeRole("ContractInstanceManager"),this.authNodeRole(!0,this.sm2Key.publicKey)]);const s=(await this.loadNodeConfig()).data;return!!s&&t.every((([e,t])=>s[function(e){if("dataChain"===e)return"bdledger";return e}(e)]===t))}}class d{handlerList=[];toSend="";isSending=!1;sendList=[];toReceive="";wssocket;constructor(e,t,s){console.log(`[createWS.js] createWssocket : ${e}`),s&&this.handlerList.push(s),this.monitor();const i=this,r=this.wssocket=new WebSocket(e);r.onerror=function(e){console.log(e)},r.onopen=t;const a=function(e){const t=JSON.parse(e.data);switch(t.action){case"sendNextSegment":i.sendNextSegment();break;case"sendSeg":i.receiveSeg(t);break;default:i.handlerList.forEach((t=>t(e,this)))}};r.onmessage=a;const n=function(){setTimeout((()=>{console.log("[createWS.js] try to reconnect");const s=i.wssocket=new WebSocket(e);s.onclose=n,s.onmessage=a,s.onopen=t}),1e3)};r.onclose=n}status(){return this.wssocket.readyState}sendNextSegment(){const e=this.toSend;if(e.length>1024){this.toSend=e.substr(1024);const t={isSegment:!0,data:e.substr(0,1024)};this.wssocket.send(JSON.stringify(t))}else{this.toSend="";const t={isSegment:!1,data:e};let s;this.wssocket.send(JSON.stringify(t)),this.isSending=!1,(s=this.sendList.pop())&&this.send(s)}}receiveSeg(e){if("start"===e.cid&&(this.toReceive=""),this.toReceive+=e.data,"done"===e.cid){console.log(`[receiveSeg] Received AllData:${this.toReceive}`);const e={data:this.toReceive};this.toReceive="",this.handlerList.forEach((t=>t(e,this.wssocket)))}}monitor(){if(!this.isSending){let e;(e=this.sendList.pop())&&this.send(e)}setTimeout((()=>this.monitor()),1e3)}send(e){if(this.isSending)this.sendList.push(e);else if(e.length>1024){this.isSending=!0,this.toSend=e.substr(1024);const t={isSegment:!0,data:e.substr(0,1024)};this.wssocket.send(JSON.stringify(t))}else this.wssocket.send(e)}addHandler(e){this.handlerList.push(e)}}class g{sm2Key;wssocket;promiseCallbackPairs={};sessionPromise;sessionResolve;loginPromise;loginResolve;constructor(e,t,s,i=a.generateKeyPairHex()){this.sm2Key=i,this.sessionPromise=new Promise(((e,t)=>{this.sessionResolve=e})),this.loginPromise=new Promise(((e,t)=>{this.loginResolve=e}));const r=this;this.wssocket=new d(e,t,(function(e,t){const i=JSON.parse(e.data);switch(i.action){case"onSessionID":r.sessionResolve(i.session);break;case"onLogin":{const e="string"==typeof i.status&&i.status.toLowerCase().includes("failed");r.loginResolve(!e)}}const a=i.responseID;let n;a&&(n=r.promiseCallbackPairs[a])&&(i?n.resolve(i):n.reject(i)),s(e,this)}))}status(){return this.wssocket.status()}sessionReceived(){return this.sessionPromise}async login(){const e=await this.sessionPromise,t={action:"login",pubKey:this.sm2Key.publicKey,signature:a.doSignature(e,this.sm2Key.privateKey,{hash:!0,der:!0})};return this.wssocket.send(JSON.stringify(t)),this.loginPromise}loggedIn(){return this.loginPromise}matchCID(e){const t=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,s={action:"matchCID",contractID:e};return this.wssocket.send(JSON.stringify(s)),new Promise(((e,s)=>{this.promiseCallbackPairs[t]={resolve:e,reject:s}}))}getMetabyCID(e){const t=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,s={action:"getMetabyCID",contractID:e,requestID:t};return this.wssocket.send(JSON.stringify(s)),new Promise(((e,s)=>{this.promiseCallbackPairs[t]={resolve:e,reject:s}}))}getMetabyReadme(e,t,s){const i=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,r={action:"getMetabyReadme",page:t,pageSize:s,keyword:e,requestID:i};return this.wssocket.send(JSON.stringify(r)),new Promise(((e,t)=>{this.promiseCallbackPairs[i]={resolve:e,reject:t}}))}getMetabyPubkey(e){const t=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,s={action:"getMetabyPubkey",pubkey:e,requestID:t};return this.wssocket.send(JSON.stringify(s)),new Promise(((e,s)=>{this.promiseCallbackPairs[t]={resolve:e,reject:s}}))}segmentWord(e){const t=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,s={words:e,action:"segmentWord",requestID:t};return this.wssocket.send(JSON.stringify(s)),new Promise(((e,s)=>{this.promiseCallbackPairs[t]={resolve:e,reject:s}}))}getMetabyOwner(e,t,s){const i=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,r={action:"getMetabyOwner",owner:e,page:t,pageSize:s,requestID:i};return this.wssocket.send(JSON.stringify(r)),new Promise(((e,t)=>{this.promiseCallbackPairs[i]={resolve:e,reject:t}}))}getDependentContract(e){const t=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,s={action:"getDependentContract",requestID:t,contractName:e};return this.wssocket.send(JSON.stringify(s)),new Promise(((e,s)=>{this.promiseCallbackPairs[t]={resolve:e,reject:s}}))}queryContractLogByDate(e){const t=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,s={action:"queryContractLogByDate",requestID:t,start:e};return this.wssocket.send(JSON.stringify(s)),new Promise(((e,s)=>{this.promiseCallbackPairs[t]={resolve:e,reject:s}}))}queryDataByHash(e){const t=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,s={action:"queryDataByHash",requestID:t,hash:e};return this.wssocket.send(JSON.stringify(s)),new Promise(((e,s)=>{this.promiseCallbackPairs[t]={resolve:e,reject:s}}))}executeContract(e,t,s){const i=this.sm2Key,r=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,n="object"==typeof s?JSON.stringify(s):s+"",o={action:"executeContract",requestID:r,contractID:e,operation:t,arg:s,...i?{pubkey:i.publicKey,signature:a.doSignature(`${e}|${t}|${n}|${i.publicKey}`,i.privateKey,{hash:!0,der:!0})}:{}};return this.wssocket.send(JSON.stringify(o)),new Promise(((e,t)=>{this.promiseCallbackPairs[r]={resolve:e,reject:t}}))}getSessionID(){const e=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,t={action:"getSessionID",requestID:e};return this.wssocket.send(JSON.stringify(t)),new Promise(((t,s)=>{this.promiseCallbackPairs[e]={resolve:t,reject:s}}))}listTheContractProcess(e){const t=this.sm2Key,s=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,i={action:"listTheContractProcess",requestID:s,contractID:e,...t?{pubkey:t.publicKey,signature:a.doSignature(`${e}|${t.publicKey}`,t.privateKey,{hash:!0,der:!0})}:{}};return this.wssocket.send(JSON.stringify(i)),new Promise(((e,t)=>{this.promiseCallbackPairs[s]={resolve:e,reject:t}}))}getMask(e){const t=this.sm2Key,s=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,i={action:"getMask",requestID:s,contractID:e,...t?{pubkey:t.publicKey,signature:a.doSignature(`${e}|${t.publicKey}`,t.privateKey,{hash:!0,der:!0})}:{}};return this.wssocket.send(JSON.stringify(i)),new Promise(((e,t)=>{this.promiseCallbackPairs[s]={resolve:e,reject:t}}))}setMask(e,t,s){const i=this.sm2Key,r=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,n={action:"setMask",requestID:r,contractID:e,operation:t,arg:s,...i?{pubkey:i.publicKey,signature:a.doSignature(`${e}|${i.publicKey}`,i.privateKey,{hash:!0,der:!0})}:{}};return this.wssocket.send(JSON.stringify(n)),new Promise(((e,t)=>{this.promiseCallbackPairs[r]={resolve:e,reject:t}}))}getMock(e){const t=this.sm2Key,s=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,i={action:"getMock",requestID:s,contractID:e,...t?{pubkey:t.publicKey,signature:a.doSignature(`${e}|${t.publicKey}`,t.privateKey,{hash:!0,der:!0})}:{}};return this.wssocket.send(JSON.stringify(i)),new Promise(((e,t)=>{this.promiseCallbackPairs[s]={resolve:e,reject:t}}))}setMock(e,t,s){const i=this.sm2Key,r=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,n={action:"setMock",requestID:r,contractID:e,operation:t,arg:s,...i?{pubkey:i.publicKey,signature:a.doSignature(`${e}|${i.publicKey}`,i.privateKey,{hash:!0,der:!0})}:{}};return this.wssocket.send(JSON.stringify(n)),new Promise(((e,t)=>{this.promiseCallbackPairs[r]={resolve:e,reject:t}}))}queryHashByOffset(e,t){const s=this.sm2Key,i=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,r={action:"queryHashByOffset",requestID:i,offset:e,count:t,...s?{pubkey:s.publicKey}:{}};return this.wssocket.send(JSON.stringify(r)),new Promise(((e,t)=>{this.promiseCallbackPairs[i]={resolve:e,reject:t}}))}loadNodeConfig(){const e=this.sm2Key,t=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,s={action:"loadNodeConfig",requestID:t,...e?{pubkey:e.publicKey,signature:a.doSignature(e.publicKey,e.privateKey,{hash:!0,der:!0})}:{}};return this.wssocket.send(JSON.stringify(s)),new Promise(((e,s)=>{this.promiseCallbackPairs[t]={resolve:e,reject:s}}))}queryUserStat(){const e=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,t={action:"queryUserStat",requestID:e};return this.wssocket.send(JSON.stringify(t)),new Promise(((t,s)=>{this.promiseCallbackPairs[e]={resolve:t,reject:s}}))}listNodes(){const e=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,t={action:"listNodes",requestID:e};return this.wssocket.send(JSON.stringify(t)),new Promise(((t,s)=>{this.promiseCallbackPairs[e]={resolve:t,reject:s}}))}killContractProcess(e){const t=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,s={action:"killContractProcess",requestID:t,id:e};return this.wssocket.send(JSON.stringify(s)),new Promise(((e,s)=>{this.promiseCallbackPairs[t]={resolve:e,reject:s}}))}distributeYPK(e,t){const s=this.sm2Key,i=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,r={action:"distributeYPK",requestID:i,pubKey:s.publicKey,projectName:e,nodeIDs:t,signature:a.doSignature(`DistributeYPK|${e}|${s.publicKey}`,s.privateKey,{hash:!0,der:!0})};return this.wssocket.send(JSON.stringify(r)),new Promise(((e,t)=>{this.promiseCallbackPairs[i]={resolve:e,reject:t}}))}listYPKs(){const e=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,t={action:"listYPKs",requestID:e};return this.wssocket.send(JSON.stringify(t)),new Promise(((t,s)=>{this.promiseCallbackPairs[e]={resolve:t,reject:s}}))}deleteFile(e){const t=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,s={action:"deleteFile",requestID:t,file:e};return this.wssocket.send(JSON.stringify(s)),new Promise(((e,s)=>{this.promiseCallbackPairs[t]={resolve:e,reject:s}}))}startContractByYPK(e){const t=this.sm2Key,s=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,i={action:"startContractByYPK",isPrivate:!0,requestID:s,owner:t.publicKey,path:`/${e}`,signature:a.doSignature(`Fixed|${e}|${t.publicKey}`,t.privateKey)};return this.wssocket.send(JSON.stringify(i)),new Promise(((e,t)=>{this.promiseCallbackPairs[s]={resolve:e,reject:t}}))}initBDServer(e,t,s,i,r){const a=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,n={action:"initBDServer",requestID:a,host:e,username:t,password:s,name:i,sm2Key:JSON.stringify(this.sm2Key),clusterHost:r};return this.wssocket.send(JSON.stringify(n)),new Promise(((e,t)=>{this.promiseCallbackPairs[a]={resolve:e,reject:t}}))}initBDCluster(e,t,s,i,r,a){const n=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,o={action:"initBDCluster",requestID:n,host:e,username:t,password:s,name:i,sm2Key:r,agents:a};return this.wssocket.send(JSON.stringify(o)),new Promise(((e,t)=>{this.promiseCallbackPairs[n]={resolve:e,reject:t}}))}listCompiledFiles(){const e=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,t={action:"listCompiledFiles",requestID:e,isPrivate:!0};return this.wssocket.send(JSON.stringify(t)),new Promise(((t,s)=>{this.promiseCallbackPairs[e]={resolve:t,reject:s}}))}getManagerPubkey(){const e=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,t={action:"getManagerPubkey",requestID:e};return this.wssocket.send(JSON.stringify(t)),new Promise(((t,s)=>{this.promiseCallbackPairs[e]={resolve:t,reject:s}}))}getClusterName(){const e=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,t={action:"getClusterName",requestID:e};return this.wssocket.send(JSON.stringify(t)),new Promise(((t,s)=>{this.promiseCallbackPairs[e]={resolve:t,reject:s}}))}setClusterName(e){const t=`${(new Date).getTime()}_${Math.floor(1e4*Math.random())}`,s={action:"setClusterName",requestID:t,name:e};return this.wssocket.send(JSON.stringify(s)),new Promise(((e,s)=>{this.promiseCallbackPairs[t]={resolve:e,reject:s}}))}}export{l as HttpClient,g as WsClient,d as WsSocket,n as aesEncrypt,h as encryptReq,c as loadRSAKey,o as rsaEncrypt}; -//# sourceMappingURL=index.mjs.map diff --git a/lib/index.mjs.map b/lib/index.mjs.map deleted file mode 100644 index a9e2415..0000000 --- a/lib/index.mjs.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.mjs","sources":["../src/crypto.ts","../src/httpClient.ts","../src/wssocket.ts","../src/wsClient.ts"],"sourcesContent":["// export function aesDecrypt(data: base64) {\n// const dataAscii = cryptico.b64to256(data)\n// const encryptedBlocks = cryptico.string2bytes(dataAscii)\n// const exkey = global.aesKey.slice(0)\n// aes.ExpandKey(exkey)\n// aes.Decrypt(encryptedBlocks, exkey)\n// return cryptico.bytes2string(encryptedBlocks)\n// }\n\nimport type { AESKey } from '@daotl/cryptico'\nimport { aes, cryptico, RSAKey } from '@daotl/cryptico'\n\nexport function aesEncrypt(data: string, aesKey: AESKey): string {\n const exkey = aesKey.slice(0)\n aes.ExpandKey(exkey)\n let blocks = cryptico.string2bytes(data)\n blocks = cryptico.pad16(blocks)\n aes.Encrypt(blocks, exkey)\n let ciphertext = cryptico.bytes2string(blocks)\n ciphertext = cryptico.b256to64(ciphertext)\n return ciphertext\n}\n\nexport function rsaEncrypt(\n data: string,\n rsaKey: { n: string; e1: string },\n): string {\n const rsa = new RSAKey()\n rsa.setPublic(rsaKey.n, rsaKey.e1)\n return rsa.encrypt(data)\n}\n\nexport function loadRSAKey(rsaKey: string): RSAKey {\n const str = cryptico.b64to256(rsaKey)\n const strs = str.split(',')\n const key = new RSAKey()\n key.setPrivate(strs[0], strs[0], strs[0])\n return key\n}\n\n// function testRSA() {\n// pubKey = loadRSAKey(global.privKey)\n// reqContent = {}\n// reqContent.action = 'main'\n// reqContent.arg = '[{\"score\":20},{\"score\":20}]'\n// reqContent.contractID = 'abc'\n// eReq = encryptReq(reqContent, pubKey)\n// url =\n// 'http://localhost:8080/SCIDE/SCManager?action=executeContractEncrypted&contractRequest=' +\n// encodeURIComponent(JSON.stringify(eReq))\n// }\n\nexport function encryptReq(\n reqContent: { contractID: string },\n pubKey: RSAKey,\n): {\n action: string | null\n contractID: string\n arg: string\n requester: string\n} {\n const aes = {\n key: cryptico.generateAESKey(),\n }\n const aesObj = JSON.stringify(aes)\n const { contractID } = reqContent\n const reqContentNoId = { ...reqContent, contractID: undefined }\n const encrypedReq = {\n action: pubKey.decrypt(aesObj),\n contractID,\n arg: aesEncrypt(JSON.stringify(reqContentNoId), aes.key),\n requester: cryptico.b256to64(\n `${pubKey.n.toString(16)},${pubKey.e.toString(16)},0`,\n ),\n }\n return encrypedReq\n}\n","import { buildAxiosFetch } from '@lifeomic/axios-fetch'\nimport axios, { type AxiosRequestConfig } from 'axios'\nimport type { KeyPairHex } from 'sm-crypto'\nimport { sm2 } from 'sm-crypto'\n\nimport type {\n ClientResponse,\n ConfigNodeArgs,\n ExecuteContractArgs,\n ListAllUsersResponseData,\n ListNodesResponse,\n ListProjectPermissionRequest,\n ListProjectPermissionResponseData,\n LoadNodeConfigResponseData,\n ExecuteContractResponse,\n PingResponse,\n SaveFileRequest,\n StartContractByYpkRequest,\n} from './types'\n\nconst genUrlParamsFromObject = (obj: Record): string => {\n return Object.entries(obj)\n .map(([key, value]) => `${key}=${String(value)}`)\n .join('&')\n}\n\nexport * from './types'\n\nexport class HttpClient {\n private fetch: (input: RequestInfo, init?: RequestInit) => Promise\n\n constructor(\n private baseUrl: string,\n private sm2Key: KeyPairHex,\n config = {} as AxiosRequestConfig,\n ) {\n const axiosInstance = axios.create({\n baseURL: 'https://some-domain.com/api/',\n timeout: 10000,\n // headers: {'X-Custom-Header': 'foobar'}\n ...config,\n })\n\n this.fetch = buildAxiosFetch(\n axiosInstance /* , function (config) {\n config.timeout = 1000;\n return config;\n } */,\n )\n }\n\n async requestWithSignature(\n path: string,\n init?: Partial,\n sm2Key?: KeyPairHex,\n ): Promise> {\n return new Promise>((resolve, reject) => {\n const rawUrl = this.baseUrl + path\n const url = `${rawUrl}${path.includes('?') ? '&' : '?'}pubKey=${\n sm2Key?.publicKey ?? this.sm2Key.publicKey\n }`\n\n // console.log('privateKey:', this.sm2Key.privateKey)\n\n // console.log('publicKey:', this.sm2Key.publicKey)\n\n // console.log('to sign:', url.substring(url.indexOf('?') + 1))\n\n const sign = this.sign(\n url.substring(url.indexOf('?') + 1),\n sm2Key?.privateKey,\n )\n\n // console.log(\n // 'url:',\n // init?.method?.toLowerCase() === 'post'\n // ? rawUrl\n // : `${encodeURI(url)}&sign=${sign}`,\n // )\n\n this.fetch(\n init?.method?.toLowerCase() === 'post'\n ? rawUrl\n : `${encodeURI(url)}&sign=${sign}`,\n {\n ...init,\n ...(init?.method === 'POST'\n ? {\n body: {\n ...(init?.body as unknown as Record),\n sign,\n } as unknown as Request['body'],\n }\n : {}),\n },\n )\n .then(async (res) => {\n // console.log(res.url,'请求成功')\n const clientRes = res as unknown as ClientResponse\n clientRes.data = (await res.text()) as Data\n // Workaround for the issue causing the 2nd consecutive request to fail:\n // https://github.com/nodejs/undici/issues/1415\n setTimeout(() => {\n resolve(clientRes)\n }, 1)\n })\n .catch((err) => {\n // const clientRes = err as unknown as ClientResponse\n // clientRes.data = (await err.text()) as Data\n // console.log(err,'errerrerrerrerrerrerrerrerrerrerrerrerrerrerr')\n setTimeout(() => {\n reject(err)\n }, 1)\n })\n })\n }\n\n async retryRequestWithSignature(retryTimes: number, path: string, init?: Partial, sm2Key?: KeyPairHex ) {\n let err: Error = new Error()\n for (let i = 0; i(path, init, sm2Key)\n } catch (e) {\n if (i < retryTimes) {\n console.log('1')\n continue\n }\n err = e as Error\n }\n }\n throw err\n }\n\n sign(data: string, privateKey?: string): string {\n return sm2.doSignature(data, privateKey ?? this.sm2Key.privateKey, {\n hash: true,\n der: true,\n })\n }\n\n // ping\n // https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id15\n ping(): Promise {\n return this.requestWithSignature('/SCManager?action=ping')\n }\n\n // 启动合约\n // https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id60\n startContract(code: string): Promise> {\n const params = { action: 'startContract', script: code }\n return this.requestWithSignature(\n `/SCManager?${genUrlParamsFromObject(params)}`,\n )\n }\n\n // 启动合约\n // https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id13\n startContractByYPK(\n _request: StartContractByYpkRequest,\n ): Promise> {\n return this.requestWithSignature(\n `/SCManager?${genUrlParamsFromObject({\n action: 'startContractByYPK',\n ..._request,\n owner: this.sm2Key.publicKey,\n aim: 'onStartContract',\n signature: sm2.doSignature(\n `Fixed|${_request.path}|${this.sm2Key.publicKey}`,\n this.sm2Key.privateKey,\n {\n hash: true,\n der: true,\n },\n ),\n })}`,\n )\n }\n\n // 调用合约\n // https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id69\n executeContract(\n contractID: string,\n operation: string,\n arg: string,\n {\n method = 'POST',\n withDynamicAnalysis = false,\n withSignature = false,\n } = {} as ExecuteContractArgs,\n ): Promise>> {\n let request = {}\n if (withDynamicAnalysis === undefined) {\n request = {\n action: 'executeContract',\n contractID,\n operation,\n arg,\n }\n } else {\n request = {\n action: 'executeContract',\n contractID,\n operation,\n withDynamicAnalysis,\n arg,\n }\n }\n if (withSignature) {\n request = {\n ...request,\n pubkey: this.sm2Key.publicKey,\n signature: this.sign(\n `${contractID}|${operation}|${arg ?? ''}|${this.sm2Key.publicKey}`,\n ),\n }\n }\n\n return this.retryRequestWithSignature(\n 3,\n `/SCManager${\n method === 'GET' ? `?${genUrlParamsFromObject(request)}` : ''\n }`,\n {\n method,\n // eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n ...(method === 'POST' ? ({ body: request } as Request) : {}),\n },\n )\n }\n\n // 停止合约\n // https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id122\n killContractProcess(\n contractID: string,\n requestID?: string,\n ): Promise> {\n const _request: Record = {\n action: 'killContractProcess',\n id: contractID,\n }\n requestID && (_request.requestID = requestID!)\n return this.requestWithSignature(\n `/SCManager?${genUrlParamsFromObject(_request)}`,\n )\n }\n\n // 停止所有合约\n // 地址 http://39.104.205.122:18010/SCIDE\n // https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id131\n killAllContract(): Promise> {\n return this.requestWithSignature('/SCManager?action=killAllContract')\n }\n\n // 申请角色\n // https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html\n applyNodeRole(\n role: string,\n ): Promise> {\n const _request = {\n action: 'applyNodeRole',\n role,\n }\n return this.requestWithSignature(\n `/SCManager?${genUrlParamsFromObject(_request)}`,\n )\n }\n\n // 授权角色\n // https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html\n authNodeRole(\n isAccept: boolean,\n authorizedPubKey: string,\n managerPair?: KeyPairHex,\n ): Promise> {\n const _request = {\n action: 'authNodeRole',\n isAccept,\n authorizedPubKey,\n }\n return this.requestWithSignature(\n `/SCManager?${genUrlParamsFromObject(_request)}`,\n undefined,\n managerPair,\n )\n }\n\n // https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html\n // 用sse获取 问题未解决!!!\n distributeContract(\n nodeIDs: string,\n projectName: string,\n isPrivate: boolean,\n ): void {\n const signature = sm2.doSignature(\n `DistributeContract|${projectName}|${this.sm2Key.publicKey}`,\n this.sm2Key.privateKey,\n { hash: true, der: true },\n )\n\n const _request = {\n action: 'distributeContract',\n nodeIDs,\n projectName,\n isPrivate,\n signature,\n }\n\n const path = `/SCManager?${genUrlParamsFromObject(_request)}`\n const url = `${this.baseUrl + path}${\n path.includes('?') ? '&' : '?'\n }pubKey=${this.sm2Key.publicKey}`\n const sig = sm2.doSignature(\n url.substring(url.indexOf('?') + 1),\n this.sm2Key.privateKey,\n {\n hash: true,\n der: true,\n },\n )\n const source = new EventSource(\n `${this.baseUrl}${path}&pubKey=${this.sm2Key.publicKey}&sign=${sig}`,\n )\n source.addEventListener(\n 'message',\n function (_event) {\n // const data = event.data as DistributeContractResponse[]\n // console.log(data, 'dd')\n // handle message\n },\n false,\n )\n }\n\n saveFile(_request: SaveFileRequest): Promise> {\n return this.requestWithSignature(\n `/SCManager?${genUrlParamsFromObject({\n action: 'saveFile',\n ..._request,\n })}`,\n )\n }\n\n listProjectPermission(\n _request: ListProjectPermissionRequest,\n ): Promise> {\n return this.requestWithSignature(\n `/SCManager?${genUrlParamsFromObject({\n action: 'listProjectPermission',\n ..._request,\n })}`,\n )\n }\n\n startContractMultiPoint(\n peersID: string,\n type: number,\n selectUnitNum: number,\n projectName: string,\n isPrivate: boolean,\n sponsorPeerID: string,\n ): Promise> {\n const _request = {\n // peerID是节点的公钥,以逗号间隔开\n peersID,\n type,\n selectUnitNum,\n projectName,\n isPrivate,\n sponsorPeerID,\n }\n return this.requestWithSignature(\n `/SCManager?${genUrlParamsFromObject({\n action: 'startContractMultiPoint',\n ..._request,\n })}`,\n )\n }\n\n // 获取节点配置信息\n async loadNodeConfig(): Promise> {\n const res = await this.requestWithSignature(\n `/SCManager?${genUrlParamsFromObject({\n action: 'loadNodeConfig',\n })}`,\n )\n return { ...res, data: (res.status === 200 && res.data ? JSON.parse( res.data).data : {}) as LoadNodeConfigResponseData}\n }\n\n // 支持的key包括:{licence,projectDir,yjsPath,dataChain,doipConfig,nodeCenter,nodeName,masterAddress,resetNodeCenterWS}\n async updateConfig(\n key: string,\n val: string,\n ): Promise> {\n return this.requestWithSignature(\n `/SCManager?${genUrlParamsFromObject({\n action: 'updateConfig',\n key,\n val,\n })}`,\n )\n }\n\n // 设置pubkey为node manager\n async resetNodeManager(): Promise {\n const res = await this.requestWithSignature(\n `/SCManager?${genUrlParamsFromObject({\n action: 'resetNodeManager',\n })}`,\n )\n if (!res.data) {\n return false\n }\n const parsed = JSON.parse(res.data)\n return parsed.data === 'success'\n }\n\n // 锁定某个用户的的私有目录编辑功能\n lockEdit(): Promise> {\n return this.requestWithSignature(\n `/SCManager?${genUrlParamsFromObject({\n action: 'lockEdit',\n })}`,\n )\n }\n\n // 解锁某个用户的的私有目录编辑功能\n unlockEdit(): Promise> {\n return this.requestWithSignature(\n `/SCManager?${genUrlParamsFromObject({\n action: 'unlockEdit',\n })}`,\n )\n }\n\n addNode(nodePubKey: string): Promise> {\n return this.requestWithSignature(\n `?${genUrlParamsFromObject({\n action: 'addNode',\n nodePubKey,\n })}`,\n )\n }\n\n // 申请角色\n applyRole(role: string): Promise> {\n return this.requestWithSignature(\n `?${genUrlParamsFromObject({\n action: 'applyRole',\n role,\n })}`,\n )\n }\n\n authNodeManager(\n isAccept: boolean,\n authorizedPubKey: string,\n ): Promise> {\n return this.requestWithSignature(\n `?${genUrlParamsFromObject({\n action: 'authNodeManager',\n isAccept,\n authorizedPubKey,\n })}`,\n )\n }\n\n listAllUsers(): Promise> {\n return this.requestWithSignature(\n `?${genUrlParamsFromObject({\n action: 'listAllUsers',\n })}`,\n )\n }\n\n // 查看节点列表\n listNodes(): Promise {\n return this.requestWithSignature(\n `?${genUrlParamsFromObject({\n action: 'listNodes',\n })}`,\n ) as unknown as Promise\n }\n\n // 建立可信执行集群\n async createTrustUnit(\n data: { nodeName: string; pubkey: string }[],\n Msg: string,\n ): Promise<{ action: string; status: string }> {\n const toSign = `action=createTrustUnit&data=${JSON.stringify(\n data,\n )}&msg=${Msg}&pubKey=04303718771b9323c204e607639f14469f9a94e55b0964a408ad3b3864b0493b645d7070da0d550f0c54b934275a8e88dedc3024467b0566db5c1108b1baeaae27`\n const sig = sm2.doSignature(toSign, this.sm2Key.privateKey, {\n hash: true,\n der: true,\n })\n\n const body = {\n action: 'createTrustUnit',\n data,\n msg: Msg,\n pubKey:\n '04303718771b9323c204e607639f14469f9a94e55b0964a408ad3b3864b0493b645d7070da0d550f0c54b934275a8e88dedc3024467b0566db5c1108b1baeaae27',\n sign: sig,\n }\n return (await this.requestWithSignature('', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(body),\n })) as unknown as { action: string; status: string }\n }\n\n // 查看可信执行集群列表\n listTrustUnits(): Promise> {\n return this.requestWithSignature(\n `?${genUrlParamsFromObject({\n action: 'listTrustUnits',\n })}`,\n )\n }\n\n // listContractProcess 查询合约实例列表\n listContractProcess(): Promise> {\n return this.requestWithSignature(\n `/SCManager?${genUrlParamsFromObject({\n action: 'listContractProcess',\n })}`,\n )\n }\n\n // 下载合约\n downloadContract(\n projectName: string,\n isPrivate: boolean,\n timestamp: number\n ): Promise> {\n const _request = {\n action: 'downloadContract',\n projectName,\n isPrivate,\n timestamp,\n }\n return this.requestWithSignature(\n `/CMManager?${genUrlParamsFromObject(_request)}`)\n }\n\n // 配置合约引擎节点,若节点没有设置过node manager,将当前key设置为node manager\n async configNode(\n args: ConfigNodeArgs,\n ): Promise {\n if (!(await this.resetNodeManager())) {\n return false\n }\n\n const kvs: [string, string][] = Object.entries(args).filter(([_k, v]) => v) as [string, string][]\n\n await Promise.all([\n ...kvs.map(([k, v]) => this.updateConfig(k, v!)),\n this.applyNodeRole('ContractProvider'),\n this.applyNodeRole('ContractUser'),\n this.applyNodeRole('ContractInstanceManager'),\n this.authNodeRole(true, this.sm2Key.publicKey),\n ])\n\n const config = (await this.loadNodeConfig()).data\n if (!config) {\n return false\n }\n\n return kvs.every(([k, v]) => config[remapNodeConfigKey(k)] === v)\n }\n}\n\nfunction remapNodeConfigKey(k: string) {\n switch (k) {\n case 'dataChain':\n return 'bdledger'\n default:\n return k\n }\n}\n","/* eslint-disable no-console,no-cond-assign */\n\nexport interface WsEvent {\n data: string\n}\n\nexport type OnOpenHandler = (this: WebSocket, ev: Event) => void\nexport type WsHandler = (ev: WsEvent, ws?: WebSocket) => void\n\ninterface SegmentData {\n action: 'sendSeg'\n cid: string\n data: string\n}\n\nexport class WsSocket {\n private handlerList: WsHandler[] = []\n private toSend = ''\n private isSending = false\n private sendList: string[] = []\n private toReceive = ''\n private wssocket: WebSocket\n\n constructor(wsurl: string, onopen: OnOpenHandler, handler?: WsHandler) {\n console.log(`[createWS.js] createWssocket : ${wsurl}`)\n if (handler) {\n this.handlerList.push(handler)\n }\n\n // TODO: we don't need monitor at all?\n this.monitor()\n\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const that = this\n\n const wssocket = (this.wssocket = new WebSocket(wsurl))\n wssocket.onerror = function (error): void {\n console.log(error)\n }\n wssocket.onopen = onopen\n\n const onmessage = function (this: WebSocket, event: MessageEvent): void {\n const obj = JSON.parse(event.data as string) as { action: string }\n switch (obj.action) {\n case 'sendNextSegment':\n that.sendNextSegment()\n break\n case 'sendSeg':\n that.receiveSeg(obj as SegmentData)\n break\n default:\n that.handlerList.forEach((h) => h(event, this))\n }\n }\n wssocket.onmessage = onmessage\n\n const reconnect = function (): void {\n setTimeout(() => {\n console.log('[createWS.js] try to reconnect')\n const wssocket = (that.wssocket = new WebSocket(wsurl))\n wssocket.onclose = reconnect\n wssocket.onmessage = onmessage\n wssocket.onopen = onopen\n }, 1000)\n }\n wssocket.onclose = reconnect\n }\n\n status(): WebSocket['CLOSED' | 'CLOSING' | 'CONNECTING' | 'OPEN'] {\n return this.wssocket.readyState\n }\n\n sendNextSegment(): void {\n const str = this.toSend\n if (str.length > 1024) {\n this.toSend = str.substr(1024)\n const obj = {\n isSegment: true,\n data: str.substr(0, 1024),\n }\n this.wssocket.send(JSON.stringify(obj))\n } else {\n this.toSend = ''\n const obj = {\n isSegment: false,\n data: str,\n }\n this.wssocket.send(JSON.stringify(obj))\n this.isSending = false\n let data\n if ((data = this.sendList.pop())) {\n this.send(data)\n }\n }\n }\n\n receiveSeg(obj: SegmentData): void {\n if (obj.cid === 'start') {\n this.toReceive = ''\n }\n this.toReceive += obj.data\n if (obj.cid === 'done') {\n console.log(`[receiveSeg] Received AllData:${this.toReceive}`)\n const event: WsEvent = {\n data: this.toReceive,\n }\n this.toReceive = ''\n this.handlerList.forEach((h) => h(event, this.wssocket))\n }\n }\n\n monitor(): void {\n if (!this.isSending) {\n let data\n if ((data = this.sendList.pop())) {\n this.send(data)\n }\n }\n setTimeout(() => this.monitor(), 1000)\n }\n\n send(data: string): void {\n if (this.isSending) {\n this.sendList.push(data)\n return\n }\n if (data.length > 1024) {\n this.isSending = true\n this.toSend = data.substr(1024)\n const obj = {\n isSegment: true,\n data: data.substr(0, 1024),\n }\n this.wssocket.send(JSON.stringify(obj))\n } else {\n this.wssocket.send(data)\n }\n }\n\n addHandler(handler: WsHandler): void {\n this.handlerList.push(handler)\n }\n}\n","/* eslint-disable no-cond-assign */\n\nimport type { KeyPairHex } from 'sm-crypto'\nimport { sm2 } from 'sm-crypto'\n\nimport type { OnOpenHandler, WsHandler } from './wssocket'\nimport { WsSocket } from './wssocket'\n\ninterface ResponseData {\n action: string\n responseID?: string\n status: true | false | string // 'Success' | 'Exception' | 'Error' | 'failed: no session'\n result?: unknown\n data: string\n [K: string]: unknown\n}\n\n// interface ListResponseData {\n// action: string\n// data: string\n// status: true | false\n// }\n\ninterface PromiseCallbackPair {\n resolve: (value: ResponseData | PromiseLike) => void\n reject: (reason?: unknown) => void\n}\n\nexport class WsClient {\n private readonly sm2Key: KeyPairHex\n private readonly wssocket: WsSocket\n private readonly promiseCallbackPairs: Record =\n {}\n\n private readonly sessionPromise: Promise\n private sessionResolve!: (value: string | PromiseLike) => void\n private readonly loginPromise: Promise\n private loginResolve!: (value: boolean | PromiseLike) => void\n\n constructor(\n url: string,\n onopen: OnOpenHandler,\n handler: WsHandler,\n sm2Key: KeyPairHex = sm2.generateKeyPairHex(),\n ) {\n this.sm2Key = sm2Key\n this.sessionPromise = new Promise((resolve, _reject) => {\n this.sessionResolve = resolve\n })\n this.loginPromise = new Promise((resolve, _reject) => {\n this.loginResolve = resolve\n })\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const that = this\n this.wssocket = new WsSocket(url, onopen, function (\n this: WebSocket,\n event,\n _,\n ) {\n const data = JSON.parse(event.data) as ResponseData\n\n switch (data.action) {\n case 'onSessionID':\n that.sessionResolve(data.session as string)\n break\n case 'onLogin':\n {\n const failed =\n typeof data.status === 'string' &&\n data.status.toLowerCase().includes('failed')\n that.loginResolve(!failed)\n }\n break\n }\n\n const reqId = data.responseID\n let pc: PromiseCallbackPair | undefined\n if (reqId && (pc = that.promiseCallbackPairs[reqId])) {\n if (data) {\n pc.resolve(data)\n } else {\n pc.reject(data)\n }\n }\n handler(event, this)\n })\n }\n\n status(): WebSocket['CLOSED' | 'CLOSING' | 'CONNECTING' | 'OPEN'] {\n return this.wssocket.status()\n }\n\n sessionReceived(): Promise {\n return this.sessionPromise\n }\n\n async login(): Promise {\n const session = await this.sessionPromise\n const request = {\n action: 'login',\n pubKey: this.sm2Key.publicKey,\n signature: sm2.doSignature(session, this.sm2Key.privateKey, {\n hash: true,\n der: true,\n }),\n }\n this.wssocket.send(JSON.stringify(request))\n return this.loginPromise\n }\n\n loggedIn(): Promise {\n return this.loginPromise\n }\n\n matchCID(contractID: string): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'matchCID',\n contractID,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n getMetabyCID(contractID: string): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'getMetabyCID',\n contractID,\n requestID,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n getMetabyReadme(\n keyword: string,\n page?: string,\n pageSize?: string,\n ): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'getMetabyReadme',\n page,\n pageSize,\n keyword,\n requestID,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n getMetabyPubkey(pubkey: string): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'getMetabyPubkey',\n pubkey,\n requestID,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n segmentWord(words: string): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n words,\n action: 'segmentWord',\n requestID,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n getMetabyOwner(\n owner: string,\n page?: string,\n pageSize?: string,\n ): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'getMetabyOwner',\n owner,\n page,\n pageSize,\n requestID,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n getDependentContract(contractName: string): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'getDependentContract',\n requestID,\n contractName,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n queryContractLogByDate(start: number): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'queryContractLogByDate',\n requestID,\n start,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n queryDataByHash(hash: string): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'queryDataByHash',\n requestID,\n hash,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n executeContract(\n contractID: string,\n method: string,\n arg: unknown,\n ): Promise {\n const sm2Key = this.sm2Key\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const argStr = (typeof arg) == 'object' ? JSON.stringify(arg):arg+\"\";\n const request = {\n action: 'executeContract',\n requestID,\n contractID,\n operation: method,\n arg: arg,\n ...(sm2Key\n ? {\n pubkey: sm2Key.publicKey,\n signature: sm2.doSignature(\n `${contractID}|${method}|${argStr}|${sm2Key.publicKey}`,\n sm2Key.privateKey,\n { hash: true, der: true },\n ),\n }\n : {}),\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n getSessionID(): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'getSessionID',\n requestID,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n listTheContractProcess(contractID: string): Promise {\n const sm2Key = this.sm2Key\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'listTheContractProcess',\n requestID,\n contractID,\n ...(sm2Key\n ? {\n pubkey: sm2Key.publicKey,\n signature: sm2.doSignature(\n `${contractID}|${sm2Key.publicKey}`,\n sm2Key.privateKey,\n { hash: true, der: true },\n ),\n }\n : {}),\n }\n this.wssocket.send(JSON.stringify(request))\n\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n getMask(\n contractID: string,\n // operation: string,\n ): Promise {\n const sm2Key = this.sm2Key\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'getMask',\n requestID,\n contractID,\n // operation,\n ...(sm2Key\n ? {\n pubkey: sm2Key.publicKey,\n signature: sm2.doSignature(\n `${contractID}|${sm2Key.publicKey}`,\n sm2Key.privateKey,\n { hash: true, der: true },\n ),\n }\n : {}),\n }\n\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n setMask(\n contractID: string,\n operation: string,\n arg: string,\n ): Promise {\n const sm2Key = this.sm2Key\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'setMask',\n requestID,\n contractID,\n operation,\n arg,\n ...(sm2Key\n ? {\n pubkey: sm2Key.publicKey,\n signature: sm2.doSignature(\n `${contractID}|${sm2Key.publicKey}`,\n sm2Key.privateKey,\n { hash: true, der: true },\n ),\n }\n : {}),\n }\n\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n getMock(\n contractID: string,\n // operation: string,\n ): Promise {\n const sm2Key = this.sm2Key\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'getMock',\n requestID,\n contractID,\n // operation,\n ...(sm2Key\n ? {\n pubkey: sm2Key.publicKey,\n signature: sm2.doSignature(\n `${contractID}|${sm2Key.publicKey}`,\n sm2Key.privateKey,\n { hash: true, der: true },\n ),\n }\n : {}),\n }\n\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n setMock(\n contractID: string,\n operation: string,\n arg: string,\n ): Promise {\n const sm2Key = this.sm2Key\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'setMock',\n requestID,\n contractID,\n operation,\n arg,\n ...(sm2Key\n ? {\n pubkey: sm2Key.publicKey,\n signature: sm2.doSignature(\n `${contractID}|${sm2Key.publicKey}`,\n sm2Key.privateKey,\n { hash: true, der: true },\n ),\n }\n : {}),\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n queryHashByOffset(offset: number, count: number): Promise {\n const sm2Key = this.sm2Key\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'queryHashByOffset',\n requestID,\n offset,\n count,\n ...(sm2Key\n ? {\n pubkey: sm2Key.publicKey,\n /* signature: sm2.doSignature(\n id + '|' + sm2Key.publicKey,\n sm2Key.privateKey,\n { hash: true, der: true },\n ), */\n }\n : {}),\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n loadNodeConfig(): Promise {\n const sm2Key = this.sm2Key\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'loadNodeConfig',\n requestID,\n\n ...(sm2Key\n ? {\n pubkey: sm2Key.publicKey,\n signature: sm2.doSignature(sm2Key.publicKey, sm2Key.privateKey, {\n hash: true,\n der: true,\n }),\n }\n : {}),\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n queryUserStat(): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'queryUserStat',\n requestID,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n listNodes(): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'listNodes',\n requestID,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n killContractProcess(id: string): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'killContractProcess',\n requestID,\n id,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n distributeYPK(projectName: string, nodeIDs: string): Promise {\n const sm2Key = this.sm2Key\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'distributeYPK',\n requestID,\n pubKey: sm2Key.publicKey,\n projectName,\n nodeIDs,\n signature: sm2.doSignature(\n `DistributeYPK|${projectName}|${sm2Key.publicKey}`,\n sm2Key.privateKey,\n { hash: true, der: true },\n ),\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n listYPKs(): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'listYPKs',\n requestID,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n deleteFile(file: string): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'deleteFile',\n requestID,\n file,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n startContractByYPK(project: string): Promise {\n const sm2Key = this.sm2Key\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'startContractByYPK',\n isPrivate: true,\n requestID,\n owner: sm2Key.publicKey,\n path: `/${project}`,\n signature: sm2.doSignature(\n `Fixed|${project}|${sm2Key.publicKey}`,\n sm2Key.privateKey,\n ),\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n initBDServer(\n host: string,\n username: string,\n password: string,\n name: string,\n clusterHost: string,\n ): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'initBDServer',\n requestID,\n host,\n username,\n password,\n name,\n sm2Key: JSON.stringify(this.sm2Key),\n clusterHost,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n initBDCluster(\n host: string,\n username: string,\n password: string,\n name: string,\n sm2Key: string,\n agents: [],\n ): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'initBDCluster',\n requestID,\n host,\n username,\n password,\n name,\n sm2Key,\n agents,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n listCompiledFiles(): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'listCompiledFiles',\n requestID,\n isPrivate: true,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n getManagerPubkey(): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'getManagerPubkey',\n requestID,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n getClusterName(): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'getClusterName',\n requestID,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n\n setClusterName(name: string): Promise {\n const requestID = `${new Date().getTime()}_${Math.floor(\n Math.random() * 10000,\n )}`\n const request = {\n action: 'setClusterName',\n requestID,\n name,\n }\n this.wssocket.send(JSON.stringify(request))\n return new Promise((resolve, reject) => {\n this.promiseCallbackPairs[requestID] = { resolve, reject }\n })\n }\n}\n"],"names":["aesEncrypt","data","aesKey","exkey","slice","aes","ExpandKey","blocks","cryptico","string2bytes","pad16","Encrypt","ciphertext","bytes2string","b256to64","rsaEncrypt","rsaKey","rsa","RSAKey","setPublic","n","e1","encrypt","loadRSAKey","strs","b64to256","split","key","setPrivate","encryptReq","reqContent","pubKey","generateAESKey","aesObj","JSON","stringify","contractID","reqContentNoId","undefined","action","decrypt","arg","requester","toString","e","genUrlParamsFromObject","obj","Object","entries","map","value","String","join","HttpClient","baseUrl","sm2Key","fetch","constructor","config","this","axiosInstance","axios","create","baseURL","timeout","buildAxiosFetch","async","path","init","Promise","resolve","reject","rawUrl","url","includes","publicKey","sign","substring","indexOf","privateKey","method","toLowerCase","encodeURI","body","then","res","clientRes","text","setTimeout","catch","err","retryTimes","Error","i","requestWithSignature","console","log","sm2","doSignature","hash","der","ping","startContract","code","params","script","startContractByYPK","_request","owner","aim","signature","executeContract","operation","withDynamicAnalysis","withSignature","request","pubkey","retryRequestWithSignature","killContractProcess","requestID","id","killAllContract","applyNodeRole","role","authNodeRole","isAccept","authorizedPubKey","managerPair","distributeContract","nodeIDs","projectName","isPrivate","sig","EventSource","addEventListener","_event","saveFile","listProjectPermission","startContractMultiPoint","peersID","type","selectUnitNum","sponsorPeerID","status","parse","val","lockEdit","unlockEdit","addNode","nodePubKey","applyRole","authNodeManager","listAllUsers","listNodes","Msg","toSign","msg","headers","listTrustUnits","listContractProcess","downloadContract","timestamp","args","resetNodeManager","kvs","filter","_k","v","all","k","updateConfig","loadNodeConfig","every","remapNodeConfigKey","WsSocket","handlerList","toSend","isSending","sendList","toReceive","wssocket","wsurl","onopen","handler","push","monitor","that","WebSocket","onerror","error","onmessage","event","sendNextSegment","receiveSeg","forEach","h","reconnect","onclose","readyState","str","length","substr","isSegment","send","pop","cid","addHandler","WsClient","promiseCallbackPairs","sessionPromise","sessionResolve","loginPromise","loginResolve","generateKeyPairHex","_reject","_","session","failed","reqId","responseID","pc","sessionReceived","loggedIn","matchCID","Date","getTime","Math","floor","random","getMetabyCID","getMetabyReadme","keyword","page","pageSize","getMetabyPubkey","segmentWord","words","getMetabyOwner","getDependentContract","contractName","queryContractLogByDate","start","queryDataByHash","argStr","getSessionID","listTheContractProcess","getMask","setMask","getMock","setMock","queryHashByOffset","offset","count","queryUserStat","distributeYPK","listYPKs","deleteFile","file","project","initBDServer","host","username","password","name","clusterHost","initBDCluster","agents","listCompiledFiles","getManagerPubkey","getClusterName","setClusterName"],"mappings":"6KAYgB,SAAAA,EAAWC,EAAcC,GACvC,MAAMC,EAAQD,EAAOE,MAAM,GAC3BC,EAAIC,UAAUH,GACd,IAAII,EAASC,EAASC,aAAaR,GACnCM,EAASC,EAASE,MAAMH,GACxBF,EAAIM,QAAQJ,EAAQJ,GACpB,IAAIS,EAAaJ,EAASK,aAAaN,GAEvC,OADAK,EAAaJ,EAASM,SAASF,GACxBA,CACT,CAEgB,SAAAG,EACdd,EACAe,GAEA,MAAMC,EAAM,IAAIC,EAEhB,OADAD,EAAIE,UAAUH,EAAOI,EAAGJ,EAAOK,IACxBJ,EAAI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ASuB,KAAKzK,KAAKC,UAAUgF,IAC3B,IAAI9C,SAAQ,CAACC,EAASC,KAC3BZ,KAAKqJ,qBAAqBzF,GAAa,CAAEjD,UAASC,SAAQ,GAE7D,CAEDqM,mBACE,MAAMrJ,EAAY,IAAG,IAAIyG,MAAOC,aAAaC,KAAKC,MAChC,IAAhBD,KAAKE,YAEDjH,EAAU,CACd5E,OAAQ,mBACRgF,aAGF,OADA5D,KAAKyH,SAASuB,KAAKzK,KAAKC,UAAUgF,IAC3B,IAAI9C,SAAQ,CAACC,EAASC,KAC3BZ,KAAKqJ,qBAAqBzF,GAAa,CAAEjD,UAASC,SAAQ,GAE7D,CAEDsM,iBACE,MAAMtJ,EAAY,IAAG,IAAIyG,MAAOC,aAAaC,KAAKC,MAChC,IAAhBD,KAAKE,YAEDjH,EAAU,CACd5E,OAAQ,iBACRgF,aAGF,OADA5D,KAAKyH,SAASuB,KAAKzK,KAAKC,UAAUgF,IAC3B,IAAI9C,SAAQ,CAACC,EAASC,KAC3BZ,KAAKqJ,qBAAqBzF,GAAa,CAAEjD,UAASC,SAAQ,GAE7D,CAEDuM,eAAeP,GACb,MAAMhJ,EAAY,IAAG,IAAIyG,MAAOC,aAAaC,KAAKC,MAChC,IAAhBD,KAAKE,YAEDjH,EAAU,CACd5E,OAAQ,iBACRgF,YACAgJ,QAGF,OADA5M,KAAKyH,SAASuB,KAAKzK,KAAKC,UAAUgF,IAC3B,IAAI9C,SAAQ,CAACC,EAASC,KAC3BZ,KAAKqJ,qBAAqBzF,GAAa,CAAEjD,UAASC,SAAQ,GAE7D"} \ No newline at end of file diff --git a/package.json b/package.json index 2334ea3..b14a441 100644 --- a/package.json +++ b/package.json @@ -30,20 +30,22 @@ "prettier": "@daotl/prettier-config", "dependencies": { "@daotl/cryptico": "^2.0.3", - "@lifeomic/axios-fetch": "^3.0.0", + "@lifeomic/axios-fetch": "3.0.1", "axios": "^0.27.2", "sm-crypto": "^0.3.11" }, "devDependencies": { "@daotl/eslint-config": "^0.3.31", + "@rollup/plugin-commonjs": "^24.0.1", "@types/node": "^18.7.15", "@types/sm-crypto": "^0.3.0", "eslint": "^8.23.0", "prettier": "^2.7.1", - "rollup": "^2.79.0", + "rollup": "^2.79.1", "rollup-plugin-dts": "^4.2.2", + "@rollup/plugin-node-resolve": "^15.0.1", "rollup-plugin-terser": "^7.0.2", - "rollup-plugin-typescript2": "^0.33.0", + "rollup-plugin-typescript2": "^0.34.1", "shx": "^0.3.4", "sucrase": "^3.25.0", "typescript": "^4.8.2" diff --git a/rollup.config.ts b/rollup.config.ts index f696874..a7cdb01 100644 --- a/rollup.config.ts +++ b/rollup.config.ts @@ -1,7 +1,8 @@ -import type { RollupOptions } from 'rollup' +import type { RollupOptions } from '@rollup' import dts from 'rollup-plugin-dts' import { terser } from 'rollup-plugin-terser' import typescript from 'rollup-plugin-typescript2' +import commonjs from '@rollup/plugin-commonjs' const pkg = require('./package.json') @@ -16,6 +17,12 @@ export default [ format: 'umd', name, sourcemap: true, + globals:{ + "@daotl/cryptico":"cryptico", + "@lifeomic/axios-fetch":"axiosFetch", + "axios":"axios", + "sm-crypto":"smCrypto" + } }, { file: `${pkg.module}`, format: 'es', sourcemap: true }, { @@ -23,6 +30,12 @@ export default [ format: 'iife', name, sourcemap: true, + globals:{ + "@daotl/cryptico":"cryptico", + "@lifeomic/axios-fetch":"axiosFetch", + "axios":"axios", + "sm-crypto":"smCrypto" + } }, ], plugins: [ @@ -30,7 +43,7 @@ export default [ tsconfig: 'tsconfig.build.json', useTsconfigDeclarationDir: true, }), - terser(), + terser(),commonjs() ], }, { diff --git a/types/crypto.d.ts b/types/crypto.d.ts deleted file mode 100644 index 9219cb6..0000000 --- a/types/crypto.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -import type { AESKey } from '@daotl/cryptico'; -import { RSAKey } from '@daotl/cryptico'; -export declare function aesEncrypt(data: string, aesKey: AESKey): string; -export declare function rsaEncrypt(data: string, rsaKey: { - n: string; - e1: string; -}): string; -export declare function loadRSAKey(rsaKey: string): RSAKey; -export declare function encryptReq(reqContent: { - contractID: string; -}, pubKey: RSAKey): { - action: string | null; - contractID: string; - arg: string; - requester: string; -}; diff --git a/types/httpClient.d.ts b/types/httpClient.d.ts deleted file mode 100644 index 5e58860..0000000 --- a/types/httpClient.d.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { type AxiosRequestConfig } from 'axios'; -import type { KeyPairHex } from 'sm-crypto'; -import type { ClientResponse, ConfigNodeArgs, ExecuteContractArgs, ListAllUsersResponseData, ListNodesResponse, ListProjectPermissionRequest, ListProjectPermissionResponseData, LoadNodeConfigResponseData, ExecuteContractResponse, PingResponse, SaveFileRequest, StartContractByYpkRequest } from './types'; -export * from './types'; -export declare class HttpClient { - private baseUrl; - private sm2Key; - private fetch; - constructor(baseUrl: string, sm2Key: KeyPairHex, config?: AxiosRequestConfig); - requestWithSignature(path: string, init?: Partial, sm2Key?: KeyPairHex): Promise>; - retryRequestWithSignature(retryTimes: number, path: string, init?: Partial, sm2Key?: KeyPairHex): Promise>; - sign(data: string, privateKey?: string): string; - ping(): Promise; - startContract(code: string): Promise>; - startContractByYPK(_request: StartContractByYpkRequest): Promise>; - executeContract(contractID: string, operation: string, arg: string, { method, withDynamicAnalysis, withSignature, }?: ExecuteContractArgs): Promise>>; - killContractProcess(contractID: string, requestID?: string): Promise>; - killAllContract(): Promise>; - applyNodeRole(role: string): Promise>; - authNodeRole(isAccept: boolean, authorizedPubKey: string, managerPair?: KeyPairHex): Promise>; - distributeContract(nodeIDs: string, projectName: string, isPrivate: boolean): void; - saveFile(_request: SaveFileRequest): Promise>; - listProjectPermission(_request: ListProjectPermissionRequest): Promise>; - startContractMultiPoint(peersID: string, type: number, selectUnitNum: number, projectName: string, isPrivate: boolean, sponsorPeerID: string): Promise>; - loadNodeConfig(): Promise>; - updateConfig(key: string, val: string): Promise>; - resetNodeManager(): Promise; - lockEdit(): Promise>; - unlockEdit(): Promise>; - addNode(nodePubKey: string): Promise>; - applyRole(role: string): Promise>; - authNodeManager(isAccept: boolean, authorizedPubKey: string): Promise>; - listAllUsers(): Promise>; - listNodes(): Promise; - createTrustUnit(data: { - nodeName: string; - pubkey: string; - }[], Msg: string): Promise<{ - action: string; - status: string; - }>; - listTrustUnits(): Promise>; - listContractProcess(): Promise>; - downloadContract(projectName: string, isPrivate: boolean, timestamp: number): Promise>; - configNode(args: ConfigNodeArgs): Promise; -} diff --git a/types/index.d.ts b/types/index.d.ts deleted file mode 100644 index a513b55..0000000 --- a/types/index.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './crypto'; -export * from './httpClient'; -export * from './wsClient'; -export * from './wssocket'; diff --git a/types/types.d.ts b/types/types.d.ts deleted file mode 100644 index 4ff5d40..0000000 --- a/types/types.d.ts +++ /dev/null @@ -1,84 +0,0 @@ -export type ClientResponse = Omit & { - data?: Data; -}; -export type PingResponse = ClientResponse<'pong'>; -export interface SaveFileRequest { - content: string; - isAppend: boolean; - isPrivate: boolean; - path: string; -} -export interface ListProjectPermissionRequest { - isPrivate: boolean; - path: string; -} -export interface ListProjectPermissionResponseData { - permissions: string[]; - ypk: string; -} -export interface StartContractByYpkRequest { - isPrivate: boolean; - path: string; - script: string; -} -export interface ListAllUsersResponseDataListItem { - key: string; - value: string; -} -export interface ListAllUsersResponseData { - kv: ListAllUsersResponseDataListItem[]; - time: ListAllUsersResponseDataListItem[]; -} -export interface OnlineContractsItem { - contractID: string; - contractName: string; - isMaster: boolean; - type: string; - yjsType: string; - [key: string]: unknown; -} -export interface OnlineItem { - cimanager: string; - contractVersion: number; - events: number; - ipPort: string; - masterAddress: string; - nodeName: string; - peerID: string; - pubKey: string; - contracts: OnlineContractsItem[]; -} -export interface ListNodesResponse { - action: string; - offline: string[]; - online: OnlineItem[]; -} -export interface DistributeContractResponse { - action: string; - progress: string; -} -export interface ExecuteContractArgs extends RequestInit { - method?: 'POST' | 'GET'; - withSignature?: boolean; - withDynamicAnalysis?: boolean; -} -export interface ExecuteContractResponse { - status?: boolean; - data?: Data; - executeTime?: number; - cid?: string; - isPrivate?: boolean; - [key: string]: unknown; -} -export interface ConfigNodeArgs { - nodeName?: string; - dataChain?: string; - masterAddress?: string; - nodeCenter?: string; - LHSProxyAddress?: string; - [K: string]: string | undefined; -} -export interface LoadNodeConfigResponseData { - doipConfig: string; - [K: string]: string; -} diff --git a/types/wsClient.d.ts b/types/wsClient.d.ts deleted file mode 100644 index 44103da..0000000 --- a/types/wsClient.d.ts +++ /dev/null @@ -1,56 +0,0 @@ -import type { KeyPairHex } from 'sm-crypto'; -import type { OnOpenHandler, WsHandler } from './wssocket'; -interface ResponseData { - action: string; - responseID?: string; - status: true | false | string; - result?: unknown; - data: string; - [K: string]: unknown; -} -export declare class WsClient { - private readonly sm2Key; - private readonly wssocket; - private readonly promiseCallbackPairs; - private readonly sessionPromise; - private sessionResolve; - private readonly loginPromise; - private loginResolve; - constructor(url: string, onopen: OnOpenHandler, handler: WsHandler, sm2Key?: KeyPairHex); - status(): WebSocket['CLOSED' | 'CLOSING' | 'CONNECTING' | 'OPEN']; - sessionReceived(): Promise; - login(): Promise; - loggedIn(): Promise; - matchCID(contractID: string): Promise; - getMetabyCID(contractID: string): Promise; - getMetabyReadme(keyword: string, page?: string, pageSize?: string): Promise; - getMetabyPubkey(pubkey: string): Promise; - segmentWord(words: string): Promise; - getMetabyOwner(owner: string, page?: string, pageSize?: string): Promise; - getDependentContract(contractName: string): Promise; - queryContractLogByDate(start: number): Promise; - queryDataByHash(hash: string): Promise; - executeContract(contractID: string, method: string, arg: unknown): Promise; - getSessionID(): Promise; - listTheContractProcess(contractID: string): Promise; - getMask(contractID: string): Promise; - setMask(contractID: string, operation: string, arg: string): Promise; - getMock(contractID: string): Promise; - setMock(contractID: string, operation: string, arg: string): Promise; - queryHashByOffset(offset: number, count: number): Promise; - loadNodeConfig(): Promise; - queryUserStat(): Promise; - listNodes(): Promise; - killContractProcess(id: string): Promise; - distributeYPK(projectName: string, nodeIDs: string): Promise; - listYPKs(): Promise; - deleteFile(file: string): Promise; - startContractByYPK(project: string): Promise; - initBDServer(host: string, username: string, password: string, name: string, clusterHost: string): Promise; - initBDCluster(host: string, username: string, password: string, name: string, sm2Key: string, agents: []): Promise; - listCompiledFiles(): Promise; - getManagerPubkey(): Promise; - getClusterName(): Promise; - setClusterName(name: string): Promise; -} -export {}; diff --git a/types/wssocket.d.ts b/types/wssocket.d.ts deleted file mode 100644 index 671a83a..0000000 --- a/types/wssocket.d.ts +++ /dev/null @@ -1,26 +0,0 @@ -export interface WsEvent { - data: string; -} -export type OnOpenHandler = (this: WebSocket, ev: Event) => void; -export type WsHandler = (ev: WsEvent, ws?: WebSocket) => void; -interface SegmentData { - action: 'sendSeg'; - cid: string; - data: string; -} -export declare class WsSocket { - private handlerList; - private toSend; - private isSending; - private sendList; - private toReceive; - private wssocket; - constructor(wsurl: string, onopen: OnOpenHandler, handler?: WsHandler); - status(): WebSocket['CLOSED' | 'CLOSING' | 'CONNECTING' | 'OPEN']; - sendNextSegment(): void; - receiveSeg(obj: SegmentData): void; - monitor(): void; - send(data: string): void; - addHandler(handler: WsHandler): void; -} -export {};