@solana/web3.js 2.0.0-experimental.87c9652 → 2.0.0-experimental.8894dc1
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/dist/index.browser.cjs +337 -10
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +323 -11
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +2244 -241
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +312 -11
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +326 -10
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +312 -11
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +39 -19
- package/dist/types/cached-abortable-iterable.d.ts +11 -0
- package/dist/types/index.d.ts +3 -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/package.json +18 -18
|
@@ -12,8 +12,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
12
12
|
var __esm = (fn, res) => function __init() {
|
|
13
13
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
14
14
|
};
|
|
15
|
-
var __commonJS = (cb,
|
|
16
|
-
return
|
|
15
|
+
var __commonJS = (cb, mod2) => function __require() {
|
|
16
|
+
return mod2 || (0, cb[__getOwnPropNames(cb)[0]])((mod2 = { exports: {} }).exports, mod2), mod2.exports;
|
|
17
17
|
};
|
|
18
18
|
var __copyProps = (to, from, except, desc) => {
|
|
19
19
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -23,13 +23,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
23
23
|
}
|
|
24
24
|
return to;
|
|
25
25
|
};
|
|
26
|
-
var __toESM = (
|
|
26
|
+
var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__getProtoOf(mod2)) : {}, __copyProps(
|
|
27
27
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
28
28
|
// file that has been converted to a CommonJS file using a Babel-
|
|
29
29
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
30
30
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
31
|
-
isNodeMode || !
|
|
32
|
-
|
|
31
|
+
isNodeMode || !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
|
|
32
|
+
mod2
|
|
33
33
|
));
|
|
34
34
|
var __publicField = (obj, key, value) => {
|
|
35
35
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
@@ -122,53 +122,16 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
122
122
|
// src/index.ts
|
|
123
123
|
init_env_shim();
|
|
124
124
|
|
|
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
|
|
125
|
+
// ../addresses/dist/index.browser.js
|
|
163
126
|
init_env_shim();
|
|
164
127
|
|
|
165
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.
|
|
128
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/index.mjs
|
|
166
129
|
init_env_shim();
|
|
167
130
|
|
|
168
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.
|
|
131
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/index.mjs
|
|
169
132
|
init_env_shim();
|
|
170
133
|
|
|
171
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.
|
|
134
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/bytes.mjs
|
|
172
135
|
init_env_shim();
|
|
173
136
|
var mergeBytes = (bytesArr) => {
|
|
174
137
|
const totalLength = bytesArr.reduce((total, arr) => total + arr.length, 0);
|
|
@@ -180,16 +143,16 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
180
143
|
});
|
|
181
144
|
return result;
|
|
182
145
|
};
|
|
183
|
-
var padBytes = (
|
|
184
|
-
if (
|
|
185
|
-
return
|
|
146
|
+
var padBytes = (bytes2, length) => {
|
|
147
|
+
if (bytes2.length >= length)
|
|
148
|
+
return bytes2;
|
|
186
149
|
const paddedBytes = new Uint8Array(length).fill(0);
|
|
187
|
-
paddedBytes.set(
|
|
150
|
+
paddedBytes.set(bytes2);
|
|
188
151
|
return paddedBytes;
|
|
189
152
|
};
|
|
190
|
-
var fixBytes = (
|
|
153
|
+
var fixBytes = (bytes2, length) => padBytes(bytes2.slice(0, length), length);
|
|
191
154
|
|
|
192
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.
|
|
155
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/errors.mjs
|
|
193
156
|
init_env_shim();
|
|
194
157
|
var DeserializingEmptyBufferError = class extends Error {
|
|
195
158
|
constructor(serializer) {
|
|
@@ -203,8 +166,15 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
203
166
|
__publicField(this, "name", "NotEnoughBytesError");
|
|
204
167
|
}
|
|
205
168
|
};
|
|
169
|
+
var ExpectedFixedSizeSerializerError = class extends Error {
|
|
170
|
+
constructor(message) {
|
|
171
|
+
message ?? (message = "Expected a fixed-size serializer, got a variable-size one.");
|
|
172
|
+
super(message);
|
|
173
|
+
__publicField(this, "name", "ExpectedFixedSizeSerializerError");
|
|
174
|
+
}
|
|
175
|
+
};
|
|
206
176
|
|
|
207
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.
|
|
177
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/fixSerializer.mjs
|
|
208
178
|
init_env_shim();
|
|
209
179
|
function fixSerializer(serializer, fixedBytes, description) {
|
|
210
180
|
return {
|
|
@@ -226,13 +196,28 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
226
196
|
};
|
|
227
197
|
}
|
|
228
198
|
|
|
229
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-
|
|
199
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/mapSerializer.mjs
|
|
200
|
+
init_env_shim();
|
|
201
|
+
function mapSerializer(serializer, unmap, map) {
|
|
202
|
+
return {
|
|
203
|
+
description: serializer.description,
|
|
204
|
+
fixedSize: serializer.fixedSize,
|
|
205
|
+
maxSize: serializer.maxSize,
|
|
206
|
+
serialize: (value) => serializer.serialize(unmap(value)),
|
|
207
|
+
deserialize: (buffer, offset = 0) => {
|
|
208
|
+
const [value, length] = serializer.deserialize(buffer, offset);
|
|
209
|
+
return map ? [map(value, buffer, offset), length] : [value, length];
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/index.mjs
|
|
230
215
|
init_env_shim();
|
|
231
216
|
|
|
232
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.
|
|
217
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
|
|
233
218
|
init_env_shim();
|
|
234
219
|
|
|
235
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.
|
|
220
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
|
|
236
221
|
init_env_shim();
|
|
237
222
|
var InvalidBaseStringError = class extends Error {
|
|
238
223
|
constructor(value, base, cause) {
|
|
@@ -243,7 +228,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
243
228
|
}
|
|
244
229
|
};
|
|
245
230
|
|
|
246
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.
|
|
231
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
|
|
247
232
|
var baseX = (alphabet) => {
|
|
248
233
|
const base = alphabet.length;
|
|
249
234
|
const baseBigInt = BigInt(base);
|
|
@@ -280,13 +265,13 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
280
265
|
deserialize(buffer, offset = 0) {
|
|
281
266
|
if (buffer.length === 0)
|
|
282
267
|
return ["", 0];
|
|
283
|
-
const
|
|
284
|
-
let trailIndex =
|
|
285
|
-
trailIndex = trailIndex === -1 ?
|
|
268
|
+
const bytes2 = buffer.slice(offset);
|
|
269
|
+
let trailIndex = bytes2.findIndex((n) => n !== 0);
|
|
270
|
+
trailIndex = trailIndex === -1 ? bytes2.length : trailIndex;
|
|
286
271
|
const leadingZeroes = alphabet[0].repeat(trailIndex);
|
|
287
|
-
if (trailIndex ===
|
|
272
|
+
if (trailIndex === bytes2.length)
|
|
288
273
|
return [leadingZeroes, buffer.length];
|
|
289
|
-
let base10Number =
|
|
274
|
+
let base10Number = bytes2.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
|
|
290
275
|
const tailChars = [];
|
|
291
276
|
while (base10Number > 0n) {
|
|
292
277
|
tailChars.unshift(alphabet[Number(base10Number % baseBigInt)]);
|
|
@@ -297,18 +282,18 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
297
282
|
};
|
|
298
283
|
};
|
|
299
284
|
|
|
300
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.
|
|
285
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base58.mjs
|
|
301
286
|
init_env_shim();
|
|
302
287
|
var base58 = baseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
303
288
|
|
|
304
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.
|
|
289
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/nullCharacters.mjs
|
|
305
290
|
init_env_shim();
|
|
306
291
|
var removeNullCharacters = (value) => (
|
|
307
292
|
// eslint-disable-next-line no-control-regex
|
|
308
293
|
value.replace(/\u0000/g, "")
|
|
309
294
|
);
|
|
310
295
|
|
|
311
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.
|
|
296
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/utf8.mjs
|
|
312
297
|
init_env_shim();
|
|
313
298
|
var utf8 = {
|
|
314
299
|
description: "utf8",
|
|
@@ -323,10 +308,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
323
308
|
}
|
|
324
309
|
};
|
|
325
310
|
|
|
326
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.
|
|
311
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/index.mjs
|
|
327
312
|
init_env_shim();
|
|
328
313
|
|
|
329
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.
|
|
314
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/common.mjs
|
|
330
315
|
init_env_shim();
|
|
331
316
|
var Endian;
|
|
332
317
|
(function(Endian2) {
|
|
@@ -334,7 +319,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
334
319
|
Endian2["Big"] = "be";
|
|
335
320
|
})(Endian || (Endian = {}));
|
|
336
321
|
|
|
337
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.
|
|
322
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/errors.mjs
|
|
338
323
|
init_env_shim();
|
|
339
324
|
var NumberOutOfRangeError = class extends RangeError {
|
|
340
325
|
constructor(serializer, min, max, actual) {
|
|
@@ -343,7 +328,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
343
328
|
}
|
|
344
329
|
};
|
|
345
330
|
|
|
346
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.
|
|
331
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/utils.mjs
|
|
347
332
|
init_env_shim();
|
|
348
333
|
function numberFactory(input) {
|
|
349
334
|
let littleEndian;
|
|
@@ -364,31 +349,42 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
364
349
|
input.set(new DataView(buffer), value, littleEndian);
|
|
365
350
|
return new Uint8Array(buffer);
|
|
366
351
|
},
|
|
367
|
-
deserialize(
|
|
368
|
-
const slice =
|
|
352
|
+
deserialize(bytes2, offset = 0) {
|
|
353
|
+
const slice = bytes2.slice(offset, offset + input.size);
|
|
369
354
|
assertEnoughBytes("i8", slice, input.size);
|
|
370
355
|
const view = toDataView(slice);
|
|
371
356
|
return [input.get(view, littleEndian), offset + input.size];
|
|
372
357
|
}
|
|
373
358
|
};
|
|
374
359
|
}
|
|
375
|
-
var toArrayBuffer = (
|
|
376
|
-
var toDataView = (
|
|
360
|
+
var toArrayBuffer = (array2) => array2.buffer.slice(array2.byteOffset, array2.byteLength + array2.byteOffset);
|
|
361
|
+
var toDataView = (array2) => new DataView(toArrayBuffer(array2));
|
|
377
362
|
var assertRange = (serializer, min, max, value) => {
|
|
378
363
|
if (value < min || value > max) {
|
|
379
364
|
throw new NumberOutOfRangeError(serializer, min, max, value);
|
|
380
365
|
}
|
|
381
366
|
};
|
|
382
|
-
var assertEnoughBytes = (serializer,
|
|
383
|
-
if (
|
|
367
|
+
var assertEnoughBytes = (serializer, bytes2, expected) => {
|
|
368
|
+
if (bytes2.length === 0) {
|
|
384
369
|
throw new DeserializingEmptyBufferError(serializer);
|
|
385
370
|
}
|
|
386
|
-
if (
|
|
387
|
-
throw new NotEnoughBytesError(serializer, expected,
|
|
371
|
+
if (bytes2.length < expected) {
|
|
372
|
+
throw new NotEnoughBytesError(serializer, expected, bytes2.length);
|
|
388
373
|
}
|
|
389
374
|
};
|
|
390
375
|
|
|
391
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.
|
|
376
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u8.mjs
|
|
377
|
+
init_env_shim();
|
|
378
|
+
var u8 = (options = {}) => numberFactory({
|
|
379
|
+
name: "u8",
|
|
380
|
+
size: 1,
|
|
381
|
+
range: [0, Number("0xff")],
|
|
382
|
+
set: (view, value) => view.setUint8(0, Number(value)),
|
|
383
|
+
get: (view) => view.getUint8(0),
|
|
384
|
+
options
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u32.mjs
|
|
392
388
|
init_env_shim();
|
|
393
389
|
var u32 = (options = {}) => numberFactory({
|
|
394
390
|
name: "u32",
|
|
@@ -399,13 +395,195 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
399
395
|
options
|
|
400
396
|
});
|
|
401
397
|
|
|
402
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.
|
|
398
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/shortU16.mjs
|
|
403
399
|
init_env_shim();
|
|
400
|
+
var shortU16 = (options = {}) => ({
|
|
401
|
+
description: options.description ?? "shortU16",
|
|
402
|
+
fixedSize: null,
|
|
403
|
+
maxSize: 3,
|
|
404
|
+
serialize: (value) => {
|
|
405
|
+
assertRange("shortU16", 0, 65535, value);
|
|
406
|
+
const bytes2 = [0];
|
|
407
|
+
for (let ii = 0; ; ii += 1) {
|
|
408
|
+
const alignedValue = value >> ii * 7;
|
|
409
|
+
if (alignedValue === 0) {
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
const nextSevenBits = 127 & alignedValue;
|
|
413
|
+
bytes2[ii] = nextSevenBits;
|
|
414
|
+
if (ii > 0) {
|
|
415
|
+
bytes2[ii - 1] |= 128;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return new Uint8Array(bytes2);
|
|
419
|
+
},
|
|
420
|
+
deserialize: (bytes2, offset = 0) => {
|
|
421
|
+
let value = 0;
|
|
422
|
+
let byteCount = 0;
|
|
423
|
+
while (++byteCount) {
|
|
424
|
+
const byteIndex = byteCount - 1;
|
|
425
|
+
const currentByte = bytes2[offset + byteIndex];
|
|
426
|
+
const nextSevenBits = 127 & currentByte;
|
|
427
|
+
value |= nextSevenBits << byteIndex * 7;
|
|
428
|
+
if ((currentByte & 128) === 0) {
|
|
429
|
+
break;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
return [value, offset + byteCount];
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
|
|
437
|
+
init_env_shim();
|
|
438
|
+
|
|
439
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/errors.mjs
|
|
440
|
+
init_env_shim();
|
|
441
|
+
var InvalidNumberOfItemsError = class extends Error {
|
|
442
|
+
constructor(serializer, expected, actual) {
|
|
443
|
+
super(`Expected [${serializer}] to have ${expected} items, got ${actual}.`);
|
|
444
|
+
__publicField(this, "name", "InvalidNumberOfItemsError");
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
var InvalidArrayLikeRemainderSizeError = class extends Error {
|
|
448
|
+
constructor(remainderSize, itemSize) {
|
|
449
|
+
super(`The remainder of the buffer (${remainderSize} bytes) cannot be split into chunks of ${itemSize} bytes. Serializers of "remainder" size must have a remainder that is a multiple of its item size. In other words, ${remainderSize} modulo ${itemSize} should be equal to zero.`);
|
|
450
|
+
__publicField(this, "name", "InvalidArrayLikeRemainderSizeError");
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
var UnrecognizedArrayLikeSerializerSizeError = class extends Error {
|
|
454
|
+
constructor(size) {
|
|
455
|
+
super(`Unrecognized array-like serializer size: ${JSON.stringify(size)}`);
|
|
456
|
+
__publicField(this, "name", "UnrecognizedArrayLikeSerializerSizeError");
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
|
|
461
|
+
init_env_shim();
|
|
462
|
+
|
|
463
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/sumSerializerSizes.mjs
|
|
464
|
+
init_env_shim();
|
|
465
|
+
function sumSerializerSizes(sizes) {
|
|
466
|
+
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
|
|
470
|
+
function getResolvedSize(size, childrenSizes, bytes2, offset) {
|
|
471
|
+
if (typeof size === "number") {
|
|
472
|
+
return [size, offset];
|
|
473
|
+
}
|
|
474
|
+
if (typeof size === "object") {
|
|
475
|
+
return size.deserialize(bytes2, offset);
|
|
476
|
+
}
|
|
477
|
+
if (size === "remainder") {
|
|
478
|
+
const childrenSize = sumSerializerSizes(childrenSizes);
|
|
479
|
+
if (childrenSize === null) {
|
|
480
|
+
throw new ExpectedFixedSizeSerializerError('Serializers of "remainder" size must have fixed-size items.');
|
|
481
|
+
}
|
|
482
|
+
const remainder = bytes2.slice(offset).length;
|
|
483
|
+
if (remainder % childrenSize !== 0) {
|
|
484
|
+
throw new InvalidArrayLikeRemainderSizeError(remainder, childrenSize);
|
|
485
|
+
}
|
|
486
|
+
return [remainder / childrenSize, offset];
|
|
487
|
+
}
|
|
488
|
+
throw new UnrecognizedArrayLikeSerializerSizeError(size);
|
|
489
|
+
}
|
|
404
490
|
function getSizeDescription(size) {
|
|
405
491
|
return typeof size === "object" ? size.description : `${size}`;
|
|
406
492
|
}
|
|
493
|
+
function getSizeFromChildren(size, childrenSizes) {
|
|
494
|
+
if (typeof size !== "number")
|
|
495
|
+
return null;
|
|
496
|
+
if (size === 0)
|
|
497
|
+
return 0;
|
|
498
|
+
const childrenSize = sumSerializerSizes(childrenSizes);
|
|
499
|
+
return childrenSize === null ? null : childrenSize * size;
|
|
500
|
+
}
|
|
501
|
+
function getSizePrefix(size, realSize) {
|
|
502
|
+
return typeof size === "object" ? size.serialize(realSize) : new Uint8Array();
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/array.mjs
|
|
506
|
+
function array(item, options = {}) {
|
|
507
|
+
const size = options.size ?? u32();
|
|
508
|
+
if (size === "remainder" && item.fixedSize === null) {
|
|
509
|
+
throw new ExpectedFixedSizeSerializerError('Serializers of "remainder" size must have fixed-size items.');
|
|
510
|
+
}
|
|
511
|
+
return {
|
|
512
|
+
description: options.description ?? `array(${item.description}; ${getSizeDescription(size)})`,
|
|
513
|
+
fixedSize: getSizeFromChildren(size, [item.fixedSize]),
|
|
514
|
+
maxSize: getSizeFromChildren(size, [item.maxSize]),
|
|
515
|
+
serialize: (value) => {
|
|
516
|
+
if (typeof size === "number" && value.length !== size) {
|
|
517
|
+
throw new InvalidNumberOfItemsError("array", size, value.length);
|
|
518
|
+
}
|
|
519
|
+
return mergeBytes([getSizePrefix(size, value.length), ...value.map((v) => item.serialize(v))]);
|
|
520
|
+
},
|
|
521
|
+
deserialize: (bytes2, offset = 0) => {
|
|
522
|
+
if (typeof size === "object" && bytes2.slice(offset).length === 0) {
|
|
523
|
+
return [[], offset];
|
|
524
|
+
}
|
|
525
|
+
const [resolvedSize, newOffset] = getResolvedSize(size, [item.fixedSize], bytes2, offset);
|
|
526
|
+
offset = newOffset;
|
|
527
|
+
const values = [];
|
|
528
|
+
for (let i = 0; i < resolvedSize; i += 1) {
|
|
529
|
+
const [value, newOffset2] = item.deserialize(bytes2, offset);
|
|
530
|
+
values.push(value);
|
|
531
|
+
offset = newOffset2;
|
|
532
|
+
}
|
|
533
|
+
return [values, offset];
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/bytes.mjs
|
|
539
|
+
init_env_shim();
|
|
540
|
+
function bytes(options = {}) {
|
|
541
|
+
const size = options.size ?? "variable";
|
|
542
|
+
const description = options.description ?? `bytes(${getSizeDescription(size)})`;
|
|
543
|
+
const byteSerializer = {
|
|
544
|
+
description,
|
|
545
|
+
fixedSize: null,
|
|
546
|
+
maxSize: null,
|
|
547
|
+
serialize: (value) => new Uint8Array(value),
|
|
548
|
+
deserialize: (bytes2, offset = 0) => {
|
|
549
|
+
const slice = bytes2.slice(offset);
|
|
550
|
+
return [slice, offset + slice.length];
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
if (size === "variable") {
|
|
554
|
+
return byteSerializer;
|
|
555
|
+
}
|
|
556
|
+
if (typeof size === "number") {
|
|
557
|
+
return fixSerializer(byteSerializer, size, description);
|
|
558
|
+
}
|
|
559
|
+
return {
|
|
560
|
+
description,
|
|
561
|
+
fixedSize: null,
|
|
562
|
+
maxSize: null,
|
|
563
|
+
serialize: (value) => {
|
|
564
|
+
const contentBytes = byteSerializer.serialize(value);
|
|
565
|
+
const lengthBytes = size.serialize(contentBytes.length);
|
|
566
|
+
return mergeBytes([lengthBytes, contentBytes]);
|
|
567
|
+
},
|
|
568
|
+
deserialize: (buffer, offset = 0) => {
|
|
569
|
+
if (buffer.slice(offset).length === 0) {
|
|
570
|
+
throw new DeserializingEmptyBufferError("bytes");
|
|
571
|
+
}
|
|
572
|
+
const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
|
|
573
|
+
const length = Number(lengthBigInt);
|
|
574
|
+
offset = lengthOffset;
|
|
575
|
+
const contentBuffer = buffer.slice(offset, offset + length);
|
|
576
|
+
if (contentBuffer.length < length) {
|
|
577
|
+
throw new NotEnoughBytesError("bytes", length, contentBuffer.length);
|
|
578
|
+
}
|
|
579
|
+
const [value, contentOffset] = byteSerializer.deserialize(contentBuffer);
|
|
580
|
+
offset += contentOffset;
|
|
581
|
+
return [value, offset];
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
}
|
|
407
585
|
|
|
408
|
-
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.
|
|
586
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/string.mjs
|
|
409
587
|
init_env_shim();
|
|
410
588
|
function string(options = {}) {
|
|
411
589
|
const size = options.size ?? u32();
|
|
@@ -446,43 +624,33 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
446
624
|
}
|
|
447
625
|
};
|
|
448
626
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
627
|
+
|
|
628
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/struct.mjs
|
|
629
|
+
init_env_shim();
|
|
630
|
+
function struct(fields, options = {}) {
|
|
631
|
+
const fieldDescriptions = fields.map(([name, serializer]) => `${String(name)}: ${serializer.description}`).join(", ");
|
|
632
|
+
return {
|
|
633
|
+
description: options.description ?? `struct(${fieldDescriptions})`,
|
|
634
|
+
fixedSize: sumSerializerSizes(fields.map(([, field]) => field.fixedSize)),
|
|
635
|
+
maxSize: sumSerializerSizes(fields.map(([, field]) => field.maxSize)),
|
|
636
|
+
serialize: (struct2) => {
|
|
637
|
+
const fieldBytes = fields.map(([key, serializer]) => serializer.serialize(struct2[key]));
|
|
638
|
+
return mergeBytes(fieldBytes);
|
|
639
|
+
},
|
|
640
|
+
deserialize: (bytes2, offset = 0) => {
|
|
641
|
+
const struct2 = {};
|
|
642
|
+
fields.forEach(([key, serializer]) => {
|
|
643
|
+
const [value, newOffset] = serializer.deserialize(bytes2, offset);
|
|
644
|
+
offset = newOffset;
|
|
645
|
+
struct2[key] = value;
|
|
646
|
+
});
|
|
647
|
+
return [struct2, offset];
|
|
462
648
|
}
|
|
463
|
-
}
|
|
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;
|
|
649
|
+
};
|
|
485
650
|
}
|
|
651
|
+
|
|
652
|
+
// ../assertions/dist/index.browser.js
|
|
653
|
+
init_env_shim();
|
|
486
654
|
function assertIsSecureContext() {
|
|
487
655
|
if (!globalThis.isSecureContext) {
|
|
488
656
|
throw new Error(
|
|
@@ -512,6 +680,12 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
512
680
|
return await cachedEd25519Decision;
|
|
513
681
|
}
|
|
514
682
|
}
|
|
683
|
+
async function assertDigestCapabilityIsAvailable() {
|
|
684
|
+
assertIsSecureContext();
|
|
685
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.digest !== "function") {
|
|
686
|
+
throw new Error("No digest implementation could be found");
|
|
687
|
+
}
|
|
688
|
+
}
|
|
515
689
|
async function assertKeyGenerationIsAvailable() {
|
|
516
690
|
assertIsSecureContext();
|
|
517
691
|
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
|
|
@@ -529,54 +703,1100 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
529
703
|
throw new Error("No key export implementation could be found");
|
|
530
704
|
}
|
|
531
705
|
}
|
|
532
|
-
async function assertSigningCapabilityIsAvailable() {
|
|
533
|
-
assertIsSecureContext();
|
|
534
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
|
|
535
|
-
throw new Error("No signing implementation could be found");
|
|
706
|
+
async function assertSigningCapabilityIsAvailable() {
|
|
707
|
+
assertIsSecureContext();
|
|
708
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.sign !== "function") {
|
|
709
|
+
throw new Error("No signing implementation could be found");
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
async function assertVerificationCapabilityIsAvailable() {
|
|
713
|
+
assertIsSecureContext();
|
|
714
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.verify !== "function") {
|
|
715
|
+
throw new Error("No signature verification implementation could be found");
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
function isBase58EncodedAddress(putativeBase58EncodedAddress) {
|
|
719
|
+
if (
|
|
720
|
+
// Lowest address (32 bytes of zeroes)
|
|
721
|
+
putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
722
|
+
putativeBase58EncodedAddress.length > 44
|
|
723
|
+
) {
|
|
724
|
+
return false;
|
|
725
|
+
}
|
|
726
|
+
const bytes2 = base58.serialize(putativeBase58EncodedAddress);
|
|
727
|
+
const numBytes = bytes2.byteLength;
|
|
728
|
+
if (numBytes !== 32) {
|
|
729
|
+
return false;
|
|
730
|
+
}
|
|
731
|
+
return true;
|
|
732
|
+
}
|
|
733
|
+
function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
|
|
734
|
+
try {
|
|
735
|
+
if (
|
|
736
|
+
// Lowest address (32 bytes of zeroes)
|
|
737
|
+
putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
738
|
+
putativeBase58EncodedAddress.length > 44
|
|
739
|
+
) {
|
|
740
|
+
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
741
|
+
}
|
|
742
|
+
const bytes2 = base58.serialize(putativeBase58EncodedAddress);
|
|
743
|
+
const numBytes = bytes2.byteLength;
|
|
744
|
+
if (numBytes !== 32) {
|
|
745
|
+
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
746
|
+
}
|
|
747
|
+
} catch (e3) {
|
|
748
|
+
throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
|
|
749
|
+
cause: e3
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
function address(putativeBase58EncodedAddress) {
|
|
754
|
+
assertIsBase58EncodedAddress(putativeBase58EncodedAddress);
|
|
755
|
+
return putativeBase58EncodedAddress;
|
|
756
|
+
}
|
|
757
|
+
function getBase58EncodedAddressCodec(config) {
|
|
758
|
+
return string({
|
|
759
|
+
description: config?.description ?? ("A 32-byte account address" ),
|
|
760
|
+
encoding: base58,
|
|
761
|
+
size: 32
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
function getBase58EncodedAddressComparator() {
|
|
765
|
+
return new Intl.Collator("en", {
|
|
766
|
+
caseFirst: "lower",
|
|
767
|
+
ignorePunctuation: false,
|
|
768
|
+
localeMatcher: "best fit",
|
|
769
|
+
numeric: false,
|
|
770
|
+
sensitivity: "variant",
|
|
771
|
+
usage: "sort"
|
|
772
|
+
}).compare;
|
|
773
|
+
}
|
|
774
|
+
var D = 37095705934669439343138083508754565189542113879843219016388785533085940283555n;
|
|
775
|
+
var P = 57896044618658097711785492504343953926634992332820282019728792003956564819949n;
|
|
776
|
+
var RM1 = 19681161376707505956807079304988542015446066515923890162744021073123829784752n;
|
|
777
|
+
function mod(a) {
|
|
778
|
+
const r = a % P;
|
|
779
|
+
return r >= 0n ? r : P + r;
|
|
780
|
+
}
|
|
781
|
+
function pow2(x, power) {
|
|
782
|
+
let r = x;
|
|
783
|
+
while (power-- > 0n) {
|
|
784
|
+
r *= r;
|
|
785
|
+
r %= P;
|
|
786
|
+
}
|
|
787
|
+
return r;
|
|
788
|
+
}
|
|
789
|
+
function pow_2_252_3(x) {
|
|
790
|
+
const x2 = x * x % P;
|
|
791
|
+
const b2 = x2 * x % P;
|
|
792
|
+
const b4 = pow2(b2, 2n) * b2 % P;
|
|
793
|
+
const b5 = pow2(b4, 1n) * x % P;
|
|
794
|
+
const b10 = pow2(b5, 5n) * b5 % P;
|
|
795
|
+
const b20 = pow2(b10, 10n) * b10 % P;
|
|
796
|
+
const b40 = pow2(b20, 20n) * b20 % P;
|
|
797
|
+
const b80 = pow2(b40, 40n) * b40 % P;
|
|
798
|
+
const b160 = pow2(b80, 80n) * b80 % P;
|
|
799
|
+
const b240 = pow2(b160, 80n) * b80 % P;
|
|
800
|
+
const b250 = pow2(b240, 10n) * b10 % P;
|
|
801
|
+
const pow_p_5_8 = pow2(b250, 2n) * x % P;
|
|
802
|
+
return pow_p_5_8;
|
|
803
|
+
}
|
|
804
|
+
function uvRatio(u, v) {
|
|
805
|
+
const v3 = mod(v * v * v);
|
|
806
|
+
const v7 = mod(v3 * v3 * v);
|
|
807
|
+
const pow = pow_2_252_3(u * v7);
|
|
808
|
+
let x = mod(u * v3 * pow);
|
|
809
|
+
const vx2 = mod(v * x * x);
|
|
810
|
+
const root1 = x;
|
|
811
|
+
const root2 = mod(x * RM1);
|
|
812
|
+
const useRoot1 = vx2 === u;
|
|
813
|
+
const useRoot2 = vx2 === mod(-u);
|
|
814
|
+
const noRoot = vx2 === mod(-u * RM1);
|
|
815
|
+
if (useRoot1)
|
|
816
|
+
x = root1;
|
|
817
|
+
if (useRoot2 || noRoot)
|
|
818
|
+
x = root2;
|
|
819
|
+
if ((mod(x) & 1n) === 1n)
|
|
820
|
+
x = mod(-x);
|
|
821
|
+
if (!useRoot1 && !useRoot2) {
|
|
822
|
+
return null;
|
|
823
|
+
}
|
|
824
|
+
return x;
|
|
825
|
+
}
|
|
826
|
+
function pointIsOnCurve(y, lastByte) {
|
|
827
|
+
const y2 = mod(y * y);
|
|
828
|
+
const u = mod(y2 - 1n);
|
|
829
|
+
const v = mod(D * y2 + 1n);
|
|
830
|
+
const x = uvRatio(u, v);
|
|
831
|
+
if (x === null) {
|
|
832
|
+
return false;
|
|
833
|
+
}
|
|
834
|
+
const isLastByteOdd = (lastByte & 128) !== 0;
|
|
835
|
+
if (x === 0n && isLastByteOdd) {
|
|
836
|
+
return false;
|
|
837
|
+
}
|
|
838
|
+
return true;
|
|
839
|
+
}
|
|
840
|
+
function byteToHex(byte) {
|
|
841
|
+
const hexString = byte.toString(16);
|
|
842
|
+
if (hexString.length === 1) {
|
|
843
|
+
return `0${hexString}`;
|
|
844
|
+
} else {
|
|
845
|
+
return hexString;
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
function decompressPointBytes(bytes2) {
|
|
849
|
+
const hexString = bytes2.reduce((acc, byte, ii) => `${byteToHex(ii === 31 ? byte & ~128 : byte)}${acc}`, "");
|
|
850
|
+
const integerLiteralString = `0x${hexString}`;
|
|
851
|
+
return BigInt(integerLiteralString);
|
|
852
|
+
}
|
|
853
|
+
async function compressedPointBytesAreOnCurve(bytes2) {
|
|
854
|
+
if (bytes2.byteLength !== 32) {
|
|
855
|
+
return false;
|
|
856
|
+
}
|
|
857
|
+
const y = decompressPointBytes(bytes2);
|
|
858
|
+
return pointIsOnCurve(y, bytes2[31]);
|
|
859
|
+
}
|
|
860
|
+
var MAX_SEED_LENGTH = 32;
|
|
861
|
+
var MAX_SEEDS = 16;
|
|
862
|
+
var PDA_MARKER_BYTES = [
|
|
863
|
+
// The string 'ProgramDerivedAddress'
|
|
864
|
+
80,
|
|
865
|
+
114,
|
|
866
|
+
111,
|
|
867
|
+
103,
|
|
868
|
+
114,
|
|
869
|
+
97,
|
|
870
|
+
109,
|
|
871
|
+
68,
|
|
872
|
+
101,
|
|
873
|
+
114,
|
|
874
|
+
105,
|
|
875
|
+
118,
|
|
876
|
+
101,
|
|
877
|
+
100,
|
|
878
|
+
65,
|
|
879
|
+
100,
|
|
880
|
+
100,
|
|
881
|
+
114,
|
|
882
|
+
101,
|
|
883
|
+
115,
|
|
884
|
+
115
|
|
885
|
+
];
|
|
886
|
+
var PointOnCurveError = class extends Error {
|
|
887
|
+
};
|
|
888
|
+
async function createProgramDerivedAddress({ programAddress, seeds }) {
|
|
889
|
+
await assertDigestCapabilityIsAvailable();
|
|
890
|
+
if (seeds.length > MAX_SEEDS) {
|
|
891
|
+
throw new Error(`A maximum of ${MAX_SEEDS} seeds may be supplied when creating an address`);
|
|
892
|
+
}
|
|
893
|
+
let textEncoder;
|
|
894
|
+
const seedBytes = seeds.reduce((acc, seed, ii) => {
|
|
895
|
+
const bytes2 = typeof seed === "string" ? (textEncoder || (textEncoder = new TextEncoder())).encode(seed) : seed;
|
|
896
|
+
if (bytes2.byteLength > MAX_SEED_LENGTH) {
|
|
897
|
+
throw new Error(`The seed at index ${ii} exceeds the maximum length of 32 bytes`);
|
|
898
|
+
}
|
|
899
|
+
acc.push(...bytes2);
|
|
900
|
+
return acc;
|
|
901
|
+
}, []);
|
|
902
|
+
const base58EncodedAddressCodec = getBase58EncodedAddressCodec();
|
|
903
|
+
const programAddressBytes = base58EncodedAddressCodec.serialize(programAddress);
|
|
904
|
+
const addressBytesBuffer = await crypto.subtle.digest(
|
|
905
|
+
"SHA-256",
|
|
906
|
+
new Uint8Array([...seedBytes, ...programAddressBytes, ...PDA_MARKER_BYTES])
|
|
907
|
+
);
|
|
908
|
+
const addressBytes = new Uint8Array(addressBytesBuffer);
|
|
909
|
+
if (await compressedPointBytesAreOnCurve(addressBytes)) {
|
|
910
|
+
throw new PointOnCurveError("Invalid seeds; point must fall off the Ed25519 curve");
|
|
911
|
+
}
|
|
912
|
+
return base58EncodedAddressCodec.deserialize(addressBytes)[0];
|
|
913
|
+
}
|
|
914
|
+
async function getProgramDerivedAddress({ programAddress, seeds }) {
|
|
915
|
+
let bumpSeed = 255;
|
|
916
|
+
while (bumpSeed > 0) {
|
|
917
|
+
try {
|
|
918
|
+
return {
|
|
919
|
+
bumpSeed,
|
|
920
|
+
pda: await createProgramDerivedAddress({
|
|
921
|
+
programAddress,
|
|
922
|
+
seeds: [...seeds, new Uint8Array([bumpSeed])]
|
|
923
|
+
})
|
|
924
|
+
};
|
|
925
|
+
} catch (e3) {
|
|
926
|
+
if (e3 instanceof PointOnCurveError) {
|
|
927
|
+
bumpSeed--;
|
|
928
|
+
} else {
|
|
929
|
+
throw e3;
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
throw new Error("Unable to find a viable program address bump seed");
|
|
934
|
+
}
|
|
935
|
+
async function createAddressWithSeed({
|
|
936
|
+
baseAddress,
|
|
937
|
+
programAddress,
|
|
938
|
+
seed
|
|
939
|
+
}) {
|
|
940
|
+
const { serialize: serialize4, deserialize: deserialize2 } = getBase58EncodedAddressCodec();
|
|
941
|
+
const seedBytes = typeof seed === "string" ? new TextEncoder().encode(seed) : seed;
|
|
942
|
+
if (seedBytes.byteLength > MAX_SEED_LENGTH) {
|
|
943
|
+
throw new Error(`The seed exceeds the maximum length of 32 bytes`);
|
|
944
|
+
}
|
|
945
|
+
const programAddressBytes = serialize4(programAddress);
|
|
946
|
+
if (programAddressBytes.length >= PDA_MARKER_BYTES.length && programAddressBytes.slice(-PDA_MARKER_BYTES.length).every((byte, index) => byte === PDA_MARKER_BYTES[index])) {
|
|
947
|
+
throw new Error(`programAddress cannot end with the PDA marker`);
|
|
948
|
+
}
|
|
949
|
+
const addressBytesBuffer = await crypto.subtle.digest(
|
|
950
|
+
"SHA-256",
|
|
951
|
+
new Uint8Array([...serialize4(baseAddress), ...seedBytes, ...programAddressBytes])
|
|
952
|
+
);
|
|
953
|
+
const addressBytes = new Uint8Array(addressBytesBuffer);
|
|
954
|
+
return deserialize2(addressBytes)[0];
|
|
955
|
+
}
|
|
956
|
+
async function getAddressFromPublicKey(publicKey) {
|
|
957
|
+
await assertKeyExporterIsAvailable();
|
|
958
|
+
if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
|
|
959
|
+
throw new Error("The `CryptoKey` must be an `Ed25519` public key");
|
|
960
|
+
}
|
|
961
|
+
const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
|
|
962
|
+
const [base58EncodedAddress] = getBase58EncodedAddressCodec().deserialize(new Uint8Array(publicKeyBytes));
|
|
963
|
+
return base58EncodedAddress;
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
// ../instructions/dist/index.browser.js
|
|
967
|
+
init_env_shim();
|
|
968
|
+
var AccountRole = /* @__PURE__ */ ((AccountRole22) => {
|
|
969
|
+
AccountRole22[AccountRole22["WRITABLE_SIGNER"] = /* 3 */
|
|
970
|
+
3] = "WRITABLE_SIGNER";
|
|
971
|
+
AccountRole22[AccountRole22["READONLY_SIGNER"] = /* 2 */
|
|
972
|
+
2] = "READONLY_SIGNER";
|
|
973
|
+
AccountRole22[AccountRole22["WRITABLE"] = /* 1 */
|
|
974
|
+
1] = "WRITABLE";
|
|
975
|
+
AccountRole22[AccountRole22["READONLY"] = /* 0 */
|
|
976
|
+
0] = "READONLY";
|
|
977
|
+
return AccountRole22;
|
|
978
|
+
})(AccountRole || {});
|
|
979
|
+
var IS_SIGNER_BITMASK = 2;
|
|
980
|
+
var IS_WRITABLE_BITMASK = 1;
|
|
981
|
+
function downgradeRoleToNonSigner(role) {
|
|
982
|
+
return role & ~IS_SIGNER_BITMASK;
|
|
983
|
+
}
|
|
984
|
+
function downgradeRoleToReadonly(role) {
|
|
985
|
+
return role & ~IS_WRITABLE_BITMASK;
|
|
986
|
+
}
|
|
987
|
+
function isSignerRole(role) {
|
|
988
|
+
return role >= 2;
|
|
989
|
+
}
|
|
990
|
+
function isWritableRole(role) {
|
|
991
|
+
return (role & IS_WRITABLE_BITMASK) !== 0;
|
|
992
|
+
}
|
|
993
|
+
function mergeRoles(roleA, roleB) {
|
|
994
|
+
return roleA | roleB;
|
|
995
|
+
}
|
|
996
|
+
function upgradeRoleToSigner(role) {
|
|
997
|
+
return role | IS_SIGNER_BITMASK;
|
|
998
|
+
}
|
|
999
|
+
function upgradeRoleToWritable(role) {
|
|
1000
|
+
return role | IS_WRITABLE_BITMASK;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
// ../keys/dist/index.browser.js
|
|
1004
|
+
init_env_shim();
|
|
1005
|
+
async function generateKeyPair() {
|
|
1006
|
+
await assertKeyGenerationIsAvailable();
|
|
1007
|
+
const keyPair = await crypto.subtle.generateKey(
|
|
1008
|
+
/* algorithm */
|
|
1009
|
+
"Ed25519",
|
|
1010
|
+
// Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
|
|
1011
|
+
/* extractable */
|
|
1012
|
+
false,
|
|
1013
|
+
// Prevents the bytes of the private key from being visible to JS.
|
|
1014
|
+
/* allowed uses */
|
|
1015
|
+
["sign", "verify"]
|
|
1016
|
+
);
|
|
1017
|
+
return keyPair;
|
|
1018
|
+
}
|
|
1019
|
+
async function signBytes(key, data) {
|
|
1020
|
+
await assertSigningCapabilityIsAvailable();
|
|
1021
|
+
const signedData = await crypto.subtle.sign("Ed25519", key, data);
|
|
1022
|
+
return new Uint8Array(signedData);
|
|
1023
|
+
}
|
|
1024
|
+
async function verifySignature(key, signature, data) {
|
|
1025
|
+
await assertVerificationCapabilityIsAvailable();
|
|
1026
|
+
return await crypto.subtle.verify("Ed25519", key, signature, data);
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
// ../transactions/dist/index.browser.js
|
|
1030
|
+
init_env_shim();
|
|
1031
|
+
function getUnsignedTransaction(transaction) {
|
|
1032
|
+
if ("signatures" in transaction) {
|
|
1033
|
+
const {
|
|
1034
|
+
signatures: _,
|
|
1035
|
+
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
1036
|
+
...unsignedTransaction
|
|
1037
|
+
} = transaction;
|
|
1038
|
+
return unsignedTransaction;
|
|
1039
|
+
} else {
|
|
1040
|
+
return transaction;
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
function assertIsBlockhash(putativeBlockhash) {
|
|
1044
|
+
try {
|
|
1045
|
+
if (
|
|
1046
|
+
// Lowest value (32 bytes of zeroes)
|
|
1047
|
+
putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
|
|
1048
|
+
putativeBlockhash.length > 44
|
|
1049
|
+
) {
|
|
1050
|
+
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
1051
|
+
}
|
|
1052
|
+
const bytes3 = base58.serialize(putativeBlockhash);
|
|
1053
|
+
const numBytes = bytes3.byteLength;
|
|
1054
|
+
if (numBytes !== 32) {
|
|
1055
|
+
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
1056
|
+
}
|
|
1057
|
+
} catch (e3) {
|
|
1058
|
+
throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
|
|
1059
|
+
cause: e3
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
|
|
1064
|
+
if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
|
|
1065
|
+
return transaction;
|
|
1066
|
+
}
|
|
1067
|
+
const out = {
|
|
1068
|
+
...getUnsignedTransaction(transaction),
|
|
1069
|
+
lifetimeConstraint: blockhashLifetimeConstraint
|
|
1070
|
+
};
|
|
1071
|
+
Object.freeze(out);
|
|
1072
|
+
return out;
|
|
1073
|
+
}
|
|
1074
|
+
function createTransaction({
|
|
1075
|
+
version
|
|
1076
|
+
}) {
|
|
1077
|
+
const out = {
|
|
1078
|
+
instructions: [],
|
|
1079
|
+
version
|
|
1080
|
+
};
|
|
1081
|
+
Object.freeze(out);
|
|
1082
|
+
return out;
|
|
1083
|
+
}
|
|
1084
|
+
var AccountRole2 = /* @__PURE__ */ ((AccountRole22) => {
|
|
1085
|
+
AccountRole22[AccountRole22["WRITABLE_SIGNER"] = /* 3 */
|
|
1086
|
+
3] = "WRITABLE_SIGNER";
|
|
1087
|
+
AccountRole22[AccountRole22["READONLY_SIGNER"] = /* 2 */
|
|
1088
|
+
2] = "READONLY_SIGNER";
|
|
1089
|
+
AccountRole22[AccountRole22["WRITABLE"] = /* 1 */
|
|
1090
|
+
1] = "WRITABLE";
|
|
1091
|
+
AccountRole22[AccountRole22["READONLY"] = /* 0 */
|
|
1092
|
+
0] = "READONLY";
|
|
1093
|
+
return AccountRole22;
|
|
1094
|
+
})(AccountRole2 || {});
|
|
1095
|
+
var IS_WRITABLE_BITMASK2 = 1;
|
|
1096
|
+
function isSignerRole2(role) {
|
|
1097
|
+
return role >= 2;
|
|
1098
|
+
}
|
|
1099
|
+
function isWritableRole2(role) {
|
|
1100
|
+
return (role & IS_WRITABLE_BITMASK2) !== 0;
|
|
1101
|
+
}
|
|
1102
|
+
function mergeRoles2(roleA, roleB) {
|
|
1103
|
+
return roleA | roleB;
|
|
1104
|
+
}
|
|
1105
|
+
var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
|
|
1106
|
+
var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
|
|
1107
|
+
function assertIsDurableNonceTransaction(transaction) {
|
|
1108
|
+
if (!isDurableNonceTransaction(transaction)) {
|
|
1109
|
+
throw new Error("Transaction is not a durable nonce transaction");
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
|
|
1113
|
+
return {
|
|
1114
|
+
accounts: [
|
|
1115
|
+
{ address: nonceAccountAddress, role: AccountRole2.WRITABLE },
|
|
1116
|
+
{
|
|
1117
|
+
address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS,
|
|
1118
|
+
role: AccountRole2.READONLY
|
|
1119
|
+
},
|
|
1120
|
+
{ address: nonceAuthorityAddress, role: AccountRole2.READONLY_SIGNER }
|
|
1121
|
+
],
|
|
1122
|
+
data: new Uint8Array([4, 0, 0, 0]),
|
|
1123
|
+
programAddress: SYSTEM_PROGRAM_ADDRESS
|
|
1124
|
+
};
|
|
1125
|
+
}
|
|
1126
|
+
function isAdvanceNonceAccountInstruction(instruction) {
|
|
1127
|
+
return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
|
|
1128
|
+
instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
|
|
1129
|
+
instruction.accounts?.length === 3 && // First account is nonce account address
|
|
1130
|
+
instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole2.WRITABLE && // Second account is recent blockhashes sysvar
|
|
1131
|
+
instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole2.READONLY && // Third account is nonce authority account
|
|
1132
|
+
instruction.accounts[2].address != null && instruction.accounts[2].role === AccountRole2.READONLY_SIGNER;
|
|
1133
|
+
}
|
|
1134
|
+
function isAdvanceNonceAccountInstructionData(data) {
|
|
1135
|
+
return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
|
|
1136
|
+
}
|
|
1137
|
+
function isDurableNonceTransaction(transaction) {
|
|
1138
|
+
return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
|
|
1139
|
+
}
|
|
1140
|
+
function setTransactionLifetimeUsingDurableNonce({
|
|
1141
|
+
nonce,
|
|
1142
|
+
nonceAccountAddress,
|
|
1143
|
+
nonceAuthorityAddress
|
|
1144
|
+
}, transaction) {
|
|
1145
|
+
const isAlreadyDurableNonceTransaction = isDurableNonceTransaction(transaction);
|
|
1146
|
+
if (isAlreadyDurableNonceTransaction && transaction.lifetimeConstraint.nonce === nonce && transaction.instructions[0].accounts[0].address === nonceAccountAddress && transaction.instructions[0].accounts[2].address === nonceAuthorityAddress) {
|
|
1147
|
+
return transaction;
|
|
1148
|
+
}
|
|
1149
|
+
const out = {
|
|
1150
|
+
...getUnsignedTransaction(transaction),
|
|
1151
|
+
instructions: [
|
|
1152
|
+
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
1153
|
+
...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions
|
|
1154
|
+
],
|
|
1155
|
+
lifetimeConstraint: {
|
|
1156
|
+
nonce
|
|
1157
|
+
}
|
|
1158
|
+
};
|
|
1159
|
+
Object.freeze(out);
|
|
1160
|
+
return out;
|
|
1161
|
+
}
|
|
1162
|
+
function setTransactionFeePayer(feePayer, transaction) {
|
|
1163
|
+
if ("feePayer" in transaction && feePayer === transaction.feePayer) {
|
|
1164
|
+
return transaction;
|
|
1165
|
+
}
|
|
1166
|
+
const out = {
|
|
1167
|
+
...getUnsignedTransaction(transaction),
|
|
1168
|
+
feePayer
|
|
1169
|
+
};
|
|
1170
|
+
Object.freeze(out);
|
|
1171
|
+
return out;
|
|
1172
|
+
}
|
|
1173
|
+
function appendTransactionInstruction(instruction, transaction) {
|
|
1174
|
+
const out = {
|
|
1175
|
+
...getUnsignedTransaction(transaction),
|
|
1176
|
+
instructions: [...transaction.instructions, instruction]
|
|
1177
|
+
};
|
|
1178
|
+
Object.freeze(out);
|
|
1179
|
+
return out;
|
|
1180
|
+
}
|
|
1181
|
+
function prependTransactionInstruction(instruction, transaction) {
|
|
1182
|
+
const out = {
|
|
1183
|
+
...getUnsignedTransaction(transaction),
|
|
1184
|
+
instructions: [instruction, ...transaction.instructions]
|
|
1185
|
+
};
|
|
1186
|
+
Object.freeze(out);
|
|
1187
|
+
return out;
|
|
1188
|
+
}
|
|
1189
|
+
function upsert(addressMap, address2, update) {
|
|
1190
|
+
addressMap[address2] = update(addressMap[address2] ?? { role: AccountRole2.READONLY });
|
|
1191
|
+
}
|
|
1192
|
+
var TYPE = Symbol("AddressMapTypeProperty");
|
|
1193
|
+
function getAddressMapFromInstructions(feePayer, instructions) {
|
|
1194
|
+
const addressMap = {
|
|
1195
|
+
[feePayer]: { [TYPE]: 0, role: AccountRole2.WRITABLE_SIGNER }
|
|
1196
|
+
};
|
|
1197
|
+
const addressesOfInvokedPrograms = /* @__PURE__ */ new Set();
|
|
1198
|
+
for (const instruction of instructions) {
|
|
1199
|
+
upsert(addressMap, instruction.programAddress, (entry) => {
|
|
1200
|
+
addressesOfInvokedPrograms.add(instruction.programAddress);
|
|
1201
|
+
if (TYPE in entry) {
|
|
1202
|
+
if (isWritableRole2(entry.role)) {
|
|
1203
|
+
switch (entry[TYPE]) {
|
|
1204
|
+
case 0:
|
|
1205
|
+
throw new Error(
|
|
1206
|
+
`This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and set as the fee payer. Program addresses may not pay fees.`
|
|
1207
|
+
);
|
|
1208
|
+
default:
|
|
1209
|
+
throw new Error(
|
|
1210
|
+
`This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and marked writable. Program addresses may not be writable.`
|
|
1211
|
+
);
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
if (entry[TYPE] === 2) {
|
|
1215
|
+
return entry;
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
return { [TYPE]: 2, role: AccountRole2.READONLY };
|
|
1219
|
+
});
|
|
1220
|
+
let addressComparator;
|
|
1221
|
+
if (!instruction.accounts) {
|
|
1222
|
+
continue;
|
|
1223
|
+
}
|
|
1224
|
+
for (const account of instruction.accounts) {
|
|
1225
|
+
upsert(addressMap, account.address, (entry) => {
|
|
1226
|
+
const {
|
|
1227
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1228
|
+
address: _,
|
|
1229
|
+
...accountMeta
|
|
1230
|
+
} = account;
|
|
1231
|
+
if (TYPE in entry) {
|
|
1232
|
+
switch (entry[TYPE]) {
|
|
1233
|
+
case 0:
|
|
1234
|
+
return entry;
|
|
1235
|
+
case 1: {
|
|
1236
|
+
const nextRole = mergeRoles2(entry.role, accountMeta.role);
|
|
1237
|
+
if ("lookupTableAddress" in accountMeta) {
|
|
1238
|
+
const shouldReplaceEntry = (
|
|
1239
|
+
// Consider using the new LOOKUP_TABLE if its address is different...
|
|
1240
|
+
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
|
|
1241
|
+
(addressComparator || (addressComparator = getBase58EncodedAddressComparator()))(
|
|
1242
|
+
accountMeta.lookupTableAddress,
|
|
1243
|
+
entry.lookupTableAddress
|
|
1244
|
+
) < 0
|
|
1245
|
+
);
|
|
1246
|
+
if (shouldReplaceEntry) {
|
|
1247
|
+
return {
|
|
1248
|
+
[TYPE]: 1,
|
|
1249
|
+
...accountMeta,
|
|
1250
|
+
role: nextRole
|
|
1251
|
+
};
|
|
1252
|
+
}
|
|
1253
|
+
} else if (isSignerRole2(accountMeta.role)) {
|
|
1254
|
+
return {
|
|
1255
|
+
[TYPE]: 2,
|
|
1256
|
+
role: nextRole
|
|
1257
|
+
};
|
|
1258
|
+
}
|
|
1259
|
+
if (entry.role !== nextRole) {
|
|
1260
|
+
return {
|
|
1261
|
+
...entry,
|
|
1262
|
+
role: nextRole
|
|
1263
|
+
};
|
|
1264
|
+
} else {
|
|
1265
|
+
return entry;
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
case 2: {
|
|
1269
|
+
const nextRole = mergeRoles2(entry.role, accountMeta.role);
|
|
1270
|
+
if (
|
|
1271
|
+
// Check to see if this address represents a program that is invoked
|
|
1272
|
+
// in this transaction.
|
|
1273
|
+
addressesOfInvokedPrograms.has(account.address)
|
|
1274
|
+
) {
|
|
1275
|
+
if (isWritableRole2(accountMeta.role)) {
|
|
1276
|
+
throw new Error(
|
|
1277
|
+
`This transaction includes an address (\`${account.address}\`) which is both invoked and marked writable. Program addresses may not be writable.`
|
|
1278
|
+
);
|
|
1279
|
+
}
|
|
1280
|
+
if (entry.role !== nextRole) {
|
|
1281
|
+
return {
|
|
1282
|
+
...entry,
|
|
1283
|
+
role: nextRole
|
|
1284
|
+
};
|
|
1285
|
+
} else {
|
|
1286
|
+
return entry;
|
|
1287
|
+
}
|
|
1288
|
+
} else if ("lookupTableAddress" in accountMeta && // Static accounts can be 'upgraded' to lookup table accounts as
|
|
1289
|
+
// long as they are not require to sign the transaction.
|
|
1290
|
+
!isSignerRole2(entry.role)) {
|
|
1291
|
+
return {
|
|
1292
|
+
...accountMeta,
|
|
1293
|
+
[TYPE]: 1,
|
|
1294
|
+
role: nextRole
|
|
1295
|
+
};
|
|
1296
|
+
} else {
|
|
1297
|
+
if (entry.role !== nextRole) {
|
|
1298
|
+
return {
|
|
1299
|
+
...entry,
|
|
1300
|
+
role: nextRole
|
|
1301
|
+
};
|
|
1302
|
+
} else {
|
|
1303
|
+
return entry;
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
if ("lookupTableAddress" in accountMeta) {
|
|
1310
|
+
return {
|
|
1311
|
+
...accountMeta,
|
|
1312
|
+
[TYPE]: 1
|
|
1313
|
+
/* LOOKUP_TABLE */
|
|
1314
|
+
};
|
|
1315
|
+
} else {
|
|
1316
|
+
return {
|
|
1317
|
+
...accountMeta,
|
|
1318
|
+
[TYPE]: 2
|
|
1319
|
+
/* STATIC */
|
|
1320
|
+
};
|
|
1321
|
+
}
|
|
1322
|
+
});
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
return addressMap;
|
|
1326
|
+
}
|
|
1327
|
+
function getOrderedAccountsFromAddressMap(addressMap) {
|
|
1328
|
+
let addressComparator;
|
|
1329
|
+
const orderedAccounts = Object.entries(addressMap).sort(([leftAddress, leftEntry], [rightAddress, rightEntry]) => {
|
|
1330
|
+
if (leftEntry[TYPE] !== rightEntry[TYPE]) {
|
|
1331
|
+
if (leftEntry[TYPE] === 0) {
|
|
1332
|
+
return -1;
|
|
1333
|
+
} else if (rightEntry[TYPE] === 0) {
|
|
1334
|
+
return 1;
|
|
1335
|
+
} else if (leftEntry[TYPE] === 2) {
|
|
1336
|
+
return -1;
|
|
1337
|
+
} else if (rightEntry[TYPE] === 2) {
|
|
1338
|
+
return 1;
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
const leftIsSigner = isSignerRole2(leftEntry.role);
|
|
1342
|
+
if (leftIsSigner !== isSignerRole2(rightEntry.role)) {
|
|
1343
|
+
return leftIsSigner ? -1 : 1;
|
|
1344
|
+
}
|
|
1345
|
+
const leftIsWritable = isWritableRole2(leftEntry.role);
|
|
1346
|
+
if (leftIsWritable !== isWritableRole2(rightEntry.role)) {
|
|
1347
|
+
return leftIsWritable ? -1 : 1;
|
|
1348
|
+
}
|
|
1349
|
+
addressComparator || (addressComparator = getBase58EncodedAddressComparator());
|
|
1350
|
+
if (leftEntry[TYPE] === 1 && rightEntry[TYPE] === 1 && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
|
|
1351
|
+
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
|
|
1352
|
+
} else {
|
|
1353
|
+
return addressComparator(leftAddress, rightAddress);
|
|
1354
|
+
}
|
|
1355
|
+
}).map(([address2, addressMeta]) => ({
|
|
1356
|
+
address: address2,
|
|
1357
|
+
...addressMeta
|
|
1358
|
+
}));
|
|
1359
|
+
return orderedAccounts;
|
|
1360
|
+
}
|
|
1361
|
+
function getCompiledAddressTableLookups(orderedAccounts) {
|
|
1362
|
+
var _a;
|
|
1363
|
+
const index = {};
|
|
1364
|
+
for (const account of orderedAccounts) {
|
|
1365
|
+
if (!("lookupTableAddress" in account)) {
|
|
1366
|
+
continue;
|
|
1367
|
+
}
|
|
1368
|
+
const entry = index[_a = account.lookupTableAddress] || (index[_a] = {
|
|
1369
|
+
readableIndices: [],
|
|
1370
|
+
writableIndices: []
|
|
1371
|
+
});
|
|
1372
|
+
if (account.role === AccountRole2.WRITABLE) {
|
|
1373
|
+
entry.writableIndices.push(account.addressIndex);
|
|
1374
|
+
} else {
|
|
1375
|
+
entry.readableIndices.push(account.addressIndex);
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
return Object.keys(index).sort(getBase58EncodedAddressComparator()).map((lookupTableAddress) => ({
|
|
1379
|
+
lookupTableAddress,
|
|
1380
|
+
...index[lookupTableAddress]
|
|
1381
|
+
}));
|
|
1382
|
+
}
|
|
1383
|
+
function getCompiledMessageHeader(orderedAccounts) {
|
|
1384
|
+
let numReadonlyNonSignerAccounts = 0;
|
|
1385
|
+
let numReadonlySignerAccounts = 0;
|
|
1386
|
+
let numSignerAccounts = 0;
|
|
1387
|
+
for (const account of orderedAccounts) {
|
|
1388
|
+
if ("lookupTableAddress" in account) {
|
|
1389
|
+
break;
|
|
1390
|
+
}
|
|
1391
|
+
const accountIsWritable = isWritableRole2(account.role);
|
|
1392
|
+
if (isSignerRole2(account.role)) {
|
|
1393
|
+
numSignerAccounts++;
|
|
1394
|
+
if (!accountIsWritable) {
|
|
1395
|
+
numReadonlySignerAccounts++;
|
|
1396
|
+
}
|
|
1397
|
+
} else if (!accountIsWritable) {
|
|
1398
|
+
numReadonlyNonSignerAccounts++;
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
return {
|
|
1402
|
+
numReadonlyNonSignerAccounts,
|
|
1403
|
+
numReadonlySignerAccounts,
|
|
1404
|
+
numSignerAccounts
|
|
1405
|
+
};
|
|
1406
|
+
}
|
|
1407
|
+
function getAccountIndex(orderedAccounts) {
|
|
1408
|
+
const out = {};
|
|
1409
|
+
for (const [index, account] of orderedAccounts.entries()) {
|
|
1410
|
+
out[account.address] = index;
|
|
1411
|
+
}
|
|
1412
|
+
return out;
|
|
1413
|
+
}
|
|
1414
|
+
function getCompiledInstructions(instructions, orderedAccounts) {
|
|
1415
|
+
const accountIndex = getAccountIndex(orderedAccounts);
|
|
1416
|
+
return instructions.map(({ accounts, data, programAddress }) => {
|
|
1417
|
+
return {
|
|
1418
|
+
programAddressIndex: accountIndex[programAddress],
|
|
1419
|
+
...accounts ? { accountIndices: accounts.map(({ address: address2 }) => accountIndex[address2]) } : null,
|
|
1420
|
+
...data ? { data } : null
|
|
1421
|
+
};
|
|
1422
|
+
});
|
|
1423
|
+
}
|
|
1424
|
+
function getCompiledLifetimeToken(lifetimeConstraint) {
|
|
1425
|
+
if ("nonce" in lifetimeConstraint) {
|
|
1426
|
+
return lifetimeConstraint.nonce;
|
|
1427
|
+
}
|
|
1428
|
+
return lifetimeConstraint.blockhash;
|
|
1429
|
+
}
|
|
1430
|
+
function getCompiledStaticAccounts(orderedAccounts) {
|
|
1431
|
+
const firstLookupTableAccountIndex = orderedAccounts.findIndex((account) => "lookupTableAddress" in account);
|
|
1432
|
+
const orderedStaticAccounts = firstLookupTableAccountIndex === -1 ? orderedAccounts : orderedAccounts.slice(0, firstLookupTableAccountIndex);
|
|
1433
|
+
return orderedStaticAccounts.map(({ address: address2 }) => address2);
|
|
1434
|
+
}
|
|
1435
|
+
function compileMessage(transaction) {
|
|
1436
|
+
const addressMap = getAddressMapFromInstructions(transaction.feePayer, transaction.instructions);
|
|
1437
|
+
const orderedAccounts = getOrderedAccountsFromAddressMap(addressMap);
|
|
1438
|
+
return {
|
|
1439
|
+
...transaction.version !== "legacy" ? { addressTableLookups: getCompiledAddressTableLookups(orderedAccounts) } : null,
|
|
1440
|
+
header: getCompiledMessageHeader(orderedAccounts),
|
|
1441
|
+
instructions: getCompiledInstructions(transaction.instructions, orderedAccounts),
|
|
1442
|
+
lifetimeToken: getCompiledLifetimeToken(transaction.lifetimeConstraint),
|
|
1443
|
+
staticAccounts: getCompiledStaticAccounts(orderedAccounts),
|
|
1444
|
+
version: transaction.version
|
|
1445
|
+
};
|
|
1446
|
+
}
|
|
1447
|
+
function getAddressTableLookupCodec() {
|
|
1448
|
+
return struct(
|
|
1449
|
+
[
|
|
1450
|
+
[
|
|
1451
|
+
"lookupTableAddress",
|
|
1452
|
+
getBase58EncodedAddressCodec(
|
|
1453
|
+
{
|
|
1454
|
+
description: "The address of the address lookup table account from which instruction addresses should be looked up"
|
|
1455
|
+
}
|
|
1456
|
+
)
|
|
1457
|
+
],
|
|
1458
|
+
[
|
|
1459
|
+
"writableIndices",
|
|
1460
|
+
array(u8(), {
|
|
1461
|
+
...{
|
|
1462
|
+
description: "The indices of the accounts in the lookup table that should be loaded as writeable"
|
|
1463
|
+
} ,
|
|
1464
|
+
size: shortU16()
|
|
1465
|
+
})
|
|
1466
|
+
],
|
|
1467
|
+
[
|
|
1468
|
+
"readableIndices",
|
|
1469
|
+
array(u8(), {
|
|
1470
|
+
...{
|
|
1471
|
+
description: "The indices of the accounts in the lookup table that should be loaded as read-only"
|
|
1472
|
+
} ,
|
|
1473
|
+
size: shortU16()
|
|
1474
|
+
})
|
|
1475
|
+
]
|
|
1476
|
+
],
|
|
1477
|
+
{
|
|
1478
|
+
description: "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"
|
|
1479
|
+
}
|
|
1480
|
+
);
|
|
1481
|
+
}
|
|
1482
|
+
function getMessageHeaderCodec() {
|
|
1483
|
+
return struct(
|
|
1484
|
+
[
|
|
1485
|
+
[
|
|
1486
|
+
"numSignerAccounts",
|
|
1487
|
+
u8(
|
|
1488
|
+
{
|
|
1489
|
+
description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction"
|
|
1490
|
+
}
|
|
1491
|
+
)
|
|
1492
|
+
],
|
|
1493
|
+
[
|
|
1494
|
+
"numReadonlySignerAccounts",
|
|
1495
|
+
u8(
|
|
1496
|
+
{
|
|
1497
|
+
description: "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"
|
|
1498
|
+
}
|
|
1499
|
+
)
|
|
1500
|
+
],
|
|
1501
|
+
[
|
|
1502
|
+
"numReadonlyNonSignerAccounts",
|
|
1503
|
+
u8(
|
|
1504
|
+
{
|
|
1505
|
+
description: "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable"
|
|
1506
|
+
}
|
|
1507
|
+
)
|
|
1508
|
+
]
|
|
1509
|
+
],
|
|
1510
|
+
{
|
|
1511
|
+
description: "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses"
|
|
1512
|
+
}
|
|
1513
|
+
);
|
|
1514
|
+
}
|
|
1515
|
+
function getInstructionCodec() {
|
|
1516
|
+
return mapSerializer(
|
|
1517
|
+
struct([
|
|
1518
|
+
[
|
|
1519
|
+
"programAddressIndex",
|
|
1520
|
+
u8(
|
|
1521
|
+
{
|
|
1522
|
+
description: "The index of the program being called, according to the well-ordered accounts list for this transaction"
|
|
1523
|
+
}
|
|
1524
|
+
)
|
|
1525
|
+
],
|
|
1526
|
+
[
|
|
1527
|
+
"accountIndices",
|
|
1528
|
+
array(
|
|
1529
|
+
u8({
|
|
1530
|
+
description: "The index of an account, according to the well-ordered accounts list for this transaction"
|
|
1531
|
+
}),
|
|
1532
|
+
{
|
|
1533
|
+
description: "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" ,
|
|
1534
|
+
size: shortU16()
|
|
1535
|
+
}
|
|
1536
|
+
)
|
|
1537
|
+
],
|
|
1538
|
+
[
|
|
1539
|
+
"data",
|
|
1540
|
+
bytes({
|
|
1541
|
+
description: "An optional buffer of data passed to the instruction" ,
|
|
1542
|
+
size: shortU16()
|
|
1543
|
+
})
|
|
1544
|
+
]
|
|
1545
|
+
]),
|
|
1546
|
+
(value) => {
|
|
1547
|
+
if (value.accountIndices !== void 0 && value.data !== void 0) {
|
|
1548
|
+
return value;
|
|
1549
|
+
}
|
|
1550
|
+
return {
|
|
1551
|
+
...value,
|
|
1552
|
+
accountIndices: value.accountIndices ?? [],
|
|
1553
|
+
data: value.data ?? new Uint8Array(0)
|
|
1554
|
+
};
|
|
1555
|
+
},
|
|
1556
|
+
(value) => {
|
|
1557
|
+
if (value.accountIndices.length && value.data.byteLength) {
|
|
1558
|
+
return value;
|
|
1559
|
+
}
|
|
1560
|
+
const { accountIndices, data, ...rest } = value;
|
|
1561
|
+
return {
|
|
1562
|
+
...rest,
|
|
1563
|
+
...accountIndices.length ? { accountIndices } : null,
|
|
1564
|
+
...data.byteLength ? { data } : null
|
|
1565
|
+
};
|
|
1566
|
+
}
|
|
1567
|
+
);
|
|
1568
|
+
}
|
|
1569
|
+
function getError(type, name) {
|
|
1570
|
+
const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
|
|
1571
|
+
return new Error(
|
|
1572
|
+
`No ${type} exists for ${name}. Use \`get${functionSuffix}()\` if you need a ${type}, and \`get${name}Codec()\` if you need to both encode and decode ${name}`
|
|
1573
|
+
);
|
|
1574
|
+
}
|
|
1575
|
+
function getUnimplementedDecoder(name) {
|
|
1576
|
+
return () => {
|
|
1577
|
+
throw getError("decoder", name);
|
|
1578
|
+
};
|
|
1579
|
+
}
|
|
1580
|
+
var VERSION_FLAG_MASK = 128;
|
|
1581
|
+
var BASE_CONFIG = {
|
|
1582
|
+
description: "A single byte that encodes the version of the transaction" ,
|
|
1583
|
+
fixedSize: null,
|
|
1584
|
+
maxSize: 1
|
|
1585
|
+
};
|
|
1586
|
+
function deserialize(bytes3, offset = 0) {
|
|
1587
|
+
const firstByte = bytes3[offset];
|
|
1588
|
+
if ((firstByte & VERSION_FLAG_MASK) === 0) {
|
|
1589
|
+
return ["legacy", offset];
|
|
1590
|
+
} else {
|
|
1591
|
+
const version = firstByte ^ VERSION_FLAG_MASK;
|
|
1592
|
+
return [version, offset + 1];
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
function serialize(value) {
|
|
1596
|
+
if (value === "legacy") {
|
|
1597
|
+
return new Uint8Array();
|
|
1598
|
+
}
|
|
1599
|
+
if (value < 0 || value > 127) {
|
|
1600
|
+
throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
|
|
1601
|
+
}
|
|
1602
|
+
return new Uint8Array([value | VERSION_FLAG_MASK]);
|
|
1603
|
+
}
|
|
1604
|
+
function getTransactionVersionCodec() {
|
|
1605
|
+
return {
|
|
1606
|
+
...BASE_CONFIG,
|
|
1607
|
+
deserialize,
|
|
1608
|
+
serialize
|
|
1609
|
+
};
|
|
1610
|
+
}
|
|
1611
|
+
var BASE_CONFIG2 = {
|
|
1612
|
+
description: "The wire format of a Solana transaction message" ,
|
|
1613
|
+
fixedSize: null,
|
|
1614
|
+
maxSize: null
|
|
1615
|
+
};
|
|
1616
|
+
function serialize2(compiledMessage) {
|
|
1617
|
+
if (compiledMessage.version === "legacy") {
|
|
1618
|
+
return struct(getPreludeStructSerializerTuple()).serialize(compiledMessage);
|
|
1619
|
+
} else {
|
|
1620
|
+
return mapSerializer(
|
|
1621
|
+
struct([
|
|
1622
|
+
...getPreludeStructSerializerTuple(),
|
|
1623
|
+
["addressTableLookups", getAddressTableLookupsSerializer()]
|
|
1624
|
+
]),
|
|
1625
|
+
(value) => {
|
|
1626
|
+
if (value.version === "legacy") {
|
|
1627
|
+
return value;
|
|
1628
|
+
}
|
|
1629
|
+
return {
|
|
1630
|
+
...value,
|
|
1631
|
+
addressTableLookups: value.addressTableLookups ?? []
|
|
1632
|
+
};
|
|
1633
|
+
}
|
|
1634
|
+
).serialize(compiledMessage);
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
function getPreludeStructSerializerTuple() {
|
|
1638
|
+
return [
|
|
1639
|
+
["version", getTransactionVersionCodec()],
|
|
1640
|
+
["header", getMessageHeaderCodec()],
|
|
1641
|
+
[
|
|
1642
|
+
"staticAccounts",
|
|
1643
|
+
array(getBase58EncodedAddressCodec(), {
|
|
1644
|
+
description: "A compact-array of static account addresses belonging to this transaction" ,
|
|
1645
|
+
size: shortU16()
|
|
1646
|
+
})
|
|
1647
|
+
],
|
|
1648
|
+
[
|
|
1649
|
+
"lifetimeToken",
|
|
1650
|
+
string({
|
|
1651
|
+
description: "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" ,
|
|
1652
|
+
encoding: base58,
|
|
1653
|
+
size: 32
|
|
1654
|
+
})
|
|
1655
|
+
],
|
|
1656
|
+
[
|
|
1657
|
+
"instructions",
|
|
1658
|
+
array(getInstructionCodec(), {
|
|
1659
|
+
description: "A compact-array of instructions belonging to this transaction" ,
|
|
1660
|
+
size: shortU16()
|
|
1661
|
+
})
|
|
1662
|
+
]
|
|
1663
|
+
];
|
|
1664
|
+
}
|
|
1665
|
+
function getAddressTableLookupsSerializer() {
|
|
1666
|
+
return array(getAddressTableLookupCodec(), {
|
|
1667
|
+
...{ description: "A compact array of address table lookups belonging to this transaction" } ,
|
|
1668
|
+
size: shortU16()
|
|
1669
|
+
});
|
|
1670
|
+
}
|
|
1671
|
+
function getCompiledMessageEncoder() {
|
|
1672
|
+
return {
|
|
1673
|
+
...BASE_CONFIG2,
|
|
1674
|
+
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
1675
|
+
serialize: serialize2
|
|
1676
|
+
};
|
|
1677
|
+
}
|
|
1678
|
+
function assertIsTransactionSignature(putativeTransactionSignature) {
|
|
1679
|
+
try {
|
|
1680
|
+
if (
|
|
1681
|
+
// Lowest value (64 bytes of zeroes)
|
|
1682
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
1683
|
+
putativeTransactionSignature.length > 88
|
|
1684
|
+
) {
|
|
1685
|
+
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
1686
|
+
}
|
|
1687
|
+
const bytes3 = base58.serialize(putativeTransactionSignature);
|
|
1688
|
+
const numBytes = bytes3.byteLength;
|
|
1689
|
+
if (numBytes !== 64) {
|
|
1690
|
+
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
1691
|
+
}
|
|
1692
|
+
} catch (e3) {
|
|
1693
|
+
throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
|
|
1694
|
+
cause: e3
|
|
1695
|
+
});
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
function isTransactionSignature(putativeTransactionSignature) {
|
|
1699
|
+
if (
|
|
1700
|
+
// Lowest value (64 bytes of zeroes)
|
|
1701
|
+
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
1702
|
+
putativeTransactionSignature.length > 88
|
|
1703
|
+
) {
|
|
1704
|
+
return false;
|
|
536
1705
|
}
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
throw new Error("No signature verification implementation could be found");
|
|
1706
|
+
const bytes3 = base58.serialize(putativeTransactionSignature);
|
|
1707
|
+
const numBytes = bytes3.byteLength;
|
|
1708
|
+
if (numBytes !== 64) {
|
|
1709
|
+
return false;
|
|
542
1710
|
}
|
|
1711
|
+
return true;
|
|
543
1712
|
}
|
|
544
|
-
async function
|
|
545
|
-
|
|
546
|
-
const
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
1713
|
+
async function getCompiledMessageSignature(message, secretKey) {
|
|
1714
|
+
const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
|
|
1715
|
+
const signature = await signBytes(secretKey, wireMessageBytes);
|
|
1716
|
+
return signature;
|
|
1717
|
+
}
|
|
1718
|
+
async function signTransaction(keyPairs, transaction) {
|
|
1719
|
+
const compiledMessage = compileMessage(transaction);
|
|
1720
|
+
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
1721
|
+
const publicKeySignaturePairs = await Promise.all(
|
|
1722
|
+
keyPairs.map(
|
|
1723
|
+
(keyPair) => Promise.all([
|
|
1724
|
+
getAddressFromPublicKey(keyPair.publicKey),
|
|
1725
|
+
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
1726
|
+
])
|
|
1727
|
+
)
|
|
555
1728
|
);
|
|
556
|
-
|
|
1729
|
+
for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
|
|
1730
|
+
nextSignatures[signerPublicKey] = signature;
|
|
1731
|
+
}
|
|
1732
|
+
const out = {
|
|
1733
|
+
...transaction,
|
|
1734
|
+
signatures: nextSignatures
|
|
1735
|
+
};
|
|
1736
|
+
Object.freeze(out);
|
|
1737
|
+
return out;
|
|
557
1738
|
}
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
1739
|
+
function transactionSignature(putativeTransactionSignature) {
|
|
1740
|
+
assertIsTransactionSignature(putativeTransactionSignature);
|
|
1741
|
+
return putativeTransactionSignature;
|
|
1742
|
+
}
|
|
1743
|
+
function getCompiledTransaction(transaction) {
|
|
1744
|
+
const compiledMessage = compileMessage(transaction);
|
|
1745
|
+
let signatures;
|
|
1746
|
+
if ("signatures" in transaction) {
|
|
1747
|
+
signatures = [];
|
|
1748
|
+
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
1749
|
+
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
1750
|
+
}
|
|
1751
|
+
} else {
|
|
1752
|
+
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
562
1753
|
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
1754
|
+
return {
|
|
1755
|
+
compiledMessage,
|
|
1756
|
+
signatures
|
|
1757
|
+
};
|
|
566
1758
|
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
1759
|
+
var BASE_CONFIG3 = {
|
|
1760
|
+
description: "The wire format of a Solana transaction" ,
|
|
1761
|
+
fixedSize: null,
|
|
1762
|
+
maxSize: null
|
|
1763
|
+
};
|
|
1764
|
+
function serialize3(transaction) {
|
|
1765
|
+
const compiledTransaction = getCompiledTransaction(transaction);
|
|
1766
|
+
return struct([
|
|
1767
|
+
[
|
|
1768
|
+
"signatures",
|
|
1769
|
+
array(bytes({ size: 64 }), {
|
|
1770
|
+
...{ description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } ,
|
|
1771
|
+
size: shortU16()
|
|
1772
|
+
})
|
|
1773
|
+
],
|
|
1774
|
+
["compiledMessage", getCompiledMessageEncoder()]
|
|
1775
|
+
]).serialize(compiledTransaction);
|
|
571
1776
|
}
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
1777
|
+
function getTransactionEncoder() {
|
|
1778
|
+
return {
|
|
1779
|
+
...BASE_CONFIG3,
|
|
1780
|
+
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
1781
|
+
serialize: serialize3
|
|
1782
|
+
};
|
|
1783
|
+
}
|
|
1784
|
+
function getBase64EncodedWireTransaction(transaction) {
|
|
1785
|
+
const wireTransactionBytes = getTransactionEncoder().serialize(transaction);
|
|
1786
|
+
{
|
|
1787
|
+
return btoa(String.fromCharCode(...wireTransactionBytes));
|
|
1788
|
+
}
|
|
575
1789
|
}
|
|
576
1790
|
|
|
577
1791
|
// src/rpc.ts
|
|
578
1792
|
init_env_shim();
|
|
579
1793
|
|
|
1794
|
+
// ../functional/dist/index.browser.js
|
|
1795
|
+
init_env_shim();
|
|
1796
|
+
function pipe(init, ...fns) {
|
|
1797
|
+
return fns.reduce((acc, fn) => fn(acc), init);
|
|
1798
|
+
}
|
|
1799
|
+
|
|
580
1800
|
// ../rpc-core/dist/index.browser.js
|
|
581
1801
|
init_env_shim();
|
|
582
1802
|
function visitNode(value, keyPath, onIntegerOverflow) {
|
|
@@ -605,85 +1825,234 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
605
1825
|
return visitNode(params, [], onIntegerOverflow);
|
|
606
1826
|
}
|
|
607
1827
|
var KEYPATH_WILDCARD = {};
|
|
608
|
-
var
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
1828
|
+
var jsonParsedTokenAccountsConfigs = [
|
|
1829
|
+
// parsed Token/Token22 token account
|
|
1830
|
+
["data", "parsed", "info", "tokenAmount", "decimals"],
|
|
1831
|
+
["data", "parsed", "info", "tokenAmount", "uiAmount"],
|
|
1832
|
+
["data", "parsed", "info", "rentExemptReserve", "decimals"],
|
|
1833
|
+
["data", "parsed", "info", "rentExemptReserve", "uiAmount"],
|
|
1834
|
+
["data", "parsed", "info", "delegatedAmount", "decimals"],
|
|
1835
|
+
["data", "parsed", "info", "delegatedAmount", "uiAmount"],
|
|
1836
|
+
["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "olderTransferFee", "transferFeeBasisPoints"],
|
|
1837
|
+
["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "newerTransferFee", "transferFeeBasisPoints"],
|
|
1838
|
+
["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "preUpdateAverageRate"],
|
|
1839
|
+
["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "currentRate"]
|
|
1840
|
+
];
|
|
1841
|
+
var jsonParsedAccountsConfigs = [
|
|
1842
|
+
...jsonParsedTokenAccountsConfigs,
|
|
1843
|
+
// parsed AddressTableLookup account
|
|
1844
|
+
["data", "parsed", "info", "lastExtendedSlotStartIndex"],
|
|
1845
|
+
// parsed Config account
|
|
1846
|
+
["data", "parsed", "info", "slashPenalty"],
|
|
1847
|
+
["data", "parsed", "info", "warmupCooldownRate"],
|
|
1848
|
+
// parsed Token/Token22 mint account
|
|
1849
|
+
["data", "parsed", "info", "decimals"],
|
|
1850
|
+
// parsed Token/Token22 multisig account
|
|
1851
|
+
["data", "parsed", "info", "numRequiredSigners"],
|
|
1852
|
+
["data", "parsed", "info", "numValidSigners"],
|
|
1853
|
+
// parsed Stake account
|
|
1854
|
+
["data", "parsed", "info", "stake", "delegation", "warmupCooldownRate"],
|
|
1855
|
+
// parsed Sysvar rent account
|
|
1856
|
+
["data", "parsed", "info", "exemptionThreshold"],
|
|
1857
|
+
["data", "parsed", "info", "burnPercent"],
|
|
1858
|
+
// parsed Vote account
|
|
1859
|
+
["data", "parsed", "info", "commission"],
|
|
1860
|
+
["data", "parsed", "info", "votes", KEYPATH_WILDCARD, "confirmationCount"]
|
|
1861
|
+
];
|
|
1862
|
+
var memoizedNotificationKeypaths;
|
|
1863
|
+
var memoizedResponseKeypaths;
|
|
1864
|
+
function getAllowedNumericKeypathsForNotification() {
|
|
1865
|
+
if (!memoizedNotificationKeypaths) {
|
|
1866
|
+
memoizedNotificationKeypaths = {
|
|
1867
|
+
accountNotifications: jsonParsedAccountsConfigs.map((c) => ["value", ...c]),
|
|
1868
|
+
programNotifications: jsonParsedAccountsConfigs.flatMap((c) => [
|
|
1869
|
+
["value", KEYPATH_WILDCARD, "account", ...c],
|
|
1870
|
+
[KEYPATH_WILDCARD, "account", ...c]
|
|
1871
|
+
])
|
|
1872
|
+
};
|
|
1873
|
+
}
|
|
1874
|
+
return memoizedNotificationKeypaths;
|
|
1875
|
+
}
|
|
1876
|
+
function getAllowedNumericKeypathsForResponse() {
|
|
1877
|
+
if (!memoizedResponseKeypaths) {
|
|
1878
|
+
memoizedResponseKeypaths = {
|
|
1879
|
+
getAccountInfo: jsonParsedAccountsConfigs.map((c) => ["value", ...c]),
|
|
1880
|
+
getBlock: [
|
|
1881
|
+
["blockTime"],
|
|
1882
|
+
["transactions", KEYPATH_WILDCARD, "meta", "preTokenBalances", KEYPATH_WILDCARD, "accountIndex"],
|
|
1883
|
+
[
|
|
1884
|
+
"transactions",
|
|
1885
|
+
KEYPATH_WILDCARD,
|
|
1886
|
+
"meta",
|
|
1887
|
+
"preTokenBalances",
|
|
1888
|
+
KEYPATH_WILDCARD,
|
|
1889
|
+
"uiTokenAmount",
|
|
1890
|
+
"decimals"
|
|
1891
|
+
],
|
|
1892
|
+
["transactions", KEYPATH_WILDCARD, "meta", "postTokenBalances", KEYPATH_WILDCARD, "accountIndex"],
|
|
1893
|
+
[
|
|
1894
|
+
"transactions",
|
|
1895
|
+
KEYPATH_WILDCARD,
|
|
1896
|
+
"meta",
|
|
1897
|
+
"postTokenBalances",
|
|
1898
|
+
KEYPATH_WILDCARD,
|
|
1899
|
+
"uiTokenAmount",
|
|
1900
|
+
"decimals"
|
|
1901
|
+
],
|
|
1902
|
+
["transactions", KEYPATH_WILDCARD, "meta", "rewards", KEYPATH_WILDCARD, "commission"],
|
|
1903
|
+
["transactions", KEYPATH_WILDCARD, "meta", "innerInstructions", KEYPATH_WILDCARD, "index"],
|
|
1904
|
+
[
|
|
1905
|
+
"transactions",
|
|
1906
|
+
KEYPATH_WILDCARD,
|
|
1907
|
+
"meta",
|
|
1908
|
+
"innerInstructions",
|
|
1909
|
+
KEYPATH_WILDCARD,
|
|
1910
|
+
"instructions",
|
|
1911
|
+
KEYPATH_WILDCARD,
|
|
1912
|
+
"programIdIndex"
|
|
1913
|
+
],
|
|
1914
|
+
[
|
|
1915
|
+
"transactions",
|
|
1916
|
+
KEYPATH_WILDCARD,
|
|
1917
|
+
"meta",
|
|
1918
|
+
"innerInstructions",
|
|
1919
|
+
KEYPATH_WILDCARD,
|
|
1920
|
+
"instructions",
|
|
1921
|
+
KEYPATH_WILDCARD,
|
|
1922
|
+
"accounts",
|
|
1923
|
+
KEYPATH_WILDCARD
|
|
1924
|
+
],
|
|
1925
|
+
[
|
|
1926
|
+
"transactions",
|
|
1927
|
+
KEYPATH_WILDCARD,
|
|
1928
|
+
"transaction",
|
|
1929
|
+
"message",
|
|
1930
|
+
"addressTableLookups",
|
|
1931
|
+
KEYPATH_WILDCARD,
|
|
1932
|
+
"writableIndexes",
|
|
1933
|
+
KEYPATH_WILDCARD
|
|
1934
|
+
],
|
|
1935
|
+
[
|
|
1936
|
+
"transactions",
|
|
1937
|
+
KEYPATH_WILDCARD,
|
|
1938
|
+
"transaction",
|
|
1939
|
+
"message",
|
|
1940
|
+
"addressTableLookups",
|
|
1941
|
+
KEYPATH_WILDCARD,
|
|
1942
|
+
"readonlyIndexes",
|
|
1943
|
+
KEYPATH_WILDCARD
|
|
1944
|
+
],
|
|
1945
|
+
[
|
|
1946
|
+
"transactions",
|
|
1947
|
+
KEYPATH_WILDCARD,
|
|
1948
|
+
"transaction",
|
|
1949
|
+
"message",
|
|
1950
|
+
"instructions",
|
|
1951
|
+
KEYPATH_WILDCARD,
|
|
1952
|
+
"programIdIndex"
|
|
1953
|
+
],
|
|
1954
|
+
[
|
|
1955
|
+
"transactions",
|
|
1956
|
+
KEYPATH_WILDCARD,
|
|
1957
|
+
"transaction",
|
|
1958
|
+
"message",
|
|
1959
|
+
"instructions",
|
|
1960
|
+
KEYPATH_WILDCARD,
|
|
1961
|
+
"accounts",
|
|
1962
|
+
KEYPATH_WILDCARD
|
|
1963
|
+
],
|
|
1964
|
+
["transactions", KEYPATH_WILDCARD, "transaction", "message", "header", "numReadonlySignedAccounts"],
|
|
1965
|
+
["transactions", KEYPATH_WILDCARD, "transaction", "message", "header", "numReadonlyUnsignedAccounts"],
|
|
1966
|
+
["transactions", KEYPATH_WILDCARD, "transaction", "message", "header", "numRequiredSignatures"],
|
|
1967
|
+
["rewards", KEYPATH_WILDCARD, "commission"]
|
|
1968
|
+
],
|
|
1969
|
+
getBlockTime: [[]],
|
|
1970
|
+
getClusterNodes: [
|
|
1971
|
+
[KEYPATH_WILDCARD, "featureSet"],
|
|
1972
|
+
[KEYPATH_WILDCARD, "shredVersion"]
|
|
1973
|
+
],
|
|
1974
|
+
getInflationGovernor: [["initial"], ["foundation"], ["foundationTerm"], ["taper"], ["terminal"]],
|
|
1975
|
+
getInflationRate: [["foundation"], ["total"], ["validator"]],
|
|
1976
|
+
getInflationReward: [[KEYPATH_WILDCARD, "commission"]],
|
|
1977
|
+
getMultipleAccounts: jsonParsedAccountsConfigs.map((c) => ["value", KEYPATH_WILDCARD, ...c]),
|
|
1978
|
+
getProgramAccounts: jsonParsedAccountsConfigs.flatMap((c) => [
|
|
1979
|
+
["value", KEYPATH_WILDCARD, "account", ...c],
|
|
1980
|
+
[KEYPATH_WILDCARD, "account", ...c]
|
|
1981
|
+
]),
|
|
1982
|
+
getRecentPerformanceSamples: [[KEYPATH_WILDCARD, "samplePeriodSecs"]],
|
|
1983
|
+
getTokenAccountBalance: [
|
|
1984
|
+
["value", "decimals"],
|
|
1985
|
+
["value", "uiAmount"]
|
|
1986
|
+
],
|
|
1987
|
+
getTokenAccountsByDelegate: jsonParsedTokenAccountsConfigs.map((c) => [
|
|
1988
|
+
"value",
|
|
1989
|
+
KEYPATH_WILDCARD,
|
|
1990
|
+
"account",
|
|
1991
|
+
...c
|
|
1992
|
+
]),
|
|
1993
|
+
getTokenAccountsByOwner: jsonParsedTokenAccountsConfigs.map((c) => [
|
|
1994
|
+
"value",
|
|
1995
|
+
KEYPATH_WILDCARD,
|
|
1996
|
+
"account",
|
|
1997
|
+
...c
|
|
1998
|
+
]),
|
|
1999
|
+
getTokenLargestAccounts: [
|
|
2000
|
+
["value", KEYPATH_WILDCARD, "decimals"],
|
|
2001
|
+
["value", KEYPATH_WILDCARD, "uiAmount"]
|
|
2002
|
+
],
|
|
2003
|
+
getTokenSupply: [
|
|
2004
|
+
["value", "decimals"],
|
|
2005
|
+
["value", "uiAmount"]
|
|
2006
|
+
],
|
|
2007
|
+
getTransaction: [
|
|
2008
|
+
["meta", "preTokenBalances", KEYPATH_WILDCARD, "accountIndex"],
|
|
2009
|
+
["meta", "preTokenBalances", KEYPATH_WILDCARD, "uiTokenAmount", "decimals"],
|
|
2010
|
+
["meta", "postTokenBalances", KEYPATH_WILDCARD, "accountIndex"],
|
|
2011
|
+
["meta", "postTokenBalances", KEYPATH_WILDCARD, "uiTokenAmount", "decimals"],
|
|
2012
|
+
["meta", "rewards", KEYPATH_WILDCARD, "commission"],
|
|
2013
|
+
["meta", "innerInstructions", KEYPATH_WILDCARD, "index"],
|
|
2014
|
+
["meta", "innerInstructions", KEYPATH_WILDCARD, "instructions", KEYPATH_WILDCARD, "programIdIndex"],
|
|
2015
|
+
[
|
|
2016
|
+
"meta",
|
|
2017
|
+
"innerInstructions",
|
|
2018
|
+
KEYPATH_WILDCARD,
|
|
2019
|
+
"instructions",
|
|
2020
|
+
KEYPATH_WILDCARD,
|
|
2021
|
+
"accounts",
|
|
2022
|
+
KEYPATH_WILDCARD
|
|
2023
|
+
],
|
|
2024
|
+
[
|
|
2025
|
+
"transaction",
|
|
2026
|
+
"message",
|
|
2027
|
+
"addressTableLookups",
|
|
2028
|
+
KEYPATH_WILDCARD,
|
|
2029
|
+
"writableIndexes",
|
|
2030
|
+
KEYPATH_WILDCARD
|
|
2031
|
+
],
|
|
2032
|
+
[
|
|
2033
|
+
"transaction",
|
|
2034
|
+
"message",
|
|
2035
|
+
"addressTableLookups",
|
|
2036
|
+
KEYPATH_WILDCARD,
|
|
2037
|
+
"readonlyIndexes",
|
|
2038
|
+
KEYPATH_WILDCARD
|
|
2039
|
+
],
|
|
2040
|
+
["transaction", "message", "instructions", KEYPATH_WILDCARD, "programIdIndex"],
|
|
2041
|
+
["transaction", "message", "instructions", KEYPATH_WILDCARD, "accounts", KEYPATH_WILDCARD],
|
|
2042
|
+
["transaction", "message", "header", "numReadonlySignedAccounts"],
|
|
2043
|
+
["transaction", "message", "header", "numReadonlyUnsignedAccounts"],
|
|
2044
|
+
["transaction", "message", "header", "numRequiredSignatures"]
|
|
2045
|
+
],
|
|
2046
|
+
getVersion: [["feature-set"]],
|
|
2047
|
+
getVoteAccounts: [
|
|
2048
|
+
["current", KEYPATH_WILDCARD, "commission"],
|
|
2049
|
+
["delinquent", KEYPATH_WILDCARD, "commission"]
|
|
2050
|
+
],
|
|
2051
|
+
simulateTransaction: jsonParsedAccountsConfigs.map((c) => ["value", "accounts", KEYPATH_WILDCARD, ...c])
|
|
2052
|
+
};
|
|
2053
|
+
}
|
|
2054
|
+
return memoizedResponseKeypaths;
|
|
2055
|
+
}
|
|
687
2056
|
function getNextAllowedKeypaths(keyPaths, property) {
|
|
688
2057
|
return keyPaths.filter((keyPath) => keyPath[0] === KEYPATH_WILDCARD && typeof property === "number" || keyPath[0] === property).map((keyPath) => keyPath.slice(1));
|
|
689
2058
|
}
|
|
@@ -710,7 +2079,11 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
710
2079
|
}
|
|
711
2080
|
}
|
|
712
2081
|
function patchResponseForSolanaLabsRpc(rawResponse, methodName) {
|
|
713
|
-
const allowedKeypaths = methodName ?
|
|
2082
|
+
const allowedKeypaths = methodName ? getAllowedNumericKeypathsForResponse()[methodName] : void 0;
|
|
2083
|
+
return visitNode2(rawResponse, allowedKeypaths ?? []);
|
|
2084
|
+
}
|
|
2085
|
+
function patchResponseForSolanaLabsRpcSubscriptions(rawResponse, methodName) {
|
|
2086
|
+
const allowedKeypaths = methodName ? getAllowedNumericKeypathsForNotification()[methodName] : void 0;
|
|
714
2087
|
return visitNode2(rawResponse, allowedKeypaths ?? []);
|
|
715
2088
|
}
|
|
716
2089
|
function createSolanaRpcApi(config) {
|
|
@@ -739,6 +2112,36 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
739
2112
|
}
|
|
740
2113
|
});
|
|
741
2114
|
}
|
|
2115
|
+
function createSolanaRpcSubscriptionsApi(config) {
|
|
2116
|
+
return new Proxy({}, {
|
|
2117
|
+
defineProperty() {
|
|
2118
|
+
return false;
|
|
2119
|
+
},
|
|
2120
|
+
deleteProperty() {
|
|
2121
|
+
return false;
|
|
2122
|
+
},
|
|
2123
|
+
get(...args) {
|
|
2124
|
+
const [_, p] = args;
|
|
2125
|
+
const notificationName = p.toString();
|
|
2126
|
+
return function(...rawParams) {
|
|
2127
|
+
const handleIntegerOverflow = config?.onIntegerOverflow;
|
|
2128
|
+
const params = patchParamsForSolanaLabsRpc(
|
|
2129
|
+
rawParams,
|
|
2130
|
+
handleIntegerOverflow ? (keyPath, value) => handleIntegerOverflow(notificationName, keyPath, value) : void 0
|
|
2131
|
+
);
|
|
2132
|
+
return {
|
|
2133
|
+
params,
|
|
2134
|
+
responseProcessor: (rawResponse) => patchResponseForSolanaLabsRpcSubscriptions(rawResponse, notificationName),
|
|
2135
|
+
subscribeMethodName: notificationName.replace(/Notifications$/, "Subscribe"),
|
|
2136
|
+
unsubscribeMethodName: notificationName.replace(/Notifications$/, "Unsubscribe")
|
|
2137
|
+
};
|
|
2138
|
+
};
|
|
2139
|
+
}
|
|
2140
|
+
});
|
|
2141
|
+
}
|
|
2142
|
+
function createSolanaRpcSubscriptionsApi_UNSTABLE(config) {
|
|
2143
|
+
return createSolanaRpcSubscriptionsApi(config);
|
|
2144
|
+
}
|
|
742
2145
|
|
|
743
2146
|
// ../rpc-transport/dist/index.browser.js
|
|
744
2147
|
init_env_shim();
|
|
@@ -805,6 +2208,100 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
805
2208
|
function createJsonRpc(rpcConfig) {
|
|
806
2209
|
return makeProxy(rpcConfig);
|
|
807
2210
|
}
|
|
2211
|
+
function registerIterableCleanup(iterable, cleanupFn) {
|
|
2212
|
+
(async () => {
|
|
2213
|
+
try {
|
|
2214
|
+
for await (const _ of iterable)
|
|
2215
|
+
;
|
|
2216
|
+
} catch {
|
|
2217
|
+
} finally {
|
|
2218
|
+
cleanupFn();
|
|
2219
|
+
}
|
|
2220
|
+
})();
|
|
2221
|
+
}
|
|
2222
|
+
function createPendingRpcSubscription(rpcConfig, { params, subscribeMethodName, unsubscribeMethodName, responseProcessor }) {
|
|
2223
|
+
return {
|
|
2224
|
+
async subscribe({ abortSignal }) {
|
|
2225
|
+
abortSignal.throwIfAborted();
|
|
2226
|
+
let subscriptionId;
|
|
2227
|
+
function handleCleanup() {
|
|
2228
|
+
if (subscriptionId !== void 0) {
|
|
2229
|
+
const payload = createJsonRpcMessage(unsubscribeMethodName, [subscriptionId]);
|
|
2230
|
+
connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload).finally(() => {
|
|
2231
|
+
connectionAbortController.abort();
|
|
2232
|
+
});
|
|
2233
|
+
} else {
|
|
2234
|
+
connectionAbortController.abort();
|
|
2235
|
+
}
|
|
2236
|
+
}
|
|
2237
|
+
abortSignal.addEventListener("abort", handleCleanup);
|
|
2238
|
+
const connectionAbortController = new AbortController();
|
|
2239
|
+
const subscribeMessage = createJsonRpcMessage(subscribeMethodName, params);
|
|
2240
|
+
const connection = await rpcConfig.transport({
|
|
2241
|
+
payload: subscribeMessage,
|
|
2242
|
+
signal: connectionAbortController.signal
|
|
2243
|
+
});
|
|
2244
|
+
function handleConnectionCleanup() {
|
|
2245
|
+
abortSignal.removeEventListener("abort", handleCleanup);
|
|
2246
|
+
}
|
|
2247
|
+
registerIterableCleanup(connection, handleConnectionCleanup);
|
|
2248
|
+
for await (const message of connection) {
|
|
2249
|
+
if ("id" in message && message.id === subscribeMessage.id) {
|
|
2250
|
+
if ("error" in message) {
|
|
2251
|
+
throw new SolanaJsonRpcError(message.error);
|
|
2252
|
+
} else {
|
|
2253
|
+
subscriptionId = message.result;
|
|
2254
|
+
break;
|
|
2255
|
+
}
|
|
2256
|
+
}
|
|
2257
|
+
}
|
|
2258
|
+
if (subscriptionId == null) {
|
|
2259
|
+
throw new Error("Failed to obtain a subscription id from the server");
|
|
2260
|
+
}
|
|
2261
|
+
return {
|
|
2262
|
+
async *[Symbol.asyncIterator]() {
|
|
2263
|
+
for await (const message of connection) {
|
|
2264
|
+
if (!("params" in message) || message.params.subscription !== subscriptionId) {
|
|
2265
|
+
continue;
|
|
2266
|
+
}
|
|
2267
|
+
const notification = message.params.result;
|
|
2268
|
+
yield responseProcessor ? responseProcessor(notification) : notification;
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
};
|
|
2272
|
+
}
|
|
2273
|
+
};
|
|
2274
|
+
}
|
|
2275
|
+
function makeProxy2(rpcConfig) {
|
|
2276
|
+
return new Proxy(rpcConfig.api, {
|
|
2277
|
+
defineProperty() {
|
|
2278
|
+
return false;
|
|
2279
|
+
},
|
|
2280
|
+
deleteProperty() {
|
|
2281
|
+
return false;
|
|
2282
|
+
},
|
|
2283
|
+
get(target, p, receiver) {
|
|
2284
|
+
return function(...rawParams) {
|
|
2285
|
+
const methodName = p.toString();
|
|
2286
|
+
const createRpcSubscription = Reflect.get(target, methodName, receiver);
|
|
2287
|
+
if (p.toString().endsWith("Notifications") === false && !createRpcSubscription) {
|
|
2288
|
+
throw new Error(
|
|
2289
|
+
"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."
|
|
2290
|
+
);
|
|
2291
|
+
}
|
|
2292
|
+
const newRequest = createRpcSubscription ? createRpcSubscription(...rawParams) : {
|
|
2293
|
+
params: rawParams,
|
|
2294
|
+
subscribeMethodName: methodName.replace(/Notifications$/, "Subscribe"),
|
|
2295
|
+
unsubscribeMethodName: methodName.replace(/Notifications$/, "Unsubscribe")
|
|
2296
|
+
};
|
|
2297
|
+
return createPendingRpcSubscription(rpcConfig, newRequest);
|
|
2298
|
+
};
|
|
2299
|
+
}
|
|
2300
|
+
});
|
|
2301
|
+
}
|
|
2302
|
+
function createJsonSubscriptionRpc(rpcConfig) {
|
|
2303
|
+
return makeProxy2(rpcConfig);
|
|
2304
|
+
}
|
|
808
2305
|
var e = globalThis.fetch;
|
|
809
2306
|
var SolanaHttpError = class extends Error {
|
|
810
2307
|
constructor(details) {
|
|
@@ -903,6 +2400,175 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
903
2400
|
return await response.json();
|
|
904
2401
|
};
|
|
905
2402
|
}
|
|
2403
|
+
var e2 = globalThis.WebSocket;
|
|
2404
|
+
var EXPLICIT_ABORT_TOKEN = Symbol(
|
|
2405
|
+
"This symbol is thrown from a socket's iterator when the connection is explicity aborted by the user"
|
|
2406
|
+
);
|
|
2407
|
+
async function createWebSocketConnection({
|
|
2408
|
+
sendBufferHighWatermark,
|
|
2409
|
+
signal,
|
|
2410
|
+
url
|
|
2411
|
+
}) {
|
|
2412
|
+
return new Promise((resolve, reject) => {
|
|
2413
|
+
signal.addEventListener("abort", handleAbort, { once: true });
|
|
2414
|
+
const iteratorState = /* @__PURE__ */ new Map();
|
|
2415
|
+
function errorAndClearAllIteratorStates(reason) {
|
|
2416
|
+
const errorCallbacks = [...iteratorState.values()].filter((state) => state.__hasPolled).map(({ onError }) => onError);
|
|
2417
|
+
iteratorState.clear();
|
|
2418
|
+
errorCallbacks.forEach((cb) => {
|
|
2419
|
+
try {
|
|
2420
|
+
cb(reason);
|
|
2421
|
+
} catch {
|
|
2422
|
+
}
|
|
2423
|
+
});
|
|
2424
|
+
}
|
|
2425
|
+
function handleAbort() {
|
|
2426
|
+
errorAndClearAllIteratorStates(EXPLICIT_ABORT_TOKEN);
|
|
2427
|
+
if (webSocket.readyState !== e2.CLOSED && webSocket.readyState !== e2.CLOSING) {
|
|
2428
|
+
webSocket.close(1e3);
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
function handleClose(ev) {
|
|
2432
|
+
bufferDrainWatcher?.onCancel();
|
|
2433
|
+
signal.removeEventListener("abort", handleAbort);
|
|
2434
|
+
webSocket.removeEventListener("close", handleClose);
|
|
2435
|
+
webSocket.removeEventListener("error", handleError);
|
|
2436
|
+
webSocket.removeEventListener("open", handleOpen);
|
|
2437
|
+
webSocket.removeEventListener("message", handleMessage);
|
|
2438
|
+
errorAndClearAllIteratorStates(ev);
|
|
2439
|
+
}
|
|
2440
|
+
function handleError(ev) {
|
|
2441
|
+
if (!hasConnected) {
|
|
2442
|
+
reject(
|
|
2443
|
+
// TODO: Coded error
|
|
2444
|
+
new Error("WebSocket failed to connect", { cause: ev })
|
|
2445
|
+
);
|
|
2446
|
+
}
|
|
2447
|
+
}
|
|
2448
|
+
let hasConnected = false;
|
|
2449
|
+
let bufferDrainWatcher;
|
|
2450
|
+
function handleOpen() {
|
|
2451
|
+
hasConnected = true;
|
|
2452
|
+
resolve({
|
|
2453
|
+
async send(payload) {
|
|
2454
|
+
const message = JSON.stringify(payload);
|
|
2455
|
+
if (!bufferDrainWatcher && webSocket.readyState === e2.OPEN && webSocket.bufferedAmount > sendBufferHighWatermark) {
|
|
2456
|
+
let onCancel;
|
|
2457
|
+
const promise = new Promise((resolve2, reject2) => {
|
|
2458
|
+
const intervalId = setInterval(() => {
|
|
2459
|
+
if (webSocket.readyState !== e2.OPEN || !(webSocket.bufferedAmount > sendBufferHighWatermark)) {
|
|
2460
|
+
clearInterval(intervalId);
|
|
2461
|
+
bufferDrainWatcher = void 0;
|
|
2462
|
+
resolve2();
|
|
2463
|
+
}
|
|
2464
|
+
}, 16);
|
|
2465
|
+
onCancel = () => {
|
|
2466
|
+
bufferDrainWatcher = void 0;
|
|
2467
|
+
clearInterval(intervalId);
|
|
2468
|
+
reject2(
|
|
2469
|
+
// TODO: Coded error
|
|
2470
|
+
new Error("WebSocket was closed before payload could be sent")
|
|
2471
|
+
);
|
|
2472
|
+
};
|
|
2473
|
+
});
|
|
2474
|
+
bufferDrainWatcher = {
|
|
2475
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2476
|
+
// @ts-ignore
|
|
2477
|
+
onCancel,
|
|
2478
|
+
promise
|
|
2479
|
+
};
|
|
2480
|
+
}
|
|
2481
|
+
if (bufferDrainWatcher) {
|
|
2482
|
+
await bufferDrainWatcher.promise;
|
|
2483
|
+
}
|
|
2484
|
+
webSocket.send(message);
|
|
2485
|
+
},
|
|
2486
|
+
async *[Symbol.asyncIterator]() {
|
|
2487
|
+
const iteratorKey = Symbol();
|
|
2488
|
+
iteratorState.set(iteratorKey, { __hasPolled: false, queuedMessages: [] });
|
|
2489
|
+
try {
|
|
2490
|
+
while (true) {
|
|
2491
|
+
const state = iteratorState.get(iteratorKey);
|
|
2492
|
+
if (!state) {
|
|
2493
|
+
throw new Error("Invariant: WebSocket message iterator is missing state storage");
|
|
2494
|
+
}
|
|
2495
|
+
if (state.__hasPolled) {
|
|
2496
|
+
throw new Error(
|
|
2497
|
+
"Invariant: WebSocket message iterator state is corrupt; iterated without first resolving existing message promise"
|
|
2498
|
+
);
|
|
2499
|
+
}
|
|
2500
|
+
const queuedMessages = state.queuedMessages;
|
|
2501
|
+
if (queuedMessages.length) {
|
|
2502
|
+
state.queuedMessages = [];
|
|
2503
|
+
yield* queuedMessages;
|
|
2504
|
+
} else {
|
|
2505
|
+
try {
|
|
2506
|
+
yield await new Promise((resolve2, reject2) => {
|
|
2507
|
+
iteratorState.set(iteratorKey, {
|
|
2508
|
+
__hasPolled: true,
|
|
2509
|
+
onError: reject2,
|
|
2510
|
+
onMessage: resolve2
|
|
2511
|
+
});
|
|
2512
|
+
});
|
|
2513
|
+
} catch (e3) {
|
|
2514
|
+
if (e3 === EXPLICIT_ABORT_TOKEN) {
|
|
2515
|
+
return;
|
|
2516
|
+
} else {
|
|
2517
|
+
throw new Error("WebSocket connection closed", { cause: e3 });
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
} finally {
|
|
2523
|
+
iteratorState.delete(iteratorKey);
|
|
2524
|
+
}
|
|
2525
|
+
}
|
|
2526
|
+
});
|
|
2527
|
+
}
|
|
2528
|
+
function handleMessage({ data }) {
|
|
2529
|
+
const message = JSON.parse(data);
|
|
2530
|
+
iteratorState.forEach((state, iteratorKey) => {
|
|
2531
|
+
if (state.__hasPolled) {
|
|
2532
|
+
const { onMessage } = state;
|
|
2533
|
+
iteratorState.set(iteratorKey, { __hasPolled: false, queuedMessages: [] });
|
|
2534
|
+
onMessage(message);
|
|
2535
|
+
} else {
|
|
2536
|
+
state.queuedMessages.push(message);
|
|
2537
|
+
}
|
|
2538
|
+
});
|
|
2539
|
+
}
|
|
2540
|
+
const webSocket = new e2(url);
|
|
2541
|
+
webSocket.addEventListener("close", handleClose);
|
|
2542
|
+
webSocket.addEventListener("error", handleError);
|
|
2543
|
+
webSocket.addEventListener("open", handleOpen);
|
|
2544
|
+
webSocket.addEventListener("message", handleMessage);
|
|
2545
|
+
});
|
|
2546
|
+
}
|
|
2547
|
+
function createWebSocketTransport({ sendBufferHighWatermark, url }) {
|
|
2548
|
+
if (/^wss?:/i.test(url) === false) {
|
|
2549
|
+
const protocolMatch = url.match(/^([^:]+):/);
|
|
2550
|
+
throw new DOMException(
|
|
2551
|
+
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.`
|
|
2552
|
+
);
|
|
2553
|
+
}
|
|
2554
|
+
return async function sendWebSocketMessage({ payload, signal }) {
|
|
2555
|
+
signal?.throwIfAborted();
|
|
2556
|
+
const connection = await createWebSocketConnection({
|
|
2557
|
+
sendBufferHighWatermark,
|
|
2558
|
+
signal,
|
|
2559
|
+
url
|
|
2560
|
+
});
|
|
2561
|
+
signal?.throwIfAborted();
|
|
2562
|
+
await connection.send(payload);
|
|
2563
|
+
return {
|
|
2564
|
+
[Symbol.asyncIterator]: connection[Symbol.asyncIterator].bind(connection),
|
|
2565
|
+
send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: connection.send.bind(connection)
|
|
2566
|
+
};
|
|
2567
|
+
};
|
|
2568
|
+
}
|
|
2569
|
+
|
|
2570
|
+
// src/rpc.ts
|
|
2571
|
+
var import_fast_stable_stringify = __toESM(require_fast_stable_stringify(), 1);
|
|
906
2572
|
|
|
907
2573
|
// src/rpc-default-config.ts
|
|
908
2574
|
init_env_shim();
|
|
@@ -944,6 +2610,197 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
944
2610
|
}
|
|
945
2611
|
};
|
|
946
2612
|
|
|
2613
|
+
// src/rpc-subscription-coalescer.ts
|
|
2614
|
+
init_env_shim();
|
|
2615
|
+
|
|
2616
|
+
// src/cached-abortable-iterable.ts
|
|
2617
|
+
init_env_shim();
|
|
2618
|
+
function registerIterableCleanup2(iterable, cleanupFn) {
|
|
2619
|
+
(async () => {
|
|
2620
|
+
try {
|
|
2621
|
+
for await (const _ of iterable)
|
|
2622
|
+
;
|
|
2623
|
+
} catch {
|
|
2624
|
+
} finally {
|
|
2625
|
+
cleanupFn();
|
|
2626
|
+
}
|
|
2627
|
+
})();
|
|
2628
|
+
}
|
|
2629
|
+
function getCachedAbortableIterableFactory({
|
|
2630
|
+
getAbortSignalFromInputArgs,
|
|
2631
|
+
getCacheEntryMissingError,
|
|
2632
|
+
getCacheKeyFromInputArgs,
|
|
2633
|
+
onCacheHit,
|
|
2634
|
+
onCreateIterable
|
|
2635
|
+
}) {
|
|
2636
|
+
const cache = /* @__PURE__ */ new Map();
|
|
2637
|
+
function getCacheEntryOrThrow(cacheKey) {
|
|
2638
|
+
const currentCacheEntry = cache.get(cacheKey);
|
|
2639
|
+
if (!currentCacheEntry) {
|
|
2640
|
+
throw getCacheEntryMissingError(cacheKey);
|
|
2641
|
+
}
|
|
2642
|
+
return currentCacheEntry;
|
|
2643
|
+
}
|
|
2644
|
+
return async (...args) => {
|
|
2645
|
+
const cacheKey = getCacheKeyFromInputArgs(...args);
|
|
2646
|
+
const signal = getAbortSignalFromInputArgs(...args);
|
|
2647
|
+
if (cacheKey === void 0) {
|
|
2648
|
+
return await onCreateIterable(signal, ...args);
|
|
2649
|
+
}
|
|
2650
|
+
const cleanup = () => {
|
|
2651
|
+
cache.delete(cacheKey);
|
|
2652
|
+
signal.removeEventListener("abort", handleAbort);
|
|
2653
|
+
};
|
|
2654
|
+
const handleAbort = () => {
|
|
2655
|
+
const cacheEntry = getCacheEntryOrThrow(cacheKey);
|
|
2656
|
+
if (cacheEntry.purgeScheduled !== true) {
|
|
2657
|
+
cacheEntry.purgeScheduled = true;
|
|
2658
|
+
globalThis.queueMicrotask(() => {
|
|
2659
|
+
cacheEntry.purgeScheduled = false;
|
|
2660
|
+
if (cacheEntry.referenceCount === 0) {
|
|
2661
|
+
cacheEntry.abortController.abort();
|
|
2662
|
+
cleanup();
|
|
2663
|
+
}
|
|
2664
|
+
});
|
|
2665
|
+
}
|
|
2666
|
+
cacheEntry.referenceCount--;
|
|
2667
|
+
};
|
|
2668
|
+
signal.addEventListener("abort", handleAbort);
|
|
2669
|
+
try {
|
|
2670
|
+
const cacheEntry = cache.get(cacheKey);
|
|
2671
|
+
if (!cacheEntry) {
|
|
2672
|
+
const singletonAbortController = new AbortController();
|
|
2673
|
+
const newIterablePromise = onCreateIterable(singletonAbortController.signal, ...args);
|
|
2674
|
+
const newCacheEntry = {
|
|
2675
|
+
abortController: singletonAbortController,
|
|
2676
|
+
iterable: newIterablePromise,
|
|
2677
|
+
purgeScheduled: false,
|
|
2678
|
+
referenceCount: 1
|
|
2679
|
+
};
|
|
2680
|
+
cache.set(cacheKey, newCacheEntry);
|
|
2681
|
+
const newIterable = await newIterablePromise;
|
|
2682
|
+
registerIterableCleanup2(newIterable, cleanup);
|
|
2683
|
+
newCacheEntry.iterable = newIterable;
|
|
2684
|
+
return newIterable;
|
|
2685
|
+
} else {
|
|
2686
|
+
cacheEntry.referenceCount++;
|
|
2687
|
+
const iterableOrIterablePromise = cacheEntry.iterable;
|
|
2688
|
+
const cachedIterable = "then" in iterableOrIterablePromise ? await iterableOrIterablePromise : iterableOrIterablePromise;
|
|
2689
|
+
await onCacheHit(cachedIterable, ...args);
|
|
2690
|
+
return cachedIterable;
|
|
2691
|
+
}
|
|
2692
|
+
} catch (e3) {
|
|
2693
|
+
cleanup();
|
|
2694
|
+
throw e3;
|
|
2695
|
+
}
|
|
2696
|
+
};
|
|
2697
|
+
}
|
|
2698
|
+
|
|
2699
|
+
// src/rpc-subscription-coalescer.ts
|
|
2700
|
+
var EXPLICIT_ABORT_TOKEN2 = Symbol(
|
|
2701
|
+
"This symbol is thrown from a subscription's iterator when the subscription is explicitly aborted by the user"
|
|
2702
|
+
);
|
|
2703
|
+
function registerIterableCleanup3(iterable, cleanupFn) {
|
|
2704
|
+
(async () => {
|
|
2705
|
+
try {
|
|
2706
|
+
for await (const _ of iterable)
|
|
2707
|
+
;
|
|
2708
|
+
} catch {
|
|
2709
|
+
} finally {
|
|
2710
|
+
cleanupFn();
|
|
2711
|
+
}
|
|
2712
|
+
})();
|
|
2713
|
+
}
|
|
2714
|
+
function getRpcSubscriptionsWithSubscriptionCoalescing({
|
|
2715
|
+
getDeduplicationKey,
|
|
2716
|
+
rpcSubscriptions
|
|
2717
|
+
}) {
|
|
2718
|
+
const cache = /* @__PURE__ */ new Map();
|
|
2719
|
+
return new Proxy(rpcSubscriptions, {
|
|
2720
|
+
defineProperty() {
|
|
2721
|
+
return false;
|
|
2722
|
+
},
|
|
2723
|
+
deleteProperty() {
|
|
2724
|
+
return false;
|
|
2725
|
+
},
|
|
2726
|
+
get(target, p, receiver) {
|
|
2727
|
+
const subscriptionMethod = Reflect.get(target, p, receiver);
|
|
2728
|
+
if (typeof subscriptionMethod !== "function") {
|
|
2729
|
+
return subscriptionMethod;
|
|
2730
|
+
}
|
|
2731
|
+
return function(...rawParams) {
|
|
2732
|
+
const deduplicationKey = getDeduplicationKey(p, rawParams);
|
|
2733
|
+
if (deduplicationKey === void 0) {
|
|
2734
|
+
return subscriptionMethod(...rawParams);
|
|
2735
|
+
}
|
|
2736
|
+
if (cache.has(deduplicationKey)) {
|
|
2737
|
+
return cache.get(deduplicationKey);
|
|
2738
|
+
}
|
|
2739
|
+
const iterableFactory = getCachedAbortableIterableFactory({
|
|
2740
|
+
getAbortSignalFromInputArgs: ({ abortSignal }) => abortSignal,
|
|
2741
|
+
getCacheEntryMissingError(deduplicationKey2) {
|
|
2742
|
+
return new Error(
|
|
2743
|
+
`Found no cache entry for subscription with deduplication key \`${deduplicationKey2?.toString()}\``
|
|
2744
|
+
);
|
|
2745
|
+
},
|
|
2746
|
+
getCacheKeyFromInputArgs: () => deduplicationKey,
|
|
2747
|
+
async onCacheHit(_iterable, _config) {
|
|
2748
|
+
},
|
|
2749
|
+
async onCreateIterable(abortSignal, config) {
|
|
2750
|
+
const pendingSubscription2 = subscriptionMethod(
|
|
2751
|
+
...rawParams
|
|
2752
|
+
);
|
|
2753
|
+
const iterable = await pendingSubscription2.subscribe({
|
|
2754
|
+
...config,
|
|
2755
|
+
abortSignal
|
|
2756
|
+
});
|
|
2757
|
+
registerIterableCleanup3(iterable, () => {
|
|
2758
|
+
cache.delete(deduplicationKey);
|
|
2759
|
+
});
|
|
2760
|
+
return iterable;
|
|
2761
|
+
}
|
|
2762
|
+
});
|
|
2763
|
+
const pendingSubscription = {
|
|
2764
|
+
async subscribe(...args) {
|
|
2765
|
+
const iterable = await iterableFactory(...args);
|
|
2766
|
+
const { abortSignal } = args[0];
|
|
2767
|
+
let abortPromise;
|
|
2768
|
+
return {
|
|
2769
|
+
...iterable,
|
|
2770
|
+
async *[Symbol.asyncIterator]() {
|
|
2771
|
+
abortPromise || (abortPromise = abortSignal.aborted ? Promise.reject(EXPLICIT_ABORT_TOKEN2) : new Promise((_, reject) => {
|
|
2772
|
+
abortSignal.addEventListener("abort", () => {
|
|
2773
|
+
reject(EXPLICIT_ABORT_TOKEN2);
|
|
2774
|
+
});
|
|
2775
|
+
}));
|
|
2776
|
+
try {
|
|
2777
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
2778
|
+
while (true) {
|
|
2779
|
+
const iteratorResult = await Promise.race([iterator.next(), abortPromise]);
|
|
2780
|
+
if (iteratorResult.done) {
|
|
2781
|
+
return;
|
|
2782
|
+
} else {
|
|
2783
|
+
yield iteratorResult.value;
|
|
2784
|
+
}
|
|
2785
|
+
}
|
|
2786
|
+
} catch (e3) {
|
|
2787
|
+
if (e3 === EXPLICIT_ABORT_TOKEN2) {
|
|
2788
|
+
return;
|
|
2789
|
+
}
|
|
2790
|
+
cache.delete(deduplicationKey);
|
|
2791
|
+
throw e3;
|
|
2792
|
+
}
|
|
2793
|
+
}
|
|
2794
|
+
};
|
|
2795
|
+
}
|
|
2796
|
+
};
|
|
2797
|
+
cache.set(deduplicationKey, pendingSubscription);
|
|
2798
|
+
return pendingSubscription;
|
|
2799
|
+
};
|
|
2800
|
+
}
|
|
2801
|
+
});
|
|
2802
|
+
}
|
|
2803
|
+
|
|
947
2804
|
// src/rpc.ts
|
|
948
2805
|
function createSolanaRpc(config) {
|
|
949
2806
|
return createJsonRpc({
|
|
@@ -951,6 +2808,24 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
951
2808
|
api: createSolanaRpcApi(DEFAULT_RPC_CONFIG)
|
|
952
2809
|
});
|
|
953
2810
|
}
|
|
2811
|
+
function createSolanaRpcSubscriptions(config) {
|
|
2812
|
+
return pipe(
|
|
2813
|
+
createJsonSubscriptionRpc({
|
|
2814
|
+
...config,
|
|
2815
|
+
api: createSolanaRpcSubscriptionsApi(DEFAULT_RPC_CONFIG)
|
|
2816
|
+
}),
|
|
2817
|
+
(rpcSubscriptions) => getRpcSubscriptionsWithSubscriptionCoalescing({
|
|
2818
|
+
getDeduplicationKey: (...args) => (0, import_fast_stable_stringify.default)(args),
|
|
2819
|
+
rpcSubscriptions
|
|
2820
|
+
})
|
|
2821
|
+
);
|
|
2822
|
+
}
|
|
2823
|
+
function createSolanaRpcSubscriptions_UNSTABLE(config) {
|
|
2824
|
+
return createJsonSubscriptionRpc({
|
|
2825
|
+
...config,
|
|
2826
|
+
api: createSolanaRpcSubscriptionsApi_UNSTABLE(DEFAULT_RPC_CONFIG)
|
|
2827
|
+
});
|
|
2828
|
+
}
|
|
954
2829
|
|
|
955
2830
|
// src/rpc-transport.ts
|
|
956
2831
|
init_env_shim();
|
|
@@ -987,14 +2862,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
987
2862
|
if (signal) {
|
|
988
2863
|
const responsePromise = coalescedRequest.responsePromise;
|
|
989
2864
|
return await new Promise((resolve, reject) => {
|
|
990
|
-
const handleAbort = (
|
|
2865
|
+
const handleAbort = (e3) => {
|
|
991
2866
|
signal.removeEventListener("abort", handleAbort);
|
|
992
2867
|
coalescedRequest.numConsumers -= 1;
|
|
993
2868
|
if (coalescedRequest.numConsumers === 0) {
|
|
994
2869
|
const abortController = coalescedRequest.abortController;
|
|
995
2870
|
abortController.abort();
|
|
996
2871
|
}
|
|
997
|
-
const abortError = new DOMException(
|
|
2872
|
+
const abortError = new DOMException(e3.target.reason, "AbortError");
|
|
998
2873
|
reject(abortError);
|
|
999
2874
|
};
|
|
1000
2875
|
signal.addEventListener("abort", handleAbort);
|
|
@@ -1010,14 +2885,15 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1010
2885
|
|
|
1011
2886
|
// src/rpc-request-deduplication.ts
|
|
1012
2887
|
init_env_shim();
|
|
1013
|
-
var
|
|
1014
|
-
function
|
|
2888
|
+
var import_fast_stable_stringify2 = __toESM(require_fast_stable_stringify(), 1);
|
|
2889
|
+
function isJsonRpcPayload(payload) {
|
|
1015
2890
|
if (payload == null || typeof payload !== "object" || Array.isArray(payload)) {
|
|
1016
|
-
return;
|
|
1017
|
-
}
|
|
1018
|
-
if ("jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && "params" in payload) {
|
|
1019
|
-
return (0, import_fast_stable_stringify.default)([payload.method, payload.params]);
|
|
2891
|
+
return false;
|
|
1020
2892
|
}
|
|
2893
|
+
return "jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && typeof payload.method === "string" && "params" in payload;
|
|
2894
|
+
}
|
|
2895
|
+
function getSolanaRpcPayloadDeduplicationKey(payload) {
|
|
2896
|
+
return isJsonRpcPayload(payload) ? (0, import_fast_stable_stringify2.default)([payload.method, payload.params]) : void 0;
|
|
1021
2897
|
}
|
|
1022
2898
|
|
|
1023
2899
|
// src/rpc-transport.ts
|
|
@@ -1029,7 +2905,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1029
2905
|
return out;
|
|
1030
2906
|
}
|
|
1031
2907
|
function createDefaultRpcTransport(config) {
|
|
1032
|
-
return
|
|
2908
|
+
return pipe(
|
|
1033
2909
|
createHttpTransport({
|
|
1034
2910
|
...config,
|
|
1035
2911
|
headers: {
|
|
@@ -1040,24 +2916,151 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1040
2916
|
}
|
|
1041
2917
|
}
|
|
1042
2918
|
}),
|
|
1043
|
-
getSolanaRpcPayloadDeduplicationKey
|
|
2919
|
+
(transport) => getRpcTransportWithRequestCoalescing(transport, getSolanaRpcPayloadDeduplicationKey)
|
|
2920
|
+
);
|
|
2921
|
+
}
|
|
2922
|
+
|
|
2923
|
+
// src/rpc-websocket-transport.ts
|
|
2924
|
+
init_env_shim();
|
|
2925
|
+
|
|
2926
|
+
// src/rpc-websocket-autopinger.ts
|
|
2927
|
+
init_env_shim();
|
|
2928
|
+
var PING_PAYLOAD = {
|
|
2929
|
+
jsonrpc: "2.0",
|
|
2930
|
+
method: "ping"
|
|
2931
|
+
};
|
|
2932
|
+
function getWebSocketTransportWithAutoping({ intervalMs, transport }) {
|
|
2933
|
+
const pingableConnections = /* @__PURE__ */ new Map();
|
|
2934
|
+
return async (...args) => {
|
|
2935
|
+
const connection = await transport(...args);
|
|
2936
|
+
let intervalId;
|
|
2937
|
+
function sendPing() {
|
|
2938
|
+
connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(PING_PAYLOAD);
|
|
2939
|
+
}
|
|
2940
|
+
function restartPingTimer() {
|
|
2941
|
+
clearInterval(intervalId);
|
|
2942
|
+
intervalId = setInterval(sendPing, intervalMs);
|
|
2943
|
+
}
|
|
2944
|
+
if (pingableConnections.has(connection) === false) {
|
|
2945
|
+
pingableConnections.set(connection, {
|
|
2946
|
+
[Symbol.asyncIterator]: connection[Symbol.asyncIterator].bind(connection),
|
|
2947
|
+
send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: (...args2) => {
|
|
2948
|
+
restartPingTimer();
|
|
2949
|
+
return connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(...args2);
|
|
2950
|
+
}
|
|
2951
|
+
});
|
|
2952
|
+
(async () => {
|
|
2953
|
+
try {
|
|
2954
|
+
for await (const _ of connection) {
|
|
2955
|
+
restartPingTimer();
|
|
2956
|
+
}
|
|
2957
|
+
} catch {
|
|
2958
|
+
} finally {
|
|
2959
|
+
pingableConnections.delete(connection);
|
|
2960
|
+
clearInterval(intervalId);
|
|
2961
|
+
if (handleOffline) {
|
|
2962
|
+
globalThis.window.removeEventListener("offline", handleOffline);
|
|
2963
|
+
}
|
|
2964
|
+
if (handleOnline) {
|
|
2965
|
+
globalThis.window.removeEventListener("online", handleOnline);
|
|
2966
|
+
}
|
|
2967
|
+
}
|
|
2968
|
+
})();
|
|
2969
|
+
if (globalThis.navigator.onLine) {
|
|
2970
|
+
restartPingTimer();
|
|
2971
|
+
}
|
|
2972
|
+
let handleOffline;
|
|
2973
|
+
let handleOnline;
|
|
2974
|
+
{
|
|
2975
|
+
handleOffline = () => {
|
|
2976
|
+
clearInterval(intervalId);
|
|
2977
|
+
};
|
|
2978
|
+
handleOnline = () => {
|
|
2979
|
+
sendPing();
|
|
2980
|
+
restartPingTimer();
|
|
2981
|
+
};
|
|
2982
|
+
globalThis.window.addEventListener("offline", handleOffline);
|
|
2983
|
+
globalThis.window.addEventListener("online", handleOnline);
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2986
|
+
return pingableConnections.get(connection);
|
|
2987
|
+
};
|
|
2988
|
+
}
|
|
2989
|
+
|
|
2990
|
+
// src/rpc-websocket-connection-sharding.ts
|
|
2991
|
+
init_env_shim();
|
|
2992
|
+
var NULL_SHARD_CACHE_KEY = Symbol(
|
|
2993
|
+
"Cache key to use when there is no connection sharding strategy"
|
|
2994
|
+
);
|
|
2995
|
+
function getWebSocketTransportWithConnectionSharding({ getShard, transport }) {
|
|
2996
|
+
return getCachedAbortableIterableFactory({
|
|
2997
|
+
getAbortSignalFromInputArgs: ({ signal }) => signal,
|
|
2998
|
+
getCacheEntryMissingError(shardKey) {
|
|
2999
|
+
return new Error(`Found no cache entry for connection with shard key \`${shardKey?.toString()}\``);
|
|
3000
|
+
},
|
|
3001
|
+
getCacheKeyFromInputArgs: ({ payload }) => getShard ? getShard(payload) : NULL_SHARD_CACHE_KEY,
|
|
3002
|
+
onCacheHit: (connection, { payload }) => connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload),
|
|
3003
|
+
onCreateIterable: (abortSignal, config) => transport({
|
|
3004
|
+
...config,
|
|
3005
|
+
signal: abortSignal
|
|
3006
|
+
})
|
|
3007
|
+
});
|
|
3008
|
+
}
|
|
3009
|
+
|
|
3010
|
+
// src/rpc-websocket-transport.ts
|
|
3011
|
+
function createDefaultRpcSubscriptionsTransport(config) {
|
|
3012
|
+
const { getShard, intervalMs, ...rest } = config;
|
|
3013
|
+
return pipe(
|
|
3014
|
+
createWebSocketTransport({
|
|
3015
|
+
...rest,
|
|
3016
|
+
sendBufferHighWatermark: config.sendBufferHighWatermark ?? // Let 128KB of data into the WebSocket buffer before buffering it in the app.
|
|
3017
|
+
131072
|
|
3018
|
+
}),
|
|
3019
|
+
(transport) => getWebSocketTransportWithAutoping({
|
|
3020
|
+
intervalMs: intervalMs ?? 5e3,
|
|
3021
|
+
transport
|
|
3022
|
+
}),
|
|
3023
|
+
(transport) => getWebSocketTransportWithConnectionSharding({
|
|
3024
|
+
getShard,
|
|
3025
|
+
transport
|
|
3026
|
+
})
|
|
1044
3027
|
);
|
|
1045
3028
|
}
|
|
1046
3029
|
|
|
1047
3030
|
exports.AccountRole = AccountRole;
|
|
3031
|
+
exports.address = address;
|
|
3032
|
+
exports.appendTransactionInstruction = appendTransactionInstruction;
|
|
1048
3033
|
exports.assertIsBase58EncodedAddress = assertIsBase58EncodedAddress;
|
|
3034
|
+
exports.assertIsBlockhash = assertIsBlockhash;
|
|
3035
|
+
exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
|
|
3036
|
+
exports.assertIsTransactionSignature = assertIsTransactionSignature;
|
|
3037
|
+
exports.createAddressWithSeed = createAddressWithSeed;
|
|
3038
|
+
exports.createDefaultRpcSubscriptionsTransport = createDefaultRpcSubscriptionsTransport;
|
|
1049
3039
|
exports.createDefaultRpcTransport = createDefaultRpcTransport;
|
|
1050
3040
|
exports.createSolanaRpc = createSolanaRpc;
|
|
3041
|
+
exports.createSolanaRpcSubscriptions = createSolanaRpcSubscriptions;
|
|
3042
|
+
exports.createSolanaRpcSubscriptions_UNSTABLE = createSolanaRpcSubscriptions_UNSTABLE;
|
|
3043
|
+
exports.createTransaction = createTransaction;
|
|
1051
3044
|
exports.downgradeRoleToNonSigner = downgradeRoleToNonSigner;
|
|
1052
3045
|
exports.downgradeRoleToReadonly = downgradeRoleToReadonly;
|
|
1053
3046
|
exports.generateKeyPair = generateKeyPair;
|
|
3047
|
+
exports.getAddressFromPublicKey = getAddressFromPublicKey;
|
|
1054
3048
|
exports.getBase58EncodedAddressCodec = getBase58EncodedAddressCodec;
|
|
1055
3049
|
exports.getBase58EncodedAddressComparator = getBase58EncodedAddressComparator;
|
|
1056
|
-
exports.
|
|
3050
|
+
exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
|
|
3051
|
+
exports.getProgramDerivedAddress = getProgramDerivedAddress;
|
|
3052
|
+
exports.isBase58EncodedAddress = isBase58EncodedAddress;
|
|
1057
3053
|
exports.isSignerRole = isSignerRole;
|
|
3054
|
+
exports.isTransactionSignature = isTransactionSignature;
|
|
1058
3055
|
exports.isWritableRole = isWritableRole;
|
|
1059
3056
|
exports.mergeRoles = mergeRoles;
|
|
3057
|
+
exports.prependTransactionInstruction = prependTransactionInstruction;
|
|
3058
|
+
exports.setTransactionFeePayer = setTransactionFeePayer;
|
|
3059
|
+
exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
|
|
3060
|
+
exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
|
|
1060
3061
|
exports.signBytes = signBytes;
|
|
3062
|
+
exports.signTransaction = signTransaction;
|
|
3063
|
+
exports.transactionSignature = transactionSignature;
|
|
1061
3064
|
exports.upgradeRoleToSigner = upgradeRoleToSigner;
|
|
1062
3065
|
exports.upgradeRoleToWritable = upgradeRoleToWritable;
|
|
1063
3066
|
exports.verifySignature = verifySignature;
|