wowok 1.7.13 → 1.7.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/arbitration.d.ts.map +1 -1
- package/dist/arbitration.js +21 -32
- package/dist/arbitration.js.map +1 -1
- package/dist/entity.d.ts +1 -0
- package/dist/entity.d.ts.map +1 -1
- package/dist/entity.js +12 -6
- package/dist/entity.js.map +1 -1
- package/dist/exception.d.ts +2 -1
- package/dist/exception.d.ts.map +1 -1
- package/dist/exception.js +1 -0
- package/dist/exception.js.map +1 -1
- package/dist/guard.d.ts.map +1 -1
- package/dist/guard.js +8 -4
- package/dist/guard.js.map +1 -1
- package/dist/payment.d.ts +2 -2
- package/dist/payment.d.ts.map +1 -1
- package/dist/payment.js +2 -2
- package/dist/payment.js.map +1 -1
- package/dist/protocol.d.ts +21 -19
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +211 -58
- package/dist/protocol.js.map +1 -1
- package/dist/service.d.ts +2 -2
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +5 -6
- package/dist/service.js.map +1 -1
- package/package.json +5 -2
- package/src/arbitration.ts +0 -551
- package/src/demand.ts +0 -300
- package/src/entity.ts +0 -171
- package/src/exception.ts +0 -37
- package/src/guard.ts +0 -810
- package/src/index.ts +0 -40
- package/src/machine.ts +0 -542
- package/src/passport.ts +0 -777
- package/src/payment.ts +0 -94
- package/src/permission.ts +0 -550
- package/src/progress.ts +0 -367
- package/src/protocol.ts +0 -549
- package/src/repository.ts +0 -680
- package/src/resource.ts +0 -155
- package/src/service.ts +0 -1349
- package/src/treasury.ts +0 -425
- package/src/utils.ts +0 -660
- package/src/wowok.ts +0 -70
- package/tsconfig.json +0 -30
- package/tsconfig.tsbuildinfo +0 -1
- package/webpack.config.cjs +0 -23
package/src/repository.ts
DELETED
|
@@ -1,680 +0,0 @@
|
|
|
1
|
-
import { Protocol, FnCallType, ValueType, RepositoryValueType, RepositoryAddress, PermissionObject, PassportObject, TxbObject, GuardObject, } from './protocol.js';
|
|
2
|
-
import { PermissionIndexType, Permission } from './permission.js'
|
|
3
|
-
import { Bcs, array_unique, IsValidDesription, IsValidAddress, IsValidArray, IsValidName, ValueTypeConvert, IsValidStringLength, uint2address} from './utils.js';
|
|
4
|
-
import { ERROR, Errors } from './exception.js';
|
|
5
|
-
import { MAX_U8, MAX_U128, MAX_U256, MAX_U64, parseObjectType } from './utils.js';
|
|
6
|
-
import { type TransactionResult, Transaction as TransactionBlock } from '@mysten/sui/transactions';
|
|
7
|
-
|
|
8
|
-
export enum Repository_Policy_Mode {
|
|
9
|
-
POLICY_MODE_FREE = 0,
|
|
10
|
-
POLICY_MODE_STRICT = 1,
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export enum Repository_Type {
|
|
14
|
-
NORMAL = 0,
|
|
15
|
-
WOWOK_GRANTEE = 1,
|
|
16
|
-
WOWOK_ORACLE = 2
|
|
17
|
-
}
|
|
18
|
-
export interface RepData {
|
|
19
|
-
id: string;
|
|
20
|
-
name: string;
|
|
21
|
-
dataType: RepositoryValueType;
|
|
22
|
-
data: string | string[];
|
|
23
|
-
object: string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface Repository_Policy {
|
|
27
|
-
key:string;
|
|
28
|
-
description: string;
|
|
29
|
-
dataType: RepositoryValueType;
|
|
30
|
-
permissionIndex?: PermissionIndexType | null; // PermissionIndex like, must be geater than 1000
|
|
31
|
-
}
|
|
32
|
-
export interface Repository_Policy_Data {
|
|
33
|
-
key: string;
|
|
34
|
-
data: Repository_Value[];
|
|
35
|
-
value_type?: ValueType; // Specifies a data type prefix; If the data prefix is already included in the data byte stream, there is no need to specify it.
|
|
36
|
-
}
|
|
37
|
-
export interface Repository_Value {
|
|
38
|
-
address: string; // UID: address or objectid
|
|
39
|
-
bcsBytes: Uint8Array; // BCS contents. Notice that: First Byte be the Type by caller, or specify type with 'Repository_Policy_Data.value_type' field.
|
|
40
|
-
}
|
|
41
|
-
export interface Repository_Value2 {
|
|
42
|
-
key: string;
|
|
43
|
-
bcsBytes: Uint8Array;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export interface Repository_Policy_Data2 {
|
|
47
|
-
address: string;
|
|
48
|
-
data: Repository_Value2[];
|
|
49
|
-
value_type?: ValueType;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export interface Repository_Policy_Data_Remove {
|
|
53
|
-
key: string;
|
|
54
|
-
address: string;
|
|
55
|
-
}
|
|
56
|
-
export class Repository {
|
|
57
|
-
protected permission ;
|
|
58
|
-
protected object:TxbObject;
|
|
59
|
-
protected txb;
|
|
60
|
-
|
|
61
|
-
get_object() { return this.object }
|
|
62
|
-
private constructor(txb:TransactionBlock, permission:PermissionObject) {
|
|
63
|
-
this.txb = txb;
|
|
64
|
-
this.permission = permission;
|
|
65
|
-
this.object = '';
|
|
66
|
-
}
|
|
67
|
-
static From(txb:TransactionBlock, permission:PermissionObject, object:TxbObject) : Repository {
|
|
68
|
-
let r = new Repository(txb, permission);
|
|
69
|
-
r.object = Protocol.TXB_OBJECT(txb, object);
|
|
70
|
-
return r
|
|
71
|
-
}
|
|
72
|
-
static New(txb:TransactionBlock, permission:PermissionObject, description:string,
|
|
73
|
-
policy_mode: Repository_Policy_Mode=Repository_Policy_Mode.POLICY_MODE_FREE, passport?:PassportObject) : Repository {
|
|
74
|
-
if (!Protocol.IsValidObjects([permission])) {
|
|
75
|
-
ERROR(Errors.IsValidObjects, 'permission')
|
|
76
|
-
}
|
|
77
|
-
if (!IsValidDesription(description)) {
|
|
78
|
-
ERROR(Errors.IsValidDesription)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
let r = new Repository(txb, permission);
|
|
82
|
-
|
|
83
|
-
if (passport) {
|
|
84
|
-
r.object = txb.moveCall({
|
|
85
|
-
target:Protocol.Instance().repositoryFn('new_with_passport') as FnCallType,
|
|
86
|
-
arguments:[passport, txb.pure.string(description), txb.pure.u8(policy_mode), Protocol.TXB_OBJECT(txb, permission)],
|
|
87
|
-
})
|
|
88
|
-
} else {
|
|
89
|
-
r.object = txb.moveCall({
|
|
90
|
-
target:Protocol.Instance().repositoryFn('new') as FnCallType,
|
|
91
|
-
arguments:[txb.pure.string(description), txb.pure.u8(policy_mode), Protocol.TXB_OBJECT(txb, permission)],
|
|
92
|
-
})
|
|
93
|
-
}
|
|
94
|
-
return r
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
launch() : RepositoryAddress {
|
|
98
|
-
return this.txb.moveCall({
|
|
99
|
-
target:Protocol.Instance().repositoryFn('create') as FnCallType,
|
|
100
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object)],
|
|
101
|
-
})
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
add_data(data:Repository_Policy_Data, passport?:PassportObject) {
|
|
105
|
-
if (!Repository.IsValidName(data.key)) {
|
|
106
|
-
ERROR(Errors.IsValidName, 'add_data')
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
data.data.forEach((value) => {
|
|
110
|
-
if (!IsValidAddress(value.address)) ERROR(Errors.IsValidAddress, `add_data.data.data.address ${value}` )
|
|
111
|
-
if (!Repository.IsValidValue(value.bcsBytes)) ERROR(Errors.IsValidValue, `add_data.data.data.bcsBytes ${value}` )
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
if (data?.value_type !== undefined) {
|
|
115
|
-
data.data.forEach((d) => {
|
|
116
|
-
if (passport) {
|
|
117
|
-
this.txb.moveCall({
|
|
118
|
-
target:Protocol.Instance().repositoryFn('add_with_passport') as FnCallType,
|
|
119
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
120
|
-
this.txb.pure.address(d.address),
|
|
121
|
-
this.txb.pure.string(data.key),
|
|
122
|
-
this.txb.pure.u8(data.value_type!),
|
|
123
|
-
this.txb.pure.vector('u8', [...d.bcsBytes]),
|
|
124
|
-
Protocol.TXB_OBJECT(this.txb, this.permission),
|
|
125
|
-
],
|
|
126
|
-
})
|
|
127
|
-
} else {
|
|
128
|
-
this.txb.moveCall({
|
|
129
|
-
target:Protocol.Instance().repositoryFn('add') as FnCallType,
|
|
130
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
131
|
-
this.txb.pure.address(d.address),
|
|
132
|
-
this.txb.pure.string(data.key),
|
|
133
|
-
this.txb.pure.u8(data.value_type!),
|
|
134
|
-
this.txb.pure.vector('u8', [...d.bcsBytes]),
|
|
135
|
-
Protocol.TXB_OBJECT(this.txb, this.permission),
|
|
136
|
-
],
|
|
137
|
-
})
|
|
138
|
-
}
|
|
139
|
-
})
|
|
140
|
-
} else {
|
|
141
|
-
data.data.forEach((d) => {
|
|
142
|
-
if (passport) {
|
|
143
|
-
this.txb.moveCall({
|
|
144
|
-
target:Protocol.Instance().repositoryFn('add_typed_data_with_passport') as FnCallType,
|
|
145
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
146
|
-
this.txb.pure.address(d.address),
|
|
147
|
-
this.txb.pure.string(data.key),
|
|
148
|
-
this.txb.pure.vector('u8', [...d.bcsBytes]),
|
|
149
|
-
Protocol.TXB_OBJECT(this.txb, this.permission),
|
|
150
|
-
],
|
|
151
|
-
})
|
|
152
|
-
} else {
|
|
153
|
-
this.txb.moveCall({
|
|
154
|
-
target:Protocol.Instance().repositoryFn('add_typed_data') as FnCallType,
|
|
155
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
156
|
-
this.txb.pure.address(d.address),
|
|
157
|
-
this.txb.pure.string(data.key),
|
|
158
|
-
this.txb.pure.vector('u8', [...d.bcsBytes]),
|
|
159
|
-
Protocol.TXB_OBJECT(this.txb, this.permission),
|
|
160
|
-
],
|
|
161
|
-
})
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
})
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
add_data2(data:Repository_Policy_Data2, passport?:PassportObject) {
|
|
169
|
-
if (!IsValidAddress(data.address)) {
|
|
170
|
-
ERROR(Errors.IsValidAddress, `add_data2.data.address ${data}`)
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
data.data.forEach((value) => {
|
|
175
|
-
if (!Repository.IsValidName(value.key)) ERROR(Errors.IsValidName, `add_data2.data.data.key ${value}`)
|
|
176
|
-
if (!Repository.IsValidValue(value.bcsBytes)) ERROR(Errors.IsValidValue, `add_data2.data.data.bcsBytes ${value}`)
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
if (data?.value_type !== undefined) {
|
|
180
|
-
data.data.forEach((d) => {
|
|
181
|
-
if (passport) {
|
|
182
|
-
this.txb.moveCall({
|
|
183
|
-
target:Protocol.Instance().repositoryFn('add_with_passport') as FnCallType,
|
|
184
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
185
|
-
this.txb.pure.address(data.address),
|
|
186
|
-
this.txb.pure.string(d.key),
|
|
187
|
-
this.txb.pure.u8(data.value_type!),
|
|
188
|
-
this.txb.pure.vector('u8', [...d.bcsBytes]),
|
|
189
|
-
Protocol.TXB_OBJECT(this.txb, this.permission),
|
|
190
|
-
],
|
|
191
|
-
})
|
|
192
|
-
} else {
|
|
193
|
-
this.txb.moveCall({
|
|
194
|
-
target:Protocol.Instance().repositoryFn('add') as FnCallType,
|
|
195
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
196
|
-
this.txb.pure.address(data.address),
|
|
197
|
-
this.txb.pure.string(d.key),
|
|
198
|
-
this.txb.pure.u8(data.value_type!),
|
|
199
|
-
this.txb.pure.vector('u8', [...d.bcsBytes]),
|
|
200
|
-
Protocol.TXB_OBJECT(this.txb, this.permission),
|
|
201
|
-
],
|
|
202
|
-
})
|
|
203
|
-
}
|
|
204
|
-
})
|
|
205
|
-
} else {
|
|
206
|
-
data.data.forEach((d) => {
|
|
207
|
-
if (passport) {
|
|
208
|
-
this.txb.moveCall({
|
|
209
|
-
target:Protocol.Instance().repositoryFn('add_typed_data_with_passport') as FnCallType,
|
|
210
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
211
|
-
this.txb.pure.address(data.address),
|
|
212
|
-
this.txb.pure.string(d.key),
|
|
213
|
-
this.txb.pure.vector('u8', [...d.bcsBytes]),
|
|
214
|
-
Protocol.TXB_OBJECT(this.txb, this.permission),
|
|
215
|
-
],
|
|
216
|
-
})
|
|
217
|
-
} else {
|
|
218
|
-
this.txb.moveCall({
|
|
219
|
-
target:Protocol.Instance().repositoryFn('add_typed_data') as FnCallType,
|
|
220
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
221
|
-
this.txb.pure.address(data.address),
|
|
222
|
-
this.txb.pure.string(d.key),
|
|
223
|
-
this.txb.pure.vector('u8', [...d.bcsBytes]),
|
|
224
|
-
Protocol.TXB_OBJECT(this.txb, this.permission),
|
|
225
|
-
],
|
|
226
|
-
})
|
|
227
|
-
}
|
|
228
|
-
})
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
remove(address:string, key:string, passport?:PassportObject) {
|
|
233
|
-
if (!Repository.IsValidName(key)) {
|
|
234
|
-
ERROR(Errors.IsValidName)
|
|
235
|
-
}
|
|
236
|
-
if (!IsValidAddress(address)) {
|
|
237
|
-
ERROR(Errors.IsValidAddress)
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (passport) {
|
|
241
|
-
this.txb.moveCall({
|
|
242
|
-
target:Protocol.Instance().repositoryFn('remove_with_passport') as FnCallType,
|
|
243
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
244
|
-
this.txb.pure.address(address),
|
|
245
|
-
this.txb.pure.string(key),
|
|
246
|
-
Protocol.TXB_OBJECT(this.txb, this.permission),
|
|
247
|
-
],
|
|
248
|
-
})
|
|
249
|
-
} else {
|
|
250
|
-
this.txb.moveCall({
|
|
251
|
-
target:Protocol.Instance().repositoryFn('remove') as FnCallType,
|
|
252
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
253
|
-
this.txb.pure.address(address),
|
|
254
|
-
this.txb.pure.string(key),
|
|
255
|
-
Protocol.TXB_OBJECT(this.txb, this.permission),
|
|
256
|
-
],
|
|
257
|
-
})
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
add_reference(references:string[], passport?:PassportObject) {
|
|
262
|
-
if (references.length === 0) return;
|
|
263
|
-
if (!IsValidArray(references, IsValidAddress)) {
|
|
264
|
-
ERROR(Errors.IsValidArray, 'add_reference')
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
if (passport) {
|
|
268
|
-
this.txb.moveCall({
|
|
269
|
-
target:Protocol.Instance().repositoryFn('reference_add_with_passport') as FnCallType,
|
|
270
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
271
|
-
this.txb.pure.vector('address', array_unique(references)),
|
|
272
|
-
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
273
|
-
})
|
|
274
|
-
} else {
|
|
275
|
-
this.txb.moveCall({
|
|
276
|
-
target:Protocol.Instance().repositoryFn('reference_add') as FnCallType,
|
|
277
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
278
|
-
this.txb.pure.vector('address', array_unique(references)),
|
|
279
|
-
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
280
|
-
})
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
remove_reference(references:string[], removeall?:boolean, passport?:PassportObject) {
|
|
284
|
-
if (references.length === 0 && !removeall) return
|
|
285
|
-
|
|
286
|
-
if (!IsValidArray(references, IsValidAddress)) {
|
|
287
|
-
ERROR(Errors.IsValidArray, 'remove_reference')
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
if (removeall) {
|
|
291
|
-
if (passport) {
|
|
292
|
-
this.txb.moveCall({
|
|
293
|
-
target:Protocol.Instance().repositoryFn('reference_removeall_with_passport') as FnCallType,
|
|
294
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
295
|
-
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
296
|
-
})
|
|
297
|
-
} else {
|
|
298
|
-
this.txb.moveCall({
|
|
299
|
-
target:Protocol.Instance().repositoryFn('reference_removeall') as FnCallType,
|
|
300
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
301
|
-
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
302
|
-
})
|
|
303
|
-
}
|
|
304
|
-
} else {
|
|
305
|
-
if (passport) {
|
|
306
|
-
this.txb.moveCall({
|
|
307
|
-
target:Protocol.Instance().repositoryFn('reference_remove_with_passport') as FnCallType,
|
|
308
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
309
|
-
this.txb.pure.vector('address', array_unique(references)),
|
|
310
|
-
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
311
|
-
})
|
|
312
|
-
} else {
|
|
313
|
-
this.txb.moveCall({
|
|
314
|
-
target:Protocol.Instance().repositoryFn('reference_remove') as FnCallType,
|
|
315
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
316
|
-
this.txb.pure.vector('address', array_unique(references)),
|
|
317
|
-
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
318
|
-
})
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
// add or modify the old
|
|
323
|
-
add_policies(policies:Repository_Policy[], passport?:PassportObject) {
|
|
324
|
-
if (policies.length === 0) return;
|
|
325
|
-
|
|
326
|
-
policies.forEach((p) => {
|
|
327
|
-
if (!IsValidDesription(p.description)) ERROR(Errors.IsValidDesription, `add_policies.policies.description ${p}`)
|
|
328
|
-
if (!Repository.IsValidName(p.key)) ERROR(Errors.IsValidName, `add_policies.policies.key ${p}`)
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
policies.forEach((policy) => {
|
|
332
|
-
let permission_index = this.txb.pure.option('u64', policy?.permissionIndex ? policy?.permissionIndex : undefined);
|
|
333
|
-
if (passport) {
|
|
334
|
-
this.txb.moveCall({
|
|
335
|
-
target:Protocol.Instance().repositoryFn('policy_add_with_passport') as FnCallType,
|
|
336
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
337
|
-
this.txb.pure.string(policy.key),
|
|
338
|
-
this.txb.pure.string(policy.description),
|
|
339
|
-
permission_index, this.txb.pure.u8(policy.dataType),
|
|
340
|
-
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
341
|
-
})
|
|
342
|
-
} else {
|
|
343
|
-
this.txb.moveCall({
|
|
344
|
-
target:Protocol.Instance().repositoryFn('policy_add') as FnCallType,
|
|
345
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
346
|
-
this.txb.pure.string(policy.key),
|
|
347
|
-
this.txb.pure.string(policy.description),
|
|
348
|
-
permission_index, this.txb.pure.u8(policy.dataType),
|
|
349
|
-
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
350
|
-
})
|
|
351
|
-
}
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
remove_policies(policy_keys:string[], removeall?:boolean, passport?:PassportObject) {
|
|
356
|
-
if (policy_keys.length === 0) return ;
|
|
357
|
-
if (!IsValidArray(policy_keys, Repository.IsValidName)){
|
|
358
|
-
ERROR(Errors.InvalidParam, 'policy_keys')
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
if (passport) {
|
|
362
|
-
if (removeall) {
|
|
363
|
-
this.txb.moveCall({
|
|
364
|
-
target:Protocol.Instance().repositoryFn('policy_removeall_with_passport') as FnCallType,
|
|
365
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
366
|
-
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
367
|
-
})
|
|
368
|
-
} else {
|
|
369
|
-
this.txb.moveCall({
|
|
370
|
-
target:Protocol.Instance().repositoryFn('policy_remove_with_passport') as FnCallType,
|
|
371
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
372
|
-
this.txb.pure.vector('string', array_unique(policy_keys)),
|
|
373
|
-
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
374
|
-
})
|
|
375
|
-
}
|
|
376
|
-
} else {
|
|
377
|
-
if (removeall) {
|
|
378
|
-
this.txb.moveCall({
|
|
379
|
-
target:Protocol.Instance().repositoryFn('policy_removeall') as FnCallType,
|
|
380
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
381
|
-
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
382
|
-
})
|
|
383
|
-
} else {
|
|
384
|
-
this.txb.moveCall({
|
|
385
|
-
target:Protocol.Instance().repositoryFn('policy_remove') as FnCallType,
|
|
386
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
387
|
-
this.txb.pure.vector('string', array_unique(policy_keys)),
|
|
388
|
-
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
389
|
-
})
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
rename_policy(policy_key:string, new_policy_key:string, passport?:PassportObject) {
|
|
394
|
-
if (!IsValidName(policy_key) || !IsValidName(new_policy_key)) {
|
|
395
|
-
ERROR(Errors.IsValidName, 'change_policy')
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
if (passport) {
|
|
399
|
-
this.txb.moveCall({
|
|
400
|
-
target:Protocol.Instance().repositoryFn('policy_rename_with_passport') as FnCallType,
|
|
401
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object),
|
|
402
|
-
this.txb.pure.string(policy_key), this.txb.pure.string(new_policy_key),
|
|
403
|
-
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
404
|
-
})
|
|
405
|
-
} else {
|
|
406
|
-
this.txb.moveCall({
|
|
407
|
-
target:Protocol.Instance().repositoryFn('policy_rename') as FnCallType,
|
|
408
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object),
|
|
409
|
-
this.txb.pure.string(policy_key), this.txb.pure.string(new_policy_key),
|
|
410
|
-
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
411
|
-
})
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
// PermissionIndex.description_set
|
|
416
|
-
set_description(description:string, passport?:PassportObject) {
|
|
417
|
-
if (!IsValidDesription(description)){
|
|
418
|
-
ERROR(Errors.IsValidDesription)
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
if (passport) {
|
|
422
|
-
this.txb.moveCall({
|
|
423
|
-
target:Protocol.Instance().repositoryFn('description_set_with_passport') as FnCallType,
|
|
424
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(description), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
425
|
-
})
|
|
426
|
-
} else {
|
|
427
|
-
this.txb.moveCall({
|
|
428
|
-
target:Protocol.Instance().repositoryFn('description_set') as FnCallType,
|
|
429
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(description), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
430
|
-
})
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
set_policy_mode(policy_mode:Repository_Policy_Mode, passport?:PassportObject) {
|
|
436
|
-
if (passport) {
|
|
437
|
-
this.txb.moveCall({
|
|
438
|
-
target:Protocol.Instance().repositoryFn('mode_set_with_passport') as FnCallType,
|
|
439
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.u8(policy_mode), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
440
|
-
})
|
|
441
|
-
} else {
|
|
442
|
-
this.txb.moveCall({
|
|
443
|
-
target:Protocol.Instance().repositoryFn('mode_set') as FnCallType,
|
|
444
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.u8(policy_mode), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
445
|
-
})
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
set_guard(guard?:GuardObject | null, passport?:PassportObject) {
|
|
450
|
-
if (guard && !Protocol.IsValidObjects([guard])) {
|
|
451
|
-
ERROR(Errors.IsValidObjects, `set_guard.guard ${guard}`);
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
if (passport) {
|
|
455
|
-
if (guard) {
|
|
456
|
-
this.txb.moveCall({
|
|
457
|
-
target:Protocol.Instance().repositoryFn('guard_set_with_passport') as FnCallType,
|
|
458
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, guard), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
459
|
-
})
|
|
460
|
-
} else {
|
|
461
|
-
this.txb.moveCall({
|
|
462
|
-
target:Protocol.Instance().repositoryFn('guard_none_with_passport') as FnCallType,
|
|
463
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
464
|
-
})
|
|
465
|
-
}
|
|
466
|
-
} else {
|
|
467
|
-
if (guard) {
|
|
468
|
-
this.txb.moveCall({
|
|
469
|
-
target:Protocol.Instance().repositoryFn('guard_set') as FnCallType,
|
|
470
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, guard), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
471
|
-
})
|
|
472
|
-
} else {
|
|
473
|
-
this.txb.moveCall({
|
|
474
|
-
target:Protocol.Instance().repositoryFn('guard_none') as FnCallType,
|
|
475
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
476
|
-
})
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
set_policy_description(policy:string, description:string, passport?:PassportObject) {
|
|
482
|
-
if (!Repository.IsValidName(policy)) {
|
|
483
|
-
ERROR(Errors.IsValidName, 'policy')
|
|
484
|
-
}
|
|
485
|
-
if (!IsValidDesription(description)) {
|
|
486
|
-
ERROR(Errors.IsValidDesription)
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
if (passport) {
|
|
490
|
-
this.txb.moveCall({
|
|
491
|
-
target:Protocol.Instance().repositoryFn('policy_description_set_with_passport') as FnCallType,
|
|
492
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(policy), this.txb.pure.string(description),
|
|
493
|
-
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
494
|
-
})
|
|
495
|
-
} else {
|
|
496
|
-
this.txb.moveCall({
|
|
497
|
-
target:Protocol.Instance().repositoryFn('policy_description_set') as FnCallType,
|
|
498
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), this.txb.pure.string(policy), this.txb.pure.string(description),
|
|
499
|
-
Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
500
|
-
})
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
set_policy_permission(policy:string, permission_index?:number, passport?:PassportObject) {
|
|
505
|
-
if (!Repository.IsValidName(policy)) {
|
|
506
|
-
ERROR(Errors.IsValidName, 'policy')
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
let index = this.txb.pure.option('u64', undefined);
|
|
510
|
-
if (permission_index !== undefined) {
|
|
511
|
-
if(!Permission.IsValidPermissionIndex(permission_index)) {
|
|
512
|
-
ERROR(Errors.IsValidPermissionIndex)
|
|
513
|
-
}
|
|
514
|
-
index = this.txb.pure.option('u64', permission_index);
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
if (passport) {
|
|
518
|
-
this.txb.moveCall({
|
|
519
|
-
target:Protocol.Instance().repositoryFn('policy_permission_set_with_passport') as FnCallType,
|
|
520
|
-
arguments:[passport, Protocol.TXB_OBJECT(this.txb, this.object), index, Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
521
|
-
})
|
|
522
|
-
} else {
|
|
523
|
-
this.txb.moveCall({
|
|
524
|
-
target:Protocol.Instance().repositoryFn('policy_permission_set') as FnCallType,
|
|
525
|
-
arguments:[Protocol.TXB_OBJECT(this.txb, this.object), index, Protocol.TXB_OBJECT(this.txb, this.permission)]
|
|
526
|
-
})
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
change_permission(new_permission:PermissionObject) {
|
|
531
|
-
if (!Protocol.IsValidObjects([new_permission])) {
|
|
532
|
-
ERROR(Errors.IsValidObjects)
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
this.txb.moveCall({
|
|
536
|
-
target:Protocol.Instance().repositoryFn('permission_set') as FnCallType,
|
|
537
|
-
arguments: [Protocol.TXB_OBJECT(this.txb, this.object), Protocol.TXB_OBJECT(this.txb, this.permission), Protocol.TXB_OBJECT(this.txb, new_permission)],
|
|
538
|
-
typeArguments:[]
|
|
539
|
-
})
|
|
540
|
-
this.permission = new_permission
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
static MAX_POLICY_COUNT = 120;
|
|
544
|
-
static MAX_KEY_LENGTH = 128;
|
|
545
|
-
static MAX_VALUE_LENGTH = 204800;
|
|
546
|
-
static MAX_REFERENCE_COUNT = 100;
|
|
547
|
-
static MAX_POLICY_DESRIPTION_LENGTH = 256;
|
|
548
|
-
|
|
549
|
-
static IsValidName = (key:string) => {
|
|
550
|
-
return IsValidStringLength(key, Repository.MAX_KEY_LENGTH) && key.length != 0;
|
|
551
|
-
}
|
|
552
|
-
static IsValidPolicyDescription(description:string) {
|
|
553
|
-
return IsValidStringLength(description, Repository.MAX_POLICY_DESRIPTION_LENGTH)
|
|
554
|
-
|
|
555
|
-
}
|
|
556
|
-
static IsValidValue = (value:Uint8Array) => {
|
|
557
|
-
return value.length < Repository.MAX_VALUE_LENGTH;
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
static rpc_de_data(fields:any) : RepData [] {
|
|
561
|
-
const rep: RepData[] = fields?.map((v:any) => {
|
|
562
|
-
const value = new Uint8Array((v?.data?.content?.fields as any)?.value);
|
|
563
|
-
const type = value?.length > 0 ? value[0] as ValueType : null;
|
|
564
|
-
var d : any = value.length > 0 ? value.slice(1) : Uint8Array.from([]);
|
|
565
|
-
if (type === ValueType.TYPE_STRING) {
|
|
566
|
-
d = Bcs.getInstance().de(ValueType.TYPE_VEC_U8, d);
|
|
567
|
-
d = new TextDecoder().decode(Uint8Array.from(d));
|
|
568
|
-
} else if (type === ValueType.TYPE_VEC_STRING) {
|
|
569
|
-
d = Bcs.getInstance().de(ValueType.TYPE_VEC_VEC_U8, d) as [];
|
|
570
|
-
d = d.map((i:any) => {
|
|
571
|
-
return new TextDecoder().decode(Uint8Array.from(i));
|
|
572
|
-
})
|
|
573
|
-
} else {
|
|
574
|
-
d = Bcs.getInstance().de(value[0], d);
|
|
575
|
-
if (type === ValueType.TYPE_ADDRESS) {
|
|
576
|
-
//d = '0x' + d;
|
|
577
|
-
} else if (type === ValueType.TYPE_VEC_ADDRESS) {
|
|
578
|
-
//d = d.map((v:string) => { return ('0x' + v) } );
|
|
579
|
-
} else if (type === ValueType.TYPE_BOOL) {
|
|
580
|
-
d = d ? 'True' : 'False'
|
|
581
|
-
}
|
|
582
|
-
};
|
|
583
|
-
return {object:v?.data?.content?.fields?.id?.id, id:(v?.data?.content?.fields as any)?.name?.fields?.id,
|
|
584
|
-
name:(v?.data?.content?.fields as any)?.name?.fields?.key,
|
|
585
|
-
data:d, dataType: ValueTypeConvert(type)
|
|
586
|
-
}
|
|
587
|
-
});
|
|
588
|
-
return rep;
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
static DataType2ValueType(data:string | number | bigint) : ValueType | undefined {
|
|
592
|
-
try {
|
|
593
|
-
const value = BigInt(data);
|
|
594
|
-
if (value < 0n) return;
|
|
595
|
-
|
|
596
|
-
if (value <= MAX_U8) {
|
|
597
|
-
return ValueType.TYPE_U8
|
|
598
|
-
} else if (value <= MAX_U64) {
|
|
599
|
-
return ValueType.TYPE_U64;
|
|
600
|
-
} else if (value <= MAX_U128) {
|
|
601
|
-
return ValueType.TYPE_U128;
|
|
602
|
-
} else if (value <= MAX_U256) {
|
|
603
|
-
return ValueType.TYPE_U256;
|
|
604
|
-
}
|
|
605
|
-
} catch (e) {
|
|
606
|
-
//console.log(e)
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
static ResolveRepositoryData = (dataType:RepositoryValueType, data:bigint | string | boolean | number | string[] | number[])
|
|
611
|
-
: {type:ValueType, data: Uint8Array} | undefined => {
|
|
612
|
-
if (dataType === RepositoryValueType.String) {
|
|
613
|
-
if (data instanceof Array) {
|
|
614
|
-
ERROR(Errors.Fail, `ResolveRepositoryData resolve RepositoryValueType.String but array ${data}`);
|
|
615
|
-
}
|
|
616
|
-
return {type: ValueType.TYPE_STRING, data: Bcs.getInstance().ser(ValueType.TYPE_STRING, data.toString())}
|
|
617
|
-
} else if (dataType === RepositoryValueType.PositiveNumber) {
|
|
618
|
-
if (data instanceof Array) {
|
|
619
|
-
ERROR(Errors.Fail, `ResolveRepositoryData resolve RepositoryValueType.PositiveNumber but array ${data}`);
|
|
620
|
-
}
|
|
621
|
-
const t = Repository.DataType2ValueType(data as string);
|
|
622
|
-
if (!t) ERROR(Errors.Fail, `ResolveRepositoryData resolve RepositoryValueType.PositiveNumber ${data}`);
|
|
623
|
-
|
|
624
|
-
return {type:t!, data:Bcs.getInstance().ser(t!, data)}
|
|
625
|
-
} else if (dataType === RepositoryValueType.Address) {
|
|
626
|
-
if (typeof(data) === 'boolean') {
|
|
627
|
-
ERROR(Errors.Fail, `ResolveRepositoryData resolve RepositoryValueType.Address but boolean ${data}`);
|
|
628
|
-
}
|
|
629
|
-
if (data instanceof Array) {
|
|
630
|
-
ERROR(Errors.Fail, `ResolveRepositoryData resolve RepositoryValueType.Address but array ${data}`);
|
|
631
|
-
}
|
|
632
|
-
let addr: string | undefined ;
|
|
633
|
-
if (typeof data === 'string') {
|
|
634
|
-
addr = data as string;
|
|
635
|
-
} else {
|
|
636
|
-
addr = uint2address(data as number | bigint);
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
if (!IsValidAddress(addr)) ERROR(Errors.Fail, `ResolveRepositoryData resolve RepositoryValueType.Address ${data}`)
|
|
640
|
-
return {type:ValueType.TYPE_ADDRESS, data:Bcs.getInstance().ser(ValueType.TYPE_ADDRESS, addr)}
|
|
641
|
-
} else if (dataType === RepositoryValueType.Address_Vec) {
|
|
642
|
-
if (!(data instanceof Array)) {
|
|
643
|
-
ERROR(Errors.Fail, `ResolveRepositoryData resolve RepositoryValueType.Address_Vec but not array ${data}`);
|
|
644
|
-
}
|
|
645
|
-
const addrs = [];
|
|
646
|
-
for(let i = 0; i < (data as string[]).length; ++i) {
|
|
647
|
-
if (!IsValidAddress((data as string[])[i])) ERROR(Errors.Fail, `ResolveRepositoryData resolve RepositoryValueType.Address_Vec ${data}`);
|
|
648
|
-
addrs.push((data as string[])[i]);
|
|
649
|
-
}
|
|
650
|
-
return {type:ValueType.TYPE_VEC_ADDRESS, data:Bcs.getInstance().ser(ValueType.TYPE_VEC_ADDRESS, addrs)}
|
|
651
|
-
} else if (dataType === RepositoryValueType.PositiveNumber_Vec) {
|
|
652
|
-
if (!(data instanceof Array)) ERROR(Errors.Fail, `ResolveRepositoryData resolve RepositoryValueType.PositiveNumber_Vec but not array ${data}`);
|
|
653
|
-
|
|
654
|
-
let type = ValueType.TYPE_U8;
|
|
655
|
-
for(let i = 0; i < (data as string[]).length; ++i) {
|
|
656
|
-
const t = Repository.DataType2ValueType(data as string);
|
|
657
|
-
if (!t) ERROR(Errors.Fail, `ResolveRepositoryData resolve RepositoryValueType.PositiveNumber_Vec ${data}`);
|
|
658
|
-
if (t! > type) type = t!;
|
|
659
|
-
}
|
|
660
|
-
if (type === ValueType.TYPE_U8) {
|
|
661
|
-
type = ValueType.TYPE_VEC_U8;
|
|
662
|
-
} else if (type === ValueType.TYPE_U64) {
|
|
663
|
-
type = ValueType.TYPE_VEC_U64;
|
|
664
|
-
} else if (type === ValueType.TYPE_U128) {
|
|
665
|
-
type = ValueType.TYPE_VEC_U128;
|
|
666
|
-
} else {
|
|
667
|
-
type = ValueType.TYPE_VEC_U256;
|
|
668
|
-
}
|
|
669
|
-
return {type:type, data:Bcs.getInstance().ser(type, data)}
|
|
670
|
-
} else if (dataType === RepositoryValueType.String_Vec) {
|
|
671
|
-
if (!(data instanceof Array)) ERROR(Errors.Fail, `ResolveRepositoryData resolve RepositoryValueType.String_Vec but not array ${data}`);
|
|
672
|
-
return {type: ValueType.TYPE_VEC_STRING, data: Bcs.getInstance().ser(ValueType.TYPE_VEC_STRING, data)}
|
|
673
|
-
} else if (dataType === RepositoryValueType.Bool) {
|
|
674
|
-
if (typeof(data) !== 'boolean') ERROR(Errors.Fail, `ResolveRepositoryData resolve RepositoryValueType.Bool ${data}`);
|
|
675
|
-
return {type:ValueType.TYPE_BOOL, data:Bcs.getInstance().ser(ValueType.TYPE_BOOL, data)}
|
|
676
|
-
}
|
|
677
|
-
ERROR(Errors.Fail, `ResolveRepositoryData resolve RepositoryValueType ${dataType}`)
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
|