merge code 0.4.0

This commit is contained in:
CaiHQ 2023-03-18 18:43:58 +08:00
parent d75feb3ee1
commit ec5099762e
14 changed files with 23 additions and 491 deletions

3
.gitignore vendored
View File

@ -3,3 +3,6 @@ node_modules
dist
package-lock.json
pnpm-lock.yaml
lib
types
.DS_Store

238
lib/index.d.ts vendored
View File

@ -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<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 };

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -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"

View File

@ -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()
],
},
{

16
types/crypto.d.ts vendored
View File

@ -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;
};

56
types/httpClient.d.ts vendored
View File

@ -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<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
View File

@ -1,4 +0,0 @@
export * from './crypto';
export * from './httpClient';
export * from './wsClient';
export * from './wssocket';

84
types/types.d.ts vendored
View File

@ -1,84 +0,0 @@
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
View File

@ -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<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
View File

@ -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 {};