github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/enterprise/platformkeysinternal/bindings/ffi_bindings.ts (about) 1 import { importModule, Application, heap, Pointer } from "@ffi"; 2 3 importModule("plat/js/webext/enterprise/platformkeysinternal", (A: Application) => { 4 const WEBEXT = typeof globalThis.browser === "undefined" ? globalThis.chrome : globalThis.browser; 5 6 return { 7 "store_Hash": (ptr: Pointer, ref: heap.Ref<any>) => { 8 const x = A.H.get<any>(ref); 9 10 if (typeof x === "undefined") { 11 A.store.Bool(ptr + 4, false); 12 A.store.Ref(ptr + 0, undefined); 13 } else { 14 A.store.Bool(ptr + 4, true); 15 A.store.Ref(ptr + 0, x["name"]); 16 } 17 }, 18 "load_Hash": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => { 19 const x = create === A.H.TRUE ? {} : A.H.get<any>(ref); 20 21 x["name"] = A.load.Ref(ptr + 0, undefined); 22 return create === A.H.TRUE ? A.H.push(x) : ref; 23 }, 24 25 "store_Algorithm": (ptr: Pointer, ref: heap.Ref<any>) => { 26 const x = A.H.get<any>(ref); 27 28 if (typeof x === "undefined") { 29 A.store.Bool(ptr + 25, false); 30 A.store.Ref(ptr + 0, undefined); 31 A.store.Bool(ptr + 24, false); 32 A.store.Int32(ptr + 4, 0); 33 A.store.Ref(ptr + 8, undefined); 34 35 A.store.Bool(ptr + 12 + 4, false); 36 A.store.Ref(ptr + 12 + 0, undefined); 37 A.store.Ref(ptr + 20, undefined); 38 } else { 39 A.store.Bool(ptr + 25, true); 40 A.store.Ref(ptr + 0, x["name"]); 41 A.store.Bool(ptr + 24, "modulusLength" in x ? true : false); 42 A.store.Int32(ptr + 4, x["modulusLength"] === undefined ? 0 : (x["modulusLength"] as number)); 43 A.store.Ref(ptr + 8, x["publicExponent"]); 44 45 if (typeof x["hash"] === "undefined") { 46 A.store.Bool(ptr + 12 + 4, false); 47 A.store.Ref(ptr + 12 + 0, undefined); 48 } else { 49 A.store.Bool(ptr + 12 + 4, true); 50 A.store.Ref(ptr + 12 + 0, x["hash"]["name"]); 51 } 52 A.store.Ref(ptr + 20, x["namedCurve"]); 53 } 54 }, 55 "load_Algorithm": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => { 56 const x = create === A.H.TRUE ? {} : A.H.get<any>(ref); 57 58 x["name"] = A.load.Ref(ptr + 0, undefined); 59 if (A.load.Bool(ptr + 24)) { 60 x["modulusLength"] = A.load.Int32(ptr + 4); 61 } else { 62 delete x["modulusLength"]; 63 } 64 x["publicExponent"] = A.load.Ref(ptr + 8, undefined); 65 if (A.load.Bool(ptr + 12 + 4)) { 66 x["hash"] = {}; 67 x["hash"]["name"] = A.load.Ref(ptr + 12 + 0, undefined); 68 } else { 69 delete x["hash"]; 70 } 71 x["namedCurve"] = A.load.Ref(ptr + 20, undefined); 72 return create === A.H.TRUE ? A.H.push(x) : ref; 73 }, 74 "has_GenerateKey": (): heap.Ref<boolean> => { 75 if (WEBEXT?.enterprise?.platformKeysInternal && "generateKey" in WEBEXT?.enterprise?.platformKeysInternal) { 76 return A.H.TRUE; 77 } 78 return A.H.FALSE; 79 }, 80 "func_GenerateKey": (fn: Pointer): void => { 81 A.store.Ref(fn, WEBEXT.enterprise.platformKeysInternal.generateKey); 82 }, 83 "call_GenerateKey": ( 84 retPtr: Pointer, 85 tokenId: heap.Ref<object>, 86 algorithm: Pointer, 87 softwareBacked: heap.Ref<boolean>, 88 callback: heap.Ref<object> 89 ): void => { 90 const algorithm_ffi = {}; 91 92 algorithm_ffi["name"] = A.load.Ref(algorithm + 0, undefined); 93 if (A.load.Bool(algorithm + 24)) { 94 algorithm_ffi["modulusLength"] = A.load.Int32(algorithm + 4); 95 } 96 algorithm_ffi["publicExponent"] = A.load.Ref(algorithm + 8, undefined); 97 if (A.load.Bool(algorithm + 12 + 4)) { 98 algorithm_ffi["hash"] = {}; 99 algorithm_ffi["hash"]["name"] = A.load.Ref(algorithm + 12 + 0, undefined); 100 } 101 algorithm_ffi["namedCurve"] = A.load.Ref(algorithm + 20, undefined); 102 103 const _ret = WEBEXT.enterprise.platformKeysInternal.generateKey( 104 A.H.get<object>(tokenId), 105 algorithm_ffi, 106 softwareBacked === A.H.TRUE, 107 A.H.get<object>(callback) 108 ); 109 }, 110 "try_GenerateKey": ( 111 retPtr: Pointer, 112 errPtr: Pointer, 113 tokenId: heap.Ref<object>, 114 algorithm: Pointer, 115 softwareBacked: heap.Ref<boolean>, 116 callback: heap.Ref<object> 117 ): heap.Ref<boolean> => { 118 try { 119 const algorithm_ffi = {}; 120 121 algorithm_ffi["name"] = A.load.Ref(algorithm + 0, undefined); 122 if (A.load.Bool(algorithm + 24)) { 123 algorithm_ffi["modulusLength"] = A.load.Int32(algorithm + 4); 124 } 125 algorithm_ffi["publicExponent"] = A.load.Ref(algorithm + 8, undefined); 126 if (A.load.Bool(algorithm + 12 + 4)) { 127 algorithm_ffi["hash"] = {}; 128 algorithm_ffi["hash"]["name"] = A.load.Ref(algorithm + 12 + 0, undefined); 129 } 130 algorithm_ffi["namedCurve"] = A.load.Ref(algorithm + 20, undefined); 131 132 const _ret = WEBEXT.enterprise.platformKeysInternal.generateKey( 133 A.H.get<object>(tokenId), 134 algorithm_ffi, 135 softwareBacked === A.H.TRUE, 136 A.H.get<object>(callback) 137 ); 138 return A.H.TRUE; 139 } catch (err: any) { 140 A.store.Ref(errPtr, err); 141 return A.H.FALSE; 142 } 143 }, 144 "has_GetTokens": (): heap.Ref<boolean> => { 145 if (WEBEXT?.enterprise?.platformKeysInternal && "getTokens" in WEBEXT?.enterprise?.platformKeysInternal) { 146 return A.H.TRUE; 147 } 148 return A.H.FALSE; 149 }, 150 "func_GetTokens": (fn: Pointer): void => { 151 A.store.Ref(fn, WEBEXT.enterprise.platformKeysInternal.getTokens); 152 }, 153 "call_GetTokens": (retPtr: Pointer, callback: heap.Ref<object>): void => { 154 const _ret = WEBEXT.enterprise.platformKeysInternal.getTokens(A.H.get<object>(callback)); 155 }, 156 "try_GetTokens": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => { 157 try { 158 const _ret = WEBEXT.enterprise.platformKeysInternal.getTokens(A.H.get<object>(callback)); 159 return A.H.TRUE; 160 } catch (err: any) { 161 A.store.Ref(errPtr, err); 162 return A.H.FALSE; 163 } 164 }, 165 }; 166 });