Skip to content

Commit

Permalink
Replace in operator with utility method that uses hasOwnProperty.…
Browse files Browse the repository at this point in the history
… Fix typing mismatch between delegation and requestId method.
  • Loading branch information
sea-snake committed Nov 28, 2024
1 parent f326af5 commit 40d6b9a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/agent/src/agent/http/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ export class HttpAgent implements Agent {
}

// Apply transform for identity.
transformedRequest = await id.transformRequest(transformedRequest);
transformedRequest = (await id.transformRequest(transformedRequest)) as HttpAgentSubmitRequest;

const body = cbor.encode(transformedRequest.body);
const backoff = this.#backoffStrategy();
Expand Down
20 changes: 16 additions & 4 deletions packages/agent/src/polling/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ interface SignedReadStateRequestWithExpiry {
};
}

/**
* Check if an object has a property
* @param value the object that might have the property
* @param property the key of property we're looking for
*/
function hasProperty<O extends object, P extends string>(
value: O,
property: P,
): value is O & Record<P, unknown> {
return Object.prototype.hasOwnProperty.call(value, property);
}

/**
* Check if value is a signed read state request with expiry
* @param value to check
Expand All @@ -32,15 +44,15 @@ function isSignedReadStateRequestWithExpiry(
return (
value !== null &&
typeof value === 'object' &&
'body' in value &&
hasProperty(value, 'body') &&
value.body !== null &&
typeof value.body === 'object' &&
'content' in value.body &&
hasProperty(value.body, 'content') &&
value.body.content !== null &&
typeof value.body.content === 'object' &&
'request_type' in value.body.content &&
hasProperty(value.body.content, 'request_type') &&
value.body.content.request_type === ReadRequestType.ReadState &&
'ingress_expiry' in value.body.content &&
hasProperty(value.body.content, 'ingress_expiry') &&
value.body.content.ingress_expiry instanceof Expiry
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/identity/src/identity/delegation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async function _createSingleDelegation(
// a user gesture if you await an async call thats not fetch, xhr, or setTimeout.
const challenge = new Uint8Array([
...domainSeparator,
...new Uint8Array(requestIdOf(delegation)),
...new Uint8Array(requestIdOf({ ...delegation })),
]);
const signature = await from.sign(challenge);

Expand Down

0 comments on commit 40d6b9a

Please sign in to comment.