fork
Configure Feed
Select the types of activity you want to include in your feed.
node and browser bindings for gleam
fork
Configure Feed
Select the types of activity you want to include in your feed.
1import { Ok, Error } from "./gleam.mjs";
2
3export function fromNavigator() {
4 const credentials = globalThis?.navigator?.credentials
5 if (globalThis.CredentialsContainer && credentials instanceof CredentialsContainer) {
6 return new Ok(credentials)
7 } else {
8 return new Error()
9 }
10}
11
12export async function isConditionalMediationAvailable() {
13 if (
14 globalThis.PublicKeyCredential &&
15 PublicKeyCredential.isConditionalMediationAvailable
16 ) {
17 return await PublicKeyCredential.isConditionalMediationAvailable();
18 }
19 return false
20}
21
22export async function isUserVerifyingPlatformAuthenticatorAvailable() {
23 if (
24 globalThis.PublicKeyCredential &&
25 PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable
26 ) {
27 return await PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable();
28 }
29 return false
30}
31
32
33export function parseCreationOptionsFromJSON(options) {
34 try {
35 return new Ok(globalThis.PublicKeyCredential.parseCreationOptionsFromJSON(options))
36 } catch (error) {
37 return new Error(`${error}`)
38 }
39}
40
41export function parseRequestOptionsFromJSON(options) {
42 try {
43 return new Ok(globalThis.PublicKeyCredential.parseRequestOptionsFromJSON(options))
44 } catch (error) {
45 return new Error(`${error}`)
46 }
47}
48
49export function authenticatorAttachment(credential) {
50 return credential.authenticatorAttachment
51}
52
53export function id(credential) {
54 return credential.id
55}
56
57export function rawId(credential) {
58 return credential.rawId
59}
60
61// on response
62export function clientDataJSON(credential) {
63 return credential.response.clientDataJSON
64}
65
66export function attestationObject(credential) {
67 return credential.response.attestationObject
68}
69
70export function getAuthenticatorData(credential) {
71 return credential.response.getAuthenticatorData()
72}
73
74export function getPublicKey(credential) {
75 return credential.response.getPublicKey()
76}
77
78export function getPublicKeyAlgorithm(credential) {
79 return credential.response.getPublicKeyAlgorithm()
80}
81
82export function getTransports(credential) {
83 return credential.response.getTransports()
84}
85
86export function authenticatorData(credential) {
87 return credential.response.authenticatorData
88}
89
90export function signature(credential) {
91 return credential.response.signature
92}
93
94export function userHandle(credential) {
95 return credential.response.userHandle
96}
97
98export function toJSON(credential) {
99 return credential.toJSON()
100}
101
102export async function createForPublicKey(container, options) {
103 try {
104 return new Ok(await container.create({ publicKey: options }))
105 } catch (error) {
106 return new Error(`${error}`)
107 }
108}
109
110export function JSONObject(entries) {
111 const output = {}
112 for (const [k, v] of entries) {
113 if (v == null || v == undefined) {
114 continue
115 } else {
116 output[k] = v
117 }
118 }
119 return output
120}
121
122export async function getForPublicKey(container, options) {
123 try {
124 return new Ok(await container.get({ publicKey: options }))
125 } catch (error) {
126 return new Error(`${error}`)
127 }
128}