@solana/codecs-core 2.0.0-experimental.0099b2a → 2.0.0-experimental.025ef21
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 +390 -5
- package/dist/index.browser.cjs +116 -74
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +109 -74
- package/dist/index.browser.js.map +1 -1
- package/dist/index.native.js +109 -74
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +116 -74
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +109 -74
- package/dist/index.node.js.map +1 -1
- package/dist/types/assertions.d.ts +0 -7
- package/dist/types/assertions.d.ts.map +1 -0
- package/dist/types/bytes.d.ts.map +1 -0
- package/dist/types/codec.d.ts +98 -32
- package/dist/types/codec.d.ts.map +1 -0
- package/dist/types/combine-codec.d.ts +4 -2
- package/dist/types/combine-codec.d.ts.map +1 -0
- package/dist/types/fix-codec.d.ts +4 -7
- package/dist/types/fix-codec.d.ts.map +1 -0
- package/dist/types/index.d.ts +7 -7
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/map-codec.d.ts +13 -5
- package/dist/types/map-codec.d.ts.map +1 -0
- package/dist/types/reverse-codec.d.ts +4 -4
- package/dist/types/reverse-codec.d.ts.map +1 -0
- package/package.json +7 -7
- package/dist/index.development.js +0 -191
- package/dist/index.development.js.map +0 -1
- package/dist/index.production.min.js +0 -26
package/dist/types/codec.d.ts
CHANGED
|
@@ -2,55 +2,121 @@
|
|
|
2
2
|
* Defines an offset in bytes.
|
|
3
3
|
*/
|
|
4
4
|
export type Offset = number;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
type BaseEncoder<TFrom> = {
|
|
6
|
+
/** Encode the provided value and return the encoded bytes directly. */
|
|
7
|
+
readonly encode: (value: TFrom) => Uint8Array;
|
|
8
|
+
/**
|
|
9
|
+
* Writes the encoded value into the provided byte array at the given offset.
|
|
10
|
+
* Returns the offset of the next byte after the encoded value.
|
|
11
|
+
*/
|
|
12
|
+
readonly write: (value: TFrom, bytes: Uint8Array, offset: Offset) => Offset;
|
|
13
|
+
};
|
|
14
|
+
export type FixedSizeEncoder<TFrom, TSize extends number = number> = BaseEncoder<TFrom> & {
|
|
15
|
+
/** The fixed size of the encoded value in bytes. */
|
|
16
|
+
readonly fixedSize: TSize;
|
|
17
|
+
};
|
|
18
|
+
export type VariableSizeEncoder<TFrom> = BaseEncoder<TFrom> & {
|
|
19
|
+
/** The total size of the encoded value in bytes. */
|
|
20
|
+
readonly getSizeFromValue: (value: TFrom) => number;
|
|
21
|
+
/** The maximum size an encoded value can be in bytes, if applicable. */
|
|
22
|
+
readonly maxSize?: number;
|
|
15
23
|
};
|
|
16
24
|
/**
|
|
17
25
|
* An object that can encode a value to a `Uint8Array`.
|
|
18
26
|
*/
|
|
19
|
-
export type Encoder<
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
export type Encoder<TFrom> = FixedSizeEncoder<TFrom> | VariableSizeEncoder<TFrom>;
|
|
28
|
+
type BaseDecoder<TTo> = {
|
|
29
|
+
/** Decodes the provided byte array at the given offset (or zero) and returns the value directly. */
|
|
30
|
+
readonly decode: (bytes: Uint8Array, offset?: Offset) => TTo;
|
|
31
|
+
/**
|
|
32
|
+
* Reads the encoded value from the provided byte array at the given offset.
|
|
33
|
+
* Returns the decoded value and the offset of the next byte after the encoded value.
|
|
34
|
+
*/
|
|
35
|
+
readonly read: (bytes: Uint8Array, offset: Offset) => [TTo, Offset];
|
|
36
|
+
};
|
|
37
|
+
export type FixedSizeDecoder<TTo, TSize extends number = number> = BaseDecoder<TTo> & {
|
|
38
|
+
/** The fixed size of the encoded value in bytes. */
|
|
39
|
+
readonly fixedSize: TSize;
|
|
40
|
+
};
|
|
41
|
+
export type VariableSizeDecoder<TTo> = BaseDecoder<TTo> & {
|
|
42
|
+
/** The maximum size an encoded value can be in bytes, if applicable. */
|
|
43
|
+
readonly maxSize?: number;
|
|
22
44
|
};
|
|
23
45
|
/**
|
|
24
46
|
* An object that can decode a value from a `Uint8Array`.
|
|
25
47
|
*/
|
|
26
|
-
export type Decoder<
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
* It returns the decoded value and the number of bytes read.
|
|
30
|
-
*/
|
|
31
|
-
decode: (bytes: Uint8Array, offset?: Offset) => [T, Offset];
|
|
32
|
-
};
|
|
48
|
+
export type Decoder<TTo> = FixedSizeDecoder<TTo> | VariableSizeDecoder<TTo>;
|
|
49
|
+
export type FixedSizeCodec<TFrom, TTo extends TFrom = TFrom, TSize extends number = number> = FixedSizeEncoder<TFrom, TSize> & FixedSizeDecoder<TTo, TSize>;
|
|
50
|
+
export type VariableSizeCodec<TFrom, TTo extends TFrom = TFrom> = VariableSizeEncoder<TFrom> & VariableSizeDecoder<TTo>;
|
|
33
51
|
/**
|
|
34
52
|
* An object that can encode and decode a value to and from a `Uint8Array`.
|
|
35
53
|
* It supports encoding looser types than it decodes for convenience.
|
|
36
54
|
* For example, a `bigint` encoder will always decode to a `bigint`
|
|
37
55
|
* but can be used to encode a `number`.
|
|
38
56
|
*
|
|
39
|
-
* @typeParam
|
|
40
|
-
* @typeParam
|
|
57
|
+
* @typeParam TFrom - The type of the value to encode.
|
|
58
|
+
* @typeParam TTo - The type of the decoded value. Defaults to `TFrom`.
|
|
41
59
|
*/
|
|
42
|
-
export type Codec<
|
|
60
|
+
export type Codec<TFrom, TTo extends TFrom = TFrom> = FixedSizeCodec<TFrom, TTo> | VariableSizeCodec<TFrom, TTo>;
|
|
43
61
|
/**
|
|
44
|
-
*
|
|
62
|
+
* Get the encoded size of a given value in bytes.
|
|
45
63
|
*/
|
|
46
|
-
export
|
|
47
|
-
|
|
48
|
-
|
|
64
|
+
export declare function getEncodedSize<TFrom>(value: TFrom, encoder: {
|
|
65
|
+
fixedSize: number;
|
|
66
|
+
} | {
|
|
67
|
+
getSizeFromValue: (value: TFrom) => number;
|
|
68
|
+
}): number;
|
|
69
|
+
/** Fills the missing `encode` function using the existing `write` function. */
|
|
70
|
+
export declare function createEncoder<TFrom, TSize extends number>(encoder: Omit<FixedSizeEncoder<TFrom, TSize>, 'encode'>): FixedSizeEncoder<TFrom, TSize>;
|
|
71
|
+
export declare function createEncoder<TFrom>(encoder: Omit<VariableSizeEncoder<TFrom>, 'encode'>): VariableSizeEncoder<TFrom>;
|
|
72
|
+
export declare function createEncoder<TFrom>(encoder: Omit<FixedSizeEncoder<TFrom>, 'encode'> | Omit<VariableSizeEncoder<TFrom>, 'encode'>): Encoder<TFrom>;
|
|
73
|
+
/** Fills the missing `decode` function using the existing `read` function. */
|
|
74
|
+
export declare function createDecoder<TTo, TSize extends number>(decoder: Omit<FixedSizeDecoder<TTo, TSize>, 'decode'>): FixedSizeDecoder<TTo, TSize>;
|
|
75
|
+
export declare function createDecoder<TTo>(decoder: Omit<VariableSizeDecoder<TTo>, 'decode'>): VariableSizeDecoder<TTo>;
|
|
76
|
+
export declare function createDecoder<TTo>(decoder: Omit<FixedSizeDecoder<TTo>, 'decode'> | Omit<VariableSizeDecoder<TTo>, 'decode'>): Decoder<TTo>;
|
|
77
|
+
/** Fills the missing `encode` and `decode` function using the existing `write` and `read` functions. */
|
|
78
|
+
export declare function createCodec<TFrom, TTo extends TFrom = TFrom, TSize extends number = number>(codec: Omit<FixedSizeCodec<TFrom, TTo, TSize>, 'encode' | 'decode'>): FixedSizeCodec<TFrom, TTo, TSize>;
|
|
79
|
+
export declare function createCodec<TFrom, TTo extends TFrom = TFrom>(codec: Omit<VariableSizeCodec<TFrom, TTo>, 'encode' | 'decode'>): VariableSizeCodec<TFrom, TTo>;
|
|
80
|
+
export declare function createCodec<TFrom, TTo extends TFrom = TFrom>(codec: Omit<FixedSizeCodec<TFrom, TTo>, 'encode' | 'decode'> | Omit<VariableSizeCodec<TFrom, TTo>, 'encode' | 'decode'>): Codec<TFrom, TTo>;
|
|
81
|
+
export declare function isFixedSize<TFrom, TSize extends number>(encoder: FixedSizeEncoder<TFrom, TSize> | VariableSizeEncoder<TFrom>): encoder is FixedSizeEncoder<TFrom, TSize>;
|
|
82
|
+
export declare function isFixedSize<TTo, TSize extends number>(decoder: FixedSizeDecoder<TTo, TSize> | VariableSizeDecoder<TTo>): decoder is FixedSizeDecoder<TTo, TSize>;
|
|
83
|
+
export declare function isFixedSize<TFrom, TTo extends TFrom, TSize extends number>(codec: FixedSizeCodec<TFrom, TTo, TSize> | VariableSizeCodec<TFrom, TTo>): codec is FixedSizeCodec<TFrom, TTo, TSize>;
|
|
84
|
+
export declare function isFixedSize<TSize extends number>(codec: {
|
|
85
|
+
fixedSize: TSize;
|
|
86
|
+
} | {
|
|
87
|
+
maxSize?: number;
|
|
88
|
+
}): codec is {
|
|
89
|
+
fixedSize: TSize;
|
|
49
90
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
export
|
|
54
|
-
|
|
91
|
+
export declare function assertIsFixedSize<TFrom, TSize extends number>(encoder: FixedSizeEncoder<TFrom, TSize> | VariableSizeEncoder<TFrom>, message?: string): asserts encoder is FixedSizeEncoder<TFrom, TSize>;
|
|
92
|
+
export declare function assertIsFixedSize<TTo, TSize extends number>(decoder: FixedSizeDecoder<TTo, TSize> | VariableSizeDecoder<TTo>, message?: string): asserts decoder is FixedSizeDecoder<TTo, TSize>;
|
|
93
|
+
export declare function assertIsFixedSize<TFrom, TTo extends TFrom, TSize extends number>(codec: FixedSizeCodec<TFrom, TTo, TSize> | VariableSizeCodec<TFrom, TTo>, message?: string): asserts codec is FixedSizeCodec<TFrom, TTo, TSize>;
|
|
94
|
+
export declare function assertIsFixedSize<TSize extends number>(codec: {
|
|
95
|
+
fixedSize: TSize;
|
|
96
|
+
} | {
|
|
97
|
+
maxSize?: number;
|
|
98
|
+
}, message?: string): asserts codec is {
|
|
99
|
+
fixedSize: TSize;
|
|
100
|
+
};
|
|
101
|
+
export declare function isVariableSize<TFrom>(encoder: Encoder<TFrom>): encoder is VariableSizeEncoder<TFrom>;
|
|
102
|
+
export declare function isVariableSize<TTo>(decoder: Decoder<TTo>): decoder is VariableSizeDecoder<TTo>;
|
|
103
|
+
export declare function isVariableSize<TFrom, TTo extends TFrom>(codec: Codec<TFrom, TTo>): codec is VariableSizeCodec<TFrom, TTo>;
|
|
104
|
+
export declare function isVariableSize(codec: {
|
|
105
|
+
fixedSize: number;
|
|
106
|
+
} | {
|
|
107
|
+
maxSize?: number;
|
|
108
|
+
}): codec is {
|
|
109
|
+
maxSize?: number;
|
|
110
|
+
};
|
|
111
|
+
export declare function assertIsVariableSize<T>(encoder: Encoder<T>, message?: string): asserts encoder is VariableSizeEncoder<T>;
|
|
112
|
+
export declare function assertIsVariableSize<T>(decoder: Decoder<T>, message?: string): asserts decoder is VariableSizeDecoder<T>;
|
|
113
|
+
export declare function assertIsVariableSize<TFrom, TTo extends TFrom>(codec: Codec<TFrom, TTo>, message?: string): asserts codec is VariableSizeCodec<TFrom, TTo>;
|
|
114
|
+
export declare function assertIsVariableSize(codec: {
|
|
115
|
+
fixedSize: number;
|
|
116
|
+
} | {
|
|
117
|
+
maxSize?: number;
|
|
118
|
+
}, message?: string): asserts codec is {
|
|
119
|
+
maxSize?: number;
|
|
55
120
|
};
|
|
121
|
+
export {};
|
|
56
122
|
//# sourceMappingURL=codec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../src/codec.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC;AAE5B,KAAK,WAAW,CAAC,KAAK,IAAI;IACtB,uEAAuE;IACvE,QAAQ,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,UAAU,CAAC;IAC9C;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,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OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { Codec, Decoder, Encoder } from './codec';
|
|
1
|
+
import { Codec, Decoder, Encoder, FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder, VariableSizeCodec, VariableSizeDecoder, VariableSizeEncoder } from './codec.js';
|
|
2
2
|
/**
|
|
3
3
|
* Combines an encoder and a decoder into a codec.
|
|
4
4
|
* The encoder and decoder must have the same fixed size, max size and description.
|
|
5
5
|
* If a description is provided, it will override the encoder and decoder descriptions.
|
|
6
6
|
*/
|
|
7
|
-
export declare function combineCodec<
|
|
7
|
+
export declare function combineCodec<TFrom, TTo extends TFrom, TSize extends number>(encoder: FixedSizeEncoder<TFrom, TSize>, decoder: FixedSizeDecoder<TTo, TSize>): FixedSizeCodec<TFrom, TTo, TSize>;
|
|
8
|
+
export declare function combineCodec<TFrom, TTo extends TFrom>(encoder: VariableSizeEncoder<TFrom>, decoder: VariableSizeDecoder<TTo>): VariableSizeCodec<TFrom, TTo>;
|
|
9
|
+
export declare function combineCodec<TFrom, TTo extends TFrom>(encoder: Encoder<TFrom>, decoder: Decoder<TTo>): Codec<TFrom, TTo>;
|
|
8
10
|
//# sourceMappingURL=combine-codec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"combine-codec.d.ts","sourceRoot":"","sources":["../../src/combine-codec.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,EACL,OAAO,EACP,OAAO,EACP,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAEhB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACtB,MAAM,SAAS,CAAC;AAEjB;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,GAAG,SAAS,KAAK,EAAE,KAAK,SAAS,MAAM,EACvE,OAAO,EAAE,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,EACvC,OAAO,EAAE,gBAAgB,CAAC,GAAG,EAAE,KAAK,CAAC,GACtC,cAAc,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AACrC,wBAAgB,YAAY,CAAC,KAAK,EAAE,GAAG,SAAS,KAAK,EACjD,OAAO,EAAE,mBAAmB,CAAC,KAAK,CAAC,EACnC,OAAO,EAAE,mBAAmB,CAAC,GAAG,CAAC,GAClC,iBAAiB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACjC,wBAAgB,YAAY,CAAC,KAAK,EAAE,GAAG,SAAS,KAAK,EACjD,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,EACvB,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,GACtB,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC"}
|
|
@@ -1,26 +1,23 @@
|
|
|
1
|
-
import { Codec, Decoder, Encoder } from './codec';
|
|
1
|
+
import { Codec, Decoder, Encoder, FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder } from './codec.js';
|
|
2
2
|
/**
|
|
3
3
|
* Creates a fixed-size encoder from a given encoder.
|
|
4
4
|
*
|
|
5
5
|
* @param encoder - The encoder to wrap into a fixed-size encoder.
|
|
6
6
|
* @param fixedBytes - The fixed number of bytes to write.
|
|
7
|
-
* @param description - A custom description for the encoder.
|
|
8
7
|
*/
|
|
9
|
-
export declare function fixEncoder<
|
|
8
|
+
export declare function fixEncoder<TFrom, TSize extends number>(encoder: Encoder<TFrom>, fixedBytes: TSize): FixedSizeEncoder<TFrom, TSize>;
|
|
10
9
|
/**
|
|
11
10
|
* Creates a fixed-size decoder from a given decoder.
|
|
12
11
|
*
|
|
13
12
|
* @param decoder - The decoder to wrap into a fixed-size decoder.
|
|
14
13
|
* @param fixedBytes - The fixed number of bytes to read.
|
|
15
|
-
* @param description - A custom description for the decoder.
|
|
16
14
|
*/
|
|
17
|
-
export declare function fixDecoder<
|
|
15
|
+
export declare function fixDecoder<TTo, TSize extends number>(decoder: Decoder<TTo>, fixedBytes: TSize): FixedSizeDecoder<TTo, TSize>;
|
|
18
16
|
/**
|
|
19
17
|
* Creates a fixed-size codec from a given codec.
|
|
20
18
|
*
|
|
21
19
|
* @param codec - The codec to wrap into a fixed-size codec.
|
|
22
20
|
* @param fixedBytes - The fixed number of bytes to read/write.
|
|
23
|
-
* @param description - A custom description for the codec.
|
|
24
21
|
*/
|
|
25
|
-
export declare function fixCodec<
|
|
22
|
+
export declare function fixCodec<TFrom, TTo extends TFrom, TSize extends number>(codec: Codec<TFrom, TTo>, fixedBytes: TSize): FixedSizeCodec<TFrom, TTo, TSize>;
|
|
26
23
|
//# sourceMappingURL=fix-codec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fix-codec.d.ts","sourceRoot":"","sources":["../../src/fix-codec.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,KAAK,EAGL,OAAO,EACP,OAAO,EACP,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAGnB,MAAM,SAAS,CAAC;AAGjB;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,KAAK,SAAS,MAAM,EAClD,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,EACvB,UAAU,EAAE,KAAK,GAClB,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,CAchC;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,KAAK,SAAS,MAAM,EAChD,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,EACrB,UAAU,EAAE,KAAK,GAClB,gBAAgB,CAAC,GAAG,EAAE,KAAK,CAAC,CAkB9B;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,GAAG,SAAS,KAAK,EAAE,KAAK,SAAS,MAAM,EACnE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,EACxB,UAAU,EAAE,KAAK,GAClB,cAAc,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,CAEnC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from './assertions';
|
|
2
|
-
export * from './bytes';
|
|
3
|
-
export * from './codec';
|
|
4
|
-
export * from './combine-codec';
|
|
5
|
-
export * from './fix-codec';
|
|
6
|
-
export * from './map-codec';
|
|
7
|
-
export * from './reverse-codec';
|
|
1
|
+
export * from './assertions.js';
|
|
2
|
+
export * from './bytes.js';
|
|
3
|
+
export * from './codec.js';
|
|
4
|
+
export * from './combine-codec.js';
|
|
5
|
+
export * from './fix-codec.js';
|
|
6
|
+
export * from './map-codec.js';
|
|
7
|
+
export * from './reverse-codec.js';
|
|
8
8
|
//# 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,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC"}
|
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
import { Codec, Decoder, Encoder } from './codec';
|
|
1
|
+
import { Codec, Decoder, Encoder, FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder, VariableSizeCodec, VariableSizeDecoder, VariableSizeEncoder } from './codec.js';
|
|
2
2
|
/**
|
|
3
3
|
* Converts an encoder A to a encoder B by mapping their values.
|
|
4
4
|
*/
|
|
5
|
-
export declare function mapEncoder<
|
|
5
|
+
export declare function mapEncoder<TOldFrom, TNewFrom, TSize extends number>(encoder: FixedSizeEncoder<TOldFrom, TSize>, unmap: (value: TNewFrom) => TOldFrom): FixedSizeEncoder<TNewFrom, TSize>;
|
|
6
|
+
export declare function mapEncoder<TOldFrom, TNewFrom>(encoder: VariableSizeEncoder<TOldFrom>, unmap: (value: TNewFrom) => TOldFrom): VariableSizeEncoder<TNewFrom>;
|
|
7
|
+
export declare function mapEncoder<TOldFrom, TNewFrom>(encoder: Encoder<TOldFrom>, unmap: (value: TNewFrom) => TOldFrom): Encoder<TNewFrom>;
|
|
6
8
|
/**
|
|
7
9
|
* Converts an decoder A to a decoder B by mapping their values.
|
|
8
10
|
*/
|
|
9
|
-
export declare function mapDecoder<
|
|
11
|
+
export declare function mapDecoder<TOldTo, TNewTo, TSize extends number>(decoder: FixedSizeDecoder<TOldTo, TSize>, map: (value: TOldTo, bytes: Uint8Array, offset: number) => TNewTo): FixedSizeDecoder<TNewTo, TSize>;
|
|
12
|
+
export declare function mapDecoder<TOldTo, TNewTo>(decoder: VariableSizeDecoder<TOldTo>, map: (value: TOldTo, bytes: Uint8Array, offset: number) => TNewTo): VariableSizeDecoder<TNewTo>;
|
|
13
|
+
export declare function mapDecoder<TOldTo, TNewTo>(decoder: Decoder<TOldTo>, map: (value: TOldTo, bytes: Uint8Array, offset: number) => TNewTo): Decoder<TNewTo>;
|
|
10
14
|
/**
|
|
11
15
|
* Converts a codec A to a codec B by mapping their values.
|
|
12
16
|
*/
|
|
13
|
-
export declare function mapCodec<
|
|
14
|
-
export declare function mapCodec<
|
|
17
|
+
export declare function mapCodec<TOldFrom, TNewFrom, TTo extends TNewFrom & TOldFrom, TSize extends number>(codec: FixedSizeCodec<TOldFrom, TTo, TSize>, unmap: (value: TNewFrom) => TOldFrom): FixedSizeCodec<TNewFrom, TTo, TSize>;
|
|
18
|
+
export declare function mapCodec<TOldFrom, TNewFrom, TTo extends TNewFrom & TOldFrom>(codec: VariableSizeCodec<TOldFrom, TTo>, unmap: (value: TNewFrom) => TOldFrom): VariableSizeCodec<TNewFrom, TTo>;
|
|
19
|
+
export declare function mapCodec<TOldFrom, TNewFrom, TTo extends TNewFrom & TOldFrom>(codec: Codec<TOldFrom, TTo>, unmap: (value: TNewFrom) => TOldFrom): Codec<TNewFrom, TTo>;
|
|
20
|
+
export declare function mapCodec<TOldFrom, TNewFrom, TOldTo extends TOldFrom, TNewTo extends TNewFrom, TSize extends number>(codec: FixedSizeCodec<TOldFrom, TOldTo, TSize>, unmap: (value: TNewFrom) => TOldFrom, map: (value: TOldTo, bytes: Uint8Array, offset: number) => TNewTo): FixedSizeCodec<TNewFrom, TNewTo, TSize>;
|
|
21
|
+
export declare function mapCodec<TOldFrom, TNewFrom, TOldTo extends TOldFrom, TNewTo extends TNewFrom>(codec: VariableSizeCodec<TOldFrom, TOldTo>, unmap: (value: TNewFrom) => TOldFrom, map: (value: TOldTo, bytes: Uint8Array, offset: number) => TNewTo): VariableSizeCodec<TNewFrom, TNewTo>;
|
|
22
|
+
export declare function mapCodec<TOldFrom, TNewFrom, TOldTo extends TOldFrom, TNewTo extends TNewFrom>(codec: Codec<TOldFrom, TOldTo>, unmap: (value: TNewFrom) => TOldFrom, map: (value: TOldTo, bytes: Uint8Array, offset: number) => TNewTo): Codec<TNewFrom, TNewTo>;
|
|
15
23
|
//# sourceMappingURL=map-codec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map-codec.d.ts","sourceRoot":"","sources":["../../src/map-codec.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,EAIL,OAAO,EACP,OAAO,EACP,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAEhB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACtB,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,SAAS,MAAM,EAC/D,OAAO,EAAE,gBAAgB,CAAC,QAAQ,EAAE,KAAK,CAAC,EAC1C,KAAK,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,QAAQ,GACrC,gBAAgB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;AACrC,wBAAgB,UAAU,CAAC,QAAQ,EAAE,QAAQ,EACzC,OAAO,EAAE,mBAAmB,CAAC,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AAQ,KAAK,QAAQ,EACpC,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,GAClE,iBAAiB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AACvC,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,SAAS,QAAQ,EAAE,MAAM,SAAS,QAAQ,EACzF,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,EAC9B,KAAK,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,QAAQ,EACpC,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,GAClE,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FixedSizeCodec, FixedSizeDecoder, FixedSizeEncoder } from './codec.js';
|
|
2
2
|
/**
|
|
3
3
|
* Reverses the bytes of a fixed-size encoder.
|
|
4
4
|
*/
|
|
5
|
-
export declare function reverseEncoder<
|
|
5
|
+
export declare function reverseEncoder<TFrom, TSize extends number>(encoder: FixedSizeEncoder<TFrom, TSize>): FixedSizeEncoder<TFrom, TSize>;
|
|
6
6
|
/**
|
|
7
7
|
* Reverses the bytes of a fixed-size decoder.
|
|
8
8
|
*/
|
|
9
|
-
export declare function reverseDecoder<
|
|
9
|
+
export declare function reverseDecoder<TTo, TSize extends number>(decoder: FixedSizeDecoder<TTo, TSize>): FixedSizeDecoder<TTo, TSize>;
|
|
10
10
|
/**
|
|
11
11
|
* Reverses the bytes of a fixed-size codec.
|
|
12
12
|
*/
|
|
13
|
-
export declare function reverseCodec<
|
|
13
|
+
export declare function reverseCodec<TFrom, TTo extends TFrom, TSize extends number>(codec: FixedSizeCodec<TFrom, TTo, TSize>): FixedSizeCodec<TFrom, TTo, TSize>;
|
|
14
14
|
//# sourceMappingURL=reverse-codec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reverse-codec.d.ts","sourceRoot":"","sources":["../../src/reverse-codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EACnB,MAAM,SAAS,CAAC;AAGjB;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,SAAS,MAAM,EACtD,OAAO,EAAE,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,GACxC,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,CAWhC;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,KAAK,SAAS,MAAM,EACpD,OAAO,EAAE,gBAAgB,CAAC,GAAG,EAAE,KAAK,CAAC,GACtC,gBAAgB,CAAC,GAAG,EAAE,KAAK,CAAC,CAc9B;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,GAAG,SAAS,KAAK,EAAE,KAAK,SAAS,MAAM,EACvE,KAAK,EAAE,cAAc,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,GACzC,cAAc,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,CAEnC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana/codecs-core",
|
|
3
|
-
"version": "2.0.0-experimental.
|
|
3
|
+
"version": "2.0.0-experimental.025ef21",
|
|
4
4
|
"description": "Core types and helpers for encoding and decoding byte arrays on Solana",
|
|
5
5
|
"exports": {
|
|
6
6
|
"browser": {
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@solana/eslint-config-solana": "^1.0.2",
|
|
53
53
|
"@swc/jest": "^0.2.29",
|
|
54
|
-
"@types/jest": "^29.5.
|
|
55
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
54
|
+
"@types/jest": "^29.5.11",
|
|
55
|
+
"@typescript-eslint/eslint-plugin": "^6.13.2",
|
|
56
56
|
"@typescript-eslint/parser": "^6.3.0",
|
|
57
57
|
"agadoo": "^3.0.0",
|
|
58
58
|
"eslint": "^8.45.0",
|
|
@@ -62,8 +62,8 @@
|
|
|
62
62
|
"jest-environment-jsdom": "^29.7.0",
|
|
63
63
|
"jest-runner-eslint": "^2.1.2",
|
|
64
64
|
"jest-runner-prettier": "^1.0.0",
|
|
65
|
-
"prettier": "^
|
|
66
|
-
"tsup": "
|
|
65
|
+
"prettier": "^3.1",
|
|
66
|
+
"tsup": "^8.0.1",
|
|
67
67
|
"typescript": "^5.2.2",
|
|
68
68
|
"version-from-git": "^1.1.1",
|
|
69
69
|
"build-scripts": "0.0.0",
|
|
@@ -79,8 +79,8 @@
|
|
|
79
79
|
]
|
|
80
80
|
},
|
|
81
81
|
"scripts": {
|
|
82
|
-
"compile:js": "tsup --config build-scripts/tsup.config.
|
|
83
|
-
"compile:typedefs": "tsc -p ./tsconfig.declarations.json",
|
|
82
|
+
"compile:js": "tsup --config build-scripts/tsup.config.package.ts",
|
|
83
|
+
"compile:typedefs": "tsc -p ./tsconfig.declarations.json && node node_modules/build-scripts/add-js-extension-to-types.mjs",
|
|
84
84
|
"dev": "jest -c node_modules/test-config/jest-dev.config.ts --rootDir . --watch",
|
|
85
85
|
"publish-packages": "pnpm publish --tag experimental --access public --no-git-checks",
|
|
86
86
|
"style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/* package.json",
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
this.globalThis = this.globalThis || {};
|
|
2
|
-
this.globalThis.solanaWeb3 = (function (exports) {
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
// src/assertions.ts
|
|
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
|
-
function assertFixedSizeCodec(data, message) {
|
|
18
|
-
if (data.fixedSize === null) {
|
|
19
|
-
throw new Error(message ?? "Expected a fixed-size codec, got a variable-size one.");
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// src/bytes.ts
|
|
24
|
-
var mergeBytes = (byteArrays) => {
|
|
25
|
-
const nonEmptyByteArrays = byteArrays.filter((arr) => arr.length);
|
|
26
|
-
if (nonEmptyByteArrays.length === 0) {
|
|
27
|
-
return byteArrays.length ? byteArrays[0] : new Uint8Array();
|
|
28
|
-
}
|
|
29
|
-
if (nonEmptyByteArrays.length === 1) {
|
|
30
|
-
return nonEmptyByteArrays[0];
|
|
31
|
-
}
|
|
32
|
-
const totalLength = nonEmptyByteArrays.reduce((total, arr) => total + arr.length, 0);
|
|
33
|
-
const result = new Uint8Array(totalLength);
|
|
34
|
-
let offset = 0;
|
|
35
|
-
nonEmptyByteArrays.forEach((arr) => {
|
|
36
|
-
result.set(arr, offset);
|
|
37
|
-
offset += arr.length;
|
|
38
|
-
});
|
|
39
|
-
return result;
|
|
40
|
-
};
|
|
41
|
-
var padBytes = (bytes, length) => {
|
|
42
|
-
if (bytes.length >= length)
|
|
43
|
-
return bytes;
|
|
44
|
-
const paddedBytes = new Uint8Array(length).fill(0);
|
|
45
|
-
paddedBytes.set(bytes);
|
|
46
|
-
return paddedBytes;
|
|
47
|
-
};
|
|
48
|
-
var fixBytes = (bytes, length) => padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length);
|
|
49
|
-
|
|
50
|
-
// src/combine-codec.ts
|
|
51
|
-
function combineCodec(encoder, decoder, description) {
|
|
52
|
-
if (encoder.fixedSize !== decoder.fixedSize) {
|
|
53
|
-
throw new Error(
|
|
54
|
-
`Encoder and decoder must have the same fixed size, got [${encoder.fixedSize}] and [${decoder.fixedSize}].`
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
if (encoder.maxSize !== decoder.maxSize) {
|
|
58
|
-
throw new Error(
|
|
59
|
-
`Encoder and decoder must have the same max size, got [${encoder.maxSize}] and [${decoder.maxSize}].`
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
if (description === void 0 && encoder.description !== decoder.description) {
|
|
63
|
-
throw new Error(
|
|
64
|
-
`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.`
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
return {
|
|
68
|
-
decode: decoder.decode,
|
|
69
|
-
description: description ?? encoder.description,
|
|
70
|
-
encode: encoder.encode,
|
|
71
|
-
fixedSize: encoder.fixedSize,
|
|
72
|
-
maxSize: encoder.maxSize
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// src/fix-codec.ts
|
|
77
|
-
function fixCodecHelper(data, fixedBytes, description) {
|
|
78
|
-
return {
|
|
79
|
-
description: description ?? `fixed(${fixedBytes}, ${data.description})`,
|
|
80
|
-
fixedSize: fixedBytes,
|
|
81
|
-
maxSize: fixedBytes
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
function fixEncoder(encoder, fixedBytes, description) {
|
|
85
|
-
return {
|
|
86
|
-
...fixCodecHelper(encoder, fixedBytes, description),
|
|
87
|
-
encode: (value) => fixBytes(encoder.encode(value), fixedBytes)
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
function fixDecoder(decoder, fixedBytes, description) {
|
|
91
|
-
return {
|
|
92
|
-
...fixCodecHelper(decoder, fixedBytes, description),
|
|
93
|
-
decode: (bytes, offset = 0) => {
|
|
94
|
-
assertByteArrayHasEnoughBytesForCodec("fixCodec", fixedBytes, bytes, offset);
|
|
95
|
-
if (offset > 0 || bytes.length > fixedBytes) {
|
|
96
|
-
bytes = bytes.slice(offset, offset + fixedBytes);
|
|
97
|
-
}
|
|
98
|
-
if (decoder.fixedSize !== null) {
|
|
99
|
-
bytes = fixBytes(bytes, decoder.fixedSize);
|
|
100
|
-
}
|
|
101
|
-
const [value] = decoder.decode(bytes, 0);
|
|
102
|
-
return [value, offset + fixedBytes];
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
function fixCodec(codec, fixedBytes, description) {
|
|
107
|
-
return combineCodec(fixEncoder(codec, fixedBytes, description), fixDecoder(codec, fixedBytes, description));
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// src/map-codec.ts
|
|
111
|
-
function mapEncoder(encoder, unmap) {
|
|
112
|
-
return {
|
|
113
|
-
description: encoder.description,
|
|
114
|
-
encode: (value) => encoder.encode(unmap(value)),
|
|
115
|
-
fixedSize: encoder.fixedSize,
|
|
116
|
-
maxSize: encoder.maxSize
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
function mapDecoder(decoder, map) {
|
|
120
|
-
return {
|
|
121
|
-
decode: (bytes, offset = 0) => {
|
|
122
|
-
const [value, length] = decoder.decode(bytes, offset);
|
|
123
|
-
return [map(value, bytes, offset), length];
|
|
124
|
-
},
|
|
125
|
-
description: decoder.description,
|
|
126
|
-
fixedSize: decoder.fixedSize,
|
|
127
|
-
maxSize: decoder.maxSize
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
function mapCodec(codec, unmap, map) {
|
|
131
|
-
return {
|
|
132
|
-
decode: map ? mapDecoder(codec, map).decode : codec.decode,
|
|
133
|
-
description: codec.description,
|
|
134
|
-
encode: mapEncoder(codec, unmap).encode,
|
|
135
|
-
fixedSize: codec.fixedSize,
|
|
136
|
-
maxSize: codec.maxSize
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// src/reverse-codec.ts
|
|
141
|
-
function reverseEncoder(encoder) {
|
|
142
|
-
assertFixedSizeCodec(encoder, "Cannot reverse a codec of variable size.");
|
|
143
|
-
return {
|
|
144
|
-
...encoder,
|
|
145
|
-
encode: (value) => encoder.encode(value).reverse()
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
function reverseDecoder(decoder) {
|
|
149
|
-
assertFixedSizeCodec(decoder, "Cannot reverse a codec of variable size.");
|
|
150
|
-
return {
|
|
151
|
-
...decoder,
|
|
152
|
-
decode: (bytes, offset = 0) => {
|
|
153
|
-
const reverseEnd = offset + decoder.fixedSize;
|
|
154
|
-
if (offset === 0 && bytes.length === reverseEnd) {
|
|
155
|
-
return decoder.decode(bytes.reverse(), offset);
|
|
156
|
-
}
|
|
157
|
-
const newBytes = mergeBytes([
|
|
158
|
-
...offset === 0 ? [] : [bytes.slice(0, offset)],
|
|
159
|
-
bytes.slice(offset, reverseEnd).reverse(),
|
|
160
|
-
...bytes.length === reverseEnd ? [] : [bytes.slice(reverseEnd)]
|
|
161
|
-
]);
|
|
162
|
-
return decoder.decode(newBytes, offset);
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
function reverseCodec(codec) {
|
|
167
|
-
return combineCodec(reverseEncoder(codec), reverseDecoder(codec));
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
exports.assertByteArrayHasEnoughBytesForCodec = assertByteArrayHasEnoughBytesForCodec;
|
|
171
|
-
exports.assertByteArrayIsNotEmptyForCodec = assertByteArrayIsNotEmptyForCodec;
|
|
172
|
-
exports.assertFixedSizeCodec = assertFixedSizeCodec;
|
|
173
|
-
exports.combineCodec = combineCodec;
|
|
174
|
-
exports.fixBytes = fixBytes;
|
|
175
|
-
exports.fixCodec = fixCodec;
|
|
176
|
-
exports.fixDecoder = fixDecoder;
|
|
177
|
-
exports.fixEncoder = fixEncoder;
|
|
178
|
-
exports.mapCodec = mapCodec;
|
|
179
|
-
exports.mapDecoder = mapDecoder;
|
|
180
|
-
exports.mapEncoder = mapEncoder;
|
|
181
|
-
exports.mergeBytes = mergeBytes;
|
|
182
|
-
exports.padBytes = padBytes;
|
|
183
|
-
exports.reverseCodec = reverseCodec;
|
|
184
|
-
exports.reverseDecoder = reverseDecoder;
|
|
185
|
-
exports.reverseEncoder = reverseEncoder;
|
|
186
|
-
|
|
187
|
-
return exports;
|
|
188
|
-
|
|
189
|
-
})({});
|
|
190
|
-
//# sourceMappingURL=out.js.map
|
|
191
|
-
//# sourceMappingURL=index.development.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/assertions.ts","../src/bytes.ts","../src/combine-codec.ts","../src/fix-codec.ts","../src/map-codec.ts","../src/reverse-codec.ts"],"names":[],"mappings":";AAKO,SAAS,kCAAkC,kBAA0B,OAAmB,SAAS,GAAG;AACvG,MAAI,MAAM,SAAS,UAAU,GAAG;AAE5B,UAAM,IAAI,MAAM,UAAU,gBAAgB,oCAAoC;AAAA,EAClF;AACJ;AAKO,SAAS,sCACZ,kBACA,UACA,OACA,SAAS,GACX;AACE,QAAM,cAAc,MAAM,SAAS;AACnC,MAAI,cAAc,UAAU;AAExB,UAAM,IAAI,MAAM,UAAU,gBAAgB,cAAc,QAAQ,eAAe,WAAW,GAAG;AAAA,EACjG;AACJ;AAKO,SAAS,qBACZ,MACA,SACqC;AACrC,MAAI,KAAK,cAAc,MAAM;AAEzB,UAAM,IAAI,MAAM,WAAW,uDAAuD;AAAA,EACtF;AACJ;;;ACnCO,IAAM,aAAa,CAAC,eAAyC;AAChE,QAAM,qBAAqB,WAAW,OAAO,SAAO,IAAI,MAAM;AAC9D,MAAI,mBAAmB,WAAW,GAAG;AACjC,WAAO,WAAW,SAAS,WAAW,CAAC,IAAI,IAAI,WAAW;AAAA,EAC9D;AAEA,MAAI,mBAAmB,WAAW,GAAG;AACjC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esContent":["import { CodecData } from './codec';\n\n/**\n * Asserts that a given byte array is not empty.\n */\nexport function assertByteArrayIsNotEmptyForCodec(codecDescription: string, bytes: Uint8Array, offset = 0) {\n if (bytes.length - offset <= 0) {\n // TODO: Coded error.\n throw new Error(`Codec [${codecDescription}] cannot decode empty byte arrays.`);\n }\n}\n\n/**\n * Asserts that a given byte array has enough bytes to decode.\n */\nexport function assertByteArrayHasEnoughBytesForCodec(\n codecDescription: string,\n expected: number,\n bytes: Uint8Array,\n offset = 0\n) {\n const bytesLength = bytes.length - offset;\n if (bytesLength < expected) {\n // TODO: Coded error.\n throw new Error(`Codec [${codecDescription}] expected ${expected} bytes, got ${bytesLength}.`);\n }\n}\n\n/**\n * Asserts that a given codec is fixed-size codec.\n */\nexport function assertFixedSizeCodec(\n data: Pick<CodecData, 'fixedSize'>,\n message?: string\n): asserts data is { fixedSize: number } {\n if (data.fixedSize === null) {\n // TODO: Coded error.\n throw new Error(message ?? 'Expected a fixed-size codec, got a variable-size one.');\n }\n}\n","/**\n * Concatenates an array of `Uint8Array`s into a single `Uint8Array`.\n * Reuses the original byte array when applicable.\n */\nexport const mergeBytes = (byteArrays: Uint8Array[]): Uint8Array => {\n const nonEmptyByteArrays = byteArrays.filter(arr => arr.length);\n if (nonEmptyByteArrays.length === 0) {\n return byteArrays.length ? byteArrays[0] : new Uint8Array();\n }\n\n if (nonEmptyByteArrays.length === 1) {\n return nonEmptyByteArrays[0];\n }\n\n const totalLength = nonEmptyByteArrays.reduce((total, arr) => total + arr.length, 0);\n const result = new Uint8Array(totalLength);\n let offset = 0;\n nonEmptyByteArrays.forEach(arr => {\n result.set(arr, offset);\n offset += arr.length;\n });\n return result;\n};\n\n/**\n * Pads a `Uint8Array` with zeroes to the specified length.\n * If the array is longer than the specified length, it is returned as-is.\n */\nexport const padBytes = (bytes: Uint8Array, length: number): Uint8Array => {\n if (bytes.length >= length) return bytes;\n const paddedBytes = new Uint8Array(length).fill(0);\n paddedBytes.set(bytes);\n return paddedBytes;\n};\n\n/**\n * Fixes a `Uint8Array` to the specified length.\n * If the array is longer than the specified length, it is truncated.\n * If the array is shorter than the specified length, it is padded with zeroes.\n */\nexport const fixBytes = (bytes: Uint8Array, length: number): Uint8Array =>\n padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length);\n","import { Codec, Decoder, Encoder } from './codec';\n\n/**\n * Combines an encoder and a decoder into a codec.\n * The encoder and decoder must have the same fixed size, max size and description.\n * If a description is provided, it will override the encoder and decoder descriptions.\n */\nexport function combineCodec<From, To extends From = From>(\n encoder: Encoder<From>,\n decoder: Decoder<To>,\n description?: string\n): Codec<From, To> {\n if (encoder.fixedSize !== decoder.fixedSize) {\n // TODO: Coded error.\n throw new Error(\n `Encoder and decoder must have the same fixed size, got [${encoder.fixedSize}] and [${decoder.fixedSize}].`\n );\n }\n\n if (encoder.maxSize !== decoder.maxSize) {\n // TODO: Coded error.\n throw new Error(\n `Encoder and decoder must have the same max size, got [${encoder.maxSize}] and [${decoder.maxSize}].`\n );\n }\n\n if (description === undefined && encoder.description !== decoder.description) {\n // TODO: Coded error.\n throw new Error(\n `Encoder and decoder must have the same description, got [${encoder.description}] and [${decoder.description}]. ` +\n `Pass a custom description as a third argument if you want to override the description and bypass this error.`\n );\n }\n\n return {\n decode: decoder.decode,\n description: description ?? encoder.description,\n encode: encoder.encode,\n fixedSize: encoder.fixedSize,\n maxSize: encoder.maxSize,\n };\n}\n","import { assertByteArrayHasEnoughBytesForCodec } from './assertions';\nimport { fixBytes } from './bytes';\nimport { Codec, CodecData, Decoder, Encoder } from './codec';\nimport { combineCodec } from './combine-codec';\n\nfunction fixCodecHelper(data: CodecData, fixedBytes: number, description?: string): CodecData {\n return {\n description: description ?? `fixed(${fixedBytes}, ${data.description})`,\n fixedSize: fixedBytes,\n maxSize: fixedBytes,\n };\n}\n\n/**\n * Creates a fixed-size encoder from a given encoder.\n *\n * @param encoder - The encoder to wrap into a fixed-size encoder.\n * @param fixedBytes - The fixed number of bytes to write.\n * @param description - A custom description for the encoder.\n */\nexport function fixEncoder<T>(encoder: Encoder<T>, fixedBytes: number, description?: string): Encoder<T> {\n return {\n ...fixCodecHelper(encoder, fixedBytes, description),\n encode: (value: T) => fixBytes(encoder.encode(value), fixedBytes),\n };\n}\n\n/**\n * Creates a fixed-size decoder from a given decoder.\n *\n * @param decoder - The decoder to wrap into a fixed-size decoder.\n * @param fixedBytes - The fixed number of bytes to read.\n * @param description - A custom description for the decoder.\n */\nexport function fixDecoder<T>(decoder: Decoder<T>, fixedBytes: number, description?: string): Decoder<T> {\n return {\n ...fixCodecHelper(decoder, fixedBytes, description),\n decode: (bytes: Uint8Array, offset = 0) => {\n assertByteArrayHasEnoughBytesForCodec('fixCodec', fixedBytes, bytes, offset);\n // Slice the byte array to the fixed size if necessary.\n if (offset > 0 || bytes.length > fixedBytes) {\n bytes = bytes.slice(offset, offset + fixedBytes);\n }\n // If the nested decoder is fixed-size, pad and truncate the byte array accordingly.\n if (decoder.fixedSize !== null) {\n bytes = fixBytes(bytes, decoder.fixedSize);\n }\n // Decode the value using the nested decoder.\n const [value] = decoder.decode(bytes, 0);\n return [value, offset + fixedBytes];\n },\n };\n}\n\n/**\n * Creates a fixed-size codec from a given codec.\n *\n * @param codec - The codec to wrap into a fixed-size codec.\n * @param fixedBytes - The fixed number of bytes to read/write.\n * @param description - A custom description for the codec.\n */\nexport function fixCodec<T, U extends T = T>(\n codec: Codec<T, U>,\n fixedBytes: number,\n description?: string\n): Codec<T, U> {\n return combineCodec(fixEncoder(codec, fixedBytes, description), fixDecoder(codec, fixedBytes, description));\n}\n","import { Codec, Decoder, Encoder } from './codec';\n\n/**\n * Converts an encoder A to a encoder B by mapping their values.\n */\nexport function mapEncoder<T, U>(encoder: Encoder<T>, unmap: (value: U) => T): Encoder<U> {\n return {\n description: encoder.description,\n encode: (value: U) => encoder.encode(unmap(value)),\n fixedSize: encoder.fixedSize,\n maxSize: encoder.maxSize,\n };\n}\n\n/**\n * Converts an decoder A to a decoder B by mapping their values.\n */\nexport function mapDecoder<T, U>(\n decoder: Decoder<T>,\n map: (value: T, bytes: Uint8Array, offset: number) => U\n): Decoder<U> {\n return {\n decode: (bytes: Uint8Array, offset = 0) => {\n const [value, length] = decoder.decode(bytes, offset);\n return [map(value, bytes, offset), length];\n },\n description: decoder.description,\n fixedSize: decoder.fixedSize,\n maxSize: decoder.maxSize,\n };\n}\n\n/**\n * Converts a codec A to a codec B by mapping their values.\n */\nexport function mapCodec<NewFrom, OldFrom, To extends NewFrom & OldFrom>(\n codec: Codec<OldFrom, To>,\n unmap: (value: NewFrom) => OldFrom\n): Codec<NewFrom, To>;\nexport function mapCodec<NewFrom, OldFrom, NewTo extends NewFrom = NewFrom, OldTo extends OldFrom = OldFrom>(\n codec: Codec<OldFrom, OldTo>,\n unmap: (value: NewFrom) => OldFrom,\n map: (value: OldTo, bytes: Uint8Array, offset: number) => NewTo\n): Codec<NewFrom, NewTo>;\nexport function mapCodec<NewFrom, OldFrom, NewTo extends NewFrom = NewFrom, OldTo extends OldFrom = OldFrom>(\n codec: Codec<OldFrom, OldTo>,\n unmap: (value: NewFrom) => OldFrom,\n map?: (value: OldTo, bytes: Uint8Array, offset: number) => NewTo\n): Codec<NewFrom, NewTo> {\n return {\n decode: map ? mapDecoder(codec, map).decode : (codec.decode as unknown as Decoder<NewTo>['decode']),\n description: codec.description,\n encode: mapEncoder(codec, unmap).encode,\n fixedSize: codec.fixedSize,\n maxSize: codec.maxSize,\n };\n}\n","import { assertFixedSizeCodec } from './assertions';\nimport { mergeBytes } from './bytes';\nimport { Codec, Decoder, Encoder } from './codec';\nimport { combineCodec } from './combine-codec';\n\n/**\n * Reverses the bytes of a fixed-size encoder.\n */\nexport function reverseEncoder<T>(encoder: Encoder<T>): Encoder<T> {\n assertFixedSizeCodec(encoder, 'Cannot reverse a codec of variable size.');\n return {\n ...encoder,\n encode: (value: T) => encoder.encode(value).reverse(),\n };\n}\n\n/**\n * Reverses the bytes of a fixed-size decoder.\n */\nexport function reverseDecoder<T>(decoder: Decoder<T>): Decoder<T> {\n assertFixedSizeCodec(decoder, 'Cannot reverse a codec of variable size.');\n return {\n ...decoder,\n decode: (bytes: Uint8Array, offset = 0) => {\n const reverseEnd = offset + decoder.fixedSize;\n if (offset === 0 && bytes.length === reverseEnd) {\n return decoder.decode(bytes.reverse(), offset);\n }\n const newBytes = mergeBytes([\n ...(offset === 0 ? [] : [bytes.slice(0, offset)]),\n bytes.slice(offset, reverseEnd).reverse(),\n ...(bytes.length === reverseEnd ? [] : [bytes.slice(reverseEnd)]),\n ]);\n return decoder.decode(newBytes, offset);\n },\n };\n}\n\n/**\n * Reverses the bytes of a fixed-size codec.\n */\nexport function reverseCodec<T, U extends T = T>(codec: Codec<T, U>): Codec<T, U> {\n return combineCodec(reverseEncoder(codec), reverseDecoder(codec));\n}\n"]}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
this.globalThis = this.globalThis || {};
|
|
2
|
-
this.globalThis.solanaWeb3 = (function (exports) {
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
function E(e,r,o=0){if(r.length-o<=0)throw new Error(`Codec [${e}] cannot decode empty byte arrays.`)}function s(e,r,o,n=0){let t=o.length-n;if(t<r)throw new Error(`Codec [${e}] expected ${r} bytes, got ${t}.`)}function a(e,r){if(e.fixedSize===null)throw new Error(r??"Expected a fixed-size codec, got a variable-size one.")}var u=e=>{let r=e.filter(i=>i.length);if(r.length===0)return e.length?e[0]:new Uint8Array;if(r.length===1)return r[0];let o=r.reduce((i,p)=>i+p.length,0),n=new Uint8Array(o),t=0;return r.forEach(i=>{n.set(i,t),t+=i.length;}),n},f=(e,r)=>{if(e.length>=r)return e;let o=new Uint8Array(r).fill(0);return o.set(e),o},m=(e,r)=>f(e.length<=r?e:e.slice(0,r),r);function c(e,r,o){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(o===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:o??e.description,encode:e.encode,fixedSize:e.fixedSize,maxSize:e.maxSize}}function x(e,r,o){return {description:o??`fixed(${r}, ${e.description})`,fixedSize:r,maxSize:r}}function l(e,r,o){return {...x(e,r,o),encode:n=>m(e.encode(n),r)}}function T(e,r,o){return {...x(e,r,o),decode:(n,t=0)=>{s("fixCodec",r,n,t),(t>0||n.length>r)&&(n=n.slice(t,t+r)),e.fixedSize!==null&&(n=m(n,e.fixedSize));let[i]=e.decode(n,0);return [i,t+r]}}}function $(e,r,o){return c(l(e,r,o),T(e,r,o))}function z(e,r){return {description:e.description,encode:o=>e.encode(r(o)),fixedSize:e.fixedSize,maxSize:e.maxSize}}function w(e,r){return {decode:(o,n=0)=>{let[t,i]=e.decode(o,n);return [r(t,o,n),i]},description:e.description,fixedSize:e.fixedSize,maxSize:e.maxSize}}function _(e,r,o){return {decode:o?w(e,o).decode:e.decode,description:e.description,encode:z(e,r).encode,fixedSize:e.fixedSize,maxSize:e.maxSize}}function C(e){return a(e,"Cannot reverse a codec of variable size."),{...e,encode:r=>e.encode(r).reverse()}}function F(e){return a(e,"Cannot reverse a codec of variable size."),{...e,decode:(r,o=0)=>{let n=o+e.fixedSize;if(o===0&&r.length===n)return e.decode(r.reverse(),o);let t=u([...o===0?[]:[r.slice(0,o)],r.slice(o,n).reverse(),...r.length===n?[]:[r.slice(n)]]);return e.decode(t,o)}}}function I(e){return c(C(e),F(e))}
|
|
6
|
-
|
|
7
|
-
exports.assertByteArrayHasEnoughBytesForCodec = s;
|
|
8
|
-
exports.assertByteArrayIsNotEmptyForCodec = E;
|
|
9
|
-
exports.assertFixedSizeCodec = a;
|
|
10
|
-
exports.combineCodec = c;
|
|
11
|
-
exports.fixBytes = m;
|
|
12
|
-
exports.fixCodec = $;
|
|
13
|
-
exports.fixDecoder = T;
|
|
14
|
-
exports.fixEncoder = l;
|
|
15
|
-
exports.mapCodec = _;
|
|
16
|
-
exports.mapDecoder = w;
|
|
17
|
-
exports.mapEncoder = z;
|
|
18
|
-
exports.mergeBytes = u;
|
|
19
|
-
exports.padBytes = f;
|
|
20
|
-
exports.reverseCodec = I;
|
|
21
|
-
exports.reverseDecoder = F;
|
|
22
|
-
exports.reverseEncoder = C;
|
|
23
|
-
|
|
24
|
-
return exports;
|
|
25
|
-
|
|
26
|
-
})({});
|