@solana/addresses 2.0.0-experimental.ee4214c → 2.0.0-experimental.efe6f4d
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/README.md +120 -13
- package/dist/index.browser.cjs +58 -36
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +57 -37
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +292 -217
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +59 -37
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +58 -36
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +57 -37
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +13 -11
- package/dist/types/address.d.ts +12 -6
- package/dist/types/address.d.ts.map +1 -0
- package/dist/types/curve.d.ts.map +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/program-derived-address.d.ts +6 -6
- 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 +9 -8
|
@@ -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,157 @@ 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 ?? 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 ?? `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
|
+
let littleEndian;
|
|
114
|
+
let defaultDescription = input.name;
|
|
115
|
+
if (input.size > 1) {
|
|
116
|
+
littleEndian = !("endian" in input.config) || input.config.endian === 0;
|
|
117
|
+
defaultDescription += littleEndian ? "(le)" : "(be)";
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
description: input.config.description ?? defaultDescription,
|
|
121
|
+
fixedSize: input.size,
|
|
122
|
+
littleEndian,
|
|
123
|
+
maxSize: input.size
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
function numberEncoderFactory(input) {
|
|
127
|
+
const codecData = sharedNumberFactory(input);
|
|
128
|
+
return {
|
|
129
|
+
description: codecData.description,
|
|
130
|
+
encode(value) {
|
|
131
|
+
if (input.range) {
|
|
132
|
+
assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value);
|
|
133
|
+
}
|
|
134
|
+
const arrayBuffer = new ArrayBuffer(input.size);
|
|
135
|
+
input.set(new DataView(arrayBuffer), value, codecData.littleEndian);
|
|
136
|
+
return new Uint8Array(arrayBuffer);
|
|
137
|
+
},
|
|
138
|
+
fixedSize: codecData.fixedSize,
|
|
139
|
+
maxSize: codecData.maxSize
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function numberDecoderFactory(input) {
|
|
143
|
+
const codecData = sharedNumberFactory(input);
|
|
144
|
+
return {
|
|
145
|
+
decode(bytes, offset = 0) {
|
|
146
|
+
assertByteArrayIsNotEmptyForCodec(codecData.description, bytes, offset);
|
|
147
|
+
assertByteArrayHasEnoughBytesForCodec(codecData.description, input.size, bytes, offset);
|
|
148
|
+
const view = new DataView(toArrayBuffer(bytes, offset, input.size));
|
|
149
|
+
return [input.get(view, codecData.littleEndian), offset + input.size];
|
|
150
|
+
},
|
|
151
|
+
description: codecData.description,
|
|
152
|
+
fixedSize: codecData.fixedSize,
|
|
153
|
+
maxSize: codecData.maxSize
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function toArrayBuffer(bytes, offset, length) {
|
|
157
|
+
const bytesOffset = bytes.byteOffset + (offset ?? 0);
|
|
158
|
+
const bytesLength = length ?? bytes.byteLength;
|
|
159
|
+
return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
|
|
160
|
+
}
|
|
161
|
+
var getU32Encoder = (config = {}) => numberEncoderFactory({
|
|
162
|
+
config,
|
|
163
|
+
name: "u32",
|
|
164
|
+
range: [0, Number("0xffffffff")],
|
|
165
|
+
set: (view, value, le) => view.setUint32(0, value, le),
|
|
166
|
+
size: 4
|
|
167
|
+
});
|
|
168
|
+
var getU32Decoder = (config = {}) => numberDecoderFactory({
|
|
169
|
+
config,
|
|
170
|
+
get: (view, le) => view.getUint32(0, le),
|
|
171
|
+
name: "u32",
|
|
172
|
+
size: 4
|
|
173
|
+
});
|
|
76
174
|
|
|
77
|
-
//
|
|
78
|
-
|
|
79
|
-
|
|
175
|
+
// ../codecs-strings/dist/index.browser.js
|
|
176
|
+
function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
|
|
177
|
+
if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
|
|
178
|
+
throw new Error(`Expected a string of base ${alphabet4.length}, got [${givenValue}].`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
var getBaseXEncoder = (alphabet4) => {
|
|
182
|
+
const base = alphabet4.length;
|
|
80
183
|
const baseBigInt = BigInt(base);
|
|
81
184
|
return {
|
|
82
185
|
description: `base${base}`,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
serialize(value) {
|
|
86
|
-
if (!value.match(new RegExp(`^[${alphabet}]*$`))) {
|
|
87
|
-
throw new InvalidBaseStringError(value, base);
|
|
88
|
-
}
|
|
186
|
+
encode(value) {
|
|
187
|
+
assertValidBaseString(alphabet4, value);
|
|
89
188
|
if (value === "")
|
|
90
189
|
return new Uint8Array();
|
|
91
190
|
const chars = [...value];
|
|
92
|
-
let trailIndex = chars.findIndex((c) => c !==
|
|
191
|
+
let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
|
|
93
192
|
trailIndex = trailIndex === -1 ? chars.length : trailIndex;
|
|
94
193
|
const leadingZeroes = Array(trailIndex).fill(0);
|
|
95
194
|
if (trailIndex === chars.length)
|
|
@@ -98,7 +197,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
98
197
|
let base10Number = 0n;
|
|
99
198
|
let baseXPower = 1n;
|
|
100
199
|
for (let i = tailChars.length - 1; i >= 0; i -= 1) {
|
|
101
|
-
base10Number += baseXPower * BigInt(
|
|
200
|
+
base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
|
|
102
201
|
baseXPower *= baseBigInt;
|
|
103
202
|
}
|
|
104
203
|
const tailBytes = [];
|
|
@@ -108,211 +207,192 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
108
207
|
}
|
|
109
208
|
return Uint8Array.from(leadingZeroes.concat(tailBytes));
|
|
110
209
|
},
|
|
111
|
-
|
|
112
|
-
|
|
210
|
+
fixedSize: null,
|
|
211
|
+
maxSize: null
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
var getBaseXDecoder = (alphabet4) => {
|
|
215
|
+
const base = alphabet4.length;
|
|
216
|
+
const baseBigInt = BigInt(base);
|
|
217
|
+
return {
|
|
218
|
+
decode(rawBytes, offset = 0) {
|
|
219
|
+
const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
|
|
220
|
+
if (bytes.length === 0)
|
|
113
221
|
return ["", 0];
|
|
114
|
-
const bytes = buffer.slice(offset);
|
|
115
222
|
let trailIndex = bytes.findIndex((n) => n !== 0);
|
|
116
223
|
trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
|
|
117
|
-
const leadingZeroes =
|
|
224
|
+
const leadingZeroes = alphabet4[0].repeat(trailIndex);
|
|
118
225
|
if (trailIndex === bytes.length)
|
|
119
|
-
return [leadingZeroes,
|
|
226
|
+
return [leadingZeroes, rawBytes.length];
|
|
120
227
|
let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
|
|
121
228
|
const tailChars = [];
|
|
122
229
|
while (base10Number > 0n) {
|
|
123
|
-
tailChars.unshift(
|
|
230
|
+
tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
|
|
124
231
|
base10Number /= baseBigInt;
|
|
125
232
|
}
|
|
126
|
-
return [leadingZeroes + tailChars.join(""),
|
|
127
|
-
}
|
|
233
|
+
return [leadingZeroes + tailChars.join(""), rawBytes.length];
|
|
234
|
+
},
|
|
235
|
+
description: `base${base}`,
|
|
236
|
+
fixedSize: null,
|
|
237
|
+
maxSize: null
|
|
128
238
|
};
|
|
129
239
|
};
|
|
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
|
|
240
|
+
var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
241
|
+
var getBase58Encoder = () => getBaseXEncoder(alphabet2);
|
|
242
|
+
var getBase58Decoder = () => getBaseXDecoder(alphabet2);
|
|
135
243
|
var removeNullCharacters = (value) => (
|
|
136
244
|
// eslint-disable-next-line no-control-regex
|
|
137
245
|
value.replace(/\u0000/g, "")
|
|
138
246
|
);
|
|
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
|
-
}
|
|
247
|
+
var e = globalThis.TextDecoder;
|
|
248
|
+
var o = globalThis.TextEncoder;
|
|
249
|
+
var getUtf8Encoder = () => {
|
|
250
|
+
let textEncoder;
|
|
251
|
+
return {
|
|
252
|
+
description: "utf8",
|
|
253
|
+
encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
|
|
254
|
+
fixedSize: null,
|
|
255
|
+
maxSize: null
|
|
256
|
+
};
|
|
167
257
|
};
|
|
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
|
-
}
|
|
258
|
+
var getUtf8Decoder = () => {
|
|
259
|
+
let textDecoder;
|
|
177
260
|
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);
|
|
261
|
+
decode(bytes, offset = 0) {
|
|
262
|
+
const value = (textDecoder || (textDecoder = new e())).decode(bytes.slice(offset));
|
|
263
|
+
return [removeNullCharacters(value), bytes.length];
|
|
188
264
|
},
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
const view = toDataView(slice);
|
|
193
|
-
return [input.get(view, littleEndian), offset + input.size];
|
|
194
|
-
}
|
|
265
|
+
description: "utf8",
|
|
266
|
+
fixedSize: null,
|
|
267
|
+
maxSize: null
|
|
195
268
|
};
|
|
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
269
|
};
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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)})`;
|
|
270
|
+
var getStringEncoder = (config = {}) => {
|
|
271
|
+
const size = config.size ?? getU32Encoder();
|
|
272
|
+
const encoding = config.encoding ?? getUtf8Encoder();
|
|
273
|
+
const description = config.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
|
|
233
274
|
if (size === "variable") {
|
|
234
|
-
return {
|
|
235
|
-
...encoding,
|
|
236
|
-
description
|
|
237
|
-
};
|
|
275
|
+
return { ...encoding, description };
|
|
238
276
|
}
|
|
239
277
|
if (typeof size === "number") {
|
|
240
|
-
return
|
|
278
|
+
return fixEncoder(encoding, size, description);
|
|
241
279
|
}
|
|
242
280
|
return {
|
|
243
281
|
description,
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
const contentBytes = encoding.serialize(value);
|
|
248
|
-
const lengthBytes = size.serialize(contentBytes.length);
|
|
282
|
+
encode: (value) => {
|
|
283
|
+
const contentBytes = encoding.encode(value);
|
|
284
|
+
const lengthBytes = size.encode(contentBytes.length);
|
|
249
285
|
return mergeBytes([lengthBytes, contentBytes]);
|
|
250
286
|
},
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
287
|
+
fixedSize: null,
|
|
288
|
+
maxSize: null
|
|
289
|
+
};
|
|
290
|
+
};
|
|
291
|
+
var getStringDecoder = (config = {}) => {
|
|
292
|
+
const size = config.size ?? getU32Decoder();
|
|
293
|
+
const encoding = config.encoding ?? getUtf8Decoder();
|
|
294
|
+
const description = config.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
|
|
295
|
+
if (size === "variable") {
|
|
296
|
+
return { ...encoding, description };
|
|
297
|
+
}
|
|
298
|
+
if (typeof size === "number") {
|
|
299
|
+
return fixDecoder(encoding, size, description);
|
|
300
|
+
}
|
|
301
|
+
return {
|
|
302
|
+
decode: (bytes, offset = 0) => {
|
|
303
|
+
assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
|
|
304
|
+
const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
|
|
256
305
|
const length = Number(lengthBigInt);
|
|
257
306
|
offset = lengthOffset;
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
}
|
|
262
|
-
const [value, contentOffset] = encoding.deserialize(contentBuffer);
|
|
307
|
+
const contentBytes = bytes.slice(offset, offset + length);
|
|
308
|
+
assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
|
|
309
|
+
const [value, contentOffset] = encoding.decode(contentBytes);
|
|
263
310
|
offset += contentOffset;
|
|
264
311
|
return [value, offset];
|
|
265
|
-
}
|
|
312
|
+
},
|
|
313
|
+
description,
|
|
314
|
+
fixedSize: null,
|
|
315
|
+
maxSize: null
|
|
266
316
|
};
|
|
317
|
+
};
|
|
318
|
+
function getSizeDescription(size) {
|
|
319
|
+
return typeof size === "object" ? size.description : `${size}`;
|
|
267
320
|
}
|
|
268
321
|
|
|
269
322
|
// src/address.ts
|
|
270
|
-
|
|
323
|
+
var memoizedBase58Encoder;
|
|
324
|
+
var memoizedBase58Decoder;
|
|
325
|
+
function getMemoizedBase58Encoder() {
|
|
326
|
+
if (!memoizedBase58Encoder)
|
|
327
|
+
memoizedBase58Encoder = getBase58Encoder();
|
|
328
|
+
return memoizedBase58Encoder;
|
|
329
|
+
}
|
|
330
|
+
function getMemoizedBase58Decoder() {
|
|
331
|
+
if (!memoizedBase58Decoder)
|
|
332
|
+
memoizedBase58Decoder = getBase58Decoder();
|
|
333
|
+
return memoizedBase58Decoder;
|
|
334
|
+
}
|
|
335
|
+
function isAddress(putativeAddress) {
|
|
271
336
|
if (
|
|
272
337
|
// Lowest address (32 bytes of zeroes)
|
|
273
|
-
|
|
274
|
-
|
|
338
|
+
putativeAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
339
|
+
putativeAddress.length > 44
|
|
275
340
|
) {
|
|
276
341
|
return false;
|
|
277
342
|
}
|
|
278
|
-
const
|
|
343
|
+
const base58Encoder = getMemoizedBase58Encoder();
|
|
344
|
+
const bytes = base58Encoder.encode(putativeAddress);
|
|
279
345
|
const numBytes = bytes.byteLength;
|
|
280
346
|
if (numBytes !== 32) {
|
|
281
347
|
return false;
|
|
282
348
|
}
|
|
283
349
|
return true;
|
|
284
350
|
}
|
|
285
|
-
function assertIsAddress(
|
|
351
|
+
function assertIsAddress(putativeAddress) {
|
|
286
352
|
try {
|
|
287
353
|
if (
|
|
288
354
|
// Lowest address (32 bytes of zeroes)
|
|
289
|
-
|
|
290
|
-
|
|
355
|
+
putativeAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
356
|
+
putativeAddress.length > 44
|
|
291
357
|
) {
|
|
292
358
|
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
293
359
|
}
|
|
294
|
-
const
|
|
360
|
+
const base58Encoder = getMemoizedBase58Encoder();
|
|
361
|
+
const bytes = base58Encoder.encode(putativeAddress);
|
|
295
362
|
const numBytes = bytes.byteLength;
|
|
296
363
|
if (numBytes !== 32) {
|
|
297
364
|
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
298
365
|
}
|
|
299
|
-
} catch (
|
|
300
|
-
throw new Error(`\`${
|
|
301
|
-
cause:
|
|
366
|
+
} catch (e2) {
|
|
367
|
+
throw new Error(`\`${putativeAddress}\` is not a base-58 encoded address`, {
|
|
368
|
+
cause: e2
|
|
302
369
|
});
|
|
303
370
|
}
|
|
304
371
|
}
|
|
305
|
-
function address(
|
|
306
|
-
assertIsAddress(
|
|
307
|
-
return
|
|
372
|
+
function address(putativeAddress) {
|
|
373
|
+
assertIsAddress(putativeAddress);
|
|
374
|
+
return putativeAddress;
|
|
308
375
|
}
|
|
309
|
-
function
|
|
310
|
-
return
|
|
311
|
-
|
|
312
|
-
|
|
376
|
+
function getAddressEncoder(config) {
|
|
377
|
+
return mapEncoder(
|
|
378
|
+
getStringEncoder({
|
|
379
|
+
description: config?.description ?? "Address",
|
|
380
|
+
encoding: getMemoizedBase58Encoder(),
|
|
381
|
+
size: 32
|
|
382
|
+
}),
|
|
383
|
+
(putativeAddress) => address(putativeAddress)
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
function getAddressDecoder(config) {
|
|
387
|
+
return getStringDecoder({
|
|
388
|
+
description: config?.description ?? "Address",
|
|
389
|
+
encoding: getMemoizedBase58Decoder(),
|
|
313
390
|
size: 32
|
|
314
391
|
});
|
|
315
392
|
}
|
|
393
|
+
function getAddressCodec(config) {
|
|
394
|
+
return combineCodec(getAddressEncoder(config), getAddressDecoder(config));
|
|
395
|
+
}
|
|
316
396
|
function getAddressComparator() {
|
|
317
397
|
return new Intl.Collator("en", {
|
|
318
398
|
caseFirst: "lower",
|
|
@@ -443,7 +523,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
443
523
|
const validFormat = Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && typeof value[1] === "number";
|
|
444
524
|
if (!validFormat) {
|
|
445
525
|
throw new Error(
|
|
446
|
-
`Expected given program derived address to have the following format: [
|
|
526
|
+
`Expected given program derived address to have the following format: [Address, ProgramDerivedAddressBump].`
|
|
447
527
|
);
|
|
448
528
|
}
|
|
449
529
|
if (value[1] < 0 || value[1] > 255) {
|
|
@@ -479,10 +559,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
479
559
|
];
|
|
480
560
|
var PointOnCurveError = class extends Error {
|
|
481
561
|
};
|
|
482
|
-
async function createProgramDerivedAddress({
|
|
483
|
-
programAddress,
|
|
484
|
-
seeds
|
|
485
|
-
}) {
|
|
562
|
+
async function createProgramDerivedAddress({ programAddress, seeds }) {
|
|
486
563
|
await assertDigestCapabilityIsAvailable();
|
|
487
564
|
if (seeds.length > MAX_SEEDS) {
|
|
488
565
|
throw new Error(`A maximum of ${MAX_SEEDS} seeds may be supplied when creating an address`);
|
|
@@ -497,7 +574,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
497
574
|
return acc;
|
|
498
575
|
}, []);
|
|
499
576
|
const base58EncodedAddressCodec = getAddressCodec();
|
|
500
|
-
const programAddressBytes = base58EncodedAddressCodec.
|
|
577
|
+
const programAddressBytes = base58EncodedAddressCodec.encode(programAddress);
|
|
501
578
|
const addressBytesBuffer = await crypto.subtle.digest(
|
|
502
579
|
"SHA-256",
|
|
503
580
|
new Uint8Array([...seedBytes, ...programAddressBytes, ...PDA_MARKER_BYTES])
|
|
@@ -506,7 +583,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
506
583
|
if (await compressedPointBytesAreOnCurve(addressBytes)) {
|
|
507
584
|
throw new PointOnCurveError("Invalid seeds; point must fall off the Ed25519 curve");
|
|
508
585
|
}
|
|
509
|
-
return base58EncodedAddressCodec.
|
|
586
|
+
return base58EncodedAddressCodec.decode(addressBytes)[0];
|
|
510
587
|
}
|
|
511
588
|
async function getProgramDerivedAddress({
|
|
512
589
|
programAddress,
|
|
@@ -520,36 +597,32 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
520
597
|
seeds: [...seeds, new Uint8Array([bumpSeed])]
|
|
521
598
|
});
|
|
522
599
|
return [address2, bumpSeed];
|
|
523
|
-
} catch (
|
|
524
|
-
if (
|
|
600
|
+
} catch (e2) {
|
|
601
|
+
if (e2 instanceof PointOnCurveError) {
|
|
525
602
|
bumpSeed--;
|
|
526
603
|
} else {
|
|
527
|
-
throw
|
|
604
|
+
throw e2;
|
|
528
605
|
}
|
|
529
606
|
}
|
|
530
607
|
}
|
|
531
608
|
throw new Error("Unable to find a viable program address bump seed");
|
|
532
609
|
}
|
|
533
|
-
async function createAddressWithSeed({
|
|
534
|
-
|
|
535
|
-
programAddress,
|
|
536
|
-
seed
|
|
537
|
-
}) {
|
|
538
|
-
const { serialize, deserialize } = getAddressCodec();
|
|
610
|
+
async function createAddressWithSeed({ baseAddress, programAddress, seed }) {
|
|
611
|
+
const { encode, decode } = getAddressCodec();
|
|
539
612
|
const seedBytes = typeof seed === "string" ? new TextEncoder().encode(seed) : seed;
|
|
540
613
|
if (seedBytes.byteLength > MAX_SEED_LENGTH) {
|
|
541
614
|
throw new Error(`The seed exceeds the maximum length of 32 bytes`);
|
|
542
615
|
}
|
|
543
|
-
const programAddressBytes =
|
|
616
|
+
const programAddressBytes = encode(programAddress);
|
|
544
617
|
if (programAddressBytes.length >= PDA_MARKER_BYTES.length && programAddressBytes.slice(-PDA_MARKER_BYTES.length).every((byte, index) => byte === PDA_MARKER_BYTES[index])) {
|
|
545
618
|
throw new Error(`programAddress cannot end with the PDA marker`);
|
|
546
619
|
}
|
|
547
620
|
const addressBytesBuffer = await crypto.subtle.digest(
|
|
548
621
|
"SHA-256",
|
|
549
|
-
new Uint8Array([...
|
|
622
|
+
new Uint8Array([...encode(baseAddress), ...seedBytes, ...programAddressBytes])
|
|
550
623
|
);
|
|
551
624
|
const addressBytes = new Uint8Array(addressBytesBuffer);
|
|
552
|
-
return
|
|
625
|
+
return decode(addressBytes)[0];
|
|
553
626
|
}
|
|
554
627
|
|
|
555
628
|
// src/public-key.ts
|
|
@@ -559,7 +632,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
559
632
|
throw new Error("The `CryptoKey` must be an `Ed25519` public key");
|
|
560
633
|
}
|
|
561
634
|
const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
|
|
562
|
-
const [base58EncodedAddress] =
|
|
635
|
+
const [base58EncodedAddress] = getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
|
|
563
636
|
return base58EncodedAddress;
|
|
564
637
|
}
|
|
565
638
|
|
|
@@ -569,6 +642,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
569
642
|
exports.createAddressWithSeed = createAddressWithSeed;
|
|
570
643
|
exports.getAddressCodec = getAddressCodec;
|
|
571
644
|
exports.getAddressComparator = getAddressComparator;
|
|
645
|
+
exports.getAddressDecoder = getAddressDecoder;
|
|
646
|
+
exports.getAddressEncoder = getAddressEncoder;
|
|
572
647
|
exports.getAddressFromPublicKey = getAddressFromPublicKey;
|
|
573
648
|
exports.getProgramDerivedAddress = getProgramDerivedAddress;
|
|
574
649
|
exports.isAddress = isAddress;
|