@tinycloud/cli 0.9.0 → 0.9.1-beta.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/dist/index.js +289 -107
- package/dist/index.js.map +1 -1
- package/dist/legacy-entry.js +706 -133
- package/dist/legacy-entry.js.map +1 -1
- package/package.json +3 -3
package/dist/legacy-entry.js
CHANGED
|
@@ -407,10 +407,10 @@ var init_util = __esm({
|
|
|
407
407
|
return obj[e];
|
|
408
408
|
});
|
|
409
409
|
};
|
|
410
|
-
util3.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (
|
|
410
|
+
util3.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object2) => {
|
|
411
411
|
const keys = [];
|
|
412
|
-
for (const key in
|
|
413
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
412
|
+
for (const key in object2) {
|
|
413
|
+
if (Object.prototype.hasOwnProperty.call(object2, key)) {
|
|
414
414
|
keys.push(key);
|
|
415
415
|
}
|
|
416
416
|
}
|
|
@@ -4531,6 +4531,9 @@ function aoutput(out, instance) {
|
|
|
4531
4531
|
throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
4532
4532
|
}
|
|
4533
4533
|
}
|
|
4534
|
+
function u8(arr) {
|
|
4535
|
+
return new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
4536
|
+
}
|
|
4534
4537
|
function u32(arr) {
|
|
4535
4538
|
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
4536
4539
|
}
|
|
@@ -4558,11 +4561,11 @@ function bytesToHex(bytes) {
|
|
|
4558
4561
|
abytes(bytes);
|
|
4559
4562
|
if (hasHexBuiltin)
|
|
4560
4563
|
return bytes.toHex();
|
|
4561
|
-
let
|
|
4564
|
+
let hex2 = "";
|
|
4562
4565
|
for (let i = 0; i < bytes.length; i++) {
|
|
4563
|
-
|
|
4566
|
+
hex2 += hexes[bytes[i]];
|
|
4564
4567
|
}
|
|
4565
|
-
return
|
|
4568
|
+
return hex2;
|
|
4566
4569
|
}
|
|
4567
4570
|
function asciiToBase16(ch) {
|
|
4568
4571
|
if (ch >= asciis._0 && ch <= asciis._9)
|
|
@@ -4573,21 +4576,21 @@ function asciiToBase16(ch) {
|
|
|
4573
4576
|
return ch - (asciis.a - 10);
|
|
4574
4577
|
return;
|
|
4575
4578
|
}
|
|
4576
|
-
function hexToBytes(
|
|
4577
|
-
if (typeof
|
|
4578
|
-
throw new Error("hex string expected, got " + typeof
|
|
4579
|
+
function hexToBytes(hex2) {
|
|
4580
|
+
if (typeof hex2 !== "string")
|
|
4581
|
+
throw new Error("hex string expected, got " + typeof hex2);
|
|
4579
4582
|
if (hasHexBuiltin)
|
|
4580
|
-
return Uint8Array.fromHex(
|
|
4581
|
-
const hl =
|
|
4583
|
+
return Uint8Array.fromHex(hex2);
|
|
4584
|
+
const hl = hex2.length;
|
|
4582
4585
|
const al = hl / 2;
|
|
4583
4586
|
if (hl % 2)
|
|
4584
4587
|
throw new Error("hex string expected, got unpadded hex of length " + hl);
|
|
4585
4588
|
const array = new Uint8Array(al);
|
|
4586
4589
|
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
4587
|
-
const n1 = asciiToBase16(
|
|
4588
|
-
const n2 = asciiToBase16(
|
|
4590
|
+
const n1 = asciiToBase16(hex2.charCodeAt(hi));
|
|
4591
|
+
const n2 = asciiToBase16(hex2.charCodeAt(hi + 1));
|
|
4589
4592
|
if (n1 === void 0 || n2 === void 0) {
|
|
4590
|
-
const char =
|
|
4593
|
+
const char = hex2[hi] + hex2[hi + 1];
|
|
4591
4594
|
throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
|
4592
4595
|
}
|
|
4593
4596
|
array[ai] = n1 * 16 + n2;
|
|
@@ -4628,6 +4631,14 @@ function createHasher(hashCons) {
|
|
|
4628
4631
|
hashC.create = () => hashCons();
|
|
4629
4632
|
return hashC;
|
|
4630
4633
|
}
|
|
4634
|
+
function createXOFer(hashCons) {
|
|
4635
|
+
const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
|
|
4636
|
+
const tmp = hashCons({});
|
|
4637
|
+
hashC.outputLen = tmp.outputLen;
|
|
4638
|
+
hashC.blockLen = tmp.blockLen;
|
|
4639
|
+
hashC.create = (opts) => hashCons(opts);
|
|
4640
|
+
return hashC;
|
|
4641
|
+
}
|
|
4631
4642
|
function randomBytes(bytesLength = 32) {
|
|
4632
4643
|
if (crypto2 && typeof crypto2.getRandomValues === "function") {
|
|
4633
4644
|
return crypto2.getRandomValues(new Uint8Array(bytesLength));
|
|
@@ -4637,12 +4648,13 @@ function randomBytes(bytesLength = 32) {
|
|
|
4637
4648
|
}
|
|
4638
4649
|
throw new Error("crypto.getRandomValues must be defined");
|
|
4639
4650
|
}
|
|
4640
|
-
var isLE, swap32IfBE, hasHexBuiltin, hexes, asciis, Hash;
|
|
4651
|
+
var isLE, swap8IfBE, swap32IfBE, hasHexBuiltin, hexes, asciis, Hash;
|
|
4641
4652
|
var init_utils = __esm({
|
|
4642
4653
|
"../../node_modules/@noble/hashes/esm/utils.js"() {
|
|
4643
4654
|
"use strict";
|
|
4644
4655
|
init_cryptoNode();
|
|
4645
4656
|
isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
|
|
4657
|
+
swap8IfBE = isLE ? (n) => n : (n) => byteSwap(n);
|
|
4646
4658
|
swap32IfBE = isLE ? (u) => u : byteSwap32;
|
|
4647
4659
|
hasHexBuiltin = /* @__PURE__ */ (() => (
|
|
4648
4660
|
// @ts-ignore
|
|
@@ -5212,10 +5224,10 @@ function _abytes2(value, length4, title = "") {
|
|
|
5212
5224
|
}
|
|
5213
5225
|
return value;
|
|
5214
5226
|
}
|
|
5215
|
-
function hexToNumber(
|
|
5216
|
-
if (typeof
|
|
5217
|
-
throw new Error("hex string expected, got " + typeof
|
|
5218
|
-
return
|
|
5227
|
+
function hexToNumber(hex2) {
|
|
5228
|
+
if (typeof hex2 !== "string")
|
|
5229
|
+
throw new Error("hex string expected, got " + typeof hex2);
|
|
5230
|
+
return hex2 === "" ? _0n : BigInt("0x" + hex2);
|
|
5219
5231
|
}
|
|
5220
5232
|
function bytesToNumberBE(bytes) {
|
|
5221
5233
|
return hexToNumber(bytesToHex(bytes));
|
|
@@ -5230,16 +5242,16 @@ function numberToBytesBE(n, len) {
|
|
|
5230
5242
|
function numberToBytesLE(n, len) {
|
|
5231
5243
|
return numberToBytesBE(n, len).reverse();
|
|
5232
5244
|
}
|
|
5233
|
-
function ensureBytes(title,
|
|
5245
|
+
function ensureBytes(title, hex2, expectedLength) {
|
|
5234
5246
|
let res;
|
|
5235
|
-
if (typeof
|
|
5247
|
+
if (typeof hex2 === "string") {
|
|
5236
5248
|
try {
|
|
5237
|
-
res = hexToBytes(
|
|
5249
|
+
res = hexToBytes(hex2);
|
|
5238
5250
|
} catch (e) {
|
|
5239
5251
|
throw new Error(title + " must be hex string or Uint8Array, cause: " + e);
|
|
5240
5252
|
}
|
|
5241
|
-
} else if (isBytes(
|
|
5242
|
-
res = Uint8Array.from(
|
|
5253
|
+
} else if (isBytes(hex2)) {
|
|
5254
|
+
res = Uint8Array.from(hex2);
|
|
5243
5255
|
} else {
|
|
5244
5256
|
throw new Error(title + " must be hex string or Uint8Array");
|
|
5245
5257
|
}
|
|
@@ -5272,11 +5284,11 @@ function bitLen(n) {
|
|
|
5272
5284
|
;
|
|
5273
5285
|
return len;
|
|
5274
5286
|
}
|
|
5275
|
-
function _validateObject(
|
|
5276
|
-
if (!
|
|
5287
|
+
function _validateObject(object2, fields, optFields = {}) {
|
|
5288
|
+
if (!object2 || typeof object2 !== "object")
|
|
5277
5289
|
throw new Error("expected valid options object");
|
|
5278
5290
|
function checkField(fieldName, expectedType, isOpt) {
|
|
5279
|
-
const val =
|
|
5291
|
+
const val = object2[fieldName];
|
|
5280
5292
|
if (isOpt && val === void 0)
|
|
5281
5293
|
return;
|
|
5282
5294
|
const current = typeof val;
|
|
@@ -6616,8 +6628,8 @@ var init_ed25519 = __esm({
|
|
|
6616
6628
|
return new __RistrettoPoint(ep);
|
|
6617
6629
|
}
|
|
6618
6630
|
/** @deprecated use `import { ristretto255_hasher } from '@noble/curves/ed25519.js';` */
|
|
6619
|
-
static hashToCurve(
|
|
6620
|
-
return ristretto255_map(ensureBytes("ristrettoHash",
|
|
6631
|
+
static hashToCurve(hex2) {
|
|
6632
|
+
return ristretto255_map(ensureBytes("ristrettoHash", hex2, 64));
|
|
6621
6633
|
}
|
|
6622
6634
|
static fromBytes(bytes) {
|
|
6623
6635
|
abytes(bytes, 32);
|
|
@@ -6650,8 +6662,8 @@ var init_ed25519 = __esm({
|
|
|
6650
6662
|
* Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-decode).
|
|
6651
6663
|
* @param hex Ristretto-encoded 32 bytes. Not every 32-byte string is valid ristretto encoding
|
|
6652
6664
|
*/
|
|
6653
|
-
static fromHex(
|
|
6654
|
-
return __RistrettoPoint.fromBytes(ensureBytes("ristrettoHex",
|
|
6665
|
+
static fromHex(hex2) {
|
|
6666
|
+
return __RistrettoPoint.fromBytes(ensureBytes("ristrettoHex", hex2, 32));
|
|
6655
6667
|
}
|
|
6656
6668
|
static msm(points, scalars) {
|
|
6657
6669
|
return pippenger(__RistrettoPoint, ed25519.Point.Fn, points, scalars);
|
|
@@ -6862,14 +6874,14 @@ function pad(hexOrBytes, { dir, size: size2 = 32 } = {}) {
|
|
|
6862
6874
|
function padHex(hex_, { dir, size: size2 = 32 } = {}) {
|
|
6863
6875
|
if (size2 === null)
|
|
6864
6876
|
return hex_;
|
|
6865
|
-
const
|
|
6866
|
-
if (
|
|
6877
|
+
const hex2 = hex_.replace("0x", "");
|
|
6878
|
+
if (hex2.length > size2 * 2)
|
|
6867
6879
|
throw new SizeExceedsPaddingSizeError({
|
|
6868
|
-
size: Math.ceil(
|
|
6880
|
+
size: Math.ceil(hex2.length / 2),
|
|
6869
6881
|
targetSize: size2,
|
|
6870
6882
|
type: "hex"
|
|
6871
6883
|
});
|
|
6872
|
-
return `0x${
|
|
6884
|
+
return `0x${hex2[dir === "right" ? "padEnd" : "padStart"](size2 * 2, "0")}`;
|
|
6873
6885
|
}
|
|
6874
6886
|
function padBytes(bytes, { dir, size: size2 = 32 } = {}) {
|
|
6875
6887
|
if (size2 === null)
|
|
@@ -6921,21 +6933,21 @@ function assertSize(hexOrBytes, { size: size2 }) {
|
|
|
6921
6933
|
maxSize: size2
|
|
6922
6934
|
});
|
|
6923
6935
|
}
|
|
6924
|
-
function hexToBigInt(
|
|
6936
|
+
function hexToBigInt(hex2, opts = {}) {
|
|
6925
6937
|
const { signed } = opts;
|
|
6926
6938
|
if (opts.size)
|
|
6927
|
-
assertSize(
|
|
6928
|
-
const value = BigInt(
|
|
6939
|
+
assertSize(hex2, { size: opts.size });
|
|
6940
|
+
const value = BigInt(hex2);
|
|
6929
6941
|
if (!signed)
|
|
6930
6942
|
return value;
|
|
6931
|
-
const size2 = (
|
|
6943
|
+
const size2 = (hex2.length - 2) / 2;
|
|
6932
6944
|
const max = (1n << BigInt(size2) * 8n - 1n) - 1n;
|
|
6933
6945
|
if (value <= max)
|
|
6934
6946
|
return value;
|
|
6935
6947
|
return value - BigInt(`0x${"f".padStart(size2 * 2, "f")}`) - 1n;
|
|
6936
6948
|
}
|
|
6937
|
-
function hexToNumber2(
|
|
6938
|
-
const value = hexToBigInt(
|
|
6949
|
+
function hexToNumber2(hex2, opts = {}) {
|
|
6950
|
+
const value = hexToBigInt(hex2, opts);
|
|
6939
6951
|
const number = Number(value);
|
|
6940
6952
|
if (!Number.isSafeInteger(number))
|
|
6941
6953
|
throw new IntegerOutOfRangeError({
|
|
@@ -6967,24 +6979,24 @@ function toHex(value, opts = {}) {
|
|
|
6967
6979
|
return bytesToHex2(value, opts);
|
|
6968
6980
|
}
|
|
6969
6981
|
function boolToHex(value, opts = {}) {
|
|
6970
|
-
const
|
|
6982
|
+
const hex2 = `0x${Number(value)}`;
|
|
6971
6983
|
if (typeof opts.size === "number") {
|
|
6972
|
-
assertSize(
|
|
6973
|
-
return pad(
|
|
6984
|
+
assertSize(hex2, { size: opts.size });
|
|
6985
|
+
return pad(hex2, { size: opts.size });
|
|
6974
6986
|
}
|
|
6975
|
-
return
|
|
6987
|
+
return hex2;
|
|
6976
6988
|
}
|
|
6977
6989
|
function bytesToHex2(value, opts = {}) {
|
|
6978
6990
|
let string2 = "";
|
|
6979
6991
|
for (let i = 0; i < value.length; i++) {
|
|
6980
6992
|
string2 += hexes2[value[i]];
|
|
6981
6993
|
}
|
|
6982
|
-
const
|
|
6994
|
+
const hex2 = `0x${string2}`;
|
|
6983
6995
|
if (typeof opts.size === "number") {
|
|
6984
|
-
assertSize(
|
|
6985
|
-
return pad(
|
|
6996
|
+
assertSize(hex2, { size: opts.size });
|
|
6997
|
+
return pad(hex2, { dir: "right", size: opts.size });
|
|
6986
6998
|
}
|
|
6987
|
-
return
|
|
6999
|
+
return hex2;
|
|
6988
7000
|
}
|
|
6989
7001
|
function numberToHex(value_, opts = {}) {
|
|
6990
7002
|
const { signed, size: size2 } = opts;
|
|
@@ -7009,10 +7021,10 @@ function numberToHex(value_, opts = {}) {
|
|
|
7009
7021
|
value: `${value_}${suffix}`
|
|
7010
7022
|
});
|
|
7011
7023
|
}
|
|
7012
|
-
const
|
|
7024
|
+
const hex2 = `0x${(signed && value < 0 ? (1n << BigInt(size2 * 8)) + BigInt(value) : value).toString(16)}`;
|
|
7013
7025
|
if (size2)
|
|
7014
|
-
return pad(
|
|
7015
|
-
return
|
|
7026
|
+
return pad(hex2, { size: size2 });
|
|
7027
|
+
return hex2;
|
|
7016
7028
|
}
|
|
7017
7029
|
function stringToHex(value_, opts = {}) {
|
|
7018
7030
|
const value = encoder.encode(value_);
|
|
@@ -7059,12 +7071,12 @@ function charCodeToBase16(char) {
|
|
|
7059
7071
|
return void 0;
|
|
7060
7072
|
}
|
|
7061
7073
|
function hexToBytes2(hex_, opts = {}) {
|
|
7062
|
-
let
|
|
7074
|
+
let hex2 = hex_;
|
|
7063
7075
|
if (opts.size) {
|
|
7064
|
-
assertSize(
|
|
7065
|
-
|
|
7076
|
+
assertSize(hex2, { size: opts.size });
|
|
7077
|
+
hex2 = pad(hex2, { dir: "right", size: opts.size });
|
|
7066
7078
|
}
|
|
7067
|
-
let hexString =
|
|
7079
|
+
let hexString = hex2.slice(2);
|
|
7068
7080
|
if (hexString.length % 2)
|
|
7069
7081
|
hexString = `0${hexString}`;
|
|
7070
7082
|
const length4 = hexString.length / 2;
|
|
@@ -7080,8 +7092,8 @@ function hexToBytes2(hex_, opts = {}) {
|
|
|
7080
7092
|
return bytes;
|
|
7081
7093
|
}
|
|
7082
7094
|
function numberToBytes(value, opts) {
|
|
7083
|
-
const
|
|
7084
|
-
return hexToBytes2(
|
|
7095
|
+
const hex2 = numberToHex(value, opts);
|
|
7096
|
+
return hexToBytes2(hex2);
|
|
7085
7097
|
}
|
|
7086
7098
|
function stringToBytes(value, opts = {}) {
|
|
7087
7099
|
const bytes = encoder2.encode(value);
|
|
@@ -7571,23 +7583,23 @@ function abool(title, value) {
|
|
|
7571
7583
|
throw new Error(title + " boolean expected, got " + value);
|
|
7572
7584
|
}
|
|
7573
7585
|
function numberToHexUnpadded(num2) {
|
|
7574
|
-
const
|
|
7575
|
-
return
|
|
7586
|
+
const hex2 = num2.toString(16);
|
|
7587
|
+
return hex2.length & 1 ? "0" + hex2 : hex2;
|
|
7576
7588
|
}
|
|
7577
|
-
function hexToNumber3(
|
|
7578
|
-
if (typeof
|
|
7579
|
-
throw new Error("hex string expected, got " + typeof
|
|
7580
|
-
return
|
|
7589
|
+
function hexToNumber3(hex2) {
|
|
7590
|
+
if (typeof hex2 !== "string")
|
|
7591
|
+
throw new Error("hex string expected, got " + typeof hex2);
|
|
7592
|
+
return hex2 === "" ? _0n7 : BigInt("0x" + hex2);
|
|
7581
7593
|
}
|
|
7582
7594
|
function bytesToHex3(bytes) {
|
|
7583
7595
|
abytes2(bytes);
|
|
7584
7596
|
if (hasHexBuiltin2)
|
|
7585
7597
|
return bytes.toHex();
|
|
7586
|
-
let
|
|
7598
|
+
let hex2 = "";
|
|
7587
7599
|
for (let i = 0; i < bytes.length; i++) {
|
|
7588
|
-
|
|
7600
|
+
hex2 += hexes3[bytes[i]];
|
|
7589
7601
|
}
|
|
7590
|
-
return
|
|
7602
|
+
return hex2;
|
|
7591
7603
|
}
|
|
7592
7604
|
function asciiToBase162(ch) {
|
|
7593
7605
|
if (ch >= asciis2._0 && ch <= asciis2._9)
|
|
@@ -7598,21 +7610,21 @@ function asciiToBase162(ch) {
|
|
|
7598
7610
|
return ch - (asciis2.a - 10);
|
|
7599
7611
|
return;
|
|
7600
7612
|
}
|
|
7601
|
-
function hexToBytes3(
|
|
7602
|
-
if (typeof
|
|
7603
|
-
throw new Error("hex string expected, got " + typeof
|
|
7613
|
+
function hexToBytes3(hex2) {
|
|
7614
|
+
if (typeof hex2 !== "string")
|
|
7615
|
+
throw new Error("hex string expected, got " + typeof hex2);
|
|
7604
7616
|
if (hasHexBuiltin2)
|
|
7605
|
-
return Uint8Array.fromHex(
|
|
7606
|
-
const hl =
|
|
7617
|
+
return Uint8Array.fromHex(hex2);
|
|
7618
|
+
const hl = hex2.length;
|
|
7607
7619
|
const al = hl / 2;
|
|
7608
7620
|
if (hl % 2)
|
|
7609
7621
|
throw new Error("hex string expected, got unpadded hex of length " + hl);
|
|
7610
7622
|
const array = new Uint8Array(al);
|
|
7611
7623
|
for (let ai = 0, hi = 0; ai < al; ai++, hi += 2) {
|
|
7612
|
-
const n1 = asciiToBase162(
|
|
7613
|
-
const n2 = asciiToBase162(
|
|
7624
|
+
const n1 = asciiToBase162(hex2.charCodeAt(hi));
|
|
7625
|
+
const n2 = asciiToBase162(hex2.charCodeAt(hi + 1));
|
|
7614
7626
|
if (n1 === void 0 || n2 === void 0) {
|
|
7615
|
-
const char =
|
|
7627
|
+
const char = hex2[hi] + hex2[hi + 1];
|
|
7616
7628
|
throw new Error('hex string expected, got non-hex character "' + char + '" at index ' + hi);
|
|
7617
7629
|
}
|
|
7618
7630
|
array[ai] = n1 * 16 + n2;
|
|
@@ -7632,16 +7644,16 @@ function numberToBytesBE2(n, len) {
|
|
|
7632
7644
|
function numberToBytesLE2(n, len) {
|
|
7633
7645
|
return numberToBytesBE2(n, len).reverse();
|
|
7634
7646
|
}
|
|
7635
|
-
function ensureBytes2(title,
|
|
7647
|
+
function ensureBytes2(title, hex2, expectedLength) {
|
|
7636
7648
|
let res;
|
|
7637
|
-
if (typeof
|
|
7649
|
+
if (typeof hex2 === "string") {
|
|
7638
7650
|
try {
|
|
7639
|
-
res = hexToBytes3(
|
|
7651
|
+
res = hexToBytes3(hex2);
|
|
7640
7652
|
} catch (e) {
|
|
7641
7653
|
throw new Error(title + " must be hex string or Uint8Array, cause: " + e);
|
|
7642
7654
|
}
|
|
7643
|
-
} else if (isBytes2(
|
|
7644
|
-
res = Uint8Array.from(
|
|
7655
|
+
} else if (isBytes2(hex2)) {
|
|
7656
|
+
res = Uint8Array.from(hex2);
|
|
7645
7657
|
} else {
|
|
7646
7658
|
throw new Error(title + " must be hex string or Uint8Array");
|
|
7647
7659
|
}
|
|
@@ -7731,15 +7743,15 @@ function createHmacDrbg(hashLen, qByteLen, hmacFn) {
|
|
|
7731
7743
|
};
|
|
7732
7744
|
return genUntil;
|
|
7733
7745
|
}
|
|
7734
|
-
function validateObject2(
|
|
7746
|
+
function validateObject2(object2, validators, optValidators = {}) {
|
|
7735
7747
|
const checkField = (fieldName, type, isOptional) => {
|
|
7736
7748
|
const checkVal = validatorFns[type];
|
|
7737
7749
|
if (typeof checkVal !== "function")
|
|
7738
7750
|
throw new Error("invalid validator function");
|
|
7739
|
-
const val =
|
|
7751
|
+
const val = object2[fieldName];
|
|
7740
7752
|
if (isOptional && val === void 0)
|
|
7741
7753
|
return;
|
|
7742
|
-
if (!checkVal(val,
|
|
7754
|
+
if (!checkVal(val, object2)) {
|
|
7743
7755
|
throw new Error("param " + String(fieldName) + " is invalid. Expected " + type + ", got " + val);
|
|
7744
7756
|
}
|
|
7745
7757
|
};
|
|
@@ -7747,7 +7759,7 @@ function validateObject2(object, validators, optValidators = {}) {
|
|
|
7747
7759
|
checkField(fieldName, type, false);
|
|
7748
7760
|
for (const [fieldName, type] of Object.entries(optValidators))
|
|
7749
7761
|
checkField(fieldName, type, true);
|
|
7750
|
-
return
|
|
7762
|
+
return object2;
|
|
7751
7763
|
}
|
|
7752
7764
|
function memoized2(fn) {
|
|
7753
7765
|
const map = /* @__PURE__ */ new WeakMap();
|
|
@@ -7782,7 +7794,7 @@ var init_utils3 = __esm({
|
|
|
7782
7794
|
stringOrUint8Array: (val) => typeof val === "string" || isBytes2(val),
|
|
7783
7795
|
isSafeInteger: (val) => Number.isSafeInteger(val),
|
|
7784
7796
|
array: (val) => Array.isArray(val),
|
|
7785
|
-
field: (val,
|
|
7797
|
+
field: (val, object2) => object2.Fp.isValid(val),
|
|
7786
7798
|
hash: (val) => typeof val === "function" && Number.isSafeInteger(val.outputLen)
|
|
7787
7799
|
};
|
|
7788
7800
|
}
|
|
@@ -8482,8 +8494,8 @@ function weierstrassPoints(opts) {
|
|
|
8482
8494
|
* Converts hash string or Uint8Array to Point.
|
|
8483
8495
|
* @param hex short/long ECDSA hex
|
|
8484
8496
|
*/
|
|
8485
|
-
static fromHex(
|
|
8486
|
-
const P = Point2.fromAffine(fromBytes2(ensureBytes2("pointHex",
|
|
8497
|
+
static fromHex(hex2) {
|
|
8498
|
+
const P = Point2.fromAffine(fromBytes2(ensureBytes2("pointHex", hex2)));
|
|
8487
8499
|
P.assertValidity();
|
|
8488
8500
|
return P;
|
|
8489
8501
|
}
|
|
@@ -8838,15 +8850,15 @@ function weierstrass(curveDef) {
|
|
|
8838
8850
|
Object.freeze(this);
|
|
8839
8851
|
}
|
|
8840
8852
|
// pair (bytes of r, bytes of s)
|
|
8841
|
-
static fromCompact(
|
|
8853
|
+
static fromCompact(hex2) {
|
|
8842
8854
|
const l = nByteLength;
|
|
8843
|
-
|
|
8844
|
-
return new Signature(slcNum(
|
|
8855
|
+
hex2 = ensureBytes2("compactSignature", hex2, l * 2);
|
|
8856
|
+
return new Signature(slcNum(hex2, 0, l), slcNum(hex2, l, 2 * l));
|
|
8845
8857
|
}
|
|
8846
8858
|
// DER encoded ECDSA signature
|
|
8847
8859
|
// https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
|
|
8848
|
-
static fromDER(
|
|
8849
|
-
const { r, s } = DER.toSig(ensureBytes2("DER",
|
|
8860
|
+
static fromDER(hex2) {
|
|
8861
|
+
const { r, s } = DER.toSig(ensureBytes2("DER", hex2));
|
|
8850
8862
|
return new Signature(r, s);
|
|
8851
8863
|
}
|
|
8852
8864
|
/**
|
|
@@ -9263,12 +9275,12 @@ var init_weierstrass = __esm({
|
|
|
9263
9275
|
const { Err: E } = DER;
|
|
9264
9276
|
if (num2 < _0n10)
|
|
9265
9277
|
throw new E("integer: negative integers are not allowed");
|
|
9266
|
-
let
|
|
9267
|
-
if (Number.parseInt(
|
|
9268
|
-
|
|
9269
|
-
if (
|
|
9278
|
+
let hex2 = numberToHexUnpadded(num2);
|
|
9279
|
+
if (Number.parseInt(hex2[0], 16) & 8)
|
|
9280
|
+
hex2 = "00" + hex2;
|
|
9281
|
+
if (hex2.length & 1)
|
|
9270
9282
|
throw new E("unexpected DER parsing assertion: unpadded hex");
|
|
9271
|
-
return
|
|
9283
|
+
return hex2;
|
|
9272
9284
|
},
|
|
9273
9285
|
decode(data) {
|
|
9274
9286
|
const { Err: E } = DER;
|
|
@@ -9279,9 +9291,9 @@ var init_weierstrass = __esm({
|
|
|
9279
9291
|
return bytesToNumberBE2(data);
|
|
9280
9292
|
}
|
|
9281
9293
|
},
|
|
9282
|
-
toSig(
|
|
9294
|
+
toSig(hex2) {
|
|
9283
9295
|
const { Err: E, _int: int, _tlv: tlv } = DER;
|
|
9284
|
-
const data = ensureBytes2("signature",
|
|
9296
|
+
const data = ensureBytes2("signature", hex2);
|
|
9285
9297
|
const { v: seqBytes, l: seqLeftBytes } = tlv.decode(48, data);
|
|
9286
9298
|
if (seqLeftBytes.length)
|
|
9287
9299
|
throw new E("invalid signature: left bytes after parsing");
|
|
@@ -9768,6 +9780,16 @@ var init_recoverAddress = __esm({
|
|
|
9768
9780
|
}
|
|
9769
9781
|
});
|
|
9770
9782
|
|
|
9783
|
+
// ../../node_modules/@noble/hashes/esm/sha256.js
|
|
9784
|
+
var sha2562;
|
|
9785
|
+
var init_sha256 = __esm({
|
|
9786
|
+
"../../node_modules/@noble/hashes/esm/sha256.js"() {
|
|
9787
|
+
"use strict";
|
|
9788
|
+
init_sha2();
|
|
9789
|
+
sha2562 = sha256;
|
|
9790
|
+
}
|
|
9791
|
+
});
|
|
9792
|
+
|
|
9771
9793
|
// ../../node_modules/viem/_esm/utils/address/isAddressEqual.js
|
|
9772
9794
|
function isAddressEqual(a, b) {
|
|
9773
9795
|
if (!isAddress(a, { strict: false }))
|
|
@@ -9860,6 +9882,358 @@ var init_esm = __esm({
|
|
|
9860
9882
|
}
|
|
9861
9883
|
});
|
|
9862
9884
|
|
|
9885
|
+
// ../../node_modules/@noble/hashes/esm/_blake.js
|
|
9886
|
+
function G1s(a, b, c, d, x) {
|
|
9887
|
+
a = a + b + x | 0;
|
|
9888
|
+
d = rotr(d ^ a, 16);
|
|
9889
|
+
c = c + d | 0;
|
|
9890
|
+
b = rotr(b ^ c, 12);
|
|
9891
|
+
return { a, b, c, d };
|
|
9892
|
+
}
|
|
9893
|
+
function G2s(a, b, c, d, x) {
|
|
9894
|
+
a = a + b + x | 0;
|
|
9895
|
+
d = rotr(d ^ a, 8);
|
|
9896
|
+
c = c + d | 0;
|
|
9897
|
+
b = rotr(b ^ c, 7);
|
|
9898
|
+
return { a, b, c, d };
|
|
9899
|
+
}
|
|
9900
|
+
var init_blake = __esm({
|
|
9901
|
+
"../../node_modules/@noble/hashes/esm/_blake.js"() {
|
|
9902
|
+
"use strict";
|
|
9903
|
+
init_utils();
|
|
9904
|
+
}
|
|
9905
|
+
});
|
|
9906
|
+
|
|
9907
|
+
// ../../node_modules/@noble/hashes/esm/blake2.js
|
|
9908
|
+
function compress(s, offset, msg, rounds, v0, v1, v2, v3, v42, v5, v62, v7, v8, v9, v10, v11, v12, v13, v14, v15) {
|
|
9909
|
+
let j = 0;
|
|
9910
|
+
for (let i = 0; i < rounds; i++) {
|
|
9911
|
+
({ a: v0, b: v42, c: v8, d: v12 } = G1s(v0, v42, v8, v12, msg[offset + s[j++]]));
|
|
9912
|
+
({ a: v0, b: v42, c: v8, d: v12 } = G2s(v0, v42, v8, v12, msg[offset + s[j++]]));
|
|
9913
|
+
({ a: v1, b: v5, c: v9, d: v13 } = G1s(v1, v5, v9, v13, msg[offset + s[j++]]));
|
|
9914
|
+
({ a: v1, b: v5, c: v9, d: v13 } = G2s(v1, v5, v9, v13, msg[offset + s[j++]]));
|
|
9915
|
+
({ a: v2, b: v62, c: v10, d: v14 } = G1s(v2, v62, v10, v14, msg[offset + s[j++]]));
|
|
9916
|
+
({ a: v2, b: v62, c: v10, d: v14 } = G2s(v2, v62, v10, v14, msg[offset + s[j++]]));
|
|
9917
|
+
({ a: v3, b: v7, c: v11, d: v15 } = G1s(v3, v7, v11, v15, msg[offset + s[j++]]));
|
|
9918
|
+
({ a: v3, b: v7, c: v11, d: v15 } = G2s(v3, v7, v11, v15, msg[offset + s[j++]]));
|
|
9919
|
+
({ a: v0, b: v5, c: v10, d: v15 } = G1s(v0, v5, v10, v15, msg[offset + s[j++]]));
|
|
9920
|
+
({ a: v0, b: v5, c: v10, d: v15 } = G2s(v0, v5, v10, v15, msg[offset + s[j++]]));
|
|
9921
|
+
({ a: v1, b: v62, c: v11, d: v12 } = G1s(v1, v62, v11, v12, msg[offset + s[j++]]));
|
|
9922
|
+
({ a: v1, b: v62, c: v11, d: v12 } = G2s(v1, v62, v11, v12, msg[offset + s[j++]]));
|
|
9923
|
+
({ a: v2, b: v7, c: v8, d: v13 } = G1s(v2, v7, v8, v13, msg[offset + s[j++]]));
|
|
9924
|
+
({ a: v2, b: v7, c: v8, d: v13 } = G2s(v2, v7, v8, v13, msg[offset + s[j++]]));
|
|
9925
|
+
({ a: v3, b: v42, c: v9, d: v14 } = G1s(v3, v42, v9, v14, msg[offset + s[j++]]));
|
|
9926
|
+
({ a: v3, b: v42, c: v9, d: v14 } = G2s(v3, v42, v9, v14, msg[offset + s[j++]]));
|
|
9927
|
+
}
|
|
9928
|
+
return { v0, v1, v2, v3, v4: v42, v5, v6: v62, v7, v8, v9, v10, v11, v12, v13, v14, v15 };
|
|
9929
|
+
}
|
|
9930
|
+
var BLAKE2;
|
|
9931
|
+
var init_blake2 = __esm({
|
|
9932
|
+
"../../node_modules/@noble/hashes/esm/blake2.js"() {
|
|
9933
|
+
"use strict";
|
|
9934
|
+
init_blake();
|
|
9935
|
+
init_utils();
|
|
9936
|
+
BLAKE2 = class extends Hash {
|
|
9937
|
+
constructor(blockLen, outputLen) {
|
|
9938
|
+
super();
|
|
9939
|
+
this.finished = false;
|
|
9940
|
+
this.destroyed = false;
|
|
9941
|
+
this.length = 0;
|
|
9942
|
+
this.pos = 0;
|
|
9943
|
+
anumber(blockLen);
|
|
9944
|
+
anumber(outputLen);
|
|
9945
|
+
this.blockLen = blockLen;
|
|
9946
|
+
this.outputLen = outputLen;
|
|
9947
|
+
this.buffer = new Uint8Array(blockLen);
|
|
9948
|
+
this.buffer32 = u32(this.buffer);
|
|
9949
|
+
}
|
|
9950
|
+
update(data) {
|
|
9951
|
+
aexists(this);
|
|
9952
|
+
data = toBytes(data);
|
|
9953
|
+
abytes(data);
|
|
9954
|
+
const { blockLen, buffer, buffer32 } = this;
|
|
9955
|
+
const len = data.length;
|
|
9956
|
+
const offset = data.byteOffset;
|
|
9957
|
+
const buf = data.buffer;
|
|
9958
|
+
for (let pos = 0; pos < len; ) {
|
|
9959
|
+
if (this.pos === blockLen) {
|
|
9960
|
+
swap32IfBE(buffer32);
|
|
9961
|
+
this.compress(buffer32, 0, false);
|
|
9962
|
+
swap32IfBE(buffer32);
|
|
9963
|
+
this.pos = 0;
|
|
9964
|
+
}
|
|
9965
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
9966
|
+
const dataOffset = offset + pos;
|
|
9967
|
+
if (take === blockLen && !(dataOffset % 4) && pos + take < len) {
|
|
9968
|
+
const data32 = new Uint32Array(buf, dataOffset, Math.floor((len - pos) / 4));
|
|
9969
|
+
swap32IfBE(data32);
|
|
9970
|
+
for (let pos32 = 0; pos + blockLen < len; pos32 += buffer32.length, pos += blockLen) {
|
|
9971
|
+
this.length += blockLen;
|
|
9972
|
+
this.compress(data32, pos32, false);
|
|
9973
|
+
}
|
|
9974
|
+
swap32IfBE(data32);
|
|
9975
|
+
continue;
|
|
9976
|
+
}
|
|
9977
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
9978
|
+
this.pos += take;
|
|
9979
|
+
this.length += take;
|
|
9980
|
+
pos += take;
|
|
9981
|
+
}
|
|
9982
|
+
return this;
|
|
9983
|
+
}
|
|
9984
|
+
digestInto(out) {
|
|
9985
|
+
aexists(this);
|
|
9986
|
+
aoutput(out, this);
|
|
9987
|
+
const { pos, buffer32 } = this;
|
|
9988
|
+
this.finished = true;
|
|
9989
|
+
clean(this.buffer.subarray(pos));
|
|
9990
|
+
swap32IfBE(buffer32);
|
|
9991
|
+
this.compress(buffer32, 0, true);
|
|
9992
|
+
swap32IfBE(buffer32);
|
|
9993
|
+
const out32 = u32(out);
|
|
9994
|
+
this.get().forEach((v, i) => out32[i] = swap8IfBE(v));
|
|
9995
|
+
}
|
|
9996
|
+
digest() {
|
|
9997
|
+
const { buffer, outputLen } = this;
|
|
9998
|
+
this.digestInto(buffer);
|
|
9999
|
+
const res = buffer.slice(0, outputLen);
|
|
10000
|
+
this.destroy();
|
|
10001
|
+
return res;
|
|
10002
|
+
}
|
|
10003
|
+
_cloneInto(to) {
|
|
10004
|
+
const { buffer, length: length4, finished, destroyed, outputLen, pos } = this;
|
|
10005
|
+
to || (to = new this.constructor({ dkLen: outputLen }));
|
|
10006
|
+
to.set(...this.get());
|
|
10007
|
+
to.buffer.set(buffer);
|
|
10008
|
+
to.destroyed = destroyed;
|
|
10009
|
+
to.finished = finished;
|
|
10010
|
+
to.length = length4;
|
|
10011
|
+
to.pos = pos;
|
|
10012
|
+
to.outputLen = outputLen;
|
|
10013
|
+
return to;
|
|
10014
|
+
}
|
|
10015
|
+
clone() {
|
|
10016
|
+
return this._cloneInto();
|
|
10017
|
+
}
|
|
10018
|
+
};
|
|
10019
|
+
}
|
|
10020
|
+
});
|
|
10021
|
+
|
|
10022
|
+
// ../../node_modules/@noble/hashes/esm/blake3.js
|
|
10023
|
+
var B3_Flags, B3_IV, B3_SIGMA, BLAKE3, blake3;
|
|
10024
|
+
var init_blake3 = __esm({
|
|
10025
|
+
"../../node_modules/@noble/hashes/esm/blake3.js"() {
|
|
10026
|
+
"use strict";
|
|
10027
|
+
init_md();
|
|
10028
|
+
init_u64();
|
|
10029
|
+
init_blake2();
|
|
10030
|
+
init_utils();
|
|
10031
|
+
B3_Flags = {
|
|
10032
|
+
CHUNK_START: 1,
|
|
10033
|
+
CHUNK_END: 2,
|
|
10034
|
+
PARENT: 4,
|
|
10035
|
+
ROOT: 8,
|
|
10036
|
+
KEYED_HASH: 16,
|
|
10037
|
+
DERIVE_KEY_CONTEXT: 32,
|
|
10038
|
+
DERIVE_KEY_MATERIAL: 64
|
|
10039
|
+
};
|
|
10040
|
+
B3_IV = SHA256_IV.slice();
|
|
10041
|
+
B3_SIGMA = /* @__PURE__ */ (() => {
|
|
10042
|
+
const Id = Array.from({ length: 16 }, (_, i) => i);
|
|
10043
|
+
const permute = (arr) => [2, 6, 3, 10, 7, 0, 4, 13, 1, 11, 12, 5, 9, 14, 15, 8].map((i) => arr[i]);
|
|
10044
|
+
const res = [];
|
|
10045
|
+
for (let i = 0, v = Id; i < 7; i++, v = permute(v))
|
|
10046
|
+
res.push(...v);
|
|
10047
|
+
return Uint8Array.from(res);
|
|
10048
|
+
})();
|
|
10049
|
+
BLAKE3 = class _BLAKE3 extends BLAKE2 {
|
|
10050
|
+
constructor(opts = {}, flags = 0) {
|
|
10051
|
+
super(64, opts.dkLen === void 0 ? 32 : opts.dkLen);
|
|
10052
|
+
this.chunkPos = 0;
|
|
10053
|
+
this.chunksDone = 0;
|
|
10054
|
+
this.flags = 0 | 0;
|
|
10055
|
+
this.stack = [];
|
|
10056
|
+
this.posOut = 0;
|
|
10057
|
+
this.bufferOut32 = new Uint32Array(16);
|
|
10058
|
+
this.chunkOut = 0;
|
|
10059
|
+
this.enableXOF = true;
|
|
10060
|
+
const { key, context } = opts;
|
|
10061
|
+
const hasContext = context !== void 0;
|
|
10062
|
+
if (key !== void 0) {
|
|
10063
|
+
if (hasContext)
|
|
10064
|
+
throw new Error('Only "key" or "context" can be specified at same time');
|
|
10065
|
+
const k = toBytes(key).slice();
|
|
10066
|
+
abytes(k, 32);
|
|
10067
|
+
this.IV = u32(k);
|
|
10068
|
+
swap32IfBE(this.IV);
|
|
10069
|
+
this.flags = flags | B3_Flags.KEYED_HASH;
|
|
10070
|
+
} else if (hasContext) {
|
|
10071
|
+
const ctx = toBytes(context);
|
|
10072
|
+
const contextKey = new _BLAKE3({ dkLen: 32 }, B3_Flags.DERIVE_KEY_CONTEXT).update(ctx).digest();
|
|
10073
|
+
this.IV = u32(contextKey);
|
|
10074
|
+
swap32IfBE(this.IV);
|
|
10075
|
+
this.flags = flags | B3_Flags.DERIVE_KEY_MATERIAL;
|
|
10076
|
+
} else {
|
|
10077
|
+
this.IV = B3_IV.slice();
|
|
10078
|
+
this.flags = flags;
|
|
10079
|
+
}
|
|
10080
|
+
this.state = this.IV.slice();
|
|
10081
|
+
this.bufferOut = u8(this.bufferOut32);
|
|
10082
|
+
}
|
|
10083
|
+
// Unused
|
|
10084
|
+
get() {
|
|
10085
|
+
return [];
|
|
10086
|
+
}
|
|
10087
|
+
set() {
|
|
10088
|
+
}
|
|
10089
|
+
b2Compress(counter, flags, buf, bufPos = 0) {
|
|
10090
|
+
const { state: s, pos } = this;
|
|
10091
|
+
const { h, l } = fromBig(BigInt(counter), true);
|
|
10092
|
+
const { v0, v1, v2, v3, v4: v42, v5, v6: v62, v7, v8, v9, v10, v11, v12, v13, v14, v15 } = compress(B3_SIGMA, bufPos, buf, 7, s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], B3_IV[0], B3_IV[1], B3_IV[2], B3_IV[3], h, l, pos, flags);
|
|
10093
|
+
s[0] = v0 ^ v8;
|
|
10094
|
+
s[1] = v1 ^ v9;
|
|
10095
|
+
s[2] = v2 ^ v10;
|
|
10096
|
+
s[3] = v3 ^ v11;
|
|
10097
|
+
s[4] = v42 ^ v12;
|
|
10098
|
+
s[5] = v5 ^ v13;
|
|
10099
|
+
s[6] = v62 ^ v14;
|
|
10100
|
+
s[7] = v7 ^ v15;
|
|
10101
|
+
}
|
|
10102
|
+
compress(buf, bufPos = 0, isLast = false) {
|
|
10103
|
+
let flags = this.flags;
|
|
10104
|
+
if (!this.chunkPos)
|
|
10105
|
+
flags |= B3_Flags.CHUNK_START;
|
|
10106
|
+
if (this.chunkPos === 15 || isLast)
|
|
10107
|
+
flags |= B3_Flags.CHUNK_END;
|
|
10108
|
+
if (!isLast)
|
|
10109
|
+
this.pos = this.blockLen;
|
|
10110
|
+
this.b2Compress(this.chunksDone, flags, buf, bufPos);
|
|
10111
|
+
this.chunkPos += 1;
|
|
10112
|
+
if (this.chunkPos === 16 || isLast) {
|
|
10113
|
+
let chunk = this.state;
|
|
10114
|
+
this.state = this.IV.slice();
|
|
10115
|
+
for (let last, chunks = this.chunksDone + 1; isLast || !(chunks & 1); chunks >>= 1) {
|
|
10116
|
+
if (!(last = this.stack.pop()))
|
|
10117
|
+
break;
|
|
10118
|
+
this.buffer32.set(last, 0);
|
|
10119
|
+
this.buffer32.set(chunk, 8);
|
|
10120
|
+
this.pos = this.blockLen;
|
|
10121
|
+
this.b2Compress(0, this.flags | B3_Flags.PARENT, this.buffer32, 0);
|
|
10122
|
+
chunk = this.state;
|
|
10123
|
+
this.state = this.IV.slice();
|
|
10124
|
+
}
|
|
10125
|
+
this.chunksDone++;
|
|
10126
|
+
this.chunkPos = 0;
|
|
10127
|
+
this.stack.push(chunk);
|
|
10128
|
+
}
|
|
10129
|
+
this.pos = 0;
|
|
10130
|
+
}
|
|
10131
|
+
_cloneInto(to) {
|
|
10132
|
+
to = super._cloneInto(to);
|
|
10133
|
+
const { IV, flags, state, chunkPos, posOut, chunkOut, stack, chunksDone } = this;
|
|
10134
|
+
to.state.set(state.slice());
|
|
10135
|
+
to.stack = stack.map((i) => Uint32Array.from(i));
|
|
10136
|
+
to.IV.set(IV);
|
|
10137
|
+
to.flags = flags;
|
|
10138
|
+
to.chunkPos = chunkPos;
|
|
10139
|
+
to.chunksDone = chunksDone;
|
|
10140
|
+
to.posOut = posOut;
|
|
10141
|
+
to.chunkOut = chunkOut;
|
|
10142
|
+
to.enableXOF = this.enableXOF;
|
|
10143
|
+
to.bufferOut32.set(this.bufferOut32);
|
|
10144
|
+
return to;
|
|
10145
|
+
}
|
|
10146
|
+
destroy() {
|
|
10147
|
+
this.destroyed = true;
|
|
10148
|
+
clean(this.state, this.buffer32, this.IV, this.bufferOut32);
|
|
10149
|
+
clean(...this.stack);
|
|
10150
|
+
}
|
|
10151
|
+
// Same as b2Compress, but doesn't modify state and returns 16 u32 array (instead of 8)
|
|
10152
|
+
b2CompressOut() {
|
|
10153
|
+
const { state: s, pos, flags, buffer32, bufferOut32: out32 } = this;
|
|
10154
|
+
const { h, l } = fromBig(BigInt(this.chunkOut++));
|
|
10155
|
+
swap32IfBE(buffer32);
|
|
10156
|
+
const { v0, v1, v2, v3, v4: v42, v5, v6: v62, v7, v8, v9, v10, v11, v12, v13, v14, v15 } = compress(B3_SIGMA, 0, buffer32, 7, s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], B3_IV[0], B3_IV[1], B3_IV[2], B3_IV[3], l, h, pos, flags);
|
|
10157
|
+
out32[0] = v0 ^ v8;
|
|
10158
|
+
out32[1] = v1 ^ v9;
|
|
10159
|
+
out32[2] = v2 ^ v10;
|
|
10160
|
+
out32[3] = v3 ^ v11;
|
|
10161
|
+
out32[4] = v42 ^ v12;
|
|
10162
|
+
out32[5] = v5 ^ v13;
|
|
10163
|
+
out32[6] = v62 ^ v14;
|
|
10164
|
+
out32[7] = v7 ^ v15;
|
|
10165
|
+
out32[8] = s[0] ^ v8;
|
|
10166
|
+
out32[9] = s[1] ^ v9;
|
|
10167
|
+
out32[10] = s[2] ^ v10;
|
|
10168
|
+
out32[11] = s[3] ^ v11;
|
|
10169
|
+
out32[12] = s[4] ^ v12;
|
|
10170
|
+
out32[13] = s[5] ^ v13;
|
|
10171
|
+
out32[14] = s[6] ^ v14;
|
|
10172
|
+
out32[15] = s[7] ^ v15;
|
|
10173
|
+
swap32IfBE(buffer32);
|
|
10174
|
+
swap32IfBE(out32);
|
|
10175
|
+
this.posOut = 0;
|
|
10176
|
+
}
|
|
10177
|
+
finish() {
|
|
10178
|
+
if (this.finished)
|
|
10179
|
+
return;
|
|
10180
|
+
this.finished = true;
|
|
10181
|
+
clean(this.buffer.subarray(this.pos));
|
|
10182
|
+
let flags = this.flags | B3_Flags.ROOT;
|
|
10183
|
+
if (this.stack.length) {
|
|
10184
|
+
flags |= B3_Flags.PARENT;
|
|
10185
|
+
swap32IfBE(this.buffer32);
|
|
10186
|
+
this.compress(this.buffer32, 0, true);
|
|
10187
|
+
swap32IfBE(this.buffer32);
|
|
10188
|
+
this.chunksDone = 0;
|
|
10189
|
+
this.pos = this.blockLen;
|
|
10190
|
+
} else {
|
|
10191
|
+
flags |= (!this.chunkPos ? B3_Flags.CHUNK_START : 0) | B3_Flags.CHUNK_END;
|
|
10192
|
+
}
|
|
10193
|
+
this.flags = flags;
|
|
10194
|
+
this.b2CompressOut();
|
|
10195
|
+
}
|
|
10196
|
+
writeInto(out) {
|
|
10197
|
+
aexists(this, false);
|
|
10198
|
+
abytes(out);
|
|
10199
|
+
this.finish();
|
|
10200
|
+
const { blockLen, bufferOut } = this;
|
|
10201
|
+
for (let pos = 0, len = out.length; pos < len; ) {
|
|
10202
|
+
if (this.posOut >= blockLen)
|
|
10203
|
+
this.b2CompressOut();
|
|
10204
|
+
const take = Math.min(blockLen - this.posOut, len - pos);
|
|
10205
|
+
out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
|
|
10206
|
+
this.posOut += take;
|
|
10207
|
+
pos += take;
|
|
10208
|
+
}
|
|
10209
|
+
return out;
|
|
10210
|
+
}
|
|
10211
|
+
xofInto(out) {
|
|
10212
|
+
if (!this.enableXOF)
|
|
10213
|
+
throw new Error("XOF is not possible after digest call");
|
|
10214
|
+
return this.writeInto(out);
|
|
10215
|
+
}
|
|
10216
|
+
xof(bytes) {
|
|
10217
|
+
anumber(bytes);
|
|
10218
|
+
return this.xofInto(new Uint8Array(bytes));
|
|
10219
|
+
}
|
|
10220
|
+
digestInto(out) {
|
|
10221
|
+
aoutput(out, this);
|
|
10222
|
+
if (this.finished)
|
|
10223
|
+
throw new Error("digest() was already called");
|
|
10224
|
+
this.enableXOF = false;
|
|
10225
|
+
this.writeInto(out);
|
|
10226
|
+
this.destroy();
|
|
10227
|
+
return out;
|
|
10228
|
+
}
|
|
10229
|
+
digest() {
|
|
10230
|
+
return this.digestInto(new Uint8Array(this.outputLen));
|
|
10231
|
+
}
|
|
10232
|
+
};
|
|
10233
|
+
blake3 = /* @__PURE__ */ createXOFer((opts) => new BLAKE3(opts));
|
|
10234
|
+
}
|
|
10235
|
+
});
|
|
10236
|
+
|
|
9863
10237
|
// ../bootstrap/dist/index.js
|
|
9864
10238
|
function actionKey(action) {
|
|
9865
10239
|
if (action === "*") return "ALL";
|
|
@@ -16421,7 +16795,10 @@ var init_dist2 = __esm({
|
|
|
16421
16795
|
const descriptor = usable.data;
|
|
16422
16796
|
const networkPublicKey = base64Decode2(descriptor.publicEncryptionKey);
|
|
16423
16797
|
const result = encryptToNetwork(this.crypto, {
|
|
16424
|
-
|
|
16798
|
+
// Discovery returns the node's canonical network identifier. Persist
|
|
16799
|
+
// that spelling in the envelope so a later response can be compared
|
|
16800
|
+
// byte-for-byte (notably for checksummed did:pkh principals).
|
|
16801
|
+
networkId: descriptor.networkId,
|
|
16425
16802
|
networkPublicKey,
|
|
16426
16803
|
plaintext,
|
|
16427
16804
|
...options?.aad !== void 0 ? { aad: options.aad } : {},
|
|
@@ -17654,6 +18031,49 @@ function serialize(value) {
|
|
|
17654
18031
|
function canonicalize2(value) {
|
|
17655
18032
|
return serialize(value);
|
|
17656
18033
|
}
|
|
18034
|
+
function verifyCompactUcanAuthorization(authorization, expectedCid) {
|
|
18035
|
+
if (/\s/.test(authorization)) throw new TypeError("compact Authorization contains whitespace");
|
|
18036
|
+
const segments = authorization.split(".");
|
|
18037
|
+
if (segments.length !== 3 || segments.some((segment) => segment.length === 0)) throw new TypeError("compact Authorization must contain three segments");
|
|
18038
|
+
const [headerSegment, payloadSegment, signatureSegment] = segments;
|
|
18039
|
+
const headerBytes = decodeBase64Url(headerSegment);
|
|
18040
|
+
const payloadBytes = decodeBase64Url(payloadSegment);
|
|
18041
|
+
const signature = decodeBase64Url(signatureSegment);
|
|
18042
|
+
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
18043
|
+
const header = JSON.parse(decoder.decode(headerBytes));
|
|
18044
|
+
const payload = JSON.parse(decoder.decode(payloadBytes));
|
|
18045
|
+
if (canonicalize2(header) !== decoder.decode(headerBytes) || canonicalize2(payload) !== decoder.decode(payloadBytes)) throw new TypeError("compact Authorization JSON is not canonical");
|
|
18046
|
+
assertExactKeys(header, ["alg", "jwk", "typ", "ucv"], "protected header");
|
|
18047
|
+
const jwk = object(header.jwk, "protected JWK");
|
|
18048
|
+
assertExactKeys(jwk, ["alg", "crv", "kty", "x"], "protected JWK");
|
|
18049
|
+
if (header.alg !== "EdDSA" || header.typ !== "JWT" || header.ucv !== "0.10.0" || jwk.alg !== "EdDSA" || jwk.crv !== "Ed25519" || jwk.kty !== "OKP" || typeof jwk.x !== "string") throw new TypeError("compact Authorization header is invalid");
|
|
18050
|
+
assertExactKeys(payload, ["att", "aud", "exp", "fct", "iss", "nbf", "nnc", "prf"], "UCAN payload");
|
|
18051
|
+
if (typeof payload.iss !== "string" || typeof payload.aud !== "string" || typeof payload.nnc !== "string" || !Number.isInteger(payload.nbf) || !Number.isInteger(payload.exp) || payload.nbf >= payload.exp || !Array.isArray(payload.prf) || payload.prf.some((proof) => typeof proof !== "string") || !Array.isArray(payload.fct) || payload.fct.length !== 1) throw new TypeError("compact Authorization payload is invalid");
|
|
18052
|
+
const principal = payload.iss.split("#", 1)[0];
|
|
18053
|
+
const publicKey = ed25519PublicKeyFromDidKey(principal);
|
|
18054
|
+
if (!equal(publicKey, decodeBase64Url(jwk.x))) throw new TypeError("compact Authorization JWK does not bind issuer");
|
|
18055
|
+
if (!ed25519.verify(signature, new TextEncoder().encode(`${headerSegment}.${payloadSegment}`), publicKey, { zip215: false })) throw new TypeError("compact Authorization signature is invalid");
|
|
18056
|
+
const cid2 = CID.createV1(85, create(30, blake3(new TextEncoder().encode(authorization)))).toString();
|
|
18057
|
+
if (expectedCid !== void 0 && cid2 !== expectedCid) throw new TypeError("compact Authorization CID mismatch");
|
|
18058
|
+
return { authorization, cid: cid2, header, payload };
|
|
18059
|
+
}
|
|
18060
|
+
function object(value, label) {
|
|
18061
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) throw new TypeError(`${label} must be an object`);
|
|
18062
|
+
return value;
|
|
18063
|
+
}
|
|
18064
|
+
function assertExactKeys(value, keys, label) {
|
|
18065
|
+
if (Object.keys(value).length !== keys.length || Object.keys(value).some((key) => !keys.includes(key))) throw new TypeError(`${label} has unknown or missing fields`);
|
|
18066
|
+
}
|
|
18067
|
+
function decodeBase64Url(value) {
|
|
18068
|
+
if (!/^[A-Za-z0-9_-]+$/.test(value) || value.length % 4 === 1) throw new TypeError("compact Authorization segment is not base64url");
|
|
18069
|
+
const bytes3 = typeof Buffer !== "undefined" ? new Uint8Array(Buffer.from(value, "base64url")) : Uint8Array.from(atob(value.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(value.length / 4) * 4, "=")), (character) => character.charCodeAt(0));
|
|
18070
|
+
const encoded = typeof Buffer !== "undefined" ? Buffer.from(bytes3).toString("base64url") : btoa(String.fromCharCode(...bytes3)).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
18071
|
+
if (encoded !== value) throw new TypeError("compact Authorization segment is not canonical");
|
|
18072
|
+
return bytes3;
|
|
18073
|
+
}
|
|
18074
|
+
function equal(left, right) {
|
|
18075
|
+
return left.length === right.length && left.every((byte, index) => byte === right[index]);
|
|
18076
|
+
}
|
|
17657
18077
|
function signingBytes(unsigned) {
|
|
17658
18078
|
const domain = utf8Bytes(ENVELOPE_SIGNATURE_DOMAIN);
|
|
17659
18079
|
const body = utf8Bytes(canonicalize2(unsigned));
|
|
@@ -17670,6 +18090,14 @@ function signingBytesV2(unsigned) {
|
|
|
17670
18090
|
bytes3.set(body, domain.length);
|
|
17671
18091
|
return bytes3;
|
|
17672
18092
|
}
|
|
18093
|
+
function signingBytesV3(unsigned) {
|
|
18094
|
+
const domain = utf8Bytes(ENVELOPE_V3_SIGNATURE_DOMAIN);
|
|
18095
|
+
const body = utf8Bytes(canonicalize2(unsigned));
|
|
18096
|
+
const bytes3 = new Uint8Array(domain.length + body.length);
|
|
18097
|
+
bytes3.set(domain);
|
|
18098
|
+
bytes3.set(body, domain.length);
|
|
18099
|
+
return bytes3;
|
|
18100
|
+
}
|
|
17673
18101
|
function signEnvelope(envelopeWithoutSig, ed25519PrivKey) {
|
|
17674
18102
|
const unsigned = unsignedShareEnvelopeSchema.parse(envelopeWithoutSig);
|
|
17675
18103
|
const publicKey = ed25519.getPublicKey(ed25519PrivKey);
|
|
@@ -17717,6 +18145,92 @@ async function verifyEnvelopeV2(envelope, options) {
|
|
|
17717
18145
|
if (parsed.authorizationTarget.kind === "policy") return await computeCid(fromBase64Url(parsed.authorizationTarget.policyBytes)) === parsed.authorizationTarget.policyCid;
|
|
17718
18146
|
return true;
|
|
17719
18147
|
}
|
|
18148
|
+
function verifyEnvelopeV3SignatureOnly(envelope) {
|
|
18149
|
+
const parsed = shareEnvelopeV3Schema.parse(envelope);
|
|
18150
|
+
const { signature, ...unsigned } = parsed;
|
|
18151
|
+
return ed25519.verify(fromBase64Url(signature.value), sha2562(signingBytesV3(unsigned)), ed25519PublicKeyFromDidKey(signature.signerDid), ED25519_VERIFY_OPTS2);
|
|
18152
|
+
}
|
|
18153
|
+
async function verifyEnvelopeV3(envelope, options) {
|
|
18154
|
+
const parsed = shareEnvelopeV3Schema.parse(envelope);
|
|
18155
|
+
if (parsed.signature.signerDid !== options.expectedSignerDid || parsed.signature.signerDid !== parsed.policy.ownerDid || !verifyEnvelopeV3SignatureOnly(parsed)) return false;
|
|
18156
|
+
const { policy } = parsed;
|
|
18157
|
+
const unsignedPolicy = { ...policy };
|
|
18158
|
+
delete unsignedPolicy.policyId;
|
|
18159
|
+
delete unsignedPolicy.signature;
|
|
18160
|
+
const policySignatureDomain = policy.schema === "xyz.tinycloud.policy/policy/v2" ? POLICY_V2_SIGNATURE_DOMAIN : POLICY_V1_SIGNATURE_DOMAIN;
|
|
18161
|
+
const policyDigest = sha2562(new TextEncoder().encode(`${policySignatureDomain}${canonicalize2(unsignedPolicy)}`));
|
|
18162
|
+
const policySignature = policy.signature;
|
|
18163
|
+
if (policySignature.suite !== "Ed25519" || policySignature.signerDid !== policy.ownerDid) return false;
|
|
18164
|
+
let policyPublicKey;
|
|
18165
|
+
let policySignatureBytes;
|
|
18166
|
+
try {
|
|
18167
|
+
policyPublicKey = ed25519PublicKeyFromDidKey(policy.ownerDid);
|
|
18168
|
+
policySignatureBytes = fromBase64Url(policySignature.value);
|
|
18169
|
+
} catch {
|
|
18170
|
+
return false;
|
|
18171
|
+
}
|
|
18172
|
+
if (policySignatureBytes.length !== 64 || !ed25519.verify(policySignatureBytes, policyDigest, policyPublicKey, ED25519_VERIFY_OPTS2)) return false;
|
|
18173
|
+
const policyIdDigest = policyDigest;
|
|
18174
|
+
if (policy.policyId !== `pol_${base32Lower(policyIdDigest)}`) return false;
|
|
18175
|
+
const policyBytes = new TextEncoder().encode(canonicalize2(policy));
|
|
18176
|
+
if (await computeCid(policyBytes) !== parsed.policyCid) return false;
|
|
18177
|
+
const sourceDigest = sha2562(new TextEncoder().encode(`${CONTENT_SOURCE_V1_DOMAIN}${canonicalize2(policy.contentSource)}`));
|
|
18178
|
+
if (hex(sourceDigest) !== parsed.contentSourceDigestHex) return false;
|
|
18179
|
+
const sortedCapabilities = [...policy.capabilityCeiling].sort((left, right) => canonicalize2(left).localeCompare(canonicalize2(right)));
|
|
18180
|
+
const capabilityCeilingHashHex = hex(sha2562(new TextEncoder().encode(`${POLICY_CAPABILITY_V1_DOMAIN}${canonicalize2(sortedCapabilities)}`)));
|
|
18181
|
+
const nativeProjection = sortedCapabilities.map((capability) => capability.kind === "encryption" ? { service: "tinycloud.encryption", space: capability.resource, path: capability.resource, actions: [capability.action] } : { service: "tinycloud.kv", space: capability.resource.slice(0, capability.resource.indexOf("/kv/")), path: capability.resource.split("/kv/")[1], actions: [...capability.actions], caveat: { type: "xyz.tinycloud.resource/selector", kind: capability.selector, value: capability.resource } }).sort((left, right) => canonicalize2(left).localeCompare(canonicalize2(right)));
|
|
18182
|
+
const nativeProjectionHashHex = hex(sha2562(new TextEncoder().encode(`${NATIVE_PROJECTION_V1_DOMAIN}${canonicalize2(nativeProjection)}`)));
|
|
18183
|
+
const expectedAttenuation = Object.fromEntries(sortedCapabilities.map((capability) => capability.kind === "encryption" ? [capability.resource, { [capability.action]: [{}] }] : [capability.resource, Object.fromEntries(capability.actions.map((action) => [action, [{ kind: capability.selector, type: "xyz.tinycloud.resource/selector", value: capability.resource }]]))]));
|
|
18184
|
+
const kv = policy.capabilityCeiling.find((capability) => capability.kind === "kv");
|
|
18185
|
+
const expectedKvActions = parsed.actions.flatMap((action) => action === "read" ? ["tinycloud.kv/get", "tinycloud.kv/metadata"] : action === "list" ? ["tinycloud.kv/list"] : ["tinycloud.kv/put"]);
|
|
18186
|
+
const marker = parsed.contentSource.kvResource.indexOf("/kv/");
|
|
18187
|
+
const resourceSpace = marker < 1 ? "" : parsed.contentSource.kvResource.slice(0, marker);
|
|
18188
|
+
const resourcePath = marker < 1 ? "" : parsed.contentSource.kvResource.slice(marker + 4);
|
|
18189
|
+
if (parsed.shareId !== parsed.contentSource.shareId || resourceSpace !== parsed.target.spaceId || resourcePath !== parsed.resource.path.replace(/\/$/, "") || parsed.resource.kind !== parsed.contentSource.selector || kv?.kind !== "kv" || expectedKvActions.some((action) => !kv.actions.includes(action)) || parsed.encryptionNetwork !== parsed.contentSource.encryptionNetwork || parsed.contentSource.keyVersion <= 0 || policy.expiresAt !== void 0 && Date.parse(parsed.expiry) > Date.parse(policy.expiresAt)) return false;
|
|
18190
|
+
const binding = parsed.attestedEnforcerBinding;
|
|
18191
|
+
const { signature: bindingSignature, ...unsignedBinding } = binding;
|
|
18192
|
+
const expectedBindingDigestHex = hex(sha2562(new TextEncoder().encode(canonicalize2({ enforcerDid: binding.enforcerDid, nodeAudience: binding.nodeAudience }))));
|
|
18193
|
+
if (binding.enforcerDid !== parsed.target.nodeAudience || binding.nodeAudience !== parsed.target.nodeAudience || binding.attestationBindingDigestHex !== expectedBindingDigestHex || bindingSignature.signerDid !== binding.enforcerDid || bindingSignature.suite !== "Ed25519" || Date.parse(binding.issuedAt) > Date.now() || Date.parse(binding.expiresAt) <= Date.now() || Date.parse(binding.expiresAt) < Date.parse(parsed.expiry)) return false;
|
|
18194
|
+
try {
|
|
18195
|
+
const digest4 = sha2562(new TextEncoder().encode(`${ATTESTED_ENFORCER_V2_DOMAIN}${canonicalize2(unsignedBinding)}`));
|
|
18196
|
+
if (!ed25519.verify(fromBase64Url(bindingSignature.value), digest4, ed25519PublicKeyFromDidKey(binding.enforcerDid), ED25519_VERIFY_OPTS2)) return false;
|
|
18197
|
+
} catch {
|
|
18198
|
+
return false;
|
|
18199
|
+
}
|
|
18200
|
+
if (parsed.policyRoot.role !== "policy-authority" || parsed.enforcementRoot.role !== "policy-enforcement" || parsed.policyRoot.cid === parsed.enforcementRoot.cid) return false;
|
|
18201
|
+
try {
|
|
18202
|
+
const policyRoot = verifyCompactUcanAuthorization(parsed.policyRoot.authorization, parsed.policyRoot.cid);
|
|
18203
|
+
const enforcementRoot = verifyCompactUcanAuthorization(parsed.enforcementRoot.authorization, parsed.enforcementRoot.cid);
|
|
18204
|
+
const policyFact = policyRoot.payload.fct[0];
|
|
18205
|
+
const enforcementFact = enforcementRoot.payload.fct[0];
|
|
18206
|
+
const common = ["ownerDid", "policyId", "policyDigestHex", "policyCid", "contentSourceDigestHex", "capabilityCeilingHashHex", "nativeProjectionHashHex", "nodeAudience"];
|
|
18207
|
+
const policyKeys = [...common, "role", "mode"];
|
|
18208
|
+
const enforcementKeys = [...policyKeys, "enforcerDid"];
|
|
18209
|
+
if (Object.keys(policyFact).length !== policyKeys.length || policyKeys.some((key) => !(key in policyFact)) || Object.keys(enforcementFact).length !== enforcementKeys.length || enforcementKeys.some((key) => !(key in enforcementFact)) || policyRoot.payload.prf.length !== 0 || enforcementRoot.payload.prf.length !== 0 || policyRoot.payload.iss.split("#", 1)[0] !== policy.ownerDid || enforcementRoot.payload.iss.split("#", 1)[0] !== policy.ownerDid || policyRoot.payload.nbf !== enforcementRoot.payload.nbf || policyRoot.payload.exp !== enforcementRoot.payload.exp || canonicalize2(policyRoot.payload.att) !== canonicalize2(expectedAttenuation) || canonicalize2(enforcementRoot.payload.att) !== canonicalize2(expectedAttenuation) || policyFact.role !== "policy-authority" || policyFact.mode !== "policy-source" || "enforcerDid" in policyFact || enforcementFact.role !== "policy-enforcement" || enforcementFact.mode !== "conditional-mint" || policyRoot.payload.aud !== `did:tinycloud:policy:${hex(policyIdDigest)}` || enforcementRoot.payload.aud !== parsed.target.nodeAudience || enforcementFact.enforcerDid !== parsed.target.nodeAudience || common.some((key) => policyFact[key] !== enforcementFact[key]) || policyFact.ownerDid !== policy.ownerDid || policyFact.policyId !== policy.policyId || policyFact.policyDigestHex !== hex(policyIdDigest) || policyFact.policyCid !== parsed.policyCid || policyFact.contentSourceDigestHex !== parsed.contentSourceDigestHex || policyFact.capabilityCeilingHashHex !== capabilityCeilingHashHex || policyFact.nativeProjectionHashHex !== nativeProjectionHashHex || policyFact.nodeAudience !== parsed.target.nodeAudience || policyRoot.payload.exp * 1e3 < Date.parse(parsed.expiry)) return false;
|
|
18210
|
+
} catch {
|
|
18211
|
+
return false;
|
|
18212
|
+
}
|
|
18213
|
+
return true;
|
|
18214
|
+
}
|
|
18215
|
+
function hex(bytes3) {
|
|
18216
|
+
return [...bytes3].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
18217
|
+
}
|
|
18218
|
+
function base32Lower(bytes3) {
|
|
18219
|
+
const alphabet2 = "abcdefghijklmnopqrstuvwxyz234567";
|
|
18220
|
+
let output = "";
|
|
18221
|
+
let buffer = 0;
|
|
18222
|
+
let bits = 0;
|
|
18223
|
+
for (const byte of bytes3) {
|
|
18224
|
+
buffer = buffer << 8 | byte;
|
|
18225
|
+
bits += 8;
|
|
18226
|
+
while (bits >= 5) {
|
|
18227
|
+
output += alphabet2[buffer >>> bits - 5 & 31];
|
|
18228
|
+
bits -= 5;
|
|
18229
|
+
}
|
|
18230
|
+
}
|
|
18231
|
+
if (bits > 0) output += alphabet2[buffer << 5 - bits & 31];
|
|
18232
|
+
return output;
|
|
18233
|
+
}
|
|
17720
18234
|
function assertCanonicalCid(cidString) {
|
|
17721
18235
|
const cid2 = CID.parse(cidString);
|
|
17722
18236
|
if (cid2.version !== 1 || cid2.code !== code || cid2.multihash.code !== 18 || // sha2-256 (0x12) only, at the link layer too
|
|
@@ -17895,7 +18409,7 @@ function registryFetcher(options, limit, tooLargeCode = "max-bytes-exceeded", st
|
|
|
17895
18409
|
};
|
|
17896
18410
|
}
|
|
17897
18411
|
function metadataFor(envelope, origin) {
|
|
17898
|
-
if (envelope.version === 2) {
|
|
18412
|
+
if (envelope.version === 2 || envelope.version === 3) {
|
|
17899
18413
|
const targetKind3 = envelope.recipientMatcher.kind === "recipientDid" ? "recipientDid" : envelope.recipientMatcher.kind === "exactEmail" ? "email" : envelope.recipientMatcher.kind === "emailDomain" ? "emailDomain" : "bearer";
|
|
17900
18414
|
return {
|
|
17901
18415
|
protocol: "tinycloud-share",
|
|
@@ -17911,7 +18425,7 @@ function metadataFor(envelope, origin) {
|
|
|
17911
18425
|
...envelope.display.filename === void 0 ? {} : { filename: envelope.display.filename },
|
|
17912
18426
|
...envelope.display.mode === void 0 ? {} : { mode: envelope.display.mode }
|
|
17913
18427
|
},
|
|
17914
|
-
...envelope.
|
|
18428
|
+
...envelope.version === 2 && envelope.content !== void 0 ? { content: { cid: envelope.content.cid } } : {}
|
|
17915
18429
|
};
|
|
17916
18430
|
}
|
|
17917
18431
|
return {
|
|
@@ -17936,8 +18450,10 @@ function parseEnvelope(bytes3) {
|
|
|
17936
18450
|
const text = new TextDecoder("utf-8", { fatal: true }).decode(bytes3);
|
|
17937
18451
|
const value = JSON.parse(text);
|
|
17938
18452
|
if (canonicalize2(value) !== text) throw new Error("share envelope is not canonical JSON");
|
|
17939
|
-
if (typeof value === "object" && value !== null && !Array.isArray(value)
|
|
17940
|
-
|
|
18453
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
18454
|
+
const version2 = value.version;
|
|
18455
|
+
if (version2 === 3) return shareEnvelopeV3Schema.parse(value);
|
|
18456
|
+
if (version2 === 2) return shareEnvelopeV2Schema.parse(value);
|
|
17941
18457
|
}
|
|
17942
18458
|
return shareEnvelopeSchema.parse(value);
|
|
17943
18459
|
} catch {
|
|
@@ -18009,6 +18525,19 @@ async function verifyV2Envelope(envelope, linkOrigin, options) {
|
|
|
18009
18525
|
if (options.trustedSignerDid === void 0 || envelope.signature.signerDid !== options.trustedSignerDid) throw new ShareReceiveError("signature-invalid", "an addressed signer trust root is required");
|
|
18010
18526
|
}
|
|
18011
18527
|
}
|
|
18528
|
+
async function verifyV3Envelope(envelope, linkOrigin, options) {
|
|
18529
|
+
if (options.expectedOrigin !== void 0 && linkOrigin !== options.expectedOrigin) {
|
|
18530
|
+
throw new ShareReceiveError("origin-mismatch", "share link origin does not match the trusted origin");
|
|
18531
|
+
}
|
|
18532
|
+
try {
|
|
18533
|
+
if (!await verifyEnvelopeV3(envelope, { expectedSignerDid: envelope.policy.ownerDid })) throw new Error("signature");
|
|
18534
|
+
} catch {
|
|
18535
|
+
throw new ShareReceiveError("signature-invalid", "share signature is invalid");
|
|
18536
|
+
}
|
|
18537
|
+
const expiry = Date.parse(envelope.expiry);
|
|
18538
|
+
if (!Number.isFinite(expiry)) throw new ShareReceiveError("envelope-invalid", "share expiry is invalid");
|
|
18539
|
+
if (expiry <= (options.now?.() ?? Date.now())) throw new ShareReceiveError("expired", "share has expired", { expiresAt: envelope.expiry });
|
|
18540
|
+
}
|
|
18012
18541
|
async function verifyV1PolicyEnvelope(envelope, linkOrigin, options) {
|
|
18013
18542
|
if (envelope.authorizationTarget.kind !== "policy") throw new ShareReceiveError("unsupported-target", "share target is not an addressed policy", { reason: "policy-target" });
|
|
18014
18543
|
if (envelope.target.origin !== linkOrigin || options.expectedOrigin !== void 0 && (linkOrigin !== options.expectedOrigin || envelope.target.origin !== options.expectedOrigin)) {
|
|
@@ -18040,12 +18569,18 @@ async function inspectShare(link2, options = {}) {
|
|
|
18040
18569
|
const resolved = await resolveShareEnvelope(link2, options);
|
|
18041
18570
|
if (resolved.envelope.version === 1 && resolved.envelope.authorizationTarget.kind === "policy") await verifyV1PolicyEnvelope(resolved.envelope, resolved.origin, options);
|
|
18042
18571
|
else if (resolved.envelope.version === 1) await verifyResolved(resolved.envelope, resolved.origin, options);
|
|
18043
|
-
else await verifyV2Envelope(resolved.envelope, resolved.origin, options);
|
|
18044
|
-
|
|
18572
|
+
else if (resolved.envelope.version === 2) await verifyV2Envelope(resolved.envelope, resolved.origin, options);
|
|
18573
|
+
else await verifyV3Envelope(resolved.envelope, resolved.origin, options);
|
|
18574
|
+
if (resolved.envelope.version === 2 || resolved.envelope.version === 3 || resolved.envelope.authorizationTarget.kind === "policy") options.onResolvedAddressedEnvelope?.(resolved.envelope, resolved.cid);
|
|
18045
18575
|
return { metadata: metadataFor(resolved.envelope, resolved.origin), link: { origin: resolved.origin, cid: resolved.cid, kind: resolved.kind } };
|
|
18046
18576
|
}
|
|
18047
18577
|
async function receiveShare(link2, options = {}) {
|
|
18048
18578
|
const resolved = await resolveShareEnvelope(link2, options);
|
|
18579
|
+
if (resolved.envelope.version === 3) {
|
|
18580
|
+
await verifyV3Envelope(resolved.envelope, resolved.origin, options);
|
|
18581
|
+
options.onResolvedAddressedEnvelope?.(resolved.envelope, resolved.cid);
|
|
18582
|
+
return { state: "authorization-required", method: resolved.envelope.recipientMatcher.kind === "recipientDid" ? "openkey-device" : "email-claim" };
|
|
18583
|
+
}
|
|
18049
18584
|
if (resolved.envelope.version === 2) {
|
|
18050
18585
|
await verifyV2Envelope(resolved.envelope, resolved.origin, options);
|
|
18051
18586
|
options.onResolvedAddressedEnvelope?.(resolved.envelope, resolved.cid);
|
|
@@ -18993,13 +19528,16 @@ async function migrateShare(input) {
|
|
|
18993
19528
|
const value = await receiveLegacyShare(input.link, input.reader);
|
|
18994
19529
|
return { protocol: "tinycloud-share", version: 1, legacy: true, value, migrated: await input.publish(value) };
|
|
18995
19530
|
}
|
|
18996
|
-
var __defProp2, __export2, external_exports2, util2, objectUtil2, ZodParsedType2, getParsedType2, ZodIssueCode2, quotelessJson2, ZodError2, errorMap2, en_default2, overrideErrorMap2, makeIssue2, EMPTY_PATH2, ParseStatus2, INVALID2, DIRTY2, OK2, isAborted2, isDirty2, isValid2, isAsync2, errorUtil2, ParseInputLazyPath2, handleResult2, ZodType2, cuidRegex2, cuid2Regex2, ulidRegex2, uuidRegex2, nanoidRegex2, jwtRegex2, durationRegex2, emailRegex2, _emojiRegex2, emojiRegex2, ipv4Regex2, ipv4CidrRegex2, ipv6Regex2, ipv6CidrRegex2, base64Regex2, base64urlRegex2, dateRegexSource2, dateRegex2, ZodString2, ZodNumber2, ZodBigInt2, ZodBoolean2, ZodDate2, ZodSymbol2, ZodUndefined2, ZodNull2, ZodAny2, ZodUnknown2, ZodNever2, ZodVoid2, ZodArray2, ZodObject2, ZodUnion2, getDiscriminator2, ZodDiscriminatedUnion2, ZodIntersection2, ZodTuple2, ZodRecord2, ZodMap2, ZodSet2, ZodFunction2, ZodLazy2, ZodLiteral2, ZodEnum2, ZodNativeEnum2, ZodPromise2, ZodEffects2, ZodOptional2, ZodNullable2, ZodDefault2, ZodCatch2, ZodNaN2, BRAND2, ZodBranded2, ZodPipeline2, ZodReadonly2, late2, ZodFirstPartyTypeKind2, instanceOfType2, stringType2, numberType2, nanType2, bigIntType2, booleanType2, dateType2, symbolType2, undefinedType2, nullType2, anyType2, unknownType2, neverType2, voidType2, arrayType2, objectType2, strictObjectType2, unionType2, discriminatedUnionType2, intersectionType2, tupleType2, recordType2, mapType2, setType2, functionType2, lazyType2, literalType2, enumType2, nativeEnumType2, promiseType2, effectsType2, optionalType2, nullableType2, preprocessType2, pipelineType2, ostring2, onumber2, oboolean2, coerce2, NEVER2, empty, src, _brrp__multiformats_scope_baseX, base_x_default, Encoder, Decoder, ComposedDecoder, Codec, base32, base32upper, base32pad, base32padupper, base32hex, base32hexupper, base32hexpad, base32hexpadupper, base32z, base36, base36upper, base58btc, base58flickr, encode_1, MSB, REST, MSBALL, INT, decode2, MSB$1, REST$1, N1, N2, N3, N4, N5, N6, N7, N8, N9, length, varint, _brrp_varint, varint_default, Digest, cache, CID, DAG_PB_CODE, SHA_256_CODE, cidSymbol, code, SHA256_CODE, base64, base64pad, base64url, base64urlpad, ED25519_MULTICODEC_PREFIX, PUBLIC_KEY_LENGTH, base64UrlString, sessionJwkCommonFields, okpPrivateJwkSchema, ecPrivateJwkSchema, sessionJwkSchema, policyTargetSchema, bearerKeyTargetSchema, recipientDidTargetSchema, authorizationTargetSchema, resourceSelectorSchema, targetSchema, displaySchema, contentPointerSchema, signatureSchema, unsignedShareEnvelopeSchema, shareEnvelopeSchema, recipientMatcherSchema, shareActionSchema, kvContentSourceSchema, sqlContentSourceSchema, contentSourceSchema, v2TargetSchema, shareDecryptionSchema, ownerAuthoritySchema, contentMetadataSchema, unsignedShareEnvelopeV2BaseSchema, unsignedShareEnvelopeV2Schema, shareEnvelopeV2Schema, unifiedResourceSchema, unifiedEncryptionNetworkSchema, unifiedKvCapabilitySchema, unifiedEncryptionCapabilitySchema, unifiedCapabilitySchema, unifiedContentSourceSchema, unifiedPolicySchema, unifiedRootSchema, attestedEnforcerBindingV2Schema, v3TargetSchema, unsignedShareEnvelopeV3BaseSchema, unsignedShareEnvelopeV3Schema, shareEnvelopeV3Schema, BEARER_READ_ABILITY, READ_ABILITIES, ED25519_VERIFY_OPTS, ENVELOPE_AAD_LABEL, SEALED_BLOB_VERSION, AAD, KEY_LENGTH, NONCE_LENGTH, TAG_LENGTH, HEADER_LENGTH, ED25519_VERIFY_OPTS2, ENVELOPE_SIGNATURE_DOMAIN, ENVELOPE_V2_SIGNATURE_DOMAIN, KEY_LENGTH2, INLINE_PREFIX, MAX_INLINE_BYTES, SHARE_RESULT_VERSION, DEFAULT_MAX_SEALED_BLOB_BYTES, DEFAULT_MAX_CONTENT_BLOB_BYTES, CONTENT_SEALED_OVERHEAD, ShareReceiveError, SHARE_CONTENT_LIMIT, SHARE_SEALED_OVERHEAD, SHARE_PUBLISH_RESULT_VERSION, DEFAULT_SHARE_LIFETIME_MS, SharePublishError, empty2, src2, _brrp__multiformats_scope_baseX2, base_x_default2, Encoder2, Decoder2, ComposedDecoder2, Codec2, base322, base32upper2, base32pad2, base32padupper2, base32hex2, base32hexupper2, base32hexpad2, base32hexpadupper2, base32z2, base362, base36upper2, base58btc2, base58flickr2, encode_12, MSB2, REST2, MSBALL2, INT2, decode6, MSB$12, REST$12, N12, N22, N32, N42, N52, N62, N72, N82, N92, length2, varint2, _brrp_varint2, varint_default2, Digest2, cache2, CID2, DAG_PB_CODE2, SHA_256_CODE2, cidSymbol2, MAX_CONTENT_BYTES, ShareNotifyError, SHARE_V2_PROTOCOL, DOMAIN, PRESENTATION_DOMAIN, SESSION_DOMAIN, INVOCATION_DOMAIN;
|
|
19531
|
+
var __defProp2, __export2, external_exports2, util2, objectUtil2, ZodParsedType2, getParsedType2, ZodIssueCode2, quotelessJson2, ZodError2, errorMap2, en_default2, overrideErrorMap2, makeIssue2, EMPTY_PATH2, ParseStatus2, INVALID2, DIRTY2, OK2, isAborted2, isDirty2, isValid2, isAsync2, errorUtil2, ParseInputLazyPath2, handleResult2, ZodType2, cuidRegex2, cuid2Regex2, ulidRegex2, uuidRegex2, nanoidRegex2, jwtRegex2, durationRegex2, emailRegex2, _emojiRegex2, emojiRegex2, ipv4Regex2, ipv4CidrRegex2, ipv6Regex2, ipv6CidrRegex2, base64Regex2, base64urlRegex2, dateRegexSource2, dateRegex2, ZodString2, ZodNumber2, ZodBigInt2, ZodBoolean2, ZodDate2, ZodSymbol2, ZodUndefined2, ZodNull2, ZodAny2, ZodUnknown2, ZodNever2, ZodVoid2, ZodArray2, ZodObject2, ZodUnion2, getDiscriminator2, ZodDiscriminatedUnion2, ZodIntersection2, ZodTuple2, ZodRecord2, ZodMap2, ZodSet2, ZodFunction2, ZodLazy2, ZodLiteral2, ZodEnum2, ZodNativeEnum2, ZodPromise2, ZodEffects2, ZodOptional2, ZodNullable2, ZodDefault2, ZodCatch2, ZodNaN2, BRAND2, ZodBranded2, ZodPipeline2, ZodReadonly2, late2, ZodFirstPartyTypeKind2, instanceOfType2, stringType2, numberType2, nanType2, bigIntType2, booleanType2, dateType2, symbolType2, undefinedType2, nullType2, anyType2, unknownType2, neverType2, voidType2, arrayType2, objectType2, strictObjectType2, unionType2, discriminatedUnionType2, intersectionType2, tupleType2, recordType2, mapType2, setType2, functionType2, lazyType2, literalType2, enumType2, nativeEnumType2, promiseType2, effectsType2, optionalType2, nullableType2, preprocessType2, pipelineType2, ostring2, onumber2, oboolean2, coerce2, NEVER2, empty, src, _brrp__multiformats_scope_baseX, base_x_default, Encoder, Decoder, ComposedDecoder, Codec, base32, base32upper, base32pad, base32padupper, base32hex, base32hexupper, base32hexpad, base32hexpadupper, base32z, base36, base36upper, base58btc, base58flickr, encode_1, MSB, REST, MSBALL, INT, decode2, MSB$1, REST$1, N1, N2, N3, N4, N5, N6, N7, N8, N9, length, varint, _brrp_varint, varint_default, Digest, cache, CID, DAG_PB_CODE, SHA_256_CODE, cidSymbol, code, SHA256_CODE, base64, base64pad, base64url, base64urlpad, ED25519_MULTICODEC_PREFIX, PUBLIC_KEY_LENGTH, base64UrlString, sessionJwkCommonFields, okpPrivateJwkSchema, ecPrivateJwkSchema, sessionJwkSchema, policyTargetSchema, bearerKeyTargetSchema, recipientDidTargetSchema, authorizationTargetSchema, resourceSelectorSchema, targetSchema, displaySchema, contentPointerSchema, signatureSchema, unsignedShareEnvelopeSchema, shareEnvelopeSchema, recipientMatcherSchema, shareActionSchema, kvContentSourceSchema, sqlContentSourceSchema, contentSourceSchema, v2TargetSchema, shareDecryptionSchema, ownerAuthoritySchema, contentMetadataSchema, unsignedShareEnvelopeV2BaseSchema, unsignedShareEnvelopeV2Schema, shareEnvelopeV2Schema, unifiedResourceSchema, unifiedEncryptionNetworkSchema, unifiedKvCapabilitySchema, unifiedEncryptionCapabilitySchema, unifiedCapabilitySchema, unifiedContentSourceSchema, unifiedPolicyV1Schema, policyCredentialRequirementV1Schema, unifiedPolicyV2Schema, unifiedPolicySchema, unifiedRootSchema, attestedEnforcerBindingV2Schema, v3TargetSchema, unsignedShareEnvelopeV3BaseSchema, unsignedShareEnvelopeV3Schema, shareEnvelopeV3Schema, BEARER_READ_ABILITY, READ_ABILITIES, ED25519_VERIFY_OPTS, ENVELOPE_AAD_LABEL, SEALED_BLOB_VERSION, AAD, KEY_LENGTH, NONCE_LENGTH, TAG_LENGTH, HEADER_LENGTH, ED25519_VERIFY_OPTS2, ENVELOPE_SIGNATURE_DOMAIN, ENVELOPE_V2_SIGNATURE_DOMAIN, ENVELOPE_V3_SIGNATURE_DOMAIN, POLICY_V1_SIGNATURE_DOMAIN, POLICY_V2_SIGNATURE_DOMAIN, CONTENT_SOURCE_V1_DOMAIN, POLICY_CAPABILITY_V1_DOMAIN, NATIVE_PROJECTION_V1_DOMAIN, ATTESTED_ENFORCER_V2_DOMAIN, KEY_LENGTH2, INLINE_PREFIX, MAX_INLINE_BYTES, SHARE_RESULT_VERSION, DEFAULT_MAX_SEALED_BLOB_BYTES, DEFAULT_MAX_CONTENT_BLOB_BYTES, CONTENT_SEALED_OVERHEAD, ShareReceiveError, SHARE_CONTENT_LIMIT, SHARE_SEALED_OVERHEAD, SHARE_PUBLISH_RESULT_VERSION, DEFAULT_SHARE_LIFETIME_MS, SharePublishError, empty2, src2, _brrp__multiformats_scope_baseX2, base_x_default2, Encoder2, Decoder2, ComposedDecoder2, Codec2, base322, base32upper2, base32pad2, base32padupper2, base32hex2, base32hexupper2, base32hexpad2, base32hexpadupper2, base32z2, base362, base36upper2, base58btc2, base58flickr2, encode_12, MSB2, REST2, MSBALL2, INT2, decode6, MSB$12, REST$12, N12, N22, N32, N42, N52, N62, N72, N82, N92, length2, varint2, _brrp_varint2, varint_default2, Digest2, cache2, CID2, DAG_PB_CODE2, SHA_256_CODE2, cidSymbol2, MAX_CONTENT_BYTES, ShareNotifyError, SHARE_V2_PROTOCOL, DOMAIN, PRESENTATION_DOMAIN, SESSION_DOMAIN, INVOCATION_DOMAIN;
|
|
18997
19532
|
var init_dist3 = __esm({
|
|
18998
19533
|
"../share-sdk/dist/index.js"() {
|
|
18999
19534
|
"use strict";
|
|
19000
19535
|
init_sha2();
|
|
19001
19536
|
init_ed25519();
|
|
19002
19537
|
init_ed25519();
|
|
19538
|
+
init_blake3();
|
|
19539
|
+
init_ed25519();
|
|
19540
|
+
init_sha256();
|
|
19003
19541
|
init_ed25519();
|
|
19004
19542
|
__defProp2 = Object.defineProperty;
|
|
19005
19543
|
__export2 = (target, all) => {
|
|
@@ -23487,9 +24025,12 @@ var init_dist3 = __esm({
|
|
|
23487
24025
|
unsignedShareEnvelopeV2Schema = unsignedShareEnvelopeV2BaseSchema.superRefine(validateV2Invariants);
|
|
23488
24026
|
shareEnvelopeV2Schema = unsignedShareEnvelopeV2BaseSchema.extend({ signature: signatureSchema }).strict().superRefine(validateV2Invariants);
|
|
23489
24027
|
unifiedResourceSchema = external_exports2.string().refine((value) => {
|
|
23490
|
-
const
|
|
23491
|
-
if (
|
|
23492
|
-
const
|
|
24028
|
+
const marker = value.indexOf("/kv/");
|
|
24029
|
+
if (marker < 1) return false;
|
|
24030
|
+
const space = value.slice(0, marker);
|
|
24031
|
+
const legacy = space.startsWith("tinycloud://");
|
|
24032
|
+
if (legacy ? /[:/?#%]/.test(space.slice("tinycloud://".length)) : !space.startsWith("tinycloud:") || /[/?#%]/.test(space)) return false;
|
|
24033
|
+
const path = value.slice(marker + 4);
|
|
23493
24034
|
return !path.startsWith("/") && !path.endsWith("/") && !path.includes("//") && path.split("/").every((segment) => segment.length > 0 && segment !== "." && segment !== "..");
|
|
23494
24035
|
}, { message: "expected canonical TinyCloud KV resource" });
|
|
23495
24036
|
unifiedEncryptionNetworkSchema = external_exports2.string().refine((value) => {
|
|
@@ -23527,7 +24068,7 @@ var init_dist3 = __esm({
|
|
|
23527
24068
|
mode: external_exports2.union([external_exports2.literal("mutable"), external_exports2.literal("immutable")]),
|
|
23528
24069
|
initialCiphertextDigestHex: external_exports2.string().regex(/^[0-9a-f]{64}$/).optional()
|
|
23529
24070
|
}).strict();
|
|
23530
|
-
|
|
24071
|
+
unifiedPolicyV1Schema = external_exports2.object({
|
|
23531
24072
|
schema: external_exports2.literal("xyz.tinycloud.policy/policy/v1"),
|
|
23532
24073
|
policyId: external_exports2.string().regex(/^pol_[a-z2-7]+$/),
|
|
23533
24074
|
ownerDid: external_exports2.string().min(1),
|
|
@@ -23537,6 +24078,31 @@ var init_dist3 = __esm({
|
|
|
23537
24078
|
capabilityCeiling: external_exports2.array(unifiedCapabilitySchema).min(2),
|
|
23538
24079
|
signature: external_exports2.object({ suite: external_exports2.string().min(1), signerDid: external_exports2.string().min(1), value: external_exports2.string().min(1) }).strict()
|
|
23539
24080
|
}).strict();
|
|
24081
|
+
policyCredentialRequirementV1Schema = external_exports2.object({
|
|
24082
|
+
type: external_exports2.literal("TinyCloudPolicyCredentialRequirement"),
|
|
24083
|
+
version: external_exports2.literal(1),
|
|
24084
|
+
requirementDigest: external_exports2.string().regex(/^[A-Za-z0-9_-]{43}$/),
|
|
24085
|
+
descriptorDigest: external_exports2.string().regex(/^[A-Za-z0-9_-]{43}$/),
|
|
24086
|
+
issuerDid: external_exports2.string().min(1),
|
|
24087
|
+
issuerKid: external_exports2.string().min(1),
|
|
24088
|
+
profile: external_exports2.object({ id: external_exports2.string().min(1), version: external_exports2.literal(1) }).strict(),
|
|
24089
|
+
credentialType: external_exports2.object({ id: external_exports2.string().min(1), version: external_exports2.literal(1) }).strict()
|
|
24090
|
+
}).strict();
|
|
24091
|
+
unifiedPolicyV2Schema = external_exports2.object({
|
|
24092
|
+
schema: external_exports2.literal("xyz.tinycloud.policy/policy/v2"),
|
|
24093
|
+
policyId: external_exports2.string().regex(/^pol_[a-z2-7]+$/),
|
|
24094
|
+
ownerDid: external_exports2.string().min(1),
|
|
24095
|
+
createdAt: external_exports2.string().datetime({ offset: true }),
|
|
24096
|
+
expiresAt: external_exports2.string().datetime({ offset: true }).optional(),
|
|
24097
|
+
contentSource: unifiedContentSourceSchema,
|
|
24098
|
+
capabilityCeiling: external_exports2.array(unifiedCapabilitySchema).min(2),
|
|
24099
|
+
credentialRequirement: policyCredentialRequirementV1Schema,
|
|
24100
|
+
signature: external_exports2.object({ suite: external_exports2.literal("Ed25519"), signerDid: external_exports2.string().min(1), value: external_exports2.string().min(1) }).strict()
|
|
24101
|
+
}).strict();
|
|
24102
|
+
unifiedPolicySchema = external_exports2.discriminatedUnion("schema", [
|
|
24103
|
+
unifiedPolicyV1Schema,
|
|
24104
|
+
unifiedPolicyV2Schema
|
|
24105
|
+
]);
|
|
23540
24106
|
unifiedRootSchema = external_exports2.object({
|
|
23541
24107
|
cid: external_exports2.string().min(1),
|
|
23542
24108
|
authorization: external_exports2.string().regex(/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/),
|
|
@@ -23592,6 +24158,13 @@ var init_dist3 = __esm({
|
|
|
23592
24158
|
ED25519_VERIFY_OPTS2 = { zip215: false };
|
|
23593
24159
|
ENVELOPE_SIGNATURE_DOMAIN = "xyz.tinycloud.share/envelope/v1\0";
|
|
23594
24160
|
ENVELOPE_V2_SIGNATURE_DOMAIN = "xyz.tinycloud.share/envelope/v2\0";
|
|
24161
|
+
ENVELOPE_V3_SIGNATURE_DOMAIN = "xyz.tinycloud.share/envelope/v3\0";
|
|
24162
|
+
POLICY_V1_SIGNATURE_DOMAIN = "xyz.tinycloud.policy/policy/v1\0";
|
|
24163
|
+
POLICY_V2_SIGNATURE_DOMAIN = "xyz.tinycloud.policy/policy/v2\0";
|
|
24164
|
+
CONTENT_SOURCE_V1_DOMAIN = "xyz.tinycloud.policy/ContentSource/v1\0";
|
|
24165
|
+
POLICY_CAPABILITY_V1_DOMAIN = "xyz.tinycloud.policy/PolicyCapability/v1\0";
|
|
24166
|
+
NATIVE_PROJECTION_V1_DOMAIN = "xyz.tinycloud.policy/NativeProjection/v1\0";
|
|
24167
|
+
ATTESTED_ENFORCER_V2_DOMAIN = "xyz.tinycloud.policy/AttestedEnforcerBinding/v2\0";
|
|
23595
24168
|
KEY_LENGTH2 = 32;
|
|
23596
24169
|
INLINE_PREFIX = "#v=2&p=";
|
|
23597
24170
|
MAX_INLINE_BYTES = 256 * 1024;
|
|
@@ -25190,13 +25763,13 @@ function createInMemoryLocalNodeIdentityStore() {
|
|
|
25190
25763
|
}
|
|
25191
25764
|
};
|
|
25192
25765
|
}
|
|
25193
|
-
function locationPayloadForRecord(
|
|
25766
|
+
function locationPayloadForRecord(record2) {
|
|
25194
25767
|
return {
|
|
25195
|
-
version:
|
|
25196
|
-
subject:
|
|
25197
|
-
multiaddrs: [...
|
|
25198
|
-
updated_at:
|
|
25199
|
-
sequence:
|
|
25768
|
+
version: record2.version,
|
|
25769
|
+
subject: record2.subject,
|
|
25770
|
+
multiaddrs: [...record2.multiaddrs],
|
|
25771
|
+
updated_at: record2.updated_at,
|
|
25772
|
+
sequence: record2.sequence
|
|
25200
25773
|
};
|
|
25201
25774
|
}
|
|
25202
25775
|
function canonicalLocationPayload(payload) {
|
|
@@ -25247,13 +25820,13 @@ function validateLocationRecord(input) {
|
|
|
25247
25820
|
return { ...payload, signature };
|
|
25248
25821
|
}
|
|
25249
25822
|
async function verifyLocationRecord(input) {
|
|
25250
|
-
const
|
|
25251
|
-
const payload = canonicalLocationPayload(locationPayloadForRecord(
|
|
25252
|
-
if (
|
|
25253
|
-
return verifyPkhSignature(
|
|
25823
|
+
const record2 = validateLocationRecord(input);
|
|
25824
|
+
const payload = canonicalLocationPayload(locationPayloadForRecord(record2));
|
|
25825
|
+
if (record2.subject.startsWith("did:pkh:")) {
|
|
25826
|
+
return verifyPkhSignature(record2.subject, payload, record2.signature);
|
|
25254
25827
|
}
|
|
25255
|
-
if (
|
|
25256
|
-
return verifyDidKeySignature(
|
|
25828
|
+
if (record2.subject.startsWith("did:key:")) {
|
|
25829
|
+
return verifyDidKeySignature(record2.subject, payload, record2.signature);
|
|
25257
25830
|
}
|
|
25258
25831
|
return false;
|
|
25259
25832
|
}
|
|
@@ -25360,18 +25933,18 @@ async function fetchRegistryLocalLinkCandidates(options2, fetchFn, existingCandi
|
|
|
25360
25933
|
}
|
|
25361
25934
|
const registryUrl = options2.registryUrl ?? DEFAULT_TINYCLOUD_LOCATION_REGISTRY_URL;
|
|
25362
25935
|
try {
|
|
25363
|
-
const
|
|
25364
|
-
if (!
|
|
25936
|
+
const record2 = await fetchLocationRecord(registryUrl, options2.subject, fetchFn);
|
|
25937
|
+
if (!record2) {
|
|
25365
25938
|
return [];
|
|
25366
25939
|
}
|
|
25367
25940
|
const shouldVerify = options2.verifyRecords ?? true;
|
|
25368
|
-
if (shouldVerify && !await verifyLocationRecord(
|
|
25941
|
+
if (shouldVerify && !await verifyLocationRecord(record2)) {
|
|
25369
25942
|
debugLog(
|
|
25370
25943
|
`registry record signature invalid for ${options2.subject}; skipping local-link lookup`
|
|
25371
25944
|
);
|
|
25372
25945
|
return [];
|
|
25373
25946
|
}
|
|
25374
|
-
return extractLocalLinkUrls(
|
|
25947
|
+
return extractLocalLinkUrls(record2).filter((url) => !existingCandidates.some((c) => c.url === url)).map((url) => ({
|
|
25375
25948
|
source: "local-link",
|
|
25376
25949
|
url,
|
|
25377
25950
|
timeoutMs: LOCAL_LINK_PROBE_TIMEOUT_MS
|
|
@@ -25380,12 +25953,12 @@ async function fetchRegistryLocalLinkCandidates(options2, fetchFn, existingCandi
|
|
|
25380
25953
|
return [];
|
|
25381
25954
|
}
|
|
25382
25955
|
}
|
|
25383
|
-
function extractLocalLinkUrls(
|
|
25384
|
-
if (!
|
|
25956
|
+
function extractLocalLinkUrls(record2) {
|
|
25957
|
+
if (!record2) {
|
|
25385
25958
|
return [];
|
|
25386
25959
|
}
|
|
25387
25960
|
const urls = [];
|
|
25388
|
-
for (const addr of
|
|
25961
|
+
for (const addr of record2.multiaddrs) {
|
|
25389
25962
|
let url;
|
|
25390
25963
|
try {
|
|
25391
25964
|
url = multiaddrToHttpUrl(addr);
|
|
@@ -25540,7 +26113,7 @@ function decodeBase64Url3(value) {
|
|
|
25540
26113
|
}
|
|
25541
26114
|
return Uint8Array.from(bytes2);
|
|
25542
26115
|
}
|
|
25543
|
-
var import_ms, __defProp3, __typeError, __defNormalProp, __export3, __publicField, __accessCheck, __privateGet, __privateAdd, __privateSet, EnsDataSchema, SiweConfigSchema, ClientSessionSchema, objectHasOwn, base32_exports, empty3, src3, _brrp__multiformats_scope_baseX3, base_x_default3, Encoder3, Decoder3, ComposedDecoder3, Codec3, base323, base32upper3, base32pad3, base32padupper3, base32hex3, base32hexupper3, base32hexpad3, base32hexpadupper3, base32z3, base36_exports, base363, base36upper3, base58_exports, base58btc3, base58flickr3, encode_13, MSB3, REST3, MSBALL3, INT3, decode22, MSB$13, REST$13, N13, N23, N33, N43, N53, N63, N73, N83, N93, length3, varint3, _brrp_varint3, varint_default3, Digest3, cache3, _a, CID3, DAG_PB_CODE3, SHA_256_CODE3, cidSymbol3, textEncoder, objectHasOwn2, CEILING_SERVICES, GRANTABLE_ACTIONS, base10_exports, base10, base16_exports, base16, base16upper, base2_exports, base22, base256emoji_exports, alphabet, alphabetBytesToChars, alphabetCharsToBytes, base256emoji, base64_exports, base642, base64pad2, base64url2, base64urlpad2, base8_exports, base8, identity_exports, identity, textEncoder2, textDecoder, identity_exports2, code2, name, encode42, identity2, sha2_browser_exports, DEFAULT_MIN_DIGEST_LENGTH, Hasher,
|
|
26116
|
+
var import_ms, __defProp3, __typeError, __defNormalProp, __export3, __publicField, __accessCheck, __privateGet, __privateAdd, __privateSet, EnsDataSchema, SiweConfigSchema, ClientSessionSchema, objectHasOwn, base32_exports, empty3, src3, _brrp__multiformats_scope_baseX3, base_x_default3, Encoder3, Decoder3, ComposedDecoder3, Codec3, base323, base32upper3, base32pad3, base32padupper3, base32hex3, base32hexupper3, base32hexpad3, base32hexpadupper3, base32z3, base36_exports, base363, base36upper3, base58_exports, base58btc3, base58flickr3, encode_13, MSB3, REST3, MSBALL3, INT3, decode22, MSB$13, REST$13, N13, N23, N33, N43, N53, N63, N73, N83, N93, length3, varint3, _brrp_varint3, varint_default3, Digest3, cache3, _a, CID3, DAG_PB_CODE3, SHA_256_CODE3, cidSymbol3, textEncoder, objectHasOwn2, CEILING_SERVICES, GRANTABLE_ACTIONS, base10_exports, base10, base16_exports, base16, base16upper, base2_exports, base22, base256emoji_exports, alphabet, alphabetBytesToChars, alphabetCharsToBytes, base256emoji, base64_exports, base642, base64pad2, base64url2, base64urlpad2, base8_exports, base8, identity_exports, identity, textEncoder2, textDecoder, identity_exports2, code2, name, encode42, identity2, sha2_browser_exports, DEFAULT_MIN_DIGEST_LENGTH, Hasher, sha25622, sha5122, bases, hashes, textEncoder3, objectHasOwn3, TRANSCRIPT_SHARE_BOOTSTRAP_SCHEMA, OWNER_NODE_ENDPOINT_SCHEMA, W3C_VC_CREDENTIAL_VERIFIER, objectHasOwn4, CompactHeaderSchema, CompactPayloadSchema, POLICY_ENGINE_CHALLENGE_RESPONSE_SCHEMA, POLICY_ENGINE_DENIAL_SCHEMA, POLICY_ENGINE_GRANT_PRESENTATION_DENIAL_CODES, JsonValueSchema, Rfc3339Schema, SignedRecordSchema, PolicyEngineSchema, OwnerNodeSchema, ResourceHintSchema, BootstrapSchema, SignatureSchema, ChallengeSchema, ChallengeResponseSchema, DenialSchema, ErrorEnvelopeDenialSchema, WireDelegationSchema, ResolveResponseSchema, DelegateReceiptSchema, SqlReadResponseSchema, KvReadResponseSchema, LISTEN_SQL_STATEMENT_CATALOG, LISTEN_SQL_STATEMENT_BY_NAME, JWKSchema, KeyTypeSchema, KeyInfoSchema, DelegationErrorSchema, DelegationSchema, DelegationStatusSchema, DelegationRevocationReceiptSchema, AccountDelegationResourceSchema, AccountDelegationDateSchema, AccountDelegationRecordSchema, AccountDelegationPageSchema, AccountDelegationQueryOptionsSchema, CapabilityEntrySchema, DelegationRecordSchema, CreateDelegationParamsSchema, DelegationChainSchema, DelegationChainV2Schema, DelegationDirectionSchema, DelegationFiltersSchema, SpaceOwnershipSchema, SpaceInfoSchema, ShareSchemaSchema, ShareLinkSchema, ShareLinkDataSchema, IngestOptionsSchema, GenerateShareParamsSchema, DelegationManagerConfigSchema, KeyProviderSchema, DelegationApiResponseSchema, DelegatedResourceSchema, CreateDelegationWasmParamsSchema, CreateDelegationWasmResultSchema, EPHEMERAL_MS, SIGNED_READ_URL_MS, SESSION_MS, SHARE_MS, APP_MS, MAX_MS, EXPIRY, DEFAULT_SIGNED_READ_URL_EXPIRY_MS2, EncodedShareDataSchema, ReceiveOptionsSchema, SharingServiceConfigSchema, DEFAULT_KNOWLEDGE_ROOT, ManifestValidationError, SERVICE_SHORT_TO_LONG, SERVICE_LONG_TO_SHORT, DEFAULT_MAX_INLINE_BYTES, MAX_SHARE_CONTENT_BYTES, MAX_SEALED_SHARE_CONTENT_BYTES, MAX_SHARE_ARTIFACT_BYTES, PUBLISHED_AAD, ShareRecipientTargetSchema, ShareResourceSchema, ShareActionSchema, ShareRecipientPolicySchema, ShareRecipientClientOptionsSchema, ShareNativeActionSchema, ShareWireActionSchema, ShareContentSourceSchema, ShareAddressedRecipientSchema, ShareAddressedDelegationRequestV2Schema, ShareAddressedDelegationEnvelopeV2Schema, ShareAddressedDelegationResponseV2Schema, ShareNativeResponseEntrySchema, ShareNativeResponseBase, ShareNativeResponseSchema, ResourceSchema, PortableDelegationSchema, MAX_NATIVE_CURSOR_BYTES, DEFAULT_EXPIRY_MS2, MAX_CONTENT_BYTES2, ethereumAddressPattern, EnsDataSchema2, PersistedTinyCloudSessionSchema, PersistedSessionDataSchema, TinyCloudSessionSchema, SpaceConfigSchema, SpaceServiceConfigSchema, SpaceDelegationParamsSchema, ServerDelegationInfoSchema, ServerDelegationsResponseSchema, ServerOwnedSpaceSchema, ServerOwnedSpacesResponseSchema, ServerCreateSpaceResponseSchema, ServerSpaceInfoResponseSchema, AutoApproveSpaceCreationHandler, defaultSpaceCreationHandler, N122, N222, N322, N422, N522, N622, N722, MSB22, REST22, string, ascii, BASES, bases_default, InvalidMultiaddrError, ValidationError, InvalidParametersError, UnknownProtocolError, Parser, MAX_IPV6_LENGTH, MAX_IPV4_LENGTH, parser, CODE_IP4, CODE_TCP, CODE_UDP, CODE_DCCP, CODE_IP6, CODE_IP6ZONE, CODE_IPCIDR, CODE_DNS, CODE_DNS4, CODE_DNS6, CODE_DNSADDR, CODE_SCTP, CODE_UDT, CODE_UTP, CODE_UNIX, CODE_P2P, CODE_ONION, CODE_ONION3, CODE_GARLIC64, CODE_GARLIC32, CODE_TLS, CODE_SNI, CODE_NOISE, CODE_QUIC, CODE_QUIC_V1, CODE_WEBTRANSPORT, CODE_CERTHASH, CODE_HTTP, CODE_HTTP_PATH, CODE_HTTPS, CODE_WS, CODE_WSS, CODE_P2P_WEBSOCKET_STAR, CODE_P2P_STARDUST, CODE_P2P_WEBRTC_STAR, CODE_P2P_WEBRTC_DIRECT, CODE_WEBRTC_DIRECT, CODE_WEBRTC, CODE_P2P_CIRCUIT, CODE_MEMORY, ip4ToBytes, ip6ToBytes, ip4ToString, ip6ToString, decoders, anybaseDecoder, validatePort, V, Registry, registry, codecs, inspect, symbol, _a2, _components, _string, _bytes, _Multiaddr, Multiaddr, ASSUME_HTTP_CODES, interpreters, word, boundry, v4, v6segment, v6, v46Exact, v4exact, v6exact, ipRegex, toString3, DEFAULT_TINYCLOUD_LOCATION_REGISTRY_URL, LOCAL_LOOPBACK_PROBE_TIMEOUT_MS, LOCAL_LINK_PROBE_TIMEOUT_MS, LOCAL_LINK_HOST_SUFFIX, LocationRecordValidationError, defaultLocalNodeIdentityStore, DNS_LABEL_REGEX;
|
|
25544
26117
|
var init_dist4 = __esm({
|
|
25545
26118
|
"../sdk-core/dist/index.js"() {
|
|
25546
26119
|
"use strict";
|
|
@@ -26228,7 +26801,7 @@ var init_dist4 = __esm({
|
|
|
26228
26801
|
identity2 = { code: code2, name, encode: encode42, digest };
|
|
26229
26802
|
sha2_browser_exports = {};
|
|
26230
26803
|
__export3(sha2_browser_exports, {
|
|
26231
|
-
sha256: () =>
|
|
26804
|
+
sha256: () => sha25622,
|
|
26232
26805
|
sha512: () => sha5122
|
|
26233
26806
|
});
|
|
26234
26807
|
DEFAULT_MIN_DIGEST_LENGTH = 20;
|
|
@@ -26265,7 +26838,7 @@ var init_dist4 = __esm({
|
|
|
26265
26838
|
}
|
|
26266
26839
|
}
|
|
26267
26840
|
};
|
|
26268
|
-
|
|
26841
|
+
sha25622 = from22({
|
|
26269
26842
|
name: "sha2-256",
|
|
26270
26843
|
code: 18,
|
|
26271
26844
|
encode: sha("SHA-256")
|