starknet 4.21.0 → 4.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,16 @@
1
+ # [4.22.0](https://github.com/0xs34n/starknet.js/compare/v4.21.1...v4.22.0) (2023-02-22)
2
+
3
+ ### Features
4
+
5
+ - move starkname to provider ([8e88ed0](https://github.com/0xs34n/starknet.js/commit/8e88ed0dd9f651dd9decea75dfdae2357e6bfa4a))
6
+
7
+ ## [4.21.1](https://github.com/0xs34n/starknet.js/compare/v4.21.0...v4.21.1) (2023-02-20)
8
+
9
+ ### Bug Fixes
10
+
11
+ - remove hex prefix should work insensitive, for both 0x and 0X ([53323d4](https://github.com/0xs34n/starknet.js/commit/53323d434d5edbeee03c4262935676c950a761d3))
12
+ - repair decodeShortString for integer strings ([1d6adf0](https://github.com/0xs34n/starknet.js/commit/1d6adf01a64f93b7016d083b81dba4e409371e74))
13
+
1
14
  # [4.21.0](https://github.com/0xs34n/starknet.js/compare/v4.20.0...v4.21.0) (2023-01-18)
2
15
 
3
16
  ### Bug Fixes
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  </p>
5
5
 
6
6
  <!-- tag line -->
7
- <h4 align='center'> JavaScript library for StarkNet.</h4>
7
+ <h4 align='center'> JavaScript library for Starknet.</h4>
8
8
 
9
9
  <!-- primary badges -->
10
10
  <p align="center">
@@ -50,7 +50,7 @@ Import `starknet` and use the [API](https://www.starknetjs.com/docs/API/)
50
50
 
51
51
  Please refer to the following code example [here](https://github.com/0xs34n/starknet.js-workshop)
52
52
 
53
- Guides can be found [here](https://www.starknetjs.com/guides/intro)
53
+ Guides can be found [here](https://www.starknetjs.com/docs/guides/intro)
54
54
 
55
55
  ## 🌐 API
56
56
 
package/dist/index.d.ts CHANGED
@@ -64,9 +64,9 @@ declare namespace number {
64
64
  /**
65
65
  * Starknet RPC version 0.2.0
66
66
  *
67
- * StarkNet Node API 0.45.0 - rpc 0.2.1
68
- * StarkNet Node Write API 0.3.0 - rpc 0.2.1
69
- * StarkNet Trace API 0.4.0 - rpc 0.2.1
67
+ * Starknet Node API 0.45.0 - rpc 0.2.1
68
+ * Starknet Node Write API 0.3.0 - rpc 0.2.1
69
+ * Starknet Trace API 0.4.0 - rpc 0.2.1
70
70
  *
71
71
  * TypeScript Representation of OpenRpc protocol types
72
72
  */
@@ -1512,7 +1512,7 @@ declare abstract class ProviderInterface {
1512
1512
  */
1513
1513
  abstract getChainId(): Promise<StarknetChainId>;
1514
1514
  /**
1515
- * Calls a function on the StarkNet contract.
1515
+ * Calls a function on the Starknet contract.
1516
1516
  *
1517
1517
  * @param call transaction to be called
1518
1518
  * @param blockIdentifier block identifier
@@ -1806,6 +1806,8 @@ declare class RpcProvider implements ProviderInterface {
1806
1806
  */
1807
1807
  getEvents(eventFilter: RPC.EventFilter): Promise<RPC.GetEventsResponse>;
1808
1808
  getSimulateTransaction(_invocation: Invocation, _invocationDetails: InvocationsDetailsWithNonce, _blockIdentifier?: BlockIdentifier): Promise<TransactionSimulationResponse>;
1809
+ getStarkName(address: BigNumberish, StarknetIdContract?: string): Promise<string>;
1810
+ getAddressFromStarkName(name: string, StarknetIdContract?: string): Promise<string>;
1809
1811
  }
1810
1812
 
1811
1813
  declare type NetworkName = 'mainnet-alpha' | 'goerli-alpha' | 'goerli-alpha-2';
@@ -1884,6 +1886,8 @@ declare class SequencerProvider implements ProviderInterface {
1884
1886
  getSimulateTransaction(invocation: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<TransactionSimulationResponse>;
1885
1887
  getStateUpdate(blockIdentifier?: BlockIdentifier): Promise<StateUpdateResponse>;
1886
1888
  getBlockTraces(blockIdentifier?: BlockIdentifier): Promise<Sequencer.BlockTransactionTracesResponse>;
1889
+ getStarkName(address: BigNumberish, StarknetIdContract?: string): Promise<string>;
1890
+ getAddressFromStarkName(name: string, StarknetIdContract?: string): Promise<string>;
1887
1891
  }
1888
1892
 
1889
1893
  interface ProviderOptions {
@@ -1916,6 +1920,8 @@ declare class Provider implements ProviderInterface {
1916
1920
  waitForTransaction(txHash: BigNumberish, retryInterval?: number, successStates?: Array<Status>): Promise<GetTransactionReceiptResponse>;
1917
1921
  getSimulateTransaction(invocation: Invocation, invocationDetails: InvocationsDetailsWithNonce, blockIdentifier?: BlockIdentifier): Promise<TransactionSimulationResponse>;
1918
1922
  getStateUpdate(blockIdentifier?: BlockIdentifier): Promise<StateUpdateResponse>;
1923
+ getStarkName(address: BigNumberish, StarknetIdContract?: string): Promise<string>;
1924
+ getAddressFromStarkName(name: string, StarknetIdContract?: string): Promise<string>;
1919
1925
  }
1920
1926
 
1921
1927
  declare class LibraryError extends CustomError {
@@ -2391,8 +2397,6 @@ declare class Account extends Provider implements AccountInterface {
2391
2397
  address: string;
2392
2398
  constructor(providerOrOptions: ProviderOptions | ProviderInterface, address: string, keyPairOrSigner: KeyPair | SignerInterface);
2393
2399
  getNonce(blockIdentifier?: BlockIdentifier): Promise<BigNumberish>;
2394
- getStarkName(StarknetIdContract?: string): Promise<string | Error>;
2395
- getAddressFromStarkName(name: string, StarknetIdContract?: string): Promise<string | Error>;
2396
2400
  estimateFee(calls: AllowArray<Call>, estimateFeeDetails?: EstimateFeeDetails | undefined): Promise<EstimateFee>;
2397
2401
  estimateInvokeFee(calls: AllowArray<Call>, { nonce: providedNonce, blockIdentifier }?: EstimateFeeDetails): Promise<EstimateFee>;
2398
2402
  estimateDeclareFee({ classHash, contract }: DeclareContractPayload, { blockIdentifier, nonce: providedNonce }?: EstimateFeeDetails): Promise<EstimateFee>;
@@ -2415,6 +2419,8 @@ declare class Account extends Provider implements AccountInterface {
2415
2419
  buildAccountDeployPayload({ classHash, addressSalt, constructorCalldata, contractAddress: providedContractAddress, }: DeployAccountContractPayload, { nonce, chainId, version, maxFee }: InvocationsSignerDetails): Promise<DeployAccountContractTransaction>;
2416
2420
  buildUDCContractPayload(payload: UniversalDeployerContractPayload | UniversalDeployerContractPayload[]): Call[];
2417
2421
  simulateTransaction(calls: AllowArray<Call>, { nonce: providedNonce, blockIdentifier }?: EstimateFeeDetails): Promise<TransactionSimulation>;
2422
+ getStarkName(address?: BigNumberish, // default to the wallet address
2423
+ StarknetIdContract?: string): Promise<string>;
2418
2424
  }
2419
2425
 
2420
2426
  declare type CallOptions = {
@@ -2845,17 +2851,43 @@ declare namespace uint256 {
2845
2851
 
2846
2852
  declare function isASCII(str: string): boolean;
2847
2853
  declare function isShortString(str: string): boolean;
2854
+ declare function isDecimalString(decim: string): boolean;
2855
+ /**
2856
+ * Convert an ASCII string to an hexadecimal string.
2857
+ * @param str - ASCII string -
2858
+ * 31 characters maxi. Ex : "uri/item23.jpg"
2859
+ * @returns a string representing an Hex number 248 bits max.
2860
+ * @Example
2861
+ * ```typescript
2862
+ * const myEncodedString: string = encodeShortString("uri/pict/t38.jpg");
2863
+ * ```
2864
+ * returns : string : "0x7572692f706963742f7433382e6a7067"
2865
+ */
2848
2866
  declare function encodeShortString(str: string): string;
2867
+ /**
2868
+ * Convert an hexadecimal or decimal string to an ASCII string.
2869
+ * @param str - string - representing a 248 bits max number.
2870
+ *
2871
+ * Ex : hex : "0x1A4F64EA56" or decimal : "236942575435676423"
2872
+ * @returns a string with 31 characters max.
2873
+ * @Example
2874
+ * ```typescript
2875
+ * const myDecodedString: string = decodeShortString("0x7572692f706963742f7433382e6a7067");
2876
+ * ```
2877
+ * return : string : "uri/pict/t38.jpg"
2878
+ */
2849
2879
  declare function decodeShortString(str: string): string;
2850
2880
 
2851
2881
  declare const shortString_isASCII: typeof isASCII;
2852
2882
  declare const shortString_isShortString: typeof isShortString;
2883
+ declare const shortString_isDecimalString: typeof isDecimalString;
2853
2884
  declare const shortString_encodeShortString: typeof encodeShortString;
2854
2885
  declare const shortString_decodeShortString: typeof decodeShortString;
2855
2886
  declare namespace shortString {
2856
2887
  export {
2857
2888
  shortString_isASCII as isASCII,
2858
2889
  shortString_isShortString as isShortString,
2890
+ shortString_isDecimalString as isDecimalString,
2859
2891
  shortString_encodeShortString as encodeShortString,
2860
2892
  shortString_decodeShortString as decodeShortString,
2861
2893
  };
@@ -14085,7 +14085,7 @@ var starknet = (() => {
14085
14085
  return [...buffer].map((x) => x.toString(16).padStart(2, "0")).join("");
14086
14086
  }
14087
14087
  function removeHexPrefix(hex) {
14088
- return hex.replace(/^0x/, "");
14088
+ return hex.replace(/^0x/i, "");
14089
14089
  }
14090
14090
  function addHexPrefix(hex) {
14091
14091
  return `0x${removeHexPrefix(hex)}`;
@@ -20720,8 +20720,149 @@ var starknet = (() => {
20720
20720
  }
20721
20721
  };
20722
20722
 
20723
- // src/provider/utils.ts
20723
+ // src/provider/starknetId.ts
20724
+ var import_bn3 = __toESM(require_bn());
20725
+
20726
+ // src/utils/starknetId.ts
20724
20727
  var import_bn2 = __toESM(require_bn());
20728
+ var basicAlphabet = "abcdefghijklmnopqrstuvwxyz0123456789-";
20729
+ var basicSizePlusOne = new import_bn2.default(basicAlphabet.length + 1);
20730
+ var bigAlphabet = "\u8FD9\u6765";
20731
+ var basicAlphabetSize = new import_bn2.default(basicAlphabet.length);
20732
+ var bigAlphabetSize = new import_bn2.default(bigAlphabet.length);
20733
+ var bigAlphabetSizePlusOne = new import_bn2.default(bigAlphabet.length + 1);
20734
+ function extractStars(str) {
20735
+ let k = 0;
20736
+ while (str.endsWith(bigAlphabet[bigAlphabet.length - 1])) {
20737
+ str = str.substring(0, str.length - 1);
20738
+ k += 1;
20739
+ }
20740
+ return [str, k];
20741
+ }
20742
+ function useDecoded(encoded) {
20743
+ let decoded = "";
20744
+ encoded.forEach((subdomain) => {
20745
+ while (!subdomain.isZero()) {
20746
+ const code = subdomain.mod(basicSizePlusOne).toNumber();
20747
+ subdomain = subdomain.div(basicSizePlusOne);
20748
+ if (code === basicAlphabet.length) {
20749
+ const nextSubdomain = subdomain.div(bigAlphabetSizePlusOne);
20750
+ if (nextSubdomain.isZero()) {
20751
+ const code2 = subdomain.mod(bigAlphabetSizePlusOne).toNumber();
20752
+ subdomain = nextSubdomain;
20753
+ if (code2 === 0)
20754
+ decoded += basicAlphabet[0];
20755
+ else
20756
+ decoded += bigAlphabet[code2 - 1];
20757
+ } else {
20758
+ const code2 = subdomain.mod(bigAlphabetSize).toNumber();
20759
+ decoded += bigAlphabet[code2];
20760
+ subdomain = subdomain.div(bigAlphabetSize);
20761
+ }
20762
+ } else
20763
+ decoded += basicAlphabet[code];
20764
+ }
20765
+ const [str, k] = extractStars(decoded);
20766
+ if (k)
20767
+ decoded = str + (k % 2 === 0 ? bigAlphabet[bigAlphabet.length - 1].repeat(k / 2 - 1) + bigAlphabet[0] + basicAlphabet[1] : bigAlphabet[bigAlphabet.length - 1].repeat((k - 1) / 2 + 1));
20768
+ decoded += ".";
20769
+ });
20770
+ if (!decoded) {
20771
+ return decoded;
20772
+ }
20773
+ return decoded.concat("stark");
20774
+ }
20775
+ function useEncoded(decoded) {
20776
+ let encoded = new import_bn2.default(0);
20777
+ let multiplier = new import_bn2.default(1);
20778
+ if (decoded.endsWith(bigAlphabet[0] + basicAlphabet[1])) {
20779
+ const [str, k] = extractStars(decoded.substring(0, decoded.length - 2));
20780
+ decoded = str + bigAlphabet[bigAlphabet.length - 1].repeat(2 * (k + 1));
20781
+ } else {
20782
+ const [str, k] = extractStars(decoded);
20783
+ if (k)
20784
+ decoded = str + bigAlphabet[bigAlphabet.length - 1].repeat(1 + 2 * (k - 1));
20785
+ }
20786
+ for (let i = 0; i < decoded.length; i += 1) {
20787
+ const char = decoded[i];
20788
+ const index = basicAlphabet.indexOf(char);
20789
+ const bnIndex = new import_bn2.default(basicAlphabet.indexOf(char));
20790
+ if (index !== -1) {
20791
+ if (i === decoded.length - 1 && decoded[i] === basicAlphabet[0]) {
20792
+ encoded = encoded.add(multiplier.mul(basicAlphabetSize));
20793
+ multiplier = multiplier.mul(basicSizePlusOne);
20794
+ multiplier = multiplier.mul(basicSizePlusOne);
20795
+ } else {
20796
+ encoded = encoded.add(multiplier.mul(bnIndex));
20797
+ multiplier = multiplier.mul(basicSizePlusOne);
20798
+ }
20799
+ } else if (bigAlphabet.indexOf(char) !== -1) {
20800
+ encoded = encoded.add(multiplier.mul(basicAlphabetSize));
20801
+ multiplier = multiplier.mul(basicSizePlusOne);
20802
+ const newid = (i === decoded.length - 1 ? 1 : 0) + bigAlphabet.indexOf(char);
20803
+ encoded = encoded.add(multiplier.mul(new import_bn2.default(newid)));
20804
+ multiplier = multiplier.mul(bigAlphabetSize);
20805
+ }
20806
+ }
20807
+ return encoded;
20808
+ }
20809
+ function getStarknetIdContract(chainId) {
20810
+ const starknetIdMainnetContract = "0x6ac597f8116f886fa1c97a23fa4e08299975ecaf6b598873ca6792b9bbfb678";
20811
+ const starknetIdTestnetContract = "0x05cf267a0af6101667013fc6bd3f6c11116a14cda9b8c4b1198520d59f900b17";
20812
+ switch (chainId) {
20813
+ case "0x534e5f4d41494e" /* MAINNET */:
20814
+ return starknetIdMainnetContract;
20815
+ case "0x534e5f474f45524c49" /* TESTNET */:
20816
+ return starknetIdTestnetContract;
20817
+ default:
20818
+ throw new Error("Starknet.id is not yet deployed on this network");
20819
+ }
20820
+ }
20821
+
20822
+ // src/provider/starknetId.ts
20823
+ async function getStarkName(provider, address, StarknetIdContract) {
20824
+ const chainId = await provider.getChainId();
20825
+ const contract = StarknetIdContract ?? getStarknetIdContract(chainId);
20826
+ try {
20827
+ const hexDomain = await provider.callContract({
20828
+ contractAddress: contract,
20829
+ entrypoint: "address_to_domain",
20830
+ calldata: compileCalldata({
20831
+ address: toHex(toBN(address))
20832
+ })
20833
+ });
20834
+ const decimalDomain = hexDomain.result.map((element) => new import_bn3.BN(hexToDecimalString(element))).slice(1);
20835
+ const stringDomain = useDecoded(decimalDomain);
20836
+ if (!stringDomain) {
20837
+ throw Error("Starkname not found");
20838
+ }
20839
+ return stringDomain;
20840
+ } catch (e) {
20841
+ if (e instanceof Error && e.message === "Starkname not found") {
20842
+ throw e;
20843
+ }
20844
+ throw Error("Could not get stark name");
20845
+ }
20846
+ }
20847
+ async function getAddressFromStarkName(provider, name, StarknetIdContract) {
20848
+ const chainId = await provider.getChainId();
20849
+ const contract = StarknetIdContract ?? getStarknetIdContract(chainId);
20850
+ try {
20851
+ const addressData = await provider.callContract({
20852
+ contractAddress: contract,
20853
+ entrypoint: "domain_to_address",
20854
+ calldata: compileCalldata({
20855
+ domain: [useEncoded(name.replace(".stark", "")).toString(10)]
20856
+ })
20857
+ });
20858
+ return addressData.result[0];
20859
+ } catch {
20860
+ throw Error("Could not get address from stark name");
20861
+ }
20862
+ }
20863
+
20864
+ // src/provider/utils.ts
20865
+ var import_bn4 = __toESM(require_bn());
20725
20866
  var validBlockTags = ["latest", "pending"];
20726
20867
  var Block = class {
20727
20868
  constructor(_identifier) {
@@ -20735,7 +20876,7 @@ var starknet = (() => {
20735
20876
  setIdentifier(__identifier) {
20736
20877
  if (typeof __identifier === "string" && isHex(__identifier)) {
20737
20878
  this.hash = __identifier;
20738
- } else if (import_bn2.BN.isBN(__identifier)) {
20879
+ } else if (import_bn4.BN.isBN(__identifier)) {
20739
20880
  this.hash = toHex(__identifier);
20740
20881
  } else if (typeof __identifier === "number") {
20741
20882
  this.number = __identifier;
@@ -21064,6 +21205,12 @@ var starknet = (() => {
21064
21205
  async getSimulateTransaction(_invocation, _invocationDetails, _blockIdentifier) {
21065
21206
  throw new Error("RPC does not implement simulateTransaction function");
21066
21207
  }
21208
+ async getStarkName(address, StarknetIdContract) {
21209
+ return getStarkName(this, address, StarknetIdContract);
21210
+ }
21211
+ async getAddressFromStarkName(name, StarknetIdContract) {
21212
+ return getAddressFromStarkName(this, name, StarknetIdContract);
21213
+ }
21067
21214
  };
21068
21215
 
21069
21216
  // src/provider/sequencer.ts
@@ -21630,6 +21777,12 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
21630
21777
  const args = new Block(blockIdentifier).sequencerIdentifier;
21631
21778
  return this.fetchEndpoint("get_block_traces", { ...args });
21632
21779
  }
21780
+ async getStarkName(address, StarknetIdContract) {
21781
+ return getStarkName(this, address, StarknetIdContract);
21782
+ }
21783
+ async getAddressFromStarkName(name, StarknetIdContract) {
21784
+ return getAddressFromStarkName(this, name, StarknetIdContract);
21785
+ }
21633
21786
  };
21634
21787
 
21635
21788
  // src/provider/default.ts
@@ -21720,6 +21873,12 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
21720
21873
  async getStateUpdate(blockIdentifier) {
21721
21874
  return this.provider.getStateUpdate(blockIdentifier);
21722
21875
  }
21876
+ async getStarkName(address, StarknetIdContract) {
21877
+ return getStarkName(this, address, StarknetIdContract);
21878
+ }
21879
+ async getAddressFromStarkName(name, StarknetIdContract) {
21880
+ return getAddressFromStarkName(this, name, StarknetIdContract);
21881
+ }
21723
21882
  };
21724
21883
 
21725
21884
  // src/provider/interface.ts
@@ -21730,7 +21889,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
21730
21889
  var defaultProvider = new Provider();
21731
21890
 
21732
21891
  // src/utils/calldata.ts
21733
- var import_bn3 = __toESM(require_bn());
21892
+ var import_bn5 = __toESM(require_bn());
21734
21893
  var import_minimalistic_assert4 = __toESM(require_minimalistic_assert());
21735
21894
  var CheckCallData = class {
21736
21895
  constructor(abi) {
@@ -21781,7 +21940,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
21781
21940
  }
21782
21941
  if (input.type === "felt") {
21783
21942
  (0, import_minimalistic_assert4.default)(
21784
- typeof args[argPosition] === "string" || typeof args[argPosition] === "number" || args[argPosition] instanceof import_bn3.default,
21943
+ typeof args[argPosition] === "string" || typeof args[argPosition] === "number" || args[argPosition] instanceof import_bn5.default,
21785
21944
  `arg ${input.name} should be a felt (string, number, BigNumber)`
21786
21945
  );
21787
21946
  argPosition += 1;
@@ -21806,7 +21965,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
21806
21965
  if (input.type === "felt*") {
21807
21966
  args[argPosition].forEach((felt) => {
21808
21967
  (0, import_minimalistic_assert4.default)(
21809
- typeof felt === "string" || typeof felt === "number" || felt instanceof import_bn3.default,
21968
+ typeof felt === "string" || typeof felt === "number" || felt instanceof import_bn5.default,
21810
21969
  `arg ${input.name} should be an array of string, number or BigNumber`
21811
21970
  );
21812
21971
  });
@@ -21819,7 +21978,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
21819
21978
  );
21820
21979
  args[argPosition].forEach((felt) => {
21821
21980
  (0, import_minimalistic_assert4.default)(
21822
- typeof felt === "string" || typeof felt === "number" || felt instanceof import_bn3.default,
21981
+ typeof felt === "string" || typeof felt === "number" || felt instanceof import_bn5.default,
21823
21982
  `arg ${input.name} should be an array of string, number or BigNumber`
21824
21983
  );
21825
21984
  });
@@ -22220,9 +22379,6 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
22220
22379
  }
22221
22380
  };
22222
22381
 
22223
- // src/account/default.ts
22224
- var import_bn5 = __toESM(require_bn());
22225
-
22226
22382
  // src/signer/interface.ts
22227
22383
  var SignerInterface = class {
22228
22384
  };
@@ -22348,6 +22504,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
22348
22504
  decodeShortString: () => decodeShortString,
22349
22505
  encodeShortString: () => encodeShortString,
22350
22506
  isASCII: () => isASCII,
22507
+ isDecimalString: () => isDecimalString,
22351
22508
  isShortString: () => isShortString
22352
22509
  });
22353
22510
  function isASCII(str) {
@@ -22356,6 +22513,9 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
22356
22513
  function isShortString(str) {
22357
22514
  return str.length <= 31;
22358
22515
  }
22516
+ function isDecimalString(decim) {
22517
+ return /^[0-9]*$/i.test(decim);
22518
+ }
22359
22519
  function encodeShortString(str) {
22360
22520
  if (!isASCII(str))
22361
22521
  throw new Error(`${str} is not an ASCII string`);
@@ -22364,7 +22524,15 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
22364
22524
  return addHexPrefix(str.replace(/./g, (char) => char.charCodeAt(0).toString(16)));
22365
22525
  }
22366
22526
  function decodeShortString(str) {
22367
- return removeHexPrefix(str).replace(/.{2}/g, (hex) => String.fromCharCode(parseInt(hex, 16)));
22527
+ if (!isASCII(str))
22528
+ throw new Error(`${str} is not an ASCII string`);
22529
+ if (isHex(str)) {
22530
+ return removeHexPrefix(str).replace(/.{2}/g, (hex) => String.fromCharCode(parseInt(hex, 16)));
22531
+ }
22532
+ if (isDecimalString(str)) {
22533
+ return decodeShortString("0X".concat(BigInt(str).toString(16)));
22534
+ }
22535
+ throw new Error(`${str} is not Hex or decimal`);
22368
22536
  }
22369
22537
 
22370
22538
  // src/utils/typedData/utils.ts
@@ -22586,99 +22754,6 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
22586
22754
  };
22587
22755
  }
22588
22756
 
22589
- // src/utils/starknetId.ts
22590
- var import_bn4 = __toESM(require_bn());
22591
- var basicAlphabet = "abcdefghijklmnopqrstuvwxyz0123456789-";
22592
- var basicSizePlusOne = new import_bn4.default(basicAlphabet.length + 1);
22593
- var bigAlphabet = "\u8FD9\u6765";
22594
- var basicAlphabetSize = new import_bn4.default(basicAlphabet.length);
22595
- var bigAlphabetSize = new import_bn4.default(bigAlphabet.length);
22596
- var bigAlphabetSizePlusOne = new import_bn4.default(bigAlphabet.length + 1);
22597
- function extractStars(str) {
22598
- let k = 0;
22599
- while (str.endsWith(bigAlphabet[bigAlphabet.length - 1])) {
22600
- str = str.substring(0, str.length - 1);
22601
- k += 1;
22602
- }
22603
- return [str, k];
22604
- }
22605
- function useDecoded(encoded) {
22606
- let decoded = "";
22607
- encoded.forEach((subdomain) => {
22608
- while (!subdomain.isZero()) {
22609
- const code = subdomain.mod(basicSizePlusOne).toNumber();
22610
- subdomain = subdomain.div(basicSizePlusOne);
22611
- if (code === basicAlphabet.length) {
22612
- const nextSubdomain = subdomain.div(bigAlphabetSizePlusOne);
22613
- if (nextSubdomain.isZero()) {
22614
- const code2 = subdomain.mod(bigAlphabetSizePlusOne).toNumber();
22615
- subdomain = nextSubdomain;
22616
- if (code2 === 0)
22617
- decoded += basicAlphabet[0];
22618
- else
22619
- decoded += bigAlphabet[code2 - 1];
22620
- } else {
22621
- const code2 = subdomain.mod(bigAlphabetSize).toNumber();
22622
- decoded += bigAlphabet[code2];
22623
- subdomain = subdomain.div(bigAlphabetSize);
22624
- }
22625
- } else
22626
- decoded += basicAlphabet[code];
22627
- }
22628
- const [str, k] = extractStars(decoded);
22629
- if (k)
22630
- decoded = str + (k % 2 === 0 ? bigAlphabet[bigAlphabet.length - 1].repeat(k / 2 - 1) + bigAlphabet[0] + basicAlphabet[1] : bigAlphabet[bigAlphabet.length - 1].repeat((k - 1) / 2 + 1));
22631
- decoded += ".";
22632
- });
22633
- return decoded.concat("stark");
22634
- }
22635
- function useEncoded(decoded) {
22636
- let encoded = new import_bn4.default(0);
22637
- let multiplier = new import_bn4.default(1);
22638
- if (decoded.endsWith(bigAlphabet[0] + basicAlphabet[1])) {
22639
- const [str, k] = extractStars(decoded.substring(0, decoded.length - 2));
22640
- decoded = str + bigAlphabet[bigAlphabet.length - 1].repeat(2 * (k + 1));
22641
- } else {
22642
- const [str, k] = extractStars(decoded);
22643
- if (k)
22644
- decoded = str + bigAlphabet[bigAlphabet.length - 1].repeat(1 + 2 * (k - 1));
22645
- }
22646
- for (let i = 0; i < decoded.length; i += 1) {
22647
- const char = decoded[i];
22648
- const index = basicAlphabet.indexOf(char);
22649
- const bnIndex = new import_bn4.default(basicAlphabet.indexOf(char));
22650
- if (index !== -1) {
22651
- if (i === decoded.length - 1 && decoded[i] === basicAlphabet[0]) {
22652
- encoded = encoded.add(multiplier.mul(basicAlphabetSize));
22653
- multiplier = multiplier.mul(basicSizePlusOne);
22654
- multiplier = multiplier.mul(basicSizePlusOne);
22655
- } else {
22656
- encoded = encoded.add(multiplier.mul(bnIndex));
22657
- multiplier = multiplier.mul(basicSizePlusOne);
22658
- }
22659
- } else if (bigAlphabet.indexOf(char) !== -1) {
22660
- encoded = encoded.add(multiplier.mul(basicAlphabetSize));
22661
- multiplier = multiplier.mul(basicSizePlusOne);
22662
- const newid = (i === decoded.length - 1 ? 1 : 0) + bigAlphabet.indexOf(char);
22663
- encoded = encoded.add(multiplier.mul(new import_bn4.default(newid)));
22664
- multiplier = multiplier.mul(bigAlphabetSize);
22665
- }
22666
- }
22667
- return encoded;
22668
- }
22669
- function getStarknetIdContract(chainId) {
22670
- const starknetIdMainnetContract = "0x6ac597f8116f886fa1c97a23fa4e08299975ecaf6b598873ca6792b9bbfb678";
22671
- const starknetIdTestnetContract = "0x05cf267a0af6101667013fc6bd3f6c11116a14cda9b8c4b1198520d59f900b17";
22672
- switch (chainId) {
22673
- case "0x534e5f4d41494e" /* MAINNET */:
22674
- return starknetIdMainnetContract;
22675
- case "0x534e5f474f45524c49" /* TESTNET */:
22676
- return starknetIdTestnetContract;
22677
- default:
22678
- throw new Error("Starknet.id is not yet deployed on this network");
22679
- }
22680
- }
22681
-
22682
22757
  // src/account/default.ts
22683
22758
  var Account = class extends Provider {
22684
22759
  constructor(providerOrOptions, address, keyPairOrSigner) {
@@ -22689,40 +22764,6 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
22689
22764
  async getNonce(blockIdentifier) {
22690
22765
  return super.getNonceForAddress(this.address, blockIdentifier);
22691
22766
  }
22692
- async getStarkName(StarknetIdContract) {
22693
- const chainId = await this.getChainId();
22694
- const contract = StarknetIdContract ?? getStarknetIdContract(chainId);
22695
- try {
22696
- const hexDomain = await this.callContract({
22697
- contractAddress: contract,
22698
- entrypoint: "address_to_domain",
22699
- calldata: compileCalldata({
22700
- address: this.address
22701
- })
22702
- });
22703
- const decimalDomain = hexDomain.result.map((element) => new import_bn5.BN(hexToDecimalString(element))).slice(1);
22704
- const stringDomain = useDecoded(decimalDomain);
22705
- return stringDomain;
22706
- } catch {
22707
- return Error("Could not get stark name");
22708
- }
22709
- }
22710
- async getAddressFromStarkName(name, StarknetIdContract) {
22711
- const chainId = await this.getChainId();
22712
- const contract = StarknetIdContract ?? getStarknetIdContract(chainId);
22713
- try {
22714
- const addressData = await this.callContract({
22715
- contractAddress: contract,
22716
- entrypoint: "domain_to_address",
22717
- calldata: compileCalldata({
22718
- domain: [useEncoded(name.replace(".stark", "")).toString(10)]
22719
- })
22720
- });
22721
- return addressData.result[0];
22722
- } catch {
22723
- return Error("Could not get address from stark name");
22724
- }
22725
- }
22726
22767
  async estimateFee(calls, estimateFeeDetails) {
22727
22768
  return this.estimateInvokeFee(calls, estimateFeeDetails);
22728
22769
  }
@@ -23151,6 +23192,9 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
23151
23192
  }
23152
23193
  };
23153
23194
  }
23195
+ async getStarkName(address = this.address, StarknetIdContract) {
23196
+ return super.getStarkName(address, StarknetIdContract);
23197
+ }
23154
23198
  };
23155
23199
 
23156
23200
  // src/account/interface.ts