@solana/rpc-types 2.0.0-canary-20240731173615

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.
Files changed (47) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +158 -0
  3. package/dist/index.browser.cjs +238 -0
  4. package/dist/index.browser.cjs.map +1 -0
  5. package/dist/index.browser.mjs +208 -0
  6. package/dist/index.browser.mjs.map +1 -0
  7. package/dist/index.native.mjs +208 -0
  8. package/dist/index.native.mjs.map +1 -0
  9. package/dist/index.node.cjs +238 -0
  10. package/dist/index.node.cjs.map +1 -0
  11. package/dist/index.node.mjs +208 -0
  12. package/dist/index.node.mjs.map +1 -0
  13. package/dist/types/account-filters.d.ts +16 -0
  14. package/dist/types/account-filters.d.ts.map +1 -0
  15. package/dist/types/account-info.d.ts +43 -0
  16. package/dist/types/account-info.d.ts.map +1 -0
  17. package/dist/types/blockhash.d.ts +12 -0
  18. package/dist/types/blockhash.d.ts.map +1 -0
  19. package/dist/types/cluster-url.d.ts +14 -0
  20. package/dist/types/cluster-url.d.ts.map +1 -0
  21. package/dist/types/commitment.d.ts +3 -0
  22. package/dist/types/commitment.d.ts.map +1 -0
  23. package/dist/types/encoded-bytes.d.ts +13 -0
  24. package/dist/types/encoded-bytes.d.ts.map +1 -0
  25. package/dist/types/index.d.ts +17 -0
  26. package/dist/types/index.d.ts.map +1 -0
  27. package/dist/types/lamports.d.ts +17 -0
  28. package/dist/types/lamports.d.ts.map +1 -0
  29. package/dist/types/rpc-api.d.ts +8 -0
  30. package/dist/types/rpc-api.d.ts.map +1 -0
  31. package/dist/types/stringified-bigint.d.ts +7 -0
  32. package/dist/types/stringified-bigint.d.ts.map +1 -0
  33. package/dist/types/stringified-number.d.ts +7 -0
  34. package/dist/types/stringified-number.d.ts.map +1 -0
  35. package/dist/types/token-amount.d.ts +9 -0
  36. package/dist/types/token-amount.d.ts.map +1 -0
  37. package/dist/types/token-balance.d.ts +14 -0
  38. package/dist/types/token-balance.d.ts.map +1 -0
  39. package/dist/types/transaction-error.d.ts +23 -0
  40. package/dist/types/transaction-error.d.ts.map +1 -0
  41. package/dist/types/transaction.d.ts +254 -0
  42. package/dist/types/transaction.d.ts.map +1 -0
  43. package/dist/types/typed-numbers.d.ts +14 -0
  44. package/dist/types/typed-numbers.d.ts.map +1 -0
  45. package/dist/types/unix-timestamp.d.ts +7 -0
  46. package/dist/types/unix-timestamp.d.ts.map +1 -0
  47. package/package.json +82 -0
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2023 Solana Labs, Inc
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,158 @@
1
+ [![npm][npm-image]][npm-url]
2
+ [![npm-downloads][npm-downloads-image]][npm-url]
3
+ [![semantic-release][semantic-release-image]][semantic-release-url]
4
+ <br />
5
+ [![code-style-prettier][code-style-prettier-image]][code-style-prettier-url]
6
+
7
+ [code-style-prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square
8
+ [code-style-prettier-url]: https://github.com/prettier/prettier
9
+ [npm-downloads-image]: https://img.shields.io/npm/dm/@solana/rpc-types/experimental.svg?style=flat
10
+ [npm-image]: https://img.shields.io/npm/v/@solana/rpc-types/experimental.svg?style=flat
11
+ [npm-url]: https://www.npmjs.com/package/@solana/rpc-types/v/experimental
12
+ [semantic-release-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
13
+ [semantic-release-url]: https://github.com/semantic-release/semantic-release
14
+
15
+ # @solana/rpc-types
16
+
17
+ This package defines types for values used in the [Solana JSON-RPC](https://docs.solana.com/api/http) and a series of helpers for working with them. It can be used standalone, but it is also exported as part of the Solana JavaScript SDK [`@solana/web3.js@experimental`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/library).
18
+
19
+ ## Types
20
+
21
+ ### `Commitment`
22
+
23
+ A type that enumerates the possible commitment statuses &ndash; each a measure of the network confirmation and stake levels on a particular block. Read more about the statuses themselves, [here](https://docs.solana.com/cluster/commitments).
24
+
25
+ ### `LamportsUnsafeBeyond2Pow53Minus1`
26
+
27
+ This type represents an integer value denominated in Lamports (ie. $1 \times 10^{-9}$ &#x25CE;).
28
+
29
+ **Note**: Despite the fact that this type is represented as a `bigint` in client code and a `u64` in server code, the JSON-RPC implementation represents Lamports as an IEEE 754 floating point number. This means that you can only safely send or receive values up to $2^{53} - 1$ between the client and the RPC server. See https://github.com/solana-labs/solana/issues/30741 for more detail.
30
+
31
+ ### `StringifiedBigInt`
32
+
33
+ This type represents a `bigint` which has been encoded as a string for transit over a transport that does not support `bigint` values natively. The JSON-RPC is such a transport.
34
+
35
+ ### `StringifiedNumber`
36
+
37
+ This type represents a number which has been encoded as a string for transit over a transport where loss of precision when using the native number type is a concern. The JSON-RPC is such a transport.
38
+
39
+ ### `UnixTimestamp`
40
+
41
+ This type represents a number in the range $[-8.64 \times 10^{15}, 8.64 \times 10^{15}]$. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#the_epoch_timestamps_and_invalid_date
42
+
43
+ ## Functions
44
+
45
+ ### `assertIsLamports()`
46
+
47
+ Lamport values returned from the RPC API conform to the type `LamportsUnsafeBeyond2Pow53Minus1`. You can use a value of that type wherever a quantity of Lamports is expected.
48
+
49
+ From time to time you might acquire a number that you expect to be a quantity of Lamports, from an untrusted network API or user input. To assert that such an arbitrary number is usable as a quantity of Lamports, use the `assertIsLamports` function.
50
+
51
+ ```ts
52
+ import { assertIsLamports } from '@solana/rpc-types';
53
+
54
+ // Imagine a function that creates a transfer instruction when a user submits a form.
55
+ function handleSubmit() {
56
+ // We know only that what the user typed conforms to the `number` type.
57
+ const lamports: number = parseInt(quantityInput.value, 10);
58
+ try {
59
+ // If this type assertion function doesn't throw, then
60
+ // Typescript will upcast `lamports` to `LamportsUnsafeBeyond2Pow53Minus1`.
61
+ assertIsLamports(lamports);
62
+ // At this point, `lamports` is a `LamportsUnsafeBeyond2Pow53Minus1` that can be used anywhere Lamports are expected.
63
+ await transfer(fromAddress, toAddress, lamports);
64
+ } catch (e) {
65
+ // `lamports` turned out not to validate as a quantity of Lamports.
66
+ }
67
+ }
68
+ ```
69
+
70
+ ### `assertIsStringifiedBigInt()`
71
+
72
+ Large integers returned from the RPC API encoded as strings conform to the type `StringifiedBigInt`.
73
+
74
+ From time to time you might acquire a string that you suspect might validate as a `StringifiedBigInt`, from an untrusted network API or user input. To assert that such an arbitrary string is usable as a `StringifiedBigInt`, use the `assertIsStringifiedBigInt` function.
75
+
76
+ See [`assertIsLamports()`](#assertislamports) for an example of how to use an assertion function.
77
+
78
+ ### `assertIsStringifiedNumber()`
79
+
80
+ Large numbers returned from the RPC API encoded as strings conform to the type `StringifiedNumber`.
81
+
82
+ From time to time you might acquire a string that you suspect might validate as a `StringifiedNumber`, from an untrusted network API or user input. To assert that such an arbitrary string is usable as a `StringifiedNumber`, use the `assertIsStringifiedNumber` function.
83
+
84
+ See [`assertIsLamports()`](#assertislamports) for an example of how to use an assertion function.
85
+
86
+ ### `assertIsUnixTimestamp()`
87
+
88
+ Timestamps returned from the RPC API conform to the type `UnixTimestamp`.
89
+
90
+ From time to time you might acquire a number that you suspect might validate as a `UnixTimestamp`, from an untrusted network API or user input. To assert that such an arbitrary number is usable as a `UnixTimestamp`, use the `assertIsUnixTimestamp` function.
91
+
92
+ See [`assertIsLamports()`](#assertislamports) for an example of how to use an assertion function.
93
+
94
+ ### `commitmentComparator()`
95
+
96
+ A function that accepts two `Commitments` as input, and returns `-1` if the first is lower than the second, `0` if they are the same, and `1` if the second is higher than the first. You can use this comparator to sort items by commitment, or to determine an upper/lower bound on a level of commitment given two options.
97
+
98
+ ```ts
99
+ import { commitmentComparator } from '@solana/rpc-types';
100
+
101
+ transactions.sort((a, b) => commitmentComparator(a.confirmationStatus, b.confirmationStatus));
102
+ ```
103
+
104
+ ### `isLamports()`
105
+
106
+ This is a type guard that accepts a `bigint` as input. It will both return `true` if the integer conforms to the `LamportsUnsafeBeyond2Pow53Minus1` type and will refine the type for use in your program.
107
+
108
+ ```ts
109
+ import { isLamports } from '@solana/rpc-types';
110
+
111
+ if (isLamports(lamports)) {
112
+ // At this point, `lamports` has been refined to a
113
+ // `LamportsUnsafeBeyond2Pow53Minus1` that can be used anywhere Lamports are expected.
114
+ await transfer(fromAddress, toAddress, lamports);
115
+ } else {
116
+ setError(`${ownerAddress} is not an address`);
117
+ }
118
+ ```
119
+
120
+ ### `isStringifiedBigInt()`
121
+
122
+ This is a type guard that accepts a string as input. It will both return `true` if the string can be parsed as a `bigint` and will refine the type for use in your program.
123
+
124
+ See [`isLamports()`](#islamports) for an example of how to use a type guard.
125
+
126
+ ### `isStringifiedNumber()`
127
+
128
+ This is a type guard that accepts a string as input. It will both return `true` if the string can be parsed as a JavaScript `Number` and will refine the type for use in your program.
129
+
130
+ See [`isLamports()`](#islamports) for an example of how to use a type guard.
131
+
132
+ ### `isUnixTimestamp()`
133
+
134
+ This is a type guard that accepts a number as input. It will both return `true` if the number is in the Unix timestamp range and will refine the type for use in your program.
135
+
136
+ See [`isLamports()`](#islamports) for an example of how to use a type guard.
137
+
138
+ ### `lamports()`
139
+
140
+ This helper combines _asserting_ that a number is a possible number of Lamports with _coercing_ it to the `LamportsUnsafeBeyond2Pow53Minus1` type. It's best used with untrusted input.
141
+
142
+ ```ts
143
+ import { lamports } from '@solana/rpc-types';
144
+
145
+ await transfer(address(fromAddress), address(toAddress), lamports(100000n));
146
+ ```
147
+
148
+ ### `stringifiedBigInt()`
149
+
150
+ This helper combines _asserting_ that a string represents a `bigint` with _coercing_ it to the `StringifiedBigInt` type. It's best used with untrusted input.
151
+
152
+ ### `stringifiedNumber()`
153
+
154
+ This helper combines _asserting_ that a string parses as a JavaScript `Number` with _coercing_ it to the `StringifiedNumber` type. It's best used with untrusted input.
155
+
156
+ ### `unixTimestamp()`
157
+
158
+ This helper combines _asserting_ that a number is in the Unix timestamp range with _coercing_ it to the `UnixTimestamp` type. It's best used with untrusted input.
@@ -0,0 +1,238 @@
1
+ 'use strict';
2
+
3
+ var codecsCore = require('@solana/codecs-core');
4
+ var codecsStrings = require('@solana/codecs-strings');
5
+ var errors = require('@solana/errors');
6
+ var codecsNumbers = require('@solana/codecs-numbers');
7
+
8
+ // src/blockhash.ts
9
+ var memoizedBase58Encoder;
10
+ var memoizedBase58Decoder;
11
+ function getMemoizedBase58Encoder() {
12
+ if (!memoizedBase58Encoder) memoizedBase58Encoder = codecsStrings.getBase58Encoder();
13
+ return memoizedBase58Encoder;
14
+ }
15
+ function getMemoizedBase58Decoder() {
16
+ if (!memoizedBase58Decoder) memoizedBase58Decoder = codecsStrings.getBase58Decoder();
17
+ return memoizedBase58Decoder;
18
+ }
19
+ function isBlockhash(putativeBlockhash) {
20
+ if (
21
+ // Lowest value (32 bytes of zeroes)
22
+ putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
23
+ putativeBlockhash.length > 44
24
+ ) {
25
+ return false;
26
+ }
27
+ const base58Encoder = getMemoizedBase58Encoder();
28
+ const bytes = base58Encoder.encode(putativeBlockhash);
29
+ const numBytes = bytes.byteLength;
30
+ if (numBytes !== 32) {
31
+ return false;
32
+ }
33
+ return true;
34
+ }
35
+ function assertIsBlockhash(putativeBlockhash) {
36
+ if (
37
+ // Lowest value (32 bytes of zeroes)
38
+ putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
39
+ putativeBlockhash.length > 44
40
+ ) {
41
+ throw new errors.SolanaError(errors.SOLANA_ERROR__BLOCKHASH_STRING_LENGTH_OUT_OF_RANGE, {
42
+ actualLength: putativeBlockhash.length
43
+ });
44
+ }
45
+ const base58Encoder = getMemoizedBase58Encoder();
46
+ const bytes = base58Encoder.encode(putativeBlockhash);
47
+ const numBytes = bytes.byteLength;
48
+ if (numBytes !== 32) {
49
+ throw new errors.SolanaError(errors.SOLANA_ERROR__INVALID_BLOCKHASH_BYTE_LENGTH, {
50
+ actualLength: numBytes
51
+ });
52
+ }
53
+ }
54
+ function blockhash(putativeBlockhash) {
55
+ assertIsBlockhash(putativeBlockhash);
56
+ return putativeBlockhash;
57
+ }
58
+ function getBlockhashEncoder() {
59
+ return codecsCore.transformEncoder(
60
+ codecsCore.fixEncoderSize(getMemoizedBase58Encoder(), 32),
61
+ (putativeBlockhash) => blockhash(putativeBlockhash)
62
+ );
63
+ }
64
+ function getBlockhashDecoder() {
65
+ return codecsCore.fixDecoderSize(getMemoizedBase58Decoder(), 32);
66
+ }
67
+ function getBlockhashCodec() {
68
+ return codecsCore.combineCodec(getBlockhashEncoder(), getBlockhashDecoder());
69
+ }
70
+ function getBlockhashComparator() {
71
+ return new Intl.Collator("en", {
72
+ caseFirst: "lower",
73
+ ignorePunctuation: false,
74
+ localeMatcher: "best fit",
75
+ numeric: false,
76
+ sensitivity: "variant",
77
+ usage: "sort"
78
+ }).compare;
79
+ }
80
+
81
+ // src/cluster-url.ts
82
+ function mainnet(putativeString) {
83
+ return putativeString;
84
+ }
85
+ function devnet(putativeString) {
86
+ return putativeString;
87
+ }
88
+ function testnet(putativeString) {
89
+ return putativeString;
90
+ }
91
+ function getCommitmentScore(commitment) {
92
+ switch (commitment) {
93
+ case "finalized":
94
+ return 2;
95
+ case "confirmed":
96
+ return 1;
97
+ case "processed":
98
+ return 0;
99
+ default:
100
+ throw new errors.SolanaError(errors.SOLANA_ERROR__INVARIANT_VIOLATION__SWITCH_MUST_BE_EXHAUSTIVE, {
101
+ unexpectedValue: commitment
102
+ });
103
+ }
104
+ }
105
+ function commitmentComparator(a, b) {
106
+ if (a === b) {
107
+ return 0;
108
+ }
109
+ return getCommitmentScore(a) < getCommitmentScore(b) ? -1 : 1;
110
+ }
111
+ var maxU64Value = 18446744073709551615n;
112
+ var memoizedU64Encoder;
113
+ var memoizedU64Decoder;
114
+ function getMemoizedU64Encoder() {
115
+ if (!memoizedU64Encoder) memoizedU64Encoder = codecsNumbers.getU64Encoder();
116
+ return memoizedU64Encoder;
117
+ }
118
+ function getMemoizedU64Decoder() {
119
+ if (!memoizedU64Decoder) memoizedU64Decoder = codecsNumbers.getU64Decoder();
120
+ return memoizedU64Decoder;
121
+ }
122
+ function isLamports(putativeLamports) {
123
+ return putativeLamports >= 0 && putativeLamports <= maxU64Value;
124
+ }
125
+ function assertIsLamports(putativeLamports) {
126
+ if (putativeLamports < 0 || putativeLamports > maxU64Value) {
127
+ throw new errors.SolanaError(errors.SOLANA_ERROR__LAMPORTS_OUT_OF_RANGE);
128
+ }
129
+ }
130
+ function lamports(putativeLamports) {
131
+ assertIsLamports(putativeLamports);
132
+ return putativeLamports;
133
+ }
134
+ function getDefaultLamportsEncoder() {
135
+ return getLamportsEncoder(getMemoizedU64Encoder());
136
+ }
137
+ function getLamportsEncoder(innerEncoder) {
138
+ return innerEncoder;
139
+ }
140
+ function getDefaultLamportsDecoder() {
141
+ return getLamportsDecoder(getMemoizedU64Decoder());
142
+ }
143
+ function getLamportsDecoder(innerDecoder) {
144
+ return codecsCore.transformDecoder(
145
+ innerDecoder,
146
+ (value) => lamports(typeof value === "bigint" ? value : BigInt(value))
147
+ );
148
+ }
149
+ function getDefaultLamportsCodec() {
150
+ return codecsCore.combineCodec(getDefaultLamportsEncoder(), getDefaultLamportsDecoder());
151
+ }
152
+ function getLamportsCodec(innerCodec) {
153
+ return codecsCore.combineCodec(getLamportsEncoder(innerCodec), getLamportsDecoder(innerCodec));
154
+ }
155
+ function isStringifiedBigInt(putativeBigInt) {
156
+ try {
157
+ BigInt(putativeBigInt);
158
+ return true;
159
+ } catch (_) {
160
+ return false;
161
+ }
162
+ }
163
+ function assertIsStringifiedBigInt(putativeBigInt) {
164
+ try {
165
+ BigInt(putativeBigInt);
166
+ } catch {
167
+ throw new errors.SolanaError(errors.SOLANA_ERROR__MALFORMED_BIGINT_STRING, {
168
+ value: putativeBigInt
169
+ });
170
+ }
171
+ }
172
+ function stringifiedBigInt(putativeBigInt) {
173
+ assertIsStringifiedBigInt(putativeBigInt);
174
+ return putativeBigInt;
175
+ }
176
+ function isStringifiedNumber(putativeNumber) {
177
+ return !Number.isNaN(Number(putativeNumber));
178
+ }
179
+ function assertIsStringifiedNumber(putativeNumber) {
180
+ if (Number.isNaN(Number(putativeNumber))) {
181
+ throw new errors.SolanaError(errors.SOLANA_ERROR__MALFORMED_NUMBER_STRING, {
182
+ value: putativeNumber
183
+ });
184
+ }
185
+ }
186
+ function stringifiedNumber(putativeNumber) {
187
+ assertIsStringifiedNumber(putativeNumber);
188
+ return putativeNumber;
189
+ }
190
+ function isUnixTimestamp(putativeTimestamp) {
191
+ if (putativeTimestamp > 864e13 || putativeTimestamp < -864e13) {
192
+ return false;
193
+ }
194
+ return true;
195
+ }
196
+ function assertIsUnixTimestamp(putativeTimestamp) {
197
+ if (putativeTimestamp > 864e13 || putativeTimestamp < -864e13) {
198
+ throw new errors.SolanaError(errors.SOLANA_ERROR__TIMESTAMP_OUT_OF_RANGE, {
199
+ value: putativeTimestamp
200
+ });
201
+ }
202
+ }
203
+ function unixTimestamp(putativeTimestamp) {
204
+ assertIsUnixTimestamp(putativeTimestamp);
205
+ return putativeTimestamp;
206
+ }
207
+
208
+ exports.assertIsBlockhash = assertIsBlockhash;
209
+ exports.assertIsLamports = assertIsLamports;
210
+ exports.assertIsStringifiedBigInt = assertIsStringifiedBigInt;
211
+ exports.assertIsStringifiedNumber = assertIsStringifiedNumber;
212
+ exports.assertIsUnixTimestamp = assertIsUnixTimestamp;
213
+ exports.blockhash = blockhash;
214
+ exports.commitmentComparator = commitmentComparator;
215
+ exports.devnet = devnet;
216
+ exports.getBlockhashCodec = getBlockhashCodec;
217
+ exports.getBlockhashComparator = getBlockhashComparator;
218
+ exports.getBlockhashDecoder = getBlockhashDecoder;
219
+ exports.getBlockhashEncoder = getBlockhashEncoder;
220
+ exports.getDefaultLamportsCodec = getDefaultLamportsCodec;
221
+ exports.getDefaultLamportsDecoder = getDefaultLamportsDecoder;
222
+ exports.getDefaultLamportsEncoder = getDefaultLamportsEncoder;
223
+ exports.getLamportsCodec = getLamportsCodec;
224
+ exports.getLamportsDecoder = getLamportsDecoder;
225
+ exports.getLamportsEncoder = getLamportsEncoder;
226
+ exports.isBlockhash = isBlockhash;
227
+ exports.isLamports = isLamports;
228
+ exports.isStringifiedBigInt = isStringifiedBigInt;
229
+ exports.isStringifiedNumber = isStringifiedNumber;
230
+ exports.isUnixTimestamp = isUnixTimestamp;
231
+ exports.lamports = lamports;
232
+ exports.mainnet = mainnet;
233
+ exports.stringifiedBigInt = stringifiedBigInt;
234
+ exports.stringifiedNumber = stringifiedNumber;
235
+ exports.testnet = testnet;
236
+ exports.unixTimestamp = unixTimestamp;
237
+ //# sourceMappingURL=index.browser.cjs.map
238
+ //# sourceMappingURL=index.browser.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/blockhash.ts","../src/cluster-url.ts","../src/commitment.ts","../src/lamports.ts","../src/stringified-bigint.ts","../src/stringified-number.ts","../src/unix-timestamp.ts"],"names":["getBase58Encoder","getBase58Decoder","SolanaError","SOLANA_ERROR__BLOCKHASH_STRING_LENGTH_OUT_OF_RANGE","SOLANA_ERROR__INVALID_BLOCKHASH_BYTE_LENGTH","transformEncoder","fixEncoderSize","fixDecoderSize","combineCodec","SOLANA_ERROR__INVARIANT_VIOLATION__SWITCH_MUST_BE_EXHAUSTIVE","getU64Encoder","getU64Decoder","SOLANA_ERROR__LAMPORTS_OUT_OF_RANGE","transformDecoder","SOLANA_ERROR__MALFORMED_BIGINT_STRING","SOLANA_ERROR__MALFORMED_NUMBER_STRING","SOLANA_ERROR__TIMESTAMP_OUT_OF_RANGE"],"mappings":";;;;;;;;AAoBA,IAAI,qBAAA,CAAA;AACJ,IAAI,qBAAA,CAAA;AAEJ,SAAS,wBAA4C,GAAA;AACjD,EAAI,IAAA,CAAC,qBAAuB,EAAA,qBAAA,GAAwBA,8BAAiB,EAAA,CAAA;AACrE,EAAO,OAAA,qBAAA,CAAA;AACX,CAAA;AAEA,SAAS,wBAA4C,GAAA;AACjD,EAAI,IAAA,CAAC,qBAAuB,EAAA,qBAAA,GAAwBC,8BAAiB,EAAA,CAAA;AACrE,EAAO,OAAA,qBAAA,CAAA;AACX,CAAA;AAEO,SAAS,YAAY,iBAA2D,EAAA;AAEnF,EAAA;AAAA;AAAA,IAEI,kBAAkB,MAAS,GAAA,EAAA;AAAA,IAE3B,kBAAkB,MAAS,GAAA,EAAA;AAAA,IAC7B;AACE,IAAO,OAAA,KAAA,CAAA;AAAA,GACX;AAEA,EAAA,MAAM,gBAAgB,wBAAyB,EAAA,CAAA;AAC/C,EAAM,MAAA,KAAA,GAAQ,aAAc,CAAA,MAAA,CAAO,iBAAiB,CAAA,CAAA;AACpD,EAAA,MAAM,WAAW,KAAM,CAAA,UAAA,CAAA;AACvB,EAAA,IAAI,aAAa,EAAI,EAAA;AACjB,IAAO,OAAA,KAAA,CAAA;AAAA,GACX;AACA,EAAO,OAAA,IAAA,CAAA;AACX,CAAA;AAEO,SAAS,kBAA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AAA,EAAA;AAC7D,IAAO,OAAA,KAAA,CAAA;AAAA,GACX;AACA,EAAO,OAAA,IAAA,CAAA;AACX,CAAA;AAEO,SAAS,sBAAsB,iBAAuE,EAAA;AAGzG,EAAI,IAAA,iBAAA,GAAoB,MAAW,IAAA,iBAAA,GAAoB,CAAU,MAAA,EAAA;AAC7D,IAAM,MAAA,IAAIb,mBAAYc,2CAAsC,EAAA;AAAA,MACxD,KAAO,EAAA,iBAAA;AAAA,KACV,CAAA,CAAA;AAAA,GACL;AACJ,CAAA;AAEO,SAAS,cAAc,iBAA0C,EAAA;AACpE,EAAA,qBAAA,CAAsB,iBAAiB,CAAA,CAAA;AACvC,EAAO,OAAA,iBAAA,CAAA;AACX","file":"index.browser.cjs","sourcesContent":["import {\n combineCodec,\n Decoder,\n Encoder,\n fixDecoderSize,\n FixedSizeCodec,\n FixedSizeDecoder,\n FixedSizeEncoder,\n fixEncoderSize,\n transformEncoder,\n} from '@solana/codecs-core';\nimport { getBase58Decoder, getBase58Encoder } from '@solana/codecs-strings';\nimport {\n SOLANA_ERROR__BLOCKHASH_STRING_LENGTH_OUT_OF_RANGE,\n SOLANA_ERROR__INVALID_BLOCKHASH_BYTE_LENGTH,\n SolanaError,\n} from '@solana/errors';\n\nexport type Blockhash = string & { readonly __brand: unique symbol };\n\nlet memoizedBase58Encoder: Encoder<string> | undefined;\nlet memoizedBase58Decoder: Decoder<string> | undefined;\n\nfunction getMemoizedBase58Encoder(): Encoder<string> {\n if (!memoizedBase58Encoder) memoizedBase58Encoder = getBase58Encoder();\n return memoizedBase58Encoder;\n}\n\nfunction getMemoizedBase58Decoder(): Decoder<string> {\n if (!memoizedBase58Decoder) memoizedBase58Decoder = getBase58Decoder();\n return memoizedBase58Decoder;\n}\n\nexport function isBlockhash(putativeBlockhash: string): putativeBlockhash is Blockhash {\n // Fast-path; see if the input string is of an acceptable length.\n if (\n // Lowest value (32 bytes of zeroes)\n putativeBlockhash.length < 32 ||\n // Highest value (32 bytes of 255)\n putativeBlockhash.length > 44\n ) {\n return false;\n }\n // Slow-path; actually attempt to decode the input string.\n const base58Encoder = getMemoizedBase58Encoder();\n const bytes = base58Encoder.encode(putativeBlockhash);\n const numBytes = bytes.byteLength;\n if (numBytes !== 32) {\n return false;\n }\n return true;\n}\n\nexport function assertIsBlockhash(putativeBlockhash: string): asserts putativeBlockhash is Blockhash {\n // Fast-path; see if the input string is of an acceptable length.\n if (\n // Lowest value (32 bytes of zeroes)\n putativeBlockhash.length < 32 ||\n // Highest value (32 bytes of 255)\n putativeBlockhash.length > 44\n ) {\n throw new SolanaError(SOLANA_ERROR__BLOCKHASH_STRING_LENGTH_OUT_OF_RANGE, {\n actualLength: putativeBlockhash.length,\n });\n }\n // Slow-path; actually attempt to decode the input string.\n const base58Encoder = getMemoizedBase58Encoder();\n const bytes = base58Encoder.encode(putativeBlockhash);\n const numBytes = bytes.byteLength;\n if (numBytes !== 32) {\n throw new SolanaError(SOLANA_ERROR__INVALID_BLOCKHASH_BYTE_LENGTH, {\n actualLength: numBytes,\n });\n }\n}\n\nexport function blockhash(putativeBlockhash: string): Blockhash {\n assertIsBlockhash(putativeBlockhash);\n return putativeBlockhash as Blockhash;\n}\n\nexport function getBlockhashEncoder(): FixedSizeEncoder<Blockhash, 32> {\n return transformEncoder(fixEncoderSize(getMemoizedBase58Encoder(), 32), putativeBlockhash =>\n blockhash(putativeBlockhash),\n );\n}\n\nexport function getBlockhashDecoder(): FixedSizeDecoder<Blockhash, 32> {\n return fixDecoderSize(getMemoizedBase58Decoder(), 32) as FixedSizeDecoder<Blockhash, 32>;\n}\n\nexport function getBlockhashCodec(): FixedSizeCodec<Blockhash, Blockhash, 32> {\n return combineCodec(getBlockhashEncoder(), getBlockhashDecoder());\n}\n\nexport function getBlockhashComparator(): (x: string, y: string) => number {\n return new Intl.Collator('en', {\n caseFirst: 'lower',\n ignorePunctuation: false,\n localeMatcher: 'best fit',\n numeric: false,\n sensitivity: 'variant',\n usage: 'sort',\n }).compare;\n}\n","export type MainnetUrl = string & { '~cluster': 'mainnet' };\nexport type DevnetUrl = string & { '~cluster': 'devnet' };\nexport type TestnetUrl = string & { '~cluster': 'testnet' };\nexport type ClusterUrl = DevnetUrl | MainnetUrl | TestnetUrl | string;\n\nexport function mainnet(putativeString: string): MainnetUrl {\n return putativeString as MainnetUrl;\n}\nexport function devnet(putativeString: string): DevnetUrl {\n return putativeString as DevnetUrl;\n}\nexport function testnet(putativeString: string): TestnetUrl {\n return putativeString as TestnetUrl;\n}\n","import { SOLANA_ERROR__INVARIANT_VIOLATION__SWITCH_MUST_BE_EXHAUSTIVE, SolanaError } from '@solana/errors';\n\nexport type Commitment = 'confirmed' | 'finalized' | 'processed';\n\nfunction getCommitmentScore(commitment: Commitment): number {\n switch (commitment) {\n case 'finalized':\n return 2;\n case 'confirmed':\n return 1;\n case 'processed':\n return 0;\n default:\n throw new SolanaError(SOLANA_ERROR__INVARIANT_VIOLATION__SWITCH_MUST_BE_EXHAUSTIVE, {\n unexpectedValue: commitment satisfies never,\n });\n }\n}\n\nexport function commitmentComparator(a: Commitment, b: Commitment): -1 | 0 | 1 {\n if (a === b) {\n return 0;\n }\n return getCommitmentScore(a) < getCommitmentScore(b) ? -1 : 1;\n}\n","import {\n Codec,\n combineCodec,\n Decoder,\n Encoder,\n FixedSizeCodec,\n FixedSizeDecoder,\n FixedSizeEncoder,\n transformDecoder,\n} from '@solana/codecs-core';\nimport { getU64Decoder, getU64Encoder, NumberCodec, NumberDecoder, NumberEncoder } from '@solana/codecs-numbers';\nimport { SOLANA_ERROR__LAMPORTS_OUT_OF_RANGE, SolanaError } from '@solana/errors';\n\n// FIXME(solana-labs/solana/issues/30341) Beware that any value above 9007199254740991 may be\n// truncated or rounded because of a downcast to JavaScript `number` between your calling code and\n// the JSON-RPC transport.\nexport type LamportsUnsafeBeyond2Pow53Minus1 = bigint & { readonly __brand: unique symbol };\n\n// Largest possible value to be represented by a u64\nconst maxU64Value = 18446744073709551615n; // 2n ** 64n - 1n\n\nlet memoizedU64Encoder: FixedSizeEncoder<bigint | number, 8> | undefined;\nlet memoizedU64Decoder: FixedSizeDecoder<bigint, 8> | undefined;\n\nfunction getMemoizedU64Encoder(): FixedSizeEncoder<bigint | number, 8> {\n if (!memoizedU64Encoder) memoizedU64Encoder = getU64Encoder();\n return memoizedU64Encoder;\n}\n\nfunction getMemoizedU64Decoder(): FixedSizeDecoder<bigint, 8> {\n if (!memoizedU64Decoder) memoizedU64Decoder = getU64Decoder();\n return memoizedU64Decoder;\n}\n\nexport function isLamports(putativeLamports: bigint): putativeLamports is LamportsUnsafeBeyond2Pow53Minus1 {\n return putativeLamports >= 0 && putativeLamports <= maxU64Value;\n}\n\nexport function assertIsLamports(\n putativeLamports: bigint,\n): asserts putativeLamports is LamportsUnsafeBeyond2Pow53Minus1 {\n if (putativeLamports < 0 || putativeLamports > maxU64Value) {\n throw new SolanaError(SOLANA_ERROR__LAMPORTS_OUT_OF_RANGE);\n }\n}\n\nexport function lamports(putativeLamports: bigint): LamportsUnsafeBeyond2Pow53Minus1 {\n assertIsLamports(putativeLamports);\n return putativeLamports;\n}\n\ntype ExtractAdditionalProps<T, U> = Omit<T, keyof U>;\n\nexport function getDefaultLamportsEncoder(): FixedSizeEncoder<LamportsUnsafeBeyond2Pow53Minus1, 8> {\n return getLamportsEncoder(getMemoizedU64Encoder());\n}\n\nexport function getLamportsEncoder<TEncoder extends NumberEncoder>(\n innerEncoder: TEncoder,\n): Encoder<LamportsUnsafeBeyond2Pow53Minus1> & ExtractAdditionalProps<TEncoder, NumberEncoder> {\n return innerEncoder;\n}\n\nexport function getDefaultLamportsDecoder(): FixedSizeDecoder<LamportsUnsafeBeyond2Pow53Minus1, 8> {\n return getLamportsDecoder(getMemoizedU64Decoder());\n}\n\nexport function getLamportsDecoder<TDecoder extends NumberDecoder>(\n innerDecoder: TDecoder,\n): Decoder<LamportsUnsafeBeyond2Pow53Minus1> & ExtractAdditionalProps<TDecoder, NumberDecoder> {\n return transformDecoder<bigint | number, LamportsUnsafeBeyond2Pow53Minus1>(innerDecoder, value =>\n lamports(typeof value === 'bigint' ? value : BigInt(value)),\n ) as Decoder<LamportsUnsafeBeyond2Pow53Minus1> & ExtractAdditionalProps<TDecoder, NumberDecoder>;\n}\n\nexport function getDefaultLamportsCodec(): FixedSizeCodec<\n LamportsUnsafeBeyond2Pow53Minus1,\n LamportsUnsafeBeyond2Pow53Minus1,\n 8\n> {\n return combineCodec(getDefaultLamportsEncoder(), getDefaultLamportsDecoder());\n}\n\nexport function getLamportsCodec<TCodec extends NumberCodec>(\n innerCodec: TCodec,\n): Codec<LamportsUnsafeBeyond2Pow53Minus1, LamportsUnsafeBeyond2Pow53Minus1> &\n ExtractAdditionalProps<TCodec, NumberCodec> {\n return combineCodec(getLamportsEncoder(innerCodec), getLamportsDecoder(innerCodec)) as Codec<\n LamportsUnsafeBeyond2Pow53Minus1,\n LamportsUnsafeBeyond2Pow53Minus1\n > &\n ExtractAdditionalProps<TCodec, NumberCodec>;\n}\n","import { SOLANA_ERROR__MALFORMED_BIGINT_STRING, SolanaError } from '@solana/errors';\n\nexport type StringifiedBigInt = string & { readonly __brand: unique symbol };\n\nexport function isStringifiedBigInt(putativeBigInt: string): putativeBigInt is StringifiedBigInt {\n try {\n BigInt(putativeBigInt);\n return true;\n } catch (_) {\n return false;\n }\n}\n\nexport function assertIsStringifiedBigInt(putativeBigInt: string): asserts putativeBigInt is StringifiedBigInt {\n try {\n BigInt(putativeBigInt);\n } catch {\n throw new SolanaError(SOLANA_ERROR__MALFORMED_BIGINT_STRING, {\n value: putativeBigInt,\n });\n }\n}\n\nexport function stringifiedBigInt(putativeBigInt: string): StringifiedBigInt {\n assertIsStringifiedBigInt(putativeBigInt);\n return putativeBigInt;\n}\n","import { SOLANA_ERROR__MALFORMED_NUMBER_STRING, SolanaError } from '@solana/errors';\n\nexport type StringifiedNumber = string & { readonly __brand: unique symbol };\n\nexport function isStringifiedNumber(putativeNumber: string): putativeNumber is StringifiedNumber {\n return !Number.isNaN(Number(putativeNumber));\n}\n\nexport function assertIsStringifiedNumber(putativeNumber: string): asserts putativeNumber is StringifiedNumber {\n if (Number.isNaN(Number(putativeNumber))) {\n throw new SolanaError(SOLANA_ERROR__MALFORMED_NUMBER_STRING, {\n value: putativeNumber,\n });\n }\n}\n\nexport function stringifiedNumber(putativeNumber: string): StringifiedNumber {\n assertIsStringifiedNumber(putativeNumber);\n return putativeNumber;\n}\n","import { SOLANA_ERROR__TIMESTAMP_OUT_OF_RANGE, SolanaError } from '@solana/errors';\n\nexport type UnixTimestamp = number & { readonly __brand: unique symbol };\n\nexport function isUnixTimestamp(putativeTimestamp: number): putativeTimestamp is UnixTimestamp {\n // see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#the_epoch_timestamps_and_invalid_date\n if (putativeTimestamp > 8.64e15 || putativeTimestamp < -8.64e15) {\n return false;\n }\n return true;\n}\n\nexport function assertIsUnixTimestamp(putativeTimestamp: number): asserts putativeTimestamp is UnixTimestamp {\n // see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#the_epoch_timestamps_and_invalid_date\n\n if (putativeTimestamp > 8.64e15 || putativeTimestamp < -8.64e15) {\n throw new SolanaError(SOLANA_ERROR__TIMESTAMP_OUT_OF_RANGE, {\n value: putativeTimestamp,\n });\n }\n}\n\nexport function unixTimestamp(putativeTimestamp: number): UnixTimestamp {\n assertIsUnixTimestamp(putativeTimestamp);\n return putativeTimestamp;\n}\n"]}
@@ -0,0 +1,208 @@
1
+ import { transformEncoder, fixEncoderSize, fixDecoderSize, combineCodec, transformDecoder } from '@solana/codecs-core';
2
+ import { getBase58Encoder, getBase58Decoder } from '@solana/codecs-strings';
3
+ import { SolanaError, SOLANA_ERROR__BLOCKHASH_STRING_LENGTH_OUT_OF_RANGE, SOLANA_ERROR__INVALID_BLOCKHASH_BYTE_LENGTH, SOLANA_ERROR__LAMPORTS_OUT_OF_RANGE, SOLANA_ERROR__MALFORMED_BIGINT_STRING, SOLANA_ERROR__MALFORMED_NUMBER_STRING, SOLANA_ERROR__TIMESTAMP_OUT_OF_RANGE, SOLANA_ERROR__INVARIANT_VIOLATION__SWITCH_MUST_BE_EXHAUSTIVE } from '@solana/errors';
4
+ import { getU64Encoder, getU64Decoder } from '@solana/codecs-numbers';
5
+
6
+ // src/blockhash.ts
7
+ var memoizedBase58Encoder;
8
+ var memoizedBase58Decoder;
9
+ function getMemoizedBase58Encoder() {
10
+ if (!memoizedBase58Encoder) memoizedBase58Encoder = getBase58Encoder();
11
+ return memoizedBase58Encoder;
12
+ }
13
+ function getMemoizedBase58Decoder() {
14
+ if (!memoizedBase58Decoder) memoizedBase58Decoder = getBase58Decoder();
15
+ return memoizedBase58Decoder;
16
+ }
17
+ function isBlockhash(putativeBlockhash) {
18
+ if (
19
+ // Lowest value (32 bytes of zeroes)
20
+ putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
21
+ putativeBlockhash.length > 44
22
+ ) {
23
+ return false;
24
+ }
25
+ const base58Encoder = getMemoizedBase58Encoder();
26
+ const bytes = base58Encoder.encode(putativeBlockhash);
27
+ const numBytes = bytes.byteLength;
28
+ if (numBytes !== 32) {
29
+ return false;
30
+ }
31
+ return true;
32
+ }
33
+ function assertIsBlockhash(putativeBlockhash) {
34
+ if (
35
+ // Lowest value (32 bytes of zeroes)
36
+ putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
37
+ putativeBlockhash.length > 44
38
+ ) {
39
+ throw new SolanaError(SOLANA_ERROR__BLOCKHASH_STRING_LENGTH_OUT_OF_RANGE, {
40
+ actualLength: putativeBlockhash.length
41
+ });
42
+ }
43
+ const base58Encoder = getMemoizedBase58Encoder();
44
+ const bytes = base58Encoder.encode(putativeBlockhash);
45
+ const numBytes = bytes.byteLength;
46
+ if (numBytes !== 32) {
47
+ throw new SolanaError(SOLANA_ERROR__INVALID_BLOCKHASH_BYTE_LENGTH, {
48
+ actualLength: numBytes
49
+ });
50
+ }
51
+ }
52
+ function blockhash(putativeBlockhash) {
53
+ assertIsBlockhash(putativeBlockhash);
54
+ return putativeBlockhash;
55
+ }
56
+ function getBlockhashEncoder() {
57
+ return transformEncoder(
58
+ fixEncoderSize(getMemoizedBase58Encoder(), 32),
59
+ (putativeBlockhash) => blockhash(putativeBlockhash)
60
+ );
61
+ }
62
+ function getBlockhashDecoder() {
63
+ return fixDecoderSize(getMemoizedBase58Decoder(), 32);
64
+ }
65
+ function getBlockhashCodec() {
66
+ return combineCodec(getBlockhashEncoder(), getBlockhashDecoder());
67
+ }
68
+ function getBlockhashComparator() {
69
+ return new Intl.Collator("en", {
70
+ caseFirst: "lower",
71
+ ignorePunctuation: false,
72
+ localeMatcher: "best fit",
73
+ numeric: false,
74
+ sensitivity: "variant",
75
+ usage: "sort"
76
+ }).compare;
77
+ }
78
+
79
+ // src/cluster-url.ts
80
+ function mainnet(putativeString) {
81
+ return putativeString;
82
+ }
83
+ function devnet(putativeString) {
84
+ return putativeString;
85
+ }
86
+ function testnet(putativeString) {
87
+ return putativeString;
88
+ }
89
+ function getCommitmentScore(commitment) {
90
+ switch (commitment) {
91
+ case "finalized":
92
+ return 2;
93
+ case "confirmed":
94
+ return 1;
95
+ case "processed":
96
+ return 0;
97
+ default:
98
+ throw new SolanaError(SOLANA_ERROR__INVARIANT_VIOLATION__SWITCH_MUST_BE_EXHAUSTIVE, {
99
+ unexpectedValue: commitment
100
+ });
101
+ }
102
+ }
103
+ function commitmentComparator(a, b) {
104
+ if (a === b) {
105
+ return 0;
106
+ }
107
+ return getCommitmentScore(a) < getCommitmentScore(b) ? -1 : 1;
108
+ }
109
+ var maxU64Value = 18446744073709551615n;
110
+ var memoizedU64Encoder;
111
+ var memoizedU64Decoder;
112
+ function getMemoizedU64Encoder() {
113
+ if (!memoizedU64Encoder) memoizedU64Encoder = getU64Encoder();
114
+ return memoizedU64Encoder;
115
+ }
116
+ function getMemoizedU64Decoder() {
117
+ if (!memoizedU64Decoder) memoizedU64Decoder = getU64Decoder();
118
+ return memoizedU64Decoder;
119
+ }
120
+ function isLamports(putativeLamports) {
121
+ return putativeLamports >= 0 && putativeLamports <= maxU64Value;
122
+ }
123
+ function assertIsLamports(putativeLamports) {
124
+ if (putativeLamports < 0 || putativeLamports > maxU64Value) {
125
+ throw new SolanaError(SOLANA_ERROR__LAMPORTS_OUT_OF_RANGE);
126
+ }
127
+ }
128
+ function lamports(putativeLamports) {
129
+ assertIsLamports(putativeLamports);
130
+ return putativeLamports;
131
+ }
132
+ function getDefaultLamportsEncoder() {
133
+ return getLamportsEncoder(getMemoizedU64Encoder());
134
+ }
135
+ function getLamportsEncoder(innerEncoder) {
136
+ return innerEncoder;
137
+ }
138
+ function getDefaultLamportsDecoder() {
139
+ return getLamportsDecoder(getMemoizedU64Decoder());
140
+ }
141
+ function getLamportsDecoder(innerDecoder) {
142
+ return transformDecoder(
143
+ innerDecoder,
144
+ (value) => lamports(typeof value === "bigint" ? value : BigInt(value))
145
+ );
146
+ }
147
+ function getDefaultLamportsCodec() {
148
+ return combineCodec(getDefaultLamportsEncoder(), getDefaultLamportsDecoder());
149
+ }
150
+ function getLamportsCodec(innerCodec) {
151
+ return combineCodec(getLamportsEncoder(innerCodec), getLamportsDecoder(innerCodec));
152
+ }
153
+ function isStringifiedBigInt(putativeBigInt) {
154
+ try {
155
+ BigInt(putativeBigInt);
156
+ return true;
157
+ } catch (_) {
158
+ return false;
159
+ }
160
+ }
161
+ function assertIsStringifiedBigInt(putativeBigInt) {
162
+ try {
163
+ BigInt(putativeBigInt);
164
+ } catch {
165
+ throw new SolanaError(SOLANA_ERROR__MALFORMED_BIGINT_STRING, {
166
+ value: putativeBigInt
167
+ });
168
+ }
169
+ }
170
+ function stringifiedBigInt(putativeBigInt) {
171
+ assertIsStringifiedBigInt(putativeBigInt);
172
+ return putativeBigInt;
173
+ }
174
+ function isStringifiedNumber(putativeNumber) {
175
+ return !Number.isNaN(Number(putativeNumber));
176
+ }
177
+ function assertIsStringifiedNumber(putativeNumber) {
178
+ if (Number.isNaN(Number(putativeNumber))) {
179
+ throw new SolanaError(SOLANA_ERROR__MALFORMED_NUMBER_STRING, {
180
+ value: putativeNumber
181
+ });
182
+ }
183
+ }
184
+ function stringifiedNumber(putativeNumber) {
185
+ assertIsStringifiedNumber(putativeNumber);
186
+ return putativeNumber;
187
+ }
188
+ function isUnixTimestamp(putativeTimestamp) {
189
+ if (putativeTimestamp > 864e13 || putativeTimestamp < -864e13) {
190
+ return false;
191
+ }
192
+ return true;
193
+ }
194
+ function assertIsUnixTimestamp(putativeTimestamp) {
195
+ if (putativeTimestamp > 864e13 || putativeTimestamp < -864e13) {
196
+ throw new SolanaError(SOLANA_ERROR__TIMESTAMP_OUT_OF_RANGE, {
197
+ value: putativeTimestamp
198
+ });
199
+ }
200
+ }
201
+ function unixTimestamp(putativeTimestamp) {
202
+ assertIsUnixTimestamp(putativeTimestamp);
203
+ return putativeTimestamp;
204
+ }
205
+
206
+ export { assertIsBlockhash, assertIsLamports, assertIsStringifiedBigInt, assertIsStringifiedNumber, assertIsUnixTimestamp, blockhash, commitmentComparator, devnet, getBlockhashCodec, getBlockhashComparator, getBlockhashDecoder, getBlockhashEncoder, getDefaultLamportsCodec, getDefaultLamportsDecoder, getDefaultLamportsEncoder, getLamportsCodec, getLamportsDecoder, getLamportsEncoder, isBlockhash, isLamports, isStringifiedBigInt, isStringifiedNumber, isUnixTimestamp, lamports, mainnet, stringifiedBigInt, stringifiedNumber, testnet, unixTimestamp };
207
+ //# sourceMappingURL=index.browser.mjs.map
208
+ //# sourceMappingURL=index.browser.mjs.map