@egret/contracts 0.0.0-stage → 7.0.2
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/LICENSE +201 -0
- package/NOTICE +21 -0
- package/README.md +22 -2
- package/README.zh-CN.md +23 -0
- package/dist/CancellationSignal.d.ts +12 -0
- package/dist/CancellationSignal.js +2 -0
- package/dist/Diagnostic.d.ts +11 -0
- package/dist/Diagnostic.js +2 -0
- package/dist/Disposable.d.ts +11 -0
- package/dist/Disposable.js +2 -0
- package/dist/HostAdapter.d.ts +17 -0
- package/dist/HostAdapter.js +2 -0
- package/dist/ImageData2D.d.ts +49 -0
- package/dist/ImageData2D.js +133 -0
- package/dist/Point2D.d.ts +6 -0
- package/dist/Point2D.js +2 -0
- package/dist/ProjectFormat.generated.d.ts +129 -0
- package/dist/ProjectFormat.generated.js +4 -0
- package/dist/RenderFrame2D.d.ts +22 -0
- package/dist/RenderFrame2D.js +2 -0
- package/dist/ResourceManifest.d.ts +75 -0
- package/dist/ResourceManifest.js +2 -0
- package/dist/SharedGeometry2D.d.ts +31 -0
- package/dist/SharedGeometry2D.js +177 -0
- package/dist/SharedMaterial2D.d.ts +46 -0
- package/dist/SharedMaterial2D.js +188 -0
- package/dist/SharedRenderFrame2D.d.ts +132 -0
- package/dist/SharedRenderFrame2D.js +5 -0
- package/dist/TextureViewRegion2D.d.ts +20 -0
- package/dist/TextureViewRegion2D.js +2 -0
- package/dist/TexturedGeometry2D.d.ts +30 -0
- package/dist/TexturedGeometry2D.js +167 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +6 -0
- package/dist/resources/fontArtifact.d.ts +7 -0
- package/dist/resources/fontArtifact.js +37 -0
- package/dist/resources/index.d.ts +4 -0
- package/dist/resources/index.js +4 -0
- package/dist/resources/manifestAdmission.d.ts +10 -0
- package/dist/resources/manifestAdmission.js +457 -0
- package/dist/resources/sha256.d.ts +3 -0
- package/dist/resources/sha256.js +111 -0
- package/package.json +25 -4
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
import { sha256Utf8, utf8ByteLength } from './sha256.js';
|
|
2
|
+
const MAX_BYTES = 4194304;
|
|
3
|
+
const admitted = new WeakMap();
|
|
4
|
+
class Refusal extends Error {
|
|
5
|
+
code;
|
|
6
|
+
pointer;
|
|
7
|
+
constructor(code, pointer) {
|
|
8
|
+
super(code);
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.pointer = pointer;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function fail(code, pointer) {
|
|
14
|
+
throw new Refusal(code, pointer);
|
|
15
|
+
}
|
|
16
|
+
const escape = (text) => text.replaceAll('~', '~0').replaceAll('/', '~1');
|
|
17
|
+
function success(value) {
|
|
18
|
+
return Object.freeze({ ok: true, value, diagnostics: Object.freeze([]) });
|
|
19
|
+
}
|
|
20
|
+
function rejection(error) {
|
|
21
|
+
const known = error instanceof Refusal
|
|
22
|
+
? error
|
|
23
|
+
: new Refusal(error instanceof RangeError ? 'RESOURCE_LIMIT_EXCEEDED' : 'RESOURCE_INPUT_INVALID', '');
|
|
24
|
+
const diagnostic = Object.freeze({
|
|
25
|
+
code: known.code,
|
|
26
|
+
pointer: known.pointer,
|
|
27
|
+
message: known.code.replaceAll('_', ' ') + '.'
|
|
28
|
+
});
|
|
29
|
+
return Object.freeze({ ok: false, diagnostics: Object.freeze([diagnostic]) });
|
|
30
|
+
}
|
|
31
|
+
// A complete descriptor-only copy precedes semantic work. Accessors never run,
|
|
32
|
+
// aliases are copied, and only the active ancestor chain is a JSON cycle.
|
|
33
|
+
function capture(input) {
|
|
34
|
+
let bytes = 0;
|
|
35
|
+
const ancestors = new Set();
|
|
36
|
+
const charge = (amount, pointer) => {
|
|
37
|
+
bytes += amount;
|
|
38
|
+
if (bytes > MAX_BYTES)
|
|
39
|
+
fail('RESOURCE_LIMIT_EXCEEDED', pointer);
|
|
40
|
+
};
|
|
41
|
+
function copy(value, pointer, depth) {
|
|
42
|
+
if (depth > 32)
|
|
43
|
+
fail('RESOURCE_LIMIT_EXCEEDED', pointer);
|
|
44
|
+
if (value === null || typeof value === 'boolean' || typeof value === 'string' || typeof value === 'number') {
|
|
45
|
+
if (typeof value === 'number' && !Number.isFinite(value))
|
|
46
|
+
fail('RESOURCE_INPUT_INVALID', pointer);
|
|
47
|
+
if (typeof value === 'string') {
|
|
48
|
+
if (value.length > MAX_BYTES)
|
|
49
|
+
fail('RESOURCE_LIMIT_EXCEEDED', pointer);
|
|
50
|
+
utf8ByteLength(value);
|
|
51
|
+
}
|
|
52
|
+
charge(utf8ByteLength(JSON.stringify(value)), pointer);
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
if (typeof value !== 'object' || ancestors.has(value))
|
|
56
|
+
fail('RESOURCE_INPUT_INVALID', pointer);
|
|
57
|
+
const array = Array.isArray(value), prototype = Object.getPrototypeOf(value);
|
|
58
|
+
if (array ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null)
|
|
59
|
+
fail('RESOURCE_INPUT_INVALID', pointer);
|
|
60
|
+
const keys = Reflect.ownKeys(value);
|
|
61
|
+
let length = 0;
|
|
62
|
+
if (array) {
|
|
63
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, 'length');
|
|
64
|
+
if (!descriptor || !('value' in descriptor) || !Number.isSafeInteger(descriptor.value) || descriptor.value < 0)
|
|
65
|
+
fail('RESOURCE_INPUT_INVALID', pointer);
|
|
66
|
+
length = descriptor.value;
|
|
67
|
+
if (keys.length !== length + 1)
|
|
68
|
+
fail('RESOURCE_INPUT_INVALID', pointer);
|
|
69
|
+
}
|
|
70
|
+
const out = array
|
|
71
|
+
? []
|
|
72
|
+
: Object.create(null);
|
|
73
|
+
charge(2, pointer);
|
|
74
|
+
ancestors.add(value);
|
|
75
|
+
let index = 0;
|
|
76
|
+
for (const key of keys) {
|
|
77
|
+
if (array && key === 'length')
|
|
78
|
+
continue;
|
|
79
|
+
if (typeof key !== 'string' || (array && key !== String(index)))
|
|
80
|
+
fail('RESOURCE_INPUT_INVALID', pointer);
|
|
81
|
+
// Refuse raw oversized keys before diagnostic escaping can expand them.
|
|
82
|
+
if (key.length > MAX_BYTES)
|
|
83
|
+
fail('RESOURCE_LIMIT_EXCEEDED', pointer);
|
|
84
|
+
const child = pointer + '/' + escape(key), descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
85
|
+
if (!descriptor || !descriptor.enumerable || !('value' in descriptor))
|
|
86
|
+
fail('RESOURCE_INPUT_INVALID', child);
|
|
87
|
+
if (index++)
|
|
88
|
+
charge(1, pointer);
|
|
89
|
+
if (!array) {
|
|
90
|
+
utf8ByteLength(key);
|
|
91
|
+
charge(utf8ByteLength(JSON.stringify(key)) + 1, child);
|
|
92
|
+
}
|
|
93
|
+
const copied = copy(descriptor.value, child, depth + 1);
|
|
94
|
+
if (Array.isArray(out))
|
|
95
|
+
out.push(copied);
|
|
96
|
+
else
|
|
97
|
+
out[key] = copied;
|
|
98
|
+
}
|
|
99
|
+
ancestors.delete(value);
|
|
100
|
+
return Object.freeze(out);
|
|
101
|
+
}
|
|
102
|
+
return copy(input, '', 1);
|
|
103
|
+
}
|
|
104
|
+
// JSON.stringify cannot serialize sorted integer-looking object keys. Emit each
|
|
105
|
+
// key explicitly after UTF-16 code-unit sorting; never normalize authored Unicode.
|
|
106
|
+
function canonical(value) {
|
|
107
|
+
if (value === null || typeof value === 'string' || typeof value === 'boolean' || typeof value === 'number')
|
|
108
|
+
return JSON.stringify(value);
|
|
109
|
+
if (Array.isArray(value))
|
|
110
|
+
return '[' + value.map(canonical).join(',') + ']';
|
|
111
|
+
const record = value;
|
|
112
|
+
return ('{' +
|
|
113
|
+
Object.keys(record)
|
|
114
|
+
.sort()
|
|
115
|
+
.map(key => JSON.stringify(key) + ':' + canonical(record[key]))
|
|
116
|
+
.join(',') +
|
|
117
|
+
'}');
|
|
118
|
+
}
|
|
119
|
+
function record(value, pointer) {
|
|
120
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
121
|
+
fail('RESOURCE_INPUT_INVALID', pointer);
|
|
122
|
+
return value;
|
|
123
|
+
}
|
|
124
|
+
function exact(value, keys, pointer) {
|
|
125
|
+
const result = record(value, pointer), actual = Object.keys(result);
|
|
126
|
+
if (actual.length !== keys.length || actual.some(key => !keys.includes(key)))
|
|
127
|
+
fail('RESOURCE_INPUT_INVALID', pointer);
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
function text(value, pointer, maximum = 128) {
|
|
131
|
+
if (typeof value !== 'string' ||
|
|
132
|
+
value.length === 0 ||
|
|
133
|
+
utf8ByteLength(value) > maximum ||
|
|
134
|
+
/[\u0000-\u001f\u007f]/u.test(value))
|
|
135
|
+
fail('RESOURCE_INPUT_INVALID', pointer);
|
|
136
|
+
return value;
|
|
137
|
+
}
|
|
138
|
+
function identity(value, prefix, pointer) {
|
|
139
|
+
const result = text(value, pointer);
|
|
140
|
+
if (!new RegExp('^' + prefix + '_[A-Za-z0-9][A-Za-z0-9_-]*$', 'u').test(result))
|
|
141
|
+
fail('RESOURCE_INPUT_INVALID', pointer);
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
function array(value, pointer) {
|
|
145
|
+
if (!Array.isArray(value))
|
|
146
|
+
fail('RESOURCE_INPUT_INVALID', pointer);
|
|
147
|
+
return value;
|
|
148
|
+
}
|
|
149
|
+
function digest(value, pointer) {
|
|
150
|
+
if (typeof value !== 'string' || !/^[0-9a-f]{64}$/u.test(value))
|
|
151
|
+
fail('RESOURCE_INPUT_INVALID', pointer);
|
|
152
|
+
return value;
|
|
153
|
+
}
|
|
154
|
+
function portablePath(value, pointer) {
|
|
155
|
+
const result = text(value, pointer, 1024);
|
|
156
|
+
if (/[\\\u0000-\u001f\u007f:*?"<>|%#]/u.test(result) ||
|
|
157
|
+
result
|
|
158
|
+
.split('/')
|
|
159
|
+
.some(part => !part ||
|
|
160
|
+
part === '.' ||
|
|
161
|
+
part === '..' ||
|
|
162
|
+
/[ .]$/u.test(part) ||
|
|
163
|
+
/^(?:CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(?:\.|$)/iu.test(part)))
|
|
164
|
+
fail('RESOURCE_PATH_INVALID', pointer);
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
function file(value, role, pointer) {
|
|
168
|
+
const item = exact(value, ['id', 'path', 'role', 'mediaType', 'sha256', 'byteLength'], pointer);
|
|
169
|
+
identity(item.id, 'f', pointer + '/id');
|
|
170
|
+
portablePath(item.path, pointer + '/path');
|
|
171
|
+
if (item.role !== role)
|
|
172
|
+
fail('RESOURCE_FILE_MISMATCH', pointer + '/role');
|
|
173
|
+
const mediaType = text(item.mediaType, pointer + '/mediaType');
|
|
174
|
+
if (/[^\u0021-\u007e]/u.test(mediaType))
|
|
175
|
+
fail('RESOURCE_INPUT_INVALID', pointer + '/mediaType');
|
|
176
|
+
digest(item.sha256, pointer + '/sha256');
|
|
177
|
+
if (typeof item.byteLength !== 'number' ||
|
|
178
|
+
!Number.isSafeInteger(item.byteLength) ||
|
|
179
|
+
item.byteLength < 0 ||
|
|
180
|
+
Object.is(item.byteLength, -0))
|
|
181
|
+
fail('RESOURCE_INPUT_INVALID', pointer + '/byteLength');
|
|
182
|
+
return item;
|
|
183
|
+
}
|
|
184
|
+
function prepare(input, claimed, sourceOnly = false) {
|
|
185
|
+
const raw = exact(capture(input), ['format', 'projectId', 'targetProfile', 'versions', 'entries'], '');
|
|
186
|
+
if (raw.format !==
|
|
187
|
+
(sourceOnly ? 'egret.resource-build-plan/1' : claimed ? 'egret.resource-manifest/1' : 'egret.resource-build/1'))
|
|
188
|
+
fail('RESOURCE_FORMAT_UNSUPPORTED', '/format');
|
|
189
|
+
const projectId = identity(raw.projectId, 'p', '/projectId'), targetProfile = text(raw.targetProfile, '/targetProfile');
|
|
190
|
+
const versionData = exact(raw.versions, ['engineVersion', 'resourceFormatVersion', 'toolProtocolVersion'], '/versions');
|
|
191
|
+
text(versionData.engineVersion, '/versions/engineVersion');
|
|
192
|
+
text(versionData.resourceFormatVersion, '/versions/resourceFormatVersion');
|
|
193
|
+
if (versionData.toolProtocolVersion !== '1.0')
|
|
194
|
+
fail('RESOURCE_FORMAT_UNSUPPORTED', '/versions/toolProtocolVersion');
|
|
195
|
+
const versions = versionData, entries = array(raw.entries, '/entries');
|
|
196
|
+
if (entries.length > 4096)
|
|
197
|
+
fail('RESOURCE_LIMIT_EXCEEDED', '/entries');
|
|
198
|
+
const selected = new Map();
|
|
199
|
+
const fileRecords = new Map(), pathOwners = new Map();
|
|
200
|
+
let edges = 0;
|
|
201
|
+
const baseKeys = [
|
|
202
|
+
'id',
|
|
203
|
+
'resourceKind',
|
|
204
|
+
'source',
|
|
205
|
+
'artifact',
|
|
206
|
+
'importer',
|
|
207
|
+
'settings',
|
|
208
|
+
'artifactFormatVersion',
|
|
209
|
+
'targetProfile',
|
|
210
|
+
'dependencies',
|
|
211
|
+
'provenance'
|
|
212
|
+
];
|
|
213
|
+
for (let index = 0; index < entries.length; index++) {
|
|
214
|
+
const pointer = '/entries/' + index, item = exact(entries[index], sourceOnly
|
|
215
|
+
? baseKeys.filter(key => key !== 'artifact')
|
|
216
|
+
: claimed
|
|
217
|
+
? [...baseKeys, 'buildKey', 'runtimeIdentity']
|
|
218
|
+
: baseKeys, pointer);
|
|
219
|
+
const id = identity(item.id, 'e', pointer + '/id');
|
|
220
|
+
if (selected.has(id))
|
|
221
|
+
fail('RESOURCE_ID_DUPLICATE', pointer + '/id');
|
|
222
|
+
text(item.resourceKind, pointer + '/resourceKind');
|
|
223
|
+
text(item.artifactFormatVersion, pointer + '/artifactFormatVersion');
|
|
224
|
+
if (text(item.targetProfile, pointer + '/targetProfile') !== targetProfile)
|
|
225
|
+
fail('RESOURCE_DEPENDENCY_INVALID', pointer + '/targetProfile');
|
|
226
|
+
const importer = exact(item.importer, ['id', 'version'], pointer + '/importer');
|
|
227
|
+
text(importer.id, pointer + '/importer/id');
|
|
228
|
+
text(importer.version, pointer + '/importer/version');
|
|
229
|
+
const settings = record(item.settings, pointer + '/settings');
|
|
230
|
+
record(item.provenance, pointer + '/provenance');
|
|
231
|
+
if (utf8ByteLength(canonical(settings)) > 65536)
|
|
232
|
+
fail('RESOURCE_LIMIT_EXCEEDED', pointer + '/settings');
|
|
233
|
+
const dependencies = array(item.dependencies, pointer + '/dependencies'), seen = new Set();
|
|
234
|
+
edges += dependencies.length;
|
|
235
|
+
if (edges > 8192)
|
|
236
|
+
fail('RESOURCE_LIMIT_EXCEEDED', pointer + '/dependencies');
|
|
237
|
+
for (let dependency = 0; dependency < dependencies.length; dependency++) {
|
|
238
|
+
const name = identity(dependencies[dependency], 'e', pointer + '/dependencies/' + dependency);
|
|
239
|
+
if (seen.has(name))
|
|
240
|
+
fail('RESOURCE_DEPENDENCY_INVALID', pointer + '/dependencies/' + dependency);
|
|
241
|
+
seen.add(name);
|
|
242
|
+
}
|
|
243
|
+
const files = sourceOnly
|
|
244
|
+
? [['source', 'source']]
|
|
245
|
+
: [
|
|
246
|
+
['source', 'source'],
|
|
247
|
+
['artifact', 'asset']
|
|
248
|
+
];
|
|
249
|
+
for (const [name, role] of files) {
|
|
250
|
+
const current = file(item[name], role, pointer + '/' + name), encoded = canonical(current), old = fileRecords.get(current.id);
|
|
251
|
+
if (old !== undefined && old !== encoded)
|
|
252
|
+
fail('RESOURCE_FILE_MISMATCH', pointer + '/' + name);
|
|
253
|
+
fileRecords.set(current.id, encoded);
|
|
254
|
+
const pathKey = current.path.normalize('NFC').toLowerCase(), owner = pathOwners.get(pathKey);
|
|
255
|
+
if (owner !== undefined && owner !== current.id)
|
|
256
|
+
fail('RESOURCE_FILE_MISMATCH', pointer + '/' + name + '/path');
|
|
257
|
+
pathOwners.set(pathKey, current.id);
|
|
258
|
+
}
|
|
259
|
+
if (claimed) {
|
|
260
|
+
digest(item.buildKey, pointer + '/buildKey');
|
|
261
|
+
digest(item.runtimeIdentity, pointer + '/runtimeIdentity');
|
|
262
|
+
}
|
|
263
|
+
const entry = Object.freeze({
|
|
264
|
+
id: item.id,
|
|
265
|
+
resourceKind: item.resourceKind,
|
|
266
|
+
source: item.source,
|
|
267
|
+
...(sourceOnly ? {} : { artifact: item.artifact }),
|
|
268
|
+
importer: item.importer,
|
|
269
|
+
settings: item.settings,
|
|
270
|
+
artifactFormatVersion: item.artifactFormatVersion,
|
|
271
|
+
targetProfile: item.targetProfile,
|
|
272
|
+
dependencies: item.dependencies,
|
|
273
|
+
provenance: item.provenance
|
|
274
|
+
});
|
|
275
|
+
selected.set(id, claimed ? { entry, pointer, claimed: item } : { entry, pointer });
|
|
276
|
+
}
|
|
277
|
+
for (const { entry, pointer } of selected.values())
|
|
278
|
+
for (const dependency of entry.dependencies)
|
|
279
|
+
if (!selected.has(dependency))
|
|
280
|
+
fail('RESOURCE_DEPENDENCY_INVALID', pointer + '/dependencies');
|
|
281
|
+
const heights = new Map(), active = new Set(), order = [];
|
|
282
|
+
function visit(id, depth) {
|
|
283
|
+
const node = selected.get(id);
|
|
284
|
+
if (depth > 32)
|
|
285
|
+
fail('RESOURCE_LIMIT_EXCEEDED', node.pointer + '/dependencies');
|
|
286
|
+
const prior = heights.get(id);
|
|
287
|
+
if (prior !== undefined)
|
|
288
|
+
return prior;
|
|
289
|
+
if (active.has(id))
|
|
290
|
+
fail('RESOURCE_DEPENDENCY_INVALID', node.pointer + '/dependencies');
|
|
291
|
+
active.add(id);
|
|
292
|
+
let height = 1;
|
|
293
|
+
for (const dependency of node.entry.dependencies)
|
|
294
|
+
height = Math.max(height, 1 + visit(dependency, depth + 1));
|
|
295
|
+
// A memoized shallow visit must not hide a deeper incoming path in a DAG.
|
|
296
|
+
if (height > 32)
|
|
297
|
+
fail('RESOURCE_LIMIT_EXCEEDED', node.pointer + '/dependencies');
|
|
298
|
+
heights.set(id, height);
|
|
299
|
+
active.delete(id);
|
|
300
|
+
order.push(id);
|
|
301
|
+
return height;
|
|
302
|
+
}
|
|
303
|
+
const ids = [...selected.keys()].sort();
|
|
304
|
+
for (const id of ids)
|
|
305
|
+
visit(id, 1);
|
|
306
|
+
return { projectId, targetProfile, versions, selected, ids, order };
|
|
307
|
+
}
|
|
308
|
+
// The pre-artifact and final-manifest paths share this exact projection and hash.
|
|
309
|
+
// File binding and artifact identity remain outside the intrinsic build key.
|
|
310
|
+
function buildIdentity(entry, targetProfile, versions, completed) {
|
|
311
|
+
const dependencies = entry.dependencies.map(dependency => ({
|
|
312
|
+
id: dependency,
|
|
313
|
+
buildKey: completed.get(dependency).buildKey
|
|
314
|
+
}));
|
|
315
|
+
const build = canonical({
|
|
316
|
+
format: 'egret.resource-build-key/1',
|
|
317
|
+
resourceKind: entry.resourceKind,
|
|
318
|
+
importer: entry.importer,
|
|
319
|
+
settings: entry.settings,
|
|
320
|
+
artifactFormatVersion: entry.artifactFormatVersion,
|
|
321
|
+
targetProfile,
|
|
322
|
+
versions,
|
|
323
|
+
source: { sha256: entry.source.sha256, byteLength: entry.source.byteLength },
|
|
324
|
+
dependencies,
|
|
325
|
+
provenance: entry.provenance
|
|
326
|
+
});
|
|
327
|
+
return { build, buildKey: sha256Utf8(build) };
|
|
328
|
+
}
|
|
329
|
+
function evaluate(input, claimed) {
|
|
330
|
+
const { projectId, targetProfile, versions, selected, ids, order } = prepare(input, claimed);
|
|
331
|
+
const completed = new Map(), inputs = new Map();
|
|
332
|
+
for (const id of order) {
|
|
333
|
+
const node = selected.get(id), entry = node.entry;
|
|
334
|
+
const { build, buildKey } = buildIdentity(entry, targetProfile, versions, completed);
|
|
335
|
+
const runtime = canonical({
|
|
336
|
+
format: 'egret.resource-identity/1',
|
|
337
|
+
projectId,
|
|
338
|
+
id,
|
|
339
|
+
buildKey,
|
|
340
|
+
artifact: {
|
|
341
|
+
sha256: entry.artifact.sha256,
|
|
342
|
+
byteLength: entry.artifact.byteLength,
|
|
343
|
+
mediaType: entry.artifact.mediaType
|
|
344
|
+
},
|
|
345
|
+
artifactFormatVersion: entry.artifactFormatVersion,
|
|
346
|
+
targetProfile
|
|
347
|
+
});
|
|
348
|
+
const runtimeIdentity = sha256Utf8(runtime);
|
|
349
|
+
if (node.claimed && (node.claimed.buildKey !== buildKey || node.claimed.runtimeIdentity !== runtimeIdentity))
|
|
350
|
+
fail('RESOURCE_KEY_MISMATCH', node.pointer);
|
|
351
|
+
completed.set(id, Object.freeze({ ...entry, buildKey, runtimeIdentity }));
|
|
352
|
+
inputs.set(id, Object.freeze({ build, runtime }));
|
|
353
|
+
}
|
|
354
|
+
const manifest = Object.freeze({
|
|
355
|
+
format: 'egret.resource-manifest/1',
|
|
356
|
+
projectId,
|
|
357
|
+
targetProfile,
|
|
358
|
+
versions,
|
|
359
|
+
entries: Object.freeze(ids.map(id => completed.get(id)))
|
|
360
|
+
});
|
|
361
|
+
const encoded = canonical(manifest);
|
|
362
|
+
if (utf8ByteLength(encoded) > MAX_BYTES)
|
|
363
|
+
fail('RESOURCE_LIMIT_EXCEEDED', '');
|
|
364
|
+
admitted.set(manifest, Object.freeze({ text: encoded, inputs }));
|
|
365
|
+
return manifest;
|
|
366
|
+
}
|
|
367
|
+
// Plans validate source metadata only; they confer no final manifest admission.
|
|
368
|
+
export function validateResourceBuildPlanDescription(input) {
|
|
369
|
+
try {
|
|
370
|
+
const { projectId, targetProfile, versions, selected, ids } = prepare(input, false, true);
|
|
371
|
+
const result = Object.freeze({
|
|
372
|
+
format: 'egret.resource-build-plan/1',
|
|
373
|
+
projectId,
|
|
374
|
+
targetProfile,
|
|
375
|
+
versions,
|
|
376
|
+
entries: Object.freeze(ids.map(id => selected.get(id).entry))
|
|
377
|
+
});
|
|
378
|
+
return success(result);
|
|
379
|
+
}
|
|
380
|
+
catch (error) {
|
|
381
|
+
return rejection(error);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
export function evaluateResourceBuildKeys(description) {
|
|
385
|
+
try {
|
|
386
|
+
const { projectId, targetProfile, versions, selected, ids, order } = prepare(description, false, true);
|
|
387
|
+
const completed = new Map();
|
|
388
|
+
for (const id of order) {
|
|
389
|
+
const entry = selected.get(id).entry, { buildKey } = buildIdentity(entry, targetProfile, versions, completed);
|
|
390
|
+
completed.set(id, Object.freeze({ ...entry, buildKey }));
|
|
391
|
+
}
|
|
392
|
+
const result = Object.freeze({
|
|
393
|
+
format: 'egret.resource-build-keys/1',
|
|
394
|
+
projectId,
|
|
395
|
+
targetProfile,
|
|
396
|
+
versions,
|
|
397
|
+
entries: Object.freeze(ids.map(id => completed.get(id)))
|
|
398
|
+
});
|
|
399
|
+
if (utf8ByteLength(canonical(result)) > MAX_BYTES)
|
|
400
|
+
fail('RESOURCE_LIMIT_EXCEEDED', '');
|
|
401
|
+
return success(result);
|
|
402
|
+
}
|
|
403
|
+
catch (error) {
|
|
404
|
+
return rejection(error);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
// Description admission shares every schema/graph rule while deliberately doing
|
|
408
|
+
// no hashing. Project tools can describe declared metadata without a build claim.
|
|
409
|
+
export function validateResourceBuildDescription(input) {
|
|
410
|
+
try {
|
|
411
|
+
const { projectId, targetProfile, versions, selected, ids } = prepare(input, false);
|
|
412
|
+
const result = Object.freeze({
|
|
413
|
+
format: 'egret.resource-build/1',
|
|
414
|
+
projectId,
|
|
415
|
+
targetProfile,
|
|
416
|
+
versions,
|
|
417
|
+
entries: Object.freeze(ids.map(id => selected.get(id).entry))
|
|
418
|
+
});
|
|
419
|
+
return success(result);
|
|
420
|
+
}
|
|
421
|
+
catch (error) {
|
|
422
|
+
return rejection(error);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
export function buildResourceManifest(description) {
|
|
426
|
+
try {
|
|
427
|
+
return success(evaluate(description, false));
|
|
428
|
+
}
|
|
429
|
+
catch (error) {
|
|
430
|
+
return rejection(error);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
export function admitResourceManifest(value) {
|
|
434
|
+
try {
|
|
435
|
+
return success(evaluate(value, true));
|
|
436
|
+
}
|
|
437
|
+
catch (error) {
|
|
438
|
+
return rejection(error);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
export function isAdmittedResourceManifest(value) {
|
|
442
|
+
return value !== null && typeof value === 'object' && admitted.has(value);
|
|
443
|
+
}
|
|
444
|
+
export function serializeResourceManifest(manifest) {
|
|
445
|
+
if (!isAdmittedResourceManifest(manifest))
|
|
446
|
+
return rejection(new Refusal('RESOURCE_INPUT_INVALID', ''));
|
|
447
|
+
return success(admitted.get(manifest).text);
|
|
448
|
+
}
|
|
449
|
+
export function getResourceManifestIdentityInputs(manifest, id) {
|
|
450
|
+
if (!isAdmittedResourceManifest(manifest))
|
|
451
|
+
throw new TypeError('A genuine admitted manifest is required.');
|
|
452
|
+
const result = admitted.get(manifest).inputs.get(id);
|
|
453
|
+
if (result === undefined)
|
|
454
|
+
throw new RangeError('Resource ID is absent from this manifest.');
|
|
455
|
+
return result;
|
|
456
|
+
}
|
|
457
|
+
//# sourceMappingURL=manifestAdmission.js.map
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// The standard SHA-256 constants are mathematical parameters, not imported code.
|
|
3
|
+
const K = [
|
|
4
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98,
|
|
5
|
+
0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
|
|
6
|
+
0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8,
|
|
7
|
+
0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
|
8
|
+
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819,
|
|
9
|
+
0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
|
|
10
|
+
0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
|
11
|
+
];
|
|
12
|
+
const rotate = (value, amount) => (value >>> amount) | (value << (32 - amount));
|
|
13
|
+
// Shared admission counts the exact encoding without requiring a host encoder.
|
|
14
|
+
export function utf8ByteLength(text) {
|
|
15
|
+
if (typeof text !== 'string')
|
|
16
|
+
throw new TypeError('UTF-8 input must be text.');
|
|
17
|
+
let length = 0;
|
|
18
|
+
for (let index = 0; index < text.length; index++) {
|
|
19
|
+
const unit = text.charCodeAt(index);
|
|
20
|
+
if (unit < 0x80)
|
|
21
|
+
length++;
|
|
22
|
+
else if (unit < 0x800)
|
|
23
|
+
length += 2;
|
|
24
|
+
else if (unit >= 0xd800 && unit <= 0xdbff) {
|
|
25
|
+
const low = text.charCodeAt(++index);
|
|
26
|
+
if (!(low >= 0xdc00 && low <= 0xdfff))
|
|
27
|
+
throw new TypeError('Unpaired UTF-16 surrogate.');
|
|
28
|
+
length += 4;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
if (unit >= 0xdc00 && unit <= 0xdfff)
|
|
32
|
+
throw new TypeError('Unpaired UTF-16 surrogate.');
|
|
33
|
+
length += 3;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return length;
|
|
37
|
+
}
|
|
38
|
+
export function sha256Utf8(text) {
|
|
39
|
+
if (typeof text !== 'string')
|
|
40
|
+
throw new TypeError('UTF-8 input must be text.');
|
|
41
|
+
if (text.length > 4194304)
|
|
42
|
+
throw new RangeError('Hash input exceeds four MiB.');
|
|
43
|
+
const length = utf8ByteLength(text);
|
|
44
|
+
if (length > 4194304)
|
|
45
|
+
throw new RangeError('Hash input exceeds four MiB.');
|
|
46
|
+
const bytes = new Uint8Array(Math.ceil((length + 9) / 64) * 64);
|
|
47
|
+
let offset = 0;
|
|
48
|
+
for (let index = 0; index < text.length; index++) {
|
|
49
|
+
let point = text.charCodeAt(index);
|
|
50
|
+
if (point >= 0xd800 && point <= 0xdbff)
|
|
51
|
+
point = 0x10000 + ((point - 0xd800) << 10) + text.charCodeAt(++index) - 0xdc00;
|
|
52
|
+
if (point < 0x80)
|
|
53
|
+
bytes[offset++] = point;
|
|
54
|
+
else if (point < 0x800) {
|
|
55
|
+
bytes[offset++] = 0xc0 | (point >>> 6);
|
|
56
|
+
bytes[offset++] = 0x80 | (point & 63);
|
|
57
|
+
}
|
|
58
|
+
else if (point < 0x10000) {
|
|
59
|
+
bytes[offset++] = 0xe0 | (point >>> 12);
|
|
60
|
+
bytes[offset++] = 0x80 | ((point >>> 6) & 63);
|
|
61
|
+
bytes[offset++] = 0x80 | (point & 63);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
bytes[offset++] = 0xf0 | (point >>> 18);
|
|
65
|
+
bytes[offset++] = 0x80 | ((point >>> 12) & 63);
|
|
66
|
+
bytes[offset++] = 0x80 | ((point >>> 6) & 63);
|
|
67
|
+
bytes[offset++] = 0x80 | (point & 63);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
bytes[length] = 0x80;
|
|
71
|
+
const bits = length * 8;
|
|
72
|
+
for (let index = 0; index < 8; index++)
|
|
73
|
+
bytes[bytes.length - 1 - index] = Math.floor(bits / 2 ** (index * 8)) & 255;
|
|
74
|
+
const state = new Uint32Array([
|
|
75
|
+
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
|
76
|
+
]);
|
|
77
|
+
const schedule = new Uint32Array(64);
|
|
78
|
+
for (let block = 0; block < bytes.length; block += 64) {
|
|
79
|
+
for (let index = 0; index < 16; index++) {
|
|
80
|
+
const start = block + index * 4;
|
|
81
|
+
schedule[index] =
|
|
82
|
+
(bytes[start] << 24) | (bytes[start + 1] << 16) | (bytes[start + 2] << 8) | bytes[start + 3];
|
|
83
|
+
}
|
|
84
|
+
for (let index = 16; index < 64; index++) {
|
|
85
|
+
const first = schedule[index - 15], second = schedule[index - 2];
|
|
86
|
+
const s0 = rotate(first, 7) ^ rotate(first, 18) ^ (first >>> 3);
|
|
87
|
+
const s1 = rotate(second, 17) ^ rotate(second, 19) ^ (second >>> 10);
|
|
88
|
+
schedule[index] = (schedule[index - 16] + s0 + schedule[index - 7] + s1) >>> 0;
|
|
89
|
+
}
|
|
90
|
+
let a = state[0], b = state[1], c = state[2], d = state[3], e = state[4], f = state[5], g = state[6], h = state[7];
|
|
91
|
+
for (let index = 0; index < 64; index++) {
|
|
92
|
+
const s1 = rotate(e, 6) ^ rotate(e, 11) ^ rotate(e, 25), choose = (e & f) ^ (~e & g);
|
|
93
|
+
const t1 = (h + s1 + choose + K[index] + schedule[index]) >>> 0;
|
|
94
|
+
const s0 = rotate(a, 2) ^ rotate(a, 13) ^ rotate(a, 22), majority = (a & b) ^ (a & c) ^ (b & c);
|
|
95
|
+
const t2 = (s0 + majority) >>> 0;
|
|
96
|
+
h = g;
|
|
97
|
+
g = f;
|
|
98
|
+
f = e;
|
|
99
|
+
e = (d + t1) >>> 0;
|
|
100
|
+
d = c;
|
|
101
|
+
c = b;
|
|
102
|
+
b = a;
|
|
103
|
+
a = (t1 + t2) >>> 0;
|
|
104
|
+
}
|
|
105
|
+
const next = [a, b, c, d, e, f, g, h];
|
|
106
|
+
for (let index = 0; index < 8; index++)
|
|
107
|
+
state[index] = (state[index] + next[index]) >>> 0;
|
|
108
|
+
}
|
|
109
|
+
return Array.from(state, word => word.toString(16).padStart(8, '0')).join('');
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=sha256.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@egret/contracts",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "7.0.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"import": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"./resources": {
|
|
11
|
+
"types": "./dist/resources/index.d.ts",
|
|
12
|
+
"import": "./dist/resources/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"license": "Apache-2.0",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md",
|
|
19
|
+
"README.zh-CN.md",
|
|
20
|
+
"LICENSE",
|
|
21
|
+
"NOTICE"
|
|
22
|
+
],
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/cnedwin/Egret_rebuild.git"
|
|
26
|
+
}
|
|
27
|
+
}
|