mirror of
https://github.com/versia-pub/docs.git
synced 2025-12-06 06:18:19 +01:00
Update signing.md
This commit is contained in:
parent
8f5136c8c8
commit
7c0e3755a0
|
|
@ -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")),
|
||||
|
|
|
|||
Loading…
Reference in a new issue