Skip to content

Commit b0c5973

Browse files
author
Shuaige1234567
committed
add:createDataBoxControl
1 parent ce41935 commit b0c5973

File tree

10 files changed

+159
-244
lines changed

10 files changed

+159
-244
lines changed

dist_2/package.json

-42
This file was deleted.

package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "js-databox",
3-
"version": "0.0.10",
3+
"version": "0.0.15",
44
"description": "",
5-
"main": "index.js",
6-
"types": "index.d.ts",
5+
"main": "./cjs/index.js",
6+
"module": "./esm/index.js",
77
"scripts": {
88
"build:types": "tsc",
9-
"build": "tsc -b && tsc -p tsconfig.json",
9+
"build": "rm -rf dist && tsc -p tsconfig.json && tsc -p tsconfig-esm.json",
1010
"test": "echo \"Error: no test specified\" && exit 1"
1111
},
1212
"keywords": [
@@ -31,12 +31,12 @@
3131
},
3232
"dependencies": {
3333
"@dfinity/agent": "^0.12.0",
34-
"@dfinity/candid": "^0.11.3",
35-
"@dfinity/principal": "^0.11.0",
34+
"@dfinity/candid": "^0.12.0",
35+
"@dfinity/principal": "^0.12.0",
3636
"@types/crypto-js": "^4.1.1",
3737
"buffer": "^6.0.3",
3838
"crypto-js": "^4.0.0",
39-
"nanoid": "^4.0.0",
39+
"nanoid": "^3.0.0",
4040
"string-random": "^0.1.3"
4141
}
4242
}

rollup.config.js

+8-21
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
1-
import resolve from "@rollup/plugin-node-resolve";
2-
import babel from "@rollup/plugin-babel";
3-
import commonjs from "rollup-plugin-commonjs";
4-
import typescript from "rollup-plugin-typescript";
5-
6-
export default {
7-
input: "src/index.ts", // 打包入口
8-
output: {
9-
// 打包出口
10-
file: "dist/index.js",
11-
format: "umd", // umd是兼容amd/cjs/iife的通用打包格式,适合浏览器
12-
name: "test", // cdn方式引入时挂载在window上面用的就是这个名字
13-
sourcemap: true,
1+
export default [
2+
{
3+
input: "src/index.js",
4+
output: [
5+
{ file: "dist/index.cjs.js", format: "cjs" },
6+
{ file: "dist/index.esm.js", format: "es" },
7+
],
148
},
15-
plugins: [
16-
// 打包插件
17-
resolve(), // 查找和打包node_modules中的第三方模块
18-
commonjs(), // 将 CommonJS 转换成 ES2015 模块供 Rollup 处理
19-
typescript(), // 解析TypeScript
20-
babel({ babelHelpers: "bundled" }), // babel配置,编译es6
21-
],
22-
};
9+
];

src/databox/databox.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {
99
Result_7,
1010
Result_9
1111
} from "./did/databox_type";
12-
import random from "string-random"
1312
import {nanoid} from "nanoid";
13+
import random from "string-random"
1414
import {Principal} from "@dfinity/principal";
1515
import {changePlainFilePermissionArg, shareFileArg} from "../types";
1616
import {AESEncryptApi, EncryptApi, RSAEncryptApi} from "../utils";
@@ -45,13 +45,15 @@ export class DataBox {
4545
}
4646
}
4747

