stealth address sdk
v1.0.0-beta.1
이 TypeScript SDK는 EIP-5564 및 EIP-6538에 정의된 대로 Ethereum 스텔스 주소로 작업하기 위한 도구를 제공합니다. 스텔스 주소 생성과 스텔스 트랜잭션과의 상호 작용을 위한 포괄적인 기능 제품군을 제공하는 것을 목표로 합니다.
포괄적인 문서와 스텔스 주소에 대해 자세히 알아보려면 공식 문서 사이트를 방문하세요.
계약 배포에 대한 정보는 공식 문서 사이트의 배포 페이지에서 확인할 수 있습니다.
npm install @scopelift/stealth-address-sdk
# or
yarn add @scopelift/stealth-address-sdk
# or
bun install @scopelift/stealth-address-sdk
테스트에서는 기본적으로 로컬 앤빌 노드를 사용합니다.
anvil
bun run test
또는 제공된( env
의 RPC_URL
) rpc url 포크를 사용하여 테스트를 실행하세요.
bun run anvil-fork
# run all tests
bun run test-fork
# or for a specific file
bun run test-fork FILE={file path}
import { generateStealthAddress } from "@scopelift/stealth-address-sdk" ;
// Your stealth meta-address URI
// Follows the format: "st:<chain>:<stealthMetaAddress>", where <chain> is the chain identifier (https://eips.ethereum.org/EIPS/eip-3770#examples) and <stealthMetaAddress> is the stealth meta-address.
const stealthMetaAddressURI = "..." ;
// Generate a stealth address using the default scheme (1)
// To learn more about the initial implementation scheme using SECP256k1, please see the reference here (https://eips.ethereum.org/EIPS/eip-5564)
const result = generateStealthAddress ( { stealthMetaAddressURI } ) ;
// Use the stealth address
console . log ( result . stealthAddress ) ;
import {
computeStealthKey ,
VALID_SCHEME_ID ,
} from "@scopelift/stealth-address-sdk" ;
// Example inputs
const viewingPrivateKey = "0x..." ; // Viewing private key of the recipient
const spendingPrivateKey = "0x..." ; // Spending private key of the recipient
const ephemeralPublicKey = "0x..." ; // Ephemeral public key from the sender's announcement
const schemeId = VALID_SCHEME_ID . SCHEME_ID_1 ; // Scheme ID, currently only '1' is supported
// Compute the stealth private key
const stealthPrivateKey = computeStealthKey ( {
viewingPrivateKey ,
spendingPrivateKey ,
ephemeralPublicKey ,
schemeId ,
} ) ;
import {
checkStealthAddress ,
VALID_SCHEME_ID ,
} from "@scopelift/stealth-address-sdk" ;
// Example inputs
const ephemeralPublicKey = "0x..." ; // The ephemeral public key from the announcement
const spendingPublicKey = "0x..." ; // The user's spending public key
const userStealthAddress = "0x..." ; // The user's stealth address
const viewingPrivateKey = "0x..." ; // The user's viewing private key
const viewTag = "0x..." ; // The view tag from the announcement
const schemeId = VALID_SCHEME_ID . SCHEME_ID_1 ; // Scheme ID, currently only '1' is supported
// Check if the announcement is intended for the user
const isForUser = checkStealthAddress ( {
ephemeralPublicKey ,
schemeId ,
spendingPublicKey ,
userStealthAddress ,
viewingPrivateKey ,
viewTag ,
} ) ;
console . log (
isForUser
? "Announcement is for the user"
: "Announcement is not for the user"
) ;
import {
ERC5564_CONTRACT_ADDRESS ,
VALID_SCHEME_ID ,
createStealthClient ,
} from "@scopelift/stealth-address-sdk" ;
// Example parameters
const chainId = 11155111 ; // Example chain ID for Sepolia
const rpcUrl = process . env . RPC_URL ; // Your env rpc url that aligns with the chainId;
const fromBlock = BigInt ( 12345678 ) ; // Example ERC5564 announcer contract deploy block for Sepolia, or the block in which the user registered their stealth meta address (as an example)
// Initialize the stealth client
const stealthClient = createStealthClient ( { chainId , rpcUrl : rpcUrl ! } ) ;
// Use the address of your calling contract if applicable
const caller = "0xYourCallingContractAddress" ;
// Your scheme id
const schemeId = BigInt ( VALID_SCHEME_ID . SCHEME_ID_1 ) ;
// The contract address of the ERC5564Announcer on your target blockchain
// You can use the provided ERC5564_CONTRACT_ADDRESS get the singleton contract address for a valid chain ID
const ERC5564Address = ERC5564_CONTRACT_ADDRESS ;
async function fetchAnnouncementsForUser ( ) {
// Example call to getAnnouncements action on the stealth client to get all potential announcements
// Use your preferred method to get announcements if different, and
// adjust parameters according to your requirements
const announcements = await stealthClient . getAnnouncements ( {
ERC5564Address ,
args : {
schemeId ,
caller ,
// Additional args for filtering, if necessary
} ,
fromBlock , // Optional fromBlock parameter (defaults to 0, which can be slow for many blocks)
} ) ;
// Example call to getAnnouncementsForUser action on the stealth client
// Adjust parameters according to your requirements
const userAnnouncements = await stealthClient . getAnnouncementsForUser ( {
announcements ,
spendingPublicKey : "0xUserSpendingPublicKey" ,
viewingPrivateKey : "0xUserViewingPrivateKey" ,
} ) ;
return userAnnouncements ;
}
MIT 라이센스