@activeledger/activehybrid 5.0.2 → 5.1.1

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 (255) hide show
  1. package/README.md +13 -46
  2. package/es/api.d.ts +53 -0
  3. package/es/api.d.ts.map +1 -0
  4. package/es/api.js +365 -0
  5. package/es/api.js.map +1 -0
  6. package/es/bootstrap.d.ts +36 -0
  7. package/es/bootstrap.d.ts.map +1 -0
  8. package/es/bootstrap.js +106 -0
  9. package/es/bootstrap.js.map +1 -0
  10. package/es/commands.d.ts +25 -0
  11. package/es/commands.d.ts.map +1 -0
  12. package/es/commands.js +185 -0
  13. package/es/commands.js.map +1 -0
  14. package/es/config.d.ts +17 -0
  15. package/es/config.d.ts.map +1 -0
  16. package/es/config.js +395 -0
  17. package/es/config.js.map +1 -0
  18. package/es/contracts.d.ts +31 -0
  19. package/es/contracts.d.ts.map +1 -0
  20. package/es/contracts.js +171 -0
  21. package/es/contracts.js.map +1 -0
  22. package/es/divergence.d.ts +8 -0
  23. package/es/divergence.d.ts.map +1 -0
  24. package/es/divergence.js +40 -0
  25. package/es/divergence.js.map +1 -0
  26. package/es/events.d.ts +38 -0
  27. package/es/events.d.ts.map +1 -0
  28. package/es/events.js +144 -0
  29. package/es/events.js.map +1 -0
  30. package/es/feed.d.ts +42 -0
  31. package/es/feed.d.ts.map +1 -0
  32. package/es/feed.js +167 -0
  33. package/es/feed.js.map +1 -0
  34. package/es/http-upstream.d.ts +83 -0
  35. package/es/http-upstream.d.ts.map +1 -0
  36. package/es/http-upstream.js +360 -0
  37. package/es/http-upstream.js.map +1 -0
  38. package/es/index.js +211 -43
  39. package/es/index.js.map +1 -1
  40. package/es/lookup.d.ts +34 -0
  41. package/es/lookup.d.ts.map +1 -0
  42. package/es/lookup.js +194 -0
  43. package/es/lookup.js.map +1 -0
  44. package/es/node.d.ts +42 -0
  45. package/es/node.d.ts.map +1 -0
  46. package/es/node.js +219 -0
  47. package/es/node.js.map +1 -0
  48. package/es/orderer.d.ts +30 -0
  49. package/es/orderer.d.ts.map +1 -0
  50. package/es/orderer.js +134 -0
  51. package/es/orderer.js.map +1 -0
  52. package/es/p2p-upstream.d.ts +47 -0
  53. package/es/p2p-upstream.d.ts.map +1 -0
  54. package/es/p2p-upstream.js +218 -0
  55. package/es/p2p-upstream.js.map +1 -0
  56. package/es/processor.d.ts +61 -0
  57. package/es/processor.d.ts.map +1 -0
  58. package/es/processor.js +640 -0
  59. package/es/processor.js.map +1 -0
  60. package/es/program.d.ts +3 -0
  61. package/es/program.d.ts.map +1 -0
  62. package/es/program.js +57 -0
  63. package/es/program.js.map +1 -0
  64. package/es/pruner.d.ts +47 -0
  65. package/es/pruner.d.ts.map +1 -0
  66. package/es/pruner.js +143 -0
  67. package/es/pruner.js.map +1 -0
  68. package/es/registry.d.ts +43 -0
  69. package/es/registry.d.ts.map +1 -0
  70. package/es/registry.js +49 -0
  71. package/es/registry.js.map +1 -0
  72. package/es/run.d.ts +36 -0
  73. package/es/run.d.ts.map +1 -0
  74. package/es/run.js +158 -0
  75. package/es/run.js.map +1 -0
  76. package/es/submit.d.ts +50 -0
  77. package/es/submit.d.ts.map +1 -0
  78. package/es/submit.js +186 -0
  79. package/es/submit.js.map +1 -0
  80. package/es/types.d.ts +67 -0
  81. package/es/types.d.ts.map +1 -0
  82. package/es/types.js +2 -0
  83. package/es/types.js.map +1 -0
  84. package/es/upstream.d.ts +36 -0
  85. package/es/upstream.d.ts.map +1 -0
  86. package/es/upstream.js +2 -0
  87. package/es/upstream.js.map +1 -0
  88. package/es/verify.d.ts +59 -0
  89. package/es/verify.d.ts.map +1 -0
  90. package/es/verify.js +203 -0
  91. package/es/verify.js.map +1 -0
  92. package/es/workspace.d.ts +4 -0
  93. package/es/workspace.d.ts.map +1 -0
  94. package/es/workspace.js +40 -0
  95. package/es/workspace.js.map +1 -0
  96. package/lib/api.d.ts +53 -0
  97. package/lib/api.d.ts.map +1 -0
  98. package/lib/api.js +402 -0
  99. package/lib/api.js.map +1 -0
  100. package/lib/bootstrap.d.ts +36 -0
  101. package/lib/bootstrap.d.ts.map +1 -0
  102. package/lib/bootstrap.js +116 -0
  103. package/lib/bootstrap.js.map +1 -0
  104. package/lib/commands.d.ts +25 -0
  105. package/lib/commands.d.ts.map +1 -0
  106. package/lib/commands.js +229 -0
  107. package/lib/commands.js.map +1 -0
  108. package/lib/config.d.ts +17 -0
  109. package/lib/config.d.ts.map +1 -0
  110. package/lib/config.js +437 -0
  111. package/lib/config.js.map +1 -0
  112. package/lib/contracts.d.ts +31 -0
  113. package/lib/contracts.d.ts.map +1 -0
  114. package/lib/contracts.js +210 -0
  115. package/lib/contracts.js.map +1 -0
  116. package/lib/divergence.d.ts +8 -0
  117. package/lib/divergence.d.ts.map +1 -0
  118. package/lib/divergence.js +46 -0
  119. package/lib/divergence.js.map +1 -0
  120. package/lib/events.d.ts +38 -0
  121. package/lib/events.d.ts.map +1 -0
  122. package/lib/events.js +152 -0
  123. package/lib/events.js.map +1 -0
  124. package/lib/feed.d.ts +42 -0
  125. package/lib/feed.d.ts.map +1 -0
  126. package/lib/feed.js +173 -0
  127. package/lib/feed.js.map +1 -0
  128. package/lib/http-upstream.d.ts +83 -0
  129. package/lib/http-upstream.d.ts.map +1 -0
  130. package/lib/http-upstream.js +401 -0
  131. package/lib/http-upstream.js.map +1 -0
  132. package/lib/index.js +210 -42
  133. package/lib/index.js.map +1 -1
  134. package/lib/lookup.d.ts +34 -0
  135. package/lib/lookup.d.ts.map +1 -0
  136. package/lib/lookup.js +201 -0
  137. package/lib/lookup.js.map +1 -0
  138. package/lib/node.d.ts +42 -0
  139. package/lib/node.d.ts.map +1 -0
  140. package/lib/node.js +257 -0
  141. package/lib/node.js.map +1 -0
  142. package/lib/orderer.d.ts +30 -0
  143. package/lib/orderer.d.ts.map +1 -0
  144. package/lib/orderer.js +138 -0
  145. package/lib/orderer.js.map +1 -0
  146. package/lib/p2p-upstream.d.ts +47 -0
  147. package/lib/p2p-upstream.d.ts.map +1 -0
  148. package/lib/p2p-upstream.js +222 -0
  149. package/lib/p2p-upstream.js.map +1 -0
  150. package/lib/processor.d.ts +61 -0
  151. package/lib/processor.d.ts.map +1 -0
  152. package/lib/processor.js +644 -0
  153. package/lib/processor.js.map +1 -0
  154. package/lib/program.d.ts +3 -0
  155. package/lib/program.d.ts.map +1 -0
  156. package/lib/program.js +61 -0
  157. package/lib/program.js.map +1 -0
  158. package/lib/pruner.d.ts +47 -0
  159. package/lib/pruner.d.ts.map +1 -0
  160. package/lib/pruner.js +147 -0
  161. package/lib/pruner.js.map +1 -0
  162. package/lib/registry.d.ts +43 -0
  163. package/lib/registry.d.ts.map +1 -0
  164. package/lib/registry.js +58 -0
  165. package/lib/registry.js.map +1 -0
  166. package/lib/run.d.ts +36 -0
  167. package/lib/run.d.ts.map +1 -0
  168. package/lib/run.js +206 -0
  169. package/lib/run.js.map +1 -0
  170. package/lib/submit.d.ts +50 -0
  171. package/lib/submit.d.ts.map +1 -0
  172. package/lib/submit.js +226 -0
  173. package/lib/submit.js.map +1 -0
  174. package/lib/types.d.ts +67 -0
  175. package/lib/types.d.ts.map +1 -0
  176. package/lib/{interfaces/hybrid.interface.js → types.js} +1 -1
  177. package/lib/types.js.map +1 -0
  178. package/lib/upstream.d.ts +36 -0
  179. package/lib/upstream.d.ts.map +1 -0
  180. package/lib/upstream.js +3 -0
  181. package/lib/upstream.js.map +1 -0
  182. package/lib/verify.d.ts +59 -0
  183. package/lib/verify.d.ts.map +1 -0
  184. package/lib/verify.js +218 -0
  185. package/lib/verify.js.map +1 -0
  186. package/lib/workspace.d.ts +4 -0
  187. package/lib/workspace.d.ts.map +1 -0
  188. package/lib/workspace.js +78 -0
  189. package/lib/workspace.js.map +1 -0
  190. package/package.json +14 -14
  191. package/es/contract.d.ts +0 -5
  192. package/es/contract.d.ts.map +0 -1
  193. package/es/contract.js +0 -33
  194. package/es/contract.js.map +0 -1
  195. package/es/contracts/default/contract.d.ts +0 -37
  196. package/es/contracts/default/contract.d.ts.map +0 -1
  197. package/es/contracts/default/contract.js +0 -848
  198. package/es/contracts/default/contract.js.map +0 -1
  199. package/es/contracts/default/fund.d.ts +0 -14
  200. package/es/contracts/default/fund.d.ts.map +0 -1
  201. package/es/contracts/default/fund.js +0 -90
  202. package/es/contracts/default/fund.js.map +0 -1
  203. package/es/contracts/default/namespace.d.ts +0 -10
  204. package/es/contracts/default/namespace.d.ts.map +0 -1
  205. package/es/contracts/default/namespace.js +0 -47
  206. package/es/contracts/default/namespace.js.map +0 -1
  207. package/es/contracts/default/onboard.d.ts +0 -7
  208. package/es/contracts/default/onboard.d.ts.map +0 -1
  209. package/es/contracts/default/onboard.js +0 -45
  210. package/es/contracts/default/onboard.js.map +0 -1
  211. package/es/contracts/default/setup.d.ts +0 -33
  212. package/es/contracts/default/setup.d.ts.map +0 -1
  213. package/es/contracts/default/setup.js +0 -413
  214. package/es/contracts/default/setup.js.map +0 -1
  215. package/es/default.config.json +0 -40
  216. package/es/interfaces/hybrid.interface.d.ts +0 -7
  217. package/es/interfaces/hybrid.interface.d.ts.map +0 -1
  218. package/es/interfaces/hybrid.interface.js +0 -2
  219. package/es/interfaces/hybrid.interface.js.map +0 -1
  220. package/es/server.d.ts +0 -23
  221. package/es/server.d.ts.map +0 -1
  222. package/es/server.js +0 -232
  223. package/es/server.js.map +0 -1
  224. package/lib/contract.d.ts +0 -5
  225. package/lib/contract.d.ts.map +0 -1
  226. package/lib/contract.js +0 -70
  227. package/lib/contract.js.map +0 -1
  228. package/lib/contracts/default/contract.d.ts +0 -37
  229. package/lib/contracts/default/contract.d.ts.map +0 -1
  230. package/lib/contracts/default/contract.js +0 -884
  231. package/lib/contracts/default/contract.js.map +0 -1
  232. package/lib/contracts/default/fund.d.ts +0 -14
  233. package/lib/contracts/default/fund.d.ts.map +0 -1
  234. package/lib/contracts/default/fund.js +0 -93
  235. package/lib/contracts/default/fund.js.map +0 -1
  236. package/lib/contracts/default/namespace.d.ts +0 -10
  237. package/lib/contracts/default/namespace.d.ts.map +0 -1
  238. package/lib/contracts/default/namespace.js +0 -83
  239. package/lib/contracts/default/namespace.js.map +0 -1
  240. package/lib/contracts/default/onboard.d.ts +0 -7
  241. package/lib/contracts/default/onboard.d.ts.map +0 -1
  242. package/lib/contracts/default/onboard.js +0 -48
  243. package/lib/contracts/default/onboard.js.map +0 -1
  244. package/lib/contracts/default/setup.d.ts +0 -33
  245. package/lib/contracts/default/setup.d.ts.map +0 -1
  246. package/lib/contracts/default/setup.js +0 -449
  247. package/lib/contracts/default/setup.js.map +0 -1
  248. package/lib/default.config.json +0 -40
  249. package/lib/interfaces/hybrid.interface.d.ts +0 -7
  250. package/lib/interfaces/hybrid.interface.d.ts.map +0 -1
  251. package/lib/interfaces/hybrid.interface.js.map +0 -1
  252. package/lib/server.d.ts +0 -23
  253. package/lib/server.d.ts.map +0 -1
  254. package/lib/server.js +0 -236
  255. package/lib/server.js.map +0 -1
