conseiljs
Advanced tools
Comparing version 0.1.24 to 0.1.25
@@ -32,3 +32,3 @@ import { OperationFees, TezosAccount, TezosAccountWithOperationGroups, TezosBlock, TezosBlockWithOperationGroups, TezosOperation, TezosOperationGroup, TezosOperationGroupWithOperations } from "../utils/ConseilTypes"; | ||
* Fetches the most recent block stored in the database. | ||
* @param {string} server Which Tezos network to go against | ||
* @param {string} server Which Conseil server to go against | ||
* @param apiKey API key to use for Conseil server. | ||
@@ -40,3 +40,3 @@ * @returns {Promise<TezosBlock>} Latest block. | ||
* Fetches a block by block hash from the db. | ||
* @param {string} server Which Tezos network to go against | ||
* @param {string} server Which Conseil server to go against | ||
* @param {String} hash The block's hash | ||
@@ -49,3 +49,3 @@ * @param apiKey API key to use for Conseil server. | ||
* Fetch a given operation group | ||
* @param {string} server Which Tezos network to go against | ||
* @param {string} server Which Conseil server to go against | ||
* @param {String} hash Operation group hash | ||
@@ -58,3 +58,3 @@ * @param apiKey API key to use for Conseil server. | ||
* Fetches all operation groups. | ||
* @param {string} server Which Tezos network to go against | ||
* @param {string} server Which Conseil server to go against | ||
* @param {TezosFilter} filter Filters to apply | ||
@@ -67,3 +67,3 @@ * @param apiKey API key to use for Conseil server. | ||
* Fetches all operations. | ||
* @param {string} server Which Tezos network to go against | ||
* @param {string} server Which Conseil server to go against | ||
* @param {TezosFilter} filter Filters to apply | ||
@@ -75,7 +75,7 @@ * @param apiKey API key to use for Conseil server. | ||
/** | ||
* Fetches all operations. | ||
* @param {string} server Which Tezos network to go against | ||
* @param {TezosFilter} filter Filters to apply | ||
* Fetches prevailing fees. | ||
* @param {string} server Which Conseil server to go against | ||
* @param {TezosFilter} filter Filters to apply. 'operation_kind' and 'limit' should be explicitly set for maximum accuracy. | ||
* @param apiKey API key to use for Conseil server. | ||
* @returns {Promise<TezosOperationGroup[]>} List of operations | ||
* @returns {Promise<TezosOperationGroup[]>} Low, medium and high fee levels. | ||
*/ | ||
@@ -85,3 +85,3 @@ function getAverageFees(server: string, filter: TezosFilter, apiKey: string): Promise<OperationFees>; | ||
* Fetches an account by account id from the db. | ||
* @param {string} server Which Tezos network to go against | ||
* @param {string} server Which Conseil server to go against | ||
* @param {String} hash The account's id number | ||
@@ -94,3 +94,3 @@ * @param apiKey API key to use for Conseil server. | ||
* Fetches all blocks from the db. | ||
* @param {string} server Which Tezos network to go against | ||
* @param {string} server Which Conseil server to go against | ||
* @param {TezosFilter} filter Filters to apply | ||
@@ -97,0 +97,0 @@ * @param apiKey API key to use for Conseil server. |
@@ -30,3 +30,3 @@ "use strict"; | ||
* Fetches the most recent block stored in the database. | ||
* @param {string} server Which Tezos network to go against | ||
* @param {string} server Which Conseil server to go against | ||
* @param apiKey API key to use for Conseil server. | ||
@@ -44,3 +44,3 @@ * @returns {Promise<TezosBlock>} Latest block. | ||
* Fetches a block by block hash from the db. | ||
* @param {string} server Which Tezos network to go against | ||
* @param {string} server Which Conseil server to go against | ||
* @param {String} hash The block's hash | ||
@@ -59,3 +59,3 @@ * @param apiKey API key to use for Conseil server. | ||
* Fetch a given operation group | ||
* @param {string} server Which Tezos network to go against | ||
* @param {string} server Which Conseil server to go against | ||
* @param {String} hash Operation group hash | ||
@@ -74,3 +74,3 @@ * @param apiKey API key to use for Conseil server. | ||
* Fetches all operation groups. | ||
* @param {string} server Which Tezos network to go against | ||
* @param {string} server Which Conseil server to go against | ||
* @param {TezosFilter} filter Filters to apply | ||
@@ -89,3 +89,3 @@ * @param apiKey API key to use for Conseil server. | ||
* Fetches all operations. | ||
* @param {string} server Which Tezos network to go against | ||
* @param {string} server Which Conseil server to go against | ||
* @param {TezosFilter} filter Filters to apply | ||
@@ -103,7 +103,7 @@ * @param apiKey API key to use for Conseil server. | ||
/** | ||
* Fetches all operations. | ||
* @param {string} server Which Tezos network to go against | ||
* @param {TezosFilter} filter Filters to apply | ||
* Fetches prevailing fees. | ||
* @param {string} server Which Conseil server to go against | ||
* @param {TezosFilter} filter Filters to apply. 'operation_kind' and 'limit' should be explicitly set for maximum accuracy. | ||
* @param apiKey API key to use for Conseil server. | ||
* @returns {Promise<TezosOperationGroup[]>} List of operations | ||
* @returns {Promise<TezosOperationGroup[]>} Low, medium and high fee levels. | ||
*/ | ||
@@ -119,3 +119,3 @@ function getAverageFees(server, filter, apiKey) { | ||
* Fetches an account by account id from the db. | ||
* @param {string} server Which Tezos network to go against | ||
* @param {string} server Which Conseil server to go against | ||
* @param {String} hash The account's id number | ||
@@ -134,3 +134,3 @@ * @param apiKey API key to use for Conseil server. | ||
* Fetches all blocks from the db. | ||
* @param {string} server Which Tezos network to go against | ||
* @param {string} server Which Conseil server to go against | ||
* @param {TezosFilter} filter Filters to apply | ||
@@ -137,0 +137,0 @@ * @param apiKey API key to use for Conseil server. |
@@ -18,2 +18,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const KeyStore_1 = require("../types/KeyStore"); | ||
const CryptoUtils = __importStar(require("../utils/CryptoUtils")); | ||
@@ -118,3 +119,3 @@ const fs = __importStar(require("fs")); | ||
const passphrase = email + password; | ||
return CryptoUtils.getKeysFromMnemonicAndPassphrase(mnemonic, passphrase, pkh, true); | ||
return CryptoUtils.getKeysFromMnemonicAndPassphrase(mnemonic, passphrase, pkh, true, KeyStore_1.StoreType.Fundraiser); | ||
} | ||
@@ -137,3 +138,3 @@ TezosWallet.unlockFundraiserIdentity = unlockFundraiserIdentity; | ||
function unlockIdentityWithMnemonic(mnemonic, passphrase) { | ||
return CryptoUtils.getKeysFromMnemonicAndPassphrase(mnemonic, passphrase, "", false); | ||
return CryptoUtils.getKeysFromMnemonicAndPassphrase(mnemonic, passphrase, "", false, KeyStore_1.StoreType.Mnemonic); | ||
} | ||
@@ -140,0 +141,0 @@ TezosWallet.unlockIdentityWithMnemonic = unlockIdentityWithMnemonic; |
/** | ||
* Represents a generic cryptocurrency key pair. | ||
* Represents a generic cryptocurrency key store. | ||
* The seed is only used for HD wallets. | ||
*/ | ||
@@ -8,2 +9,11 @@ export interface KeyStore { | ||
publicKeyHash: string; | ||
seed: string; | ||
storeType: StoreType; | ||
} | ||
/** | ||
* Type of key store, i.e. whether it was generated from a fundraiser PDF or from a new mnemonic | ||
*/ | ||
export declare enum StoreType { | ||
Mnemonic = 0, | ||
Fundraiser = 1, | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* Type of key store, i.e. whether it was generated from a fundraiser PDF or from a new mnemonic | ||
*/ | ||
var StoreType; | ||
(function (StoreType) { | ||
StoreType[StoreType["Mnemonic"] = 0] = "Mnemonic"; | ||
StoreType[StoreType["Fundraiser"] = 1] = "Fundraiser"; | ||
})(StoreType = exports.StoreType || (exports.StoreType = {})); | ||
//# sourceMappingURL=KeyStore.js.map |
/// <reference types="node" /> | ||
import { KeyStore } from "../types/KeyStore"; | ||
import { KeyStore, StoreType } from "../types/KeyStore"; | ||
import { Error } from "../types/Error"; | ||
@@ -53,6 +53,7 @@ /** | ||
* @param {string} pkh The public key hash supposedly produced by the given mnemonic and passphrase | ||
* @param {string} checkPKH Check whether presumed public key hash matches the actual public key hash | ||
* @param {boolean} checkPKH Check whether presumed public key hash matches the actual public key hash | ||
* @param {StoreType} storeType Type of the generated key store | ||
* @returns {KeyStore} Generated keys | ||
*/ | ||
export declare function getKeysFromMnemonicAndPassphrase(mnemonic: string, passphrase: string, pkh?: string, checkPKH?: boolean): Error | KeyStore; | ||
export declare function getKeysFromMnemonicAndPassphrase(mnemonic: string, passphrase: string, pkh: string | undefined, checkPKH: boolean | undefined, storeType: StoreType): Error | KeyStore; | ||
/** | ||
@@ -59,0 +60,0 @@ * Generates a new bip39 mnemonic |
@@ -119,11 +119,15 @@ "use strict"; | ||
* @param {string} pkh The public key hash supposedly produced by the given mnemonic and passphrase | ||
* @param {string} checkPKH Check whether presumed public key hash matches the actual public key hash | ||
* @param {boolean} checkPKH Check whether presumed public key hash matches the actual public key hash | ||
* @param {StoreType} storeType Type of the generated key store | ||
* @returns {KeyStore} Generated keys | ||
*/ | ||
function getKeysFromMnemonicAndPassphrase(mnemonic, passphrase, pkh = '', checkPKH = true) { | ||
function getKeysFromMnemonicAndPassphrase(mnemonic, passphrase, pkh = '', checkPKH = true, storeType) { | ||
const lengthOfMnemonic = mnemonic.split(" ").length; | ||
if (lengthOfMnemonic !== 15) | ||
return { error: "The mnemonic should be 15 words." }; | ||
if (!bip39.validateMnemonic(mnemonic)) | ||
return { error: "The given mnemonic could not be validated." }; | ||
const seed = bip39.mnemonicToSeed(mnemonic, passphrase).slice(0, 32); | ||
const key_pair = sodium.crypto_sign_seed_keypair(seed, ""); | ||
const nonce = ""; | ||
const key_pair = sodium.crypto_sign_seed_keypair(seed, nonce); | ||
const privateKey = base58CheckEncode(key_pair.privateKey, "edsk"); | ||
@@ -135,5 +139,7 @@ const publicKey = base58CheckEncode(key_pair.publicKey, "edpk"); | ||
return { | ||
publicKey: publicKey, | ||
privateKey: privateKey, | ||
publicKeyHash: publicKeyHash | ||
publicKey, | ||
privateKey, | ||
publicKeyHash, | ||
seed, | ||
storeType | ||
}; | ||
@@ -140,0 +146,0 @@ } |
@@ -13,2 +13,3 @@ "use strict"; | ||
const cryptoUtils = __importStar(require("../src/utils/CryptoUtils")); | ||
const KeyStore_1 = require("../src/types/KeyStore"); | ||
describe('base58CheckDecode() and base58CheckEncode()', () => { | ||
@@ -24,9 +25,13 @@ it('should correctly decode and encode a Tezos account ID', () => { | ||
it('should produce the correct mnemonic-based key pair', () => { | ||
const result = cryptoUtils.getKeysFromMnemonicAndPassphrase('clerk rhythm bonus fabric vital luggage team engine stairs palm degree gossip hour say tenant', 'password', 'tz1frMTRzFcEwTXC8WGZzkfZs1CfSL1F4Mnc', false); | ||
const result = cryptoUtils.getKeysFromMnemonicAndPassphrase('clerk rhythm bonus fabric vital luggage team engine stairs palm degree gossip hour say tenant', 'password', 'tz1frMTRzFcEwTXC8WGZzkfZs1CfSL1F4Mnc', true, KeyStore_1.StoreType.Mnemonic); | ||
chai_1.expect(result.publicKeyHash).to.equal('tz1frMTRzFcEwTXC8WGZzkfZs1CfSL1F4Mnc'); | ||
}); | ||
it('should be 15 words', () => { | ||
const result = cryptoUtils.getKeysFromMnemonicAndPassphrase('clerk rhythm bonus fabric vital luggage team engine stairs palm degree gossip hour say', 'password'); | ||
const result = cryptoUtils.getKeysFromMnemonicAndPassphrase('clerk rhythm bonus fabric vital luggage team engine stairs palm degree gossip hour say', 'password', 'tz1frMTRzFcEwTXC8WGZzkfZs1CfSL1F4Mnc', true, KeyStore_1.StoreType.Mnemonic); | ||
chai_1.expect(result.error).to.equal("The mnemonic should be 15 words."); | ||
}); | ||
it('should detect invalid mnemonics', () => { | ||
const result = cryptoUtils.getKeysFromMnemonicAndPassphrase('clerk rhythm bonus fabric vital luggage team engine stairs palm degree gossip hour say tenants', 'password', 'tz1frMTRzFcEwTXC8WGZzkfZs1CfSL1F4Mnc', true, KeyStore_1.StoreType.Mnemonic); | ||
chai_1.expect(result.error).to.equal("The given mnemonic could not be validated."); | ||
}); | ||
}); | ||
@@ -48,3 +53,3 @@ describe('encryptMessage() and decryptMessage()', () => { | ||
const encrypted = cryptoUtils.encryptMessage(message, passphrase, salt); | ||
const decrypted = cryptoUtils.decryptMessage(encrypted, passphrase, salt); | ||
cryptoUtils.decryptMessage(encrypted, passphrase, salt); | ||
} | ||
@@ -51,0 +56,0 @@ catch (err) { |
@@ -20,2 +20,3 @@ "use strict"; | ||
require("mocha"); | ||
const KeyStore_1 = require("../src/types/KeyStore"); | ||
const fs = __importStar(require("fs")); | ||
@@ -35,3 +36,5 @@ const src_1 = require("../src"); | ||
privateKey: 'edskS5owtVaAtWifnCNo8tUpAw2535AXEDY4RXBRV1NHbQ58RDdpaWz2KyrvFXE4SuCTbHU8exUecW33GRqkAfLeNLBS5sPyoi', | ||
publicKeyHash: 'tz1hcXqtiMYFhvuirD4guE7ts4yDuCAmtD95' | ||
publicKeyHash: 'tz1hcXqtiMYFhvuirD4guE7ts4yDuCAmtD95', | ||
seed: '', | ||
storeType: KeyStore_1.StoreType.Mnemonic | ||
}; | ||
@@ -48,3 +51,5 @@ const wallet = { identities: [keys] }; | ||
privateKey: 'edskS5owtVaAtWifnCNo8tUpAw2535AXEDY4RXBRV1NHbQ58RDdpaWz2KyrvFXE4SuCTbHU8exUecW33GRqkAfLeNLBS5sPyoi', | ||
publicKeyHash: 'tz1hcXqtiMYFhvuirD4guE7ts4yDuCAmtD95' | ||
publicKeyHash: 'tz1hcXqtiMYFhvuirD4guE7ts4yDuCAmtD95', | ||
seed: '', | ||
storeType: KeyStore_1.StoreType.Mnemonic | ||
}; | ||
@@ -60,3 +65,3 @@ const wallet = { identities: [keys] }; | ||
chai_1.expect(result.publicKeyHash).to.equal('tz1aj32NRPg49jtvSDhkpruQAFevjaewaLew'); | ||
const result2 = src_1.TezosWallet.unlockFundraiserIdentity('vendorrr excite awake enroll essay gather mention knife inmate insect agent become alpha desert menu', 'byixpeyi.dofdqvwn@tezos.example.org', 'SU0j4HSgbd', 'tz1aj32NRPg49jtvSDhkpruQAFevjaewaLew'); | ||
const result2 = src_1.TezosWallet.unlockFundraiserIdentity('vendor excite awake enroll essay gather mention knife inmate insect agent become alpha desert menu', 'byixpeyi.dofdqvwn@tezos.example.org', 'SU0j4HSgbd', 'tz2aj32NRPg49jtvSDhkpruQAFevjaewaLew'); | ||
chai_1.expect(result2.error).to.equal('The given mnemonic and passphrase do not correspond to the applied public key hash'); | ||
@@ -68,3 +73,2 @@ }); | ||
const result = src_1.TezosWallet.generateMnemonic(); | ||
console.log(result); | ||
chai_1.expect(result.split(' ').length).to.equal(15); | ||
@@ -71,0 +75,0 @@ }); |
@@ -18,2 +18,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const KeyStore_1 = require("../types/KeyStore"); | ||
const CryptoUtils = __importStar(require("../utils/CryptoUtils")); | ||
@@ -118,3 +119,3 @@ const fs = __importStar(require("fs")); | ||
const passphrase = email + password; | ||
return CryptoUtils.getKeysFromMnemonicAndPassphrase(mnemonic, passphrase, pkh, true); | ||
return CryptoUtils.getKeysFromMnemonicAndPassphrase(mnemonic, passphrase, pkh, true, KeyStore_1.StoreType.Fundraiser); | ||
} | ||
@@ -137,3 +138,3 @@ TezosWallet.unlockFundraiserIdentity = unlockFundraiserIdentity; | ||
function unlockIdentityWithMnemonic(mnemonic, passphrase) { | ||
return CryptoUtils.getKeysFromMnemonicAndPassphrase(mnemonic, passphrase, "", false); | ||
return CryptoUtils.getKeysFromMnemonicAndPassphrase(mnemonic, passphrase, "", false, KeyStore_1.StoreType.Mnemonic); | ||
} | ||
@@ -140,0 +141,0 @@ TezosWallet.unlockIdentityWithMnemonic = unlockIdentityWithMnemonic; |
/** | ||
* Represents a generic cryptocurrency key pair. | ||
* Represents a generic cryptocurrency key store. | ||
* The seed is only used for HD wallets. | ||
*/ | ||
@@ -8,2 +9,11 @@ export interface KeyStore { | ||
publicKeyHash: string; | ||
seed: string; | ||
storeType: StoreType; | ||
} | ||
/** | ||
* Type of key store, i.e. whether it was generated from a fundraiser PDF or from a new mnemonic | ||
*/ | ||
export declare enum StoreType { | ||
Mnemonic = 0, | ||
Fundraiser = 1, | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
* Type of key store, i.e. whether it was generated from a fundraiser PDF or from a new mnemonic | ||
*/ | ||
var StoreType; | ||
(function (StoreType) { | ||
StoreType[StoreType["Mnemonic"] = 0] = "Mnemonic"; | ||
StoreType[StoreType["Fundraiser"] = 1] = "Fundraiser"; | ||
})(StoreType = exports.StoreType || (exports.StoreType = {})); | ||
//# sourceMappingURL=KeyStore.js.map |
/// <reference types="node" /> | ||
import { KeyStore } from "../types/KeyStore"; | ||
import { KeyStore, StoreType } from "../types/KeyStore"; | ||
import { Error } from "../types/Error"; | ||
@@ -53,6 +53,7 @@ /** | ||
* @param {string} pkh The public key hash supposedly produced by the given mnemonic and passphrase | ||
* @param {string} checkPKH Check whether presumed public key hash matches the actual public key hash | ||
* @param {boolean} checkPKH Check whether presumed public key hash matches the actual public key hash | ||
* @param {StoreType} storeType Type of the generated key store | ||
* @returns {KeyStore} Generated keys | ||
*/ | ||
export declare function getKeysFromMnemonicAndPassphrase(mnemonic: string, passphrase: string, pkh?: string, checkPKH?: boolean): Error | KeyStore; | ||
export declare function getKeysFromMnemonicAndPassphrase(mnemonic: string, passphrase: string, pkh: string | undefined, checkPKH: boolean | undefined, storeType: StoreType): Error | KeyStore; | ||
/** | ||
@@ -59,0 +60,0 @@ * Generates a new bip39 mnemonic |
@@ -119,11 +119,15 @@ "use strict"; | ||
* @param {string} pkh The public key hash supposedly produced by the given mnemonic and passphrase | ||
* @param {string} checkPKH Check whether presumed public key hash matches the actual public key hash | ||
* @param {boolean} checkPKH Check whether presumed public key hash matches the actual public key hash | ||
* @param {StoreType} storeType Type of the generated key store | ||
* @returns {KeyStore} Generated keys | ||
*/ | ||
function getKeysFromMnemonicAndPassphrase(mnemonic, passphrase, pkh = '', checkPKH = true) { | ||
function getKeysFromMnemonicAndPassphrase(mnemonic, passphrase, pkh = '', checkPKH = true, storeType) { | ||
const lengthOfMnemonic = mnemonic.split(" ").length; | ||
if (lengthOfMnemonic !== 15) | ||
return { error: "The mnemonic should be 15 words." }; | ||
if (!bip39.validateMnemonic(mnemonic)) | ||
return { error: "The given mnemonic could not be validated." }; | ||
const seed = bip39.mnemonicToSeed(mnemonic, passphrase).slice(0, 32); | ||
const key_pair = sodium.crypto_sign_seed_keypair(seed, ""); | ||
const nonce = ""; | ||
const key_pair = sodium.crypto_sign_seed_keypair(seed, nonce); | ||
const privateKey = base58CheckEncode(key_pair.privateKey, "edsk"); | ||
@@ -135,5 +139,7 @@ const publicKey = base58CheckEncode(key_pair.publicKey, "edpk"); | ||
return { | ||
publicKey: publicKey, | ||
privateKey: privateKey, | ||
publicKeyHash: publicKeyHash | ||
publicKey, | ||
privateKey, | ||
publicKeyHash, | ||
seed, | ||
storeType | ||
}; | ||
@@ -140,0 +146,0 @@ } |
{ | ||
"name": "conseiljs", | ||
"version": "0.1.24", | ||
"version": "0.1.25", | ||
"description": "Client-side library for dApp development.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
import {Wallet, EncryptedWalletVersionOne} from "../types/Wallet"; | ||
import {KeyStore} from "../types/KeyStore"; | ||
import {KeyStore, StoreType} from "../types/KeyStore"; | ||
import {Error} from "../types/Error"; | ||
@@ -94,5 +94,15 @@ import * as CryptoUtils from "../utils/CryptoUtils"; | ||
*/ | ||
export function unlockFundraiserIdentity(mnemonic: string, email: string, password: string, pkh: string): KeyStore | Error { | ||
export function unlockFundraiserIdentity( | ||
mnemonic: string, | ||
email: string, | ||
password: string, | ||
pkh: string): KeyStore | Error { | ||
const passphrase = email + password; | ||
return CryptoUtils.getKeysFromMnemonicAndPassphrase(mnemonic, passphrase, pkh, true) | ||
return CryptoUtils.getKeysFromMnemonicAndPassphrase( | ||
mnemonic, | ||
passphrase, | ||
pkh, | ||
true, | ||
StoreType.Fundraiser | ||
) | ||
} | ||
@@ -115,5 +125,11 @@ | ||
export function unlockIdentityWithMnemonic(mnemonic: string, passphrase: string): KeyStore | Error{ | ||
return CryptoUtils.getKeysFromMnemonicAndPassphrase(mnemonic, passphrase, "",false) | ||
return CryptoUtils.getKeysFromMnemonicAndPassphrase( | ||
mnemonic, | ||
passphrase, | ||
"", | ||
false, | ||
StoreType.Mnemonic | ||
) | ||
} | ||
} |
/** | ||
* Represents a generic cryptocurrency key pair. | ||
* Represents a generic cryptocurrency key store. | ||
* The seed is only used for HD wallets. | ||
*/ | ||
@@ -7,3 +8,13 @@ export interface KeyStore { | ||
privateKey: string, | ||
publicKeyHash: string | ||
publicKeyHash: string, | ||
seed: string, | ||
storeType: StoreType | ||
} | ||
/** | ||
* Type of key store, i.e. whether it was generated from a fundraiser PDF or from a new mnemonic | ||
*/ | ||
export enum StoreType { | ||
Mnemonic, | ||
Fundraiser | ||
} |
import * as base58Check from 'bs58check' | ||
import * as bip39 from 'bip39'; | ||
import * as sodium from 'libsodium-wrappers-sumo'; | ||
import {KeyStore} from "../types/KeyStore"; | ||
import {KeyStore, StoreType} from "../types/KeyStore"; | ||
import {Error} from "../types/Error"; | ||
@@ -126,10 +126,18 @@ import * as crypto from 'crypto'; | ||
* @param {string} pkh The public key hash supposedly produced by the given mnemonic and passphrase | ||
* @param {string} checkPKH Check whether presumed public key hash matches the actual public key hash | ||
* @param {boolean} checkPKH Check whether presumed public key hash matches the actual public key hash | ||
* @param {StoreType} storeType Type of the generated key store | ||
* @returns {KeyStore} Generated keys | ||
*/ | ||
export function getKeysFromMnemonicAndPassphrase(mnemonic: string, passphrase: string, pkh = '', checkPKH = true): Error | KeyStore { | ||
export function getKeysFromMnemonicAndPassphrase( | ||
mnemonic: string, | ||
passphrase: string, | ||
pkh = '', | ||
checkPKH = true, | ||
storeType: StoreType): Error | KeyStore { | ||
const lengthOfMnemonic = mnemonic.split(" ").length; | ||
if (lengthOfMnemonic !== 15) return {error: "The mnemonic should be 15 words."}; | ||
if(!bip39.validateMnemonic(mnemonic)) return {error: "The given mnemonic could not be validated."}; | ||
const seed = bip39.mnemonicToSeed(mnemonic, passphrase).slice(0, 32); | ||
const key_pair = sodium.crypto_sign_seed_keypair(seed, ""); | ||
const nonce = ""; | ||
const key_pair = sodium.crypto_sign_seed_keypair(seed, nonce); | ||
const privateKey = base58CheckEncode(key_pair.privateKey, "edsk"); | ||
@@ -140,5 +148,7 @@ const publicKey = base58CheckEncode(key_pair.publicKey, "edpk"); | ||
return { | ||
publicKey: publicKey, | ||
privateKey: privateKey, | ||
publicKeyHash: publicKeyHash | ||
publicKey, | ||
privateKey, | ||
publicKeyHash, | ||
seed, | ||
storeType | ||
} | ||
@@ -145,0 +155,0 @@ } |
import {expect} from 'chai'; | ||
import 'mocha'; | ||
import * as cryptoUtils from "../src/utils/CryptoUtils"; | ||
import {KeyStore} from "../src/types/KeyStore"; | ||
import {KeyStore, StoreType} from "../src/types/KeyStore"; | ||
@@ -21,3 +21,4 @@ describe('base58CheckDecode() and base58CheckEncode()', () => { | ||
'tz1frMTRzFcEwTXC8WGZzkfZs1CfSL1F4Mnc', | ||
false | ||
true, | ||
StoreType.Mnemonic | ||
); | ||
@@ -29,6 +30,19 @@ expect(result.publicKeyHash).to.equal('tz1frMTRzFcEwTXC8WGZzkfZs1CfSL1F4Mnc'); | ||
'clerk rhythm bonus fabric vital luggage team engine stairs palm degree gossip hour say', | ||
'password' | ||
'password', | ||
'tz1frMTRzFcEwTXC8WGZzkfZs1CfSL1F4Mnc', | ||
true, | ||
StoreType.Mnemonic | ||
); | ||
expect(result.error).to.equal("The mnemonic should be 15 words."); | ||
}); | ||
it('should detect invalid mnemonics', () => { | ||
const result: any = cryptoUtils.getKeysFromMnemonicAndPassphrase( | ||
'clerk rhythm bonus fabric vital luggage team engine stairs palm degree gossip hour say tenants', | ||
'password', | ||
'tz1frMTRzFcEwTXC8WGZzkfZs1CfSL1F4Mnc', | ||
true, | ||
StoreType.Mnemonic | ||
); | ||
expect(result.error).to.equal("The given mnemonic could not be validated."); | ||
}); | ||
}); | ||
@@ -51,3 +65,3 @@ | ||
const encrypted = cryptoUtils.encryptMessage(message, passphrase, salt); | ||
const decrypted = cryptoUtils.decryptMessage(encrypted, passphrase, salt); | ||
cryptoUtils.decryptMessage(encrypted, passphrase, salt); | ||
} catch (err) { | ||
@@ -54,0 +68,0 @@ expect(err.message).to.equal('The password strength should not be less than 3.'); |
import {expect} from 'chai'; | ||
import 'mocha'; | ||
import {KeyStore} from "../src/types/KeyStore"; | ||
import {KeyStore, StoreType} from "../src/types/KeyStore"; | ||
import {Wallet} from "../src/types/Wallet"; | ||
@@ -22,3 +22,5 @@ import * as fs from 'fs' | ||
privateKey: 'edskS5owtVaAtWifnCNo8tUpAw2535AXEDY4RXBRV1NHbQ58RDdpaWz2KyrvFXE4SuCTbHU8exUecW33GRqkAfLeNLBS5sPyoi', | ||
publicKeyHash: 'tz1hcXqtiMYFhvuirD4guE7ts4yDuCAmtD95' | ||
publicKeyHash: 'tz1hcXqtiMYFhvuirD4guE7ts4yDuCAmtD95', | ||
seed: '', | ||
storeType: StoreType.Mnemonic | ||
}; | ||
@@ -36,3 +38,5 @@ const wallet: Wallet = {identities: [keys]}; | ||
privateKey: 'edskS5owtVaAtWifnCNo8tUpAw2535AXEDY4RXBRV1NHbQ58RDdpaWz2KyrvFXE4SuCTbHU8exUecW33GRqkAfLeNLBS5sPyoi', | ||
publicKeyHash: 'tz1hcXqtiMYFhvuirD4guE7ts4yDuCAmtD95' | ||
publicKeyHash: 'tz1hcXqtiMYFhvuirD4guE7ts4yDuCAmtD95', | ||
seed: '', | ||
storeType: StoreType.Mnemonic | ||
}; | ||
@@ -56,6 +60,6 @@ const wallet: Wallet = {identities: [keys]}; | ||
const result2 = <Error> TezosWallet.unlockFundraiserIdentity( | ||
'vendorrr excite awake enroll essay gather mention knife inmate insect agent become alpha desert menu', | ||
'vendor excite awake enroll essay gather mention knife inmate insect agent become alpha desert menu', | ||
'byixpeyi.dofdqvwn@tezos.example.org', | ||
'SU0j4HSgbd', | ||
'tz1aj32NRPg49jtvSDhkpruQAFevjaewaLew' | ||
'tz2aj32NRPg49jtvSDhkpruQAFevjaewaLew' | ||
); | ||
@@ -69,3 +73,2 @@ expect(result2.error).to.equal('The given mnemonic and passphrase do not correspond to the applied public key hash'); | ||
const result = TezosWallet.generateMnemonic(); | ||
console.log(result); | ||
expect(result.split(' ').length).to.equal(15); | ||
@@ -72,0 +75,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
330308
5443