-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: tweaked invoice rpcs * feat: tests and keyPair util * chore: pnpm lock * fix: use browser window crpyto * chore: createInvoiceTweaked test * chore: revert pnpm-lock changes * chore: move crypto to test * chore: remove wildcard import * fix: rpc tests * chore: bump wasm bundles --------- Co-authored-by: Alex Lewin <[email protected]>
- Loading branch information
1 parent
4d8b515
commit d0a7432
Showing
15 changed files
with
2,600 additions
and
2,883 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,6 @@ | ||
--- | ||
'@fedimint/fedimint-client-wasm-bundler': patch | ||
'@fedimint/fedimint-client-wasm-web': patch | ||
--- | ||
|
||
Adds tweak invoice rpcs |
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
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,44 @@ | ||
import * as secp256k1 from 'secp256k1' | ||
|
||
const randomBytes = (size: number): Uint8Array => { | ||
const array = new Uint8Array(size) | ||
window.crypto.getRandomValues(array) | ||
return array | ||
} | ||
|
||
interface KeyPair { | ||
secretKey: string | ||
publicKey: string | ||
} | ||
|
||
export const keyPair = (secretKey?: Uint8Array): KeyPair => { | ||
const privateKey: Uint8Array = secretKey | ||
? validatePrivateKey(secretKey) | ||
: generatePrivateKey() | ||
|
||
const publicKey = secp256k1.publicKeyCreate(privateKey) | ||
|
||
return { | ||
secretKey: Array.from(privateKey) | ||
.map((b) => b.toString(16).padStart(2, '0')) | ||
.join(''), // Convert Uint8Array to hex string | ||
publicKey: Array.from(publicKey) | ||
.map((b) => b.toString(16).padStart(2, '0')) | ||
.join(''), // Convert Uint8Array to hex string | ||
} | ||
} | ||
|
||
const validatePrivateKey = (key: Uint8Array): Uint8Array => { | ||
if (!secp256k1.privateKeyVerify(key)) { | ||
throw new Error('Invalid private key provided') | ||
} | ||
return key | ||
} | ||
|
||
const generatePrivateKey = (): Uint8Array => { | ||
let key: Uint8Array | ||
do { | ||
key = randomBytes(32) | ||
} while (!secp256k1.privateKeyVerify(key)) | ||
return key | ||
} |
Oops, something went wrong.