Skip to content

Commit

Permalink
v0.3.16: add mfu support. (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
taichunmin authored Aug 4, 2024
2 parents f31fc71 + 095df72 commit 2b9a2ba
Show file tree
Hide file tree
Showing 27 changed files with 1,442 additions and 429 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<p>A JavaScript SDK for ChameleonUltra support Web Bluetooth API, Web Serial API and Node.js.</p>

<p>
<a href="https://github.com/taichunmin/chameleon-ultra.js/blob/master/pages/demos.md"><b>Demo</b></a> •
<a href="https://taichunmin.idv.tw/chameleon-ultra.js/documents/Demos.html"><b>Demo</b></a> •
<a href="https://taichunmin.idv.tw/chameleon-ultra.js/"><b>Documentation</b></a> •
<a href="https://taichunmin.idv.tw/chameleon-ultra.js/classes/index.ChameleonUltra.html"><b>Reference</b></a>
</p>
Expand Down
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"module": "./dist/index.mjs",
"name": "chameleon-ultra.js",
"type": "commonjs",
"version": "0.3.15",
"version": "0.3.16",
"bugs": {
"url": "https://github.com/taichunmin/chameleon-ultra.js/issues"
},
Expand All @@ -20,9 +20,9 @@
}
],
"dependencies": {
"@taichunmin/buffer": "^0.13.6",
"@taichunmin/crc": "^0.0.13",
"debug": "^4.3.5",
"@taichunmin/buffer": "^0.13.7",
"@taichunmin/crc": "^0.0.14",
"debug": "^4.3.6",
"jszip": "^3.10.1",
"lodash": "^4.17.21",
"serialport": "^12.0.0",
Expand All @@ -37,25 +37,25 @@
"@types/jest": "^29.5.12",
"@types/livereload": "^0.9.5",
"@types/lodash": "^4.17.7",
"@types/node": "^20.14.10",
"@types/node": "^22.0.2",
"@types/pug": "^2.0.10",
"@types/serve-static": "^1.15.7",
"@types/uglify-js": "^3.17.5",
"@types/web-bluetooth": "^0.0.20",
"@typescript-eslint/eslint-plugin": "^7.16.1",
"@typescript-eslint/parser": "^7.16.1",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"chokidar": "^3.6.0",
"concurrently": "^8.2.2",
"dayjs": "^1.11.11",
"dayjs": "^1.11.12",
"dotenv": "^16.4.5",
"esbuild-plugins-node-modules-polyfill": "^1.6.4",
"eslint": "^8.57.0",
"eslint-config-love": "^43",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-local-rules": "^3.0.2",
"eslint-plugin-n": "^17.9.0",
"eslint-plugin-promise": "^6.4.0",
"eslint-plugin-n": "^17.10.1",
"eslint-plugin-promise": "^7.0.0",
"eslint-plugin-pug": "^1.2.5",
"eslint-plugin-tsdoc": "^0.3.0",
"finalhandler": "^1.2.0",
Expand All @@ -69,16 +69,16 @@
"rimraf": "^6.0.1",
"serve-static": "^1.15.0",
"supports-color": "^9.4.0",
"ts-jest": "^29.2.2",
"ts-jest": "^29.2.4",
"ts-node": "^10.9.2",
"tsup": "^8.1.0",
"tsx": "^4.16.2",
"typedoc": "^0.26.4",
"typedoc-plugin-mdn-links": "^3.2.4",
"tsup": "^8.2.3",
"tsx": "^4.16.5",
"typedoc": "^0.26.5",
"typedoc-plugin-mdn-links": "^3.2.6",
"typedoc-plugin-missing-exports": "^3.0.0",
"typedoc-plugin-rename-defaults": "^0.7.1",
"typedoc-plugin-zod": "^1.2.0",
"typescript": "^5.5.3",
"typescript": "^5.5.4",
"utility-types": "^3.11.0"
},
"exports": {
Expand Down Expand Up @@ -168,7 +168,7 @@
"build:pug": "tsx ./pug/build.ts",
"build:sitemap": "tsx ./sitemap.ts",
"build": "yarn build:js && yarn build:docs && yarn build:pug && yarn build:sitemap",
"dev:docs": "nodemon --watch src --ext ts,md --exec \"yarn build:docs\"",
"dev:docs": "nodemon --watch src --watch pages --ext ts,md --exec \"yarn build:docs\"",
"dev:https": "tsx ./https.ts",
"dev:js": "yarn build:js --watch",
"dev:pug": "nodemon --watch pug --ext pug --exec \"yarn build:pug\"",
Expand Down
16 changes: 6 additions & 10 deletions pages/demos.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
# Demos
---
title: Demos
group: Documents
category: Guides
---

- [Demos](#demos)
- [device-settings.html](#device-settingshtml)
- [dfu.html](#dfuhtml)
- [mfkey32.html](#mfkey32html)
- [mifare1k.html](#mifare1khtml)
- [hf14a-scanner.html](#hf14a-scannerhtml)
- [mifare-xiaomi.html](#mifare-xiaomihtml)
- [mifare-value.html](#mifare-valuehtml)
- [lf-em410x.html](#lf-em410xhtml)
# Demos

## [device-settings.html](https://taichunmin.idv.tw/chameleon-ultra.js/device-settings.html)

Expand Down
10 changes: 10 additions & 0 deletions pug/include/bootstrapV4.pug
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,14 @@ html(lang="zh-Hant")
script(crossorigin="anonymous", src=`${baseurl}plugin/DfuZip.global.js`)
script(crossorigin="anonymous", src=`${baseurl}plugin/WebbleAdapter.global.js`)
script(crossorigin="anonymous", src=`${baseurl}plugin/WebserialAdapter.global.js`)
script(type="importmap").
{
"imports": {
"@taichunmin/buffer": "https://cdn.jsdelivr.net/npm/@taichunmin/buffer@0/+esm",
"@taichunmin/crc/crc16a": "https://cdn.jsdelivr.net/npm/@taichunmin/crc@0/crc16a/+esm",
"@taichunmin/crc/crc32": "https://cdn.jsdelivr.net/npm/@taichunmin/crc@0/crc32/+esm",
"jszip": "https://cdn.jsdelivr.net/npm/jszip/+esm",
"lodash": "https://cdn.jsdelivr.net/npm/lodash/+esm"
}
}
block script
2 changes: 1 addition & 1 deletion pug/src/hf14a-scanner.pug
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ block script
const newTags = []
for (const tag of scanned) {
newTags.push({
atqa: toHex(tag.atqa.reverse()),
atqa: toHex(tag.atqa.toReversed()),
sak: toHex(tag.sak),
ts: Date.now(),
uid: toHex(tag.uid),
Expand Down
2 changes: 1 addition & 1 deletion pug/src/lf-em410x.pug
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ block script
ultraBle.use(new WebbleAdapter())

const toHex = buf => _.toUpper(buf.toString('hex'))
const WELL_KNOWN_KEYS = ['19920427', '51243648']
const WELL_KNOWN_KEYS = ['1DD00A11', '19920427', '51243648']

window.vm = new Vue({
el: '#app',
Expand Down
7 changes: 4 additions & 3 deletions pug/src/mfkey32.pug
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ block script
const ultraBle = new ChameleonUltra()
ultraBle.use(new Debug())
ultraBle.use(new WebbleAdapter())
const toHex = buf => _.toUpper(buf.toString('hex'))

window.vm = new Vue({
el: '#app',
Expand Down Expand Up @@ -166,10 +167,10 @@ block script
const tag1 = _.first(await ultra.cmdHf14aScan())
await ultra.cmdChangeDeviceMode(DeviceMode.TAG)
const tag2 = {
atqa: _.toUpper(tag1.atqa.reverse().toString('hex')),
sak: _.toUpper(tag1.sak.toString('hex')),
atqa: toHex(tag1.atqa.toReversed()),
sak: toHex(tag1.sak),
slot,
uid: _.toUpper(tag1.uid.toString('hex')),
uid: toHex(tag1.uid),
}
tag2.tagType = (tag2.atqa === '0002' && tag2.sak === '18') ? 1 : 0
console.log(tag2)
Expand Down
2 changes: 1 addition & 1 deletion pug/src/mifare-xiaomi.pug
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ block script
dumpB64: dump.toString('base64url'),
uid: toHex(dump.subarray(0, 4)),
sak: toHex(dump.subarray(5, 6)),
atqa: toHex(dump.subarray(6, 8).reverse()),
atqa: toHex(dump.subarray(6, 8).toReversed()),
})
},
showLoading (opts = {}) {
Expand Down
2 changes: 1 addition & 1 deletion pug/src/mifare1k.pug
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ block script
mfCardSetAntiColl (hf14aAntiColl) {
for (const k of ['uid', 'atqa', 'sak', 'ats']) {
let buf = hf14aAntiColl?.[k] ?? new Buffer()
if (k === 'atqa') buf = buf.reverse()
if (k === 'atqa') buf = buf.toReversed()
this.$set(this.ss, k, buf.toString('hex'))
}
},
Expand Down
8 changes: 4 additions & 4 deletions src/ChameleonUltra.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import _ from 'lodash'
import { Buffer } from '@taichunmin/buffer'
import _ from 'lodash'
import { ChameleonUltra } from './ChameleonUltra'
import BufferMockAdapter from './plugin/BufferMockAdapter'
import {
AnimationMode,
ButtonAction,
Expand All @@ -17,6 +16,7 @@ import {
Slot,
TagType,
} from './enums'
import BufferMockAdapter from './plugin/BufferMockAdapter'

describe('ChameleonUltra with BufferMockAdapter', () => {
let ultra: ChameleonUltra
Expand Down Expand Up @@ -1133,7 +1133,7 @@ describe('ChameleonUltra with BufferMockAdapter', () => {
adapter.send.push(Buffer.from('11ef 07da 0000 0010 0f 040dc445420d2981e7480000e1100600 c7', 'hex'))

// act
const actual = await ultra.mfuReadPages({ pageOffset: 0 })
const actual = await ultra.mfuReadPages({ start: 0 })

// assert
expect(actual).toEqual(Buffer.from('040dc445420d2981e7480000e1100600', 'hex'))
Expand All @@ -1149,7 +1149,7 @@ describe('ChameleonUltra with BufferMockAdapter', () => {
adapter.send.push(Buffer.from('11ef 07da 0000 0000 1f 00', 'hex'))

// act
await ultra.mfuWritePage({ pageOffset: 9, data: Buffer.from('00000000', 'hex') })
await ultra.mfuWritePage({ start: 9, data: Buffer.from('00000000', 'hex') })

// assert
expect(adapter.recv).toEqual([
Expand Down
Loading

0 comments on commit 2b9a2ba

Please sign in to comment.