starknet 11.9.0 → 11.9.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/index.d.ts CHANGED
@@ -925,7 +925,12 @@ type getEstimateFeeBulkOptions = {
925
925
  type ContractVersion = {
926
926
  /** version of the cairo language */
927
927
  cairo: CairoVersion;
928
- /** version of the cairo compiler used to compile the contract */
928
+ /**
929
+ * Major version of the Cairo compiler used to compile the contract ('0' for Cairo 0).
930
+ * `undefined` when unknown: for example with the option `compiler: false` of
931
+ * `getContractVersion`, or for a compiler that this version of starknet.js does not know yet,
932
+ * such as a future 3.x.
933
+ */
929
934
  compiler: CompilerVersion;
930
935
  };
931
936
 
@@ -1324,7 +1329,8 @@ declare abstract class ProviderInterface {
1324
1329
  * @param contractAddress string
1325
1330
  * @param classHash undefined
1326
1331
  * @param options - getContractVersionOptions
1327
- * - (optional) compiler - (default true) extract compiler version using type tactic from abi
1332
+ * - (optional) compiler - (default true) read the major version of the compiler in the Sierra
1333
+ * program (undefined when unknown, for example a compiler newer than 2.x)
1328
1334
  * - (optional) blockIdentifier - block identifier
1329
1335
  */
1330
1336
  abstract getContractVersion(contractAddress: BigNumberish, classHash?: undefined, options?: getContractVersionOptions): Promise<ContractVersion>;
@@ -1333,7 +1339,8 @@ declare abstract class ProviderInterface {
1333
1339
  * @param contractAddress undefined
1334
1340
  * @param classHash
1335
1341
  * @param options - getContractVersionOptions
1336
- * - (optional) compiler - (default true) extract compiler version using type tactic from abi
1342
+ * - (optional) compiler - (default true) read the major version of the compiler in the Sierra
1343
+ * program (undefined when unknown, for example a compiler newer than 2.x)
1337
1344
  * - (optional) blockIdentifier - block identifier
1338
1345
  */
1339
1346
  abstract getContractVersion(contractAddress: undefined, classHash: BigNumberish, options?: getContractVersionOptions): Promise<ContractVersion>;
@@ -10872,10 +10879,21 @@ declare function isCairo1Abi(abi: Abi): boolean;
10872
10879
  */
10873
10880
  declare function isTypeNonZero(type: string): boolean;
10874
10881
  /**
10875
- * Return ContractVersion (Abi version) based on Abi
10876
- * or undefined for unknown version
10877
- * @param abi
10878
- * @returns string
10882
+ * Guess the Cairo version and the compiler version of a contract from the shape of its abi.
10883
+ *
10884
+ * The compiler version is only a guess: '2' when the abi has an `interface` entry, '1' for
10885
+ * another Cairo 1 abi. The guess is wrong for a contract compiled by Cairo 2 that has no
10886
+ * `interface` entry (no external function, or functions declared one by one with
10887
+ * `#[external(v0)]`): the answer is '1'.
10888
+ * For a declared class, `provider.getContractVersion` gives the real compiler version: it reads
10889
+ * it in the Sierra program.
10890
+ * @param abi the abi of the contract
10891
+ * @returns the versions; `undefined` when the abi does not tell
10892
+ * @example
10893
+ * ```typescript
10894
+ * const version = cairo.getAbiContractVersion(myAbi);
10895
+ * // version = { cairo: '1', compiler: '2' }
10896
+ * ```
10879
10897
  */
10880
10898
  declare function getAbiContractVersion(abi: Abi): ContractVersion;
10881
10899
  /**
@@ -16119,7 +16137,9 @@ declare class CairoEthAddress {
16119
16137
  }
16120
16138
 
16121
16139
  /**
16122
- * The largest value a Secp256k1Point can carry : both coordinates at their maximum, 512 bits.
16140
+ * The largest number the 512 bits of a Secp256k1Point can hold : both coordinates at their
16141
+ * maximum. It is only a bound : a point must also be on the curve, and this value is not, so
16142
+ * `new CairoSecp256k1Point(SECP256K1_POINT_MAX)` throws.
16123
16143
  * @example
16124
16144
  * ```typescript
16125
16145
  * const result = SECP256K1_POINT_MAX === (1n << 512n) - 1n;
@@ -16154,17 +16174,33 @@ interface Secp256k1PointStruct {
16154
16174
  * class accepts is the 512-bit concatenation `x || y`, x in the upper half : that is the shape an
16155
16175
  * uncompressed public key already has once its `04` prefix is dropped.
16156
16176
  *
16157
- * Both ways in are supported : one number, or the four limbs directly, which is how a response is
16158
- * read back.
16177
+ * Both ways in are supported : one number, or the four limbs directly, in the order a call carries
16178
+ * them.
16179
+ *
16180
+ * What the caller passes in is checked as soon as the point is built : it must be on the curve, or
16181
+ * be (0, 0), which stands for the point at infinity, since a contract refuses anything else. A
16182
+ * point read from a contract response is taken as it comes, without this check.
16159
16183
  * @example
16160
16184
  * ```typescript
16161
- * // one number, x in the upper 256 bits
16162
- * const point = new CairoSecp256k1Point(1n);
16163
- * point.toApiRequest(); // ["0", "0", "1", "0"] x = 0, y = 1
16185
+ * // G, the generator of the curve, as one number : x in the upper 256 bits, y in the lower ones
16186
+ * const G =
16187
+ * 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8n;
16188
+ * const point = new CairoSecp256k1Point(G);
16189
+ * point.toStruct();
16190
+ * // { xLow: "0x29bfcdb2dce28d959f2815b16f81798", xHigh: "0x79be667ef9dcbbac55a06295ce870b07",
16191
+ * // yLow: "0xfd17b448a68554199c47d08ffb10d4b8", yHigh: "0x483ada7726a3c4655da4fbfc0e1108a8" }
16192
+ *
16193
+ * // the same point from its four limbs, as a call carries them
16194
+ * const same = new CairoSecp256k1Point(
16195
+ * '0x29bfcdb2dce28d959f2815b16f81798',
16196
+ * '0x79be667ef9dcbbac55a06295ce870b07',
16197
+ * '0xfd17b448a68554199c47d08ffb10d4b8',
16198
+ * '0x483ada7726a3c4655da4fbfc0e1108a8'
16199
+ * );
16200
+ * same.toBigInt() === G; // true
16164
16201
  *
16165
- * // the four limbs, as a call carries them
16166
- * const same = new CairoSecp256k1Point(0, 0, 1, 0);
16167
- * same.toBigInt(); // 1n
16202
+ * new CairoSecp256k1Point(1n); // x = 0, y = 1
16203
+ * // throws Error("Secp256k1Point: this point is not on the secp256k1 curve (y^2 must equal x^3 + 7 modulo p), so a contract would refuse it")
16168
16204
  * ```
16169
16205
  */
16170
16206
  declare class CairoSecp256k1Point {
@@ -16172,8 +16208,9 @@ declare class CairoSecp256k1Point {
16172
16208
  * The low 128 bits of the x coordinate.
16173
16209
  * @example
16174
16210
  * ```typescript
16175
- * const result = new CairoSecp256k1Point({ xLow: 1, xHigh: 2, yLow: 3, yHigh: 4 }).xLow;
16176
- * // result = 1n
16211
+ * // G, the generator of the curve, as in the example of the class
16212
+ * const result = new CairoSecp256k1Point(G).xLow;
16213
+ * // result = 0x29bfcdb2dce28d959f2815b16f81798n
16177
16214
  * ```
16178
16215
  */
16179
16216
  xLow: bigint;
@@ -16181,8 +16218,9 @@ declare class CairoSecp256k1Point {
16181
16218
  * The high 128 bits of the x coordinate.
16182
16219
  * @example
16183
16220
  * ```typescript
16184
- * const result = new CairoSecp256k1Point({ xLow: 1, xHigh: 2, yLow: 3, yHigh: 4 }).xHigh;
16185
- * // result = 2n
16221
+ * // G, the generator of the curve, as in the example of the class
16222
+ * const result = new CairoSecp256k1Point(G).xHigh;
16223
+ * // result = 0x79be667ef9dcbbac55a06295ce870b07n
16186
16224
  * ```
16187
16225
  */
16188
16226
  xHigh: bigint;
@@ -16190,8 +16228,9 @@ declare class CairoSecp256k1Point {
16190
16228
  * The low 128 bits of the y coordinate.
16191
16229
  * @example
16192
16230
  * ```typescript
16193
- * const result = new CairoSecp256k1Point({ xLow: 1, xHigh: 2, yLow: 3, yHigh: 4 }).yLow;
16194
- * // result = 3n
16231
+ * // G, the generator of the curve, as in the example of the class
16232
+ * const result = new CairoSecp256k1Point(G).yLow;
16233
+ * // result = 0xfd17b448a68554199c47d08ffb10d4b8n
16195
16234
  * ```
16196
16235
  */
16197
16236
  yLow: bigint;
@@ -16199,8 +16238,9 @@ declare class CairoSecp256k1Point {
16199
16238
  * The high 128 bits of the y coordinate.
16200
16239
  * @example
16201
16240
  * ```typescript
16202
- * const result = new CairoSecp256k1Point({ xLow: 1, xHigh: 2, yLow: 3, yHigh: 4 }).yHigh;
16203
- * // result = 4n
16241
+ * // G, the generator of the curve, as in the example of the class
16242
+ * const result = new CairoSecp256k1Point(G).yHigh;
16243
+ * // result = 0x483ada7726a3c4655da4fbfc0e1108a8n
16204
16244
  * ```
16205
16245
  */
16206
16246
  yHigh: bigint;
@@ -16222,17 +16262,22 @@ declare class CairoSecp256k1Point {
16222
16262
  */
16223
16263
  constructor(xLow: BigNumberish, xHigh: BigNumberish, yLow: BigNumberish, yHigh: BigNumberish);
16224
16264
  /**
16225
- * Throw unless the value can be carried by a Secp256k1Point, and return it as a number.
16265
+ * Throw unless the value is a point that a contract accepts, and return it as a number.
16266
+ *
16267
+ * The value must fit in 512 bits, and the point it stands for must be on the curve, or be (0, 0),
16268
+ * the point at infinity.
16226
16269
  *
16227
16270
  * Unlike the other classes here this one gives the number back rather than returning nothing :
16228
16271
  * the constructor needs it, and computing it twice would mean splitting a 512-bit value twice.
16229
16272
  * @param {BigNumberish} input the 512-bit value to check
16230
16273
  * @returns {bigint} the value, once checked
16231
- * @throws {Error} when the value is null, undefined, text, `'0x'`, of an unread type, a decimal number, or outside [0, 2^512 - 1]
16274
+ * @throws {Error} when the value is null, undefined, text, `'0x'`, of an unread type, a decimal number, or outside [0, 2^512 - 1], or when the point is not on the curve
16232
16275
  * @example
16233
16276
  * ```typescript
16234
- * const result = CairoSecp256k1Point.validate('0x1234');
16235
- * // result = 4660n
16277
+ * const result = CairoSecp256k1Point.validate(0n);
16278
+ * // result = 0n (0, 0), the point at infinity
16279
+ * CairoSecp256k1Point.validate('0x1234');
16280
+ * // throws Error("Secp256k1Point: this point is not on the secp256k1 curve (y^2 must equal x^3 + 7 modulo p), so a contract would refuse it")
16236
16281
  * CairoSecp256k1Point.validate(SECP256K1_POINT_MAX + 1n);
16237
16282
  * // throws Error("input is bigger than SECP256K1_POINT_MAX")
16238
16283
  * CairoSecp256k1Point.validate('abc');
@@ -16243,17 +16288,27 @@ declare class CairoSecp256k1Point {
16243
16288
  */
16244
16289
  static validate(input: BigNumberish | unknown): bigint;
16245
16290
  /**
16246
- * Throw unless the four limbs can each be carried by 128 bits, and return them as numbers.
16291
+ * Throw unless the four limbs each fit in 128 bits and together make a point that a contract
16292
+ * accepts, and return them as numbers.
16247
16293
  * @param {BigNumberish} xLow the low 128 bits of x
16248
16294
  * @param {BigNumberish} xHigh the high 128 bits of x
16249
16295
  * @param {BigNumberish} yLow the low 128 bits of y
16250
16296
  * @param {BigNumberish} yHigh the high 128 bits of y
16251
16297
  * @returns {{xLow: bigint, xHigh: bigint, yLow: bigint, yHigh: bigint}} the four limbs, checked
16252
- * @throws {Error} when a limb is null, undefined, text, `'0x'`, not a number, a decimal number, negative, or wider than 128 bits
16298
+ * @throws {Error} when a limb is null, undefined, text, `'0x'`, not a number, a decimal number, negative, or wider than 128 bits, or when the point is not on the curve
16253
16299
  * @example
16254
16300
  * ```typescript
16255
- * const result = CairoSecp256k1Point.validateProps(1, 2, 3, 4);
16256
- * // result = { xLow: 1n, xHigh: 2n, yLow: 3n, yHigh: 4n }
16301
+ * // G, the generator of the curve
16302
+ * const result = CairoSecp256k1Point.validateProps(
16303
+ * '0x29bfcdb2dce28d959f2815b16f81798',
16304
+ * '0x79be667ef9dcbbac55a06295ce870b07',
16305
+ * '0xfd17b448a68554199c47d08ffb10d4b8',
16306
+ * '0x483ada7726a3c4655da4fbfc0e1108a8'
16307
+ * );
16308
+ * // result = { xLow: 0x29bfcdb2dce28d959f2815b16f81798n, xHigh: 0x79be667ef9dcbbac55a06295ce870b07n,
16309
+ * // yLow: 0xfd17b448a68554199c47d08ffb10d4b8n, yHigh: 0x483ada7726a3c4655da4fbfc0e1108a8n }
16310
+ * CairoSecp256k1Point.validateProps(1, 2, 3, 4);
16311
+ * // throws Error("Secp256k1Point: this point is not on the secp256k1 curve (y^2 must equal x^3 + 7 modulo p), so a contract would refuse it")
16257
16312
  * CairoSecp256k1Point.validateProps(1, 2, 3, 2n ** 128n);
16258
16313
  * // throws Error("yHigh must fit in 128 bits")
16259
16314
  * CairoSecp256k1Point.validateProps(1.5, 2, 3, 4);
@@ -16269,18 +16324,18 @@ declare class CairoSecp256k1Point {
16269
16324
  yHigh: bigint;
16270
16325
  };
16271
16326
  /**
16272
- * Can this value be carried by a Secp256k1Point?
16327
+ * Is this value a point that a contract accepts as a Secp256k1Point?
16273
16328
  *
16274
16329
  * The non-throwing form of {@link CairoSecp256k1Point.validate}, so it answers false for every
16275
16330
  * input that one refuses, whatever the reason.
16276
16331
  * @param {any} data the value to test
16277
- * @returns {boolean} true when the value fits in 512 bits
16332
+ * @returns {boolean} true when the value fits in 512 bits and stands for a point on the curve, or for (0, 0)
16278
16333
  * @example
16279
16334
  * ```typescript
16280
- * const result = CairoSecp256k1Point.is(SECP256K1_POINT_MAX);
16281
- * // result = true
16282
- * const result2 = CairoSecp256k1Point.is(SECP256K1_POINT_MAX + 1n);
16283
- * // result2 = false
16335
+ * const result = CairoSecp256k1Point.is(0n);
16336
+ * // result = true (0, 0), the point at infinity
16337
+ * const result2 = CairoSecp256k1Point.is(SECP256K1_POINT_MAX);
16338
+ * // result2 = false x is not smaller than p
16284
16339
  * ```
16285
16340
  */
16286
16341
  static is(data: any): boolean;
@@ -16299,13 +16354,18 @@ declare class CairoSecp256k1Point {
16299
16354
  static isAbiType(abiType: string): boolean;
16300
16355
  /**
16301
16356
  * Read one point off a contract response, advancing the iterator past its four felts.
16357
+ *
16358
+ * A response is read as it comes : each felt must fit in 128 bits, but the point is not checked
16359
+ * against the curve. What a node answers is taken as correct, and a contract can only return a
16360
+ * point on the curve, or (0, 0).
16302
16361
  * @param {Iterator<string>} responseIterator the response felts, positioned on this point
16303
16362
  * @returns {CairoSecp256k1Point} the point that was read
16363
+ * @throws {Error} when the response ends before four felts, or when a felt does not fit in 128 bits
16304
16364
  * @example
16305
16365
  * ```typescript
16306
16366
  * const response = ['0x0', '0x0', '0x1', '0x0'];
16307
16367
  * const result = CairoSecp256k1Point.factoryFromApiResponse(response.values()).toBigInt();
16308
- * // result = 1n
16368
+ * // result = 1n not on the curve, and read all the same
16309
16369
  * ```
16310
16370
  */
16311
16371
  static factoryFromApiResponse(responseIterator: Iterator<string>): CairoSecp256k1Point;
@@ -16317,10 +16377,11 @@ declare class CairoSecp256k1Point {
16317
16377
  * @returns {bigint} the two coordinates concatenated, x in the upper 256 bits
16318
16378
  * @example
16319
16379
  * ```typescript
16320
- * const result = new CairoSecp256k1Point(1n).toBigInt();
16321
- * // result = 1n
16322
- * const result2 = new CairoSecp256k1Point(0, 0, 3, 0).toBigInt();
16323
- * // result2 = 3n
16380
+ * // G, the generator of the curve, as in the example of the class
16381
+ * const result = new CairoSecp256k1Point(G).toBigInt() === G;
16382
+ * // result = true
16383
+ * const result2 = new CairoSecp256k1Point(0, 0, 0, 0).toBigInt();
16384
+ * // result2 = 0n (0, 0), the point at infinity
16324
16385
  * ```
16325
16386
  */
16326
16387
  toBigInt(): bigint;
@@ -16329,8 +16390,10 @@ declare class CairoSecp256k1Point {
16329
16390
  * @returns {Secp256k1PointStruct} the limbs, each 0x-prefixed and unpadded
16330
16391
  * @example
16331
16392
  * ```typescript
16332
- * const result = new CairoSecp256k1Point({ xLow: 1, xHigh: 2, yLow: 3, yHigh: 4 }).toStruct();
16333
- * // result = { xLow: "0x1", xHigh: "0x2", yLow: "0x3", yHigh: "0x4" }
16393
+ * // G, the generator of the curve, as in the example of the class
16394
+ * const result = new CairoSecp256k1Point(G).toStruct();
16395
+ * // result = { xLow: "0x29bfcdb2dce28d959f2815b16f81798", xHigh: "0x79be667ef9dcbbac55a06295ce870b07",
16396
+ * // yLow: "0xfd17b448a68554199c47d08ffb10d4b8", yHigh: "0x483ada7726a3c4655da4fbfc0e1108a8" }
16334
16397
  * ```
16335
16398
  */
16336
16399
  toStruct(): Secp256k1PointStruct;
@@ -16339,8 +16402,8 @@ declare class CairoSecp256k1Point {
16339
16402
  * @returns {string} the 512-bit value as a 0x-prefixed hex string
16340
16403
  * @example
16341
16404
  * ```typescript
16342
- * const result = new CairoSecp256k1Point(4660n).toHexString();
16343
- * // result = "0x1234"
16405
+ * const result = new CairoSecp256k1Point(0n).toHexString();
16406
+ * // result = "0x0" (0, 0), the point at infinity
16344
16407
  * ```
16345
16408
  */
16346
16409
  toHexString(): string;
@@ -16349,8 +16412,10 @@ declare class CairoSecp256k1Point {
16349
16412
  * @returns {string[]} the limbs as decimal strings, `[xLow, xHigh, yLow, yHigh]`, flagged as compiled
16350
16413
  * @example
16351
16414
  * ```typescript
16352
- * const result = new CairoSecp256k1Point({ xLow: 1, xHigh: 2, yLow: 3, yHigh: 4 }).toApiRequest();
16353
- * // result = ["1", "2", "3", "4"]
16415
+ * // G, the generator of the curve, as in the example of the class
16416
+ * const result = new CairoSecp256k1Point(G).toApiRequest();
16417
+ * // result = ["3468390537006497937951914270391801752", "161825202758953104525843685720298294023",
16418
+ * // "336417762351022071123394393598455764152", "96009999919712310848645357523629574312"]
16354
16419
  * ```
16355
16420
  */
16356
16421
  toApiRequest(): string[];
@@ -16361,11 +16426,19 @@ declare class CairoSecp256k1Point {
16361
16426
  * read as a point whose upper limbs are zero. A longer one is refused rather than truncated.
16362
16427
  * @param {string} hexString the value, 0x-prefixed or not, at most 128 hex digits
16363
16428
  * @returns {CairoSecp256k1Point} the point the string spells
16364
- * @throws {Error} when the string holds more than 128 hex digits
16365
- * @example
16366
- * ```typescript
16367
- * const result = CairoSecp256k1Point.fromHex('0x1').toApiRequest();
16368
- * // result = ["0", "0", "1", "0"]
16429
+ * @throws {Error} when the string holds more than 128 hex digits, or when the point is not on the
16430
+ * curve
16431
+ * @example
16432
+ * ```typescript
16433
+ * // G, the generator of the curve
16434
+ * const result = CairoSecp256k1Point.fromHex(
16435
+ * '0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8'
16436
+ * ).xHigh;
16437
+ * // result = 0x79be667ef9dcbbac55a06295ce870b07n
16438
+ * const result2 = CairoSecp256k1Point.fromHex('0x0').toApiRequest();
16439
+ * // result2 = ["0", "0", "0", "0"] left-padded to 128 hex digits : (0, 0), the point at infinity
16440
+ * CairoSecp256k1Point.fromHex('0x1'); // x = 0, y = 1
16441
+ * // throws Error("Secp256k1Point: this point is not on the secp256k1 curve (y^2 must equal x^3 + 7 modulo p), so a contract would refuse it")
16369
16442
  * ```
16370
16443
  */
16371
16444
  static fromHex(hexString: string): CairoSecp256k1Point;