starknet 6.21.1 → 6.22.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/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # [6.22.0](https://github.com/starknet-io/starknet.js/compare/v6.21.2...v6.22.0) (2025-01-29)
2
+
3
+ ### Features
4
+
5
+ - units utils ([#1277](https://github.com/starknet-io/starknet.js/issues/1277)) ([26037e9](https://github.com/starknet-io/starknet.js/commit/26037e92c4cdfa220c29fd1147beae7408d8d004))
6
+
7
+ ## [6.21.2](https://github.com/starknet-io/starknet.js/compare/v6.21.1...v6.21.2) (2025-01-29)
8
+
9
+ ### Bug Fixes
10
+
11
+ - add starkid improvements ([#1301](https://github.com/starknet-io/starknet.js/issues/1301)) ([51702db](https://github.com/starknet-io/starknet.js/commit/51702dbd8dd3dcb0d6e7960b6b320c8c17afff1b))
12
+
1
13
  ## [6.21.1](https://github.com/starknet-io/starknet.js/compare/v6.21.0...v6.21.1) (2025-01-23)
2
14
 
3
15
  ### Bug Fixes
package/dist/index.d.ts CHANGED
@@ -6862,6 +6862,21 @@ declare function dynamicFelt(hardcoded: BigNumberish | undefined, reference?: nu
6862
6862
  * ```
6863
6863
  */
6864
6864
  declare function dynamicCallData(hardcoded: BigNumberish | undefined, reference?: BigNumberish[] | undefined, arrayReference?: BigNumberish[] | undefined): CairoCustomEnum;
6865
+ /**
6866
+ * Check if a given string is a valid Starknet.id domain.
6867
+ *
6868
+ * @param {string} domain - The domain string to validate.
6869
+ * @returns {boolean} - True if the domain is a valid Starknet.id domain, false otherwise.
6870
+ * @example
6871
+ * ```typescript
6872
+ * const result = starknetId.isStarkDomain("example.stark");
6873
+ * // result = true
6874
+ *
6875
+ * const result2 = starknetId.isStarkDomain("invalid-domain");
6876
+ * // result2 = false
6877
+ * ```
6878
+ */
6879
+ declare function isStarkDomain(domain: string): boolean;
6865
6880
 
6866
6881
  declare const starknetId_StarknetIdContract: typeof StarknetIdContract;
6867
6882
  declare const starknetId_StarknetIdIdentityContract: typeof StarknetIdIdentityContract;
@@ -6878,10 +6893,11 @@ declare const starknetId_getStarknetIdMulticallContract: typeof getStarknetIdMul
6878
6893
  declare const starknetId_getStarknetIdPfpContract: typeof getStarknetIdPfpContract;
6879
6894
  declare const starknetId_getStarknetIdPopContract: typeof getStarknetIdPopContract;
6880
6895
  declare const starknetId_getStarknetIdVerifierContract: typeof getStarknetIdVerifierContract;
6896
+ declare const starknetId_isStarkDomain: typeof isStarkDomain;
6881
6897
  declare const starknetId_useDecoded: typeof useDecoded;
6882
6898
  declare const starknetId_useEncoded: typeof useEncoded;
6883
6899
  declare namespace starknetId {
6884
- export { starknetId_StarknetIdContract as StarknetIdContract, starknetId_StarknetIdIdentityContract as StarknetIdIdentityContract, starknetId_StarknetIdMulticallContract as StarknetIdMulticallContract, starknetId_StarknetIdPfpContract as StarknetIdPfpContract, starknetId_StarknetIdPopContract as StarknetIdPopContract, starknetId_StarknetIdVerifierContract as StarknetIdVerifierContract, starknetId_dynamicCallData as dynamicCallData, starknetId_dynamicFelt as dynamicFelt, starknetId_execution as execution, starknetId_getStarknetIdContract as getStarknetIdContract, starknetId_getStarknetIdIdentityContract as getStarknetIdIdentityContract, starknetId_getStarknetIdMulticallContract as getStarknetIdMulticallContract, starknetId_getStarknetIdPfpContract as getStarknetIdPfpContract, starknetId_getStarknetIdPopContract as getStarknetIdPopContract, starknetId_getStarknetIdVerifierContract as getStarknetIdVerifierContract, starknetId_useDecoded as useDecoded, starknetId_useEncoded as useEncoded };
6900
+ export { starknetId_StarknetIdContract as StarknetIdContract, starknetId_StarknetIdIdentityContract as StarknetIdIdentityContract, starknetId_StarknetIdMulticallContract as StarknetIdMulticallContract, starknetId_StarknetIdPfpContract as StarknetIdPfpContract, starknetId_StarknetIdPopContract as StarknetIdPopContract, starknetId_StarknetIdVerifierContract as StarknetIdVerifierContract, starknetId_dynamicCallData as dynamicCallData, starknetId_dynamicFelt as dynamicFelt, starknetId_execution as execution, starknetId_getStarknetIdContract as getStarknetIdContract, starknetId_getStarknetIdIdentityContract as getStarknetIdIdentityContract, starknetId_getStarknetIdMulticallContract as getStarknetIdMulticallContract, starknetId_getStarknetIdPfpContract as getStarknetIdPfpContract, starknetId_getStarknetIdPopContract as getStarknetIdPopContract, starknetId_getStarknetIdVerifierContract as getStarknetIdVerifierContract, starknetId_isStarkDomain as isStarkDomain, starknetId_useDecoded as useDecoded, starknetId_useEncoded as useEncoded };
6885
6901
  }
6886
6902
 
6887
6903
  /**
@@ -7928,6 +7944,16 @@ declare function extractContractHashes(payload: DeclareContractPayload): Complet
7928
7944
  */
7929
7945
  declare function contractClassResponseToLegacyCompiledContract(ccr: ContractClassResponse): LegacyCompiledContract;
7930
7946
 
7947
+ /**
7948
+ * Convert strk to fri or fri to strk
7949
+ * @example
7950
+ * ```typescript
7951
+ * units(1000n, 'fri') // '0.000000000000001' strk
7952
+ * units('1', 'strk') // '1000000000000000000' fri
7953
+ * ```
7954
+ */
7955
+ declare function units(amount: string | bigint, simbol?: 'fri' | 'strk'): string;
7956
+
7931
7957
  /**
7932
7958
  * Request Permission for wallet account, return addresses that are allowed by user
7933
7959
  * @param {boolean} [silent_mode=false] false: request user interaction allowance. true: return only pre-allowed
@@ -8034,4 +8060,4 @@ declare namespace connect {
8034
8060
  /** @deprecated prefer the 'num' naming */
8035
8061
  declare const number: typeof num;
8036
8062
 
8037
- export { type Abi, type AbiEntry, type AbiEnum, type AbiEnums, type AbiEvent, type AbiEvents, type AbiInterfaces, type AbiStruct, type AbiStructs, Account, AccountInterface, type AccountInvocationItem, type AccountInvocations, type AccountInvocationsFactoryDetails, type AllowArray, type Args, type ArgsOrCalldata, type ArgsOrCalldataWithOptions, type ArraySignatureType, type AsyncContractFunction, BatchClient, type BatchClientOptions, type BigNumberish, type Block$1 as Block, type BlockIdentifier, type BlockNumber, BlockStatus, BlockTag, type BlockWithTxHashes, type Builtins, type ByteArray, type ByteCode, type CairoAssembly, type CairoContract, CairoCustomEnum, type CairoEnum, type CairoEnumRaw, type CairoEvent, type CairoEventDefinition, type CairoEventVariant, CairoOption, CairoOptionVariant, CairoResult, CairoResultVariant, CairoUint256, CairoUint512, type CairoVersion, type Call, type CallContractResponse, CallData, type CallDetails, type CallOptions, type CallStruct, type Calldata, type CompiledContract, type CompiledSierra, type CompiledSierraCasm, type CompilerVersion, type CompleteDeclareContractPayload, type CompressedProgram, Contract, type ContractClass, type ContractClassIdentifier, type ContractClassPayload, type ContractClassResponse, type ContractEntryPointFields, ContractFactory, type ContractFactoryParams, type ContractFunction, ContractInterface, type ContractOptions, type ContractVersion, CustomError, type DeclareAndDeployContractPayload, type DeclareContractPayload, type DeclareContractResponse, type DeclareContractTransaction, type DeclareDeployUDCResponse, type DeclareSignerDetails, type DeclareTransactionReceiptResponse, type DeployAccountContractPayload, type DeployAccountContractTransaction, type DeployAccountSignerDetails, type DeployAccountTransactionReceiptResponse, type DeployContractResponse, type DeployContractUDCResponse, type DeployTransactionReceiptResponse, type Details, ETH_ADDRESS, EntryPointType, type EntryPointsByType, type EstimateFee, type EstimateFeeAction, type EstimateFeeBulk, type EstimateFeeDetails, type EstimateFeeResponse, type EstimateFeeResponseBulk, EthSigner, type EventEntry, type FeeEstimate, type FunctionAbi, type GetBlockResponse, type GetTransactionReceiptResponse, type GetTransactionResponse, type GetTxReceiptResponseWithoutHelper, type HexCalldata, type InterfaceAbi, type Invocation, type Invocations, type InvocationsDetails, type InvocationsDetailsWithNonce, type InvocationsSignerDetails, type InvokeFunctionResponse, type InvokeOptions, type InvokeTransactionReceiptResponse, type L1HandlerTransactionReceiptResponse, type LedgerPathCalculation, LedgerSigner111 as LedgerSigner, LedgerSigner111, LedgerSigner221, type LegacyCompiledContract, type LegacyContractClass, type LegacyEvent, LibraryError, Literal, type MessageToL1, type MultiDeployContractResponse, type MultiType, NON_ZERO_PREFIX, type Nonce, type OptionalPayload, type OutsideCall, type OutsideExecution, type OutsideExecutionOptions, OutsideExecutionTypesV1, OutsideExecutionTypesV2, OutsideExecutionVersion, type OutsideTransaction, type ParsedEvent, type ParsedEvents, type ParsedStruct, type PendingBlock, type PendingStateUpdate, type Program, RpcProvider as Provider, ProviderInterface, type ProviderOptions, type PythonicHints, index$3 as RPC, rpc_0_6 as RPC06, rpc_0_7 as RPC07, RPCResponseParser, type RPC_ERROR, type RPC_ERROR_SET, type RawArgs, type RawArgsArray, type RawArgsObject, type RawCalldata, ReceiptTx, type RejectedTransactionReceiptResponse, ResponseParser, type Result, type RevertedTransactionReceiptResponse, RpcChannel, RpcError, RpcProvider, type RpcProviderOptions, type SIMULATION_FLAG, type SierraContractClass, type SierraContractEntryPointFields, type SierraEntryPointsByType, type SierraProgramDebugInfo, type Signature, Signer, SignerInterface, type SimulateTransactionDetails, type SimulateTransactionResponse, type SimulatedTransaction, type SimulationFlags, type StarkProfile, type StateUpdate, type StateUpdateResponse, type Storage, type SuccessfulTransactionReceiptResponse, TransactionExecutionStatus, TransactionFinalityStatus, type TransactionReceipt, type TransactionReceiptCallbacks, type TransactionReceiptCallbacksDefault, type TransactionReceiptCallbacksDefined, type TransactionReceiptStatus, type TransactionReceiptUtilityInterface, type TransactionReceiptValue, TransactionStatus, type TransactionStatusReceiptSets, TransactionType, type Tupled, type TypedContractV2, UINT_128_MAX, UINT_128_MIN, UINT_256_HIGH_MAX, UINT_256_HIGH_MIN, UINT_256_LOW_MAX, UINT_256_LOW_MIN, UINT_256_MAX, UINT_256_MIN, UINT_512_MAX, UINT_512_MIN, Uint, type Uint256, type Uint512, type UniversalDeployerContractPayload, type UniversalDetails, type UniversalSuggestedFee, type V2DeclareSignerDetails, type V2DeployAccountSignerDetails, type V2InvocationsSignerDetails, type V3DeclareSignerDetails, type V3DeployAccountSignerDetails, type V3InvocationsSignerDetails, type V3TransactionDetails, ValidateType, WalletAccount, type WeierstrassSignatureType, addAddressPadding, byteArray, cairo, constants, contractClassResponseToLegacyCompiledContract, defaultProvider, ec, encode, eth, index as events, extractContractHashes, fixProto, fixStack, getCalldata, getChecksumAddress, type getContractVersionOptions, type getEstimateFeeBulkOptions, getLedgerPathBuffer111 as getLedgerPathBuffer, getLedgerPathBuffer111, getLedgerPathBuffer221, type getSimulateTransactionOptions, index$1 as hash, isSierra, json, merkle, num, number, outsideExecution, parseCalldataField, provider, selector, shortString, splitArgsAndOptions, src5, stark, starknetId, transaction, typedData, index$2 as types, uint256$1 as uint256, v2 as v2hash, v3 as v3hash, validateAndParseAddress, validateChecksumAddress, type waitForTransactionOptions, connect as wallet };
8063
+ export { type Abi, type AbiEntry, type AbiEnum, type AbiEnums, type AbiEvent, type AbiEvents, type AbiInterfaces, type AbiStruct, type AbiStructs, Account, AccountInterface, type AccountInvocationItem, type AccountInvocations, type AccountInvocationsFactoryDetails, type AllowArray, type Args, type ArgsOrCalldata, type ArgsOrCalldataWithOptions, type ArraySignatureType, type AsyncContractFunction, BatchClient, type BatchClientOptions, type BigNumberish, type Block$1 as Block, type BlockIdentifier, type BlockNumber, BlockStatus, BlockTag, type BlockWithTxHashes, type Builtins, type ByteArray, type ByteCode, type CairoAssembly, type CairoContract, CairoCustomEnum, type CairoEnum, type CairoEnumRaw, type CairoEvent, type CairoEventDefinition, type CairoEventVariant, CairoOption, CairoOptionVariant, CairoResult, CairoResultVariant, CairoUint256, CairoUint512, type CairoVersion, type Call, type CallContractResponse, CallData, type CallDetails, type CallOptions, type CallStruct, type Calldata, type CompiledContract, type CompiledSierra, type CompiledSierraCasm, type CompilerVersion, type CompleteDeclareContractPayload, type CompressedProgram, Contract, type ContractClass, type ContractClassIdentifier, type ContractClassPayload, type ContractClassResponse, type ContractEntryPointFields, ContractFactory, type ContractFactoryParams, type ContractFunction, ContractInterface, type ContractOptions, type ContractVersion, CustomError, type DeclareAndDeployContractPayload, type DeclareContractPayload, type DeclareContractResponse, type DeclareContractTransaction, type DeclareDeployUDCResponse, type DeclareSignerDetails, type DeclareTransactionReceiptResponse, type DeployAccountContractPayload, type DeployAccountContractTransaction, type DeployAccountSignerDetails, type DeployAccountTransactionReceiptResponse, type DeployContractResponse, type DeployContractUDCResponse, type DeployTransactionReceiptResponse, type Details, ETH_ADDRESS, EntryPointType, type EntryPointsByType, type EstimateFee, type EstimateFeeAction, type EstimateFeeBulk, type EstimateFeeDetails, type EstimateFeeResponse, type EstimateFeeResponseBulk, EthSigner, type EventEntry, type FeeEstimate, type FunctionAbi, type GetBlockResponse, type GetTransactionReceiptResponse, type GetTransactionResponse, type GetTxReceiptResponseWithoutHelper, type HexCalldata, type InterfaceAbi, type Invocation, type Invocations, type InvocationsDetails, type InvocationsDetailsWithNonce, type InvocationsSignerDetails, type InvokeFunctionResponse, type InvokeOptions, type InvokeTransactionReceiptResponse, type L1HandlerTransactionReceiptResponse, type LedgerPathCalculation, LedgerSigner111 as LedgerSigner, LedgerSigner111, LedgerSigner221, type LegacyCompiledContract, type LegacyContractClass, type LegacyEvent, LibraryError, Literal, type MessageToL1, type MultiDeployContractResponse, type MultiType, NON_ZERO_PREFIX, type Nonce, type OptionalPayload, type OutsideCall, type OutsideExecution, type OutsideExecutionOptions, OutsideExecutionTypesV1, OutsideExecutionTypesV2, OutsideExecutionVersion, type OutsideTransaction, type ParsedEvent, type ParsedEvents, type ParsedStruct, type PendingBlock, type PendingStateUpdate, type Program, RpcProvider as Provider, ProviderInterface, type ProviderOptions, type PythonicHints, index$3 as RPC, rpc_0_6 as RPC06, rpc_0_7 as RPC07, RPCResponseParser, type RPC_ERROR, type RPC_ERROR_SET, type RawArgs, type RawArgsArray, type RawArgsObject, type RawCalldata, ReceiptTx, type RejectedTransactionReceiptResponse, ResponseParser, type Result, type RevertedTransactionReceiptResponse, RpcChannel, RpcError, RpcProvider, type RpcProviderOptions, type SIMULATION_FLAG, type SierraContractClass, type SierraContractEntryPointFields, type SierraEntryPointsByType, type SierraProgramDebugInfo, type Signature, Signer, SignerInterface, type SimulateTransactionDetails, type SimulateTransactionResponse, type SimulatedTransaction, type SimulationFlags, type StarkProfile, type StateUpdate, type StateUpdateResponse, type Storage, type SuccessfulTransactionReceiptResponse, TransactionExecutionStatus, TransactionFinalityStatus, type TransactionReceipt, type TransactionReceiptCallbacks, type TransactionReceiptCallbacksDefault, type TransactionReceiptCallbacksDefined, type TransactionReceiptStatus, type TransactionReceiptUtilityInterface, type TransactionReceiptValue, TransactionStatus, type TransactionStatusReceiptSets, TransactionType, type Tupled, type TypedContractV2, UINT_128_MAX, UINT_128_MIN, UINT_256_HIGH_MAX, UINT_256_HIGH_MIN, UINT_256_LOW_MAX, UINT_256_LOW_MIN, UINT_256_MAX, UINT_256_MIN, UINT_512_MAX, UINT_512_MIN, Uint, type Uint256, type Uint512, type UniversalDeployerContractPayload, type UniversalDetails, type UniversalSuggestedFee, type V2DeclareSignerDetails, type V2DeployAccountSignerDetails, type V2InvocationsSignerDetails, type V3DeclareSignerDetails, type V3DeployAccountSignerDetails, type V3InvocationsSignerDetails, type V3TransactionDetails, ValidateType, WalletAccount, type WeierstrassSignatureType, addAddressPadding, byteArray, cairo, constants, contractClassResponseToLegacyCompiledContract, defaultProvider, ec, encode, eth, index as events, extractContractHashes, fixProto, fixStack, getCalldata, getChecksumAddress, type getContractVersionOptions, type getEstimateFeeBulkOptions, getLedgerPathBuffer111 as getLedgerPathBuffer, getLedgerPathBuffer111, getLedgerPathBuffer221, type getSimulateTransactionOptions, index$1 as hash, isSierra, json, merkle, num, number, outsideExecution, parseCalldataField, provider, selector, shortString, splitArgsAndOptions, src5, stark, starknetId, transaction, typedData, index$2 as types, uint256$1 as uint256, units, v2 as v2hash, v3 as v3hash, validateAndParseAddress, validateChecksumAddress, type waitForTransactionOptions, connect as wallet };
@@ -3303,6 +3303,7 @@ var starknet = (() => {
3303
3303
  typedData: () => typedData_exports,
3304
3304
  types: () => types_exports,
3305
3305
  uint256: () => uint256_exports,
3306
+ units: () => units,
3306
3307
  v2hash: () => v2_exports,
3307
3308
  v3hash: () => v3_exports,
3308
3309
  validateAndParseAddress: () => validateAndParseAddress,
@@ -17339,6 +17340,7 @@ ${indent}}` : "}";
17339
17340
  getStarknetIdPfpContract: () => getStarknetIdPfpContract,
17340
17341
  getStarknetIdPopContract: () => getStarknetIdPopContract,
17341
17342
  getStarknetIdVerifierContract: () => getStarknetIdVerifierContract,
17343
+ isStarkDomain: () => isStarkDomain,
17342
17344
  useDecoded: () => useDecoded,
17343
17345
  useEncoded: () => useEncoded
17344
17346
  });
@@ -17524,6 +17526,9 @@ ${indent}}` : "}";
17524
17526
  ArrayReference: arrayReference ? tuple(arrayReference[0], arrayReference[1]) : void 0
17525
17527
  });
17526
17528
  }
17529
+ function isStarkDomain(domain) {
17530
+ return /^(?:[a-z0-9-]{1,48}(?:[a-z0-9-]{1,48}[a-z0-9-])?\.)*[a-z0-9-]{1,48}\.stark$/.test(domain);
17531
+ }
17527
17532
 
17528
17533
  // src/provider/extensions/starknetId.ts
17529
17534
  var StarknetId = class _StarknetId {
@@ -17582,10 +17587,14 @@ ${indent}}` : "}";
17582
17587
  }
17583
17588
  }
