Skip to content

Commit

Permalink
Merge pull request #2 from KELs7/kels7-wip-make-it-work-in-the-browser
Browse files Browse the repository at this point in the history
Kels7 wip make it work in the browser
  • Loading branch information
duelingbenjos authored Feb 27, 2024
2 parents 55ebfb9 + 2ac1b11 commit 433956c
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 176 deletions.
12 changes: 6 additions & 6 deletions dist/index.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ declare function generate_keys(seed?: any): {
* @return String vk
* vk: A 64 character long hex representation of a verify key (public key)
*/
declare function get_vk(sk: any): any;
declare function get_vk(sk: any): string;
/**
* @param String sk
* sk: A 64 character long hex representation of a signing key (private key)
Expand All @@ -255,8 +255,8 @@ declare function format_to_keys(sk: any): {
* vk: Verify Key (VK) represented as a 64 character hex string
*/
declare function keys_to_format(kp: any): {
vk: any;
sk: any;
vk: string;
sk: string;
};
/**
* @param Uint8Array(length: 32) seed
Expand All @@ -268,8 +268,8 @@ declare function keys_to_format(kp: any): {
* vk: Verify Key (VK) represented as a 64 character hex string
*/
declare function new_wallet(seed?: any): {
vk: any;
sk: any;
vk: string;
sk: string;
};
/**
* @param seed Bip39 seed phrase (128 characters in hex)
Expand Down Expand Up @@ -369,7 +369,7 @@ declare function encryptStrHash(password: any, string: any): any;
* @return {string} Decrypted string
*/
declare function decryptStrHash(password: any, encryptedString: any): any;
declare function buf2hex(buffer: any): any;
declare function buf2hex(buffer: ArrayBuffer): string;
declare function hex2buf(hexString: any): Uint8Array;
declare function str2buf(string: any): Uint8Array;
declare function concatUint8Arrays(array1: any, array2: any): Uint8Array;
Expand Down
12 changes: 6 additions & 6 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ declare function generate_keys(seed?: any): {
* @return String vk
* vk: A 64 character long hex representation of a verify key (public key)
*/
declare function get_vk(sk: any): any;
declare function get_vk(sk: any): string;
/**
* @param String sk
* sk: A 64 character long hex representation of a signing key (private key)
Expand All @@ -255,8 +255,8 @@ declare function format_to_keys(sk: any): {
* vk: Verify Key (VK) represented as a 64 character hex string
*/
declare function keys_to_format(kp: any): {
vk: any;
sk: any;
vk: string;
sk: string;
};
/**
* @param Uint8Array(length: 32) seed
Expand All @@ -268,8 +268,8 @@ declare function keys_to_format(kp: any): {
* vk: Verify Key (VK) represented as a 64 character hex string
*/
declare function new_wallet(seed?: any): {
vk: any;
sk: any;
vk: string;
sk: string;
};
/**
* @param seed Bip39 seed phrase (128 characters in hex)
Expand Down Expand Up @@ -369,7 +369,7 @@ declare function encryptStrHash(password: any, string: any): any;
* @return {string} Decrypted string
*/
declare function decryptStrHash(password: any, encryptedString: any): any;
declare function buf2hex(buffer: any): any;
declare function buf2hex(buffer: ArrayBuffer): string;
declare function hex2buf(hexString: any): Uint8Array;
declare function str2buf(string: any): Uint8Array;
declare function concatUint8Arrays(array1: any, array2: any): Uint8Array;
Expand Down
14 changes: 9 additions & 5 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions dist/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ function decryptStrHash(password, encryptedString) {
}
}
function buf2hex(buffer) {
return Array.prototype.map.call(new Uint8Array(buffer), (x) => ("00" + x.toString(16)).slice(-2)).join("");
const uint8Array = new Uint8Array(buffer);
const hexArray = Array.prototype.map.call(uint8Array, (x) => ("00" + x.toString(16)).slice(-2));
const hexString = hexArray.join("");
return hexString;
}
function hex2buf(hexString) {
var bytes = new Uint8Array(Math.ceil(hexString.length / 2));
Expand Down Expand Up @@ -294,7 +297,7 @@ var stringifyTransaction = (tx) => Buffer.from(JSON.stringify(tx)).toString("hex
// src/lib/wallet.ts
import nacl from "tweetnacl";
import * as bip39 from "bip39";
import bip32 from "ed25519-hd-key";
import { HDKey } from "ed25519-keygen/hdkey";
var create_wallet = (args = {}) => {
let { sk, keepPrivate, seed } = args;
let vk;
Expand Down Expand Up @@ -356,10 +359,11 @@ function generate_keys_bip39(seed = void 0, derivationIndex = 0) {
finalMnemonic = bip39.generateMnemonic(256);
finalSeed = bip39.mnemonicToSeedSync(finalMnemonic).toString("hex");
}
let hdkey = HDKey.fromMasterSeed(finalSeed);
const derivationPath = "m/44'/789'/" + derivationIndex + "'/0'/0'";
const { key, chainCode } = bip32.derivePath(derivationPath, finalSeed, 2147483648);
const privateKey = key.toString("hex");
const publicKey = bip32.getPublicKey(key, false).toString("hex");
hdkey = hdkey.derive(derivationPath);
const privateKey = buf2hex(hdkey.privateKey);
const publicKey = buf2hex(hdkey.publicKey).slice(2);
if (publicKey !== get_vk(privateKey)) {
throw Error("Bip32 public key does not match with Lamden public key!");
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.mjs.map

Large diffs are not rendered by default.

Loading

0 comments on commit 433956c

Please sign in to comment.