@typemove/move 1.0.0-rc.20 → 1.0.0-rc.22

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.
Files changed (96) hide show
  1. package/dist/cjs/abstract-codegen.d.ts.map +1 -0
  2. package/dist/cjs/abstract-codegen.js +466 -0
  3. package/dist/cjs/abstract-codegen.js.map +1 -0
  4. package/dist/cjs/abstract-move-coder.d.ts.map +1 -0
  5. package/dist/cjs/abstract-move-coder.js +247 -0
  6. package/dist/cjs/abstract-move-coder.js.map +1 -0
  7. package/dist/cjs/account.d.ts.map +1 -0
  8. package/dist/cjs/account.js +76 -0
  9. package/dist/cjs/account.js.map +1 -0
  10. package/dist/cjs/chain-adapter.d.ts.map +1 -0
  11. package/dist/cjs/chain-adapter.js +11 -0
  12. package/dist/cjs/chain-adapter.js.map +1 -0
  13. package/dist/cjs/index.d.ts.map +1 -0
  14. package/dist/cjs/index.js +11 -0
  15. package/dist/cjs/index.js.map +1 -0
  16. package/dist/cjs/internal-models.d.ts.map +1 -0
  17. package/dist/cjs/internal-models.js +10 -0
  18. package/dist/cjs/internal-models.js.map +1 -0
  19. package/dist/cjs/package.json +3 -0
  20. package/dist/{ts-type.test.d.ts.map → cjs/ts-type.test.d.ts.map} +1 -1
  21. package/dist/cjs/ts-type.test.js.map +1 -0
  22. package/dist/cjs/types.d.ts.map +1 -0
  23. package/dist/cjs/types.js +218 -0
  24. package/dist/cjs/types.js.map +1 -0
  25. package/dist/cjs/utils.d.ts.map +1 -0
  26. package/dist/cjs/utils.js +82 -0
  27. package/dist/cjs/utils.js.map +1 -0
  28. package/dist/{utils.test.d.ts.map → cjs/utils.test.d.ts.map} +1 -1
  29. package/dist/cjs/utils.test.js.map +1 -0
  30. package/dist/esm/abstract-codegen.d.ts +49 -0
  31. package/dist/esm/abstract-codegen.d.ts.map +1 -0
  32. package/dist/esm/abstract-codegen.js.map +1 -0
  33. package/dist/esm/abstract-move-coder.d.ts +26 -0
  34. package/dist/esm/abstract-move-coder.d.ts.map +1 -0
  35. package/dist/esm/abstract-move-coder.js.map +1 -0
  36. package/dist/esm/account.d.ts +16 -0
  37. package/dist/esm/account.d.ts.map +1 -0
  38. package/dist/esm/account.js.map +1 -0
  39. package/dist/esm/chain-adapter.d.ts +14 -0
  40. package/dist/esm/chain-adapter.d.ts.map +1 -0
  41. package/dist/esm/chain-adapter.js.map +1 -0
  42. package/dist/esm/index.d.ts +8 -0
  43. package/dist/esm/index.d.ts.map +1 -0
  44. package/dist/esm/index.js.map +1 -0
  45. package/dist/esm/internal-models.d.ts +36 -0
  46. package/dist/esm/internal-models.d.ts.map +1 -0
  47. package/dist/esm/internal-models.js.map +1 -0
  48. package/dist/esm/ts-type.test.d.ts +2 -0
  49. package/dist/esm/ts-type.test.d.ts.map +1 -0
  50. package/dist/esm/ts-type.test.js.map +1 -0
  51. package/dist/esm/types.d.ts +43 -0
  52. package/dist/esm/types.d.ts.map +1 -0
  53. package/dist/esm/types.js.map +1 -0
  54. package/dist/esm/utils.d.ts +17 -0
  55. package/dist/esm/utils.d.ts.map +1 -0
  56. package/dist/esm/utils.js.map +1 -0
  57. package/dist/esm/utils.test.d.ts +2 -0
  58. package/dist/esm/utils.test.d.ts.map +1 -0
  59. package/dist/esm/utils.test.js.map +1 -0
  60. package/package.json +10 -5
  61. package/dist/abstract-codegen.d.ts.map +0 -1
  62. package/dist/abstract-codegen.js.map +0 -1
  63. package/dist/abstract-move-coder.d.ts.map +0 -1
  64. package/dist/abstract-move-coder.js.map +0 -1
  65. package/dist/account.d.ts.map +0 -1
  66. package/dist/account.js.map +0 -1
  67. package/dist/chain-adapter.d.ts.map +0 -1
  68. package/dist/chain-adapter.js.map +0 -1
  69. package/dist/index.d.ts.map +0 -1
  70. package/dist/index.js.map +0 -1
  71. package/dist/internal-models.d.ts.map +0 -1
  72. package/dist/internal-models.js.map +0 -1
  73. package/dist/ts-type.test.js.map +0 -1
  74. package/dist/types.d.ts.map +0 -1
  75. package/dist/types.js.map +0 -1
  76. package/dist/utils.d.ts.map +0 -1
  77. package/dist/utils.js.map +0 -1
  78. package/dist/utils.test.js.map +0 -1
  79. /package/dist/{abstract-codegen.d.ts → cjs/abstract-codegen.d.ts} +0 -0
  80. /package/dist/{abstract-move-coder.d.ts → cjs/abstract-move-coder.d.ts} +0 -0
  81. /package/dist/{account.d.ts → cjs/account.d.ts} +0 -0
  82. /package/dist/{chain-adapter.d.ts → cjs/chain-adapter.d.ts} +0 -0
  83. /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
  84. /package/dist/{internal-models.d.ts → cjs/internal-models.d.ts} +0 -0
  85. /package/dist/{ts-type.test.d.ts → cjs/ts-type.test.d.ts} +0 -0
  86. /package/dist/{types.d.ts → cjs/types.d.ts} +0 -0
  87. /package/dist/{utils.d.ts → cjs/utils.d.ts} +0 -0
  88. /package/dist/{utils.test.d.ts → cjs/utils.test.d.ts} +0 -0
  89. /package/dist/{abstract-codegen.js → esm/abstract-codegen.js} +0 -0
  90. /package/dist/{abstract-move-coder.js → esm/abstract-move-coder.js} +0 -0
  91. /package/dist/{account.js → esm/account.js} +0 -0
  92. /package/dist/{chain-adapter.js → esm/chain-adapter.js} +0 -0
  93. /package/dist/{index.js → esm/index.js} +0 -0
  94. /package/dist/{internal-models.js → esm/internal-models.js} +0 -0
  95. /package/dist/{types.js → esm/types.js} +0 -0
  96. /package/dist/{utils.js → esm/utils.js} +0 -0
