MCPcopy Create free account
hub / github.com/Treeki/BirdBridge / unpackObject

Function unpackObject

apis/authflow.ts:33–49  ·  view source on GitHub ↗
(str: string)

Source from the content-addressed store, hash-verified

31}
32
33async function unpackObject<T>(str: string): Promise<T | null> {
34 try {
35 const bits = str.split('|');
36 if (bits.length == 2) {
37 const json = atob(bits[0]);
38 const bytes = new TextEncoder().encode(json).buffer;
39 const signature = base64.decode(bits[1]);
40 if (await crypto.subtle.verify('HMAC', bridgeKey, signature, bytes)) {
41 return JSON.parse(json);
42 }
43 }
44 } catch (ex) {
45 console.error('Failed to unpack signed object', ex);
46 }
47
48 return null;
49}
50
51/// Data passed in a hidden, signed field when submitting the authorisation form
52interface SignInFormData {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected