@solana/codecs-strings 2.0.0-experimental.5e8ac8d
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 +20 -0
- package/README.md +25 -0
- package/dist/index.browser.cjs +298 -0
- package/dist/index.browser.cjs.map +1 -0
- package/dist/index.browser.js +270 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/index.development.js +469 -0
- package/dist/index.development.js.map +1 -0
- package/dist/index.native.js +251 -0
- package/dist/index.native.js.map +1 -0
- package/dist/index.node.cjs +293 -0
- package/dist/index.node.cjs.map +1 -0
- package/dist/index.node.js +265 -0
- package/dist/index.node.js.map +1 -0
- package/dist/index.production.min.js +37 -0
- package/dist/types/assertions.d.ts +5 -0
- package/dist/types/assertions.d.ts.map +1 -0
- package/dist/types/base10.d.ts +7 -0
- package/dist/types/base10.d.ts.map +1 -0
- package/dist/types/base16.d.ts +8 -0
- package/dist/types/base16.d.ts.map +1 -0
- package/dist/types/base58.d.ts +7 -0
- package/dist/types/base58.d.ts.map +1 -0
- package/dist/types/base64.d.ts +8 -0
- package/dist/types/base64.d.ts.map +1 -0
- package/dist/types/baseX-reslice.d.ts +20 -0
- package/dist/types/baseX-reslice.d.ts.map +1 -0
- package/dist/types/baseX.d.ts +24 -0
- package/dist/types/baseX.d.ts.map +1 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/null-characters.d.ts +5 -0
- package/dist/types/null-characters.d.ts.map +1 -0
- package/dist/types/string.d.ts +25 -0
- package/dist/types/string.d.ts.map +1 -0
- package/dist/types/utf8.d.ts +8 -0
- package/dist/types/utf8.d.ts.map +1 -0
- package/package.json +104 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { combineCodec, fixEncoder, mergeBytes, fixDecoder, assertByteArrayIsNotEmptyForCodec, assertByteArrayHasEnoughBytesForCodec } from '@solana/codecs-core';
|
|
2
|
+
import { getU32Encoder, getU32Decoder } from '@solana/codecs-numbers';
|
|
3
|
+
|
|
4
|
+
// src/assertions.ts
|
|
5
|
+
function assertValidBaseString(alphabet4, testValue, givenValue = testValue) {
|
|
6
|
+
if (!testValue.match(new RegExp(`^[${alphabet4}]*$`))) {
|
|
7
|
+
throw new Error(`Expected a string of base ${alphabet4.length}, got [${givenValue}].`);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
var getBaseXEncoder = (alphabet4) => {
|
|
11
|
+
const base = alphabet4.length;
|
|
12
|
+
const baseBigInt = BigInt(base);
|
|
13
|
+
return {
|
|
14
|
+
description: `base${base}`,
|
|
15
|
+
encode(value) {
|
|
16
|
+
assertValidBaseString(alphabet4, value);
|
|
17
|
+
if (value === "")
|
|
18
|
+
return new Uint8Array();
|
|
19
|
+
const chars = [...value];
|
|
20
|
+
let trailIndex = chars.findIndex((c) => c !== alphabet4[0]);
|
|
21
|
+
trailIndex = trailIndex === -1 ? chars.length : trailIndex;
|
|
22
|
+
const leadingZeroes = Array(trailIndex).fill(0);
|
|
23
|
+
if (trailIndex === chars.length)
|
|
24
|
+
return Uint8Array.from(leadingZeroes);
|
|
25
|
+
const tailChars = chars.slice(trailIndex);
|
|
26
|
+
let base10Number = 0n;
|
|
27
|
+
let baseXPower = 1n;
|
|
28
|
+
for (let i = tailChars.length - 1; i >= 0; i -= 1) {
|
|
29
|
+
base10Number += baseXPower * BigInt(alphabet4.indexOf(tailChars[i]));
|
|
30
|
+
baseXPower *= baseBigInt;
|
|
31
|
+
}
|
|
32
|
+
const tailBytes = [];
|
|
33
|
+
while (base10Number > 0n) {
|
|
34
|
+
tailBytes.unshift(Number(base10Number % 256n));
|
|
35
|
+
base10Number /= 256n;
|
|
36
|
+
}
|
|
37
|
+
return Uint8Array.from(leadingZeroes.concat(tailBytes));
|
|
38
|
+
},
|
|
39
|
+
fixedSize: null,
|
|
40
|
+
maxSize: null
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
var getBaseXDecoder = (alphabet4) => {
|
|
44
|
+
const base = alphabet4.length;
|
|
45
|
+
const baseBigInt = BigInt(base);
|
|
46
|
+
return {
|
|
47
|
+
decode(rawBytes, offset = 0) {
|
|
48
|
+
const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
|
|
49
|
+
if (bytes.length === 0)
|
|
50
|
+
return ["", 0];
|
|
51
|
+
let trailIndex = bytes.findIndex((n) => n !== 0);
|
|
52
|
+
trailIndex = trailIndex === -1 ? bytes.length : trailIndex;
|
|
53
|
+
const leadingZeroes = alphabet4[0].repeat(trailIndex);
|
|
54
|
+
if (trailIndex === bytes.length)
|
|
55
|
+
return [leadingZeroes, rawBytes.length];
|
|
56
|
+
let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);
|
|
57
|
+
const tailChars = [];
|
|
58
|
+
while (base10Number > 0n) {
|
|
59
|
+
tailChars.unshift(alphabet4[Number(base10Number % baseBigInt)]);
|
|
60
|
+
base10Number /= baseBigInt;
|
|
61
|
+
}
|
|
62
|
+
return [leadingZeroes + tailChars.join(""), rawBytes.length];
|
|
63
|
+
},
|
|
64
|
+
description: `base${base}`,
|
|
65
|
+
fixedSize: null,
|
|
66
|
+
maxSize: null
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
var getBaseXCodec = (alphabet4) => combineCodec(getBaseXEncoder(alphabet4), getBaseXDecoder(alphabet4));
|
|
70
|
+
|
|
71
|
+
// src/base10.ts
|
|
72
|
+
var alphabet = "0123456789";
|
|
73
|
+
var getBase10Encoder = () => getBaseXEncoder(alphabet);
|
|
74
|
+
var getBase10Decoder = () => getBaseXDecoder(alphabet);
|
|
75
|
+
var getBase10Codec = () => getBaseXCodec(alphabet);
|
|
76
|
+
var getBase16Encoder = () => ({
|
|
77
|
+
description: "base16",
|
|
78
|
+
encode(value) {
|
|
79
|
+
const lowercaseValue = value.toLowerCase();
|
|
80
|
+
assertValidBaseString("0123456789abcdef", lowercaseValue, value);
|
|
81
|
+
const matches = lowercaseValue.match(/.{1,2}/g);
|
|
82
|
+
return Uint8Array.from(matches ? matches.map((byte) => parseInt(byte, 16)) : []);
|
|
83
|
+
},
|
|
84
|
+
fixedSize: null,
|
|
85
|
+
maxSize: null
|
|
86
|
+
});
|
|
87
|
+
var getBase16Decoder = () => ({
|
|
88
|
+
decode(bytes, offset = 0) {
|
|
89
|
+
const value = bytes.slice(offset).reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
|
|
90
|
+
return [value, bytes.length];
|
|
91
|
+
},
|
|
92
|
+
description: "base16",
|
|
93
|
+
fixedSize: null,
|
|
94
|
+
maxSize: null
|
|
95
|
+
});
|
|
96
|
+
var getBase16Codec = () => combineCodec(getBase16Encoder(), getBase16Decoder());
|
|
97
|
+
|
|
98
|
+
// src/base58.ts
|
|
99
|
+
var alphabet2 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
100
|
+
var getBase58Encoder = () => getBaseXEncoder(alphabet2);
|
|
101
|
+
var getBase58Decoder = () => getBaseXDecoder(alphabet2);
|
|
102
|
+
var getBase58Codec = () => getBaseXCodec(alphabet2);
|
|
103
|
+
var getBaseXResliceEncoder = (alphabet4, bits) => ({
|
|
104
|
+
description: `base${alphabet4.length}`,
|
|
105
|
+
encode(value) {
|
|
106
|
+
assertValidBaseString(alphabet4, value);
|
|
107
|
+
if (value === "")
|
|
108
|
+
return new Uint8Array();
|
|
109
|
+
const charIndices = [...value].map((c) => alphabet4.indexOf(c));
|
|
110
|
+
return new Uint8Array(reslice(charIndices, bits, 8, false));
|
|
111
|
+
},
|
|
112
|
+
fixedSize: null,
|
|
113
|
+
maxSize: null
|
|
114
|
+
});
|
|
115
|
+
var getBaseXResliceDecoder = (alphabet4, bits) => ({
|
|
116
|
+
decode(rawBytes, offset = 0) {
|
|
117
|
+
const bytes = offset === 0 ? rawBytes : rawBytes.slice(offset);
|
|
118
|
+
if (bytes.length === 0)
|
|
119
|
+
return ["", rawBytes.length];
|
|
120
|
+
const charIndices = reslice([...bytes], 8, bits, true);
|
|
121
|
+
return [charIndices.map((i) => alphabet4[i]).join(""), rawBytes.length];
|
|
122
|
+
},
|
|
123
|
+
description: `base${alphabet4.length}`,
|
|
124
|
+
fixedSize: null,
|
|
125
|
+
maxSize: null
|
|
126
|
+
});
|
|
127
|
+
var getBaseXResliceCodec = (alphabet4, bits) => combineCodec(getBaseXResliceEncoder(alphabet4, bits), getBaseXResliceDecoder(alphabet4, bits));
|
|
128
|
+
function reslice(input, inputBits, outputBits, useRemainder) {
|
|
129
|
+
const output = [];
|
|
130
|
+
let accumulator = 0;
|
|
131
|
+
let bitsInAccumulator = 0;
|
|
132
|
+
const mask = (1 << outputBits) - 1;
|
|
133
|
+
for (const value of input) {
|
|
134
|
+
accumulator = accumulator << inputBits | value;
|
|
135
|
+
bitsInAccumulator += inputBits;
|
|
136
|
+
while (bitsInAccumulator >= outputBits) {
|
|
137
|
+
bitsInAccumulator -= outputBits;
|
|
138
|
+
output.push(accumulator >> bitsInAccumulator & mask);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (useRemainder && bitsInAccumulator > 0) {
|
|
142
|
+
output.push(accumulator << outputBits - bitsInAccumulator & mask);
|
|
143
|
+
}
|
|
144
|
+
return output;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// src/base64.ts
|
|
148
|
+
var alphabet3 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
149
|
+
var getBase64Encoder = () => {
|
|
150
|
+
{
|
|
151
|
+
return {
|
|
152
|
+
description: `base64`,
|
|
153
|
+
encode(value) {
|
|
154
|
+
assertValidBaseString(alphabet3, value.replace(/=/g, ""));
|
|
155
|
+
return new Uint8Array(Buffer.from(value, "base64"));
|
|
156
|
+
},
|
|
157
|
+
fixedSize: null,
|
|
158
|
+
maxSize: null
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
var getBase64Decoder = () => {
|
|
163
|
+
{
|
|
164
|
+
return {
|
|
165
|
+
decode: (bytes, offset = 0) => [Buffer.from(bytes, offset).toString("base64"), bytes.length],
|
|
166
|
+
description: `base64`,
|
|
167
|
+
fixedSize: null,
|
|
168
|
+
maxSize: null
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
var getBase64Codec = () => combineCodec(getBase64Encoder(), getBase64Decoder());
|
|
173
|
+
|
|
174
|
+
// src/null-characters.ts
|
|
175
|
+
var removeNullCharacters = (value) => (
|
|
176
|
+
// eslint-disable-next-line no-control-regex
|
|
177
|
+
value.replace(/\u0000/g, "")
|
|
178
|
+
);
|
|
179
|
+
var padNullCharacters = (value, chars) => value.padEnd(chars, "\0");
|
|
180
|
+
|
|
181
|
+
// ../text-encoding-impl/dist/index.node.js
|
|
182
|
+
var e = globalThis.TextDecoder;
|
|
183
|
+
var o = globalThis.TextEncoder;
|
|
184
|
+
|
|
185
|
+
// src/utf8.ts
|
|
186
|
+
var getUtf8Encoder = () => {
|
|
187
|
+
let textEncoder;
|
|
188
|
+
return {
|
|
189
|
+
description: "utf8",
|
|
190
|
+
encode: (value) => new Uint8Array((textEncoder || (textEncoder = new o())).encode(value)),
|
|
191
|
+
fixedSize: null,
|
|
192
|
+
maxSize: null
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
var getUtf8Decoder = () => {
|
|
196
|
+
let textDecoder;
|
|
197
|
+
return {
|
|
198
|
+
decode(bytes, offset = 0) {
|
|
199
|
+
const value = (textDecoder || (textDecoder = new e())).decode(bytes.slice(offset));
|
|
200
|
+
return [removeNullCharacters(value), bytes.length];
|
|
201
|
+
},
|
|
202
|
+
description: "utf8",
|
|
203
|
+
fixedSize: null,
|
|
204
|
+
maxSize: null
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
var getUtf8Codec = () => combineCodec(getUtf8Encoder(), getUtf8Decoder());
|
|
208
|
+
|
|
209
|
+
// src/string.ts
|
|
210
|
+
var getStringEncoder = (options = {}) => {
|
|
211
|
+
const size = options.size ?? getU32Encoder();
|
|
212
|
+
const encoding = options.encoding ?? getUtf8Encoder();
|
|
213
|
+
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
|
|
214
|
+
if (size === "variable") {
|
|
215
|
+
return { ...encoding, description };
|
|
216
|
+
}
|
|
217
|
+
if (typeof size === "number") {
|
|
218
|
+
return fixEncoder(encoding, size, description);
|
|
219
|
+
}
|
|
220
|
+
return {
|
|
221
|
+
description,
|
|
222
|
+
encode: (value) => {
|
|
223
|
+
const contentBytes = encoding.encode(value);
|
|
224
|
+
const lengthBytes = size.encode(contentBytes.length);
|
|
225
|
+
return mergeBytes([lengthBytes, contentBytes]);
|
|
226
|
+
},
|
|
227
|
+
fixedSize: null,
|
|
228
|
+
maxSize: null
|
|
229
|
+
};
|
|
230
|
+
};
|
|
231
|
+
var getStringDecoder = (options = {}) => {
|
|
232
|
+
const size = options.size ?? getU32Decoder();
|
|
233
|
+
const encoding = options.encoding ?? getUtf8Decoder();
|
|
234
|
+
const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;
|
|
235
|
+
if (size === "variable") {
|
|
236
|
+
return { ...encoding, description };
|
|
237
|
+
}
|
|
238
|
+
if (typeof size === "number") {
|
|
239
|
+
return fixDecoder(encoding, size, description);
|
|
240
|
+
}
|
|
241
|
+
return {
|
|
242
|
+
decode: (bytes, offset = 0) => {
|
|
243
|
+
assertByteArrayIsNotEmptyForCodec("string", bytes, offset);
|
|
244
|
+
const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);
|
|
245
|
+
const length = Number(lengthBigInt);
|
|
246
|
+
offset = lengthOffset;
|
|
247
|
+
const contentBytes = bytes.slice(offset, offset + length);
|
|
248
|
+
assertByteArrayHasEnoughBytesForCodec("string", length, contentBytes);
|
|
249
|
+
const [value, contentOffset] = encoding.decode(contentBytes);
|
|
250
|
+
offset += contentOffset;
|
|
251
|
+
return [value, offset];
|
|
252
|
+
},
|
|
253
|
+
description,
|
|
254
|
+
fixedSize: null,
|
|
255
|
+
maxSize: null
|
|
256
|
+
};
|
|
257
|
+
};
|
|
258
|
+
var getStringCodec = (options = {}) => combineCodec(getStringEncoder(options), getStringDecoder(options));
|
|
259
|
+
function getSizeDescription(size) {
|
|
260
|
+
return typeof size === "object" ? size.description : `${size}`;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export { assertValidBaseString, getBase10Codec, getBase10Decoder, getBase10Encoder, getBase16Codec, getBase16Decoder, getBase16Encoder, getBase58Codec, getBase58Decoder, getBase58Encoder, getBase64Codec, getBase64Decoder, getBase64Encoder, getBaseXCodec, getBaseXDecoder, getBaseXEncoder, getBaseXResliceCodec, getBaseXResliceDecoder, getBaseXResliceEncoder, getStringCodec, getStringDecoder, getStringEncoder, getUtf8Codec, getUtf8Decoder, getUtf8Encoder, padNullCharacters, removeNullCharacters };
|
|
264
|
+
//# sourceMappingURL=out.js.map
|
|
265
|
+
//# sourceMappingURL=index.node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/assertions.ts","../src/baseX.ts","../src/base10.ts","../src/base16.ts","../src/base58.ts","../src/base64.ts","../src/baseX-reslice.ts","../src/null-characters.ts","../src/string.ts","../src/utf8.ts","../../text-encoding-impl/src/index.node.ts"],"names":["alphabet","combineCodec","e","TextDecoder","TextEncoder"],"mappings":";AAGO,SAAS,sBAAsBA,WAAkB,WAAmB,aAAa,WAAW;AAC/F,MAAI,CAAC,UAAU,MAAM,IAAI,OAAO,KAAKA,SAAQ,KAAK,CAAC,GAAG;AAElD,UAAM,IAAI,MAAM,6BAA6BA,UAAS,MAAM,UAAU,UAAU,IAAI;AAAA,EACxF;AACJ;;;ACRA,SAAgB,oBAAsC;AAS/C,IAAM,kBAAkB,CAACA,cAAsC;AAClE,QAAM,OAAOA,UAAS;AACtB,QAAM,aAAa,OAAO,IAAI;AAC9B,SAAO;AAAA,IACH,aAAa,OAAO,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;AACrB,WAAO,EAAE,GAAG,UAAU,YAAY;AAAA,EACtC;AAEA,MAAI,OAAO,SAAS,UAAU;AAC1B,WAAO,WAAW,UAAU,MAAM,WAAW;AAAA,EACjD;AAEA,SAAO;AAAA,IACH,QAAQ,CAAC,OAAmB,SAAS,MAAM;AACvC,wCAAkC,UAAU,OAAO,MAAM;AACzD,YAAM,CAAC,cAAc,YAAY,IAAI,KAAK,OAAO,OAAO,MAAM;AAC9D,YAAM,SAAS,OAAO,YAAY;AAClC,eAAS;AACT,YAAM,eAAe,MAAM,MAAM,QAAQ,SAAS,MAAM;AACxD,4CAAsC,UAAU,QAAQ,YAAY;AACpE,YAAM,CAAC,OAAO,aAAa,IAAI,SAAS,OAAO,YAAY;AAC3D,gBAAU;AACV,aAAO,CAAC,OAAO,MAAM;AAAA,IACzB;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,SAAS;AAAA,EACb;AACJ;AAGO,IAAM,iBAAiB,CAAC,UAA0D,CAAC,MACtFA,cAAa,iBAAiB,OAAO,GAAG,iBAAiB,OAAO,CAAC;AAErE,SAAS,mBAAmB,MAA+C;AACvE,SAAO,OAAO,SAAS,WAAW,KAAK,cAAc,GAAG,IAAI;AAChE","sourcesContent":["/**\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 // TODO: Coded error.\n throw new Error(`Expected a string of base ${alphabet.length}, got [${givenValue}].`);\n }\n}\n","import { Codec, combineCodec, Decoder, Encoder } 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): Encoder<string> => {\n const base = alphabet.length;\n const baseBigInt = BigInt(base);\n return {\n description: `base${base}`,\n encode(value: string): Uint8Array {\n // Check if the value is valid.\n assertValidBaseString(alphabet, value);\n if (value === '') return new Uint8Array();\n\n // Handle leading zeroes.\n const chars = [...value];\n let trailIndex = chars.findIndex(c => c !== alphabet[0]);\n trailIndex = trailIndex === -1 ? chars.length : trailIndex;\n const leadingZeroes = Array(trailIndex).fill(0);\n if (trailIndex === chars.length) return Uint8Array.from(leadingZeroes);\n\n // From baseX to base10.\n const tailChars = chars.slice(trailIndex);\n let base10Number = 0n;\n let baseXPower = 1n;\n for (let i = tailChars.length - 1; i >= 0; i -= 1) {\n base10Number += baseXPower * BigInt(alphabet.indexOf(tailChars[i]));\n baseXPower *= baseBigInt;\n }\n\n // From base10 to bytes.\n const tailBytes = [];\n while (base10Number > 0n) {\n tailBytes.unshift(Number(base10Number % 256n));\n base10Number /= 256n;\n }\n return Uint8Array.from(leadingZeroes.concat(tailBytes));\n },\n fixedSize: null,\n maxSize: null,\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): Decoder<string> => {\n const base = alphabet.length;\n const baseBigInt = BigInt(base);\n return {\n decode(rawBytes, offset = 0): [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 let base10Number = bytes.slice(trailIndex).reduce((sum, byte) => sum * 256n + BigInt(byte), 0n);\n\n // From base10 to baseX.\n const tailChars = [];\n while (base10Number > 0n) {\n tailChars.unshift(alphabet[Number(base10Number % baseBigInt)]);\n base10Number /= baseBigInt;\n }\n\n return [leadingZeroes + tailChars.join(''), rawBytes.length];\n },\n description: `base${base}`,\n fixedSize: null,\n maxSize: null,\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): Codec<string> =>\n combineCodec(getBaseXEncoder(alphabet), getBaseXDecoder(alphabet));\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 { Codec, combineCodec, Decoder, Encoder } from '@solana/codecs-core';\n\nimport { assertValidBaseString } from './assertions';\n\n/** Encodes strings in base16. */\nexport const getBase16Encoder = (): Encoder<string> => ({\n description: 'base16',\n encode(value: string) {\n const lowercaseValue = value.toLowerCase();\n assertValidBaseString('0123456789abcdef', lowercaseValue, value);\n const matches = lowercaseValue.match(/.{1,2}/g);\n return Uint8Array.from(matches ? matches.map((byte: string) => parseInt(byte, 16)) : []);\n },\n fixedSize: null,\n maxSize: null,\n});\n\n/** Decodes strings in base16. */\nexport const getBase16Decoder = (): Decoder<string> => ({\n decode(bytes, offset = 0) {\n const value = bytes.slice(offset).reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');\n return [value, bytes.length];\n },\n description: 'base16',\n fixedSize: null,\n maxSize: null,\n});\n\n/** Encodes and decodes strings in base16. */\nexport const getBase16Codec = (): Codec<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 { combineCodec, Decoder, Encoder, mapDecoder, mapEncoder } from '@solana/codecs-core';\n\nimport { assertValidBaseString } from './assertions';\nimport { getBaseXResliceDecoder, getBaseXResliceEncoder } from './baseX-reslice';\n\nconst alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';\n\n/** Encodes strings in base64. */\nexport const getBase64Encoder = (): Encoder<string> => {\n if (__BROWSER__) {\n return {\n description: `base64`,\n encode(value: string): Uint8Array {\n try {\n const bytes = (atob as Window['atob'])(value)\n .split('')\n .map(c => c.charCodeAt(0));\n return new Uint8Array(bytes);\n } catch (e) {\n // TODO: Coded error.\n throw new Error(`Expected a string of base 64, got [${value}].`);\n }\n },\n fixedSize: null,\n maxSize: null,\n };\n }\n\n if (__NODEJS__) {\n return {\n description: `base64`,\n encode(value: string): Uint8Array {\n assertValidBaseString(alphabet, value.replace(/=/g, ''));\n return new Uint8Array(Buffer.from(value, 'base64'));\n },\n fixedSize: null,\n maxSize: null,\n };\n }\n\n return mapEncoder(getBaseXResliceEncoder(alphabet, 6), (value: string): string => value.replace(/=/g, ''));\n};\n\n/** Decodes strings in base64. */\nexport const getBase64Decoder = (): Decoder<string> => {\n if (__BROWSER__) {\n return {\n decode(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 description: `base64`,\n fixedSize: null,\n maxSize: null,\n };\n }\n\n if (__NODEJS__) {\n return {\n decode: (bytes, offset = 0) => [Buffer.from(bytes, offset).toString('base64'), bytes.length],\n description: `base64`,\n fixedSize: null,\n maxSize: null,\n };\n }\n\n return mapDecoder(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 = () => combineCodec(getBase64Encoder(), getBase64Decoder());\n","import { Codec, combineCodec, Decoder, Encoder } 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): Encoder<string> => ({\n description: `base${alphabet.length}`,\n encode(value: string): Uint8Array {\n assertValidBaseString(alphabet, value);\n if (value === '') return new Uint8Array();\n const charIndices = [...value].map(c => alphabet.indexOf(c));\n return new Uint8Array(reslice(charIndices, bits, 8, false));\n },\n fixedSize: null,\n maxSize: null,\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): Decoder<string> => ({\n decode(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 description: `base${alphabet.length}`,\n fixedSize: null,\n maxSize: null,\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): Codec<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","/**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","import {\n assertByteArrayHasEnoughBytesForCodec,\n assertByteArrayIsNotEmptyForCodec,\n BaseCodecOptions,\n Codec,\n CodecData,\n combineCodec,\n Decoder,\n Encoder,\n fixDecoder,\n fixEncoder,\n mergeBytes,\n} from '@solana/codecs-core';\nimport { getU32Decoder, getU32Encoder, NumberCodec, NumberDecoder, NumberEncoder } from '@solana/codecs-numbers';\n\nimport { getUtf8Decoder, getUtf8Encoder } from './utf8';\n\n/** Defines the options for string codecs. */\nexport type StringCodecOptions<\n TPrefix extends NumberCodec | NumberEncoder | NumberDecoder,\n TEncoding extends Codec<string> | Encoder<string> | Decoder<string>\n> = BaseCodecOptions & {\n /**\n * The size of the string. It can be one of the following:\n * - a {@link NumberCodec} that prefixes the string with its size.\n * - a fixed number of bytes.\n * - or `'variable'` to use the rest of the byte array.\n * @defaultValue u32 prefix.\n */\n size?: TPrefix | number | 'variable';\n\n /**\n * The codec to use for encoding and decoding the content.\n * @defaultValue UTF-8 encoding.\n */\n encoding?: TEncoding;\n};\n\n/** Encodes strings from a given encoding and size strategy. */\nexport const getStringEncoder = (options: StringCodecOptions<NumberEncoder, Encoder<string>> = {}): Encoder<string> => {\n const size = options.size ?? getU32Encoder();\n const encoding = options.encoding ?? getUtf8Encoder();\n const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;\n\n if (size === 'variable') {\n return { ...encoding, description };\n }\n\n if (typeof size === 'number') {\n return fixEncoder(encoding, size, description);\n }\n\n return {\n description,\n encode: (value: string) => {\n const contentBytes = encoding.encode(value);\n const lengthBytes = size.encode(contentBytes.length);\n return mergeBytes([lengthBytes, contentBytes]);\n },\n fixedSize: null,\n maxSize: null,\n };\n};\n\n/** Decodes strings from a given encoding and size strategy. */\nexport const getStringDecoder = (options: StringCodecOptions<NumberDecoder, Decoder<string>> = {}): Decoder<string> => {\n const size = options.size ?? getU32Decoder();\n const encoding = options.encoding ?? getUtf8Decoder();\n const description = options.description ?? `string(${encoding.description}; ${getSizeDescription(size)})`;\n\n if (size === 'variable') {\n return { ...encoding, description };\n }\n\n if (typeof size === 'number') {\n return fixDecoder(encoding, size, description);\n }\n\n return {\n decode: (bytes: Uint8Array, offset = 0) => {\n assertByteArrayIsNotEmptyForCodec('string', bytes, offset);\n const [lengthBigInt, lengthOffset] = size.decode(bytes, offset);\n const length = Number(lengthBigInt);\n offset = lengthOffset;\n const contentBytes = bytes.slice(offset, offset + length);\n assertByteArrayHasEnoughBytesForCodec('string', length, contentBytes);\n const [value, contentOffset] = encoding.decode(contentBytes);\n offset += contentOffset;\n return [value, offset];\n },\n description,\n fixedSize: null,\n maxSize: null,\n };\n};\n\n/** Encodes and decodes strings from a given encoding and size strategy. */\nexport const getStringCodec = (options: StringCodecOptions<NumberCodec, Codec<string>> = {}): Codec<string> =>\n combineCodec(getStringEncoder(options), getStringDecoder(options));\n\nfunction getSizeDescription(size: CodecData | number | 'variable'): string {\n return typeof size === 'object' ? size.description : `${size}`;\n}\n","import { Codec, combineCodec, Decoder, Encoder } from '@solana/codecs-core';\nimport { TextDecoder, TextEncoder } from 'text-encoding-impl';\n\nimport { removeNullCharacters } from './null-characters';\n\n/** Encodes UTF-8 strings using the native `TextEncoder` API. */\nexport const getUtf8Encoder = (): Encoder<string> => {\n let textEncoder: TextEncoder;\n return {\n description: 'utf8',\n encode: (value: string) => new Uint8Array((textEncoder ||= new TextEncoder()).encode(value)),\n fixedSize: null,\n maxSize: null,\n };\n};\n\n/** Decodes UTF-8 strings using the native `TextDecoder` API. */\nexport const getUtf8Decoder = (): Decoder<string> => {\n let textDecoder: TextDecoder;\n return {\n decode(bytes, offset = 0) {\n const value = (textDecoder ||= new TextDecoder()).decode(bytes.slice(offset));\n return [removeNullCharacters(value), bytes.length];\n },\n description: 'utf8',\n fixedSize: null,\n maxSize: null,\n };\n};\n\n/** Encodes and decodes UTF-8 strings using the native `TextEncoder` and `TextDecoder` API. */\nexport const getUtf8Codec = (): Codec<string> => combineCodec(getUtf8Encoder(), getUtf8Decoder());\n","export const TextDecoder = globalThis.TextDecoder;\nexport const TextEncoder = globalThis.TextEncoder;\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
this.globalThis = this.globalThis || {};
|
|
2
|
+
this.globalThis.solanaWeb3 = (function (exports) {
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
function u(e,r,t=r){if(!r.match(new RegExp(`^[${e}]*$`)))throw new Error(`Expected a string of base ${e.length}, got [${t}].`)}function S(e,r,t=0){if(r.length-t<=0)throw new Error(`Codec [${e}] cannot decode empty byte arrays.`)}function x(e,r,t,n=0){let i=t.length-n;if(i<r)throw new Error(`Codec [${e}] expected ${r} bytes, got ${i}.`)}var I=e=>{let r=e.filter(o=>o.length);if(r.length===0)return e.length?e[0]:new Uint8Array;if(r.length===1)return r[0];let t=r.reduce((o,c)=>o+c.length,0),n=new Uint8Array(t),i=0;return r.forEach(o=>{n.set(o,i),i+=o.length;}),n},H=(e,r)=>{if(e.length>=r)return e;let t=new Uint8Array(r).fill(0);return t.set(e),t},U=(e,r)=>H(e.length<=r?e:e.slice(0,r),r);function d(e,r,t){if(e.fixedSize!==r.fixedSize)throw new Error(`Encoder and decoder must have the same fixed size, got [${e.fixedSize}] and [${r.fixedSize}].`);if(e.maxSize!==r.maxSize)throw new Error(`Encoder and decoder must have the same max size, got [${e.maxSize}] and [${r.maxSize}].`);if(t===void 0&&e.description!==r.description)throw new Error(`Encoder and decoder must have the same description, got [${e.description}] and [${r.description}]. Pass a custom description as a third argument if you want to override the description and bypass this error.`);return {decode:r.decode,description:t??e.description,encode:e.encode,fixedSize:e.fixedSize,maxSize:e.maxSize}}function y(e,r,t){return {description:t??`fixed(${r}, ${e.description})`,fixedSize:r,maxSize:r}}function w(e,r,t){return {...y(e,r,t),encode:n=>U(e.encode(n),r)}}function N(e,r,t){return {...y(e,r,t),decode:(n,i=0)=>{x("fixCodec",r,n,i),(i>0||n.length>r)&&(n=n.slice(i,i+r)),e.fixedSize!==null&&(n=U(n,e.fixedSize));let[o]=e.decode(n,0);return [o,i+r]}}}var z=e=>{let r=e.length,t=BigInt(r);return {description:`base${r}`,encode(n){if(u(e,n),n==="")return new Uint8Array;let i=[...n],o=i.findIndex(g=>g!==e[0]);o=o===-1?i.length:o;let c=Array(o).fill(0);if(o===i.length)return Uint8Array.from(c);let a=i.slice(o),s=0n,m=1n;for(let g=a.length-1;g>=0;g-=1)s+=m*BigInt(e.indexOf(a[g])),m*=t;let l=[];for(;s>0n;)l.unshift(Number(s%256n)),s/=256n;return Uint8Array.from(c.concat(l))},fixedSize:null,maxSize:null}},p=e=>{let r=e.length,t=BigInt(r);return {decode(n,i=0){let o=i===0?n:n.slice(i);if(o.length===0)return ["",0];let c=o.findIndex(l=>l!==0);c=c===-1?o.length:c;let a=e[0].repeat(c);if(c===o.length)return [a,n.length];let s=o.slice(c).reduce((l,g)=>l*256n+BigInt(g),0n),m=[];for(;s>0n;)m.unshift(e[Number(s%t)]),s/=t;return [a+m.join(""),n.length]},description:`base${r}`,fixedSize:null,maxSize:null}},h=e=>d(z(e),p(e));var E="0123456789",me=()=>z(E),le=()=>p(E),ue=()=>h(E);var P=()=>({description:"base16",encode(e){let r=e.toLowerCase();u("0123456789abcdef",r,e);let t=r.match(/.{1,2}/g);return Uint8Array.from(t?t.map(n=>parseInt(n,16)):[])},fixedSize:null,maxSize:null}),W=()=>({decode(e,r=0){return [e.slice(r).reduce((n,i)=>n+i.toString(16).padStart(2,"0"),""),e.length]},description:"base16",fixedSize:null,maxSize:null}),Be=()=>d(P(),W());var C="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",Ie=()=>z(C),Ue=()=>p(C),ye=()=>h(C);var B=(e,r)=>({description:`base${e.length}`,encode(t){if(u(e,t),t==="")return new Uint8Array;let n=[...t].map(i=>e.indexOf(i));return new Uint8Array(O(n,r,8,!1))},fixedSize:null,maxSize:null}),b=(e,r)=>({decode(t,n=0){let i=n===0?t:t.slice(n);return i.length===0?["",t.length]:[O([...i],8,r,!0).map(c=>e[c]).join(""),t.length]},description:`base${e.length}`,fixedSize:null,maxSize:null}),Te=(e,r)=>d(B(e,r),b(e,r));function O(e,r,t,n){let i=[],o=0,c=0,a=(1<<t)-1;for(let s of e)for(o=o<<r|s,c+=r;c>=t;)c-=t,i.push(o>>c&a);return n&&c>0&&i.push(o<<t-c&a),i}var j=()=>({description:"base64",encode(e){try{let r=atob(e).split("").map(t=>t.charCodeAt(0));return new Uint8Array(r)}catch{throw new Error(`Expected a string of base 64, got [${e}].`)}},fixedSize:null,maxSize:null}),M=()=>({decode(e,r=0){let t=e.slice(r);return [btoa(String.fromCharCode(...t)),e.length]},description:"base64",fixedSize:null,maxSize:null}),Pe=()=>d(j(),M());var _=e=>e.replace(/\u0000/g,""),Me=(e,r)=>e.padEnd(r,"\0");function G(e,r,t,n){if(n<r||n>t)throw new Error(`Codec [${e}] expected number to be in the range [${r}, ${t}], got ${n}.`)}function T(e){let r,t=e.name;return e.size>1&&(r=!("endian"in e.options)||e.options.endian===0,t+=r?"(le)":"(be)"),{description:e.options.description??t,fixedSize:e.size,littleEndian:r,maxSize:e.size}}function J(e){let r=T(e);return {description:r.description,encode(t){e.range&&G(e.name,e.range[0],e.range[1],t);let n=new ArrayBuffer(e.size);return e.set(new DataView(n),t,r.littleEndian),new Uint8Array(n)},fixedSize:r.fixedSize,maxSize:r.maxSize}}function Z(e){let r=T(e);return {decode(t,n=0){S(r.description,t,n),x(r.description,e.size,t,n);let i=new DataView(q(t,n,e.size));return [e.get(i,r.littleEndian),n+e.size]},description:r.description,fixedSize:r.fixedSize,maxSize:r.maxSize}}function q(e,r,t){let n=e.byteOffset+(r??0),i=t??e.byteLength;return e.buffer.slice(n,n+i)}var X=(e={})=>J({name:"u32",options:e,range:[0,+"0xffffffff"],set:(r,t,n)=>r.setUint32(0,t,n),size:4}),V=(e={})=>Z({get:(r,t)=>r.getUint32(0,t),name:"u32",options:e,size:4});var R=globalThis.TextDecoder,L=globalThis.TextEncoder;var v=()=>{let e;return {description:"utf8",encode:r=>new Uint8Array((e||(e=new L)).encode(r)),fixedSize:null,maxSize:null}},D=()=>{let e;return {decode(r,t=0){let n=(e||(e=new R)).decode(r.slice(t));return [_(n),r.length]},description:"utf8",fixedSize:null,maxSize:null}},cr=()=>d(v(),D());var K=(e={})=>{let r=e.size??X(),t=e.encoding??v(),n=e.description??`string(${t.description}; ${k(r)})`;return r==="variable"?{...t,description:n}:typeof r=="number"?w(t,r,n):{description:n,encode:i=>{let o=t.encode(i),c=r.encode(o.length);return I([c,o])},fixedSize:null,maxSize:null}},Q=(e={})=>{let r=e.size??V(),t=e.encoding??D(),n=e.description??`string(${t.description}; ${k(r)})`;return r==="variable"?{...t,description:n}:typeof r=="number"?N(t,r,n):{decode:(i,o=0)=>{S("string",i,o);let[c,a]=r.decode(i,o),s=Number(c);o=a;let m=i.slice(o,o+s);x("string",s,m);let[l,g]=t.decode(m);return o+=g,[l,o]},description:n,fixedSize:null,maxSize:null}},Er=(e={})=>d(K(e),Q(e));function k(e){return typeof e=="object"?e.description:`${e}`}
|
|
6
|
+
|
|
7
|
+
exports.assertValidBaseString = u;
|
|
8
|
+
exports.getBase10Codec = ue;
|
|
9
|
+
exports.getBase10Decoder = le;
|
|
10
|
+
exports.getBase10Encoder = me;
|
|
11
|
+
exports.getBase16Codec = Be;
|
|
12
|
+
exports.getBase16Decoder = W;
|
|
13
|
+
exports.getBase16Encoder = P;
|
|
14
|
+
exports.getBase58Codec = ye;
|
|
15
|
+
exports.getBase58Decoder = Ue;
|
|
16
|
+
exports.getBase58Encoder = Ie;
|
|
17
|
+
exports.getBase64Codec = Pe;
|
|
18
|
+
exports.getBase64Decoder = M;
|
|
19
|
+
exports.getBase64Encoder = j;
|
|
20
|
+
exports.getBaseXCodec = h;
|
|
21
|
+
exports.getBaseXDecoder = p;
|
|
22
|
+
exports.getBaseXEncoder = z;
|
|
23
|
+
exports.getBaseXResliceCodec = Te;
|
|
24
|
+
exports.getBaseXResliceDecoder = b;
|
|
25
|
+
exports.getBaseXResliceEncoder = B;
|
|
26
|
+
exports.getStringCodec = Er;
|
|
27
|
+
exports.getStringDecoder = Q;
|
|
28
|
+
exports.getStringEncoder = K;
|
|
29
|
+
exports.getUtf8Codec = cr;
|
|
30
|
+
exports.getUtf8Decoder = D;
|
|
31
|
+
exports.getUtf8Encoder = v;
|
|
32
|
+
exports.padNullCharacters = Me;
|
|
33
|
+
exports.removeNullCharacters = _;
|
|
34
|
+
|
|
35
|
+
return exports;
|
|
36
|
+
|
|
37
|
+
})({});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertions.d.ts","sourceRoot":"","sources":["../../src/assertions.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,SAAY,QAKhG"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Encodes strings in base10. */
|
|
2
|
+
export declare const getBase10Encoder: () => import("@solana/codecs-core").Encoder<string>;
|
|
3
|
+
/** Decodes strings in base10. */
|
|
4
|
+
export declare const getBase10Decoder: () => import("@solana/codecs-core").Decoder<string>;
|
|
5
|
+
/** Encodes and decodes strings in base10. */
|
|
6
|
+
export declare const getBase10Codec: () => import("@solana/codecs-core").Codec<string>;
|
|
7
|
+
//# sourceMappingURL=base10.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base10.d.ts","sourceRoot":"","sources":["../../src/base10.ts"],"names":[],"mappings":"AAIA,iCAAiC;AACjC,eAAO,MAAM,gBAAgB,qDAAkC,CAAC;AAEhE,iCAAiC;AACjC,eAAO,MAAM,gBAAgB,qDAAkC,CAAC;AAEhE,6CAA6C;AAC7C,eAAO,MAAM,cAAc,mDAAgC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Codec, Decoder, Encoder } from '@solana/codecs-core';
|
|
2
|
+
/** Encodes strings in base16. */
|
|
3
|
+
export declare const getBase16Encoder: () => Encoder<string>;
|
|
4
|
+
/** Decodes strings in base16. */
|
|
5
|
+
export declare const getBase16Decoder: () => Decoder<string>;
|
|
6
|
+
/** Encodes and decodes strings in base16. */
|
|
7
|
+
export declare const getBase16Codec: () => Codec<string>;
|
|
8
|
+
//# sourceMappingURL=base16.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base16.d.ts","sourceRoot":"","sources":["../../src/base16.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAgB,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAI5E,iCAAiC;AACjC,eAAO,MAAM,gBAAgB,QAAO,QAAQ,MAAM,CAUhD,CAAC;AAEH,iCAAiC;AACjC,eAAO,MAAM,gBAAgB,QAAO,QAAQ,MAAM,CAQhD,CAAC;AAEH,6CAA6C;AAC7C,eAAO,MAAM,cAAc,QAAO,MAAM,MAAM,CAAyD,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Encodes strings in base58. */
|
|
2
|
+
export declare const getBase58Encoder: () => import("@solana/codecs-core").Encoder<string>;
|
|
3
|
+
/** Decodes strings in base58. */
|
|
4
|
+
export declare const getBase58Decoder: () => import("@solana/codecs-core").Decoder<string>;
|
|
5
|
+
/** Encodes and decodes strings in base58. */
|
|
6
|
+
export declare const getBase58Codec: () => import("@solana/codecs-core").Codec<string>;
|
|
7
|
+
//# sourceMappingURL=base58.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base58.d.ts","sourceRoot":"","sources":["../../src/base58.ts"],"names":[],"mappings":"AAIA,iCAAiC;AACjC,eAAO,MAAM,gBAAgB,qDAAkC,CAAC;AAEhE,iCAAiC;AACjC,eAAO,MAAM,gBAAgB,qDAAkC,CAAC;AAEhE,6CAA6C;AAC7C,eAAO,MAAM,cAAc,mDAAgC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Decoder, Encoder } from '@solana/codecs-core';
|
|
2
|
+
/** Encodes strings in base64. */
|
|
3
|
+
export declare const getBase64Encoder: () => Encoder<string>;
|
|
4
|
+
/** Decodes strings in base64. */
|
|
5
|
+
export declare const getBase64Decoder: () => Decoder<string>;
|
|
6
|
+
/** Encodes and decodes strings in base64. */
|
|
7
|
+
export declare const getBase64Codec: () => import("@solana/codecs-core").Codec<string, string>;
|
|
8
|
+
//# sourceMappingURL=base64.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../src/base64.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,OAAO,EAAE,OAAO,EAA0B,MAAM,qBAAqB,CAAC;AAO7F,iCAAiC;AACjC,eAAO,MAAM,gBAAgB,QAAO,QAAQ,MAAM,CAiCjD,CAAC;AAEF,iCAAiC;AACjC,eAAO,MAAM,gBAAgB,QAAO,QAAQ,MAAM,CA0BjD,CAAC;AAEF,6CAA6C;AAC7C,eAAO,MAAM,cAAc,2DAA6D,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Codec, Decoder, Encoder } from '@solana/codecs-core';
|
|
2
|
+
/**
|
|
3
|
+
* Encodes a string using a custom alphabet by reslicing the bits of the byte array.
|
|
4
|
+
* @see {@link getBaseXResliceCodec} for a more detailed description.
|
|
5
|
+
*/
|
|
6
|
+
export declare const getBaseXResliceEncoder: (alphabet: string, bits: number) => Encoder<string>;
|
|
7
|
+
/**
|
|
8
|
+
* Decodes a string using a custom alphabet by reslicing the bits of the byte array.
|
|
9
|
+
* @see {@link getBaseXResliceCodec} for a more detailed description.
|
|
10
|
+
*/
|
|
11
|
+
export declare const getBaseXResliceDecoder: (alphabet: string, bits: number) => Decoder<string>;
|
|
12
|
+
/**
|
|
13
|
+
* A string serializer that reslices bytes into custom chunks
|
|
14
|
+
* of bits that are then mapped to a custom alphabet.
|
|
15
|
+
*
|
|
16
|
+
* This can be used to create serializers whose alphabet
|
|
17
|
+
* is a power of 2 such as base16 or base64.
|
|
18
|
+
*/
|
|
19
|
+
export declare const getBaseXResliceCodec: (alphabet: string, bits: number) => Codec<string>;
|
|
20
|
+
//# sourceMappingURL=baseX-reslice.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseX-reslice.d.ts","sourceRoot":"","sources":["../../src/baseX-reslice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAgB,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAI5E;;;GAGG;AACH,eAAO,MAAM,sBAAsB,aAAc,MAAM,QAAQ,MAAM,KAAG,QAAQ,MAAM,CAUpF,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,sBAAsB,aAAc,MAAM,QAAQ,MAAM,KAAG,QAAQ,MAAM,CAUpF,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,aAAc,MAAM,QAAQ,MAAM,KAAG,MAAM,MAAM,CACc,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Codec, Decoder, Encoder } from '@solana/codecs-core';
|
|
2
|
+
/**
|
|
3
|
+
* Encodes a string using a custom alphabet by dividing
|
|
4
|
+
* by the base and handling leading zeroes.
|
|
5
|
+
* @see {@link getBaseXCodec} for a more detailed description.
|
|
6
|
+
*/
|
|
7
|
+
export declare const getBaseXEncoder: (alphabet: string) => Encoder<string>;
|
|
8
|
+
/**
|
|
9
|
+
* Decodes a string using a custom alphabet by dividing
|
|
10
|
+
* by the base and handling leading zeroes.
|
|
11
|
+
* @see {@link getBaseXCodec} for a more detailed description.
|
|
12
|
+
*/
|
|
13
|
+
export declare const getBaseXDecoder: (alphabet: string) => Decoder<string>;
|
|
14
|
+
/**
|
|
15
|
+
* A string codec that requires a custom alphabet and uses
|
|
16
|
+
* the length of that alphabet as the base. It then divides
|
|
17
|
+
* the input by the base as many times as necessary to get
|
|
18
|
+
* the output. It also supports leading zeroes by using the
|
|
19
|
+
* first character of the alphabet as the zero character.
|
|
20
|
+
*
|
|
21
|
+
* This can be used to create codecs such as base10 or base58.
|
|
22
|
+
*/
|
|
23
|
+
export declare const getBaseXCodec: (alphabet: string) => Codec<string>;
|
|
24
|
+
//# sourceMappingURL=baseX.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseX.d.ts","sourceRoot":"","sources":["../../src/baseX.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAgB,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAI5E;;;;GAIG;AACH,eAAO,MAAM,eAAe,aAAc,MAAM,KAAG,QAAQ,MAAM,CAqChE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,eAAe,aAAc,MAAM,KAAG,QAAQ,MAAM,CA8BhE,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,aAAc,MAAM,KAAG,MAAM,MAAM,CACS,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './assertions';
|
|
2
|
+
export * from './base10';
|
|
3
|
+
export * from './base16';
|
|
4
|
+
export * from './base58';
|
|
5
|
+
export * from './base64';
|
|
6
|
+
export * from './baseX';
|
|
7
|
+
export * from './baseX-reslice';
|
|
8
|
+
export * from './null-characters';
|
|
9
|
+
export * from './string';
|
|
10
|
+
export * from './utf8';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**Removes null characters from a string. */
|
|
2
|
+
export declare const removeNullCharacters: (value: string) => string;
|
|
3
|
+
/** Pads a string with null characters at the end. */
|
|
4
|
+
export declare const padNullCharacters: (value: string, chars: number) => string;
|
|
5
|
+
//# sourceMappingURL=null-characters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"null-characters.d.ts","sourceRoot":"","sources":["../../src/null-characters.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,eAAO,MAAM,oBAAoB,UAAW,MAAM,WAElB,CAAC;AAEjC,qDAAqD;AACrD,eAAO,MAAM,iBAAiB,UAAW,MAAM,SAAS,MAAM,WAAkC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BaseCodecOptions, Codec, Decoder, Encoder } from '@solana/codecs-core';
|
|
2
|
+
import { NumberCodec, NumberDecoder, NumberEncoder } from '@solana/codecs-numbers';
|
|
3
|
+
/** Defines the options for string codecs. */
|
|
4
|
+
export type StringCodecOptions<TPrefix extends NumberCodec | NumberEncoder | NumberDecoder, TEncoding extends Codec<string> | Encoder<string> | Decoder<string>> = BaseCodecOptions & {
|
|
5
|
+
/**
|
|
6
|
+
* The size of the string. It can be one of the following:
|
|
7
|
+
* - a {@link NumberCodec} that prefixes the string with its size.
|
|
8
|
+
* - a fixed number of bytes.
|
|
9
|
+
* - or `'variable'` to use the rest of the byte array.
|
|
10
|
+
* @defaultValue u32 prefix.
|
|
11
|
+
*/
|
|
12
|
+
size?: TPrefix | number | 'variable';
|
|
13
|
+
/**
|
|
14
|
+
* The codec to use for encoding and decoding the content.
|
|
15
|
+
* @defaultValue UTF-8 encoding.
|
|
16
|
+
*/
|
|
17
|
+
encoding?: TEncoding;
|
|
18
|
+
};
|
|
19
|
+
/** Encodes strings from a given encoding and size strategy. */
|
|
20
|
+
export declare const getStringEncoder: (options?: StringCodecOptions<NumberEncoder, Encoder<string>>) => Encoder<string>;
|
|
21
|
+
/** Decodes strings from a given encoding and size strategy. */
|
|
22
|
+
export declare const getStringDecoder: (options?: StringCodecOptions<NumberDecoder, Decoder<string>>) => Decoder<string>;
|
|
23
|
+
/** Encodes and decodes strings from a given encoding and size strategy. */
|
|
24
|
+
export declare const getStringCodec: (options?: StringCodecOptions<NumberCodec, Codec<string>>) => Codec<string>;
|
|
25
|
+
//# sourceMappingURL=string.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/string.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,gBAAgB,EAChB,KAAK,EAGL,OAAO,EACP,OAAO,EAIV,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAgC,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAIjH,6CAA6C;AAC7C,MAAM,MAAM,kBAAkB,CAC1B,OAAO,SAAS,WAAW,GAAG,aAAa,GAAG,aAAa,EAC3D,SAAS,SAAS,KAAK,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,IACnE,gBAAgB,GAAG;IACnB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,UAAU,CAAC;IAErC;;;OAGG;IACH,QAAQ,CAAC,EAAE,SAAS,CAAC;CACxB,CAAC;AAEF,+DAA+D;AAC/D,eAAO,MAAM,gBAAgB,aAAa,mBAAmB,aAAa,EAAE,QAAQ,MAAM,CAAC,CAAC,KAAQ,QAAQ,MAAM,CAuBjH,CAAC;AAEF,+DAA+D;AAC/D,eAAO,MAAM,gBAAgB,aAAa,mBAAmB,aAAa,EAAE,QAAQ,MAAM,CAAC,CAAC,KAAQ,QAAQ,MAAM,CA6BjH,CAAC;AAEF,2EAA2E;AAC3E,eAAO,MAAM,cAAc,aAAa,mBAAmB,WAAW,EAAE,MAAM,MAAM,CAAC,CAAC,KAAQ,MAAM,MAAM,CACpC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Codec, Decoder, Encoder } from '@solana/codecs-core';
|
|
2
|
+
/** Encodes UTF-8 strings using the native `TextEncoder` API. */
|
|
3
|
+
export declare const getUtf8Encoder: () => Encoder<string>;
|
|
4
|
+
/** Decodes UTF-8 strings using the native `TextDecoder` API. */
|
|
5
|
+
export declare const getUtf8Decoder: () => Decoder<string>;
|
|
6
|
+
/** Encodes and decodes UTF-8 strings using the native `TextEncoder` and `TextDecoder` API. */
|
|
7
|
+
export declare const getUtf8Codec: () => Codec<string>;
|
|
8
|
+
//# sourceMappingURL=utf8.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utf8.d.ts","sourceRoot":"","sources":["../../src/utf8.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAgB,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAK5E,gEAAgE;AAChE,eAAO,MAAM,cAAc,QAAO,QAAQ,MAAM,CAQ/C,CAAC;AAEF,gEAAgE;AAChE,eAAO,MAAM,cAAc,QAAO,QAAQ,MAAM,CAW/C,CAAC;AAEF,8FAA8F;AAC9F,eAAO,MAAM,YAAY,QAAO,MAAM,MAAM,CAAqD,CAAC"}
|