initial commit
This commit is contained in:
16
types/crypto.d.ts
vendored
Normal file
16
types/crypto.d.ts
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
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;
|
||||
};
|
||||
56
types/httpClient.d.ts
vendored
Normal file
56
types/httpClient.d.ts
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
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<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>;
|
||||
}
|
||||
4
types/index.d.ts
vendored
Normal file
4
types/index.d.ts
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from './crypto';
|
||||
export * from './httpClient';
|
||||
export * from './wsClient';
|
||||
export * from './wssocket';
|
||||
84
types/types.d.ts
vendored
Normal file
84
types/types.d.ts
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
export type ClientResponse<Data> = Omit<Response, 'data'> & {
|
||||
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<Data> {
|
||||
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;
|
||||
}
|
||||
56
types/wsClient.d.ts
vendored
Normal file
56
types/wsClient.d.ts
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
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<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 {};
|
||||
26
types/wssocket.d.ts
vendored
Normal file
26
types/wssocket.d.ts
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
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 {};
|
||||
Reference in New Issue
Block a user