Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fauna integration #341

Merged
merged 4 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/fetch-extension/src/config.ui.var.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const ADDITIONAL_INTL_MESSAGES: IntlMessages = {};
// export const SUBSCRIPTION_SERVER = "ws://localhost:4000/subscription";
// export const AUTH_SERVER = "http://localhost:5500";

export const AUTH_SERVER = "https://auth-attila.sandbox-london-b.fetch-ai.com";
export const AUTH_SERVER = "https://accounts.fetch.ai/v1";

export const FNS_TEST_ADDRESS = "fetch1s84mudgmjfjmkef7ludqnwy0fchh3mf4p4rmll";

Expand All @@ -36,8 +36,8 @@ let SUBSCRIPTION_SERVER, MESSAGING_SERVER;
export let NOTYPHI_BASE_URL: string;

if (process.env.NODE_ENV === "production") {
SUBSCRIPTION_SERVER = "wss://messaging.fetch-ai.network/subscription";
MESSAGING_SERVER = "https://messaging.fetch-ai.network/graphql";
SUBSCRIPTION_SERVER = "wss://messaging-server.prod.fetch-ai.com/subscription";
MESSAGING_SERVER = "https://messaging-server.prod.fetch-ai.com/graphql";
NOTYPHI_BASE_URL = "https://api.notyphi.com/v1";
} else {
SUBSCRIPTION_SERVER =
Expand Down
52 changes: 36 additions & 16 deletions packages/fetch-extension/src/utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ declare global {
const signArbitrary = async (
chainId: string,
addr: string,
pubKey: string,
data: string,
requester: any // TODO(!!!): Update types
) => {
Expand Down Expand Up @@ -68,11 +67,7 @@ const signArbitrary = async (
new SignMessagingPayload(chainId, toBase64(serializeSignDoc(signDoc)))
);

return {
signature,
public_key: pubKey,
signed_bytes: toBase64(serializeSignDoc(signDoc)),
};
return signature;
};

export const getJWT = async (chainId: string, url: string) => {
Expand All @@ -98,38 +93,63 @@ export const getJWT = async (chainId: string, url: string) => {
);
const request = {
address: addr,
public_key: pubKey.publicKey,
client_id: "fetch-wallet",
};

const r1 = await axios.post(`${url}/request_token`, request, config);
const r1 = await axios.post(
`${url}/auth/login/wallet/challenge`,
request,
config
);

if (r1.status !== 200) throw new RequestError(r1.statusText);

let loginRequest = undefined;
let signature = undefined;

try {
loginRequest = await signArbitrary(
signature = await signArbitrary(
chainId,
addr,
pubKey.publicKey,
r1.data.payload,
r1.data.challenge,
requester
);
} catch (err: any) {
throw new RejectError(err.toString());
}

if (loginRequest === undefined) {
if (signature === undefined) {
return undefined;
}

const r2 = await axios.post(`${url}/login`, loginRequest, config);
const loginRequest = {
address: addr,
public_key: {
value: toBase64(fromHex(pubKey.publicKey)),
type: "tendermint/PubKeySecp256k1",
},
nonce: r1.data.nonce,
challenge: r1.data.challenge,
signature: signature,
client_id: "fetch-wallet",
scope: "",
};

const r2 = await axios.post(
`${url}/auth/login/wallet/verify`,
loginRequest,
config
);

if (r2.status !== 200) {
throw new RequestError(r1.statusText);
throw new RequestError(r2.statusText);
}

const r3 = await axios.post(`${url}/tokens`, r2.data, config);
if (r3.status !== 200) {
throw new RequestError(r3.statusText);
}

return r2.data.token;
return r3.data.access_token;
};
function generateUUID() {
// Public Domain/MIT
Expand Down
Loading