@t2000/cli 8.0.0 → 8.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{dist-BOOS6EPV.js → dist-JNPBEKR5.js} +1337 -512
- package/dist/{dist-BOOS6EPV.js.map → dist-JNPBEKR5.js.map} +1 -1
- package/dist/index.js +1602 -655
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -17198,7 +17198,7 @@ var require_bitmapper = __commonJS({
|
|
|
17198
17198
|
function bitRetriever(data, depth) {
|
|
17199
17199
|
let leftOver = [];
|
|
17200
17200
|
let i = 0;
|
|
17201
|
-
function
|
|
17201
|
+
function split4() {
|
|
17202
17202
|
if (i === data.length) {
|
|
17203
17203
|
throw new Error("Ran out of data");
|
|
17204
17204
|
}
|
|
@@ -17241,7 +17241,7 @@ var require_bitmapper = __commonJS({
|
|
|
17241
17241
|
return {
|
|
17242
17242
|
get: function(count) {
|
|
17243
17243
|
while (leftOver.length < count) {
|
|
17244
|
-
|
|
17244
|
+
split4();
|
|
17245
17245
|
}
|
|
17246
17246
|
let returner = leftOver.slice(0, count);
|
|
17247
17247
|
leftOver = leftOver.slice(count);
|
|
@@ -22171,24 +22171,24 @@ function invert(number, modulo) {
|
|
|
22171
22171
|
throw new Error("invert: does not exist");
|
|
22172
22172
|
return mod(x, modulo);
|
|
22173
22173
|
}
|
|
22174
|
-
function assertIsSquare(
|
|
22175
|
-
if (!
|
|
22174
|
+
function assertIsSquare(Fp2, root, n) {
|
|
22175
|
+
if (!Fp2.eql(Fp2.sqr(root), n))
|
|
22176
22176
|
throw new Error("Cannot find square root");
|
|
22177
22177
|
}
|
|
22178
|
-
function sqrt3mod4(
|
|
22179
|
-
const p1div4 = (
|
|
22180
|
-
const root =
|
|
22181
|
-
assertIsSquare(
|
|
22178
|
+
function sqrt3mod4(Fp2, n) {
|
|
22179
|
+
const p1div4 = (Fp2.ORDER + _1n2) / _4n;
|
|
22180
|
+
const root = Fp2.pow(n, p1div4);
|
|
22181
|
+
assertIsSquare(Fp2, root, n);
|
|
22182
22182
|
return root;
|
|
22183
22183
|
}
|
|
22184
|
-
function sqrt5mod8(
|
|
22185
|
-
const p5div8 = (
|
|
22186
|
-
const n2 =
|
|
22187
|
-
const v =
|
|
22188
|
-
const nv =
|
|
22189
|
-
const i =
|
|
22190
|
-
const root =
|
|
22191
|
-
assertIsSquare(
|
|
22184
|
+
function sqrt5mod8(Fp2, n) {
|
|
22185
|
+
const p5div8 = (Fp2.ORDER - _5n) / _8n;
|
|
22186
|
+
const n2 = Fp2.mul(n, _2n);
|
|
22187
|
+
const v = Fp2.pow(n2, p5div8);
|
|
22188
|
+
const nv = Fp2.mul(n, v);
|
|
22189
|
+
const i = Fp2.mul(Fp2.mul(nv, _2n), v);
|
|
22190
|
+
const root = Fp2.mul(nv, Fp2.sub(i, Fp2.ONE));
|
|
22191
|
+
assertIsSquare(Fp2, root, n);
|
|
22192
22192
|
return root;
|
|
22193
22193
|
}
|
|
22194
22194
|
function sqrt9mod16(P) {
|
|
@@ -22198,18 +22198,18 @@ function sqrt9mod16(P) {
|
|
|
22198
22198
|
const c2 = tn(Fp_, c1);
|
|
22199
22199
|
const c3 = tn(Fp_, Fp_.neg(c1));
|
|
22200
22200
|
const c4 = (P + _7n) / _16n;
|
|
22201
|
-
return (
|
|
22202
|
-
let tv1 =
|
|
22203
|
-
let tv2 =
|
|
22204
|
-
const tv3 =
|
|
22205
|
-
const tv4 =
|
|
22206
|
-
const e1 =
|
|
22207
|
-
const e2 =
|
|
22208
|
-
tv1 =
|
|
22209
|
-
tv2 =
|
|
22210
|
-
const e3 =
|
|
22211
|
-
const root =
|
|
22212
|
-
assertIsSquare(
|
|
22201
|
+
return (Fp2, n) => {
|
|
22202
|
+
let tv1 = Fp2.pow(n, c4);
|
|
22203
|
+
let tv2 = Fp2.mul(tv1, c1);
|
|
22204
|
+
const tv3 = Fp2.mul(tv1, c2);
|
|
22205
|
+
const tv4 = Fp2.mul(tv1, c3);
|
|
22206
|
+
const e1 = Fp2.eql(Fp2.sqr(tv2), n);
|
|
22207
|
+
const e2 = Fp2.eql(Fp2.sqr(tv3), n);
|
|
22208
|
+
tv1 = Fp2.cmov(tv1, tv2, e1);
|
|
22209
|
+
tv2 = Fp2.cmov(tv4, tv3, e2);
|
|
22210
|
+
const e3 = Fp2.eql(Fp2.sqr(tv2), n);
|
|
22211
|
+
const root = Fp2.cmov(tv1, tv2, e3);
|
|
22212
|
+
assertIsSquare(Fp2, root, n);
|
|
22213
22213
|
return root;
|
|
22214
22214
|
};
|
|
22215
22215
|
}
|
|
@@ -22232,32 +22232,32 @@ function tonelliShanks(P) {
|
|
|
22232
22232
|
return sqrt3mod4;
|
|
22233
22233
|
let cc = _Fp.pow(Z, Q);
|
|
22234
22234
|
const Q1div2 = (Q + _1n2) / _2n;
|
|
22235
|
-
return function tonelliSlow(
|
|
22236
|
-
if (
|
|
22235
|
+
return function tonelliSlow(Fp2, n) {
|
|
22236
|
+
if (Fp2.is0(n))
|
|
22237
22237
|
return n;
|
|
22238
|
-
if (FpLegendre(
|
|
22238
|
+
if (FpLegendre(Fp2, n) !== 1)
|
|
22239
22239
|
throw new Error("Cannot find square root");
|
|
22240
22240
|
let M = S;
|
|
22241
|
-
let c =
|
|
22242
|
-
let t =
|
|
22243
|
-
let R =
|
|
22244
|
-
while (!
|
|
22245
|
-
if (
|
|
22246
|
-
return
|
|
22241
|
+
let c = Fp2.mul(Fp2.ONE, cc);
|
|
22242
|
+
let t = Fp2.pow(n, Q);
|
|
22243
|
+
let R = Fp2.pow(n, Q1div2);
|
|
22244
|
+
while (!Fp2.eql(t, Fp2.ONE)) {
|
|
22245
|
+
if (Fp2.is0(t))
|
|
22246
|
+
return Fp2.ZERO;
|
|
22247
22247
|
let i = 1;
|
|
22248
|
-
let t_tmp =
|
|
22249
|
-
while (!
|
|
22248
|
+
let t_tmp = Fp2.sqr(t);
|
|
22249
|
+
while (!Fp2.eql(t_tmp, Fp2.ONE)) {
|
|
22250
22250
|
i++;
|
|
22251
|
-
t_tmp =
|
|
22251
|
+
t_tmp = Fp2.sqr(t_tmp);
|
|
22252
22252
|
if (i === M)
|
|
22253
22253
|
throw new Error("Cannot find square root");
|
|
22254
22254
|
}
|
|
22255
22255
|
const exponent = _1n2 << BigInt(M - i - 1);
|
|
22256
|
-
const b =
|
|
22256
|
+
const b = Fp2.pow(c, exponent);
|
|
22257
22257
|
M = i;
|
|
22258
|
-
c =
|
|
22259
|
-
t =
|
|
22260
|
-
R =
|
|
22258
|
+
c = Fp2.sqr(b);
|
|
22259
|
+
t = Fp2.mul(t, c);
|
|
22260
|
+
R = Fp2.mul(R, b);
|
|
22261
22261
|
}
|
|
22262
22262
|
return R;
|
|
22263
22263
|
};
|
|
@@ -22304,46 +22304,46 @@ function validateField(field) {
|
|
|
22304
22304
|
validateObject(field, opts);
|
|
22305
22305
|
return field;
|
|
22306
22306
|
}
|
|
22307
|
-
function FpPow(
|
|
22307
|
+
function FpPow(Fp2, num, power) {
|
|
22308
22308
|
if (power < _0n2)
|
|
22309
22309
|
throw new Error("invalid exponent, negatives unsupported");
|
|
22310
22310
|
if (power === _0n2)
|
|
22311
|
-
return
|
|
22311
|
+
return Fp2.ONE;
|
|
22312
22312
|
if (power === _1n2)
|
|
22313
22313
|
return num;
|
|
22314
|
-
let p =
|
|
22314
|
+
let p = Fp2.ONE;
|
|
22315
22315
|
let d = num;
|
|
22316
22316
|
while (power > _0n2) {
|
|
22317
22317
|
if (power & _1n2)
|
|
22318
|
-
p =
|
|
22319
|
-
d =
|
|
22318
|
+
p = Fp2.mul(p, d);
|
|
22319
|
+
d = Fp2.sqr(d);
|
|
22320
22320
|
power >>= _1n2;
|
|
22321
22321
|
}
|
|
22322
22322
|
return p;
|
|
22323
22323
|
}
|
|
22324
|
-
function FpInvertBatch(
|
|
22325
|
-
const inverted = new Array(nums.length).fill(passZero ?
|
|
22324
|
+
function FpInvertBatch(Fp2, nums, passZero = false) {
|
|
22325
|
+
const inverted = new Array(nums.length).fill(passZero ? Fp2.ZERO : void 0);
|
|
22326
22326
|
const multipliedAcc = nums.reduce((acc, num, i) => {
|
|
22327
|
-
if (
|
|
22327
|
+
if (Fp2.is0(num))
|
|
22328
22328
|
return acc;
|
|
22329
22329
|
inverted[i] = acc;
|
|
22330
|
-
return
|
|
22331
|
-
},
|
|
22332
|
-
const invertedAcc =
|
|
22330
|
+
return Fp2.mul(acc, num);
|
|
22331
|
+
}, Fp2.ONE);
|
|
22332
|
+
const invertedAcc = Fp2.inv(multipliedAcc);
|
|
22333
22333
|
nums.reduceRight((acc, num, i) => {
|
|
22334
|
-
if (
|
|
22334
|
+
if (Fp2.is0(num))
|
|
22335
22335
|
return acc;
|
|
22336
|
-
inverted[i] =
|
|
22337
|
-
return
|
|
22336
|
+
inverted[i] = Fp2.mul(acc, inverted[i]);
|
|
22337
|
+
return Fp2.mul(acc, num);
|
|
22338
22338
|
}, invertedAcc);
|
|
22339
22339
|
return inverted;
|
|
22340
22340
|
}
|
|
22341
|
-
function FpLegendre(
|
|
22342
|
-
const p1mod2 = (
|
|
22343
|
-
const powered =
|
|
22344
|
-
const yes =
|
|
22345
|
-
const zero =
|
|
22346
|
-
const no =
|
|
22341
|
+
function FpLegendre(Fp2, n) {
|
|
22342
|
+
const p1mod2 = (Fp2.ORDER - _1n2) / _2n;
|
|
22343
|
+
const powered = Fp2.pow(n, p1mod2);
|
|
22344
|
+
const yes = Fp2.eql(powered, Fp2.ONE);
|
|
22345
|
+
const zero = Fp2.eql(powered, Fp2.ZERO);
|
|
22346
|
+
const no = Fp2.eql(powered, Fp2.neg(Fp2.ONE));
|
|
22347
22347
|
if (!yes && !zero && !no)
|
|
22348
22348
|
throw new Error("invalid Legendre symbol result");
|
|
22349
22349
|
return yes ? 1 : zero ? 0 : -1;
|
|
@@ -22694,16 +22694,16 @@ function createCurveFields(type, CURVE, curveOpts = {}, FpFnLE) {
|
|
|
22694
22694
|
if (!(typeof val === "bigint" && val > _0n3))
|
|
22695
22695
|
throw new Error(`CURVE.${p} must be positive bigint`);
|
|
22696
22696
|
}
|
|
22697
|
-
const
|
|
22698
|
-
const
|
|
22697
|
+
const Fp2 = createField(CURVE.p, curveOpts.Fp, FpFnLE);
|
|
22698
|
+
const Fn2 = createField(CURVE.n, curveOpts.Fn, FpFnLE);
|
|
22699
22699
|
const _b = type === "weierstrass" ? "b" : "d";
|
|
22700
22700
|
const params = ["Gx", "Gy", "a", _b];
|
|
22701
22701
|
for (const p of params) {
|
|
22702
|
-
if (!
|
|
22702
|
+
if (!Fp2.isValid(CURVE[p]))
|
|
22703
22703
|
throw new Error(`CURVE.${p} must be valid field element of CURVE.Fp`);
|
|
22704
22704
|
}
|
|
22705
22705
|
CURVE = Object.freeze(Object.assign({}, CURVE));
|
|
22706
|
-
return { CURVE, Fp, Fn };
|
|
22706
|
+
return { CURVE, Fp: Fp2, Fn: Fn2 };
|
|
22707
22707
|
}
|
|
22708
22708
|
function createKeygen(randomSecretKey, getPublicKey) {
|
|
22709
22709
|
return function keygen(seed) {
|
|
@@ -22717,29 +22717,29 @@ var _0n4 = BigInt(0);
|
|
|
22717
22717
|
var _1n4 = BigInt(1);
|
|
22718
22718
|
var _2n2 = BigInt(2);
|
|
22719
22719
|
var _8n2 = BigInt(8);
|
|
22720
|
-
function isEdValidXY(
|
|
22721
|
-
const x2 =
|
|
22722
|
-
const y2 =
|
|
22723
|
-
const left =
|
|
22724
|
-
const right =
|
|
22725
|
-
return
|
|
22720
|
+
function isEdValidXY(Fp2, CURVE, x, y) {
|
|
22721
|
+
const x2 = Fp2.sqr(x);
|
|
22722
|
+
const y2 = Fp2.sqr(y);
|
|
22723
|
+
const left = Fp2.add(Fp2.mul(CURVE.a, x2), y2);
|
|
22724
|
+
const right = Fp2.add(Fp2.ONE, Fp2.mul(CURVE.d, Fp2.mul(x2, y2)));
|
|
22725
|
+
return Fp2.eql(left, right);
|
|
22726
22726
|
}
|
|
22727
22727
|
function edwards(params, extraOpts = {}) {
|
|
22728
22728
|
const validated = createCurveFields("edwards", params, extraOpts, extraOpts.FpFnLE);
|
|
22729
|
-
const { Fp, Fn } = validated;
|
|
22729
|
+
const { Fp: Fp2, Fn: Fn2 } = validated;
|
|
22730
22730
|
let CURVE = validated.CURVE;
|
|
22731
22731
|
const { h: cofactor } = CURVE;
|
|
22732
22732
|
validateObject(extraOpts, {}, { uvRatio: "function" });
|
|
22733
|
-
const MASK = _2n2 << BigInt(
|
|
22734
|
-
const modP = (n) =>
|
|
22735
|
-
const
|
|
22733
|
+
const MASK = _2n2 << BigInt(Fn2.BYTES * 8) - _1n4;
|
|
22734
|
+
const modP = (n) => Fp2.create(n);
|
|
22735
|
+
const uvRatio3 = extraOpts.uvRatio || ((u, v) => {
|
|
22736
22736
|
try {
|
|
22737
|
-
return { isValid: true, value:
|
|
22737
|
+
return { isValid: true, value: Fp2.sqrt(Fp2.div(u, v)) };
|
|
22738
22738
|
} catch (e) {
|
|
22739
22739
|
return { isValid: false, value: _0n4 };
|
|
22740
22740
|
}
|
|
22741
22741
|
});
|
|
22742
|
-
if (!isEdValidXY(
|
|
22742
|
+
if (!isEdValidXY(Fp2, CURVE, CURVE.Gx, CURVE.Gy))
|
|
22743
22743
|
throw new Error("bad curve params: generator point");
|
|
22744
22744
|
function acoord(title, n, banZero = false) {
|
|
22745
22745
|
const min = banZero ? _1n4 : _0n4;
|
|
@@ -22754,10 +22754,10 @@ function edwards(params, extraOpts = {}) {
|
|
|
22754
22754
|
const { X, Y, Z } = p;
|
|
22755
22755
|
const is0 = p.is0();
|
|
22756
22756
|
if (iz == null)
|
|
22757
|
-
iz = is0 ? _8n2 :
|
|
22757
|
+
iz = is0 ? _8n2 : Fp2.inv(Z);
|
|
22758
22758
|
const x = modP(X * iz);
|
|
22759
22759
|
const y = modP(Y * iz);
|
|
22760
|
-
const zz =
|
|
22760
|
+
const zz = Fp2.mul(Z, iz);
|
|
22761
22761
|
if (is0)
|
|
22762
22762
|
return { x: _0n4, y: _1n4 };
|
|
22763
22763
|
if (zz !== _1n4)
|
|
@@ -22791,9 +22791,9 @@ function edwards(params, extraOpts = {}) {
|
|
|
22791
22791
|
static ZERO = new Point(_0n4, _1n4, _1n4, _0n4);
|
|
22792
22792
|
// 0, 1, 1, 0
|
|
22793
22793
|
// math field
|
|
22794
|
-
static Fp =
|
|
22794
|
+
static Fp = Fp2;
|
|
22795
22795
|
// scalar field
|
|
22796
|
-
static Fn =
|
|
22796
|
+
static Fn = Fn2;
|
|
22797
22797
|
X;
|
|
22798
22798
|
Y;
|
|
22799
22799
|
Z;
|
|
@@ -22818,7 +22818,7 @@ function edwards(params, extraOpts = {}) {
|
|
|
22818
22818
|
}
|
|
22819
22819
|
// Uses algo from RFC8032 5.1.3.
|
|
22820
22820
|
static fromBytes(bytes, zip215 = false) {
|
|
22821
|
-
const len =
|
|
22821
|
+
const len = Fp2.BYTES;
|
|
22822
22822
|
const { a, d } = CURVE;
|
|
22823
22823
|
bytes = copyBytes(abytes(bytes, len, "point"));
|
|
22824
22824
|
abool(zip215, "zip215");
|
|
@@ -22826,12 +22826,12 @@ function edwards(params, extraOpts = {}) {
|
|
|
22826
22826
|
const lastByte = bytes[len - 1];
|
|
22827
22827
|
normed[len - 1] = lastByte & ~128;
|
|
22828
22828
|
const y = bytesToNumberLE(normed);
|
|
22829
|
-
const max = zip215 ? MASK :
|
|
22829
|
+
const max = zip215 ? MASK : Fp2.ORDER;
|
|
22830
22830
|
aInRange("point.y", y, _0n4, max);
|
|
22831
22831
|
const y2 = modP(y * y);
|
|
22832
22832
|
const u = modP(y2 - _1n4);
|
|
22833
22833
|
const v = modP(d * y2 - a);
|
|
22834
|
-
let { isValid, value: x } =
|
|
22834
|
+
let { isValid, value: x } = uvRatio3(u, v);
|
|
22835
22835
|
if (!isValid)
|
|
22836
22836
|
throw new Error("bad point: invalid y coordinate");
|
|
22837
22837
|
const isXOdd = (x & _1n4) === _1n4;
|
|
@@ -22926,7 +22926,7 @@ function edwards(params, extraOpts = {}) {
|
|
|
22926
22926
|
}
|
|
22927
22927
|
// Constant-time multiplication.
|
|
22928
22928
|
multiply(scalar) {
|
|
22929
|
-
if (!
|
|
22929
|
+
if (!Fn2.isValidNot0(scalar))
|
|
22930
22930
|
throw new Error("invalid scalar: expected 1 <= sc < curve.n");
|
|
22931
22931
|
const { p, f } = wnaf.cached(this, scalar, (p2) => normalizeZ(Point, p2));
|
|
22932
22932
|
return normalizeZ(Point, [p, f])[0];
|
|
@@ -22937,7 +22937,7 @@ function edwards(params, extraOpts = {}) {
|
|
|
22937
22937
|
// Does NOT allow scalars higher than CURVE.n.
|
|
22938
22938
|
// Accepts optional accumulator to merge with multiply (important for sparse scalars)
|
|
22939
22939
|
multiplyUnsafe(scalar, acc = Point.ZERO) {
|
|
22940
|
-
if (!
|
|
22940
|
+
if (!Fn2.isValid(scalar))
|
|
22941
22941
|
throw new Error("invalid scalar: expected 0 <= sc < curve.n");
|
|
22942
22942
|
if (scalar === _0n4)
|
|
22943
22943
|
return Point.ZERO;
|
|
@@ -22969,7 +22969,7 @@ function edwards(params, extraOpts = {}) {
|
|
|
22969
22969
|
}
|
|
22970
22970
|
toBytes() {
|
|
22971
22971
|
const { x, y } = this.toAffine();
|
|
22972
|
-
const bytes =
|
|
22972
|
+
const bytes = Fp2.toBytes(y);
|
|
22973
22973
|
bytes[bytes.length - 1] |= x & _1n4 ? 128 : 0;
|
|
22974
22974
|
return bytes;
|
|
22975
22975
|
}
|
|
@@ -22980,7 +22980,7 @@ function edwards(params, extraOpts = {}) {
|
|
|
22980
22980
|
return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
|
|
22981
22981
|
}
|
|
22982
22982
|
}
|
|
22983
|
-
const wnaf = new wNAF(Point,
|
|
22983
|
+
const wnaf = new wNAF(Point, Fn2.BITS);
|
|
22984
22984
|
Point.BASE.precompute(8);
|
|
22985
22985
|
return Point;
|
|
22986
22986
|
}
|
|
@@ -22995,9 +22995,9 @@ function eddsa(Point, cHash, eddsaOpts = {}) {
|
|
|
22995
22995
|
mapToCurve: "function"
|
|
22996
22996
|
});
|
|
22997
22997
|
const { prehash } = eddsaOpts;
|
|
22998
|
-
const { BASE, Fp, Fn } = Point;
|
|
22998
|
+
const { BASE, Fp: Fp2, Fn: Fn2 } = Point;
|
|
22999
22999
|
const randomBytes3 = eddsaOpts.randomBytes || randomBytes;
|
|
23000
|
-
const
|
|
23000
|
+
const adjustScalarBytes3 = eddsaOpts.adjustScalarBytes || ((bytes) => bytes);
|
|
23001
23001
|
const domain = eddsaOpts.domain || ((data, ctx, phflag) => {
|
|
23002
23002
|
abool(phflag, "phflag");
|
|
23003
23003
|
if (ctx.length || phflag)
|
|
@@ -23005,13 +23005,13 @@ function eddsa(Point, cHash, eddsaOpts = {}) {
|
|
|
23005
23005
|
return data;
|
|
23006
23006
|
});
|
|
23007
23007
|
function modN_LE(hash) {
|
|
23008
|
-
return
|
|
23008
|
+
return Fn2.create(bytesToNumberLE(hash));
|
|
23009
23009
|
}
|
|
23010
23010
|
function getPrivateScalar(key) {
|
|
23011
23011
|
const len = lengths.secretKey;
|
|
23012
23012
|
abytes(key, lengths.secretKey, "secretKey");
|
|
23013
23013
|
const hashed = abytes(cHash(key), 2 * len, "hashedSecretKey");
|
|
23014
|
-
const head =
|
|
23014
|
+
const head = adjustScalarBytes3(hashed.slice(0, len));
|
|
23015
23015
|
const prefix = hashed.slice(len, 2 * len);
|
|
23016
23016
|
const scalar = modN_LE(head);
|
|
23017
23017
|
return { head, prefix, scalar };
|
|
@@ -23037,10 +23037,10 @@ function eddsa(Point, cHash, eddsaOpts = {}) {
|
|
|
23037
23037
|
const r = hashDomainToScalar(options.context, prefix, msg);
|
|
23038
23038
|
const R = BASE.multiply(r).toBytes();
|
|
23039
23039
|
const k = hashDomainToScalar(options.context, R, pointBytes, msg);
|
|
23040
|
-
const s =
|
|
23041
|
-
if (!
|
|
23040
|
+
const s = Fn2.create(r + k * scalar);
|
|
23041
|
+
if (!Fn2.isValid(s))
|
|
23042
23042
|
throw new Error("sign failed: invalid s");
|
|
23043
|
-
const rs = concatBytes(R,
|
|
23043
|
+
const rs = concatBytes(R, Fn2.toBytes(s));
|
|
23044
23044
|
return abytes(rs, lengths.signature, "result");
|
|
23045
23045
|
}
|
|
23046
23046
|
const verifyOpts = { zip215: true };
|
|
@@ -23071,7 +23071,7 @@ function eddsa(Point, cHash, eddsaOpts = {}) {
|
|
|
23071
23071
|
const RkA = R.add(A.multiplyUnsafe(k));
|
|
23072
23072
|
return RkA.subtract(SB).clearCofactor().is0();
|
|
23073
23073
|
}
|
|
23074
|
-
const _size =
|
|
23074
|
+
const _size = Fp2.BYTES;
|
|
23075
23075
|
const lengths = {
|
|
23076
23076
|
secretKey: _size,
|
|
23077
23077
|
publicKey: _size,
|
|
@@ -23082,7 +23082,7 @@ function eddsa(Point, cHash, eddsaOpts = {}) {
|
|
|
23082
23082
|
return abytes(seed, lengths.seed, "seed");
|
|
23083
23083
|
}
|
|
23084
23084
|
function isValidSecretKey(key) {
|
|
23085
|
-
return isBytes(key) && key.length ===
|
|
23085
|
+
return isBytes(key) && key.length === Fn2.BYTES;
|
|
23086
23086
|
}
|
|
23087
23087
|
function isValidPublicKey(key, zip215) {
|
|
23088
23088
|
try {
|
|
@@ -23111,14 +23111,14 @@ function eddsa(Point, cHash, eddsaOpts = {}) {
|
|
|
23111
23111
|
const is25519 = size === 32;
|
|
23112
23112
|
if (!is25519 && size !== 57)
|
|
23113
23113
|
throw new Error("only defined for 25519 and 448");
|
|
23114
|
-
const u = is25519 ?
|
|
23115
|
-
return
|
|
23114
|
+
const u = is25519 ? Fp2.div(_1n4 + y, _1n4 - y) : Fp2.div(y - _1n4, y + _1n4);
|
|
23115
|
+
return Fp2.toBytes(u);
|
|
23116
23116
|
},
|
|
23117
23117
|
toMontgomerySecret(secretKey) {
|
|
23118
23118
|
const size = lengths.secretKey;
|
|
23119
23119
|
abytes(secretKey, size);
|
|
23120
23120
|
const hashed = cHash(secretKey.subarray(0, size));
|
|
23121
|
-
return
|
|
23121
|
+
return adjustScalarBytes3(hashed).subarray(0, size);
|
|
23122
23122
|
}
|
|
23123
23123
|
};
|
|
23124
23124
|
return Object.freeze({
|
|
@@ -24315,9 +24315,9 @@ function randomBytes2(bytesLength = 32) {
|
|
|
24315
24315
|
function setBigUint64(view, byteOffset, value, isLE) {
|
|
24316
24316
|
if (typeof view.setBigUint64 === "function")
|
|
24317
24317
|
return view.setBigUint64(byteOffset, value, isLE);
|
|
24318
|
-
const
|
|
24318
|
+
const _32n3 = BigInt(32);
|
|
24319
24319
|
const _u32_max = BigInt(4294967295);
|
|
24320
|
-
const wh = Number(value >>
|
|
24320
|
+
const wh = Number(value >> _32n3 & _u32_max);
|
|
24321
24321
|
const wl = Number(value & _u32_max);
|
|
24322
24322
|
const h = isLE ? 4 : 0;
|
|
24323
24323
|
const l = isLE ? 0 : 4;
|
|
@@ -24430,6 +24430,59 @@ var SHA256_IV3 = /* @__PURE__ */ Uint32Array.from([
|
|
|
24430
24430
|
528734635,
|
|
24431
24431
|
1541459225
|
|
24432
24432
|
]);
|
|
24433
|
+
var SHA512_IV3 = /* @__PURE__ */ Uint32Array.from([
|
|
24434
|
+
1779033703,
|
|
24435
|
+
4089235720,
|
|
24436
|
+
3144134277,
|
|
24437
|
+
2227873595,
|
|
24438
|
+
1013904242,
|
|
24439
|
+
4271175723,
|
|
24440
|
+
2773480762,
|
|
24441
|
+
1595750129,
|
|
24442
|
+
1359893119,
|
|
24443
|
+
2917565137,
|
|
24444
|
+
2600822924,
|
|
24445
|
+
725511199,
|
|
24446
|
+
528734635,
|
|
24447
|
+
4215389547,
|
|
24448
|
+
1541459225,
|
|
24449
|
+
327033209
|
|
24450
|
+
]);
|
|
24451
|
+
|
|
24452
|
+
// ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/_u64.js
|
|
24453
|
+
var U32_MASK642 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
24454
|
+
var _32n2 = /* @__PURE__ */ BigInt(32);
|
|
24455
|
+
function fromBig2(n, le = false) {
|
|
24456
|
+
if (le)
|
|
24457
|
+
return { h: Number(n & U32_MASK642), l: Number(n >> _32n2 & U32_MASK642) };
|
|
24458
|
+
return { h: Number(n >> _32n2 & U32_MASK642) | 0, l: Number(n & U32_MASK642) | 0 };
|
|
24459
|
+
}
|
|
24460
|
+
function split3(lst, le = false) {
|
|
24461
|
+
const len = lst.length;
|
|
24462
|
+
let Ah = new Uint32Array(len);
|
|
24463
|
+
let Al = new Uint32Array(len);
|
|
24464
|
+
for (let i = 0; i < len; i++) {
|
|
24465
|
+
const { h, l } = fromBig2(lst[i], le);
|
|
24466
|
+
[Ah[i], Al[i]] = [h, l];
|
|
24467
|
+
}
|
|
24468
|
+
return [Ah, Al];
|
|
24469
|
+
}
|
|
24470
|
+
var shrSH3 = (h, _l, s) => h >>> s;
|
|
24471
|
+
var shrSL3 = (h, l, s) => h << 32 - s | l >>> s;
|
|
24472
|
+
var rotrSH3 = (h, l, s) => h >>> s | l << 32 - s;
|
|
24473
|
+
var rotrSL3 = (h, l, s) => h << 32 - s | l >>> s;
|
|
24474
|
+
var rotrBH3 = (h, l, s) => h << 64 - s | l >>> s - 32;
|
|
24475
|
+
var rotrBL3 = (h, l, s) => h >>> s - 32 | l << 64 - s;
|
|
24476
|
+
function add3(Ah, Al, Bh, Bl) {
|
|
24477
|
+
const l = (Al >>> 0) + (Bl >>> 0);
|
|
24478
|
+
return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
|
|
24479
|
+
}
|
|
24480
|
+
var add3L3 = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
|
|
24481
|
+
var add3H3 = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
|
|
24482
|
+
var add4L3 = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
|
|
24483
|
+
var add4H3 = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
|
|
24484
|
+
var add5L3 = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
|
|
24485
|
+
var add5H3 = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
|
|
24433
24486
|
|
|
24434
24487
|
// ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/sha2.js
|
|
24435
24488
|
var SHA256_K = /* @__PURE__ */ Uint32Array.from([
|
|
@@ -24569,75 +24622,205 @@ var SHA256 = class extends HashMD3 {
|
|
|
24569
24622
|
clean3(this.buffer);
|
|
24570
24623
|
}
|
|
24571
24624
|
};
|
|
24572
|
-
var
|
|
24573
|
-
|
|
24574
|
-
|
|
24575
|
-
|
|
24576
|
-
|
|
24577
|
-
|
|
24578
|
-
|
|
24579
|
-
|
|
24580
|
-
|
|
24581
|
-
|
|
24582
|
-
|
|
24583
|
-
|
|
24584
|
-
|
|
24585
|
-
|
|
24586
|
-
|
|
24587
|
-
|
|
24588
|
-
|
|
24589
|
-
|
|
24590
|
-
|
|
24591
|
-
|
|
24592
|
-
|
|
24593
|
-
|
|
24594
|
-
|
|
24595
|
-
|
|
24596
|
-
|
|
24597
|
-
|
|
24598
|
-
|
|
24599
|
-
|
|
24600
|
-
|
|
24601
|
-
|
|
24602
|
-
|
|
24625
|
+
var K5123 = /* @__PURE__ */ (() => split3([
|
|
24626
|
+
"0x428a2f98d728ae22",
|
|
24627
|
+
"0x7137449123ef65cd",
|
|
24628
|
+
"0xb5c0fbcfec4d3b2f",
|
|
24629
|
+
"0xe9b5dba58189dbbc",
|
|
24630
|
+
"0x3956c25bf348b538",
|
|
24631
|
+
"0x59f111f1b605d019",
|
|
24632
|
+
"0x923f82a4af194f9b",
|
|
24633
|
+
"0xab1c5ed5da6d8118",
|
|
24634
|
+
"0xd807aa98a3030242",
|
|
24635
|
+
"0x12835b0145706fbe",
|
|
24636
|
+
"0x243185be4ee4b28c",
|
|
24637
|
+
"0x550c7dc3d5ffb4e2",
|
|
24638
|
+
"0x72be5d74f27b896f",
|
|
24639
|
+
"0x80deb1fe3b1696b1",
|
|
24640
|
+
"0x9bdc06a725c71235",
|
|
24641
|
+
"0xc19bf174cf692694",
|
|
24642
|
+
"0xe49b69c19ef14ad2",
|
|
24643
|
+
"0xefbe4786384f25e3",
|
|
24644
|
+
"0x0fc19dc68b8cd5b5",
|
|
24645
|
+
"0x240ca1cc77ac9c65",
|
|
24646
|
+
"0x2de92c6f592b0275",
|
|
24647
|
+
"0x4a7484aa6ea6e483",
|
|
24648
|
+
"0x5cb0a9dcbd41fbd4",
|
|
24649
|
+
"0x76f988da831153b5",
|
|
24650
|
+
"0x983e5152ee66dfab",
|
|
24651
|
+
"0xa831c66d2db43210",
|
|
24652
|
+
"0xb00327c898fb213f",
|
|
24653
|
+
"0xbf597fc7beef0ee4",
|
|
24654
|
+
"0xc6e00bf33da88fc2",
|
|
24655
|
+
"0xd5a79147930aa725",
|
|
24656
|
+
"0x06ca6351e003826f",
|
|
24657
|
+
"0x142929670a0e6e70",
|
|
24658
|
+
"0x27b70a8546d22ffc",
|
|
24659
|
+
"0x2e1b21385c26c926",
|
|
24660
|
+
"0x4d2c6dfc5ac42aed",
|
|
24661
|
+
"0x53380d139d95b3df",
|
|
24662
|
+
"0x650a73548baf63de",
|
|
24663
|
+
"0x766a0abb3c77b2a8",
|
|
24664
|
+
"0x81c2c92e47edaee6",
|
|
24665
|
+
"0x92722c851482353b",
|
|
24666
|
+
"0xa2bfe8a14cf10364",
|
|
24667
|
+
"0xa81a664bbc423001",
|
|
24668
|
+
"0xc24b8b70d0f89791",
|
|
24669
|
+
"0xc76c51a30654be30",
|
|
24670
|
+
"0xd192e819d6ef5218",
|
|
24671
|
+
"0xd69906245565a910",
|
|
24672
|
+
"0xf40e35855771202a",
|
|
24673
|
+
"0x106aa07032bbd1b8",
|
|
24674
|
+
"0x19a4c116b8d2d0c8",
|
|
24675
|
+
"0x1e376c085141ab53",
|
|
24676
|
+
"0x2748774cdf8eeb99",
|
|
24677
|
+
"0x34b0bcb5e19b48a8",
|
|
24678
|
+
"0x391c0cb3c5c95a63",
|
|
24679
|
+
"0x4ed8aa4ae3418acb",
|
|
24680
|
+
"0x5b9cca4f7763e373",
|
|
24681
|
+
"0x682e6ff3d6b2b8a3",
|
|
24682
|
+
"0x748f82ee5defb2fc",
|
|
24683
|
+
"0x78a5636f43172f60",
|
|
24684
|
+
"0x84c87814a1f0ab72",
|
|
24685
|
+
"0x8cc702081a6439ec",
|
|
24686
|
+
"0x90befffa23631e28",
|
|
24687
|
+
"0xa4506cebde82bde9",
|
|
24688
|
+
"0xbef9a3f7b2c67915",
|
|
24689
|
+
"0xc67178f2e372532b",
|
|
24690
|
+
"0xca273eceea26619c",
|
|
24691
|
+
"0xd186b8c721c0c207",
|
|
24692
|
+
"0xeada7dd6cde0eb1e",
|
|
24693
|
+
"0xf57d4f7fee6ed178",
|
|
24694
|
+
"0x06f067aa72176fba",
|
|
24695
|
+
"0x0a637dc5a2c898a6",
|
|
24696
|
+
"0x113f9804bef90dae",
|
|
24697
|
+
"0x1b710b35131c471b",
|
|
24698
|
+
"0x28db77f523047d84",
|
|
24699
|
+
"0x32caab7b40c72493",
|
|
24700
|
+
"0x3c9ebe0a15c9bebc",
|
|
24701
|
+
"0x431d67c49c100d4c",
|
|
24702
|
+
"0x4cc5d4becb3e42b6",
|
|
24703
|
+
"0x597f299cfc657e2a",
|
|
24704
|
+
"0x5fcb6fab3ad6faec",
|
|
24705
|
+
"0x6c44198c4a475817"
|
|
24706
|
+
].map((n) => BigInt(n))))();
|
|
24707
|
+
var SHA512_Kh3 = /* @__PURE__ */ (() => K5123[0])();
|
|
24708
|
+
var SHA512_Kl3 = /* @__PURE__ */ (() => K5123[1])();
|
|
24709
|
+
var SHA512_W_H3 = /* @__PURE__ */ new Uint32Array(80);
|
|
24710
|
+
var SHA512_W_L3 = /* @__PURE__ */ new Uint32Array(80);
|
|
24711
|
+
var SHA512 = class extends HashMD3 {
|
|
24712
|
+
constructor(outputLen = 64) {
|
|
24713
|
+
super(128, outputLen, 16, false);
|
|
24714
|
+
this.Ah = SHA512_IV3[0] | 0;
|
|
24715
|
+
this.Al = SHA512_IV3[1] | 0;
|
|
24716
|
+
this.Bh = SHA512_IV3[2] | 0;
|
|
24717
|
+
this.Bl = SHA512_IV3[3] | 0;
|
|
24718
|
+
this.Ch = SHA512_IV3[4] | 0;
|
|
24719
|
+
this.Cl = SHA512_IV3[5] | 0;
|
|
24720
|
+
this.Dh = SHA512_IV3[6] | 0;
|
|
24721
|
+
this.Dl = SHA512_IV3[7] | 0;
|
|
24722
|
+
this.Eh = SHA512_IV3[8] | 0;
|
|
24723
|
+
this.El = SHA512_IV3[9] | 0;
|
|
24724
|
+
this.Fh = SHA512_IV3[10] | 0;
|
|
24725
|
+
this.Fl = SHA512_IV3[11] | 0;
|
|
24726
|
+
this.Gh = SHA512_IV3[12] | 0;
|
|
24727
|
+
this.Gl = SHA512_IV3[13] | 0;
|
|
24728
|
+
this.Hh = SHA512_IV3[14] | 0;
|
|
24729
|
+
this.Hl = SHA512_IV3[15] | 0;
|
|
24603
24730
|
}
|
|
24604
|
-
|
|
24605
|
-
|
|
24606
|
-
|
|
24607
|
-
|
|
24608
|
-
this.iHash.digestInto(out);
|
|
24609
|
-
this.oHash.update(out);
|
|
24610
|
-
this.oHash.digestInto(out);
|
|
24611
|
-
this.destroy();
|
|
24731
|
+
// prettier-ignore
|
|
24732
|
+
get() {
|
|
24733
|
+
const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
24734
|
+
return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
|
|
24612
24735
|
}
|
|
24613
|
-
|
|
24614
|
-
|
|
24615
|
-
this.
|
|
24616
|
-
|
|
24736
|
+
// prettier-ignore
|
|
24737
|
+
set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
|
|
24738
|
+
this.Ah = Ah | 0;
|
|
24739
|
+
this.Al = Al | 0;
|
|
24740
|
+
this.Bh = Bh | 0;
|
|
24741
|
+
this.Bl = Bl | 0;
|
|
24742
|
+
this.Ch = Ch | 0;
|
|
24743
|
+
this.Cl = Cl | 0;
|
|
24744
|
+
this.Dh = Dh | 0;
|
|
24745
|
+
this.Dl = Dl | 0;
|
|
24746
|
+
this.Eh = Eh | 0;
|
|
24747
|
+
this.El = El | 0;
|
|
24748
|
+
this.Fh = Fh | 0;
|
|
24749
|
+
this.Fl = Fl | 0;
|
|
24750
|
+
this.Gh = Gh | 0;
|
|
24751
|
+
this.Gl = Gl | 0;
|
|
24752
|
+
this.Hh = Hh | 0;
|
|
24753
|
+
this.Hl = Hl | 0;
|
|
24617
24754
|
}
|
|
24618
|
-
|
|
24619
|
-
|
|
24620
|
-
|
|
24621
|
-
|
|
24622
|
-
|
|
24623
|
-
|
|
24624
|
-
|
|
24625
|
-
|
|
24626
|
-
|
|
24627
|
-
|
|
24628
|
-
|
|
24755
|
+
process(view, offset) {
|
|
24756
|
+
for (let i = 0; i < 16; i++, offset += 4) {
|
|
24757
|
+
SHA512_W_H3[i] = view.getUint32(offset);
|
|
24758
|
+
SHA512_W_L3[i] = view.getUint32(offset += 4);
|
|
24759
|
+
}
|
|
24760
|
+
for (let i = 16; i < 80; i++) {
|
|
24761
|
+
const W15h = SHA512_W_H3[i - 15] | 0;
|
|
24762
|
+
const W15l = SHA512_W_L3[i - 15] | 0;
|
|
24763
|
+
const s0h = rotrSH3(W15h, W15l, 1) ^ rotrSH3(W15h, W15l, 8) ^ shrSH3(W15h, W15l, 7);
|
|
24764
|
+
const s0l = rotrSL3(W15h, W15l, 1) ^ rotrSL3(W15h, W15l, 8) ^ shrSL3(W15h, W15l, 7);
|
|
24765
|
+
const W2h = SHA512_W_H3[i - 2] | 0;
|
|
24766
|
+
const W2l = SHA512_W_L3[i - 2] | 0;
|
|
24767
|
+
const s1h = rotrSH3(W2h, W2l, 19) ^ rotrBH3(W2h, W2l, 61) ^ shrSH3(W2h, W2l, 6);
|
|
24768
|
+
const s1l = rotrSL3(W2h, W2l, 19) ^ rotrBL3(W2h, W2l, 61) ^ shrSL3(W2h, W2l, 6);
|
|
24769
|
+
const SUMl = add4L3(s0l, s1l, SHA512_W_L3[i - 7], SHA512_W_L3[i - 16]);
|
|
24770
|
+
const SUMh = add4H3(SUMl, s0h, s1h, SHA512_W_H3[i - 7], SHA512_W_H3[i - 16]);
|
|
24771
|
+
SHA512_W_H3[i] = SUMh | 0;
|
|
24772
|
+
SHA512_W_L3[i] = SUMl | 0;
|
|
24773
|
+
}
|
|
24774
|
+
let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
24775
|
+
for (let i = 0; i < 80; i++) {
|
|
24776
|
+
const sigma1h = rotrSH3(Eh, El, 14) ^ rotrSH3(Eh, El, 18) ^ rotrBH3(Eh, El, 41);
|
|
24777
|
+
const sigma1l = rotrSL3(Eh, El, 14) ^ rotrSL3(Eh, El, 18) ^ rotrBL3(Eh, El, 41);
|
|
24778
|
+
const CHIh = Eh & Fh ^ ~Eh & Gh;
|
|
24779
|
+
const CHIl = El & Fl ^ ~El & Gl;
|
|
24780
|
+
const T1ll = add5L3(Hl, sigma1l, CHIl, SHA512_Kl3[i], SHA512_W_L3[i]);
|
|
24781
|
+
const T1h = add5H3(T1ll, Hh, sigma1h, CHIh, SHA512_Kh3[i], SHA512_W_H3[i]);
|
|
24782
|
+
const T1l = T1ll | 0;
|
|
24783
|
+
const sigma0h = rotrSH3(Ah, Al, 28) ^ rotrBH3(Ah, Al, 34) ^ rotrBH3(Ah, Al, 39);
|
|
24784
|
+
const sigma0l = rotrSL3(Ah, Al, 28) ^ rotrBL3(Ah, Al, 34) ^ rotrBL3(Ah, Al, 39);
|
|
24785
|
+
const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
|
|
24786
|
+
const MAJl = Al & Bl ^ Al & Cl ^ Bl & Cl;
|
|
24787
|
+
Hh = Gh | 0;
|
|
24788
|
+
Hl = Gl | 0;
|
|
24789
|
+
Gh = Fh | 0;
|
|
24790
|
+
Gl = Fl | 0;
|
|
24791
|
+
Fh = Eh | 0;
|
|
24792
|
+
Fl = El | 0;
|
|
24793
|
+
({ h: Eh, l: El } = add3(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
|
|
24794
|
+
Dh = Ch | 0;
|
|
24795
|
+
Dl = Cl | 0;
|
|
24796
|
+
Ch = Bh | 0;
|
|
24797
|
+
Cl = Bl | 0;
|
|
24798
|
+
Bh = Ah | 0;
|
|
24799
|
+
Bl = Al | 0;
|
|
24800
|
+
const All = add3L3(T1l, sigma0l, MAJl);
|
|
24801
|
+
Ah = add3H3(All, T1h, sigma0h, MAJh);
|
|
24802
|
+
Al = All | 0;
|
|
24803
|
+
}
|
|
24804
|
+
({ h: Ah, l: Al } = add3(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
|
|
24805
|
+
({ h: Bh, l: Bl } = add3(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
|
|
24806
|
+
({ h: Ch, l: Cl } = add3(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
|
|
24807
|
+
({ h: Dh, l: Dl } = add3(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
|
|
24808
|
+
({ h: Eh, l: El } = add3(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
|
|
24809
|
+
({ h: Fh, l: Fl } = add3(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
|
|
24810
|
+
({ h: Gh, l: Gl } = add3(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
|
|
24811
|
+
({ h: Hh, l: Hl } = add3(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
|
|
24812
|
+
this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
|
|
24629
24813
|
}
|
|
24630
|
-
|
|
24631
|
-
|
|
24814
|
+
roundClean() {
|
|
24815
|
+
clean3(SHA512_W_H3, SHA512_W_L3);
|
|
24632
24816
|
}
|
|
24633
24817
|
destroy() {
|
|
24634
|
-
this.
|
|
24635
|
-
this.
|
|
24636
|
-
this.iHash.destroy();
|
|
24818
|
+
clean3(this.buffer);
|
|
24819
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
24637
24820
|
}
|
|
24638
24821
|
};
|
|
24639
|
-
var
|
|
24640
|
-
|
|
24822
|
+
var sha2562 = /* @__PURE__ */ createHasher3(() => new SHA256());
|
|
24823
|
+
var sha5123 = /* @__PURE__ */ createHasher3(() => new SHA512());
|
|
24641
24824
|
|
|
24642
24825
|
// ../../node_modules/.pnpm/@noble+curves@1.9.7/node_modules/@noble/curves/esm/utils.js
|
|
24643
24826
|
var _0n5 = /* @__PURE__ */ BigInt(0);
|
|
@@ -24701,6 +24884,17 @@ function ensureBytes(title, hex, expectedLength) {
|
|
|
24701
24884
|
throw new Error(title + " of length " + expectedLength + " expected, got " + len);
|
|
24702
24885
|
return res;
|
|
24703
24886
|
}
|
|
24887
|
+
function equalBytes(a, b) {
|
|
24888
|
+
if (a.length !== b.length)
|
|
24889
|
+
return false;
|
|
24890
|
+
let diff = 0;
|
|
24891
|
+
for (let i = 0; i < a.length; i++)
|
|
24892
|
+
diff |= a[i] ^ b[i];
|
|
24893
|
+
return diff === 0;
|
|
24894
|
+
}
|
|
24895
|
+
function copyBytes2(bytes) {
|
|
24896
|
+
return Uint8Array.from(bytes);
|
|
24897
|
+
}
|
|
24704
24898
|
var isPosBig2 = (n) => typeof n === "bigint" && _0n5 <= n;
|
|
24705
24899
|
function inRange2(n, min, max) {
|
|
24706
24900
|
return isPosBig2(n) && isPosBig2(min) && isPosBig2(max) && min <= n && n < max;
|
|
@@ -24780,6 +24974,9 @@ function _validateObject(object, fields, optFields = {}) {
|
|
|
24780
24974
|
Object.entries(fields).forEach(([k, v]) => checkField(k, v, false));
|
|
24781
24975
|
Object.entries(optFields).forEach(([k, v]) => checkField(k, v, true));
|
|
24782
24976
|
}
|
|
24977
|
+
var notImplemented2 = () => {
|
|
24978
|
+
throw new Error("not implemented");
|
|
24979
|
+
};
|
|
24783
24980
|
function memoized2(fn) {
|
|
24784
24981
|
const map = /* @__PURE__ */ new WeakMap();
|
|
24785
24982
|
return (arg, ...args) => {
|
|
@@ -24835,24 +25032,24 @@ function invert2(number, modulo) {
|
|
|
24835
25032
|
throw new Error("invert: does not exist");
|
|
24836
25033
|
return mod2(x, modulo);
|
|
24837
25034
|
}
|
|
24838
|
-
function assertIsSquare2(
|
|
24839
|
-
if (!
|
|
25035
|
+
function assertIsSquare2(Fp2, root, n) {
|
|
25036
|
+
if (!Fp2.eql(Fp2.sqr(root), n))
|
|
24840
25037
|
throw new Error("Cannot find square root");
|
|
24841
25038
|
}
|
|
24842
|
-
function sqrt3mod42(
|
|
24843
|
-
const p1div4 = (
|
|
24844
|
-
const root =
|
|
24845
|
-
assertIsSquare2(
|
|
25039
|
+
function sqrt3mod42(Fp2, n) {
|
|
25040
|
+
const p1div4 = (Fp2.ORDER + _1n7) / _4n2;
|
|
25041
|
+
const root = Fp2.pow(n, p1div4);
|
|
25042
|
+
assertIsSquare2(Fp2, root, n);
|
|
24846
25043
|
return root;
|
|
24847
25044
|
}
|
|
24848
|
-
function sqrt5mod82(
|
|
24849
|
-
const p5div8 = (
|
|
24850
|
-
const n2 =
|
|
24851
|
-
const v =
|
|
24852
|
-
const nv =
|
|
24853
|
-
const i =
|
|
24854
|
-
const root =
|
|
24855
|
-
assertIsSquare2(
|
|
25045
|
+
function sqrt5mod82(Fp2, n) {
|
|
25046
|
+
const p5div8 = (Fp2.ORDER - _5n3) / _8n4;
|
|
25047
|
+
const n2 = Fp2.mul(n, _2n4);
|
|
25048
|
+
const v = Fp2.pow(n2, p5div8);
|
|
25049
|
+
const nv = Fp2.mul(n, v);
|
|
25050
|
+
const i = Fp2.mul(Fp2.mul(nv, _2n4), v);
|
|
25051
|
+
const root = Fp2.mul(nv, Fp2.sub(i, Fp2.ONE));
|
|
25052
|
+
assertIsSquare2(Fp2, root, n);
|
|
24856
25053
|
return root;
|
|
24857
25054
|
}
|
|
24858
25055
|
function sqrt9mod162(P) {
|
|
@@ -24862,18 +25059,18 @@ function sqrt9mod162(P) {
|
|
|
24862
25059
|
const c2 = tn(Fp_, c1);
|
|
24863
25060
|
const c3 = tn(Fp_, Fp_.neg(c1));
|
|
24864
25061
|
const c4 = (P + _7n2) / _16n2;
|
|
24865
|
-
return (
|
|
24866
|
-
let tv1 =
|
|
24867
|
-
let tv2 =
|
|
24868
|
-
const tv3 =
|
|
24869
|
-
const tv4 =
|
|
24870
|
-
const e1 =
|
|
24871
|
-
const e2 =
|
|
24872
|
-
tv1 =
|
|
24873
|
-
tv2 =
|
|
24874
|
-
const e3 =
|
|
24875
|
-
const root =
|
|
24876
|
-
assertIsSquare2(
|
|
25062
|
+
return (Fp2, n) => {
|
|
25063
|
+
let tv1 = Fp2.pow(n, c4);
|
|
25064
|
+
let tv2 = Fp2.mul(tv1, c1);
|
|
25065
|
+
const tv3 = Fp2.mul(tv1, c2);
|
|
25066
|
+
const tv4 = Fp2.mul(tv1, c3);
|
|
25067
|
+
const e1 = Fp2.eql(Fp2.sqr(tv2), n);
|
|
25068
|
+
const e2 = Fp2.eql(Fp2.sqr(tv3), n);
|
|
25069
|
+
tv1 = Fp2.cmov(tv1, tv2, e1);
|
|
25070
|
+
tv2 = Fp2.cmov(tv4, tv3, e2);
|
|
25071
|
+
const e3 = Fp2.eql(Fp2.sqr(tv2), n);
|
|
25072
|
+
const root = Fp2.cmov(tv1, tv2, e3);
|
|
25073
|
+
assertIsSquare2(Fp2, root, n);
|
|
24877
25074
|
return root;
|
|
24878
25075
|
};
|
|
24879
25076
|
}
|
|
@@ -24896,32 +25093,32 @@ function tonelliShanks2(P) {
|
|
|
24896
25093
|
return sqrt3mod42;
|
|
24897
25094
|
let cc = _Fp.pow(Z, Q);
|
|
24898
25095
|
const Q1div2 = (Q + _1n7) / _2n4;
|
|
24899
|
-
return function tonelliSlow(
|
|
24900
|
-
if (
|
|
25096
|
+
return function tonelliSlow(Fp2, n) {
|
|
25097
|
+
if (Fp2.is0(n))
|
|
24901
25098
|
return n;
|
|
24902
|
-
if (FpLegendre2(
|
|
25099
|
+
if (FpLegendre2(Fp2, n) !== 1)
|
|
24903
25100
|
throw new Error("Cannot find square root");
|
|
24904
25101
|
let M = S;
|
|
24905
|
-
let c =
|
|
24906
|
-
let t =
|
|
24907
|
-
let R =
|
|
24908
|
-
while (!
|
|
24909
|
-
if (
|
|
24910
|
-
return
|
|
25102
|
+
let c = Fp2.mul(Fp2.ONE, cc);
|
|
25103
|
+
let t = Fp2.pow(n, Q);
|
|
25104
|
+
let R = Fp2.pow(n, Q1div2);
|
|
25105
|
+
while (!Fp2.eql(t, Fp2.ONE)) {
|
|
25106
|
+
if (Fp2.is0(t))
|
|
25107
|
+
return Fp2.ZERO;
|
|
24911
25108
|
let i = 1;
|
|
24912
|
-
let t_tmp =
|
|
24913
|
-
while (!
|
|
25109
|
+
let t_tmp = Fp2.sqr(t);
|
|
25110
|
+
while (!Fp2.eql(t_tmp, Fp2.ONE)) {
|
|
24914
25111
|
i++;
|
|
24915
|
-
t_tmp =
|
|
25112
|
+
t_tmp = Fp2.sqr(t_tmp);
|
|
24916
25113
|
if (i === M)
|
|
24917
25114
|
throw new Error("Cannot find square root");
|
|
24918
25115
|
}
|
|
24919
25116
|
const exponent = _1n7 << BigInt(M - i - 1);
|
|
24920
|
-
const b =
|
|
25117
|
+
const b = Fp2.pow(c, exponent);
|
|
24921
25118
|
M = i;
|
|
24922
|
-
c =
|
|
24923
|
-
t =
|
|
24924
|
-
R =
|
|
25119
|
+
c = Fp2.sqr(b);
|
|
25120
|
+
t = Fp2.mul(t, c);
|
|
25121
|
+
R = Fp2.mul(R, b);
|
|
24925
25122
|
}
|
|
24926
25123
|
return R;
|
|
24927
25124
|
};
|
|
@@ -24935,6 +25132,7 @@ function FpSqrt2(P) {
|
|
|
24935
25132
|
return sqrt9mod162(P);
|
|
24936
25133
|
return tonelliShanks2(P);
|
|
24937
25134
|
}
|
|
25135
|
+
var isNegativeLE2 = (num, modulo) => (mod2(num, modulo) & _1n7) === _1n7;
|
|
24938
25136
|
var FIELD_FIELDS2 = [
|
|
24939
25137
|
"create",
|
|
24940
25138
|
"isValid",
|
|
@@ -24968,46 +25166,46 @@ function validateField2(field) {
|
|
|
24968
25166
|
_validateObject(field, opts);
|
|
24969
25167
|
return field;
|
|
24970
25168
|
}
|
|
24971
|
-
function FpPow2(
|
|
25169
|
+
function FpPow2(Fp2, num, power) {
|
|
24972
25170
|
if (power < _0n6)
|
|
24973
25171
|
throw new Error("invalid exponent, negatives unsupported");
|
|
24974
25172
|
if (power === _0n6)
|
|
24975
|
-
return
|
|
25173
|
+
return Fp2.ONE;
|
|
24976
25174
|
if (power === _1n7)
|
|
24977
25175
|
return num;
|
|
24978
|
-
let p =
|
|
25176
|
+
let p = Fp2.ONE;
|
|
24979
25177
|
let d = num;
|
|
24980
25178
|
while (power > _0n6) {
|
|
24981
25179
|
if (power & _1n7)
|
|
24982
|
-
p =
|
|
24983
|
-
d =
|
|
25180
|
+
p = Fp2.mul(p, d);
|
|
25181
|
+
d = Fp2.sqr(d);
|
|
24984
25182
|
power >>= _1n7;
|
|
24985
25183
|
}
|
|
24986
25184
|
return p;
|
|
24987
25185
|
}
|
|
24988
|
-
function FpInvertBatch2(
|
|
24989
|
-
const inverted = new Array(nums.length).fill(passZero ?
|
|
25186
|
+
function FpInvertBatch2(Fp2, nums, passZero = false) {
|
|
25187
|
+
const inverted = new Array(nums.length).fill(passZero ? Fp2.ZERO : void 0);
|
|
24990
25188
|
const multipliedAcc = nums.reduce((acc, num, i) => {
|
|
24991
|
-
if (
|
|
25189
|
+
if (Fp2.is0(num))
|
|
24992
25190
|
return acc;
|
|
24993
25191
|
inverted[i] = acc;
|
|
24994
|
-
return
|
|
24995
|
-
},
|
|
24996
|
-
const invertedAcc =
|
|
25192
|
+
return Fp2.mul(acc, num);
|
|
25193
|
+
}, Fp2.ONE);
|
|
25194
|
+
const invertedAcc = Fp2.inv(multipliedAcc);
|
|
24997
25195
|
nums.reduceRight((acc, num, i) => {
|
|
24998
|
-
if (
|
|
25196
|
+
if (Fp2.is0(num))
|
|
24999
25197
|
return acc;
|
|
25000
|
-
inverted[i] =
|
|
25001
|
-
return
|
|
25198
|
+
inverted[i] = Fp2.mul(acc, inverted[i]);
|
|
25199
|
+
return Fp2.mul(acc, num);
|
|
25002
25200
|
}, invertedAcc);
|
|
25003
25201
|
return inverted;
|
|
25004
25202
|
}
|
|
25005
|
-
function FpLegendre2(
|
|
25006
|
-
const p1mod2 = (
|
|
25007
|
-
const powered =
|
|
25008
|
-
const yes =
|
|
25009
|
-
const zero =
|
|
25010
|
-
const no =
|
|
25203
|
+
function FpLegendre2(Fp2, n) {
|
|
25204
|
+
const p1mod2 = (Fp2.ORDER - _1n7) / _2n4;
|
|
25205
|
+
const powered = Fp2.pow(n, p1mod2);
|
|
25206
|
+
const yes = Fp2.eql(powered, Fp2.ONE);
|
|
25207
|
+
const zero = Fp2.eql(powered, Fp2.ZERO);
|
|
25208
|
+
const no = Fp2.eql(powered, Fp2.neg(Fp2.ONE));
|
|
25011
25209
|
if (!yes && !zero && !no)
|
|
25012
25210
|
throw new Error("invalid Legendre symbol result");
|
|
25013
25211
|
return yes ? 1 : zero ? 0 : -1;
|
|
@@ -25307,130 +25505,972 @@ var wNAF2 = class {
|
|
|
25307
25505
|
}
|
|
25308
25506
|
return comp;
|
|
25309
25507
|
}
|
|
25310
|
-
cached(point, scalar, transform) {
|
|
25311
|
-
const W = getW2(point);
|
|
25312
|
-
return this.wNAF(W, this.getPrecomputes(W, point, transform), scalar);
|
|
25508
|
+
cached(point, scalar, transform) {
|
|
25509
|
+
const W = getW2(point);
|
|
25510
|
+
return this.wNAF(W, this.getPrecomputes(W, point, transform), scalar);
|
|
25511
|
+
}
|
|
25512
|
+
unsafe(point, scalar, transform, prev) {
|
|
25513
|
+
const W = getW2(point);
|
|
25514
|
+
if (W === 1)
|
|
25515
|
+
return this._unsafeLadder(point, scalar, prev);
|
|
25516
|
+
return this.wNAFUnsafe(W, this.getPrecomputes(W, point, transform), scalar, prev);
|
|
25517
|
+
}
|
|
25518
|
+
// We calculate precomputes for elliptic curve point multiplication
|
|
25519
|
+
// using windowed method. This specifies window size and
|
|
25520
|
+
// stores precomputed values. Usually only base point would be precomputed.
|
|
25521
|
+
createCache(P, W) {
|
|
25522
|
+
validateW2(W, this.bits);
|
|
25523
|
+
pointWindowSizes2.set(P, W);
|
|
25524
|
+
pointPrecomputes2.delete(P);
|
|
25525
|
+
}
|
|
25526
|
+
hasCache(elm) {
|
|
25527
|
+
return getW2(elm) !== 1;
|
|
25528
|
+
}
|
|
25529
|
+
};
|
|
25530
|
+
function mulEndoUnsafe(Point, point, k1, k2) {
|
|
25531
|
+
let acc = point;
|
|
25532
|
+
let p1 = Point.ZERO;
|
|
25533
|
+
let p2 = Point.ZERO;
|
|
25534
|
+
while (k1 > _0n7 || k2 > _0n7) {
|
|
25535
|
+
if (k1 & _1n8)
|
|
25536
|
+
p1 = p1.add(acc);
|
|
25537
|
+
if (k2 & _1n8)
|
|
25538
|
+
p2 = p2.add(acc);
|
|
25539
|
+
acc = acc.double();
|
|
25540
|
+
k1 >>= _1n8;
|
|
25541
|
+
k2 >>= _1n8;
|
|
25542
|
+
}
|
|
25543
|
+
return { p1, p2 };
|
|
25544
|
+
}
|
|
25545
|
+
function pippenger(c, fieldN, points, scalars) {
|
|
25546
|
+
validateMSMPoints(points, c);
|
|
25547
|
+
validateMSMScalars(scalars, fieldN);
|
|
25548
|
+
const plength = points.length;
|
|
25549
|
+
const slength = scalars.length;
|
|
25550
|
+
if (plength !== slength)
|
|
25551
|
+
throw new Error("arrays of points and scalars must have equal length");
|
|
25552
|
+
const zero = c.ZERO;
|
|
25553
|
+
const wbits = bitLen2(BigInt(plength));
|
|
25554
|
+
let windowSize = 1;
|
|
25555
|
+
if (wbits > 12)
|
|
25556
|
+
windowSize = wbits - 3;
|
|
25557
|
+
else if (wbits > 4)
|
|
25558
|
+
windowSize = wbits - 2;
|
|
25559
|
+
else if (wbits > 0)
|
|
25560
|
+
windowSize = 2;
|
|
25561
|
+
const MASK = bitMask2(windowSize);
|
|
25562
|
+
const buckets = new Array(Number(MASK) + 1).fill(zero);
|
|
25563
|
+
const lastBits = Math.floor((fieldN.BITS - 1) / windowSize) * windowSize;
|
|
25564
|
+
let sum = zero;
|
|
25565
|
+
for (let i = lastBits; i >= 0; i -= windowSize) {
|
|
25566
|
+
buckets.fill(zero);
|
|
25567
|
+
for (let j = 0; j < slength; j++) {
|
|
25568
|
+
const scalar = scalars[j];
|
|
25569
|
+
const wbits2 = Number(scalar >> BigInt(i) & MASK);
|
|
25570
|
+
buckets[wbits2] = buckets[wbits2].add(points[j]);
|
|
25571
|
+
}
|
|
25572
|
+
let resI = zero;
|
|
25573
|
+
for (let j = buckets.length - 1, sumI = zero; j > 0; j--) {
|
|
25574
|
+
sumI = sumI.add(buckets[j]);
|
|
25575
|
+
resI = resI.add(sumI);
|
|
25576
|
+
}
|
|
25577
|
+
sum = sum.add(resI);
|
|
25578
|
+
if (i !== 0)
|
|
25579
|
+
for (let j = 0; j < windowSize; j++)
|
|
25580
|
+
sum = sum.double();
|
|
25581
|
+
}
|
|
25582
|
+
return sum;
|
|
25583
|
+
}
|
|
25584
|
+
function createField2(order, field, isLE) {
|
|
25585
|
+
if (field) {
|
|
25586
|
+
if (field.ORDER !== order)
|
|
25587
|
+
throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
|
|
25588
|
+
validateField2(field);
|
|
25589
|
+
return field;
|
|
25590
|
+
} else {
|
|
25591
|
+
return Field2(order, { isLE });
|
|
25592
|
+
}
|
|
25593
|
+
}
|
|
25594
|
+
function _createCurveFields(type, CURVE, curveOpts = {}, FpFnLE) {
|
|
25595
|
+
if (FpFnLE === void 0)
|
|
25596
|
+
FpFnLE = type === "edwards";
|
|
25597
|
+
if (!CURVE || typeof CURVE !== "object")
|
|
25598
|
+
throw new Error(`expected valid ${type} CURVE object`);
|
|
25599
|
+
for (const p of ["p", "n", "h"]) {
|
|
25600
|
+
const val = CURVE[p];
|
|
25601
|
+
if (!(typeof val === "bigint" && val > _0n7))
|
|
25602
|
+
throw new Error(`CURVE.${p} must be positive bigint`);
|
|
25603
|
+
}
|
|
25604
|
+
const Fp2 = createField2(CURVE.p, curveOpts.Fp, FpFnLE);
|
|
25605
|
+
const Fn2 = createField2(CURVE.n, curveOpts.Fn, FpFnLE);
|
|
25606
|
+
const _b = type === "weierstrass" ? "b" : "d";
|
|
25607
|
+
const params = ["Gx", "Gy", "a", _b];
|
|
25608
|
+
for (const p of params) {
|
|
25609
|
+
if (!Fp2.isValid(CURVE[p]))
|
|
25610
|
+
throw new Error(`CURVE.${p} must be valid field element of CURVE.Fp`);
|
|
25611
|
+
}
|
|
25612
|
+
CURVE = Object.freeze(Object.assign({}, CURVE));
|
|
25613
|
+
return { CURVE, Fp: Fp2, Fn: Fn2 };
|
|
25614
|
+
}
|
|
25615
|
+
|
|
25616
|
+
// ../../node_modules/.pnpm/@noble+curves@1.9.7/node_modules/@noble/curves/esm/abstract/edwards.js
|
|
25617
|
+
var _0n8 = BigInt(0);
|
|
25618
|
+
var _1n9 = BigInt(1);
|
|
25619
|
+
var _2n5 = BigInt(2);
|
|
25620
|
+
var _8n5 = BigInt(8);
|
|
25621
|
+
function isEdValidXY2(Fp2, CURVE, x, y) {
|
|
25622
|
+
const x2 = Fp2.sqr(x);
|
|
25623
|
+
const y2 = Fp2.sqr(y);
|
|
25624
|
+
const left = Fp2.add(Fp2.mul(CURVE.a, x2), y2);
|
|
25625
|
+
const right = Fp2.add(Fp2.ONE, Fp2.mul(CURVE.d, Fp2.mul(x2, y2)));
|
|
25626
|
+
return Fp2.eql(left, right);
|
|
25627
|
+
}
|
|
25628
|
+
function edwards2(params, extraOpts = {}) {
|
|
25629
|
+
const validated = _createCurveFields("edwards", params, extraOpts, extraOpts.FpFnLE);
|
|
25630
|
+
const { Fp: Fp2, Fn: Fn2 } = validated;
|
|
25631
|
+
let CURVE = validated.CURVE;
|
|
25632
|
+
const { h: cofactor } = CURVE;
|
|
25633
|
+
_validateObject(extraOpts, {}, { uvRatio: "function" });
|
|
25634
|
+
const MASK = _2n5 << BigInt(Fn2.BYTES * 8) - _1n9;
|
|
25635
|
+
const modP = (n) => Fp2.create(n);
|
|
25636
|
+
const uvRatio3 = extraOpts.uvRatio || ((u, v) => {
|
|
25637
|
+
try {
|
|
25638
|
+
return { isValid: true, value: Fp2.sqrt(Fp2.div(u, v)) };
|
|
25639
|
+
} catch (e) {
|
|
25640
|
+
return { isValid: false, value: _0n8 };
|
|
25641
|
+
}
|
|
25642
|
+
});
|
|
25643
|
+
if (!isEdValidXY2(Fp2, CURVE, CURVE.Gx, CURVE.Gy))
|
|
25644
|
+
throw new Error("bad curve params: generator point");
|
|
25645
|
+
function acoord(title, n, banZero = false) {
|
|
25646
|
+
const min = banZero ? _1n9 : _0n8;
|
|
25647
|
+
aInRange2("coordinate " + title, n, min, MASK);
|
|
25648
|
+
return n;
|
|
25649
|
+
}
|
|
25650
|
+
function aextpoint(other) {
|
|
25651
|
+
if (!(other instanceof Point))
|
|
25652
|
+
throw new Error("ExtendedPoint expected");
|
|
25653
|
+
}
|
|
25654
|
+
const toAffineMemo = memoized2((p, iz) => {
|
|
25655
|
+
const { X, Y, Z } = p;
|
|
25656
|
+
const is0 = p.is0();
|
|
25657
|
+
if (iz == null)
|
|
25658
|
+
iz = is0 ? _8n5 : Fp2.inv(Z);
|
|
25659
|
+
const x = modP(X * iz);
|
|
25660
|
+
const y = modP(Y * iz);
|
|
25661
|
+
const zz = Fp2.mul(Z, iz);
|
|
25662
|
+
if (is0)
|
|
25663
|
+
return { x: _0n8, y: _1n9 };
|
|
25664
|
+
if (zz !== _1n9)
|
|
25665
|
+
throw new Error("invZ was invalid");
|
|
25666
|
+
return { x, y };
|
|
25667
|
+
});
|
|
25668
|
+
const assertValidMemo = memoized2((p) => {
|
|
25669
|
+
const { a, d } = CURVE;
|
|
25670
|
+
if (p.is0())
|
|
25671
|
+
throw new Error("bad point: ZERO");
|
|
25672
|
+
const { X, Y, Z, T } = p;
|
|
25673
|
+
const X2 = modP(X * X);
|
|
25674
|
+
const Y2 = modP(Y * Y);
|
|
25675
|
+
const Z2 = modP(Z * Z);
|
|
25676
|
+
const Z4 = modP(Z2 * Z2);
|
|
25677
|
+
const aX2 = modP(X2 * a);
|
|
25678
|
+
const left = modP(Z2 * modP(aX2 + Y2));
|
|
25679
|
+
const right = modP(Z4 + modP(d * modP(X2 * Y2)));
|
|
25680
|
+
if (left !== right)
|
|
25681
|
+
throw new Error("bad point: equation left != right (1)");
|
|
25682
|
+
const XY = modP(X * Y);
|
|
25683
|
+
const ZT = modP(Z * T);
|
|
25684
|
+
if (XY !== ZT)
|
|
25685
|
+
throw new Error("bad point: equation left != right (2)");
|
|
25686
|
+
return true;
|
|
25687
|
+
});
|
|
25688
|
+
class Point {
|
|
25689
|
+
constructor(X, Y, Z, T) {
|
|
25690
|
+
this.X = acoord("x", X);
|
|
25691
|
+
this.Y = acoord("y", Y);
|
|
25692
|
+
this.Z = acoord("z", Z, true);
|
|
25693
|
+
this.T = acoord("t", T);
|
|
25694
|
+
Object.freeze(this);
|
|
25695
|
+
}
|
|
25696
|
+
static CURVE() {
|
|
25697
|
+
return CURVE;
|
|
25698
|
+
}
|
|
25699
|
+
static fromAffine(p) {
|
|
25700
|
+
if (p instanceof Point)
|
|
25701
|
+
throw new Error("extended point not allowed");
|
|
25702
|
+
const { x, y } = p || {};
|
|
25703
|
+
acoord("x", x);
|
|
25704
|
+
acoord("y", y);
|
|
25705
|
+
return new Point(x, y, _1n9, modP(x * y));
|
|
25706
|
+
}
|
|
25707
|
+
// Uses algo from RFC8032 5.1.3.
|
|
25708
|
+
static fromBytes(bytes, zip215 = false) {
|
|
25709
|
+
const len = Fp2.BYTES;
|
|
25710
|
+
const { a, d } = CURVE;
|
|
25711
|
+
bytes = copyBytes2(_abytes2(bytes, len, "point"));
|
|
25712
|
+
_abool2(zip215, "zip215");
|
|
25713
|
+
const normed = copyBytes2(bytes);
|
|
25714
|
+
const lastByte = bytes[len - 1];
|
|
25715
|
+
normed[len - 1] = lastByte & ~128;
|
|
25716
|
+
const y = bytesToNumberLE2(normed);
|
|
25717
|
+
const max = zip215 ? MASK : Fp2.ORDER;
|
|
25718
|
+
aInRange2("point.y", y, _0n8, max);
|
|
25719
|
+
const y2 = modP(y * y);
|
|
25720
|
+
const u = modP(y2 - _1n9);
|
|
25721
|
+
const v = modP(d * y2 - a);
|
|
25722
|
+
let { isValid, value: x } = uvRatio3(u, v);
|
|
25723
|
+
if (!isValid)
|
|
25724
|
+
throw new Error("bad point: invalid y coordinate");
|
|
25725
|
+
const isXOdd = (x & _1n9) === _1n9;
|
|
25726
|
+
const isLastByteOdd = (lastByte & 128) !== 0;
|
|
25727
|
+
if (!zip215 && x === _0n8 && isLastByteOdd)
|
|
25728
|
+
throw new Error("bad point: x=0 and x_0=1");
|
|
25729
|
+
if (isLastByteOdd !== isXOdd)
|
|
25730
|
+
x = modP(-x);
|
|
25731
|
+
return Point.fromAffine({ x, y });
|
|
25732
|
+
}
|
|
25733
|
+
static fromHex(bytes, zip215 = false) {
|
|
25734
|
+
return Point.fromBytes(ensureBytes("point", bytes), zip215);
|
|
25735
|
+
}
|
|
25736
|
+
get x() {
|
|
25737
|
+
return this.toAffine().x;
|
|
25738
|
+
}
|
|
25739
|
+
get y() {
|
|
25740
|
+
return this.toAffine().y;
|
|
25741
|
+
}
|
|
25742
|
+
precompute(windowSize = 8, isLazy = true) {
|
|
25743
|
+
wnaf.createCache(this, windowSize);
|
|
25744
|
+
if (!isLazy)
|
|
25745
|
+
this.multiply(_2n5);
|
|
25746
|
+
return this;
|
|
25747
|
+
}
|
|
25748
|
+
// Useful in fromAffine() - not for fromBytes(), which always created valid points.
|
|
25749
|
+
assertValidity() {
|
|
25750
|
+
assertValidMemo(this);
|
|
25751
|
+
}
|
|
25752
|
+
// Compare one point to another.
|
|
25753
|
+
equals(other) {
|
|
25754
|
+
aextpoint(other);
|
|
25755
|
+
const { X: X1, Y: Y1, Z: Z1 } = this;
|
|
25756
|
+
const { X: X2, Y: Y2, Z: Z2 } = other;
|
|
25757
|
+
const X1Z2 = modP(X1 * Z2);
|
|
25758
|
+
const X2Z1 = modP(X2 * Z1);
|
|
25759
|
+
const Y1Z2 = modP(Y1 * Z2);
|
|
25760
|
+
const Y2Z1 = modP(Y2 * Z1);
|
|
25761
|
+
return X1Z2 === X2Z1 && Y1Z2 === Y2Z1;
|
|
25762
|
+
}
|
|
25763
|
+
is0() {
|
|
25764
|
+
return this.equals(Point.ZERO);
|
|
25765
|
+
}
|
|
25766
|
+
negate() {
|
|
25767
|
+
return new Point(modP(-this.X), this.Y, this.Z, modP(-this.T));
|
|
25768
|
+
}
|
|
25769
|
+
// Fast algo for doubling Extended Point.
|
|
25770
|
+
// https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#doubling-dbl-2008-hwcd
|
|
25771
|
+
// Cost: 4M + 4S + 1*a + 6add + 1*2.
|
|
25772
|
+
double() {
|
|
25773
|
+
const { a } = CURVE;
|
|
25774
|
+
const { X: X1, Y: Y1, Z: Z1 } = this;
|
|
25775
|
+
const A = modP(X1 * X1);
|
|
25776
|
+
const B = modP(Y1 * Y1);
|
|
25777
|
+
const C = modP(_2n5 * modP(Z1 * Z1));
|
|
25778
|
+
const D = modP(a * A);
|
|
25779
|
+
const x1y1 = X1 + Y1;
|
|
25780
|
+
const E = modP(modP(x1y1 * x1y1) - A - B);
|
|
25781
|
+
const G = D + B;
|
|
25782
|
+
const F = G - C;
|
|
25783
|
+
const H = D - B;
|
|
25784
|
+
const X3 = modP(E * F);
|
|
25785
|
+
const Y3 = modP(G * H);
|
|
25786
|
+
const T3 = modP(E * H);
|
|
25787
|
+
const Z3 = modP(F * G);
|
|
25788
|
+
return new Point(X3, Y3, Z3, T3);
|
|
25789
|
+
}
|
|
25790
|
+
// Fast algo for adding 2 Extended Points.
|
|
25791
|
+
// https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#addition-add-2008-hwcd
|
|
25792
|
+
// Cost: 9M + 1*a + 1*d + 7add.
|
|
25793
|
+
add(other) {
|
|
25794
|
+
aextpoint(other);
|
|
25795
|
+
const { a, d } = CURVE;
|
|
25796
|
+
const { X: X1, Y: Y1, Z: Z1, T: T1 } = this;
|
|
25797
|
+
const { X: X2, Y: Y2, Z: Z2, T: T2 } = other;
|
|
25798
|
+
const A = modP(X1 * X2);
|
|
25799
|
+
const B = modP(Y1 * Y2);
|
|
25800
|
+
const C = modP(T1 * d * T2);
|
|
25801
|
+
const D = modP(Z1 * Z2);
|
|
25802
|
+
const E = modP((X1 + Y1) * (X2 + Y2) - A - B);
|
|
25803
|
+
const F = D - C;
|
|
25804
|
+
const G = D + C;
|
|
25805
|
+
const H = modP(B - a * A);
|
|
25806
|
+
const X3 = modP(E * F);
|
|
25807
|
+
const Y3 = modP(G * H);
|
|
25808
|
+
const T3 = modP(E * H);
|
|
25809
|
+
const Z3 = modP(F * G);
|
|
25810
|
+
return new Point(X3, Y3, Z3, T3);
|
|
25811
|
+
}
|
|
25812
|
+
subtract(other) {
|
|
25813
|
+
return this.add(other.negate());
|
|
25814
|
+
}
|
|
25815
|
+
// Constant-time multiplication.
|
|
25816
|
+
multiply(scalar) {
|
|
25817
|
+
if (!Fn2.isValidNot0(scalar))
|
|
25818
|
+
throw new Error("invalid scalar: expected 1 <= sc < curve.n");
|
|
25819
|
+
const { p, f } = wnaf.cached(this, scalar, (p2) => normalizeZ2(Point, p2));
|
|
25820
|
+
return normalizeZ2(Point, [p, f])[0];
|
|
25821
|
+
}
|
|
25822
|
+
// Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
25823
|
+
// It's faster, but should only be used when you don't care about
|
|
25824
|
+
// an exposed private key e.g. sig verification.
|
|
25825
|
+
// Does NOT allow scalars higher than CURVE.n.
|
|
25826
|
+
// Accepts optional accumulator to merge with multiply (important for sparse scalars)
|
|
25827
|
+
multiplyUnsafe(scalar, acc = Point.ZERO) {
|
|
25828
|
+
if (!Fn2.isValid(scalar))
|
|
25829
|
+
throw new Error("invalid scalar: expected 0 <= sc < curve.n");
|
|
25830
|
+
if (scalar === _0n8)
|
|
25831
|
+
return Point.ZERO;
|
|
25832
|
+
if (this.is0() || scalar === _1n9)
|
|
25833
|
+
return this;
|
|
25834
|
+
return wnaf.unsafe(this, scalar, (p) => normalizeZ2(Point, p), acc);
|
|
25835
|
+
}
|
|
25836
|
+
// Checks if point is of small order.
|
|
25837
|
+
// If you add something to small order point, you will have "dirty"
|
|
25838
|
+
// point with torsion component.
|
|
25839
|
+
// Multiplies point by cofactor and checks if the result is 0.
|
|
25840
|
+
isSmallOrder() {
|
|
25841
|
+
return this.multiplyUnsafe(cofactor).is0();
|
|
25842
|
+
}
|
|
25843
|
+
// Multiplies point by curve order and checks if the result is 0.
|
|
25844
|
+
// Returns `false` is the point is dirty.
|
|
25845
|
+
isTorsionFree() {
|
|
25846
|
+
return wnaf.unsafe(this, CURVE.n).is0();
|
|
25847
|
+
}
|
|
25848
|
+
// Converts Extended point to default (x, y) coordinates.
|
|
25849
|
+
// Can accept precomputed Z^-1 - for example, from invertBatch.
|
|
25850
|
+
toAffine(invertedZ) {
|
|
25851
|
+
return toAffineMemo(this, invertedZ);
|
|
25852
|
+
}
|
|
25853
|
+
clearCofactor() {
|
|
25854
|
+
if (cofactor === _1n9)
|
|
25855
|
+
return this;
|
|
25856
|
+
return this.multiplyUnsafe(cofactor);
|
|
25857
|
+
}
|
|
25858
|
+
toBytes() {
|
|
25859
|
+
const { x, y } = this.toAffine();
|
|
25860
|
+
const bytes = Fp2.toBytes(y);
|
|
25861
|
+
bytes[bytes.length - 1] |= x & _1n9 ? 128 : 0;
|
|
25862
|
+
return bytes;
|
|
25863
|
+
}
|
|
25864
|
+
toHex() {
|
|
25865
|
+
return bytesToHex2(this.toBytes());
|
|
25866
|
+
}
|
|
25867
|
+
toString() {
|
|
25868
|
+
return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
|
|
25869
|
+
}
|
|
25870
|
+
// TODO: remove
|
|
25871
|
+
get ex() {
|
|
25872
|
+
return this.X;
|
|
25873
|
+
}
|
|
25874
|
+
get ey() {
|
|
25875
|
+
return this.Y;
|
|
25876
|
+
}
|
|
25877
|
+
get ez() {
|
|
25878
|
+
return this.Z;
|
|
25879
|
+
}
|
|
25880
|
+
get et() {
|
|
25881
|
+
return this.T;
|
|
25882
|
+
}
|
|
25883
|
+
static normalizeZ(points) {
|
|
25884
|
+
return normalizeZ2(Point, points);
|
|
25885
|
+
}
|
|
25886
|
+
static msm(points, scalars) {
|
|
25887
|
+
return pippenger(Point, Fn2, points, scalars);
|
|
25888
|
+
}
|
|
25889
|
+
_setWindowSize(windowSize) {
|
|
25890
|
+
this.precompute(windowSize);
|
|
25891
|
+
}
|
|
25892
|
+
toRawBytes() {
|
|
25893
|
+
return this.toBytes();
|
|
25894
|
+
}
|
|
25895
|
+
}
|
|
25896
|
+
Point.BASE = new Point(CURVE.Gx, CURVE.Gy, _1n9, modP(CURVE.Gx * CURVE.Gy));
|
|
25897
|
+
Point.ZERO = new Point(_0n8, _1n9, _1n9, _0n8);
|
|
25898
|
+
Point.Fp = Fp2;
|
|
25899
|
+
Point.Fn = Fn2;
|
|
25900
|
+
const wnaf = new wNAF2(Point, Fn2.BITS);
|
|
25901
|
+
Point.BASE.precompute(8);
|
|
25902
|
+
return Point;
|
|
25903
|
+
}
|
|
25904
|
+
var PrimeEdwardsPoint2 = class {
|
|
25905
|
+
constructor(ep) {
|
|
25906
|
+
this.ep = ep;
|
|
25907
|
+
}
|
|
25908
|
+
// Static methods that must be implemented by subclasses
|
|
25909
|
+
static fromBytes(_bytes) {
|
|
25910
|
+
notImplemented2();
|
|
25911
|
+
}
|
|
25912
|
+
static fromHex(_hex) {
|
|
25913
|
+
notImplemented2();
|
|
25914
|
+
}
|
|
25915
|
+
get x() {
|
|
25916
|
+
return this.toAffine().x;
|
|
25917
|
+
}
|
|
25918
|
+
get y() {
|
|
25919
|
+
return this.toAffine().y;
|
|
25920
|
+
}
|
|
25921
|
+
// Common implementations
|
|
25922
|
+
clearCofactor() {
|
|
25923
|
+
return this;
|
|
25924
|
+
}
|
|
25925
|
+
assertValidity() {
|
|
25926
|
+
this.ep.assertValidity();
|
|
25927
|
+
}
|
|
25928
|
+
toAffine(invertedZ) {
|
|
25929
|
+
return this.ep.toAffine(invertedZ);
|
|
25930
|
+
}
|
|
25931
|
+
toHex() {
|
|
25932
|
+
return bytesToHex2(this.toBytes());
|
|
25933
|
+
}
|
|
25934
|
+
toString() {
|
|
25935
|
+
return this.toHex();
|
|
25936
|
+
}
|
|
25937
|
+
isTorsionFree() {
|
|
25938
|
+
return true;
|
|
25939
|
+
}
|
|
25940
|
+
isSmallOrder() {
|
|
25941
|
+
return false;
|
|
25942
|
+
}
|
|
25943
|
+
add(other) {
|
|
25944
|
+
this.assertSame(other);
|
|
25945
|
+
return this.init(this.ep.add(other.ep));
|
|
25946
|
+
}
|
|
25947
|
+
subtract(other) {
|
|
25948
|
+
this.assertSame(other);
|
|
25949
|
+
return this.init(this.ep.subtract(other.ep));
|
|
25950
|
+
}
|
|
25951
|
+
multiply(scalar) {
|
|
25952
|
+
return this.init(this.ep.multiply(scalar));
|
|
25953
|
+
}
|
|
25954
|
+
multiplyUnsafe(scalar) {
|
|
25955
|
+
return this.init(this.ep.multiplyUnsafe(scalar));
|
|
25956
|
+
}
|
|
25957
|
+
double() {
|
|
25958
|
+
return this.init(this.ep.double());
|
|
25959
|
+
}
|
|
25960
|
+
negate() {
|
|
25961
|
+
return this.init(this.ep.negate());
|
|
25962
|
+
}
|
|
25963
|
+
precompute(windowSize, isLazy) {
|
|
25964
|
+
return this.init(this.ep.precompute(windowSize, isLazy));
|
|
25965
|
+
}
|
|
25966
|
+
/** @deprecated use `toBytes` */
|
|
25967
|
+
toRawBytes() {
|
|
25968
|
+
return this.toBytes();
|
|
25969
|
+
}
|
|
25970
|
+
};
|
|
25971
|
+
function eddsa2(Point, cHash, eddsaOpts = {}) {
|
|
25972
|
+
if (typeof cHash !== "function")
|
|
25973
|
+
throw new Error('"hash" function param is required');
|
|
25974
|
+
_validateObject(eddsaOpts, {}, {
|
|
25975
|
+
adjustScalarBytes: "function",
|
|
25976
|
+
randomBytes: "function",
|
|
25977
|
+
domain: "function",
|
|
25978
|
+
prehash: "function",
|
|
25979
|
+
mapToCurve: "function"
|
|
25980
|
+
});
|
|
25981
|
+
const { prehash } = eddsaOpts;
|
|
25982
|
+
const { BASE, Fp: Fp2, Fn: Fn2 } = Point;
|
|
25983
|
+
const randomBytes3 = eddsaOpts.randomBytes || randomBytes2;
|
|
25984
|
+
const adjustScalarBytes3 = eddsaOpts.adjustScalarBytes || ((bytes) => bytes);
|
|
25985
|
+
const domain = eddsaOpts.domain || ((data, ctx, phflag) => {
|
|
25986
|
+
_abool2(phflag, "phflag");
|
|
25987
|
+
if (ctx.length || phflag)
|
|
25988
|
+
throw new Error("Contexts/pre-hash are not supported");
|
|
25989
|
+
return data;
|
|
25990
|
+
});
|
|
25991
|
+
function modN_LE(hash) {
|
|
25992
|
+
return Fn2.create(bytesToNumberLE2(hash));
|
|
25993
|
+
}
|
|
25994
|
+
function getPrivateScalar(key) {
|
|
25995
|
+
const len = lengths.secretKey;
|
|
25996
|
+
key = ensureBytes("private key", key, len);
|
|
25997
|
+
const hashed = ensureBytes("hashed private key", cHash(key), 2 * len);
|
|
25998
|
+
const head = adjustScalarBytes3(hashed.slice(0, len));
|
|
25999
|
+
const prefix = hashed.slice(len, 2 * len);
|
|
26000
|
+
const scalar = modN_LE(head);
|
|
26001
|
+
return { head, prefix, scalar };
|
|
26002
|
+
}
|
|
26003
|
+
function getExtendedPublicKey(secretKey) {
|
|
26004
|
+
const { head, prefix, scalar } = getPrivateScalar(secretKey);
|
|
26005
|
+
const point = BASE.multiply(scalar);
|
|
26006
|
+
const pointBytes = point.toBytes();
|
|
26007
|
+
return { head, prefix, scalar, point, pointBytes };
|
|
26008
|
+
}
|
|
26009
|
+
function getPublicKey(secretKey) {
|
|
26010
|
+
return getExtendedPublicKey(secretKey).pointBytes;
|
|
26011
|
+
}
|
|
26012
|
+
function hashDomainToScalar(context = Uint8Array.of(), ...msgs) {
|
|
26013
|
+
const msg = concatBytes2(...msgs);
|
|
26014
|
+
return modN_LE(cHash(domain(msg, ensureBytes("context", context), !!prehash)));
|
|
26015
|
+
}
|
|
26016
|
+
function sign(msg, secretKey, options = {}) {
|
|
26017
|
+
msg = ensureBytes("message", msg);
|
|
26018
|
+
if (prehash)
|
|
26019
|
+
msg = prehash(msg);
|
|
26020
|
+
const { prefix, scalar, pointBytes } = getExtendedPublicKey(secretKey);
|
|
26021
|
+
const r = hashDomainToScalar(options.context, prefix, msg);
|
|
26022
|
+
const R = BASE.multiply(r).toBytes();
|
|
26023
|
+
const k = hashDomainToScalar(options.context, R, pointBytes, msg);
|
|
26024
|
+
const s = Fn2.create(r + k * scalar);
|
|
26025
|
+
if (!Fn2.isValid(s))
|
|
26026
|
+
throw new Error("sign failed: invalid s");
|
|
26027
|
+
const rs = concatBytes2(R, Fn2.toBytes(s));
|
|
26028
|
+
return _abytes2(rs, lengths.signature, "result");
|
|
26029
|
+
}
|
|
26030
|
+
const verifyOpts = { zip215: true };
|
|
26031
|
+
function verify(sig, msg, publicKey, options = verifyOpts) {
|
|
26032
|
+
const { context, zip215 } = options;
|
|
26033
|
+
const len = lengths.signature;
|
|
26034
|
+
sig = ensureBytes("signature", sig, len);
|
|
26035
|
+
msg = ensureBytes("message", msg);
|
|
26036
|
+
publicKey = ensureBytes("publicKey", publicKey, lengths.publicKey);
|
|
26037
|
+
if (zip215 !== void 0)
|
|
26038
|
+
_abool2(zip215, "zip215");
|
|
26039
|
+
if (prehash)
|
|
26040
|
+
msg = prehash(msg);
|
|
26041
|
+
const mid = len / 2;
|
|
26042
|
+
const r = sig.subarray(0, mid);
|
|
26043
|
+
const s = bytesToNumberLE2(sig.subarray(mid, len));
|
|
26044
|
+
let A, R, SB;
|
|
26045
|
+
try {
|
|
26046
|
+
A = Point.fromBytes(publicKey, zip215);
|
|
26047
|
+
R = Point.fromBytes(r, zip215);
|
|
26048
|
+
SB = BASE.multiplyUnsafe(s);
|
|
26049
|
+
} catch (error) {
|
|
26050
|
+
return false;
|
|
26051
|
+
}
|
|
26052
|
+
if (!zip215 && A.isSmallOrder())
|
|
26053
|
+
return false;
|
|
26054
|
+
const k = hashDomainToScalar(context, R.toBytes(), A.toBytes(), msg);
|
|
26055
|
+
const RkA = R.add(A.multiplyUnsafe(k));
|
|
26056
|
+
return RkA.subtract(SB).clearCofactor().is0();
|
|
26057
|
+
}
|
|
26058
|
+
const _size = Fp2.BYTES;
|
|
26059
|
+
const lengths = {
|
|
26060
|
+
secretKey: _size,
|
|
26061
|
+
publicKey: _size,
|
|
26062
|
+
signature: 2 * _size,
|
|
26063
|
+
seed: _size
|
|
26064
|
+
};
|
|
26065
|
+
function randomSecretKey(seed = randomBytes3(lengths.seed)) {
|
|
26066
|
+
return _abytes2(seed, lengths.seed, "seed");
|
|
26067
|
+
}
|
|
26068
|
+
function keygen(seed) {
|
|
26069
|
+
const secretKey = utils.randomSecretKey(seed);
|
|
26070
|
+
return { secretKey, publicKey: getPublicKey(secretKey) };
|
|
26071
|
+
}
|
|
26072
|
+
function isValidSecretKey(key) {
|
|
26073
|
+
return isBytes3(key) && key.length === Fn2.BYTES;
|
|
26074
|
+
}
|
|
26075
|
+
function isValidPublicKey(key, zip215) {
|
|
26076
|
+
try {
|
|
26077
|
+
return !!Point.fromBytes(key, zip215);
|
|
26078
|
+
} catch (error) {
|
|
26079
|
+
return false;
|
|
26080
|
+
}
|
|
26081
|
+
}
|
|
26082
|
+
const utils = {
|
|
26083
|
+
getExtendedPublicKey,
|
|
26084
|
+
randomSecretKey,
|
|
26085
|
+
isValidSecretKey,
|
|
26086
|
+
isValidPublicKey,
|
|
26087
|
+
/**
|
|
26088
|
+
* Converts ed public key to x public key. Uses formula:
|
|
26089
|
+
* - ed25519:
|
|
26090
|
+
* - `(u, v) = ((1+y)/(1-y), sqrt(-486664)*u/x)`
|
|
26091
|
+
* - `(x, y) = (sqrt(-486664)*u/v, (u-1)/(u+1))`
|
|
26092
|
+
* - ed448:
|
|
26093
|
+
* - `(u, v) = ((y-1)/(y+1), sqrt(156324)*u/x)`
|
|
26094
|
+
* - `(x, y) = (sqrt(156324)*u/v, (1+u)/(1-u))`
|
|
26095
|
+
*/
|
|
26096
|
+
toMontgomery(publicKey) {
|
|
26097
|
+
const { y } = Point.fromBytes(publicKey);
|
|
26098
|
+
const size = lengths.publicKey;
|
|
26099
|
+
const is25519 = size === 32;
|
|
26100
|
+
if (!is25519 && size !== 57)
|
|
26101
|
+
throw new Error("only defined for 25519 and 448");
|
|
26102
|
+
const u = is25519 ? Fp2.div(_1n9 + y, _1n9 - y) : Fp2.div(y - _1n9, y + _1n9);
|
|
26103
|
+
return Fp2.toBytes(u);
|
|
26104
|
+
},
|
|
26105
|
+
toMontgomerySecret(secretKey) {
|
|
26106
|
+
const size = lengths.secretKey;
|
|
26107
|
+
_abytes2(secretKey, size);
|
|
26108
|
+
const hashed = cHash(secretKey.subarray(0, size));
|
|
26109
|
+
return adjustScalarBytes3(hashed).subarray(0, size);
|
|
26110
|
+
},
|
|
26111
|
+
/** @deprecated */
|
|
26112
|
+
randomPrivateKey: randomSecretKey,
|
|
26113
|
+
/** @deprecated */
|
|
26114
|
+
precompute(windowSize = 8, point = Point.BASE) {
|
|
26115
|
+
return point.precompute(windowSize, false);
|
|
26116
|
+
}
|
|
26117
|
+
};
|
|
26118
|
+
return Object.freeze({
|
|
26119
|
+
keygen,
|
|
26120
|
+
getPublicKey,
|
|
26121
|
+
sign,
|
|
26122
|
+
verify,
|
|
26123
|
+
utils,
|
|
26124
|
+
Point,
|
|
26125
|
+
lengths
|
|
26126
|
+
});
|
|
26127
|
+
}
|
|
26128
|
+
function _eddsa_legacy_opts_to_new(c) {
|
|
26129
|
+
const CURVE = {
|
|
26130
|
+
a: c.a,
|
|
26131
|
+
d: c.d,
|
|
26132
|
+
p: c.Fp.ORDER,
|
|
26133
|
+
n: c.n,
|
|
26134
|
+
h: c.h,
|
|
26135
|
+
Gx: c.Gx,
|
|
26136
|
+
Gy: c.Gy
|
|
26137
|
+
};
|
|
26138
|
+
const Fp2 = c.Fp;
|
|
26139
|
+
const Fn2 = Field2(CURVE.n, c.nBitLength, true);
|
|
26140
|
+
const curveOpts = { Fp: Fp2, Fn: Fn2, uvRatio: c.uvRatio };
|
|
26141
|
+
const eddsaOpts = {
|
|
26142
|
+
randomBytes: c.randomBytes,
|
|
26143
|
+
adjustScalarBytes: c.adjustScalarBytes,
|
|
26144
|
+
domain: c.domain,
|
|
26145
|
+
prehash: c.prehash,
|
|
26146
|
+
mapToCurve: c.mapToCurve
|
|
26147
|
+
};
|
|
26148
|
+
return { CURVE, curveOpts, hash: c.hash, eddsaOpts };
|
|
26149
|
+
}
|
|
26150
|
+
function _eddsa_new_output_to_legacy(c, eddsa3) {
|
|
26151
|
+
const Point = eddsa3.Point;
|
|
26152
|
+
const legacy = Object.assign({}, eddsa3, {
|
|
26153
|
+
ExtendedPoint: Point,
|
|
26154
|
+
CURVE: c,
|
|
26155
|
+
nBitLength: Point.Fn.BITS,
|
|
26156
|
+
nByteLength: Point.Fn.BYTES
|
|
26157
|
+
});
|
|
26158
|
+
return legacy;
|
|
26159
|
+
}
|
|
26160
|
+
function twistedEdwards(c) {
|
|
26161
|
+
const { CURVE, curveOpts, hash, eddsaOpts } = _eddsa_legacy_opts_to_new(c);
|
|
26162
|
+
const Point = edwards2(CURVE, curveOpts);
|
|
26163
|
+
const EDDSA = eddsa2(Point, hash, eddsaOpts);
|
|
26164
|
+
return _eddsa_new_output_to_legacy(c, EDDSA);
|
|
26165
|
+
}
|
|
26166
|
+
|
|
26167
|
+
// ../../node_modules/.pnpm/@noble+curves@1.9.7/node_modules/@noble/curves/esm/ed25519.js
|
|
26168
|
+
var _0n9 = /* @__PURE__ */ BigInt(0);
|
|
26169
|
+
var _1n10 = BigInt(1);
|
|
26170
|
+
var _2n6 = BigInt(2);
|
|
26171
|
+
var _3n3 = BigInt(3);
|
|
26172
|
+
var _5n4 = BigInt(5);
|
|
26173
|
+
var _8n6 = BigInt(8);
|
|
26174
|
+
var ed25519_CURVE_p2 = BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed");
|
|
26175
|
+
var ed25519_CURVE2 = /* @__PURE__ */ (() => ({
|
|
26176
|
+
p: ed25519_CURVE_p2,
|
|
26177
|
+
n: BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),
|
|
26178
|
+
h: _8n6,
|
|
26179
|
+
a: BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),
|
|
26180
|
+
d: BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),
|
|
26181
|
+
Gx: BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),
|
|
26182
|
+
Gy: BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")
|
|
26183
|
+
}))();
|
|
26184
|
+
function ed25519_pow_2_252_32(x) {
|
|
26185
|
+
const _10n = BigInt(10), _20n = BigInt(20), _40n = BigInt(40), _80n = BigInt(80);
|
|
26186
|
+
const P = ed25519_CURVE_p2;
|
|
26187
|
+
const x2 = x * x % P;
|
|
26188
|
+
const b2 = x2 * x % P;
|
|
26189
|
+
const b4 = pow22(b2, _2n6, P) * b2 % P;
|
|
26190
|
+
const b5 = pow22(b4, _1n10, P) * x % P;
|
|
26191
|
+
const b10 = pow22(b5, _5n4, P) * b5 % P;
|
|
26192
|
+
const b20 = pow22(b10, _10n, P) * b10 % P;
|
|
26193
|
+
const b40 = pow22(b20, _20n, P) * b20 % P;
|
|
26194
|
+
const b80 = pow22(b40, _40n, P) * b40 % P;
|
|
26195
|
+
const b160 = pow22(b80, _80n, P) * b80 % P;
|
|
26196
|
+
const b240 = pow22(b160, _80n, P) * b80 % P;
|
|
26197
|
+
const b250 = pow22(b240, _10n, P) * b10 % P;
|
|
26198
|
+
const pow_p_5_8 = pow22(b250, _2n6, P) * x % P;
|
|
26199
|
+
return { pow_p_5_8, b2 };
|
|
26200
|
+
}
|
|
26201
|
+
function adjustScalarBytes2(bytes) {
|
|
26202
|
+
bytes[0] &= 248;
|
|
26203
|
+
bytes[31] &= 127;
|
|
26204
|
+
bytes[31] |= 64;
|
|
26205
|
+
return bytes;
|
|
26206
|
+
}
|
|
26207
|
+
var ED25519_SQRT_M12 = /* @__PURE__ */ BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");
|
|
26208
|
+
function uvRatio2(u, v) {
|
|
26209
|
+
const P = ed25519_CURVE_p2;
|
|
26210
|
+
const v3 = mod2(v * v * v, P);
|
|
26211
|
+
const v7 = mod2(v3 * v3 * v, P);
|
|
26212
|
+
const pow = ed25519_pow_2_252_32(u * v7).pow_p_5_8;
|
|
26213
|
+
let x = mod2(u * v3 * pow, P);
|
|
26214
|
+
const vx2 = mod2(v * x * x, P);
|
|
26215
|
+
const root1 = x;
|
|
26216
|
+
const root2 = mod2(x * ED25519_SQRT_M12, P);
|
|
26217
|
+
const useRoot1 = vx2 === u;
|
|
26218
|
+
const useRoot2 = vx2 === mod2(-u, P);
|
|
26219
|
+
const noRoot = vx2 === mod2(-u * ED25519_SQRT_M12, P);
|
|
26220
|
+
if (useRoot1)
|
|
26221
|
+
x = root1;
|
|
26222
|
+
if (useRoot2 || noRoot)
|
|
26223
|
+
x = root2;
|
|
26224
|
+
if (isNegativeLE2(x, P))
|
|
26225
|
+
x = mod2(-x, P);
|
|
26226
|
+
return { isValid: useRoot1 || useRoot2, value: x };
|
|
26227
|
+
}
|
|
26228
|
+
var Fp = /* @__PURE__ */ (() => Field2(ed25519_CURVE2.p, { isLE: true }))();
|
|
26229
|
+
var Fn = /* @__PURE__ */ (() => Field2(ed25519_CURVE2.n, { isLE: true }))();
|
|
26230
|
+
var ed25519Defaults = /* @__PURE__ */ (() => ({
|
|
26231
|
+
...ed25519_CURVE2,
|
|
26232
|
+
Fp,
|
|
26233
|
+
hash: sha5123,
|
|
26234
|
+
adjustScalarBytes: adjustScalarBytes2,
|
|
26235
|
+
// dom2
|
|
26236
|
+
// Ratio of u to v. Allows us to combine inversion and square root. Uses algo from RFC8032 5.1.3.
|
|
26237
|
+
// Constant-time, u/√v
|
|
26238
|
+
uvRatio: uvRatio2
|
|
26239
|
+
}))();
|
|
26240
|
+
var ed255192 = /* @__PURE__ */ (() => twistedEdwards(ed25519Defaults))();
|
|
26241
|
+
var SQRT_M1 = ED25519_SQRT_M12;
|
|
26242
|
+
var SQRT_AD_MINUS_ONE = /* @__PURE__ */ BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235");
|
|
26243
|
+
var INVSQRT_A_MINUS_D = /* @__PURE__ */ BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578");
|
|
26244
|
+
var ONE_MINUS_D_SQ = /* @__PURE__ */ BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838");
|
|
26245
|
+
var D_MINUS_ONE_SQ = /* @__PURE__ */ BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");
|
|
26246
|
+
var invertSqrt = (number) => uvRatio2(_1n10, number);
|
|
26247
|
+
var MAX_255B = /* @__PURE__ */ BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
|
26248
|
+
var bytes255ToNumberLE = (bytes) => ed255192.Point.Fp.create(bytesToNumberLE2(bytes) & MAX_255B);
|
|
26249
|
+
function calcElligatorRistrettoMap(r0) {
|
|
26250
|
+
const { d } = ed25519_CURVE2;
|
|
26251
|
+
const P = ed25519_CURVE_p2;
|
|
26252
|
+
const mod3 = (n) => Fp.create(n);
|
|
26253
|
+
const r = mod3(SQRT_M1 * r0 * r0);
|
|
26254
|
+
const Ns = mod3((r + _1n10) * ONE_MINUS_D_SQ);
|
|
26255
|
+
let c = BigInt(-1);
|
|
26256
|
+
const D = mod3((c - d * r) * mod3(r + d));
|
|
26257
|
+
let { isValid: Ns_D_is_sq, value: s } = uvRatio2(Ns, D);
|
|
26258
|
+
let s_ = mod3(s * r0);
|
|
26259
|
+
if (!isNegativeLE2(s_, P))
|
|
26260
|
+
s_ = mod3(-s_);
|
|
26261
|
+
if (!Ns_D_is_sq)
|
|
26262
|
+
s = s_;
|
|
26263
|
+
if (!Ns_D_is_sq)
|
|
26264
|
+
c = r;
|
|
26265
|
+
const Nt = mod3(c * (r - _1n10) * D_MINUS_ONE_SQ - D);
|
|
26266
|
+
const s2 = s * s;
|
|
26267
|
+
const W0 = mod3((s + s) * D);
|
|
26268
|
+
const W1 = mod3(Nt * SQRT_AD_MINUS_ONE);
|
|
26269
|
+
const W2 = mod3(_1n10 - s2);
|
|
26270
|
+
const W3 = mod3(_1n10 + s2);
|
|
26271
|
+
return new ed255192.Point(mod3(W0 * W3), mod3(W2 * W1), mod3(W1 * W3), mod3(W0 * W2));
|
|
26272
|
+
}
|
|
26273
|
+
function ristretto255_map(bytes) {
|
|
26274
|
+
abytes3(bytes, 64);
|
|
26275
|
+
const r1 = bytes255ToNumberLE(bytes.subarray(0, 32));
|
|
26276
|
+
const R1 = calcElligatorRistrettoMap(r1);
|
|
26277
|
+
const r2 = bytes255ToNumberLE(bytes.subarray(32, 64));
|
|
26278
|
+
const R2 = calcElligatorRistrettoMap(r2);
|
|
26279
|
+
return new _RistrettoPoint(R1.add(R2));
|
|
26280
|
+
}
|
|
26281
|
+
var _RistrettoPoint = class __RistrettoPoint extends PrimeEdwardsPoint2 {
|
|
26282
|
+
constructor(ep) {
|
|
26283
|
+
super(ep);
|
|
26284
|
+
}
|
|
26285
|
+
static fromAffine(ap) {
|
|
26286
|
+
return new __RistrettoPoint(ed255192.Point.fromAffine(ap));
|
|
26287
|
+
}
|
|
26288
|
+
assertSame(other) {
|
|
26289
|
+
if (!(other instanceof __RistrettoPoint))
|
|
26290
|
+
throw new Error("RistrettoPoint expected");
|
|
26291
|
+
}
|
|
26292
|
+
init(ep) {
|
|
26293
|
+
return new __RistrettoPoint(ep);
|
|
26294
|
+
}
|
|
26295
|
+
/** @deprecated use `import { ristretto255_hasher } from '@noble/curves/ed25519.js';` */
|
|
26296
|
+
static hashToCurve(hex) {
|
|
26297
|
+
return ristretto255_map(ensureBytes("ristrettoHash", hex, 64));
|
|
26298
|
+
}
|
|
26299
|
+
static fromBytes(bytes) {
|
|
26300
|
+
abytes3(bytes, 32);
|
|
26301
|
+
const { a, d } = ed25519_CURVE2;
|
|
26302
|
+
const P = ed25519_CURVE_p2;
|
|
26303
|
+
const mod3 = (n) => Fp.create(n);
|
|
26304
|
+
const s = bytes255ToNumberLE(bytes);
|
|
26305
|
+
if (!equalBytes(Fp.toBytes(s), bytes) || isNegativeLE2(s, P))
|
|
26306
|
+
throw new Error("invalid ristretto255 encoding 1");
|
|
26307
|
+
const s2 = mod3(s * s);
|
|
26308
|
+
const u1 = mod3(_1n10 + a * s2);
|
|
26309
|
+
const u2 = mod3(_1n10 - a * s2);
|
|
26310
|
+
const u1_2 = mod3(u1 * u1);
|
|
26311
|
+
const u2_2 = mod3(u2 * u2);
|
|
26312
|
+
const v = mod3(a * d * u1_2 - u2_2);
|
|
26313
|
+
const { isValid, value: I } = invertSqrt(mod3(v * u2_2));
|
|
26314
|
+
const Dx = mod3(I * u2);
|
|
26315
|
+
const Dy = mod3(I * Dx * v);
|
|
26316
|
+
let x = mod3((s + s) * Dx);
|
|
26317
|
+
if (isNegativeLE2(x, P))
|
|
26318
|
+
x = mod3(-x);
|
|
26319
|
+
const y = mod3(u1 * Dy);
|
|
26320
|
+
const t = mod3(x * y);
|
|
26321
|
+
if (!isValid || isNegativeLE2(t, P) || y === _0n9)
|
|
26322
|
+
throw new Error("invalid ristretto255 encoding 2");
|
|
26323
|
+
return new __RistrettoPoint(new ed255192.Point(x, y, _1n10, t));
|
|
26324
|
+
}
|
|
26325
|
+
/**
|
|
26326
|
+
* Converts ristretto-encoded string to ristretto point.
|
|
26327
|
+
* Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-decode).
|
|
26328
|
+
* @param hex Ristretto-encoded 32 bytes. Not every 32-byte string is valid ristretto encoding
|
|
26329
|
+
*/
|
|
26330
|
+
static fromHex(hex) {
|
|
26331
|
+
return __RistrettoPoint.fromBytes(ensureBytes("ristrettoHex", hex, 32));
|
|
25313
26332
|
}
|
|
25314
|
-
|
|
25315
|
-
|
|
25316
|
-
if (W === 1)
|
|
25317
|
-
return this._unsafeLadder(point, scalar, prev);
|
|
25318
|
-
return this.wNAFUnsafe(W, this.getPrecomputes(W, point, transform), scalar, prev);
|
|
26333
|
+
static msm(points, scalars) {
|
|
26334
|
+
return pippenger(__RistrettoPoint, ed255192.Point.Fn, points, scalars);
|
|
25319
26335
|
}
|
|
25320
|
-
|
|
25321
|
-
|
|
25322
|
-
|
|
25323
|
-
|
|
25324
|
-
|
|
25325
|
-
|
|
25326
|
-
|
|
26336
|
+
/**
|
|
26337
|
+
* Encodes ristretto point to Uint8Array.
|
|
26338
|
+
* Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-encode).
|
|
26339
|
+
*/
|
|
26340
|
+
toBytes() {
|
|
26341
|
+
let { X, Y, Z, T } = this.ep;
|
|
26342
|
+
const P = ed25519_CURVE_p2;
|
|
26343
|
+
const mod3 = (n) => Fp.create(n);
|
|
26344
|
+
const u1 = mod3(mod3(Z + Y) * mod3(Z - Y));
|
|
26345
|
+
const u2 = mod3(X * Y);
|
|
26346
|
+
const u2sq = mod3(u2 * u2);
|
|
26347
|
+
const { value: invsqrt } = invertSqrt(mod3(u1 * u2sq));
|
|
26348
|
+
const D1 = mod3(invsqrt * u1);
|
|
26349
|
+
const D2 = mod3(invsqrt * u2);
|
|
26350
|
+
const zInv = mod3(D1 * D2 * T);
|
|
26351
|
+
let D;
|
|
26352
|
+
if (isNegativeLE2(T * zInv, P)) {
|
|
26353
|
+
let _x = mod3(Y * SQRT_M1);
|
|
26354
|
+
let _y = mod3(X * SQRT_M1);
|
|
26355
|
+
X = _x;
|
|
26356
|
+
Y = _y;
|
|
26357
|
+
D = mod3(D1 * INVSQRT_A_MINUS_D);
|
|
26358
|
+
} else {
|
|
26359
|
+
D = D2;
|
|
26360
|
+
}
|
|
26361
|
+
if (isNegativeLE2(X * zInv, P))
|
|
26362
|
+
Y = mod3(-Y);
|
|
26363
|
+
let s = mod3((Z - Y) * D);
|
|
26364
|
+
if (isNegativeLE2(s, P))
|
|
26365
|
+
s = mod3(-s);
|
|
26366
|
+
return Fp.toBytes(s);
|
|
25327
26367
|
}
|
|
25328
|
-
|
|
25329
|
-
|
|
26368
|
+
/**
|
|
26369
|
+
* Compares two Ristretto points.
|
|
26370
|
+
* Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-equals).
|
|
26371
|
+
*/
|
|
26372
|
+
equals(other) {
|
|
26373
|
+
this.assertSame(other);
|
|
26374
|
+
const { X: X1, Y: Y1 } = this.ep;
|
|
26375
|
+
const { X: X2, Y: Y2 } = other.ep;
|
|
26376
|
+
const mod3 = (n) => Fp.create(n);
|
|
26377
|
+
const one = mod3(X1 * Y2) === mod3(Y1 * X2);
|
|
26378
|
+
const two = mod3(Y1 * Y2) === mod3(X1 * X2);
|
|
26379
|
+
return one || two;
|
|
26380
|
+
}
|
|
26381
|
+
is0() {
|
|
26382
|
+
return this.equals(__RistrettoPoint.ZERO);
|
|
25330
26383
|
}
|
|
25331
26384
|
};
|
|
25332
|
-
|
|
25333
|
-
|
|
25334
|
-
|
|
25335
|
-
|
|
25336
|
-
|
|
25337
|
-
|
|
25338
|
-
|
|
25339
|
-
|
|
25340
|
-
|
|
25341
|
-
|
|
25342
|
-
|
|
25343
|
-
|
|
26385
|
+
_RistrettoPoint.BASE = /* @__PURE__ */ (() => new _RistrettoPoint(ed255192.Point.BASE))();
|
|
26386
|
+
_RistrettoPoint.ZERO = /* @__PURE__ */ (() => new _RistrettoPoint(ed255192.Point.ZERO))();
|
|
26387
|
+
_RistrettoPoint.Fp = /* @__PURE__ */ (() => Fp)();
|
|
26388
|
+
_RistrettoPoint.Fn = /* @__PURE__ */ (() => Fn)();
|
|
26389
|
+
|
|
26390
|
+
// ../../node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/hmac.js
|
|
26391
|
+
var HMAC = class extends Hash {
|
|
26392
|
+
constructor(hash, _key) {
|
|
26393
|
+
super();
|
|
26394
|
+
this.finished = false;
|
|
26395
|
+
this.destroyed = false;
|
|
26396
|
+
ahash3(hash);
|
|
26397
|
+
const key = toBytes(_key);
|
|
26398
|
+
this.iHash = hash.create();
|
|
26399
|
+
if (typeof this.iHash.update !== "function")
|
|
26400
|
+
throw new Error("Expected instance of class which extends utils.Hash");
|
|
26401
|
+
this.blockLen = this.iHash.blockLen;
|
|
26402
|
+
this.outputLen = this.iHash.outputLen;
|
|
26403
|
+
const blockLen = this.blockLen;
|
|
26404
|
+
const pad = new Uint8Array(blockLen);
|
|
26405
|
+
pad.set(key.length > blockLen ? hash.create().update(key).digest() : key);
|
|
26406
|
+
for (let i = 0; i < pad.length; i++)
|
|
26407
|
+
pad[i] ^= 54;
|
|
26408
|
+
this.iHash.update(pad);
|
|
26409
|
+
this.oHash = hash.create();
|
|
26410
|
+
for (let i = 0; i < pad.length; i++)
|
|
26411
|
+
pad[i] ^= 54 ^ 92;
|
|
26412
|
+
this.oHash.update(pad);
|
|
26413
|
+
clean3(pad);
|
|
25344
26414
|
}
|
|
25345
|
-
|
|
25346
|
-
|
|
25347
|
-
|
|
25348
|
-
|
|
25349
|
-
validateMSMScalars(scalars, fieldN);
|
|
25350
|
-
const plength = points.length;
|
|
25351
|
-
const slength = scalars.length;
|
|
25352
|
-
if (plength !== slength)
|
|
25353
|
-
throw new Error("arrays of points and scalars must have equal length");
|
|
25354
|
-
const zero = c.ZERO;
|
|
25355
|
-
const wbits = bitLen2(BigInt(plength));
|
|
25356
|
-
let windowSize = 1;
|
|
25357
|
-
if (wbits > 12)
|
|
25358
|
-
windowSize = wbits - 3;
|
|
25359
|
-
else if (wbits > 4)
|
|
25360
|
-
windowSize = wbits - 2;
|
|
25361
|
-
else if (wbits > 0)
|
|
25362
|
-
windowSize = 2;
|
|
25363
|
-
const MASK = bitMask2(windowSize);
|
|
25364
|
-
const buckets = new Array(Number(MASK) + 1).fill(zero);
|
|
25365
|
-
const lastBits = Math.floor((fieldN.BITS - 1) / windowSize) * windowSize;
|
|
25366
|
-
let sum = zero;
|
|
25367
|
-
for (let i = lastBits; i >= 0; i -= windowSize) {
|
|
25368
|
-
buckets.fill(zero);
|
|
25369
|
-
for (let j = 0; j < slength; j++) {
|
|
25370
|
-
const scalar = scalars[j];
|
|
25371
|
-
const wbits2 = Number(scalar >> BigInt(i) & MASK);
|
|
25372
|
-
buckets[wbits2] = buckets[wbits2].add(points[j]);
|
|
25373
|
-
}
|
|
25374
|
-
let resI = zero;
|
|
25375
|
-
for (let j = buckets.length - 1, sumI = zero; j > 0; j--) {
|
|
25376
|
-
sumI = sumI.add(buckets[j]);
|
|
25377
|
-
resI = resI.add(sumI);
|
|
25378
|
-
}
|
|
25379
|
-
sum = sum.add(resI);
|
|
25380
|
-
if (i !== 0)
|
|
25381
|
-
for (let j = 0; j < windowSize; j++)
|
|
25382
|
-
sum = sum.double();
|
|
26415
|
+
update(buf) {
|
|
26416
|
+
aexists3(this);
|
|
26417
|
+
this.iHash.update(buf);
|
|
26418
|
+
return this;
|
|
25383
26419
|
}
|
|
25384
|
-
|
|
25385
|
-
|
|
25386
|
-
|
|
25387
|
-
|
|
25388
|
-
|
|
25389
|
-
|
|
25390
|
-
|
|
25391
|
-
|
|
25392
|
-
} else {
|
|
25393
|
-
return Field2(order, { isLE });
|
|
26420
|
+
digestInto(out) {
|
|
26421
|
+
aexists3(this);
|
|
26422
|
+
abytes3(out, this.outputLen);
|
|
26423
|
+
this.finished = true;
|
|
26424
|
+
this.iHash.digestInto(out);
|
|
26425
|
+
this.oHash.update(out);
|
|
26426
|
+
this.oHash.digestInto(out);
|
|
26427
|
+
this.destroy();
|
|
25394
26428
|
}
|
|
25395
|
-
|
|
25396
|
-
|
|
25397
|
-
|
|
25398
|
-
|
|
25399
|
-
if (!CURVE || typeof CURVE !== "object")
|
|
25400
|
-
throw new Error(`expected valid ${type} CURVE object`);
|
|
25401
|
-
for (const p of ["p", "n", "h"]) {
|
|
25402
|
-
const val = CURVE[p];
|
|
25403
|
-
if (!(typeof val === "bigint" && val > _0n7))
|
|
25404
|
-
throw new Error(`CURVE.${p} must be positive bigint`);
|
|
26429
|
+
digest() {
|
|
26430
|
+
const out = new Uint8Array(this.oHash.outputLen);
|
|
26431
|
+
this.digestInto(out);
|
|
26432
|
+
return out;
|
|
25405
26433
|
}
|
|
25406
|
-
|
|
25407
|
-
|
|
25408
|
-
|
|
25409
|
-
|
|
25410
|
-
|
|
25411
|
-
|
|
25412
|
-
|
|
26434
|
+
_cloneInto(to) {
|
|
26435
|
+
to || (to = Object.create(Object.getPrototypeOf(this), {}));
|
|
26436
|
+
const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
|
|
26437
|
+
to = to;
|
|
26438
|
+
to.finished = finished;
|
|
26439
|
+
to.destroyed = destroyed;
|
|
26440
|
+
to.blockLen = blockLen;
|
|
26441
|
+
to.outputLen = outputLen;
|
|
26442
|
+
to.oHash = oHash._cloneInto(to.oHash);
|
|
26443
|
+
to.iHash = iHash._cloneInto(to.iHash);
|
|
26444
|
+
return to;
|
|
25413
26445
|
}
|
|
25414
|
-
|
|
25415
|
-
|
|
25416
|
-
}
|
|
26446
|
+
clone() {
|
|
26447
|
+
return this._cloneInto();
|
|
26448
|
+
}
|
|
26449
|
+
destroy() {
|
|
26450
|
+
this.destroyed = true;
|
|
26451
|
+
this.oHash.destroy();
|
|
26452
|
+
this.iHash.destroy();
|
|
26453
|
+
}
|
|
26454
|
+
};
|
|
26455
|
+
var hmac3 = (hash, key, message) => new HMAC(hash, key).update(message).digest();
|
|
26456
|
+
hmac3.create = (hash, key) => new HMAC(hash, key);
|
|
25417
26457
|
|
|
25418
26458
|
// ../../node_modules/.pnpm/@noble+curves@1.9.7/node_modules/@noble/curves/esm/abstract/weierstrass.js
|
|
25419
|
-
var divNearest = (num, den) => (num + (num >= 0 ? den : -den) /
|
|
26459
|
+
var divNearest = (num, den) => (num + (num >= 0 ? den : -den) / _2n7) / den;
|
|
25420
26460
|
function _splitEndoScalar(k, basis, n) {
|
|
25421
26461
|
const [[a1, b1], [a2, b2]] = basis;
|
|
25422
26462
|
const c1 = divNearest(b2 * k, n);
|
|
25423
26463
|
const c2 = divNearest(-b1 * k, n);
|
|
25424
26464
|
let k1 = k - c1 * a1 - c2 * a2;
|
|
25425
26465
|
let k2 = -c1 * b1 - c2 * b2;
|
|
25426
|
-
const k1neg = k1 <
|
|
25427
|
-
const k2neg = k2 <
|
|
26466
|
+
const k1neg = k1 < _0n10;
|
|
26467
|
+
const k2neg = k2 < _0n10;
|
|
25428
26468
|
if (k1neg)
|
|
25429
26469
|
k1 = -k1;
|
|
25430
26470
|
if (k2neg)
|
|
25431
26471
|
k2 = -k2;
|
|
25432
|
-
const MAX_NUM = bitMask2(Math.ceil(bitLen2(n) / 2)) +
|
|
25433
|
-
if (k1 <
|
|
26472
|
+
const MAX_NUM = bitMask2(Math.ceil(bitLen2(n) / 2)) + _1n11;
|
|
26473
|
+
if (k1 < _0n10 || k1 >= MAX_NUM || k2 < _0n10 || k2 >= MAX_NUM) {
|
|
25434
26474
|
throw new Error("splitScalar (endomorphism): failed, k=" + k);
|
|
25435
26475
|
}
|
|
25436
26476
|
return { k1neg, k1, k2neg, k2 };
|
|
@@ -25518,7 +26558,7 @@ var DER = {
|
|
|
25518
26558
|
_int: {
|
|
25519
26559
|
encode(num) {
|
|
25520
26560
|
const { Err: E } = DER;
|
|
25521
|
-
if (num <
|
|
26561
|
+
if (num < _0n10)
|
|
25522
26562
|
throw new E("integer: negative integers are not allowed");
|
|
25523
26563
|
let hex = numberToHexUnpadded(num);
|
|
25524
26564
|
if (Number.parseInt(hex[0], 16) & 8)
|
|
@@ -25556,31 +26596,31 @@ var DER = {
|
|
|
25556
26596
|
return tlv.encode(48, seq);
|
|
25557
26597
|
}
|
|
25558
26598
|
};
|
|
25559
|
-
var
|
|
25560
|
-
var
|
|
25561
|
-
var
|
|
25562
|
-
var
|
|
26599
|
+
var _0n10 = BigInt(0);
|
|
26600
|
+
var _1n11 = BigInt(1);
|
|
26601
|
+
var _2n7 = BigInt(2);
|
|
26602
|
+
var _3n4 = BigInt(3);
|
|
25563
26603
|
var _4n3 = BigInt(4);
|
|
25564
|
-
function _normFnElement(
|
|
25565
|
-
const { BYTES: expected } =
|
|
26604
|
+
function _normFnElement(Fn2, key) {
|
|
26605
|
+
const { BYTES: expected } = Fn2;
|
|
25566
26606
|
let num;
|
|
25567
26607
|
if (typeof key === "bigint") {
|
|
25568
26608
|
num = key;
|
|
25569
26609
|
} else {
|
|
25570
26610
|
let bytes = ensureBytes("private key", key);
|
|
25571
26611
|
try {
|
|
25572
|
-
num =
|
|
26612
|
+
num = Fn2.fromBytes(bytes);
|
|
25573
26613
|
} catch (error) {
|
|
25574
26614
|
throw new Error(`invalid private key: expected ui8a of size ${expected}, got ${typeof key}`);
|
|
25575
26615
|
}
|
|
25576
26616
|
}
|
|
25577
|
-
if (!
|
|
26617
|
+
if (!Fn2.isValidNot0(num))
|
|
25578
26618
|
throw new Error("invalid private key: out of range [1..N-1]");
|
|
25579
26619
|
return num;
|
|
25580
26620
|
}
|
|
25581
26621
|
function weierstrassN(params, extraOpts = {}) {
|
|
25582
26622
|
const validated = _createCurveFields("weierstrass", params, extraOpts);
|
|
25583
|
-
const { Fp, Fn } = validated;
|
|
26623
|
+
const { Fp: Fp2, Fn: Fn2 } = validated;
|
|
25584
26624
|
let CURVE = validated.CURVE;
|
|
25585
26625
|
const { h: cofactor, n: CURVE_ORDER } = CURVE;
|
|
25586
26626
|
_validateObject(extraOpts, {}, {
|
|
@@ -25594,25 +26634,25 @@ function weierstrassN(params, extraOpts = {}) {
|
|
|
25594
26634
|
});
|
|
25595
26635
|
const { endo } = extraOpts;
|
|
25596
26636
|
if (endo) {
|
|
25597
|
-
if (!
|
|
26637
|
+
if (!Fp2.is0(CURVE.a) || typeof endo.beta !== "bigint" || !Array.isArray(endo.basises)) {
|
|
25598
26638
|
throw new Error('invalid endo: expected "beta": bigint and "basises": array');
|
|
25599
26639
|
}
|
|
25600
26640
|
}
|
|
25601
|
-
const lengths = getWLengths(
|
|
26641
|
+
const lengths = getWLengths(Fp2, Fn2);
|
|
25602
26642
|
function assertCompressionIsSupported() {
|
|
25603
|
-
if (!
|
|
26643
|
+
if (!Fp2.isOdd)
|
|
25604
26644
|
throw new Error("compression is not supported: Field does not have .isOdd()");
|
|
25605
26645
|
}
|
|
25606
26646
|
function pointToBytes(_c, point, isCompressed) {
|
|
25607
26647
|
const { x, y } = point.toAffine();
|
|
25608
|
-
const bx =
|
|
26648
|
+
const bx = Fp2.toBytes(x);
|
|
25609
26649
|
_abool2(isCompressed, "isCompressed");
|
|
25610
26650
|
if (isCompressed) {
|
|
25611
26651
|
assertCompressionIsSupported();
|
|
25612
|
-
const hasEvenY = !
|
|
26652
|
+
const hasEvenY = !Fp2.isOdd(y);
|
|
25613
26653
|
return concatBytes2(pprefix(hasEvenY), bx);
|
|
25614
26654
|
} else {
|
|
25615
|
-
return concatBytes2(Uint8Array.of(4), bx,
|
|
26655
|
+
return concatBytes2(Uint8Array.of(4), bx, Fp2.toBytes(y));
|
|
25616
26656
|
}
|
|
25617
26657
|
}
|
|
25618
26658
|
function pointFromBytes(bytes) {
|
|
@@ -25622,27 +26662,27 @@ function weierstrassN(params, extraOpts = {}) {
|
|
|
25622
26662
|
const head = bytes[0];
|
|
25623
26663
|
const tail = bytes.subarray(1);
|
|
25624
26664
|
if (length === comp && (head === 2 || head === 3)) {
|
|
25625
|
-
const x =
|
|
25626
|
-
if (!
|
|
26665
|
+
const x = Fp2.fromBytes(tail);
|
|
26666
|
+
if (!Fp2.isValid(x))
|
|
25627
26667
|
throw new Error("bad point: is not on curve, wrong x");
|
|
25628
26668
|
const y2 = weierstrassEquation(x);
|
|
25629
26669
|
let y;
|
|
25630
26670
|
try {
|
|
25631
|
-
y =
|
|
26671
|
+
y = Fp2.sqrt(y2);
|
|
25632
26672
|
} catch (sqrtError) {
|
|
25633
26673
|
const err = sqrtError instanceof Error ? ": " + sqrtError.message : "";
|
|
25634
26674
|
throw new Error("bad point: is not on curve, sqrt error" + err);
|
|
25635
26675
|
}
|
|
25636
26676
|
assertCompressionIsSupported();
|
|
25637
|
-
const isYOdd =
|
|
26677
|
+
const isYOdd = Fp2.isOdd(y);
|
|
25638
26678
|
const isHeadOdd = (head & 1) === 1;
|
|
25639
26679
|
if (isHeadOdd !== isYOdd)
|
|
25640
|
-
y =
|
|
26680
|
+
y = Fp2.neg(y);
|
|
25641
26681
|
return { x, y };
|
|
25642
26682
|
} else if (length === uncomp && head === 4) {
|
|
25643
|
-
const L =
|
|
25644
|
-
const x =
|
|
25645
|
-
const y =
|
|
26683
|
+
const L = Fp2.BYTES;
|
|
26684
|
+
const x = Fp2.fromBytes(tail.subarray(0, L));
|
|
26685
|
+
const y = Fp2.fromBytes(tail.subarray(L, L * 2));
|
|
25646
26686
|
if (!isValidXY(x, y))
|
|
25647
26687
|
throw new Error("bad point: is not on curve");
|
|
25648
26688
|
return { x, y };
|
|
@@ -25653,23 +26693,23 @@ function weierstrassN(params, extraOpts = {}) {
|
|
|
25653
26693
|
const encodePoint = extraOpts.toBytes || pointToBytes;
|
|
25654
26694
|
const decodePoint = extraOpts.fromBytes || pointFromBytes;
|
|
25655
26695
|
function weierstrassEquation(x) {
|
|
25656
|
-
const x2 =
|
|
25657
|
-
const x3 =
|
|
25658
|
-
return
|
|
26696
|
+
const x2 = Fp2.sqr(x);
|
|
26697
|
+
const x3 = Fp2.mul(x2, x);
|
|
26698
|
+
return Fp2.add(Fp2.add(x3, Fp2.mul(x, CURVE.a)), CURVE.b);
|
|
25659
26699
|
}
|
|
25660
26700
|
function isValidXY(x, y) {
|
|
25661
|
-
const left =
|
|
26701
|
+
const left = Fp2.sqr(y);
|
|
25662
26702
|
const right = weierstrassEquation(x);
|
|
25663
|
-
return
|
|
26703
|
+
return Fp2.eql(left, right);
|
|
25664
26704
|
}
|
|
25665
26705
|
if (!isValidXY(CURVE.Gx, CURVE.Gy))
|
|
25666
26706
|
throw new Error("bad curve params: generator point");
|
|
25667
|
-
const _4a3 =
|
|
25668
|
-
const _27b2 =
|
|
25669
|
-
if (
|
|
26707
|
+
const _4a3 = Fp2.mul(Fp2.pow(CURVE.a, _3n4), _4n3);
|
|
26708
|
+
const _27b2 = Fp2.mul(Fp2.sqr(CURVE.b), BigInt(27));
|
|
26709
|
+
if (Fp2.is0(Fp2.add(_4a3, _27b2)))
|
|
25670
26710
|
throw new Error("bad curve params: a or b");
|
|
25671
26711
|
function acoord(title, n, banZero = false) {
|
|
25672
|
-
if (!
|
|
26712
|
+
if (!Fp2.isValid(n) || banZero && Fp2.is0(n))
|
|
25673
26713
|
throw new Error(`bad point coordinate ${title}`);
|
|
25674
26714
|
return n;
|
|
25675
26715
|
}
|
|
@@ -25680,32 +26720,32 @@ function weierstrassN(params, extraOpts = {}) {
|
|
|
25680
26720
|
function splitEndoScalarN(k) {
|
|
25681
26721
|
if (!endo || !endo.basises)
|
|
25682
26722
|
throw new Error("no endo");
|
|
25683
|
-
return _splitEndoScalar(k, endo.basises,
|
|
26723
|
+
return _splitEndoScalar(k, endo.basises, Fn2.ORDER);
|
|
25684
26724
|
}
|
|
25685
26725
|
const toAffineMemo = memoized2((p, iz) => {
|
|
25686
26726
|
const { X, Y, Z } = p;
|
|
25687
|
-
if (
|
|
26727
|
+
if (Fp2.eql(Z, Fp2.ONE))
|
|
25688
26728
|
return { x: X, y: Y };
|
|
25689
26729
|
const is0 = p.is0();
|
|
25690
26730
|
if (iz == null)
|
|
25691
|
-
iz = is0 ?
|
|
25692
|
-
const x =
|
|
25693
|
-
const y =
|
|
25694
|
-
const zz =
|
|
26731
|
+
iz = is0 ? Fp2.ONE : Fp2.inv(Z);
|
|
26732
|
+
const x = Fp2.mul(X, iz);
|
|
26733
|
+
const y = Fp2.mul(Y, iz);
|
|
26734
|
+
const zz = Fp2.mul(Z, iz);
|
|
25695
26735
|
if (is0)
|
|
25696
|
-
return { x:
|
|
25697
|
-
if (!
|
|
26736
|
+
return { x: Fp2.ZERO, y: Fp2.ZERO };
|
|
26737
|
+
if (!Fp2.eql(zz, Fp2.ONE))
|
|
25698
26738
|
throw new Error("invZ was invalid");
|
|
25699
26739
|
return { x, y };
|
|
25700
26740
|
});
|
|
25701
26741
|
const assertValidMemo = memoized2((p) => {
|
|
25702
26742
|
if (p.is0()) {
|
|
25703
|
-
if (extraOpts.allowInfinityPoint && !
|
|
26743
|
+
if (extraOpts.allowInfinityPoint && !Fp2.is0(p.Y))
|
|
25704
26744
|
return;
|
|
25705
26745
|
throw new Error("bad point: ZERO");
|
|
25706
26746
|
}
|
|
25707
26747
|
const { x, y } = p.toAffine();
|
|
25708
|
-
if (!
|
|
26748
|
+
if (!Fp2.isValid(x) || !Fp2.isValid(y))
|
|
25709
26749
|
throw new Error("bad point: x or y not field elements");
|
|
25710
26750
|
if (!isValidXY(x, y))
|
|
25711
26751
|
throw new Error("bad point: equation left != right");
|
|
@@ -25714,7 +26754,7 @@ function weierstrassN(params, extraOpts = {}) {
|
|
|
25714
26754
|
return true;
|
|
25715
26755
|
});
|
|
25716
26756
|
function finishEndo(endoBeta, k1p, k2p, k1neg, k2neg) {
|
|
25717
|
-
k2p = new Point(
|
|
26757
|
+
k2p = new Point(Fp2.mul(k2p.X, endoBeta), k2p.Y, k2p.Z);
|
|
25718
26758
|
k1p = negateCt2(k1neg, k1p);
|
|
25719
26759
|
k2p = negateCt2(k2neg, k2p);
|
|
25720
26760
|
return k1p.add(k2p);
|
|
@@ -25733,13 +26773,13 @@ function weierstrassN(params, extraOpts = {}) {
|
|
|
25733
26773
|
/** Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
25734
26774
|
static fromAffine(p) {
|
|
25735
26775
|
const { x, y } = p || {};
|
|
25736
|
-
if (!p || !
|
|
26776
|
+
if (!p || !Fp2.isValid(x) || !Fp2.isValid(y))
|
|
25737
26777
|
throw new Error("invalid affine point");
|
|
25738
26778
|
if (p instanceof Point)
|
|
25739
26779
|
throw new Error("projective point not allowed");
|
|
25740
|
-
if (
|
|
26780
|
+
if (Fp2.is0(x) && Fp2.is0(y))
|
|
25741
26781
|
return Point.ZERO;
|
|
25742
|
-
return new Point(x, y,
|
|
26782
|
+
return new Point(x, y, Fp2.ONE);
|
|
25743
26783
|
}
|
|
25744
26784
|
static fromBytes(bytes) {
|
|
25745
26785
|
const P = Point.fromAffine(decodePoint(_abytes2(bytes, void 0, "point")));
|
|
@@ -25764,7 +26804,7 @@ function weierstrassN(params, extraOpts = {}) {
|
|
|
25764
26804
|
precompute(windowSize = 8, isLazy = true) {
|
|
25765
26805
|
wnaf.createCache(this, windowSize);
|
|
25766
26806
|
if (!isLazy)
|
|
25767
|
-
this.multiply(
|
|
26807
|
+
this.multiply(_3n4);
|
|
25768
26808
|
return this;
|
|
25769
26809
|
}
|
|
25770
26810
|
// TODO: return `this`
|
|
@@ -25774,22 +26814,22 @@ function weierstrassN(params, extraOpts = {}) {
|
|
|
25774
26814
|
}
|
|
25775
26815
|
hasEvenY() {
|
|
25776
26816
|
const { y } = this.toAffine();
|
|
25777
|
-
if (!
|
|
26817
|
+
if (!Fp2.isOdd)
|
|
25778
26818
|
throw new Error("Field doesn't support isOdd");
|
|
25779
|
-
return !
|
|
26819
|
+
return !Fp2.isOdd(y);
|
|
25780
26820
|
}
|
|
25781
26821
|
/** Compare one point to another. */
|
|
25782
26822
|
equals(other) {
|
|
25783
26823
|
aprjpoint(other);
|
|
25784
26824
|
const { X: X1, Y: Y1, Z: Z1 } = this;
|
|
25785
26825
|
const { X: X2, Y: Y2, Z: Z2 } = other;
|
|
25786
|
-
const U1 =
|
|
25787
|
-
const U2 =
|
|
26826
|
+
const U1 = Fp2.eql(Fp2.mul(X1, Z2), Fp2.mul(X2, Z1));
|
|
26827
|
+
const U2 = Fp2.eql(Fp2.mul(Y1, Z2), Fp2.mul(Y2, Z1));
|
|
25788
26828
|
return U1 && U2;
|
|
25789
26829
|
}
|
|
25790
26830
|
/** Flips point to one corresponding to (x, -y) in Affine coordinates. */
|
|
25791
26831
|
negate() {
|
|
25792
|
-
return new Point(this.X,
|
|
26832
|
+
return new Point(this.X, Fp2.neg(this.Y), this.Z);
|
|
25793
26833
|
}
|
|
25794
26834
|
// Renes-Costello-Batina exception-free doubling formula.
|
|
25795
26835
|
// There is 30% faster Jacobian formula, but it is not complete.
|
|
@@ -25797,40 +26837,40 @@ function weierstrassN(params, extraOpts = {}) {
|
|
|
25797
26837
|
// Cost: 8M + 3S + 3*a + 2*b3 + 15add.
|
|
25798
26838
|
double() {
|
|
25799
26839
|
const { a, b } = CURVE;
|
|
25800
|
-
const b3 =
|
|
26840
|
+
const b3 = Fp2.mul(b, _3n4);
|
|
25801
26841
|
const { X: X1, Y: Y1, Z: Z1 } = this;
|
|
25802
|
-
let X3 =
|
|
25803
|
-
let t0 =
|
|
25804
|
-
let t1 =
|
|
25805
|
-
let t2 =
|
|
25806
|
-
let t3 =
|
|
25807
|
-
t3 =
|
|
25808
|
-
Z3 =
|
|
25809
|
-
Z3 =
|
|
25810
|
-
X3 =
|
|
25811
|
-
Y3 =
|
|
25812
|
-
Y3 =
|
|
25813
|
-
X3 =
|
|
25814
|
-
Y3 =
|
|
25815
|
-
Y3 =
|
|
25816
|
-
X3 =
|
|
25817
|
-
Z3 =
|
|
25818
|
-
t2 =
|
|
25819
|
-
t3 =
|
|
25820
|
-
t3 =
|
|
25821
|
-
t3 =
|
|
25822
|
-
Z3 =
|
|
25823
|
-
t0 =
|
|
25824
|
-
t0 =
|
|
25825
|
-
t0 =
|
|
25826
|
-
Y3 =
|
|
25827
|
-
t2 =
|
|
25828
|
-
t2 =
|
|
25829
|
-
t0 =
|
|
25830
|
-
X3 =
|
|
25831
|
-
Z3 =
|
|
25832
|
-
Z3 =
|
|
25833
|
-
Z3 =
|
|
26842
|
+
let X3 = Fp2.ZERO, Y3 = Fp2.ZERO, Z3 = Fp2.ZERO;
|
|
26843
|
+
let t0 = Fp2.mul(X1, X1);
|
|
26844
|
+
let t1 = Fp2.mul(Y1, Y1);
|
|
26845
|
+
let t2 = Fp2.mul(Z1, Z1);
|
|
26846
|
+
let t3 = Fp2.mul(X1, Y1);
|
|
26847
|
+
t3 = Fp2.add(t3, t3);
|
|
26848
|
+
Z3 = Fp2.mul(X1, Z1);
|
|
26849
|
+
Z3 = Fp2.add(Z3, Z3);
|
|
26850
|
+
X3 = Fp2.mul(a, Z3);
|
|
26851
|
+
Y3 = Fp2.mul(b3, t2);
|
|
26852
|
+
Y3 = Fp2.add(X3, Y3);
|
|
26853
|
+
X3 = Fp2.sub(t1, Y3);
|
|
26854
|
+
Y3 = Fp2.add(t1, Y3);
|
|
26855
|
+
Y3 = Fp2.mul(X3, Y3);
|
|
26856
|
+
X3 = Fp2.mul(t3, X3);
|
|
26857
|
+
Z3 = Fp2.mul(b3, Z3);
|
|
26858
|
+
t2 = Fp2.mul(a, t2);
|
|
26859
|
+
t3 = Fp2.sub(t0, t2);
|
|
26860
|
+
t3 = Fp2.mul(a, t3);
|
|
26861
|
+
t3 = Fp2.add(t3, Z3);
|
|
26862
|
+
Z3 = Fp2.add(t0, t0);
|
|
26863
|
+
t0 = Fp2.add(Z3, t0);
|
|
26864
|
+
t0 = Fp2.add(t0, t2);
|
|
26865
|
+
t0 = Fp2.mul(t0, t3);
|
|
26866
|
+
Y3 = Fp2.add(Y3, t0);
|
|
26867
|
+
t2 = Fp2.mul(Y1, Z1);
|
|
26868
|
+
t2 = Fp2.add(t2, t2);
|
|
26869
|
+
t0 = Fp2.mul(t2, t3);
|
|
26870
|
+
X3 = Fp2.sub(X3, t0);
|
|
26871
|
+
Z3 = Fp2.mul(t2, t1);
|
|
26872
|
+
Z3 = Fp2.add(Z3, Z3);
|
|
26873
|
+
Z3 = Fp2.add(Z3, Z3);
|
|
25834
26874
|
return new Point(X3, Y3, Z3);
|
|
25835
26875
|
}
|
|
25836
26876
|
// Renes-Costello-Batina exception-free addition formula.
|
|
@@ -25841,49 +26881,49 @@ function weierstrassN(params, extraOpts = {}) {
|
|
|
25841
26881
|
aprjpoint(other);
|
|
25842
26882
|
const { X: X1, Y: Y1, Z: Z1 } = this;
|
|
25843
26883
|
const { X: X2, Y: Y2, Z: Z2 } = other;
|
|
25844
|
-
let X3 =
|
|
26884
|
+
let X3 = Fp2.ZERO, Y3 = Fp2.ZERO, Z3 = Fp2.ZERO;
|
|
25845
26885
|
const a = CURVE.a;
|
|
25846
|
-
const b3 =
|
|
25847
|
-
let t0 =
|
|
25848
|
-
let t1 =
|
|
25849
|
-
let t2 =
|
|
25850
|
-
let t3 =
|
|
25851
|
-
let t4 =
|
|
25852
|
-
t3 =
|
|
25853
|
-
t4 =
|
|
25854
|
-
t3 =
|
|
25855
|
-
t4 =
|
|
25856
|
-
let t5 =
|
|
25857
|
-
t4 =
|
|
25858
|
-
t5 =
|
|
25859
|
-
t4 =
|
|
25860
|
-
t5 =
|
|
25861
|
-
X3 =
|
|
25862
|
-
t5 =
|
|
25863
|
-
X3 =
|
|
25864
|
-
t5 =
|
|
25865
|
-
Z3 =
|
|
25866
|
-
X3 =
|
|
25867
|
-
Z3 =
|
|
25868
|
-
X3 =
|
|
25869
|
-
Z3 =
|
|
25870
|
-
Y3 =
|
|
25871
|
-
t1 =
|
|
25872
|
-
t1 =
|
|
25873
|
-
t2 =
|
|
25874
|
-
t4 =
|
|
25875
|
-
t1 =
|
|
25876
|
-
t2 =
|
|
25877
|
-
t2 =
|
|
25878
|
-
t4 =
|
|
25879
|
-
t0 =
|
|
25880
|
-
Y3 =
|
|
25881
|
-
t0 =
|
|
25882
|
-
X3 =
|
|
25883
|
-
X3 =
|
|
25884
|
-
t0 =
|
|
25885
|
-
Z3 =
|
|
25886
|
-
Z3 =
|
|
26886
|
+
const b3 = Fp2.mul(CURVE.b, _3n4);
|
|
26887
|
+
let t0 = Fp2.mul(X1, X2);
|
|
26888
|
+
let t1 = Fp2.mul(Y1, Y2);
|
|
26889
|
+
let t2 = Fp2.mul(Z1, Z2);
|
|
26890
|
+
let t3 = Fp2.add(X1, Y1);
|
|
26891
|
+
let t4 = Fp2.add(X2, Y2);
|
|
26892
|
+
t3 = Fp2.mul(t3, t4);
|
|
26893
|
+
t4 = Fp2.add(t0, t1);
|
|
26894
|
+
t3 = Fp2.sub(t3, t4);
|
|
26895
|
+
t4 = Fp2.add(X1, Z1);
|
|
26896
|
+
let t5 = Fp2.add(X2, Z2);
|
|
26897
|
+
t4 = Fp2.mul(t4, t5);
|
|
26898
|
+
t5 = Fp2.add(t0, t2);
|
|
26899
|
+
t4 = Fp2.sub(t4, t5);
|
|
26900
|
+
t5 = Fp2.add(Y1, Z1);
|
|
26901
|
+
X3 = Fp2.add(Y2, Z2);
|
|
26902
|
+
t5 = Fp2.mul(t5, X3);
|
|
26903
|
+
X3 = Fp2.add(t1, t2);
|
|
26904
|
+
t5 = Fp2.sub(t5, X3);
|
|
26905
|
+
Z3 = Fp2.mul(a, t4);
|
|
26906
|
+
X3 = Fp2.mul(b3, t2);
|
|
26907
|
+
Z3 = Fp2.add(X3, Z3);
|
|
26908
|
+
X3 = Fp2.sub(t1, Z3);
|
|
26909
|
+
Z3 = Fp2.add(t1, Z3);
|
|
26910
|
+
Y3 = Fp2.mul(X3, Z3);
|
|
26911
|
+
t1 = Fp2.add(t0, t0);
|
|
26912
|
+
t1 = Fp2.add(t1, t0);
|
|
26913
|
+
t2 = Fp2.mul(a, t2);
|
|
26914
|
+
t4 = Fp2.mul(b3, t4);
|
|
26915
|
+
t1 = Fp2.add(t1, t2);
|
|
26916
|
+
t2 = Fp2.sub(t0, t2);
|
|
26917
|
+
t2 = Fp2.mul(a, t2);
|
|
26918
|
+
t4 = Fp2.add(t4, t2);
|
|
26919
|
+
t0 = Fp2.mul(t1, t4);
|
|
26920
|
+
Y3 = Fp2.add(Y3, t0);
|
|
26921
|
+
t0 = Fp2.mul(t5, t4);
|
|
26922
|
+
X3 = Fp2.mul(t3, X3);
|
|
26923
|
+
X3 = Fp2.sub(X3, t0);
|
|
26924
|
+
t0 = Fp2.mul(t3, t1);
|
|
26925
|
+
Z3 = Fp2.mul(t5, Z3);
|
|
26926
|
+
Z3 = Fp2.add(Z3, t0);
|
|
25887
26927
|
return new Point(X3, Y3, Z3);
|
|
25888
26928
|
}
|
|
25889
26929
|
subtract(other) {
|
|
@@ -25903,7 +26943,7 @@ function weierstrassN(params, extraOpts = {}) {
|
|
|
25903
26943
|
*/
|
|
25904
26944
|
multiply(scalar) {
|
|
25905
26945
|
const { endo: endo2 } = extraOpts;
|
|
25906
|
-
if (!
|
|
26946
|
+
if (!Fn2.isValidNot0(scalar))
|
|
25907
26947
|
throw new Error("invalid scalar: out of range");
|
|
25908
26948
|
let point, fake;
|
|
25909
26949
|
const mul = (n) => wnaf.cached(this, n, (p) => normalizeZ2(Point, p));
|
|
@@ -25928,11 +26968,11 @@ function weierstrassN(params, extraOpts = {}) {
|
|
|
25928
26968
|
multiplyUnsafe(sc) {
|
|
25929
26969
|
const { endo: endo2 } = extraOpts;
|
|
25930
26970
|
const p = this;
|
|
25931
|
-
if (!
|
|
26971
|
+
if (!Fn2.isValid(sc))
|
|
25932
26972
|
throw new Error("invalid scalar: out of range");
|
|
25933
|
-
if (sc ===
|
|
26973
|
+
if (sc === _0n10 || p.is0())
|
|
25934
26974
|
return Point.ZERO;
|
|
25935
|
-
if (sc ===
|
|
26975
|
+
if (sc === _1n11)
|
|
25936
26976
|
return p;
|
|
25937
26977
|
if (wnaf.hasCache(this))
|
|
25938
26978
|
return this.multiply(sc);
|
|
@@ -25961,7 +27001,7 @@ function weierstrassN(params, extraOpts = {}) {
|
|
|
25961
27001
|
*/
|
|
25962
27002
|
isTorsionFree() {
|
|
25963
27003
|
const { isTorsionFree } = extraOpts;
|
|
25964
|
-
if (cofactor ===
|
|
27004
|
+
if (cofactor === _1n11)
|
|
25965
27005
|
return true;
|
|
25966
27006
|
if (isTorsionFree)
|
|
25967
27007
|
return isTorsionFree(Point, this);
|
|
@@ -25969,7 +27009,7 @@ function weierstrassN(params, extraOpts = {}) {
|
|
|
25969
27009
|
}
|
|
25970
27010
|
clearCofactor() {
|
|
25971
27011
|
const { clearCofactor } = extraOpts;
|
|
25972
|
-
if (cofactor ===
|
|
27012
|
+
if (cofactor === _1n11)
|
|
25973
27013
|
return this;
|
|
25974
27014
|
if (clearCofactor)
|
|
25975
27015
|
return clearCofactor(Point, this);
|
|
@@ -26009,17 +27049,17 @@ function weierstrassN(params, extraOpts = {}) {
|
|
|
26009
27049
|
return normalizeZ2(Point, points);
|
|
26010
27050
|
}
|
|
26011
27051
|
static msm(points, scalars) {
|
|
26012
|
-
return pippenger(Point,
|
|
27052
|
+
return pippenger(Point, Fn2, points, scalars);
|
|
26013
27053
|
}
|
|
26014
27054
|
static fromPrivateKey(privateKey) {
|
|
26015
|
-
return Point.BASE.multiply(_normFnElement(
|
|
27055
|
+
return Point.BASE.multiply(_normFnElement(Fn2, privateKey));
|
|
26016
27056
|
}
|
|
26017
27057
|
}
|
|
26018
|
-
Point.BASE = new Point(CURVE.Gx, CURVE.Gy,
|
|
26019
|
-
Point.ZERO = new Point(
|
|
26020
|
-
Point.Fp =
|
|
26021
|
-
Point.Fn =
|
|
26022
|
-
const bits =
|
|
27058
|
+
Point.BASE = new Point(CURVE.Gx, CURVE.Gy, Fp2.ONE);
|
|
27059
|
+
Point.ZERO = new Point(Fp2.ZERO, Fp2.ONE, Fp2.ZERO);
|
|
27060
|
+
Point.Fp = Fp2;
|
|
27061
|
+
Point.Fn = Fn2;
|
|
27062
|
+
const bits = Fn2.BITS;
|
|
26023
27063
|
const wnaf = new wNAF2(Point, extraOpts.endo ? Math.ceil(bits / 2) : bits);
|
|
26024
27064
|
Point.BASE.precompute(8);
|
|
26025
27065
|
return Point;
|
|
@@ -26027,22 +27067,22 @@ function weierstrassN(params, extraOpts = {}) {
|
|
|
26027
27067
|
function pprefix(hasEvenY) {
|
|
26028
27068
|
return Uint8Array.of(hasEvenY ? 2 : 3);
|
|
26029
27069
|
}
|
|
26030
|
-
function getWLengths(
|
|
27070
|
+
function getWLengths(Fp2, Fn2) {
|
|
26031
27071
|
return {
|
|
26032
|
-
secretKey:
|
|
26033
|
-
publicKey: 1 +
|
|
26034
|
-
publicKeyUncompressed: 1 + 2 *
|
|
27072
|
+
secretKey: Fn2.BYTES,
|
|
27073
|
+
publicKey: 1 + Fp2.BYTES,
|
|
27074
|
+
publicKeyUncompressed: 1 + 2 * Fp2.BYTES,
|
|
26035
27075
|
publicKeyHasPrefix: true,
|
|
26036
|
-
signature: 2 *
|
|
27076
|
+
signature: 2 * Fn2.BYTES
|
|
26037
27077
|
};
|
|
26038
27078
|
}
|
|
26039
27079
|
function ecdh(Point, ecdhOpts = {}) {
|
|
26040
|
-
const { Fn } = Point;
|
|
27080
|
+
const { Fn: Fn2 } = Point;
|
|
26041
27081
|
const randomBytes_ = ecdhOpts.randomBytes || randomBytes2;
|
|
26042
|
-
const lengths = Object.assign(getWLengths(Point.Fp,
|
|
27082
|
+
const lengths = Object.assign(getWLengths(Point.Fp, Fn2), { seed: getMinHashLength(Fn2.ORDER) });
|
|
26043
27083
|
function isValidSecretKey(secretKey) {
|
|
26044
27084
|
try {
|
|
26045
|
-
return !!_normFnElement(
|
|
27085
|
+
return !!_normFnElement(Fn2, secretKey);
|
|
26046
27086
|
} catch (error) {
|
|
26047
27087
|
return false;
|
|
26048
27088
|
}
|
|
@@ -26061,10 +27101,10 @@ function ecdh(Point, ecdhOpts = {}) {
|
|
|
26061
27101
|
}
|
|
26062
27102
|
}
|
|
26063
27103
|
function randomSecretKey(seed = randomBytes_(lengths.seed)) {
|
|
26064
|
-
return mapHashToField(_abytes2(seed, lengths.seed, "seed"),
|
|
27104
|
+
return mapHashToField(_abytes2(seed, lengths.seed, "seed"), Fn2.ORDER);
|
|
26065
27105
|
}
|
|
26066
27106
|
function getPublicKey(secretKey, isCompressed = true) {
|
|
26067
|
-
return Point.BASE.multiply(_normFnElement(
|
|
27107
|
+
return Point.BASE.multiply(_normFnElement(Fn2, secretKey)).toBytes(isCompressed);
|
|
26068
27108
|
}
|
|
26069
27109
|
function keygen(seed) {
|
|
26070
27110
|
const secretKey = randomSecretKey(seed);
|
|
@@ -26076,7 +27116,7 @@ function ecdh(Point, ecdhOpts = {}) {
|
|
|
26076
27116
|
if (item instanceof Point)
|
|
26077
27117
|
return true;
|
|
26078
27118
|
const { secretKey, publicKey, publicKeyUncompressed } = lengths;
|
|
26079
|
-
if (
|
|
27119
|
+
if (Fn2.allowedLengths || secretKey === publicKey)
|
|
26080
27120
|
return void 0;
|
|
26081
27121
|
const l = ensureBytes("key", item).length;
|
|
26082
27122
|
return l === publicKey || l === publicKeyUncompressed;
|
|
@@ -26086,7 +27126,7 @@ function ecdh(Point, ecdhOpts = {}) {
|
|
|
26086
27126
|
throw new Error("first arg must be private key");
|
|
26087
27127
|
if (isProbPub(publicKeyB) === false)
|
|
26088
27128
|
throw new Error("second arg must be public key");
|
|
26089
|
-
const s = _normFnElement(
|
|
27129
|
+
const s = _normFnElement(Fn2, secretKeyA);
|
|
26090
27130
|
const b = Point.fromHex(publicKeyB);
|
|
26091
27131
|
return b.multiply(s).toBytes(isCompressed);
|
|
26092
27132
|
}
|
|
@@ -26097,7 +27137,7 @@ function ecdh(Point, ecdhOpts = {}) {
|
|
|
26097
27137
|
// TODO: remove
|
|
26098
27138
|
isValidPrivateKey: isValidSecretKey,
|
|
26099
27139
|
randomPrivateKey: randomSecretKey,
|
|
26100
|
-
normPrivateKeyToScalar: (key) => _normFnElement(
|
|
27140
|
+
normPrivateKeyToScalar: (key) => _normFnElement(Fn2, key),
|
|
26101
27141
|
precompute(windowSize = 8, point = Point.BASE) {
|
|
26102
27142
|
return point.precompute(windowSize, false);
|
|
26103
27143
|
}
|
|
@@ -26115,8 +27155,8 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
26115
27155
|
});
|
|
26116
27156
|
const randomBytes3 = ecdsaOpts.randomBytes || randomBytes2;
|
|
26117
27157
|
const hmac4 = ecdsaOpts.hmac || ((key, ...msgs) => hmac3(hash, key, concatBytes2(...msgs)));
|
|
26118
|
-
const { Fp, Fn } = Point;
|
|
26119
|
-
const { ORDER: CURVE_ORDER, BITS: fnBits } =
|
|
27158
|
+
const { Fp: Fp2, Fn: Fn2 } = Point;
|
|
27159
|
+
const { ORDER: CURVE_ORDER, BITS: fnBits } = Fn2;
|
|
26120
27160
|
const { keygen, getPublicKey, getSharedSecret, utils, lengths } = ecdh(Point, ecdsaOpts);
|
|
26121
27161
|
const defaultSigOpts = {
|
|
26122
27162
|
prehash: false,
|
|
@@ -26127,11 +27167,11 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
26127
27167
|
};
|
|
26128
27168
|
const defaultSigOpts_format = "compact";
|
|
26129
27169
|
function isBiggerThanHalfOrder(number) {
|
|
26130
|
-
const HALF = CURVE_ORDER >>
|
|
27170
|
+
const HALF = CURVE_ORDER >> _1n11;
|
|
26131
27171
|
return number > HALF;
|
|
26132
27172
|
}
|
|
26133
27173
|
function validateRS(title, num) {
|
|
26134
|
-
if (!
|
|
27174
|
+
if (!Fn2.isValidNot0(num))
|
|
26135
27175
|
throw new Error(`invalid signature ${title}: out of range 1..Point.Fn.ORDER`);
|
|
26136
27176
|
return num;
|
|
26137
27177
|
}
|
|
@@ -26161,10 +27201,10 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
26161
27201
|
format = "compact";
|
|
26162
27202
|
bytes = bytes.subarray(1);
|
|
26163
27203
|
}
|
|
26164
|
-
const L =
|
|
27204
|
+
const L = Fn2.BYTES;
|
|
26165
27205
|
const r = bytes.subarray(0, L);
|
|
26166
27206
|
const s = bytes.subarray(L, L * 2);
|
|
26167
|
-
return new Signature(
|
|
27207
|
+
return new Signature(Fn2.fromBytes(r), Fn2.fromBytes(s), recid);
|
|
26168
27208
|
}
|
|
26169
27209
|
static fromHex(hex, format) {
|
|
26170
27210
|
return this.fromBytes(hexToBytes2(hex), format);
|
|
@@ -26173,22 +27213,22 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
26173
27213
|
return new Signature(this.r, this.s, recovery);
|
|
26174
27214
|
}
|
|
26175
27215
|
recoverPublicKey(messageHash) {
|
|
26176
|
-
const FIELD_ORDER =
|
|
27216
|
+
const FIELD_ORDER = Fp2.ORDER;
|
|
26177
27217
|
const { r, s, recovery: rec } = this;
|
|
26178
27218
|
if (rec == null || ![0, 1, 2, 3].includes(rec))
|
|
26179
27219
|
throw new Error("recovery id invalid");
|
|
26180
|
-
const hasCofactor = CURVE_ORDER *
|
|
27220
|
+
const hasCofactor = CURVE_ORDER * _2n7 < FIELD_ORDER;
|
|
26181
27221
|
if (hasCofactor && rec > 1)
|
|
26182
27222
|
throw new Error("recovery id is ambiguous for h>1 curve");
|
|
26183
27223
|
const radj = rec === 2 || rec === 3 ? r + CURVE_ORDER : r;
|
|
26184
|
-
if (!
|
|
27224
|
+
if (!Fp2.isValid(radj))
|
|
26185
27225
|
throw new Error("recovery id 2 or 3 invalid");
|
|
26186
|
-
const x =
|
|
27226
|
+
const x = Fp2.toBytes(radj);
|
|
26187
27227
|
const R = Point.fromBytes(concatBytes2(pprefix((rec & 1) === 0), x));
|
|
26188
|
-
const ir =
|
|
27228
|
+
const ir = Fn2.inv(radj);
|
|
26189
27229
|
const h = bits2int_modN(ensureBytes("msgHash", messageHash));
|
|
26190
|
-
const u1 =
|
|
26191
|
-
const u2 =
|
|
27230
|
+
const u1 = Fn2.create(-h * ir);
|
|
27231
|
+
const u2 = Fn2.create(s * ir);
|
|
26192
27232
|
const Q = Point.BASE.multiplyUnsafe(u1).add(R.multiplyUnsafe(u2));
|
|
26193
27233
|
if (Q.is0())
|
|
26194
27234
|
throw new Error("point at infinify");
|
|
@@ -26203,8 +27243,8 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
26203
27243
|
validateSigFormat(format);
|
|
26204
27244
|
if (format === "der")
|
|
26205
27245
|
return hexToBytes2(DER.hexFromSig(this));
|
|
26206
|
-
const r =
|
|
26207
|
-
const s =
|
|
27246
|
+
const r = Fn2.toBytes(this.r);
|
|
27247
|
+
const s = Fn2.toBytes(this.s);
|
|
26208
27248
|
if (format === "recovered") {
|
|
26209
27249
|
if (this.recovery == null)
|
|
26210
27250
|
throw new Error("recovery bit must be present");
|
|
@@ -26225,7 +27265,7 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
26225
27265
|
return Signature.fromBytes(ensureBytes("sig", hex), "der");
|
|
26226
27266
|
}
|
|
26227
27267
|
normalizeS() {
|
|
26228
|
-
return this.hasHighS() ? new Signature(this.r,
|
|
27268
|
+
return this.hasHighS() ? new Signature(this.r, Fn2.neg(this.s), this.recovery) : this;
|
|
26229
27269
|
}
|
|
26230
27270
|
toDERRawBytes() {
|
|
26231
27271
|
return this.toBytes("der");
|
|
@@ -26248,12 +27288,12 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
26248
27288
|
return delta > 0 ? num >> BigInt(delta) : num;
|
|
26249
27289
|
};
|
|
26250
27290
|
const bits2int_modN = ecdsaOpts.bits2int_modN || function bits2int_modN_def(bytes) {
|
|
26251
|
-
return
|
|
27291
|
+
return Fn2.create(bits2int(bytes));
|
|
26252
27292
|
};
|
|
26253
27293
|
const ORDER_MASK = bitMask2(fnBits);
|
|
26254
27294
|
function int2octets(num) {
|
|
26255
|
-
aInRange2("num < 2^" + fnBits, num,
|
|
26256
|
-
return
|
|
27295
|
+
aInRange2("num < 2^" + fnBits, num, _0n10, ORDER_MASK);
|
|
27296
|
+
return Fn2.toBytes(num);
|
|
26257
27297
|
}
|
|
26258
27298
|
function validateMsgAndHash(message, prehash) {
|
|
26259
27299
|
_abytes2(message, void 0, "message");
|
|
@@ -26265,7 +27305,7 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
26265
27305
|
const { lowS, prehash, extraEntropy } = validateSigOpts(opts, defaultSigOpts);
|
|
26266
27306
|
message = validateMsgAndHash(message, prehash);
|
|
26267
27307
|
const h1int = bits2int_modN(message);
|
|
26268
|
-
const d = _normFnElement(
|
|
27308
|
+
const d = _normFnElement(Fn2, privateKey);
|
|
26269
27309
|
const seedArgs = [int2octets(d), int2octets(h1int)];
|
|
26270
27310
|
if (extraEntropy != null && extraEntropy !== false) {
|
|
26271
27311
|
const e = extraEntropy === true ? randomBytes3(lengths.secretKey) : extraEntropy;
|
|
@@ -26275,20 +27315,20 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
26275
27315
|
const m = h1int;
|
|
26276
27316
|
function k2sig(kBytes) {
|
|
26277
27317
|
const k = bits2int(kBytes);
|
|
26278
|
-
if (!
|
|
27318
|
+
if (!Fn2.isValidNot0(k))
|
|
26279
27319
|
return;
|
|
26280
|
-
const ik =
|
|
27320
|
+
const ik = Fn2.inv(k);
|
|
26281
27321
|
const q = Point.BASE.multiply(k).toAffine();
|
|
26282
|
-
const r =
|
|
26283
|
-
if (r ===
|
|
27322
|
+
const r = Fn2.create(q.x);
|
|
27323
|
+
if (r === _0n10)
|
|
26284
27324
|
return;
|
|
26285
|
-
const s =
|
|
26286
|
-
if (s ===
|
|
27325
|
+
const s = Fn2.create(ik * Fn2.create(m + r * d));
|
|
27326
|
+
if (s === _0n10)
|
|
26287
27327
|
return;
|
|
26288
|
-
let recovery = (q.x === r ? 0 : 2) | Number(q.y &
|
|
27328
|
+
let recovery = (q.x === r ? 0 : 2) | Number(q.y & _1n11);
|
|
26289
27329
|
let normS = s;
|
|
26290
27330
|
if (lowS && isBiggerThanHalfOrder(s)) {
|
|
26291
|
-
normS =
|
|
27331
|
+
normS = Fn2.neg(s);
|
|
26292
27332
|
recovery ^= 1;
|
|
26293
27333
|
}
|
|
26294
27334
|
return new Signature(r, normS, recovery);
|
|
@@ -26298,7 +27338,7 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
26298
27338
|
function sign(message, secretKey, opts = {}) {
|
|
26299
27339
|
message = ensureBytes("message", message);
|
|
26300
27340
|
const { seed, k2sig } = prepSig(message, secretKey, opts);
|
|
26301
|
-
const drbg = createHmacDrbg(hash.outputLen,
|
|
27341
|
+
const drbg = createHmacDrbg(hash.outputLen, Fn2.BYTES, hmac4);
|
|
26302
27342
|
const sig = drbg(seed, k2sig);
|
|
26303
27343
|
return sig;
|
|
26304
27344
|
}
|
|
@@ -26344,13 +27384,13 @@ function ecdsa(Point, hash, ecdsaOpts = {}) {
|
|
|
26344
27384
|
return false;
|
|
26345
27385
|
const { r, s } = sig;
|
|
26346
27386
|
const h = bits2int_modN(message);
|
|
26347
|
-
const is =
|
|
26348
|
-
const u1 =
|
|
26349
|
-
const u2 =
|
|
27387
|
+
const is = Fn2.inv(s);
|
|
27388
|
+
const u1 = Fn2.create(h * is);
|
|
27389
|
+
const u2 = Fn2.create(r * is);
|
|
26350
27390
|
const R = Point.BASE.multiplyUnsafe(u1).add(P.multiplyUnsafe(u2));
|
|
26351
27391
|
if (R.is0())
|
|
26352
27392
|
return false;
|
|
26353
|
-
const v =
|
|
27393
|
+
const v = Fn2.create(R.x);
|
|
26354
27394
|
return v === r;
|
|
26355
27395
|
} catch (e) {
|
|
26356
27396
|
return false;
|
|
@@ -26385,16 +27425,16 @@ function _weierstrass_legacy_opts_to_new(c) {
|
|
|
26385
27425
|
Gx: c.Gx,
|
|
26386
27426
|
Gy: c.Gy
|
|
26387
27427
|
};
|
|
26388
|
-
const
|
|
27428
|
+
const Fp2 = c.Fp;
|
|
26389
27429
|
let allowedLengths = c.allowedPrivateKeyLengths ? Array.from(new Set(c.allowedPrivateKeyLengths.map((l) => Math.ceil(l / 2)))) : void 0;
|
|
26390
|
-
const
|
|
27430
|
+
const Fn2 = Field2(CURVE.n, {
|
|
26391
27431
|
BITS: c.nBitLength,
|
|
26392
27432
|
allowedLengths,
|
|
26393
27433
|
modFromBytes: c.wrapPrivateKey
|
|
26394
27434
|
});
|
|
26395
27435
|
const curveOpts = {
|
|
26396
|
-
Fp,
|
|
26397
|
-
Fn,
|
|
27436
|
+
Fp: Fp2,
|
|
27437
|
+
Fn: Fn2,
|
|
26398
27438
|
allowInfinityPoint: c.allowInfinityPoint,
|
|
26399
27439
|
endo: c.endo,
|
|
26400
27440
|
isTorsionFree: c.isTorsionFree,
|
|
@@ -26452,25 +27492,25 @@ var secp256k1_ENDO = {
|
|
|
26452
27492
|
[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), BigInt("0x3086d221a7d46bcde86c90e49284eb15")]
|
|
26453
27493
|
]
|
|
26454
27494
|
};
|
|
26455
|
-
var
|
|
27495
|
+
var _2n8 = /* @__PURE__ */ BigInt(2);
|
|
26456
27496
|
function sqrtMod(y) {
|
|
26457
27497
|
const P = secp256k1_CURVE.p;
|
|
26458
|
-
const
|
|
27498
|
+
const _3n5 = BigInt(3), _6n = BigInt(6), _11n = BigInt(11), _22n = BigInt(22);
|
|
26459
27499
|
const _23n = BigInt(23), _44n = BigInt(44), _88n = BigInt(88);
|
|
26460
27500
|
const b2 = y * y * y % P;
|
|
26461
27501
|
const b3 = b2 * b2 * y % P;
|
|
26462
|
-
const b6 = pow22(b3,
|
|
26463
|
-
const b9 = pow22(b6,
|
|
26464
|
-
const b11 = pow22(b9,
|
|
27502
|
+
const b6 = pow22(b3, _3n5, P) * b3 % P;
|
|
27503
|
+
const b9 = pow22(b6, _3n5, P) * b3 % P;
|
|
27504
|
+
const b11 = pow22(b9, _2n8, P) * b2 % P;
|
|
26465
27505
|
const b22 = pow22(b11, _11n, P) * b11 % P;
|
|
26466
27506
|
const b44 = pow22(b22, _22n, P) * b22 % P;
|
|
26467
27507
|
const b88 = pow22(b44, _44n, P) * b44 % P;
|
|
26468
27508
|
const b176 = pow22(b88, _88n, P) * b88 % P;
|
|
26469
27509
|
const b220 = pow22(b176, _44n, P) * b44 % P;
|
|
26470
|
-
const b223 = pow22(b220,
|
|
27510
|
+
const b223 = pow22(b220, _3n5, P) * b3 % P;
|
|
26471
27511
|
const t1 = pow22(b223, _23n, P) * b22 % P;
|
|
26472
27512
|
const t2 = pow22(t1, _6n, P) * b2 % P;
|
|
26473
|
-
const root = pow22(t2,
|
|
27513
|
+
const root = pow22(t2, _2n8, P);
|
|
26474
27514
|
if (!Fpk1.eql(Fpk1.sqr(root), y))
|
|
26475
27515
|
throw new Error("Cannot find square root");
|
|
26476
27516
|
return root;
|
|
@@ -28193,7 +29233,7 @@ function resolveApiKey(apiKey) {
|
|
|
28193
29233
|
if (!key) {
|
|
28194
29234
|
throw new T2000Error(
|
|
28195
29235
|
"INVALID_KEY",
|
|
28196
|
-
"No Private
|
|
29236
|
+
"No Private Inference key. Pass `apiKey` or set T2000_API_KEY. Generate one at agents.t2000.ai/manage."
|
|
28197
29237
|
);
|
|
28198
29238
|
}
|
|
28199
29239
|
return key;
|
|
@@ -28371,7 +29411,24 @@ function jcs(value) {
|
|
|
28371
29411
|
function verifyReceiptSignature(receipt, signingKeyHex) {
|
|
28372
29412
|
try {
|
|
28373
29413
|
const sig = receipt.signature;
|
|
28374
|
-
if (sig?.
|
|
29414
|
+
if (!sig?.value) {
|
|
29415
|
+
return false;
|
|
29416
|
+
}
|
|
29417
|
+
const endorsed = hexToBytes2(signingKeyHex.replace(/^0x/, ""));
|
|
29418
|
+
const sigBytes = hexToBytes2(sig.value);
|
|
29419
|
+
if (sig.algo === "ed25519") {
|
|
29420
|
+
if (sigBytes.length !== 64 || endorsed.length !== 32) {
|
|
29421
|
+
return false;
|
|
29422
|
+
}
|
|
29423
|
+
const { value: _omitted, ...sigRest } = sig;
|
|
29424
|
+
const canonical2 = {
|
|
29425
|
+
...receipt,
|
|
29426
|
+
signature: sigRest
|
|
29427
|
+
};
|
|
29428
|
+
const msg = new TextEncoder().encode(jcs(canonical2));
|
|
29429
|
+
return ed255192.verify(sigBytes, msg, endorsed);
|
|
29430
|
+
}
|
|
29431
|
+
if (sig.algo !== "ecdsa-secp256k1") {
|
|
28375
29432
|
return false;
|
|
28376
29433
|
}
|
|
28377
29434
|
const canonical = {
|
|
@@ -28387,7 +29444,6 @@ function verifyReceiptSignature(receipt, signingKeyHex) {
|
|
|
28387
29444
|
signature: { algo: sig.algo, key_id: sig.key_id ?? "" }
|
|
28388
29445
|
};
|
|
28389
29446
|
const prehash = sha2563(new TextEncoder().encode(jcs(canonical)));
|
|
28390
|
-
const sigBytes = hexToBytes2(sig.value);
|
|
28391
29447
|
if (sigBytes.length !== 65) {
|
|
28392
29448
|
return false;
|
|
28393
29449
|
}
|
|
@@ -28399,8 +29455,7 @@ function verifyReceiptSignature(receipt, signingKeyHex) {
|
|
|
28399
29455
|
return false;
|
|
28400
29456
|
}
|
|
28401
29457
|
const recovered = secp256k1.Signature.fromCompact(sigBytes.slice(0, 64)).addRecoveryBit(v).recoverPublicKey(prehash).toHex(false);
|
|
28402
|
-
|
|
28403
|
-
return recovered.toLowerCase() === endorsed.toLowerCase();
|
|
29458
|
+
return recovered.toLowerCase() === bytesToHex2(endorsed).toLowerCase();
|
|
28404
29459
|
} catch {
|
|
28405
29460
|
return false;
|
|
28406
29461
|
}
|
|
@@ -28900,9 +29955,9 @@ var T2000 = class _T2000 extends import_index2.default {
|
|
|
28900
29955
|
//
|
|
28901
29956
|
// Inference as a wallet verb — the agent's brain + wallet in one package.
|
|
28902
29957
|
// Key-based today (`apiKey` / `T2000_API_KEY`); the x402 no-key pay-per-call
|
|
28903
|
-
// path is a later add. The model runs on
|
|
29958
|
+
// path is a later add. The model runs on t2000 Private Inference (ZDR; a
|
|
28904
29959
|
// `phala/*` confidential tier runs in a GPU-TEE).
|
|
28905
|
-
/** Non-streaming chat completion against
|
|
29960
|
+
/** Non-streaming chat completion against Private Inference. */
|
|
28906
29961
|
async chat(params) {
|
|
28907
29962
|
return chatCompletion(params);
|
|
28908
29963
|
}
|
|
@@ -28911,7 +29966,7 @@ var T2000 = class _T2000 extends import_index2.default {
|
|
|
28911
29966
|
chatStream(params) {
|
|
28912
29967
|
return chatCompletionStream(params);
|
|
28913
29968
|
}
|
|
28914
|
-
/** The Private
|
|
29969
|
+
/** The Private Inference model catalog (`GET /v1/models`). */
|
|
28915
29970
|
async models(opts) {
|
|
28916
29971
|
return listModels(opts);
|
|
28917
29972
|
}
|
|
@@ -32619,8 +33674,8 @@ function numOrUndef(v) {
|
|
|
32619
33674
|
}
|
|
32620
33675
|
function registerChat(program3) {
|
|
32621
33676
|
program3.command("chat").argument("<message...>", "Your prompt").description(
|
|
32622
|
-
"Chat with a model on
|
|
32623
|
-
).option("--model <id>", `Model id (default ${DEFAULT_MODEL}; see \`t2 models\`)`, DEFAULT_MODEL).option("--system <text>", "System prompt").option("--max-tokens <n>", "Max output tokens").option("--temperature <t>", "Sampling temperature (0\u20132)").option("--no-stream", "Wait for the full response instead of streaming").option("--api-key <key>", "Private
|
|
33677
|
+
"Chat with a model on t2000 Private Inference (OpenAI-compatible, ZDR; a phala/* tier is GPU-TEE confidential). Needs an API key \u2014 generate one at agents.t2000.ai/manage, then pass --api-key or set T2000_API_KEY."
|
|
33678
|
+
).option("--model <id>", `Model id (default ${DEFAULT_MODEL}; see \`t2 models\`)`, DEFAULT_MODEL).option("--system <text>", "System prompt").option("--max-tokens <n>", "Max output tokens").option("--temperature <t>", "Sampling temperature (0\u20132)").option("--no-stream", "Wait for the full response instead of streaming").option("--api-key <key>", "Private Inference key (or set T2000_API_KEY)").option("--api <url>", "API base URL (default https://api.t2000.ai/v1)").action(
|
|
32624
33679
|
async (messageParts, opts) => {
|
|
32625
33680
|
try {
|
|
32626
33681
|
const messages = [];
|
|
@@ -32668,7 +33723,7 @@ function registerChat(program3) {
|
|
|
32668
33723
|
}
|
|
32669
33724
|
}
|
|
32670
33725
|
);
|
|
32671
|
-
program3.command("models").description("List the t2000 Private
|
|
33726
|
+
program3.command("models").description("List the t2000 Private Inference model catalog (id \xB7 privacy tier \xB7 per-1M pricing).").option("--api-key <key>", "Private Inference key (or set T2000_API_KEY)").option("--api <url>", "API base URL (default https://api.t2000.ai/v1)").action(async (opts) => {
|
|
32672
33727
|
try {
|
|
32673
33728
|
const models = await listModels({ apiKey: opts.apiKey, apiBase: opts.api });
|
|
32674
33729
|
if (isJsonMode()) {
|
|
@@ -33122,7 +34177,7 @@ function registerMcpStart(parent) {
|
|
|
33122
34177
|
parent.command("start", { isDefault: true }).description("Start MCP server (stdio transport \u2014 for AI client integration)").option("--key <path>", "Custom wallet path (default ~/.t2000/wallet.key)").action(async (opts) => {
|
|
33123
34178
|
let mod3;
|
|
33124
34179
|
try {
|
|
33125
|
-
mod3 = await import("./dist-
|
|
34180
|
+
mod3 = await import("./dist-JNPBEKR5.js");
|
|
33126
34181
|
} catch {
|
|
33127
34182
|
console.error("MCP server not installed. Run:\n npm install -g @t2000/mcp");
|
|
33128
34183
|
process.exit(1);
|
|
@@ -33752,27 +34807,6 @@ function registerAgentCreate(group) {
|
|
|
33752
34807
|
|
|
33753
34808
|
// src/commands/agent/index.ts
|
|
33754
34809
|
var DEFAULT_API_BASE4 = process.env.T2000_API_URL ?? "https://api.t2000.ai/v1";
|
|
33755
|
-
function normalizeTopupAsset(input) {
|
|
33756
|
-
return input?.toLowerCase() === "usdsui" ? "USDsui" : "USDC";
|
|
33757
|
-
}
|
|
33758
|
-
async function fundCredit(agent, base, amountStr, assetOpt) {
|
|
33759
|
-
const amount = Number.parseFloat(amountStr);
|
|
33760
|
-
if (Number.isNaN(amount) || amount <= 0) {
|
|
33761
|
-
throw new Error(`amount must be a positive number (got "${amountStr}").`);
|
|
33762
|
-
}
|
|
33763
|
-
const asset = normalizeTopupAsset(assetOpt);
|
|
33764
|
-
const cfg = await fetchJson2(`${base}/agent/topup`, { method: "GET" });
|
|
33765
|
-
const treasury = cfg.treasury;
|
|
33766
|
-
if (!treasury) {
|
|
33767
|
-
throw new Error("Could not resolve the t2000 treasury address.");
|
|
33768
|
-
}
|
|
33769
|
-
const sent = await agent.send({ to: treasury, amount, asset });
|
|
33770
|
-
const topup = await fetchJson2(`${base}/agent/topup`, {
|
|
33771
|
-
method: "POST",
|
|
33772
|
-
body: { address: agent.address(), digest: sent.tx }
|
|
33773
|
-
});
|
|
33774
|
-
return { amount, asset, balanceUsd: topup.balanceUsd };
|
|
33775
|
-
}
|
|
33776
34810
|
async function fetchJson2(url, init) {
|
|
33777
34811
|
const res = await fetch(url, {
|
|
33778
34812
|
method: init.method,
|
|
@@ -33788,105 +34822,16 @@ async function fetchJson2(url, init) {
|
|
|
33788
34822
|
return json;
|
|
33789
34823
|
}
|
|
33790
34824
|
function registerAgent(program3) {
|
|
33791
|
-
const group = program3.command("agent").description("Agent ID \u2014
|
|
34825
|
+
const group = program3.command("agent").description("Agent ID \u2014 on-chain identity for this wallet (register \xB7 handle \xB7 profile \xB7 ownership)").addHelpText(
|
|
33792
34826
|
"after",
|
|
33793
34827
|
`
|
|
33794
34828
|
Subcommands:
|
|
33795
34829
|
$ t2 agent create --name "Atlas Research" Wallet + Agent ID + profile in one pass
|
|
33796
|
-
$ t2 agent
|
|
33797
|
-
$ t2 agent
|
|
33798
|
-
$ t2 agent onboard Already funded \u2192 just mint a key
|
|
34830
|
+
$ t2 agent register Existing wallet \u2192 on-chain Agent ID (gasless)
|
|
34831
|
+
$ t2 agent handle alice Claim @alice
|
|
33799
34832
|
`
|
|
33800
34833
|
);
|
|
33801
34834
|
registerAgentCreate(group);
|
|
33802
|
-
group.command("onboard").description(
|
|
33803
|
-
"Buy-side setup: fund credit (gasless USDC/USDsui) + mint a Private API key. Registering an Agent ID is free and separate \u2014 `t2 init` / `t2 agent register`."
|
|
33804
|
-
).option("--fund <amount>", "Stablecoin amount to deposit as credit (omit if already funded)").option("--asset <asset>", "USDC (default) or USDsui", "USDC").option("--key <path>", "Custom wallet path (default ~/.t2000/wallet.key)").option("--api <url>", `API base URL (default ${DEFAULT_API_BASE4})`).action(
|
|
33805
|
-
async (opts) => {
|
|
33806
|
-
try {
|
|
33807
|
-
const base = opts.api ?? DEFAULT_API_BASE4;
|
|
33808
|
-
const agent = await withAgent({ keyPath: opts.key });
|
|
33809
|
-
const address = agent.address();
|
|
33810
|
-
if (opts.fund !== void 0) {
|
|
33811
|
-
const funded = await fundCredit(agent, base, opts.fund, opts.asset);
|
|
33812
|
-
if (!isJsonMode()) {
|
|
33813
|
-
printSuccess(
|
|
33814
|
-
`Funded ${formatUsd(funded.amount)} ${funded.asset} \u2192 credit $${funded.balanceUsd}`
|
|
33815
|
-
);
|
|
33816
|
-
}
|
|
33817
|
-
}
|
|
33818
|
-
const challenge = await fetchJson2(`${base}/agent/challenge`, {
|
|
33819
|
-
method: "POST",
|
|
33820
|
-
body: { address }
|
|
33821
|
-
});
|
|
33822
|
-
const nonce = challenge.nonce;
|
|
33823
|
-
if (!nonce) {
|
|
33824
|
-
throw new Error("Failed to get a challenge nonce.");
|
|
33825
|
-
}
|
|
33826
|
-
const message = new TextEncoder().encode(`t2000-agent-keys:${nonce}`);
|
|
33827
|
-
const { signature } = await agent.keypair.signPersonalMessage(message);
|
|
33828
|
-
const minted = await fetchJson2(`${base}/agent/keys`, {
|
|
33829
|
-
method: "POST",
|
|
33830
|
-
body: { address, nonce, signature }
|
|
33831
|
-
});
|
|
33832
|
-
const key = minted.key;
|
|
33833
|
-
if (!key) {
|
|
33834
|
-
throw new Error("Failed to mint an API key.");
|
|
33835
|
-
}
|
|
33836
|
-
let registered = false;
|
|
33837
|
-
try {
|
|
33838
|
-
await registerWallet({ keypair: agent.keypair, address, base });
|
|
33839
|
-
registered = true;
|
|
33840
|
-
} catch {
|
|
33841
|
-
}
|
|
33842
|
-
if (isJsonMode()) {
|
|
33843
|
-
printJson({ address, apiKey: key, baseUrl: base, registered });
|
|
33844
|
-
return;
|
|
33845
|
-
}
|
|
33846
|
-
printBlank();
|
|
33847
|
-
printSuccess("Agent onboarded \u2014 API key minted (shown once, store it now)");
|
|
33848
|
-
printKeyValue("Address", truncateAddress(address));
|
|
33849
|
-
printKeyValue("API key", key);
|
|
33850
|
-
printKeyValue(
|
|
33851
|
-
"Agent ID",
|
|
33852
|
-
registered ? "registered" : "pending (retry: t2 agent register)"
|
|
33853
|
-
);
|
|
33854
|
-
printKeyValue("Base URL", base);
|
|
33855
|
-
printBlank();
|
|
33856
|
-
printInfo(`export OPENAI_BASE_URL=${base} OPENAI_API_KEY=${key}`);
|
|
33857
|
-
printBlank();
|
|
33858
|
-
} catch (error) {
|
|
33859
|
-
handleError(error);
|
|
33860
|
-
}
|
|
33861
|
-
}
|
|
33862
|
-
);
|
|
33863
|
-
group.command("topup").argument("<amount>", "Stablecoin amount to deposit as credit").description(
|
|
33864
|
-
"Top up this wallet's t2000 credit with gasless USDC/USDsui (no new key). The 'never runs dry' primitive \u2014 call it on a 402 or a schedule."
|
|
33865
|
-
).option("--asset <asset>", "USDC (default) or USDsui", "USDC").option("--key <path>", "Custom wallet path (default ~/.t2000/wallet.key)").option("--api <url>", `API base URL (default ${DEFAULT_API_BASE4})`).action(
|
|
33866
|
-
async (amount, opts) => {
|
|
33867
|
-
try {
|
|
33868
|
-
const base = opts.api ?? DEFAULT_API_BASE4;
|
|
33869
|
-
const agent = await withAgent({ keyPath: opts.key });
|
|
33870
|
-
const funded = await fundCredit(agent, base, amount, opts.asset);
|
|
33871
|
-
if (isJsonMode()) {
|
|
33872
|
-
printJson({
|
|
33873
|
-
address: agent.address(),
|
|
33874
|
-
funded: funded.amount,
|
|
33875
|
-
asset: funded.asset,
|
|
33876
|
-
balanceUsd: funded.balanceUsd
|
|
33877
|
-
});
|
|
33878
|
-
return;
|
|
33879
|
-
}
|
|
33880
|
-
printBlank();
|
|
33881
|
-
printSuccess(
|
|
33882
|
-
`Topped up ${formatUsd(funded.amount)} ${funded.asset} \u2192 credit $${funded.balanceUsd}`
|
|
33883
|
-
);
|
|
33884
|
-
printBlank();
|
|
33885
|
-
} catch (error) {
|
|
33886
|
-
handleError(error);
|
|
33887
|
-
}
|
|
33888
|
-
}
|
|
33889
|
-
);
|
|
33890
34835
|
group.command("register").description(
|
|
33891
34836
|
"Register this wallet on-chain as an Agent ID (sponsored, gasless). Idempotent \u2014 safe to re-run."
|
|
33892
34837
|
).option("--key <path>", "Custom wallet path (default ~/.t2000/wallet.key)").option("--api <url>", `API base URL (default ${DEFAULT_API_BASE4})`).action(async (opts) => {
|
|
@@ -34197,8 +35142,8 @@ Examples:
|
|
|
34197
35142
|
$ t2 balance Show USDC / USDsui / SUI holdings
|
|
34198
35143
|
$ t2 send 5 USDC alice.sui Send 5 USDC (gasless; asset required)
|
|
34199
35144
|
$ t2 swap 100 USDC SUI Swap 100 USDC for SUI via Cetus
|
|
34200
|
-
$ t2 chat "Summarize Sui in 3 lines" Private
|
|
34201
|
-
$ t2 models List the Private
|
|
35145
|
+
$ t2 chat "Summarize Sui in 3 lines" Private Inference (OpenAI-compatible; needs T2000_API_KEY)
|
|
35146
|
+
$ t2 models List the Private Inference model catalog
|
|
34202
35147
|
$ t2 pay <url> --estimate Preview an x402 service's price + input schema (no payment)
|
|
34203
35148
|
$ t2 services search "image" Discover x402 services in the gateway catalog
|
|
34204
35149
|
$ t2 agents Look up the agent directory (agents.t2000.ai)
|
|
@@ -34245,6 +35190,8 @@ program2.parse();
|
|
|
34245
35190
|
@noble/curves/esm/utils.js:
|
|
34246
35191
|
@noble/curves/esm/abstract/modular.js:
|
|
34247
35192
|
@noble/curves/esm/abstract/curve.js:
|
|
35193
|
+
@noble/curves/esm/abstract/edwards.js:
|
|
35194
|
+
@noble/curves/esm/ed25519.js:
|
|
34248
35195
|
@noble/curves/esm/abstract/weierstrass.js:
|
|
34249
35196
|
@noble/curves/esm/_shortw_utils.js:
|
|
34250
35197
|
@noble/curves/esm/secp256k1.js:
|