Skip to content

Commit

Permalink
feat: fauna integration (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
agent-dominatrix authored Nov 27, 2023
1 parent 5ee90de commit 1938032
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 19 deletions.
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

0 comments on commit 1938032

Please sign in to comment.