wowok 1.1.1 → 1.1.3

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/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 { VariableType } from './guard';
7
+ import { GuardVariable } from './guard';
8
8
 
9
9
 
10
10
  export enum MODULES {
@@ -56,61 +56,48 @@ 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
- TYPE_LOGIC_OPERATOR_U128_GREATER = 11,
63
- TYPE_LOGIC_OPERATOR_U128_GREATER_EQUAL = 12,
64
- TYPE_LOGIC_OPERATOR_U128_LESSER = 13,
65
- TYPE_LOGIC_OPERATOR_U128_LESSER_EQUAL = 14,
66
- TYPE_LOGIC_OPERATOR_U128_EQUAL = 15,
67
- TYPE_LOGIC_OPERATOR_EQUAL = 16, // TYPE&DATA(vector<u8>) MUST BE EQUAL
68
- TYPE_LOGIC_OPERATOR_HAS_SUBSTRING = 17, // SUBSTRING
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
69
+ TYPE_LOGIC_AND = 20, // AND
70
+ TYPE_LOGIC_OR = 21, // OR
71
+ }
71
72
 
72
- export enum ContextType {
73
- TYPE_CONTEXT_SIGNER = 60,
74
- TYPE_CONTEXT_CLOCK = 61,
75
- TYPE_CONTEXT_FUTURE_ID = 62,
76
-
77
- TYPE_CONTEXT_bool = 70,
78
- TYPE_CONTEXT_address = 71,
79
- TYPE_CONTEXT_u64 = 72,
80
- TYPE_CONTEXT_u8 = 73,
81
- TYPE_CONTEXT_vec_u8 = 74,
82
- /* TYPE_CONTEXT_u128 = 75,
83
- TYPE_CONTEXT_vec_address = 76,
84
- TYPE_CONTEXT_vec_bool = 77,
85
- TYPE_CONTEXT_vec_vec_u8 = 78,
86
- TYPE_CONTEXT_vec_u64 = 79,
87
- TYPE_CONTEXT_vec_u128 = 80,
88
- TYPE_CONTEXT_option_address = 81,
89
- TYPE_CONTEXT_option_bool = 82,
90
- TYPE_CONTEXT_option_u8 = 83,
91
- TYPE_CONTEXT_option_u64 = 84,
92
- 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_U256 = 116,
93
91
  }
94
92
 
95
- export enum ValueType {
96
- TYPE_STATIC_bool = 100,
97
- TYPE_STATIC_address = 101,
98
- TYPE_STATIC_u64 = 102,
99
- TYPE_STATIC_u8 = 103,
100
- TYPE_STATIC_vec_u8 = 104,
101
- TYPE_STATIC_u128 = 105,
102
- TYPE_STATIC_vec_address = 106,
103
- TYPE_STATIC_vec_bool = 107,
104
- TYPE_STATIC_vec_vec_u8 = 108,
105
- TYPE_STATIC_vec_u64 = 109,
106
- TYPE_STATIC_vec_u128 = 110,
107
- TYPE_STATIC_option_address = 111,
108
- TYPE_STATIC_option_bool = 112,
109
- TYPE_STATIC_option_u8 = 113,
110
- TYPE_STATIC_option_u64 = 114,
111
- TYPE_STATIC_option_u128 = 115,
93
+ export enum ContextType {
94
+ TYPE_SIGNER = 60,
95
+ TYPE_CLOCK = 61,
96
+ TYPE_WITNESS_ID = 62,
97
+ TYPE_VARIABLE = 80,
112
98
  }
113
99
 
100
+ export type VariableType = ValueType | ContextType.TYPE_WITNESS_ID;
114
101
  export type Data_Type = ValueType | OperatorType | ContextType;
115
102
 
116
103
  export enum ENTRYPOINT {
@@ -128,8 +115,7 @@ export class Protocol {
128
115
  protected graphql = '';
129
116
  protected txb: TransactionBlock | undefined;
130
117
 
131
- constructor(network:ENTRYPOINT, signer_address:string) {
132
- this.signer = signer_address;
118
+ constructor(network:ENTRYPOINT=ENTRYPOINT.testnet) {
133
119
  this.UseNetwork(network);
134
120
  this.NewSession();
135
121
  }
@@ -143,7 +129,7 @@ export class Protocol {
143
129
  case ENTRYPOINT.devnet:
144
130
  break;
145
131
  case ENTRYPOINT.testnet:
146
- this.package = "0x142a896540e7bb2858ca8a3ec6194511e409a7d81225abddf84ae58fd4764735";
132
+ this.package = "0xffd87461cb8e54e0ae612a0d6a323d8c6fb4a85933e7481d3f4926ced3e6d7c7";
147
133
  this.everyone_guard = "0x78a41fcc4f566360839613f6b917fb101ae015e56b43143f496f265b6422fddc";
148
134
  this.graphql = 'https://sui-testnet.mystenlabs.com/graphql';
149
135
  break;
@@ -183,7 +169,6 @@ export class Protocol {
183
169
  ServiceFn = (fn: any) => { return `${this.package}::${MODULES.service}::${fn}`};
184
170
  WowokFn = (fn: any) => { return `${this.package}::${MODULES.wowok}::${fn}`};
185
171
 
186
-
187
172
  Query = async (objects: Query_Param[], options:SuiObjectDataOptions={showContent:true}) : Promise<SuiObjectResponse[]> => {
188
173
  const client = new SuiClient({ url: this.NetworkUrl() });
189
174
  const ids = objects.map((value) => value.objectid);
@@ -196,6 +181,11 @@ export class Protocol {
196
181
  }
197
182
  return res;
198
183
  }
184
+ Query_Raw = async (objects: string[], options:SuiObjectDataOptions={showContent:true}) : Promise<SuiObjectResponse[]> => {
185
+ const client = new SuiClient({ url: this.NetworkUrl() });
186
+ return await client.call('sui_multiGetObjects', [objects, options]) as SuiObjectResponse[];
187
+ }
188
+
199
189
  NewSession = () : TransactionBlock => {
200
190
  this.txb = new TransactionBlock();
201
191
  return this.txb
@@ -248,7 +238,12 @@ export class Protocol {
248
238
  { return this.package + '::' + key + '::'; })
249
239
  object_name_from_type_repr = (type_repr:string) : string => {
250
240
  let i = type_repr.indexOf('::');
251
- if (i > 0 && type_repr.slice(0, i).includes(this.package)) {
241
+ if (i > 0 && type_repr.slice(0, i) === this.package) {
242
+ i = type_repr.indexOf('<');
243
+ if (i > 0) {
244
+ type_repr = type_repr.slice(0, i);
245
+ }
246
+
252
247
  let n = type_repr.lastIndexOf('::');
253
248
  if (n > 0) {
254
249
  return type_repr.slice(n+2);
@@ -296,7 +291,7 @@ export class RpcResultParser {
296
291
  export type Query_Param = {
297
292
  objectid: string;
298
293
  callback: (protocol:Protocol, response:SuiObjectResponse, param:Query_Param, option:SuiObjectDataOptions)=>void;
299
- parser?: (result:any[], guardid: string, chain_sense_bsc:Uint8Array, variable?:VariableType) => boolean;
294
+ parser?: (result:any[], guardid: string, chain_sense_bsc:Uint8Array, variable?:GuardVariable) => boolean;
300
295
  data?: any; // response data filted by callback
301
- variables?: VariableType;
296
+ variables?: GuardVariable;
302
297
  };
package/src/repository.ts CHANGED
@@ -139,6 +139,74 @@ export class Repository {
139
139
  ],
140
140
  })
141
141
  }
142
+ add_reference(references:string[], passport?:PassportObject) {
143
+ if (!references) {
144
+ ERROR(Errors.InvalidParam, 'references')
145
+ }
146
+
147
+ if (!IsValidArray(references, IsValidAddress)) {
148
+ ERROR(Errors.IsValidArray, 'references')
149
+ }
150
+
151
+ let txb = this.protocol.CurrentSession();
152
+ if (passport) {
153
+ txb.moveCall({
154
+ target:this.protocol.RepositoryFn('reference_add_with_passport') as FnCallType,
155
+ arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
156
+ txb.pure(array_unique(references), 'vector<address>'),
157
+ Protocol.TXB_OBJECT(txb, this.permission)]
158
+ })
159
+ } else {
160
+ txb.moveCall({
161
+ target:this.protocol.RepositoryFn('reference_add') as FnCallType,
162
+ arguments:[Protocol.TXB_OBJECT(txb, this.object),
163
+ txb.pure(array_unique(references), 'vector<address>'),
164
+ Protocol.TXB_OBJECT(txb, this.permission)]
165
+ })
166
+ }
167
+ }
168
+ remove_reference(references:string[], removeall?:boolean, passport?:PassportObject) {
169
+ if (!references) {
170
+ ERROR(Errors.InvalidParam, 'references')
171
+ }
172
+
173
+ if (!IsValidArray(references, IsValidAddress)) {
174
+ ERROR(Errors.IsValidArray, 'references')
175
+ }
176
+
177
+ let txb = this.protocol.CurrentSession();
178
+ if (removeall) {
179
+ if (passport) {
180
+ txb.moveCall({
181
+ target:this.protocol.RepositoryFn('reference_removeall_with_passport') as FnCallType,
182
+ arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
183
+ Protocol.TXB_OBJECT(txb, this.permission)]
184
+ })
185
+ } else {
186
+ txb.moveCall({
187
+ target:this.protocol.RepositoryFn('reference_removeall') as FnCallType,
188
+ arguments:[Protocol.TXB_OBJECT(txb, this.object),
189
+ Protocol.TXB_OBJECT(txb, this.permission)]
190
+ })
191
+ }
192
+ } else {
193
+ if (passport) {
194
+ txb.moveCall({
195
+ target:this.protocol.RepositoryFn('reference_remove_with_passport') as FnCallType,
196
+ arguments:[passport, Protocol.TXB_OBJECT(txb, this.object),
197
+ txb.pure(array_unique(references), 'vector<address>'),
198
+ Protocol.TXB_OBJECT(txb, this.permission)]
199
+ })
200
+ } else {
201
+ txb.moveCall({
202
+ target:this.protocol.RepositoryFn('reference_remove') as FnCallType,
203
+ arguments:[Protocol.TXB_OBJECT(txb, this.object),
204
+ txb.pure(array_unique(references), 'vector<address>'),
205
+ Protocol.TXB_OBJECT(txb, this.permission)]
206
+ })
207
+ }
208
+ }
209
+ }
142
210
  // add or modify the old
143
211
  add_policies(policies:Repository_Policy[], passport?:PassportObject) {
144
212
  if (!policies) {
package/src/utils.ts CHANGED
@@ -118,6 +118,12 @@ export class Bcs {
118
118
  ser_u64(data:number) : Uint8Array {
119
119
  return this.bcs.ser(BCS.U64, data).toBytes();
120
120
  }
121
+ ser_u128(data:number) : Uint8Array {
122
+ return this.bcs.ser(BCS.U128, data).toBytes();
123
+ }
124
+ ser_u256(data:number) : Uint8Array {
125
+ return this.bcs.ser(BCS.U256, data).toBytes();
126
+ }
121
127
  ser_string(data:string) : Uint8Array {
122
128
  return this.bcs.ser(BCS.STRING, data).toBytes();
123
129
  }
@@ -197,3 +203,39 @@ export const IsValidArray = (arr: any[], validFunc:any) : boolean => {
197
203
 
198
204
  export const OptionNone = (txb:TransactionBlock) : TransactionArgument => { return txb.pure([], BCS.U8) };
199
205
 
206
+ export type ArgType = {
207
+ isCoin: boolean;
208
+ coin: string;
209
+ token: string;
210
+ }
211
+ export const ParseType = (type:string) : ArgType => {
212
+ let i = type.indexOf('<');
213
+ if (i > 0 && type.length > 12) {
214
+ let c = type.slice(0, i);
215
+ if (c === '0x2::coin::Coin' || c === '0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin') {
216
+ let coin = type.slice(i+1, type.length-1); // < >>
217
+ let t = coin.lastIndexOf('::');
218
+ return {isCoin:true, coin:coin, token:coin.slice(t+2)}
219
+ }
220
+ }
221
+ return {isCoin:false, coin:'', token:''}
222
+ }
223
+
224
+ export function toFixed(x:number) {
225
+ let res = '';
226
+ if (Math.abs(x) < 1.0) {
227
+ var e = parseInt(x.toString().split('e-')[1]);
228
+ if (e) {
229
+ x *= Math.pow(10,e-1);
230
+ res = '0.' + (new Array(e)).join('0') + x.toString().substring(2);
231
+ }
232
+ } else {
233
+ var e = parseInt(x.toString().split('+')[1]);
234
+ if (e > 20) {
235
+ e -= 20;
236
+ x /= Math.pow(10,e);
237
+ res = x + (new Array(e+1)).join('0');
238
+ }
239
+ }
240
+ return res;
241
+ }
package/tsconfig.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  /* Visit https://aka.ms/tsconfig to read more about this file */
4
- // "outDir": "out", // 输出的文件夹
4
+ // "outDir": "out",
5
5
  // "sourceMap": true,
6
6
  /* Projects */
7
7
  // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
@@ -14,7 +14,8 @@
14
14
  /* Language and Environment */
15
15
  "target": "ESNext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
16
16
  "lib": ["es2020", "DOM"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
17
- // "jsx": "preserve", /* Specify what JSX code is generated. */
17
+ "downlevelIteration": true,
18
+ // "jsx": "preserve", /* Specify what JSX code is generated. */
18
19
  // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
19
20
  // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
20
21
  // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */