github.com/primecitizens/pcz/std@v0.2.1/plat/js/webext/platformkeysinternal/bindings/ffi_bindings.ts (about)

     1  import { importModule, Application, heap, Pointer } from "@ffi";
     2  
     3  importModule("plat/js/webext/platformkeysinternal", (A: Application) => {
     4    const WEBEXT = typeof globalThis.browser === "undefined" ? globalThis.chrome : globalThis.browser;
     5  
     6    return {
     7      "has_GetPublicKey": (): heap.Ref<boolean> => {
     8        if (WEBEXT?.platformKeysInternal && "getPublicKey" in WEBEXT?.platformKeysInternal) {
     9          return A.H.TRUE;
    10        }
    11        return A.H.FALSE;
    12      },
    13      "func_GetPublicKey": (fn: Pointer): void => {
    14        A.store.Ref(fn, WEBEXT.platformKeysInternal.getPublicKey);
    15      },
    16      "call_GetPublicKey": (
    17        retPtr: Pointer,
    18        certificate: heap.Ref<object>,
    19        algorithmName: heap.Ref<object>,
    20        callback: heap.Ref<object>
    21      ): void => {
    22        const _ret = WEBEXT.platformKeysInternal.getPublicKey(
    23          A.H.get<object>(certificate),
    24          A.H.get<object>(algorithmName),
    25          A.H.get<object>(callback)
    26        );
    27      },
    28      "try_GetPublicKey": (
    29        retPtr: Pointer,
    30        errPtr: Pointer,
    31        certificate: heap.Ref<object>,
    32        algorithmName: heap.Ref<object>,
    33        callback: heap.Ref<object>
    34      ): heap.Ref<boolean> => {
    35        try {
    36          const _ret = WEBEXT.platformKeysInternal.getPublicKey(
    37            A.H.get<object>(certificate),
    38            A.H.get<object>(algorithmName),
    39            A.H.get<object>(callback)
    40          );
    41          return A.H.TRUE;
    42        } catch (err: any) {
    43          A.store.Ref(errPtr, err);
    44          return A.H.FALSE;
    45        }
    46      },
    47      "has_GetPublicKeyBySpki": (): heap.Ref<boolean> => {
    48        if (WEBEXT?.platformKeysInternal && "getPublicKeyBySpki" in WEBEXT?.platformKeysInternal) {
    49          return A.H.TRUE;
    50        }
    51        return A.H.FALSE;
    52      },
    53      "func_GetPublicKeyBySpki": (fn: Pointer): void => {
    54        A.store.Ref(fn, WEBEXT.platformKeysInternal.getPublicKeyBySpki);
    55      },
    56      "call_GetPublicKeyBySpki": (
    57        retPtr: Pointer,
    58        publicKeySpkiDer: heap.Ref<object>,
    59        algorithmName: heap.Ref<object>,
    60        callback: heap.Ref<object>
    61      ): void => {
    62        const _ret = WEBEXT.platformKeysInternal.getPublicKeyBySpki(
    63          A.H.get<object>(publicKeySpkiDer),
    64          A.H.get<object>(algorithmName),
    65          A.H.get<object>(callback)
    66        );
    67      },
    68      "try_GetPublicKeyBySpki": (
    69        retPtr: Pointer,
    70        errPtr: Pointer,
    71        publicKeySpkiDer: heap.Ref<object>,
    72        algorithmName: heap.Ref<object>,
    73        callback: heap.Ref<object>
    74      ): heap.Ref<boolean> => {
    75        try {
    76          const _ret = WEBEXT.platformKeysInternal.getPublicKeyBySpki(
    77            A.H.get<object>(publicKeySpkiDer),
    78            A.H.get<object>(algorithmName),
    79            A.H.get<object>(callback)
    80          );
    81          return A.H.TRUE;
    82        } catch (err: any) {
    83          A.store.Ref(errPtr, err);
    84          return A.H.FALSE;
    85        }
    86      },
    87      "has_SelectClientCertificates": (): heap.Ref<boolean> => {
    88        if (WEBEXT?.platformKeysInternal && "selectClientCertificates" in WEBEXT?.platformKeysInternal) {
    89          return A.H.TRUE;
    90        }
    91        return A.H.FALSE;
    92      },
    93      "func_SelectClientCertificates": (fn: Pointer): void => {
    94        A.store.Ref(fn, WEBEXT.platformKeysInternal.selectClientCertificates);
    95      },
    96      "call_SelectClientCertificates": (retPtr: Pointer, details: Pointer, callback: heap.Ref<object>): void => {
    97        const details_ffi = {};
    98  
    99        if (A.load.Bool(details + 0 + 8)) {
   100          details_ffi["request"] = {};
   101          details_ffi["request"]["certificateTypes"] = A.load.Ref(details + 0 + 0, undefined);
   102          details_ffi["request"]["certificateAuthorities"] = A.load.Ref(details + 0 + 4, undefined);
   103        }
   104        details_ffi["clientCerts"] = A.load.Ref(details + 12, undefined);
   105        if (A.load.Bool(details + 17)) {
   106          details_ffi["interactive"] = A.load.Bool(details + 16);
   107        }
   108  
   109        const _ret = WEBEXT.platformKeysInternal.selectClientCertificates(details_ffi, A.H.get<object>(callback));
   110      },
   111      "try_SelectClientCertificates": (
   112        retPtr: Pointer,
   113        errPtr: Pointer,
   114        details: Pointer,
   115        callback: heap.Ref<object>
   116      ): heap.Ref<boolean> => {
   117        try {
   118          const details_ffi = {};
   119  
   120          if (A.load.Bool(details + 0 + 8)) {
   121            details_ffi["request"] = {};
   122            details_ffi["request"]["certificateTypes"] = A.load.Ref(details + 0 + 0, undefined);
   123            details_ffi["request"]["certificateAuthorities"] = A.load.Ref(details + 0 + 4, undefined);
   124          }
   125          details_ffi["clientCerts"] = A.load.Ref(details + 12, undefined);
   126          if (A.load.Bool(details + 17)) {
   127            details_ffi["interactive"] = A.load.Bool(details + 16);
   128          }
   129  
   130          const _ret = WEBEXT.platformKeysInternal.selectClientCertificates(details_ffi, A.H.get<object>(callback));
   131          return A.H.TRUE;
   132        } catch (err: any) {
   133          A.store.Ref(errPtr, err);
   134          return A.H.FALSE;
   135        }
   136      },
   137      "has_Sign": (): heap.Ref<boolean> => {
   138        if (WEBEXT?.platformKeysInternal && "sign" in WEBEXT?.platformKeysInternal) {
   139          return A.H.TRUE;
   140        }
   141        return A.H.FALSE;
   142      },
   143      "func_Sign": (fn: Pointer): void => {
   144        A.store.Ref(fn, WEBEXT.platformKeysInternal.sign);
   145      },
   146      "call_Sign": (
   147        retPtr: Pointer,
   148        tokenId: heap.Ref<object>,
   149        publicKey: heap.Ref<object>,
   150        algorithmName: heap.Ref<object>,
   151        hashAlgorithmName: heap.Ref<object>,
   152        data: heap.Ref<object>,
   153        callback: heap.Ref<object>
   154      ): void => {
   155        const _ret = WEBEXT.platformKeysInternal.sign(
   156          A.H.get<object>(tokenId),
   157          A.H.get<object>(publicKey),
   158          A.H.get<object>(algorithmName),
   159          A.H.get<object>(hashAlgorithmName),
   160          A.H.get<object>(data),
   161          A.H.get<object>(callback)
   162        );
   163      },
   164      "try_Sign": (
   165        retPtr: Pointer,
   166        errPtr: Pointer,
   167        tokenId: heap.Ref<object>,
   168        publicKey: heap.Ref<object>,
   169        algorithmName: heap.Ref<object>,
   170        hashAlgorithmName: heap.Ref<object>,
   171        data: heap.Ref<object>,
   172        callback: heap.Ref<object>
   173      ): heap.Ref<boolean> => {
   174        try {
   175          const _ret = WEBEXT.platformKeysInternal.sign(
   176            A.H.get<object>(tokenId),
   177            A.H.get<object>(publicKey),
   178            A.H.get<object>(algorithmName),
   179            A.H.get<object>(hashAlgorithmName),
   180            A.H.get<object>(data),
   181            A.H.get<object>(callback)
   182          );
   183          return A.H.TRUE;
   184        } catch (err: any) {
   185          A.store.Ref(errPtr, err);
   186          return A.H.FALSE;
   187        }
   188      },
   189    };
   190  });