@solana/web3.js 1.87.3 → 2.0.0-experimental.0099b2a
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 +56 -112
- package/dist/index.browser.cjs +927 -0
- package/dist/index.browser.cjs.map +1 -0
- package/dist/index.browser.js +876 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/index.development.js +4180 -0
- package/dist/index.development.js.map +1 -0
- package/dist/index.native.js +865 -0
- package/dist/index.native.js.map +1 -0
- package/dist/index.node.cjs +916 -0
- package/dist/index.node.cjs.map +1 -0
- package/dist/index.node.js +865 -0
- package/dist/index.node.js.map +1 -0
- package/dist/index.production.min.js +87 -0
- package/dist/types/airdrop-confirmer.d.ts +20 -0
- package/dist/types/airdrop.d.ts +23 -0
- package/dist/types/cached-abortable-iterable.d.ts +11 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/rpc-default-config.d.ts +3 -0
- package/dist/types/rpc-integer-overflow-error.d.ts +8 -0
- package/dist/types/rpc-request-coalescer.d.ts +5 -0
- package/dist/types/rpc-request-deduplication.d.ts +2 -0
- package/dist/types/rpc-subscription-coalescer.d.ts +10 -0
- package/dist/types/rpc-transport.d.ts +4 -0
- package/dist/types/rpc-websocket-autopinger.d.ts +8 -0
- package/dist/types/rpc-websocket-connection-sharding.d.ts +13 -0
- package/dist/types/rpc-websocket-transport.d.ts +13 -0
- package/dist/types/rpc.d.ts +7 -0
- package/dist/types/send-transaction.d.ts +37 -0
- package/dist/types/transaction-confirmation-strategy-blockheight.d.ts +10 -0
- package/dist/types/transaction-confirmation-strategy-nonce.d.ts +15 -0
- package/dist/types/transaction-confirmation-strategy-racer.d.ts +14 -0
- package/dist/types/transaction-confirmation-strategy-recent-signature.d.ts +13 -0
- package/dist/types/transaction-confirmation-strategy-timeout.d.ts +8 -0
- package/dist/types/transaction-confirmation.d.ts +37 -0
- package/package.json +85 -109
- package/lib/index.browser.cjs.js +0 -10296
- package/lib/index.browser.cjs.js.map +0 -1
- package/lib/index.browser.esm.js +0 -10193
- package/lib/index.browser.esm.js.map +0 -1
- package/lib/index.cjs.js +0 -12589
- package/lib/index.cjs.js.map +0 -1
- package/lib/index.d.ts +0 -3947
- package/lib/index.esm.js +0 -12480
- package/lib/index.esm.js.map +0 -1
- package/lib/index.iife.js +0 -26233
- package/lib/index.iife.js.map +0 -1
- package/lib/index.iife.min.js +0 -20
- package/lib/index.iife.min.js.map +0 -1
- package/lib/index.native.js +0 -10296
- package/lib/index.native.js.map +0 -1
- package/src/__forks__/browser/fetch-impl.ts +0 -4
- package/src/__forks__/browser/rpc-websocket-factory.ts +0 -1
- package/src/__forks__/react-native/fetch-impl.ts +0 -4
- package/src/__forks__/react-native/rpc-websocket-factory.ts +0 -1
- package/src/account-data.ts +0 -39
- package/src/account.ts +0 -55
- package/src/blockhash.ts +0 -4
- package/src/bpf-loader-deprecated.ts +0 -5
- package/src/bpf-loader.ts +0 -45
- package/src/connection.ts +0 -6796
- package/src/epoch-schedule.ts +0 -102
- package/src/errors.ts +0 -50
- package/src/fee-calculator.ts +0 -18
- package/src/fetch-impl.ts +0 -16
- package/src/index.ts +0 -24
- package/src/instruction.ts +0 -58
- package/src/keypair.ts +0 -102
- package/src/layout.ts +0 -188
- package/src/loader.ts +0 -267
- package/src/message/account-keys.ts +0 -79
- package/src/message/compiled-keys.ts +0 -165
- package/src/message/index.ts +0 -47
- package/src/message/legacy.ts +0 -326
- package/src/message/v0.ts +0 -496
- package/src/message/versioned.ts +0 -36
- package/src/nonce-account.ts +0 -82
- package/src/programs/address-lookup-table/index.ts +0 -435
- package/src/programs/address-lookup-table/state.ts +0 -84
- package/src/programs/compute-budget.ts +0 -281
- package/src/programs/ed25519.ts +0 -157
- package/src/programs/index.ts +0 -7
- package/src/programs/secp256k1.ts +0 -228
- package/src/programs/stake.ts +0 -935
- package/src/programs/system.ts +0 -1048
- package/src/programs/vote.ts +0 -543
- package/src/publickey.ts +0 -259
- package/src/rpc-websocket-factory.ts +0 -4
- package/src/rpc-websocket.ts +0 -79
- package/src/sysvar.ts +0 -37
- package/src/timing.ts +0 -23
- package/src/transaction/constants.ts +0 -12
- package/src/transaction/expiry-custom-errors.ts +0 -48
- package/src/transaction/index.ts +0 -5
- package/src/transaction/legacy.ts +0 -948
- package/src/transaction/message.ts +0 -140
- package/src/transaction/versioned.ts +0 -126
- package/src/utils/assert.ts +0 -8
- package/src/utils/bigint.ts +0 -43
- package/src/utils/borsh-schema.ts +0 -38
- package/src/utils/cluster.ts +0 -35
- package/src/utils/ed25519.ts +0 -43
- package/src/utils/index.ts +0 -5
- package/src/utils/makeWebsocketUrl.ts +0 -26
- package/src/utils/promise-timeout.ts +0 -14
- package/src/utils/secp256k1.ts +0 -11
- package/src/utils/send-and-confirm-raw-transaction.ts +0 -102
- package/src/utils/send-and-confirm-transaction.ts +0 -98
- package/src/utils/shortvec-encoding.ts +0 -28
- package/src/utils/sleep.ts +0 -4
- package/src/utils/to-buffer.ts +0 -11
- package/src/validator-info.ts +0 -104
- package/src/vote-account.ts +0 -236
|
@@ -0,0 +1,4180 @@
|
|
|
1
|
+
this.globalThis = this.globalThis || {};
|
|
2
|
+
this.globalThis.solanaWeb3 = (function (exports) {
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
var __create = Object.create;
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
8
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __esm = (fn, res) => function __init() {
|
|
12
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
13
|
+
};
|
|
14
|
+
var __commonJS = (cb, mod2) => function __require() {
|
|
15
|
+
return mod2 || (0, cb[__getOwnPropNames(cb)[0]])((mod2 = { exports: {} }).exports, mod2), mod2.exports;
|
|
16
|
+
};
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from))
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__getProtoOf(mod2)) : {}, __copyProps(
|
|
26
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
27
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
28
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
29
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
30
|
+
isNodeMode || !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
|
|
31
|
+
mod2
|
|
32
|
+
));
|
|
33
|
+
|
|
34
|
+
// ../build-scripts/env-shim.ts
|
|
35
|
+
var init_env_shim = __esm({
|
|
36
|
+
"../build-scripts/env-shim.ts"() {
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// ../../node_modules/.pnpm/fast-stable-stringify@1.0.0/node_modules/fast-stable-stringify/index.js
|
|
41
|
+
var require_fast_stable_stringify = __commonJS({
|
|
42
|
+
"../../node_modules/.pnpm/fast-stable-stringify@1.0.0/node_modules/fast-stable-stringify/index.js"(exports, module) {
|
|
43
|
+
init_env_shim();
|
|
44
|
+
var objToString = Object.prototype.toString;
|
|
45
|
+
var objKeys = Object.keys || function(obj) {
|
|
46
|
+
var keys = [];
|
|
47
|
+
for (var name in obj) {
|
|
48
|
+
keys.push(name);
|
|
49
|
+
}
|
|
50
|
+
return keys;
|
|
51
|
+
};
|
|
52
|
+
function stringify(val, isArrayProp) {
|
|
53
|
+
var i, max, str, keys, key, propVal, toStr;
|
|
54
|
+
if (val === true) {
|
|
55
|
+
return "true";
|
|
56
|
+
}
|
|
57
|
+
if (val === false) {
|
|
58
|
+
return "false";
|
|
59
|
+
}
|
|
60
|
+
switch (typeof val) {
|
|
61
|
+
case "object":
|
|
62
|
+
if (val === null) {
|
|
63
|
+
return null;
|
|
64
|
+
} else if (val.toJSON && typeof val.toJSON === "function") {
|
|
65
|
+
return stringify(val.toJSON(), isArrayProp);
|
|
66
|
+
} else {
|
|
67
|
+
toStr = objToString.call(val);
|
|
68
|
+
if (toStr === "[object Array]") {
|
|
69
|
+
str = "[";
|
|
70
|
+
max = val.length - 1;
|
|
71
|
+
for (i = 0; i < max; i++) {
|
|
72
|
+
str += stringify(val[i], true) + ",";
|
|
73
|
+
}
|
|
74
|
+
if (max > -1) {
|
|
75
|
+
str += stringify(val[i], true);
|
|
76
|
+
}
|
|
77
|
+
return str + "]";
|
|
78
|
+
} else if (toStr === "[object Object]") {
|
|
79
|
+
keys = objKeys(val).sort();
|
|
80
|
+
max = keys.length;
|
|
81
|
+
str = "";
|
|
82
|
+
i = 0;
|
|
83
|
+
while (i < max) {
|
|
84
|
+
key = keys[i];
|
|
85
|
+
propVal = stringify(val[key], false);
|
|
86
|
+
if (propVal !== void 0) {
|
|
87
|
+
if (str) {
|
|
88
|
+
str += ",";
|
|
89
|
+
}
|
|
90
|
+
str += JSON.stringify(key) + ":" + propVal;
|
|
91
|
+
}
|
|
92
|
+
i++;
|
|
93
|
+
}
|
|
94
|
+
return "{" + str + "}";
|
|
95
|
+
} else {
|
|
96
|
+
return JSON.stringify(val);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
case "function":
|
|
100
|
+
case "undefined":
|
|
101
|
+
return isArrayProp ? null : void 0;
|
|
102
|
+
case "string":
|
|
103
|
+
return JSON.stringify(val);
|
|
104
|
+
default:
|
|
105
|
+
return isFinite(val) ? val : null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
module.exports = function(val) {
|
|
109
|
+
var returnVal = stringify(val, false);
|
|
110
|
+
if (returnVal !== void 0) {
|
|
111
|
+
return "" + returnVal;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// src/index.ts
|
|
118
|
+
init_env_shim();
|
|
119
|
+
|
|
120
|
+
// ../addresses/dist/index.browser.js
|
|
121
|
+
init_env_shim();
|
|
122
|
+
|
|
123
|
+
// ../codecs-core/dist/index.browser.js
|
|
124
|
+
init_env_shim();
|
|
125
|
+
function assertByteArrayIsNotEmptyForCodec(codecDescription, bytes, offset = 0) {
|
|
126
|
+
if (bytes.length - offset <= 0) {
|
|
127
|
+
throw new Error(`Codec [${codecDescription}] cannot decode empty byte arrays.`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function assertByteArrayHasEnoughBytesForCodec(codecDescription, expected, bytes, offset = 0) {
|
|
131
|
+
const bytesLength = bytes.length - offset;
|
|
132
|
+
if (bytesLength < expected) {
|
|
133
|
+
throw new Error(`Codec [${codecDescription}] expected ${expected} bytes, got ${bytesLength}.`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
var mergeBytes = (byteArrays) => {
|
|
137
|
+
const nonEmptyByteArrays = byteArrays.filter((arr) => arr.length);
|
|
138
|
+
if (nonEmptyByteArrays.length === 0) {
|
|
139
|
+
return byteArrays.length ? byteArrays[0] : new Uint8Array();
|
|
140
|
+
}
|
|
141
|
+
if (nonEmptyByteArrays.length === 1) {
|
|
142
|
+
return nonEmptyByteArrays[0];
|
|
143
|
+
}
|
|
144
|
+
const totalLength = nonEmptyByteArrays.reduce((total, arr) => total + arr.length, 0);
|
|
145
|
+
const result = new Uint8Array(totalLength);
|
|
146
|
+
let offset = 0;
|
|
147
|
+
nonEmptyByteArrays.forEach((arr) => {
|
|
148
|
+
result.set(arr, offset);
|
|
149
|
+
offset += arr.length;
|
|
150
|
+
});
|
|
151
|
+
return result;
|
|
152
|
+
};
|
|
153
|
+
var padBytes = (bytes, length) => {
|
|
154
|
+
if (bytes.length >= length)
|
|
155
|
+
return bytes;
|
|
156
|
+
const paddedBytes = new Uint8Array(length).fill(0);
|
|
157
|
+
paddedBytes.set(bytes);
|
|
158
|
+
return paddedBytes;
|
|
159
|
+
};
|
|
160
|
+
var fixBytes = (bytes, length) => padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length);
|
|
161
|
+
function combineCodec(encoder, decoder, description) {
|
|
162
|
+
if (encoder.fixedSize !== decoder.fixedSize) {
|
|
163
|
+
throw new Error(
|
|
164
|
+
`Encoder and decoder must have the same fixed size, got [${encoder.fixedSize}] and [${decoder.fixedSize}].`
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
if (encoder.maxSize !== decoder.maxSize) {
|
|
168
|
+
throw new Error(
|
|
169
|
+
`Encoder and decoder must have the same max size, got [${encoder.maxSize}] and [${decoder.maxSize}].`
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
if (description === void 0 && encoder.description !== decoder.description) {
|
|
173
|
+
throw new Error(
|
|
174
|
+
`Encoder and decoder must have the same description, got [${encoder.description}] and [${decoder.description}]. Pass a custom description as a third argument if you want to override the description and bypass this error.`
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
decode: decoder.decode,
|
|
179
|
+
description: description ?? encoder.description,
|
|
180
|
+
encode: encoder.encode,
|
|
181
|
+
fixedSize: encoder.fixedSize,
|
|
182
|
+
maxSize: encoder.maxSize
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
function fixCodecHelper(data, fixedBytes, description) {
|
|
186
|
+
return {
|
|
187
|
+
description: description ?? `fixed(${fixedBytes}, ${data.description})`,
|
|
188
|
+
fixedSize: fixedBytes,
|
|
189
|
+
maxSize: fixedBytes
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function fixEncoder(encoder, fixedBytes, description) {
|
|
193
|
+
return {
|
|
194
|
+
...fixCodecHelper(encoder, fixedBytes, description),
|
|
195
|
+
encode: (value) => fixBytes(encoder.encode(value), fixedBytes)
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function fixDecoder(decoder, fixedBytes, description) {
|
|
199
|
+
return {
|
|
200
|
+
...fixCodecHelper(decoder, fixedBytes, description),
|
|
201
|
+
decode: (bytes, offset = 0) => {
|
|
202
|
+
assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes, offset);
|
|
203
|
+
if (offset > 0 || bytes.length > fixedBytes) {
|
|
204
|
+
bytes = bytes.slice(offset, offset + fixedBytes);
|
|
205
|
+
}
|
|
206
|
+
if (decoder.fixedSize !== null) {
|
|
207
|
+
bytes = fixBytes(bytes, decoder.fixedSize);
|
|
208
|
+
}
|
|
209
|
+
const [value] = decoder.decode(bytes, 0);
|
|
210
|
+
return [value, offset + fixedBytes];
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function mapEncoder(encoder, unmap) {
|
|
215
|
+
return {
|
|
216
|
+
description: encoder.description,
|
|
217
|
+
encode: (value) => encoder.encode(unmap(value)),
|
|
218
|
+
fixedSize: encoder.fixedSize,
|
|
219
|
+
maxSize: encoder.maxSize
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
function mapDecoder(decoder, map) {
|
|
223
|
+
return {
|
|
224
|
+
decode: (bytes, offset = 0) => {
|
|
225
|
+
const [value, length] = decoder.decode(bytes, offset);
|
|
226
|
+
return [map(value, bytes, offset), length];
|
|
227
|
+
},
|
|
228
|
+
description: decoder.description,
|
|
229
|
+
fixedSize: decoder.fixedSize,
|
|
230
|
+
maxSize: decoder.maxSize
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// ../codecs-strings/dist/index.browser.js
|
|
235
|
+
init_env_shim();
|
|
236
|
+
|
|
237
|
+
// ../codecs-numbers/dist/index.browser.js
|
|
238
|
+
init_env_shim();
|
|
239
|
+
function assertNumberIsBetweenForCodec(codecDescription, min, max, value) {
|
|
240
|
+
if (value < min || value > max) {
|
|
241
|
+
throw new Error(
|
|
242
|
+
`Codec [${codecDescription}] expected number to be in the range [${min}, ${max}], got ${value}.`
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
function sharedNumberFactory(input) {
|
|
247
|
+
let littleEndian;
|
|
248
|
+
let defaultDescription = input.name;
|
|
249
|
+
if (input.size > 1) {
|
|
250
|
+
littleEndian = !("endian" in input.options) || input.options.endian === 0;
|
|
251
|
+
defaultDescription += littleEndian ? "(le)" : "(be)";
|
|
252
|
+
}
|
|
253
|
+
return {
|
|
254
|
+
description: input.options.description ?? defaultDescription,
|
|
255
|
+
fixedSize: input.size,
|
|
256
|
+
littleEndian,
|
|
257
|
+
maxSize: input.size
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
function numberEncoderFactory(input) {
|
|
261
|
+
const codecData = sharedNumberFactory(input);
|
|
262
|
+
return {
|
|
263
|
+
description: codecData.description,
|
|
264
|
+
encode(value) {
|
|
265
|
+
if (input.range) {
|
|
266
|
+
assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);
|
|
267
|
+
}
|
|
268
|
+
const arrayBuffer = new ArrayBuffer(input.size);
|
|
269
|
+
input.set(new DataView(arrayBuffer), value, codecData.littleEndian);
|
|
270
|
+
return new Uint8Array(arrayBuffer);
|
|
271
|
+
},
|
|
272
|
+
fixedSize: codecData.fixedSize,
|
|
273
|
+
maxSize: codecData.maxSize
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
function numberDecoderFactory(input) {
|
|
277
|
+
const codecData = sharedNumberFactory(input);
|
|
278
|
+
return {
|
|
279
|
+
decode(bytes, offset = 0) {
|
|
280
|
+
assertByteArrayIsNotEmptyForCodec(codecData.description, bytes, offset);
|
|
281
|
+
assertByteArrayHasEnoughBytesForCodec(codecData.description, input.size, bytes, offset);
|
|
282
|
+
const view = new DataView(toArrayBuffer(bytes, offset, input.size));
|
|
283
|
+
return [input.get(view, codecData.littleEndian), offset + input.size];
|
|
284
|
+
},
|
|
285
|
+
description: codecData.description,
|
|
286
|
+
fixedSize: codecData.fixedSize,
|
|
287
|
+
maxSize: codecData.maxSize
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
function toArrayBuffer(bytes, offset, length) {
|
|
291
|
+
const bytesOffset = bytes.byteOffset + (offset ?? 0);
|
|
292
|
+
const bytesLength = length ?? bytes.byteLength;
|
|
293
|
+
return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
|
|
294
|
+
}
|
|
295
|
+
var getShortU16Encoder = (options = {}) => ({
|
|
296
|
+
description: options.description ?? "shortU16",
|
|
297
|
+
encode: (value) => {
|
|
298
|
+
assertNumberIsBetweenForCodec("shortU16", 0, 65535, value);
|
|
299
|
+
const bytes = [0];
|
|
300
|
+
for (let ii = 0; ; ii += 1) {
|
|
301
|
+
const alignedValue = value >> ii * 7;
|
|
302
|
+
if (alignedValue === 0) {
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
const nextSevenBits = 127 & alignedValue;
|
|
306
|
+
bytes[ii] = nextSevenBits;
|
|
307
|
+
if (ii > 0) {
|
|
308
|
+
bytes[ii - 1] |= 128;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return new Uint8Array(bytes);
|
|
312
|
+
},
|
|
313
|
+
fixedSize: null,
|
|
314
|
+
maxSize: 3
|
|
315
|
+
});
|
|
316
|
+
var getShortU16Decoder = (options = {}) => ({
|
|
317
|
+
decode: (bytes, offset = 0) => {
|
|
318
|
+
let value = 0;
|
|
319
|
+
let byteCount = 0;
|
|
320
|
+
while (++byteCount) {
|
|
321
|
+
const byteIndex = byteCount - 1;
|
|
322
|
+
const currentByte = bytes[offset + byteIndex];
|
|
323
|
+
const nextSevenBits = 127 & currentByte;
|
|
324
|
+
value |= nextSevenBits << byteIndex * 7;
|
|
325
|
+
if ((currentByte & 128) === 0) {
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return [value, offset + byteCount];
|
|
330
|
+
},
|
|
331
|
+
description: options.description ?? "shortU16",
|
|
332
|
+
fixedSize: null,
|
|
333
|
+
maxSize: 3
|
|
334
|
+
});
|
|
335
|
+
var getU32Encoder = (options = {}) => numberEncoderFactory({
|
|
336
|
+
name: "u32",
|
|
337
|
+
options,
|
|
338
|
+
range: [0, Number("0xffffffff")],
|
|
339
|
+
set: (view, value, le) => view.setUint32(0, value, le),
|
|
340
|
+
size: 4
|
|
341
|
+
});
|
|
342
|
+
var getU32Decoder = (options = {}) => numberDecoderFactory({
|
|
343
|
+
get: (view, le) => view.getUint32(0, le),
|
|
344
|
+
name: "u32",
|
|
345
|
+
options,
|
|
346
|
+
size: 4
|
|
347
|
+
});
|
|
348
|
+
var getU8Encoder = (options = {}) => numberEncoderFactory({
|
|
349
|
+
name: "u8",
|
|
350
|
+
options,
|
|
351
|
+
range: [0, Number("0xff")],
|
|
352
|
+
set: (view, value) => view.setUint8(0, value),
|
|
353
|
+
size: 1
|
|
354
|
+
});
|
|
355
|
+
var getU8Decoder = (options = {}) => numberDecoderFactory({
|
|
356
|
+
get: (view) => view.getUint8(0),
|
|
357
|
+
name: "u8",
|
|
358
|
+
options,
|
|
359
|
+
size: 1
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
// ../codecs-strings/dist/index.browser.js
|
|
363
|
+
function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
|
|
364
|
+
if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
|
|
365
|
+
throw new Error(`Expected a string of base ${alphabet4.length}, got [${givenValue}].`);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
var getBaseXEncoder = (alphabet4) => {
|
|
369
|
+
const base = alphabet4.length;
|
|
370
|
+
const baseBigInt = BigInt(base);
|
|
371
|
+
return {
|
|
372
|
+
description: `base${base}`,
|
|
373
|
+
encode(value) {
|
|
374
|
+
assertValidBaseString(alphabet4, value);
|
|
375
|
+
if (value === "")
|
|
376
|
+
return new Uint8Array();
|
|
377
|
+
const chars = [...value];
|
|
378
|
+
let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
|
|
379
|
+
trailIndex = trailIndex === -1 ? chars.length : trailIndex;
|
|
380
|
+
const leadingZeroes = Array(trailIndex).fill(0);
|
|
381
|
+
if (trailIndex === chars.length)
|
|
382
|
+
return Uint8Array.from(leadingZeroes);
|
|
383
|
+
const tailChars = chars.slice(trailIndex);
|
|
384
|
+
let base10Number = 0n;
|
|
385
|
+
let baseXPower = 1n;
|
|
386
|
+
for (let i = tailChars.length - 1; i >= 0; i -= 1) {
|
|
387
|
+
base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
|
|
388
|
+
baseXPower *= baseBigInt;
|
|
389
|
+
}
|
|
390
|
+
const tailBytes = [];
|
|
391
|
+
while (base10Number > 0n) {
|
|
392
|
+
tailBytes.unshift(Number(base10Number % 256n));
|
|
393
|
+
base10Number /= 256n;
|
|
394
|
+
}
|
|
395
|
+
return Uint8Array.from(leadingZeroes.concat(tailBytes));
|
|
396
|
+
},
|
|
397
|
+
fixedSize: null,
|
|
398
|
+
maxSize: null
|
|
399
|
+
};
|
|
400
|
+
};
|
|
401
|
+
var getBaseXDecoder = (alphabet4) => {
|
|
402
|
+
const base = alphabet4.length;
|
|
403
|
+
const baseBigInt = BigInt(base);
|
|
404
|
+
return {
|
|
405
|
+
decode(rawBytes, offset = 0) {
|
|
406
|
+
const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
|
|
407
|
+
if (bytes.length === 0)
|
|
408
|
+
return ["", 0];
|
|
409
|
+
let trailIndex = bytes.findIndex((n) => n !== 0);
|
|
410
|
+
trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
|
|
411
|
+
const leadingZeroes = alphabet4[0].repeat(trailIndex);
|
|
412
|
+
if (trailIndex === bytes.length)
|
|
413
|
+
return [leadingZeroes, rawBytes.length];
|
|
414
|
+
let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
|
|
415
|
+
const tailChars = [];
|
|
416
|
+
while (base10Number > 0n) {
|
|
417
|
+
tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
|
|
418
|
+
base10Number /= baseBigInt;
|
|
419
|
+
}
|
|
420
|
+
return [leadingZeroes + tailChars.join(""), rawBytes.length];
|
|
421
|
+
},
|
|
422
|
+
description: `base${base}`,
|
|
423
|
+
fixedSize: null,
|
|
424
|
+
maxSize: null
|
|
425
|
+
};
|
|
426
|
+
};
|
|
427
|
+
var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
428
|
+
var getBase58Encoder = () => getBaseXEncoder(alphabet2);
|
|
429
|
+
var getBase58Decoder = () => getBaseXDecoder(alphabet2);
|
|
430
|
+
var getBase64Encoder = () => {
|
|
431
|
+
{
|
|
432
|
+
return {
|
|
433
|
+
description: `base64`,
|
|
434
|
+
encode(value) {
|
|
435
|
+
try {
|
|
436
|
+
const bytes = atob(value).split("").map((c) => c.charCodeAt(0));
|
|
437
|
+
return new Uint8Array(bytes);
|
|
438
|
+
} catch (e23) {
|
|
439
|
+
throw new Error(`Expected a string of base 64, got [${value}].`);
|
|
440
|
+
}
|
|
441
|
+
},
|
|
442
|
+
fixedSize: null,
|
|
443
|
+
maxSize: null
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
var removeNullCharacters = (value) => (
|
|
448
|
+
// eslint-disable-next-line no-control-regex
|
|
449
|
+
value.replace(/\u0000/g, "")
|
|
450
|
+
);
|
|
451
|
+
var e = globalThis.TextDecoder;
|
|
452
|
+
var o = globalThis.TextEncoder;
|
|
453
|
+
var getUtf8Encoder = () => {
|
|
454
|
+
let textEncoder;
|
|
455
|
+
return {
|
|
456
|
+
description: "utf8",
|
|
457
|
+
encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
|
|
458
|
+
fixedSize: null,
|
|
459
|
+
maxSize: null
|
|
460
|
+
};
|
|
461
|
+
};
|
|
462
|
+
var getUtf8Decoder = () => {
|
|
463
|
+
let textDecoder;
|
|
464
|
+
return {
|
|
465
|
+
decode(bytes, offset = 0) {
|
|
466
|
+
const value = (textDecoder || (textDecoder = new e())).decode(bytes.slice(offset));
|
|
467
|
+
return [removeNullCharacters(value), bytes.length];
|
|
468
|
+
},
|
|
469
|
+
description: "utf8",
|
|
470
|
+
fixedSize: null,
|
|
471
|
+
maxSize: null
|
|
472
|
+
};
|
|
473
|
+
};
|
|
474
|
+
var getStringEncoder = (options = {}) => {
|
|
475
|
+
const size = options.size ?? getU32Encoder();
|
|
476
|
+
const encoding = options.encoding ?? getUtf8Encoder();
|
|
477
|
+
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
|
|
478
|
+
if (size === "variable") {
|
|
479
|
+
return { ...encoding, description };
|
|
480
|
+
}
|
|
481
|
+
if (typeof size === "number") {
|
|
482
|
+
return fixEncoder(encoding, size, description);
|
|
483
|
+
}
|
|
484
|
+
return {
|
|
485
|
+
description,
|
|
486
|
+
encode: (value) => {
|
|
487
|
+
const contentBytes = encoding.encode(value);
|
|
488
|
+
const lengthBytes = size.encode(contentBytes.length);
|
|
489
|
+
return mergeBytes([lengthBytes, contentBytes]);
|
|
490
|
+
},
|
|
491
|
+
fixedSize: null,
|
|
492
|
+
maxSize: null
|
|
493
|
+
};
|
|
494
|
+
};
|
|
495
|
+
var getStringDecoder = (options = {}) => {
|
|
496
|
+
const size = options.size ?? getU32Decoder();
|
|
497
|
+
const encoding = options.encoding ?? getUtf8Decoder();
|
|
498
|
+
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
|
|
499
|
+
if (size === "variable") {
|
|
500
|
+
return { ...encoding, description };
|
|
501
|
+
}
|
|
502
|
+
if (typeof size === "number") {
|
|
503
|
+
return fixDecoder(encoding, size, description);
|
|
504
|
+
}
|
|
505
|
+
return {
|
|
506
|
+
decode: (bytes, offset = 0) => {
|
|
507
|
+
assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
|
|
508
|
+
const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
|
|
509
|
+
const length = Number(lengthBigInt);
|
|
510
|
+
offset = lengthOffset;
|
|
511
|
+
const contentBytes = bytes.slice(offset, offset + length);
|
|
512
|
+
assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
|
|
513
|
+
const [value, contentOffset] = encoding.decode(contentBytes);
|
|
514
|
+
offset += contentOffset;
|
|
515
|
+
return [value, offset];
|
|
516
|
+
},
|
|
517
|
+
description,
|
|
518
|
+
fixedSize: null,
|
|
519
|
+
maxSize: null
|
|
520
|
+
};
|
|
521
|
+
};
|
|
522
|
+
function getSizeDescription(size) {
|
|
523
|
+
return typeof size === "object" ? size.description : `${size}`;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// ../assertions/dist/index.browser.js
|
|
527
|
+
init_env_shim();
|
|
528
|
+
function assertIsSecureContext() {
|
|
529
|
+
if (!globalThis.isSecureContext) {
|
|
530
|
+
throw new Error(
|
|
531
|
+
"Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts"
|
|
532
|
+
);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
var cachedEd25519Decision;
|
|
536
|
+
async function isEd25519CurveSupported(subtle) {
|
|
537
|
+
if (cachedEd25519Decision === void 0) {
|
|
538
|
+
cachedEd25519Decision = new Promise((resolve) => {
|
|
539
|
+
subtle.generateKey(
|
|
540
|
+
"Ed25519",
|
|
541
|
+
/* extractable */
|
|
542
|
+
false,
|
|
543
|
+
["sign", "verify"]
|
|
544
|
+
).catch(() => {
|
|
545
|
+
resolve(cachedEd25519Decision = false);
|
|
546
|
+
}).then(() => {
|
|
547
|
+
resolve(cachedEd25519Decision = true);
|
|
548
|
+
});
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
if (typeof cachedEd25519Decision === "boolean") {
|
|
552
|
+
return cachedEd25519Decision;
|
|
553
|
+
} else {
|
|
554
|
+
return await cachedEd25519Decision;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
async function assertDigestCapabilityIsAvailable() {
|
|
558
|
+
assertIsSecureContext();
|
|
559
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.digest !== "function") {
|
|
560
|
+
throw new Error("No digest implementation could be found");
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
async function assertKeyGenerationIsAvailable() {
|
|
564
|
+
assertIsSecureContext();
|
|
565
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
|
|
566
|
+
throw new Error("No key generation implementation could be found");
|
|
567
|
+
}
|
|
568
|
+
if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
|
|
569
|
+
throw new Error(
|
|
570
|
+
"This runtime does not support the generation of Ed25519 key pairs.\n\nInstall and import `@solana/webcrypto-ed25519-polyfill` before generating keys in environments that do not support Ed25519.\n\nFor a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20"
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
async function assertKeyExporterIsAvailable() {
|
|
575
|
+
assertIsSecureContext();
|
|
576
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
|
|
577
|
+
throw new Error("No key export implementation could be found");
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
async function assertSigningCapabilityIsAvailable() {
|
|
581
|
+
assertIsSecureContext();
|
|
582
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
|
|
583
|
+
throw new Error("No signing implementation could be found");
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
async function assertVerificationCapabilityIsAvailable() {
|
|
587
|
+
assertIsSecureContext();
|
|
588
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.verify !== "function") {
|
|
589
|
+
throw new Error("No signature verification implementation could be found");
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// ../addresses/dist/index.browser.js
|
|
594
|
+
var memoizedBase58Encoder;
|
|
595
|
+
var memoizedBase58Decoder;
|
|
596
|
+
function getMemoizedBase58Encoder() {
|
|
597
|
+
if (!memoizedBase58Encoder)
|
|
598
|
+
memoizedBase58Encoder = getBase58Encoder();
|
|
599
|
+
return memoizedBase58Encoder;
|
|
600
|
+
}
|
|
601
|
+
function getMemoizedBase58Decoder() {
|
|
602
|
+
if (!memoizedBase58Decoder)
|
|
603
|
+
memoizedBase58Decoder = getBase58Decoder();
|
|
604
|
+
return memoizedBase58Decoder;
|
|
605
|
+
}
|
|
606
|
+
function isAddress(putativeBase58EncodedAddress) {
|
|
607
|
+
if (
|
|
608
|
+
// Lowest address (32 bytes of zeroes)
|
|
609
|
+
putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
610
|
+
putativeBase58EncodedAddress.length > 44
|
|
611
|
+
) {
|
|
612
|
+
return false;
|
|
613
|
+
}
|
|
614
|
+
const base58Encoder3 = getMemoizedBase58Encoder();
|
|
615
|
+
const bytes = base58Encoder3.encode(putativeBase58EncodedAddress);
|
|
616
|
+
const numBytes = bytes.byteLength;
|
|
617
|
+
if (numBytes !== 32) {
|
|
618
|
+
return false;
|
|
619
|
+
}
|
|
620
|
+
return true;
|
|
621
|
+
}
|
|
622
|
+
function assertIsAddress(putativeBase58EncodedAddress) {
|
|
623
|
+
try {
|
|
624
|
+
if (
|
|
625
|
+
// Lowest address (32 bytes of zeroes)
|
|
626
|
+
putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
627
|
+
putativeBase58EncodedAddress.length > 44
|
|
628
|
+
) {
|
|
629
|
+
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
630
|
+
}
|
|
631
|
+
const base58Encoder3 = getMemoizedBase58Encoder();
|
|
632
|
+
const bytes = base58Encoder3.encode(putativeBase58EncodedAddress);
|
|
633
|
+
const numBytes = bytes.byteLength;
|
|
634
|
+
if (numBytes !== 32) {
|
|
635
|
+
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
636
|
+
}
|
|
637
|
+
} catch (e3) {
|
|
638
|
+
throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
|
|
639
|
+
cause: e3
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
function address(putativeBase58EncodedAddress) {
|
|
644
|
+
assertIsAddress(putativeBase58EncodedAddress);
|
|
645
|
+
return putativeBase58EncodedAddress;
|
|
646
|
+
}
|
|
647
|
+
function getAddressEncoder(config) {
|
|
648
|
+
return mapEncoder(
|
|
649
|
+
getStringEncoder({
|
|
650
|
+
description: config?.description ?? "Base58EncodedAddress",
|
|
651
|
+
encoding: getMemoizedBase58Encoder(),
|
|
652
|
+
size: 32
|
|
653
|
+
}),
|
|
654
|
+
(putativeAddress) => address(putativeAddress)
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
function getAddressDecoder(config) {
|
|
658
|
+
return getStringDecoder({
|
|
659
|
+
description: config?.description ?? "Base58EncodedAddress",
|
|
660
|
+
encoding: getMemoizedBase58Decoder(),
|
|
661
|
+
size: 32
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
function getAddressCodec(config) {
|
|
665
|
+
return combineCodec(getAddressEncoder(config), getAddressDecoder(config));
|
|
666
|
+
}
|
|
667
|
+
function getAddressComparator() {
|
|
668
|
+
return new Intl.Collator("en", {
|
|
669
|
+
caseFirst: "lower",
|
|
670
|
+
ignorePunctuation: false,
|
|
671
|
+
localeMatcher: "best fit",
|
|
672
|
+
numeric: false,
|
|
673
|
+
sensitivity: "variant",
|
|
674
|
+
usage: "sort"
|
|
675
|
+
}).compare;
|
|
676
|
+
}
|
|
677
|
+
var D = 37095705934669439343138083508754565189542113879843219016388785533085940283555n;
|
|
678
|
+
var P = 57896044618658097711785492504343953926634992332820282019728792003956564819949n;
|
|
679
|
+
var RM1 = 19681161376707505956807079304988542015446066515923890162744021073123829784752n;
|
|
680
|
+
function mod(a) {
|
|
681
|
+
const r = a % P;
|
|
682
|
+
return r >= 0n ? r : P + r;
|
|
683
|
+
}
|
|
684
|
+
function pow2(x, power) {
|
|
685
|
+
let r = x;
|
|
686
|
+
while (power-- > 0n) {
|
|
687
|
+
r *= r;
|
|
688
|
+
r %= P;
|
|
689
|
+
}
|
|
690
|
+
return r;
|
|
691
|
+
}
|
|
692
|
+
function pow_2_252_3(x) {
|
|
693
|
+
const x2 = x * x % P;
|
|
694
|
+
const b2 = x2 * x % P;
|
|
695
|
+
const b4 = pow2(b2, 2n) * b2 % P;
|
|
696
|
+
const b5 = pow2(b4, 1n) * x % P;
|
|
697
|
+
const b10 = pow2(b5, 5n) * b5 % P;
|
|
698
|
+
const b20 = pow2(b10, 10n) * b10 % P;
|
|
699
|
+
const b40 = pow2(b20, 20n) * b20 % P;
|
|
700
|
+
const b80 = pow2(b40, 40n) * b40 % P;
|
|
701
|
+
const b160 = pow2(b80, 80n) * b80 % P;
|
|
702
|
+
const b240 = pow2(b160, 80n) * b80 % P;
|
|
703
|
+
const b250 = pow2(b240, 10n) * b10 % P;
|
|
704
|
+
const pow_p_5_8 = pow2(b250, 2n) * x % P;
|
|
705
|
+
return pow_p_5_8;
|
|
706
|
+
}
|
|
707
|
+
function uvRatio(u, v) {
|
|
708
|
+
const v3 = mod(v * v * v);
|
|
709
|
+
const v7 = mod(v3 * v3 * v);
|
|
710
|
+
const pow = pow_2_252_3(u * v7);
|
|
711
|
+
let x = mod(u * v3 * pow);
|
|
712
|
+
const vx2 = mod(v * x * x);
|
|
713
|
+
const root1 = x;
|
|
714
|
+
const root2 = mod(x * RM1);
|
|
715
|
+
const useRoot1 = vx2 === u;
|
|
716
|
+
const useRoot2 = vx2 === mod(-u);
|
|
717
|
+
const noRoot = vx2 === mod(-u * RM1);
|
|
718
|
+
if (useRoot1)
|
|
719
|
+
x = root1;
|
|
720
|
+
if (useRoot2 || noRoot)
|
|
721
|
+
x = root2;
|
|
722
|
+
if ((mod(x) & 1n) === 1n)
|
|
723
|
+
x = mod(-x);
|
|
724
|
+
if (!useRoot1 && !useRoot2) {
|
|
725
|
+
return null;
|
|
726
|
+
}
|
|
727
|
+
return x;
|
|
728
|
+
}
|
|
729
|
+
function pointIsOnCurve(y, lastByte) {
|
|
730
|
+
const y2 = mod(y * y);
|
|
731
|
+
const u = mod(y2 - 1n);
|
|
732
|
+
const v = mod(D * y2 + 1n);
|
|
733
|
+
const x = uvRatio(u, v);
|
|
734
|
+
if (x === null) {
|
|
735
|
+
return false;
|
|
736
|
+
}
|
|
737
|
+
const isLastByteOdd = (lastByte & 128) !== 0;
|
|
738
|
+
if (x === 0n && isLastByteOdd) {
|
|
739
|
+
return false;
|
|
740
|
+
}
|
|
741
|
+
return true;
|
|
742
|
+
}
|
|
743
|
+
function byteToHex(byte) {
|
|
744
|
+
const hexString = byte.toString(16);
|
|
745
|
+
if (hexString.length === 1) {
|
|
746
|
+
return `0${hexString}`;
|
|
747
|
+
} else {
|
|
748
|
+
return hexString;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
function decompressPointBytes(bytes) {
|
|
752
|
+
const hexString = bytes.reduce((acc, byte, ii) => `${byteToHex(ii === 31 ? byte & ~128 : byte)}${acc}`, "");
|
|
753
|
+
const integerLiteralString = `0x${hexString}`;
|
|
754
|
+
return BigInt(integerLiteralString);
|
|
755
|
+
}
|
|
756
|
+
async function compressedPointBytesAreOnCurve(bytes) {
|
|
757
|
+
if (bytes.byteLength !== 32) {
|
|
758
|
+
return false;
|
|
759
|
+
}
|
|
760
|
+
const y = decompressPointBytes(bytes);
|
|
761
|
+
return pointIsOnCurve(y, bytes[31]);
|
|
762
|
+
}
|
|
763
|
+
function isProgramDerivedAddress(value) {
|
|
764
|
+
return Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && typeof value[1] === "number" && value[1] >= 0 && value[1] <= 255 && isAddress(value[0]);
|
|
765
|
+
}
|
|
766
|
+
function assertIsProgramDerivedAddress(value) {
|
|
767
|
+
const validFormat = Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && typeof value[1] === "number";
|
|
768
|
+
if (!validFormat) {
|
|
769
|
+
throw new Error(
|
|
770
|
+
`Expected given program derived address to have the following format: [Base58EncodedAddress, ProgramDerivedAddressBump].`
|
|
771
|
+
);
|
|
772
|
+
}
|
|
773
|
+
if (value[1] < 0 || value[1] > 255) {
|
|
774
|
+
throw new Error(`Expected program derived address bump to be in the range [0, 255], got: ${value[1]}.`);
|
|
775
|
+
}
|
|
776
|
+
assertIsAddress(value[0]);
|
|
777
|
+
}
|
|
778
|
+
var MAX_SEED_LENGTH = 32;
|
|
779
|
+
var MAX_SEEDS = 16;
|
|
780
|
+
var PDA_MARKER_BYTES = [
|
|
781
|
+
// The string 'ProgramDerivedAddress'
|
|
782
|
+
80,
|
|
783
|
+
114,
|
|
784
|
+
111,
|
|
785
|
+
103,
|
|
786
|
+
114,
|
|
787
|
+
97,
|
|
788
|
+
109,
|
|
789
|
+
68,
|
|
790
|
+
101,
|
|
791
|
+
114,
|
|
792
|
+
105,
|
|
793
|
+
118,
|
|
794
|
+
101,
|
|
795
|
+
100,
|
|
796
|
+
65,
|
|
797
|
+
100,
|
|
798
|
+
100,
|
|
799
|
+
114,
|
|
800
|
+
101,
|
|
801
|
+
115,
|
|
802
|
+
115
|
|
803
|
+
];
|
|
804
|
+
var PointOnCurveError = class extends Error {
|
|
805
|
+
};
|
|
806
|
+
async function createProgramDerivedAddress({
|
|
807
|
+
programAddress,
|
|
808
|
+
seeds
|
|
809
|
+
}) {
|
|
810
|
+
await assertDigestCapabilityIsAvailable();
|
|
811
|
+
if (seeds.length > MAX_SEEDS) {
|
|
812
|
+
throw new Error(`A maximum of ${MAX_SEEDS} seeds may be supplied when creating an address`);
|
|
813
|
+
}
|
|
814
|
+
let textEncoder;
|
|
815
|
+
const seedBytes = seeds.reduce((acc, seed, ii) => {
|
|
816
|
+
const bytes = typeof seed === "string" ? (textEncoder || (textEncoder = new TextEncoder())).encode(seed) : seed;
|
|
817
|
+
if (bytes.byteLength > MAX_SEED_LENGTH) {
|
|
818
|
+
throw new Error(`The seed at index ${ii} exceeds the maximum length of 32 bytes`);
|
|
819
|
+
}
|
|
820
|
+
acc.push(...bytes);
|
|
821
|
+
return acc;
|
|
822
|
+
}, []);
|
|
823
|
+
const base58EncodedAddressCodec = getAddressCodec();
|
|
824
|
+
const programAddressBytes = base58EncodedAddressCodec.encode(programAddress);
|
|
825
|
+
const addressBytesBuffer = await crypto.subtle.digest(
|
|
826
|
+
"SHA-256",
|
|
827
|
+
new Uint8Array([...seedBytes, ...programAddressBytes, ...PDA_MARKER_BYTES])
|
|
828
|
+
);
|
|
829
|
+
const addressBytes = new Uint8Array(addressBytesBuffer);
|
|
830
|
+
if (await compressedPointBytesAreOnCurve(addressBytes)) {
|
|
831
|
+
throw new PointOnCurveError("Invalid seeds; point must fall off the Ed25519 curve");
|
|
832
|
+
}
|
|
833
|
+
return base58EncodedAddressCodec.decode(addressBytes)[0];
|
|
834
|
+
}
|
|
835
|
+
async function getProgramDerivedAddress({
|
|
836
|
+
programAddress,
|
|
837
|
+
seeds
|
|
838
|
+
}) {
|
|
839
|
+
let bumpSeed = 255;
|
|
840
|
+
while (bumpSeed > 0) {
|
|
841
|
+
try {
|
|
842
|
+
const address2 = await createProgramDerivedAddress({
|
|
843
|
+
programAddress,
|
|
844
|
+
seeds: [...seeds, new Uint8Array([bumpSeed])]
|
|
845
|
+
});
|
|
846
|
+
return [address2, bumpSeed];
|
|
847
|
+
} catch (e3) {
|
|
848
|
+
if (e3 instanceof PointOnCurveError) {
|
|
849
|
+
bumpSeed--;
|
|
850
|
+
} else {
|
|
851
|
+
throw e3;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
throw new Error("Unable to find a viable program address bump seed");
|
|
856
|
+
}
|
|
857
|
+
async function createAddressWithSeed({
|
|
858
|
+
baseAddress,
|
|
859
|
+
programAddress,
|
|
860
|
+
seed
|
|
861
|
+
}) {
|
|
862
|
+
const { encode: encode2, decode: decode2 } = getAddressCodec();
|
|
863
|
+
const seedBytes = typeof seed === "string" ? new TextEncoder().encode(seed) : seed;
|
|
864
|
+
if (seedBytes.byteLength > MAX_SEED_LENGTH) {
|
|
865
|
+
throw new Error(`The seed exceeds the maximum length of 32 bytes`);
|
|
866
|
+
}
|
|
867
|
+
const programAddressBytes = encode2(programAddress);
|
|
868
|
+
if (programAddressBytes.length >= PDA_MARKER_BYTES.length && programAddressBytes.slice(-PDA_MARKER_BYTES.length).every((byte, index) => byte === PDA_MARKER_BYTES[index])) {
|
|
869
|
+
throw new Error(`programAddress cannot end with the PDA marker`);
|
|
870
|
+
}
|
|
871
|
+
const addressBytesBuffer = await crypto.subtle.digest(
|
|
872
|
+
"SHA-256",
|
|
873
|
+
new Uint8Array([...encode2(baseAddress), ...seedBytes, ...programAddressBytes])
|
|
874
|
+
);
|
|
875
|
+
const addressBytes = new Uint8Array(addressBytesBuffer);
|
|
876
|
+
return decode2(addressBytes)[0];
|
|
877
|
+
}
|
|
878
|
+
async function getAddressFromPublicKey(publicKey) {
|
|
879
|
+
await assertKeyExporterIsAvailable();
|
|
880
|
+
if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
|
|
881
|
+
throw new Error("The `CryptoKey` must be an `Ed25519` public key");
|
|
882
|
+
}
|
|
883
|
+
const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
|
|
884
|
+
const [base58EncodedAddress] = getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
|
|
885
|
+
return base58EncodedAddress;
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
// ../instructions/dist/index.browser.js
|
|
889
|
+
init_env_shim();
|
|
890
|
+
var AccountRole = /* @__PURE__ */ ((AccountRole22) => {
|
|
891
|
+
AccountRole22[AccountRole22["WRITABLE_SIGNER"] = /* 3 */
|
|
892
|
+
3] = "WRITABLE_SIGNER";
|
|
893
|
+
AccountRole22[AccountRole22["READONLY_SIGNER"] = /* 2 */
|
|
894
|
+
2] = "READONLY_SIGNER";
|
|
895
|
+
AccountRole22[AccountRole22["WRITABLE"] = /* 1 */
|
|
896
|
+
1] = "WRITABLE";
|
|
897
|
+
AccountRole22[AccountRole22["READONLY"] = /* 0 */
|
|
898
|
+
0] = "READONLY";
|
|
899
|
+
return AccountRole22;
|
|
900
|
+
})(AccountRole || {});
|
|
901
|
+
var IS_SIGNER_BITMASK = 2;
|
|
902
|
+
var IS_WRITABLE_BITMASK = 1;
|
|
903
|
+
function downgradeRoleToNonSigner(role) {
|
|
904
|
+
return role & ~IS_SIGNER_BITMASK;
|
|
905
|
+
}
|
|
906
|
+
function downgradeRoleToReadonly(role) {
|
|
907
|
+
return role & ~IS_WRITABLE_BITMASK;
|
|
908
|
+
}
|
|
909
|
+
function isSignerRole(role) {
|
|
910
|
+
return role >= 2;
|
|
911
|
+
}
|
|
912
|
+
function isWritableRole(role) {
|
|
913
|
+
return (role & IS_WRITABLE_BITMASK) !== 0;
|
|
914
|
+
}
|
|
915
|
+
function mergeRoles(roleA, roleB) {
|
|
916
|
+
return roleA | roleB;
|
|
917
|
+
}
|
|
918
|
+
function upgradeRoleToSigner(role) {
|
|
919
|
+
return role | IS_SIGNER_BITMASK;
|
|
920
|
+
}
|
|
921
|
+
function upgradeRoleToWritable(role) {
|
|
922
|
+
return role | IS_WRITABLE_BITMASK;
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
// ../keys/dist/index.browser.js
|
|
926
|
+
init_env_shim();
|
|
927
|
+
async function generateKeyPair() {
|
|
928
|
+
await assertKeyGenerationIsAvailable();
|
|
929
|
+
const keyPair = await crypto.subtle.generateKey(
|
|
930
|
+
/* algorithm */
|
|
931
|
+
"Ed25519",
|
|
932
|
+
// Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
|
|
933
|
+
/* extractable */
|
|
934
|
+
false,
|
|
935
|
+
// Prevents the bytes of the private key from being visible to JS.
|
|
936
|
+
/* allowed uses */
|
|
937
|
+
["sign", "verify"]
|
|
938
|
+
);
|
|
939
|
+
return keyPair;
|
|
940
|
+
}
|
|
941
|
+
async function signBytes(key, data) {
|
|
942
|
+
await assertSigningCapabilityIsAvailable();
|
|
943
|
+
const signedData = await crypto.subtle.sign("Ed25519", key, data);
|
|
944
|
+
return new Uint8Array(signedData);
|
|
945
|
+
}
|
|
946
|
+
async function verifySignature(key, signature, data) {
|
|
947
|
+
await assertVerificationCapabilityIsAvailable();
|
|
948
|
+
return await crypto.subtle.verify("Ed25519", key, signature, data);
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
// ../rpc-types/dist/index.browser.js
|
|
952
|
+
init_env_shim();
|
|
953
|
+
function getCommitmentScore(commitment) {
|
|
954
|
+
switch (commitment) {
|
|
955
|
+
case "finalized":
|
|
956
|
+
return 2;
|
|
957
|
+
case "confirmed":
|
|
958
|
+
return 1;
|
|
959
|
+
case "processed":
|
|
960
|
+
return 0;
|
|
961
|
+
default:
|
|
962
|
+
return ((_) => {
|
|
963
|
+
throw new Error(`Unrecognized commitment \`${commitment}\`.`);
|
|
964
|
+
})();
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
function commitmentComparator(a, b) {
|
|
968
|
+
if (a === b) {
|
|
969
|
+
return 0;
|
|
970
|
+
}
|
|
971
|
+
return getCommitmentScore(a) < getCommitmentScore(b) ? -1 : 1;
|
|
972
|
+
}
|
|
973
|
+
var maxU64Value = 18446744073709551615n;
|
|
974
|
+
function isLamports(putativeLamports) {
|
|
975
|
+
return putativeLamports >= 0 && putativeLamports <= maxU64Value;
|
|
976
|
+
}
|
|
977
|
+
function assertIsLamports(putativeLamports) {
|
|
978
|
+
if (putativeLamports < 0) {
|
|
979
|
+
throw new Error("Input for 64-bit unsigned integer cannot be negative");
|
|
980
|
+
}
|
|
981
|
+
if (putativeLamports > maxU64Value) {
|
|
982
|
+
throw new Error("Input number is too large to be represented as a 64-bit unsigned integer");
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
function lamports(putativeLamports) {
|
|
986
|
+
assertIsLamports(putativeLamports);
|
|
987
|
+
return putativeLamports;
|
|
988
|
+
}
|
|
989
|
+
function isStringifiedBigInt(putativeBigInt) {
|
|
990
|
+
try {
|
|
991
|
+
BigInt(putativeBigInt);
|
|
992
|
+
return true;
|
|
993
|
+
} catch (_) {
|
|
994
|
+
return false;
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
function assertIsStringifiedBigInt(putativeBigInt) {
|
|
998
|
+
try {
|
|
999
|
+
BigInt(putativeBigInt);
|
|
1000
|
+
} catch (e3) {
|
|
1001
|
+
throw new Error(`\`${putativeBigInt}\` cannot be parsed as a BigInt`, {
|
|
1002
|
+
cause: e3
|
|
1003
|
+
});
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
function stringifiedBigInt(putativeBigInt) {
|
|
1007
|
+
assertIsStringifiedBigInt(putativeBigInt);
|
|
1008
|
+
return putativeBigInt;
|
|
1009
|
+
}
|
|
1010
|
+
function isStringifiedNumber(putativeNumber) {
|
|
1011
|
+
return !Number.isNaN(Number(putativeNumber));
|
|
1012
|
+
}
|
|
1013
|
+
function assertIsStringifiedNumber(putativeNumber) {
|
|
1014
|
+
if (Number.isNaN(Number(putativeNumber))) {
|
|
1015
|
+
throw new Error(`\`${putativeNumber}\` cannot be parsed as a Number`);
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
function stringifiedNumber(putativeNumber) {
|
|
1019
|
+
assertIsStringifiedNumber(putativeNumber);
|
|
1020
|
+
return putativeNumber;
|
|
1021
|
+
}
|
|
1022
|
+
function isUnixTimestamp(putativeTimestamp) {
|
|
1023
|
+
if (putativeTimestamp > 864e13 || putativeTimestamp < -864e13) {
|
|
1024
|
+
return false;
|
|
1025
|
+
}
|
|
1026
|
+
return true;
|
|
1027
|
+
}
|
|
1028
|
+
function assertIsUnixTimestamp(putativeTimestamp) {
|
|
1029
|
+
try {
|
|
1030
|
+
if (putativeTimestamp > 864e13 || putativeTimestamp < -864e13) {
|
|
1031
|
+
throw new Error("Expected input number to be in the range [-8.64e15, 8.64e15]");
|
|
1032
|
+
}
|
|
1033
|
+
} catch (e3) {
|
|
1034
|
+
throw new Error(`\`${putativeTimestamp}\` is not a timestamp`, {
|
|
1035
|
+
cause: e3
|
|
1036
|
+
});
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
function unixTimestamp(putativeTimestamp) {
|
|
1040
|
+
assertIsUnixTimestamp(putativeTimestamp);
|
|
1041
|
+
return putativeTimestamp;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
// ../transactions/dist/index.browser.js
|
|
1045
|
+
init_env_shim();
|
|
1046
|
+
|
|
1047
|
+
// ../codecs-data-structures/dist/index.browser.js
|
|
1048
|
+
init_env_shim();
|
|
1049
|
+
function sumCodecSizes(sizes) {
|
|
1050
|
+
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
|
|
1051
|
+
}
|
|
1052
|
+
function decodeArrayLikeCodecSize(size, childrenSizes, bytes, offset) {
|
|
1053
|
+
if (typeof size === "number") {
|
|
1054
|
+
return [size, offset];
|
|
1055
|
+
}
|
|
1056
|
+
if (typeof size === "object") {
|
|
1057
|
+
return size.decode(bytes, offset);
|
|
1058
|
+
}
|
|
1059
|
+
if (size === "remainder") {
|
|
1060
|
+
const childrenSize = sumCodecSizes(childrenSizes);
|
|
1061
|
+
if (childrenSize === null) {
|
|
1062
|
+
throw new Error('Codecs of "remainder" size must have fixed-size items.');
|
|
1063
|
+
}
|
|
1064
|
+
const remainder = bytes.slice(offset).length;
|
|
1065
|
+
if (remainder % childrenSize !== 0) {
|
|
1066
|
+
throw new Error(
|
|
1067
|
+
`The remainder of the byte array (${remainder} bytes) cannot be split into chunks of ${childrenSize} bytes. Codecs of "remainder" size must have a remainder that is a multiple of its item size. In other words, ${remainder} modulo ${childrenSize} should be equal to zero.`
|
|
1068
|
+
);
|
|
1069
|
+
}
|
|
1070
|
+
return [remainder / childrenSize, offset];
|
|
1071
|
+
}
|
|
1072
|
+
throw new Error(`Unrecognized array-like codec size: ${JSON.stringify(size)}`);
|
|
1073
|
+
}
|
|
1074
|
+
function getArrayLikeCodecSizeDescription(size) {
|
|
1075
|
+
return typeof size === "object" ? size.description : `${size}`;
|
|
1076
|
+
}
|
|
1077
|
+
function getArrayLikeCodecSizeFromChildren(size, childrenSizes) {
|
|
1078
|
+
if (typeof size !== "number")
|
|
1079
|
+
return null;
|
|
1080
|
+
if (size === 0)
|
|
1081
|
+
return 0;
|
|
1082
|
+
const childrenSize = sumCodecSizes(childrenSizes);
|
|
1083
|
+
return childrenSize === null ? null : childrenSize * size;
|
|
1084
|
+
}
|
|
1085
|
+
function getArrayLikeCodecSizePrefix(size, realSize) {
|
|
1086
|
+
return typeof size === "object" ? size.encode(realSize) : new Uint8Array();
|
|
1087
|
+
}
|
|
1088
|
+
function assertValidNumberOfItemsForCodec(codecDescription, expected, actual) {
|
|
1089
|
+
if (expected !== actual) {
|
|
1090
|
+
throw new Error(`Expected [${codecDescription}] to have ${expected} items, got ${actual}.`);
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
function arrayCodecHelper(item, size, description) {
|
|
1094
|
+
if (size === "remainder" && item.fixedSize === null) {
|
|
1095
|
+
throw new Error('Codecs of "remainder" size must have fixed-size items.');
|
|
1096
|
+
}
|
|
1097
|
+
return {
|
|
1098
|
+
description: description ?? `array(${item.description}; ${getArrayLikeCodecSizeDescription(size)})`,
|
|
1099
|
+
fixedSize: getArrayLikeCodecSizeFromChildren(size, [item.fixedSize]),
|
|
1100
|
+
maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
function getArrayEncoder(item, options = {}) {
|
|
1104
|
+
const size = options.size ?? getU32Encoder();
|
|
1105
|
+
return {
|
|
1106
|
+
...arrayCodecHelper(item, size, options.description),
|
|
1107
|
+
encode: (value) => {
|
|
1108
|
+
if (typeof size === "number") {
|
|
1109
|
+
assertValidNumberOfItemsForCodec("array", size, value.length);
|
|
1110
|
+
}
|
|
1111
|
+
return mergeBytes([getArrayLikeCodecSizePrefix(size, value.length), ...value.map((v) => item.encode(v))]);
|
|
1112
|
+
}
|
|
1113
|
+
};
|
|
1114
|
+
}
|
|
1115
|
+
function getArrayDecoder(item, options = {}) {
|
|
1116
|
+
const size = options.size ?? getU32Decoder();
|
|
1117
|
+
return {
|
|
1118
|
+
...arrayCodecHelper(item, size, options.description),
|
|
1119
|
+
decode: (bytes, offset = 0) => {
|
|
1120
|
+
if (typeof size === "object" && bytes.slice(offset).length === 0) {
|
|
1121
|
+
return [[], offset];
|
|
1122
|
+
}
|
|
1123
|
+
const [resolvedSize, newOffset] = decodeArrayLikeCodecSize(size, [item.fixedSize], bytes, offset);
|
|
1124
|
+
offset = newOffset;
|
|
1125
|
+
const values = [];
|
|
1126
|
+
for (let i = 0; i < resolvedSize; i += 1) {
|
|
1127
|
+
const [value, newOffset2] = item.decode(bytes, offset);
|
|
1128
|
+
values.push(value);
|
|
1129
|
+
offset = newOffset2;
|
|
1130
|
+
}
|
|
1131
|
+
return [values, offset];
|
|
1132
|
+
}
|
|
1133
|
+
};
|
|
1134
|
+
}
|
|
1135
|
+
function getBytesEncoder(options = {}) {
|
|
1136
|
+
const size = options.size ?? "variable";
|
|
1137
|
+
const sizeDescription = typeof size === "object" ? size.description : `${size}`;
|
|
1138
|
+
const description = options.description ?? `bytes(${sizeDescription})`;
|
|
1139
|
+
const byteEncoder = {
|
|
1140
|
+
description,
|
|
1141
|
+
encode: (value) => value,
|
|
1142
|
+
fixedSize: null,
|
|
1143
|
+
maxSize: null
|
|
1144
|
+
};
|
|
1145
|
+
if (size === "variable") {
|
|
1146
|
+
return byteEncoder;
|
|
1147
|
+
}
|
|
1148
|
+
if (typeof size === "number") {
|
|
1149
|
+
return fixEncoder(byteEncoder, size, description);
|
|
1150
|
+
}
|
|
1151
|
+
return {
|
|
1152
|
+
...byteEncoder,
|
|
1153
|
+
encode: (value) => {
|
|
1154
|
+
const contentBytes = byteEncoder.encode(value);
|
|
1155
|
+
const lengthBytes = size.encode(contentBytes.length);
|
|
1156
|
+
return mergeBytes([lengthBytes, contentBytes]);
|
|
1157
|
+
}
|
|
1158
|
+
};
|
|
1159
|
+
}
|
|
1160
|
+
function getBytesDecoder(options = {}) {
|
|
1161
|
+
const size = options.size ?? "variable";
|
|
1162
|
+
const sizeDescription = typeof size === "object" ? size.description : `${size}`;
|
|
1163
|
+
const description = options.description ?? `bytes(${sizeDescription})`;
|
|
1164
|
+
const byteDecoder = {
|
|
1165
|
+
decode: (bytes, offset = 0) => {
|
|
1166
|
+
const slice = bytes.slice(offset);
|
|
1167
|
+
return [slice, offset + slice.length];
|
|
1168
|
+
},
|
|
1169
|
+
description,
|
|
1170
|
+
fixedSize: null,
|
|
1171
|
+
maxSize: null
|
|
1172
|
+
};
|
|
1173
|
+
if (size === "variable") {
|
|
1174
|
+
return byteDecoder;
|
|
1175
|
+
}
|
|
1176
|
+
if (typeof size === "number") {
|
|
1177
|
+
return fixDecoder(byteDecoder, size, description);
|
|
1178
|
+
}
|
|
1179
|
+
return {
|
|
1180
|
+
...byteDecoder,
|
|
1181
|
+
decode: (bytes, offset = 0) => {
|
|
1182
|
+
assertByteArrayIsNotEmptyForCodec("bytes", bytes, offset);
|
|
1183
|
+
const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
|
|
1184
|
+
const length = Number(lengthBigInt);
|
|
1185
|
+
offset = lengthOffset;
|
|
1186
|
+
const contentBytes = bytes.slice(offset, offset + length);
|
|
1187
|
+
assertByteArrayHasEnoughBytesForCodec("bytes", length, contentBytes);
|
|
1188
|
+
const [value, contentOffset] = byteDecoder.decode(contentBytes);
|
|
1189
|
+
offset += contentOffset;
|
|
1190
|
+
return [value, offset];
|
|
1191
|
+
}
|
|
1192
|
+
};
|
|
1193
|
+
}
|
|
1194
|
+
function structCodecHelper(fields, description) {
|
|
1195
|
+
const fieldDescriptions = fields.map(([name, codec]) => `${String(name)}: ${codec.description}`).join(", ");
|
|
1196
|
+
return {
|
|
1197
|
+
description: description ?? `struct(${fieldDescriptions})`,
|
|
1198
|
+
fixedSize: sumCodecSizes(fields.map(([, field]) => field.fixedSize)),
|
|
1199
|
+
maxSize: sumCodecSizes(fields.map(([, field]) => field.maxSize))
|
|
1200
|
+
};
|
|
1201
|
+
}
|
|
1202
|
+
function getStructEncoder(fields, options = {}) {
|
|
1203
|
+
return {
|
|
1204
|
+
...structCodecHelper(fields, options.description),
|
|
1205
|
+
encode: (struct) => {
|
|
1206
|
+
const fieldBytes = fields.map(([key, codec]) => codec.encode(struct[key]));
|
|
1207
|
+
return mergeBytes(fieldBytes);
|
|
1208
|
+
}
|
|
1209
|
+
};
|
|
1210
|
+
}
|
|
1211
|
+
function getStructDecoder(fields, options = {}) {
|
|
1212
|
+
return {
|
|
1213
|
+
...structCodecHelper(fields, options.description),
|
|
1214
|
+
decode: (bytes, offset = 0) => {
|
|
1215
|
+
const struct = {};
|
|
1216
|
+
fields.forEach(([key, codec]) => {
|
|
1217
|
+
const [value, newOffset] = codec.decode(bytes, offset);
|
|
1218
|
+
offset = newOffset;
|
|
1219
|
+
struct[key] = value;
|
|
1220
|
+
});
|
|
1221
|
+
return [struct, offset];
|
|
1222
|
+
}
|
|
1223
|
+
};
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
// ../functional/dist/index.browser.js
|
|
1227
|
+
init_env_shim();
|
|
1228
|
+
function pipe(init, ...fns) {
|
|
1229
|
+
return fns.reduce((acc, fn) => fn(acc), init);
|
|
1230
|
+
}
|
|
1231
|
+
function getUnsignedTransaction(transaction) {
|
|
1232
|
+
if ("signatures" in transaction) {
|
|
1233
|
+
const {
|
|
1234
|
+
signatures: _,
|
|
1235
|
+
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
1236
|
+
...unsignedTransaction
|
|
1237
|
+
} = transaction;
|
|
1238
|
+
return unsignedTransaction;
|
|
1239
|
+
} else {
|
|
1240
|
+
return transaction;
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
var base58Encoder;
|
|
1244
|
+
function assertIsBlockhash(putativeBlockhash) {
|
|
1245
|
+
if (!base58Encoder)
|
|
1246
|
+
base58Encoder = getBase58Encoder();
|
|
1247
|
+
try {
|
|
1248
|
+
if (
|
|
1249
|
+
// Lowest value (32 bytes of zeroes)
|
|
1250
|
+
putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
|
|
1251
|
+
putativeBlockhash.length > 44
|
|
1252
|
+
) {
|
|
1253
|
+
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
1254
|
+
}
|
|
1255
|
+
const bytes = base58Encoder.encode(putativeBlockhash);
|
|
1256
|
+
const numBytes = bytes.byteLength;
|
|
1257
|
+
if (numBytes !== 32) {
|
|
1258
|
+
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
1259
|
+
}
|
|
1260
|
+
} catch (e3) {
|
|
1261
|
+
throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
|
|
1262
|
+
cause: e3
|
|
1263
|
+
});
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
|
|
1267
|
+
if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
|
|
1268
|
+
return transaction;
|
|
1269
|
+
}
|
|
1270
|
+
const out = {
|
|
1271
|
+
...getUnsignedTransaction(transaction),
|
|
1272
|
+
lifetimeConstraint: blockhashLifetimeConstraint
|
|
1273
|
+
};
|
|
1274
|
+
Object.freeze(out);
|
|
1275
|
+
return out;
|
|
1276
|
+
}
|
|
1277
|
+
function createTransaction({
|
|
1278
|
+
version
|
|
1279
|
+
}) {
|
|
1280
|
+
const out = {
|
|
1281
|
+
instructions: [],
|
|
1282
|
+
version
|
|
1283
|
+
};
|
|
1284
|
+
Object.freeze(out);
|
|
1285
|
+
return out;
|
|
1286
|
+
}
|
|
1287
|
+
var AccountRole2 = /* @__PURE__ */ ((AccountRole22) => {
|
|
1288
|
+
AccountRole22[AccountRole22["WRITABLE_SIGNER"] = /* 3 */
|
|
1289
|
+
3] = "WRITABLE_SIGNER";
|
|
1290
|
+
AccountRole22[AccountRole22["READONLY_SIGNER"] = /* 2 */
|
|
1291
|
+
2] = "READONLY_SIGNER";
|
|
1292
|
+
AccountRole22[AccountRole22["WRITABLE"] = /* 1 */
|
|
1293
|
+
1] = "WRITABLE";
|
|
1294
|
+
AccountRole22[AccountRole22["READONLY"] = /* 0 */
|
|
1295
|
+
0] = "READONLY";
|
|
1296
|
+
return AccountRole22;
|
|
1297
|
+
})(AccountRole2 || {});
|
|
1298
|
+
var IS_WRITABLE_BITMASK2 = 1;
|
|
1299
|
+
function isSignerRole2(role) {
|
|
1300
|
+
return role >= 2;
|
|
1301
|
+
}
|
|
1302
|
+
function isWritableRole2(role) {
|
|
1303
|
+
return (role & IS_WRITABLE_BITMASK2) !== 0;
|
|
1304
|
+
}
|
|
1305
|
+
function mergeRoles2(roleA, roleB) {
|
|
1306
|
+
return roleA | roleB;
|
|
1307
|
+
}
|
|
1308
|
+
var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
|
|
1309
|
+
var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
|
|
1310
|
+
function assertIsDurableNonceTransaction(transaction) {
|
|
1311
|
+
if (!isDurableNonceTransaction(transaction)) {
|
|
1312
|
+
throw new Error("Transaction is not a durable nonce transaction");
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
|
|
1316
|
+
return {
|
|
1317
|
+
accounts: [
|
|
1318
|
+
{ address: nonceAccountAddress, role: AccountRole2.WRITABLE },
|
|
1319
|
+
{
|
|
1320
|
+
address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS,
|
|
1321
|
+
role: AccountRole2.READONLY
|
|
1322
|
+
},
|
|
1323
|
+
{ address: nonceAuthorityAddress, role: AccountRole2.READONLY_SIGNER }
|
|
1324
|
+
],
|
|
1325
|
+
data: new Uint8Array([4, 0, 0, 0]),
|
|
1326
|
+
programAddress: SYSTEM_PROGRAM_ADDRESS
|
|
1327
|
+
};
|
|
1328
|
+
}
|
|
1329
|
+
function isAdvanceNonceAccountInstruction(instruction) {
|
|
1330
|
+
return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
|
|
1331
|
+
instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
|
|
1332
|
+
instruction.accounts?.length === 3 && // First account is nonce account address
|
|
1333
|
+
instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole2.WRITABLE && // Second account is recent blockhashes sysvar
|
|
1334
|
+
instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole2.READONLY && // Third account is nonce authority account
|
|
1335
|
+
instruction.accounts[2].address != null && isSignerRole2(instruction.accounts[2].role);
|
|
1336
|
+
}
|
|
1337
|
+
function isAdvanceNonceAccountInstructionData(data) {
|
|
1338
|
+
return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
|
|
1339
|
+
}
|
|
1340
|
+
function isDurableNonceTransaction(transaction) {
|
|
1341
|
+
return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
|
|
1342
|
+
}
|
|
1343
|
+
function isAdvanceNonceAccountInstructionForNonce(instruction, nonceAccountAddress, nonceAuthorityAddress) {
|
|
1344
|
+
return instruction.accounts[0].address === nonceAccountAddress && instruction.accounts[2].address === nonceAuthorityAddress;
|
|
1345
|
+
}
|
|
1346
|
+
function setTransactionLifetimeUsingDurableNonce({
|
|
1347
|
+
nonce,
|
|
1348
|
+
nonceAccountAddress,
|
|
1349
|
+
nonceAuthorityAddress
|
|
1350
|
+
}, transaction) {
|
|
1351
|
+
let newInstructions;
|
|
1352
|
+
const firstInstruction = transaction.instructions[0];
|
|
1353
|
+
if (firstInstruction && isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
1354
|
+
if (isAdvanceNonceAccountInstructionForNonce(firstInstruction, nonceAccountAddress, nonceAuthorityAddress)) {
|
|
1355
|
+
if (isDurableNonceTransaction(transaction) && transaction.lifetimeConstraint.nonce === nonce) {
|
|
1356
|
+
return transaction;
|
|
1357
|
+
} else {
|
|
1358
|
+
newInstructions = [firstInstruction, ...transaction.instructions.slice(1)];
|
|
1359
|
+
}
|
|
1360
|
+
} else {
|
|
1361
|
+
newInstructions = [
|
|
1362
|
+
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
1363
|
+
...transaction.instructions.slice(1)
|
|
1364
|
+
];
|
|
1365
|
+
}
|
|
1366
|
+
} else {
|
|
1367
|
+
newInstructions = [
|
|
1368
|
+
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
1369
|
+
...transaction.instructions
|
|
1370
|
+
];
|
|
1371
|
+
}
|
|
1372
|
+
const out = {
|
|
1373
|
+
...getUnsignedTransaction(transaction),
|
|
1374
|
+
instructions: newInstructions,
|
|
1375
|
+
lifetimeConstraint: {
|
|
1376
|
+
nonce
|
|
1377
|
+
}
|
|
1378
|
+
};
|
|
1379
|
+
Object.freeze(out);
|
|
1380
|
+
return out;
|
|
1381
|
+
}
|
|
1382
|
+
function setTransactionFeePayer(feePayer, transaction) {
|
|
1383
|
+
if ("feePayer" in transaction && feePayer === transaction.feePayer) {
|
|
1384
|
+
return transaction;
|
|
1385
|
+
}
|
|
1386
|
+
const out = {
|
|
1387
|
+
...getUnsignedTransaction(transaction),
|
|
1388
|
+
feePayer
|
|
1389
|
+
};
|
|
1390
|
+
Object.freeze(out);
|
|
1391
|
+
return out;
|
|
1392
|
+
}
|
|
1393
|
+
function appendTransactionInstruction(instruction, transaction) {
|
|
1394
|
+
const out = {
|
|
1395
|
+
...getUnsignedTransaction(transaction),
|
|
1396
|
+
instructions: [...transaction.instructions, instruction]
|
|
1397
|
+
};
|
|
1398
|
+
Object.freeze(out);
|
|
1399
|
+
return out;
|
|
1400
|
+
}
|
|
1401
|
+
function prependTransactionInstruction(instruction, transaction) {
|
|
1402
|
+
const out = {
|
|
1403
|
+
...getUnsignedTransaction(transaction),
|
|
1404
|
+
instructions: [instruction, ...transaction.instructions]
|
|
1405
|
+
};
|
|
1406
|
+
Object.freeze(out);
|
|
1407
|
+
return out;
|
|
1408
|
+
}
|
|
1409
|
+
function upsert(addressMap, address2, update) {
|
|
1410
|
+
addressMap[address2] = update(addressMap[address2] ?? { role: AccountRole2.READONLY });
|
|
1411
|
+
}
|
|
1412
|
+
var TYPE = Symbol("AddressMapTypeProperty");
|
|
1413
|
+
function getAddressMapFromInstructions(feePayer, instructions) {
|
|
1414
|
+
const addressMap = {
|
|
1415
|
+
[feePayer]: { [TYPE]: 0, role: AccountRole2.WRITABLE_SIGNER }
|
|
1416
|
+
};
|
|
1417
|
+
const addressesOfInvokedPrograms = /* @__PURE__ */ new Set();
|
|
1418
|
+
for (const instruction of instructions) {
|
|
1419
|
+
upsert(addressMap, instruction.programAddress, (entry) => {
|
|
1420
|
+
addressesOfInvokedPrograms.add(instruction.programAddress);
|
|
1421
|
+
if (TYPE in entry) {
|
|
1422
|
+
if (isWritableRole2(entry.role)) {
|
|
1423
|
+
switch (entry[TYPE]) {
|
|
1424
|
+
case 0:
|
|
1425
|
+
throw new Error(
|
|
1426
|
+
`This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and set as the fee payer. Program addresses may not pay fees.`
|
|
1427
|
+
);
|
|
1428
|
+
default:
|
|
1429
|
+
throw new Error(
|
|
1430
|
+
`This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and marked writable. Program addresses may not be writable.`
|
|
1431
|
+
);
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
if (entry[TYPE] === 2) {
|
|
1435
|
+
return entry;
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
return { [TYPE]: 2, role: AccountRole2.READONLY };
|
|
1439
|
+
});
|
|
1440
|
+
let addressComparator;
|
|
1441
|
+
if (!instruction.accounts) {
|
|
1442
|
+
continue;
|
|
1443
|
+
}
|
|
1444
|
+
for (const account of instruction.accounts) {
|
|
1445
|
+
upsert(addressMap, account.address, (entry) => {
|
|
1446
|
+
const {
|
|
1447
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1448
|
+
address: _,
|
|
1449
|
+
...accountMeta
|
|
1450
|
+
} = account;
|
|
1451
|
+
if (TYPE in entry) {
|
|
1452
|
+
switch (entry[TYPE]) {
|
|
1453
|
+
case 0:
|
|
1454
|
+
return entry;
|
|
1455
|
+
case 1: {
|
|
1456
|
+
const nextRole = mergeRoles2(entry.role, accountMeta.role);
|
|
1457
|
+
if ("lookupTableAddress" in accountMeta) {
|
|
1458
|
+
const shouldReplaceEntry = (
|
|
1459
|
+
// Consider using the new LOOKUP_TABLE if its address is different...
|
|
1460
|
+
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
|
|
1461
|
+
(addressComparator || (addressComparator = getAddressComparator()))(
|
|
1462
|
+
accountMeta.lookupTableAddress,
|
|
1463
|
+
entry.lookupTableAddress
|
|
1464
|
+
) < 0
|
|
1465
|
+
);
|
|
1466
|
+
if (shouldReplaceEntry) {
|
|
1467
|
+
return {
|
|
1468
|
+
[TYPE]: 1,
|
|
1469
|
+
...accountMeta,
|
|
1470
|
+
role: nextRole
|
|
1471
|
+
};
|
|
1472
|
+
}
|
|
1473
|
+
} else if (isSignerRole2(accountMeta.role)) {
|
|
1474
|
+
return {
|
|
1475
|
+
[TYPE]: 2,
|
|
1476
|
+
role: nextRole
|
|
1477
|
+
};
|
|
1478
|
+
}
|
|
1479
|
+
if (entry.role !== nextRole) {
|
|
1480
|
+
return {
|
|
1481
|
+
...entry,
|
|
1482
|
+
role: nextRole
|
|
1483
|
+
};
|
|
1484
|
+
} else {
|
|
1485
|
+
return entry;
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
case 2: {
|
|
1489
|
+
const nextRole = mergeRoles2(entry.role, accountMeta.role);
|
|
1490
|
+
if (
|
|
1491
|
+
// Check to see if this address represents a program that is invoked
|
|
1492
|
+
// in this transaction.
|
|
1493
|
+
addressesOfInvokedPrograms.has(account.address)
|
|
1494
|
+
) {
|
|
1495
|
+
if (isWritableRole2(accountMeta.role)) {
|
|
1496
|
+
throw new Error(
|
|
1497
|
+
`This transaction includes an address (\`${account.address}\`) which is both invoked and marked writable. Program addresses may not be writable.`
|
|
1498
|
+
);
|
|
1499
|
+
}
|
|
1500
|
+
if (entry.role !== nextRole) {
|
|
1501
|
+
return {
|
|
1502
|
+
...entry,
|
|
1503
|
+
role: nextRole
|
|
1504
|
+
};
|
|
1505
|
+
} else {
|
|
1506
|
+
return entry;
|
|
1507
|
+
}
|
|
1508
|
+
} else if ("lookupTableAddress" in accountMeta && // Static accounts can be 'upgraded' to lookup table accounts as
|
|
1509
|
+
// long as they are not require to sign the transaction.
|
|
1510
|
+
!isSignerRole2(entry.role)) {
|
|
1511
|
+
return {
|
|
1512
|
+
...accountMeta,
|
|
1513
|
+
[TYPE]: 1,
|
|
1514
|
+
role: nextRole
|
|
1515
|
+
};
|
|
1516
|
+
} else {
|
|
1517
|
+
if (entry.role !== nextRole) {
|
|
1518
|
+
return {
|
|
1519
|
+
...entry,
|
|
1520
|
+
role: nextRole
|
|
1521
|
+
};
|
|
1522
|
+
} else {
|
|
1523
|
+
return entry;
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
if ("lookupTableAddress" in accountMeta) {
|
|
1530
|
+
return {
|
|
1531
|
+
...accountMeta,
|
|
1532
|
+
[TYPE]: 1
|
|
1533
|
+
/* LOOKUP_TABLE */
|
|
1534
|
+
};
|
|
1535
|
+
} else {
|
|
1536
|
+
return {
|
|
1537
|
+
...accountMeta,
|
|
1538
|
+
[TYPE]: 2
|
|
1539
|
+
/* STATIC */
|
|
1540
|
+
};
|
|
1541
|
+
}
|
|
1542
|
+
});
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
return addressMap;
|
|
1546
|
+
}
|
|
1547
|
+
function getOrderedAccountsFromAddressMap(addressMap) {
|
|
1548
|
+
let addressComparator;
|
|
1549
|
+
const orderedAccounts = Object.entries(addressMap).sort(([leftAddress, leftEntry], [rightAddress, rightEntry]) => {
|
|
1550
|
+
if (leftEntry[TYPE] !== rightEntry[TYPE]) {
|
|
1551
|
+
if (leftEntry[TYPE] === 0) {
|
|
1552
|
+
return -1;
|
|
1553
|
+
} else if (rightEntry[TYPE] === 0) {
|
|
1554
|
+
return 1;
|
|
1555
|
+
} else if (leftEntry[TYPE] === 2) {
|
|
1556
|
+
return -1;
|
|
1557
|
+
} else if (rightEntry[TYPE] === 2) {
|
|
1558
|
+
return 1;
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
const leftIsSigner = isSignerRole2(leftEntry.role);
|
|
1562
|
+
if (leftIsSigner !== isSignerRole2(rightEntry.role)) {
|
|
1563
|
+
return leftIsSigner ? -1 : 1;
|
|
1564
|
+
}
|
|
1565
|
+
const leftIsWritable = isWritableRole2(leftEntry.role);
|
|
1566
|
+
if (leftIsWritable !== isWritableRole2(rightEntry.role)) {
|
|
1567
|
+
return leftIsWritable ? -1 : 1;
|
|
1568
|
+
}
|
|
1569
|
+
addressComparator || (addressComparator = getAddressComparator());
|
|
1570
|
+
if (leftEntry[TYPE] === 1 && rightEntry[TYPE] === 1 && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
|
|
1571
|
+
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
|
|
1572
|
+
} else {
|
|
1573
|
+
return addressComparator(leftAddress, rightAddress);
|
|
1574
|
+
}
|
|
1575
|
+
}).map(([address2, addressMeta]) => ({
|
|
1576
|
+
address: address2,
|
|
1577
|
+
...addressMeta
|
|
1578
|
+
}));
|
|
1579
|
+
return orderedAccounts;
|
|
1580
|
+
}
|
|
1581
|
+
function getCompiledAddressTableLookups(orderedAccounts) {
|
|
1582
|
+
var _a;
|
|
1583
|
+
const index = {};
|
|
1584
|
+
for (const account of orderedAccounts) {
|
|
1585
|
+
if (!("lookupTableAddress" in account)) {
|
|
1586
|
+
continue;
|
|
1587
|
+
}
|
|
1588
|
+
const entry = index[_a = account.lookupTableAddress] || (index[_a] = {
|
|
1589
|
+
readableIndices: [],
|
|
1590
|
+
writableIndices: []
|
|
1591
|
+
});
|
|
1592
|
+
if (account.role === AccountRole2.WRITABLE) {
|
|
1593
|
+
entry.writableIndices.push(account.addressIndex);
|
|
1594
|
+
} else {
|
|
1595
|
+
entry.readableIndices.push(account.addressIndex);
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
return Object.keys(index).sort(getAddressComparator()).map((lookupTableAddress) => ({
|
|
1599
|
+
lookupTableAddress,
|
|
1600
|
+
...index[lookupTableAddress]
|
|
1601
|
+
}));
|
|
1602
|
+
}
|
|
1603
|
+
function getCompiledMessageHeader(orderedAccounts) {
|
|
1604
|
+
let numReadonlyNonSignerAccounts = 0;
|
|
1605
|
+
let numReadonlySignerAccounts = 0;
|
|
1606
|
+
let numSignerAccounts = 0;
|
|
1607
|
+
for (const account of orderedAccounts) {
|
|
1608
|
+
if ("lookupTableAddress" in account) {
|
|
1609
|
+
break;
|
|
1610
|
+
}
|
|
1611
|
+
const accountIsWritable = isWritableRole2(account.role);
|
|
1612
|
+
if (isSignerRole2(account.role)) {
|
|
1613
|
+
numSignerAccounts++;
|
|
1614
|
+
if (!accountIsWritable) {
|
|
1615
|
+
numReadonlySignerAccounts++;
|
|
1616
|
+
}
|
|
1617
|
+
} else if (!accountIsWritable) {
|
|
1618
|
+
numReadonlyNonSignerAccounts++;
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
return {
|
|
1622
|
+
numReadonlyNonSignerAccounts,
|
|
1623
|
+
numReadonlySignerAccounts,
|
|
1624
|
+
numSignerAccounts
|
|
1625
|
+
};
|
|
1626
|
+
}
|
|
1627
|
+
function getAccountIndex(orderedAccounts) {
|
|
1628
|
+
const out = {};
|
|
1629
|
+
for (const [index, account] of orderedAccounts.entries()) {
|
|
1630
|
+
out[account.address] = index;
|
|
1631
|
+
}
|
|
1632
|
+
return out;
|
|
1633
|
+
}
|
|
1634
|
+
function getCompiledInstructions(instructions, orderedAccounts) {
|
|
1635
|
+
const accountIndex = getAccountIndex(orderedAccounts);
|
|
1636
|
+
return instructions.map(({ accounts, data, programAddress }) => {
|
|
1637
|
+
return {
|
|
1638
|
+
programAddressIndex: accountIndex[programAddress],
|
|
1639
|
+
...accounts ? { accountIndices: accounts.map(({ address: address2 }) => accountIndex[address2]) } : null,
|
|
1640
|
+
...data ? { data } : null
|
|
1641
|
+
};
|
|
1642
|
+
});
|
|
1643
|
+
}
|
|
1644
|
+
function getCompiledLifetimeToken(lifetimeConstraint) {
|
|
1645
|
+
if ("nonce" in lifetimeConstraint) {
|
|
1646
|
+
return lifetimeConstraint.nonce;
|
|
1647
|
+
}
|
|
1648
|
+
return lifetimeConstraint.blockhash;
|
|
1649
|
+
}
|
|
1650
|
+
function getCompiledStaticAccounts(orderedAccounts) {
|
|
1651
|
+
const firstLookupTableAccountIndex = orderedAccounts.findIndex((account) => "lookupTableAddress" in account);
|
|
1652
|
+
const orderedStaticAccounts = firstLookupTableAccountIndex === -1 ? orderedAccounts : orderedAccounts.slice(0, firstLookupTableAccountIndex);
|
|
1653
|
+
return orderedStaticAccounts.map(({ address: address2 }) => address2);
|
|
1654
|
+
}
|
|
1655
|
+
function compileMessage(transaction) {
|
|
1656
|
+
const addressMap = getAddressMapFromInstructions(transaction.feePayer, transaction.instructions);
|
|
1657
|
+
const orderedAccounts = getOrderedAccountsFromAddressMap(addressMap);
|
|
1658
|
+
return {
|
|
1659
|
+
...transaction.version !== "legacy" ? { addressTableLookups: getCompiledAddressTableLookups(orderedAccounts) } : null,
|
|
1660
|
+
header: getCompiledMessageHeader(orderedAccounts),
|
|
1661
|
+
instructions: getCompiledInstructions(transaction.instructions, orderedAccounts),
|
|
1662
|
+
lifetimeToken: getCompiledLifetimeToken(transaction.lifetimeConstraint),
|
|
1663
|
+
staticAccounts: getCompiledStaticAccounts(orderedAccounts),
|
|
1664
|
+
version: transaction.version
|
|
1665
|
+
};
|
|
1666
|
+
}
|
|
1667
|
+
function getCompiledTransaction(transaction) {
|
|
1668
|
+
const compiledMessage = compileMessage(transaction);
|
|
1669
|
+
let signatures;
|
|
1670
|
+
if ("signatures" in transaction) {
|
|
1671
|
+
signatures = [];
|
|
1672
|
+
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
1673
|
+
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
1674
|
+
}
|
|
1675
|
+
} else {
|
|
1676
|
+
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
1677
|
+
}
|
|
1678
|
+
return {
|
|
1679
|
+
compiledMessage,
|
|
1680
|
+
signatures
|
|
1681
|
+
};
|
|
1682
|
+
}
|
|
1683
|
+
function getAccountMetas(message) {
|
|
1684
|
+
const { header } = message;
|
|
1685
|
+
const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
|
|
1686
|
+
const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
|
|
1687
|
+
const accountMetas = [];
|
|
1688
|
+
let accountIndex = 0;
|
|
1689
|
+
for (let i = 0; i < numWritableSignerAccounts; i++) {
|
|
1690
|
+
accountMetas.push({
|
|
1691
|
+
address: message.staticAccounts[accountIndex],
|
|
1692
|
+
role: AccountRole2.WRITABLE_SIGNER
|
|
1693
|
+
});
|
|
1694
|
+
accountIndex++;
|
|
1695
|
+
}
|
|
1696
|
+
for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
|
|
1697
|
+
accountMetas.push({
|
|
1698
|
+
address: message.staticAccounts[accountIndex],
|
|
1699
|
+
role: AccountRole2.READONLY_SIGNER
|
|
1700
|
+
});
|
|
1701
|
+
accountIndex++;
|
|
1702
|
+
}
|
|
1703
|
+
for (let i = 0; i < numWritableNonSignerAccounts; i++) {
|
|
1704
|
+
accountMetas.push({
|
|
1705
|
+
address: message.staticAccounts[accountIndex],
|
|
1706
|
+
role: AccountRole2.WRITABLE
|
|
1707
|
+
});
|
|
1708
|
+
accountIndex++;
|
|
1709
|
+
}
|
|
1710
|
+
for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
|
|
1711
|
+
accountMetas.push({
|
|
1712
|
+
address: message.staticAccounts[accountIndex],
|
|
1713
|
+
role: AccountRole2.READONLY
|
|
1714
|
+
});
|
|
1715
|
+
accountIndex++;
|
|
1716
|
+
}
|
|
1717
|
+
return accountMetas;
|
|
1718
|
+
}
|
|
1719
|
+
function convertInstruction(instruction, accountMetas) {
|
|
1720
|
+
const programAddress = accountMetas[instruction.programAddressIndex]?.address;
|
|
1721
|
+
if (!programAddress) {
|
|
1722
|
+
throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
|
|
1723
|
+
}
|
|
1724
|
+
const accounts = instruction.accountIndices?.map((accountIndex) => accountMetas[accountIndex]);
|
|
1725
|
+
const { data } = instruction;
|
|
1726
|
+
return {
|
|
1727
|
+
programAddress,
|
|
1728
|
+
...accounts && accounts.length ? { accounts } : {},
|
|
1729
|
+
...data && data.length ? { data } : {}
|
|
1730
|
+
};
|
|
1731
|
+
}
|
|
1732
|
+
function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
|
|
1733
|
+
if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
1734
|
+
return {
|
|
1735
|
+
blockhash: messageLifetimeToken,
|
|
1736
|
+
lastValidBlockHeight: lastValidBlockHeight ?? 2n ** 64n - 1n
|
|
1737
|
+
// U64 MAX
|
|
1738
|
+
};
|
|
1739
|
+
} else {
|
|
1740
|
+
const nonceAccountAddress = firstInstruction.accounts[0].address;
|
|
1741
|
+
assertIsAddress(nonceAccountAddress);
|
|
1742
|
+
const nonceAuthorityAddress = firstInstruction.accounts[2].address;
|
|
1743
|
+
assertIsAddress(nonceAuthorityAddress);
|
|
1744
|
+
return {
|
|
1745
|
+
nonce: messageLifetimeToken,
|
|
1746
|
+
nonceAccountAddress,
|
|
1747
|
+
nonceAuthorityAddress
|
|
1748
|
+
};
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
function convertSignatures(compiledTransaction) {
|
|
1752
|
+
const {
|
|
1753
|
+
compiledMessage: { staticAccounts },
|
|
1754
|
+
signatures
|
|
1755
|
+
} = compiledTransaction;
|
|
1756
|
+
return signatures.reduce((acc, sig, index) => {
|
|
1757
|
+
const allZeros = sig.every((byte) => byte === 0);
|
|
1758
|
+
if (allZeros)
|
|
1759
|
+
return acc;
|
|
1760
|
+
const address2 = staticAccounts[index];
|
|
1761
|
+
return { ...acc, [address2]: sig };
|
|
1762
|
+
}, {});
|
|
1763
|
+
}
|
|
1764
|
+
function decompileTransaction(compiledTransaction, lastValidBlockHeight) {
|
|
1765
|
+
const { compiledMessage } = compiledTransaction;
|
|
1766
|
+
if ("addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups.length > 0) {
|
|
1767
|
+
throw new Error("Cannot convert transaction with addressTableLookups");
|
|
1768
|
+
}
|
|
1769
|
+
const feePayer = compiledMessage.staticAccounts[0];
|
|
1770
|
+
if (!feePayer)
|
|
1771
|
+
throw new Error("No fee payer set in CompiledTransaction");
|
|
1772
|
+
const accountMetas = getAccountMetas(compiledMessage);
|
|
1773
|
+
const instructions = compiledMessage.instructions.map(
|
|
1774
|
+
(compiledInstruction) => convertInstruction(compiledInstruction, accountMetas)
|
|
1775
|
+
);
|
|
1776
|
+
const firstInstruction = instructions[0];
|
|
1777
|
+
const lifetimeConstraint = getLifetimeConstraint(
|
|
1778
|
+
compiledMessage.lifetimeToken,
|
|
1779
|
+
firstInstruction,
|
|
1780
|
+
lastValidBlockHeight
|
|
1781
|
+
);
|
|
1782
|
+
const signatures = convertSignatures(compiledTransaction);
|
|
1783
|
+
return pipe(
|
|
1784
|
+
createTransaction({ version: compiledMessage.version }),
|
|
1785
|
+
(tx) => setTransactionFeePayer(feePayer, tx),
|
|
1786
|
+
(tx) => instructions.reduce((acc, instruction) => {
|
|
1787
|
+
return appendTransactionInstruction(instruction, acc);
|
|
1788
|
+
}, tx),
|
|
1789
|
+
(tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
|
|
1790
|
+
(tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
|
|
1791
|
+
);
|
|
1792
|
+
}
|
|
1793
|
+
var lookupTableAddressDescription = "The address of the address lookup table account from which instruction addresses should be looked up" ;
|
|
1794
|
+
var writableIndicesDescription = "The indices of the accounts in the lookup table that should be loaded as writeable" ;
|
|
1795
|
+
var readableIndicesDescription = "The indices of the accounts in the lookup table that should be loaded as read-only" ;
|
|
1796
|
+
var addressTableLookupDescription = "A pointer to the address of an address lookup table, along with the readonly/writeable indices of the addresses that should be loaded from it" ;
|
|
1797
|
+
var memoizedAddressTableLookupEncoder;
|
|
1798
|
+
function getAddressTableLookupEncoder() {
|
|
1799
|
+
if (!memoizedAddressTableLookupEncoder) {
|
|
1800
|
+
memoizedAddressTableLookupEncoder = getStructEncoder(
|
|
1801
|
+
[
|
|
1802
|
+
["lookupTableAddress", getAddressEncoder({ description: lookupTableAddressDescription })],
|
|
1803
|
+
[
|
|
1804
|
+
"writableIndices",
|
|
1805
|
+
getArrayEncoder(getU8Encoder(), {
|
|
1806
|
+
description: writableIndicesDescription,
|
|
1807
|
+
size: getShortU16Encoder()
|
|
1808
|
+
})
|
|
1809
|
+
],
|
|
1810
|
+
[
|
|
1811
|
+
"readableIndices",
|
|
1812
|
+
getArrayEncoder(getU8Encoder(), {
|
|
1813
|
+
description: readableIndicesDescription,
|
|
1814
|
+
size: getShortU16Encoder()
|
|
1815
|
+
})
|
|
1816
|
+
]
|
|
1817
|
+
],
|
|
1818
|
+
{ description: addressTableLookupDescription }
|
|
1819
|
+
);
|
|
1820
|
+
}
|
|
1821
|
+
return memoizedAddressTableLookupEncoder;
|
|
1822
|
+
}
|
|
1823
|
+
var memoizedAddressTableLookupDecoder;
|
|
1824
|
+
function getAddressTableLookupDecoder() {
|
|
1825
|
+
if (!memoizedAddressTableLookupDecoder) {
|
|
1826
|
+
memoizedAddressTableLookupDecoder = getStructDecoder(
|
|
1827
|
+
[
|
|
1828
|
+
["lookupTableAddress", getAddressDecoder({ description: lookupTableAddressDescription })],
|
|
1829
|
+
[
|
|
1830
|
+
"writableIndices",
|
|
1831
|
+
getArrayDecoder(getU8Decoder(), {
|
|
1832
|
+
description: writableIndicesDescription,
|
|
1833
|
+
size: getShortU16Decoder()
|
|
1834
|
+
})
|
|
1835
|
+
],
|
|
1836
|
+
[
|
|
1837
|
+
"readableIndices",
|
|
1838
|
+
getArrayDecoder(getU8Decoder(), {
|
|
1839
|
+
description: readableIndicesDescription,
|
|
1840
|
+
size: getShortU16Decoder()
|
|
1841
|
+
})
|
|
1842
|
+
]
|
|
1843
|
+
],
|
|
1844
|
+
{ description: addressTableLookupDescription }
|
|
1845
|
+
);
|
|
1846
|
+
}
|
|
1847
|
+
return memoizedAddressTableLookupDecoder;
|
|
1848
|
+
}
|
|
1849
|
+
var memoizedU8Encoder;
|
|
1850
|
+
function getMemoizedU8Encoder() {
|
|
1851
|
+
if (!memoizedU8Encoder)
|
|
1852
|
+
memoizedU8Encoder = getU8Encoder();
|
|
1853
|
+
return memoizedU8Encoder;
|
|
1854
|
+
}
|
|
1855
|
+
function getMemoizedU8EncoderDescription(description) {
|
|
1856
|
+
const encoder = getMemoizedU8Encoder();
|
|
1857
|
+
return {
|
|
1858
|
+
...encoder,
|
|
1859
|
+
description: description ?? encoder.description
|
|
1860
|
+
};
|
|
1861
|
+
}
|
|
1862
|
+
var memoizedU8Decoder;
|
|
1863
|
+
function getMemoizedU8Decoder() {
|
|
1864
|
+
if (!memoizedU8Decoder)
|
|
1865
|
+
memoizedU8Decoder = getU8Decoder();
|
|
1866
|
+
return memoizedU8Decoder;
|
|
1867
|
+
}
|
|
1868
|
+
function getMemoizedU8DecoderDescription(description) {
|
|
1869
|
+
const decoder = getMemoizedU8Decoder();
|
|
1870
|
+
return {
|
|
1871
|
+
...decoder,
|
|
1872
|
+
description: description ?? decoder.description
|
|
1873
|
+
};
|
|
1874
|
+
}
|
|
1875
|
+
var numSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" ;
|
|
1876
|
+
var numReadonlySignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction, but may not be writable" ;
|
|
1877
|
+
var numReadonlyNonSignerAccountsDescription = "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" ;
|
|
1878
|
+
var messageHeaderDescription = "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" ;
|
|
1879
|
+
function getMessageHeaderEncoder() {
|
|
1880
|
+
return getStructEncoder(
|
|
1881
|
+
[
|
|
1882
|
+
["numSignerAccounts", getMemoizedU8EncoderDescription(numSignerAccountsDescription)],
|
|
1883
|
+
["numReadonlySignerAccounts", getMemoizedU8EncoderDescription(numReadonlySignerAccountsDescription)],
|
|
1884
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8EncoderDescription(numReadonlyNonSignerAccountsDescription)]
|
|
1885
|
+
],
|
|
1886
|
+
{
|
|
1887
|
+
description: messageHeaderDescription
|
|
1888
|
+
}
|
|
1889
|
+
);
|
|
1890
|
+
}
|
|
1891
|
+
function getMessageHeaderDecoder() {
|
|
1892
|
+
return getStructDecoder(
|
|
1893
|
+
[
|
|
1894
|
+
["numSignerAccounts", getMemoizedU8DecoderDescription(numSignerAccountsDescription)],
|
|
1895
|
+
["numReadonlySignerAccounts", getMemoizedU8DecoderDescription(numReadonlySignerAccountsDescription)],
|
|
1896
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8DecoderDescription(numReadonlyNonSignerAccountsDescription)]
|
|
1897
|
+
],
|
|
1898
|
+
{
|
|
1899
|
+
description: messageHeaderDescription
|
|
1900
|
+
}
|
|
1901
|
+
);
|
|
1902
|
+
}
|
|
1903
|
+
var programAddressIndexDescription = "The index of the program being called, according to the well-ordered accounts list for this transaction" ;
|
|
1904
|
+
var accountIndexDescription = "The index of an account, according to the well-ordered accounts list for this transaction" ;
|
|
1905
|
+
var accountIndicesDescription = "An optional list of account indices, according to the well-ordered accounts list for this transaction, in the order in which the program being called expects them" ;
|
|
1906
|
+
var dataDescription = "An optional buffer of data passed to the instruction" ;
|
|
1907
|
+
var memoizedGetInstructionEncoder;
|
|
1908
|
+
function getInstructionEncoder() {
|
|
1909
|
+
if (!memoizedGetInstructionEncoder) {
|
|
1910
|
+
memoizedGetInstructionEncoder = mapEncoder(
|
|
1911
|
+
getStructEncoder([
|
|
1912
|
+
["programAddressIndex", getU8Encoder({ description: programAddressIndexDescription })],
|
|
1913
|
+
[
|
|
1914
|
+
"accountIndices",
|
|
1915
|
+
getArrayEncoder(getU8Encoder({ description: accountIndexDescription }), {
|
|
1916
|
+
description: accountIndicesDescription,
|
|
1917
|
+
size: getShortU16Encoder()
|
|
1918
|
+
})
|
|
1919
|
+
],
|
|
1920
|
+
["data", getBytesEncoder({ description: dataDescription, size: getShortU16Encoder() })]
|
|
1921
|
+
]),
|
|
1922
|
+
// Convert an instruction to have all fields defined
|
|
1923
|
+
(instruction) => {
|
|
1924
|
+
if (instruction.accountIndices !== void 0 && instruction.data !== void 0) {
|
|
1925
|
+
return instruction;
|
|
1926
|
+
}
|
|
1927
|
+
return {
|
|
1928
|
+
...instruction,
|
|
1929
|
+
accountIndices: instruction.accountIndices ?? [],
|
|
1930
|
+
data: instruction.data ?? new Uint8Array(0)
|
|
1931
|
+
};
|
|
1932
|
+
}
|
|
1933
|
+
);
|
|
1934
|
+
}
|
|
1935
|
+
return memoizedGetInstructionEncoder;
|
|
1936
|
+
}
|
|
1937
|
+
var memoizedGetInstructionDecoder;
|
|
1938
|
+
function getInstructionDecoder() {
|
|
1939
|
+
if (!memoizedGetInstructionDecoder) {
|
|
1940
|
+
memoizedGetInstructionDecoder = mapDecoder(
|
|
1941
|
+
getStructDecoder([
|
|
1942
|
+
["programAddressIndex", getU8Decoder({ description: programAddressIndexDescription })],
|
|
1943
|
+
[
|
|
1944
|
+
"accountIndices",
|
|
1945
|
+
getArrayDecoder(getU8Decoder({ description: accountIndexDescription }), {
|
|
1946
|
+
description: accountIndicesDescription,
|
|
1947
|
+
size: getShortU16Decoder()
|
|
1948
|
+
})
|
|
1949
|
+
],
|
|
1950
|
+
["data", getBytesDecoder({ description: dataDescription, size: getShortU16Decoder() })]
|
|
1951
|
+
]),
|
|
1952
|
+
// Convert an instruction to exclude optional fields if they are empty
|
|
1953
|
+
(instruction) => {
|
|
1954
|
+
if (instruction.accountIndices.length && instruction.data.byteLength) {
|
|
1955
|
+
return instruction;
|
|
1956
|
+
}
|
|
1957
|
+
const { accountIndices, data, ...rest } = instruction;
|
|
1958
|
+
return {
|
|
1959
|
+
...rest,
|
|
1960
|
+
...accountIndices.length ? { accountIndices } : null,
|
|
1961
|
+
...data.byteLength ? { data } : null
|
|
1962
|
+
};
|
|
1963
|
+
}
|
|
1964
|
+
);
|
|
1965
|
+
}
|
|
1966
|
+
return memoizedGetInstructionDecoder;
|
|
1967
|
+
}
|
|
1968
|
+
var VERSION_FLAG_MASK = 128;
|
|
1969
|
+
var BASE_CONFIG = {
|
|
1970
|
+
description: "A single byte that encodes the version of the transaction" ,
|
|
1971
|
+
fixedSize: null,
|
|
1972
|
+
maxSize: 1
|
|
1973
|
+
};
|
|
1974
|
+
function decode(bytes, offset = 0) {
|
|
1975
|
+
const firstByte = bytes[offset];
|
|
1976
|
+
if ((firstByte & VERSION_FLAG_MASK) === 0) {
|
|
1977
|
+
return ["legacy", offset];
|
|
1978
|
+
} else {
|
|
1979
|
+
const version = firstByte ^ VERSION_FLAG_MASK;
|
|
1980
|
+
return [version, offset + 1];
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
function encode(value) {
|
|
1984
|
+
if (value === "legacy") {
|
|
1985
|
+
return new Uint8Array();
|
|
1986
|
+
}
|
|
1987
|
+
if (value < 0 || value > 127) {
|
|
1988
|
+
throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
|
|
1989
|
+
}
|
|
1990
|
+
return new Uint8Array([value | VERSION_FLAG_MASK]);
|
|
1991
|
+
}
|
|
1992
|
+
function getTransactionVersionDecoder() {
|
|
1993
|
+
return {
|
|
1994
|
+
...BASE_CONFIG,
|
|
1995
|
+
decode
|
|
1996
|
+
};
|
|
1997
|
+
}
|
|
1998
|
+
function getTransactionVersionEncoder() {
|
|
1999
|
+
return {
|
|
2000
|
+
...BASE_CONFIG,
|
|
2001
|
+
encode
|
|
2002
|
+
};
|
|
2003
|
+
}
|
|
2004
|
+
var staticAccountsDescription = "A compact-array of static account addresses belonging to this transaction" ;
|
|
2005
|
+
var lifetimeTokenDescription = "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" ;
|
|
2006
|
+
var instructionsDescription = "A compact-array of instructions belonging to this transaction" ;
|
|
2007
|
+
var addressTableLookupsDescription = "A compact array of address table lookups belonging to this transaction" ;
|
|
2008
|
+
function getCompiledMessageLegacyEncoder() {
|
|
2009
|
+
return getStructEncoder(getPreludeStructEncoderTuple());
|
|
2010
|
+
}
|
|
2011
|
+
function getCompiledMessageVersionedEncoder() {
|
|
2012
|
+
return mapEncoder(
|
|
2013
|
+
getStructEncoder([
|
|
2014
|
+
...getPreludeStructEncoderTuple(),
|
|
2015
|
+
["addressTableLookups", getAddressTableLookupArrayEncoder()]
|
|
2016
|
+
]),
|
|
2017
|
+
(value) => {
|
|
2018
|
+
if (value.version === "legacy") {
|
|
2019
|
+
return value;
|
|
2020
|
+
}
|
|
2021
|
+
return {
|
|
2022
|
+
...value,
|
|
2023
|
+
addressTableLookups: value.addressTableLookups ?? []
|
|
2024
|
+
};
|
|
2025
|
+
}
|
|
2026
|
+
);
|
|
2027
|
+
}
|
|
2028
|
+
function getPreludeStructEncoderTuple() {
|
|
2029
|
+
return [
|
|
2030
|
+
["version", getTransactionVersionEncoder()],
|
|
2031
|
+
["header", getMessageHeaderEncoder()],
|
|
2032
|
+
[
|
|
2033
|
+
"staticAccounts",
|
|
2034
|
+
getArrayEncoder(getAddressEncoder(), {
|
|
2035
|
+
description: staticAccountsDescription,
|
|
2036
|
+
size: getShortU16Encoder()
|
|
2037
|
+
})
|
|
2038
|
+
],
|
|
2039
|
+
[
|
|
2040
|
+
"lifetimeToken",
|
|
2041
|
+
getStringEncoder({
|
|
2042
|
+
description: lifetimeTokenDescription,
|
|
2043
|
+
encoding: getBase58Encoder(),
|
|
2044
|
+
size: 32
|
|
2045
|
+
})
|
|
2046
|
+
],
|
|
2047
|
+
[
|
|
2048
|
+
"instructions",
|
|
2049
|
+
getArrayEncoder(getInstructionEncoder(), {
|
|
2050
|
+
description: instructionsDescription,
|
|
2051
|
+
size: getShortU16Encoder()
|
|
2052
|
+
})
|
|
2053
|
+
]
|
|
2054
|
+
];
|
|
2055
|
+
}
|
|
2056
|
+
function getPreludeStructDecoderTuple() {
|
|
2057
|
+
return [
|
|
2058
|
+
["version", getTransactionVersionDecoder()],
|
|
2059
|
+
["header", getMessageHeaderDecoder()],
|
|
2060
|
+
[
|
|
2061
|
+
"staticAccounts",
|
|
2062
|
+
getArrayDecoder(getAddressDecoder(), {
|
|
2063
|
+
description: staticAccountsDescription,
|
|
2064
|
+
size: getShortU16Decoder()
|
|
2065
|
+
})
|
|
2066
|
+
],
|
|
2067
|
+
[
|
|
2068
|
+
"lifetimeToken",
|
|
2069
|
+
getStringDecoder({
|
|
2070
|
+
description: lifetimeTokenDescription,
|
|
2071
|
+
encoding: getBase58Decoder(),
|
|
2072
|
+
size: 32
|
|
2073
|
+
})
|
|
2074
|
+
],
|
|
2075
|
+
[
|
|
2076
|
+
"instructions",
|
|
2077
|
+
getArrayDecoder(getInstructionDecoder(), {
|
|
2078
|
+
description: instructionsDescription,
|
|
2079
|
+
size: getShortU16Decoder()
|
|
2080
|
+
})
|
|
2081
|
+
],
|
|
2082
|
+
["addressTableLookups", getAddressTableLookupArrayDecoder()]
|
|
2083
|
+
];
|
|
2084
|
+
}
|
|
2085
|
+
function getAddressTableLookupArrayEncoder() {
|
|
2086
|
+
return getArrayEncoder(getAddressTableLookupEncoder(), {
|
|
2087
|
+
description: addressTableLookupsDescription,
|
|
2088
|
+
size: getShortU16Encoder()
|
|
2089
|
+
});
|
|
2090
|
+
}
|
|
2091
|
+
function getAddressTableLookupArrayDecoder() {
|
|
2092
|
+
return getArrayDecoder(getAddressTableLookupDecoder(), {
|
|
2093
|
+
description: addressTableLookupsDescription,
|
|
2094
|
+
size: getShortU16Decoder()
|
|
2095
|
+
});
|
|
2096
|
+
}
|
|
2097
|
+
var messageDescription = "The wire format of a Solana transaction message" ;
|
|
2098
|
+
function getCompiledMessageEncoder() {
|
|
2099
|
+
return {
|
|
2100
|
+
description: messageDescription,
|
|
2101
|
+
encode: (compiledMessage) => {
|
|
2102
|
+
if (compiledMessage.version === "legacy") {
|
|
2103
|
+
return getCompiledMessageLegacyEncoder().encode(compiledMessage);
|
|
2104
|
+
} else {
|
|
2105
|
+
return getCompiledMessageVersionedEncoder().encode(compiledMessage);
|
|
2106
|
+
}
|
|
2107
|
+
},
|
|
2108
|
+
fixedSize: null,
|
|
2109
|
+
maxSize: null
|
|
2110
|
+
};
|
|
2111
|
+
}
|
|
2112
|
+
function getCompiledMessageDecoder() {
|
|
2113
|
+
return mapDecoder(
|
|
2114
|
+
getStructDecoder(getPreludeStructDecoderTuple(), {
|
|
2115
|
+
description: messageDescription
|
|
2116
|
+
}),
|
|
2117
|
+
({ addressTableLookups, ...restOfMessage }) => {
|
|
2118
|
+
if (restOfMessage.version === "legacy" || !addressTableLookups?.length) {
|
|
2119
|
+
return restOfMessage;
|
|
2120
|
+
}
|
|
2121
|
+
return { ...restOfMessage, addressTableLookups };
|
|
2122
|
+
}
|
|
2123
|
+
);
|
|
2124
|
+
}
|
|
2125
|
+
var signaturesDescription = "A compact array of 64-byte, base-64 encoded Ed25519 signatures" ;
|
|
2126
|
+
var transactionDescription = "The wire format of a Solana transaction" ;
|
|
2127
|
+
function getCompiledTransactionEncoder() {
|
|
2128
|
+
return getStructEncoder(
|
|
2129
|
+
[
|
|
2130
|
+
[
|
|
2131
|
+
"signatures",
|
|
2132
|
+
getArrayEncoder(getBytesEncoder({ size: 64 }), {
|
|
2133
|
+
description: signaturesDescription,
|
|
2134
|
+
size: getShortU16Encoder()
|
|
2135
|
+
})
|
|
2136
|
+
],
|
|
2137
|
+
["compiledMessage", getCompiledMessageEncoder()]
|
|
2138
|
+
],
|
|
2139
|
+
{
|
|
2140
|
+
description: transactionDescription
|
|
2141
|
+
}
|
|
2142
|
+
);
|
|
2143
|
+
}
|
|
2144
|
+
function getSignatureDecoder() {
|
|
2145
|
+
return mapDecoder(getBytesDecoder({ size: 64 }), (bytes) => bytes);
|
|
2146
|
+
}
|
|
2147
|
+
function getCompiledTransactionDecoder() {
|
|
2148
|
+
return getStructDecoder(
|
|
2149
|
+
[
|
|
2150
|
+
[
|
|
2151
|
+
"signatures",
|
|
2152
|
+
getArrayDecoder(getSignatureDecoder(), {
|
|
2153
|
+
description: signaturesDescription,
|
|
2154
|
+
size: getShortU16Decoder()
|
|
2155
|
+
})
|
|
2156
|
+
],
|
|
2157
|
+
["compiledMessage", getCompiledMessageDecoder()]
|
|
2158
|
+
],
|
|
2159
|
+
{
|
|
2160
|
+
description: transactionDescription
|
|
2161
|
+
}
|
|
2162
|
+
);
|
|
2163
|
+
}
|
|
2164
|
+
function getTransactionEncoder() {
|
|
2165
|
+
return mapEncoder(getCompiledTransactionEncoder(), getCompiledTransaction);
|
|
2166
|
+
}
|
|
2167
|
+
function getTransactionDecoder(lastValidBlockHeight) {
|
|
2168
|
+
return mapDecoder(
|
|
2169
|
+
getCompiledTransactionDecoder(),
|
|
2170
|
+
(compiledTransaction) => decompileTransaction(compiledTransaction, lastValidBlockHeight)
|
|
2171
|
+
);
|
|
2172
|
+
}
|
|
2173
|
+
function getTransactionCodec(lastValidBlockHeight) {
|
|
2174
|
+
return combineCodec(getTransactionEncoder(), getTransactionDecoder(lastValidBlockHeight));
|
|
2175
|
+
}
|
|
2176
|
+
var base58Encoder2;
|
|
2177
|
+
var base58Decoder;
|
|
2178
|
+
function assertIsTransactionSignature(putativeTransactionSignature) {
|
|
2179
|
+
if (!base58Encoder2)
|
|
2180
|
+
base58Encoder2 = getBase58Encoder();
|
|
2181
|
+
try {
|
|
2182
|
+
if (
|
|
2183
|
+
// Lowest value (64 bytes of zeroes)
|
|
2184
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
2185
|
+
putativeTransactionSignature.length > 88
|
|
2186
|
+
) {
|
|
2187
|
+
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
2188
|
+
}
|
|
2189
|
+
const bytes = base58Encoder2.encode(putativeTransactionSignature);
|
|
2190
|
+
const numBytes = bytes.byteLength;
|
|
2191
|
+
if (numBytes !== 64) {
|
|
2192
|
+
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
2193
|
+
}
|
|
2194
|
+
} catch (e3) {
|
|
2195
|
+
throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
|
|
2196
|
+
cause: e3
|
|
2197
|
+
});
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
function isTransactionSignature(putativeTransactionSignature) {
|
|
2201
|
+
if (!base58Encoder2)
|
|
2202
|
+
base58Encoder2 = getBase58Encoder();
|
|
2203
|
+
if (
|
|
2204
|
+
// Lowest value (64 bytes of zeroes)
|
|
2205
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
2206
|
+
putativeTransactionSignature.length > 88
|
|
2207
|
+
) {
|
|
2208
|
+
return false;
|
|
2209
|
+
}
|
|
2210
|
+
const bytes = base58Encoder2.encode(putativeTransactionSignature);
|
|
2211
|
+
const numBytes = bytes.byteLength;
|
|
2212
|
+
if (numBytes !== 64) {
|
|
2213
|
+
return false;
|
|
2214
|
+
}
|
|
2215
|
+
return true;
|
|
2216
|
+
}
|
|
2217
|
+
function getSignatureFromTransaction(transaction) {
|
|
2218
|
+
if (!base58Decoder)
|
|
2219
|
+
base58Decoder = getBase58Decoder();
|
|
2220
|
+
const signatureBytes = transaction.signatures[transaction.feePayer];
|
|
2221
|
+
if (!signatureBytes) {
|
|
2222
|
+
throw new Error(
|
|
2223
|
+
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
2224
|
+
);
|
|
2225
|
+
}
|
|
2226
|
+
const transactionSignature2 = base58Decoder.decode(signatureBytes)[0];
|
|
2227
|
+
return transactionSignature2;
|
|
2228
|
+
}
|
|
2229
|
+
async function signTransaction(keyPairs, transaction) {
|
|
2230
|
+
const compiledMessage = compileMessage(transaction);
|
|
2231
|
+
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
2232
|
+
const wireMessageBytes = getCompiledMessageEncoder().encode(compiledMessage);
|
|
2233
|
+
const publicKeySignaturePairs = await Promise.all(
|
|
2234
|
+
keyPairs.map(
|
|
2235
|
+
(keyPair) => Promise.all([getAddressFromPublicKey(keyPair.publicKey), signBytes(keyPair.privateKey, wireMessageBytes)])
|
|
2236
|
+
)
|
|
2237
|
+
);
|
|
2238
|
+
for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
|
|
2239
|
+
nextSignatures[signerPublicKey] = signature;
|
|
2240
|
+
}
|
|
2241
|
+
const out = {
|
|
2242
|
+
...transaction,
|
|
2243
|
+
signatures: nextSignatures
|
|
2244
|
+
};
|
|
2245
|
+
Object.freeze(out);
|
|
2246
|
+
return out;
|
|
2247
|
+
}
|
|
2248
|
+
function transactionSignature(putativeTransactionSignature) {
|
|
2249
|
+
assertIsTransactionSignature(putativeTransactionSignature);
|
|
2250
|
+
return putativeTransactionSignature;
|
|
2251
|
+
}
|
|
2252
|
+
function assertTransactionIsFullySigned(transaction) {
|
|
2253
|
+
const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => i.accounts?.filter((a) => isSignerRole2(a.role)) ?? []).map((a) => a.address);
|
|
2254
|
+
const requiredSigners = /* @__PURE__ */ new Set([transaction.feePayer, ...signerAddressesFromInstructions]);
|
|
2255
|
+
requiredSigners.forEach((address2) => {
|
|
2256
|
+
if (!transaction.signatures[address2]) {
|
|
2257
|
+
throw new Error(`Transaction is missing signature for address \`${address2}\``);
|
|
2258
|
+
}
|
|
2259
|
+
});
|
|
2260
|
+
}
|
|
2261
|
+
function getBase64EncodedWireTransaction(transaction) {
|
|
2262
|
+
const wireTransactionBytes = getTransactionEncoder().encode(transaction);
|
|
2263
|
+
{
|
|
2264
|
+
return btoa(String.fromCharCode(...wireTransactionBytes));
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
|
|
2268
|
+
// src/airdrop.ts
|
|
2269
|
+
init_env_shim();
|
|
2270
|
+
|
|
2271
|
+
// src/airdrop-confirmer.ts
|
|
2272
|
+
init_env_shim();
|
|
2273
|
+
|
|
2274
|
+
// src/transaction-confirmation-strategy-racer.ts
|
|
2275
|
+
init_env_shim();
|
|
2276
|
+
async function raceStrategies(signature, config, getSpecificStrategiesForRace) {
|
|
2277
|
+
const { abortSignal: callerAbortSignal, commitment, getRecentSignatureConfirmationPromise } = config;
|
|
2278
|
+
callerAbortSignal?.throwIfAborted();
|
|
2279
|
+
const abortController = new AbortController();
|
|
2280
|
+
if (callerAbortSignal) {
|
|
2281
|
+
const handleAbort = () => {
|
|
2282
|
+
abortController.abort();
|
|
2283
|
+
};
|
|
2284
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
2285
|
+
}
|
|
2286
|
+
try {
|
|
2287
|
+
const specificStrategies = getSpecificStrategiesForRace({
|
|
2288
|
+
...config,
|
|
2289
|
+
abortSignal: abortController.signal
|
|
2290
|
+
});
|
|
2291
|
+
return await Promise.race([
|
|
2292
|
+
getRecentSignatureConfirmationPromise({
|
|
2293
|
+
abortSignal: abortController.signal,
|
|
2294
|
+
commitment,
|
|
2295
|
+
signature
|
|
2296
|
+
}),
|
|
2297
|
+
...specificStrategies
|
|
2298
|
+
]);
|
|
2299
|
+
} finally {
|
|
2300
|
+
abortController.abort();
|
|
2301
|
+
}
|
|
2302
|
+
}
|
|
2303
|
+
|
|
2304
|
+
// src/transaction-confirmation-strategy-recent-signature.ts
|
|
2305
|
+
init_env_shim();
|
|
2306
|
+
function createRecentSignatureConfirmationPromiseFactory(rpc, rpcSubscriptions) {
|
|
2307
|
+
return async function getRecentSignatureConfirmationPromise({
|
|
2308
|
+
abortSignal: callerAbortSignal,
|
|
2309
|
+
commitment,
|
|
2310
|
+
signature
|
|
2311
|
+
}) {
|
|
2312
|
+
const abortController = new AbortController();
|
|
2313
|
+
function handleAbort() {
|
|
2314
|
+
abortController.abort();
|
|
2315
|
+
}
|
|
2316
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
2317
|
+
const signatureStatusNotifications = await rpcSubscriptions.signatureNotifications(signature, { commitment }).subscribe({ abortSignal: abortController.signal });
|
|
2318
|
+
const signatureDidCommitPromise = (async () => {
|
|
2319
|
+
for await (const signatureStatusNotification of signatureStatusNotifications) {
|
|
2320
|
+
if (signatureStatusNotification.value.err) {
|
|
2321
|
+
throw new Error(`The transaction with signature \`${signature}\` failed.`, {
|
|
2322
|
+
cause: signatureStatusNotification.value.err
|
|
2323
|
+
});
|
|
2324
|
+
} else {
|
|
2325
|
+
return;
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
})();
|
|
2329
|
+
const signatureStatusLookupPromise = (async () => {
|
|
2330
|
+
const { value: signatureStatusResults } = await rpc.getSignatureStatuses([signature]).send({ abortSignal: abortController.signal });
|
|
2331
|
+
const signatureStatus = signatureStatusResults[0];
|
|
2332
|
+
if (signatureStatus && signatureStatus.confirmationStatus && commitmentComparator(signatureStatus.confirmationStatus, commitment) >= 0) {
|
|
2333
|
+
return;
|
|
2334
|
+
} else {
|
|
2335
|
+
await new Promise(() => {
|
|
2336
|
+
});
|
|
2337
|
+
}
|
|
2338
|
+
})();
|
|
2339
|
+
try {
|
|
2340
|
+
return await Promise.race([signatureDidCommitPromise, signatureStatusLookupPromise]);
|
|
2341
|
+
} finally {
|
|
2342
|
+
abortController.abort();
|
|
2343
|
+
}
|
|
2344
|
+
};
|
|
2345
|
+
}
|
|
2346
|
+
|
|
2347
|
+
// src/transaction-confirmation-strategy-timeout.ts
|
|
2348
|
+
init_env_shim();
|
|
2349
|
+
async function getTimeoutPromise({ abortSignal: callerAbortSignal, commitment }) {
|
|
2350
|
+
return await new Promise((_, reject) => {
|
|
2351
|
+
const handleAbort = (e3) => {
|
|
2352
|
+
clearTimeout(timeoutId);
|
|
2353
|
+
const abortError = new DOMException(e3.target.reason, "AbortError");
|
|
2354
|
+
reject(abortError);
|
|
2355
|
+
};
|
|
2356
|
+
callerAbortSignal.addEventListener("abort", handleAbort);
|
|
2357
|
+
const timeoutMs = commitment === "processed" ? 3e4 : 6e4;
|
|
2358
|
+
const startMs = performance.now();
|
|
2359
|
+
const timeoutId = (
|
|
2360
|
+
// We use `setTimeout` instead of `AbortSignal.timeout()` because we want to measure
|
|
2361
|
+
// elapsed time instead of active time.
|
|
2362
|
+
// See https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static
|
|
2363
|
+
setTimeout(() => {
|
|
2364
|
+
const elapsedMs = performance.now() - startMs;
|
|
2365
|
+
reject(new DOMException(`Timeout elapsed after ${elapsedMs} ms`, "TimeoutError"));
|
|
2366
|
+
}, timeoutMs)
|
|
2367
|
+
);
|
|
2368
|
+
});
|
|
2369
|
+
}
|
|
2370
|
+
|
|
2371
|
+
// src/airdrop-confirmer.ts
|
|
2372
|
+
function createDefaultSignatureOnlyRecentTransactionConfirmer({
|
|
2373
|
+
rpc,
|
|
2374
|
+
rpcSubscriptions
|
|
2375
|
+
}) {
|
|
2376
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
2377
|
+
rpc,
|
|
2378
|
+
rpcSubscriptions
|
|
2379
|
+
);
|
|
2380
|
+
return async function confirmSignatureOnlyRecentTransaction(config) {
|
|
2381
|
+
await waitForRecentTransactionConfirmationUntilTimeout({
|
|
2382
|
+
...config,
|
|
2383
|
+
getRecentSignatureConfirmationPromise,
|
|
2384
|
+
getTimeoutPromise
|
|
2385
|
+
});
|
|
2386
|
+
};
|
|
2387
|
+
}
|
|
2388
|
+
async function waitForRecentTransactionConfirmationUntilTimeout(config) {
|
|
2389
|
+
await raceStrategies(
|
|
2390
|
+
config.signature,
|
|
2391
|
+
config,
|
|
2392
|
+
function getSpecificStrategiesForRace({ abortSignal, commitment, getTimeoutPromise: getTimeoutPromise2 }) {
|
|
2393
|
+
return [
|
|
2394
|
+
getTimeoutPromise2({
|
|
2395
|
+
abortSignal,
|
|
2396
|
+
commitment
|
|
2397
|
+
})
|
|
2398
|
+
];
|
|
2399
|
+
}
|
|
2400
|
+
);
|
|
2401
|
+
}
|
|
2402
|
+
|
|
2403
|
+
// src/airdrop.ts
|
|
2404
|
+
function createDefaultAirdropRequester({ rpc, rpcSubscriptions }) {
|
|
2405
|
+
const confirmSignatureOnlyTransaction = createDefaultSignatureOnlyRecentTransactionConfirmer({
|
|
2406
|
+
rpc,
|
|
2407
|
+
rpcSubscriptions
|
|
2408
|
+
});
|
|
2409
|
+
return async function requestAirdrop(config) {
|
|
2410
|
+
return await requestAndConfirmAirdrop({
|
|
2411
|
+
...config,
|
|
2412
|
+
confirmSignatureOnlyTransaction,
|
|
2413
|
+
rpc
|
|
2414
|
+
});
|
|
2415
|
+
};
|
|
2416
|
+
}
|
|
2417
|
+
async function requestAndConfirmAirdrop({
|
|
2418
|
+
abortSignal,
|
|
2419
|
+
commitment,
|
|
2420
|
+
confirmSignatureOnlyTransaction,
|
|
2421
|
+
lamports: lamports2,
|
|
2422
|
+
recipientAddress,
|
|
2423
|
+
rpc
|
|
2424
|
+
}) {
|
|
2425
|
+
const airdropTransactionSignature = await rpc.requestAirdrop(recipientAddress, lamports2, { commitment }).send({ abortSignal });
|
|
2426
|
+
await confirmSignatureOnlyTransaction({
|
|
2427
|
+
abortSignal,
|
|
2428
|
+
commitment,
|
|
2429
|
+
signature: airdropTransactionSignature
|
|
2430
|
+
});
|
|
2431
|
+
return airdropTransactionSignature;
|
|
2432
|
+
}
|
|
2433
|
+
|
|
2434
|
+
// src/rpc.ts
|
|
2435
|
+
init_env_shim();
|
|
2436
|
+
|
|
2437
|
+
// ../rpc-core/dist/index.browser.js
|
|
2438
|
+
init_env_shim();
|
|
2439
|
+
function visitNode(value, keyPath, onIntegerOverflow) {
|
|
2440
|
+
if (Array.isArray(value)) {
|
|
2441
|
+
return value.map(
|
|
2442
|
+
(element, ii) => visitNode(element, [...keyPath, ii], onIntegerOverflow)
|
|
2443
|
+
);
|
|
2444
|
+
} else if (typeof value === "object" && value !== null) {
|
|
2445
|
+
const out = {};
|
|
2446
|
+
for (const propName in value) {
|
|
2447
|
+
if (Object.prototype.hasOwnProperty.call(value, propName)) {
|
|
2448
|
+
out[propName] = visitNode(value[propName], [...keyPath, propName], onIntegerOverflow);
|
|
2449
|
+
}
|
|
2450
|
+
}
|
|
2451
|
+
return out;
|
|
2452
|
+
} else if (typeof value === "bigint") {
|
|
2453
|
+
if (onIntegerOverflow && (value > Number.MAX_SAFE_INTEGER || value < -Number.MAX_SAFE_INTEGER)) {
|
|
2454
|
+
onIntegerOverflow(keyPath, value);
|
|
2455
|
+
}
|
|
2456
|
+
return Number(value);
|
|
2457
|
+
} else {
|
|
2458
|
+
return value;
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
function patchParamsForSolanaLabsRpc(params, onIntegerOverflow) {
|
|
2462
|
+
return visitNode(params, [], onIntegerOverflow);
|
|
2463
|
+
}
|
|
2464
|
+
var KEYPATH_WILDCARD = {};
|
|
2465
|
+
var jsonParsedTokenAccountsConfigs = [
|
|
2466
|
+
// parsed Token/Token22 token account
|
|
2467
|
+
["data", "parsed", "info", "tokenAmount", "decimals"],
|
|
2468
|
+
["data", "parsed", "info", "tokenAmount", "uiAmount"],
|
|
2469
|
+
["data", "parsed", "info", "rentExemptReserve", "decimals"],
|
|
2470
|
+
["data", "parsed", "info", "rentExemptReserve", "uiAmount"],
|
|
2471
|
+
["data", "parsed", "info", "delegatedAmount", "decimals"],
|
|
2472
|
+
["data", "parsed", "info", "delegatedAmount", "uiAmount"],
|
|
2473
|
+
["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "olderTransferFee", "transferFeeBasisPoints"],
|
|
2474
|
+
["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "newerTransferFee", "transferFeeBasisPoints"],
|
|
2475
|
+
["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "preUpdateAverageRate"],
|
|
2476
|
+
["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "currentRate"]
|
|
2477
|
+
];
|
|
2478
|
+
var jsonParsedAccountsConfigs = [
|
|
2479
|
+
...jsonParsedTokenAccountsConfigs,
|
|
2480
|
+
// parsed AddressTableLookup account
|
|
2481
|
+
["data", "parsed", "info", "lastExtendedSlotStartIndex"],
|
|
2482
|
+
// parsed Config account
|
|
2483
|
+
["data", "parsed", "info", "slashPenalty"],
|
|
2484
|
+
["data", "parsed", "info", "warmupCooldownRate"],
|
|
2485
|
+
// parsed Token/Token22 mint account
|
|
2486
|
+
["data", "parsed", "info", "decimals"],
|
|
2487
|
+
// parsed Token/Token22 multisig account
|
|
2488
|
+
["data", "parsed", "info", "numRequiredSigners"],
|
|
2489
|
+
["data", "parsed", "info", "numValidSigners"],
|
|
2490
|
+
// parsed Stake account
|
|
2491
|
+
["data", "parsed", "info", "stake", "delegation", "warmupCooldownRate"],
|
|
2492
|
+
// parsed Sysvar rent account
|
|
2493
|
+
["data", "parsed", "info", "exemptionThreshold"],
|
|
2494
|
+
["data", "parsed", "info", "burnPercent"],
|
|
2495
|
+
// parsed Vote account
|
|
2496
|
+
["data", "parsed", "info", "commission"],
|
|
2497
|
+
["data", "parsed", "info", "votes", KEYPATH_WILDCARD, "confirmationCount"]
|
|
2498
|
+
];
|
|
2499
|
+
var memoizedNotificationKeypaths;
|
|
2500
|
+
var memoizedResponseKeypaths;
|
|
2501
|
+
function getAllowedNumericKeypathsForNotification() {
|
|
2502
|
+
if (!memoizedNotificationKeypaths) {
|
|
2503
|
+
memoizedNotificationKeypaths = {
|
|
2504
|
+
accountNotifications: jsonParsedAccountsConfigs.map((c) => ["value", ...c]),
|
|
2505
|
+
blockNotifications: [
|
|
2506
|
+
["value", "block", "blockTime"],
|
|
2507
|
+
[
|
|
2508
|
+
"value",
|
|
2509
|
+
"block",
|
|
2510
|
+
"transactions",
|
|
2511
|
+
KEYPATH_WILDCARD,
|
|
2512
|
+
"meta",
|
|
2513
|
+
"preTokenBalances",
|
|
2514
|
+
KEYPATH_WILDCARD,
|
|
2515
|
+
"accountIndex"
|
|
2516
|
+
],
|
|
2517
|
+
[
|
|
2518
|
+
"value",
|
|
2519
|
+
"block",
|
|
2520
|
+
"transactions",
|
|
2521
|
+
KEYPATH_WILDCARD,
|
|
2522
|
+
"meta",
|
|
2523
|
+
"preTokenBalances",
|
|
2524
|
+
KEYPATH_WILDCARD,
|
|
2525
|
+
"uiTokenAmount",
|
|
2526
|
+
"decimals"
|
|
2527
|
+
],
|
|
2528
|
+
[
|
|
2529
|
+
"value",
|
|
2530
|
+
"block",
|
|
2531
|
+
"transactions",
|
|
2532
|
+
KEYPATH_WILDCARD,
|
|
2533
|
+
"meta",
|
|
2534
|
+
"postTokenBalances",
|
|
2535
|
+
KEYPATH_WILDCARD,
|
|
2536
|
+
"accountIndex"
|
|
2537
|
+
],
|
|
2538
|
+
[
|
|
2539
|
+
"value",
|
|
2540
|
+
"block",
|
|
2541
|
+
"transactions",
|
|
2542
|
+
KEYPATH_WILDCARD,
|
|
2543
|
+
"meta",
|
|
2544
|
+
"postTokenBalances",
|
|
2545
|
+
KEYPATH_WILDCARD,
|
|
2546
|
+
"uiTokenAmount",
|
|
2547
|
+
"decimals"
|
|
2548
|
+
],
|
|
2549
|
+
["value", "block", "transactions", KEYPATH_WILDCARD, "meta", "rewards", KEYPATH_WILDCARD, "commission"],
|
|
2550
|
+
[
|
|
2551
|
+
"value",
|
|
2552
|
+
"block",
|
|
2553
|
+
"transactions",
|
|
2554
|
+
KEYPATH_WILDCARD,
|
|
2555
|
+
"meta",
|
|
2556
|
+
"innerInstructions",
|
|
2557
|
+
KEYPATH_WILDCARD,
|
|
2558
|
+
"index"
|
|
2559
|
+
],
|
|
2560
|
+
[
|
|
2561
|
+
"value",
|
|
2562
|
+
"block",
|
|
2563
|
+
"transactions",
|
|
2564
|
+
KEYPATH_WILDCARD,
|
|
2565
|
+
"meta",
|
|
2566
|
+
"innerInstructions",
|
|
2567
|
+
KEYPATH_WILDCARD,
|
|
2568
|
+
"instructions",
|
|
2569
|
+
KEYPATH_WILDCARD,
|
|
2570
|
+
"programIdIndex"
|
|
2571
|
+
],
|
|
2572
|
+
[
|
|
2573
|
+
"value",
|
|
2574
|
+
"block",
|
|
2575
|
+
"transactions",
|
|
2576
|
+
KEYPATH_WILDCARD,
|
|
2577
|
+
"meta",
|
|
2578
|
+
"innerInstructions",
|
|
2579
|
+
KEYPATH_WILDCARD,
|
|
2580
|
+
"instructions",
|
|
2581
|
+
KEYPATH_WILDCARD,
|
|
2582
|
+
"accounts",
|
|
2583
|
+
KEYPATH_WILDCARD
|
|
2584
|
+
],
|
|
2585
|
+
[
|
|
2586
|
+
"value",
|
|
2587
|
+
"block",
|
|
2588
|
+
"transactions",
|
|
2589
|
+
KEYPATH_WILDCARD,
|
|
2590
|
+
"transaction",
|
|
2591
|
+
"message",
|
|
2592
|
+
"addressTableLookups",
|
|
2593
|
+
KEYPATH_WILDCARD,
|
|
2594
|
+
"writableIndexes",
|
|
2595
|
+
KEYPATH_WILDCARD
|
|
2596
|
+
],
|
|
2597
|
+
[
|
|
2598
|
+
"value",
|
|
2599
|
+
"block",
|
|
2600
|
+
"transactions",
|
|
2601
|
+
KEYPATH_WILDCARD,
|
|
2602
|
+
"transaction",
|
|
2603
|
+
"message",
|
|
2604
|
+
"addressTableLookups",
|
|
2605
|
+
KEYPATH_WILDCARD,
|
|
2606
|
+
"readonlyIndexes",
|
|
2607
|
+
KEYPATH_WILDCARD
|
|
2608
|
+
],
|
|
2609
|
+
[
|
|
2610
|
+
"value",
|
|
2611
|
+
"block",
|
|
2612
|
+
"transactions",
|
|
2613
|
+
KEYPATH_WILDCARD,
|
|
2614
|
+
"transaction",
|
|
2615
|
+
"message",
|
|
2616
|
+
"instructions",
|
|
2617
|
+
KEYPATH_WILDCARD,
|
|
2618
|
+
"programIdIndex"
|
|
2619
|
+
],
|
|
2620
|
+
[
|
|
2621
|
+
"value",
|
|
2622
|
+
"block",
|
|
2623
|
+
"transactions",
|
|
2624
|
+
KEYPATH_WILDCARD,
|
|
2625
|
+
"transaction",
|
|
2626
|
+
"message",
|
|
2627
|
+
"instructions",
|
|
2628
|
+
KEYPATH_WILDCARD,
|
|
2629
|
+
"accounts",
|
|
2630
|
+
KEYPATH_WILDCARD
|
|
2631
|
+
],
|
|
2632
|
+
[
|
|
2633
|
+
"value",
|
|
2634
|
+
"block",
|
|
2635
|
+
"transactions",
|
|
2636
|
+
KEYPATH_WILDCARD,
|
|
2637
|
+
"transaction",
|
|
2638
|
+
"message",
|
|
2639
|
+
"header",
|
|
2640
|
+
"numReadonlySignedAccounts"
|
|
2641
|
+
],
|
|
2642
|
+
[
|
|
2643
|
+
"value",
|
|
2644
|
+
"block",
|
|
2645
|
+
"transactions",
|
|
2646
|
+
KEYPATH_WILDCARD,
|
|
2647
|
+
"transaction",
|
|
2648
|
+
"message",
|
|
2649
|
+
"header",
|
|
2650
|
+
"numReadonlyUnsignedAccounts"
|
|
2651
|
+
],
|
|
2652
|
+
[
|
|
2653
|
+
"value",
|
|
2654
|
+
"block",
|
|
2655
|
+
"transactions",
|
|
2656
|
+
KEYPATH_WILDCARD,
|
|
2657
|
+
"transaction",
|
|
2658
|
+
"message",
|
|
2659
|
+
"header",
|
|
2660
|
+
"numRequiredSignatures"
|
|
2661
|
+
],
|
|
2662
|
+
["value", "block", "rewards", KEYPATH_WILDCARD, "commission"]
|
|
2663
|
+
],
|
|
2664
|
+
programNotifications: jsonParsedAccountsConfigs.flatMap((c) => [
|
|
2665
|
+
["value", KEYPATH_WILDCARD, "account", ...c],
|
|
2666
|
+
[KEYPATH_WILDCARD, "account", ...c]
|
|
2667
|
+
])
|
|
2668
|
+
};
|
|
2669
|
+
}
|
|
2670
|
+
return memoizedNotificationKeypaths;
|
|
2671
|
+
}
|
|
2672
|
+
function getAllowedNumericKeypathsForResponse() {
|
|
2673
|
+
if (!memoizedResponseKeypaths) {
|
|
2674
|
+
memoizedResponseKeypaths = {
|
|
2675
|
+
getAccountInfo: jsonParsedAccountsConfigs.map((c) => ["value", ...c]),
|
|
2676
|
+
getBlock: [
|
|
2677
|
+
["blockTime"],
|
|
2678
|
+
["transactions", KEYPATH_WILDCARD, "meta", "preTokenBalances", KEYPATH_WILDCARD, "accountIndex"],
|
|
2679
|
+
[
|
|
2680
|
+
"transactions",
|
|
2681
|
+
KEYPATH_WILDCARD,
|
|
2682
|
+
"meta",
|
|
2683
|
+
"preTokenBalances",
|
|
2684
|
+
KEYPATH_WILDCARD,
|
|
2685
|
+
"uiTokenAmount",
|
|
2686
|
+
"decimals"
|
|
2687
|
+
],
|
|
2688
|
+
["transactions", KEYPATH_WILDCARD, "meta", "postTokenBalances", KEYPATH_WILDCARD, "accountIndex"],
|
|
2689
|
+
[
|
|
2690
|
+
"transactions",
|
|
2691
|
+
KEYPATH_WILDCARD,
|
|
2692
|
+
"meta",
|
|
2693
|
+
"postTokenBalances",
|
|
2694
|
+
KEYPATH_WILDCARD,
|
|
2695
|
+
"uiTokenAmount",
|
|
2696
|
+
"decimals"
|
|
2697
|
+
],
|
|
2698
|
+
["transactions", KEYPATH_WILDCARD, "meta", "rewards", KEYPATH_WILDCARD, "commission"],
|
|
2699
|
+
["transactions", KEYPATH_WILDCARD, "meta", "innerInstructions", KEYPATH_WILDCARD, "index"],
|
|
2700
|
+
[
|
|
2701
|
+
"transactions",
|
|
2702
|
+
KEYPATH_WILDCARD,
|
|
2703
|
+
"meta",
|
|
2704
|
+
"innerInstructions",
|
|
2705
|
+
KEYPATH_WILDCARD,
|
|
2706
|
+
"instructions",
|
|
2707
|
+
KEYPATH_WILDCARD,
|
|
2708
|
+
"programIdIndex"
|
|
2709
|
+
],
|
|
2710
|
+
[
|
|
2711
|
+
"transactions",
|
|
2712
|
+
KEYPATH_WILDCARD,
|
|
2713
|
+
"meta",
|
|
2714
|
+
"innerInstructions",
|
|
2715
|
+
KEYPATH_WILDCARD,
|
|
2716
|
+
"instructions",
|
|
2717
|
+
KEYPATH_WILDCARD,
|
|
2718
|
+
"accounts",
|
|
2719
|
+
KEYPATH_WILDCARD
|
|
2720
|
+
],
|
|
2721
|
+
[
|
|
2722
|
+
"transactions",
|
|
2723
|
+
KEYPATH_WILDCARD,
|
|
2724
|
+
"transaction",
|
|
2725
|
+
"message",
|
|
2726
|
+
"addressTableLookups",
|
|
2727
|
+
KEYPATH_WILDCARD,
|
|
2728
|
+
"writableIndexes",
|
|
2729
|
+
KEYPATH_WILDCARD
|
|
2730
|
+
],
|
|
2731
|
+
[
|
|
2732
|
+
"transactions",
|
|
2733
|
+
KEYPATH_WILDCARD,
|
|
2734
|
+
"transaction",
|
|
2735
|
+
"message",
|
|
2736
|
+
"addressTableLookups",
|
|
2737
|
+
KEYPATH_WILDCARD,
|
|
2738
|
+
"readonlyIndexes",
|
|
2739
|
+
KEYPATH_WILDCARD
|
|
2740
|
+
],
|
|
2741
|
+
[
|
|
2742
|
+
"transactions",
|
|
2743
|
+
KEYPATH_WILDCARD,
|
|
2744
|
+
"transaction",
|
|
2745
|
+
"message",
|
|
2746
|
+
"instructions",
|
|
2747
|
+
KEYPATH_WILDCARD,
|
|
2748
|
+
"programIdIndex"
|
|
2749
|
+
],
|
|
2750
|
+
[
|
|
2751
|
+
"transactions",
|
|
2752
|
+
KEYPATH_WILDCARD,
|
|
2753
|
+
"transaction",
|
|
2754
|
+
"message",
|
|
2755
|
+
"instructions",
|
|
2756
|
+
KEYPATH_WILDCARD,
|
|
2757
|
+
"accounts",
|
|
2758
|
+
KEYPATH_WILDCARD
|
|
2759
|
+
],
|
|
2760
|
+
["transactions", KEYPATH_WILDCARD, "transaction", "message", "header", "numReadonlySignedAccounts"],
|
|
2761
|
+
["transactions", KEYPATH_WILDCARD, "transaction", "message", "header", "numReadonlyUnsignedAccounts"],
|
|
2762
|
+
["transactions", KEYPATH_WILDCARD, "transaction", "message", "header", "numRequiredSignatures"],
|
|
2763
|
+
["rewards", KEYPATH_WILDCARD, "commission"]
|
|
2764
|
+
],
|
|
2765
|
+
getBlockTime: [[]],
|
|
2766
|
+
getClusterNodes: [
|
|
2767
|
+
[KEYPATH_WILDCARD, "featureSet"],
|
|
2768
|
+
[KEYPATH_WILDCARD, "shredVersion"]
|
|
2769
|
+
],
|
|
2770
|
+
getInflationGovernor: [["initial"], ["foundation"], ["foundationTerm"], ["taper"], ["terminal"]],
|
|
2771
|
+
getInflationRate: [["foundation"], ["total"], ["validator"]],
|
|
2772
|
+
getInflationReward: [[KEYPATH_WILDCARD, "commission"]],
|
|
2773
|
+
getMultipleAccounts: jsonParsedAccountsConfigs.map((c) => ["value", KEYPATH_WILDCARD, ...c]),
|
|
2774
|
+
getProgramAccounts: jsonParsedAccountsConfigs.flatMap((c) => [
|
|
2775
|
+
["value", KEYPATH_WILDCARD, "account", ...c],
|
|
2776
|
+
[KEYPATH_WILDCARD, "account", ...c]
|
|
2777
|
+
]),
|
|
2778
|
+
getRecentPerformanceSamples: [[KEYPATH_WILDCARD, "samplePeriodSecs"]],
|
|
2779
|
+
getTokenAccountBalance: [
|
|
2780
|
+
["value", "decimals"],
|
|
2781
|
+
["value", "uiAmount"]
|
|
2782
|
+
],
|
|
2783
|
+
getTokenAccountsByDelegate: jsonParsedTokenAccountsConfigs.map((c) => [
|
|
2784
|
+
"value",
|
|
2785
|
+
KEYPATH_WILDCARD,
|
|
2786
|
+
"account",
|
|
2787
|
+
...c
|
|
2788
|
+
]),
|
|
2789
|
+
getTokenAccountsByOwner: jsonParsedTokenAccountsConfigs.map((c) => [
|
|
2790
|
+
"value",
|
|
2791
|
+
KEYPATH_WILDCARD,
|
|
2792
|
+
"account",
|
|
2793
|
+
...c
|
|
2794
|
+
]),
|
|
2795
|
+
getTokenLargestAccounts: [
|
|
2796
|
+
["value", KEYPATH_WILDCARD, "decimals"],
|
|
2797
|
+
["value", KEYPATH_WILDCARD, "uiAmount"]
|
|
2798
|
+
],
|
|
2799
|
+
getTokenSupply: [
|
|
2800
|
+
["value", "decimals"],
|
|
2801
|
+
["value", "uiAmount"]
|
|
2802
|
+
],
|
|
2803
|
+
getTransaction: [
|
|
2804
|
+
["meta", "preTokenBalances", KEYPATH_WILDCARD, "accountIndex"],
|
|
2805
|
+
["meta", "preTokenBalances", KEYPATH_WILDCARD, "uiTokenAmount", "decimals"],
|
|
2806
|
+
["meta", "postTokenBalances", KEYPATH_WILDCARD, "accountIndex"],
|
|
2807
|
+
["meta", "postTokenBalances", KEYPATH_WILDCARD, "uiTokenAmount", "decimals"],
|
|
2808
|
+
["meta", "rewards", KEYPATH_WILDCARD, "commission"],
|
|
2809
|
+
["meta", "innerInstructions", KEYPATH_WILDCARD, "index"],
|
|
2810
|
+
["meta", "innerInstructions", KEYPATH_WILDCARD, "instructions", KEYPATH_WILDCARD, "programIdIndex"],
|
|
2811
|
+
[
|
|
2812
|
+
"meta",
|
|
2813
|
+
"innerInstructions",
|
|
2814
|
+
KEYPATH_WILDCARD,
|
|
2815
|
+
"instructions",
|
|
2816
|
+
KEYPATH_WILDCARD,
|
|
2817
|
+
"accounts",
|
|
2818
|
+
KEYPATH_WILDCARD
|
|
2819
|
+
],
|
|
2820
|
+
[
|
|
2821
|
+
"transaction",
|
|
2822
|
+
"message",
|
|
2823
|
+
"addressTableLookups",
|
|
2824
|
+
KEYPATH_WILDCARD,
|
|
2825
|
+
"writableIndexes",
|
|
2826
|
+
KEYPATH_WILDCARD
|
|
2827
|
+
],
|
|
2828
|
+
[
|
|
2829
|
+
"transaction",
|
|
2830
|
+
"message",
|
|
2831
|
+
"addressTableLookups",
|
|
2832
|
+
KEYPATH_WILDCARD,
|
|
2833
|
+
"readonlyIndexes",
|
|
2834
|
+
KEYPATH_WILDCARD
|
|
2835
|
+
],
|
|
2836
|
+
["transaction", "message", "instructions", KEYPATH_WILDCARD, "programIdIndex"],
|
|
2837
|
+
["transaction", "message", "instructions", KEYPATH_WILDCARD, "accounts", KEYPATH_WILDCARD],
|
|
2838
|
+
["transaction", "message", "header", "numReadonlySignedAccounts"],
|
|
2839
|
+
["transaction", "message", "header", "numReadonlyUnsignedAccounts"],
|
|
2840
|
+
["transaction", "message", "header", "numRequiredSignatures"]
|
|
2841
|
+
],
|
|
2842
|
+
getVersion: [["feature-set"]],
|
|
2843
|
+
getVoteAccounts: [
|
|
2844
|
+
["current", KEYPATH_WILDCARD, "commission"],
|
|
2845
|
+
["delinquent", KEYPATH_WILDCARD, "commission"]
|
|
2846
|
+
],
|
|
2847
|
+
simulateTransaction: jsonParsedAccountsConfigs.map((c) => ["value", "accounts", KEYPATH_WILDCARD, ...c])
|
|
2848
|
+
};
|
|
2849
|
+
}
|
|
2850
|
+
return memoizedResponseKeypaths;
|
|
2851
|
+
}
|
|
2852
|
+
function getNextAllowedKeypaths(keyPaths, property) {
|
|
2853
|
+
return keyPaths.filter((keyPath) => keyPath[0] === KEYPATH_WILDCARD && typeof property === "number" || keyPath[0] === property).map((keyPath) => keyPath.slice(1));
|
|
2854
|
+
}
|
|
2855
|
+
function visitNode2(value, allowedKeypaths) {
|
|
2856
|
+
if (Array.isArray(value)) {
|
|
2857
|
+
return value.map((element, ii) => {
|
|
2858
|
+
const nextAllowedKeypaths = getNextAllowedKeypaths(allowedKeypaths, ii);
|
|
2859
|
+
return visitNode2(element, nextAllowedKeypaths);
|
|
2860
|
+
});
|
|
2861
|
+
} else if (typeof value === "object" && value !== null) {
|
|
2862
|
+
const out = {};
|
|
2863
|
+
for (const [propName, innerValue] of Object.entries(value)) {
|
|
2864
|
+
const nextAllowedKeypaths = getNextAllowedKeypaths(allowedKeypaths, propName);
|
|
2865
|
+
out[propName] = visitNode2(innerValue, nextAllowedKeypaths);
|
|
2866
|
+
}
|
|
2867
|
+
return out;
|
|
2868
|
+
} else if (typeof value === "number" && // The presence of an allowed keypath on the route to this value implies it's allowlisted;
|
|
2869
|
+
// Upcast the value to `bigint` unless an allowed keypath is present.
|
|
2870
|
+
allowedKeypaths.length === 0 && // Only try to upcast an Integer to `bigint`
|
|
2871
|
+
Number.isInteger(value)) {
|
|
2872
|
+
return BigInt(value);
|
|
2873
|
+
} else {
|
|
2874
|
+
return value;
|
|
2875
|
+
}
|
|
2876
|
+
}
|
|
2877
|
+
function patchResponseForSolanaLabsRpc(rawResponse, methodName) {
|
|
2878
|
+
const allowedKeypaths = methodName ? getAllowedNumericKeypathsForResponse()[methodName] : void 0;
|
|
2879
|
+
return visitNode2(rawResponse, allowedKeypaths ?? []);
|
|
2880
|
+
}
|
|
2881
|
+
function patchResponseForSolanaLabsRpcSubscriptions(rawResponse, methodName) {
|
|
2882
|
+
const allowedKeypaths = methodName ? getAllowedNumericKeypathsForNotification()[methodName] : void 0;
|
|
2883
|
+
return visitNode2(rawResponse, allowedKeypaths ?? []);
|
|
2884
|
+
}
|
|
2885
|
+
function createSolanaRpcApi(config) {
|
|
2886
|
+
return new Proxy({}, {
|
|
2887
|
+
defineProperty() {
|
|
2888
|
+
return false;
|
|
2889
|
+
},
|
|
2890
|
+
deleteProperty() {
|
|
2891
|
+
return false;
|
|
2892
|
+
},
|
|
2893
|
+
get(...args) {
|
|
2894
|
+
const [_, p] = args;
|
|
2895
|
+
const methodName = p.toString();
|
|
2896
|
+
return function(...rawParams) {
|
|
2897
|
+
const handleIntegerOverflow = config?.onIntegerOverflow;
|
|
2898
|
+
const params = patchParamsForSolanaLabsRpc(
|
|
2899
|
+
rawParams,
|
|
2900
|
+
handleIntegerOverflow ? (keyPath, value) => handleIntegerOverflow(methodName, keyPath, value) : void 0
|
|
2901
|
+
);
|
|
2902
|
+
return {
|
|
2903
|
+
methodName,
|
|
2904
|
+
params,
|
|
2905
|
+
responseProcessor: (rawResponse) => patchResponseForSolanaLabsRpc(rawResponse, methodName)
|
|
2906
|
+
};
|
|
2907
|
+
};
|
|
2908
|
+
}
|
|
2909
|
+
});
|
|
2910
|
+
}
|
|
2911
|
+
function createSolanaRpcSubscriptionsApi(config) {
|
|
2912
|
+
return new Proxy({}, {
|
|
2913
|
+
defineProperty() {
|
|
2914
|
+
return false;
|
|
2915
|
+
},
|
|
2916
|
+
deleteProperty() {
|
|
2917
|
+
return false;
|
|
2918
|
+
},
|
|
2919
|
+
get(...args) {
|
|
2920
|
+
const [_, p] = args;
|
|
2921
|
+
const notificationName = p.toString();
|
|
2922
|
+
return function(...rawParams) {
|
|
2923
|
+
const handleIntegerOverflow = config?.onIntegerOverflow;
|
|
2924
|
+
const params = patchParamsForSolanaLabsRpc(
|
|
2925
|
+
rawParams,
|
|
2926
|
+
handleIntegerOverflow ? (keyPath, value) => handleIntegerOverflow(notificationName, keyPath, value) : void 0
|
|
2927
|
+
);
|
|
2928
|
+
return {
|
|
2929
|
+
params,
|
|
2930
|
+
responseProcessor: (rawResponse) => patchResponseForSolanaLabsRpcSubscriptions(rawResponse, notificationName),
|
|
2931
|
+
subscribeMethodName: notificationName.replace(/Notifications$/, "Subscribe"),
|
|
2932
|
+
unsubscribeMethodName: notificationName.replace(/Notifications$/, "Unsubscribe")
|
|
2933
|
+
};
|
|
2934
|
+
};
|
|
2935
|
+
}
|
|
2936
|
+
});
|
|
2937
|
+
}
|
|
2938
|
+
function createSolanaRpcSubscriptionsApi_UNSTABLE(config) {
|
|
2939
|
+
return createSolanaRpcSubscriptionsApi(config);
|
|
2940
|
+
}
|
|
2941
|
+
|
|
2942
|
+
// ../rpc-transport/dist/index.browser.js
|
|
2943
|
+
init_env_shim();
|
|
2944
|
+
var SolanaJsonRpcError = class extends Error {
|
|
2945
|
+
constructor(details) {
|
|
2946
|
+
super(`JSON-RPC 2.0 error (${details.code}): ${details.message}`);
|
|
2947
|
+
Error.captureStackTrace(this, this.constructor);
|
|
2948
|
+
this.code = details.code;
|
|
2949
|
+
this.data = details.data;
|
|
2950
|
+
}
|
|
2951
|
+
get name() {
|
|
2952
|
+
return "SolanaJsonRpcError";
|
|
2953
|
+
}
|
|
2954
|
+
};
|
|
2955
|
+
var _nextMessageId = 0;
|
|
2956
|
+
function getNextMessageId() {
|
|
2957
|
+
const id = _nextMessageId;
|
|
2958
|
+
_nextMessageId = (_nextMessageId + 1) % Number.MAX_SAFE_INTEGER;
|
|
2959
|
+
return id;
|
|
2960
|
+
}
|
|
2961
|
+
function createJsonRpcMessage(method, params) {
|
|
2962
|
+
return {
|
|
2963
|
+
id: getNextMessageId(),
|
|
2964
|
+
jsonrpc: "2.0",
|
|
2965
|
+
method,
|
|
2966
|
+
params
|
|
2967
|
+
};
|
|
2968
|
+
}
|
|
2969
|
+
function createPendingRpcRequest(rpcConfig, pendingRequest) {
|
|
2970
|
+
return {
|
|
2971
|
+
async send(options) {
|
|
2972
|
+
const { methodName, params, responseProcessor } = pendingRequest;
|
|
2973
|
+
const payload = createJsonRpcMessage(methodName, params);
|
|
2974
|
+
const response = await rpcConfig.transport({
|
|
2975
|
+
payload,
|
|
2976
|
+
signal: options?.abortSignal
|
|
2977
|
+
});
|
|
2978
|
+
if ("error" in response) {
|
|
2979
|
+
throw new SolanaJsonRpcError(response.error);
|
|
2980
|
+
} else {
|
|
2981
|
+
return responseProcessor ? responseProcessor(response.result) : response.result;
|
|
2982
|
+
}
|
|
2983
|
+
}
|
|
2984
|
+
};
|
|
2985
|
+
}
|
|
2986
|
+
function makeProxy(rpcConfig) {
|
|
2987
|
+
return new Proxy(rpcConfig.api, {
|
|
2988
|
+
defineProperty() {
|
|
2989
|
+
return false;
|
|
2990
|
+
},
|
|
2991
|
+
deleteProperty() {
|
|
2992
|
+
return false;
|
|
2993
|
+
},
|
|
2994
|
+
get(target, p, receiver) {
|
|
2995
|
+
return function(...rawParams) {
|
|
2996
|
+
const methodName = p.toString();
|
|
2997
|
+
const createRpcRequest = Reflect.get(target, methodName, receiver);
|
|
2998
|
+
const newRequest = createRpcRequest ? createRpcRequest(...rawParams) : { methodName, params: rawParams };
|
|
2999
|
+
return createPendingRpcRequest(rpcConfig, newRequest);
|
|
3000
|
+
};
|
|
3001
|
+
}
|
|
3002
|
+
});
|
|
3003
|
+
}
|
|
3004
|
+
function createJsonRpc(rpcConfig) {
|
|
3005
|
+
return makeProxy(rpcConfig);
|
|
3006
|
+
}
|
|
3007
|
+
function registerIterableCleanup(iterable, cleanupFn) {
|
|
3008
|
+
(async () => {
|
|
3009
|
+
try {
|
|
3010
|
+
for await (const _ of iterable)
|
|
3011
|
+
;
|
|
3012
|
+
} catch {
|
|
3013
|
+
} finally {
|
|
3014
|
+
cleanupFn();
|
|
3015
|
+
}
|
|
3016
|
+
})();
|
|
3017
|
+
}
|
|
3018
|
+
function createPendingRpcSubscription(rpcConfig, { params, subscribeMethodName, unsubscribeMethodName, responseProcessor }) {
|
|
3019
|
+
return {
|
|
3020
|
+
async subscribe({ abortSignal }) {
|
|
3021
|
+
abortSignal.throwIfAborted();
|
|
3022
|
+
let subscriptionId;
|
|
3023
|
+
function handleCleanup() {
|
|
3024
|
+
if (subscriptionId !== void 0) {
|
|
3025
|
+
const payload = createJsonRpcMessage(unsubscribeMethodName, [subscriptionId]);
|
|
3026
|
+
connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload).finally(() => {
|
|
3027
|
+
connectionAbortController.abort();
|
|
3028
|
+
});
|
|
3029
|
+
} else {
|
|
3030
|
+
connectionAbortController.abort();
|
|
3031
|
+
}
|
|
3032
|
+
}
|
|
3033
|
+
abortSignal.addEventListener("abort", handleCleanup);
|
|
3034
|
+
const connectionAbortController = new AbortController();
|
|
3035
|
+
const subscribeMessage = createJsonRpcMessage(subscribeMethodName, params);
|
|
3036
|
+
const connection = await rpcConfig.transport({
|
|
3037
|
+
payload: subscribeMessage,
|
|
3038
|
+
signal: connectionAbortController.signal
|
|
3039
|
+
});
|
|
3040
|
+
function handleConnectionCleanup() {
|
|
3041
|
+
abortSignal.removeEventListener("abort", handleCleanup);
|
|
3042
|
+
}
|
|
3043
|
+
registerIterableCleanup(connection, handleConnectionCleanup);
|
|
3044
|
+
for await (const message of connection) {
|
|
3045
|
+
if ("id" in message && message.id === subscribeMessage.id) {
|
|
3046
|
+
if ("error" in message) {
|
|
3047
|
+
throw new SolanaJsonRpcError(message.error);
|
|
3048
|
+
} else {
|
|
3049
|
+
subscriptionId = message.result;
|
|
3050
|
+
break;
|
|
3051
|
+
}
|
|
3052
|
+
}
|
|
3053
|
+
}
|
|
3054
|
+
if (subscriptionId == null) {
|
|
3055
|
+
throw new Error("Failed to obtain a subscription id from the server");
|
|
3056
|
+
}
|
|
3057
|
+
return {
|
|
3058
|
+
async *[Symbol.asyncIterator]() {
|
|
3059
|
+
for await (const message of connection) {
|
|
3060
|
+
if (!("params" in message) || message.params.subscription !== subscriptionId) {
|
|
3061
|
+
continue;
|
|
3062
|
+
}
|
|
3063
|
+
const notification = message.params.result;
|
|
3064
|
+
yield responseProcessor ? responseProcessor(notification) : notification;
|
|
3065
|
+
}
|
|
3066
|
+
}
|
|
3067
|
+
};
|
|
3068
|
+
}
|
|
3069
|
+
};
|
|
3070
|
+
}
|
|
3071
|
+
function makeProxy2(rpcConfig) {
|
|
3072
|
+
return new Proxy(rpcConfig.api, {
|
|
3073
|
+
defineProperty() {
|
|
3074
|
+
return false;
|
|
3075
|
+
},
|
|
3076
|
+
deleteProperty() {
|
|
3077
|
+
return false;
|
|
3078
|
+
},
|
|
3079
|
+
get(target, p, receiver) {
|
|
3080
|
+
return function(...rawParams) {
|
|
3081
|
+
const methodName = p.toString();
|
|
3082
|
+
const createRpcSubscription = Reflect.get(target, methodName, receiver);
|
|
3083
|
+
if (p.toString().endsWith("Notifications") === false && !createRpcSubscription) {
|
|
3084
|
+
throw new Error(
|
|
3085
|
+
"Either the notification name must end in 'Notifications' or the API must supply a subscription creator function to map between the notification name and the subscribe/unsubscribe method names."
|
|
3086
|
+
);
|
|
3087
|
+
}
|
|
3088
|
+
const newRequest = createRpcSubscription ? createRpcSubscription(...rawParams) : {
|
|
3089
|
+
params: rawParams,
|
|
3090
|
+
subscribeMethodName: methodName.replace(/Notifications$/, "Subscribe"),
|
|
3091
|
+
unsubscribeMethodName: methodName.replace(/Notifications$/, "Unsubscribe")
|
|
3092
|
+
};
|
|
3093
|
+
return createPendingRpcSubscription(rpcConfig, newRequest);
|
|
3094
|
+
};
|
|
3095
|
+
}
|
|
3096
|
+
});
|
|
3097
|
+
}
|
|
3098
|
+
function createJsonSubscriptionRpc(rpcConfig) {
|
|
3099
|
+
return makeProxy2(rpcConfig);
|
|
3100
|
+
}
|
|
3101
|
+
var e2 = globalThis.fetch;
|
|
3102
|
+
var SolanaHttpError = class extends Error {
|
|
3103
|
+
constructor(details) {
|
|
3104
|
+
super(`HTTP error (${details.statusCode}): ${details.message}`);
|
|
3105
|
+
Error.captureStackTrace(this, this.constructor);
|
|
3106
|
+
this.statusCode = details.statusCode;
|
|
3107
|
+
}
|
|
3108
|
+
get name() {
|
|
3109
|
+
return "SolanaHttpError";
|
|
3110
|
+
}
|
|
3111
|
+
};
|
|
3112
|
+
var DISALLOWED_HEADERS = {
|
|
3113
|
+
accept: true,
|
|
3114
|
+
"content-length": true,
|
|
3115
|
+
"content-type": true
|
|
3116
|
+
};
|
|
3117
|
+
var FORBIDDEN_HEADERS = {
|
|
3118
|
+
"accept-charset": true,
|
|
3119
|
+
"accept-encoding": true,
|
|
3120
|
+
"access-control-request-headers": true,
|
|
3121
|
+
"access-control-request-method": true,
|
|
3122
|
+
connection: true,
|
|
3123
|
+
"content-length": true,
|
|
3124
|
+
cookie: true,
|
|
3125
|
+
date: true,
|
|
3126
|
+
dnt: true,
|
|
3127
|
+
expect: true,
|
|
3128
|
+
host: true,
|
|
3129
|
+
"keep-alive": true,
|
|
3130
|
+
origin: true,
|
|
3131
|
+
"permissions-policy": true,
|
|
3132
|
+
// No currently available Typescript technique allows you to match on a prefix.
|
|
3133
|
+
// 'proxy-':true,
|
|
3134
|
+
// 'sec-':true,
|
|
3135
|
+
referer: true,
|
|
3136
|
+
te: true,
|
|
3137
|
+
trailer: true,
|
|
3138
|
+
"transfer-encoding": true,
|
|
3139
|
+
upgrade: true,
|
|
3140
|
+
via: true
|
|
3141
|
+
};
|
|
3142
|
+
function assertIsAllowedHttpRequestHeaders(headers) {
|
|
3143
|
+
const badHeaders = Object.keys(headers).filter((headerName) => {
|
|
3144
|
+
const lowercaseHeaderName = headerName.toLowerCase();
|
|
3145
|
+
return DISALLOWED_HEADERS[headerName.toLowerCase()] === true || FORBIDDEN_HEADERS[headerName.toLowerCase()] === true || lowercaseHeaderName.startsWith("proxy-") || lowercaseHeaderName.startsWith("sec-");
|
|
3146
|
+
});
|
|
3147
|
+
if (badHeaders.length > 0) {
|
|
3148
|
+
throw new Error(
|
|
3149
|
+
`${badHeaders.length > 1 ? "These headers are" : "This header is"} forbidden: \`${badHeaders.join("`, `")}\`. Learn more at https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name.`
|
|
3150
|
+
);
|
|
3151
|
+
}
|
|
3152
|
+
}
|
|
3153
|
+
function normalizeHeaders(headers) {
|
|
3154
|
+
const out = {};
|
|
3155
|
+
for (const headerName in headers) {
|
|
3156
|
+
out[headerName.toLowerCase()] = headers[headerName];
|
|
3157
|
+
}
|
|
3158
|
+
return out;
|
|
3159
|
+
}
|
|
3160
|
+
function createHttpTransport({ httpAgentNodeOnly, headers, url }) {
|
|
3161
|
+
if (headers) {
|
|
3162
|
+
assertIsAllowedHttpRequestHeaders(headers);
|
|
3163
|
+
}
|
|
3164
|
+
const agent = void 0;
|
|
3165
|
+
if (httpAgentNodeOnly != null) {
|
|
3166
|
+
console.warn(
|
|
3167
|
+
"createHttpTransport(): The `httpAgentNodeOnly` config you supplied has been ignored; HTTP agents are only usable in Node environments."
|
|
3168
|
+
);
|
|
3169
|
+
}
|
|
3170
|
+
const customHeaders = headers && normalizeHeaders(headers);
|
|
3171
|
+
return async function makeHttpRequest({
|
|
3172
|
+
payload,
|
|
3173
|
+
signal
|
|
3174
|
+
}) {
|
|
3175
|
+
const body = JSON.stringify(payload);
|
|
3176
|
+
const requestInfo = {
|
|
3177
|
+
agent,
|
|
3178
|
+
body,
|
|
3179
|
+
headers: {
|
|
3180
|
+
...customHeaders,
|
|
3181
|
+
// Keep these headers lowercase so they will override any user-supplied headers above.
|
|
3182
|
+
accept: "application/json",
|
|
3183
|
+
"content-length": body.length.toString(),
|
|
3184
|
+
"content-type": "application/json; charset=utf-8"
|
|
3185
|
+
},
|
|
3186
|
+
method: "POST",
|
|
3187
|
+
signal
|
|
3188
|
+
};
|
|
3189
|
+
const response = await e2(url, requestInfo);
|
|
3190
|
+
if (!response.ok) {
|
|
3191
|
+
throw new SolanaHttpError({
|
|
3192
|
+
message: response.statusText,
|
|
3193
|
+
statusCode: response.status
|
|
3194
|
+
});
|
|
3195
|
+
}
|
|
3196
|
+
return await response.json();
|
|
3197
|
+
};
|
|
3198
|
+
}
|
|
3199
|
+
var e22 = globalThis.WebSocket;
|
|
3200
|
+
var EXPLICIT_ABORT_TOKEN = Symbol(
|
|
3201
|
+
"This symbol is thrown from a socket's iterator when the connection is explicity aborted by the user"
|
|
3202
|
+
);
|
|
3203
|
+
async function createWebSocketConnection({
|
|
3204
|
+
sendBufferHighWatermark,
|
|
3205
|
+
signal,
|
|
3206
|
+
url
|
|
3207
|
+
}) {
|
|
3208
|
+
return new Promise((resolve, reject) => {
|
|
3209
|
+
signal.addEventListener("abort", handleAbort, { once: true });
|
|
3210
|
+
const iteratorState = /* @__PURE__ */ new Map();
|
|
3211
|
+
function errorAndClearAllIteratorStates(reason) {
|
|
3212
|
+
const errorCallbacks = [...iteratorState.values()].filter((state) => state.__hasPolled).map(({ onError }) => onError);
|
|
3213
|
+
iteratorState.clear();
|
|
3214
|
+
errorCallbacks.forEach((cb) => {
|
|
3215
|
+
try {
|
|
3216
|
+
cb(reason);
|
|
3217
|
+
} catch {
|
|
3218
|
+
}
|
|
3219
|
+
});
|
|
3220
|
+
}
|
|
3221
|
+
function handleAbort() {
|
|
3222
|
+
errorAndClearAllIteratorStates(EXPLICIT_ABORT_TOKEN);
|
|
3223
|
+
if (webSocket.readyState !== e22.CLOSED && webSocket.readyState !== e22.CLOSING) {
|
|
3224
|
+
webSocket.close(1e3);
|
|
3225
|
+
}
|
|
3226
|
+
}
|
|
3227
|
+
function handleClose(ev) {
|
|
3228
|
+
bufferDrainWatcher?.onCancel();
|
|
3229
|
+
signal.removeEventListener("abort", handleAbort);
|
|
3230
|
+
webSocket.removeEventListener("close", handleClose);
|
|
3231
|
+
webSocket.removeEventListener("error", handleError);
|
|
3232
|
+
webSocket.removeEventListener("open", handleOpen);
|
|
3233
|
+
webSocket.removeEventListener("message", handleMessage);
|
|
3234
|
+
errorAndClearAllIteratorStates(ev);
|
|
3235
|
+
}
|
|
3236
|
+
function handleError(ev) {
|
|
3237
|
+
if (!hasConnected) {
|
|
3238
|
+
reject(
|
|
3239
|
+
// TODO: Coded error
|
|
3240
|
+
new Error("WebSocket failed to connect", { cause: ev })
|
|
3241
|
+
);
|
|
3242
|
+
}
|
|
3243
|
+
}
|
|
3244
|
+
let hasConnected = false;
|
|
3245
|
+
let bufferDrainWatcher;
|
|
3246
|
+
function handleOpen() {
|
|
3247
|
+
hasConnected = true;
|
|
3248
|
+
resolve({
|
|
3249
|
+
async send(payload) {
|
|
3250
|
+
const message = JSON.stringify(payload);
|
|
3251
|
+
if (!bufferDrainWatcher && webSocket.readyState === e22.OPEN && webSocket.bufferedAmount > sendBufferHighWatermark) {
|
|
3252
|
+
let onCancel;
|
|
3253
|
+
const promise = new Promise((resolve2, reject2) => {
|
|
3254
|
+
const intervalId = setInterval(() => {
|
|
3255
|
+
if (webSocket.readyState !== e22.OPEN || !(webSocket.bufferedAmount > sendBufferHighWatermark)) {
|
|
3256
|
+
clearInterval(intervalId);
|
|
3257
|
+
bufferDrainWatcher = void 0;
|
|
3258
|
+
resolve2();
|
|
3259
|
+
}
|
|
3260
|
+
}, 16);
|
|
3261
|
+
onCancel = () => {
|
|
3262
|
+
bufferDrainWatcher = void 0;
|
|
3263
|
+
clearInterval(intervalId);
|
|
3264
|
+
reject2(
|
|
3265
|
+
// TODO: Coded error
|
|
3266
|
+
new Error("WebSocket was closed before payload could be sent")
|
|
3267
|
+
);
|
|
3268
|
+
};
|
|
3269
|
+
});
|
|
3270
|
+
bufferDrainWatcher = {
|
|
3271
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3272
|
+
// @ts-ignore
|
|
3273
|
+
onCancel,
|
|
3274
|
+
promise
|
|
3275
|
+
};
|
|
3276
|
+
}
|
|
3277
|
+
if (bufferDrainWatcher) {
|
|
3278
|
+
await bufferDrainWatcher.promise;
|
|
3279
|
+
}
|
|
3280
|
+
webSocket.send(message);
|
|
3281
|
+
},
|
|
3282
|
+
async *[Symbol.asyncIterator]() {
|
|
3283
|
+
const iteratorKey = Symbol();
|
|
3284
|
+
iteratorState.set(iteratorKey, { __hasPolled: false, queuedMessages: [] });
|
|
3285
|
+
try {
|
|
3286
|
+
while (true) {
|
|
3287
|
+
const state = iteratorState.get(iteratorKey);
|
|
3288
|
+
if (!state) {
|
|
3289
|
+
throw new Error("Invariant: WebSocket message iterator is missing state storage");
|
|
3290
|
+
}
|
|
3291
|
+
if (state.__hasPolled) {
|
|
3292
|
+
throw new Error(
|
|
3293
|
+
"Invariant: WebSocket message iterator state is corrupt; iterated without first resolving existing message promise"
|
|
3294
|
+
);
|
|
3295
|
+
}
|
|
3296
|
+
const queuedMessages = state.queuedMessages;
|
|
3297
|
+
if (queuedMessages.length) {
|
|
3298
|
+
state.queuedMessages = [];
|
|
3299
|
+
yield* queuedMessages;
|
|
3300
|
+
} else {
|
|
3301
|
+
try {
|
|
3302
|
+
yield await new Promise((resolve2, reject2) => {
|
|
3303
|
+
iteratorState.set(iteratorKey, {
|
|
3304
|
+
__hasPolled: true,
|
|
3305
|
+
onError: reject2,
|
|
3306
|
+
onMessage: resolve2
|
|
3307
|
+
});
|
|
3308
|
+
});
|
|
3309
|
+
} catch (e3) {
|
|
3310
|
+
if (e3 === EXPLICIT_ABORT_TOKEN) {
|
|
3311
|
+
return;
|
|
3312
|
+
} else {
|
|
3313
|
+
throw new Error("WebSocket connection closed", { cause: e3 });
|
|
3314
|
+
}
|
|
3315
|
+
}
|
|
3316
|
+
}
|
|
3317
|
+
}
|
|
3318
|
+
} finally {
|
|
3319
|
+
iteratorState.delete(iteratorKey);
|
|
3320
|
+
}
|
|
3321
|
+
}
|
|
3322
|
+
});
|
|
3323
|
+
}
|
|
3324
|
+
function handleMessage({ data }) {
|
|
3325
|
+
const message = JSON.parse(data);
|
|
3326
|
+
iteratorState.forEach((state, iteratorKey) => {
|
|
3327
|
+
if (state.__hasPolled) {
|
|
3328
|
+
const { onMessage } = state;
|
|
3329
|
+
iteratorState.set(iteratorKey, { __hasPolled: false, queuedMessages: [] });
|
|
3330
|
+
onMessage(message);
|
|
3331
|
+
} else {
|
|
3332
|
+
state.queuedMessages.push(message);
|
|
3333
|
+
}
|
|
3334
|
+
});
|
|
3335
|
+
}
|
|
3336
|
+
const webSocket = new e22(url);
|
|
3337
|
+
webSocket.addEventListener("close", handleClose);
|
|
3338
|
+
webSocket.addEventListener("error", handleError);
|
|
3339
|
+
webSocket.addEventListener("open", handleOpen);
|
|
3340
|
+
webSocket.addEventListener("message", handleMessage);
|
|
3341
|
+
});
|
|
3342
|
+
}
|
|
3343
|
+
function createWebSocketTransport({ sendBufferHighWatermark, url }) {
|
|
3344
|
+
if (/^wss?:/i.test(url) === false) {
|
|
3345
|
+
const protocolMatch = url.match(/^([^:]+):/);
|
|
3346
|
+
throw new DOMException(
|
|
3347
|
+
protocolMatch ? `Failed to construct 'WebSocket': The URL's scheme must be either 'ws' or 'wss'. '${protocolMatch[1]}:' is not allowed.` : `Failed to construct 'WebSocket': The URL '${url}' is invalid.`
|
|
3348
|
+
);
|
|
3349
|
+
}
|
|
3350
|
+
return async function sendWebSocketMessage({ payload, signal }) {
|
|
3351
|
+
signal?.throwIfAborted();
|
|
3352
|
+
const connection = await createWebSocketConnection({
|
|
3353
|
+
sendBufferHighWatermark,
|
|
3354
|
+
signal,
|
|
3355
|
+
url
|
|
3356
|
+
});
|
|
3357
|
+
signal?.throwIfAborted();
|
|
3358
|
+
await connection.send(payload);
|
|
3359
|
+
return {
|
|
3360
|
+
[Symbol.asyncIterator]: connection[Symbol.asyncIterator].bind(connection),
|
|
3361
|
+
send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: connection.send.bind(connection)
|
|
3362
|
+
};
|
|
3363
|
+
};
|
|
3364
|
+
}
|
|
3365
|
+
|
|
3366
|
+
// src/rpc.ts
|
|
3367
|
+
var import_fast_stable_stringify = __toESM(require_fast_stable_stringify(), 1);
|
|
3368
|
+
|
|
3369
|
+
// src/rpc-default-config.ts
|
|
3370
|
+
init_env_shim();
|
|
3371
|
+
|
|
3372
|
+
// src/rpc-integer-overflow-error.ts
|
|
3373
|
+
init_env_shim();
|
|
3374
|
+
var SolanaJsonRpcIntegerOverflowError = class extends Error {
|
|
3375
|
+
constructor(methodName, keyPath, value) {
|
|
3376
|
+
const argPosition = (typeof keyPath[0] === "number" ? keyPath[0] : parseInt(keyPath[0], 10)) + 1;
|
|
3377
|
+
let ordinal = "";
|
|
3378
|
+
const lastDigit = argPosition % 10;
|
|
3379
|
+
const lastTwoDigits = argPosition % 100;
|
|
3380
|
+
if (lastDigit == 1 && lastTwoDigits != 11) {
|
|
3381
|
+
ordinal = argPosition + "st";
|
|
3382
|
+
} else if (lastDigit == 2 && lastTwoDigits != 12) {
|
|
3383
|
+
ordinal = argPosition + "nd";
|
|
3384
|
+
} else if (lastDigit == 3 && lastTwoDigits != 13) {
|
|
3385
|
+
ordinal = argPosition + "rd";
|
|
3386
|
+
} else {
|
|
3387
|
+
ordinal = argPosition + "th";
|
|
3388
|
+
}
|
|
3389
|
+
const path = keyPath.length > 1 ? keyPath.slice(1).map((pathPart) => typeof pathPart === "number" ? `[${pathPart}]` : pathPart).join(".") : null;
|
|
3390
|
+
super(
|
|
3391
|
+
`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\`.`
|
|
3392
|
+
);
|
|
3393
|
+
this.keyPath = keyPath;
|
|
3394
|
+
this.methodName = methodName;
|
|
3395
|
+
this.value = value;
|
|
3396
|
+
}
|
|
3397
|
+
get name() {
|
|
3398
|
+
return "SolanaJsonRpcIntegerOverflowError";
|
|
3399
|
+
}
|
|
3400
|
+
};
|
|
3401
|
+
|
|
3402
|
+
// src/rpc-default-config.ts
|
|
3403
|
+
var DEFAULT_RPC_CONFIG = {
|
|
3404
|
+
onIntegerOverflow(methodName, keyPath, value) {
|
|
3405
|
+
throw new SolanaJsonRpcIntegerOverflowError(methodName, keyPath, value);
|
|
3406
|
+
}
|
|
3407
|
+
};
|
|
3408
|
+
|
|
3409
|
+
// src/rpc-subscription-coalescer.ts
|
|
3410
|
+
init_env_shim();
|
|
3411
|
+
|
|
3412
|
+
// src/cached-abortable-iterable.ts
|
|
3413
|
+
init_env_shim();
|
|
3414
|
+
function registerIterableCleanup2(iterable, cleanupFn) {
|
|
3415
|
+
(async () => {
|
|
3416
|
+
try {
|
|
3417
|
+
for await (const _ of iterable)
|
|
3418
|
+
;
|
|
3419
|
+
} catch {
|
|
3420
|
+
} finally {
|
|
3421
|
+
cleanupFn();
|
|
3422
|
+
}
|
|
3423
|
+
})();
|
|
3424
|
+
}
|
|
3425
|
+
function getCachedAbortableIterableFactory({
|
|
3426
|
+
getAbortSignalFromInputArgs,
|
|
3427
|
+
getCacheEntryMissingError,
|
|
3428
|
+
getCacheKeyFromInputArgs,
|
|
3429
|
+
onCacheHit,
|
|
3430
|
+
onCreateIterable
|
|
3431
|
+
}) {
|
|
3432
|
+
const cache = /* @__PURE__ */ new Map();
|
|
3433
|
+
function getCacheEntryOrThrow(cacheKey) {
|
|
3434
|
+
const currentCacheEntry = cache.get(cacheKey);
|
|
3435
|
+
if (!currentCacheEntry) {
|
|
3436
|
+
throw getCacheEntryMissingError(cacheKey);
|
|
3437
|
+
}
|
|
3438
|
+
return currentCacheEntry;
|
|
3439
|
+
}
|
|
3440
|
+
return async (...args) => {
|
|
3441
|
+
const cacheKey = getCacheKeyFromInputArgs(...args);
|
|
3442
|
+
const signal = getAbortSignalFromInputArgs(...args);
|
|
3443
|
+
if (cacheKey === void 0) {
|
|
3444
|
+
return await onCreateIterable(signal, ...args);
|
|
3445
|
+
}
|
|
3446
|
+
const cleanup = () => {
|
|
3447
|
+
cache.delete(cacheKey);
|
|
3448
|
+
signal.removeEventListener("abort", handleAbort);
|
|
3449
|
+
};
|
|
3450
|
+
const handleAbort = () => {
|
|
3451
|
+
const cacheEntry = getCacheEntryOrThrow(cacheKey);
|
|
3452
|
+
if (cacheEntry.purgeScheduled !== true) {
|
|
3453
|
+
cacheEntry.purgeScheduled = true;
|
|
3454
|
+
globalThis.queueMicrotask(() => {
|
|
3455
|
+
cacheEntry.purgeScheduled = false;
|
|
3456
|
+
if (cacheEntry.referenceCount === 0) {
|
|
3457
|
+
cacheEntry.abortController.abort();
|
|
3458
|
+
cleanup();
|
|
3459
|
+
}
|
|
3460
|
+
});
|
|
3461
|
+
}
|
|
3462
|
+
cacheEntry.referenceCount--;
|
|
3463
|
+
};
|
|
3464
|
+
signal.addEventListener("abort", handleAbort);
|
|
3465
|
+
try {
|
|
3466
|
+
const cacheEntry = cache.get(cacheKey);
|
|
3467
|
+
if (!cacheEntry) {
|
|
3468
|
+
const singletonAbortController = new AbortController();
|
|
3469
|
+
const newIterablePromise = onCreateIterable(singletonAbortController.signal, ...args);
|
|
3470
|
+
const newCacheEntry = {
|
|
3471
|
+
abortController: singletonAbortController,
|
|
3472
|
+
iterable: newIterablePromise,
|
|
3473
|
+
purgeScheduled: false,
|
|
3474
|
+
referenceCount: 1
|
|
3475
|
+
};
|
|
3476
|
+
cache.set(cacheKey, newCacheEntry);
|
|
3477
|
+
const newIterable = await newIterablePromise;
|
|
3478
|
+
registerIterableCleanup2(newIterable, cleanup);
|
|
3479
|
+
newCacheEntry.iterable = newIterable;
|
|
3480
|
+
return newIterable;
|
|
3481
|
+
} else {
|
|
3482
|
+
cacheEntry.referenceCount++;
|
|
3483
|
+
const iterableOrIterablePromise = cacheEntry.iterable;
|
|
3484
|
+
const cachedIterable = "then" in iterableOrIterablePromise ? await iterableOrIterablePromise : iterableOrIterablePromise;
|
|
3485
|
+
await onCacheHit(cachedIterable, ...args);
|
|
3486
|
+
return cachedIterable;
|
|
3487
|
+
}
|
|
3488
|
+
} catch (e3) {
|
|
3489
|
+
cleanup();
|
|
3490
|
+
throw e3;
|
|
3491
|
+
}
|
|
3492
|
+
};
|
|
3493
|
+
}
|
|
3494
|
+
|
|
3495
|
+
// src/rpc-subscription-coalescer.ts
|
|
3496
|
+
var EXPLICIT_ABORT_TOKEN2 = Symbol(
|
|
3497
|
+
"This symbol is thrown from a subscription's iterator when the subscription is explicitly aborted by the user"
|
|
3498
|
+
);
|
|
3499
|
+
function registerIterableCleanup3(iterable, cleanupFn) {
|
|
3500
|
+
(async () => {
|
|
3501
|
+
try {
|
|
3502
|
+
for await (const _ of iterable)
|
|
3503
|
+
;
|
|
3504
|
+
} catch {
|
|
3505
|
+
} finally {
|
|
3506
|
+
cleanupFn();
|
|
3507
|
+
}
|
|
3508
|
+
})();
|
|
3509
|
+
}
|
|
3510
|
+
function getRpcSubscriptionsWithSubscriptionCoalescing({
|
|
3511
|
+
getDeduplicationKey,
|
|
3512
|
+
rpcSubscriptions
|
|
3513
|
+
}) {
|
|
3514
|
+
const cache = /* @__PURE__ */ new Map();
|
|
3515
|
+
return new Proxy(rpcSubscriptions, {
|
|
3516
|
+
defineProperty() {
|
|
3517
|
+
return false;
|
|
3518
|
+
},
|
|
3519
|
+
deleteProperty() {
|
|
3520
|
+
return false;
|
|
3521
|
+
},
|
|
3522
|
+
get(target, p, receiver) {
|
|
3523
|
+
const subscriptionMethod = Reflect.get(target, p, receiver);
|
|
3524
|
+
if (typeof subscriptionMethod !== "function") {
|
|
3525
|
+
return subscriptionMethod;
|
|
3526
|
+
}
|
|
3527
|
+
return function(...rawParams) {
|
|
3528
|
+
const deduplicationKey = getDeduplicationKey(p, rawParams);
|
|
3529
|
+
if (deduplicationKey === void 0) {
|
|
3530
|
+
return subscriptionMethod(...rawParams);
|
|
3531
|
+
}
|
|
3532
|
+
if (cache.has(deduplicationKey)) {
|
|
3533
|
+
return cache.get(deduplicationKey);
|
|
3534
|
+
}
|
|
3535
|
+
const iterableFactory = getCachedAbortableIterableFactory({
|
|
3536
|
+
getAbortSignalFromInputArgs: ({ abortSignal }) => abortSignal,
|
|
3537
|
+
getCacheEntryMissingError(deduplicationKey2) {
|
|
3538
|
+
return new Error(
|
|
3539
|
+
`Found no cache entry for subscription with deduplication key \`${deduplicationKey2?.toString()}\``
|
|
3540
|
+
);
|
|
3541
|
+
},
|
|
3542
|
+
getCacheKeyFromInputArgs: () => deduplicationKey,
|
|
3543
|
+
async onCacheHit(_iterable, _config) {
|
|
3544
|
+
},
|
|
3545
|
+
async onCreateIterable(abortSignal, config) {
|
|
3546
|
+
const pendingSubscription2 = subscriptionMethod(
|
|
3547
|
+
...rawParams
|
|
3548
|
+
);
|
|
3549
|
+
const iterable = await pendingSubscription2.subscribe({
|
|
3550
|
+
...config,
|
|
3551
|
+
abortSignal
|
|
3552
|
+
});
|
|
3553
|
+
registerIterableCleanup3(iterable, () => {
|
|
3554
|
+
cache.delete(deduplicationKey);
|
|
3555
|
+
});
|
|
3556
|
+
return iterable;
|
|
3557
|
+
}
|
|
3558
|
+
});
|
|
3559
|
+
const pendingSubscription = {
|
|
3560
|
+
async subscribe(...args) {
|
|
3561
|
+
const iterable = await iterableFactory(...args);
|
|
3562
|
+
const { abortSignal } = args[0];
|
|
3563
|
+
let abortPromise;
|
|
3564
|
+
return {
|
|
3565
|
+
...iterable,
|
|
3566
|
+
async *[Symbol.asyncIterator]() {
|
|
3567
|
+
abortPromise || (abortPromise = abortSignal.aborted ? Promise.reject(EXPLICIT_ABORT_TOKEN2) : new Promise((_, reject) => {
|
|
3568
|
+
abortSignal.addEventListener("abort", () => {
|
|
3569
|
+
reject(EXPLICIT_ABORT_TOKEN2);
|
|
3570
|
+
});
|
|
3571
|
+
}));
|
|
3572
|
+
try {
|
|
3573
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
3574
|
+
while (true) {
|
|
3575
|
+
const iteratorResult = await Promise.race([iterator.next(), abortPromise]);
|
|
3576
|
+
if (iteratorResult.done) {
|
|
3577
|
+
return;
|
|
3578
|
+
} else {
|
|
3579
|
+
yield iteratorResult.value;
|
|
3580
|
+
}
|
|
3581
|
+
}
|
|
3582
|
+
} catch (e3) {
|
|
3583
|
+
if (e3 === EXPLICIT_ABORT_TOKEN2) {
|
|
3584
|
+
return;
|
|
3585
|
+
}
|
|
3586
|
+
cache.delete(deduplicationKey);
|
|
3587
|
+
throw e3;
|
|
3588
|
+
}
|
|
3589
|
+
}
|
|
3590
|
+
};
|
|
3591
|
+
}
|
|
3592
|
+
};
|
|
3593
|
+
cache.set(deduplicationKey, pendingSubscription);
|
|
3594
|
+
return pendingSubscription;
|
|
3595
|
+
};
|
|
3596
|
+
}
|
|
3597
|
+
});
|
|
3598
|
+
}
|
|
3599
|
+
|
|
3600
|
+
// src/rpc.ts
|
|
3601
|
+
function createSolanaRpc(config) {
|
|
3602
|
+
return createJsonRpc({
|
|
3603
|
+
...config,
|
|
3604
|
+
api: createSolanaRpcApi(DEFAULT_RPC_CONFIG)
|
|
3605
|
+
});
|
|
3606
|
+
}
|
|
3607
|
+
function createSolanaRpcSubscriptions(config) {
|
|
3608
|
+
return pipe(
|
|
3609
|
+
createJsonSubscriptionRpc({
|
|
3610
|
+
...config,
|
|
3611
|
+
api: createSolanaRpcSubscriptionsApi(DEFAULT_RPC_CONFIG)
|
|
3612
|
+
}),
|
|
3613
|
+
(rpcSubscriptions) => getRpcSubscriptionsWithSubscriptionCoalescing({
|
|
3614
|
+
getDeduplicationKey: (...args) => (0, import_fast_stable_stringify.default)(args),
|
|
3615
|
+
rpcSubscriptions
|
|
3616
|
+
})
|
|
3617
|
+
);
|
|
3618
|
+
}
|
|
3619
|
+
function createSolanaRpcSubscriptions_UNSTABLE(config) {
|
|
3620
|
+
return createJsonSubscriptionRpc({
|
|
3621
|
+
...config,
|
|
3622
|
+
api: createSolanaRpcSubscriptionsApi_UNSTABLE(DEFAULT_RPC_CONFIG)
|
|
3623
|
+
});
|
|
3624
|
+
}
|
|
3625
|
+
|
|
3626
|
+
// src/rpc-transport.ts
|
|
3627
|
+
init_env_shim();
|
|
3628
|
+
|
|
3629
|
+
// src/rpc-request-coalescer.ts
|
|
3630
|
+
init_env_shim();
|
|
3631
|
+
function getRpcTransportWithRequestCoalescing(transport, getDeduplicationKey) {
|
|
3632
|
+
let coalescedRequestsByDeduplicationKey;
|
|
3633
|
+
return async function makeCoalescedHttpRequest(config) {
|
|
3634
|
+
const { payload, signal } = config;
|
|
3635
|
+
const deduplicationKey = getDeduplicationKey(payload);
|
|
3636
|
+
if (deduplicationKey === void 0) {
|
|
3637
|
+
return await transport(config);
|
|
3638
|
+
}
|
|
3639
|
+
if (!coalescedRequestsByDeduplicationKey) {
|
|
3640
|
+
Promise.resolve().then(() => {
|
|
3641
|
+
coalescedRequestsByDeduplicationKey = void 0;
|
|
3642
|
+
});
|
|
3643
|
+
coalescedRequestsByDeduplicationKey = {};
|
|
3644
|
+
}
|
|
3645
|
+
if (coalescedRequestsByDeduplicationKey[deduplicationKey] == null) {
|
|
3646
|
+
const abortController = new AbortController();
|
|
3647
|
+
coalescedRequestsByDeduplicationKey[deduplicationKey] = {
|
|
3648
|
+
abortController,
|
|
3649
|
+
numConsumers: 0,
|
|
3650
|
+
responsePromise: transport({
|
|
3651
|
+
...config,
|
|
3652
|
+
signal: abortController.signal
|
|
3653
|
+
})
|
|
3654
|
+
};
|
|
3655
|
+
}
|
|
3656
|
+
const coalescedRequest = coalescedRequestsByDeduplicationKey[deduplicationKey];
|
|
3657
|
+
coalescedRequest.numConsumers++;
|
|
3658
|
+
if (signal) {
|
|
3659
|
+
const responsePromise = coalescedRequest.responsePromise;
|
|
3660
|
+
return await new Promise((resolve, reject) => {
|
|
3661
|
+
const handleAbort = (e3) => {
|
|
3662
|
+
signal.removeEventListener("abort", handleAbort);
|
|
3663
|
+
coalescedRequest.numConsumers -= 1;
|
|
3664
|
+
if (coalescedRequest.numConsumers === 0) {
|
|
3665
|
+
const abortController = coalescedRequest.abortController;
|
|
3666
|
+
abortController.abort();
|
|
3667
|
+
}
|
|
3668
|
+
const abortError = new DOMException(e3.target.reason, "AbortError");
|
|
3669
|
+
reject(abortError);
|
|
3670
|
+
};
|
|
3671
|
+
signal.addEventListener("abort", handleAbort);
|
|
3672
|
+
responsePromise.then(resolve).finally(() => {
|
|
3673
|
+
signal.removeEventListener("abort", handleAbort);
|
|
3674
|
+
});
|
|
3675
|
+
});
|
|
3676
|
+
} else {
|
|
3677
|
+
return await coalescedRequest.responsePromise;
|
|
3678
|
+
}
|
|
3679
|
+
};
|
|
3680
|
+
}
|
|
3681
|
+
|
|
3682
|
+
// src/rpc-request-deduplication.ts
|
|
3683
|
+
init_env_shim();
|
|
3684
|
+
var import_fast_stable_stringify2 = __toESM(require_fast_stable_stringify(), 1);
|
|
3685
|
+
function isJsonRpcPayload(payload) {
|
|
3686
|
+
if (payload == null || typeof payload !== "object" || Array.isArray(payload)) {
|
|
3687
|
+
return false;
|
|
3688
|
+
}
|
|
3689
|
+
return "jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && typeof payload.method === "string" && "params" in payload;
|
|
3690
|
+
}
|
|
3691
|
+
function getSolanaRpcPayloadDeduplicationKey(payload) {
|
|
3692
|
+
return isJsonRpcPayload(payload) ? (0, import_fast_stable_stringify2.default)([payload.method, payload.params]) : void 0;
|
|
3693
|
+
}
|
|
3694
|
+
|
|
3695
|
+
// src/rpc-transport.ts
|
|
3696
|
+
function normalizeHeaders2(headers) {
|
|
3697
|
+
const out = {};
|
|
3698
|
+
for (const headerName in headers) {
|
|
3699
|
+
out[headerName.toLowerCase()] = headers[headerName];
|
|
3700
|
+
}
|
|
3701
|
+
return out;
|
|
3702
|
+
}
|
|
3703
|
+
function createDefaultRpcTransport(config) {
|
|
3704
|
+
return pipe(
|
|
3705
|
+
createHttpTransport({
|
|
3706
|
+
...config,
|
|
3707
|
+
headers: {
|
|
3708
|
+
...config.headers ? normalizeHeaders2(config.headers) : void 0,
|
|
3709
|
+
...{
|
|
3710
|
+
// Keep these headers lowercase so they will override any user-supplied headers above.
|
|
3711
|
+
"solana-client": `js/${"2.0.0-development"}` ?? "UNKNOWN"
|
|
3712
|
+
}
|
|
3713
|
+
}
|
|
3714
|
+
}),
|
|
3715
|
+
(transport) => getRpcTransportWithRequestCoalescing(transport, getSolanaRpcPayloadDeduplicationKey)
|
|
3716
|
+
);
|
|
3717
|
+
}
|
|
3718
|
+
|
|
3719
|
+
// src/rpc-websocket-transport.ts
|
|
3720
|
+
init_env_shim();
|
|
3721
|
+
|
|
3722
|
+
// src/rpc-websocket-autopinger.ts
|
|
3723
|
+
init_env_shim();
|
|
3724
|
+
var PING_PAYLOAD = {
|
|
3725
|
+
jsonrpc: "2.0",
|
|
3726
|
+
method: "ping"
|
|
3727
|
+
};
|
|
3728
|
+
function getWebSocketTransportWithAutoping({ intervalMs, transport }) {
|
|
3729
|
+
const pingableConnections = /* @__PURE__ */ new Map();
|
|
3730
|
+
return async (...args) => {
|
|
3731
|
+
const connection = await transport(...args);
|
|
3732
|
+
let intervalId;
|
|
3733
|
+
function sendPing() {
|
|
3734
|
+
connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(PING_PAYLOAD);
|
|
3735
|
+
}
|
|
3736
|
+
function restartPingTimer() {
|
|
3737
|
+
clearInterval(intervalId);
|
|
3738
|
+
intervalId = setInterval(sendPing, intervalMs);
|
|
3739
|
+
}
|
|
3740
|
+
if (pingableConnections.has(connection) === false) {
|
|
3741
|
+
pingableConnections.set(connection, {
|
|
3742
|
+
[Symbol.asyncIterator]: connection[Symbol.asyncIterator].bind(connection),
|
|
3743
|
+
send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: (...args2) => {
|
|
3744
|
+
restartPingTimer();
|
|
3745
|
+
return connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(...args2);
|
|
3746
|
+
}
|
|
3747
|
+
});
|
|
3748
|
+
(async () => {
|
|
3749
|
+
try {
|
|
3750
|
+
for await (const _ of connection) {
|
|
3751
|
+
restartPingTimer();
|
|
3752
|
+
}
|
|
3753
|
+
} catch {
|
|
3754
|
+
} finally {
|
|
3755
|
+
pingableConnections.delete(connection);
|
|
3756
|
+
clearInterval(intervalId);
|
|
3757
|
+
if (handleOffline) {
|
|
3758
|
+
globalThis.window.removeEventListener("offline", handleOffline);
|
|
3759
|
+
}
|
|
3760
|
+
if (handleOnline) {
|
|
3761
|
+
globalThis.window.removeEventListener("online", handleOnline);
|
|
3762
|
+
}
|
|
3763
|
+
}
|
|
3764
|
+
})();
|
|
3765
|
+
if (globalThis.navigator.onLine) {
|
|
3766
|
+
restartPingTimer();
|
|
3767
|
+
}
|
|
3768
|
+
let handleOffline;
|
|
3769
|
+
let handleOnline;
|
|
3770
|
+
{
|
|
3771
|
+
handleOffline = () => {
|
|
3772
|
+
clearInterval(intervalId);
|
|
3773
|
+
};
|
|
3774
|
+
handleOnline = () => {
|
|
3775
|
+
sendPing();
|
|
3776
|
+
restartPingTimer();
|
|
3777
|
+
};
|
|
3778
|
+
globalThis.window.addEventListener("offline", handleOffline);
|
|
3779
|
+
globalThis.window.addEventListener("online", handleOnline);
|
|
3780
|
+
}
|
|
3781
|
+
}
|
|
3782
|
+
return pingableConnections.get(connection);
|
|
3783
|
+
};
|
|
3784
|
+
}
|
|
3785
|
+
|
|
3786
|
+
// src/rpc-websocket-connection-sharding.ts
|
|
3787
|
+
init_env_shim();
|
|
3788
|
+
var NULL_SHARD_CACHE_KEY = Symbol(
|
|
3789
|
+
"Cache key to use when there is no connection sharding strategy"
|
|
3790
|
+
);
|
|
3791
|
+
function getWebSocketTransportWithConnectionSharding({ getShard, transport }) {
|
|
3792
|
+
return getCachedAbortableIterableFactory({
|
|
3793
|
+
getAbortSignalFromInputArgs: ({ signal }) => signal,
|
|
3794
|
+
getCacheEntryMissingError(shardKey) {
|
|
3795
|
+
return new Error(`Found no cache entry for connection with shard key \`${shardKey?.toString()}\``);
|
|
3796
|
+
},
|
|
3797
|
+
getCacheKeyFromInputArgs: ({ payload }) => getShard ? getShard(payload) : NULL_SHARD_CACHE_KEY,
|
|
3798
|
+
onCacheHit: (connection, { payload }) => connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload),
|
|
3799
|
+
onCreateIterable: (abortSignal, config) => transport({
|
|
3800
|
+
...config,
|
|
3801
|
+
signal: abortSignal
|
|
3802
|
+
})
|
|
3803
|
+
});
|
|
3804
|
+
}
|
|
3805
|
+
|
|
3806
|
+
// src/rpc-websocket-transport.ts
|
|
3807
|
+
function createDefaultRpcSubscriptionsTransport(config) {
|
|
3808
|
+
const { getShard, intervalMs, ...rest } = config;
|
|
3809
|
+
return pipe(
|
|
3810
|
+
createWebSocketTransport({
|
|
3811
|
+
...rest,
|
|
3812
|
+
sendBufferHighWatermark: config.sendBufferHighWatermark ?? // Let 128KB of data into the WebSocket buffer before buffering it in the app.
|
|
3813
|
+
131072
|
|
3814
|
+
}),
|
|
3815
|
+
(transport) => getWebSocketTransportWithAutoping({
|
|
3816
|
+
intervalMs: intervalMs ?? 5e3,
|
|
3817
|
+
transport
|
|
3818
|
+
}),
|
|
3819
|
+
(transport) => getWebSocketTransportWithConnectionSharding({
|
|
3820
|
+
getShard,
|
|
3821
|
+
transport
|
|
3822
|
+
})
|
|
3823
|
+
);
|
|
3824
|
+
}
|
|
3825
|
+
|
|
3826
|
+
// src/send-transaction.ts
|
|
3827
|
+
init_env_shim();
|
|
3828
|
+
|
|
3829
|
+
// src/transaction-confirmation.ts
|
|
3830
|
+
init_env_shim();
|
|
3831
|
+
|
|
3832
|
+
// src/transaction-confirmation-strategy-blockheight.ts
|
|
3833
|
+
init_env_shim();
|
|
3834
|
+
function createBlockHeightExceedencePromiseFactory(rpcSubscriptions) {
|
|
3835
|
+
return async function getBlockHeightExceedencePromise({ abortSignal: callerAbortSignal, lastValidBlockHeight }) {
|
|
3836
|
+
const abortController = new AbortController();
|
|
3837
|
+
function handleAbort() {
|
|
3838
|
+
abortController.abort();
|
|
3839
|
+
}
|
|
3840
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
3841
|
+
const slotNotifications = await rpcSubscriptions.slotNotifications().subscribe({ abortSignal: abortController.signal });
|
|
3842
|
+
try {
|
|
3843
|
+
for await (const slotNotification of slotNotifications) {
|
|
3844
|
+
if (slotNotification.slot > lastValidBlockHeight) {
|
|
3845
|
+
throw new Error(
|
|
3846
|
+
"The network has progressed past the last block for which this transaction could have committed."
|
|
3847
|
+
);
|
|
3848
|
+
}
|
|
3849
|
+
}
|
|
3850
|
+
} finally {
|
|
3851
|
+
abortController.abort();
|
|
3852
|
+
}
|
|
3853
|
+
};
|
|
3854
|
+
}
|
|
3855
|
+
|
|
3856
|
+
// src/transaction-confirmation-strategy-nonce.ts
|
|
3857
|
+
init_env_shim();
|
|
3858
|
+
var NONCE_VALUE_OFFSET = 4 + // version(u32)
|
|
3859
|
+
4 + // state(u32)
|
|
3860
|
+
32;
|
|
3861
|
+
function createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions) {
|
|
3862
|
+
return async function getNonceInvalidationPromise({
|
|
3863
|
+
abortSignal: callerAbortSignal,
|
|
3864
|
+
commitment,
|
|
3865
|
+
currentNonceValue,
|
|
3866
|
+
nonceAccountAddress
|
|
3867
|
+
}) {
|
|
3868
|
+
const abortController = new AbortController();
|
|
3869
|
+
function handleAbort() {
|
|
3870
|
+
abortController.abort();
|
|
3871
|
+
}
|
|
3872
|
+
callerAbortSignal.addEventListener("abort", handleAbort, { signal: abortController.signal });
|
|
3873
|
+
const accountNotifications = await rpcSubscriptions.accountNotifications(nonceAccountAddress, { commitment, encoding: "base64" }).subscribe({ abortSignal: abortController.signal });
|
|
3874
|
+
const base58Decoder2 = getBase58Decoder();
|
|
3875
|
+
const base64Encoder = getBase64Encoder();
|
|
3876
|
+
function getNonceFromAccountData([base64EncodedBytes]) {
|
|
3877
|
+
const data = base64Encoder.encode(base64EncodedBytes);
|
|
3878
|
+
const nonceValueBytes = data.slice(NONCE_VALUE_OFFSET, NONCE_VALUE_OFFSET + 32);
|
|
3879
|
+
return base58Decoder2.decode(nonceValueBytes)[0];
|
|
3880
|
+
}
|
|
3881
|
+
const nonceAccountDidAdvancePromise = (async () => {
|
|
3882
|
+
for await (const accountNotification of accountNotifications) {
|
|
3883
|
+
const nonceValue = getNonceFromAccountData(accountNotification.value.data);
|
|
3884
|
+
if (nonceValue !== currentNonceValue) {
|
|
3885
|
+
throw new Error(
|
|
3886
|
+
`The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
|
|
3887
|
+
);
|
|
3888
|
+
}
|
|
3889
|
+
}
|
|
3890
|
+
})();
|
|
3891
|
+
const nonceIsAlreadyInvalidPromise = (async () => {
|
|
3892
|
+
const { value: nonceAccount } = await rpc.getAccountInfo(nonceAccountAddress, {
|
|
3893
|
+
commitment,
|
|
3894
|
+
dataSlice: { length: 32, offset: NONCE_VALUE_OFFSET },
|
|
3895
|
+
encoding: "base58"
|
|
3896
|
+
}).send({ abortSignal: abortController.signal });
|
|
3897
|
+
if (!nonceAccount) {
|
|
3898
|
+
throw new Error(`No nonce account could be found at address \`${nonceAccountAddress}\`.`);
|
|
3899
|
+
}
|
|
3900
|
+
const nonceValue = (
|
|
3901
|
+
// This works because we asked for the exact slice of data representing the nonce
|
|
3902
|
+
// value, and furthermore asked for it in `base58` encoding.
|
|
3903
|
+
nonceAccount.data[0]
|
|
3904
|
+
);
|
|
3905
|
+
if (nonceValue !== currentNonceValue) {
|
|
3906
|
+
throw new Error(
|
|
3907
|
+
`The nonce \`${currentNonceValue}\` is no longer valid. It has advanced to \`${nonceValue}\`.`
|
|
3908
|
+
);
|
|
3909
|
+
} else {
|
|
3910
|
+
await new Promise(() => {
|
|
3911
|
+
});
|
|
3912
|
+
}
|
|
3913
|
+
})();
|
|
3914
|
+
try {
|
|
3915
|
+
return await Promise.race([nonceAccountDidAdvancePromise, nonceIsAlreadyInvalidPromise]);
|
|
3916
|
+
} finally {
|
|
3917
|
+
abortController.abort();
|
|
3918
|
+
}
|
|
3919
|
+
};
|
|
3920
|
+
}
|
|
3921
|
+
|
|
3922
|
+
// src/transaction-confirmation.ts
|
|
3923
|
+
function createDefaultDurableNonceTransactionConfirmer({
|
|
3924
|
+
rpc,
|
|
3925
|
+
rpcSubscriptions
|
|
3926
|
+
}) {
|
|
3927
|
+
const getNonceInvalidationPromise = createNonceInvalidationPromiseFactory(rpc, rpcSubscriptions);
|
|
3928
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
3929
|
+
rpc,
|
|
3930
|
+
rpcSubscriptions
|
|
3931
|
+
);
|
|
3932
|
+
return async function confirmDurableNonceTransaction(config) {
|
|
3933
|
+
await waitForDurableNonceTransactionConfirmation({
|
|
3934
|
+
...config,
|
|
3935
|
+
getNonceInvalidationPromise,
|
|
3936
|
+
getRecentSignatureConfirmationPromise
|
|
3937
|
+
});
|
|
3938
|
+
};
|
|
3939
|
+
}
|
|
3940
|
+
function createDefaultRecentTransactionConfirmer({
|
|
3941
|
+
rpc,
|
|
3942
|
+
rpcSubscriptions
|
|
3943
|
+
}) {
|
|
3944
|
+
const getBlockHeightExceedencePromise = createBlockHeightExceedencePromiseFactory(rpcSubscriptions);
|
|
3945
|
+
const getRecentSignatureConfirmationPromise = createRecentSignatureConfirmationPromiseFactory(
|
|
3946
|
+
rpc,
|
|
3947
|
+
rpcSubscriptions
|
|
3948
|
+
);
|
|
3949
|
+
return async function confirmRecentTransaction(config) {
|
|
3950
|
+
await waitForRecentTransactionConfirmation({
|
|
3951
|
+
...config,
|
|
3952
|
+
getBlockHeightExceedencePromise,
|
|
3953
|
+
getRecentSignatureConfirmationPromise
|
|
3954
|
+
});
|
|
3955
|
+
};
|
|
3956
|
+
}
|
|
3957
|
+
async function waitForDurableNonceTransactionConfirmation(config) {
|
|
3958
|
+
await raceStrategies(
|
|
3959
|
+
getSignatureFromTransaction(config.transaction),
|
|
3960
|
+
config,
|
|
3961
|
+
function getSpecificStrategiesForRace({ abortSignal, commitment, getNonceInvalidationPromise, transaction }) {
|
|
3962
|
+
return [
|
|
3963
|
+
getNonceInvalidationPromise({
|
|
3964
|
+
abortSignal,
|
|
3965
|
+
commitment,
|
|
3966
|
+
currentNonceValue: transaction.lifetimeConstraint.nonce,
|
|
3967
|
+
nonceAccountAddress: transaction.instructions[0].accounts[0].address
|
|
3968
|
+
})
|
|
3969
|
+
];
|
|
3970
|
+
}
|
|
3971
|
+
);
|
|
3972
|
+
}
|
|
3973
|
+
async function waitForRecentTransactionConfirmation(config) {
|
|
3974
|
+
await raceStrategies(
|
|
3975
|
+
getSignatureFromTransaction(config.transaction),
|
|
3976
|
+
config,
|
|
3977
|
+
function getSpecificStrategiesForRace({ abortSignal, getBlockHeightExceedencePromise, transaction }) {
|
|
3978
|
+
return [
|
|
3979
|
+
getBlockHeightExceedencePromise({
|
|
3980
|
+
abortSignal,
|
|
3981
|
+
lastValidBlockHeight: transaction.lifetimeConstraint.lastValidBlockHeight
|
|
3982
|
+
})
|
|
3983
|
+
];
|
|
3984
|
+
}
|
|
3985
|
+
);
|
|
3986
|
+
}
|
|
3987
|
+
|
|
3988
|
+
// src/send-transaction.ts
|
|
3989
|
+
function getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, config) {
|
|
3990
|
+
if (
|
|
3991
|
+
// The developer has supplied no value for `preflightCommitment`.
|
|
3992
|
+
!config?.preflightCommitment && // The value of `commitment` is lower than the server default of `preflightCommitment`.
|
|
3993
|
+
commitmentComparator(
|
|
3994
|
+
commitment,
|
|
3995
|
+
"finalized"
|
|
3996
|
+
/* default value of `preflightCommitment` */
|
|
3997
|
+
) < 0
|
|
3998
|
+
) {
|
|
3999
|
+
return {
|
|
4000
|
+
...config,
|
|
4001
|
+
// In the common case, it is unlikely that you want to simulate a transaction at
|
|
4002
|
+
// `finalized` commitment when your standard of commitment for confirming the
|
|
4003
|
+
// transaction is lower. Cap the simulation commitment level to the level of the
|
|
4004
|
+
// confirmation commitment.
|
|
4005
|
+
preflightCommitment: commitment
|
|
4006
|
+
};
|
|
4007
|
+
}
|
|
4008
|
+
return config;
|
|
4009
|
+
}
|
|
4010
|
+
async function sendTransaction_INTERNAL({
|
|
4011
|
+
abortSignal,
|
|
4012
|
+
commitment,
|
|
4013
|
+
rpc,
|
|
4014
|
+
transaction,
|
|
4015
|
+
...sendTransactionConfig
|
|
4016
|
+
}) {
|
|
4017
|
+
const base64EncodedWireTransaction = getBase64EncodedWireTransaction(transaction);
|
|
4018
|
+
return await rpc.sendTransaction(base64EncodedWireTransaction, {
|
|
4019
|
+
...getSendTransactionConfigWithAdjustedPreflightCommitment(commitment, sendTransactionConfig),
|
|
4020
|
+
encoding: "base64"
|
|
4021
|
+
}).send({ abortSignal });
|
|
4022
|
+
}
|
|
4023
|
+
function createDefaultDurableNonceTransactionSender({
|
|
4024
|
+
rpc,
|
|
4025
|
+
rpcSubscriptions
|
|
4026
|
+
}) {
|
|
4027
|
+
const confirmDurableNonceTransaction = createDefaultDurableNonceTransactionConfirmer({
|
|
4028
|
+
rpc,
|
|
4029
|
+
rpcSubscriptions
|
|
4030
|
+
});
|
|
4031
|
+
return async function sendDurableNonceTransaction(transaction, config) {
|
|
4032
|
+
await sendAndConfirmDurableNonceTransaction({
|
|
4033
|
+
...config,
|
|
4034
|
+
confirmDurableNonceTransaction,
|
|
4035
|
+
rpc,
|
|
4036
|
+
transaction
|
|
4037
|
+
});
|
|
4038
|
+
};
|
|
4039
|
+
}
|
|
4040
|
+
function createDefaultTransactionSender({
|
|
4041
|
+
rpc,
|
|
4042
|
+
rpcSubscriptions
|
|
4043
|
+
}) {
|
|
4044
|
+
const confirmRecentTransaction = createDefaultRecentTransactionConfirmer({
|
|
4045
|
+
rpc,
|
|
4046
|
+
rpcSubscriptions
|
|
4047
|
+
});
|
|
4048
|
+
return async function sendTransaction(transaction, config) {
|
|
4049
|
+
await sendAndConfirmTransaction({
|
|
4050
|
+
...config,
|
|
4051
|
+
confirmRecentTransaction,
|
|
4052
|
+
rpc,
|
|
4053
|
+
transaction
|
|
4054
|
+
});
|
|
4055
|
+
};
|
|
4056
|
+
}
|
|
4057
|
+
async function sendAndConfirmDurableNonceTransaction({
|
|
4058
|
+
abortSignal,
|
|
4059
|
+
commitment,
|
|
4060
|
+
confirmDurableNonceTransaction,
|
|
4061
|
+
rpc,
|
|
4062
|
+
transaction,
|
|
4063
|
+
...sendTransactionConfig
|
|
4064
|
+
}) {
|
|
4065
|
+
const transactionSignature2 = await sendTransaction_INTERNAL({
|
|
4066
|
+
...sendTransactionConfig,
|
|
4067
|
+
abortSignal,
|
|
4068
|
+
commitment,
|
|
4069
|
+
rpc,
|
|
4070
|
+
transaction
|
|
4071
|
+
});
|
|
4072
|
+
await confirmDurableNonceTransaction({
|
|
4073
|
+
abortSignal,
|
|
4074
|
+
commitment,
|
|
4075
|
+
transaction
|
|
4076
|
+
});
|
|
4077
|
+
return transactionSignature2;
|
|
4078
|
+
}
|
|
4079
|
+
async function sendAndConfirmTransaction({
|
|
4080
|
+
abortSignal,
|
|
4081
|
+
commitment,
|
|
4082
|
+
confirmRecentTransaction,
|
|
4083
|
+
rpc,
|
|
4084
|
+
transaction,
|
|
4085
|
+
...sendTransactionConfig
|
|
4086
|
+
}) {
|
|
4087
|
+
const transactionSignature2 = await sendTransaction_INTERNAL({
|
|
4088
|
+
...sendTransactionConfig,
|
|
4089
|
+
abortSignal,
|
|
4090
|
+
commitment,
|
|
4091
|
+
rpc,
|
|
4092
|
+
transaction
|
|
4093
|
+
});
|
|
4094
|
+
await confirmRecentTransaction({
|
|
4095
|
+
abortSignal,
|
|
4096
|
+
commitment,
|
|
4097
|
+
transaction
|
|
4098
|
+
});
|
|
4099
|
+
return transactionSignature2;
|
|
4100
|
+
}
|
|
4101
|
+
|
|
4102
|
+
exports.AccountRole = AccountRole;
|
|
4103
|
+
exports.address = address;
|
|
4104
|
+
exports.appendTransactionInstruction = appendTransactionInstruction;
|
|
4105
|
+
exports.assertIsAddress = assertIsAddress;
|
|
4106
|
+
exports.assertIsBlockhash = assertIsBlockhash;
|
|
4107
|
+
exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
|
|
4108
|
+
exports.assertIsLamports = assertIsLamports;
|
|
4109
|
+
exports.assertIsProgramDerivedAddress = assertIsProgramDerivedAddress;
|
|
4110
|
+
exports.assertIsStringifiedBigInt = assertIsStringifiedBigInt;
|
|
4111
|
+
exports.assertIsStringifiedNumber = assertIsStringifiedNumber;
|
|
4112
|
+
exports.assertIsTransactionSignature = assertIsTransactionSignature;
|
|
4113
|
+
exports.assertIsUnixTimestamp = assertIsUnixTimestamp;
|
|
4114
|
+
exports.assertTransactionIsFullySigned = assertTransactionIsFullySigned;
|
|
4115
|
+
exports.commitmentComparator = commitmentComparator;
|
|
4116
|
+
exports.createAddressWithSeed = createAddressWithSeed;
|
|
4117
|
+
exports.createBlockHeightExceedencePromiseFactory = createBlockHeightExceedencePromiseFactory;
|
|
4118
|
+
exports.createDefaultAirdropRequester = createDefaultAirdropRequester;
|
|
4119
|
+
exports.createDefaultDurableNonceTransactionConfirmer = createDefaultDurableNonceTransactionConfirmer;
|
|
4120
|
+
exports.createDefaultDurableNonceTransactionSender = createDefaultDurableNonceTransactionSender;
|
|
4121
|
+
exports.createDefaultRecentTransactionConfirmer = createDefaultRecentTransactionConfirmer;
|
|
4122
|
+
exports.createDefaultRpcSubscriptionsTransport = createDefaultRpcSubscriptionsTransport;
|
|
4123
|
+
exports.createDefaultRpcTransport = createDefaultRpcTransport;
|
|
4124
|
+
exports.createDefaultTransactionSender = createDefaultTransactionSender;
|
|
4125
|
+
exports.createNonceInvalidationPromiseFactory = createNonceInvalidationPromiseFactory;
|
|
4126
|
+
exports.createRecentSignatureConfirmationPromiseFactory = createRecentSignatureConfirmationPromiseFactory;
|
|
4127
|
+
exports.createSolanaRpc = createSolanaRpc;
|
|
4128
|
+
exports.createSolanaRpcSubscriptions = createSolanaRpcSubscriptions;
|
|
4129
|
+
exports.createSolanaRpcSubscriptions_UNSTABLE = createSolanaRpcSubscriptions_UNSTABLE;
|
|
4130
|
+
exports.createTransaction = createTransaction;
|
|
4131
|
+
exports.downgradeRoleToNonSigner = downgradeRoleToNonSigner;
|
|
4132
|
+
exports.downgradeRoleToReadonly = downgradeRoleToReadonly;
|
|
4133
|
+
exports.generateKeyPair = generateKeyPair;
|
|
4134
|
+
exports.getAddressCodec = getAddressCodec;
|
|
4135
|
+
exports.getAddressComparator = getAddressComparator;
|
|
4136
|
+
exports.getAddressDecoder = getAddressDecoder;
|
|
4137
|
+
exports.getAddressEncoder = getAddressEncoder;
|
|
4138
|
+
exports.getAddressFromPublicKey = getAddressFromPublicKey;
|
|
4139
|
+
exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
|
|
4140
|
+
exports.getProgramDerivedAddress = getProgramDerivedAddress;
|
|
4141
|
+
exports.getSignatureFromTransaction = getSignatureFromTransaction;
|
|
4142
|
+
exports.getTransactionCodec = getTransactionCodec;
|
|
4143
|
+
exports.getTransactionDecoder = getTransactionDecoder;
|
|
4144
|
+
exports.getTransactionEncoder = getTransactionEncoder;
|
|
4145
|
+
exports.isAddress = isAddress;
|
|
4146
|
+
exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
|
|
4147
|
+
exports.isLamports = isLamports;
|
|
4148
|
+
exports.isProgramDerivedAddress = isProgramDerivedAddress;
|
|
4149
|
+
exports.isSignerRole = isSignerRole;
|
|
4150
|
+
exports.isStringifiedBigInt = isStringifiedBigInt;
|
|
4151
|
+
exports.isStringifiedNumber = isStringifiedNumber;
|
|
4152
|
+
exports.isTransactionSignature = isTransactionSignature;
|
|
4153
|
+
exports.isUnixTimestamp = isUnixTimestamp;
|
|
4154
|
+
exports.isWritableRole = isWritableRole;
|
|
4155
|
+
exports.lamports = lamports;
|
|
4156
|
+
exports.mergeRoles = mergeRoles;
|
|
4157
|
+
exports.prependTransactionInstruction = prependTransactionInstruction;
|
|
4158
|
+
exports.requestAndConfirmAirdrop = requestAndConfirmAirdrop;
|
|
4159
|
+
exports.sendAndConfirmDurableNonceTransaction = sendAndConfirmDurableNonceTransaction;
|
|
4160
|
+
exports.sendAndConfirmTransaction = sendAndConfirmTransaction;
|
|
4161
|
+
exports.setTransactionFeePayer = setTransactionFeePayer;
|
|
4162
|
+
exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
|
|
4163
|
+
exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
|
|
4164
|
+
exports.signBytes = signBytes;
|
|
4165
|
+
exports.signTransaction = signTransaction;
|
|
4166
|
+
exports.stringifiedBigInt = stringifiedBigInt;
|
|
4167
|
+
exports.stringifiedNumber = stringifiedNumber;
|
|
4168
|
+
exports.transactionSignature = transactionSignature;
|
|
4169
|
+
exports.unixTimestamp = unixTimestamp;
|
|
4170
|
+
exports.upgradeRoleToSigner = upgradeRoleToSigner;
|
|
4171
|
+
exports.upgradeRoleToWritable = upgradeRoleToWritable;
|
|
4172
|
+
exports.verifySignature = verifySignature;
|
|
4173
|
+
exports.waitForDurableNonceTransactionConfirmation = waitForDurableNonceTransactionConfirmation;
|
|
4174
|
+
exports.waitForRecentTransactionConfirmation = waitForRecentTransactionConfirmation;
|
|
4175
|
+
|
|
4176
|
+
return exports;
|
|
4177
|
+
|
|
4178
|
+
})({});
|
|
4179
|
+
//# sourceMappingURL=out.js.map
|
|
4180
|
+
//# sourceMappingURL=index.development.js.map
|