1+ export function or < L extends string , R extends string > ( left : API . UnibaseDecoder < L > | API . CombobaseDecoder < L > , right : API . UnibaseDecoder < R > | API . CombobaseDecoder < R > ) : ComposedDecoder < L | R > ;
2+ /**
3+ * @class
4+ * @template {string} Base
5+ * @template {string} Prefix
6+ * @implements {API.MultibaseCodec<Prefix>}
7+ * @implements {API.MultibaseEncoder<Prefix>}
8+ * @implements {API.MultibaseDecoder<Prefix>}
9+ * @implements {API.BaseCodec}
10+ * @implements {API.BaseEncoder}
11+ * @implements {API.BaseDecoder}
12+ */
13+ export class Codec < Base extends string , Prefix extends string > implements API . MultibaseCodec < Prefix > , API . MultibaseEncoder < Prefix > , API . MultibaseDecoder < Prefix > , API . BaseCodec , API . BaseEncoder , API . BaseDecoder {
14+ /**
15+ * @param {Base } name
16+ * @param {Prefix } prefix
17+ * @param {(bytes:Uint8Array) => string } baseEncode
18+ * @param {(text:string) => Uint8Array } baseDecode
19+ */
20+ constructor ( name : Base , prefix : Prefix , baseEncode : ( bytes : Uint8Array ) => string , baseDecode : ( text : string ) => Uint8Array ) ;
21+ name : Base ;
22+ prefix : Prefix ;
23+ baseEncode : ( bytes : Uint8Array ) => string ;
24+ baseDecode : ( text : string ) => Uint8Array ;
25+ encoder : Encoder < Base , Prefix > ;
26+ decoder : Decoder < Base , Prefix > ;
27+ /**
28+ * @param {Uint8Array } input
29+ */
30+ encode ( input : Uint8Array ) : API . Multibase < Prefix > ;
31+ /**
32+ * @param {string } input
33+ */
34+ decode ( input : string ) : Uint8Array ;
35+ }
36+ export function from < Base extends string , Prefix extends string > ( { name, prefix, encode, decode } : {
37+ name : Base ;
38+ prefix : Prefix ;
39+ encode : ( bytes : Uint8Array ) => string ;
40+ decode : ( input : string ) => Uint8Array ;
41+ } ) : Codec < Base , Prefix > ;
42+ export function baseX < Base extends string , Prefix extends string > ( { prefix, name, alphabet } : {
43+ name : Base ;
44+ prefix : Prefix ;
45+ alphabet : string ;
46+ } ) : Codec < Base , Prefix > ;
47+ export function rfc4648 < Base extends string , Prefix extends string > ( { name, prefix, bitsPerChar, alphabet } : {
48+ name : Base ;
49+ prefix : Prefix ;
50+ alphabet : string ;
51+ bitsPerChar : number ;
52+ } ) : Codec < Base , Prefix > ;
53+ export type Decoders < Prefix extends string > = Record < Prefix , API . UnibaseDecoder < Prefix > > ;
54+ import * as API from "./interface.js" ;
55+ /**
56+ * @template {string} Prefix
57+ * @typedef {Record<Prefix, API.UnibaseDecoder<Prefix>> } Decoders
58+ */
59+ /**
60+ * @template {string} Prefix
61+ * @implements {API.MultibaseDecoder<Prefix>}
62+ * @implements {API.CombobaseDecoder<Prefix>}
63+ */
64+ declare class ComposedDecoder < Prefix extends string > implements API . MultibaseDecoder < Prefix > , API . CombobaseDecoder < Prefix > {
65+ /**
66+ * @param {Decoders<Prefix> } decoders
67+ */
68+ constructor ( decoders : Decoders < Prefix > ) ;
69+ decoders : Decoders < Prefix > ;
70+ /**
71+ * @template {string} OtherPrefix
72+ * @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix> } decoder
73+ * @returns {ComposedDecoder<Prefix|OtherPrefix> }
74+ */
75+ or < OtherPrefix extends string > ( decoder : API . UnibaseDecoder < OtherPrefix > | ComposedDecoder < OtherPrefix > ) : ComposedDecoder < Prefix | OtherPrefix > ;
76+ /**
77+ * @param {string } input
78+ * @returns {Uint8Array }
79+ */
80+ decode ( input : string ) : Uint8Array ;
81+ }
82+ /**
83+ * Class represents both BaseEncoder and MultibaseEncoder meaning it
84+ * can be used to encode to multibase or base encode without multibase
85+ * prefix.
86+ *
87+ * @class
88+ * @template {string} Base
89+ * @template {string} Prefix
90+ * @implements {API.MultibaseEncoder<Prefix>}
91+ * @implements {API.BaseEncoder}
92+ */
93+ declare class Encoder < Base extends string , Prefix extends string > implements API . MultibaseEncoder < Prefix > , API . BaseEncoder {
94+ /**
95+ * @param {Base } name
96+ * @param {Prefix } prefix
97+ * @param {(bytes:Uint8Array) => string } baseEncode
98+ */
99+ constructor ( name : Base , prefix : Prefix , baseEncode : ( bytes : Uint8Array ) => string ) ;
100+ name : Base ;
101+ prefix : Prefix ;
102+ baseEncode : ( bytes : Uint8Array ) => string ;
103+ /**
104+ * @param {Uint8Array } bytes
105+ * @returns {API.Multibase<Prefix> }
106+ */
107+ encode ( bytes : Uint8Array ) : API . Multibase < Prefix > ;
108+ }
109+ /**
110+ * @template {string} Prefix
111+ */
112+ /**
113+ * Class represents both BaseDecoder and MultibaseDecoder so it could be used
114+ * to decode multibases (with matching prefix) or just base decode strings
115+ * with corresponding base encoding.
116+ *
117+ * @class
118+ * @template {string} Base
119+ * @template {string} Prefix
120+ * @implements {API.MultibaseDecoder<Prefix>}
121+ * @implements {API.UnibaseDecoder<Prefix>}
122+ * @implements {API.BaseDecoder}
123+ */
124+ declare class Decoder < Base extends string , Prefix extends string > implements API . MultibaseDecoder < Prefix > , API . UnibaseDecoder < Prefix > , API . BaseDecoder {
125+ /**
126+ * @param {Base } name
127+ * @param {Prefix } prefix
128+ * @param {(text:string) => Uint8Array } baseDecode
129+ */
130+ constructor ( name : Base , prefix : Prefix , baseDecode : ( text : string ) => Uint8Array ) ;
131+ name : Base ;
132+ prefix : Prefix ;
133+ /** @private */
134+ private prefixCodePoint ;
135+ baseDecode : ( text : string ) => Uint8Array ;
136+ /**
137+ * @param {string } text
138+ */
139+ decode ( text : string ) : Uint8Array ;
140+ /**
141+ * @template {string} OtherPrefix
142+ * @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix> } decoder
143+ * @returns {ComposedDecoder<Prefix|OtherPrefix> }
144+ */
145+ or < OtherPrefix extends string > ( decoder : API . UnibaseDecoder < OtherPrefix > | ComposedDecoder < OtherPrefix > ) : ComposedDecoder < Prefix | OtherPrefix > ;
146+ }
147+ export { } ;
148+ //# sourceMappingURL=base.d.ts.map
0 commit comments