@atbash/sdk 0.7.1-dev.0 → 0.8.0-dev.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/browser.d.mts +163 -1
- package/dist/browser.mjs +813 -95
- package/dist/browser.mjs.map +1 -1
- package/dist/index.d.mts +163 -1
- package/dist/index.d.ts +163 -1
- package/dist/index.js +6651 -3668
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6653 -3676
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -5
package/dist/browser.mjs
CHANGED
|
@@ -247,12 +247,12 @@ var require_bn = __commonJS({
|
|
|
247
247
|
}
|
|
248
248
|
this.strip();
|
|
249
249
|
};
|
|
250
|
-
function parseBase(str, start, end,
|
|
250
|
+
function parseBase(str, start, end, mul6) {
|
|
251
251
|
var r2 = 0;
|
|
252
252
|
var len = Math.min(str.length, end);
|
|
253
253
|
for (var i = start; i < len; i++) {
|
|
254
254
|
var c = str.charCodeAt(i) - 48;
|
|
255
|
-
r2 *=
|
|
255
|
+
r2 *= mul6;
|
|
256
256
|
if (c >= 49) {
|
|
257
257
|
r2 += c - 49 + 10;
|
|
258
258
|
} else if (c >= 17) {
|
|
@@ -1663,7 +1663,7 @@ var require_bn = __commonJS({
|
|
|
1663
1663
|
out.length = x.length + y.length;
|
|
1664
1664
|
return out.strip();
|
|
1665
1665
|
};
|
|
1666
|
-
BN2.prototype.mul = function
|
|
1666
|
+
BN2.prototype.mul = function mul6(num) {
|
|
1667
1667
|
var out = new BN2(null);
|
|
1668
1668
|
out.words = new Array(this.length + num.length);
|
|
1669
1669
|
return this.mulTo(num, out);
|
|
@@ -1916,7 +1916,7 @@ var require_bn = __commonJS({
|
|
|
1916
1916
|
BN2.prototype.abs = function abs2() {
|
|
1917
1917
|
return this.clone().iabs();
|
|
1918
1918
|
};
|
|
1919
|
-
BN2.prototype._ishlnsubmul = function _ishlnsubmul(num,
|
|
1919
|
+
BN2.prototype._ishlnsubmul = function _ishlnsubmul(num, mul6, shift) {
|
|
1920
1920
|
var len = num.length + shift;
|
|
1921
1921
|
var i;
|
|
1922
1922
|
this._expand(len);
|
|
@@ -1924,7 +1924,7 @@ var require_bn = __commonJS({
|
|
|
1924
1924
|
var carry = 0;
|
|
1925
1925
|
for (i = 0; i < num.length; i++) {
|
|
1926
1926
|
w = (this.words[i + shift] | 0) + carry;
|
|
1927
|
-
var right = (num.words[i] | 0) *
|
|
1927
|
+
var right = (num.words[i] | 0) * mul6;
|
|
1928
1928
|
w -= right & 67108863;
|
|
1929
1929
|
carry = (w >> 26) - (right / 67108864 | 0);
|
|
1930
1930
|
this.words[i + shift] = w & 67108863;
|
|
@@ -2686,7 +2686,7 @@ var require_bn = __commonJS({
|
|
|
2686
2686
|
this._verify2(a, b);
|
|
2687
2687
|
return this.imod(a.imul(b));
|
|
2688
2688
|
};
|
|
2689
|
-
Red.prototype.mul = function
|
|
2689
|
+
Red.prototype.mul = function mul6(a, b) {
|
|
2690
2690
|
this._verify2(a, b);
|
|
2691
2691
|
return this.imod(a.mul(b));
|
|
2692
2692
|
};
|
|
@@ -2837,7 +2837,7 @@ var require_bn = __commonJS({
|
|
|
2837
2837
|
}
|
|
2838
2838
|
return res._forceRed(this);
|
|
2839
2839
|
};
|
|
2840
|
-
Mont.prototype.mul = function
|
|
2840
|
+
Mont.prototype.mul = function mul6(a, b) {
|
|
2841
2841
|
if (a.isZero() || b.isZero()) return new BN2(0)._forceRed(this);
|
|
2842
2842
|
var t = a.mul(b);
|
|
2843
2843
|
var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
|
|
@@ -3034,11 +3034,11 @@ var HashMD = class {
|
|
|
3034
3034
|
length = 0;
|
|
3035
3035
|
pos = 0;
|
|
3036
3036
|
destroyed = false;
|
|
3037
|
-
constructor(blockLen, outputLen, padOffset,
|
|
3037
|
+
constructor(blockLen, outputLen, padOffset, isLE2) {
|
|
3038
3038
|
this.blockLen = blockLen;
|
|
3039
3039
|
this.outputLen = outputLen;
|
|
3040
3040
|
this.padOffset = padOffset;
|
|
3041
|
-
this.isLE =
|
|
3041
|
+
this.isLE = isLE2;
|
|
3042
3042
|
this.buffer = new Uint8Array(blockLen);
|
|
3043
3043
|
this.view = createView(this.buffer);
|
|
3044
3044
|
}
|
|
@@ -3071,7 +3071,7 @@ var HashMD = class {
|
|
|
3071
3071
|
aexists(this);
|
|
3072
3072
|
aoutput(out, this);
|
|
3073
3073
|
this.finished = true;
|
|
3074
|
-
const { buffer: buffer2, view, blockLen, isLE } = this;
|
|
3074
|
+
const { buffer: buffer2, view, blockLen, isLE: isLE2 } = this;
|
|
3075
3075
|
let { pos } = this;
|
|
3076
3076
|
buffer2[pos++] = 128;
|
|
3077
3077
|
clean(this.buffer.subarray(pos));
|
|
@@ -3081,7 +3081,7 @@ var HashMD = class {
|
|
|
3081
3081
|
}
|
|
3082
3082
|
for (let i = pos; i < blockLen; i++)
|
|
3083
3083
|
buffer2[i] = 0;
|
|
3084
|
-
view.setBigUint64(blockLen - 8, BigInt(this.length * 8),
|
|
3084
|
+
view.setBigUint64(blockLen - 8, BigInt(this.length * 8), isLE2);
|
|
3085
3085
|
this.process(view, 0);
|
|
3086
3086
|
const oview = createView(out);
|
|
3087
3087
|
const len = this.outputLen;
|
|
@@ -3092,7 +3092,7 @@ var HashMD = class {
|
|
|
3092
3092
|
if (outLen > state2.length)
|
|
3093
3093
|
throw new Error("_sha2: outputLen bigger than state");
|
|
3094
3094
|
for (let i = 0; i < outLen; i++)
|
|
3095
|
-
oview.setUint32(4 * i, state2[i],
|
|
3095
|
+
oview.setUint32(4 * i, state2[i], isLE2);
|
|
3096
3096
|
}
|
|
3097
3097
|
digest() {
|
|
3098
3098
|
const { buffer: buffer2, outputLen } = this;
|
|
@@ -3786,18 +3786,18 @@ var _Field = class {
|
|
|
3786
3786
|
}
|
|
3787
3787
|
fromBytes(bytes, skipValidation = false) {
|
|
3788
3788
|
abytes2(bytes);
|
|
3789
|
-
const { _lengths: allowedLengths, BYTES, isLE, ORDER, _mod: modFromBytes } = this;
|
|
3789
|
+
const { _lengths: allowedLengths, BYTES, isLE: isLE2, ORDER, _mod: modFromBytes } = this;
|
|
3790
3790
|
if (allowedLengths) {
|
|
3791
3791
|
if (bytes.length < 1 || !allowedLengths.includes(bytes.length) || bytes.length > BYTES) {
|
|
3792
3792
|
throw new Error("Field.fromBytes: expected " + allowedLengths + " bytes, got " + bytes.length);
|
|
3793
3793
|
}
|
|
3794
3794
|
const padded = new Uint8Array(BYTES);
|
|
3795
|
-
padded.set(bytes,
|
|
3795
|
+
padded.set(bytes, isLE2 ? 0 : padded.length - bytes.length);
|
|
3796
3796
|
bytes = padded;
|
|
3797
3797
|
}
|
|
3798
3798
|
if (bytes.length !== BYTES)
|
|
3799
3799
|
throw new Error("Field.fromBytes: expected " + BYTES + " bytes, got " + bytes.length);
|
|
3800
|
-
let scalar =
|
|
3800
|
+
let scalar = isLE2 ? bytesToNumberLE(bytes) : bytesToNumberBE(bytes);
|
|
3801
3801
|
if (modFromBytes)
|
|
3802
3802
|
scalar = mod(scalar, ORDER);
|
|
3803
3803
|
if (!skipValidation) {
|
|
@@ -3833,16 +3833,16 @@ function getMinHashLength(fieldOrder) {
|
|
|
3833
3833
|
const length = getFieldBytesLength(fieldOrder);
|
|
3834
3834
|
return length + Math.ceil(length / 2);
|
|
3835
3835
|
}
|
|
3836
|
-
function mapHashToField(key3, fieldOrder,
|
|
3836
|
+
function mapHashToField(key3, fieldOrder, isLE2 = false) {
|
|
3837
3837
|
abytes2(key3);
|
|
3838
3838
|
const len = key3.length;
|
|
3839
3839
|
const fieldLen = getFieldBytesLength(fieldOrder);
|
|
3840
3840
|
const minLen = Math.max(getMinHashLength(fieldOrder), 16);
|
|
3841
3841
|
if (len < minLen || len > 1024)
|
|
3842
3842
|
throw new Error("expected " + minLen + "-1024 bytes of input, got " + len);
|
|
3843
|
-
const num =
|
|
3843
|
+
const num = isLE2 ? bytesToNumberLE(key3) : bytesToNumberBE(key3);
|
|
3844
3844
|
const reduced = mod(num, fieldOrder - _1n2) + _1n2;
|
|
3845
|
-
return
|
|
3845
|
+
return isLE2 ? numberToBytesLE(reduced, fieldLen) : numberToBytesBE(reduced, fieldLen);
|
|
3846
3846
|
}
|
|
3847
3847
|
|
|
3848
3848
|
// node_modules/@noble/curves/abstract/curve.js
|
|
@@ -4041,14 +4041,14 @@ function mulEndoUnsafe(Point2, point5, k1, k2) {
|
|
|
4041
4041
|
}
|
|
4042
4042
|
return { p1, p2 };
|
|
4043
4043
|
}
|
|
4044
|
-
function createField(order, field,
|
|
4044
|
+
function createField(order, field, isLE2) {
|
|
4045
4045
|
if (field) {
|
|
4046
4046
|
if (field.ORDER !== order)
|
|
4047
4047
|
throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
|
|
4048
4048
|
validateField(field);
|
|
4049
4049
|
return field;
|
|
4050
4050
|
} else {
|
|
4051
|
-
return Field(order, { isLE });
|
|
4051
|
+
return Field(order, { isLE: isLE2 });
|
|
4052
4052
|
}
|
|
4053
4053
|
}
|
|
4054
4054
|
function createCurveFields(type2, CURVE, curveOpts = {}, FpFnLE) {
|
|
@@ -4639,15 +4639,15 @@ function weierstrass(params, extraOpts = {}) {
|
|
|
4639
4639
|
if (!Fn.isValidNot0(scalar))
|
|
4640
4640
|
throw new RangeError("invalid scalar: out of range");
|
|
4641
4641
|
let point5, fake;
|
|
4642
|
-
const
|
|
4642
|
+
const mul6 = (n) => wnaf.cached(this, n, (p) => normalizeZ(Point2, p));
|
|
4643
4643
|
if (endo2) {
|
|
4644
4644
|
const { k1neg, k1, k2neg, k2 } = splitEndoScalarN(scalar);
|
|
4645
|
-
const { p: k1p, f: k1f } =
|
|
4646
|
-
const { p: k2p, f: k2f } =
|
|
4645
|
+
const { p: k1p, f: k1f } = mul6(k1);
|
|
4646
|
+
const { p: k2p, f: k2f } = mul6(k2);
|
|
4647
4647
|
fake = k1f.add(k2f);
|
|
4648
4648
|
point5 = finishEndo(endo2.beta, k1p, k2p, k1neg, k2neg);
|
|
4649
4649
|
} else {
|
|
4650
|
-
const { p, f: f2 } =
|
|
4650
|
+
const { p, f: f2 } = mul6(scalar);
|
|
4651
4651
|
point5 = p;
|
|
4652
4652
|
fake = f2;
|
|
4653
4653
|
}
|
|
@@ -5241,14 +5241,14 @@ function fromByteArray(uint8) {
|
|
|
5241
5241
|
return parts.join("");
|
|
5242
5242
|
}
|
|
5243
5243
|
var ieee754 = {};
|
|
5244
|
-
ieee754.read = function(buffer2, offset,
|
|
5244
|
+
ieee754.read = function(buffer2, offset, isLE2, mLen, nBytes) {
|
|
5245
5245
|
var e, m;
|
|
5246
5246
|
var eLen = nBytes * 8 - mLen - 1;
|
|
5247
5247
|
var eMax = (1 << eLen) - 1;
|
|
5248
5248
|
var eBias = eMax >> 1;
|
|
5249
5249
|
var nBits = -7;
|
|
5250
|
-
var i =
|
|
5251
|
-
var d =
|
|
5250
|
+
var i = isLE2 ? nBytes - 1 : 0;
|
|
5251
|
+
var d = isLE2 ? -1 : 1;
|
|
5252
5252
|
var s2 = buffer2[offset + i];
|
|
5253
5253
|
i += d;
|
|
5254
5254
|
e = s2 & (1 << -nBits) - 1;
|
|
@@ -5271,14 +5271,14 @@ ieee754.read = function(buffer2, offset, isLE, mLen, nBytes) {
|
|
|
5271
5271
|
}
|
|
5272
5272
|
return (s2 ? -1 : 1) * m * Math.pow(2, e - mLen);
|
|
5273
5273
|
};
|
|
5274
|
-
ieee754.write = function(buffer2, value, offset,
|
|
5274
|
+
ieee754.write = function(buffer2, value, offset, isLE2, mLen, nBytes) {
|
|
5275
5275
|
var e, m, c;
|
|
5276
5276
|
var eLen = nBytes * 8 - mLen - 1;
|
|
5277
5277
|
var eMax = (1 << eLen) - 1;
|
|
5278
5278
|
var eBias = eMax >> 1;
|
|
5279
5279
|
var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
|
|
5280
|
-
var i =
|
|
5281
|
-
var d =
|
|
5280
|
+
var i = isLE2 ? 0 : nBytes - 1;
|
|
5281
|
+
var d = isLE2 ? 1 : -1;
|
|
5282
5282
|
var s2 = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
|
|
5283
5283
|
value = Math.abs(value);
|
|
5284
5284
|
if (isNaN(value) || value === Infinity) {
|
|
@@ -6163,10 +6163,10 @@ ieee754.write = function(buffer2, value, offset, isLE, mLen, nBytes) {
|
|
|
6163
6163
|
byteLength3 = byteLength3 >>> 0;
|
|
6164
6164
|
if (!noAssert) checkOffset(offset, byteLength3, this.length);
|
|
6165
6165
|
let val = this[offset];
|
|
6166
|
-
let
|
|
6166
|
+
let mul6 = 1;
|
|
6167
6167
|
let i = 0;
|
|
6168
|
-
while (++i < byteLength3 && (
|
|
6169
|
-
val += this[offset + i] *
|
|
6168
|
+
while (++i < byteLength3 && (mul6 *= 256)) {
|
|
6169
|
+
val += this[offset + i] * mul6;
|
|
6170
6170
|
}
|
|
6171
6171
|
return val;
|
|
6172
6172
|
};
|
|
@@ -6177,9 +6177,9 @@ ieee754.write = function(buffer2, value, offset, isLE, mLen, nBytes) {
|
|
|
6177
6177
|
checkOffset(offset, byteLength3, this.length);
|
|
6178
6178
|
}
|
|
6179
6179
|
let val = this[offset + --byteLength3];
|
|
6180
|
-
let
|
|
6181
|
-
while (byteLength3 > 0 && (
|
|
6182
|
-
val += this[offset + --byteLength3] *
|
|
6180
|
+
let mul6 = 1;
|
|
6181
|
+
while (byteLength3 > 0 && (mul6 *= 256)) {
|
|
6182
|
+
val += this[offset + --byteLength3] * mul6;
|
|
6183
6183
|
}
|
|
6184
6184
|
return val;
|
|
6185
6185
|
};
|
|
@@ -6237,13 +6237,13 @@ ieee754.write = function(buffer2, value, offset, isLE, mLen, nBytes) {
|
|
|
6237
6237
|
byteLength3 = byteLength3 >>> 0;
|
|
6238
6238
|
if (!noAssert) checkOffset(offset, byteLength3, this.length);
|
|
6239
6239
|
let val = this[offset];
|
|
6240
|
-
let
|
|
6240
|
+
let mul6 = 1;
|
|
6241
6241
|
let i = 0;
|
|
6242
|
-
while (++i < byteLength3 && (
|
|
6243
|
-
val += this[offset + i] *
|
|
6242
|
+
while (++i < byteLength3 && (mul6 *= 256)) {
|
|
6243
|
+
val += this[offset + i] * mul6;
|
|
6244
6244
|
}
|
|
6245
|
-
|
|
6246
|
-
if (val >=
|
|
6245
|
+
mul6 *= 128;
|
|
6246
|
+
if (val >= mul6) val -= Math.pow(2, 8 * byteLength3);
|
|
6247
6247
|
return val;
|
|
6248
6248
|
};
|
|
6249
6249
|
Buffer5.prototype.readIntBE = function readIntBE(offset, byteLength3, noAssert) {
|
|
@@ -6251,13 +6251,13 @@ ieee754.write = function(buffer2, value, offset, isLE, mLen, nBytes) {
|
|
|
6251
6251
|
byteLength3 = byteLength3 >>> 0;
|
|
6252
6252
|
if (!noAssert) checkOffset(offset, byteLength3, this.length);
|
|
6253
6253
|
let i = byteLength3;
|
|
6254
|
-
let
|
|
6254
|
+
let mul6 = 1;
|
|
6255
6255
|
let val = this[offset + --i];
|
|
6256
|
-
while (i > 0 && (
|
|
6257
|
-
val += this[offset + --i] *
|
|
6256
|
+
while (i > 0 && (mul6 *= 256)) {
|
|
6257
|
+
val += this[offset + --i] * mul6;
|
|
6258
6258
|
}
|
|
6259
|
-
|
|
6260
|
-
if (val >=
|
|
6259
|
+
mul6 *= 128;
|
|
6260
|
+
if (val >= mul6) val -= Math.pow(2, 8 * byteLength3);
|
|
6261
6261
|
return val;
|
|
6262
6262
|
};
|
|
6263
6263
|
Buffer5.prototype.readInt8 = function readInt8(offset, noAssert) {
|
|
@@ -6344,11 +6344,11 @@ ieee754.write = function(buffer2, value, offset, isLE, mLen, nBytes) {
|
|
|
6344
6344
|
const maxBytes = Math.pow(2, 8 * byteLength3) - 1;
|
|
6345
6345
|
checkInt(this, value, offset, byteLength3, maxBytes, 0);
|
|
6346
6346
|
}
|
|
6347
|
-
let
|
|
6347
|
+
let mul6 = 1;
|
|
6348
6348
|
let i = 0;
|
|
6349
6349
|
this[offset] = value & 255;
|
|
6350
|
-
while (++i < byteLength3 && (
|
|
6351
|
-
this[offset + i] = value /
|
|
6350
|
+
while (++i < byteLength3 && (mul6 *= 256)) {
|
|
6351
|
+
this[offset + i] = value / mul6 & 255;
|
|
6352
6352
|
}
|
|
6353
6353
|
return offset + byteLength3;
|
|
6354
6354
|
};
|
|
@@ -6361,10 +6361,10 @@ ieee754.write = function(buffer2, value, offset, isLE, mLen, nBytes) {
|
|
|
6361
6361
|
checkInt(this, value, offset, byteLength3, maxBytes, 0);
|
|
6362
6362
|
}
|
|
6363
6363
|
let i = byteLength3 - 1;
|
|
6364
|
-
let
|
|
6364
|
+
let mul6 = 1;
|
|
6365
6365
|
this[offset + i] = value & 255;
|
|
6366
|
-
while (--i >= 0 && (
|
|
6367
|
-
this[offset + i] = value /
|
|
6366
|
+
while (--i >= 0 && (mul6 *= 256)) {
|
|
6367
|
+
this[offset + i] = value / mul6 & 255;
|
|
6368
6368
|
}
|
|
6369
6369
|
return offset + byteLength3;
|
|
6370
6370
|
};
|
|
@@ -6465,14 +6465,14 @@ ieee754.write = function(buffer2, value, offset, isLE, mLen, nBytes) {
|
|
|
6465
6465
|
checkInt(this, value, offset, byteLength3, limit - 1, -limit);
|
|
6466
6466
|
}
|
|
6467
6467
|
let i = 0;
|
|
6468
|
-
let
|
|
6468
|
+
let mul6 = 1;
|
|
6469
6469
|
let sub = 0;
|
|
6470
6470
|
this[offset] = value & 255;
|
|
6471
|
-
while (++i < byteLength3 && (
|
|
6471
|
+
while (++i < byteLength3 && (mul6 *= 256)) {
|
|
6472
6472
|
if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
|
|
6473
6473
|
sub = 1;
|
|
6474
6474
|
}
|
|
6475
|
-
this[offset + i] = (value /
|
|
6475
|
+
this[offset + i] = (value / mul6 >> 0) - sub & 255;
|
|
6476
6476
|
}
|
|
6477
6477
|
return offset + byteLength3;
|
|
6478
6478
|
};
|
|
@@ -6484,14 +6484,14 @@ ieee754.write = function(buffer2, value, offset, isLE, mLen, nBytes) {
|
|
|
6484
6484
|
checkInt(this, value, offset, byteLength3, limit - 1, -limit);
|
|
6485
6485
|
}
|
|
6486
6486
|
let i = byteLength3 - 1;
|
|
6487
|
-
let
|
|
6487
|
+
let mul6 = 1;
|
|
6488
6488
|
let sub = 0;
|
|
6489
6489
|
this[offset + i] = value & 255;
|
|
6490
|
-
while (--i >= 0 && (
|
|
6490
|
+
while (--i >= 0 && (mul6 *= 256)) {
|
|
6491
6491
|
if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
|
|
6492
6492
|
sub = 1;
|
|
6493
6493
|
}
|
|
6494
|
-
this[offset + i] = (value /
|
|
6494
|
+
this[offset + i] = (value / mul6 >> 0) - sub & 255;
|
|
6495
6495
|
}
|
|
6496
6496
|
return offset + byteLength3;
|
|
6497
6497
|
};
|
|
@@ -7228,12 +7228,12 @@ bn$1.exports;
|
|
|
7228
7228
|
}
|
|
7229
7229
|
this.strip();
|
|
7230
7230
|
};
|
|
7231
|
-
function parseBase(str, start, end,
|
|
7231
|
+
function parseBase(str, start, end, mul6) {
|
|
7232
7232
|
var r2 = 0;
|
|
7233
7233
|
var len = Math.min(str.length, end);
|
|
7234
7234
|
for (var i = start; i < len; i++) {
|
|
7235
7235
|
var c = str.charCodeAt(i) - 48;
|
|
7236
|
-
r2 *=
|
|
7236
|
+
r2 *= mul6;
|
|
7237
7237
|
if (c >= 49) {
|
|
7238
7238
|
r2 += c - 49 + 10;
|
|
7239
7239
|
} else if (c >= 17) {
|
|
@@ -8640,7 +8640,7 @@ bn$1.exports;
|
|
|
8640
8640
|
out.length = x.length + y.length;
|
|
8641
8641
|
return out.strip();
|
|
8642
8642
|
};
|
|
8643
|
-
BN2.prototype.mul = function
|
|
8643
|
+
BN2.prototype.mul = function mul6(num) {
|
|
8644
8644
|
var out = new BN2(null);
|
|
8645
8645
|
out.words = new Array(this.length + num.length);
|
|
8646
8646
|
return this.mulTo(num, out);
|
|
@@ -8886,7 +8886,7 @@ bn$1.exports;
|
|
|
8886
8886
|
BN2.prototype.abs = function abs2() {
|
|
8887
8887
|
return this.clone().iabs();
|
|
8888
8888
|
};
|
|
8889
|
-
BN2.prototype._ishlnsubmul = function _ishlnsubmul(num,
|
|
8889
|
+
BN2.prototype._ishlnsubmul = function _ishlnsubmul(num, mul6, shift) {
|
|
8890
8890
|
var len = num.length + shift;
|
|
8891
8891
|
var i;
|
|
8892
8892
|
this._expand(len);
|
|
@@ -8894,7 +8894,7 @@ bn$1.exports;
|
|
|
8894
8894
|
var carry = 0;
|
|
8895
8895
|
for (i = 0; i < num.length; i++) {
|
|
8896
8896
|
w = (this.words[i + shift] | 0) + carry;
|
|
8897
|
-
var right = (num.words[i] | 0) *
|
|
8897
|
+
var right = (num.words[i] | 0) * mul6;
|
|
8898
8898
|
w -= right & 67108863;
|
|
8899
8899
|
carry = (w >> 26) - (right / 67108864 | 0);
|
|
8900
8900
|
this.words[i + shift] = w & 67108863;
|
|
@@ -9654,7 +9654,7 @@ bn$1.exports;
|
|
|
9654
9654
|
this._verify2(a, b);
|
|
9655
9655
|
return this.imod(a.imul(b));
|
|
9656
9656
|
};
|
|
9657
|
-
Red.prototype.mul = function
|
|
9657
|
+
Red.prototype.mul = function mul6(a, b) {
|
|
9658
9658
|
this._verify2(a, b);
|
|
9659
9659
|
return this.imod(a.mul(b));
|
|
9660
9660
|
};
|
|
@@ -9805,7 +9805,7 @@ bn$1.exports;
|
|
|
9805
9805
|
}
|
|
9806
9806
|
return res._forceRed(this);
|
|
9807
9807
|
};
|
|
9808
|
-
Mont.prototype.mul = function
|
|
9808
|
+
Mont.prototype.mul = function mul6(a, b) {
|
|
9809
9809
|
if (a.isZero() || b.isZero()) return new BN2(0)._forceRed(this);
|
|
9810
9810
|
var t = a.mul(b);
|
|
9811
9811
|
var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
|
|
@@ -21507,20 +21507,20 @@ function calcIv(self2, iv, ck) {
|
|
|
21507
21507
|
self2._finID = Buffer$c.concat([iv, Buffer$c.from([0, 0, 0, 1])]);
|
|
21508
21508
|
return Buffer$c.concat([iv, Buffer$c.from([0, 0, 0, 2])]);
|
|
21509
21509
|
}
|
|
21510
|
-
var
|
|
21510
|
+
var ghash3 = new GHASH(ck);
|
|
21511
21511
|
var len = iv.length;
|
|
21512
21512
|
var toPad = len % 16;
|
|
21513
|
-
|
|
21513
|
+
ghash3.update(iv);
|
|
21514
21514
|
if (toPad) {
|
|
21515
21515
|
toPad = 16 - toPad;
|
|
21516
|
-
|
|
21516
|
+
ghash3.update(Buffer$c.alloc(toPad, 0));
|
|
21517
21517
|
}
|
|
21518
|
-
|
|
21518
|
+
ghash3.update(Buffer$c.alloc(8, 0));
|
|
21519
21519
|
var ivBits = len * 8;
|
|
21520
21520
|
var tail = Buffer$c.alloc(8);
|
|
21521
21521
|
tail.writeUIntBE(ivBits, 0, 8);
|
|
21522
|
-
|
|
21523
|
-
self2._finID =
|
|
21522
|
+
ghash3.update(tail);
|
|
21523
|
+
self2._finID = ghash3.state;
|
|
21524
21524
|
var out = Buffer$c.from(self2._finID);
|
|
21525
21525
|
incr32(out);
|
|
21526
21526
|
return out;
|
|
@@ -22612,13 +22612,13 @@ bn.exports;
|
|
|
22612
22612
|
}
|
|
22613
22613
|
this._strip();
|
|
22614
22614
|
};
|
|
22615
|
-
function parseBase(str, start, end,
|
|
22615
|
+
function parseBase(str, start, end, mul6) {
|
|
22616
22616
|
var r2 = 0;
|
|
22617
22617
|
var b = 0;
|
|
22618
22618
|
var len = Math.min(str.length, end);
|
|
22619
22619
|
for (var i = start; i < len; i++) {
|
|
22620
22620
|
var c = str.charCodeAt(i) - 48;
|
|
22621
|
-
r2 *=
|
|
22621
|
+
r2 *= mul6;
|
|
22622
22622
|
if (c >= 49) {
|
|
22623
22623
|
b = c - 49 + 10;
|
|
22624
22624
|
} else if (c >= 17) {
|
|
@@ -22626,7 +22626,7 @@ bn.exports;
|
|
|
22626
22626
|
} else {
|
|
22627
22627
|
b = c;
|
|
22628
22628
|
}
|
|
22629
|
-
assert2(c >= 0 && b <
|
|
22629
|
+
assert2(c >= 0 && b < mul6, "Invalid character");
|
|
22630
22630
|
r2 += b;
|
|
22631
22631
|
}
|
|
22632
22632
|
return r2;
|
|
@@ -23950,7 +23950,7 @@ bn.exports;
|
|
|
23950
23950
|
}
|
|
23951
23951
|
return res;
|
|
23952
23952
|
};
|
|
23953
|
-
BN2.prototype.mul = function
|
|
23953
|
+
BN2.prototype.mul = function mul6(num) {
|
|
23954
23954
|
var out = new BN2(null);
|
|
23955
23955
|
out.words = new Array(this.length + num.length);
|
|
23956
23956
|
return this.mulTo(num, out);
|
|
@@ -24198,7 +24198,7 @@ bn.exports;
|
|
|
24198
24198
|
BN2.prototype.abs = function abs2() {
|
|
24199
24199
|
return this.clone().iabs();
|
|
24200
24200
|
};
|
|
24201
|
-
BN2.prototype._ishlnsubmul = function _ishlnsubmul(num,
|
|
24201
|
+
BN2.prototype._ishlnsubmul = function _ishlnsubmul(num, mul6, shift) {
|
|
24202
24202
|
var len = num.length + shift;
|
|
24203
24203
|
var i;
|
|
24204
24204
|
this._expand(len);
|
|
@@ -24206,7 +24206,7 @@ bn.exports;
|
|
|
24206
24206
|
var carry = 0;
|
|
24207
24207
|
for (i = 0; i < num.length; i++) {
|
|
24208
24208
|
w = (this.words[i + shift] | 0) + carry;
|
|
24209
|
-
var right = (num.words[i] | 0) *
|
|
24209
|
+
var right = (num.words[i] | 0) * mul6;
|
|
24210
24210
|
w -= right & 67108863;
|
|
24211
24211
|
carry = (w >> 26) - (right / 67108864 | 0);
|
|
24212
24212
|
this.words[i + shift] = w & 67108863;
|
|
@@ -24975,7 +24975,7 @@ bn.exports;
|
|
|
24975
24975
|
this._verify2(a, b);
|
|
24976
24976
|
return this.imod(a.imul(b));
|
|
24977
24977
|
};
|
|
24978
|
-
Red.prototype.mul = function
|
|
24978
|
+
Red.prototype.mul = function mul6(a, b) {
|
|
24979
24979
|
this._verify2(a, b);
|
|
24980
24980
|
return this.imod(a.mul(b));
|
|
24981
24981
|
};
|
|
@@ -25126,7 +25126,7 @@ bn.exports;
|
|
|
25126
25126
|
}
|
|
25127
25127
|
return res._forceRed(this);
|
|
25128
25128
|
};
|
|
25129
|
-
Mont.prototype.mul = function
|
|
25129
|
+
Mont.prototype.mul = function mul6(a, b) {
|
|
25130
25130
|
if (a.isZero() || b.isZero()) return new BN2(0)._forceRed(this);
|
|
25131
25131
|
var t = a.mul(b);
|
|
25132
25132
|
var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
|
|
@@ -43292,8 +43292,8 @@ function loadAgent(privkey) {
|
|
|
43292
43292
|
if (!isValidPrivateKey(privkey)) {
|
|
43293
43293
|
throw new Error("invalid private key \u2014 must be 64 hex characters (secp256k1)");
|
|
43294
43294
|
}
|
|
43295
|
-
const
|
|
43296
|
-
return { privkey:
|
|
43295
|
+
const clean3 = stripHex(privkey);
|
|
43296
|
+
return { privkey: clean3, pubkey: derivePublicKey(clean3) };
|
|
43297
43297
|
}
|
|
43298
43298
|
function signOp(opName, args, privkeyHex, blockchainRidHex) {
|
|
43299
43299
|
if (!isValidPrivateKey(privkeyHex)) {
|
|
@@ -43440,6 +43440,695 @@ function chainForNetwork(network) {
|
|
|
43440
43440
|
return network === "private" ? PRIVATE_CHAIN : PUBLIC_CHAIN;
|
|
43441
43441
|
}
|
|
43442
43442
|
|
|
43443
|
+
// node_modules/@noble/hashes/hkdf.js
|
|
43444
|
+
function extract(hash3, ikm, salt) {
|
|
43445
|
+
ahash(hash3);
|
|
43446
|
+
if (salt === void 0)
|
|
43447
|
+
salt = new Uint8Array(hash3.outputLen);
|
|
43448
|
+
return hmac(hash3, salt, ikm);
|
|
43449
|
+
}
|
|
43450
|
+
var HKDF_COUNTER = /* @__PURE__ */ Uint8Array.of(0);
|
|
43451
|
+
var EMPTY_BUFFER = /* @__PURE__ */ Uint8Array.of();
|
|
43452
|
+
function expand2(hash3, prk, info2, length = 32) {
|
|
43453
|
+
ahash(hash3);
|
|
43454
|
+
anumber(length, "length");
|
|
43455
|
+
abytes(prk, void 0, "prk");
|
|
43456
|
+
const olen = hash3.outputLen;
|
|
43457
|
+
if (prk.length < olen)
|
|
43458
|
+
throw new Error('"prk" must be at least HashLen octets');
|
|
43459
|
+
if (length > 255 * olen)
|
|
43460
|
+
throw new Error("Length must be <= 255*HashLen");
|
|
43461
|
+
const blocks = Math.ceil(length / olen);
|
|
43462
|
+
if (info2 === void 0)
|
|
43463
|
+
info2 = EMPTY_BUFFER;
|
|
43464
|
+
else
|
|
43465
|
+
abytes(info2, void 0, "info");
|
|
43466
|
+
const okm = new Uint8Array(blocks * olen);
|
|
43467
|
+
const HMAC = hmac.create(hash3, prk);
|
|
43468
|
+
const HMACTmp = HMAC._cloneInto();
|
|
43469
|
+
const T = new Uint8Array(HMAC.outputLen);
|
|
43470
|
+
for (let counter = 0; counter < blocks; counter++) {
|
|
43471
|
+
HKDF_COUNTER[0] = counter + 1;
|
|
43472
|
+
HMACTmp.update(counter === 0 ? EMPTY_BUFFER : T).update(info2).update(HKDF_COUNTER).digestInto(T);
|
|
43473
|
+
okm.set(T, olen * counter);
|
|
43474
|
+
HMAC._cloneInto(HMACTmp);
|
|
43475
|
+
}
|
|
43476
|
+
HMAC.destroy();
|
|
43477
|
+
HMACTmp.destroy();
|
|
43478
|
+
clean(T, HKDF_COUNTER);
|
|
43479
|
+
return okm.slice(0, length);
|
|
43480
|
+
}
|
|
43481
|
+
var hkdf = (hash3, ikm, salt, info2, length) => expand2(hash3, extract(hash3, ikm, salt), info2, length);
|
|
43482
|
+
|
|
43483
|
+
// node_modules/@noble/ciphers/utils.js
|
|
43484
|
+
function isBytes3(a) {
|
|
43485
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
|
|
43486
|
+
}
|
|
43487
|
+
function abool2(b) {
|
|
43488
|
+
if (typeof b !== "boolean")
|
|
43489
|
+
throw new TypeError(`boolean expected, not ${b}`);
|
|
43490
|
+
}
|
|
43491
|
+
function anumber3(n) {
|
|
43492
|
+
if (typeof n !== "number")
|
|
43493
|
+
throw new TypeError("number expected, got " + typeof n);
|
|
43494
|
+
if (!Number.isSafeInteger(n) || n < 0)
|
|
43495
|
+
throw new RangeError("positive integer expected, got " + n);
|
|
43496
|
+
}
|
|
43497
|
+
function abytes3(value, length, title = "") {
|
|
43498
|
+
const bytes = isBytes3(value);
|
|
43499
|
+
const len = value?.length;
|
|
43500
|
+
const needsLen = length !== void 0;
|
|
43501
|
+
if (!bytes || needsLen && len !== length) {
|
|
43502
|
+
const prefix = title && `"${title}" `;
|
|
43503
|
+
const ofLen = needsLen ? ` of length ${length}` : "";
|
|
43504
|
+
const got = bytes ? `length=${len}` : `type=${typeof value}`;
|
|
43505
|
+
const message = prefix + "expected Uint8Array" + ofLen + ", got " + got;
|
|
43506
|
+
if (!bytes)
|
|
43507
|
+
throw new TypeError(message);
|
|
43508
|
+
throw new RangeError(message);
|
|
43509
|
+
}
|
|
43510
|
+
return value;
|
|
43511
|
+
}
|
|
43512
|
+
function aexists2(instance, checkFinished = true) {
|
|
43513
|
+
if (instance.destroyed)
|
|
43514
|
+
throw new Error("Hash instance has been destroyed");
|
|
43515
|
+
if (checkFinished && instance.finished)
|
|
43516
|
+
throw new Error("Hash#digest() has already been called");
|
|
43517
|
+
}
|
|
43518
|
+
function aoutput2(out, instance, onlyAligned = false) {
|
|
43519
|
+
abytes3(out, void 0, "output");
|
|
43520
|
+
const min2 = instance.outputLen;
|
|
43521
|
+
if (out.length < min2) {
|
|
43522
|
+
throw new RangeError("digestInto() expects output buffer of length at least " + min2);
|
|
43523
|
+
}
|
|
43524
|
+
if (onlyAligned && !isAligned32(out))
|
|
43525
|
+
throw new Error("invalid output, must be aligned");
|
|
43526
|
+
}
|
|
43527
|
+
function u8(arr) {
|
|
43528
|
+
return new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
43529
|
+
}
|
|
43530
|
+
function u32(arr) {
|
|
43531
|
+
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
43532
|
+
}
|
|
43533
|
+
function clean2(...arrays) {
|
|
43534
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
43535
|
+
arrays[i].fill(0);
|
|
43536
|
+
}
|
|
43537
|
+
}
|
|
43538
|
+
function createView2(arr) {
|
|
43539
|
+
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
43540
|
+
}
|
|
43541
|
+
var isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
|
|
43542
|
+
var byteSwap = (word) => word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
|
|
43543
|
+
var swap8IfBE = isLE ? (n) => n : (n) => byteSwap(n) >>> 0;
|
|
43544
|
+
var byteSwap32 = (arr) => {
|
|
43545
|
+
for (let i = 0; i < arr.length; i++)
|
|
43546
|
+
arr[i] = byteSwap(arr[i]);
|
|
43547
|
+
return arr;
|
|
43548
|
+
};
|
|
43549
|
+
var swap32IfBE = isLE ? (u) => u : byteSwap32;
|
|
43550
|
+
function equalBytes(a, b) {
|
|
43551
|
+
if (a.length !== b.length)
|
|
43552
|
+
return false;
|
|
43553
|
+
let diff = 0;
|
|
43554
|
+
for (let i = 0; i < a.length; i++)
|
|
43555
|
+
diff |= a[i] ^ b[i];
|
|
43556
|
+
return diff === 0;
|
|
43557
|
+
}
|
|
43558
|
+
function wrapMacConstructor(keyLen, macCons, fromMsg) {
|
|
43559
|
+
const mac = macCons;
|
|
43560
|
+
const getArgs = fromMsg || (() => []);
|
|
43561
|
+
const macC = (msg, key3) => mac(key3, ...getArgs(msg)).update(msg).digest();
|
|
43562
|
+
const tmp = mac(new Uint8Array(keyLen), ...getArgs(new Uint8Array(0)));
|
|
43563
|
+
macC.outputLen = tmp.outputLen;
|
|
43564
|
+
macC.blockLen = tmp.blockLen;
|
|
43565
|
+
macC.create = (key3, ...args) => mac(key3, ...args);
|
|
43566
|
+
return macC;
|
|
43567
|
+
}
|
|
43568
|
+
var wrapCipher = /* @__NO_SIDE_EFFECTS__ */ (params, constructor) => {
|
|
43569
|
+
function wrappedCipher(key3, ...args) {
|
|
43570
|
+
abytes3(key3, void 0, "key");
|
|
43571
|
+
if (params.nonceLength !== void 0) {
|
|
43572
|
+
const nonce = args[0];
|
|
43573
|
+
abytes3(nonce, params.varSizeNonce ? void 0 : params.nonceLength, "nonce");
|
|
43574
|
+
}
|
|
43575
|
+
const tagl = params.tagLength;
|
|
43576
|
+
if (tagl && args[1] !== void 0)
|
|
43577
|
+
abytes3(args[1], void 0, "AAD");
|
|
43578
|
+
const cipher2 = constructor(key3, ...args);
|
|
43579
|
+
const checkOutput = (fnLength, output) => {
|
|
43580
|
+
if (output !== void 0) {
|
|
43581
|
+
if (fnLength !== 2)
|
|
43582
|
+
throw new Error("cipher output not supported");
|
|
43583
|
+
abytes3(output, void 0, "output");
|
|
43584
|
+
}
|
|
43585
|
+
};
|
|
43586
|
+
let called = false;
|
|
43587
|
+
const wrCipher = {
|
|
43588
|
+
encrypt(data, output) {
|
|
43589
|
+
if (called)
|
|
43590
|
+
throw new Error("cannot encrypt() twice with same key + nonce");
|
|
43591
|
+
called = true;
|
|
43592
|
+
abytes3(data);
|
|
43593
|
+
checkOutput(cipher2.encrypt.length, output);
|
|
43594
|
+
return cipher2.encrypt(data, output);
|
|
43595
|
+
},
|
|
43596
|
+
decrypt(data, output) {
|
|
43597
|
+
abytes3(data);
|
|
43598
|
+
if (tagl && data.length < tagl)
|
|
43599
|
+
throw new Error('"ciphertext" expected length bigger than tagLength=' + tagl);
|
|
43600
|
+
checkOutput(cipher2.decrypt.length, output);
|
|
43601
|
+
return cipher2.decrypt(data, output);
|
|
43602
|
+
}
|
|
43603
|
+
};
|
|
43604
|
+
return wrCipher;
|
|
43605
|
+
}
|
|
43606
|
+
Object.assign(wrappedCipher, params);
|
|
43607
|
+
return wrappedCipher;
|
|
43608
|
+
};
|
|
43609
|
+
function getOutput(expectedLength, out, onlyAligned = true) {
|
|
43610
|
+
if (out === void 0)
|
|
43611
|
+
return new Uint8Array(expectedLength);
|
|
43612
|
+
abytes3(out, void 0, "output");
|
|
43613
|
+
if (out.length !== expectedLength)
|
|
43614
|
+
throw new Error('"output" expected Uint8Array of length ' + expectedLength + ", got: " + out.length);
|
|
43615
|
+
if (onlyAligned && !isAligned32(out))
|
|
43616
|
+
throw new Error("invalid output, must be aligned");
|
|
43617
|
+
return out;
|
|
43618
|
+
}
|
|
43619
|
+
function u64Lengths(dataLength, aadLength, isLE2) {
|
|
43620
|
+
anumber3(dataLength);
|
|
43621
|
+
anumber3(aadLength);
|
|
43622
|
+
abool2(isLE2);
|
|
43623
|
+
const num = new Uint8Array(16);
|
|
43624
|
+
const view = createView2(num);
|
|
43625
|
+
view.setBigUint64(0, BigInt(aadLength), isLE2);
|
|
43626
|
+
view.setBigUint64(8, BigInt(dataLength), isLE2);
|
|
43627
|
+
return num;
|
|
43628
|
+
}
|
|
43629
|
+
function isAligned32(bytes) {
|
|
43630
|
+
return bytes.byteOffset % 4 === 0;
|
|
43631
|
+
}
|
|
43632
|
+
function copyBytes2(bytes) {
|
|
43633
|
+
return Uint8Array.from(abytes3(bytes));
|
|
43634
|
+
}
|
|
43635
|
+
|
|
43636
|
+
// node_modules/@noble/ciphers/_polyval.js
|
|
43637
|
+
var BLOCK_SIZE = 16;
|
|
43638
|
+
var ZEROS16 = /* @__PURE__ */ new Uint8Array(16);
|
|
43639
|
+
var ZEROS32 = /* @__PURE__ */ u32(ZEROS16);
|
|
43640
|
+
var POLY = 225;
|
|
43641
|
+
var mul22 = (s0, s1, s2, s3) => {
|
|
43642
|
+
const hiBit = s3 & 1;
|
|
43643
|
+
return {
|
|
43644
|
+
s3: s2 << 31 | s3 >>> 1,
|
|
43645
|
+
s2: s1 << 31 | s2 >>> 1,
|
|
43646
|
+
s1: s0 << 31 | s1 >>> 1,
|
|
43647
|
+
// NIST SP 800-38D §6.3 applies `V >> 1` and XORs R on carry. In this
|
|
43648
|
+
// 4x32-bit split, R = 0xe1 || 0^120 lives in the top byte of s0.
|
|
43649
|
+
s0: s0 >>> 1 ^ POLY << 24 & -(hiBit & 1)
|
|
43650
|
+
// reduce % poly
|
|
43651
|
+
};
|
|
43652
|
+
};
|
|
43653
|
+
var swapLE = (n) => (n >>> 0 & 255) << 24 | (n >>> 8 & 255) << 16 | (n >>> 16 & 255) << 8 | n >>> 24 & 255 | 0;
|
|
43654
|
+
var estimateWindow = (bytes) => {
|
|
43655
|
+
if (bytes > 64 * 1024)
|
|
43656
|
+
return 8;
|
|
43657
|
+
if (bytes > 1024)
|
|
43658
|
+
return 4;
|
|
43659
|
+
return 2;
|
|
43660
|
+
};
|
|
43661
|
+
var GHASH2 = class {
|
|
43662
|
+
blockLen = BLOCK_SIZE;
|
|
43663
|
+
outputLen = BLOCK_SIZE;
|
|
43664
|
+
s0 = 0;
|
|
43665
|
+
s1 = 0;
|
|
43666
|
+
s2 = 0;
|
|
43667
|
+
s3 = 0;
|
|
43668
|
+
finished = false;
|
|
43669
|
+
destroyed = false;
|
|
43670
|
+
t;
|
|
43671
|
+
W;
|
|
43672
|
+
windowSize;
|
|
43673
|
+
// We select bits per window adaptively based on expectedLength
|
|
43674
|
+
constructor(key3, expectedLength) {
|
|
43675
|
+
abytes3(key3, 16, "key");
|
|
43676
|
+
key3 = copyBytes2(key3);
|
|
43677
|
+
const kView = createView2(key3);
|
|
43678
|
+
let k0 = kView.getUint32(0, false);
|
|
43679
|
+
let k1 = kView.getUint32(4, false);
|
|
43680
|
+
let k2 = kView.getUint32(8, false);
|
|
43681
|
+
let k3 = kView.getUint32(12, false);
|
|
43682
|
+
const doubles = [];
|
|
43683
|
+
for (let i = 0; i < 128; i++) {
|
|
43684
|
+
doubles.push({ s0: swapLE(k0), s1: swapLE(k1), s2: swapLE(k2), s3: swapLE(k3) });
|
|
43685
|
+
({ s0: k0, s1: k1, s2: k2, s3: k3 } = mul22(k0, k1, k2, k3));
|
|
43686
|
+
}
|
|
43687
|
+
const W2 = estimateWindow(expectedLength || 1024);
|
|
43688
|
+
if (![1, 2, 4, 8].includes(W2))
|
|
43689
|
+
throw new Error("ghash: invalid window size, expected 2, 4 or 8");
|
|
43690
|
+
this.W = W2;
|
|
43691
|
+
const bits = 128;
|
|
43692
|
+
const windows = bits / W2;
|
|
43693
|
+
const windowSize = this.windowSize = 2 ** W2;
|
|
43694
|
+
const items = [];
|
|
43695
|
+
for (let w = 0; w < windows; w++) {
|
|
43696
|
+
for (let byte = 0; byte < windowSize; byte++) {
|
|
43697
|
+
let s0 = 0, s1 = 0, s2 = 0, s3 = 0;
|
|
43698
|
+
for (let j = 0; j < W2; j++) {
|
|
43699
|
+
const bit = byte >>> W2 - j - 1 & 1;
|
|
43700
|
+
if (!bit)
|
|
43701
|
+
continue;
|
|
43702
|
+
const { s0: d0, s1: d1, s2: d2, s3: d3 } = doubles[W2 * w + j];
|
|
43703
|
+
s0 ^= d0, s1 ^= d1, s2 ^= d2, s3 ^= d3;
|
|
43704
|
+
}
|
|
43705
|
+
items.push({ s0, s1, s2, s3 });
|
|
43706
|
+
}
|
|
43707
|
+
}
|
|
43708
|
+
this.t = items;
|
|
43709
|
+
}
|
|
43710
|
+
_updateBlock(s0, s1, s2, s3) {
|
|
43711
|
+
s0 ^= this.s0, s1 ^= this.s1, s2 ^= this.s2, s3 ^= this.s3;
|
|
43712
|
+
const { W: W2, t, windowSize } = this;
|
|
43713
|
+
let o0 = 0, o1 = 0, o2 = 0, o3 = 0;
|
|
43714
|
+
const mask = (1 << W2) - 1;
|
|
43715
|
+
let w = 0;
|
|
43716
|
+
for (const num of [s0, s1, s2, s3]) {
|
|
43717
|
+
for (let bytePos = 0; bytePos < 4; bytePos++) {
|
|
43718
|
+
const byte = num >>> 8 * bytePos & 255;
|
|
43719
|
+
for (let bitPos = 8 / W2 - 1; bitPos >= 0; bitPos--) {
|
|
43720
|
+
const bit = byte >>> W2 * bitPos & mask;
|
|
43721
|
+
const { s0: e0, s1: e1, s2: e2, s3: e3 } = t[w * windowSize + bit];
|
|
43722
|
+
o0 ^= e0, o1 ^= e1, o2 ^= e2, o3 ^= e3;
|
|
43723
|
+
w += 1;
|
|
43724
|
+
}
|
|
43725
|
+
}
|
|
43726
|
+
}
|
|
43727
|
+
this.s0 = o0;
|
|
43728
|
+
this.s1 = o1;
|
|
43729
|
+
this.s2 = o2;
|
|
43730
|
+
this.s3 = o3;
|
|
43731
|
+
}
|
|
43732
|
+
update(data) {
|
|
43733
|
+
aexists2(this);
|
|
43734
|
+
abytes3(data);
|
|
43735
|
+
data = copyBytes2(data);
|
|
43736
|
+
const b32 = u32(data);
|
|
43737
|
+
const blocks = Math.floor(data.length / BLOCK_SIZE);
|
|
43738
|
+
const left = data.length % BLOCK_SIZE;
|
|
43739
|
+
for (let i = 0; i < blocks; i++) {
|
|
43740
|
+
this._updateBlock(swap8IfBE(b32[i * 4 + 0]), swap8IfBE(b32[i * 4 + 1]), swap8IfBE(b32[i * 4 + 2]), swap8IfBE(b32[i * 4 + 3]));
|
|
43741
|
+
}
|
|
43742
|
+
if (left) {
|
|
43743
|
+
ZEROS16.set(data.subarray(blocks * BLOCK_SIZE));
|
|
43744
|
+
this._updateBlock(swap8IfBE(ZEROS32[0]), swap8IfBE(ZEROS32[1]), swap8IfBE(ZEROS32[2]), swap8IfBE(ZEROS32[3]));
|
|
43745
|
+
clean2(ZEROS32);
|
|
43746
|
+
}
|
|
43747
|
+
return this;
|
|
43748
|
+
}
|
|
43749
|
+
destroy() {
|
|
43750
|
+
this.destroyed = true;
|
|
43751
|
+
const { t } = this;
|
|
43752
|
+
for (const elm of t) {
|
|
43753
|
+
elm.s0 = 0, elm.s1 = 0, elm.s2 = 0, elm.s3 = 0;
|
|
43754
|
+
}
|
|
43755
|
+
}
|
|
43756
|
+
digestInto(out) {
|
|
43757
|
+
aexists2(this);
|
|
43758
|
+
aoutput2(out, this, true);
|
|
43759
|
+
this.finished = true;
|
|
43760
|
+
const { s0, s1, s2, s3 } = this;
|
|
43761
|
+
const o32 = u32(out);
|
|
43762
|
+
o32[0] = s0;
|
|
43763
|
+
o32[1] = s1;
|
|
43764
|
+
o32[2] = s2;
|
|
43765
|
+
o32[3] = s3;
|
|
43766
|
+
swap32IfBE(o32);
|
|
43767
|
+
}
|
|
43768
|
+
digest() {
|
|
43769
|
+
const res = new Uint8Array(BLOCK_SIZE);
|
|
43770
|
+
this.digestInto(res);
|
|
43771
|
+
this.destroy();
|
|
43772
|
+
return res;
|
|
43773
|
+
}
|
|
43774
|
+
};
|
|
43775
|
+
var ghash2 = /* @__PURE__ */ wrapMacConstructor(16, (key3, expectedLength) => new GHASH2(key3, expectedLength), (msg) => [msg.length]);
|
|
43776
|
+
|
|
43777
|
+
// node_modules/@noble/ciphers/aes.js
|
|
43778
|
+
var BLOCK_SIZE2 = 16;
|
|
43779
|
+
var BLOCK_SIZE32 = 4;
|
|
43780
|
+
var EMPTY_BLOCK = /* @__PURE__ */ new Uint8Array(BLOCK_SIZE2);
|
|
43781
|
+
var POLY2 = 283;
|
|
43782
|
+
function validateKeyLength(key3) {
|
|
43783
|
+
if (![16, 24, 32].includes(key3.length))
|
|
43784
|
+
throw new Error('"aes key" expected Uint8Array of length 16/24/32, got length=' + key3.length);
|
|
43785
|
+
}
|
|
43786
|
+
function mul23(n) {
|
|
43787
|
+
return n << 1 ^ POLY2 & -(n >> 7);
|
|
43788
|
+
}
|
|
43789
|
+
function mul5(a, b) {
|
|
43790
|
+
let res = 0;
|
|
43791
|
+
for (; b > 0; b >>= 1) {
|
|
43792
|
+
res ^= a & -(b & 1);
|
|
43793
|
+
a = mul23(a);
|
|
43794
|
+
}
|
|
43795
|
+
return res;
|
|
43796
|
+
}
|
|
43797
|
+
var sbox = /* @__PURE__ */ (() => {
|
|
43798
|
+
const t = new Uint8Array(256);
|
|
43799
|
+
for (let i = 0, x = 1; i < 256; i++, x ^= mul23(x))
|
|
43800
|
+
t[i] = x;
|
|
43801
|
+
const box = new Uint8Array(256);
|
|
43802
|
+
box[0] = 99;
|
|
43803
|
+
for (let i = 0; i < 255; i++) {
|
|
43804
|
+
let x = t[255 - i];
|
|
43805
|
+
x |= x << 8;
|
|
43806
|
+
box[t[i]] = (x ^ x >> 4 ^ x >> 5 ^ x >> 6 ^ x >> 7 ^ 99) & 255;
|
|
43807
|
+
}
|
|
43808
|
+
clean2(t);
|
|
43809
|
+
return box;
|
|
43810
|
+
})();
|
|
43811
|
+
var rotr32_8 = (n) => n << 24 | n >>> 8;
|
|
43812
|
+
var rotl32_8 = (n) => n << 8 | n >>> 24;
|
|
43813
|
+
function genTtable(sbox2, fn) {
|
|
43814
|
+
if (sbox2.length !== 256)
|
|
43815
|
+
throw new Error("Wrong sbox length");
|
|
43816
|
+
const T0 = new Uint32Array(256).map((_, j) => fn(sbox2[j]));
|
|
43817
|
+
const T1 = T0.map(rotl32_8);
|
|
43818
|
+
const T2 = T1.map(rotl32_8);
|
|
43819
|
+
const T3 = T2.map(rotl32_8);
|
|
43820
|
+
const T01 = new Uint32Array(256 * 256);
|
|
43821
|
+
const T23 = new Uint32Array(256 * 256);
|
|
43822
|
+
const sbox22 = new Uint16Array(256 * 256);
|
|
43823
|
+
for (let i = 0; i < 256; i++) {
|
|
43824
|
+
for (let j = 0; j < 256; j++) {
|
|
43825
|
+
const idx = i * 256 + j;
|
|
43826
|
+
T01[idx] = T0[i] ^ T1[j];
|
|
43827
|
+
T23[idx] = T2[i] ^ T3[j];
|
|
43828
|
+
sbox22[idx] = sbox2[i] << 8 | sbox2[j];
|
|
43829
|
+
}
|
|
43830
|
+
}
|
|
43831
|
+
return { sbox: sbox2, sbox2: sbox22, T0, T1, T2, T3, T01, T23 };
|
|
43832
|
+
}
|
|
43833
|
+
var tableEncoding = /* @__PURE__ */ genTtable(sbox, (s2) => mul5(s2, 3) << 24 | s2 << 16 | s2 << 8 | mul5(s2, 2));
|
|
43834
|
+
var xPowers = /* @__PURE__ */ (() => {
|
|
43835
|
+
const p = new Uint8Array(16);
|
|
43836
|
+
for (let i = 0, x = 1; i < 16; i++, x = mul23(x))
|
|
43837
|
+
p[i] = x;
|
|
43838
|
+
return p;
|
|
43839
|
+
})();
|
|
43840
|
+
function expandKeyLE(key3) {
|
|
43841
|
+
abytes3(key3);
|
|
43842
|
+
const len = key3.length;
|
|
43843
|
+
validateKeyLength(key3);
|
|
43844
|
+
const { sbox2 } = tableEncoding;
|
|
43845
|
+
const toClean = [];
|
|
43846
|
+
if (!isLE || !isAligned32(key3))
|
|
43847
|
+
toClean.push(key3 = copyBytes2(key3));
|
|
43848
|
+
const k32 = swap32IfBE(u32(key3));
|
|
43849
|
+
const Nk = k32.length;
|
|
43850
|
+
const subByte = (n) => applySbox(sbox2, n, n, n, n);
|
|
43851
|
+
const xk = new Uint32Array(len + 28);
|
|
43852
|
+
xk.set(k32);
|
|
43853
|
+
for (let i = Nk; i < xk.length; i++) {
|
|
43854
|
+
let t = xk[i - 1];
|
|
43855
|
+
if (i % Nk === 0)
|
|
43856
|
+
t = subByte(rotr32_8(t)) ^ xPowers[i / Nk - 1];
|
|
43857
|
+
else if (Nk > 6 && i % Nk === 4)
|
|
43858
|
+
t = subByte(t);
|
|
43859
|
+
xk[i] = xk[i - Nk] ^ t;
|
|
43860
|
+
}
|
|
43861
|
+
clean2(...toClean);
|
|
43862
|
+
return xk;
|
|
43863
|
+
}
|
|
43864
|
+
function apply0123(T01, T23, s0, s1, s2, s3) {
|
|
43865
|
+
return T01[s0 << 8 & 65280 | s1 >>> 8 & 255] ^ T23[s2 >>> 8 & 65280 | s3 >>> 24 & 255];
|
|
43866
|
+
}
|
|
43867
|
+
function applySbox(sbox2, s0, s1, s2, s3) {
|
|
43868
|
+
return sbox2[s0 & 255 | s1 & 65280] | sbox2[s2 >>> 16 & 255 | s3 >>> 16 & 65280] << 16;
|
|
43869
|
+
}
|
|
43870
|
+
function encrypt(xk, s0, s1, s2, s3) {
|
|
43871
|
+
const { sbox2, T01, T23 } = tableEncoding;
|
|
43872
|
+
let k = 0;
|
|
43873
|
+
s0 ^= xk[k++], s1 ^= xk[k++], s2 ^= xk[k++], s3 ^= xk[k++];
|
|
43874
|
+
const rounds = xk.length / 4 - 2;
|
|
43875
|
+
for (let i = 0; i < rounds; i++) {
|
|
43876
|
+
const t02 = xk[k++] ^ apply0123(T01, T23, s0, s1, s2, s3);
|
|
43877
|
+
const t12 = xk[k++] ^ apply0123(T01, T23, s1, s2, s3, s0);
|
|
43878
|
+
const t22 = xk[k++] ^ apply0123(T01, T23, s2, s3, s0, s1);
|
|
43879
|
+
const t32 = xk[k++] ^ apply0123(T01, T23, s3, s0, s1, s2);
|
|
43880
|
+
s0 = t02, s1 = t12, s2 = t22, s3 = t32;
|
|
43881
|
+
}
|
|
43882
|
+
const t0 = xk[k++] ^ applySbox(sbox2, s0, s1, s2, s3);
|
|
43883
|
+
const t1 = xk[k++] ^ applySbox(sbox2, s1, s2, s3, s0);
|
|
43884
|
+
const t2 = xk[k++] ^ applySbox(sbox2, s2, s3, s0, s1);
|
|
43885
|
+
const t3 = xk[k++] ^ applySbox(sbox2, s3, s0, s1, s2);
|
|
43886
|
+
return { s0: t0, s1: t1, s2: t2, s3: t3 };
|
|
43887
|
+
}
|
|
43888
|
+
function ctr32(xk, isLE2, nonce, src, dst) {
|
|
43889
|
+
abytes3(nonce, BLOCK_SIZE2, "nonce");
|
|
43890
|
+
abytes3(src);
|
|
43891
|
+
dst = getOutput(src.length, dst);
|
|
43892
|
+
const ctr2 = nonce;
|
|
43893
|
+
const c32 = u32(ctr2);
|
|
43894
|
+
const view = createView2(ctr2);
|
|
43895
|
+
const src32 = u32(src);
|
|
43896
|
+
const dst32 = u32(dst);
|
|
43897
|
+
const ctrPos = isLE2 ? 0 : 12;
|
|
43898
|
+
const srcLen = src.length;
|
|
43899
|
+
let ctrNum = view.getUint32(ctrPos, isLE2);
|
|
43900
|
+
let { s0, s1, s2, s3 } = encrypt(xk, swap8IfBE(c32[0]), swap8IfBE(c32[1]), swap8IfBE(c32[2]), swap8IfBE(c32[3]));
|
|
43901
|
+
for (let i = 0; i + 4 <= src32.length; i += 4) {
|
|
43902
|
+
dst32[i + 0] = src32[i + 0] ^ swap8IfBE(s0);
|
|
43903
|
+
dst32[i + 1] = src32[i + 1] ^ swap8IfBE(s1);
|
|
43904
|
+
dst32[i + 2] = src32[i + 2] ^ swap8IfBE(s2);
|
|
43905
|
+
dst32[i + 3] = src32[i + 3] ^ swap8IfBE(s3);
|
|
43906
|
+
ctrNum = ctrNum + 1 >>> 0;
|
|
43907
|
+
view.setUint32(ctrPos, ctrNum, isLE2);
|
|
43908
|
+
({ s0, s1, s2, s3 } = encrypt(xk, swap8IfBE(c32[0]), swap8IfBE(c32[1]), swap8IfBE(c32[2]), swap8IfBE(c32[3])));
|
|
43909
|
+
}
|
|
43910
|
+
const start = BLOCK_SIZE2 * Math.floor(src32.length / BLOCK_SIZE32);
|
|
43911
|
+
if (start < srcLen) {
|
|
43912
|
+
const b32 = new Uint32Array([s0, s1, s2, s3]);
|
|
43913
|
+
swap32IfBE(b32);
|
|
43914
|
+
const buf = u8(b32);
|
|
43915
|
+
for (let i = start, pos = 0; i < srcLen; i++, pos++)
|
|
43916
|
+
dst[i] = src[i] ^ buf[pos];
|
|
43917
|
+
clean2(b32);
|
|
43918
|
+
}
|
|
43919
|
+
return dst;
|
|
43920
|
+
}
|
|
43921
|
+
function computeTag(fn, isLE2, key3, data, AAD) {
|
|
43922
|
+
const aadLength = AAD ? AAD.length : 0;
|
|
43923
|
+
const h = fn.create(key3, data.length + aadLength);
|
|
43924
|
+
if (AAD)
|
|
43925
|
+
h.update(AAD);
|
|
43926
|
+
const num = u64Lengths(8 * data.length, 8 * aadLength, isLE2);
|
|
43927
|
+
h.update(data);
|
|
43928
|
+
h.update(num);
|
|
43929
|
+
const res = h.digest();
|
|
43930
|
+
clean2(num);
|
|
43931
|
+
return res;
|
|
43932
|
+
}
|
|
43933
|
+
var gcm = /* @__PURE__ */ wrapCipher({ blockSize: 16, nonceLength: 12, tagLength: 16, varSizeNonce: true }, function aesgcm(key3, nonce, AAD) {
|
|
43934
|
+
if (nonce.length < 8)
|
|
43935
|
+
throw new Error("aes/gcm: invalid nonce length");
|
|
43936
|
+
const tagLength = 16;
|
|
43937
|
+
function _computeTag(authKey, tagMask, data) {
|
|
43938
|
+
const tag = computeTag(ghash2, false, authKey, data, AAD);
|
|
43939
|
+
for (let i = 0; i < tagMask.length; i++)
|
|
43940
|
+
tag[i] ^= tagMask[i];
|
|
43941
|
+
return tag;
|
|
43942
|
+
}
|
|
43943
|
+
function deriveKeys2() {
|
|
43944
|
+
const xk = expandKeyLE(key3);
|
|
43945
|
+
const authKey = EMPTY_BLOCK.slice();
|
|
43946
|
+
const counter = EMPTY_BLOCK.slice();
|
|
43947
|
+
ctr32(xk, false, counter, counter, authKey);
|
|
43948
|
+
if (nonce.length === 12) {
|
|
43949
|
+
counter.set(nonce);
|
|
43950
|
+
} else {
|
|
43951
|
+
const nonceLen = EMPTY_BLOCK.slice();
|
|
43952
|
+
const view = createView2(nonceLen);
|
|
43953
|
+
view.setBigUint64(8, BigInt(nonce.length * 8), false);
|
|
43954
|
+
const g = ghash2.create(authKey).update(nonce).update(nonceLen);
|
|
43955
|
+
g.digestInto(counter);
|
|
43956
|
+
g.destroy();
|
|
43957
|
+
}
|
|
43958
|
+
const tagMask = ctr32(xk, false, counter, EMPTY_BLOCK);
|
|
43959
|
+
return { xk, authKey, counter, tagMask };
|
|
43960
|
+
}
|
|
43961
|
+
return {
|
|
43962
|
+
encrypt(plaintext) {
|
|
43963
|
+
const { xk, authKey, counter, tagMask } = deriveKeys2();
|
|
43964
|
+
const out = new Uint8Array(plaintext.length + tagLength);
|
|
43965
|
+
const toClean = [xk, authKey, counter, tagMask];
|
|
43966
|
+
if (!isAligned32(plaintext))
|
|
43967
|
+
toClean.push(plaintext = copyBytes2(plaintext));
|
|
43968
|
+
ctr32(xk, false, counter, plaintext, out.subarray(0, plaintext.length));
|
|
43969
|
+
const tag = _computeTag(authKey, tagMask, out.subarray(0, out.length - tagLength));
|
|
43970
|
+
toClean.push(tag);
|
|
43971
|
+
out.set(tag, plaintext.length);
|
|
43972
|
+
clean2(...toClean);
|
|
43973
|
+
return out;
|
|
43974
|
+
},
|
|
43975
|
+
decrypt(ciphertext) {
|
|
43976
|
+
const { xk, authKey, counter, tagMask } = deriveKeys2();
|
|
43977
|
+
const toClean = [xk, authKey, tagMask, counter];
|
|
43978
|
+
if (!isAligned32(ciphertext))
|
|
43979
|
+
toClean.push(ciphertext = copyBytes2(ciphertext));
|
|
43980
|
+
const data = ciphertext.subarray(0, -tagLength);
|
|
43981
|
+
const passedTag = ciphertext.subarray(-tagLength);
|
|
43982
|
+
const tag = _computeTag(authKey, tagMask, data);
|
|
43983
|
+
toClean.push(tag);
|
|
43984
|
+
if (!equalBytes(tag, passedTag)) {
|
|
43985
|
+
clean2(...toClean);
|
|
43986
|
+
throw new Error("aes/gcm: invalid ghash tag");
|
|
43987
|
+
}
|
|
43988
|
+
const out = ctr32(xk, false, counter, data);
|
|
43989
|
+
clean2(...toClean);
|
|
43990
|
+
return out;
|
|
43991
|
+
}
|
|
43992
|
+
};
|
|
43993
|
+
});
|
|
43994
|
+
|
|
43995
|
+
// src-ts/crypto/ecies.ts
|
|
43996
|
+
var FORMAT_VERSION = 1;
|
|
43997
|
+
var EPH_PUBKEY_LEN = 33;
|
|
43998
|
+
var NONCE_LEN = 12;
|
|
43999
|
+
var GCM_TAG_LEN = 16;
|
|
44000
|
+
var HEADER_LEN = 1 + EPH_PUBKEY_LEN + NONCE_LEN;
|
|
44001
|
+
var EciesDomain = {
|
|
44002
|
+
toolCall: "atbash:chain-encryption:v1:toolcall",
|
|
44003
|
+
verdict: "atbash:chain-encryption:v1:verdict",
|
|
44004
|
+
note: "atbash:chain-encryption:v1:note",
|
|
44005
|
+
policy: "atbash:chain-encryption:v1:policy",
|
|
44006
|
+
raw: "atbash:chain-encryption:v1:raw"
|
|
44007
|
+
};
|
|
44008
|
+
function deriveKey(sharedPoint, ephPubKey, domain) {
|
|
44009
|
+
const sharedX = sharedPoint.slice(1);
|
|
44010
|
+
return hkdf(sha256, sharedX, ephPubKey, new TextEncoder().encode(domain), 32);
|
|
44011
|
+
}
|
|
44012
|
+
function normalizeHex(hex) {
|
|
44013
|
+
return hex.trim().replace(/^0x/i, "").toLowerCase();
|
|
44014
|
+
}
|
|
44015
|
+
function encryptForOrg(plaintext, orgPubKeyHex, aad, domain = EciesDomain.raw) {
|
|
44016
|
+
const orgPubKey = hexToBytes2(normalizeHex(orgPubKeyHex));
|
|
44017
|
+
if (orgPubKey.length !== EPH_PUBKEY_LEN) {
|
|
44018
|
+
throw new Error(
|
|
44019
|
+
`Invalid org public key: expected ${EPH_PUBKEY_LEN} bytes (compressed secp256k1), got ${orgPubKey.length}`
|
|
44020
|
+
);
|
|
44021
|
+
}
|
|
44022
|
+
const ephPrivKey = secp256k1.utils.randomSecretKey();
|
|
44023
|
+
const ephPubKey = secp256k1.getPublicKey(ephPrivKey, true);
|
|
44024
|
+
const key3 = deriveKey(secp256k1.getSharedSecret(ephPrivKey, orgPubKey, true), ephPubKey, domain);
|
|
44025
|
+
const nonce = new Uint8Array(NONCE_LEN);
|
|
44026
|
+
crypto.getRandomValues(nonce);
|
|
44027
|
+
const aadBytes = new TextEncoder().encode(`${domain}|${aad}`);
|
|
44028
|
+
const sealed = gcm(key3, nonce, aadBytes).encrypt(
|
|
44029
|
+
new TextEncoder().encode(plaintext)
|
|
44030
|
+
);
|
|
44031
|
+
const payload = new Uint8Array(HEADER_LEN + sealed.length);
|
|
44032
|
+
payload[0] = FORMAT_VERSION;
|
|
44033
|
+
payload.set(ephPubKey, 1);
|
|
44034
|
+
payload.set(nonce, 1 + EPH_PUBKEY_LEN);
|
|
44035
|
+
payload.set(sealed, HEADER_LEN);
|
|
44036
|
+
return payload;
|
|
44037
|
+
}
|
|
44038
|
+
function decryptForOrg(payload, orgPrivKeyHex, aad, domain = EciesDomain.raw) {
|
|
44039
|
+
if (payload.length < HEADER_LEN + GCM_TAG_LEN) {
|
|
44040
|
+
throw new Error("Malformed encrypted payload: too short");
|
|
44041
|
+
}
|
|
44042
|
+
const version2 = payload[0];
|
|
44043
|
+
if (version2 !== FORMAT_VERSION) {
|
|
44044
|
+
throw new Error(
|
|
44045
|
+
`Unsupported encrypted payload version: ${version2} (expected ${FORMAT_VERSION})`
|
|
44046
|
+
);
|
|
44047
|
+
}
|
|
44048
|
+
const ephPubKey = payload.subarray(1, 1 + EPH_PUBKEY_LEN);
|
|
44049
|
+
const nonce = payload.subarray(1 + EPH_PUBKEY_LEN, HEADER_LEN);
|
|
44050
|
+
const sealed = payload.subarray(HEADER_LEN);
|
|
44051
|
+
const orgPrivKey = hexToBytes2(normalizeHex(orgPrivKeyHex));
|
|
44052
|
+
const key3 = deriveKey(secp256k1.getSharedSecret(orgPrivKey, ephPubKey, true), ephPubKey, domain);
|
|
44053
|
+
const aadBytes = new TextEncoder().encode(`${domain}|${aad}`);
|
|
44054
|
+
const opened = gcm(key3, nonce, aadBytes).decrypt(sealed);
|
|
44055
|
+
return new TextDecoder().decode(opened);
|
|
44056
|
+
}
|
|
44057
|
+
function encryptedLength(plaintextByteLength) {
|
|
44058
|
+
return HEADER_LEN + plaintextByteLength + GCM_TAG_LEN;
|
|
44059
|
+
}
|
|
44060
|
+
|
|
44061
|
+
// src-ts/encrypted-toolcall.ts
|
|
44062
|
+
var { Buffer: PolyBuffer, gtx: pcgtx2 } = index;
|
|
44063
|
+
var MERKLE_HASH_VERSION2 = 2;
|
|
44064
|
+
function normalizeActionForHash(action) {
|
|
44065
|
+
action = action.trim();
|
|
44066
|
+
try {
|
|
44067
|
+
const parsed = JSON.parse(action);
|
|
44068
|
+
if (parsed && typeof parsed === "object" && "args" in parsed) {
|
|
44069
|
+
const obj2 = parsed;
|
|
44070
|
+
const dynamicKeys = [
|
|
44071
|
+
"session_id",
|
|
44072
|
+
"task_id",
|
|
44073
|
+
"tool_call_id",
|
|
44074
|
+
"turn_id",
|
|
44075
|
+
"api_request_id"
|
|
44076
|
+
];
|
|
44077
|
+
if (dynamicKeys.some((k) => k in obj2)) {
|
|
44078
|
+
return JSON.stringify({ tool_name: obj2.tool_name, args: obj2.args });
|
|
44079
|
+
}
|
|
44080
|
+
}
|
|
44081
|
+
} catch {
|
|
44082
|
+
}
|
|
44083
|
+
return action;
|
|
44084
|
+
}
|
|
44085
|
+
function signOpWithBytes(opName, args, privkeyHex, blockchainRidHex) {
|
|
44086
|
+
const priv2 = hexToBytes2(privkeyHex.trim().replace(/^0x/i, "").toLowerCase());
|
|
44087
|
+
if (priv2.length !== 32) {
|
|
44088
|
+
throw new Error("invalid private key");
|
|
44089
|
+
}
|
|
44090
|
+
const ridBytes = hexToBytes2(
|
|
44091
|
+
blockchainRidHex.trim().replace(/^0x/i, "").toLowerCase()
|
|
44092
|
+
);
|
|
44093
|
+
if (ridBytes.length !== 32) {
|
|
44094
|
+
throw new Error("invalid blockchain rid \u2014 must be 32 bytes hex");
|
|
44095
|
+
}
|
|
44096
|
+
const pub2 = secp256k1.getPublicKey(priv2, true);
|
|
44097
|
+
const encodedArgs = args.map(
|
|
44098
|
+
(a) => typeof a === "string" ? a : PolyBuffer.from(a)
|
|
44099
|
+
);
|
|
44100
|
+
let g = pcgtx2.emptyGtx(PolyBuffer.from(ridBytes));
|
|
44101
|
+
g = pcgtx2.addTransactionToGtx(opName, encodedArgs, g);
|
|
44102
|
+
pcgtx2.addSignerToGtx(PolyBuffer.from(pub2), g);
|
|
44103
|
+
const digest9 = pcgtx2.getDigestToSign(g, MERKLE_HASH_VERSION2);
|
|
44104
|
+
const signature2 = secp256k1.sign(digest9, priv2, { prehash: false });
|
|
44105
|
+
g = pcgtx2.addSignature(PolyBuffer.from(pub2), PolyBuffer.from(signature2), g);
|
|
44106
|
+
return pcgtx2.serialize(g).toString("hex");
|
|
44107
|
+
}
|
|
44108
|
+
function signEncryptedToolCall(toolCallId, action, context, toolName, toolArgsJson, orgEncryptionPubKey, privkeyHex, blockchainRidHex) {
|
|
44109
|
+
const plaintext = {
|
|
44110
|
+
tool_name: toolName,
|
|
44111
|
+
action,
|
|
44112
|
+
context,
|
|
44113
|
+
tool_args_json: toolArgsJson
|
|
44114
|
+
};
|
|
44115
|
+
const contentCipher = encryptForOrg(
|
|
44116
|
+
JSON.stringify(plaintext),
|
|
44117
|
+
orgEncryptionPubKey,
|
|
44118
|
+
toolCallId,
|
|
44119
|
+
EciesDomain.toolCall
|
|
44120
|
+
);
|
|
44121
|
+
const actionHash = bytesToHex2(
|
|
44122
|
+
sha256(new TextEncoder().encode(normalizeActionForHash(action)))
|
|
44123
|
+
);
|
|
44124
|
+
return signOpWithBytes(
|
|
44125
|
+
"log_encrypted_tool_call",
|
|
44126
|
+
[toolCallId, toolName, contentCipher, actionHash],
|
|
44127
|
+
privkeyHex,
|
|
44128
|
+
blockchainRidHex
|
|
44129
|
+
);
|
|
44130
|
+
}
|
|
44131
|
+
|
|
43443
44132
|
// src-ts/endpoint.ts
|
|
43444
44133
|
var ALLOWED_JUDGE_HOSTS = /* @__PURE__ */ new Set([
|
|
43445
44134
|
"atbash.ai",
|
|
@@ -43643,6 +44332,8 @@ var Atbash = class _Atbash {
|
|
|
43643
44332
|
orgName;
|
|
43644
44333
|
/** Default judge response-signing pubkey, if configured (see fromConfig). */
|
|
43645
44334
|
verifyPubKey;
|
|
44335
|
+
/** Default org encryption key — see {@link AtbashOptions.orgEncryptionPubKey}. */
|
|
44336
|
+
orgEncryptionPubKey;
|
|
43646
44337
|
/** When true (default), `auditToolCall` denies on any error. */
|
|
43647
44338
|
failClosed;
|
|
43648
44339
|
logger;
|
|
@@ -43665,6 +44356,7 @@ var Atbash = class _Atbash {
|
|
|
43665
44356
|
this.blockchainRid = options.blockchainRid ?? native.DEFAULT_BLOCKCHAIN_RID;
|
|
43666
44357
|
this.orgName = options.orgName;
|
|
43667
44358
|
this.verifyPubKey = options.verifyPubKey;
|
|
44359
|
+
this.orgEncryptionPubKey = options.orgEncryptionPubKey;
|
|
43668
44360
|
this.failClosed = options.failClosed !== false;
|
|
43669
44361
|
this.logger = options.logger ?? {};
|
|
43670
44362
|
this.http = new HttpClient(this.endpoint, options.timeoutMs ?? 3e4);
|
|
@@ -43758,8 +44450,18 @@ var Atbash = class _Atbash {
|
|
|
43758
44450
|
}
|
|
43759
44451
|
const toolCallId = generateToolCallId();
|
|
43760
44452
|
const brid = this.bridFromChainOpts(options.chainOpts);
|
|
44453
|
+
const orgKey = options.orgEncryptionPubKey ?? this.orgEncryptionPubKey;
|
|
43761
44454
|
try {
|
|
43762
|
-
const signedHex =
|
|
44455
|
+
const signedHex = orgKey ? signEncryptedToolCall(
|
|
44456
|
+
toolCallId,
|
|
44457
|
+
action,
|
|
44458
|
+
context,
|
|
44459
|
+
options.toolName ?? "",
|
|
44460
|
+
options.toolArgsJson ?? "",
|
|
44461
|
+
orgKey,
|
|
44462
|
+
this.auth.privkey,
|
|
44463
|
+
brid
|
|
44464
|
+
) : native.signLogToolCall(
|
|
43763
44465
|
toolCallId,
|
|
43764
44466
|
action,
|
|
43765
44467
|
context,
|
|
@@ -43881,6 +44583,7 @@ var Atbash = class _Atbash {
|
|
|
43881
44583
|
onChain: Boolean(data.on_chain),
|
|
43882
44584
|
enforced: Boolean(data.enforced),
|
|
43883
44585
|
enforcementMode: String(data.enforcement_mode ?? ""),
|
|
44586
|
+
status: String(data.status ?? ""),
|
|
43884
44587
|
score
|
|
43885
44588
|
};
|
|
43886
44589
|
}
|
|
@@ -43922,6 +44625,12 @@ var Atbash = class _Atbash {
|
|
|
43922
44625
|
resolved: input.resolved
|
|
43923
44626
|
});
|
|
43924
44627
|
if (result.verdict === "No verdict") {
|
|
44628
|
+
if (result.status !== "logged") {
|
|
44629
|
+
return this.fail(
|
|
44630
|
+
`judge returned no verdict without an audit-tier marker (status: ${result.status || "absent"})`,
|
|
44631
|
+
result.toolCallId
|
|
44632
|
+
);
|
|
44633
|
+
}
|
|
43925
44634
|
return {
|
|
43926
44635
|
allow: true,
|
|
43927
44636
|
verdict: "ALLOW",
|
|
@@ -44512,24 +45221,24 @@ function verifyJudgeResponseSignature(bodyBytes, signatureHex, pubKeyHex) {
|
|
|
44512
45221
|
var { Buffer: Buffer4 } = index;
|
|
44513
45222
|
var HKDF_INFO = new TextEncoder().encode("atbash:memory-encryption");
|
|
44514
45223
|
var KEY_LEN = 32;
|
|
44515
|
-
var
|
|
45224
|
+
var NONCE_LEN2 = 12;
|
|
44516
45225
|
function stripHex2(s2) {
|
|
44517
45226
|
return s2.trim().replace(/^0x/i, "").toLowerCase();
|
|
44518
45227
|
}
|
|
44519
45228
|
function hexToU8(hex) {
|
|
44520
|
-
const
|
|
44521
|
-
if (!/^[0-9a-f]+$/.test(
|
|
45229
|
+
const clean3 = stripHex2(hex);
|
|
45230
|
+
if (!/^[0-9a-f]+$/.test(clean3) || clean3.length % 2 !== 0) {
|
|
44522
45231
|
throw new Error("invalid hex");
|
|
44523
45232
|
}
|
|
44524
|
-
const out = new Uint8Array(
|
|
45233
|
+
const out = new Uint8Array(clean3.length / 2);
|
|
44525
45234
|
for (let i = 0; i < out.length; i++) {
|
|
44526
|
-
out[i] = parseInt(
|
|
45235
|
+
out[i] = parseInt(clean3.slice(i * 2, i * 2 + 2), 16);
|
|
44527
45236
|
}
|
|
44528
45237
|
return out;
|
|
44529
45238
|
}
|
|
44530
|
-
function toArrayBuffer(
|
|
44531
|
-
const ab = new ArrayBuffer(
|
|
44532
|
-
new Uint8Array(ab).set(
|
|
45239
|
+
function toArrayBuffer(u82) {
|
|
45240
|
+
const ab = new ArrayBuffer(u82.byteLength);
|
|
45241
|
+
new Uint8Array(ab).set(u82);
|
|
44533
45242
|
return ab;
|
|
44534
45243
|
}
|
|
44535
45244
|
async function deriveRawKeyBytes(privkeyHex) {
|
|
@@ -44556,7 +45265,7 @@ async function encryptMemoryContent2(plaintext, key3) {
|
|
|
44556
45265
|
if (key3.byteLength !== KEY_LEN) {
|
|
44557
45266
|
throw new Error(`encryptMemoryContent: key must be ${KEY_LEN} bytes`);
|
|
44558
45267
|
}
|
|
44559
|
-
const nonce = new Uint8Array(
|
|
45268
|
+
const nonce = new Uint8Array(NONCE_LEN2);
|
|
44560
45269
|
crypto.getRandomValues(nonce);
|
|
44561
45270
|
const aesKey = await importAesKey(new Uint8Array(key3));
|
|
44562
45271
|
const cipherBuf = await crypto.subtle.encrypt(
|
|
@@ -44570,8 +45279,8 @@ async function decryptMemoryContent2(ciphertext, nonce, key3) {
|
|
|
44570
45279
|
if (key3.byteLength !== KEY_LEN) {
|
|
44571
45280
|
throw new Error(`decryptMemoryContent: key must be ${KEY_LEN} bytes`);
|
|
44572
45281
|
}
|
|
44573
|
-
if (nonce.byteLength !==
|
|
44574
|
-
throw new Error(`decryptMemoryContent: nonce must be ${
|
|
45282
|
+
if (nonce.byteLength !== NONCE_LEN2) {
|
|
45283
|
+
throw new Error(`decryptMemoryContent: nonce must be ${NONCE_LEN2} bytes`);
|
|
44575
45284
|
}
|
|
44576
45285
|
const aesKey = await importAesKey(new Uint8Array(key3));
|
|
44577
45286
|
const plainBuf = await crypto.subtle.decrypt(
|
|
@@ -44709,9 +45418,9 @@ async function scanMemoryBatch(entries, auth, opts) {
|
|
|
44709
45418
|
}
|
|
44710
45419
|
|
|
44711
45420
|
// src-ts/memory/chain.ts
|
|
44712
|
-
var { createClient, encryption: encryption2, newSignatureProvider: newSignatureProvider2, Buffer:
|
|
45421
|
+
var { createClient, encryption: encryption2, newSignatureProvider: newSignatureProvider2, Buffer: PolyBuffer2 } = index;
|
|
44713
45422
|
function toGtxBytes(bytes) {
|
|
44714
|
-
return
|
|
45423
|
+
return PolyBuffer2.from(new Uint8Array(bytes));
|
|
44715
45424
|
}
|
|
44716
45425
|
async function resolveChainOptsForOrg(opts, auth) {
|
|
44717
45426
|
if (opts?.orgName && !opts.chainOpts?.blockchainRid && auth) {
|
|
@@ -45270,6 +45979,7 @@ export {
|
|
|
45270
45979
|
DEFAULT_MEMORY_PATH_PATTERNS,
|
|
45271
45980
|
DEFAULT_MEMORY_READ_TOOL_NAMES,
|
|
45272
45981
|
DEFAULT_MEMORY_WRITE_TOOL_NAMES,
|
|
45982
|
+
EciesDomain,
|
|
45273
45983
|
MemoryGuardManager,
|
|
45274
45984
|
MemoryIntegrityError,
|
|
45275
45985
|
PointerStore,
|
|
@@ -45282,13 +45992,16 @@ export {
|
|
|
45282
45992
|
createFileLogger,
|
|
45283
45993
|
createMemoryGuardManager,
|
|
45284
45994
|
createMemorySnapshot2 as createMemorySnapshot,
|
|
45995
|
+
decryptForOrg,
|
|
45285
45996
|
decryptMemoryContent2 as decryptMemoryContent,
|
|
45286
45997
|
defaultPluginLogPath,
|
|
45287
45998
|
defaultPointerPath,
|
|
45288
45999
|
deriveMemoryKey2 as deriveMemoryKey,
|
|
45289
46000
|
derivePublicKey2 as derivePublicKey,
|
|
45290
46001
|
diffMemorySnapshots2 as diffMemorySnapshots,
|
|
46002
|
+
encryptForOrg,
|
|
45291
46003
|
encryptMemoryContent2 as encryptMemoryContent,
|
|
46004
|
+
encryptedLength,
|
|
45292
46005
|
flushTelemetry,
|
|
45293
46006
|
generateKeypair2 as generateKeypair,
|
|
45294
46007
|
getActiveMemory,
|
|
@@ -45304,6 +46017,7 @@ export {
|
|
|
45304
46017
|
loadAgent2 as loadAgent,
|
|
45305
46018
|
loadAgentFromFile,
|
|
45306
46019
|
loadUserConfig,
|
|
46020
|
+
normalizeActionForHash,
|
|
45307
46021
|
normalizeForMatching2 as normalizeForMatching,
|
|
45308
46022
|
normalizeStatus,
|
|
45309
46023
|
normalizeVerdict,
|
|
@@ -45320,6 +46034,7 @@ export {
|
|
|
45320
46034
|
scanMemoryBatch,
|
|
45321
46035
|
setupTelemetry,
|
|
45322
46036
|
shutdownTelemetry,
|
|
46037
|
+
signEncryptedToolCall,
|
|
45323
46038
|
signJudgeAction2 as signJudgeAction,
|
|
45324
46039
|
signLogToolCall2 as signLogToolCall,
|
|
45325
46040
|
syncLocalMemory,
|
|
@@ -45345,5 +46060,8 @@ postchain-client/built/esm/index.js:
|
|
|
45345
46060
|
* @license MIT
|
|
45346
46061
|
*)
|
|
45347
46062
|
(*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> *)
|
|
46063
|
+
|
|
46064
|
+
@noble/ciphers/utils.js:
|
|
46065
|
+
(*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) *)
|
|
45348
46066
|
*/
|
|
45349
46067
|
//# sourceMappingURL=browser.mjs.map
|