idkit-core
Version:
The identity SDK. Privacy-preserving identity and proof of personhood with World ID.
71 lines (67 loc) • 2.4 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/lib/backend.ts
var backend_exports = {};
__export(backend_exports, {
verifyCloudProof: () => verifyCloudProof
});
module.exports = __toCommonJS(backend_exports);
// src/lib/hashing.ts
var import_buffer = require("buffer/index.js");
var import_ox = require("ox");
function hashToField(input) {
if (import_ox.Bytes.validate(input) || import_ox.Hex.validate(input)) return hashEncodedBytes(input);
return hashString(input);
}
function hashString(input) {
const bytesInput = import_buffer.Buffer.from(input);
return hashEncodedBytes(bytesInput);
}
function hashEncodedBytes(input) {
const hash = BigInt(import_ox.Hash.keccak256(input, { as: "Hex" })) >> 8n;
const rawDigest = hash.toString(16);
return { hash, digest: `0x${rawDigest.padStart(64, "0")}` };
}
// src/lib/backend.ts
var import_browser_or_node = require("browser-or-node");
async function verifyCloudProof(proof, app_id, action, signal, endpoint) {
if (import_browser_or_node.isBrowser) {
throw new Error("verifyCloudProof can only be used in the backend.");
}
const response = await fetch(endpoint ?? `https://developer.worldcoin.org/api/v2/verify/${app_id}`, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
...proof,
action,
signal_hash: hashToField(signal ?? "").digest
})
});
if (response.ok) {
return { success: true };
} else {
return { success: false, ...await response.json() };
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
verifyCloudProof
});