upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfiatjaf <fiatjaf@gmail.com>2023-08-15 11:50:39 -0300
committerfiatjaf <fiatjaf@gmail.com>2023-08-15 11:50:39 -0300
commit2239f9654110ead3d896d768549412f0b3b12369 (patch)
treee615a950bbd580b49862b4f3d4762ef2f42b1cda
parentc78bd4cef11d76fd5aa1add31e42cbdc5da1c6ea (diff)
remove these TLV functions.
-rw-r--r--44.md34
1 files changed, 0 insertions, 34 deletions
diff --git a/44.md b/44.md
index da84059..8f840aa 100644
--- a/44.md
+++ b/44.md
@@ -54,40 +54,6 @@ export const utf8Decoder = new TextDecoder()
54 54
55export const utf8Encoder = new TextEncoder() 55export const utf8Encoder = new TextEncoder()
56 56
57export type TLV = {[t: number]: Uint8Array[]}
58
59export 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
75export 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
91export const getSharedSecret = (privkey: string, pubkey: string): Uint8Array => 57export 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