@solana/addresses 2.0.0-experimental.fe07532 → 2.0.0-experimental.feaeef2
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 +21 -21
- package/dist/index.browser.cjs +59 -67
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +59 -67
- package/dist/index.browser.js.map +1 -1
- package/dist/index.native.js +59 -67
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +59 -67
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +59 -67
- package/dist/index.node.js.map +1 -1
- package/dist/types/address.d.ts +8 -14
- package/dist/types/address.d.ts.map +1 -0
- package/dist/types/curve.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -3
- 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 +14 -34
- package/dist/index.development.js +0 -663
- package/dist/index.development.js.map +0 -1
- package/dist/index.production.min.js +0 -22
|
@@ -1,663 +0,0 @@
|
|
|
1
|
-
this.globalThis = this.globalThis || {};
|
|
2
|
-
this.globalThis.solanaWeb3 = (function (exports) {
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
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);
|
|
26
|
-
const result = new Uint8Array(totalLength);
|
|
27
|
-
let offset = 0;
|
|
28
|
-
nonEmptyByteArrays.forEach((arr) => {
|
|
29
|
-
result.set(arr, offset);
|
|
30
|
-
offset += arr.length;
|
|
31
|
-
});
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
var padBytes = (bytes, length) => {
|
|
35
|
-
if (bytes.length >= length)
|
|
36
|
-
return bytes;
|
|
37
|
-
const paddedBytes = new Uint8Array(length).fill(0);
|
|
38
|
-
paddedBytes.set(bytes);
|
|
39
|
-
return paddedBytes;
|
|
40
|
-
};
|
|
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
|
-
);
|
|
47
|
-
}
|
|
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
|
-
);
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
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})`,
|
|
69
|
-
fixedSize: fixedBytes,
|
|
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);
|
|
86
|
-
}
|
|
87
|
-
if (decoder.fixedSize !== null) {
|
|
88
|
-
bytes = fixBytes(bytes, decoder.fixedSize);
|
|
89
|
-
}
|
|
90
|
-
const [value] = decoder.decode(bytes, 0);
|
|
91
|
-
return [value, offset + fixedBytes];
|
|
92
|
-
}
|
|
93
|
-
};
|
|
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
|
-
}
|
|
103
|
-
|
|
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
|
-
);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
function sharedNumberFactory(input) {
|
|
113
|
-
let littleEndian;
|
|
114
|
-
let defaultDescription = input.name;
|
|
115
|
-
if (input.size > 1) {
|
|
116
|
-
littleEndian = !("endian" in input.options) || input.options.endian === 0;
|
|
117
|
-
defaultDescription += littleEndian ? "(le)" : "(be)";
|
|
118
|
-
}
|
|
119
|
-
return {
|
|
120
|
-
description: input.options.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 = (options = {}) => numberEncoderFactory({
|
|
162
|
-
name: "u32",
|
|
163
|
-
options,
|
|
164
|
-
range: [0, Number("0xffffffff")],
|
|
165
|
-
set: (view, value, le) => view.setUint32(0, value, le),
|
|
166
|
-
size: 4
|
|
167
|
-
});
|
|
168
|
-
var getU32Decoder = (options = {}) => numberDecoderFactory({
|
|
169
|
-
get: (view, le) => view.getUint32(0, le),
|
|
170
|
-
name: "u32",
|
|
171
|
-
options,
|
|
172
|
-
size: 4
|
|
173
|
-
});
|
|
174
|
-
|
|
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;
|
|
183
|
-
const baseBigInt = BigInt(base);
|
|
184
|
-
return {
|
|
185
|
-
description: `base${base}`,
|
|
186
|
-
encode(value) {
|
|
187
|
-
assertValidBaseString(alphabet4, value);
|
|
188
|
-
if (value === "")
|
|
189
|
-
return new Uint8Array();
|
|
190
|
-
const chars = [...value];
|
|
191
|
-
let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
|
|
192
|
-
trailIndex = trailIndex === -1 ? chars.length : trailIndex;
|
|
193
|
-
const leadingZeroes = Array(trailIndex).fill(0);
|
|
194
|
-
if (trailIndex === chars.length)
|
|
195
|
-
return Uint8Array.from(leadingZeroes);
|
|
196
|
-
const tailChars = chars.slice(trailIndex);
|
|
197
|
-
let base10Number = 0n;
|
|
198
|
-
let baseXPower = 1n;
|
|
199
|
-
for (let i = tailChars.length - 1; i >= 0; i -= 1) {
|
|
200
|
-
base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
|
|
201
|
-
baseXPower *= baseBigInt;
|
|
202
|
-
}
|
|
203
|
-
const tailBytes = [];
|
|
204
|
-
while (base10Number > 0n) {
|
|
205
|
-
tailBytes.unshift(Number(base10Number % 256n));
|
|
206
|
-
base10Number /= 256n;
|
|
207
|
-
}
|
|
208
|
-
return Uint8Array.from(leadingZeroes.concat(tailBytes));
|
|
209
|
-
},
|
|
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)
|
|
221
|
-
return ["", 0];
|
|
222
|
-
let trailIndex = bytes.findIndex((n) => n !== 0);
|
|
223
|
-
trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
|
|
224
|
-
const leadingZeroes = alphabet4[0].repeat(trailIndex);
|
|
225
|
-
if (trailIndex === bytes.length)
|
|
226
|
-
return [leadingZeroes, rawBytes.length];
|
|
227
|
-
let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
|
|
228
|
-
const tailChars = [];
|
|
229
|
-
while (base10Number > 0n) {
|
|
230
|
-
tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
|
|
231
|
-
base10Number /= baseBigInt;
|
|
232
|
-
}
|
|
233
|
-
return [leadingZeroes + tailChars.join(""), rawBytes.length];
|
|
234
|
-
},
|
|
235
|
-
description: `base${base}`,
|
|
236
|
-
fixedSize: null,
|
|
237
|
-
maxSize: null
|
|
238
|
-
};
|
|
239
|
-
};
|
|
240
|
-
var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
241
|
-
var getBase58Encoder = () => getBaseXEncoder(alphabet2);
|
|
242
|
-
var getBase58Decoder = () => getBaseXDecoder(alphabet2);
|
|
243
|
-
var removeNullCharacters = (value) => (
|
|
244
|
-
// eslint-disable-next-line no-control-regex
|
|
245
|
-
value.replace(/\u0000/g, "")
|
|
246
|
-
);
|
|
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
|
-
};
|
|
257
|
-
};
|
|
258
|
-
var getUtf8Decoder = () => {
|
|
259
|
-
let textDecoder;
|
|
260
|
-
return {
|
|
261
|
-
decode(bytes, offset = 0) {
|
|
262
|
-
const value = (textDecoder || (textDecoder = new e())).decode(bytes.slice(offset));
|
|
263
|
-
return [removeNullCharacters(value), bytes.length];
|
|
264
|
-
},
|
|
265
|
-
description: "utf8",
|
|
266
|
-
fixedSize: null,
|
|
267
|
-
maxSize: null
|
|
268
|
-
};
|
|
269
|
-
};
|
|
270
|
-
var getStringEncoder = (options = {}) => {
|
|
271
|
-
const size = options.size ?? getU32Encoder();
|
|
272
|
-
const encoding = options.encoding ?? getUtf8Encoder();
|
|
273
|
-
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
|
|
274
|
-
if (size === "variable") {
|
|
275
|
-
return { ...encoding, description };
|
|
276
|
-
}
|
|
277
|
-
if (typeof size === "number") {
|
|
278
|
-
return fixEncoder(encoding, size, description);
|
|
279
|
-
}
|
|
280
|
-
return {
|
|
281
|
-
description,
|
|
282
|
-
encode: (value) => {
|
|
283
|
-
const contentBytes = encoding.encode(value);
|
|
284
|
-
const lengthBytes = size.encode(contentBytes.length);
|
|
285
|
-
return mergeBytes([lengthBytes, contentBytes]);
|
|
286
|
-
},
|
|
287
|
-
fixedSize: null,
|
|
288
|
-
maxSize: null
|
|
289
|
-
};
|
|
290
|
-
};
|
|
291
|
-
var getStringDecoder = (options = {}) => {
|
|
292
|
-
const size = options.size ?? getU32Decoder();
|
|
293
|
-
const encoding = options.encoding ?? getUtf8Decoder();
|
|
294
|
-
const description = options.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);
|
|
305
|
-
const length = Number(lengthBigInt);
|
|
306
|
-
offset = lengthOffset;
|
|
307
|
-
const contentBytes = bytes.slice(offset, offset + length);
|
|
308
|
-
assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
|
|
309
|
-
const [value, contentOffset] = encoding.decode(contentBytes);
|
|
310
|
-
offset += contentOffset;
|
|
311
|
-
return [value, offset];
|
|
312
|
-
},
|
|
313
|
-
description,
|
|
314
|
-
fixedSize: null,
|
|
315
|
-
maxSize: null
|
|
316
|
-
};
|
|
317
|
-
};
|
|
318
|
-
function getSizeDescription(size) {
|
|
319
|
-
return typeof size === "object" ? size.description : `${size}`;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
// src/address.ts
|
|
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(putativeBase58EncodedAddress) {
|
|
336
|
-
if (
|
|
337
|
-
// Lowest address (32 bytes of zeroes)
|
|
338
|
-
putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
339
|
-
putativeBase58EncodedAddress.length > 44
|
|
340
|
-
) {
|
|
341
|
-
return false;
|
|
342
|
-
}
|
|
343
|
-
const base58Encoder = getMemoizedBase58Encoder();
|
|
344
|
-
const bytes = base58Encoder.encode(putativeBase58EncodedAddress);
|
|
345
|
-
const numBytes = bytes.byteLength;
|
|
346
|
-
if (numBytes !== 32) {
|
|
347
|
-
return false;
|
|
348
|
-
}
|
|
349
|
-
return true;
|
|
350
|
-
}
|
|
351
|
-
function assertIsAddress(putativeBase58EncodedAddress) {
|
|
352
|
-
try {
|
|
353
|
-
if (
|
|
354
|
-
// Lowest address (32 bytes of zeroes)
|
|
355
|
-
putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
356
|
-
putativeBase58EncodedAddress.length > 44
|
|
357
|
-
) {
|
|
358
|
-
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
359
|
-
}
|
|
360
|
-
const base58Encoder = getMemoizedBase58Encoder();
|
|
361
|
-
const bytes = base58Encoder.encode(putativeBase58EncodedAddress);
|
|
362
|
-
const numBytes = bytes.byteLength;
|
|
363
|
-
if (numBytes !== 32) {
|
|
364
|
-
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
365
|
-
}
|
|
366
|
-
} catch (e2) {
|
|
367
|
-
throw new Error(`\`${putativeBase58EncodedAddress}\` is not a base-58 encoded address`, {
|
|
368
|
-
cause: e2
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
function address(putativeBase58EncodedAddress) {
|
|
373
|
-
assertIsAddress(putativeBase58EncodedAddress);
|
|
374
|
-
return putativeBase58EncodedAddress;
|
|
375
|
-
}
|
|
376
|
-
function getAddressEncoder(config) {
|
|
377
|
-
return mapEncoder(
|
|
378
|
-
getStringEncoder({
|
|
379
|
-
description: config?.description ?? "Base58EncodedAddress",
|
|
380
|
-
encoding: getMemoizedBase58Encoder(),
|
|
381
|
-
size: 32
|
|
382
|
-
}),
|
|
383
|
-
(putativeAddress) => address(putativeAddress)
|
|
384
|
-
);
|
|
385
|
-
}
|
|
386
|
-
function getAddressDecoder(config) {
|
|
387
|
-
return getStringDecoder({
|
|
388
|
-
description: config?.description ?? "Base58EncodedAddress",
|
|
389
|
-
encoding: getMemoizedBase58Decoder(),
|
|
390
|
-
size: 32
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
function getAddressCodec(config) {
|
|
394
|
-
return combineCodec(getAddressEncoder(config), getAddressDecoder(config));
|
|
395
|
-
}
|
|
396
|
-
function getAddressComparator() {
|
|
397
|
-
return new Intl.Collator("en", {
|
|
398
|
-
caseFirst: "lower",
|
|
399
|
-
ignorePunctuation: false,
|
|
400
|
-
localeMatcher: "best fit",
|
|
401
|
-
numeric: false,
|
|
402
|
-
sensitivity: "variant",
|
|
403
|
-
usage: "sort"
|
|
404
|
-
}).compare;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
// ../assertions/dist/index.browser.js
|
|
408
|
-
function assertIsSecureContext() {
|
|
409
|
-
if (!globalThis.isSecureContext) {
|
|
410
|
-
throw new Error(
|
|
411
|
-
"Cryptographic operations are only allowed in secure browser contexts. Read more here: https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts"
|
|
412
|
-
);
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
async function assertDigestCapabilityIsAvailable() {
|
|
416
|
-
assertIsSecureContext();
|
|
417
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.digest !== "function") {
|
|
418
|
-
throw new Error("No digest implementation could be found");
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
async function assertKeyExporterIsAvailable() {
|
|
422
|
-
assertIsSecureContext();
|
|
423
|
-
if (typeof globalThis.crypto === "undefined" || typeof globalThis.crypto.subtle?.exportKey !== "function") {
|
|
424
|
-
throw new Error("No key export implementation could be found");
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
// src/vendor/noble/ed25519.ts
|
|
429
|
-
var D = 37095705934669439343138083508754565189542113879843219016388785533085940283555n;
|
|
430
|
-
var P = 57896044618658097711785492504343953926634992332820282019728792003956564819949n;
|
|
431
|
-
var RM1 = 19681161376707505956807079304988542015446066515923890162744021073123829784752n;
|
|
432
|
-
function mod(a) {
|
|
433
|
-
const r = a % P;
|
|
434
|
-
return r >= 0n ? r : P + r;
|
|
435
|
-
}
|
|
436
|
-
function pow2(x, power) {
|
|
437
|
-
let r = x;
|
|
438
|
-
while (power-- > 0n) {
|
|
439
|
-
r *= r;
|
|
440
|
-
r %= P;
|
|
441
|
-
}
|
|
442
|
-
return r;
|
|
443
|
-
}
|
|
444
|
-
function pow_2_252_3(x) {
|
|
445
|
-
const x2 = x * x % P;
|
|
446
|
-
const b2 = x2 * x % P;
|
|
447
|
-
const b4 = pow2(b2, 2n) * b2 % P;
|
|
448
|
-
const b5 = pow2(b4, 1n) * x % P;
|
|
449
|
-
const b10 = pow2(b5, 5n) * b5 % P;
|
|
450
|
-
const b20 = pow2(b10, 10n) * b10 % P;
|
|
451
|
-
const b40 = pow2(b20, 20n) * b20 % P;
|
|
452
|
-
const b80 = pow2(b40, 40n) * b40 % P;
|
|
453
|
-
const b160 = pow2(b80, 80n) * b80 % P;
|
|
454
|
-
const b240 = pow2(b160, 80n) * b80 % P;
|
|
455
|
-
const b250 = pow2(b240, 10n) * b10 % P;
|
|
456
|
-
const pow_p_5_8 = pow2(b250, 2n) * x % P;
|
|
457
|
-
return pow_p_5_8;
|
|
458
|
-
}
|
|
459
|
-
function uvRatio(u, v) {
|
|
460
|
-
const v3 = mod(v * v * v);
|
|
461
|
-
const v7 = mod(v3 * v3 * v);
|
|
462
|
-
const pow = pow_2_252_3(u * v7);
|
|
463
|
-
let x = mod(u * v3 * pow);
|
|
464
|
-
const vx2 = mod(v * x * x);
|
|
465
|
-
const root1 = x;
|
|
466
|
-
const root2 = mod(x * RM1);
|
|
467
|
-
const useRoot1 = vx2 === u;
|
|
468
|
-
const useRoot2 = vx2 === mod(-u);
|
|
469
|
-
const noRoot = vx2 === mod(-u * RM1);
|
|
470
|
-
if (useRoot1)
|
|
471
|
-
x = root1;
|
|
472
|
-
if (useRoot2 || noRoot)
|
|
473
|
-
x = root2;
|
|
474
|
-
if ((mod(x) & 1n) === 1n)
|
|
475
|
-
x = mod(-x);
|
|
476
|
-
if (!useRoot1 && !useRoot2) {
|
|
477
|
-
return null;
|
|
478
|
-
}
|
|
479
|
-
return x;
|
|
480
|
-
}
|
|
481
|
-
function pointIsOnCurve(y, lastByte) {
|
|
482
|
-
const y2 = mod(y * y);
|
|
483
|
-
const u = mod(y2 - 1n);
|
|
484
|
-
const v = mod(D * y2 + 1n);
|
|
485
|
-
const x = uvRatio(u, v);
|
|
486
|
-
if (x === null) {
|
|
487
|
-
return false;
|
|
488
|
-
}
|
|
489
|
-
const isLastByteOdd = (lastByte & 128) !== 0;
|
|
490
|
-
if (x === 0n && isLastByteOdd) {
|
|
491
|
-
return false;
|
|
492
|
-
}
|
|
493
|
-
return true;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
// src/curve.ts
|
|
497
|
-
function byteToHex(byte) {
|
|
498
|
-
const hexString = byte.toString(16);
|
|
499
|
-
if (hexString.length === 1) {
|
|
500
|
-
return `0${hexString}`;
|
|
501
|
-
} else {
|
|
502
|
-
return hexString;
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
function decompressPointBytes(bytes) {
|
|
506
|
-
const hexString = bytes.reduce((acc, byte, ii) => `${byteToHex(ii === 31 ? byte & ~128 : byte)}${acc}`, "");
|
|
507
|
-
const integerLiteralString = `0x${hexString}`;
|
|
508
|
-
return BigInt(integerLiteralString);
|
|
509
|
-
}
|
|
510
|
-
async function compressedPointBytesAreOnCurve(bytes) {
|
|
511
|
-
if (bytes.byteLength !== 32) {
|
|
512
|
-
return false;
|
|
513
|
-
}
|
|
514
|
-
const y = decompressPointBytes(bytes);
|
|
515
|
-
return pointIsOnCurve(y, bytes[31]);
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
// src/program-derived-address.ts
|
|
519
|
-
function isProgramDerivedAddress(value) {
|
|
520
|
-
return Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && typeof value[1] === "number" && value[1] >= 0 && value[1] <= 255 && isAddress(value[0]);
|
|
521
|
-
}
|
|
522
|
-
function assertIsProgramDerivedAddress(value) {
|
|
523
|
-
const validFormat = Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && typeof value[1] === "number";
|
|
524
|
-
if (!validFormat) {
|
|
525
|
-
throw new Error(
|
|
526
|
-
`Expected given program derived address to have the following format: [Base58EncodedAddress, ProgramDerivedAddressBump].`
|
|
527
|
-
);
|
|
528
|
-
}
|
|
529
|
-
if (value[1] < 0 || value[1] > 255) {
|
|
530
|
-
throw new Error(`Expected program derived address bump to be in the range [0, 255], got: ${value[1]}.`);
|
|
531
|
-
}
|
|
532
|
-
assertIsAddress(value[0]);
|
|
533
|
-
}
|
|
534
|
-
var MAX_SEED_LENGTH = 32;
|
|
535
|
-
var MAX_SEEDS = 16;
|
|
536
|
-
var PDA_MARKER_BYTES = [
|
|
537
|
-
// The string 'ProgramDerivedAddress'
|
|
538
|
-
80,
|
|
539
|
-
114,
|
|
540
|
-
111,
|
|
541
|
-
103,
|
|
542
|
-
114,
|
|
543
|
-
97,
|
|
544
|
-
109,
|
|
545
|
-
68,
|
|
546
|
-
101,
|
|
547
|
-
114,
|
|
548
|
-
105,
|
|
549
|
-
118,
|
|
550
|
-
101,
|
|
551
|
-
100,
|
|
552
|
-
65,
|
|
553
|
-
100,
|
|
554
|
-
100,
|
|
555
|
-
114,
|
|
556
|
-
101,
|
|
557
|
-
115,
|
|
558
|
-
115
|
|
559
|
-
];
|
|
560
|
-
var PointOnCurveError = class extends Error {
|
|
561
|
-
};
|
|
562
|
-
async function createProgramDerivedAddress({
|
|
563
|
-
programAddress,
|
|
564
|
-
seeds
|
|
565
|
-
}) {
|
|
566
|
-
await assertDigestCapabilityIsAvailable();
|
|
567
|
-
if (seeds.length > MAX_SEEDS) {
|
|
568
|
-
throw new Error(`A maximum of ${MAX_SEEDS} seeds may be supplied when creating an address`);
|
|
569
|
-
}
|
|
570
|
-
let textEncoder;
|
|
571
|
-
const seedBytes = seeds.reduce((acc, seed, ii) => {
|
|
572
|
-
const bytes = typeof seed === "string" ? (textEncoder || (textEncoder = new TextEncoder())).encode(seed) : seed;
|
|
573
|
-
if (bytes.byteLength > MAX_SEED_LENGTH) {
|
|
574
|
-
throw new Error(`The seed at index ${ii} exceeds the maximum length of 32 bytes`);
|
|
575
|
-
}
|
|
576
|
-
acc.push(...bytes);
|
|
577
|
-
return acc;
|
|
578
|
-
}, []);
|
|
579
|
-
const base58EncodedAddressCodec = getAddressCodec();
|
|
580
|
-
const programAddressBytes = base58EncodedAddressCodec.encode(programAddress);
|
|
581
|
-
const addressBytesBuffer = await crypto.subtle.digest(
|
|
582
|
-
"SHA-256",
|
|
583
|
-
new Uint8Array([...seedBytes, ...programAddressBytes, ...PDA_MARKER_BYTES])
|
|
584
|
-
);
|
|
585
|
-
const addressBytes = new Uint8Array(addressBytesBuffer);
|
|
586
|
-
if (await compressedPointBytesAreOnCurve(addressBytes)) {
|
|
587
|
-
throw new PointOnCurveError("Invalid seeds; point must fall off the Ed25519 curve");
|
|
588
|
-
}
|
|
589
|
-
return base58EncodedAddressCodec.decode(addressBytes)[0];
|
|
590
|
-
}
|
|
591
|
-
async function getProgramDerivedAddress({
|
|
592
|
-
programAddress,
|
|
593
|
-
seeds
|
|
594
|
-
}) {
|
|
595
|
-
let bumpSeed = 255;
|
|
596
|
-
while (bumpSeed > 0) {
|
|
597
|
-
try {
|
|
598
|
-
const address2 = await createProgramDerivedAddress({
|
|
599
|
-
programAddress,
|
|
600
|
-
seeds: [...seeds, new Uint8Array([bumpSeed])]
|
|
601
|
-
});
|
|
602
|
-
return [address2, bumpSeed];
|
|
603
|
-
} catch (e2) {
|
|
604
|
-
if (e2 instanceof PointOnCurveError) {
|
|
605
|
-
bumpSeed--;
|
|
606
|
-
} else {
|
|
607
|
-
throw e2;
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
throw new Error("Unable to find a viable program address bump seed");
|
|
612
|
-
}
|
|
613
|
-
async function createAddressWithSeed({
|
|
614
|
-
baseAddress,
|
|
615
|
-
programAddress,
|
|
616
|
-
seed
|
|
617
|
-
}) {
|
|
618
|
-
const { encode, decode } = getAddressCodec();
|
|
619
|
-
const seedBytes = typeof seed === "string" ? new TextEncoder().encode(seed) : seed;
|
|
620
|
-
if (seedBytes.byteLength > MAX_SEED_LENGTH) {
|
|
621
|
-
throw new Error(`The seed exceeds the maximum length of 32 bytes`);
|
|
622
|
-
}
|
|
623
|
-
const programAddressBytes = encode(programAddress);
|
|
624
|
-
if (programAddressBytes.length >= PDA_MARKER_BYTES.length && programAddressBytes.slice(-PDA_MARKER_BYTES.length).every((byte, index) => byte === PDA_MARKER_BYTES[index])) {
|
|
625
|
-
throw new Error(`programAddress cannot end with the PDA marker`);
|
|
626
|
-
}
|
|
627
|
-
const addressBytesBuffer = await crypto.subtle.digest(
|
|
628
|
-
"SHA-256",
|
|
629
|
-
new Uint8Array([...encode(baseAddress), ...seedBytes, ...programAddressBytes])
|
|
630
|
-
);
|
|
631
|
-
const addressBytes = new Uint8Array(addressBytesBuffer);
|
|
632
|
-
return decode(addressBytes)[0];
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
// src/public-key.ts
|
|
636
|
-
async function getAddressFromPublicKey(publicKey) {
|
|
637
|
-
await assertKeyExporterIsAvailable();
|
|
638
|
-
if (publicKey.type !== "public" || publicKey.algorithm.name !== "Ed25519") {
|
|
639
|
-
throw new Error("The `CryptoKey` must be an `Ed25519` public key");
|
|
640
|
-
}
|
|
641
|
-
const publicKeyBytes = await crypto.subtle.exportKey("raw", publicKey);
|
|
642
|
-
const [base58EncodedAddress] = getAddressDecoder().decode(new Uint8Array(publicKeyBytes));
|
|
643
|
-
return base58EncodedAddress;
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
exports.address = address;
|
|
647
|
-
exports.assertIsAddress = assertIsAddress;
|
|
648
|
-
exports.assertIsProgramDerivedAddress = assertIsProgramDerivedAddress;
|
|
649
|
-
exports.createAddressWithSeed = createAddressWithSeed;
|
|
650
|
-
exports.getAddressCodec = getAddressCodec;
|
|
651
|
-
exports.getAddressComparator = getAddressComparator;
|
|
652
|
-
exports.getAddressDecoder = getAddressDecoder;
|
|
653
|
-
exports.getAddressEncoder = getAddressEncoder;
|
|
654
|
-
exports.getAddressFromPublicKey = getAddressFromPublicKey;
|
|
655
|
-
exports.getProgramDerivedAddress = getProgramDerivedAddress;
|
|
656
|
-
exports.isAddress = isAddress;
|
|
657
|
-
exports.isProgramDerivedAddress = isProgramDerivedAddress;
|
|
658
|
-
|
|
659
|
-
return exports;
|
|
660
|
-
|
|
661
|
-
})({});
|
|
662
|
-
//# sourceMappingURL=out.js.map
|
|
663
|
-
//# sourceMappingURL=index.development.js.map
|