mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-09 02:45:29 +08:00
refactor: replace WASM-based PoW with a high-performance native Go implementation and add context support for cancellation.
This commit is contained in:
@@ -109,7 +109,7 @@ func (c *Client) GetPow(ctx context.Context, a *auth.RequestAuth, maxAttempts in
|
||||
data, _ := resp["data"].(map[string]any)
|
||||
bizData, _ := data["biz_data"].(map[string]any)
|
||||
challenge, _ := bizData["challenge"].(map[string]any)
|
||||
answer, err := ComputePow(challenge)
|
||||
answer, err := ComputePow(ctx, challenge)
|
||||
if err != nil {
|
||||
attempts++
|
||||
continue
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package deepseek
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@@ -9,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
// ComputePow 使用纯 Go 实现求解 PoW challenge (DeepSeekHashV1)。
|
||||
func ComputePow(challenge map[string]any) (int64, error) {
|
||||
func ComputePow(ctx context.Context, challenge map[string]any) (int64, error) {
|
||||
algo, _ := challenge["algorithm"].(string)
|
||||
if algo != "DeepSeekHashV1" {
|
||||
return 0, errors.New("unsupported algorithm")
|
||||
@@ -19,7 +20,7 @@ func ComputePow(challenge map[string]any) (int64, error) {
|
||||
expireAt := toInt64(challenge["expire_at"], 1680000000)
|
||||
difficulty := toInt64FromFloat(challenge["difficulty"], 144000)
|
||||
|
||||
return pow.SolvePow(challengeStr, salt, expireAt, difficulty)
|
||||
return pow.SolvePow(ctx, challengeStr, salt, expireAt, difficulty)
|
||||
}
|
||||
|
||||
// BuildPowHeader 序列化 {algorithm,challenge,salt,answer,signature,target_path} 为 base64(JSON)。
|
||||
|
||||
@@ -13,7 +13,7 @@ func TestPreloadPowNoOp(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestComputePowUnsupportedAlgorithm(t *testing.T) {
|
||||
_, err := ComputePow(map[string]any{"algorithm": "unknown"})
|
||||
_, err := ComputePow(context.Background(), map[string]any{"algorithm": "unknown"})
|
||||
if err == nil {
|
||||
t.Fatal("expected error for unsupported algorithm")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user