@@ -1,884 +0,0 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- const fs = __importStar(require("fs"));
37
- const ts = __importStar(require("typescript-api"));
38
- const activecontracts_1 = require("@activeledger/activecontracts");
39
- const activeoptions_1 = require("@activeledger/activeoptions");
40
- const activecrypto_1 = require("@activeledger/activecrypto");
41
- const BANNED_IDENTIFIERS = [
42
- "process",
43
- "global",
44
- "globalThis",
45
- "eval",
46
- "Function",
47
- "AsyncFunction",
48
- "GeneratorFunction",
49
- "AsyncGeneratorFunction",
50
- "module",
51
- "exports",
52
- "__dirname",
53
- "__filename",
54
- "setTimeout",
55
- "setInterval",
56
- "setImmediate",
57
- "queueMicrotask",
58
- "atob",
59
- "btoa",
60
- "Reflect",
61
- "Proxy",
62
- "WebAssembly",
63
- "Symbol",
64
- "arguments",
65
- "caller",
66
- "callee",
67
- "console",
68
- "debugger",
69
- "fetch",
70
- "SharedArrayBuffer",
71
- "Atomics",
72
- "performance",
73
- "Performance",
74
- "Intl",
75
- "FinalizationRegistry",
76
- "WeakRef",
77
- "gc",
78
- "v8",
79
- "vm",
80
- "worker_threads",
81
- "cluster",
82
- "child_process",
83
- "os",
84
- "path",
85
- "fs",
86
- "http",
87
- "https",
88
- "net",
89
- "tls",
90
- "crypto",
91
- "root",
92
- "window",
93
- "top",
94
- "stop",
95
- "close",
96
- "InternalError",
97
- ];
98
- const PROTECTED_IDENTIFIERS = [
99
- "ActiveLogger",
100
- "ActiveRequest",
101
- "ActiveCrypto",
102
- "ActiveOptions",
103
- "ActiveDefinitions",
104
- "ActiveGZip",
105
- "Standard",
106
- "Activity",
107
- "ActivityStream",
108
- "EventEngine",
109
- "PostProcessQueryEvent",
110
- "Math",
111
- "Date",
112
- "JSON",
113
- "Array",
114
- "Object",
115
- "String",
116
- "Number",
117
- "Boolean",
118
- "Error",
119
- "Promise",
120
- "Buffer",
121
- "Map",
122
- "Set",
123
- "Uint8Array",
124
- "BigInt",
125
- "URL",
126
- "URLSearchParams",
127
- "TextEncoder",
128
- "TextDecoder",
129
- "self",
130
- ];
131
- const BANNED_PROPERTIES = [
132
- "exit",
133
- "kill",
134
- "spawn",
135
- "fork",
136
- "exec",
137
- "readFile",
138
- "writeFile",
139
- "unlink",
140
- "rmdir",
141
- "mkdir",
142
- "appendFile",
143
- "readdir",
144
- "stat",
145
- "lstat",
146
- "readFileSync",
147
- "writeFileSync",
148
- "unlinkSync",
149
- "rmdirSync",
150
- "rmSync",
151
- "mkdirSync",
152
- "appendFileSync",
153
- "readdirSync",
154
- "statSync",
155
- "lstatSync",
156
- "existsSync",
157
- "realpathSync",
158
- "copyFileSync",
159
- "renameSync",
160
- "cpSync",
161
- "chmodSync",
162
- "chownSync",
163
- "symlinkSync",
164
- "linkSync",
165
- "truncateSync",
166
- "opendirSync",
167
- "watchFile",
168
- "unwatchFile",
169
- "execSync",
170
- "execFileSync",
171
- "spawnSync",
172
- "setTimeout",
173
- "setInterval",
174
- "setImmediate",
175
- "queueMicrotask",
176
- "fetch",
177
- "atob",
178
- "btoa",
179
- "constructor",
180
- "__proto__",
181
- "prototype",
182
- "defineProperty",
183
- "defineProperties",
184
- "setPrototypeOf",
185
- "getPrototypeOf",
186
- "assign",
187
- "__defineGetter__",
188
- "__defineSetter__",
189
- "__lookupGetter__",
190
- "__lookupSetter__",
191
- "binding",
192
- "internalBinding",
193
- "allocUnsafe",
194
- "bind",
195
- "call",
196
- "apply",
197
- "getOwnPropertyDescriptor",
198
- "getOwnPropertyDescriptors",
199
- "getOwnPropertyNames",
200
- "getOwnPropertySymbols",
201
- "preventExtensions",
202
- "isExtensible",
203
- "seal",
204
- "isSealed",
205
- "freeze",
206
- "isFrozen",
207
- "toSource",
208
- "valueOf",
209
- "hasOwnProperty",
210
- "isPrototypeOf",
211
- "propertyIsEnumerable",
212
- "toLocaleString",
213
- "captureStackTrace",
214
- "stackTraceLimit",
215
- "stack",
216
- "fileName",
217
- "lineNumber",
218
- "columnNumber",
219
- "__count__",
220
- "__noSuchMethod__",
221
- "__parent__",
222
- "eval",
223
- "Function",
224
- "global",
225
- "globalThis",
226
- "process",
227
- "module",
228
- "require",
229
- ];
230
- const BANNED_PROPERTIES_SET = new Set(BANNED_PROPERTIES);
231
- class Contract extends activecontracts_1.Standard {
232
- name;
233
- namespace;
234
- contract;
235
- link;
236
- version = "";
237
- identity;
238
- rootDir = "./contracts/";
239
- verify(signatureless) {
240
- return new Promise((resolve, reject) => {
241
- let stream = Object.keys(this.transactions.$i)[0];
242
- this.identity = this.getActivityStreams(stream);
243
- if (!signatureless) {
244
- if (typeof this.transactions.$i[this.identity.getName()].version ==
245
- "string" ||
246
- (this.transactions.$entry &&
247
- this.transactions.$entry.indexOf("link") !== -1)) {
248
- resolve(true);
249
- }
250
- else {
251
- reject("No Version Found");
252
- }
253
- }
254
- else {
255
- reject("Signatures Needed");
256
- }
257
- });
258
- }
259
- vote() {
260
- return new Promise((resolve, reject) => {
261
- switch (this.transactions.$entry) {
262
- case "update":
263
- this.voteUpdate(resolve, reject);
264
- break;
265
- case "link":
266
- this.voteLink(resolve, reject);
267
- break;
268
- case "unlink":
269
- this.voteUnlink(resolve, reject);
270
- break;
271
- case "lock":
272
- this.voteLock(resolve, reject);
273
- break;
274
- case "unlock":
275
- this.voteUnlock(resolve, reject);
276
- break;
277
- default:
278
- this.voteAdd(resolve, reject);
279
- break;
280
- }
281
- });
282
- }
283
- commit() {
284
- return new Promise((resolve, reject) => {
285
- switch (this.transactions.$entry) {
286
- case "update":
287
- this.commitUpdate(resolve, reject);
288
- break;
289
- case "link":
290
- this.commitLink(resolve, reject);
291
- break;
292
- case "unlink":
293
- this.commitUnlink(resolve, reject);
294
- break;
295
- case "lock":
296
- this.commitLock(resolve, reject);
297
- break;
298
- case "unlock":
299
- this.commitUnlock(resolve, reject);
300
- break;
301
- default:
302
- this.commitAdd(resolve, reject);
303
- break;
304
- }
305
- });
306
- }
307
- static REFERENCE_BUILD = 40100;
308
- useContractReferences() {
309
- return (activeoptions_1.ActiveOptions.get("build", 0) >= Contract.REFERENCE_BUILD);
310
- }
311
- static ES2025_BUILD = 40200;
312
- contractTarget() {
313
- return activeoptions_1.ActiveOptions.get("build", 0) >= Contract.ES2025_BUILD
314
- ? "es2025"
315
- : "es2017";
316
- }
317
- compiledEntry(base64, streamName) {
318
- return activeoptions_1.ActiveOptions.get("build", 0) >= Contract.ES2025_BUILD
319
- ? Contract.hashContractSource(base64)
320
- : streamName;
321
- }
322
- static hashContractSource(base64) {
323
- return activecrypto_1.ActiveCrypto.Hash.getHash(Buffer.from(base64, "base64").toString(), "sha256");
324
- }
325
- normaliseLegacyVersions(state) {
326
- if (!state.contract)
327
- return;
328
- const versions = Object.keys(state.contract);
329
- for (let i = versions.length; i--;) {
330
- const entry = state.contract[versions[i]];
331
- if (typeof entry !== "string")
332
- continue;
333
- state.contract[versions[i]] = {
334
- hash: Contract.hashContractSource(entry),
335
- };
336
- }
337
- }
338
- transpile(target) {
339
- return ts.transpileModule(Buffer.from(this.transactions.$i[this.identity.getName()].contract, "base64").toString(), {
340
- compilerOptions: {
341
- alwaysStrict: true,
342
- strictNullChecks: true,
343
- noImplicitAny: true,
344
- removeComments: true,
345
- module: ts.ModuleKind.CommonJS,
346
- moduleResolution: ts.ModuleResolutionKind.Classic,
347
- target: target === "es2025"
348
- ? ts.ScriptTarget.ES2025
349
- : ts.ScriptTarget.ES2017,
350
- esModuleInterop: false,
351
- ignoreDeprecations: "6.0",
352
- },
353
- }).outputText;
354
- }
355
- securityScan(sourceCode, namespace) {
356
- const allowedModules = ["@activeledger/activetoolkits", "@activeledger/activecontracts"];
357
- const policy = {
358
- allowDynamicAccess: false,
359
- allowRequire: false,
360
- allowEval: false,
361
- allowComputedProperties: false,
362
- allowProcessNextTick: false,
363
- allowLocalLibs: false
364
- };
365
- const securityConfig = activeoptions_1.ActiveOptions.get("security", { namespace: {} });
366
- if (securityConfig && securityConfig.namespace && securityConfig.namespace[namespace]) {
367
- const nsConfig = securityConfig.namespace[namespace];
368
- if (nsConfig.std)
369
- allowedModules.push(...nsConfig.std);
370
- if (nsConfig.external)
371
- allowedModules.push(...nsConfig.external);
372
- if (nsConfig.policy)
373
- Object.assign(policy, nsConfig.policy);
374
- }
375
- const privilegedNamespaces = ["default"];
376
- if (privilegedNamespaces.indexOf(namespace) !== -1) {
377
- return;
378
- }
379
- const sourceFile = ts.createSourceFile("contract.ts", sourceCode, ts.ScriptTarget.Latest, true);
380
- const report = (node, message) => {
381
- const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart());
382
- throw new Error(`Security Violation [${line + 1}:${character + 1}]: ${message}`);
383
- };
384
- const isLocalLibSpecifier = (spec) => spec.startsWith("./") && !spec.split("/").includes("..");
385
- const isModuleAllowed = (spec) => allowedModules.indexOf(spec) !== -1 ||
386
- (policy.allowLocalLibs && isLocalLibSpecifier(spec));
387
- const resolveModuleSpecifierText = (expr) => ts.isStringLiteral(expr) || ts.isNoSubstitutionTemplateLiteral(expr)
388
- ? expr.text
389
- : null;
390
- const unwrap = (node) => {
391
- while (ts.isParenthesizedExpression(node) ||
392
- ts.isAsExpression(node) ||
393
- ts.isTypeAssertionExpression(node) ||
394
- ts.isNonNullExpression(node)) {
395
- node = node.expression;
396
- }
397
- return node;
398
- };
399
- const checkNode = (node) => {
400
- const isWriteAccess = (node) => {
401
- const parent = node.parent;
402
- if (!parent)
403
- return false;
404
- if (ts.isImportSpecifier(parent) || ts.isImportClause(parent) || ts.isNamespaceImport(parent) || ts.isImportDeclaration(parent))
405
- return false;
406
- if (ts.isBinaryExpression(parent) &&
407
- parent.operatorToken.kind >= ts.SyntaxKind.FirstAssignment &&
408
- parent.operatorToken.kind <= ts.SyntaxKind.LastAssignment &&
409
- parent.left === node)
410
- return true;
411
- if (ts.isPrefixUnaryExpression(parent) &&
412
- (parent.operator === ts.SyntaxKind.PlusPlusToken ||
413
- parent.operator === ts.SyntaxKind.MinusMinusToken))
414
- return true;
415
- if (ts.isPostfixUnaryExpression(parent))
416
- return true;
417
- if (ts.isVariableDeclaration(parent) && parent.name === node)
418
- return true;
419
- if (ts.isFunctionDeclaration(parent) && parent.name === node)
420
- return true;
421
- if (ts.isClassDeclaration(parent) && parent.name === node)
422
- return true;
423
- if (ts.isBindingElement(parent) && parent.name === node)
424
- return true;
425
- if ((ts.isForInStatement(parent) || ts.isForOfStatement(parent)) &&
426
- parent.initializer === node)
427
- return true;
428
- return false;
429
- };
430
- const isThisAccess = (expr) => {
431
- const unwrapped = unwrap(expr);
432
- if (unwrapped.kind === ts.SyntaxKind.ThisKeyword)
433
- return true;
434
- if (ts.isPropertyAccessExpression(unwrapped))
435
- return isThisAccess(unwrapped.expression);
436
- return false;
437
- };
438
- const chainTouchesBanned = (expr) => {
439
- let current = unwrap(expr);
440
- while (true) {
441
- if (ts.isPropertyAccessExpression(current)) {
442
- if (ts.isIdentifier(current.name) &&
443
- BANNED_PROPERTIES_SET.has(current.name.text)) {
444
- return true;
445
- }
446
- current = unwrap(current.expression);
447
- continue;
448
- }
449
- if (ts.isElementAccessExpression(current)) {
450
- const arg = current.argumentExpression;
451
- if ((ts.isStringLiteral(arg) ||
452
- ts.isNoSubstitutionTemplateLiteral(arg)) &&
453
- BANNED_PROPERTIES_SET.has(arg.text)) {
454
- return true;
455
- }
456
- current = unwrap(current.expression);
457
- continue;
458
- }
459
- return false;
460
- }
461
- };
462
- if (ts.isIdentifier(node)) {
463
- if (node.text === "require") {
464
- const parent = node.parent;
465
- if (!ts.isCallExpression(parent) || parent.expression !== node) {
466
- report(node, `Unauthorized use of 'require' identifier`);
467
- }
468
- }
469
- if (node.text === "process") {
470
- if (ts.isPropertyAccessExpression(node.parent) && node.parent.name.text === "nextTick" && policy.allowProcessNextTick) {
471
- }
472
- else {
473
- report(node, `Unauthorized use of 'process' global`);
474
- }
475
- return;
476
- }
477
- if (BANNED_IDENTIFIERS.indexOf(node.text) !== -1) {
478
- if (!(ts.isPropertyAccessExpression(node.parent) && node.parent.name === node)) {
479
- report(node, `Unauthorized identifier '${node.text}'`);
480
- }
481
- }
482
- if (PROTECTED_IDENTIFIERS.indexOf(node.text) !== -1 &&
483
- isWriteAccess(node)) {
484
- report(node, `Unauthorized modification of protected identifier '${node.text}'`);
485
- }
486
- }
487
- if (ts.isPropertyAccessExpression(node)) {
488
- if (ts.isIdentifier(node.name) &&
489
- BANNED_PROPERTIES_SET.has(node.name.text)) {
490
- if (node.expression.kind === ts.SyntaxKind.ThisKeyword) {
491
- }
492
- else {
493
- report(node.name, `Unauthorized property access '${node.name.text}'`);
494
- }
495
- }
496
- const unwrappedExpr = unwrap(node.expression);
497
- if (ts.isIdentifier(unwrappedExpr) &&
498
- PROTECTED_IDENTIFIERS.indexOf(unwrappedExpr.text) !== -1 &&
499
- isWriteAccess(node)) {
500
- report(node, `Unauthorized modification of protected object '${unwrappedExpr.text}'`);
501
- }
502
- }
503
- if (ts.isElementAccessExpression(node)) {
504
- let key = "";
505
- let dynamicAccess = false;
506
- const unwrappedExpr = unwrap(node.expression);
507
- if (ts.isStringLiteral(node.argumentExpression)) {
508
- key = node.argumentExpression.text;
509
- }
510
- else if (ts.isNoSubstitutionTemplateLiteral(node.argumentExpression)) {
511
- key = node.argumentExpression.text;
512
- }
513
- else if (ts.isTemplateExpression(node.argumentExpression) || ts.isIdentifier(node.argumentExpression)) {
514
- dynamicAccess = true;
515
- }
516
- else if (ts.isNumericLiteral(node.argumentExpression)) {
517
- }
518
- else {
519
- dynamicAccess = true;
520
- }
521
- if (!dynamicAccess && key && BANNED_PROPERTIES_SET.has(key)) {
522
- if (node.expression.kind !== ts.SyntaxKind.ThisKeyword) {
523
- report(node.argumentExpression, `Unauthorized element access '${key}'`);
524
- }
525
- }
526
- if (isThisAccess(node.expression) && !chainTouchesBanned(node.expression)) {
527
- }
528
- else {
529
- if (policy.allowDynamicAccess) {
530
- }
531
- else {
532
- if (dynamicAccess) {
533
- report(node, `Dynamic element access is forbidden`);
534
- }
535
- }
536
- }
537
- if (ts.isIdentifier(unwrappedExpr) &&
538
- PROTECTED_IDENTIFIERS.indexOf(unwrappedExpr.text) !== -1 &&
539
- isWriteAccess(node)) {
540
- report(node, `Unauthorized modification of protected object '${unwrappedExpr.text}'`);
541
- }
542
- }
543
- if (ts.isBindingElement(node) && ts.isIdentifier(node.name)) {
544
- let propertyName = "";
545
- if (!node.propertyName) {
546
- propertyName = node.name.text;
547
- }
548
- else if (ts.isIdentifier(node.propertyName)) {
549
- propertyName = node.propertyName.text;
550
- }
551
- else if (ts.isComputedPropertyName(node.propertyName) &&
552
- (ts.isStringLiteral(node.propertyName.expression) ||
553
- ts.isNoSubstitutionTemplateLiteral(node.propertyName.expression))) {
554
- propertyName = node.propertyName.expression.text;
555
- }
556
- if (propertyName && BANNED_PROPERTIES_SET.has(propertyName)) {
557
- report(node, `Unauthorized destructuring of property '${propertyName}'`);
558
- }
559
- }
560
- if (ts.isComputedPropertyName(node)) {
561
- if (!policy.allowComputedProperties && !ts.isStringLiteral(node.expression) && !ts.isNumericLiteral(node.expression)) {
562
- report(node, `Dynamic computed property names are forbidden`);
563
- }
564
- }
565
- if (ts.isWithStatement(node)) {
566
- report(node, `with statements are forbidden`);
567
- }
568
- if (ts.isDecorator(node)) {
569
- report(node, `Decorators are forbidden`);
570
- }
571
- if (ts.isTaggedTemplateExpression(node)) {
572
- report(node, `Tagged template expressions are forbidden`);
573
- }
574
- if (ts.isMetaProperty(node)) {
575
- report(node, `Meta properties are forbidden`);
576
- }
577
- if (ts.isPrivateIdentifier(node)) {
578
- report(node, `Private identifiers are forbidden`);
579
- }
580
- if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "require") {
581
- const arg = node.arguments[0];
582
- const spec = arg ? resolveModuleSpecifierText(arg) : null;
583
- if (spec === null) {
584
- report(node, `Dynamic require is forbidden`);
585
- }
586
- else if (!isModuleAllowed(spec)) {
587
- report(node, `Module '${spec}' is not on the allow-list`);
588
- }
589
- }
590
- if (ts.isImportDeclaration(node)) {
591
- const spec = resolveModuleSpecifierText(node.moduleSpecifier);
592
- if (spec === null) {
593
- report(node, `Dynamic import specifier is forbidden`);
594
- }
595
- else if (!isModuleAllowed(spec)) {
596
- report(node, `Import of module '${spec}' is forbidden`);
597
- }
598
- }
599
- if (ts.isImportEqualsDeclaration(node) && ts.isExternalModuleReference(node.moduleReference)) {
600
- const spec = resolveModuleSpecifierText(node.moduleReference.expression);
601
- if (spec === null) {
602
- report(node, `Dynamic import specifier is forbidden`);
603
- }
604
- else if (!isModuleAllowed(spec)) {
605
- report(node, `Module '${spec}' is not on the allow-list`);
606
- }
607
- }
608
- if (ts.isExportDeclaration(node) && node.moduleSpecifier) {
609
- const spec = resolveModuleSpecifierText(node.moduleSpecifier);
610
- if (spec === null) {
611
- report(node, `Dynamic re-export specifier is forbidden`);
612
- }
613
- else if (!isModuleAllowed(spec)) {
614
- report(node, `Re-export of module '${spec}' is forbidden`);
615
- }
616
- }
617
- if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword) {
618
- report(node, `Dynamic import() is forbidden`);
619
- }
620
- if (ts.isDebuggerStatement(node)) {
621
- report(node, `debugger statements are forbidden`);
622
- }
623
- if (ts.isDeleteExpression(node) && ts.isPropertyAccessExpression(node.expression)) {
624
- if (BANNED_PROPERTIES_SET.has(node.expression.name.text)) {
625
- report(node.expression.name, `Unauthorized deletion of property '${node.expression.name.text}'`);
626
- }
627
- }
628
- ts.forEachChild(node, checkNode);
629
- };
630
- checkNode(sourceFile);
631
- }
632
- voteLock(resolve, reject) {
633
- let stream = Object.keys(this.transactions.$i)[0];
634
- this.namespace = this.transactions.$i[stream].namespace.toLowerCase();
635
- this.contract = this.transactions.$i[stream].contract.toLowerCase();
636
- if (this.transactions.$i[stream].version) {
637
- this.version =
638
- "@" + this.transactions.$i[stream].version.toLowerCase();
639
- }
640
- try {
641
- this.assertDeployerAllowed();
642
- }
643
- catch (e) {
644
- return reject(e.message);
645
- }
646
- if (this.identity.getState().namespace == this.namespace) {
647
- if (fs.existsSync(this.rootDir + this.namespace + "/" + this.contract + ".js")) {
648
- if (!fs.existsSync(this.rootDir +
649
- this.namespace +
650
- "/_LOCK." +
651
- this.contract +
652
- this.version)) {
653
- return resolve(true);
654
- }
655
- else {
656
- return reject("Lock already exists");
657
- }
658
- }
659
- else {
660
- return reject("Contract not found in namespace");
661
- }
662
- }
663
- return reject("Invalid Namespace");
664
- }
665
- voteUnlock(resolve, reject) {
666
- let stream = Object.keys(this.transactions.$i)[0];
667
- this.namespace = this.transactions.$i[stream].namespace.toLowerCase();
668
- this.contract = this.transactions.$i[stream].contract.toLowerCase();
669
- if (this.transactions.$i[stream].version) {
670
- this.version =
671
- "@" + this.transactions.$i[stream].version.toLowerCase();
672
- }
673
- try {
674
- this.assertDeployerAllowed();
675
- }
676
- catch (e) {
677
- return reject(e.message);
678
- }
679
- if (this.identity.getState().namespace == this.namespace) {
680
- if (fs.existsSync(this.rootDir +
681
- this.namespace +
682
- "/_LOCK." +
683
- this.contract +
684
- this.version)) {
685
- return resolve(true);
686
- }
687
- else {
688
- return reject("Lock doesn't exists");
689
- }
690
- }
691
- return reject("Invalid Namespace");
692
- }
693
- commitLock(resolve, reject) {
694
- fs.closeSync(fs.openSync(this.rootDir +
695
- this.namespace +
696
- "/_LOCK." +
697
- this.contract +
698
- this.version, "w"));
699
- resolve(true);
700
- }
701
- commitUnlock(resolve, reject) {
702
- fs.unlinkSync(this.rootDir + this.namespace + "/_LOCK." + this.contract + this.version);
703
- resolve(true);
704
- }
705
- voteLink(resolve, reject) {
706
- let stream = Object.keys(this.transactions.$i)[0];
707
- this.namespace = this.transactions.$i[stream].namespace.toLowerCase();
708
- this.contract = this.transactions.$i[stream].contract.toLowerCase();
709
- this.link = this.transactions.$i[stream].link.toLowerCase();
710
- try {
711
- this.assertDeployerAllowed();
712
- }
713
- catch (e) {
714
- return reject(e.message);
715
- }
716
- if (this.identity.getState().namespace == this.namespace) {
717
- if (fs.existsSync(this.rootDir + this.namespace + "/" + this.contract + ".js")) {
718
- if (!fs.existsSync(this.rootDir + this.namespace + "/" + this.link + ".js")) {
719
- return resolve(true);
720
- }
721
- else {
722
- return reject("Link already exists");
723
- }
724
- }
725
- else {
726
- return reject("Contract not found in namespace");
727
- }
728
- }
729
- return reject("Invalid Namespace");
730
- }
731
- voteUnlink(resolve, reject) {
732
- let stream = Object.keys(this.transactions.$i)[0];
733
- this.namespace = this.transactions.$i[stream].namespace.toLowerCase();
734
- this.contract = this.transactions.$i[stream].contract.toLowerCase();
735
- this.link = this.transactions.$i[stream].link.toLowerCase();
736
- try {
737
- this.assertDeployerAllowed();
738
- }
739
- catch (e) {
740
- return reject(e.message);
741
- }
742
- if (this.identity.getState().namespace == this.namespace) {
743
- if (fs.existsSync(this.rootDir + this.namespace + "/" + this.link + ".js")) {
744
- return resolve(true);
745
- }
746
- else {
747
- return reject("Link doesn't exists");
748
- }
749
- }
750
- return reject("Invalid Namespace");
751
- }
752
- commitLink(resolve, reject) {
753
- fs.symlinkSync(`${this.contract}.js`, `${this.rootDir}${this.namespace}/${this.link}.js`, "file");
754
- resolve(true);
755
- }
756
- commitUnlink(resolve, reject) {
757
- fs.unlinkSync(`${this.rootDir}${this.namespace}/${this.link}.js`);
758
- resolve(true);
759
- }
760
- assertDeployerAllowed() {
761
- const deploy = (activeoptions_1.ActiveOptions.get("security", {}) || {}).deploy || {};
762
- const allowlist = deploy.allowlist;
763
- if (Array.isArray(allowlist) && allowlist.length > 0) {
764
- if (allowlist.indexOf(this.identity.getId()) === -1) {
765
- throw new Error("Deployer not permitted");
766
- }
767
- }
768
- }
769
- assertContractOwner() {
770
- const deploy = (activeoptions_1.ActiveOptions.get("security", {}) || {}).deploy || {};
771
- if (!deploy.enforceContractOwnership)
772
- return;
773
- const output = Object.keys(this.transactions.$o || {})[0];
774
- const target = output ? this.getActivityStreams(output) : undefined;
775
- const owner = target ? target.getAuthority() : undefined;
776
- if (!owner || owner !== this.identity.getId()) {
777
- throw new Error("Not contract owner");
778
- }
779
- }
780
- voteAdd(resolve, reject) {
781
- let stream = Object.keys(this.transactions.$i)[0];
782
- this.namespace = this.transactions.$i[stream].namespace.toLowerCase();
783
- this.name = this.transactions.$i[stream].name.toLowerCase();
784
- try {
785
- this.assertDeployerAllowed();
786
- }
787
- catch (e) {
788
- return reject(e.message);
789
- }
790
- if (this.identity.getState().namespace == this.namespace) {
791
- try {
792
- this.securityScan(Buffer.from(this.transactions.$i[this.identity.getName()].contract, "base64").toString(), this.namespace);
793
- resolve(true);
794
- }
795
- catch (e) {
796
- reject(e.message);
797
- }
798
- }
799
- else {
800
- return reject("Invalid Namespace");
801
- }
802
- }
803
- commitAdd(resolve, reject) {
804
- if (!fs.existsSync(this.rootDir + this.namespace))
805
- fs.mkdirSync(this.rootDir + this.namespace);
806
- let txi = this.transactions.$i[this.identity.getName()];
807
- const target = this.contractTarget();
808
- let code = this.transpile(target);
809
- let stream = this.newActivityStream(`contract.${this.namespace}.${this.name}@${txi.version}`);
810
- let state = stream.getState();
811
- stream.setAuthority(this.identity.getName());
812
- state.name = this.name;
813
- state.namespace = this.namespace;
814
- state.contract = {};
815
- state.contract[txi.version] = this.useContractReferences()
816
- ? {
817
- umid: this.umid,
818
- hash: Contract.hashContractSource(txi.contract),
819
- ...(target === "es2017" ? {} : { target }),
820
- }
821
- : txi.contract;
822
- if (this.useContractReferences()) {
823
- state.identity = this.identity.getName();
824
- }
825
- state.compiled = {};
826
- state.compiled[txi.version] = this.compiledEntry(txi.contract, stream.getName());
827
- fs.writeFileSync(`${this.rootDir}${this.namespace}/${stream.getName()}.js`, code);
828
- fs.writeFileSync(`${this.rootDir}${this.namespace}/${stream.getName()}@${txi.version}.js`, code);
829
- stream.setState(state);
830
- resolve(true);
831
- }
832
- voteUpdate(resolve, reject) {
833
- let stream = Object.keys(this.transactions.$i)[0];
834
- this.namespace = this.transactions.$i[stream].namespace.toLowerCase();
835
- this.name = this.transactions.$i[stream].name.toLowerCase();
836
- try {
837
- this.assertDeployerAllowed();
838
- }
839
- catch (e) {
840
- return reject(e.message);
841
- }
842
- if (this.identity.getState().namespace == this.namespace) {
843
- try {
844
- this.assertContractOwner();
845
- this.securityScan(Buffer.from(this.transactions.$i[this.identity.getName()].contract, "base64").toString(), this.namespace);
846
- resolve(true);
847
- }
848
- catch (e) {
849
- reject(e.message);
850
- }
851
- }
852
- else {
853
- return reject("Invalid Namespace");
854
- }
855
- }
856
- commitUpdate(resolve, reject) {
857
- let txi = this.transactions.$i[this.identity.getName()];
858
- let output = Object.keys(this.transactions.$o)[0];
859
- let stream = this.getActivityStreams(output);
860
- const target = this.contractTarget();
861
- let code = this.transpile(target);
862
- let state = stream.getState();
863
- if (this.useContractReferences()) {
864
- this.normaliseLegacyVersions(state);
865
- }
866
- state.contract[txi.version] = this.useContractReferences()
867
- ? {
868
- umid: this.umid,
869
- hash: Contract.hashContractSource(txi.contract),
870
- ...(target === "es2017" ? {} : { target }),
871
- }
872
- : txi.contract;
873
- if (this.useContractReferences()) {
874
- state.identity = this.identity.getName();
875
- }
876
- state.compiled[txi.version] = this.compiledEntry(txi.contract, stream.getName());
877
- fs.writeFileSync(`${this.rootDir}${this.namespace}/${stream.getName()}.js`, code);
878
- fs.writeFileSync(`${this.rootDir}${this.namespace}/${stream.getName()}@${txi.version}.js`, code);
879
- stream.setState(state);
880
- resolve(true);
881
- }
882
- }
883
- exports.default = Contract;
884
- //# sourceMappingURL=contract.js.map