-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: increase test coverage, deterministic stealth meta address gen, (…
…#46) * feat: improve coverage * feat: coverage to .98 * package: update viem * feat: large num of announcements to 100 for testing speed * feat: biome for linting and formatting (#56) * feat: deterministic gen stealth meta address (#60) * fix: valid compressed key input type clarity * feat: get stealth meta address from keys * feat: is valid pub key * feat: is valid key tests * feat: gen keys from sig * feat: extract portions into own func for testing * feat: get stealth meta address from signature * feat: example for gen stealth meta address from sig * Update examples/generateDeterministicStealthMetaAddress/README.md * feat: send and receive test (#62) * feat: handle just passing the stealth meta-address directly * feat: send and receive test --------- Co-authored-by: Gary Ghayrat <[email protected]>
- Loading branch information
1 parent
126062a
commit d7ddf54
Showing
79 changed files
with
1,969 additions
and
697 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
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
# Configuration and development tools | ||
.prettierrc | ||
.bun | ||
tsconfig.json | ||
README.md | ||
|
This file was deleted.
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,43 @@ | ||
{ | ||
"$schema": "https://biomejs.dev/schemas/1.6.4/schema.json", | ||
"vcs": { | ||
"root": ".", | ||
"enabled": true, | ||
"clientKind": "git", | ||
"useIgnoreFile": true | ||
}, | ||
"organizeImports": { | ||
"enabled": true | ||
}, | ||
"linter": { | ||
"enabled": true, | ||
"rules": { | ||
"recommended": true | ||
} | ||
}, | ||
"files": { | ||
"include": ["src/**/*.ts", "examples/**/*.ts", "biome.json"] | ||
}, | ||
"formatter": { | ||
"enabled": true, | ||
"formatWithErrors": false, | ||
"ignore": [], | ||
"attributePosition": "auto", | ||
"indentStyle": "tab", | ||
"indentWidth": 2, | ||
"lineEnding": "lf", | ||
"lineWidth": 80 | ||
}, | ||
"javascript": { | ||
"globals": ["NodeJS"], | ||
"formatter": { | ||
"enabled": true, | ||
"lineWidth": 80, | ||
"indentWidth": 2, | ||
"indentStyle": "space", | ||
"quoteStyle": "single", | ||
"arrowParentheses": "asNeeded", | ||
"trailingComma": "none" | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[test] | ||
coverageSkipTestFiles = true | ||
coverageThreshold = 0 | ||
coverageThreshold = 0.8 | ||
root = "./src" |
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
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
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 @@ | ||
VITE_RPC_URL='Your rpc url' |
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 @@ | ||
# Generate Deterministic Stealth Meta-Address Example |
Binary file not shown.
12 changes: 12 additions & 0 deletions
12
examples/generateDeterministicStealthMetaAddress/index.html
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,12 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
</head> | ||
<body> | ||
<h1>Generate Deterministic Stealth Meta-address Example</h1> | ||
<div id="root"></div> | ||
<script type="module" src="/index.tsx"></script> | ||
</body> | ||
</html> |
81 changes: 81 additions & 0 deletions
81
examples/generateDeterministicStealthMetaAddress/index.tsx
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,81 @@ | ||
import React, { useState } from "react"; | ||
import ReactDOM from "react-dom/client"; | ||
import { Address, createWalletClient, custom } from "viem"; | ||
import { sepolia } from "viem/chains"; | ||
import "viem/window"; | ||
|
||
import { generateStealthMetaAddressFromSignature } from "@scopelift/stealth-address-sdk"; | ||
|
||
/** | ||
* This React component demonstrates the process of generating a stealth meta-address deterministically using a user-signed message | ||
* It's deterministic in that the same stealth meta-address is generated for the same user, chain id, and message | ||
* It utilizes Viem's walletClient for wallet interaction | ||
* | ||
* @returns The component renders a button to first handle connecting the wallet, and a subsequent button to handle stealth meta-address generation | ||
* | ||
* @example | ||
* To run the development server: `bun run dev`. | ||
*/ | ||
const Example = () => { | ||
// Initialize your configuration | ||
const chain = sepolia; // Example Viem chain | ||
|
||
// Initialize Viem wallet client if using Viem | ||
const walletClient = createWalletClient({ | ||
chain, | ||
transport: custom(window.ethereum!), | ||
}); | ||
|
||
// State | ||
const [account, setAccount] = useState<Address>(); | ||
const [stealthMetaAddress, setStealthMetaAddress] = useState<`0x${string}`>(); | ||
|
||
const connect = async () => { | ||
const [address] = await walletClient.requestAddresses(); | ||
setAccount(address); | ||
}; | ||
|
||
const signMessage = async () => { | ||
// An example message to sign for generating the stealth meta-address | ||
// Usually this message includes the chain id to mitigate replay attacks across different chains | ||
// The message that is signed should clearly communicate to the user what they are signing and why | ||
const MESSAGE_TO_SIGN = `Generate Stealth Meta-Address on ${chain.id} chain`; | ||
|
||
if (!account) throw new Error("A connected account is required"); | ||
|
||
const signature = await walletClient.signMessage({ | ||
account, | ||
message: MESSAGE_TO_SIGN, | ||
}); | ||
|
||
return signature; | ||
}; | ||
|
||
const handleSignAndGenStealthMetaAddress = async () => { | ||
const signature = await signMessage(); | ||
const stealthMetaAddress = | ||
generateStealthMetaAddressFromSignature(signature); | ||
|
||
setStealthMetaAddress(stealthMetaAddress); | ||
}; | ||
|
||
if (account) | ||
return ( | ||
<> | ||
{!stealthMetaAddress ? ( | ||
<button onClick={handleSignAndGenStealthMetaAddress}> | ||
Generate Stealth Meta-Address | ||
</button> | ||
) : ( | ||
<div>Stealth Meta-Address: {stealthMetaAddress}</div> | ||
)} | ||
<div>Connected: {account}</div> | ||
</> | ||
); | ||
|
||
return <button onClick={connect}>Connect Wallet</button>; | ||
}; | ||
|
||
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render( | ||
<Example /> | ||
); |
21 changes: 21 additions & 0 deletions
21
examples/generateDeterministicStealthMetaAddress/package.json
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,21 @@ | ||
{ | ||
"name": "example-generate-deterministic-stealth-meta-address", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite" | ||
}, | ||
"dependencies": { | ||
"@types/react": "^18.2.61", | ||
"@types/react-dom": "^18.2.19", | ||
"@vitejs/plugin-react": "^4.2.1", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"@scopelift/stealth-address-sdk": "latest", | ||
"viem": "latest", | ||
"vite": "latest" | ||
}, | ||
"devDependencies": { | ||
"typescript": "^5.3.3" | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
examples/generateDeterministicStealthMetaAddress/tsconfig.json
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,17 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"lib": ["ESNext", "DOM", "DOM.Iterable"], | ||
"moduleResolution": "Node", | ||
"strict": true, | ||
"esModuleInterop": true, | ||
"noEmit": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noImplicitReturns": true, | ||
"skipLibCheck": true, | ||
"jsx": "react", | ||
}, | ||
"include": ["."], | ||
} |
7 changes: 7 additions & 0 deletions
7
examples/generateDeterministicStealthMetaAddress/vite.config.ts
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,7 @@ | ||
import react from '@vitejs/plugin-react'; | ||
import { defineConfig } from 'vite'; | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [react()] | ||
}); |
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
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.