Update signing.md

This commit is contained in:
Gaspard Wierzbinski 2023-11-26 18:07:35 -10:00 committed by GitHub
parent 8f5136c8c8
commit 7c0e3755a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -54,6 +54,19 @@ Where `/users/uuid/inbox` is the path of the request.
Here is an example of signing a request using TypeScript and the WebCrypto API: Here is an example of signing a request using TypeScript and the WebCrypto API:
```typescript ```typescript
/**
* Convert a string into an ArrayBuffer
* from https://developers.google.com/web/updates/2012/06/How-to-convert-ArrayBuffer-to-and-from-String
*/
const str2ab = (str: string) => {
const buf = new ArrayBuffer(str.length);
const bufView = new Uint8Array(buf);
for (let i = 0, strLen = str.length; i < strLen; i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
};
const privateKey = await crypto.subtle.importKey( const privateKey = await crypto.subtle.importKey(
"pkcs8", "pkcs8",
str2ab(atob("base64_private_key")), str2ab(atob("base64_private_key")),