diff --git a/44.md b/44.md index da840593..8f840aab 100644 --- a/44.md +++ b/44.md @@ -54,40 +54,6 @@ export const utf8Decoder = new TextDecoder() export const utf8Encoder = new TextEncoder() -export type TLV = {[t: number]: Uint8Array[]} - -export function parseTLV(data: Uint8Array): TLV { - let result: TLV = {} - let rest = data - while (rest.length > 0) { - let t = rest[0] - let l = rest[1] - if (!l) throw new Error(`malformed TLV ${t}`) - let v = rest.slice(2, 2 + l) - rest = rest.slice(2 + l) - if (v.length < l) throw new Error(`not enough data to read on TLV ${t}`) - result[t] = result[t] || [] - result[t].push(v) - } - return result -} - -export function encodeTLV(tlv: TLV): Uint8Array { - let entries: Uint8Array[] = [] - - Object.entries(tlv).forEach(([t, vs]) => { - vs.forEach(v => { - let entry = new Uint8Array(v.length + 2) - entry.set([parseInt(t)], 0) - entry.set([v.length], 1) - entry.set(v, 2) - entries.push(entry) - }) - }) - - return concatBytes(...entries) -} - export const getSharedSecret = (privkey: string, pubkey: string): Uint8Array => sha256(secp256k1.getSharedSecret(privkey, "02" + pubkey).subarray(1, 33))