Skip to content

Commit ca79d3c

Browse files
sid6mathurthibmeu
authored andcommitted
Add await and other readability improvements to Request signing
1 parent 99fdd89 commit ca79d3c

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

packages/web-bot-auth/README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ More concrete examples are provided on [cloudflareresearch/web-bot-auth/examples
2828
### Signing
2929

3030
```typescript
31-
import { Algorithm, signatureHeaders } from "web-bot-auth";
31+
import { signatureHeaders } from "web-bot-auth";
3232
import { signerFromJWK } from "web-bot-auth/crypto";
3333

34-
// The following simple request ios going to be signed
35-
const request = new Request("https://example.com");
34+
// The following simple request is going to be signed
35+
const request = new Request("https://http-message-signatures-example.research.cloudflare.com/debug");
3636

37-
// available at https://github.com/cloudflareresearch/web-bot-auth/blob/main/examples/rfc9421-keys/ed25519.json
37+
// This is a testing-only private key/public key pair described in RFC 9421
38+
// Also available at https://github.com/cloudflareresearch/web-bot-auth/blob/main/examples/rfc9421-keys/ed25519.json
3839
const RFC_9421_ED25519_TEST_KEY = {
3940
kty: "OKP",
4041
crv: "Ed25519",
@@ -43,7 +44,8 @@ const RFC_9421_ED25519_TEST_KEY = {
4344
x: "JrQLj5P_89iXES9-vFgrIy29clF9CC_oPPsw3c5D0bs",
4445
};
4546

46-
const headers = signatureHeaders(
47+
const now = new Date();
48+
const headers = await signatureHeaders(
4749
request,
4850
await signerFromJWK(RFC_9421_ED25519_TEST_KEY),
4951
{
@@ -53,7 +55,7 @@ const headers = signatureHeaders(
5355
);
5456

5557
// Et voila! Here is our signed request
56-
const signedRequest = new Request("https://example.com", {
58+
const signedRequest = new Request("https://http-message-signatures-example.research.cloudflare.com/debug", {
5759
headers: {
5860
Signature: headers["Signature"],
5961
"Signature-Input": headers["Signature-Input"],

0 commit comments

Comments
 (0)