Skip to content

Instantly share code, notes, and snippets.

@jamescoletti
Last active October 21, 2021 19:26
Show Gist options
  • Save jamescoletti/e7375db9d4694e70bd55d09cf0002eb6 to your computer and use it in GitHub Desktop.
Save jamescoletti/e7375db9d4694e70bd55d09cf0002eb6 to your computer and use it in GitHub Desktop.
Decrypt Kin QR code
import libsodium from 'libsodium-wrappers';
import kinSdk from '@kinecosystem/kin-sdk-v2';
const KEY_SIZE = 32;
// Password provided during backup process
const PASSPHRASE = '<your passphrase>';
// "salt" value from QR code JSON
const SALT = '<your salt>';
// "seed" value from QR code JSON
const SEED = '<your seed>';
(async () => {
await libsodium.ready;
const sodium = libsodium;
const hashBytes = sodium.crypto_pwhash(
KEY_SIZE,
PASSPHRASE,
sodium.from_hex(SALT),
sodium.crypto_pwhash_OPSLIMIT_INTERACTIVE,
sodium.crypto_pwhash_MEMLIMIT_INTERACTIVE,
sodium.crypto_pwhash_ALG_DEFAULT,
);
const seedBytes = sodium.from_hex(SEED);
const nonce = seedBytes.slice(0, sodium.crypto_secretbox_NONCEBYTES);
const cipherText = seedBytes.slice(sodium.crypto_secretbox_NONCEBYTES);
const decryptedSeedBytes = sodium.crypto_secretbox_open_easy(cipherText, nonce, hashBytes).slice(0, KEY_SIZE);
const privateKey = kinSdk.PrivateKey.fromString(decryptedSeedBytes);
console.log(privateKey.publicKey().toBase58());
// expecting same value as "pkey" from QR code JSON, but different public address returned?
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment