{"version":3,"file":"descriptor.mjs","names":[],"sources":["../src/descriptor.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nexport type DescriptorInput = {\n\tdata: Buffer;\n\tsignature: Buffer;\n};\n\nfunction buildTLV(tag: Buffer, value: Buffer): Buffer {\n\tconst length = value.length;\n\n\tif (length > 0xff) {\n\t\tthrow new Error('Value length exceeds 255 bytes');\n\t}\n\n\treturn Buffer.concat([tag, new Uint8Array([length]), value]);\n}\n\nexport function buildDescriptor({ data, signature }: DescriptorInput): Buffer {\n\tconst SIGNATURE_TAG = Buffer.from(new Uint8Array([0x08]));\n\tconst descriptor = Buffer.concat([data, buildTLV(SIGNATURE_TAG, signature)]);\n\tconst descriptorLength = Buffer.from(new Uint16Array([descriptor.length]).buffer);\n\treturn Buffer.concat([descriptorLength, descriptor]);\n}\n"],"mappings":";AAOA,SAAS,SAAS,KAAa,OAAuB;CACrD,MAAM,SAAS,MAAM;AAErB,KAAI,SAAS,IACZ,OAAM,IAAI,MAAM,iCAAiC;AAGlD,QAAO,OAAO,OAAO;EAAC;EAAK,IAAI,WAAW,CAAC,OAAO,CAAC;EAAE;EAAM,CAAC;;AAG7D,SAAgB,gBAAgB,EAAE,MAAM,aAAsC;CAC7E,MAAM,gBAAgB,OAAO,KAAK,IAAI,WAAW,CAAC,EAAK,CAAC,CAAC;CACzD,MAAM,aAAa,OAAO,OAAO,CAAC,MAAM,SAAS,eAAe,UAAU,CAAC,CAAC;CAC5E,MAAM,mBAAmB,OAAO,KAAK,IAAI,YAAY,CAAC,WAAW,OAAO,CAAC,CAAC,OAAO;AACjF,QAAO,OAAO,OAAO,CAAC,kBAAkB,WAAW,CAAC"}