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