Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nfc: add support for binary tokens (crawB) #296

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@capacitor/core": "^6.2.0",
"@capacitor/haptics": "^6.0.2",
"@capacitor/ios": "^6.0.0",
"@cashu/cashu-ts": "^2.0.0-rc3",
"@cashu/cashu-ts": "^2.2.0-rc3",
"@cashu/crypto": "^0.3.4",
"@chenfengyuan/vue-qrcode": "^2.0.0",
"@gandlaf21/bc-ur": "^1.1.12",
Expand Down
22 changes: 14 additions & 8 deletions src/components/SendTokenDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,12 @@ import { Buffer } from "buffer";
import { useCameraStore } from "src/stores/camera";
import { useP2PKStore } from "src/stores/p2pk";
import TokenInformation from "components/TokenInformation.vue";
import { getDecodedToken, getEncodedTokenV4 } from "@cashu/cashu-ts";
import {
getDecodedToken,
getEncodedTokenBinary,
getEncodedToken,
getEncodedTokenV4,
} from "@cashu/cashu-ts";

import { mapActions, mapState, mapWritableState } from "pinia";
import ChooseMint from "components/ChooseMint.vue";
Expand All @@ -477,7 +482,6 @@ import {
notify,
notifyWarning,
} from "src/js/notify.ts";
import { getEncodedTokenV3 } from "@cashu/cashu-ts/dist/lib/es5/utils";
export default defineComponent({
name: "SendTokenDialog",
mixins: [windowMixin],
Expand Down Expand Up @@ -751,10 +755,14 @@ export default defineComponent({
this.sendData.tokensBase64 = getEncodedTokenV4(decodedToken);
} catch {
console.log("### Could not encode token to V4");
this.sendData.tokensBase64 = getEncodedTokenV3(decodedToken);
this.sendData.tokensBase64 = getEncodedToken(decodedToken, {
version: 3,
});
}
} else {
this.sendData.tokensBase64 = getEncodedTokenV3(decodedToken);
this.sendData.tokensBase64 = getEncodedToken(decodedToken, {
version: 3,
});
}
},
deleteThisToken: function () {
Expand Down Expand Up @@ -805,9 +813,8 @@ export default defineComponent({
];
break;
case "binary":
throw new Error("Binary encoding not supported yet");
/*
const data = null;
const token = getDecodedToken(this.sendData.tokensBase64);
const data = getEncodedTokenBinary(token);
records = [
{
recordType: "mime",
Expand All @@ -816,7 +823,6 @@ export default defineComponent({
},
];
break;
*/
default:
throw new Error(
`Unknown NFC encoding: ${this.nfcEncoding}`
Expand Down
10 changes: 2 additions & 8 deletions src/components/SettingsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -568,11 +568,6 @@
</q-item-label>
</q-item-section>
</q-item>
<!--
disable binary for now
TODO: re-enable once we can decode
-->
<!--
<q-item clickable @click="nfcEncoding = 'binary'">
<q-item-section avatar>
<q-icon
Expand All @@ -586,13 +581,12 @@
/>
</q-item-section>
<q-item-section>
<q-item-label title>Raw Binary</q-item-label>
<q-item-label title>Binary</q-item-label>
<q-item-label caption>
Raw bytes instead of Base64. Makes ~33% shorter tokens.
Store tokens as binary data
</q-item-label>
</q-item-section>
</q-item>
-->
<q-item>
<q-toggle
v-model="showNfcButtonInDrawer"
Expand Down
8 changes: 3 additions & 5 deletions src/stores/receiveTokensStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
notify,
notifyWarning,
} from "../js/notify";
import { Token } from "@cashu/cashu-ts";
import { getDecodedTokenBinary, getEncodedToken, Token } from "@cashu/cashu-ts";
import { useSwapStore } from "./swap";
import { Clipboard } from "@capacitor/clipboard";

Expand Down Expand Up @@ -177,10 +177,8 @@ export const useReceiveTokensStore = defineStore("receiveTokensStore", {
"binary data does not contain a cashu token"
);
}
// TODO: decode the binary token from data
throw new Error(
"binary token parsing not implemented yet"
);
const token = getDecodedTokenBinary(data);
tokenStr = getEncodedToken(token);
break;
default:
throw new Error(`unsupported recordType ${recordType}`);
Expand Down
Loading