@solana/addresses 2.0.0-experimental.4366e2e → 2.0.0-experimental.45c014d

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.
@@ -2,19 +2,30 @@ this.globalThis = this.globalThis || {};
2
2
  this.globalThis.solanaWeb3 = (function (exports) {
3
3
  'use strict';
4
4
 
5
- var __defProp = Object.defineProperty;
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
- var __publicField = (obj, key, value) => {
8
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
9
- return value;
10
- };
11
-
12
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/bytes.mjs
13
- var mergeBytes = (bytesArr) => {
14
- const totalLength = bytesArr.reduce((total, arr) => total + arr.length, 0);
5
+ // ../codecs-core/dist/index.browser.js
6
+ function assertByteArrayIsNotEmptyForCodec(codecDescription, bytes, offset = 0) {
7
+ if (bytes.length - offset <= 0) {
8
+ throw new Error(`Codec [${codecDescription}] cannot decode empty byte arrays.`);
9
+ }
10
+ }
11
+ function assertByteArrayHasEnoughBytesForCodec(codecDescription, expected, bytes, offset = 0) {
12
+ const bytesLength = bytes.length - offset;
13
+ if (bytesLength < expected) {
14
+ throw new Error(`Codec [${codecDescription}] expected ${expected} bytes, got ${bytesLength}.`);
15
+ }
16
+ }
17
+ var mergeBytes = (byteArrays) => {
18
+ const nonEmptyByteArrays = byteArrays.filter((arr) => arr.length);
19
+ if (nonEmptyByteArrays.length === 0) {
20
+ return byteArrays.length ? byteArrays[0] : new Uint8Array();
21
+ }
22
+ if (nonEmptyByteArrays.length === 1) {
23
+ return nonEmptyByteArrays[0];
24
+ }
25
+ const totalLength = nonEmptyByteArrays.reduce((total, arr) => total + arr.length, 0);
15
26
  const result = new Uint8Array(totalLength);
16
27
  let offset = 0;
17
- bytesArr.forEach((arr) => {
28
+ nonEmptyByteArrays.forEach((arr) => {
18
29
  result.set(arr, offset);
19
30
  offset += arr.length;
20
31
  });
@@ -27,69 +38,158 @@ this.globalThis.solanaWeb3 = (function (exports) {
27
38
  paddedBytes.set(bytes);
28
39
  return paddedBytes;
29
40
  };
30
- var fixBytes = (bytes, length) => padBytes(bytes.slice(0, length), length);
31
-
32
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/errors.mjs
33
- var DeserializingEmptyBufferError = class extends Error {
34
- constructor(serializer) {
35
- super(`Serializer [${serializer}] cannot deserialize empty buffers.`);
36
- __publicField(this, "name", "DeserializingEmptyBufferError");
41
+ var fixBytes = (bytes, length) => padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length);
42
+ function combineCodec(encoder, decoder, description) {
43
+ if (encoder.fixedSize !== decoder.fixedSize) {
44
+ throw new Error(
45
+ `Encoder and decoder must have the same fixed size, got [${encoder.fixedSize}] and [${decoder.fixedSize}].`
46
+ );
37
47
  }
38
- };
39
- var NotEnoughBytesError = class extends Error {
40
- constructor(serializer, expected, actual) {
41
- super(`Serializer [${serializer}] expected ${expected} bytes, got ${actual}.`);
42
- __publicField(this, "name", "NotEnoughBytesError");
48
+ if (encoder.maxSize !== decoder.maxSize) {
49
+ throw new Error(
50
+ `Encoder and decoder must have the same max size, got [${encoder.maxSize}] and [${decoder.maxSize}].`
51
+ );
52
+ }
53
+ if (description === void 0 && encoder.description !== decoder.description) {
54
+ throw new Error(
55
+ `Encoder and decoder must have the same description, got [${encoder.description}] and [${decoder.description}]. Pass a custom description as a third argument if you want to override the description and bypass this error.`
56
+ );
43
57
  }
44
- };
45
-
46
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-core@0.8.9/node_modules/@metaplex-foundation/umi-serializers-core/dist/esm/fixSerializer.mjs
47
- function fixSerializer(serializer, fixedBytes, description) {
48
58
  return {
49
- description: description ?? `fixed(${fixedBytes}, ${serializer.description})`,
59
+ decode: decoder.decode,
60
+ description: description != null ? description : encoder.description,
61
+ encode: encoder.encode,
62
+ fixedSize: encoder.fixedSize,
63
+ maxSize: encoder.maxSize
64
+ };
65
+ }
66
+ function fixCodecHelper(data, fixedBytes, description) {
67
+ return {
68
+ description: description != null ? description : `fixed(${fixedBytes}, ${data.description})`,
50
69
  fixedSize: fixedBytes,
51
- maxSize: fixedBytes,
52
- serialize: (value) => fixBytes(serializer.serialize(value), fixedBytes),
53
- deserialize: (buffer, offset = 0) => {
54
- buffer = buffer.slice(offset, offset + fixedBytes);
55
- if (buffer.length < fixedBytes) {
56
- throw new NotEnoughBytesError("fixSerializer", fixedBytes, buffer.length);
70
+ maxSize: fixedBytes
71
+ };
72
+ }
73
+ function fixEncoder(encoder, fixedBytes, description) {
74
+ return {
75
+ ...fixCodecHelper(encoder, fixedBytes, description),
76
+ encode: (value) => fixBytes(encoder.encode(value), fixedBytes)
77
+ };
78
+ }
79
+ function fixDecoder(decoder, fixedBytes, description) {
80
+ return {
81
+ ...fixCodecHelper(decoder, fixedBytes, description),
82
+ decode: (bytes, offset = 0) => {
83
+ assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes, offset);
84
+ if (offset > 0 || bytes.length > fixedBytes) {
85
+ bytes = bytes.slice(offset, offset + fixedBytes);
57
86
  }
58
- if (serializer.fixedSize !== null) {
59
- buffer = fixBytes(buffer, serializer.fixedSize);
87
+ if (decoder.fixedSize !== null) {
88
+ bytes = fixBytes(bytes, decoder.fixedSize);
60
89
  }
61
- const [value] = serializer.deserialize(buffer, 0);
90
+ const [value] = decoder.decode(bytes, 0);
62
91
  return [value, offset + fixedBytes];
63
92
  }
64
93
  };
65
94
  }
95
+ function mapEncoder(encoder, unmap) {
96
+ return {
97
+ description: encoder.description,
98
+ encode: (value) => encoder.encode(unmap(value)),
99
+ fixedSize: encoder.fixedSize,
100
+ maxSize: encoder.maxSize
101
+ };
102
+ }
66
103
 
67
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/errors.mjs
68
- var InvalidBaseStringError = class extends Error {
69
- constructor(value, base, cause) {
70
- const message = `Expected a string of base ${base}, got [${value}].`;
71
- super(message);
72
- __publicField(this, "name", "InvalidBaseStringError");
73
- this.cause = cause;
104
+ // ../codecs-numbers/dist/index.browser.js
105
+ function assertNumberIsBetweenForCodec(codecDescription, min, max, value) {
106
+ if (value < min || value > max) {
107
+ throw new Error(
108
+ `Codec [${codecDescription}] expected number to be in the range [${min}, ${max}], got ${value}.`
109
+ );
74
110
  }
75
- };
111
+ }
112
+ function sharedNumberFactory(input) {
113
+ var _a;
114
+ let littleEndian;
115
+ let defaultDescription = input.name;
116
+ if (input.size > 1) {
117
+ littleEndian = !("endian" in input.config) || input.config.endian === 0;
118
+ defaultDescription += littleEndian ? "(le)" : "(be)";
119
+ }
120
+ return {
121
+ description: (_a = input.config.description) != null ? _a : defaultDescription,
122
+ fixedSize: input.size,
123
+ littleEndian,
124
+ maxSize: input.size
125
+ };
126
+ }
127
+ function numberEncoderFactory(input) {
128
+ const codecData = sharedNumberFactory(input);
129
+ return {
130
+ description: codecData.description,
131
+ encode(value) {
132
+ if (input.range) {
133
+ assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);
134
+ }
135
+ const arrayBuffer = new ArrayBuffer(input.size);
136
+ input.set(new DataView(arrayBuffer), value, codecData.littleEndian);
137
+ return new Uint8Array(arrayBuffer);
138
+ },
139
+ fixedSize: codecData.fixedSize,
140
+ maxSize: codecData.maxSize
141
+ };
142
+ }
143
+ function numberDecoderFactory(input) {
144
+ const codecData = sharedNumberFactory(input);
145
+ return {
146
+ decode(bytes, offset = 0) {
147
+ assertByteArrayIsNotEmptyForCodec(codecData.description, bytes, offset);
148
+ assertByteArrayHasEnoughBytesForCodec(codecData.description, input.size, bytes, offset);
149
+ const view = new DataView(toArrayBuffer(bytes, offset, input.size));
150
+ return [input.get(view, codecData.littleEndian), offset + input.size];
151
+ },
152
+ description: codecData.description,
153
+ fixedSize: codecData.fixedSize,
154
+ maxSize: codecData.maxSize
155
+ };
156
+ }
157
+ function toArrayBuffer(bytes, offset, length) {
158
+ const bytesOffset = bytes.byteOffset + (offset != null ? offset : 0);
159
+ const bytesLength = length != null ? length : bytes.byteLength;
160
+ return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
161
+ }
162
+ var getU32Encoder = (config = {}) => numberEncoderFactory({
163
+ config,
164
+ name: "u32",
165
+ range: [0, Number("0xffffffff")],
166
+ set: (view, value, le) => view.setUint32(0, value, le),
167
+ size: 4
168
+ });
169
+ var getU32Decoder = (config = {}) => numberDecoderFactory({
170
+ config,
171
+ get: (view, le) => view.getUint32(0, le),
172
+ name: "u32",
173
+ size: 4
174
+ });
76
175
 
77
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/baseX.mjs
78
- var baseX = (alphabet) => {
79
- const base = alphabet.length;
176
+ // ../codecs-strings/dist/index.browser.js
177
+ function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
178
+ if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
179
+ throw new Error(`Expected a string of base ${alphabet4.length}, got [${givenValue}].`);
180
+ }
181
+ }
182
+ var getBaseXEncoder = (alphabet4) => {
183
+ const base = alphabet4.length;
80
184
  const baseBigInt = BigInt(base);
81
185
  return {
82
186
  description: `base${base}`,
83
- fixedSize: null,
84
- maxSize: null,
85
- serialize(value) {
86
- if (!value.match(new RegExp(`^[${alphabet}]*$`))) {
87
- throw new InvalidBaseStringError(value, base);
88
- }
187
+ encode(value) {
188
+ assertValidBaseString(alphabet4, value);
89
189
  if (value === "")
90
190
  return new Uint8Array();
91
191
  const chars = [...value];
92
- let trailIndex = chars.findIndex((c) => c !== alphabet[0]);
192
+ let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
93
193
  trailIndex = trailIndex === -1 ? chars.length : trailIndex;
94
194
  const leadingZeroes = Array(trailIndex).fill(0);
95
195
  if (trailIndex === chars.length)
@@ -98,7 +198,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
98
198
  let base10Number = 0n;
99
199
  let baseXPower = 1n;
100
200
  for (let i = tailChars.length - 1; i >= 0; i -= 1) {
101
- base10Number += baseXPower * BigInt(alphabet.indexOf(tailChars[i]));
201
+ base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
102
202
  baseXPower *= baseBigInt;
103
203
  }
104
204
  const tailBytes = [];
@@ -108,212 +208,197 @@ this.globalThis.solanaWeb3 = (function (exports) {
108
208
  }
109
209
  return Uint8Array.from(leadingZeroes.concat(tailBytes));
110
210
  },
111
- deserialize(buffer, offset = 0) {
112
- if (buffer.length === 0)
211
+ fixedSize: null,
212
+ maxSize: null
213
+ };
214
+ };
215
+ var getBaseXDecoder = (alphabet4) => {
216
+ const base = alphabet4.length;
217
+ const baseBigInt = BigInt(base);
218
+ return {
219
+ decode(rawBytes, offset = 0) {
220
+ const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
221
+ if (bytes.length === 0)
113
222
  return ["", 0];
114
- const bytes = buffer.slice(offset);
115
223
  let trailIndex = bytes.findIndex((n) => n !== 0);
116
224
  trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
117
- const leadingZeroes = alphabet[0].repeat(trailIndex);
225
+ const leadingZeroes = alphabet4[0].repeat(trailIndex);
118
226
  if (trailIndex === bytes.length)
119
- return [leadingZeroes, buffer.length];
227
+ return [leadingZeroes, rawBytes.length];
120
228
  let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
121
229
  const tailChars = [];
122
230
  while (base10Number > 0n) {
123
- tailChars.unshift(alphabet[Number(base10Number % baseBigInt)]);
231
+ tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
124
232
  base10Number /= baseBigInt;
125
233
  }
126
- return [leadingZeroes + tailChars.join(""), buffer.length];
127
- }
234
+ return [leadingZeroes + tailChars.join(""), rawBytes.length];
235
+ },
236
+ description: `base${base}`,
237
+ fixedSize: null,
238
+ maxSize: null
128
239
  };
129
240
  };
130
-
131
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/base58.mjs
132
- var base58 = baseX("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");
133
-
134
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/nullCharacters.mjs
241
+ var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
242
+ var getBase58Encoder = () => getBaseXEncoder(alphabet2);
243
+ var getBase58Decoder = () => getBaseXDecoder(alphabet2);
135
244
  var removeNullCharacters = (value) => (
136
245
  // eslint-disable-next-line no-control-regex
137
246
  value.replace(/\u0000/g, "")
138
247
  );
139
-
140
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-encodings@0.8.9/node_modules/@metaplex-foundation/umi-serializers-encodings/dist/esm/utf8.mjs
141
- var utf8 = {
142
- description: "utf8",
143
- fixedSize: null,
144
- maxSize: null,
145
- serialize(value) {
146
- return new TextEncoder().encode(value);
147
- },
148
- deserialize(buffer, offset = 0) {
149
- const value = new TextDecoder().decode(buffer.slice(offset));
150
- return [removeNullCharacters(value), buffer.length];
151
- }
152
- };
153
-
154
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/common.mjs
155
- var Endian;
156
- (function(Endian2) {
157
- Endian2["Little"] = "le";
158
- Endian2["Big"] = "be";
159
- })(Endian || (Endian = {}));
160
-
161
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/errors.mjs
162
- var NumberOutOfRangeError = class extends RangeError {
163
- constructor(serializer, min, max, actual) {
164
- super(`Serializer [${serializer}] expected number to be between ${min} and ${max}, got ${actual}.`);
165
- __publicField(this, "name", "NumberOutOfRangeError");
166
- }
248
+ var e = globalThis.TextDecoder;
249
+ var o = globalThis.TextEncoder;
250
+ var getUtf8Encoder = () => {
251
+ let textEncoder;
252
+ return {
253
+ description: "utf8",
254
+ encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
255
+ fixedSize: null,
256
+ maxSize: null
257
+ };
167
258
  };
168
-
169
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/utils.mjs
170
- function numberFactory(input) {
171
- let littleEndian;
172
- let defaultDescription = input.name;
173
- if (input.size > 1) {
174
- littleEndian = !("endian" in input.options) || input.options.endian === Endian.Little;
175
- defaultDescription += littleEndian ? "(le)" : "(be)";
176
- }
259
+ var getUtf8Decoder = () => {
260
+ let textDecoder;
177
261
  return {
178
- description: input.options.description ?? defaultDescription,
179
- fixedSize: input.size,
180
- maxSize: input.size,
181
- serialize(value) {
182
- if (input.range) {
183
- assertRange(input.name, input.range[0], input.range[1], value);
184
- }
185
- const buffer = new ArrayBuffer(input.size);
186
- input.set(new DataView(buffer), value, littleEndian);
187
- return new Uint8Array(buffer);
262
+ decode(bytes, offset = 0) {
263
+ const value = (textDecoder || (textDecoder = new e())).decode(bytes.slice(offset));
264
+ return [removeNullCharacters(value), bytes.length];
188
265
  },
189
- deserialize(bytes, offset = 0) {
190
- const slice = bytes.slice(offset, offset + input.size);
191
- assertEnoughBytes("i8", slice, input.size);
192
- const view = toDataView(slice);
193
- return [input.get(view, littleEndian), offset + input.size];
194
- }
266
+ description: "utf8",
267
+ fixedSize: null,
268
+ maxSize: null
195
269
  };
196
- }
197
- var toArrayBuffer = (array) => array.buffer.slice(array.byteOffset, array.byteLength + array.byteOffset);
198
- var toDataView = (array) => new DataView(toArrayBuffer(array));
199
- var assertRange = (serializer, min, max, value) => {
200
- if (value < min || value > max) {
201
- throw new NumberOutOfRangeError(serializer, min, max, value);
202
- }
203
- };
204
- var assertEnoughBytes = (serializer, bytes, expected) => {
205
- if (bytes.length === 0) {
206
- throw new DeserializingEmptyBufferError(serializer);
207
- }
208
- if (bytes.length < expected) {
209
- throw new NotEnoughBytesError(serializer, expected, bytes.length);
210
- }
211
270
  };
212
-
213
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers-numbers@0.8.9/node_modules/@metaplex-foundation/umi-serializers-numbers/dist/esm/u32.mjs
214
- var u32 = (options = {}) => numberFactory({
215
- name: "u32",
216
- size: 4,
217
- range: [0, Number("0xffffffff")],
218
- set: (view, value, le) => view.setUint32(0, Number(value), le),
219
- get: (view, le) => view.getUint32(0, le),
220
- options
221
- });
222
-
223
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/utils.mjs
224
- function getSizeDescription(size) {
225
- return typeof size === "object" ? size.description : `${size}`;
226
- }
227
-
228
- // ../../node_modules/.pnpm/@metaplex-foundation+umi-serializers@0.8.9/node_modules/@metaplex-foundation/umi-serializers/dist/esm/string.mjs
229
- function string(options = {}) {
230
- const size = options.size ?? u32();
231
- const encoding = options.encoding ?? utf8;
232
- const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
271
+ var getStringEncoder = (config = {}) => {
272
+ var _a, _b, _c;
273
+ const size = (_a = config.size) != null ? _a : getU32Encoder();
274
+ const encoding = (_b = config.encoding) != null ? _b : getUtf8Encoder();
275
+ const description = (_c = config.description) != null ? _c : `string(${encoding.description}; ${getSizeDescription(size)})`;
233
276
  if (size === "variable") {
234
- return {
235
- ...encoding,
236
- description
237
- };
277
+ return { ...encoding, description };
238
278
  }
239
279
  if (typeof size === "number") {
240
- return fixSerializer(encoding, size, description);
280
+ return fixEncoder(encoding, size, description);
241
281
  }
242
282
  return {
243
283
  description,
244
- fixedSize: null,
245
- maxSize: null,
246
- serialize: (value) => {
247
- const contentBytes = encoding.serialize(value);
248
- const lengthBytes = size.serialize(contentBytes.length);
284
+ encode: (value) => {
285
+ const contentBytes = encoding.encode(value);
286
+ const lengthBytes = size.encode(contentBytes.length);
249
287
  return mergeBytes([lengthBytes, contentBytes]);
250
288
  },
251
- deserialize: (buffer, offset = 0) => {
252
- if (buffer.slice(offset).length === 0) {
253
- throw new DeserializingEmptyBufferError("string");
254
- }
255
- const [lengthBigInt, lengthOffset] = size.deserialize(buffer, offset);
289
+ fixedSize: null,
290
+ maxSize: null
291
+ };
292
+ };
293
+ var getStringDecoder = (config = {}) => {
294
+ var _a, _b, _c;
295
+ const size = (_a = config.size) != null ? _a : getU32Decoder();
296
+ const encoding = (_b = config.encoding) != null ? _b : getUtf8Decoder();
297
+ const description = (_c = config.description) != null ? _c : `string(${encoding.description}; ${getSizeDescription(size)})`;
298
+ if (size === "variable") {
299
+ return { ...encoding, description };
300
+ }
301
+ if (typeof size === "number") {
302
+ return fixDecoder(encoding, size, description);
303
+ }
304
+ return {
305
+ decode: (bytes, offset = 0) => {
306
+ assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
307
+ const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
256
308
  const length = Number(lengthBigInt);
257
309
  offset = lengthOffset;
258
- const contentBuffer = buffer.slice(offset, offset + length);
259
- if (contentBuffer.length < length) {
260
- throw new NotEnoughBytesError("string", length, contentBuffer.length);
261
- }
262
- const [value, contentOffset] = encoding.deserialize(contentBuffer);
310
+ const contentBytes = bytes.slice(offset, offset + length);
311
+ assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
312
+ const [value, contentOffset] = encoding.decode(contentBytes);
263
313
  offset += contentOffset;
264
314
  return [value, offset];
265
- }
315
+ },
316
+ description,
317
+ fixedSize: null,
318
+ maxSize: null
266
319
  };
320
+ };
321
+ function getSizeDescription(size) {
322
+ return typeof size === "object" ? size.description : `${size}`;
267
323
  }
268
324
 
269
- // src/base58.ts
270
- function isBase58EncodedAddress(putativeBase58EncodedAddress) {
325
+ // src/address.ts
326
+ var memoizedBase58Encoder;
327
+ var memoizedBase58Decoder;
328
+ function getMemoizedBase58Encoder() {
329
+ if (!memoizedBase58Encoder)
330
+ memoizedBase58Encoder = getBase58Encoder();
331
+ return memoizedBase58Encoder;
332
+ }
333
+ function getMemoizedBase58Decoder() {
334
+ if (!memoizedBase58Decoder)
335
+ memoizedBase58Decoder = getBase58Decoder();
336
+ return memoizedBase58Decoder;
337
+ }
338
+ function isAddress(putativeAddress) {
271
339
  if (
272
340
  // Lowest address (32 bytes of zeroes)
273
- putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
274
- putativeBase58EncodedAddress.length > 44
341
+ putativeAddress.length < 32 || // Highest address (32 bytes of 255)
342
+ putativeAddress.length > 44
275
343
  ) {
276
344
  return false;
277
345
  }
278
- const bytes = base58.serialize(putativeBase58EncodedAddress);
346
+ const base58Encoder = getMemoizedBase58Encoder();
347
+ const bytes = base58Encoder.encode(putativeAddress);
279
348
  const numBytes = bytes.byteLength;
280
349
  if (numBytes !== 32) {
281
350
  return false;
282
351
  }
283
352
  return true;
284
353
  }
285
- function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
354
+ function assertIsAddress(putativeAddress) {
286
355
  try {
287
356
  if (
288
357
  // Lowest address (32 bytes of zeroes)
289
- putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
290
- putativeBase58EncodedAddress.length > 44
358
+ putativeAddress.length < 32 || // Highest address (32 bytes of 255)
359
+ putativeAddress.length > 44
291
360
  ) {
292
361
  throw new Error("Expected input string to decode to a byte array of length 32.");
293
362
  }
294
- const bytes = base58.serialize(putativeBase58EncodedAddress);
363
+ const base58Encoder = getMemoizedBase58Encoder();
364
+ const bytes = base58Encoder.encode(putativeAddress);
295
365
  const numBytes = bytes.byteLength;
296
366
  if (numBytes !== 32) {
297
367
  throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
298
368
  }
299
- } catch (e) {
300
- throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
301
- cause: e
369
+ } catch (e2) {
370
+ throw new Error(`\`${putativeAddress}\` is not a base-58 encoded address`, {
371
+ cause: e2
302
372
  });
303
373
  }
304
374
  }
305
- function address(putativeBase58EncodedAddress) {
306
- assertIsBase58EncodedAddress(putativeBase58EncodedAddress);
307
- return putativeBase58EncodedAddress;
375
+ function address(putativeAddress) {
376
+ assertIsAddress(putativeAddress);
377
+ return putativeAddress;
308
378
  }
309
- function getBase58EncodedAddressCodec(config) {
310
- return string({
311
- description: config?.description ?? ("A 32-byte account address" ),
312
- encoding: base58,
379
+ function getAddressEncoder(config) {
380
+ var _a;
381
+ return mapEncoder(
382
+ getStringEncoder({
383
+ description: (_a = config == null ? void 0 : config.description) != null ? _a : "Address",
384
+ encoding: getMemoizedBase58Encoder(),
385
+ size: 32
386
+ }),
387
+ (putativeAddress) => address(putativeAddress)
388
+ );
389
+ }
390
+ function getAddressDecoder(config) {
391
+ var _a;
392
+ return getStringDecoder({
393
+ description: (_a = config == null ? void 0 : config.description) != null ? _a : "Address",
394
+ encoding: getMemoizedBase58Decoder(),
313
395
  size: 32
314
396
  });
315
397
  }
316
- function getBase58EncodedAddressComparator() {
398
+ function getAddressCodec(config) {
399
+ return combineCodec(getAddressEncoder(config), getAddressDecoder(config));
400
+ }
401
+ function getAddressComparator() {
317
402
  return new Intl.Collator("en", {
318
403
  caseFirst: "lower",
319
404
  ignorePunctuation: false,
@@ -333,14 +418,16 @@ this.globalThis.solanaWeb3 = (function (exports) {
333
418
  }
334
419
  }
335
420
  async function assertDigestCapabilityIsAvailable() {
421
+ var _a;
336
422
  assertIsSecureContext();
337
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.digest !== "function") {
423
+ if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.digest) !== "function") {
338
424
  throw new Error("No digest implementation could be found");
339
425
  }
340
426
  }
341
427
  async function assertKeyExporterIsAvailable() {
428
+ var _a;
342
429
  assertIsSecureContext();
343
- if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
430
+ if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.exportKey) !== "function") {
344
431
  throw new Error("No key export implementation could be found");
345
432
  }
346
433
  }
@@ -435,7 +522,22 @@ this.globalThis.solanaWeb3 = (function (exports) {
435
522
  return pointIsOnCurve(y, bytes[31]);
436
523
  }
437
524
 
438
- // src/computed-address.ts
525
+ // src/program-derived-address.ts
526
+ function isProgramDerivedAddress(value) {
527
+ return Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && typeof value[1] === "number" && value[1] >= 0 && value[1] <= 255 && isAddress(value[0]);
528
+ }
529
+ function assertIsProgramDerivedAddress(value) {
530
+ const validFormat = Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && typeof value[1] === "number";
531
+ if (!validFormat) {
532
+ throw new Error(
533
+ `Expected given program derived address to have the following format: [Address, ProgramDerivedAddressBump].`
534
+ );
535
+ }
536
+ if (value[1] < 0 || value[1] > 255) {
537
+ throw new Error(`Expected program derived address bump to be in the range [0, 255], got: ${value[1]}.`);
538
+ }
539
+ assertIsAddress(value[0]);
540
+ }
439
541
  var MAX_SEED_LENGTH = 32;
440
542
  var MAX_SEEDS = 16;
441
543
  var PDA_MARKER_BYTES = [
@@ -478,8 +580,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
478
580
  acc.push(...bytes);
479
581
  return acc;
480
582
  }, []);
481
- const base58EncodedAddressCodec = getBase58EncodedAddressCodec();
482
- const programAddressBytes = base58EncodedAddressCodec.serialize(programAddress);
583
+ const base58EncodedAddressCodec = getAddressCodec();
584
+ const programAddressBytes = base58EncodedAddressCodec.encode(programAddress);
483
585
  const addressBytesBuffer = await crypto.subtle.digest(
484
586
  "SHA-256",
485
587
  new Uint8Array([...seedBytes, ...programAddressBytes, ...PDA_MARKER_BYTES])
@@ -488,49 +590,46 @@ this.globalThis.solanaWeb3 = (function (exports) {
488
590
  if (await compressedPointBytesAreOnCurve(addressBytes)) {
489
591
  throw new PointOnCurveError("Invalid seeds; point must fall off the Ed25519 curve");
490
592
  }
491
- return base58EncodedAddressCodec.deserialize(addressBytes)[0];
593
+ return base58EncodedAddressCodec.decode(addressBytes)[0];
492
594
  }
493
- async function getProgramDerivedAddress({ programAddress, seeds }) {
595
+ async function getProgramDerivedAddress({
596
+ programAddress,
597
+ seeds
598
+ }) {
494
599
  let bumpSeed = 255;
495
600
  while (bumpSeed > 0) {
496
601
  try {
497
- return {
498
- bumpSeed,
499
- pda: await createProgramDerivedAddress({
500
- programAddress,
501
- seeds: [...seeds, new Uint8Array([bumpSeed])]
502
- })
503
- };
504
- } catch (e) {
505
- if (e instanceof PointOnCurveError) {
602
+ const address2 = await createProgramDerivedAddress({
603
+ programAddress,
604
+ seeds: [...seeds, new Uint8Array([bumpSeed])]
605
+ });
606
+ return [address2, bumpSeed];
607
+ } catch (e2) {
608
+ if (e2 instanceof PointOnCurveError) {
506
609
  bumpSeed--;
507
610
  } else {
508
- throw e;
611
+ throw e2;
509
612
  }
510
613
  }
511
614
  }
512
615
  throw new Error("Unable to find a viable program address bump seed");
513
616
  }
514
- async function createAddressWithSeed({
515
- baseAddress,
516
- programAddress,
517
- seed
518
- }) {
519
- const { serialize, deserialize } = getBase58EncodedAddressCodec();
617
+ async function createAddressWithSeed({ baseAddress, programAddress, seed }) {
618
+ const { encode, decode } = getAddressCodec();
520
619
  const seedBytes = typeof seed === "string" ? new TextEncoder().encode(seed) : seed;
521
620
  if (seedBytes.byteLength > MAX_SEED_LENGTH) {
522
621
  throw new Error(`The seed exceeds the maximum length of 32 bytes`);
523
622
  }
524
- const programAddressBytes = serialize(programAddress);
623
+ const programAddressBytes = encode(programAddress);
525
624
  if (programAddressBytes.length >= PDA_MARKER_BYTES.length && programAddressBytes.slice(-PDA_MARKER_BYTES.length).every((byte, index) => byte === PDA_MARKER_BYTES[index])) {
526
625
  throw new Error(`programAddress cannot end with the PDA marker`);
527
626
  }
528
627
  const addressBytesBuffer = await crypto.subtle.digest(
529
628
  "SHA-256",
530
- new Uint8Array([...serialize(baseAddress), ...seedBytes, ...programAddressBytes])
629
+ new Uint8Array([...encode(baseAddress), ...seedBytes, ...programAddressBytes])
531
630
  );
532
631
  const addressBytes = new Uint8Array(addressBytesBuffer);
533
- return deserialize(addressBytes)[0];
632
+ return decode(addressBytes)[0];
534
633
  }
535
634
 
536
635
  // src/public-key.ts
@@ -540,18 +639,22 @@ this.globalThis.solanaWeb3 = (function (exports) {
540
639
  throw new Error("The `CryptoKey` must be an `Ed25519` public key");
541
640
  }
542
641
  const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
543
- const [base58EncodedAddress] = getBase58EncodedAddressCodec().deserialize(new Uint8Array(publicKeyBytes));
642
+ const [base58EncodedAddress] = getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
544
643
  return base58EncodedAddress;
545
644
  }
546
645
 
547
646
  exports.address = address;
548
- exports.assertIsBase58EncodedAddress = assertIsBase58EncodedAddress;
647
+ exports.assertIsAddress = assertIsAddress;
648
+ exports.assertIsProgramDerivedAddress = assertIsProgramDerivedAddress;
549
649
  exports.createAddressWithSeed = createAddressWithSeed;
650
+ exports.getAddressCodec = getAddressCodec;
651
+ exports.getAddressComparator = getAddressComparator;
652
+ exports.getAddressDecoder = getAddressDecoder;
653
+ exports.getAddressEncoder = getAddressEncoder;
550
654
  exports.getAddressFromPublicKey = getAddressFromPublicKey;
551
- exports.getBase58EncodedAddressCodec = getBase58EncodedAddressCodec;
552
- exports.getBase58EncodedAddressComparator = getBase58EncodedAddressComparator;
553
655
  exports.getProgramDerivedAddress = getProgramDerivedAddress;
554
- exports.isBase58EncodedAddress = isBase58EncodedAddress;
656
+ exports.isAddress = isAddress;
657
+ exports.isProgramDerivedAddress = isProgramDerivedAddress;
555
658
 
556
659
  return exports;
557
660