@solana/rpc-types 2.0.0-experimental.25278c4

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/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 an 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,117 @@
1
+ 'use strict';
2
+
3
+ // src/commitment.ts
4
+ function getCommitmentScore(commitment) {
5
+ switch (commitment) {
6
+ case "finalized":
7
+ return 2;
8
+ case "confirmed":
9
+ return 1;
10
+ case "processed":
11
+ return 0;
12
+ default:
13
+ return ((_) => {
14
+ throw new Error(`Unrecognized commitment \`${commitment}\`.`);
15
+ })();
16
+ }
17
+ }
18
+ function commitmentComparator(a, b) {
19
+ if (a === b) {
20
+ return 0;
21
+ }
22
+ return getCommitmentScore(a) < getCommitmentScore(b) ? -1 : 1;
23
+ }
24
+
25
+ // src/lamports.ts
26
+ var maxU64Value = 18446744073709551615n;
27
+ function isLamports(putativeLamports) {
28
+ return putativeLamports >= 0 && putativeLamports <= maxU64Value;
29
+ }
30
+ function assertIsLamports(putativeLamports) {
31
+ if (putativeLamports < 0) {
32
+ throw new Error("Input for 64-bit unsigned integer cannot be negative");
33
+ }
34
+ if (putativeLamports > maxU64Value) {
35
+ throw new Error("Input number is too large to be represented as a 64-bit unsigned integer");
36
+ }
37
+ }
38
+ function lamports(putativeLamports) {
39
+ assertIsLamports(putativeLamports);
40
+ return putativeLamports;
41
+ }
42
+
43
+ // src/stringified-bigint.ts
44
+ function isStringifiedBigInt(putativeBigInt) {
45
+ try {
46
+ BigInt(putativeBigInt);
47
+ return true;
48
+ } catch (_) {
49
+ return false;
50
+ }
51
+ }
52
+ function assertIsStringifiedBigInt(putativeBigInt) {
53
+ try {
54
+ BigInt(putativeBigInt);
55
+ } catch (e) {
56
+ throw new Error(`\`${putativeBigInt}\` cannot be parsed as a BigInt`, {
57
+ cause: e
58
+ });
59
+ }
60
+ }
61
+ function stringifiedBigInt(putativeBigInt) {
62
+ assertIsStringifiedBigInt(putativeBigInt);
63
+ return putativeBigInt;
64
+ }
65
+
66
+ // src/stringified-number.ts
67
+ function isStringifiedNumber(putativeNumber) {
68
+ return !Number.isNaN(Number(putativeNumber));
69
+ }
70
+ function assertIsStringifiedNumber(putativeNumber) {
71
+ if (Number.isNaN(Number(putativeNumber))) {
72
+ throw new Error(`\`${putativeNumber}\` cannot be parsed as a Number`);
73
+ }
74
+ }
75
+ function stringifiedNumber(putativeNumber) {
76
+ assertIsStringifiedNumber(putativeNumber);
77
+ return putativeNumber;
78
+ }
79
+
80
+ // src/unix-timestamp.ts
81
+ function isUnixTimestamp(putativeTimestamp) {
82
+ if (putativeTimestamp > 864e13 || putativeTimestamp < -864e13) {
83
+ return false;
84
+ }
85
+ return true;
86
+ }
87
+ function assertIsUnixTimestamp(putativeTimestamp) {
88
+ try {
89
+ if (putativeTimestamp > 864e13 || putativeTimestamp < -864e13) {
90
+ throw new Error("Expected input number to be in the range [-8.64e15, 8.64e15]");
91
+ }
92
+ } catch (e) {
93
+ throw new Error(`\`${putativeTimestamp}\` is not a timestamp`, {
94
+ cause: e
95
+ });
96
+ }
97
+ }
98
+ function unixTimestamp(putativeTimestamp) {
99
+ assertIsUnixTimestamp(putativeTimestamp);
100
+ return putativeTimestamp;
101
+ }
102
+
103
+ exports.assertIsLamports = assertIsLamports;
104
+ exports.assertIsStringifiedBigInt = assertIsStringifiedBigInt;
105
+ exports.assertIsStringifiedNumber = assertIsStringifiedNumber;
106
+ exports.assertIsUnixTimestamp = assertIsUnixTimestamp;
107
+ exports.commitmentComparator = commitmentComparator;
108
+ exports.isLamports = isLamports;
109
+ exports.isStringifiedBigInt = isStringifiedBigInt;
110
+ exports.isStringifiedNumber = isStringifiedNumber;
111
+ exports.isUnixTimestamp = isUnixTimestamp;
112
+ exports.lamports = lamports;
113
+ exports.stringifiedBigInt = stringifiedBigInt;
114
+ exports.stringifiedNumber = stringifiedNumber;
115
+ exports.unixTimestamp = unixTimestamp;
116
+ //# sourceMappingURL=out.js.map
117
+ //# sourceMappingURL=index.browser.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commitment.ts","../src/lamports.ts","../src/stringified-bigint.ts","../src/stringified-number.ts","../src/unix-timestamp.ts"],"names":[],"mappings":";AAEA,SAAS,mBAAmB,YAAgC;AACxD,UAAQ,YAAY;AAAA,IAChB,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX;AACI,cAAQ,CAAC,MAAa;AAClB,cAAM,IAAI,MAAM,6BAA6B,UAAU,KAAK;AAAA,MAChE,GAAG,UAAU;AAAA,EACrB;AACJ;AAEO,SAAS,qBAAqB,GAAe,GAA2B;AAC3E,MAAI,MAAM,GAAG;AACT,WAAO;AAAA,EACX;AACA,SAAO,mBAAmB,CAAC,IAAI,mBAAmB,CAAC,IAAI,KAAK;AAChE;;;AChBA,IAAM,cAAc;AAEb,SAAS,WAAW,kBAAgF;AACvG,SAAO,oBAAoB,KAAK,oBAAoB;AACxD;AAEO,SAAS,iBACZ,kBAC4D;AAC5D,MAAI,mBAAmB,GAAG;AAEtB,UAAM,IAAI,MAAM,sDAAsD;AAAA,EAC1E;AAEA,MAAI,mBAAmB,aAAa;AAEhC,UAAM,IAAI,MAAM,0EAA0E;AAAA,EAC9F;AACJ;AAEO,SAAS,SAAS,kBAA4D;AACjF,mBAAiB,gBAAgB;AACjC,SAAO;AACX;;;AC3BO,SAAS,oBAAoB,gBAA6D;AAC7F,MAAI;AACA,WAAO,cAAc;AACrB,WAAO;AAAA,EACX,SAAS,GAAG;AACR,WAAO;AAAA,EACX;AACJ;AAEO,SAAS,0BAA0B,gBAAqE;AAC3G,MAAI;AACA,WAAO,cAAc;AAAA,EACzB,SAAS,GAAG;AACR,UAAM,IAAI,MAAM,KAAK,cAAc,mCAAmC;AAAA,MAClE,OAAO;AAAA,IACX,CAAC;AAAA,EACL;AACJ;AAEO,SAAS,kBAAkB,gBAA2C;AACzE,4BAA0B,cAAc;AACxC,SAAO;AACX;;;ACtBO,SAAS,oBAAoB,gBAA6D;AAC7F,SAAO,CAAC,OAAO,MAAM,OAAO,cAAc,CAAC;AAC/C;AAEO,SAAS,0BAA0B,gBAAqE;AAC3G,MAAI,OAAO,MAAM,OAAO,cAAc,CAAC,GAAG;AACtC,UAAM,IAAI,MAAM,KAAK,cAAc,iCAAiC;AAAA,EACxE;AACJ;AAEO,SAAS,kBAAkB,gBAA2C;AACzE,4BAA0B,cAAc;AACxC,SAAO;AACX;;;ACbO,SAAS,gBAAgB,mBAA+D;AAE3F,MAAI,oBAAoB,UAAW,oBAAoB,SAAU;AAC7D,WAAO;AAAA,EACX;AACA,SAAO;AACX;AAEO,SAAS,sBAAsB,mBAAuE;AAEzG,MAAI;AACA,QAAI,oBAAoB,UAAW,oBAAoB,SAAU;AAC7D,YAAM,IAAI,MAAM,8DAA8D;AAAA,IAClF;AAAA,EACJ,SAAS,GAAG;AACR,UAAM,IAAI,MAAM,KAAK,iBAAiB,yBAAyB;AAAA,MAC3D,OAAO;AAAA,IACX,CAAC;AAAA,EACL;AACJ;AAEO,SAAS,cAAc,mBAA0C;AACpE,wBAAsB,iBAAiB;AACvC,SAAO;AACX","sourcesContent":["export 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 return ((_: never) => {\n throw new Error(`Unrecognized commitment \\`${commitment}\\`.`);\n })(commitment);\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","// 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\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) {\n // TODO: Coded error.\n throw new Error('Input for 64-bit unsigned integer cannot be negative');\n }\n\n if (putativeLamports > maxU64Value) {\n // TODO: Coded error.\n throw new Error('Input number is too large to be represented as a 64-bit unsigned integer');\n }\n}\n\nexport function lamports(putativeLamports: bigint): LamportsUnsafeBeyond2Pow53Minus1 {\n assertIsLamports(putativeLamports);\n return putativeLamports;\n}\n","export 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 (e) {\n throw new Error(`\\`${putativeBigInt}\\` cannot be parsed as a BigInt`, {\n cause: e,\n });\n }\n}\n\nexport function stringifiedBigInt(putativeBigInt: string): StringifiedBigInt {\n assertIsStringifiedBigInt(putativeBigInt);\n return putativeBigInt;\n}\n","export 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 Error(`\\`${putativeNumber}\\` cannot be parsed as a Number`);\n }\n}\n\nexport function stringifiedNumber(putativeNumber: string): StringifiedNumber {\n assertIsStringifiedNumber(putativeNumber);\n return putativeNumber;\n}\n","export 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 try {\n if (putativeTimestamp > 8.64e15 || putativeTimestamp < -8.64e15) {\n throw new Error('Expected input number to be in the range [-8.64e15, 8.64e15]');\n }\n } catch (e) {\n throw new Error(`\\`${putativeTimestamp}\\` is not a timestamp`, {\n cause: e,\n });\n }\n}\n\nexport function unixTimestamp(putativeTimestamp: number): UnixTimestamp {\n assertIsUnixTimestamp(putativeTimestamp);\n return putativeTimestamp;\n}\n"]}
@@ -0,0 +1,103 @@
1
+ // src/commitment.ts
2
+ function getCommitmentScore(commitment) {
3
+ switch (commitment) {
4
+ case "finalized":
5
+ return 2;
6
+ case "confirmed":
7
+ return 1;
8
+ case "processed":
9
+ return 0;
10
+ default:
11
+ return ((_) => {
12
+ throw new Error(`Unrecognized commitment \`${commitment}\`.`);
13
+ })();
14
+ }
15
+ }
16
+ function commitmentComparator(a, b) {
17
+ if (a === b) {
18
+ return 0;
19
+ }
20
+ return getCommitmentScore(a) < getCommitmentScore(b) ? -1 : 1;
21
+ }
22
+
23
+ // src/lamports.ts
24
+ var maxU64Value = 18446744073709551615n;
25
+ function isLamports(putativeLamports) {
26
+ return putativeLamports >= 0 && putativeLamports <= maxU64Value;
27
+ }
28
+ function assertIsLamports(putativeLamports) {
29
+ if (putativeLamports < 0) {
30
+ throw new Error("Input for 64-bit unsigned integer cannot be negative");
31
+ }
32
+ if (putativeLamports > maxU64Value) {
33
+ throw new Error("Input number is too large to be represented as a 64-bit unsigned integer");
34
+ }
35
+ }
36
+ function lamports(putativeLamports) {
37
+ assertIsLamports(putativeLamports);
38
+ return putativeLamports;
39
+ }
40
+
41
+ // src/stringified-bigint.ts
42
+ function isStringifiedBigInt(putativeBigInt) {
43
+ try {
44
+ BigInt(putativeBigInt);
45
+ return true;
46
+ } catch (_) {
47
+ return false;
48
+ }
49
+ }
50
+ function assertIsStringifiedBigInt(putativeBigInt) {
51
+ try {
52
+ BigInt(putativeBigInt);
53
+ } catch (e) {
54
+ throw new Error(`\`${putativeBigInt}\` cannot be parsed as a BigInt`, {
55
+ cause: e
56
+ });
57
+ }
58
+ }
59
+ function stringifiedBigInt(putativeBigInt) {
60
+ assertIsStringifiedBigInt(putativeBigInt);
61
+ return putativeBigInt;
62
+ }
63
+
64
+ // src/stringified-number.ts
65
+ function isStringifiedNumber(putativeNumber) {
66
+ return !Number.isNaN(Number(putativeNumber));
67
+ }
68
+ function assertIsStringifiedNumber(putativeNumber) {
69
+ if (Number.isNaN(Number(putativeNumber))) {
70
+ throw new Error(`\`${putativeNumber}\` cannot be parsed as a Number`);
71
+ }
72
+ }
73
+ function stringifiedNumber(putativeNumber) {
74
+ assertIsStringifiedNumber(putativeNumber);
75
+ return putativeNumber;
76
+ }
77
+
78
+ // src/unix-timestamp.ts
79
+ function isUnixTimestamp(putativeTimestamp) {
80
+ if (putativeTimestamp > 864e13 || putativeTimestamp < -864e13) {
81
+ return false;
82
+ }
83
+ return true;
84
+ }
85
+ function assertIsUnixTimestamp(putativeTimestamp) {
86
+ try {
87
+ if (putativeTimestamp > 864e13 || putativeTimestamp < -864e13) {
88
+ throw new Error("Expected input number to be in the range [-8.64e15, 8.64e15]");
89
+ }
90
+ } catch (e) {
91
+ throw new Error(`\`${putativeTimestamp}\` is not a timestamp`, {
92
+ cause: e
93
+ });
94
+ }
95
+ }
96
+ function unixTimestamp(putativeTimestamp) {
97
+ assertIsUnixTimestamp(putativeTimestamp);
98
+ return putativeTimestamp;
99
+ }
100
+
101
+ export { assertIsLamports, assertIsStringifiedBigInt, assertIsStringifiedNumber, assertIsUnixTimestamp, commitmentComparator, isLamports, isStringifiedBigInt, isStringifiedNumber, isUnixTimestamp, lamports, stringifiedBigInt, stringifiedNumber, unixTimestamp };
102
+ //# sourceMappingURL=out.js.map
103
+ //# sourceMappingURL=index.browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commitment.ts","../src/lamports.ts","../src/stringified-bigint.ts","../src/stringified-number.ts","../src/unix-timestamp.ts"],"names":[],"mappings":";AAEA,SAAS,mBAAmB,YAAgC;AACxD,UAAQ,YAAY;AAAA,IAChB,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX;AACI,cAAQ,CAAC,MAAa;AAClB,cAAM,IAAI,MAAM,6BAA6B,UAAU,KAAK;AAAA,MAChE,GAAG,UAAU;AAAA,EACrB;AACJ;AAEO,SAAS,qBAAqB,GAAe,GAA2B;AAC3E,MAAI,MAAM,GAAG;AACT,WAAO;AAAA,EACX;AACA,SAAO,mBAAmB,CAAC,IAAI,mBAAmB,CAAC,IAAI,KAAK;AAChE;;;AChBA,IAAM,cAAc;AAEb,SAAS,WAAW,kBAAgF;AACvG,SAAO,oBAAoB,KAAK,oBAAoB;AACxD;AAEO,SAAS,iBACZ,kBAC4D;AAC5D,MAAI,mBAAmB,GAAG;AAEtB,UAAM,IAAI,MAAM,sDAAsD;AAAA,EAC1E;AAEA,MAAI,mBAAmB,aAAa;AAEhC,UAAM,IAAI,MAAM,0EAA0E;AAAA,EAC9F;AACJ;AAEO,SAAS,SAAS,kBAA4D;AACjF,mBAAiB,gBAAgB;AACjC,SAAO;AACX;;;AC3BO,SAAS,oBAAoB,gBAA6D;AAC7F,MAAI;AACA,WAAO,cAAc;AACrB,WAAO;AAAA,EACX,SAAS,GAAG;AACR,WAAO;AAAA,EACX;AACJ;AAEO,SAAS,0BAA0B,gBAAqE;AAC3G,MAAI;AACA,WAAO,cAAc;AAAA,EACzB,SAAS,GAAG;AACR,UAAM,IAAI,MAAM,KAAK,cAAc,mCAAmC;AAAA,MAClE,OAAO;AAAA,IACX,CAAC;AAAA,EACL;AACJ;AAEO,SAAS,kBAAkB,gBAA2C;AACzE,4BAA0B,cAAc;AACxC,SAAO;AACX;;;ACtBO,SAAS,oBAAoB,gBAA6D;AAC7F,SAAO,CAAC,OAAO,MAAM,OAAO,cAAc,CAAC;AAC/C;AAEO,SAAS,0BAA0B,gBAAqE;AAC3G,MAAI,OAAO,MAAM,OAAO,cAAc,CAAC,GAAG;AACtC,UAAM,IAAI,MAAM,KAAK,cAAc,iCAAiC;AAAA,EACxE;AACJ;AAEO,SAAS,kBAAkB,gBAA2C;AACzE,4BAA0B,cAAc;AACxC,SAAO;AACX;;;ACbO,SAAS,gBAAgB,mBAA+D;AAE3F,MAAI,oBAAoB,UAAW,oBAAoB,SAAU;AAC7D,WAAO;AAAA,EACX;AACA,SAAO;AACX;AAEO,SAAS,sBAAsB,mBAAuE;AAEzG,MAAI;AACA,QAAI,oBAAoB,UAAW,oBAAoB,SAAU;AAC7D,YAAM,IAAI,MAAM,8DAA8D;AAAA,IAClF;AAAA,EACJ,SAAS,GAAG;AACR,UAAM,IAAI,MAAM,KAAK,iBAAiB,yBAAyB;AAAA,MAC3D,OAAO;AAAA,IACX,CAAC;AAAA,EACL;AACJ;AAEO,SAAS,cAAc,mBAA0C;AACpE,wBAAsB,iBAAiB;AACvC,SAAO;AACX","sourcesContent":["export 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 return ((_: never) => {\n throw new Error(`Unrecognized commitment \\`${commitment}\\`.`);\n })(commitment);\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","// 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\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) {\n // TODO: Coded error.\n throw new Error('Input for 64-bit unsigned integer cannot be negative');\n }\n\n if (putativeLamports > maxU64Value) {\n // TODO: Coded error.\n throw new Error('Input number is too large to be represented as a 64-bit unsigned integer');\n }\n}\n\nexport function lamports(putativeLamports: bigint): LamportsUnsafeBeyond2Pow53Minus1 {\n assertIsLamports(putativeLamports);\n return putativeLamports;\n}\n","export 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 (e) {\n throw new Error(`\\`${putativeBigInt}\\` cannot be parsed as a BigInt`, {\n cause: e,\n });\n }\n}\n\nexport function stringifiedBigInt(putativeBigInt: string): StringifiedBigInt {\n assertIsStringifiedBigInt(putativeBigInt);\n return putativeBigInt;\n}\n","export 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 Error(`\\`${putativeNumber}\\` cannot be parsed as a Number`);\n }\n}\n\nexport function stringifiedNumber(putativeNumber: string): StringifiedNumber {\n assertIsStringifiedNumber(putativeNumber);\n return putativeNumber;\n}\n","export 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 try {\n if (putativeTimestamp > 8.64e15 || putativeTimestamp < -8.64e15) {\n throw new Error('Expected input number to be in the range [-8.64e15, 8.64e15]');\n }\n } catch (e) {\n throw new Error(`\\`${putativeTimestamp}\\` is not a timestamp`, {\n cause: e,\n });\n }\n}\n\nexport function unixTimestamp(putativeTimestamp: number): UnixTimestamp {\n assertIsUnixTimestamp(putativeTimestamp);\n return putativeTimestamp;\n}\n"]}
@@ -0,0 +1,103 @@
1
+ // src/commitment.ts
2
+ function getCommitmentScore(commitment) {
3
+ switch (commitment) {
4
+ case "finalized":
5
+ return 2;
6
+ case "confirmed":
7
+ return 1;
8
+ case "processed":
9
+ return 0;
10
+ default:
11
+ return ((_) => {
12
+ throw new Error(`Unrecognized commitment \`${commitment}\`.`);
13
+ })();
14
+ }
15
+ }
16
+ function commitmentComparator(a, b) {
17
+ if (a === b) {
18
+ return 0;
19
+ }
20
+ return getCommitmentScore(a) < getCommitmentScore(b) ? -1 : 1;
21
+ }
22
+
23
+ // src/lamports.ts
24
+ var maxU64Value = 18446744073709551615n;
25
+ function isLamports(putativeLamports) {
26
+ return putativeLamports >= 0 && putativeLamports <= maxU64Value;
27
+ }
28
+ function assertIsLamports(putativeLamports) {
29
+ if (putativeLamports < 0) {
30
+ throw new Error("Input for 64-bit unsigned integer cannot be negative");
31
+ }
32
+ if (putativeLamports > maxU64Value) {
33
+ throw new Error("Input number is too large to be represented as a 64-bit unsigned integer");
34
+ }
35
+ }
36
+ function lamports(putativeLamports) {
37
+ assertIsLamports(putativeLamports);
38
+ return putativeLamports;
39
+ }
40
+
41
+ // src/stringified-bigint.ts
42
+ function isStringifiedBigInt(putativeBigInt) {
43
+ try {
44
+ BigInt(putativeBigInt);
45
+ return true;
46
+ } catch (_) {
47
+ return false;
48
+ }
49
+ }
50
+ function assertIsStringifiedBigInt(putativeBigInt) {
51
+ try {
52
+ BigInt(putativeBigInt);
53
+ } catch (e) {
54
+ throw new Error(`\`${putativeBigInt}\` cannot be parsed as a BigInt`, {
55
+ cause: e
56
+ });
57
+ }
58
+ }
59
+ function stringifiedBigInt(putativeBigInt) {
60
+ assertIsStringifiedBigInt(putativeBigInt);
61
+ return putativeBigInt;
62
+ }
63
+
64
+ // src/stringified-number.ts
65
+ function isStringifiedNumber(putativeNumber) {
66
+ return !Number.isNaN(Number(putativeNumber));
67
+ }
68
+ function assertIsStringifiedNumber(putativeNumber) {
69
+ if (Number.isNaN(Number(putativeNumber))) {
70
+ throw new Error(`\`${putativeNumber}\` cannot be parsed as a Number`);
71
+ }
72
+ }
73
+ function stringifiedNumber(putativeNumber) {
74
+ assertIsStringifiedNumber(putativeNumber);
75
+ return putativeNumber;
76
+ }
77
+
78
+ // src/unix-timestamp.ts
79
+ function isUnixTimestamp(putativeTimestamp) {
80
+ if (putativeTimestamp > 864e13 || putativeTimestamp < -864e13) {
81
+ return false;
82
+ }
83
+ return true;
84
+ }
85
+ function assertIsUnixTimestamp(putativeTimestamp) {
86
+ try {
87
+ if (putativeTimestamp > 864e13 || putativeTimestamp < -864e13) {
88
+ throw new Error("Expected input number to be in the range [-8.64e15, 8.64e15]");
89
+ }
90
+ } catch (e) {
91
+ throw new Error(`\`${putativeTimestamp}\` is not a timestamp`, {
92
+ cause: e
93
+ });
94
+ }
95
+ }
96
+ function unixTimestamp(putativeTimestamp) {
97
+ assertIsUnixTimestamp(putativeTimestamp);
98
+ return putativeTimestamp;
99
+ }
100
+
101
+ export { assertIsLamports, assertIsStringifiedBigInt, assertIsStringifiedNumber, assertIsUnixTimestamp, commitmentComparator, isLamports, isStringifiedBigInt, isStringifiedNumber, isUnixTimestamp, lamports, stringifiedBigInt, stringifiedNumber, unixTimestamp };
102
+ //# sourceMappingURL=out.js.map
103
+ //# sourceMappingURL=index.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commitment.ts","../src/lamports.ts","../src/stringified-bigint.ts","../src/stringified-number.ts","../src/unix-timestamp.ts"],"names":[],"mappings":";AAEA,SAAS,mBAAmB,YAAgC;AACxD,UAAQ,YAAY;AAAA,IAChB,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX;AACI,cAAQ,CAAC,MAAa;AAClB,cAAM,IAAI,MAAM,6BAA6B,UAAU,KAAK;AAAA,MAChE,GAAG,UAAU;AAAA,EACrB;AACJ;AAEO,SAAS,qBAAqB,GAAe,GAA2B;AAC3E,MAAI,MAAM,GAAG;AACT,WAAO;AAAA,EACX;AACA,SAAO,mBAAmB,CAAC,IAAI,mBAAmB,CAAC,IAAI,KAAK;AAChE;;;AChBA,IAAM,cAAc;AAEb,SAAS,WAAW,kBAAgF;AACvG,SAAO,oBAAoB,KAAK,oBAAoB;AACxD;AAEO,SAAS,iBACZ,kBAC4D;AAC5D,MAAI,mBAAmB,GAAG;AAEtB,UAAM,IAAI,MAAM,sDAAsD;AAAA,EAC1E;AAEA,MAAI,mBAAmB,aAAa;AAEhC,UAAM,IAAI,MAAM,0EAA0E;AAAA,EAC9F;AACJ;AAEO,SAAS,SAAS,kBAA4D;AACjF,mBAAiB,gBAAgB;AACjC,SAAO;AACX;;;AC3BO,SAAS,oBAAoB,gBAA6D;AAC7F,MAAI;AACA,WAAO,cAAc;AACrB,WAAO;AAAA,EACX,SAAS,GAAG;AACR,WAAO;AAAA,EACX;AACJ;AAEO,SAAS,0BAA0B,gBAAqE;AAC3G,MAAI;AACA,WAAO,cAAc;AAAA,EACzB,SAAS,GAAG;AACR,UAAM,IAAI,MAAM,KAAK,cAAc,mCAAmC;AAAA,MAClE,OAAO;AAAA,IACX,CAAC;AAAA,EACL;AACJ;AAEO,SAAS,kBAAkB,gBAA2C;AACzE,4BAA0B,cAAc;AACxC,SAAO;AACX;;;ACtBO,SAAS,oBAAoB,gBAA6D;AAC7F,SAAO,CAAC,OAAO,MAAM,OAAO,cAAc,CAAC;AAC/C;AAEO,SAAS,0BAA0B,gBAAqE;AAC3G,MAAI,OAAO,MAAM,OAAO,cAAc,CAAC,GAAG;AACtC,UAAM,IAAI,MAAM,KAAK,cAAc,iCAAiC;AAAA,EACxE;AACJ;AAEO,SAAS,kBAAkB,gBAA2C;AACzE,4BAA0B,cAAc;AACxC,SAAO;AACX;;;ACbO,SAAS,gBAAgB,mBAA+D;AAE3F,MAAI,oBAAoB,UAAW,oBAAoB,SAAU;AAC7D,WAAO;AAAA,EACX;AACA,SAAO;AACX;AAEO,SAAS,sBAAsB,mBAAuE;AAEzG,MAAI;AACA,QAAI,oBAAoB,UAAW,oBAAoB,SAAU;AAC7D,YAAM,IAAI,MAAM,8DAA8D;AAAA,IAClF;AAAA,EACJ,SAAS,GAAG;AACR,UAAM,IAAI,MAAM,KAAK,iBAAiB,yBAAyB;AAAA,MAC3D,OAAO;AAAA,IACX,CAAC;AAAA,EACL;AACJ;AAEO,SAAS,cAAc,mBAA0C;AACpE,wBAAsB,iBAAiB;AACvC,SAAO;AACX","sourcesContent":["export 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 return ((_: never) => {\n throw new Error(`Unrecognized commitment \\`${commitment}\\`.`);\n })(commitment);\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","// 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\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) {\n // TODO: Coded error.\n throw new Error('Input for 64-bit unsigned integer cannot be negative');\n }\n\n if (putativeLamports > maxU64Value) {\n // TODO: Coded error.\n throw new Error('Input number is too large to be represented as a 64-bit unsigned integer');\n }\n}\n\nexport function lamports(putativeLamports: bigint): LamportsUnsafeBeyond2Pow53Minus1 {\n assertIsLamports(putativeLamports);\n return putativeLamports;\n}\n","export 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 (e) {\n throw new Error(`\\`${putativeBigInt}\\` cannot be parsed as a BigInt`, {\n cause: e,\n });\n }\n}\n\nexport function stringifiedBigInt(putativeBigInt: string): StringifiedBigInt {\n assertIsStringifiedBigInt(putativeBigInt);\n return putativeBigInt;\n}\n","export 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 Error(`\\`${putativeNumber}\\` cannot be parsed as a Number`);\n }\n}\n\nexport function stringifiedNumber(putativeNumber: string): StringifiedNumber {\n assertIsStringifiedNumber(putativeNumber);\n return putativeNumber;\n}\n","export 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 try {\n if (putativeTimestamp > 8.64e15 || putativeTimestamp < -8.64e15) {\n throw new Error('Expected input number to be in the range [-8.64e15, 8.64e15]');\n }\n } catch (e) {\n throw new Error(`\\`${putativeTimestamp}\\` is not a timestamp`, {\n cause: e,\n });\n }\n}\n\nexport function unixTimestamp(putativeTimestamp: number): UnixTimestamp {\n assertIsUnixTimestamp(putativeTimestamp);\n return putativeTimestamp;\n}\n"]}
@@ -0,0 +1,117 @@
1
+ 'use strict';
2
+
3
+ // src/commitment.ts
4
+ function getCommitmentScore(commitment) {
5
+ switch (commitment) {
6
+ case "finalized":
7
+ return 2;
8
+ case "confirmed":
9
+ return 1;
10
+ case "processed":
11
+ return 0;
12
+ default:
13
+ return ((_) => {
14
+ throw new Error(`Unrecognized commitment \`${commitment}\`.`);
15
+ })();
16
+ }
17
+ }
18
+ function commitmentComparator(a, b) {
19
+ if (a === b) {
20
+ return 0;
21
+ }
22
+ return getCommitmentScore(a) < getCommitmentScore(b) ? -1 : 1;
23
+ }
24
+
25
+ // src/lamports.ts
26
+ var maxU64Value = 18446744073709551615n;
27
+ function isLamports(putativeLamports) {
28
+ return putativeLamports >= 0 && putativeLamports <= maxU64Value;
29
+ }
30
+ function assertIsLamports(putativeLamports) {
31
+ if (putativeLamports < 0) {
32
+ throw new Error("Input for 64-bit unsigned integer cannot be negative");
33
+ }
34
+ if (putativeLamports > maxU64Value) {
35
+ throw new Error("Input number is too large to be represented as a 64-bit unsigned integer");
36
+ }
37
+ }
38
+ function lamports(putativeLamports) {
39
+ assertIsLamports(putativeLamports);
40
+ return putativeLamports;
41
+ }
42
+
43
+ // src/stringified-bigint.ts
44
+ function isStringifiedBigInt(putativeBigInt) {
45
+ try {
46
+ BigInt(putativeBigInt);
47
+ return true;
48
+ } catch (_) {
49
+ return false;
50
+ }
51
+ }
52
+ function assertIsStringifiedBigInt(putativeBigInt) {
53
+ try {
54
+ BigInt(putativeBigInt);
55
+ } catch (e) {
56
+ throw new Error(`\`${putativeBigInt}\` cannot be parsed as a BigInt`, {
57
+ cause: e
58
+ });
59
+ }
60
+ }
61
+ function stringifiedBigInt(putativeBigInt) {
62
+ assertIsStringifiedBigInt(putativeBigInt);
63
+ return putativeBigInt;
64
+ }
65
+
66
+ // src/stringified-number.ts
67
+ function isStringifiedNumber(putativeNumber) {
68
+ return !Number.isNaN(Number(putativeNumber));
69
+ }
70
+ function assertIsStringifiedNumber(putativeNumber) {
71
+ if (Number.isNaN(Number(putativeNumber))) {
72
+ throw new Error(`\`${putativeNumber}\` cannot be parsed as a Number`);
73
+ }
74
+ }
75
+ function stringifiedNumber(putativeNumber) {
76
+ assertIsStringifiedNumber(putativeNumber);
77
+ return putativeNumber;
78
+ }
79
+
80
+ // src/unix-timestamp.ts
81
+ function isUnixTimestamp(putativeTimestamp) {
82
+ if (putativeTimestamp > 864e13 || putativeTimestamp < -864e13) {
83
+ return false;
84
+ }
85
+ return true;
86
+ }
87
+ function assertIsUnixTimestamp(putativeTimestamp) {
88
+ try {
89
+ if (putativeTimestamp > 864e13 || putativeTimestamp < -864e13) {
90
+ throw new Error("Expected input number to be in the range [-8.64e15, 8.64e15]");
91
+ }
92
+ } catch (e) {
93
+ throw new Error(`\`${putativeTimestamp}\` is not a timestamp`, {
94
+ cause: e
95
+ });
96
+ }
97
+ }
98
+ function unixTimestamp(putativeTimestamp) {
99
+ assertIsUnixTimestamp(putativeTimestamp);
100
+ return putativeTimestamp;
101
+ }
102
+
103
+ exports.assertIsLamports = assertIsLamports;
104
+ exports.assertIsStringifiedBigInt = assertIsStringifiedBigInt;
105
+ exports.assertIsStringifiedNumber = assertIsStringifiedNumber;
106
+ exports.assertIsUnixTimestamp = assertIsUnixTimestamp;
107
+ exports.commitmentComparator = commitmentComparator;
108
+ exports.isLamports = isLamports;
109
+ exports.isStringifiedBigInt = isStringifiedBigInt;
110
+ exports.isStringifiedNumber = isStringifiedNumber;
111
+ exports.isUnixTimestamp = isUnixTimestamp;
112
+ exports.lamports = lamports;
113
+ exports.stringifiedBigInt = stringifiedBigInt;
114
+ exports.stringifiedNumber = stringifiedNumber;
115
+ exports.unixTimestamp = unixTimestamp;
116
+ //# sourceMappingURL=out.js.map
117
+ //# sourceMappingURL=index.node.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commitment.ts","../src/lamports.ts","../src/stringified-bigint.ts","../src/stringified-number.ts","../src/unix-timestamp.ts"],"names":[],"mappings":";AAEA,SAAS,mBAAmB,YAAgC;AACxD,UAAQ,YAAY;AAAA,IAChB,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX;AACI,cAAQ,CAAC,MAAa;AAClB,cAAM,IAAI,MAAM,6BAA6B,UAAU,KAAK;AAAA,MAChE,GAAG,UAAU;AAAA,EACrB;AACJ;AAEO,SAAS,qBAAqB,GAAe,GAA2B;AAC3E,MAAI,MAAM,GAAG;AACT,WAAO;AAAA,EACX;AACA,SAAO,mBAAmB,CAAC,IAAI,mBAAmB,CAAC,IAAI,KAAK;AAChE;;;AChBA,IAAM,cAAc;AAEb,SAAS,WAAW,kBAAgF;AACvG,SAAO,oBAAoB,KAAK,oBAAoB;AACxD;AAEO,SAAS,iBACZ,kBAC4D;AAC5D,MAAI,mBAAmB,GAAG;AAEtB,UAAM,IAAI,MAAM,sDAAsD;AAAA,EAC1E;AAEA,MAAI,mBAAmB,aAAa;AAEhC,UAAM,IAAI,MAAM,0EAA0E;AAAA,EAC9F;AACJ;AAEO,SAAS,SAAS,kBAA4D;AACjF,mBAAiB,gBAAgB;AACjC,SAAO;AACX;;;AC3BO,SAAS,oBAAoB,gBAA6D;AAC7F,MAAI;AACA,WAAO,cAAc;AACrB,WAAO;AAAA,EACX,SAAS,GAAG;AACR,WAAO;AAAA,EACX;AACJ;AAEO,SAAS,0BAA0B,gBAAqE;AAC3G,MAAI;AACA,WAAO,cAAc;AAAA,EACzB,SAAS,GAAG;AACR,UAAM,IAAI,MAAM,KAAK,cAAc,mCAAmC;AAAA,MAClE,OAAO;AAAA,IACX,CAAC;AAAA,EACL;AACJ;AAEO,SAAS,kBAAkB,gBAA2C;AACzE,4BAA0B,cAAc;AACxC,SAAO;AACX;;;ACtBO,SAAS,oBAAoB,gBAA6D;AAC7F,SAAO,CAAC,OAAO,MAAM,OAAO,cAAc,CAAC;AAC/C;AAEO,SAAS,0BAA0B,gBAAqE;AAC3G,MAAI,OAAO,MAAM,OAAO,cAAc,CAAC,GAAG;AACtC,UAAM,IAAI,MAAM,KAAK,cAAc,iCAAiC;AAAA,EACxE;AACJ;AAEO,SAAS,kBAAkB,gBAA2C;AACzE,4BAA0B,cAAc;AACxC,SAAO;AACX;;;ACbO,SAAS,gBAAgB,mBAA+D;AAE3F,MAAI,oBAAoB,UAAW,oBAAoB,SAAU;AAC7D,WAAO;AAAA,EACX;AACA,SAAO;AACX;AAEO,SAAS,sBAAsB,mBAAuE;AAEzG,MAAI;AACA,QAAI,oBAAoB,UAAW,oBAAoB,SAAU;AAC7D,YAAM,IAAI,MAAM,8DAA8D;AAAA,IAClF;AAAA,EACJ,SAAS,GAAG;AACR,UAAM,IAAI,MAAM,KAAK,iBAAiB,yBAAyB;AAAA,MAC3D,OAAO;AAAA,IACX,CAAC;AAAA,EACL;AACJ;AAEO,SAAS,cAAc,mBAA0C;AACpE,wBAAsB,iBAAiB;AACvC,SAAO;AACX","sourcesContent":["export 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 return ((_: never) => {\n throw new Error(`Unrecognized commitment \\`${commitment}\\`.`);\n })(commitment);\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","// 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\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) {\n // TODO: Coded error.\n throw new Error('Input for 64-bit unsigned integer cannot be negative');\n }\n\n if (putativeLamports > maxU64Value) {\n // TODO: Coded error.\n throw new Error('Input number is too large to be represented as a 64-bit unsigned integer');\n }\n}\n\nexport function lamports(putativeLamports: bigint): LamportsUnsafeBeyond2Pow53Minus1 {\n assertIsLamports(putativeLamports);\n return putativeLamports;\n}\n","export 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 (e) {\n throw new Error(`\\`${putativeBigInt}\\` cannot be parsed as a BigInt`, {\n cause: e,\n });\n }\n}\n\nexport function stringifiedBigInt(putativeBigInt: string): StringifiedBigInt {\n assertIsStringifiedBigInt(putativeBigInt);\n return putativeBigInt;\n}\n","export 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 Error(`\\`${putativeNumber}\\` cannot be parsed as a Number`);\n }\n}\n\nexport function stringifiedNumber(putativeNumber: string): StringifiedNumber {\n assertIsStringifiedNumber(putativeNumber);\n return putativeNumber;\n}\n","export 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 try {\n if (putativeTimestamp > 8.64e15 || putativeTimestamp < -8.64e15) {\n throw new Error('Expected input number to be in the range [-8.64e15, 8.64e15]');\n }\n } catch (e) {\n throw new Error(`\\`${putativeTimestamp}\\` is not a timestamp`, {\n cause: e,\n });\n }\n}\n\nexport function unixTimestamp(putativeTimestamp: number): UnixTimestamp {\n assertIsUnixTimestamp(putativeTimestamp);\n return putativeTimestamp;\n}\n"]}
@@ -0,0 +1,103 @@
1
+ // src/commitment.ts
2
+ function getCommitmentScore(commitment) {
3
+ switch (commitment) {
4
+ case "finalized":
5
+ return 2;
6
+ case "confirmed":
7
+ return 1;
8
+ case "processed":
9
+ return 0;
10
+ default:
11
+ return ((_) => {
12
+ throw new Error(`Unrecognized commitment \`${commitment}\`.`);
13
+ })();
14
+ }
15
+ }
16
+ function commitmentComparator(a, b) {
17
+ if (a === b) {
18
+ return 0;
19
+ }
20
+ return getCommitmentScore(a) < getCommitmentScore(b) ? -1 : 1;
21
+ }
22
+
23
+ // src/lamports.ts
24
+ var maxU64Value = 18446744073709551615n;
25
+ function isLamports(putativeLamports) {
26
+ return putativeLamports >= 0 && putativeLamports <= maxU64Value;
27
+ }
28
+ function assertIsLamports(putativeLamports) {
29
+ if (putativeLamports < 0) {
30
+ throw new Error("Input for 64-bit unsigned integer cannot be negative");
31
+ }
32
+ if (putativeLamports > maxU64Value) {
33
+ throw new Error("Input number is too large to be represented as a 64-bit unsigned integer");
34
+ }
35
+ }
36
+ function lamports(putativeLamports) {
37
+ assertIsLamports(putativeLamports);
38
+ return putativeLamports;
39
+ }
40
+
41
+ // src/stringified-bigint.ts
42
+ function isStringifiedBigInt(putativeBigInt) {
43
+ try {
44
+ BigInt(putativeBigInt);
45
+ return true;
46
+ } catch (_) {
47
+ return false;
48
+ }
49
+ }
50
+ function assertIsStringifiedBigInt(putativeBigInt) {
51
+ try {
52
+ BigInt(putativeBigInt);
53
+ } catch (e) {
54
+ throw new Error(`\`${putativeBigInt}\` cannot be parsed as a BigInt`, {
55
+ cause: e
56
+ });
57
+ }
58
+ }
59
+ function stringifiedBigInt(putativeBigInt) {
60
+ assertIsStringifiedBigInt(putativeBigInt);
61
+ return putativeBigInt;
62
+ }
63
+
64
+ // src/stringified-number.ts
65
+ function isStringifiedNumber(putativeNumber) {
66
+ return !Number.isNaN(Number(putativeNumber));
67
+ }
68
+ function assertIsStringifiedNumber(putativeNumber) {
69
+ if (Number.isNaN(Number(putativeNumber))) {
70
+ throw new Error(`\`${putativeNumber}\` cannot be parsed as a Number`);
71
+ }
72
+ }
73
+ function stringifiedNumber(putativeNumber) {
74
+ assertIsStringifiedNumber(putativeNumber);
75
+ return putativeNumber;
76
+ }
77
+
78
+ // src/unix-timestamp.ts
79
+ function isUnixTimestamp(putativeTimestamp) {
80
+ if (putativeTimestamp > 864e13 || putativeTimestamp < -864e13) {
81
+ return false;
82
+ }
83
+ return true;
84
+ }
85
+ function assertIsUnixTimestamp(putativeTimestamp) {
86
+ try {
87
+ if (putativeTimestamp > 864e13 || putativeTimestamp < -864e13) {
88
+ throw new Error("Expected input number to be in the range [-8.64e15, 8.64e15]");
89
+ }
90
+ } catch (e) {
91
+ throw new Error(`\`${putativeTimestamp}\` is not a timestamp`, {
92
+ cause: e
93
+ });
94
+ }
95
+ }
96
+ function unixTimestamp(putativeTimestamp) {
97
+ assertIsUnixTimestamp(putativeTimestamp);
98
+ return putativeTimestamp;
99
+ }
100
+
101
+ export { assertIsLamports, assertIsStringifiedBigInt, assertIsStringifiedNumber, assertIsUnixTimestamp, commitmentComparator, isLamports, isStringifiedBigInt, isStringifiedNumber, isUnixTimestamp, lamports, stringifiedBigInt, stringifiedNumber, unixTimestamp };
102
+ //# sourceMappingURL=out.js.map
103
+ //# sourceMappingURL=index.node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commitment.ts","../src/lamports.ts","../src/stringified-bigint.ts","../src/stringified-number.ts","../src/unix-timestamp.ts"],"names":[],"mappings":";AAEA,SAAS,mBAAmB,YAAgC;AACxD,UAAQ,YAAY;AAAA,IAChB,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX,KAAK;AACD,aAAO;AAAA,IACX;AACI,cAAQ,CAAC,MAAa;AAClB,cAAM,IAAI,MAAM,6BAA6B,UAAU,KAAK;AAAA,MAChE,GAAG,UAAU;AAAA,EACrB;AACJ;AAEO,SAAS,qBAAqB,GAAe,GAA2B;AAC3E,MAAI,MAAM,GAAG;AACT,WAAO;AAAA,EACX;AACA,SAAO,mBAAmB,CAAC,IAAI,mBAAmB,CAAC,IAAI,KAAK;AAChE;;;AChBA,IAAM,cAAc;AAEb,SAAS,WAAW,kBAAgF;AACvG,SAAO,oBAAoB,KAAK,oBAAoB;AACxD;AAEO,SAAS,iBACZ,kBAC4D;AAC5D,MAAI,mBAAmB,GAAG;AAEtB,UAAM,IAAI,MAAM,sDAAsD;AAAA,EAC1E;AAEA,MAAI,mBAAmB,aAAa;AAEhC,UAAM,IAAI,MAAM,0EAA0E;AAAA,EAC9F;AACJ;AAEO,SAAS,SAAS,kBAA4D;AACjF,mBAAiB,gBAAgB;AACjC,SAAO;AACX;;;AC3BO,SAAS,oBAAoB,gBAA6D;AAC7F,MAAI;AACA,WAAO,cAAc;AACrB,WAAO;AAAA,EACX,SAAS,GAAG;AACR,WAAO;AAAA,EACX;AACJ;AAEO,SAAS,0BAA0B,gBAAqE;AAC3G,MAAI;AACA,WAAO,cAAc;AAAA,EACzB,SAAS,GAAG;AACR,UAAM,IAAI,MAAM,KAAK,cAAc,mCAAmC;AAAA,MAClE,OAAO;AAAA,IACX,CAAC;AAAA,EACL;AACJ;AAEO,SAAS,kBAAkB,gBAA2C;AACzE,4BAA0B,cAAc;AACxC,SAAO;AACX;;;ACtBO,SAAS,oBAAoB,gBAA6D;AAC7F,SAAO,CAAC,OAAO,MAAM,OAAO,cAAc,CAAC;AAC/C;AAEO,SAAS,0BAA0B,gBAAqE;AAC3G,MAAI,OAAO,MAAM,OAAO,cAAc,CAAC,GAAG;AACtC,UAAM,IAAI,MAAM,KAAK,cAAc,iCAAiC;AAAA,EACxE;AACJ;AAEO,SAAS,kBAAkB,gBAA2C;AACzE,4BAA0B,cAAc;AACxC,SAAO;AACX;;;ACbO,SAAS,gBAAgB,mBAA+D;AAE3F,MAAI,oBAAoB,UAAW,oBAAoB,SAAU;AAC7D,WAAO;AAAA,EACX;AACA,SAAO;AACX;AAEO,SAAS,sBAAsB,mBAAuE;AAEzG,MAAI;AACA,QAAI,oBAAoB,UAAW,oBAAoB,SAAU;AAC7D,YAAM,IAAI,MAAM,8DAA8D;AAAA,IAClF;AAAA,EACJ,SAAS,GAAG;AACR,UAAM,IAAI,MAAM,KAAK,iBAAiB,yBAAyB;AAAA,MAC3D,OAAO;AAAA,IACX,CAAC;AAAA,EACL;AACJ;AAEO,SAAS,cAAc,mBAA0C;AACpE,wBAAsB,iBAAiB;AACvC,SAAO;AACX","sourcesContent":["export 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 return ((_: never) => {\n throw new Error(`Unrecognized commitment \\`${commitment}\\`.`);\n })(commitment);\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","// 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\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) {\n // TODO: Coded error.\n throw new Error('Input for 64-bit unsigned integer cannot be negative');\n }\n\n if (putativeLamports > maxU64Value) {\n // TODO: Coded error.\n throw new Error('Input number is too large to be represented as a 64-bit unsigned integer');\n }\n}\n\nexport function lamports(putativeLamports: bigint): LamportsUnsafeBeyond2Pow53Minus1 {\n assertIsLamports(putativeLamports);\n return putativeLamports;\n}\n","export 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 (e) {\n throw new Error(`\\`${putativeBigInt}\\` cannot be parsed as a BigInt`, {\n cause: e,\n });\n }\n}\n\nexport function stringifiedBigInt(putativeBigInt: string): StringifiedBigInt {\n assertIsStringifiedBigInt(putativeBigInt);\n return putativeBigInt;\n}\n","export 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 Error(`\\`${putativeNumber}\\` cannot be parsed as a Number`);\n }\n}\n\nexport function stringifiedNumber(putativeNumber: string): StringifiedNumber {\n assertIsStringifiedNumber(putativeNumber);\n return putativeNumber;\n}\n","export 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 try {\n if (putativeTimestamp > 8.64e15 || putativeTimestamp < -8.64e15) {\n throw new Error('Expected input number to be in the range [-8.64e15, 8.64e15]');\n }\n } catch (e) {\n throw new Error(`\\`${putativeTimestamp}\\` is not a timestamp`, {\n cause: e,\n });\n }\n}\n\nexport function unixTimestamp(putativeTimestamp: number): UnixTimestamp {\n assertIsUnixTimestamp(putativeTimestamp);\n return putativeTimestamp;\n}\n"]}
@@ -0,0 +1,3 @@
1
+ export type Commitment = 'confirmed' | 'finalized' | 'processed';
2
+ export declare function commitmentComparator(a: Commitment, b: Commitment): -1 | 0 | 1;
3
+ //# sourceMappingURL=commitment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commitment.d.ts","sourceRoot":"","sources":["../../src/commitment.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,WAAW,GAAG,WAAW,CAAC;AAiBjE,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAK7E"}
@@ -0,0 +1,6 @@
1
+ export * from './commitment';
2
+ export * from './lamports';
3
+ export * from './stringified-bigint';
4
+ export * from './stringified-number';
5
+ export * from './unix-timestamp';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,7 @@
1
+ export type LamportsUnsafeBeyond2Pow53Minus1 = bigint & {
2
+ readonly __brand: unique symbol;
3
+ };
4
+ export declare function isLamports(putativeLamports: bigint): putativeLamports is LamportsUnsafeBeyond2Pow53Minus1;
5
+ export declare function assertIsLamports(putativeLamports: bigint): asserts putativeLamports is LamportsUnsafeBeyond2Pow53Minus1;
6
+ export declare function lamports(putativeLamports: bigint): LamportsUnsafeBeyond2Pow53Minus1;
7
+ //# sourceMappingURL=lamports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lamports.d.ts","sourceRoot":"","sources":["../../src/lamports.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,gCAAgC,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,MAAM,CAAA;CAAE,CAAC;AAK5F,wBAAgB,UAAU,CAAC,gBAAgB,EAAE,MAAM,GAAG,gBAAgB,IAAI,gCAAgC,CAEzG;AAED,wBAAgB,gBAAgB,CAC5B,gBAAgB,EAAE,MAAM,GACzB,OAAO,CAAC,gBAAgB,IAAI,gCAAgC,CAU9D;AAED,wBAAgB,QAAQ,CAAC,gBAAgB,EAAE,MAAM,GAAG,gCAAgC,CAGnF"}
@@ -0,0 +1,7 @@
1
+ export type StringifiedBigInt = string & {
2
+ readonly __brand: unique symbol;
3
+ };
4
+ export declare function isStringifiedBigInt(putativeBigInt: string): putativeBigInt is StringifiedBigInt;
5
+ export declare function assertIsStringifiedBigInt(putativeBigInt: string): asserts putativeBigInt is StringifiedBigInt;
6
+ export declare function stringifiedBigInt(putativeBigInt: string): StringifiedBigInt;
7
+ //# sourceMappingURL=stringified-bigint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stringified-bigint.d.ts","sourceRoot":"","sources":["../../src/stringified-bigint.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,MAAM,CAAA;CAAE,CAAC;AAE7E,wBAAgB,mBAAmB,CAAC,cAAc,EAAE,MAAM,GAAG,cAAc,IAAI,iBAAiB,CAO/F;AAED,wBAAgB,yBAAyB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,IAAI,iBAAiB,CAQ7G;AAED,wBAAgB,iBAAiB,CAAC,cAAc,EAAE,MAAM,GAAG,iBAAiB,CAG3E"}
@@ -0,0 +1,7 @@
1
+ export type StringifiedNumber = string & {
2
+ readonly __brand: unique symbol;
3
+ };
4
+ export declare function isStringifiedNumber(putativeNumber: string): putativeNumber is StringifiedNumber;
5
+ export declare function assertIsStringifiedNumber(putativeNumber: string): asserts putativeNumber is StringifiedNumber;
6
+ export declare function stringifiedNumber(putativeNumber: string): StringifiedNumber;
7
+ //# sourceMappingURL=stringified-number.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stringified-number.d.ts","sourceRoot":"","sources":["../../src/stringified-number.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,MAAM,CAAA;CAAE,CAAC;AAE7E,wBAAgB,mBAAmB,CAAC,cAAc,EAAE,MAAM,GAAG,cAAc,IAAI,iBAAiB,CAE/F;AAED,wBAAgB,yBAAyB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,IAAI,iBAAiB,CAI7G;AAED,wBAAgB,iBAAiB,CAAC,cAAc,EAAE,MAAM,GAAG,iBAAiB,CAG3E"}
@@ -0,0 +1,7 @@
1
+ export type UnixTimestamp = number & {
2
+ readonly __brand: unique symbol;
3
+ };
4
+ export declare function isUnixTimestamp(putativeTimestamp: number): putativeTimestamp is UnixTimestamp;
5
+ export declare function assertIsUnixTimestamp(putativeTimestamp: number): asserts putativeTimestamp is UnixTimestamp;
6
+ export declare function unixTimestamp(putativeTimestamp: number): UnixTimestamp;
7
+ //# sourceMappingURL=unix-timestamp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unix-timestamp.d.ts","sourceRoot":"","sources":["../../src/unix-timestamp.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,MAAM,CAAA;CAAE,CAAC;AAEzE,wBAAgB,eAAe,CAAC,iBAAiB,EAAE,MAAM,GAAG,iBAAiB,IAAI,aAAa,CAM7F;AAED,wBAAgB,qBAAqB,CAAC,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,IAAI,aAAa,CAW3G;AAED,wBAAgB,aAAa,CAAC,iBAAiB,EAAE,MAAM,GAAG,aAAa,CAGtE"}
package/package.json ADDED
@@ -0,0 +1,95 @@
1
+ {
2
+ "name": "@solana/rpc-types",
3
+ "version": "2.0.0-experimental.25278c4",
4
+ "description": "Type definitions for values used in the Solana RPC, and helper functions for working with them",
5
+ "exports": {
6
+ "browser": {
7
+ "import": "./dist/index.browser.js",
8
+ "require": "./dist/index.browser.cjs"
9
+ },
10
+ "node": {
11
+ "import": "./dist/index.node.js",
12
+ "require": "./dist/index.node.cjs"
13
+ },
14
+ "react-native": "./dist/index.native.js",
15
+ "types": "./dist/types/index.d.ts"
16
+ },
17
+ "browser": {
18
+ "./dist/index.node.cjs": "./dist/index.browser.cjs",
19
+ "./dist/index.node.js": "./dist/index.browser.js"
20
+ },
21
+ "main": "./dist/index.node.cjs",
22
+ "module": "./dist/index.node.js",
23
+ "react-native": "./dist/index.native.js",
24
+ "types": "./dist/types/index.d.ts",
25
+ "type": "module",
26
+ "files": [
27
+ "./dist/"
28
+ ],
29
+ "sideEffects": false,
30
+ "keywords": [
31
+ "blockchain",
32
+ "solana",
33
+ "web3"
34
+ ],
35
+ "author": "Solana Labs Maintainers <maintainers@solanalabs.com>",
36
+ "license": "MIT",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "https://github.com/solana-labs/solana-web3.js"
40
+ },
41
+ "bugs": {
42
+ "url": "http://github.com/solana-labs/solana-web3.js/issues"
43
+ },
44
+ "browserslist": [
45
+ "supports bigint and not dead",
46
+ "maintained node versions"
47
+ ],
48
+ "devDependencies": {
49
+ "@solana/eslint-config-solana": "^1.0.2",
50
+ "@swc/jest": "^0.2.29",
51
+ "@types/jest": "^29.5.6",
52
+ "@typescript-eslint/eslint-plugin": "^6.7.0",
53
+ "@typescript-eslint/parser": "^6.3.0",
54
+ "agadoo": "^3.0.0",
55
+ "eslint": "^8.45.0",
56
+ "eslint-plugin-jest": "^27.4.2",
57
+ "eslint-plugin-sort-keys-fix": "^1.1.2",
58
+ "jest": "^29.7.0",
59
+ "jest-environment-jsdom": "^29.7.0",
60
+ "jest-fetch-mock-fork": "^3.0.4",
61
+ "jest-runner-eslint": "^2.1.2",
62
+ "jest-runner-prettier": "^1.0.0",
63
+ "prettier": "^2.8",
64
+ "tsup": "7.2.0",
65
+ "typescript": "^5.2.2",
66
+ "version-from-git": "^1.1.1",
67
+ "@solana/transactions": "2.0.0-experimental.25278c4",
68
+ "build-scripts": "0.0.0",
69
+ "test-config": "0.0.0",
70
+ "tsconfig": "0.0.0"
71
+ },
72
+ "bundlewatch": {
73
+ "defaultCompression": "gzip",
74
+ "files": [
75
+ {
76
+ "path": "./dist/index*.js"
77
+ }
78
+ ]
79
+ },
80
+ "scripts": {
81
+ "compile:js": "tsup --config build-scripts/tsup.config.package.ts",
82
+ "compile:typedefs": "tsc -p ./tsconfig.declarations.json",
83
+ "dev": "jest -c node_modules/test-config/jest-dev.config.ts --globalSetup test-config/test-validator-setup.js --globalTeardown test-config/test-validator-teardown.js --rootDir . --watch",
84
+ "publish-packages": "pnpm publish --tag experimental --access public --no-git-checks",
85
+ "style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/* package.json",
86
+ "test:lint": "jest -c node_modules/test-config/jest-lint.config.ts --rootDir . --silent",
87
+ "test:prettier": "jest -c node_modules/test-config/jest-prettier.config.ts --rootDir . --silent",
88
+ "test:treeshakability:browser": "agadoo dist/index.browser.js",
89
+ "test:treeshakability:native": "agadoo dist/index.native.js",
90
+ "test:treeshakability:node": "agadoo dist/index.node.js",
91
+ "test:typecheck": "tsc --noEmit",
92
+ "test:unit:browser": "jest -c node_modules/test-config/jest-unit.config.browser.ts --globalSetup test-config/test-validator-setup.js --globalTeardown test-config/test-validator-teardown.js --rootDir . --silent",
93
+ "test:unit:node": "jest -c node_modules/test-config/jest-unit.config.node.ts --globalSetup test-config/test-validator-setup.js --globalTeardown test-config/test-validator-teardown.js --rootDir . --silent"
94
+ }
95
+ }