import { RadixSerializer , RadixPrimitive } from '..' ; @ RadixSerializer . registerPrimitive ( ':byt:' ) export class RadixBytes implements RadixPrimitive { public readonly bytes : Buffer ; constructor ( bytes ) { this . bytes = Buffer . from ( bytes ) ; } public static fromEncoded ( encoded ) { return new this ( Buffer . from ( encoded , 'base64' ) ) ; } public static fromJSON ( bytes ) { return this . fromEncoded ( bytes ) ; } public toJSON ( ) { return `:byt:${ this . bytes . toString ( 'base64' ) }` ; } public toDSON ( ) { return RadixSerializer . toDSON ( this ) ; } public encodeCBOR ( encoder ) { const output = Buffer . alloc ( this . bytes . length + 1 ) ; output . writeInt8 ( 0x01 , 0 ) ; this . bytes . copy ( output , 1 ) ; return encoder . pushAny ( output ) ; } public toString ( ) { return this . bytes . toString ( ) ; } public asJSON ( ) { return JSON . parse ( this . bytes . toString ( 'utf8' ) ) ; } }