wowok 1.1.2 → 1.1.4
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/README.md +3 -2
- package/dist/exception.d.ts +2 -1
- package/dist/exception.d.ts.map +1 -1
- package/dist/exception.js +1 -0
- package/dist/guard.d.ts +29 -25
- package/dist/guard.d.ts.map +1 -1
- package/dist/guard.js +341 -352
- package/dist/passport.d.ts +32 -14
- package/dist/passport.d.ts.map +1 -1
- package/dist/passport.js +467 -78
- package/dist/protocol.d.ts +46 -38
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +59 -48
- package/dist/utils.d.ts +17 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +54 -0
- package/package.json +3 -2
- package/src/exception.ts +1 -0
- package/src/guard.ts +349 -365
- package/src/passport.ts +484 -85
- package/src/protocol.ts +69 -51
- package/src/utils.ts +59 -1
package/src/protocol.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519';
|
|
|
4
4
|
import { BCS, getSuiMoveConfig, toHEX, fromHEX, BcsReader } from '@mysten/bcs';
|
|
5
5
|
import { TransactionBlock, Inputs, TransactionResult, TransactionArgument } from '@mysten/sui.js/transactions';
|
|
6
6
|
import { capitalize, IsValidArray } from './utils'
|
|
7
|
-
import {
|
|
7
|
+
import { GuardVariable } from './guard';
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
export enum MODULES {
|
|
@@ -56,64 +56,82 @@ export type FnCallType = `${string}::${string}::${string}`;
|
|
|
56
56
|
|
|
57
57
|
export enum OperatorType {
|
|
58
58
|
TYPE_QUERY = 1, // query wowok object
|
|
59
|
-
TYPE_FUTURE_QUERY = 2,
|
|
60
|
-
TYPE_QUERY_FROM_CONTEXT = 3,
|
|
61
59
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
60
|
+
TYPE_LOGIC_AS_U256_GREATER = 11,
|
|
61
|
+
TYPE_LOGIC_AS_U256_GREATER_EQUAL = 12,
|
|
62
|
+
TYPE_LOGIC_AS_U256_LESSER = 13,
|
|
63
|
+
TYPE_LOGIC_AS_U256_LESSER_EQUAL = 14,
|
|
64
|
+
TYPE_LOGIC_AS_U256_EQUAL = 15,
|
|
65
|
+
TYPE_LOGIC_EQUAL = 16, // TYPE&DATA(vector<u8>) MUST BE EQUAL
|
|
66
|
+
TYPE_LOGIC_HAS_SUBSTRING = 17, // SUBSTRING
|
|
69
67
|
TYPE_LOGIC_ALWAYS_TRUE = 18, // aways true
|
|
70
68
|
TYPE_LOGIC_NOT = 19, // NOT
|
|
71
69
|
TYPE_LOGIC_AND = 20, // AND
|
|
72
70
|
TYPE_LOGIC_OR = 21, // OR
|
|
73
71
|
}
|
|
74
72
|
|
|
75
|
-
export enum
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
TYPE_CONTEXT_option_u128 = 85,*/
|
|
73
|
+
export enum ValueType {
|
|
74
|
+
TYPE_BOOL = 100,
|
|
75
|
+
TYPE_ADDRESS = 101,
|
|
76
|
+
TYPE_U64 = 102,
|
|
77
|
+
TYPE_U8 = 103,
|
|
78
|
+
TYPE_VEC_U8 = 104,
|
|
79
|
+
TYPE_U128 = 105,
|
|
80
|
+
TYPE_VEC_ADDRESS = 106,
|
|
81
|
+
TYPE_VEC_BOOL = 107,
|
|
82
|
+
TYPE_VEC_VEC_U8 = 108,
|
|
83
|
+
TYPE_VEC_U64 = 109,
|
|
84
|
+
TYPE_VEC_U128 = 110,
|
|
85
|
+
TYPE_OPTION_ADDRESS = 111,
|
|
86
|
+
TYPE_OPTION_BOOL = 112,
|
|
87
|
+
TYPE_OPTION_U8 = 113,
|
|
88
|
+
TYPE_OPTION_U64 = 114,
|
|
89
|
+
TYPE_OPTION_U128 = 115,
|
|
90
|
+
TYPE_OPTION_U256 = 116,
|
|
91
|
+
TYPE_VEC_U256 = 117,
|
|
92
|
+
TYPE_U256 = 118,
|
|
96
93
|
}
|
|
97
94
|
|
|
98
|
-
export
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
95
|
+
export const OperatorTypeArray = (Object.values(OperatorType) as []).filter((v)=>typeof(v) === 'number') as number[];
|
|
96
|
+
export const ValueTypeArray = (Object.values(ValueType) as []).filter((v)=>typeof(v) === 'number') as number[];
|
|
97
|
+
export const IsValidOperatorType = (type:number) => { return OperatorTypeArray.includes(type)}
|
|
98
|
+
export const IsValidValueType = (type:number) => { return ValueTypeArray.includes(type)}
|
|
99
|
+
|
|
100
|
+
interface ValueTypeString {
|
|
101
|
+
type: ValueType;
|
|
102
|
+
name: string;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export const SER_VALUE: ValueTypeString[] = [
|
|
106
|
+
{type: ValueType.TYPE_BOOL, name: 'bool'},
|
|
107
|
+
{type: ValueType.TYPE_ADDRESS, name: 'address'},
|
|
108
|
+
{type: ValueType.TYPE_U64, name: 'u64'},
|
|
109
|
+
{type: ValueType.TYPE_U8, name: 'u8'},
|
|
110
|
+
{type: ValueType.TYPE_VEC_U8, name: 'vector<u8>'},
|
|
111
|
+
{type: ValueType.TYPE_U128, name: 'u128'},
|
|
112
|
+
{type: ValueType.TYPE_VEC_ADDRESS, name: 'vector<address>'},
|
|
113
|
+
{type: ValueType.TYPE_VEC_BOOL, name: 'vector<bool>'},
|
|
114
|
+
{type: ValueType.TYPE_VEC_VEC_U8, name: 'vector<vector<u8>>'},
|
|
115
|
+
{type: ValueType.TYPE_VEC_U64, name: 'vector<u64>'},
|
|
116
|
+
{type: ValueType.TYPE_VEC_U128, name: 'vector<u128>'},
|
|
117
|
+
{type: ValueType.TYPE_OPTION_ADDRESS, name: 'Option<address>'},
|
|
118
|
+
{type: ValueType.TYPE_OPTION_BOOL, name: 'Option<bool>'},
|
|
119
|
+
{type: ValueType.TYPE_OPTION_U8, name: 'Option<u8>'},
|
|
120
|
+
{type: ValueType.TYPE_OPTION_U64, name: 'Option<u64>'},
|
|
121
|
+
{type: ValueType.TYPE_OPTION_U128, name: 'Option<u128>'},
|
|
122
|
+
{type: ValueType.TYPE_OPTION_U256, name: 'Option<u256>'},
|
|
123
|
+
{type: ValueType.TYPE_VEC_U256, name: 'vector<u256>'},
|
|
124
|
+
{type: ValueType.TYPE_U256, name: 'u256'},
|
|
125
|
+
]
|
|
126
|
+
|
|
127
|
+
export enum ContextType {
|
|
128
|
+
TYPE_SIGNER = 60,
|
|
129
|
+
TYPE_CLOCK = 61,
|
|
130
|
+
TYPE_WITNESS_ID = 62,
|
|
131
|
+
TYPE_VARIABLE = 80,
|
|
115
132
|
}
|
|
116
133
|
|
|
134
|
+
export type VariableType = ValueType | ContextType.TYPE_WITNESS_ID;
|
|
117
135
|
export type Data_Type = ValueType | OperatorType | ContextType;
|
|
118
136
|
|
|
119
137
|
export enum ENTRYPOINT {
|
|
@@ -145,7 +163,7 @@ export class Protocol {
|
|
|
145
163
|
case ENTRYPOINT.devnet:
|
|
146
164
|
break;
|
|
147
165
|
case ENTRYPOINT.testnet:
|
|
148
|
-
this.package = "
|
|
166
|
+
this.package = "0x9a7fc338ab9fd0a8f4c108e2f3dbe53393b83529263eb31a391120997d962400";
|
|
149
167
|
this.everyone_guard = "0x78a41fcc4f566360839613f6b917fb101ae015e56b43143f496f265b6422fddc";
|
|
150
168
|
this.graphql = 'https://sui-testnet.mystenlabs.com/graphql';
|
|
151
169
|
break;
|
|
@@ -307,7 +325,7 @@ export class RpcResultParser {
|
|
|
307
325
|
export type Query_Param = {
|
|
308
326
|
objectid: string;
|
|
309
327
|
callback: (protocol:Protocol, response:SuiObjectResponse, param:Query_Param, option:SuiObjectDataOptions)=>void;
|
|
310
|
-
parser?: (result:any[], guardid: string, chain_sense_bsc:Uint8Array, variable?:
|
|
328
|
+
parser?: (result:any[], guardid: string, chain_sense_bsc:Uint8Array, variable?:GuardVariable) => boolean;
|
|
311
329
|
data?: any; // response data filted by callback
|
|
312
|
-
variables?:
|
|
330
|
+
variables?: GuardVariable;
|
|
313
331
|
};
|
package/src/utils.ts
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
import { bcs, BCS, toHEX, fromHEX, getSuiMoveConfig, TypeName, StructTypeDefinition } from '@mysten/bcs';
|
|
2
2
|
import { TransactionBlock, Inputs, TransactionResult, TransactionArgument } from '@mysten/sui.js/transactions';
|
|
3
|
+
import { ERROR, Errors } from './exception';
|
|
4
|
+
import { OperatorType } from './protocol';
|
|
3
5
|
|
|
4
|
-
export const
|
|
6
|
+
export const OPTION_NONE = 0;
|
|
7
|
+
export const readOption = (arr: number[], de:string) : {bNone:boolean, value:any}=> {
|
|
8
|
+
let o = arr.splice(0, 1);
|
|
9
|
+
if (o[0] == 1) { // true
|
|
10
|
+
return {bNone:false, value:Bcs.getInstance().de(de, Uint8Array.from(arr))};
|
|
11
|
+
} else if (o[0] == 0) {
|
|
12
|
+
return {bNone:true, value:OPTION_NONE};
|
|
13
|
+
} else {
|
|
14
|
+
ERROR(Errors.Fail, 'readOption: option invalid')
|
|
15
|
+
return {bNone:true, value:OPTION_NONE}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const ulebDecode = (arr: Uint8Array) : {value: number, length: number} => {
|
|
5
20
|
let total = 0;
|
|
6
21
|
let shift = 0;
|
|
7
22
|
let len = 0;
|
|
@@ -23,6 +38,30 @@ export const ulebDecode = (arr: number[] | Uint8Array) : {value: number, length:
|
|
|
23
38
|
};
|
|
24
39
|
}
|
|
25
40
|
|
|
41
|
+
export const readVec = (arr: any[], cb:(arr:any[], i:number, length:number) => any) : any[] => {
|
|
42
|
+
let r = ulebDecode(Uint8Array.from(arr));
|
|
43
|
+
arr.splice(0, r.length) ;
|
|
44
|
+
|
|
45
|
+
let result = [];
|
|
46
|
+
for (let i = 0; i < r.value; i++) {
|
|
47
|
+
result.push(cb(arr, i, r.value));
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const cb_U8 = (arr:any[], i:number, length:number) : any => {
|
|
53
|
+
return arr.shift();
|
|
54
|
+
}
|
|
55
|
+
export const cb_U64 = (arr:any[], i:number, length:number) : any => {
|
|
56
|
+
return arr.splice(0, 8);
|
|
57
|
+
}
|
|
58
|
+
export const cb_U128 = (arr:any[], i:number, length:number) : any => {
|
|
59
|
+
return arr.splice(0, 16);
|
|
60
|
+
}
|
|
61
|
+
export const cb_U256 = (arr:any[], i:number, length:number) : any => {
|
|
62
|
+
return arr.splice(0, 32);
|
|
63
|
+
}
|
|
64
|
+
|
|
26
65
|
export const concatenate = (resultConstructor:any, ...arrays:any[]) => {
|
|
27
66
|
let totalLength = 0;
|
|
28
67
|
for (const arr of arrays) {
|
|
@@ -106,6 +145,16 @@ export class Bcs {
|
|
|
106
145
|
ser_vector_u8(data:number[]) : Uint8Array {
|
|
107
146
|
return this.bcs.ser('vector<u8>', data).toBytes();
|
|
108
147
|
}
|
|
148
|
+
ser_vector_address(data:number[]) : Uint8Array {
|
|
149
|
+
return this.bcs.ser('vector<address>', data).toBytes();
|
|
150
|
+
}
|
|
151
|
+
ser_vector_bool(data:number[]) : Uint8Array {
|
|
152
|
+
return this.bcs.ser('vector<bool>', data).toBytes();
|
|
153
|
+
}
|
|
154
|
+
ser_vector_u128(data:number[]) : Uint8Array {
|
|
155
|
+
return this.bcs.ser('vector<u128>', data).toBytes();
|
|
156
|
+
}
|
|
157
|
+
|
|
109
158
|
ser_address(data:string) : Uint8Array {
|
|
110
159
|
return this.bcs.ser(BCS.ADDRESS, data).toBytes();
|
|
111
160
|
}
|
|
@@ -118,9 +167,18 @@ export class Bcs {
|
|
|
118
167
|
ser_u64(data:number) : Uint8Array {
|
|
119
168
|
return this.bcs.ser(BCS.U64, data).toBytes();
|
|
120
169
|
}
|
|
170
|
+
ser_u128(data:number) : Uint8Array {
|
|
171
|
+
return this.bcs.ser(BCS.U128, data).toBytes();
|
|
172
|
+
}
|
|
173
|
+
ser_u256(data:number) : Uint8Array {
|
|
174
|
+
return this.bcs.ser(BCS.U256, data).toBytes();
|
|
175
|
+
}
|
|
121
176
|
ser_string(data:string) : Uint8Array {
|
|
122
177
|
return this.bcs.ser(BCS.STRING, data).toBytes();
|
|
123
178
|
}
|
|
179
|
+
ser(type:TypeName | StructTypeDefinition, data:Uint8Array) {
|
|
180
|
+
return this.bcs.ser(type, data).toBytes();
|
|
181
|
+
}
|
|
124
182
|
de(type:TypeName | StructTypeDefinition, data:Uint8Array) {
|
|
125
183
|
return this.bcs.de(type, data)
|
|
126
184
|
}
|