@calimero-network/mero-js 33.2.0 → 33.3.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 +1 -1
- package/dist/client/approvals.d.ts +102 -2
- package/dist/client/approvals.js +21 -0
- package/dist/client/calimero-client.d.ts +36 -1
- package/dist/client/calimero-client.js +124 -3
- package/dist/client/files.d.ts +30 -0
- package/dist/client/files.js +128 -0
- package/dist/client/index.d.ts +4 -2
- package/dist/client/index.js +2 -1
- package/dist/index.browser.mjs +4 -4
- package/dist/index.browser.mjs.map +4 -4
- package/dist/index.cjs +752 -20
- package/dist/index.cjs.map +4 -4
- package/dist/index.mjs +754 -20
- package/dist/index.mjs.map +4 -4
- package/dist/sealed/file.d.ts +46 -0
- package/dist/sealed/file.js +131 -0
- package/dist/sealed/fixtures/sealed-file-multi-segment-vectors.d.ts +41 -0
- package/dist/sealed/fixtures/sealed-file-multi-segment-vectors.js +63 -0
- package/dist/sealed/fixtures/sealed-file-vectors.d.ts +60 -0
- package/dist/sealed/fixtures/sealed-file-vectors.js +87 -0
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -4,6 +4,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
8
|
var __export = (target, all) => {
|
|
8
9
|
for (var name in all)
|
|
9
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -25,6 +26,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
26
|
mod
|
|
26
27
|
));
|
|
27
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
28
30
|
|
|
29
31
|
// src/index.ts
|
|
30
32
|
var index_exports = {};
|
|
@@ -35,6 +37,7 @@ __export(index_exports, {
|
|
|
35
37
|
AppError: () => AppError,
|
|
36
38
|
ArgsTooLarge: () => ArgsTooLarge,
|
|
37
39
|
BadOrigin: () => BadOrigin,
|
|
40
|
+
CONSENT_STORAGE_KEY: () => CONSENT_STORAGE_KEY,
|
|
38
41
|
CalimeroClient: () => CalimeroClient,
|
|
39
42
|
CalimeroError: () => CalimeroError,
|
|
40
43
|
ClusterNotUpgraded: () => ClusterNotUpgraded,
|
|
@@ -48,6 +51,7 @@ __export(index_exports, {
|
|
|
48
51
|
DEFAULT_RELEASE_MIRROR: () => DEFAULT_RELEASE_MIRROR,
|
|
49
52
|
DEFAULT_RETRY: () => DEFAULT_RETRY,
|
|
50
53
|
DirectoryError: () => DirectoryError,
|
|
54
|
+
ExportError: () => ExportError,
|
|
51
55
|
FILE_PART_BYTES: () => FILE_PART_BYTES,
|
|
52
56
|
FeatureNotActive: () => FeatureNotActive,
|
|
53
57
|
GITHUB_RELEASES: () => GITHUB_RELEASES,
|
|
@@ -86,6 +90,7 @@ __export(index_exports, {
|
|
|
86
90
|
UnavailableError: () => UnavailableError,
|
|
87
91
|
WrongNode: () => WrongNode,
|
|
88
92
|
WrongRecoveryCode: () => WrongRecoveryCode,
|
|
93
|
+
acceptInviteConsent: () => acceptInviteConsent,
|
|
89
94
|
agentKeyBinding: () => agentKeyBinding,
|
|
90
95
|
agentQuoteVerifier: () => agentQuoteVerifier,
|
|
91
96
|
attestAgent: () => attestAgent,
|
|
@@ -98,6 +103,8 @@ __export(index_exports, {
|
|
|
98
103
|
compareVersions: () => compareVersions,
|
|
99
104
|
confirmationCode: () => confirmationCode,
|
|
100
105
|
consentReturn: () => consentReturn,
|
|
106
|
+
createInviteConsent: () => createInviteConsent,
|
|
107
|
+
createOrgConsent: () => createOrgConsent,
|
|
101
108
|
createQuoteVerifier: () => createQuoteVerifier,
|
|
102
109
|
createRouteClient: () => createRouteClient,
|
|
103
110
|
createRoutes: () => createRoutes,
|
|
@@ -156,7 +163,8 @@ __export(index_exports, {
|
|
|
156
163
|
verifyReleaseUrl: () => verifyReleaseUrl,
|
|
157
164
|
verifySignedAgentPolicy: () => verifySignedAgentPolicy,
|
|
158
165
|
verifySignedNodeRelease: () => verifySignedNodeRelease,
|
|
159
|
-
withdrawConsent: () => withdrawConsent
|
|
166
|
+
withdrawConsent: () => withdrawConsent,
|
|
167
|
+
withoutConsentReturn: () => withoutConsentReturn
|
|
160
168
|
});
|
|
161
169
|
module.exports = __toCommonJS(index_exports);
|
|
162
170
|
|
|
@@ -165,15 +173,26 @@ function hex(bytes) {
|
|
|
165
173
|
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
166
174
|
}
|
|
167
175
|
function fromHex(value, label, expectedBytes) {
|
|
168
|
-
const
|
|
169
|
-
if (!/^[0-9a-fA-F]*$/.test(
|
|
176
|
+
const clean2 = value.trim();
|
|
177
|
+
if (!/^[0-9a-fA-F]*$/.test(clean2) || clean2.length !== expectedBytes * 2) {
|
|
170
178
|
throw new Error(
|
|
171
|
-
`${label} must be ${expectedBytes * 2} hex characters, got ${
|
|
179
|
+
`${label} must be ${expectedBytes * 2} hex characters, got ${clean2.length}`
|
|
172
180
|
);
|
|
173
181
|
}
|
|
174
182
|
const bytes = new Uint8Array(expectedBytes);
|
|
175
183
|
for (let i = 0; i < expectedBytes; i += 1) {
|
|
176
|
-
bytes[i] = Number.parseInt(
|
|
184
|
+
bytes[i] = Number.parseInt(clean2.slice(i * 2, i * 2 + 2), 16);
|
|
185
|
+
}
|
|
186
|
+
return bytes;
|
|
187
|
+
}
|
|
188
|
+
function fromHexUnsized(value, label) {
|
|
189
|
+
const clean2 = value.trim();
|
|
190
|
+
if (!/^[0-9a-fA-F]*$/.test(clean2) || clean2.length % 2 !== 0) {
|
|
191
|
+
throw new Error(`${label} must be an even number of hex characters`);
|
|
192
|
+
}
|
|
193
|
+
const bytes = new Uint8Array(clean2.length / 2);
|
|
194
|
+
for (let i = 0; i < bytes.length; i += 1) {
|
|
195
|
+
bytes[i] = Number.parseInt(clean2.slice(i * 2, i * 2 + 2), 16);
|
|
177
196
|
}
|
|
178
197
|
return bytes;
|
|
179
198
|
}
|
|
@@ -836,11 +855,11 @@ async function verifyEcdsa(spki, curve, hash, signature, data) {
|
|
|
836
855
|
return crypto.subtle.verify({ name: "ECDSA", hash }, key, p1363, data);
|
|
837
856
|
}
|
|
838
857
|
function fromBase64(value, what) {
|
|
839
|
-
const
|
|
840
|
-
if (!/^[A-Za-z0-9+/]*={0,2}$/.test(
|
|
858
|
+
const clean2 = value.replace(/\s+/g, "");
|
|
859
|
+
if (!/^[A-Za-z0-9+/]*={0,2}$/.test(clean2) || clean2.length % 4 !== 0) {
|
|
841
860
|
throw new Error(`${what} is not base64`);
|
|
842
861
|
}
|
|
843
|
-
const binary = atob(
|
|
862
|
+
const binary = atob(clean2);
|
|
844
863
|
const bytes = new Uint8Array(binary.length);
|
|
845
864
|
for (let i = 0; i < binary.length; i += 1) bytes[i] = binary.charCodeAt(i);
|
|
846
865
|
return bytes;
|
|
@@ -4247,6 +4266,600 @@ function refusalOf(response, error) {
|
|
|
4247
4266
|
return errorFrom(response.status, body, response.headers.get("retry-after"));
|
|
4248
4267
|
}
|
|
4249
4268
|
|
|
4269
|
+
// node_modules/.pnpm/@noble+hashes@2.4.0/node_modules/@noble/hashes/_u64.js
|
|
4270
|
+
var fromNumH = (n) => n / 2 ** 32 | 0;
|
|
4271
|
+
var fromNumL = (n) => n >>> 0;
|
|
4272
|
+
function setU64FromNum(view, byteOffset, n, isLE) {
|
|
4273
|
+
const h = fromNumH(n);
|
|
4274
|
+
const l = fromNumL(n);
|
|
4275
|
+
view.setUint32(byteOffset, isLE ? l : h, isLE);
|
|
4276
|
+
view.setUint32(byteOffset + 4, isLE ? h : l, isLE);
|
|
4277
|
+
}
|
|
4278
|
+
|
|
4279
|
+
// node_modules/.pnpm/@noble+hashes@2.4.0/node_modules/@noble/hashes/utils.js
|
|
4280
|
+
function isBytes(a) {
|
|
4281
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
|
|
4282
|
+
}
|
|
4283
|
+
var atitle = (title) => title ? `"${title}" ` : "";
|
|
4284
|
+
function anumber(n, title = "") {
|
|
4285
|
+
if (typeof n !== "number")
|
|
4286
|
+
throw new TypeError(atitle(title) + "expected number, got " + typeof n);
|
|
4287
|
+
if (!Number.isSafeInteger(n) || n < 0)
|
|
4288
|
+
throw new RangeError(atitle(title) + "expected integer >= 0, got " + n);
|
|
4289
|
+
return n;
|
|
4290
|
+
}
|
|
4291
|
+
function abytes(value, length, title = "") {
|
|
4292
|
+
if (isBytes(value) && (length === void 0 || value.length === length))
|
|
4293
|
+
return value;
|
|
4294
|
+
if (length !== void 0)
|
|
4295
|
+
anumber(length, "length");
|
|
4296
|
+
const bytes = isBytes(value);
|
|
4297
|
+
const ofLen = length !== void 0 ? ` of length ${length}` : "";
|
|
4298
|
+
const got = bytes ? `length=${value.length}` : `type=${typeof value}`;
|
|
4299
|
+
const message = atitle(title) + "expected Uint8Array" + ofLen + ", got " + got;
|
|
4300
|
+
if (!bytes)
|
|
4301
|
+
throw new TypeError(message);
|
|
4302
|
+
throw new RangeError(message);
|
|
4303
|
+
}
|
|
4304
|
+
var aobject = (value, label) => {
|
|
4305
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
4306
|
+
throw new TypeError((label === "object" ? "" : `"${label}" `) + "expected object, got type=" + typeof value);
|
|
4307
|
+
};
|
|
4308
|
+
var aopts = (value, label) => {
|
|
4309
|
+
aobject(value, label);
|
|
4310
|
+
const proto = Object.getPrototypeOf(value);
|
|
4311
|
+
if (proto !== Object.prototype && proto !== null)
|
|
4312
|
+
throw new TypeError(`"${label}" expected plain object`);
|
|
4313
|
+
if (Object.hasOwn(value, "__proto__"))
|
|
4314
|
+
throw new TypeError(`"${label}.__proto__" is not allowed`);
|
|
4315
|
+
};
|
|
4316
|
+
function aexists(instance, checkFinished = true) {
|
|
4317
|
+
if (instance.destroyed)
|
|
4318
|
+
throw new Error("hash was destroyed");
|
|
4319
|
+
if (checkFinished && instance.finished)
|
|
4320
|
+
throw new Error("digest() was already called");
|
|
4321
|
+
}
|
|
4322
|
+
function aoutput(out, instance) {
|
|
4323
|
+
abytes(out, void 0, "output");
|
|
4324
|
+
const min = instance.outputLen;
|
|
4325
|
+
if (!(out.length >= min)) {
|
|
4326
|
+
throw new RangeError('"output" expected length >= ' + min);
|
|
4327
|
+
}
|
|
4328
|
+
}
|
|
4329
|
+
function clean(...arrays) {
|
|
4330
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
4331
|
+
arrays[i].fill(0);
|
|
4332
|
+
}
|
|
4333
|
+
}
|
|
4334
|
+
function createView(arr) {
|
|
4335
|
+
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
4336
|
+
}
|
|
4337
|
+
function rotr(word, shift) {
|
|
4338
|
+
return word << 32 - shift | word >>> shift;
|
|
4339
|
+
}
|
|
4340
|
+
function checkOpts(defaults, opts, title = "opts") {
|
|
4341
|
+
aopts(defaults, "defaults");
|
|
4342
|
+
if (opts !== void 0)
|
|
4343
|
+
aopts(opts, title);
|
|
4344
|
+
const merged = Object.assign(/* @__PURE__ */ Object.create(null), defaults, opts);
|
|
4345
|
+
return merged;
|
|
4346
|
+
}
|
|
4347
|
+
function createHasher(hashCons, info = {}) {
|
|
4348
|
+
if (typeof hashCons !== "function")
|
|
4349
|
+
throw new TypeError('"hashCons" expected function, got type=' + typeof hashCons);
|
|
4350
|
+
info = checkOpts({}, info, "info");
|
|
4351
|
+
const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
|
|
4352
|
+
const tmp = hashCons(void 0);
|
|
4353
|
+
hashC.outputLen = tmp.outputLen;
|
|
4354
|
+
hashC.blockLen = tmp.blockLen;
|
|
4355
|
+
hashC.canXOF = tmp.canXOF;
|
|
4356
|
+
hashC.create = (opts) => hashCons(opts);
|
|
4357
|
+
Object.assign(hashC, info);
|
|
4358
|
+
return Object.freeze(hashC);
|
|
4359
|
+
}
|
|
4360
|
+
var oidNist = (suffix) => ({
|
|
4361
|
+
// Current NIST hashAlgs suffixes used here fit in one DER subidentifier octet.
|
|
4362
|
+
// Larger suffix values would need base-128 OID encoding and a different length byte.
|
|
4363
|
+
oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, suffix])
|
|
4364
|
+
});
|
|
4365
|
+
|
|
4366
|
+
// node_modules/.pnpm/@noble+hashes@2.4.0/node_modules/@noble/hashes/_md.js
|
|
4367
|
+
function Chi(a, b, c) {
|
|
4368
|
+
return a & b ^ ~a & c;
|
|
4369
|
+
}
|
|
4370
|
+
function Maj(a, b, c) {
|
|
4371
|
+
return a & b ^ a & c ^ b & c;
|
|
4372
|
+
}
|
|
4373
|
+
var HashMD = class {
|
|
4374
|
+
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
4375
|
+
__publicField(this, "blockLen");
|
|
4376
|
+
__publicField(this, "outputLen");
|
|
4377
|
+
__publicField(this, "canXOF", false);
|
|
4378
|
+
__publicField(this, "padOffset");
|
|
4379
|
+
__publicField(this, "isLE");
|
|
4380
|
+
// For partial updates less than block size
|
|
4381
|
+
__publicField(this, "buffer");
|
|
4382
|
+
__publicField(this, "view");
|
|
4383
|
+
__publicField(this, "finished", false);
|
|
4384
|
+
__publicField(this, "length", 0);
|
|
4385
|
+
__publicField(this, "pos", 0);
|
|
4386
|
+
__publicField(this, "destroyed", false);
|
|
4387
|
+
this.blockLen = blockLen;
|
|
4388
|
+
this.outputLen = outputLen;
|
|
4389
|
+
this.padOffset = padOffset;
|
|
4390
|
+
this.isLE = isLE;
|
|
4391
|
+
this.buffer = new Uint8Array(blockLen);
|
|
4392
|
+
this.view = createView(this.buffer);
|
|
4393
|
+
}
|
|
4394
|
+
update(data) {
|
|
4395
|
+
aexists(this);
|
|
4396
|
+
abytes(data);
|
|
4397
|
+
const { view, buffer, blockLen } = this;
|
|
4398
|
+
const len = data.length;
|
|
4399
|
+
let processed = false;
|
|
4400
|
+
for (let pos = 0; pos < len; ) {
|
|
4401
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
4402
|
+
if (take === blockLen) {
|
|
4403
|
+
const dataView = createView(data);
|
|
4404
|
+
for (; blockLen <= len - pos; pos += blockLen)
|
|
4405
|
+
this.process(dataView, pos);
|
|
4406
|
+
processed = true;
|
|
4407
|
+
continue;
|
|
4408
|
+
}
|
|
4409
|
+
buffer.set(pos === 0 && take === len ? data : data.subarray(pos, pos + take), this.pos);
|
|
4410
|
+
this.pos += take;
|
|
4411
|
+
pos += take;
|
|
4412
|
+
if (this.pos === blockLen) {
|
|
4413
|
+
this.process(view, 0);
|
|
4414
|
+
this.pos = 0;
|
|
4415
|
+
processed = true;
|
|
4416
|
+
}
|
|
4417
|
+
}
|
|
4418
|
+
this.length += data.length;
|
|
4419
|
+
if (processed)
|
|
4420
|
+
this.roundClean();
|
|
4421
|
+
return this;
|
|
4422
|
+
}
|
|
4423
|
+
digestInto(out) {
|
|
4424
|
+
aexists(this);
|
|
4425
|
+
aoutput(out, this);
|
|
4426
|
+
this.finished = true;
|
|
4427
|
+
const { buffer, view, blockLen, isLE } = this;
|
|
4428
|
+
let { pos } = this;
|
|
4429
|
+
buffer[pos++] = 128;
|
|
4430
|
+
buffer.fill(0, pos);
|
|
4431
|
+
if (this.padOffset > blockLen - pos) {
|
|
4432
|
+
this.process(view, 0);
|
|
4433
|
+
buffer.fill(0);
|
|
4434
|
+
}
|
|
4435
|
+
setU64FromNum(view, blockLen - 8, this.length * 8, isLE);
|
|
4436
|
+
this.process(view, 0);
|
|
4437
|
+
this.roundClean();
|
|
4438
|
+
const oview = out === buffer ? view : createView(out);
|
|
4439
|
+
const len = this.outputLen;
|
|
4440
|
+
const outLen = len / 4;
|
|
4441
|
+
const state = this.get();
|
|
4442
|
+
if (len % 4 || outLen > state.length)
|
|
4443
|
+
throw new Error("invalid outputLen");
|
|
4444
|
+
for (let i = 0; i < outLen; i++)
|
|
4445
|
+
oview.setUint32(4 * i, state[i], isLE);
|
|
4446
|
+
}
|
|
4447
|
+
digest() {
|
|
4448
|
+
const { buffer, outputLen } = this;
|
|
4449
|
+
this.digestInto(buffer);
|
|
4450
|
+
const res = buffer.slice(0, outputLen);
|
|
4451
|
+
this.destroy();
|
|
4452
|
+
return res;
|
|
4453
|
+
}
|
|
4454
|
+
_cloneIntoMeta(to) {
|
|
4455
|
+
const { buffer, length, finished, destroyed, pos } = this;
|
|
4456
|
+
to.destroyed = destroyed;
|
|
4457
|
+
to.finished = finished;
|
|
4458
|
+
to.length = length;
|
|
4459
|
+
to.pos = pos;
|
|
4460
|
+
if (pos)
|
|
4461
|
+
to.buffer.set(buffer);
|
|
4462
|
+
return to;
|
|
4463
|
+
}
|
|
4464
|
+
clone() {
|
|
4465
|
+
return this._cloneInto();
|
|
4466
|
+
}
|
|
4467
|
+
};
|
|
4468
|
+
var SHA256_IV = /* @__PURE__ */ Uint32Array.from([
|
|
4469
|
+
1779033703,
|
|
4470
|
+
3144134277,
|
|
4471
|
+
1013904242,
|
|
4472
|
+
2773480762,
|
|
4473
|
+
1359893119,
|
|
4474
|
+
2600822924,
|
|
4475
|
+
528734635,
|
|
4476
|
+
1541459225
|
|
4477
|
+
]);
|
|
4478
|
+
|
|
4479
|
+
// node_modules/.pnpm/@noble+hashes@2.4.0/node_modules/@noble/hashes/sha2.js
|
|
4480
|
+
var SHA256_K = /* @__PURE__ */ Uint32Array.from([
|
|
4481
|
+
1116352408,
|
|
4482
|
+
1899447441,
|
|
4483
|
+
3049323471,
|
|
4484
|
+
3921009573,
|
|
4485
|
+
961987163,
|
|
4486
|
+
1508970993,
|
|
4487
|
+
2453635748,
|
|
4488
|
+
2870763221,
|
|
4489
|
+
3624381080,
|
|
4490
|
+
310598401,
|
|
4491
|
+
607225278,
|
|
4492
|
+
1426881987,
|
|
4493
|
+
1925078388,
|
|
4494
|
+
2162078206,
|
|
4495
|
+
2614888103,
|
|
4496
|
+
3248222580,
|
|
4497
|
+
3835390401,
|
|
4498
|
+
4022224774,
|
|
4499
|
+
264347078,
|
|
4500
|
+
604807628,
|
|
4501
|
+
770255983,
|
|
4502
|
+
1249150122,
|
|
4503
|
+
1555081692,
|
|
4504
|
+
1996064986,
|
|
4505
|
+
2554220882,
|
|
4506
|
+
2821834349,
|
|
4507
|
+
2952996808,
|
|
4508
|
+
3210313671,
|
|
4509
|
+
3336571891,
|
|
4510
|
+
3584528711,
|
|
4511
|
+
113926993,
|
|
4512
|
+
338241895,
|
|
4513
|
+
666307205,
|
|
4514
|
+
773529912,
|
|
4515
|
+
1294757372,
|
|
4516
|
+
1396182291,
|
|
4517
|
+
1695183700,
|
|
4518
|
+
1986661051,
|
|
4519
|
+
2177026350,
|
|
4520
|
+
2456956037,
|
|
4521
|
+
2730485921,
|
|
4522
|
+
2820302411,
|
|
4523
|
+
3259730800,
|
|
4524
|
+
3345764771,
|
|
4525
|
+
3516065817,
|
|
4526
|
+
3600352804,
|
|
4527
|
+
4094571909,
|
|
4528
|
+
275423344,
|
|
4529
|
+
430227734,
|
|
4530
|
+
506948616,
|
|
4531
|
+
659060556,
|
|
4532
|
+
883997877,
|
|
4533
|
+
958139571,
|
|
4534
|
+
1322822218,
|
|
4535
|
+
1537002063,
|
|
4536
|
+
1747873779,
|
|
4537
|
+
1955562222,
|
|
4538
|
+
2024104815,
|
|
4539
|
+
2227730452,
|
|
4540
|
+
2361852424,
|
|
4541
|
+
2428436474,
|
|
4542
|
+
2756734187,
|
|
4543
|
+
3204031479,
|
|
4544
|
+
3329325298
|
|
4545
|
+
]);
|
|
4546
|
+
var SHA256_W = /* @__PURE__ */ new Uint32Array(64);
|
|
4547
|
+
var SHA2_32B = class extends HashMD {
|
|
4548
|
+
constructor(outputLen, IV) {
|
|
4549
|
+
super(64, outputLen, 8, false);
|
|
4550
|
+
// We cannot use array here since array allows indexing by variable
|
|
4551
|
+
// which means optimizer/compiler cannot use registers.
|
|
4552
|
+
// Numeric initializers matter: starting the fields as `undefined` changes
|
|
4553
|
+
// V8's field representation and makes sha256 3x slower (measured).
|
|
4554
|
+
__publicField(this, "A", 0);
|
|
4555
|
+
__publicField(this, "B", 0);
|
|
4556
|
+
__publicField(this, "C", 0);
|
|
4557
|
+
__publicField(this, "D", 0);
|
|
4558
|
+
__publicField(this, "E", 0);
|
|
4559
|
+
__publicField(this, "F", 0);
|
|
4560
|
+
__publicField(this, "G", 0);
|
|
4561
|
+
__publicField(this, "H", 0);
|
|
4562
|
+
this.A = IV[0] | 0;
|
|
4563
|
+
this.B = IV[1] | 0;
|
|
4564
|
+
this.C = IV[2] | 0;
|
|
4565
|
+
this.D = IV[3] | 0;
|
|
4566
|
+
this.E = IV[4] | 0;
|
|
4567
|
+
this.F = IV[5] | 0;
|
|
4568
|
+
this.G = IV[6] | 0;
|
|
4569
|
+
this.H = IV[7] | 0;
|
|
4570
|
+
}
|
|
4571
|
+
get() {
|
|
4572
|
+
const { A, B, C, D, E, F, G, H } = this;
|
|
4573
|
+
return [A, B, C, D, E, F, G, H];
|
|
4574
|
+
}
|
|
4575
|
+
// prettier-ignore
|
|
4576
|
+
set(A, B, C, D, E, F, G, H) {
|
|
4577
|
+
this.A = A | 0;
|
|
4578
|
+
this.B = B | 0;
|
|
4579
|
+
this.C = C | 0;
|
|
4580
|
+
this.D = D | 0;
|
|
4581
|
+
this.E = E | 0;
|
|
4582
|
+
this.F = F | 0;
|
|
4583
|
+
this.G = G | 0;
|
|
4584
|
+
this.H = H | 0;
|
|
4585
|
+
}
|
|
4586
|
+
_cloneInto(to) {
|
|
4587
|
+
(to || (to = new this.constructor())).set(...this.get());
|
|
4588
|
+
return this._cloneIntoMeta(to);
|
|
4589
|
+
}
|
|
4590
|
+
process(view, offset) {
|
|
4591
|
+
for (let i = 0; i < 16; i++, offset += 4)
|
|
4592
|
+
SHA256_W[i] = view.getUint32(offset, false);
|
|
4593
|
+
for (let i = 16; i < 64; i++) {
|
|
4594
|
+
const W15 = SHA256_W[i - 15];
|
|
4595
|
+
const W2 = SHA256_W[i - 2];
|
|
4596
|
+
const s0 = rotr(W15, 7) ^ rotr(W15, 18) ^ W15 >>> 3;
|
|
4597
|
+
const s1 = rotr(W2, 17) ^ rotr(W2, 19) ^ W2 >>> 10;
|
|
4598
|
+
SHA256_W[i] = s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16] | 0;
|
|
4599
|
+
}
|
|
4600
|
+
let { A, B, C, D, E, F, G, H } = this;
|
|
4601
|
+
for (let i = 0; i < 64; i++) {
|
|
4602
|
+
const sigma1 = rotr(E, 6) ^ rotr(E, 11) ^ rotr(E, 25);
|
|
4603
|
+
const T1 = H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i] | 0;
|
|
4604
|
+
const sigma0 = rotr(A, 2) ^ rotr(A, 13) ^ rotr(A, 22);
|
|
4605
|
+
const T2 = sigma0 + Maj(A, B, C) | 0;
|
|
4606
|
+
H = G;
|
|
4607
|
+
G = F;
|
|
4608
|
+
F = E;
|
|
4609
|
+
E = D + T1 | 0;
|
|
4610
|
+
D = C;
|
|
4611
|
+
C = B;
|
|
4612
|
+
B = A;
|
|
4613
|
+
A = T1 + T2 | 0;
|
|
4614
|
+
}
|
|
4615
|
+
A = A + this.A | 0;
|
|
4616
|
+
B = B + this.B | 0;
|
|
4617
|
+
C = C + this.C | 0;
|
|
4618
|
+
D = D + this.D | 0;
|
|
4619
|
+
E = E + this.E | 0;
|
|
4620
|
+
F = F + this.F | 0;
|
|
4621
|
+
G = G + this.G | 0;
|
|
4622
|
+
H = H + this.H | 0;
|
|
4623
|
+
this.set(A, B, C, D, E, F, G, H);
|
|
4624
|
+
}
|
|
4625
|
+
roundClean() {
|
|
4626
|
+
clean(SHA256_W);
|
|
4627
|
+
}
|
|
4628
|
+
destroy() {
|
|
4629
|
+
this.destroyed = true;
|
|
4630
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
4631
|
+
clean(this.buffer);
|
|
4632
|
+
}
|
|
4633
|
+
};
|
|
4634
|
+
var _SHA256 = class extends SHA2_32B {
|
|
4635
|
+
constructor() {
|
|
4636
|
+
super(32, SHA256_IV);
|
|
4637
|
+
}
|
|
4638
|
+
};
|
|
4639
|
+
var sha2562 = /* @__PURE__ */ createHasher(
|
|
4640
|
+
() => new _SHA256(),
|
|
4641
|
+
/* @__PURE__ */ oidNist(1)
|
|
4642
|
+
);
|
|
4643
|
+
|
|
4644
|
+
// src/sealed/file.ts
|
|
4645
|
+
var CHUNK_BYTES = 64 * 1024;
|
|
4646
|
+
var TAG_BYTES = 16;
|
|
4647
|
+
var SEALED_CHUNK_BYTES = CHUNK_BYTES + TAG_BYTES;
|
|
4648
|
+
var SEGMENT_BYTES = 256 * SEALED_CHUNK_BYTES;
|
|
4649
|
+
var NONCE_BYTES = 12;
|
|
4650
|
+
var enc = new TextEncoder();
|
|
4651
|
+
var AAD_PREFIX = enc.encode("calimero.file.v1");
|
|
4652
|
+
var SEGMENT_DOMAIN = enc.encode("calimero.file.segments.v1\0");
|
|
4653
|
+
var EXPORT_WRAP_SALT = enc.encode("calimero.export-wrap.v1");
|
|
4654
|
+
var DERIVE_LABEL = enc.encode("calimero.sealed.derive.v1\0");
|
|
4655
|
+
var ExportError = class extends Error {
|
|
4656
|
+
constructor(code, message) {
|
|
4657
|
+
super(message);
|
|
4658
|
+
this.code = code;
|
|
4659
|
+
this.name = "ExportError";
|
|
4660
|
+
}
|
|
4661
|
+
};
|
|
4662
|
+
var sha2563 = async (data) => new Uint8Array(await crypto.subtle.digest("SHA-256", data));
|
|
4663
|
+
function fileId(segments) {
|
|
4664
|
+
const count = new Uint8Array(4);
|
|
4665
|
+
new DataView(count.buffer).setUint32(0, segments.length, false);
|
|
4666
|
+
return sha2563(concat(SEGMENT_DOMAIN, count, ...segments));
|
|
4667
|
+
}
|
|
4668
|
+
function prefixed(field) {
|
|
4669
|
+
const bytes = enc.encode(field);
|
|
4670
|
+
const length = new Uint8Array(4);
|
|
4671
|
+
new DataView(length.buffer).setUint32(0, bytes.length, false);
|
|
4672
|
+
return concat(length, bytes);
|
|
4673
|
+
}
|
|
4674
|
+
async function unwrapExport(recipient, ephemeral, wrap, wrapped) {
|
|
4675
|
+
if (wrapped.length < NONCE_BYTES) throw new ExportError("TAMPERED", "the wrapped key is truncated");
|
|
4676
|
+
const shared = await dh(recipient.privateKey, ephemeral);
|
|
4677
|
+
if (shared.every((b) => b === 0)) throw new ExportError("BAD_ANSWER", "the ephemeral key is of low order");
|
|
4678
|
+
const info = concat(ephemeral, recipient.publicKey, prefixed(wrap.appId), prefixed(wrap.fileId));
|
|
4679
|
+
const ikm = await crypto.subtle.importKey("raw", shared, "HKDF", false, ["deriveBits"]);
|
|
4680
|
+
const keyBytes = await crypto.subtle.deriveBits(
|
|
4681
|
+
{ name: "HKDF", hash: "SHA-256", salt: EXPORT_WRAP_SALT, info: concat(DERIVE_LABEL, info) },
|
|
4682
|
+
ikm,
|
|
4683
|
+
256
|
|
4684
|
+
);
|
|
4685
|
+
const key = await crypto.subtle.importKey("raw", keyBytes, "AES-GCM", false, ["decrypt"]);
|
|
4686
|
+
let secret;
|
|
4687
|
+
try {
|
|
4688
|
+
secret = await crypto.subtle.decrypt(
|
|
4689
|
+
{ name: "AES-GCM", iv: wrapped.subarray(0, NONCE_BYTES) },
|
|
4690
|
+
key,
|
|
4691
|
+
wrapped.subarray(NONCE_BYTES)
|
|
4692
|
+
);
|
|
4693
|
+
} catch {
|
|
4694
|
+
throw new ExportError("TAMPERED", "the wrapped key does not open");
|
|
4695
|
+
}
|
|
4696
|
+
if (secret.byteLength !== 32) throw new ExportError("TAMPERED", "the wrapped key has the wrong length");
|
|
4697
|
+
return new Uint8Array(secret);
|
|
4698
|
+
}
|
|
4699
|
+
var SegmentReader = class _SegmentReader {
|
|
4700
|
+
constructor(key, segments) {
|
|
4701
|
+
this.key = key;
|
|
4702
|
+
this.segments = segments;
|
|
4703
|
+
this.pending = new Uint8Array();
|
|
4704
|
+
this.index = 0;
|
|
4705
|
+
this.next = 0;
|
|
4706
|
+
this.size = 0;
|
|
4707
|
+
this.hash = sha2562.create();
|
|
4708
|
+
}
|
|
4709
|
+
static async create(dataKey, segments) {
|
|
4710
|
+
const key = await crypto.subtle.importKey("raw", dataKey, "AES-GCM", false, ["decrypt"]);
|
|
4711
|
+
return new _SegmentReader(key, segments.map(hex));
|
|
4712
|
+
}
|
|
4713
|
+
/** Take the next segment; `emit` gets the plaintext of every chunk it completes. */
|
|
4714
|
+
async push(segment, emit) {
|
|
4715
|
+
const want = this.segments[this.next];
|
|
4716
|
+
if (want === void 0) throw new ExportError("TAMPERED", `the file has no segment ${this.next}`);
|
|
4717
|
+
if (this.next + 1 < this.segments.length && segment.length !== SEGMENT_BYTES) {
|
|
4718
|
+
throw new ExportError("TAMPERED", `segment ${this.next} is not a whole segment`);
|
|
4719
|
+
}
|
|
4720
|
+
if (hex(await sha2563(segment)) !== want) {
|
|
4721
|
+
throw new ExportError("TAMPERED", `segment ${this.next} is not the one the file lists`);
|
|
4722
|
+
}
|
|
4723
|
+
this.next += 1;
|
|
4724
|
+
const data = concat(this.pending, segment);
|
|
4725
|
+
let at = 0;
|
|
4726
|
+
while (data.length - at > SEALED_CHUNK_BYTES) {
|
|
4727
|
+
await emit(await this.open(data.subarray(at, at + SEALED_CHUNK_BYTES), false));
|
|
4728
|
+
at += SEALED_CHUNK_BYTES;
|
|
4729
|
+
}
|
|
4730
|
+
this.pending = data.slice(at);
|
|
4731
|
+
}
|
|
4732
|
+
/** Open the last chunk and check the whole plaintext's size and SHA-256: GCM does not commit to its key. */
|
|
4733
|
+
async finishExpecting(size, sha256Hex) {
|
|
4734
|
+
if (this.next !== this.segments.length) throw new ExportError("TAMPERED", "the file is missing segments");
|
|
4735
|
+
if (this.pending.length < TAG_BYTES) throw new ExportError("TAMPERED", "the file is truncated");
|
|
4736
|
+
const last = await this.open(this.pending, true);
|
|
4737
|
+
if (this.size !== size || hex(this.hash.digest()) !== sha256Hex) {
|
|
4738
|
+
throw new ExportError("TAMPERED", "the file is not the one that was sealed");
|
|
4739
|
+
}
|
|
4740
|
+
return last;
|
|
4741
|
+
}
|
|
4742
|
+
async open(chunk, last) {
|
|
4743
|
+
const iv = new Uint8Array(NONCE_BYTES);
|
|
4744
|
+
new DataView(iv.buffer).setBigUint64(4, BigInt(this.index), false);
|
|
4745
|
+
let plain;
|
|
4746
|
+
try {
|
|
4747
|
+
plain = new Uint8Array(
|
|
4748
|
+
await crypto.subtle.decrypt(
|
|
4749
|
+
{ name: "AES-GCM", iv, additionalData: concat(AAD_PREFIX, new Uint8Array([last ? 1 : 0])) },
|
|
4750
|
+
this.key,
|
|
4751
|
+
chunk
|
|
4752
|
+
)
|
|
4753
|
+
);
|
|
4754
|
+
} catch {
|
|
4755
|
+
throw new ExportError(
|
|
4756
|
+
"TAMPERED",
|
|
4757
|
+
`chunk ${this.index} does not open: the file is altered, truncated or under another key`
|
|
4758
|
+
);
|
|
4759
|
+
}
|
|
4760
|
+
this.hash.update(plain);
|
|
4761
|
+
this.size += plain.length;
|
|
4762
|
+
this.index += 1;
|
|
4763
|
+
return plain;
|
|
4764
|
+
}
|
|
4765
|
+
};
|
|
4766
|
+
|
|
4767
|
+
// src/client/files.ts
|
|
4768
|
+
function hexField(value, label, bytes) {
|
|
4769
|
+
if (typeof value !== "string") throw new ExportError("BAD_ANSWER", `the node answered a bad ${label}`);
|
|
4770
|
+
try {
|
|
4771
|
+
return bytes === void 0 ? fromHexUnsized(value, label) : fromHex(value, label, bytes);
|
|
4772
|
+
} catch {
|
|
4773
|
+
throw new ExportError("BAD_ANSWER", `the node answered a bad ${label}`);
|
|
4774
|
+
}
|
|
4775
|
+
}
|
|
4776
|
+
function checked(answer) {
|
|
4777
|
+
const a = answer;
|
|
4778
|
+
if (typeof a !== "object" || a === null) throw new ExportError("BAD_ANSWER", "the node answered a bad export");
|
|
4779
|
+
if (typeof a.app !== "string") throw new ExportError("BAD_ANSWER", "the node answered a bad app");
|
|
4780
|
+
if (typeof a.size !== "number" || !Number.isSafeInteger(a.size) || a.size < 0) {
|
|
4781
|
+
throw new ExportError("BAD_ANSWER", "the node answered a bad size");
|
|
4782
|
+
}
|
|
4783
|
+
if (!Array.isArray(a.segments)) throw new ExportError("BAD_ANSWER", "the node answered a bad segment list");
|
|
4784
|
+
return {
|
|
4785
|
+
app: a.app,
|
|
4786
|
+
size: a.size,
|
|
4787
|
+
named: hexField(a.id, "file id", 32),
|
|
4788
|
+
segments: a.segments.map((h) => hexField(h, "segment hash", 32)),
|
|
4789
|
+
sha256: hex(hexField(a.sha256, "sha256", 32)),
|
|
4790
|
+
ephemeral: hexField(a.ephemeral, "ephemeral key", 32),
|
|
4791
|
+
wrapped: hexField(a.wrapped, "wrapped key")
|
|
4792
|
+
};
|
|
4793
|
+
}
|
|
4794
|
+
var aborted = () => new ExportError("ABORTED", "the export was aborted");
|
|
4795
|
+
async function readSegment(response, signal) {
|
|
4796
|
+
const declared = Number(response.headers.get("content-length"));
|
|
4797
|
+
if (Number.isFinite(declared) && declared > SEGMENT_BYTES) {
|
|
4798
|
+
await response.body?.cancel();
|
|
4799
|
+
throw new ExportError("TOO_LARGE", "a segment is longer than a whole segment");
|
|
4800
|
+
}
|
|
4801
|
+
if (!response.body) return new Uint8Array();
|
|
4802
|
+
const reader = response.body.getReader();
|
|
4803
|
+
const stop = () => void reader.cancel();
|
|
4804
|
+
signal?.addEventListener("abort", stop);
|
|
4805
|
+
const parts = [];
|
|
4806
|
+
let total = 0;
|
|
4807
|
+
try {
|
|
4808
|
+
for (; ; ) {
|
|
4809
|
+
const { done, value } = await reader.read();
|
|
4810
|
+
if (done) break;
|
|
4811
|
+
total += value.length;
|
|
4812
|
+
if (total > SEGMENT_BYTES) {
|
|
4813
|
+
await reader.cancel();
|
|
4814
|
+
throw new ExportError("TOO_LARGE", "a segment is longer than a whole segment");
|
|
4815
|
+
}
|
|
4816
|
+
parts.push(value);
|
|
4817
|
+
}
|
|
4818
|
+
} finally {
|
|
4819
|
+
signal?.removeEventListener("abort", stop);
|
|
4820
|
+
}
|
|
4821
|
+
if (signal?.aborted) throw aborted();
|
|
4822
|
+
return concat(...parts);
|
|
4823
|
+
}
|
|
4824
|
+
async function exportFileTo(transport, app, id, sink, signal, recipientSecret) {
|
|
4825
|
+
try {
|
|
4826
|
+
return await exportChecked(transport, app, id, sink, signal, recipientSecret);
|
|
4827
|
+
} catch (error) {
|
|
4828
|
+
if (signal?.aborted && !(error instanceof ExportError)) throw aborted();
|
|
4829
|
+
throw error;
|
|
4830
|
+
}
|
|
4831
|
+
}
|
|
4832
|
+
async function exportChecked(transport, app, id, sink, signal, recipientSecret) {
|
|
4833
|
+
const recipient = await x25519KeyPair(recipientSecret);
|
|
4834
|
+
const answer = checked(
|
|
4835
|
+
await transport.json("POST", routePath("apps/{app}/files/{id}/export", { app, id }), {
|
|
4836
|
+
body: { recipient: hex(recipient.publicKey) },
|
|
4837
|
+
signal
|
|
4838
|
+
})
|
|
4839
|
+
);
|
|
4840
|
+
const { segments, named } = answer;
|
|
4841
|
+
if (segments.length === 0 || hex(await fileId(segments)) !== hex(named) || hex(named) !== id) {
|
|
4842
|
+
throw new ExportError("NOT_THE_FILE", `the node answered segments that are not the file ${id}`);
|
|
4843
|
+
}
|
|
4844
|
+
const dataKey = await unwrapExport(recipient, answer.ephemeral, { appId: answer.app, fileId: id }, answer.wrapped);
|
|
4845
|
+
const reader = await SegmentReader.create(dataKey, segments);
|
|
4846
|
+
for (let k = 0; k < segments.length; k += 1) {
|
|
4847
|
+
if (signal?.aborted) throw aborted();
|
|
4848
|
+
const response = await transport.request("GET", routePath("apps/{app}/files/{id}/segments/{k}", { app, id, k }), {
|
|
4849
|
+
signal
|
|
4850
|
+
});
|
|
4851
|
+
await reader.push(await readSegment(response, signal), (chunk) => sink.write(chunk));
|
|
4852
|
+
}
|
|
4853
|
+
const last = await reader.finishExpecting(answer.size, answer.sha256);
|
|
4854
|
+
if (last.length > 0) await sink.write(last);
|
|
4855
|
+
return { size: answer.size, sha256: answer.sha256 };
|
|
4856
|
+
}
|
|
4857
|
+
async function exportFile(transport, app, id, signal) {
|
|
4858
|
+
const chunks = [];
|
|
4859
|
+
await exportFileTo(transport, app, id, { write: (chunk) => void chunks.push(chunk) }, signal);
|
|
4860
|
+
return concat(...chunks);
|
|
4861
|
+
}
|
|
4862
|
+
|
|
4250
4863
|
// src/client/recovery-key.ts
|
|
4251
4864
|
var RECOVERY_DOMAIN = "calimero.org-recovery.v1\0";
|
|
4252
4865
|
var MAX_RECOVERY_NONCE_BYTES = 64;
|
|
@@ -4373,6 +4986,13 @@ function consentReturn(href) {
|
|
|
4373
4986
|
if (!requestId || result !== "approved" && result !== "declined") return null;
|
|
4374
4987
|
return { requestId, result };
|
|
4375
4988
|
}
|
|
4989
|
+
function withoutConsentReturn(href) {
|
|
4990
|
+
const url2 = new URL(String(href));
|
|
4991
|
+
url2.searchParams.delete("request_id");
|
|
4992
|
+
url2.searchParams.delete("result");
|
|
4993
|
+
return url2.toString();
|
|
4994
|
+
}
|
|
4995
|
+
var CONSENT_STORAGE_KEY = "calimero.consent";
|
|
4376
4996
|
var RELEASE_VERIFIER = "https://mero-tee.vercel.app";
|
|
4377
4997
|
function releaseNotesUrl(version) {
|
|
4378
4998
|
return `https://github.com/calimero-network/mero-tee/releases/tag/mero-tee-v${encodeURIComponent(version)}`;
|
|
@@ -4434,6 +5054,15 @@ function withdrawConsent(scope, version, returnTo) {
|
|
|
4434
5054
|
function upgradeConsent(app, toVersion, returnTo) {
|
|
4435
5055
|
return { kind: "upgrade", subject: { app, toVersion }, returnTo };
|
|
4436
5056
|
}
|
|
5057
|
+
function createOrgConsent(name, returnTo) {
|
|
5058
|
+
return { kind: "createOrg", subject: { name }, returnTo };
|
|
5059
|
+
}
|
|
5060
|
+
function createInviteConsent(subject, returnTo) {
|
|
5061
|
+
return { kind: "createInvite", subject, returnTo };
|
|
5062
|
+
}
|
|
5063
|
+
function acceptInviteConsent(token, returnTo) {
|
|
5064
|
+
return { kind: "acceptInvite", subject: { token }, returnTo };
|
|
5065
|
+
}
|
|
4437
5066
|
|
|
4438
5067
|
// src/client/calimero-client.ts
|
|
4439
5068
|
var FILE_PART_BYTES = 16 * 1024 * 1024;
|
|
@@ -4708,6 +5337,18 @@ var CalimeroClient = class _CalimeroClient {
|
|
|
4708
5337
|
async downloadBlob(app, id) {
|
|
4709
5338
|
return new Uint8Array(await (await this.apps.blobDownload({ app, id })).arrayBuffer());
|
|
4710
5339
|
}
|
|
5340
|
+
/**
|
|
5341
|
+
* Write the plaintext of sealed file `id` of component app `app` to `sink`, checked against its id,
|
|
5342
|
+
* size and hash. On rejection, discard what `sink` received: it is authentic but may be a prefix of
|
|
5343
|
+
* the file. A failed check is an `ExportError`; `signal` aborts the download.
|
|
5344
|
+
*/
|
|
5345
|
+
exportFileTo(app, id, sink, signal) {
|
|
5346
|
+
return exportFileTo(this.transport, app, id, sink, signal);
|
|
5347
|
+
}
|
|
5348
|
+
/** The plaintext of sealed file `id` of component app `app`, in memory; use {@link exportFileTo} for a large one. */
|
|
5349
|
+
exportFile(app, id, signal) {
|
|
5350
|
+
return exportFile(this.transport, app, id, signal);
|
|
5351
|
+
}
|
|
4711
5352
|
/**
|
|
4712
5353
|
* Download a component app's blob with a grant one of its runs handed out
|
|
4713
5354
|
* (`BlobRef::grant`, up to 24 h). No session needed: the grant is the
|
|
@@ -4858,6 +5499,8 @@ var CalimeroClient = class _CalimeroClient {
|
|
|
4858
5499
|
* (`CONSENT_CODE_MISMATCH`) and does not navigate. Answers the request
|
|
4859
5500
|
* once `navigate` returns (or `confirm` declines): with a popup
|
|
4860
5501
|
* (`url => window.open(url)`), poll it with {@link waitForConsent}.
|
|
5502
|
+
* Before navigating it keeps `requestId` in `sessionStorage` (where there
|
|
5503
|
+
* is one), for {@link resumeConsent} when the page sends the person back.
|
|
4861
5504
|
*/
|
|
4862
5505
|
async openConsentPage(request, navigateOrOptions = {}) {
|
|
4863
5506
|
const options = typeof navigateOrOptions === "function" ? { navigate: navigateOrOptions } : navigateOrOptions;
|
|
@@ -4878,9 +5521,84 @@ var CalimeroClient = class _CalimeroClient {
|
|
|
4878
5521
|
}
|
|
4879
5522
|
}
|
|
4880
5523
|
if (options.confirm && !await options.confirm(started)) return started;
|
|
5524
|
+
try {
|
|
5525
|
+
consentStorage()?.setItem(CONSENT_STORAGE_KEY, started.requestId);
|
|
5526
|
+
} catch {
|
|
5527
|
+
}
|
|
4881
5528
|
navigate(started.url);
|
|
4882
5529
|
return started;
|
|
4883
5530
|
}
|
|
5531
|
+
/**
|
|
5532
|
+
* On the page the consent page sent the person back to
|
|
5533
|
+
* (`returnTo?request_id=…&result=…`): the decision on the request this page
|
|
5534
|
+
* started, read from the node (`GET /consent/{id}/result`), never from the
|
|
5535
|
+
* URL. `null` when the URL carries no `request_id`. The request is
|
|
5536
|
+
* `options.requestId`, or the one {@link openConsentPage} stored in this
|
|
5537
|
+
* tab; with the default `href` (`location.href`) the parameters are then
|
|
5538
|
+
* removed with `history.replaceState`, and the stored id once decided.
|
|
5539
|
+
*
|
|
5540
|
+
* Throws `CalimeroError`:
|
|
5541
|
+
* - `CONSENT_NOT_STARTED`: the URL names a request, and this page started none;
|
|
5542
|
+
* - `CONSENT_REQUEST_MISMATCH`: the URL names another request than this page's;
|
|
5543
|
+
* - `CONSENT_NOT_DECIDED`: this page's request is still pending although the
|
|
5544
|
+
* page sent the person back, a sign that another request was approved on a
|
|
5545
|
+
* page that was not the node's. Do not act on it;
|
|
5546
|
+
* - `CONSENT_REPLACED`: the node no longer knows this page's request (`404`):
|
|
5547
|
+
* an account has one undecided request per node, and a newer one replaced
|
|
5548
|
+
* it, possibly on a page that was not the node's. Do not act on it either.
|
|
5549
|
+
*
|
|
5550
|
+
* The URL's `result` is never trusted: the answer's `status` is the node's.
|
|
5551
|
+
* An approval's `outcome` (`orgId`, an invite's `token`, the `org` joined) is
|
|
5552
|
+
* in the answer, typed by `kind`.
|
|
5553
|
+
*/
|
|
5554
|
+
async resumeConsent(options = {}) {
|
|
5555
|
+
const g = globalThis;
|
|
5556
|
+
const href = options.href ?? g.location?.href;
|
|
5557
|
+
if (href === void 0) throw new Error("no page to read the consent return from; pass `href`");
|
|
5558
|
+
const url2 = new URL(href);
|
|
5559
|
+
const returned = url2.searchParams.get("request_id");
|
|
5560
|
+
if (!returned) return null;
|
|
5561
|
+
if (options.href === void 0 && g.history) g.history.replaceState(g.history.state, "", withoutConsentReturn(url2));
|
|
5562
|
+
let ownId = options.requestId;
|
|
5563
|
+
if (ownId === void 0) {
|
|
5564
|
+
try {
|
|
5565
|
+
ownId = consentStorage()?.getItem(CONSENT_STORAGE_KEY) ?? void 0;
|
|
5566
|
+
} catch {
|
|
5567
|
+
ownId = void 0;
|
|
5568
|
+
}
|
|
5569
|
+
}
|
|
5570
|
+
if (!ownId) {
|
|
5571
|
+
throw new CalimeroError(200, "CONSENT_NOT_STARTED", "this page started no consent request", { returned });
|
|
5572
|
+
}
|
|
5573
|
+
if (returned !== ownId) {
|
|
5574
|
+
throw new CalimeroError(200, "CONSENT_REQUEST_MISMATCH", "the consent page returned another request than this page started", {
|
|
5575
|
+
requestId: ownId,
|
|
5576
|
+
returned
|
|
5577
|
+
});
|
|
5578
|
+
}
|
|
5579
|
+
let result;
|
|
5580
|
+
try {
|
|
5581
|
+
result = await this.consent.pageResult({ request: ownId });
|
|
5582
|
+
} catch (e) {
|
|
5583
|
+
if (e instanceof NotFound) {
|
|
5584
|
+
forgetConsent(ownId);
|
|
5585
|
+
throw new CalimeroError(404, "CONSENT_REPLACED", "this page's consent request was replaced by a newer one", {
|
|
5586
|
+
requestId: ownId
|
|
5587
|
+
});
|
|
5588
|
+
}
|
|
5589
|
+
throw e;
|
|
5590
|
+
}
|
|
5591
|
+
if (result.requestId !== ownId) {
|
|
5592
|
+
throw new CalimeroError(200, "CONSENT_REQUEST_MISMATCH", "the node answered another request", { requestId: ownId, returned: result.requestId });
|
|
5593
|
+
}
|
|
5594
|
+
if (result.status === "pending") {
|
|
5595
|
+
throw new CalimeroError(200, "CONSENT_NOT_DECIDED", "the consent page returned, but this request is still pending", {
|
|
5596
|
+
requestId: ownId
|
|
5597
|
+
});
|
|
5598
|
+
}
|
|
5599
|
+
forgetConsent(ownId);
|
|
5600
|
+
return result;
|
|
5601
|
+
}
|
|
4884
5602
|
/**
|
|
4885
5603
|
* Poll `client.consent.pageResult` until the request is decided, every
|
|
4886
5604
|
* `intervalMs` (2 s), until `signal` aborts or `expiresAt` (Unix seconds)
|
|
@@ -4902,6 +5620,20 @@ var CalimeroClient = class _CalimeroClient {
|
|
|
4902
5620
|
// ---------------------------------------------------------------- deployers
|
|
4903
5621
|
// ---------------------------------------------------------------- deployments
|
|
4904
5622
|
};
|
|
5623
|
+
function consentStorage() {
|
|
5624
|
+
try {
|
|
5625
|
+
return globalThis.sessionStorage;
|
|
5626
|
+
} catch {
|
|
5627
|
+
return void 0;
|
|
5628
|
+
}
|
|
5629
|
+
}
|
|
5630
|
+
function forgetConsent(requestId) {
|
|
5631
|
+
try {
|
|
5632
|
+
const store = consentStorage();
|
|
5633
|
+
if (store?.getItem(CONSENT_STORAGE_KEY) === requestId) store.removeItem(CONSENT_STORAGE_KEY);
|
|
5634
|
+
} catch {
|
|
5635
|
+
}
|
|
5636
|
+
}
|
|
4905
5637
|
|
|
4906
5638
|
// src/client/capabilities.ts
|
|
4907
5639
|
var ORG_CAPABILITIES = {
|
|
@@ -5438,11 +6170,11 @@ async function openDataKey(header, secret) {
|
|
|
5438
6170
|
if (hex(recipient.publicKey) !== header.recipient) {
|
|
5439
6171
|
throw new Error("this key is not the one the file was sealed to");
|
|
5440
6172
|
}
|
|
5441
|
-
const
|
|
5442
|
-
const dhValue = await dh(recipient.privateKey,
|
|
6173
|
+
const enc2 = fromHex(header.enc, "encapsulated key", 32);
|
|
6174
|
+
const dhValue = await dh(recipient.privateKey, enc2);
|
|
5443
6175
|
const empty = new Uint8Array(0);
|
|
5444
6176
|
const prk = await labeledExtract2(KEM_SUITE2, empty, "eae_prk", dhValue);
|
|
5445
|
-
const shared = await labeledExpand2(KEM_SUITE2, prk, "shared_secret", concat(
|
|
6177
|
+
const shared = await labeledExpand2(KEM_SUITE2, prk, "shared_secret", concat(enc2, recipient.publicKey), 32);
|
|
5446
6178
|
const pskIdHash = await labeledExtract2(HPKE_SUITE2, empty, "psk_id_hash", empty);
|
|
5447
6179
|
const infoHash = await labeledExtract2(HPKE_SUITE2, empty, "info_hash", HPKE_INFO);
|
|
5448
6180
|
const context = concat(new Uint8Array([MODE_BASE]), pskIdHash, infoHash);
|
|
@@ -5466,23 +6198,23 @@ async function openDataKey(header, secret) {
|
|
|
5466
6198
|
return plain;
|
|
5467
6199
|
}
|
|
5468
6200
|
async function holderRecoveryBody(holder, files, secret, options = {}) {
|
|
5469
|
-
const
|
|
6201
|
+
const checked2 = [];
|
|
5470
6202
|
for (const f of [...files].sort((a, b) => a.name.localeCompare(b.name))) {
|
|
5471
6203
|
const header = await verifyRecoveryHeader(f);
|
|
5472
6204
|
if (options.verifyQuote) await verifyRecoveryAttestation(header, options.verifyQuote);
|
|
5473
6205
|
if (holderKey(header.holder) !== holderKey(holder)) {
|
|
5474
6206
|
throw new Error(`${f.name} is ${holderKey(header.holder)}'s, not ${holderKey(holder)}'s`);
|
|
5475
6207
|
}
|
|
5476
|
-
|
|
6208
|
+
checked2.push({ name: f.name, header });
|
|
5477
6209
|
}
|
|
5478
6210
|
const open = async (c) => ({
|
|
5479
6211
|
file: c.name,
|
|
5480
6212
|
key: hex(await openDataKey(c.header, secret))
|
|
5481
6213
|
});
|
|
5482
|
-
const slice =
|
|
6214
|
+
const slice = checked2.filter((c) => c.header.kind === "holder").pop();
|
|
5483
6215
|
if (!slice) throw new Error(`no holder file of ${holderKey(holder)}`);
|
|
5484
6216
|
const newestByApp = /* @__PURE__ */ new Map();
|
|
5485
|
-
for (const c of
|
|
6217
|
+
for (const c of checked2) {
|
|
5486
6218
|
if (c.header.kind === "app" && c.header.app && (!options.apps || options.apps.includes(c.header.app))) {
|
|
5487
6219
|
newestByApp.set(c.header.app, c);
|
|
5488
6220
|
}
|
|
@@ -5491,10 +6223,10 @@ async function holderRecoveryBody(holder, files, secret, options = {}) {
|
|
|
5491
6223
|
holder: holderKey(holder),
|
|
5492
6224
|
slice: await open(slice),
|
|
5493
6225
|
apps: await Promise.all([...newestByApp.values()].map(open)),
|
|
5494
|
-
code: await Promise.all(
|
|
6226
|
+
code: await Promise.all(checked2.filter((c) => c.header.kind === "code").map(open))
|
|
5495
6227
|
};
|
|
5496
6228
|
}
|
|
5497
|
-
async function
|
|
6229
|
+
async function sha2564(data) {
|
|
5498
6230
|
return new Uint8Array(await crypto.subtle.digest("SHA-256", data));
|
|
5499
6231
|
}
|
|
5500
6232
|
async function recoveryAttestationNonce(cluster, node) {
|
|
@@ -5503,11 +6235,11 @@ async function recoveryAttestationNonce(cluster, node) {
|
|
|
5503
6235
|
new DataView(len.buffer).setUint32(0, name.length, false);
|
|
5504
6236
|
const id = new Uint8Array(8);
|
|
5505
6237
|
new DataView(id.buffer).setBigUint64(0, BigInt(node), false);
|
|
5506
|
-
return hex(await
|
|
6238
|
+
return hex(await sha2564(concat(utf85("calimero.recovery-backup.attest.v1\0"), len, name, id)));
|
|
5507
6239
|
}
|
|
5508
6240
|
async function receiptKeyBinding(receiptKey, governance) {
|
|
5509
|
-
const g = await
|
|
5510
|
-
return hex(await
|
|
6241
|
+
const g = await sha2564(utf85(JSON.stringify(governance)));
|
|
6242
|
+
return hex(await sha2564(concat(utf85("calimero.tee-attest.receipt-key.v2"), receiptKey, g)));
|
|
5511
6243
|
}
|
|
5512
6244
|
async function verifyRecoveryAttestation(header, verifyQuote) {
|
|
5513
6245
|
const doc = header.attestation;
|