@@ -0,0 +1,247 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AbstractMoveCoder = void 0;
4
+ const utils_js_1 = require("./utils.js");
5
+ const types_js_1 = require("./types.js");
6
+ class AbstractMoveCoder {
7
+ moduleMapping = new Map();
8
+ typeMapping = new Map();
9
+ funcMapping = new Map();
10
+ // network: string
11
+ adapter;
12
+ constructor(adapter) {
13
+ this.adapter = adapter;
14
+ }
15
+ contains(account, name) {
16
+ return this.moduleMapping.has((0, utils_js_1.moduleQname)({ address: account, name }));
17
+ }
18
+ loadInternal(module) {
19
+ const account = (0, utils_js_1.accountAddressString)(module.address);
20
+ if (this.contains(account, module.name)) {
21
+ return;
22
+ }
23
+ this.moduleMapping.set((0, utils_js_1.moduleQname)({ address: account, name: module.name }), module);
24
+ for (const struct of module.structs) {
25
+ // TODO move to util
26
+ const key = [account, module.name, struct.name].join(utils_js_1.SPLITTER);
27
+ this.typeMapping.set(key, struct);
28
+ }
29
+ for (const func of module.exposedFunctions) {
30
+ // if (!func.isEntry) {
31
+ // continue
32
+ // }
33
+ const key = [account, module.name, func.name].join(utils_js_1.SPLITTER);
34
+ this.funcMapping.set(key, func);
35
+ }
36
+ }
37
+ decodeBigInt(data) {
38
+ if (Array.isArray(data)) {
39
+ throw new Error('data is in byte array');
40
+ // Only sui function need this, strange
41
+ // const bytes = data as number[]
42
+ // return bytesToBigInt(new Uint8Array(bytes.slice().reverse()))
43
+ }
44
+ return BigInt(data);
45
+ }
46
+ requestMap = new Map();
47
+ async getMoveStruct(type) {
48
+ const [account_, module, typeName] = type.split(utils_js_1.SPLITTER);
49
+ const account = (0, utils_js_1.accountAddressString)(account_);
50
+ type = [account, module, typeName].join(utils_js_1.SPLITTER);
51
+ let struct = this.typeMapping.get(type);
52
+ if (struct) {
53
+ return struct;
54
+ }
55
+ const key = account + utils_js_1.SPLITTER + module;
56
+ let resp = this.requestMap.get(account + utils_js_1.SPLITTER + module);
57
+ if (!resp) {
58
+ resp = this.adapter.fetchModule(account, module).then((m) => {
59
+ return this.load(m);
60
+ });
61
+ this.requestMap.set(key, resp);
62
+ }
63
+ await resp;
64
+ struct = this.typeMapping.get(type);
65
+ if (struct) {
66
+ return struct;
67
+ }
68
+ throw new Error('Failed to load function ' + type + ' type are not imported anywhere');
69
+ }
70
+ async getMoveFunction(type) {
71
+ const [account_, module, typeName] = type.split(utils_js_1.SPLITTER);
72
+ const account = (0, utils_js_1.accountAddressString)(account_);
73
+ type = [account, module, typeName].join(utils_js_1.SPLITTER);
74
+ let func = this.funcMapping.get(type);
75
+ if (func) {
76
+ return func;
77
+ }
78
+ const key = account + utils_js_1.SPLITTER + module;
79
+ let resp = this.requestMap.get(account + utils_js_1.SPLITTER + module);
80
+ if (!resp) {
81
+ resp = this.adapter.fetchModule(account, module).then((m) => {
82
+ return this.load(m);
83
+ });
84
+ this.requestMap.set(key, resp);
85
+ }
86
+ await resp;
87
+ func = this.funcMapping.get(type);
88
+ if (func) {
89
+ return func;
90
+ }
91
+ throw new Error('Failed to load function ' + type + ' type are not imported anywhere');
92
+ }
93
+ async decode(data, type) {
94
+ // process simple type
95
+ if (type.reference) {
96
+ return data;
97
+ }
98
+ switch (type.qname) {
99
+ case 'signer': // TODO check this, aptos only
100
+ case 'address':
101
+ case 'Address':
102
+ case '0x1::string::String':
103
+ case 'bool':
104
+ case 'Bool':
105
+ case 'u8':
106
+ case 'U8':
107
+ case 'u16':
108
+ case 'U16':
109
+ case 'u32':
110
+ case 'U32':
111
+ return data;
112
+ case 'u64':
113
+ case 'U64':
114
+ case 'u128':
115
+ case 'U128':
116
+ case 'u256':
117
+ case 'U256':
118
+ return this.decodeBigInt(data);
119
+ }
120
+ // process vector
121
+ if (type.qname.toLowerCase() === utils_js_1.VECTOR_STR) {
122
+ // vector<u8> as hex string
123
+ if (type.typeArgs[0].qname === 'u8' || type.typeArgs[0].qname === 'U8') {
124
+ return data;
125
+ }
126
+ const res = [];
127
+ for (const entry of data) {
128
+ res.push(await this.decode(entry, type.typeArgs[0]));
129
+ }
130
+ return res;
131
+ }
132
+ // Process complex type
133
+ const struct = await this.getMoveStruct(type.qname);
134
+ const typeCtx = new Map();
135
+ for (const [idx, typeArg] of type.typeArgs.entries()) {
136
+ typeCtx.set('T' + idx, typeArg);
137
+ }
138
+ const typedData = {};
139
+ for (const field of struct.fields) {
140
+ let filedType = field.type;
141
+ filedType = filedType.applyTypeArgs(typeCtx);
142
+ const fieldValue = this.adapter.getData(data)[field.name];
143
+ const value = await this.decode(fieldValue, filedType);
144
+ typedData[field.name] = value;
145
+ }
146
+ return typedData;
147
+ }
148
+ async decodeArray(entries, types, strict = true) {
149
+ const entriesDecoded = [];
150
+ for (const [idx, arg] of entries.entries()) {
151
+ // TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them
152
+ const argType = types[idx];
153
+ try {
154
+ if (!strict && arg === undefined) {
155
+ entriesDecoded.push(arg);
156
+ }
157
+ else {
158
+ entriesDecoded.push(await this.decode(arg, argType));
159
+ }
160
+ }
161
+ catch (e) {
162
+ throw Error('Decoding error for ' + JSON.stringify(arg) + 'using type' + argType + e.toString());
163
+ }
164
+ }
165
+ return entriesDecoded;
166
+ }
167
+ encode(data) {
168
+ if (!data) {
169
+ return undefined;
170
+ }
171
+ for (const [key, value] of Object.entries(data)) {
172
+ if (!value) {
173
+ continue;
174
+ }
175
+ if (typeof value === 'bigint') {
176
+ data[key] = value.toString();
177
+ }
178
+ }
179
+ return data;
180
+ }
181
+ encodeArray(entriesDecoded) {
182
+ const entries = [];
183
+ for (const [idx, arg] of entriesDecoded.entries()) {
184
+ entries.push(this.encode(arg));
185
+ }
186
+ return entries;
187
+ }
188
+ async decodeCallResult(res, func) {
189
+ const f = await this.getMoveFunction(func);
190
+ return this.decodeArray(res, f.return);
191
+ }
192
+ async filterAndDecodeStruct(typeMatcher, structsWithTags) {
193
+ if (!structsWithTags) {
194
+ return [];
195
+ }
196
+ // const typeMatcherDescriptor = parseMoveType(typeMatcher)
197
+ const results = [];
198
+ for (const resource of structsWithTags) {
199
+ const resourceType = this.adapter.getType(resource);
200
+ const resourceTypeDescriptor = (0, types_js_1.parseMoveType)(resourceType);
201
+ if (!(0, types_js_1.matchType)(typeMatcher, resourceTypeDescriptor)) {
202
+ continue;
203
+ }
204
+ const result = await this.decodedStruct(resource);
205
+ if (result) {
206
+ results.push(result);
207
+ }
208
+ else {
209
+ console.error('decoding error');
210
+ }
211
+ }
212
+ return results;
213
+ }
214
+ async decodedStruct(typeStruct) {
215
+ const typeDescriptor = (0, types_js_1.parseMoveType)(this.adapter.getType(typeStruct));
216
+ const typeArguments = typeDescriptor.typeArgs.map((t) => t.getSignature());
217
+ let dataTyped = undefined;
218
+ try {
219
+ dataTyped = await this.decode(typeStruct, typeDescriptor);
220
+ }
221
+ catch (e) {
222
+ throw Error('Decoding error for struct' + JSON.stringify(typeStruct) + e.toString());
223
+ // return undefined
224
+ }
225
+ return {
226
+ ...typeStruct,
227
+ data_decoded: dataTyped,
228
+ type_arguments: typeArguments,
229
+ };
230
+ }
231
+ async decodedType(typeStruct, type) {
232
+ if (typeStruct === null || typeStruct == undefined) {
233
+ return typeStruct;
234
+ }
235
+ if (typeof typeStruct === 'object') {
236
+ if ('type' in typeStruct) {
237
+ const typeInStruct = (0, types_js_1.parseMoveType)(typeStruct.type.toString() || '');
238
+ if (!(0, types_js_1.matchType)(type, typeInStruct)) {
239
+ return undefined;
240
+ }
241
+ }
242
+ }
243
+ return await this.decode(typeStruct, type);
244
+ }
245
+ }
246
+ exports.AbstractMoveCoder = AbstractMoveCoder;
247
+ //# sourceMappingURL=abstract-move-coder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abstract-move-coder.js","sourceRoot":"","sources":["../../src/abstract-move-coder.ts"],"names":[],"mappings":";;;AAAA,yCAAoF;AACpF,yCAAoF;AAKpF,MAAsB,iBAAiB;IAC3B,aAAa,GAAG,IAAI,GAAG,EAA8B,CAAA;IACvD,WAAW,GAAG,IAAI,GAAG,EAA8B,CAAA;IACnD,WAAW,GAAG,IAAI,GAAG,EAAgC,CAAA;IAC7D,kBAAkB;IAClB,OAAO,CAAsC;IAE7C,YAAsB,OAA6C;QACjE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,QAAQ,CAAC,OAAe,EAAE,IAAY;QACpC,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAA,sBAAW,EAAC,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IACxE,CAAC;IAIS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UAAU,KAAK,QAAQ,EAAE;YAClC,IAAI,MAAM,IAAI,UAAU,EAAE;gBACxB,MAAM,YAAY,GAAG,IAAA,wBAAa,EAAE,UAAU,CAAC,IAAY,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;gBAC7E,IAAI,CAAC,IAAA,oBAAS,EAAC,IAAI,EAAE,YAAY,CAAC,EAAE;oBAClC,OAAO,SAAS,CAAA;iBACjB;aACF;SACF;QAED,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;IAC5C,CAAC;CACF;AA5QD,8CA4QC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../src/account.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAEzD,qBAAa,wBAAwB;IAEnC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;IACjC,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,MAAM,CAAA;gBAEN,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;IAMjD,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAW1C;AAED,qBAAa,eAAe;IAC1B,cAAc,wCAA8C;IAC5D,eAAe,cAAoB;IAEnC,QAAQ,CACN,MAAM,EAAE,kBAAkB,EAC1B,YAAY,EAAE,MAAM,GACnB,wBAAwB;IAqB3B,OAAO,CAAC,iBAAiB;IAoBzB,OAAO,CAAC,cAAc;CAgBvB"}
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AccountRegister = exports.AccountModulesImportInfo = void 0;
4
+ const utils_js_1 = require("./utils.js");
5
+ class AccountModulesImportInfo {
6
+ // account to module
7
+ imports;
8
+ account;
9
+ moduleName;
10
+ constructor(account, tsModuleName) {
11
+ this.account = account;
12
+ this.moduleName = tsModuleName;
13
+ this.imports = new Map();
14
+ }
15
+ addImport(account, module) {
16
+ if (account === this.account) {
17
+ return;
18
+ }
19
+ let accountModules = this.imports.get(account);
20
+ if (!accountModules) {
21
+ accountModules = new Set();
22
+ this.imports.set(account, accountModules);
23
+ }
24
+ accountModules.add(module);
25
+ }
26
+ }
27
+ exports.AccountModulesImportInfo = AccountModulesImportInfo;
28
+ class AccountRegister {
29
+ accountImports = new Map();
30
+ pendingAccounts = new Set();
31
+ register(module, tsModuleName) {
32
+ const currentModuleFqn = (0, utils_js_1.moduleQname)(module);
33
+ let accountModuleImports = this.accountImports.get(module.address);
34
+ if (!accountModuleImports) {
35
+ accountModuleImports = new AccountModulesImportInfo(module.address, tsModuleName);
36
+ this.accountImports.set(module.address, accountModuleImports);
37
+ // the account has already be processed, delete pending task
38
+ this.pendingAccounts.delete(module.address);
39
+ }
40
+ this.registerStruct(module, accountModuleImports);
41
+ this.registerFunctions(module, accountModuleImports);
42
+ this.accountImports.set(currentModuleFqn, accountModuleImports);
43
+ return accountModuleImports;
44
+ }
45
+ registerFunctions(module, accountModuleImports) {
46
+ for (const func of module.exposedFunctions) {
47
+ if (!func.isEntry) {
48
+ continue;
49
+ }
50
+ for (const param of func.params) {
51
+ for (const type of param.dependedTypes()) {
52
+ const [account, module] = (0, utils_js_1.moduleQnameForType)(type);
53
+ accountModuleImports.addImport(account, module);
54
+ if (!this.accountImports.has(account)) {
55
+ this.pendingAccounts.add(account);
56
+ }
57
+ }
58
+ }
59
+ }
60
+ }
61
+ registerStruct(module, accountModuleImports) {
62
+ for (const struct of module.structs) {
63
+ for (const field of struct.fields) {
64
+ for (const type of field.type.dependedTypes()) {
65
+ const [account, module] = (0, utils_js_1.moduleQnameForType)(type);
66
+ accountModuleImports.addImport(account, module);
67
+ if (!this.accountImports.has(account)) {
68
+ this.pendingAccounts.add(account);
69
+ }
70
+ }
71
+ }
72
+ }
73
+ }
74
+ }
75
+ exports.AccountRegister = AccountRegister;
76
+ //# sourceMappingURL=account.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/account.ts"],"names":[],"mappings":";;;AAAA,yCAA4D;AAG5D,MAAa,wBAAwB;IACnC,oBAAoB;IACpB,OAAO,CAA0B;IACjC,OAAO,CAAQ;IACf,UAAU,CAAQ;IAElB,YAAY,OAAe,EAAE,YAAoB;QAC/C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,UAAU,GAAG,YAAY,CAAA;QAC9B,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAuB,CAAA;IAC/C,CAAC;IAED,SAAS,CAAC,OAAe,EAAE,MAAc;QACvC,IAAI,OAAO,KAAK,IAAI,CAAC,OAAO,EAAE;YAC5B,OAAM;SACP;QACD,IAAI,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;QAC9C,IAAI,CAAC,cAAc,EAAE;YACnB,cAAc,GAAG,IAAI,GAAG,EAAU,CAAA;YAClC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,cAAc,CAAC,CAAA;SAC1C;QACD,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IAC5B,CAAC;CACF;AAvBD,4DAuBC;AAED,MAAa,eAAe;IAC1B,cAAc,GAAG,IAAI,GAAG,EAAoC,CAAA;IAC5D,eAAe,GAAG,IAAI,GAAG,EAAU,CAAA;IAEnC,QAAQ,CACN,MAA0B,EAC1B,YAAoB;QAEpB,MAAM,gBAAgB,GAAG,IAAA,sBAAW,EAAC,MAAM,CAAC,CAAA;QAE5C,IAAI,oBAAoB,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QAClE,IAAI,CAAC,oBAAoB,EAAE;YACzB,oBAAoB,GAAG,IAAI,wBAAwB,CACjD,MAAM,CAAC,OAAO,EACd,YAAY,CACb,CA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,CAAC,EAAE,IAAI,EAAE,UAAU,GAAG,GAAG;CAC3C"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChainAdapter = void 0;
4
+ class ChainAdapter {
5
+ endpoint;
6
+ constructor(endpoint) {
7
+ this.endpoint = endpoint;
8
+ }
9
+ }
10
+ exports.ChainAdapter = ChainAdapter;
11
+ //# sourceMappingURL=chain-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chain-adapter.js","sourceRoot":"","sources":["../../src/chain-adapter.ts"],"names":[],"mappings":";;;AAGA,MAAsB,YAAY;IAChC,QAAQ,CAAQ;IAEhB,YAAY,QAAgB;QAC1B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC1B,CAAC;CAoBF;AAzBD,oCAyBC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,0BAA0B,CAAA;AACxC,cAAc,sBAAsB,CAAA"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./types.js"), exports);
5
+ tslib_1.__exportStar(require("./utils.js"), exports);
6
+ tslib_1.__exportStar(require("./account.js"), exports);
7
+ tslib_1.__exportStar(require("./chain-adapter.js"), exports);
8
+ tslib_1.__exportStar(require("./abstract-codegen.js"), exports);
9
+ tslib_1.__exportStar(require("./abstract-move-coder.js"), exports);
10
+ tslib_1.__exportStar(require("./internal-models.js"), exports);
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAA0B;AAC1B,qDAA0B;AAC1B,uDAA4B;AAC5B,6DAAkC;AAClC,gEAAqC;AACrC,mEAAwC;AACxC,+DAAoC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal-models.d.ts","sourceRoot":"","sources":["../../src/internal-models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE3C,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,gBAAgB,EAAE,oBAAoB,EAAE,CAAA;IACxC,OAAO,EAAE,kBAAkB,EAAE,CAAA;CAC9B;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,8BAA8B,CAAA;IAC1C,OAAO,EAAE,OAAO,CAAA;IAChB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,UAAU,EAAE,qBAAqB,EAAE,CAAA;IACnC,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,MAAM,EAAE,cAAc,EAAE,CAAA;CACzB;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,OAAO,CAAA;IACjB,SAAS,EAAE,MAAM,EAAE,CAAA;IACnB,UAAU,EAAE,qBAAqB,EAAE,CAAA;IACnC,MAAM,EAAE,uBAAuB,EAAE,CAAA;CAClC;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,cAAc,CAAA;CACrB;AAED,oBAAY,8BAA8B;IACxC,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,MAAM,WAAW;CAClB;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,WAAW,EAAE,MAAM,EAAE,CAAA;CACtB,CAAA"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InternalMoveFunctionVisibility = void 0;
4
+ var InternalMoveFunctionVisibility;
5
+ (function (InternalMoveFunctionVisibility) {
6
+ InternalMoveFunctionVisibility["PRIVATE"] = "private";
7
+ InternalMoveFunctionVisibility["PUBLIC"] = "public";
8
+ InternalMoveFunctionVisibility["FRIEND"] = "friend";
9
+ })(InternalMoveFunctionVisibility || (exports.InternalMoveFunctionVisibility = InternalMoveFunctionVisibility = {}));
10
+ //# sourceMappingURL=internal-models.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal-models.js","sourceRoot":"","sources":["../../src/internal-models.ts"],"names":[],"mappings":";;;AAgCA,IAAY,8BAIX;AAJD,WAAY,8BAA8B;IACxC,qDAAmB,CAAA;IACnB,mDAAiB,CAAA;IACjB,mDAAiB,CAAA;AACnB,CAAC,EAJW,8BAA8B,8CAA9B,8BAA8B,QAIzC"}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"ts-type.test.d.ts","sourceRoot":"","sources":["../src/ts-type.test.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"ts-type.test.d.ts","sourceRoot":"","sources":["../../src/ts-type.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ts-type.test.js","sourceRoot":"","sources":["../../src/ts-type.test.ts"],"names":[],"mappings":";;AAAA,+BAA6B;AAC7B,yCAA0C;AAE1C,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;IACxB,IAAI,CAAC,sBAAsB,EAAE,KAAK,IAAI,EAAE;QACtC,MAAM,GAAG,GAAG,IAAA,wBAAa,EAAC,8BAA8B,CAAC,CAAA;QAEzD,IAAA,aAAM,EAAC,GAAG,CAAC,KAAK,KAAK,GAAG,CAAC,CAAA;QACzB,IAAA,aAAM,EAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,IAAI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AAC,EAAE,CAAC,CAErB;AAED,eAAO,MAAM,aAAa;;;;;;;;;;;CAqBzB,CAAA;AAWD;;;;GAIG;AACH,wBAAgB,SAAS,CACvB,OAAO,EAAE,cAAc,EACvB,IAAI,EAAE,cAAc,GACnB,OAAO,CAcT"}
@@ -0,0 +1,218 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.matchType = exports.BUILTIN_TYPES = exports.vectorType = exports.ANY_TYPE = exports.parseMoveType = exports.TypeDescriptor = void 0;
4
+ const utils_js_1 = require("./utils.js");
5
+ class TypeDescriptor {
6
+ qname;
7
+ reference;
8
+ mutable;
9
+ typeArgs;
10
+ constructor(symbol, typeParams) {
11
+ this.qname = symbol;
12
+ this.reference = false;
13
+ this.mutable = false;
14
+ this.typeArgs = typeParams || [];
15
+ }
16
+ apply(...typeArgs) {
17
+ const newObj = this.clone();
18
+ newObj.typeArgs = typeArgs;
19
+ return newObj;
20
+ }
21
+ clone() {
22
+ const newObj = new TypeDescriptor(this.qname, this.typeArgs);
23
+ newObj.reference = this.reference;
24
+ newObj.mutable = this.mutable;
25
+ return newObj;
26
+ }
27
+ // compare qname without consider case for system type
28
+ compareQname(t) {
29
+ let t1 = this.qname;
30
+ if (BUILTIN_TYPES_SET.has(this.qname.toLowerCase())) {
31
+ t1 = this.qname.toLowerCase();
32
+ }
33
+ let t2 = t.qname;
34
+ if (BUILTIN_TYPES_SET.has(t.qname.toLowerCase())) {
35
+ t2 = t.qname;
36
+ }
37
+ return t1 === t2;
38
+ }
39
+ getSignature() {
40
+ if (this.typeArgs.length > 0) {
41
+ return (this.qname +
42
+ '<' +
43
+ this.typeArgs.map((t) => t.getSignature()).join(', ') +
44
+ '>');
45
+ }
46
+ return this.qname;
47
+ }
48
+ // Replace T0, T1 with more concrete type
49
+ applyTypeArgs(ctx) {
50
+ const replace = ctx.get(this.qname);
51
+ if (replace) {
52
+ return replace;
53
+ }
54
+ if (ctx.size === 0 || this.typeArgs.length === 0) {
55
+ return this;
56
+ }
57
+ const typeArgs = [];
58
+ for (const arg of this.typeArgs) {
59
+ const replace = ctx.get(arg.qname);
60
+ if (replace) {
61
+ typeArgs.push(replace);
62
+ }
63
+ else {
64
+ typeArgs.push(arg.applyTypeArgs(ctx));
65
+ }
66
+ }
67
+ return new TypeDescriptor(this.qname, typeArgs);
68
+ }
69
+ // all depended types including itself, not include system type
70
+ dependedTypes() {
71
+ if (this.qname.startsWith('&')) {
72
+ console.error('Not expected &');
73
+ return [];
74
+ }
75
+ if (this.isVector()) {
76
+ return this.typeArgs[0].dependedTypes();
77
+ }
78
+ if (BUILTIN_TYPES_SET.has(this.qname.toLowerCase())) {
79
+ return [];
80
+ }
81
+ switch (this.qname) {
82
+ case 'signer':
83
+ case '0x1::string::String':
84
+ return [];
85
+ }
86
+ // Type parameters are not depended
87
+ if (this.qname.indexOf(utils_js_1.SPLITTER) == -1) {
88
+ if (this.qname.startsWith('T')) {
89
+ return [];
90
+ }
91
+ }
92
+ const types = new Set();
93
+ for (const param of this.typeArgs) {
94
+ param.dependedTypes().forEach((t) => types.add(t));
95
+ }
96
+ types.add(this.qname);
97
+ return Array.from(types);
98
+ }
99
+ isVector() {
100
+ return this.qname.toLowerCase() === utils_js_1.VECTOR_STR;
101
+ }
102
+ }
103
+ exports.TypeDescriptor = TypeDescriptor;
104
+ function parseMoveType(type) {
105
+ const stack = [new TypeDescriptor('')];
106
+ let buffer = [];
107
+ // xxx:asdf<g1<a,<c,d>>, b, g2<a,b>, e>
108
+ for (let i = 0; i < type.length; i++) {
109
+ const ch = type[i];
110
+ if (ch === ' ') {
111
+ continue;
112
+ }
113
+ if (ch === '<') {
114
+ // const symbol = type.slice(symbolStart, i)
115
+ // symbolStart =
116
+ const symbol = buffer.join('');
117
+ buffer = [];
118
+ stack[stack.length - 1].qname = symbol;
119
+ adjustType(stack[stack.length - 1]);
120
+ stack.push(new TypeDescriptor(''));
121
+ continue;
122
+ }
123
+ if (ch === '>' || ch === ',') {
124
+ const typeParam = stack.pop();
125
+ if (!typeParam) {
126
+ throw Error('Unexpected stack size');
127
+ }
128
+ if (buffer.length > 0) {
129
+ typeParam.qname = buffer.join('');
130
+ buffer = [];
131
+ }
132
+ adjustType(typeParam);
133
+ stack[stack.length - 1].typeArgs.push(typeParam);
134
+ if (ch === ',') {
135
+ stack.push(new TypeDescriptor(''));
136
+ }
137
+ continue;
138
+ }
139
+ buffer.push(ch);
140
+ }
141
+ if (buffer.length > 0) {
142
+ stack[stack.length - 1].qname = buffer.join('');
143
+ }
144
+ adjustType(stack[stack.length - 1]);
145
+ const res = stack.pop();
146
+ if (!res || stack.length > 0) {
147
+ throw Error('Unexpected stack size');
148
+ }
149
+ return res;
150
+ }
151
+ exports.parseMoveType = parseMoveType;
152
+ function adjustType(type) {
153
+ if (type.qname.startsWith('&')) {
154
+ type.reference = true;
155
+ type.qname = type.qname.slice(1);
156
+ }
157
+ if (type.qname.startsWith('mut')) {
158
+ type.mutable = true;
159
+ type.qname = type.qname.slice(3);
160
+ }
161
+ const parts = type.qname.split(utils_js_1.SPLITTER);
162
+ if (parts.length > 1) {
163
+ const [account, module, name] = parts;
164
+ type.qname = [(0, utils_js_1.accountTypeString)(account), module, name].join(utils_js_1.SPLITTER);
165
+ }
166
+ }
167
+ exports.ANY_TYPE = new TypeDescriptor('any');
168
+ function vectorType(t = exports.ANY_TYPE) {
169
+ return exports.BUILTIN_TYPES.VECTOR_TYPE_ANY.apply(t);
170
+ }
171
+ exports.vectorType = vectorType;
172
+ exports.BUILTIN_TYPES = {
173
+ ADDRESS_TYPE: new TypeDescriptor('address'),
174
+ // export const Address = new TypeDescriptor<string>("Address")
175
+ VECTOR_TYPE_ANY: new TypeDescriptor('vector'),
176
+ VECTOR_TYPE: vectorType,
177
+ BOOL_TYPE: new TypeDescriptor('bool'),
178
+ U8_TYPE: new TypeDescriptor('u8'),
179
+ // export const U8 = new TypeDescriptor<number>("U8")
180
+ U16_TYPE: new TypeDescriptor('u16'),
181
+ // export const U16 = new TypeDescriptor<number>("U16")
182
+ U32_TYPE: new TypeDescriptor('u32'),
183
+ // export const U32 = new TypeDescriptor<number>("U32")
184
+ U64_TYPE: new TypeDescriptor('u64'),
185
+ // export const U64 = new TypeDescriptor<number>("U64")
186
+ U128_TYPE: new TypeDescriptor('u128'),
187
+ // export const U128 = new TypeDescriptor<number>("U128")
188
+ U256_TYPE: new TypeDescriptor('u256'),
189
+ // export const U256 = new TypeDescriptor<number>("U256")
190
+ };
191
+ const BUILTIN_TYPES_SET = new Set(Object.values(exports.BUILTIN_TYPES).flatMap((t) => {
192
+ if (typeof t === 'object') {
193
+ return [t.qname.toLowerCase()];
194
+ }
195
+ return [];
196
+ }));
197
+ /**
198
+ *
199
+ * @param matcher
200
+ * @param type
201
+ */
202
+ function matchType(matcher, type) {
203
+ if (matcher.qname === 'any') {
204
+ return true;
205
+ }
206
+ if (!matcher.compareQname(type)) {
207
+ return false;
208
+ }
209
+ for (const [idx, matcherTarg] of matcher.typeArgs.entries()) {
210
+ const targ = type.typeArgs[idx];
211
+ if (!matchType(matcherTarg, targ)) {
212
+ return false;
213
+ }
214
+ }
215
+ return true;
216
+ }
217
+ exports.matchType = matchType;
218
+ //# sourceMappingURL=types.js.map