github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/quickunlockprivate/bindings/ffi_bindings.ts (about) 1 import { importModule, Application, heap, Pointer } from "@ffi"; 2 3 importModule("plat/js/webext/quickunlockprivate", (A: Application) => { 4 const WEBEXT = typeof globalThis.browser === "undefined" ? globalThis.chrome : globalThis.browser; 5 6 return { 7 "constof_CredentialProblem": (ref: heap.Ref<string>): number => { 8 const idx = ["TOO_SHORT", "TOO_LONG", "TOO_WEAK", "CONTAINS_NONDIGIT"].indexOf(A.H.get(ref)); 9 return idx < 0 ? 0 : idx + 1; 10 }, 11 12 "store_CredentialCheck": (ptr: Pointer, ref: heap.Ref<any>) => { 13 const x = A.H.get<any>(ref); 14 15 if (typeof x === "undefined") { 16 A.store.Bool(ptr + 8, false); 17 A.store.Ref(ptr + 0, undefined); 18 A.store.Ref(ptr + 4, undefined); 19 } else { 20 A.store.Bool(ptr + 8, true); 21 A.store.Ref(ptr + 0, x["errors"]); 22 A.store.Ref(ptr + 4, x["warnings"]); 23 } 24 }, 25 "load_CredentialCheck": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => { 26 const x = create === A.H.TRUE ? {} : A.H.get<any>(ref); 27 28 x["errors"] = A.load.Ref(ptr + 0, undefined); 29 x["warnings"] = A.load.Ref(ptr + 4, undefined); 30 return create === A.H.TRUE ? A.H.push(x) : ref; 31 }, 32 33 "store_CredentialRequirements": (ptr: Pointer, ref: heap.Ref<any>) => { 34 const x = A.H.get<any>(ref); 35 36 if (typeof x === "undefined") { 37 A.store.Bool(ptr + 10, false); 38 A.store.Bool(ptr + 8, false); 39 A.store.Int32(ptr + 0, 0); 40 A.store.Bool(ptr + 9, false); 41 A.store.Int32(ptr + 4, 0); 42 } else { 43 A.store.Bool(ptr + 10, true); 44 A.store.Bool(ptr + 8, "minLength" in x ? true : false); 45 A.store.Int32(ptr + 0, x["minLength"] === undefined ? 0 : (x["minLength"] as number)); 46 A.store.Bool(ptr + 9, "maxLength" in x ? true : false); 47 A.store.Int32(ptr + 4, x["maxLength"] === undefined ? 0 : (x["maxLength"] as number)); 48 } 49 }, 50 "load_CredentialRequirements": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => { 51 const x = create === A.H.TRUE ? {} : A.H.get<any>(ref); 52 53 if (A.load.Bool(ptr + 8)) { 54 x["minLength"] = A.load.Int32(ptr + 0); 55 } else { 56 delete x["minLength"]; 57 } 58 if (A.load.Bool(ptr + 9)) { 59 x["maxLength"] = A.load.Int32(ptr + 4); 60 } else { 61 delete x["maxLength"]; 62 } 63 return create === A.H.TRUE ? A.H.push(x) : ref; 64 }, 65 "constof_QuickUnlockMode": (ref: heap.Ref<string>): number => { 66 const idx = ["PIN"].indexOf(A.H.get(ref)); 67 return idx < 0 ? 0 : idx + 1; 68 }, 69 70 "store_TokenInfo": (ptr: Pointer, ref: heap.Ref<any>) => { 71 const x = A.H.get<any>(ref); 72 73 if (typeof x === "undefined") { 74 A.store.Bool(ptr + 9, false); 75 A.store.Ref(ptr + 0, undefined); 76 A.store.Bool(ptr + 8, false); 77 A.store.Int32(ptr + 4, 0); 78 } else { 79 A.store.Bool(ptr + 9, true); 80 A.store.Ref(ptr + 0, x["token"]); 81 A.store.Bool(ptr + 8, "lifetimeSeconds" in x ? true : false); 82 A.store.Int32(ptr + 4, x["lifetimeSeconds"] === undefined ? 0 : (x["lifetimeSeconds"] as number)); 83 } 84 }, 85 "load_TokenInfo": (ptr: Pointer, create: heap.Ref<boolean>, ref: heap.Ref<any>): heap.Ref<any> => { 86 const x = create === A.H.TRUE ? {} : A.H.get<any>(ref); 87 88 x["token"] = A.load.Ref(ptr + 0, undefined); 89 if (A.load.Bool(ptr + 8)) { 90 x["lifetimeSeconds"] = A.load.Int32(ptr + 4); 91 } else { 92 delete x["lifetimeSeconds"]; 93 } 94 return create === A.H.TRUE ? A.H.push(x) : ref; 95 }, 96 "has_CanAuthenticatePin": (): heap.Ref<boolean> => { 97 if (WEBEXT?.quickUnlockPrivate && "canAuthenticatePin" in WEBEXT?.quickUnlockPrivate) { 98 return A.H.TRUE; 99 } 100 return A.H.FALSE; 101 }, 102 "func_CanAuthenticatePin": (fn: Pointer): void => { 103 A.store.Ref(fn, WEBEXT.quickUnlockPrivate.canAuthenticatePin); 104 }, 105 "call_CanAuthenticatePin": (retPtr: Pointer): void => { 106 const _ret = WEBEXT.quickUnlockPrivate.canAuthenticatePin(); 107 A.store.Ref(retPtr, _ret); 108 }, 109 "try_CanAuthenticatePin": (retPtr: Pointer, errPtr: Pointer): heap.Ref<boolean> => { 110 try { 111 const _ret = WEBEXT.quickUnlockPrivate.canAuthenticatePin(); 112 A.store.Ref(retPtr, _ret); 113 return A.H.TRUE; 114 } catch (err: any) { 115 A.store.Ref(errPtr, err); 116 return A.H.FALSE; 117 } 118 }, 119 "has_CheckCredential": (): heap.Ref<boolean> => { 120 if (WEBEXT?.quickUnlockPrivate && "checkCredential" in WEBEXT?.quickUnlockPrivate) { 121 return A.H.TRUE; 122 } 123 return A.H.FALSE; 124 }, 125 "func_CheckCredential": (fn: Pointer): void => { 126 A.store.Ref(fn, WEBEXT.quickUnlockPrivate.checkCredential); 127 }, 128 "call_CheckCredential": (retPtr: Pointer, mode: number, credential: heap.Ref<object>): void => { 129 const _ret = WEBEXT.quickUnlockPrivate.checkCredential( 130 mode > 0 && mode <= 1 ? ["PIN"][mode - 1] : undefined, 131 A.H.get<object>(credential) 132 ); 133 A.store.Ref(retPtr, _ret); 134 }, 135 "try_CheckCredential": ( 136 retPtr: Pointer, 137 errPtr: Pointer, 138 mode: number, 139 credential: heap.Ref<object> 140 ): heap.Ref<boolean> => { 141 try { 142 const _ret = WEBEXT.quickUnlockPrivate.checkCredential( 143 mode > 0 && mode <= 1 ? ["PIN"][mode - 1] : undefined, 144 A.H.get<object>(credential) 145 ); 146 A.store.Ref(retPtr, _ret); 147 return A.H.TRUE; 148 } catch (err: any) { 149 A.store.Ref(errPtr, err); 150 return A.H.FALSE; 151 } 152 }, 153 "has_GetActiveModes": (): heap.Ref<boolean> => { 154 if (WEBEXT?.quickUnlockPrivate && "getActiveModes" in WEBEXT?.quickUnlockPrivate) { 155 return A.H.TRUE; 156 } 157 return A.H.FALSE; 158 }, 159 "func_GetActiveModes": (fn: Pointer): void => { 160 A.store.Ref(fn, WEBEXT.quickUnlockPrivate.getActiveModes); 161 }, 162 "call_GetActiveModes": (retPtr: Pointer): void => { 163 const _ret = WEBEXT.quickUnlockPrivate.getActiveModes(); 164 A.store.Ref(retPtr, _ret); 165 }, 166 "try_GetActiveModes": (retPtr: Pointer, errPtr: Pointer): heap.Ref<boolean> => { 167 try { 168 const _ret = WEBEXT.quickUnlockPrivate.getActiveModes(); 169 A.store.Ref(retPtr, _ret); 170 return A.H.TRUE; 171 } catch (err: any) { 172 A.store.Ref(errPtr, err); 173 return A.H.FALSE; 174 } 175 }, 176 "has_GetAuthToken": (): heap.Ref<boolean> => { 177 if (WEBEXT?.quickUnlockPrivate && "getAuthToken" in WEBEXT?.quickUnlockPrivate) { 178 return A.H.TRUE; 179 } 180 return A.H.FALSE; 181 }, 182 "func_GetAuthToken": (fn: Pointer): void => { 183 A.store.Ref(fn, WEBEXT.quickUnlockPrivate.getAuthToken); 184 }, 185 "call_GetAuthToken": (retPtr: Pointer, accountPassword: heap.Ref<object>): void => { 186 const _ret = WEBEXT.quickUnlockPrivate.getAuthToken(A.H.get<object>(accountPassword)); 187 A.store.Ref(retPtr, _ret); 188 }, 189 "try_GetAuthToken": (retPtr: Pointer, errPtr: Pointer, accountPassword: heap.Ref<object>): heap.Ref<boolean> => { 190 try { 191 const _ret = WEBEXT.quickUnlockPrivate.getAuthToken(A.H.get<object>(accountPassword)); 192 A.store.Ref(retPtr, _ret); 193 return A.H.TRUE; 194 } catch (err: any) { 195 A.store.Ref(errPtr, err); 196 return A.H.FALSE; 197 } 198 }, 199 "has_GetAvailableModes": (): heap.Ref<boolean> => { 200 if (WEBEXT?.quickUnlockPrivate && "getAvailableModes" in WEBEXT?.quickUnlockPrivate) { 201 return A.H.TRUE; 202 } 203 return A.H.FALSE; 204 }, 205 "func_GetAvailableModes": (fn: Pointer): void => { 206 A.store.Ref(fn, WEBEXT.quickUnlockPrivate.getAvailableModes); 207 }, 208 "call_GetAvailableModes": (retPtr: Pointer): void => { 209 const _ret = WEBEXT.quickUnlockPrivate.getAvailableModes(); 210 A.store.Ref(retPtr, _ret); 211 }, 212 "try_GetAvailableModes": (retPtr: Pointer, errPtr: Pointer): heap.Ref<boolean> => { 213 try { 214 const _ret = WEBEXT.quickUnlockPrivate.getAvailableModes(); 215 A.store.Ref(retPtr, _ret); 216 return A.H.TRUE; 217 } catch (err: any) { 218 A.store.Ref(errPtr, err); 219 return A.H.FALSE; 220 } 221 }, 222 "has_GetCredentialRequirements": (): heap.Ref<boolean> => { 223 if (WEBEXT?.quickUnlockPrivate && "getCredentialRequirements" in WEBEXT?.quickUnlockPrivate) { 224 return A.H.TRUE; 225 } 226 return A.H.FALSE; 227 }, 228 "func_GetCredentialRequirements": (fn: Pointer): void => { 229 A.store.Ref(fn, WEBEXT.quickUnlockPrivate.getCredentialRequirements); 230 }, 231 "call_GetCredentialRequirements": (retPtr: Pointer, mode: number): void => { 232 const _ret = WEBEXT.quickUnlockPrivate.getCredentialRequirements( 233 mode > 0 && mode <= 1 ? ["PIN"][mode - 1] : undefined 234 ); 235 A.store.Ref(retPtr, _ret); 236 }, 237 "try_GetCredentialRequirements": (retPtr: Pointer, errPtr: Pointer, mode: number): heap.Ref<boolean> => { 238 try { 239 const _ret = WEBEXT.quickUnlockPrivate.getCredentialRequirements( 240 mode > 0 && mode <= 1 ? ["PIN"][mode - 1] : undefined 241 ); 242 A.store.Ref(retPtr, _ret); 243 return A.H.TRUE; 244 } catch (err: any) { 245 A.store.Ref(errPtr, err); 246 return A.H.FALSE; 247 } 248 }, 249 "has_OnActiveModesChanged": (): heap.Ref<boolean> => { 250 if ( 251 WEBEXT?.quickUnlockPrivate?.onActiveModesChanged && 252 "addListener" in WEBEXT?.quickUnlockPrivate?.onActiveModesChanged 253 ) { 254 return A.H.TRUE; 255 } 256 return A.H.FALSE; 257 }, 258 "func_OnActiveModesChanged": (fn: Pointer): void => { 259 A.store.Ref(fn, WEBEXT.quickUnlockPrivate.onActiveModesChanged.addListener); 260 }, 261 "call_OnActiveModesChanged": (retPtr: Pointer, callback: heap.Ref<object>): void => { 262 const _ret = WEBEXT.quickUnlockPrivate.onActiveModesChanged.addListener(A.H.get<object>(callback)); 263 }, 264 "try_OnActiveModesChanged": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => { 265 try { 266 const _ret = WEBEXT.quickUnlockPrivate.onActiveModesChanged.addListener(A.H.get<object>(callback)); 267 return A.H.TRUE; 268 } catch (err: any) { 269 A.store.Ref(errPtr, err); 270 return A.H.FALSE; 271 } 272 }, 273 "has_OffActiveModesChanged": (): heap.Ref<boolean> => { 274 if ( 275 WEBEXT?.quickUnlockPrivate?.onActiveModesChanged && 276 "removeListener" in WEBEXT?.quickUnlockPrivate?.onActiveModesChanged 277 ) { 278 return A.H.TRUE; 279 } 280 return A.H.FALSE; 281 }, 282 "func_OffActiveModesChanged": (fn: Pointer): void => { 283 A.store.Ref(fn, WEBEXT.quickUnlockPrivate.onActiveModesChanged.removeListener); 284 }, 285 "call_OffActiveModesChanged": (retPtr: Pointer, callback: heap.Ref<object>): void => { 286 const _ret = WEBEXT.quickUnlockPrivate.onActiveModesChanged.removeListener(A.H.get<object>(callback)); 287 }, 288 "try_OffActiveModesChanged": (retPtr: Pointer, errPtr: Pointer, callback: heap.Ref<object>): heap.Ref<boolean> => { 289 try { 290 const _ret = WEBEXT.quickUnlockPrivate.onActiveModesChanged.removeListener(A.H.get<object>(callback)); 291 return A.H.TRUE; 292 } catch (err: any) { 293 A.store.Ref(errPtr, err); 294 return A.H.FALSE; 295 } 296 }, 297 "has_HasOnActiveModesChanged": (): heap.Ref<boolean> => { 298 if ( 299 WEBEXT?.quickUnlockPrivate?.onActiveModesChanged && 300 "hasListener" in WEBEXT?.quickUnlockPrivate?.onActiveModesChanged 301 ) { 302 return A.H.TRUE; 303 } 304 return A.H.FALSE; 305 }, 306 "func_HasOnActiveModesChanged": (fn: Pointer): void => { 307 A.store.Ref(fn, WEBEXT.quickUnlockPrivate.onActiveModesChanged.hasListener); 308 }, 309 "call_HasOnActiveModesChanged": (retPtr: Pointer, callback: heap.Ref<object>): void => { 310 const _ret = WEBEXT.quickUnlockPrivate.onActiveModesChanged.hasListener(A.H.get<object>(callback)); 311 A.store.Bool(retPtr, _ret); 312 }, 313 "try_HasOnActiveModesChanged": ( 314 retPtr: Pointer, 315 errPtr: Pointer, 316 callback: heap.Ref<object> 317 ): heap.Ref<boolean> => { 318 try { 319 const _ret = WEBEXT.quickUnlockPrivate.onActiveModesChanged.hasListener(A.H.get<object>(callback)); 320 A.store.Bool(retPtr, _ret); 321 return A.H.TRUE; 322 } catch (err: any) { 323 A.store.Ref(errPtr, err); 324 return A.H.FALSE; 325 } 326 }, 327 "has_SetLockScreenEnabled": (): heap.Ref<boolean> => { 328 if (WEBEXT?.quickUnlockPrivate && "setLockScreenEnabled" in WEBEXT?.quickUnlockPrivate) { 329 return A.H.TRUE; 330 } 331 return A.H.FALSE; 332 }, 333 "func_SetLockScreenEnabled": (fn: Pointer): void => { 334 A.store.Ref(fn, WEBEXT.quickUnlockPrivate.setLockScreenEnabled); 335 }, 336 "call_SetLockScreenEnabled": (retPtr: Pointer, token: heap.Ref<object>, enabled: heap.Ref<boolean>): void => { 337 const _ret = WEBEXT.quickUnlockPrivate.setLockScreenEnabled(A.H.get<object>(token), enabled === A.H.TRUE); 338 A.store.Ref(retPtr, _ret); 339 }, 340 "try_SetLockScreenEnabled": ( 341 retPtr: Pointer, 342 errPtr: Pointer, 343 token: heap.Ref<object>, 344 enabled: heap.Ref<boolean> 345 ): heap.Ref<boolean> => { 346 try { 347 const _ret = WEBEXT.quickUnlockPrivate.setLockScreenEnabled(A.H.get<object>(token), enabled === A.H.TRUE); 348 A.store.Ref(retPtr, _ret); 349 return A.H.TRUE; 350 } catch (err: any) { 351 A.store.Ref(errPtr, err); 352 return A.H.FALSE; 353 } 354 }, 355 "has_SetModes": (): heap.Ref<boolean> => { 356 if (WEBEXT?.quickUnlockPrivate && "setModes" in WEBEXT?.quickUnlockPrivate) { 357 return A.H.TRUE; 358 } 359 return A.H.FALSE; 360 }, 361 "func_SetModes": (fn: Pointer): void => { 362 A.store.Ref(fn, WEBEXT.quickUnlockPrivate.setModes); 363 }, 364 "call_SetModes": ( 365 retPtr: Pointer, 366 token: heap.Ref<object>, 367 modes: heap.Ref<object>, 368 credentials: heap.Ref<object> 369 ): void => { 370 const _ret = WEBEXT.quickUnlockPrivate.setModes( 371 A.H.get<object>(token), 372 A.H.get<object>(modes), 373 A.H.get<object>(credentials) 374 ); 375 A.store.Ref(retPtr, _ret); 376 }, 377 "try_SetModes": ( 378 retPtr: Pointer, 379 errPtr: Pointer, 380 token: heap.Ref<object>, 381 modes: heap.Ref<object>, 382 credentials: heap.Ref<object> 383 ): heap.Ref<boolean> => { 384 try { 385 const _ret = WEBEXT.quickUnlockPrivate.setModes( 386 A.H.get<object>(token), 387 A.H.get<object>(modes), 388 A.H.get<object>(credentials) 389 ); 390 A.store.Ref(retPtr, _ret); 391 return A.H.TRUE; 392 } catch (err: any) { 393 A.store.Ref(errPtr, err); 394 return A.H.FALSE; 395 } 396 }, 397 "has_SetPinAutosubmitEnabled": (): heap.Ref<boolean> => { 398 if (WEBEXT?.quickUnlockPrivate && "setPinAutosubmitEnabled" in WEBEXT?.quickUnlockPrivate) { 399 return A.H.TRUE; 400 } 401 return A.H.FALSE; 402 }, 403 "func_SetPinAutosubmitEnabled": (fn: Pointer): void => { 404 A.store.Ref(fn, WEBEXT.quickUnlockPrivate.setPinAutosubmitEnabled); 405 }, 406 "call_SetPinAutosubmitEnabled": ( 407 retPtr: Pointer, 408 token: heap.Ref<object>, 409 pin: heap.Ref<object>, 410 enabled: heap.Ref<boolean> 411 ): void => { 412 const _ret = WEBEXT.quickUnlockPrivate.setPinAutosubmitEnabled( 413 A.H.get<object>(token), 414 A.H.get<object>(pin), 415 enabled === A.H.TRUE 416 ); 417 A.store.Ref(retPtr, _ret); 418 }, 419 "try_SetPinAutosubmitEnabled": ( 420 retPtr: Pointer, 421 errPtr: Pointer, 422 token: heap.Ref<object>, 423 pin: heap.Ref<object>, 424 enabled: heap.Ref<boolean> 425 ): heap.Ref<boolean> => { 426 try { 427 const _ret = WEBEXT.quickUnlockPrivate.setPinAutosubmitEnabled( 428 A.H.get<object>(token), 429 A.H.get<object>(pin), 430 enabled === A.H.TRUE 431 ); 432 A.store.Ref(retPtr, _ret); 433 return A.H.TRUE; 434 } catch (err: any) { 435 A.store.Ref(errPtr, err); 436 return A.H.FALSE; 437 } 438 }, 439 }; 440 });