-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathsignAuthEntry.ts
More file actions
48 lines (42 loc) · 1.13 KB
/
Copy pathsignAuthEntry.ts
File metadata and controls
48 lines (42 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import {
requestAccess,
requestAllowedStatus,
submitAuthEntry,
} from "@shared/api/external";
import { FreighterApiError } from "@shared/api/types";
import { FreighterApiNodeError } from "@shared/api/helpers/extensionMessaging";
import { isBrowser } from ".";
export const signAuthEntry = async (
entryXdr: string,
opts?: {
networkPassphrase?: string;
address?: string;
},
): Promise<
{ signedAuthEntry: Buffer | null; signerAddress: string } & {
error?: FreighterApiError;
}
> => {
if (isBrowser) {
const { isAllowed } = await requestAllowedStatus();
if (!isAllowed) {
const req = await requestAccess();
if (req.error) {
return { signedAuthEntry: null, signerAddress: "", error: req.error };
}
}
const req = await submitAuthEntry(entryXdr, __PACKAGE_VERSION__, opts);
if (req.error) {
return { signedAuthEntry: null, signerAddress: "", error: req.error };
}
return {
signedAuthEntry: req.signedAuthEntry,
signerAddress: req.signerAddress,
};
}
return {
signedAuthEntry: null,
signerAddress: "",
error: FreighterApiNodeError,
};
};