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