@beechatnetwork/lib-dqx
v0.0.8
Published
The library that allows to build an application that interacts with DQx tags.
Downloads
24
Readme
lib-dqx
The library that allows to build an application that interacts with DQx tags.
Setting up
Install rn-nodeify
See rn-nodeify docs page for more details.
rn-nodeify --install stream,buffer,events,assert --hack
Install react-native-nfc-manager
npm i --save react-native-nfc-manager
Then follow the installation guide in react-native-nfc-manager docs page.
Install @beechat-network/lib-dqx
npm i --save @beechat-network/lib-dqx
Library usage
This library exports the following functions:
dilithiumGenKeyPair
Generate new Dilithium2 key pair.
declare async function dilithiumGenKeyPair({randomBytes: (size: number) => Buffer}): {secretKey: Buffer, publicKey: Buffer};
dilithiumSign
Sign 32 byte challenge using the provided secretKey.
declare async function dilithiumSign({secretKey: Buffer, challenge: Buffer}): Buffer;
dilithiumVerifySig
Verify Dilithium2 signature against the provided 32 byte challenge and public key.
Function prototype:
declare async function dilithiumVerifySig({publicKey: Buffer, challenge: Buffer, signature: Buffer}): boolean;
Function returns true if the signature validation was successful or false otherwise.
Example usage:
import {
dilithiumVerifySig
} from 'lib-dqx';
let publicKey = Buffer.from("74ae33c77b79fdf95c80c262746130a060039e8f2a95dbd9b77bd2824315dd64d2c70e614d5bd1eecb1d685254c96fac0ce2d6fc04f46a6791686c70a96b8c31599e30c1e0796fbea007c736d26d9b3e6a0c2bb0d1098e5b0a0f320ef4d495ebc6134661ace6735610a897fd42c79019e561f52c0065a21f7fd4bcfb5bfa4405b044fd1b7f536d9a179deeb57e217b1c752e70074cdabb18af53da7c735bc2a0cd183b8d93ccbd5f111875f39ce879b1e9903bf6df1f973f5b04224c46b1bde963c1ba256be29c97db24dfc6e70e1de0a168d318a549d19113692c60fc6949d8e8ce3fece35ceb038942ae45faab2709927a32c716432acefda881dba5d6987beb7107d1eb7fc79128aac935f362d7c5b7e1f705ddaa6b35e4d865c62dea04e4979b9ab03c3a74a478fbc74bb7d62bde4d1a79366aac9b7206afa1dcca6222d830f83fed4b5a9b8b747a288d195b1e261d81888827e200e0e421db97c19656aaaa8a82f48144644413b37bc8d87f36f82311fc6932929d983c02153a7df0a406d472df2a93a28fb15b6f39693619564a58a7b2989cb44f9c51c1a3cd2c9ef465d8c846b22ddd130b044270d905b85afb1a81fce0c92c8635f925ad7140ea588bd9438e4081260a44b546c26d4f5408f53fafb02d131d149125a91a82413b5a86dee5d8415b2cb35e23c2623d60f367769fda538fa43c691fc2dcbb567af2dd03cbcc3ff95cfb0ff932f19b7a332747a07c7bda8ca6e53df27d7ec327e5efa8cfa5b2750d1c4f558990a3a5f06c2a1377ff5be8477085abf45eae168239fdcc1ebc0952b97a48e5ec8254891c5003fa1bb0c6f38848a5a5b09365deab69bc2bb381dca27c4b7f0c0a378730b6b83c9f17c1315a3d4d0e0e5ed3c7f23d54ac465dc763800e5c1a53f2a687544f9047c4575246d029f0f318a6e18cbb49d718f891b6f204d2af60765231b3ddc45f0fb8f826d30fb853d20d0f0b707abbe03e806e6f8c881529d60a219e46f3f5058453d98be1f46d125dfdeeee6ff8037daa2b01aba874319bad25fa2dd6336910b813673d27c1add9e7d1cafcfe722c6068640bf3a9556d6a90cdb9ad7d07e905860a8a090bef10540836f6c9205ca128e907c387658788868cec79fa657f131a95b723af2f37ebbb9740f266bb18ed8ff03bbeffc2c659771fb8d3366a2f48245634954919fb6632fb556f2813d795c197b68d885bf1574f7159de4746dc63de00ac1e54b5412b41d347d1c47e73743351a7635eb7a8a39b2357f0a9e4d50b088576f7a085892b6b73d59a5d3413379360b5e3e756212f272836400cb3539949b92b16dd9d27dbe5bda482d3745b73f489db895a08267d0470731f8bacdabd87cbcbbbe6d47ab091725e50ab0ffe89dd1d8a319437ae4031a771293ee415da4266b16966833b81df705db990dd8cf71ec666669221627e9cd319083949fc58b98c2e6a7237a3a91cb409db35de942c07594010cb111ab6ce6deb802b0da6fcd72479442fe082aa01b2c28e5f4515413cf03c0fd16cde5af4aff5982dcd042e46550f27b376d46ffb05b8c21577dc54c03e129b3062f3d7b64a2e9a053d59a4ac4d65415009ef7fa6b86d5c8ea5e5946a3ce8289df6f842b6e70a5bdb8ade054f151c0aecace161529d7ff80e598d3220dc5663114d53408719ab9dadb2b9334d967d9cf9ea9fb8542cc621ae119ed61e733d148aa2307670606a4027c3f76762dd2e507321f96234f6b4396bbd684cde5c7cefd242a9b4b592667a19de55149522be300223fcb02003d9639761cebd9a1dd39a71cb6ad0d4245a24fd65a806ff2c6b28252967a26c1b82b8c39a11f87cd693db", "hex");
let challenge = Buffer.from("0e4222c411e8e688403c2cc2a3aadb9bcdd0947cf082b30b268fc91bc7dafaca", "hex");
let signature = Buffer.from("d127e98447a0c63719bf223d2666d5ecd9b5166f9e3e5b9dd64d29f62761e63d350fa137f00763169119c8520c696dc609500e80a041fa34be91e9ee2734e280c1c864df204d78f39f8ef7ef75ba1312c7867ac6facccf335c2fc87cd266e27538be4c445998633af9e949fcb2cc4d4db481907715540e8b9debc272ead7048f90a8371d848d4b1ded590372947e66d2680697c5f0ea0e643961f0dac32bb721aaeee1f499257dc62f6efb8fe4e359523540e06ca06345765758b52f2b5ec515b51ff0f5b92405c8e0403ee7bdbb45db6b6cc64a943d927cce91d51693d20cf6a6c8a069479ff8828090be729fae735bcc4ca9b3c9cddede846c7a8becd07917ba09390e39426bbcc911a31b4040d55a63bd0ba3c2e64d3739016a704b835f0fdde4166d72f185a404844434dab97c30e865cc6de640eb7da34d63e1ac6f73f51bb8251d25cda515b297b06c5d20a84fe9881418ee0edc830ec7a66519b1802d207eba04c42f41f4964db6c0edff2b1608fae729589639b92e84745990be3876f6fa912e8fd032b8b40895a8147f18f7bfb2c9f300861e8d19767d0dc96f58b6866742a921c29b17466a5458493ea0f2caa062ffa2336fcebaee7e22390252c6830c74183ee3d9d927071b467db50a34cb44d2f95bcbe538121172132f6674d18ae4058921008d31ad92a41963a7359a1b0971e915fe9fe571637449e00c1be747c701c9dd3722dade3ce86ebab942bdc0ecb0420e851447a30135d06e0bc0e2ec65f7d6fb9c60e319c08e0a08daf32c5076e6981761a7399a5c448b862d0c2beb656fc2fcf3ed40495292891f8393e872cd6d80dd2e50bc2fa5a60e57be452dd34b984dfdf3fbdb7b83c9b546cd17a020f214c7fd7cf71b8b8c3ce5fe51dcf5c549faf0aa8293d560623f45dd358f97c38a3c22d41a988e12698997066a39dcad17dfa9bca603df840721f45ea6fe237f948847c8e2720340b151167e605647bd01fa88574e443078259d879f875326ec5df915db7208db6129d5dd3642377093ad7eef299afe018de263523d031d0c4c018248348a329174fedbde44bddf6016fa493ac3d218182f1220d51701ce6ad64a0e13c66fba102f991541886f8afbfb0c35b0e7317b4fffb2770d9929fb539e392e313ae559ee954e93be8e0ab739443da784959e49f555c418c6e984e2b945c53873913eda66834bb5a092d5f577f9d8a89d7397493d70f914c960b8401a10d6f27292292f0944567a50dba3b19b9c8976fcace8b5fe76a3ffd8f7d8d1ad18822aeb086833165e2b1cbd02960861ef8532301905e1be89e5a13f57f1c890cebd094d10fd803c8d3556503c35edd7e1d50f9e519ad43f36c8d2d41f08591a1e813b63317f3af77b2b196c97eeac4d6b9f8cfca73c34d74a2ff9d0bcc27ba96cd6ebbf569c4e0ef0923863dec6ee2f9be3bc93cbce165861307fa707b73bae00f52c8d5f9307032a660ef7e24e05ace964b750190672ef45fba32b9b74e6523911c779168da98124141ecd3d08ceadb689711adcb813b47f9f4d4672402d00ef95f0d91594b6fb76d6ec18b920e990d55bbe236a29d58d60ba1960b71fc3ab34294eae514bec1541a3adfb8200549438b3ffc1f1215e8d03d9f1067041ec2a082f1a4f6937735b4b825c40115c937995bc421922d07f702a3398aa4dc53688d01edb6cd04a5c8b6b7e64f428ee3d6a1dd91812c0f9fc6e3b34292d119e7f50372c2b00b88b74cb51aed73f5d127ab1d7d196dd8559eed2f935dacd24230a8e46c4774f5503f0407c5d5a25ce365b65ad56630e46b27b929026728533cc0cb8e9e8f77a5e92237b26adaa2af3ba11c61322f4a20ac8b48a07f2975be64e9b04a7e508d967e45ae9465e240acbff5ba039e89ef113daec6e83f3ec7d17ef806f0b2e04936923ab834b194bb6631198cc6029a76e77e34b8055e9d0e3ba577d3a80c927bbb0ce66706285a2578d0cacb335a5e79476f42784bdb76c795495e7238cd119c7e1127873ecf37645868ee50903d2f99c4decc2094e367ff4806ee63662e69501b77185d0de93401c7f482486d9cdffb55d53ac85eab907db6310cc3a41e2f431376d453247a1a3822da201fc93284142c3e7265778bb7d72da37c2da95c1e5337e7f3a6d22aba810d20a845294daa06f7e09d4650248b30bec05ed9448131fe27a4c9947290d9c5e58cdd229d041947777139ebae2299591894cfb3b611ad9ee303f632d35969621b89cfee35de7884d2676498869752b248ad2d63c17576c6b65b2db5f69cad4242a9970f1ffe168be5d8a57de8fa527b3d64ee8e6b9fa1485a7f82a39480727ea835a494ba1b1ab66fafc5501ee94931e56024072baac2bf083f4306784a541faecc9eb9aff4c07361ec07078cc8d51bbe6063733bf78f604ae282131ed8bff639df0052ead1de55ad5c34ba5d668f0166d35ab4df0f340ebda8ed2bdb065cf96b830b3fdeb8db5bd0e69b53a2e7c6f76ebe2c2db994f711b81652b1e32c0fa7e7a6f6588cf3c9a47b74f7df697aefbdc5ee0845ad0224615d0f9466fac869b6909c486af1f629b63f78780d886f853fde0ffe9bc8ea0636fe2936bf727a9d75e06dbc6d9d10c050c6541b0bec9fd4e5f9c4ce083313d9cc6214ab7cec4b0019801ba4bf53cf969bd0f2438a6b4358f5470477231800ba3a5ef6ba76afda576cfa27d3e3c5f91a3eb16b7fe45cfd1185cda82f3f85898eec83c18801abfa04438e2f96d8f81b9ffb1fa1db8a8506831862e6ace9f9f90f2bd1adc9a9f7315f7aa9fef7058c1f3f1ba783df506fdf67ff8b4a377e9dfeb00e492aed09873f61b6ad5346fadc56f5916c5348a9141b749b702745d0a42a3b90465a851ed32eb4ed1fd766ea0f9b9f396d4038dd1d2d791a252d528061848789e4b23e79336464322355ebac3f16d0b3adc574d493fe5cbfb48f3abcb907fc0cfcaa85d7607e7b72b5a98d605380088947775eb519fc6764e9b6c03742f47b487ccd98e58ba8bce3da3cbc51ba2c1defd78117a4da6eaa23660acf53f39994f7846e1f463731de1f4ba6d230b273ed293d759b117a0c018f3bc5e7808375c165fc0ca2fdd882ddf113177e3b2f17cb64cc7e0d601f9dd8e1d795511f4d0741251e0b8787bc4533691b5c0f344bf3c9febcf6413af5d3ed5e40fd2b78ae7b04d09ac185da0bc581f52a1c5fd6cdf89e9577428f1e502c383e6d4ae5ec4220024e4ec05bab59814737fcc8167179dded58a534c186d0fa92085ba49138128a418023ab56542ef06064668d228b802162223313a3b496c71798c9ab2b9babbbfdbdeeff101092d3537555b7e8792a1dce0ebecedf2fe11163f48545873a7dce8061126414355565f7e8295b0d300000000000000000000000000000000001628323f", "hex");
dilithiumVerifySig({publicKey, challenge, signature})
.then((res) => {
console.log('Verify result', res);
});
dilithium
dqxPerformNFC
Start NFC scan and perform an operation with the Dilithium tag.
Function prototype:
declare async function dqxPerformNFC(nfcAction: function, {setWorkStatusMessage: function}, options: object): object;
Where:
nfcAction
- one of the functions listed above (signChallenge
,eraseKeys
etc.);{setWorkStatusMessage}
- an object containing callbacks:setWorkStatusMessage(text: string): null
- a callback that is called whenever there is some status update, the status update could be displayed in the UI;
options
- command-specific options;
signChallenge
import {
dqxPerformNFC,
} from 'lib-dqx/rn-api.js';
import {
signChallenge,
} from 'lib-dqx';
let result = await dqxPerformNFC(
signChallenge,
{setWorkStatusMessage},
{challenge},
);
// result.publicKeyHash - SHA256 hash of the Dilithium public key
// result.signature - the Dilithium signature of the presented challenge
generateKeys
import {
dqxPerformNFC,
} from 'lib-dqx/rn-api.js';
import {
generateKeys,
} from 'lib-dqx';
let result = await dqxPerformNFC(
generateKeys,
{setWorkStatusMessage},
{erasePassword},
);
eraseKeys
import {
dqxPerformNFC,
} from 'lib-dqx/rn-api.js';
import {
eraseKeys,
} from 'lib-dqx';
let result = await dqxPerformNFC(
eraseKeys,
{setWorkStatusMessage},
{erasePassword},
);
changePassword
import {
dqxPerformNFC,
} from 'lib-dqx/rn-api.js';
import {
changePassword,
} from 'lib-dqx';
let result = await dqxPerformNFC(
changePassword,
{setWorkStatusMessage},
{oldPassword, erasePassword},
);
writeURL
import {
dqxPerformNFC,
} from 'lib-dqx/rn-api.js';
import {
writeURL,
} from 'lib-dqx';
let result = await dqxPerformNFC(
writeURL,
{setWorkStatusMessage},
{newURL, erasePassword},
);
getPublicKey
import {
dqxPerformNFC,
} from 'lib-dqx/rn-api.js';
import {
getPublicKey,
} from 'lib-dqx';
let result = await dqxPerformNFC(
getPublicKey,
{setWorkStatusMessage},
{},
);