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