@solana/addresses 2.0.0-experimental.82bbf6f → 2.0.0-experimental.85b7dfe
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +124 -17
- package/dist/index.browser.cjs +103 -39
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +97 -37
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +346 -222
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +95 -37
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +105 -39
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +97 -37
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +13 -7
- package/dist/types/address.d.ts +18 -0
- package/dist/types/address.d.ts.map +1 -0
- package/dist/types/curve.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/program-derived-address.d.ts +38 -0
- package/dist/types/program-derived-address.d.ts.map +1 -0
- package/dist/types/public-key.d.ts +2 -2
- package/dist/types/public-key.d.ts.map +1 -0
- package/dist/types/vendor/noble/ed25519.d.ts.map +1 -0
- package/package.json +17 -16
- package/dist/types/base58.d.ts +0 -10
- package/dist/types/computed-address.d.ts +0 -18
|
@@ -2,19 +2,30 @@ this.globalThis = this.globalThis || {};
|
|
|
2
2
|
this.globalThis.solanaWeb3 = (function (exports) {
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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 (
|
|
59
|
-
|
|
87
|
+
if (decoder.fixedSize !== null) {
|
|
88
|
+
bytes = fixBytes(bytes, decoder.fixedSize);
|
|
60
89
|
}
|
|
61
|
-
const [value] =
|
|
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
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
//
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
84
|
-
|
|
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 !==
|
|
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(
|
|
201
|
+
base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
|
|
102
202
|
baseXPower *= baseBigInt;
|
|
103
203
|
}
|
|
104
204
|
const tailBytes = [];
|
|
@@ -108,193 +208,197 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
108
208
|
}
|
|
109
209
|
return Uint8Array.from(leadingZeroes.concat(tailBytes));
|
|
110
210
|
},
|
|
111
|
-
|
|
112
|
-
|
|
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 =
|
|
225
|
+
const leadingZeroes = alphabet4[0].repeat(trailIndex);
|
|
118
226
|
if (trailIndex === bytes.length)
|
|
119
|
-
return [leadingZeroes,
|
|
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(
|
|
231
|
+
tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
|
|
124
232
|
base10Number /= baseBigInt;
|
|
125
233
|
}
|
|
126
|
-
return [leadingZeroes + tailChars.join(""),
|
|
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
|
-
|
|
132
|
-
var
|
|
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
|
-
|
|
141
|
-
var
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
-
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|
|
280
|
+
return fixEncoder(encoding, size, description);
|
|
241
281
|
}
|
|
242
282
|
return {
|
|
243
283
|
description,
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
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
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
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
|
|
259
|
-
|
|
260
|
-
|
|
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/
|
|
270
|
-
|
|
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) {
|
|
339
|
+
if (
|
|
340
|
+
// Lowest address (32 bytes of zeroes)
|
|
341
|
+
putativeAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
342
|
+
putativeAddress.length > 44
|
|
343
|
+
) {
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
const base58Encoder = getMemoizedBase58Encoder();
|
|
347
|
+
const bytes = base58Encoder.encode(putativeAddress);
|
|
348
|
+
const numBytes = bytes.byteLength;
|
|
349
|
+
if (numBytes !== 32) {
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
352
|
+
return true;
|
|
353
|
+
}
|
|
354
|
+
function assertIsAddress(putativeAddress) {
|
|
271
355
|
try {
|
|
272
356
|
if (
|
|
273
357
|
// Lowest address (32 bytes of zeroes)
|
|
274
|
-
|
|
275
|
-
|
|
358
|
+
putativeAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
359
|
+
putativeAddress.length > 44
|
|
276
360
|
) {
|
|
277
361
|
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
278
362
|
}
|
|
279
|
-
const
|
|
363
|
+
const base58Encoder = getMemoizedBase58Encoder();
|
|
364
|
+
const bytes = base58Encoder.encode(putativeAddress);
|
|
280
365
|
const numBytes = bytes.byteLength;
|
|
281
366
|
if (numBytes !== 32) {
|
|
282
367
|
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
283
368
|
}
|
|
284
|
-
} catch (
|
|
285
|
-
throw new Error(`\`${
|
|
286
|
-
cause:
|
|
369
|
+
} catch (e2) {
|
|
370
|
+
throw new Error(`\`${putativeAddress}\` is not a base-58 encoded address`, {
|
|
371
|
+
cause: e2
|
|
287
372
|
});
|
|
288
373
|
}
|
|
289
374
|
}
|
|
290
|
-
function
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
375
|
+
function address(putativeAddress) {
|
|
376
|
+
assertIsAddress(putativeAddress);
|
|
377
|
+
return putativeAddress;
|
|
378
|
+
}
|
|
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(),
|
|
294
395
|
size: 32
|
|
295
396
|
});
|
|
296
397
|
}
|
|
297
|
-
function
|
|
398
|
+
function getAddressCodec(config) {
|
|
399
|
+
return combineCodec(getAddressEncoder(config), getAddressDecoder(config));
|
|
400
|
+
}
|
|
401
|
+
function getAddressComparator() {
|
|
298
402
|
return new Intl.Collator("en", {
|
|
299
403
|
caseFirst: "lower",
|
|
300
404
|
ignorePunctuation: false,
|
|
@@ -314,14 +418,16 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
314
418
|
}
|
|
315
419
|
}
|
|
316
420
|
async function assertDigestCapabilityIsAvailable() {
|
|
421
|
+
var _a;
|
|
317
422
|
assertIsSecureContext();
|
|
318
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle
|
|
423
|
+
if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.digest) !== "function") {
|
|
319
424
|
throw new Error("No digest implementation could be found");
|
|
320
425
|
}
|
|
321
426
|
}
|
|
322
427
|
async function assertKeyExporterIsAvailable() {
|
|
428
|
+
var _a;
|
|
323
429
|
assertIsSecureContext();
|
|
324
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle
|
|
430
|
+
if (typeof globalThis.crypto === "undefined" || typeof ((_a = globalThis.crypto.subtle) == null ? void 0 : _a.exportKey) !== "function") {
|
|
325
431
|
throw new Error("No key export implementation could be found");
|
|
326
432
|
}
|
|
327
433
|
}
|
|
@@ -416,7 +522,22 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
416
522
|
return pointIsOnCurve(y, bytes[31]);
|
|
417
523
|
}
|
|
418
524
|
|
|
419
|
-
// src/
|
|
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
|
+
}
|
|
420
541
|
var MAX_SEED_LENGTH = 32;
|
|
421
542
|
var MAX_SEEDS = 16;
|
|
422
543
|
var PDA_MARKER_BYTES = [
|
|
@@ -459,8 +580,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
459
580
|
acc.push(...bytes);
|
|
460
581
|
return acc;
|
|
461
582
|
}, []);
|
|
462
|
-
const base58EncodedAddressCodec =
|
|
463
|
-
const programAddressBytes = base58EncodedAddressCodec.
|
|
583
|
+
const base58EncodedAddressCodec = getAddressCodec();
|
|
584
|
+
const programAddressBytes = base58EncodedAddressCodec.encode(programAddress);
|
|
464
585
|
const addressBytesBuffer = await crypto.subtle.digest(
|
|
465
586
|
"SHA-256",
|
|
466
587
|
new Uint8Array([...seedBytes, ...programAddressBytes, ...PDA_MARKER_BYTES])
|
|
@@ -469,49 +590,46 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
469
590
|
if (await compressedPointBytesAreOnCurve(addressBytes)) {
|
|
470
591
|
throw new PointOnCurveError("Invalid seeds; point must fall off the Ed25519 curve");
|
|
471
592
|
}
|
|
472
|
-
return base58EncodedAddressCodec.
|
|
593
|
+
return base58EncodedAddressCodec.decode(addressBytes)[0];
|
|
473
594
|
}
|
|
474
|
-
async function getProgramDerivedAddress({
|
|
595
|
+
async function getProgramDerivedAddress({
|
|
596
|
+
programAddress,
|
|
597
|
+
seeds
|
|
598
|
+
}) {
|
|
475
599
|
let bumpSeed = 255;
|
|
476
600
|
while (bumpSeed > 0) {
|
|
477
601
|
try {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
} catch (e) {
|
|
486
|
-
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) {
|
|
487
609
|
bumpSeed--;
|
|
488
610
|
} else {
|
|
489
|
-
throw
|
|
611
|
+
throw e2;
|
|
490
612
|
}
|
|
491
613
|
}
|
|
492
614
|
}
|
|
493
615
|
throw new Error("Unable to find a viable program address bump seed");
|
|
494
616
|
}
|
|
495
|
-
async function createAddressWithSeed({
|
|
496
|
-
|
|
497
|
-
programAddress,
|
|
498
|
-
seed
|
|
499
|
-
}) {
|
|
500
|
-
const { serialize, deserialize } = getBase58EncodedAddressCodec();
|
|
617
|
+
async function createAddressWithSeed({ baseAddress, programAddress, seed }) {
|
|
618
|
+
const { encode, decode } = getAddressCodec();
|
|
501
619
|
const seedBytes = typeof seed === "string" ? new TextEncoder().encode(seed) : seed;
|
|
502
620
|
if (seedBytes.byteLength > MAX_SEED_LENGTH) {
|
|
503
621
|
throw new Error(`The seed exceeds the maximum length of 32 bytes`);
|
|
504
622
|
}
|
|
505
|
-
const programAddressBytes =
|
|
623
|
+
const programAddressBytes = encode(programAddress);
|
|
506
624
|
if (programAddressBytes.length >= PDA_MARKER_BYTES.length && programAddressBytes.slice(-PDA_MARKER_BYTES.length).every((byte, index) => byte === PDA_MARKER_BYTES[index])) {
|
|
507
625
|
throw new Error(`programAddress cannot end with the PDA marker`);
|
|
508
626
|
}
|
|
509
627
|
const addressBytesBuffer = await crypto.subtle.digest(
|
|
510
628
|
"SHA-256",
|
|
511
|
-
new Uint8Array([...
|
|
629
|
+
new Uint8Array([...encode(baseAddress), ...seedBytes, ...programAddressBytes])
|
|
512
630
|
);
|
|
513
631
|
const addressBytes = new Uint8Array(addressBytesBuffer);
|
|
514
|
-
return
|
|
632
|
+
return decode(addressBytes)[0];
|
|
515
633
|
}
|
|
516
634
|
|
|
517
635
|
// src/public-key.ts
|
|
@@ -521,16 +639,22 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
521
639
|
throw new Error("The `CryptoKey` must be an `Ed25519` public key");
|
|
522
640
|
}
|
|
523
641
|
const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
|
|
524
|
-
const [base58EncodedAddress] =
|
|
642
|
+
const [base58EncodedAddress] = getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
|
|
525
643
|
return base58EncodedAddress;
|
|
526
644
|
}
|
|
527
645
|
|
|
528
|
-
exports.
|
|
646
|
+
exports.address = address;
|
|
647
|
+
exports.assertIsAddress = assertIsAddress;
|
|
648
|
+
exports.assertIsProgramDerivedAddress = assertIsProgramDerivedAddress;
|
|
529
649
|
exports.createAddressWithSeed = createAddressWithSeed;
|
|
650
|
+
exports.getAddressCodec = getAddressCodec;
|
|
651
|
+
exports.getAddressComparator = getAddressComparator;
|
|
652
|
+
exports.getAddressDecoder = getAddressDecoder;
|
|
653
|
+
exports.getAddressEncoder = getAddressEncoder;
|
|
530
654
|
exports.getAddressFromPublicKey = getAddressFromPublicKey;
|
|
531
|
-
exports.getBase58EncodedAddressCodec = getBase58EncodedAddressCodec;
|
|
532
|
-
exports.getBase58EncodedAddressComparator = getBase58EncodedAddressComparator;
|
|
533
655
|
exports.getProgramDerivedAddress = getProgramDerivedAddress;
|
|
656
|
+
exports.isAddress = isAddress;
|
|
657
|
+
exports.isProgramDerivedAddress = isProgramDerivedAddress;
|
|
534
658
|
|
|
535
659
|
return exports;
|
|
536
660
|
|