@solana/web3.js 2.0.0-experimental.b0e1171 → 2.0.0-experimental.b463a7a
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 +106 -1
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +88 -5
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +2267 -221
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +77 -3
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +95 -3
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +77 -3
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +36 -5
- package/dist/types/index.d.ts +4 -0
- package/dist/types/rpc-websocket-autopinger.d.ts +8 -0
- package/dist/types/rpc-websocket-transport.d.ts +7 -0
- package/dist/types/rpc.d.ts +4 -3
- package/package.json +20 -20
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/rpc-default-config.d.ts.map +0 -1
- package/dist/types/rpc-integer-overflow-error.d.ts.map +0 -1
- package/dist/types/rpc-request-coalescer.d.ts.map +0 -1
- package/dist/types/rpc-request-deduplication.d.ts.map +0 -1
- package/dist/types/rpc-transport.d.ts.map +0 -1
- package/dist/types/rpc.d.ts.map +0 -1
|
@@ -8,11 +8,12 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
8
8
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
9
9
|
var __getProtoOf = Object.getPrototypeOf;
|
|
10
10
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
12
|
var __esm = (fn, res) => function __init() {
|
|
12
13
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
13
14
|
};
|
|
14
|
-
var __commonJS = (cb,
|
|
15
|
-
return
|
|
15
|
+
var __commonJS = (cb, mod2) => function __require() {
|
|
16
|
+
return mod2 || (0, cb[__getOwnPropNames(cb)[0]])((mod2 = { exports: {} }).exports, mod2), mod2.exports;
|
|
16
17
|
};
|
|
17
18
|
var __copyProps = (to, from, except, desc) => {
|
|
18
19
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -22,14 +23,18 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
22
23
|
}
|
|
23
24
|
return to;
|
|
24
25
|
};
|
|
25
|
-
var __toESM = (
|
|
26
|
+
var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__getProtoOf(mod2)) : {}, __copyProps(
|
|
26
27
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
27
28
|
// file that has been converted to a CommonJS file using a Babel-
|
|
28
29
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
29
30
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
30
|
-
isNodeMode || !
|
|
31
|
-
|
|
31
|
+
isNodeMode || !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
|
|
32
|
+
mod2
|
|
32
33
|
));
|
|
34
|
+
var __publicField = (obj, key, value) => {
|
|
35
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
36
|
+
return value;
|
|
37
|
+
};
|
|
33
38
|
|
|
34
39
|
// ../build-scripts/env-shim.ts
|
|
35
40
|
var init_env_shim = __esm({
|
|
@@ -37,147 +42,6 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
37
42
|
}
|
|
38
43
|
});
|
|
39
44
|
|
|
40
|
-
// ../../node_modules/.pnpm/base-x@4.0.0/node_modules/base-x/src/index.js
|
|
41
|
-
var require_src = __commonJS({
|
|
42
|
-
"../../node_modules/.pnpm/base-x@4.0.0/node_modules/base-x/src/index.js"(exports, module) {
|
|
43
|
-
init_env_shim();
|
|
44
|
-
function base(ALPHABET) {
|
|
45
|
-
if (ALPHABET.length >= 255) {
|
|
46
|
-
throw new TypeError("Alphabet too long");
|
|
47
|
-
}
|
|
48
|
-
var BASE_MAP = new Uint8Array(256);
|
|
49
|
-
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
50
|
-
BASE_MAP[j] = 255;
|
|
51
|
-
}
|
|
52
|
-
for (var i = 0; i < ALPHABET.length; i++) {
|
|
53
|
-
var x = ALPHABET.charAt(i);
|
|
54
|
-
var xc = x.charCodeAt(0);
|
|
55
|
-
if (BASE_MAP[xc] !== 255) {
|
|
56
|
-
throw new TypeError(x + " is ambiguous");
|
|
57
|
-
}
|
|
58
|
-
BASE_MAP[xc] = i;
|
|
59
|
-
}
|
|
60
|
-
var BASE = ALPHABET.length;
|
|
61
|
-
var LEADER = ALPHABET.charAt(0);
|
|
62
|
-
var FACTOR = Math.log(BASE) / Math.log(256);
|
|
63
|
-
var iFACTOR = Math.log(256) / Math.log(BASE);
|
|
64
|
-
function encode(source) {
|
|
65
|
-
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
66
|
-
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
67
|
-
} else if (Array.isArray(source)) {
|
|
68
|
-
source = Uint8Array.from(source);
|
|
69
|
-
}
|
|
70
|
-
if (!(source instanceof Uint8Array)) {
|
|
71
|
-
throw new TypeError("Expected Uint8Array");
|
|
72
|
-
}
|
|
73
|
-
if (source.length === 0) {
|
|
74
|
-
return "";
|
|
75
|
-
}
|
|
76
|
-
var zeroes = 0;
|
|
77
|
-
var length = 0;
|
|
78
|
-
var pbegin = 0;
|
|
79
|
-
var pend = source.length;
|
|
80
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
81
|
-
pbegin++;
|
|
82
|
-
zeroes++;
|
|
83
|
-
}
|
|
84
|
-
var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
|
|
85
|
-
var b58 = new Uint8Array(size);
|
|
86
|
-
while (pbegin !== pend) {
|
|
87
|
-
var carry = source[pbegin];
|
|
88
|
-
var i2 = 0;
|
|
89
|
-
for (var it1 = size - 1; (carry !== 0 || i2 < length) && it1 !== -1; it1--, i2++) {
|
|
90
|
-
carry += 256 * b58[it1] >>> 0;
|
|
91
|
-
b58[it1] = carry % BASE >>> 0;
|
|
92
|
-
carry = carry / BASE >>> 0;
|
|
93
|
-
}
|
|
94
|
-
if (carry !== 0) {
|
|
95
|
-
throw new Error("Non-zero carry");
|
|
96
|
-
}
|
|
97
|
-
length = i2;
|
|
98
|
-
pbegin++;
|
|
99
|
-
}
|
|
100
|
-
var it2 = size - length;
|
|
101
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
102
|
-
it2++;
|
|
103
|
-
}
|
|
104
|
-
var str = LEADER.repeat(zeroes);
|
|
105
|
-
for (; it2 < size; ++it2) {
|
|
106
|
-
str += ALPHABET.charAt(b58[it2]);
|
|
107
|
-
}
|
|
108
|
-
return str;
|
|
109
|
-
}
|
|
110
|
-
function decodeUnsafe(source) {
|
|
111
|
-
if (typeof source !== "string") {
|
|
112
|
-
throw new TypeError("Expected String");
|
|
113
|
-
}
|
|
114
|
-
if (source.length === 0) {
|
|
115
|
-
return new Uint8Array();
|
|
116
|
-
}
|
|
117
|
-
var psz = 0;
|
|
118
|
-
var zeroes = 0;
|
|
119
|
-
var length = 0;
|
|
120
|
-
while (source[psz] === LEADER) {
|
|
121
|
-
zeroes++;
|
|
122
|
-
psz++;
|
|
123
|
-
}
|
|
124
|
-
var size = (source.length - psz) * FACTOR + 1 >>> 0;
|
|
125
|
-
var b256 = new Uint8Array(size);
|
|
126
|
-
while (source[psz]) {
|
|
127
|
-
var carry = BASE_MAP[source.charCodeAt(psz)];
|
|
128
|
-
if (carry === 255) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
var i2 = 0;
|
|
132
|
-
for (var it3 = size - 1; (carry !== 0 || i2 < length) && it3 !== -1; it3--, i2++) {
|
|
133
|
-
carry += BASE * b256[it3] >>> 0;
|
|
134
|
-
b256[it3] = carry % 256 >>> 0;
|
|
135
|
-
carry = carry / 256 >>> 0;
|
|
136
|
-
}
|
|
137
|
-
if (carry !== 0) {
|
|
138
|
-
throw new Error("Non-zero carry");
|
|
139
|
-
}
|
|
140
|
-
length = i2;
|
|
141
|
-
psz++;
|
|
142
|
-
}
|
|
143
|
-
var it4 = size - length;
|
|
144
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
145
|
-
it4++;
|
|
146
|
-
}
|
|
147
|
-
var vch = new Uint8Array(zeroes + (size - it4));
|
|
148
|
-
var j2 = zeroes;
|
|
149
|
-
while (it4 !== size) {
|
|
150
|
-
vch[j2++] = b256[it4++];
|
|
151
|
-
}
|
|
152
|
-
return vch;
|
|
153
|
-
}
|
|
154
|
-
function decode(string) {
|
|
155
|
-
var buffer = decodeUnsafe(string);
|
|
156
|
-
if (buffer) {
|
|
157
|
-
return buffer;
|
|
158
|
-
}
|
|
159
|
-
throw new Error("Non-base" + BASE + " character");
|
|
160
|
-
}
|
|
161
|
-
return {
|
|
162
|
-
encode,
|
|
163
|
-
decodeUnsafe,
|
|
164
|
-
decode
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
module.exports = base;
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
// ../../node_modules/.pnpm/bs58@5.0.0/node_modules/bs58/index.js
|
|
172
|
-
var require_bs58 = __commonJS({
|
|
173
|
-
"../../node_modules/.pnpm/bs58@5.0.0/node_modules/bs58/index.js"(exports, module) {
|
|
174
|
-
init_env_shim();
|
|
175
|
-
var basex = require_src();
|
|
176
|
-
var ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
177
|
-
module.exports = basex(ALPHABET);
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
|
|
181
45
|
// ../../node_modules/.pnpm/fast-stable-stringify@1.0.0/node_modules/fast-stable-stringify/index.js
|
|
182
46
|
var require_fast_stable_stringify = __commonJS({
|
|
183
47
|
"../../node_modules/.pnpm/fast-stable-stringify@1.0.0/node_modules/fast-stable-stringify/index.js"(exports, module) {
|
|
@@ -237,59 +101,1629 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
237
101
|
return JSON.stringify(val);
|
|
238
102
|
}
|
|
239
103
|
}
|
|
240
|
-
case "function":
|
|
241
|
-
case "undefined":
|
|
242
|
-
return isArrayProp ? null : void 0;
|
|
243
|
-
case "string":
|
|
244
|
-
return JSON.stringify(val);
|
|
245
|
-
default:
|
|
246
|
-
return isFinite(val) ? val : null;
|
|
104
|
+
case "function":
|
|
105
|
+
case "undefined":
|
|
106
|
+
return isArrayProp ? null : void 0;
|
|
107
|
+
case "string":
|
|
108
|
+
return JSON.stringify(val);
|
|
109
|
+
default:
|
|
110
|
+
return isFinite(val) ? val : null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
module.exports = function(val) {
|
|
114
|
+
var returnVal = stringify(val, false);
|
|
115
|
+
if (returnVal !== void 0) {
|
|
116
|
+
return "" + returnVal;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// src/index.ts
|
|
123
|
+
init_env_shim();
|
|
124
|
+
|
|
125
|
+
// ../addresses/dist/index.browser.js
|
|
126
|
+
init_env_shim();
|
|
127
|
+
|
|
128
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/index.mjs
|
|
129
|
+
init_env_shim();
|
|
130
|
+
|
|
131
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/index.mjs
|
|
132
|
+
init_env_shim();
|
|
133
|
+
|
|
134
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/bytes.mjs
|
|
135
|
+
init_env_shim();
|
|
136
|
+
var mergeBytes = (bytesArr) => {
|
|
137
|
+
const totalLength = bytesArr.reduce((total, arr) => total + arr.length, 0);
|
|
138
|
+
const result = new Uint8Array(totalLength);
|
|
139
|
+
let offset = 0;
|
|
140
|
+
bytesArr.forEach((arr) => {
|
|
141
|
+
result.set(arr, offset);
|
|
142
|
+
offset += arr.length;
|
|
143
|
+
});
|
|
144
|
+
return result;
|
|
145
|
+
};
|
|
146
|
+
var padBytes = (bytes2, length) => {
|
|
147
|
+
if (bytes2.length >= length)
|
|
148
|
+
return bytes2;
|
|
149
|
+
const paddedBytes = new Uint8Array(length).fill(0);
|
|
150
|
+
paddedBytes.set(bytes2);
|
|
151
|
+
return paddedBytes;
|
|
152
|
+
};
|
|
153
|
+
var fixBytes = (bytes2, length) => padBytes(bytes2.slice(0, length), length);
|
|
154
|
+
|
|
155
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/errors.mjs
|
|
156
|
+
init_env_shim();
|
|
157
|
+
var DeserializingEmptyBufferError = class extends Error {
|
|
158
|
+
constructor(serializer) {
|
|
159
|
+
super(`Serializer [${serializer}] cannot deserialize empty buffers.`);
|
|
160
|
+
__publicField(this, "name", "DeserializingEmptyBufferError");
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
var NotEnoughBytesError = class extends Error {
|
|
164
|
+
constructor(serializer, expected, actual) {
|
|
165
|
+
super(`Serializer [${serializer}] expected ${expected} bytes, got ${actual}.`);
|
|
166
|
+
__publicField(this, "name", "NotEnoughBytesError");
|
|
167
|
+
}
|
|
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
|
+
};
|
|
176
|
+
|
|
177
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/fixSerializer.mjs
|
|
178
|
+
init_env_shim();
|
|
179
|
+
function fixSerializer(serializer, fixedBytes, description) {
|
|
180
|
+
return {
|
|
181
|
+
description: description ?? `fixed(${fixedBytes}, ${serializer.description})`,
|
|
182
|
+
fixedSize: fixedBytes,
|
|
183
|
+
maxSize: fixedBytes,
|
|
184
|
+
serialize: (value) => fixBytes(serializer.serialize(value), fixedBytes),
|
|
185
|
+
deserialize: (buffer, offset = 0) => {
|
|
186
|
+
buffer = buffer.slice(offset, offset + fixedBytes);
|
|
187
|
+
if (buffer.length < fixedBytes) {
|
|
188
|
+
throw new NotEnoughBytesError("fixSerializer", fixedBytes, buffer.length);
|
|
189
|
+
}
|
|
190
|
+
if (serializer.fixedSize !== null) {
|
|
191
|
+
buffer = fixBytes(buffer, serializer.fixedSize);
|
|
192
|
+
}
|
|
193
|
+
const [value] = serializer.deserialize(buffer, 0);
|
|
194
|
+
return [value, offset + fixedBytes];
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
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
|
|
215
|
+
init_env_shim();
|
|
216
|
+
|
|
217
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
|
|
218
|
+
init_env_shim();
|
|
219
|
+
|
|
220
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
|
|
221
|
+
init_env_shim();
|
|
222
|
+
var InvalidBaseStringError = class extends Error {
|
|
223
|
+
constructor(value, base, cause) {
|
|
224
|
+
const message = `Expected a string of base ${base}, got [${value}].`;
|
|
225
|
+
super(message);
|
|
226
|
+
__publicField(this, "name", "InvalidBaseStringError");
|
|
227
|
+
this.cause = cause;
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
|
|
232
|
+
var baseX = (alphabet) => {
|
|
233
|
+
const base = alphabet.length;
|
|
234
|
+
const baseBigInt = BigInt(base);
|
|
235
|
+
return {
|
|
236
|
+
description: `base${base}`,
|
|
237
|
+
fixedSize: null,
|
|
238
|
+
maxSize: null,
|
|
239
|
+
serialize(value) {
|
|
240
|
+
if (!value.match(new RegExp(`^[${alphabet}]*$`))) {
|
|
241
|
+
throw new InvalidBaseStringError(value, base);
|
|
242
|
+
}
|
|
243
|
+
if (value === "")
|
|
244
|
+
return new Uint8Array();
|
|
245
|
+
const chars = [...value];
|
|
246
|
+
let trailIndex = chars.findIndex((c) => c !== alphabet[0]);
|
|
247
|
+
trailIndex = trailIndex === -1 ? chars.length : trailIndex;
|
|
248
|
+
const leadingZeroes = Array(trailIndex).fill(0);
|
|
249
|
+
if (trailIndex === chars.length)
|
|
250
|
+
return Uint8Array.from(leadingZeroes);
|
|
251
|
+
const tailChars = chars.slice(trailIndex);
|
|
252
|
+
let base10Number = 0n;
|
|
253
|
+
let baseXPower = 1n;
|
|
254
|
+
for (let i = tailChars.length - 1; i >= 0; i -= 1) {
|
|
255
|
+
base10Number += baseXPower * BigInt(alphabet.indexOf(tailChars[i]));
|
|
256
|
+
baseXPower *= baseBigInt;
|
|
257
|
+
}
|
|
258
|
+
const tailBytes = [];
|
|
259
|
+
while (base10Number > 0n) {
|
|
260
|
+
tailBytes.unshift(Number(base10Number % 256n));
|
|
261
|
+
base10Number /= 256n;
|
|
262
|
+
}
|
|
263
|
+
return Uint8Array.from(leadingZeroes.concat(tailBytes));
|
|
264
|
+
},
|
|
265
|
+
deserialize(buffer, offset = 0) {
|
|
266
|
+
if (buffer.length === 0)
|
|
267
|
+
return ["", 0];
|
|
268
|
+
const bytes2 = buffer.slice(offset);
|
|
269
|
+
let trailIndex = bytes2.findIndex((n) => n !== 0);
|
|
270
|
+
trailIndex = trailIndex === -1 ? bytes2.length : trailIndex;
|
|
271
|
+
const leadingZeroes = alphabet[0].repeat(trailIndex);
|
|
272
|
+
if (trailIndex === bytes2.length)
|
|
273
|
+
return [leadingZeroes, buffer.length];
|
|
274
|
+
let base10Number = bytes2.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
|
|
275
|
+
const tailChars = [];
|
|
276
|
+
while (base10Number > 0n) {
|
|
277
|
+
tailChars.unshift(alphabet[Number(base10Number % baseBigInt)]);
|
|
278
|
+
base10Number /= baseBigInt;
|
|
279
|
+
}
|
|
280
|
+
return [leadingZeroes + tailChars.join(""), buffer.length];
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base58.mjs
|
|
286
|
+
init_env_shim();
|
|
287
|
+
var base58 = baseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
|
|
288
|
+
|
|
289
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/nullCharacters.mjs
|
|
290
|
+
init_env_shim();
|
|
291
|
+
var removeNullCharacters = (value) => (
|
|
292
|
+
// eslint-disable-next-line no-control-regex
|
|
293
|
+
value.replace(/\u0000/g, "")
|
|
294
|
+
);
|
|
295
|
+
|
|
296
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/utf8.mjs
|
|
297
|
+
init_env_shim();
|
|
298
|
+
var utf8 = {
|
|
299
|
+
description: "utf8",
|
|
300
|
+
fixedSize: null,
|
|
301
|
+
maxSize: null,
|
|
302
|
+
serialize(value) {
|
|
303
|
+
return new TextEncoder().encode(value);
|
|
304
|
+
},
|
|
305
|
+
deserialize(buffer, offset = 0) {
|
|
306
|
+
const value = new TextDecoder().decode(buffer.slice(offset));
|
|
307
|
+
return [removeNullCharacters(value), buffer.length];
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/index.mjs
|
|
312
|
+
init_env_shim();
|
|
313
|
+
|
|
314
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/common.mjs
|
|
315
|
+
init_env_shim();
|
|
316
|
+
var Endian;
|
|
317
|
+
(function(Endian2) {
|
|
318
|
+
Endian2["Little"] = "le";
|
|
319
|
+
Endian2["Big"] = "be";
|
|
320
|
+
})(Endian || (Endian = {}));
|
|
321
|
+
|
|
322
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/errors.mjs
|
|
323
|
+
init_env_shim();
|
|
324
|
+
var NumberOutOfRangeError = class extends RangeError {
|
|
325
|
+
constructor(serializer, min, max, actual) {
|
|
326
|
+
super(`Serializer [${serializer}] expected number to be between ${min} and ${max}, got ${actual}.`);
|
|
327
|
+
__publicField(this, "name", "NumberOutOfRangeError");
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/utils.mjs
|
|
332
|
+
init_env_shim();
|
|
333
|
+
function numberFactory(input) {
|
|
334
|
+
let littleEndian;
|
|
335
|
+
let defaultDescription = input.name;
|
|
336
|
+
if (input.size > 1) {
|
|
337
|
+
littleEndian = !("endian" in input.options) || input.options.endian === Endian.Little;
|
|
338
|
+
defaultDescription += littleEndian ? "(le)" : "(be)";
|
|
339
|
+
}
|
|
340
|
+
return {
|
|
341
|
+
description: input.options.description ?? defaultDescription,
|
|
342
|
+
fixedSize: input.size,
|
|
343
|
+
maxSize: input.size,
|
|
344
|
+
serialize(value) {
|
|
345
|
+
if (input.range) {
|
|
346
|
+
assertRange(input.name, input.range[0], input.range[1], value);
|
|
347
|
+
}
|
|
348
|
+
const buffer = new ArrayBuffer(input.size);
|
|
349
|
+
input.set(new DataView(buffer), value, littleEndian);
|
|
350
|
+
return new Uint8Array(buffer);
|
|
351
|
+
},
|
|
352
|
+
deserialize(bytes2, offset = 0) {
|
|
353
|
+
const slice = bytes2.slice(offset, offset + input.size);
|
|
354
|
+
assertEnoughBytes("i8", slice, input.size);
|
|
355
|
+
const view = toDataView(slice);
|
|
356
|
+
return [input.get(view, littleEndian), offset + input.size];
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
var toArrayBuffer = (array2) => array2.buffer.slice(array2.byteOffset, array2.byteLength + array2.byteOffset);
|
|
361
|
+
var toDataView = (array2) => new DataView(toArrayBuffer(array2));
|
|
362
|
+
var assertRange = (serializer, min, max, value) => {
|
|
363
|
+
if (value < min || value > max) {
|
|
364
|
+
throw new NumberOutOfRangeError(serializer, min, max, value);
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
var assertEnoughBytes = (serializer, bytes2, expected) => {
|
|
368
|
+
if (bytes2.length === 0) {
|
|
369
|
+
throw new DeserializingEmptyBufferError(serializer);
|
|
370
|
+
}
|
|
371
|
+
if (bytes2.length < expected) {
|
|
372
|
+
throw new NotEnoughBytesError(serializer, expected, bytes2.length);
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
|
|
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
|
|
388
|
+
init_env_shim();
|
|
389
|
+
var u32 = (options = {}) => numberFactory({
|
|
390
|
+
name: "u32",
|
|
391
|
+
size: 4,
|
|
392
|
+
range: [0, Number("0xffffffff")],
|
|
393
|
+
set: (view, value, le) => view.setUint32(0, Number(value), le),
|
|
394
|
+
get: (view, le) => view.getUint32(0, le),
|
|
395
|
+
options
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/shortU16.mjs
|
|
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
|
+
}
|
|
490
|
+
function getSizeDescription(size) {
|
|
491
|
+
return typeof size === "object" ? size.description : `${size}`;
|
|
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
|
+
}
|
|
585
|
+
|
|
586
|
+
// ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/string.mjs
|
|
587
|
+
init_env_shim();
|
|
588
|
+
function string(options = {}) {
|
|
589
|
+
const size = options.size ?? u32();
|
|
590
|
+
const encoding = options.encoding ?? utf8;
|
|
591
|
+
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
|
|
592
|
+
if (size === "variable") {
|
|
593
|
+
return {
|
|
594
|
+
...encoding,
|
|
595
|
+
description
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
if (typeof size === "number") {
|
|
599
|
+
return fixSerializer(encoding, size, description);
|
|
600
|
+
}
|
|
601
|
+
return {
|
|
602
|
+
description,
|
|
603
|
+
fixedSize: null,
|
|
604
|
+
maxSize: null,
|
|
605
|
+
serialize: (value) => {
|
|
606
|
+
const contentBytes = encoding.serialize(value);
|
|
607
|
+
const lengthBytes = size.serialize(contentBytes.length);
|
|
608
|
+
return mergeBytes([lengthBytes, contentBytes]);
|
|
609
|
+
},
|
|
610
|
+
deserialize: (buffer, offset = 0) => {
|
|
611
|
+
if (buffer.slice(offset).length === 0) {
|
|
612
|
+
throw new DeserializingEmptyBufferError("string");
|
|
613
|
+
}
|
|
614
|
+
const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
|
|
615
|
+
const length = Number(lengthBigInt);
|
|
616
|
+
offset = lengthOffset;
|
|
617
|
+
const contentBuffer = buffer.slice(offset, offset + length);
|
|
618
|
+
if (contentBuffer.length < length) {
|
|
619
|
+
throw new NotEnoughBytesError("string", length, contentBuffer.length);
|
|
620
|
+
}
|
|
621
|
+
const [value, contentOffset] = encoding.deserialize(contentBuffer);
|
|
622
|
+
offset += contentOffset;
|
|
623
|
+
return [value, offset];
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
}
|
|
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];
|
|
648
|
+
}
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
// ../assertions/dist/index.browser.js
|
|
653
|
+
init_env_shim();
|
|
654
|
+
function assertIsSecureContext() {
|
|
655
|
+
if (!globalThis.isSecureContext) {
|
|
656
|
+
throw new Error(
|
|
657
|
+
"Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts"
|
|
658
|
+
);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
var cachedEd25519Decision;
|
|
662
|
+
async function isEd25519CurveSupported(subtle) {
|
|
663
|
+
if (cachedEd25519Decision === void 0) {
|
|
664
|
+
cachedEd25519Decision = new Promise((resolve) => {
|
|
665
|
+
subtle.generateKey(
|
|
666
|
+
"Ed25519",
|
|
667
|
+
/* extractable */
|
|
668
|
+
false,
|
|
669
|
+
["sign", "verify"]
|
|
670
|
+
).catch(() => {
|
|
671
|
+
resolve(cachedEd25519Decision = false);
|
|
672
|
+
}).then(() => {
|
|
673
|
+
resolve(cachedEd25519Decision = true);
|
|
674
|
+
});
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
if (typeof cachedEd25519Decision === "boolean") {
|
|
678
|
+
return cachedEd25519Decision;
|
|
679
|
+
} else {
|
|
680
|
+
return await cachedEd25519Decision;
|
|
681
|
+
}
|
|
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
|
+
}
|
|
689
|
+
async function assertKeyGenerationIsAvailable() {
|
|
690
|
+
assertIsSecureContext();
|
|
691
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.generateKey !== "function") {
|
|
692
|
+
throw new Error("No key generation implementation could be found");
|
|
693
|
+
}
|
|
694
|
+
if (!await isEd25519CurveSupported(globalThis.crypto.subtle)) {
|
|
695
|
+
throw new Error(
|
|
696
|
+
"This runtime does not support the generation of Ed25519 key pairs.\n\nInstall and import `@solana/webcrypto-ed25519-polyfill` before generating keys in environments that do not support Ed25519.\n\nFor a list of runtimes that currently support Ed25519 operations, visit https://github.com/WICG/webcrypto-secure-curves/issues/20"
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
async function assertKeyExporterIsAvailable() {
|
|
701
|
+
assertIsSecureContext();
|
|
702
|
+
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
|
|
703
|
+
throw new Error("No key export implementation could be found");
|
|
704
|
+
}
|
|
705
|
+
}
|
|
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 assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
|
|
719
|
+
try {
|
|
720
|
+
if (
|
|
721
|
+
// Lowest address (32 bytes of zeroes)
|
|
722
|
+
putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
723
|
+
putativeBase58EncodedAddress.length > 44
|
|
724
|
+
) {
|
|
725
|
+
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
726
|
+
}
|
|
727
|
+
const bytes2 = base58.serialize(putativeBase58EncodedAddress);
|
|
728
|
+
const numBytes = bytes2.byteLength;
|
|
729
|
+
if (numBytes !== 32) {
|
|
730
|
+
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
731
|
+
}
|
|
732
|
+
} catch (e3) {
|
|
733
|
+
throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
|
|
734
|
+
cause: e3
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
function getBase58EncodedAddressCodec(config) {
|
|
739
|
+
return string({
|
|
740
|
+
description: config?.description ?? ("A 32-byte account address" ),
|
|
741
|
+
encoding: base58,
|
|
742
|
+
size: 32
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
function getBase58EncodedAddressComparator() {
|
|
746
|
+
return new Intl.Collator("en", {
|
|
747
|
+
caseFirst: "lower",
|
|
748
|
+
ignorePunctuation: false,
|
|
749
|
+
localeMatcher: "best fit",
|
|
750
|
+
numeric: false,
|
|
751
|
+
sensitivity: "variant",
|
|
752
|
+
usage: "sort"
|
|
753
|
+
}).compare;
|
|
754
|
+
}
|
|
755
|
+
var D = 37095705934669439343138083508754565189542113879843219016388785533085940283555n;
|
|
756
|
+
var P = 57896044618658097711785492504343953926634992332820282019728792003956564819949n;
|
|
757
|
+
var RM1 = 19681161376707505956807079304988542015446066515923890162744021073123829784752n;
|
|
758
|
+
function mod(a) {
|
|
759
|
+
const r = a % P;
|
|
760
|
+
return r >= 0n ? r : P + r;
|
|
761
|
+
}
|
|
762
|
+
function pow2(x, power) {
|
|
763
|
+
let r = x;
|
|
764
|
+
while (power-- > 0n) {
|
|
765
|
+
r *= r;
|
|
766
|
+
r %= P;
|
|
767
|
+
}
|
|
768
|
+
return r;
|
|
769
|
+
}
|
|
770
|
+
function pow_2_252_3(x) {
|
|
771
|
+
const x2 = x * x % P;
|
|
772
|
+
const b2 = x2 * x % P;
|
|
773
|
+
const b4 = pow2(b2, 2n) * b2 % P;
|
|
774
|
+
const b5 = pow2(b4, 1n) * x % P;
|
|
775
|
+
const b10 = pow2(b5, 5n) * b5 % P;
|
|
776
|
+
const b20 = pow2(b10, 10n) * b10 % P;
|
|
777
|
+
const b40 = pow2(b20, 20n) * b20 % P;
|
|
778
|
+
const b80 = pow2(b40, 40n) * b40 % P;
|
|
779
|
+
const b160 = pow2(b80, 80n) * b80 % P;
|
|
780
|
+
const b240 = pow2(b160, 80n) * b80 % P;
|
|
781
|
+
const b250 = pow2(b240, 10n) * b10 % P;
|
|
782
|
+
const pow_p_5_8 = pow2(b250, 2n) * x % P;
|
|
783
|
+
return pow_p_5_8;
|
|
784
|
+
}
|
|
785
|
+
function uvRatio(u, v) {
|
|
786
|
+
const v3 = mod(v * v * v);
|
|
787
|
+
const v7 = mod(v3 * v3 * v);
|
|
788
|
+
const pow = pow_2_252_3(u * v7);
|
|
789
|
+
let x = mod(u * v3 * pow);
|
|
790
|
+
const vx2 = mod(v * x * x);
|
|
791
|
+
const root1 = x;
|
|
792
|
+
const root2 = mod(x * RM1);
|
|
793
|
+
const useRoot1 = vx2 === u;
|
|
794
|
+
const useRoot2 = vx2 === mod(-u);
|
|
795
|
+
const noRoot = vx2 === mod(-u * RM1);
|
|
796
|
+
if (useRoot1)
|
|
797
|
+
x = root1;
|
|
798
|
+
if (useRoot2 || noRoot)
|
|
799
|
+
x = root2;
|
|
800
|
+
if ((mod(x) & 1n) === 1n)
|
|
801
|
+
x = mod(-x);
|
|
802
|
+
if (!useRoot1 && !useRoot2) {
|
|
803
|
+
return null;
|
|
804
|
+
}
|
|
805
|
+
return x;
|
|
806
|
+
}
|
|
807
|
+
function pointIsOnCurve(y, lastByte) {
|
|
808
|
+
const y2 = mod(y * y);
|
|
809
|
+
const u = mod(y2 - 1n);
|
|
810
|
+
const v = mod(D * y2 + 1n);
|
|
811
|
+
const x = uvRatio(u, v);
|
|
812
|
+
if (x === null) {
|
|
813
|
+
return false;
|
|
814
|
+
}
|
|
815
|
+
const isLastByteOdd = (lastByte & 128) !== 0;
|
|
816
|
+
if (x === 0n && isLastByteOdd) {
|
|
817
|
+
return false;
|
|
818
|
+
}
|
|
819
|
+
return true;
|
|
820
|
+
}
|
|
821
|
+
function byteToHex(byte) {
|
|
822
|
+
const hexString = byte.toString(16);
|
|
823
|
+
if (hexString.length === 1) {
|
|
824
|
+
return `0${hexString}`;
|
|
825
|
+
} else {
|
|
826
|
+
return hexString;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
function decompressPointBytes(bytes2) {
|
|
830
|
+
const hexString = bytes2.reduce((acc, byte, ii) => `${byteToHex(ii === 31 ? byte & ~128 : byte)}${acc}`, "");
|
|
831
|
+
const integerLiteralString = `0x${hexString}`;
|
|
832
|
+
return BigInt(integerLiteralString);
|
|
833
|
+
}
|
|
834
|
+
async function compressedPointBytesAreOnCurve(bytes2) {
|
|
835
|
+
if (bytes2.byteLength !== 32) {
|
|
836
|
+
return false;
|
|
837
|
+
}
|
|
838
|
+
const y = decompressPointBytes(bytes2);
|
|
839
|
+
return pointIsOnCurve(y, bytes2[31]);
|
|
840
|
+
}
|
|
841
|
+
var MAX_SEED_LENGTH = 32;
|
|
842
|
+
var MAX_SEEDS = 16;
|
|
843
|
+
var PDA_MARKER_BYTES = [
|
|
844
|
+
// The string 'ProgramDerivedAddress'
|
|
845
|
+
80,
|
|
846
|
+
114,
|
|
847
|
+
111,
|
|
848
|
+
103,
|
|
849
|
+
114,
|
|
850
|
+
97,
|
|
851
|
+
109,
|
|
852
|
+
68,
|
|
853
|
+
101,
|
|
854
|
+
114,
|
|
855
|
+
105,
|
|
856
|
+
118,
|
|
857
|
+
101,
|
|
858
|
+
100,
|
|
859
|
+
65,
|
|
860
|
+
100,
|
|
861
|
+
100,
|
|
862
|
+
114,
|
|
863
|
+
101,
|
|
864
|
+
115,
|
|
865
|
+
115
|
|
866
|
+
];
|
|
867
|
+
var PointOnCurveError = class extends Error {
|
|
868
|
+
};
|
|
869
|
+
async function createProgramDerivedAddress({ programAddress, seeds }) {
|
|
870
|
+
await assertDigestCapabilityIsAvailable();
|
|
871
|
+
if (seeds.length > MAX_SEEDS) {
|
|
872
|
+
throw new Error(`A maximum of ${MAX_SEEDS} seeds may be supplied when creating an address`);
|
|
873
|
+
}
|
|
874
|
+
let textEncoder;
|
|
875
|
+
const seedBytes = seeds.reduce((acc, seed, ii) => {
|
|
876
|
+
const bytes2 = typeof seed === "string" ? (textEncoder || (textEncoder = new TextEncoder())).encode(seed) : seed;
|
|
877
|
+
if (bytes2.byteLength > MAX_SEED_LENGTH) {
|
|
878
|
+
throw new Error(`The seed at index ${ii} exceeds the maximum length of 32 bytes`);
|
|
879
|
+
}
|
|
880
|
+
acc.push(...bytes2);
|
|
881
|
+
return acc;
|
|
882
|
+
}, []);
|
|
883
|
+
const base58EncodedAddressCodec = getBase58EncodedAddressCodec();
|
|
884
|
+
const programAddressBytes = base58EncodedAddressCodec.serialize(programAddress);
|
|
885
|
+
const addressBytesBuffer = await crypto.subtle.digest(
|
|
886
|
+
"SHA-256",
|
|
887
|
+
new Uint8Array([...seedBytes, ...programAddressBytes, ...PDA_MARKER_BYTES])
|
|
888
|
+
);
|
|
889
|
+
const addressBytes = new Uint8Array(addressBytesBuffer);
|
|
890
|
+
if (await compressedPointBytesAreOnCurve(addressBytes)) {
|
|
891
|
+
throw new PointOnCurveError("Invalid seeds; point must fall off the Ed25519 curve");
|
|
892
|
+
}
|
|
893
|
+
return base58EncodedAddressCodec.deserialize(addressBytes)[0];
|
|
894
|
+
}
|
|
895
|
+
async function getProgramDerivedAddress({ programAddress, seeds }) {
|
|
896
|
+
let bumpSeed = 255;
|
|
897
|
+
while (bumpSeed > 0) {
|
|
898
|
+
try {
|
|
899
|
+
return {
|
|
900
|
+
bumpSeed,
|
|
901
|
+
pda: await createProgramDerivedAddress({
|
|
902
|
+
programAddress,
|
|
903
|
+
seeds: [...seeds, new Uint8Array([bumpSeed])]
|
|
904
|
+
})
|
|
905
|
+
};
|
|
906
|
+
} catch (e3) {
|
|
907
|
+
if (e3 instanceof PointOnCurveError) {
|
|
908
|
+
bumpSeed--;
|
|
909
|
+
} else {
|
|
910
|
+
throw e3;
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
throw new Error("Unable to find a viable program address bump seed");
|
|
915
|
+
}
|
|
916
|
+
async function createAddressWithSeed({
|
|
917
|
+
baseAddress,
|
|
918
|
+
programAddress,
|
|
919
|
+
seed
|
|
920
|
+
}) {
|
|
921
|
+
const { serialize: serialize4, deserialize: deserialize2 } = getBase58EncodedAddressCodec();
|
|
922
|
+
const seedBytes = typeof seed === "string" ? new TextEncoder().encode(seed) : seed;
|
|
923
|
+
if (seedBytes.byteLength > MAX_SEED_LENGTH) {
|
|
924
|
+
throw new Error(`The seed exceeds the maximum length of 32 bytes`);
|
|
925
|
+
}
|
|
926
|
+
const programAddressBytes = serialize4(programAddress);
|
|
927
|
+
if (programAddressBytes.length >= PDA_MARKER_BYTES.length && programAddressBytes.slice(-PDA_MARKER_BYTES.length).every((byte, index) => byte === PDA_MARKER_BYTES[index])) {
|
|
928
|
+
throw new Error(`programAddress cannot end with the PDA marker`);
|
|
929
|
+
}
|
|
930
|
+
const addressBytesBuffer = await crypto.subtle.digest(
|
|
931
|
+
"SHA-256",
|
|
932
|
+
new Uint8Array([...serialize4(baseAddress), ...seedBytes, ...programAddressBytes])
|
|
933
|
+
);
|
|
934
|
+
const addressBytes = new Uint8Array(addressBytesBuffer);
|
|
935
|
+
return deserialize2(addressBytes)[0];
|
|
936
|
+
}
|
|
937
|
+
async function getAddressFromPublicKey(publicKey) {
|
|
938
|
+
await assertKeyExporterIsAvailable();
|
|
939
|
+
if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
|
|
940
|
+
throw new Error("The `CryptoKey` must be an `Ed25519` public key");
|
|
941
|
+
}
|
|
942
|
+
const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
|
|
943
|
+
const [base58EncodedAddress] = getBase58EncodedAddressCodec().deserialize(new Uint8Array(publicKeyBytes));
|
|
944
|
+
return base58EncodedAddress;
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
// ../instructions/dist/index.browser.js
|
|
948
|
+
init_env_shim();
|
|
949
|
+
var AccountRole = /* @__PURE__ */ ((AccountRole22) => {
|
|
950
|
+
AccountRole22[AccountRole22["WRITABLE_SIGNER"] = /* 3 */
|
|
951
|
+
3] = "WRITABLE_SIGNER";
|
|
952
|
+
AccountRole22[AccountRole22["READONLY_SIGNER"] = /* 2 */
|
|
953
|
+
2] = "READONLY_SIGNER";
|
|
954
|
+
AccountRole22[AccountRole22["WRITABLE"] = /* 1 */
|
|
955
|
+
1] = "WRITABLE";
|
|
956
|
+
AccountRole22[AccountRole22["READONLY"] = /* 0 */
|
|
957
|
+
0] = "READONLY";
|
|
958
|
+
return AccountRole22;
|
|
959
|
+
})(AccountRole || {});
|
|
960
|
+
var IS_SIGNER_BITMASK = 2;
|
|
961
|
+
var IS_WRITABLE_BITMASK = 1;
|
|
962
|
+
function downgradeRoleToNonSigner(role) {
|
|
963
|
+
return role & ~IS_SIGNER_BITMASK;
|
|
964
|
+
}
|
|
965
|
+
function downgradeRoleToReadonly(role) {
|
|
966
|
+
return role & ~IS_WRITABLE_BITMASK;
|
|
967
|
+
}
|
|
968
|
+
function isSignerRole(role) {
|
|
969
|
+
return role >= 2;
|
|
970
|
+
}
|
|
971
|
+
function isWritableRole(role) {
|
|
972
|
+
return (role & IS_WRITABLE_BITMASK) !== 0;
|
|
973
|
+
}
|
|
974
|
+
function mergeRoles(roleA, roleB) {
|
|
975
|
+
return roleA | roleB;
|
|
976
|
+
}
|
|
977
|
+
function upgradeRoleToSigner(role) {
|
|
978
|
+
return role | IS_SIGNER_BITMASK;
|
|
979
|
+
}
|
|
980
|
+
function upgradeRoleToWritable(role) {
|
|
981
|
+
return role | IS_WRITABLE_BITMASK;
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
// ../keys/dist/index.browser.js
|
|
985
|
+
init_env_shim();
|
|
986
|
+
async function generateKeyPair() {
|
|
987
|
+
await assertKeyGenerationIsAvailable();
|
|
988
|
+
const keyPair = await crypto.subtle.generateKey(
|
|
989
|
+
/* algorithm */
|
|
990
|
+
"Ed25519",
|
|
991
|
+
// Native implementation status: https://github.com/WICG/webcrypto-secure-curves/issues/20
|
|
992
|
+
/* extractable */
|
|
993
|
+
false,
|
|
994
|
+
// Prevents the bytes of the private key from being visible to JS.
|
|
995
|
+
/* allowed uses */
|
|
996
|
+
["sign", "verify"]
|
|
997
|
+
);
|
|
998
|
+
return keyPair;
|
|
999
|
+
}
|
|
1000
|
+
async function signBytes(key, data) {
|
|
1001
|
+
await assertSigningCapabilityIsAvailable();
|
|
1002
|
+
const signedData = await crypto.subtle.sign("Ed25519", key, data);
|
|
1003
|
+
return new Uint8Array(signedData);
|
|
1004
|
+
}
|
|
1005
|
+
async function verifySignature(key, signature, data) {
|
|
1006
|
+
await assertVerificationCapabilityIsAvailable();
|
|
1007
|
+
return await crypto.subtle.verify("Ed25519", key, signature, data);
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
// ../transactions/dist/index.browser.js
|
|
1011
|
+
init_env_shim();
|
|
1012
|
+
function getUnsignedTransaction(transaction) {
|
|
1013
|
+
if ("signatures" in transaction) {
|
|
1014
|
+
const {
|
|
1015
|
+
signatures: _,
|
|
1016
|
+
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
1017
|
+
...unsignedTransaction
|
|
1018
|
+
} = transaction;
|
|
1019
|
+
return unsignedTransaction;
|
|
1020
|
+
} else {
|
|
1021
|
+
return transaction;
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
function assertIsBlockhash(putativeBlockhash) {
|
|
1025
|
+
try {
|
|
1026
|
+
if (
|
|
1027
|
+
// Lowest value (32 bytes of zeroes)
|
|
1028
|
+
putativeBlockhash.length < 32 || // Highest value (32 bytes of 255)
|
|
1029
|
+
putativeBlockhash.length > 44
|
|
1030
|
+
) {
|
|
1031
|
+
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
1032
|
+
}
|
|
1033
|
+
const bytes3 = base58.serialize(putativeBlockhash);
|
|
1034
|
+
const numBytes = bytes3.byteLength;
|
|
1035
|
+
if (numBytes !== 32) {
|
|
1036
|
+
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
1037
|
+
}
|
|
1038
|
+
} catch (e3) {
|
|
1039
|
+
throw new Error(`\`${putativeBlockhash}\` is not a blockhash`, {
|
|
1040
|
+
cause: e3
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
|
|
1045
|
+
if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
|
|
1046
|
+
return transaction;
|
|
1047
|
+
}
|
|
1048
|
+
const out = {
|
|
1049
|
+
...getUnsignedTransaction(transaction),
|
|
1050
|
+
lifetimeConstraint: blockhashLifetimeConstraint
|
|
1051
|
+
};
|
|
1052
|
+
Object.freeze(out);
|
|
1053
|
+
return out;
|
|
1054
|
+
}
|
|
1055
|
+
function createTransaction({
|
|
1056
|
+
version
|
|
1057
|
+
}) {
|
|
1058
|
+
const out = {
|
|
1059
|
+
instructions: [],
|
|
1060
|
+
version
|
|
1061
|
+
};
|
|
1062
|
+
Object.freeze(out);
|
|
1063
|
+
return out;
|
|
1064
|
+
}
|
|
1065
|
+
var AccountRole2 = /* @__PURE__ */ ((AccountRole22) => {
|
|
1066
|
+
AccountRole22[AccountRole22["WRITABLE_SIGNER"] = /* 3 */
|
|
1067
|
+
3] = "WRITABLE_SIGNER";
|
|
1068
|
+
AccountRole22[AccountRole22["READONLY_SIGNER"] = /* 2 */
|
|
1069
|
+
2] = "READONLY_SIGNER";
|
|
1070
|
+
AccountRole22[AccountRole22["WRITABLE"] = /* 1 */
|
|
1071
|
+
1] = "WRITABLE";
|
|
1072
|
+
AccountRole22[AccountRole22["READONLY"] = /* 0 */
|
|
1073
|
+
0] = "READONLY";
|
|
1074
|
+
return AccountRole22;
|
|
1075
|
+
})(AccountRole2 || {});
|
|
1076
|
+
var IS_WRITABLE_BITMASK2 = 1;
|
|
1077
|
+
function isSignerRole2(role) {
|
|
1078
|
+
return role >= 2;
|
|
1079
|
+
}
|
|
1080
|
+
function isWritableRole2(role) {
|
|
1081
|
+
return (role & IS_WRITABLE_BITMASK2) !== 0;
|
|
1082
|
+
}
|
|
1083
|
+
function mergeRoles2(roleA, roleB) {
|
|
1084
|
+
return roleA | roleB;
|
|
1085
|
+
}
|
|
1086
|
+
var RECENT_BLOCKHASHES_SYSVAR_ADDRESS = "SysvarRecentB1ockHashes11111111111111111111";
|
|
1087
|
+
var SYSTEM_PROGRAM_ADDRESS = "11111111111111111111111111111111";
|
|
1088
|
+
function assertIsDurableNonceTransaction(transaction) {
|
|
1089
|
+
if (!isDurableNonceTransaction(transaction)) {
|
|
1090
|
+
throw new Error("Transaction is not a durable nonce transaction");
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
function createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress) {
|
|
1094
|
+
return {
|
|
1095
|
+
accounts: [
|
|
1096
|
+
{ address: nonceAccountAddress, role: AccountRole2.WRITABLE },
|
|
1097
|
+
{
|
|
1098
|
+
address: RECENT_BLOCKHASHES_SYSVAR_ADDRESS,
|
|
1099
|
+
role: AccountRole2.READONLY
|
|
1100
|
+
},
|
|
1101
|
+
{ address: nonceAuthorityAddress, role: AccountRole2.READONLY_SIGNER }
|
|
1102
|
+
],
|
|
1103
|
+
data: new Uint8Array([4, 0, 0, 0]),
|
|
1104
|
+
programAddress: SYSTEM_PROGRAM_ADDRESS
|
|
1105
|
+
};
|
|
1106
|
+
}
|
|
1107
|
+
function isAdvanceNonceAccountInstruction(instruction) {
|
|
1108
|
+
return instruction.programAddress === SYSTEM_PROGRAM_ADDRESS && // Test for `AdvanceNonceAccount` instruction data
|
|
1109
|
+
instruction.data != null && isAdvanceNonceAccountInstructionData(instruction.data) && // Test for exactly 3 accounts
|
|
1110
|
+
instruction.accounts?.length === 3 && // First account is nonce account address
|
|
1111
|
+
instruction.accounts[0].address != null && instruction.accounts[0].role === AccountRole2.WRITABLE && // Second account is recent blockhashes sysvar
|
|
1112
|
+
instruction.accounts[1].address === RECENT_BLOCKHASHES_SYSVAR_ADDRESS && instruction.accounts[1].role === AccountRole2.READONLY && // Third account is nonce authority account
|
|
1113
|
+
instruction.accounts[2].address != null && instruction.accounts[2].role === AccountRole2.READONLY_SIGNER;
|
|
1114
|
+
}
|
|
1115
|
+
function isAdvanceNonceAccountInstructionData(data) {
|
|
1116
|
+
return data.byteLength === 4 && data[0] === 4 && data[1] === 0 && data[2] === 0 && data[3] === 0;
|
|
1117
|
+
}
|
|
1118
|
+
function isDurableNonceTransaction(transaction) {
|
|
1119
|
+
return "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.nonce === "string" && transaction.instructions[0] != null && isAdvanceNonceAccountInstruction(transaction.instructions[0]);
|
|
1120
|
+
}
|
|
1121
|
+
function setTransactionLifetimeUsingDurableNonce({
|
|
1122
|
+
nonce,
|
|
1123
|
+
nonceAccountAddress,
|
|
1124
|
+
nonceAuthorityAddress
|
|
1125
|
+
}, transaction) {
|
|
1126
|
+
const isAlreadyDurableNonceTransaction = isDurableNonceTransaction(transaction);
|
|
1127
|
+
if (isAlreadyDurableNonceTransaction && transaction.lifetimeConstraint.nonce === nonce && transaction.instructions[0].accounts[0].address === nonceAccountAddress && transaction.instructions[0].accounts[2].address === nonceAuthorityAddress) {
|
|
1128
|
+
return transaction;
|
|
1129
|
+
}
|
|
1130
|
+
const out = {
|
|
1131
|
+
...getUnsignedTransaction(transaction),
|
|
1132
|
+
instructions: [
|
|
1133
|
+
createAdvanceNonceAccountInstruction(nonceAccountAddress, nonceAuthorityAddress),
|
|
1134
|
+
...isAlreadyDurableNonceTransaction ? transaction.instructions.slice(1) : transaction.instructions
|
|
1135
|
+
],
|
|
1136
|
+
lifetimeConstraint: {
|
|
1137
|
+
nonce
|
|
1138
|
+
}
|
|
1139
|
+
};
|
|
1140
|
+
Object.freeze(out);
|
|
1141
|
+
return out;
|
|
1142
|
+
}
|
|
1143
|
+
function setTransactionFeePayer(feePayer, transaction) {
|
|
1144
|
+
if ("feePayer" in transaction && feePayer === transaction.feePayer) {
|
|
1145
|
+
return transaction;
|
|
1146
|
+
}
|
|
1147
|
+
const out = {
|
|
1148
|
+
...getUnsignedTransaction(transaction),
|
|
1149
|
+
feePayer
|
|
1150
|
+
};
|
|
1151
|
+
Object.freeze(out);
|
|
1152
|
+
return out;
|
|
1153
|
+
}
|
|
1154
|
+
function appendTransactionInstruction(instruction, transaction) {
|
|
1155
|
+
const out = {
|
|
1156
|
+
...getUnsignedTransaction(transaction),
|
|
1157
|
+
instructions: [...transaction.instructions, instruction]
|
|
1158
|
+
};
|
|
1159
|
+
Object.freeze(out);
|
|
1160
|
+
return out;
|
|
1161
|
+
}
|
|
1162
|
+
function prependTransactionInstruction(instruction, transaction) {
|
|
1163
|
+
const out = {
|
|
1164
|
+
...getUnsignedTransaction(transaction),
|
|
1165
|
+
instructions: [instruction, ...transaction.instructions]
|
|
1166
|
+
};
|
|
1167
|
+
Object.freeze(out);
|
|
1168
|
+
return out;
|
|
1169
|
+
}
|
|
1170
|
+
function upsert(addressMap, address, update) {
|
|
1171
|
+
addressMap[address] = update(addressMap[address] ?? { role: AccountRole2.READONLY });
|
|
1172
|
+
}
|
|
1173
|
+
var TYPE = Symbol("AddressMapTypeProperty");
|
|
1174
|
+
function getAddressMapFromInstructions(feePayer, instructions) {
|
|
1175
|
+
const addressMap = {
|
|
1176
|
+
[feePayer]: { [TYPE]: 0, role: AccountRole2.WRITABLE_SIGNER }
|
|
1177
|
+
};
|
|
1178
|
+
const addressesOfInvokedPrograms = /* @__PURE__ */ new Set();
|
|
1179
|
+
for (const instruction of instructions) {
|
|
1180
|
+
upsert(addressMap, instruction.programAddress, (entry) => {
|
|
1181
|
+
addressesOfInvokedPrograms.add(instruction.programAddress);
|
|
1182
|
+
if (TYPE in entry) {
|
|
1183
|
+
if (isWritableRole2(entry.role)) {
|
|
1184
|
+
switch (entry[TYPE]) {
|
|
1185
|
+
case 0:
|
|
1186
|
+
throw new Error(
|
|
1187
|
+
`This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and set as the fee payer. Program addresses may not pay fees.`
|
|
1188
|
+
);
|
|
1189
|
+
default:
|
|
1190
|
+
throw new Error(
|
|
1191
|
+
`This transaction includes an address (\`${instruction.programAddress}\`) which is both invoked and marked writable. Program addresses may not be writable.`
|
|
1192
|
+
);
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
if (entry[TYPE] === 2) {
|
|
1196
|
+
return entry;
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
return { [TYPE]: 2, role: AccountRole2.READONLY };
|
|
1200
|
+
});
|
|
1201
|
+
let addressComparator;
|
|
1202
|
+
if (!instruction.accounts) {
|
|
1203
|
+
continue;
|
|
1204
|
+
}
|
|
1205
|
+
for (const account of instruction.accounts) {
|
|
1206
|
+
upsert(addressMap, account.address, (entry) => {
|
|
1207
|
+
const {
|
|
1208
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1209
|
+
address: _,
|
|
1210
|
+
...accountMeta
|
|
1211
|
+
} = account;
|
|
1212
|
+
if (TYPE in entry) {
|
|
1213
|
+
switch (entry[TYPE]) {
|
|
1214
|
+
case 0:
|
|
1215
|
+
return entry;
|
|
1216
|
+
case 1: {
|
|
1217
|
+
const nextRole = mergeRoles2(entry.role, accountMeta.role);
|
|
1218
|
+
if ("lookupTableAddress" in accountMeta) {
|
|
1219
|
+
const shouldReplaceEntry = (
|
|
1220
|
+
// Consider using the new LOOKUP_TABLE if its address is different...
|
|
1221
|
+
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
|
|
1222
|
+
(addressComparator || (addressComparator = getBase58EncodedAddressComparator()))(
|
|
1223
|
+
accountMeta.lookupTableAddress,
|
|
1224
|
+
entry.lookupTableAddress
|
|
1225
|
+
) < 0
|
|
1226
|
+
);
|
|
1227
|
+
if (shouldReplaceEntry) {
|
|
1228
|
+
return {
|
|
1229
|
+
[TYPE]: 1,
|
|
1230
|
+
...accountMeta,
|
|
1231
|
+
role: nextRole
|
|
1232
|
+
};
|
|
1233
|
+
}
|
|
1234
|
+
} else if (isSignerRole2(accountMeta.role)) {
|
|
1235
|
+
return {
|
|
1236
|
+
[TYPE]: 2,
|
|
1237
|
+
role: nextRole
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
1240
|
+
if (entry.role !== nextRole) {
|
|
1241
|
+
return {
|
|
1242
|
+
...entry,
|
|
1243
|
+
role: nextRole
|
|
1244
|
+
};
|
|
1245
|
+
} else {
|
|
1246
|
+
return entry;
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
case 2: {
|
|
1250
|
+
const nextRole = mergeRoles2(entry.role, accountMeta.role);
|
|
1251
|
+
if (
|
|
1252
|
+
// Check to see if this address represents a program that is invoked
|
|
1253
|
+
// in this transaction.
|
|
1254
|
+
addressesOfInvokedPrograms.has(account.address)
|
|
1255
|
+
) {
|
|
1256
|
+
if (isWritableRole2(accountMeta.role)) {
|
|
1257
|
+
throw new Error(
|
|
1258
|
+
`This transaction includes an address (\`${account.address}\`) which is both invoked and marked writable. Program addresses may not be writable.`
|
|
1259
|
+
);
|
|
1260
|
+
}
|
|
1261
|
+
if (entry.role !== nextRole) {
|
|
1262
|
+
return {
|
|
1263
|
+
...entry,
|
|
1264
|
+
role: nextRole
|
|
1265
|
+
};
|
|
1266
|
+
} else {
|
|
1267
|
+
return entry;
|
|
1268
|
+
}
|
|
1269
|
+
} else if ("lookupTableAddress" in accountMeta && // Static accounts can be 'upgraded' to lookup table accounts as
|
|
1270
|
+
// long as they are not require to sign the transaction.
|
|
1271
|
+
!isSignerRole2(entry.role)) {
|
|
1272
|
+
return {
|
|
1273
|
+
...accountMeta,
|
|
1274
|
+
[TYPE]: 1,
|
|
1275
|
+
role: nextRole
|
|
1276
|
+
};
|
|
1277
|
+
} else {
|
|
1278
|
+
if (entry.role !== nextRole) {
|
|
1279
|
+
return {
|
|
1280
|
+
...entry,
|
|
1281
|
+
role: nextRole
|
|
1282
|
+
};
|
|
1283
|
+
} else {
|
|
1284
|
+
return entry;
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
if ("lookupTableAddress" in accountMeta) {
|
|
1291
|
+
return {
|
|
1292
|
+
...accountMeta,
|
|
1293
|
+
[TYPE]: 1
|
|
1294
|
+
/* LOOKUP_TABLE */
|
|
1295
|
+
};
|
|
1296
|
+
} else {
|
|
1297
|
+
return {
|
|
1298
|
+
...accountMeta,
|
|
1299
|
+
[TYPE]: 2
|
|
1300
|
+
/* STATIC */
|
|
1301
|
+
};
|
|
1302
|
+
}
|
|
1303
|
+
});
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
return addressMap;
|
|
1307
|
+
}
|
|
1308
|
+
function getOrderedAccountsFromAddressMap(addressMap) {
|
|
1309
|
+
let addressComparator;
|
|
1310
|
+
const orderedAccounts = Object.entries(addressMap).sort(([leftAddress, leftEntry], [rightAddress, rightEntry]) => {
|
|
1311
|
+
if (leftEntry[TYPE] !== rightEntry[TYPE]) {
|
|
1312
|
+
if (leftEntry[TYPE] === 0) {
|
|
1313
|
+
return -1;
|
|
1314
|
+
} else if (rightEntry[TYPE] === 0) {
|
|
1315
|
+
return 1;
|
|
1316
|
+
} else if (leftEntry[TYPE] === 2) {
|
|
1317
|
+
return -1;
|
|
1318
|
+
} else if (rightEntry[TYPE] === 2) {
|
|
1319
|
+
return 1;
|
|
247
1320
|
}
|
|
248
1321
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
1322
|
+
const leftIsSigner = isSignerRole2(leftEntry.role);
|
|
1323
|
+
if (leftIsSigner !== isSignerRole2(rightEntry.role)) {
|
|
1324
|
+
return leftIsSigner ? -1 : 1;
|
|
1325
|
+
}
|
|
1326
|
+
const leftIsWritable = isWritableRole2(leftEntry.role);
|
|
1327
|
+
if (leftIsWritable !== isWritableRole2(rightEntry.role)) {
|
|
1328
|
+
return leftIsWritable ? -1 : 1;
|
|
1329
|
+
}
|
|
1330
|
+
addressComparator || (addressComparator = getBase58EncodedAddressComparator());
|
|
1331
|
+
if (leftEntry[TYPE] === 1 && rightEntry[TYPE] === 1 && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
|
|
1332
|
+
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
|
|
1333
|
+
} else {
|
|
1334
|
+
return addressComparator(leftAddress, rightAddress);
|
|
1335
|
+
}
|
|
1336
|
+
}).map(([address, addressMeta]) => ({
|
|
1337
|
+
address,
|
|
1338
|
+
...addressMeta
|
|
1339
|
+
}));
|
|
1340
|
+
return orderedAccounts;
|
|
1341
|
+
}
|
|
1342
|
+
function getCompiledAddressTableLookups(orderedAccounts) {
|
|
1343
|
+
var _a;
|
|
1344
|
+
const index = {};
|
|
1345
|
+
for (const account of orderedAccounts) {
|
|
1346
|
+
if (!("lookupTableAddress" in account)) {
|
|
1347
|
+
continue;
|
|
1348
|
+
}
|
|
1349
|
+
const entry = index[_a = account.lookupTableAddress] || (index[_a] = {
|
|
1350
|
+
readableIndices: [],
|
|
1351
|
+
writableIndices: []
|
|
1352
|
+
});
|
|
1353
|
+
if (account.role === AccountRole2.WRITABLE) {
|
|
1354
|
+
entry.writableIndices.push(account.addressIndex);
|
|
1355
|
+
} else {
|
|
1356
|
+
entry.readableIndices.push(account.addressIndex);
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
return Object.keys(index).sort(getBase58EncodedAddressComparator()).map((lookupTableAddress) => ({
|
|
1360
|
+
lookupTableAddress,
|
|
1361
|
+
...index[lookupTableAddress]
|
|
1362
|
+
}));
|
|
1363
|
+
}
|
|
1364
|
+
function getCompiledMessageHeader(orderedAccounts) {
|
|
1365
|
+
let numReadonlyNonSignerAccounts = 0;
|
|
1366
|
+
let numReadonlySignerAccounts = 0;
|
|
1367
|
+
let numSignerAccounts = 0;
|
|
1368
|
+
for (const account of orderedAccounts) {
|
|
1369
|
+
if ("lookupTableAddress" in account) {
|
|
1370
|
+
break;
|
|
1371
|
+
}
|
|
1372
|
+
const accountIsWritable = isWritableRole2(account.role);
|
|
1373
|
+
if (isSignerRole2(account.role)) {
|
|
1374
|
+
numSignerAccounts++;
|
|
1375
|
+
if (!accountIsWritable) {
|
|
1376
|
+
numReadonlySignerAccounts++;
|
|
253
1377
|
}
|
|
1378
|
+
} else if (!accountIsWritable) {
|
|
1379
|
+
numReadonlyNonSignerAccounts++;
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
return {
|
|
1383
|
+
numReadonlyNonSignerAccounts,
|
|
1384
|
+
numReadonlySignerAccounts,
|
|
1385
|
+
numSignerAccounts
|
|
1386
|
+
};
|
|
1387
|
+
}
|
|
1388
|
+
function getAccountIndex(orderedAccounts) {
|
|
1389
|
+
const out = {};
|
|
1390
|
+
for (const [index, account] of orderedAccounts.entries()) {
|
|
1391
|
+
out[account.address] = index;
|
|
1392
|
+
}
|
|
1393
|
+
return out;
|
|
1394
|
+
}
|
|
1395
|
+
function getCompiledInstructions(instructions, orderedAccounts) {
|
|
1396
|
+
const accountIndex = getAccountIndex(orderedAccounts);
|
|
1397
|
+
return instructions.map(({ accounts, data, programAddress }) => {
|
|
1398
|
+
return {
|
|
1399
|
+
programAddressIndex: accountIndex[programAddress],
|
|
1400
|
+
...accounts ? { accountIndices: accounts.map(({ address }) => accountIndex[address]) } : null,
|
|
1401
|
+
...data ? { data } : null
|
|
254
1402
|
};
|
|
1403
|
+
});
|
|
1404
|
+
}
|
|
1405
|
+
function getCompiledLifetimeToken(lifetimeConstraint) {
|
|
1406
|
+
if ("nonce" in lifetimeConstraint) {
|
|
1407
|
+
return lifetimeConstraint.nonce;
|
|
255
1408
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
)
|
|
271
|
-
|
|
1409
|
+
return lifetimeConstraint.blockhash;
|
|
1410
|
+
}
|
|
1411
|
+
function getCompiledStaticAccounts(orderedAccounts) {
|
|
1412
|
+
const firstLookupTableAccountIndex = orderedAccounts.findIndex((account) => "lookupTableAddress" in account);
|
|
1413
|
+
const orderedStaticAccounts = firstLookupTableAccountIndex === -1 ? orderedAccounts : orderedAccounts.slice(0, firstLookupTableAccountIndex);
|
|
1414
|
+
return orderedStaticAccounts.map(({ address }) => address);
|
|
1415
|
+
}
|
|
1416
|
+
function compileMessage(transaction) {
|
|
1417
|
+
const addressMap = getAddressMapFromInstructions(transaction.feePayer, transaction.instructions);
|
|
1418
|
+
const orderedAccounts = getOrderedAccountsFromAddressMap(addressMap);
|
|
1419
|
+
return {
|
|
1420
|
+
...transaction.version !== "legacy" ? { addressTableLookups: getCompiledAddressTableLookups(orderedAccounts) } : null,
|
|
1421
|
+
header: getCompiledMessageHeader(orderedAccounts),
|
|
1422
|
+
instructions: getCompiledInstructions(transaction.instructions, orderedAccounts),
|
|
1423
|
+
lifetimeToken: getCompiledLifetimeToken(transaction.lifetimeConstraint),
|
|
1424
|
+
staticAccounts: getCompiledStaticAccounts(orderedAccounts),
|
|
1425
|
+
version: transaction.version
|
|
1426
|
+
};
|
|
1427
|
+
}
|
|
1428
|
+
function getAddressTableLookupCodec() {
|
|
1429
|
+
return struct(
|
|
1430
|
+
[
|
|
1431
|
+
[
|
|
1432
|
+
"lookupTableAddress",
|
|
1433
|
+
getBase58EncodedAddressCodec(
|
|
1434
|
+
{
|
|
1435
|
+
description: "The address of the address lookup table account from which instruction addresses should be looked up"
|
|
1436
|
+
}
|
|
1437
|
+
)
|
|
1438
|
+
],
|
|
1439
|
+
[
|
|
1440
|
+
"writableIndices",
|
|
1441
|
+
array(u8(), {
|
|
1442
|
+
...{
|
|
1443
|
+
description: "The indices of the accounts in the lookup table that should be loaded as writeable"
|
|
1444
|
+
} ,
|
|
1445
|
+
size: shortU16()
|
|
1446
|
+
})
|
|
1447
|
+
],
|
|
1448
|
+
[
|
|
1449
|
+
"readableIndices",
|
|
1450
|
+
array(u8(), {
|
|
1451
|
+
...{
|
|
1452
|
+
description: "The indices of the accounts in the lookup table that should be loaded as read-only"
|
|
1453
|
+
} ,
|
|
1454
|
+
size: shortU16()
|
|
1455
|
+
})
|
|
1456
|
+
]
|
|
1457
|
+
],
|
|
1458
|
+
{
|
|
1459
|
+
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"
|
|
1460
|
+
}
|
|
1461
|
+
);
|
|
1462
|
+
}
|
|
1463
|
+
function getMessageHeaderCodec() {
|
|
1464
|
+
return struct(
|
|
1465
|
+
[
|
|
1466
|
+
[
|
|
1467
|
+
"numSignerAccounts",
|
|
1468
|
+
u8(
|
|
1469
|
+
{
|
|
1470
|
+
description: "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction"
|
|
1471
|
+
}
|
|
1472
|
+
)
|
|
1473
|
+
],
|
|
1474
|
+
[
|
|
1475
|
+
"numReadonlySignerAccounts",
|
|
1476
|
+
u8(
|
|
1477
|
+
{
|
|
1478
|
+
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"
|
|
1479
|
+
}
|
|
1480
|
+
)
|
|
1481
|
+
],
|
|
1482
|
+
[
|
|
1483
|
+
"numReadonlyNonSignerAccounts",
|
|
1484
|
+
u8(
|
|
1485
|
+
{
|
|
1486
|
+
description: "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable"
|
|
1487
|
+
}
|
|
1488
|
+
)
|
|
1489
|
+
]
|
|
1490
|
+
],
|
|
1491
|
+
{
|
|
1492
|
+
description: "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses"
|
|
1493
|
+
}
|
|
1494
|
+
);
|
|
1495
|
+
}
|
|
1496
|
+
function getInstructionCodec() {
|
|
1497
|
+
return mapSerializer(
|
|
1498
|
+
struct([
|
|
1499
|
+
[
|
|
1500
|
+
"programAddressIndex",
|
|
1501
|
+
u8(
|
|
1502
|
+
{
|
|
1503
|
+
description: "The index of the program being called, according to the well-ordered accounts list for this transaction"
|
|
1504
|
+
}
|
|
1505
|
+
)
|
|
1506
|
+
],
|
|
1507
|
+
[
|
|
1508
|
+
"accountIndices",
|
|
1509
|
+
array(
|
|
1510
|
+
u8({
|
|
1511
|
+
description: "The index of an account, according to the well-ordered accounts list for this transaction"
|
|
1512
|
+
}),
|
|
1513
|
+
{
|
|
1514
|
+
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" ,
|
|
1515
|
+
size: shortU16()
|
|
1516
|
+
}
|
|
1517
|
+
)
|
|
1518
|
+
],
|
|
1519
|
+
[
|
|
1520
|
+
"data",
|
|
1521
|
+
bytes({
|
|
1522
|
+
description: "An optional buffer of data passed to the instruction" ,
|
|
1523
|
+
size: shortU16()
|
|
1524
|
+
})
|
|
1525
|
+
]
|
|
1526
|
+
]),
|
|
1527
|
+
(value) => {
|
|
1528
|
+
if (value.accountIndices !== void 0 && value.data !== void 0) {
|
|
1529
|
+
return value;
|
|
1530
|
+
}
|
|
1531
|
+
return {
|
|
1532
|
+
...value,
|
|
1533
|
+
accountIndices: value.accountIndices ?? [],
|
|
1534
|
+
data: value.data ?? new Uint8Array(0)
|
|
1535
|
+
};
|
|
1536
|
+
},
|
|
1537
|
+
(value) => {
|
|
1538
|
+
if (value.accountIndices.length && value.data.byteLength) {
|
|
1539
|
+
return value;
|
|
1540
|
+
}
|
|
1541
|
+
const { accountIndices, data, ...rest } = value;
|
|
1542
|
+
return {
|
|
1543
|
+
...rest,
|
|
1544
|
+
...accountIndices.length ? { accountIndices } : null,
|
|
1545
|
+
...data.byteLength ? { data } : null
|
|
1546
|
+
};
|
|
272
1547
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
1548
|
+
);
|
|
1549
|
+
}
|
|
1550
|
+
function getError(type, name) {
|
|
1551
|
+
const functionSuffix = name + type[0].toUpperCase() + type.slice(1);
|
|
1552
|
+
return new Error(
|
|
1553
|
+
`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}`
|
|
1554
|
+
);
|
|
1555
|
+
}
|
|
1556
|
+
function getUnimplementedDecoder(name) {
|
|
1557
|
+
return () => {
|
|
1558
|
+
throw getError("decoder", name);
|
|
1559
|
+
};
|
|
1560
|
+
}
|
|
1561
|
+
var VERSION_FLAG_MASK = 128;
|
|
1562
|
+
var BASE_CONFIG = {
|
|
1563
|
+
description: "A single byte that encodes the version of the transaction" ,
|
|
1564
|
+
fixedSize: null,
|
|
1565
|
+
maxSize: 1
|
|
1566
|
+
};
|
|
1567
|
+
function deserialize(bytes3, offset = 0) {
|
|
1568
|
+
const firstByte = bytes3[offset];
|
|
1569
|
+
if ((firstByte & VERSION_FLAG_MASK) === 0) {
|
|
1570
|
+
return ["legacy", offset];
|
|
1571
|
+
} else {
|
|
1572
|
+
const version = firstByte ^ VERSION_FLAG_MASK;
|
|
1573
|
+
return [version, offset + 1];
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
function serialize(value) {
|
|
1577
|
+
if (value === "legacy") {
|
|
1578
|
+
return new Uint8Array();
|
|
1579
|
+
}
|
|
1580
|
+
if (value < 0 || value > 127) {
|
|
1581
|
+
throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
|
|
1582
|
+
}
|
|
1583
|
+
return new Uint8Array([value | VERSION_FLAG_MASK]);
|
|
1584
|
+
}
|
|
1585
|
+
function getTransactionVersionCodec() {
|
|
1586
|
+
return {
|
|
1587
|
+
...BASE_CONFIG,
|
|
1588
|
+
deserialize,
|
|
1589
|
+
serialize
|
|
1590
|
+
};
|
|
1591
|
+
}
|
|
1592
|
+
var BASE_CONFIG2 = {
|
|
1593
|
+
description: "The wire format of a Solana transaction message" ,
|
|
1594
|
+
fixedSize: null,
|
|
1595
|
+
maxSize: null
|
|
1596
|
+
};
|
|
1597
|
+
function serialize2(compiledMessage) {
|
|
1598
|
+
if (compiledMessage.version === "legacy") {
|
|
1599
|
+
return struct(getPreludeStructSerializerTuple()).serialize(compiledMessage);
|
|
1600
|
+
} else {
|
|
1601
|
+
return mapSerializer(
|
|
1602
|
+
struct([
|
|
1603
|
+
...getPreludeStructSerializerTuple(),
|
|
1604
|
+
["addressTableLookups", getAddressTableLookupsSerializer()]
|
|
1605
|
+
]),
|
|
1606
|
+
(value) => {
|
|
1607
|
+
if (value.version === "legacy") {
|
|
1608
|
+
return value;
|
|
1609
|
+
}
|
|
1610
|
+
return {
|
|
1611
|
+
...value,
|
|
1612
|
+
addressTableLookups: value.addressTableLookups ?? []
|
|
1613
|
+
};
|
|
1614
|
+
}
|
|
1615
|
+
).serialize(compiledMessage);
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
function getPreludeStructSerializerTuple() {
|
|
1619
|
+
return [
|
|
1620
|
+
["version", getTransactionVersionCodec()],
|
|
1621
|
+
["header", getMessageHeaderCodec()],
|
|
1622
|
+
[
|
|
1623
|
+
"staticAccounts",
|
|
1624
|
+
array(getBase58EncodedAddressCodec(), {
|
|
1625
|
+
description: "A compact-array of static account addresses belonging to this transaction" ,
|
|
1626
|
+
size: shortU16()
|
|
1627
|
+
})
|
|
1628
|
+
],
|
|
1629
|
+
[
|
|
1630
|
+
"lifetimeToken",
|
|
1631
|
+
string({
|
|
1632
|
+
description: "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" ,
|
|
1633
|
+
encoding: base58,
|
|
1634
|
+
size: 32
|
|
1635
|
+
})
|
|
1636
|
+
],
|
|
1637
|
+
[
|
|
1638
|
+
"instructions",
|
|
1639
|
+
array(getInstructionCodec(), {
|
|
1640
|
+
description: "A compact-array of instructions belonging to this transaction" ,
|
|
1641
|
+
size: shortU16()
|
|
1642
|
+
})
|
|
1643
|
+
]
|
|
1644
|
+
];
|
|
1645
|
+
}
|
|
1646
|
+
function getAddressTableLookupsSerializer() {
|
|
1647
|
+
return array(getAddressTableLookupCodec(), {
|
|
1648
|
+
...{ description: "A compact array of address table lookups belonging to this transaction" } ,
|
|
1649
|
+
size: shortU16()
|
|
1650
|
+
});
|
|
1651
|
+
}
|
|
1652
|
+
function getCompiledMessageEncoder() {
|
|
1653
|
+
return {
|
|
1654
|
+
...BASE_CONFIG2,
|
|
1655
|
+
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
1656
|
+
serialize: serialize2
|
|
1657
|
+
};
|
|
1658
|
+
}
|
|
1659
|
+
async function getCompiledMessageSignature(message, secretKey) {
|
|
1660
|
+
const wireMessageBytes = getCompiledMessageEncoder().serialize(message);
|
|
1661
|
+
const signature = await signBytes(secretKey, wireMessageBytes);
|
|
1662
|
+
return signature;
|
|
1663
|
+
}
|
|
1664
|
+
async function signTransaction(keyPair, transaction) {
|
|
1665
|
+
const compiledMessage = compileMessage(transaction);
|
|
1666
|
+
const [signerPublicKey, signature] = await Promise.all([
|
|
1667
|
+
getAddressFromPublicKey(keyPair.publicKey),
|
|
1668
|
+
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
1669
|
+
]);
|
|
1670
|
+
const nextSignatures = {
|
|
1671
|
+
..."signatures" in transaction ? transaction.signatures : null,
|
|
1672
|
+
...{ [signerPublicKey]: signature }
|
|
1673
|
+
};
|
|
1674
|
+
const out = {
|
|
1675
|
+
...transaction,
|
|
1676
|
+
signatures: nextSignatures
|
|
1677
|
+
};
|
|
1678
|
+
Object.freeze(out);
|
|
1679
|
+
return out;
|
|
1680
|
+
}
|
|
1681
|
+
function getCompiledTransaction(transaction) {
|
|
1682
|
+
const compiledMessage = compileMessage(transaction);
|
|
1683
|
+
let signatures;
|
|
1684
|
+
if ("signatures" in transaction) {
|
|
1685
|
+
signatures = [];
|
|
1686
|
+
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
1687
|
+
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
277
1688
|
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
cause: e2
|
|
281
|
-
});
|
|
1689
|
+
} else {
|
|
1690
|
+
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
282
1691
|
}
|
|
1692
|
+
return {
|
|
1693
|
+
compiledMessage,
|
|
1694
|
+
signatures
|
|
1695
|
+
};
|
|
283
1696
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
1697
|
+
var BASE_CONFIG3 = {
|
|
1698
|
+
description: "The wire format of a Solana transaction" ,
|
|
1699
|
+
fixedSize: null,
|
|
1700
|
+
maxSize: null
|
|
1701
|
+
};
|
|
1702
|
+
function serialize3(transaction) {
|
|
1703
|
+
const compiledTransaction = getCompiledTransaction(transaction);
|
|
1704
|
+
return struct([
|
|
1705
|
+
[
|
|
1706
|
+
"signatures",
|
|
1707
|
+
array(bytes({ size: 64 }), {
|
|
1708
|
+
...{ description: "A compact array of 64-byte, base-64 encoded Ed25519 signatures" } ,
|
|
1709
|
+
size: shortU16()
|
|
1710
|
+
})
|
|
1711
|
+
],
|
|
1712
|
+
["compiledMessage", getCompiledMessageEncoder()]
|
|
1713
|
+
]).serialize(compiledTransaction);
|
|
1714
|
+
}
|
|
1715
|
+
function getTransactionEncoder() {
|
|
1716
|
+
return {
|
|
1717
|
+
...BASE_CONFIG3,
|
|
1718
|
+
deserialize: getUnimplementedDecoder("CompiledMessage"),
|
|
1719
|
+
serialize: serialize3
|
|
1720
|
+
};
|
|
1721
|
+
}
|
|
1722
|
+
function getBase64EncodedWireTransaction(transaction) {
|
|
1723
|
+
const wireTransactionBytes = getTransactionEncoder().serialize(transaction);
|
|
1724
|
+
{
|
|
1725
|
+
return btoa(String.fromCharCode(...wireTransactionBytes));
|
|
1726
|
+
}
|
|
293
1727
|
}
|
|
294
1728
|
|
|
295
1729
|
// src/rpc.ts
|
|
@@ -297,7 +1731,6 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
297
1731
|
|
|
298
1732
|
// ../rpc-core/dist/index.browser.js
|
|
299
1733
|
init_env_shim();
|
|
300
|
-
__toESM(require_bs58(), 1);
|
|
301
1734
|
function visitNode(value, keyPath, onIntegerOverflow) {
|
|
302
1735
|
if (Array.isArray(value)) {
|
|
303
1736
|
return value.map(
|
|
@@ -324,32 +1757,246 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
324
1757
|
return visitNode(params, [], onIntegerOverflow);
|
|
325
1758
|
}
|
|
326
1759
|
var KEYPATH_WILDCARD = {};
|
|
327
|
-
var
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
1760
|
+
var memoizedNotificationKeypaths;
|
|
1761
|
+
var memoizedResponseKeypaths;
|
|
1762
|
+
function getAllowedNumericKeypathsForNotification() {
|
|
1763
|
+
if (!memoizedNotificationKeypaths) {
|
|
1764
|
+
memoizedNotificationKeypaths = {};
|
|
1765
|
+
}
|
|
1766
|
+
return memoizedNotificationKeypaths;
|
|
1767
|
+
}
|
|
1768
|
+
function getAllowedNumericKeypathsForResponse() {
|
|
1769
|
+
if (!memoizedResponseKeypaths) {
|
|
1770
|
+
const jsonParsedTokenAccountsConfigs = [
|
|
1771
|
+
// parsed Token/Token22 token account
|
|
1772
|
+
["data", "parsed", "info", "tokenAmount", "decimals"],
|
|
1773
|
+
["data", "parsed", "info", "tokenAmount", "uiAmount"],
|
|
1774
|
+
["data", "parsed", "info", "rentExemptReserve", "decimals"],
|
|
1775
|
+
["data", "parsed", "info", "rentExemptReserve", "uiAmount"],
|
|
1776
|
+
["data", "parsed", "info", "delegatedAmount", "decimals"],
|
|
1777
|
+
["data", "parsed", "info", "delegatedAmount", "uiAmount"],
|
|
1778
|
+
[
|
|
1779
|
+
"data",
|
|
1780
|
+
"parsed",
|
|
1781
|
+
"info",
|
|
1782
|
+
"extensions",
|
|
1783
|
+
KEYPATH_WILDCARD,
|
|
1784
|
+
"state",
|
|
1785
|
+
"olderTransferFee",
|
|
1786
|
+
"transferFeeBasisPoints"
|
|
1787
|
+
],
|
|
1788
|
+
[
|
|
1789
|
+
"data",
|
|
1790
|
+
"parsed",
|
|
1791
|
+
"info",
|
|
1792
|
+
"extensions",
|
|
1793
|
+
KEYPATH_WILDCARD,
|
|
1794
|
+
"state",
|
|
1795
|
+
"newerTransferFee",
|
|
1796
|
+
"transferFeeBasisPoints"
|
|
1797
|
+
],
|
|
1798
|
+
["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "preUpdateAverageRate"],
|
|
1799
|
+
["data", "parsed", "info", "extensions", KEYPATH_WILDCARD, "state", "currentRate"]
|
|
1800
|
+
];
|
|
1801
|
+
const jsonParsedAccountsConfigs = [
|
|
1802
|
+
...jsonParsedTokenAccountsConfigs,
|
|
1803
|
+
// parsed AddressTableLookup account
|
|
1804
|
+
["data", "parsed", "info", "lastExtendedSlotStartIndex"],
|
|
1805
|
+
// parsed Config account
|
|
1806
|
+
["data", "parsed", "info", "slashPenalty"],
|
|
1807
|
+
["data", "parsed", "info", "warmupCooldownRate"],
|
|
1808
|
+
// parsed Token/Token22 mint account
|
|
1809
|
+
["data", "parsed", "info", "decimals"],
|
|
1810
|
+
// parsed Token/Token22 multisig account
|
|
1811
|
+
["data", "parsed", "info", "numRequiredSigners"],
|
|
1812
|
+
["data", "parsed", "info", "numValidSigners"],
|
|
1813
|
+
// parsed Stake account
|
|
1814
|
+
["data", "parsed", "info", "stake", "delegation", "warmupCooldownRate"],
|
|
1815
|
+
// parsed Sysvar rent account
|
|
1816
|
+
["data", "parsed", "info", "exemptionThreshold"],
|
|
1817
|
+
["data", "parsed", "info", "burnPercent"],
|
|
1818
|
+
// parsed Vote account
|
|
1819
|
+
["data", "parsed", "info", "commission"],
|
|
1820
|
+
["data", "parsed", "info", "votes", KEYPATH_WILDCARD, "confirmationCount"]
|
|
1821
|
+
];
|
|
1822
|
+
memoizedResponseKeypaths = {
|
|
1823
|
+
getAccountInfo: jsonParsedAccountsConfigs.map((c) => ["value", ...c]),
|
|
1824
|
+
getBlock: [
|
|
1825
|
+
["blockTime"],
|
|
1826
|
+
["transactions", KEYPATH_WILDCARD, "meta", "preTokenBalances", KEYPATH_WILDCARD, "accountIndex"],
|
|
1827
|
+
[
|
|
1828
|
+
"transactions",
|
|
1829
|
+
KEYPATH_WILDCARD,
|
|
1830
|
+
"meta",
|
|
1831
|
+
"preTokenBalances",
|
|
1832
|
+
KEYPATH_WILDCARD,
|
|
1833
|
+
"uiTokenAmount",
|
|
1834
|
+
"decimals"
|
|
1835
|
+
],
|
|
1836
|
+
["transactions", KEYPATH_WILDCARD, "meta", "postTokenBalances", KEYPATH_WILDCARD, "accountIndex"],
|
|
1837
|
+
[
|
|
1838
|
+
"transactions",
|
|
1839
|
+
KEYPATH_WILDCARD,
|
|
1840
|
+
"meta",
|
|
1841
|
+
"postTokenBalances",
|
|
1842
|
+
KEYPATH_WILDCARD,
|
|
1843
|
+
"uiTokenAmount",
|
|
1844
|
+
"decimals"
|
|
1845
|
+
],
|
|
1846
|
+
["transactions", KEYPATH_WILDCARD, "meta", "rewards", KEYPATH_WILDCARD, "commission"],
|
|
1847
|
+
["transactions", KEYPATH_WILDCARD, "meta", "innerInstructions", KEYPATH_WILDCARD, "index"],
|
|
1848
|
+
[
|
|
1849
|
+
"transactions",
|
|
1850
|
+
KEYPATH_WILDCARD,
|
|
1851
|
+
"meta",
|
|
1852
|
+
"innerInstructions",
|
|
1853
|
+
KEYPATH_WILDCARD,
|
|
1854
|
+
"instructions",
|
|
1855
|
+
KEYPATH_WILDCARD,
|
|
1856
|
+
"programIdIndex"
|
|
1857
|
+
],
|
|
1858
|
+
[
|
|
1859
|
+
"transactions",
|
|
1860
|
+
KEYPATH_WILDCARD,
|
|
1861
|
+
"meta",
|
|
1862
|
+
"innerInstructions",
|
|
1863
|
+
KEYPATH_WILDCARD,
|
|
1864
|
+
"instructions",
|
|
1865
|
+
KEYPATH_WILDCARD,
|
|
1866
|
+
"accounts",
|
|
1867
|
+
KEYPATH_WILDCARD
|
|
1868
|
+
],
|
|
1869
|
+
[
|
|
1870
|
+
"transactions",
|
|
1871
|
+
KEYPATH_WILDCARD,
|
|
1872
|
+
"transaction",
|
|
1873
|
+
"message",
|
|
1874
|
+
"addressTableLookups",
|
|
1875
|
+
KEYPATH_WILDCARD,
|
|
1876
|
+
"writableIndexes",
|
|
1877
|
+
KEYPATH_WILDCARD
|
|
1878
|
+
],
|
|
1879
|
+
[
|
|
1880
|
+
"transactions",
|
|
1881
|
+
KEYPATH_WILDCARD,
|
|
1882
|
+
"transaction",
|
|
1883
|
+
"message",
|
|
1884
|
+
"addressTableLookups",
|
|
1885
|
+
KEYPATH_WILDCARD,
|
|
1886
|
+
"readonlyIndexes",
|
|
1887
|
+
KEYPATH_WILDCARD
|
|
1888
|
+
],
|
|
1889
|
+
[
|
|
1890
|
+
"transactions",
|
|
1891
|
+
KEYPATH_WILDCARD,
|
|
1892
|
+
"transaction",
|
|
1893
|
+
"message",
|
|
1894
|
+
"instructions",
|
|
1895
|
+
KEYPATH_WILDCARD,
|
|
1896
|
+
"programIdIndex"
|
|
1897
|
+
],
|
|
1898
|
+
[
|
|
1899
|
+
"transactions",
|
|
1900
|
+
KEYPATH_WILDCARD,
|
|
1901
|
+
"transaction",
|
|
1902
|
+
"message",
|
|
1903
|
+
"instructions",
|
|
1904
|
+
KEYPATH_WILDCARD,
|
|
1905
|
+
"accounts",
|
|
1906
|
+
KEYPATH_WILDCARD
|
|
1907
|
+
],
|
|
1908
|
+
["transactions", KEYPATH_WILDCARD, "transaction", "message", "header", "numReadonlySignedAccounts"],
|
|
1909
|
+
["transactions", KEYPATH_WILDCARD, "transaction", "message", "header", "numReadonlyUnsignedAccounts"],
|
|
1910
|
+
["transactions", KEYPATH_WILDCARD, "transaction", "message", "header", "numRequiredSignatures"],
|
|
1911
|
+
["rewards", KEYPATH_WILDCARD, "commission"]
|
|
1912
|
+
],
|
|
1913
|
+
getBlockTime: [[]],
|
|
1914
|
+
getClusterNodes: [
|
|
1915
|
+
[KEYPATH_WILDCARD, "featureSet"],
|
|
1916
|
+
[KEYPATH_WILDCARD, "shredVersion"]
|
|
1917
|
+
],
|
|
1918
|
+
getInflationGovernor: [["initial"], ["foundation"], ["foundationTerm"], ["taper"], ["terminal"]],
|
|
1919
|
+
getInflationRate: [["foundation"], ["total"], ["validator"]],
|
|
1920
|
+
getInflationReward: [[KEYPATH_WILDCARD, "commission"]],
|
|
1921
|
+
getMultipleAccounts: jsonParsedAccountsConfigs.map((c) => ["value", KEYPATH_WILDCARD, ...c]),
|
|
1922
|
+
getProgramAccounts: jsonParsedAccountsConfigs.flatMap((c) => [
|
|
1923
|
+
["value", KEYPATH_WILDCARD, "account", ...c],
|
|
1924
|
+
[KEYPATH_WILDCARD, "account", ...c]
|
|
1925
|
+
]),
|
|
1926
|
+
getRecentPerformanceSamples: [[KEYPATH_WILDCARD, "samplePeriodSecs"]],
|
|
1927
|
+
getTokenAccountBalance: [
|
|
1928
|
+
["value", "decimals"],
|
|
1929
|
+
["value", "uiAmount"]
|
|
1930
|
+
],
|
|
1931
|
+
getTokenAccountsByDelegate: jsonParsedTokenAccountsConfigs.map((c) => [
|
|
1932
|
+
"value",
|
|
1933
|
+
KEYPATH_WILDCARD,
|
|
1934
|
+
"account",
|
|
1935
|
+
...c
|
|
1936
|
+
]),
|
|
1937
|
+
getTokenAccountsByOwner: jsonParsedTokenAccountsConfigs.map((c) => [
|
|
1938
|
+
"value",
|
|
1939
|
+
KEYPATH_WILDCARD,
|
|
1940
|
+
"account",
|
|
1941
|
+
...c
|
|
1942
|
+
]),
|
|
1943
|
+
getTokenLargestAccounts: [
|
|
1944
|
+
["value", KEYPATH_WILDCARD, "decimals"],
|
|
1945
|
+
["value", KEYPATH_WILDCARD, "uiAmount"]
|
|
1946
|
+
],
|
|
1947
|
+
getTokenSupply: [
|
|
1948
|
+
["value", "decimals"],
|
|
1949
|
+
["value", "uiAmount"]
|
|
1950
|
+
],
|
|
1951
|
+
getTransaction: [
|
|
1952
|
+
["meta", "preTokenBalances", KEYPATH_WILDCARD, "accountIndex"],
|
|
1953
|
+
["meta", "preTokenBalances", KEYPATH_WILDCARD, "uiTokenAmount", "decimals"],
|
|
1954
|
+
["meta", "postTokenBalances", KEYPATH_WILDCARD, "accountIndex"],
|
|
1955
|
+
["meta", "postTokenBalances", KEYPATH_WILDCARD, "uiTokenAmount", "decimals"],
|
|
1956
|
+
["meta", "rewards", KEYPATH_WILDCARD, "commission"],
|
|
1957
|
+
["meta", "innerInstructions", KEYPATH_WILDCARD, "index"],
|
|
1958
|
+
["meta", "innerInstructions", KEYPATH_WILDCARD, "instructions", KEYPATH_WILDCARD, "programIdIndex"],
|
|
1959
|
+
[
|
|
1960
|
+
"meta",
|
|
1961
|
+
"innerInstructions",
|
|
1962
|
+
KEYPATH_WILDCARD,
|
|
1963
|
+
"instructions",
|
|
1964
|
+
KEYPATH_WILDCARD,
|
|
1965
|
+
"accounts",
|
|
1966
|
+
KEYPATH_WILDCARD
|
|
1967
|
+
],
|
|
1968
|
+
[
|
|
1969
|
+
"transaction",
|
|
1970
|
+
"message",
|
|
1971
|
+
"addressTableLookups",
|
|
1972
|
+
KEYPATH_WILDCARD,
|
|
1973
|
+
"writableIndexes",
|
|
1974
|
+
KEYPATH_WILDCARD
|
|
1975
|
+
],
|
|
1976
|
+
[
|
|
1977
|
+
"transaction",
|
|
1978
|
+
"message",
|
|
1979
|
+
"addressTableLookups",
|
|
1980
|
+
KEYPATH_WILDCARD,
|
|
1981
|
+
"readonlyIndexes",
|
|
1982
|
+
KEYPATH_WILDCARD
|
|
1983
|
+
],
|
|
1984
|
+
["transaction", "message", "instructions", KEYPATH_WILDCARD, "programIdIndex"],
|
|
1985
|
+
["transaction", "message", "instructions", KEYPATH_WILDCARD, "accounts", KEYPATH_WILDCARD],
|
|
1986
|
+
["transaction", "message", "header", "numReadonlySignedAccounts"],
|
|
1987
|
+
["transaction", "message", "header", "numReadonlyUnsignedAccounts"],
|
|
1988
|
+
["transaction", "message", "header", "numRequiredSignatures"]
|
|
1989
|
+
],
|
|
1990
|
+
getVersion: [["feature-set"]],
|
|
1991
|
+
getVoteAccounts: [
|
|
1992
|
+
["current", KEYPATH_WILDCARD, "commission"],
|
|
1993
|
+
["delinquent", KEYPATH_WILDCARD, "commission"]
|
|
1994
|
+
],
|
|
1995
|
+
simulateTransaction: jsonParsedAccountsConfigs.map((c) => ["value", "accounts", KEYPATH_WILDCARD, ...c])
|
|
1996
|
+
};
|
|
1997
|
+
}
|
|
1998
|
+
return memoizedResponseKeypaths;
|
|
1999
|
+
}
|
|
353
2000
|
function getNextAllowedKeypaths(keyPaths, property) {
|
|
354
2001
|
return keyPaths.filter((keyPath) => keyPath[0] === KEYPATH_WILDCARD && typeof property === "number" || keyPath[0] === property).map((keyPath) => keyPath.slice(1));
|
|
355
2002
|
}
|
|
@@ -368,14 +2015,19 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
368
2015
|
return out;
|
|
369
2016
|
} else if (typeof value === "number" && // The presence of an allowed keypath on the route to this value implies it's allowlisted;
|
|
370
2017
|
// Upcast the value to `bigint` unless an allowed keypath is present.
|
|
371
|
-
allowedKeypaths.length === 0
|
|
2018
|
+
allowedKeypaths.length === 0 && // Only try to upcast an Integer to `bigint`
|
|
2019
|
+
Number.isInteger(value)) {
|
|
372
2020
|
return BigInt(value);
|
|
373
2021
|
} else {
|
|
374
2022
|
return value;
|
|
375
2023
|
}
|
|
376
2024
|
}
|
|
377
2025
|
function patchResponseForSolanaLabsRpc(rawResponse, methodName) {
|
|
378
|
-
const allowedKeypaths = methodName ?
|
|
2026
|
+
const allowedKeypaths = methodName ? getAllowedNumericKeypathsForResponse()[methodName] : void 0;
|
|
2027
|
+
return visitNode2(rawResponse, allowedKeypaths ?? []);
|
|
2028
|
+
}
|
|
2029
|
+
function patchResponseForSolanaLabsRpcSubscriptions(rawResponse, methodName) {
|
|
2030
|
+
const allowedKeypaths = methodName ? getAllowedNumericKeypathsForNotification()[methodName] : void 0;
|
|
379
2031
|
return visitNode2(rawResponse, allowedKeypaths ?? []);
|
|
380
2032
|
}
|
|
381
2033
|
function createSolanaRpcApi(config) {
|
|
@@ -404,6 +2056,33 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
404
2056
|
}
|
|
405
2057
|
});
|
|
406
2058
|
}
|
|
2059
|
+
function createSolanaRpcSubscriptionsApi(config) {
|
|
2060
|
+
return new Proxy({}, {
|
|
2061
|
+
defineProperty() {
|
|
2062
|
+
return false;
|
|
2063
|
+
},
|
|
2064
|
+
deleteProperty() {
|
|
2065
|
+
return false;
|
|
2066
|
+
},
|
|
2067
|
+
get(...args) {
|
|
2068
|
+
const [_, p] = args;
|
|
2069
|
+
const notificationName = p.toString();
|
|
2070
|
+
return function(...rawParams) {
|
|
2071
|
+
const handleIntegerOverflow = config?.onIntegerOverflow;
|
|
2072
|
+
const params = patchParamsForSolanaLabsRpc(
|
|
2073
|
+
rawParams,
|
|
2074
|
+
handleIntegerOverflow ? (keyPath, value) => handleIntegerOverflow(notificationName, keyPath, value) : void 0
|
|
2075
|
+
);
|
|
2076
|
+
return {
|
|
2077
|
+
params,
|
|
2078
|
+
responseProcessor: (rawResponse) => patchResponseForSolanaLabsRpcSubscriptions(rawResponse, notificationName),
|
|
2079
|
+
subscribeMethodName: notificationName.replace(/Notifications$/, "Subscribe"),
|
|
2080
|
+
unsubscribeMethodName: notificationName.replace(/Notifications$/, "Unsubscribe")
|
|
2081
|
+
};
|
|
2082
|
+
};
|
|
2083
|
+
}
|
|
2084
|
+
});
|
|
2085
|
+
}
|
|
407
2086
|
|
|
408
2087
|
// ../rpc-transport/dist/index.browser.js
|
|
409
2088
|
init_env_shim();
|
|
@@ -470,6 +2149,100 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
470
2149
|
function createJsonRpc(rpcConfig) {
|
|
471
2150
|
return makeProxy(rpcConfig);
|
|
472
2151
|
}
|
|
2152
|
+
function registerIterableCleanup(iterable, cleanupFn) {
|
|
2153
|
+
(async () => {
|
|
2154
|
+
try {
|
|
2155
|
+
for await (const _ of iterable)
|
|
2156
|
+
;
|
|
2157
|
+
} catch {
|
|
2158
|
+
} finally {
|
|
2159
|
+
cleanupFn();
|
|
2160
|
+
}
|
|
2161
|
+
})();
|
|
2162
|
+
}
|
|
2163
|
+
function createPendingRpcSubscription(rpcConfig, { params, subscribeMethodName, unsubscribeMethodName, responseProcessor }) {
|
|
2164
|
+
return {
|
|
2165
|
+
async subscribe(options) {
|
|
2166
|
+
options?.abortSignal?.throwIfAborted();
|
|
2167
|
+
let subscriptionId;
|
|
2168
|
+
function handleCleanup() {
|
|
2169
|
+
if (subscriptionId !== void 0) {
|
|
2170
|
+
const payload = createJsonRpcMessage(unsubscribeMethodName, [subscriptionId]);
|
|
2171
|
+
connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload).finally(() => {
|
|
2172
|
+
connectionAbortController.abort();
|
|
2173
|
+
});
|
|
2174
|
+
} else {
|
|
2175
|
+
connectionAbortController.abort();
|
|
2176
|
+
}
|
|
2177
|
+
}
|
|
2178
|
+
options?.abortSignal?.addEventListener("abort", handleCleanup);
|
|
2179
|
+
const connectionAbortController = new AbortController();
|
|
2180
|
+
const subscribeMessage = createJsonRpcMessage(subscribeMethodName, params);
|
|
2181
|
+
const connection = await rpcConfig.transport({
|
|
2182
|
+
payload: subscribeMessage,
|
|
2183
|
+
signal: connectionAbortController.signal
|
|
2184
|
+
});
|
|
2185
|
+
function handleConnectionCleanup() {
|
|
2186
|
+
options?.abortSignal?.removeEventListener("abort", handleCleanup);
|
|
2187
|
+
}
|
|
2188
|
+
registerIterableCleanup(connection, handleConnectionCleanup);
|
|
2189
|
+
for await (const message of connection) {
|
|
2190
|
+
if ("id" in message && message.id === subscribeMessage.id) {
|
|
2191
|
+
if ("error" in message) {
|
|
2192
|
+
throw new SolanaJsonRpcError(message.error);
|
|
2193
|
+
} else {
|
|
2194
|
+
subscriptionId = message.result;
|
|
2195
|
+
break;
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2198
|
+
}
|
|
2199
|
+
if (subscriptionId == null) {
|
|
2200
|
+
throw new Error("Failed to obtain a subscription id from the server");
|
|
2201
|
+
}
|
|
2202
|
+
return {
|
|
2203
|
+
async *[Symbol.asyncIterator]() {
|
|
2204
|
+
for await (const message of connection) {
|
|
2205
|
+
if (!("params" in message) || message.params.subscription !== subscriptionId) {
|
|
2206
|
+
continue;
|
|
2207
|
+
}
|
|
2208
|
+
const notification = message.params.result;
|
|
2209
|
+
yield responseProcessor ? responseProcessor(notification) : notification;
|
|
2210
|
+
}
|
|
2211
|
+
}
|
|
2212
|
+
};
|
|
2213
|
+
}
|
|
2214
|
+
};
|
|
2215
|
+
}
|
|
2216
|
+
function makeProxy2(rpcConfig) {
|
|
2217
|
+
return new Proxy(rpcConfig.api, {
|
|
2218
|
+
defineProperty() {
|
|
2219
|
+
return false;
|
|
2220
|
+
},
|
|
2221
|
+
deleteProperty() {
|
|
2222
|
+
return false;
|
|
2223
|
+
},
|
|
2224
|
+
get(target, p, receiver) {
|
|
2225
|
+
return function(...rawParams) {
|
|
2226
|
+
const methodName = p.toString();
|
|
2227
|
+
const createRpcSubscription = Reflect.get(target, methodName, receiver);
|
|
2228
|
+
if (p.toString().endsWith("Notifications") === false && !createRpcSubscription) {
|
|
2229
|
+
throw new Error(
|
|
2230
|
+
"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."
|
|
2231
|
+
);
|
|
2232
|
+
}
|
|
2233
|
+
const newRequest = createRpcSubscription ? createRpcSubscription(...rawParams) : {
|
|
2234
|
+
params: rawParams,
|
|
2235
|
+
subscribeMethodName: methodName.replace(/Notifications$/, "Subscribe"),
|
|
2236
|
+
unsubscribeMethodName: methodName.replace(/Notifications$/, "Unsubscribe")
|
|
2237
|
+
};
|
|
2238
|
+
return createPendingRpcSubscription(rpcConfig, newRequest);
|
|
2239
|
+
};
|
|
2240
|
+
}
|
|
2241
|
+
});
|
|
2242
|
+
}
|
|
2243
|
+
function createJsonSubscriptionRpc(rpcConfig) {
|
|
2244
|
+
return makeProxy2(rpcConfig);
|
|
2245
|
+
}
|
|
473
2246
|
var e = globalThis.fetch;
|
|
474
2247
|
var SolanaHttpError = class extends Error {
|
|
475
2248
|
constructor(details) {
|
|
@@ -568,6 +2341,166 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
568
2341
|
return await response.json();
|
|
569
2342
|
};
|
|
570
2343
|
}
|
|
2344
|
+
var e2 = globalThis.WebSocket;
|
|
2345
|
+
async function createWebSocketConnection({
|
|
2346
|
+
sendBufferHighWatermark,
|
|
2347
|
+
signal,
|
|
2348
|
+
url
|
|
2349
|
+
}) {
|
|
2350
|
+
return new Promise((resolve, reject) => {
|
|
2351
|
+
signal.addEventListener("abort", handleAbort, { once: true });
|
|
2352
|
+
const iteratorState = /* @__PURE__ */ new Map();
|
|
2353
|
+
function handleAbort() {
|
|
2354
|
+
if (webSocket.readyState !== e2.CLOSED && webSocket.readyState !== e2.CLOSING) {
|
|
2355
|
+
webSocket.close(1e3);
|
|
2356
|
+
}
|
|
2357
|
+
}
|
|
2358
|
+
function handleClose(ev) {
|
|
2359
|
+
bufferDrainWatcher?.onCancel();
|
|
2360
|
+
signal.removeEventListener("abort", handleAbort);
|
|
2361
|
+
webSocket.removeEventListener("close", handleClose);
|
|
2362
|
+
webSocket.removeEventListener("error", handleError);
|
|
2363
|
+
webSocket.removeEventListener("open", handleOpen);
|
|
2364
|
+
webSocket.removeEventListener("message", handleMessage);
|
|
2365
|
+
iteratorState.forEach((state, iteratorKey) => {
|
|
2366
|
+
if (state.__hasPolled) {
|
|
2367
|
+
const { onError } = state;
|
|
2368
|
+
iteratorState.delete(iteratorKey);
|
|
2369
|
+
onError(ev);
|
|
2370
|
+
} else {
|
|
2371
|
+
iteratorState.delete(iteratorKey);
|
|
2372
|
+
}
|
|
2373
|
+
});
|
|
2374
|
+
}
|
|
2375
|
+
function handleError(ev) {
|
|
2376
|
+
if (!hasConnected) {
|
|
2377
|
+
reject(
|
|
2378
|
+
// TODO: Coded error
|
|
2379
|
+
new Error("WebSocket failed to connect", { cause: ev })
|
|
2380
|
+
);
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2383
|
+
let hasConnected = false;
|
|
2384
|
+
let bufferDrainWatcher;
|
|
2385
|
+
function handleOpen() {
|
|
2386
|
+
hasConnected = true;
|
|
2387
|
+
resolve({
|
|
2388
|
+
async send(payload) {
|
|
2389
|
+
const message = JSON.stringify(payload);
|
|
2390
|
+
if (!bufferDrainWatcher && webSocket.readyState === e2.OPEN && webSocket.bufferedAmount > sendBufferHighWatermark) {
|
|
2391
|
+
let onCancel;
|
|
2392
|
+
const promise = new Promise((resolve2, reject2) => {
|
|
2393
|
+
const intervalId = setInterval(() => {
|
|
2394
|
+
if (webSocket.readyState !== e2.OPEN || !(webSocket.bufferedAmount > sendBufferHighWatermark)) {
|
|
2395
|
+
clearInterval(intervalId);
|
|
2396
|
+
bufferDrainWatcher = void 0;
|
|
2397
|
+
resolve2();
|
|
2398
|
+
}
|
|
2399
|
+
}, 16);
|
|
2400
|
+
onCancel = () => {
|
|
2401
|
+
bufferDrainWatcher = void 0;
|
|
2402
|
+
clearInterval(intervalId);
|
|
2403
|
+
reject2(
|
|
2404
|
+
// TODO: Coded error
|
|
2405
|
+
new Error("WebSocket was closed before payload could be sent")
|
|
2406
|
+
);
|
|
2407
|
+
};
|
|
2408
|
+
});
|
|
2409
|
+
bufferDrainWatcher = {
|
|
2410
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2411
|
+
// @ts-ignore
|
|
2412
|
+
onCancel,
|
|
2413
|
+
promise
|
|
2414
|
+
};
|
|
2415
|
+
}
|
|
2416
|
+
if (bufferDrainWatcher) {
|
|
2417
|
+
await bufferDrainWatcher.promise;
|
|
2418
|
+
}
|
|
2419
|
+
webSocket.send(message);
|
|
2420
|
+
},
|
|
2421
|
+
async *[Symbol.asyncIterator]() {
|
|
2422
|
+
const iteratorKey = Symbol();
|
|
2423
|
+
iteratorState.set(iteratorKey, { __hasPolled: false, queuedMessages: [] });
|
|
2424
|
+
try {
|
|
2425
|
+
while (true) {
|
|
2426
|
+
const state = iteratorState.get(iteratorKey);
|
|
2427
|
+
if (!state) {
|
|
2428
|
+
throw new Error("Invariant: WebSocket message iterator is missing state storage");
|
|
2429
|
+
}
|
|
2430
|
+
if (state.__hasPolled) {
|
|
2431
|
+
throw new Error(
|
|
2432
|
+
"Invariant: WebSocket message iterator state is corrupt; iterated without first resolving existing message promise"
|
|
2433
|
+
);
|
|
2434
|
+
}
|
|
2435
|
+
const queuedMessages = state.queuedMessages;
|
|
2436
|
+
if (queuedMessages.length) {
|
|
2437
|
+
state.queuedMessages = [];
|
|
2438
|
+
yield* queuedMessages;
|
|
2439
|
+
} else {
|
|
2440
|
+
try {
|
|
2441
|
+
yield await new Promise((onMessage, onError) => {
|
|
2442
|
+
iteratorState.set(iteratorKey, {
|
|
2443
|
+
__hasPolled: true,
|
|
2444
|
+
onError,
|
|
2445
|
+
onMessage
|
|
2446
|
+
});
|
|
2447
|
+
});
|
|
2448
|
+
} catch (e3) {
|
|
2449
|
+
if (e3 !== null && typeof e3 === "object" && "type" in e3 && e3.type === "close" && "wasClean" in e3 && e3.wasClean) {
|
|
2450
|
+
return;
|
|
2451
|
+
} else {
|
|
2452
|
+
throw new Error("WebSocket connection closed", { cause: e3 });
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2457
|
+
} finally {
|
|
2458
|
+
iteratorState.delete(iteratorKey);
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
});
|
|
2462
|
+
}
|
|
2463
|
+
function handleMessage({ data }) {
|
|
2464
|
+
const message = JSON.parse(data);
|
|
2465
|
+
iteratorState.forEach((state, iteratorKey) => {
|
|
2466
|
+
if (state.__hasPolled) {
|
|
2467
|
+
const { onMessage } = state;
|
|
2468
|
+
iteratorState.set(iteratorKey, { __hasPolled: false, queuedMessages: [] });
|
|
2469
|
+
onMessage(message);
|
|
2470
|
+
} else {
|
|
2471
|
+
state.queuedMessages.push(message);
|
|
2472
|
+
}
|
|
2473
|
+
});
|
|
2474
|
+
}
|
|
2475
|
+
const webSocket = new e2(url);
|
|
2476
|
+
webSocket.addEventListener("close", handleClose);
|
|
2477
|
+
webSocket.addEventListener("error", handleError);
|
|
2478
|
+
webSocket.addEventListener("open", handleOpen);
|
|
2479
|
+
webSocket.addEventListener("message", handleMessage);
|
|
2480
|
+
});
|
|
2481
|
+
}
|
|
2482
|
+
function createWebSocketTransport({ sendBufferHighWatermark, url }) {
|
|
2483
|
+
if (/^wss?:/i.test(url) === false) {
|
|
2484
|
+
const protocolMatch = url.match(/^([^:]+):/);
|
|
2485
|
+
throw new DOMException(
|
|
2486
|
+
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.`
|
|
2487
|
+
);
|
|
2488
|
+
}
|
|
2489
|
+
return async function sendWebSocketMessage({ payload, signal }) {
|
|
2490
|
+
signal?.throwIfAborted();
|
|
2491
|
+
const connection = await createWebSocketConnection({
|
|
2492
|
+
sendBufferHighWatermark,
|
|
2493
|
+
signal,
|
|
2494
|
+
url
|
|
2495
|
+
});
|
|
2496
|
+
signal?.throwIfAborted();
|
|
2497
|
+
await connection.send(payload);
|
|
2498
|
+
return {
|
|
2499
|
+
[Symbol.asyncIterator]: connection[Symbol.asyncIterator].bind(connection),
|
|
2500
|
+
send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: connection.send.bind(connection)
|
|
2501
|
+
};
|
|
2502
|
+
};
|
|
2503
|
+
}
|
|
571
2504
|
|
|
572
2505
|
// src/rpc-default-config.ts
|
|
573
2506
|
init_env_shim();
|
|
@@ -616,6 +2549,12 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
616
2549
|
api: createSolanaRpcApi(DEFAULT_RPC_CONFIG)
|
|
617
2550
|
});
|
|
618
2551
|
}
|
|
2552
|
+
function createSolanaRpcSubscriptions(config) {
|
|
2553
|
+
return createJsonSubscriptionRpc({
|
|
2554
|
+
...config,
|
|
2555
|
+
api: createSolanaRpcSubscriptionsApi(DEFAULT_RPC_CONFIG)
|
|
2556
|
+
});
|
|
2557
|
+
}
|
|
619
2558
|
|
|
620
2559
|
// src/rpc-transport.ts
|
|
621
2560
|
init_env_shim();
|
|
@@ -652,14 +2591,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
652
2591
|
if (signal) {
|
|
653
2592
|
const responsePromise = coalescedRequest.responsePromise;
|
|
654
2593
|
return await new Promise((resolve, reject) => {
|
|
655
|
-
const handleAbort = (
|
|
2594
|
+
const handleAbort = (e3) => {
|
|
656
2595
|
signal.removeEventListener("abort", handleAbort);
|
|
657
2596
|
coalescedRequest.numConsumers -= 1;
|
|
658
2597
|
if (coalescedRequest.numConsumers === 0) {
|
|
659
2598
|
const abortController = coalescedRequest.abortController;
|
|
660
2599
|
abortController.abort();
|
|
661
2600
|
}
|
|
662
|
-
const abortError = new DOMException(
|
|
2601
|
+
const abortError = new DOMException(e3.target.reason, "AbortError");
|
|
663
2602
|
reject(abortError);
|
|
664
2603
|
};
|
|
665
2604
|
signal.addEventListener("abort", handleAbort);
|
|
@@ -709,10 +2648,117 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
709
2648
|
);
|
|
710
2649
|
}
|
|
711
2650
|
|
|
2651
|
+
// src/rpc-websocket-transport.ts
|
|
2652
|
+
init_env_shim();
|
|
2653
|
+
|
|
2654
|
+
// src/rpc-websocket-autopinger.ts
|
|
2655
|
+
init_env_shim();
|
|
2656
|
+
var PING_PAYLOAD = {
|
|
2657
|
+
jsonrpc: "2.0",
|
|
2658
|
+
method: "ping"
|
|
2659
|
+
};
|
|
2660
|
+
function getWebSocketTransportWithAutoping({ intervalMs, transport }) {
|
|
2661
|
+
const pingableConnections = /* @__PURE__ */ new Map();
|
|
2662
|
+
return async (...args) => {
|
|
2663
|
+
const connection = await transport(...args);
|
|
2664
|
+
let intervalId;
|
|
2665
|
+
function sendPing() {
|
|
2666
|
+
connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(PING_PAYLOAD);
|
|
2667
|
+
}
|
|
2668
|
+
function restartPingTimer() {
|
|
2669
|
+
clearInterval(intervalId);
|
|
2670
|
+
intervalId = setInterval(sendPing, intervalMs);
|
|
2671
|
+
}
|
|
2672
|
+
if (pingableConnections.has(connection) === false) {
|
|
2673
|
+
pingableConnections.set(connection, {
|
|
2674
|
+
[Symbol.asyncIterator]: connection[Symbol.asyncIterator].bind(connection),
|
|
2675
|
+
send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: (...args2) => {
|
|
2676
|
+
restartPingTimer();
|
|
2677
|
+
return connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(...args2);
|
|
2678
|
+
}
|
|
2679
|
+
});
|
|
2680
|
+
(async () => {
|
|
2681
|
+
try {
|
|
2682
|
+
for await (const _ of connection) {
|
|
2683
|
+
restartPingTimer();
|
|
2684
|
+
}
|
|
2685
|
+
} catch {
|
|
2686
|
+
} finally {
|
|
2687
|
+
pingableConnections.delete(connection);
|
|
2688
|
+
clearInterval(intervalId);
|
|
2689
|
+
if (handleOffline) {
|
|
2690
|
+
globalThis.window.removeEventListener("offline", handleOffline);
|
|
2691
|
+
}
|
|
2692
|
+
if (handleOnline) {
|
|
2693
|
+
globalThis.window.removeEventListener("online", handleOnline);
|
|
2694
|
+
}
|
|
2695
|
+
}
|
|
2696
|
+
})();
|
|
2697
|
+
if (globalThis.navigator.onLine) {
|
|
2698
|
+
restartPingTimer();
|
|
2699
|
+
}
|
|
2700
|
+
let handleOffline;
|
|
2701
|
+
let handleOnline;
|
|
2702
|
+
{
|
|
2703
|
+
handleOffline = () => {
|
|
2704
|
+
clearInterval(intervalId);
|
|
2705
|
+
};
|
|
2706
|
+
handleOnline = () => {
|
|
2707
|
+
sendPing();
|
|
2708
|
+
restartPingTimer();
|
|
2709
|
+
};
|
|
2710
|
+
globalThis.window.addEventListener("offline", handleOffline);
|
|
2711
|
+
globalThis.window.addEventListener("online", handleOnline);
|
|
2712
|
+
}
|
|
2713
|
+
}
|
|
2714
|
+
return pingableConnections.get(connection);
|
|
2715
|
+
};
|
|
2716
|
+
}
|
|
2717
|
+
|
|
2718
|
+
// src/rpc-websocket-transport.ts
|
|
2719
|
+
function createDefaultRpcSubscriptionsTransport(config) {
|
|
2720
|
+
const { intervalMs, ...rest } = config;
|
|
2721
|
+
return getWebSocketTransportWithAutoping({
|
|
2722
|
+
intervalMs: intervalMs ?? 5e3,
|
|
2723
|
+
transport: createWebSocketTransport({
|
|
2724
|
+
...rest,
|
|
2725
|
+
sendBufferHighWatermark: config.sendBufferHighWatermark ?? // Let 128KB of data into the WebSocket buffer before buffering it in the app.
|
|
2726
|
+
131072
|
|
2727
|
+
})
|
|
2728
|
+
});
|
|
2729
|
+
}
|
|
2730
|
+
|
|
2731
|
+
exports.AccountRole = AccountRole;
|
|
2732
|
+
exports.appendTransactionInstruction = appendTransactionInstruction;
|
|
712
2733
|
exports.assertIsBase58EncodedAddress = assertIsBase58EncodedAddress;
|
|
2734
|
+
exports.assertIsBlockhash = assertIsBlockhash;
|
|
2735
|
+
exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
|
|
2736
|
+
exports.createAddressWithSeed = createAddressWithSeed;
|
|
2737
|
+
exports.createDefaultRpcSubscriptionsTransport = createDefaultRpcSubscriptionsTransport;
|
|
713
2738
|
exports.createDefaultRpcTransport = createDefaultRpcTransport;
|
|
714
2739
|
exports.createSolanaRpc = createSolanaRpc;
|
|
2740
|
+
exports.createSolanaRpcSubscriptions = createSolanaRpcSubscriptions;
|
|
2741
|
+
exports.createTransaction = createTransaction;
|
|
2742
|
+
exports.downgradeRoleToNonSigner = downgradeRoleToNonSigner;
|
|
2743
|
+
exports.downgradeRoleToReadonly = downgradeRoleToReadonly;
|
|
2744
|
+
exports.generateKeyPair = generateKeyPair;
|
|
2745
|
+
exports.getAddressFromPublicKey = getAddressFromPublicKey;
|
|
2746
|
+
exports.getBase58EncodedAddressCodec = getBase58EncodedAddressCodec;
|
|
715
2747
|
exports.getBase58EncodedAddressComparator = getBase58EncodedAddressComparator;
|
|
2748
|
+
exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
|
|
2749
|
+
exports.getProgramDerivedAddress = getProgramDerivedAddress;
|
|
2750
|
+
exports.isSignerRole = isSignerRole;
|
|
2751
|
+
exports.isWritableRole = isWritableRole;
|
|
2752
|
+
exports.mergeRoles = mergeRoles;
|
|
2753
|
+
exports.prependTransactionInstruction = prependTransactionInstruction;
|
|
2754
|
+
exports.setTransactionFeePayer = setTransactionFeePayer;
|
|
2755
|
+
exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
|
|
2756
|
+
exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
|
|
2757
|
+
exports.signBytes = signBytes;
|
|
2758
|
+
exports.signTransaction = signTransaction;
|
|
2759
|
+
exports.upgradeRoleToSigner = upgradeRoleToSigner;
|
|
2760
|
+
exports.upgradeRoleToWritable = upgradeRoleToWritable;
|
|
2761
|
+
exports.verifySignature = verifySignature;
|
|
716
2762
|
|
|
717
2763
|
return exports;
|
|
718
2764
|
|