Skip to content

Instantly share code, notes, and snippets.

@htdangkhoa
Created March 24, 2025 10:12
Show Gist options
  • Save htdangkhoa/13e7f27c3f3272e6d4979a9f2a3ca9c2 to your computer and use it in GitHub Desktop.
Save htdangkhoa/13e7f27c3f3272e6d4979a9f2a3ca9c2 to your computer and use it in GitHub Desktop.
import protobuf from 'protobufjs';
const migrationProto = `
syntax = "proto3";
message MigrationPayload {
enum Algorithm {
ALGORITHM_UNSPECIFIED = 0;
ALGORITHM_SHA1 = 1;
ALGORITHM_SHA256 = 2;
ALGORITHM_SHA512 = 3;
ALGORITHM_MD5 = 4;
}
enum DigitCount {
DIGIT_COUNT_UNSPECIFIED = 0;
DIGIT_COUNT_SIX = 1;
DIGIT_COUNT_EIGHT = 2;
}
enum OtpType {
OTP_TYPE_UNSPECIFIED = 0;
OTP_TYPE_HOTP = 1;
OTP_TYPE_TOTP = 2;
}
message OtpParameters {
bytes secret = 1;
string name = 2;
string issuer = 3;
Algorithm algorithm = 4;
DigitCount digits = 5;
OtpType type = 6;
int64 counter = 7;
}
repeated OtpParameters otp_parameters = 1;
int32 version = 2;
int32 batch_size = 3;
int32 batch_index = 4;
int32 batch_id = 5;
}
`;
async function main(...args: string[]) {
const [link] = args;
const { root: proto } = protobuf.parse(migrationProto);
const MigrationPayload = proto.lookupType('MigrationPayload');
const { searchParams } = new URL(link);
const data = searchParams.get('data');
const encodedMessage = Buffer.from(data!, 'base64');
const decodedMessage = MigrationPayload.decode(encodedMessage);
const raw = decodedMessage.toJSON();
console.log(JSON.stringify(raw, null, 2));
}
if (require.main === module) {
const args = process.argv.slice(2);
main(...args).catch((err) => {
console.error(err);
process.exit(1);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment