定制 symbiotic/btc-puzzle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

symbiotic/btc-puzzle

Composer 安装命令:

composer require symbiotic/btc-puzzle

包简介

README 文档

README

Pool server   <-- Client.exe Request range

Pool server   --> Generate range
             
Pool server   --> Request signature adresses 
                 |----1Address0 <- Pool server  - 1 address from the pool server
                 |----1Address1 <- User server | 
                 |----1Address2 <- User server |- addresses from pool members
                 |----1Address3 <- User server |
                 |----1Address4 <- User server |
                 
Pool Server   --> Send to client
                { 
                 rangeStart: xxxxxxxxx,
                 rangeEnd  : xxxxxxxxx,
                 signatureAddresses : [1Address1, ...],
                }
               
Pool Server  <-- Client sending the found verification addresses to the pool
                { 
                 rangeStart: xxxxxxxxx,
                 rangeEnd  : xxxxxxxxx,
                 signature: ['privateHex1' => '1Address1',....],
                }
               
Pool Server  --> Check signature addresses and signatory range
       

To form the verification addresses of the issued range, several remote participant servers are used enumeration, which eliminates the fake passage of the range even by the creator of the enumeration pool.

Each server, at its discretion, can keep logs of issued sectors, and after finding the puzzle, it is easy to check who range was given.

Algorithm for generating a verification address

To create a verification address, use:

  • puzzle number
  • sector number
  • user ID of the user (for which the sector is issued)

The algorithm is simple, a hash is created based on the data and the first characters of the number are taken from it, which are substituted inside range. As an answer, a verification address and a hash of the sector are given, which is formed from a secret phrase, a puzzle and a number sectors.

Example:

secret = efjiej34f9349gj4309hg4349tfh3044f3
puzzle: 66
sectorNumber = 32352000
userID = 1

We calculate:
                  hex( 2^(66 -1) +(2^40 * sectorNumber ) )
startHex        = 3eda7000000000000

                  hex( 2^(66 - 1) +(2^40 * sectorNumber + 1 ) )
nextHex         = 3eda7010000000000

                  hex( next - start) 
range           = ffffffffff   // 2^40 we need the number of characters
                 strlen( range )
addressHashLen  = 10

Sector hash for crypt password
                      sha256(secret + puzzle + sectorNumber)
sectorHash         =  99980898683611033808737021fe85d29f08d02ef13076071348e330418ba8a4

Sector signature for subsequent verification that the address was issued from your server.

                sha256(secret + puzzle + sectorNumber + userID)
userSectorHash     = f87e6a01e99458e2121e1bf53985b8f98899cbc44458b53a1d627cf1381ea428

Address private key prefix
                 substr(startHex, addressHashLen (10) )
startHexPrefix = 3eda700 - remove characters equal to the length of the range

                 startHexPrefix +  substr(userSectorHash, 0, addressHashLen (10) )
addressPrivHex     = 3eda700f87e6a01e9 - range prefix and 10 sector hash characters for the user

address            = 1BU1bkkW3YX1NyBxmaLpP48pe2uvh67jX

We perform a hashing operation 5-50 several times
                      sha256(sectorHash + addressPrivHex) 
passwordSHA256      = bde3eafd6fd1ca80870601f32e0c2f592462e446f7c5139e4ee9eb9230a10609


password = BLOWFISH( passwordSHA256 )

Answer:

'sectorHash' : '99980898683611033808737021fe85d29f08d02ef13076071348e330418ba8a4',
'address'     : '1BU1bkkW3YX1NyBxmaLpP48pe2uvh67jX'
'userSectorHash' : 'f87e6a01e99458e2121e1bf53985b8f98899cbc44458b53a1d627cf1381ea428',
'signatureBlowfish' => '$2y$10$n5Ehd0YUVvy1tW2nLaMRTu6TGE84FY2mCbFwMDndTk1yBSf2J7pui'
            

Usage

To use, you must create a secret phrase with a length of at least 20 characters. No one should know her otherwise will be able to generate range addresses on your behalf.

The token is needed to protect against enumeration, otherwise each user will be able to enumerate all sectors and get verification addresses before passing the ranges.

$config = new \Symbiotic\BtcPuzzle\Config(
    [
        // your secret phrase for generating signatures
        'secret' => 'efjiej34f9349gj4309hg4349tfh3044f3',
        // authorization token for generating a range signature
        'token' => 'Aich45vbdghbds'
    ]
);

For convenient work, there is a controller that accepts GET parameters for operation:

$controller = new \Symbiotic\BtcPuzzle\SignatureController($config, $_GET);

echo $controller->dispatch();
Example:

// Verification address generator
$generator = new \Symbiotic\BtcPuzzle\SignatureGenerator($config->getToken(), $config->getSecret()); 

// Puzzle Range 
$sector = new \Symbiotic\BtcPuzzle\Sector($puzzleId, $sectorNumber);

// Create a verification address for the user
$address = $generator->generateSectorAddress($token, $sector, $user_id);

// hash of the sector for subsequent authentication of the issuance by the user's server
$sectorHash = $generator->getSectorHash($puzzleId, $sectorNumber);

$signature = $generator->generateSectorSignature($token, $sector, $user_id);

echo json_encode([
    'sectorHash' => $signature['sectorHash'],
    'userSectorHash' => $signature['userSectorHash']
    'signatureBlowfish' => $signature['signatureBlowfish']
    'address' => $signature['address']/*we give only the address without the private key*/
 ]);

symbiotic/btc-puzzle 适用场景与选型建议

symbiotic/btc-puzzle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9 次下载、GitHub Stars 达 3, 最近一次更新时间为 2023 年 05 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 symbiotic/btc-puzzle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 symbiotic/btc-puzzle 我们能提供哪些服务?
定制开发 / 二次开发

基于 symbiotic/btc-puzzle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 17
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2023-05-08