starknet 5.0.0 → 5.0.1
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/CHANGELOG.md +7 -0
- package/dist/index.global.js +225 -176
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +21 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -4
package/dist/index.global.js
CHANGED
|
@@ -30,21 +30,6 @@ var starknet = (() => {
|
|
|
30
30
|
));
|
|
31
31
|
var __toCommonJS = (mod2) => __copyProps(__defProp({}, "__esModule", { value: true }), mod2);
|
|
32
32
|
|
|
33
|
-
// node_modules/minimalistic-assert/index.js
|
|
34
|
-
var require_minimalistic_assert = __commonJS({
|
|
35
|
-
"node_modules/minimalistic-assert/index.js"(exports, module) {
|
|
36
|
-
module.exports = assert7;
|
|
37
|
-
function assert7(val, msg) {
|
|
38
|
-
if (!val)
|
|
39
|
-
throw new Error(msg || "Assertion failed");
|
|
40
|
-
}
|
|
41
|
-
assert7.equal = function assertEqual(l, r, msg) {
|
|
42
|
-
if (l != r)
|
|
43
|
-
throw new Error(msg || "Assertion failed: " + l + " != " + r);
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
|
|
48
33
|
// node_modules/whatwg-fetch/fetch.js
|
|
49
34
|
var fetch_exports = {};
|
|
50
35
|
__export(fetch_exports, {
|
|
@@ -600,7 +585,7 @@ var starknet = (() => {
|
|
|
600
585
|
}
|
|
601
586
|
}
|
|
602
587
|
exports.output = output2;
|
|
603
|
-
var
|
|
588
|
+
var assert3 = {
|
|
604
589
|
number: number2,
|
|
605
590
|
bool: bool2,
|
|
606
591
|
bytes: bytes2,
|
|
@@ -608,7 +593,7 @@ var starknet = (() => {
|
|
|
608
593
|
exists: exists2,
|
|
609
594
|
output: output2
|
|
610
595
|
};
|
|
611
|
-
exports.default =
|
|
596
|
+
exports.default = assert3;
|
|
612
597
|
}
|
|
613
598
|
});
|
|
614
599
|
|
|
@@ -3105,9 +3090,6 @@ var starknet = (() => {
|
|
|
3105
3090
|
validateChecksumAddress: () => validateChecksumAddress
|
|
3106
3091
|
});
|
|
3107
3092
|
|
|
3108
|
-
// src/contract/default.ts
|
|
3109
|
-
var import_minimalistic_assert4 = __toESM(require_minimalistic_assert());
|
|
3110
|
-
|
|
3111
3093
|
// src/types/lib.ts
|
|
3112
3094
|
var TransactionStatus = /* @__PURE__ */ ((TransactionStatus2) => {
|
|
3113
3095
|
TransactionStatus2["NOT_RECEIVED"] = "NOT_RECEIVED";
|
|
@@ -5339,7 +5321,15 @@ var starknet = (() => {
|
|
|
5339
5321
|
toHex: () => toHex,
|
|
5340
5322
|
toHexString: () => toHexString
|
|
5341
5323
|
});
|
|
5342
|
-
|
|
5324
|
+
|
|
5325
|
+
// src/utils/assert.ts
|
|
5326
|
+
function assert(condition, message) {
|
|
5327
|
+
if (!condition) {
|
|
5328
|
+
throw new Error(message || "Assertion failure");
|
|
5329
|
+
}
|
|
5330
|
+
}
|
|
5331
|
+
|
|
5332
|
+
// src/utils/number.ts
|
|
5343
5333
|
function isHex(hex) {
|
|
5344
5334
|
return /^0x[0-9a-f]*$/i.test(hex);
|
|
5345
5335
|
}
|
|
@@ -5361,7 +5351,7 @@ var starknet = (() => {
|
|
|
5361
5351
|
const inputBigInt = BigInt(input);
|
|
5362
5352
|
const lowerBoundBigInt = BigInt(lowerBound);
|
|
5363
5353
|
const upperBoundBigInt = BigInt(upperBound);
|
|
5364
|
-
(
|
|
5354
|
+
assert(
|
|
5365
5355
|
inputBigInt >= lowerBoundBigInt && inputBigInt <= upperBoundBigInt,
|
|
5366
5356
|
`Message not signable, ${messageSuffix}.`
|
|
5367
5357
|
);
|
|
@@ -6174,24 +6164,51 @@ var starknet = (() => {
|
|
|
6174
6164
|
});
|
|
6175
6165
|
|
|
6176
6166
|
// node_modules/@noble/curves/lib/esm/abstract/utils.js
|
|
6167
|
+
var utils_exports = {};
|
|
6168
|
+
__export(utils_exports, {
|
|
6169
|
+
bitGet: () => bitGet,
|
|
6170
|
+
bitLen: () => bitLen,
|
|
6171
|
+
bitMask: () => bitMask,
|
|
6172
|
+
bitSet: () => bitSet,
|
|
6173
|
+
bytesToHex: () => bytesToHex,
|
|
6174
|
+
bytesToNumberBE: () => bytesToNumberBE,
|
|
6175
|
+
bytesToNumberLE: () => bytesToNumberLE,
|
|
6176
|
+
concatBytes: () => concatBytes2,
|
|
6177
|
+
ensureBytes: () => ensureBytes,
|
|
6178
|
+
equalBytes: () => equalBytes,
|
|
6179
|
+
hashToPrivateScalar: () => hashToPrivateScalar,
|
|
6180
|
+
hexToBytes: () => hexToBytes,
|
|
6181
|
+
hexToNumber: () => hexToNumber,
|
|
6182
|
+
isPositiveInt: () => isPositiveInt,
|
|
6183
|
+
nLength: () => nLength,
|
|
6184
|
+
numberToBytesBE: () => numberToBytesBE,
|
|
6185
|
+
numberToBytesLE: () => numberToBytesLE,
|
|
6186
|
+
numberToHexUnpadded: () => numberToHexUnpadded,
|
|
6187
|
+
validateOpts: () => validateOpts
|
|
6188
|
+
});
|
|
6177
6189
|
var _0n2 = BigInt(0);
|
|
6178
6190
|
var _1n2 = BigInt(1);
|
|
6179
6191
|
var _2n2 = BigInt(2);
|
|
6192
|
+
function isPositiveInt(num) {
|
|
6193
|
+
return typeof num === "number" && Number.isSafeInteger(num) && num > 0;
|
|
6194
|
+
}
|
|
6180
6195
|
function validateOpts(curve) {
|
|
6181
6196
|
validateField(curve.Fp);
|
|
6182
6197
|
for (const i of ["n", "h"]) {
|
|
6183
|
-
|
|
6184
|
-
|
|
6198
|
+
const val = curve[i];
|
|
6199
|
+
if (typeof val !== "bigint")
|
|
6200
|
+
throw new Error(`Invalid curve param ${i}=${val} (${typeof val})`);
|
|
6185
6201
|
}
|
|
6186
6202
|
if (!curve.Fp.isValid(curve.Gx))
|
|
6187
6203
|
throw new Error("Invalid generator X coordinate Fp element");
|
|
6188
6204
|
if (!curve.Fp.isValid(curve.Gy))
|
|
6189
6205
|
throw new Error("Invalid generator Y coordinate Fp element");
|
|
6190
6206
|
for (const i of ["nBitLength", "nByteLength"]) {
|
|
6191
|
-
|
|
6207
|
+
const val = curve[i];
|
|
6208
|
+
if (val === void 0)
|
|
6192
6209
|
continue;
|
|
6193
|
-
if (!
|
|
6194
|
-
throw new Error(`Invalid curve param ${i}=${
|
|
6210
|
+
if (!isPositiveInt(val))
|
|
6211
|
+
throw new Error(`Invalid curve param ${i}=${val} (${typeof val})`);
|
|
6195
6212
|
}
|
|
6196
6213
|
return Object.freeze({ ...nLength(curve.n, curve.nBitLength), ...curve });
|
|
6197
6214
|
}
|
|
@@ -6267,15 +6284,31 @@ var starknet = (() => {
|
|
|
6267
6284
|
const nByteLength = Math.ceil(_nBitLength / 8);
|
|
6268
6285
|
return { nBitLength: _nBitLength, nByteLength };
|
|
6269
6286
|
}
|
|
6270
|
-
function hashToPrivateScalar(hash2,
|
|
6287
|
+
function hashToPrivateScalar(hash2, groupOrder, isLE2 = false) {
|
|
6271
6288
|
hash2 = ensureBytes(hash2);
|
|
6272
|
-
const
|
|
6273
|
-
const minLen =
|
|
6274
|
-
if (
|
|
6275
|
-
throw new Error(
|
|
6289
|
+
const hashLen = hash2.length;
|
|
6290
|
+
const minLen = nLength(groupOrder).nByteLength + 8;
|
|
6291
|
+
if (minLen < 24 || hashLen < minLen || hashLen > 1024)
|
|
6292
|
+
throw new Error(`hashToPrivateScalar: expected ${minLen}-1024 bytes of input, got ${hashLen}`);
|
|
6276
6293
|
const num = isLE2 ? bytesToNumberLE(hash2) : bytesToNumberBE(hash2);
|
|
6277
|
-
return mod(num,
|
|
6294
|
+
return mod(num, groupOrder - _1n2) + _1n2;
|
|
6278
6295
|
}
|
|
6296
|
+
function equalBytes(b1, b2) {
|
|
6297
|
+
if (b1.length !== b2.length)
|
|
6298
|
+
return false;
|
|
6299
|
+
for (let i = 0; i < b1.length; i++)
|
|
6300
|
+
if (b1[i] !== b2[i])
|
|
6301
|
+
return false;
|
|
6302
|
+
return true;
|
|
6303
|
+
}
|
|
6304
|
+
function bitLen(n) {
|
|
6305
|
+
let len;
|
|
6306
|
+
for (len = 0; n > 0n; n >>= _1n2, len += 1)
|
|
6307
|
+
;
|
|
6308
|
+
return len;
|
|
6309
|
+
}
|
|
6310
|
+
var bitGet = (n, pos) => n >> BigInt(pos) & 1n;
|
|
6311
|
+
var bitSet = (n, pos, value) => n | (value ? _1n2 : _0n2) << BigInt(pos);
|
|
6279
6312
|
var bitMask = (n) => (_2n2 << BigInt(n - 1)) - _1n2;
|
|
6280
6313
|
|
|
6281
6314
|
// node_modules/@noble/curves/lib/esm/abstract/modular.js
|
|
@@ -6343,28 +6376,28 @@ var starknet = (() => {
|
|
|
6343
6376
|
}
|
|
6344
6377
|
const Q1div2 = (Q + _1n3) / _2n3;
|
|
6345
6378
|
return function tonelliSlow(Fp2, n) {
|
|
6346
|
-
if (Fp2.pow(n, legendreC)
|
|
6379
|
+
if (Fp2.pow(n, legendreC) === Fp2.negate(Fp2.ONE))
|
|
6347
6380
|
throw new Error("Cannot find square root");
|
|
6348
|
-
let
|
|
6349
|
-
let
|
|
6350
|
-
let
|
|
6351
|
-
let
|
|
6352
|
-
|
|
6353
|
-
|
|
6354
|
-
|
|
6355
|
-
let
|
|
6356
|
-
for (
|
|
6357
|
-
if (Fp2.equals(
|
|
6381
|
+
let r = S;
|
|
6382
|
+
let g = Fp2.pow(Fp2.mul(Fp2.ONE, Z), Q);
|
|
6383
|
+
let x = Fp2.pow(n, Q1div2);
|
|
6384
|
+
let b = Fp2.pow(n, Q);
|
|
6385
|
+
while (!Fp2.equals(b, Fp2.ONE)) {
|
|
6386
|
+
if (Fp2.equals(b, Fp2.ZERO))
|
|
6387
|
+
return Fp2.ZERO;
|
|
6388
|
+
let m = 1;
|
|
6389
|
+
for (let t2 = Fp2.square(b); m < r; m++) {
|
|
6390
|
+
if (Fp2.equals(t2, Fp2.ONE))
|
|
6358
6391
|
break;
|
|
6359
6392
|
t2 = Fp2.square(t2);
|
|
6360
6393
|
}
|
|
6361
|
-
|
|
6362
|
-
|
|
6363
|
-
|
|
6364
|
-
|
|
6365
|
-
|
|
6394
|
+
const ge = Fp2.pow(g, _1n3 << BigInt(r - m - 1));
|
|
6395
|
+
g = Fp2.square(ge);
|
|
6396
|
+
x = Fp2.mul(x, ge);
|
|
6397
|
+
b = Fp2.mul(b, g);
|
|
6398
|
+
r = m;
|
|
6366
6399
|
}
|
|
6367
|
-
return
|
|
6400
|
+
return x;
|
|
6368
6401
|
};
|
|
6369
6402
|
}
|
|
6370
6403
|
function FpSqrt(P) {
|
|
@@ -6461,10 +6494,10 @@ var starknet = (() => {
|
|
|
6461
6494
|
}, inverted);
|
|
6462
6495
|
return tmp;
|
|
6463
6496
|
}
|
|
6464
|
-
function Fp(ORDER,
|
|
6497
|
+
function Fp(ORDER, bitLen2, isLE2 = false, redef = {}) {
|
|
6465
6498
|
if (ORDER <= _0n3)
|
|
6466
6499
|
throw new Error(`Expected Fp ORDER > 0, got ${ORDER}`);
|
|
6467
|
-
const { nBitLength: BITS, nByteLength: BYTES } = nLength(ORDER,
|
|
6500
|
+
const { nBitLength: BITS, nByteLength: BYTES } = nLength(ORDER, bitLen2);
|
|
6468
6501
|
if (BYTES > 2048)
|
|
6469
6502
|
throw new Error("Field lengths over 2048 bytes are not supported");
|
|
6470
6503
|
const sqrtP = FpSqrt(ORDER);
|
|
@@ -6688,40 +6721,39 @@ var starknet = (() => {
|
|
|
6688
6721
|
super(message);
|
|
6689
6722
|
}
|
|
6690
6723
|
};
|
|
6691
|
-
|
|
6692
|
-
|
|
6693
|
-
|
|
6694
|
-
|
|
6695
|
-
|
|
6696
|
-
|
|
6697
|
-
|
|
6698
|
-
|
|
6699
|
-
|
|
6700
|
-
|
|
6701
|
-
|
|
6702
|
-
|
|
6703
|
-
|
|
6704
|
-
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
6710
|
-
|
|
6711
|
-
|
|
6712
|
-
|
|
6713
|
-
|
|
6714
|
-
|
|
6715
|
-
|
|
6716
|
-
|
|
6717
|
-
|
|
6718
|
-
|
|
6724
|
+
var DER = {
|
|
6725
|
+
slice(s) {
|
|
6726
|
+
return Number.parseInt(s[0], 16) >= 8 ? "00" + s : s;
|
|
6727
|
+
},
|
|
6728
|
+
parseInt(data) {
|
|
6729
|
+
if (data.length < 2 || data[0] !== 2) {
|
|
6730
|
+
throw new DERError(`Invalid signature integer tag: ${bytesToHex(data)}`);
|
|
6731
|
+
}
|
|
6732
|
+
const len = data[1];
|
|
6733
|
+
const res = data.subarray(2, len + 2);
|
|
6734
|
+
if (!len || res.length !== len) {
|
|
6735
|
+
throw new DERError(`Invalid signature integer: wrong length`);
|
|
6736
|
+
}
|
|
6737
|
+
if (res[0] === 0 && res[1] <= 127) {
|
|
6738
|
+
throw new DERError("Invalid signature integer: trailing length");
|
|
6739
|
+
}
|
|
6740
|
+
return { data: bytesToNumberBE(res), left: data.subarray(len + 2) };
|
|
6741
|
+
},
|
|
6742
|
+
parseSig(data) {
|
|
6743
|
+
if (data.length < 2 || data[0] != 48) {
|
|
6744
|
+
throw new DERError(`Invalid signature tag: ${bytesToHex(data)}`);
|
|
6745
|
+
}
|
|
6746
|
+
if (data[1] !== data.length - 2) {
|
|
6747
|
+
throw new DERError("Invalid signature: incorrect length");
|
|
6748
|
+
}
|
|
6749
|
+
const { data: r, left: sBytes } = DER.parseInt(data.subarray(2));
|
|
6750
|
+
const { data: s, left: rBytesLeft } = DER.parseInt(sBytes);
|
|
6751
|
+
if (rBytesLeft.length) {
|
|
6752
|
+
throw new DERError(`Invalid signature: left bytes after parsing: ${bytesToHex(rBytesLeft)}`);
|
|
6753
|
+
}
|
|
6754
|
+
return { r, s };
|
|
6719
6755
|
}
|
|
6720
|
-
|
|
6721
|
-
}
|
|
6722
|
-
var _0n5 = BigInt(0);
|
|
6723
|
-
var _1n5 = BigInt(1);
|
|
6724
|
-
var _3n2 = BigInt(3);
|
|
6756
|
+
};
|
|
6725
6757
|
function validatePointOpts(curve) {
|
|
6726
6758
|
const opts = validateOpts(curve);
|
|
6727
6759
|
const Fp2 = opts.Fp;
|
|
@@ -6752,11 +6784,12 @@ var starknet = (() => {
|
|
|
6752
6784
|
validateHTFOpts(opts.htfDefaults);
|
|
6753
6785
|
return Object.freeze({ ...opts });
|
|
6754
6786
|
}
|
|
6787
|
+
var _0n5 = BigInt(0);
|
|
6788
|
+
var _1n5 = BigInt(1);
|
|
6789
|
+
var _3n2 = BigInt(3);
|
|
6755
6790
|
function weierstrassPoints(opts) {
|
|
6756
6791
|
const CURVE2 = validatePointOpts(opts);
|
|
6757
|
-
const Fp2 = CURVE2
|
|
6758
|
-
const { nByteLength, nBitLength: nBitLength2 } = CURVE2;
|
|
6759
|
-
const groupLen = nByteLength;
|
|
6792
|
+
const { Fp: Fp2 } = CURVE2;
|
|
6760
6793
|
function weierstrassEquation(x) {
|
|
6761
6794
|
const { a, b } = CURVE2;
|
|
6762
6795
|
const x2 = Fp2.square(x);
|
|
@@ -6767,13 +6800,13 @@ var starknet = (() => {
|
|
|
6767
6800
|
return _0n5 < num && num < CURVE2.n;
|
|
6768
6801
|
}
|
|
6769
6802
|
function normalizePrivateKey2(key) {
|
|
6770
|
-
|
|
6771
|
-
|
|
6772
|
-
|
|
6803
|
+
const { normalizePrivateKey: custom, nByteLength: groupLen, wrapPrivateKey, n: order } = CURVE2;
|
|
6804
|
+
if (typeof custom === "function")
|
|
6805
|
+
key = custom(key);
|
|
6773
6806
|
let num;
|
|
6774
6807
|
if (typeof key === "bigint") {
|
|
6775
6808
|
num = key;
|
|
6776
|
-
} else if (
|
|
6809
|
+
} else if (isPositiveInt(key)) {
|
|
6777
6810
|
num = BigInt(key);
|
|
6778
6811
|
} else if (typeof key === "string") {
|
|
6779
6812
|
if (key.length !== 2 * groupLen)
|
|
@@ -6786,14 +6819,14 @@ var starknet = (() => {
|
|
|
6786
6819
|
} else {
|
|
6787
6820
|
throw new TypeError("Expected valid private key");
|
|
6788
6821
|
}
|
|
6789
|
-
if (
|
|
6790
|
-
num = mod(num,
|
|
6822
|
+
if (wrapPrivateKey)
|
|
6823
|
+
num = mod(num, order);
|
|
6791
6824
|
if (!isWithinCurveOrder(num))
|
|
6792
6825
|
throw new Error("Expected private key: 0 < key < n");
|
|
6793
6826
|
return num;
|
|
6794
6827
|
}
|
|
6795
6828
|
function normalizeScalar(num) {
|
|
6796
|
-
if (
|
|
6829
|
+
if (isPositiveInt(num))
|
|
6797
6830
|
return BigInt(num);
|
|
6798
6831
|
if (typeof num === "bigint" && isWithinCurveOrder(num))
|
|
6799
6832
|
return num;
|
|
@@ -6831,9 +6864,6 @@ var starknet = (() => {
|
|
|
6831
6864
|
negate() {
|
|
6832
6865
|
return new ProjectivePoint2(this.x, Fp2.negate(this.y), this.z);
|
|
6833
6866
|
}
|
|
6834
|
-
doubleAdd() {
|
|
6835
|
-
return this.add(this);
|
|
6836
|
-
}
|
|
6837
6867
|
double() {
|
|
6838
6868
|
const { a, b } = CURVE2;
|
|
6839
6869
|
const b3 = Fp2.mul(b, 3n);
|
|
@@ -7002,23 +7032,26 @@ var starknet = (() => {
|
|
|
7002
7032
|
return new Point2(ax, ay);
|
|
7003
7033
|
}
|
|
7004
7034
|
isTorsionFree() {
|
|
7005
|
-
|
|
7035
|
+
const { h: cofactor, isTorsionFree } = CURVE2;
|
|
7036
|
+
if (cofactor === _1n5)
|
|
7006
7037
|
return true;
|
|
7007
|
-
if (
|
|
7008
|
-
return
|
|
7009
|
-
throw new Error("
|
|
7038
|
+
if (isTorsionFree)
|
|
7039
|
+
return isTorsionFree(ProjectivePoint2, this);
|
|
7040
|
+
throw new Error("isTorsionFree() has not been declared for the elliptic curve");
|
|
7010
7041
|
}
|
|
7011
7042
|
clearCofactor() {
|
|
7012
|
-
|
|
7043
|
+
const { h: cofactor, clearCofactor } = CURVE2;
|
|
7044
|
+
if (cofactor === _1n5)
|
|
7013
7045
|
return this;
|
|
7014
|
-
if (
|
|
7015
|
-
return
|
|
7046
|
+
if (clearCofactor)
|
|
7047
|
+
return clearCofactor(ProjectivePoint2, this);
|
|
7016
7048
|
return this.multiplyUnsafe(CURVE2.h);
|
|
7017
7049
|
}
|
|
7018
7050
|
}
|
|
7019
7051
|
ProjectivePoint2.BASE = new ProjectivePoint2(CURVE2.Gx, CURVE2.Gy, Fp2.ONE);
|
|
7020
7052
|
ProjectivePoint2.ZERO = new ProjectivePoint2(Fp2.ZERO, Fp2.ONE, Fp2.ZERO);
|
|
7021
|
-
const
|
|
7053
|
+
const _bits = CURVE2.nBitLength;
|
|
7054
|
+
const wnaf = wNAF(ProjectivePoint2, CURVE2.endo ? Math.ceil(_bits / 2) : _bits);
|
|
7022
7055
|
function assertPrjPoint(other) {
|
|
7023
7056
|
if (!(other instanceof ProjectivePoint2))
|
|
7024
7057
|
throw new TypeError("ProjectivePoint expected");
|
|
@@ -7058,7 +7091,7 @@ var starknet = (() => {
|
|
|
7058
7091
|
if (this.equals(Point2.ZERO)) {
|
|
7059
7092
|
if (CURVE2.allowInfinityPoint)
|
|
7060
7093
|
return;
|
|
7061
|
-
throw new Error("Point
|
|
7094
|
+
throw new Error("Point at infinity");
|
|
7062
7095
|
}
|
|
7063
7096
|
const msg = "Point is not on elliptic curve";
|
|
7064
7097
|
const { x, y } = this;
|
|
@@ -7079,50 +7112,54 @@ var starknet = (() => {
|
|
|
7079
7112
|
negate() {
|
|
7080
7113
|
return new Point2(this.x, Fp2.negate(this.y));
|
|
7081
7114
|
}
|
|
7115
|
+
toProj() {
|
|
7116
|
+
return ProjectivePoint2.fromAffine(this);
|
|
7117
|
+
}
|
|
7082
7118
|
double() {
|
|
7083
|
-
return
|
|
7119
|
+
return this.toProj().double().toAffine();
|
|
7084
7120
|
}
|
|
7085
7121
|
add(other) {
|
|
7086
|
-
return
|
|
7122
|
+
return this.toProj().add(ProjectivePoint2.fromAffine(other)).toAffine();
|
|
7087
7123
|
}
|
|
7088
7124
|
subtract(other) {
|
|
7089
7125
|
return this.add(other.negate());
|
|
7090
7126
|
}
|
|
7091
7127
|
multiply(scalar) {
|
|
7092
|
-
return
|
|
7128
|
+
return this.toProj().multiply(scalar, this).toAffine();
|
|
7093
7129
|
}
|
|
7094
7130
|
multiplyUnsafe(scalar) {
|
|
7095
|
-
return
|
|
7131
|
+
return this.toProj().multiplyUnsafe(scalar).toAffine();
|
|
7096
7132
|
}
|
|
7097
7133
|
clearCofactor() {
|
|
7098
|
-
return
|
|
7134
|
+
return this.toProj().clearCofactor().toAffine();
|
|
7099
7135
|
}
|
|
7100
7136
|
isTorsionFree() {
|
|
7101
|
-
return
|
|
7137
|
+
return this.toProj().isTorsionFree();
|
|
7102
7138
|
}
|
|
7103
7139
|
multiplyAndAddUnsafe(Q, a, b) {
|
|
7104
|
-
const P =
|
|
7140
|
+
const P = this.toProj();
|
|
7105
7141
|
const aP = a === _0n5 || a === _1n5 || this !== Point2.BASE ? P.multiplyUnsafe(a) : P.multiply(a);
|
|
7106
7142
|
const bQ = ProjectivePoint2.fromAffine(Q).multiplyUnsafe(b);
|
|
7107
7143
|
const sum = aP.add(bQ);
|
|
7108
7144
|
return sum.equals(ProjectivePoint2.ZERO) ? void 0 : sum.toAffine();
|
|
7109
7145
|
}
|
|
7110
7146
|
static hashToCurve(msg, options) {
|
|
7111
|
-
|
|
7112
|
-
|
|
7147
|
+
const { mapToCurve } = CURVE2;
|
|
7148
|
+
if (!mapToCurve)
|
|
7149
|
+
throw new Error("CURVE.mapToCurve() has not been defined");
|
|
7113
7150
|
msg = ensureBytes(msg);
|
|
7114
7151
|
const u = hash_to_field(msg, 2, { ...CURVE2.htfDefaults, ...options });
|
|
7115
|
-
const { x: x0, y: y0 } =
|
|
7116
|
-
const { x: x1, y: y1 } =
|
|
7117
|
-
|
|
7118
|
-
return p;
|
|
7152
|
+
const { x: x0, y: y0 } = mapToCurve(u[0]);
|
|
7153
|
+
const { x: x1, y: y1 } = mapToCurve(u[1]);
|
|
7154
|
+
return new Point2(x0, y0).add(new Point2(x1, y1)).clearCofactor();
|
|
7119
7155
|
}
|
|
7120
7156
|
static encodeToCurve(msg, options) {
|
|
7121
|
-
|
|
7122
|
-
|
|
7157
|
+
const { mapToCurve } = CURVE2;
|
|
7158
|
+
if (!mapToCurve)
|
|
7159
|
+
throw new Error("CURVE.mapToCurve() has not been defined");
|
|
7123
7160
|
msg = ensureBytes(msg);
|
|
7124
7161
|
const u = hash_to_field(msg, 1, { ...CURVE2.htfDefaults, ...options });
|
|
7125
|
-
const { x, y } =
|
|
7162
|
+
const { x, y } = mapToCurve(u[0]);
|
|
7126
7163
|
return new Point2(x, y).clearCofactor();
|
|
7127
7164
|
}
|
|
7128
7165
|
}
|
|
@@ -7138,7 +7175,7 @@ var starknet = (() => {
|
|
|
7138
7175
|
}
|
|
7139
7176
|
function validateOpts2(curve) {
|
|
7140
7177
|
const opts = validateOpts(curve);
|
|
7141
|
-
if (typeof opts.hash !== "function" || !
|
|
7178
|
+
if (typeof opts.hash !== "function" || !isPositiveInt(opts.hash.outputLen))
|
|
7142
7179
|
throw new Error("Invalid hash function");
|
|
7143
7180
|
if (typeof opts.hmac !== "function")
|
|
7144
7181
|
throw new Error("Invalid hmac function");
|
|
@@ -7202,10 +7239,12 @@ var starknet = (() => {
|
|
|
7202
7239
|
const { Point: Point2, ProjectivePoint: ProjectivePoint2, normalizePrivateKey: normalizePrivateKey2, weierstrassEquation, isWithinCurveOrder } = weierstrassPoints({
|
|
7203
7240
|
...CURVE2,
|
|
7204
7241
|
toBytes(c, point, isCompressed) {
|
|
7242
|
+
const x = Fp2.toBytes(point.x);
|
|
7243
|
+
const cat = concatBytes2;
|
|
7205
7244
|
if (isCompressed) {
|
|
7206
|
-
return
|
|
7245
|
+
return cat(Uint8Array.from([point.hasEvenY() ? 2 : 3]), x);
|
|
7207
7246
|
} else {
|
|
7208
|
-
return
|
|
7247
|
+
return cat(Uint8Array.from([4]), x, Fp2.toBytes(point.y));
|
|
7209
7248
|
}
|
|
7210
7249
|
},
|
|
7211
7250
|
fromBytes(bytes2) {
|
|
@@ -7255,16 +7294,17 @@ var starknet = (() => {
|
|
|
7255
7294
|
function normalizeS(s) {
|
|
7256
7295
|
return isBiggerThanHalfOrder(s) ? mod(-s, CURVE_ORDER) : s;
|
|
7257
7296
|
}
|
|
7297
|
+
function bits2int_2(bytes2) {
|
|
7298
|
+
const delta = bytes2.length * 8 - CURVE2.nBitLength;
|
|
7299
|
+
const num = bytesToNumberBE(bytes2);
|
|
7300
|
+
return delta > 0 ? num >> BigInt(delta) : num;
|
|
7301
|
+
}
|
|
7258
7302
|
function _truncateHash(hash2, truncateOnly = false) {
|
|
7259
|
-
const
|
|
7260
|
-
|
|
7261
|
-
|
|
7262
|
-
|
|
7263
|
-
|
|
7264
|
-
h = h >> BigInt(delta);
|
|
7265
|
-
if (!truncateOnly && h >= n)
|
|
7266
|
-
h -= n;
|
|
7267
|
-
return h;
|
|
7303
|
+
const h = bits2int_2(hash2);
|
|
7304
|
+
if (truncateOnly)
|
|
7305
|
+
return h;
|
|
7306
|
+
const { n } = CURVE2;
|
|
7307
|
+
return h >= n ? h - n : h;
|
|
7268
7308
|
}
|
|
7269
7309
|
const truncateHash = CURVE2.truncateHash || _truncateHash;
|
|
7270
7310
|
class Signature3 {
|
|
@@ -7280,15 +7320,17 @@ var starknet = (() => {
|
|
|
7280
7320
|
if (typeof hex !== "string" && !arr)
|
|
7281
7321
|
throw new TypeError(`${name}: Expected string or Uint8Array`);
|
|
7282
7322
|
const str = arr ? bytesToHex(hex) : hex;
|
|
7283
|
-
|
|
7284
|
-
|
|
7285
|
-
|
|
7323
|
+
const gl = CURVE2.nByteLength * 2;
|
|
7324
|
+
if (str.length !== 2 * gl)
|
|
7325
|
+
throw new Error(`${name}: Expected ${gl / 2}-byte hex`);
|
|
7326
|
+
const slice = (from, to) => hexToNumber(str.slice(from, to));
|
|
7327
|
+
return new Signature3(slice(0, gl), slice(gl, 2 * gl));
|
|
7286
7328
|
}
|
|
7287
7329
|
static fromDER(hex) {
|
|
7288
7330
|
const arr = hex instanceof Uint8Array;
|
|
7289
7331
|
if (typeof hex !== "string" && !arr)
|
|
7290
7332
|
throw new TypeError(`Signature.fromDER: Expected string or Uint8Array`);
|
|
7291
|
-
const { r, s } =
|
|
7333
|
+
const { r, s } = DER.parseSig(arr ? hex : hexToBytes(hex));
|
|
7292
7334
|
return new Signature3(r, s);
|
|
7293
7335
|
}
|
|
7294
7336
|
assertValidity() {
|
|
@@ -7305,15 +7347,18 @@ var starknet = (() => {
|
|
|
7305
7347
|
const { r, s, recovery } = this;
|
|
7306
7348
|
if (recovery == null)
|
|
7307
7349
|
throw new Error("Cannot recover: recovery bit is not present");
|
|
7308
|
-
if (
|
|
7350
|
+
if (![0, 1, 2, 3].includes(recovery))
|
|
7309
7351
|
throw new Error("Cannot recover: invalid recovery bit");
|
|
7310
7352
|
const h = truncateHash(ensureBytes(msgHash));
|
|
7311
7353
|
const { n } = CURVE2;
|
|
7312
|
-
const
|
|
7354
|
+
const radj = recovery === 2 || recovery === 3 ? r + n : r;
|
|
7355
|
+
if (radj >= Fp2.ORDER)
|
|
7356
|
+
throw new Error("Cannot recover: bit 2/3 is invalid with current r");
|
|
7357
|
+
const rinv = invert(radj, n);
|
|
7313
7358
|
const u1 = mod(-h * rinv, n);
|
|
7314
7359
|
const u2 = mod(s * rinv, n);
|
|
7315
7360
|
const prefix = recovery & 1 ? "03" : "02";
|
|
7316
|
-
const R = Point2.fromHex(prefix + numToFieldStr(
|
|
7361
|
+
const R = Point2.fromHex(prefix + numToFieldStr(radj));
|
|
7317
7362
|
const Q = Point2.BASE.multiplyAndAddUnsafe(R, u1, u2);
|
|
7318
7363
|
if (!Q)
|
|
7319
7364
|
throw new Error("Cannot recover: point at infinify");
|
|
@@ -7326,17 +7371,18 @@ var starknet = (() => {
|
|
|
7326
7371
|
normalizeS() {
|
|
7327
7372
|
return this.hasHighS() ? new Signature3(this.r, mod(-this.s, CURVE_ORDER), this.recovery) : this;
|
|
7328
7373
|
}
|
|
7329
|
-
toDERRawBytes(
|
|
7330
|
-
return hexToBytes(this.toDERHex(
|
|
7331
|
-
}
|
|
7332
|
-
toDERHex(
|
|
7333
|
-
const
|
|
7334
|
-
|
|
7335
|
-
|
|
7336
|
-
const
|
|
7337
|
-
const
|
|
7338
|
-
const sLen =
|
|
7339
|
-
const
|
|
7374
|
+
toDERRawBytes() {
|
|
7375
|
+
return hexToBytes(this.toDERHex());
|
|
7376
|
+
}
|
|
7377
|
+
toDERHex() {
|
|
7378
|
+
const { numberToHexUnpadded: toHex2 } = utils_exports;
|
|
7379
|
+
const sHex = DER.slice(toHex2(this.s));
|
|
7380
|
+
const rHex = DER.slice(toHex2(this.r));
|
|
7381
|
+
const sHexL = sHex.length / 2;
|
|
7382
|
+
const rHexL = rHex.length / 2;
|
|
7383
|
+
const sLen = toHex2(sHexL);
|
|
7384
|
+
const rLen = toHex2(rHexL);
|
|
7385
|
+
const length = toHex2(rHexL + sHexL + 4);
|
|
7340
7386
|
return `30${length}02${rLen}${rHex}02${sLen}${sHex}`;
|
|
7341
7387
|
}
|
|
7342
7388
|
toCompactRawBytes() {
|
|
@@ -7347,8 +7393,6 @@ var starknet = (() => {
|
|
|
7347
7393
|
}
|
|
7348
7394
|
}
|
|
7349
7395
|
const utils2 = {
|
|
7350
|
-
mod: (n, modulo = Fp2.ORDER) => mod(n, modulo),
|
|
7351
|
-
invert: Fp2.invert,
|
|
7352
7396
|
isValidPrivateKey(privateKey) {
|
|
7353
7397
|
try {
|
|
7354
7398
|
normalizePrivateKey2(privateKey);
|
|
@@ -7398,8 +7442,12 @@ var starknet = (() => {
|
|
|
7398
7442
|
return b.multiply(normalizePrivateKey2(privateA)).toRawBytes(isCompressed);
|
|
7399
7443
|
}
|
|
7400
7444
|
function bits2int(bytes2) {
|
|
7401
|
-
const
|
|
7402
|
-
|
|
7445
|
+
const { nByteLength } = CURVE2;
|
|
7446
|
+
if (!(bytes2 instanceof Uint8Array))
|
|
7447
|
+
throw new Error("Expected Uint8Array");
|
|
7448
|
+
const slice = bytes2.length > nByteLength ? bytes2.slice(0, nByteLength) : bytes2;
|
|
7449
|
+
let num = bytesToNumberBE(slice);
|
|
7450
|
+
return num;
|
|
7403
7451
|
}
|
|
7404
7452
|
function bits2octets(bytes2) {
|
|
7405
7453
|
const z1 = bits2int(bytes2);
|
|
@@ -7448,7 +7496,8 @@ var starknet = (() => {
|
|
|
7448
7496
|
}
|
|
7449
7497
|
return new Signature3(r, normS, recovery);
|
|
7450
7498
|
}
|
|
7451
|
-
|
|
7499
|
+
const defaultSigOpts = { lowS: CURVE2.lowS };
|
|
7500
|
+
function sign(msgHash, privKey, opts = defaultSigOpts) {
|
|
7452
7501
|
const { seed, m, d } = initSigArgs(msgHash, privKey, opts.extraEntropy);
|
|
7453
7502
|
const drbg = new HmacDrbg(CURVE2.hash.outputLen, CURVE2.nByteLength, CURVE2.hmac);
|
|
7454
7503
|
drbg.reseedSync(seed);
|
|
@@ -7457,6 +7506,9 @@ var starknet = (() => {
|
|
|
7457
7506
|
drbg.reseedSync();
|
|
7458
7507
|
return sig;
|
|
7459
7508
|
}
|
|
7509
|
+
function signUnhashed(msg, privKey, opts = defaultSigOpts) {
|
|
7510
|
+
return sign(CURVE2.hash(ensureBytes(msg)), privKey, opts);
|
|
7511
|
+
}
|
|
7460
7512
|
Point2.BASE._setWindowSize(8);
|
|
7461
7513
|
function verify(signature, msgHash, publicKey, opts = { lowS: CURVE2.lowS }) {
|
|
7462
7514
|
try {
|
|
@@ -7500,6 +7552,7 @@ var starknet = (() => {
|
|
|
7500
7552
|
getPublicKey,
|
|
7501
7553
|
getSharedSecret,
|
|
7502
7554
|
sign,
|
|
7555
|
+
signUnhashed,
|
|
7503
7556
|
verify,
|
|
7504
7557
|
Point: Point2,
|
|
7505
7558
|
ProjectivePoint: ProjectivePoint2,
|
|
@@ -7777,11 +7830,12 @@ var starknet = (() => {
|
|
|
7777
7830
|
function grindKey(seed) {
|
|
7778
7831
|
const _seed = ensureBytes0x(seed);
|
|
7779
7832
|
const sha256mask = 2n ** 256n;
|
|
7780
|
-
const
|
|
7833
|
+
const Fn = Fp(CURVE.n);
|
|
7834
|
+
const limit = sha256mask - Fn.create(sha256mask);
|
|
7781
7835
|
for (let i = 0; ; i++) {
|
|
7782
7836
|
const key = hashKeyWithIndex(_seed, i);
|
|
7783
7837
|
if (key < limit)
|
|
7784
|
-
return
|
|
7838
|
+
return Fn.create(key).toString(16);
|
|
7785
7839
|
}
|
|
7786
7840
|
}
|
|
7787
7841
|
function getStarkKey(privateKey) {
|
|
@@ -12411,7 +12465,7 @@ var starknet = (() => {
|
|
|
12411
12465
|
}
|
|
12412
12466
|
function getStarknetIdContract(chainId) {
|
|
12413
12467
|
const starknetIdMainnetContract = "0x6ac597f8116f886fa1c97a23fa4e08299975ecaf6b598873ca6792b9bbfb678";
|
|
12414
|
-
const starknetIdTestnetContract = "
|
|
12468
|
+
const starknetIdTestnetContract = "0x3bab268e932d2cecd1946f100ae67ce3dff9fd234119ea2f6da57d16d29fce";
|
|
12415
12469
|
switch (chainId) {
|
|
12416
12470
|
case "0x534e5f4d41494e" /* SN_MAIN */:
|
|
12417
12471
|
return starknetIdMainnetContract;
|
|
@@ -13495,9 +13549,6 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
13495
13549
|
// src/provider/index.ts
|
|
13496
13550
|
var defaultProvider = new Provider();
|
|
13497
13551
|
|
|
13498
|
-
// src/utils/calldata/index.ts
|
|
13499
|
-
var import_minimalistic_assert3 = __toESM(require_minimalistic_assert());
|
|
13500
|
-
|
|
13501
13552
|
// src/utils/calldata/formatter.ts
|
|
13502
13553
|
var guard = {
|
|
13503
13554
|
isBN: (data, type, key) => {
|
|
@@ -13723,27 +13774,26 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
13723
13774
|
}
|
|
13724
13775
|
|
|
13725
13776
|
// src/utils/calldata/validate.ts
|
|
13726
|
-
var import_minimalistic_assert2 = __toESM(require_minimalistic_assert());
|
|
13727
13777
|
var validateFelt = (parameter, input) => {
|
|
13728
|
-
(
|
|
13778
|
+
assert(
|
|
13729
13779
|
typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint",
|
|
13730
13780
|
`Validate: arg ${input.name} should be a felt (string, number, BigNumber)`
|
|
13731
13781
|
);
|
|
13732
13782
|
};
|
|
13733
13783
|
var validateStruct = (parameter, input, structs) => {
|
|
13734
|
-
(
|
|
13784
|
+
assert(
|
|
13735
13785
|
typeof parameter === "object" && !Array.isArray(parameter),
|
|
13736
13786
|
`Validate: arg ${input.name} is cairo type struct (${input.type}), and should be defined as js object (not array)`
|
|
13737
13787
|
);
|
|
13738
13788
|
structs[input.type].members.forEach(({ name }) => {
|
|
13739
|
-
(
|
|
13789
|
+
assert(
|
|
13740
13790
|
Object.keys(parameter).includes(name),
|
|
13741
13791
|
`Validate: arg ${input.name} should have a property ${name}`
|
|
13742
13792
|
);
|
|
13743
13793
|
});
|
|
13744
13794
|
};
|
|
13745
13795
|
var validateTuple = (parameter, input) => {
|
|
13746
|
-
(
|
|
13796
|
+
assert(
|
|
13747
13797
|
typeof parameter === "object" && !Array.isArray(parameter),
|
|
13748
13798
|
`Validate: arg ${input.name} should be a tuple (defined as object)`
|
|
13749
13799
|
);
|
|
@@ -13752,7 +13802,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
13752
13802
|
const baseType = input.type.replace("*", "");
|
|
13753
13803
|
if (isTypeFelt(baseType) && isLongText(parameter))
|
|
13754
13804
|
return;
|
|
13755
|
-
(
|
|
13805
|
+
assert(Array.isArray(parameter), `Validate: arg ${input.name} should be an Array`);
|
|
13756
13806
|
switch (true) {
|
|
13757
13807
|
case isTypeFelt(baseType):
|
|
13758
13808
|
parameter.forEach((param) => validateFelt(param, input));
|
|
@@ -13812,7 +13862,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
13812
13862
|
const isView = abi.stateMutability === "view";
|
|
13813
13863
|
return type === "INVOKE" ? !isView : isView;
|
|
13814
13864
|
}).map((abi) => abi.name);
|
|
13815
|
-
(
|
|
13865
|
+
assert(
|
|
13816
13866
|
invocableFunctionNames.includes(method),
|
|
13817
13867
|
`${type === "INVOKE" ? "invocable" : "viewable"} method not found in abi`
|
|
13818
13868
|
);
|
|
@@ -14011,7 +14061,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14011
14061
|
}
|
|
14012
14062
|
async call(method, args = [], options = { parseRequest: true, parseResponse: true, formatResponse: void 0 }) {
|
|
14013
14063
|
var _a;
|
|
14014
|
-
(
|
|
14064
|
+
assert(this.address !== null, "contract is not connected to an address");
|
|
14015
14065
|
const blockIdentifier = (options == null ? void 0 : options.blockIdentifier) || void 0;
|
|
14016
14066
|
let calldata = args[0];
|
|
14017
14067
|
if (options.parseRequest && !((_a = args[0]) == null ? void 0 : _a.compiled)) {
|
|
@@ -14039,7 +14089,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14039
14089
|
invoke(method, args = [], options = {
|
|
14040
14090
|
parseRequest: true
|
|
14041
14091
|
}) {
|
|
14042
|
-
(
|
|
14092
|
+
assert(this.address !== null, "contract is not connected to an address");
|
|
14043
14093
|
let calldata = args == null ? void 0 : args[0];
|
|
14044
14094
|
if (options.parseRequest && !(calldata == null ? void 0 : calldata.compiled)) {
|
|
14045
14095
|
const { inputs } = this.abi.find((abi) => abi.name === method);
|
|
@@ -14073,7 +14123,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14073
14123
|
}
|
|
14074
14124
|
async estimate(method, args = []) {
|
|
14075
14125
|
var _a;
|
|
14076
|
-
(
|
|
14126
|
+
assert(this.address !== null, "contract is not connected to an address");
|
|
14077
14127
|
if (!((_a = args[0]) == null ? void 0 : _a.compiled)) {
|
|
14078
14128
|
this.callData.validate("INVOKE", method, args);
|
|
14079
14129
|
}
|
|
@@ -14100,7 +14150,6 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14100
14150
|
};
|
|
14101
14151
|
|
|
14102
14152
|
// src/contract/contractFactory.ts
|
|
14103
|
-
var import_minimalistic_assert5 = __toESM(require_minimalistic_assert());
|
|
14104
14153
|
var ContractFactory = class {
|
|
14105
14154
|
constructor(compiledContract, classHash, account, abi = compiledContract.abi) {
|
|
14106
14155
|
this.abi = abi;
|
|
@@ -14138,7 +14187,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14138
14187
|
constructorCalldata,
|
|
14139
14188
|
salt: addressSalt
|
|
14140
14189
|
});
|
|
14141
|
-
(
|
|
14190
|
+
assert(Boolean(contract_address), "Deployment of the contract failed");
|
|
14142
14191
|
const contractInstance = new Contract(
|
|
14143
14192
|
this.compiledContract.abi,
|
|
14144
14193
|
contract_address,
|