feat: implement fiber wasm demo#367
Conversation
ashuralyk
commented
Apr 16, 2026
- I have read the Contributing Guidelines
✅ Deploy Preview for docsccc ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for apiccc ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for liveccc ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
✅ Deploy Preview for appccc ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Code Review
This pull request adds a Fiber node demo for managing in-browser nodes, peers, and payments. Feedback focuses on narrowing security header scope to maintain wallet compatibility, fixing signature byte conversion for key derivation, and replacing floating-point math with fixed-point utilities to ensure precision for CKB amounts.
| async headers() { | ||
| return [ | ||
| { | ||
| source: "/(.*)", |
There was a problem hiding this comment.
The source pattern /(.*) applies the COOP and COEP headers to all routes. However, the comments on lines 9-12 state that these headers should only be applied to /connected/Fiber because they break cross-origin wallet popups (like JoyID) used on other pages. Applying these headers globally will break wallet functionality for the rest of the application, including the /fiber-sign-proxy mentioned in the comments.
| source: "/(.*)", | |
| source: "/connected/Fiber", |
| addLog("info", `Signing "${message}"…`); | ||
| try { | ||
| const sig = await signer.signMessage(message); | ||
| const sigBytes = new TextEncoder().encode(sig.signature); |
There was a problem hiding this comment.
The sig.signature returned by CCC signers is a hex string. Using TextEncoder().encode() will encode the literal characters of the hex string (e.g., '0', 'x', 'a'...) rather than the actual bytes of the signature. This results in incorrect entropy for the derived keys. Use ccc.bytesFrom() to correctly parse the hex signature into bytes, adhering to the repository's standard for handling hex-like types.
| const sigBytes = new TextEncoder().encode(sig.signature); | |
| const sigBytes = ccc.bytesFrom(sig.signature); |
References
- Functions should accept more generic types like HexLike and perform necessary type conversions internally, rather than requiring the caller to do so.
| const result = await invoke<FjOpenChannel>("open_channel", [ | ||
| { | ||
| pubkey: peerId, | ||
| funding_amount: ccc.numToHex(Math.round(Number(fundingAmount) * 1e8)), |
There was a problem hiding this comment.
Using floating-point arithmetic (Number(fundingAmount) * 1e8) to handle CKB amounts can lead to precision issues. It is safer to use ccc.fixedPointFrom(fundingAmount, 8) which handles decimal parsing using bigint internally to avoid floating-point errors.
| funding_amount: ccc.numToHex(Math.round(Number(fundingAmount) * 1e8)), | |
| funding_amount: ccc.numToHex(ccc.fixedPointFrom(fundingAmount, 8)), |
| const preimage = ccc.hexFrom(crypto.getRandomValues(new Uint8Array(32))); | ||
| const result = await invoke<FjInvoice>("new_invoice", [ | ||
| { | ||
| amount: ccc.numToHex(ccc.numFrom(Math.round(Number(amount) * 1e8))), |
There was a problem hiding this comment.
Using floating-point arithmetic to handle CKB amounts can lead to precision issues. Use ccc.fixedPointFrom(amount, 8) to safely convert the string input to a shannon-denominated bigint.
| amount: ccc.numToHex(ccc.numFrom(Math.round(Number(amount) * 1e8))), | |
| amount: ccc.numToHex(ccc.fixedPointFrom(amount, 8)), |
|
|
||
| /** Converts a shannon balance (hex) to a CKB string with 4 decimal places. */ | ||
| export function hexToCkb(hex: string): string { | ||
| return (Number(ccc.numFrom(hex)) / 1e8).toFixed(4); |
There was a problem hiding this comment.
Converting large shannon balances to Number can result in precision loss if the value exceeds Number.MAX_SAFE_INTEGER (~90 million CKB). Use ccc.fixedPointToString to safely format bigint balances for display without losing precision.
| return (Number(ccc.numFrom(hex)) / 1e8).toFixed(4); | |
| return ccc.fixedPointToString(ccc.numFrom(hex), 8); |
