-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b45ec4
commit db888b1
Showing
5 changed files
with
393 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { ethers } from 'ethers'; | ||
|
||
function base64ToBytes(base64: string): Buffer { | ||
return Buffer.from(base64, 'base64'); | ||
} | ||
|
||
function bytesToUint256Array(bytes: Buffer): string[] { | ||
const uint256Array: string[] = []; | ||
for (let i = 0; i < bytes.length; i += 32) { | ||
const chunk = bytes.subarray(i, i + 32); | ||
uint256Array.push(ethers.toBigInt(chunk).toString()); | ||
} | ||
return uint256Array; | ||
} | ||
|
||
// 立即执行的异步函数 | ||
(async () => { | ||
|
||
// 示例数据 | ||
const pubkeyBase64 = 'shxvsYSiVXG/HoCOSO1RFeYzeMBvCxVV/bEPzTk4CH9cZz73ejD5LhrzHIw40UST'; | ||
const msgBase64 = 'YWJj'; | ||
const sigBase64 = 'sKSxcK9kYEpZ0KJbbCbyMSHOjcf6ffauBjVD4TIYYiZaDh69pPugobhxMrj358fRAXt+NdXUkP9HfmqRXPSub8xfVi6alfZ8bGbUvWOK2KN/4S/OLPQaO+BYWZKY2/SF'; | ||
|
||
|
||
// 解码并转换为 uint256 数组 | ||
const pubkeyBytes = base64ToBytes(pubkeyBase64); | ||
const msgBytes = base64ToBytes(msgBase64); | ||
const sigBytes = base64ToBytes(sigBase64); | ||
|
||
const pubkeyUint256Array = bytesToUint256Array(pubkeyBytes); | ||
const msgUint256Array = bytesToUint256Array(msgBytes); | ||
const sigUint256Array = bytesToUint256Array(sigBytes); | ||
|
||
console.log('Public Key:', pubkeyUint256Array); | ||
console.log('Message:', msgUint256Array); | ||
console.log('Signature:', sigUint256Array); | ||
})(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "account-contracts", | ||
"version": "1.0.0", | ||
"description": "**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**", | ||
"main": "index.js", | ||
"type": "module", | ||
"directories": { | ||
"lib": "lib", | ||
"test": "test" | ||
}, | ||
"scripts": { | ||
"start": "npx tsx index.tsx", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"ethers": "^6.13.3" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^22.7.4", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.6.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.