wowok 1.6.84 → 1.6.85
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/permission.d.ts +1 -1
- package/dist/permission.d.ts.map +1 -1
- package/dist/permission.js +0 -45
- package/package.json +1 -1
- package/src/permission.ts +18 -60
- package/tsconfig.json +112 -112
- package/dist/empty.d.ts +0 -1
- package/dist/empty.d.ts.map +0 -1
- package/dist/empty.js +0 -1
- package/dist/src/arbitration.d.ts +0 -61
- package/dist/src/arbitration.d.ts.map +0 -1
- package/dist/src/arbitration.js +0 -473
- package/dist/src/demand.d.ts +0 -26
- package/dist/src/demand.d.ts.map +0 -1
- package/dist/src/demand.js +0 -256
- package/dist/src/entity.d.ts +0 -27
- package/dist/src/entity.d.ts.map +0 -1
- package/dist/src/entity.js +0 -95
- package/dist/src/exception.d.ts +0 -31
- package/dist/src/exception.d.ts.map +0 -1
- package/dist/src/exception.js +0 -34
- package/dist/src/guard.d.ts +0 -79
- package/dist/src/guard.d.ts.map +0 -1
- package/dist/src/guard.js +0 -749
- package/dist/src/index.d.ts +0 -25
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -24
- package/dist/src/machine.d.ts +0 -67
- package/dist/src/machine.d.ts.map +0 -1
- package/dist/src/machine.js +0 -518
- package/dist/src/passport.d.ts +0 -86
- package/dist/src/passport.d.ts.map +0 -1
- package/dist/src/passport.js +0 -645
- package/dist/src/payment.d.ts +0 -16
- package/dist/src/payment.d.ts.map +0 -1
- package/dist/src/payment.js +0 -41
- package/dist/src/permission.d.ts +0 -150
- package/dist/src/permission.d.ts.map +0 -1
- package/dist/src/permission.js +0 -502
- package/dist/src/progress.d.ts +0 -72
- package/dist/src/progress.d.ts.map +0 -1
- package/dist/src/progress.js +0 -301
- package/dist/src/protocol.d.ts +0 -226
- package/dist/src/protocol.d.ts.map +0 -1
- package/dist/src/protocol.js +0 -482
- package/dist/src/repository.d.ts +0 -83
- package/dist/src/repository.d.ts.map +0 -1
- package/dist/src/repository.js +0 -528
- package/dist/src/resource.d.ts +0 -35
- package/dist/src/resource.d.ts.map +0 -1
- package/dist/src/resource.js +0 -130
- package/dist/src/service.d.ts +0 -128
- package/dist/src/service.d.ts.map +0 -1
- package/dist/src/service.js +0 -1234
- package/dist/src/treasury.d.ts +0 -55
- package/dist/src/treasury.d.ts.map +0 -1
- package/dist/src/treasury.js +0 -396
- package/dist/src/utils.d.ts +0 -93
- package/dist/src/utils.d.ts.map +0 -1
- package/dist/src/utils.js +0 -616
- package/dist/src/wowok.d.ts +0 -15
- package/dist/src/wowok.d.ts.map +0 -1
- package/dist/src/wowok.js +0 -67
package/dist/src/passport.js
DELETED
|
@@ -1,645 +0,0 @@
|
|
|
1
|
-
import { Inputs } from '@mysten/sui/transactions';
|
|
2
|
-
import { Protocol, ContextType, OperatorType, ValueType, SER_VALUE } from './protocol';
|
|
3
|
-
import { parse_object_type, array_unique, Bcs, ulebDecode, IsValidAddress, IsValidArray, readOption, readOptionString } from './utils';
|
|
4
|
-
import { ERROR, Errors } from './exception';
|
|
5
|
-
import { Guard, GuardMaker } from './guard';
|
|
6
|
-
export class GuardParser {
|
|
7
|
-
guard_list = [];
|
|
8
|
-
guards;
|
|
9
|
-
constructor(guards) {
|
|
10
|
-
this.guards = guards;
|
|
11
|
-
}
|
|
12
|
-
guardlist = () => { return this.guard_list; };
|
|
13
|
-
static DeGuardObject_FromData = (guard_constants, guard_input_bytes) => {
|
|
14
|
-
let constants = GuardParser.parse_constant(guard_constants);
|
|
15
|
-
// console.log(constants)
|
|
16
|
-
let inputs = GuardParser.parse_bcs(constants, guard_input_bytes);
|
|
17
|
-
// console.log(data);
|
|
18
|
-
if (!inputs || inputs.length == 0)
|
|
19
|
-
ERROR(Errors.Fail, 'GuardObject: data parsed error');
|
|
20
|
-
let stack = [];
|
|
21
|
-
inputs.forEach((d) => {
|
|
22
|
-
GuardParser.ResolveData(constants, stack, { ...d, child: [] });
|
|
23
|
-
});
|
|
24
|
-
if (stack.length != 1) {
|
|
25
|
-
ERROR(Errors.Fail, 'GuardObject: parse error');
|
|
26
|
-
}
|
|
27
|
-
return { object: stack.pop(), constant: constants };
|
|
28
|
-
};
|
|
29
|
-
/// convert guard-on-chain to js object
|
|
30
|
-
static DeGuardObject = async (protocol, guard) => {
|
|
31
|
-
if (!IsValidAddress(guard)) {
|
|
32
|
-
ERROR(Errors.IsValidAddress, 'GuardObject guard');
|
|
33
|
-
}
|
|
34
|
-
let res = await protocol.query_raw([guard]);
|
|
35
|
-
if (res.length == 0 || !res[0].data || res[0].data?.objectId != guard) {
|
|
36
|
-
ERROR(Errors.Fail, 'GuardObject query error');
|
|
37
|
-
}
|
|
38
|
-
// console.log(res[0].data?.content);
|
|
39
|
-
let content = res[0].data.content;
|
|
40
|
-
if (content?.type != protocol.package('base') + '::guard::Guard') {
|
|
41
|
-
ERROR(Errors.Fail, 'GuardObject object invalid');
|
|
42
|
-
}
|
|
43
|
-
return GuardParser.DeGuardObject_FromData(content.fields.constants, content.fields.input.fields.bytes);
|
|
44
|
-
};
|
|
45
|
-
static ResolveData = (constants, stack, current) => {
|
|
46
|
-
switch (current.type) {
|
|
47
|
-
case OperatorType.TYPE_LOGIC_NOT:
|
|
48
|
-
current.ret_type = ValueType.TYPE_BOOL;
|
|
49
|
-
if (stack.length < 1)
|
|
50
|
-
ERROR(Errors.Fail, 'ResolveData: TYPE_LOGIC_NOT');
|
|
51
|
-
let param = stack.pop();
|
|
52
|
-
if (!param.ret_type || param.ret_type != ValueType.TYPE_BOOL) {
|
|
53
|
-
ERROR(Errors.Fail, 'ResolveData: TYPE_LOGIC_NOT type invalid');
|
|
54
|
-
}
|
|
55
|
-
current.child.push(param);
|
|
56
|
-
stack.push(current);
|
|
57
|
-
return;
|
|
58
|
-
case OperatorType.TYPE_LOGIC_AS_U256_GREATER:
|
|
59
|
-
case OperatorType.TYPE_LOGIC_AS_U256_GREATER_EQUAL:
|
|
60
|
-
case OperatorType.TYPE_LOGIC_AS_U256_LESSER:
|
|
61
|
-
case OperatorType.TYPE_LOGIC_AS_U256_LESSER_EQUAL:
|
|
62
|
-
case OperatorType.TYPE_LOGIC_AS_U256_EQUAL:
|
|
63
|
-
case OperatorType.TYPE_NUMBER_ADD:
|
|
64
|
-
case OperatorType.TYPE_NUMBER_DEVIDE:
|
|
65
|
-
case OperatorType.TYPE_NUMBER_MOD:
|
|
66
|
-
case OperatorType.TYPE_NUMBER_MULTIPLY:
|
|
67
|
-
case OperatorType.TYPE_NUMBER_SUBTRACT:
|
|
68
|
-
if (current.type === OperatorType.TYPE_LOGIC_AS_U256_GREATER || current.type === OperatorType.TYPE_LOGIC_AS_U256_GREATER_EQUAL ||
|
|
69
|
-
current.type === OperatorType.TYPE_LOGIC_AS_U256_LESSER || current.type === OperatorType.TYPE_LOGIC_AS_U256_LESSER_EQUAL ||
|
|
70
|
-
current.type === OperatorType.TYPE_LOGIC_AS_U256_EQUAL) {
|
|
71
|
-
current.ret_type = ValueType.TYPE_BOOL;
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
current.ret_type = ValueType.TYPE_U256;
|
|
75
|
-
}
|
|
76
|
-
if (stack.length < current.value || current.value < 2)
|
|
77
|
-
ERROR(Errors.Fail, 'ResolveData: ' + current.type);
|
|
78
|
-
for (let i = 0; i < current.value; ++i) {
|
|
79
|
-
var p = stack.pop();
|
|
80
|
-
if (!p.ret_type || !GuardMaker.match_u256(p.ret_type))
|
|
81
|
-
ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' INVALID param type');
|
|
82
|
-
current.child.push(p);
|
|
83
|
-
}
|
|
84
|
-
stack.push(current);
|
|
85
|
-
return;
|
|
86
|
-
case OperatorType.TYPE_LOGIC_EQUAL:
|
|
87
|
-
current.ret_type = ValueType.TYPE_BOOL;
|
|
88
|
-
if (stack.length < current.value || current.value < 2)
|
|
89
|
-
ERROR(Errors.Fail, 'ResolveData: ' + current.type);
|
|
90
|
-
var p0 = stack.pop();
|
|
91
|
-
current.child.push(p0);
|
|
92
|
-
for (let i = 1; i < current.value; ++i) {
|
|
93
|
-
var p = stack.pop();
|
|
94
|
-
if (!p.ret_type || (p.ret_type != p0.ret_type))
|
|
95
|
-
ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' INVALID param type');
|
|
96
|
-
current.child.push(p);
|
|
97
|
-
}
|
|
98
|
-
stack.push(current);
|
|
99
|
-
return;
|
|
100
|
-
case OperatorType.TYPE_LOGIC_HAS_SUBSTRING:
|
|
101
|
-
current.ret_type = ValueType.TYPE_BOOL;
|
|
102
|
-
if (stack.length < current.value || current.value < 2)
|
|
103
|
-
ERROR(Errors.Fail, 'ResolveData: ' + current.type);
|
|
104
|
-
for (let i = 0; i < current.value; ++i) {
|
|
105
|
-
var p = stack.pop();
|
|
106
|
-
if (!p.ret_type || (p.ret_type != ValueType.TYPE_STRING))
|
|
107
|
-
ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' INVALID param type');
|
|
108
|
-
current.child.push(p);
|
|
109
|
-
}
|
|
110
|
-
stack.push(current);
|
|
111
|
-
return;
|
|
112
|
-
case OperatorType.TYPE_LOGIC_AND:
|
|
113
|
-
case OperatorType.TYPE_LOGIC_OR:
|
|
114
|
-
current.ret_type = ValueType.TYPE_BOOL;
|
|
115
|
-
if (stack.length < current.value || current.value < 2)
|
|
116
|
-
ERROR(Errors.Fail, 'ResolveData: ' + current.type);
|
|
117
|
-
for (let i = 0; i < current.value; ++i) {
|
|
118
|
-
var p = stack.pop();
|
|
119
|
-
if (!p.ret_type || (p.ret_type != ValueType.TYPE_BOOL))
|
|
120
|
-
ERROR(Errors.Fail, 'ResolveData: ' + current.type + ' INVALID param type');
|
|
121
|
-
current.child.push(p);
|
|
122
|
-
}
|
|
123
|
-
stack.push(current);
|
|
124
|
-
return;
|
|
125
|
-
case OperatorType.TYPE_QUERY:
|
|
126
|
-
if (!current?.cmd)
|
|
127
|
-
ERROR(Errors.Fail, 'OperateParamCount: cmd invalid ' + current.type);
|
|
128
|
-
let r = Guard.GetCmd(current.cmd);
|
|
129
|
-
if (!r)
|
|
130
|
-
ERROR(Errors.Fail, 'OperateParamCount: cmd not supported ' + current.type);
|
|
131
|
-
current.ret_type = r[4];
|
|
132
|
-
if (stack.length < r[3].length)
|
|
133
|
-
ERROR(Errors.Fail, 'OperateParamCount: cmd param lost ' + current.type);
|
|
134
|
-
r[3].forEach((e) => {
|
|
135
|
-
let d = stack.pop();
|
|
136
|
-
if (!d?.ret_type || d.ret_type != e) {
|
|
137
|
-
ERROR(Errors.Fail, 'OperateParamCount: cmd param not match ' + current.type);
|
|
138
|
-
}
|
|
139
|
-
current.child.push(d);
|
|
140
|
-
});
|
|
141
|
-
stack.push(current);
|
|
142
|
-
return;
|
|
143
|
-
case ValueType.TYPE_ADDRESS:
|
|
144
|
-
case ValueType.TYPE_BOOL:
|
|
145
|
-
case ValueType.TYPE_U128:
|
|
146
|
-
case ValueType.TYPE_U256:
|
|
147
|
-
case ValueType.TYPE_U64:
|
|
148
|
-
case ValueType.TYPE_U8:
|
|
149
|
-
case ValueType.TYPE_VEC_ADDRESS:
|
|
150
|
-
case ValueType.TYPE_VEC_BOOL:
|
|
151
|
-
case ValueType.TYPE_VEC_U128:
|
|
152
|
-
case ValueType.TYPE_VEC_U256:
|
|
153
|
-
case ValueType.TYPE_VEC_U64:
|
|
154
|
-
case ValueType.TYPE_VEC_U8:
|
|
155
|
-
case ValueType.TYPE_VEC_VEC_U8:
|
|
156
|
-
case ValueType.TYPE_OPTION_ADDRESS:
|
|
157
|
-
case ValueType.TYPE_OPTION_BOOL:
|
|
158
|
-
case ValueType.TYPE_OPTION_U128:
|
|
159
|
-
case ValueType.TYPE_OPTION_U256:
|
|
160
|
-
case ValueType.TYPE_OPTION_U64:
|
|
161
|
-
case ValueType.TYPE_OPTION_U8:
|
|
162
|
-
case ValueType.TYPE_STRING:
|
|
163
|
-
current.ret_type = current.type;
|
|
164
|
-
stack.push(current);
|
|
165
|
-
return;
|
|
166
|
-
case ContextType.TYPE_CLOCK:
|
|
167
|
-
current.ret_type = ValueType.TYPE_U64;
|
|
168
|
-
stack.push(current);
|
|
169
|
-
return;
|
|
170
|
-
case ContextType.TYPE_SIGNER:
|
|
171
|
-
current.ret_type = ValueType.TYPE_ADDRESS;
|
|
172
|
-
stack.push(current);
|
|
173
|
-
return;
|
|
174
|
-
case ContextType.TYPE_GUARD:
|
|
175
|
-
current.ret_type = ValueType.TYPE_ADDRESS;
|
|
176
|
-
stack.push(current);
|
|
177
|
-
return;
|
|
178
|
-
case ContextType.TYPE_CONSTANT:
|
|
179
|
-
let v = constants.find((e) => e.identifier == current?.identifier);
|
|
180
|
-
if (!v)
|
|
181
|
-
ERROR(Errors.Fail, 'OperateParamCount: identifier invalid ' + current.type);
|
|
182
|
-
current.ret_type = v?.type;
|
|
183
|
-
stack.push(current);
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
ERROR(Errors.Fail, 'OperateParamCount: type invalid ' + current.type);
|
|
187
|
-
};
|
|
188
|
-
static Parse_Guard_Helper(guards, res) {
|
|
189
|
-
const protocol = Protocol.Instance();
|
|
190
|
-
const me = new GuardParser(guards);
|
|
191
|
-
res.forEach((r) => {
|
|
192
|
-
const c = r.data?.content;
|
|
193
|
-
if (!c)
|
|
194
|
-
ERROR(Errors.Fail, 'Parse_Guard_Helper invalid content');
|
|
195
|
-
const index = protocol.WOWOK_OBJECTS_TYPE().findIndex(v => { return v.includes('guard::Guard') && v == c.type; });
|
|
196
|
-
if (index === -1)
|
|
197
|
-
ERROR(Errors.Fail, 'Parse_Guard_Helper invalid type: ' + c.type);
|
|
198
|
-
if (c.fields.input.type === (protocol.package('base') + '::bcs::BCS')) {
|
|
199
|
-
const constants = GuardParser.parse_constant(c.fields.constants); // MUST first
|
|
200
|
-
const inputs = GuardParser.parse_bcs(constants, Uint8Array.from(c.fields.input.fields.bytes));
|
|
201
|
-
me.guard_list.push({ id: c.fields.id.id, input: [...inputs], constant: [...constants], digest: r.data?.digest ?? '', version: r.data?.version ?? '' });
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
ERROR(Errors.Fail, 'Parse_Guard_Helper invalid package: ' + c.fields.input.type);
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
return me;
|
|
208
|
-
}
|
|
209
|
-
static Create = async (guards, onGuardInfo) => {
|
|
210
|
-
if (!IsValidArray(guards, IsValidAddress)) {
|
|
211
|
-
if (onGuardInfo)
|
|
212
|
-
onGuardInfo(undefined);
|
|
213
|
-
return undefined;
|
|
214
|
-
}
|
|
215
|
-
let guard_list = array_unique(guards);
|
|
216
|
-
if (onGuardInfo) {
|
|
217
|
-
Protocol.Instance().query_raw(guard_list)
|
|
218
|
-
.then((res) => {
|
|
219
|
-
onGuardInfo(GuardParser.Parse_Guard_Helper(guards, res));
|
|
220
|
-
}).catch((e) => {
|
|
221
|
-
console.log(e);
|
|
222
|
-
onGuardInfo(undefined);
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
const res = await Protocol.Instance().query_raw(guard_list);
|
|
227
|
-
return GuardParser.Parse_Guard_Helper(guards, res);
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
future_fills = () => {
|
|
231
|
-
const ret = [];
|
|
232
|
-
this.guard_list.forEach((g) => {
|
|
233
|
-
// cmd already in query_list, so filter it out.
|
|
234
|
-
//console.log(g.constant); console.log(g.input)
|
|
235
|
-
g.constant.filter((i) => i.bWitness).forEach((v) => {
|
|
236
|
-
const cmd = g.input.filter((k) => k.identifier === v.identifier && k.cmd !== undefined).map((k) => k.cmd);
|
|
237
|
-
let cited = 0;
|
|
238
|
-
g.input.forEach((k) => {
|
|
239
|
-
if (k.identifier === v.identifier)
|
|
240
|
-
cited++;
|
|
241
|
-
});
|
|
242
|
-
ret.push({ guard: g.id, witness: undefined, identifier: v.identifier, type: v.type, cmd: cmd ?? [], cited: cited });
|
|
243
|
-
});
|
|
244
|
-
});
|
|
245
|
-
return ret;
|
|
246
|
-
};
|
|
247
|
-
static parse_constant = (constants) => {
|
|
248
|
-
let ret = [];
|
|
249
|
-
constants.forEach((c) => {
|
|
250
|
-
let v = c?.fields ?? c; // graphql dosnot 'fields', but rpcall has.
|
|
251
|
-
const data = Uint8Array.from(v.value);
|
|
252
|
-
const type = data.slice(0, 1)[0];
|
|
253
|
-
if (v.bWitness) { //@ witness
|
|
254
|
-
ret.push({ identifier: v.identifier, type: type, bWitness: v.bWitness, value: undefined });
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
257
|
-
var value = data.slice(1);
|
|
258
|
-
switch (type) {
|
|
259
|
-
case ValueType.TYPE_ADDRESS:
|
|
260
|
-
value = '0x' + Bcs.getInstance().de(ValueType.TYPE_ADDRESS, Uint8Array.from(value)).toString();
|
|
261
|
-
break;
|
|
262
|
-
case ValueType.TYPE_BOOL:
|
|
263
|
-
case ValueType.TYPE_U8:
|
|
264
|
-
case ValueType.TYPE_U64:
|
|
265
|
-
case ValueType.TYPE_U128:
|
|
266
|
-
case ValueType.TYPE_U256:
|
|
267
|
-
case ValueType.TYPE_VEC_U8:
|
|
268
|
-
case ValueType.TYPE_VEC_U64:
|
|
269
|
-
case ValueType.TYPE_VEC_U128:
|
|
270
|
-
case ValueType.TYPE_VEC_ADDRESS:
|
|
271
|
-
case ValueType.TYPE_VEC_BOOL:
|
|
272
|
-
case ValueType.TYPE_VEC_VEC_U8:
|
|
273
|
-
case ValueType.TYPE_OPTION_ADDRESS:
|
|
274
|
-
case ValueType.TYPE_OPTION_BOOL:
|
|
275
|
-
case ValueType.TYPE_OPTION_U128:
|
|
276
|
-
case ValueType.TYPE_OPTION_U8:
|
|
277
|
-
case ValueType.TYPE_OPTION_U64:
|
|
278
|
-
case ValueType.TYPE_OPTION_U256:
|
|
279
|
-
case ValueType.TYPE_VEC_U256:
|
|
280
|
-
case ValueType.TYPE_STRING:
|
|
281
|
-
case ValueType.TYPE_OPTION_STRING:
|
|
282
|
-
case ValueType.TYPE_OPTION_VEC_U8:
|
|
283
|
-
case ValueType.TYPE_VEC_STRING:
|
|
284
|
-
let de = SER_VALUE.find(s => s.type == type);
|
|
285
|
-
if (!de)
|
|
286
|
-
ERROR(Errors.Fail, 'GuardObject de error');
|
|
287
|
-
value = Bcs.getInstance().de(type, Uint8Array.from(value));
|
|
288
|
-
break;
|
|
289
|
-
default:
|
|
290
|
-
ERROR(Errors.Fail, 'GuardObject constant type invalid:' + type);
|
|
291
|
-
}
|
|
292
|
-
ret.push({ identifier: v.identifier, type: type, bWitness: v.bWitness, value: value });
|
|
293
|
-
});
|
|
294
|
-
return ret;
|
|
295
|
-
};
|
|
296
|
-
static parse_bcs = (constants, chain_bytes) => {
|
|
297
|
-
let bytes = Uint8Array.from(chain_bytes);
|
|
298
|
-
let arr = [].slice.call(bytes.reverse());
|
|
299
|
-
let data = [];
|
|
300
|
-
while (arr.length > 0) {
|
|
301
|
-
let type = arr.shift();
|
|
302
|
-
let value;
|
|
303
|
-
let cmd;
|
|
304
|
-
let identifier;
|
|
305
|
-
switch (type) {
|
|
306
|
-
case ContextType.TYPE_SIGNER:
|
|
307
|
-
case ContextType.TYPE_CLOCK:
|
|
308
|
-
case ContextType.TYPE_GUARD:
|
|
309
|
-
case OperatorType.TYPE_LOGIC_NOT:
|
|
310
|
-
break;
|
|
311
|
-
case OperatorType.TYPE_LOGIC_AS_U256_GREATER:
|
|
312
|
-
case OperatorType.TYPE_LOGIC_AS_U256_GREATER_EQUAL:
|
|
313
|
-
case OperatorType.TYPE_LOGIC_AS_U256_LESSER:
|
|
314
|
-
case OperatorType.TYPE_LOGIC_AS_U256_LESSER_EQUAL:
|
|
315
|
-
case OperatorType.TYPE_LOGIC_AS_U256_EQUAL:
|
|
316
|
-
case OperatorType.TYPE_LOGIC_EQUAL:
|
|
317
|
-
case OperatorType.TYPE_LOGIC_HAS_SUBSTRING:
|
|
318
|
-
case OperatorType.TYPE_NUMBER_ADD:
|
|
319
|
-
case OperatorType.TYPE_NUMBER_DEVIDE:
|
|
320
|
-
case OperatorType.TYPE_NUMBER_MOD:
|
|
321
|
-
case OperatorType.TYPE_NUMBER_MULTIPLY:
|
|
322
|
-
case OperatorType.TYPE_NUMBER_SUBTRACT:
|
|
323
|
-
case OperatorType.TYPE_LOGIC_AND: //@ with logics count
|
|
324
|
-
case OperatorType.TYPE_LOGIC_OR:
|
|
325
|
-
value = arr.shift();
|
|
326
|
-
break;
|
|
327
|
-
case ContextType.TYPE_CONSTANT:
|
|
328
|
-
identifier = arr.shift(); // identifier
|
|
329
|
-
break;
|
|
330
|
-
case ValueType.TYPE_ADDRESS:
|
|
331
|
-
value = '0x' + Bcs.getInstance().de(ValueType.TYPE_ADDRESS, Uint8Array.from(arr)).toString();
|
|
332
|
-
arr.splice(0, 32); // address
|
|
333
|
-
break;
|
|
334
|
-
case ValueType.TYPE_BOOL:
|
|
335
|
-
case ValueType.TYPE_U8:
|
|
336
|
-
value = Bcs.getInstance().de(type, Uint8Array.from(arr));
|
|
337
|
-
arr.shift();
|
|
338
|
-
break;
|
|
339
|
-
case ValueType.TYPE_U64:
|
|
340
|
-
value = Bcs.getInstance().de(type, Uint8Array.from(arr));
|
|
341
|
-
arr.splice(0, 8);
|
|
342
|
-
break;
|
|
343
|
-
case ValueType.TYPE_U128:
|
|
344
|
-
value = Bcs.getInstance().de(type, Uint8Array.from(arr));
|
|
345
|
-
arr.splice(0, 16);
|
|
346
|
-
break;
|
|
347
|
-
case ValueType.TYPE_U256:
|
|
348
|
-
value = Bcs.getInstance().de(type, Uint8Array.from(arr));
|
|
349
|
-
arr.splice(0, 32);
|
|
350
|
-
break;
|
|
351
|
-
case ValueType.TYPE_VEC_U8:
|
|
352
|
-
case ValueType.TYPE_VEC_BOOL:
|
|
353
|
-
case ValueType.TYPE_STRING:
|
|
354
|
-
let r = ulebDecode(Uint8Array.from(arr));
|
|
355
|
-
value = Bcs.getInstance().de(type, Uint8Array.from(arr));
|
|
356
|
-
arr.splice(0, r.value + r.length);
|
|
357
|
-
break;
|
|
358
|
-
case ValueType.TYPE_VEC_ADDRESS:
|
|
359
|
-
r = ulebDecode(Uint8Array.from(arr));
|
|
360
|
-
value = Bcs.getInstance().de(type, Uint8Array.from(arr));
|
|
361
|
-
arr.splice(0, r.value * 32 + r.length);
|
|
362
|
-
break;
|
|
363
|
-
case ValueType.TYPE_VEC_U128:
|
|
364
|
-
r = ulebDecode(Uint8Array.from(arr));
|
|
365
|
-
value = Bcs.getInstance().de(type, Uint8Array.from(arr));
|
|
366
|
-
arr.splice(0, r.value * 16 + r.length);
|
|
367
|
-
break;
|
|
368
|
-
case ValueType.TYPE_VEC_U256:
|
|
369
|
-
r = ulebDecode(Uint8Array.from(arr));
|
|
370
|
-
value = Bcs.getInstance().de(type, Uint8Array.from(arr));
|
|
371
|
-
arr.splice(0, r.value * 32 + r.length);
|
|
372
|
-
break;
|
|
373
|
-
case ValueType.TYPE_VEC_U64:
|
|
374
|
-
r = ulebDecode(Uint8Array.from(arr));
|
|
375
|
-
value = Bcs.getInstance().de(type, Uint8Array.from(arr));
|
|
376
|
-
arr.splice(0, r.value * 8 + r.length);
|
|
377
|
-
break;
|
|
378
|
-
case ValueType.TYPE_VEC_VEC_U8:
|
|
379
|
-
case ValueType.TYPE_VEC_STRING:
|
|
380
|
-
r = ulebDecode(Uint8Array.from(arr));
|
|
381
|
-
arr.splice(0, r.length);
|
|
382
|
-
let res = [];
|
|
383
|
-
for (let i = 0; i < r.value; i++) {
|
|
384
|
-
let r2 = ulebDecode(Uint8Array.from(arr));
|
|
385
|
-
res.push(Bcs.getInstance().de(ValueType.TYPE_VEC_U8, Uint8Array.from(arr)));
|
|
386
|
-
arr.splice(0, r2.length + r2.value);
|
|
387
|
-
}
|
|
388
|
-
value = res;
|
|
389
|
-
break;
|
|
390
|
-
case OperatorType.TYPE_QUERY:
|
|
391
|
-
let t = arr.splice(0, 1); // data-type
|
|
392
|
-
if (t[0] == ValueType.TYPE_ADDRESS) {
|
|
393
|
-
let addr = '0x' + Bcs.getInstance().de(ValueType.TYPE_ADDRESS, Uint8Array.from(arr)).toString();
|
|
394
|
-
arr.splice(0, 32); // address
|
|
395
|
-
value = addr;
|
|
396
|
-
cmd = Bcs.getInstance().de('u16', Uint8Array.from(arr.splice(0, 2))); // cmd(u16)
|
|
397
|
-
}
|
|
398
|
-
else if (t[0] == ContextType.TYPE_CONSTANT) {
|
|
399
|
-
let id = arr.splice(0, 1); // key
|
|
400
|
-
let v = constants.find((v) => (v.identifier == id[0]) &&
|
|
401
|
-
((v.type == ValueType.TYPE_ADDRESS)));
|
|
402
|
-
if (!v) {
|
|
403
|
-
ERROR(Errors.Fail, 'GuardObject: indentifier not in constant');
|
|
404
|
-
}
|
|
405
|
-
identifier = id[0];
|
|
406
|
-
cmd = Bcs.getInstance().de('u16', Uint8Array.from(arr.splice(0, 2))); // cmd(u16)
|
|
407
|
-
}
|
|
408
|
-
else {
|
|
409
|
-
ERROR(Errors.Fail, 'GuardObject: constant type invalid');
|
|
410
|
-
}
|
|
411
|
-
break;
|
|
412
|
-
case ValueType.TYPE_OPTION_ADDRESS:
|
|
413
|
-
let read = readOption(arr, ValueType.TYPE_ADDRESS);
|
|
414
|
-
value = read.value;
|
|
415
|
-
if (!read.bNone)
|
|
416
|
-
arr.splice(0, 32);
|
|
417
|
-
break;
|
|
418
|
-
case ValueType.TYPE_OPTION_BOOL:
|
|
419
|
-
read = readOption(arr, ValueType.TYPE_BOOL);
|
|
420
|
-
value = read.value;
|
|
421
|
-
if (!read.bNone)
|
|
422
|
-
arr.splice(0, 1);
|
|
423
|
-
break;
|
|
424
|
-
case ValueType.TYPE_OPTION_U8:
|
|
425
|
-
read = readOption(arr, ValueType.TYPE_U8);
|
|
426
|
-
value = read.value;
|
|
427
|
-
if (!read.bNone)
|
|
428
|
-
arr.splice(0, 1);
|
|
429
|
-
break;
|
|
430
|
-
case ValueType.TYPE_OPTION_U128:
|
|
431
|
-
read = readOption(arr, ValueType.TYPE_U128);
|
|
432
|
-
value = read.value;
|
|
433
|
-
if (!read.bNone)
|
|
434
|
-
arr.splice(0, 16);
|
|
435
|
-
break;
|
|
436
|
-
case ValueType.TYPE_OPTION_U256:
|
|
437
|
-
read = readOption(arr, ValueType.TYPE_U256);
|
|
438
|
-
value = read.value;
|
|
439
|
-
if (!read.bNone)
|
|
440
|
-
arr.splice(0, 32);
|
|
441
|
-
break;
|
|
442
|
-
case ValueType.TYPE_OPTION_U64:
|
|
443
|
-
read = readOption(arr, ValueType.TYPE_U64);
|
|
444
|
-
value = read.value;
|
|
445
|
-
if (!read.bNone)
|
|
446
|
-
arr.splice(0, 8);
|
|
447
|
-
break;
|
|
448
|
-
case ValueType.TYPE_OPTION_STRING:
|
|
449
|
-
read = readOptionString(arr); // splice in it
|
|
450
|
-
value = read.value;
|
|
451
|
-
break;
|
|
452
|
-
default:
|
|
453
|
-
ERROR(Errors.Fail, 'GuardObject: parse_bcs types ' + type);
|
|
454
|
-
}
|
|
455
|
-
data.push({ type: type, value: value, cmd: cmd, identifier: identifier });
|
|
456
|
-
}
|
|
457
|
-
return data;
|
|
458
|
-
};
|
|
459
|
-
done = async (fill, onPassportQueryReady) => {
|
|
460
|
-
let objects = [];
|
|
461
|
-
// check all witness and get all objects to query.
|
|
462
|
-
this.guard_list.forEach((g) => {
|
|
463
|
-
g.constant.forEach((v) => {
|
|
464
|
-
if (v.bWitness) {
|
|
465
|
-
const value = fill?.find((i) => i.identifier === v.identifier);
|
|
466
|
-
if (!value) {
|
|
467
|
-
ERROR(Errors.Fail, 'done: invalid witness ' + v.identifier);
|
|
468
|
-
}
|
|
469
|
-
else {
|
|
470
|
-
v.value = value.witness;
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
});
|
|
474
|
-
g.input.filter((v) => v.cmd !== undefined).forEach((i) => {
|
|
475
|
-
if (i.identifier !== undefined) {
|
|
476
|
-
const value = g.constant.find((c) => c.identifier === i.identifier && c.type === ValueType.TYPE_ADDRESS);
|
|
477
|
-
if (!value || !IsValidAddress(value.value))
|
|
478
|
-
ERROR(Errors.Fail, 'done: invalid identifier ' + i.identifier);
|
|
479
|
-
objects.push(value.value);
|
|
480
|
-
}
|
|
481
|
-
else {
|
|
482
|
-
objects.push(i.value);
|
|
483
|
-
}
|
|
484
|
-
});
|
|
485
|
-
});
|
|
486
|
-
if (onPassportQueryReady) {
|
|
487
|
-
if (objects.length === 0) {
|
|
488
|
-
onPassportQueryReady(this.done_helper([]));
|
|
489
|
-
return;
|
|
490
|
-
}
|
|
491
|
-
Protocol.Instance().query_raw(array_unique(objects), { showType: true }).then((res) => {
|
|
492
|
-
onPassportQueryReady(this.done_helper(res));
|
|
493
|
-
}).catch(e => {
|
|
494
|
-
console.log(e);
|
|
495
|
-
onPassportQueryReady(undefined);
|
|
496
|
-
});
|
|
497
|
-
return undefined;
|
|
498
|
-
}
|
|
499
|
-
else {
|
|
500
|
-
let res = [];
|
|
501
|
-
if (objects.length > 0) {
|
|
502
|
-
res = await Protocol.Instance().query_raw(array_unique(objects), { showType: true });
|
|
503
|
-
}
|
|
504
|
-
return this.done_helper(res);
|
|
505
|
-
}
|
|
506
|
-
};
|
|
507
|
-
done_helper(res) {
|
|
508
|
-
let query = [];
|
|
509
|
-
let guards = [];
|
|
510
|
-
this.guard_list.forEach(g => {
|
|
511
|
-
guards.push(g.id);
|
|
512
|
-
g.input.filter((v) => v.cmd !== undefined).forEach(q => {
|
|
513
|
-
let id = q.value;
|
|
514
|
-
if (!id && q.identifier !== undefined) {
|
|
515
|
-
id = g.constant.find((i) => i.identifier == q.identifier)?.value;
|
|
516
|
-
}
|
|
517
|
-
let r = res.find(r => r.data?.objectId == id);
|
|
518
|
-
if (!r) {
|
|
519
|
-
ERROR(Errors.Fail, 'query object not match');
|
|
520
|
-
}
|
|
521
|
-
let object = this.object_query(r.data); // build passport query objects
|
|
522
|
-
if (!object) {
|
|
523
|
-
ERROR(Errors.Fail, 'query object fail');
|
|
524
|
-
}
|
|
525
|
-
query.push(object);
|
|
526
|
-
});
|
|
527
|
-
});
|
|
528
|
-
return { query: query, info: this.guard_list };
|
|
529
|
-
}
|
|
530
|
-
// create onchain query for objects : object, movecall-types, id
|
|
531
|
-
object_query = (data, method = 'guard_query') => {
|
|
532
|
-
for (let k = 0; k < Protocol.Instance().WOWOK_OBJECTS_TYPE().length; k++) {
|
|
533
|
-
if (data.type.includes(Protocol.Instance().WOWOK_OBJECTS_TYPE()[k])) { // type: pack::m::Object<...>
|
|
534
|
-
return { target: Protocol.Instance().WOWOK_OBJECTS_PREFIX_TYPE()[k] + method,
|
|
535
|
-
object: Inputs.SharedObjectRef({
|
|
536
|
-
objectId: data.objectId,
|
|
537
|
-
mutable: false,
|
|
538
|
-
initialSharedVersion: data.version,
|
|
539
|
-
}),
|
|
540
|
-
types: parse_object_type(data.type),
|
|
541
|
-
id: data.objectId, };
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
};
|
|
545
|
-
}
|
|
546
|
-
export class Passport {
|
|
547
|
-
static MAX_GUARD_COUNT = 8;
|
|
548
|
-
passport;
|
|
549
|
-
txb;
|
|
550
|
-
get_object() { return this.passport; }
|
|
551
|
-
// return passport object used
|
|
552
|
-
// bObject(true) in cmd env; (false) in service env
|
|
553
|
-
constructor(txb, query, bObject = false) {
|
|
554
|
-
if (query.info.length === 0 || query.info.length > Passport.MAX_GUARD_COUNT) {
|
|
555
|
-
ERROR(Errors.InvalidParam, 'guards');
|
|
556
|
-
}
|
|
557
|
-
this.txb = txb; //console.log(query)
|
|
558
|
-
this.passport = this.txb.moveCall({
|
|
559
|
-
target: Protocol.Instance().passportFn('new'),
|
|
560
|
-
arguments: []
|
|
561
|
-
});
|
|
562
|
-
// add others guards, if any
|
|
563
|
-
query.info.forEach((g) => {
|
|
564
|
-
const ids = g.constant.filter((i) => i.bWitness).map((v) => v.identifier);
|
|
565
|
-
const values = g.constant.filter((i) => i.bWitness).map((v) => {
|
|
566
|
-
const bcs = Bcs.getInstance().ser(v.type, v.value);
|
|
567
|
-
let r = new Uint8Array(bcs.length + 1);
|
|
568
|
-
r.set([v.type], 0);
|
|
569
|
-
r.set(bcs, 1);
|
|
570
|
-
return [].slice.call(r);
|
|
571
|
-
});
|
|
572
|
-
const guard = g.version !== undefined && g.digest !== undefined ?
|
|
573
|
-
txb.objectRef({ objectId: g.id, version: g.version, digest: g.digest }) :
|
|
574
|
-
txb.object(g.id);
|
|
575
|
-
//console.log(ids); console.log(values)
|
|
576
|
-
this.txb.moveCall({
|
|
577
|
-
target: Protocol.Instance().passportFn('guard_add'),
|
|
578
|
-
arguments: [this.passport, guard, this.txb.pure.vector('u8', [].slice.call(ids)),
|
|
579
|
-
this.txb.pure(Bcs.getInstance().ser('vector<vector<u8>>', [...values]))]
|
|
580
|
-
});
|
|
581
|
-
});
|
|
582
|
-
const clock = this.txb.sharedObjectRef(Protocol.CLOCK_OBJECT);
|
|
583
|
-
// rules: 'verify' & 'query' in turns; 'verify' at final end.
|
|
584
|
-
query?.query.forEach((q) => {
|
|
585
|
-
this.txb.moveCall({
|
|
586
|
-
target: Protocol.Instance().passportFn('passport_verify'),
|
|
587
|
-
arguments: [this.passport, this.txb.object(clock)]
|
|
588
|
-
});
|
|
589
|
-
this.txb.moveCall({
|
|
590
|
-
target: q.target,
|
|
591
|
-
arguments: [bObject ? this.txb.object(q.object) : this.txb.object(q.id), this.passport],
|
|
592
|
-
typeArguments: q.types,
|
|
593
|
-
});
|
|
594
|
-
});
|
|
595
|
-
this.txb.moveCall({
|
|
596
|
-
target: Protocol.Instance().passportFn('passport_verify'),
|
|
597
|
-
arguments: [this.passport, this.txb.object(clock)]
|
|
598
|
-
});
|
|
599
|
-
}
|
|
600
|
-
destroy() {
|
|
601
|
-
this.txb.moveCall({
|
|
602
|
-
target: Protocol.Instance().passportFn('destroy'),
|
|
603
|
-
arguments: [this.passport]
|
|
604
|
-
});
|
|
605
|
-
}
|
|
606
|
-
freeze() {
|
|
607
|
-
this.txb.moveCall({
|
|
608
|
-
target: Protocol.Instance().passportFn('freezen'),
|
|
609
|
-
arguments: [this.passport]
|
|
610
|
-
});
|
|
611
|
-
}
|
|
612
|
-
query_result(sender, handleResult) {
|
|
613
|
-
this.txb.moveCall({
|
|
614
|
-
target: Protocol.Instance().passportFn('query_result'),
|
|
615
|
-
arguments: [this.passport]
|
|
616
|
-
});
|
|
617
|
-
Protocol.Client().devInspectTransactionBlock({ sender: sender, transactionBlock: this.txb }).then((res) => {
|
|
618
|
-
const r = Passport.ResolveQueryRes(this.txb, res);
|
|
619
|
-
if (r)
|
|
620
|
-
handleResult(r);
|
|
621
|
-
}).catch(e => {
|
|
622
|
-
console.log(e);
|
|
623
|
-
});
|
|
624
|
-
}
|
|
625
|
-
query_result_async = async (sender) => {
|
|
626
|
-
this.txb.moveCall({
|
|
627
|
-
target: Protocol.Instance().passportFn('query_result'),
|
|
628
|
-
arguments: [this.passport]
|
|
629
|
-
});
|
|
630
|
-
const res = await Protocol.Client().devInspectTransactionBlock({ sender: sender, transactionBlock: this.txb });
|
|
631
|
-
return Passport.ResolveQueryRes(this.txb, res);
|
|
632
|
-
};
|
|
633
|
-
static ResolveQueryRes(txb, res) {
|
|
634
|
-
for (let i = 0; i < res.results?.length; ++i) {
|
|
635
|
-
const v = res.results[i];
|
|
636
|
-
if (v?.returnValues && v.returnValues.length === 2 &&
|
|
637
|
-
v.returnValues[0][1] === 'bool' && v.returnValues[1][1] === 'vector<address>') { // (bool, vector<address>)
|
|
638
|
-
const result = Bcs.getInstance().de('bool', Uint8Array.from(v.returnValues[0][0]));
|
|
639
|
-
const guards = Bcs.getInstance().de('vector<address>', Uint8Array.from(v.returnValues[1][0])).map((v) => '0x' + v);
|
|
640
|
-
return { txb: txb, result: result, guards: guards };
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
return undefined;
|
|
644
|
-
}
|
|
645
|
-
}
|
package/dist/src/payment.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { CoinObject, PaymentAddress } from './protocol';
|
|
2
|
-
import { Transaction as TransactionBlock } from '@mysten/sui/transactions';
|
|
3
|
-
export interface Payment_Receiver {
|
|
4
|
-
address: string;
|
|
5
|
-
coin: CoinObject;
|
|
6
|
-
}
|
|
7
|
-
export interface PaymentParam {
|
|
8
|
-
receiver: Payment_Receiver[];
|
|
9
|
-
business_index: bigint;
|
|
10
|
-
business_remark: string;
|
|
11
|
-
for_object?: string;
|
|
12
|
-
for_guard?: string;
|
|
13
|
-
}
|
|
14
|
-
export declare const PAYMENT_MAX_RECEIVER_COUNT = 200;
|
|
15
|
-
export declare function create_payment(txb: TransactionBlock, pay_token_type: string, param: PaymentParam): PaymentAddress;
|
|
16
|
-
//# sourceMappingURL=payment.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"payment.d.ts","sourceRoot":"","sources":["../../src/payment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAc,cAAc,EAAsB,MAAM,YAAY,CAAC;AAGxF,OAAO,EAAE,WAAW,IAAI,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAE1E,MAAM,WAAW,gBAAgB;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,UAAU,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IACzB,QAAQ,EAAE,gBAAgB,EAAE,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAO,0BAA0B,MAAM,CAAC;AAC/C,wBAAgB,cAAc,CAAC,GAAG,EAAC,gBAAgB,EAAE,cAAc,EAAC,MAAM,EAAE,KAAK,EAAC,YAAY,GAAI,cAAc,CAuC/G"}
|