@solana/rpc-types 2.0.0-experimental.be3a154 → 2.0.0-experimental.bea19d2
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/README.md +1 -1
- package/dist/index.browser.cjs +64 -0
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +60 -1
- package/dist/index.browser.js.map +1 -1
- package/dist/index.native.js +60 -1
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +64 -0
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +60 -1
- package/dist/index.node.js.map +1 -1
- package/dist/types/account-filters.d.ts +14 -0
- package/dist/types/account-filters.d.ts.map +1 -0
- package/dist/types/account-info.d.ts +43 -0
- package/dist/types/account-info.d.ts.map +1 -0
- package/dist/types/blockhash.d.ts +5 -0
- package/dist/types/blockhash.d.ts.map +1 -0
- package/dist/types/cluster-url.d.ts +14 -0
- package/dist/types/cluster-url.d.ts.map +1 -0
- package/dist/types/encoded-bytes.d.ts +13 -0
- package/dist/types/encoded-bytes.d.ts.map +1 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/rpc-api.d.ts +8 -0
- package/dist/types/rpc-api.d.ts.map +1 -0
- package/dist/types/rpc-errors.d.ts +21 -0
- package/dist/types/rpc-errors.d.ts.map +1 -0
- package/dist/types/token-amount.d.ts +9 -0
- package/dist/types/token-amount.d.ts.map +1 -0
- package/dist/types/token-balance.d.ts +14 -0
- package/dist/types/token-balance.d.ts.map +1 -0
- package/dist/types/transaction-error.d.ts +23 -0
- package/dist/types/transaction-error.d.ts.map +1 -0
- package/dist/types/transaction.d.ts +251 -0
- package/dist/types/transaction.d.ts.map +1 -0
- package/dist/types/typed-numbers.d.ts +14 -0
- package/dist/types/typed-numbers.d.ts.map +1 -0
- package/package.json +12 -31
package/README.md
CHANGED
|
@@ -46,7 +46,7 @@ This type represents a number in the range $[-8.64 \times 10^{15}, 8.64 \times 1
|
|
|
46
46
|
|
|
47
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
48
|
|
|
49
|
-
From time to time you might acquire
|
|
49
|
+
From time to time you might acquire a number that you expect to be a quantity of Lamports, from an untrusted network API or user input. To assert that such an arbitrary number is usable as a quantity of Lamports, use the `assertIsLamports` function.
|
|
50
50
|
|
|
51
51
|
```ts
|
|
52
52
|
import { assertIsLamports } from '@solana/rpc-types';
|
package/dist/index.browser.cjs
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var codecsStrings = require('@solana/codecs-strings');
|
|
4
|
+
|
|
5
|
+
// src/blockhash.ts
|
|
6
|
+
var base58Encoder;
|
|
7
|
+
function assertIsBlockhash(putativeBlockhash) {
|
|
8
|
+
if (!base58Encoder)
|
|
9
|
+
base58Encoder = codecsStrings.getBase58Encoder();
|
|
10
|
+
try {
|
|
11
|
+
if (
|
|
12
|
+
// Lowest value (32 bytes of zeroes)
|
|
13
|
+
putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
|
|
14
|
+
putativeBlockhash.length > 44
|
|
15
|
+
) {
|
|
16
|
+
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
17
|
+
}
|
|
18
|
+
const bytes = base58Encoder.encode(putativeBlockhash);
|
|
19
|
+
const numBytes = bytes.byteLength;
|
|
20
|
+
if (numBytes !== 32) {
|
|
21
|
+
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
22
|
+
}
|
|
23
|
+
} catch (e) {
|
|
24
|
+
throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
|
|
25
|
+
cause: e
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// src/cluster-url.ts
|
|
31
|
+
function mainnet(putativeString) {
|
|
32
|
+
return putativeString;
|
|
33
|
+
}
|
|
34
|
+
function devnet(putativeString) {
|
|
35
|
+
return putativeString;
|
|
36
|
+
}
|
|
37
|
+
function testnet(putativeString) {
|
|
38
|
+
return putativeString;
|
|
39
|
+
}
|
|
40
|
+
|
|
3
41
|
// src/commitment.ts
|
|
4
42
|
function getCommitmentScore(commitment) {
|
|
5
43
|
switch (commitment) {
|
|
@@ -40,6 +78,27 @@ function lamports(putativeLamports) {
|
|
|
40
78
|
return putativeLamports;
|
|
41
79
|
}
|
|
42
80
|
|
|
81
|
+
// src/rpc-errors.ts
|
|
82
|
+
var SolanaRpcErrorCode = {
|
|
83
|
+
JSON_RPC_INVALID_PARAMS: -32602,
|
|
84
|
+
JSON_RPC_SCAN_ERROR: -32012,
|
|
85
|
+
JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,
|
|
86
|
+
JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,
|
|
87
|
+
JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,
|
|
88
|
+
JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,
|
|
89
|
+
JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,
|
|
90
|
+
JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016,
|
|
91
|
+
JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,
|
|
92
|
+
JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,
|
|
93
|
+
JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,
|
|
94
|
+
JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,
|
|
95
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,
|
|
96
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,
|
|
97
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,
|
|
98
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,
|
|
99
|
+
JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015
|
|
100
|
+
};
|
|
101
|
+
|
|
43
102
|
// src/stringified-bigint.ts
|
|
44
103
|
function isStringifiedBigInt(putativeBigInt) {
|
|
45
104
|
try {
|
|
@@ -100,18 +159,23 @@ function unixTimestamp(putativeTimestamp) {
|
|
|
100
159
|
return putativeTimestamp;
|
|
101
160
|
}
|
|
102
161
|
|
|
162
|
+
exports.SolanaRpcErrorCode = SolanaRpcErrorCode;
|
|
163
|
+
exports.assertIsBlockhash = assertIsBlockhash;
|
|
103
164
|
exports.assertIsLamports = assertIsLamports;
|
|
104
165
|
exports.assertIsStringifiedBigInt = assertIsStringifiedBigInt;
|
|
105
166
|
exports.assertIsStringifiedNumber = assertIsStringifiedNumber;
|
|
106
167
|
exports.assertIsUnixTimestamp = assertIsUnixTimestamp;
|
|
107
168
|
exports.commitmentComparator = commitmentComparator;
|
|
169
|
+
exports.devnet = devnet;
|
|
108
170
|
exports.isLamports = isLamports;
|
|
109
171
|
exports.isStringifiedBigInt = isStringifiedBigInt;
|
|
110
172
|
exports.isStringifiedNumber = isStringifiedNumber;
|
|
111
173
|
exports.isUnixTimestamp = isUnixTimestamp;
|
|
112
174
|
exports.lamports = lamports;
|
|
175
|
+
exports.mainnet = mainnet;
|
|
113
176
|
exports.stringifiedBigInt = stringifiedBigInt;
|
|
114
177
|
exports.stringifiedNumber = stringifiedNumber;
|
|
178
|
+
exports.testnet = testnet;
|
|
115
179
|
exports.unixTimestamp = unixTimestamp;
|
|
116
180
|
//# sourceMappingURL=out.js.map
|
|
117
181
|
//# sourceMappingURL=index.browser.cjs.map
|
|
@@ -1 +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"]}
|
|
1
|
+
{"version":3,"sources":["../src/blockhash.ts","../src/cluster-url.ts","../src/commitment.ts","../src/lamports.ts","../src/rpc-errors.ts","../src/stringified-bigint.ts","../src/stringified-number.ts","../src/unix-timestamp.ts"],"names":[],"mappings":";AACA,SAAS,wBAAwB;AAIjC,IAAI;AAEG,SAAS,kBAAkB,mBAAmE;AACjG,MAAI,CAAC;AAAe,oBAAgB,iBAAiB;AACrD,MAAI;AAEA;AAAA;AAAA,MAEI,kBAAkB,SAAS;AAAA,MAE3B,kBAAkB,SAAS;AAAA,MAC7B;AACE,YAAM,IAAI,MAAM,+DAA+D;AAAA,IACnF;AAEA,UAAM,QAAQ,cAAc,OAAO,iBAAiB;AACpD,UAAM,WAAW,MAAM;AACvB,QAAI,aAAa,IAAI;AACjB,YAAM,IAAI,MAAM,gFAAgF,QAAQ,EAAE;AAAA,IAC9G;AAAA,EACJ,SAAS,GAAG;AACR,UAAM,IAAI,MAAM,KAAK,iBAAiB,yBAAyB;AAAA,MAC3D,OAAO;AAAA,IACX,CAAC;AAAA,E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E;AAAA,EAClE,uDAAuD;AAC3D;;;AClBO,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":["import type { Encoder } from '@solana/codecs-core';\nimport { getBase58Encoder } from '@solana/codecs-strings';\n\nexport type Blockhash = string & { readonly __brand: unique symbol };\n\nlet base58Encoder: Encoder<string> | undefined;\n\nexport function assertIsBlockhash(putativeBlockhash: string): asserts putativeBlockhash is Blockhash {\n if (!base58Encoder) base58Encoder = getBase58Encoder();\n try {\n // Fast-path; see if the input string is of an acceptable length.\n if (\n // Lowest value (32 bytes of zeroes)\n putativeBlockhash.length < 32 ||\n // Highest value (32 bytes of 255)\n putativeBlockhash.length > 44\n ) {\n throw new Error('Expected input string to decode to a byte array of length 32.');\n }\n // Slow-path; actually attempt to decode the input string.\n const bytes = base58Encoder.encode(putativeBlockhash);\n const numBytes = bytes.byteLength;\n if (numBytes !== 32) {\n throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);\n }\n } catch (e) {\n throw new Error(`\\`${putativeBlockhash}\\` is not a blockhash`, {\n cause: e,\n });\n }\n}\n","export type MainnetUrl = string & { '~cluster': 'mainnet' };\nexport type DevnetUrl = string & { '~cluster': 'devnet' };\nexport type TestnetUrl = string & { '~cluster': 'testnet' };\nexport type ClusterUrl = string | MainnetUrl | DevnetUrl | TestnetUrl;\n\nexport function mainnet(putativeString: string): MainnetUrl {\n return putativeString as MainnetUrl;\n}\nexport function devnet(putativeString: string): DevnetUrl {\n return putativeString as DevnetUrl;\n}\nexport function testnet(putativeString: string): TestnetUrl {\n return putativeString as TestnetUrl;\n}\n","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","// Keep in sync with https://github.com/solana-labs/solana/blob/master/rpc-client-api/src/custom_error.rs\n// Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/\nexport const SolanaRpcErrorCode = {\n JSON_RPC_INVALID_PARAMS: -32602,\n JSON_RPC_SCAN_ERROR: -32012,\n JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,\n JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,\n JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,\n JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,\n JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,\n JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016,\n JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,\n JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,\n JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,\n JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,\n JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,\n JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,\n JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,\n JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,\n JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015,\n} as const;\n\nexport type SolanaRpcErrorCodeEnum = (typeof SolanaRpcErrorCode)[keyof typeof SolanaRpcErrorCode];\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"]}
|
package/dist/index.browser.js
CHANGED
|
@@ -1,3 +1,41 @@
|
|
|
1
|
+
import { getBase58Encoder } from '@solana/codecs-strings';
|
|
2
|
+
|
|
3
|
+
// src/blockhash.ts
|
|
4
|
+
var base58Encoder;
|
|
5
|
+
function assertIsBlockhash(putativeBlockhash) {
|
|
6
|
+
if (!base58Encoder)
|
|
7
|
+
base58Encoder = getBase58Encoder();
|
|
8
|
+
try {
|
|
9
|
+
if (
|
|
10
|
+
// Lowest value (32 bytes of zeroes)
|
|
11
|
+
putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
|
|
12
|
+
putativeBlockhash.length > 44
|
|
13
|
+
) {
|
|
14
|
+
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
15
|
+
}
|
|
16
|
+
const bytes = base58Encoder.encode(putativeBlockhash);
|
|
17
|
+
const numBytes = bytes.byteLength;
|
|
18
|
+
if (numBytes !== 32) {
|
|
19
|
+
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
20
|
+
}
|
|
21
|
+
} catch (e) {
|
|
22
|
+
throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
|
|
23
|
+
cause: e
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// src/cluster-url.ts
|
|
29
|
+
function mainnet(putativeString) {
|
|
30
|
+
return putativeString;
|
|
31
|
+
}
|
|
32
|
+
function devnet(putativeString) {
|
|
33
|
+
return putativeString;
|
|
34
|
+
}
|
|
35
|
+
function testnet(putativeString) {
|
|
36
|
+
return putativeString;
|
|
37
|
+
}
|
|
38
|
+
|
|
1
39
|
// src/commitment.ts
|
|
2
40
|
function getCommitmentScore(commitment) {
|
|
3
41
|
switch (commitment) {
|
|
@@ -38,6 +76,27 @@ function lamports(putativeLamports) {
|
|
|
38
76
|
return putativeLamports;
|
|
39
77
|
}
|
|
40
78
|
|
|
79
|
+
// src/rpc-errors.ts
|
|
80
|
+
var SolanaRpcErrorCode = {
|
|
81
|
+
JSON_RPC_INVALID_PARAMS: -32602,
|
|
82
|
+
JSON_RPC_SCAN_ERROR: -32012,
|
|
83
|
+
JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,
|
|
84
|
+
JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,
|
|
85
|
+
JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,
|
|
86
|
+
JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,
|
|
87
|
+
JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,
|
|
88
|
+
JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016,
|
|
89
|
+
JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,
|
|
90
|
+
JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,
|
|
91
|
+
JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,
|
|
92
|
+
JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,
|
|
93
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,
|
|
94
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,
|
|
95
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,
|
|
96
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,
|
|
97
|
+
JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015
|
|
98
|
+
};
|
|
99
|
+
|
|
41
100
|
// src/stringified-bigint.ts
|
|
42
101
|
function isStringifiedBigInt(putativeBigInt) {
|
|
43
102
|
try {
|
|
@@ -98,6 +157,6 @@ function unixTimestamp(putativeTimestamp) {
|
|
|
98
157
|
return putativeTimestamp;
|
|
99
158
|
}
|
|
100
159
|
|
|
101
|
-
export { assertIsLamports, assertIsStringifiedBigInt, assertIsStringifiedNumber, assertIsUnixTimestamp, commitmentComparator, isLamports, isStringifiedBigInt, isStringifiedNumber, isUnixTimestamp, lamports, stringifiedBigInt, stringifiedNumber, unixTimestamp };
|
|
160
|
+
export { SolanaRpcErrorCode, assertIsBlockhash, assertIsLamports, assertIsStringifiedBigInt, assertIsStringifiedNumber, assertIsUnixTimestamp, commitmentComparator, devnet, isLamports, isStringifiedBigInt, isStringifiedNumber, isUnixTimestamp, lamports, mainnet, stringifiedBigInt, stringifiedNumber, testnet, unixTimestamp };
|
|
102
161
|
//# sourceMappingURL=out.js.map
|
|
103
162
|
//# sourceMappingURL=index.browser.js.map
|
|
@@ -1 +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,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AAc,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"]}
|
|
1
|
+
{"version":3,"sources":["../src/blockhash.ts","../src/cluster-url.ts","../src/commitment.ts","../src/lamports.ts","../src/rpc-errors.ts","../src/stringified-bigint.ts","../src/stringified-number.ts","../src/unix-timestamp.ts"],"names":[],"mappings":";AACA,SAAS,wBAAwB;AAIjC,IAAI;AAEG,SAAS,kBAAkB,mBAAmE;AACjG,MAAI,CAAC;AAAe,oBAAgB,iBAAiB;AACrD,MAAI;AAEA;AAAA;AAAA,MAEI,kBAAkB,SAAS;AAAA,MAE3B,kBAAkB,SAAS;AAAA,MAC7B;AACE,YAAM,IAAI,MAAM,+DAA+D;AAAA,IACnF;AAEA,UAAM,QAAQ,cAAc,OAAO,iBAAiB;AACpD,UAAM,WAAW,MAAM;AACvB,QAAI,aAAa,IAAI;AACjB,YAAM,IAAI,MAAM,gFAAgF,QAAQ,EAAE;AAAA,IAC9G;AAAA,EACJ,SAAS,GAAG;AACR,UAAM,IAAI,MAAM,KAAK,iBAAiB,yBAAyB;AAAA,MAC3D,OAAO;AAAA,IACX,CAAC;AAAA,EACL;AACJ;;;ACzBO,SAAS,QAAQ,gBAAoC;AACxD,SAAO;AACX;AACO,SAAS,OAAO,gBAAmC;AACtD,SAAO;AACX;AACO,SAAS,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ACX,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":["import type { Encoder } from '@solana/codecs-core';\nimport { getBase58Encoder } from '@solana/codecs-strings';\n\nexport type Blockhash = string & { readonly __brand: unique symbol };\n\nlet base58Encoder: Encoder<string> | undefined;\n\nexport function assertIsBlockhash(putativeBlockhash: string): asserts putativeBlockhash is Blockhash {\n if (!base58Encoder) base58Encoder = getBase58Encoder();\n try {\n // Fast-path; see if the input string is of an acceptable length.\n if (\n // Lowest value (32 bytes of zeroes)\n putativeBlockhash.length < 32 ||\n // Highest value (32 bytes of 255)\n putativeBlockhash.length > 44\n ) {\n throw new Error('Expected input string to decode to a byte array of length 32.');\n }\n // Slow-path; actually attempt to decode the input string.\n const bytes = base58Encoder.encode(putativeBlockhash);\n const numBytes = bytes.byteLength;\n if (numBytes !== 32) {\n throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);\n }\n } catch (e) {\n throw new Error(`\\`${putativeBlockhash}\\` is not a blockhash`, {\n cause: e,\n });\n }\n}\n","export type MainnetUrl = string & { '~cluster': 'mainnet' };\nexport type DevnetUrl = string & { '~cluster': 'devnet' };\nexport type TestnetUrl = string & { '~cluster': 'testnet' };\nexport type ClusterUrl = string | MainnetUrl | DevnetUrl | TestnetUrl;\n\nexport function mainnet(putativeString: string): MainnetUrl {\n return putativeString as MainnetUrl;\n}\nexport function devnet(putativeString: string): DevnetUrl {\n return putativeString as DevnetUrl;\n}\nexport function testnet(putativeString: string): TestnetUrl {\n return putativeString as TestnetUrl;\n}\n","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","// Keep in sync with https://github.com/solana-labs/solana/blob/master/rpc-client-api/src/custom_error.rs\n// Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/\nexport const SolanaRpcErrorCode = {\n JSON_RPC_INVALID_PARAMS: -32602,\n JSON_RPC_SCAN_ERROR: -32012,\n JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,\n JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,\n JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,\n JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,\n JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,\n JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016,\n JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,\n JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,\n JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,\n JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,\n JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,\n JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,\n JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,\n JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,\n JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015,\n} as const;\n\nexport type SolanaRpcErrorCodeEnum = (typeof SolanaRpcErrorCode)[keyof typeof SolanaRpcErrorCode];\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"]}
|
package/dist/index.native.js
CHANGED
|
@@ -1,3 +1,41 @@
|
|
|
1
|
+
import { getBase58Encoder } from '@solana/codecs-strings';
|
|
2
|
+
|
|
3
|
+
// src/blockhash.ts
|
|
4
|
+
var base58Encoder;
|
|
5
|
+
function assertIsBlockhash(putativeBlockhash) {
|
|
6
|
+
if (!base58Encoder)
|
|
7
|
+
base58Encoder = getBase58Encoder();
|
|
8
|
+
try {
|
|
9
|
+
if (
|
|
10
|
+
// Lowest value (32 bytes of zeroes)
|
|
11
|
+
putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
|
|
12
|
+
putativeBlockhash.length > 44
|
|
13
|
+
) {
|
|
14
|
+
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
15
|
+
}
|
|
16
|
+
const bytes = base58Encoder.encode(putativeBlockhash);
|
|
17
|
+
const numBytes = bytes.byteLength;
|
|
18
|
+
if (numBytes !== 32) {
|
|
19
|
+
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
20
|
+
}
|
|
21
|
+
} catch (e) {
|
|
22
|
+
throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
|
|
23
|
+
cause: e
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// src/cluster-url.ts
|
|
29
|
+
function mainnet(putativeString) {
|
|
30
|
+
return putativeString;
|
|
31
|
+
}
|
|
32
|
+
function devnet(putativeString) {
|
|
33
|
+
return putativeString;
|
|
34
|
+
}
|
|
35
|
+
function testnet(putativeString) {
|
|
36
|
+
return putativeString;
|
|
37
|
+
}
|
|
38
|
+
|
|
1
39
|
// src/commitment.ts
|
|
2
40
|
function getCommitmentScore(commitment) {
|
|
3
41
|
switch (commitment) {
|
|
@@ -38,6 +76,27 @@ function lamports(putativeLamports) {
|
|
|
38
76
|
return putativeLamports;
|
|
39
77
|
}
|
|
40
78
|
|
|
79
|
+
// src/rpc-errors.ts
|
|
80
|
+
var SolanaRpcErrorCode = {
|
|
81
|
+
JSON_RPC_INVALID_PARAMS: -32602,
|
|
82
|
+
JSON_RPC_SCAN_ERROR: -32012,
|
|
83
|
+
JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,
|
|
84
|
+
JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,
|
|
85
|
+
JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,
|
|
86
|
+
JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,
|
|
87
|
+
JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,
|
|
88
|
+
JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016,
|
|
89
|
+
JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,
|
|
90
|
+
JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,
|
|
91
|
+
JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,
|
|
92
|
+
JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,
|
|
93
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,
|
|
94
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,
|
|
95
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,
|
|
96
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,
|
|
97
|
+
JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015
|
|
98
|
+
};
|
|
99
|
+
|
|
41
100
|
// src/stringified-bigint.ts
|
|
42
101
|
function isStringifiedBigInt(putativeBigInt) {
|
|
43
102
|
try {
|
|
@@ -98,6 +157,6 @@ function unixTimestamp(putativeTimestamp) {
|
|
|
98
157
|
return putativeTimestamp;
|
|
99
158
|
}
|
|
100
159
|
|
|
101
|
-
export { assertIsLamports, assertIsStringifiedBigInt, assertIsStringifiedNumber, assertIsUnixTimestamp, commitmentComparator, isLamports, isStringifiedBigInt, isStringifiedNumber, isUnixTimestamp, lamports, stringifiedBigInt, stringifiedNumber, unixTimestamp };
|
|
160
|
+
export { SolanaRpcErrorCode, assertIsBlockhash, assertIsLamports, assertIsStringifiedBigInt, assertIsStringifiedNumber, assertIsUnixTimestamp, commitmentComparator, devnet, isLamports, isStringifiedBigInt, isStringifiedNumber, isUnixTimestamp, lamports, mainnet, stringifiedBigInt, stringifiedNumber, testnet, unixTimestamp };
|
|
102
161
|
//# sourceMappingURL=out.js.map
|
|
103
162
|
//# sourceMappingURL=index.native.js.map
|
package/dist/index.native.js.map
CHANGED
|
@@ -1 +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,I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,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"]}
|
|
1
|
+
{"version":3,"sources":["../src/blockhash.ts","../src/cluster-url.ts","../src/commitment.ts","../src/lamports.ts","../src/rpc-errors.ts","../src/stringified-bigint.ts","../src/stringified-number.ts","../src/unix-timestamp.ts"],"names":[],"mappings":";AACA,SAAS,wBAAwB;AAIjC,IAAI;AAEG,SAAS,kBAAkB,mBAAmE;AACjG,MAAI,CAAC;AAAe,oBAAgB,iBAAiB;AACrD,MAAI;AAEA;AAAA;AAAA,MAEI,kBAAkB,SAAS;AAAA,MAE3B,kBAAkB,SAAS;AAAA,MAC7B;AACE,YAAM,IAAI,MAAM,+DAA+D;AAAA,IACnF;AAEA,UAAM,QAAQ,cAAc,OAAO,iBAAiB;AACpD,UAAM,WAAW,MAAM;AACvB,QAAI,aAAa,IAAI;AACjB,YAAM,IAAI,MAAM,gFAAgF,QAAQ,EAAE;AAAA,IAC9G;AAAA,EACJ,SAAS,GAAG;AACR,UAAM,IAAI,MAAM,KAAK,iBAAiB,yBAAyB;AAAA,MAC3D,OAAO;AAAA,IACX,CAAC;AAAA,EACL;AACJ;;;ACzBO,SAAS,QAAQ,gBAAoC;AACxD,SAAO;AACX;AACO,SAAS,OAAO,gBAAmC;AACtD,SAAO;AACX;AACO,SAAS,QAAQ,gBAAoC;AACxD,SAAO;AACX;;;ACXA,SAAS,mBAAmB,YAAgC;AACxD,UAAQ,YAAY;AAAA,IA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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":["import type { Encoder } from '@solana/codecs-core';\nimport { getBase58Encoder } from '@solana/codecs-strings';\n\nexport type Blockhash = string & { readonly __brand: unique symbol };\n\nlet base58Encoder: Encoder<string> | undefined;\n\nexport function assertIsBlockhash(putativeBlockhash: string): asserts putativeBlockhash is Blockhash {\n if (!base58Encoder) base58Encoder = getBase58Encoder();\n try {\n // Fast-path; see if the input string is of an acceptable length.\n if (\n // Lowest value (32 bytes of zeroes)\n putativeBlockhash.length < 32 ||\n // Highest value (32 bytes of 255)\n putativeBlockhash.length > 44\n ) {\n throw new Error('Expected input string to decode to a byte array of length 32.');\n }\n // Slow-path; actually attempt to decode the input string.\n const bytes = base58Encoder.encode(putativeBlockhash);\n const numBytes = bytes.byteLength;\n if (numBytes !== 32) {\n throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);\n }\n } catch (e) {\n throw new Error(`\\`${putativeBlockhash}\\` is not a blockhash`, {\n cause: e,\n });\n }\n}\n","export type MainnetUrl = string & { '~cluster': 'mainnet' };\nexport type DevnetUrl = string & { '~cluster': 'devnet' };\nexport type TestnetUrl = string & { '~cluster': 'testnet' };\nexport type ClusterUrl = string | MainnetUrl | DevnetUrl | TestnetUrl;\n\nexport function mainnet(putativeString: string): MainnetUrl {\n return putativeString as MainnetUrl;\n}\nexport function devnet(putativeString: string): DevnetUrl {\n return putativeString as DevnetUrl;\n}\nexport function testnet(putativeString: string): TestnetUrl {\n return putativeString as TestnetUrl;\n}\n","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","// Keep in sync with https://github.com/solana-labs/solana/blob/master/rpc-client-api/src/custom_error.rs\n// Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/\nexport const SolanaRpcErrorCode = {\n JSON_RPC_INVALID_PARAMS: -32602,\n JSON_RPC_SCAN_ERROR: -32012,\n JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,\n JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,\n JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,\n JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,\n JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,\n JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016,\n JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,\n JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,\n JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,\n JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,\n JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,\n JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,\n JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,\n JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,\n JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015,\n} as const;\n\nexport type SolanaRpcErrorCodeEnum = (typeof SolanaRpcErrorCode)[keyof typeof SolanaRpcErrorCode];\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"]}
|
package/dist/index.node.cjs
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var codecsStrings = require('@solana/codecs-strings');
|
|
4
|
+
|
|
5
|
+
// src/blockhash.ts
|
|
6
|
+
var base58Encoder;
|
|
7
|
+
function assertIsBlockhash(putativeBlockhash) {
|
|
8
|
+
if (!base58Encoder)
|
|
9
|
+
base58Encoder = codecsStrings.getBase58Encoder();
|
|
10
|
+
try {
|
|
11
|
+
if (
|
|
12
|
+
// Lowest value (32 bytes of zeroes)
|
|
13
|
+
putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
|
|
14
|
+
putativeBlockhash.length > 44
|
|
15
|
+
) {
|
|
16
|
+
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
17
|
+
}
|
|
18
|
+
const bytes = base58Encoder.encode(putativeBlockhash);
|
|
19
|
+
const numBytes = bytes.byteLength;
|
|
20
|
+
if (numBytes !== 32) {
|
|
21
|
+
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
22
|
+
}
|
|
23
|
+
} catch (e) {
|
|
24
|
+
throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
|
|
25
|
+
cause: e
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// src/cluster-url.ts
|
|
31
|
+
function mainnet(putativeString) {
|
|
32
|
+
return putativeString;
|
|
33
|
+
}
|
|
34
|
+
function devnet(putativeString) {
|
|
35
|
+
return putativeString;
|
|
36
|
+
}
|
|
37
|
+
function testnet(putativeString) {
|
|
38
|
+
return putativeString;
|
|
39
|
+
}
|
|
40
|
+
|
|
3
41
|
// src/commitment.ts
|
|
4
42
|
function getCommitmentScore(commitment) {
|
|
5
43
|
switch (commitment) {
|
|
@@ -40,6 +78,27 @@ function lamports(putativeLamports) {
|
|
|
40
78
|
return putativeLamports;
|
|
41
79
|
}
|
|
42
80
|
|
|
81
|
+
// src/rpc-errors.ts
|
|
82
|
+
var SolanaRpcErrorCode = {
|
|
83
|
+
JSON_RPC_INVALID_PARAMS: -32602,
|
|
84
|
+
JSON_RPC_SCAN_ERROR: -32012,
|
|
85
|
+
JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,
|
|
86
|
+
JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,
|
|
87
|
+
JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,
|
|
88
|
+
JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,
|
|
89
|
+
JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,
|
|
90
|
+
JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016,
|
|
91
|
+
JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,
|
|
92
|
+
JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,
|
|
93
|
+
JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,
|
|
94
|
+
JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,
|
|
95
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,
|
|
96
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,
|
|
97
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,
|
|
98
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,
|
|
99
|
+
JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015
|
|
100
|
+
};
|
|
101
|
+
|
|
43
102
|
// src/stringified-bigint.ts
|
|
44
103
|
function isStringifiedBigInt(putativeBigInt) {
|
|
45
104
|
try {
|
|
@@ -100,18 +159,23 @@ function unixTimestamp(putativeTimestamp) {
|
|
|
100
159
|
return putativeTimestamp;
|
|
101
160
|
}
|
|
102
161
|
|
|
162
|
+
exports.SolanaRpcErrorCode = SolanaRpcErrorCode;
|
|
163
|
+
exports.assertIsBlockhash = assertIsBlockhash;
|
|
103
164
|
exports.assertIsLamports = assertIsLamports;
|
|
104
165
|
exports.assertIsStringifiedBigInt = assertIsStringifiedBigInt;
|
|
105
166
|
exports.assertIsStringifiedNumber = assertIsStringifiedNumber;
|
|
106
167
|
exports.assertIsUnixTimestamp = assertIsUnixTimestamp;
|
|
107
168
|
exports.commitmentComparator = commitmentComparator;
|
|
169
|
+
exports.devnet = devnet;
|
|
108
170
|
exports.isLamports = isLamports;
|
|
109
171
|
exports.isStringifiedBigInt = isStringifiedBigInt;
|
|
110
172
|
exports.isStringifiedNumber = isStringifiedNumber;
|
|
111
173
|
exports.isUnixTimestamp = isUnixTimestamp;
|
|
112
174
|
exports.lamports = lamports;
|
|
175
|
+
exports.mainnet = mainnet;
|
|
113
176
|
exports.stringifiedBigInt = stringifiedBigInt;
|
|
114
177
|
exports.stringifiedNumber = stringifiedNumber;
|
|
178
|
+
exports.testnet = testnet;
|
|
115
179
|
exports.unixTimestamp = unixTimestamp;
|
|
116
180
|
//# sourceMappingURL=out.js.map
|
|
117
181
|
//# sourceMappingURL=index.node.cjs.map
|
package/dist/index.node.cjs.map
CHANGED
|
@@ -1 +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"]}
|
|
1
|
+
{"version":3,"sources":["../src/blockhash.ts","../src/cluster-url.ts","../src/commitment.ts","../src/lamports.ts","../src/rpc-errors.ts","../src/stringified-bigint.ts","../src/stringified-number.ts","../src/unix-timestamp.ts"],"names":[],"mappings":";AACA,SAAS,wBAAwB;AAIjC,IAAI;AAEG,SAAS,kBAAkB,mBAAmE;AACjG,MAAI,CAAC;AAAe,oBAAgB,iBAAiB;AACrD,MAAI;AAEA;AAAA;AAAA,MAEI,kBAAkB,SAAS;AAAA,MAE3B,kBAAkB,SAAS;AAAA,MAC7B;AACE,YAAM,IAAI,MAAM,+DAA+D;AAAA,IACnF;AAEA,UAAM,QAAQ,cAAc,OAAO,iBAAiB;AACpD,UAAM,WAAW,MAAM;AACvB,QAAI,aAAa,IAAI;AACjB,YAAM,IAAI,MAAM,gFAAgF,QAAQ,EAAE;AAAA,IAC9G;AAAA,EACJ,SAAS,GAAG;AACR,UAAM,IAAI,MAAM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Base58Encoder } from '@solana/codecs-strings';\n\nexport type Blockhash = string & { readonly __brand: unique symbol };\n\nlet base58Encoder: Encoder<string> | undefined;\n\nexport function assertIsBlockhash(putativeBlockhash: string): asserts putativeBlockhash is Blockhash {\n if (!base58Encoder) base58Encoder = getBase58Encoder();\n try {\n // Fast-path; see if the input string is of an acceptable length.\n if (\n // Lowest value (32 bytes of zeroes)\n putativeBlockhash.length < 32 ||\n // Highest value (32 bytes of 255)\n putativeBlockhash.length > 44\n ) {\n throw new Error('Expected input string to decode to a byte array of length 32.');\n }\n // Slow-path; actually attempt to decode the input string.\n const bytes = base58Encoder.encode(putativeBlockhash);\n const numBytes = bytes.byteLength;\n if (numBytes !== 32) {\n throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);\n }\n } catch (e) {\n throw new Error(`\\`${putativeBlockhash}\\` is not a blockhash`, {\n cause: e,\n });\n }\n}\n","export type MainnetUrl = string & { '~cluster': 'mainnet' };\nexport type DevnetUrl = string & { '~cluster': 'devnet' };\nexport type TestnetUrl = string & { '~cluster': 'testnet' };\nexport type ClusterUrl = string | MainnetUrl | DevnetUrl | TestnetUrl;\n\nexport function mainnet(putativeString: string): MainnetUrl {\n return putativeString as MainnetUrl;\n}\nexport function devnet(putativeString: string): DevnetUrl {\n return putativeString as DevnetUrl;\n}\nexport function testnet(putativeString: string): TestnetUrl {\n return putativeString as TestnetUrl;\n}\n","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","// Keep in sync with https://github.com/solana-labs/solana/blob/master/rpc-client-api/src/custom_error.rs\n// Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/\nexport const SolanaRpcErrorCode = {\n JSON_RPC_INVALID_PARAMS: -32602,\n JSON_RPC_SCAN_ERROR: -32012,\n JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,\n JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,\n JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,\n JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,\n JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,\n JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016,\n JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,\n JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,\n JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,\n JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,\n JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,\n JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,\n JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,\n JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,\n JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015,\n} as const;\n\nexport type SolanaRpcErrorCodeEnum = (typeof SolanaRpcErrorCode)[keyof typeof SolanaRpcErrorCode];\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"]}
|
package/dist/index.node.js
CHANGED
|
@@ -1,3 +1,41 @@
|
|
|
1
|
+
import { getBase58Encoder } from '@solana/codecs-strings';
|
|
2
|
+
|
|
3
|
+
// src/blockhash.ts
|
|
4
|
+
var base58Encoder;
|
|
5
|
+
function assertIsBlockhash(putativeBlockhash) {
|
|
6
|
+
if (!base58Encoder)
|
|
7
|
+
base58Encoder = getBase58Encoder();
|
|
8
|
+
try {
|
|
9
|
+
if (
|
|
10
|
+
// Lowest value (32 bytes of zeroes)
|
|
11
|
+
putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
|
|
12
|
+
putativeBlockhash.length > 44
|
|
13
|
+
) {
|
|
14
|
+
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
15
|
+
}
|
|
16
|
+
const bytes = base58Encoder.encode(putativeBlockhash);
|
|
17
|
+
const numBytes = bytes.byteLength;
|
|
18
|
+
if (numBytes !== 32) {
|
|
19
|
+
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
20
|
+
}
|
|
21
|
+
} catch (e) {
|
|
22
|
+
throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
|
|
23
|
+
cause: e
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// src/cluster-url.ts
|
|
29
|
+
function mainnet(putativeString) {
|
|
30
|
+
return putativeString;
|
|
31
|
+
}
|
|
32
|
+
function devnet(putativeString) {
|
|
33
|
+
return putativeString;
|
|
34
|
+
}
|
|
35
|
+
function testnet(putativeString) {
|
|
36
|
+
return putativeString;
|
|
37
|
+
}
|
|
38
|
+
|
|
1
39
|
// src/commitment.ts
|
|
2
40
|
function getCommitmentScore(commitment) {
|
|
3
41
|
switch (commitment) {
|
|
@@ -38,6 +76,27 @@ function lamports(putativeLamports) {
|
|
|
38
76
|
return putativeLamports;
|
|
39
77
|
}
|
|
40
78
|
|
|
79
|
+
// src/rpc-errors.ts
|
|
80
|
+
var SolanaRpcErrorCode = {
|
|
81
|
+
JSON_RPC_INVALID_PARAMS: -32602,
|
|
82
|
+
JSON_RPC_SCAN_ERROR: -32012,
|
|
83
|
+
JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,
|
|
84
|
+
JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,
|
|
85
|
+
JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,
|
|
86
|
+
JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,
|
|
87
|
+
JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,
|
|
88
|
+
JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016,
|
|
89
|
+
JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,
|
|
90
|
+
JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,
|
|
91
|
+
JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,
|
|
92
|
+
JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,
|
|
93
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,
|
|
94
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,
|
|
95
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,
|
|
96
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,
|
|
97
|
+
JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015
|
|
98
|
+
};
|
|
99
|
+
|
|
41
100
|
// src/stringified-bigint.ts
|
|
42
101
|
function isStringifiedBigInt(putativeBigInt) {
|
|
43
102
|
try {
|
|
@@ -98,6 +157,6 @@ function unixTimestamp(putativeTimestamp) {
|
|
|
98
157
|
return putativeTimestamp;
|
|
99
158
|
}
|
|
100
159
|
|
|
101
|
-
export { assertIsLamports, assertIsStringifiedBigInt, assertIsStringifiedNumber, assertIsUnixTimestamp, commitmentComparator, isLamports, isStringifiedBigInt, isStringifiedNumber, isUnixTimestamp, lamports, stringifiedBigInt, stringifiedNumber, unixTimestamp };
|
|
160
|
+
export { SolanaRpcErrorCode, assertIsBlockhash, assertIsLamports, assertIsStringifiedBigInt, assertIsStringifiedNumber, assertIsUnixTimestamp, commitmentComparator, devnet, isLamports, isStringifiedBigInt, isStringifiedNumber, isUnixTimestamp, lamports, mainnet, stringifiedBigInt, stringifiedNumber, testnet, unixTimestamp };
|
|
102
161
|
//# sourceMappingURL=out.js.map
|
|
103
162
|
//# sourceMappingURL=index.node.js.map
|