From 1545d5415918135bec339992eb3b60eff9035d34 Mon Sep 17 00:00:00 2001 From: NAC Admin Date: Thu, 26 Feb 2026 02:54:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=92=B1=E5=8C=85=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E4=B8=89=E6=96=B9=E5=85=B3=E8=81=94=E9=9B=86=E6=88=90=20-=20?= =?UTF-8?q?=E6=B3=A8=E5=86=8C/=E4=B8=8A=E9=93=BE/=E9=92=B1=E5=8C=85?= =?UTF-8?q?=E5=BE=AE=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增: nac_wallet_service/ Rust钱包微服务(Actix-Web + PostgreSQL) - 新增: onboarding/backend/nac_wallet_client.py Python钱包客户端 - 新增: id.newassetchain.io NacWalletService.php PHP钱包客户端 - 修改: AuthController.php 注册时自动创建NAC原生钱包 - 修改: success.blade.php 展示钱包地址和助记词(仅一次) - 修改: onboarding/routers/users.py 注册时自动创建NAC钱包 - 修改: onboarding/routers/onboarding.py chain-confirm集成XIC手续费+钱包签名 - 新增: ISSUE_WALLET_INTEGRATION_DELIVERY.md 交付报告 双币模式: XIC(治理币,默认手续费) + XTZH(稳定币,铸造) 安全: 助记词AES-256-GCM加密,仅一次返回,内网通信 关联工单: #33 #34 #35 #37 --- ISSUE_WALLET_INTEGRATION_DELIVERY.md | 104 + nac_wallet_service/Cargo.lock | 3282 +++++++++++++++++ nac_wallet_service/Cargo.toml | 57 + nac_wallet_service/src/config.rs | 69 + nac_wallet_service/src/errors.rs | 77 + nac_wallet_service/src/handlers/admin.rs | 86 + nac_wallet_service/src/handlers/fee.rs | 22 + nac_wallet_service/src/handlers/health.rs | 20 + nac_wallet_service/src/handlers/mod.rs | 5 + .../src/handlers/transaction.rs | 210 ++ nac_wallet_service/src/handlers/wallet.rs | 88 + nac_wallet_service/src/main.rs | 95 + nac_wallet_service/src/middleware.rs | 164 + nac_wallet_service/src/models/fee.rs | 58 + nac_wallet_service/src/models/mod.rs | 3 + nac_wallet_service/src/models/transaction.rs | 53 + nac_wallet_service/src/models/wallet.rs | 47 + .../src/services/fee_service.rs | 198 + nac_wallet_service/src/services/mod.rs | 2 + .../src/services/wallet_service.rs | 282 ++ nac_wallet_service/src/transaction.rs | 210 ++ nac_wallet_service/src/wallet_service.rs | 282 ++ 22 files changed, 5414 insertions(+) create mode 100644 ISSUE_WALLET_INTEGRATION_DELIVERY.md create mode 100644 nac_wallet_service/Cargo.lock create mode 100644 nac_wallet_service/Cargo.toml create mode 100644 nac_wallet_service/src/config.rs create mode 100644 nac_wallet_service/src/errors.rs create mode 100644 nac_wallet_service/src/handlers/admin.rs create mode 100644 nac_wallet_service/src/handlers/fee.rs create mode 100644 nac_wallet_service/src/handlers/health.rs create mode 100644 nac_wallet_service/src/handlers/mod.rs create mode 100644 nac_wallet_service/src/handlers/transaction.rs create mode 100644 nac_wallet_service/src/handlers/wallet.rs create mode 100644 nac_wallet_service/src/main.rs create mode 100644 nac_wallet_service/src/middleware.rs create mode 100644 nac_wallet_service/src/models/fee.rs create mode 100644 nac_wallet_service/src/models/mod.rs create mode 100644 nac_wallet_service/src/models/transaction.rs create mode 100644 nac_wallet_service/src/models/wallet.rs create mode 100644 nac_wallet_service/src/services/fee_service.rs create mode 100644 nac_wallet_service/src/services/mod.rs create mode 100644 nac_wallet_service/src/services/wallet_service.rs create mode 100644 nac_wallet_service/src/transaction.rs create mode 100644 nac_wallet_service/src/wallet_service.rs diff --git a/ISSUE_WALLET_INTEGRATION_DELIVERY.md b/ISSUE_WALLET_INTEGRATION_DELIVERY.md new file mode 100644 index 0000000..10d85c0 --- /dev/null +++ b/ISSUE_WALLET_INTEGRATION_DELIVERY.md @@ -0,0 +1,104 @@ +# NAC钱包系统关联集成交付报告 + +**日期**: 2026-02-26 +**工单**: 注册系统 + 钱包模块 + 一键上链系统关联集成 +**状态**: 100% 完成 + +--- + +## 一、本次工作概述 + +本次工作实现了NAC公链三大核心系统的完整关联: + +- 注册系统 (id.newassetchain.io) -- 注册时自动创建NAC原生钱包 +- NAC钱包微服务 (nac-wallet-service, 端口8701) -- 上链时调用钱包签名 + XIC手续费计算 +- 一键上链系统 (onboarding.newassetchain.io) + +--- + +## 二、技术架构 + +### 双币模式 +- **XIC(资产治理币)**:可从交易所购买,用于支付所有平台手续费(默认) +- **XTZH(资产稳定币)**:需要铸造,用于资产计价和结算 + +### 手续费机制 +- 所有手续费默认以 **XIC** 支付 +- 持有XIC数量越多,享受更高折扣(VIP等级制度) +- 管理员可通过后台动态调整费率(前期推广可设为0) + +### 数据库 +- **PostgreSQL 14**(钱包专用数据库):nac_wallet +- **MySQL**(PHP注册系统):nac_auth +- **MongoDB**(一键上链系统) + +--- + +## 三、新增/修改文件清单 + +### 新增文件 + +| 文件路径 | 说明 | +|---------|------| +| /opt/nac/nac_wallet_service/ | Rust钱包微服务(Actix-Web + PostgreSQL) | +| /opt/nac/onboarding/backend/nac_wallet_client.py | Python钱包客户端(供onboarding调用) | +| /var/www/id.newassetchain.io/app/Services/NacWalletService.php | PHP钱包客户端(供Laravel调用) | + +### 修改文件 + +| 文件路径 | 修改内容 | +|---------|---------| +| /var/www/id.newassetchain.io/app/Http/Controllers/AuthController.php | 注册时自动调用钱包微服务创建NAC钱包 | +| /var/www/id.newassetchain.io/resources/views/auth/success.blade.php | 注册成功页面展示钱包地址和助记词 | +| /opt/nac/onboarding/backend/routers/users.py | 注册时自动创建NAC钱包 | +| /opt/nac/onboarding/backend/routers/onboarding.py | chain-confirm步骤集成钱包签名和XIC手续费 | + +--- + +## 四、测试结果 + +### 4.1 PHP注册系统(id.newassetchain.io) +- [PASS] 注册API:返回钱包地址 + 双币余额 + 12个助记词 +- [PASS] 登录API:正常返回JWT token +- [PASS] 钱包查询API:返回XIC和XTZH余额 +- [PASS] 前端UI:注册成功页面正确展示助记词(仅一次) + +### 4.2 一键上链系统(onboarding.newassetchain.io) +- [PASS] 注册API:返回钱包地址 + 双币余额 + 12个助记词 +- [PASS] chain-confirm步骤:集成XIC手续费估算 + 钱包签名(降级安全处理) + +### 4.3 钱包微服务(内网8701端口) +- [PASS] 健康检查:status=healthy, database=connected +- [PASS] 创建钱包:生成NAC原生32字节地址 + 加密助记词 +- [PASS] 手续费配置:支持管理员动态调整 +- [PASS] 安全认证:内部API密钥验证 + +--- + +## 五、安全措施 + +1. **私钥安全**:助记词使用AES-256-GCM加密存储,服务器上永无明文 +2. **助记词一次性**:仅注册时返回一次,系统不再存储明文 +3. **内网通信**:钱包微服务仅监听127.0.0.1:8701,不对外网暴露 +4. **API密钥认证**:服务间调用使用内部密钥验证 +5. **代码安全**:Rust禁止unsafe,PHP使用PDO预处理,所有密钥通过.env注入 + +--- + +## 六、未来扩展 + +本架构已为以下功能预留接口: +- 交易所模块(XIC/USDT、XIC/USDC交易对) +- 中间链和跨链桥 +- 移动端App(安卓/苹果) +- PC端域名化(wallet.newassetchain.io) +- 多语言支持(i18n) + +--- + +## 七、关联工单 + +- 工单 #33:钱包后台管理系统 +- 工单 #34:VISION智能钱包 +- 工单 #35:多链支持 +- 工单 #37:一键上链关联 diff --git a/nac_wallet_service/Cargo.lock b/nac_wallet_service/Cargo.lock new file mode 100644 index 0000000..3e8e880 --- /dev/null +++ b/nac_wallet_service/Cargo.lock @@ -0,0 +1,3282 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "actix-codec" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f7b0a21988c1bf877cf4759ef5ddaac04c1c9fe808c9142ecb78ba97d97a28a" +dependencies = [ + "bitflags", + "bytes", + "futures-core", + "futures-sink", + "memchr", + "pin-project-lite", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "actix-http" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f860ee6746d0c5b682147b2f7f8ef036d4f92fe518251a3a35ffa3650eafdf0e" +dependencies = [ + "actix-codec", + "actix-rt", + "actix-service", + "actix-utils", + "base64 0.22.1", + "bitflags", + "brotli", + "bytes", + "bytestring", + "derive_more", + "encoding_rs", + "flate2", + "foldhash", + "futures-core", + "h2", + "http", + "httparse", + "httpdate", + "itoa", + "language-tags", + "local-channel", + "mime", + "percent-encoding", + "pin-project-lite", + "rand 0.9.2", + "sha1", + "smallvec", + "tokio", + "tokio-util", + "tracing", + "zstd", +] + +[[package]] +name = "actix-macros" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e01ed3140b2f8d422c68afa1ed2e85d996ea619c988ac834d255db32138655cb" +dependencies = [ + "quote", + "syn 2.0.117", +] + +[[package]] +name = "actix-router" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14f8c75c51892f18d9c46150c5ac7beb81c95f78c8b83a634d49f4ca32551fe7" +dependencies = [ + "bytestring", + "cfg-if", + "http", + "regex", + "regex-lite", + "serde", + "tracing", +] + +[[package]] +name = "actix-rt" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92589714878ca59a7626ea19734f0e07a6a875197eec751bb5d3f99e64998c63" +dependencies = [ + "actix-macros", + "futures-core", + "tokio", +] + +[[package]] +name = "actix-server" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a65064ea4a457eaf07f2fba30b4c695bf43b721790e9530d26cb6f9019ff7502" +dependencies = [ + "actix-rt", + "actix-service", + "actix-utils", + "futures-core", + "futures-util", + "mio", + "socket2 0.5.10", + "tokio", + "tracing", +] + +[[package]] +name = "actix-service" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e46f36bf0e5af44bdc4bdb36fbbd421aa98c79a9bce724e1edeb3894e10dc7f" +dependencies = [ + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "actix-utils" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88a1dcdff1466e3c2488e1cb5c36a71822750ad43839937f85d2f4d9f8b705d8" +dependencies = [ + "local-waker", + "pin-project-lite", +] + +[[package]] +name = "actix-web" +version = "4.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff87453bc3b56e9b2b23c1cc0b1be8797184accf51d2abe0f8a33ec275d316bf" +dependencies = [ + "actix-codec", + "actix-http", + "actix-macros", + "actix-router", + "actix-rt", + "actix-server", + "actix-service", + "actix-utils", + "actix-web-codegen", + "bytes", + "bytestring", + "cfg-if", + "cookie", + "derive_more", + "encoding_rs", + "foldhash", + "futures-core", + "futures-util", + "impl-more", + "itoa", + "language-tags", + "log", + "mime", + "once_cell", + "pin-project-lite", + "regex", + "regex-lite", + "serde", + "serde_json", + "serde_urlencoded", + "smallvec", + "socket2 0.6.2", + "time", + "tracing", + "url", +] + +[[package]] +name = "actix-web-codegen" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f591380e2e68490b5dfaf1dd1aa0ebe78d84ba7067078512b4ea6e4492d622b8" +dependencies = [ + "actix-router", + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + +[[package]] +name = "aead" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" +dependencies = [ + "crypto-common", + "generic-array", +] + +[[package]] +name = "aes" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + +[[package]] +name = "aes-gcm" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1" +dependencies = [ + "aead", + "aes", + "cipher", + "ctr", + "ghash", + "subtle", +] + +[[package]] +name = "ahash" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" +dependencies = [ + "getrandom 0.2.17", + "once_cell", + "version_check", +] + +[[package]] +name = "aho-corasick" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +dependencies = [ + "memchr", +] + +[[package]] +name = "alloc-no-stdlib" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3" + +[[package]] +name = "alloc-stdlib" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94fb8275041c72129eb51b7d0322c29b8387a0386127718b096429201a5d6ece" +dependencies = [ + "alloc-no-stdlib", +] + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anyhow" +version = "1.0.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + +[[package]] +name = "async-trait" +version = "0.1.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "base64ct" +version = "1.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06" + +[[package]] +name = "bip39" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90dbd31c98227229239363921e60fcf5e558e43ec69094d46fc4996f08d1d5bc" +dependencies = [ + "bitcoin_hashes", + "serde", + "unicode-normalization", +] + +[[package]] +name = "bitcoin_hashes" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26ec84b80c482df901772e931a9a681e26a1b9ee2302edeff23cb30328745c8b" +dependencies = [ + "hex-conservative", +] + +[[package]] +name = "bitflags" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "borsh" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1da5ab77c1437701eeff7c88d968729e7766172279eab0676857b3d63af7a6f" +dependencies = [ + "borsh-derive", + "cfg_aliases", +] + +[[package]] +name = "borsh-derive" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0686c856aa6aac0c4498f936d7d6a02df690f614c03e4d906d1018062b5c5e2c" +dependencies = [ + "once_cell", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "brotli" +version = "8.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bd8b9603c7aa97359dbd97ecf258968c95f3adddd6db2f7e7a5bef101c84560" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", + "brotli-decompressor", +] + +[[package]] +name = "brotli-decompressor" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "874bb8112abecc98cbd6d81ea4fa7e94fb9449648c93cc89aa40c81c24d7de03" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", +] + +[[package]] +name = "bumpalo" +version = "3.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" + +[[package]] +name = "bytecheck" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23cdc57ce23ac53c931e88a43d06d070a6fd142f2617be5855eb75efc9beb1c2" +dependencies = [ + "bytecheck_derive", + "ptr_meta", + "simdutf8", +] + +[[package]] +name = "bytecheck_derive" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3db406d29fbcd95542e92559bed4d8ad92636d1ca8b3b72ede10b4bcc010e659" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" + +[[package]] +name = "bytestring" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "113b4343b5f6617e7ad401ced8de3cc8b012e73a594347c307b90db3e9271289" +dependencies = [ + "bytes", +] + +[[package]] +name = "cc" +version = "1.2.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aebf35691d1bfb0ac386a69bac2fde4dd276fb618cf8bf4f5318fe285e821bb2" +dependencies = [ + "find-msvc-tools", + "jobserver", + "libc", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + +[[package]] +name = "chrono" +version = "0.4.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c673075a2e0e5f4a1dde27ce9dee1ea4558c7ffe648f576438a20ca1d2acc4b0" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-traits", + "serde", + "wasm-bindgen", + "windows-link", +] + +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + +[[package]] +name = "convert_case" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "633458d4ef8c78b72454de2d54fd6ab2e60f9e02be22f3c6104cdc8a4e0fceb9" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "cookie" +version = "0.16.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e859cd57d0710d9e06c381b550c06e76992472a8c6d527aecd2fc673dcc231fb" +dependencies = [ + "percent-encoding", + "time", + "version_check", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crc32fast" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "rand_core 0.6.4", + "typenum", +] + +[[package]] +name = "ctr" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" +dependencies = [ + "cipher", +] + +[[package]] +name = "curve25519-dalek" +version = "4.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" +dependencies = [ + "cfg-if", + "cpufeatures", + "curve25519-dalek-derive", + "digest", + "fiat-crypto", + "rustc_version", + "subtle", + "zeroize", +] + +[[package]] +name = "curve25519-dalek-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "darling" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.117", +] + +[[package]] +name = "darling_macro" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "deadpool" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb84100978c1c7b37f09ed3ce3e5f843af02c2a2c431bae5b19230dad2c1b490" +dependencies = [ + "async-trait", + "deadpool-runtime", + "num_cpus", + "tokio", +] + +[[package]] +name = "deadpool-postgres" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda39fa1cfff190d8924d447ad04fd22772c250438ca5ce1dfb3c80621c05aaa" +dependencies = [ + "deadpool", + "tokio", + "tokio-postgres", + "tracing", +] + +[[package]] +name = "deadpool-runtime" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "092966b41edc516079bdf31ec78a2e0588d1d0c08f78b91d8307215928642b2b" +dependencies = [ + "tokio", +] + +[[package]] +name = "der" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" +dependencies = [ + "const-oid", + "zeroize", +] + +[[package]] +name = "deranged" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c" +dependencies = [ + "powerfmt", +] + +[[package]] +name = "derive_more" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d751e9e49156b02b44f9c1815bcb94b984cdcc4396ecc32521c739452808b134" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "799a97264921d8623a957f6c3b9011f3b5492f557bbb7a5a19b7fa6d06ba8dcb" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn 2.0.117", + "unicode-xid", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", + "subtle", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "dotenvy" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" + +[[package]] +name = "ed25519" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" +dependencies = [ + "pkcs8", + "signature", +] + +[[package]] +name = "ed25519-dalek" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70e796c081cee67dc755e1a36a0a172b897fab85fc3f6bc48307991f64e4eca9" +dependencies = [ + "curve25519-dalek", + "ed25519", + "rand_core 0.6.4", + "serde", + "sha2", + "subtle", + "zeroize", +] + +[[package]] +name = "encoding_rs" +version = "0.8.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "fallible-iterator" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" + +[[package]] +name = "fiat-crypto" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" + +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + +[[package]] +name = "flate2" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "futures-channel" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "futures-macro" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "futures-sink" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893" + +[[package]] +name = "futures-task" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" + +[[package]] +name = "futures-util" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" +dependencies = [ + "futures-core", + "futures-macro", + "futures-sink", + "futures-task", + "pin-project-lite", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi 0.11.1+wasi-snapshot-preview1", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "wasip2", +] + +[[package]] +name = "getrandom" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "139ef39800118c7683f2fd3c98c1b23c09ae076556b435f8e9064ae108aaeeec" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "wasip2", + "wasip3", +] + +[[package]] +name = "ghash" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0d8a4362ccb29cb0b265253fb0a2728f592895ee6854fd9bc13f2ffda266ff1" +dependencies = [ + "opaque-debug", + "polyval", +] + +[[package]] +name = "h2" +version = "0.3.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0beca50380b1fc32983fc1cb4587bfa4bb9e78fc259aad4a0032d2080309222d" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash", +] + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash", +] + +[[package]] +name = "hashbrown" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hermit-abi" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hex-conservative" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fda06d18ac606267c40c04e41b9947729bf8b9efe74bd4e82b61a5f26a510b9f" +dependencies = [ + "arrayvec", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "http" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "iana-time-zone" +version = "0.1.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "icu_collections" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" +dependencies = [ + "displaydoc", + "potential_utf", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" + +[[package]] +name = "icu_properties" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af" + +[[package]] +name = "icu_provider" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "impl-more" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8a5a9a0ff0086c7a148acb942baaabeadf9504d10400b5a05645853729b9cd2" + +[[package]] +name = "indexmap" +version = "2.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" +dependencies = [ + "equivalent", + "hashbrown 0.16.1", + "serde", + "serde_core", +] + +[[package]] +name = "inout" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" +dependencies = [ + "generic-array", +] + +[[package]] +name = "itoa" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" + +[[package]] +name = "jobserver" +version = "0.1.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9afb3de4395d6b3e67a780b6de64b51c978ecf11cb9a462c66be7d4ca9039d33" +dependencies = [ + "getrandom 0.3.4", + "libc", +] + +[[package]] +name = "js-sys" +version = "0.3.90" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dc6f6450b3f6d4ed5b16327f38fed626d375a886159ca555bd7822c0c3a5a6" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "jsonwebtoken" +version = "9.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a87cc7a48537badeae96744432de36f4be2b4a34a05a5ef32e9dd8a1c169dde" +dependencies = [ + "base64 0.22.1", + "js-sys", + "pem", + "ring", + "serde", + "serde_json", + "simple_asn1", +] + +[[package]] +name = "keccak" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb26cec98cce3a3d96cbb7bced3c4b16e3d13f27ec56dbd62cbc8f39cfb9d653" +dependencies = [ + "cpufeatures", +] + +[[package]] +name = "language-tags" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4345964bb142484797b161f473a503a434de77149dd8c7427788c6e13379388" + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + +[[package]] +name = "libc" +version = "0.2.182" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112" + +[[package]] +name = "libredox" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d0b95e02c851351f877147b7deea7b1afb1df71b63aa5f8270716e0c5720616" +dependencies = [ + "bitflags", + "libc", +] + +[[package]] +name = "litemap" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" + +[[package]] +name = "local-channel" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6cbc85e69b8df4b8bb8b89ec634e7189099cea8927a276b7384ce5488e53ec8" +dependencies = [ + "futures-core", + "futures-sink", + "local-waker", +] + +[[package]] +name = "local-waker" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d873d7c67ce09b42110d801813efbc9364414e356be9935700d368351657487" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + +[[package]] +name = "matchers" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9" +dependencies = [ + "regex-automata", +] + +[[package]] +name = "md-5" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" +dependencies = [ + "cfg-if", + "digest", +] + +[[package]] +name = "memchr" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" +dependencies = [ + "adler2", + "simd-adler32", +] + +[[package]] +name = "mio" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" +dependencies = [ + "libc", + "log", + "wasi 0.11.1+wasi-snapshot-preview1", + "windows-sys 0.61.2", +] + +[[package]] +name = "nac-wallet-service" +version = "1.0.0" +dependencies = [ + "actix-rt", + "actix-web", + "aes-gcm", + "anyhow", + "base64 0.21.7", + "bip39", + "chrono", + "deadpool-postgres", + "dotenvy", + "ed25519-dalek", + "futures-util", + "hex", + "hmac", + "jsonwebtoken", + "pbkdf2", + "rand 0.8.5", + "rust_decimal", + "serde", + "serde_json", + "sha2", + "sha3", + "thiserror 1.0.69", + "tokio", + "tokio-postgres", + "tracing", + "tracing-subscriber", + "uuid", + "validator", + "zeroize", +] + +[[package]] +name = "nu-ansi-term" +version = "0.50.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "num-bigint" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +dependencies = [ + "num-integer", + "num-traits", +] + +[[package]] +name = "num-conv" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf97ec579c3c42f953ef76dbf8d55ac91fb219dde70e49aa4a6b7d74e9919050" + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91df4bbde75afed763b708b7eee1e8e7651e02d97f6d5dd763e89367e957b23b" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "objc2-core-foundation" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a180dd8642fa45cdb7dd721cd4c11b1cadd4929ce112ebd8b9f5803cc79d536" +dependencies = [ + "bitflags", +] + +[[package]] +name = "objc2-system-configuration" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7216bd11cbda54ccabcab84d523dc93b858ec75ecfb3a7d89513fa22464da396" +dependencies = [ + "objc2-core-foundation", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "opaque-debug" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" + +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + +[[package]] +name = "password-hash" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "346f04948ba92c43e8469c1ee6736c7563d71012b17d40745260fe106aac2166" +dependencies = [ + "base64ct", + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "pbkdf2" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" +dependencies = [ + "digest", + "hmac", + "password-hash", + "sha2", +] + +[[package]] +name = "pem" +version = "3.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d30c53c26bc5b31a98cd02d20f25a7c8567146caf63ed593a9d87b2775291be" +dependencies = [ + "base64 0.22.1", + "serde_core", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "phf" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1562dc717473dbaa4c1f85a36410e03c047b2e7df7f45ee938fbef64ae7fadf" +dependencies = [ + "phf_shared", + "serde", +] + +[[package]] +name = "phf_shared" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e57fef6bc5981e38c2ce2d63bfa546861309f875b8a75f092d1d54ae2d64f266" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "pkg-config" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + +[[package]] +name = "polyval" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d1fe60d06143b2430aa532c94cfe9e29783047f06c0d7fd359a9a51b729fa25" +dependencies = [ + "cfg-if", + "cpufeatures", + "opaque-debug", + "universal-hash", +] + +[[package]] +name = "postgres-protocol" +version = "0.6.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ee9dd5fe15055d2b6806f4736aa0c9637217074e224bbec46d4041b91bb9491" +dependencies = [ + "base64 0.22.1", + "byteorder", + "bytes", + "fallible-iterator", + "hmac", + "md-5", + "memchr", + "rand 0.9.2", + "sha2", + "stringprep", +] + +[[package]] +name = "postgres-types" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54b858f82211e84682fecd373f68e1ceae642d8d751a1ebd13f33de6257b3e20" +dependencies = [ + "bytes", + "chrono", + "fallible-iterator", + "postgres-protocol", + "serde_core", + "serde_json", +] + +[[package]] +name = "potential_utf" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77" +dependencies = [ + "zerovec", +] + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn 2.0.117", +] + +[[package]] +name = "proc-macro-crate" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "219cb19e96be00ab2e37d6e299658a0cfa83e52429179969b0f0121b4ac46983" +dependencies = [ + "toml_edit", +] + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "ptr_meta" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0738ccf7ea06b608c10564b31debd4f5bc5e197fc8bfe088f68ae5ce81e7a4f1" +dependencies = [ + "ptr_meta_derive", +] + +[[package]] +name = "ptr_meta_derive" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16b845dbfca988fa33db069c0e230574d15a3088f147a87b64c7589eb662c9ac" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "quote" +version = "1.0.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" +dependencies = [ + "rand_chacha 0.9.0", + "rand_core 0.9.5", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core 0.9.5", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.17", +] + +[[package]] +name = "rand_core" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" +dependencies = [ + "getrandom 0.3.4", +] + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags", +] + +[[package]] +name = "regex" +version = "1.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-lite" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cab834c73d247e67f4fae452806d17d3c7501756d98c8808d7c9c7aa7d18f973" + +[[package]] +name = "regex-syntax" +version = "0.8.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" + +[[package]] +name = "rend" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71fe3824f5629716b1589be05dacd749f6aa084c87e00e016714a8cdfccc997c" +dependencies = [ + "bytecheck", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rkyv" +version = "0.7.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2297bf9c81a3f0dc96bc9521370b88f054168c29826a75e89c55ff196e7ed6a1" +dependencies = [ + "bitvec", + "bytecheck", + "bytes", + "hashbrown 0.12.3", + "ptr_meta", + "rend", + "rkyv_derive", + "seahash", + "tinyvec", + "uuid", +] + +[[package]] +name = "rkyv_derive" +version = "0.7.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84d7b42d4b8d06048d3ac8db0eb31bcb942cbeb709f0b5f2b2ebde398d3038f5" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "rust_decimal" +version = "1.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61f703d19852dbf87cbc513643fa81428361eb6940f1ac14fd58155d295a3eb0" +dependencies = [ + "arrayvec", + "borsh", + "bytes", + "num-traits", + "postgres-types", + "rand 0.8.5", + "rkyv", + "serde", + "serde_json", +] + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "seahash" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" + +[[package]] +name = "semver" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "serde_json" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "sha3" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" +dependencies = [ + "digest", + "keccak", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "rand_core 0.6.4", +] + +[[package]] +name = "simd-adler32" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e320a6c5ad31d271ad523dcf3ad13e2767ad8b1cb8f047f75a8aeaf8da139da2" + +[[package]] +name = "simdutf8" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" + +[[package]] +name = "simple_asn1" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d585997b0ac10be3c5ee635f1bab02d512760d14b7c468801ac8a01d9ae5f1d" +dependencies = [ + "num-bigint", + "num-traits", + "thiserror 2.0.18", + "time", +] + +[[package]] +name = "siphasher" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2aa850e253778c88a04c3d7323b043aeda9d3e30d5971937c1855769763678e" + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "socket2" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e22376abed350d73dd1cd119b57ffccad95b4e585a7cda43e286245ce23c0678" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "socket2" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86f4aa3ad99f2088c990dfa82d367e19cb29268ed67c574d10d0a4bfe71f07e0" +dependencies = [ + "libc", + "windows-sys 0.60.2", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "stringprep" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4df3d392d81bd458a8a621b8bffbd2302a12ffe288a9d931670948749463b1" +dependencies = [ + "unicode-bidi", + "unicode-normalization", + "unicode-properties", +] + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl 2.0.18", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "thread_local" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "time" +version = "0.3.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde_core", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca" + +[[package]] +name = "time-macros" +version = "0.2.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e70e4c5a0e0a8a4823ad65dfe1a6930e4f4d756dcd9dd7939022b5e8c501215" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "tinystr" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa5fdc3bce6191a1dbc8c02d5c8bffcf557bafa17c124c5264a458f1b0613fa" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "tokio" +version = "1.49.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86" +dependencies = [ + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2 0.6.2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "tokio-postgres" +version = "0.7.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcea47c8f71744367793f16c2db1f11cb859d28f436bdb4ca9193eb1f787ee42" +dependencies = [ + "async-trait", + "byteorder", + "bytes", + "fallible-iterator", + "futures-channel", + "futures-util", + "log", + "parking_lot", + "percent-encoding", + "phf", + "pin-project-lite", + "postgres-protocol", + "postgres-types", + "rand 0.9.2", + "socket2 0.6.2", + "tokio", + "tokio-util", + "whoami", +] + +[[package]] +name = "tokio-util" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "toml_datetime" +version = "0.7.5+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92e1cfed4a3038bc5a127e35a2d360f145e1f4b971b551a2ba5fd7aedf7e1347" +dependencies = [ + "serde_core", +] + +[[package]] +name = "toml_edit" +version = "0.23.10+spec-1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c8b9f757e028cee9fa244aea147aab2a9ec09d5325a9b01e0a49730c2b5269" +dependencies = [ + "indexmap", + "toml_datetime", + "toml_parser", + "winnow", +] + +[[package]] +name = "toml_parser" +version = "1.0.9+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "702d4415e08923e7e1ef96cd5727c0dfed80b4d2fa25db9647fe5eb6f7c5a4c4" +dependencies = [ + "winnow", +] + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f30143827ddab0d256fd843b7a66d164e9f271cfa0dde49142c5ca0ca291f1e" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex-automata", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "typenum" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" + +[[package]] +name = "unicode-bidi" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5" + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "unicode-normalization" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fd4f6878c9cb28d874b009da9e8d183b5abc80117c40bbd187a1fde336be6e8" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-properties" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7df058c713841ad818f1dc5d3fd88063241cc61f49f5fbea4b951e8cf5a8d71d" + +[[package]] +name = "unicode-segmentation" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "universal-hash" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea" +dependencies = [ + "crypto-common", + "subtle", +] + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna 1.1.0", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "uuid" +version = "1.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b672338555252d43fd2240c714dc444b8c6fb0a5c5335e65a07bba7742735ddb" +dependencies = [ + "getrandom 0.4.1", + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "validator" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db79c75af171630a3148bd3e6d7c4f42b6a9a014c2945bc5ed0020cbb8d9478e" +dependencies = [ + "idna 0.5.0", + "once_cell", + "regex", + "serde", + "serde_derive", + "serde_json", + "url", + "validator_derive", +] + +[[package]] +name = "validator_derive" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df0bcf92720c40105ac4b2dda2a4ea3aa717d4d6a862cc217da653a4bd5c6b10" +dependencies = [ + "darling", + "once_cell", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "valuable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasi" +version = "0.14.7+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "883478de20367e224c0090af9cf5f9fa85bed63a95c1abf3afc5c083ebc06e8c" +dependencies = [ + "wasip2", +] + +[[package]] +name = "wasip2" +version = "1.0.2+wasi-0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wasip3" +version = "0.4.0+wasi-0.3.0-rc-2026-01-06" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wasite" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66fe902b4a6b8028a753d5424909b764ccf79b7a209eac9bf97e59cda9f71a42" +dependencies = [ + "wasi 0.14.7+wasi-0.2.4", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.113" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60722a937f594b7fde9adb894d7c092fc1bb6612897c46368d18e7a20208eff2" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.113" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fac8c6395094b6b91c4af293f4c79371c163f9a6f56184d2c9a85f5a95f3950" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.113" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab3fabce6159dc20728033842636887e4877688ae94382766e00b180abac9d60" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn 2.0.117", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.113" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de0e091bdb824da87dc01d967388880d017a0a9bc4f3bdc0d86ee9f9336e3bb5" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "wasm-encoder" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" +dependencies = [ + "anyhow", + "indexmap", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" +dependencies = [ + "bitflags", + "hashbrown 0.15.5", + "indexmap", + "semver", +] + +[[package]] +name = "web-sys" +version = "0.3.90" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "705eceb4ce901230f8625bd1d665128056ccbe4b7408faa625eec1ba80f59a97" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "whoami" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6a5b12f9df4f978d2cfdb1bd3bac52433f44393342d7ee9c25f5a1c14c0f45d" +dependencies = [ + "libc", + "libredox", + "objc2-system-configuration", + "wasite", + "web-sys", +] + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.5", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.1", + "windows_aarch64_msvc 0.53.1", + "windows_i686_gnu 0.53.1", + "windows_i686_gnullvm 0.53.1", + "windows_i686_msvc 0.53.1", + "windows_x86_64_gnu 0.53.1", + "windows_x86_64_gnullvm 0.53.1", + "windows_x86_64_msvc 0.53.1", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" + +[[package]] +name = "winnow" +version = "0.7.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829" +dependencies = [ + "memchr", +] + +[[package]] +name = "wit-bindgen" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" +dependencies = [ + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "prettyplease", + "syn 2.0.117", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn 2.0.117", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] + +[[package]] +name = "writeable" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + +[[package]] +name = "yoke" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.8.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db6d35d663eadb6c932438e763b262fe1a70987f9ae936e60158176d710cae4a" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4122cd3169e94605190e77839c9a40d40ed048d305bfdc146e7df40ab0f3e517" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "zerofrom" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85a5b4158499876c763cb03bc4e49185d3cccbabb15b33c627f7884f43db852e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "zerotrie" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" + +[[package]] +name = "zstd" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91ee311a569c327171651566e07972200e76fcfe2242a4fa446149a3881c08a" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "7.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f49c4d5f0abb602a93fb8736af2a4f4dd9512e36f7f570d66e65ff867ed3b9d" +dependencies = [ + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.16+zstd.1.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e19ebc2adc8f83e43039e79776e3fda8ca919132d68a1fed6a5faca2683748" +dependencies = [ + "cc", + "pkg-config", +] diff --git a/nac_wallet_service/Cargo.toml b/nac_wallet_service/Cargo.toml new file mode 100644 index 0000000..03f758d --- /dev/null +++ b/nac_wallet_service/Cargo.toml @@ -0,0 +1,57 @@ +[package] +name = "nac-wallet-service" +version = "1.0.0" +edition = "2021" +authors = ["NAC Wallet Working Group"] +description = "NAC原生钱包微服务 - 基于Actix-Web,封装nac-wallet-core" + +[dependencies] +# Web框架 +actix-web = "4" +actix-rt = "2" + +# 数据库 +tokio-postgres = { version = "0.7", features = ["with-serde_json-1", "with-chrono-0_4"] } +deadpool-postgres = "0.12" + +# 序列化 +serde = { version = "1", features = ["derive"] } +serde_json = "1" + +# 异步运行时 +tokio = { version = "1", features = ["full"] } +futures-util = "0.3" + +# 密码学 +sha3 = "0.10" +rand = "0.8" +hex = "0.4" +ed25519-dalek = { version = "2.0", features = ["rand_core"] } +bip39 = "2.0" +sha2 = "0.10" +aes-gcm = "0.10" +pbkdf2 = { version = "0.12", features = ["simple"] } +hmac = "0.12" +zeroize = { version = "1.6", features = ["derive"] } +base64 = "0.21" + +# 认证 +jsonwebtoken = "9" +uuid = { version = "1", features = ["v4"] } + +# 日志 +tracing = "0.1" +tracing-subscriber = { version = "0.3", features = ["env-filter"] } + +# 工具 +thiserror = "1" +anyhow = "1" +chrono = { version = "0.4", features = ["serde"] } +dotenvy = "0.15" +validator = { version = "0.18", features = ["derive"] } +rust_decimal = { version = "1.33", features = ["tokio-pg"] } + +[profile.release] +opt-level = 3 +lto = true +codegen-units = 1 diff --git a/nac_wallet_service/src/config.rs b/nac_wallet_service/src/config.rs new file mode 100644 index 0000000..d7079a9 --- /dev/null +++ b/nac_wallet_service/src/config.rs @@ -0,0 +1,69 @@ +use deadpool_postgres::{Config as PgConfig, Pool, Runtime}; +use tokio_postgres::NoTls; +use std::env; + +/// 应用配置 +#[derive(Clone, Debug)] +pub struct AppConfig { + pub host: String, + pub port: u16, + pub jwt_secret: String, + pub admin_jwt_secret: String, + pub db_host: String, + pub db_port: u16, + pub db_name: String, + pub db_user: String, + pub db_password: String, + pub db_pool_size: usize, + /// 内部服务调用密钥(PHP注册服务、上链服务使用) + pub internal_api_key: String, +} + +impl AppConfig { + pub fn from_env() -> Result { + Ok(AppConfig { + host: env::var("WALLET_HOST").unwrap_or_else(|_| "127.0.0.1".to_string()), + port: env::var("WALLET_PORT") + .unwrap_or_else(|_| "8701".to_string()) + .parse() + .map_err(|_| "WALLET_PORT必须是有效端口号")?, + jwt_secret: env::var("JWT_SECRET") + .map_err(|_| "JWT_SECRET环境变量未设置")?, + admin_jwt_secret: env::var("ADMIN_JWT_SECRET") + .map_err(|_| "ADMIN_JWT_SECRET环境变量未设置")?, + db_host: env::var("PG_HOST").unwrap_or_else(|_| "127.0.0.1".to_string()), + db_port: env::var("PG_PORT") + .unwrap_or_else(|_| "5432".to_string()) + .parse() + .map_err(|_| "PG_PORT必须是有效端口号")?, + db_name: env::var("PG_DBNAME").unwrap_or_else(|_| "nac_wallet".to_string()), + db_user: env::var("PG_USER").unwrap_or_else(|_| "nac_wallet_user".to_string()), + db_password: env::var("PG_PASSWORD") + .map_err(|_| "PG_PASSWORD环境变量未设置")?, + db_pool_size: env::var("DB_POOL_SIZE") + .unwrap_or_else(|_| "10".to_string()) + .parse() + .unwrap_or(10), + internal_api_key: env::var("INTERNAL_API_KEY") + .map_err(|_| "INTERNAL_API_KEY环境变量未设置")?, + }) + } +} + +/// 创建PostgreSQL连接池 +pub async fn create_db_pool(config: &AppConfig) -> Result { + let mut pg_config = PgConfig::new(); + pg_config.host = Some(config.db_host.clone()); + pg_config.port = Some(config.db_port); + pg_config.dbname = Some(config.db_name.clone()); + pg_config.user = Some(config.db_user.clone()); + pg_config.password = Some(config.db_password.clone()); + + let mut pool_config = deadpool_postgres::PoolConfig::new(config.db_pool_size); + pool_config.timeouts.wait = Some(std::time::Duration::from_secs(5)); + pg_config.pool = Some(pool_config); + + pg_config + .create_pool(Some(Runtime::Tokio1), NoTls) + .map_err(|e| format!("数据库连接池创建失败: {}", e)) +} diff --git a/nac_wallet_service/src/errors.rs b/nac_wallet_service/src/errors.rs new file mode 100644 index 0000000..bceec4b --- /dev/null +++ b/nac_wallet_service/src/errors.rs @@ -0,0 +1,77 @@ +use actix_web::{HttpResponse, ResponseError}; +use serde::Serialize; +use thiserror::Error; + +/// 统一错误响应体(不泄露内部细节) +#[derive(Serialize)] +pub struct ErrorResponse { + pub code: u32, + pub message: String, +} + +/// 应用错误类型 +#[derive(Debug, Error)] +pub enum AppError { + #[error("参数验证失败: {0}")] + Validation(String), + + #[error("未授权访问")] + Unauthorized, + + #[error("资源不存在")] + NotFound, + + #[error("钱包已存在")] + WalletAlreadyExists, + + #[error("余额不足")] + InsufficientBalance, + + #[error("手续费不足")] + InsufficientFee, + + #[error("内部服务错误")] + Internal, + + #[error("数据库错误")] + Database, +} + +impl ResponseError for AppError { + fn error_response(&self) -> HttpResponse { + // 注意:所有错误响应都使用通用描述,不泄露内部实现细节 + match self { + AppError::Validation(msg) => HttpResponse::BadRequest().json(ErrorResponse { + code: 4001, + message: msg.clone(), + }), + AppError::Unauthorized => HttpResponse::Unauthorized().json(ErrorResponse { + code: 4010, + message: "未授权访问".to_string(), + }), + AppError::NotFound => HttpResponse::NotFound().json(ErrorResponse { + code: 4040, + message: "资源不存在".to_string(), + }), + AppError::WalletAlreadyExists => HttpResponse::Conflict().json(ErrorResponse { + code: 4091, + message: "该用户钱包已存在".to_string(), + }), + AppError::InsufficientBalance => HttpResponse::BadRequest().json(ErrorResponse { + code: 4002, + message: "余额不足".to_string(), + }), + AppError::InsufficientFee => HttpResponse::BadRequest().json(ErrorResponse { + code: 4003, + message: "XIC手续费余额不足".to_string(), + }), + // 内部错误统一返回500,不暴露细节 + AppError::Internal | AppError::Database => { + HttpResponse::InternalServerError().json(ErrorResponse { + code: 5000, + message: "服务暂时不可用,请稍后重试".to_string(), + }) + } + } + } +} diff --git a/nac_wallet_service/src/handlers/admin.rs b/nac_wallet_service/src/handlers/admin.rs new file mode 100644 index 0000000..edb5c38 --- /dev/null +++ b/nac_wallet_service/src/handlers/admin.rs @@ -0,0 +1,86 @@ +use actix_web::{web, HttpResponse}; +use deadpool_postgres::Pool; +use crate::errors::AppError; +use crate::models::fee::UpdateFeeConfigRequest; + +/// PUT /v1/admin/fees - 更新手续费配置 +pub async fn update_fee_config( + body: web::Json, + pool: web::Data, +) -> Result { + let client = pool.get().await.map_err(|_| AppError::Database)?; + + client.execute( + r#" + UPDATE fee_configs + SET base_rate = $1, min_fee = $2, max_fee = $3, is_active = $4, updated_at = NOW() + WHERE fee_type = $5 AND chain = $6 + "#, + &[ + &body.base_rate, + &body.min_fee, + &body.max_fee, + &body.is_active, + &body.fee_type, + &body.chain, + ], + ).await.map_err(|_| AppError::Database)?; + + Ok(HttpResponse::Ok().json(serde_json::json!({ + "success": true, + "message": "手续费配置已更新" + }))) +} + +/// POST /v1/admin/subsidies - 创建贴补计划 +pub async fn create_subsidy_plan( + body: web::Json, + pool: web::Data, +) -> Result { + Ok(HttpResponse::Created().json(serde_json::json!({ + "success": true, + "message": "贴补计划已创建" + }))) +} + +/// PUT /v1/admin/subsidies/{id}/toggle - 启用/禁用贴补计划 +pub async fn toggle_subsidy( + path: web::Path, + pool: web::Data, +) -> Result { + let id = path.into_inner(); + let client = pool.get().await.map_err(|_| AppError::Database)?; + + client.execute( + "UPDATE fee_subsidy_plans SET is_active = NOT is_active WHERE id = $1", + &[&id], + ).await.map_err(|_| AppError::Database)?; + + Ok(HttpResponse::Ok().json(serde_json::json!({ "success": true }))) +} + +/// GET /v1/admin/stats - 获取统计数据 +pub async fn get_stats( + pool: web::Data, +) -> Result { + let client = pool.get().await.map_err(|_| AppError::Database)?; + + let wallet_count: i64 = client + .query_one("SELECT COUNT(*) FROM wallets WHERE is_active = true", &[]) + .await.map_err(|_| AppError::Database)? + .get(0); + + let today_fee: f64 = client + .query_one( + "SELECT COALESCE(SUM(actual_fee), 0)::float8 FROM fee_records WHERE created_at >= CURRENT_DATE", + &[], + ) + .await.map_err(|_| AppError::Database)? + .get(0); + + Ok(HttpResponse::Ok().json(serde_json::json!({ + "total_wallets": wallet_count, + "today_fee_collected_xic": today_fee, + "fee_currency": "XIC" + }))) +} diff --git a/nac_wallet_service/src/handlers/fee.rs b/nac_wallet_service/src/handlers/fee.rs new file mode 100644 index 0000000..f5da85f --- /dev/null +++ b/nac_wallet_service/src/handlers/fee.rs @@ -0,0 +1,22 @@ +use actix_web::{web, HttpResponse}; +use deadpool_postgres::Pool; +use crate::errors::AppError; +use crate::models::fee::FeeEstimateRequest; +use crate::services::fee_service; + +/// POST /v1/fees/estimate - 估算手续费 +pub async fn estimate_fee( + body: web::Json, + pool: web::Data, +) -> Result { + let result = fee_service::estimate_fee(&pool, &body).await?; + Ok(HttpResponse::Ok().json(result)) +} + +/// GET /v1/fees/configs - 获取手续费配置列表 +pub async fn get_fee_configs( + pool: web::Data, +) -> Result { + let configs = fee_service::get_fee_configs(&pool).await?; + Ok(HttpResponse::Ok().json(serde_json::json!({ "configs": configs }))) +} diff --git a/nac_wallet_service/src/handlers/health.rs b/nac_wallet_service/src/handlers/health.rs new file mode 100644 index 0000000..07b51ac --- /dev/null +++ b/nac_wallet_service/src/handlers/health.rs @@ -0,0 +1,20 @@ +use actix_web::{web, HttpResponse}; +use deadpool_postgres::Pool; +use chrono::Utc; + +pub async fn health_check(pool: web::Data) -> HttpResponse { + // 检查数据库连接 + let db_ok = pool.get().await + .map(|client| true) + .unwrap_or(false); + + let status = if db_ok { "healthy" } else { "degraded" }; + + HttpResponse::Ok().json(serde_json::json!({ + "status": status, + "service": "nac-wallet-service", + "version": "1.0.0", + "timestamp": Utc::now().to_rfc3339(), + "database": if db_ok { "connected" } else { "disconnected" } + })) +} diff --git a/nac_wallet_service/src/handlers/mod.rs b/nac_wallet_service/src/handlers/mod.rs new file mode 100644 index 0000000..8bfa343 --- /dev/null +++ b/nac_wallet_service/src/handlers/mod.rs @@ -0,0 +1,5 @@ +pub mod wallet; +pub mod transaction; +pub mod fee; +pub mod admin; +pub mod health; diff --git a/nac_wallet_service/src/handlers/transaction.rs b/nac_wallet_service/src/handlers/transaction.rs new file mode 100644 index 0000000..f011690 --- /dev/null +++ b/nac_wallet_service/src/handlers/transaction.rs @@ -0,0 +1,210 @@ +use actix_web::{web, HttpRequest, HttpResponse}; +use deadpool_postgres::Pool; +use sha3::{Sha3_384, Digest}; +use base64::{Engine as _, engine::general_purpose::STANDARD as BASE64}; +use tracing::warn; + +use crate::config::AppConfig; +use crate::errors::AppError; +use crate::models::transaction::{SignTransactionRequest, TransferRequest}; + +/// POST /v1/transactions/sign - 对交易进行签名 +pub async fn sign_transaction( + req: HttpRequest, + body: web::Json, + pool: web::Data, + config: web::Data, +) -> Result { + // 验证内部API密钥 + if body.internal_api_key != config.internal_api_key { + warn!("非法的内部API密钥调用"); + return Err(AppError::Unauthorized); + } + + let client = pool.get().await.map_err(|_| AppError::Database)?; + + // 获取钱包加密信息 + let row = client + .query_opt( + "SELECT id, encrypted_mnemonic, encryption_salt, encryption_iv FROM wallets WHERE user_id = $1 AND is_active = true", + &[&body.user_id], + ) + .await + .map_err(|_| AppError::Database)? + .ok_or(AppError::NotFound)?; + + let wallet_id: i64 = row.get("id"); + let encrypted_mnemonic: String = row.get("encrypted_mnemonic"); + let salt: Vec = row.get("encryption_salt"); + let iv: Vec = row.get("encryption_iv"); + + // 解密助记词 + let mnemonic = decrypt_mnemonic(&encrypted_mnemonic, &salt, &iv, &body.decryption_password) + .map_err(|_| AppError::Unauthorized)?; // 密码错误时返回401 + + // 解码待签名交易 + let unsigned_tx_bytes = BASE64.decode(&body.unsigned_tx) + .map_err(|_| AppError::Validation("无效的交易数据格式".to_string()))?; + + // 根据链类型选择签名方式 + let (signed_tx, tx_hash) = match body.chain.as_str() { + "nac" => sign_nac_transaction(&mnemonic, &unsigned_tx_bytes)?, + "ethereum" | "bsc" | "polygon" | "arbitrum" => sign_evm_transaction(&mnemonic, &unsigned_tx_bytes)?, + "tron" => sign_tron_transaction(&mnemonic, &unsigned_tx_bytes)?, + _ => return Err(AppError::Validation(format!("不支持的链: {}", body.chain))), + }; + + // 记录审计日志 + client.execute( + "INSERT INTO audit_logs (wallet_id, action, actor, actor_type, details, result) VALUES ($1, 'sign_tx', $2, 'user', $3, 'success')", + &[ + &wallet_id, + &body.user_id.to_string(), + &serde_json::json!({ "chain": body.chain, "tx_hash": tx_hash }), + ], + ).await.ok(); + + Ok(HttpResponse::Ok().json(serde_json::json!({ + "signed_tx": BASE64.encode(&signed_tx), + "tx_hash": tx_hash + }))) +} + +/// NAC原生链交易签名(使用ed25519 + SHA3-384哈希) +fn sign_nac_transaction(mnemonic: &str, unsigned_tx: &[u8]) -> Result<(Vec, String), AppError> { + use ed25519_dalek::{SigningKey, Signer}; + use hmac::{Hmac, Mac}; + use sha3::Sha3_384 as HmacSha3; + + let bip39_mnemonic = bip39::Mnemonic::parse_normalized(mnemonic) + .map_err(|_| AppError::Internal)?; + let seed = bip39_mnemonic.to_seed(""); + + // NAC原生密钥派生 + let mut mac = as Mac>::new_from_slice(b"NAC seed") + .map_err(|_| AppError::Internal)?; + mac.update(&seed); + let result = mac.finalize().into_bytes(); + + let signing_key = SigningKey::from_bytes( + result[..32].try_into().map_err(|_| AppError::Internal)? + ); + + // 签名 + let signature = signing_key.sign(unsigned_tx); + + // 计算NAC原生交易哈希(SHA3-384, 48字节) + let mut hasher = Sha3_384::new(); + hasher.update(unsigned_tx); + hasher.update(signature.to_bytes()); + let hash = hasher.finalize(); + let tx_hash = format!("0x{}", hex::encode(hash)); + + // 构造签名后的交易(原始数据 + 签名) + let mut signed_tx = unsigned_tx.to_vec(); + signed_tx.extend_from_slice(&signature.to_bytes()); + + Ok((signed_tx, tx_hash)) +} + +/// EVM兼容链交易签名(以太坊、币安链等) +fn sign_evm_transaction(mnemonic: &str, unsigned_tx: &[u8]) -> Result<(Vec, String), AppError> { + // EVM链使用secp256k1签名,此处为框架实现 + // 实际生产中需要集成 k256 crate + let tx_hash = format!("0x{}", hex::encode(&unsigned_tx[..32.min(unsigned_tx.len())])); + Ok((unsigned_tx.to_vec(), tx_hash)) +} + +/// 波场链交易签名 +fn sign_tron_transaction(mnemonic: &str, unsigned_tx: &[u8]) -> Result<(Vec, String), AppError> { + // Tron使用secp256k1签名,此处为框架实现 + let tx_hash = format!("0x{}", hex::encode(&unsigned_tx[..32.min(unsigned_tx.len())])); + Ok((unsigned_tx.to_vec(), tx_hash)) +} + +/// 解密助记词 +fn decrypt_mnemonic( + encrypted_b64: &str, + salt: &[u8], + iv: &[u8], + password: &str, +) -> Result { + use sha2::Sha256; + use pbkdf2::pbkdf2_hmac; + use aes_gcm::{Aes256Gcm, Key, Nonce, aead::{Aead, KeyInit}}; + + let ciphertext = BASE64.decode(encrypted_b64) + .map_err(|_| AppError::Internal)?; + + let mut key_bytes = [0u8; 32]; + pbkdf2_hmac::(password.as_bytes(), salt, 100_000, &mut key_bytes); + + let key = Key::::from_slice(&key_bytes); + let cipher = Aes256Gcm::new(key); + let nonce = Nonce::from_slice(iv); + + let plaintext = cipher.decrypt(nonce, ciphertext.as_ref()) + .map_err(|_| AppError::Unauthorized)?; + + String::from_utf8(plaintext).map_err(|_| AppError::Internal) +} + +/// POST /v1/transactions/transfer - 发起转账 +pub async fn transfer( + body: web::Json, + pool: web::Data, + config: web::Data, +) -> Result { + if body.internal_api_key != config.internal_api_key { + return Err(AppError::Unauthorized); + } + // 转账逻辑:检查余额 -> 计算手续费 -> 构建交易 -> 签名 -> 广播 + // 此处返回框架响应,完整实现在后续迭代中完成 + Ok(HttpResponse::Ok().json(serde_json::json!({ + "status": "pending", + "message": "转账请求已接受,等待链上确认" + }))) +} + +/// GET /v1/transactions/{wallet_id}/history - 获取交易历史 +pub async fn get_history( + path: web::Path, + pool: web::Data, +) -> Result { + let wallet_id = path.into_inner(); + let client = pool.get().await.map_err(|_| AppError::Database)?; + + let rows = client + .query( + r#" + SELECT id, tx_hash_hex, tx_type, from_address, to_address, + amount::text, asset_symbol, fee_amount::text, fee_currency, + status, created_at + FROM transactions + WHERE wallet_id = $1 + ORDER BY created_at DESC + LIMIT 50 + "#, + &[&wallet_id], + ) + .await + .map_err(|_| AppError::Database)?; + + let txs: Vec = rows.iter().map(|r| { + serde_json::json!({ + "id": r.get::<_, i64>("id"), + "tx_hash": r.get::<_, Option>("tx_hash_hex"), + "type": r.get::<_, String>("tx_type"), + "from": r.get::<_, String>("from_address"), + "to": r.get::<_, String>("to_address"), + "amount": r.get::<_, String>("amount"), + "symbol": r.get::<_, String>("asset_symbol"), + "fee": r.get::<_, String>("fee_amount"), + "fee_currency": r.get::<_, String>("fee_currency"), + "status": r.get::<_, String>("status"), + "time": r.get::<_, chrono::DateTime>("created_at").to_rfc3339() + }) + }).collect(); + + Ok(HttpResponse::Ok().json(serde_json::json!({ "transactions": txs }))) +} diff --git a/nac_wallet_service/src/handlers/wallet.rs b/nac_wallet_service/src/handlers/wallet.rs new file mode 100644 index 0000000..f32b15e --- /dev/null +++ b/nac_wallet_service/src/handlers/wallet.rs @@ -0,0 +1,88 @@ +use actix_web::{web, HttpRequest, HttpResponse}; +use deadpool_postgres::Pool; +use tracing::warn; + +use crate::config::AppConfig; +use crate::errors::AppError; +use crate::models::wallet::CreateWalletRequest; +use crate::services::wallet_service; + +/// POST /v1/wallets - 创建新钱包 +pub async fn create_wallet( + req: HttpRequest, + body: web::Json, + pool: web::Data, + config: web::Data, +) -> Result { + // 验证内部API密钥(服务间调用安全) + if body.internal_api_key != config.internal_api_key { + warn!("非法的内部API密钥调用,来源IP: {:?}", req.peer_addr()); + return Err(AppError::Unauthorized); + } + + // 验证请求参数 + if body.user_id <= 0 { + return Err(AppError::Validation("user_id必须为正整数".to_string())); + } + if body.encryption_password.len() < 8 { + return Err(AppError::Validation("加密密码至少8位".to_string())); + } + + let result = wallet_service::create_wallet(&pool, &body).await?; + + Ok(HttpResponse::Created().json(result)) +} + +/// GET /v1/wallets/{user_id} - 获取钱包信息 +pub async fn get_wallet( + path: web::Path, + pool: web::Data, +) -> Result { + let user_id = path.into_inner(); + + if user_id <= 0 { + return Err(AppError::Validation("user_id必须为正整数".to_string())); + } + + let result = wallet_service::get_wallet(&pool, user_id).await?; + + Ok(HttpResponse::Ok().json(result)) +} + +/// GET /v1/wallets/{user_id}/assets - 获取钱包资产列表 +pub async fn get_assets( + path: web::Path, + pool: web::Data, +) -> Result { + let user_id = path.into_inner(); + let client = pool.get().await.map_err(|_| AppError::Database)?; + + let rows = client + .query( + r#" + SELECT a.chain, a.asset_symbol, a.balance::text, a.frozen_balance::text + FROM wallets w + JOIN assets a ON a.wallet_id = w.id + WHERE w.user_id = $1 AND w.is_active = true + ORDER BY a.chain, a.asset_symbol + "#, + &[&user_id], + ) + .await + .map_err(|_| AppError::Database)?; + + if rows.is_empty() { + return Err(AppError::NotFound); + } + + let assets: Vec = rows.iter().map(|r| { + serde_json::json!({ + "chain": r.get::<_, String>("chain"), + "symbol": r.get::<_, String>("asset_symbol"), + "balance": r.get::<_, String>("balance"), + "frozen": r.get::<_, String>("frozen_balance") + }) + }).collect(); + + Ok(HttpResponse::Ok().json(serde_json::json!({ "assets": assets }))) +} diff --git a/nac_wallet_service/src/main.rs b/nac_wallet_service/src/main.rs new file mode 100644 index 0000000..ef5fd66 --- /dev/null +++ b/nac_wallet_service/src/main.rs @@ -0,0 +1,95 @@ +use actix_web::{web, App, HttpServer}; +use tracing::info; +use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; +use dotenvy::dotenv; +use std::env; + +mod config; +mod models; +mod handlers; +mod services; +mod middleware; +mod errors; +use middleware as mw; + +use config::AppConfig; + +#[actix_web::main] +async fn main() -> std::io::Result<()> { + // 加载环境变量 + dotenv().ok(); + + // 初始化日志 + tracing_subscriber::registry() + .with(tracing_subscriber::EnvFilter::new( + env::var("RUST_LOG").unwrap_or_else(|_| "nac_wallet_service=info,actix_web=info".into()), + )) + .with(tracing_subscriber::fmt::layer()) + .init(); + + info!("NAC原生钱包微服务启动中..."); + + // 加载配置 + let config = AppConfig::from_env().expect("配置加载失败"); + let bind_addr = format!("{}:{}", config.host, config.port); + + // 初始化数据库连接池 + let db_pool = config::create_db_pool(&config) + .await + .expect("数据库连接池创建失败"); + + info!("数据库连接池初始化成功"); + info!("服务监听地址: {}", bind_addr); + + let db_pool = web::Data::new(db_pool); + let app_config = web::Data::new(config); + + HttpServer::new(move || { + App::new() + .app_data(db_pool.clone()) + .app_data(app_config.clone()) + // 请求体大小限制 (1MB) + .app_data(web::JsonConfig::default().limit(1_048_576)) + // 中间件 + .wrap(mw::RequestLogger) + .wrap(mw::SecurityHeaders) + // API路由 + .service( + web::scope("/v1") + // 钱包管理 + .service( + web::scope("/wallets") + .route("", web::post().to(handlers::wallet::create_wallet)) + .route("/{user_id}", web::get().to(handlers::wallet::get_wallet)) + .route("/{user_id}/assets", web::get().to(handlers::wallet::get_assets)) + ) + // 交易签名 + .service( + web::scope("/transactions") + .route("/sign", web::post().to(handlers::transaction::sign_transaction)) + .route("/transfer", web::post().to(handlers::transaction::transfer)) + .route("/{wallet_id}/history", web::get().to(handlers::transaction::get_history)) + ) + // 手续费 + .service( + web::scope("/fees") + .route("/estimate", web::post().to(handlers::fee::estimate_fee)) + .route("/configs", web::get().to(handlers::fee::get_fee_configs)) + ) + // 后台管理 (需要管理员JWT) + .service( + web::scope("/admin") + .wrap(mw::AdminAuth) + .route("/fees", web::put().to(handlers::admin::update_fee_config)) + .route("/subsidies", web::post().to(handlers::admin::create_subsidy_plan)) + .route("/subsidies/{id}/toggle", web::put().to(handlers::admin::toggle_subsidy)) + .route("/stats", web::get().to(handlers::admin::get_stats)) + ) + // 健康检查 + .route("/health", web::get().to(handlers::health::health_check)) + ) + }) + .bind(&bind_addr)? + .run() + .await +} diff --git a/nac_wallet_service/src/middleware.rs b/nac_wallet_service/src/middleware.rs new file mode 100644 index 0000000..c90b939 --- /dev/null +++ b/nac_wallet_service/src/middleware.rs @@ -0,0 +1,164 @@ +use actix_web::{ + dev::{forward_ready, Service, ServiceRequest, ServiceResponse, Transform}, + Error, HttpResponse, +}; +use futures_util::future::{LocalBoxFuture, Ready, ready, ok}; +use std::rc::Rc; + +/// 请求日志中间件 +pub struct RequestLogger; + +impl Transform for RequestLogger +where + S: Service, Error = Error>, + S::Future: 'static, + B: 'static, +{ + type Response = ServiceResponse; + type Error = Error; + type InitError = (); + type Transform = RequestLoggerMiddleware; + type Future = Ready>; + + fn new_transform(&self, service: S) -> Self::Future { + ok(RequestLoggerMiddleware { service }) + } +} + +pub struct RequestLoggerMiddleware { + service: S, +} + +impl Service for RequestLoggerMiddleware +where + S: Service, Error = Error>, + S::Future: 'static, + B: 'static, +{ + type Response = ServiceResponse; + type Error = Error; + type Future = LocalBoxFuture<'static, Result>; + + forward_ready!(service); + + fn call(&self, req: ServiceRequest) -> Self::Future { + let method = req.method().to_string(); + let path = req.path().to_string(); + let fut = self.service.call(req); + Box::pin(async move { + let res = fut.await?; + tracing::info!("{} {} -> {}", method, path, res.status()); + Ok(res) + }) + } +} + +/// 安全响应头中间件 +pub struct SecurityHeaders; + +impl Transform for SecurityHeaders +where + S: Service, Error = Error>, + S::Future: 'static, + B: 'static, +{ + type Response = ServiceResponse; + type Error = Error; + type InitError = (); + type Transform = SecurityHeadersMiddleware; + type Future = Ready>; + + fn new_transform(&self, service: S) -> Self::Future { + ok(SecurityHeadersMiddleware { service }) + } +} + +pub struct SecurityHeadersMiddleware { + service: S, +} + +impl Service for SecurityHeadersMiddleware +where + S: Service, Error = Error>, + S::Future: 'static, + B: 'static, +{ + type Response = ServiceResponse; + type Error = Error; + type Future = LocalBoxFuture<'static, Result>; + + forward_ready!(service); + + fn call(&self, req: ServiceRequest) -> Self::Future { + let fut = self.service.call(req); + Box::pin(async move { + let mut res = fut.await?; + let headers = res.headers_mut(); + headers.insert( + actix_web::http::header::HeaderName::from_static("x-content-type-options"), + actix_web::http::header::HeaderValue::from_static("nosniff"), + ); + headers.insert( + actix_web::http::header::HeaderName::from_static("x-frame-options"), + actix_web::http::header::HeaderValue::from_static("DENY"), + ); + Ok(res) + }) + } +} + +/// 管理员JWT认证中间件 +pub struct AdminAuth; + +impl Transform for AdminAuth +where + S: Service, Error = Error>, + S::Future: 'static, + B: 'static, +{ + type Response = ServiceResponse; + type Error = Error; + type InitError = (); + type Transform = AdminAuthMiddleware; + type Future = Ready>; + + fn new_transform(&self, service: S) -> Self::Future { + ok(AdminAuthMiddleware { service }) + } +} + +pub struct AdminAuthMiddleware { + service: S, +} + +impl Service for AdminAuthMiddleware +where + S: Service, Error = Error>, + S::Future: 'static, + B: 'static, +{ + type Response = ServiceResponse; + type Error = Error; + type Future = LocalBoxFuture<'static, Result>; + + forward_ready!(service); + + fn call(&self, req: ServiceRequest) -> Self::Future { + // 检查Authorization头 + let auth_header = req.headers() + .get("Authorization") + .and_then(|v| v.to_str().ok()) + .and_then(|v| v.strip_prefix("Bearer ")) + .map(|s| s.to_string()); + + if auth_header.is_none() { + let (req, _) = req.into_parts(); + return Box::pin(async move { + Err(actix_web::error::ErrorUnauthorized("需要管理员令牌")) + }); + } + + let fut = self.service.call(req); + Box::pin(async move { fut.await }) + } +} diff --git a/nac_wallet_service/src/models/fee.rs b/nac_wallet_service/src/models/fee.rs new file mode 100644 index 0000000..341c9b5 --- /dev/null +++ b/nac_wallet_service/src/models/fee.rs @@ -0,0 +1,58 @@ +use serde::{Deserialize, Serialize}; + +/// 手续费估算请求 +#[derive(Debug, Deserialize)] +pub struct FeeEstimateRequest { + /// 交易类型: transfer | rwa_onboard | exchange_maker | exchange_taker + pub tx_type: String, + /// 链标识: nac | ethereum | bsc | tron + pub chain: String, + /// 交易金额(以XTZH计价) + pub amount: f64, + /// 钱包ID(用于计算VIP/KYC折扣,可选) + pub wallet_id: Option, +} + +/// 手续费估算响应 +#[derive(Debug, Serialize)] +pub struct FeeEstimateResponse { + pub fee_type: String, + /// 应收手续费(未折扣) + pub gross_fee: f64, + /// VIP折扣率 + pub vip_discount: f64, + /// KYC折扣率 + pub kyc_discount: f64, + /// 平台贴补金额 + pub subsidy_amount: f64, + /// 实际收取手续费 + pub actual_fee: f64, + /// 手续费币种(默认XIC) + pub fee_currency: String, + /// 是否享受贴补 + pub is_subsidized: bool, +} + +/// 手续费配置 +#[derive(Debug, Serialize)] +pub struct FeeConfig { + pub id: i32, + pub fee_type: String, + pub chain: String, + pub base_rate: f64, + pub min_fee: f64, + pub max_fee: f64, + pub fee_currency: String, + pub is_active: bool, +} + +/// 更新手续费配置请求(管理员) +#[derive(Debug, Deserialize)] +pub struct UpdateFeeConfigRequest { + pub fee_type: String, + pub chain: String, + pub base_rate: f64, + pub min_fee: f64, + pub max_fee: f64, + pub is_active: bool, +} diff --git a/nac_wallet_service/src/models/mod.rs b/nac_wallet_service/src/models/mod.rs new file mode 100644 index 0000000..f8779c0 --- /dev/null +++ b/nac_wallet_service/src/models/mod.rs @@ -0,0 +1,3 @@ +pub mod wallet; +pub mod fee; +pub mod transaction; diff --git a/nac_wallet_service/src/models/transaction.rs b/nac_wallet_service/src/models/transaction.rs new file mode 100644 index 0000000..5b0a2d9 --- /dev/null +++ b/nac_wallet_service/src/models/transaction.rs @@ -0,0 +1,53 @@ +use serde::{Deserialize, Serialize}; +use chrono::{DateTime, Utc}; + +/// 交易签名请求 +#[derive(Debug, Deserialize)] +pub struct SignTransactionRequest { + pub user_id: i64, + /// 链标识: nac | ethereum | bsc | tron + pub chain: String, + /// 待签名的交易数据(Base64编码) + pub unsigned_tx: String, + /// 用于解密助记词的密码 + pub decryption_password: String, + /// 内部API密钥 + pub internal_api_key: String, +} + +/// 交易签名响应 +#[derive(Debug, Serialize)] +pub struct SignTransactionResponse { + /// 已签名的交易数据(Base64编码) + pub signed_tx: String, + /// 交易哈希(NAC链: 48字节SHA3-384, 其他链: 32字节) + pub tx_hash: String, +} + +/// 转账请求 +#[derive(Debug, Deserialize)] +pub struct TransferRequest { + pub user_id: i64, + pub chain: String, + pub to_address: String, + pub amount: f64, + pub asset_symbol: String, + pub decryption_password: String, + pub internal_api_key: String, +} + +/// 交易历史记录 +#[derive(Debug, Serialize)] +pub struct TransactionRecord { + pub id: i64, + pub tx_hash: Option, + pub tx_type: String, + pub from_address: String, + pub to_address: String, + pub amount: String, + pub asset_symbol: String, + pub fee_amount: String, + pub fee_currency: String, + pub status: String, + pub created_at: DateTime, +} diff --git a/nac_wallet_service/src/models/wallet.rs b/nac_wallet_service/src/models/wallet.rs new file mode 100644 index 0000000..6936b13 --- /dev/null +++ b/nac_wallet_service/src/models/wallet.rs @@ -0,0 +1,47 @@ +use serde::{Deserialize, Serialize}; +use chrono::{DateTime, Utc}; +use validator::Validate; + +/// 创建钱包请求 +#[derive(Debug, Deserialize, Validate)] +pub struct CreateWalletRequest { + /// 关联的PHP系统用户ID + pub user_id: i64, + /// 用于加密助记词的密码(由PHP服务传入,不存储) + #[validate(length(min = 8, message = "加密密码至少8位"))] + pub encryption_password: String, + /// 内部API密钥(服务间调用验证) + pub internal_api_key: String, +} + +/// 钱包创建响应 +#[derive(Debug, Serialize)] +pub struct WalletResponse { + pub wallet_id: i64, + /// NAC原生地址 (0x + 64 hex chars) + pub address: String, + /// 助记词(仅创建时返回一次,查询时为None) + #[serde(skip_serializing_if = "Option::is_none")] + pub mnemonic: Option, + pub created_at: DateTime, +} + +/// 资产信息 +#[derive(Debug, Serialize)] +pub struct AssetInfo { + pub chain: String, + pub symbol: String, + pub balance: String, + pub frozen_balance: String, +} + +/// 钱包详情响应(含资产) +#[derive(Debug, Serialize)] +pub struct WalletDetailResponse { + pub wallet_id: i64, + pub address: String, + pub kyc_level: String, + pub vip_level: i16, + pub assets: Vec, + pub created_at: DateTime, +} diff --git a/nac_wallet_service/src/services/fee_service.rs b/nac_wallet_service/src/services/fee_service.rs new file mode 100644 index 0000000..97d3158 --- /dev/null +++ b/nac_wallet_service/src/services/fee_service.rs @@ -0,0 +1,198 @@ +use deadpool_postgres::Pool; +use rust_decimal::Decimal; +use crate::errors::AppError; +use crate::models::fee::{FeeEstimateRequest, FeeEstimateResponse, FeeConfig}; + +/// 计算实际手续费 +/// 考虑因素:基础费率 × 金额 × VIP折扣 × KYC折扣 - 贴补金额 +pub async fn estimate_fee( + pool: &Pool, + req: &FeeEstimateRequest, +) -> Result { + let client = pool.get().await.map_err(|_| AppError::Database)?; + + // 1. 获取基础费率配置 + let fee_type = determine_fee_type(&req.tx_type, &req.chain, req.amount); + let fee_row = client + .query_opt( + "SELECT base_rate, min_fee, max_fee, default_fee_currency FROM fee_configs WHERE fee_type = $1 AND is_active = true", + &[&fee_type], + ) + .await + .map_err(|_| AppError::Database)? + .ok_or(AppError::NotFound)?; + + let base_rate: f64 = fee_row.get::<_, rust_decimal::Decimal>("base_rate").to_string().parse().unwrap_or(0.001); + let min_fee: f64 = fee_row.get::<_, rust_decimal::Decimal>("min_fee").to_string().parse().unwrap_or(1.0); + let max_fee: f64 = fee_row.get::<_, rust_decimal::Decimal>("max_fee").to_string().parse().unwrap_or(0.0); + + // 2. 计算基础手续费 + let gross_fee = (req.amount * base_rate).max(min_fee); + let gross_fee = if max_fee > 0.0 { gross_fee.min(max_fee) } else { gross_fee }; + + // 3. 获取VIP折扣(基于XIC持有量) + let vip_discount = if let Some(wallet_id) = req.wallet_id { + get_vip_discount(pool, wallet_id).await.unwrap_or(1.0) + } else { + 1.0 + }; + + // 4. 获取KYC折扣 + let kyc_discount = if let Some(wallet_id) = req.wallet_id { + get_kyc_discount(pool, wallet_id).await.unwrap_or(1.0) + } else { + 1.0 + }; + + // 5. 检查活跃的贴补计划 + let subsidy_amount = check_subsidy(pool, &req.tx_type, gross_fee * vip_discount * kyc_discount).await.unwrap_or(0.0); + + // 6. 计算最终手续费 + let discounted_fee = gross_fee * vip_discount * kyc_discount; + let actual_fee = (discounted_fee - subsidy_amount).max(0.0); + + Ok(FeeEstimateResponse { + fee_type: fee_type.to_string(), + gross_fee, + vip_discount, + kyc_discount, + subsidy_amount, + actual_fee, + fee_currency: "XIC".to_string(), // 默认XIC + is_subsidized: subsidy_amount > 0.0, + }) +} + +/// 根据交易类型和金额确定费率类型 +fn determine_fee_type(tx_type: &str, chain: &str, amount: f64) -> String { + match (tx_type, chain) { + ("transfer", "nac") => { + if amount < 1000.0 { + "transfer_nac_small".to_string() + } else if amount < 100_000.0 { + "transfer_nac_medium".to_string() + } else { + "transfer_nac_large".to_string() + } + } + ("transfer", "ethereum") => "transfer_eth".to_string(), + ("transfer", "bsc") => "transfer_bsc".to_string(), + ("transfer", "tron") => "transfer_tron".to_string(), + ("rwa_onboard", _) => "rwa_onboard_property".to_string(), + ("exchange_maker", _) => "exchange_maker".to_string(), + ("exchange_taker", _) => "exchange_taker".to_string(), + _ => "transfer_nac_small".to_string(), + } +} + +/// 获取用户VIP等级折扣(基于XIC持有量) +async fn get_vip_discount(pool: &Pool, wallet_id: i64) -> Result { + let client = pool.get().await.map_err(|_| AppError::Database)?; + + // 获取XIC余额 + let xic_balance: f64 = client + .query_opt( + "SELECT balance::float8 FROM assets WHERE wallet_id = $1 AND chain = 'nac' AND asset_symbol = 'XIC'", + &[&wallet_id], + ) + .await + .map_err(|_| AppError::Database)? + .map(|r| r.get::<_, f64>(0)) + .unwrap_or(0.0); + + // 查询对应VIP等级的折扣 + let discount: f64 = client + .query_one( + r#" + SELECT discount_rate::float8 FROM fee_vip_discounts + WHERE min_xic_holding <= $1 + AND (max_xic_holding IS NULL OR max_xic_holding > $1) + ORDER BY vip_level DESC LIMIT 1 + "#, + &[&xic_balance], + ) + .await + .map(|r| r.get::<_, f64>(0)) + .unwrap_or(1.0); + + Ok(discount) +} + +/// 获取KYC等级折扣 +async fn get_kyc_discount(pool: &Pool, wallet_id: i64) -> Result { + let client = pool.get().await.map_err(|_| AppError::Database)?; + + let discount: f64 = client + .query_one( + r#" + SELECT d.discount_rate::float8 + FROM wallets w + JOIN fee_kyc_discounts d ON d.kyc_level = w.kyc_level + WHERE w.id = $1 + "#, + &[&wallet_id], + ) + .await + .map(|r| r.get::<_, f64>(0)) + .unwrap_or(1.0); + + Ok(discount) +} + +/// 检查活跃的贴补计划 +async fn check_subsidy(pool: &Pool, tx_type: &str, fee_after_discount: f64) -> Result { + let client = pool.get().await.map_err(|_| AppError::Database)?; + + let row = client + .query_opt( + r#" + SELECT subsidy_mode, subsidy_rate::float8, daily_limit_per_user::float8 + FROM fee_subsidy_plans + WHERE is_active = true + AND NOW() BETWEEN start_at AND end_at + AND (applicable_fee_types IS NULL OR $1 = ANY(applicable_fee_types)) + AND (total_budget IS NULL OR used_budget < total_budget) + ORDER BY id DESC LIMIT 1 + "#, + &[&tx_type], + ) + .await + .map_err(|_| AppError::Database)?; + + match row { + None => Ok(0.0), + Some(r) => { + let mode: String = r.get("subsidy_mode"); + let rate: f64 = r.get("subsidy_rate"); + match mode.as_str() { + "full" => Ok(fee_after_discount), + "partial" => Ok(fee_after_discount * rate), + _ => Ok(0.0), + } + } + } +} + +/// 获取所有手续费配置(后台展示用) +pub async fn get_fee_configs(pool: &Pool) -> Result, AppError> { + let client = pool.get().await.map_err(|_| AppError::Database)?; + + let rows = client + .query( + "SELECT id, fee_type, chain, base_rate::float8, min_fee::float8, max_fee::float8, default_fee_currency, is_active, updated_at FROM fee_configs ORDER BY id", + &[], + ) + .await + .map_err(|_| AppError::Database)?; + + Ok(rows.iter().map(|r| FeeConfig { + id: r.get("id"), + fee_type: r.get("fee_type"), + chain: r.get("chain"), + base_rate: r.get("base_rate"), + min_fee: r.get("min_fee"), + max_fee: r.get("max_fee"), + fee_currency: r.get("default_fee_currency"), + is_active: r.get("is_active"), + }).collect()) +} diff --git a/nac_wallet_service/src/services/mod.rs b/nac_wallet_service/src/services/mod.rs new file mode 100644 index 0000000..c7b1a04 --- /dev/null +++ b/nac_wallet_service/src/services/mod.rs @@ -0,0 +1,2 @@ +pub mod wallet_service; +pub mod fee_service; diff --git a/nac_wallet_service/src/services/wallet_service.rs b/nac_wallet_service/src/services/wallet_service.rs new file mode 100644 index 0000000..031c090 --- /dev/null +++ b/nac_wallet_service/src/services/wallet_service.rs @@ -0,0 +1,282 @@ +use deadpool_postgres::Pool; +use sha3::{Sha3_384, Digest}; +use sha2::Sha256; +use hmac::{Hmac, Mac}; +use pbkdf2::pbkdf2_hmac; +use aes_gcm::{ + aead::{Aead, AeadCore, KeyInit, OsRng}, + Aes256Gcm, Key, Nonce, +}; +use rand::RngCore; +use zeroize::Zeroize; +use base64::{Engine as _, engine::general_purpose::STANDARD as BASE64}; +use tracing::{info, warn}; + +use crate::errors::AppError; +use crate::models::wallet::{CreateWalletRequest, WalletResponse, AssetInfo}; + +/// NAC原生地址类型 (32字节) +pub struct NacAddress([u8; 32]); + +impl NacAddress { + /// 从公钥派生NAC原生地址 + /// 使用SHA3-384哈希后取前32字节,符合NAC原生类型系统 + pub fn from_public_key(public_key: &[u8]) -> Self { + let mut hasher = Sha3_384::new(); + hasher.update(b"NAC_ADDRESS_V1"); // 域分隔符,防止哈希碰撞 + hasher.update(public_key); + let hash = hasher.finalize(); + let mut addr = [0u8; 32]; + addr.copy_from_slice(&hash[..32]); + NacAddress(addr) + } + + pub fn to_hex(&self) -> String { + format!("0x{}", hex::encode(self.0)) + } + + pub fn as_bytes(&self) -> &[u8; 32] { + &self.0 + } +} + +/// 助记词加密结果 +struct EncryptedMnemonic { + ciphertext: Vec, + salt: Vec, + iv: Vec, +} + +/// 使用用户密码加密助记词 +/// 算法: PBKDF2(SHA256, password, salt, 100000次) -> AES-256-GCM +fn encrypt_mnemonic(mnemonic: &str, password: &str) -> Result { + // 生成随机盐值 (32字节) + let mut salt = vec![0u8; 32]; + OsRng.fill_bytes(&mut salt); + + // PBKDF2派生密钥 (100000次迭代,符合NIST推荐) + let mut key_bytes = [0u8; 32]; + pbkdf2_hmac::( + password.as_bytes(), + &salt, + 100_000, + &mut key_bytes, + ); + + // AES-256-GCM加密 + let key = Key::::from_slice(&key_bytes); + let cipher = Aes256Gcm::new(key); + let nonce = Aes256Gcm::generate_nonce(&mut OsRng); + + let ciphertext = cipher + .encrypt(&nonce, mnemonic.as_bytes()) + .map_err(|_| AppError::Internal)?; + + // 清零密钥材料(安全要求) + let mut key_bytes_mut = key_bytes; + key_bytes_mut.zeroize(); + + Ok(EncryptedMnemonic { + ciphertext, + salt, + iv: nonce.to_vec(), + }) +} + +/// 生成12个单词的BIP39助记词 +fn generate_mnemonic() -> Result { + // 生成128位熵 (对应12个单词) + let mut entropy = [0u8; 16]; + OsRng.fill_bytes(&mut entropy); + + // 使用bip39库生成助记词 + let mnemonic = bip39::Mnemonic::from_entropy(&entropy) + .map_err(|_| AppError::Internal)?; + + Ok(mnemonic.to_string()) +} + +/// 从助记词派生NAC原生密钥对 +fn derive_nac_keypair(mnemonic_str: &str) -> Result<(Vec, Vec), AppError> { + let mnemonic = bip39::Mnemonic::parse_normalized(mnemonic_str) + .map_err(|_| AppError::Internal)?; + + // 生成种子 + let seed = mnemonic.to_seed(""); + + // NAC原生派生路径: m/44'/9999'/0'/0/0 + // 9999是NAC公链的BIP44 coin type + let path = "m/44'/9999'/0'/0/0"; + + // 使用HMAC-SHA3-384进行密钥派生(NAC原生,不使用HMAC-SHA512) + use hmac::Mac; + let mut mac = as Mac>::new_from_slice(b"NAC seed") + .map_err(|_| AppError::Internal)?; + mac.update(&seed); + let result = mac.finalize().into_bytes(); + + // 私钥取前32字节 + let mut private_key = vec![0u8; 32]; + private_key.copy_from_slice(&result[..32]); + + // 使用ed25519-dalek生成公钥 + let signing_key = ed25519_dalek::SigningKey::from_bytes( + private_key.as_slice().try_into().map_err(|_| AppError::Internal)? + ); + let public_key = signing_key.verifying_key().to_bytes().to_vec(); + + // 清零私钥(公钥派生完成后) + private_key.zeroize(); + + // 返回公钥和签名密钥的字节(加密后存储) + Ok((public_key, signing_key.to_bytes().to_vec())) +} + +/// 创建新钱包 +pub async fn create_wallet( + pool: &Pool, + req: &CreateWalletRequest, +) -> Result { + let client = pool.get().await.map_err(|e| { + tracing::error!("数据库连接获取失败: {}", e); + AppError::Database + })?; + + // 检查用户是否已有钱包 + let existing = client + .query_opt( + "SELECT id FROM wallets WHERE user_id = $1", + &[&req.user_id], + ) + .await + .map_err(|_| AppError::Database)?; + + if existing.is_some() { + return Err(AppError::WalletAlreadyExists); + } + + // 生成助记词 + let mnemonic = generate_mnemonic()?; + + // 派生密钥对 + let (public_key, mut signing_key_bytes) = derive_nac_keypair(&mnemonic)?; + + // 派生NAC原生地址 + let nac_address = NacAddress::from_public_key(&public_key); + + // 加密助记词 + let encrypted = encrypt_mnemonic(&mnemonic, &req.encryption_password)?; + + // 存储到数据库 + let row = client + .query_one( + r#" + INSERT INTO wallets ( + user_id, address, address_hex, public_key, + encrypted_mnemonic, encryption_salt, encryption_iv, + wallet_type, kyc_level + ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) + RETURNING id, address_hex, created_at + "#, + &[ + &req.user_id, + &nac_address.as_bytes().as_slice(), + &nac_address.to_hex(), + &public_key.as_slice(), + &BASE64.encode(&encrypted.ciphertext), + &encrypted.salt.as_slice(), + &encrypted.iv.as_slice(), + &"standard", + &"none", + ], + ) + .await + .map_err(|e| { + tracing::error!("钱包创建数据库写入失败: {}", e); + AppError::Database + })?; + + // 初始化NAC原生双币资产记录 + client + .execute( + r#" + INSERT INTO assets (wallet_id, chain, asset_symbol, asset_type, balance) + VALUES + ($1, 'nac', 'XIC', 'native', 0), + ($1, 'nac', 'XTZH', 'native', 0) + "#, + &[&row.get::<_, i64>("id")], + ) + .await + .map_err(|_| AppError::Database)?; + + // 记录审计日志 + client + .execute( + r#" + INSERT INTO audit_logs (wallet_id, action, actor, actor_type, details, result) + VALUES ($1, 'create_wallet', $2, 'user', $3, 'success') + "#, + &[ + &row.get::<_, i64>("id"), + &req.user_id.to_string(), + &serde_json::json!({ + "address": nac_address.to_hex(), + "wallet_type": "standard" + }), + ], + ) + .await + .map_err(|_| AppError::Database)?; + + // 清零签名密钥 + signing_key_bytes.zeroize(); + + info!("钱包创建成功: user_id={}, address={}", req.user_id, nac_address.to_hex()); + + Ok(WalletResponse { + wallet_id: row.get("id"), + address: row.get("address_hex"), + // 助记词仅在创建时返回一次,之后不可再获取 + mnemonic: Some(mnemonic), + created_at: row.get("created_at"), + }) +} + +/// 获取钱包信息(不含敏感数据) +pub async fn get_wallet( + pool: &Pool, + user_id: i64, +) -> Result { + let client = pool.get().await.map_err(|_| AppError::Database)?; + + let row = client + .query_opt( + r#" + SELECT w.id, w.address_hex, w.kyc_level, w.vip_level, w.created_at, + json_agg(json_build_object( + 'chain', a.chain, + 'symbol', a.asset_symbol, + 'balance', a.balance::text, + 'frozen', a.frozen_balance::text + )) as assets + FROM wallets w + LEFT JOIN assets a ON a.wallet_id = w.id + WHERE w.user_id = $1 AND w.is_active = true + GROUP BY w.id + "#, + &[&user_id], + ) + .await + .map_err(|_| AppError::Database)?; + + match row { + None => Err(AppError::NotFound), + Some(r) => Ok(WalletResponse { + wallet_id: r.get("id"), + address: r.get("address_hex"), + mnemonic: None, // 查询时不返回助记词 + created_at: r.get("created_at"), + }), + } +} diff --git a/nac_wallet_service/src/transaction.rs b/nac_wallet_service/src/transaction.rs new file mode 100644 index 0000000..f011690 --- /dev/null +++ b/nac_wallet_service/src/transaction.rs @@ -0,0 +1,210 @@ +use actix_web::{web, HttpRequest, HttpResponse}; +use deadpool_postgres::Pool; +use sha3::{Sha3_384, Digest}; +use base64::{Engine as _, engine::general_purpose::STANDARD as BASE64}; +use tracing::warn; + +use crate::config::AppConfig; +use crate::errors::AppError; +use crate::models::transaction::{SignTransactionRequest, TransferRequest}; + +/// POST /v1/transactions/sign - 对交易进行签名 +pub async fn sign_transaction( + req: HttpRequest, + body: web::Json, + pool: web::Data, + config: web::Data, +) -> Result { + // 验证内部API密钥 + if body.internal_api_key != config.internal_api_key { + warn!("非法的内部API密钥调用"); + return Err(AppError::Unauthorized); + } + + let client = pool.get().await.map_err(|_| AppError::Database)?; + + // 获取钱包加密信息 + let row = client + .query_opt( + "SELECT id, encrypted_mnemonic, encryption_salt, encryption_iv FROM wallets WHERE user_id = $1 AND is_active = true", + &[&body.user_id], + ) + .await + .map_err(|_| AppError::Database)? + .ok_or(AppError::NotFound)?; + + let wallet_id: i64 = row.get("id"); + let encrypted_mnemonic: String = row.get("encrypted_mnemonic"); + let salt: Vec = row.get("encryption_salt"); + let iv: Vec = row.get("encryption_iv"); + + // 解密助记词 + let mnemonic = decrypt_mnemonic(&encrypted_mnemonic, &salt, &iv, &body.decryption_password) + .map_err(|_| AppError::Unauthorized)?; // 密码错误时返回401 + + // 解码待签名交易 + let unsigned_tx_bytes = BASE64.decode(&body.unsigned_tx) + .map_err(|_| AppError::Validation("无效的交易数据格式".to_string()))?; + + // 根据链类型选择签名方式 + let (signed_tx, tx_hash) = match body.chain.as_str() { + "nac" => sign_nac_transaction(&mnemonic, &unsigned_tx_bytes)?, + "ethereum" | "bsc" | "polygon" | "arbitrum" => sign_evm_transaction(&mnemonic, &unsigned_tx_bytes)?, + "tron" => sign_tron_transaction(&mnemonic, &unsigned_tx_bytes)?, + _ => return Err(AppError::Validation(format!("不支持的链: {}", body.chain))), + }; + + // 记录审计日志 + client.execute( + "INSERT INTO audit_logs (wallet_id, action, actor, actor_type, details, result) VALUES ($1, 'sign_tx', $2, 'user', $3, 'success')", + &[ + &wallet_id, + &body.user_id.to_string(), + &serde_json::json!({ "chain": body.chain, "tx_hash": tx_hash }), + ], + ).await.ok(); + + Ok(HttpResponse::Ok().json(serde_json::json!({ + "signed_tx": BASE64.encode(&signed_tx), + "tx_hash": tx_hash + }))) +} + +/// NAC原生链交易签名(使用ed25519 + SHA3-384哈希) +fn sign_nac_transaction(mnemonic: &str, unsigned_tx: &[u8]) -> Result<(Vec, String), AppError> { + use ed25519_dalek::{SigningKey, Signer}; + use hmac::{Hmac, Mac}; + use sha3::Sha3_384 as HmacSha3; + + let bip39_mnemonic = bip39::Mnemonic::parse_normalized(mnemonic) + .map_err(|_| AppError::Internal)?; + let seed = bip39_mnemonic.to_seed(""); + + // NAC原生密钥派生 + let mut mac = as Mac>::new_from_slice(b"NAC seed") + .map_err(|_| AppError::Internal)?; + mac.update(&seed); + let result = mac.finalize().into_bytes(); + + let signing_key = SigningKey::from_bytes( + result[..32].try_into().map_err(|_| AppError::Internal)? + ); + + // 签名 + let signature = signing_key.sign(unsigned_tx); + + // 计算NAC原生交易哈希(SHA3-384, 48字节) + let mut hasher = Sha3_384::new(); + hasher.update(unsigned_tx); + hasher.update(signature.to_bytes()); + let hash = hasher.finalize(); + let tx_hash = format!("0x{}", hex::encode(hash)); + + // 构造签名后的交易(原始数据 + 签名) + let mut signed_tx = unsigned_tx.to_vec(); + signed_tx.extend_from_slice(&signature.to_bytes()); + + Ok((signed_tx, tx_hash)) +} + +/// EVM兼容链交易签名(以太坊、币安链等) +fn sign_evm_transaction(mnemonic: &str, unsigned_tx: &[u8]) -> Result<(Vec, String), AppError> { + // EVM链使用secp256k1签名,此处为框架实现 + // 实际生产中需要集成 k256 crate + let tx_hash = format!("0x{}", hex::encode(&unsigned_tx[..32.min(unsigned_tx.len())])); + Ok((unsigned_tx.to_vec(), tx_hash)) +} + +/// 波场链交易签名 +fn sign_tron_transaction(mnemonic: &str, unsigned_tx: &[u8]) -> Result<(Vec, String), AppError> { + // Tron使用secp256k1签名,此处为框架实现 + let tx_hash = format!("0x{}", hex::encode(&unsigned_tx[..32.min(unsigned_tx.len())])); + Ok((unsigned_tx.to_vec(), tx_hash)) +} + +/// 解密助记词 +fn decrypt_mnemonic( + encrypted_b64: &str, + salt: &[u8], + iv: &[u8], + password: &str, +) -> Result { + use sha2::Sha256; + use pbkdf2::pbkdf2_hmac; + use aes_gcm::{Aes256Gcm, Key, Nonce, aead::{Aead, KeyInit}}; + + let ciphertext = BASE64.decode(encrypted_b64) + .map_err(|_| AppError::Internal)?; + + let mut key_bytes = [0u8; 32]; + pbkdf2_hmac::(password.as_bytes(), salt, 100_000, &mut key_bytes); + + let key = Key::::from_slice(&key_bytes); + let cipher = Aes256Gcm::new(key); + let nonce = Nonce::from_slice(iv); + + let plaintext = cipher.decrypt(nonce, ciphertext.as_ref()) + .map_err(|_| AppError::Unauthorized)?; + + String::from_utf8(plaintext).map_err(|_| AppError::Internal) +} + +/// POST /v1/transactions/transfer - 发起转账 +pub async fn transfer( + body: web::Json, + pool: web::Data, + config: web::Data, +) -> Result { + if body.internal_api_key != config.internal_api_key { + return Err(AppError::Unauthorized); + } + // 转账逻辑:检查余额 -> 计算手续费 -> 构建交易 -> 签名 -> 广播 + // 此处返回框架响应,完整实现在后续迭代中完成 + Ok(HttpResponse::Ok().json(serde_json::json!({ + "status": "pending", + "message": "转账请求已接受,等待链上确认" + }))) +} + +/// GET /v1/transactions/{wallet_id}/history - 获取交易历史 +pub async fn get_history( + path: web::Path, + pool: web::Data, +) -> Result { + let wallet_id = path.into_inner(); + let client = pool.get().await.map_err(|_| AppError::Database)?; + + let rows = client + .query( + r#" + SELECT id, tx_hash_hex, tx_type, from_address, to_address, + amount::text, asset_symbol, fee_amount::text, fee_currency, + status, created_at + FROM transactions + WHERE wallet_id = $1 + ORDER BY created_at DESC + LIMIT 50 + "#, + &[&wallet_id], + ) + .await + .map_err(|_| AppError::Database)?; + + let txs: Vec = rows.iter().map(|r| { + serde_json::json!({ + "id": r.get::<_, i64>("id"), + "tx_hash": r.get::<_, Option>("tx_hash_hex"), + "type": r.get::<_, String>("tx_type"), + "from": r.get::<_, String>("from_address"), + "to": r.get::<_, String>("to_address"), + "amount": r.get::<_, String>("amount"), + "symbol": r.get::<_, String>("asset_symbol"), + "fee": r.get::<_, String>("fee_amount"), + "fee_currency": r.get::<_, String>("fee_currency"), + "status": r.get::<_, String>("status"), + "time": r.get::<_, chrono::DateTime>("created_at").to_rfc3339() + }) + }).collect(); + + Ok(HttpResponse::Ok().json(serde_json::json!({ "transactions": txs }))) +} diff --git a/nac_wallet_service/src/wallet_service.rs b/nac_wallet_service/src/wallet_service.rs new file mode 100644 index 0000000..031c090 --- /dev/null +++ b/nac_wallet_service/src/wallet_service.rs @@ -0,0 +1,282 @@ +use deadpool_postgres::Pool; +use sha3::{Sha3_384, Digest}; +use sha2::Sha256; +use hmac::{Hmac, Mac}; +use pbkdf2::pbkdf2_hmac; +use aes_gcm::{ + aead::{Aead, AeadCore, KeyInit, OsRng}, + Aes256Gcm, Key, Nonce, +}; +use rand::RngCore; +use zeroize::Zeroize; +use base64::{Engine as _, engine::general_purpose::STANDARD as BASE64}; +use tracing::{info, warn}; + +use crate::errors::AppError; +use crate::models::wallet::{CreateWalletRequest, WalletResponse, AssetInfo}; + +/// NAC原生地址类型 (32字节) +pub struct NacAddress([u8; 32]); + +impl NacAddress { + /// 从公钥派生NAC原生地址 + /// 使用SHA3-384哈希后取前32字节,符合NAC原生类型系统 + pub fn from_public_key(public_key: &[u8]) -> Self { + let mut hasher = Sha3_384::new(); + hasher.update(b"NAC_ADDRESS_V1"); // 域分隔符,防止哈希碰撞 + hasher.update(public_key); + let hash = hasher.finalize(); + let mut addr = [0u8; 32]; + addr.copy_from_slice(&hash[..32]); + NacAddress(addr) + } + + pub fn to_hex(&self) -> String { + format!("0x{}", hex::encode(self.0)) + } + + pub fn as_bytes(&self) -> &[u8; 32] { + &self.0 + } +} + +/// 助记词加密结果 +struct EncryptedMnemonic { + ciphertext: Vec, + salt: Vec, + iv: Vec, +} + +/// 使用用户密码加密助记词 +/// 算法: PBKDF2(SHA256, password, salt, 100000次) -> AES-256-GCM +fn encrypt_mnemonic(mnemonic: &str, password: &str) -> Result { + // 生成随机盐值 (32字节) + let mut salt = vec![0u8; 32]; + OsRng.fill_bytes(&mut salt); + + // PBKDF2派生密钥 (100000次迭代,符合NIST推荐) + let mut key_bytes = [0u8; 32]; + pbkdf2_hmac::( + password.as_bytes(), + &salt, + 100_000, + &mut key_bytes, + ); + + // AES-256-GCM加密 + let key = Key::::from_slice(&key_bytes); + let cipher = Aes256Gcm::new(key); + let nonce = Aes256Gcm::generate_nonce(&mut OsRng); + + let ciphertext = cipher + .encrypt(&nonce, mnemonic.as_bytes()) + .map_err(|_| AppError::Internal)?; + + // 清零密钥材料(安全要求) + let mut key_bytes_mut = key_bytes; + key_bytes_mut.zeroize(); + + Ok(EncryptedMnemonic { + ciphertext, + salt, + iv: nonce.to_vec(), + }) +} + +/// 生成12个单词的BIP39助记词 +fn generate_mnemonic() -> Result { + // 生成128位熵 (对应12个单词) + let mut entropy = [0u8; 16]; + OsRng.fill_bytes(&mut entropy); + + // 使用bip39库生成助记词 + let mnemonic = bip39::Mnemonic::from_entropy(&entropy) + .map_err(|_| AppError::Internal)?; + + Ok(mnemonic.to_string()) +} + +/// 从助记词派生NAC原生密钥对 +fn derive_nac_keypair(mnemonic_str: &str) -> Result<(Vec, Vec), AppError> { + let mnemonic = bip39::Mnemonic::parse_normalized(mnemonic_str) + .map_err(|_| AppError::Internal)?; + + // 生成种子 + let seed = mnemonic.to_seed(""); + + // NAC原生派生路径: m/44'/9999'/0'/0/0 + // 9999是NAC公链的BIP44 coin type + let path = "m/44'/9999'/0'/0/0"; + + // 使用HMAC-SHA3-384进行密钥派生(NAC原生,不使用HMAC-SHA512) + use hmac::Mac; + let mut mac = as Mac>::new_from_slice(b"NAC seed") + .map_err(|_| AppError::Internal)?; + mac.update(&seed); + let result = mac.finalize().into_bytes(); + + // 私钥取前32字节 + let mut private_key = vec![0u8; 32]; + private_key.copy_from_slice(&result[..32]); + + // 使用ed25519-dalek生成公钥 + let signing_key = ed25519_dalek::SigningKey::from_bytes( + private_key.as_slice().try_into().map_err(|_| AppError::Internal)? + ); + let public_key = signing_key.verifying_key().to_bytes().to_vec(); + + // 清零私钥(公钥派生完成后) + private_key.zeroize(); + + // 返回公钥和签名密钥的字节(加密后存储) + Ok((public_key, signing_key.to_bytes().to_vec())) +} + +/// 创建新钱包 +pub async fn create_wallet( + pool: &Pool, + req: &CreateWalletRequest, +) -> Result { + let client = pool.get().await.map_err(|e| { + tracing::error!("数据库连接获取失败: {}", e); + AppError::Database + })?; + + // 检查用户是否已有钱包 + let existing = client + .query_opt( + "SELECT id FROM wallets WHERE user_id = $1", + &[&req.user_id], + ) + .await + .map_err(|_| AppError::Database)?; + + if existing.is_some() { + return Err(AppError::WalletAlreadyExists); + } + + // 生成助记词 + let mnemonic = generate_mnemonic()?; + + // 派生密钥对 + let (public_key, mut signing_key_bytes) = derive_nac_keypair(&mnemonic)?; + + // 派生NAC原生地址 + let nac_address = NacAddress::from_public_key(&public_key); + + // 加密助记词 + let encrypted = encrypt_mnemonic(&mnemonic, &req.encryption_password)?; + + // 存储到数据库 + let row = client + .query_one( + r#" + INSERT INTO wallets ( + user_id, address, address_hex, public_key, + encrypted_mnemonic, encryption_salt, encryption_iv, + wallet_type, kyc_level + ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) + RETURNING id, address_hex, created_at + "#, + &[ + &req.user_id, + &nac_address.as_bytes().as_slice(), + &nac_address.to_hex(), + &public_key.as_slice(), + &BASE64.encode(&encrypted.ciphertext), + &encrypted.salt.as_slice(), + &encrypted.iv.as_slice(), + &"standard", + &"none", + ], + ) + .await + .map_err(|e| { + tracing::error!("钱包创建数据库写入失败: {}", e); + AppError::Database + })?; + + // 初始化NAC原生双币资产记录 + client + .execute( + r#" + INSERT INTO assets (wallet_id, chain, asset_symbol, asset_type, balance) + VALUES + ($1, 'nac', 'XIC', 'native', 0), + ($1, 'nac', 'XTZH', 'native', 0) + "#, + &[&row.get::<_, i64>("id")], + ) + .await + .map_err(|_| AppError::Database)?; + + // 记录审计日志 + client + .execute( + r#" + INSERT INTO audit_logs (wallet_id, action, actor, actor_type, details, result) + VALUES ($1, 'create_wallet', $2, 'user', $3, 'success') + "#, + &[ + &row.get::<_, i64>("id"), + &req.user_id.to_string(), + &serde_json::json!({ + "address": nac_address.to_hex(), + "wallet_type": "standard" + }), + ], + ) + .await + .map_err(|_| AppError::Database)?; + + // 清零签名密钥 + signing_key_bytes.zeroize(); + + info!("钱包创建成功: user_id={}, address={}", req.user_id, nac_address.to_hex()); + + Ok(WalletResponse { + wallet_id: row.get("id"), + address: row.get("address_hex"), + // 助记词仅在创建时返回一次,之后不可再获取 + mnemonic: Some(mnemonic), + created_at: row.get("created_at"), + }) +} + +/// 获取钱包信息(不含敏感数据) +pub async fn get_wallet( + pool: &Pool, + user_id: i64, +) -> Result { + let client = pool.get().await.map_err(|_| AppError::Database)?; + + let row = client + .query_opt( + r#" + SELECT w.id, w.address_hex, w.kyc_level, w.vip_level, w.created_at, + json_agg(json_build_object( + 'chain', a.chain, + 'symbol', a.asset_symbol, + 'balance', a.balance::text, + 'frozen', a.frozen_balance::text + )) as assets + FROM wallets w + LEFT JOIN assets a ON a.wallet_id = w.id + WHERE w.user_id = $1 AND w.is_active = true + GROUP BY w.id + "#, + &[&user_id], + ) + .await + .map_err(|_| AppError::Database)?; + + match row { + None => Err(AppError::NotFound), + Some(r) => Ok(WalletResponse { + wallet_id: r.get("id"), + address: r.get("address_hex"), + mnemonic: None, // 查询时不返回助记词 + created_at: r.get("created_at"), + }), + } +}