diff options
| author | fiatjaf <fiatjaf@gmail.com> | 2023-08-15 11:50:39 -0300 |
|---|---|---|
| committer | fiatjaf <fiatjaf@gmail.com> | 2023-08-15 11:50:39 -0300 |
| commit | 2239f9654110ead3d896d768549412f0b3b12369 (patch) | |
| tree | e615a950bbd580b49862b4f3d4762ef2f42b1cda | |
| parent | c78bd4cef11d76fd5aa1add31e42cbdc5da1c6ea (diff) | |
remove these TLV functions.
| -rw-r--r-- | 44.md | 34 |
1 files changed, 0 insertions, 34 deletions
| @@ -54,40 +54,6 @@ export const utf8Decoder = new TextDecoder() | |||
| 54 | 54 | ||
| 55 | export const utf8Encoder = new TextEncoder() | 55 | export const utf8Encoder = new TextEncoder() |
| 56 | 56 | ||
| 57 | export type TLV = {[t: number]: Uint8Array[]} | ||
| 58 | |||
| 59 | export function parseTLV(data: Uint8Array): TLV { | ||
| 60 | let result: TLV = {} | ||
| 61 | let rest = data | ||
| 62 | while (rest.length > 0) { | ||
| 63 | let t = rest[0] | ||
| 64 | let l = rest[1] | ||
| 65 | if (!l) throw new Error(`malformed TLV ${t}`) | ||
| 66 | let v = rest.slice(2, 2 + l) | ||
| 67 | rest = rest.slice(2 + l) | ||
| 68 | if (v.length < l) throw new Error(`not enough data to read on TLV ${t}`) | ||
| 69 | result[t] = result[t] || [] | ||
| 70 | result[t].push(v) | ||
| 71 | } | ||
| 72 | return result | ||
| 73 | } | ||
| 74 | |||
| 75 | export function encodeTLV(tlv: TLV): Uint8Array { | ||
| 76 | let entries: Uint8Array[] = [] | ||
| 77 | |||
| 78 | Object.entries(tlv).forEach(([t, vs]) => { | ||
| 79 | vs.forEach(v => { | ||
| 80 | let entry = new Uint8Array(v.length + 2) | ||
| 81 | entry.set([parseInt(t)], 0) | ||
| 82 | entry.set([v.length], 1) | ||
| 83 | entry.set(v, 2) | ||
| 84 | entries.push(entry) | ||
| 85 | }) | ||
| 86 | }) | ||
| 87 | |||
| 88 | return concatBytes(...entries) | ||
| 89 | } | ||
| 90 | |||
| 91 | export const getSharedSecret = (privkey: string, pubkey: string): Uint8Array => | 57 | export const getSharedSecret = (privkey: string, pubkey: string): Uint8Array => |
| 92 | sha256(secp256k1.getSharedSecret(privkey, "02" + pubkey).subarray(1, 33)) | 58 | sha256(secp256k1.getSharedSecret(privkey, "02" + pubkey).subarray(1, 33)) |
| 93 | 59 | ||