Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

feat: POST auth requests to verify & throw on failed publish #82

Merged
merged 3 commits into from
Sep 14, 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
22 changes: 17 additions & 5 deletions packages/auth-client/src/controllers/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
isJsonRpcResult,
} from "@walletconnect/jsonrpc-utils";
import { PairingTypes, RelayerTypes, Verify } from "@walletconnect/types";
import { getInternalError, hashKey, TYPE_1 } from "@walletconnect/utils";
import { getInternalError, hashKey, isBrowser, TYPE_1 } from "@walletconnect/utils";
import { AUTH_CLIENT_PUBLIC_KEY_NAME, ENGINE_RPC_OPTS } from "../constants";
import { AuthClientTypes, AuthEngineTypes, IAuthEngine, JsonRpcTypes } from "../types";
import { getDidAddress, getDidChainId, getNamespacedDidChainId } from "../utils/address";
Expand Down Expand Up @@ -203,8 +203,16 @@ export class AuthEngine extends IAuthEngine {
const rpcOpts = ENGINE_RPC_OPTS[method].req;
if (expiry) rpcOpts.ttl = expiry;
this.client.core.history.set(topic, payload);
await this.client.core.relayer.publish(topic, message, rpcOpts);

if (isBrowser()) {
const hash = hashMessage(JSON.stringify(payload));
this.client.core.verify.register({ attestationId: hash });
}
await this.client.core.relayer.publish(topic, message, {
...rpcOpts,
internal: {
throwOnFailedPublish: true,
},
});
return payload.id;
};

Expand All @@ -214,9 +222,13 @@ export class AuthEngine extends IAuthEngine {
const record = await this.client.core.history.get(topic, id);
const rpcOpts = ENGINE_RPC_OPTS[record.request.method].res;

await this.client.core.relayer.publish(topic, message, rpcOpts);
await this.client.core.relayer.publish(topic, message, {
...rpcOpts,
internal: {
throwOnFailedPublish: true,
},
});
await this.client.core.history.resolve(payload);

return payload.id;
};

Expand Down
17 changes: 3 additions & 14 deletions packages/auth-client/test/helpers/ws.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import { IJsonRpcConnection } from "@walletconnect/jsonrpc-utils";
import { ICore } from "@walletconnect/types";
import EventEmitter from "events";

export async function disconnectSocket(core: ICore) {
if (core.relayer.connected) {
core.relayer.provider.events = new EventEmitter();
core.relayer.core.heartbeat.events = new EventEmitter();
core.relayer.provider.connection.on("open", async () => {
await disconnect(core.relayer.provider.connection);
});
await disconnect(core.relayer.provider.connection);
}
}

function disconnect(socket: IJsonRpcConnection) {
return socket.close();
// wait a bit for all ACK requests to be processed
await new Promise<void>((resolve) => setTimeout(resolve, 1000));
await core.relayer.transportClose();
}
Loading