starknet 4.21.1 → 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 +6 -0
- package/dist/index.d.ts +12 -6
- package/dist/index.global.js +168 -136
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +168 -136
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +168 -136
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
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
|
+
|
|
1
7
|
## [4.21.1](https://github.com/0xs34n/starknet.js/compare/v4.21.0...v4.21.1) (2023-02-20)
|
|
2
8
|
|
|
3
9
|
### Bug Fixes
|
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
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
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
|
|
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 = {
|
package/dist/index.global.js
CHANGED
|
@@ -20720,8 +20720,149 @@ var starknet = (() => {
|
|
|
20720
20720
|
}
|
|
20721
20721
|
};
|
|
20722
20722
|
|
|
20723
|
-
// src/provider/
|
|
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 (
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
};
|
|
@@ -22598,99 +22754,6 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
22598
22754
|
};
|
|
22599
22755
|
}
|
|
22600
22756
|
|
|
22601
|
-
// src/utils/starknetId.ts
|
|
22602
|
-
var import_bn4 = __toESM(require_bn());
|
|
22603
|
-
var basicAlphabet = "abcdefghijklmnopqrstuvwxyz0123456789-";
|
|
22604
|
-
var basicSizePlusOne = new import_bn4.default(basicAlphabet.length + 1);
|
|
22605
|
-
var bigAlphabet = "\u8FD9\u6765";
|
|
22606
|
-
var basicAlphabetSize = new import_bn4.default(basicAlphabet.length);
|
|
22607
|
-
var bigAlphabetSize = new import_bn4.default(bigAlphabet.length);
|
|
22608
|
-
var bigAlphabetSizePlusOne = new import_bn4.default(bigAlphabet.length + 1);
|
|
22609
|
-
function extractStars(str) {
|
|
22610
|
-
let k = 0;
|
|
22611
|
-
while (str.endsWith(bigAlphabet[bigAlphabet.length - 1])) {
|
|
22612
|
-
str = str.substring(0, str.length - 1);
|
|
22613
|
-
k += 1;
|
|
22614
|
-
}
|
|
22615
|
-
return [str, k];
|
|
22616
|
-
}
|
|
22617
|
-
function useDecoded(encoded) {
|
|
22618
|
-
let decoded = "";
|
|
22619
|
-
encoded.forEach((subdomain) => {
|
|
22620
|
-
while (!subdomain.isZero()) {
|
|
22621
|
-
const code = subdomain.mod(basicSizePlusOne).toNumber();
|
|
22622
|
-
subdomain = subdomain.div(basicSizePlusOne);
|
|
22623
|
-
if (code === basicAlphabet.length) {
|
|
22624
|
-
const nextSubdomain = subdomain.div(bigAlphabetSizePlusOne);
|
|
22625
|
-
if (nextSubdomain.isZero()) {
|
|
22626
|
-
const code2 = subdomain.mod(bigAlphabetSizePlusOne).toNumber();
|
|
22627
|
-
subdomain = nextSubdomain;
|
|
22628
|
-
if (code2 === 0)
|
|
22629
|
-
decoded += basicAlphabet[0];
|
|
22630
|
-
else
|
|
22631
|
-
decoded += bigAlphabet[code2 - 1];
|
|
22632
|
-
} else {
|
|
22633
|
-
const code2 = subdomain.mod(bigAlphabetSize).toNumber();
|
|
22634
|
-
decoded += bigAlphabet[code2];
|
|
22635
|
-
subdomain = subdomain.div(bigAlphabetSize);
|
|
22636
|
-
}
|
|
22637
|
-
} else
|
|
22638
|
-
decoded += basicAlphabet[code];
|
|
22639
|
-
}
|
|
22640
|
-
const [str, k] = extractStars(decoded);
|
|
22641
|
-
if (k)
|
|
22642
|
-
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));
|
|
22643
|
-
decoded += ".";
|
|
22644
|
-
});
|
|
22645
|
-
return decoded.concat("stark");
|
|
22646
|
-
}
|
|
22647
|
-
function useEncoded(decoded) {
|
|
22648
|
-
let encoded = new import_bn4.default(0);
|
|
22649
|
-
let multiplier = new import_bn4.default(1);
|
|
22650
|
-
if (decoded.endsWith(bigAlphabet[0] + basicAlphabet[1])) {
|
|
22651
|
-
const [str, k] = extractStars(decoded.substring(0, decoded.length - 2));
|
|
22652
|
-
decoded = str + bigAlphabet[bigAlphabet.length - 1].repeat(2 * (k + 1));
|
|
22653
|
-
} else {
|
|
22654
|
-
const [str, k] = extractStars(decoded);
|
|
22655
|
-
if (k)
|
|
22656
|
-
decoded = str + bigAlphabet[bigAlphabet.length - 1].repeat(1 + 2 * (k - 1));
|
|
22657
|
-
}
|
|
22658
|
-
for (let i = 0; i < decoded.length; i += 1) {
|
|
22659
|
-
const char = decoded[i];
|
|
22660
|
-
const index = basicAlphabet.indexOf(char);
|
|
22661
|
-
const bnIndex = new import_bn4.default(basicAlphabet.indexOf(char));
|
|
22662
|
-
if (index !== -1) {
|
|
22663
|
-
if (i === decoded.length - 1 && decoded[i] === basicAlphabet[0]) {
|
|
22664
|
-
encoded = encoded.add(multiplier.mul(basicAlphabetSize));
|
|
22665
|
-
multiplier = multiplier.mul(basicSizePlusOne);
|
|
22666
|
-
multiplier = multiplier.mul(basicSizePlusOne);
|
|
22667
|
-
} else {
|
|
22668
|
-
encoded = encoded.add(multiplier.mul(bnIndex));
|
|
22669
|
-
multiplier = multiplier.mul(basicSizePlusOne);
|
|
22670
|
-
}
|
|
22671
|
-
} else if (bigAlphabet.indexOf(char) !== -1) {
|
|
22672
|
-
encoded = encoded.add(multiplier.mul(basicAlphabetSize));
|
|
22673
|
-
multiplier = multiplier.mul(basicSizePlusOne);
|
|
22674
|
-
const newid = (i === decoded.length - 1 ? 1 : 0) + bigAlphabet.indexOf(char);
|
|
22675
|
-
encoded = encoded.add(multiplier.mul(new import_bn4.default(newid)));
|
|
22676
|
-
multiplier = multiplier.mul(bigAlphabetSize);
|
|
22677
|
-
}
|
|
22678
|
-
}
|
|
22679
|
-
return encoded;
|
|
22680
|
-
}
|
|
22681
|
-
function getStarknetIdContract(chainId) {
|
|
22682
|
-
const starknetIdMainnetContract = "0x6ac597f8116f886fa1c97a23fa4e08299975ecaf6b598873ca6792b9bbfb678";
|
|
22683
|
-
const starknetIdTestnetContract = "0x05cf267a0af6101667013fc6bd3f6c11116a14cda9b8c4b1198520d59f900b17";
|
|
22684
|
-
switch (chainId) {
|
|
22685
|
-
case "0x534e5f4d41494e" /* MAINNET */:
|
|
22686
|
-
return starknetIdMainnetContract;
|
|
22687
|
-
case "0x534e5f474f45524c49" /* TESTNET */:
|
|
22688
|
-
return starknetIdTestnetContract;
|
|
22689
|
-
default:
|
|
22690
|
-
throw new Error("Starknet.id is not yet deployed on this network");
|
|
22691
|
-
}
|
|
22692
|
-
}
|
|
22693
|
-
|
|
22694
22757
|
// src/account/default.ts
|
|
22695
22758
|
var Account = class extends Provider {
|
|
22696
22759
|
constructor(providerOrOptions, address, keyPairOrSigner) {
|
|
@@ -22701,40 +22764,6 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
22701
22764
|
async getNonce(blockIdentifier) {
|
|
22702
22765
|
return super.getNonceForAddress(this.address, blockIdentifier);
|
|
22703
22766
|
}
|
|
22704
|
-
async getStarkName(StarknetIdContract) {
|
|
22705
|
-
const chainId = await this.getChainId();
|
|
22706
|
-
const contract = StarknetIdContract ?? getStarknetIdContract(chainId);
|
|
22707
|
-
try {
|
|
22708
|
-
const hexDomain = await this.callContract({
|
|
22709
|
-
contractAddress: contract,
|
|
22710
|
-
entrypoint: "address_to_domain",
|
|
22711
|
-
calldata: compileCalldata({
|
|
22712
|
-
address: this.address
|
|
22713
|
-
})
|
|
22714
|
-
});
|
|
22715
|
-
const decimalDomain = hexDomain.result.map((element) => new import_bn5.BN(hexToDecimalString(element))).slice(1);
|
|
22716
|
-
const stringDomain = useDecoded(decimalDomain);
|
|
22717
|
-
return stringDomain;
|
|
22718
|
-
} catch {
|
|
22719
|
-
return Error("Could not get stark name");
|
|
22720
|
-
}
|
|
22721
|
-
}
|
|
22722
|
-
async getAddressFromStarkName(name, StarknetIdContract) {
|
|
22723
|
-
const chainId = await this.getChainId();
|
|
22724
|
-
const contract = StarknetIdContract ?? getStarknetIdContract(chainId);
|
|
22725
|
-
try {
|
|
22726
|
-
const addressData = await this.callContract({
|
|
22727
|
-
contractAddress: contract,
|
|
22728
|
-
entrypoint: "domain_to_address",
|
|
22729
|
-
calldata: compileCalldata({
|
|
22730
|
-
domain: [useEncoded(name.replace(".stark", "")).toString(10)]
|
|
22731
|
-
})
|
|
22732
|
-
});
|
|
22733
|
-
return addressData.result[0];
|
|
22734
|
-
} catch {
|
|
22735
|
-
return Error("Could not get address from stark name");
|
|
22736
|
-
}
|
|
22737
|
-
}
|
|
22738
22767
|
async estimateFee(calls, estimateFeeDetails) {
|
|
22739
22768
|
return this.estimateInvokeFee(calls, estimateFeeDetails);
|
|
22740
22769
|
}
|
|
@@ -23163,6 +23192,9 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
23163
23192
|
}
|
|
23164
23193
|
};
|
|
23165
23194
|
}
|
|
23195
|
+
async getStarkName(address = this.address, StarknetIdContract) {
|
|
23196
|
+
return super.getStarkName(address, StarknetIdContract);
|
|
23197
|
+
}
|
|
23166
23198
|
};
|
|
23167
23199
|
|
|
23168
23200
|
// src/account/interface.ts
|