48-
public async put_plain_files(files: File[], is_private: boolean): Promise<string[]> {
48+
public async put_plain_files(files: File[], is_private: boolean, key_arr?: string[]): Promise<string[]> {
4949
try {
50+
if (key_arr && key_arr.length !== files.length) throw new Error("文件数量与key数量不匹配")
5051
const Actor = this.DataBoxActor
51-
const keyArr: Array<string> = []
5252
const allPromise: Array<Promise<any>> = []
53-
for (const file of files) {
54-
const key = nanoid()
53+
const keyArr: string[] = []
54+
for (let i = 0; i < files.length; i++) {
55+
const file = files[i]
56+
const key = key_arr ? key_arr[i] : nanoid()
5557
keyArr.push(key)
5658
const total_size = file.size
5759
const total_index = Math.ceil(total_size / chunkSize)
@@ -136,13 +138,15 @@ export class DataBox {
136138
}
137139
}
138140

139-
public async put_encrypt_files(files: File[], is_private: boolean, publicKey: string): Promise<string[]> {
141+
public async put_encrypt_files(files: File[], is_private: boolean, publicKey: string, key_arr?: string[]): Promise<string[]> {
140142
try {
143+
if (key_arr && key_arr.length !== files.length) throw new Error("文件数量与key数量不匹配")
141144
const Actor = this.DataBoxActor
142145
const keyArr: Array<string> = []
143146
const allPromise: Array<any> = []
144-
for (const file of files) {
145-
const key = nanoid()
147+
for (let i = 0; i < files.length; i++) {
148+
const file = files[i]
149+
const key = key_arr ? key_arr[i] : nanoid()
146150
keyArr.push(key)
147151
const total_size = file.size
148152
const allData = await this.FileRead(file)

src/metabox/did/metabox.ts

+41-78
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
export const idlFactory = ({IDL}) => {
2-
const Branch = IDL.Rec();
3-
const List = IDL.Rec();
42
const Error = IDL.Variant({
53
'NoFreeBoxNum': IDL.Null,
64
'NoUnBoundOg': IDL.Null,
@@ -40,14 +38,31 @@ export const idlFactory = ({IDL}) => {
4038
'box_type': BoxType,
4139
});
4240
const CreateBoxArgs = IDL.Record({'metadata': BoxMetadata});
43-
const Result_6 = IDL.Variant({'ok': IDL.Principal, 'err': Error});
41+
const Result_5 = IDL.Variant({'ok': IDL.Principal, 'err': Error});
4442
const DelBoxArgs = IDL.Record({
4543
'cycleTo': IDL.Opt(IDL.Principal),
4644
'box_type': BoxType,
4745
'canisterId': IDL.Principal,
4846
});
49-
const Result_5 = IDL.Variant({'ok': IDL.Text, 'err': Error});
47+
const Result_4 = IDL.Variant({'ok': IDL.Text, 'err': Error});
5048
const BoxStatus = IDL.Variant({'stopped': IDL.Null, 'running': IDL.Null});
49+
const BoxState__1 = IDL.Record({
50+
'status': BoxStatus,
51+
'owner': IDL.Principal,
52+
'avatar_key': IDL.Text,
53+
'is_private': IDL.Bool,
54+
'box_name': IDL.Text,
55+
'box_type': BoxType,
56+
});
57+
const BackUp = IDL.Variant({
58+
'One': IDL.Vec(IDL.Tuple(IDL.Principal, IDL.Vec(IDL.Principal))),
59+
'Six': IDL.Vec(IDL.Tuple(IDL.Principal, IDL.Text)),
60+
'Two': IDL.Vec(IDL.Tuple(IDL.Principal, IDL.Nat)),
61+
'Seven': IDL.Vec(IDL.Principal),
62+
'Five': IDL.Vec(IDL.Tuple(IDL.Text, IDL.Principal)),
63+
'Four': IDL.Vec(IDL.Tuple(IDL.Principal, IDL.Principal)),
64+
'Three': IDL.Vec(IDL.Tuple(IDL.Principal, BoxState__1)),
65+
});
5166
const BoxState = IDL.Record({
5267
'status': BoxStatus,
5368
'owner': IDL.Principal,
@@ -56,7 +71,7 @@ export const idlFactory = ({IDL}) => {
5671
'box_name': IDL.Text,
5772
'box_type': BoxType,
5873
});
59-
const Result_4 = IDL.Variant({'ok': BoxState, 'err': Error});
74+
const Result_3 = IDL.Variant({'ok': BoxState, 'err': Error});
6075
const BoxAllInfo = IDL.Record({
6176
'status': BoxStatus,
6277
'owner': IDL.Principal,
@@ -66,49 +81,21 @@ export const idlFactory = ({IDL}) => {
6681
'box_name': IDL.Text,
6782
'box_type': BoxType,
6883
});
84+
const Result_2 = IDL.Variant({
85+
'ok': IDL.Vec(IDL.Principal),
86+
'err': Error,
87+
});
6988
const BoxInfo__1 = IDL.Record({
7089
'status': BoxStatus,
7190
'canister_id': IDL.Principal,
7291
'is_private': IDL.Bool,
7392
'box_name': IDL.Text,
7493
'box_type': BoxType,
7594
});
76-
const Hash = IDL.Nat32;
77-
const Key = IDL.Record({'key': BoxInfo__1, 'hash': Hash});
78-
List.fill(IDL.Opt(IDL.Tuple(IDL.Tuple(Key, IDL.Null), List)));
79-
const AssocList = IDL.Opt(IDL.Tuple(IDL.Tuple(Key, IDL.Null), List));
80-
const Leaf = IDL.Record({'size': IDL.Nat, 'keyvals': AssocList});
81-
const Trie = IDL.Variant({
82-
'branch': Branch,
83-
'leaf': Leaf,
84-
'empty': IDL.Null,
85-
});
86-
Branch.fill(IDL.Record({'left': Trie, 'size': IDL.Nat, 'right': Trie}));
87-
const Set = IDL.Variant({
88-
'branch': Branch,
89-
'leaf': Leaf,
90-
'empty': IDL.Null,
91-
});
92-
const Result_3 = IDL.Variant({
93-
'ok': IDL.Vec(IDL.Principal),
94-
'err': Error,
95-
});
9695
const TopUpArgs = IDL.Record({
9796
'box_id': IDL.Principal,
9897
'icp_amount': IDL.Nat64,
9998
});
100-
const AccountIdentifier = IDL.Vec(IDL.Nat8);
101-
const BlockIndex__1 = IDL.Nat64;
102-
const Token = IDL.Record({'e8s': IDL.Nat64});
103-
const BlockIndex = IDL.Nat64;
104-
const TransferError = IDL.Variant({
105-
'TxTooOld': IDL.Record({'allowed_window_nanos': IDL.Nat64}),
106-
'BadFee': IDL.Record({'expected_fee': Token}),
107-
'TxDuplicate': IDL.Record({'duplicate_of': BlockIndex}),
108-
'TxCreatedInFuture': IDL.Null,
109-
'InsufficientFunds': IDL.Record({'balance': Token}),
110-
});
111-
const Result_2 = IDL.Variant({'ok': BlockIndex__1, 'err': TransferError});
11299
const UpdateWasmArgs = IDL.Record({
113100
'wasm': IDL.Vec(IDL.Nat8),
114101
'box_type': BoxType,
@@ -125,23 +112,24 @@ export const idlFactory = ({IDL}) => {
125112
const MetaBox = IDL.Service({
126113
'acceptSharedBox': IDL.Func([IDL.Principal, IDL.Principal], [Result], []),
127114
'addAdmin': IDL.Func([IDL.Principal], [IDL.Bool], []),
128-
'boundOgDataboxOwner': IDL.Func(
129-
[IDL.Principal, IDL.Principal],
130-
[Result],
131-
[],
132-
),
115+
'addControlWhiteList': IDL.Func([IDL.Principal], [IDL.Bool], []),
133116
'burnxtc': IDL.Func([IDL.Nat], [RustResult], []),
134117
'changeAdmin': IDL.Func([IDL.Vec(IDL.Principal)], [IDL.Bool], []),
135118
'changeBoxAvatarKey': IDL.Func([IDL.Text], [], []),
136119
'clearLog': IDL.Func([], [], []),
137-
'createDataBoxFee': IDL.Func([CreateBoxArgs, IDL.Bool], [Result_6], []),
138-
'createDataBoxFree': IDL.Func([CreateBoxArgs], [Result_6], []),
139-
'createProfile': IDL.Func([IDL.Vec(IDL.Nat8)], [Result_6], []),
140-
'deleteBox': IDL.Func([DelBoxArgs], [Result_5], []),
120+
'createDataBoxControl': IDL.Func(
121+
[CreateBoxArgs, IDL.Bool, IDL.Opt(IDL.Principal)],
122+
[Result_5],
123+
[],
124+
),
125+
'createDataBoxFee': IDL.Func([CreateBoxArgs, IDL.Bool], [Result_5], []),
126+
'createDataBoxFree': IDL.Func([CreateBoxArgs], [Result_5], []),
127+
'createProfile': IDL.Func([IDL.Vec(IDL.Nat8)], [Result_5], []),
128+
'deleteBox': IDL.Func([DelBoxArgs], [Result_4], []),
141129
'emitShareBox': IDL.Func([IDL.Principal, IDL.Principal], [Result], []),
142-
'getActivitySet': IDL.Func([], [IDL.Vec(IDL.Principal)], ['query']),
143130
'getAdmins': IDL.Func([], [IDL.Vec(IDL.Principal)], ['query']),
144-
'getBoxState': IDL.Func([IDL.Principal], [Result_4], ['query']),
131+
'getBackUp': IDL.Func([IDL.Nat], [BackUp], ['query']),
132+
'getBoxState': IDL.Func([IDL.Principal], [Result_3], ['query']),
145133
'getBoxes': IDL.Func([IDL.Principal], [IDL.Vec(BoxAllInfo)], ['query']),
146134
'getCycleBalance': IDL.Func([], [IDL.Nat64], ['query']),
147135
'getDataBoxVersion': IDL.Func([], [IDL.Nat], ['query']),
@@ -153,18 +141,6 @@ export const idlFactory = ({IDL}) => {
153141
['query'],
154142
),
155143
'getNamePrin': IDL.Func([IDL.Principal], [IDL.Opt(IDL.Text)], ['query']),
156-
'getOGBoxes': IDL.Func([], [IDL.Vec(BoxInfo__1)], ['query']),
157-
'getOGNum': IDL.Func([], [IDL.Nat], ['query']),
158-
'getOGPreBoxes': IDL.Func(
159-
[IDL.Principal],
160-
[IDL.Vec(BoxInfo__1)],
161-
['query'],
162-
),
163-
'getOGUpBoxes': IDL.Func(
164-
[IDL.Principal],
165-
[IDL.Vec(BoxInfo__1)],
166-
['query'],
167-
),
168144
'getPre': IDL.Func([], [IDL.Nat, IDL.Nat], ['query']),
169145
'getPrincipalFromName': IDL.Func(
170146
[IDL.Text],
@@ -181,25 +157,14 @@ export const idlFactory = ({IDL}) => {
181157
'getSharedBoxes': IDL.Func([], [IDL.Vec(BoxAllInfo)], ['query']),
182158
'getTotal': IDL.Func([], [IDL.Nat, IDL.Nat], ['query']),
183159
'getUserBalance': IDL.Func([], [IDL.Opt(IDL.Nat)], ['query']),
184-
'getUserOgBox': IDL.Func(
185-
[],
186-
[IDL.Vec(IDL.Tuple(IDL.Principal, Set))],
187-
['query'],
188-
),
189-
'getUserPreBox': IDL.Func(
190-
[],
191-
[IDL.Vec(IDL.Tuple(IDL.Principal, Set))],
192-
['query'],
193-
),
194-
'initPreCreateDatabox': IDL.Func([], [Result_3], []),
195-
'initPreCreateProfile': IDL.Func([], [Result_3], []),
160+
'initPreCreateDatabox': IDL.Func([], [Result_2], []),
161+
'initPreCreateProfile': IDL.Func([], [Result_2], []),
196162
'installCycleWasm': IDL.Func([IDL.Vec(IDL.Nat8)], [Result], []),
197163
'isNotFirstDataBox': IDL.Func([], [IDL.Bool], ['query']),
198-
'preCreateDataBox': IDL.Func([], [Result_3], []),
164+
'preCreateDataBox': IDL.Func([], [Result_2], []),
199165
'preCreateDataBoxOne': IDL.Func([], [Result], []),
200-
'preCreateProfile': IDL.Func([], [Result_3], []),
201-
'preCreateProfileOne': IDL.Func([], [Result_3], []),
202-
'recoverOG': IDL.Func([IDL.Principal], [], []),
166+
'preCreateProfile': IDL.Func([], [Result_2], []),
167+
'preCreateProfileOne': IDL.Func([], [Result_2], []),
203168
'refreshBalance': IDL.Func([IDL.Principal], [], []),
204169
'removeShareBox': IDL.Func([IDL.Principal, IDL.Principal], [Result], []),
205170
'removeSharedBox': IDL.Func([IDL.Principal, IDL.Principal], [Result], []),
@@ -213,8 +178,6 @@ export const idlFactory = ({IDL}) => {
213178
[Result],
214179
[],
215180
),
216-
'transferOutICP': IDL.Func([AccountIdentifier, IDL.Nat64], [Result_2], []),
217-
'transferV1UserID': IDL.Func([IDL.Text, IDL.Principal], [Result], []),
218181
'updateBoxInfo': IDL.Func([BoxInfo__1], [Result], []),
219182
'updateDataBoxVersion': IDL.Func([IDL.Nat], [IDL.Bool], []),
220183
'updateProfileVersion': IDL.Func([IDL.Nat], [IDL.Bool], []),

0 commit comments

Comments
 (0)