【发布时间】:2022-06-15 00:39:05
【问题描述】:
我需要帮助重写这段代码,我承认我是新手,不知道该怎么做,但我不能使用这个客户端版本的代码,因为响应可能被欺骗,代码:
const sodium = require("libsodium-wrappers")
const bs58check = require("bs58check")
const prefix = {
edsig: new Uint8Array([9, 245, 205, 134, 18]),
edpk: new Uint8Array([13, 15, 37, 217])
};
function hex2buf(hex) {
return new Uint8Array(
hex.match(/[\da-f]{2}/gi).map(function (h) {
return parseInt(h, 16)
})
);
}
function b58decode(enc, prefix) {
return bs58check.decode(enc).slice(prefix.length);
}
async function verifyUserSignature(bytes, sig, pk) {
await sodium.ready;
try {
const verify = sodium.crypto_sign_verify_detached(
b58decode(sig, prefix.edsig),
sodium.crypto_generichash(32, hex2buf(bytes)),
b58decode(pk, prefix.edpk)
)
console.log("Verify: ", verify)
return verify
} catch (e) {
console.log("Error: ", e)
throw e
}
}
const bytes = myBytes
const sig = mySig
const pubKey = myPubKey
verifyUserSignature(bytes, sig, pubKey)
是否有可能做到这一点? 我发现PHP也有:
sodium_crypto_sign_verify_detached
PHP class for encoding & decoding Base-58 values - https://github.com/ionux/php-base58
【问题讨论】:
-
你好。预计您已尝试自己解决问题。请编辑您的问题并添加您的 PHP 代码,并说明您在该代码中的哪一点没有得到您期望的结果。
标签: javascript php