handle signed get
This commit is contained in:
parent
6ef1b5c9cc
commit
9c2ce04ae1
10
src/net.ts
10
src/net.ts
|
@ -25,18 +25,16 @@ export const signedFetch = async (url: string, init: RequestInit, signedInit: Si
|
|||
["Content-Type", `application/ld+json; profile="${CONTEXT}"`]
|
||||
];
|
||||
|
||||
const newHeaders = new Headers();
|
||||
|
||||
if (signedInit.digest && init.body) {
|
||||
signedHeaders.push(["Digest", signedInit.digest]);
|
||||
}
|
||||
else if (init.body) {
|
||||
else if (init.method === "POST" && init.body) {
|
||||
if (Buffer.isBuffer(init.body) || typeof init.body === "string") {
|
||||
signedHeaders.push(["Digest", hashDigest(init.body)]);
|
||||
}
|
||||
else throw "unsupported body type";
|
||||
}
|
||||
else {
|
||||
throw "no body provided";
|
||||
}
|
||||
|
||||
const signer = new Sha256Signer({
|
||||
privateKey: signedInit.privateKey,
|
||||
|
@ -49,8 +47,8 @@ export const signedFetch = async (url: string, init: RequestInit, signedInit: Si
|
|||
headers: signedHeaders
|
||||
});
|
||||
|
||||
const newHeaders = new Headers();
|
||||
newHeaders.set("Signature", signature);
|
||||
}
|
||||
|
||||
if (Array.isArray(init.headers) || !init.headers) {
|
||||
for (const header of (init.headers || [])) {
|
||||
|
|
Loading…
Reference in New Issue