Skip to content

oott123/brain-pow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

brain-pow

用于 人工大脑 的 PoW 模块。

采用 Rust + wasm,简单,体积小(40K before gzip),比较快,不过可能并非很快。

适用于简单低成本的验证场景。

算法

leading_zero_bits(blake2s(challenge + padding)) >= difficulty

其中:

  • challenge: 服务端输入的挑战,小于等于 42 字节
  • difficulty: 难度
  • leading_zero_bits: 计算出来的 hash 从最高位开始按位检查有多少位是0

PoW 模块通过暴力搜索,计算出满足条件的 8 字节 padding,返回 challenge + padding 作为 response。

编译

cargo install wasm-pack
wasm-pack build --release --target web

用法

客户端实现参考 resolver.jsworker.js

服务端需要自行实现。

为什么没有 npm

因为大家的 bundler 都不一样,很难在 npm 包里提供好用的 wasm 模块和 worker。

考虑到一共也不需要几个文件,按自己的打包器习惯,复制代码到自己仓库里更好维护。

About

Simple WASM PoW module.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors