Skip to content

Commit

Permalink
guard: Adding fetch middleware into GuardSigner (#622)
Browse files Browse the repository at this point in the history
  • Loading branch information
corbanbrook authored Dec 6, 2024
1 parent 8e8a76a commit 434202e
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/guard/src/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,25 @@ export class GuardSigner implements signers.SapientSigner {
constructor(
public readonly address: string,
public readonly url: string,
public readonly appendSuffix: boolean = false
public readonly appendSuffix: boolean = false,
public readonly projectAccessKey?: string
) {
this.guard = new Guard(url, fetch)
this.guard = new Guard(url, this._fetch)
}

_fetch = (input: RequestInfo, init?: RequestInit): Promise<Response> => {
const headers: { [key: string]: any } = {}

const projectAccessKey = this.projectAccessKey

if (projectAccessKey && projectAccessKey.length > 0) {
headers['X-Access-Key'] = projectAccessKey
}

// before the request is made
init!.headers = { ...init!.headers, ...headers }

return fetch(input, init)
}

async getAddress(): Promise<string> {
Expand Down

0 comments on commit 434202e

Please sign in to comment.