remove these TLV functions.

This commit is contained in:
fiatjaf 2023-08-15 11:50:39 -03:00
parent c78bd4cef1
commit 2239f96541
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1

34
44.md
View File

@ -54,40 +54,6 @@ export const utf8Decoder = new TextDecoder()
export const utf8Encoder = new TextEncoder() 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 => export const getSharedSecret = (privkey: string, pubkey: string): Uint8Array =>
sha256(secp256k1.getSharedSecret(privkey, "02" + pubkey).subarray(1, 33)) sha256(secp256k1.getSharedSecret(privkey, "02" + pubkey).subarray(1, 33))