starknet 8.5.2 → 8.5.4
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 +12 -0
- package/README.md +1 -1
- package/dist/index.d.ts +50 -17
- package/dist/index.global.js +466 -114
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +75 -59
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +75 -59
- package/dist/index.mjs.map +1 -1
- package/package.json +17 -34
package/dist/index.mjs
CHANGED
|
@@ -1106,7 +1106,8 @@ var CairoFelt252 = class _CairoFelt252 {
|
|
|
1106
1106
|
static abiSelector = "core::felt252";
|
|
1107
1107
|
constructor(data) {
|
|
1108
1108
|
_CairoFelt252.validate(data);
|
|
1109
|
-
|
|
1109
|
+
const processedData = _CairoFelt252.__processData(data);
|
|
1110
|
+
this.data = processedData.subarray(processedData.findIndex((x) => x > 0));
|
|
1110
1111
|
}
|
|
1111
1112
|
static __processData(data) {
|
|
1112
1113
|
if (isString(data)) {
|
|
@@ -1709,7 +1710,9 @@ var CairoBytes31 = class _CairoBytes31 {
|
|
|
1709
1710
|
static abiSelector = "core::bytes_31::bytes31";
|
|
1710
1711
|
constructor(data) {
|
|
1711
1712
|
_CairoBytes31.validate(data);
|
|
1712
|
-
|
|
1713
|
+
const processedData = _CairoBytes31.__processData(data);
|
|
1714
|
+
this.data = new Uint8Array(_CairoBytes31.MAX_BYTE_SIZE);
|
|
1715
|
+
this.data.set(processedData, _CairoBytes31.MAX_BYTE_SIZE - processedData.length);
|
|
1713
1716
|
}
|
|
1714
1717
|
static __processData(data) {
|
|
1715
1718
|
if (isString(data)) {
|
|
@@ -1730,11 +1733,16 @@ var CairoBytes31 = class _CairoBytes31 {
|
|
|
1730
1733
|
return uint8ArrayToBigInt(this.data);
|
|
1731
1734
|
}
|
|
1732
1735
|
decodeUtf8() {
|
|
1733
|
-
|
|
1736
|
+
const cutoff = this.data.findIndex((x) => x > 0);
|
|
1737
|
+
const pruned = this.data.subarray(cutoff >= 0 ? cutoff : Infinity);
|
|
1738
|
+
return new TextDecoder().decode(pruned);
|
|
1734
1739
|
}
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1740
|
+
/**
|
|
1741
|
+
* @param padded flag for including leading zeros
|
|
1742
|
+
*/
|
|
1743
|
+
toHexString(padded) {
|
|
1744
|
+
const hex = padded === "padded" ? buf2hex(this.data) : this.toBigInt().toString(16);
|
|
1745
|
+
return addHexPrefix(hex);
|
|
1738
1746
|
}
|
|
1739
1747
|
static validate(data) {
|
|
1740
1748
|
const byteLength = _CairoBytes31.__processData(data).length;
|
|
@@ -1792,10 +1800,13 @@ var errorCodes = {
|
|
|
1792
1800
|
UNSUPPORTED_TX_VERSION: 61,
|
|
1793
1801
|
UNSUPPORTED_CONTRACT_CLASS_VERSION: 62,
|
|
1794
1802
|
UNEXPECTED_ERROR: 63,
|
|
1803
|
+
REPLACEMENT_TRANSACTION_UNDERPRICED: 64,
|
|
1804
|
+
FEE_BELOW_MINIMUM: 65,
|
|
1795
1805
|
INVALID_SUBSCRIPTION_ID: 66,
|
|
1796
1806
|
TOO_MANY_ADDRESSES_IN_FILTER: 67,
|
|
1797
1807
|
TOO_MANY_BLOCKS_BACK: 68,
|
|
1798
1808
|
COMPILATION_ERROR: 100,
|
|
1809
|
+
//
|
|
1799
1810
|
INVALID_ADDRESS: 150,
|
|
1800
1811
|
TOKEN_NOT_SUPPORTED: 151,
|
|
1801
1812
|
INVALID_SIGNATURE: 153,
|
|
@@ -2030,11 +2041,11 @@ var CairoByteArray = class _CairoByteArray {
|
|
|
2030
2041
|
]);
|
|
2031
2042
|
}
|
|
2032
2043
|
decodeUtf8() {
|
|
2033
|
-
const allBytes = this.
|
|
2044
|
+
const allBytes = concatenateArrayBuffer(this.toElements());
|
|
2034
2045
|
return new TextDecoder().decode(allBytes);
|
|
2035
2046
|
}
|
|
2036
2047
|
toBigInt() {
|
|
2037
|
-
const allBytes = this.
|
|
2048
|
+
const allBytes = concatenateArrayBuffer(this.toElements());
|
|
2038
2049
|
if (allBytes.length === 0) {
|
|
2039
2050
|
return 0n;
|
|
2040
2051
|
}
|
|
@@ -2045,15 +2056,39 @@ var CairoByteArray = class _CairoByteArray {
|
|
|
2045
2056
|
return result;
|
|
2046
2057
|
}
|
|
2047
2058
|
toHexString() {
|
|
2048
|
-
const allBytes = this.
|
|
2059
|
+
const allBytes = concatenateArrayBuffer(this.toElements());
|
|
2049
2060
|
const hexValue = allBytes.length === 0 ? "0" : buf2hex(allBytes);
|
|
2050
2061
|
return addHexPrefix(hexValue);
|
|
2051
2062
|
}
|
|
2052
2063
|
toBuffer() {
|
|
2053
|
-
this.
|
|
2054
|
-
const allBytes = this.reconstructBytes();
|
|
2064
|
+
const allBytes = concatenateArrayBuffer(this.toElements());
|
|
2055
2065
|
return buffer_default.from(allBytes);
|
|
2056
2066
|
}
|
|
2067
|
+
/**
|
|
2068
|
+
* returns an array of all the data chunks and the pending word
|
|
2069
|
+
* when concatenated, represents the original bytes sequence
|
|
2070
|
+
*/
|
|
2071
|
+
toElements() {
|
|
2072
|
+
this.assertInitialized();
|
|
2073
|
+
const allChunks = this.data.flatMap((chunk) => chunk.data);
|
|
2074
|
+
const pendingLen = Number(this.pending_word_len.toBigInt());
|
|
2075
|
+
if (pendingLen) {
|
|
2076
|
+
const pending = new Uint8Array(pendingLen);
|
|
2077
|
+
const paddingDifference = pendingLen - this.pending_word.data.length;
|
|
2078
|
+
pending.set(this.pending_word.data, paddingDifference);
|
|
2079
|
+
allChunks.push(pending);
|
|
2080
|
+
}
|
|
2081
|
+
return allChunks;
|
|
2082
|
+
}
|
|
2083
|
+
/**
|
|
2084
|
+
* Private helper to check if the CairoByteArray is properly initialized
|
|
2085
|
+
*/
|
|
2086
|
+
assertInitialized() {
|
|
2087
|
+
assert(
|
|
2088
|
+
this.data && this.pending_word !== void 0 && this.pending_word_len !== void 0,
|
|
2089
|
+
"CairoByteArray is not properly initialized"
|
|
2090
|
+
);
|
|
2091
|
+
}
|
|
2057
2092
|
static validate(data) {
|
|
2058
2093
|
assert(data !== null && data !== void 0, "Invalid input: null or undefined");
|
|
2059
2094
|
assert(
|
|
@@ -2101,30 +2136,6 @@ var CairoByteArray = class _CairoByteArray {
|
|
|
2101
2136
|
static isAbiType(abiType) {
|
|
2102
2137
|
return abiType === _CairoByteArray.abiSelector;
|
|
2103
2138
|
}
|
|
2104
|
-
/**
|
|
2105
|
-
* Private helper to check if the CairoByteArray is properly initialized
|
|
2106
|
-
*/
|
|
2107
|
-
assertInitialized() {
|
|
2108
|
-
assert(
|
|
2109
|
-
this.data && this.pending_word !== void 0 && this.pending_word_len !== void 0,
|
|
2110
|
-
"CairoByteArray is not properly initialized"
|
|
2111
|
-
);
|
|
2112
|
-
}
|
|
2113
|
-
/**
|
|
2114
|
-
* Private helper to reconstruct the full byte sequence from chunks and pending word
|
|
2115
|
-
*/
|
|
2116
|
-
reconstructBytes() {
|
|
2117
|
-
this.assertInitialized();
|
|
2118
|
-
const allChunks = this.data.flatMap((chunk) => chunk.data);
|
|
2119
|
-
const pendingLen = Number(this.pending_word_len.toBigInt());
|
|
2120
|
-
if (pendingLen) {
|
|
2121
|
-
const pending = new Uint8Array(pendingLen);
|
|
2122
|
-
const paddingDifference = pendingLen - this.pending_word.data.length;
|
|
2123
|
-
pending.set(this.pending_word.data, paddingDifference);
|
|
2124
|
-
allChunks.push(pending);
|
|
2125
|
-
}
|
|
2126
|
-
return concatenateArrayBuffer(allChunks);
|
|
2127
|
-
}
|
|
2128
2139
|
static factoryFromApiResponse(responseIterator) {
|
|
2129
2140
|
const data = Array.from(
|
|
2130
2141
|
{ length: Number(getNext(responseIterator)) },
|
|
@@ -5699,7 +5710,7 @@ var RpcChannel = class {
|
|
|
5699
5710
|
}
|
|
5700
5711
|
/**
|
|
5701
5712
|
* fetch rpc node specVersion
|
|
5702
|
-
* @example this.specVersion = "0.
|
|
5713
|
+
* @example this.specVersion = "0.8.1"
|
|
5703
5714
|
*/
|
|
5704
5715
|
getSpecVersion() {
|
|
5705
5716
|
return this.fetchEndpoint("starknet_specVersion");
|
|
@@ -5850,21 +5861,22 @@ var RpcChannel = class {
|
|
|
5850
5861
|
}
|
|
5851
5862
|
async waitForTransaction(txHash, options) {
|
|
5852
5863
|
const transactionHash = toHex(txHash);
|
|
5853
|
-
let
|
|
5864
|
+
let retries = options?.retries ?? this.retries;
|
|
5865
|
+
let lifeCycleRetries = options?.lifeCycleRetries ?? 3;
|
|
5854
5866
|
let onchain = false;
|
|
5855
5867
|
let isErrorState = false;
|
|
5856
5868
|
const retryInterval = options?.retryInterval ?? this.transactionRetryIntervalDefault;
|
|
5857
|
-
const errorStates = options?.errorStates ?? [
|
|
5858
|
-
RPCSPEC08.ETransactionStatus.REJECTED
|
|
5859
|
-
// TODO: commented out to preserve the long-standing behavior of "reverted" not being treated as an error by default
|
|
5860
|
-
// should decide which behavior to keep in the future
|
|
5861
|
-
// RPC.ETransactionExecutionStatus.REVERTED,
|
|
5862
|
-
];
|
|
5869
|
+
const errorStates = options?.errorStates ?? [RPCSPEC08.ETransactionStatus.REJECTED];
|
|
5863
5870
|
const successStates = options?.successStates ?? [
|
|
5864
5871
|
// RPC.ETransactionExecutionStatus.SUCCEEDED, Starknet 0.14.0 this one can have incomplete events
|
|
5865
5872
|
RPCSPEC08.ETransactionStatus.ACCEPTED_ON_L2,
|
|
5866
5873
|
RPCSPEC08.ETransactionStatus.ACCEPTED_ON_L1
|
|
5867
5874
|
];
|
|
5875
|
+
const LifeCycleErrorMessages = {
|
|
5876
|
+
[RPCSPEC09.ETransactionStatus.RECEIVED]: SYSTEM_MESSAGES.txEvictedFromMempool,
|
|
5877
|
+
[RPCSPEC09.ETransactionStatus.PRE_CONFIRMED]: SYSTEM_MESSAGES.consensusFailed,
|
|
5878
|
+
[RPCSPEC09.ETransactionStatus.CANDIDATE]: SYSTEM_MESSAGES.txFailsBlockBuildingValidation
|
|
5879
|
+
};
|
|
5868
5880
|
const txLife = [];
|
|
5869
5881
|
let txStatus;
|
|
5870
5882
|
while (!onchain) {
|
|
@@ -5893,15 +5905,11 @@ var RpcChannel = class {
|
|
|
5893
5905
|
}
|
|
5894
5906
|
if (error instanceof RpcError && error.isType("TXN_HASH_NOT_FOUND")) {
|
|
5895
5907
|
logger.info("txLife: ", txLife);
|
|
5896
|
-
const
|
|
5897
|
-
|
|
5898
|
-
[RPCSPEC09.ETransactionStatus.PRE_CONFIRMED]: SYSTEM_MESSAGES.consensusFailed,
|
|
5899
|
-
[RPCSPEC09.ETransactionStatus.CANDIDATE]: SYSTEM_MESSAGES.txFailsBlockBuildingValidation
|
|
5900
|
-
};
|
|
5901
|
-
const errorMessage = errorMessages[txLife.at(-1)];
|
|
5902
|
-
if (errorMessage) {
|
|
5908
|
+
const errorMessage = LifeCycleErrorMessages[txLife.at(-1)];
|
|
5909
|
+
if (errorMessage && lifeCycleRetries <= 0) {
|
|
5903
5910
|
throw new Error(errorMessage);
|
|
5904
5911
|
}
|
|
5912
|
+
lifeCycleRetries -= 1;
|
|
5905
5913
|
}
|
|
5906
5914
|
if (retries <= 0) {
|
|
5907
5915
|
throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
|
|
@@ -6291,14 +6299,14 @@ var RpcChannel2 = class {
|
|
|
6291
6299
|
}
|
|
6292
6300
|
/**
|
|
6293
6301
|
* fetch rpc node specVersion
|
|
6294
|
-
* @example this.specVersion = "0.
|
|
6302
|
+
* @example this.specVersion = "0.9.0"
|
|
6295
6303
|
*/
|
|
6296
6304
|
getSpecVersion() {
|
|
6297
6305
|
return this.fetchEndpoint("starknet_specVersion");
|
|
6298
6306
|
}
|
|
6299
6307
|
/**
|
|
6300
6308
|
* fetch if undefined else just return this.specVersion
|
|
6301
|
-
* @example this.specVersion = "0.
|
|
6309
|
+
* @example this.specVersion = "0.9.0"
|
|
6302
6310
|
*/
|
|
6303
6311
|
async setUpSpecVersion() {
|
|
6304
6312
|
if (!this.specVersion) {
|
|
@@ -6442,7 +6450,8 @@ var RpcChannel2 = class {
|
|
|
6442
6450
|
}
|
|
6443
6451
|
async waitForTransaction(txHash, options) {
|
|
6444
6452
|
const transactionHash = toHex(txHash);
|
|
6445
|
-
let
|
|
6453
|
+
let retries = options?.retries ?? this.retries;
|
|
6454
|
+
let lifeCycleRetries = options?.lifeCycleRetries ?? 3;
|
|
6446
6455
|
let onchain = false;
|
|
6447
6456
|
let isErrorState = false;
|
|
6448
6457
|
const retryInterval = options?.retryInterval ?? this.transactionRetryIntervalDefault;
|
|
@@ -6452,6 +6461,11 @@ var RpcChannel2 = class {
|
|
|
6452
6461
|
RPCSPEC09.ETransactionFinalityStatus.ACCEPTED_ON_L2,
|
|
6453
6462
|
RPCSPEC09.ETransactionFinalityStatus.ACCEPTED_ON_L1
|
|
6454
6463
|
];
|
|
6464
|
+
const errorMessages = {
|
|
6465
|
+
[RPCSPEC09.ETransactionStatus.RECEIVED]: SYSTEM_MESSAGES.txEvictedFromMempool,
|
|
6466
|
+
[RPCSPEC09.ETransactionStatus.PRE_CONFIRMED]: SYSTEM_MESSAGES.consensusFailed,
|
|
6467
|
+
[RPCSPEC09.ETransactionStatus.CANDIDATE]: SYSTEM_MESSAGES.txFailsBlockBuildingValidation
|
|
6468
|
+
};
|
|
6455
6469
|
const txLife = [];
|
|
6456
6470
|
let txStatus;
|
|
6457
6471
|
while (!onchain) {
|
|
@@ -6480,15 +6494,11 @@ var RpcChannel2 = class {
|
|
|
6480
6494
|
}
|
|
6481
6495
|
if (error instanceof RpcError && error.isType("TXN_HASH_NOT_FOUND")) {
|
|
6482
6496
|
logger.info("txLife: ", txLife);
|
|
6483
|
-
const errorMessages = {
|
|
6484
|
-
[RPCSPEC09.ETransactionStatus.RECEIVED]: SYSTEM_MESSAGES.txEvictedFromMempool,
|
|
6485
|
-
[RPCSPEC09.ETransactionStatus.PRE_CONFIRMED]: SYSTEM_MESSAGES.consensusFailed,
|
|
6486
|
-
[RPCSPEC09.ETransactionStatus.CANDIDATE]: SYSTEM_MESSAGES.txFailsBlockBuildingValidation
|
|
6487
|
-
};
|
|
6488
6497
|
const errorMessage = errorMessages[txLife.at(-1)];
|
|
6489
|
-
if (errorMessage) {
|
|
6498
|
+
if (errorMessage && lifeCycleRetries <= 0) {
|
|
6490
6499
|
throw new Error(errorMessage);
|
|
6491
6500
|
}
|
|
6501
|
+
lifeCycleRetries -= 1;
|
|
6492
6502
|
}
|
|
6493
6503
|
if (retries <= 0) {
|
|
6494
6504
|
throw new Error(`waitForTransaction timed-out with retries ${this.retries}`);
|
|
@@ -7675,12 +7685,15 @@ function createTransactionReceipt(receipt) {
|
|
|
7675
7685
|
match(callbacks) {
|
|
7676
7686
|
return statusReceipt in callbacks ? callbacks[statusReceipt](value) : callbacks._();
|
|
7677
7687
|
},
|
|
7688
|
+
// @ts-ignore - docs
|
|
7678
7689
|
isSuccess() {
|
|
7679
7690
|
return statusReceipt === "SUCCEEDED";
|
|
7680
7691
|
},
|
|
7692
|
+
// @ts-ignore - docs
|
|
7681
7693
|
isReverted() {
|
|
7682
7694
|
return statusReceipt === "REVERTED";
|
|
7683
7695
|
},
|
|
7696
|
+
// @ts-ignore - docs
|
|
7684
7697
|
isError() {
|
|
7685
7698
|
return false;
|
|
7686
7699
|
}
|
|
@@ -7693,12 +7706,15 @@ function createTransactionReceipt(receipt) {
|
|
|
7693
7706
|
match(callbacks) {
|
|
7694
7707
|
return "ERROR" in callbacks ? callbacks.ERROR(errorValue) : callbacks._();
|
|
7695
7708
|
},
|
|
7709
|
+
// @ts-ignore - docs
|
|
7696
7710
|
isSuccess() {
|
|
7697
7711
|
return false;
|
|
7698
7712
|
},
|
|
7713
|
+
// @ts-ignore - docs
|
|
7699
7714
|
isReverted() {
|
|
7700
7715
|
return false;
|
|
7701
7716
|
},
|
|
7717
|
+
// @ts-ignore - docs
|
|
7702
7718
|
isError() {
|
|
7703
7719
|
return true;
|
|
7704
7720
|
}
|