Registry / security / otpauth-migration-parser

otpauth-migration-parser

JSON →
library0.1.1jsnpmunverified

A lightweight parser for Google Authenticator Account Export QR code data (otpauth-migration:// URIs). Version 0.1.1 is current, with no active development cadence. It decodes protobuf-encoded migration payloads into structured token information including secret, name, issuer, algorithm, digits, type, and counter. Differentiated by being the only dedicated npm package specifically for decoding the migration format, as opposed to general OTP URI parsers.

npm install otpauth-migration-parser
INSTALL
IMPORT
SIG · OTPAUTH-MIGRATION-
O
otpauth-migration-parser
securityjavascriptv0.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import parser from 'otpauth-migration-parser'
const parser = require('otpauth-migration-parser')
The package uses default export as a Promise function. ESM import is correct; CommonJS require works but may cause issues with TypeScript.
default
const parser = require('otpauth-migration-parser').default
const parser = require('otpauth-migration-parser')
If using CommonJS require, you must access .default to get the Promise function.
default
import parser from 'otpauth-migration-parser'
import * as parser from 'otpauth-migration-parser'
The package exports a single default function, not a namespace. Using namespace import will break.

Shows ESM import, parsing a sample Google Authenticator migration URI, and iterating over decoded accounts.

import parser from 'otpauth-migration-parser'; const dataUri = 'otpauth-migration://offline?data=ChQKFQgGEAQoEjAIARIQNxY2NzQ2MzEzNTg5NzY1ORoFEgN0ZXN0IAEoATABQAFIAQ=='; (async () => { try { const accounts = await parser(dataUri); accounts.forEach(acc => { console.log(`Issuer: ${acc.issuer}, Name: ${acc.name}, Type: ${acc.type}`); }); } catch (err) { console.error('Failed to parse migration data:', err); } })();
Debug
Known issues
gotchaThe package returns 'counter' as a Long object with low/high/unsigned fields, not a number.
fix
Convert counter to number with: counter.toNumber() or use a bigint library.
affects: >=0.1.0
gotchaThe parser expects the URI scheme to be exactly 'otpauth-migration://offline?data=...'. Other variations will fail silently or throw.
fix
Ensure the URI is a full migration link, not a standard otpauth:// URI.
affects: >=0.1.0
gotchaThe default export is a Promise function, not a synchronous parser. Calling it without await returns a Promise.
fix
Use await or .then() when calling the parser.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: parser is not a function
Using CommonJS require without .default or using namespace import with ESM.
fix
Use EsModuleInterop: true and import parser from 'otpauth-migration-parser'. If using require, do const parser = require('otpauth-migration-parser').default;
Error: Invalid data
The migration URI data parameter is not valid base64 or malformed protobuf payload.
fix
Verify the URI is a valid 'otpauth-migration://offline?data=...' link from Google Authenticator export.
Upgrade
Version history
0.1.1latest on npm
Audit
Dependencies
protobufjsrequiredDecoding protobuf-encoded migration data
Agent activity
12 hits · last 30 days
node
12
Resources
otpauth-migration-parser — npm install otpauth-migration-parser · libregistry