stealth address sdk
v1.0.0-beta.1
TypeScript SDK ini menyediakan alat untuk bekerja dengan alamat siluman Ethereum seperti yang didefinisikan dalam EIP-5564 dan EIP-6538. Ini bertujuan untuk menawarkan serangkaian fungsi komprehensif untuk menghasilkan alamat siluman dan berinteraksi dengan transaksi siluman.
Untuk dokumentasi komprehensif dan mempelajari lebih lanjut tentang alamat tersembunyi, silakan kunjungi situs dokumentasi resmi kami.
Informasi tentang penerapan kontrak dapat ditemukan di halaman penerapan di situs dokumentasi resmi kami.
npm install @scopelift/stealth-address-sdk
# or
yarn add @scopelift/stealth-address-sdk
# or
bun install @scopelift/stealth-address-sdk
Pengujian default menggunakan simpul landasan lokal Anda
anvil
bun run test
Alternatifnya, jalankan pengujian Anda menggunakan fork url rpc ( RPC_URL
dalam env
) yang Anda sediakan
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 ;
}
Lisensi MIT