File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -136,3 +136,25 @@ export function toProto(tokenId: Type): Proto.TokenId {
136136 symbol : tokenId . symbol ,
137137 } ;
138138}
139+
140+ /**
141+ * Encode a TokenId to UTF-8 bytes. This is the serialization format used for token IDs in transactions.
142+ *
143+ * @param {TokenId } tokenId - The TokenId to encode.
144+ * @returns {Uint8Array } The UTF-8 byte representation of the TokenId.
145+ */
146+ export function toBytes ( tokenId : TokenId ) : Uint8Array {
147+ return new TextEncoder ( ) . encode ( tokenId . symbol ) ;
148+ }
149+
150+ /**
151+ * Decode UTF-8 bytes to a TokenId. This can be used to deserialize token IDs in transactions.
152+ *
153+ * @param {Uint8Array } bytes - The UTF-8 byte array to decode.
154+ * @returns {TokenId } The decoded TokenId.
155+ * @throws {Err } If the decoded string is longer than 256 utf-8 encoded bytes.
156+ */
157+ export function fromBytes ( bytes : ArrayBuffer ) : TokenId {
158+ const symbol = new TextDecoder ( ) . decode ( bytes ) ;
159+ return fromString ( symbol ) ;
160+ }
You can’t perform that action at this time.
0 commit comments