@solana/web3.js 1.74.0 → 2.0.0-experimental.1b52291

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 (102) hide show
  1. package/README.md +55 -112
  2. package/dist/index.browser.cjs +77 -0
  3. package/dist/index.browser.cjs.map +1 -0
  4. package/dist/index.browser.js +68 -0
  5. package/dist/index.browser.js.map +1 -0
  6. package/dist/index.development.js +539 -0
  7. package/dist/index.development.js.map +1 -0
  8. package/dist/index.native.js +70 -0
  9. package/dist/index.native.js.map +1 -0
  10. package/dist/index.node.cjs +79 -0
  11. package/dist/index.node.cjs.map +1 -0
  12. package/dist/index.node.js +70 -0
  13. package/dist/index.node.js.map +1 -0
  14. package/dist/index.production.min.js +13 -0
  15. package/dist/types/index.d.ts +4 -0
  16. package/dist/types/index.d.ts.map +1 -0
  17. package/dist/types/rpc-default-config.d.ts +3 -0
  18. package/dist/types/rpc-default-config.d.ts.map +1 -0
  19. package/dist/types/rpc-integer-overflow-error.d.ts +8 -0
  20. package/dist/types/rpc-integer-overflow-error.d.ts.map +1 -0
  21. package/dist/types/rpc-transport.d.ts +4 -0
  22. package/dist/types/rpc-transport.d.ts.map +1 -0
  23. package/dist/types/rpc.d.ts +5 -0
  24. package/dist/types/rpc.d.ts.map +1 -0
  25. package/package.json +86 -113
  26. package/lib/index.browser.cjs.js +0 -9485
  27. package/lib/index.browser.cjs.js.map +0 -1
  28. package/lib/index.browser.esm.js +0 -9379
  29. package/lib/index.browser.esm.js.map +0 -1
  30. package/lib/index.cjs.js +0 -12009
  31. package/lib/index.cjs.js.map +0 -1
  32. package/lib/index.d.ts +0 -3865
  33. package/lib/index.esm.js +0 -11896
  34. package/lib/index.esm.js.map +0 -1
  35. package/lib/index.iife.js +0 -24568
  36. package/lib/index.iife.js.map +0 -1
  37. package/lib/index.iife.min.js +0 -13
  38. package/lib/index.iife.min.js.map +0 -1
  39. package/lib/index.native.js +0 -9485
  40. package/lib/index.native.js.map +0 -1
  41. package/src/__forks__/browser/fetch-impl.ts +0 -4
  42. package/src/__forks__/browser/rpc-websocket-factory.ts +0 -1
  43. package/src/__forks__/react-native/fetch-impl.ts +0 -4
  44. package/src/__forks__/react-native/rpc-websocket-factory.ts +0 -1
  45. package/src/account-data.ts +0 -39
  46. package/src/account.ts +0 -55
  47. package/src/blockhash.ts +0 -4
  48. package/src/bpf-loader-deprecated.ts +0 -5
  49. package/src/bpf-loader.ts +0 -45
  50. package/src/connection.ts +0 -6678
  51. package/src/epoch-schedule.ts +0 -102
  52. package/src/errors.ts +0 -50
  53. package/src/fee-calculator.ts +0 -18
  54. package/src/fetch-impl.ts +0 -13
  55. package/src/index.ts +0 -24
  56. package/src/instruction.ts +0 -58
  57. package/src/keypair.ts +0 -93
  58. package/src/layout.ts +0 -188
  59. package/src/loader.ts +0 -236
  60. package/src/message/account-keys.ts +0 -79
  61. package/src/message/compiled-keys.ts +0 -165
  62. package/src/message/index.ts +0 -47
  63. package/src/message/legacy.ts +0 -326
  64. package/src/message/v0.ts +0 -496
  65. package/src/message/versioned.ts +0 -36
  66. package/src/nonce-account.ts +0 -82
  67. package/src/programs/address-lookup-table/index.ts +0 -435
  68. package/src/programs/address-lookup-table/state.ts +0 -84
  69. package/src/programs/compute-budget.ts +0 -281
  70. package/src/programs/ed25519.ts +0 -157
  71. package/src/programs/index.ts +0 -7
  72. package/src/programs/secp256k1.ts +0 -228
  73. package/src/programs/stake.ts +0 -935
  74. package/src/programs/system.ts +0 -1048
  75. package/src/programs/vote.ts +0 -541
  76. package/src/publickey.ts +0 -259
  77. package/src/rpc-websocket-factory.ts +0 -4
  78. package/src/rpc-websocket.ts +0 -79
  79. package/src/sysvar.ts +0 -37
  80. package/src/timing.ts +0 -23
  81. package/src/transaction/constants.ts +0 -12
  82. package/src/transaction/expiry-custom-errors.ts +0 -48
  83. package/src/transaction/index.ts +0 -5
  84. package/src/transaction/legacy.ts +0 -908
  85. package/src/transaction/message.ts +0 -140
  86. package/src/transaction/versioned.ts +0 -126
  87. package/src/utils/assert.ts +0 -8
  88. package/src/utils/bigint.ts +0 -43
  89. package/src/utils/borsh-schema.ts +0 -38
  90. package/src/utils/cluster.ts +0 -31
  91. package/src/utils/ed25519.ts +0 -46
  92. package/src/utils/index.ts +0 -5
  93. package/src/utils/makeWebsocketUrl.ts +0 -26
  94. package/src/utils/promise-timeout.ts +0 -14
  95. package/src/utils/secp256k1.ts +0 -18
  96. package/src/utils/send-and-confirm-raw-transaction.ts +0 -102
  97. package/src/utils/send-and-confirm-transaction.ts +0 -98
  98. package/src/utils/shortvec-encoding.ts +0 -28
  99. package/src/utils/sleep.ts +0 -4
  100. package/src/utils/to-buffer.ts +0 -11
  101. package/src/validator-info.ts +0 -104
  102. package/src/vote-account.ts +0 -236
