wowok 1.0.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.
@@ -0,0 +1,8 @@
1
+ import { SuiClient } from '../node_modules/@mysten/sui.js/client';
2
+ import { ENTRYPOINT } from './config.js';
3
+ export * from './config.js';
4
+ export declare class Community {
5
+ protected client: SuiClient;
6
+ constructor(entry: ENTRYPOINT);
7
+ create(data: any): Promise<import("@mysten/sui.js/dist/cjs/client/types/generated").SuiTransactionBlockResponse>;
8
+ }
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.Community = void 0;
27
+ const client_1 = require("../node_modules/@mysten/sui.js/client");
28
+ const transactions_1 = require("../node_modules/@mysten/sui.js/transactions");
29
+ const ed25519_1 = require("../node_modules/@mysten/sui.js/keypairs/ed25519");
30
+ const bcs_1 = require("../node_modules/@mysten/bcs");
31
+ const config_js_1 = require("./config.js");
32
+ __exportStar(require("./config.js"), exports);
33
+ class Community {
34
+ constructor(entry) {
35
+ this.client = new client_1.SuiClient({ url: (0, client_1.getFullnodeUrl)(entry) });
36
+ }
37
+ create(data) {
38
+ var _a, _b;
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ const txb = new transactions_1.TransactionBlock();
41
+ /// resolve nd
42
+ var community = txb.moveCall({
43
+ target: (0, config_js_1.CommunityFn)('new'),
44
+ arguments: [
45
+ txb.pure((_a = data.name) !== null && _a !== void 0 ? _a : '', bcs_1.BCS.STRING),
46
+ txb.pure((_b = data.discription) !== null && _b !== void 0 ? _b : '', bcs_1.BCS.STRING)
47
+ ],
48
+ });
49
+ /// resolve admins
50
+ data.admins.forEach((admin) => {
51
+ console.log(admin.address);
52
+ txb.moveCall({
53
+ target: (0, config_js_1.CommunityFn)('admin_add'),
54
+ arguments: [
55
+ community,
56
+ txb.pure(admin.address, bcs_1.BCS.ADDRESS)
57
+ ]
58
+ });
59
+ });
60
+ /// resolve members
61
+ data.members.forEach((member) => {
62
+ var _a;
63
+ txb.moveCall({
64
+ target: (0, config_js_1.CommunityFn)('member_addforce'),
65
+ arguments: [
66
+ community,
67
+ txb.pure(member.address, bcs_1.BCS.ADDRESS),
68
+ txb.pure((_a = member.name) !== null && _a !== void 0 ? _a : '', bcs_1.BCS.STRING)
69
+ ]
70
+ });
71
+ });
72
+ /// create
73
+ txb.moveCall({
74
+ target: (0, config_js_1.CommunityFn)('create'),
75
+ arguments: [
76
+ community
77
+ ]
78
+ });
79
+ const privkey = (0, bcs_1.fromHEX)(config_js_1.SENDER_PRIV);
80
+ const keypair = ed25519_1.Ed25519Keypair.fromSecretKey(privkey);
81
+ const options = { showInput: true,
82
+ showEffects: true,
83
+ showEvents: true,
84
+ showBalanceChanges: true,
85
+ showObjectChanges: true };
86
+ const response = yield this.client.signAndExecuteTransactionBlock({
87
+ transactionBlock: txb,
88
+ signer: keypair,
89
+ options
90
+ });
91
+ console.log(response);
92
+ return response;
93
+ });
94
+ }
95
+ }
96
+ exports.Community = Community;
@@ -0,0 +1,19 @@
1
+ export declare const PACKAGE = "0x6b9dec1b3ca2e92f366eeeff47d119712f44d3a6cef8959f95b3a09bac2c9840";
2
+ export declare const SENDER_PRIV = "0xc9bbc30f72ef7d9aa674a3be1448b9267141a676b59f3f4315231617a5bbc0e8";
3
+ export declare class Config {
4
+ constructor();
5
+ }
6
+ export declare enum ENTRYPOINT {
7
+ mainnet = "mainnet",
8
+ testnet = "testnet",
9
+ devnet = "devnet",
10
+ localnet = "localnet"
11
+ }
12
+ export declare enum MODULES {
13
+ machine = "machine",
14
+ community = "community"
15
+ }
16
+ export type FnCallType = `${string}::${string}::${string}`;
17
+ export declare const ContractFn: (mod: any, fn: any) => string;
18
+ export declare const MachineFn: (fn: any) => string;
19
+ export declare const CommunityFn: (fn: any) => string;
package/dist/config.js ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommunityFn = exports.MachineFn = exports.ContractFn = exports.MODULES = exports.ENTRYPOINT = exports.Config = exports.SENDER_PRIV = exports.PACKAGE = void 0;
4
+ exports.PACKAGE = "0x6b9dec1b3ca2e92f366eeeff47d119712f44d3a6cef8959f95b3a09bac2c9840"; // address, NOT id
5
+ exports.SENDER_PRIV = "0xc9bbc30f72ef7d9aa674a3be1448b9267141a676b59f3f4315231617a5bbc0e8";
6
+ class Config {
7
+ constructor() {
8
+ }
9
+ }
10
+ exports.Config = Config;
11
+ var ENTRYPOINT;
12
+ (function (ENTRYPOINT) {
13
+ ENTRYPOINT["mainnet"] = "mainnet";
14
+ ENTRYPOINT["testnet"] = "testnet";
15
+ ENTRYPOINT["devnet"] = "devnet";
16
+ ENTRYPOINT["localnet"] = "localnet";
17
+ })(ENTRYPOINT || (exports.ENTRYPOINT = ENTRYPOINT = {}));
18
+ var MODULES;
19
+ (function (MODULES) {
20
+ MODULES["machine"] = "machine";
21
+ MODULES["community"] = "community";
22
+ })(MODULES || (exports.MODULES = MODULES = {}));
23
+ exports.ContractFn = ((mod, fn) => { return `${exports.PACKAGE}::${mod}::${fn}`; });
24
+ const MachineFn = (fn) => { return `${exports.PACKAGE}::${MODULES.machine}::${fn}`; };
25
+ exports.MachineFn = MachineFn;
26
+ const CommunityFn = (fn) => { return `${exports.PACKAGE}::${MODULES.community}::${fn}`; };
27
+ exports.CommunityFn = CommunityFn;
package/dist/demand.js ADDED
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.change_permission = exports.present = exports.deposit = exports.demand_yes = exports.demand_set_description = exports.demand_set_guard = exports.demand_expand_time = exports.demand_refund = exports.destroy = exports.launch = exports.demand = exports.MAX_PRESENTERS_COUNT = exports.MAX_EARNEST_COUNT = void 0;
4
+ const bcs_1 = require("@mysten/bcs");
5
+ const protocol_1 = require("./protocol");
6
+ exports.MAX_EARNEST_COUNT = 200;
7
+ exports.MAX_PRESENTERS_COUNT = 200;
8
+ function demand(earnest_type, txb, permission, description, earnest, passport) {
9
+ if (passport) {
10
+ return txb.moveCall({
11
+ target: protocol_1.PROTOCOL.DemandFn('new_with_passport'),
12
+ arguments: [passport, txb.pure((0, protocol_1.description_data)(description)), earnest, permission],
13
+ typeArguments: [earnest_type],
14
+ });
15
+ }
16
+ else {
17
+ return txb.moveCall({
18
+ target: protocol_1.PROTOCOL.DemandFn('new'),
19
+ arguments: [txb.pure((0, protocol_1.description_data)(description)), earnest, permission],
20
+ typeArguments: [earnest_type],
21
+ });
22
+ }
23
+ }
24
+ exports.demand = demand;
25
+ function launch(earnest_type, txb, demand) {
26
+ return txb.moveCall({
27
+ target: protocol_1.PROTOCOL.DemandFn('create'),
28
+ arguments: [demand],
29
+ typeArguments: [earnest_type],
30
+ });
31
+ }
32
+ exports.launch = launch;
33
+ function destroy(earnest_type, txb, demand) {
34
+ return txb.moveCall({
35
+ target: protocol_1.PROTOCOL.DemandFn('destroy'),
36
+ arguments: [demand],
37
+ typeArguments: [earnest_type]
38
+ });
39
+ }
40
+ exports.destroy = destroy;
41
+ function demand_refund(earnest_type, txb, demand, permission, passport) {
42
+ if (passport) {
43
+ txb.moveCall({
44
+ target: protocol_1.PROTOCOL.DemandFn('refund_with_passport'),
45
+ arguments: [passport, demand, txb.object(protocol_1.CLOCK_OBJECT), permission],
46
+ typeArguments: [earnest_type],
47
+ });
48
+ }
49
+ else {
50
+ txb.moveCall({
51
+ target: protocol_1.PROTOCOL.DemandFn('refund'),
52
+ arguments: [demand, txb.object(protocol_1.CLOCK_OBJECT), permission],
53
+ typeArguments: [earnest_type],
54
+ });
55
+ }
56
+ }
57
+ exports.demand_refund = demand_refund;
58
+ function demand_expand_time(earnest_type, txb, demand, permission, minutes_duration, passport) {
59
+ if (passport) {
60
+ return txb.moveCall({
61
+ target: protocol_1.PROTOCOL.DemandFn('time_expand_with_passport'),
62
+ arguments: [passport, demand, txb.pure(minutes_duration, bcs_1.BCS.U64), txb.object(protocol_1.CLOCK_OBJECT), permission],
63
+ typeArguments: [earnest_type],
64
+ });
65
+ }
66
+ else {
67
+ return txb.moveCall({
68
+ target: protocol_1.PROTOCOL.DemandFn('time_expand'),
69
+ arguments: [demand, txb.pure(minutes_duration, bcs_1.BCS.U64), txb.object(protocol_1.CLOCK_OBJECT), permission],
70
+ typeArguments: [earnest_type],
71
+ });
72
+ }
73
+ }
74
+ exports.demand_expand_time = demand_expand_time;
75
+ function demand_set_guard(earnest_type, txb, demand, permission, guard, passport) {
76
+ if (passport) {
77
+ if (guard) {
78
+ return txb.moveCall({
79
+ target: protocol_1.PROTOCOL.DemandFn('guard_set_with_passport'),
80
+ arguments: [passport, demand, guard, permission],
81
+ typeArguments: [earnest_type],
82
+ });
83
+ }
84
+ else {
85
+ return txb.moveCall({
86
+ target: protocol_1.PROTOCOL.DemandFn('guard_none_with_passport'),
87
+ arguments: [passport, demand, permission],
88
+ typeArguments: [earnest_type],
89
+ });
90
+ }
91
+ }
92
+ else {
93
+ if (guard) {
94
+ return txb.moveCall({
95
+ target: protocol_1.PROTOCOL.DemandFn('guard_set'),
96
+ arguments: [demand, guard, permission],
97
+ typeArguments: [earnest_type],
98
+ });
99
+ }
100
+ else {
101
+ return txb.moveCall({
102
+ target: protocol_1.PROTOCOL.DemandFn('guard_none'),
103
+ arguments: [demand, permission],
104
+ typeArguments: [earnest_type],
105
+ });
106
+ }
107
+ }
108
+ }
109
+ exports.demand_set_guard = demand_set_guard;
110
+ function demand_set_description(earnest_type, txb, demand, permission, description, passport) {
111
+ if (passport) {
112
+ txb.moveCall({
113
+ target: protocol_1.PROTOCOL.DemandFn('description_set_with_passport'),
114
+ arguments: [passport, demand, txb.pure((0, protocol_1.description_data)(description)), permission],
115
+ typeArguments: [earnest_type],
116
+ });
117
+ }
118
+ else {
119
+ txb.moveCall({
120
+ target: protocol_1.PROTOCOL.DemandFn('description_set'),
121
+ arguments: [demand, txb.pure((0, protocol_1.description_data)(description)), permission],
122
+ typeArguments: [earnest_type],
123
+ });
124
+ }
125
+ }
126
+ exports.demand_set_description = demand_set_description;
127
+ function demand_yes(earnest_type, txb, demand, permission, service, passport) {
128
+ if (passport) {
129
+ txb.moveCall({
130
+ target: protocol_1.PROTOCOL.DemandFn('yes_with_passport'),
131
+ arguments: [passport, demand, txb.pure(service, bcs_1.BCS.ADDRESS), permission],
132
+ typeArguments: [earnest_type],
133
+ });
134
+ }
135
+ else {
136
+ txb.moveCall({
137
+ target: protocol_1.PROTOCOL.DemandFn('yes'),
138
+ arguments: [demand, txb.pure(service, bcs_1.BCS.ADDRESS), permission],
139
+ typeArguments: [earnest_type],
140
+ });
141
+ }
142
+ }
143
+ exports.demand_yes = demand_yes;
144
+ function deposit(earnest_type, txb, demand, earnest) {
145
+ return txb.moveCall({
146
+ target: protocol_1.PROTOCOL.DemandFn('deposit'),
147
+ arguments: [demand, earnest],
148
+ typeArguments: [earnest_type],
149
+ });
150
+ }
151
+ exports.deposit = deposit;
152
+ function present(earnest_type, service_type, txb, demand, service, tips, passport) {
153
+ if (passport) {
154
+ return txb.moveCall({
155
+ target: protocol_1.PROTOCOL.DemandFn('present_with_passport'),
156
+ arguments: [passport, demand, service, txb.pure((0, protocol_1.description_data)(tips)),],
157
+ typeArguments: [earnest_type, service_type],
158
+ });
159
+ }
160
+ else {
161
+ return txb.moveCall({
162
+ target: protocol_1.PROTOCOL.DemandFn('present'),
163
+ arguments: [demand, service, txb.pure((0, protocol_1.description_data)(tips)),],
164
+ typeArguments: [earnest_type, service_type],
165
+ });
166
+ }
167
+ }
168
+ exports.present = present;
169
+ function change_permission(earnest_type, txb, demand, old_permission, new_permission) {
170
+ txb.moveCall({
171
+ target: protocol_1.PROTOCOL.DemandFn('permission_set'),
172
+ arguments: [demand, old_permission, new_permission],
173
+ typeArguments: [earnest_type]
174
+ });
175
+ }
176
+ exports.change_permission = change_permission;
package/dist/guard.js ADDED
@@ -0,0 +1,267 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sense_objects_fn = exports.description_fn = exports.parse_sense_bsc = exports.SenseMaker = exports.Sense_Cmd = exports.query_description = exports.signer_guard = exports.launch = exports.Guard_Sense_Binder = void 0;
4
+ const bcs_1 = require("@mysten/bcs");
5
+ const protocol_1 = require("./protocol");
6
+ const util_1 = require("./util");
7
+ var Guard_Sense_Binder;
8
+ (function (Guard_Sense_Binder) {
9
+ Guard_Sense_Binder[Guard_Sense_Binder["AND"] = 1] = "AND";
10
+ Guard_Sense_Binder[Guard_Sense_Binder["OR"] = 2] = "OR";
11
+ })(Guard_Sense_Binder || (exports.Guard_Sense_Binder = Guard_Sense_Binder = {}));
12
+ function launch(txb, creation) {
13
+ var guard = txb.moveCall({
14
+ target: protocol_1.PROTOCOL.GuardFn('new'),
15
+ arguments: [txb.pure(creation.description, bcs_1.BCS.STRING),],
16
+ });
17
+ creation?.senses.forEach((sense) => {
18
+ txb.moveCall({
19
+ target: protocol_1.PROTOCOL.GuardFn('sense_add'),
20
+ arguments: [guard, txb.pure([].slice.call(sense.input)),
21
+ txb.pure(sense.notAfterSense, bcs_1.BCS.BOOL),
22
+ txb.pure(sense.binder, bcs_1.BCS.U8),
23
+ ]
24
+ });
25
+ });
26
+ return txb.moveCall({
27
+ target: protocol_1.PROTOCOL.GuardFn("create"),
28
+ arguments: [guard]
29
+ });
30
+ }
31
+ exports.launch = launch;
32
+ function signer_guard(txb) {
33
+ txb.moveCall({
34
+ target: protocol_1.PROTOCOL.GuardFn('signer_guard'),
35
+ arguments: []
36
+ }); // { kind: 'Result', index: 0 }, ref to address could used by PTB
37
+ }
38
+ exports.signer_guard = signer_guard;
39
+ function query_description(txb, guard) {
40
+ txb.moveCall({
41
+ target: protocol_1.PROTOCOL.GuardFn('description'),
42
+ arguments: [guard]
43
+ });
44
+ }
45
+ exports.query_description = query_description;
46
+ exports.Sense_Cmd = [[protocol_1.MODULES.permission, 'creator', 1, [], protocol_1.Data_Type.TYPE_STATIC_address],
47
+ [protocol_1.MODULES.permission, 'is_admin', 2, [protocol_1.Data_Type.TYPE_STATIC_address], protocol_1.Data_Type.TYPE_STATIC_bool],
48
+ [protocol_1.MODULES.permission, 'has_rights', 3, [protocol_1.Data_Type.TYPE_STATIC_address, protocol_1.Data_Type.TYPE_STATIC_u64], protocol_1.Data_Type.TYPE_STATIC_bool],
49
+ [protocol_1.MODULES.permission, 'contains_address', 4, [protocol_1.Data_Type.TYPE_STATIC_address], protocol_1.Data_Type.TYPE_STATIC_bool],
50
+ [protocol_1.MODULES.permission, 'contains_index', 5, [protocol_1.Data_Type.TYPE_STATIC_address, protocol_1.Data_Type.TYPE_STATIC_u64], protocol_1.Data_Type.TYPE_STATIC_bool],
51
+ [protocol_1.MODULES.permission, 'contains_guard', 6, [protocol_1.Data_Type.TYPE_STATIC_address, protocol_1.Data_Type.TYPE_STATIC_u64], protocol_1.Data_Type.TYPE_STATIC_bool],
52
+ [protocol_1.MODULES.repository, 'permission', 1, [], protocol_1.Data_Type.TYPE_STATIC_address],
53
+ [protocol_1.MODULES.repository, 'policy_contains', 2, [protocol_1.Data_Type.TYPE_STATIC_vec_u8], protocol_1.Data_Type.TYPE_STATIC_bool],
54
+ [protocol_1.MODULES.repository, 'policy_has_permission_index', 3, [protocol_1.Data_Type.TYPE_STATIC_vec_u8], protocol_1.Data_Type.TYPE_STATIC_bool],
55
+ [protocol_1.MODULES.repository, 'policy_permission_index', 4, [protocol_1.Data_Type.TYPE_STATIC_vec_u8], protocol_1.Data_Type.TYPE_STATIC_u64],
56
+ [protocol_1.MODULES.repository, 'policy_value_type', 5, [protocol_1.Data_Type.TYPE_STATIC_vec_u8], protocol_1.Data_Type.TYPE_STATIC_u8],
57
+ [protocol_1.MODULES.repository, 'contains_id', 6, [protocol_1.Data_Type.TYPE_STATIC_address], protocol_1.Data_Type.TYPE_STATIC_bool],
58
+ [protocol_1.MODULES.repository, 'contains_value', 7, [protocol_1.Data_Type.TYPE_STATIC_address, protocol_1.Data_Type.TYPE_STATIC_vec_u8], protocol_1.Data_Type.TYPE_STATIC_bool],
59
+ [protocol_1.MODULES.repository, 'value_without_type', 8, [protocol_1.Data_Type.TYPE_STATIC_address, protocol_1.Data_Type.TYPE_STATIC_vec_u8], protocol_1.Data_Type.TYPE_STATIC_vec_u8],
60
+ [protocol_1.MODULES.repository, 'value', 9, [protocol_1.Data_Type.TYPE_STATIC_address, protocol_1.Data_Type.TYPE_STATIC_vec_u8], protocol_1.Data_Type.TYPE_STATIC_vec_u8],
61
+ [protocol_1.MODULES.repository, 'type', 10, [], protocol_1.Data_Type.TYPE_STATIC_u8],
62
+ [protocol_1.MODULES.repository, 'policy_mode', 11, [], protocol_1.Data_Type.TYPE_STATIC_u8],
63
+ ];
64
+ class SenseMaker {
65
+ data = [];
66
+ type_validator = [];
67
+ constructor() { }
68
+ // serialize const & data
69
+ add_param(type, param) {
70
+ const bcs = new bcs_1.BCS((0, bcs_1.getSuiMoveConfig)());
71
+ switch (type) {
72
+ case protocol_1.Data_Type.TYPE_STATIC_address:
73
+ this.data.push(bcs.ser(bcs_1.BCS.U8, type).toBytes());
74
+ this.data.push(bcs.ser(bcs_1.BCS.ADDRESS, param).toBytes());
75
+ this.type_validator.push(type);
76
+ break;
77
+ case protocol_1.Data_Type.TYPE_STATIC_bool:
78
+ this.data.push(bcs.ser(bcs_1.BCS.U8, type).toBytes());
79
+ this.data.push(bcs.ser(bcs_1.BCS.BOOL, param).toBytes());
80
+ this.type_validator.push(type);
81
+ break;
82
+ case protocol_1.Data_Type.TYPE_STATIC_u8:
83
+ this.data.push(bcs.ser(bcs_1.BCS.U8, type).toBytes());
84
+ this.data.push(bcs.ser(bcs_1.BCS.U8, param).toBytes());
85
+ this.type_validator.push(type);
86
+ break;
87
+ case protocol_1.Data_Type.TYPE_STATIC_u64:
88
+ this.data.push(bcs.ser(bcs_1.BCS.U8, type).toBytes());
89
+ this.data.push(bcs.ser(bcs_1.BCS.U64, param).toBytes());
90
+ this.type_validator.push(type);
91
+ break;
92
+ case protocol_1.Data_Type.TYPE_STATIC_vec_u8:
93
+ this.data.push(bcs.ser(bcs_1.BCS.U8, type).toBytes());
94
+ this.data.push(bcs.ser("vector<u8>", param).toBytes());
95
+ this.type_validator.push(type);
96
+ // this.data[this.data.length-1].forEach((item : number) => console.log(item))
97
+ break;
98
+ case protocol_1.Data_Type.TYPE_CONTEXT_SIGNER:
99
+ this.data.push(bcs.ser(bcs_1.BCS.U8, type).toBytes());
100
+ this.type_validator.push(protocol_1.Data_Type.TYPE_STATIC_address);
101
+ break;
102
+ case protocol_1.Data_Type.TYPE_CONTEXT_CURRENT_CLOCK:
103
+ this.data.push(bcs.ser(bcs_1.BCS.U8, type).toBytes());
104
+ this.type_validator.push(protocol_1.Data_Type.TYPE_STATIC_u64);
105
+ break;
106
+ case protocol_1.Data_Type.TYPE_CONTEXT_CURRENT_PROGRESS:
107
+ this.data.push(bcs.ser(bcs_1.BCS.U8, type).toBytes());
108
+ this.type_validator.push(protocol_1.Data_Type.TYPE_STATIC_address);
109
+ break;
110
+ default:
111
+ return false;
112
+ }
113
+ ;
114
+ return true;
115
+ }
116
+ add_cmd(object_address, sense_index) {
117
+ if (!object_address || sense_index >= exports.Sense_Cmd.length) {
118
+ return false;
119
+ }
120
+ let offset = this.type_validator.length - exports.Sense_Cmd[sense_index][3].length;
121
+ if (offset < 0) {
122
+ return false;
123
+ }
124
+ let types = this.type_validator.slice(offset);
125
+ if (!(0, util_1.array_equal)(types, exports.Sense_Cmd[sense_index][3])) { // type validate
126
+ return false;
127
+ }
128
+ const bcs = new bcs_1.BCS((0, bcs_1.getSuiMoveConfig)());
129
+ this.data.push(bcs.ser(bcs_1.BCS.U8, protocol_1.Data_Type.TYPE_DYNAMIC_QUERY).toBytes()); // TYPE
130
+ this.data.push(bcs.ser(bcs_1.BCS.ADDRESS, object_address).toBytes()); // object address
131
+ this.data.push(bcs.ser(bcs_1.BCS.U8, exports.Sense_Cmd[sense_index][2]).toBytes()); // cmd
132
+ this.type_validator.splice(offset, exports.Sense_Cmd[sense_index][3].length); // delete type stack
133
+ this.type_validator.push(exports.Sense_Cmd[sense_index][4]); // add the return value type to type stack
134
+ // console.log(this.type_validator)
135
+ return true;
136
+ }
137
+ add_logic(type) {
138
+ switch (type) {
139
+ case protocol_1.Data_Type.TYPE_LOGIC_OPERATOR_U128_GREATER:
140
+ case protocol_1.Data_Type.TYPE_LOGIC_OPERATOR_U128_GREATER_EQUAL:
141
+ case protocol_1.Data_Type.TYPE_LOGIC_OPERATOR_U128_LESSER:
142
+ case protocol_1.Data_Type.TYPE_LOGIC_OPERATOR_U128_LESSER_EQUAL:
143
+ case protocol_1.Data_Type.TYPE_LOGIC_OPERATOR_U128_EQUAL:
144
+ if (this.type_validator.length < 2) {
145
+ return false;
146
+ }
147
+ if (!match_u128(this.type_validator[this.type_validator.length - 1])) {
148
+ return false;
149
+ }
150
+ if (!match_u128(this.type_validator[this.type_validator.length - 2])) {
151
+ return false;
152
+ }
153
+ break;
154
+ case protocol_1.Data_Type.TYPE_LOGIC_OPERATOR_EQUAL:
155
+ case protocol_1.Data_Type.TYPE_LOGIC_OPERATOR_HAS_SUBSTRING:
156
+ if (this.type_validator.length < 2) {
157
+ return false;
158
+ }
159
+ break;
160
+ default:
161
+ return false;
162
+ }
163
+ const bcs = new bcs_1.BCS((0, bcs_1.getSuiMoveConfig)());
164
+ this.data.push(bcs.ser(bcs_1.BCS.U8, type).toBytes()); // TYPE
165
+ this.type_validator.splice(this.type_validator.length - 2); // delete type stack
166
+ this.type_validator.push(protocol_1.Data_Type.TYPE_STATIC_bool); // add bool to type stack
167
+ return true;
168
+ }
169
+ make(bNotAfterSense, binder) {
170
+ //console.log(this.type_validator);
171
+ //this.data.forEach((value:Uint8Array) => console.log(value));
172
+ if (this.type_validator.length != 1 || this.type_validator[0] != protocol_1.Data_Type.TYPE_STATIC_bool) {
173
+ return undefined;
174
+ } // ERROR
175
+ let input = (0, util_1.concatenate)(Uint8Array, ...this.data);
176
+ const sense = { input: input, notAfterSense: bNotAfterSense, binder: binder };
177
+ return sense;
178
+ }
179
+ }
180
+ exports.SenseMaker = SenseMaker;
181
+ function match_u128(type) {
182
+ if (type == protocol_1.Data_Type.TYPE_STATIC_option_u8 ||
183
+ type == protocol_1.Data_Type.TYPE_STATIC_option_u64 ||
184
+ type == protocol_1.Data_Type.TYPE_STATIC_option_u128) {
185
+ return true;
186
+ }
187
+ return false;
188
+ }
189
+ // parse guard senses input bytes of a guard, return [objectids] for 'query_cmd'
190
+ function parse_sense_bsc(chain_sense_bsc) {
191
+ // console.log(data);
192
+ var array = [].slice.call(chain_sense_bsc.reverse());
193
+ const bcs = new bcs_1.BCS((0, bcs_1.getSuiMoveConfig)());
194
+ var result = [];
195
+ while (array.length > 0) {
196
+ var type = array.shift();
197
+ // console.log(type);
198
+ switch (type) {
199
+ case protocol_1.Data_Type.TYPE_CONTEXT_SIGNER:
200
+ case protocol_1.Data_Type.TYPE_CONTEXT_CURRENT_CLOCK:
201
+ case protocol_1.Data_Type.TYPE_CONTEXT_CURRENT_PROGRESS:
202
+ case protocol_1.Data_Type.TYPE_LOGIC_OPERATOR_U128_GREATER:
203
+ case protocol_1.Data_Type.TYPE_LOGIC_OPERATOR_U128_GREATER_EQUAL:
204
+ case protocol_1.Data_Type.TYPE_LOGIC_OPERATOR_U128_LESSER:
205
+ case protocol_1.Data_Type.TYPE_LOGIC_OPERATOR_U128_LESSER_EQUAL:
206
+ case protocol_1.Data_Type.TYPE_LOGIC_OPERATOR_U128_EQUAL:
207
+ case protocol_1.Data_Type.TYPE_LOGIC_OPERATOR_EQUAL:
208
+ case protocol_1.Data_Type.TYPE_LOGIC_OPERATOR_HAS_SUBSTRING:
209
+ break;
210
+ case protocol_1.Data_Type.TYPE_STATIC_address:
211
+ //console.log('0x' + bcs.de(BCS.ADDRESS, Uint8Array.from(array)).toString());
212
+ array.splice(0, 32);
213
+ break;
214
+ case protocol_1.Data_Type.TYPE_STATIC_bool:
215
+ case protocol_1.Data_Type.TYPE_STATIC_u8:
216
+ array.splice(0, 1);
217
+ break;
218
+ case protocol_1.Data_Type.TYPE_STATIC_u64:
219
+ array.splice(0, 8);
220
+ break;
221
+ case protocol_1.Data_Type.TYPE_STATIC_u128:
222
+ array.splice(0, 16);
223
+ break;
224
+ case protocol_1.Data_Type.TYPE_STATIC_vec_u8:
225
+ let { value, length } = (0, util_1.ulebDecode)(Uint8Array.from(array));
226
+ array.splice(0, value + length);
227
+ break;
228
+ case protocol_1.Data_Type.TYPE_DYNAMIC_QUERY:
229
+ result.push('0x' + bcs.de(bcs_1.BCS.ADDRESS, Uint8Array.from(array)).toString());
230
+ array.splice(0, 33); // address + cmd
231
+ break;
232
+ default:
233
+ // console.log('parse_sense_bsc:undefined');
234
+ return undefined; // error
235
+ }
236
+ }
237
+ return result;
238
+ }
239
+ exports.parse_sense_bsc = parse_sense_bsc;
240
+ const MODULE_GUARD_INDEX = 7;
241
+ const description_fn = (response, param, option) => {
242
+ if (!response.error) {
243
+ let c = response?.data?.content;
244
+ if (c.type == protocol_1.OBJECTS_TYPE[MODULE_GUARD_INDEX] && c.fields.id.id == param.objectid) { // GUARD OBJECT
245
+ let description = c.fields.description;
246
+ if (!param.data.includes(description)) {
247
+ param.data.push(description);
248
+ }
249
+ }
250
+ }
251
+ };
252
+ exports.description_fn = description_fn;
253
+ const sense_objects_fn = (response, param, option) => {
254
+ if (!response.error) {
255
+ let c = response?.data?.content;
256
+ if (c.type == protocol_1.OBJECTS_TYPE[MODULE_GUARD_INDEX] && c.fields.id.id == param.objectid) { // GUARD OBJECT
257
+ for (let i = 0; i < c.fields.senses.length; i++) {
258
+ let sense = c.fields.senses[i];
259
+ if (sense.type == (protocol_1.OBJECTS_TYPE_PREFIX[MODULE_GUARD_INDEX] + 'Sense')) { // ...::guard::Sense
260
+ let ids = parse_sense_bsc(Uint8Array.from(sense.fields.input.fields.bytes));
261
+ param.data = (0, util_1.array_unique)(param.data.concat(ids));
262
+ }
263
+ }
264
+ }
265
+ }
266
+ };
267
+ exports.sense_objects_fn = sense_objects_fn;
@@ -0,0 +1,2 @@
1
+ export * from './config.js';
2
+ export * from './community.js';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";