239 lines
9.2 KiB
TypeScript
239 lines
9.2 KiB
TypeScript
|
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<Data> = Omit<Response, 'data'> & {
|
||
|
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<Data> {
|
||
|
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<any>);
|
||
|
requestWithSignature<Data>(path: string, init?: Partial<RequestInit>, sm2Key?: KeyPairHex): Promise<ClientResponse<Data>>;
|
||
|
retryRequestWithSignature<Data>(retryTimes: number, path: string, init?: Partial<RequestInit>, sm2Key?: KeyPairHex): Promise<ClientResponse<Data>>;
|
||
|
sign(data: string, privateKey?: string): string;
|
||
|
ping(): Promise<PingResponse>;
|
||
|
startContract(code: string): Promise<ClientResponse<string>>;
|
||
|
startContractByYPK(_request: StartContractByYpkRequest): Promise<ClientResponse<string>>;
|
||
|
executeContract(contractID: string, operation: string, arg: string, { method, withDynamicAnalysis, withSignature, }?: ExecuteContractArgs): Promise<ClientResponse<ExecuteContractResponse<string>>>;
|
||
|
killContractProcess(contractID: string, requestID?: string): Promise<ClientResponse<string>>;
|
||
|
killAllContract(): Promise<ClientResponse<string>>;
|
||
|
applyNodeRole(role: string): Promise<ClientResponse<{
|
||
|
action: string;
|
||
|
data: string;
|
||
|
role?: string;
|
||
|
}>>;
|
||
|
authNodeRole(isAccept: boolean, authorizedPubKey: string, managerPair?: KeyPairHex): Promise<ClientResponse<{
|
||
|
action: string;
|
||
|
data: string;
|
||
|
}>>;
|
||
|
distributeContract(nodeIDs: string, projectName: string, isPrivate: boolean): void;
|
||
|
saveFile(_request: SaveFileRequest): Promise<ClientResponse<string>>;
|
||
|
listProjectPermission(_request: ListProjectPermissionRequest): Promise<ClientResponse<ListProjectPermissionResponseData>>;
|
||
|
startContractMultiPoint(peersID: string, type: number, selectUnitNum: number, projectName: string, isPrivate: boolean, sponsorPeerID: string): Promise<ClientResponse<string>>;
|
||
|
loadNodeConfig(): Promise<ClientResponse<LoadNodeConfigResponseData>>;
|
||
|
updateConfig(key: string, val: string): Promise<ClientResponse<boolean>>;
|
||
|
resetNodeManager(): Promise<boolean>;
|
||
|
lockEdit(): Promise<ClientResponse<string>>;
|
||
|
unlockEdit(): Promise<ClientResponse<string>>;
|
||
|
addNode(nodePubKey: string): Promise<ClientResponse<string>>;
|
||
|
applyRole(role: string): Promise<ClientResponse<string>>;
|
||
|
authNodeManager(isAccept: boolean, authorizedPubKey: string): Promise<ClientResponse<string>>;
|
||
|
listAllUsers(): Promise<ClientResponse<ListAllUsersResponseData>>;
|
||
|
listNodes(): Promise<ListNodesResponse>;
|
||
|
createTrustUnit(data: {
|
||
|
nodeName: string;
|
||
|
pubkey: string;
|
||
|
}[], Msg: string): Promise<{
|
||
|
action: string;
|
||
|
status: string;
|
||
|
}>;
|
||
|
listTrustUnits(): Promise<ClientResponse<{
|
||
|
key: string;
|
||
|
value: string;
|
||
|
}[]>>;
|
||
|
listContractProcess(): Promise<ClientResponse<string>>;
|
||
|
downloadContract(projectName: string, isPrivate: boolean, timestamp: number): Promise<ClientResponse<string>>;
|
||
|
configNode(args: ConfigNodeArgs): Promise<boolean>;
|
||
|
}
|
||
|
|
||
|
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<string>;
|
||
|
login(): Promise<boolean>;
|
||
|
loggedIn(): Promise<boolean>;
|
||
|
matchCID(contractID: string): Promise<ResponseData>;
|
||
|
getMetabyCID(contractID: string): Promise<ResponseData>;
|
||
|
getMetabyReadme(keyword: string, page?: string, pageSize?: string): Promise<ResponseData>;
|
||
|
getMetabyPubkey(pubkey: string): Promise<ResponseData>;
|
||
|
segmentWord(words: string): Promise<ResponseData>;
|
||
|
getMetabyOwner(owner: string, page?: string, pageSize?: string): Promise<ResponseData>;
|
||
|
getDependentContract(contractName: string): Promise<ResponseData>;
|
||
|
queryContractLogByDate(start: number): Promise<ResponseData>;
|
||
|
queryDataByHash(hash: string): Promise<ResponseData>;
|
||
|
executeContract(contractID: string, method: string, arg: unknown): Promise<ResponseData>;
|
||
|
getSessionID(): Promise<ResponseData>;
|
||
|
listTheContractProcess(contractID: string): Promise<ResponseData>;
|
||
|
getMask(contractID: string): Promise<ResponseData>;
|
||
|
setMask(contractID: string, operation: string, arg: string): Promise<ResponseData>;
|
||
|
getMock(contractID: string): Promise<ResponseData>;
|
||
|
setMock(contractID: string, operation: string, arg: string): Promise<ResponseData>;
|
||
|
queryHashByOffset(offset: number, count: number): Promise<ResponseData>;
|
||
|
loadNodeConfig(): Promise<ResponseData>;
|
||
|
queryUserStat(): Promise<ResponseData>;
|
||
|
listNodes(): Promise<ResponseData>;
|
||
|
killContractProcess(id: string): Promise<ResponseData>;
|
||
|
distributeYPK(projectName: string, nodeIDs: string): Promise<ResponseData>;
|
||
|
listYPKs(): Promise<ResponseData>;
|
||
|
deleteFile(file: string): Promise<ResponseData>;
|
||
|
startContractByYPK(project: string): Promise<ResponseData>;
|
||
|
initBDServer(host: string, username: string, password: string, name: string, clusterHost: string): Promise<ResponseData>;
|
||
|
initBDCluster(host: string, username: string, password: string, name: string, sm2Key: string, agents: []): Promise<ResponseData>;
|
||
|
listCompiledFiles(): Promise<ResponseData>;
|
||
|
getManagerPubkey(): Promise<ResponseData>;
|
||
|
getClusterName(): Promise<ResponseData>;
|
||
|
setClusterName(name: string): Promise<ResponseData>;
|
||
|
}
|
||
|
|
||
|
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 };
|