17584
17589
  static async getAddressFromStarkName(provider, name, StarknetIdContract2) {
17590
+ const starkName = name.endsWith(".stark") ? name : `${name}.stark`;
17591
+ if (!isStarkDomain(starkName)) {
17592
+ throw new Error("Invalid domain, must be a valid .stark domain");
17593
+ }
17585
17594
  const chainId = await provider.getChainId();
17586
17595
  const contract = StarknetIdContract2 ?? getStarknetIdContract(chainId);
17587
17596
  try {
17588
- const encodedDomain = name.replace(".stark", "").split(".").map((part) => useEncoded(part).toString(10));
17597
+ const encodedDomain = starkName.replace(".stark", "").split(".").map((part) => useEncoded(part).toString(10));
17589
17598
  const addressData = await provider.callContract({
17590
17599
  contractAddress: contract,
17591
17600
  entrypoint: "domain_to_address",
@@ -20326,6 +20335,32 @@ ${indent}}` : "}";
20326
20335
  var ResponseParser = class {
20327
20336
  };
20328
20337
 
20338
+ // src/utils/units.ts
20339
+ function units(amount, simbol = "fri") {
20340
+ if (simbol === "strk") {
20341
+ let numStr = "";
20342
+ if (typeof amount === "bigint") numStr = amount.toString();
20343
+ else if (typeof amount === "string") {
20344
+ if (isHex2(amount)) {
20345
+ numStr = BigInt(amount).toString();
20346
+ } else {
20347
+ numStr = amount;
20348
+ }
20349
+ }
20350
+ const [integer, decimal = "0"] = numStr.split(".");
20351
+ const pdec = decimal.padEnd(18, "0");
20352
+ return `${integer}${pdec}`.replace(/\b0+/g, "");
20353
+ }
20354
+ const bis = BigInt(amount).toString();
20355
+ let strk;
20356
+ if (bis.length <= 18) {
20357
+ strk = `0.${bis.padStart(18, "0")}`;
20358
+ } else {
20359
+ strk = `${bis.slice(0, bis.length - 18)}.${bis.slice(bis.length - 18)}`;
20360
+ }
20361
+ return strk.replace(/(\.[0-9]*[1-9])0+$|\.0*$/, "$1");
20362
+ }
20363
+
20329
20364
  // src/index.ts
20330
20365
  var number = num_exports;
20331
20366
  return __toCommonJS(src_exports);