package/README.md CHANGED
@@ -6,150 +6,93 @@
6
6
 
7
7
  [code-style-prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square
8
8
  [code-style-prettier-url]: https://github.com/prettier/prettier
9
- [npm-downloads-image]: https://img.shields.io/npm/dm/@solana/web3.js.svg?style=flat
10
- [npm-image]: https://img.shields.io/npm/v/@solana/web3.js.svg?style=flat
11
- [npm-url]: https://www.npmjs.com/package/@solana/web3.js
9
+ [npm-downloads-image]: https://img.shields.io/npm/dm/@solana/web3.js/experimental.svg?style=flat
10
+ [npm-image]: https://img.shields.io/npm/v/@solana/web3.js/experimental.svg?style=flat
11
+ [npm-url]: https://www.npmjs.com/package/@solana/web3.js/v/experimental
12
12
  [semantic-release-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
13
13
  [semantic-release-url]: https://github.com/semantic-release/semantic-release
14
14
 
15
- # Solana JavaScript SDK
15
+ # Experimental Solana JavaScript SDK
16
16
 
17
- Use this to interact with accounts and programs on the Solana network through the Solana [JSON RPC API](https://docs.solana.com/apps/jsonrpc-api).
17
+ Use this to interact with accounts and programs on the Solana network through the Solana [JSON-RPC API](https://docs.solana.com/apps/jsonrpc-api).
18
+
19
+ **This library is experimental**. It is unsuitable for production use, because the API is unstable and may change without warning. If you want to build a production Solana application, use the [1.x branch](https://www.npmjs.com/package/@solana/web3.js).
18
20
 
19
21
  ## Installation
20
22
 
21
- ### For use in Node.js or a web application
23
+ ### For use in Node.js, React Native, or a web application
22
24
 
23
- ```
24
- $ npm install --save @solana/web3.js
25
+ ```shell
26
+ npm install --save @solana/web3.js@experimental
25
27
  ```
26
28
 
27
29
  ### For use in a browser, without a build system
28
30
 
29
31
  ```html
30
- <!-- Development (un-minified) -->
31
- <script src="https://unpkg.com/@solana/web3.js@latest/lib/index.iife.js"></script>
32
+ <!-- Development (debug mode, unminified) -->
33
+ <script src="https://unpkg.com/@solana/web3.js@experimental/dist/index.development.js"></script>
32
34
 
33
35
  <!-- Production (minified) -->
34
- <script src="https://unpkg.com/@solana/web3.js@latest/lib/index.iife.min.js"></script>
36
+ <script src="https://unpkg.com/@solana/web3.js@experimental/dist/index.production.min.js"></script>
35
37
  ```
36
38
 
37
- ## Documentation and examples
38
-
39
- - [The Solana Cookbook](https://solanacookbook.com/) has extensive task-based documentation using this library.
40
- - For more detail on individual functions, see the [latest API Documentation](https://solana-labs.github.io/solana-web3.js)
39
+ ## Usage
41
40
 
42
- ## Getting help
41
+ There are 3 main applications of this library.
43
42
 
44
- Have a question or a problem? Check the [Solana Stack Exchange](https://solana.stackexchange.com) to see if anyone else is having the same one. If not, [post a new question](https://solana.stackexchange.com/questions/ask).
43
+ 1. **RPC**. Solana apps interact with the network by calling methods on the Solana JSON-RPC.
44
+ 2. **Transactions**. Solana apps interact with Solana program by building and sending transactions.
45
+ 3. **Keys**. People use cryptographic keys to verify the provenance of messages and to attest to the ownership of their accounts.
45
46
 
46
- Include:
47
+ ### RPC
47
48
 
48
- - A detailed description of what you're trying to achieve
49
- - Source code, if possible
50
- - The text of any errors you encountered, with stacktraces if available
49
+ First, configure your connection to an RPC server. This might be a server that you host, one that you lease, or one of the limited-use [public RPC servers](https://docs.solana.com/cluster/rpc-endpoints).
51
50
 
52
- ## Compatibility
53
-
54
- This library requires a JavaScript runtime that supports [`BigInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) and the [exponentiation operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Exponentiation). Both are supported in the following runtimes:
51
+ ```ts
52
+ import { createDefaultRpcTransport } from '@solana/web3.js';
53
+ const devnetTransport = createDefaultRpcTransport({ url: 'https://api.devnet.solana.com' });
54
+ ```
55
55
 
56
- - Browsers, by [release date](https://caniuse.com/bigint):
57
- - Chrome: May 2018
58
- - Firefox: July 2019
59
- - Safari: September 2020
60
- - Mobile Safari: September 2020
61
- - Edge: January 2020
62
- - Opera: June 2018
63
- - Samsung Internet: April 2019
64
- - Runtimes, [by version](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt):
65
- - Deno: >=1.0
66
- - Node: >=10.4.0
67
- - React Native:
68
- - \>=0.7.0 using the [Hermes](https://reactnative.dev/blog/2022/07/08/hermes-as-the-default) engine ([integration guide](https://solanacookbook.com/integrations/react-native.html#how-to-use-solana-web3-js-in-a-react-native-app)):
56
+ Second, construct an RPC instance that uses that transport.
69
57
 
70
- ## Development environment setup
58
+ ```ts
59
+ const devnetRpc = createSolanaRpc({ transport: devnetTransport });
60
+ ```
71
61
 
72
- ### Testing
62
+ Now, you can use it to call methods on your RPC server. For instance, here is how you would fetch an account's balance.
73
63
 
74
- #### Unit tests
64
+ ```ts
65
+ const balanceInLamports = await devnetRpc.getBalance('11111111111111111111111111111111' as Base58EncodedAddress);
66
+ console.log('Balance of account 11111111111111111111111111111111 in Lamports', balanceInLamports);
67
+ ```
75
68
 
76
- To run the full suite of unit tests, excute the following in the root:
69
+ ### Transactions
77
70
 
78
- ```shell
79
- $ npm test
80
- ```
71
+ Unimplemented.
81
72
 
82
- #### Integration tests
73
+ ### Keys
83
74
 
84
- Integration tests require a validator client running on your machine.
75
+ #### Addresses and public keys
85
76
 
86
- To install a test validator:
77
+ Client applications primarily deal with addresses and public keys in the form of base58-encoded strings. Addresses and public keys returned from the RPC API conform to the type `Base58EncodedAddress`. You can use a value of that type wherever a base58-encoded address or key is expected.
87
78
 
88
- ```shell
89
- $ npm run test:live-with-test-validator:setup
90
- ```
79
+ From time to time you might acquire a string, that you expect to validate as an address, from an untrusted network API or user input. To assert that such an arbitrary string is a base58-encoded address, use the `assertIsBase58EncodedAddress` function.
91
80
 
92
- To start the test validator and run all of the integration tests in live mode:
81
+ ```ts
82
+ import { assertIsBase58EncodedAddress } from '@solana/web3.js`;
93
83
 
94
- ```shell
95
- $ cd packages/library-legacy
96
- $ npm run test:live-with-test-validator
84
+ // Imagine a function that fetches an account's balance when a user submits a form.
85
+ function handleSubmit() {
86
+ // We know only that what the user typed conforms to the `string` type.
87
+ const address: string = accountAddressInput.value;
88
+ try {
89
+ // If this type assertion function doesn't throw, then
90
+ // Typescript will upcast `address` to `Base58EncodedAddress`.
91
+ assertIsBase58EncodedAddress(address);
92
+ // At this point, `address` is a `Base58EncodedAddress` that can be used with the RPC.
93
+ const balanceInLamports = await rpc.getBalance(address);
94
+ } catch (e) {
95
+ // `address` turned out not to be a base58-encoded address
96
+ }
97
+ }
97
98
  ```
98
-
99
- ### Speed up build times with remote caching
100
-
101
- Cache build artifacts remotely so that you, others, and the CI server can take advantage of each others' build efforts.
102
-
103
- 1. Log the Turborepo CLI into the Solana Vercel account
104
- ```shell
105
- pnpm turbo login
106
- ```
107
- 2. Link the repository to the remote cache
108
- ```shell
109
- pnpm turbo link
110
- ```
111
-
112
- ## Contributing
113
-
114
- If you found a bug or would like to request a feature, please [file an issue](https://github.com/solana-labs/solana-web3.js/issues/new). If, based on the discussion on an issue you would like to offer a code change, please make a [pull request](https://github.com/solana-labs/solana-web3.js/compare). If neither of these describes what you would like to contribute, read the [getting help](#getting-help) section above.
115
-
116
- ## Disclaimer
117
-
118
- All claims, content, designs, algorithms, estimates, roadmaps,
119
- specifications, and performance measurements described in this project
120
- are done with the Solana Foundation's ("SF") best efforts. It is up to
121
- the reader to check and validate their accuracy and truthfulness.
122
- Furthermore nothing in this project constitutes a solicitation for
123
- investment.
124
-
125
- Any content produced by SF or developer resources that SF provides, are
126
- for educational and inspiration purposes only. SF does not encourage,
127
- induce or sanction the deployment, integration or use of any such
128
- applications (including the code comprising the Solana blockchain
129
- protocol) in violation of applicable laws or regulations and hereby
130
- prohibits any such deployment, integration or use. This includes use of
131
- any such applications by the reader (a) in violation of export control
132
- or sanctions laws of the United States or any other applicable
133
- jurisdiction, (b) if the reader is located in or ordinarily resident in
134
- a country or territory subject to comprehensive sanctions administered
135
- by the U.S. Office of Foreign Assets Control (OFAC), or (c) if the
136
- reader is or is working on behalf of a Specially Designated National
137
- (SDN) or a person subject to similar blocking or denied party
138
- prohibitions.
139
-
140
- The reader should be aware that U.S. export control and sanctions laws
141
- prohibit U.S. persons (and other persons that are subject to such laws)
142
- from transacting with persons in certain countries and territories or
143
- that are on the SDN list. As a project based primarily on open-source
144
- software, it is possible that such sanctioned persons may nevertheless
145
- bypass prohibitions, obtain the code comprising the Solana blockchain
146
- protocol (or other project code or applications) and deploy, integrate,
147
- or otherwise use it. Accordingly, there is a risk to individuals that
148
- other persons using the Solana blockchain protocol may be sanctioned
149
- persons and that transactions with such persons would be a violation of
150
- U.S. export controls and sanctions law. This risk applies to
151
- individuals, organizations, and other ecosystem participants that
152
- deploy, integrate, or use the Solana blockchain protocol code directly
153
- (e.g., as a node operator), and individuals that transact on the Solana
154
- blockchain through light clients, third party interfaces, and/or wallet
155
- software.
@@ -0,0 +1,77 @@
1
+ 'use strict';
2
+
3
+ var keys = require('@solana/keys');
4
+ var rpcCore = require('@solana/rpc-core');
5
+ var rpcTransport = require('@solana/rpc-transport');
6
+
7
+ // src/index.ts
8
+
9
+ // src/rpc-integer-overflow-error.ts
10
+ var SolanaJsonRpcIntegerOverflowError = class extends Error {
11
+ constructor(methodName, keyPath, value) {
12
+ const argPosition = (typeof keyPath[0] === "number" ? keyPath[0] : parseInt(keyPath[0], 10)) + 1;
13
+ let ordinal = "";
14
+ const lastDigit = argPosition % 10;
15
+ const lastTwoDigits = argPosition % 100;
16
+ if (lastDigit == 1 && lastTwoDigits != 11) {
17
+ ordinal = argPosition + "st";
18
+ } else if (lastDigit == 2 && lastTwoDigits != 12) {
19
+ ordinal = argPosition + "nd";
20
+ } else if (lastDigit == 3 && lastTwoDigits != 13) {
21
+ ordinal = argPosition + "rd";
22
+ } else {
23
+ ordinal = argPosition + "th";
24
+ }
25
+ const path = keyPath.length > 1 ? keyPath.slice(1).map((pathPart) => typeof pathPart === "number" ? `[${pathPart}]` : pathPart).join(".") : null;
26
+ super(
27
+ `The ${ordinal} argument to the \`${methodName}\` RPC method${path ? ` at path \`${path}\`` : ""} was \`${value}\`. This number is unsafe for use with the Solana JSON-RPC because it exceeds \`Number.MAX_SAFE_INTEGER\`.`
28
+ );
29
+ this.keyPath = keyPath;
30
+ this.methodName = methodName;
31
+ this.value = value;
32
+ }
33
+ get name() {
34
+ return "SolanaJsonRpcIntegerOverflowError";
35
+ }
36
+ };
37
+
38
+ // src/rpc-default-config.ts
39
+ var DEFAULT_RPC_CONFIG = {
40
+ onIntegerOverflow(methodName, keyPath, value) {
41
+ throw new SolanaJsonRpcIntegerOverflowError(methodName, keyPath, value);
42
+ }
43
+ };
44
+ function createSolanaRpc(config) {
45
+ return rpcTransport.createJsonRpc({
46
+ ...config,
47
+ api: rpcCore.createSolanaRpcApi(DEFAULT_RPC_CONFIG)
48
+ });
49
+ }
50
+ function normalizeHeaders(headers) {
51
+ const out = {};
52
+ for (const headerName in headers) {
53
+ out[headerName.toLowerCase()] = headers[headerName];
54
+ }
55
+ return out;
56
+ }
57
+ function createDefaultRpcTransport(config) {
58
+ return rpcTransport.createHttpTransport({
59
+ ...config,
60
+ headers: {
61
+ ...config.headers ? normalizeHeaders(config.headers) : void 0,
62
+ ...{
63
+ // Keep these headers lowercase so they will override any user-supplied headers above.
64
+ "solana-client": `js/${"2.0.0-development"}` ?? "UNKNOWN"
65
+ }
66
+ }
67
+ });
68
+ }
69
+
70
+ exports.createDefaultRpcTransport = createDefaultRpcTransport;
71
+ exports.createSolanaRpc = createSolanaRpc;
72
+ Object.keys(keys).forEach(function (k) {
73
+ if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
74
+ enumerable: true,
75
+ get: function () { return keys[k]; }
76
+ });
77
+ });
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/rpc.ts","../src/rpc-integer-overflow-error.ts","../src/rpc-default-config.ts","../src/rpc-transport.ts"],"names":[],"mappings":";AAAA,cAAc;;;ACAd,SAA2B,0BAA0B;;;ACA9C,IAAM,oCAAN,cAAgD,MAAM;AAAA,EAIzD,YAAY,YAAoB,SAA8B,OAAe;AACzE,UAAM,eAAe,OAAO,QAAQ,CAAC,MAAM,WAAW,QAAQ,CAAC,IAAI,SAAS,QAAQ,CAAC,GAAG,EAAE,KAAK;AAC/F,QAAI,UAAU;AACd,UAAM,YAAY,cAAc;AAChC,UAAM,gBAAgB,cAAc;AACpC,QAAI,aAAa,KAAK,iBAAiB,IAAI;AACvC,gBAAU,cAAc;AAAA,IAC5B,WAAW,aAAa,KAAK,iBAAiB,IAAI;AAC9C,gBAAU,cAAc;AAAA,IAC5B,WAAW,aAAa,KAAK,iBAAiB,IAAI;AAC9C,gBAAU,cAAc;AAAA,IAC5B,OAAO;AACH,gBAAU,cAAc;AAAA,IAC5B;AACA,UAAM,OACF,QAAQ,SAAS,IACX,QACK,MAAM,CAAC,EACP,IAAI,cAAa,OAAO,aAAa,WAAW,IAAI,cAAc,QAAS,EAC3E,KAAK,GAAG,IACb;AACV;AAAA,MACI,OAAO,6BAA6B,0BAC7B,OAAO,cAAc,WAAW,YAAY;AAAA,IAGvD;AACA,SAAK,UAAU;AACf,SAAK,aAAa;AAClB,SAAK,QAAQ;AAAA,EACjB;AAAA,EACA,IAAI,OAAO;AACP,WAAO;AAAA,EACX;AACJ;;;ACnCO,IAAM,qBAAwE;AAAA,EACjF,kBAAkB,YAAY,SAAS,OAAO;AAC1C,UAAM,IAAI,kCAAkC,YAAY,SAAS,KAAK;AAAA,EAC1E;AACJ;;;AFJA,SAAS,qBAAqB;AAGvB,SAAS,gBAAgB,QAAiF;AAC7G,SAAO,cAAgC;AAAA,IACnC,GAAG;AAAA,IACH,KAAK,mBAAmB,kBAAkB;AAAA,EAC9C,CAAC;AACL;;;AGXA,SAAS,2BAA2B;AAMpC,SAAS,iBACL,SACiD;AACjD,QAAM,MAA8B,CAAC;AACrC,aAAW,cAAc,SAAS;AAC9B,QAAI,WAAW,YAAY,CAAC,IAAI,QAAQ,UAAU;AAAA,EACtD;AACA,SAAO;AACX;AAEO,SAAS,0BAA0B,QAAkE;AACxG,SAAO,oBAAoB;AAAA,IACvB,GAAG;AAAA,IACH,SAAS;AAAA,MACL,GAAI,OAAO,UAAU,iBAAiB,OAAO,OAAO,IAAI;AAAA,MACxD,GAAI;AAAA;AAAA,QAEA,iBAAiB,MAAM,yBAAiB;AAAA,MAC5C;AAAA,IACJ;AAAA,EACJ,CAAC;AACL","sourcesContent":["export * from '@solana/keys';\nexport * from './rpc';\nexport * from './rpc-transport';\n","import { SolanaRpcMethods, createSolanaRpcApi } from '@solana/rpc-core';\nimport { DEFAULT_RPC_CONFIG } from './rpc-default-config';\n\nimport { createJsonRpc } from '@solana/rpc-transport';\nimport type { Rpc } from '@solana/rpc-transport/dist/types/json-rpc-types';\n\nexport function createSolanaRpc(config: Omit<Parameters<typeof createJsonRpc>[0], 'api'>): Rpc<SolanaRpcMethods> {\n return createJsonRpc<SolanaRpcMethods>({\n ...config,\n api: createSolanaRpcApi(DEFAULT_RPC_CONFIG),\n });\n}\n","export class SolanaJsonRpcIntegerOverflowError extends Error {\n readonly methodName: string;\n readonly keyPath: (number | string)[];\n readonly value: bigint;\n constructor(methodName: string, keyPath: (number | string)[], value: bigint) {\n const argPosition = (typeof keyPath[0] === 'number' ? keyPath[0] : parseInt(keyPath[0], 10)) + 1;\n let ordinal = '';\n const lastDigit = argPosition % 10;\n const lastTwoDigits = argPosition % 100;\n if (lastDigit == 1 && lastTwoDigits != 11) {\n ordinal = argPosition + 'st';\n } else if (lastDigit == 2 && lastTwoDigits != 12) {\n ordinal = argPosition + 'nd';\n } else if (lastDigit == 3 && lastTwoDigits != 13) {\n ordinal = argPosition + 'rd';\n } else {\n ordinal = argPosition + 'th';\n }\n const path =\n keyPath.length > 1\n ? keyPath\n .slice(1)\n .map(pathPart => (typeof pathPart === 'number' ? `[${pathPart}]` : pathPart))\n .join('.')\n : null;\n super(\n `The ${ordinal} argument to the \\`${methodName}\\` RPC method` +\n `${path ? ` at path \\`${path}\\`` : ''} was \\`${value}\\`. This number is ` +\n 'unsafe for use with the Solana JSON-RPC because it exceeds ' +\n '`Number.MAX_SAFE_INTEGER`.'\n );\n this.keyPath = keyPath;\n this.methodName = methodName;\n this.value = value;\n }\n get name() {\n return 'SolanaJsonRpcIntegerOverflowError';\n }\n}\n","import { createSolanaRpcApi } from '@solana/rpc-core';\nimport { SolanaJsonRpcIntegerOverflowError } from './rpc-integer-overflow-error';\n\nexport const DEFAULT_RPC_CONFIG: Partial<Parameters<typeof createSolanaRpcApi>[0]> = {\n onIntegerOverflow(methodName, keyPath, value) {\n throw new SolanaJsonRpcIntegerOverflowError(methodName, keyPath, value);\n },\n};\n","import { createHttpTransport } from '@solana/rpc-transport';\nimport { IRpcTransport } from '@solana/rpc-transport/dist/types/transports/transport-types';\n\n/**\n * Lowercasing header names makes it easier to override user-supplied headers.\n */\nfunction normalizeHeaders<T extends Record<string, string>>(\n headers: T\n): { [K in keyof T & string as Lowercase<K>]: T[K] } {\n const out: Record<string, string> = {};\n for (const headerName in headers) {\n out[headerName.toLowerCase()] = headers[headerName];\n }\n return out as { [K in keyof T & string as Lowercase<K>]: T[K] };\n}\n\nexport function createDefaultRpcTransport(config: Parameters<typeof createHttpTransport>[0]): IRpcTransport {\n return createHttpTransport({\n ...config,\n headers: {\n ...(config.headers ? normalizeHeaders(config.headers) : undefined),\n ...({\n // Keep these headers lowercase so they will override any user-supplied headers above.\n 'solana-client': `js/${__VERSION__}` ?? 'UNKNOWN',\n } as { [overrideHeader: string]: string }),\n },\n });\n}\n"]}
@@ -0,0 +1,68 @@
1
+ export * from '@solana/keys';
2
+ import { createSolanaRpcApi } from '@solana/rpc-core';
3
+ import { createJsonRpc, createHttpTransport } from '@solana/rpc-transport';
4
+
5
+ // src/index.ts
6
+
7
+ // src/rpc-integer-overflow-error.ts
8
+ var SolanaJsonRpcIntegerOverflowError = class extends Error {
9
+ constructor(methodName, keyPath, value) {
10
+ const argPosition = (typeof keyPath[0] === "number" ? keyPath[0] : parseInt(keyPath[0], 10)) + 1;
11
+ let ordinal = "";
12
+ const lastDigit = argPosition % 10;
13
+ const lastTwoDigits = argPosition % 100;
14
+ if (lastDigit == 1 && lastTwoDigits != 11) {
15
+ ordinal = argPosition + "st";
16
+ } else if (lastDigit == 2 && lastTwoDigits != 12) {
17
+ ordinal = argPosition + "nd";
18
+ } else if (lastDigit == 3 && lastTwoDigits != 13) {
19
+ ordinal = argPosition + "rd";
20
+ } else {
21
+ ordinal = argPosition + "th";
22
+ }
23
+ const path = keyPath.length > 1 ? keyPath.slice(1).map((pathPart) => typeof pathPart === "number" ? `[${pathPart}]` : pathPart).join(".") : null;
24
+ super(
25
+ `The ${ordinal} argument to the \`${methodName}\` RPC method${path ? ` at path \`${path}\`` : ""} was \`${value}\`. This number is unsafe for use with the Solana JSON-RPC because it exceeds \`Number.MAX_SAFE_INTEGER\`.`
26
+ );
27
+ this.keyPath = keyPath;
28
+ this.methodName = methodName;
29
+ this.value = value;
30
+ }
31
+ get name() {
32
+ return "SolanaJsonRpcIntegerOverflowError";
33
+ }
34
+ };
35
+
36
+ // src/rpc-default-config.ts
37
+ var DEFAULT_RPC_CONFIG = {
38
+ onIntegerOverflow(methodName, keyPath, value) {
39
+ throw new SolanaJsonRpcIntegerOverflowError(methodName, keyPath, value);
40
+ }
41
+ };
42
+ function createSolanaRpc(config) {
43
+ return createJsonRpc({
44
+ ...config,
45
+ api: createSolanaRpcApi(DEFAULT_RPC_CONFIG)
46
+ });
47
+ }
48
+ function normalizeHeaders(headers) {
49
+ const out = {};
50
+ for (const headerName in headers) {
51
+ out[headerName.toLowerCase()] = headers[headerName];
52
+ }
53
+ return out;
54
+ }
55
+ function createDefaultRpcTransport(config) {
56
+ return createHttpTransport({
57
+ ...config,
58
+ headers: {
59
+ ...config.headers ? normalizeHeaders(config.headers) : void 0,
60
+ ...{
61
+ // Keep these headers lowercase so they will override any user-supplied headers above.
62
+ "solana-client": `js/${"2.0.0-development"}` ?? "UNKNOWN"
63
+ }
64
+ }
65
+ });
66
+ }
67
+
68
+ export { createDefaultRpcTransport, createSolanaRpc };
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/rpc.ts","../src/rpc-integer-overflow-error.ts","../src/rpc-default-config.ts","../src/rpc-transport.ts"],"names":[],"mappings":";AAAA,cAAc;;;ACAd,SAA2B,0BAA0B;;;ACA9C,IAAM,oCAAN,cAAgD,MAAM;AAAA,EAIzD,YAAY,YAAoB,SAA8B,OAAe;AACzE,UAAM,eAAe,OAAO,QAAQ,CAAC,MAAM,WAAW,QAAQ,CAAC,IAAI,SAAS,QAAQ,CAAC,GAAG,EAAE,KAAK;AAC/F,QAAI,UAAU;AACd,UAAM,YAAY,cAAc;AAChC,UAAM,gBAAgB,cAAc;AACpC,QAAI,aAAa,KAAK,iBAAiB,IAAI;AACvC,gBAAU,cAAc;AAAA,IAC5B,WAAW,aAAa,KAAK,iBAAiB,IAAI;AAC9C,gBAAU,cAAc;AAAA,IAC5B,WAAW,aAAa,KAAK,iBAAiB,IAAI;AAC9C,gBAAU,cAAc;AAAA,IAC5B,OAAO;AACH,gBAAU,cAAc;AAAA,IAC5B;AACA,UAAM,OACF,QAAQ,SAAS,IACX,QACK,MAAM,CAAC,EACP,IAAI,cAAa,OAAO,aAAa,WAAW,IAAI,cAAc,QAAS,EAC3E,KAAK,GAAG,IACb;AACV;AAAA,MACI,OAAO,6BAA6B,0BAC7B,OAAO,cAAc,WAAW,YAAY;AAAA,IAGvD;AACA,SAAK,UAAU;AACf,SAAK,aAAa;AAClB,SAAK,QAAQ;AAAA,EACjB;AAAA,EACA,IAAI,OAAO;AACP,WAAO;AAAA,EACX;AACJ;;;ACnCO,IAAM,qBAAwE;AAAA,EACjF,kBAAkB,YAAY,SAAS,OAAO;AAC1C,UAAM,IAAI,kCAAkC,YAAY,SAAS,KAAK;AAAA,EAC1E;AACJ;;;AFJA,SAAS,qBAAqB;AAGvB,SAAS,gBAAgB,QAAiF;AAC7G,SAAO,cAAgC;AAAA,IACnC,GAAG;AAAA,IACH,KAAK,mBAAmB,kBAAkB;AAAA,EAC9C,CAAC;AACL;;;AGXA,SAAS,2BAA2B;AAMpC,SAAS,iBACL,SACiD;AACjD,QAAM,MAA8B,CAAC;AACrC,aAAW,cAAc,SAAS;AAC9B,QAAI,WAAW,YAAY,CAAC,IAAI,QAAQ,UAAU;AAAA,EACtD;AACA,SAAO;AACX;AAEO,SAAS,0BAA0B,QAAkE;AACxG,SAAO,oBAAoB;AAAA,IACvB,GAAG;AAAA,IACH,SAAS;AAAA,MACL,GAAI,OAAO,UAAU,iBAAiB,OAAO,OAAO,IAAI;AAAA,MACxD,GAAI;AAAA;AAAA,QAEA,iBAAiB,MAAM,yBAAiB;AAAA,MAC5C;AAAA,IACJ;AAAA,EACJ,CAAC;AACL","sourcesContent":["export * from '@solana/keys';\nexport * from './rpc';\nexport * from './rpc-transport';\n","import { SolanaRpcMethods, createSolanaRpcApi } from '@solana/rpc-core';\nimport { DEFAULT_RPC_CONFIG } from './rpc-default-config';\n\nimport { createJsonRpc } from '@solana/rpc-transport';\nimport type { Rpc } from '@solana/rpc-transport/dist/types/json-rpc-types';\n\nexport function createSolanaRpc(config: Omit<Parameters<typeof createJsonRpc>[0], 'api'>): Rpc<SolanaRpcMethods> {\n return createJsonRpc<SolanaRpcMethods>({\n ...config,\n api: createSolanaRpcApi(DEFAULT_RPC_CONFIG),\n });\n}\n","export class SolanaJsonRpcIntegerOverflowError extends Error {\n readonly methodName: string;\n readonly keyPath: (number | string)[];\n readonly value: bigint;\n constructor(methodName: string, keyPath: (number | string)[], value: bigint) {\n const argPosition = (typeof keyPath[0] === 'number' ? keyPath[0] : parseInt(keyPath[0], 10)) + 1;\n let ordinal = '';\n const lastDigit = argPosition % 10;\n const lastTwoDigits = argPosition % 100;\n if (lastDigit == 1 && lastTwoDigits != 11) {\n ordinal = argPosition + 'st';\n } else if (lastDigit == 2 && lastTwoDigits != 12) {\n ordinal = argPosition + 'nd';\n } else if (lastDigit == 3 && lastTwoDigits != 13) {\n ordinal = argPosition + 'rd';\n } else {\n ordinal = argPosition + 'th';\n }\n const path =\n keyPath.length > 1\n ? keyPath\n .slice(1)\n .map(pathPart => (typeof pathPart === 'number' ? `[${pathPart}]` : pathPart))\n .join('.')\n : null;\n super(\n `The ${ordinal} argument to the \\`${methodName}\\` RPC method` +\n `${path ? ` at path \\`${path}\\`` : ''} was \\`${value}\\`. This number is ` +\n 'unsafe for use with the Solana JSON-RPC because it exceeds ' +\n '`Number.MAX_SAFE_INTEGER`.'\n );\n this.keyPath = keyPath;\n this.methodName = methodName;\n this.value = value;\n }\n get name() {\n return 'SolanaJsonRpcIntegerOverflowError';\n }\n}\n","import { createSolanaRpcApi } from '@solana/rpc-core';\nimport { SolanaJsonRpcIntegerOverflowError } from './rpc-integer-overflow-error';\n\nexport const DEFAULT_RPC_CONFIG: Partial<Parameters<typeof createSolanaRpcApi>[0]> = {\n onIntegerOverflow(methodName, keyPath, value) {\n throw new SolanaJsonRpcIntegerOverflowError(methodName, keyPath, value);\n },\n};\n","import { createHttpTransport } from '@solana/rpc-transport';\nimport { IRpcTransport } from '@solana/rpc-transport/dist/types/transports/transport-types';\n\n/**\n * Lowercasing header names makes it easier to override user-supplied headers.\n */\nfunction normalizeHeaders<T extends Record<string, string>>(\n headers: T\n): { [K in keyof T & string as Lowercase<K>]: T[K] } {\n const out: Record<string, string> = {};\n for (const headerName in headers) {\n out[headerName.toLowerCase()] = headers[headerName];\n }\n return out as { [K in keyof T & string as Lowercase<K>]: T[K] };\n}\n\nexport function createDefaultRpcTransport(config: Parameters<typeof createHttpTransport>[0]): IRpcTransport {\n return createHttpTransport({\n ...config,\n headers: {\n ...(config.headers ? normalizeHeaders(config.headers) : undefined),\n ...({\n // Keep these headers lowercase so they will override any user-supplied headers above.\n 'solana-client': `js/${__VERSION__}` ?? 'UNKNOWN',\n } as { [overrideHeader: string]: string }),\n },\n });\n}\n"]}