Skip to content

Commit bd04c35

Browse files
committed
fix: transform request instead of sign
1 parent cfe141a commit bd04c35

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/agent/index.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -162,38 +162,37 @@ export class WsAgent {
162162
ingress_expiry,
163163
};
164164

165-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
166165
const transformedRequest = (await this._transform({
167166
endpoint: Endpoint.Call,
168167
message: submit,
169168
})) as WsAgentSubmitRequest;
170169

171-
const envelope = await this._signRequest(transformedRequest.message, id);
170+
// we need to adapt out ws request to the identity's transform
171+
// in order to get the signed request
172+
const idTransformedRequest = await id.transformRequest({
173+
// mock the request to be compatible
174+
request: {
175+
body: null,
176+
method: 'POST',
177+
headers: {},
178+
},
179+
endpoint: Endpoint.Call,
180+
body: transformedRequest.message,
181+
}) as { body: Envelope<CallRequest> };
182+
172183
const message: WsAgentRequestMessage<CallRequest> = {
173-
envelope,
184+
envelope: idTransformedRequest.body,
174185
};
175186

176187
this._requestAndRetry(message);
177188
}
178189

179-
private async _signRequest<T extends Record<string, any>>(
180-
message: T,
181-
identity: SignIdentity,
182-
): Promise<Envelope<T>> {
183-
const requestId = requestIdOf(message);
184-
return {
185-
content: message,
186-
sender_pubkey: identity.getPublicKey().toDer(),
187-
sender_sig: await identity.sign(concat(domainSeparator, requestId)),
188-
};
189-
}
190-
191190
/**
192191
* Sends a fire-and-forget request body to the WebSocket Gateway.
193192
* If the request fails, the request
194193
*/
195-
private _requestAndRetry<T>(
196-
message: WsAgentRequestMessage<T>,
194+
private _requestAndRetry(
195+
message: WsAgentRequestMessage<CallRequest>,
197196
tries = 0,
198197
): void {
199198
const messageBytes = Cbor.encode(message);

0 commit comments

Comments
 (0)