From 7c0e3755a03ab272965e9f8ea5f9ec36ba3b517a Mon Sep 17 00:00:00 2001 From: Gaspard Wierzbinski Date: Sun, 26 Nov 2023 18:07:35 -1000 Subject: [PATCH] Update signing.md --- docs/cryptography/signing.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/cryptography/signing.md b/docs/cryptography/signing.md index f0d3aa6..b6534d8 100644 --- a/docs/cryptography/signing.md +++ b/docs/cryptography/signing.md @@ -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: ```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( "pkcs8", str2ab(atob("base64_private_key")),