starknet 11.1.0 → 11.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -62,6 +62,7 @@ __export(index_exports, {
62
62
  CairoResult: () => CairoResult,
63
63
  CairoResultVariant: () => CairoResultVariant,
64
64
  CairoSecp256k1Point: () => CairoSecp256k1Point,
65
+ CairoStorageAddress: () => CairoStorageAddress,
65
66
  CairoStruct: () => CairoStruct,
66
67
  CairoTuple: () => CairoTuple,
67
68
  CairoTypeCustomEnum: () => CairoTypeCustomEnum,
@@ -108,7 +109,7 @@ __export(index_exports, {
108
109
  PaymasterInterface: () => PaymasterInterface,
109
110
  PaymasterRpc: () => PaymasterRpc,
110
111
  PluginManager: () => PluginManager,
111
- Provider: () => RpcProvider,
112
+ Provider: () => Provider,
112
113
  ProviderInterface: () => ProviderInterface,
113
114
  RPC: () => api_exports,
114
115
  RPC0102: () => v0_10_2_exports,
@@ -255,6 +256,7 @@ __export(constants_exports, {
255
256
  RANGE_I32: () => RANGE_I32,
256
257
  RANGE_I64: () => RANGE_I64,
257
258
  RANGE_I8: () => RANGE_I8,
259
+ RANGE_STORAGE_ADDRESS: () => RANGE_STORAGE_ADDRESS,
258
260
  RANGE_U128: () => RANGE_U128,
259
261
  RANGE_U16: () => RANGE_U16,
260
262
  RANGE_U32: () => RANGE_U32,
@@ -486,6 +488,7 @@ var RANGE_I128 = range(-(2n ** 127n), 2n ** 127n - 1n);
486
488
  var RANGE_ETH_ADDRESS = range(ZERO, 2n ** 160n - 1n);
487
489
  var RANGE_CONTRACT_ADDRESS = range(ZERO, ADDR_BOUND - 1n);
488
490
  var RANGE_CLASS_HASH = range(ZERO, 2n ** 251n - 1n);
491
+ var RANGE_STORAGE_ADDRESS = range(ZERO, 2n ** 251n - 1n);
489
492
  var LegacyUDC = {
490
493
  ADDRESS: "0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf",
491
494
  ENTRYPOINT: "deployContract"
@@ -1167,6 +1170,7 @@ var Literal = {
1167
1170
  ClassHash: "core::starknet::class_hash::ClassHash",
1168
1171
  ContractAddress: "core::starknet::contract_address::ContractAddress",
1169
1172
  Secp256k1Point: "core::starknet::secp256k1::Secp256k1Point",
1173
+ StorageAddress: "core::starknet::storage_access::StorageAddress",
1170
1174
  U96: "core::internal::bounded_int::BoundedInt::<0, 79228162514264337593543950335>"
1171
1175
  };
1172
1176
  var ETH_ADDRESS = "core::starknet::eth_address::EthAddress";
@@ -8280,6 +8284,169 @@ var CairoContractAddress = class _CairoContractAddress {
8280
8284
  }
8281
8285
  };
8282
8286
 
8287
+ // src/utils/cairoDataTypes/storageAddress.ts
8288
+ var CairoStorageAddress = class _CairoStorageAddress {
8289
+ /**
8290
+ * The address, always as a bigint.
8291
+ * @example
8292
+ * ```typescript
8293
+ * const result = new CairoStorageAddress('0x1234').data;
8294
+ * // result = 4660n
8295
+ * ```
8296
+ */
8297
+ data;
8298
+ /**
8299
+ * The abi type this class serializes.
8300
+ * @example
8301
+ * ```typescript
8302
+ * const result = CairoStorageAddress.abiSelector;
8303
+ * // result = "core::starknet::storage_access::StorageAddress"
8304
+ * ```
8305
+ */
8306
+ static abiSelector = Literal.StorageAddress;
8307
+ /**
8308
+ * Build from a number or a numeric string, refusing text and anything outside the
8309
+ * StorageAddress range.
8310
+ * @param {BigNumberish | boolean} data the address to carry, within [0, 2^251 - 1]
8311
+ * @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of the StorageAddress range
8312
+ * @example
8313
+ * ```typescript
8314
+ * const result = new CairoStorageAddress('0x1234').toApiRequest();
8315
+ * // result = ["4660"]
8316
+ * ```
8317
+ */
8318
+ constructor(data) {
8319
+ _CairoStorageAddress.validate(data);
8320
+ this.data = new CairoFelt252(data).toBigInt();
8321
+ }
8322
+ /**
8323
+ * Serialize to the single felt a contract call carries.
8324
+ * @returns {string[]} one decimal-string felt, flagged as compiled
8325
+ * @example
8326
+ * ```typescript
8327
+ * const result = new CairoStorageAddress('0x1234').toApiRequest();
8328
+ * // result = ["4660"]
8329
+ * ```
8330
+ */
8331
+ toApiRequest() {
8332
+ return addCompiledFlag([this.toBigInt().toString()]);
8333
+ }
8334
+ /**
8335
+ * The address as a number.
8336
+ * @returns {bigint} the number this address holds
8337
+ * @example
8338
+ * ```typescript
8339
+ * const result = new CairoStorageAddress('0x1234').toBigInt();
8340
+ * // result = 4660n
8341
+ * ```
8342
+ */
8343
+ toBigInt() {
8344
+ return this.data;
8345
+ }
8346
+ /**
8347
+ * The address in hexadecimal, without padding.
8348
+ *
8349
+ * Leading zeros are dropped, as they are everywhere else in the library.
8350
+ * @returns {string} the address as a 0x-prefixed hex string
8351
+ * @example
8352
+ * ```typescript
8353
+ * const result = new CairoStorageAddress(4660).toHexString();
8354
+ * // result = "0x1234"
8355
+ * const result2 = new CairoStorageAddress('0x0034').toHexString();
8356
+ * // result2 = "0x34" (four digits in, two out)
8357
+ * ```
8358
+ */
8359
+ toHexString() {
8360
+ return addHexPrefix(this.toBigInt().toString(16));
8361
+ }
8362
+ /**
8363
+ * Throw unless the value can be carried by a StorageAddress.
8364
+ *
8365
+ * Text is refused first, then a number with a decimal part. A number or a bigint is read as it
8366
+ * is, so that a negative one reaches the range check. Anything else is read as a felt252 — which
8367
+ * is what refuses a null, an object or an unsupported type. The value is finally checked against
8368
+ * the range of the Cairo `StorageAddress` type, [0, 2^251), which is narrower than the field.
8369
+ * @param {BigNumberish | boolean} data the value to check
8370
+ * @throws {Error} when the value is text, a decimal number, not a felt252 input, or out of the StorageAddress range
8371
+ * @example
8372
+ * ```typescript
8373
+ * CairoStorageAddress.validate('0x1234'); // passes
8374
+ * CairoStorageAddress.validate('abc');
8375
+ * // throws Error("Invalid input: a StorageAddress cannot be built from text")
8376
+ * CairoStorageAddress.validate(2n ** 251n);
8377
+ * // throws Error("Value is out of StorageAddress range [0, 3618502788666131106986593281521497120414687020801267626233049500247285301247]")
8378
+ * CairoStorageAddress.validate(-1);
8379
+ * // throws Error("Value is out of StorageAddress range [0, 3618502788666131106986593281521497120414687020801267626233049500247285301247]")
8380
+ * ```
8381
+ */
8382
+ static validate(data) {
8383
+ assert(!isText(data), "Invalid input: a StorageAddress cannot be built from text");
8384
+ assert(
8385
+ !isNumber(data) || Number.isInteger(data),
8386
+ "Invalid input: decimal numbers are not supported, only integers"
8387
+ );
8388
+ const value = isNumber(data) || isBigInt(data) ? BigInt(data) : new CairoFelt252(data).toBigInt();
8389
+ assert(
8390
+ value >= RANGE_STORAGE_ADDRESS.min && value <= RANGE_STORAGE_ADDRESS.max,
8391
+ `Value is out of StorageAddress range [${RANGE_STORAGE_ADDRESS.min}, ${RANGE_STORAGE_ADDRESS.max}]`
8392
+ );
8393
+ }
8394
+ /**
8395
+ * Can this value be carried by a StorageAddress?
8396
+ *
8397
+ * The non-throwing form of {@link CairoStorageAddress.validate}, so it answers false for every
8398
+ * input that one refuses, whatever the reason.
8399
+ * @param {BigNumberish | boolean} data the value to test
8400
+ * @returns {boolean} true when the value fits in a StorageAddress
8401
+ * @example
8402
+ * ```typescript
8403
+ * const result = CairoStorageAddress.is('0x1234');
8404
+ * // result = true
8405
+ * const result2 = CairoStorageAddress.is('abc');
8406
+ * // result2 = false (text, not a number)
8407
+ * ```
8408
+ */
8409
+ static is(data) {
8410
+ try {
8411
+ _CairoStorageAddress.validate(data);
8412
+ return true;
8413
+ } catch {
8414
+ return false;
8415
+ }
8416
+ }
8417
+ /**
8418
+ * Is this abi type the one this class serializes?
8419
+ * @param {string} abiType the abi type to test
8420
+ * @returns {boolean} true for `core::starknet::storage_access::StorageAddress`
8421
+ * @example
8422
+ * ```typescript
8423
+ * const result = CairoStorageAddress.isAbiType(
8424
+ * 'core::starknet::storage_access::StorageAddress'
8425
+ * );
8426
+ * // result = true
8427
+ * const result2 = CairoStorageAddress.isAbiType('core::felt252');
8428
+ * // result2 = false
8429
+ * ```
8430
+ */
8431
+ static isAbiType(abiType) {
8432
+ return abiType === _CairoStorageAddress.abiSelector;
8433
+ }
8434
+ /**
8435
+ * Read one StorageAddress off a contract response, advancing the iterator past it.
8436
+ * @param {Iterator<string>} responseIterator the response felts, positioned on this address
8437
+ * @returns {CairoStorageAddress} the address that was read
8438
+ * @example
8439
+ * ```typescript
8440
+ * const response = ['0x1234'];
8441
+ * const result = CairoStorageAddress.factoryFromApiResponse(response.values()).toBigInt();
8442
+ * // result = 4660n
8443
+ * ```
8444
+ */
8445
+ static factoryFromApiResponse(responseIterator) {
8446
+ return new _CairoStorageAddress(getNext(responseIterator));
8447
+ }
8448
+ };
8449
+
8283
8450
  // src/utils/cairoDataTypes/ethAddress.ts
8284
8451
  var CairoEthAddress = class _CairoEthAddress {
8285
8452
  /**
@@ -10686,6 +10853,7 @@ var LEAF_TYPES = [
10686
10853
  CairoEthAddress,
10687
10854
  CairoClassHash,
10688
10855
  CairoContractAddress,
10856
+ CairoStorageAddress,
10689
10857
  CairoBytes31,
10690
10858
  CairoByteArray,
10691
10859
  CairoSecp256k1Point,
@@ -10759,6 +10927,7 @@ var cairoTypeStrategy = {
10759
10927
  [CairoEthAddress.abiSelector]: (instance) => instance.toBigInt(),
10760
10928
  [CairoClassHash.abiSelector]: (instance) => instance.toBigInt(),
10761
10929
  [CairoContractAddress.abiSelector]: (instance) => instance.toBigInt(),
10930
+ [CairoStorageAddress.abiSelector]: (instance) => instance.toBigInt(),
10762
10931
  [CairoBytes31.abiSelector]: (instance) => instance.decodeUtf8(),
10763
10932
  [CairoByteArray.abiSelector]: (instance) => instance.decodeUtf8(),
10764
10933
  [CairoSecp256k1Point.abiSelector]: (instance) => instance.toBigInt(),
@@ -17538,6 +17707,9 @@ if (typeof Symbol.dispose !== "undefined") {
17538
17707
  WebSocketProvider.prototype[Symbol.dispose] = WebSocketProvider.prototype.dispose;
17539
17708
  }
17540
17709
 
17710
+ // src/provider/index.ts
17711
+ var Provider = RpcProvider;
17712
+
17541
17713
  // src/signer/interface.ts
17542
17714
  var SignerInterface = class {
17543
17715
  };
@@ -18005,13 +18177,13 @@ var LedgerSigner221 = class extends LedgerSigner111 {
18005
18177
  *
18006
18178
  * If you are using APP v2.2.1 with an account created with the v1.1.1, you need to use :
18007
18179
  * ```typescript
18008
- * const myLedgerSigner = new LedgerSigner211(myNodeTransport, 0, undefined, getLedgerPathBuffer111);
18180
+ * const myLedgerSigner = new LedgerSigner221(myNodeTransport, 0, undefined, getLedgerPathBuffer111);
18009
18181
  * ```
18010
18182
  * @example
18011
18183
  * ```typescript
18012
18184
  * import TransportNodeHid from "@ledgerhq/hw-transport-node-hid";
18013
18185
  * const myNodeTransport = await TransportNodeHid.create();
18014
- * const myLedgerSigner = new LedgerSigner211(myNodeTransport, 0);
18186
+ * const myLedgerSigner = new LedgerSigner221(myNodeTransport, 0);
18015
18187
  * ```
18016
18188
  */
18017
18189
  constructor(transport, accountID, eip2645application = "LedgerW", pathFunction = getLedgerPathBuffer221) {
@@ -21528,6 +21700,7 @@ function units(amount, simbol = "fri") {
21528
21700
  CairoResult,
21529
21701
  CairoResultVariant,
21530
21702
  CairoSecp256k1Point,
21703
+ CairoStorageAddress,
21531
21704
  CairoStruct,
21532
21705
  CairoTuple,
21533
21706
  CairoTypeCustomEnum,