Skip to content

Instantly share code, notes, and snippets.

@amatiash
Last active November 13, 2021 05:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save amatiash/495a120991bdfe8d61381bb5a00c67a9 to your computer and use it in GitHub Desktop.
Save amatiash/495a120991bdfe8d61381bb5a00c67a9 to your computer and use it in GitHub Desktop.
Convert Stellar KIN keys into Solana KIN keypair
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var web3_js_1 = require("@solana/web3.js");
var hex_to_32_1 = __importDefault(require("hex-to-32"));
var atob_1 = __importDefault(require("atob"));
var bs58_1 = __importDefault(require("bs58"));
// ----------------------------------------------------
var base64ToArrayBuffer = function (base64) {
var binary_string = atob_1.default(base64);
var len = binary_string.length;
var bytes = new Uint8Array(len);
for (var i = 0; i < len; i++) {
bytes[i] = binary_string.charCodeAt(i);
}
return bytes.buffer;
};
// ----------------------------------------------------
var StellarPublicKey = 'GCYMCOHDWCX7DN7UWPSGED7Z5UPOY24KWFHP6GSY2NOIV62L2OZCHTLA'; // Replace with your stellar public key
var StellarSecretKey = 'SDDTKXJ62SCPRMFOOKUZVLFOQHY6UMNX3FS2DW45NADGOMCDNYZ4KJFH'; // Replace with your stellar private key
// ----------------------------------------------------
var StellarPublicKeyHex = hex_to_32_1.default.decode(StellarPublicKey);
var StellarSecretKeyHex = hex_to_32_1.default.decode(StellarSecretKey);
var StellarPublicKeyHexRow = StellarPublicKeyHex.slice(2, -4);
var StellarSecretKeyHexRow = StellarSecretKeyHex.slice(2, -4);
var joined = StellarSecretKeyHexRow + StellarPublicKeyHexRow;
var joined64 = Buffer.from(joined, 'hex').toString('base64');
var StellarSecretKeyHexBytes = Buffer.from(StellarPublicKeyHexRow, 'hex');
var SolanaPublicKey = bs58_1.default.encode(StellarSecretKeyHexBytes);
var arrayBuffer = base64ToArrayBuffer(joined64);
var account = new web3_js_1.Account(arrayBuffer);
var secretKey = account.secretKey;
var SolanaSecretKey = bs58_1.default.encode(secretKey);
console.log('Public key: ' + SolanaPublicKey);
console.log('Secret key: ' + SolanaSecretKey);
// Based on this solution: https://www.reddit.com/r/KinFoundation/comments/j7qejf/quick_guide_on_converting_kin_keypair_ready_for/
import {Account} from '@solana/web3.js'
import hexTo32 from 'hex-to-32'
import atob from 'atob'
import bs58 from 'bs58'
// ----------------------------------------------------
const base64ToArrayBuffer = (base64) => {
const binary_string = atob(base64);
const len = binary_string.length;
const bytes = new Uint8Array(len);
for (let i = 0; i < len; i++) {
bytes[i] = binary_string.charCodeAt(i);
}
return bytes.buffer;
}
// ----------------------------------------------------
const StellarPublicKey = 'GCYMCOHDWCX7DN7UWPSGED7Z5UPOY24KWFHP6GSY2NOIV62L2OZCHTLA' // Replace with your stellar public key
const StellarSecretKey = 'SDDTKXJ62SCPRMFOOKUZVLFOQHY6UMNX3FS2DW45NADGOMCDNYZ4KJFH' // Replace with your stellar private key
// ----------------------------------------------------
const StellarPublicKeyHex = hexTo32.decode(StellarPublicKey)
const StellarSecretKeyHex = hexTo32.decode(StellarSecretKey)
const StellarPublicKeyHexRow = StellarPublicKeyHex.slice(2, -4)
const StellarSecretKeyHexRow = StellarSecretKeyHex.slice(2, -4)
const joined = StellarSecretKeyHexRow + StellarPublicKeyHexRow
const joined64 = Buffer.from(joined, 'hex').toString('base64')
const StellarSecretKeyHexBytes = Buffer.from(StellarPublicKeyHexRow, 'hex')
const SolanaPublicKey = bs58.encode(StellarSecretKeyHexBytes)
const arrayBuffer = base64ToArrayBuffer(joined64)
const account = new Account(arrayBuffer as Uint8Array)
const secretKey = account.secretKey
const SolanaSecretKey = bs58.encode(secretKey)
console.log('Public key: ' + SolanaPublicKey)
console.log('Secret key: ' + SolanaSecretKey)
{
"name": "get-my-kin",
"license": "MIT",
"version": "1.0.0",
"description": "Get kin Solana keys",
"scripts": {},
"dependencies": {
"@solana/web3.js": "^1.0.0",
"atob": "^2.1.2",
"bs58": "^4.0.1",
"hex-to-32": "^2.0.0"
}
}
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"sourceMap": true,
"declaration": false,
"strict": true,
"noImplicitAny": false,
"esModuleInterop": true,
"resolveJsonModule": true,
"downlevelIteration": true
},
"exclude": [
"node_modules"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment