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")),