Decode and encode Token V4 #73
No reviewers
Labels
No labels
DB & Storage
Deployment
Error Handling & Logging
Maintenance
Payment Backend
backport
backport v0.13.x
backport v0.14.x
backport v0.15.x
bindings
blocked
bug
cdk-sql
ci
cli
deps
documentation
duplicate
enhancement
good first issue
help wanted
invalid
keep-open
ldk-node-ui
migrations
mint
mutation-testing
needs rebase
needs review
new nut
nut change
question
ready
rust-version
rustfmt
stacked hold
stale
testing
wallet
weekly-report
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
cashubtc/cdk!73
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "token-v4"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #68
I have an open question on the draft NUT if secrets should be bytes instead of strings: https://github.com/cashubtc/nuts/pull/109/files#r1555859864. However, as it stands, this successfully decodes and encodes v4 tokens.
⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.
Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.
🔎 Detected hardcoded secret in your pull request
b1bf4506a0🛠 Guidelines to remediate hardcoded secrets
To avoid such incidents in the future consider
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
Our GitHub checks need improvements? Share your feedbacks!
Thanks for this. Going to leave open for now as the NUT is still a draft
@ -0,0 +39,4 @@serde_json = { workspace = true }serde_with = "3.4.0"url = { workspace = true }itertools = "0.12.0"I would recommend always adding a dependency with the default-features set to
falseand than manually importing the features that you want to use in the project. This helps with:For this specific one:
@ -0,0 +363,4 @@for proof in &proofs.proofs {amount += proof.amount;}}should this
println!be here?@ -0,0 +411,4 @@token: token.token.into_iter().map(Into::into).collect(),memo: token.memo,unit: token.unit,}Is there a specific reason to use ciborium here? woudn't
serde_json::from_slicebe enough?@ -0,0 +363,4 @@for proof in &proofs.proofs {amount += proof.amount;}}@ -0,0 +363,4 @@for proof in &proofs.proofs {amount += proof.amount;}}i highly discourage using
unwrap.Recommend going with
expectand adding useful log to the user@ -0,0 +47,4 @@const STRLEN: usize = 14;pub fn to_bytes(&self) -> Vec<u8> {hex::decode(self.to_string()).unwrap()maybe go with
expectinstead ofunwrapif changing the function signature is not an option@ -0,0 +47,4 @@const STRLEN: usize = 14;pub fn to_bytes(&self) -> Vec<u8> {hex::decode(self.to_string()).unwrap()i would rather we change the function signature to a result
@ -0,0 +363,4 @@for proof in &proofs.proofs {amount += proof.amount;}}I agree unwrap should only be allowed within tests. Ideally a specific and useful error is returned
@ -0,0 +363,4 @@for proof in &proofs.proofs {amount += proof.amount;}}Lets remove the print an output is needed it should be a log message not print.
@ -0,0 +564,4 @@}}impl From<ProofV4> for Proof {I think these can be removed now that your question on the Nut is resolved?
Just a few small changes. @lorenzolfm called out around the use of unwrap
@ -0,0 +47,4 @@const STRLEN: usize = 14;pub fn to_bytes(&self) -> Vec<u8> {hex::decode(self.to_string()).unwrap()then maybe the function name should be
try_into_bytes🤔@ -0,0 +411,4 @@token: token.token.into_iter().map(Into::into).collect(),memo: token.memo,unit: token.unit,}The decoded bytes are CBOR not JSON.
@ -0,0 +47,4 @@const STRLEN: usize = 14;pub fn to_bytes(&self) -> Vec<u8> {hex::decode(self.to_string()).unwrap()I don't think we should change the signature because this should never fail. However, the only reason it can fail now is that we store the hex string instead of the bytes in this object. Ideally, the
Idstruct should hold the bytes. Should I mark this as a TODO for now and follow up with a refactor shortly?@ -0,0 +47,4 @@const STRLEN: usize = 14;pub fn to_bytes(&self) -> Vec<u8> {hex::decode(self.to_string()).unwrap()Yes that makes sense
Closing in favor of new PR given the major code refactor.
Yeah sorry about that
No worries!
Pull request closed