@solana/codecs-strings 2.0.0-20241006045741

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 ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2023 Solana Labs, Inc
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,201 @@
1
+ [![npm][npm-image]][npm-url]
2
+ [![npm-downloads][npm-downloads-image]][npm-url]
3
+ [![semantic-release][semantic-release-image]][semantic-release-url]
4
+ <br />
5
+ [![code-style-prettier][code-style-prettier-image]][code-style-prettier-url]
6
+
7
+ [code-style-prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square
8
+ [code-style-prettier-url]: https://github.com/prettier/prettier
9
+ [npm-downloads-image]: https://img.shields.io/npm/dm/@solana/codecs-strings/rc.svg?style=flat
10
+ [npm-image]: https://img.shields.io/npm/v/@solana/codecs-strings/rc.svg?style=flat
11
+ [npm-url]: https://www.npmjs.com/package/@solana/codecs-strings/v/rc
12
+ [semantic-release-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
13
+ [semantic-release-url]: https://github.com/semantic-release/semantic-release
14
+
15
+ # @solana/codecs-strings
16
+
17
+ This package contains codecs for strings of different sizes and encodings. It can be used standalone, but it is also exported as part of the Solana JavaScript SDK [`@solana/web3.js@rc`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/library).
18
+
19
+ This package is also part of the [`@solana/codecs` package](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs) which acts as an entry point for all codec packages as well as for their documentation.
20
+
21
+ ## Sizing string codecs
22
+
23
+ The `@solana/codecs-strings` package offers a variety of string codecs such as `utf8`, `base58`, `base64`, etc — which we will discuss in more detail below. However, before digging into the available string codecs, it's important to understand the different sizing strategies available for string codecs.
24
+
25
+ By default, all available string codecs will return a `VariableSizeCodec<string>` meaning that:
26
+
27
+ - When encoding a string, all bytes necessary to encode the string will be used.
28
+ - When decoding a byte array at a given offset, all bytes starting from that offset will be decoded as a string.
29
+
30
+ For instance, here's how you can encode/decode `utf8` strings without any size boundary:
31
+
32
+ ```ts
33
+ const codec = getUtf8Codec();
34
+
35
+ codec.encode('hello');
36
+ // 0x68656c6c6f
37
+ // └-- Any bytes necessary to encode our content.
38
+
39
+ codec.decode(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f]));
40
+ // 'hello'
41
+ ```
42
+
43
+ This might be what you want — e.g. when having a string at the end of a data structure — but in many cases, you might want to have a size boundary for your string. You may achieve this by composing your string codec with the [`fixCodecSize`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-core#fixing-the-size-of-codecs) or [`addCodecSizePrefix`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs-core#prefixing-the-size-of-codecs) functions.
44
+
45
+ The `fixCodecSize` function accepts a fixed byte length and returns a `FixedSizeCodec<string>` that will always use that amount of bytes to encode and decode a string. Any string longer or smaller than that size will be truncated or padded respectively. Here's how you can use it with a `utf8` codec:
46
+
47
+ ```ts
48
+ const codec = fixCodecSize(getUtf8Codec(), 5);
49
+
50
+ codec.encode('hello');
51
+ // 0x68656c6c6f
52
+ // └-- The exact 5 bytes of content.
53
+
54
+ codec.encode('hello world');
55
+ // 0x68656c6c6f
56
+ // └-- The truncated 5 bytes of content.
57
+
58
+ codec.encode('hell');
59
+ // 0x68656c6c00
60
+ // └-- The padded 5 bytes of content.
61
+
62
+ codec.decode(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f, 0xff, 0xff, 0xff, 0xff]));
63
+ // 'hello'
64
+ ```
65
+
66
+ The `addCodecSizePrefix` function accepts an additional number codec that will be used to encode and decode a size prefix for the string. This prefix allows us to know when to stop reading the string when decoding a given byte array. Here's how you can use it with a `utf8` codec:
67
+
68
+ ```ts
69
+ const codec = addCodecSizePrefix(getUtf8Codec(), getU32Codec());
70
+
71
+ codec.encode('hello');
72
+ // 0x0500000068656c6c6f
73
+ // | └-- The 5 bytes of content.
74
+ // └-- 4-byte prefix telling us to read 5 bytes.
75
+
76
+ codec.decode(new Uint8Array([0x05, 0x00, 0x00, 0x00, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0xff, 0xff, 0xff, 0xff]));
77
+ // "hello"
78
+ ```
79
+
80
+ Now, let's take a look at the available string encodings. Just remember that you can use the `fixSizeCodec` or `prefixSizeCodec` functions on any of these encodings to add a size boundary to them.
81
+
82
+ ## Utf8 codec
83
+
84
+ The `getUtf8Codec` function encodes and decodes a UTF-8 string to and from a byte array.
85
+
86
+ ```ts
87
+ const bytes = getUtf8Codec().encode('hello'); // 0x68656c6c6f
88
+ const value = getUtf8Codec().decode(bytes); // "hello"
89
+ ```
90
+
91
+ As usual, separate `getUtf8Encoder` and `getUtf8Decoder` functions are also available.
92
+
93
+ ```ts
94
+ const bytes = getUtf8Encoder().encode('hello'); // 0x68656c6c6f
95
+ const value = getUtf8Decoder().decode(bytes); // "hello"
96
+ ```
97
+
98
+ ## Base 64 codec
99
+
100
+ The `getBase64Codec` function encodes and decodes a base-64 string to and from a byte array.
101
+
102
+ ```ts
103
+ const bytes = getBase64Codec().encode('hello+world'); // 0x85e965a3ec28ae57
104
+ const value = getBase64Codec().decode(bytes); // "hello+world"
105
+ ```
106
+
107
+ As usual, separate `getBase64Encoder` and `getBase64Decoder` functions are also available.
108
+
109
+ ```ts
110
+ const bytes = getBase64Encoder().encode('hello+world'); // 0x85e965a3ec28ae57
111
+ const value = getBase64Decoder().decode(bytes); // "hello+world"
112
+ ```
113
+
114
+ ## Base 58 codec
115
+
116
+ The `getBase58Codec` function encodes and decodes a base-58 string to and from a byte array.
117
+
118
+ ```ts
119
+ const bytes = getBase58Codec().encode('heLLo'); // 0x1b6a3070
120
+ const value = getBase58Codec().decode(bytes); // "heLLo"
121
+ ```
122
+
123
+ As usual, separate `getBase58Encoder` and `getBase58Decoder` functions are also available.
124
+
125
+ ```ts
126
+ const bytes = getBase58Encoder().encode('heLLo'); // 0x1b6a3070
127
+ const value = getBase58Decoder().decode(bytes); // "heLLo"
128
+ ```
129
+
130
+ ## Base 16 codec
131
+
132
+ The `getBase16Codec` function encodes and decodes a base-16 string to and from a byte array.
133
+
134
+ ```ts
135
+ const bytes = getBase16Codec().encode('deadface'); // 0xdeadface
136
+ const value = getBase16Codec().decode(bytes); // "deadface"
137
+ ```
138
+
139
+ As usual, separate `getBase16Encoder` and `getBase16Decoder` functions are also available.
140
+
141
+ ```ts
142
+ const bytes = getBase16Encoder().encode('deadface'); // 0xdeadface
143
+ const value = getBase16Decoder().decode(bytes); // "deadface"
144
+ ```
145
+
146
+ ## Base 10 codec
147
+
148
+ The `getBase10Codec` function encodes and decodes a base-10 string to and from a byte array.
149
+
150
+ ```ts
151
+ const bytes = getBase10Codec().encode('1024'); // 0x0400
152
+ const value = getBase10Codec().decode(bytes); // "1024"
153
+ ```
154
+
155
+ As usual, separate `getBase10Encoder` and `getBase10Decoder` functions are also available.
156
+
157
+ ```ts
158
+ const bytes = getBase10Encoder().encode('1024'); // 0x0400
159
+ const value = getBase10Decoder().decode(bytes); // "1024"
160
+ ```
161
+
162
+ ## Base X codec
163
+
164
+ The `getBaseXCodec` accepts a custom `alphabet` of `X` characters and creates a base-X codec using that alphabet. It does so by iteratively dividing by `X` and handling leading zeros.
165
+
166
+ The base-10 and base-58 codecs use this base-x codec under the hood.
167
+
168
+ ```ts
169
+ const alphabet = '0ehlo';
170
+ const bytes = getBaseXCodec(alphabet).encode('hello'); // 0x05bd
171
+ const value = getBaseXCodec(alphabet).decode(bytes); // "hello"
172
+ ```
173
+
174
+ As usual, separate `getBaseXEncoder` and `getBaseXDecoder` functions are also available.
175
+
176
+ ```ts
177
+ const bytes = getBaseXEncoder(alphabet).encode('hello'); // 0x05bd
178
+ const value = getBaseXDecoder(alphabet).decode(bytes); // "hello"
179
+ ```
180
+
181
+ ## Re-slicing base X codec
182
+
183
+ The `getBaseXResliceCodec` also creates a base-x codec but uses a different strategy. It re-slices bytes into custom chunks of bits that are then mapped to a provided `alphabet`. The number of bits per chunk is also provided and should typically be set to `log2(alphabet.length)`.
184
+
185
+ This is typically used to create codecs whose alphabet’s length is a power of 2 such as base-16 or base-64.
186
+
187
+ ```ts
188
+ const bytes = getBaseXResliceCodec('elho', 2).encode('hellolol'); // 0x4aee
189
+ const value = getBaseXResliceCodec('elho', 2).decode(bytes); // "hellolol"
190
+ ```
191
+
192
+ As usual, separate `getBaseXResliceEncoder` and `getBaseXResliceDecoder` functions are also available.
193
+
194
+ ```ts
195
+ const bytes = getBaseXResliceEncoder('elho', 2).encode('hellolol'); // 0x4aee
196
+ const value = getBaseXResliceDecoder('elho', 2).decode(bytes); // "hellolol"
197
+ ```
198
+
199
+ ---
200
+
201
+ To read more about the available codecs and how to use them, check out the documentation of the main [`@solana/codecs` package](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs).
@@ -0,0 +1,288 @@
1
+ 'use strict';
2
+
3
+ var errors = require('@solana/errors');
4
+ var codecsCore = require('@solana/codecs-core');
5
+
6
+ // src/assertions.ts
7
+ function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
8
+ if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
9
+ throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__INVALID_STRING_FOR_BASE, {
10
+ alphabet: alphabet4,
11
+ base: alphabet4.length,
12
+ value: givenValue
13
+ });
14
+ }
15
+ }
16
+ var getBaseXEncoder = (alphabet4) => {
17
+ return codecsCore.createEncoder({
18
+ getSizeFromValue: (value) => {
19
+ const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet4[0]);
20
+ if (!tailChars) return value.length;
21
+ const base10Number = getBigIntFromBaseX(tailChars, alphabet4);
22
+ return leadingZeroes.length + Math.ceil(base10Number.toString(16).length / 2);
23
+ },
24
+ write(value, bytes, offset) {
25
+ assertValidBaseString(alphabet4, value);
26
+ if (value === "") return offset;
27
+ const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet4[0]);
28
+ if (!tailChars) {
29
+ bytes.set(new Uint8Array(leadingZeroes.length).fill(0), offset);
30
+ return offset + leadingZeroes.length;
31
+ }
32
+ let base10Number = getBigIntFromBaseX(tailChars, alphabet4);
33
+ const tailBytes = [];
34
+ while (base10Number > 0n) {
35
+ tailBytes.unshift(Number(base10Number % 256n));
36
+ base10Number /= 256n;
37
+ }
38
+ const bytesToAdd = [...Array(leadingZeroes.length).fill(0), ...tailBytes];
39
+ bytes.set(bytesToAdd, offset);
40
+ return offset + bytesToAdd.length;
41
+ }
42
+ });
43
+ };
44
+ var getBaseXDecoder = (alphabet4) => {
45
+ return codecsCore.createDecoder({
46
+ read(rawBytes, offset) {
47
+ const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
48
+ if (bytes.length === 0) return ["", 0];
49
+ let trailIndex = bytes.findIndex((n) => n !== 0);
50
+ trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
51
+ const leadingZeroes = alphabet4[0].repeat(trailIndex);
52
+ if (trailIndex === bytes.length) return [leadingZeroes, rawBytes.length];
53
+ const base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
54
+ const tailChars = getBaseXFromBigInt(base10Number, alphabet4);
55
+ return [leadingZeroes + tailChars, rawBytes.length];
56
+ }
57
+ });
58
+ };
59
+ var getBaseXCodec = (alphabet4) => codecsCore.combineCodec(getBaseXEncoder(alphabet4), getBaseXDecoder(alphabet4));
60
+ function partitionLeadingZeroes(value, zeroCharacter) {
61
+ const [leadingZeros, tailChars] = value.split(new RegExp(`((?!${zeroCharacter}).*)`));
62
+ return [leadingZeros, tailChars];
63
+ }
64
+ function getBigIntFromBaseX(value, alphabet4) {
65
+ const base = BigInt(alphabet4.length);
66
+ let sum = 0n;
67
+ for (const char of value) {
68
+ sum *= base;
69
+ sum += BigInt(alphabet4.indexOf(char));
70
+ }
71
+ return sum;
72
+ }
73
+ function getBaseXFromBigInt(value, alphabet4) {
74
+ const base = BigInt(alphabet4.length);
75
+ const tailChars = [];
76
+ while (value > 0n) {
77
+ tailChars.unshift(alphabet4[Number(value % base)]);
78
+ value /= base;
79
+ }
80
+ return tailChars.join("");
81
+ }
82
+
83
+ // src/base10.ts
84
+ var alphabet = "0123456789";
85
+ var getBase10Encoder = () => getBaseXEncoder(alphabet);
86
+ var getBase10Decoder = () => getBaseXDecoder(alphabet);
87
+ var getBase10Codec = () => getBaseXCodec(alphabet);
88
+ var INVALID_STRING_ERROR_BASE_CONFIG = {
89
+ alphabet: "0123456789abcdef",
90
+ base: 16
91
+ };
92
+ function charCodeToBase16(char) {
93
+ if (char >= 48 /* ZERO */ && char <= 57 /* NINE */) return char - 48 /* ZERO */;
94
+ if (char >= 65 /* A_UP */ && char <= 70 /* F_UP */) return char - (65 /* A_UP */ - 10);
95
+ if (char >= 97 /* A_LO */ && char <= 102 /* F_LO */) return char - (97 /* A_LO */ - 10);
96
+ }
97
+ var getBase16Encoder = () => codecsCore.createEncoder({
98
+ getSizeFromValue: (value) => Math.ceil(value.length / 2),
99
+ write(value, bytes, offset) {
100
+ const len = value.length;
101
+ const al = len / 2;
102
+ if (len === 1) {
103
+ const c = value.charCodeAt(0);
104
+ const n = charCodeToBase16(c);
105
+ if (n === void 0) {
106
+ throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__INVALID_STRING_FOR_BASE, {
107
+ ...INVALID_STRING_ERROR_BASE_CONFIG,
108
+ value
109
+ });
110
+ }
111
+ bytes.set([n], offset);
112
+ return 1 + offset;
113
+ }
114
+ const hexBytes = new Uint8Array(al);
115
+ for (let i = 0, j = 0; i < al; i++) {
116
+ const c1 = value.charCodeAt(j++);
117
+ const c2 = value.charCodeAt(j++);
118
+ const n1 = charCodeToBase16(c1);
119
+ const n2 = charCodeToBase16(c2);
120
+ if (n1 === void 0 || n2 === void 0 && !Number.isNaN(c2)) {
121
+ throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__INVALID_STRING_FOR_BASE, {
122
+ ...INVALID_STRING_ERROR_BASE_CONFIG,
123
+ value
124
+ });
125
+ }
126
+ hexBytes[i] = !Number.isNaN(c2) ? n1 << 4 | (n2 ?? 0) : n1;
127
+ }
128
+ bytes.set(hexBytes, offset);
129
+ return hexBytes.length + offset;
130
+ }
131
+ });
132
+ var getBase16Decoder = () => codecsCore.createDecoder({
133
+ read(bytes, offset) {
134
+ const value = bytes.slice(offset).reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
135
+ return [value, bytes.length];
136
+ }
137
+ });
138
+ var getBase16Codec = () => codecsCore.combineCodec(getBase16Encoder(), getBase16Decoder());
139
+
140
+ // src/base58.ts
141
+ var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
142
+ var getBase58Encoder = () => getBaseXEncoder(alphabet2);
143
+ var getBase58Decoder = () => getBaseXDecoder(alphabet2);
144
+ var getBase58Codec = () => getBaseXCodec(alphabet2);
145
+ var getBaseXResliceEncoder = (alphabet4, bits) => codecsCore.createEncoder({
146
+ getSizeFromValue: (value) => Math.floor(value.length * bits / 8),
147
+ write(value, bytes, offset) {
148
+ assertValidBaseString(alphabet4, value);
149
+ if (value === "") return offset;
150
+ const charIndices = [...value].map((c) => alphabet4.indexOf(c));
151
+ const reslicedBytes = reslice(charIndices, bits, 8, false);
152
+ bytes.set(reslicedBytes, offset);
153
+ return reslicedBytes.length + offset;
154
+ }
155
+ });
156
+ var getBaseXResliceDecoder = (alphabet4, bits) => codecsCore.createDecoder({
157
+ read(rawBytes, offset = 0) {
158
+ const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
159
+ if (bytes.length === 0) return ["", rawBytes.length];
160
+ const charIndices = reslice([...bytes], 8, bits, true);
161
+ return [charIndices.map((i) => alphabet4[i]).join(""), rawBytes.length];
162
+ }
163
+ });
164
+ var getBaseXResliceCodec = (alphabet4, bits) => codecsCore.combineCodec(getBaseXResliceEncoder(alphabet4, bits), getBaseXResliceDecoder(alphabet4, bits));
165
+ function reslice(input, inputBits, outputBits, useRemainder) {
166
+ const output = [];
167
+ let accumulator = 0;
168
+ let bitsInAccumulator = 0;
169
+ const mask = (1 << outputBits) - 1;
170
+ for (const value of input) {
171
+ accumulator = accumulator << inputBits | value;
172
+ bitsInAccumulator += inputBits;
173
+ while (bitsInAccumulator >= outputBits) {
174
+ bitsInAccumulator -= outputBits;
175
+ output.push(accumulator >> bitsInAccumulator & mask);
176
+ }
177
+ }
178
+ if (useRemainder && bitsInAccumulator > 0) {
179
+ output.push(accumulator << outputBits - bitsInAccumulator & mask);
180
+ }
181
+ return output;
182
+ }
183
+
184
+ // src/base64.ts
185
+ var alphabet3 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
186
+ var getBase64Encoder = () => {
187
+ {
188
+ return codecsCore.createEncoder({
189
+ getSizeFromValue: (value) => {
190
+ try {
191
+ return atob(value).length;
192
+ } catch (e2) {
193
+ throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__INVALID_STRING_FOR_BASE, {
194
+ alphabet: alphabet3,
195
+ base: 64,
196
+ value
197
+ });
198
+ }
199
+ },
200
+ write(value, bytes, offset) {
201
+ try {
202
+ const bytesToAdd = atob(value).split("").map((c) => c.charCodeAt(0));
203
+ bytes.set(bytesToAdd, offset);
204
+ return bytesToAdd.length + offset;
205
+ } catch (e2) {
206
+ throw new errors.SolanaError(errors.SOLANA_ERROR__CODECS__INVALID_STRING_FOR_BASE, {
207
+ alphabet: alphabet3,
208
+ base: 64,
209
+ value
210
+ });
211
+ }
212
+ }
213
+ });
214
+ }
215
+ };
216
+ var getBase64Decoder = () => {
217
+ {
218
+ return codecsCore.createDecoder({
219
+ read(bytes, offset = 0) {
220
+ const slice = bytes.slice(offset);
221
+ const value = btoa(String.fromCharCode(...slice));
222
+ return [value, bytes.length];
223
+ }
224
+ });
225
+ }
226
+ };
227
+ var getBase64Codec = () => codecsCore.combineCodec(getBase64Encoder(), getBase64Decoder());
228
+
229
+ // src/null-characters.ts
230
+ var removeNullCharacters = (value) => (
231
+ // eslint-disable-next-line no-control-regex
232
+ value.replace(/\u0000/g, "")
233
+ );
234
+ var padNullCharacters = (value, chars) => value.padEnd(chars, "\0");
235
+
236
+ // ../text-encoding-impl/dist/index.browser.mjs
237
+ var e = globalThis.TextDecoder;
238
+ var o = globalThis.TextEncoder;
239
+
240
+ // src/utf8.ts
241
+ var getUtf8Encoder = () => {
242
+ let textEncoder;
243
+ return codecsCore.createEncoder({
244
+ getSizeFromValue: (value) => (textEncoder ||= new o()).encode(value).length,
245
+ write: (value, bytes, offset) => {
246
+ const bytesToAdd = (textEncoder ||= new o()).encode(value);
247
+ bytes.set(bytesToAdd, offset);
248
+ return offset + bytesToAdd.length;
249
+ }
250
+ });
251
+ };
252
+ var getUtf8Decoder = () => {
253
+ let textDecoder;
254
+ return codecsCore.createDecoder({
255
+ read(bytes, offset) {
256
+ const value = (textDecoder ||= new e()).decode(bytes.slice(offset));
257
+ return [removeNullCharacters(value), bytes.length];
258
+ }
259
+ });
260
+ };
261
+ var getUtf8Codec = () => codecsCore.combineCodec(getUtf8Encoder(), getUtf8Decoder());
262
+
263
+ exports.assertValidBaseString = assertValidBaseString;
264
+ exports.getBase10Codec = getBase10Codec;
265
+ exports.getBase10Decoder = getBase10Decoder;
266
+ exports.getBase10Encoder = getBase10Encoder;
267
+ exports.getBase16Codec = getBase16Codec;
268
+ exports.getBase16Decoder = getBase16Decoder;
269
+ exports.getBase16Encoder = getBase16Encoder;
270
+ exports.getBase58Codec = getBase58Codec;
271
+ exports.getBase58Decoder = getBase58Decoder;
272
+ exports.getBase58Encoder = getBase58Encoder;
273
+ exports.getBase64Codec = getBase64Codec;
274
+ exports.getBase64Decoder = getBase64Decoder;
275
+ exports.getBase64Encoder = getBase64Encoder;
276
+ exports.getBaseXCodec = getBaseXCodec;
277
+ exports.getBaseXDecoder = getBaseXDecoder;
278
+ exports.getBaseXEncoder = getBaseXEncoder;
279
+ exports.getBaseXResliceCodec = getBaseXResliceCodec;
280
+ exports.getBaseXResliceDecoder = getBaseXResliceDecoder;
281
+ exports.getBaseXResliceEncoder = getBaseXResliceEncoder;
282
+ exports.getUtf8Codec = getUtf8Codec;
283
+ exports.getUtf8Decoder = getUtf8Decoder;
284
+ exports.getUtf8Encoder = getUtf8Encoder;
285
+ exports.padNullCharacters = padNullCharacters;
286
+ exports.removeNullCharacters = removeNullCharacters;
287
+ //# sourceMappingURL=index.browser.cjs.map
288
+ //# sourceMappingURL=index.browser.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/assertions.ts","../src/baseX.ts","../src/base10.ts","../src/base16.ts","../src/base58.ts","../src/baseX-reslice.ts","../src/base64.ts","../src/null-characters.ts","../../text-encoding-impl/src/index.browser.ts","../src/utf8.ts"],"names":["alphabet","SolanaError","SOLANA_ERROR__CODECS__INVALID_STRING_FOR_BASE","createEncoder","createDecoder","combineC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AAG,MAAM,MAAM,CAAA,CAAA;AAAA,KACrD;AAAA,GACH,CAAA,CAAA;AACL,EAAA;AAGO,IAAM,eAAe,MAAiCC,uBAAAA,CAAa,cAAe,EAAA,EAAG,gBAAgB","file":"index.browser.cjs","sourcesContent":["import { SOLANA_ERROR__CODECS__INVALID_STRING_FOR_BASE, SolanaError } from '@solana/errors';\n\n/**\n * Asserts that a given string matches a given alphabet.\n */\nexport function assertValidBaseString(alphabet: string, testValue: string, givenValue = testValue) {\n if (!testValue.match(new RegExp(`^[${alphabet}]*$`))) {\n throw new SolanaError(SOLANA_ERROR__CODECS__INVALID_STRING_FOR_BASE, {\n alphabet,\n base: alphabet.length,\n value: givenValue,\n });\n }\n}\n","import {\n combineCodec,\n createDecoder,\n createEncoder,\n VariableSizeCodec,\n VariableSizeDecoder,\n VariableSizeEncoder,\n} from '@solana/codecs-core';\n\nimport { assertValidBaseString } from './assertions';\n\n/**\n * Encodes a string using a custom alphabet by dividing\n * by the base and handling leading zeroes.\n * @see {@link getBaseXCodec} for a more detailed description.\n */\nexport const getBaseXEncoder = (alphabet: string): VariableSizeEncoder<string> => {\n return createEncoder({\n getSizeFromValue: (value: string): number => {\n const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet[0]);\n if (!tailChars) return value.length;\n\n const base10Number = getBigIntFromBaseX(tailChars, alphabet);\n return leadingZeroes.length + Math.ceil(base10Number.toString(16).length / 2);\n },\n write(value: string, bytes, offset) {\n // Check if the value is valid.\n assertValidBaseString(alphabet, value);\n if (value === '') return offset;\n\n // Handle leading zeroes.\n const [leadingZeroes, tailChars] = partitionLeadingZeroes(value, alphabet[0]);\n if (!tailChars) {\n bytes.set(new Uint8Array(leadingZeroes.length).fill(0), offset);\n return offset + leadingZeroes.length;\n }\n\n // From baseX to base10.\n let base10Number = getBigIntFromBaseX(tailChars, alphabet);\n\n // From base10 to bytes.\n const tailBytes: number[] = [];\n while (base10Number > 0n) {\n tailBytes.unshift(Number(base10Number % 256n));\n base10Number /= 256n;\n }\n\n const bytesToAdd = [...Array(leadingZeroes.length).fill(0), ...tailBytes];\n bytes.set(bytesToAdd, offset);\n return offset + bytesToAdd.length;\n },\n });\n};\n\n/**\n * Decodes a string using a custom alphabet by dividing\n * by the base and handling leading zeroes.\n * @see {@link getBaseXCodec} for a more detailed description.\n */\nexport const getBaseXDecoder = (alphabet: string): VariableSizeDecoder<string> => {\n return createDecoder({\n read(rawBytes, offset): [string, number] {\n const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);\n if (bytes.length === 0) return ['', 0];\n\n // Handle leading zeroes.\n let trailIndex = bytes.findIndex(n => n !== 0);\n trailIndex = trailIndex === -1 ? bytes.length : trailIndex;\n const leadingZeroes = alphabet[0].repeat(trailIndex);\n if (trailIndex === bytes.length) return [leadingZeroes, rawBytes.length];\n\n // From bytes to base10.\n const base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);\n\n // From base10 to baseX.\n const tailChars = getBaseXFromBigInt(base10Number, alphabet);\n\n return [leadingZeroes + tailChars, rawBytes.length];\n },\n });\n};\n\n/**\n * A string codec that requires a custom alphabet and uses\n * the length of that alphabet as the base. It then divides\n * the input by the base as many times as necessary to get\n * the output. It also supports leading zeroes by using the\n * first character of the alphabet as the zero character.\n *\n * This can be used to create codecs such as base10 or base58.\n */\nexport const getBaseXCodec = (alphabet: string): VariableSizeCodec<string> =>\n combineCodec(getBaseXEncoder(alphabet), getBaseXDecoder(alphabet));\n\nfunction partitionLeadingZeroes(\n value: string,\n zeroCharacter: string,\n): [leadingZeros: string, tailChars: string | undefined] {\n const [leadingZeros, tailChars] = value.split(new RegExp(`((?!${zeroCharacter}).*)`));\n return [leadingZeros, tailChars];\n}\n\nfunction getBigIntFromBaseX(value: string, alphabet: string): bigint {\n const base = BigInt(alphabet.length);\n let sum = 0n;\n for (const char of value) {\n sum *= base;\n sum += BigInt(alphabet.indexOf(char));\n }\n return sum;\n}\n\nfunction getBaseXFromBigInt(value: bigint, alphabet: string): string {\n const base = BigInt(alphabet.length);\n const tailChars = [];\n while (value > 0n) {\n tailChars.unshift(alphabet[Number(value % base)]);\n value /= base;\n }\n return tailChars.join('');\n}\n","import { getBaseXCodec, getBaseXDecoder, getBaseXEncoder } from './baseX';\n\nconst alphabet = '0123456789';\n\n/** Encodes strings in base10. */\nexport const getBase10Encoder = () => getBaseXEncoder(alphabet);\n\n/** Decodes strings in base10. */\nexport const getBase10Decoder = () => getBaseXDecoder(alphabet);\n\n/** Encodes and decodes strings in base10. */\nexport const getBase10Codec = () => getBaseXCodec(alphabet);\n","import {\n combineCodec,\n createDecoder,\n createEncoder,\n VariableSizeCodec,\n VariableSizeDecoder,\n VariableSizeEncoder,\n} from '@solana/codecs-core';\nimport { SOLANA_ERROR__CODECS__INVALID_STRING_FOR_BASE, SolanaError } from '@solana/errors';\n\nconst enum HexC {\n ZERO = 48, // 0\n NINE = 57, // 9\n A_UP = 65, // A\n F_UP = 70, // F\n A_LO = 97, // a\n F_LO = 102, // f\n}\n\nconst INVALID_STRING_ERROR_BASE_CONFIG = {\n alphabet: '0123456789abcdef',\n base: 16,\n} as const;\n\nfunction charCodeToBase16(char: number) {\n if (char >= HexC.ZERO && char <= HexC.NINE) return char - HexC.ZERO;\n if (char >= HexC.A_UP && char <= HexC.F_UP) return char - (HexC.A_UP - 10);\n if (char >= HexC.A_LO && char <= HexC.F_LO) return char - (HexC.A_LO - 10);\n}\n\n/** Encodes strings in base16. */\nexport const getBase16Encoder = (): VariableSizeEncoder<string> =>\n createEncoder({\n getSizeFromValue: (value: string) => Math.ceil(value.length / 2),\n write(value: string, bytes, offset) {\n const len = value.length;\n const al = len / 2;\n if (len === 1) {\n const c = value.charCodeAt(0);\n const n = charCodeToBase16(c);\n if (n === undefined) {\n throw new SolanaError(SOLANA_ERROR__CODECS__INVALID_STRING_FOR_BASE, {\n ...INVALID_STRING_ERROR_BASE_CONFIG,\n value,\n });\n }\n bytes.set([n], offset);\n return 1 + offset;\n }\n const hexBytes = new Uint8Array(al);\n for (let i = 0, j = 0; i < al; i++) {\n const c1 = value.charCodeAt(j++);\n const c2 = value.charCodeAt(j++);\n\n const n1 = charCodeToBase16(c1);\n const n2 = charCodeToBase16(c2);\n if (n1 === undefined || (n2 === undefined && !Number.isNaN(c2))) {\n throw new SolanaError(SOLANA_ERROR__CODECS__INVALID_STRING_FOR_BASE, {\n ...INVALID_STRING_ERROR_BASE_CONFIG,\n value,\n });\n }\n hexBytes[i] = !Number.isNaN(c2) ? (n1 << 4) | (n2 ?? 0) : n1;\n }\n\n bytes.set(hexBytes, offset);\n return hexBytes.length + offset;\n },\n });\n\n/** Decodes strings in base16. */\nexport const getBase16Decoder = (): VariableSizeDecoder<string> =>\n createDecoder({\n read(bytes, offset) {\n const value = bytes.slice(offset).reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');\n return [value, bytes.length];\n },\n });\n\n/** Encodes and decodes strings in base16. */\nexport const getBase16Codec = (): VariableSizeCodec<string> => combineCodec(getBase16Encoder(), getBase16Decoder());\n","import { getBaseXCodec, getBaseXDecoder, getBaseXEncoder } from './baseX';\n\nconst alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';\n\n/** Encodes strings in base58. */\nexport const getBase58Encoder = () => getBaseXEncoder(alphabet);\n\n/** Decodes strings in base58. */\nexport const getBase58Decoder = () => getBaseXDecoder(alphabet);\n\n/** Encodes and decodes strings in base58. */\nexport const getBase58Codec = () => getBaseXCodec(alphabet);\n","import {\n combineCodec,\n createDecoder,\n createEncoder,\n VariableSizeCodec,\n VariableSizeDecoder,\n VariableSizeEncoder,\n} from '@solana/codecs-core';\n\nimport { assertValidBaseString } from './assertions';\n\n/**\n * Encodes a string using a custom alphabet by reslicing the bits of the byte array.\n * @see {@link getBaseXResliceCodec} for a more detailed description.\n */\nexport const getBaseXResliceEncoder = (alphabet: string, bits: number): VariableSizeEncoder<string> =>\n createEncoder({\n getSizeFromValue: (value: string) => Math.floor((value.length * bits) / 8),\n write(value: string, bytes, offset) {\n assertValidBaseString(alphabet, value);\n if (value === '') return offset;\n const charIndices = [...value].map(c => alphabet.indexOf(c));\n const reslicedBytes = reslice(charIndices, bits, 8, false);\n bytes.set(reslicedBytes, offset);\n return reslicedBytes.length + offset;\n },\n });\n\n/**\n * Decodes a string using a custom alphabet by reslicing the bits of the byte array.\n * @see {@link getBaseXResliceCodec} for a more detailed description.\n */\nexport const getBaseXResliceDecoder = (alphabet: string, bits: number): VariableSizeDecoder<string> =>\n createDecoder({\n read(rawBytes, offset = 0): [string, number] {\n const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);\n if (bytes.length === 0) return ['', rawBytes.length];\n const charIndices = reslice([...bytes], 8, bits, true);\n return [charIndices.map(i => alphabet[i]).join(''), rawBytes.length];\n },\n });\n\n/**\n * A string serializer that reslices bytes into custom chunks\n * of bits that are then mapped to a custom alphabet.\n *\n * This can be used to create serializers whose alphabet\n * is a power of 2 such as base16 or base64.\n */\nexport const getBaseXResliceCodec = (alphabet: string, bits: number): VariableSizeCodec<string> =>\n combineCodec(getBaseXResliceEncoder(alphabet, bits), getBaseXResliceDecoder(alphabet, bits));\n\n/** Helper function to reslice the bits inside bytes. */\nfunction reslice(input: number[], inputBits: number, outputBits: number, useRemainder: boolean): number[] {\n const output = [];\n let accumulator = 0;\n let bitsInAccumulator = 0;\n const mask = (1 << outputBits) - 1;\n for (const value of input) {\n accumulator = (accumulator << inputBits) | value;\n bitsInAccumulator += inputBits;\n while (bitsInAccumulator >= outputBits) {\n bitsInAccumulator -= outputBits;\n output.push((accumulator >> bitsInAccumulator) & mask);\n }\n }\n if (useRemainder && bitsInAccumulator > 0) {\n output.push((accumulator << (outputBits - bitsInAccumulator)) & mask);\n }\n return output;\n}\n","import {\n combineCodec,\n createDecoder,\n createEncoder,\n transformDecoder,\n transformEncoder,\n VariableSizeCodec,\n VariableSizeDecoder,\n VariableSizeEncoder,\n} from '@solana/codecs-core';\nimport { SOLANA_ERROR__CODECS__INVALID_STRING_FOR_BASE, SolanaError } from '@solana/errors';\n\nimport { assertValidBaseString } from './assertions';\nimport { getBaseXResliceDecoder, getBaseXResliceEncoder } from './baseX-reslice';\n\nconst alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\n\n/** Encodes strings in base64. */\nexport const getBase64Encoder = (): VariableSizeEncoder<string> => {\n if (__BROWSER__) {\n return createEncoder({\n getSizeFromValue: (value: string) => {\n try {\n return (atob as Window['atob'])(value).length;\n } catch (e) {\n throw new SolanaError(SOLANA_ERROR__CODECS__INVALID_STRING_FOR_BASE, {\n alphabet,\n base: 64,\n value,\n });\n }\n },\n write(value: string, bytes, offset) {\n try {\n const bytesToAdd = (atob as Window['atob'])(value)\n .split('')\n .map(c => c.charCodeAt(0));\n bytes.set(bytesToAdd, offset);\n return bytesToAdd.length + offset;\n } catch (e) {\n throw new SolanaError(SOLANA_ERROR__CODECS__INVALID_STRING_FOR_BASE, {\n alphabet,\n base: 64,\n value,\n });\n }\n },\n });\n }\n\n if (__NODEJS__) {\n return createEncoder({\n getSizeFromValue: (value: string) => Buffer.from(value, 'base64').length,\n write(value: string, bytes, offset) {\n assertValidBaseString(alphabet, value.replace(/=/g, ''));\n const buffer = Buffer.from(value, 'base64');\n bytes.set(buffer, offset);\n return buffer.length + offset;\n },\n });\n }\n\n return transformEncoder(getBaseXResliceEncoder(alphabet, 6), (value: string): string => value.replace(/=/g, ''));\n};\n\n/** Decodes strings in base64. */\nexport const getBase64Decoder = (): VariableSizeDecoder<string> => {\n if (__BROWSER__) {\n return createDecoder({\n read(bytes, offset = 0) {\n const slice = bytes.slice(offset);\n const value = (btoa as Window['btoa'])(String.fromCharCode(...slice));\n return [value, bytes.length];\n },\n });\n }\n\n if (__NODEJS__) {\n return createDecoder({\n read: (bytes, offset = 0) => [Buffer.from(bytes, offset).toString('base64'), bytes.length],\n });\n }\n\n return transformDecoder(getBaseXResliceDecoder(alphabet, 6), (value: string): string =>\n value.padEnd(Math.ceil(value.length / 4) * 4, '='),\n );\n};\n\n/** Encodes and decodes strings in base64. */\nexport const getBase64Codec = (): VariableSizeCodec<string> => combineCodec(getBase64Encoder(), getBase64Decoder());\n","/**Removes null characters from a string. */\nexport const removeNullCharacters = (value: string) =>\n // eslint-disable-next-line no-control-regex\n value.replace(/\\u0000/g, '');\n\n/** Pads a string with null characters at the end. */\nexport const padNullCharacters = (value: string, chars: number) => value.padEnd(chars, '\\u0000');\n","export const TextDecoder = globalThis.TextDecoder;\nexport const TextEncoder = globalThis.TextEncoder;\n","import {\n combineCodec,\n createDecoder,\n createEncoder,\n VariableSizeCodec,\n VariableSizeDecoder,\n VariableSizeEncoder,\n} from '@solana/codecs-core';\nimport { TextDecoder, TextEncoder } from '@solana/text-encoding-impl';\n\nimport { removeNullCharacters } from './null-characters';\n\n/** Encodes UTF-8 strings using the native `TextEncoder` API. */\nexport const getUtf8Encoder = (): VariableSizeEncoder<string> => {\n let textEncoder: TextEncoder;\n return createEncoder({\n getSizeFromValue: value => (textEncoder ||= new TextEncoder()).encode(value).length,\n write: (value: string, bytes, offset) => {\n const bytesToAdd = (textEncoder ||= new TextEncoder()).encode(value);\n bytes.set(bytesToAdd, offset);\n return offset + bytesToAdd.length;\n },\n });\n};\n\n/** Decodes UTF-8 strings using the native `TextDecoder` API. */\nexport const getUtf8Decoder = (): VariableSizeDecoder<string> => {\n let textDecoder: TextDecoder;\n return createDecoder({\n read(bytes, offset) {\n const value = (textDecoder ||= new TextDecoder()).decode(bytes.slice(offset));\n return [removeNullCharacters(value), bytes.length];\n },\n });\n};\n\n/** Encodes and decodes UTF-8 strings using the native `TextEncoder` and `TextDecoder` API. */\nexport const getUtf8Codec = (): VariableSizeCodec<string> => combineCodec(getUtf8Encoder(), getUtf8Decoder());\n"]}