MCPcopy Create free account
hub / github.com/cameri/nostream / getMessageKeys

Function getMessageKeys

src/utils/nip44.ts:44–61  ·  view source on GitHub ↗
(
  conversationKey: Buffer,
  nonce: Buffer,
)

Source from the content-addressed store, hash-verified

42}
43
44function getMessageKeys(
45 conversationKey: Buffer,
46 nonce: Buffer,
47): { chachaKey: Buffer; chachaNonce: Buffer; hmacKey: Buffer } {
48 if (conversationKey.length !== 32) {
49 throw new Error('invalid conversation_key length')
50 }
51 if (nonce.length !== 32) {
52 throw new Error('invalid nonce length')
53 }
54
55 const keys = hkdfExpand(conversationKey, nonce, 76)
56 return {
57 chachaKey: keys.subarray(0, 32),
58 chachaNonce: keys.subarray(32, 44),
59 hmacKey: keys.subarray(44, 76),
60 }
61}
62
63function calcPaddedLen(unpaddedLen: number): number {
64 if (unpaddedLen <= 32) {

Callers 2

nip44EncryptFunction · 0.85
nip44DecryptFunction · 0.85

Calls 1

hkdfExpandFunction · 0.85

Tested by

no test coverage detected