mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-04 20:46:39 +02:00
Added testAPI and canvasAPI
This commit is contained in:
parent
4337ccbf33
commit
e50e9deca4
10 changed files with 177 additions and 256 deletions
25
test/testAPI.js
Normal file
25
test/testAPI.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
const testAPI = function(){
|
||||
"use strict";
|
||||
|
||||
function bufferToString(hash){
|
||||
const chunks = [];
|
||||
(new Uint32Array(hash)).forEach(function(num){
|
||||
chunks.push(num.toString(16));
|
||||
});
|
||||
return chunks.map(function(chunk){
|
||||
return "0".repeat(8 - chunk.length) + chunk;
|
||||
}).join("");
|
||||
}
|
||||
|
||||
|
||||
|
||||
return {
|
||||
hash: async function(input){
|
||||
const buffer = ((typeof input) === "string")?
|
||||
new TextEncoder("utf-8").encode(input):
|
||||
input;
|
||||
const hash = await crypto.subtle.digest("SHA-256", buffer);
|
||||
return bufferToString(hash);
|
||||
}
|
||||
};
|
||||
}();
|
Loading…
Add table
Add a link
Reference in a new issue