How to use createUnknownRecord method in wpt

Best JavaScript code snippet using wpt

nfc.js

Source:nfc.js Github

copy

Full Screen

...278 this._fetchChainData('contractRegistration', externalPublicKeyHash)279 ]280 ).then(() => {281 generateSecureRandom(32).then(randomBytes => Buffer.from(randomBytes).toString('hex')).then(randomNumber => {282 function createUnknownRecord(hex) {283 return {284 tnf: 0x05,285 type: [],286 id: [],287 payload: helpers._hexToBytes(hex)288 };289 };290 // Create records for link to app store and AAR.291 var kongDomain = 'https://kong.cash';292 var androidAppName = 'kongApp';293 var uriRecord = Ndef.uriRecord(kongDomain);294 var aarRecord = Ndef.androidApplicationRecord(androidAppName);295 // Create padding record.296 var shortMessage = Ndef.encodeMessage([uriRecord, aarRecord]);297 var paddingLength = 12 * 4 - shortMessage.length - 5; // Revisit this.298 var paddingRecord = createUnknownRecord('9'.repeat(paddingLength));299 // Create short-hand names for block variables.300 var blockHash = this.state.blockchainData.blockHash;301 var blockTime = this.state.blockchainData.blockTime;302 // Create combined hash for input record.303 var combinedHash = crypto.createHash('sha256').update(304 '0x' + randomNumber + blockHash305 ).digest('hex');306 console.log('RANDOM NUM INPUT');307 console.log(randomNumber);308 console.log('RANDOM HASH INPUT');309 console.log(combinedHash);310 // Combine all.311 var ndefMessage = Ndef.encodeMessage([312 // Static Lock Bytes.313 uriRecord, // URI with domain that forwards to iOS app store.314 aarRecord, // Android application record.315 paddingRecord, // Padd.316 // Dynamic Lock Bytes.317 createUnknownRecord( // 06 Bytes: Header318 '01'.repeat(4) + // 04 Bytes: Hardware Revision Number319 '02'.repeat(4) + // 04 Bytes: Firmware Number320 '03'.repeat(8) + // 08 Bytes: Serial Number321 '04'.repeat(64) + // 64 Bytes: Public Key 1322 '05'.repeat(64) + // 64 Bytes: Public Key 2323 '06'.repeat(20) + // 20 Bytes: Smart Contract Address324 '07'.repeat(7) + // 06 Bytes: NXP i2c Serial325 '08'.repeat(16) + // 16 Bytes: NXP MCU Serial326 '09'.repeat(9) + // 08 Bytes: ATECC608A Serial327 '01'.repeat(128) // 128 Bytes: Config Zone Bytes328 ),329 // Output.330 createUnknownRecord( // 06 Bytes: Header331 '00' + // 01 Byte: Last Command Code.332 '01'.repeat(32) + // 32 Bytes: Last External Random Number.333 '02'.repeat(32) + // 32 Bytes: Last Blockhash.334 '03'.repeat(32) + // 32 Bytes: Last SHA256 (External Random Number + Blockhash).335 '04'.repeat(32) + // 32 Bytes: Last Internal Random SHA256 Hash (Internal Random Number).336 '05'.repeat(64) + // 64 Bytes: Last Signature 1 (SHA256 Hash (External Random Number + Blockhash)).337 '06'.repeat(64) + // 64 Bytes: Last Signature 2 (SHA256 Hash (Internal Random Number)).338 '07'.repeat(47) // 47 Bytes: Padding339 ),340 // Input.341 createUnknownRecord( // 03 Bytes: Header342 '00' + // 01 Bytes: Command Code.343 randomNumber + // 32 Bytes: External Random Number.344 blockHash + // 32 Bytes: Blockhash.345 combinedHash + // 32 Bytes: SHA256 (External Random Number + Blockhash).346 crc16(347 helpers._hexToBytes(348 '00' +349 randomNumber +350 blockHash +351 combinedHash352 )353 ).toString(16) // 02 Bytes: CRC16354 )355 ]);356 // TLV.357 var ndefTLV = [358 0x03, // Field Type (0x03 = NDEF Message)359 0xFF, // Length field360 ndefMessage.length >> 8, // Length field cont.361 ndefMessage.length - (ndefMessage.length >> 8) * 256 // Length field cont.362 ];363 // Note: Length field in 3 byte version:364 // [0xFF, 0xYY, 0xXZ] where 0xYY, 0xZZ are sliced from word 0xYYZZ (!)365 // Prepend TLV.366 var ndefMessage = ndefTLV.concat(ndefMessage);367 // Append terminator and trailing 0x00368 ndefMessage = ndefMessage.concat([0xfe]);369 while (ndefMessage.length % 4 > 0) ndefMessage = ndefMessage.concat([0x00])370 // Determine number of ic blocks.371 // var icBlockWithLastNdefRecord = Math.ceil(ndefMessage.length / 16);372 // Prepend 16 bytes for first 4 registers.373 var completeMemory = helpers._hexToBytes('00'.repeat(16)).concat(ndefMessage);374 // Create array with register numbers.375 var registers = [...Array(Math.ceil(completeMemory.length / 4)).keys()]376 // Remove registers that won't be written; The input record begins at register 0xB0.377 registers = registers.filter(register => register >= 0xB0);378 // Update state.379 this.setState({nfcData: Object.assign({}, this.state.nfcData, {380 nfcWrittenInputExternalRandomNumber: randomNumber,381 nfcWrittenInputBlockhash: blockHash,382 nfcWrittenInputCombinedHash: combinedHash383 })});384 // Write.385 Promise.all(386 registers.map(i => {387 return NfcManager.sendMifareCommandIOS([0xa2]388 .concat(i) // Register number.389 .concat(completeMemory.slice(390 i * 4, // Start position in payload.391 (i + 1) * 4) // End position in payload.392 )393 );394 })395 ).then(() => {396 NfcManager.setAlertMessageIOS(strings.textProcessingSendingChallengeIOS);397 // Read lastIcBlock to finish input.398 NfcManager.sendMifareCommandIOS([0x30, (this.state.nfcData.icBlockWithLastNdefRecord + 1) * 4 - 1]).then(() => {399 // DEBUG prints.400 console.log(`NFC DATA AFTER WRITE IOS: ${Date.now()}`);401 console.log(this.state.nfcData);402 /***************************403 * Timeout for Calculation. *404 ***************************/405 console.log(`STARTING TIMEOUT: ${Date.now()}`);406 helpers._delay(3000).then(() => {407 console.log(`END OF TIMEOUT: ${Date.now()}`);408 /****************409 * Read Results. *410 ****************/411 NfcManager.sendMifareCommandIOS([0x3A, 0x64, 0x84]).then((hashByteArray) => {412 NfcManager.setAlertMessageIOS(strings.textProcessingReadingResultsIOS);413 console.log(`READ HASH BYTE ARRAY CALLED: ${Date.now()}`);414 NfcManager.sendMifareCommandIOS([0x3A, 0x84, 0xA4]).then((signatureByteArray) => {415 console.log(`READ Signature CALLED: ${Date.now()}`);416 // Get external and internal hash.417 var nfcReadOutputExternalRandomNumber = helpers._bytesToHex(hashByteArray.slice(1, 33)).toLowerCase();418 var nfcReadOutputBlockhash = helpers._bytesToHex(hashByteArray.slice(33, 65)).toLowerCase();419 var nfcReadOutputCombinedHash = helpers._bytesToHex(hashByteArray.slice(65, 97)).toLowerCase();420 var nfcReadOutputInternalRandomNumber = helpers._bytesToHex(hashByteArray.slice(97, 129)).toLowerCase();421 // Get signatures.422 var nfcReadOutputExternalSignature = helpers._bytesToHex(signatureByteArray.slice(1, 65)).toLowerCase();423 var nfcReadOutputInternalSignature = helpers._bytesToHex(signatureByteArray.slice(65, 129)).toLowerCase();424 // Counter.425 var nfcReadOutputCounter = helpers._bytesToHex(signatureByteArray.slice(129, 130)).toLowerCase();426 // Update state.427 this.setState({nfcData: Object.assign({}, this.state.nfcData, {428 nfcReadOutputExternalRandomNumber: nfcReadOutputExternalRandomNumber,429 nfcReadOutputBlockhash: nfcReadOutputBlockhash,430 nfcReadOutputCombinedHash: nfcReadOutputCombinedHash,431 nfcReadOutputInternalRandomNumber: nfcReadOutputInternalRandomNumber,432 nfcReadOutputExternalSignature: nfcReadOutputExternalSignature,433 nfcReadOutputInternalSignature: nfcReadOutputInternalSignature,434 nfcReadOutputCounter: nfcReadOutputCounter435 })});436 // DEBUG prints.437 console.log(`NFC DATA AFTER RESULTS READ: ${Date.now()}`);438 console.log(this.state.nfcData);439 /*********************440 * Confirmation Read. *441 *********************/442 NfcManager.sendMifareCommandIOS([0x30, (this.state.nfcData.icBlockWithLastNdefRecord + 1) * 4 - 1]).then(() => {443 /****************444 * Verification. *445 ****************/446 NfcManager.setAlertMessageIOS(strings.textProcessingPreparingResultsIOS);447 console.log(`Starting verification (in ms): ${Date.now()}`)448 this._goToScreen('atProcessing', strings.textProcessingVerificationStartIOS);449 this._nfcStartFullVerification();450 }).catch((err) => {this._goToNfcFailScreen('nfcFailReadLastNdef', err)})451 }).catch((err) => {this._goToNfcFailScreen('nfcFailNfcReadSignatures', err)})452 }).catch((err) => {this._goToNfcFailScreen('nfcFailNfcReadHashes', err)})453 }).catch((err) => {this._goToNfcFailScreen('nfcFailTimeout', err)})454 }).catch((err) => {this._goToNfcFailScreen('nfcFailReadLastNdef', err)})455 }).catch((err) => {this._goToNfcFailScreen('nfcFailWriteInput', err)})456 }).catch((err) => {this._goToNfcFailScreen('nfcFailRng', err)})457 }).catch((err) => {458 NfcManager.setAlertMessageIOS(strings.textProcessingPreparingResultsIOS);459 this._goToFailScreen(460 strings.textFailBlockchainGetLatestBlockAndRegistrationWarning,461 strings.textFailBlockchainGetLatestBlockAndRegistrationDescription + '\n(' + err + ')');462 NfcManager.cancelTechnologyRequest().catch(() => 0);463 NfcManager.unregisterTagEventExIOS().catch(() => 0); 464 })465 }).catch((err) => {this._goToNfcFailScreen('nfcFailReadHashesWarning', err)})466 }).catch((err) => {this._goToNfcFailScreen('nfcFailReadConfigWarning', err)})467 });468 }); 469 //}) 470 },471 _nfcAndroidScan: async function() {472 // Close technology if it is still running.473 NfcManager.cancelTechnologyRequest().catch((err) => console.warn(err))474 // Start listening to new incoming events.475 if (this.state.fullVerification) {476 NfcManager.registerTagEvent().then(() => this._nfcAndroidProcessFullScan())477 } else {478 NfcManager.registerTagEvent().then(() => this._nfcAndroidProcessQuickScan())479 } 480 },481 _nfcAndroidProcessFullScan: async function() {482 /*********************483 * Start NFC Handler. *484 *********************/485 NfcManager.isSupported(NfcTech.NfcA).then(() => {486 console.log(`CHECK SUPPORT: ${Date.now()}`);487 NfcManager.requestTechnology(NfcTech.NfcA).then(() => {488 console.log(`TECH REQUEST: ${Date.now()}`);489 // Update view.490 this._goToScreen('atProcessing', strings.textProcessingStartAndroid);491 /******************492 * Check Tag Type. *493 ******************/494 NfcManager.transceive([0x3a, 0x11, 0x15]).then((ret) => {495 console.log(`CHECKING TAG TYPE: ${Date.now()}`);496 var validTag = (497 JSON.stringify(ret.slice(2, -2)) == JSON.stringify([1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3])498 );499 // This should be removed once we have settled on an appropriate tag type check...500 var validTag = true;501 if (validTag) {502 /******************************503 * Get Configuration Register. *504 ******************************/505 NfcManager.transceive([0x30, 0xe8]).then((configBytes) => {506 this.setState({nfcData: Object.assign({}, this.state.nfcData, {507 icBlockWithLastNdefRecord: configBytes[1]508 })});509 console.log('CONFIG');510 console.log(configBytes);511 /************512 * Get Keys. *513 ************/514 NfcManager.transceive([0x3a, 0x15, 0x35]).then((ret) => {515 // Slice keys from response.516 var externalPublicKey = helpers._bytesToHex(ret.slice(2, 66));517 var internalPublicKey = helpers._bytesToHex(ret.slice(66, 130));518 var externalPublicKeyHash = '0x' + crypto.createHash('sha256').update(externalPublicKey, 'hex').digest('hex');519 // Update state.520 this.setState({nfcData: Object.assign({}, this.state.nfcData, {521 nfcReadInfoPrimaryPublicKey: externalPublicKey,522 nfcReadInfoSecondaryPublicKey: internalPublicKey,523 nfcReadInfoPrimaryPublicKeyHash: externalPublicKeyHash524 })});525 // DEBUG prints.526 console.log('KEY DATA');527 console.log(this.state.nfcData);528 /******************************************529 * Check Registration and Begin Challenge. *530 ******************************************/531 // Combining the two to reduce the overall time needed.532 Promise.all(533 [534 this._fetchChainData('latestBlock'),535 this._fetchChainData('contractRegistration', externalPublicKeyHash)536 ]537 ).then(() => {538 generateSecureRandom(32).then(randomBytes => Buffer.from(randomBytes).toString('hex')).then(randomNumber => {539 function createUnknownRecord(hex) {540 return {541 tnf: 0x05,542 type: [],543 id: [],544 payload: helpers._hexToBytes(hex)545 };546 };547 // Create records for link to app store and AAR.548 var kongDomain = 'https://kong.cash';549 var androidAppName = 'ch.vrfy';550 var uriRecord = Ndef.uriRecord(kongDomain);551 var aarRecord = Ndef.androidApplicationRecord(androidAppName);552 // Create padding record.553 var shortMessage = Ndef.encodeMessage([uriRecord, aarRecord]);554 var paddingLength = 12 * 4 - shortMessage.length - 5; // Revisit this.555 var paddingRecord = createUnknownRecord('9'.repeat(paddingLength));556 // Create short-hand names for block variables.557 var blockHash = this.state.blockchainData.blockHash;558 var blockTime = this.state.blockchainData.blockTime;559 // Create combined hash for input record.560 var combinedHash = crypto.createHash('sha256').update(561 '0x' + randomNumber + blockHash562 ).digest('hex');563 // Combine all.564 var ndefMessage = Ndef.encodeMessage([565 // Static Lock Bytes.566 uriRecord, // URI with domain that forwards to iOS app store.567 aarRecord, // Android application record.568 paddingRecord, // Padd.569 // Dynamic Lock Bytes.570 createUnknownRecord(571 '01'.repeat(4) +572 '02'.repeat(4) +573 '03'.repeat(8) +574 '04'.repeat(64) + // 64 Bytes: Public Key 1575 '05'.repeat(64) +576 '06'.repeat(20) +577 '07'.repeat(7) +578 '08'.repeat(16) + 579 '09'.repeat(9) + // 08 Bytes: ATECC608A Serial580 '01'.repeat(128)581 ),582 // Output.583 createUnknownRecord(584 '00' +585 '01'.repeat(32) + // 32 Bytes: Last External Random Number.586 '02'.repeat(32) + // 32 Bytes: Last Blockhash.587 '03'.repeat(32) + // 32 Bytes: Last SHA256 (External Random Number + Blockhash).588 '04'.repeat(32) +589 '05'.repeat(64) + // 64 Bytes: Last Signature 1 (SHA256 Hash (External Random Number + Blockhash)).590 '06'.repeat(64) +591 '07'.repeat(47)592 ),593 // Input.594 createUnknownRecord( // 03 Bytes: Header595 '00' + // 01 Bytes: Command Code.596 randomNumber + // 32 Bytes: External Random Number.597 blockHash + // 32 Bytes: Blockhash.598 combinedHash + // 32 Bytes: SHA256 (External Random Number + Blockhash).599 crc16(600 helpers._hexToBytes(601 '00' +602 randomNumber +603 blockHash +604 combinedHash605 )606 ).toString(16) // 02 Bytes: CRC16607 )608 ]);...

Full Screen

Full Screen

nfc-helpers.js

Source:nfc-helpers.js Github

copy

Full Screen

...116function createMimeRecord(buffer) {117 return createRecord(118 'mime', buffer, test_record_id, 'application/octet-stream');119}120function createUnknownRecord(buffer) {121 return createRecord('unknown', buffer, test_record_id);122}123function createUrlRecord(url, isAbsUrl) {124 if (isAbsUrl) {125 return createRecord('absolute-url', url, test_record_id);126 }127 return createRecord('url', url, test_record_id);128}129// Compares NDEFMessageSource that was provided to the API130// (e.g. NDEFReader.write), and NDEFMessage that was received by the131// mock NFC service.132function assertNDEFMessagesEqual(providedMessage, receivedMessage) {133 // If simple data type is passed, e.g. String or ArrayBuffer or134 // ArrayBufferView, convert it to NDEFMessage before comparing....

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3 if(err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9### WebPageTest(options)10### WebPageTest#runTest(url, options, callback)11### WebPageTest#getLocations(callback)12### WebPageTest#getTesters(callback)13### WebPageTest#getTestStatus(testId, callback)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt=require('wpt');2var wptObj=new wpt();3wptObj.createUnknownRecord(options,function(err,data){4 if(err){5 console.log(err);6 }else{7 console.log(data);8 }9});10var wpt=require('wpt');11var wptObj=new wpt();12wptObj.getLocations(function(err,data){13 if(err){14 console.log(err);15 }else{16 console.log(data);17 }18});19var wpt=require('wpt');20var wptObj=new wpt();21var options={tests:'1,2'};22wptObj.getTests(options,function(err,data){23 if(err){24 console.log(err);25 }else{26 console.log(data);27 }28});29var wpt=require('wpt');30var wptObj=new wpt();31var options={test:'1'};32wptObj.getTestStatus(options,function(err,data){33 if(err){34 console.log(err);35 }else{36 console.log(data);37 }38});39var wpt=require('wpt');40var wptObj=new wpt();41var options={test:'1'};42wptObj.getTestResults(options,function(err,data){43 if(err){44 console.log(err);45 }else{46 console.log(data);47 }48});49var wpt=require('wpt');50var wptObj=new wpt();51var options={test:'1'};52wptObj.getTestResultsByLocation(options,function(err,data){53 if(err){54 console.log(err);55 }else{56 console.log(data);57 }58});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4var wpt = new WebPageTest(options);5 if (err) return console.error(err);6 console.log(data

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var options = {3};4var wpt = new WebPageTest('www.webpagetest.org');5 if (err) return console.error(err);6 console.log(data);7});8var wpt = require('webpagetest');9var options = {10};11var wpt = new WebPageTest('www.webpagetest.org');

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful